pi-vault-mind 0.14.2 → 0.16.3

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 (164) hide show
  1. package/CHANGELOG.md +293 -0
  2. package/README.md +5 -5
  3. package/agents/broadcaster.agent.md +2 -2
  4. package/agents/heavy-lifter.agent.md +1 -1
  5. package/agents/main.agent.md +29 -0
  6. package/agents/manager.agent.md +1 -1
  7. package/agents/miner.agent.md +1 -1
  8. package/dist/packages/obsidian/src/client.js +331 -0
  9. package/dist/packages/obsidian/src/types.js +1 -0
  10. package/dist/src/activity.d.ts +49 -0
  11. package/dist/src/activity.js +175 -0
  12. package/dist/src/agent-bus/Agent.d.ts +9 -1
  13. package/dist/src/agent-bus/Agent.js +18 -2
  14. package/dist/src/agent-bus/index.d.ts +5 -5
  15. package/dist/src/agent-bus/index.js +1 -1
  16. package/dist/src/agent-queue.js +12 -3
  17. package/dist/src/agents/BroadcasterAgent.d.ts +1 -1
  18. package/dist/src/agents/BroadcasterAgent.js +2 -2
  19. package/dist/src/agents/HeavyLifterAgent.d.ts +1 -1
  20. package/dist/src/agents/HeavyLifterAgent.js +2 -2
  21. package/dist/src/agents/ManagerAgent.js +1 -1
  22. package/dist/src/agents/MinerAgent.d.ts +1 -1
  23. package/dist/src/agents/MinerAgent.js +2 -2
  24. package/dist/src/agents/index.d.ts +2 -2
  25. package/dist/src/agents/index.js +2 -2
  26. package/dist/src/auth.d.ts +17 -15
  27. package/dist/src/auth.js +26 -37
  28. package/dist/src/autosync.js +2 -2
  29. package/dist/src/commands.d.ts +2 -19
  30. package/dist/src/commands.js +301 -231
  31. package/dist/src/config-keys.d.ts +16 -0
  32. package/dist/src/config-keys.js +45 -0
  33. package/dist/src/discover-schema.js +4 -4
  34. package/dist/src/edits.d.ts +21 -0
  35. package/dist/src/edits.js +75 -0
  36. package/dist/src/embedding-probe.d.ts +34 -0
  37. package/dist/src/embedding-probe.js +142 -0
  38. package/dist/src/embedding-providers.d.ts +133 -0
  39. package/dist/src/embedding-providers.js +173 -0
  40. package/dist/src/embedding-secrets.d.ts +38 -0
  41. package/dist/src/embedding-secrets.js +291 -0
  42. package/dist/src/engine.d.ts +6 -0
  43. package/dist/src/engine.js +78 -6
  44. package/dist/src/events.js +7 -10
  45. package/dist/src/extension-packages.d.ts +9 -0
  46. package/dist/src/extension-packages.js +14 -0
  47. package/dist/src/git.d.ts +19 -0
  48. package/dist/src/git.js +78 -0
  49. package/dist/src/graph.d.ts +2 -1
  50. package/dist/src/graph.js +47 -13
  51. package/dist/src/identities-config.d.ts +6 -0
  52. package/dist/src/identities-config.js +39 -0
  53. package/dist/src/identity-injector.js +1 -1
  54. package/dist/src/index.js +9 -26
  55. package/dist/src/lance.d.ts +9 -0
  56. package/dist/src/lance.js +143 -203
  57. package/dist/src/modal-client.d.ts +16 -0
  58. package/dist/src/modal-client.js +16 -0
  59. package/dist/src/modal-config.d.ts +37 -14
  60. package/dist/src/modal-config.js +59 -32
  61. package/dist/src/model-router.d.ts +27 -0
  62. package/dist/src/model-router.js +67 -0
  63. package/dist/src/models.d.ts +42 -0
  64. package/dist/src/models.js +78 -0
  65. package/dist/src/personalize.js +17 -3
  66. package/dist/src/scaffold.d.ts +48 -0
  67. package/dist/src/scaffold.js +246 -0
  68. package/dist/src/server.d.ts +47 -4
  69. package/dist/src/server.js +988 -221
  70. package/dist/src/session-search.d.ts +63 -0
  71. package/dist/src/session-search.js +379 -0
  72. package/dist/src/settings-ui.d.ts +2 -2
  73. package/dist/src/settings-ui.js +76 -135
  74. package/dist/src/sync.d.ts +3 -3
  75. package/dist/src/sync.js +19 -15
  76. package/dist/src/tool-catalog.d.ts +18 -0
  77. package/dist/src/tool-catalog.js +232 -0
  78. package/dist/src/tools/marksman.js +1 -1
  79. package/dist/src/tools.js +111 -65
  80. package/dist/src/types.d.ts +127 -71
  81. package/dist/src/utils.d.ts +57 -6
  82. package/dist/src/utils.js +114 -28
  83. package/dist/src/vault-tools.d.ts +34 -0
  84. package/dist/src/vault-tools.js +99 -0
  85. package/dist/src/vault-writer.js +4 -1
  86. package/dist/src/vm-handlers.js +140 -43
  87. package/dist/src/watcher.js +9 -9
  88. package/dist/test/activity-tool.test.js +54 -0
  89. package/dist/test/agent-bus/Agent.test.js +174 -0
  90. package/dist/test/agent-bus/AgentLoader.test.js +180 -0
  91. package/dist/test/agent-bus/AgentRegistry.test.js +86 -0
  92. package/dist/test/agent-bus/LLMProvider.test.js +162 -0
  93. package/dist/test/agent-bus/TaskQueue.test.js +256 -0
  94. package/dist/test/agent-dispatch-context.test.js +73 -0
  95. package/dist/test/agent-queue.test.js +1 -1
  96. package/dist/test/agents/Agents.test.js +282 -0
  97. package/dist/test/auth.test.js +57 -56
  98. package/dist/test/bridge-identity.test.js +34 -3
  99. package/dist/test/classify-search-mode.test.js +51 -0
  100. package/dist/test/commands.test.js +410 -0
  101. package/dist/test/config-merge.test.js +98 -0
  102. package/dist/test/context-capture.test.js +56 -0
  103. package/dist/test/discover-schema.test.js +8 -5
  104. package/dist/test/dispatch.test.js +45 -91
  105. package/dist/test/edits.test.js +144 -0
  106. package/dist/test/embedding-probe.test.js +424 -0
  107. package/dist/test/embedding-providers.test.js +157 -0
  108. package/dist/test/embedding-secrets.test.js +210 -0
  109. package/dist/test/engine-identity.test.js +1 -1
  110. package/dist/test/events.test.js +675 -0
  111. package/dist/test/git-bridge.test.js +160 -0
  112. package/dist/test/graph.test.js +464 -0
  113. package/dist/test/helpers/server.js +81 -0
  114. package/dist/test/identity-injector.test.js +197 -0
  115. package/dist/test/index.test.js +5 -7
  116. package/dist/test/lance-modal.test.js +67 -2
  117. package/dist/test/lance.test.js +429 -0
  118. package/dist/test/modal-client.test.js +1 -1
  119. package/dist/test/modal-config.test.js +92 -79
  120. package/dist/test/model-readiness.test.js +122 -0
  121. package/dist/test/model-router.test.js +99 -0
  122. package/dist/test/obsidian-client.test.js +42 -0
  123. package/dist/test/personalize.test.js +1 -1
  124. package/dist/test/rest-models.test.js +153 -0
  125. package/dist/test/rest-queue.test.js +135 -87
  126. package/dist/test/rest-setup.test.js +625 -115
  127. package/dist/test/rest-vm.test.js +355 -94
  128. package/dist/test/server-cors.test.js +48 -0
  129. package/dist/test/server-ws.test.js +61 -34
  130. package/dist/test/session-crud.test.js +323 -0
  131. package/dist/test/session-search.test.js +139 -0
  132. package/dist/test/settings-ui.test.js +113 -4
  133. package/dist/test/sync.test.js +12 -12
  134. package/dist/test/tombstone.test.js +8 -10
  135. package/dist/test/tool-catalog.test.js +86 -0
  136. package/dist/test/utils.test.js +588 -0
  137. package/dist/test/vault-tools.test.js +103 -12
  138. package/dist/test/vault-writer.test.js +371 -0
  139. package/dist/test/vm-handlers.test.js +620 -0
  140. package/extension-packages.json +9 -0
  141. package/package.json +107 -90
  142. package/pi-vault-mind.config.example.json +24 -2
  143. package/scripts/check-deps.sh +35 -32
  144. package/scripts/cli-e2e.mjs +215 -0
  145. package/scripts/configuration-e2e.mjs +783 -0
  146. package/scripts/e2e-commands.mjs +391 -0
  147. package/scripts/e2e-ws.mjs +3 -2
  148. package/scripts/fetch-modal-token.sh +4 -3
  149. package/scripts/generate-config-keys-json.mjs +45 -0
  150. package/scripts/generate-extension-packages-json.mjs +55 -0
  151. package/scripts/pi-session-query +0 -0
  152. package/scripts/publish-obsidian-plugin.sh +0 -0
  153. package/scripts/reset-test-vault.sh +2 -2
  154. package/scripts/setup-test-config.sh +0 -0
  155. package/scripts/setup-vault-pi.sh +48 -9
  156. package/scripts/test-slash-commands.mjs +2 -2
  157. package/scripts/vault-pi.sh +12 -3
  158. package/skills/github-release-notes-file/SKILL.md +42 -0
  159. package/skills/obsidian-guided-test-session/SKILL.md +110 -0
  160. package/skills/obsidian-interactive-test/SKILL.md +88 -0
  161. package/skills/obsidian-plugin-publish/SKILL.md +58 -0
  162. package/skills/pi-vault-mind-release/SKILL.md +141 -0
  163. package/skills/pre-test-release/SKILL.md +116 -0
  164. package/dist/test/auto-indexer.test.js +0 -2
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Vault config scaffolding — the single, UI-agnostic implementation of
3
+ * "create/merge-safe-update the config + collection files + injector
4
+ * artifacts + vault-root .gitignore." Shared by every entry point that needs
5
+ * to scaffold a vault: the `/vm setup` CLI command (`commands.ts`), the HTTP
6
+ * `/vm/setup` API route (`server.ts`), and any future consumer (e.g. an
7
+ * Obsidian plugin refactor) — none of them should carry their own copy of
8
+ * the collections/injectors template.
9
+ */
10
+ import * as fs from "node:fs";
11
+ import * as path from "node:path";
12
+ import { EXT_ROOT, ensureDir, getConfigPath, loadConfig, resolveInitCollectionName, } from "./utils.js";
13
+ /**
14
+ * Vault-root `.gitignore` entries that keep pi-vault-mind compatible with
15
+ * `obsidian-git` (and, transitively, Obsidian Sync setups that also back up via
16
+ * git). The `.vault-mind/` directory holds local state (token, index, framework
17
+ * dir) that must never be committed, EXCEPT the hand-tuned config file, which is
18
+ * re-included via a `!` negation. The LanceDB index is a large, per-device,
19
+ * rebuildable binary; Obsidian's workspace UI state churns constantly. See
20
+ * docs/OBSIDIAN_SETUP.md §6.
21
+ */
22
+ export const GITIGNORE_ENTRIES = [
23
+ ".vault-mind/*",
24
+ "!.vault-mind/vault-mind.config.json",
25
+ ".lancedb/",
26
+ ".obsidian/workspace*.json",
27
+ ];
28
+ /**
29
+ * Decide what to do with the vault `.gitignore`, given its current contents
30
+ * (`null` if absent). Pure — does no I/O — so it is unit-testable. Creates the
31
+ * file when missing, appends only the entries that aren't already present
32
+ * (line-exact match, trimmed), and skips when everything is covered.
33
+ *
34
+ * A bare `.vault-mind/` directory exclude would block the per-file config
35
+ * negation (git cannot re-include a file inside an ignored directory), so when
36
+ * one is present it is rewritten to `.vault-mind/*` and the whole file returned.
37
+ */
38
+ export const planGitignore = (existing) => {
39
+ const createContent = "# pi-vault-mind: ignore local state, keep the hand-tuned config tracked\n" +
40
+ ".vault-mind/*\n" +
41
+ "!.vault-mind/vault-mind.config.json\n" +
42
+ "# rebuildable binary index\n" +
43
+ ".lancedb/\n" +
44
+ "# Obsidian UI workspace state churns constantly\n" +
45
+ ".obsidian/workspace*.json\n";
46
+ if (existing === null)
47
+ return { action: "create", content: createContent };
48
+ // Match leniently: `.lancedb`, `.lancedb/`, and `/.lancedb/` are one rule,
49
+ // so we don't append a duplicate when the user already ignores it differently.
50
+ const normalize = (s) => s.trim().replace(/^\/+|\/+$/g, "");
51
+ // Rewrite a bare `.vault-mind/` directory exclude to the glob form so the
52
+ // per-file config negation can take effect.
53
+ let rewrote = false;
54
+ const lines = existing.split(/\r?\n/).map((l) => {
55
+ if (normalize(l) === ".vault-mind") {
56
+ rewrote = true;
57
+ return ".vault-mind/*";
58
+ }
59
+ return l;
60
+ });
61
+ const present = new Set(lines.map(normalize));
62
+ const missing = GITIGNORE_ENTRIES.filter((e) => !present.has(normalize(e)));
63
+ if (rewrote) {
64
+ let content = lines.join("\n");
65
+ if (missing.length > 0) {
66
+ if (!content.endsWith("\n"))
67
+ content += "\n";
68
+ content += `# pi-vault-mind\n${missing.join("\n")}\n`;
69
+ }
70
+ else if (!content.endsWith("\n")) {
71
+ content += "\n";
72
+ }
73
+ return { action: "rewrite", content };
74
+ }
75
+ if (missing.length === 0)
76
+ return { action: "skip", content: "" };
77
+ const prefix = existing.length === 0 ? "" : existing.endsWith("\n") ? "\n" : "\n\n";
78
+ return { action: "append", content: `${prefix}# pi-vault-mind\n${missing.join("\n")}\n` };
79
+ };
80
+ /**
81
+ * Scaffold (or merge-safe-update) `.vault-mind/vault-mind.config.json`,
82
+ * the default collection files, injector artifacts, and vault-root
83
+ * `.gitignore` for `vaultPath`. UI-agnostic — returns what happened instead
84
+ * of notifying; callers (a CLI command, an HTTP handler, anything else)
85
+ * render the result however fits their surface.
86
+ */
87
+ export const scaffoldVaultConfig = (vaultPath, collectionOverride) => {
88
+ const created = [];
89
+ const updated = [];
90
+ const skipped = [];
91
+ const initCollection = resolveInitCollectionName(vaultPath, collectionOverride);
92
+ // `effectiveCfg.injectors` below concatenates DEFAULT_CONFIG's injectors
93
+ // with the file's own (mergeConfigLayer's design), which can list the
94
+ // same artifactPath twice once the file has its own "draft-context"
95
+ // entry — track handled paths so ensureFile reports each one once.
96
+ const handledPaths = new Set();
97
+ const ensureFile = (dest, tmpl) => {
98
+ if (handledPaths.has(dest))
99
+ return;
100
+ handledPaths.add(dest);
101
+ if (fs.existsSync(dest)) {
102
+ skipped.push(dest);
103
+ return;
104
+ }
105
+ ensureDir(dest);
106
+ const src = path.join(EXT_ROOT, "templates", tmpl);
107
+ fs.writeFileSync(dest, fs.existsSync(src) ? fs.readFileSync(src) : "", "utf-8");
108
+ created.push(dest);
109
+ };
110
+ const defaultCollections = {
111
+ main: {
112
+ path: `collections/${initCollection}.jsonl`,
113
+ schema: ["id", "domain", "source", "fact", "tag", "artifact"],
114
+ dedupField: "fact",
115
+ },
116
+ pending: { path: "collections/pending.jsonl", schema: "main" },
117
+ context_events: {
118
+ path: "collections/context_events.jsonl",
119
+ schema: ["id", "type", "session_entry_id", "content", "timestamp", "tags"],
120
+ dedupField: "id",
121
+ },
122
+ };
123
+ const defaultInjectors = [
124
+ {
125
+ name: "draft-context",
126
+ regex: "draft\\s+(\\S+)",
127
+ collection: "main",
128
+ filterField: "tag",
129
+ artifactPath: "collections/artifact.md",
130
+ },
131
+ ];
132
+ const cfgDest = getConfigPath(vaultPath);
133
+ if (!fs.existsSync(cfgDest)) {
134
+ const tmpl = {
135
+ version: 2,
136
+ collections: defaultCollections,
137
+ injectors: defaultInjectors,
138
+ identities: {
139
+ roles: {
140
+ main: {
141
+ allowedTools: [
142
+ "read",
143
+ "write",
144
+ "edit",
145
+ "bash",
146
+ "grep",
147
+ "find",
148
+ "ls",
149
+ "vm_search",
150
+ "vm_query",
151
+ "vm_append",
152
+ "vm_stats",
153
+ "vm_status",
154
+ "vm_describe",
155
+ "vm_configure",
156
+ "vault_read",
157
+ "vault_search",
158
+ "vault_list",
159
+ "vault_tags",
160
+ "vm_backlinks",
161
+ "vm_related",
162
+ "vm_broken_links",
163
+ "vm_codegraph_impact",
164
+ ],
165
+ },
166
+ },
167
+ },
168
+ vaultMind: {
169
+ dataDir: ".lancedb",
170
+ ftsEnabled: true,
171
+ graph: { enabled: true, canvasSync: false },
172
+ },
173
+ };
174
+ ensureDir(cfgDest);
175
+ fs.writeFileSync(cfgDest, `${JSON.stringify(tmpl, null, 2)}\n`, "utf-8");
176
+ created.push(cfgDest);
177
+ }
178
+ else {
179
+ // Merge-safe AND order-independent: whichever caller wrote the file
180
+ // first (a wizard writing embedding/vault fields, an HTTP setup call,
181
+ // anything else), this still seeds the default collections/injectors
182
+ // whenever they're missing or empty — never only when the file itself
183
+ // is brand new. Never touches fields that are already populated.
184
+ try {
185
+ const existing = JSON.parse(fs.readFileSync(cfgDest, "utf-8"));
186
+ let changed = false;
187
+ if (!existing.version) {
188
+ existing.version = 2;
189
+ changed = true;
190
+ }
191
+ if (!existing.collections || Object.keys(existing.collections).length === 0) {
192
+ existing.collections = defaultCollections;
193
+ changed = true;
194
+ }
195
+ if (!existing.injectors || existing.injectors.length === 0) {
196
+ existing.injectors = defaultInjectors;
197
+ changed = true;
198
+ }
199
+ if (!existing.vaultMind) {
200
+ existing.vaultMind = {};
201
+ changed = true;
202
+ }
203
+ if (changed) {
204
+ fs.writeFileSync(cfgDest, `${JSON.stringify(existing, null, 2)}\n`, "utf-8");
205
+ updated.push(cfgDest);
206
+ }
207
+ else {
208
+ skipped.push(cfgDest);
209
+ }
210
+ }
211
+ catch {
212
+ skipped.push(cfgDest);
213
+ }
214
+ }
215
+ // Reload the config we just wrote so we scaffold the collections it defines.
216
+ const effectiveCfg = fs.existsSync(cfgDest)
217
+ ? loadConfig(vaultPath)
218
+ : { collections: {}, injectors: [] };
219
+ for (const [name, def] of Object.entries(effectiveCfg.collections)) {
220
+ ensureFile(def.path, name === "pending" ? "PENDING_LEDGER.jsonl" : "UCL_LEDGER.jsonl");
221
+ }
222
+ for (const ij of effectiveCfg.injectors) {
223
+ if (ij.artifactPath)
224
+ ensureFile(ij.artifactPath, "ARTIFACT.md");
225
+ }
226
+ // Keep the rebuildable binary index out of git so obsidian-git (and git-backed
227
+ // Obsidian Sync setups) never commit it. See docs/OBSIDIAN_SETUP.md §6.
228
+ const gitignoreDest = path.join(vaultPath, ".gitignore");
229
+ const plan = planGitignore(fs.existsSync(gitignoreDest) ? fs.readFileSync(gitignoreDest, "utf-8") : null);
230
+ if (plan.action === "create") {
231
+ fs.writeFileSync(gitignoreDest, plan.content, "utf-8");
232
+ created.push(gitignoreDest);
233
+ }
234
+ else if (plan.action === "append") {
235
+ fs.appendFileSync(gitignoreDest, plan.content);
236
+ updated.push(gitignoreDest);
237
+ }
238
+ else if (plan.action === "rewrite") {
239
+ fs.writeFileSync(gitignoreDest, plan.content, "utf-8");
240
+ updated.push(gitignoreDest);
241
+ }
242
+ else {
243
+ skipped.push(gitignoreDest);
244
+ }
245
+ return { created, updated, skipped, collectionName: initCollection };
246
+ };
@@ -9,22 +9,48 @@
9
9
  * GET /vault-mind/context → latest editor context (file, cursor, selection) for pi agents
