@andorra-labs/code 0.1.10 → 0.1.12

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 (238) hide show
  1. package/README.md +31 -205
  2. package/THIRD_PARTY_NOTICES.md +30 -0
  3. package/dist/src/agent-execution.js +50 -2
  4. package/dist/src/agent-mcp.js +5 -0
  5. package/dist/src/app-server/protocol.d.ts +9 -1
  6. package/dist/src/app-server/protocol.js +1 -1
  7. package/dist/src/app-server.d.ts +49 -1
  8. package/dist/src/app-server.js +353 -64
  9. package/dist/src/automation-service.js +1 -1
  10. package/dist/src/browser-panel-tool.d.ts +24 -3
  11. package/dist/src/browser-panel-tool.js +80 -6
  12. package/dist/src/browser-runner.js +3 -1
  13. package/dist/src/browser-session.d.ts +8 -0
  14. package/dist/src/browser-session.js +27 -1
  15. package/dist/src/browser-ui/app.js +237 -15
  16. package/dist/src/browser-ui/index.html +5 -5
  17. package/dist/src/browser-ui/style.css +110 -65
  18. package/dist/src/browser-ui/tokens.css +27 -26
  19. package/dist/src/browser-view.d.ts +16 -0
  20. package/dist/src/browser-view.js +38 -2
  21. package/dist/src/claude-provider.js +15 -2
  22. package/dist/src/cli.d.ts +2 -1
  23. package/dist/src/cli.js +175 -43
  24. package/dist/src/code-intelligence/CodeIntelligenceManager.js +1 -1
  25. package/dist/src/codex-provider.js +6 -3
  26. package/dist/src/coding-tools.d.ts +26 -1
  27. package/dist/src/coding-tools.js +104 -33
  28. package/dist/src/command-screens.js +1 -1
  29. package/dist/src/commands.js +1 -1
  30. package/dist/src/completion-gates.d.ts +42 -7
  31. package/dist/src/completion-gates.js +55 -9
  32. package/dist/src/completion.d.ts +51 -1
  33. package/dist/src/completion.js +164 -5
  34. package/dist/src/config.d.ts +1 -0
  35. package/dist/src/config.js +2 -0
  36. package/dist/src/dashboard-view.js +2 -2
  37. package/dist/src/deadline.js +4 -0
  38. package/dist/src/decision/PreparedSteps.js +1 -1
  39. package/dist/src/delegation-changes.js +19 -2
  40. package/dist/src/diff-preview.d.ts +1 -0
  41. package/dist/src/diff-preview.js +12 -3
  42. package/dist/src/engine-streams.d.ts +22 -0
  43. package/dist/src/engine-streams.js +16 -0
  44. package/dist/src/extensions.js +17 -6
  45. package/dist/src/file-read-key.d.ts +8 -0
  46. package/dist/src/file-read-key.js +12 -0
  47. package/dist/src/graph-editor-session.js +2 -1
  48. package/dist/src/graph-health.d.ts +21 -0
  49. package/dist/src/graph-health.js +46 -0
  50. package/dist/src/graph-manager-chat.d.ts +52 -3
  51. package/dist/src/graph-manager-chat.js +62 -17
  52. package/dist/src/graph-runner.js +62 -5
  53. package/dist/src/graph-server.d.ts +1 -1
  54. package/dist/src/graph-server.js +48 -27
  55. package/dist/src/graph-sync.d.ts +8 -0
  56. package/dist/src/graph-sync.js +54 -3
  57. package/dist/src/graph-tool.js +1 -1
  58. package/dist/src/graph-ui/app.js +362 -123
  59. package/dist/src/graph-ui/controls.css +95 -22
  60. package/dist/src/graph-ui/controls.js +31 -1
  61. package/dist/src/graph-ui/embed.js +62 -13
  62. package/dist/src/graph-ui/icons.js +7 -0
  63. package/dist/src/graph-ui/index.html +4 -4
  64. package/dist/src/graph-ui/manager-state.js +143 -5
  65. package/dist/src/graph-ui/manager.css +21 -20
  66. package/dist/src/graph-ui/manager.js +337 -75
  67. package/dist/src/graph-ui/model-picker.js +279 -0
  68. package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
  69. package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
  70. package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
  71. package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
  72. package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
  73. package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
  74. package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
  75. package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
  76. package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
  77. package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
  78. package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
  79. package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
  80. package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
  81. package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
  82. package/dist/src/graph-ui/skill-picker.js +1 -1
  83. package/dist/src/graph-ui/studio-canvas.js +8 -8
  84. package/dist/src/graph-ui/studio.css +18 -15
  85. package/dist/src/graph-ui/studio.js +92 -35
  86. package/dist/src/graph-ui/style.css +122 -79
  87. package/dist/src/graph-ui/theme.js +2 -2
  88. package/dist/src/graph-ui/tokens.css +33 -29
  89. package/dist/src/graphs.d.ts +5 -2
  90. package/dist/src/graphs.js +10 -9
  91. package/dist/src/mcp.d.ts +52 -14
  92. package/dist/src/mcp.js +285 -128
  93. package/dist/src/membership-errors.d.ts +7 -1
  94. package/dist/src/membership-errors.js +9 -3
  95. package/dist/src/memory/ProjectMemory.d.ts +77 -0
  96. package/dist/src/memory/ProjectMemory.js +310 -0
  97. package/dist/src/memory/index.d.ts +1 -0
  98. package/dist/src/memory/index.js +1 -0
  99. package/dist/src/opencode-provider.js +5 -6
  100. package/dist/src/package-name.d.ts +3 -0
  101. package/dist/src/package-name.js +3 -0
  102. package/dist/src/provider-engine.js +2 -2
  103. package/dist/src/pull-requests.d.ts +42 -6
  104. package/dist/src/pull-requests.js +11 -3
  105. package/dist/src/qa/runtime/PtyManager.js +2 -1
  106. package/dist/src/react-runtime.js +137 -22
  107. package/dist/src/read-document-doc.d.ts +20 -0
  108. package/dist/src/read-document-doc.js +524 -0
  109. package/dist/src/read-document-docx.d.ts +21 -0
  110. package/dist/src/read-document-docx.js +584 -0
  111. package/dist/src/read-document-text.d.ts +29 -0
  112. package/dist/src/read-document-text.js +67 -0
  113. package/dist/src/read-document-tool.d.ts +48 -0
  114. package/dist/src/read-document-tool.js +162 -0
  115. package/dist/src/read-document.d.ts +78 -0
  116. package/dist/src/read-document.js +353 -0
  117. package/dist/src/read-image.d.ts +29 -2
  118. package/dist/src/read-image.js +42 -17
  119. package/dist/src/remote/cert.d.ts +1 -1
  120. package/dist/src/remote/cert.js +2 -7
  121. package/dist/src/remote/client.js +1 -1
  122. package/dist/src/remote/pem.d.ts +6 -0
  123. package/dist/src/remote/pem.js +11 -0
  124. package/dist/src/run-records.js +49 -10
  125. package/dist/src/runtime.d.ts +21 -0
  126. package/dist/src/runtime.js +10 -1
  127. package/dist/src/session-changes.d.ts +6 -1
  128. package/dist/src/session-changes.js +13 -5
  129. package/dist/src/sessions.d.ts +3 -1
  130. package/dist/src/sessions.js +5 -3
  131. package/dist/src/side-panel.d.ts +6 -1
  132. package/dist/src/side-panel.js +12 -10
  133. package/dist/src/sign-in-detection.d.ts +82 -0
  134. package/dist/src/sign-in-detection.js +197 -0
  135. package/dist/src/sign-in-offer.d.ts +35 -0
  136. package/dist/src/sign-in-offer.js +116 -0
  137. package/dist/src/skills/bundled/create-skill/SKILL.md +1 -1
  138. package/dist/src/skills/bundled/diagram/SKILL.md +1 -1
  139. package/dist/src/skills/bundled/graph-manager/SKILL.md +59 -7
  140. package/dist/src/skills/bundled/graph-manager/patterns.md +27 -0
  141. package/dist/src/skills/bundled/provenance.json +4 -4
  142. package/dist/src/skills/runtime-skills.d.ts +6 -0
  143. package/dist/src/skills/runtime-skills.js +16 -3
  144. package/dist/src/stall-recovery.d.ts +6 -2
  145. package/dist/src/stall-recovery.js +7 -2
  146. package/dist/src/stray-files.d.ts +14 -0
  147. package/dist/src/stray-files.js +81 -0
  148. package/dist/src/subagent-run.js +6 -1
  149. package/dist/src/terminal-ui.d.ts +1 -1
  150. package/dist/src/terminal-ui.js +11 -5
  151. package/dist/src/time-limit.d.ts +53 -0
  152. package/dist/src/time-limit.js +79 -0
  153. package/dist/src/tool-activity.js +1 -1
  154. package/dist/src/tool-schema-compatibility.d.ts +7 -2
  155. package/dist/src/tool-schema-compatibility.js +8 -4
  156. package/dist/src/tools.js +92 -7
  157. package/dist/src/transcript.d.ts +5 -0
  158. package/dist/src/transcript.js +12 -4
  159. package/dist/src/types.d.ts +8 -0
  160. package/dist/src/untracked-file-removal.d.ts +3 -0
  161. package/dist/src/untracked-file-removal.js +125 -0
  162. package/dist/src/update-check.js +1 -1
  163. package/dist/src/update.d.ts +11 -1
  164. package/dist/src/update.js +27 -5
  165. package/dist/src/usage-analytics.d.ts +3 -1
  166. package/dist/src/usage-analytics.js +16 -2
  167. package/dist/src/workspace-git-metadata.d.ts +15 -0
  168. package/dist/src/workspace-git-metadata.js +50 -1
  169. package/dist/src/workspace-instructions.js +1 -1
  170. package/package.json +6 -26
  171. package/docs/README.md +0 -36
  172. package/docs/agents/README.md +0 -62
  173. package/docs/agents/install-for-agents.md +0 -56
  174. package/docs/agents/mcp-server.md +0 -212
  175. package/docs/agents/subagent-mode.md +0 -149
  176. package/docs/concepts/README.md +0 -47
  177. package/docs/concepts/jev-actionable-routing.md +0 -113
  178. package/docs/concepts/jev-decision-thresholds.md +0 -412
  179. package/docs/concepts/jev-efficiency.md +0 -217
  180. package/docs/concepts/jev-eval-2026-11-01.md +0 -78
  181. package/docs/concepts/limits.md +0 -52
  182. package/docs/concepts/memory.md +0 -10
  183. package/docs/concepts/security.md +0 -50
  184. package/docs/concepts/workspace-instructions.md +0 -29
  185. package/docs/getting-started/README.md +0 -82
  186. package/docs/getting-started/accounts.md +0 -78
  187. package/docs/getting-started/configure-providers.md +0 -132
  188. package/docs/guides/README.md +0 -13
  189. package/docs/guides/browser.md +0 -39
  190. package/docs/guides/desktop-app.md +0 -414
  191. package/docs/guides/extensions.md +0 -102
  192. package/docs/guides/graph-builder.md +0 -116
  193. package/docs/guides/headless.md +0 -46
  194. package/docs/guides/tui.md +0 -75
  195. package/docs/guides/update.md +0 -70
  196. package/docs/guides/web-search.md +0 -51
  197. package/docs/guides/windows-code-signing.md +0 -319
  198. package/docs/llms.txt +0 -45
  199. package/docs/reference/README.md +0 -7
  200. package/docs/reference/cli.md +0 -76
  201. package/docs/reference/config.md +0 -91
  202. package/docs/reference/slash-commands.md +0 -59
  203. package/docs/superpowers/plans/2026-11-01-claude-console-sign-in.md +0 -111
  204. package/docs/superpowers/plans/2026-11-01-jev-node-opt-in.md +0 -910
  205. package/docs/superpowers/plans/2026-11-02-workflow-pane.md +0 -398
  206. package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +0 -125
  207. package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +0 -295
  208. package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +0 -203
  209. package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +0 -79
  210. package/docs/superpowers/specs/2026-10-31-work-line-summary-design.md +0 -50
  211. package/docs/superpowers/specs/2026-11-01-claude-console-sign-in-design.md +0 -176
  212. package/docs/superpowers/specs/2026-11-01-jev-node-opt-in-design.md +0 -164
  213. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +0 -111
  214. package/docs/superpowers/specs/2026-11-02-workflow-pane-design.md +0 -130
  215. package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +0 -206
  216. package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +0 -291
  217. package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +0 -182
  218. package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +0 -156
  219. package/scripts/jev-efficiency-eval.mjs +0 -187
  220. package/scripts/jev-efficiency-live.mjs +0 -193
  221. package/scripts/zcode-engine-replay.mjs +0 -223
  222. package/tests/agent-centric-mcp-test-plan.md +0 -208
  223. package/tests/analytics-settings-test-plan.md +0 -165
  224. package/tests/browser-cli-smoke.mjs +0 -276
  225. package/tests/browser-test-plan.md +0 -280
  226. package/tests/chat-side-panel-test-plan.md +0 -309
  227. package/tests/decision-engine-test-plan.md +0 -163
  228. package/tests/default-active-jev-test-plan.md +0 -85
  229. package/tests/harness-extensions-test-plan.md +0 -113
  230. package/tests/jev-all-decisions-test-plan.md +0 -156
  231. package/tests/jev-efficiency/criteria.json +0 -158
  232. package/tests/jev-efficiency/workloads.mjs +0 -242
  233. package/tests/jev-efficiency-test-plan.md +0 -198
  234. package/tests/permissions-sandbox-probe.mjs +0 -74
  235. package/tests/permissions-test-plan.md +0 -191
  236. package/tests/product-telemetry-test-plan.md +0 -536
  237. package/tests/thinking-stream-preview-test-plan.md +0 -136
  238. package/tests/zcode-react-engine-test-plan.md +0 -396
