@andorra-labs/code 0.1.5 → 0.1.7

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 (224) 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 +526 -41
  4. package/dist/src/agent-mcp-catalog.d.ts +21 -0
  5. package/dist/src/agent-mcp-catalog.js +40 -0
  6. package/dist/src/agent-mcp.d.ts +36 -3
  7. package/dist/src/agent-mcp.js +114 -45
  8. package/dist/src/app-server/protocol.d.ts +57 -5
  9. package/dist/src/app-server/protocol.js +18 -1
  10. package/dist/src/app-server/workspace.d.ts +9 -1
  11. package/dist/src/app-server/workspace.js +50 -3
  12. package/dist/src/app-server.d.ts +115 -41
  13. package/dist/src/app-server.js +1316 -221
  14. package/dist/src/auth/AuthManager.d.ts +33 -1
  15. package/dist/src/auth/AuthManager.js +138 -10
  16. package/dist/src/auth/callback-page.d.ts +4 -0
  17. package/dist/src/auth/callback-page.js +70 -0
  18. package/dist/src/auth/callback.d.ts +39 -0
  19. package/dist/src/auth/callback.js +146 -22
  20. package/dist/src/auth/index.d.ts +10 -6
  21. package/dist/src/auth/index.js +2 -2
  22. package/dist/src/auth/store.d.ts +142 -3
  23. package/dist/src/auth/store.js +334 -13
  24. package/dist/src/auth/types.d.ts +17 -1
  25. package/dist/src/auth-commands.d.ts +11 -2
  26. package/dist/src/auth-commands.js +14 -7
  27. package/dist/src/automation-runner.d.ts +9 -0
  28. package/dist/src/automation-runner.js +22 -1
  29. package/dist/src/automation-tool.js +18 -3
  30. package/dist/src/automations.d.ts +5 -0
  31. package/dist/src/automations.js +11 -1
  32. package/dist/src/browser-captcha-tool.d.ts +54 -0
  33. package/dist/src/browser-captcha-tool.js +374 -0
  34. package/dist/src/browser-panel-tool.d.ts +7 -0
  35. package/dist/src/browser-panel-tool.js +74 -3
  36. package/dist/src/browser-runner.js +19 -4
  37. package/dist/src/browser-server.js +21 -1
  38. package/dist/src/browser-session.d.ts +16 -0
  39. package/dist/src/browser-session.js +35 -0
  40. package/dist/src/browser-ui/app.js +193 -3
  41. package/dist/src/browser-ui/style.css +15 -1
  42. package/dist/src/browser-view.d.ts +72 -4
  43. package/dist/src/browser-view.js +229 -17
  44. package/dist/src/capabilities.d.ts +9 -3
  45. package/dist/src/capabilities.js +20 -5
  46. package/dist/src/capsolver.d.ts +60 -0
  47. package/dist/src/capsolver.js +101 -0
  48. package/dist/src/claude-provider.d.ts +6 -0
  49. package/dist/src/claude-provider.js +34 -3
  50. package/dist/src/cli-executable.d.ts +33 -0
  51. package/dist/src/cli-executable.js +64 -0
  52. package/dist/src/cli-process.d.ts +47 -0
  53. package/dist/src/cli-process.js +113 -0
  54. package/dist/src/cli-sign-in.d.ts +68 -0
  55. package/dist/src/cli-sign-in.js +224 -0
  56. package/dist/src/cli.js +84 -26
  57. package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +1 -1
  58. package/dist/src/code-intelligence/CodeIntelligenceManager.js +5 -5
  59. package/dist/src/codex-provider.js +12 -0
  60. package/dist/src/coding-tools.d.ts +5 -0
  61. package/dist/src/coding-tools.js +98 -53
  62. package/dist/src/command-output-tap.d.ts +16 -0
  63. package/dist/src/command-output-tap.js +45 -0
  64. package/dist/src/command-screens.js +3 -3
  65. package/dist/src/commands.d.ts +15 -2
  66. package/dist/src/commands.js +14 -13
  67. package/dist/src/completion.d.ts +23 -5
  68. package/dist/src/completion.js +380 -17
  69. package/dist/src/config.d.ts +61 -0
  70. package/dist/src/config.js +276 -12
  71. package/dist/src/context-budget.d.ts +7 -0
  72. package/dist/src/context-budget.js +18 -1
  73. package/dist/src/deadline.js +6 -0
  74. package/dist/src/decision/FactContinuations.d.ts +41 -6
  75. package/dist/src/decision/FactContinuations.js +211 -64
  76. package/dist/src/decision/PreparedSteps.js +3 -1
  77. package/dist/src/decision/checks.d.ts +25 -0
  78. package/dist/src/decision/checks.js +77 -6
  79. package/dist/src/delegation-changes.d.ts +109 -0
  80. package/dist/src/delegation-changes.js +431 -0
  81. package/dist/src/extensions.d.ts +1 -0
  82. package/dist/src/extensions.js +16 -3
  83. package/dist/src/graph-provider-portability.js +2 -2
  84. package/dist/src/graph-quota.d.ts +1 -1
  85. package/dist/src/graph-quota.js +1 -1
  86. package/dist/src/graph-runner.js +35 -21
  87. package/dist/src/graph-selection.d.ts +6 -0
  88. package/dist/src/graph-selection.js +10 -0
  89. package/dist/src/graph-server.d.ts +8 -0
  90. package/dist/src/graph-server.js +76 -6
  91. package/dist/src/graph-sync.d.ts +65 -0
  92. package/dist/src/graph-sync.js +433 -13
  93. package/dist/src/graph-tool.d.ts +52 -0
  94. package/dist/src/graph-tool.js +136 -0
  95. package/dist/src/graph-ui/app.js +272 -50
  96. package/dist/src/graph-ui/controls.js +6 -0
  97. package/dist/src/graph-ui/drafts.js +39 -0
  98. package/dist/src/graph-ui/embed.js +1 -1
  99. package/dist/src/graph-ui/icons.js +1 -0
  100. package/dist/src/graph-ui/index.html +2 -2
  101. package/dist/src/graph-ui/skill-picker.js +242 -0
  102. package/dist/src/graph-ui/studio.css +7 -5
  103. package/dist/src/graph-ui/style.css +65 -12
  104. package/dist/src/graphs.d.ts +60 -5
  105. package/dist/src/graphs.js +191 -37
  106. package/dist/src/grok-provider.d.ts +50 -0
  107. package/dist/src/grok-provider.js +186 -0
  108. package/dist/src/handoffs.d.ts +13 -0
  109. package/dist/src/handoffs.js +31 -1
  110. package/dist/src/hardened-runtime.d.ts +4 -4
  111. package/dist/src/hardened-runtime.js +109 -9
  112. package/dist/src/managed-sign-in.d.ts +38 -0
  113. package/dist/src/managed-sign-in.js +169 -0
  114. package/dist/src/markdown.d.ts +5 -0
  115. package/dist/src/markdown.js +5 -2
  116. package/dist/src/mcp.js +11 -0
  117. package/dist/src/membership.d.ts +8 -1
  118. package/dist/src/membership.js +15 -5
  119. package/dist/src/model-metadata.js +14 -2
  120. package/dist/src/model-override.d.ts +10 -0
  121. package/dist/src/model-override.js +20 -0
  122. package/dist/src/opencode-cli-provider.d.ts +122 -0
  123. package/dist/src/opencode-cli-provider.js +415 -0
  124. package/dist/src/opencode-provider.js +23 -8
  125. package/dist/src/palette.d.ts +2 -0
  126. package/dist/src/palette.js +2 -0
  127. package/dist/src/permissions.d.ts +19 -1
  128. package/dist/src/permissions.js +30 -1
  129. package/dist/src/powershell-pool.d.ts +11 -2
  130. package/dist/src/powershell-pool.js +34 -5
  131. package/dist/src/provider-connection.js +36 -0
  132. package/dist/src/provider-engine.d.ts +2 -1
  133. package/dist/src/provider-engine.js +64 -13
  134. package/dist/src/provider-import.js +6 -1
  135. package/dist/src/provider-keys.d.ts +48 -0
  136. package/dist/src/provider-keys.js +121 -0
  137. package/dist/src/provider-settings.js +22 -3
  138. package/dist/src/providers.d.ts +12 -1
  139. package/dist/src/providers.js +27 -8
  140. package/dist/src/pull-requests.d.ts +123 -20
  141. package/dist/src/pull-requests.js +334 -84
  142. package/dist/src/qa/qa-authorize.js +9 -1
  143. package/dist/src/qa/runtime/ProcessManager.d.ts +6 -0
  144. package/dist/src/qa/runtime/ProcessManager.js +16 -0
  145. package/dist/src/react-runtime.js +106 -7
  146. package/dist/src/read-image.d.ts +30 -0
  147. package/dist/src/read-image.js +97 -0
  148. package/dist/src/remote/engine-pool.js +1 -1
  149. package/dist/src/run-progress.js +6 -1
  150. package/dist/src/run-records.d.ts +133 -27
  151. package/dist/src/run-records.js +320 -40
  152. package/dist/src/runtime.d.ts +38 -1
  153. package/dist/src/runtime.js +27 -4
  154. package/dist/src/save-lock.d.ts +11 -0
  155. package/dist/src/save-lock.js +29 -2
  156. package/dist/src/secret-redaction.d.ts +13 -0
  157. package/dist/src/secret-redaction.js +71 -0
  158. package/dist/src/session-summary.d.ts +10 -4
  159. package/dist/src/session-summary.js +14 -7
  160. package/dist/src/sessions.js +8 -2
  161. package/dist/src/shell.js +4 -1
  162. package/dist/src/side-panel.d.ts +1 -1
  163. package/dist/src/side-panel.js +1 -1
  164. package/dist/src/skill-commands.d.ts +2 -0
  165. package/dist/src/skill-commands.js +2 -0
  166. package/dist/src/skills/bundled/create-agent/SKILL.md +81 -0
  167. package/dist/src/skills/bundled/create-skill/SKILL.md +81 -0
  168. package/dist/src/skills/bundled/doctor/SKILL.md +43 -0
  169. package/dist/src/skills/bundled/graph-manager/SKILL.md +100 -0
  170. package/dist/src/skills/bundled/graph-manager/errors.md +38 -0
  171. package/dist/src/skills/bundled/graph-manager/patterns.md +78 -0
  172. package/dist/src/skills/bundled/manage-mcp/SKILL.md +75 -0
  173. package/dist/src/skills/bundled/manage-mcp/probe.md +165 -0
  174. package/dist/src/skills/bundled/manage-skills/SKILL.md +67 -0
  175. package/dist/src/skills/bundled/provenance.json +50 -0
  176. package/dist/src/skills/bundled/write-instructions/SKILL.md +42 -0
  177. package/dist/src/skills/invocable-skills.d.ts +41 -0
  178. package/dist/src/skills/invocable-skills.js +49 -0
  179. package/dist/src/skills/prompt-skills.d.ts +1 -0
  180. package/dist/src/skills/prompt-skills.js +33 -0
  181. package/dist/src/skills/runtime-skills.d.ts +4 -0
  182. package/dist/src/skills/runtime-skills.js +21 -0
  183. package/dist/src/structured-step.d.ts +55 -0
  184. package/dist/src/structured-step.js +85 -0
  185. package/dist/src/subagent-run.d.ts +1 -1
  186. package/dist/src/subagent-run.js +29 -33
  187. package/dist/src/telemetry/schema.d.ts +2 -2
  188. package/dist/src/telemetry/schema.js +3 -2
  189. package/dist/src/terminal-ui.d.ts +38 -0
  190. package/dist/src/terminal-ui.js +126 -28
  191. package/dist/src/timers.d.ts +21 -2
  192. package/dist/src/timers.js +12 -4
  193. package/dist/src/tool-dependencies.js +4 -0
  194. package/dist/src/tool-names.d.ts +18 -0
  195. package/dist/src/tool-names.js +26 -0
  196. package/dist/src/tools.d.ts +9 -0
  197. package/dist/src/tools.js +159 -20
  198. package/dist/src/trajectory.js +32 -12
  199. package/dist/src/transcript.js +5 -0
  200. package/dist/src/types.d.ts +36 -0
  201. package/dist/src/web-search.d.ts +59 -0
  202. package/dist/src/web-search.js +216 -0
  203. package/docs/agents/README.md +2 -2
  204. package/docs/agents/mcp-server.md +28 -3
  205. package/docs/agents/subagent-mode.md +7 -4
  206. package/docs/concepts/README.md +1 -1
  207. package/docs/concepts/security.md +4 -2
  208. package/docs/getting-started/accounts.md +15 -4
  209. package/docs/getting-started/configure-providers.md +30 -3
  210. package/docs/guides/README.md +1 -0
  211. package/docs/guides/browser.md +12 -0
  212. package/docs/guides/desktop-app.md +11 -4
  213. package/docs/guides/graph-builder.md +9 -1
  214. package/docs/guides/web-search.md +47 -0
  215. package/docs/reference/cli.md +4 -3
  216. package/docs/reference/config.md +4 -4
  217. package/docs/reference/slash-commands.md +2 -1
  218. package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +125 -0
  219. package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +295 -0
  220. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +7 -0
  221. package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +206 -0
  222. package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +291 -0
  223. package/package.json +1 -1
  224. package/tests/permissions-test-plan.md +2 -1
