@andorra-labs/code 0.1.9 → 0.1.11
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 +28 -208
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/dist/src/agent-execution.js +56 -0
- package/dist/src/app-server/protocol.d.ts +109 -1
- package/dist/src/app-server/protocol.js +8 -1
- package/dist/src/app-server.d.ts +59 -1
- package/dist/src/app-server.js +418 -63
- package/dist/src/auth/index.d.ts +1 -1
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/store.d.ts +17 -1
- package/dist/src/auth/store.js +25 -2
- package/dist/src/automation-service.js +1 -1
- package/dist/src/browser-session.d.ts +8 -0
- package/dist/src/browser-session.js +27 -1
- package/dist/src/browser-ui/app.js +255 -33
- package/dist/src/browser-ui/index.html +9 -9
- package/dist/src/browser-ui/style.css +110 -65
- package/dist/src/browser-ui/tokens.css +27 -26
- package/dist/src/cli.js +10 -5
- package/dist/src/coding-tools.d.ts +24 -0
- package/dist/src/coding-tools.js +71 -8
- package/dist/src/command-screens.js +1 -1
- package/dist/src/commands.d.ts +1 -1
- package/dist/src/commands.js +2 -2
- package/dist/src/completion-gates.d.ts +42 -7
- package/dist/src/completion-gates.js +55 -9
- package/dist/src/completion.d.ts +9 -1
- package/dist/src/completion.js +20 -2
- package/dist/src/dashboard-view.js +2 -2
- package/dist/src/deadline.js +4 -0
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/file-diff.d.ts +105 -0
- package/dist/src/file-diff.js +244 -0
- package/dist/src/graph-manager-chat.js +4 -4
- package/dist/src/graph-runner.js +39 -2
- package/dist/src/graph-sync.d.ts +8 -0
- package/dist/src/graph-sync.js +54 -3
- package/dist/src/graph-tool.js +1 -1
- package/dist/src/graph-ui/app.js +303 -129
- package/dist/src/graph-ui/controls.css +43 -22
- package/dist/src/graph-ui/controls.js +31 -1
- package/dist/src/graph-ui/embed.js +56 -7
- package/dist/src/graph-ui/icons.js +5 -0
- package/dist/src/graph-ui/index.html +3 -3
- package/dist/src/graph-ui/manager-state.js +2 -2
- package/dist/src/graph-ui/manager.css +19 -18
- package/dist/src/graph-ui/manager.js +5 -5
- package/dist/src/graph-ui/skill-picker.js +5 -5
- package/dist/src/graph-ui/studio-canvas.js +16 -16
- package/dist/src/graph-ui/studio.css +18 -15
- package/dist/src/graph-ui/studio.js +99 -42
- package/dist/src/graph-ui/style.css +125 -80
- package/dist/src/graph-ui/theme.js +2 -2
- package/dist/src/graph-ui/tokens.css +33 -29
- package/dist/src/graphs.d.ts +10 -3
- package/dist/src/graphs.js +15 -4
- package/dist/src/mcp.d.ts +75 -0
- package/dist/src/mcp.js +240 -8
- package/dist/src/membership-errors.d.ts +7 -1
- package/dist/src/membership-errors.js +9 -3
- package/dist/src/provider-keys.d.ts +5 -1
- package/dist/src/provider-keys.js +7 -3
- package/dist/src/provider-settings.d.ts +4 -1
- package/dist/src/provider-settings.js +46 -5
- package/dist/src/pull-requests.d.ts +42 -6
- package/dist/src/pull-requests.js +11 -3
- package/dist/src/qa/guidance.js +6 -19
- package/dist/src/qa/index.d.ts +0 -2
- package/dist/src/qa/index.js +0 -2
- package/dist/src/qa/profile/QaProfile.d.ts +5 -1
- package/dist/src/qa/profile/QaProfile.js +6 -2
- package/dist/src/qa/tools.d.ts +19 -1
- package/dist/src/qa/tools.js +20 -145
- package/dist/src/react-runtime.js +134 -16
- package/dist/src/read-document-doc.d.ts +20 -0
- package/dist/src/read-document-doc.js +524 -0
- package/dist/src/read-document-docx.d.ts +21 -0
- package/dist/src/read-document-docx.js +584 -0
- package/dist/src/read-document-text.d.ts +29 -0
- package/dist/src/read-document-text.js +67 -0
- package/dist/src/read-document-tool.d.ts +48 -0
- package/dist/src/read-document-tool.js +162 -0
- package/dist/src/read-document.d.ts +78 -0
- package/dist/src/read-document.js +353 -0
- package/dist/src/read-image.d.ts +29 -2
- package/dist/src/read-image.js +42 -17
- package/dist/src/remote/engine-pool.js +18 -6
- package/dist/src/runtime.d.ts +19 -0
- package/dist/src/runtime.js +10 -1
- package/dist/src/screen-selection.d.ts +38 -0
- package/dist/src/screen-selection.js +103 -0
- package/dist/src/session-changes.d.ts +122 -0
- package/dist/src/session-changes.js +804 -0
- package/dist/src/side-panel.d.ts +6 -1
- package/dist/src/side-panel.js +12 -10
- package/dist/src/skills/bundled/create-skill/SKILL.md +1 -1
- package/dist/src/skills/bundled/diagram/SKILL.md +1 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +37 -3
- package/dist/src/skills/bundled/graph-manager/patterns.md +27 -0
- package/dist/src/skills/bundled/provenance.json +4 -4
- package/dist/src/skills/runtime-skills.js +3 -3
- package/dist/src/stall-recovery.d.ts +15 -0
- package/dist/src/stall-recovery.js +17 -0
- package/dist/src/telemetry/schema.d.ts +1 -1
- package/dist/src/telemetry/schema.js +1 -2
- package/dist/src/terminal-ui.d.ts +64 -20
- package/dist/src/terminal-ui.js +312 -82
- package/dist/src/time-limit.d.ts +53 -0
- package/dist/src/time-limit.js +79 -0
- package/dist/src/tool-diff-stats.d.ts +9 -0
- package/dist/src/tool-diff-stats.js +20 -0
- package/dist/src/tool-names.d.ts +1 -1
- package/dist/src/tool-result-filter.js +1 -1
- package/dist/src/tools.js +118 -9
- package/dist/src/transcript.d.ts +11 -0
- package/dist/src/transcript.js +15 -3
- package/dist/src/types.d.ts +12 -0
- package/dist/src/usage-analytics.d.ts +3 -1
- package/dist/src/usage-analytics.js +16 -2
- package/package.json +6 -26
- package/dist/src/qa/api/http-runner.d.ts +0 -3
- package/dist/src/qa/api/http-runner.js +0 -47
- package/dist/src/qa/git/ChangeDetector.d.ts +0 -26
- package/dist/src/qa/git/ChangeDetector.js +0 -177
- package/dist/src/qa/git/DiffReviewer.d.ts +0 -28
- package/dist/src/qa/git/DiffReviewer.js +0 -115
- package/dist/src/qa/orchestrator/ChangeClassifier.d.ts +0 -14
- package/dist/src/qa/orchestrator/ChangeClassifier.js +0 -28
- package/dist/src/qa/orchestrator/MergeGate.d.ts +0 -14
- package/dist/src/qa/orchestrator/MergeGate.js +0 -40
- package/dist/src/qa/orchestrator/QaOrchestrator.d.ts +0 -79
- package/dist/src/qa/orchestrator/QaOrchestrator.js +0 -373
- package/dist/src/qa/runners/CommandRunner.d.ts +0 -22
- package/dist/src/qa/runners/CommandRunner.js +0 -96
- package/dist/src/qa/runners/TestRunner.d.ts +0 -21
- package/dist/src/qa/runners/TestRunner.js +0 -66
- package/dist/src/qa/runtime/RuntimeSmoke.d.ts +0 -11
- package/dist/src/qa/runtime/RuntimeSmoke.js +0 -78
- package/dist/src/qa/runtime-detect.d.ts +0 -10
- package/dist/src/qa/runtime-detect.js +0 -72
- package/dist/src/qa/security/DependencyScanner.d.ts +0 -19
- package/dist/src/qa/security/DependencyScanner.js +0 -167
- package/dist/src/qa/security/SecretScanner.d.ts +0 -3
- package/dist/src/qa/security/SecretScanner.js +0 -55
- package/docs/README.md +0 -36
- package/docs/agents/README.md +0 -62
- package/docs/agents/install-for-agents.md +0 -56
- package/docs/agents/mcp-server.md +0 -212
- package/docs/agents/subagent-mode.md +0 -149
- package/docs/concepts/README.md +0 -47
- package/docs/concepts/jev-actionable-routing.md +0 -113
- package/docs/concepts/jev-decision-thresholds.md +0 -412
- package/docs/concepts/jev-efficiency.md +0 -217
- package/docs/concepts/jev-eval-2026-11-01.md +0 -78
- package/docs/concepts/limits.md +0 -52
- package/docs/concepts/memory.md +0 -10
- package/docs/concepts/security.md +0 -50
- package/docs/concepts/workspace-instructions.md +0 -29
- package/docs/getting-started/README.md +0 -82
- package/docs/getting-started/accounts.md +0 -78
- package/docs/getting-started/configure-providers.md +0 -132
- package/docs/guides/README.md +0 -13
- package/docs/guides/browser.md +0 -39
- package/docs/guides/desktop-app.md +0 -414
- package/docs/guides/extensions.md +0 -102
- package/docs/guides/graph-builder.md +0 -116
- package/docs/guides/headless.md +0 -46
- package/docs/guides/tui.md +0 -75
- package/docs/guides/update.md +0 -70
- package/docs/guides/web-search.md +0 -51
- package/docs/guides/windows-code-signing.md +0 -319
- package/docs/llms.txt +0 -45
- package/docs/reference/README.md +0 -7
- package/docs/reference/cli.md +0 -76
- package/docs/reference/config.md +0 -91
- package/docs/reference/slash-commands.md +0 -59
- package/docs/superpowers/plans/2026-11-01-claude-console-sign-in.md +0 -111
- package/docs/superpowers/plans/2026-11-01-jev-node-opt-in.md +0 -910
- package/docs/superpowers/plans/2026-11-02-workflow-pane.md +0 -398
- package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +0 -125
- package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +0 -295
- package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +0 -203
- package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +0 -79
- package/docs/superpowers/specs/2026-10-31-work-line-summary-design.md +0 -50
- package/docs/superpowers/specs/2026-11-01-claude-console-sign-in-design.md +0 -176
- package/docs/superpowers/specs/2026-11-01-jev-node-opt-in-design.md +0 -164
- package/docs/superpowers/specs/2026-11-01-pr-section-design.md +0 -111
- package/docs/superpowers/specs/2026-11-02-workflow-pane-design.md +0 -130
- package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +0 -206
- package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +0 -291
- package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +0 -182
- package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +0 -156
- package/scripts/jev-efficiency-eval.mjs +0 -187
- package/scripts/jev-efficiency-live.mjs +0 -193
- package/scripts/zcode-engine-replay.mjs +0 -223
- package/tests/agent-centric-mcp-test-plan.md +0 -208
- package/tests/analytics-settings-test-plan.md +0 -165
- package/tests/browser-cli-smoke.mjs +0 -276
- package/tests/browser-test-plan.md +0 -280
- package/tests/chat-side-panel-test-plan.md +0 -309
- package/tests/decision-engine-test-plan.md +0 -163
- package/tests/default-active-jev-test-plan.md +0 -85
- package/tests/harness-extensions-test-plan.md +0 -113
- package/tests/jev-all-decisions-test-plan.md +0 -156
- package/tests/jev-efficiency/criteria.json +0 -158
- package/tests/jev-efficiency/workloads.mjs +0 -242
- package/tests/jev-efficiency-test-plan.md +0 -198
- package/tests/permissions-sandbox-probe.mjs +0 -74
- package/tests/permissions-test-plan.md +0 -191
- package/tests/product-telemetry-test-plan.md +0 -536
- package/tests/thinking-stream-preview-test-plan.md +0 -136
- package/tests/zcode-react-engine-test-plan.md +0 -396
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { diffArrays } from 'diff';
|
|
2
|
+
/** Past this size a side is not line-diffed: the write limit of the file tools. */
|
|
3
|
+
export const DIFF_BYTE_LIMIT = 8 * 1024 * 1024;
|
|
4
|
+
/**
|
|
5
|
+
* Past this many lines on either side a text is not split into lines: a newline-dense file inside the byte
|
|
6
|
+
* limit would otherwise cost one string per line before any bound applies.
|
|
7
|
+
*/
|
|
8
|
+
export const DIFF_LINE_LIMIT = 200_000;
|
|
9
|
+
/** How long the exact match may take before the changed middle is shown as a replacement. */
|
|
10
|
+
const MATCH_TIMEOUT_MS = 250;
|
|
11
|
+
/** The edit distance the exact match gives up at, whatever the time. */
|
|
12
|
+
const MATCH_EDIT_LIMIT = 4_000;
|
|
13
|
+
const DEFAULT_CONTEXT = 3;
|
|
14
|
+
const DEFAULT_MAX_LINES = 2_000;
|
|
15
|
+
const DEFAULT_MAX_CHARS = 512 * 1024;
|
|
16
|
+
const DEFAULT_LINE_CHARS = 2_000;
|
|
17
|
+
/** The text a side holds, `null` for an absent file, or `undefined` for content that is not UTF-8 text. */
|
|
18
|
+
export function decodeText(side) {
|
|
19
|
+
if (side === null)
|
|
20
|
+
return null;
|
|
21
|
+
if (typeof side === 'string')
|
|
22
|
+
return side.includes('\0') ? undefined : side;
|
|
23
|
+
if (side.includes(0))
|
|
24
|
+
return undefined;
|
|
25
|
+
try {
|
|
26
|
+
return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(side);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function byteLength(side) {
|
|
33
|
+
if (side === null)
|
|
34
|
+
return 0;
|
|
35
|
+
return typeof side === 'string' ? Buffer.byteLength(side) : side.length;
|
|
36
|
+
}
|
|
37
|
+
/** A text's lines, each keeping its terminator so that a final line without one compares as different. */
|
|
38
|
+
function tokens(text) {
|
|
39
|
+
return text === '' ? [] : text.split(/(?<=\n)/);
|
|
40
|
+
}
|
|
41
|
+
/** How many lines a text has, without splitting it: a final line without a terminator counts. */
|
|
42
|
+
export function lineCount(text) {
|
|
43
|
+
if (text === '')
|
|
44
|
+
return 0;
|
|
45
|
+
let count = 0;
|
|
46
|
+
for (let at = text.indexOf('\n'); at >= 0; at = text.indexOf('\n', at + 1))
|
|
47
|
+
count++;
|
|
48
|
+
return text.endsWith('\n') ? count : count + 1;
|
|
49
|
+
}
|
|
50
|
+
function display(token) {
|
|
51
|
+
return token.endsWith('\r\n') ? token.slice(0, -2) : token.endsWith('\n') ? token.slice(0, -1) : token;
|
|
52
|
+
}
|
|
53
|
+
/** The diff between two sides of one file. */
|
|
54
|
+
export function fileDiff(before, after, options = {}) {
|
|
55
|
+
const oldText = decodeText(before);
|
|
56
|
+
const newText = decodeText(after);
|
|
57
|
+
if (oldText === undefined || newText === undefined)
|
|
58
|
+
return { kind: 'binary' };
|
|
59
|
+
if (byteLength(before) > DIFF_BYTE_LIMIT || byteLength(after) > DIFF_BYTE_LIMIT) {
|
|
60
|
+
return { kind: 'too-large', ...coarseCounts(oldText ?? '', newText ?? '') };
|
|
61
|
+
}
|
|
62
|
+
const diff = textDiff(oldText ?? '', newText ?? '', options);
|
|
63
|
+
if (diff.coarse)
|
|
64
|
+
return { kind: 'too-large', linesAdded: diff.linesAdded, linesRemoved: diff.linesRemoved };
|
|
65
|
+
return { kind: 'text', diff };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The diff of two texts, as `fileDiff` returns it for text sides.
|
|
69
|
+
*
|
|
70
|
+
* Work and memory are bounded by the change, not the file: the shared head and tail are trimmed before the
|
|
71
|
+
* match, the result is kept as stretches rather than one record per line, and lines past the output bound
|
|
72
|
+
* are counted without being built. A side with more than `DIFF_LINE_LIMIT` lines is not split into lines at
|
|
73
|
+
* all: the counts come from a scan of the shared ends, and `coarse` says there are no hunks for that reason.
|
|
74
|
+
*/
|
|
75
|
+
export function textDiff(oldText, newText, options = {}) {
|
|
76
|
+
const context = Math.max(0, options.context ?? DEFAULT_CONTEXT);
|
|
77
|
+
const maxLines = Math.max(0, options.maxLines ?? DEFAULT_MAX_LINES);
|
|
78
|
+
const maxChars = Math.max(0, options.maxChars ?? DEFAULT_MAX_CHARS);
|
|
79
|
+
const lineChars = Math.max(1, options.lineChars ?? DEFAULT_LINE_CHARS);
|
|
80
|
+
if (lineCount(oldText) > DIFF_LINE_LIMIT || lineCount(newText) > DIFF_LINE_LIMIT) {
|
|
81
|
+
return { hunks: [], ...coarseCounts(oldText, newText), hiddenLines: 0, coarse: true };
|
|
82
|
+
}
|
|
83
|
+
const a = tokens(oldText);
|
|
84
|
+
const b = tokens(newText);
|
|
85
|
+
let head = 0;
|
|
86
|
+
while (head < a.length && head < b.length && a[head] === b[head])
|
|
87
|
+
head += 1;
|
|
88
|
+
let tail = 0;
|
|
89
|
+
while (tail < a.length - head && tail < b.length - head && a[a.length - 1 - tail] === b[b.length - 1 - tail])
|
|
90
|
+
tail += 1;
|
|
91
|
+
const midA = a.slice(head, a.length - tail);
|
|
92
|
+
const midB = b.slice(head, b.length - tail);
|
|
93
|
+
// The exact match runs on the changed middle only, bounded in time and edit distance; past either bound
|
|
94
|
+
// the middle is shown as removed then added, which is still a true diff.
|
|
95
|
+
let changes = midA.length && midB.length
|
|
96
|
+
? diffArrays(midA, midB, { timeout: MATCH_TIMEOUT_MS, maxEditLength: MATCH_EDIT_LIMIT })
|
|
97
|
+
: undefined;
|
|
98
|
+
changes ??= [
|
|
99
|
+
...(midA.length ? [{ value: midA, added: false, removed: true }] : []),
|
|
100
|
+
...(midB.length ? [{ value: midB, added: true, removed: false }] : []),
|
|
101
|
+
];
|
|
102
|
+
const runs = [];
|
|
103
|
+
if (head)
|
|
104
|
+
runs.push({ kind: 'context', oldStart: 1, newStart: 1, count: head, lines: a, offset: 0 });
|
|
105
|
+
let oldPos = head + 1, newPos = head + 1;
|
|
106
|
+
let linesAdded = 0, linesRemoved = 0;
|
|
107
|
+
for (const change of changes) {
|
|
108
|
+
const kind = change.added ? 'add' : change.removed ? 'del' : 'context';
|
|
109
|
+
runs.push({ kind, oldStart: oldPos, newStart: newPos, count: change.value.length, lines: change.value, offset: 0 });
|
|
110
|
+
if (kind !== 'add')
|
|
111
|
+
oldPos += change.value.length;
|
|
112
|
+
if (kind !== 'del')
|
|
113
|
+
newPos += change.value.length;
|
|
114
|
+
if (kind === 'add')
|
|
115
|
+
linesAdded += change.value.length;
|
|
116
|
+
else if (kind === 'del')
|
|
117
|
+
linesRemoved += change.value.length;
|
|
118
|
+
}
|
|
119
|
+
if (tail)
|
|
120
|
+
runs.push({ kind: 'context', oldStart: oldPos, newStart: newPos, count: tail, lines: a, offset: a.length - tail });
|
|
121
|
+
// Hunks: every changed stretch with `context` kept lines on each side, merged when the kept lines between
|
|
122
|
+
// two changes are no more than twice the context.
|
|
123
|
+
const grouped = [];
|
|
124
|
+
for (let index = 0; index < runs.length;) {
|
|
125
|
+
if (runs[index].kind === 'context') {
|
|
126
|
+
index++;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const parts = [];
|
|
130
|
+
const before = runs[index - 1];
|
|
131
|
+
if (before && context)
|
|
132
|
+
parts.push({ run: before, from: Math.max(0, before.count - context), to: before.count });
|
|
133
|
+
let at = index;
|
|
134
|
+
for (;;) {
|
|
135
|
+
parts.push({ run: runs[at], from: 0, to: runs[at].count });
|
|
136
|
+
const next = runs[at + 1];
|
|
137
|
+
if (!next) {
|
|
138
|
+
at += 1;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
if (next.kind !== 'context') {
|
|
142
|
+
at += 1;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (runs[at + 2] && next.count <= 2 * context) {
|
|
146
|
+
parts.push({ run: next, from: 0, to: next.count });
|
|
147
|
+
at += 2;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (context)
|
|
151
|
+
parts.push({ run: next, from: 0, to: Math.min(context, next.count) });
|
|
152
|
+
at += 2;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
grouped.push(parts);
|
|
156
|
+
index = at;
|
|
157
|
+
}
|
|
158
|
+
const hunks = [];
|
|
159
|
+
let emitted = 0, chars = 0, hidden = 0, full = maxLines === 0;
|
|
160
|
+
for (const parts of grouped) {
|
|
161
|
+
let oldLines = 0, newLines = 0;
|
|
162
|
+
for (const part of parts) {
|
|
163
|
+
if (part.run.kind !== 'add')
|
|
164
|
+
oldLines += part.to - part.from;
|
|
165
|
+
if (part.run.kind !== 'del')
|
|
166
|
+
newLines += part.to - part.from;
|
|
167
|
+
}
|
|
168
|
+
const first = parts[0];
|
|
169
|
+
const firstOld = parts.find(part => part.run.kind !== 'add');
|
|
170
|
+
const firstNew = parts.find(part => part.run.kind !== 'del');
|
|
171
|
+
// An empty side starts at the line before the change, as unified diff headers do.
|
|
172
|
+
const oldStart = firstOld ? firstOld.run.oldStart + firstOld.from : first.run.oldStart - 1;
|
|
173
|
+
const newStart = firstNew ? firstNew.run.newStart + firstNew.from : first.run.newStart - 1;
|
|
174
|
+
const lines = [];
|
|
175
|
+
for (const part of parts) {
|
|
176
|
+
if (full) {
|
|
177
|
+
hidden += part.to - part.from;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
for (let k = part.from; k < part.to; k++) {
|
|
181
|
+
const token = part.run.lines[part.run.offset + k];
|
|
182
|
+
const whole = display(token);
|
|
183
|
+
const text = whole.length > lineChars ? whole.slice(0, lineChars) : whole;
|
|
184
|
+
if (emitted >= maxLines || chars + text.length > maxChars) {
|
|
185
|
+
full = true;
|
|
186
|
+
hidden += part.to - k;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
const line = { kind: part.run.kind, text };
|
|
190
|
+
if (part.run.kind !== 'add')
|
|
191
|
+
line.oldLine = part.run.oldStart + k;
|
|
192
|
+
if (part.run.kind !== 'del')
|
|
193
|
+
line.newLine = part.run.newStart + k;
|
|
194
|
+
if (!token.endsWith('\n'))
|
|
195
|
+
line.noNewline = true;
|
|
196
|
+
if (text.length < whole.length)
|
|
197
|
+
line.clipped = true;
|
|
198
|
+
lines.push(line);
|
|
199
|
+
emitted++;
|
|
200
|
+
chars += text.length;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (lines.length)
|
|
204
|
+
hunks.push({ oldStart, oldLines, newStart, newLines, lines });
|
|
205
|
+
}
|
|
206
|
+
return { hunks, linesAdded, linesRemoved, hiddenLines: hidden };
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Added and removed counts without splitting either text: the shared head and tail (whole lines) are found
|
|
210
|
+
* by scanning characters from each end, and every line between them counts as changed. Memory is the two
|
|
211
|
+
* strings; time is one pass over them.
|
|
212
|
+
*/
|
|
213
|
+
export function coarseCounts(oldText, newText) {
|
|
214
|
+
if (oldText === newText)
|
|
215
|
+
return { linesAdded: 0, linesRemoved: 0 };
|
|
216
|
+
const a = oldText, b = newText;
|
|
217
|
+
const min = Math.min(a.length, b.length);
|
|
218
|
+
let prefix = 0;
|
|
219
|
+
while (prefix < min && a.charCodeAt(prefix) === b.charCodeAt(prefix))
|
|
220
|
+
prefix++;
|
|
221
|
+
// Whole lines of the shared prefix: a line is shared only with its terminator.
|
|
222
|
+
let head = 0, headEnd = 0;
|
|
223
|
+
for (let at = a.indexOf('\n'); at >= 0 && at < prefix; at = a.indexOf('\n', at + 1)) {
|
|
224
|
+
head++;
|
|
225
|
+
headEnd = at + 1;
|
|
226
|
+
}
|
|
227
|
+
// The shared suffix, never reaching back into the shared head.
|
|
228
|
+
const room = Math.min(a.length - headEnd, b.length - headEnd);
|
|
229
|
+
let suffix = 0;
|
|
230
|
+
while (suffix < room && a.charCodeAt(a.length - 1 - suffix) === b.charCodeAt(b.length - 1 - suffix))
|
|
231
|
+
suffix++;
|
|
232
|
+
// Whole lines of the shared suffix: the lines that start inside it on both sides.
|
|
233
|
+
const startA = a.length - suffix, startB = b.length - suffix;
|
|
234
|
+
let tail = 0;
|
|
235
|
+
if (suffix > 0) {
|
|
236
|
+
for (let at = a.indexOf('\n', startA); at >= 0 && at < a.length - 1; at = a.indexOf('\n', at + 1))
|
|
237
|
+
tail++;
|
|
238
|
+
const lineStartA = startA === 0 || a.charCodeAt(startA - 1) === 10;
|
|
239
|
+
const lineStartB = startB === 0 || b.charCodeAt(startB - 1) === 10;
|
|
240
|
+
if (lineStartA && lineStartB)
|
|
241
|
+
tail++;
|
|
242
|
+
}
|
|
243
|
+
return { linesAdded: Math.max(0, lineCount(b) - head - tail), linesRemoved: Math.max(0, lineCount(a) - head - tail) };
|
|
244
|
+
}
|
|
@@ -15,7 +15,7 @@ const RESET_WAIT_MS = 10_000;
|
|
|
15
15
|
const ENDING_WAIT_MS = 30_000;
|
|
16
16
|
/** Mirrors `MAX_TASK_CHARS` in `app-server.ts`: the engine refuses a longer `run.start` task or `run.steer` text. */
|
|
17
17
|
export const MANAGER_TASK_MAX_CHARS = 100_000;
|
|
18
|
-
const UPDATE_MESSAGE = 'Update Andorra to use Graph Manager.';
|
|
18
|
+
const UPDATE_MESSAGE = 'Update Andorra Code to use Graph Manager.';
|
|
19
19
|
const TOO_LARGE_MESSAGE = 'This graph is too large to send to Graph Manager.';
|
|
20
20
|
/** The longest tool or approval line the panel is given. */
|
|
21
21
|
const TOOL_LINE_MAX = 120;
|
|
@@ -72,9 +72,9 @@ export function describeManagerTool(name, value, graphOfDraft = () => undefined)
|
|
|
72
72
|
/** What each `graphs` action does, as the row's verb. An action not named here shows its own name. */
|
|
73
73
|
const GRAPH_ACTION_VERBS = {
|
|
74
74
|
andorra_graph_begin: 'Open draft', andorra_graph_get: 'Read graph', andorra_graph_guide: 'Read guide',
|
|
75
|
-
andorra_graph_node_upsert: 'Set
|
|
75
|
+
andorra_graph_node_upsert: 'Set step', andorra_graph_node_patch: 'Edit step', andorra_graph_node_remove: 'Remove step',
|
|
76
76
|
andorra_graph_edge_upsert: 'Connect', andorra_graph_edge_remove: 'Remove connection', andorra_graph_patch: 'Edit graph',
|
|
77
|
-
andorra_graph_validate: 'Validate draft', andorra_graph_publish: 'Save
|
|
77
|
+
andorra_graph_validate: 'Validate draft', andorra_graph_publish: 'Save version', andorra_graph_discard: 'Discard draft',
|
|
78
78
|
andorra_graph_delete: 'Delete graph', andorra_graph_restore: 'Restore graph',
|
|
79
79
|
};
|
|
80
80
|
/**
|
|
@@ -477,7 +477,7 @@ export class GraphManagerChat {
|
|
|
477
477
|
const created = await this.request(engine, 'sessions.create', { workspace: this.workspace, name: title });
|
|
478
478
|
const id = record(created.session).id;
|
|
479
479
|
if (typeof id !== 'string')
|
|
480
|
-
throw new Error('Graph Manager could not
|
|
480
|
+
throw new Error('Graph Manager could not start its conversation.');
|
|
481
481
|
// The rename pins the name, so the engine's automatic titling leaves it alone.
|
|
482
482
|
await this.request(engine, 'sessions.rename', { id, name: title });
|
|
483
483
|
this.sessionId = id;
|
package/dist/src/graph-runner.js
CHANGED
|
@@ -247,12 +247,49 @@ export async function runGraph(graph, options) {
|
|
|
247
247
|
if (!(options.inheritedSkills ?? []).includes(skillId))
|
|
248
248
|
activeSkills.delete(skillId);
|
|
249
249
|
}
|
|
250
|
-
|
|
250
|
+
// A fresh run normally starts at the entry. A wake addressed to a node (an Auto-fix prompt goes to the node that
|
|
251
|
+
// switched Auto-fix on) starts at that node instead, when it is still an agent of this graph and can start with
|
|
252
|
+
// only what the run itself supplies: a node that needs its predecessor's handoff would fail its own input checks.
|
|
253
|
+
const startNode = (() => {
|
|
254
|
+
const requested = options.resumeFrom === undefined ? options.startNode : undefined;
|
|
255
|
+
const node = requested === undefined ? undefined : pinned.nodes[requested];
|
|
256
|
+
if (requested === undefined || node?.type !== 'agent')
|
|
257
|
+
return pinned.entry;
|
|
258
|
+
if (node.inputSchema) {
|
|
259
|
+
try {
|
|
260
|
+
validateValue(node.inputSchema, resolveMapping(node.inputs, { run: { input: runInput, state: runState, loop: { iteration: 1 } } }, node.inputSchema), `Node ${requested} inputs`);
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
return pinned.entry;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// A join that waits for every branch can complete only when each branch it waits for can run from here. A node
|
|
267
|
+
// on one branch of a fork reaches the join without its siblings, and the run would end at the join with the
|
|
268
|
+
// rest of the graph skipped; starting at the entry runs every branch, as before.
|
|
269
|
+
const reachable = new Set();
|
|
270
|
+
for (const frontier = [requested]; frontier.length > 0;) {
|
|
271
|
+
const nodeId = frontier.pop();
|
|
272
|
+
if (reachable.has(nodeId))
|
|
273
|
+
continue;
|
|
274
|
+
reachable.add(nodeId);
|
|
275
|
+
for (const edge of pinned.edges)
|
|
276
|
+
if (edge.source === nodeId)
|
|
277
|
+
frontier.push(edge.target);
|
|
278
|
+
}
|
|
279
|
+
const joinsComplete = [...reachable].every(nodeId => {
|
|
280
|
+
const join = pinned.nodes[nodeId];
|
|
281
|
+
if (join?.type !== 'join' || join.join?.mode === 'any')
|
|
282
|
+
return true;
|
|
283
|
+
return pinned.edges.every(edge => edge.target !== nodeId || edge.bootstrap || reachable.has(edge.source));
|
|
284
|
+
});
|
|
285
|
+
return joinsComplete ? requested : pinned.entry;
|
|
286
|
+
})();
|
|
287
|
+
const queue = [{ nodeId: startNode, generation: 0, path: [], inputs: {}, predecessors: {} }];
|
|
251
288
|
const visits = new Map();
|
|
252
289
|
const executed = new Set();
|
|
253
290
|
let nextGeneration = 0;
|
|
254
291
|
const pendingJoins = new Map();
|
|
255
|
-
let currentNode =
|
|
292
|
+
let currentNode = startNode;
|
|
256
293
|
let lastCompletion;
|
|
257
294
|
if (options.resumeFrom) {
|
|
258
295
|
// Rehydrate the scheduler from the journal replay of a stopped attempt. The frontier is
|
package/dist/src/graph-sync.d.ts
CHANGED
|
@@ -111,6 +111,14 @@ export declare class GraphSync {
|
|
|
111
111
|
private request;
|
|
112
112
|
private perform;
|
|
113
113
|
private restoreDraft;
|
|
114
|
+
/**
|
|
115
|
+
* Whether this exact snapshot is already published here, read without the save lock. Revision
|
|
116
|
+
* files are immutable, so a published one cannot change under the read; anything less than a
|
|
117
|
+
* published copy with these exact contents — a missing or different file, an unpublished one past
|
|
118
|
+
* the latest pointer, a conflict — is left to the locked restore, which decides it. The conflict
|
|
119
|
+
* copy's id is derived from this snapshot's hash, so its receipt can only be this snapshot's.
|
|
120
|
+
*/
|
|
121
|
+
private alreadyRestored;
|
|
114
122
|
private restoreSnapshot;
|
|
115
123
|
}
|
|
116
124
|
/** What a caller needs from a sync it owns; a test supplies its own in place of a real one. */
|
package/dist/src/graph-sync.js
CHANGED
|
@@ -642,7 +642,13 @@ export class GraphSync {
|
|
|
642
642
|
}
|
|
643
643
|
async perform() {
|
|
644
644
|
this.deadline = this.now() + 20_000;
|
|
645
|
-
|
|
645
|
+
// The timer re-checks an account that is already in sync every 30 seconds, and the local sweep
|
|
646
|
+
// takes several passes to visit every file. Saying "Saving…" and then "will resume" for each of
|
|
647
|
+
// them would take back a verdict nothing has changed: while a pass sends nothing, the account
|
|
648
|
+
// stays synced. A save or delete replaces this object, and so does the first upload of the pass
|
|
649
|
+
// (a revision save marks nothing pending), so a change during the pass is reported.
|
|
650
|
+
const recheck = this.status.state === 'synced' ? this.status : undefined;
|
|
651
|
+
this.status = recheck ?? { state: 'syncing', detail: 'Saving graphs to your account…' };
|
|
646
652
|
// Repair interrupted local deletions before network authorization: even an offline machine
|
|
647
653
|
// must not show a graph whose tombstone was committed before a crash. A save that landed
|
|
648
654
|
// after that tombstone is revived rather than removed.
|
|
@@ -718,6 +724,8 @@ export class GraphSync {
|
|
|
718
724
|
if (options.confirm || !await this.cached(hash)) {
|
|
719
725
|
// A refused snapshot stays on this machine and is offered again on a later sweep, so an
|
|
720
726
|
// upgraded account uploads it then.
|
|
727
|
+
if (this.status === recheck)
|
|
728
|
+
this.status = { state: 'syncing', detail: 'Saving graphs to your account…' };
|
|
721
729
|
try {
|
|
722
730
|
await this.request(`/${hash}${options.pin ? '?pin=1' : ''}`, token, raw);
|
|
723
731
|
}
|
|
@@ -865,7 +873,16 @@ export class GraphSync {
|
|
|
865
873
|
? await readFile(join(this.folder, 'snapshots', `${hash}.json`), 'utf8')
|
|
866
874
|
: await this.request(`/${hash}`, token);
|
|
867
875
|
// A cloud receipt proves upload, not that its user-visible copy still exists.
|
|
868
|
-
|
|
876
|
+
// A graph another window's sweep or a save is writing right now is not a sync failure:
|
|
877
|
+
// the checkpoint keeps this snapshot first, and the next pass restores it.
|
|
878
|
+
try {
|
|
879
|
+
await this.restoreSnapshot(raw, hash, receipts, deleted);
|
|
880
|
+
}
|
|
881
|
+
catch (error) {
|
|
882
|
+
if (error instanceof SaveLockBusyError)
|
|
883
|
+
throw new SyncPaused();
|
|
884
|
+
throw error;
|
|
885
|
+
}
|
|
869
886
|
progress.page.remaining.shift();
|
|
870
887
|
await atomic(progressPath, JSON.stringify(progress));
|
|
871
888
|
}
|
|
@@ -879,7 +896,7 @@ export class GraphSync {
|
|
|
879
896
|
? { state: 'offline', detail: `${refused.size} graph change(s) exceed the free tier and were saved on this computer only. Upgrade to Premium to sync them.` }
|
|
880
897
|
: invalidLocalFiles
|
|
881
898
|
? { state: 'offline', detail: `${invalidLocalFiles} local graph file(s) could not be read. Other graphs synchronized; original files preserved.` }
|
|
882
|
-
: !localComplete ? { state: 'pending', detail: 'Saved locally; local history sync will resume automatically.' }
|
|
899
|
+
: !localComplete && !(recheck !== undefined && this.status === recheck) ? { state: 'pending', detail: 'Saved locally; local history sync will resume automatically.' }
|
|
883
900
|
: { state: 'synced', detail: 'Graphs saved locally and to your account' };
|
|
884
901
|
}
|
|
885
902
|
async restoreDraft(raw, hash) {
|
|
@@ -898,6 +915,32 @@ export class GraphSync {
|
|
|
898
915
|
}
|
|
899
916
|
await immutable(path, raw);
|
|
900
917
|
}
|
|
918
|
+
/**
|
|
919
|
+
* Whether this exact snapshot is already published here, read without the save lock. Revision
|
|
920
|
+
* files are immutable, so a published one cannot change under the read; anything less than a
|
|
921
|
+
* published copy with these exact contents — a missing or different file, an unpublished one past
|
|
922
|
+
* the latest pointer, a conflict — is left to the locked restore, which decides it. The conflict
|
|
923
|
+
* copy's id is derived from this snapshot's hash, so its receipt can only be this snapshot's.
|
|
924
|
+
*/
|
|
925
|
+
async alreadyRestored(graph, hash, receipts) {
|
|
926
|
+
const published = async (id, matches) => {
|
|
927
|
+
try {
|
|
928
|
+
const folder = join(this.directory, 'graphs', id);
|
|
929
|
+
const latest = JSON.parse(await readFile(join(folder, 'latest.json'), 'utf8'));
|
|
930
|
+
if (!Number.isSafeInteger(latest) || latest < graph.revision)
|
|
931
|
+
return false;
|
|
932
|
+
return matches(await readFile(join(folder, `${graph.revision}.json`), 'utf8'));
|
|
933
|
+
}
|
|
934
|
+
catch {
|
|
935
|
+
return false;
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
if (await published(graph.id, raw => digest(envelope('revision', JSON.parse(raw))) === hash))
|
|
939
|
+
return true;
|
|
940
|
+
const conflict = `cloud-${hash.slice(0, 40)}`;
|
|
941
|
+
const path = join(this.directory, 'graphs', conflict, `${graph.revision}.json`);
|
|
942
|
+
return receipts[path] !== undefined && await published(conflict, raw => digest(raw) === receipts[path]);
|
|
943
|
+
}
|
|
901
944
|
async restoreSnapshot(raw, hash, receipts, deleted) {
|
|
902
945
|
const value = parseSnapshot(raw, hash);
|
|
903
946
|
// A graph deleted on this machine stays deleted: its snapshots stay cached but restore no
|
|
@@ -918,6 +961,14 @@ export class GraphSync {
|
|
|
918
961
|
await immutable(join(this.folder, 'snapshots', `${hash}.json`), raw);
|
|
919
962
|
return;
|
|
920
963
|
}
|
|
964
|
+
// Every sweep visits every snapshot the account holds, and a restore takes the graph's save
|
|
965
|
+
// lock. A revision this machine already holds needs no restore, so it must not take the lock:
|
|
966
|
+
// each window's engine runs its own sweep, and hundreds of needless locks per pass made the
|
|
967
|
+
// sweeps collide with each other and with the user's saves until no pass could finish.
|
|
968
|
+
if (await this.alreadyRestored(graph, hash, receipts)) {
|
|
969
|
+
await immutable(join(this.folder, 'snapshots', `${hash}.json`), raw);
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
921
972
|
// The guard re-reads the tombstone file under the graph's save lock, so a delete that landed
|
|
922
973
|
// while this pass was running is honored even though this pass read an older verdict.
|
|
923
974
|
let restored = true;
|
package/dist/src/graph-tool.js
CHANGED
|
@@ -85,7 +85,7 @@ export function createGraphTool(pool = sharedPool) {
|
|
|
85
85
|
name: 'graphs', capability: 'external', executionMode: 'sequential',
|
|
86
86
|
description: 'Create, edit, validate, publish, delete or restore Andorra graphs (multi-agent workflows) in the signed-in account\'s graph store, the same store the Graph Builder and graph picker use. Never write graph files on disk. '
|
|
87
87
|
+ 'Call action andorra_graph_guide first for node types, ports, limits and error codes; load the skill andorra:graph-manager to design a graph with the user. '
|
|
88
|
-
+ 'Put the action\'s arguments in args. Drafts are kept in this Andorra process for up to an hour; publish saves a revision and syncs it to the account. Publish, delete and restore ask for permission. '
|
|
88
|
+
+ 'Put the action\'s arguments in args. Drafts are kept in this Andorra process for up to an hour; publish saves a revision and syncs it to the account. Publish, delete and restore ask the user for permission, except under Full Access, which approves them without a prompt; never tell the user a prompt is coming when the task runs in Full Access. '
|
|
89
89
|
+ `Actions and their args (* required): ${actionSummary()}.`,
|
|
90
90
|
parameters: { type: 'object', additionalProperties: false, properties: {
|
|
91
91
|
action: { type: 'string', enum: ACTIONS },
|