@@ -9,6 +9,8 @@ import { desktopUaOverride, hardenContext, stealthContextOptions, stealthLaunchA
9
9
  export const VIEW_TAB_LIMIT = 6;
10
10
  export const VIEW_SESSION_LIMIT = 4;
11
11
  export const VIEW_IDLE_CLOSE_MS = 10 * 60 * 1000;
12
+ /** The longest single idle-reap lease a caller may take; a holder renews well inside it. */
13
+ export const VIEW_HOLD_MAX_MS = 10 * 60 * 1000;
12
14
  /** The pacing window between emitted frames: one per display refresh, with the coalescer holding the newest. */
13
15
  export const VIEW_FRAME_MIN_INTERVAL_MS = 16;
14
16
  export const VIEW_GOTO_TIMEOUT_MS = 30_000;
@@ -371,6 +373,8 @@ export class BrowserViewManager {
371
373
  * closes, so the next open returns to the project profile.
372
374
  */
373
375
  incognito = new Set();
376
+ /** Idle-reap leases by session id: the time each session's browser is held until (see `hold`). */
377
+ holds = new Map();
374
378
  closed = false;
375
379
  constructor(emit, launchBrowser, options = {}) {
376
380
  this.emit = emit;
@@ -646,17 +650,49 @@ export class BrowserViewManager {
646
650
  return;
647
651
  this.emit('browser.view', { kind: 'tabs', sessionId, ...this.summary(session) });
648
652
  }
649
- scheduleIdleClose(sessionId, session) {
653
+ /**
654
+ * Keep a session's panel browser from being idle-reaped for the next `ms`.
655
+ *
656
+ * A live run whose agent drove the panel renews this lease while it lasts, so
657
+ * a page it opened for the user — a sign-in it asked them to complete, say —
658
+ * is still there when they look, however long the run waits on their answer.
659
+ * A lease, not a flag: a run engine that dies stops renewing, and the browser
660
+ * falls back to the ordinary idle window instead of staying pinned forever.
661
+ */
662
+ hold(sessionId, ms) {
663
+ const now = Date.now();
664
+ // A lapsed lease still sets its session's idle deadline (lease end + the idle window), so it is
665
+ // forgotten only once that deadline has passed too.
666
+ for (const [id, until] of this.holds)
667
+ if (until + VIEW_IDLE_CLOSE_MS <= now)
668
+ this.holds.delete(id);
669
+ this.holds.set(sessionId, now + Math.max(0, Math.min(ms, VIEW_HOLD_MAX_MS)));
670
+ return { held: this.sessions.has(sessionId) };
671
+ }
672
+ scheduleIdleClose(sessionId, session, delay = VIEW_IDLE_CLOSE_MS) {
650
673
  if (session.idleTimer)
651
674
  clearTimeout(session.idleTimer);
652
675
  // A session someone is watching (streaming) is never idle-reaped; only an
653
676
  // abandoned open browser is, so a forgotten panel cannot pin memory forever.
654
677
  session.idleTimer = setTimeout(() => {
655
678
  session.idleTimer = undefined;
679
+ // A browser a run held is not idle until a full idle window after its
680
+ // latest lease ends. The lease is read now, not when this check was
681
+ // scheduled: renewals since then move the deadline, and an earlier check
682
+ // that fires on a stale deadline just looks again at the current one.
683
+ const until = this.holds.get(sessionId);
684
+ if (until !== undefined) {
685
+ const remaining = until + VIEW_IDLE_CLOSE_MS - Date.now();
686
+ if (remaining > 0) {
687
+ this.scheduleIdleClose(sessionId, session, remaining);
688
+ return;
689
+ }
690
+ this.holds.delete(sessionId);
691
+ }
656
692
  // A tab still being created is work in progress, not idleness.
657
693
  if (!session.streaming && session.pendingTabs === 0)
658
694
  void this.closeSession(sessionId, 'idle', session);
659
- }, VIEW_IDLE_CLOSE_MS);
695
+ }, delay);
660
696
  session.idleTimer.unref?.();
661
697
  }
662
698
  async stopScreencast(tab) {
@@ -401,11 +401,22 @@ export function parseClaudeResponse(output, tools = []) {
401
401
  else if (turnLimit && direct.length && !structured)
402
402
  response = { text: texts.join('\n'), toolCalls: direct };
403
403
  else
404
- throw new MalformedClaudeStep('Claude did not return a complete Andorra model step');
404
+ throw new MalformedClaudeStep(`Claude did not return a complete Andorra model step (${incompleteStep(result, Boolean(structured), texts.length > 0, acknowledgements)})`);
405
405
  if (result.usage)
406
406
  response.usage = claudeUsage(result.usage);
407
407
  return response;
408
408
  }
409
+ /** Why a step was incomplete, as counts and protocol states only: reply content never reaches it. */
410
+ function incompleteStep(result, structured, answeredInText, acknowledgements) {
411
+ const stop = typeof result.stop_reason === 'string' && /^[a-z_]{1,40}$/.test(result.stop_reason) ? `, stop reason ${result.stop_reason}` : '';
412
+ if (!structured)
413
+ return `${answeredInText ? 'it answered in text with no structured reply' : 'it sent no structured reply'}${stop}`;
414
+ if (acknowledgements.length !== 1)
415
+ return `the CLI acknowledged the structured reply ${acknowledgements.length} times${stop}`;
416
+ if (acknowledgements[0].is_error === true)
417
+ return `the CLI refused the structured reply${stop}`;
418
+ return `the structured reply and the CLI result disagreed${stop}`;
419
+ }
409
420
  function claudeUsage(usage) {
410
421
  const token = (name) => typeof usage[name] === 'number' && Number.isSafeInteger(usage[name]) && usage[name] >= 0 ? usage[name] : undefined;
411
422
  const input = token('input_tokens');
@@ -523,7 +534,9 @@ export function createClaudeAdapter(_config, dependencies = {}) {
523
534
  // the run on the first one throws away everything the run had done up to that step.
524
535
  if (!(error instanceof MalformedClaudeStep) || attempt >= STEP_ATTEMPTS)
525
536
  throw error;
526
- await request.onRetry?.({ retry: attempt, maxRetries: STEP_ATTEMPTS - 1, delayMs: 0, reason: `${error.message}. Asking again.` });
537
+ // Quiet: the step is asked again at once and usually arrives, so the reader has nothing to
538
+ // act on. The retry is still recorded, and a step that never arrives fails the run aloud.
539
+ await request.onRetry?.({ retry: attempt, maxRetries: STEP_ATTEMPTS - 1, delayMs: 0, reason: `${error.message}. Asking again.`, quiet: true });
527
540
  }
528
541
  }
529
542
  },
package/dist/src/cli.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { saveConfig } from './config.js';
3
3
  import { providerSecrets } from './providers.js';
4
4
  import { type RunResult } from './runtime.js';
5
- import { checkGraphModelHealth } from './graph-health.js';
5
+ import { checkGraphModelHealth, checkSessionModelHealth } from './graph-health.js';
6
6
  import { loadAccessibleGraph } from './membership.js';
7
7
  import type { RuntimeEvent } from './types.js';
8
8
  /**
@@ -67,6 +67,7 @@ export declare function withNodeModelResolution(event: RuntimeEvent, lookup: (pr
67
67
  export declare function main(argv?: string[], dependencies?: {
68
68
  loadGraph?: typeof loadAccessibleGraph;
69
69
  checkGraphHealth?: typeof checkGraphModelHealth;
70
+ checkSessionModel?: typeof checkSessionModelHealth;
70
71
  trajectoryDirectory?: string;
71
72
  saveConfig?: typeof saveConfig;
72
73
  }): Promise<number>;
package/dist/src/cli.js CHANGED
@@ -14,13 +14,13 @@ import { workspacePermissionKey, permissionLabel } from './permissions.js';
14
14
  import { configDirectory, loadConfig, resolveCodeIntelConfig, resolveConfiguredLimits, saveConfig } from './config.js';
15
15
  import { compactHistory, compactedContextEstimate, executeCommand, HELP } from './commands.js';
16
16
  import { applyModelContextWindow, createAdapter, providerSecrets, recordProviderModel } from './providers.js';
17
- import { createTools } from './tools.js';
18
17
  import { disposeAllQaProcesses, disposeAllQaPtys, getQaPtyManager } from './qa/index.js';
19
18
  import { disposePooledPowerShell } from './powershell-pool.js';
20
19
  import { loadWorkspaceInstructions } from './workspace-instructions.js';
21
20
  import { runGraph, stopReasonPhrase } from './runtime.js';
22
21
  import { GraphDeletedError, validateGraph } from './graphs.js';
23
- import { checkGraphModelHealth, formatGraphHealthFailure } from './graph-health.js';
22
+ import { checkGraphModelHealth, checkSessionModelHealth, formatGraphHealthFailure } from './graph-health.js';
23
+ import { ModelHealthCache } from './model-health-cache.js';
24
24
  import { getMembership, loadAccessibleGraph, PaidMembershipRequiredError } from './membership.js';
25
25
  import { configuredSurface, createRunHandle, drainTelemetry, graphShape, reportInterruptedRuns, reportRunFinished, reportRunStarted, reportSessionStarted } from './telemetry/surface.js';
26
26
  import { createRunTelemetry, recordModelUse } from './telemetry/capture.js';
@@ -35,11 +35,10 @@ const graphFallbackReason = (error) => error instanceof FreeTierLimitError || er
35
35
  ? `${error.message} Starting with the local Default graph.`
36
36
  : missingSavedGraph(error) ? 'The selected graph is no longer stored locally. Starting with the Default graph; use /graph to choose another.' : GRAPH_FALLBACK_NOTICE;
37
37
  import { configuredGraphSelection, currentGraphSubject } from './graph-selection.js';
38
- import { launchGraphEditor } from './graph-server.js';
39
38
  import { createGraphEditorSession } from './graph-editor-session.js';
40
39
  import { FreeTierLimitError } from './graph-quota.js';
41
- import { updateInstallation } from './update.js';
42
40
  import { availableUpdate, parseUpdateAnswer, recordUpdateChoice, updateCheckDisabled } from './update-check.js';
41
+ import { offerSignInImport } from './sign-in-offer.js';
43
42
  import { RunControl } from './run-control.js';
44
43
  import { TimerRegistry } from './timers.js';
45
44
  import { TerminalUI } from './terminal-ui.js';
@@ -55,6 +54,7 @@ import { attachmentLabel, attachmentReadRoots, attachmentReferenceBlock, pruneAt
55
54
  import { describeTool, formatAnswer, formatEvent, formatRunResult } from './transcript.js';
56
55
  import { staticToolTimestamp } from './tool-call-clock.js';
57
56
  import { LocalToolMemory } from './memory/LocalToolMemory.js';
57
+ import { ProjectMemory } from './memory/ProjectMemory.js';
58
58
  import { askClarification } from './clarification-ui.js';
59
59
  import { refreshModelContext, resolveModelContext, withEvaluationReasoningEffort } from './model-metadata.js';
60
60
  import { isScreenCommand, runCommandScreen } from './command-screens.js';
@@ -73,7 +73,46 @@ import { TodoStore } from './todos.js';
73
73
  import { canExtendLineage, carryRailOwnedFields, displayHistory, lineagePoints, lineageThrough, SessionStore, sessionName, projectIdentity } from './sessions.js';
74
74
  import { SessionTitle } from './session-title.js';
75
75
  import { createBrowserBridge } from './browser-bridge.js';
76
- import { startBrowserServer, openBrowserUrl } from './browser-server.js';
76
+ /*
77
+ * Loaded on first use rather than with the process. The tool set (and the schema library behind
78
+ * it) is needed only once a task runs; the updater, the graph editor and the browser server each
79
+ * serve a single command and bring their own dependencies (the editor's scheduler and sync, the
80
+ * browser runner's MCP client). Imported statically, they all loaded before the terminal could
81
+ * draw its first frame.
82
+ */
83
+ const loadTools = () => import('./tools.js');
84
+ /** How long the keyboard must be quiet before the warm-up loads its next set. */
85
+ const WARM_IDLE_MS = 400;
86
+ /**
87
+ * Load what the first task needs — the tool set, the provider SDK adapters and the schema compiler
88
+ * — after the terminal has drawn, while the person reads the screen, so the first task does not
89
+ * pay for it. Best effort: a module that fails here fails again, with its real error, where the
90
+ * task imports it.
91
+ *
92
+ * Resolving and compiling a module graph runs synchronously inside `import()`, holding the event
93
+ * loop for a few hundred milliseconds per set. Keys typed during that arrive together, and the
94
+ * composer reads a line and its Enter that arrive together as pasted text — a newline, not a
95
+ * submission. So each set loads only after the keyboard has been quiet for a moment, and the
96
+ * warm-up stops once `stop()` says a task has begun: the task imports whatever is still missing.
97
+ */
98
+ async function warmRunModules(lastInputAt, stop) {
99
+ for (const load of [loadTools, () => import('./engine-streams.js').then(module => module.loadEngineStreams()), () => import('typebox/compile')]) {
100
+ for (;;) {
101
+ if (stop())
102
+ return;
103
+ const quiet = Date.now() - lastInputAt();
104
+ if (quiet >= WARM_IDLE_MS)
105
+ break;
106
+ await new Promise(resolve => setTimeout(resolve, WARM_IDLE_MS - quiet).unref());
107
+ }
108
+ await load().catch(() => { });
109
+ }
110
+ }
111
+ const updateInstallation = async (...args) => (await import('./update.js')).updateInstallation(...args);
112
+ const launchGraphEditor = async (noOpen) => (await import('./graph-server.js')).launchGraphEditor(noOpen);
113
+ const startBrowserServer = async () => (await import('./browser-server.js')).startBrowserServer();
114
+ // Only called once startBrowserServer has resolved, so the module is already loaded here.
115
+ const openBrowserUrl = (url) => { void import('./browser-server.js').then(module => module.openBrowserUrl(url)); };
77
116
  /**
78
117
  * The version this build reports, read from the package manifest rather than hard-coded.
79
118
  *
@@ -137,6 +176,24 @@ async function offerStartupUpdate() {
137
176
  return false;
138
177
  }
139
178
  }
179
+ /**
180
+ * Asks once, on the first interactive launch, whether to add the vendor CLIs this machine is already
181
+ * signed in to as providers. Bounded and silent on failure: startup continues either way, and the
182
+ * configuration is loaded after this so anything added is what the session starts with.
183
+ */
184
+ async function offerStartupSignIns() {
185
+ let lines;
186
+ try {
187
+ await offerSignInImport({
188
+ write: text => { process.stdout.write(text); },
189
+ ask: question => (lines ??= createInterface({ input: process.stdin, output: process.stdout, terminal: true })).question(question),
190
+ });
191
+ }
192
+ catch { /* The offer is a convenience; it never decides whether the session starts. */ }
193
+ finally {
194
+ lines?.close();
195
+ }
196
+ }
140
197
  /** Display-only Git metadata must never run workspace-controlled PATH helpers. */
141
198
  export async function gitBranch(workspace) {
142
199
  try {
@@ -282,6 +339,12 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
282
339
  const persistConfig = dependencies.saveConfig ?? saveConfig;
283
340
  const loadGraph = dependencies.loadGraph ?? loadAccessibleGraph;
284
341
  const checkGraphHealth = dependencies.checkGraphHealth ?? checkGraphModelHealth;
342
+ // Selecting Default checks only the session's model (see checkSessionModelHealth). A caller that
343
+ // substitutes the graph check and not this one keeps every check on its substitute.
344
+ const checkSessionModel = dependencies.checkSessionModel ?? (dependencies.checkGraphHealth === undefined ? checkSessionModelHealth : undefined);
345
+ // The models that answered recently, shared with the desktop engine and other sessions on this
346
+ // home, so a check right after another one does not pay for the same round trip again.
347
+ const modelHealth = new ModelHealthCache(configDirectory());
285
348
  // MCP uses stdio for JSON-RPC; never install the ordinary auth reporter here,
286
349
  // because a mid-session sign-out notice on stdout would corrupt the protocol.
287
350
  if (argv[0] === 'mcp-server') {
@@ -517,6 +580,10 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
517
580
  await trajectory.flush();
518
581
  return 0;
519
582
  }
583
+ bootMark('cli.update-check');
584
+ if (interactive)
585
+ await offerStartupSignIns();
586
+ bootMark('cli.sign-ins');
520
587
  const config = await startupGuard(() => loadConfig());
521
588
  const workspace = await startupGuard(async () => {
522
589
  const resolved = await realpath(values.cwd ?? process.cwd());
@@ -544,6 +611,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
544
611
  selected.model = values.model;
545
612
  }
546
613
  });
614
+ bootMark('cli.config');
547
615
  const permissions = values.yolo ? 'full-access' : config.workspacePermissions?.[workspacePermissionKey(workspace)] ?? 'ask-for-approval';
548
616
  // `--jev on|off` is this session's decision policy the way `--yolo` is its permission mode: it is
549
617
  // never written to the configuration, and an explicit `/jev on|off` during the session replaces it.
@@ -613,6 +681,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
613
681
  process.stderr.write(safeTerminal(graphFallbackNotice) + '\n');
614
682
  }
615
683
  });
