@andorra-labs/code 0.1.6 → 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 (108) hide show
  1. package/dist/src/agent-execution.js +404 -25
  2. package/dist/src/agent-mcp-catalog.d.ts +21 -0
  3. package/dist/src/agent-mcp-catalog.js +40 -0
  4. package/dist/src/agent-mcp.d.ts +19 -3
  5. package/dist/src/agent-mcp.js +18 -44
  6. package/dist/src/app-server/protocol.d.ts +25 -3
  7. package/dist/src/app-server/protocol.js +5 -1
  8. package/dist/src/app-server/workspace.d.ts +8 -1
  9. package/dist/src/app-server/workspace.js +43 -2
  10. package/dist/src/app-server.js +88 -3
  11. package/dist/src/auth/AuthManager.d.ts +33 -1
  12. package/dist/src/auth/AuthManager.js +138 -10
  13. package/dist/src/auth/callback-page.d.ts +4 -0
  14. package/dist/src/auth/callback-page.js +70 -0
  15. package/dist/src/auth/callback.d.ts +39 -0
  16. package/dist/src/auth/callback.js +146 -22
  17. package/dist/src/auth/index.d.ts +10 -6
  18. package/dist/src/auth/index.js +2 -2
  19. package/dist/src/auth/store.d.ts +142 -3
  20. package/dist/src/auth/store.js +334 -13
  21. package/dist/src/auth/types.d.ts +17 -1
  22. package/dist/src/auth-commands.d.ts +11 -2
  23. package/dist/src/auth-commands.js +14 -7
  24. package/dist/src/automation-tool.js +10 -2
  25. package/dist/src/automations.d.ts +5 -0
  26. package/dist/src/automations.js +10 -0
  27. package/dist/src/capabilities.d.ts +9 -3
  28. package/dist/src/capabilities.js +7 -3
  29. package/dist/src/cli.js +31 -4
  30. package/dist/src/codex-provider.js +12 -0
  31. package/dist/src/coding-tools.d.ts +5 -0
  32. package/dist/src/coding-tools.js +54 -48
  33. package/dist/src/commands.d.ts +5 -1
  34. package/dist/src/commands.js +7 -6
  35. package/dist/src/completion.js +46 -0
  36. package/dist/src/config.d.ts +48 -0
  37. package/dist/src/config.js +248 -10
  38. package/dist/src/context-budget.d.ts +7 -0
  39. package/dist/src/context-budget.js +18 -1
  40. package/dist/src/decision/FactContinuations.d.ts +41 -6
  41. package/dist/src/decision/FactContinuations.js +211 -64
  42. package/dist/src/decision/PreparedSteps.js +3 -1
  43. package/dist/src/decision/checks.d.ts +25 -0
  44. package/dist/src/decision/checks.js +77 -6
  45. package/dist/src/delegation-changes.d.ts +109 -0
  46. package/dist/src/delegation-changes.js +431 -0
  47. package/dist/src/graph-server.d.ts +1 -0
  48. package/dist/src/graph-server.js +15 -3
  49. package/dist/src/graph-sync.d.ts +15 -0
  50. package/dist/src/graph-sync.js +50 -1
  51. package/dist/src/graph-tool.d.ts +52 -0
  52. package/dist/src/graph-tool.js +136 -0
  53. package/dist/src/graph-ui/app.js +212 -43
  54. package/dist/src/graph-ui/controls.js +6 -0
  55. package/dist/src/graph-ui/drafts.js +39 -0
  56. package/dist/src/graph-ui/embed.js +1 -1
  57. package/dist/src/graph-ui/index.html +2 -2
  58. package/dist/src/graph-ui/studio.css +7 -5
  59. package/dist/src/graph-ui/style.css +46 -12
  60. package/dist/src/graphs.d.ts +15 -2
  61. package/dist/src/graphs.js +42 -13
  62. package/dist/src/hardened-runtime.d.ts +4 -4
  63. package/dist/src/hardened-runtime.js +109 -9
  64. package/dist/src/powershell-pool.d.ts +9 -0
  65. package/dist/src/powershell-pool.js +16 -0
  66. package/dist/src/provider-keys.d.ts +48 -0
  67. package/dist/src/provider-keys.js +121 -0
  68. package/dist/src/pull-requests.d.ts +14 -5
  69. package/dist/src/pull-requests.js +28 -10
  70. package/dist/src/qa/runtime/ProcessManager.d.ts +6 -0
  71. package/dist/src/qa/runtime/ProcessManager.js +16 -0
  72. package/dist/src/react-runtime.js +30 -2
  73. package/dist/src/read-image.d.ts +30 -0
  74. package/dist/src/read-image.js +97 -0
  75. package/dist/src/secret-redaction.d.ts +13 -0
  76. package/dist/src/secret-redaction.js +71 -0
  77. package/dist/src/session-summary.d.ts +10 -4
  78. package/dist/src/session-summary.js +14 -7
  79. package/dist/src/sessions.js +4 -1
  80. package/dist/src/skills/bundled/graph-manager/SKILL.md +14 -11
  81. package/dist/src/skills/bundled/provenance.json +1 -1
  82. package/dist/src/telemetry/schema.d.ts +1 -1
  83. package/dist/src/telemetry/schema.js +1 -1
  84. package/dist/src/terminal-ui.d.ts +9 -0
  85. package/dist/src/terminal-ui.js +14 -0
  86. package/dist/src/tool-dependencies.js +4 -0
  87. package/dist/src/tools.d.ts +9 -0
  88. package/dist/src/tools.js +116 -11
  89. package/dist/src/transcript.js +5 -0
  90. package/dist/src/types.d.ts +13 -0
  91. package/dist/src/web-search.d.ts +59 -0
  92. package/dist/src/web-search.js +216 -0
  93. package/docs/agents/README.md +2 -2
  94. package/docs/agents/mcp-server.md +15 -2
  95. package/docs/concepts/README.md +1 -1
  96. package/docs/concepts/security.md +2 -2
  97. package/docs/getting-started/accounts.md +15 -4
  98. package/docs/getting-started/configure-providers.md +1 -1
  99. package/docs/guides/README.md +1 -0
  100. package/docs/guides/desktop-app.md +1 -1
  101. package/docs/guides/graph-builder.md +1 -1
  102. package/docs/guides/web-search.md +47 -0
  103. package/docs/reference/cli.md +4 -3
  104. package/docs/reference/config.md +3 -3
  105. package/docs/reference/slash-commands.md +2 -1
  106. package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +295 -0
  107. package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +291 -0
  108. package/package.json +1 -1
