@andorra-labs/code 0.1.14 → 0.1.16
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/acp-agent.d.ts +54 -0
- package/dist/src/acp-agent.js +991 -0
- package/dist/src/agent-definitions.js +29 -6
- package/dist/src/agent-execution.js +8 -2
- package/dist/src/agent-mcp-catalog.js +2 -0
- package/dist/src/agent-mcp.d.ts +3 -1
- package/dist/src/agent-mcp.js +97 -11
- package/dist/src/andorra/entry.js +21 -3
- package/dist/src/andorra/hosted.d.ts +3 -0
- package/dist/src/andorra/hosted.js +5 -1
- package/dist/src/andorra/notices.d.ts +10 -1
- package/dist/src/andorra/notices.js +25 -2
- package/dist/src/andorra/terminal.d.ts +2 -0
- package/dist/src/andorra/terminal.js +2 -2
- package/dist/src/app-server/protocol.d.ts +9 -2
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server/workspace.d.ts +1 -0
- package/dist/src/app-server/workspace.js +141 -10
- package/dist/src/app-server.d.ts +115 -0
- package/dist/src/app-server.js +980 -63
- package/dist/src/auth/AuthManager.js +4 -4
- package/dist/src/auth/deployment.js +2 -2
- package/dist/src/browser-bridge.d.ts +1 -0
- package/dist/src/browser-bridge.js +5 -2
- package/dist/src/browser-external-app.d.ts +27 -0
- package/dist/src/browser-external-app.js +60 -0
- package/dist/src/browser-panel-tool.d.ts +6 -0
- package/dist/src/browser-panel-tool.js +36 -0
- package/dist/src/browser-runner.js +1 -0
- package/dist/src/browser-server.d.ts +5 -0
- package/dist/src/browser-server.js +27 -3
- package/dist/src/browser-ui/style.css +3 -3
- package/dist/src/browser-ui/tokens.css +27 -16
- package/dist/src/browser-view.d.ts +16 -0
- package/dist/src/browser-view.js +60 -2
- package/dist/src/bug-report.d.ts +81 -0
- package/dist/src/bug-report.js +235 -0
- package/dist/src/claude-provider.d.ts +2 -1
- package/dist/src/claude-provider.js +13 -9
- package/dist/src/cli-sign-in.d.ts +3 -1
- package/dist/src/cli-sign-in.js +4 -1
- package/dist/src/cli.js +184 -40
- package/dist/src/codex-errors.js +4 -1
- package/dist/src/coding-tools.js +7 -7
- package/dist/src/command-screens.d.ts +9 -2
- package/dist/src/command-screens.js +166 -97
- package/dist/src/commands.d.ts +3 -2
- package/dist/src/commands.js +1 -0
- package/dist/src/compaction-phrases.d.ts +4 -0
- package/dist/src/compaction-phrases.js +20 -0
- package/dist/src/completion-gates.d.ts +22 -0
- package/dist/src/completion-gates.js +11 -0
- package/dist/src/config.d.ts +5 -0
- package/dist/src/config.js +48 -0
- package/dist/src/context-compaction.js +2 -1
- package/dist/src/decision/DecisionManager.js +3 -2
- package/dist/src/decision/requestPhrases.d.ts +4 -0
- package/dist/src/decision/requestPhrases.js +23 -0
- package/dist/src/github-inbox.d.ts +55 -0
- package/dist/src/github-inbox.js +153 -0
- package/dist/src/google-provider.d.ts +31 -0
- package/dist/src/google-provider.js +153 -0
- package/dist/src/graph-health.js +8 -4
- package/dist/src/graph-manager-chat.js +6 -1
- package/dist/src/graph-provider-portability.js +32 -10
- package/dist/src/graph-quota.d.ts +29 -2
- package/dist/src/graph-quota.js +68 -10
- package/dist/src/graph-runner.js +24 -7
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +9 -7
- package/dist/src/graph-sync.d.ts +1 -0
- package/dist/src/graph-sync.js +93 -34
- package/dist/src/graph-tool.d.ts +2 -0
- package/dist/src/graph-tool.js +2 -2
- package/dist/src/graph-ui/app.js +177 -41
- package/dist/src/graph-ui/controls.css +1 -0
- package/dist/src/graph-ui/edge-router.js +121 -53
- package/dist/src/graph-ui/embed.js +2 -2
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graph-ui/manager.css +1 -1
- package/dist/src/graph-ui/manager.js +2 -2
- package/dist/src/graph-ui/sidebar.js +30 -0
- package/dist/src/graph-ui/studio-canvas.js +26 -13
- package/dist/src/graph-ui/studio.css +15 -7
- package/dist/src/graph-ui/studio.js +11 -4
- package/dist/src/graph-ui/style.css +77 -45
- package/dist/src/graph-ui/theme.js +3 -36
- package/dist/src/graph-ui/tokens.css +27 -19
- package/dist/src/graph-visibility.d.ts +31 -0
- package/dist/src/graph-visibility.js +102 -0
- package/dist/src/graphs.js +4 -3
- package/dist/src/live-model.d.ts +24 -0
- package/dist/src/live-model.js +37 -0
- package/dist/src/managed-sign-in.d.ts +1 -0
- package/dist/src/managed-sign-in.js +13 -0
- package/dist/src/membership-errors.d.ts +2 -0
- package/dist/src/membership-errors.js +5 -1
- package/dist/src/membership.d.ts +23 -1
- package/dist/src/membership.js +48 -6
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +1 -1
- package/dist/src/model-metadata.js +12 -3
- package/dist/src/paged-transcript.d.ts +2 -0
- package/dist/src/paged-transcript.js +16 -0
- package/dist/src/plan-pass.d.ts +59 -0
- package/dist/src/plan-pass.js +165 -0
- package/dist/src/provider-connection.js +17 -0
- package/dist/src/provider-engine.d.ts +5 -0
- package/dist/src/provider-engine.js +6 -3
- package/dist/src/provider-import.js +3 -1
- package/dist/src/provider-settings.js +14 -2
- package/dist/src/providers.d.ts +33 -2
- package/dist/src/providers.js +101 -28
- package/dist/src/pull-request-checks.d.ts +26 -0
- package/dist/src/pull-request-checks.js +56 -0
- package/dist/src/pull-request-conversation.d.ts +134 -0
- package/dist/src/pull-request-conversation.js +221 -0
- package/dist/src/pull-request-create.d.ts +175 -0
- package/dist/src/pull-request-create.js +392 -0
- package/dist/src/pull-request-details.d.ts +242 -0
- package/dist/src/pull-request-details.js +614 -0
- package/dist/src/pull-request-edit.d.ts +23 -0
- package/dist/src/pull-request-edit.js +91 -0
- package/dist/src/pull-request-logs.d.ts +76 -0
- package/dist/src/pull-request-logs.js +172 -0
- package/dist/src/pull-request-merge.d.ts +112 -0
- package/dist/src/pull-request-merge.js +258 -0
- package/dist/src/pull-request-review.d.ts +137 -0
- package/dist/src/pull-request-review.js +401 -0
- package/dist/src/pull-requests.d.ts +43 -2
- package/dist/src/pull-requests.js +112 -21
- package/dist/src/react-runtime.js +58 -9
- package/dist/src/read-document-tool.d.ts +2 -0
- package/dist/src/read-document-tool.js +6 -6
- package/dist/src/remote/engine-pool.js +42 -6
- package/dist/src/run-control.d.ts +10 -0
- package/dist/src/run-control.js +24 -0
- package/dist/src/run-progress.d.ts +10 -0
- package/dist/src/run-progress.js +122 -0
- package/dist/src/run-records.d.ts +2 -2
- package/dist/src/runtime-environment.d.ts +1 -0
- package/dist/src/runtime-environment.js +13 -0
- package/dist/src/runtime.d.ts +5 -1
- package/dist/src/runtime.js +14 -2
- package/dist/src/save-lock.js +14 -7
- package/dist/src/session-title.d.ts +3 -0
- package/dist/src/session-title.js +5 -2
- package/dist/src/sign-in-detection.d.ts +1 -1
- package/dist/src/sign-in-detection.js +10 -3
- package/dist/src/sign-in-offer.js +1 -1
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/bug-report/SKILL.md +80 -0
- package/dist/src/skills/bundled/graph-manager/SKILL.md +9 -1
- package/dist/src/skills/bundled/graph-manager/errors.md +1 -0
- package/dist/src/skills/bundled/provenance.json +7 -2
- package/dist/src/skills/runtime-skills.js +1 -0
- package/dist/src/subagent-run.js +1 -0
- package/dist/src/telemetry/capture-core.d.ts +17 -0
- package/dist/src/telemetry/capture-core.js +59 -1
- package/dist/src/telemetry/classify.d.ts +3 -1
- package/dist/src/telemetry/classify.js +37 -0
- package/dist/src/telemetry/emitter.d.ts +2 -0
- package/dist/src/telemetry/emitter.js +42 -5
- package/dist/src/telemetry/schema.d.ts +22 -0
- package/dist/src/telemetry/schema.js +68 -1
- package/dist/src/telemetry/surface.d.ts +1 -0
- package/dist/src/telemetry/uploader.d.ts +12 -1
- package/dist/src/telemetry/uploader.js +30 -2
- package/dist/src/terminal-links.d.ts +16 -0
- package/dist/src/terminal-links.js +113 -0
- package/dist/src/terminal-ui.d.ts +8 -1
- package/dist/src/terminal-ui.js +40 -14
- package/dist/src/tool-catalog.js +1 -1
- package/dist/src/trajectory.js +6 -1
- package/dist/src/transcript.d.ts +2 -0
- package/dist/src/transcript.js +10 -3
- package/dist/src/types.d.ts +9 -0
- package/dist/src/usage-analytics.js +18 -10
- package/package.json +2 -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
|
|
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'],
|
|
@@ -183,6 +183,8 @@ export async function readClaudeCatalog(signal, dependencies = {}) {
|
|
|
183
183
|
}
|
|
184
184
|
class MalformedClaudeStep extends Error {
|
|
185
185
|
unparsedReply;
|
|
186
|
+
/** Record-only telemetry code; the error keeps its class so whole-agent retries behave as before. */
|
|
187
|
+
telemetryCode = 'malformed_response';
|
|
186
188
|
constructor(message, unparsedReply) {
|
|
187
189
|
super(message);
|
|
188
190
|
this.unparsedReply = unparsedReply;
|
|
@@ -580,6 +582,14 @@ function withDecodeMs(response, decodeMs) {
|
|
|
580
582
|
response.usage.decodeMs = decodeMs;
|
|
581
583
|
return response;
|
|
582
584
|
}
|
|
585
|
+
export function claudeRequestBlocks(messages, tools) {
|
|
586
|
+
const content = [{ type: 'text', text: `availableTools: ${JSON.stringify(tools)}` }];
|
|
587
|
+
messages.forEach(({ images, providerContinuation, reasoningContent, ...message }, index) => {
|
|
588
|
+
content.push({ type: 'text', text: `conversation message ${index + 1}: ${JSON.stringify({ ...message, ...(images?.length ? { imageCount: images.length } : {}) })}` });
|
|
589
|
+
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 } }));
|
|
590
|
+
});
|
|
591
|
+
return content;
|
|
592
|
+
}
|
|
583
593
|
export function createClaudeAdapter(_config, dependencies = {}) {
|
|
584
594
|
const run = dependencies.run ?? runClaudeProcess;
|
|
585
595
|
return {
|
|
@@ -594,13 +604,7 @@ export function createClaudeAdapter(_config, dependencies = {}) {
|
|
|
594
604
|
const signal = AbortSignal.any([request.signal, AbortSignal.timeout(10 * 60_000)]);
|
|
595
605
|
if (!await signedIn(run, signal))
|
|
596
606
|
throw new Error(signInMessage);
|
|
597
|
-
const content =
|
|
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
|
-
}));
|
|
607
|
+
const content = claudeRequestBlocks(request.messages, request.tools);
|
|
604
608
|
const args = [...claudeIsolationArgs, '--print', '--input-format', 'stream-json', '--output-format', 'stream-json', '--verbose',
|
|
605
609
|
'--max-turns', '1',
|
|
606
610
|
'--model', request.model, ...(auxiliary
|
|
@@ -626,7 +630,7 @@ export function createClaudeAdapter(_config, dependencies = {}) {
|
|
|
626
630
|
catch (error) {
|
|
627
631
|
if (!(error instanceof MalformedClaudeStep) || attempt >= STEP_ATTEMPTS)
|
|
628
632
|
throw error;
|
|
629
|
-
await request.onRetry?.({ retry: attempt, maxRetries: STEP_ATTEMPTS - 1, delayMs: 0, reason: `${error.message}. Asking again.`, quiet: true,
|
|
633
|
+
await request.onRetry?.({ retry: attempt, maxRetries: STEP_ATTEMPTS - 1, delayMs: 0, reason: `${error.message}. Asking again.`, quiet: true, code: 'malformed_response',
|
|
630
634
|
...(error.unparsedReply === undefined ? {} : { unparsedReply: error.unparsedReply }) });
|
|
631
635
|
input = compose(retryNote(error.message));
|
|
632
636
|
}
|
|
@@ -17,7 +17,9 @@ export interface CliSignInSpec {
|
|
|
17
17
|
}>;
|
|
18
18
|
env(): NodeJS.ProcessEnv;
|
|
19
19
|
loginArgs: readonly string[];
|
|
20
|
-
|
|
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;
|
package/dist/src/cli-sign-in.js
CHANGED
|
@@ -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, () => [...
|
|
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.` };
|