@andorra-labs/code 0.1.10 → 0.1.12
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/README.md +31 -205
- package/THIRD_PARTY_NOTICES.md +30 -0
- package/dist/src/agent-execution.js +50 -2
- package/dist/src/agent-mcp.js +5 -0
- package/dist/src/app-server/protocol.d.ts +9 -1
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server.d.ts +49 -1
- package/dist/src/app-server.js +353 -64
- package/dist/src/automation-service.js +1 -1
- package/dist/src/browser-panel-tool.d.ts +24 -3
- package/dist/src/browser-panel-tool.js +80 -6
- package/dist/src/browser-runner.js +3 -1
- package/dist/src/browser-session.d.ts +8 -0
- package/dist/src/browser-session.js +27 -1
- package/dist/src/browser-ui/app.js +237 -15
- package/dist/src/browser-ui/index.html +5 -5
- package/dist/src/browser-ui/style.css +110 -65
- package/dist/src/browser-ui/tokens.css +27 -26
- package/dist/src/browser-view.d.ts +16 -0
- package/dist/src/browser-view.js +38 -2
- package/dist/src/claude-provider.js +15 -2
- package/dist/src/cli.d.ts +2 -1
- package/dist/src/cli.js +175 -43
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +1 -1
- package/dist/src/codex-provider.js +6 -3
- package/dist/src/coding-tools.d.ts +26 -1
- package/dist/src/coding-tools.js +104 -33
- package/dist/src/command-screens.js +1 -1
- package/dist/src/commands.js +1 -1
- package/dist/src/completion-gates.d.ts +42 -7
- package/dist/src/completion-gates.js +55 -9
- package/dist/src/completion.d.ts +51 -1
- package/dist/src/completion.js +164 -5
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.js +2 -0
- package/dist/src/dashboard-view.js +2 -2
- package/dist/src/deadline.js +4 -0
- package/dist/src/decision/PreparedSteps.js +1 -1
- package/dist/src/delegation-changes.js +19 -2
- package/dist/src/diff-preview.d.ts +1 -0
- package/dist/src/diff-preview.js +12 -3
- package/dist/src/engine-streams.d.ts +22 -0
- package/dist/src/engine-streams.js +16 -0
- package/dist/src/extensions.js +17 -6
- package/dist/src/file-read-key.d.ts +8 -0
- package/dist/src/file-read-key.js +12 -0
- package/dist/src/graph-editor-session.js +2 -1
- package/dist/src/graph-health.d.ts +21 -0
- package/dist/src/graph-health.js +46 -0
- package/dist/src/graph-manager-chat.d.ts +52 -3
- package/dist/src/graph-manager-chat.js +62 -17
- package/dist/src/graph-runner.js +62 -5
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +48 -27
- package/dist/src/graph-sync.d.ts +8 -0
- package/dist/src/graph-sync.js +54 -3
- package/dist/src/graph-tool.js +1 -1
- package/dist/src/graph-ui/app.js +362 -123
- package/dist/src/graph-ui/controls.css +95 -22
- package/dist/src/graph-ui/controls.js +31 -1
- package/dist/src/graph-ui/embed.js +62 -13
- package/dist/src/graph-ui/icons.js +7 -0
- package/dist/src/graph-ui/index.html +4 -4
- package/dist/src/graph-ui/manager-state.js +143 -5
- package/dist/src/graph-ui/manager.css +21 -20
- package/dist/src/graph-ui/manager.js +337 -75
- package/dist/src/graph-ui/model-picker.js +279 -0
- package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
- package/dist/src/graph-ui/skill-picker.js +1 -1
- package/dist/src/graph-ui/studio-canvas.js +8 -8
- package/dist/src/graph-ui/studio.css +18 -15
- package/dist/src/graph-ui/studio.js +92 -35
- package/dist/src/graph-ui/style.css +122 -79
- package/dist/src/graph-ui/theme.js +2 -2
- package/dist/src/graph-ui/tokens.css +33 -29
- package/dist/src/graphs.d.ts +5 -2
- package/dist/src/graphs.js +10 -9
- package/dist/src/mcp.d.ts +52 -14
- package/dist/src/mcp.js +285 -128
- package/dist/src/membership-errors.d.ts +7 -1
- package/dist/src/membership-errors.js +9 -3
- package/dist/src/memory/ProjectMemory.d.ts +77 -0
- package/dist/src/memory/ProjectMemory.js +310 -0
- package/dist/src/memory/index.d.ts +1 -0
- package/dist/src/memory/index.js +1 -0
- package/dist/src/opencode-provider.js +5 -6
- package/dist/src/package-name.d.ts +3 -0
- package/dist/src/package-name.js +3 -0
- package/dist/src/provider-engine.js +2 -2
- package/dist/src/pull-requests.d.ts +42 -6
- package/dist/src/pull-requests.js +11 -3
- package/dist/src/qa/runtime/PtyManager.js +2 -1
- package/dist/src/react-runtime.js +137 -22
- package/dist/src/read-document-doc.d.ts +20 -0
- package/dist/src/read-document-doc.js +524 -0
- package/dist/src/read-document-docx.d.ts +21 -0
- package/dist/src/read-document-docx.js +584 -0
- package/dist/src/read-document-text.d.ts +29 -0
- package/dist/src/read-document-text.js +67 -0
- package/dist/src/read-document-tool.d.ts +48 -0
- package/dist/src/read-document-tool.js +162 -0
- package/dist/src/read-document.d.ts +78 -0
- package/dist/src/read-document.js +353 -0
- package/dist/src/read-image.d.ts +29 -2
- package/dist/src/read-image.js +42 -17
- package/dist/src/remote/cert.d.ts +1 -1
- package/dist/src/remote/cert.js +2 -7
- package/dist/src/remote/client.js +1 -1
- package/dist/src/remote/pem.d.ts +6 -0
- package/dist/src/remote/pem.js +11 -0
- package/dist/src/run-records.js +49 -10
- package/dist/src/runtime.d.ts +21 -0
- package/dist/src/runtime.js +10 -1
- package/dist/src/session-changes.d.ts +6 -1
- package/dist/src/session-changes.js +13 -5
- package/dist/src/sessions.d.ts +3 -1
- package/dist/src/sessions.js +5 -3
- package/dist/src/side-panel.d.ts +6 -1
- package/dist/src/side-panel.js +12 -10
- package/dist/src/sign-in-detection.d.ts +82 -0
- package/dist/src/sign-in-detection.js +197 -0
- package/dist/src/sign-in-offer.d.ts +35 -0
- package/dist/src/sign-in-offer.js +116 -0
- package/dist/src/skills/bundled/create-skill/SKILL.md +1 -1
- package/dist/src/skills/bundled/diagram/SKILL.md +1 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +59 -7
- package/dist/src/skills/bundled/graph-manager/patterns.md +27 -0
- package/dist/src/skills/bundled/provenance.json +4 -4
- package/dist/src/skills/runtime-skills.d.ts +6 -0
- package/dist/src/skills/runtime-skills.js +16 -3
- package/dist/src/stall-recovery.d.ts +6 -2
- package/dist/src/stall-recovery.js +7 -2
- package/dist/src/stray-files.d.ts +14 -0
- package/dist/src/stray-files.js +81 -0
- package/dist/src/subagent-run.js +6 -1
- package/dist/src/terminal-ui.d.ts +1 -1
- package/dist/src/terminal-ui.js +11 -5
- package/dist/src/time-limit.d.ts +53 -0
- package/dist/src/time-limit.js +79 -0
- package/dist/src/tool-activity.js +1 -1
- package/dist/src/tool-schema-compatibility.d.ts +7 -2
- package/dist/src/tool-schema-compatibility.js +8 -4
- package/dist/src/tools.js +92 -7
- package/dist/src/transcript.d.ts +5 -0
- package/dist/src/transcript.js +12 -4
- package/dist/src/types.d.ts +8 -0
- package/dist/src/untracked-file-removal.d.ts +3 -0
- package/dist/src/untracked-file-removal.js +125 -0
- package/dist/src/update-check.js +1 -1
- package/dist/src/update.d.ts +11 -1
- package/dist/src/update.js +27 -5
- package/dist/src/usage-analytics.d.ts +3 -1
- package/dist/src/usage-analytics.js +16 -2
- package/dist/src/workspace-git-metadata.d.ts +15 -0
- package/dist/src/workspace-git-metadata.js +50 -1
- package/dist/src/workspace-instructions.js +1 -1
- package/package.json +6 -26
- package/docs/README.md +0 -36
- package/docs/agents/README.md +0 -62
- package/docs/agents/install-for-agents.md +0 -56
- package/docs/agents/mcp-server.md +0 -212
- package/docs/agents/subagent-mode.md +0 -149
- package/docs/concepts/README.md +0 -47
- package/docs/concepts/jev-actionable-routing.md +0 -113
- package/docs/concepts/jev-decision-thresholds.md +0 -412
- package/docs/concepts/jev-efficiency.md +0 -217
- package/docs/concepts/jev-eval-2026-11-01.md +0 -78
- package/docs/concepts/limits.md +0 -52
- package/docs/concepts/memory.md +0 -10
- package/docs/concepts/security.md +0 -50
- package/docs/concepts/workspace-instructions.md +0 -29
- package/docs/getting-started/README.md +0 -82
- package/docs/getting-started/accounts.md +0 -78
- package/docs/getting-started/configure-providers.md +0 -132
- package/docs/guides/README.md +0 -13
- package/docs/guides/browser.md +0 -39
- package/docs/guides/desktop-app.md +0 -414
- package/docs/guides/extensions.md +0 -102
- package/docs/guides/graph-builder.md +0 -116
- package/docs/guides/headless.md +0 -46
- package/docs/guides/tui.md +0 -75
- package/docs/guides/update.md +0 -70
- package/docs/guides/web-search.md +0 -51
- package/docs/guides/windows-code-signing.md +0 -319
- package/docs/llms.txt +0 -45
- package/docs/reference/README.md +0 -7
- package/docs/reference/cli.md +0 -76
- package/docs/reference/config.md +0 -91
- package/docs/reference/slash-commands.md +0 -59
- package/docs/superpowers/plans/2026-11-01-claude-console-sign-in.md +0 -111
- package/docs/superpowers/plans/2026-11-01-jev-node-opt-in.md +0 -910
- package/docs/superpowers/plans/2026-11-02-workflow-pane.md +0 -398
- package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +0 -125
- package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +0 -295
- package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +0 -203
- package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +0 -79
- package/docs/superpowers/specs/2026-10-31-work-line-summary-design.md +0 -50
- package/docs/superpowers/specs/2026-11-01-claude-console-sign-in-design.md +0 -176
- package/docs/superpowers/specs/2026-11-01-jev-node-opt-in-design.md +0 -164
- package/docs/superpowers/specs/2026-11-01-pr-section-design.md +0 -111
- package/docs/superpowers/specs/2026-11-02-workflow-pane-design.md +0 -130
- package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +0 -206
- package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +0 -291
- package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +0 -182
- package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +0 -156
- package/scripts/jev-efficiency-eval.mjs +0 -187
- package/scripts/jev-efficiency-live.mjs +0 -193
- package/scripts/zcode-engine-replay.mjs +0 -223
- package/tests/agent-centric-mcp-test-plan.md +0 -208
- package/tests/analytics-settings-test-plan.md +0 -165
- package/tests/browser-cli-smoke.mjs +0 -276
- package/tests/browser-test-plan.md +0 -280
- package/tests/chat-side-panel-test-plan.md +0 -309
- package/tests/decision-engine-test-plan.md +0 -163
- package/tests/default-active-jev-test-plan.md +0 -85
- package/tests/harness-extensions-test-plan.md +0 -113
- package/tests/jev-all-decisions-test-plan.md +0 -156
- package/tests/jev-efficiency/criteria.json +0 -158
- package/tests/jev-efficiency/workloads.mjs +0 -242
- package/tests/jev-efficiency-test-plan.md +0 -198
- package/tests/permissions-sandbox-probe.mjs +0 -74
- package/tests/permissions-test-plan.md +0 -191
- package/tests/product-telemetry-test-plan.md +0 -536
- package/tests/thinking-stream-preview-test-plan.md +0 -136
- package/tests/zcode-react-engine-test-plan.md +0 -396
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a model working under a wall-clock limit is told about it.
|
|
3
|
+
*
|
|
4
|
+
* The runtime has always enforced `limits.wallTimeMs`: when the clock runs out the attempt is
|
|
5
|
+
* stopped where it stands. The model was never told there was a clock. In a benchmark run with a
|
|
6
|
+
* fifteen-minute limit the agent spent the whole allowance at full reasoning effort on one build,
|
|
7
|
+
* was stopped with nothing usable on disk, and never knew the end was near; the trials that
|
|
8
|
+
* survived a stop did so only because their output happened to be written already.
|
|
9
|
+
*
|
|
10
|
+
* So a bounded attempt is told three things: that there is a limit and what it means for how to
|
|
11
|
+
* work (once, in the system prompt, where it never changes and so never disturbs the cached
|
|
12
|
+
* prefix), and how much time is left as it runs down (a short runtime message when half, a quarter
|
|
13
|
+
* and a tenth remain, appended at the tail of the conversation). An unbounded attempt, which is the
|
|
14
|
+
* default, is told nothing.
|
|
15
|
+
* @module time-limit
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Below this a limit is too short for a notice to be acted on; the prompt line still applies.
|
|
19
|
+
* A node inside a graph is handed what is left of the graph's limit, a few milliseconds under the
|
|
20
|
+
* configured figure, so a configured two minutes must sit clear of this floor.
|
|
21
|
+
*/
|
|
22
|
+
export declare const TIME_NOTICE_MIN_LIMIT_MS = 90000;
|
|
23
|
+
interface Stage {
|
|
24
|
+
id: 'half' | 'quarter' | 'tenth';
|
|
25
|
+
remaining: number;
|
|
26
|
+
text: (left: string) => string;
|
|
27
|
+
}
|
|
28
|
+
/** "about 7 minutes" or "about 40 seconds": the model plans in round figures, not milliseconds. */
|
|
29
|
+
export declare function formatTimeLeft(ms: number): string;
|
|
30
|
+
/** The system-prompt paragraph for an attempt that has `limitMs` of wall-clock time. */
|
|
31
|
+
export declare function timeLimitPrompt(limitMs: number): string;
|
|
32
|
+
/**
|
|
33
|
+
* A system prompt with the time-limit paragraph for `limitMs`, replacing any it already holds.
|
|
34
|
+
*
|
|
35
|
+
* A resumed attempt restores the stopped attempt's conversation, system message included, while
|
|
36
|
+
* its limit is narrowed to what was left of the clock. Left alone, the restored prompt would still
|
|
37
|
+
* promise the original fifteen minutes to a run that has one; and with less than the notice floor
|
|
38
|
+
* left, no later notice would correct it.
|
|
39
|
+
*/
|
|
40
|
+
export declare function withTimeLimitPrompt(system: string, limitMs: number | undefined): string;
|
|
41
|
+
export interface TimeLimitNotice {
|
|
42
|
+
stage: Stage['id'];
|
|
43
|
+
text: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The notices for one attempt. `next` is asked before each model request with the time still
|
|
47
|
+
* left; it answers at most once per stage, and when several stages passed during one long step it
|
|
48
|
+
* answers only for the most urgent, since the earlier ones describe a moment that is gone.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createTimeLimitNotices(limitMs: number): {
|
|
51
|
+
next(remainingMs: number | undefined): TimeLimitNotice | undefined;
|
|
52
|
+
};
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a model working under a wall-clock limit is told about it.
|
|
3
|
+
*
|
|
4
|
+
* The runtime has always enforced `limits.wallTimeMs`: when the clock runs out the attempt is
|
|
5
|
+
* stopped where it stands. The model was never told there was a clock. In a benchmark run with a
|
|
6
|
+
* fifteen-minute limit the agent spent the whole allowance at full reasoning effort on one build,
|
|
7
|
+
* was stopped with nothing usable on disk, and never knew the end was near; the trials that
|
|
8
|
+
* survived a stop did so only because their output happened to be written already.
|
|
9
|
+
*
|
|
10
|
+
* So a bounded attempt is told three things: that there is a limit and what it means for how to
|
|
11
|
+
* work (once, in the system prompt, where it never changes and so never disturbs the cached
|
|
12
|
+
* prefix), and how much time is left as it runs down (a short runtime message when half, a quarter
|
|
13
|
+
* and a tenth remain, appended at the tail of the conversation). An unbounded attempt, which is the
|
|
14
|
+
* default, is told nothing.
|
|
15
|
+
* @module time-limit
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Below this a limit is too short for a notice to be acted on; the prompt line still applies.
|
|
19
|
+
* A node inside a graph is handed what is left of the graph's limit, a few milliseconds under the
|
|
20
|
+
* configured figure, so a configured two minutes must sit clear of this floor.
|
|
21
|
+
*/
|
|
22
|
+
export const TIME_NOTICE_MIN_LIMIT_MS = 90_000;
|
|
23
|
+
/** Most urgent last, so the stage that applies is the last one whose share has been reached. */
|
|
24
|
+
const STAGES = [
|
|
25
|
+
{ id: 'half', remaining: 0.5, text: left => `Runtime: half of this run's time limit is used; ${left} remain. Check that every output the task requires already exists in a usable form, write any that does not, then keep going.` },
|
|
26
|
+
{ id: 'quarter', remaining: 0.25, text: left => `Runtime: ${left} remain of this run's time limit. Put the best version you have of every required output on disk now, then keep working on what is still missing or failing. Do not finish early: time left unused is worth nothing, and a task reported as unfinished is not accepted while time remains.` },
|
|
27
|
+
{ id: 'tenth', remaining: 0.1, text: left => `Runtime: ${left} remain and the run is stopped when the time is up. Keep the required outputs on disk in their best state at every moment from here on, and spend what is left on small, quick fixes to what is still failing. Finish only if the task is done.` },
|
|
28
|
+
];
|
|
29
|
+
/** "about 7 minutes" or "about 40 seconds": the model plans in round figures, not milliseconds. */
|
|
30
|
+
export function formatTimeLeft(ms) {
|
|
31
|
+
const seconds = Math.max(0, Math.round(ms / 1000));
|
|
32
|
+
if (seconds < 90)
|
|
33
|
+
return `about ${Math.max(5, Math.round(seconds / 5) * 5)} seconds`;
|
|
34
|
+
const minutes = Math.round(seconds / 60);
|
|
35
|
+
if (minutes < 90)
|
|
36
|
+
return `about ${minutes} minutes`;
|
|
37
|
+
const hours = Math.round(minutes / 6) / 10;
|
|
38
|
+
return `about ${hours} hours`;
|
|
39
|
+
}
|
|
40
|
+
/** The system-prompt paragraph for an attempt that has `limitMs` of wall-clock time. */
|
|
41
|
+
export function timeLimitPrompt(limitMs) {
|
|
42
|
+
return `This run has a wall-clock limit of ${formatTimeLeft(limitMs)}. When the time is up the run is stopped where it stands and only what is already on disk counts, so write a working version of every required output early and improve it afterwards rather than saving it for the end. Size commands, installs and your own deliberation to the time available. Use all of it: do not end the run early with the task unfinished. The runtime tells you when half, a quarter and a tenth of the time remain.`;
|
|
43
|
+
}
|
|
44
|
+
const PROMPT_LINE = /\nThis run has a wall-clock limit of [^\n]*/g;
|
|
45
|
+
/**
|
|
46
|
+
* A system prompt with the time-limit paragraph for `limitMs`, replacing any it already holds.
|
|
47
|
+
*
|
|
48
|
+
* A resumed attempt restores the stopped attempt's conversation, system message included, while
|
|
49
|
+
* its limit is narrowed to what was left of the clock. Left alone, the restored prompt would still
|
|
50
|
+
* promise the original fifteen minutes to a run that has one; and with less than the notice floor
|
|
51
|
+
* left, no later notice would correct it.
|
|
52
|
+
*/
|
|
53
|
+
export function withTimeLimitPrompt(system, limitMs) {
|
|
54
|
+
const stripped = system.replace(PROMPT_LINE, '');
|
|
55
|
+
return limitMs ? `${stripped}\n${timeLimitPrompt(limitMs)}` : stripped;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The notices for one attempt. `next` is asked before each model request with the time still
|
|
59
|
+
* left; it answers at most once per stage, and when several stages passed during one long step it
|
|
60
|
+
* answers only for the most urgent, since the earlier ones describe a moment that is gone.
|
|
61
|
+
*/
|
|
62
|
+
export function createTimeLimitNotices(limitMs) {
|
|
63
|
+
let announced = -1;
|
|
64
|
+
return {
|
|
65
|
+
next(remainingMs) {
|
|
66
|
+
if (remainingMs === undefined || limitMs < TIME_NOTICE_MIN_LIMIT_MS)
|
|
67
|
+
return undefined;
|
|
68
|
+
let reached = -1;
|
|
69
|
+
for (const [index, stage] of STAGES.entries())
|
|
70
|
+
if (remainingMs <= limitMs * stage.remaining)
|
|
71
|
+
reached = index;
|
|
72
|
+
if (reached <= announced)
|
|
73
|
+
return undefined;
|
|
74
|
+
announced = reached;
|
|
75
|
+
const stage = STAGES[reached];
|
|
76
|
+
return { stage: stage.id, text: stage.text(formatTimeLeft(remainingMs)) };
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -66,7 +66,7 @@ export function activityForRuntimeEvent(event, activity) {
|
|
|
66
66
|
if (event.type === 'node.tool.completed' || event.type === 'node.tool.failed')
|
|
67
67
|
return activity.finish(event.data);
|
|
68
68
|
if (event.type === 'agent.model.retry')
|
|
69
|
-
return activity.retry(event.data);
|
|
69
|
+
return event.data.quiet === true ? undefined : activity.retry(event.data);
|
|
70
70
|
// Session completion also covers exhausted retries, failed requests and cancellation.
|
|
71
71
|
if (event.type === 'agent.model.completed' || event.type === 'agent.session.completed')
|
|
72
72
|
return activity.finishModel(event.data);
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Returns true when the full validator authoritatively checked an extended contract.
|
|
3
|
+
*
|
|
4
|
+
* The compiler is several hundred modules and only schemas with extended keywords need it, so it
|
|
5
|
+
* is loaded the first time one does rather than with every process that can run a tool.
|
|
6
|
+
*/
|
|
7
|
+
export declare function validateExtendedToolSchema(schema: Record<string, unknown>, input: unknown): Promise<boolean>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Compile } from 'typebox/compile';
|
|
2
1
|
const nativeKeywords = new Set(['type', 'const', 'enum', 'properties', 'required', 'additionalProperties', 'items', 'oneOf', 'minimum', 'maximum', 'minItems', 'maxItems', 'minLength', 'maxLength', 'title', 'description', 'default', 'examples', '$schema', '$id']);
|
|
3
2
|
function needsExtendedValidation(schema) {
|
|
4
3
|
if (!schema || typeof schema !== 'object')
|
|
@@ -25,13 +24,18 @@ function needsExtendedValidation(schema) {
|
|
|
25
24
|
|| (Array.isArray(node.oneOf) && node.oneOf.some(needsExtendedValidation));
|
|
26
25
|
}
|
|
27
26
|
const validators = new WeakMap();
|
|
28
|
-
/**
|
|
29
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Returns true when the full validator authoritatively checked an extended contract.
|
|
29
|
+
*
|
|
30
|
+
* The compiler is several hundred modules and only schemas with extended keywords need it, so it
|
|
31
|
+
* is loaded the first time one does rather than with every process that can run a tool.
|
|
32
|
+
*/
|
|
33
|
+
export async function validateExtendedToolSchema(schema, input) {
|
|
30
34
|
if (!needsExtendedValidation(schema))
|
|
31
35
|
return false;
|
|
32
36
|
let validator = validators.get(schema);
|
|
33
37
|
if (!validator) {
|
|
34
|
-
validator = Compile(schema);
|
|
38
|
+
validator = (await import('typebox/compile')).Compile(schema);
|
|
35
39
|
validators.set(schema, validator);
|
|
36
40
|
}
|
|
37
41
|
if (!validator.Check(input)) {
|
package/dist/src/tools.js
CHANGED
|
@@ -14,6 +14,8 @@ import { andorraCreateWriteTool } from '../vendor/engine/runtime/coding-agent/co
|
|
|
14
14
|
import { andorraWithFileMutationQueue } from '../vendor/engine/runtime/coding-agent/core/tools/file-mutation-queue.js';
|
|
15
15
|
import { andorraDetectSupportedImageMimeType } from '../vendor/engine/runtime/coding-agent/utils/mime.js';
|
|
16
16
|
import { READ_IMAGE_FILE_LIMIT } from './read-image.js';
|
|
17
|
+
import { decodeLegacyText, sniffDocument } from './read-document.js';
|
|
18
|
+
import { READ_DOCUMENT_FILE_LIMIT } from './read-document-tool.js';
|
|
17
19
|
import { clipText } from './text.js';
|
|
18
20
|
import { pullRequestSettings } from './pull-requests.js';
|
|
19
21
|
import { approveOperation } from './capabilities.js';
|
|
@@ -244,6 +246,56 @@ async function readImage(context, name) {
|
|
|
244
246
|
await handle.close();
|
|
245
247
|
}
|
|
246
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* The whole of a regular file whose leading bytes `accept` recognizes, or undefined when they are
|
|
251
|
+
* not recognized or the path is not a regular file. Same guards as the text and image readers:
|
|
252
|
+
* the path policy, a non-blocking open, the size bound checked on the open handle, and one byte
|
|
253
|
+
* past the bound read so a file that grows mid-read is refused rather than truncated.
|
|
254
|
+
*/
|
|
255
|
+
async function readRecognized(context, name, limit, what, accept) {
|
|
256
|
+
const resolved = await safePath(context, name);
|
|
257
|
+
if (!(await stat(resolved)).isFile())
|
|
258
|
+
return undefined;
|
|
259
|
+
context.signal.throwIfAborted();
|
|
260
|
+
const handle = await open(resolved, constants.O_RDONLY | (process.platform === 'win32' ? 0 : constants.O_NONBLOCK));
|
|
261
|
+
try {
|
|
262
|
+
const info = await handle.stat();
|
|
263
|
+
if (!info.isFile())
|
|
264
|
+
return undefined;
|
|
265
|
+
const head = Buffer.alloc(4100);
|
|
266
|
+
const sniffed = await handle.read(head, 0, head.length, 0);
|
|
267
|
+
if (!accept(head.subarray(0, sniffed.bytesRead)))
|
|
268
|
+
return undefined;
|
|
269
|
+
if (info.size > limit)
|
|
270
|
+
throw new Error(`${what} exceeds the ${limit / (1024 * 1024)} MiB read limit`);
|
|
271
|
+
const chunks = [];
|
|
272
|
+
let size = 0;
|
|
273
|
+
while (size <= limit) {
|
|
274
|
+
context.signal.throwIfAborted();
|
|
275
|
+
const chunk = Buffer.alloc(Math.min(256 * 1024, limit + 1 - size));
|
|
276
|
+
const result = await handle.read(chunk, 0, chunk.length, size);
|
|
277
|
+
if (!result.bytesRead)
|
|
278
|
+
break;
|
|
279
|
+
size += result.bytesRead;
|
|
280
|
+
chunks.push(chunk.subarray(0, result.bytesRead));
|
|
281
|
+
}
|
|
282
|
+
if (size > limit)
|
|
283
|
+
throw new Error(`${what} grew beyond the read limit`);
|
|
284
|
+
return Buffer.concat(chunks, size);
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
await handle.close();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/** The bytes of a file that opens like a PDF, a zip (docx) or a compound file (doc); undefined otherwise. */
|
|
291
|
+
function readDocument(context, name) {
|
|
292
|
+
return readRecognized(context, name, READ_DOCUMENT_FILE_LIMIT, 'File', head => sniffDocument(head) !== undefined);
|
|
293
|
+
}
|
|
294
|
+
/** A text file in an older encoding, decoded; undefined when the bytes do not look like text. */
|
|
295
|
+
async function readLegacyText(context, name) {
|
|
296
|
+
const bytes = await readRecognized(context, name, FILE_LIMIT, 'File', () => true);
|
|
297
|
+
return bytes ? decodeLegacyText(bytes) : undefined;
|
|
298
|
+
}
|
|
247
299
|
function assertMutationPermission(context) {
|
|
248
300
|
if (!context.pinFilePaths && !context.fileMutationApproval?.explicit && (permissionMode(context) === 'read-only' || permissionMode(context) === 'plan'))
|
|
249
301
|
throw new Error('Permission denied: file mutation grant was revoked');
|
|
@@ -285,7 +337,12 @@ async function atomicWrite(context, name, content, expectedContent) {
|
|
|
285
337
|
context.signal.throwIfAborted();
|
|
286
338
|
await mutationPermission(context, name);
|
|
287
339
|
assertMutationPermission(context);
|
|
288
|
-
|
|
340
|
+
// A replacement starts private and takes the old file's mode below, so its content is never
|
|
341
|
+
// briefly more readable than the file it replaces. A new file has no mode to inherit: it is
|
|
342
|
+
// created like any other program creates one (0666 narrowed by the process umask), not 0600,
|
|
343
|
+
// which left files the agent wrote unreadable to a web server, a test runner or any other
|
|
344
|
+
// account that was meant to use them.
|
|
345
|
+
const handle = await open(temporary, 'wx', existing ? 0o600 : 0o666);
|
|
289
346
|
created = true;
|
|
290
347
|
try {
|
|
291
348
|
await mutationPermission(context, name);
|
|
@@ -637,6 +694,21 @@ function qaPermissionTool(tool) {
|
|
|
637
694
|
return tool.execute(args, context);
|
|
638
695
|
} };
|
|
639
696
|
}
|
|
697
|
+
const AWAIT_REVIEW_DEFAULT_MINUTES = 360;
|
|
698
|
+
/** What a review wait tells the agent to do next. */
|
|
699
|
+
function reviewWaitAnswer(ended, minutes, signal) {
|
|
700
|
+
switch (ended.kind) {
|
|
701
|
+
case 'comments': return `${ended.prompt}
|
|
702
|
+
|
|
703
|
+
When this round is pushed and its threads are answered, call pull_request with action await_review again to wait for the next review.`;
|
|
704
|
+
case 'finished': return `${ended.pullRequest.url} is ${ended.pullRequest.state}, so Auto-fix is off and there is no review left to wait for. Finish your work and report.`;
|
|
705
|
+
case 'off': return `Auto-fix is off for ${ended.pullRequest.url}, so no review will be waited for. Finish your work and report; switch Auto-fix on only if the user asks.`;
|
|
706
|
+
case 'none': return 'No pull request is tracked for this session, so there is no review to wait for.';
|
|
707
|
+
case 'timeout': return `No new review arrived in ${minutes} minute${minutes === 1 ? '' : 's'}. Call await_review again to keep waiting, or finish and report.`;
|
|
708
|
+
case 'steered': return 'The user sent you a message while you were waiting for a review. Read and answer it; call await_review again afterwards if the review loop should continue.';
|
|
709
|
+
case 'aborted': throw signal.reason instanceof Error ? signal.reason : new Error('The run was stopped while it waited for a review.');
|
|
710
|
+
}
|
|
711
|
+
}
|
|
640
712
|
export function createTools() {
|
|
641
713
|
return [
|
|
642
714
|
createAutomationTool(),
|
|
@@ -778,12 +850,13 @@ export function createTools() {
|
|
|
778
850
|
context.wakesArmed?.push(timer.id);
|
|
779
851
|
return `Timer ${timer.id.slice(0, 8)} armed: your prompt will be delivered in ${args.seconds} second${args.seconds === 1 ? '' : 's'}, at ${new Date(timer.fireAt).toISOString()}. It fires once.`;
|
|
780
852
|
}),
|
|
781
|
-
{ ...tool('pull_request', 'Show or change the pull request this session tracks in the desktop Plan card. A PR you open with `gh pr create` is attached automatically; use attach for one opened another way. update changes its settings when the user asks: mergeWhenReady enables GitHub auto-merge (gh pr merge --auto), draft converts to a draft or marks it ready, autoFix wakes you with a prompt when a code-review bot (Codex, CodeRabbit, Greptile, Copilot) comments and switches itself off once the PR is merged or closed. dismiss removes it from the card. Only change a setting the user asked you to change.', {
|
|
782
|
-
action: { type: 'string', enum: ['status', 'attach', 'update', 'dismiss'], description: 'status shows the tracked PR; attach starts tracking url; update changes settings; dismiss stops tracking' },
|
|
853
|
+
{ ...tool('pull_request', 'Show or change the pull request this session tracks in the desktop Plan card. A PR you open with `gh pr create` is attached automatically; use attach for one opened another way. update changes its settings when the user asks: mergeWhenReady enables GitHub auto-merge (gh pr merge --auto), draft converts to a draft or marks it ready, autoFix wakes you with a prompt when a code-review bot (Codex, CodeRabbit, Greptile, Copilot) comments and switches itself off once the PR is merged or closed. await_review keeps you in this run while Auto-fix is on: it waits, without using the model, until new review comments arrive (and returns them), the PR is merged or closed, the user messages you, or timeoutMinutes pass. Use it to own the review loop: fix a round, push, resolve the threads you fixed, then call await_review again, until the PR is merged or closed. Never wait for a review with sleep, a shell loop or set_timer. dismiss removes it from the card. Only change a setting the user asked you to change.', {
|
|
854
|
+
action: { type: 'string', enum: ['status', 'attach', 'update', 'await_review', 'dismiss'], description: 'status shows the tracked PR; attach starts tracking url; update changes settings; await_review waits for the next review round; dismiss stops tracking' },
|
|
783
855
|
url: property('The GitHub pull request URL (attach only)'),
|
|
784
856
|
autoFix: { type: 'boolean', description: 'Wake this session when a code-review bot (Codex, CodeRabbit, Greptile, Copilot) comments, until the PR is merged or closed' },
|
|
785
857
|
mergeWhenReady: { type: 'boolean', description: 'GitHub auto-merge once checks and reviews pass' },
|
|
786
858
|
draft: { type: 'boolean', description: 'true converts to a draft, false marks it ready for review' },
|
|
859
|
+
timeoutMinutes: { type: 'integer', minimum: 1, maximum: 1440, description: `How long await_review waits for a review before returning (1 to 1440, default ${AWAIT_REVIEW_DEFAULT_MINUTES})` },
|
|
787
860
|
}, ['action'], async (args, context) => {
|
|
788
861
|
const control = context.pullRequests;
|
|
789
862
|
if (!control)
|
|
@@ -803,21 +876,33 @@ export function createTools() {
|
|
|
803
876
|
const url = string(args, 'url');
|
|
804
877
|
if (Object.keys(settings).length)
|
|
805
878
|
await approve();
|
|
806
|
-
return `Tracking ${describe(await control.attach(url, settings))}`;
|
|
879
|
+
return `Tracking ${describe(await control.attach(url, settings, context.wakeOrigin))}`;
|
|
807
880
|
}
|
|
808
881
|
case 'update': {
|
|
809
882
|
if (!Object.keys(settings).length)
|
|
810
883
|
throw new Error('update needs at least one of autoFix, mergeWhenReady, draft');
|
|
811
884
|
await approve();
|
|
812
|
-
return `Updated ${describe(await control.update(settings))}`;
|
|
885
|
+
return `Updated ${describe(await control.update(settings, context.wakeOrigin))}`;
|
|
886
|
+
}
|
|
887
|
+
case 'await_review': {
|
|
888
|
+
if (!control.awaitReview)
|
|
889
|
+
throw new Error('await_review is unavailable here; this surface cannot hold a run open for a review. End your turn: Auto-fix wakes you when comments arrive.');
|
|
890
|
+
const minutes = args.timeoutMinutes === undefined ? AWAIT_REVIEW_DEFAULT_MINUTES : args.timeoutMinutes;
|
|
891
|
+
if (typeof minutes !== 'number' || !Number.isSafeInteger(minutes) || minutes < 1 || minutes > 1_440)
|
|
892
|
+
throw new Error('timeoutMinutes must be an integer from 1 to 1440');
|
|
893
|
+
const awaitReview = control.awaitReview.bind(control);
|
|
894
|
+
const wait = () => awaitReview(context.signal, minutes * 60_000, context.wakeOrigin);
|
|
895
|
+
// Waiting on a reviewer is not the run's work: its time limits are paused for as long as this waits.
|
|
896
|
+
const ended = await (context.waitOutside ? context.waitOutside(wait) : wait());
|
|
897
|
+
return reviewWaitAnswer(ended, minutes, context.signal);
|
|
813
898
|
}
|
|
814
899
|
case 'dismiss':
|
|
815
900
|
await control.dismiss();
|
|
816
901
|
return 'The pull request is no longer tracked for this session.';
|
|
817
|
-
default: throw new Error('action must be status, attach, update, or dismiss');
|
|
902
|
+
default: throw new Error('action must be status, attach, update, await_review, or dismiss');
|
|
818
903
|
}
|
|
819
904
|
}), family: 'git', executionMode: 'sequential' },
|
|
820
|
-
...createCodingTools({ safePath, read, readImage, atomicWrite, authorize, files, fileLimit: FILE_LIMIT }),
|
|
905
|
+
...createCodingTools({ safePath, read, readImage, readDocument, readLegacyText, atomicWrite, authorize, files, fileLimit: FILE_LIMIT }),
|
|
821
906
|
...createQaTools().map(qaPermissionTool),
|
|
822
907
|
createBrowserSessionTool(authorize),
|
|
823
908
|
createSolveCaptchaTool(authorize),
|
package/dist/src/transcript.d.ts
CHANGED
|
@@ -10,10 +10,15 @@ import { type ToolCallStamp } from './tool-call-clock.js';
|
|
|
10
10
|
export declare function formatDurationSuffix(data: Record<string, unknown>): string;
|
|
11
11
|
/** Describe the action without dumping file contents or graph handoff payloads. */
|
|
12
12
|
export declare function describeTool(name: string, value: unknown): string;
|
|
13
|
+
/**
|
|
14
|
+
* `clipRows` asks a width-aware view to cut each collapsed row to one screen line instead of
|
|
15
|
+
* wrapping it; the full rows stay in `detail`, which the view shows when expanded.
|
|
16
|
+
*/
|
|
13
17
|
export interface TranscriptEntry {
|
|
14
18
|
text: string;
|
|
15
19
|
detail?: string;
|
|
16
20
|
toolCall?: ToolCallStamp;
|
|
21
|
+
clipRows?: boolean;
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
19
24
|
* Colors are selected from trusted presentation markers, never provider ANSI.
|
package/dist/src/transcript.js
CHANGED
|
@@ -60,6 +60,9 @@ export function describeTool(name, value) {
|
|
|
60
60
|
case 'git_read':
|
|
61
61
|
case 'git_write': return `Git ${line(args.operation)}`;
|
|
62
62
|
case 'memory_search': return `Search memory for "${line(args.query)}"`;
|
|
63
|
+
case 'memory_read': return `Read memory ${line(args.name)}`;
|
|
64
|
+
case 'memory_write': return `Save memory ${line(args.name)}`;
|
|
65
|
+
case 'memory_delete': return `Delete memory ${line(args.name)}`;
|
|
63
66
|
case 'repo_explore': return `Explore repository for "${line(args.query)}"`;
|
|
64
67
|
default: return `${line(name)}${args.path ? ` ${line(args.path)}` : ''}`;
|
|
65
68
|
}
|
|
@@ -128,6 +131,7 @@ export function formatRunResult(result) {
|
|
|
128
131
|
const assemble = (body) => [...(body ? [body] : []), ...trailer].join('\n').replace(/^\n+/, '');
|
|
129
132
|
return { text: assemble(rendered.text), ...(rendered.detail ? { detail: assemble(rendered.detail) } : {}) };
|
|
130
133
|
}
|
|
134
|
+
const TOOL_RESULT_PREVIEW_ROWS = 3;
|
|
131
135
|
export function formatEvent(event) {
|
|
132
136
|
const data = event.data;
|
|
133
137
|
if (data.provider === 'andorra' || data.provider === 'jev') {
|
|
@@ -157,10 +161,12 @@ export function formatEvent(event) {
|
|
|
157
161
|
return { text: 'Summarizing earlier work to free context.' };
|
|
158
162
|
if (event.type === 'agent.context.compaction.retry')
|
|
159
163
|
return { text: `Context summary incomplete (${line(data.reason)}); retrying ${line(data.nextAttempt)}/3.` };
|
|
164
|
+
if (event.type === 'agent.model.retry' && data.quiet === true)
|
|
165
|
+
return undefined;
|
|
160
166
|
if (event.type === 'agent.model.retry')
|
|
161
167
|
return { text: `\u2022 ${actor}Provider request retry ${line(data.retry)}/${line(data.maxRetries)} in ${formatRetryDelay(data.delayMs)}: ${line(data.reason)}` };
|
|
162
168
|
if (event.type === 'graph.node.started')
|
|
163
|
-
return { text: `
|
|
169
|
+
return { text: `Step: ${line(data.nodeName ?? data.nodeId)}${Number(data.visit) > 1 ? ` (visit ${line(data.visit)})` : ''}` };
|
|
164
170
|
if (event.type === 'agent.modifier.iteration.started' && Number(data.maxIterations) > 1)
|
|
165
171
|
return { text: `${line(data.nodeName ?? data.nodeId)} - loop ${line(data.iteration)}/${line(data.maxIterations)}` };
|
|
166
172
|
if (event.type === 'agent.modifier.copy.started' && Number(data.copies) > 1)
|
|
@@ -197,8 +203,10 @@ export function formatEvent(event) {
|
|
|
197
203
|
}
|
|
198
204
|
const output = clean(data.output).trimEnd();
|
|
199
205
|
const rows = output.split('\n');
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
// Three rows, each held to one screen line by the TUI (clipRows), keep a tool result to a
|
|
207
|
+
// glance; Ctrl+O shows the rest.
|
|
208
|
+
const preview = rows.slice(0, TOOL_RESULT_PREVIEW_ROWS).map(row => clipText(row, 180));
|
|
209
|
+
const shortened = rows.length > TOOL_RESULT_PREVIEW_ROWS || preview.some((row, index) => row !== rows[index]);
|
|
202
210
|
const failed = event.type === 'node.tool.failed';
|
|
203
211
|
const heading = `${actor}${failed ? `${line(data.name)} failed: ` : ''}`;
|
|
204
212
|
// The duration trails the output the way a shell reports completion: `… in 123ms`. A missing
|
|
@@ -207,7 +215,7 @@ export function formatEvent(event) {
|
|
|
207
215
|
const suffix = formatDurationSuffix(data) ?? '';
|
|
208
216
|
const indent = (text) => text.split('\n').map((row, index) => `${index ? ' ' : ' └ '}${index ? '' : heading}${row}`).join('\n');
|
|
209
217
|
return { text: indent(preview.join('\n') || '(no output)') + (shortened ? `\n … ${rows.length} lines total` : '') + suffix,
|
|
210
|
-
...(shortened ? { detail: indent(output) + suffix } : {}) };
|
|
218
|
+
...(shortened ? { detail: indent(output) + suffix, clipRows: true } : {}) };
|
|
211
219
|
}
|
|
212
220
|
if (event.type === 'agent.turn.continued')
|
|
213
221
|
return { text: data.toolCallDropped === true
|
package/dist/src/types.d.ts
CHANGED
|
@@ -76,11 +76,13 @@ export interface ModelRequestContext {
|
|
|
76
76
|
subagentId?: string;
|
|
77
77
|
invocationId?: string;
|
|
78
78
|
}
|
|
79
|
+
/** `quiet` retries are recorded in the event stream and trajectory but shown nowhere. */
|
|
79
80
|
export interface ModelRetry {
|
|
80
81
|
retry: number;
|
|
81
82
|
maxRetries: number;
|
|
82
83
|
delayMs: number;
|
|
83
84
|
reason: string;
|
|
85
|
+
quiet?: boolean;
|
|
84
86
|
}
|
|
85
87
|
export interface GenerateRequest {
|
|
86
88
|
model: string;
|
|
@@ -211,6 +213,12 @@ export interface ToolContext {
|
|
|
211
213
|
* surfaces with no live permission control, where presenting a plan cannot proceed.
|
|
212
214
|
*/
|
|
213
215
|
approvePlan?: () => Promise<import('./permissions.js').PermissionMode>;
|
|
216
|
+
/**
|
|
217
|
+
* Run `work` as a wait on something outside the run (a reviewer on GitHub, say), with every enclosing wall-time
|
|
218
|
+
* budget suspended for its duration, the way a question to the user is. Set by `bindUserWaits`; a surface with no
|
|
219
|
+
* budget leaves it unset and the caller runs the work directly.
|
|
220
|
+
*/
|
|
221
|
+
waitOutside?: <T>(work: () => Promise<T>) => Promise<T>;
|
|
214
222
|
onApprovalEvent?: (type: string, data: Record<string, unknown>) => void | Promise<void>;
|
|
215
223
|
/** Browser lifecycle observations, scoped to the current coding session, never a tool-supplied identity. */
|
|
216
224
|
onBrowserEvent?: (type: string, data: Record<string, unknown>) => void | Promise<void>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// The Orchestrator reads and delegates; it has no write or shell tools. A stray file in the working
|
|
2
|
+
// folder (a shell accident such as a file named nul, or one named after a pasted sentence) is still
|
|
3
|
+
// something it must be able to clear without starting a subagent, because such a file can be what
|
|
4
|
+
// stops a subagent from starting. This tool removes exactly one untracked regular file and nothing
|
|
5
|
+
// else: no directories, no links, no tracked files, nothing outside the workspace's own repository.
|
|
6
|
+
import { execFile } from 'node:child_process';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import { lstat, realpath, rm } from 'node:fs/promises';
|
|
9
|
+
import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
10
|
+
import { approveOperation } from './capabilities.js';
|
|
11
|
+
import { assertLocalFilePath, assertPlanMutationAllowed } from './permissions.js';
|
|
12
|
+
const exec = promisify(execFile);
|
|
13
|
+
export const REMOVE_UNTRACKED_FILE = 'remove_untracked_file';
|
|
14
|
+
const inside = (root, target) => {
|
|
15
|
+
const path = relative(root, target);
|
|
16
|
+
return path !== '' && path !== '..' && !path.startsWith(`..${sep}`) && !isAbsolute(path);
|
|
17
|
+
};
|
|
18
|
+
function git(cwd, args, signal) {
|
|
19
|
+
return exec('git', ['-c', 'core.hooksPath=', '-c', 'core.fsmonitor=false', '-c', 'core.longpaths=true', ...args], { cwd, signal, windowsHide: true, timeout: 15_000 });
|
|
20
|
+
}
|
|
21
|
+
async function toplevel(cwd, signal) {
|
|
22
|
+
try {
|
|
23
|
+
return await realpath((await git(cwd, ['rev-parse', '--show-toplevel'], signal)).stdout.trim());
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (signal.aborted)
|
|
27
|
+
throw error;
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolves the requested path to the file it names on disk and checks everything that does not
|
|
33
|
+
* need the user: inside the workspace, a regular file, in the workspace's own repository, not
|
|
34
|
+
* tracked there under any spelling. Called again after the prompt, so a folder swapped for a link
|
|
35
|
+
* or a file that became tracked while the prompt was open is refused instead of removed.
|
|
36
|
+
*/
|
|
37
|
+
async function check(workspace, requested, signal) {
|
|
38
|
+
const root = await realpath(workspace);
|
|
39
|
+
const target = join(root, requested);
|
|
40
|
+
if (!inside(root, target))
|
|
41
|
+
throw new Error('The path must name a file inside the workspace.');
|
|
42
|
+
const missing = () => new Error(`No such file: ${requested}`);
|
|
43
|
+
// The folder is resolved, so a link anywhere above the file cannot carry the removal elsewhere.
|
|
44
|
+
const folder = await realpath(dirname(target)).catch(() => { throw missing(); });
|
|
45
|
+
if (folder !== root && !inside(root, folder))
|
|
46
|
+
throw new Error('The path must name a file inside the workspace.');
|
|
47
|
+
const linkPath = join(folder, target.slice(dirname(target).length + 1));
|
|
48
|
+
const info = await lstat(linkPath).catch(() => { throw missing(); });
|
|
49
|
+
if (info.isDirectory())
|
|
50
|
+
throw new Error('Only a single file can be removed, not a directory.');
|
|
51
|
+
if (!info.isFile())
|
|
52
|
+
throw new Error('Only a regular file can be removed, not a link or a special file.');
|
|
53
|
+
// The file's own spelling on disk: a case-insensitive file system answers to readme.md for README.md.
|
|
54
|
+
const path = await realpath(linkPath).catch(() => { throw missing(); });
|
|
55
|
+
if (!inside(root, path))
|
|
56
|
+
throw new Error('The path must name a file inside the workspace.');
|
|
57
|
+
const relativePath = relative(root, path).split(sep).join('/');
|
|
58
|
+
if (relativePath.split('/').some(part => part.toLowerCase() === '.git'))
|
|
59
|
+
throw new Error('Files inside .git cannot be removed.');
|
|
60
|
+
const repository = await toplevel(root, signal);
|
|
61
|
+
if (!repository)
|
|
62
|
+
throw new Error('Only an untracked file in a Git repository can be removed, and the workspace is not one.');
|
|
63
|
+
// The repository that owns the file must be the workspace's: a nested repository or a submodule
|
|
64
|
+
// has its own index, and a file it tracks is not untracked just because the outer one ignores it.
|
|
65
|
+
if (await toplevel(dirname(path), signal) !== repository)
|
|
66
|
+
throw new Error(`${relativePath} belongs to a nested repository or submodule; only an untracked file of the workspace's own repository can be removed.`);
|
|
67
|
+
// Matched without regard to case: on a case-insensitive file system any spelling is the same file.
|
|
68
|
+
try {
|
|
69
|
+
await git(repository, ['ls-files', '--error-unmatch', '--', `:(literal,icase)${relative(repository, path).split(sep).join('/')}`], signal);
|
|
70
|
+
throw new Error(`${relativePath} is tracked by Git; only an untracked file can be removed. Changes to tracked files go through a subagent.`);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (signal.aborted)
|
|
74
|
+
throw error;
|
|
75
|
+
if (error.code !== 1)
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
return { root, path, relativePath, info };
|
|
79
|
+
}
|
|
80
|
+
export function removeUntrackedFileTool() {
|
|
81
|
+
return {
|
|
82
|
+
name: REMOVE_UNTRACKED_FILE,
|
|
83
|
+
executionMode: 'sequential',
|
|
84
|
+
description: 'Remove one untracked file from the workspace, such as a stray file a shell command left behind by mistake (a file named nul, or one named after a sentence). Refuses directories, links, files Git tracks, files of a nested repository, and anything outside the workspace. Asks the user first unless the session is in Full Access. Use it only for a file that is plainly an accident or that the user asked you to remove; any other change goes through a subagent.',
|
|
85
|
+
parameters: { type: 'object', properties: {
|
|
86
|
+
path: { type: 'string', minLength: 1, maxLength: 4096, description: 'The file\'s path relative to the workspace, exactly as listed by Glob or git_read.' },
|
|
87
|
+
}, required: ['path'], additionalProperties: false },
|
|
88
|
+
execute: async (args, ctx) => {
|
|
89
|
+
ctx.signal.throwIfAborted();
|
|
90
|
+
if (Object.keys(args).some(key => key !== 'path') || typeof args.path !== 'string' || !args.path || args.path.includes('\0')) {
|
|
91
|
+
throw new Error(`${REMOVE_UNTRACKED_FILE} takes only the path of one file`);
|
|
92
|
+
}
|
|
93
|
+
const requested = args.path;
|
|
94
|
+
assertLocalFilePath(requested);
|
|
95
|
+
if (isAbsolute(requested))
|
|
96
|
+
throw new Error('Give the path relative to the workspace.');
|
|
97
|
+
assertPlanMutationAllowed(ctx);
|
|
98
|
+
const checked = await check(ctx.workspace, requested, ctx.signal);
|
|
99
|
+
// Full Access approves this on its own; every other mode asks the user.
|
|
100
|
+
await approveOperation(ctx, REMOVE_UNTRACKED_FILE, { path: checked.relativePath, bytes: checked.info.size });
|
|
101
|
+
ctx.signal.throwIfAborted();
|
|
102
|
+
// The review record keeps what the file held, so the user can undo the removal.
|
|
103
|
+
const recording = ctx.fileChanges ? await ctx.fileChanges.beforeWrite(checked.path).catch(() => undefined) : undefined;
|
|
104
|
+
const locked = recording ? await recording.begin().then(() => true, () => false) : false;
|
|
105
|
+
try {
|
|
106
|
+
assertPlanMutationAllowed(ctx);
|
|
107
|
+
// The prompt and the recorder can both wait. What was approved is removed only if it is
|
|
108
|
+
// still the same file at the same place: same resolved path, same file on disk, untracked.
|
|
109
|
+
const now = await check(ctx.workspace, requested, ctx.signal);
|
|
110
|
+
if (now.path !== checked.path || now.info.ino !== checked.info.ino || now.info.dev !== checked.info.dev) {
|
|
111
|
+
throw new Error(`${checked.relativePath} changed while the removal was waiting; nothing was removed.`);
|
|
112
|
+
}
|
|
113
|
+
await rm(now.path, { force: false, maxRetries: 3, retryDelay: 100 });
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (locked)
|
|
117
|
+
await recording.abort().catch(() => { });
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
if (locked)
|
|
121
|
+
await recording.commit().catch(() => { });
|
|
122
|
+
return JSON.stringify({ removed: checked.relativePath });
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
package/dist/src/update-check.js
CHANGED
|
@@ -3,7 +3,7 @@ import { dirname, join, resolve } from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import semver from 'semver';
|
|
5
5
|
import { configDirectory } from './config.js';
|
|
6
|
-
import { PACKAGE_NAME } from './
|
|
6
|
+
import { PACKAGE_NAME } from './package-name.js';
|
|
7
7
|
/** The registry document for the release the `latest` dist-tag names. */
|
|
8
8
|
const REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME.replace('/', '%2F')}/latest`;
|
|
9
9
|
/** npm is asked at most this often; launches in between use the cached answer. */
|
package/dist/src/update.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** The package `andorra update` installs. */
|
|
2
|
-
|
|
2
|
+
import { PACKAGE_NAME } from './package-name.js';
|
|
3
|
+
export { PACKAGE_NAME };
|
|
3
4
|
export interface RunOptions {
|
|
4
5
|
/** Show the command's output while it runs instead of only capturing it; npm install uses this. */
|
|
5
6
|
stream?: boolean;
|
|
@@ -31,7 +32,16 @@ export interface UpdateOptions {
|
|
|
31
32
|
lockDirectory?: string;
|
|
32
33
|
/** Injectable only for tests; the CLI runs the npm that ships beside the Node.js running it. */
|
|
33
34
|
npm?: string;
|
|
35
|
+
/** Injectable only for tests; the CLI uses the install prefix of the Node.js running it. */
|
|
36
|
+
nodePrefix?: string;
|
|
34
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The prefix to name to npm when the package is the global install of the Node.js running it, as
|
|
40
|
+
* the native installer lays it out (~/.andorracode/runtime/node). npm would otherwise take its
|
|
41
|
+
* global prefix from the user's .npmrc or NPM_CONFIG_PREFIX, which names a different directory
|
|
42
|
+
* and turns the update into a refusal. For every other layout npm's own answer stands.
|
|
43
|
+
*/
|
|
44
|
+
export declare function ownedNodePrefix(packageRoot: string, nodePrefix: string): Promise<string | undefined>;
|
|
35
45
|
export interface UpdateLockOptions {
|
|
36
46
|
breakLock?: boolean;
|
|
37
47
|
isRunning?: (pid: number) => boolean;
|