@@ -174,6 +174,7 @@ export class GraphSync {
174
174
  }
175
175
  async drafts() {
176
176
  const result = [];
177
+ const cleared = await this.readClearedDrafts();
177
178
  for (const entry of await entries(join(this.directory, 'graph-drafts'))) {
178
179
  if (!entry.isFile() || !/^[a-f0-9]{64}\.json$/.test(entry.name))
179
180
  continue;
@@ -181,7 +182,11 @@ export class GraphSync {
181
182
  const hash = entry.name.slice(0, -5);
182
183
  const value = parseSnapshot(await readFile(join(this.directory, 'graph-drafts', entry.name), 'utf8'), hash);
183
184
  const timestamp = value.content.metadata?.updatedAt;
184
- result.push({ snapshot: hash, name: typeof value.content.name === 'string' ? value.content.name : value.graphId, graphId: value.graphId, revision: value.revision, updatedAt: typeof timestamp === 'string' ? Date.parse(timestamp) || 0 : 0 });
185
+ const updatedAt = typeof timestamp === 'string' ? Date.parse(timestamp) || 0 : 0;
186
+ const mark = cleared.get(value.graphId);
187
+ if (mark && (updatedAt <= mark.at || mark.snapshots.has(hash)))
188
+ continue;
189
+ result.push({ snapshot: hash, name: typeof value.content.name === 'string' ? value.content.name : value.graphId, graphId: value.graphId, revision: value.revision, updatedAt });
185
190
  }
186
191
  catch {
187
192
  this.status = { state: 'offline', detail: 'A local draft cannot be read. Other drafts remain available; the damaged file is preserved.' };
@@ -189,6 +194,50 @@ export class GraphSync {
189
194
  }
190
195
  return result.sort((a, b) => b.updatedAt - a.updatedAt);
191
196
  }
197
+ /**
198
+ * Draft snapshots are immutable, and every sweep restores the ones the account holds, so a draft
199
+ * the user cleared cannot be unlinked: it would come back. Each cleared graph instead has its own
200
+ * marker file under `graph-drafts-cleared/`, naming the instant up to which its drafts are
201
+ * cleared and any snapshot dated after that instant (saved under a clock that ran ahead) that
202
+ * was cleared with them. The listing leaves those out; a later autosave is a new snapshot, newer
203
+ * than the mark, and is listed again. A cleared snapshot stays on disk and still opens by hash.
204
+ *
205
+ * One file per graph, replaced whole, so two editors sharing this folder cannot drop each
206
+ * other's clears: clears of different graphs touch different files, and two clears of the same
207
+ * graph each record every draft that graph had.
208
+ */
209
+ async readClearedDrafts() {
210
+ const cleared = new Map();
211
+ for (const entry of await entries(join(this.directory, 'graph-drafts-cleared'))) {
212
+ if (!entry.isFile() || !/^[a-f0-9]{64}\.json$/.test(entry.name))
213
+ continue;
214
+ try {
215
+ const saved = JSON.parse(await readFile(join(this.directory, 'graph-drafts-cleared', entry.name), 'utf8'));
216
+ if (!object(saved) || !safeId(saved.graphId) || typeof saved.at !== 'number' || !Number.isFinite(saved.at))
217
+ continue;
218
+ const snapshots = Array.isArray(saved.snapshots) ? saved.snapshots.filter((hash) => typeof hash === 'string' && /^[a-f0-9]{64}$/.test(hash)) : [];
219
+ cleared.set(saved.graphId, { at: saved.at, snapshots: new Set(snapshots) });
220
+ }
221
+ catch { /* A damaged marker clears nothing, so no draft is hidden by mistake. */ }
222
+ }
223
+ return cleared;
224
+ }
225
+ /** Clear every draft the named graphs have right now, whatever clock dated them. */
226
+ async clearDrafts(graphIds) {
227
+ if (!Array.isArray(graphIds) || !graphIds.length || graphIds.length > 500 || graphIds.some(id => !safeId(id)))
228
+ throw new Error('Invalid draft');
229
+ const wanted = new Set(graphIds), now = Date.now();
230
+ const [listed, cleared] = [await this.drafts(), await this.readClearedDrafts()];
231
+ await mkdir(join(this.directory, 'graph-drafts-cleared'), { recursive: true });
232
+ for (const id of wanted) {
233
+ // A snapshot dated at or before now is covered by the instant; only one dated later needs
234
+ // naming. Earlier names are kept while they stay ahead of the instant, newest 500 at most.
235
+ const ahead = listed.filter(item => item.graphId === id && item.updatedAt > now).map(item => item.snapshot);
236
+ const snapshots = [...new Set([...ahead, ...(cleared.get(id)?.snapshots ?? [])])].slice(0, 500);
237
+ await atomic(join(this.directory, 'graph-drafts-cleared', `${digest(id)}.json`), JSON.stringify({ graphId: id, at: now, snapshots }));
238
+ this.lastDraft.delete(id);
239
+ }
240
+ }
192
241
  async draft(hash) {
193
242
  if (!/^[a-f0-9]{64}$/.test(hash))
194
243
  throw new Error('Invalid draft');
@@ -0,0 +1,52 @@
1
+ import type { Tool } from './types.js';
2
+ /** What the tool needs from the graph backend; `AgentMcpBackend` in production. */
3
+ export interface GraphBackend {
4
+ call(name: string, args: unknown, options?: {
5
+ beforeSave?: () => void;
6
+ }): Promise<{
7
+ ok: true;
8
+ data: unknown;
9
+ } | {
10
+ ok: false;
11
+ error: unknown;
12
+ }>;
13
+ close(): Promise<void>;
14
+ }
15
+ /**
16
+ * One graph backend per installation directory, created on the first graph action and closed after
17
+ * an idle hour.
18
+ *
19
+ * Shared across the tasks of one process so a draft begun in one task survives into the next, and so
20
+ * at most one cloud-sync loop runs per home however many tasks touch graphs. Nothing is loaded until
21
+ * a graph action runs: the backend module pulls in graph sync, membership and the subagent runner.
22
+ */
23
+ export declare class GraphBackendPool {
24
+ private readonly options;
25
+ private readonly entries;
26
+ constructor(options?: {
27
+ create?: (directory: string) => Promise<GraphBackend>;
28
+ idleCloseMs?: number;
29
+ });
30
+ call(directory: string, action: string, args: unknown, options?: {
31
+ beforeSave?: () => void;
32
+ }): Promise<{
33
+ ok: true;
34
+ data: unknown;
35
+ } | {
36
+ ok: false;
37
+ error: unknown;
38
+ }>;
39
+ /** Close every backend (tests, shutdown). A later action opens a fresh one. */
40
+ close(): Promise<void>;
41
+ /** Open backends, by directory; for tests that prove laziness and idle closing. */
42
+ get size(): number;
43
+ private closeEntry;
44
+ }
45
+ /**
46
+ * The engine's built-in graph authoring tool: the graph MCP server's graph actions, in process.
47
+ *
48
+ * Agents inside Andorra get graph authoring without a configured MCP server, a child process or an
49
+ * `andorra` command on PATH. One tool with an `action` keeps every request's schema small; the action
50
+ * names are the MCP tool names, so the guide, the graph-manager skill and the error codes apply as-is.
51
+ */
52
+ export declare function createGraphTool(pool?: GraphBackendPool): Tool;
@@ -0,0 +1,136 @@
1
+ import { AGENT_MCP_GRAPH_TOOLS } from './agent-mcp-catalog.js';
2
+ import { approveOperation } from './capabilities.js';
3
+ import { configDirectory } from './config.js';
4
+ import { assertPlanMutationAllowed } from './permissions.js';
5
+ /** Actions that save a revision to the account's graph store; drafts and reads stay in memory. */
6
+ const DURABLE_ACTIONS = new Set(['andorra_graph_publish', 'andorra_graph_delete', 'andorra_graph_restore']);
7
+ const ACTIONS = AGENT_MCP_GRAPH_TOOLS.map(tool => tool.name);
8
+ /** A published graph is commonly tens of kilobytes; a reply is bounded, never silently cut mid-graph. */
9
+ const MAX_REPLY_CHARS = 100_000;
10
+ /** Drafts expire after an hour in the backend, so an idle backend is closed no sooner. */
11
+ const DEFAULT_IDLE_CLOSE_MS = 60 * 60_000;
12
+ /**
13
+ * One graph backend per installation directory, created on the first graph action and closed after
14
+ * an idle hour.
15
+ *
16
+ * Shared across the tasks of one process so a draft begun in one task survives into the next, and so
17
+ * at most one cloud-sync loop runs per home however many tasks touch graphs. Nothing is loaded until
18
+ * a graph action runs: the backend module pulls in graph sync, membership and the subagent runner.
19
+ */
20
+ export class GraphBackendPool {
21
+ options;
22
+ entries = new Map();
23
+ constructor(options = {}) {
24
+ this.options = options;
25
+ }
26
+ async call(directory, action, args, options = {}) {
27
+ let entry = this.entries.get(directory);
28
+ if (!entry) {
29
+ const backend = (this.options.create ?? defaultBackend)(directory);
30
+ entry = { backend, active: 0 };
31
+ this.entries.set(directory, entry);
32
+ // A failed construction must not poison the directory: the next action tries again.
33
+ backend.catch(() => { if (this.entries.get(directory)?.backend === backend)
34
+ this.entries.delete(directory); });
35
+ }
36
+ clearTimeout(entry.timer);
37
+ entry.active++;
38
+ try {
39
+ return await (await entry.backend).call(action, args, options);
40
+ }
41
+ finally {
42
+ entry.active--;
43
+ if (entry.active === 0 && this.entries.get(directory) === entry) {
44
+ entry.timer = setTimeout(() => { void this.closeEntry(directory, entry); }, this.options.idleCloseMs ?? DEFAULT_IDLE_CLOSE_MS);
45
+ entry.timer.unref?.();
46
+ }
47
+ }
48
+ }
49
+ /** Close every backend (tests, shutdown). A later action opens a fresh one. */
50
+ async close() {
51
+ await Promise.all([...this.entries].map(([directory, entry]) => this.closeEntry(directory, entry)));
52
+ }
53
+ /** Open backends, by directory; for tests that prove laziness and idle closing. */
54
+ get size() { return this.entries.size; }
55
+ async closeEntry(directory, entry) {
56
+ clearTimeout(entry.timer);
57
+ if (entry.active > 0 || this.entries.get(directory) !== entry)
58
+ return;
59
+ this.entries.delete(directory);
60
+ await (await entry.backend.catch(() => undefined))?.close().catch(() => { });
61
+ }
62
+ }
63
+ async function defaultBackend(directory) {
64
+ const { AgentMcpBackend } = await import('./agent-mcp.js');
65
+ return new AgentMcpBackend({ directory, recoverRuns: false });
66
+ }
67
+ const sharedPool = new GraphBackendPool();
68
+ /** `name {arg*, arg}`: the arguments each action takes, `*` marking the required ones. */
69
+ function actionSummary() {
70
+ return AGENT_MCP_GRAPH_TOOLS.map(tool => {
71
+ const { properties, required } = tool.inputSchema;
72
+ const names = Object.keys(properties).map(key => required.includes(key) ? `${key}*` : key);
73
+ return names.length ? `${tool.name} {${names.join(', ')}}` : tool.name;
74
+ }).join('; ');
75
+ }
76
+ /**
77
+ * The engine's built-in graph authoring tool: the graph MCP server's graph actions, in process.
78
+ *
79
+ * Agents inside Andorra get graph authoring without a configured MCP server, a child process or an
80
+ * `andorra` command on PATH. One tool with an `action` keeps every request's schema small; the action
81
+ * names are the MCP tool names, so the guide, the graph-manager skill and the error codes apply as-is.
82
+ */
83
+ export function createGraphTool(pool = sharedPool) {
84
+ return {
85
+ name: 'graphs', capability: 'external', executionMode: 'sequential',
86
+ description: 'Create, edit, validate, publish, delete or restore Andorra graphs (multi-agent workflows) in the signed-in account\'s graph store, the same store the Graph Builder and graph picker use. Never write graph files on disk. '
87
+ + 'Call action andorra_graph_guide first for node types, ports, limits and error codes; load the skill andorra:graph-manager to design a graph with the user. '
88
+ + 'Put the action\'s arguments in args. Drafts are kept in this Andorra process for up to an hour; publish saves a revision and syncs it to the account. Publish, delete and restore ask for permission. '
89
+ + `Actions and their args (* required): ${actionSummary()}.`,
90
+ parameters: { type: 'object', additionalProperties: false, properties: {
91
+ action: { type: 'string', enum: ACTIONS },
92
+ args: { type: 'object', description: 'Arguments of the action; omit for actions that take none.' },
93
+ }, required: ['action'] },
94
+ execute: async (args, context) => {
95
+ context.signal.throwIfAborted();
96
+ if (Object.keys(args).some(key => key !== 'action' && key !== 'args'))
97
+ throw new Error('graphs takes only action and args.');
98
+ const action = args.action;
99
+ if (typeof action !== 'string' || !ACTIONS.includes(action))
100
+ throw new Error(`action must be one of: ${ACTIONS.join(', ')}.`);
101
+ const input = args.args ?? {};
102
+ if (!input || typeof input !== 'object' || Array.isArray(input))
103
+ throw new Error('args must be an object.');
104
+ // Saving changes the account's graphs and syncs them to every machine: the same gate
105
+ // automations use for durable work, which also refuses it in plan mode.
106
+ if (DURABLE_ACTIONS.has(action))
107
+ await approveOperation(context, 'graphs', { action, args: input });
108
+ context.signal.throwIfAborted();
109
+ // The approval above is not the last word: the backend still awaits sign-in checks and cloud
110
+ // sync before it writes. Re-check right before the write, so a task cancelled or switched to
111
+ // Plan in the meantime saves nothing, and report that refusal rather than a backend error.
112
+ let refused;
113
+ const beforeSave = () => {
114
+ try {
115
+ context.signal.throwIfAborted();
116
+ assertPlanMutationAllowed(context);
117
+ }
118
+ catch (error) {
119
+ refused = error;
120
+ throw error;
121
+ }
122
+ };
123
+ const reply = await pool.call(context.automationDirectory ?? configDirectory(), action, input, { beforeSave });
124
+ if (refused !== undefined)
125
+ throw refused;
126
+ let text = JSON.stringify(reply);
127
+ if (text.length > MAX_REPLY_CHARS)
128
+ text = JSON.stringify({ ok: reply.ok, truncated: true,
129
+ note: `The reply exceeded ${MAX_REPLY_CHARS} characters and is shown only in part.`,
130
+ preview: text.slice(0, 2_000) });
131
+ if (!reply.ok)
132
+ throw new Error(text);
133
+ return text;
134
+ },
135
+ };
136
+ }