684
+ bootMark('cli.startup-graph');
616
685
  let activeUsage = { inputTokens: 0, outputTokens: 0, requests: 0, cacheRead: 0, cacheWrite: 0 };
617
686
  // Cache totals stay sparse: a provider that reports no cache counts must not
618
687
  // materialize explicit zeros in persisted session state or the /usage screen.
@@ -721,6 +790,32 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
721
790
  let browserCancelPending = false;
722
791
  const rollbackFailureMessage = 'Session storage rollback failed. Repair local storage and inspect session history before restarting this CLI.';
723
792
  await startupGuard(() => mkdir(runRecordsDirectory(directory), { recursive: true }));
793
+ let runEventSink;
794
+ const codeIntelLabel = (state) => state === 'indexing' ? 'Indexing' : state === 'ready' ? 'Ready' : state === 'syncing' ? 'Updating'
795
+ : state === 'degraded' ? 'Degraded' : state === 'error' ? 'Error' : undefined;
796
+ const codeIntelNotice = (event) => {
797
+ if (event.type === 'codeintel.state') {
798
+ const label = codeIntelLabel(event.data.state);
799
+ terminal?.setStatus({ codeIntel: label });
800
+ if (event.data.state === 'error')
801
+ process.stderr.write(`CodeGraph: ${String(event.data.detail ?? 'unavailable')}\n`);
802
+ }
803
+ };
804
+ // A shell commonly starts in the user's home. Never recursively index that
805
+ // personal tree as an implicit side effect of opening the coding client.
806
+ // This override is session-only; /codegraph enable remains an explicit opt-in.
807
+ const homeWorkspace = workspace === await realpath(homedir()).catch(() => homedir());
808
+ // Opening the code graph (git lookups, the index database) touches neither run records nor
809
+ // sessions, so it proceeds while the recovery pass below reads them; the first frame waits for
810
+ // whichever finishes last instead of for both in turn.
811
+ const codeIntelOpening = CodeIntelligenceManager.create({
812
+ permissions: state.permissions,
813
+ config: homeWorkspace ? { ...resolveCodeIntelConfig(config), enabled: false, enabledRepos: [] } : resolveCodeIntelConfig(config), workspace,
814
+ onEvent: event => (runEventSink ?? codeIntelNotice)(event),
815
+ });
816
+ // Observed here so a failure cannot surface as an unhandled rejection while recovery runs;
817
+ // the startup guard below still receives it.
818
+ codeIntelOpening.catch(() => { });
724
819
  // Attempts a previous process left in flight (or never opened a record for at all) are classified