10
10
  *
11
11
  * Binds 127.0.0.1 only — no network exposure. Port defaults to 11435,
12
- * configurable via vaultMind.httpPort in pi-vault-mind.config.json.
12
+ * configurable via vaultMind.httpPort in .vault-mind/vault-mind.config.json.
13
13
  *
14
14
  * Used by the Vault Mind Obsidian plugin and local automation scripts to notify
15
15
  * pi of file saves via explicit push notifications.
16
16
  *
17
17
  * New Stage-1 routes (auth-gated by `PVM_API_TOKEN`):
18
- * GET /vm/status, POST /vm/init, POST /vm/setup, POST /server/start,
18
+ * GET /vm/status, POST /vm/setup, POST /server/start,
19
19
  * GET /vault-mind/config, GET /agent/queue, GET /agent/jobs/:id,
20
20
  * POST /agent/jobs/:id/retry, POST /agent/jobs/:id/cancel,
21
21
  * POST /vm/search, POST /vm/append, WS /agent/stream,
22
22
  * GET /vm/pending, POST /vm/approve.
23
+ * GET /vault-mind/models.
23
24
  */
24
25
  import * as http from "node:http";
25
26
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
26
27
  import { WebSocketServer } from "ws";
27
28
  import type { WatcherState } from "./watcher.js";
