@andorra-labs/code 0.1.13 → 0.1.15

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 (168) hide show
  1. package/dist/src/account-presentation.js +4 -1
  2. package/dist/src/acp-agent.d.ts +54 -0
  3. package/dist/src/acp-agent.js +991 -0
  4. package/dist/src/agent-execution.js +304 -140
  5. package/dist/src/agent-mcp-catalog.js +2 -0
  6. package/dist/src/agent-mcp.d.ts +2 -0
  7. package/dist/src/agent-mcp.js +86 -4
  8. package/dist/src/andorra/endpoint.d.ts +7 -0
  9. package/dist/src/andorra/endpoint.js +46 -0
  10. package/dist/src/andorra/entry.d.ts +21 -0
  11. package/dist/src/andorra/entry.js +118 -0
  12. package/dist/src/andorra/errors.d.ts +2 -0
  13. package/dist/src/andorra/errors.js +39 -0
  14. package/dist/src/andorra/hosted.d.ts +55 -0
  15. package/dist/src/andorra/hosted.js +130 -0
  16. package/dist/src/andorra/monitor.d.ts +151 -0
  17. package/dist/src/andorra/monitor.js +393 -0
  18. package/dist/src/andorra/notices.d.ts +16 -0
  19. package/dist/src/andorra/notices.js +38 -0
  20. package/dist/src/andorra/opt-in.d.ts +58 -0
  21. package/dist/src/andorra/opt-in.js +112 -0
  22. package/dist/src/andorra/request-watch.d.ts +6 -0
  23. package/dist/src/andorra/request-watch.js +10 -0
  24. package/dist/src/andorra/state.d.ts +86 -0
  25. package/dist/src/andorra/state.js +238 -0
  26. package/dist/src/andorra/terminal.d.ts +70 -0
  27. package/dist/src/andorra/terminal.js +125 -0
  28. package/dist/src/andorra/usage-format.d.ts +9 -0
  29. package/dist/src/andorra/usage-format.js +19 -0
  30. package/dist/src/anthropic-credentials.js +9 -1
  31. package/dist/src/app-server/protocol.d.ts +10 -2
  32. package/dist/src/app-server/protocol.js +1 -1
  33. package/dist/src/app-server/workspace.d.ts +1 -0
  34. package/dist/src/app-server/workspace.js +141 -10
  35. package/dist/src/app-server.d.ts +35 -0
  36. package/dist/src/app-server.js +377 -124
  37. package/dist/src/auth/AuthManager.d.ts +9 -0
  38. package/dist/src/auth/AuthManager.js +164 -24
  39. package/dist/src/auth/deployment.d.ts +1 -0
  40. package/dist/src/auth/deployment.js +1 -0
  41. package/dist/src/auth/index.d.ts +1 -1
  42. package/dist/src/auth/index.js +1 -1
  43. package/dist/src/auth/store.d.ts +26 -0
  44. package/dist/src/auth/store.js +34 -1
  45. package/dist/src/browser-bridge.d.ts +1 -0
  46. package/dist/src/browser-bridge.js +5 -2
  47. package/dist/src/browser-external-app.d.ts +27 -0
  48. package/dist/src/browser-external-app.js +60 -0
  49. package/dist/src/browser-panel-tool.d.ts +6 -0
  50. package/dist/src/browser-panel-tool.js +36 -0
  51. package/dist/src/browser-runner.js +1 -1
  52. package/dist/src/browser-server.d.ts +5 -0
  53. package/dist/src/browser-server.js +27 -3
  54. package/dist/src/browser-stealth.d.ts +19 -1
  55. package/dist/src/browser-stealth.js +23 -3
  56. package/dist/src/browser-ui/tokens.css +4 -4
  57. package/dist/src/browser-view.d.ts +81 -0
  58. package/dist/src/browser-view.js +289 -18
  59. package/dist/src/bug-report.d.ts +81 -0
  60. package/dist/src/bug-report.js +235 -0
  61. package/dist/src/claude-provider.d.ts +2 -1
  62. package/dist/src/claude-provider.js +10 -8
  63. package/dist/src/cli-sign-in.d.ts +3 -1
  64. package/dist/src/cli-sign-in.js +4 -1
  65. package/dist/src/cli.js +205 -58
  66. package/dist/src/coding-tools.js +7 -7
  67. package/dist/src/command-screens.d.ts +26 -3
  68. package/dist/src/command-screens.js +323 -85
  69. package/dist/src/commands.d.ts +7 -1
  70. package/dist/src/commands.js +79 -27
  71. package/dist/src/completion-gates.d.ts +22 -0
  72. package/dist/src/completion-gates.js +11 -0
  73. package/dist/src/config.d.ts +11 -1
  74. package/dist/src/config.js +134 -3
  75. package/dist/src/dashboard-view.d.ts +2 -0
  76. package/dist/src/dashboard-view.js +11 -2
  77. package/dist/src/decision/PreparedSteps.js +1 -1
  78. package/dist/src/decision/applyToolMenu.js +1 -1
  79. package/dist/src/decision/toolFamilies.js +1 -1
  80. package/dist/src/decision/types.d.ts +1 -0
  81. package/dist/src/google-provider.d.ts +31 -0
  82. package/dist/src/google-provider.js +153 -0
  83. package/dist/src/graph-health.d.ts +11 -0
  84. package/dist/src/graph-health.js +36 -4
  85. package/dist/src/graph-manager-chat.d.ts +33 -0
  86. package/dist/src/graph-manager-chat.js +165 -6
  87. package/dist/src/graph-runner.js +27 -0
  88. package/dist/src/graph-selection.js +2 -1
  89. package/dist/src/graph-sync.d.ts +1 -0
  90. package/dist/src/graph-sync.js +93 -34
  91. package/dist/src/graph-tool.d.ts +2 -0
  92. package/dist/src/graph-tool.js +2 -2
  93. package/dist/src/graph-ui/app.js +92 -10
  94. package/dist/src/graph-ui/edge-router.js +121 -53
  95. package/dist/src/graph-ui/manager.js +40 -5
  96. package/dist/src/graph-ui/style.css +5 -2
  97. package/dist/src/graph-ui/tokens.css +4 -4
  98. package/dist/src/graph-visibility.d.ts +31 -0
  99. package/dist/src/graph-visibility.js +102 -0
  100. package/dist/src/graphs.js +1 -3
  101. package/dist/src/hardened-runtime.js +1 -1
  102. package/dist/src/live-model.d.ts +24 -0
  103. package/dist/src/live-model.js +37 -0
  104. package/dist/src/managed-sign-in.d.ts +1 -0
  105. package/dist/src/managed-sign-in.js +13 -0
  106. package/dist/src/membership-errors.d.ts +2 -0
  107. package/dist/src/membership-errors.js +6 -2
  108. package/dist/src/membership.d.ts +13 -2
  109. package/dist/src/membership.js +39 -8
  110. package/dist/src/model-context-windows.d.ts +2 -0
  111. package/dist/src/model-context-windows.js +24 -0
  112. package/dist/src/model-health-cache.js +1 -1
  113. package/dist/src/model-metadata.d.ts +1 -0
  114. package/dist/src/model-metadata.js +47 -3
  115. package/dist/src/paged-transcript.d.ts +2 -0
  116. package/dist/src/paged-transcript.js +16 -0
  117. package/dist/src/palette.d.ts +1 -0
  118. package/dist/src/palette.js +1 -1
  119. package/dist/src/permissions.js +17 -4
  120. package/dist/src/provider-connection.js +32 -0
  121. package/dist/src/provider-engine.d.ts +5 -0
  122. package/dist/src/provider-engine.js +3 -3
  123. package/dist/src/provider-import.js +3 -1
  124. package/dist/src/provider-settings.d.ts +16 -1
  125. package/dist/src/provider-settings.js +50 -22
  126. package/dist/src/providers.d.ts +29 -3
  127. package/dist/src/providers.js +100 -18
  128. package/dist/src/react-runtime.js +33 -12
  129. package/dist/src/read-document-tool.d.ts +2 -0
  130. package/dist/src/read-document-tool.js +6 -6
  131. package/dist/src/remote/engine-pool.js +31 -6
  132. package/dist/src/run-control.d.ts +2 -2
  133. package/dist/src/run-control.js +9 -6
  134. package/dist/src/runtime-environment.d.ts +1 -0
  135. package/dist/src/runtime-environment.js +13 -0
  136. package/dist/src/runtime.d.ts +2 -0
  137. package/dist/src/runtime.js +2 -1
  138. package/dist/src/save-lock.js +14 -7
  139. package/dist/src/session-title.d.ts +3 -0
  140. package/dist/src/session-title.js +5 -2
  141. package/dist/src/sessions.d.ts +1 -0
  142. package/dist/src/sessions.js +4 -2
  143. package/dist/src/sign-in-detection.d.ts +1 -1
  144. package/dist/src/sign-in-detection.js +10 -3
  145. package/dist/src/sign-in-offer.js +1 -1
  146. package/dist/src/skill-commands.js +1 -1
  147. package/dist/src/skills/bundled/bug-report/SKILL.md +80 -0
  148. package/dist/src/skills/bundled/graph-manager/SKILL.md +9 -1
  149. package/dist/src/skills/bundled/graph-manager/errors.md +2 -1
  150. package/dist/src/skills/bundled/provenance.json +743 -738
  151. package/dist/src/skills/runtime-skills.js +1 -0
  152. package/dist/src/subagent-run.d.ts +2 -0
  153. package/dist/src/subagent-run.js +14 -3
  154. package/dist/src/telemetry/schema.d.ts +1 -1
  155. package/dist/src/telemetry/schema.js +2 -2
  156. package/dist/src/telemetry/uploader.d.ts +7 -1
  157. package/dist/src/telemetry/uploader.js +11 -2
  158. package/dist/src/terminal-links.d.ts +16 -0
  159. package/dist/src/terminal-links.js +113 -0
  160. package/dist/src/terminal-ui.d.ts +29 -1
  161. package/dist/src/terminal-ui.js +113 -24
  162. package/dist/src/tool-catalog.js +1 -1
  163. package/dist/src/trajectory.js +6 -1
  164. package/dist/src/transcript.d.ts +2 -0
  165. package/dist/src/transcript.js +5 -1
  166. package/dist/src/types.d.ts +5 -0
  167. package/dist/src/workspace-instructions.js +1 -1
  168. package/package.json +13 -1
