mocode-ai 1.3.10 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -70
- package/README.zh-CN.md +81 -73
- package/dist/agent/core.js +226 -293
- package/dist/agent/index.js +14 -10
- package/dist/agent/mode.js +3 -3
- package/dist/agent/runtime-context.js +45 -0
- package/dist/agent/spawn.js +101 -86
- package/dist/agent/tool-helpers.js +134 -0
- package/dist/agent/trace-state.js +118 -0
- package/dist/agents/coordinator.js +6 -1
- package/dist/changeset/index.js +9 -8
- package/dist/config/index.js +109 -77
- package/dist/config/presets.js +3 -1
- package/dist/config/profiles.js +125 -0
- package/dist/context/age-aware.js +2 -4
- package/dist/context/artifacts.js +6 -13
- package/dist/context/budget.js +6 -8
- package/dist/context/classifier.js +1 -2
- package/dist/context/encoders/code.js +2 -6
- package/dist/context/encoders/command.js +1 -3
- package/dist/context/encoders/search.js +1 -3
- package/dist/context/index.js +1 -1
- package/dist/context/lifecycle.js +5 -3
- package/dist/context/pipeline.js +1 -1
- package/dist/context/relevance.js +2 -4
- package/dist/context/token-calibration.js +13 -18
- package/dist/host/stdio.js +73 -12
- package/dist/i18n/index.js +96 -44
- package/dist/index.js +1 -1
- package/dist/llm/index.js +39 -23
- package/dist/llm/provider.js +23 -0
- package/dist/llm/providers/anthropic.js +12 -18
- package/dist/llm/tool-schema.js +48 -0
- package/dist/mcp/client.js +70 -25
- package/dist/mcp/config.js +1 -3
- package/dist/mcp/index.js +3 -1
- package/dist/memory/reflect.js +3 -6
- package/dist/memory/store.js +10 -12
- package/dist/permissions/index.js +66 -22
- package/dist/pet/bridge.js +2 -2
- package/dist/repl/commands/appearance.js +72 -0
- package/dist/repl/commands/compact.js +114 -0
- package/dist/repl/commands/context.js +17 -0
- package/dist/repl/commands/image.js +71 -0
- package/dist/repl/commands/memory.js +51 -0
- package/dist/repl/commands/mode.js +47 -0
- package/dist/repl/commands/model.js +435 -0
- package/dist/repl/commands/pet.js +70 -0
- package/dist/repl/commands/registry.js +46 -0
- package/dist/repl/commands/session.js +102 -0
- package/dist/repl/commands/skill.js +95 -0
- package/dist/repl/commands/system.js +202 -0
- package/dist/repl/commands/tool-group.js +233 -0
- package/dist/repl/commands/types.js +4 -0
- package/dist/repl/commands.js +324 -0
- package/dist/repl/index.js +5 -2581
- package/dist/repl/message-format.js +151 -0
- package/dist/repl/running-input.js +147 -0
- package/dist/repl/runtime.js +816 -0
- package/dist/repl/status-bar.js +161 -0
- package/dist/rollback/index.js +44 -14
- package/dist/runtime/browser-manager.js +1 -1
- package/dist/runtime/dev-server-manager.js +1 -1
- package/dist/runtime/input-injector.js +313 -0
- package/dist/runtime/screen-capture.js +89 -0
- package/dist/runtime/screen-pipeline.js +223 -0
- package/dist/sandbox/index.js +1 -1
- package/dist/sandbox/policy.js +8 -2
- package/dist/session/compact.js +22 -34
- package/dist/session/index.js +2 -2
- package/dist/session/notes.js +39 -5
- package/dist/session/persist.js +14 -8
- package/dist/session/scheduler.js +3 -4
- package/dist/session/trace-metrics.js +24 -10
- package/dist/skills/activation.js +10 -5
- package/dist/skills/discover.js +5 -17
- package/dist/skills/index.js +1 -1
- package/dist/skills/runner.js +28 -44
- package/dist/skills/toolmap.js +5 -2
- package/dist/tools/builtins/browser.js +17 -3
- package/dist/tools/builtins/computer.js +322 -0
- package/dist/tools/builtins/dev-server.js +1 -3
- package/dist/tools/builtins/edit-file.js +21 -7
- package/dist/tools/builtins/grep.js +1 -1
- package/dist/tools/builtins/index.js +28 -25
- package/dist/tools/builtins/memory-forget.js +1 -1
- package/dist/tools/builtins/memory-graph.js +4 -7
- package/dist/tools/builtins/memory-list.js +2 -6
- package/dist/tools/builtins/memory-save.js +8 -2
- package/dist/tools/builtins/memory-search.js +4 -4
- package/dist/tools/builtins/note-append.js +14 -3
- package/dist/tools/builtins/plan-update.js +40 -9
- package/dist/tools/builtins/run-command.js +8 -8
- package/dist/tools/builtins/screenshot.js +11 -87
- package/dist/tools/builtins/task.js +29 -40
- package/dist/tools/builtins/use-skill.js +1 -1
- package/dist/tools/builtins/view-image.js +5 -3
- package/dist/tools/builtins/web-fetch.js +1 -3
- package/dist/tools/builtins/web-search.js +3 -7
- package/dist/tools/builtins/write-file.js +4 -2
- package/dist/tools/constants.js +50 -37
- package/dist/tools/policy.js +221 -0
- package/dist/tools/registry.js +40 -19
- package/dist/tools/resource-lock.js +4 -2
- package/dist/tools/router.js +143 -0
- package/dist/tools/validation.js +6 -5
- package/dist/ui/batch.js +73 -38
- package/dist/ui/clipboard.js +17 -5
- package/dist/ui/content.js +166 -13
- package/dist/ui/diff.js +61 -19
- package/dist/ui/fuzzy.js +35 -2
- package/dist/ui/intervention.js +2 -4
- package/dist/ui/layout-internal/content-write.js +587 -0
- package/dist/ui/layout-internal/core.js +590 -0
- package/dist/ui/layout-internal/input-paint.js +365 -0
- package/dist/ui/layout-internal/screen.js +128 -0
- package/dist/ui/layout-internal/scroll.js +152 -0
- package/dist/ui/layout-internal/selection.js +229 -0
- package/dist/ui/layout-internal/state.js +82 -0
- package/dist/ui/layout-internal/statusbar.js +351 -0
- package/dist/ui/layout-types.js +1 -0
- package/dist/ui/layout.js +3 -2288
- package/dist/ui/markdown.js +10 -2
- package/dist/ui/prompt-internal/editor-operations.js +56 -0
- package/dist/ui/prompt-internal/editor.js +940 -0
- package/dist/ui/prompt-internal/paste.js +52 -0
- package/dist/ui/prompt-internal/pickers.js +519 -0
- package/dist/ui/prompt-internal/types.js +1 -0
- package/dist/ui/prompt.js +4 -1506
- package/dist/ui/render.js +87 -2
- package/dist/verification/affected.js +11 -5
- package/dist/verification/discovery.js +1 -3
- package/dist/verification/profile.js +11 -3
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ MoCode isn't a chat box with a coat of paint — it's an agent that actually get
|
|
|
76
76
|
- **Autonomous multi-step execution** — In a single conversation, the agent chains multiple steps on its own: read code, edit code, run tests, fix based on errors, and so on. It decides the next step without you nagging it. When it hits a decision point, it calls `ask_human` to pop up a panel and ask you (blocking until you respond).
|
|
77
77
|
- **Parallel read-only tools** — Consecutive read-only operations in a turn (reading files, grep, glob, codegraph, web search/fetch) run concurrently, so total time is roughly the slowest single call instead of the sum of all of them. Operations with side effects (writing/editing files) stay sequential to preserve snapshot ordering and data safety.
|
|
78
78
|
- **Sub-agents divide and conquer** — Complex tasks can spawn independent sub-agents with isolated histories and scoped toolsets. Read-only workers can fan out concurrently; writer workers run in private filesystem overlays and return ChangeSets that are merged under expected-hash checks and canonical resource locks. Only structured findings return to the main thread.
|
|
79
|
-
- **Plan / Auto dual mode** — In `plan` mode the agent is read-only (reads code, queries indexes, searches — never writes to disk, runs commands, or spawns sub-agents) and produces a plan; `auto` mode
|
|
79
|
+
- **Plan / Auto dual mode** — In `plan` mode the agent is read-only (reads code, queries indexes, searches — never writes to disk, runs commands, or spawns sub-agents) and produces a plan; `auto` mode permits execution. Tool capabilities are not a static “full” mode: a lightweight LLM router selects the minimum sufficient groups for each real user turn, and the main model may add groups on a later step when needed.
|
|
80
80
|
- **Pressure-driven context compression** — Normal history keeps full tool evidence. At 80% occupancy, one scheduler event runs all enabled cleanup and always follows with a history summary. `/context` shows live usage and `/compact` remains an explicit manual override.
|
|
81
81
|
- **Cross-session long-term memory** — The agent can save project architecture, conventions, and lessons learned as long-term memory, auto-loaded in future sessions. A background process periodically reflects on conversations to mine things worth remembering. Memories can be created, searched, updated, and forgotten, with recall-based decay.
|
|
82
82
|
- **Project context (`AGENTS.md`)** — A single project-level memory file at `AGENTS.md` captures both static facts (project description, commands, module list, directory tree) and human/AI-written insights (conventions, architectural decisions, pitfalls). Generate it once with `/init`, then keep it up to date by hand or by asking the agent to refresh it. Loaded automatically into the system prompt on every turn.
|
|
@@ -84,6 +84,7 @@ MoCode isn't a chat box with a coat of paint — it's an agent that actually get
|
|
|
84
84
|
- **Interruptible and reversible** — Ctrl+C interrupts the current turn at any time (kills child processes recursively, rolls history back to before the turn started, leaves no half-finished tool calls). `/rollback` restores file changes from per-turn snapshots, with a per-file keep/undo choice — no git dependency required.
|
|
85
85
|
- **Input safety net** — Long prompts no longer fear a stray Enter: `Ctrl+G` opens an in-TUI composer popup (notepad-style editing — Enter inserts a newline, with soft wrap, selection, copy/cut/paste and undo; Ctrl+S fills the text back into the input box without sending). `Ctrl+R`/`Ctrl+P` fuzzy-search your input history (Enter only fills it back), and the post-send recall window widens to 2 seconds with any-key recall for long inputs.
|
|
86
86
|
- **Sandbox protection** — File reads/writes go through a sandbox that blocks out-of-bounds paths (`../../`, absolute paths outside the root, symlink escapes, etc.), so the agent never touches files outside your working directory.
|
|
87
|
+
- **Computer Use (high-risk, routed only for explicit GUI intent)** — When the request genuinely requires real mouse/keyboard interaction, the router can expose the `computer-control` group and feed each resulting screenshot back to the model. `/cu off` (or `MOCODE_COMPUTER_USE_ENABLED=false`) is a hard veto; `/cu on` merely allows routing and does not keep the tool permanently visible. The blast radius exceeds file tools because OS input bypasses the file sandbox. **Use a VM / sandbox / dedicated test machine**, not a daily driver. Every action still passes the permission gate, and plan mode always blocks it. Windows first; macOS/Linux pending.
|
|
87
88
|
|
|
88
89
|
## Features
|
|
89
90
|
|
|
@@ -148,8 +149,8 @@ LLM_MODEL=glm-4.6 # swap in your model name
|
|
|
148
149
|
|
|
149
150
|
Common backend `base_url` values:
|
|
150
151
|
|
|
151
|
-
| Backend |
|
|
152
|
-
| -------------- |
|
|
152
|
+
| Backend | base_url |
|
|
153
|
+
| -------------- | --------------------------------------------------- |
|
|
153
154
|
| GLM (Zhipu) | `https://open.bigmodel.cn/api/v3` |
|
|
154
155
|
| DeepSeek | `https://api.deepseek.com` |
|
|
155
156
|
| Qwen (Alibaba) | `https://dashscope.aliyuncs.com/compatible-mode/v1` |
|
|
@@ -160,24 +161,28 @@ Common backend `base_url` values:
|
|
|
160
161
|
|
|
161
162
|
### Optional configuration
|
|
162
163
|
|
|
163
|
-
| Environment variable
|
|
164
|
-
|
|
|
165
|
-
| `MAX_TOKENS`
|
|
166
|
-
| `CONTEXT_WINDOW_TOKENS`
|
|
167
|
-
| `LLM_STREAM_USAGE`
|
|
168
|
-
| `AUTO_COMPACT`
|
|
169
|
-
| `AUTO_REFLECT`
|
|
170
|
-
| `REFLECT_EVERY_N`
|
|
171
|
-
| `ANYSEARCH_API_KEY`
|
|
172
|
-
| `ANYSEARCH_BASE_URL`
|
|
173
|
-
| `SKILLS_DIRS`
|
|
174
|
-
| `MOCODE_CONTEXT_OPTIMIZE`
|
|
175
|
-
| `MOCODE_CONTEXT_RELPRUNE`
|
|
176
|
-
| `MOCODE_LIFECYCLE`
|
|
177
|
-
| `MAX_STEPS`
|
|
178
|
-
| `SUB_AGENT_MAX_STEPS`
|
|
179
|
-
| `SANDBOX_ROOT`
|
|
180
|
-
| `
|
|
164
|
+
| Environment variable | Description | Default |
|
|
165
|
+
| ------------------------------- | --------------------------------------------------------------------------------------------- | --------------------------- |
|
|
166
|
+
| `MAX_TOKENS` | Max tokens per response | unlimited |
|
|
167
|
+
| `CONTEXT_WINDOW_TOKENS` | Model context window; must match the real model | `256000` |
|
|
168
|
+
| `LLM_STREAM_USAGE` | Include `stream_options.include_usage` on streaming requests for real usage | `true` |
|
|
169
|
+
| `AUTO_COMPACT` | Final history-compaction safety fallback | `true` |
|
|
170
|
+
| `AUTO_REFLECT` | Background reflection pass (opt-in; periodically mines memories from conversations) | `false` |
|
|
171
|
+
| `REFLECT_EVERY_N` | Trigger a background reflection every N turns (runs alongside the agent, non-blocking) | `5` |
|
|
172
|
+
| `ANYSEARCH_API_KEY` | Web search API key (falls back to anonymous free quota if unset) | none |
|
|
173
|
+
| `ANYSEARCH_BASE_URL` | Search API endpoint | `https://api.anysearch.com` |
|
|
174
|
+
| `SKILLS_DIRS` | Override the default skill scan directories (platform path separator) | three default directories |
|
|
175
|
+
| `MOCODE_CONTEXT_OPTIMIZE` | Opt-in typed encoding of Cold logs/searches, only under real pressure | `false` |
|
|
176
|
+
| `MOCODE_CONTEXT_RELPRUNE` | Opt-in exact superseded-evidence pruning, only under real pressure | `false` |
|
|
177
|
+
| `MOCODE_LIFECYCLE` | Provenance metadata tracking; never ages or rewrites content | `true` |
|
|
178
|
+
| `MAX_STEPS` | Max agent loop steps per turn (infinite-loop safety only) | `1000` |
|
|
179
|
+
| `SUB_AGENT_MAX_STEPS` | Sub-agent loop safety ceiling; defaults to the main-agent value | `1000` |
|
|
180
|
+
| `SANDBOX_ROOT` | Sandbox root directory (file operation boundary; falls back to cwd if unset) | none |
|
|
181
|
+
| `MOCODE_SUBAGENT_ENABLED` | Set `false` to veto the `orchestration` route group; unset/`true` allows on-demand routing | unset |
|
|
182
|
+
| `MOCODE_FRONTEND_TOOLS_ENABLED` | Set `false` to veto `browser-debug` and `desktop-observe`; unset/`true` allows routing | unset |
|
|
183
|
+
| `MOCODE_COMPUTER_USE_ENABLED` | Set `false` to veto high-risk `computer-control`; unset/`true` allows explicit-intent routing | unset |
|
|
184
|
+
| `MEMORY_ENABLED` | Set `false` to veto memory groups; `true` also enables the Memory Index | unset |
|
|
185
|
+
| `MOCODE_THEME` | Color theme (default/dark/light…; shell env takes precedence over file) | `default` |
|
|
181
186
|
|
|
182
187
|
## Usage
|
|
183
188
|
|
|
@@ -196,32 +201,33 @@ The agent operates in **the working directory it was launched from** — to have
|
|
|
196
201
|
|
|
197
202
|
## Tools
|
|
198
203
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
|
202
|
-
|
|
|
203
|
-
| `
|
|
204
|
-
| `
|
|
205
|
-
| `
|
|
206
|
-
| `
|
|
207
|
-
| `
|
|
208
|
-
| `
|
|
209
|
-
| `
|
|
210
|
-
| `
|
|
211
|
-
| `
|
|
212
|
-
| `
|
|
213
|
-
| `
|
|
214
|
-
| `
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
| `
|
|
218
|
-
| `
|
|
219
|
-
| `
|
|
220
|
-
| `
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
204
|
+
Every real user turn first goes through a constrained LLM router. Ten common tools are always available (`read_file`, `view_image`, `glob`, `grep`, `web_search`, `web_fetch`, `plan_update`, `note_append`, `ask_human`, `use_skill`); additional capabilities are selected as composable groups for writing, shell debugging, browser debugging, desktop observation/control, memory, orchestration, and MCP. If the initial set is insufficient, the main model must call `add_tool_groups` alone; the expanded schemas appear on the next model step. A routing failure reuses the previous turn’s groups (or common-only), never the full toolset.
|
|
205
|
+
|
|
206
|
+
| Tool | Purpose |
|
|
207
|
+
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
208
|
+
| `read_file` | Read a file with line numbers; supports `offset` / `limit` |
|
|
209
|
+
| `write_file` | Create/overwrite a file, auto-creating parent directories |
|
|
210
|
+
| `edit_file` | Precise string replacement (`old_string` must match uniquely) |
|
|
211
|
+
| `run_command` | Run a shell command, merging stdout+stderr, 120s default timeout |
|
|
212
|
+
| `glob` | Find files by glob pattern (excludes node_modules/.git) |
|
|
213
|
+
| `grep` | Regex content search, pure JS implementation, no `rg` dependency |
|
|
214
|
+
| `codegraph` | With a `.codegraph/` index built, query symbol source and call chains (more accurate and cheaper than read_file/grep) |
|
|
215
|
+
| `web_search` | Web search (AnySearch), returns title/URL/snippet/body |
|
|
216
|
+
| `web_fetch` | Fetch a URL, cleaning HTML into plain text |
|
|
217
|
+
| `use_skill` | Load the full SKILL.md instructions for a given skill |
|
|
218
|
+
| `ask_human` | Pop up a Q&A panel at decision points; user picks a preset or types freely (blocks until answered) |
|
|
219
|
+
| `plan_update` | Record/update the session execution plan (the `## Plan:` block in notes.md); three-state steps, at most one in_progress, auto-settles to `## Done:` when all complete |
|
|
220
|
+
| `sub-agent` | Spawn a capable isolated worker; read tasks can run concurrently and writes use overlay + ChangeSet safe merge |
|
|
221
|
+
|
|
222
|
+
| `memory_save` | Save a piece of cross-session long-term memory (title indexed, body fetched on demand) |
|
|
223
|
+
| `memory_search` | Search memory bodies by keyword; hits boost the recall count (affects forgetting decay) |
|
|
224
|
+
| `memory_list` | List the memory index (id/title/summary, no body) |
|
|
225
|
+
| `memory_update` | Edit a memory in place (id unchanged; correct stale facts / update summary / toggle pin) |
|
|
226
|
+
| `memory_forget` | Forget a memory: archived by default (recoverable), `mode=delete` for a hard delete (pinned memories can't be deleted) |
|
|
227
|
+
|
|
228
|
+
The six `memory_*` tools are split into `memory-read` and `memory-write` route groups. They appear only when the router selects them; `MEMORY_ENABLED=false` vetoes both groups, while `MEMORY_ENABLED=true` also enables the compact Memory Index in the prompt. `/memory_switch` manages that compatibility gate.
|
|
229
|
+
|
|
230
|
+
Frontend capabilities are also split by purpose: `browser` + `dev_server` form `browser-debug`, while whole-desktop `screenshot` is `desktop-observe`; `view_image` remains a common read tool. The router may combine these groups with `computer-control` when a task genuinely needs both structured web diagnostics and real desktop interaction. `/fe off` is a hard veto, not a manual profile selector.
|
|
225
231
|
|
|
226
232
|
### Frontend / UI loop
|
|
227
233
|
|
|
@@ -241,28 +247,30 @@ dev_server stop id=srv-xxxx
|
|
|
241
247
|
|
|
242
248
|
## Slash commands
|
|
243
249
|
|
|
244
|
-
| Command
|
|
245
|
-
|
|
|
246
|
-
| `/exit` `/quit`
|
|
247
|
-
| `/clear`
|
|
248
|
-
| `/image`
|
|
249
|
-
| `/context`
|
|
250
|
-
| `/skills`
|
|
251
|
-
| `/compact`
|
|
252
|
-
| `/resume`
|
|
253
|
-
| `/rollback`
|
|
254
|
-
| `/memory`
|
|
255
|
-
| `/memory_switch`
|
|
256
|
-
| `/reflect`
|
|
257
|
-
| `/model`
|
|
258
|
-
| `/init`
|
|
259
|
-
| `/theme`
|
|
260
|
-
| `/plan`
|
|
261
|
-
| `/auto`
|
|
262
|
-
| `/pet`
|
|
263
|
-
| `/fe`
|
|
264
|
-
| `/
|
|
265
|
-
| `/
|
|
250
|
+
| Command | Purpose |
|
|
251
|
+
| ---------------- | ---------------------------------------------------------------------------------------------- |
|
|
252
|
+
| `/exit` `/quit` | Exit MoCode |
|
|
253
|
+
| `/clear` | Clear history (keeps the system prompt) + clear screen |
|
|
254
|
+
| `/image` | Attach a local image to the next message; supports `attach <path>` / `list` / `clear` |
|
|
255
|
+
| `/context` | Show a context usage bar (tokens / message count, estimated or measured) |
|
|
256
|
+
| `/skills` | List discovered skills |
|
|
257
|
+
| `/compact` | Compress history (optionally with a focus hint: `/compact …`) |
|
|
258
|
+
| `/resume` | Resume a saved session |
|
|
259
|
+
| `/rollback` | Menu to pick a turn to roll back to (↑↓ · Enter) |
|
|
260
|
+
| `/memory` | Show memory library: entry count + recent index |
|
|
261
|
+
| `/memory_switch` | Allow/block memory routing and toggle the Memory Index; effective next real user turn |
|
|
262
|
+
| `/reflect` | Manually trigger a background memory reflection pass |
|
|
263
|
+
| `/model` | Configure the LLM (baseURL / apiKey / model / context window), applied immediately + persisted |
|
|
264
|
+
| `/init` | Scan the project and generate `AGENTS.md` project memory (dispatched to the agent) |
|
|
265
|
+
| `/theme` | Switch color theme (↑↓ · Enter, or `/theme <name>` directly) |
|
|
266
|
+
| `/plan` | Switch to plan mode (read-only exploration + plan output, approve to switch to auto) |
|
|
267
|
+
| `/auto` | Switch back to executable mode; tools are routed per task |
|
|
268
|
+
| `/pet` | Toggle the optional desktop pet (floating window mirroring agent state) |
|
|
269
|
+
| `/fe` | Allow/block automatic routing of `browser-debug` and `desktop-observe` |
|
|
270
|
+
| `/cu` | Allow/block automatic routing of high-risk `computer-control` |
|
|
271
|
+
| `/subagent` | Allow/block automatic routing of `orchestration` |
|
|
272
|
+
| `/pet skin` | Pick a pet skin (↑↓ · Enter) |
|
|
273
|
+
| `/pet quit` | Fully shut down the pet process (not just disconnect) |
|
|
266
274
|
|
|
267
275
|
Type `/` to trigger the dropdown menu, keep typing to filter; Esc to cancel.
|
|
268
276
|
|
|
@@ -299,7 +307,7 @@ The system prompt provides lightweight guidance rather than a framework gate: in
|
|
|
299
307
|
MoCode has a **two-tier memory** model distinct from skills:
|
|
300
308
|
|
|
301
309
|
- **Tier-1 — `AGENTS.md` (auto-loaded every session):** Markdown project memory that gets concatenated into the system prompt on every turn. Discovery walks `~/.mocode/AGENTS.md` → every `AGENTS.md` from the cwd up to the filesystem root (far→near, near wins). On overflow the body is truncated with a marker pointing back at the files. Generate or refresh one with `/init`, or write it by hand — it's plain Markdown, no schema. `AGENTS.md` is also where the agent itself persists "next-session facts" it deduces (architecture, conventions, pitfalls).
|
|
302
|
-
- **Tier-2 — `memory_*` tool library (agent-driven,
|
|
310
|
+
- **Tier-2 — `memory_*` tool library (agent-driven, routed on demand):** Discrete tagged records (`decision` / `fact` / `pitfall` / `reference` / `feedback`) with recall-count-based decay (30-day → archived; 90-day → GC). The LLM router selects `memory-read` for retrieval and `memory-write` only for explicit persistence intent. Set `MEMORY_ENABLED=false` to veto both groups; `true` additionally injects the compact Memory Index. The agent searches before saving and updates existing entries rather than duplicating them.
|
|
303
311
|
|
|
304
312
|
## Type checking
|
|
305
313
|
|
package/README.zh-CN.md
CHANGED
|
@@ -76,13 +76,14 @@ mocode 不是一个套壳聊天框,而是一个能真正动手干活的 agent:
|
|
|
76
76
|
- **自主多步推进** — 一次对话里连续多步:读代码、改代码、跑测试、根据报错再改……agent 自己决定下一步,中途不用你反复催。遇到卡点会调 `ask_human` 弹面板问你(阻塞到回应)。
|
|
77
77
|
- **只读工具并行执行** — 一轮里连续的只读操作(读文件、grep、glob、codegraph、联网搜索/抓取)自动并发跑,总耗时 ≈ 最慢一个,而不是逐个排队。写文件 / 改文件这类有副作用的操作仍串行,保快照顺序与数据安全。
|
|
78
78
|
- **子 agent 分而治之** — 复杂任务可派生拥有独立历史与受限工具集的子 agent。只读 worker 可并行扇出;写 worker 在私有文件系统 overlay 中运行,返回的 ChangeSet 经过 expected hash 校验与规范化资源锁后才合并。主线只接收结构化发现,不接收过程噪声。
|
|
79
|
-
- **计划 / 执行双模式** — `plan` 模式下只读探查(读代码、查索引、搜索,绝不写盘、不跑命令、不派生子 agent)
|
|
79
|
+
- **计划 / 执行双模式** — `plan` 模式下只读探查(读代码、查索引、搜索,绝不写盘、不跑命令、不派生子 agent),产出计划;`auto` 模式允许执行,但不是静态“全工具”模式:每个真实用户轮先由轻量 LLM router 选择最小充分工具簇,主模型需要时可在后续 step 追加能力。
|
|
80
80
|
- **统一压力驱动压缩** — 正常 history 保留完整工具证据;达到 80% 后由一次调度事件运行所有已启用的清理,并始终继续 history 摘要。`/context` 显示实时用量,`/compact` 仍是用户显式覆盖。
|
|
81
81
|
- **跨会话长期记忆** — agent 能把项目架构、约定、踩过的坑存成长期记忆,下次会话自动加载;后台还会定期从对话里反思挖掘值得记住的事。记忆可增删改、带召回衰减。
|
|
82
82
|
- **会话记事本(notes.md)** — 复杂多步任务(≥3 处文件改动 / ≥5 步工具调用)时,agent 在 `.mocode/sessions/<sessionId>/notes.md` 维护一个工作记事本(落盘抗压缩),可记录中间发现、设计决策、待验证问题和结构化计划。执行计划由专用 `plan_update` 工具维护——三态步骤机(`pending`/`in_progress`/`completed`,同一时刻至多一个 `in_progress`),全部完成自动结算为 `## Done:`。活跃 plan 在压缩后重注入系统提示、notes.md 一变就重同步进上下文,若连续多步未更新还会有温和提醒。TUI 状态栏实时显示进度 chip:`plan: [标题] (3/7) ▸ [当前步]`。
|
|
83
83
|
- **可中断、可回滚** — Ctrl+C 随时打断当前轮次(树杀子进程,历史还原到本轮开始前,不留残半的工具调用);`/rollback` 按轮次快照恢复文件改动,逐个文件「保留/撤销」,不依赖 git。
|
|
84
84
|
- **输入安全网** — 长 prompt 不再怕误按 Enter:`Ctrl+G` 弹出 TUI 内「输入面板」(记事本式编辑,Enter=换行、软换行、选区、复制/剪切/粘贴、撤销,Ctrl+S 填回输入框不自动发送);`Ctrl+R`/`Ctrl+P` 模糊搜索历史输入(Enter 只回填不发送);长文本误发后撤回窗口自动放宽到 2 秒且任意键可撤回。
|
|
85
85
|
- **沙箱防护** — 文件读写经沙箱拦截,挡掉越界路径(`../../`、绝对外圈、软链出圈等),不碰工作目录之外的文件。
|
|
86
|
+
- **Computer Use(高危,仅明确 GUI 意图时路由)** — 请求确实需要真实鼠标/键盘交互时,router 才可暴露 `computer-control`,并把每次动作后的截图回灌模型。`/cu off`(或 `MOCODE_COMPUTER_USE_ENABLED=false`)是硬否决;`/cu on` 仅允许按需路由,不会让工具常驻。它会绕过文件沙箱,**强烈建议只在 VM / 沙箱 / 专用测试机里使用**。每个动作仍走权限门,plan 模式永远屏蔽。Windows 首发,macOS/Linux 待接入。
|
|
86
87
|
|
|
87
88
|
## 特性
|
|
88
89
|
|
|
@@ -147,10 +148,10 @@ LLM_MODEL=glm-4.6 # 换成你的模型名
|
|
|
147
148
|
|
|
148
149
|
常见后端 `base_url`:
|
|
149
150
|
|
|
150
|
-
| 后端 |
|
|
151
|
-
|
|
|
151
|
+
| 后端 | base_url |
|
|
152
|
+
| ----------- | --------------------------------------------------- |
|
|
152
153
|
| GLM(智谱) | `https://open.bigmodel.cn/api/v3` |
|
|
153
|
-
| DeepSeek
|
|
154
|
+
| DeepSeek | `https://api.deepseek.com` |
|
|
154
155
|
| Qwen(阿里) | `https://dashscope.aliyuncs.com/compatible-mode/v1` |
|
|
155
156
|
| 本地 Ollama | `http://localhost:11434/v1` |
|
|
156
157
|
| 本地 vLLM | `http://localhost:8000/v1` |
|
|
@@ -159,24 +160,28 @@ LLM_MODEL=glm-4.6 # 换成你的模型名
|
|
|
159
160
|
|
|
160
161
|
### 可选配置
|
|
161
162
|
|
|
162
|
-
| 环境变量
|
|
163
|
-
|
|
|
164
|
-
| `MAX_TOKENS`
|
|
165
|
-
| `CONTEXT_WINDOW_TOKENS`
|
|
166
|
-
| `LLM_STREAM_USAGE`
|
|
167
|
-
| `AUTO_COMPACT`
|
|
168
|
-
| `AUTO_REFLECT`
|
|
169
|
-
| `REFLECT_EVERY_N`
|
|
170
|
-
| `ANYSEARCH_API_KEY`
|
|
171
|
-
| `ANYSEARCH_BASE_URL`
|
|
172
|
-
| `SKILLS_DIRS`
|
|
173
|
-
| `MOCODE_CONTEXT_OPTIMIZE`
|
|
174
|
-
| `MOCODE_CONTEXT_RELPRUNE`
|
|
175
|
-
| `MOCODE_LIFECYCLE`
|
|
176
|
-
| `MAX_STEPS`
|
|
177
|
-
| `SUB_AGENT_MAX_STEPS`
|
|
178
|
-
| `SANDBOX_ROOT`
|
|
179
|
-
| `
|
|
163
|
+
| 环境变量 | 说明 | 默认值 |
|
|
164
|
+
| ------------------------------- | ---------------------------------------------------------------------------- | --------------------------- |
|
|
165
|
+
| `MAX_TOKENS` | 单次回复最大 token | 不限 |
|
|
166
|
+
| `CONTEXT_WINDOW_TOKENS` | 模型上下文窗口,须对齐真实模型 | `256000` |
|
|
167
|
+
| `LLM_STREAM_USAGE` | 流式请求带 `stream_options.include_usage` 拿真实用量 | `true` |
|
|
168
|
+
| `AUTO_COMPACT` | 最终 history compact 安全保护 | `true` |
|
|
169
|
+
| `AUTO_REFLECT` | 后台反思 pass(默认关闭,需要时显式开启) | `false` |
|
|
170
|
+
| `REFLECT_EVERY_N` | 每 N 轮触发一次后台反思(与 agent 并发,不阻塞) | `5` |
|
|
171
|
+
| `ANYSEARCH_API_KEY` | 联网搜索 API key(不配走匿名免费额度) | 无 |
|
|
172
|
+
| `ANYSEARCH_BASE_URL` | 搜索 API 端点 | `https://api.anysearch.com` |
|
|
173
|
+
| `SKILLS_DIRS` | 覆盖默认 skill 扫描目录(平台分隔符) | 三目录自动扫描 |
|
|
174
|
+
| `MOCODE_CONTEXT_OPTIMIZE` | 仅在真实 pressure 下编码 Cold 日志/搜索(显式开启) | `false` |
|
|
175
|
+
| `MOCODE_CONTEXT_RELPRUNE` | 仅在真实 pressure 下裁剪精确 superseded 证据(显式开启) | `false` |
|
|
176
|
+
| `MOCODE_LIFECYCLE` | 只维护 provenance 元数据,不按次数改写正文 | `true` |
|
|
177
|
+
| `MAX_STEPS` | 每轮 Agent 循环最大步数(仅防无限循环) | `1000` |
|
|
178
|
+
| `SUB_AGENT_MAX_STEPS` | 子 Agent 循环安全上限,默认与主 Agent 一致 | `1000` |
|
|
179
|
+
| `SANDBOX_ROOT` | 沙箱根目录(文件操作边界;未配则用 cwd 兜底) | 无 |
|
|
180
|
+
| `MOCODE_SUBAGENT_ENABLED` | 设 `false` 硬禁用 `orchestration`;unset/`true` 允许按需路由 | 未设置 |
|
|
181
|
+
| `MOCODE_FRONTEND_TOOLS_ENABLED` | 设 `false` 硬禁用 `browser-debug` / `desktop-observe`;unset/`true` 允许路由 | 未设置 |
|
|
182
|
+
| `MOCODE_COMPUTER_USE_ENABLED` | 设 `false` 硬禁用高危 `computer-control`;unset/`true` 允许明确意图时路由 | 未设置 |
|
|
183
|
+
| `MEMORY_ENABLED` | 设 `false` 硬禁用 memory 簇;`true` 还会启用 Memory Index | 未设置 |
|
|
184
|
+
| `MOCODE_THEME` | 颜色主题(default/dark/light…;shell 设置优先于文件) | `default` |
|
|
180
185
|
|
|
181
186
|
## 运行
|
|
182
187
|
|
|
@@ -195,32 +200,33 @@ agent 工作在**启动时所在的工作目录**——想让它操作某个项
|
|
|
195
200
|
|
|
196
201
|
## 工具
|
|
197
202
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
|
201
|
-
|
|
|
202
|
-
| `
|
|
203
|
-
| `
|
|
204
|
-
| `
|
|
205
|
-
| `
|
|
206
|
-
| `
|
|
207
|
-
| `
|
|
208
|
-
| `
|
|
209
|
-
| `
|
|
210
|
-
| `
|
|
211
|
-
| `
|
|
212
|
-
| `
|
|
213
|
-
| `
|
|
214
|
-
| `
|
|
215
|
-
| `
|
|
216
|
-
| `
|
|
217
|
-
| `
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
| `
|
|
221
|
-
| `
|
|
222
|
-
| `
|
|
223
|
-
| `
|
|
203
|
+
每个真实用户轮都会先经过受约束的 LLM router。十个公共工具始终可用(`read_file`、`view_image`、`glob`、`grep`、`web_search`、`web_fetch`、`plan_update`、`note_append`、`ask_human`、`use_skill`);写文件、shell 调试、浏览器调试、桌面观察/控制、记忆、编排和 MCP 作为可组合工具簇按需选择。初始能力不足时,主模型必须单独调用 `add_tool_groups`,新增 schema 从下一 step 生效。路由失败只继承上一轮工具簇(或仅公共工具),绝不回退到全工具。
|
|
204
|
+
|
|
205
|
+
| 工具 | 作用 |
|
|
206
|
+
| ------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
207
|
+
| `read_file` | 读文本文件,带行号,支持 `offset` / `limit` |
|
|
208
|
+
| `view_image` | 读取已有 PNG/JPEG/GIF/WebP 图片并作为视觉输入回灌模型(最大 4 MiB) |
|
|
209
|
+
| `screenshot` | 经用户确认后截取主显示器或整个桌面,保存 PNG 并立即交给视觉模型分析 |
|
|
210
|
+
| `write_file` | 创建/覆盖文件,自动建父目录 |
|
|
211
|
+
| `edit_file` | 精确字符串替换(`old_string` 须唯一匹配) |
|
|
212
|
+
| `run_command` | 执行 shell 命令,合并 stdout+stderr,默认 120s 超时 |
|
|
213
|
+
| `dev_server` | 启动/查看/读日志/停止常驻后台进程(dev server),跨工具调用存活 |
|
|
214
|
+
| `browser` | Playwright 驱动真实 Chromium:导航 / 点击 / 填表 / 取文本 / 截图 / 控制台诊断 |
|
|
215
|
+
| `glob` | 按 glob 模式找文件(排除 node_modules/.git) |
|
|
216
|
+
| `grep` | 内容正则搜索,纯 JS 实现,不依赖 `rg` |
|
|
217
|
+
| `codegraph` | 已建 `.codegraph/` 索引时,查代码符号源码与调用链(比 read_file/grep 更准更省) |
|
|
218
|
+
| `web_search` | 联网搜索(AnySearch),返回标题/URL/摘要/正文 |
|
|
219
|
+
| `web_fetch` | 抓取指定 URL,HTML 清洗成纯文本 |
|
|
220
|
+
| `use_skill` | 加载某 skill 的完整 SKILL.md 指令 |
|
|
221
|
+
| `ask_human` | 决策点弹终端问答面板,用户选预设项或自由输入(阻塞至回应) |
|
|
222
|
+
| `plan_update` | 记录/更新会话执行计划(notes.md 的 `## Plan:` 段);三态步骤机,同一时刻至多一个 in_progress,全部完成自动结算为 `## Done:` |
|
|
223
|
+
| `sub-agent` | 派生工具权限不超过父级 snapshot 的隔离子 Agent;只读任务可并发,写任务通过 overlay + ChangeSet 安全合并 |
|
|
224
|
+
|
|
225
|
+
| `memory_save` | 存一条跨会话长期记忆(标题进索引,正文按需取) |
|
|
226
|
+
| `memory_search` | 按关键词搜记忆正文,命中即提升召回计数(影响遗忘衰减) |
|
|
227
|
+
| `memory_list` | 列记忆索引(id/标题/摘要,无正文) |
|
|
228
|
+
| `memory_update` | 原地改一条记忆(id 不变;纠正过时事实 / 改摘要 / 改 pin) |
|
|
229
|
+
| `memory_forget` | 遗忘记忆:默认归档(可复活),`mode=delete` 硬删(pinned 拒删) |
|
|
224
230
|
|
|
225
231
|
### 前端 / UI 闭环
|
|
226
232
|
|
|
@@ -238,34 +244,36 @@ dev_server stop id=srv-xxxx
|
|
|
238
244
|
- 两者在 plan 模式下均被禁用;mocode 退出时会树杀后台进程并关闭浏览器。
|
|
239
245
|
- 浏览器二进制不随 npm 包分发,首次使用前需 `npx playwright install chromium`。
|
|
240
246
|
|
|
241
|
-
|
|
247
|
+
前端能力按用途拆分:`browser` + `dev_server` 属于 `browser-debug`,整桌面截图 `screenshot` 属于 `desktop-observe`,`view_image` 则始终是公共只读工具。任务同时需要结构化网页诊断与真实桌面交互时,router 可再组合 `computer-control`。`/fe off` 是硬否决,不是手动 profile 选择器。
|
|
242
248
|
|
|
243
|
-
|
|
249
|
+
6 个 `memory_*` 工具拆成 `memory-read` 与 `memory-write`。只有 router 选择对应簇时才出现;`MEMORY_ENABLED=false` 会硬禁用两簇,`true` 还会把紧凑 Memory Index 注入 prompt。`/memory_switch` 同时管理这个兼容 gate 与 Index 状态。
|
|
244
250
|
|
|
245
251
|
## 斜杠命令
|
|
246
252
|
|
|
247
|
-
| 命令
|
|
248
|
-
|
|
|
249
|
-
| `/exit` `/quit`
|
|
250
|
-
| `/clear`
|
|
251
|
-
| `/image`
|
|
252
|
-
| `/context`
|
|
253
|
-
| `/skills`
|
|
254
|
-
| `/compact`
|
|
255
|
-
| `/resume`
|
|
256
|
-
| `/rollback`
|
|
257
|
-
| `/memory`
|
|
258
|
-
| `/memory_switch` |
|
|
259
|
-
| `/reflect`
|
|
260
|
-
| `/model`
|
|
261
|
-
| `/init`
|
|
262
|
-
| `/theme`
|
|
263
|
-
| `/plan`
|
|
264
|
-
| `/auto`
|
|
265
|
-
| `/pet`
|
|
266
|
-
| `/fe`
|
|
267
|
-
| `/
|
|
268
|
-
| `/
|
|
253
|
+
| 命令 | 作用 |
|
|
254
|
+
| ---------------- | ------------------------------------------------------------------- |
|
|
255
|
+
| `/exit` `/quit` | 退出 mocode |
|
|
256
|
+
| `/clear` | 清空历史(保留系统提示)+ 清屏 |
|
|
257
|
+
| `/image` | 附加本地图片到下一条消息;支持 `list` / `clear` |
|
|
258
|
+
| `/context` | 显示上下文用量条(token / 消息数 / 估算或实测) |
|
|
259
|
+
| `/skills` | 列出已发现的 skill |
|
|
260
|
+
| `/compact` | 压缩历史(可带焦点 `/compact …`) |
|
|
261
|
+
| `/resume` | 续接已保存的会话 |
|
|
262
|
+
| `/rollback` | 菜单选轮次回滚(↑↓ · Enter) |
|
|
263
|
+
| `/memory` | 看记忆库:条目数 + 近期索引 |
|
|
264
|
+
| `/memory_switch` | 允许/禁止 memory 自动路由并切换 Memory Index;下一真实用户轮生效 |
|
|
265
|
+
| `/reflect` | 手动触发一次后台记忆反思 pass |
|
|
266
|
+
| `/model` | 配置大模型(baseURL / apiKey / model / 上下文窗口),即时生效 + 持久化 |
|
|
267
|
+
| `/init` | 扫描项目生成 `AGENTS.md` 项目记忆(发给 agent 执行) |
|
|
268
|
+
| `/theme` | 切换颜色主题(↑↓ · Enter,或 `/theme <name>` 直切) |
|
|
269
|
+
| `/plan` | 切到 plan 模式(只读探查 + 产出计划,审批后切 auto 执行) |
|
|
270
|
+
| `/auto` | 切回可执行模式;工具按任务自动路由 |
|
|
271
|
+
| `/pet` | 开关桌宠(独立悬浮窗,镜像 agent 状态动画) |
|
|
272
|
+
| `/fe` | 允许/禁止自动路由 `browser-debug` 与 `desktop-observe` |
|
|
273
|
+
| `/cu` | 允许/禁止自动路由高危 `computer-control` |
|
|
274
|
+
| `/subagent` | 允许/禁止自动路由 `orchestration` |
|
|
275
|
+
| `/pet skin` | 选桌宠皮肤(↑↓ · Enter) |
|
|
276
|
+
| `/pet quit` | 完全关闭桌宠进程(而非仅断开本连接) |
|
|
269
277
|
|
|
270
278
|
输入 `/` 触发下拉菜单,继续打字过滤;Esc 取消。
|
|
271
279
|
|
|
@@ -302,7 +310,7 @@ system prompt 提供轻量建议而不是框架硬门:只检查支持下一步
|
|
|
302
310
|
mocode 的**双层记忆**模型,跟 Skills 是两件事:
|
|
303
311
|
|
|
304
312
|
- **Tier-1 — `AGENTS.md`(每轮自动加载):** Markdown 项目记忆,每轮拼进 system prompt。发现路径:`~/.mocode/AGENTS.md` → 从 cwd 往上逐级 `AGENTS.md`(远→近拼接,近的覆盖更突出);超长截断并标注原始文件。运行 `/init` 生成或刷新,纯 Markdown,可手写,无 schema。agent 自己推得的「下次要记住的事实」(架构/约定/坑位)也写在这里。
|
|
305
|
-
- **Tier-2 — `memory_*` 工具库(agent
|
|
313
|
+
- **Tier-2 — `memory_*` 工具库(agent 主导,按需路由):** 离散带标签条目(`decision` / `fact` / `pitfall` / `reference` / `feedback`),按召回计数衰减(30 天 → archived,90 天 → 硬删 GC)。agent 用 `memory-read` 召回,用 `memory-write` 处理明确的持久化意图;保存前先搜索,已有条目优先更新而非重复创建。`MEMORY_ENABLED=false` 会硬禁用两簇,`true` 还会注入紧凑 Memory Index;可在 REPL 内用 `/memory_switch` 管理。
|
|
306
314
|
|
|
307
315
|
## 类型检查
|
|
308
316
|
|