mocode-ai 1.10.0 → 1.10.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.
Files changed (50) hide show
  1. package/dist/agent/index.js +13 -3
  2. package/dist/agent/mentioned-files.js +71 -0
  3. package/dist/agent/model-turn.js +55 -11
  4. package/dist/agent/progress-guard.js +67 -0
  5. package/dist/agent/run-coordinator.js +140 -12
  6. package/dist/agent/short-path-completion.js +109 -0
  7. package/dist/agent/spawn.js +39 -0
  8. package/dist/agent/stages/history-manager.js +1 -0
  9. package/dist/agent/tool-helpers.js +2 -2
  10. package/dist/agent/tool-turn.js +49 -4
  11. package/dist/agent/work-discipline.js +9 -9
  12. package/dist/config/index.js +13 -10
  13. package/dist/context/relevance.js +2 -1
  14. package/dist/host/stdio.js +88 -27
  15. package/dist/i18n/index.js +26 -10
  16. package/dist/llm/index.js +27 -3
  17. package/dist/llm/message-shape.js +18 -0
  18. package/dist/llm/reasoning.js +17 -0
  19. package/dist/models/reasoning-cap.js +19 -2
  20. package/dist/orchestrator/lane-executor.js +7 -1
  21. package/dist/orchestrator/repl.js +30 -49
  22. package/dist/repl/commands/appearance.js +1 -2
  23. package/dist/repl/commands/compact.js +4 -0
  24. package/dist/repl/commands/model-actions.js +4 -3
  25. package/dist/repl/commands/model.js +2 -3
  26. package/dist/repl/message-format.js +7 -6
  27. package/dist/repl/running-input.js +27 -65
  28. package/dist/repl/runtime.js +118 -76
  29. package/dist/rollback/store.js +36 -23
  30. package/dist/runtime/runtime.js +1 -1
  31. package/dist/session/compact.js +41 -4
  32. package/dist/session/retention.js +4 -0
  33. package/dist/session/short-path-metrics.js +185 -0
  34. package/dist/session/store.js +78 -3
  35. package/dist/session/terminal-transcript.js +101 -0
  36. package/dist/tools/builtins/ask-human.js +2 -2
  37. package/dist/tools/builtins/edit-file.js +28 -5
  38. package/dist/tools/builtins/grep.js +85 -35
  39. package/dist/tools/builtins/plan-update.js +4 -2
  40. package/dist/tools/builtins/read-file.js +95 -44
  41. package/dist/tools/builtins/run-command.js +57 -9
  42. package/dist/tools/ripgrep-client.js +31 -11
  43. package/dist/tools/tool-runtime.js +29 -8
  44. package/dist/ui/layout-internal/content-write.js +7 -3
  45. package/dist/ui/layout-internal/core.js +1 -1
  46. package/dist/ui/layout-internal/state.js +0 -6
  47. package/dist/ui/layout-internal/statusbar.js +0 -30
  48. package/dist/ui/output-sink.js +24 -0
  49. package/dist/ui/spinner.js +3 -1
  50. package/package.json +4 -2
@@ -330,11 +330,25 @@ export class ToolRuntime {
330
330
  async executeToolOnce(tool, args, signal, opts) {
331
331
  const startedAt = Date.now();
332
332
  const capabilities = this.getToolCapabilities(tool);
333
+ const commandStartedAt = tool.name === 'run_command' ? performance.now() : undefined;
334
+ const commandTiming = commandStartedAt === undefined ? undefined : { totalMs: 0 };
335
+ const captureWorkspace = async (phase, capture) => {
336
+ if (!commandTiming)
337
+ return capture();
338
+ const captureStartedAt = performance.now();
339
+ try {
340
+ return await capture();
341
+ }
342
+ finally {
343
+ commandTiming[phase] = performance.now() - captureStartedAt;
344
+ }
345
+ };
333
346
  let mutationVersionBefore;
334
347
  let capturedPath;
348
+ let outcome;
335
349
  try {
336
350
  const requests = this.dependencies.resolveResourceLockRequests(capabilities, args);
337
- return await this.dependencies.resourceLockManager.withLocks(requests, signal, async () => {
351
+ outcome = await this.dependencies.resourceLockManager.withLocks(requests, signal, async () => {
338
352
  opts?.onLockAcquired?.(args);
339
353
  const mutationBefore = this.dependencies.getCurrentTurnMutationState();
340
354
  mutationVersionBefore = mutationBefore.version;
@@ -346,7 +360,7 @@ export class ToolRuntime {
346
360
  : null;
347
361
  capturedPath = pathCapture?.path;
348
362
  const workspaceCapture = capabilities.effect === 'process' || capabilities.effect === 'unknown'
349
- ? await this.dependencies.beginWorkspaceMutation()
363
+ ? await captureWorkspace('workspaceBeforeMs', () => this.dependencies.beginWorkspaceMutation())
350
364
  : null;
351
365
  let raw;
352
366
  try {
@@ -358,12 +372,15 @@ export class ToolRuntime {
358
372
  delegation: opts?.delegation,
359
373
  readDedup: opts?.readDedup,
360
374
  });
375
+ if (commandTiming && isStructuredOutcome(raw))
376
+ commandTiming.commandMs = raw.durationMs;
361
377
  }
362
378
  finally {
363
379
  if (pathCapture)
364
380
  this.dependencies.endPathMutation(pathCapture, tool.name);
365
- if (workspaceCapture)
366
- await this.dependencies.endWorkspaceMutation(workspaceCapture, tool.name);
381
+ if (workspaceCapture) {
382
+ await captureWorkspace('workspaceAfterMs', () => this.dependencies.endWorkspaceMutation(workspaceCapture, tool.name));
383
+ }
367
384
  }
368
385
  const mutationAfter = this.dependencies.getCurrentTurnMutationState();
369
386
  const changedFiles = mutationAfter.version !== mutationBefore.version
@@ -385,10 +402,14 @@ export class ToolRuntime {
385
402
  ? mutationAfter.changedFiles.filter((item) => item.path === capturedPath).map((item) => item.path)
386
403
  : mutationAfter.changedFiles.map((item) => item.path)
387
404
  : [];
388
- if (signal?.aborted || (error instanceof Error && error.name === 'AbortError')) {
389
- return terminalOutcome('aborted', 'ABORTED', t('command.interrupted'), startedAt, changedFiles);
390
- }
391
- return executionErrorOutcome(tool.name, error, startedAt, changedFiles);
405
+ outcome =
406
+ signal?.aborted || (error instanceof Error && error.name === 'AbortError')
407
+ ? terminalOutcome('aborted', 'ABORTED', t('command.interrupted'), startedAt, changedFiles)
408
+ : executionErrorOutcome(tool.name, error, startedAt, changedFiles);
392
409
  }
410
+ if (!commandTiming || commandStartedAt === undefined)
411
+ return outcome;
412
+ commandTiming.totalMs = performance.now() - commandStartedAt;
413
+ return { ...outcome, commandTiming };
393
414
  }
394
415
  }
@@ -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
+ }
@@ -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 停转)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocode-ai",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
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",