@@ -1,4 +1,4 @@
1
- import { permissionMode } from './permissions.js';
1
+ import { permissionMode, serializeApprovals } from './permissions.js';
2
2
  import { DecisionManager } from './decision/DecisionManager.js';
3
3
  import { randomUUID } from 'node:crypto';
4
4
  import { TodoStore } from './todos.js';
@@ -6,13 +6,13 @@ import { WidgetStore } from './widgets.js';
6
6
  import { isDeepStrictEqual } from 'node:util';
7
7
  import { validateGraph, nodeOutcomes, maxNodeVisitsOf } from './graphs.js';
8
8
  import { executeModifiedAgent, matchesOutput } from './agent-modifiers.js';
9
- import { executeAgentNode } from './agent-execution.js';
9
+ import { executeAgentNode, PLAN_DECISION_MARKER } from './agent-execution.js';
10
10
  import { resolveLimits, stopReasonSentence, withinToolBudget, generateWithUsage } from './runtime.js';
11
11
  import { bindUserWaits, createRuntimeBudget } from './deadline.js';
12
12
  import { capabilityTools } from './capabilities.js';
13
13
  import { canonicalToolName } from './tool-names.js';
14
14
  import { ArtifactStore } from './artifacts.js';
15
- import { resolveValue, validateValue, nodeOutputSchema } from './handoffs.js';
15
+ import { resolveMapping, validateValue, nodeOutputSchema } from './handoffs.js';
16
16
  import { memorySearchTool } from './memory/tools/memorySearchTool.js';
