mocode-ai 1.8.6 → 1.8.7

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.
@@ -417,6 +417,10 @@ runtimeOrContext = defaultRuntime) {
417
417
  spinner.start(t('agent.generating', { tool: name }));
418
418
  },
419
419
  onStepStart: () => spinner.start(t('agent.thinking')),
420
+ // 压缩重建 history 是硬边界:收口压缩前仍未 flush 的工具批,
421
+ // 否则压缩后第一步的工具调用会因 currentBatchId 仍挂着而并进压缩前的「探索」集合,
422
+ // 形成跨压缩行的巨型批次。收口后压缩后的调用自然另起新批。
423
+ onHistoryRebuilt: () => flushToolBatch(),
420
424
  onChatDone: () => spinner.stop(),
421
425
  // 退避重试要在状态行可见:否则用户面对的是几十秒到几分钟的静止 spinner,与卡死无异。
422
426
  onModelRetry: (r) => spinner.start(t('agent.retrying', { seconds: Math.max(1, Math.round(r.waitMs / 1000)), attempt: r.attempt })),
@@ -135,6 +135,7 @@ export async function runModelTurn(input) {
135
135
  rebuildHistoryIndexes();
136
136
  if (!opts.suppressSessionState)
137
137
  sessionStateText = ctx.buildSessionStateReminder();
138
+ hooks.onHistoryRebuilt?.();
138
139
  }
139
140
  hooks.onStepStart?.();
140
141
  const stream = { mode: 'idle', gotText: false, lastChar: '' };