@@ -0,0 +1,235 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { AUTH_DEPLOYMENT } from './auth/deployment.js';
4
+ import { AuthError } from './auth/types.js';
5
+ import { redactSecrets } from './memory/redaction.js';
6
+ /** The built-in skill that interviews the user; a run that carries it also gets the tool below. */
7
+ export const BUG_REPORT_SKILL = 'andorra:bug-report';
8
+ export const BUG_REPORT_TOOL = 'submit_bug_report';
9
+ export const SEND_CHOICE = 'Send report';
10
+ export const CANCEL_CHOICE = 'Do not send';
11
+ /** The report's text fields with the byte limits the service enforces (infra/andorra-auth/bug_report.py). */
12
+ const FIELDS = [
13
+ { name: 'title', required: true, limit: 120, heading: 'Title' },
14
+ { name: 'description', required: true, limit: 4000, heading: 'What happened' },
15
+ { name: 'steps', required: false, limit: 2000, heading: 'Steps to reproduce' },
16
+ { name: 'expected', required: false, limit: 1000, heading: 'Expected' },
17
+ { name: 'actual', required: false, limit: 2000, heading: 'Actual' },
18
+ ];
19
+ export class BugReportError extends Error {
20
+ code;
21
+ constructor(code, message) {
22
+ super(message);
23
+ this.code = code;
24
+ this.name = 'BugReportError';
25
+ }
26
+ }
27
+ const SIGN_IN = 'Bug reports need a signed-in Andorra account, and this installation is signed out. Nothing was sent. Tell the user to sign in (run `andorra login`, type /login, or use Account in the desktop app) and then run /bug-report again. Any plan can report, including Free.';
28
+ const CONTROL = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F­؜​-‏‪-‮⁠-⁤⁦--]/g;
29
+ function fieldText(value, field) {
30
+ if (value === undefined || value === null) {
31
+ if (field.required)
32
+ throw new BugReportError('invalid', `A bug report needs ${field.name}: ask the user and call again.`);
33
+ return undefined;
34
+ }
35
+ if (typeof value !== 'string')
36
+ throw new BugReportError('invalid', `${field.name} must be text.`);
37
+ let text = redactSecrets(value.normalize('NFC').replace(/\r\n?/g, '\n').replace(CONTROL, '')).text.replace(/\n{3,}/g, '\n\n').trim();
38
+ if (field.name === 'title')
39
+ text = text.replace(/\s+/g, ' ');
40
+ if (!text) {
41
+ if (field.required)
42
+ throw new BugReportError('invalid', `A bug report needs ${field.name}: ask the user and call again.`);
43
+ return undefined;
44
+ }
45
+ const bytes = Buffer.byteLength(text, 'utf8');
46
+ if (bytes > field.limit)
47
+ throw new BugReportError('invalid', `${field.name} is ${bytes} bytes and the limit is ${field.limit}. Shorten it (keep the part that shows the problem) and call again.`);
48
+ return text;
49
+ }
50
+ /** The report as it will be sent: trimmed, bounded, and with anything credential-shaped replaced. */
51
+ export function normalizeBugReport(args) {
52
+ const unknown = Object.keys(args).filter(key => !FIELDS.some(field => field.name === key));
53
+ if (unknown.length)
54
+ throw new BugReportError('invalid', `Unknown bug report field${unknown.length === 1 ? '' : 's'}: ${unknown.join(', ')}. Use title, description, steps, expected and actual.`);
55
+ const report = {};
56
+ for (const field of FIELDS) {
57
+ const text = fieldText(args[field.name], field);
58
+ if (text !== undefined)
59
+ report[field.name] = text;
60
+ }
61
+ return report;
62
+ }
63
+ /** Exactly what the user is asked to approve: every field that will be sent, and what is attached. */
64
+ export function bugReportPreview(report, environment) {
65
+ const attached = [environment.appVersion ? `Andorra Code ${environment.appVersion}` : undefined, environment.surface, environment.os, environment.arch].filter(Boolean).join(', ');
66
+ return [
67
+ 'Send this bug report to the Andorra team?',
68
+ ...FIELDS.filter(field => report[field.name] !== undefined).map(field => `${field.heading}:\n${report[field.name]}`),
69
+ `Also sent: your account id and plan, and ${attached}. Nothing else: no files, prompts or conversation.`,
70
+ ].join('\n\n');
71
+ }
72
+ async function packageVersion() {
73
+ try {
74
+ const manifest = JSON.parse(await readFile(fileURLToPath(new URL('../../package.json', import.meta.url)), 'utf8'));
75
+ return typeof manifest.version === 'string' && /^\d{1,4}\.\d{1,4}\.\d{1,4}(?:-[0-9A-Za-z.]{1,24})?$/.test(manifest.version) ? manifest.version : undefined;
76
+ }
77
+ catch {
78
+ return undefined;
79
+ }
80
+ }
81
+ export async function bugReportEnvironment(env = process.env, version = packageVersion) {
82
+ const appVersion = await version();
83
+ const os = process.platform === 'win32' ? 'windows' : process.platform === 'darwin' ? 'macos' : process.platform === 'linux' ? 'linux' : 'other';
84
+ const arch = process.arch === 'x64' || process.arch === 'arm64' ? process.arch : 'other';
85
+ const surface = env.ANDORRA_SURFACE === 'desktop' ? 'desktop' : env.ANDORRA_SURFACE === 'cli' ? 'cli' : undefined;
86
+ return { ...(appVersion ? { appVersion } : {}), ...(surface ? { surface } : {}), os, arch };
87
+ }
88
+ async function boundedJson(response, limit = 16_384) {
89
+ const reader = response.body?.getReader();
90
+ if (!reader)
91
+ return {};
92
+ const chunks = [];
93
+ let size = 0;
94
+ try {
95
+ for (;;) {
96
+ const { done, value } = await reader.read();
97
+ if (done)
98
+ break;
99
+ size += value.byteLength;
100
+ if (size > limit)
101
+ return {};
102
+ chunks.push(value);
103
+ }
104
+ }
105
+ finally {
106
+ await reader.cancel().catch(() => { });
107
+ reader.releaseLock();
108
+ }
109
+ try {
110
+ const value = JSON.parse(Buffer.concat(chunks).toString('utf8'));
111
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
112
+ }
113
+ catch {
114
+ return {};
115
+ }
116
+ }
117
+ export function createBugReportClient(deps) {
118
+ return {
119
+ async token(signal) {
120
+ let token;
121
+ try {
122
+ token = await deps.accessToken(signal);
123
+ }
124
+ catch (error) {
125
+ signal?.throwIfAborted();
126
+ if (error instanceof AuthError && (error.code === 'login_required' || error.code === 'invalid_token'))
127
+ throw new BugReportError('signed_out', SIGN_IN);
128
+ throw new BugReportError('unavailable', 'The Andorra sign-in could not be checked just now, so the report was not sent. Tell the user to try again shortly.');
129
+ }
130
+ if (!token)
131
+ throw new BugReportError('signed_out', SIGN_IN);
132
+ return token;
133
+ },
134
+ async submit(report, environment, token, signal) {
135
+ const base = new URL(deps.apiBaseUrl());
136
+ if (base.protocol !== 'https:' || base.username || base.password || base.search || base.hash)
137
+ throw new BugReportError('unavailable', 'Bug reports are not available in this build.');
138
+ const bounded = signal ? AbortSignal.any([signal, AbortSignal.timeout(30_000)]) : AbortSignal.timeout(30_000);
139
+ let response;
140
+ try {
141
+ response = await deps.fetch(`${base.href.replace(/\/+$/, '')}/bug-reports`, {
142
+ method: 'POST', headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
143
+ body: JSON.stringify({ ...report, environment }), signal: bounded, redirect: 'error',
144
+ });
145
+ }
146
+ catch {
147
+ signal?.throwIfAborted();
148
+ throw new BugReportError('unavailable', 'The bug report service could not be reached, so it is not known whether the report arrived. Tell the user, and offer to send it again in a moment.');
149
+ }
150
+ const body = await boundedJson(response);
151
+ if (response.status === 201 && typeof body.reference === 'string' && /^BR-[1-9]\d{0,8}$/.test(body.reference))
152
+ return { reference: body.reference };
153
+ if (response.status === 401)
154
+ throw new BugReportError('signed_out', SIGN_IN);
155
+ if (response.status === 403)
156
+ throw new BugReportError('refused', 'The Andorra account could not be used to send a report: it is disabled or its email address is not verified. Nothing was sent. Tell the user to verify their email or sign in again.');
157
+ if (response.status === 400 || response.status === 413)
158
+ throw new BugReportError('invalid', 'The service refused the report as malformed or too long. Nothing was sent. Shorten the longest section and try once more.');
159
+ if (response.status === 429) {
160
+ const reset = typeof body.resetsAt === 'string' && Number.isFinite(Date.parse(body.resetsAt)) ? ` It resets at ${new Date(body.resetsAt).toISOString()}.` : '';
161
+ throw new BugReportError('limit', `The daily bug report limit has been reached, so this report was not sent.${reset} Do not retry now; tell the user when they can send it.`);
162
+ }
163
+ throw new BugReportError('unavailable', 'The bug report service is not available right now, so the report was not sent. Tell the user to try again later; do not retry in a loop.');
164
+ },
165
+ };
166
+ }
167
+ /** The shipped client. Sign-in code is loaded on first use, so a run that never reports does not pay for it. */
168
+ export const bugReports = createBugReportClient({
169
+ accessToken: async (signal) => {
170
+ const { getAccessToken, AUTH_REFRESH_BUDGET_MS } = await import('./auth/index.js');
171
+ return getAccessToken(signal ? AbortSignal.any([signal, AbortSignal.timeout(AUTH_REFRESH_BUDGET_MS)]) : AbortSignal.timeout(AUTH_REFRESH_BUDGET_MS));
172
+ },
173
+ apiBaseUrl: () => AUTH_DEPLOYMENT.apiBaseUrl,
174
+ fetch: (...args) => globalThis.fetch(...args),
175
+ });
176
+ /**
177
+ * Files a bug report with the Andorra team. The report leaves the machine only after the user has read
178
+ * exactly what will be sent and chosen to send it, so the tool refuses on a surface where nobody can answer.
179
+ */
180
+ export function bugReportTool(options = {}) {
181
+ const client = options.client ?? bugReports;
182
+ const environmentOf = options.environment ?? (() => bugReportEnvironment());
183
+ const text = { type: 'string', minLength: 1 };
184
+ return {
185
+ name: BUG_REPORT_TOOL, executionMode: 'sequential',
186
+ description: 'Send a bug report about Andorra Code to the Andorra team. Call it only after the bug-report skill\'s interview, with the answers the user gave: never invent steps or details. The tool shows the user the exact report and sends it only if they choose to; a different answer comes back to you as their requested change. It needs a signed-in Andorra account (any plan). Never put credentials, private code or file contents in a report.',
187
+ parameters: { type: 'object', properties: {
188
+ title: { ...text, maxLength: 120, description: 'One line naming the problem, for example "Send button does nothing after attaching a file".' },
189
+ description: { ...text, maxLength: 4000, description: 'What happened, in the user\'s words, with any error text they saw.' },
190
+ steps: { ...text, maxLength: 2000, description: 'Numbered steps that reproduce it, if the user knows them.' },
191
+ expected: { ...text, maxLength: 1000, description: 'What the user expected to happen.' },
192
+ actual: { ...text, maxLength: 2000, description: 'What happened instead.' },
193
+ }, required: ['title', 'description'], additionalProperties: false },
194
+ eventOutput: output => {
195
+ try {
196
+ const result = JSON.parse(output);
197
+ return result.sent ? `Bug report sent (${result.reference}).` : 'Bug report not sent.';
198
+ }
199
+ catch {
200
+ return 'Bug report not sent.';
201
+ }
202
+ },
203
+ execute: async (args, ctx) => {
204
+ ctx.signal.throwIfAborted();
205
+ const report = normalizeBugReport(args);
206
+ if (ctx.approvalMode === 'headless' || !ctx.askUser)
207
+ throw new BugReportError('refused', 'A bug report is sent only after the user reads and confirms it, and nobody can answer on this surface. Nothing was sent. Tell the user to run /bug-report in an interactive session (the terminal app or the desktop app).');
208
+ // Checked first so a signed-out user is never asked to confirm a report that cannot be sent.
209
+ await client.token(ctx.signal);
210
+ const environment = await environmentOf();
211
+ const question = bugReportPreview(report, environment);
212
+ const choices = [SEND_CHOICE, CANCEL_CHOICE];
213
+ await options.emit?.('agent.clarification.requested', { question, choices });
214
+ let answer;
215
+ try {
216
+ answer = await ctx.askUser(question, ctx.userSignal ?? ctx.signal, choices);
217
+ }
218
+ finally {
219
+ await options.emit?.('agent.clarification.answered', { answered: typeof answer === 'string' && !!answer.trim() });
220
+ }
221
+ ctx.signal.throwIfAborted();
222
+ const reply = typeof answer === 'string' ? answer.trim() : '';
223
+ if (reply !== SEND_CHOICE) {
224
+ const declined = !reply || reply === CANCEL_CHOICE || reply.toLowerCase() === '/cancel';
225
+ return JSON.stringify({ sent: false, ...(declined
226
+ ? { note: 'The user chose not to send the report. Nothing was sent. Do not call this tool again unless they ask.' }
227
+ : { userReply: reply.slice(0, 4000), note: 'The user answered with this instead of sending. Nothing was sent. If it asks for a change, revise the report and call this tool again so they can confirm the new text.' }) });
228
+ }
229
+ // Read again: the confirmation can stay open longer than an access token lives.
230
+ const token = await client.token(ctx.signal);
231
+ const { reference } = await client.submit(report, environment, token, ctx.signal);
232
+ return JSON.stringify({ sent: true, reference, note: `The report reached the Andorra team. Give the user the reference ${reference}. There is no page for them to open: the tracker is private.` });
233
+ },
234
+ };
235
+ }
@@ -1,4 +1,4 @@
1
- import type { ModelAdapter, ModelResponse, ToolSchema } from './types.js';
1
+ import type { GenerateRequest, ModelAdapter, ModelResponse, ToolSchema } from './types.js';
2
2
  export declare function claudeEnvironment(source?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
3
3
  export declare const claudeIsolationArgs: string[];
4
4
  export interface ClaudeProcessOptions {
@@ -30,6 +30,7 @@ export declare function retryNote(reason: string): string;
30
30
  type ManifestTool = Pick<ToolSchema, 'name'> & Partial<Pick<ToolSchema, 'parameters'>>;
31
31
  export declare function parseClaudeResponse(output: string, tools?: readonly ManifestTool[]): ModelResponse;
32
32
  export declare function parseClaudeAuxiliaryResponse(output: string, maxTokens: number): ModelResponse;
33
+ export declare function claudeRequestBlocks(messages: GenerateRequest['messages'], tools: GenerateRequest['tools']): object[];
33
34
  export declare function createClaudeAdapter(_config: {
34
35
  model: string;
35
36
  }, dependencies?: ClaudeDependencies): ModelAdapter;
@@ -11,7 +11,7 @@ const executeFile = promisify(execFile);
11
11
  const OUTPUT_LIMIT = 8 * 1024 * 1024;
12
12
  const AUXILIARY_BUDGET_USD = '0.000000001';
13
13
  const signInMessage = 'Sign in with the Claude CLI (claude auth login), then retry the Claude subscription provider.';
14
- const systemPrompt = 'You are the model component of Andorra Code. The supplied conversation is the complete context. Return one structured response with text and toolCalls. To request an Andorra tool, return its name and its arguments as a JSON object in toolCalls. Andorra authorizes and executes tools and supplies observations in the next conversation. Do not use built-in tools. Otherwise return text and an empty toolCalls array.';
14
+ const systemPrompt = 'You are the model component of Andorra Code. The supplied content is the complete context: the availableTools list, then the conversation messages in order, one per block. Return one structured response with text and toolCalls. To request an Andorra tool, return its name and its arguments as a JSON object in toolCalls. Andorra authorizes and executes tools and supplies observations in the next conversation. Do not use built-in tools. Otherwise return text and an empty toolCalls array.';
15
15
  const auxiliarySystemPrompt = 'You are the text-only model component of Andorra Code. The supplied conversation is the complete context. Follow its instructions and return only the requested text. Do not call tools.';
16
16
  const outputSchema = {
17
17
  type: 'object', additionalProperties: false, required: ['text', 'toolCalls'],
@@ -580,6 +580,14 @@ function withDecodeMs(response, decodeMs) {
580
580
  response.usage.decodeMs = decodeMs;
581
581
  return response;
582
582
  }
583
+ export function claudeRequestBlocks(messages, tools) {
584
+ const content = [{ type: 'text', text: `availableTools: ${JSON.stringify(tools)}` }];
585
+ messages.forEach(({ images, providerContinuation, reasoningContent, ...message }, index) => {
586
+ content.push({ type: 'text', text: `conversation message ${index + 1}: ${JSON.stringify({ ...message, ...(images?.length ? { imageCount: images.length } : {}) })}` });
587
+ images?.forEach((image, imageIndex) => content.push({ type: 'text', text: `Image ${imageIndex + 1} from conversation message ${index + 1}:` }, { type: 'image', source: { type: 'base64', media_type: image.mimeType, data: image.data } }));
588
+ });
589
+ return content;
590
+ }
583
591
  export function createClaudeAdapter(_config, dependencies = {}) {
584
592
  const run = dependencies.run ?? runClaudeProcess;
585
593
  return {
@@ -594,13 +602,7 @@ export function createClaudeAdapter(_config, dependencies = {}) {
594
602
  const signal = AbortSignal.any([request.signal, AbortSignal.timeout(10 * 60_000)]);
595
603
  if (!await signedIn(run, signal))
596
604
  throw new Error(signInMessage);
597
- const content = [{ type: 'text', text: JSON.stringify({
598
- conversation: request.messages.map(({ images, providerContinuation, reasoningContent, ...message }) => ({ ...message, ...(images?.length ? { imageCount: images.length } : {}) })),
599
- availableTools: request.tools,
600
- }) }];
601
- request.messages.forEach((message, index) => message.images?.forEach((image, imageIndex) => {
602
- content.push({ type: 'text', text: `Image ${imageIndex + 1} from conversation message ${index + 1}:` }, { type: 'image', source: { type: 'base64', media_type: image.mimeType, data: image.data } });
603
- }));
605
+ const content = claudeRequestBlocks(request.messages, request.tools);
604
606
  const args = [...claudeIsolationArgs, '--print', '--input-format', 'stream-json', '--output-format', 'stream-json', '--verbose',
605
607
  '--max-turns', '1',
606
608
  '--model', request.model, ...(auxiliary
@@ -17,7 +17,9 @@ export interface CliSignInSpec {
17
17
  }>;
18
18
  env(): NodeJS.ProcessEnv;
19
19
  loginArgs: readonly string[];
20
- logoutArgs: readonly string[];
20
+ /** Absent when the CLI has no sign-out command; `signOutHint` then tells the user where to sign out. */
21
+ logoutArgs?: readonly string[];
22
+ signOutHint?: string;
21
23
  status(signal: AbortSignal): Promise<{
22
24
  signedIn: boolean;
23
25
  email?: string;
@@ -174,9 +174,12 @@ export class CliSignIn {
174
174
  async logout() {
175
175
  if (this.attempt?.live)
176
176
  return { state: 'error', reason: 'busy', message: `A ${this.spec.product} sign-in is in progress. Finish or cancel it before signing out.` };
177
+ const logoutArgs = this.spec.logoutArgs;
178
+ if (!logoutArgs)
179
+ return { state: 'error', reason: 'unsupported', message: this.spec.signOutHint ?? `Sign out with the ${this.spec.product} CLI, then refresh.` };
177
180
  try {
178
181
  const executable = await this.spec.resolveExecutable();
179
- await runBoundedCli(executable, () => [...this.spec.logoutArgs], AbortSignal.timeout(60_000), { env: this.spec.env(), label: `${this.spec.product} CLI`, acceptedExitCodes: [0, 1] });
182
+ await runBoundedCli(executable, () => [...logoutArgs], AbortSignal.timeout(60_000), { env: this.spec.env(), label: `${this.spec.product} CLI`, acceptedExitCodes: [0, 1] });
180
183
  const account = await this.spec.status(AbortSignal.timeout(30_000));
181
184
  if (account.signedIn)
182
185
  return { state: 'error', reason: 'logoutFailed', message: `${this.spec.product} is still signed in. Sign out with its CLI and refresh.` };