@andorra-labs/code 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/account-presentation.js +3 -3
- package/dist/src/agent-execution.d.ts +2 -0
- package/dist/src/agent-execution.js +526 -41
- package/dist/src/agent-mcp-catalog.d.ts +21 -0
- package/dist/src/agent-mcp-catalog.js +40 -0
- package/dist/src/agent-mcp.d.ts +36 -3
- package/dist/src/agent-mcp.js +114 -45
- package/dist/src/app-server/protocol.d.ts +57 -5
- package/dist/src/app-server/protocol.js +18 -1
- package/dist/src/app-server/workspace.d.ts +9 -1
- package/dist/src/app-server/workspace.js +50 -3
- package/dist/src/app-server.d.ts +115 -41
- package/dist/src/app-server.js +1316 -221
- package/dist/src/auth/AuthManager.d.ts +33 -1
- package/dist/src/auth/AuthManager.js +138 -10
- package/dist/src/auth/callback-page.d.ts +4 -0
- package/dist/src/auth/callback-page.js +70 -0
- package/dist/src/auth/callback.d.ts +39 -0
- package/dist/src/auth/callback.js +146 -22
- package/dist/src/auth/index.d.ts +10 -6
- package/dist/src/auth/index.js +2 -2
- package/dist/src/auth/store.d.ts +142 -3
- package/dist/src/auth/store.js +334 -13
- package/dist/src/auth/types.d.ts +17 -1
- package/dist/src/auth-commands.d.ts +11 -2
- package/dist/src/auth-commands.js +14 -7
- package/dist/src/automation-runner.d.ts +9 -0
- package/dist/src/automation-runner.js +22 -1
- package/dist/src/automation-tool.js +18 -3
- package/dist/src/automations.d.ts +5 -0
- package/dist/src/automations.js +11 -1
- package/dist/src/browser-captcha-tool.d.ts +54 -0
- package/dist/src/browser-captcha-tool.js +374 -0
- package/dist/src/browser-panel-tool.d.ts +7 -0
- package/dist/src/browser-panel-tool.js +74 -3
- package/dist/src/browser-runner.js +19 -4
- package/dist/src/browser-server.js +21 -1
- package/dist/src/browser-session.d.ts +16 -0
- package/dist/src/browser-session.js +35 -0
- package/dist/src/browser-ui/app.js +193 -3
- package/dist/src/browser-ui/style.css +15 -1
- package/dist/src/browser-view.d.ts +72 -4
- package/dist/src/browser-view.js +229 -17
- package/dist/src/capabilities.d.ts +9 -3
- package/dist/src/capabilities.js +20 -5
- package/dist/src/capsolver.d.ts +60 -0
- package/dist/src/capsolver.js +101 -0
- package/dist/src/claude-provider.d.ts +6 -0
- package/dist/src/claude-provider.js +34 -3
- package/dist/src/cli-executable.d.ts +33 -0
- package/dist/src/cli-executable.js +64 -0
- package/dist/src/cli-process.d.ts +47 -0
- package/dist/src/cli-process.js +113 -0
- package/dist/src/cli-sign-in.d.ts +68 -0
- package/dist/src/cli-sign-in.js +224 -0
- package/dist/src/cli.js +84 -26
- package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +1 -1
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +5 -5
- package/dist/src/codex-provider.js +12 -0
- package/dist/src/coding-tools.d.ts +5 -0
- package/dist/src/coding-tools.js +98 -53
- package/dist/src/command-output-tap.d.ts +16 -0
- package/dist/src/command-output-tap.js +45 -0
- package/dist/src/command-screens.js +3 -3
- package/dist/src/commands.d.ts +15 -2
- package/dist/src/commands.js +14 -13
- package/dist/src/completion.d.ts +23 -5
- package/dist/src/completion.js +380 -17
- package/dist/src/config.d.ts +61 -0
- package/dist/src/config.js +276 -12
- package/dist/src/context-budget.d.ts +7 -0
- package/dist/src/context-budget.js +18 -1
- package/dist/src/deadline.js +6 -0
- package/dist/src/decision/FactContinuations.d.ts +41 -6
- package/dist/src/decision/FactContinuations.js +211 -64
- package/dist/src/decision/PreparedSteps.js +3 -1
- package/dist/src/decision/checks.d.ts +25 -0
- package/dist/src/decision/checks.js +77 -6
- package/dist/src/delegation-changes.d.ts +109 -0
- package/dist/src/delegation-changes.js +431 -0
- package/dist/src/extensions.d.ts +1 -0
- package/dist/src/extensions.js +16 -3
- package/dist/src/graph-provider-portability.js +2 -2
- package/dist/src/graph-quota.d.ts +1 -1
- package/dist/src/graph-quota.js +1 -1
- package/dist/src/graph-runner.js +35 -21
- package/dist/src/graph-selection.d.ts +6 -0
- package/dist/src/graph-selection.js +10 -0
- package/dist/src/graph-server.d.ts +8 -0
- package/dist/src/graph-server.js +76 -6
- package/dist/src/graph-sync.d.ts +65 -0
- package/dist/src/graph-sync.js +433 -13
- package/dist/src/graph-tool.d.ts +52 -0
- package/dist/src/graph-tool.js +136 -0
- package/dist/src/graph-ui/app.js +272 -50
- package/dist/src/graph-ui/controls.js +6 -0
- package/dist/src/graph-ui/drafts.js +39 -0
- package/dist/src/graph-ui/embed.js +1 -1
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +2 -2
- package/dist/src/graph-ui/skill-picker.js +242 -0
- package/dist/src/graph-ui/studio.css +7 -5
- package/dist/src/graph-ui/style.css +65 -12
- package/dist/src/graphs.d.ts +60 -5
- package/dist/src/graphs.js +191 -37
- package/dist/src/grok-provider.d.ts +50 -0
- package/dist/src/grok-provider.js +186 -0
- package/dist/src/handoffs.d.ts +13 -0
- package/dist/src/handoffs.js +31 -1
- package/dist/src/hardened-runtime.d.ts +4 -4
- package/dist/src/hardened-runtime.js +109 -9
- package/dist/src/managed-sign-in.d.ts +38 -0
- package/dist/src/managed-sign-in.js +169 -0
- package/dist/src/markdown.d.ts +5 -0
- package/dist/src/markdown.js +5 -2
- package/dist/src/mcp.js +11 -0
- package/dist/src/membership.d.ts +8 -1
- package/dist/src/membership.js +15 -5
- package/dist/src/model-metadata.js +14 -2
- package/dist/src/model-override.d.ts +10 -0
- package/dist/src/model-override.js +20 -0
- package/dist/src/opencode-cli-provider.d.ts +122 -0
- package/dist/src/opencode-cli-provider.js +415 -0
- package/dist/src/opencode-provider.js +23 -8
- package/dist/src/palette.d.ts +2 -0
- package/dist/src/palette.js +2 -0
- package/dist/src/permissions.d.ts +19 -1
- package/dist/src/permissions.js +30 -1
- package/dist/src/powershell-pool.d.ts +11 -2
- package/dist/src/powershell-pool.js +34 -5
- package/dist/src/provider-connection.js +36 -0
- package/dist/src/provider-engine.d.ts +2 -1
- package/dist/src/provider-engine.js +64 -13
- package/dist/src/provider-import.js +6 -1
- package/dist/src/provider-keys.d.ts +48 -0
- package/dist/src/provider-keys.js +121 -0
- package/dist/src/provider-settings.js +22 -3
- package/dist/src/providers.d.ts +12 -1
- package/dist/src/providers.js +27 -8
- package/dist/src/pull-requests.d.ts +123 -20
- package/dist/src/pull-requests.js +334 -84
- package/dist/src/qa/qa-authorize.js +9 -1
- package/dist/src/qa/runtime/ProcessManager.d.ts +6 -0
- package/dist/src/qa/runtime/ProcessManager.js +16 -0
- package/dist/src/react-runtime.js +106 -7
- package/dist/src/read-image.d.ts +30 -0
- package/dist/src/read-image.js +97 -0
- package/dist/src/remote/engine-pool.js +1 -1
- package/dist/src/run-progress.js +6 -1
- package/dist/src/run-records.d.ts +133 -27
- package/dist/src/run-records.js +320 -40
- package/dist/src/runtime.d.ts +38 -1
- package/dist/src/runtime.js +27 -4
- package/dist/src/save-lock.d.ts +11 -0
- package/dist/src/save-lock.js +29 -2
- package/dist/src/secret-redaction.d.ts +13 -0
- package/dist/src/secret-redaction.js +71 -0
- package/dist/src/session-summary.d.ts +10 -4
- package/dist/src/session-summary.js +14 -7
- package/dist/src/sessions.js +8 -2
- package/dist/src/shell.js +4 -1
- package/dist/src/side-panel.d.ts +1 -1
- package/dist/src/side-panel.js +1 -1
- package/dist/src/skill-commands.d.ts +2 -0
- package/dist/src/skill-commands.js +2 -0
- package/dist/src/skills/bundled/create-agent/SKILL.md +81 -0
- package/dist/src/skills/bundled/create-skill/SKILL.md +81 -0
- package/dist/src/skills/bundled/doctor/SKILL.md +43 -0
- package/dist/src/skills/bundled/graph-manager/SKILL.md +100 -0
- package/dist/src/skills/bundled/graph-manager/errors.md +38 -0
- package/dist/src/skills/bundled/graph-manager/patterns.md +78 -0
- package/dist/src/skills/bundled/manage-mcp/SKILL.md +75 -0
- package/dist/src/skills/bundled/manage-mcp/probe.md +165 -0
- package/dist/src/skills/bundled/manage-skills/SKILL.md +67 -0
- package/dist/src/skills/bundled/provenance.json +50 -0
- package/dist/src/skills/bundled/write-instructions/SKILL.md +42 -0
- package/dist/src/skills/invocable-skills.d.ts +41 -0
- package/dist/src/skills/invocable-skills.js +49 -0
- package/dist/src/skills/prompt-skills.d.ts +1 -0
- package/dist/src/skills/prompt-skills.js +33 -0
- package/dist/src/skills/runtime-skills.d.ts +4 -0
- package/dist/src/skills/runtime-skills.js +21 -0
- package/dist/src/structured-step.d.ts +55 -0
- package/dist/src/structured-step.js +85 -0
- package/dist/src/subagent-run.d.ts +1 -1
- package/dist/src/subagent-run.js +29 -33
- package/dist/src/telemetry/schema.d.ts +2 -2
- package/dist/src/telemetry/schema.js +3 -2
- package/dist/src/terminal-ui.d.ts +38 -0
- package/dist/src/terminal-ui.js +126 -28
- package/dist/src/timers.d.ts +21 -2
- package/dist/src/timers.js +12 -4
- package/dist/src/tool-dependencies.js +4 -0
- package/dist/src/tool-names.d.ts +18 -0
- package/dist/src/tool-names.js +26 -0
- package/dist/src/tools.d.ts +9 -0
- package/dist/src/tools.js +159 -20
- package/dist/src/trajectory.js +32 -12
- package/dist/src/transcript.js +5 -0
- package/dist/src/types.d.ts +36 -0
- package/dist/src/web-search.d.ts +59 -0
- package/dist/src/web-search.js +216 -0
- package/docs/agents/README.md +2 -2
- package/docs/agents/mcp-server.md +28 -3
- package/docs/agents/subagent-mode.md +7 -4
- package/docs/concepts/README.md +1 -1
- package/docs/concepts/security.md +4 -2
- package/docs/getting-started/accounts.md +15 -4
- package/docs/getting-started/configure-providers.md +30 -3
- package/docs/guides/README.md +1 -0
- package/docs/guides/browser.md +12 -0
- package/docs/guides/desktop-app.md +11 -4
- package/docs/guides/graph-builder.md +9 -1
- package/docs/guides/web-search.md +47 -0
- package/docs/reference/cli.md +4 -3
- package/docs/reference/config.md +4 -4
- package/docs/reference/slash-commands.md +2 -1
- package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +125 -0
- package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +295 -0
- package/docs/superpowers/specs/2026-11-01-pr-section-design.md +7 -0
- package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +206 -0
- package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +291 -0
- package/package.json +1 -1
- package/tests/permissions-test-plan.md +2 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { CliUnavailableError } from './cli-executable.js';
|
|
6
|
+
import { runBoundedCli, stopProcessTree } from './cli-process.js';
|
|
7
|
+
import { resolveTrustedTaskkill } from './shell.js';
|
|
8
|
+
function validAttempt(id) { return typeof id === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(id); }
|
|
9
|
+
/** The first sign-in page and device code in what the CLI printed, held to the allowed hosts. */
|
|
10
|
+
export function readSignInPrompt(output, pageHosts) {
|
|
11
|
+
const plain = output.replace(/\u001b\[[0-9;]*m/g, '');
|
|
12
|
+
let authUrl;
|
|
13
|
+
for (const match of plain.matchAll(/https:\/\/[^\s"'<>]+/g)) {
|
|
14
|
+
try {
|
|
15
|
+
const url = new URL(match[0]);
|
|
16
|
+
if (url.username || url.password || url.port || !pageHosts.some(host => url.hostname === host || url.hostname.endsWith(`.${host}`)))
|
|
17
|
+
continue;
|
|
18
|
+
authUrl = url.href;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
catch { /* not a URL */ }
|
|
22
|
+
}
|
|
23
|
+
const userCode = plain.match(/^\s*([A-Z0-9]{4,5}-[A-Z0-9]{4,5})\s*$/m)?.[1];
|
|
24
|
+
return { ...(authUrl ? { authUrl } : {}), ...(userCode ? { userCode } : {}) };
|
|
25
|
+
}
|
|
26
|
+
const OUTPUT_LIMIT = 64 * 1024;
|
|
27
|
+
/** How long a start waits for the CLI to print its sign-in page before answering. */
|
|
28
|
+
const PROMPT_WAIT_MS = 15_000;
|
|
29
|
+
/**
|
|
30
|
+
* Runs one vendor CLI's own login command and reports what it left behind.
|
|
31
|
+
*
|
|
32
|
+
* The browser ceremony and the tokens belong to the vendor CLI, which stores them where it always
|
|
33
|
+
* does; Andorra never reads or copies them. This class starts the command, surfaces the page and
|
|
34
|
+
* code it prints, forwards a pasted code, stops it on cancel, and asks the CLI who is signed in.
|
|
35
|
+
*/
|
|
36
|
+
export class CliSignIn {
|
|
37
|
+
spec;
|
|
38
|
+
attempt;
|
|
39
|
+
closed = false;
|
|
40
|
+
constructor(spec) {
|
|
41
|
+
this.spec = spec;
|
|
42
|
+
}
|
|
43
|
+
failed(message) { return `${this.spec.product} sign-in did not complete. ${message}`.trim(); }
|
|
44
|
+
async start(attemptId) {
|
|
45
|
+
if (!validAttempt(attemptId))
|
|
46
|
+
return { state: 'error', reason: 'unsupported', message: 'A valid sign-in attempt ID is required.' };
|
|
47
|
+
if (this.closed)
|
|
48
|
+
return { state: 'error', reason: 'unavailable', attemptId, message: `The ${this.spec.product} sign-in service has closed.` };
|
|
49
|
+
const current = this.attempt;
|
|
50
|
+
if (current?.id === attemptId)
|
|
51
|
+
return { ...current.view };
|
|
52
|
+
if (current?.live)
|
|
53
|
+
return { state: 'error', reason: 'busy', attemptId, message: `Another ${this.spec.product} sign-in is already in progress. Finish or cancel it first.` };
|
|
54
|
+
let finish;
|
|
55
|
+
const finished = new Promise(resolve => { finish = resolve; });
|
|
56
|
+
const attempt = { id: attemptId, view: { state: 'starting', attemptId }, live: true, output: '', finished, finish };
|
|
57
|
+
this.attempt = attempt;
|
|
58
|
+
const abandon = (view) => {
|
|
59
|
+
if (attempt.live)
|
|
60
|
+
attempt.view = view;
|
|
61
|
+
attempt.live = false;
|
|
62
|
+
finish();
|
|
63
|
+
return { ...attempt.view };
|
|
64
|
+
};
|
|
65
|
+
let executable;
|
|
66
|
+
try {
|
|
67
|
+
executable = await this.spec.resolveExecutable();
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
return abandon({ state: 'error', reason: 'unavailable', attemptId, message: error instanceof CliUnavailableError ? error.message : this.failed('Check the CLI and try again.') });
|
|
71
|
+
}
|
|
72
|
+
if (!attempt.live)
|
|
73
|
+
return { ...attempt.view };
|
|
74
|
+
try {
|
|
75
|
+
attempt.cwd = await mkdtemp(join(tmpdir(), 'andorra-signin-'));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return abandon({ state: 'error', reason: 'unavailable', attemptId, message: this.failed('Try again.') });
|
|
79
|
+
}
|
|
80
|
+
const env = this.spec.env();
|
|
81
|
+
if (process.platform === 'win32')
|
|
82
|
+
attempt.taskkill = await resolveTrustedTaskkill(attempt.cwd).catch(() => undefined);
|
|
83
|
+
if (!attempt.live) {
|
|
84
|
+
await rm(attempt.cwd, { recursive: true, force: true }).catch(() => { });
|
|
85
|
+
return { ...attempt.view };
|
|
86
|
+
}
|
|
87
|
+
attempt.view = { state: 'waiting', attemptId, ...(this.spec.acceptsCode ? { acceptsCode: true } : {}) };
|
|
88
|
+
const child = spawn(executable.command, [...executable.args, ...this.spec.loginArgs], {
|
|
89
|
+
cwd: attempt.cwd, env, shell: false, windowsHide: true, detached: process.platform !== 'win32', stdio: ['pipe', 'pipe', 'pipe'],
|
|
90
|
+
});
|
|
91
|
+
attempt.child = child;
|
|
92
|
+
let prompted;
|
|
93
|
+
const promptSeen = new Promise(resolve => { prompted = resolve; });
|
|
94
|
+
const read = (chunk) => {
|
|
95
|
+
if (attempt.output.length >= OUTPUT_LIMIT)
|
|
96
|
+
return;
|
|
97
|
+
attempt.output += chunk.toString('utf8').slice(0, OUTPUT_LIMIT - attempt.output.length);
|
|
98
|
+
const prompt = readSignInPrompt(attempt.output, this.spec.pageHosts);
|
|
99
|
+
// A device code is shown to the person anyway, so the attempt keeps it for its own status
|
|
100
|
+
// answers; it often prints a moment after the page.
|
|
101
|
+
if (prompt.userCode && attempt.live && attempt.view.state === 'waiting' && !attempt.view.userCode)
|
|
102
|
+
attempt.view = { ...attempt.view, userCode: prompt.userCode };
|
|
103
|
+
if (prompt.authUrl)
|
|
104
|
+
prompted();
|
|
105
|
+
};
|
|
106
|
+
child.stdout.on('data', read);
|
|
107
|
+
child.stderr.on('data', read);
|
|
108
|
+
child.stdin.on('error', () => { });
|
|
109
|
+
let settled = false;
|
|
110
|
+
const settle = async (code) => {
|
|
111
|
+
if (settled)
|
|
112
|
+
return;
|
|
113
|
+
settled = true;
|
|
114
|
+
prompted();
|
|
115
|
+
clearTimeout(attempt.timer);
|
|
116
|
+
if (attempt.live && attempt.view.state === 'waiting') {
|
|
117
|
+
const account = code === 0 ? await this.spec.status(AbortSignal.timeout(30_000)).catch(() => undefined) : undefined;
|
|
118
|
+
attempt.view = account?.signedIn
|
|
119
|
+
? { state: 'signedIn', attemptId, ...(account.email ? { email: account.email } : {}), ...(account.planType ? { planType: account.planType } : {}) }
|
|
120
|
+
: { state: 'error', reason: code === 0 ? 'unverified' : 'denied', attemptId, message: this.failed('Try again.') };
|
|
121
|
+
}
|
|
122
|
+
attempt.live = false;
|
|
123
|
+
if (attempt.cwd)
|
|
124
|
+
await rm(attempt.cwd, { recursive: true, force: true }).catch(() => { });
|
|
125
|
+
finish();
|
|
126
|
+
};
|
|
127
|
+
child.once('error', () => {
|
|
128
|
+
if (attempt.view.state === 'waiting')
|
|
129
|
+
attempt.view = { state: 'error', reason: 'unavailable', attemptId, message: this.failed('The CLI could not be started.') };
|
|
130
|
+
if (child.pid === undefined)
|
|
131
|
+
void settle(null);
|
|
132
|
+
});
|
|
133
|
+
child.once('close', code => { void settle(code); });
|
|
134
|
+
attempt.timer = setTimeout(() => { void this.stop(attempt, { state: 'error', reason: 'timeout', attemptId, message: `${this.spec.product} sign-in timed out. Try signing in again.` }); }, this.spec.timeoutMs ?? 10 * 60_000);
|
|
135
|
+
// The page is the one thing the person needs from this answer, so the start waits briefly for
|
|
136
|
+
// the CLI to print it. Later status answers never repeat it.
|
|
137
|
+
await Promise.race([promptSeen, new Promise(resolve => setTimeout(resolve, PROMPT_WAIT_MS).unref?.())]);
|
|
138
|
+
// A device-code CLI prints the code just after the page; give it a moment to arrive.
|
|
139
|
+
for (let waited = 0; this.spec.deviceCode && attempt.live && !readSignInPrompt(attempt.output, this.spec.pageHosts).userCode && waited < 3000; waited += 100) {
|
|
140
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
141
|
+
}
|
|
142
|
+
const prompt = readSignInPrompt(attempt.output, this.spec.pageHosts);
|
|
143
|
+
if (attempt.live && attempt.view.state === 'waiting' && prompt.userCode)
|
|
144
|
+
attempt.view = { ...attempt.view, userCode: prompt.userCode };
|
|
145
|
+
return { ...attempt.view, ...(attempt.live && prompt.authUrl ? { authUrl: prompt.authUrl } : {}) };
|
|
146
|
+
}
|
|
147
|
+
/** Forward a code the sign-in page showed to the waiting CLI. */
|
|
148
|
+
async submitCode(attemptId, code) {
|
|
149
|
+
const attempt = this.attempt;
|
|
150
|
+
if (!validAttempt(attemptId) || attempt?.id !== attemptId)
|
|
151
|
+
return { state: 'cancelled', attemptId, message: `This ${this.spec.product} sign-in attempt is no longer active.` };
|
|
152
|
+
if (!this.spec.acceptsCode || !attempt.live || !attempt.child?.stdin?.writable)
|
|
153
|
+
return { ...attempt.view };
|
|
154
|
+
const value = code.trim();
|
|
155
|
+
if (!value || value.length > 2000 || /[\s\u0000-\u001f\u007f]/.test(value))
|
|
156
|
+
return { ...attempt.view, message: 'That code is not valid. Copy the whole code from the sign-in page.' };
|
|
157
|
+
attempt.child.stdin.write(`${value}\n`);
|
|
158
|
+
return { ...attempt.view };
|
|
159
|
+
}
|
|
160
|
+
async status(attemptId) {
|
|
161
|
+
if (attemptId !== undefined && !validAttempt(attemptId))
|
|
162
|
+
return { state: 'error', reason: 'unsupported', message: 'A valid sign-in attempt ID is required.' };
|
|
163
|
+
const attempt = this.attempt;
|
|
164
|
+
if (attemptId !== undefined) {
|
|
165
|
+
if (attempt?.id !== attemptId)
|
|
166
|
+
return { state: 'cancelled', attemptId, message: `This ${this.spec.product} sign-in attempt is no longer active.` };
|
|
167
|
+
return { ...attempt.view };
|
|
168
|
+
}
|
|
169
|
+
if (attempt?.live)
|
|
170
|
+
return { ...attempt.view };
|
|
171
|
+
try {
|
|
172
|
+
const account = await this.spec.status(AbortSignal.timeout(30_000));
|
|
173
|
+
return account.signedIn ? { state: 'signedIn', ...(account.email ? { email: account.email } : {}), ...(account.planType ? { planType: account.planType } : {}) } : { state: 'signedOut' };
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
return { state: 'error', reason: 'unavailable', message: error instanceof CliUnavailableError ? error.message : `${this.spec.product} sign-in status is unavailable. Check the CLI and try again.` };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async cancel(attemptId) {
|
|
180
|
+
if (!validAttempt(attemptId))
|
|
181
|
+
return { state: 'error', reason: 'unsupported', message: 'A valid sign-in attempt ID is required.' };
|
|
182
|
+
const attempt = this.attempt;
|
|
183
|
+
if (attempt?.id !== attemptId)
|
|
184
|
+
return { state: 'cancelled', attemptId, message: `This ${this.spec.product} sign-in attempt is no longer active.` };
|
|
185
|
+
if (attempt.live)
|
|
186
|
+
await this.stop(attempt, { state: 'cancelled', attemptId, message: `${this.spec.product} sign-in cancelled.` });
|
|
187
|
+
return { ...attempt.view };
|
|
188
|
+
}
|
|
189
|
+
/** Run the CLI's own sign-out, then report what its stored login now says. */
|
|
190
|
+
async logout() {
|
|
191
|
+
if (this.attempt?.live)
|
|
192
|
+
return { state: 'error', reason: 'busy', message: `A ${this.spec.product} sign-in is in progress. Finish or cancel it before signing out.` };
|
|
193
|
+
try {
|
|
194
|
+
const executable = await this.spec.resolveExecutable();
|
|
195
|
+
await runBoundedCli(executable, () => [...this.spec.logoutArgs], AbortSignal.timeout(60_000), { env: this.spec.env(), label: `${this.spec.product} CLI`, acceptedExitCodes: [0, 1] });
|
|
196
|
+
const account = await this.spec.status(AbortSignal.timeout(30_000));
|
|
197
|
+
if (account.signedIn)
|
|
198
|
+
return { state: 'error', reason: 'logoutFailed', message: `${this.spec.product} is still signed in. Sign out with its CLI and refresh.` };
|
|
199
|
+
this.attempt = undefined;
|
|
200
|
+
return { state: 'signedOut' };
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
return { state: 'error', reason: 'logoutFailed', message: error instanceof CliUnavailableError ? error.message : `${this.spec.product} sign-out could not be completed. Refresh status and try again.` };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async stop(attempt, view) {
|
|
207
|
+
if (attempt.live)
|
|
208
|
+
attempt.view = view;
|
|
209
|
+
attempt.live = false;
|
|
210
|
+
clearTimeout(attempt.timer);
|
|
211
|
+
if (attempt.child)
|
|
212
|
+
attempt.stopping ??= stopProcessTree(attempt.child, attempt.taskkill);
|
|
213
|
+
else
|
|
214
|
+
attempt.finish();
|
|
215
|
+
await attempt.stopping;
|
|
216
|
+
await attempt.finished;
|
|
217
|
+
}
|
|
218
|
+
async close() {
|
|
219
|
+
this.closed = true;
|
|
220
|
+
const attempt = this.attempt;
|
|
221
|
+
if (attempt?.live)
|
|
222
|
+
await this.stop(attempt, { state: 'cancelled', attemptId: attempt.id, message: `${this.spec.product} sign-in cancelled.` });
|
|
223
|
+
}
|
|
224
|
+
}
|
package/dist/src/cli.js
CHANGED
|
@@ -6,6 +6,7 @@ import { hostedDecisionPolicy } from './decision/hostedPolicy.js';
|
|
|
6
6
|
import { parseArgs, stripVTControlCharacters } from 'node:util';
|
|
7
7
|
import { appendFile, mkdir, open, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises';
|
|
8
8
|
import { existsSync } from 'node:fs';
|
|
9
|
+
import { createInterface } from 'node:readline/promises';
|
|
9
10
|
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
10
11
|
import { fileURLToPath } from 'node:url';
|
|
11
12
|
import { homedir } from 'node:os';
|
|
@@ -18,7 +19,7 @@ import { QA_SYSTEM_GUIDANCE, disposeAllQaProcesses, disposeAllQaPtys, getQaPtyMa
|
|
|
18
19
|
import { disposePooledPowerShell } from './powershell-pool.js';
|
|
19
20
|
import { loadWorkspaceInstructions } from './workspace-instructions.js';
|
|
20
21
|
import { runGraph, stopReasonPhrase } from './runtime.js';
|
|
21
|
-
import { validateGraph } from './graphs.js';
|
|
22
|
+
import { GraphDeletedError, validateGraph } from './graphs.js';
|
|
22
23
|
import { checkGraphModelHealth, formatGraphHealthFailure } from './graph-health.js';
|
|
23
24
|
import { getMembership, loadAccessibleGraph, PaidMembershipRequiredError } from './membership.js';
|
|
24
25
|
import { configuredSurface, createRunHandle, drainTelemetry, graphShape, reportInterruptedRuns, reportRunFinished, reportRunStarted, reportSessionStarted } from './telemetry/surface.js';
|
|
@@ -28,8 +29,11 @@ import { GraphProviderUnavailableError } from './graph-provider-portability.js';
|
|
|
28
29
|
import { MAX_SUBAGENT_TASK_CHARS, SubagentInvalidArgumentError, SubagentProviderNotSetError, SubagentRunInProgressError, SubagentRunner, SubagentSelectionError } from './subagent-run.js';
|
|
29
30
|
/** Shown when a saved per-account graph selection is denied account access at launch or refresh. */
|
|
30
31
|
const GRAPH_FALLBACK_NOTICE = 'The selected graph needs paid account access, which is currently unavailable. Starting with the local Default graph; once access is restored, switch back with /graph.';
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const missingSavedGraph = (error) => error?.code === 'ENOENT';
|
|
33
|
+
/** A stale saved choice should not abort startup after a crash between graph removal and config reset. */
|
|
34
|
+
const graphFallbackReason = (error) => error instanceof FreeTierLimitError || error instanceof GraphDeletedError
|
|
35
|
+
? `${error.message} Starting with the local Default graph.`
|
|
36
|
+
: missingSavedGraph(error) ? 'The selected graph is no longer stored locally. Starting with the Default graph; use /graph to choose another.' : GRAPH_FALLBACK_NOTICE;
|
|
33
37
|
import { configuredGraphSelection, currentGraphSubject } from './graph-selection.js';
|
|
34
38
|
import { launchGraphEditor } from './graph-server.js';
|
|
35
39
|
import { createGraphEditorSession } from './graph-editor-session.js';
|
|
@@ -38,6 +42,13 @@ import { updateInstallation } from './update.js';
|
|
|
38
42
|
import { RunControl } from './run-control.js';
|
|
39
43
|
import { TimerRegistry } from './timers.js';
|
|
40
44
|
import { TerminalUI } from './terminal-ui.js';
|
|
45
|
+
import { listInvocableSkills } from './skills/invocable-skills.js';
|
|
46
|
+
/** Give the `/` popup the skills a person can type. Best effort: a failed read leaves the popup on the built-in commands. */
|
|
47
|
+
function offerSkillCommands(terminal, config, directory) {
|
|
48
|
+
if (!terminal)
|
|
49
|
+
return;
|
|
50
|
+
void listInvocableSkills(config, undefined, directory).then(skills => terminal.setSkillCommands(skills), () => { });
|
|
51
|
+
}
|
|
41
52
|
import { meterStreamedRequest } from './token-rate.js';
|
|
42
53
|
import { attachmentLabel, attachmentReadRoots, attachmentReferenceBlock, pruneAttachments, readClipboardImage, resolveAttachments, writeClipboardText } from './attachments.js';
|
|
43
54
|
import { describeTool, formatEvent, formatRunResult } from './transcript.js';
|
|
@@ -53,7 +64,7 @@ import { isBuiltinSlashCommand } from './skill-commands.js';
|
|
|
53
64
|
import { executeAuthCommand } from './auth-commands.js';
|
|
54
65
|
import { setAuthSignOutReporter } from './auth/index.js';
|
|
55
66
|
import { getAccountPresentation } from './account-presentation.js';
|
|
56
|
-
import { acquireSessionMutationLock, clearOpenRunClaim,
|
|
67
|
+
import { acquireSessionMutationLock, clearOpenRunClaim, createCheckpointFailureTracker, removeRunCheckpoint, RUNNING_TURN_SUMMARY, reconcileInterruptedRuns, runRecordPath, runRecordsDirectory, writeOpenRunRecord, writeRunCheckpoint, writeStudioRunSummary } from './run-records.js';
|
|
57
68
|
import { gitChangeSummary } from './git-summary.js';
|
|
58
69
|
import { writeActivity } from './activity.js';
|
|
59
70
|
import { TodoStore } from './todos.js';
|
|
@@ -241,15 +252,29 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
241
252
|
const machineOutput = argv.includes('--json') || argv[0] === 'subagent' || argv[0] === 'automations';
|
|
242
253
|
setAuthSignOutReporter(error => reportSignOut(machineOutput, undefined, error.message));
|
|
243
254
|
if (argv[0] === 'login' || argv[0] === 'logout' || argv[0] === 'auth') {
|
|
244
|
-
|
|
245
|
-
|
|
255
|
+
const usage = 'Usage: andorra login [--no-browser] | andorra logout [--all] | andorra auth status';
|
|
256
|
+
const noBrowser = argv[0] === 'login' && argv.length === 2 && argv[1] === '--no-browser';
|
|
257
|
+
const everywhere = argv[0] === 'logout' && argv.length === 2 && argv[1] === '--all';
|
|
258
|
+
if ((argv[0] === 'auth' && (argv.length !== 2 || argv[1] !== 'status')) || (argv[0] !== 'auth' && argv.length !== 1 && !noBrowser && !everywhere))
|
|
259
|
+
throw new Error(usage);
|
|
246
260
|
const controller = new AbortController();
|
|
247
261
|
const cancel = () => controller.abort();
|
|
248
262
|
process.once('SIGINT', cancel);
|
|
249
263
|
process.once('SIGTERM', cancel);
|
|
250
264
|
try {
|
|
251
265
|
const print = (message) => process.stdout.write(safeTerminal(message) + '\n');
|
|
252
|
-
|
|
266
|
+
// Where no browser can open here, the address that finishes the sign-in is pasted back on
|
|
267
|
+
// stdin. Only an interactive terminal is asked: piped input is not someone at a keyboard.
|
|
268
|
+
const lines = argv[0] === 'login' && process.stdin.isTTY ? createInterface({ input: process.stdin, output: process.stdout, terminal: true }) : undefined;
|
|
269
|
+
// readline swallows Ctrl+C while it reads; route it to the same cancellation.
|
|
270
|
+
lines?.on('SIGINT', cancel);
|
|
271
|
+
const readCallback = lines ? (prompt, signal) => lines.question(`${prompt} `, { signal }) : undefined;
|
|
272
|
+
try {
|
|
273
|
+
print(await executeAuthCommand(argv[0] === 'auth' ? 'status' : argv[0], { signal: controller.signal, print, noBrowser, readCallback, everywhere }));
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
lines?.close();
|
|
277
|
+
}
|
|
253
278
|
}
|
|
254
279
|
finally {
|
|
255
280
|
process.removeListener('SIGINT', cancel);
|
|
@@ -324,7 +349,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
324
349
|
let terminal;
|
|
325
350
|
const print = (text) => terminal ? terminal.print(text) : process.stdout.write(safeTerminal(text) + '\n');
|
|
326
351
|
if (values.help) {
|
|
327
|
-
print(`Andorra Code\nUsage: andorra [--cwd path] [--provider id] [--model id] [--graph id] [--run-input file.json] [--run-state file.json] [--yolo] [--jev on|off] [--debug]\n andorra --prompt "task" [--json] [--yolo] [--jev on|off] [--debug]\n andorra subagent --prompt "task" [--provider id] [--model id] [--read-only]\n andorra graph [--no-open]\n andorra automations list|run|service|serve\n andorra app-server --stdio\n andorra mcp-server --stdio\n andorra remote serve|status|code|devices|revoke|share|unshare|pair|workspaces|unpair|rotate-cert\n andorra update\n andorra login\n andorra logout\n andorra auth status\n\n${HELP}`);
|
|
352
|
+
print(`Andorra Code\nUsage: andorra [--cwd path] [--provider id] [--model id] [--graph id] [--run-input file.json] [--run-state file.json] [--yolo] [--jev on|off] [--debug]\n andorra --prompt "task" [--json] [--yolo] [--jev on|off] [--debug]\n andorra subagent --prompt "task" [--provider id] [--model id] [--read-only]\n andorra graph [--no-open]\n andorra automations list|run|service|serve\n andorra app-server --stdio\n andorra mcp-server --stdio\n andorra remote serve|status|code|devices|revoke|share|unshare|pair|workspaces|unpair|rotate-cert\n andorra update\n andorra login [--no-browser]\n andorra logout [--all]\n andorra auth status\n\n${HELP}`);
|
|
328
353
|
return 0;
|
|
329
354
|
}
|
|
330
355
|
if (values.version) {
|
|
@@ -482,6 +507,18 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
482
507
|
result.text += `\nThis session started with --jev ${jevOverride ? 'on' : 'off'}, which overrides the saved preference until /jev on|off.`;
|
|
483
508
|
};
|
|
484
509
|
const state = await startupGuard(async () => ({ config, workspace, graph: values.graph ?? configuredGraphSelection(config, await currentGraphSubject()), permissions, yolo: permissions === 'full-access', usage: { inputTokens: 0, outputTokens: 0, requests: 0 }, notify: print, history: [],
|
|
510
|
+
// `/login` on a machine without a browser takes the sign-in address pasted back from another device.
|
|
511
|
+
readLine: async (prompt, signal) => {
|
|
512
|
+
if (!terminal)
|
|
513
|
+
throw new Error('No interactive terminal to read from.');
|
|
514
|
+
return terminal.question(prompt, { signal, title: 'Sign in', history: false });
|
|
515
|
+
},
|
|
516
|
+
// Over SSH only the terminal's own clipboard (OSC 52) reaches the machine the user sits at.
|
|
517
|
+
copyText: (text) => {
|
|
518
|
+
if (!terminal)
|
|
519
|
+
throw new Error('No interactive terminal.');
|
|
520
|
+
terminal.copyText(text, { terminalOnly: Boolean(process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) });
|
|
521
|
+
},
|
|
485
522
|
// Direct /model shares the graph-override question with the /model screen; without a
|
|
486
523
|
// terminal the answer is always "keep", so nothing is ever overridden unobserved.
|
|
487
524
|
confirmModelOverride: async (question) => {
|
|
@@ -495,7 +532,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
495
532
|
} }));
|
|
496
533
|
// A saved per-account graph selection re-checks membership on every launch, so a transient
|
|
497
534
|
// account-service failure or a membership lapse must not deny the whole session: fall back
|
|
498
|
-
// to the local
|
|
535
|
+
// to the local Andorra Agent graph and say so. A selection whose providers this machine
|
|
499
536
|
// cannot serve stays selected instead — the session refresh reports it and the header asks for
|
|
500
537
|
// the model override that runs it, so /model is one command away rather than a re-selection.
|
|
501
538
|
// An explicit --graph flag still fails fast because the caller asked for that exact graph.
|
|
@@ -516,7 +553,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
516
553
|
// binding failure and sets the override hint, so the reason and the way out arrive together.
|
|
517
554
|
if (error instanceof GraphProviderUnavailableError && values.graph === undefined)
|
|
518
555
|
return;
|
|
519
|
-
if (values.graph !== undefined || !(error instanceof PaidMembershipRequiredError))
|
|
556
|
+
if (values.graph !== undefined || (!(error instanceof PaidMembershipRequiredError || error instanceof GraphDeletedError) && !missingSavedGraph(error)))
|
|
520
557
|
throw error;
|
|
521
558
|
state.graph = 'default';
|
|
522
559
|
graphFallbackNotice = graphFallbackReason(error);
|
|
@@ -819,8 +856,9 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
819
856
|
await startupGuard(async () => {
|
|
820
857
|
const selected = config.providers.find(p => p.id === config.provider);
|
|
821
858
|
const codeIntelState = codeIntelLabel((await codeIntel.getStatus()).state);
|
|
822
|
-
terminal = new TerminalUI({ account: { label: 'Checking account...', notice: 'Checking member access. Local
|
|
859
|
+
terminal = new TerminalUI({ account: { label: 'Checking account...', notice: 'Checking member access. Local Andorra Agent remains available.' }, workspace, 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, version: await cliVersion(), branch: await gitBranch(workspace), yolo: state.yolo, permissions: permissionLabel(state.permissions), graphSelection: state.graph ?? 'default', // The refresh below reads the definition of a graph that cannot bind, so construction must not depend on binding it.
|
|
823
860
|
graph: startupGraph ?? await loadGraph(state.graph ?? 'default').catch(() => undefined), ...(codeIntelState ? { codeIntel: codeIntelState } : {}), clipboardImageProbe: readClipboardImage, clipboardTextWriter: writeClipboardText });
|
|
861
|
+
offerSkillCommands(terminal, state.config, directory);
|
|
824
862
|
terminal.setLocalCommandHandler((input, mode, durationMs) => {
|
|
825
863
|
// Local view commands never reach either CLI command loop.
|
|
826
864
|
void debugRecord('command.started', { input, mode });
|
|
@@ -878,7 +916,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
878
916
|
// The refresh path applies the same membership fallback as startup: without it the
|
|
879
917
|
// denial would only print here while state.graph stays on the paid graph and the first
|
|
880
918
|
// task retries the denied selection.
|
|
881
|
-
if (values.graph !== undefined || (state.graph ?? 'default') === 'default' || !(error instanceof PaidMembershipRequiredError))
|
|
919
|
+
if (values.graph !== undefined || (state.graph ?? 'default') === 'default' || (!(error instanceof PaidMembershipRequiredError || error instanceof GraphDeletedError) && !missingSavedGraph(error)))
|
|
882
920
|
throw error;
|
|
883
921
|
state.graph = 'default';
|
|
884
922
|
graphFallbackNotice = graphFallbackReason(error);
|
|
@@ -1106,11 +1144,11 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
1106
1144
|
// state. It is written into the open record so recovery can still join a crash's pair.
|
|
1107
1145
|
const telemetryRunId = randomUUID();
|
|
1108
1146
|
const startedAt = new Date().toISOString();
|
|
1109
|
-
//
|
|
1110
|
-
// re-enters the node with, so
|
|
1111
|
-
//
|
|
1112
|
-
//
|
|
1113
|
-
|
|
1147
|
+
// Which nodes' newest checkpoint could not be written. A checkpoint is the conversation a
|
|
1148
|
+
// resume re-enters the node with, so the node is marked until one of its later writes lands,
|
|
1149
|
+
// and the record carries the mark past a crash: a resume of the attempt warns that the node may
|
|
1150
|
+
// repeat work.
|
|
1151
|
+
const checkpointHealth = createCheckpointFailureTracker(directory, runId);
|
|
1114
1152
|
// The selector this attempt runs on, captured at start. Every record the attempt writes
|
|
1115
1153
|
// carries it: the result's own `graph` is the pinned graph object, whose id is the bundled
|
|
1116
1154
|
// harness's id rather than the selection that loaded it ('default' loads `software-engineer`),
|
|
@@ -1181,7 +1219,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
1181
1219
|
endedAt: new Date().toISOString(),
|
|
1182
1220
|
// The flag a resume consults before it trusts this attempt's conversation: a checkpoint
|
|
1183
1221
|
// that could not be written leaves the node to be re-entered from its opening task.
|
|
1184
|
-
...(
|
|
1222
|
+
...(checkpointHealth.intact ? {} : { checkpointIntegrity: 'failed', checkpointFailures: checkpointHealth.failures }),
|
|
1185
1223
|
...(runInput === undefined ? {} : { runInput }), ...(runState === undefined ? {} : { runState }) };
|
|
1186
1224
|
try {
|
|
1187
1225
|
await writeFile(runRecordPath(directory, runId, 'json'), JSON.stringify(record, null, 2) + '\n', { mode: 0o600 });
|
|
@@ -1273,9 +1311,8 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
1273
1311
|
const persistCheckpoint = (nodeId, messages, state, meta) => {
|
|
1274
1312
|
checkpointWrites = checkpointWrites
|
|
1275
1313
|
.then(() => writeRunCheckpoint(directory, runId, { nodeId, messages, state, revision: state.directionRevision, savedAt: new Date().toISOString(), ...(meta?.generation === undefined ? {} : { generation: meta.generation }), ...(meta?.provider === undefined ? {} : { provider: meta.provider }), ...(meta?.model === undefined ? {} : { model: meta.model }), ...(meta?.routedFrom === undefined ? {} : { routedFrom: meta.routedFrom }) }))
|
|
1276
|
-
.
|
|
1277
|
-
|
|
1278
|
-
await noteCheckpointWriteFailure(directory, runId, error instanceof Error ? error.message : String(error));
|
|
1314
|
+
.then(() => checkpointHealth.succeeded({ nodeId, generation: meta?.generation }), async (error) => {
|
|
1315
|
+
await checkpointHealth.failed({ nodeId, generation: meta?.generation }, error);
|
|
1279
1316
|
process.stderr.write(`Could not write the run checkpoint: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
1280
1317
|
});
|
|
1281
1318
|
// The write is handed back so the runtime can await it: the checkpoint is the conversation a
|
|
@@ -1709,7 +1746,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
1709
1746
|
terminal?.noteGeneratedTokens(usage.outputTokens, origin?.invocationId, origin?.final === true, usage.decodeMs);
|
|
1710
1747
|
terminal?.setStatus(sessionUsage());
|
|
1711
1748
|
},
|
|
1712
|
-
adapter: tracedAdapter(runtimeProvider(selected)), tools: [...createTools(), ...snapshot.tools, ...mcp.tools], history: state.history, instructions, codeIntel, ...decisionPolicy,
|
|
1749
|
+
adapter: tracedAdapter(runtimeProvider(selected)), tools: [...createTools(), ...snapshot.tools, ...mcp.tools], installedSkillClaims: snapshot.claimsSkillName, history: state.history, instructions, codeIntel, ...decisionPolicy,
|
|
1713
1750
|
// Installation-wide bounds. Nothing is set by default, which leaves the run with no
|
|
1714
1751
|
// wall clock and no iteration ceiling; a graph or node bound still narrows these.
|
|
1715
1752
|
limits: resolveConfiguredLimits(config),
|
|
@@ -1774,6 +1811,25 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
1774
1811
|
await runResumed();
|
|
1775
1812
|
}
|
|
1776
1813
|
} : undefined,
|
|
1814
|
+
// Approving a plan flips this session only, the way the engine's own flip does: the saved
|
|
1815
|
+
// workspace default keeps planning the next task, so the footer follows the live mode and
|
|
1816
|
+
// the configuration is never touched. The control is updated with the state, exactly as
|
|
1817
|
+
// `/permissions` does mid-run — `permissionMode()` reads the control first, so a flip of
|
|
1818
|
+
// the state alone would leave every tool still refused.
|
|
1819
|
+
approvePlan: terminal ? async () => {
|
|
1820
|
+
const saved = state.config.workspacePermissions?.[workspacePermissionKey(workspace)];
|
|
1821
|
+
const next = saved === 'ask-for-approval' || saved === 'approve-for-me' || saved === 'full-access' ? saved : 'ask-for-approval';
|
|
1822
|
+
state.permissions = next;
|
|
1823
|
+
state.yolo = next === 'full-access';
|
|
1824
|
+
if (runControl) {
|
|
1825
|
+
runControl.yolo = state.yolo;
|
|
1826
|
+
runControl.permissions = state.permissions;
|
|
1827
|
+
}
|
|
1828
|
+
// An editing mode by construction, so the index resumes if plan mode had suspended it.
|
|
1829
|
+
await state.codeIntel?.setPermissions(next);
|
|
1830
|
+
terminal.setStatus({ permissions: permissionLabel(state.permissions), ...sessionUsage() });
|
|
1831
|
+
return next;
|
|
1832
|
+
} : undefined,
|
|
1777
1833
|
approve: async (name, args, signal) => {
|
|
1778
1834
|
if (!terminal || exiting)
|
|
1779
1835
|
return false;
|
|
@@ -1821,7 +1877,7 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
1821
1877
|
endedAt: new Date().toISOString(),
|
|
1822
1878
|
// The flag a resume consults before it trusts this attempt's conversation: a checkpoint
|
|
1823
1879
|
// that could not be written leaves the node to be re-entered from its opening task.
|
|
1824
|
-
...(
|
|
1880
|
+
...(checkpointHealth.intact ? {} : { checkpointIntegrity: 'failed', checkpointFailures: checkpointHealth.failures }),
|
|
1825
1881
|
...(runInput === undefined ? {} : { runInput }), ...(runState === undefined ? {} : { runState }) };
|
|
1826
1882
|
await writeFile(runRecordPath(directory, result.id, 'json'), JSON.stringify(finishedRecord, null, 2) + '\n', { mode: 0o600 });
|
|
1827
1883
|
finishTelemetry(result.status, result.reason, result);
|
|
@@ -2232,6 +2288,8 @@ export async function main(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
2232
2288
|
}
|
|
2233
2289
|
if (/^\/graph(?:\s|$)/.test(line) || result.clear && /^\/(providers|model)(?:\s|$)/.test(line))
|
|
2234
2290
|
await refreshGraphStatus();
|
|
2291
|
+
if (/^\/(skills|plugins)(?:\s|$)/.test(line))
|
|
2292
|
+
offerSkillCommands(terminal, state.config, directory);
|
|
2235
2293
|
trajectory.addSecrets(providerSecrets(config.providers));
|
|
2236
2294
|
refreshStatus();
|
|
2237
2295
|
}
|
|
@@ -2404,7 +2462,7 @@ export function subagentExitCode(outcome, signals) {
|
|
|
2404
2462
|
/**
|
|
2405
2463
|
* `andorra subagent`: one Andorra run driven by an external host (Claude CLI, Codex CLI).
|
|
2406
2464
|
*
|
|
2407
|
-
* The graph is always the bundled
|
|
2465
|
+
* The graph is always the bundled Andorra Agent harness and the provider/model is mandatory:
|
|
2408
2466
|
* the call's own flags win, the saved `/subagent` setting is next, and with neither the command
|
|
2409
2467
|
* answers on stdout with the PROVIDER_NOT_SET envelope carrying every configured provider and
|
|
2410
2468
|
* model, so a Bash-spawning host can ask its user and retry with the pick. Stdout stays reserved
|
|
@@ -2428,7 +2486,7 @@ async function runSubagentCommand(argv) {
|
|
|
2428
2486
|
continue;
|
|
2429
2487
|
const name = argument.split('=')[0];
|
|
2430
2488
|
if (!accepted.includes(name)) {
|
|
2431
|
-
fail('INVALID_ARGUMENTS', `Unknown option ${name}. andorra subagent accepts --prompt, --provider, --model, --read-only and --cwd, and always runs the
|
|
2489
|
+
fail('INVALID_ARGUMENTS', `Unknown option ${name}. andorra subagent accepts --prompt, --provider, --model, --read-only and --cwd, and always runs the Andorra Agent default graph.`);
|
|
2432
2490
|
return 1;
|
|
2433
2491
|
}
|
|
2434
2492
|
if (valued.has(name) && !argument.includes('='))
|
|
@@ -2452,7 +2510,7 @@ async function runSubagentCommand(argv) {
|
|
|
2452
2510
|
}
|
|
2453
2511
|
if (values.help) {
|
|
2454
2512
|
process.stdout.write('Usage: andorra subagent --prompt "task" [--provider id] [--model id] [--read-only] [--cwd path]\n'
|
|
2455
|
-
+ 'Runs the built-in
|
|
2513
|
+
+ 'Runs the built-in Andorra Agent graph once and prints the run result as one JSON line on stdout.\n'
|
|
2456
2514
|
+ 'Provider/model is mandatory: pass --provider/--model, or set it in Andorra with /subagent. Without either,\n'
|
|
2457
2515
|
+ 'the output is a PROVIDER_NOT_SET error listing every configured provider and model — show that list to\n'
|
|
2458
2516
|
+ 'the user, ask which pair to use, and retry with --provider and --model.\n'
|
|
@@ -102,7 +102,7 @@ export declare class CodeIntelligenceManager {
|
|
|
102
102
|
setEnabled(enabled: boolean): Promise<void>;
|
|
103
103
|
rebuild(signal?: AbortSignal): Promise<void>;
|
|
104
104
|
dispose(): Promise<void>;
|
|
105
|
-
/** Suspend cache writers before publishing Read Only; retain the user's CodeGraph preference. */
|
|
105
|
+
/** Suspend cache writers before publishing Read Only or Plan; retain the user's CodeGraph preference. */
|
|
106
106
|
setPermissions(permissions: PermissionMode | undefined): Promise<void>;
|
|
107
107
|
}
|
|
108
108
|
export {};
|
|
@@ -132,9 +132,9 @@ export class CodeIntelligenceManager {
|
|
|
132
132
|
: (config.enabledRepos ?? []).includes(repositoryId);
|
|
133
133
|
const manager = new CodeIntelligenceManager(options.workspace, repositoryRoot, options.readinessMs ?? 10_000, options.onEvent, enabled, options.syncTimeoutMs);
|
|
134
134
|
manager.providerFactory = options.providerFactory ?? (() => new CodeGraphProvider({ onEvent: event => manager.onProviderEvent(event) }));
|
|
135
|
-
manager.readOnly = options.permissions === 'read-only';
|
|
135
|
+
manager.readOnly = options.permissions === 'read-only' || options.permissions === 'plan';
|
|
136
136
|
if (manager.readOnly) {
|
|
137
|
-
await manager.emit('codeintel.state', { state: 'uninitialized', available: false, detail: 'Code intelligence is suspended in Read Only mode because its cache requires writes' });
|
|
137
|
+
await manager.emit('codeintel.state', { state: 'uninitialized', available: false, detail: options.permissions === 'plan' ? 'Code intelligence is suspended in Plan mode because its cache requires writes' : 'Code intelligence is suspended in Read Only mode because its cache requires writes' });
|
|
138
138
|
return manager;
|
|
139
139
|
}
|
|
140
140
|
if (!enabled) {
|
|
@@ -597,14 +597,14 @@ export class CodeIntelligenceManager {
|
|
|
597
597
|
for (const entry of entries)
|
|
598
598
|
await entry.provider.dispose().catch(() => { });
|
|
599
599
|
}
|
|
600
|
-
/** Suspend cache writers before publishing Read Only; retain the user's CodeGraph preference. */
|
|
600
|
+
/** Suspend cache writers before publishing Read Only or Plan; retain the user's CodeGraph preference. */
|
|
601
601
|
async setPermissions(permissions) {
|
|
602
|
-
if (permissions === 'read-only') {
|
|
602
|
+
if (permissions === 'read-only' || permissions === 'plan') {
|
|
603
603
|
this.readOnly = true;
|
|
604
604
|
for (const entry of this.entries.values())
|
|
605
605
|
await entry.provider.dispose({ requireIdle: true });
|
|
606
606
|
this.entries.clear();
|
|
607
|
-
await this.emit('codeintel.state', { state: 'uninitialized', available: false, detail: 'Code intelligence is suspended in Read Only mode because its cache requires writes' });
|
|
607
|
+
await this.emit('codeintel.state', { state: 'uninitialized', available: false, detail: permissions === 'plan' ? 'Code intelligence is suspended in Plan mode because its cache requires writes' : 'Code intelligence is suspended in Read Only mode because its cache requires writes' });
|
|
608
608
|
return;
|
|
609
609
|
}
|
|
610
610
|
if (!this.readOnly)
|
|
@@ -101,6 +101,18 @@ export function createCodexAdapter(config, connect = codexConnectFor(config)) {
|
|
|
101
101
|
const config = { ...codexInferenceConfig };
|
|
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
|
+
// 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
|
|
107
|
+
// Codex CLI exposes no token-level output bound — strict config rejects
|
|
108
|
+
// `model_max_output_tokens` as an unknown field), and the caller's deadline bounds the
|
|
109
|
+
// rest. An ordinary run names no bound and keeps the model's own effort. An unusable
|
|
110
|
+
// allowance is refused before a thread is spent on it.
|
|
111
|
+
if (request.maxTokens !== undefined) {
|
|
112
|
+
if (!Number.isSafeInteger(request.maxTokens) || request.maxTokens < 1)
|
|
113
|
+
throw new Error('Invalid auxiliary output allowance.');
|
|
114
|
+
config.model_reasoning_effort = 'minimal';
|
|
115
|
+
}
|
|
104
116
|
const started = await rpc.request('thread/start', {
|
|
105
117
|
model: request.model, modelProvider: 'openai', ephemeral: true, cwd,
|
|
106
118
|
environments: [], runtimeWorkspaceRoots: [], selectedCapabilityRoots: [], dynamicTools: [],
|
|
@@ -3,6 +3,11 @@ import type { Tool, ToolContext } from './types.js';
|
|
|
3
3
|
export interface CodingToolPolicy {
|
|
4
4
|
safePath(context: ToolContext, name: string, missing?: boolean): Promise<string>;
|
|
5
5
|
read(context: ToolContext, name: string): Promise<string>;
|
|
6
|
+
/** The bytes of a supported image file, by signature; undefined for anything else. */
|
|
7
|
+
readImage?(context: ToolContext, name: string): Promise<{
|
|
8
|
+
mimeType: string;
|
|
9
|
+
bytes: Buffer;
|
|
10
|
+
} | undefined>;
|
|
6
11
|
atomicWrite(context: ToolContext, name: string, content: string, expected?: string): Promise<void>;
|
|
7
12
|
authorize(name: string, args: Record<string, unknown>, context: ToolContext): Promise<void>;
|
|
8
13
|
files(context: ToolContext, directory: string): AsyncIterable<string>;
|