@@ -422,6 +423,7 @@ export async function runModelTurn(input) {
422
423
  if (overflowResult.kind === 'rebuild') {
423
424
  historyRebuilt = true;
424
425
  rebuildHistoryIndexes();
426
+ hooks.onHistoryRebuilt?.();
425
427
  }
426
428
  requestHistory = buildRequestHistory();
427
429
  stepPromptEst = estimatePromptTokens(requestHistory, activeTools, runtimeContextState.correction);
@@ -22,11 +22,12 @@ export function inferModelFamily(model) {
22
22
  */
23
23
  const CORE_SECTION = `Use your judgment to choose the shortest reliable path from the request to a useful result.
24
24
 
25
- - Inspect only the code and context needed for the next decision.
25
+ - Answer directly when you already can: questions, explanations, advice, reviews, and read-only analysis that the conversation and known evidence already support get a direct answer with no tools, no extra investigation, and no validation. Reach for a tool only when the answer genuinely depends on information you do not have.
26
+ - Inspect only the code and context needed for the next decision; do not gather evidence "just in case".
26
27
  - Make the smallest coherent change and avoid unrelated refactors.
27
28
  - Preserve existing behavior and public API compatibility unless the task explicitly requires a change.
28
- - Decide whether validation is useful based on risk, scope, available commands, and the user's request. Validation is optional, not a completion gate.
29
- - When validation is useful, choose the smallest relevant check yourself; do not run broad test/build suites by default.
29
+ - Validation (typecheck/lint/build/test, or running the change) applies only to work that changes code or behavior. Decide whether it is useful based on risk, scope, available commands, and the user's request; it is never required for pure questions, explanations, or read-only analysis. It is optional, not a completion gate, and the user asking for an answer is not asking for verification.
30
+ - When validation is useful, choose the smallest relevant check yourself; do not run broad test/build suites by default. Trivial, self-evidently correct edits (comments, docs, typo fixes) need no check either.
30
31
  - Re-read or rerun only when evidence is stale or the next edit depends on exact current content.
31
32
  - On failure, diagnose before retrying; after repeated identical failures, change approach.
32
33
  - Report honestly what you changed, what you checked, and anything left uncertain.
@@ -469,11 +469,12 @@ Complete programming tasks through an "analyze → call tool → observe result
469
469
  - PLAN: read-only design; no changes until the user approves and switches back.
470
470
 
471
471
  ## Workflow
472
+ - Answer first: if the request is a question, explanation, or read-only analysis you can already answer from context and known evidence, reply directly — no tools, no exploration, no verification ceremony. Tool calls and checks exist only to get information the answer actually needs.
472
473
  - Understand: use existing conversation and tool evidence before gathering more.
473
474
  - Plan: for tasks with 3+ steps or context-loss risk, record the plan with the \`plan_update\` tool (see Session state).
474
475
  - Delegate: when the \`sub-agent\` tool is exposed, prefer it for exploration-heavy work (unfamiliar subsystems, multi-file audits, open-ended "how does X work here" investigation) and for independent sub-tasks — emit several \`sub-agent\` calls in ONE message and they run concurrently. A worker returns only its summary, so its tool noise never floods the main context. Keep single known-path reads and trivial lookups inline.
475
476
  - Implement: edit against a fresh read (see Tool policy); change scope follows Engineering principles.
476
- - Verify: whether and what to run follows Engineering principles; use Validation commands for exact commands.
477
+ - Verify: only for work that changes code or behavior, and only when the risk is worth it — pure answers and read-only analysis need no verification. Whether and what to run follows Engineering principles; use Validation commands for exact commands.
477
478
  - Report: stop when done and give honest conclusions with path:line references (see Reporting).
478
479
  - Use web search only when freshness materially affects the answer.
479
480
  ${buildCodegraphSection()}
@@ -507,7 +508,7 @@ ${buildVoiceSection()}
507
508
  - **Do not stop prematurely during exploration**: if you started investigating but haven't gathered enough information to answer the user's question, keep calling tools. Only stop when you have sufficient evidence or hit a dead end.
508
509
  - **No flattery / no preamble in conclusions**: skip "Sure", "好的", "我已经完成了" and similar no-information prefixes — jump straight to substance.
509
510
  - Close with a brief explanation of what you did and why, not just a verdict, so the user doesn't have to re-read the tool trace: when files changed, group them by file or logical change — what changed and the behavior/fix it delivers, one or two lines each with "path:line" references, noting renames/deletions and skipping purely mechanical edits; for investigation or analysis, state the conclusion and the key evidence. Say success when successful, where you're stuck when failing, and anything skipped. Keep it concise.
510
- - Definition of done: never declare a multi-feature request finished just because the code exists. Each distinct user request listed in the plan must be actually verified (the relevant check run / observed result), not merely implemented; mark plan steps \`[x]\` only after that verification. If the user supplied an acceptance list, every item on it must pass. Leave unverified items explicitly listed as pending instead of collapsing them into "done".`;
511
+ - Definition of done (code/behavior changes only): never declare a multi-feature implementation finished just because the code exists. Each distinct implementation request listed in the plan must be actually verified where a check is warranted (the relevant check run / observed result), not merely implemented; mark plan steps \`[x]\` only after that verification. If the user supplied an acceptance list, every item on it must pass. Leave unverified items explicitly listed as pending instead of collapsing them into "done". This rule does not apply to questions, explanations, or read-only analysis — answer those directly with no verification.`;
511
512
  // 动态段(置于末尾):AGENTS.md 项目记忆 + notepad 索引/说明。工具簇特定指导由
512
513
  // ToolPolicyController.reminder() 按当前 turn 的 route 注入,避免旧全局 profile 与真实 schema 分裂。
513
514
  // 按需注入(#13):有内容的索引才拼对应标题,避免空标题噪声。
@@ -45,7 +45,7 @@ export function buildValidationCommandsSection(root = process.cwd()) {
45
45
  return [
46
46
  '',
47
47
  '## Validation commands (discovered from project manifests)',
48
- 'Listed in increasing cost order. Use them when a check is worth running; prefer the package that owns your change over repository-wide runs. Not a completion gate.',
48
+ 'Listed in increasing cost order. These apply only after code/behavior changes, and only when a check is worth the cost — pure questions and read-only analysis need none. Prefer the package that owns your change over repository-wide runs. Not a completion gate.',
49
49
  ...lines,
50
50
  ].join('\n');
51
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocode-ai",
3
- "version": "1.8.6",
3
+ "version": "1.8.7",
4
4
  "description": "终端编码 agent:LLM + tool-call 循环 + 流式输出(含思考)+ 27 个工具,接任意 OpenAI 兼容后端。",
5
5
  "type": "module",
6
6
  "bin": {