mocode-ai 1.10.0 → 1.11.0

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.
Files changed (59) hide show
  1. package/dist/agent/index.js +18 -7
  2. package/dist/agent/mentioned-files.js +71 -0
  3. package/dist/agent/model-turn.js +68 -30
  4. package/dist/agent/progress-guard.js +67 -0
  5. package/dist/agent/run-coordinator.js +155 -24
  6. package/dist/agent/short-path-completion.js +109 -0
  7. package/dist/agent/spawn.js +43 -0
  8. package/dist/agent/stages/history-manager.js +1 -0
  9. package/dist/agent/stages/tool-dispatcher.js +6 -3
  10. package/dist/agent/tool-helpers.js +2 -2
  11. package/dist/agent/tool-turn.js +49 -4
  12. package/dist/agent/work-discipline.js +12 -9
  13. package/dist/changeset/index.js +2 -1
  14. package/dist/config/index.js +12 -10
  15. package/dist/context/overlapping-reads.js +66 -0
  16. package/dist/context/relevance.js +11 -2
  17. package/dist/context/usage-snapshot.js +9 -6
  18. package/dist/host/stdio.js +96 -42
  19. package/dist/i18n/index.js +26 -10
  20. package/dist/llm/index.js +27 -3
  21. package/dist/llm/message-shape.js +18 -0
  22. package/dist/llm/reasoning.js +17 -0
  23. package/dist/memory/index.js +1 -1
  24. package/dist/memory/tail.js +9 -26
  25. package/dist/models/reasoning-cap.js +19 -2
  26. package/dist/orchestrator/lane-executor.js +7 -1
  27. package/dist/orchestrator/repl.js +30 -49
  28. package/dist/repl/commands/appearance.js +1 -2
  29. package/dist/repl/commands/compact.js +4 -0
  30. package/dist/repl/commands/model-actions.js +4 -3
  31. package/dist/repl/commands/model.js +2 -3
  32. package/dist/repl/message-format.js +7 -6
  33. package/dist/repl/running-input.js +27 -65
  34. package/dist/repl/runtime.js +119 -77
  35. package/dist/rollback/index.js +2 -2
  36. package/dist/rollback/store.js +73 -38
  37. package/dist/runtime/runtime.js +1 -1
  38. package/dist/session/compact.js +41 -4
  39. package/dist/session/retention.js +4 -0
  40. package/dist/session/short-path-metrics.js +185 -0
  41. package/dist/session/store.js +78 -3
  42. package/dist/session/terminal-transcript.js +101 -0
  43. package/dist/tools/builtins/ask-human.js +2 -2
  44. package/dist/tools/builtins/edit-file.js +79 -19
  45. package/dist/tools/builtins/grep.js +161 -42
  46. package/dist/tools/builtins/plan-update.js +4 -2
  47. package/dist/tools/builtins/read-file.js +148 -55
  48. package/dist/tools/builtins/run-command.js +57 -9
  49. package/dist/tools/ripgrep-client.js +72 -26
  50. package/dist/tools/tool-runtime.js +29 -8
  51. package/dist/ui/layout-internal/content-write.js +7 -3
  52. package/dist/ui/layout-internal/core.js +1 -1
  53. package/dist/ui/layout-internal/state.js +0 -6
  54. package/dist/ui/layout-internal/statusbar.js +0 -30
  55. package/dist/ui/output-sink.js +24 -0
  56. package/dist/ui/render.js +3 -0
  57. package/dist/ui/spinner.js +3 -1
  58. package/dist/verification/evidence.js +52 -0
  59. package/package.json +4 -2
@@ -7,6 +7,7 @@ import * as content from '../content.js';
7
7
  import { reset as resetBatches, shiftBatchesAfter, shiftBatchesForReflow } from '../batch.js';
8
8
  import { renderMarkdownWithMeta } from '../markdown.js';
9
9
  import { state } from './state.js';
10
+ import { isStdoutMuted } from '../output-sink.js';
10
11
  import { esc, cup, getGeo, setRegion, runningCaretPos } from './screen.js';
11
12
  import { viewportAbsStart, repaintViewport } from './scroll.js';
12
13
  // ── 流式 markdown 渲染节流(2026-10-05)──
