@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.
Files changed (224) hide show
  1. package/dist/src/account-presentation.js +3 -3
  2. package/dist/src/agent-execution.d.ts +2 -0
  3. package/dist/src/agent-execution.js +526 -41
  4. package/dist/src/agent-mcp-catalog.d.ts +21 -0
  5. package/dist/src/agent-mcp-catalog.js +40 -0
  6. package/dist/src/agent-mcp.d.ts +36 -3
  7. package/dist/src/agent-mcp.js +114 -45
  8. package/dist/src/app-server/protocol.d.ts +57 -5
  9. package/dist/src/app-server/protocol.js +18 -1
  10. package/dist/src/app-server/workspace.d.ts +9 -1
  11. package/dist/src/app-server/workspace.js +50 -3
  12. package/dist/src/app-server.d.ts +115 -41
  13. package/dist/src/app-server.js +1316 -221
  14. package/dist/src/auth/AuthManager.d.ts +33 -1
  15. package/dist/src/auth/AuthManager.js +138 -10
  16. package/dist/src/auth/callback-page.d.ts +4 -0
  17. package/dist/src/auth/callback-page.js +70 -0
  18. package/dist/src/auth/callback.d.ts +39 -0
  19. package/dist/src/auth/callback.js +146 -22
  20. package/dist/src/auth/index.d.ts +10 -6
  21. package/dist/src/auth/index.js +2 -2
  22. package/dist/src/auth/store.d.ts +142 -3
  23. package/dist/src/auth/store.js +334 -13
  24. package/dist/src/auth/types.d.ts +17 -1
  25. package/dist/src/auth-commands.d.ts +11 -2
  26. package/dist/src/auth-commands.js +14 -7
  27. package/dist/src/automation-runner.d.ts +9 -0
  28. package/dist/src/automation-runner.js +22 -1
  29. package/dist/src/automation-tool.js +18 -3
  30. package/dist/src/automations.d.ts +5 -0
  31. package/dist/src/automations.js +11 -1
  32. package/dist/src/browser-captcha-tool.d.ts +54 -0
  33. package/dist/src/browser-captcha-tool.js +374 -0
  34. package/dist/src/browser-panel-tool.d.ts +7 -0
  35. package/dist/src/browser-panel-tool.js +74 -3
  36. package/dist/src/browser-runner.js +19 -4
  37. package/dist/src/browser-server.js +21 -1
  38. package/dist/src/browser-session.d.ts +16 -0
  39. package/dist/src/browser-session.js +35 -0
  40. package/dist/src/browser-ui/app.js +193 -3
  41. package/dist/src/browser-ui/style.css +15 -1
  42. package/dist/src/browser-view.d.ts +72 -4
  43. package/dist/src/browser-view.js +229 -17
  44. package/dist/src/capabilities.d.ts +9 -3
  45. package/dist/src/capabilities.js +20 -5
  46. package/dist/src/capsolver.d.ts +60 -0
  47. package/dist/src/capsolver.js +101 -0
  48. package/dist/src/claude-provider.d.ts +6 -0
  49. package/dist/src/claude-provider.js +34 -3
  50. package/dist/src/cli-executable.d.ts +33 -0
  51. package/dist/src/cli-executable.js +64 -0
  52. package/dist/src/cli-process.d.ts +47 -0
  53. package/dist/src/cli-process.js +113 -0
  54. package/dist/src/cli-sign-in.d.ts +68 -0
  55. package/dist/src/cli-sign-in.js +224 -0
  56. package/dist/src/cli.js +84 -26
  57. package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +1 -1
  58. package/dist/src/code-intelligence/CodeIntelligenceManager.js +5 -5
  59. package/dist/src/codex-provider.js +12 -0
  60. package/dist/src/coding-tools.d.ts +5 -0
  61. package/dist/src/coding-tools.js +98 -53
  62. package/dist/src/command-output-tap.d.ts +16 -0
  63. package/dist/src/command-output-tap.js +45 -0
  64. package/dist/src/command-screens.js +3 -3
  65. package/dist/src/commands.d.ts +15 -2
  66. package/dist/src/commands.js +14 -13
  67. package/dist/src/completion.d.ts +23 -5
  68. package/dist/src/completion.js +380 -17
  69. package/dist/src/config.d.ts +61 -0
  70. package/dist/src/config.js +276 -12
  71. package/dist/src/context-budget.d.ts +7 -0
  72. package/dist/src/context-budget.js +18 -1
  73. package/dist/src/deadline.js +6 -0
  74. package/dist/src/decision/FactContinuations.d.ts +41 -6
  75. package/dist/src/decision/FactContinuations.js +211 -64
  76. package/dist/src/decision/PreparedSteps.js +3 -1
  77. package/dist/src/decision/checks.d.ts +25 -0
  78. package/dist/src/decision/checks.js +77 -6
  79. package/dist/src/delegation-changes.d.ts +109 -0
  80. package/dist/src/delegation-changes.js +431 -0
  81. package/dist/src/extensions.d.ts +1 -0
  82. package/dist/src/extensions.js +16 -3
  83. package/dist/src/graph-provider-portability.js +2 -2
  84. package/dist/src/graph-quota.d.ts +1 -1
  85. package/dist/src/graph-quota.js +1 -1
  86. package/dist/src/graph-runner.js +35 -21
  87. package/dist/src/graph-selection.d.ts +6 -0
  88. package/dist/src/graph-selection.js +10 -0
  89. package/dist/src/graph-server.d.ts +8 -0
  90. package/dist/src/graph-server.js +76 -6
  91. package/dist/src/graph-sync.d.ts +65 -0
  92. package/dist/src/graph-sync.js +433 -13
  93. package/dist/src/graph-tool.d.ts +52 -0
  94. package/dist/src/graph-tool.js +136 -0
  95. package/dist/src/graph-ui/app.js +272 -50
  96. package/dist/src/graph-ui/controls.js +6 -0
  97. package/dist/src/graph-ui/drafts.js +39 -0
  98. package/dist/src/graph-ui/embed.js +1 -1
  99. package/dist/src/graph-ui/icons.js +1 -0
  100. package/dist/src/graph-ui/index.html +2 -2
  101. package/dist/src/graph-ui/skill-picker.js +242 -0
  102. package/dist/src/graph-ui/studio.css +7 -5
  103. package/dist/src/graph-ui/style.css +65 -12
  104. package/dist/src/graphs.d.ts +60 -5
  105. package/dist/src/graphs.js +191 -37
  106. package/dist/src/grok-provider.d.ts +50 -0
  107. package/dist/src/grok-provider.js +186 -0
  108. package/dist/src/handoffs.d.ts +13 -0
  109. package/dist/src/handoffs.js +31 -1
  110. package/dist/src/hardened-runtime.d.ts +4 -4
  111. package/dist/src/hardened-runtime.js +109 -9
  112. package/dist/src/managed-sign-in.d.ts +38 -0
  113. package/dist/src/managed-sign-in.js +169 -0
  114. package/dist/src/markdown.d.ts +5 -0
  115. package/dist/src/markdown.js +5 -2
  116. package/dist/src/mcp.js +11 -0
  117. package/dist/src/membership.d.ts +8 -1
  118. package/dist/src/membership.js +15 -5
  119. package/dist/src/model-metadata.js +14 -2
  120. package/dist/src/model-override.d.ts +10 -0
  121. package/dist/src/model-override.js +20 -0
  122. package/dist/src/opencode-cli-provider.d.ts +122 -0
  123. package/dist/src/opencode-cli-provider.js +415 -0
  124. package/dist/src/opencode-provider.js +23 -8
  125. package/dist/src/palette.d.ts +2 -0
  126. package/dist/src/palette.js +2 -0
  127. package/dist/src/permissions.d.ts +19 -1
  128. package/dist/src/permissions.js +30 -1
  129. package/dist/src/powershell-pool.d.ts +11 -2
  130. package/dist/src/powershell-pool.js +34 -5
  131. package/dist/src/provider-connection.js +36 -0
  132. package/dist/src/provider-engine.d.ts +2 -1
  133. package/dist/src/provider-engine.js +64 -13
  134. package/dist/src/provider-import.js +6 -1
  135. package/dist/src/provider-keys.d.ts +48 -0
  136. package/dist/src/provider-keys.js +121 -0
  137. package/dist/src/provider-settings.js +22 -3
  138. package/dist/src/providers.d.ts +12 -1
  139. package/dist/src/providers.js +27 -8
  140. package/dist/src/pull-requests.d.ts +123 -20
  141. package/dist/src/pull-requests.js +334 -84
  142. package/dist/src/qa/qa-authorize.js +9 -1
  143. package/dist/src/qa/runtime/ProcessManager.d.ts +6 -0
  144. package/dist/src/qa/runtime/ProcessManager.js +16 -0
  145. package/dist/src/react-runtime.js +106 -7
  146. package/dist/src/read-image.d.ts +30 -0
  147. package/dist/src/read-image.js +97 -0
  148. package/dist/src/remote/engine-pool.js +1 -1
  149. package/dist/src/run-progress.js +6 -1
  150. package/dist/src/run-records.d.ts +133 -27
  151. package/dist/src/run-records.js +320 -40
  152. package/dist/src/runtime.d.ts +38 -1
  153. package/dist/src/runtime.js +27 -4
  154. package/dist/src/save-lock.d.ts +11 -0
  155. package/dist/src/save-lock.js +29 -2
  156. package/dist/src/secret-redaction.d.ts +13 -0
  157. package/dist/src/secret-redaction.js +71 -0
  158. package/dist/src/session-summary.d.ts +10 -4
  159. package/dist/src/session-summary.js +14 -7
  160. package/dist/src/sessions.js +8 -2
  161. package/dist/src/shell.js +4 -1
  162. package/dist/src/side-panel.d.ts +1 -1
  163. package/dist/src/side-panel.js +1 -1
  164. package/dist/src/skill-commands.d.ts +2 -0
  165. package/dist/src/skill-commands.js +2 -0
  166. package/dist/src/skills/bundled/create-agent/SKILL.md +81 -0
  167. package/dist/src/skills/bundled/create-skill/SKILL.md +81 -0
  168. package/dist/src/skills/bundled/doctor/SKILL.md +43 -0
  169. package/dist/src/skills/bundled/graph-manager/SKILL.md +100 -0
  170. package/dist/src/skills/bundled/graph-manager/errors.md +38 -0
  171. package/dist/src/skills/bundled/graph-manager/patterns.md +78 -0
  172. package/dist/src/skills/bundled/manage-mcp/SKILL.md +75 -0
  173. package/dist/src/skills/bundled/manage-mcp/probe.md +165 -0
  174. package/dist/src/skills/bundled/manage-skills/SKILL.md +67 -0
  175. package/dist/src/skills/bundled/provenance.json +50 -0
  176. package/dist/src/skills/bundled/write-instructions/SKILL.md +42 -0
  177. package/dist/src/skills/invocable-skills.d.ts +41 -0
  178. package/dist/src/skills/invocable-skills.js +49 -0
  179. package/dist/src/skills/prompt-skills.d.ts +1 -0
  180. package/dist/src/skills/prompt-skills.js +33 -0
  181. package/dist/src/skills/runtime-skills.d.ts +4 -0
  182. package/dist/src/skills/runtime-skills.js +21 -0
  183. package/dist/src/structured-step.d.ts +55 -0
  184. package/dist/src/structured-step.js +85 -0
  185. package/dist/src/subagent-run.d.ts +1 -1
  186. package/dist/src/subagent-run.js +29 -33
  187. package/dist/src/telemetry/schema.d.ts +2 -2
  188. package/dist/src/telemetry/schema.js +3 -2
  189. package/dist/src/terminal-ui.d.ts +38 -0
  190. package/dist/src/terminal-ui.js +126 -28
  191. package/dist/src/timers.d.ts +21 -2
  192. package/dist/src/timers.js +12 -4
  193. package/dist/src/tool-dependencies.js +4 -0
  194. package/dist/src/tool-names.d.ts +18 -0
  195. package/dist/src/tool-names.js +26 -0
  196. package/dist/src/tools.d.ts +9 -0
  197. package/dist/src/tools.js +159 -20
  198. package/dist/src/trajectory.js +32 -12
  199. package/dist/src/transcript.js +5 -0
  200. package/dist/src/types.d.ts +36 -0
  201. package/dist/src/web-search.d.ts +59 -0
  202. package/dist/src/web-search.js +216 -0
  203. package/docs/agents/README.md +2 -2
  204. package/docs/agents/mcp-server.md +28 -3
  205. package/docs/agents/subagent-mode.md +7 -4
  206. package/docs/concepts/README.md +1 -1
  207. package/docs/concepts/security.md +4 -2
  208. package/docs/getting-started/accounts.md +15 -4
  209. package/docs/getting-started/configure-providers.md +30 -3
  210. package/docs/guides/README.md +1 -0
  211. package/docs/guides/browser.md +12 -0
  212. package/docs/guides/desktop-app.md +11 -4
  213. package/docs/guides/graph-builder.md +9 -1
  214. package/docs/guides/web-search.md +47 -0
  215. package/docs/reference/cli.md +4 -3
  216. package/docs/reference/config.md +4 -4
  217. package/docs/reference/slash-commands.md +2 -1
  218. package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +125 -0
  219. package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +295 -0
  220. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +7 -0
  221. package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +206 -0
  222. package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +291 -0
  223. package/package.json +1 -1
  224. 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
