@andorra-labs/code 0.1.4 → 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.
Files changed (171) hide show
  1. package/dist/src/account-presentation.js +3 -3
  2. package/dist/src/agent-execution.d.ts +2 -0
  3. package/dist/src/agent-execution.js +126 -20
  4. package/dist/src/agent-mcp.d.ts +18 -1
  5. package/dist/src/agent-mcp.js +103 -8
  6. package/dist/src/app-server/protocol.d.ts +33 -3
  7. package/dist/src/app-server/protocol.js +14 -1
  8. package/dist/src/app-server/workspace.d.ts +1 -0
  9. package/dist/src/app-server/workspace.js +7 -1
  10. package/dist/src/app-server.d.ts +115 -41
  11. package/dist/src/app-server.js +1229 -219
  12. package/dist/src/automation-runner.d.ts +9 -0
  13. package/dist/src/automation-runner.js +22 -1
  14. package/dist/src/automation-tool.js +8 -1
  15. package/dist/src/automations.js +1 -1
  16. package/dist/src/browser-captcha-tool.d.ts +54 -0
  17. package/dist/src/browser-captcha-tool.js +374 -0
  18. package/dist/src/browser-panel-tool.d.ts +7 -0
  19. package/dist/src/browser-panel-tool.js +74 -3
  20. package/dist/src/browser-runner.js +19 -4
  21. package/dist/src/browser-server.js +21 -1
  22. package/dist/src/browser-session.d.ts +16 -0
  23. package/dist/src/browser-session.js +35 -0
  24. package/dist/src/browser-ui/app.js +193 -3
  25. package/dist/src/browser-ui/style.css +15 -1
  26. package/dist/src/browser-view.d.ts +72 -4
  27. package/dist/src/browser-view.js +229 -17
  28. package/dist/src/capabilities.js +13 -2
  29. package/dist/src/capsolver.d.ts +60 -0
  30. package/dist/src/capsolver.js +101 -0
  31. package/dist/src/claude-provider.d.ts +6 -0
  32. package/dist/src/claude-provider.js +34 -3
  33. package/dist/src/cli-executable.d.ts +33 -0
  34. package/dist/src/cli-executable.js +64 -0
  35. package/dist/src/cli-process.d.ts +47 -0
  36. package/dist/src/cli-process.js +113 -0
  37. package/dist/src/cli-sign-in.d.ts +68 -0
  38. package/dist/src/cli-sign-in.js +224 -0
  39. package/dist/src/cli.js +54 -23
  40. package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +1 -1
  41. package/dist/src/code-intelligence/CodeIntelligenceManager.js +5 -5
  42. package/dist/src/coding-tools.js +44 -5
  43. package/dist/src/command-output-tap.d.ts +16 -0
  44. package/dist/src/command-output-tap.js +45 -0
  45. package/dist/src/command-screens.js +3 -3
  46. package/dist/src/commands.d.ts +10 -1
  47. package/dist/src/commands.js +7 -7
  48. package/dist/src/completion.d.ts +23 -5
  49. package/dist/src/completion.js +334 -17
  50. package/dist/src/config.d.ts +13 -0
  51. package/dist/src/config.js +28 -2
  52. package/dist/src/deadline.js +6 -0
  53. package/dist/src/extensions.d.ts +1 -0
  54. package/dist/src/extensions.js +16 -3
  55. package/dist/src/graph-provider-portability.js +2 -2
  56. package/dist/src/graph-quota.d.ts +1 -1
  57. package/dist/src/graph-quota.js +1 -1
  58. package/dist/src/graph-runner.js +35 -21
  59. package/dist/src/graph-selection.d.ts +6 -0
  60. package/dist/src/graph-selection.js +10 -0
  61. package/dist/src/graph-server.d.ts +7 -0
  62. package/dist/src/graph-server.js +61 -3
  63. package/dist/src/graph-sync.d.ts +50 -0
  64. package/dist/src/graph-sync.js +383 -12
  65. package/dist/src/graph-ui/app.js +61 -8
  66. package/dist/src/graph-ui/icons.js +1 -0
  67. package/dist/src/graph-ui/index.html +1 -1
  68. package/dist/src/graph-ui/skill-picker.js +242 -0
  69. package/dist/src/graph-ui/style.css +19 -0
  70. package/dist/src/graphs.d.ts +46 -4
  71. package/dist/src/graphs.js +152 -27
  72. package/dist/src/grok-provider.d.ts +50 -0
  73. package/dist/src/grok-provider.js +186 -0
  74. package/dist/src/handoffs.d.ts +13 -0
  75. package/dist/src/handoffs.js +31 -1
  76. package/dist/src/managed-sign-in.d.ts +38 -0
  77. package/dist/src/managed-sign-in.js +169 -0
  78. package/dist/src/markdown.d.ts +5 -0
  79. package/dist/src/markdown.js +5 -2
  80. package/dist/src/mcp.js +11 -0
  81. package/dist/src/membership.d.ts +8 -1
  82. package/dist/src/membership.js +15 -5
  83. package/dist/src/model-metadata.js +14 -2
  84. package/dist/src/model-override.d.ts +10 -0
  85. package/dist/src/model-override.js +20 -0
  86. package/dist/src/opencode-cli-provider.d.ts +122 -0
  87. package/dist/src/opencode-cli-provider.js +415 -0
  88. package/dist/src/opencode-provider.js +23 -8
  89. package/dist/src/palette.d.ts +2 -0
  90. package/dist/src/palette.js +2 -0
  91. package/dist/src/permissions.d.ts +19 -1
  92. package/dist/src/permissions.js +30 -1
  93. package/dist/src/powershell-pool.d.ts +2 -2
  94. package/dist/src/powershell-pool.js +18 -5
  95. package/dist/src/provider-connection.js +36 -0
  96. package/dist/src/provider-engine.d.ts +2 -1
  97. package/dist/src/provider-engine.js +64 -13
  98. package/dist/src/provider-import.js +6 -1
  99. package/dist/src/provider-settings.js +22 -3
  100. package/dist/src/providers.d.ts +12 -1
  101. package/dist/src/providers.js +27 -8
  102. package/dist/src/pull-requests.d.ts +111 -17
  103. package/dist/src/pull-requests.js +308 -76
  104. package/dist/src/qa/qa-authorize.js +9 -1
  105. package/dist/src/react-runtime.js +76 -5
  106. package/dist/src/remote/engine-pool.js +1 -1
  107. package/dist/src/run-progress.js +6 -1
  108. package/dist/src/run-records.d.ts +133 -27
  109. package/dist/src/run-records.js +320 -40
  110. package/dist/src/runtime.d.ts +38 -1
  111. package/dist/src/runtime.js +27 -4
  112. package/dist/src/save-lock.d.ts +11 -0
  113. package/dist/src/save-lock.js +29 -2
  114. package/dist/src/sessions.js +4 -1
  115. package/dist/src/shell.js +4 -1
  116. package/dist/src/side-panel.d.ts +1 -1
  117. package/dist/src/side-panel.js +1 -1
  118. package/dist/src/skill-commands.d.ts +2 -0
  119. package/dist/src/skill-commands.js +2 -0
  120. package/dist/src/skills/bundled/create-agent/SKILL.md +81 -0
  121. package/dist/src/skills/bundled/create-skill/SKILL.md +81 -0
  122. package/dist/src/skills/bundled/doctor/SKILL.md +43 -0
  123. package/dist/src/skills/bundled/graph-manager/SKILL.md +97 -0
  124. package/dist/src/skills/bundled/graph-manager/errors.md +38 -0
  125. package/dist/src/skills/bundled/graph-manager/patterns.md +78 -0
  126. package/dist/src/skills/bundled/manage-mcp/SKILL.md +75 -0
  127. package/dist/src/skills/bundled/manage-mcp/probe.md +165 -0
  128. package/dist/src/skills/bundled/manage-skills/SKILL.md +67 -0
  129. package/dist/src/skills/bundled/provenance.json +50 -0
  130. package/dist/src/skills/bundled/write-instructions/SKILL.md +42 -0
  131. package/dist/src/skills/invocable-skills.d.ts +41 -0
  132. package/dist/src/skills/invocable-skills.js +49 -0
  133. package/dist/src/skills/prompt-skills.d.ts +1 -0
  134. package/dist/src/skills/prompt-skills.js +33 -0
  135. package/dist/src/skills/runtime-skills.d.ts +4 -0
  136. package/dist/src/skills/runtime-skills.js +21 -0
  137. package/dist/src/structured-step.d.ts +55 -0
  138. package/dist/src/structured-step.js +85 -0
  139. package/dist/src/subagent-run.d.ts +1 -1
  140. package/dist/src/subagent-run.js +29 -33
  141. package/dist/src/telemetry/schema.d.ts +2 -2
  142. package/dist/src/telemetry/schema.js +3 -2
  143. package/dist/src/terminal-ui.d.ts +29 -0
  144. package/dist/src/terminal-ui.js +112 -28
  145. package/dist/src/timers.d.ts +21 -2
  146. package/dist/src/timers.js +12 -4
  147. package/dist/src/tool-names.d.ts +18 -0
  148. package/dist/src/tool-names.js +26 -0
  149. package/dist/src/tools.js +45 -11
  150. package/dist/src/trajectory.js +32 -12
  151. package/dist/src/types.d.ts +23 -0
  152. package/dist/src/update.d.ts +26 -16
  153. package/dist/src/update.js +232 -275
  154. package/docs/agents/install-for-agents.md +15 -24
  155. package/docs/agents/mcp-server.md +13 -1
  156. package/docs/agents/subagent-mode.md +7 -4
  157. package/docs/concepts/security.md +2 -0
  158. package/docs/getting-started/README.md +14 -6
  159. package/docs/getting-started/configure-providers.md +29 -2
  160. package/docs/guides/README.md +1 -1
  161. package/docs/guides/browser.md +12 -0
  162. package/docs/guides/desktop-app.md +45 -9
  163. package/docs/guides/graph-builder.md +8 -0
  164. package/docs/guides/update.md +37 -16
  165. package/docs/reference/cli.md +1 -1
  166. package/docs/reference/config.md +2 -2
  167. package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +125 -0
  168. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +7 -0
  169. package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +206 -0
  170. package/package.json +1 -1
  171. package/tests/permissions-test-plan.md +2 -1