@@ -57,7 +58,8 @@ export function shouldRenderMdSegment(elapsedNow, pendingChars) {
57
58
  */
58
59
  export function contentWrite(s) {
59
60
  if (!state.active || !ui.isTTY) {
60
- stdout.write(s);
61
+ if (!isStdoutMuted())
62
+ stdout.write(s);
61
63
  return;
62
64
  }
63
65
  if (state.mdActive)
@@ -373,7 +375,8 @@ export function flushMdSegment() {
373
375
  */
374
376
  export function contentWriteMd(s) {
375
377
  if (!state.active || !ui.isTTY) {
376
- stdout.write(s);
378
+ if (!isStdoutMuted())
379
+ stdout.write(s);
377
380
  return;
378
381
  }
379
382
  if (!state.mdActive)
@@ -403,7 +406,8 @@ export function contentWriteMd(s) {
403
406
  */
404
407
  export function contentWriteMdOnce(s) {
405
408
  if (!state.active || !ui.isTTY) {
406
- stdout.write(s);
409
+ if (!isStdoutMuted())
410
+ stdout.write(s);
407
411
  return;
408
412
  }
409
413
  if (state.mdActive)
@@ -30,7 +30,7 @@ import { paintInput, repaint } from './input-paint.js';
30
30
  import { WHEEL_LINES, screenRowToAbsLine, repaintViewport, scrollBy, scrollWheel, resetScroll, lockScrollToBottom, } from './scroll.js';
31
31
  import { contentWrite, contentInsertAfter, contentDeleteFrom, contentReplaceLine, reflowContentForResize, flushMdSegment, } from './content-write.js';
32
32
  export { isTuiActive, getGeo, getEffectiveContentBottom, setRegion, contentMode, isStreamingPaused } from './screen.js';
33
- export { drawStatusBar, setStatus, stopTurnTimer, startTurnTimerIfRunning, paintLiveAtCursor, clearLiveAtCursor, setLiveUsage, setQueuedTurn, setStatusBase, setPendingAttachChips, togglePlanExpanded, togglePlanDetail, } from './statusbar.js';
33
+ export { drawStatusBar, setStatus, stopTurnTimer, startTurnTimerIfRunning, paintLiveAtCursor, clearLiveAtCursor, setLiveUsage, setStatusBase, setPendingAttachChips, togglePlanExpanded, togglePlanDetail, } from './statusbar.js';
34
34
  export { paintInput, paintRunningInput, repaint } from './input-paint.js';
35
35
  export { isScrolled, repaintViewport, repaintContentLine, scrollBy, scrollWheel, resetScroll, setMenuReserve, lockScrollToBottom, unlockScroll, isScrollLocked, } from './scroll.js';
36
36
  export { contentWrite, writeBanner, rewriteBanner, bannerHeight, contentWriteMd, contentWriteMdOnce, clearContent, rewindContent, writeWelcomeBlock, dismissWelcomeBlock, contentInsertAfter, contentDeleteFrom, totalRows, isLastContentRowBlank, normalizeMutationBoundary, normalizeInputBoundary, contentReplaceLine, notifyContentReset, } from './content-write.js';
@@ -69,12 +69,6 @@ export const state = {
69
69
  * composeModelLine 在 RUNNING 态把它画成 chip 放 context 进度条左侧;
70
70
  * 不主动触发重画——RUNNING 态 turnTimer 80ms 心跳重画自然取最新值。 */
71
71
  liveUsage: undefined,
72
- /** 运行态已排队消息:队首(第一条/下一条待自动发送)纯文本预览,无=undefined。 */
73
- queuedText: undefined,
74
- /** 队首排队消息入队时的模式,用于在 chip 上标注 Plan/Auto。 */
75
- queuedMode: undefined,
76
- /** 排队剩余条数(>=1);1 = 单条不显示计数,>1 在 chip 上显示「×N」。 */
77
- queuedCount: 1,
78
72
  statusText: '',
79
73
  spinnerFrame: undefined,
80
74
  turnStart: null, // RUNNING 态起点(Date.now());INPUT 态为 null。composeStatus 据此拼走时。
@@ -64,12 +64,6 @@ export function composeSpinnerLine(status, cols) {
64
64
  lead = `${ui.accent}●${ui.reset} ${ui.dim}${status.status}${ui.reset}`;
65
65
  leadW = 1 + 1 + displayWidth(status.status);
66
66
  }
67
- // 排队下一跳:紧跟「● 状态(+走时)」右侧显示,运行中持续可见,当前任务结束即自动发送。
68
- const queued = queuedChip();
69
- if (queued) {
70
- lead += ` ${queued.str}`;
71
- leadW += 2 + queued.w;
72
- }
73
67
  // ── 右段:仅滚动回看时显历史指示 ──
74
68
  let tail = '';
75
69
  let tailW = 0;
@@ -577,30 +571,6 @@ export function clearLiveAtCursor() {
577
571
  export function setLiveUsage(u) {
578
572
  state.liveUsage = u;
579
573
  }
580
- /**
581
- * 设置/清除运行态已排队消息 chip(显示在 `● 状态` 右侧)。
582
- * text = 队首(第一条/下一条待自动发送)预览,多条排队时保持展示第一条不变;
583
- * count = 排队总条数(>1 显示「×N」)。立即重画一次保证入队瞬间可见;之后 80ms 心跳会自然带上。
584
- */
585
- export function setQueuedTurn(text, mode, count = 1) {
586
- state.queuedText = text;
587
- state.queuedMode = mode;
588
- state.queuedCount = count;
589
- drawStatusBar();
590
- }
591
- /** 排队 chip:▸ 排队[ ×N] · <第一条首行…>(Plan)。只拼左段,宽度另计(不含 ANSI)。 */
592
- function queuedChip() {
593
- const raw = state.queuedText;
594
- if (!raw)
595
- return null;
596
- const firstLine = raw.split('\n')[0] ?? '';
597
- const preview = truncateDisplay(firstLine.trim(), 32);
598
- const modeTag = state.queuedMode === 'plan' ? t('status.queuePlanTag') : '';
599
- const label = state.queuedCount > 1 ? t('status.queuedCount', { count: state.queuedCount }) : t('status.queued');
600
- const plain = `${label} ${preview}${modeTag}`;
601
- const str = `${ui.yellow}▸ ${plain}${ui.reset}`;
602
- return { str, w: 2 + displayWidth(plain) };
603
- }
604
574
  /** 更新状态行基线(模型 / context / cwd / 模式标识 / 活跃 plan chip / 本轮 token chip)。repl 在轮次边界与切模式时调。 */
605
575
  export function setStatusBase(b) {
606
576
  state.base = b;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 非 TTY 输出闸门。
3
+ *
4
+ * `layout.contentWrite` / `Spinner` 在「布局没激活」时的兜底是直接 `stdout.write`——
5
+ * 这是 REPL 在管道 / 重定向下仍能看到正文的保证。但 stdio host(work-app 的 agent 子进程)
6
+ * 的 stdout 是 NDJSON 协议通道,裸文本进去就是**协议污染**:客户端 JSON.parse 失败 →
7
+ * 当成 diagnostic → 用户什么都看不到(压缩行、图片卡片行、压缩 spinner 全在这里丢掉)。
8
+ *
9
+ * 所以 host 启动时把闸门关掉:兜底写被丢弃,真正的用户可见反馈改由 NDJSON 事件承载
10
+ * (`context_compacted` / `image_relief` …)。REPL / headless 从不调 mute,行为零变化。
11
+ */
12
+ let muted = false;
13
+ /** 关闭「非 TTY 直接写 stdout」的兜底。仅 stdio host 调用。 */
14
+ export function muteStdoutOutput() {
15
+ muted = true;
16
+ }
17
+ /** 兜底写是否已被关闭(宿主需要自己承担输出时返回 true)。 */
18
+ export function isStdoutMuted() {
19
+ return muted;
20
+ }
21
+ /** 测试用:复位闸门。 */
22
+ export function resetStdoutOutput() {
23
+ muted = false;
24
+ }
package/dist/ui/render.js CHANGED
@@ -579,6 +579,9 @@ export function summarizeToolResult(name, output) {
579
579
  // 「无匹配」结果不含任何文件头:必须显式识别,否则会被当成 1 处匹配(nonEmpty 只有 1 行)。
580
580
  if (!nonEmpty.length || nonEmpty[0].startsWith('无匹配'))
581
581
  return t('toolSummary.noMatches');
582
+ const paths = /^\[grep files=(\d+)\]$/.exec(nonEmpty[0]);
583
+ if (paths)
584
+ return t('toolSummary.files', { count: Number(paths[1]) });
582
585
  // 带 context 时 body 行数 ≠ 命中数(邻居行 + ` --` 分隔都在里面),
583
586
  // 按每文件头的真实命中数求和才对得上模型看到的「N 处匹配」。
584
587
  let matches = 0;
@@ -1,5 +1,6 @@
1
1
  import { stdout } from 'node:process';
2
2
  import { ui } from './theme.js';
3
+ import { isStdoutMuted } from './output-sink.js';
3
4
  const FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
4
5
  /**
5
6
  * 当前活跃 spinner:`start()` 的 TTY 路径登记,`stop()` 不清——供 `pauseCurrent()` 在介入面板
@@ -29,7 +30,8 @@ export class Spinner {
29
30
  this.stop();
30
31
  this.msg = msg;
31
32
  if (!ui.isTTY) {
32
- stdout.write(`${ui.dim}${msg}…${ui.reset}\n`);
33
+ if (!isStdoutMuted())
34
+ stdout.write(`${ui.dim}${msg}…${ui.reset}\n`);
33
35
  return;
34
36
  }
35
37
  activeSpinner = this; // TTY 路径:登记为当前可暂停 spinner(介入面板进入前 pauseCurrent 停转)
@@ -0,0 +1,52 @@
1
+ const VALIDATION_COMMAND = /^(?:(?:npm|pnpm|yarn|bun) (?:run )?(?:test|typecheck|lint|build)(?: --workspace [@\w./-]+)?|node --test(?: [\w./-]+)*|node (?:[\w./-]+\/)?verify[\w.-]*\.(?:[cm]?js))$/;
2
+ const PRESERVES_EVIDENCE = new Set(['read_file', 'grep', 'glob', 'plan_update', 'note_append']);
3
+ const MAX_CHECKS = 3;
4
+ /** Advisory evidence for one turn. Commands still execute normally if the agent requests a rerun. */
5
+ export function createVerificationEvidence() {
6
+ const passed = new Map();
7
+ let edited = false;
8
+ let pending = false;
9
+ const invalidate = () => {
10
+ passed.clear();
11
+ pending = false;
12
+ };
13
+ return {
14
+ invalidate,
15
+ observe(tool, args, outcome) {
16
+ if (outcome.changedFiles?.length || outcome.changeSet?.changes.length || outcome.staleFiles?.length) {
17
+ invalidate();
18
+ if (outcome.status === 'success' && (tool === 'edit_file' || tool === 'write_file'))
19
+ edited = true;
20
+ return;
21
+ }
22
+ if (!edited || PRESERVES_EVIDENCE.has(tool))
23
+ return;
24
+ const command = tool === 'run_command' && typeof args?.command === 'string' ? args.command.trim() : '';
25
+ if (command.length > 160 || !VALIDATION_COMMAND.test(command)) {
26
+ invalidate();
27
+ return;
28
+ }
29
+ const shell = typeof args?.shell === 'string' ? args.shell : '';
30
+ const key = JSON.stringify([command, shell]);
31
+ if (outcome.status !== 'success' || outcome.code !== 'OK') {
32
+ passed.delete(key);
33
+ return;
34
+ }
35
+ passed.delete(key);
36
+ passed.set(key, shell ? `${command} (shell: ${shell})` : command);
37
+ if (passed.size > MAX_CHECKS)
38
+ passed.delete(passed.keys().next().value);
39
+ pending = true;
40
+ },
41
+ takeReminder() {
42
+ if (!pending || !passed.size)
43
+ return;
44
+ pending = false;
45
+ return [
46
+ '## Validation evidence for the current edits',
47
+ ...[...passed.values()].map((command) => `- Passed: \`${command}\``),
48
+ 'If these checks cover the requested outcomes and their inputs and environment have not changed, use the results above and finish. Run any gaps, explicitly requested fresh checks, or checks invalidated by a change.',
49
+ ].join('\n');
50
+ },
51
+ };
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocode-ai",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "终端编码 agent:LLM + tool-call 循环 + 流式输出(含思考)+ 27 个工具,接任意 OpenAI 兼容后端。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -37,9 +37,11 @@
37
37
  "lint:fix": "eslint . --fix",
38
38
  "format": "prettier --write .",
39
39
  "format:check": "prettier --check .",
40
- "eval:smoke": "tsx evals/smoke.ts && tsx evals/coding/smoke.ts && tsx evals/quality-metrics.ts && tsx evals/work-discipline.ts",
40
+ "eval:smoke": "tsx evals/smoke.ts && tsx evals/coding/smoke.ts && tsx evals/short-path/smoke.ts && tsx evals/quality-metrics.ts && tsx evals/work-discipline.ts",
41
41
  "eval:coding": "tsx evals/coding/runner.ts",
42
42
  "eval:coding:list": "tsx evals/coding/runner.ts --list",
43
+ "eval:short": "tsx evals/short-path/runner.ts",
44
+ "eval:short:list": "tsx evals/short-path/runner.ts --list",
43
45
  "eval:memory-handoff": "tsx evals/memory-compact-handoff.ts",
44
46
  "eval:memory-retrieval": "tsx evals/memory-retrieval.ts",
45
47
  "eval:memory-retrieval:live": "tsx evals/memory-retrieval.ts --live",