- /** The free allowance names its own reason; any other membership refusal is an access outage. */
32
- const graphFallbackReason = (error) => error instanceof FreeTierLimitError ? `${error.message} Starting with the local Default graph.` : GRAPH_FALLBACK_NOTICE;
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, noteCheckpointWriteFailure, removeRunCheckpoint, RUNNING_TURN_SUMMARY, reconcileInterruptedRuns, runRecordPath, runRecordsDirectory, writeOpenRunRecord, writeRunCheckpoint, writeStudioRunSummary } from './run-records.js';
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
- if ((argv[0] === 'auth' && (argv.length !== 2 || argv[1] !== 'status')) || (argv[0] !== 'auth' && argv.length !== 1))
245
- throw new Error('Usage: andorra login | andorra logout | andorra auth status');
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
- print(await executeAuthCommand(argv[0] === 'auth' ? 'status' : argv[0], { signal: controller.signal, print }));
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 Software Engineer graph and say so. A selection whose providers this machine
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 Software Engineer 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.
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
- // Whether a checkpoint could not be written. A checkpoint is the conversation a resume
1110
- // re-enters the node with, so a run whose checkpoint failed is one no resume may replay: the
1111
- // resume would re-enter the node from its opening task and repeat the tool calls it had
1112
- // already made. The failure is marked, and the record carries it past a crash.
1113
- let checkpointFailed = false;
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
- ...(checkpointFailed ? { checkpointIntegrity: 'failed' } : {}),
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
- .catch(async (error) => {
1277
- checkpointFailed = true;
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
- ...(checkpointFailed ? { checkpointIntegrity: 'failed' } : {}),
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 Software Engineer harness and the provider/model is mandatory:
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 Software Engineer default graph.`);
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 Software Engineer graph once and prints the run result as one JSON line on stdout.\n'
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>;