@andorra-labs/code 0.1.14 → 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.
- package/dist/src/acp-agent.d.ts +54 -0
- package/dist/src/acp-agent.js +991 -0
- package/dist/src/agent-execution.js +4 -0
- package/dist/src/agent-mcp-catalog.js +2 -0
- package/dist/src/agent-mcp.d.ts +2 -0
- package/dist/src/agent-mcp.js +84 -2
- 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 +6 -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 +8 -0
- package/dist/src/app-server.js +87 -41
- package/dist/src/auth/AuthManager.js +4 -4
- 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-server.d.ts +5 -0
- package/dist/src/browser-server.js +27 -3
- 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 +10 -8
- package/dist/src/cli-sign-in.d.ts +3 -1
- package/dist/src/cli-sign-in.js +4 -1
- package/dist/src/cli.js +164 -34
- package/dist/src/coding-tools.js +7 -7
- package/dist/src/command-screens.d.ts +9 -2
- package/dist/src/command-screens.js +161 -94
- package/dist/src/commands.d.ts +1 -1
- package/dist/src/commands.js +1 -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/google-provider.d.ts +31 -0
- package/dist/src/google-provider.js +153 -0
- package/dist/src/graph-health.js +1 -1
- package/dist/src/graph-manager-chat.js +6 -1
- 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 +67 -8
- package/dist/src/graph-ui/edge-router.js +121 -53
- package/dist/src/graph-visibility.d.ts +31 -0
- package/dist/src/graph-visibility.js +102 -0
- 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 +3 -0
- package/dist/src/membership.js +19 -2
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.js +8 -1
- package/dist/src/paged-transcript.d.ts +2 -0
- package/dist/src/paged-transcript.js +16 -0
- package/dist/src/provider-connection.js +17 -0
- package/dist/src/provider-engine.d.ts +5 -0
- package/dist/src/provider-engine.js +3 -3
- package/dist/src/provider-import.js +3 -1
- package/dist/src/provider-settings.js +14 -2
- package/dist/src/providers.d.ts +16 -2
- package/dist/src/providers.js +36 -12
- package/dist/src/react-runtime.js +21 -5
- 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 +26 -2
- package/dist/src/runtime-environment.d.ts +1 -0
- package/dist/src/runtime-environment.js +13 -0
- 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/telemetry/uploader.d.ts +7 -1
- package/dist/src/telemetry/uploader.js +11 -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 +2 -1
- package/dist/src/types.d.ts +2 -0
- package/package.json +2 -1
package/dist/src/browser-view.js
CHANGED
|
@@ -5,6 +5,7 @@ import { mkdir } from 'node:fs/promises';
|
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { observePage, observationResult } from './browser-observation.js';
|
|
8
|
+
import { externalAppPromptNote, externalAppScheme, guardExternalApps } from './browser-external-app.js';
|
|
8
9
|
import { desktopUaOverride, hardenContext, stealthLaunchArgs, STEALTH_LOCALE, userAgentMetadata } from './browser-stealth.js';
|
|
9
10
|
export const VIEW_TAB_LIMIT = 6;
|
|
10
11
|
export const VIEW_SESSION_LIMIT = 4;
|
|
@@ -432,6 +433,7 @@ export class BrowserViewManager {
|
|
|
432
433
|
// the context. Only the locale stays as a stealth option.
|
|
433
434
|
const context = await chromium.launchPersistentContext(directory, { ...headedViewLaunchOptions(channel, candidate, scale, paths), locale: STEALTH_LOCALE, viewport: { ...viewport }, acceptDownloads: false });
|
|
434
435
|
await hardenContext(context);
|
|
436
|
+
await guardExternalApps(context);
|
|
435
437
|
return context;
|
|
436
438
|
};
|
|
437
439
|
try {
|
|
@@ -578,10 +580,56 @@ export class BrowserViewManager {
|
|
|
578
580
|
}
|
|
579
581
|
async showWindow(sessionId) {
|
|
580
582
|
await this.moveWindow(sessionId, VIEW_ONSCREEN_POSITION, true);
|
|
583
|
+
// The user can now see and answer the prompt on the tab this brought to the front, so that tab's
|
|
584
|
+
// notice has done its job. Other tabs keep theirs: their prompts are still behind this one, or in
|
|
585
|
+
// a popup's own window that was not moved.
|
|
586
|
+
const session = this.sessions.get(sessionId);
|
|
587
|
+
const active = session?.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
588
|
+
if (!session || !active?.appPrompt)
|
|
589
|
+
return;
|
|
590
|
+
active.appPrompt = undefined;
|
|
591
|
+
this.publishTabs(sessionId, session);
|
|
581
592
|
}
|
|
582
593
|
async hideWindow(sessionId) {
|
|
583
594
|
await this.moveWindow(sessionId, VIEW_OFFSCREEN_POSITION, false);
|
|
584
595
|
}
|
|
596
|
+
/**
|
|
597
|
+
* Whether the native window holding this tab is on the user's screen right now.
|
|
598
|
+
* Sessions of one project share a window, so one session can hide what another
|
|
599
|
+
* showed; the window's own bounds are the only record that stays true.
|
|
600
|
+
*/
|
|
601
|
+
async windowOnScreen(session, tab) {
|
|
602
|
+
try {
|
|
603
|
+
const cdp = await this.browserCdpFor(session);
|
|
604
|
+
const found = await cdp.send('Browser.getWindowForTarget', tab.targetId !== undefined ? { targetId: tab.targetId } : {});
|
|
605
|
+
const bounds = found?.bounds;
|
|
606
|
+
return typeof bounds?.left === 'number' && typeof bounds.top === 'number' && bounds.windowState !== 'minimized'
|
|
607
|
+
&& bounds.left > VIEW_OFFSCREEN_POSITION.left / 2 && bounds.top > VIEW_OFFSCREEN_POSITION.top / 2;
|
|
608
|
+
}
|
|
609
|
+
catch {
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* An app link got past the in-page guard. With the window on screen the user can
|
|
615
|
+
* see the browser's prompt; otherwise the tab is flagged so the panel and the
|
|
616
|
+
* agent are told why it stopped responding.
|
|
617
|
+
*/
|
|
618
|
+
async flagAppPrompt(sessionId, session, tab, scheme) {
|
|
619
|
+
const at = Date.now();
|
|
620
|
+
if (await this.windowOnScreen(session, tab))
|
|
621
|
+
return;
|
|
622
|
+
if (session.closing || session.tabs.get(tab.id) !== tab)
|
|
623
|
+
return;
|
|
624
|
+
tab.appPrompt = { scheme, at };
|
|
625
|
+
this.publishTabs(sessionId, session);
|
|
626
|
+
}
|
|
627
|
+
/** What to tell the agent when a tab may be stuck behind the browser's "Open app?" prompt. */
|
|
628
|
+
appPromptNote(sessionId, tabId) {
|
|
629
|
+
const session = this.sessions.get(sessionId);
|
|
630
|
+
const tab = session ? session.tabs.get(tabId ?? session.activeTabId ?? '') : undefined;
|
|
631
|
+
return tab?.appPrompt ? externalAppPromptNote(tab.appPrompt) : undefined;
|
|
632
|
+
}
|
|
585
633
|
async moveWindow(sessionId, position, activate) {
|
|
586
634
|
const session = this.sessions.get(sessionId);
|
|
587
635
|
if (!session || session.closing)
|
|
@@ -913,7 +961,7 @@ export class BrowserViewManager {
|
|
|
913
961
|
summary(session) {
|
|
914
962
|
return {
|
|
915
963
|
profile: session.profile,
|
|
916
|
-
tabs: [...session.tabs.values()].map(tab => ({ id: tab.id, url: tab.url, title: tab.title, loading: tab.loading })),
|
|
964
|
+
tabs: [...session.tabs.values()].map(tab => ({ id: tab.id, url: tab.url, title: tab.title, loading: tab.loading, ...(tab.appPrompt ? { appPrompt: { ...tab.appPrompt } } : {}) })),
|
|
917
965
|
...(session.activeTabId ? { activeTabId: session.activeTabId } : {}),
|
|
918
966
|
};
|
|
919
967
|
}
|
|
@@ -1103,6 +1151,16 @@ export class BrowserViewManager {
|
|
|
1103
1151
|
documentRequest = request;
|
|
1104
1152
|
}
|
|
1105
1153
|
catch { }
|
|
1154
|
+
// An app link the in-page guard could not cancel (an iframe src, a redirect, a
|
|
1155
|
+
// form post) still shows up here, in any frame. Chromium is now raising its
|
|
1156
|
+
// "Open app?" prompt, which nothing in this process can see or dismiss.
|
|
1157
|
+
let scheme;
|
|
1158
|
+
try {
|
|
1159
|
+
scheme = externalAppScheme(request?.url?.());
|
|
1160
|
+
}
|
|
1161
|
+
catch { }
|
|
1162
|
+
if (scheme)
|
|
1163
|
+
void this.flagAppPrompt(sessionId, session, tab, scheme);
|
|
1106
1164
|
});
|
|
1107
1165
|
page.on('requestfailed', (request) => { if (request === documentRequest)
|
|
1108
1166
|
documentRequest = undefined; });
|
|
@@ -1298,7 +1356,7 @@ export class BrowserViewManager {
|
|
|
1298
1356
|
session.contextTask ??= Promise.resolve()
|
|
1299
1357
|
// Headed: the browser's own identity goes through, only the locale stays as a stealth option.
|
|
1300
1358
|
.then(() => session.browser.newContext({ viewport: { ...session.viewport }, acceptDownloads: false, locale: STEALTH_LOCALE }))
|
|
1301
|
-
.then(async (context) => { await hardenContext(context); session.context = context; return context; });
|
|
1359
|
+
.then(async (context) => { await hardenContext(context); await guardExternalApps(context); session.context = context; return context; });
|
|
1302
1360
|
return await session.contextTask;
|
|
1303
1361
|
}
|
|
1304
1362
|
async openTab(sessionId, url, signal) {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Tool } from './types.js';
|
|
2
|
+
/** The built-in skill that interviews the user; a run that carries it also gets the tool below. */
|
|
3
|
+
export declare const BUG_REPORT_SKILL = "andorra:bug-report";
|
|
4
|
+
export declare const BUG_REPORT_TOOL = "submit_bug_report";
|
|
5
|
+
export declare const SEND_CHOICE = "Send report";
|
|
6
|
+
export declare const CANCEL_CHOICE = "Do not send";
|
|
7
|
+
/** The report's text fields with the byte limits the service enforces (infra/andorra-auth/bug_report.py). */
|
|
8
|
+
declare const FIELDS: readonly [{
|
|
9
|
+
readonly name: "title";
|
|
10
|
+
readonly required: true;
|
|
11
|
+
readonly limit: 120;
|
|
12
|
+
readonly heading: "Title";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "description";
|
|
15
|
+
readonly required: true;
|
|
16
|
+
readonly limit: 4000;
|
|
17
|
+
readonly heading: "What happened";
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "steps";
|
|
20
|
+
readonly required: false;
|
|
21
|
+
readonly limit: 2000;
|
|
22
|
+
readonly heading: "Steps to reproduce";
|
|
23
|
+
}, {
|
|
24
|
+
readonly name: "expected";
|
|
25
|
+
readonly required: false;
|
|
26
|
+
readonly limit: 1000;
|
|
27
|
+
readonly heading: "Expected";
|
|
28
|
+
}, {
|
|
29
|
+
readonly name: "actual";
|
|
30
|
+
readonly required: false;
|
|
31
|
+
readonly limit: 2000;
|
|
32
|
+
readonly heading: "Actual";
|
|
33
|
+
}];
|
|
34
|
+
type FieldName = typeof FIELDS[number]['name'];
|
|
35
|
+
export type BugReport = {
|
|
36
|
+
title: string;
|
|
37
|
+
description: string;
|
|
38
|
+
} & Partial<Record<Exclude<FieldName, 'title' | 'description'>, string>>;
|
|
39
|
+
export interface BugReportEnvironment {
|
|
40
|
+
appVersion?: string;
|
|
41
|
+
surface?: 'cli' | 'desktop';
|
|
42
|
+
os: 'windows' | 'macos' | 'linux' | 'other';
|
|
43
|
+
arch: 'x64' | 'arm64' | 'other';
|
|
44
|
+
}
|
|
45
|
+
export type BugReportFailure = 'signed_out' | 'refused' | 'invalid' | 'limit' | 'unavailable';
|
|
46
|
+
export declare class BugReportError extends Error {
|
|
47
|
+
readonly code: BugReportFailure;
|
|
48
|
+
constructor(code: BugReportFailure, message: string);
|
|
49
|
+
}
|
|
50
|
+
/** The report as it will be sent: trimmed, bounded, and with anything credential-shaped replaced. */
|
|
51
|
+
export declare function normalizeBugReport(args: Record<string, unknown>): BugReport;
|
|
52
|
+
/** Exactly what the user is asked to approve: every field that will be sent, and what is attached. */
|
|
53
|
+
export declare function bugReportPreview(report: BugReport, environment: BugReportEnvironment): string;
|
|
54
|
+
export declare function bugReportEnvironment(env?: NodeJS.ProcessEnv, version?: () => Promise<string | undefined>): Promise<BugReportEnvironment>;
|
|
55
|
+
export interface BugReportDependencies {
|
|
56
|
+
accessToken(signal?: AbortSignal): Promise<string>;
|
|
57
|
+
apiBaseUrl(): string;
|
|
58
|
+
fetch: typeof globalThis.fetch;
|
|
59
|
+
}
|
|
60
|
+
export interface BugReportClient {
|
|
61
|
+
/** Throws `signed_out` unless an Andorra account is signed in on this installation. */
|
|
62
|
+
token(signal?: AbortSignal): Promise<string>;
|
|
63
|
+
submit(report: BugReport, environment: BugReportEnvironment, token: string, signal?: AbortSignal): Promise<{
|
|
64
|
+
reference: string;
|
|
65
|
+
}>;
|
|
66
|
+
}
|
|
67
|
+
export declare function createBugReportClient(deps: BugReportDependencies): BugReportClient;
|
|
68
|
+
/** The shipped client. Sign-in code is loaded on first use, so a run that never reports does not pay for it. */
|
|
69
|
+
export declare const bugReports: BugReportClient;
|
|
70
|
+
export interface BugReportToolOptions {
|
|
71
|
+
client?: BugReportClient;
|
|
72
|
+
environment?: () => Promise<BugReportEnvironment>;
|
|
73
|
+
/** Tells the surface a question is open, the way ask_user does, so the tool clock pauses while it waits. */
|
|
74
|
+
emit?: (type: string, data: Record<string, unknown>) => void | Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Files a bug report with the Andorra team. The report leaves the machine only after the user has read
|
|
78
|
+
* exactly what will be sent and chosen to send it, so the tool refuses on a surface where nobody can answer.
|
|
79
|
+
*/
|
|
80
|
+
export declare function bugReportTool(options?: BugReportToolOptions): Tool;
|
|
81
|
+
export {};
|
|
@@ -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'],
|
|
@@ -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 =
|
|
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
|
-
|
|
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.` };
|