725
820
  // before this one can write any: the pass reads pids and rewrites markers, and sessions are not
726
821
  // loaded yet here, so it can never race an in-memory copy. Best-effort: a damaged home must not
@@ -744,26 +839,9 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
744
839
  }
745
840
  }
746
841
  catch { /* Recovery is best effort. */ }
747
- let runEventSink;
748
- const codeIntelLabel = (state) => state === 'indexing' ? 'Indexing' : state === 'ready' ? 'Ready' : state === 'syncing' ? 'Updating'
749
- : state === 'degraded' ? 'Degraded' : state === 'error' ? 'Error' : undefined;
750
- const codeIntelNotice = (event) => {
751
- if (event.type === 'codeintel.state') {
752
- const label = codeIntelLabel(event.data.state);
753
- terminal?.setStatus({ codeIntel: label });
754
- if (event.data.state === 'error')
755
- process.stderr.write(`CodeGraph: ${String(event.data.detail ?? 'unavailable')}\n`);
756
- }
757
- };
758
- // A shell commonly starts in the user's home. Never recursively index that
759
- // personal tree as an implicit side effect of opening the coding client.
760
- // This override is session-only; /codegraph enable remains an explicit opt-in.
761
- const homeWorkspace = workspace === await realpath(homedir()).catch(() => homedir());
762
- const codeIntel = await startupGuard(() => CodeIntelligenceManager.create({
763
- permissions: state.permissions,
764
- config: homeWorkspace ? { ...resolveCodeIntelConfig(config), enabled: false, enabledRepos: [] } : resolveCodeIntelConfig(config), workspace,
765
- onEvent: event => (runEventSink ?? codeIntelNotice)(event),
766
- }));
842
+ bootMark('cli.reconciled');
843
+ const codeIntel = await startupGuard(() => codeIntelOpening);
844
+ bootMark('cli.codeintel');
767
845
  releaseCodeIntel = () => codeIntel.dispose();
