@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
package/dist/src/coding-tools.js
CHANGED
|
@@ -6,9 +6,12 @@ import { promisify } from 'node:util';
|
|
|
6
6
|
import { StringDecoder } from 'node:string_decoder';
|
|
7
7
|
import { andorraCreateReadTool, andorraCreateWriteTool, andorraCreateEditTool, andorraCreateFindTool, andorraCreateGrepTool, andorraCreateLsTool, andorraCreateBashTool, andorraCreatePowerShellTool, } from '../vendor/engine/runtime/coding-agent/core/tools/index.js';
|
|
8
8
|
import { andorraGetToolPath } from '../vendor/engine/runtime/coding-agent/utils/tools-manager.js';
|
|
9
|
+
import { registerEditArgumentPreparer } from './diff-preview.js';
|
|
10
|
+
import { stateKey } from './file-read-key.js';
|
|
9
11
|
import { defaultShellKind, runShell, runNativeProcess } from './shell.js';
|
|
10
12
|
import { commandTimingSummary } from './command-metrics.js';
|
|
11
13
|
import { runPooledPowerShell } from './powershell-pool.js';
|
|
14
|
+
import { withStrayFileNotice } from './stray-files.js';
|
|
12
15
|
import { assertNotHostKill, assertNotHostKillArgv, hostShellOf } from './host-process-guard.js';
|
|
13
16
|
import { getQaProcessManager, PERSISTENT_JOBS_SUPPORTED } from './qa/runtime/ProcessManager.js';
|
|
14
17
|
import { clipText } from './text.js';
|
|
@@ -19,6 +22,9 @@ import { withGrepRegex } from './grep-regex.js';
|
|
|
19
22
|
import { claimReadImages, readImageObservation } from './read-image.js';
|
|
20
23
|
import { READ_PDF_RENDER_PAGES, legacyTextObservation, readDocumentObservation } from './read-document-tool.js';
|
|
21
24
|
const execFileAsync = promisify(execFile);
|
|
25
|
+
// Edit previews use the executor's own argument normalizer. Construction only defines metadata;
|
|
26
|
+
// previewing never invokes the tool executor.
|
|
27
|
+
registerEditArgumentPreparer(andorraCreateEditTool('.').prepareArguments);
|
|
22
28
|
const excluded = new Set(['.git', 'node_modules', '.andorracode']);
|
|
23
29
|
const MAX_MODEL_OUTPUT = 24_000;
|
|
24
30
|
/** Lines returned by one Read call: both the default and the accepted maximum for `limit`. */
|
|
@@ -178,10 +184,7 @@ const boolArg = (args, key) => {
|
|
|
178
184
|
* entries under the key the canonical tools look up. It must be applied to a path normalized
|
|
179
185
|
* the same way the policy's safePath normalizes it, or the entries never match.
|
|
180
186
|
*/
|
|
181
|
-
export
|
|
182
|
-
const key = path.resolve(resolved);
|
|
183
|
-
return process.platform === 'win32' ? key.toLowerCase() : key;
|
|
184
|
-
}
|
|
187
|
+
export { stateKey };
|
|
185
188
|
function state(context) {
|
|
186
189
|
context.toolState ??= { fileReads: new Map() };
|
|
187
190
|
return context.toolState;
|
|
@@ -725,7 +728,7 @@ export function createCodingTools(policy) {
|
|
|
725
728
|
});
|
|
726
729
|
return args;
|
|
727
730
|
};
|
|
728
|
-
const Glob = zTool('Glob', 'Find files by glob pattern inside the workspace. This replaces Andorra list_files and Pi find/ls with one bounded discovery tool.', { type: 'object', properties: {
|
|
731
|
+
const Glob = zTool('Glob', 'Find files by glob pattern inside the workspace. This replaces Andorra list_files and Pi find/ls with one bounded discovery tool. It matches names, not contents, so use it to find something by name (for example *deploy*) before searching file contents; raise head_limit when the result reaches the limit.', { type: 'object', properties: {
|
|
729
732
|
pattern: { type: 'string', description: 'Glob pattern such as **/*.ts or src/**/*.spec.ts' },
|
|
730
733
|
path: { type: 'string', description: 'Directory inside the workspace; defaults to .' },
|
|
731
734
|
head_limit: { type: 'integer', minimum: 1, maximum: 1000, description: 'Maximum paths; default 100' },
|
|
@@ -906,7 +909,7 @@ export function createCodingTools(policy) {
|
|
|
906
909
|
const canonicalShell = (name, kind) => {
|
|
907
910
|
const actual = kind === 'powershell' ? 'PowerShell' : 'Bash';
|
|
908
911
|
const syntax = kind === 'powershell'
|
|
909
|
-
? 'PowerShell syntax; use & before a quoted executable path. No cmd.exe substitution. Do not pipe a running child into Select-Object -First: it terminates the pipeline before the child completes and can cause exit 4294967295. Host output is already tail-bounded; use Select-Object -Last if further filtering is needed. Prefer file-written scripts over nested quoting for multiline Python/JavaScript. Prefer direct invocation (& $exe @args) for child processes: Windows PowerShell Start-Process -ArgumentList flattens arrays and can split a multi-word argument unless it is quoted manually. Windows PowerShell also alters what it hands a native program: piping a string into one (ssh, wsl, bash -s, docker exec) appends CRLF after the last line, so a remote shell runs that line with a stray \r, and double quotes inside a native argument are dropped. Send a multi-line script to a remote or POSIX shell as base64 instead: $b = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(($script -replace "`r", "") + "`n")); & ssh host "echo $b | base64 -d | bash".'
|
|
912
|
+
? 'PowerShell syntax; use & before a quoted executable path. No cmd.exe substitution. Do not pipe a running child into Select-Object -First: it terminates the pipeline before the child completes and can cause exit 4294967295. Host output is already tail-bounded; use Select-Object -Last if further filtering is needed. Prefer file-written scripts over nested quoting for multiline Python/JavaScript. Prefer direct invocation (& $exe @args) for child processes: Windows PowerShell Start-Process -ArgumentList flattens arrays and can split a multi-word argument unless it is quoted manually. Windows PowerShell also alters what it hands a native program: piping a string into one (ssh, wsl, bash -s, docker exec) appends CRLF after the last line, so a remote shell runs that line with a stray \r, and double quotes inside a native argument are dropped. Windows PowerShell binds the content of Set-Content or Add-Content as the file name when a switch such as -NoNewline comes before a positional path: name -Path and -Value, or use Write. Send a multi-line script to a remote or POSIX shell as base64 instead: $b = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(($script -replace "`r", "") + "`n")); & ssh host "echo $b | base64 -d | bash".'
|
|
910
913
|
: 'Bash syntax (Git Bash on Windows).';
|
|
911
914
|
const tool = zTool(name, `Execute a foreground ${actual} command in the workspace. The working directory is the workspace; ${syntax} Output is tail-bounded. Commands follow the current workspace permissions. Restricted modes use the Codex OS sandbox and block network/outside writes; explicit escalation requires justification and approval. Credential environment variables are excluded; credential files remain accessible. This uses the compact command/timeout/description contract while retaining Pi/Andorra process-tree cleanup. Background execution is not exposed${kind === 'powershell' ? '' : ': a command that leaves a job running (cmd &) waits for that job, and the timeout then stops it'}. Start long-running work with AsyncProcess instead${PERSISTENT_JOBS_SUPPORTED ? ', with persist: true for a service the user needs left running after you finish' : ''}.`, { type: 'object', properties: {
|
|
912
915
|
command: { type: 'string', description: 'Command to execute' },
|
|
@@ -955,20 +958,22 @@ export function createCodingTools(policy) {
|
|
|
955
958
|
const current = kind === 'powershell'
|
|
956
959
|
? andorraCreatePowerShellTool(cwd, { operations, persistOutput: false, exposeSessionEnvironment: false })
|
|
957
960
|
: andorraCreateBashTool(cwd, { operations, persistOutput: false, exposeSessionEnvironment: false });
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
961
|
+
return withStrayFileNotice(cwd, async () => {
|
|
962
|
+
try {
|
|
963
|
+
const result = await current.execute(randomUUID(), { command, timeout: timeout / 1000 }, context.signal);
|
|
964
|
+
return nativeObservation(result.content.filter(part => part.type === 'text').map(part => part.text).join('\n'), true);
|
|
965
|
+
}
|
|
966
|
+
catch (error) {
|
|
967
|
+
if (!(error instanceof Error))
|
|
968
|
+
throw error;
|
|
969
|
+
const message = shellTimeoutGuidance(error.message, timeout);
|
|
970
|
+
if (message.length > MAX_MODEL_OUTPUT)
|
|
971
|
+
throw new Error(nativeObservation(message, true));
|
|
972
|
+
if (message !== error.message)
|
|
973
|
+
throw new Error(message);
|
|
964
974
|
throw error;
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
throw new Error(nativeObservation(message, true));
|
|
968
|
-
if (message !== error.message)
|
|
969
|
-
throw new Error(message);
|
|
970
|
-
throw error;
|
|
971
|
-
}
|
|
975
|
+
}
|
|
976
|
+
});
|
|
972
977
|
});
|
|
973
978
|
// The vendored shell throws on any exit other than 0, so a return is a clean exit.
|
|
974
979
|
return { ...tool, exitZeroOnReturn: true };
|
|
@@ -1035,8 +1040,9 @@ export function createCodingTools(policy) {
|
|
|
1035
1040
|
const cwd = await policy.safePath(context, '.');
|
|
1036
1041
|
// Preserve the legacy observation formats: 'shell' keeps the runShell observation,
|
|
1037
1042
|
// while explicit 'powershell'/'bash' use native tail truncation and errors.
|
|
1043
|
+
const command = args.command;
|
|
1038
1044
|
if (name === 'shell')
|
|
1039
|
-
return nativeObservation(await runShell(
|
|
1045
|
+
return withStrayFileNotice(cwd, async () => nativeObservation(await runShell(command, cwd, timeout, context.signal, kind, undefined, undefined, launchPolicy), true));
|
|
1040
1046
|
const operations = { exec: async (value, directory, options) => {
|
|
1041
1047
|
try {
|
|
1042
1048
|
await runShell(value, directory, timeout, context.signal, kind, options.onData, undefined, launchPolicy);
|
|
@@ -1053,15 +1059,17 @@ export function createCodingTools(policy) {
|
|
|
1053
1059
|
const current = kind === 'powershell'
|
|
1054
1060
|
? andorraCreatePowerShellTool(cwd, { operations, persistOutput: false, exposeSessionEnvironment: false })
|
|
1055
1061
|
: andorraCreateBashTool(cwd, { operations, persistOutput: false, exposeSessionEnvironment: false });
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1062
|
+
return withStrayFileNotice(cwd, async () => {
|
|
1063
|
+
try {
|
|
1064
|
+
const result = await current.execute(randomUUID(), { command, timeout: timeout / 1000 }, context.signal);
|
|
1065
|
+
return nativeObservation(result.content.filter(part => part.type === 'text').map(part => part.text).join('\n'), true);
|
|
1066
|
+
}
|
|
1067
|
+
catch (error) {
|
|
1068
|
+
if (error instanceof Error && error.message.length > 24_000)
|
|
1069
|
+
throw new Error(nativeObservation(error.message, true));
|
|
1070
|
+
throw error;
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
1065
1073
|
},
|
|
1066
1074
|
};
|
|
1067
1075
|
});
|
|
@@ -1086,7 +1094,7 @@ export function createCodingTools(policy) {
|
|
|
1086
1094
|
const executable = program === 'node' ? process.execPath : program === 'git' ? 'git' : andorraGetToolPath('rg');
|
|
1087
1095
|
if (!executable)
|
|
1088
1096
|
throw new Error('Native executable is not installed');
|
|
1089
|
-
return nativeObservation(await runNativeProcess(executable, argv, cwd, timeout, context.signal, launchPolicy), true);
|
|
1097
|
+
return withStrayFileNotice(cwd, async () => nativeObservation(await runNativeProcess(executable, argv, cwd, timeout, context.signal, launchPolicy), true));
|
|
1090
1098
|
});
|
|
1091
1099
|
const AsyncProcess = zTool('AsyncProcess', `Start a shell command in the background and return immediately; inspect status/logs, wait for completion without polling, or stop it. Use for independent builds, test suites, and dev servers so other agent work can continue. Each job has a generated ID. ${PERSISTENT_JOBS_SUPPORTED
|
|
1092
1100
|
? 'Jobs are killed when the owning CLI exits unless started with persist: true. When the task is to leave a service running for the user (a web server, daemon or listener they will use after you finish), start it with persist: true and do not stop it before you finish.'
|
|
@@ -1142,7 +1150,7 @@ export function createCodingTools(policy) {
|
|
|
1142
1150
|
const timeout = intArg(args, 'timeout', { min: 1, max: 600000 }) ?? 30000;
|
|
1143
1151
|
const launchPolicy = await shellPermission(policy, 'PowerShellFast', args, context);
|
|
1144
1152
|
const cwd = await policy.safePath(context, '.');
|
|
1145
|
-
return nativeObservation(await runPooledPowerShell(command, cwd, timeout, context.signal, launchPolicy, context.onCommandOutput), true);
|
|
1153
|
+
return withStrayFileNotice(cwd, async () => nativeObservation(await runPooledPowerShell(command, cwd, timeout, context.signal, launchPolicy, context.onCommandOutput), true));
|
|
1146
1154
|
});
|
|
1147
1155
|
const ShellMetrics = zTool('ShellMetrics', 'Return bounded per-process command timing statistics (p50/p95/p99), startup/validation, execution, first-output and cleanup phases without leaking command arguments.', { type: 'object', properties: {}, additionalProperties: false }, 'parallel', async () => JSON.stringify(commandTimingSummary()));
|
|
1148
1156
|
const platformShell = process.platform === 'win32' ? canonicalShell('PowerShell', 'powershell') : canonicalShell('Bash', 'bash');
|
package/dist/src/completion.d.ts
CHANGED
|
@@ -52,7 +52,8 @@ export declare function completionResponse(response: ModelResponse): ModelRespon
|
|
|
52
52
|
* line breaks belong, and the transcript draws its markdown as one literal paragraph.
|
|
53
53
|
*
|
|
54
54
|
* Two shapes are decoded. A summary escaped throughout has no real line break and at least two
|
|
55
|
-
* escaped paragraph breaks
|
|
55
|
+
* escaped paragraph breaks, or at least two escaped breaks outside code that open markdown
|
|
56
|
+
* structure (one paragraph break and a list is enough); every escape in it is undone. A model can also switch to the extra
|
|
56
57
|
* escaping partway through, leaving a few real line breaks and the rest escaped: one `## heading`
|
|
57
58
|
* then swallows everything after it. That mixed summary is decoded only when at least two escaped
|
|
58
59
|
* breaks outside code open markdown structure (a heading, list item, quote, table, fence, or a
|
|
@@ -64,6 +65,47 @@ export declare function completionResponse(response: ModelResponse): ModelRespon
|
|
|
64
65
|
* (`displayHistory` in sessions.ts).
|
|
65
66
|
*/
|
|
66
67
|
export declare function decodeDoubleEscapedSummary(summary: string, notes?: string[]): string;
|
|
68
|
+
/**
|
|
69
|
+
* Replace a completion envelope a model wrote as message text, so the transcript never shows raw
|
|
70
|
+
* JSON. Two live shapes, both glm-5.3-flash on GX10:
|
|
71
|
+
* - Run 3a8378f0 ended a QA report with "Submitting the report." and then the whole envelope as
|
|
72
|
+
* text, `{"summary":"…\n\n## 1. Target…","tests":[…],"prUrl":"…"}`, about 12 KB, instead of
|
|
73
|
+
* calling complete_agent. The runtime rightly sent it back; the caller passes a `note` saying so,
|
|
74
|
+
* which stands in for the envelope (the report itself arrives later through complete_agent).
|
|
75
|
+
* - Session bbedcfbf narrated beside its tool calls as `{"summary":"Starting the PR comment fixer
|
|
76
|
+
* round…","tests":[]}`. With no `note`, the envelope's summary stands in for it, decoded like a
|
|
77
|
+
* completion's, so the narration still reads as prose.
|
|
78
|
+
*
|
|
79
|
+
* Only an envelope that ends the text is replaced: a JSON object whose `summary` is a string, which
|
|
80
|
+
* parses on its own from its opening brace to the end of the text (closing brackets the model left
|
|
81
|
+
* off are supplied, as for a completion), bare or as the whole of a final fenced block. One shown in
|
|
82
|
+
* inline code, one followed by more prose, and otherwise malformed JSON are left as written.
|
|
83
|
+
*/
|
|
84
|
+
export declare function withoutTrailingEnvelope(text: string, note?: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Remove the completion fields a model copied into the end of its summary as text. Some models
|
|
87
|
+
* call complete_agent with every field set and then also write the same fields out under the
|
|
88
|
+
* answer:
|
|
89
|
+
*
|
|
90
|
+
* Browser is open.
|
|
91
|
+
*
|
|
92
|
+
* summary: Browser panel opened successfully on example.com.
|
|
93
|
+
* tests: none — no checks were required.
|
|
94
|
+
* outcome: completed
|
|
95
|
+
* output: {}
|
|
96
|
+
*
|
|
97
|
+
* The transcript draws the summary as the answer, so those lines reached the user as a raw field
|
|
98
|
+
* dump. Unlike an embedded JSON envelope (`rejectEmbeddedEnvelope`), the arguments themselves are
|
|
99
|
+
* intact, so there is nothing for a retry to repair: the trailing block is dropped and recorded.
|
|
100
|
+
*
|
|
101
|
+
* Only a block at the very end is touched, outside code, after a blank line (or making up the whole
|
|
102
|
+
* summary), in which every line is a field line or continues one, and which holds an `outcome:` line
|
|
103
|
+
* and at least one other field. When the completion carries an outcome, the echoed line must name
|
|
104
|
+
* that same outcome, so an answer that ends on "Tests: 12 passed" and "Output: dist/" is not an echo.
|
|
105
|
+
* A summary that shows the fields in a code block is left as written. When the block is the whole
|
|
106
|
+
* summary, its `summary:` field, with the lines under it, becomes the answer.
|
|
107
|
+
*/
|
|
108
|
+
export declare function stripEchoedEnvelope(summary: string, outcome: string | undefined, notes?: string[]): string;
|
|
67
109
|
/**
|
|
68
110
|
* Parse one completion, accepting mechanically imperfect envelopes that are semantically correct.
|
|
69
111
|
*
|
package/dist/src/completion.js
CHANGED
|
@@ -265,7 +265,8 @@ function parseCompletionJson(text, stopReason, notes) {
|
|
|
265
265
|
* line breaks belong, and the transcript draws its markdown as one literal paragraph.
|
|
266
266
|
*
|
|
267
267
|
* Two shapes are decoded. A summary escaped throughout has no real line break and at least two
|
|
268
|
-
* escaped paragraph breaks
|
|
268
|
+
* escaped paragraph breaks, or at least two escaped breaks outside code that open markdown
|
|
269
|
+
* structure (one paragraph break and a list is enough); every escape in it is undone. A model can also switch to the extra
|
|
269
270
|
* escaping partway through, leaving a few real line breaks and the rest escaped: one `## heading`
|
|
270
271
|
* then swallows everything after it. That mixed summary is decoded only when at least two escaped
|
|
271
272
|
* breaks outside code open markdown structure (a heading, list item, quote, table, fence, or a
|
|
@@ -278,7 +279,9 @@ function parseCompletionJson(text, stopReason, notes) {
|
|
|
278
279
|
*/
|
|
279
280
|
export function decodeDoubleEscapedSummary(summary, notes) {
|
|
280
281
|
if (!summary.includes('\n')) {
|
|
281
|
-
|
|
282
|
+
// One escaped paragraph break followed by an escaped list ("Done.\n\nReport:\n- a\n- b") is as
|
|
283
|
+
// clearly layout as two paragraph breaks, so escaped structure outside code counts too.
|
|
284
|
+
if ((summary.match(/\\n\\n/g)?.length ?? 0) < 2 && escapedStructureCount(summary) < 2)
|
|
282
285
|
return summary;
|
|
283
286
|
notes?.push('completion summary arrived with its newlines escaped twice and was decoded');
|
|
284
287
|
const decoded = { n: '\n', r: '\r', t: '\t', '"': '"', '\\': '\\' };
|
|
@@ -307,6 +310,15 @@ export function decodeDoubleEscapedSummary(summary, notes) {
|
|
|
307
310
|
// `\\` is matched as a unit and kept, so an escaped backslash before an "n" is never read as a break.
|
|
308
311
|
return mapOutsideCode(summary, (prose, line) => prose.replace(/\\(\\|n|")/g, (escape, char) => char === '"' ? '"' : char === 'n' && structuralLines.has(line) ? '\n' : escape));
|
|
309
312
|
}
|
|
313
|
+
/** How many escaped breaks outside code open markdown structure, as the mixed-summary scan counts them. */
|
|
314
|
+
function escapedStructureCount(summary) {
|
|
315
|
+
let count = 0;
|
|
316
|
+
mapOutsideCode(summary, (prose, _line, beforeCode) => {
|
|
317
|
+
count += (beforeCode ? `${prose}\`` : prose).match(ESCAPED_STRUCTURE)?.length ?? 0;
|
|
318
|
+
return prose;
|
|
319
|
+
});
|
|
320
|
+
return count;
|
|
321
|
+
}
|
|
310
322
|
/**
|
|
311
323
|
* An escaped break that stands for markdown structure: a whole run of `\n` before a block opener,
|
|
312
324
|
* or a whole run of two or more before text. "Regex \n\n matches" (a run before a space) is prose,
|
|
@@ -558,6 +570,135 @@ function rejectEmbeddedEnvelope(summary) {
|
|
|
558
570
|
throw new Error(`Completion summary contains the completion envelope itself (its "${field}" field and what follows were written inside the summary string). Send summary, tests, outcome and output as separate complete_agent arguments: summary holds only the answer text in markdown, with no JSON fields after it.`);
|
|
559
571
|
return summary;
|
|
560
572
|
}
|
|
573
|
+
/** Where a completion envelope written as text could begin. */
|
|
574
|
+
const ENVELOPE_START = /\{\s*"summary"\s*:/g;
|
|
575
|
+
/**
|
|
576
|
+
* Replace a completion envelope a model wrote as message text, so the transcript never shows raw
|
|
577
|
+
* JSON. Two live shapes, both glm-5.3-flash on GX10:
|
|
578
|
+
* - Run 3a8378f0 ended a QA report with "Submitting the report." and then the whole envelope as
|
|
579
|
+
* text, `{"summary":"…\n\n## 1. Target…","tests":[…],"prUrl":"…"}`, about 12 KB, instead of
|
|
580
|
+
* calling complete_agent. The runtime rightly sent it back; the caller passes a `note` saying so,
|
|
581
|
+
* which stands in for the envelope (the report itself arrives later through complete_agent).
|
|
582
|
+
* - Session bbedcfbf narrated beside its tool calls as `{"summary":"Starting the PR comment fixer
|
|
583
|
+
* round…","tests":[]}`. With no `note`, the envelope's summary stands in for it, decoded like a
|
|
584
|
+
* completion's, so the narration still reads as prose.
|
|
585
|
+
*
|
|
586
|
+
* Only an envelope that ends the text is replaced: a JSON object whose `summary` is a string, which
|
|
587
|
+
* parses on its own from its opening brace to the end of the text (closing brackets the model left
|
|
588
|
+
* off are supplied, as for a completion), bare or as the whole of a final fenced block. One shown in
|
|
589
|
+
* inline code, one followed by more prose, and otherwise malformed JSON are left as written.
|
|
590
|
+
*/
|
|
591
|
+
export function withoutTrailingEnvelope(text, note) {
|
|
592
|
+
for (const match of text.matchAll(ENVELOPE_START)) {
|
|
593
|
+
let before = text.slice(0, match.index);
|
|
594
|
+
let rest = text.slice(match.index).trimEnd();
|
|
595
|
+
const fence = /(?:^|\n) {0,3}(`{3,}|~{3,})[\w-]*[ \t]*\n$/.exec(before);
|
|
596
|
+
if (fence) {
|
|
597
|
+
const closer = new RegExp(`\\n {0,3}${fence[1][0] === '`' ? '`' : '~'}{${fence[1].length},}$`).exec(rest);
|
|
598
|
+
if (!closer)
|
|
599
|
+
continue;
|
|
600
|
+
rest = rest.slice(0, closer.index);
|
|
601
|
+
before = before.slice(0, fence.index);
|
|
602
|
+
}
|
|
603
|
+
// The parser closes an envelope the model left one or two brackets short, which is how run
|
|
604
|
+
// 3a8378f0 ended (its `output` object never closed). Its other repair, dropping text after a
|
|
605
|
+
// whole envelope, is refused here: prose after the JSON means the envelope does not end the text.
|
|
606
|
+
let value;
|
|
607
|
+
const repairs = [];
|
|
608
|
+
try {
|
|
609
|
+
value = parseCompletionJson(rest, undefined, repairs);
|
|
610
|
+
}
|
|
611
|
+
catch {
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
if (repairs.some(note => note.includes('after its closing brace')))
|
|
615
|
+
continue;
|
|
616
|
+
const summary = value && typeof value === 'object' && !Array.isArray(value) ? value.summary : undefined;
|
|
617
|
+
if (typeof summary !== 'string')
|
|
618
|
+
continue;
|
|
619
|
+
return [before.trimEnd(), note ?? decodeDoubleEscapedSummary(summary).trim()].filter(Boolean).join('\n\n');
|
|
620
|
+
}
|
|
621
|
+
return text;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* A completion field the model echoed as a plain-text line at the end of its summary
|
|
625
|
+
* (`outcome: completed`). Bold or backticked keys (`**tests:**`, `` `outcome`: ``) count too, but a
|
|
626
|
+
* backtick must close right after the key: `` `outcome: completed` `` is an example in inline code,
|
|
627
|
+
* not an echoed field.
|
|
628
|
+
*/
|
|
629
|
+
const ECHOED_FIELD_LINE = /^\s*(?:[-*+]\s+)?(?:\*\*|__)?(?:`(summary|tests|outcome|output|artifacts|remaining)`|(summary|tests|outcome|output|artifacts|remaining))(?:\*\*|__)?\s*:(?:\*\*|__)?\s*(.*)$/i;
|
|
630
|
+
/** A line that continues the echoed field above it: a list item or indented text under `tests:`. */
|
|
631
|
+
const ECHOED_CONTINUATION = /^\s*(?:[-*+]\s|\d+[.)]\s|\s{2,}\S)/;
|
|
632
|
+
/**
|
|
633
|
+
* Remove the completion fields a model copied into the end of its summary as text. Some models
|
|
634
|
+
* call complete_agent with every field set and then also write the same fields out under the
|
|
635
|
+
* answer:
|
|
636
|
+
*
|
|
637
|
+
* Browser is open.
|
|
638
|
+
*
|
|
639
|
+
* summary: Browser panel opened successfully on example.com.
|
|
640
|
+
* tests: none — no checks were required.
|
|
641
|
+
* outcome: completed
|
|
642
|
+
* output: {}
|
|
643
|
+
*
|
|
644
|
+
* The transcript draws the summary as the answer, so those lines reached the user as a raw field
|
|
645
|
+
* dump. Unlike an embedded JSON envelope (`rejectEmbeddedEnvelope`), the arguments themselves are
|
|
646
|
+
* intact, so there is nothing for a retry to repair: the trailing block is dropped and recorded.
|
|
647
|
+
*
|
|
648
|
+
* Only a block at the very end is touched, outside code, after a blank line (or making up the whole
|
|
649
|
+
* summary), in which every line is a field line or continues one, and which holds an `outcome:` line
|
|
650
|
+
* and at least one other field. When the completion carries an outcome, the echoed line must name
|
|
651
|
+
* that same outcome, so an answer that ends on "Tests: 12 passed" and "Output: dist/" is not an echo.
|
|
652
|
+
* A summary that shows the fields in a code block is left as written. When the block is the whole
|
|
653
|
+
* summary, its `summary:` field, with the lines under it, becomes the answer.
|
|
654
|
+
*/
|
|
655
|
+
export function stripEchoedEnvelope(summary, outcome, notes) {
|
|
656
|
+
const lines = summary.replace(/\s+$/, '').split('\n');
|
|
657
|
+
const code = codeBlockLines(lines);
|
|
658
|
+
const fields = new Set();
|
|
659
|
+
let echoedSummary;
|
|
660
|
+
let echoedOutcome;
|
|
661
|
+
let start = lines.length;
|
|
662
|
+
let sawField = false;
|
|
663
|
+
// Lines under the field above them, collected while scanning upward until that field is reached.
|
|
664
|
+
let continuation = [];
|
|
665
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
666
|
+
const line = lines[index];
|
|
667
|
+
if (line.trim() === '')
|
|
668
|
+
break;
|
|
669
|
+
if (code[index])
|
|
670
|
+
return summary;
|
|
671
|
+
const field = ECHOED_FIELD_LINE.exec(line);
|
|
672
|
+
if (field) {
|
|
673
|
+
const key = (field[1] ?? field[2]).toLowerCase();
|
|
674
|
+
fields.add(key);
|
|
675
|
+
if (key === 'summary')
|
|
676
|
+
echoedSummary = [field[3], ...continuation].join('\n').trim();
|
|
677
|
+
if (key === 'outcome')
|
|
678
|
+
echoedOutcome = field[3].replace(/[`*_"'.]/g, '').trim().toLowerCase();
|
|
679
|
+
sawField = true;
|
|
680
|
+
continuation = [];
|
|
681
|
+
}
|
|
682
|
+
else if (ECHOED_CONTINUATION.test(line))
|
|
683
|
+
continuation.unshift(line);
|
|
684
|
+
else
|
|
685
|
+
return summary;
|
|
686
|
+
start = index;
|
|
687
|
+
}
|
|
688
|
+
// The block's first line must be a field: a list that only continues prose above is not an echo.
|
|
689
|
+
if (!sawField || !ECHOED_FIELD_LINE.test(lines[start] ?? ''))
|
|
690
|
+
return summary;
|
|
691
|
+
if (fields.size < 2 || echoedOutcome === undefined)
|
|
692
|
+
return summary;
|
|
693
|
+
if (outcome !== undefined && echoedOutcome !== outcome.toLowerCase())
|
|
694
|
+
return summary;
|
|
695
|
+
const kept = lines.slice(0, start).join('\n').replace(/\s+$/, '');
|
|
696
|
+
const answer = kept || echoedSummary?.replace(/^\*\*|\*\*$/g, '').trim();
|
|
697
|
+
if (!answer)
|
|
698
|
+
return summary;
|
|
699
|
+
notes?.push(`completion summary ended with its own ${[...fields].join(', ')} fields written out as text, removed by the host`);
|
|
700
|
+
return answer;
|
|
701
|
+
}
|
|
561
702
|
/**
|
|
562
703
|
* Parse one completion, accepting mechanically imperfect envelopes that are semantically correct.
|
|
563
704
|
*
|
|
@@ -641,14 +782,14 @@ export function parseCompletion(text, options, reject, notes, stopReason) {
|
|
|
641
782
|
// serialized, and an output field named `tests` is legitimate there.
|
|
642
783
|
if (written === undefined)
|
|
643
784
|
notes?.push(OUTPUT_STOOD_IN_NOTE);
|
|
644
|
-
const summary = written === undefined ? decodeDoubleEscapedSummary(JSON.stringify(output).slice(0, 2000), notes) : rejectEmbeddedEnvelope(decodeDoubleEscapedSummary(written, notes));
|
|
785
|
+
const summary = written === undefined ? decodeDoubleEscapedSummary(JSON.stringify(output).slice(0, 2000), notes) : stripEchoedEnvelope(rejectEmbeddedEnvelope(decodeDoubleEscapedSummary(written, notes)), outcome, notes);
|
|
645
786
|
return { summary,
|
|
646
787
|
tests: Array.isArray(value.tests) && value.tests.every((item) => typeof item === 'string') ? value.tests : [], outcome, output,
|
|
647
788
|
artifacts: value.artifacts ?? [], ...(remainingItems(value.remaining) ? { remaining: remainingItems(value.remaining) } : {}) };
|
|
648
789
|
}
|
|
649
790
|
if (value && typeof value.summary === 'string' && value.summary.trim()
|
|
650
791
|
&& Array.isArray(value.tests) && value.tests.every((x) => typeof x === 'string')) {
|
|
651
|
-
return { summary: rejectEmbeddedEnvelope(decodeDoubleEscapedSummary(value.summary, notes)), tests: value.tests };
|
|
792
|
+
return { summary: stripEchoedEnvelope(rejectEmbeddedEnvelope(decodeDoubleEscapedSummary(value.summary, notes)), typeof value.outcome === "string" ? value.outcome : undefined, notes), tests: value.tests };
|
|
652
793
|
}
|
|
653
794
|
throw new Error("Completion needs a nonempty summary and a tests array of strings");
|
|
654
795
|
}
|
package/dist/src/config.d.ts
CHANGED
package/dist/src/config.js
CHANGED
|
@@ -128,6 +128,8 @@ export function validateConfig(value) {
|
|
|
128
128
|
throw new Error('jevEnabled must be a boolean');
|
|
129
129
|
if (c.commandMemory !== undefined && typeof c.commandMemory !== 'boolean')
|
|
130
130
|
throw new Error('commandMemory must be a boolean');
|
|
131
|
+
if (c.projectMemory !== undefined && typeof c.projectMemory !== 'boolean')
|
|
132
|
+
throw new Error('projectMemory must be a boolean');
|
|
131
133
|
if (c.systemPromptOverride !== undefined && (typeof c.systemPromptOverride !== 'string' || !c.systemPromptOverride.trim() || c.systemPromptOverride.length > MAX_SYSTEM_PROMPT_OVERRIDE)) {
|
|
132
134
|
throw new Error(`systemPromptOverride must be nonempty text of up to ${MAX_SYSTEM_PROMPT_OVERRIDE} characters`);
|
|
133
135
|
}
|
|
@@ -7,7 +7,7 @@ const kinds = ['investigate', 'retry', 'change_strategy', 'verify', 'complete'];
|
|
|
7
7
|
const triggerKinds = new Set(['investigate', 'verify']);
|
|
8
8
|
// Landing or dropping a delegated change is a decision taken after reviewing it, so neither can be
|
|
9
9
|
// prepared ahead and run before the review.
|
|
10
|
-
const forbidden = new Set([PREPARE_STEPS, 'complete_agent', 'update_todos', 'ask_user', 'spawn_subagent', 'accept_change', 'discard_change']);
|
|
10
|
+
const forbidden = new Set([PREPARE_STEPS, 'complete_agent', 'update_todos', 'ask_user', 'spawn_subagent', 'accept_change', 'discard_change', 'remove_untracked_file']);
|
|
11
11
|
const object = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
12
12
|
export function boundedDecisionText(text, bytes) {
|
|
13
13
|
const value = redactSecrets(text).text;
|
|
@@ -10,6 +10,7 @@ import { promisify } from 'node:util';
|
|
|
10
10
|
import { chmod, copyFile, lstat, mkdir, mkdtemp, readFile, readdir, readlink, realpath, rm, rmdir, symlink, writeFile } from 'node:fs/promises';
|
|
11
11
|
import { tmpdir } from 'node:os';
|
|
12
12
|
import { basename, dirname, join } from 'node:path';
|
|
13
|
+
import { isWindowsDeviceName } from './stray-files.js';
|
|
13
14
|
const exec = promisify(execFile);
|
|
14
15
|
/** Characters of a change's diff that are inlined into the spawn observation. */
|
|
15
16
|
export const DELEGATION_DIFF_LIMIT = 20_000;
|
|
@@ -26,7 +27,9 @@ const REMOVE_RETRIES = { maxRetries: 5, retryDelay: 100 };
|
|
|
26
27
|
// repository must not get to run its own programs because a subagent was spawned. safecrlf is off
|
|
27
28
|
// because a snapshot takes the files as they are: with `core.safecrlf=true` Git refuses to add a
|
|
28
29
|
// file whose line endings its own conversion would change, and the snapshot would fail.
|
|
29
|
-
|
|
30
|
+
// longpaths is on because one file whose path is over Windows' 260 characters would otherwise fail
|
|
31
|
+
// the snapshot, and with it every delegation, until the user removed the file by hand.
|
|
32
|
+
const HARDENED = ['-c', 'core.hooksPath=', '-c', 'core.fsmonitor=false', '-c', 'core.safecrlf=false', '-c', 'core.longpaths=true'];
|
|
30
33
|
// Patches are made with the diff-tree plumbing, not porcelain `git diff`: porcelain honours the
|
|
31
34
|
// user's diff.noprefix, diff.external, colour and textconv settings, any of which turns a clean
|
|
32
35
|
// merge into a patch `git apply` rejects or rewrites. Plumbing ignores them by default; the
|
|
@@ -76,10 +79,24 @@ const RUNTIME_FILES = ':(exclude,glob)**/.andorra/runtime/**';
|
|
|
76
79
|
async function writeWorkingTree(root, start, signal) {
|
|
77
80
|
return withTemporaryIndex(async (env) => {
|
|
78
81
|
await git(root, ['read-tree', start], { signal, env });
|
|
79
|
-
await
|
|
82
|
+
const unreadable = await deviceNamedFiles(root, env, signal);
|
|
83
|
+
await git(root, ['add', '-A', '--', '.', RUNTIME_FILES, ...unreadable.map(path => `:(exclude,literal)${path}`)], { signal, env, timeout: BULK_TIMEOUT_MS, maxBuffer: ADD_MAX_BUFFER });
|
|
80
84
|
return (await git(root, ['write-tree'], { signal, env })).trim();
|
|
81
85
|
});
|
|
82
86
|
}
|
|
87
|
+
// More names than this are left in: the exclusions travel on the command line, which Windows bounds.
|
|
88
|
+
const DEVICE_NAMED_LIMIT = 100;
|
|
89
|
+
/**
|
|
90
|
+
* Untracked files Windows reads as a device (`nul`, `con`), which Git cannot open there: adding one
|
|
91
|
+
* fails the whole `git add`. Such a file is a shell accident, never work, and nothing on Windows can
|
|
92
|
+
* write one through an ordinary path, so every tree made here leaves it out the same way.
|
|
93
|
+
*/
|
|
94
|
+
async function deviceNamedFiles(root, env, signal) {
|
|
95
|
+
if (process.platform !== 'win32')
|
|
96
|
+
return [];
|
|
97
|
+
const untracked = await git(root, ['ls-files', '-o', '--exclude-standard', '-z', '--', '.', RUNTIME_FILES], { signal, env, timeout: BULK_TIMEOUT_MS, maxBuffer: ADD_MAX_BUFFER });
|
|
98
|
+
return untracked.split('\0').filter(path => path && path.split('/').some(isWindowsDeviceName)).slice(0, DEVICE_NAMED_LIMIT);
|
|
99
|
+
}
|
|
83
100
|
/** A dangling commit holding `tree`; it is never referenced by a ref. */
|
|
84
101
|
async function commitTree(root, tree, parent, message, signal) {
|
|
85
102
|
return (await git(root, ['commit-tree', tree, '-p', parent, '-m', message], { signal, env: SNAPSHOT_IDENTITY })).trim();
|
|
@@ -2,5 +2,6 @@ export interface FileChangePreview {
|
|
|
2
2
|
text: string;
|
|
3
3
|
detail?: string;
|
|
4
4
|
}
|
|
5
|
+
export declare function registerEditArgumentPreparer(prepare: ((args: Record<string, unknown>) => unknown) | undefined): void;
|
|
5
6
|
/** Proposed tool arguments only: writes may overwrite an existing file. */
|
|
6
7
|
export declare function formatFileChange(name: string, args: Record<string, unknown>): FileChangePreview | undefined;
|
package/dist/src/diff-preview.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { stripVTControlCharacters } from 'node:util';
|
|
2
2
|
import { clipText } from './text.js';
|
|
3
3
|
import { canonicalToolName } from './tool-names.js';
|
|
4
|
-
import { andorraCreateEditTool } from '../vendor/engine/runtime/coding-agent/core/tools/edit.js';
|
|
5
4
|
const PREVIEW_LINES = 12;
|
|
6
5
|
const DETAIL_LINES = 200;
|
|
7
6
|
const LINE_WIDTH = 300;
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The edit tool's own argument normalizer, registered by the coding tools when they load.
|
|
9
|
+
*
|
|
10
|
+
* Importing the vendored edit tool here would load its schema library with every transcript
|
|
11
|
+
* renderer, including the first terminal frame. An `edit` call only exists once the coding tools
|
|
12
|
+
* have been created, and they register the normalizer as they load, so a preview never needs it
|
|
13
|
+
* earlier; a call rendered before that (a resumed transcript) previews its arguments as written.
|
|
14
|
+
*/
|
|
15
|
+
let prepareEditArguments;
|
|
16
|
+
export function registerEditArgumentPreparer(prepare) {
|
|
17
|
+
prepareEditArguments = prepare;
|
|
18
|
+
}
|
|
10
19
|
/** Keep file content from controlling the terminal or disguising diff markers. */
|
|
11
20
|
function printable(value) {
|
|
12
21
|
return stripVTControlCharacters(value)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vendored provider SDK adapters, loaded on the first model request instead of at startup.
|
|
3
|
+
*
|
|
4
|
+
* Each adapter imports its vendor SDK (`openai`, `@anthropic-ai/sdk`, `@google/genai` and the
|
|
5
|
+
* Google auth stack behind it), several hundred files between them. Nothing before the first model
|
|
6
|
+
* call needs them, so importing them statically made every launch — including `andorra --version`
|
|
7
|
+
* and the first terminal frame — wait for the whole set to resolve and compile. The promise is
|
|
8
|
+
* shared, so concurrent first requests load the set once.
|
|
9
|
+
*/
|
|
10
|
+
type Completions = typeof import('../vendor/engine/runtime/ai/api/openai-completions.js');
|
|
11
|
+
type Responses = typeof import('../vendor/engine/runtime/ai/api/openai-responses.js');
|
|
12
|
+
type Messages = typeof import('../vendor/engine/runtime/ai/api/anthropic-messages.js');
|
|
13
|
+
type GoogleShared = typeof import('../vendor/engine/runtime/ai/api/google-shared.js');
|
|
14
|
+
export interface EngineStreams {
|
|
15
|
+
chatStream: Completions['andorraStream'];
|
|
16
|
+
responsesStream: Responses['andorraStream'];
|
|
17
|
+
messagesStream: Messages['andorraStream'];
|
|
18
|
+
convertGoogleMessages: GoogleShared['andorraConvertMessages'];
|
|
19
|
+
convertGoogleTools: GoogleShared['andorraConvertTools'];
|
|
20
|
+
}
|
|
21
|
+
export declare function loadEngineStreams(): Promise<EngineStreams>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
let loading;
|
|
2
|
+
export function loadEngineStreams() {
|
|
3
|
+
loading ??= Promise.all([
|
|
4
|
+
import('../vendor/engine/runtime/ai/api/openai-completions.js'),
|
|
5
|
+
import('../vendor/engine/runtime/ai/api/openai-responses.js'),
|
|
6
|
+
import('../vendor/engine/runtime/ai/api/anthropic-messages.js'),
|
|
7
|
+
import('../vendor/engine/runtime/ai/api/google-shared.js'),
|
|
8
|
+
]).then(([completions, responses, messages, google]) => ({
|
|
9
|
+
chatStream: completions.andorraStream,
|
|
10
|
+
responsesStream: responses.andorraStream,
|
|
11
|
+
messagesStream: messages.andorraStream,
|
|
12
|
+
convertGoogleMessages: google.andorraConvertMessages,
|
|
13
|
+
convertGoogleTools: google.andorraConvertTools,
|
|
14
|
+
}), error => { loading = undefined; throw error; });
|
|
15
|
+
return loading;
|
|
16
|
+
}
|
package/dist/src/extensions.js
CHANGED
|
@@ -9,6 +9,7 @@ import { acquireSaveLock, SaveLockBusyError } from './save-lock.js';
|
|
|
9
9
|
import { configDirectory, validateMcpServer } from './config.js';
|
|
10
10
|
export { validateMcpServer } from './config.js';
|
|
11
11
|
import { resolveBuiltinSkill } from './skills/invocable-skills.js';
|
|
12
|
+
import { bundledSkillCatalog, bundledSkillDirectory } from './skills/runtime-skills.js';
|
|
12
13
|
import { isBuiltinSlashCommand } from './skill-commands.js';
|
|
13
14
|
const unzip = promisify(gunzip);
|
|
14
15
|
const MAX_ARCHIVE_BYTES = 64 * 1024 * 1024;
|
|
@@ -539,12 +540,22 @@ export async function installBundle(kind, source, config, signal, directory = co
|
|
|
539
540
|
await rm(stage, { recursive: true, force: true });
|
|
540
541
|
}
|
|
541
542
|
}
|
|
542
|
-
async function skillEntry(id, config, directory,
|
|
543
|
+
async function skillEntry(id, config, directory, allowBuiltin = false) {
|
|
543
544
|
skillIdValid(id);
|
|
544
|
-
const found = (await listBundles('skills', config, { directory
|
|
545
|
-
if (
|
|
545
|
+
const found = (await listBundles('skills', config, { directory })).find(item => item.id === id);
|
|
546
|
+
if (found)
|
|
547
|
+
return found;
|
|
548
|
+
// Andorra's own skills are not installed bundles, but their files ship with this package; serving
|
|
549
|
+
// them keeps a client's skill view consistent with what a run can load. Only listing and reading
|
|
550
|
+
// resolve them; writes and removals stay installed-only, so a client cannot edit files inside
|
|
551
|
+
// this package.
|
|
552
|
+
if (!allowBuiltin)
|
|
546
553
|
throw new Error('Skill is unavailable');
|
|
547
|
-
|
|
554
|
+
const base = bundledSkillDirectory(id);
|
|
555
|
+
if (!base)
|
|
556
|
+
throw new Error('Skill is unavailable');
|
|
557
|
+
const catalog = bundledSkillCatalog().find(item => item.id === id);
|
|
558
|
+
return { id, name: id.split(':').at(-1) ?? id, description: catalog?.description ?? 'Built-in skill', enabled: true, path: base };
|
|
548
559
|
}
|
|
549
560
|
function resourceTarget(skill, path) {
|
|
550
561
|
if (!path || isAbsolute(path) || /[\0]/.test(path))
|
|
@@ -556,7 +567,7 @@ function resourceTarget(skill, path) {
|
|
|
556
567
|
return { base, target };
|
|
557
568
|
}
|
|
558
569
|
export async function listSkillResources(id, config, directory = configDirectory()) {
|
|
559
|
-
const skill = await skillEntry(id, config, directory);
|
|
570
|
+
const skill = await skillEntry(id, config, directory, true);
|
|
560
571
|
const paths = [];
|
|
561
572
|
let count = 0;
|
|
562
573
|
const base = skill.repository?.path ?? skill.path;
|
|
@@ -578,7 +589,7 @@ export async function listSkillResources(id, config, directory = configDirectory
|
|
|
578
589
|
return paths.sort();
|
|
579
590
|
}
|
|
580
591
|
export async function readSkillResource(id, path, config, directory = configDirectory()) {
|
|
581
|
-
const skill = await skillEntry(id, config, directory);
|
|
592
|
+
const skill = await skillEntry(id, config, directory, true);
|
|
582
593
|
const { base, target } = resourceTarget(skill, path);
|
|
583
594
|
return boundedRead(target, base, undefined, MAX_SKILL_DOCUMENT_BYTES);
|
|
584
595
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The key a file-read record is stored under: the resolved path, case-folded on Windows.
|
|
3
|
+
*
|
|
4
|
+
* Kept free of imports so producers of the same state (the CodeGraph complete-source seed) can
|
|
5
|
+
* share the canonical tools' key without loading the tools themselves. It must be applied to a path
|
|
6
|
+
* normalized the same way the policy's safePath normalizes it, or the entries never match.
|
|
7
|
+
*/
|
|
8
|
+
export declare function stateKey(resolved: string): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* The key a file-read record is stored under: the resolved path, case-folded on Windows.
|
|
4
|
+
*
|
|
5
|
+
* Kept free of imports so producers of the same state (the CodeGraph complete-source seed) can
|
|
6
|
+
* share the canonical tools' key without loading the tools themselves. It must be applied to a path
|
|
7
|
+
* normalized the same way the policy's safePath normalizes it, or the entries never match.
|
|
8
|
+
*/
|
|
9
|
+
export function stateKey(resolved) {
|
|
10
|
+
const key = path.resolve(resolved);
|
|
11
|
+
return process.platform === 'win32' ? key.toLowerCase() : key;
|
|
12
|
+
}
|