@andorra-labs/code 0.1.16 → 0.1.18
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 +6 -0
- package/dist/src/acp-agent.js +15 -4
- package/dist/src/agent-execution.js +108 -19
- package/dist/src/agent-mcp-catalog.js +1 -0
- package/dist/src/agent-mcp.d.ts +3 -0
- package/dist/src/agent-mcp.js +33 -1
- package/dist/src/andorra/entry.d.ts +10 -0
- package/dist/src/andorra/entry.js +18 -4
- package/dist/src/andorra/errors.js +3 -0
- package/dist/src/andorra/hosted.d.ts +2 -1
- package/dist/src/andorra/hosted.js +2 -1
- package/dist/src/andorra/notices.d.ts +5 -0
- package/dist/src/andorra/notices.js +7 -0
- package/dist/src/andorra/state.d.ts +3 -2
- package/dist/src/andorra/state.js +4 -4
- package/dist/src/andorra/terminal.js +7 -2
- package/dist/src/anthropic-credentials.js +2 -0
- package/dist/src/app-server/error.d.ts +5 -0
- package/dist/src/app-server/error.js +7 -0
- package/dist/src/app-server/protocol.d.ts +30 -44
- package/dist/src/app-server/protocol.js +5 -1
- package/dist/src/app-server/workspace.d.ts +108 -0
- package/dist/src/app-server/workspace.js +608 -11
- package/dist/src/app-server.d.ts +390 -33
- package/dist/src/app-server.js +3033 -565
- package/dist/src/attachments.d.ts +10 -0
- package/dist/src/attachments.js +102 -7
- package/dist/src/automation-tool.js +2 -1
- package/dist/src/bridge/cloud.d.ts +27 -0
- package/dist/src/bridge/cloud.js +187 -0
- package/dist/src/bridge/command.d.ts +30 -0
- package/dist/src/bridge/command.js +359 -0
- package/dist/src/bridge/control.d.ts +70 -0
- package/dist/src/bridge/control.js +238 -0
- package/dist/src/bridge/engines.d.ts +90 -0
- package/dist/src/bridge/engines.js +601 -0
- package/dist/src/bridge/github.d.ts +108 -0
- package/dist/src/bridge/github.js +378 -0
- package/dist/src/bridge/host-ops.d.ts +9 -0
- package/dist/src/bridge/host-ops.js +139 -0
- package/dist/src/bridge/host.d.ts +47 -0
- package/dist/src/bridge/host.js +543 -0
- package/dist/src/bridge/link.d.ts +38 -0
- package/dist/src/bridge/link.js +508 -0
- package/dist/src/bridge/login-link.d.ts +29 -0
- package/dist/src/bridge/login-link.js +54 -0
- package/dist/src/bridge/protocol.d.ts +136 -0
- package/dist/src/bridge/protocol.js +11 -0
- package/dist/src/bridge/store.d.ts +12 -0
- package/dist/src/bridge/store.js +61 -0
- package/dist/src/bridge/wording.d.ts +6 -0
- package/dist/src/bridge/wording.js +10 -0
- package/dist/src/browser-server.js +7 -1
- package/dist/src/browser-ui/tokens.css +1 -1
- package/dist/src/bug-report-attachments.d.ts +48 -0
- package/dist/src/bug-report-attachments.js +327 -0
- package/dist/src/bug-report.d.ts +23 -3
- package/dist/src/bug-report.js +72 -9
- package/dist/src/change-authors.d.ts +41 -0
- package/dist/src/change-authors.js +146 -0
- package/dist/src/cli.d.ts +1 -3
- package/dist/src/cli.js +191 -35
- package/dist/src/codex-provider.js +1 -1
- package/dist/src/coding-tools.js +24 -17
- package/dist/src/command-screens.d.ts +6 -0
- package/dist/src/command-screens.js +14 -11
- package/dist/src/commands.d.ts +15 -3
- package/dist/src/commands.js +2 -1
- package/dist/src/compaction-phrases.js +1 -1
- package/dist/src/completion.js +89 -8
- package/dist/src/config.d.ts +71 -3
- package/dist/src/config.js +205 -78
- package/dist/src/context-budget.js +15 -2
- package/dist/src/deadline.js +13 -1
- package/dist/src/decision/DecisionEngine.d.ts +2 -0
- package/dist/src/decision/DecisionManager.d.ts +11 -0
- package/dist/src/decision/DecisionManager.js +36 -0
- package/dist/src/decision/applyTaskKind.d.ts +8 -0
- package/dist/src/decision/applyTaskKind.js +53 -0
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/hostedPolicy.js +2 -1
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +2 -0
- package/dist/src/decision/providers/AndorraDecisionProvider.js +12 -0
- package/dist/src/decision/requestPhrases.js +0 -1
- package/dist/src/decision/taskKind.d.ts +52 -0
- package/dist/src/decision/taskKind.js +76 -0
- package/dist/src/decision/types.d.ts +1 -1
- package/dist/src/default-graph.js +1 -1
- package/dist/src/efficiency.d.ts +5 -0
- package/dist/src/efficiency.js +5 -1
- package/dist/src/effort-routing.d.ts +27 -0
- package/dist/src/effort-routing.js +34 -0
- package/dist/src/evidence.d.ts +110 -0
- package/dist/src/evidence.js +195 -0
- package/dist/src/file-diff.d.ts +4 -0
- package/dist/src/file-diff.js +2 -1
- package/dist/src/github-app/agent-writes.d.ts +102 -0
- package/dist/src/github-app/agent-writes.js +320 -0
- package/dist/src/github-app/client.d.ts +368 -0
- package/dist/src/github-app/client.js +830 -0
- package/dist/src/github-app/event-source.d.ts +208 -0
- package/dist/src/github-app/event-source.js +684 -0
- package/dist/src/github-app/metrics.d.ts +32 -0
- package/dist/src/github-app/metrics.js +49 -0
- package/dist/src/github-app/review-loop.d.ts +274 -0
- package/dist/src/github-app/review-loop.js +1177 -0
- package/dist/src/github-app/review-node.d.ts +81 -0
- package/dist/src/github-app/review-node.js +205 -0
- package/dist/src/github-app/review-post.d.ts +73 -0
- package/dist/src/github-app/review-post.js +139 -0
- package/dist/src/github-app/review-text.d.ts +107 -0
- package/dist/src/github-app/review-text.js +1133 -0
- package/dist/src/github-app/review-threads.d.ts +47 -0
- package/dist/src/github-app/review-threads.js +107 -0
- package/dist/src/github-app/reviewer.d.ts +121 -0
- package/dist/src/github-app/reviewer.js +598 -0
- package/dist/src/github-app/store.d.ts +59 -0
- package/dist/src/github-app/store.js +148 -0
- package/dist/src/github-app/triggers.d.ts +141 -0
- package/dist/src/github-app/triggers.js +441 -0
- package/dist/src/github-names.d.ts +15 -0
- package/dist/src/github-names.js +15 -0
- package/dist/src/glob-search.d.ts +61 -0
- package/dist/src/glob-search.js +180 -0
- package/dist/src/graph-health.js +6 -1
- package/dist/src/graph-manager-chat.js +1 -1
- package/dist/src/graph-preview.d.ts +48 -0
- package/dist/src/graph-preview.js +56 -0
- package/dist/src/graph-provider-portability.js +2 -1
- package/dist/src/graph-runner.js +65 -4
- package/dist/src/graph-server.js +7 -5
- package/dist/src/graph-sync.js +3 -3
- package/dist/src/graph-ui/app.js +121 -7
- package/dist/src/graph-ui/icons.js +2 -1
- package/dist/src/graph-ui/studio.js +15 -1
- package/dist/src/graph-ui/tokens.css +1 -1
- package/dist/src/graphs.d.ts +40 -1
- package/dist/src/graphs.js +164 -15
- package/dist/src/hardened-runtime.js +32 -21
- package/dist/src/image-input.d.ts +16 -0
- package/dist/src/image-input.js +41 -0
- package/dist/src/membership.d.ts +10 -0
- package/dist/src/membership.js +19 -4
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +6 -0
- package/dist/src/model-metadata.js +35 -15
- package/dist/src/model-override.d.ts +2 -1
- package/dist/src/model-override.js +9 -0
- package/dist/src/model-relay/local.d.ts +116 -0
- package/dist/src/model-relay/local.js +468 -0
- package/dist/src/model-relay/remote.d.ts +129 -0
- package/dist/src/model-relay/remote.js +252 -0
- package/dist/src/model-relay/runs.d.ts +34 -0
- package/dist/src/model-relay/runs.js +146 -0
- package/dist/src/model-relay/wire.d.ts +5 -0
- package/dist/src/model-relay/wire.js +5 -0
- package/dist/src/model-tiers.d.ts +3 -0
- package/dist/src/model-tiers.js +3 -3
- package/dist/src/project-registry.d.ts +21 -0
- package/dist/src/project-registry.js +74 -0
- package/dist/src/provider-engine.d.ts +13 -1
- package/dist/src/provider-engine.js +74 -0
- package/dist/src/provider-import.d.ts +0 -12
- package/dist/src/provider-import.js +7 -195
- package/dist/src/providers.d.ts +28 -2
- package/dist/src/providers.js +59 -12
- package/dist/src/pull-request-logs.d.ts +12 -1
- package/dist/src/pull-request-logs.js +14 -3
- package/dist/src/pull-requests.d.ts +338 -8
- package/dist/src/pull-requests.js +482 -53
- package/dist/src/react-runtime.js +99 -16
- package/dist/src/remote/engine-pool.d.ts +88 -4
- package/dist/src/remote/engine-pool.js +367 -90
- package/dist/src/remote/roots.d.ts +19 -0
- package/dist/src/remote/roots.js +45 -7
- package/dist/src/remote/types.d.ts +0 -44
- package/dist/src/run-control.d.ts +7 -0
- package/dist/src/run-control.js +23 -0
- package/dist/src/run-records.d.ts +7 -2
- package/dist/src/run-records.js +71 -6
- package/dist/src/runtime.d.ts +34 -2
- package/dist/src/runtime.js +18 -2
- package/dist/src/session-changes.d.ts +35 -0
- package/dist/src/session-changes.js +194 -6
- package/dist/src/session-monitor.js +2 -1
- package/dist/src/session-reaper.d.ts +1 -1
- package/dist/src/session-reaper.js +6 -1
- package/dist/src/session-summary.d.ts +2 -1
- package/dist/src/session-summary.js +2 -1
- package/dist/src/sessions.d.ts +35 -1
- package/dist/src/sessions.js +70 -4
- package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
- package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
- package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
- package/dist/src/skills/bundled/provenance.json +3 -3
- package/dist/src/skills/runtime-skills.js +1 -1
- package/dist/src/task-checkout.d.ts +141 -0
- package/dist/src/task-checkout.js +558 -0
- package/dist/src/telemetry/emitter.d.ts +15 -0
- package/dist/src/telemetry/emitter.js +35 -1
- package/dist/src/telemetry/schema.d.ts +25 -2
- package/dist/src/telemetry/schema.js +52 -4
- package/dist/src/telemetry/surface.d.ts +2 -1
- package/dist/src/telemetry/surface.js +4 -1
- package/dist/src/terminal-ui.d.ts +1 -0
- package/dist/src/terminal-ui.js +10 -3
- package/dist/src/test-edit-guard.d.ts +37 -0
- package/dist/src/test-edit-guard.js +216 -3
- package/dist/src/thinking-level-detect.d.ts +11 -0
- package/dist/src/thinking-level-detect.js +47 -0
- package/dist/src/thinking-levels.d.ts +30 -0
- package/dist/src/thinking-levels.js +124 -0
- package/dist/src/timers.d.ts +3 -0
- package/dist/src/tool-catalog.js +1 -1
- package/dist/src/tools.js +59 -9
- package/dist/src/transcript.js +1 -1
- package/dist/src/types.d.ts +34 -0
- package/package.json +6 -1
- package/dist/src/remote/cert.d.ts +0 -11
- package/dist/src/remote/cert.js +0 -87
- package/dist/src/remote/client.d.ts +0 -119
- package/dist/src/remote/client.js +0 -544
- package/dist/src/remote/command.d.ts +0 -4
- package/dist/src/remote/command.js +0 -194
- package/dist/src/remote/errors.d.ts +0 -11
- package/dist/src/remote/errors.js +0 -14
- package/dist/src/remote/network.d.ts +0 -22
- package/dist/src/remote/network.js +0 -102
- package/dist/src/remote/pairing.d.ts +0 -63
- package/dist/src/remote/pairing.js +0 -299
- package/dist/src/remote/pem.d.ts +0 -2
- package/dist/src/remote/pem.js +0 -7
- package/dist/src/remote/serve.d.ts +0 -68
- package/dist/src/remote/serve.js +0 -244
- package/dist/src/remote/server.d.ts +0 -21
- package/dist/src/remote/server.js +0 -406
|
@@ -11,6 +11,14 @@ export type PendingAttachment = {
|
|
|
11
11
|
} | {
|
|
12
12
|
kind: 'file';
|
|
13
13
|
path: string;
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'upload';
|
|
16
|
+
name: string;
|
|
17
|
+
dataBase64: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'stored-file';
|
|
20
|
+
name: string;
|
|
21
|
+
spoolId: string;
|
|
14
22
|
};
|
|
15
23
|
export interface UserAttachmentRef {
|
|
16
24
|
id: string;
|
|
@@ -61,4 +69,6 @@ export declare function parseAppleScriptHex(text: string): string;
|
|
|
61
69
|
export declare function readClipboardImage(): Promise<Buffer | undefined>;
|
|
62
70
|
export declare function writeClipboardText(text: string): Promise<void>;
|
|
63
71
|
export declare function parsePendingAttachments(value: unknown): PendingAttachment[];
|
|
72
|
+
/** Turn desktop paths into attachment data before the request crosses the Cloud relay. */
|
|
73
|
+
export declare function cloudAttachments(value: unknown): Promise<PendingAttachment[]>;
|
|
64
74
|
export declare function defaultAttachmentsHome(): string;
|
package/dist/src/attachments.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
-
import { existsSync, statSync } from 'node:fs';
|
|
3
|
-
import { mkdir, readFile, readdir, realpath, rm, rename, stat, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { constants, existsSync, statSync } from 'node:fs';
|
|
3
|
+
import { mkdir, open, readFile, readdir, realpath, rm, rename, stat, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { join, relative, resolve, basename, dirname, isAbsolute, sep } from 'node:path';
|
|
6
6
|
import { randomUUID } from 'node:crypto';
|
|
7
7
|
export const MAX_ATTACHMENTS = 10;
|
|
8
8
|
export const MAX_TEXT_ATTACHMENT_CHARS = 1_000_000;
|
|
9
9
|
export const MAX_IMAGE_ATTACHMENT_BYTES = 5 * 1024 * 1024;
|
|
10
|
+
const MAX_CLOUD_ATTACHMENT_WIRE_BYTES = 12 * 1024 * 1024;
|
|
10
11
|
export const PASTE_ATTACH_LINES = 24;
|
|
11
12
|
export const PASTE_ATTACH_CHARS = 2_000;
|
|
12
13
|
const MAX_PATH_PASTE_LINES = 8;
|
|
@@ -78,6 +79,8 @@ export function attachmentLabel(pending) {
|
|
|
78
79
|
return pending.path;
|
|
79
80
|
}
|
|
80
81
|
}
|
|
82
|
+
if (pending.kind === 'upload' || pending.kind === 'stored-file')
|
|
83
|
+
return pending.name;
|
|
81
84
|
if (pending.kind === 'image') {
|
|
82
85
|
const bytes = Math.floor(pending.dataBase64.length * 3 / 4);
|
|
83
86
|
return `${pending.name ?? 'clipboard.png'} (${formatBytes(bytes)})`;
|
|
@@ -132,6 +135,14 @@ export async function resolveAttachments(home, workspace, pendings, createdSpool
|
|
|
132
135
|
refs.push({ id, kind: 'image', name, path, bytes: data.length, mimeType: pending.mimeType });
|
|
133
136
|
images.push({ mimeType: pending.mimeType, data: data.toString('base64') });
|
|
134
137
|
}
|
|
138
|
+
else if (pending.kind === 'upload' || pending.kind === 'stored-file') {
|
|
139
|
+
const data = pending.kind === 'upload' ? Buffer.from(pending.dataBase64, 'base64') : await readStoredAttachment(home, pending);
|
|
140
|
+
const name = sanitizeName(pending.name, 'attachment');
|
|
141
|
+
const { id, path } = await spool(home, name, file => writeFile(file, data, { mode: 0o600 }));
|
|
142
|
+
spooled.push({ path });
|
|
143
|
+
createdSpools?.push(dirname(path));
|
|
144
|
+
refs.push({ id, kind: 'file', name, path, bytes: data.length });
|
|
145
|
+
}
|
|
135
146
|
else {
|
|
136
147
|
const path = resolve(pending.path);
|
|
137
148
|
const info = await stat(path).catch(() => undefined);
|
|
@@ -172,15 +183,24 @@ export function attachmentReferenceBlock(refs, options = {}) {
|
|
|
172
183
|
}
|
|
173
184
|
const SPOOL_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
174
185
|
export async function attachmentReadRoots(home, refs) {
|
|
186
|
+
if (refs.length === 0)
|
|
187
|
+
return [];
|
|
175
188
|
const base = attachmentsDirectory(home);
|
|
189
|
+
const canonicalBase = await realpath(base).catch(() => undefined);
|
|
190
|
+
if (canonicalBase === undefined)
|
|
191
|
+
return [];
|
|
176
192
|
const roots = new Set();
|
|
177
193
|
for (const ref of refs) {
|
|
178
|
-
if (ref.kind === 'file')
|
|
179
|
-
continue;
|
|
180
194
|
const directory = dirname(ref.path);
|
|
181
|
-
|
|
195
|
+
const spoolId = basename(directory);
|
|
196
|
+
if (!SPOOL_ID.test(spoolId) || relative(base, directory) !== spoolId)
|
|
197
|
+
continue;
|
|
198
|
+
// Uploaded files use the spool id as their ref id. Ordinary path attachments have independent ids.
|
|
199
|
+
if (ref.kind === 'file' && (ref.directory || ref.id !== spoolId))
|
|
182
200
|
continue;
|
|
183
|
-
|
|
201
|
+
const canonicalDirectory = await realpath(directory).catch(() => undefined);
|
|
202
|
+
if (canonicalDirectory !== undefined && relative(canonicalBase, canonicalDirectory) === spoolId)
|
|
203
|
+
roots.add(canonicalDirectory);
|
|
184
204
|
}
|
|
185
205
|
return [...roots];
|
|
186
206
|
}
|
|
@@ -334,13 +354,88 @@ export function parsePendingAttachments(value) {
|
|
|
334
354
|
throw new Error(`attachments[${index}] exceeds the ${formatBytes(MAX_IMAGE_ATTACHMENT_BYTES)} image limit`);
|
|
335
355
|
return { kind: 'image', ...(name === undefined ? {} : { name }), mimeType: record.mimeType, dataBase64: record.dataBase64 };
|
|
336
356
|
}
|
|
357
|
+
if (record.kind === 'stored-file') {
|
|
358
|
+
if (name === undefined || !validStoredAttachment(record.spoolId, name))
|
|
359
|
+
throw new Error(`attachments[${index}] must identify a stored attachment`);
|
|
360
|
+
return { kind: 'stored-file', name, spoolId: record.spoolId };
|
|
361
|
+
}
|
|
362
|
+
if (record.kind === 'upload') {
|
|
363
|
+
if (!name || typeof record.dataBase64 !== 'string' || record.dataBase64.length > Math.ceil(MAX_IMAGE_ATTACHMENT_BYTES / 3) * 4) {
|
|
364
|
+
throw new Error(`attachments[${index}] must be a named file up to 5 MB`);
|
|
365
|
+
}
|
|
366
|
+
const data = Buffer.from(record.dataBase64, 'base64');
|
|
367
|
+
if (data.length > MAX_IMAGE_ATTACHMENT_BYTES || data.toString('base64') !== record.dataBase64) {
|
|
368
|
+
throw new Error(`attachments[${index}] has invalid file data`);
|
|
369
|
+
}
|
|
370
|
+
return { kind: 'upload', name, dataBase64: record.dataBase64 };
|
|
371
|
+
}
|
|
337
372
|
if (record.kind === 'file') {
|
|
338
373
|
if (typeof record.path !== 'string' || !record.path.trim())
|
|
339
374
|
throw new Error(`attachments[${index}].path must be a filesystem path`);
|
|
340
375
|
return { kind: 'file', path: record.path };
|
|
341
376
|
}
|
|
342
|
-
throw new Error(`attachments[${index}].kind must be text, image, or file`);
|
|
377
|
+
throw new Error(`attachments[${index}].kind must be text, image, file, upload, or stored-file`);
|
|
343
378
|
});
|
|
344
379
|
}
|
|
380
|
+
/** Turn desktop paths into attachment data before the request crosses the Cloud relay. */
|
|
381
|
+
export async function cloudAttachments(value) {
|
|
382
|
+
const attachments = [];
|
|
383
|
+
let bytes = 2;
|
|
384
|
+
for (const pending of parsePendingAttachments(value)) {
|
|
385
|
+
let attachment = pending;
|
|
386
|
+
if (pending.kind === 'file') {
|
|
387
|
+
const name = basename(pending.path);
|
|
388
|
+
const data = await readAttachmentFile(pending.path, name);
|
|
389
|
+
const mimeType = imageSignatureMime(data);
|
|
390
|
+
const dataBase64 = data.toString('base64');
|
|
391
|
+
attachment = mimeType === undefined ? { kind: 'upload', name, dataBase64 } : { kind: 'image', name, mimeType, dataBase64 };
|
|
392
|
+
}
|
|
393
|
+
bytes += Buffer.byteLength(JSON.stringify(attachment)) + 1;
|
|
394
|
+
if (bytes > MAX_CLOUD_ATTACHMENT_WIRE_BYTES)
|
|
395
|
+
throw new Error('These attachments exceed the combined Cloud transfer limit. Send fewer attachments at a time.');
|
|
396
|
+
attachments.push(attachment);
|
|
397
|
+
}
|
|
398
|
+
return attachments;
|
|
399
|
+
}
|
|
400
|
+
function validStoredAttachment(spoolId, name) {
|
|
401
|
+
return typeof spoolId === 'string' && SPOOL_ID.test(spoolId) && name !== '' && sanitizeName(name, '') === name;
|
|
402
|
+
}
|
|
403
|
+
/** Resolve a returned attachment on the engine that created its spool, using its id and name only. */
|
|
404
|
+
async function readStoredAttachment(home, pending) {
|
|
405
|
+
const { name, spoolId } = pending;
|
|
406
|
+
if (!validStoredAttachment(spoolId, name))
|
|
407
|
+
throw new Error('Invalid stored attachment reference.');
|
|
408
|
+
const base = await realpath(attachmentsDirectory(home)).catch(() => undefined);
|
|
409
|
+
const entry = base === undefined ? undefined : await realpath(join(base, spoolId, name)).catch(() => undefined);
|
|
410
|
+
if (base === undefined || entry === undefined || relative(base, entry) !== join(spoolId, name)) {
|
|
411
|
+
throw new Error(`Attachment ${name} is no longer available on Cloud. Attach it again to resend.`);
|
|
412
|
+
}
|
|
413
|
+
return readAttachmentFile(entry, name);
|
|
414
|
+
}
|
|
415
|
+
async function readAttachmentFile(path, name) {
|
|
416
|
+
const file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK)
|
|
417
|
+
.catch(() => { throw new Error(`Could not open attachment ${name}.`); });
|
|
418
|
+
try {
|
|
419
|
+
const info = await file.stat();
|
|
420
|
+
if (!info.isFile())
|
|
421
|
+
throw new Error(`Attach individual files to Cloud. ${name} is not a regular file.`);
|
|
422
|
+
if (info.size > MAX_IMAGE_ATTACHMENT_BYTES)
|
|
423
|
+
throw new Error(`${name} exceeds the 5 MB Cloud file limit.`);
|
|
424
|
+
const buffer = Buffer.alloc(info.size + 1);
|
|
425
|
+
let length = 0;
|
|
426
|
+
while (length < buffer.length) {
|
|
427
|
+
const { bytesRead } = await file.read(buffer, length, buffer.length - length, length);
|
|
428
|
+
if (bytesRead === 0)
|
|
429
|
+
break;
|
|
430
|
+
length += bytesRead;
|
|
431
|
+
}
|
|
432
|
+
if (length !== info.size)
|
|
433
|
+
throw new Error(`${name} changed while it was being attached. Try again.`);
|
|
434
|
+
return buffer.subarray(0, length);
|
|
435
|
+
}
|
|
436
|
+
finally {
|
|
437
|
+
await file.close();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
345
440
|
const throwName = (index) => { throw new Error(`attachments[${index}].name must be a string`); };
|
|
346
441
|
export function defaultAttachmentsHome() { return process.env.ANDORRACODE_HOME || join(homedir(), '.andorracode'); }
|
|
@@ -46,7 +46,8 @@ export function createAutomationTool() {
|
|
|
46
46
|
}
|
|
47
47
|
const { action: _action, id: _id, ...input } = args;
|
|
48
48
|
if (args.action === 'create') {
|
|
49
|
-
|
|
49
|
+
// Filed under the task's project, not under the worktree the task happens to work in.
|
|
50
|
+
input.project ??= context.project ?? context.workspace;
|
|
50
51
|
input.execution = { ...context.wakeCarry, permissions: permissionMode(context) ?? 'ask-for-approval' };
|
|
51
52
|
input.execution = Object.fromEntries(Object.entries(input.execution).filter(([key]) => ['provider', 'model', 'graph', 'permissions', 'reasoningEffort'].includes(key)));
|
|
52
53
|
assertPlanMutationAllowed(context);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** How often a Cloud instance tells the service whether anyone is using it. */
|
|
2
|
+
export declare const HEARTBEAT_MS = 60000;
|
|
3
|
+
export declare const MAX_BOOT_INPUT_BYTES = 4096;
|
|
4
|
+
/**
|
|
5
|
+
* The link in progress, next to bridge.json. It holds the secret before the boot code is spent, so a link the service
|
|
6
|
+
* accepted is never lost to a failed write: a later run finds it complete and only renames it into place.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PENDING_IDENTITY = "bridge.json.pending";
|
|
9
|
+
/** Shares ~/work when no folder is shared yet, so Cloud always has somewhere to work. */
|
|
10
|
+
export declare function ensureWorkFolder(directory: string, workDirectory?: string): Promise<void>;
|
|
11
|
+
type BootInput = {
|
|
12
|
+
apiBase: string;
|
|
13
|
+
directory: string;
|
|
14
|
+
print(line: string): void;
|
|
15
|
+
workDirectory?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Links a Cloud instance to its owner with the one-time boot code read from stdin, or, with only an environment id,
|
|
19
|
+
* finishes a link the service already accepted. A boot whose answer does not prove a refusal keeps the pending secret,
|
|
20
|
+
* which is proved at once when the environment id is known, and otherwise by the next boot. The code and the secret are
|
|
21
|
+
* never printed: the secret is made here, a boot sends only its hash, and a recovery presents it to the token route
|
|
22
|
+
* exactly as `andorra bridge run` does.
|
|
23
|
+
*/
|
|
24
|
+
export declare function runCloudBoot(input: BootInput & {
|
|
25
|
+
stdin: string;
|
|
26
|
+
}): Promise<number>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { createHash, randomBytes, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { loadConfig } from '../config.js';
|
|
6
|
+
import { cloudBoot, ControlError, environmentToken } from './control.js';
|
|
7
|
+
import { readBridgeIdentity, shareFolder } from './store.js';
|
|
8
|
+
/** How often a Cloud instance tells the service whether anyone is using it. */
|
|
9
|
+
export const HEARTBEAT_MS = 60_000;
|
|
10
|
+
export const MAX_BOOT_INPUT_BYTES = 4096;
|
|
11
|
+
const RESTART = 'Stop and start Cloud again.';
|
|
12
|
+
const REFUSED_BOOT = {
|
|
13
|
+
boot_expired: `This instance's start code expired. ${RESTART}`,
|
|
14
|
+
boot_used: `This instance's start code was already used. ${RESTART}`,
|
|
15
|
+
boot_unknown: `This instance's start code was not recognised. ${RESTART}`,
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Boot answers that prove the service refused this code and recorded nothing for it, so no later call with the same
|
|
19
|
+
* secret can link: only then is the pending secret dropped. "Already used" is not one (the first, unanswered attempt may
|
|
20
|
+
* be what used it), and neither is any server, network or unreadable answer.
|
|
21
|
+
*/
|
|
22
|
+
const PROVEN_REFUSALS = new Set(['boot_unknown', 'boot_expired']);
|
|
23
|
+
const REFUSED_SECRET = 'Could not finish linking this instance: the Andorra service did not accept its secret. Delete Cloud and start it again.';
|
|
24
|
+
const ENVIRONMENT_ID = /^env_[A-Za-z0-9_-]{22}$/;
|
|
25
|
+
/**
|
|
26
|
+
* The link in progress, next to bridge.json. It holds the secret before the boot code is spent, so a link the service
|
|
27
|
+
* accepted is never lost to a failed write: a later run finds it complete and only renames it into place.
|
|
28
|
+
*/
|
|
29
|
+
export const PENDING_IDENTITY = 'bridge.json.pending';
|
|
30
|
+
async function readPending(directory) {
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(await readFile(join(directory, PENDING_IDENTITY), 'utf8'));
|
|
33
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
34
|
+
return undefined;
|
|
35
|
+
const found = parsed;
|
|
36
|
+
if (typeof found.secret !== 'string' || !found.secret)
|
|
37
|
+
return undefined;
|
|
38
|
+
const pending = { secret: found.secret };
|
|
39
|
+
for (const key of ['environmentId', 'name', 'linkedAt']) {
|
|
40
|
+
if (typeof found[key] === 'string' && found[key])
|
|
41
|
+
pending[key] = found[key];
|
|
42
|
+
}
|
|
43
|
+
return pending;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function complete(pending) {
|
|
50
|
+
return Boolean(pending?.environmentId && pending.name && pending.linkedAt);
|
|
51
|
+
}
|
|
52
|
+
/** Replaces the pending file whole, so a failed write never leaves it without the secret it already held. */
|
|
53
|
+
async function writePending(directory, pending) {
|
|
54
|
+
await mkdir(directory, { recursive: true });
|
|
55
|
+
const target = join(directory, PENDING_IDENTITY);
|
|
56
|
+
const temporary = `${target}.${randomUUID()}.tmp`;
|
|
57
|
+
try {
|
|
58
|
+
await writeFile(temporary, `${JSON.stringify(pending, null, 2)}\n`, { mode: 0o600 });
|
|
59
|
+
await rename(temporary, target);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
await rm(temporary, { force: true }).catch(() => undefined);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function finishLink(directory) {
|
|
67
|
+
await rename(join(directory, PENDING_IDENTITY), join(directory, 'bridge.json'));
|
|
68
|
+
}
|
|
69
|
+
/** Shares ~/work when no folder is shared yet, so Cloud always has somewhere to work. */
|
|
70
|
+
export async function ensureWorkFolder(directory, workDirectory) {
|
|
71
|
+
if (((await loadConfig(directory)).bridge?.folders ?? []).length > 0)
|
|
72
|
+
return;
|
|
73
|
+
const work = workDirectory ?? join(homedir(), 'work');
|
|
74
|
+
await mkdir(work, { recursive: true });
|
|
75
|
+
await shareFolder(directory, work, 'work');
|
|
76
|
+
}
|
|
77
|
+
function bootInput(stdin) {
|
|
78
|
+
if (Buffer.byteLength(stdin) > MAX_BOOT_INPUT_BYTES)
|
|
79
|
+
return {};
|
|
80
|
+
try {
|
|
81
|
+
const parsed = JSON.parse(stdin);
|
|
82
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
83
|
+
return {};
|
|
84
|
+
const { bootCode, environmentId } = parsed;
|
|
85
|
+
return {
|
|
86
|
+
...(typeof bootCode === 'string' && bootCode ? { bootCode } : {}),
|
|
87
|
+
...(typeof environmentId === 'string' && ENVIRONMENT_ID.test(environmentId) ? { environmentId } : {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function saveLink(directory, environmentId, secret, print) {
|
|
95
|
+
try {
|
|
96
|
+
await writePending(directory, { environmentId, name: 'Cloud', secret, linkedAt: new Date().toISOString() });
|
|
97
|
+
await finishLink(directory);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
print(`Linked, but could not save this instance's link: ${error instanceof Error ? error.message : String(error)}. Run the boot again to finish.`);
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
print('Linked as Cloud.');
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Whether the service accepts the pending secret for this environment: the proof that a link it was asked for was
|
|
108
|
+
* recorded, though its answer was lost. The local file is not trusted alone. Answers the failure when it is not proved.
|
|
109
|
+
*/
|
|
110
|
+
async function proveLink(input, environmentId, secret) {
|
|
111
|
+
try {
|
|
112
|
+
await ensureWorkFolder(input.directory, input.workDirectory);
|
|
113
|
+
await environmentToken(input.apiBase, environmentId, secret);
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
return error ?? new Error('unknown failure');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Finishes a link the service accepted but whose answer was lost, on a restart that carries no boot code. */
|
|
121
|
+
async function finishAcceptedLink(input, environmentId, secret) {
|
|
122
|
+
const error = await proveLink(input, environmentId, secret);
|
|
123
|
+
if (error === undefined)
|
|
124
|
+
return saveLink(input.directory, environmentId, secret, input.print);
|
|
125
|
+
if (error instanceof ControlError)
|
|
126
|
+
input.print(error.code === 'unlinked' ? REFUSED_SECRET : `Could not reach Andorra: ${error.message}`);
|
|
127
|
+
else
|
|
128
|
+
input.print(`Could not link this instance: ${error instanceof Error ? error.message : String(error)}`);
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Links a Cloud instance to its owner with the one-time boot code read from stdin, or, with only an environment id,
|
|
133
|
+
* finishes a link the service already accepted. A boot whose answer does not prove a refusal keeps the pending secret,
|
|
134
|
+
* which is proved at once when the environment id is known, and otherwise by the next boot. The code and the secret are
|
|
135
|
+
* never printed: the secret is made here, a boot sends only its hash, and a recovery presents it to the token route
|
|
136
|
+
* exactly as `andorra bridge run` does.
|
|
137
|
+
*/
|
|
138
|
+
export async function runCloudBoot(input) {
|
|
139
|
+
const { apiBase, directory, print } = input;
|
|
140
|
+
if (await readBridgeIdentity(directory)) {
|
|
141
|
+
print('Already linked.');
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
const pending = await readPending(directory);
|
|
145
|
+
if (complete(pending)) {
|
|
146
|
+
try {
|
|
147
|
+
await finishLink(directory);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
print(`Could not save this instance's link: ${error instanceof Error ? error.message : String(error)}`);
|
|
151
|
+
return 1;
|
|
152
|
+
}
|
|
153
|
+
print('Linked as Cloud.');
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
const { bootCode, environmentId } = bootInput(input.stdin);
|
|
157
|
+
if (bootCode === undefined && pending && environmentId !== undefined)
|
|
158
|
+
return finishAcceptedLink(input, environmentId, pending.secret);
|
|
159
|
+
if (bootCode === undefined) {
|
|
160
|
+
print('Could not link this instance: the start code was missing or malformed.');
|
|
161
|
+
return 1;
|
|
162
|
+
}
|
|
163
|
+
// A link whose answer never arrived is retried with the same secret, in case the service recorded it.
|
|
164
|
+
const secret = pending?.secret ?? randomBytes(32).toString('base64url');
|
|
165
|
+
let linked;
|
|
166
|
+
try {
|
|
167
|
+
await writePending(directory, { secret });
|
|
168
|
+
await ensureWorkFolder(directory, input.workDirectory);
|
|
169
|
+
linked = await cloudBoot(apiBase, bootCode, createHash('sha256').update(secret).digest('hex'));
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
if (!(error instanceof ControlError)) {
|
|
173
|
+
print(`Could not link this instance: ${error instanceof Error ? error.message : String(error)}`);
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
if (PROVEN_REFUSALS.has(error.code)) {
|
|
177
|
+
await rm(join(directory, PENDING_IDENTITY), { force: true }).catch(() => undefined);
|
|
178
|
+
}
|
|
179
|
+
else if (environmentId !== undefined && await proveLink(input, environmentId, secret) === undefined) {
|
|
180
|
+
// The service may have recorded the link before its answer was lost; it accepts the secret if so.
|
|
181
|
+
return saveLink(directory, environmentId, secret, print);
|
|
182
|
+
}
|
|
183
|
+
print(REFUSED_BOOT[error.code] ?? `Could not reach Andorra: ${error.message}`);
|
|
184
|
+
return 1;
|
|
185
|
+
}
|
|
186
|
+
return saveLink(directory, linked.environmentId, secret, print);
|
|
187
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { runBridgeHost } from './host.js';
|
|
2
|
+
import { bridgeCommand } from './wording.js';
|
|
3
|
+
export { bridgeCommand };
|
|
4
|
+
export declare function bridgeUsage(launched?: boolean): string;
|
|
5
|
+
export declare const BRIDGE_USAGE: string;
|
|
6
|
+
export declare function cloudApiBase(environment: NodeJS.ProcessEnv): string | undefined;
|
|
7
|
+
/** How often a running bridge checks that this machine is still linked locally (bridge.json unchanged). */
|
|
8
|
+
export declare const IDENTITY_CHECK_MS = 10000;
|
|
9
|
+
export interface BridgeCommandDependencies {
|
|
10
|
+
version?: string;
|
|
11
|
+
apiBase?: string;
|
|
12
|
+
sleep?: (ms: number) => Promise<void>;
|
|
13
|
+
now?: () => number;
|
|
14
|
+
runHost?: typeof runBridgeHost;
|
|
15
|
+
/** Where a Cloud instance's work folder lives; defaults to ~/work. */
|
|
16
|
+
workDirectory?: string;
|
|
17
|
+
/** Whether a person can answer a question on this terminal; defaults to whether stdin is a TTY. */
|
|
18
|
+
interactive?: boolean;
|
|
19
|
+
/** Asks one question on the terminal and resolves with the answer typed. */
|
|
20
|
+
ask?: (question: string) => Promise<string>;
|
|
21
|
+
/** Whether this command runs over SSH, where the person is not at the machine; defaults to SSH_CONNECTION or SSH_TTY being set. */
|
|
22
|
+
overSsh?: boolean;
|
|
23
|
+
/** Opens an address on this computer and says whether it worked; defaults to the platform's opener. */
|
|
24
|
+
open?: (address: string) => Promise<boolean>;
|
|
25
|
+
/** Whether this machine runs under the bridge launcher (no "andorra" command); defaults to ANDORRA_BRIDGE_LAUNCHER being exactly 1. */
|
|
26
|
+
launched?: boolean;
|
|
27
|
+
/** The platform the opener and the stop signals are chosen for; defaults to process.platform. */
|
|
28
|
+
platform?: NodeJS.Platform;
|
|
29
|
+
}
|
|
30
|
+
export declare function runBridgeCommand(args: string[], print: (line: string) => void, dependencies?: BridgeCommandDependencies): Promise<number>;
|