@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
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The tools the Andorra agent-control MCP server advertises, as plain data.
3
+ *
4
+ * Kept apart from `agent-mcp.ts` so the engine can describe its built-in `graphs` tool without
5
+ * loading the graph backend (and its sync, membership and subagent modules) until a graph action runs.
6
+ */
7
+ export interface AgentMcpToolSpec {
8
+ name: string;
9
+ description: string;
10
+ inputSchema: {
11
+ type: 'object';
12
+ properties: Record<string, unknown>;
13
+ required: string[];
14
+ additionalProperties: false;
15
+ };
16
+ }
17
+ export declare const AGENT_MCP_CATALOG: readonly AgentMcpToolSpec[];
18
+ /** The tool names this server advertises; bundled skills that drive it are checked against this list. */
19
+ export declare const AGENT_MCP_TOOL_NAMES: readonly string[];
20
+ /** Graph authoring: what the engine's built-in `graphs` tool offers. Session and subagent tools stay MCP-only. */
21
+ export declare const AGENT_MCP_GRAPH_TOOLS: readonly AgentMcpToolSpec[];
@@ -0,0 +1,40 @@
1
+ const obj = (properties, required = []) => ({ type: 'object',
2
+ properties, required, additionalProperties: false });
3
+ const str = { type: 'string' };
4
+ const num = { type: 'integer', minimum: 0 };
5
+ const graphDraftSchema = { draftId: str };
6
+ const graphReference = { draftId: str, nodeId: str };
7
+ const searchFilters = { projectName: str, projectPath: str,
8
+ lookbackMinutes: num, updatedAfter: str, updatedBefore: str, includeArchived: { type: 'boolean' } };
9
+ export const AGENT_MCP_CATALOG = [
10
+ { name: 'andorra_graph_guide', description: 'Read Andorra graph architecture, node types, outcome routes, loops and save error contracts.', inputSchema: obj({}) },
11
+ { name: 'andorra_providers_list', description: 'List valid graph provider IDs and models without credentials.', inputSchema: obj({}) },
12
+ { name: 'andorra_graphs_list', description: 'List available graphs, names and revisions. Deleted graphs are listed only with includeDeleted.', inputSchema: obj({ includeDeleted: { type: 'boolean' } }) },
13
+ { name: 'andorra_graph_get', description: 'Read one published graph, optionally by revision.', inputSchema: obj({ id: str, revision: { type: 'integer', minimum: 1 } }, ['id']) },
14
+ { name: 'andorra_graph_begin', description: 'Open an ephemeral graph draft. mode=create needs a new id and name; mode=edit opens latest.', inputSchema: obj({ mode: { type: 'string', enum: ['create', 'edit'] }, id: str, name: str }, ['mode', 'id']) },
15
+ { name: 'andorra_graph_node_upsert', description: 'Create or replace a node in a draft. Agent nodes require a configured provider ID.', inputSchema: obj({ draftId: str, node: { type: 'object' } }, ['draftId', 'node']) },
16
+ { name: 'andorra_graph_node_patch', description: 'Change an existing node prompt, instruction, model, provider, completion, etc. without replacing other fields.', inputSchema: obj({ ...graphReference, patch: { type: 'object' } }, ['draftId', 'nodeId', 'patch']) },
17
+ { name: 'andorra_graph_node_remove', description: 'Remove a non-entry node and its incident edges from a draft.', inputSchema: obj(graphReference, ['draftId', 'nodeId']) },
18
+ { name: 'andorra_graph_edge_upsert', description: 'Create or replace an edge. Outcome must match a source node port (pass/fail, true/false, body/done...).', inputSchema: obj({ draftId: str, edge: { type: 'object' } }, ['draftId', 'edge']) },
19
+ { name: 'andorra_graph_edge_remove', description: 'Remove an edge by ID from a draft.', inputSchema: obj({ ...graphDraftSchema, edgeId: str }, ['draftId', 'edgeId']) },
20
+ { name: 'andorra_graph_patch', description: 'Set graph entry, name, limits, schemas, widgets or metadata in a draft.', inputSchema: obj({ draftId: str, patch: { type: 'object' } }, ['draftId', 'patch']) },
21
+ { name: 'andorra_graph_validate', description: 'Validate a draft; report all missing provider and outcome paths, plus graph topology issues.', inputSchema: obj(graphDraftSchema, ['draftId']) },
22
+ { name: 'andorra_graph_publish', description: 'Validate and atomically publish the next immutable graph revision; optimistic concurrency guards other editors.', inputSchema: obj(graphDraftSchema, ['draftId']) },
23
+ { name: 'andorra_graph_delete', description: 'Soft-delete a graph after the user confirms in chat: publishes a revision marked deleted, hides it from listings and new runs, keeps every revision. confirm must repeat the id.', inputSchema: obj({ id: str, expectedRevision: { type: 'integer', minimum: 1 }, confirm: str }, ['id', 'expectedRevision', 'confirm']) },
24
+ { name: 'andorra_graph_restore', description: 'Restore a soft-deleted graph by publishing the next revision without the deleted marker.', inputSchema: obj({ id: str, expectedRevision: { type: 'integer', minimum: 1 } }, ['id', 'expectedRevision']) },
25
+ { name: 'andorra_graph_discard', description: 'Discard an unpublished local graph draft.', inputSchema: obj(graphDraftSchema, ['draftId']) },
26
+ { name: 'andorra_projects_list', description: 'List registered projects and discovered session workspaces.', inputSchema: obj({}) },
27
+ { name: 'andorra_sessions_list', description: 'Search sessions by project, status and last X minutes (lookbackMinutes). Supports paginated results.', inputSchema: obj({ ...searchFilters, status: { type: 'string', enum: ['completed', 'pending', 'running', 'required_input', 'incomplete'] },
28
+ offset: num, limit: { type: 'integer', minimum: 1, maximum: 100 } }) },
29
+ { name: 'andorra_session_get', description: 'Read session metadata and up to 20 recent turn excerpts; no filesystem access.', inputSchema: obj({ sessionId: str,
30
+ historyLimit: { type: 'integer', minimum: 0, maximum: 20 }, historyOffset: num }, ['sessionId']) },
31
+ { name: 'andorra_sessions_attention', description: 'Find sessions requiring human feedback or review: required_input and incomplete; supports project and time filters.', inputSchema: obj(searchFilters) },
32
+ { name: 'andorra_subagent_start', description: 'Run the bundled Andorra Agent graph once as an Andorra subagent. Requires a provider/model: pass provider and model, or the saved /subagent setting. On PROVIDER_NOT_SET, show the listed providers and models to your user, ask which to use, then retry with provider and model. Writes are allowed unless permissions is read-only.', inputSchema: obj({ prompt: str, provider: str, model: str, permissions: { type: 'string', enum: ['full-access', 'read-only'] }, workspace: str }, ['prompt']) },
33
+ { name: 'andorra_subagent_status', description: 'Poll the subagent run: state, current node and recent events. The runId must be the one the start returned, so the answer is about that run.', inputSchema: obj({ runId: str }, ['runId']) },
34
+ { name: 'andorra_subagent_result', description: 'Read the subagent run outcome. waitMs (0-60000) waits for completion within the call; otherwise returns running immediately when unfinished. The finished reply carries the full run result including completion summary and status. The runId must be the one the start returned.', inputSchema: obj({ waitMs: { type: 'integer', minimum: 0, maximum: 60000 }, runId: str }, ['runId']) },
35
+ { name: 'andorra_subagent_cancel', description: 'Cancel the subagent run. The runId must be the one the start returned, so a delayed cancellation cannot stop a run that replaced it.', inputSchema: obj({ runId: str }, ['runId']) },
36
+ ];
37
+ /** The tool names this server advertises; bundled skills that drive it are checked against this list. */
38
+ export const AGENT_MCP_TOOL_NAMES = AGENT_MCP_CATALOG.map(tool => tool.name);
39
+ /** Graph authoring: what the engine's built-in `graphs` tool offers. Session and subagent tools stay MCP-only. */
40
+ export const AGENT_MCP_GRAPH_TOOLS = AGENT_MCP_CATALOG.filter(tool => tool.name.startsWith('andorra_graph_') || tool.name === 'andorra_graphs_list' || tool.name === 'andorra_providers_list');
@@ -5,6 +5,7 @@ import { getMembership } from './membership.js';
5
5
  import { SessionStore } from './sessions.js';
