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.
- package/CHANGELOG.md +293 -0
- package/README.md +5 -5
- package/agents/broadcaster.agent.md +2 -2
- package/agents/heavy-lifter.agent.md +1 -1
- package/agents/main.agent.md +29 -0
- package/agents/manager.agent.md +1 -1
- package/agents/miner.agent.md +1 -1
- package/dist/packages/obsidian/src/client.js +331 -0
- package/dist/packages/obsidian/src/types.js +1 -0
- package/dist/src/activity.d.ts +49 -0
- package/dist/src/activity.js +175 -0
- package/dist/src/agent-bus/Agent.d.ts +9 -1
- package/dist/src/agent-bus/Agent.js +18 -2
- package/dist/src/agent-bus/index.d.ts +5 -5
- package/dist/src/agent-bus/index.js +1 -1
- package/dist/src/agent-queue.js +12 -3
- package/dist/src/agents/BroadcasterAgent.d.ts +1 -1
- package/dist/src/agents/BroadcasterAgent.js +2 -2
- package/dist/src/agents/HeavyLifterAgent.d.ts +1 -1
- package/dist/src/agents/HeavyLifterAgent.js +2 -2
- package/dist/src/agents/ManagerAgent.js +1 -1
- package/dist/src/agents/MinerAgent.d.ts +1 -1
- package/dist/src/agents/MinerAgent.js +2 -2
- package/dist/src/agents/index.d.ts +2 -2
- package/dist/src/agents/index.js +2 -2
- package/dist/src/auth.d.ts +17 -15
- package/dist/src/auth.js +26 -37
- package/dist/src/autosync.js +2 -2
- package/dist/src/commands.d.ts +2 -19
- package/dist/src/commands.js +301 -231
- package/dist/src/config-keys.d.ts +16 -0
- package/dist/src/config-keys.js +45 -0
- package/dist/src/discover-schema.js +4 -4
- package/dist/src/edits.d.ts +21 -0
- package/dist/src/edits.js +75 -0
- package/dist/src/embedding-probe.d.ts +34 -0
- package/dist/src/embedding-probe.js +142 -0
- package/dist/src/embedding-providers.d.ts +133 -0
- package/dist/src/embedding-providers.js +173 -0
- package/dist/src/embedding-secrets.d.ts +38 -0
- package/dist/src/embedding-secrets.js +291 -0
- package/dist/src/engine.d.ts +6 -0
- package/dist/src/engine.js +78 -6
- package/dist/src/events.js +7 -10
- package/dist/src/extension-packages.d.ts +9 -0
- package/dist/src/extension-packages.js +14 -0
- package/dist/src/git.d.ts +19 -0
- package/dist/src/git.js +78 -0
- package/dist/src/graph.d.ts +2 -1
- package/dist/src/graph.js +47 -13
- package/dist/src/identities-config.d.ts +6 -0
- package/dist/src/identities-config.js +39 -0
- package/dist/src/identity-injector.js +1 -1
- package/dist/src/index.js +9 -26
- package/dist/src/lance.d.ts +9 -0
- package/dist/src/lance.js +143 -203
- package/dist/src/modal-client.d.ts +16 -0
- package/dist/src/modal-client.js +16 -0
- package/dist/src/modal-config.d.ts +37 -14
- package/dist/src/modal-config.js +59 -32
- package/dist/src/model-router.d.ts +27 -0
- package/dist/src/model-router.js +67 -0
- package/dist/src/models.d.ts +42 -0
- package/dist/src/models.js +78 -0
- package/dist/src/personalize.js +17 -3
- package/dist/src/scaffold.d.ts +48 -0
- package/dist/src/scaffold.js +246 -0
- package/dist/src/server.d.ts +47 -4
- package/dist/src/server.js +988 -221
- package/dist/src/session-search.d.ts +63 -0
- package/dist/src/session-search.js +379 -0
- package/dist/src/settings-ui.d.ts +2 -2
- package/dist/src/settings-ui.js +76 -135
- package/dist/src/sync.d.ts +3 -3
- package/dist/src/sync.js +19 -15
- package/dist/src/tool-catalog.d.ts +18 -0
- package/dist/src/tool-catalog.js +232 -0
- package/dist/src/tools/marksman.js +1 -1
- package/dist/src/tools.js +111 -65
- package/dist/src/types.d.ts +127 -71
- package/dist/src/utils.d.ts +57 -6
- package/dist/src/utils.js +114 -28
- package/dist/src/vault-tools.d.ts +34 -0
- package/dist/src/vault-tools.js +99 -0
- package/dist/src/vault-writer.js +4 -1
- package/dist/src/vm-handlers.js +140 -43
- package/dist/src/watcher.js +9 -9
- package/dist/test/activity-tool.test.js +54 -0
- package/dist/test/agent-bus/Agent.test.js +174 -0
- package/dist/test/agent-bus/AgentLoader.test.js +180 -0
- package/dist/test/agent-bus/AgentRegistry.test.js +86 -0
- package/dist/test/agent-bus/LLMProvider.test.js +162 -0
- package/dist/test/agent-bus/TaskQueue.test.js +256 -0
- package/dist/test/agent-dispatch-context.test.js +73 -0
- package/dist/test/agent-queue.test.js +1 -1
- package/dist/test/agents/Agents.test.js +282 -0
- package/dist/test/auth.test.js +57 -56
- package/dist/test/bridge-identity.test.js +34 -3
- package/dist/test/classify-search-mode.test.js +51 -0
- package/dist/test/commands.test.js +410 -0
- package/dist/test/config-merge.test.js +98 -0
- package/dist/test/context-capture.test.js +56 -0
- package/dist/test/discover-schema.test.js +8 -5
- package/dist/test/dispatch.test.js +45 -91
- package/dist/test/edits.test.js +144 -0
- package/dist/test/embedding-probe.test.js +424 -0
- package/dist/test/embedding-providers.test.js +157 -0
- package/dist/test/embedding-secrets.test.js +210 -0
- package/dist/test/engine-identity.test.js +1 -1
- package/dist/test/events.test.js +675 -0
- package/dist/test/git-bridge.test.js +160 -0
- package/dist/test/graph.test.js +464 -0
- package/dist/test/helpers/server.js +81 -0
- package/dist/test/identity-injector.test.js +197 -0
- package/dist/test/index.test.js +5 -7
- package/dist/test/lance-modal.test.js +67 -2
- package/dist/test/lance.test.js +429 -0
- package/dist/test/modal-client.test.js +1 -1
- package/dist/test/modal-config.test.js +92 -79
- package/dist/test/model-readiness.test.js +122 -0
- package/dist/test/model-router.test.js +99 -0
- package/dist/test/obsidian-client.test.js +42 -0
- package/dist/test/personalize.test.js +1 -1
- package/dist/test/rest-models.test.js +153 -0
- package/dist/test/rest-queue.test.js +135 -87
- package/dist/test/rest-setup.test.js +625 -115
- package/dist/test/rest-vm.test.js +355 -94
- package/dist/test/server-cors.test.js +48 -0
- package/dist/test/server-ws.test.js +61 -34
- package/dist/test/session-crud.test.js +323 -0
- package/dist/test/session-search.test.js +139 -0
- package/dist/test/settings-ui.test.js +113 -4
- package/dist/test/sync.test.js +12 -12
- package/dist/test/tombstone.test.js +8 -10
- package/dist/test/tool-catalog.test.js +86 -0
- package/dist/test/utils.test.js +588 -0
- package/dist/test/vault-tools.test.js +103 -12
- package/dist/test/vault-writer.test.js +371 -0
- package/dist/test/vm-handlers.test.js +620 -0
- package/extension-packages.json +9 -0
- package/package.json +107 -90
- package/pi-vault-mind.config.example.json +24 -2
- package/scripts/check-deps.sh +35 -32
- package/scripts/cli-e2e.mjs +215 -0
- package/scripts/configuration-e2e.mjs +783 -0
- package/scripts/e2e-commands.mjs +391 -0
- package/scripts/e2e-ws.mjs +3 -2
- package/scripts/fetch-modal-token.sh +4 -3
- package/scripts/generate-config-keys-json.mjs +45 -0
- package/scripts/generate-extension-packages-json.mjs +55 -0
- package/scripts/pi-session-query +0 -0
- package/scripts/publish-obsidian-plugin.sh +0 -0
- package/scripts/reset-test-vault.sh +2 -2
- package/scripts/setup-test-config.sh +0 -0
- package/scripts/setup-vault-pi.sh +48 -9
- package/scripts/test-slash-commands.mjs +2 -2
- package/scripts/vault-pi.sh +12 -3
- package/skills/github-release-notes-file/SKILL.md +42 -0
- package/skills/obsidian-guided-test-session/SKILL.md +110 -0
- package/skills/obsidian-interactive-test/SKILL.md +88 -0
- package/skills/obsidian-plugin-publish/SKILL.md +58 -0
- package/skills/pi-vault-mind-release/SKILL.md +141 -0
- package/skills/pre-test-release/SKILL.md +116 -0
- 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
|
+
};
|
package/dist/src/server.d.ts
CHANGED
|
@@ -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
|
|
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/
|
|
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,
|
|
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
|
-
|
|
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 {};
|