@@ -4,4 +4,4 @@
4
4
  <body>
5
5
  <aside class="rail" id="library-rail"><div id="rail-resize" role="separator" aria-label="Resize library sidebar" aria-orientation="vertical" aria-controls="library-rail" tabindex="0"></div><div class="rail-body" tabindex="0" aria-label="Graph and node library"><div class="section-label">Your graphs <button id="new-graph" aria-label="Create graph" title="Create graph" data-icon="plus"></button></div><input id="search" type="search" placeholder="Find a graph" aria-label="Find a graph"><nav id="graphs" aria-label="Graphs" tabindex="0"></nav><div class="section-label library-label">Node library</div><input id="node-search" type="search" placeholder="Search nodes..." aria-label="Search nodes"><nav id="node-library" aria-label="Node library"></nav><p class="hint">Drag a node onto the canvas, or select it and press Enter to add it. Connect each outcome to one or more destinations.</p></div><footer class="rail-footer">Your account <span id="sync-status" role="status">Saved locally; cloud sync pending</span></footer></aside>
6
6
  <main><header class="chrome"><div id="host-chrome" class="host-chrome" hidden></div><div class="graph-heading"><strong id="graph-title">Graph studio</strong><span id="revision">Loading graphs...</span><span id="host-notice" class="chip chip-accent" role="status" hidden></span></div><div class="chrome-actions" id="chrome-actions"><button id="toggle-inspector" class="icon-button" aria-expanded="true" aria-label="Inspector" title="Show or hide the inspector" data-icon="panel-right"></button><div class="menu" id="more-wrap"><button id="more" class="icon-button" aria-haspopup="menu" aria-expanded="false" aria-controls="more-menu" aria-label="More actions" title="More actions" data-icon="more"></button><div id="more-menu" class="menu-list" role="menu" aria-label="More actions" hidden><button id="duplicate" type="button" role="menuitem" data-icon="copy">Duplicate</button></div></div><button id="save" class="primary">Save revision</button></div></header><div class="workspace"><section id="canvas" aria-label="Graph canvas"><div id="scene"><svg id="edges" aria-label="Graph connections"></svg><div id="nodes"></div></div><div id="empty">Create a graph to get started.</div><div id="canvas-hint" class="canvas-hint" role="note"><span id="canvas-hint-text">Drag the background to pan - Scroll to zoom</span><button id="canvas-hint-close" type="button" class="icon-button" aria-label="Dismiss canvas tips" title="Dismiss" data-icon="x"></button></div><div class="canvas-toolbar" role="toolbar" aria-label="Canvas controls"><button id="undo" aria-label="Undo" title="Undo (Ctrl/Cmd+Z)" data-icon="undo"></button><button id="redo" aria-label="Redo" title="Redo (Ctrl/Cmd+Y)" data-icon="redo"></button><span class="toolbar-divider" aria-hidden="true"></span><button id="zoom-out" aria-label="Zoom out" title="Zoom out" data-icon="zoom-out"></button><output id="zoom" aria-label="Zoom level">100%</output><button id="zoom-in" aria-label="Zoom in" title="Zoom in" data-icon="zoom-in"></button><button id="fit" aria-label="Fit graph" title="Fit graph" data-icon="fit"></button><button id="layout" aria-label="Arrange" title="Arrange nodes" data-icon="arrange"></button></div></section><aside id="inspector"><div id="resize" role="separator" aria-label="Resize inspector" aria-orientation="vertical" tabindex="0"></div><header class="panel-header"><strong id="inspector-title">Graph settings</strong><button id="graph-settings" class="btn-small">Graph</button></header><div id="inspector-body"></div></aside></div><footer class="status"><span id="status" role="status" aria-live="polite">Connecting to your workspace...</span><span class="status-actions"><button id="theme-toggle" type="button" hidden>Light</button><button id="export">Export JSON</button></span></footer></main>
