This file is for AI agents working in this repository. Keep changes aligned with the current codebase and prefer concise, minimal edits.
- Language: Nim (pure std library, no external dependencies)
- UI: Terminal-first interactive CLI
- Default working style: terminal-first, tool-driven
- Main purpose: a terminal AI coding assistant with provider abstraction, sessions, and built-in tools
- Version: v0.1.1
src/nimcode.nim— CLI entry pointsrc/nimcode/config/— settings and defaultssrc/nimcode/provider/— provider abstraction (OpenAI, Anthropic, Google, DeepSeek)src/nimcode/agent/— agent loop, events, system promptsrc/nimcode/tools/— built-in tools (read, write, edit, bash, ls, grep, find, plan, jobs, kill, cron, spawn, skill_ref)src/nimcode/session/— JSONL session storagesrc/nimcode/contextfiles/— AGENTS.md / CLAUDE.md discoverysrc/nimcode/context/— token estimation and context managementsrc/nimcode/skills/— skills loadingsrc/nimcode/memory/— persistent memory (memory.md)src/nimcode/mcp/— MCP (Model Context Protocol) clientsrc/nimcode/cron/— Cron schedulersrc/nimcode/sandbox/— Sandbox (bwrap) supportsrc/nimcode/a2a/— A2A (Agent-to-Agent) protocolsrc/nimcode/acp/— ACP (Agent Client Protocol)src/nimcode/hermes/— Hermes daemontests/— test filesbin/— compiled binariesPLAN.md— 迁移计划与进度
- Providers stream responses through the provider abstraction.
- The agent loop builds a system prompt, sends messages, handles stream events, executes tools, and continues until completion.
- Tools should stay stateless when possible; shared execution state belongs in registries.
- Sessions are stored as JSONL.
- Context files (AGENTS.md, CLAUDE.md, .cursorrules) are automatically loaded from project, parent, and global directories.
- Skills are loaded from
.skills/(project) and~/.nimcode/skills/(global). - Memory is stored in
~/.nimcode/memory.md. - MCP servers are configured in
~/.nimcode/mcp.jsonor.nimcode/mcp.json. - Cron jobs are stored in
~/.nimcode/cron.json.
- Minimize external dependencies. Prefer Nim std library (
std/httpclient,std/json,std/strutils,std/os,std/options, etc.) over third-party Nimble packages. Only introduce an external dependency when the std lib genuinely cannot accomplish the task, and document the reason. - Read before editing.
- Prefer small, targeted changes.
- Keep behavior consistent with existing patterns.
- Do not introduce broad refactors unless requested.
- Do not add license headers unless the repository already uses them.
- Do not auto-commit. Commit only when the user explicitly asks.
- Use
resultor explicit return; avoid implicit returns for clarity. - Prefer
letovervarwhen values don't change. - Use
procfor functions,funcfor pure functions (no side effects). - Use
methodonly for dynamic dispatch on object types. - Follow existing naming:
camelCasefor procs/vars,PascalCasefor types/objects,SCREAMING_SNAKE_CASEfor constants. - Use
Option[T]fromstd/optionsfor nullable values instead of nil pointers. - Prefer
seq[T]over arrays for dynamic collections. - Use
stringfor text; avoidcstringunless interfacing with C. - Keep modules focused — one primary concern per file.
- Use
importfor standard library,from ... importfor selective imports. - Handle errors with
try/exceptorResulttypes; do not usequitfor normal error handling. - Add doc comments with
##for public procs and types.
Built-in tools include:
read— Read file contents (supports text and images)write— Write content to filesedit— Edit files using exact text replacementbash— Execute shell commands (with sandbox support)ls— List directory contentsgrep— Search file contents using regexfind— Find files by name patternplan— Publish or update a structured task planjobs— List background jobskill— Kill a running background jobcron— Manage scheduled tasks (create, list, enable, disable, remove)spawn— Spawn a sub-agent to handle a task in parallelskill_ref— Load a reference file from an active skillweb_search— Search the web (when enabled)- MCP tools — Tools from MCP servers (auto-registered)
plan: read-only toolsagent: all tools allowedyolo: all tools auto-execute (same as agent for now)- Sandbox: optional bwrap isolation for bash commands (strict/standard/none)
{
"providers": {
"openai": { "apiKey": "${OPENAI_API_KEY}", "baseUrl": "https://api.openai.com/v1", "api": "openai-chat" },
"anthropic": { "apiKey": "${ANTHROPIC_API_KEY}", "baseUrl": "https://api.anthropic.com", "api": "anthropic-messages" },
"deepseek": { "apiKey": "${DEEPSEEK_API_KEY}", "baseUrl": "https://api.deepseek.com", "api": "openai-chat" },
"google-gemini": { "apiKey": "${GOOGLE_API_KEY}", "baseUrl": "...", "api": "google-gemini" }
},
"defaultProvider": "deepseek",
"defaultModel": "deepseek-chat",
"defaultMode": "agent",
"defaultThinkingLevel": "medium",
"webSearch": { "enabled": false, "providerType": "responses" },
"sandbox": { "enabled": false, "level": "none" },
"compaction": { "enabled": true, "reserveTokens": 16384, "keepRecentTokens": 20000 },
"retry": { "enabled": true, "maxRetries": 3, "baseDelayMs": 2000 },
"approval": { "bashWhitelist": ["go ", "make ", "git "], "confirmBeforeWrite": false }
}{
"mcpServers": {
"my-server": {
"type": "stdio",
"command": "/path/to/mcp-server",
"args": ["--flag"],
"env": [{ "name": "KEY", "value": "value" }]
}
}
}Common commands:
nim c src/nimcode.nim— compile the projectnim c -o:bin/nimcode src/nimcode.nim— compile to bin/nimcodenim c -d:release -o:bin/nimcode src/nimcode.nim— release buildmake build— debug buildmake release— release buildmake clean— clean build artifacts./bin/nimcode --help— show help./bin/nimcode --version— show version./bin/nimcode -P "say hi"— print mode test
clear— Clear conversation historyexit/quit— Exit NimCodehelp— Show available commandsmode— Show current modeprovider— Show current providermodel— Show current modelthinking— Show thinking levelsession— Show session infosessions— List recent sessionsusage— Show context usagemcp— Show MCP server statussandbox— Show sandbox statuscron— List cron jobstools— List available tools
Current version: v0.1.1
Next version: v0.1.2