17
17
  import { resolveEfficiency } from './efficiency.js';
18
18
  import { collectWorkspaceFacts } from './workspace-facts.js';
@@ -196,7 +196,6 @@ export async function runGraph(graph, options) {
196
196
  const budget = createRuntimeBudget(options.context.signal, limits.wallTimeMs, options.context.runControl);
197
197
  const signal = budget.signal;
198
198
  const confirmedClarifications = [];
199
- let approvalQueue = Promise.resolve();
200
199
  // Bind before queueing: the queue must serialize the budget-aware `approve`, or a wait
201
200
  // that only enters the queue would still be charged to the run's clock.
202
201
  const awaiting = bindUserWaits(options.context, budget, signal);
@@ -204,14 +203,12 @@ export async function runGraph(graph, options) {
204
203
  const context = {
205
204
  ...awaiting,
206
205
  toolState: awaiting.toolState ?? { fileReads: new Map() },
207
- approve: (...args) => {
208
- const pending = approvalQueue.then(() => { args[2].throwIfAborted(); return awaiting.approve(...args); });
209
- approvalQueue = pending.catch(() => { });
210
- return pending;
211
- },
206
+ approve: serializeApprovals((...args) => awaiting.approve(...args), () => permissionMode(awaiting)),
212
207
  ...(askUser ? { askUser: async (...args) => {
213
208
  const answer = await askUser(...args);
214
- if (typeof answer === 'string' && answer.trim())
209
+ // A plan presentation is not a clarification pair to distill: the plan body rides its own
210
+ // journal events, and the verdict ('Approve plan') carries no reusable requirement.
211
+ if (typeof answer === 'string' && answer.trim() && !args[0].includes(PLAN_DECISION_MARKER))
215
212
  confirmedClarifications.push({ question: args[0], answer });
216
213
  return answer;
217
214
  } } : {}),
@@ -625,6 +622,12 @@ export async function runGraph(graph, options) {
625
622
  providers.set(provider, { ...resolved });
626
623
  }
627
624
  }
625
+ // A run that switched the session onto this graph hands the session's history to the first agent
626
+ // it starts — the entry node, or the first agent after an entry that is not one (an Action or an
627
+ // Approval cannot take model history) — whatever that agent's own history policy says. A resumed
628
+ // attempt in which an agent already completed is past that point and gets nothing more.
629
+ let entryHistoryPending = options.entryHistory === true
630
+ && !Object.keys(result.nodeResults ?? {}).some(nodeId => pinned.nodes[nodeId]?.type === 'agent');
628
631
  /**
629
632
  * @param steerSource - the steering callback this invocation may poll, or undefined to
630
633
  * run without steering. Steering is a single destructive queue, so handing the same
@@ -636,12 +639,26 @@ export async function runGraph(graph, options) {
636
639
  * when `undefined` is passed, so "no steering" would silently become "use the shared
637
640
  * source" and every branch would race again.
638
641
  */
642
+ // A node reads the shared queue (when its branch owns it) and, beside it, whatever is meant for that node
643
+ // alone. Both sources are called before either is awaited: each removes what it hands over synchronously,
644
+ // and the poll races the answer against the abort signal, so nothing may sit taken but not yet returned.
645
+ const nodeSteering = options.getNodeSteeringMessages;
646
+ const withNodeSteering = (shared, nodeId) => nodeSteering === undefined ? shared : async (signal) => {
647
+ const common = shared?.(signal);
648
+ const own = nodeSteering(nodeId, signal);
649
+ return [...(common === undefined ? [] : await common), ...await own];
650
+ };
639
651
  const invoke = async (activation, maxToolCalls, wallTimeMs, concurrencyBudget, steerSource, continuation) => {
640
652
  const nodeId = activation.nodeId;
641
653
  const node = pinned.nodes[nodeId];
642
654
  // A seeded activation carries its own continuation (the re-entered node's captured
643
655
  // conversation); the explicit argument keeps the pause/resume control path unchanged.
644
656
  continuation = continuation ?? activation.continuation;
657
+ // Only agent nodes are invoked, so the first invocation is the first agent the run starts, and
658
+ // it takes the seed. A visit that re-enters a saved conversation already holds whatever it was
659
+ // given; every later invocation, a loop back to the entry included, keeps its own policy.
660
+ const seedsEntryHistory = entryHistoryPending && !continuation;
661
+ entryHistoryPending = false;
645
662
  const narrow = (run, remaining) => remaining === undefined ? run : run === undefined ? remaining : Math.min(run, remaining);
646
663
  maxToolCalls = narrow(maxToolCalls, continuation?.state.remainingToolCalls);
647
664
  wallTimeMs = narrow(wallTimeMs, continuation?.state.remainingWallTimeMs);
@@ -686,7 +703,8 @@ export async function runGraph(graph, options) {
686
703
  // under the restored transcript mid-visit. Routing decides again on the visit's next
687
704
  // fresh activation, exactly as it would for any new node entry. The override rides the
688
705
  // node, so both executor paths resolve the routed pair through their normal machinery.
689
- const routedNode = activation.routedModel ? { ...node, provider: activation.routedModel.provider, model: activation.routedModel.model } : node;
706
+ const routed = activation.routedModel ? { ...node, provider: activation.routedModel.provider, model: activation.routedModel.model } : node;
707
+ const routedNode = seedsEntryHistory ? { ...routed, contextPolicy: { ...routed.contextPolicy, history: true } } : routed;
690
708
  const outcome = await (continuation && !continuation.state.copies ? executeAgentNode : executeModifiedAgent)(routedNode, {
691
709
  ...options,
692
710
  ...(activation.routedModel ? { modelPinned: true } : {}),
@@ -749,7 +767,7 @@ export async function runGraph(graph, options) {
749
767
  resolveProvider: id => { const resolved = providers.get(id); if (!resolved)
750
768
  throw new Error(`Provider is not available: ${id}`); return instrument(id, resolved); },
751
769
  mappedInputs: activation.inputs, predecessorOutputs,
752
- getSteeringMessages: steerSource,
770
+ getSteeringMessages: withNodeSteering(steerSource, nodeId),
753
771
  limits: { ...limits, maxToolCalls, wallTimeMs },
754
772
  onUsage: (usage, origin) => {
755
773
  addMeasuredUsage(liveUsage, usage);
@@ -830,9 +848,7 @@ export async function runGraph(graph, options) {
830
848
  currentNode = item.nodeId;
831
849
  const node = pinned.nodes[item.nodeId];
832
850
  const count = (visits.get(item.nodeId) ?? 0) + 1;
833
- const mapped = {};
834
- for (const [key, expression] of Object.entries(node.inputs ?? {}))
835
- mapped[key] = resolveValue(expression, { source: item.source, run: { input: runInput, state: runState, loop: { iteration: count } } });
851
+ const mapped = resolveMapping(node.inputs, { source: item.source, run: { input: runInput, state: runState, loop: { iteration: count } } }, node.inputSchema);
836
852
  mergeInputs(item.inputs, mapped, item.nodeId);
837
853
  if (node.inputSchema)
838
854
  validateValue(node.inputSchema, item.inputs, `Node ${item.nodeId} inputs`);
@@ -965,9 +981,7 @@ export async function runGraph(graph, options) {
965
981
  break;
966
982
  }
967
983
  const scope = { source: activation.source, run: { input: runInput, state: runState, loop: { iteration: count } } };
968
- const configuredInputs = {};
969
- for (const [key, expression] of Object.entries(node.inputs ?? {}))
970
- configuredInputs[key] = resolveValue(expression, scope);
984
+ const configuredInputs = resolveMapping(node.inputs, scope, node.inputSchema);
971
985
  mergeInputs(activation.inputs, configuredInputs, nodeId);
972
986
  if (node.inputSchema)
973
987
  validateValue(node.inputSchema, activation.inputs, `Node ${nodeId} inputs`);
@@ -1165,9 +1179,9 @@ export async function runGraph(graph, options) {
1165
1179
  delete queued.conversation;
1166
1180
  if (executed.has(targetKey) || queued)
1167
1181
  continue;
1168
- const inputs = {};
1169
- for (const [key, expression] of Object.entries(edge.inputMapping ?? {}))
1170
- inputs[key] = resolveValue(expression, { source: completion, run: { input: runInput, state: runState, loop: { iteration: count } } });
1182
+ // An optional input whose source field was omitted stays absent (see resolveMapping): the
1183
+ // graph's validation accepted that mapping, so the target runs without it.
1184
+ const inputs = resolveMapping(edge.inputMapping, { source: completion, run: { input: runInput, state: runState, loop: { iteration: count } } }, target.inputSchema);
1171
1185
  const incoming = { ...(node.modifiers?.parallel?.mode === 'branches' ? { parallelGroup: `${nodeId}:${activation.generation}:${count}`, concurrency: node.modifiers.parallel.maxConcurrent } : {}), nodeId: edge.target, generation, path, inputs, source: completion, predecessors: { [nodeId]: completion } };
1172
1186
  if (node.type === 'agent' && target.type === 'agent' && node.contextPolicy?.conversation !== 'isolate')
1173
1187
  incoming.conversation = conversations.get(activation);
@@ -15,3 +15,9 @@ export declare function identityStillHolds(declared: {
15
15
  /** Legacy installation-wide selections have no reliable owner. Require explicit reselection. */
16
16
  export declare function configuredGraphSelection(config: Config, subject?: string): string;
17
17
  export declare function saveGraphSelection(config: Config, graph: string, subject?: string): void;
18
+ /**
19
+ * A deleted graph must not stay an account's configured editor default: startup selects it, and
20
+ * the preflight falls back only for a membership refusal, so its missing file would abort the
21
+ * launch. Point the account back at the bundled preset; other accounts keep their selections.
22
+ */
23
+ export declare function resetDeletedGraphSelection(config: Config, subject: string, graph: string): Config | undefined;
@@ -29,3 +29,13 @@ export function saveGraphSelection(config, graph, subject) {
29
29
  config.graphSelections = { ...config.graphSelections, [subject]: graph };
30
30
  delete config.graph;
31
31
  }
32
+ /**
33
+ * A deleted graph must not stay an account's configured editor default: startup selects it, and
34
+ * the preflight falls back only for a membership refusal, so its missing file would abort the
35
+ * launch. Point the account back at the bundled preset; other accounts keep their selections.
36
+ */
37
+ export function resetDeletedGraphSelection(config, subject, graph) {
38
+ if (config.graphSelections?.[subject] !== graph)
39
+ return undefined;
40
+ return { ...config, graphSelections: { ...config.graphSelections, [subject]: 'default' } };
41
+ }
@@ -1,13 +1,21 @@
1
1
  import { type Config } from './config.js';
2
2
  import { type Membership } from './membership.js';
3
+ import { GraphSync } from './graph-sync.js';
3
4
  export declare function createGraphSessionCheck(subject: string | undefined, status?: (signal?: AbortSignal) => Promise<import("./auth/types.js").AuthStatus>, membership?: (signal?: AbortSignal, home?: string) => Promise<Membership>): () => Promise<void>;
4
5
  export declare function requireGraphProviders(directory?: string): Promise<Config>;
5
6
  export declare function startGraphServer(directory?: string, checkMembership?: () => Promise<unknown>, options?: {
6
7
  membership?: () => Promise<Membership>;
8
+ sync?: GraphSync;
7
9
  }): Promise<{
8
10
  url: string;
9
11
  origin: string;
10
12
  token: string;
11
13
  close: () => Promise<void>;
12
14
  }>;
15
+ /**
16
+ * Reset the configured selection only after the deletion succeeds. Otherwise a graph-lock
17
+ * timeout would change the next CLI launch even though the graph still exists. A crash
18
+ * between removal and reset is handled by the CLI's missing-selection fallback.
19
+ */
20
+ export declare function deleteGraphWithTombstone(id: string, graphDirectory: string, directory: string, subject: string | undefined, sync: Pick<GraphSync, 'forgetGraph'> | undefined): Promise<void>;
13
21
  export declare function launchGraphEditor(noOpen?: boolean): Promise<void>;
@@ -5,8 +5,10 @@ import { join } from 'node:path';
5
5
  import { execFile } from 'node:child_process';
6
6
  import { changeConfigFile, configDirectory, loadConfig, validateConfig } from './config.js';
7
7
  import { stampGraphProviderProfiles } from './graph-provider-portability.js';
8
- import { listGraphs, loadGraph, saveGraph, validateGraph, migrateGraphForEditor } from './graphs.js';
8
+ import { resetDeletedGraphSelection } from './graph-selection.js';
9
+ import { listGraphs, loadGraph, saveGraph, validateGraph, migrateGraphForEditor, deleteGraph, withoutDeletedGraphs } from './graphs.js';
9
10
  import { createTools } from './tools.js';
11
+ import { AutomationStore } from './automations.js';
10
12
  import { deleteAgentDefinition, exportAgentDefinition, importAgentDefinition, listAgentDefinitions, readAgentDefinition, saveAgentDefinition, validateAgentDefinition } from './agent-definitions.js';
11
13
  import { discoverModelMetadata, resolveModelContext } from './model-metadata.js';
12
14
  import { MODEL_LISTING_TIMEOUT_MS, providerLabel, providerModels, recordProviderModel } from './providers.js';
@@ -17,6 +19,7 @@ import { getAuthStatus } from './auth/index.js';
17
19
  import { readActivity } from './activity.js';
18
20
  import { graphStorageDirectory } from './graph-account.js';
19
21
  import { GraphSync } from './graph-sync.js';
22
+ import { editorSkillCatalog } from './skills/invocable-skills.js';
20
23
  import { graphRevisionHistory, previewGraphRoutes, studioRuns, studioRunEvents } from './graph-studio-features.js';
21
24
  const setupMessage = 'No providers configured. Run `andorra` and open `/providers` first, then retry `andorra graph`.';
22
25
  export function createGraphSessionCheck(subject, status = getAuthStatus, membership = getMembership) {
@@ -52,11 +55,14 @@ export async function requireGraphProviders(directory = configDirectory()) {
52
55
  if (!value || typeof value !== 'object' || !Array.isArray(value.providers) || !value.providers.length)
53
56
  throw new Error(setupMessage);
54
57
  try {
55
- return validateConfig(value);
58
+ validateConfig({ ...value, providerKeys: undefined, providerKeysPendingDeletion: undefined });
56
59
  }
57
60
  catch {
58
61
  throw new Error('Invalid provider configuration. Run `andorra` and open `/providers` to repair it.');
59
62
  }
63
+ // Loaded through the configuration reader so saved API keys come back from the OS credential store;
64
+ // a store that cannot be read says so rather than passing for an invalid file.
65
+ return await loadConfig(directory);
60
66
  }
61
67
  /** Graph editing may be provider-free, but invalid config keeps actionable repair guidance. */
62
68
  async function editorConfig(directory) {
@@ -73,7 +79,8 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
73
79
  // A caller supplying its own authorization check has no production account binding.
74
80
  const account = checkMembership === readGraphMembership ? await getAuthStatus() : { signedIn: false, subject: undefined };
75
81
  const graphDirectory = account.subject ? await graphStorageDirectory(directory, account.subject, true) : directory;
76
- const sync = account.subject ? new GraphSync(graphDirectory, account.subject) : undefined;
82
+ // A caller may bring its own store of drafts: a test has no signed-in account to bind one to.
83
+ const sync = options.sync ?? (account.subject ? new GraphSync(graphDirectory, account.subject) : undefined);
77
84
  await sync?.start();
78
85
  const checkSession = checkMembership === readGraphMembership ? createGraphSessionCheck(account.subject) : checkMembership;
79
86
  // Whether this account is held to the free allowance. A membership answer that could not be read
@@ -103,9 +110,11 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
103
110
  '/studio.css': ['studio.css', 'text/css; charset=utf-8'],
104
111
  '/embed.js': ['embed.js', 'text/javascript; charset=utf-8'],
105
112
  '/sidebar.js': ['sidebar.js', 'text/javascript; charset=utf-8'],
113
+ '/drafts.js': ['drafts.js', 'text/javascript; charset=utf-8'],
106
114
  '/edge-router.js': ['edge-router.js', 'text/javascript; charset=utf-8'],
107
115
  '/icons.js': ['icons.js', 'text/javascript; charset=utf-8'],
108
116
  '/controls.js': ['controls.js', 'text/javascript; charset=utf-8'],
117
+ '/skill-picker.js': ['skill-picker.js', 'text/javascript; charset=utf-8'],
109
118
  '/controls.css': ['controls.css', 'text/css; charset=utf-8'],
110
119
  '/style.css': ['style.css', 'text/css; charset=utf-8'],
111
120
  '/library.css': ['library.css', 'text/css; charset=utf-8'],
@@ -235,6 +244,11 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
235
244
  reply(res, 200, sync?.status ?? { state: 'pending', detail: 'Saved locally' });
236
245
  return;
237
246
  }
247
+ // The prompt fields' `/` picker, and the names they warn about: this machine's skills.
248
+ if (req.method === 'GET' && path === '/api/skills') {
249
+ reply(res, 200, await editorSkillCatalog(config, AbortSignal.timeout(MODEL_LISTING_TIMEOUT_MS), directory));
250
+ return;
251
+ }
238
252
  if (req.method === 'GET' && path === '/api/drafts') {
239
253
  reply(res, 200, sync ? await sync.drafts() : []);
240
254
  return;
@@ -317,7 +331,8 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
317
331
  graphMigrationErrors.push({ id, name: id, error: error instanceof Error ? error.message : 'Graph load failed' });
318
332
  });
319
333
  const free = await freeTier();
320
- for (const saved of savedGraphs) {
334
+ // Deleted graphs stay out of the editor; restoring one goes through the graph MCP server.
335
+ for (const saved of withoutDeletedGraphs(savedGraphs)) {
321
336
  try {
322
337
  graphs.push(migrateGraphForEditor(saved, { addOrchestrator: !free }));
323
338
  }
@@ -328,7 +343,7 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
328
343
  const plan = free
329
344
  ? { paid: false, customGraphLimit: FREE_CUSTOM_GRAPH_LIMIT, nodeLimit: FREE_GRAPH_NODE_LIMIT, ...await readGraphQuota(graphDirectory, savedGraphs) }
330
345
  : { paid: true };
331
- reply(res, 200, { plan, graphs, graphMigrationErrors, definitions: await listAgentDefinitions(directory), defaultProvider: config.provider, providers: providerRegistryPayload(config.providers), tools: [...createTools().filter(tool => tool.providerVisible !== false).map(tool => tool.name), 'git_read', 'read_artifact', 'write_artifact', 'repo_explore', 'memory_search', 'read_skill_resource', 'browser.panel'], runtime: { spawnAvailable: true, rawShellForSubagents: false, browser: true, deployment: false } });
346
+ reply(res, 200, { plan, graphs, graphMigrationErrors, definitions: await listAgentDefinitions(directory), defaultProvider: config.provider, providers: providerRegistryPayload(config.providers), tools: [...createTools().filter(tool => tool.providerVisible !== false).map(tool => tool.name), 'git_read', 'read_artifact', 'write_artifact', 'repo_explore', 'memory_search', 'read_skill_resource', 'browser.panel', 'browser.incognito'], runtime: { spawnAvailable: true, rawShellForSubagents: false, browser: true, deployment: false } });
332
347
  return;
333
348
  }
334
349
  if (req.method === 'GET' && /^\/api\/graphs\/[\w-]+\/revisions$/.test(path)) {
@@ -363,6 +378,20 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
363
378
  reply(res, 200, { ...migrateGraphForEditor(saved, { addOrchestrator: !await freeTier() }), ...(saved.schemaVersion < 3 ? { editorMigration: true } : {}) });
364
379
  return;
365
380
  }
381
+ if (req.method === 'DELETE' && /^\/api\/graphs\/[\w-]+$/.test(path)) {
382
+ const id = path.split('/').at(-1);
383
+ // The preset is bundled with the CLI: it has no storage to remove, and hiding it would
384
+ // only last until the next launch.
385
+ if (id === 'default') {
386
+ reply(res, 400, { error: 'The bundled default graph cannot be deleted.' });
387
+ return;
388
+ }
389
+ // forgetGraph schedules the post-delete sync pass itself; scheduling another here
390
+ // would bump the pass generation and traverse the whole history twice per delete.
391
+ await deleteGraphWithTombstone(id, graphDirectory, directory, account.subject, sync);
392
+ reply(res, 200, { deleted: id });
393
+ return;
394
+ }
366
395
  if (req.method === 'GET' && /^\/api\/definitions\/[\w-]+\/export$/.test(path)) {
367
396
  reply(res, 200, exportAgentDefinition(await readAgentDefinition(path.split('/')[3], directory)));
368
397
  return;
@@ -373,7 +402,7 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
373
402
  reply(res, 200, { deleted: id });
374
403
  return;
375
404
  }
376
- if (req.method === 'POST' && ['/api/graphs', '/api/drafts', '/api/validate', '/api/definitions', '/api/definitions/import', '/api/preview'].includes(path)) {
405
+ if (req.method === 'POST' && ['/api/graphs', '/api/drafts', '/api/drafts/clear', '/api/validate', '/api/definitions', '/api/definitions/import', '/api/preview'].includes(path)) {
377
406
  if (!req.headers['content-type']?.startsWith('application/json')) {
378
407
  reply(res, 415, { error: 'Expected application/json' });
379
408
  return;
@@ -389,6 +418,19 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
389
418
  chunks.push(Buffer.from(chunk));
390
419
  }
391
420
  const value = JSON.parse(Buffer.concat(chunks).toString('utf8'));
421
+ // The deletion marker is set only through the graph MCP server's delete tool, which confirms
422
+ // with the person and checks automations first; an ordinary save may not carry it.
423
+ if (path === '/api/graphs' && value && typeof value === 'object' && value.metadata && typeof value.metadata === 'object' && Object.hasOwn(value.metadata, 'deletedAt')) {
424
+ reply(res, 400, { error: 'metadata.deletedAt is reserved for deleting a graph through the graph MCP server.' });
425
+ return;
426
+ }
427
+ if (path === '/api/drafts/clear') {
428
+ if (!sync)
429
+ throw new Error('Sign in to persist drafts');
430
+ await sync.clearDrafts(value?.graphIds);
431
+ reply(res, 200, await sync.drafts());
432
+ return;
433
+ }
392
434
  if (path === '/api/drafts') {
393
435
  if (!sync)
394
436
  throw new Error('Sign in to persist drafts');
@@ -432,6 +474,9 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
432
474
  }
433
475
  const expected = graph.revision === 0 ? null : graph.revision;
434
476
  const saved = await freeTier() ? await saveFreeTierGraph(stamped, expected, graphDirectory) : await saveGraph(stamped, expected, graphDirectory);
477
+ // Do not claim a successful re-creation while its tombstone still excludes cloud
478
+ // uploads and drafts. reviveGraph retries account-lock contention and reports errors.
479
+ await sync?.reviveGraph(saved.id);
435
480
  void sync?.sync();
436
481
  reply(res, 200, saved);
437
482
  return;
@@ -466,6 +511,31 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
466
511
  origin = `http://127.0.0.1:${address.port}`;
467
512
  return { url: `${origin}/#token=${token}`, origin, token, close: async () => { await sync?.close(); await new Promise((resolve, reject) => { server.closeAllConnections(); server.close(error => error ? reject(error) : resolve()); }); } };
468
513
  }
514
+ /**
515
+ * Reset the configured selection only after the deletion succeeds. Otherwise a graph-lock
516
+ * timeout would change the next CLI launch even though the graph still exists. A crash
517
+ * between removal and reset is handled by the CLI's missing-selection fallback.
518
+ */
519
+ export async function deleteGraphWithTombstone(id, graphDirectory, directory, subject, sync) {
520
+ // An automation would fail at its next run; the user decides what it runs instead. The graph
521
+ // MCP server's delete tool applies the same check, so the editor cannot bypass it.
522
+ const users = (await new AutomationStore(directory).list()).filter(job => job.execution?.graph === id);
523
+ if (users.length)
524
+ throw new Error('Graph ' + id + ' is run by automation'
525
+ + (users.length === 1 ? ' ' : 's ') + users.map(job => '"' + job.name + '"').join(', ')
526
+ + '. Change or remove ' + (users.length === 1 ? 'it' : 'them') + ' first.');
527
+ if (sync) {
528
+ // forgetGraph already detaches the old folder under the graph lock. A second removal
529
+ // here could erase a new graph that was saved under the same id after that detach.
530
+ await sync.forgetGraph(id);
531
+ }
532
+ else {
533
+ await deleteGraph(id, graphDirectory);
534
+ }
535
+ if (subject) {
536
+ await changeConfigFile(directory, current => resetDeletedGraphSelection(current, subject, id) ?? current);
537
+ }
538
+ }
469
539
  export async function launchGraphEditor(noOpen = false) {
470
540
  const app = await startGraphServer();
471
541
  process.stdout.write(`Andorra Graph: ${app.url}\nPress Ctrl+C to stop the local server.\n`);
@@ -38,11 +38,76 @@ export declare class GraphSync {
38
38
  revision: number;
39
39
  updatedAt: number;
40
40
  }[]>;
41
+ /**
42
+ * Draft snapshots are immutable, and every sweep restores the ones the account holds, so a draft
43
+ * the user cleared cannot be unlinked: it would come back. Each cleared graph instead has its own
44
+ * marker file under `graph-drafts-cleared/`, naming the instant up to which its drafts are
45
+ * cleared and any snapshot dated after that instant (saved under a clock that ran ahead) that
46
+ * was cleared with them. The listing leaves those out; a later autosave is a new snapshot, newer
47
+ * than the mark, and is listed again. A cleared snapshot stays on disk and still opens by hash.
48
+ *
49
+ * One file per graph, replaced whole, so two editors sharing this folder cannot drop each
50
+ * other's clears: clears of different graphs touch different files, and two clears of the same
51
+ * graph each record every draft that graph had.
52
+ */
53
+ private readClearedDrafts;
54
+ /** Clear every draft the named graphs have right now, whatever clock dated them. */
55
+ clearDrafts(graphIds: string[]): Promise<void>;
41
56
  draft(hash: string): Promise<Graph>;
57
+ /**
58
+ * The tombstones and their lineage floors are one durable record. Keeping them in one atomic
59
+ * replacement means a crash cannot publish a deletion without its floor (or vice versa).
60
+ * The legacy split files are read only for migration; the next mutation writes the combined file.
61
+ */
62
+ private readDeletionState;
63
+ private readDeletedGraphs;
64
+ private readDeletedRevisions;
65
+ /**
66
+ * Read-modify-write the deletion state under one account-wide lock. Two editors deleting
67
+ * different graphs hold different graphs' save locks, so only a lock across the account stops
68
+ * one replacement from dropping the other's deletion; reviveGraph is serialized by it too.
69
+ * A deletion records its floor in the same lock hold, so a revival can never inherit a floor
70
+ * without the tombstone that justifies it.
71
+ */
72
+ private updateDeletionState;
73
+ /**
74
+ * The account-wide lock every tombstone change and deletion tail runs under: two editors
75
+ * deleting different graphs hold different graphs' save locks, so only a lock across the
76
+ * account stops one replacement from dropping the other's deletion, and reviveGraph is
77
+ * serialized by it too.
78
+ */
79
+ private acquireAccountLock;
80
+ /**
81
+ * The user deleted a graph. Record that before removing anything: the tombstone is written under
82
+ * the graph's save lock, and every later cloud restore re-reads it under the same lock, so a pass
83
+ * running while the delete lands cannot write the graph back. The graph's drafts die with it —
84
+ * each draft snapshot names a graph, and none is left to open. The newest revision the folder had
85
+ * reached is recorded with the tombstone: it is the floor a later revival needs to keep the old
86
+ * lineage's cloud revisions from advancing a replacement.
87
+ */
88
+ forgetGraph(id: string): Promise<void>;
89
+ /** Remove every draft that names the graph: its drafts die with it. The caller holds the account lock. */
90
+ private pruneDrafts;
91
+ /**
92
+ * A graph with this id was saved again: its cloud snapshots may restore once more. The floor
93
+ * recorded at the deletion stays — it is what keeps the old lineage's revisions from advancing
94
+ * the replacement's latest pointer.
95
+ */
96
+ reviveGraph(id: string): Promise<void>;
42
97
  sync(): Promise<void>;
43
98
  private now;
44
99
  private checkBudget;
45
100
  private cached;
101
+ /**
102
+ * A committed tombstone has two possible local folders: the old folder an interrupted
103
+ * delete did not detach, or a replacement published while revival waited for the account
104
+ * lock. The deletion marker and head at deletion identify only the former. Legacy
105
+ * tombstones have no marker, so retain the existing conservative cached-head check.
106
+ *
107
+ * Lock order matches forgetGraph (graph, then account); inspect fresh state only while
108
+ * holding both locks, so a concurrent save/revival cannot be removed by a stale pass.
109
+ */
110
+ private reconcileDeletedFolders;
46
111
  private request;
47
112
  private perform;
48
113
  private restoreDraft;