@andorra-labs/code 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/account-presentation.js +3 -3
- package/dist/src/agent-execution.d.ts +2 -0
- package/dist/src/agent-execution.js +126 -20
- package/dist/src/agent-mcp.d.ts +18 -1
- package/dist/src/agent-mcp.js +103 -8
- package/dist/src/app-server/protocol.d.ts +33 -3
- package/dist/src/app-server/protocol.js +14 -1
- package/dist/src/app-server/workspace.d.ts +1 -0
- package/dist/src/app-server/workspace.js +7 -1
- package/dist/src/app-server.d.ts +115 -41
- package/dist/src/app-server.js +1229 -219
- package/dist/src/automation-runner.d.ts +9 -0
- package/dist/src/automation-runner.js +22 -1
- package/dist/src/automation-tool.js +8 -1
- package/dist/src/automations.js +1 -1
- package/dist/src/browser-captcha-tool.d.ts +54 -0
- package/dist/src/browser-captcha-tool.js +374 -0
- package/dist/src/browser-panel-tool.d.ts +7 -0
- package/dist/src/browser-panel-tool.js +74 -3
- package/dist/src/browser-runner.js +19 -4
- package/dist/src/browser-server.js +21 -1
- package/dist/src/browser-session.d.ts +16 -0
- package/dist/src/browser-session.js +35 -0
- package/dist/src/browser-ui/app.js +193 -3
- package/dist/src/browser-ui/style.css +15 -1
- package/dist/src/browser-view.d.ts +72 -4
- package/dist/src/browser-view.js +229 -17
- package/dist/src/capabilities.js +13 -2
- package/dist/src/capsolver.d.ts +60 -0
- package/dist/src/capsolver.js +101 -0
- package/dist/src/claude-provider.d.ts +6 -0
- package/dist/src/claude-provider.js +34 -3
- package/dist/src/cli-executable.d.ts +33 -0
- package/dist/src/cli-executable.js +64 -0
- package/dist/src/cli-process.d.ts +47 -0
- package/dist/src/cli-process.js +113 -0
- package/dist/src/cli-sign-in.d.ts +68 -0
- package/dist/src/cli-sign-in.js +224 -0
- package/dist/src/cli.js +53 -22
- package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +1 -1
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +5 -5
- package/dist/src/coding-tools.js +44 -5
- package/dist/src/command-output-tap.d.ts +16 -0
- package/dist/src/command-output-tap.js +45 -0
- package/dist/src/command-screens.js +3 -3
- package/dist/src/commands.d.ts +10 -1
- package/dist/src/commands.js +7 -7
- package/dist/src/completion.d.ts +23 -5
- package/dist/src/completion.js +334 -17
- package/dist/src/config.d.ts +13 -0
- package/dist/src/config.js +28 -2
- package/dist/src/deadline.js +6 -0
- package/dist/src/extensions.d.ts +1 -0
- package/dist/src/extensions.js +16 -3
- package/dist/src/graph-provider-portability.js +2 -2
- package/dist/src/graph-quota.d.ts +1 -1
- package/dist/src/graph-quota.js +1 -1
- package/dist/src/graph-runner.js +35 -21
- package/dist/src/graph-selection.d.ts +6 -0
- package/dist/src/graph-selection.js +10 -0
- package/dist/src/graph-server.d.ts +7 -0
- package/dist/src/graph-server.js +61 -3
- package/dist/src/graph-sync.d.ts +50 -0
- package/dist/src/graph-sync.js +383 -12
- package/dist/src/graph-ui/app.js +61 -8
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graph-ui/skill-picker.js +242 -0
- package/dist/src/graph-ui/style.css +19 -0
- package/dist/src/graphs.d.ts +46 -4
- package/dist/src/graphs.js +152 -27
- package/dist/src/grok-provider.d.ts +50 -0
- package/dist/src/grok-provider.js +186 -0
- package/dist/src/handoffs.d.ts +13 -0
- package/dist/src/handoffs.js +31 -1
- package/dist/src/managed-sign-in.d.ts +38 -0
- package/dist/src/managed-sign-in.js +169 -0
- package/dist/src/markdown.d.ts +5 -0
- package/dist/src/markdown.js +5 -2
- package/dist/src/mcp.js +11 -0
- package/dist/src/membership.d.ts +8 -1
- package/dist/src/membership.js +15 -5
- package/dist/src/model-metadata.js +14 -2
- package/dist/src/model-override.d.ts +10 -0
- package/dist/src/model-override.js +20 -0
- package/dist/src/opencode-cli-provider.d.ts +122 -0
- package/dist/src/opencode-cli-provider.js +415 -0
- package/dist/src/opencode-provider.js +23 -8
- package/dist/src/palette.d.ts +2 -0
- package/dist/src/palette.js +2 -0
- package/dist/src/permissions.d.ts +19 -1
- package/dist/src/permissions.js +30 -1
- package/dist/src/powershell-pool.d.ts +2 -2
- package/dist/src/powershell-pool.js +18 -5
- package/dist/src/provider-connection.js +36 -0
- package/dist/src/provider-engine.d.ts +2 -1
- package/dist/src/provider-engine.js +64 -13
- package/dist/src/provider-import.js +6 -1
- package/dist/src/provider-settings.js +22 -3
- package/dist/src/providers.d.ts +12 -1
- package/dist/src/providers.js +27 -8
- package/dist/src/pull-requests.d.ts +111 -17
- package/dist/src/pull-requests.js +308 -76
- package/dist/src/qa/qa-authorize.js +9 -1
- package/dist/src/react-runtime.js +76 -5
- package/dist/src/remote/engine-pool.js +1 -1
- package/dist/src/run-progress.js +6 -1
- package/dist/src/run-records.d.ts +133 -27
- package/dist/src/run-records.js +320 -40
- package/dist/src/runtime.d.ts +38 -1
- package/dist/src/runtime.js +27 -4
- package/dist/src/save-lock.d.ts +11 -0
- package/dist/src/save-lock.js +29 -2
- package/dist/src/sessions.js +4 -1
- package/dist/src/shell.js +4 -1
- package/dist/src/side-panel.d.ts +1 -1
- package/dist/src/side-panel.js +1 -1
- package/dist/src/skill-commands.d.ts +2 -0
- package/dist/src/skill-commands.js +2 -0
- package/dist/src/skills/bundled/create-agent/SKILL.md +81 -0
- package/dist/src/skills/bundled/create-skill/SKILL.md +81 -0
- package/dist/src/skills/bundled/doctor/SKILL.md +43 -0
- package/dist/src/skills/bundled/graph-manager/SKILL.md +97 -0
- package/dist/src/skills/bundled/graph-manager/errors.md +38 -0
- package/dist/src/skills/bundled/graph-manager/patterns.md +78 -0
- package/dist/src/skills/bundled/manage-mcp/SKILL.md +75 -0
- package/dist/src/skills/bundled/manage-mcp/probe.md +165 -0
- package/dist/src/skills/bundled/manage-skills/SKILL.md +67 -0
- package/dist/src/skills/bundled/provenance.json +50 -0
- package/dist/src/skills/bundled/write-instructions/SKILL.md +42 -0
- package/dist/src/skills/invocable-skills.d.ts +41 -0
- package/dist/src/skills/invocable-skills.js +49 -0
- package/dist/src/skills/prompt-skills.d.ts +1 -0
- package/dist/src/skills/prompt-skills.js +33 -0
- package/dist/src/skills/runtime-skills.d.ts +4 -0
- package/dist/src/skills/runtime-skills.js +21 -0
- package/dist/src/structured-step.d.ts +55 -0
- package/dist/src/structured-step.js +85 -0
- package/dist/src/subagent-run.d.ts +1 -1
- package/dist/src/subagent-run.js +29 -33
- package/dist/src/telemetry/schema.d.ts +2 -2
- package/dist/src/telemetry/schema.js +3 -2
- package/dist/src/terminal-ui.d.ts +29 -0
- package/dist/src/terminal-ui.js +112 -28
- package/dist/src/timers.d.ts +21 -2
- package/dist/src/timers.js +12 -4
- package/dist/src/tool-names.d.ts +18 -0
- package/dist/src/tool-names.js +26 -0
- package/dist/src/tools.js +45 -11
- package/dist/src/trajectory.js +32 -12
- package/dist/src/types.d.ts +23 -0
- package/docs/agents/mcp-server.md +13 -1
- package/docs/agents/subagent-mode.md +7 -4
- package/docs/concepts/security.md +2 -0
- package/docs/getting-started/configure-providers.md +29 -2
- package/docs/guides/browser.md +12 -0
- package/docs/guides/desktop-app.md +10 -3
- package/docs/guides/graph-builder.md +8 -0
- package/docs/reference/config.md +2 -2
- package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +125 -0
- package/docs/superpowers/specs/2026-11-01-pr-section-design.md +7 -0
- package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +206 -0
- package/package.json +1 -1
- package/tests/permissions-test-plan.md +2 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { monotonicNow } from './duration.js';
|
|
2
|
+
const FLUSH_INTERVAL_MS = 1_000;
|
|
3
|
+
/** What a quiet gap may queue between flushes: the tap carries the newest text, never all of it. */
|
|
4
|
+
const PENDING_LIMIT = 8_192;
|
|
5
|
+
export function createCommandOutputTap(emit, now = monotonicNow) {
|
|
6
|
+
let pending = '';
|
|
7
|
+
let timer;
|
|
8
|
+
// The first chunk flushes at once: a reader who expands a running call sees its opening output
|
|
9
|
+
// without waiting out an interval that began before anything printed.
|
|
10
|
+
let lastFlush = Number.NEGATIVE_INFINITY;
|
|
11
|
+
let stopped = false;
|
|
12
|
+
const flush = () => {
|
|
13
|
+
timer = undefined;
|
|
14
|
+
if (stopped || !pending)
|
|
15
|
+
return;
|
|
16
|
+
const chunk = pending;
|
|
17
|
+
pending = '';
|
|
18
|
+
lastFlush = now();
|
|
19
|
+
emit(chunk);
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
push(chunk) {
|
|
23
|
+
if (stopped || !chunk)
|
|
24
|
+
return;
|
|
25
|
+
pending += chunk;
|
|
26
|
+
if (pending.length > PENDING_LIMIT)
|
|
27
|
+
pending = pending.slice(-PENDING_LIMIT);
|
|
28
|
+
const since = now() - lastFlush;
|
|
29
|
+
if (timer === undefined && since >= FLUSH_INTERVAL_MS)
|
|
30
|
+
flush();
|
|
31
|
+
else if (timer === undefined) {
|
|
32
|
+
timer = setTimeout(flush, FLUSH_INTERVAL_MS - since);
|
|
33
|
+
timer.unref();
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
stop() {
|
|
37
|
+
stopped = true;
|
|
38
|
+
if (timer !== undefined) {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
timer = undefined;
|
|
41
|
+
}
|
|
42
|
+
pending = '';
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -4,7 +4,7 @@ import { editProviderSettings } from './provider-settings.js';
|
|
|
4
4
|
import { retireRemovedCodexAccounts, retireUnsavedCodexAccounts } from './codex-auth.js';
|
|
5
5
|
import { droppedAnthropicAccounts, retireAnthropicAccounts } from './anthropic-console-auth.js';
|
|
6
6
|
import { importProvidersFromRemote } from './provider-import.js';
|
|
7
|
-
import { DEFAULT_HARNESS, listGraphs } from './graphs.js';
|
|
7
|
+
import { DEFAULT_HARNESS, listGraphs, withoutDeletedGraphs } from './graphs.js';
|
|
8
8
|
import { graphStorageDirectory } from './graph-account.js';
|
|
9
9
|
import { configuredGraphSelection, currentGraphSubject, saveGraphSelection } from './graph-selection.js';
|
|
10
10
|
import { getMembership, loadAccessibleGraph, requireGraphMembership, ANDORRA_GRAPH_SELECTION } from './membership.js';
|
|
@@ -316,8 +316,8 @@ export async function runCommandScreen(line, state, ui, persist, signal, adapter
|
|
|
316
316
|
const items = [{
|
|
317
317
|
id: DEFAULT_HARNESS.id,
|
|
318
318
|
label: 'Default',
|
|
319
|
-
description: '
|
|
320
|
-
}, { id: ANDORRA_GRAPH_SELECTION, label: 'Andorra', description: free ? 'Premium workflow: Orchestrator ->
|
|
319
|
+
description: 'Andorra Agent only. Reads project instructions and completes the task without an Orchestrator.',
|
|
320
|
+
}, { id: ANDORRA_GRAPH_SELECTION, label: 'Andorra', description: free ? 'Premium workflow: Orchestrator -> Andorra Agent -> Done' : 'Paid workflow: Orchestrator -> Andorra Agent -> Done' }, ...withoutDeletedGraphs(saved).filter(graph => graph.id !== 'default').map(graph => ({ id: graph.id, label: `${graph.name} (${graph.id}@${graph.revision})`, description: 'Saved custom graph' })), { id: ':divider', label: '', separator: true }, { id: ':create', label: 'Create new graph', description: atLimit ? 'Free tier includes 1 custom graph. Upgrade to Premium for more graphs.' : 'Open the web graph builder' }, { id: ':edit', label: 'Edit Graphs', bold: true, description: 'Open saved graphs in the web graph builder' }];
|
|
321
321
|
while (!signal.aborted) {
|
|
322
322
|
const selected = await ui.select('Graph', items, { selectedId: state.graph ?? DEFAULT_HARNESS.id, description: 'Choose and save your default graph for this account, or create one in the web builder. After saving, reopen /graph to select it.', signal });
|
|
323
323
|
if (selected === undefined || signal.aborted)
|
package/dist/src/commands.d.ts
CHANGED
|
@@ -62,6 +62,12 @@ export interface ConversationTurn {
|
|
|
62
62
|
direction?: string;
|
|
63
63
|
/** Disk-backed attachments the turn was submitted with; the replay path re-references them by path. */
|
|
64
64
|
attachments?: import('./attachments.js').UserAttachmentRef[];
|
|
65
|
+
/**
|
|
66
|
+
* Set when this turn's opening message was delivered by a wake rather than sent by the user: the agent's
|
|
67
|
+
* own `set_timer` reminder (`timer`), or the review comments an Auto-fix wake brought (`auto-fix`).
|
|
68
|
+
* The text is the task, or the direction of a continued attempt; a client labels it as what it is.
|
|
69
|
+
*/
|
|
70
|
+
wake?: TurnWake;
|
|
65
71
|
/**
|
|
66
72
|
* The messages the user typed into the attempt while it was running, in the order it read them.
|
|
67
73
|
*
|
|
@@ -72,9 +78,12 @@ export interface ConversationTurn {
|
|
|
72
78
|
*/
|
|
73
79
|
steers?: {
|
|
74
80
|
text: string;
|
|
75
|
-
attachments?: import('./attachments.js').UserAttachmentRef[];
|
|
81
|
+
attachments?: import('./attachments.js').UserAttachmentRef[]; /** A wake's reminder read mid-run, not the user's message. */
|
|
82
|
+
wake?: TurnWake;
|
|
76
83
|
}[];
|
|
77
84
|
}
|
|
85
|
+
/** What delivered a turn's message instead of the user (see `ConversationTurn.wake`). */
|
|
86
|
+
export type TurnWake = 'timer' | 'auto-fix';
|
|
78
87
|
/**
|
|
79
88
|
* Collapse retained turns into a single summary entry so the next request sends one
|
|
80
89
|
* condensed user/assistant pair instead of every full completion.
|
package/dist/src/commands.js
CHANGED
|
@@ -297,7 +297,7 @@ export async function executeCommand(line, state, persist, signal, graphAccess =
|
|
|
297
297
|
draft.graph = id;
|
|
298
298
|
// This form has no UI to confirm on, so the warning that the switch starts fresh travels
|
|
299
299
|
// in the returned text; an unchanged graph clears nothing and carries no warning.
|
|
300
|
-
result = { text: `Graph: ${id === 'default' ? 'Default' : graph.name} (${id === 'default' ? '
|
|
300
|
+
result = { text: `Graph: ${id === 'default' ? 'Default' : graph.name} (${id === 'default' ? 'Andorra Agent only' : `${graph.id}@${graph.revision}`})${changed ? ". This session's context is cleared and the new graph starts fresh." : ''}${unavailable ? ` ${unavailable} The graph is selected anyway; a task on it starts only once it can run on this machine, or after /model overrides every node with one provider you have.` : ''}`, clear: changed, save };
|
|
301
301
|
}
|
|
302
302
|
catch (error) {
|
|
303
303
|
return { text: `Graph unavailable: ${error instanceof Error ? error.message : id}. Use /graph to browse saved graphs.` };
|
|
@@ -333,8 +333,8 @@ export async function executeCommand(line, state, persist, signal, graphAccess =
|
|
|
333
333
|
result = handleCommand(line, draft);
|
|
334
334
|
}
|
|
335
335
|
const permissionsChanged = draft.permissions !== state.permissions;
|
|
336
|
-
// Cache writes must stop before Read Only is persisted or exposed to the run.
|
|
337
|
-
if (permissionsChanged && draft.permissions === 'read-only')
|
|
336
|
+
// Cache writes must stop before Read Only or Plan is persisted or exposed to the run.
|
|
337
|
+
if (permissionsChanged && (draft.permissions === 'read-only' || draft.permissions === 'plan'))
|
|
338
338
|
await state.codeIntel?.setPermissions(draft.permissions);
|
|
339
339
|
if (result.save && feedbackWrite) {
|
|
340
340
|
// The preference belongs to the installation, so its change is written to the file's current
|
|
@@ -373,7 +373,7 @@ export async function executeCommand(line, state, persist, signal, graphAccess =
|
|
|
373
373
|
delete state.config.externalSubagent;
|
|
374
374
|
state.yolo = draft.yolo;
|
|
375
375
|
state.permissions = draft.permissions;
|
|
376
|
-
if (permissionsChanged && draft.permissions !== 'read-only')
|
|
376
|
+
if (permissionsChanged && draft.permissions !== 'read-only' && draft.permissions !== 'plan')
|
|
377
377
|
await state.codeIntel?.setPermissions(draft.permissions);
|
|
378
378
|
if (draft.graph === undefined)
|
|
379
379
|
delete state.graph;
|
|
@@ -470,14 +470,14 @@ export function handleCommand(line, state) {
|
|
|
470
470
|
const changed = state.graph !== undefined;
|
|
471
471
|
delete state.graph;
|
|
472
472
|
if (changed)
|
|
473
|
-
return { text: 'Graph: Default (
|
|
473
|
+
return { text: 'Graph: Default (Andorra Agent)', clear: true };
|
|
474
474
|
}
|
|
475
|
-
return { text: 'Graph: Default -
|
|
475
|
+
return { text: 'Graph: Default - Andorra Agent only. Use the graph selector for the paid Andorra workflow or custom graphs.' };
|
|
476
476
|
case '/permissions':
|
|
477
477
|
if (!arg)
|
|
478
478
|
return { text: `Permissions: ${permissionLabel(state.permissions ?? (state.yolo ? 'full-access' : 'ask-for-approval'))}` };
|
|
479
479
|
if (!isPermissionMode(arg))
|
|
480
|
-
return { text: 'Usage: /permissions read-only|ask-for-approval|approve-for-me|full-access' };
|
|
480
|
+
return { text: 'Usage: /permissions read-only|plan|ask-for-approval|approve-for-me|full-access' };
|
|
481
481
|
state.config.workspacePermissions = { ...state.config.workspacePermissions, [workspacePermissionKey(state.workspace)]: arg };
|
|
482
482
|
state.permissions = arg;
|
|
483
483
|
state.yolo = arg === 'full-access';
|
package/dist/src/completion.d.ts
CHANGED
|
@@ -17,17 +17,35 @@ export declare const SUMMARY_DESCRIPTION = "Markdown shown to the user as the fi
|
|
|
17
17
|
export declare const COMPLETION_GUIDANCE = "Finish with complete_agent alone or final JSON. Todos/artifacts do not finish a node. Compare deliverables and verification evidence with acceptance criteria. Fulfill assigned requirements: intake/research nodes hand off downstream work; implementation nodes finish implementation and verification, not a progress checkpoint. Continue available work. For a concrete external blocker, report the blocker and unfinished work honestly. Use a blocked outcome if available; otherwise the sole outcome permits a terminal report, not a claim that the task is done. Only when this node is responsible for producing the final user answer, its summary must satisfy the user's response requirements: include complete requested files and exact formatting, including requested code fences, without abbreviation, path substitution, or offers to provide content later. Each fence opens and closes on its own line; a file written to the workspace that the user did not ask to see in the answer is named by path, not reproduced. Intermediate intake, research, and delegation nodes must instead keep a concise handoff and preserve these final-answer acceptance requirements in the downstream task instruction or output; do not implement or reproduce the final deliverable before handing off. Preserve required fields and valid JSON; escape quotes and Windows backslashes or use C:/repo/file.ts, and write each summary line break as \\n rather than dropping it. Never claim unperformed work.";
|
|
18
18
|
/** Control-plane completion remains available when the execution-tool budget is exhausted. */
|
|
19
19
|
export declare function completionTool(options: RunOptions): ToolSchema;
|
|
20
|
-
|
|
20
|
+
export declare const COMPLETION_ALONE_ERROR = "complete_agent must be called alone; no tools in this batch were executed.";
|
|
21
|
+
/**
|
|
22
|
+
* Only a direct, sole model control call can request completion, never a tool observation.
|
|
23
|
+
*
|
|
24
|
+
* The one companion allowed is `update_todos`: closing the plan and handing off in the same batch is
|
|
25
|
+
* the natural last move, and it changes no workspace state. Rejecting it threw the todo update away
|
|
26
|
+
* too, so every repair prompt then showed the model a plan that still said "in progress" for work it
|
|
27
|
+
* had finished, and the model spent its repairs arguing with that stale list. The todo calls are
|
|
28
|
+
* returned for the runtime to apply before it judges the handoff; anything else still voids the batch.
|
|
29
|
+
*/
|
|
21
30
|
export declare function completionResponse(response: ModelResponse): ModelResponse & {
|
|
22
31
|
completionError?: string;
|
|
23
32
|
completionSource: 'complete_agent' | 'final_text';
|
|
33
|
+
completionTodoCalls?: ModelResponse['toolCalls'];
|
|
24
34
|
};
|
|
25
35
|
/**
|
|
26
36
|
* Undo one extra layer of string escaping in a summary. Some models JSON-escape the summary again
|
|
27
37
|
* inside already-JSON tool arguments, so the parsed text holds a backslash and an "n" where its
|
|
28
|
-
* line breaks belong, and the transcript draws its markdown as one literal paragraph.
|
|
29
|
-
*
|
|
30
|
-
*
|
|
38
|
+
* line breaks belong, and the transcript draws its markdown as one literal paragraph.
|
|
39
|
+
*
|
|
40
|
+
* Two shapes are decoded. A summary escaped throughout has no real line break and at least two
|
|
41
|
+
* escaped paragraph breaks; every escape in it is undone. A model can also switch to the extra
|
|
42
|
+
* escaping partway through, leaving a few real line breaks and the rest escaped: one `## heading`
|
|
43
|
+
* then swallows everything after it. That mixed summary is decoded only when at least two escaped
|
|
44
|
+
* breaks outside code open markdown structure (a heading, list item, quote, table, fence, or a
|
|
45
|
+
* paragraph break before text). Only its `\"` outside code, and its `\n` outside code on the lines
|
|
46
|
+
* holding that structure, are undone, so inline code, real fenced blocks and the lines the model
|
|
47
|
+
* wrote correctly keep the escapes and Windows paths they show. A summary that merely mentions an
|
|
48
|
+
* escape sequence, or a Windows path, is left as written.
|
|
31
49
|
* Sessions saved before this decode ran still hold the escaped text, so their readers apply it too
|
|
32
50
|
* (`displayHistory` in sessions.ts).
|
|
33
51
|
*/
|
|
@@ -42,4 +60,4 @@ export declare function decodeDoubleEscapedSummary(summary: string, notes?: stri
|
|
|
42
60
|
* rejection for either burns a repair on a coin flip and can end a node whose work is already
|
|
43
61
|
* done, so they are coerced and recorded instead.
|
|
44
62
|
*/
|
|
45
|
-
export declare function parseCompletion(text: string, options: RunOptions, reject: (reason: string) => void, notes?: string[]): Completion | undefined;
|
|
63
|
+
export declare function parseCompletion(text: string, options: RunOptions, reject: (reason: string) => void, notes?: string[], stopReason?: string): Completion | undefined;
|
package/dist/src/completion.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { validateJsonSchemaValue } from '../vendor/zcode/source/tool/json-schema.js';
|
|
2
|
+
import { interruptsParagraph } from './markdown.js';
|
|
2
3
|
export const COMPLETION_TOOL = 'complete_agent';
|
|
3
4
|
export const FINAL_RESPONSE_GUIDANCE = "Only when this node is responsible for producing the final user answer, its summary must satisfy the user's response requirements: include complete requested files and exact formatting, including requested code fences, without abbreviation, path substitution, or offers to provide content later. Each fence opens and closes on its own line; a file written to the workspace that the user did not ask to see in the answer is named by path, not reproduced. Intermediate intake, research, and delegation nodes must instead keep a concise handoff and preserve these final-answer acceptance requirements in the downstream task instruction or output; do not implement or reproduce the final deliverable before handing off.";
|
|
4
5
|
/**
|
|
@@ -30,8 +31,14 @@ function providerOutputSchema(schema) {
|
|
|
30
31
|
/** Native JSON Schema checks plus Andorra's graph-specific artifact/integer contracts. */
|
|
31
32
|
function validateCompletionOutput(schema, value) {
|
|
32
33
|
const validation = validateJsonSchemaValue(value, providerOutputSchema(schema));
|
|
33
|
-
if (!validation.valid)
|
|
34
|
-
|
|
34
|
+
if (!validation.valid) {
|
|
35
|
+
const errors = validation.errors.map(error => error.replace(/^\$/, 'Agent output'));
|
|
36
|
+
// "output.x is not allowed" names the mistake but not the fix, and a model told only that tends to
|
|
37
|
+
// resend the same object. Naming the fields the output does accept is the fix.
|
|
38
|
+
const declared = Object.keys(schema.properties ?? {});
|
|
39
|
+
const extra = errors.some(error => /^Agent output\.[^.\s[]+ is not allowed$/.test(error));
|
|
40
|
+
throw new Error(errors.join('; ') + (extra && declared.length ? `. The output object accepts only: ${declared.join(', ')}` : ''));
|
|
41
|
+
}
|
|
35
42
|
const checkHostContracts = (node, item, path) => {
|
|
36
43
|
if (node.type === 'integer' && !Number.isSafeInteger(item))
|
|
37
44
|
throw new Error(`${path}: expected integer`);
|
|
@@ -74,40 +81,347 @@ export function completionTool(options) {
|
|
|
74
81
|
},
|
|
75
82
|
};
|
|
76
83
|
}
|
|
77
|
-
|
|
84
|
+
export const COMPLETION_ALONE_ERROR = 'complete_agent must be called alone; no tools in this batch were executed.';
|
|
85
|
+
/**
|
|
86
|
+
* Only a direct, sole model control call can request completion, never a tool observation.
|
|
87
|
+
*
|
|
88
|
+
* The one companion allowed is `update_todos`: closing the plan and handing off in the same batch is
|
|
89
|
+
* the natural last move, and it changes no workspace state. Rejecting it threw the todo update away
|
|
90
|
+
* too, so every repair prompt then showed the model a plan that still said "in progress" for work it
|
|
91
|
+
* had finished, and the model spent its repairs arguing with that stale list. The todo calls are
|
|
92
|
+
* returned for the runtime to apply before it judges the handoff; anything else still voids the batch.
|
|
93
|
+
*/
|
|
78
94
|
export function completionResponse(response) {
|
|
79
95
|
const call = response.toolCalls.find(call => call.name === COMPLETION_TOOL);
|
|
80
96
|
if (!call)
|
|
81
97
|
return { ...response, completionSource: 'final_text' };
|
|
82
|
-
|
|
98
|
+
const others = response.toolCalls.filter(other => other !== call);
|
|
99
|
+
const todosOnly = others.length > 0 && others.every(other => other.name === 'update_todos');
|
|
100
|
+
return { ...response, completionSource: 'complete_agent', toolCalls: [], text: call.arguments,
|
|
101
|
+
...(others.length === 0 ? {} : todosOnly ? { completionTodoCalls: others } : { completionError: COMPLETION_ALONE_ERROR }) };
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The most closing brackets the host appends to a completion. Dropping the envelope's last `}`
|
|
105
|
+
* after closing `output`, or both of those, is a slip a model repeats on every retry; a longer
|
|
106
|
+
* open tail is an answer that stopped early, which the model has to send again.
|
|
107
|
+
*/
|
|
108
|
+
const MAX_APPENDED_CLOSERS = 2;
|
|
109
|
+
/**
|
|
110
|
+
* Scan JSON text outside its strings and return the closers its still-open objects and arrays
|
|
111
|
+
* need, innermost first. Undefined when nothing is open, when the text ends inside a string, or
|
|
112
|
+
* when a closer does not match its opener: only a missing tail, never a misplaced bracket.
|
|
113
|
+
*/
|
|
114
|
+
function missingClosers(text) {
|
|
115
|
+
const open = [];
|
|
116
|
+
let inString = false, escaped = false;
|
|
117
|
+
for (const char of text) {
|
|
118
|
+
if (inString) {
|
|
119
|
+
if (escaped)
|
|
120
|
+
escaped = false;
|
|
121
|
+
else if (char === '\\')
|
|
122
|
+
escaped = true;
|
|
123
|
+
else if (char === '"')
|
|
124
|
+
inString = false;
|
|
125
|
+
}
|
|
126
|
+
else if (char === '"')
|
|
127
|
+
inString = true;
|
|
128
|
+
else if (char === '{')
|
|
129
|
+
open.push('}');
|
|
130
|
+
else if (char === '[')
|
|
131
|
+
open.push(']');
|
|
132
|
+
else if ((char === '}' || char === ']') && open.pop() !== char)
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
return inString || !open.length ? undefined : open.reverse().join('');
|
|
83
136
|
}
|
|
137
|
+
const truncatedStop = (stopReason) => stopReason === 'length' || stopReason === 'max_tokens';
|
|
84
138
|
/** Classify parser failures without echoing model text, paths, or private analysis. */
|
|
85
|
-
function syntaxFailure(error) {
|
|
139
|
+
function syntaxFailure(error, text) {
|
|
86
140
|
const message = error.message;
|
|
87
141
|
const position = message.match(/at position (\d+)(?: \(line (\d+) column (\d+)\))?/);
|
|
88
142
|
const location = position ? ` at position ${position[1]}${position[2] ? ` (line ${position[2]}, column ${position[3]})` : ''}` : '';
|
|
143
|
+
// V8 reports a missing final brace as "Expected ',' or '}' after property value" at the text's
|
|
144
|
+
// length, so the end of the text is located by position, not only by the "unexpected end" wording.
|
|
145
|
+
const atEnd = /unexpected end/i.test(message) || (position !== null && Number(position[1]) >= text.trimEnd().length);
|
|
89
146
|
const category = /bad (?:escaped character|unicode escape)/i.test(message) ? 'invalidEscape'
|
|
90
147
|
: /bad control character/i.test(message) ? 'unescapedControlCharacter'
|
|
91
148
|
: /unterminated string/i.test(message) ? 'unterminatedString'
|
|
92
|
-
:
|
|
149
|
+
: atEnd ? 'unexpectedEnd'
|
|
93
150
|
: /unexpected token/i.test(message) ? 'unexpectedToken' : 'syntax';
|
|
94
|
-
|
|
151
|
+
const closers = category === 'unexpectedEnd' ? missingClosers(text) : undefined;
|
|
152
|
+
const closes = (tail) => { try {
|
|
153
|
+
JSON.parse(text.trimEnd() + tail);
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return false;
|
|
158
|
+
} };
|
|
159
|
+
// Name the one fix: a generic "keep it valid JSON" let a model drop the same brace five times.
|
|
160
|
+
const ending = category !== 'unexpectedEnd' ? ''
|
|
161
|
+
: closers && closers.length > MAX_APPENDED_CLOSERS ? ` The JSON ended before it was closed: ${closers.length} objects or arrays are still open, so the answer stopped early. Send the whole completion again, shorter, from its opening brace.`
|
|
162
|
+
: closers && closes(closers) ? ` The JSON ended before it was closed: add \`${closers}\` at the very end to close the completion envelope.`
|
|
163
|
+
: ' The JSON ended before it was closed: finish the last value, then close every open object and array.';
|
|
164
|
+
return `Invalid completion JSON [${category}]${location}.${ending} Both final text and complete_agent arguments must contain one complete JSON object, without analysis tags or surrounding prose. Use forward slashes for Windows paths (C:/repo/src/file.ts), or escape each backslash; escape quotes inside strings and write line breaks as \\n escapes, keeping the summary's markdown structure. Preserve the completion envelope and required fields. Keep the handoff concise by default, without repeating file contents or the intake transcript. ${FINAL_RESPONSE_GUIDANCE} Keep the enclosing completion valid JSON.`;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Parse completion JSON, appending the closing brackets a model left off its end. The live shape is
|
|
168
|
+
* a finished report ending `..."prUrl":"…"}`: output closed, the envelope's own `}` never written,
|
|
169
|
+
* and the same omission on every retry. The appended text must parse, and the result then faces
|
|
170
|
+
* every contract and schema check unchanged, so a member closed into the wrong object is still
|
|
171
|
+
* rejected. A response stopped by the output-token limit is never closed by the host.
|
|
172
|
+
*/
|
|
173
|
+
function parseCompletionJson(text, stopReason, notes) {
|
|
174
|
+
try {
|
|
175
|
+
return JSON.parse(text);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
const closers = truncatedStop(stopReason) ? undefined : missingClosers(text);
|
|
179
|
+
if (!closers || closers.length > MAX_APPENDED_CLOSERS)
|
|
180
|
+
throw error;
|
|
181
|
+
let value;
|
|
182
|
+
try {
|
|
183
|
+
value = JSON.parse(text.trimEnd() + closers);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
notes?.push(`completion JSON ended without its last ${closers.length === 1 ? 'closing bracket' : `${closers.length} closing brackets`} (${closers}), appended by the host`);
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
95
191
|
}
|
|
96
192
|
/**
|
|
97
193
|
* Undo one extra layer of string escaping in a summary. Some models JSON-escape the summary again
|
|
98
194
|
* inside already-JSON tool arguments, so the parsed text holds a backslash and an "n" where its
|
|
99
|
-
* line breaks belong, and the transcript draws its markdown as one literal paragraph.
|
|
100
|
-
*
|
|
101
|
-
*
|
|
195
|
+
* line breaks belong, and the transcript draws its markdown as one literal paragraph.
|
|
196
|
+
*
|
|
197
|
+
* Two shapes are decoded. A summary escaped throughout has no real line break and at least two
|
|
198
|
+
* escaped paragraph breaks; every escape in it is undone. A model can also switch to the extra
|
|
199
|
+
* escaping partway through, leaving a few real line breaks and the rest escaped: one `## heading`
|
|
200
|
+
* then swallows everything after it. That mixed summary is decoded only when at least two escaped
|
|
201
|
+
* breaks outside code open markdown structure (a heading, list item, quote, table, fence, or a
|
|
202
|
+
* paragraph break before text). Only its `\"` outside code, and its `\n` outside code on the lines
|
|
203
|
+
* holding that structure, are undone, so inline code, real fenced blocks and the lines the model
|
|
204
|
+
* wrote correctly keep the escapes and Windows paths they show. A summary that merely mentions an
|
|
205
|
+
* escape sequence, or a Windows path, is left as written.
|
|
102
206
|
* Sessions saved before this decode ran still hold the escaped text, so their readers apply it too
|
|
103
207
|
* (`displayHistory` in sessions.ts).
|
|
104
208
|
*/
|
|
105
209
|
export function decodeDoubleEscapedSummary(summary, notes) {
|
|
106
|
-
if (summary.includes('\n')
|
|
210
|
+
if (!summary.includes('\n')) {
|
|
211
|
+
if ((summary.match(/\\n\\n/g)?.length ?? 0) < 2)
|
|
212
|
+
return summary;
|
|
213
|
+
notes?.push('completion summary arrived with its newlines escaped twice and was decoded');
|
|
214
|
+
const decoded = { n: '\n', r: '\r', t: '\t', '"': '"', '\\': '\\' };
|
|
215
|
+
return summary.replace(/\\(["\\nrt])/g, (_, char) => decoded[char]);
|
|
216
|
+
}
|
|
217
|
+
// Without a literal backslash-n there is no escaped break to repair, and the scan below is skipped.
|
|
218
|
+
if (!summary.includes('\\n'))
|
|
219
|
+
return summary;
|
|
220
|
+
// The escaped part is the real lines whose prose holds escaped structure. Breaks are decoded only
|
|
221
|
+
// there, so a Windows path on a line the model wrote correctly (`C:\new\tests`) keeps its
|
|
222
|
+
// separators; an escaped quote has no such reading and is decoded on every line.
|
|
223
|
+
const structuralLines = new Set();
|
|
224
|
+
let structural = 0;
|
|
225
|
+
mapOutsideCode(summary, (prose, line, beforeCode) => {
|
|
226
|
+
// Inline code right after the piece is the text a paragraph break opens; a backtick stands in for
|
|
227
|
+
// it, which no block-opener alternative matches on its own.
|
|
228
|
+
const count = (beforeCode ? `${prose}\`` : prose).match(ESCAPED_STRUCTURE)?.length ?? 0;
|
|
229
|
+
if (count > 0)
|
|
230
|
+
structuralLines.add(line);
|
|
231
|
+
structural += count;
|
|
232
|
+
return prose;
|
|
233
|
+
});
|
|
234
|
+
if (structural < 2)
|
|
107
235
|
return summary;
|
|
108
|
-
notes?.push('completion summary arrived with its newlines escaped twice and was decoded');
|
|
109
|
-
|
|
110
|
-
return summary.replace(/\\(
|
|
236
|
+
notes?.push('completion summary arrived with some of its newlines escaped twice and was decoded');
|
|
237
|
+
// `\\` is matched as a unit and kept, so an escaped backslash before an "n" is never read as a break.
|
|
238
|
+
return mapOutsideCode(summary, (prose, line) => prose.replace(/\\(\\|n|")/g, (escape, char) => char === '"' ? '"' : char === 'n' && structuralLines.has(line) ? '\n' : escape));
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* An escaped break that stands for markdown structure: a whole run of `\n` before a block opener,
|
|
242
|
+
* or a whole run of two or more before text. "Regex \n\n matches" (a run before a space) is prose,
|
|
243
|
+
* not layout; the run is matched from its start to its end, so its own last `\n` never counts as
|
|
244
|
+
* the text after it.
|
|
245
|
+
*/
|
|
246
|
+
const ESCAPED_STRUCTURE = /(?<!\\n)(?:\\n)+(?=#{1,6} |[-*+] |\d+[.)] |> |\||```|~~~)|(?<!\\n)(?:\\n){2,}(?!\\n)(?=\S)/g;
|
|
247
|
+
function mapOutsideCode(text, transform) {
|
|
248
|
+
const lines = text.split('\n');
|
|
249
|
+
const code = codeBlockLines(lines);
|
|
250
|
+
const out = [];
|
|
251
|
+
for (let start = 0; start < lines.length;) {
|
|
252
|
+
if (code[start]) {
|
|
253
|
+
out.push(lines[start++]);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
let end = start + 1;
|
|
257
|
+
while (end < lines.length && !code[end] && !interruptsParagraph(lines[end]))
|
|
258
|
+
end++;
|
|
259
|
+
out.push(mapProse(lines.slice(start, end).join('\n'), start, transform));
|
|
260
|
+
start = end;
|
|
261
|
+
}
|
|
262
|
+
return out.join('\n');
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Whether the backtick run at `start` is a fence whose line breaks were escaped: one that follows an
|
|
266
|
+
* escaped break, or one followed by an info string and an escaped break (```` ```ts\n ````). An
|
|
267
|
+
* inline span of three backticks has prose or code after its run, not a bare word and a break.
|
|
268
|
+
*/
|
|
269
|
+
function escapedFence(source, start, length) {
|
|
270
|
+
if (length < 3)
|
|
271
|
+
return false;
|
|
272
|
+
if (source.slice(Math.max(0, start - 2), start) === '\\n')
|
|
273
|
+
return true;
|
|
274
|
+
const info = /[\w+.#-]*\\n/y;
|
|
275
|
+
info.lastIndex = start + length;
|
|
276
|
+
return info.test(source);
|
|
277
|
+
}
|
|
278
|
+
/** Which lines belong to a fenced or indented code block. */
|
|
279
|
+
function codeBlockLines(lines) {
|
|
280
|
+
let fence;
|
|
281
|
+
let indented = false;
|
|
282
|
+
let previousBlank = true;
|
|
283
|
+
return lines.map(line => {
|
|
284
|
+
const blank = line.trim() === '';
|
|
285
|
+
const afterBlank = previousBlank;
|
|
286
|
+
previousBlank = blank;
|
|
287
|
+
if (fence !== undefined) {
|
|
288
|
+
const close = /^ {0,3}(`{3,}|~{3,})[ \t\r]*$/.exec(line)?.[1];
|
|
289
|
+
if (close !== undefined && close[0] === fence[0] && close.length >= fence.length)
|
|
290
|
+
fence = undefined;
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
indented = line.startsWith(' ') ? indented || afterBlank : indented && blank;
|
|
294
|
+
if (indented)
|
|
295
|
+
return true;
|
|
296
|
+
// A real opener as `openingFence` reads one: a backtick fence's info string holds no backtick.
|
|
297
|
+
// An escaped fence's layout is its run, at most a language word, then a literal break; a literal
|
|
298
|
+
// `\n` further along the info string (```` ```js title="\n" ````) leaves the opener real.
|
|
299
|
+
const open = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
|
|
300
|
+
if (open === null || (open[1][0] === '`' && open[2].includes('`')) || /^[\w+.#-]*\\n/.test(open[2]))
|
|
301
|
+
return false;
|
|
302
|
+
fence = open[1];
|
|
303
|
+
return true;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Whether a span body from `start` to `end` crosses a paragraph boundary, as `maskSegmentCodeSpans`
|
|
308
|
+
* reads a multi-line span. `firstBreak` is the first real line break at or after `start` (Infinity
|
|
309
|
+
* when there is none), which the caller tracks as it walks forward instead of searching again. A body on one real line never does, whatever markers it shows: the
|
|
310
|
+
* transcript renders it as a single-line span. Across lines, the paragraph has no interrupting line
|
|
311
|
+
* after its first, so only the body's first and last pieces (parts of their lines) can interrupt.
|
|
312
|
+
*/
|
|
313
|
+
function crossesParagraph(source, start, end, firstBreak) {
|
|
314
|
+
if (firstBreak > end)
|
|
315
|
+
return false;
|
|
316
|
+
return interruptsParagraph(source.slice(start, firstBreak)) || interruptsParagraph(source.slice(source.lastIndexOf('\n', end) + 1, end));
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Transform the prose of one paragraph, keeping its code spans. A backslash before punctuation is
|
|
320
|
+
* skipped as a pair, so an escaped backtick never opens a span, but the pair stays in the prose the
|
|
321
|
+
* transform sees (`\"` is one of the escapes it decodes). The search for a closer stops at the first
|
|
322
|
+
* run of the opener's length, and a length already searched for in vain from an earlier position is
|
|
323
|
+
* not searched for again, so no part of the paragraph is scanned twice for the same length. The next
|
|
324
|
+
* real line break is found once per line, not once per span, which keeps a line of many spans linear.
|
|
325
|
+
* A prose piece that ends where a span begins is passed with `beforeCode`, so a paragraph break
|
|
326
|
+
* escaped just before inline code can still be read as one.
|
|
327
|
+
*/
|
|
328
|
+
function mapProse(source, firstLine, transform) {
|
|
329
|
+
let out = '';
|
|
330
|
+
let prose = '';
|
|
331
|
+
let line = firstLine;
|
|
332
|
+
let nextBreak = -1;
|
|
333
|
+
const unclosed = new Set();
|
|
334
|
+
const runs = /`+/g;
|
|
335
|
+
const closerFor = (from, length) => {
|
|
336
|
+
if (unclosed.has(length))
|
|
337
|
+
return undefined;
|
|
338
|
+
runs.lastIndex = from;
|
|
339
|
+
for (let run = runs.exec(source); run; run = runs.exec(source)) {
|
|
340
|
+
if (run[0].length === length && !escapedFence(source, run.index, length))
|
|
341
|
+
return run.index;
|
|
342
|
+
}
|
|
343
|
+
unclosed.add(length);
|
|
344
|
+
return undefined;
|
|
345
|
+
};
|
|
346
|
+
const flush = (beforeCode = false) => {
|
|
347
|
+
out += transform(prose, line, beforeCode);
|
|
348
|
+
prose = '';
|
|
349
|
+
};
|
|
350
|
+
for (let index = 0; index < source.length;) {
|
|
351
|
+
const char = source[index];
|
|
352
|
+
if (char === '\n') {
|
|
353
|
+
flush();
|
|
354
|
+
out += '\n';
|
|
355
|
+
line++;
|
|
356
|
+
index++;
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
if (char === '\\' && index + 1 < source.length && /[!-/:-@[-`{-~]/.test(source[index + 1])) {
|
|
360
|
+
prose += source.slice(index, index + 2);
|
|
361
|
+
index += 2;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (char !== '`') {
|
|
365
|
+
prose += char;
|
|
366
|
+
index++;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
runs.lastIndex = index;
|
|
370
|
+
const length = runs.exec(source)[0].length;
|
|
371
|
+
const closing = escapedFence(source, index, length) ? undefined : closerFor(index + length, length);
|
|
372
|
+
if (closing !== undefined && nextBreak !== Infinity && nextBreak < index) {
|
|
373
|
+
const found = source.indexOf('\n', index);
|
|
374
|
+
nextBreak = found === -1 ? Infinity : found;
|
|
375
|
+
}
|
|
376
|
+
if (closing === undefined || crossesParagraph(source, index + length, closing, nextBreak)) {
|
|
377
|
+
prose += '`'.repeat(length);
|
|
378
|
+
index += length;
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
flush(true);
|
|
382
|
+
const span = source.slice(index, closing + length);
|
|
383
|
+
out += span;
|
|
384
|
+
line += span.split('\n').length - 1;
|
|
385
|
+
index += span.length;
|
|
386
|
+
}
|
|
387
|
+
flush();
|
|
388
|
+
return out;
|
|
389
|
+
}
|
|
390
|
+
/** The envelope's own report fields, which a strict output schema that does not declare them refuses. */
|
|
391
|
+
const ENVELOPE_FIELDS = {
|
|
392
|
+
summary: (item) => typeof item === 'string' && item.trim().length > 0,
|
|
393
|
+
tests: (item) => Array.isArray(item) && item.every(entry => typeof entry === 'string'),
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Move the envelope's `summary` and `tests` back out of `output`.
|
|
397
|
+
*
|
|
398
|
+
* The completion tool asks for `summary` and `tests` beside `output`, and a node's output schema
|
|
399
|
+
* often has look-alike fields of its own (`implementationSummary`, `testsRun`). Models copy the two
|
|
400
|
+
* envelope fields into `output` as well, and a strict schema then rejects the whole handoff with
|
|
401
|
+
* "output.summary is not allowed" — a live run spent every repair resending that same object after
|
|
402
|
+
* its work was done. The copy is the model's own text in the wrong place, so the host puts it where
|
|
403
|
+
* the envelope reads it (keeping the top-level copy when one is already usable) and records the
|
|
404
|
+
* move. Only undeclared fields under a schema that forbids extras are touched: a schema that
|
|
405
|
+
* declares `summary` or accepts extras gets the output exactly as sent.
|
|
406
|
+
*/
|
|
407
|
+
function liftEnvelopeFields(envelope, output, schema, notes) {
|
|
408
|
+
if (!schema || schema.additionalProperties !== false)
|
|
409
|
+
return output;
|
|
410
|
+
const misplaced = Object.keys(ENVELOPE_FIELDS)
|
|
411
|
+
.filter(key => Object.hasOwn(output, key) && !Object.hasOwn(schema.properties ?? {}, key));
|
|
412
|
+
if (!misplaced.length)
|
|
413
|
+
return output;
|
|
414
|
+
const rest = { ...output };
|
|
415
|
+
for (const key of misplaced) {
|
|
416
|
+
const lifted = !ENVELOPE_FIELDS[key](envelope[key]);
|
|
417
|
+
if (lifted)
|
|
418
|
+
envelope[key] = rest[key];
|
|
419
|
+
delete rest[key];
|
|
420
|
+
notes?.push(lifted
|
|
421
|
+
? `completion output carried the envelope's ${key}; it was moved to the top level`
|
|
422
|
+
: `completion output repeated the envelope's ${key}; the copy inside output was dropped`);
|
|
423
|
+
}
|
|
424
|
+
return rest;
|
|
111
425
|
}
|
|
112
426
|
/**
|
|
113
427
|
* Parse one completion, accepting mechanically imperfect envelopes that are semantically correct.
|
|
@@ -119,9 +433,10 @@ export function decodeDoubleEscapedSummary(summary, notes) {
|
|
|
119
433
|
* rejection for either burns a repair on a coin flip and can end a node whose work is already
|
|
120
434
|
* done, so they are coerced and recorded instead.
|
|
121
435
|
*/
|
|
122
|
-
export function parseCompletion(text, options, reject, notes) {
|
|
436
|
+
export function parseCompletion(text, options, reject, notes, stopReason) {
|
|
437
|
+
const body = text.replace(/^```(?:json)?\s*\n?/, '').replace(/\n?```\s*$/, '');
|
|
123
438
|
try {
|
|
124
|
-
const value =
|
|
439
|
+
const value = parseCompletionJson(body, stopReason, notes);
|
|
125
440
|
if (options.completionPolicy && value && typeof value === 'object' && !Array.isArray(value)) {
|
|
126
441
|
const policy = options.completionPolicy;
|
|
127
442
|
const outcome = value.outcome ?? (policy.mode === 'single' ? policy.outcome : undefined);
|
|
@@ -142,6 +457,8 @@ export function parseCompletion(text, options, reject, notes) {
|
|
|
142
457
|
}
|
|
143
458
|
if (!output || typeof output !== 'object' || Array.isArray(output))
|
|
144
459
|
throw new Error("Completion outcome or output does not match the declared contract");
|
|
460
|
+
if (value.output !== undefined)
|
|
461
|
+
output = liftEnvelopeFields(value, output, options.outputSchema, notes);
|
|
145
462
|
if (options.canonicalTask !== undefined)
|
|
146
463
|
output.originalTask = options.canonicalTask;
|
|
147
464
|
if (options.outputSchema)
|
|
@@ -190,6 +507,6 @@ export function parseCompletion(text, options, reject, notes) {
|
|
|
190
507
|
throw new Error("Completion needs a nonempty summary and a tests array of strings");
|
|
191
508
|
}
|
|
192
509
|
catch (error) {
|
|
193
|
-
reject(error instanceof SyntaxError ? syntaxFailure(error) : error instanceof Error ? error.message : "Invalid completion JSON");
|
|
510
|
+
reject(error instanceof SyntaxError ? syntaxFailure(error, body) : error instanceof Error ? error.message : "Invalid completion JSON");
|
|
194
511
|
}
|
|
195
512
|
}
|
package/dist/src/config.d.ts
CHANGED
|
@@ -72,7 +72,20 @@ export interface Config {
|
|
|
72
72
|
systemPromptOverride?: string;
|
|
73
73
|
/** Days without activity after which a session is archived automatically; unset means never. */
|
|
74
74
|
autoArchiveDays?: number;
|
|
75
|
+
/** Browser tool settings. */
|
|
76
|
+
browser?: BrowserConfig;
|
|
75
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Browser tool settings.
|
|
80
|
+
*
|
|
81
|
+
* `capsolverApiKey` is a secret like a provider's `apiKey`: the engine reports only whether one is
|
|
82
|
+
* present, never its value. `CAPSOLVER_API_KEY` in the environment is the fallback when it is unset.
|
|
83
|
+
*/
|
|
84
|
+
export interface BrowserConfig {
|
|
85
|
+
capsolverApiKey?: string;
|
|
86
|
+
}
|
|
87
|
+
export declare const MAX_CAPSOLVER_API_KEY_LENGTH = 256;
|
|
88
|
+
export declare function validateBrowserConfig(value: unknown): BrowserConfig;
|
|
76
89
|
/** The longest override the setting accepts: the same bound the workspace guide is clipped to. */
|
|
77
90
|
export declare const MAX_SYSTEM_PROMPT_OVERRIDE = 16000;
|
|
78
91
|
export declare const AUTO_ARCHIVE_MIN_DAYS = 1;
|