@andorra-labs/code 0.1.11 → 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 +8 -2
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/dist/src/agent-execution.js +15 -3
- package/dist/src/agent-mcp.js +5 -0
- package/dist/src/app-server/protocol.d.ts +8 -1
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server.d.ts +15 -0
- package/dist/src/app-server.js +89 -10
- 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-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 +2 -1
- package/dist/src/coding-tools.js +39 -31
- package/dist/src/completion.d.ts +43 -1
- package/dist/src/completion.js +145 -4
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.js +2 -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 +50 -5
- package/dist/src/graph-runner.js +23 -3
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +39 -18
- package/dist/src/graph-ui/app.js +100 -30
- package/dist/src/graph-ui/controls.css +52 -0
- package/dist/src/graph-ui/icons.js +3 -0
- package/dist/src/graph-ui/index.html +2 -2
- package/dist/src/graph-ui/manager-state.js +141 -3
- package/dist/src/graph-ui/manager.css +2 -2
- package/dist/src/graph-ui/manager.js +328 -66
- 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/graphs.d.ts +2 -0
- package/dist/src/graphs.js +7 -7
- package/dist/src/mcp.d.ts +52 -14
- package/dist/src/mcp.js +285 -128
- 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/qa/runtime/PtyManager.js +2 -1
- package/dist/src/react-runtime.js +16 -8
- 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 +2 -0
- package/dist/src/sessions.d.ts +3 -1
- package/dist/src/sessions.js +5 -3
- 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/graph-manager/SKILL.md +22 -4
- package/dist/src/skills/bundled/provenance.json +1 -1
- package/dist/src/skills/runtime-skills.d.ts +6 -0
- package/dist/src/skills/runtime-skills.js +13 -0
- 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 +9 -3
- 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/transcript.d.ts +5 -0
- package/dist/src/transcript.js +11 -3
- package/dist/src/types.d.ts +2 -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/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 +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// A shell command can leave a file behind whose name is plainly a mistake: a whole sentence (a
|
|
2
|
+
// path and its content passed in the wrong order) or a Windows device name (output sent to `nul`
|
|
3
|
+
// from a shell that is not cmd.exe). Nothing stops a process from creating one, so the shell tools
|
|
4
|
+
// look at their working directory before and after a command and tell the model what appeared.
|
|
5
|
+
import { readdir } from 'node:fs/promises';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
/** A directory with more entries than this is not compared: the check must stay cheap. */
|
|
8
|
+
const SCAN_LIMIT = 5_000;
|
|
9
|
+
/** No deliberate file name is this long; a pasted sentence is. */
|
|
10
|
+
const NAME_LIMIT = 150;
|
|
11
|
+
/** Windows' MAX_PATH, which Git and most tools there still enforce. */
|
|
12
|
+
const WINDOWS_PATH_LIMIT = 260;
|
|
13
|
+
const SHOWN_NAME_CHARS = 80;
|
|
14
|
+
const SHOWN_FILES = 3;
|
|
15
|
+
/** Whether Windows reads this file name as a device (`nul`, `con`, `com1`, also with an extension). */
|
|
16
|
+
export function isWindowsDeviceName(name) {
|
|
17
|
+
return /^(con|prn|aux|nul|com[1-9]|lpt[1-9])\s*(\..*)?$/i.test(name);
|
|
18
|
+
}
|
|
19
|
+
/** Why a new file with this name is almost certainly a mistake, or undefined when the name is ordinary. */
|
|
20
|
+
export function strayNameReason(name, directory, platform = process.platform) {
|
|
21
|
+
if (platform === 'win32' && isWindowsDeviceName(name))
|
|
22
|
+
return 'a reserved Windows device name';
|
|
23
|
+
if (name.length >= NAME_LIMIT)
|
|
24
|
+
return `a ${name.length}-character name`;
|
|
25
|
+
if (platform === 'win32' && join(directory, name).length >= WINDOWS_PATH_LIMIT)
|
|
26
|
+
return 'a path over the Windows 260-character limit';
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
/** The entry names of a directory, or undefined when it cannot be listed or is too large to compare. */
|
|
30
|
+
export async function directoryNames(directory) {
|
|
31
|
+
try {
|
|
32
|
+
const names = await readdir(directory);
|
|
33
|
+
return names.length > SCAN_LIMIT ? undefined : new Set(names);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The note for the entries that appeared in `directory` since `before` and have a stray name; empty when none did. */
|
|
40
|
+
export async function strayFileNotice(directory, before, platform = process.platform) {
|
|
41
|
+
if (!before)
|
|
42
|
+
return '';
|
|
43
|
+
const after = await directoryNames(directory);
|
|
44
|
+
if (!after)
|
|
45
|
+
return '';
|
|
46
|
+
const found = [];
|
|
47
|
+
for (const name of after) {
|
|
48
|
+
if (before.has(name))
|
|
49
|
+
continue;
|
|
50
|
+
const reason = strayNameReason(name, directory, platform);
|
|
51
|
+
if (!reason)
|
|
52
|
+
continue;
|
|
53
|
+
const shown = name.length > SHOWN_NAME_CHARS ? `${name.slice(0, SHOWN_NAME_CHARS)}…` : name;
|
|
54
|
+
found.push(`${JSON.stringify(shown)} (${reason})`);
|
|
55
|
+
}
|
|
56
|
+
if (!found.length)
|
|
57
|
+
return '';
|
|
58
|
+
const listed = found.slice(0, SHOWN_FILES).join(', ') + (found.length > SHOWN_FILES ? ` and ${found.length - SHOWN_FILES} more` : '');
|
|
59
|
+
return `\n[Warning: this command created ${found.length === 1 ? 'a file' : 'files'} in ${directory} whose name is almost certainly a mistake: ${listed}. `
|
|
60
|
+
+ 'Delete it now unless it was intended; such a file breaks Git and other tools on Windows. '
|
|
61
|
+
+ 'The usual causes are a path and its content passed in the wrong order (Windows PowerShell binds the content of Set-Content or Add-Content as the path when a switch such as -NoNewline comes before a positional path: name -Path and -Value, or use Write) '
|
|
62
|
+
+ 'and output redirected to nul outside cmd.exe (use $null in PowerShell, /dev/null in Bash).]';
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Runs a shell tool's command and adds the stray-file note to whatever it reports. A command that
|
|
66
|
+
* fails reports through its error, so the note is added there too: the command that leaves such a
|
|
67
|
+
* file behind has usually failed on the next line.
|
|
68
|
+
*/
|
|
69
|
+
export async function withStrayFileNotice(directory, run) {
|
|
70
|
+
const before = await directoryNames(directory);
|
|
71
|
+
try {
|
|
72
|
+
const output = await run();
|
|
73
|
+
return output + await strayFileNotice(directory, before);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const notice = await strayFileNotice(directory, before);
|
|
77
|
+
if (notice && error instanceof Error)
|
|
78
|
+
error.message += notice;
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
package/dist/src/subagent-run.js
CHANGED
|
@@ -11,12 +11,12 @@ import { createRunTelemetry, recordModelUse } from './telemetry/capture.js';
|
|
|
11
11
|
import { checkGraphModelHealth } from './graph-health.js';
|
|
12
12
|
import { validateGraph } from './graphs.js';
|
|
13
13
|
import { runGraph } from './runtime.js';
|
|
14
|
-
import { createTools } from './tools.js';
|
|
15
14
|
import { loadWorkspaceInstructions } from './workspace-instructions.js';
|
|
16
15
|
import { extensionSnapshot } from './extensions.js';
|
|
17
16
|
import { resolveModelContext } from './model-metadata.js';
|
|
18
17
|
import { MemoryManager } from './memory/MemoryManager.js';
|
|
19
18
|
import { LocalToolMemory } from './memory/LocalToolMemory.js';
|
|
19
|
+
import { ProjectMemory } from './memory/ProjectMemory.js';
|
|
20
20
|
import { ArtifactStore } from './artifacts.js';
|
|
21
21
|
import { CodeIntelligenceManager } from './code-intelligence/CodeIntelligenceManager.js';
|
|
22
22
|
import { DecisionManager } from './decision/DecisionManager.js';
|
|
@@ -536,6 +536,7 @@ export class SubagentRunner {
|
|
|
536
536
|
let codeIntel;
|
|
537
537
|
/** The repository's learned command guidance, when the installation keeps it. */
|
|
538
538
|
let commandMemory;
|
|
539
|
+
let projectMemory;
|
|
539
540
|
/** The checkpoint writes, chained so the newest conversation is the file's content. */
|
|
540
541
|
let checkpointWrites = Promise.resolve();
|
|
541
542
|
try {
|
|
@@ -614,6 +615,8 @@ export class SubagentRunner {
|
|
|
614
615
|
// run honours it like any other run.
|
|
615
616
|
if (config.commandMemory !== false)
|
|
616
617
|
commandMemory = await LocalToolMemory.open({ workspace: run.workspace, directory: run.directory });
|
|
618
|
+
if (config.projectMemory !== false)
|
|
619
|
+
projectMemory = await ProjectMemory.open({ home: run.directory, workspace: run.workspace });
|
|
617
620
|
// The checkpoints land one at a time, newest last: the runner calls back synchronously from
|
|
618
621
|
// several nodes, and an unserialized write could leave an older conversation as the file's
|
|
619
622
|
// final content.
|
|
@@ -635,6 +638,7 @@ export class SubagentRunner {
|
|
|
635
638
|
// while its checkpoint was still queued could be killed with that conversation unwritten.
|
|
636
639
|
return checkpointWrites;
|
|
637
640
|
};
|
|
641
|
+
const { createTools } = await import('./tools.js');
|
|
638
642
|
const graphOptions = {
|
|
639
643
|
task: run.task, runId: run.runId, provider: run.providerId, model: run.model,
|
|
640
644
|
adapter: adapterFor(resolvedProvider),
|
|
@@ -673,6 +677,7 @@ export class SubagentRunner {
|
|
|
673
677
|
context,
|
|
674
678
|
artifactStore,
|
|
675
679
|
...(commandMemory ? { commandMemory } : {}),
|
|
680
|
+
...(projectMemory ? { projectMemory } : {}),
|
|
676
681
|
memory,
|
|
677
682
|
decisionManager: new DecisionManager({ config: await subagentDecisionConfig(config, () => (options.membership ?? getMembership)(signal)), onEvent: event => this.observe(run, event) }),
|
|
678
683
|
decisionNodeOptIn: true,
|
|
@@ -427,7 +427,7 @@ export declare class TerminalUI extends EventEmitter {
|
|
|
427
427
|
loadScreen<T>(title: string, load: (signal: AbortSignal) => Promise<T>, options?: ScreenOptions): Promise<T | undefined>;
|
|
428
428
|
private openModal;
|
|
429
429
|
private finishModal;
|
|
430
|
-
print(text: string, detail?: string, toolCall?: ToolCallStamp, conversation?: boolean, notice?: boolean, alignRight?: boolean): void;
|
|
430
|
+
print(text: string, detail?: string, toolCall?: ToolCallStamp, conversation?: boolean, notice?: boolean, alignRight?: boolean, clipRows?: boolean): void;
|
|
431
431
|
/**
|
|
432
432
|
* Echo submitted text as its own bordered box.
|
|
433
433
|
*
|
package/dist/src/terminal-ui.js
CHANGED
|
@@ -1131,7 +1131,7 @@ export class TerminalUI extends EventEmitter {
|
|
|
1131
1131
|
modal.resolve(value);
|
|
1132
1132
|
this.scheduleRender();
|
|
1133
1133
|
}
|
|
1134
|
-
print(text, detail, toolCall, conversation = false, notice = true, alignRight = false) {
|
|
1134
|
+
print(text, detail, toolCall, conversation = false, notice = true, alignRight = false, clipRows = false) {
|
|
1135
1135
|
if (notice) {
|
|
1136
1136
|
this.dashboardNotices.push(clean(String(text)).slice(0, 100_000));
|
|
1137
1137
|
this.dashboardNotices = this.dashboardNotices.slice(-12);
|
|
@@ -1140,7 +1140,7 @@ export class TerminalUI extends EventEmitter {
|
|
|
1140
1140
|
if (this.modal?.kind === 'loading')
|
|
1141
1141
|
this.modal.lines = [...this.modal.lines, ...lines].slice(-100);
|
|
1142
1142
|
const entry = { text: lines.join('\n'), ...(detail ? { detail: clean(detail) } : {}),
|
|
1143
|
-
...(toolCall ? { toolCall, timing: this.toolClock.get(toolCall.key) } : {}), ...(conversation ? { conversation: true } : {}), ...(alignRight ? { alignRight: true } : {}) };
|
|
1143
|
+
...(toolCall ? { toolCall, timing: this.toolClock.get(toolCall.key) } : {}), ...(conversation ? { conversation: true } : {}), ...(alignRight ? { alignRight: true } : {}), ...(clipRows && detail ? { clipRows: true } : {}) };
|
|
1144
1144
|
if (this.scroll)
|
|
1145
1145
|
this.scroll += this.transcriptRows(entry, this.chatColumns()).length;
|
|
1146
1146
|
this.transcript.append(entry);
|
|
@@ -3101,7 +3101,13 @@ export class TerminalUI extends EventEmitter {
|
|
|
3101
3101
|
? promptExpanded && entry.detail ? entry.detail : entry.text
|
|
3102
3102
|
: this.expandedTranscript && entry.detail ? entry.detail : entry.text + (entry.detail ? ' (Ctrl+O to expand)' : '');
|
|
3103
3103
|
if (!entry.toolCall) {
|
|
3104
|
-
|
|
3104
|
+
// A collapsed tool result holds each output row to one screen line; Ctrl+O shows the rows
|
|
3105
|
+
// whole. The last row is the `… N lines total (Ctrl+O to expand)` marker, which still wraps
|
|
3106
|
+
// so a narrow pane never hides the key that reveals the rest.
|
|
3107
|
+
const shown = entry.clipRows && text !== entry.detail
|
|
3108
|
+
? text.split('\n').map((row, index, rows) => index < rows.length - 1 ? clip(row, Math.max(1, width - 4)) : row).join('\n')
|
|
3109
|
+
: text;
|
|
3110
|
+
const rows = this.wrapTranscript(shown + '\n', width, entry.alignRight === true);
|
|
3105
3111
|
if (!disclosure)
|
|
3106
3112
|
return rows;
|
|
3107
3113
|
return rows.map(row => {
|
|
@@ -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/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,6 +161,8 @@ 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')
|
|
@@ -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;
|
|
@@ -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;
|
package/dist/src/update.js
CHANGED
|
@@ -8,7 +8,8 @@ import semver from 'semver';
|
|
|
8
8
|
import { configDirectory } from './config.js';
|
|
9
9
|
const executeFile = promisify(execFile);
|
|
10
10
|
/** The package `andorra update` installs. */
|
|
11
|
-
|
|
11
|
+
import { PACKAGE_NAME } from './package-name.js';
|
|
12
|
+
export { PACKAGE_NAME };
|
|
12
13
|
/** The npm dist-tag the update follows. */
|
|
13
14
|
const RELEASE_TAG = 'latest';
|
|
14
15
|
/** Bounded install attempts; only a failure that still looks transient is retried. */
|
|
@@ -74,6 +75,25 @@ async function npmCli() {
|
|
|
74
75
|
}
|
|
75
76
|
throw new Error('Cannot find npm beside the Node.js installation running Andorra. Install Node.js with npm, then run andorra update again.');
|
|
76
77
|
}
|
|
78
|
+
/** The install prefix of the Node.js running Andorra: the directory above `bin/node`, or the directory of `node.exe`. */
|
|
79
|
+
async function runningNodePrefix() {
|
|
80
|
+
const nodeDirectory = dirname(await realpath(process.execPath));
|
|
81
|
+
return process.platform === 'win32' ? nodeDirectory : resolve(nodeDirectory, '..');
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The prefix to name to npm when the package is the global install of the Node.js running it, as
|
|
85
|
+
* the native installer lays it out (~/.andorracode/runtime/node). npm would otherwise take its
|
|
86
|
+
* global prefix from the user's .npmrc or NPM_CONFIG_PREFIX, which names a different directory
|
|
87
|
+
* and turns the update into a refusal. For every other layout npm's own answer stands.
|
|
88
|
+
*/
|
|
89
|
+
export async function ownedNodePrefix(packageRoot, nodePrefix) {
|
|
90
|
+
const prefix = await realpath(nodePrefix).catch(() => undefined);
|
|
91
|
+
if (!prefix)
|
|
92
|
+
return undefined;
|
|
93
|
+
const scoped = PACKAGE_NAME.split('/');
|
|
94
|
+
const candidates = [join(prefix, 'lib', 'node_modules', ...scoped), join(prefix, 'node_modules', ...scoped)];
|
|
95
|
+
return candidates.some(candidate => samePath(candidate, packageRoot)) ? prefix : undefined;
|
|
96
|
+
}
|
|
77
97
|
/** Keep the opaque, escaped shapes Windows error text can carry when matching it. */
|
|
78
98
|
function normalizePathText(text) {
|
|
79
99
|
return text.replace(/\\{2,}/g, '\\').replace(/\\/g, '/').toLowerCase();
|
|
@@ -283,10 +303,10 @@ function installFailureMessage(entry, version, outcome, cause) {
|
|
|
283
303
|
* looks like a transient Windows sharing violation is retried a bounded number of times, after
|
|
284
304
|
* checking that the package can be moved again; anything else is reported at once.
|
|
285
305
|
*/
|
|
286
|
-
async function installRelease(run, sleep, probe, npm, cwd, packageRoot, entry, version, previous) {
|
|
306
|
+
async function installRelease(run, sleep, probe, npm, cwd, packageRoot, entry, version, previous, prefixArgs) {
|
|
287
307
|
for (let attempt = 1; attempt <= INSTALL_ATTEMPTS; attempt += 1) {
|
|
288
308
|
try {
|
|
289
|
-
await run(process.execPath, [npm, 'install', '--global', `${PACKAGE_NAME}@${version}`, '--prefer-online', '--no-audit', '--no-fund'], cwd, { stream: true });
|
|
309
|
+
await run(process.execPath, [npm, 'install', '--global', ...prefixArgs, `${PACKAGE_NAME}@${version}`, '--prefer-online', '--no-audit', '--no-fund'], cwd, { stream: true });
|
|
290
310
|
return { ok: true };
|
|
291
311
|
}
|
|
292
312
|
catch (error) {
|
|
@@ -512,9 +532,11 @@ export async function updateInstallation(options = {}) {
|
|
|
512
532
|
// npm runs outside the package it replaces: a working directory inside it would keep Windows from
|
|
513
533
|
// moving it, and a project's .npmrc in the caller's directory has no say over a global install.
|
|
514
534
|
const cwd = home;
|
|
535
|
+
const owned = await ownedNodePrefix(packageRoot, options.nodePrefix ?? await runningNodePrefix());
|
|
536
|
+
const prefixArgs = owned ? ['--prefix', owned] : [];
|
|
515
537
|
let globalRoot;
|
|
516
538
|
try {
|
|
517
|
-
globalRoot = lastLine(await run(process.execPath, [npm, 'root', '--global'], cwd));
|
|
539
|
+
globalRoot = lastLine(await run(process.execPath, [npm, 'root', '--global', ...prefixArgs], cwd));
|
|
518
540
|
}
|
|
519
541
|
catch (error) {
|
|
520
542
|
throw new Error(`Could not ask npm where global packages are installed, so nothing was changed.\n${error.message}`);
|
|
@@ -556,7 +578,7 @@ export async function updateInstallation(options = {}) {
|
|
|
556
578
|
const replaceable = await probe(packageRoot);
|
|
557
579
|
if (replaceable.state !== 'clear')
|
|
558
580
|
throw probeRefusal(packageRoot, replaceable);
|
|
559
|
-
const outcome = await installRelease(run, sleep, probe, npm, cwd, packageRoot, entry, latest, current);
|
|
581
|
+
const outcome = await installRelease(run, sleep, probe, npm, cwd, packageRoot, entry, latest, current, prefixArgs);
|
|
560
582
|
if (!outcome.ok)
|
|
561
583
|
throw new Error(installFailureMessage(entry, latest, { locked: outcome.locked, installed: outcome.installed }, outcome.cause));
|
|
562
584
|
const installed = await installedVersion(entry);
|
|
@@ -4,3 +4,18 @@
|
|
|
4
4
|
* parent repositories and external worktree/common directories are unavailable.
|
|
5
5
|
*/
|
|
6
6
|
export declare function workspaceGitMetadata(args: string[], workspace: string): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Identity of a linked worktree's main repository: its origin url and the main checkout's root.
|
|
9
|
+
*
|
|
10
|
+
* `workspaceGitMetadata` never leaves the workspace, so a worktree whose shared Git directory lives
|
|
11
|
+
* in the main checkout has no remote there. Project memory needs every worktree of a repository to
|
|
12
|
+
* resolve to one identity, so this follows the worktree's own `.git` pointer and `commondir` out
|
|
13
|
+
* of the workspace. It only reads three small files with bounded reads and runs nothing; a
|
|
14
|
+
* workspace could name any remote in its own config anyway, so following the pointer grants no
|
|
15
|
+
* identity it could not already claim. Returns undefined when the workspace is not a linked
|
|
16
|
+
* worktree or any step is malformed.
|
|
17
|
+
*/
|
|
18
|
+
export declare function linkedWorktreeIdentity(workspace: string): Promise<{
|
|
19
|
+
remote: string;
|
|
20
|
+
root: string;
|
|
21
|
+
} | undefined>;
|
|
@@ -68,7 +68,10 @@ export async function workspaceGitMetadata(args, workspace) {
|
|
|
68
68
|
}
|
|
69
69
|
if (common)
|
|
70
70
|
directory = await checked(resolve(directory, common));
|
|
71
|
-
|
|
71
|
+
return originUrl(await text(join(directory, 'config'), 65536));
|
|
72
|
+
}
|
|
73
|
+
/** The `remote "origin"` url of a Git config file's text, or '' when it names none. */
|
|
74
|
+
function originUrl(config) {
|
|
72
75
|
let origin = false;
|
|
73
76
|
let remote = '';
|
|
74
77
|
for (const line of config.split(/\r?\n/)) {
|
|
@@ -86,6 +89,52 @@ export async function workspaceGitMetadata(args, workspace) {
|
|
|
86
89
|
}
|
|
87
90
|
return remote;
|
|
88
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Identity of a linked worktree's main repository: its origin url and the main checkout's root.
|
|
94
|
+
*
|
|
95
|
+
* `workspaceGitMetadata` never leaves the workspace, so a worktree whose shared Git directory lives
|
|
96
|
+
* in the main checkout has no remote there. Project memory needs every worktree of a repository to
|
|
97
|
+
* resolve to one identity, so this follows the worktree's own `.git` pointer and `commondir` out
|
|
98
|
+
* of the workspace. It only reads three small files with bounded reads and runs nothing; a
|
|
99
|
+
* workspace could name any remote in its own config anyway, so following the pointer grants no
|
|
100
|
+
* identity it could not already claim. Returns undefined when the workspace is not a linked
|
|
101
|
+
* worktree or any step is malformed.
|
|
102
|
+
*/
|
|
103
|
+
export async function linkedWorktreeIdentity(workspace) {
|
|
104
|
+
const read = async (path, limit) => {
|
|
105
|
+
const handle = await open(path, 'r');
|
|
106
|
+
try {
|
|
107
|
+
const info = await handle.stat();
|
|
108
|
+
if (!info.isFile() || info.size > limit)
|
|
109
|
+
throw new Error('Invalid Git metadata');
|
|
110
|
+
const buffer = Buffer.alloc(limit + 1);
|
|
111
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
112
|
+
if (bytesRead > limit)
|
|
113
|
+
throw new Error('Invalid Git metadata');
|
|
114
|
+
return buffer.subarray(0, bytesRead).toString('utf8').trim();
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
await handle.close();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
try {
|
|
121
|
+
const root = await realpath(workspace);
|
|
122
|
+
const pointer = /^gitdir: (.+)$/.exec(await read(join(root, '.git'), 4096));
|
|
123
|
+
if (!pointer)
|
|
124
|
+
return undefined;
|
|
125
|
+
const gitDirectory = resolve(root, pointer[1]);
|
|
126
|
+
const common = await realpath(resolve(gitDirectory, await read(join(gitDirectory, 'commondir'), 4096)));
|
|
127
|
+
if (!(await stat(common)).isDirectory())
|
|
128
|
+
return undefined;
|
|
129
|
+
const remote = originUrl(await read(join(common, 'config'), 65536));
|
|
130
|
+
// A standard layout keeps the shared directory at <main checkout>/.git.
|
|
131
|
+
const mainRoot = common.replace(/[\\/]+$/, '').replace(/[\\/]\.git$/i, '');
|
|
132
|
+
return { remote, root: mainRoot === common ? common : mainRoot };
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
89
138
|
/** Decode a single Git config value, rejecting unsupported/malformed escapes. */
|
|
90
139
|
function configValue(value) {
|
|
91
140
|
let result = '';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { readdir } from 'node:fs/promises';
|
|
2
|
-
import { createTools } from './tools.js';
|
|
3
2
|
import { clipText } from './text.js';
|
|
4
3
|
/** Guide names in order of preference, each with the spelling that wins a same-name tie. */
|
|
5
4
|
const GUIDE_NAMES = ['ANDORRA.md', 'AGENTS.md'];
|
|
@@ -39,6 +38,7 @@ export async function loadWorkspaceInstructions(workspace, signal, override) {
|
|
|
39
38
|
return '';
|
|
40
39
|
// read_file is the raw-content reader; the canonical Read prefixes 'N\t' line numbers,
|
|
41
40
|
// which would corrupt the guidance text injected into the model prompt.
|
|
41
|
+
const { createTools } = await import('./tools.js');
|
|
42
42
|
const guide = await createTools().find(tool => tool.name === 'read_file').execute({ path }, {
|
|
43
43
|
workspace, signal, yolo: false, approve: async () => false,
|
|
44
44
|
});
|