768
846
  state.codeIntel = codeIntel;
769
847
  /**
@@ -931,10 +1009,18 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
931
1009
  terminal?.setStatus({ provider: selected?.id ?? 'No provider', model: selected?.model ?? '/providers to configure', providerModels: Object.fromEntries(config.providers.map(p => [p.id, p.model])), reasoningEffort: selected?.reasoningEffort, contextWindow: selected?.contextWindow, yolo: state.yolo, permissions: permissionLabel(state.permissions), jevEnabled, ...sessionUsage() });
932
1010
  };
933
1011
  let graphModelsHealthy = false;
934
- const refreshGraphStatus = async () => {
1012
+ /**
1013
+ * Load the selected graph and probe its models, reporting the result in the footer.
1014
+ *
1015
+ * `background` is the launch check: it runs under its own controller instead of `active`, so the
1016
+ * prompt is open while it waits on the model, and a submission cancels it (see
1017
+ * `settleStartupGraphCheck`) rather than queueing behind it — every task probes its graph's models
1018
+ * in its own preflight anyway.
1019
+ */
1020
+ const refreshGraphStatus = async (background) => {
935
1021
  if (terminal) {
936
- const controller = active ?? new AbortController();
937
- const ownsController = !active;
1022
+ const controller = background ?? active ?? new AbortController();
1023
+ const ownsController = !background && !active;
938
1024
  if (ownsController)
939
1025
  active = controller;
940
1026
  terminal.setStatus({ activity: 'Checking graph models', backgroundActivity: true });
@@ -979,18 +1065,38 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
979
1065
  startupGraphSelection = state.graph ?? 'default';
980
1066
  jevEnabled = jevOn();
981
1067
  terminal.setStatus({ graphSelection: state.graph ?? 'default', graph, graphNeedsOverride: false, jevEnabled });
982
- const health = await checkGraphHealth(graph, config, controller.signal);
1068
+ await modelHealth.load();
1069
+ // Default is one agent on the session's own model, so its selection checks that model
1070
+ // rather than asking it for a reply as a graph check would; the run still probes it.
1071
+ const sessionOnly = (state.graph ?? 'default') === 'default' && checkSessionModel !== undefined;
1072
+ const health = sessionOnly
1073
+ ? await checkSessionModel(config, controller.signal, { verified: modelHealth })
1074
+ : await checkGraphHealth(graph, config, controller.signal, { verified: modelHealth });
983
1075
  graphModelsHealthy = health.healthy;
984
1076
  if (!health.healthy)
985
- print(formatGraphHealthFailure(health));
1077
+ print(formatGraphHealthFailure(health, sessionOnly
1078
+ ? 'Choose another model with /model, or check the provider with /providers.'
1079
+ : undefined));
986
1080
  }
987
1081
  finally {
988
1082
  if (ownsController)
989
1083
  active = undefined;
990
- terminal.setStatus({ activity: graphModelsHealthy ? 'Ready' : 'Graph models unavailable' });
1084
+ // A launch check cancelled by a submission proved nothing either way; what runs next
1085
+ // reports its own state, as commands already return the footer to Ready.
1086
+ terminal.setStatus({ activity: background?.signal.aborted ? 'Ready' : graphModelsHealthy ? 'Ready' : 'Graph models unavailable' });
991
1087
  }
992
1088
  }