29
+ export type ModelReadinessStatus = "model-registry-error" | "model-registry-empty" | "provider-authentication-required" | "configured-provider-unavailable" | "model-selection-required" | "current-model-unavailable" | "ready";
30
+ export type ModelAuthSource = "stored" | "runtime" | "environment" | "fallback" | "models_json_key" | "models_json_command";
31
+ export type ModelReadinessResponse = {
32
+ status: "model-registry-error";
33
+ } | {
34
+ status: "model-registry-empty";
35
+ } | {
36
+ status: "provider-authentication-required";
37
+ authSource?: ModelAuthSource;
38
+ } | {
39
+ status: "configured-provider-unavailable";
40
+ providerId: string;
41
+ } | {
42
+ status: "model-selection-required";
43
+ } | {
44
+ status: "current-model-unavailable";
45
+ modelId: string;
46
+ } | {
47
+ status: "ready";
48
+ model: {
49
+ id: string;
50
+ name: string;
51
+ provider: string;
52
+ };
53
+ };
28
54
  export interface ServerState {
29
55
  server: http.Server | null;
30
56
  /** WebSocket server for live queue streaming. */
@@ -41,10 +67,21 @@ export interface ServerState {
41
67
  selection: string | null;
42
68
  cursor: number | null;
43
69
  };
44
- /** The vault path this server is serving (default vault from global config, or cwd). */
70
+ /** The vault path this server is serving (default vault from global config, { cwd }). */
45
71
  vaultPath?: string;
46
72
  /** Unsubscribe from queue notifications when stopping the server. */
47
73
  unsubQueue?: () => void;
74
+ /** Unsubscribe from tool-call bus events when stopping the server. */
75
+ unsubToolBus?: () => void;
76
+ /**
77
+ * ID of the session currently being used by the active pi RPC subprocess.
78
+ * Set when the plugin opens a chat session, cleared on disconnect.
79
+ * DELETE/PATCH on this id is rejected with 409 Conflict to prevent corrupting
80
+ * the live connection.
81
+ */
82
+ activeSessionId?: string;
83
+ /** Async callback to derive model readiness from ExtensionContext.modelRegistry. */
84
+ getModelReadiness?: () => Promise<ModelReadinessResponse>;
48
85
  }