6
6
  import { type SubagentProviderListing } from './subagent-run.js';
7
7
  import type { ModelAdapter } from './types.js';
8
+ import { AGENT_MCP_TOOL_NAMES } from './agent-mcp-catalog.js';
8
9
  type Issue = {
9
10
  code: string;
10
11
  message: string;
@@ -45,6 +46,14 @@ export interface AgentMcpBackendOptions {
45
46
  subagentWorkspace?: string;
46
47
  /** Test-only adapter so subagent runs stay offline and deterministic. */
47
48
  subagentAdapterFactory?: (provider: import('./providers.js').ProviderConfig) => ModelAdapter;
49
+ /**
50
+ * Whether construction sweeps the home for runs a crashed process left `running` (default true).
51
+ *
52
+ * The stdio server needs it: a host that only talks to the server would otherwise never see its own
53
+ * crashed runs classified. The engine's built-in `graphs` tool passes false: it starts no subagent
54
+ * runs, and the run records of its home belong to the engine that hosts it.
55
+ */
56
+ recoverRuns?: boolean;
48
57
  }
49
58
  export declare const GRAPH_AGENT_GUIDE: string;
50
59
  export declare class AgentMcpError extends Error {
@@ -113,10 +122,17 @@ export declare class AgentMcpBackend {
113
122
  private readGraph;
114
123
  private upsertNode;
115
124
  private upsertEdge;
116
- call(name: string, rawArgs?: unknown): Promise<AgentMcpReply>;
125
+ /**
126
+ * Run one tool call. `beforeSave` runs synchronously immediately before a revision is written
127
+ * (publish, delete, restore), after every await that precedes the write; throwing from it abandons
128
+ * the save. An embedding host uses it to refuse a save its task may no longer make (cancelled, or
129
+ * switched to Plan) while the call was waiting on sign-in checks or cloud sync.
130
+ */
131
+ call(name: string, rawArgs?: unknown, options?: {
132
+ beforeSave?: () => void;
133
+ }): Promise<AgentMcpReply>;
117
134
  private dispatch;
118
135
  }
119
136
  /** The tool names this server advertises; bundled skills that drive it are checked against this list. */
120
- export declare const AGENT_MCP_TOOL_NAMES: readonly string[];
137
+ export { AGENT_MCP_TOOL_NAMES };
121
138
  export declare function runAgentMcpServer(): Promise<number>;
122
- export {};
@@ -14,6 +14,7 @@ import { getAgentSession, listAgentProjects, queryAgentSessions, scanAgentSessio
14
14
  import { AutomationStore } from './automations.js';
15
15
  import { canonicalWorkspace, MAX_SUBAGENT_TASK_CHARS, SubagentInvalidArgumentError, SubagentProviderNotSetError, SubagentRunInProgressError, SubagentRunner, SubagentSelectionError } from './subagent-run.js';
16
16
  import { reconcileInterruptedRuns } from './run-records.js';
17
+ import { AGENT_MCP_CATALOG, AGENT_MCP_TOOL_NAMES } from './agent-mcp-catalog.js';
17
18
  export const GRAPH_AGENT_GUIDE = [
18
19
  '# Andorra Code Graph Agent Architecture (MCP)',
19
20
  '',
@@ -254,7 +255,8 @@ export class AgentMcpBackend {
254
255
  // Another engine in this process may have a live run in this home — an app-server, or a
255
256
  // second backend. A record this process is running is not this backend's to classify, so the
256
257
  // sweep leaves it alone.
257
- this.recovery = reconcileInterruptedRuns(this.directory, undefined, { skipOwnProcess: true }).then(() => undefined).catch(() => undefined);
258
+ this.recovery = options.recoverRuns === false ? Promise.resolve()
259
+ : reconcileInterruptedRuns(this.directory, undefined, { skipOwnProcess: true }).then(() => undefined).catch(() => undefined);
258
260
  }
259
261
  /** The startup recovery, finished before the first subagent start is accepted. */
260
262
  recovery;
@@ -418,7 +420,7 @@ export class AgentMcpBackend {
418
420
  * The revision goes through the same save path as a publish, so free-tier rules and the optimistic
419
421
  * revision check apply unchanged, and cloud sync carries the marker to every machine.
420
422
  */
421
- async setDeleted(deleting, args, access) {
423
+ async setDeleted(deleting, args, access, beforeSave) {
422
424
  const tool = deleting ? 'andorra_graph_delete' : 'andorra_graph_restore';
423
425
  const id = field(args, 'id');
424
426
  if (id === 'default' || id.includes(':'))
@@ -459,6 +461,7 @@ export class AgentMcpBackend {
459
461
  else
460
462
  delete metadata.deletedAt;
461
463
  const next = { ...latest, metadata };
464
+ beforeSave?.();
462
465
  const saved = freshAccess.free ? await saveFreeTierGraph(next, latest.revision, access.directory)
463
466
  : await saveGraph(next, latest.revision, access.directory);
464
467
  // A draft of a deleted graph could only publish over the deletion.
@@ -534,9 +537,15 @@ export class AgentMcpBackend {
534
537
  draft.graph.edges[index] = edge;
535
538
  return { edge, edgeCount: draft.graph.edges.length };
536
539
  }
537
- async call(name, rawArgs = {}) {
540
+ /**
541
+ * Run one tool call. `beforeSave` runs synchronously immediately before a revision is written
542
+ * (publish, delete, restore), after every await that precedes the write; throwing from it abandons
543
+ * the save. An embedding host uses it to refuse a save its task may no longer make (cancelled, or
544
+ * switched to Plan) while the call was waiting on sign-in checks or cloud sync.
545
+ */
546
+ async call(name, rawArgs = {}, options = {}) {
538
547
  try {
539
- return { ok: true, data: await this.dispatch(name, argsRecord(rawArgs)) };
548
+ return { ok: true, data: await this.dispatch(name, argsRecord(rawArgs), options.beforeSave) };
540
549
  }
541
550
  catch (error) {
542
551
  if (error instanceof GraphConflictError)
@@ -561,7 +570,7 @@ export class AgentMcpBackend {
561
570
  return { ok: false, error: backendIssue(error) };
562
571
  }
563
572
  }
564
- async dispatch(name, args) {
573
+ async dispatch(name, args, beforeSave) {
565
574
  if (name === 'andorra_graph_guide')
566
575
  return { architecture: GRAPH_AGENT_GUIDE, resourceUri: 'andorra://graph/architecture' };
567
576
  if (name === 'andorra_projects_list')
@@ -699,7 +708,7 @@ export class AgentMcpBackend {
699
708
  return { graph, ...(isDeletedGraph(graph) ? { deletedAt: graph.metadata.deletedAt } : {}) };
700
709
  }
701
710
  if (name === 'andorra_graph_delete' || name === 'andorra_graph_restore')
702
- return this.setDeleted(name === 'andorra_graph_delete', args, access);
711
+ return this.setDeleted(name === 'andorra_graph_delete', args, access, beforeSave);
703
712
  if (name === 'andorra_graph_begin') {
704
713
  const mode = field(args, 'mode');
705
714
  const id = field(args, 'id');
@@ -869,6 +878,7 @@ export class AgentMcpBackend {
869
878
  const stamped = stampGraphProviderProfiles(normalized, latestProfiles);
870
879
  if (Buffer.byteLength(JSON.stringify(stamped)) > 512 * 1024)
871
880
  throw new AgentMcpError('VALIDATION_FAILED', 'Graph exceeds 512 KiB after portable provider identities are recorded.');
881
+ beforeSave?.();
872
882
  const saved = finalAccess.free ? await saveFreeTierGraph(stamped, draft.expectedRevision, access.directory)
873
883
  : await saveGraph(stamped, draft.expectedRevision, access.directory);
874
884
  // A re-created graph id must not stay deleted: the editor's save endpoint clears the
@@ -889,48 +899,12 @@ export class AgentMcpBackend {
889
899
  }
890
900
  }
891
901
  }
892
- const obj = (properties, required = []) => ({ type: 'object',
893
- properties, required, additionalProperties: false });
894
- const str = { type: 'string' };
895
- const num = { type: 'integer', minimum: 0 };
896
- const graphDraftSchema = { draftId: str };
897
- const graphReference = { draftId: str, nodeId: str };
898
- const searchFilters = { projectName: str, projectPath: str,
899
- lookbackMinutes: num, updatedAfter: str, updatedBefore: str, includeArchived: { type: 'boolean' } };
900
- const catalog = [
901
- { name: 'andorra_graph_guide', description: 'Read Andorra graph architecture, node types, outcome routes, loops and save error contracts.', inputSchema: obj({}) },
902
- { name: 'andorra_providers_list', description: 'List valid graph provider IDs and models without credentials.', inputSchema: obj({}) },
903
- { name: 'andorra_graphs_list', description: 'List available graphs, names and revisions. Deleted graphs are listed only with includeDeleted.', inputSchema: obj({ includeDeleted: { type: 'boolean' } }) },
904
- { name: 'andorra_graph_get', description: 'Read one published graph, optionally by revision.', inputSchema: obj({ id: str, revision: { type: 'integer', minimum: 1 } }, ['id']) },
905
- { name: 'andorra_graph_begin', description: 'Open an ephemeral graph draft. mode=create needs a new id and name; mode=edit opens latest.', inputSchema: obj({ mode: { type: 'string', enum: ['create', 'edit'] }, id: str, name: str }, ['mode', 'id']) },
906
- { name: 'andorra_graph_node_upsert', description: 'Create or replace a node in a draft. Agent nodes require a configured provider ID.', inputSchema: obj({ draftId: str, node: { type: 'object' } }, ['draftId', 'node']) },
907
- { name: 'andorra_graph_node_patch', description: 'Change an existing node prompt, instruction, model, provider, completion, etc. without replacing other fields.', inputSchema: obj({ ...graphReference, patch: { type: 'object' } }, ['draftId', 'nodeId', 'patch']) },
908
- { name: 'andorra_graph_node_remove', description: 'Remove a non-entry node and its incident edges from a draft.', inputSchema: obj(graphReference, ['draftId', 'nodeId']) },
909
- { name: 'andorra_graph_edge_upsert', description: 'Create or replace an edge. Outcome must match a source node port (pass/fail, true/false, body/done...).', inputSchema: obj({ draftId: str, edge: { type: 'object' } }, ['draftId', 'edge']) },
910
- { name: 'andorra_graph_edge_remove', description: 'Remove an edge by ID from a draft.', inputSchema: obj({ ...graphDraftSchema, edgeId: str }, ['draftId', 'edgeId']) },
911
- { name: 'andorra_graph_patch', description: 'Set graph entry, name, limits, schemas, widgets or metadata in a draft.', inputSchema: obj({ draftId: str, patch: { type: 'object' } }, ['draftId', 'patch']) },
912
- { name: 'andorra_graph_validate', description: 'Validate a draft; report all missing provider and outcome paths, plus graph topology issues.', inputSchema: obj(graphDraftSchema, ['draftId']) },
913
- { name: 'andorra_graph_publish', description: 'Validate and atomically publish the next immutable graph revision; optimistic concurrency guards other editors.', inputSchema: obj(graphDraftSchema, ['draftId']) },
914
- { name: 'andorra_graph_delete', description: 'Soft-delete a graph after the user confirms in chat: publishes a revision marked deleted, hides it from listings and new runs, keeps every revision. confirm must repeat the id.', inputSchema: obj({ id: str, expectedRevision: { type: 'integer', minimum: 1 }, confirm: str }, ['id', 'expectedRevision', 'confirm']) },
915
- { name: 'andorra_graph_restore', description: 'Restore a soft-deleted graph by publishing the next revision without the deleted marker.', inputSchema: obj({ id: str, expectedRevision: { type: 'integer', minimum: 1 } }, ['id', 'expectedRevision']) },
916
- { name: 'andorra_graph_discard', description: 'Discard an unpublished local graph draft.', inputSchema: obj(graphDraftSchema, ['draftId']) },
917
- { name: 'andorra_projects_list', description: 'List registered projects and discovered session workspaces.', inputSchema: obj({}) },
918
- { name: 'andorra_sessions_list', description: 'Search sessions by project, status and last X minutes (lookbackMinutes). Supports paginated results.', inputSchema: obj({ ...searchFilters, status: { type: 'string', enum: ['completed', 'pending', 'running', 'required_input', 'incomplete'] },
919
- offset: num, limit: { type: 'integer', minimum: 1, maximum: 100 } }) },
920
- { name: 'andorra_session_get', description: 'Read session metadata and up to 20 recent turn excerpts; no filesystem access.', inputSchema: obj({ sessionId: str,
921
- historyLimit: { type: 'integer', minimum: 0, maximum: 20 }, historyOffset: num }, ['sessionId']) },
922
- { name: 'andorra_sessions_attention', description: 'Find sessions requiring human feedback or review: required_input and incomplete; supports project and time filters.', inputSchema: obj(searchFilters) },
923
- { name: 'andorra_subagent_start', description: 'Run the bundled Andorra Agent graph once as an Andorra subagent. Requires a provider/model: pass provider and model, or the saved /subagent setting. On PROVIDER_NOT_SET, show the listed providers and models to your user, ask which to use, then retry with provider and model. Writes are allowed unless permissions is read-only.', inputSchema: obj({ prompt: str, provider: str, model: str, permissions: { type: 'string', enum: ['full-access', 'read-only'] }, workspace: str }, ['prompt']) },
924
- { name: 'andorra_subagent_status', description: 'Poll the subagent run: state, current node and recent events. The runId must be the one the start returned, so the answer is about that run.', inputSchema: obj({ runId: str }, ['runId']) },
925
- { name: 'andorra_subagent_result', description: 'Read the subagent run outcome. waitMs (0-60000) waits for completion within the call; otherwise returns running immediately when unfinished. The finished reply carries the full run result including completion summary and status. The runId must be the one the start returned.', inputSchema: obj({ waitMs: { type: 'integer', minimum: 0, maximum: 60000 }, runId: str }, ['runId']) },
926
- { name: 'andorra_subagent_cancel', description: 'Cancel the subagent run. The runId must be the one the start returned, so a delayed cancellation cannot stop a run that replaced it.', inputSchema: obj({ runId: str }, ['runId']) },
927
- ];
928
902
  /** The tool names this server advertises; bundled skills that drive it are checked against this list. */
929
- export const AGENT_MCP_TOOL_NAMES = catalog.map(tool => tool.name);
903
+ export { AGENT_MCP_TOOL_NAMES };
930
904
  export async function runAgentMcpServer() {
931
905
  const backend = new AgentMcpBackend();
932
906
  const server = new Server({ name: 'andorra-code-agent-control', version: '1.0.0' }, { capabilities: { tools: {}, resources: {} } });
933
- server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: catalog }));
907
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [...AGENT_MCP_CATALOG] }));
934
908
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
935
909
  const reply = await backend.call(request.params.name, request.params.arguments ?? {});
936
910
  return { isError: !reply.ok, content: [{ type: 'text', text: JSON.stringify(reply) }] };
@@ -44,7 +44,7 @@ export declare const APP_SERVER_PROTOCOL_VERSION = 2;
44
44
  * one when a client omits it. An engine without it rebuilds a replaced entry from its own field
45
45
  * list, so a save through it silently drops the rename and every surface falls back to the id; a
46
46
  * client that can show the field must refuse the write first. */
47
- export declare const APP_SERVER_CAPABILITIES: readonly ["run.start.runPermissions", "automations", "providers.models", "providers.test", "providers.test.model", "providers.streamIdleTimeout", "providers.modelContextWindows", "providers.name", "providers.claude", "providers.claudeAuth", "providers.grok", "providers.opencode", "providers.auth.submit", "providers.opencodeGo", "providers.discover.draft", "providers.codexAuth", "providers.codexAuth.logout", "providers.codexAccounts", "providers.anthropicConsole", "run.resume.direction", "run.steer", "run.overrideAllNodes", "run.setModel", "run.setModel.node", "run.setPermissions", "run.start.continueSession", "run.start.entryHistory", "remote.owner.projects", "remote.workspaces.probe", "remote.engine.relay", "remote.hosting.device.grant", "extensions.manage", "extensions.resources", "skills.invoke", "mcp.manage", "runs.files", "sessions.files", "account.profile", "sessions.stats", "sessions.usage", "config.analytics", "config.analytics.planGate", "sessions.trajectory", "config.externalSubagent", "config.decisions", "browser.view", "attachments.read", "config.general", "sessions.pullRequest", "browser.view.go", "config.browser"];
47
+ export declare const APP_SERVER_CAPABILITIES: readonly ["run.start.runPermissions", "automations", "providers.models", "providers.test", "providers.test.model", "providers.streamIdleTimeout", "providers.modelContextWindows", "providers.name", "providers.claude", "providers.claudeAuth", "providers.grok", "providers.opencode", "providers.auth.submit", "providers.opencodeGo", "providers.discover.draft", "providers.codexAuth", "providers.codexAuth.logout", "providers.codexAccounts", "providers.anthropicConsole", "run.resume.direction", "run.resume.model", "run.steer", "run.overrideAllNodes", "run.setModel", "run.setModel.node", "run.setPermissions", "run.start.continueSession", "run.start.entryHistory", "remote.owner.projects", "remote.workspaces.probe", "remote.engine.relay", "remote.hosting.device.grant", "extensions.manage", "extensions.resources", "skills.invoke", "mcp.manage", "runs.files", "sessions.files", "account.profile", "sessions.stats", "sessions.usage", "config.analytics", "config.analytics.planGate", "sessions.trajectory", "config.externalSubagent", "config.decisions", "browser.view", "attachments.read", "config.general", "sessions.pullRequest", "browser.view.go", "config.browser", "config.webSearch"];
48
48
  /** One client call. `params` is omitted only for calls that take no arguments. */
49
49
  export interface AppServerRequest {
50
50
  id: number | string;
@@ -242,6 +242,23 @@ export interface AppServerConfig {
242
242
  hasCapsolverKey: boolean;
243
243
  capsolverKeySource?: 'config' | 'env';
244
244
  };
245
+ /**
246
+ * The web_search tool's services. Keys are never reported: for each service `saved` says the
247
+ * configuration holds its key (or, for SearXNG, its URL), and `source` which value the tool would
248
+ * use (absent when it is not usable). The search engine ID and SearXNG URL are not secrets and come
249
+ * back as saved. A patch sends `{ webSearch: { <field>: string | null } }` with any of
250
+ * defaultProvider, braveApiKey, tavilyApiKey, exaApiKey, serperApiKey, googleApiKey,
251
+ * googleSearchEngineId and searxngUrl; null removes the field and an omitted one is kept.
252
+ */
253
+ webSearch?: {
254
+ defaultProvider?: 'brave' | 'tavily' | 'exa' | 'serper' | 'google' | 'searxng';
255
+ providers: Record<'brave' | 'tavily' | 'exa' | 'serper' | 'google' | 'searxng', {
256
+ saved: boolean;
257
+ source?: 'config' | 'env';
258
+ }>;
259
+ googleSearchEngineId?: string;
260
+ searxngUrl?: string;
261
+ };
245
262
  }
246
263
  export interface AppServerAccount {
247
264
  signedIn: boolean;
@@ -409,7 +426,11 @@ export interface AppServerGitFile {
409
426
  index: string;
410
427
  worktree: string;
411
428
  }
412
- /** `truncated` means the working tree listed more changes than the engine reads in one answer. */
429
+ /**
430
+ * `truncated` means the working tree listed more changes than the engine reads in one answer, and
431
+ * `repository` is false unless a `.git` sits at the workspace folder or its immediate parent: a
432
+ * repository Git would only reach by walking further up the tree is not that folder's.
433
+ */
413
434
  export interface AppServerGitStatus {
414
435
  repository: boolean;
415
436
  branch?: string;
@@ -421,7 +442,8 @@ export interface AppServerGitStatus {
421
442
  *
422
443
  * `current` is absent in a detached HEAD rather than naming the commit as if it were a branch, and
423
444
  * `branches` holds local branches only: a remote-tracking ref is not a branch a checkout can land on
424
- * without a decision — which local branch tracks it — the client cannot express here.
445
+ * without a decision — which local branch tracks it — the client cannot express here. The repository
446
+ * has to be the workspace folder itself or its immediate parent; `repository` is false otherwise.
425
447
  */
426
448
  export interface AppServerBranchList {
427
449
  repository: boolean;
@@ -37,6 +37,10 @@ export const APP_SERVER_PROTOCOL_VERSION = 2;
37
37
  // attempt's first steering message. An engine without it accepts the field and ignores it, so a
38
38
  // client that offers a continuation message must not send one to such an engine: the resume would
39
39
  // succeed with the user's instruction silently dropped.
40
+ // `run.resume.model`: `run.resume` honors an explicit `provider`/`model` pair and runs the continued
41
+ // attempt on it (checkpoint re-attribution, like a live model switch). An engine without it accepts
42
+ // the fields and ignores them, so a client that offers a switched pair must not send one to such an
43
+ // engine: the resume would succeed while silently continuing on the stopped attempt's own pair.
40
44
  // `remote.engine.relay`: this engine can proxy a full-grant paired workspace's engine surface —
41
45
  // `remote.engine.connect`/`request`/`disconnect` — so a window may run tasks on that machine. An
42
46
  // engine without it has only the browse subset, and the desktop keeps the read-only presentation.
@@ -116,4 +120,4 @@ export const APP_SERVER_PROTOCOL_VERSION = 2;
116
120
  // and the children it delegates without a model of their own — instead of the run. An engine that
117
121
  // advertises `run.setModel` but not this ignores the unknown parameter and would answer a node-scoped
118
122
  // request as a whole-run one, so a client that promises one node's switch must refuse it here first.
119
- export const APP_SERVER_CAPABILITIES = ['run.start.runPermissions', 'automations', 'providers.models', 'providers.test', 'providers.test.model', 'providers.streamIdleTimeout', 'providers.modelContextWindows', 'providers.name', 'providers.claude', 'providers.claudeAuth', 'providers.grok', 'providers.opencode', 'providers.auth.submit', 'providers.opencodeGo', 'providers.discover.draft', 'providers.codexAuth', 'providers.codexAuth.logout', 'providers.codexAccounts', 'providers.anthropicConsole', 'run.resume.direction', 'run.steer', 'run.overrideAllNodes', 'run.setModel', 'run.setModel.node', 'run.setPermissions', 'run.start.continueSession', 'run.start.entryHistory', 'remote.owner.projects', 'remote.workspaces.probe', 'remote.engine.relay', 'remote.hosting.device.grant', 'extensions.manage', 'extensions.resources', 'skills.invoke', 'mcp.manage', 'runs.files', 'sessions.files', 'account.profile', 'sessions.stats', 'sessions.usage', 'config.analytics', 'config.analytics.planGate', 'sessions.trajectory', 'config.externalSubagent', 'config.decisions', 'browser.view', 'attachments.read', 'config.general', 'sessions.pullRequest', 'browser.view.go', 'config.browser'];
123
+ export const APP_SERVER_CAPABILITIES = ['run.start.runPermissions', 'automations', 'providers.models', 'providers.test', 'providers.test.model', 'providers.streamIdleTimeout', 'providers.modelContextWindows', 'providers.name', 'providers.claude', 'providers.claudeAuth', 'providers.grok', 'providers.opencode', 'providers.auth.submit', 'providers.opencodeGo', 'providers.discover.draft', 'providers.codexAuth', 'providers.codexAuth.logout', 'providers.codexAccounts', 'providers.anthropicConsole', 'run.resume.direction', 'run.resume.model', 'run.steer', 'run.overrideAllNodes', 'run.setModel', 'run.setModel.node', 'run.setPermissions', 'run.start.continueSession', 'run.start.entryHistory', 'remote.owner.projects', 'remote.workspaces.probe', 'remote.engine.relay', 'remote.hosting.device.grant', 'extensions.manage', 'extensions.resources', 'skills.invoke', 'mcp.manage', 'runs.files', 'sessions.files', 'account.profile', 'sessions.stats', 'sessions.usage', 'config.analytics', 'config.analytics.planGate', 'sessions.trajectory', 'config.externalSubagent', 'config.decisions', 'browser.view', 'attachments.read', 'config.general', 'sessions.pullRequest', 'browser.view.go', 'config.browser', 'config.webSearch'];
@@ -68,7 +68,9 @@ export declare function gitStatus(root: string, options?: {
68
68
  * working tree is on is asked separately because a detached HEAD has none, and "absent from the
69
69
  * listing" would otherwise be indistinguishable from a branch that only does not exist yet.
70
70
  * Remote-tracking refs are left out: landing on one needs a tracking decision — which local branch
71
- * follows it — that this request cannot express.
71
+ * follows it — that this request cannot express. The repository has to be the workspace folder
72
+ * itself or its immediate parent (`gitInScope`); a repository Git would only reach further up the
73
+ * tree is not this folder's to offer.
72
74
  */
73
75
  export declare function listBranches(root: string): Promise<AppServerBranchList>;
74
76
  /**
@@ -80,6 +82,10 @@ export declare function listBranches(root: string): Promise<AppServerBranchList>
80
82
  * branch than the one in the request. Nothing else about the name is guessed; Git's own refusal is
81
83
  * what the caller reports, because it names the reason (no such branch, a working tree that would
82
84
  * lose changes) better than a rule kept in sync here could.
85
+ *
86
+ * The repository has to be the workspace folder itself or its immediate parent (`gitInScope`): a
87
+ * switch Git would only reach by walking further up the tree would move some ancestor repository's
88
+ * working tree, not this folder's.
83
89
  */
84
90
  export declare function checkoutBranch(root: string, options: {
85
91
  branch?: unknown;
@@ -93,6 +99,7 @@ export declare function checkoutBranch(root: string, options: {
93
99
  * `base` names what the diff is taken against: the working tree alone (unstaged changes, Git's
94
100
  * default) or `head`, which is what a per-file view wants because it includes staged and unstaged
95
101
  * changes together. Untracked files have no diff at all and are read as content by the client.
102
+ * A folder out of Git scope (`gitInScope`) has nothing to compare, answered without running Git.
96
103
  */
97
104
  export declare function gitDiff(root: string, options?: {
98
105
  path?: unknown;
@@ -2,7 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import { createReadStream } from 'node:fs';
3
3
  import { opendir, open, readFile, readdir, realpath, stat } from 'node:fs/promises';
4
4
  import { StringDecoder } from 'node:string_decoder';
5
- import { isAbsolute, join, relative, resolve, sep } from 'node:path';
5
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
6
6
  import { runRecordPath, runRecordsDirectory, sessionHasOpenRun } from '../run-records.js';
7
7
  import { validSavedSession } from '../sessions.js';
8
8
  import { listBundles } from '../extensions.js';
@@ -153,6 +153,32 @@ export async function readWorkspaceFile(root, name) {
153
153
  await handle.close();
154
154
  }
155
155
  }
156
+ /**
157
+ * Whether Git may be consulted about a workspace folder, and which repository that is: a `.git`
158
+ * sits at the folder itself or at its immediate parent, and the repository Git actually resolves
159
+ * to is one of those two.
160
+ *
161
+ * Git's own discovery never stops at the folder it is given — it walks every ancestor to the drive
162
+ * root — so on a machine whose home directory is itself a repository, a blank folder registered as
163
+ * a project is answered with that ancestor's branches and status, and a checkout would act on the
164
+ * ancestor's working tree. The parent stays in scope because a folder added directly inside a
165
+ * repository's root is still part of that repository's tree to the person who added it; nothing
166
+ * further up is. Presence is checked on the filesystem first, so a folder out of scope costs no
167
+ * process: `status --untracked-files=all` against an accidental ancestor of a large home directory
168
+ * would spend the whole timeout walking it. A `.git` that exists but is not a repository is
169
+ * skipped by Git, which then keeps walking — so the repository the folder resolves to is verified
170
+ * against this scope directly rather than assumed from what the filesystem happens to hold.
171
+ */
172
+ async function gitInScope(root) {
173
+ const parent = dirname(root);
174
+ const holds = async (folder) => stat(join(folder, '.git')).then(() => true, () => false);
175
+ if (!(await holds(root)) && !(await holds(parent)))
176
+ return false;
177
+ const top = await collectCapped('git', ['-C', root, 'rev-parse', '--show-toplevel'], 4 * 1024, GIT_TIMEOUT_MS).catch(() => undefined);
178
+ if (!top || top.code !== 0)
179
+ return false;
180
+ return inside(root, top.text.trim()) || inside(parent, top.text.trim());
181
+ }
156
182
  /**
157
183
  * Working-tree status through the `git` executable.
158
184
  *
@@ -166,6 +192,8 @@ export async function readWorkspaceFile(root, name) {
166
192
  * following field, so no path has to be decoded.
167
193
  */
168
194
  export async function gitStatus(root, options = {}) {
195
+ if (!(await gitInScope(root)))
196
+ return { repository: false, files: [] };
169
197
  let collected;
170
198
  try {
171
199
  // Streamed and capped, like the diff path: `execFile` fails the whole call once a repository's
@@ -230,9 +258,13 @@ const MAX_BRANCH_NAME_CHARS = 200;
230
258
  * working tree is on is asked separately because a detached HEAD has none, and "absent from the
231
259
  * listing" would otherwise be indistinguishable from a branch that only does not exist yet.
232
260
  * Remote-tracking refs are left out: landing on one needs a tracking decision — which local branch
233
- * follows it — that this request cannot express.
261
+ * follows it — that this request cannot express. The repository has to be the workspace folder
262
+ * itself or its immediate parent (`gitInScope`); a repository Git would only reach further up the
263
+ * tree is not this folder's to offer.
234
264
  */
235
265
  export async function listBranches(root) {
266
+ if (!(await gitInScope(root)))
267
+ return { repository: false, branches: [] };
236
268
  let collected;
237
269
  try {
238
270
  // `:lstrip=2` removes the fixed `refs/heads/` prefix instead of asking for an abbreviation:
@@ -286,8 +318,14 @@ export async function listBranches(root) {
286
318
  * branch than the one in the request. Nothing else about the name is guessed; Git's own refusal is
287
319
  * what the caller reports, because it names the reason (no such branch, a working tree that would
288
320
  * lose changes) better than a rule kept in sync here could.
321
+ *
322
+ * The repository has to be the workspace folder itself or its immediate parent (`gitInScope`): a
323
+ * switch Git would only reach by walking further up the tree would move some ancestor repository's
324
+ * working tree, not this folder's.
289
325
  */
290
326
  export async function checkoutBranch(root, options) {
327
+ if (!(await gitInScope(root)))
328
+ throw new Error('The project folder is not a Git repository');
291
329
  if (typeof options.branch !== 'string')
292
330
  throw new Error('A branch name must be a string');
293
331
  const name = options.branch.trim();
@@ -313,8 +351,11 @@ export async function checkoutBranch(root, options) {
313
351
  * `base` names what the diff is taken against: the working tree alone (unstaged changes, Git's
314
352
  * default) or `head`, which is what a per-file view wants because it includes staged and unstaged
315
353
  * changes together. Untracked files have no diff at all and are read as content by the client.
354
+ * A folder out of Git scope (`gitInScope`) has nothing to compare, answered without running Git.
316
355
  */
317
356
  export async function gitDiff(root, options = {}) {
357
+ if (!(await gitInScope(root)))
358
+ return { diff: '', truncated: false };
318
359
  // The pathspec keeps the name that was asked for. `resolveInside` follows the final component with
319
360
  // `realpath`, which is what a *read* needs — a link that leaves the project must be refused — but a
320
361
  // diff is addressed by Git: canonicalizing a tracked symlink would ask for its target's diff, which
@@ -5,7 +5,7 @@ import { mkdir, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises
5
5
  import { homedir } from 'node:os';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import { join, resolve } from 'node:path';
8
- import { changeConfigFile, configDirectory, ConfigConflictError, loadConfig, reconcileSubagentPair, resolveCodeIntelConfig, resolveConfiguredLimits, validateMcpServer } from './config.js';
8
+ import { changeConfigFile, configDirectory, ConfigConflictError, loadConfig, reconcileSubagentPair, resolveCodeIntelConfig, resolveConfiguredLimits, validateMcpServer, checkSearxngUrl, validateWebSearchConfig, WEB_SEARCH_FIELDS, WEB_SEARCH_KEY_FIELDS, WEB_SEARCH_PROVIDERS } from './config.js';
9
9
  import { isUnlimitedAlias } from './limits.js';
10
10
  import { isPermissionMode, workspacePermissionKey } from './permissions.js';
11
11
  import { RunControl } from './run-control.js';
@@ -74,6 +74,7 @@ import { TerminalFlow, TerminalManager } from './app-server/terminal.js';
74
74
  import { BrowserViewManager, browserViewUrl } from './browser-view.js';
75
75
  import { createBrowserIncognitoTool, createBrowserPanelTool, runPanelOperation, validatePanelArguments } from './browser-panel-tool.js';
76
76
  import { resolveCapsolverKey } from './capsolver.js';
77
+ import { resolveWebSearchProvider } from './web-search.js';
77
78
  import { checkoutBranch, gitDiff, gitStatus, listBranches, listExtensions, listRuns, readRun, readSessionTrajectory, runRecordFile, sessionTrajectoryFile, readTree, readWorkspaceFile, summarizeMcpServer, workspaceRoot } from './app-server/workspace.js';
78
79
  import { withReasoningEvents } from './app-server/reasoning.js';
79
80
  import { APP_SERVER_PROTOCOL_VERSION, APP_SERVER_CAPABILITIES, } from './app-server/protocol.js';
@@ -157,7 +158,7 @@ const RELAY_LONG_DEADLINE_MS = 1_260_000;
157
158
  */
158
159
  const MAX_RESUME_LINEAGE = 32;
159
160
  /** Fields a client may change through `config.set`. Anything else is rejected rather than merged. */
160
- const EDITABLE_CONFIG_KEYS = ['provider', 'providers', 'graph', 'graphSelections', 'jevEnabled', 'decisions', 'commandMemory', 'limits', 'workspacePermissions', 'mcpServers', 'extensions', 'memory', 'codeIntel', 'externalSubagent', 'analytics', 'systemPromptOverride', 'autoArchiveDays', 'browser'];
161
+ const EDITABLE_CONFIG_KEYS = ['provider', 'providers', 'graph', 'graphSelections', 'jevEnabled', 'decisions', 'commandMemory', 'limits', 'workspacePermissions', 'mcpServers', 'extensions', 'memory', 'codeIntel', 'externalSubagent', 'analytics', 'systemPromptOverride', 'autoArchiveDays', 'browser', 'webSearch'];
161
162
  function message(error) { return error instanceof Error ? error.message : String(error); }
162
163
  /** Project an owned authentication result instead of forwarding any official CLI payload wholesale. */
163
164
  function providerAuthView(view, includeUrl) {
@@ -450,6 +451,7 @@ function configView(config, analytics) {
450
451
  ...(config.systemPromptOverride === undefined ? {} : { systemPromptOverride: config.systemPromptOverride }),
451
452
  ...(config.autoArchiveDays === undefined ? {} : { autoArchiveDays: config.autoArchiveDays }),
452
453
  ...(resolveCapsolverKey(config) ? { browser: browserConfigView(config) } : {}),
454
+ ...webSearchConfigView(config),
453
455
  };
454
456
  }
455
457
  /** The Browser page's view: whether a CapSolver key exists and which one is used, never the key. No key at all omits the block. */
@@ -479,6 +481,68 @@ function mergeBrowserConfig(current, patch) {
479
481
  }
480
482
  return Object.keys(next).length ? next : undefined;
481
483
  }
484
+ /**
485
+ * The Web Search page's view: for each service whether a value is saved and which one the tool would
486
+ * use, the non-secret values as saved, and the chosen default. Never a key. Nothing saved or found in
487
+ * the environment omits the block.
488
+ */
489
+ function webSearchConfigView(config) {
490
+ const saved = config.webSearch ?? {};
491
+ const providers = Object.fromEntries(WEB_SEARCH_PROVIDERS.map(id => {
492
+ const resolved = resolveWebSearchProvider(id, config);
493
+ const stored = id === 'searxng' ? !!saved.searxngUrl : !!saved[WEB_SEARCH_KEY_FIELDS[id]];
494
+ return [id, { saved: stored, ...(resolved ? { source: resolved.source } : {}) }];
495
+ }));
496
+ if (!config.webSearch && !Object.values(providers).some(provider => provider.source))
497
+ return {};
498
+ return { webSearch: {
499
+ providers,
500
+ ...(saved.defaultProvider ? { defaultProvider: saved.defaultProvider } : {}),
501
+ ...(saved.googleSearchEngineId ? { googleSearchEngineId: saved.googleSearchEngineId } : {}),
502
+ ...(saved.searxngUrl ? { searxngUrl: saved.searxngUrl } : {}),
503
+ } };
504
+ }
505
+ /**
506
+ * Apply a `webSearch` patch to the stored block.
507
+ *
508
+ * Like `browser`, a patch names only what changes: a string saves a value, `null` removes it, and an
509
+ * omitted field keeps what is stored, because the view never carries the keys back. An empty block
510
+ * is dropped.
511
+ */
512
+ function mergeWebSearchConfig(current, patch) {
513
+ if (!patch || typeof patch !== 'object' || Array.isArray(patch))
514
+ throw new AppServerError('invalid-params', 'webSearch must be an object');
515
+ const fields = patch;
516
+ const unknown = Object.keys(fields).filter(key => !WEB_SEARCH_FIELDS.includes(key));
517
+ if (unknown.length)
518
+ throw new AppServerError('invalid-params', `webSearch accepts only ${WEB_SEARCH_FIELDS.join(', ')}`);
519
+ const next = { ...current };
520
+ for (const [field, value] of Object.entries(fields)) {
521
+ if (value === null) {
522
+ delete next[field];
523
+ continue;
524
+ }
525
+ if (value === undefined)
526
+ continue;
527
+ if (typeof value !== 'string' || !value.trim())
528
+ throw new AppServerError('invalid-params', `webSearch.${field} must be a nonempty string, or null to remove it`);
529
+ if (field === 'searxngUrl') {
530
+ const checked = checkSearxngUrl(value);
531
+ if ('error' in checked)
532
+ throw new AppServerError('invalid-params', checked.error);
533
+ next[field] = checked.url;
534
+ }
535
+ else
536
+ next[field] = value.trim();
537
+ }
538
+ try {
539
+ validateWebSearchConfig(next);
540
+ }
541
+ catch (error) {
542
+ throw new AppServerError('invalid-params', message(error));
543
+ }
544
+ return Object.keys(next).length ? next : undefined;
545
+ }
482
546
  /**
483
547
  * Merge a client's provider list with the stored secrets.
484
548
  *
@@ -1712,6 +1776,13 @@ export class AppServer {
1712
1776
  delete merged.systemPromptOverride;
1713
1777
  if (patch.autoArchiveDays === null)
1714
1778
  delete merged.autoArchiveDays;
1779
+ if (Object.hasOwn(patch, 'webSearch')) {
1780
+ const webSearch = mergeWebSearchConfig(current.webSearch, patch.webSearch);
1781
+ if (webSearch)
1782
+ merged.webSearch = webSearch;
1783
+ else
1784
+ delete merged.webSearch;
1785
+ }
1715
1786
  if (Object.hasOwn(patch, 'browser')) {
1716
1787
  const browser = mergeBrowserConfig(current.browser, patch.browser);
1717
1788
  if (browser)
@@ -6052,7 +6123,21 @@ export class AppServer {
6052
6123
  if (subject !== undefined && await currentGraphSubject() !== subject) {
6053
6124
  throw new AppServerError('auth', 'the signed-in account changed during the read; read the graph again');
6054
6125
  }
6055
- return { graph, ...(subject === undefined ? {} : { subject }) };
6126
+ // The copy a run would bind, beside the saved definition the editor and export read: a start
6127
+ // resolves the saved provider references through this installation's providers (the way
6128
+ // `loadAccessibleGraph` does) — aliasing a recorded identity this machine lacks and pinning its
6129
+ // recorded model — so a client previewing the graph's models names the pair that actually
6130
+ // executes rather than the saved references. A definition that cannot bind here refuses its run
6131
+ // outright, so the field is omitted and the client previews the saved references instead.
6132
+ let execution;
6133
+ try {
6134
+ execution = bindPortableGraphProviders(graph, await loadConfig(this.directory));
6135
+ }
6136
+ catch (error) {
6137
+ if (!(error instanceof GraphProviderUnavailableError))
6138
+ throw error;
6139
+ }
6140
+ return { graph, ...(execution !== undefined ? { execution } : {}), ...(subject === undefined ? {} : { subject }) };
6056
6141
  }
6057
6142
  /**
6058
6143
  * Persist the installation's graph selection.