993
1089
  };
1090
+ let startupGraphCheck;
1091
+ /** Cancel the launch graph check if it is still running, and wait until it has let go. */
1092
+ const settleStartupGraphCheck = async () => {
1093
+ const pending = startupGraphCheck;
1094
+ if (!pending)
1095
+ return;
1096
+ startupGraphCheck = undefined;
1097
+ pending.controller.abort(new Error('Superseded by a submitted task'));
1098
+ await pending.done;
1099
+ };
994
1100
  const graphEditor = createGraphEditorSession();
995
1101
  let accountRefresh;
996
1102
  let accountRefreshTimer;
@@ -1093,7 +1199,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
1093
1199
  else
1094
1200
  kill();
1095
1201
  };
1096
- const teardown = () => { terminated = true; exiting = true; active?.abort(); sessionTimers.clear(); terminal?.close(); };
1202
+ const teardown = () => { terminated = true; exiting = true; active?.abort(); startupGraphCheck?.controller.abort(); sessionTimers.clear(); terminal?.close(); };
1097
1203
  // The Ctrl+C escalation must not become a suggestion: after the terminal is restored, a
1098
1204
  // run wedged past its abort signal gets a short grace window and then a hard exit.
1099
1205
  // SIGTERM keeps the patient teardown instead — cleanup of a canceled shell tree is a
@@ -1110,7 +1216,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
1110
1216
  process.on('SIGINT', interrupt);