7
- <script src="/compat.js" defer></script><script src="/icons.js" defer></script><script src="/controls.js" defer></script><script src="/edge-router.js" defer></script><script src="/app.js" defer></script><script src="/embed.js" defer></script><script src="/sidebar.js" defer></script><script src="/studio.js" defer></script><script src="/studio-canvas.js" defer></script></body></html>
7
+ <script src="/compat.js" defer></script><script src="/icons.js" defer></script><script src="/controls.js" defer></script><script src="/skill-picker.js" defer></script><script src="/edge-router.js" defer></script><script src="/app.js" defer></script><script src="/embed.js" defer></script><script src="/sidebar.js" defer></script><script src="/studio.js" defer></script><script src="/studio-canvas.js" defer></script></body></html>
@@ -0,0 +1,242 @@
1
+ /*
2
+ * Skills in graph prompts. Typing `/` in a prompt opens a browser of this machine's skills, and
3
+ * picking one writes its `/command` where the slash was. When the graph runs, the node loads every
4
+ * skill its prompts name (src/skills/prompt-skills.ts finds them with the same pattern as below).
5
+ *
6
+ * A name no skill on this machine answers to is a warning under the prompt, never an error: the
7
+ * graph still saves and runs, and the agent is told to go on without that skill. A graph can be
8
+ * built on one machine and run on another, and a project's own skills (.agents/skills) are only
9
+ * known when the run starts in that project.
10
+ */
11
+ 'use strict';
12
+ (() => {
13
+ const REFERENCE = /(^|[\s([{])\/((?:skill::)?[A-Za-z0-9][\w-]*(?::(?:\.|[\w-]+(?:\.[\w-]+)*(?:\/[\w-]+(?:\.[\w-]+)*)*))?)(?![\w:/-])(?!\.\w)/g;
14
+ // A qualified command (`/team:skills/review`) keeps filtering through its slashes and dots.
15
+ const QUERY = /(^|[\s([{])\/([\w-]*(?::[\w.\/:-]*)?)$/;
16
+ const STALE_MS = 15_000;
17
+ const MAX_SHOWN = 60;
18
+ let cache = { at: 0, value: undefined, error: undefined, pending: undefined };
19
+ let pickerSeq = 0;
20
+ // One picker is open at a time; a window resize moves that one. The inspector redraws its fields
21
+ // often, so no per-field window listener is left behind.
22
+ let openPlace;
23
+ window.addEventListener('resize', () => openPlace?.());
24
+
25
+ const el = (tag, text, className) => { const item = document.createElement(tag); if (text !== undefined) item.textContent = text; if (className) item.className = className; return item; };
26
+ const icon = (name, size = 14) => globalThis.AndorraIcons?.icon?.(name, size);
27
+
28
+ /** The catalog, refetched when older than a few seconds so a skill turned on in Settings shows up. */
29
+ function catalog(load, force = false) {
30
+ if (cache.pending) return cache.pending;
31
+ if (!force && cache.value && Date.now() - cache.at < STALE_MS) return Promise.resolve(cache.value);
32
+ cache.pending = Promise.resolve().then(load).then(value => {
33
+ cache = { at: Date.now(), value: { skills: Array.isArray(value?.skills) ? value.skills : [], inactive: Array.isArray(value?.inactive) ? value.inactive : [], reserved: Array.isArray(value?.reserved) ? value.reserved : [] }, error: undefined, pending: undefined };
34
+ return cache.value;
35
+ }, error => {
36
+ // A failed refresh keeps the last catalog that loaded; with none, nothing is judged missing.
37
+ cache = { ...cache, at: Date.now(), error: error?.message || String(error), pending: undefined };
38
+ return cache.value;
39
+ });
40
+ return cache.pending;
41
+ }
42
+
43
+ /** Every `/name` a prompt names, in order, without built-in commands. */
44
+ function references(text, reserved = []) {
45
+ const names = [];
46
+ if (typeof text !== 'string' || !text.includes('/')) return names;
47
+ for (const match of text.matchAll(REFERENCE)) {
48
+ const name = match[2];
49
+ if (!reserved.includes(name) && !names.includes(name)) names.push(name);
50
+ }
51
+ return names;
52
+ }
53
+
54
+ const named = (skill, name) => skill.command === '/' + name || skill.id === name;
55
+ const answers = (skill, name) => named(skill, name) || skill.name === name;
56
+
57
+ /**
58
+ * The names in a prompt this machine cannot load, each with the reason. An installed skill owns
59
+ * its name even while turned off or broken, as it does for a typed command: Andorra's skill of the
60
+ * same name then answers only to `/andorra:name`, so the short name is reported, not substituted.
61
+ */
62
+ function problems(text, value) {
63
+ if (!value) return [];
64
+ const result = [];
65
+ for (const name of references(text, value.reserved)) {
66
+ if (value.skills.some(skill => named(skill, name))) continue;
67
+ const inactive = value.inactive.find(skill => answers(skill, name));
68
+ if (!inactive && value.skills.some(skill => skill.source === 'installed' && answers(skill, name))) continue;
69
+ result.push({ name, state: inactive?.state ?? 'missing' });
70
+ }
71
+ return result;
72
+ }
73
+
74
+ function problemText({ name, state }) {
75
+ if (state === 'disabled') return `/${name} is turned off in Skills settings. The node still runs, without it.`;
76
+ if (state === 'unavailable') return `/${name} is installed but cannot be loaded; repair it in Skills settings. The node still runs, without it.`;
77
+ return `Skill /${name} not found on this machine. The node still runs, without it.`;
78
+ }
79
+
80
+ function matching(skills, query) {
81
+ const needle = query.toLowerCase();
82
+ const rank = skill => skill.command.slice(1).toLowerCase().startsWith(needle) ? 0 : String(skill.name).toLowerCase().startsWith(needle) ? 1 : 2;
83
+ return skills
84
+ .filter(skill => typeof skill.command === 'string' && `${skill.command}\n${skill.name}\n${skill.id}\n${skill.description ?? ''}`.toLowerCase().includes(needle))
85
+ .sort((a, b) => rank(a) - rank(b) || (a.source === b.source ? 0 : a.source === 'installed' ? -1 : 1) || a.command.localeCompare(b.command));
86
+ }
87
+
88
+ /** The caret's box in the viewport, measured on a mirror of the textarea. */
89
+ function caretRect(textarea) {
90
+ const box = textarea.getBoundingClientRect();
91
+ try {
92
+ const style = getComputedStyle(textarea);
93
+ const mirror = document.createElement('div');
94
+ for (const property of ['boxSizing', 'width', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'fontFamily', 'fontSize', 'fontWeight', 'fontStyle', 'letterSpacing', 'lineHeight', 'tabSize', 'textTransform', 'wordSpacing', 'textIndent']) mirror.style[property] = style[property];
95
+ Object.assign(mirror.style, { position: 'fixed', visibility: 'hidden', top: '0', left: '-9999px', whiteSpace: 'pre-wrap', overflowWrap: 'break-word', overflow: 'hidden', height: 'auto' });
96
+ mirror.textContent = textarea.value.slice(0, textarea.selectionStart);
97
+ const marker = el('span', '\u200b'); mirror.append(marker);
98
+ document.body.append(mirror);
99
+ const top = marker.offsetTop - textarea.scrollTop, left = marker.offsetLeft - textarea.scrollLeft;
100
+ const height = parseFloat(style.lineHeight) || marker.offsetHeight || 18;
101
+ mirror.remove();
102
+ const y = Math.min(Math.max(box.top + top, box.top), box.bottom - height);
103
+ const x = Math.min(Math.max(box.left + left, box.left), box.right);
104
+ return { left: x, top: y, bottom: y + height };
105
+ } catch { return { left: box.left, top: box.bottom, bottom: box.bottom }; }
106
+ }
107
+
108
+ /**
109
+ * Gives a prompt textarea the `/` picker and the warning row. `load` fetches the catalog;
110
+ * `onPick` runs after a picked command is written, so the caller can record the change.
111
+ */
112
+ function attach(textarea, { load, onPick } = {}) {
113
+ if (!textarea || typeof load !== 'function' || textarea.dataset?.skillPicker) return;
114
+ textarea.dataset.skillPicker = 'on';
115
+ const id = `skill-picker-${++pickerSeq}`;
116
+ textarea.setAttribute('aria-autocomplete', 'list');
117
+ textarea.setAttribute('aria-haspopup', 'listbox');
118
+ textarea.setAttribute('aria-expanded', 'false');
119
+
120
+ const warnings = el('div', undefined, 'skill-warnings'); warnings.setAttribute('role', 'status'); warnings.hidden = true;
121
+ textarea.after(warnings);
122
+ const renderWarnings = value => {
123
+ warnings.replaceChildren();
124
+ for (const problem of problems(textarea.value, value)) {
125
+ const row = el('p', undefined, 'skill-warning');
126
+ row.title = 'A skill in a project\'s .agents/skills folder is found when the graph runs in that project. Install or turn on skills in Settings > Skills.';
127
+ const glyph = icon('warning'); if (glyph) row.append(glyph);
128
+ row.append(el('span', problemText(problem)));
129
+ warnings.append(row);
130
+ }
131
+ warnings.hidden = !warnings.childElementCount;
132
+ };
133
+ let warnTimer;
134
+ const refreshWarnings = (force = false) => { void catalog(load, force).then(renderWarnings); };
135
+
136
+ let panel, list, options = [], active = 0, query;
137
+ const close = () => {
138
+ panel?.remove(); panel = undefined; list = undefined; options = []; query = undefined;
139
+ if (openPlace === place) openPlace = undefined;
140
+ textarea.setAttribute('aria-expanded', 'false'); textarea.removeAttribute('aria-controls'); textarea.removeAttribute('aria-activedescendant');
141
+ };
142
+ const highlight = index => {
143
+ active = index;
144
+ options.forEach((option, i) => { option.row.dataset.active = String(i === index); option.row.setAttribute('aria-selected', String(i === index)); });
145
+ const current = options[index]?.row;
146
+ if (current) { textarea.setAttribute('aria-activedescendant', current.id); current.scrollIntoView?.({ block: 'nearest' }); }
147
+ else textarea.removeAttribute('aria-activedescendant');
148
+ };
149
+ const accept = skill => {
150
+ if (!query || !skill) return;
151
+ const value = textarea.value;
152
+ // A pick replaces the whole token under the caret, including any part typed after it.
153
+ const tail = /^[\w:.\/-]*/.exec(value.slice(query.end))[0].length;
154
+ const after = value.slice(query.end + tail);
155
+ const insert = skill.command + (/^\s/.test(after) ? '' : ' ');
156
+ textarea.value = value.slice(0, query.start) + insert + after;
157
+ const caret = query.start + insert.length;
158
+ textarea.setSelectionRange(caret, caret);
159
+ close();
160
+ textarea.dispatchEvent(new Event('input', { bubbles: true }));
161
+ textarea.dispatchEvent(new Event('change', { bubbles: true }));
162
+ onPick?.(skill);
163
+ };
164
+ const place = () => {
165
+ if (!panel) return;
166
+ const caret = caretRect(textarea);
167
+ const width = Math.min(380, window.innerWidth - 16);
168
+ panel.style.width = `${width}px`;
169
+ panel.style.left = `${Math.min(Math.max(8, caret.left - 12), window.innerWidth - width - 8)}px`;
170
+ const below = window.innerHeight - caret.bottom - 12, above = caret.top - 12;
171
+ if (below >= 180 || below >= above) { panel.style.top = `${caret.bottom + 4}px`; panel.style.bottom = ''; panel.style.maxHeight = `${Math.max(120, below)}px`; }
172
+ else { panel.style.bottom = `${window.innerHeight - caret.top + 4}px`; panel.style.top = ''; panel.style.maxHeight = `${Math.max(120, above)}px`; }
173
+ };
174
+ const render = value => {
175
+ if (!query) return;
176
+ if (!panel) {
177
+ panel = el('div', undefined, 'select-panel skill-picker'); panel.id = id;
178
+ panel.setAttribute('role', 'listbox'); panel.setAttribute('aria-label', 'Skills');
179
+ // Keep focus in the prompt while the pointer chooses.
180
+ panel.addEventListener('mousedown', event => event.preventDefault());
181
+ (textarea.closest('dialog') ?? document.body).append(panel);
182
+ textarea.setAttribute('aria-expanded', 'true'); textarea.setAttribute('aria-controls', id);
183
+ openPlace = place;
184
+ }
185
+ panel.replaceChildren();
186
+ list = el('div', undefined, 'select-list'); panel.append(list);
187
+ const found = value ? matching(value.skills, query.text).slice(0, MAX_SHOWN) : [];
188
+ options = [];
189
+ let group;
190
+ for (const skill of found) {
191
+ const source = skill.source === 'installed' ? 'Installed' : 'Andorra';
192
+ if (source !== group) { group = source; list.append(el('div', source, 'select-group')); }
193
+ const row = el('div', undefined, 'select-option skill-option'); row.id = `${id}-${options.length}`;
194
+ row.setAttribute('role', 'option');
195
+ row.append(el('span', skill.command, 'skill-option-command'));
196
+ if (skill.description) { const description = el('span', skill.description, 'skill-option-description'); row.title = skill.description; row.append(description); }
197
+ const index = options.length;
198
+ row.addEventListener('mousemove', () => { if (active !== index) highlight(index); });
199
+ row.addEventListener('click', () => accept(skill));
200
+ options.push({ skill, row }); list.append(row);
201
+ }
202
+ if (!found.length) {
203
+ const text = !value ? `Skills could not be loaded${cache.error ? `: ${cache.error}` : ''}. A /name you type still runs.`
204
+ : !value.skills.length ? 'No skills are installed on this machine. A /name you type is kept, and the node runs without a skill it cannot find.'
205
+ : `No skill on this machine matches /${query.text}. You can keep it; the node runs without a skill it cannot find.`;
206
+ list.append(el('p', text, 'help skill-picker-empty'));
207
+ }
208
+ panel.append(el('div', found.length ? 'Up/Down to choose, Enter to insert, Esc to close' : 'Esc to close', 'skill-picker-hint'));
209
+ highlight(Math.min(active, Math.max(0, options.length - 1)));
210
+ place();
211
+ };
212
+ const update = () => {
213
+ const start = textarea.selectionStart, end = textarea.selectionEnd;
214
+ const match = start === end ? QUERY.exec(textarea.value.slice(0, start)) : null;
215
+ if (!match || document.activeElement !== textarea) { close(); return; }
216
+ const next = { start: match.index + match[1].length, end: start, text: match[2] };
217
+ if (query?.text !== next.text) active = 0;
218
+ query = next;
219
+ render(cache.value);
220
+ void catalog(load).then(value => { if (query === next) render(value); });
221
+ };
222
+
223
+ textarea.addEventListener('input', () => { update(); clearTimeout(warnTimer); warnTimer = setTimeout(() => refreshWarnings(), 200); });
224
+ textarea.addEventListener('click', update);
225
+ textarea.addEventListener('focus', () => refreshWarnings());
226
+ textarea.addEventListener('blur', close);
227
+ textarea.addEventListener('scroll', () => place());
228
+ // Capture runs before the prompt's own Escape handling (leaving full screen), so Escape closes
229
+ // only the picker while it is open.
230
+ textarea.addEventListener('keydown', event => {
231
+ if (!panel || event.isComposing) return;
232
+ if (event.key === 'Escape') { event.preventDefault(); event.stopImmediatePropagation(); close(); return; }
233
+ if (event.shiftKey || event.ctrlKey || event.metaKey || event.altKey || !options.length) return;
234
+ if (event.key === 'ArrowDown') { event.preventDefault(); highlight((active + 1) % options.length); }
235
+ else if (event.key === 'ArrowUp') { event.preventDefault(); highlight((active - 1 + options.length) % options.length); }
236
+ else if (event.key === 'Enter' || event.key === 'Tab') { event.preventDefault(); accept(options[active]?.skill); }
237
+ }, true);
238
+ refreshWarnings();
239
+ }
240
+
241
+ globalThis.AndorraSkillPicker = { attach, references, problems, problemText, invalidate: () => { cache = { at: 0, value: undefined, error: undefined, pending: undefined }; } };
242
+ })();
@@ -389,6 +389,25 @@ body.prompt-fullscreen #inspector { z-index: 60; }
389
389
  .link-button:hover:not(:disabled) { background: transparent; color: var(--text); }
390
390
  .provider-warning { margin: 0 0 var(--space-3); }
391
391
 
392
+ /* Skills in prompts (skill-picker.js): the `/` picker reuses the dropdown panel, and a name this
393
+ machine has no skill for is a warning row under its field, not a validation error. */
394
+ .field > .skill-warnings { grid-column: 1 / -1; grid-row: 3; }
395
+ .skill-warnings { display: flex; flex-direction: column; gap: var(--space-1); margin-top: var(--space-1); }
396
+ .skill-warnings[hidden] { display: none; }
397
+ .skill-warning {
398
+ display: flex; align-items: flex-start; gap: var(--space-1); margin: 0; padding: 4px var(--space-2);
399
+ border-radius: var(--row-radius); color: var(--warn-text); box-shadow: inset 0 0 0 1px var(--warn);
400
+ font-size: var(--type-xs); line-height: 1.5; cursor: help;
401
+ }
402
+ .skill-warning > svg { flex: none; margin-top: 2px; }
403
+ /* controls.css loads after this file, so the picker's rules are scoped to win over .select-option. */
404
+ .skill-picker.select-panel { z-index: 450; }
405
+ .skill-picker .skill-option { flex-direction: column; align-items: stretch; justify-content: center; gap: 0; min-height: 36px; padding: 4px 8px; text-align: left; }
406
+ .skill-picker .skill-option-command { display: block; min-width: 0; font-family: var(--font-mono); font-size: var(--type-row); overflow: hidden; text-overflow: ellipsis; }
407
+ .skill-picker .skill-option-description { display: block; min-width: 0; color: var(--text-3); font-size: var(--type-xs); overflow: hidden; text-overflow: ellipsis; }
408
+ .skill-picker-empty { margin: 6px 8px; white-space: normal; }
409
+ .skill-picker-hint { padding: 6px 8px 2px; border-top: 1px solid var(--border); margin-top: 4px; color: var(--text-3); font-size: var(--type-xs); }
410
+
392
411
  /* A validation problem is an error, and errors are the one colour the chrome allows. */
393
412
  .validation { font-size: var(--type-xs); line-height: 1.5; padding-left: 18px; color: var(--err-text); }
394
413
  .valid { color: var(--text-2); font-size: var(--type-xs); }
@@ -177,7 +177,7 @@ export interface Graph {
177
177
  [key: string]: unknown;
178
178
  };
179
179
  }
180
- export declare const GRAPH_TOOLS: readonly ["Read", "Write", "Edit", "Glob", "Grep", "Bash", "PowerShell", "NativeExec", "AsyncProcess", "PowerShellFast", "ShellMetrics", "read_file", "list_files", "search_files", "write_file", "edit_file", "read", "write", "edit", "find", "grep", "ls", "powershell", "bash", "shell", "git_read", "read_artifact", "write_artifact", "repo_explore", "memory_search", "set_timer", "pull_request", "qa.inspect_project", "qa.status", "qa.fast", "qa.deep", "qa.test", "qa.terminal", "qa.security", "qa.browser", "qa.browser_session", "read_skill_resource", "browser.panel"];
180
+ export declare const GRAPH_TOOLS: readonly ["Read", "Write", "Edit", "Glob", "Grep", "Bash", "PowerShell", "NativeExec", "AsyncProcess", "PowerShellFast", "ShellMetrics", "read_file", "list_files", "search_files", "write_file", "edit_file", "read", "write", "edit", "find", "grep", "ls", "powershell", "bash", "shell", "git_read", "read_artifact", "write_artifact", "repo_explore", "memory_search", "set_timer", "pull_request", "qa.inspect_project", "qa.status", "qa.fast", "qa.deep", "qa.test", "qa.terminal", "qa.security", "qa.browser", "qa.browser_session", "browser.solve_captcha", "read_skill_resource", "browser.panel", "browser.incognito"];
181
181
  /** QA tool names are an explicit allowlist; gating keys off membership, never a name prefix. */
182
182
  export declare const QA_TOOL_NAMES: readonly string[];
183
183
  export declare const isQaToolName: (name: string) => boolean;
@@ -207,7 +207,14 @@ export declare const DEFAULT_HARNESS_REVISION_2: Graph;
207
207
  export declare const DEFAULT_HARNESS_REVISION_3: Graph;
208
208
  /** Frozen revision 4 adds skill resources to the published revision-3 snapshot. */
209
209
  export declare const DEFAULT_HARNESS_REVISION_4: Graph;
210
- /** Revision 5 enables the integrated browser for all default agents. */
210
+ /** Frozen revision 5 enables the integrated browser for all default agents. */
211
+ export declare const DEFAULT_HARNESS_REVISION_5: Graph;
212
+ /**
213
+ * Revision 6 renames the bundled execution agent to Andorra Agent and widens its role to general
214
+ * tasks alongside coding. The agent still receives the confirmed task instruction through the same
215
+ * intake handoff, and topology, capabilities and tooling are exactly revision 5's, so the change is
216
+ * presentation and instruction only.
217
+ */
211
218
  export declare const DEFAULT_HARNESS: Graph;
212
219
  /** Upgrade only in-memory copies. Stored snapshots remain unchanged. */
213
220
  /**
@@ -263,8 +270,43 @@ export declare function graphLeavesNodesToSession(graph: {
263
270
  export declare class GraphConflictError extends Error {
264
271
  constructor(message?: string);
265
272
  }
266
- /** Publish an immutable cloud revision only when the local revision is absent or identical. */
267
- export declare function restoreGraphRevision(input: unknown, directory: string): Promise<Graph>;
273
+ /**
274
+ * A soft-deleted graph: its latest revision carries `metadata.deletedAt`.
275
+ *
276
+ * Deleting publishes that revision rather than removing files, because cloud sync restores every graph
277
+ * an account holds and would bring removed files back. Every earlier revision stays stored.
278
+ */
279
+ export declare function isDeletedGraph(graph: Pick<Graph, 'metadata'>): boolean;
280
+ /** What a listing shows. Quota is computed from the full list, so deleted graphs still count there. */
281
+ export declare function withoutDeletedGraphs<T extends Pick<Graph, 'metadata'>>(graphs: T[]): T[];
282
+ /** A new run named a deleted graph. Resuming a session that already ran it is still allowed. */
283
+ export declare class GraphDeletedError extends Error {
284
+ readonly code = "GRAPH_DELETED";
285
+ constructor(name: string);
286
+ }
287
+ /**
288
+ * Publish an immutable cloud revision only when the local revision is absent or identical.
289
+ *
290
+ * `skip` and `floorOf` are consulted under the folder's save lock immediately before any write:
291
+ * a graph deleted on this machine must not be written back, and asking while holding the lock
292
+ * makes those verdicts final against a delete or revival that is still running.
293
+ */
294
+ export declare function restoreGraphRevision(input: unknown, directory: string, skip?: (graph: Graph) => Promise<boolean>, floorOf?: (graph: Graph) => Promise<number | undefined>): Promise<{
295
+ graph: Graph;
296
+ restored: boolean;
297
+ }>;
268
298
  export declare function loadGraph(id: string, revision?: number, directory?: string): Promise<Graph>;
269
299
  export declare function listGraphs(directory?: string, onLoadError?: (id: string, error: unknown) => void): Promise<Graph[]>;
270
300
  export declare function saveGraph(input: unknown, expectedRevision: number | null, directory?: string): Promise<Graph>;
301
+ /**
302
+ * Remove a saved graph and its whole revision history.
303
+ *
304
+ * The save lock serializes against a save or cloud restore of the same graph, so a delete cannot
305
+ * race one into leaving a half-written folder behind. The folder leaves the live path in one
306
+ * rename while the lock is held, so a save that lands during the removal writes into a fresh
307
+ * folder and survives it. Deleting the bundled `default` is refused: it has no storage to remove,
308
+ * and a hidden preset would only return on the next launch.
309
+ */
310
+ export declare function deleteGraph(id: string, directory?: string, options?: {
311
+ onDetached?: () => Promise<void>;
312
+ }): Promise<void>;
@@ -2,10 +2,10 @@ import { mkdir, readFile, readdir, rename, unlink, writeFile } from 'node:fs/pro
2
2
  import { join } from 'node:path';
3
3
  import { randomUUID } from 'node:crypto';
4
4
  import { configDirectory } from './config.js';
5
- import { acquireSaveLock, archiveUnpublishedSnapshot, SaveLockBusyError } from './save-lock.js';
5
+ import { acquireSaveLock, archiveUnpublishedSnapshot, removeLockedFolder, SaveLockBusyError } from './save-lock.js';
6
6
  import { validateMappingConstants, validateMappings, validateSchema, validateValue, schemaAt, nodeOutputSchema } from './handoffs.js';
7
7
  import { CANONICAL_CODING_TOOLS, canonicalToolName, canonicalizeToolList, toolNameMatches } from './tool-names.js';
8
- export const GRAPH_TOOLS = [...CANONICAL_CODING_TOOLS, 'NativeExec', 'AsyncProcess', 'PowerShellFast', 'ShellMetrics', 'read_file', 'list_files', 'search_files', 'write_file', 'edit_file', 'read', 'write', 'edit', 'find', 'grep', 'ls', 'powershell', 'bash', 'shell', 'git_read', 'read_artifact', 'write_artifact', 'repo_explore', 'memory_search', 'set_timer', 'pull_request', 'qa.inspect_project', 'qa.status', 'qa.fast', 'qa.deep', 'qa.test', 'qa.terminal', 'qa.security', 'qa.browser', 'qa.browser_session', 'read_skill_resource', 'browser.panel'];
8
+ export const GRAPH_TOOLS = [...CANONICAL_CODING_TOOLS, 'NativeExec', 'AsyncProcess', 'PowerShellFast', 'ShellMetrics', 'read_file', 'list_files', 'search_files', 'write_file', 'edit_file', 'read', 'write', 'edit', 'find', 'grep', 'ls', 'powershell', 'bash', 'shell', 'git_read', 'read_artifact', 'write_artifact', 'repo_explore', 'memory_search', 'set_timer', 'pull_request', 'qa.inspect_project', 'qa.status', 'qa.fast', 'qa.deep', 'qa.test', 'qa.terminal', 'qa.security', 'qa.browser', 'qa.browser_session', 'browser.solve_captcha', 'read_skill_resource', 'browser.panel', 'browser.incognito'];
9
9
  /** QA tool names are an explicit allowlist; gating keys off membership, never a name prefix. */
10
10
  export const QA_TOOL_NAMES = ['qa.inspect_project', 'qa.status', 'qa.fast', 'qa.deep', 'qa.test', 'qa.terminal', 'qa.security', 'qa.browser'];
11
11
  export const isQaToolName = (name) => QA_TOOL_NAMES.includes(name);
@@ -26,7 +26,7 @@ export function createOrchestratorNode(id = 'orchestrator') {
26
26
  id, name: 'Orchestrator', type: 'agent', agentRole: 'orchestrator', executor: 'react-basic',
27
27
  instruction: 'Understand the requested work before delegating implementation. Inspect relevant repository files, components, interfaces, architecture and testing patterns with the available read tools. Ground codebase findings in inspected paths and distinguish evidence from unknowns. Ask the user to clarify requirements, acceptance criteria, design preferences and important tradeoffs before handing work onward; do not infer approval from silence. Summarize the confirmed requirements, design considerations and codebase findings, then produce a concrete task instruction for the next Agent. Research subagents are optional and bounded; use only those that help resolve specific questions. Do not implement or modify the workspace during intake.',
28
28
  capabilities: { filesystem: 'read', shell: 'disabled', git: 'read', github: 'none', browser: 'playwright', deployment: 'none' },
29
- tools: ['read_file', 'list_files', 'search_files', 'git_read', 'read_artifact', 'write_artifact', 'repo_explore', 'read_skill_resource', 'qa.browser_session', 'browser.panel'],
29
+ tools: ['read_file', 'list_files', 'search_files', 'git_read', 'read_artifact', 'write_artifact', 'repo_explore', 'read_skill_resource', 'qa.browser_session', 'browser.panel', 'browser.incognito'],
30
30
  completion: { mode: 'single', outcome: 'completed' },
31
31
  contextPolicy: { history: true },
32
32
  inputs: { originalTask: '$run.input.task' },
@@ -73,8 +73,8 @@ DEFAULT_HARNESS_REVISION_3.nodes.orchestrator.retry = { maxAttempts: 2 };
73
73
  /** Frozen revision 4 adds skill resources to the published revision-3 snapshot. */
74
74
  export const DEFAULT_HARNESS_REVISION_4 = { ...structuredClone(DEFAULT_HARNESS_REVISION_3), revision: 4 };
75
75
  DEFAULT_HARNESS_REVISION_4.nodes.orchestrator.tools.push('read_skill_resource');
76
- /** Revision 5 enables the integrated browser for all default agents. */
77
- export const DEFAULT_HARNESS = {
76
+ /** Frozen revision 5 enables the integrated browser for all default agents. */
77
+ export const DEFAULT_HARNESS_REVISION_5 = {
78
78
  schemaVersion: 3, id: 'default', name: 'Software Engineer', revision: 5, entry: 'orchestrator',
79
79
  nodes: {
80
80
  orchestrator: { ...createOrchestratorNode(), retry: { maxAttempts: 2 }, position: { x: 100, y: 120 } },
@@ -82,6 +82,15 @@ export const DEFAULT_HARNESS = {
82
82
  done: { id: 'done', name: 'Done', type: 'end', position: { x: 780, y: 120 } },
83
83
  }, edges: [{ id: 'orchestrator-engineer', source: 'orchestrator', target: 'engineer', outcome: 'completed', inputMapping: structuredClone(ORCHESTRATOR_HANDOFF) }, { id: 'engineer-done', source: 'engineer', target: 'done', outcome: 'completed' }],
84
84
  };
85
+ /**
86
+ * Revision 6 renames the bundled execution agent to Andorra Agent and widens its role to general
87
+ * tasks alongside coding. The agent still receives the confirmed task instruction through the same
88
+ * intake handoff, and topology, capabilities and tooling are exactly revision 5's, so the change is
89
+ * presentation and instruction only.
90
+ */
91
+ export const DEFAULT_HARNESS = { ...structuredClone(DEFAULT_HARNESS_REVISION_5), name: 'Andorra Agent', revision: 6 };
92
+ DEFAULT_HARNESS.nodes.engineer.name = 'Andorra Agent';
93
+ DEFAULT_HARNESS.nodes.engineer.instruction = 'Carry out the confirmed task instruction completely, whether it is a coding task or a general one: implement code and verify changes with appropriate tools, and answer general research, writing and analysis directly. Use the supplied requirements, acceptance criteria, design considerations and repository findings to guide the work. Verify the result and report remaining issues.';
85
94
  /** Upgrade only in-memory copies. Stored snapshots remain unchanged. */
86
95
  /**
87
96
  * `addOrchestrator: false` upgrades a legacy graph without an Orchestrator to the current schema as it
@@ -196,7 +205,8 @@ export function permitsBuiltInTool(node, name, child = false) {
196
205
  return false;
197
206
  const policy = effectiveCapabilities(node);
198
207
  const canonical = canonicalToolName(name);
199
- if (name === 'qa.browser_session')
208
+ // The solve tool only acts on this agent's own qa.browser_session pages, so it follows the same policy.
209
+ if (name === 'qa.browser_session' || name === 'browser.solve_captcha')
200
210
  return policy.browser === 'playwright';
201
211
  if (['Read', 'Glob', 'Grep', 'repo_explore', 'read_skill_resource'].includes(canonical))
202
212
  return policy.filesystem !== 'none';
@@ -944,8 +954,52 @@ function validateGraphInternal(value, options = {}) {
944
954
  export class GraphConflictError extends Error {
945
955
  constructor(message = 'This graph changed in another editor. Reload it before saving.') { super(message); this.name = 'GraphConflictError'; }
946
956
  }
947
- /** Publish an immutable cloud revision only when the local revision is absent or identical. */
948
- export async function restoreGraphRevision(input, directory) {
957
+ /**
958
+ * A soft-deleted graph: its latest revision carries `metadata.deletedAt`.
959
+ *
960
+ * Deleting publishes that revision rather than removing files, because cloud sync restores every graph
961
+ * an account holds and would bring removed files back. Every earlier revision stays stored.
962
+ */
963
+ export function isDeletedGraph(graph) {
964
+ return typeof graph.metadata?.deletedAt === 'string' && graph.metadata.deletedAt.length > 0;
965
+ }
966
+ /** What a listing shows. Quota is computed from the full list, so deleted graphs still count there. */
967
+ export function withoutDeletedGraphs(graphs) {
968
+ return graphs.filter(graph => !isDeletedGraph(graph));
969
+ }
970
+ /** A new run named a deleted graph. Resuming a session that already ran it is still allowed. */
971
+ export class GraphDeletedError extends Error {
972
+ code = 'GRAPH_DELETED';
973
+ constructor(name) { super(`Graph ${name} was deleted. Restore it before running it.`); this.name = 'GraphDeletedError'; }
974
+ }
975
+ /** Whether the folder holds a published graph: a save's latest pointer or any numbered revision. */
976
+ async function publishedRevision(folder) {
977
+ try {
978
+ await readFile(join(folder, 'latest.json'), 'utf8');
979
+ return true;
980
+ }
981
+ catch (error) {
982
+ if (error.code !== 'ENOENT')
983
+ return true;
984
+ }
985
+ try {
986
+ for (const entry of await readdir(folder))
987
+ if (/^\d+\.json$/.test(entry))
988
+ return true;
989
+ return false;
990
+ }
991
+ catch (error) {
992
+ return error.code !== 'ENOENT';
993
+ }
994
+ }
995
+ /**
996
+ * Publish an immutable cloud revision only when the local revision is absent or identical.
997
+ *
998
+ * `skip` and `floorOf` are consulted under the folder's save lock immediately before any write:
999
+ * a graph deleted on this machine must not be written back, and asking while holding the lock
1000
+ * makes those verdicts final against a delete or revival that is still running.
1001
+ */
1002
+ export async function restoreGraphRevision(input, directory, skip, floorOf) {
949
1003
  const graph = validateGraphInternal(input);
950
1004
  if (graph.id === 'default' || graph.revision < 1)
951
1005
  throw new Error('Invalid cloud revision');
@@ -954,6 +1008,64 @@ export async function restoreGraphRevision(input, directory) {
954
1008
  const release = await acquireSaveLock(folder);
955
1009
  const temp = join(folder, `latest-${randomUUID()}.tmp`);
956
1010
  try {
1011
+ if (skip && await skip(graph)) {
1012
+ // The tombstone is the authority: what this restore finds here is either residue from a
1013
+ // restore that raced the delete — removed under the lock — or a graph a save re-created
1014
+ // after the delete and before the tombstone revival cleared it. Erasing that re-creation
1015
+ // would lose a save that already succeeded, so only an unpublished folder is removed.
1016
+ if (!await publishedRevision(folder))
1017
+ await removeLockedFolder(folder);
1018
+ return { graph, restored: false };
1019
+ }
1020
+ // The latest pointer is read before any write: the floor verdict below needs it, and a
1021
+ // damaged pointer must refuse the restore before the folder receives new content.
1022
+ let current = 0;
1023
+ try {
1024
+ const raw = await readFile(join(folder, 'latest.json'), 'utf8');
1025
+ try {
1026
+ current = JSON.parse(raw);
1027
+ }
1028
+ catch {
1029
+ throw new GraphConflictError('The local latest pointer is damaged; preserve it as a conflict.');
1030
+ }
1031
+ }
1032
+ catch (error) {
1033
+ if (error.code !== 'ENOENT')
1034
+ throw error;
1035
+ }
1036
+ if (!Number.isSafeInteger(current) || current < 0)
1037
+ throw new GraphConflictError('Invalid latest revision');
1038
+ // A re-created id starts a new lineage. While a deletion floor is recorded for the id, cloud
1039
+ // revisions above the replacement's head never advance its latest pointer: the floor the
1040
+ // deleting machine recorded can sit behind the cloud (another device synced newer revisions
1041
+ // it never pulled), so a revision above the floor is not proof of new-lineage history.
1042
+ // New-lineage snapshots are unaffected — they were restored locally before their upload, so
1043
+ // their revisions never exceed the head. A device with no local graph at all still adopts
1044
+ // revisions above the floor: only what the deleting machine had already seen is known to
1045
+ // belong to the deleted lineage. Everything else stays in the immutable snapshot cache,
1046
+ // which would otherwise make the replacement open as the old graph again.
1047
+ const floor = floorOf ? await floorOf(graph) : undefined;
1048
+ if (floor !== undefined && current < graph.revision && (current >= 1 || graph.revision <= floor)) {
1049
+ // A live replacement can still take a later revision of its own lineage: storage pins
1050
+ // metadata.createdAt per lineage (a save takes it from the stored head, never from the
1051
+ // submitted graph), every save of the lineage preserves it, and a foreign lineage cannot
1052
+ // produce it. A snapshot above the head that carries the replacement's creation time is a
1053
+ // later edit of the replacement — another device that adopted it and saved — so it advances
1054
+ // the pointer like any save. Anything else belongs to the deleted lineage the floor keeps
1055
+ // out: the replacement is young, or the revision predates it, or no replacement lives here.
1056
+ let replacementCreatedAt;
1057
+ if (current >= 1) {
1058
+ // An unreadable head cannot vouch for any lineage, so the verdict stays refusal.
1059
+ try {
1060
+ replacementCreatedAt = JSON.parse(await readFile(join(folder, `${current}.json`), 'utf8'))?.metadata?.createdAt;
1061
+ }
1062
+ catch {
1063
+ replacementCreatedAt = undefined;
1064
+ }
1065
+ }
1066
+ if (replacementCreatedAt === undefined || graph.metadata?.createdAt !== replacementCreatedAt)
1067
+ return { graph, restored: false };
1068
+ }
957
1069
  const snapshot = join(folder, `${graph.revision}.json`);
958
1070
  let exists = false;
959
1071
  try {
@@ -975,27 +1087,11 @@ export async function restoreGraphRevision(input, directory) {
975
1087
  }
976
1088
  if (!exists)
977
1089
  await writeFile(snapshot, JSON.stringify(graph, null, 2) + '\n', { flag: 'wx', mode: 0o600 });
978
- let current = 0;
979
- try {
980
- const raw = await readFile(join(folder, 'latest.json'), 'utf8');
981
- try {
982
- current = JSON.parse(raw);
983
- }
984
- catch {
985
- throw new GraphConflictError('The local latest pointer is damaged; preserve it as a conflict.');
986
- }
987
- }
988
- catch (error) {
989
- if (error.code !== 'ENOENT')
990
- throw error;
991
- }
992
- if (!Number.isSafeInteger(current) || current < 0)
993
- throw new GraphConflictError('Invalid latest revision');
994
1090
  if (graph.revision > current) {
995
1091
  await writeFile(temp, JSON.stringify(graph.revision), { flag: 'wx', mode: 0o600 });
996
1092
  await rename(temp, join(folder, 'latest.json'));
997
1093
  }
998
- return graph;
1094
+ return { graph, restored: true };
999
1095
  }
1000
1096
  finally {
1001
1097
  await unlink(temp).catch(() => { });
@@ -1008,9 +1104,9 @@ export async function loadGraph(id, revision, directory = configDirectory()) {
1008
1104
  if (revision !== undefined && (!Number.isSafeInteger(revision) || revision < 1))
1009
1105
  throw new Error('Invalid graph revision');
1010
1106
  if (id === 'default') {
1011
- if (revision !== undefined && ![1, 2, 3, 4, 5].includes(revision))
1107
+ if (revision !== undefined && ![1, 2, 3, 4, 5, 6].includes(revision))
1012
1108
  throw new Error('Default graph revision does not exist');
1013
- return structuredClone(revision === 1 ? LEGACY_DEFAULT_HARNESS : revision === 2 ? DEFAULT_HARNESS_REVISION_2 : revision === 3 ? DEFAULT_HARNESS_REVISION_3 : revision === 4 ? DEFAULT_HARNESS_REVISION_4 : DEFAULT_HARNESS);
1109
+ return structuredClone(revision === 1 ? LEGACY_DEFAULT_HARNESS : revision === 2 ? DEFAULT_HARNESS_REVISION_2 : revision === 3 ? DEFAULT_HARNESS_REVISION_3 : revision === 4 ? DEFAULT_HARNESS_REVISION_4 : revision === 5 ? DEFAULT_HARNESS_REVISION_5 : DEFAULT_HARNESS);
1014
1110
  }
1015
1111
  const folder = join(directory, 'graphs', id);
1016
1112
  const selected = revision ?? JSON.parse(await readFile(join(folder, 'latest.json'), 'utf8'));
@@ -1100,3 +1196,32 @@ export async function saveGraph(input, expectedRevision, directory = configDirec
1100
1196
  await releaseLock();
1101
1197
  }
1102
1198
  }
1199
+ /**
1200
+ * Remove a saved graph and its whole revision history.
1201
+ *
1202
+ * The save lock serializes against a save or cloud restore of the same graph, so a delete cannot
1203
+ * race one into leaving a half-written folder behind. The folder leaves the live path in one
1204
+ * rename while the lock is held, so a save that lands during the removal writes into a fresh
1205
+ * folder and survives it. Deleting the bundled `default` is refused: it has no storage to remove,
1206
+ * and a hidden preset would only return on the next launch.
1207
+ */
1208
+ export async function deleteGraph(id, directory = configDirectory(), options = {}) {
1209
+ if (!validId(id) || id === 'default')
1210
+ throw new Error('Invalid graph id');
1211
+ const folder = join(directory, 'graphs', id);
1212
+ let releaseLock;
1213
+ try {
1214
+ releaseLock = await acquireSaveLock(folder);
1215
+ }
1216
+ catch (error) {
1217
+ if (error instanceof SaveLockBusyError)
1218
+ throw new GraphConflictError('Wait for the current save before deleting this graph.');
1219
+ throw error;
1220
+ }
1221
+ try {
1222
+ await removeLockedFolder(folder, options.onDetached);
1223
+ }
1224
+ finally {
1225
+ await releaseLock();
1226
+ }
1227
+ }