49
86
  export declare function createServerState(port?: number): ServerState;
50
87
  export type ServerEvent = {
@@ -65,7 +102,12 @@ export type ServerEvent = {
65
102
  export declare const emitVaultEditProposed: (wss: WebSocketServer | null, path: string, oldContent: string, newContent: string, jobId?: string) => void;
66
103
  export declare const emitJobNotification: (wss: WebSocketServer | null, jobId: string, status: string, message: string) => void;
67
104
  export declare const emitContextRequest: (wss: WebSocketServer | null, requestId: string) => void;
68
- export declare function startServer(pi: ExtensionAPI, serverState: ServerState, watcherState: WatcherState): void;
105
+ type CorsResponse = {
106
+ setHeader(name: string, value: string): unknown;
107
+ };
108
+ /** Apply the browser policy for the local bridge without reflecting arbitrary origins. */
109
+ export declare function applyCorsPolicy(origin: string | undefined, serverPort: number, res: CorsResponse): void;
110
+ export declare function startServer(pi: ExtensionAPI, serverState: ServerState, watcherState: WatcherState, readinessCallback?: () => Promise<ModelReadinessResponse>): void;
69
111
  export declare function stopServer(serverState: ServerState): void;
70
112
  /**
71
113
  * Wrap a request handler with bearer-token auth. Use this for every
@@ -81,3 +123,4 @@ export declare const withAuth: (req: http.IncomingMessage, res: http.ServerRespo
81
123
  }) => void;
82
124
  /** Read the full request body as UTF-8. Already used by handleScan; exposed for new routes. */
83
125
  export declare const readJsonBody: (req: http.IncomingMessage) => Promise<unknown>;
126
+ export {};