1111
1217
  process.on('SIGTERM', teardown);
1112
1218
  terminal?.on('SIGINT', interrupt);
1113
- terminal?.on('close', () => { tabTitle.close(); exiting = true; active?.abort(); });
1219
+ terminal?.on('close', () => { tabTitle.close(); exiting = true; active?.abort(); startupGraphCheck?.controller.abort(); });
1114
1220
  /**
1115
1221
  * Carry one attempt into the next turn's context. The turns live on `state` so commands
1116
1222
  * such as /compact and /clear can replace them and the next run sees the result.
@@ -1137,6 +1243,9 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
1137
1243
  /** The task text an attachment-only submission runs with; both surfaces substitute the same words. */
1138
1244
  const ATTACHMENT_ONLY_TASK = 'See the attached file(s).';
1139
1245
  const run = async (task, pending = []) => {
1246
+ // A task from the browser or a timer can arrive while the launch check is still probing; the
1247
+ // task's preflight probes again, and the check must not repaint the footer mid-run.
1248
+ await settleStartupGraphCheck();
1140
1249
  if (browserRollbackFailed)
1141
1250
  throw new Error(rollbackFailureMessage);
1142
1251
  if (!config.providers.length) {
@@ -1572,7 +1681,9 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
1572
1681
  : await preflight(signal => loadGraph(state.graph ?? 'default', signal));
1573
1682
  terminal?.setStatus({ activity: 'Checking graph models', backgroundActivity: true });
1574
1683
  graphModelsHealthy = false;
1684
+ await modelHealth.load();
1575
1685
  const health = await preflight(signal => checkGraphHealth(loadedGraph, config, signal, {
1686
+ verified: modelHealth,
1576
1687
  onUsage: (delta, reference) => {
1577
1688
  const key = `${reference.provider}\0${reference.model}`;
1578
1689
  const entry = probeModels.get(key) ?? { provider: reference.provider, model: reference.model, usage: {} };
@@ -1666,7 +1777,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
1666
1777
  const entry = formatEvent(event);
1667
1778
  if (entry) {
1668
1779
  if (terminal)
1669
- terminal.print(entry.text, entry.detail, entry.toolCall, false, /failed|error|stopped/.test(event.type));
1780
+ terminal.print(entry.text, entry.detail, entry.toolCall, false, /failed|error|stopped/.test(event.type), false, entry.clipRows);
1670
1781
  // The plain path has no Ctrl+O, so an agent message whose code block collapsed into
1671
1782
  // `detail` must print the full rendering, not the truncated summary.
1672
1783
  else if (event.type === 'agent.message' && entry.detail)
@@ -1746,7 +1857,8 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
1746
1857
  jevEnabled = jevOn();
1747
1858
  terminal?.setStatus({ graph, jevEnabled });
1748
1859
  const commandMemory = config.commandMemory === false ? undefined : await LocalToolMemory.open({ workspace, directory });
1749
- const execute = (options) => runGraph(graph, { ...options, runInput, runState, commandMemory, todoStore,
1860
+ const projectMemory = config.projectMemory === false ? undefined : await ProjectMemory.open({ home: directory, workspace });
1861
+ const execute = (options) => runGraph(graph, { ...options, runInput, runState, commandMemory, projectMemory, todoStore,
1750
1862
  ...(runSkill.skill ? { inheritedSkills: [runSkill.skill.id], skillInvocationInstruction: runSkill.skill.instruction } : {}),
1751
1863
  resolveModel: (id, model) => {
1752
1864
  const provider = config.providers.find(item => item.id === id);
@@ -1805,7 +1917,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
1805
1917
  terminal?.noteGeneratedTokens(usage.outputTokens, origin?.invocationId, origin?.final === true, usage.decodeMs);
1806
1918
  terminal?.setStatus(sessionUsage());
1807
1919
  },
1808
- adapter: tracedAdapter(runtimeProvider(selected)), tools: [...createTools(), ...snapshot.tools, ...mcp.tools], installedSkillClaims: snapshot.claimsSkillName, history: state.history, instructions, codeIntel, ...decisionPolicy,
1920
+ adapter: tracedAdapter(runtimeProvider(selected)), tools: [...(await loadTools()).createTools(), ...snapshot.tools, ...mcp.tools], installedSkillClaims: snapshot.claimsSkillName, history: state.history, instructions, codeIntel, ...decisionPolicy,
1809
1921
  // Installation-wide bounds. Nothing is set by default, which leaves the run with no
1810
1922
  // wall clock and no iteration ceiling; a graph or node bound still narrows these.
1811
1923
  limits: resolveConfiguredLimits(config),
@@ -2087,6 +2199,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
2087
2199
  }
2088
2200
  }
2089
2201
  terminal.start();
2202
+ bootMark('cli.started');
2090
2203
  browserBridge = await createBrowserBridge(directory, () => {
2091
2204
  const snapshot = {
2092
2205
  ...(savedSession ?? { version: 1, id: trajectory.sessionId, name: 'New CLI session', workspace, updatedAt: new Date(sessionStartedAt).toISOString(), history: [], usage: { ...state.usage } }),
@@ -2207,19 +2320,34 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
2207
2320
  if (values.debug)
2208
2321
  print(sessionDescription());
2209
2322
  void refreshAccountStatus();
2210
- try {
2211
- await refreshGraphStatus();
2212
- }
2213
- catch (error) {
2214
- if (!exiting)
2215
- print(`Graph check failed: ${error instanceof Error ? error.message : 'Unknown failure'}`);
2216
- }
2323
+ // The graph check waits on a live model request, seconds on most providers, so it runs behind
2324
+ // the open prompt instead of in front of it.
2325
+ const startupCheckController = new AbortController();
2326
+ startupGraphCheck = {
2327
+ controller: startupCheckController,
2328
+ done: refreshGraphStatus(startupCheckController).catch(error => {
2329
+ if (!exiting && !startupCheckController.signal.aborted)
2330
+ print(`Graph check failed: ${error instanceof Error ? error.message : 'Unknown failure'}`);
2331
+ }),
2332
+ };
2333
+ void startupGraphCheck.done.then(() => bootMark('cli.graph-checked'));
2334
+ // Load what the first task needs while the screen is idle; the graph check above is waiting on
2335
+ // the network, so the two overlap rather than queue. The composer below is armed first, and
2336
+ // every keystroke postpones the next set (see warmRunModules).
2337
+ // Counting from now also lets the composer arm and the frame settle before the first set loads.
2338
+ let lastInputAt = Date.now();
2339
+ const noteInput = () => { lastInputAt = Date.now(); };
2340
+ process.stdin.on('data', noteInput);
2341
+ void warmRunModules(() => lastInputAt, () => exiting || active !== undefined)
2342
+ .finally(() => process.stdin.off('data', noteInput))
2343
+ .then(() => bootMark('cli.warm'));
2217
2344
  accountPolling = setInterval(scheduleAccountRefresh, 60_000);
2218
2345
  accountPolling.unref?.();
2219
2346
  while (!exiting) {
2220
2347
  let line;
2221
2348
  try {
2222
2349
  const asked = terminal.question('Describe a task, or type /help', { conversationPrompt: true });
2350
+ bootMark('cli.prompt');
2223
2351
  // A timer may have come due while the previous task was still saving, or while a
2224
2352
  // command screen or an approval owned the terminal; now the composer is armed again,
2225
2353
  // so hand it every self-wake prompt that had to wait.
@@ -2236,6 +2364,9 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
2236
2364
  continue;
2237
2365
  line = ATTACHMENT_ONLY_TASK;
2238
2366
  }
2367
+ // Every command and task below assumes the startup check is no longer touching the graph,
2368
+ // `active` or the footer.
2369
+ await settleStartupGraphCheck();
2239
2370
  const commandStartedAt = Date.now();
2240
2371
  await debugRecord('command.started', { input: line, mode: 'interactive' });
2241
2372
  try {
@@ -2487,6 +2618,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
2487
2618
  () => terminal?.close(),
2488
2619
  () => graphEditor.close(),
2489
2620
  () => codeIntel.dispose(),
2621
+ () => modelHealth.flush(),
2490
2622
  // QA dev servers are owned by this CLI session.
2491
2623
  () => Promise.all([disposeAllQaProcesses(), disposeAllQaPtys(), disposePooledPowerShell()]).catch(() => { }),
2492
2624
  ]) {
@@ -1,6 +1,6 @@
1
1
  import { isAbsolute, relative, resolve } from 'node:path';
2
2
  import { realpath } from 'node:fs/promises';
3
- import { stateKey as codingToolStateKey } from '../coding-tools.js';
3
+ import { stateKey as codingToolStateKey } from '../file-read-key.js';
4
4
  import { storeFileRead } from '../file-read-state.js';
5
5
  import { resolveRepositoryId, resolveRepositoryRoot } from './repository.js';
6
6
  import { CodeGraphSyncBarrier } from './codegraph/CodeGraphSyncBarrier.js';
@@ -102,8 +102,11 @@ export function createCodexAdapter(config, connect = codexConnectFor(config)) {
102
102
  // Empty maps merge with user configuration; explicitly disable every inherited server.
103
103
  config.mcp_servers = Object.fromEntries(Object.keys(settings?.config?.mcp_servers ?? {}).map(name => [name, { enabled: false }]));
104
104
  // An auxiliary request (`maxTokens` — a session title, a compaction batch) bounds its own
105
- // turn: `model_reasoning_effort: 'minimal'` caps the reasoning the auxiliary thread may
106
- // spend, which is the bulk of what the previous Codex exclusion avoided (the installed
105
+ // turn: `model_reasoning_effort: 'low'` caps the reasoning the auxiliary thread may
106
+ // spend, which is the bulk of what the previous Codex exclusion avoided. `low` is the
107
+ // lowest level every model in the Codex catalog accepts: current models (gpt-6.1-sol among
108
+ // them) do not offer `minimal`, and asking for it failed the whole turn — every model
109
+ // health probe and session title on those models (the installed
107
110
  // Codex CLI exposes no token-level output bound — strict config rejects
108
111
  // `model_max_output_tokens` as an unknown field), and the caller's deadline bounds the
109
112
  // rest. An ordinary run names no bound and keeps the model's own effort. An unusable
@@ -111,7 +114,7 @@ export function createCodexAdapter(config, connect = codexConnectFor(config)) {
111
114
  if (request.maxTokens !== undefined) {
112
115
  if (!Number.isSafeInteger(request.maxTokens) || request.maxTokens < 1)
113
116
  throw new Error('Invalid auxiliary output allowance.');
114
- config.model_reasoning_effort = 'minimal';
117
+ config.model_reasoning_effort = 'low';
115
118
  }
116
119
  const started = await rpc.request('thread/start', {
117
120
  model: request.model, modelProvider: 'openai', ephemeral: true, cwd,
@@ -1,3 +1,4 @@
1
+ import { stateKey } from './file-read-key.js';
1
2
  import type { Tool, ToolContext } from './types.js';
2
3
  /** Filesystem policy stays outside copied tool algorithms. Every operation is checked. */
3
4
  export interface CodingToolPolicy {
@@ -8,11 +9,35 @@ export interface CodingToolPolicy {
8
9
  mimeType: string;
9
10
  bytes: Buffer;
10
11
  } | undefined>;
12
+ /** The bytes of a file that opens like a PDF or a Word container; undefined for anything else. */
13
+ readDocument?(context: ToolContext, name: string): Promise<Buffer | undefined>;
14
+ /** A text file in an encoding other than UTF-8, decoded; undefined when it is not text. */
15
+ readLegacyText?(context: ToolContext, name: string): Promise<{
16
+ text: string;
17
+ encoding: string;
18
+ } | undefined>;
11
19
  atomicWrite(context: ToolContext, name: string, content: string, expected?: string): Promise<void>;
12
20
  authorize(name: string, args: Record<string, unknown>, context: ToolContext): Promise<void>;
13
21
  files(context: ToolContext, directory: string): AsyncIterable<string>;
14
22
  fileLimit: number;
15
23
  }
24
+ /**
25
+ * How long a foreground shell command may run when the call names no timeout.
26
+ *
27
+ * Thirty seconds, the earlier default, is shorter than an ordinary package install, compile or
28
+ * test run: the command was killed and the model had to notice, raise the timeout and start it
29
+ * again from nothing. Two minutes covers those without leaving a hung command unnoticed for long.
30
+ */
31
+ export declare const SHELL_DEFAULT_TIMEOUT_MS = 120000;
32
+ export declare const SHELL_MAX_TIMEOUT_MS = 600000;
33
+ /**
34
+ * What a timed-out command's error tells the model to do next.
35
+ *
36
+ * The bare "timed out after N ms" says the command was stopped but not that the work is lost, nor
37
+ * which of the two ways forward fits: a longer timeout while one is left to ask for, or a
38
+ * background job once the ceiling is reached.
39
+ */
40
+ export declare function shellTimeoutGuidance(message: string, timeout: number): string;
16
41
  /**
17
42
  * Key for the per-context file-read state.
18
43
  *
@@ -20,5 +45,5 @@ export interface CodingToolPolicy {
20
45
  * entries under the key the canonical tools look up. It must be applied to a path normalized
21
46
  * the same way the policy's safePath normalizes it, or the entries never match.
22
47
  */
23
- export declare function stateKey(resolved: string): string;
48
+ export { stateKey };
24
49
  export declare function createCodingTools(policy: CodingToolPolicy): Tool[];