@andorra-labs/code 0.1.11 → 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.
- package/README.md +8 -2
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/dist/src/agent-execution.js +15 -3
- package/dist/src/agent-mcp.js +5 -0
- package/dist/src/app-server/protocol.d.ts +8 -1
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server.d.ts +15 -0
- package/dist/src/app-server.js +89 -10
- package/dist/src/browser-panel-tool.d.ts +24 -3
- package/dist/src/browser-panel-tool.js +80 -6
- package/dist/src/browser-runner.js +3 -1
- package/dist/src/browser-view.d.ts +16 -0
- package/dist/src/browser-view.js +38 -2
- package/dist/src/claude-provider.js +15 -2
- package/dist/src/cli.d.ts +2 -1
- package/dist/src/cli.js +175 -43
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +1 -1
- package/dist/src/codex-provider.js +6 -3
- package/dist/src/coding-tools.d.ts +2 -1
- package/dist/src/coding-tools.js +39 -31
- package/dist/src/completion.d.ts +43 -1
- package/dist/src/completion.js +145 -4
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.js +2 -0
- package/dist/src/decision/PreparedSteps.js +1 -1
- package/dist/src/delegation-changes.js +19 -2
- package/dist/src/diff-preview.d.ts +1 -0
- package/dist/src/diff-preview.js +12 -3
- package/dist/src/engine-streams.d.ts +22 -0
- package/dist/src/engine-streams.js +16 -0
- package/dist/src/extensions.js +17 -6
- package/dist/src/file-read-key.d.ts +8 -0
- package/dist/src/file-read-key.js +12 -0
- package/dist/src/graph-editor-session.js +2 -1
- package/dist/src/graph-health.d.ts +21 -0
- package/dist/src/graph-health.js +46 -0
- package/dist/src/graph-manager-chat.d.ts +52 -3
- package/dist/src/graph-manager-chat.js +50 -5
- package/dist/src/graph-runner.js +23 -3
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +39 -18
- package/dist/src/graph-ui/app.js +100 -30
- package/dist/src/graph-ui/controls.css +52 -0
- package/dist/src/graph-ui/icons.js +3 -0
- package/dist/src/graph-ui/index.html +2 -2
- package/dist/src/graph-ui/manager-state.js +141 -3
- package/dist/src/graph-ui/manager.css +2 -2
- package/dist/src/graph-ui/manager.js +328 -66
- package/dist/src/graph-ui/model-picker.js +279 -0
- package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
- package/dist/src/graphs.d.ts +2 -0
- package/dist/src/graphs.js +7 -7
- package/dist/src/mcp.d.ts +52 -14
- package/dist/src/mcp.js +285 -128
- package/dist/src/memory/ProjectMemory.d.ts +77 -0
- package/dist/src/memory/ProjectMemory.js +310 -0
- package/dist/src/memory/index.d.ts +1 -0
- package/dist/src/memory/index.js +1 -0
- package/dist/src/opencode-provider.js +5 -6
- package/dist/src/package-name.d.ts +3 -0
- package/dist/src/package-name.js +3 -0
- package/dist/src/provider-engine.js +2 -2
- package/dist/src/qa/runtime/PtyManager.js +2 -1
- package/dist/src/react-runtime.js +16 -8
- package/dist/src/remote/cert.d.ts +1 -1
- package/dist/src/remote/cert.js +2 -7
- package/dist/src/remote/client.js +1 -1
- package/dist/src/remote/pem.d.ts +6 -0
- package/dist/src/remote/pem.js +11 -0
- package/dist/src/run-records.js +49 -10
- package/dist/src/runtime.d.ts +2 -0
- package/dist/src/sessions.d.ts +3 -1
- package/dist/src/sessions.js +5 -3
- package/dist/src/sign-in-detection.d.ts +82 -0
- package/dist/src/sign-in-detection.js +197 -0
- package/dist/src/sign-in-offer.d.ts +35 -0
- package/dist/src/sign-in-offer.js +116 -0
- package/dist/src/skills/bundled/graph-manager/SKILL.md +22 -4
- package/dist/src/skills/bundled/provenance.json +1 -1
- package/dist/src/skills/runtime-skills.d.ts +6 -0
- package/dist/src/skills/runtime-skills.js +13 -0
- package/dist/src/stray-files.d.ts +14 -0
- package/dist/src/stray-files.js +81 -0
- package/dist/src/subagent-run.js +6 -1
- package/dist/src/terminal-ui.d.ts +1 -1
- package/dist/src/terminal-ui.js +9 -3
- package/dist/src/tool-activity.js +1 -1
- package/dist/src/tool-schema-compatibility.d.ts +7 -2
- package/dist/src/tool-schema-compatibility.js +8 -4
- package/dist/src/transcript.d.ts +5 -0
- package/dist/src/transcript.js +11 -3
- package/dist/src/types.d.ts +2 -0
- package/dist/src/untracked-file-removal.d.ts +3 -0
- package/dist/src/untracked-file-removal.js +125 -0
- package/dist/src/update-check.js +1 -1
- package/dist/src/update.d.ts +11 -1
- package/dist/src/update.js +27 -5
- package/dist/src/workspace-git-metadata.d.ts +15 -0
- package/dist/src/workspace-git-metadata.js +50 -1
- package/dist/src/workspace-instructions.js +1 -1
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ import { connectMcpServers } from './mcp.js';
|
|
|
21
21
|
import { hostedDecisionPolicy } from './decision/hostedPolicy.js';
|
|
22
22
|
import { CodeIntelligenceManager } from './code-intelligence/CodeIntelligenceManager.js';
|
|
23
23
|
import { LocalToolMemory } from './memory/LocalToolMemory.js';
|
|
24
|
+
import { ProjectMemory } from './memory/ProjectMemory.js';
|
|
24
25
|
import { TodoStore } from './todos.js';
|
|
25
26
|
import { RunControl } from './run-control.js';
|
|
26
27
|
import { createSessionTrajectory } from './trajectory.js';
|
|
@@ -248,12 +249,13 @@ export async function runBrowserTask(session, task, control, options = {}) {
|
|
|
248
249
|
adapter: adapters(refreshed), contextWindow: refreshed.contextWindow, providerType: selected.type, baseUrl: selected.baseUrl }));
|
|
249
250
|
const membership = config.jevEnabled === false ? { paid: false } : await getMembership(signal, directory);
|
|
250
251
|
const commandMemory = config.commandMemory === false ? undefined : await LocalToolMemory.open({ workspace, directory });
|
|
252
|
+
const projectMemory = config.projectMemory === false ? undefined : await ProjectMemory.open({ home: directory, workspace });
|
|
251
253
|
signal.throwIfAborted();
|
|
252
254
|
const result = await runGraph(graph, {
|
|
253
255
|
task, runId, provider: selected.id, model: refreshed.model, adapter: adapters(refreshed), contextWindow: refreshed.contextWindow,
|
|
254
256
|
tools: [...createTools(), ...snapshot.tools, ...mcp.tools], history: (session.contextHistory ?? session.history).slice(-6),
|
|
255
257
|
instructions: `${workspaceGuidance}${snapshot.instructions}`,
|
|
256
|
-
context, codeIntel, commandMemory, todoStore: new TodoStore(),
|
|
258
|
+
context, codeIntel, commandMemory, projectMemory, todoStore: new TodoStore(),
|
|
257
259
|
...hostedDecisionPolicy(membership, config.jevEnabled !== false, config.decisions), limits: resolveConfiguredLimits(config),
|
|
258
260
|
getSteeringMessages: async () => control.steering().map(content => ({ role: 'user', content })),
|
|
259
261
|
onEvent,
|
|
@@ -24,6 +24,8 @@ export interface BrowserViewTab {
|
|
|
24
24
|
export declare const VIEW_TAB_LIMIT = 6;
|
|
25
25
|
export declare const VIEW_SESSION_LIMIT = 4;
|
|
26
26
|
export declare const VIEW_IDLE_CLOSE_MS: number;
|
|
27
|
+
/** The longest single idle-reap lease a caller may take; a holder renews well inside it. */
|
|
28
|
+
export declare const VIEW_HOLD_MAX_MS: number;
|
|
27
29
|
/** The pacing window between emitted frames: one per display refresh, with the coalescer holding the newest. */
|
|
28
30
|
export declare const VIEW_FRAME_MIN_INTERVAL_MS = 16;
|
|
29
31
|
export declare const VIEW_GOTO_TIMEOUT_MS = 30000;
|
|
@@ -212,6 +214,8 @@ export declare class BrowserViewManager {
|
|
|
212
214
|
* closes, so the next open returns to the project profile.
|
|
213
215
|
*/
|
|
214
216
|
private readonly incognito;
|
|
217
|
+
/** Idle-reap leases by session id: the time each session's browser is held until (see `hold`). */
|
|
218
|
+
private readonly holds;
|
|
215
219
|
private closed;
|
|
216
220
|
constructor(emit: BrowserViewEmit, launchBrowser?: ((scale: number) => Promise<any>) | undefined, options?: BrowserViewOptions);
|
|
217
221
|
private publishRuntime;
|
|
@@ -248,6 +252,18 @@ export declare class BrowserViewManager {
|
|
|
248
252
|
private disposeBrowser;
|
|
249
253
|
private summary;
|
|
250
254
|
private publishTabs;
|
|
255
|
+
/**
|
|
256
|
+
* Keep a session's panel browser from being idle-reaped for the next `ms`.
|
|
257
|
+
*
|
|
258
|
+
* A live run whose agent drove the panel renews this lease while it lasts, so
|
|
259
|
+
* a page it opened for the user — a sign-in it asked them to complete, say —
|
|
260
|
+
* is still there when they look, however long the run waits on their answer.
|
|
261
|
+
* A lease, not a flag: a run engine that dies stops renewing, and the browser
|
|
262
|
+
* falls back to the ordinary idle window instead of staying pinned forever.
|
|
263
|
+
*/
|
|
264
|
+
hold(sessionId: string, ms: number): {
|
|
265
|
+
held: boolean;
|
|
266
|
+
};
|
|
251
267
|
private scheduleIdleClose;
|
|
252
268
|
private stopScreencast;
|
|
253
269
|
/**
|
package/dist/src/browser-view.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
},
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
748
|
-
const
|
|
749
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
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 '../
|
|
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: '
|
|
106
|
-
// spend, which is the bulk of what the previous Codex exclusion avoided
|
|
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 = '
|
|
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 {
|
|
@@ -44,5 +45,5 @@ export declare function shellTimeoutGuidance(message: string, timeout: number):
|
|
|
44
45
|
* entries under the key the canonical tools look up. It must be applied to a path normalized
|
|
45
46
|
* the same way the policy's safePath normalizes it, or the entries never match.
|
|
46
47
|
*/
|
|
47
|
-
export
|
|
48
|
+
export { stateKey };
|
|
48
49
|
export declare function createCodingTools(policy: CodingToolPolicy): Tool[];
|