pi-knowledge 0.15.0 → 0.16.1

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 (61) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +61 -23
  3. package/dist/index.d.ts +10 -4
  4. package/dist/index.js +145 -166
  5. package/dist/src/coverage-snapshot.d.ts +23 -0
  6. package/dist/src/coverage-snapshot.js +53 -0
  7. package/dist/src/daemon/client.d.ts +60 -0
  8. package/dist/src/daemon/client.js +360 -0
  9. package/dist/src/daemon/main.d.ts +2 -0
  10. package/dist/src/daemon/main.js +109 -0
  11. package/dist/src/daemon/protocol.d.ts +71 -0
  12. package/dist/src/daemon/protocol.js +170 -0
  13. package/dist/src/daemon/runtime.d.ts +26 -0
  14. package/dist/src/daemon/runtime.js +192 -0
  15. package/dist/src/daemon/server.d.ts +46 -0
  16. package/dist/src/daemon/server.js +500 -0
  17. package/dist/src/daemon/service.d.ts +49 -0
  18. package/dist/src/daemon/service.js +527 -0
  19. package/dist/src/diagnostics/health.d.ts +6 -0
  20. package/dist/src/diagnostics/health.js +135 -2
  21. package/dist/src/engine.d.ts +13 -8
  22. package/dist/src/engine.js +569 -100
  23. package/dist/src/filesystem-access.d.ts +9 -0
  24. package/dist/src/filesystem-access.js +100 -0
  25. package/dist/src/indexer/chunker.d.ts +12 -0
  26. package/dist/src/indexer/chunker.js +307 -9
  27. package/dist/src/mcp/http.d.ts +47 -0
  28. package/dist/src/mcp/http.js +564 -0
  29. package/dist/src/mcp/main.d.ts +2 -0
  30. package/dist/src/mcp/main.js +97 -0
  31. package/dist/src/mcp/protocol.d.ts +81 -0
  32. package/dist/src/mcp/protocol.js +444 -0
  33. package/dist/src/mcp/server.d.ts +42 -0
  34. package/dist/src/mcp/server.js +378 -0
  35. package/dist/src/model-worker-client.js +9 -0
  36. package/dist/src/model-worker-contract.d.ts +3 -0
  37. package/dist/src/model-worker-contract.js +8 -0
  38. package/dist/src/model-worker.js +76 -4
  39. package/dist/src/network/safe-fetch.d.ts +7 -0
  40. package/dist/src/network/safe-fetch.js +199 -0
  41. package/dist/src/node-runtime.d.ts +3 -0
  42. package/dist/src/node-runtime.js +78 -0
  43. package/dist/src/profiles.d.ts +15 -0
  44. package/dist/src/profiles.js +160 -0
  45. package/dist/src/runtime-config.js +5 -6
  46. package/dist/src/secure-files.d.ts +17 -0
  47. package/dist/src/secure-files.js +183 -0
  48. package/dist/src/status.js +12 -7
  49. package/dist/src/storage/sqlite.d.ts +4 -1
  50. package/dist/src/storage/sqlite.js +46 -3
  51. package/dist/src/type-guards.d.ts +1 -0
  52. package/dist/src/type-guards.js +3 -0
  53. package/dist/src/watcher/file-watcher.d.ts +3 -1
  54. package/dist/src/watcher/file-watcher.js +166 -32
  55. package/dist/src/windows-security.d.ts +4 -0
  56. package/dist/src/windows-security.js +67 -0
  57. package/docs/configuration.md +40 -9
  58. package/docs/daemon-profiles.md +302 -0
  59. package/docs/mcp-clients.md +266 -0
  60. package/docs/offline-mode.md +6 -6
  61. package/package.json +28 -2
@@ -0,0 +1,360 @@
1
+ import { spawn } from "node:child_process";
2
+ import { randomUUID } from "node:crypto";
3
+ import { existsSync } from "node:fs";
4
+ import { createConnection } from "node:net";
5
+ import { StringDecoder } from "node:string_decoder";
6
+ import { setTimeout as delay } from "node:timers/promises";
7
+ import { fileURLToPath } from "node:url";
8
+ import { configureDaemonNodePath, resolveDaemonNodePath } from "../node-runtime.js";
9
+ import { resolveKnowledgeProfile } from "../profiles.js";
10
+ import { DAEMON_PROTOCOL_VERSION, DAEMON_REQUEST_TIMEOUT_MS, DAEMON_SHUTDOWN_GRACE_MS, DAEMON_SHUTDOWN_SETTLE_MS, DAEMON_START_TIMEOUT_MS, MAX_RPC_FRAME_BYTES, packageBuildIdentity, packageVersion, parseDaemonServerFrame, runtimeConfigurationSignature, } from "./protocol.js";
11
+ import { processIsAlive, readDaemonManifest, readDaemonOwner } from "./runtime.js";
12
+ function serializeFilesystemAccess(access) {
13
+ if (!access)
14
+ return undefined;
15
+ return { allowed_roots: access.allowedRoots, allow_network: access.allowNetwork };
16
+ }
17
+ function requestDaemon(profile, method, params, signal, onProgress, manifestOverride) {
18
+ if (signal?.aborted)
19
+ return Promise.reject(new Error("Cancelled"));
20
+ const manifest = manifestOverride ?? readDaemonManifest(profile);
21
+ if (!manifest)
22
+ return Promise.reject(new Error(`Knowledge profile daemon is not running: ${profile.name}`));
23
+ if (manifest.protocol_version !== DAEMON_PROTOCOL_VERSION) {
24
+ return Promise.reject(new Error(`Unsupported daemon protocol version: ${manifest.protocol_version}`));
25
+ }
26
+ const requestId = randomUUID();
27
+ const { promise, resolve, reject } = Promise.withResolvers();
28
+ const socket = createConnection(manifest.endpoint);
29
+ let buffer = "";
30
+ const decoder = new StringDecoder("utf8");
31
+ let settled = false;
32
+ const finish = (error, result) => {
33
+ if (settled)
34
+ return;
35
+ settled = true;
36
+ clearTimeout(timeout);
37
+ signal?.removeEventListener("abort", abort);
38
+ socket.destroy();
39
+ if (error)
40
+ reject(error);
41
+ else
42
+ resolve(result);
43
+ };
44
+ const abort = () => {
45
+ if (settled)
46
+ return;
47
+ if (socket.writable) {
48
+ socket.write(`${JSON.stringify({ type: "cancel", version: DAEMON_PROTOCOL_VERSION, id: requestId, token: manifest.auth_token })}\n`);
49
+ }
50
+ finish(new Error("Cancelled"));
51
+ };
52
+ const timeout = setTimeout(() => finish(new Error(`Daemon request timed out: ${method}`)), method === "ping"
53
+ ? DAEMON_START_TIMEOUT_MS
54
+ : method === "shutdown"
55
+ ? DAEMON_SHUTDOWN_GRACE_MS + DAEMON_SHUTDOWN_SETTLE_MS + 5_000
56
+ : DAEMON_REQUEST_TIMEOUT_MS);
57
+ signal?.addEventListener("abort", abort, { once: true });
58
+ socket.once("connect", () => {
59
+ socket.write(`${JSON.stringify({
60
+ type: "request",
61
+ version: DAEMON_PROTOCOL_VERSION,
62
+ id: requestId,
63
+ token: manifest.auth_token,
64
+ package_version: packageVersion(),
65
+ build_identity: packageBuildIdentity(),
66
+ method,
67
+ params,
68
+ })}\n`);
69
+ });
70
+ socket.on("data", (chunk) => {
71
+ buffer += decoder.write(chunk);
72
+ if (Buffer.byteLength(buffer) > MAX_RPC_FRAME_BYTES) {
73
+ finish(new Error("Daemon response exceeds the configured frame limit"));
74
+ return;
75
+ }
76
+ let newline = buffer.indexOf("\n");
77
+ while (newline >= 0) {
78
+ const line = buffer.slice(0, newline).trim();
79
+ buffer = buffer.slice(newline + 1);
80
+ if (line) {
81
+ try {
82
+ const frame = parseDaemonServerFrame(JSON.parse(line));
83
+ if (frame.id !== requestId)
84
+ throw new Error("Daemon response request id mismatch");
85
+ if (frame.type === "progress")
86
+ onProgress?.(frame.message);
87
+ else if (frame.type === "error")
88
+ finish(new Error(frame.message));
89
+ else
90
+ finish(undefined, frame.result);
91
+ }
92
+ catch (error) {
93
+ finish(error instanceof Error ? error : new Error(String(error)));
94
+ }
95
+ }
96
+ newline = buffer.indexOf("\n");
97
+ }
98
+ });
99
+ socket.once("error", (error) => finish(error));
100
+ socket.once("close", () => {
101
+ if (!settled)
102
+ finish(new Error("Daemon connection closed before a response"));
103
+ });
104
+ return promise;
105
+ }
106
+ function daemonEntryPath() {
107
+ const current = fileURLToPath(import.meta.url);
108
+ const extension = current.endsWith(".js") ? ".js" : ".ts";
109
+ const path = fileURLToPath(new URL(`./main${extension}`, import.meta.url));
110
+ if (!existsSync(path))
111
+ throw new Error(`Profile daemon entry not found: ${path}`);
112
+ return path;
113
+ }
114
+ function daemonEnvironment(profile) {
115
+ const env = {};
116
+ const exactKeys = [
117
+ "HOME",
118
+ "USERPROFILE",
119
+ "TMPDIR",
120
+ "TEMP",
121
+ "TMP",
122
+ "SYSTEMROOT",
123
+ "WINDIR",
124
+ "SSL_CERT_FILE",
125
+ "SSL_CERT_DIR",
126
+ "HTTP_PROXY",
127
+ "HTTPS_PROXY",
128
+ "NO_PROXY",
129
+ ];
130
+ for (const key of exactKeys) {
131
+ if (process.env[key] !== undefined)
132
+ env[key] = process.env[key];
133
+ }
134
+ for (const [key, value] of Object.entries(process.env)) {
135
+ if (key.startsWith("PI_KNOWLEDGE_") || key.startsWith("OPENAI_"))
136
+ env[key] = value;
137
+ }
138
+ delete env.NODE_OPTIONS;
139
+ delete env.NODE_PATH;
140
+ delete env.PI_KNOWLEDGE_MCP_HTTP_TOKEN;
141
+ env.PI_KNOWLEDGE_PROFILE = profile.name;
142
+ env.PI_KNOWLEDGE_PROFILE_ROOT = profile.profileRoot;
143
+ if (profile.name === "default")
144
+ env.PI_KNOWLEDGE_DIR = profile.storageDir;
145
+ else {
146
+ delete env.PI_KNOWLEDGE_DIR;
147
+ delete env.OMP_KNOWLEDGE_DIR;
148
+ }
149
+ return env;
150
+ }
151
+ function spawnDaemon(profile) {
152
+ const nodePath = resolveDaemonNodePath(profile);
153
+ const entry = daemonEntryPath();
154
+ const args = entry.endsWith(".ts") ? ["--experimental-strip-types", entry, "run"] : [entry, "run"];
155
+ args.push("--profile", profile.name, "--expect-profile-id", profile.id);
156
+ const { promise, resolve, reject } = Promise.withResolvers();
157
+ const child = spawn(nodePath, args, {
158
+ cwd: profile.storageDir,
159
+ detached: true,
160
+ env: daemonEnvironment(profile),
161
+ shell: false,
162
+ stdio: "ignore",
163
+ windowsHide: true,
164
+ });
165
+ child.once("error", reject);
166
+ child.once("spawn", () => {
167
+ if (child.pid === undefined) {
168
+ reject(new Error("Profile daemon process started without a process id"));
169
+ return;
170
+ }
171
+ resolve(child.pid);
172
+ });
173
+ child.unref();
174
+ return promise;
175
+ }
176
+ function assertRuntimeConfiguration(ping) {
177
+ const expected = runtimeConfigurationSignature();
178
+ if (ping.runtime_configuration_signature !== expected) {
179
+ throw new Error("Knowledge profile daemon is running with different runtime configuration; stop and restart it before using this client");
180
+ }
181
+ }
182
+ async function waitForDaemonReady(profile, expectedPid, deadline = Date.now() + DAEMON_START_TIMEOUT_MS) {
183
+ let lastError;
184
+ while (Date.now() < deadline) {
185
+ const candidate = readDaemonManifest(profile);
186
+ if (candidate) {
187
+ let ping;
188
+ try {
189
+ ping = await requestDaemon(profile, "ping", {}, undefined, undefined, candidate);
190
+ }
191
+ catch (error) {
192
+ lastError = error instanceof Error ? error : new Error(String(error));
193
+ }
194
+ if (ping) {
195
+ assertRuntimeConfiguration(ping);
196
+ if (ping.ready)
197
+ return new KnowledgeDaemonClient(profile);
198
+ }
199
+ }
200
+ if (!processIsAlive(expectedPid)) {
201
+ const owner = readDaemonOwner(profile);
202
+ if (!owner || !processIsAlive(owner.pid))
203
+ return undefined;
204
+ }
205
+ await delay(50);
206
+ }
207
+ throw new Error(`Knowledge profile daemon did not become ready: ${lastError?.message ?? profile.name}`);
208
+ }
209
+ const ensureRuns = new Map();
210
+ export async function ensureDaemonClient(profile = resolveKnowledgeProfile()) {
211
+ const existing = ensureRuns.get(profile.id);
212
+ if (existing)
213
+ return existing;
214
+ const run = (async () => {
215
+ const manifest = readDaemonManifest(profile);
216
+ if (manifest) {
217
+ if (manifest.package_version !== packageVersion() || manifest.build_identity !== packageBuildIdentity()) {
218
+ try {
219
+ await requestDaemon(profile, "shutdown", {}, undefined, undefined, manifest);
220
+ await waitForDaemonShutdown(profile, manifest.instance_id);
221
+ }
222
+ catch (error) {
223
+ const owner = readDaemonOwner(profile);
224
+ if (owner?.instance_id === manifest.instance_id && processIsAlive(owner.pid)) {
225
+ await waitForDaemonShutdown(profile, manifest.instance_id);
226
+ }
227
+ else {
228
+ const replacement = readDaemonManifest(profile);
229
+ if (replacement &&
230
+ replacement.instance_id !== manifest.instance_id &&
231
+ replacement.package_version === packageVersion() &&
232
+ replacement.build_identity === packageBuildIdentity()) {
233
+ const ready = await waitForDaemonReady(profile, replacement.pid);
234
+ if (ready)
235
+ return ready;
236
+ }
237
+ if (owner?.instance_id === manifest.instance_id) {
238
+ // A dead stale owner is recovered by the normal ownership election below.
239
+ }
240
+ else if (owner && processIsAlive(owner.pid)) {
241
+ throw error;
242
+ }
243
+ }
244
+ }
245
+ }
246
+ else {
247
+ const ready = await waitForDaemonReady(profile, manifest.pid);
248
+ if (ready)
249
+ return ready;
250
+ }
251
+ }
252
+ const startupDeadline = Date.now() + DAEMON_START_TIMEOUT_MS;
253
+ let spawnedPid;
254
+ do {
255
+ spawnedPid = await spawnDaemon(profile);
256
+ const ready = await waitForDaemonReady(profile, spawnedPid, startupDeadline);
257
+ if (ready)
258
+ return ready;
259
+ const owner = readDaemonOwner(profile);
260
+ if (owner && processIsAlive(owner.pid)) {
261
+ throw new Error(`Knowledge profile daemon process ${spawnedPid} exited while owner PID ${owner.pid} remained live`);
262
+ }
263
+ } while (Date.now() < startupDeadline);
264
+ throw new Error(`Knowledge profile daemon process ${String(spawnedPid)} exited before becoming ready`);
265
+ })().finally(() => {
266
+ if (ensureRuns.get(profile.id) === run)
267
+ ensureRuns.delete(profile.id);
268
+ });
269
+ ensureRuns.set(profile.id, run);
270
+ return run;
271
+ }
272
+ export async function configureAndEnsureDaemonClient(profile, nodePath, signal) {
273
+ if (signal?.aborted)
274
+ throw new Error("Cancelled");
275
+ configureDaemonNodePath(profile, nodePath);
276
+ if (signal?.aborted)
277
+ throw new Error("Cancelled");
278
+ return ensureDaemonClient(profile);
279
+ }
280
+ export async function waitForDaemonShutdown(profile, instanceId, timeoutMs = DAEMON_SHUTDOWN_GRACE_MS + DAEMON_SHUTDOWN_SETTLE_MS + 5_000) {
281
+ const deadline = Date.now() + timeoutMs;
282
+ while (Date.now() < deadline) {
283
+ const manifest = readDaemonManifest(profile);
284
+ const owner = readDaemonOwner(profile);
285
+ const manifestReleased = !manifest || manifest.instance_id !== instanceId;
286
+ const ownerReleased = !owner || owner.instance_id !== instanceId;
287
+ if (manifestReleased && ownerReleased)
288
+ return;
289
+ await delay(50);
290
+ }
291
+ throw new Error(`Knowledge profile daemon did not stop within ${timeoutMs}ms`);
292
+ }
293
+ export class KnowledgeDaemonClient {
294
+ profile;
295
+ constructor(profile) {
296
+ this.profile = profile;
297
+ }
298
+ ping(signal) {
299
+ return requestDaemon(this.profile, "ping", {}, signal);
300
+ }
301
+ plan(source, options = {}, signal, access) {
302
+ return requestDaemon(this.profile, "plan", { source, options, access: serializeFilesystemAccess(access) }, signal);
303
+ }
304
+ configure(nodePath, signal) {
305
+ return requestDaemon(this.profile, "configure", { node_path: nodePath }, signal);
306
+ }
307
+ add(source, name, onProgress, signal, options = {}, access) {
308
+ return requestDaemon(this.profile, "add", { source, name, options, access: serializeFilesystemAccess(access) }, signal, onProgress);
309
+ }
310
+ search(query, options = {}, signal) {
311
+ return requestDaemon(this.profile, "search", { query, options }, signal);
312
+ }
313
+ symbolSearch(query, options = {}, signal) {
314
+ return requestDaemon(this.profile, "symbol_search", { query, options }, signal);
315
+ }
316
+ update(target, onProgress, signal, access) {
317
+ return requestDaemon(this.profile, "update", { target, access: serializeFilesystemAccess(access) }, signal, onProgress);
318
+ }
319
+ list(signal) {
320
+ return requestDaemon(this.profile, "list", {}, signal);
321
+ }
322
+ status(signal) {
323
+ return requestDaemon(this.profile, "status", {}, signal);
324
+ }
325
+ doctor(signal) {
326
+ return requestDaemon(this.profile, "doctor", {}, signal);
327
+ }
328
+ remove(target, signal) {
329
+ return requestDaemon(this.profile, "remove", { target }, signal);
330
+ }
331
+ exportKB(target, output, signal, onProgress, access) {
332
+ return requestDaemon(this.profile, "export", { target, output, access: serializeFilesystemAccess(access) }, signal, onProgress);
333
+ }
334
+ importKB(input, onProgress, signal, access) {
335
+ return requestDaemon(this.profile, "import", { input, access: serializeFilesystemAccess(access) }, signal, onProgress);
336
+ }
337
+ clear(signal) {
338
+ return requestDaemon(this.profile, "clear", {}, signal);
339
+ }
340
+ enableWatchers(signal) {
341
+ return requestDaemon(this.profile, "enable_watchers", {}, signal);
342
+ }
343
+ async shutdown(signal) {
344
+ const manifest = readDaemonManifest(this.profile);
345
+ try {
346
+ return await requestDaemon(this.profile, "shutdown", {}, signal, undefined, manifest);
347
+ }
348
+ catch (error) {
349
+ const current = readDaemonManifest(this.profile);
350
+ if (!manifest || !current || current.instance_id !== manifest.instance_id || !processIsAlive(manifest.pid)) {
351
+ return { accepted: true };
352
+ }
353
+ if (!current.ready) {
354
+ await waitForDaemonShutdown(this.profile, manifest.instance_id);
355
+ return { accepted: true };
356
+ }
357
+ throw error;
358
+ }
359
+ }
360
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+ import { resolveKnowledgeProfile } from "../profiles.js";
3
+ import { ensureDaemonClient, KnowledgeDaemonClient, waitForDaemonShutdown } from "./client.js";
4
+ import { readDaemonManifest } from "./runtime.js";
5
+ import { DaemonStartupCancelledError, ProfileDaemonServer } from "./server.js";
6
+ function parseArguments(argv) {
7
+ const command = argv[0] ?? "run";
8
+ if (command !== "run" && command !== "start" && command !== "status" && command !== "stop") {
9
+ throw new Error(`Unknown daemon command: ${command}`);
10
+ }
11
+ let profileName;
12
+ let expectedProfileId;
13
+ let watchersEnabled = false;
14
+ for (let index = 1; index < argv.length; index++) {
15
+ const argument = argv[index];
16
+ if (argument === "--watchers") {
17
+ watchersEnabled = true;
18
+ continue;
19
+ }
20
+ if (argument === "--profile" || argument === "--expect-profile-id") {
21
+ const value = argv[index + 1];
22
+ if (!value)
23
+ throw new Error(`Missing value for ${argument}`);
24
+ if (argument === "--profile")
25
+ profileName = value;
26
+ else
27
+ expectedProfileId = value;
28
+ index++;
29
+ continue;
30
+ }
31
+ throw new Error(`Unknown daemon option: ${argument}`);
32
+ }
33
+ return { command, profileName, expectedProfileId, watchersEnabled };
34
+ }
35
+ function printJson(value) {
36
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
37
+ }
38
+ async function runForeground(options) {
39
+ const profile = resolveKnowledgeProfile(options.profileName);
40
+ if (options.expectedProfileId && options.expectedProfileId !== profile.id) {
41
+ throw new Error(`Resolved profile identity changed before daemon startup: expected ${options.expectedProfileId}, got ${profile.id}`);
42
+ }
43
+ const server = new ProfileDaemonServer(profile, { watchersEnabled: options.watchersEnabled });
44
+ let terminationRequested = false;
45
+ const stop = () => {
46
+ terminationRequested = true;
47
+ void server.shutdown().catch((error) => {
48
+ console.error(error instanceof Error ? error.message : "Profile daemon shutdown failed");
49
+ process.exit(1);
50
+ });
51
+ };
52
+ process.once("SIGINT", stop);
53
+ process.once("SIGTERM", stop);
54
+ try {
55
+ const manifest = await server.start();
56
+ if (terminationRequested) {
57
+ await server.shutdown();
58
+ return;
59
+ }
60
+ printJson({
61
+ status: "ready",
62
+ profile: { name: profile.name, id: profile.id },
63
+ pid: manifest.pid,
64
+ watchers_enabled: manifest.watcher_enabled,
65
+ });
66
+ await server.waitUntilStopped();
67
+ }
68
+ catch (error) {
69
+ if (!(terminationRequested && error instanceof DaemonStartupCancelledError))
70
+ throw error;
71
+ await server.shutdown();
72
+ }
73
+ finally {
74
+ process.off("SIGINT", stop);
75
+ process.off("SIGTERM", stop);
76
+ }
77
+ }
78
+ async function runCommand(options) {
79
+ if (options.command === "run") {
80
+ await runForeground(options);
81
+ return;
82
+ }
83
+ const profile = resolveKnowledgeProfile(options.profileName);
84
+ if (options.command === "start") {
85
+ const client = await ensureDaemonClient(profile);
86
+ if (options.watchersEnabled)
87
+ await client.enableWatchers();
88
+ printJson(await client.ping());
89
+ return;
90
+ }
91
+ const manifest = readDaemonManifest(profile);
92
+ if (!manifest)
93
+ throw new Error(`Knowledge profile daemon is not running: ${profile.name}`);
94
+ const client = new KnowledgeDaemonClient(profile);
95
+ if (options.command === "status") {
96
+ printJson(await client.ping());
97
+ return;
98
+ }
99
+ await client.shutdown();
100
+ await waitForDaemonShutdown(profile, manifest.instance_id);
101
+ printJson({ stopped: true, instance_id: manifest.instance_id });
102
+ }
103
+ try {
104
+ await runCommand(parseArguments(process.argv.slice(2)));
105
+ }
106
+ catch (error) {
107
+ console.error(error instanceof Error ? error.message : String(error));
108
+ process.exitCode = 1;
109
+ }
@@ -0,0 +1,71 @@
1
+ export declare const DAEMON_PROTOCOL_VERSION = 1;
2
+ export declare const MAX_RPC_FRAME_BYTES: number;
3
+ export declare const MAX_RPC_CONNECTIONS = 64;
4
+ export declare const MAX_RPC_IN_FLIGHT = 32;
5
+ export declare const MAX_PROGRESS_FRAMES = 1000;
6
+ export declare const DAEMON_START_TIMEOUT_MS = 20000;
7
+ export declare const DAEMON_REQUEST_TIMEOUT_MS: number;
8
+ export declare const DAEMON_SHUTDOWN_GRACE_MS = 10000;
9
+ export declare const DAEMON_SHUTDOWN_SETTLE_MS = 2000;
10
+ export type DaemonMethod = "ping" | "shutdown" | "enable_watchers" | "plan" | "configure" | "add" | "update" | "remove" | "clear" | "import" | "export" | "search" | "symbol_search" | "list" | "status" | "doctor";
11
+ export type DaemonMethodScope = "read" | "source-read" | "write" | "admin";
12
+ export declare const DAEMON_METHOD_SCOPE: Record<DaemonMethod, DaemonMethodScope>;
13
+ export interface DaemonOwnerRecord {
14
+ protocol_version: typeof DAEMON_PROTOCOL_VERSION;
15
+ profile_id: string;
16
+ instance_id: string;
17
+ pid: number;
18
+ started_at: number;
19
+ endpoint: string;
20
+ }
21
+ export interface DaemonManifest extends DaemonOwnerRecord {
22
+ profile_name: string;
23
+ storage_dir: string;
24
+ package_version: string;
25
+ build_identity: string;
26
+ auth_token: string;
27
+ ready: boolean;
28
+ watcher_enabled: boolean;
29
+ runtime_configuration_signature: string;
30
+ last_snapshot_error?: string;
31
+ }
32
+ export interface DaemonRequestFrame {
33
+ type: "request";
34
+ version: typeof DAEMON_PROTOCOL_VERSION;
35
+ id: string;
36
+ token: string;
37
+ package_version: string;
38
+ build_identity: string;
39
+ method: DaemonMethod;
40
+ params: Record<string, unknown>;
41
+ }
42
+ export interface DaemonCancelFrame {
43
+ type: "cancel";
44
+ version: typeof DAEMON_PROTOCOL_VERSION;
45
+ id: string;
46
+ token: string;
47
+ }
48
+ export type DaemonClientFrame = DaemonRequestFrame | DaemonCancelFrame;
49
+ export interface DaemonProgressFrame {
50
+ type: "progress";
51
+ id: string;
52
+ message: string;
53
+ }
54
+ export interface DaemonResultFrame {
55
+ type: "result";
56
+ id: string;
57
+ result: unknown;
58
+ }
59
+ export interface DaemonErrorFrame {
60
+ type: "error";
61
+ id: string;
62
+ code: string;
63
+ message: string;
64
+ }
65
+ export type DaemonServerFrame = DaemonProgressFrame | DaemonResultFrame | DaemonErrorFrame;
66
+ export declare function isDaemonMethod(value: unknown): value is DaemonMethod;
67
+ export declare function parseDaemonClientFrame(value: unknown): DaemonClientFrame;
68
+ export declare function parseDaemonServerFrame(value: unknown): DaemonServerFrame;
69
+ export declare function runtimeConfigurationSignature(env?: NodeJS.ProcessEnv): string;
70
+ export declare function packageBuildIdentity(): string;
71
+ export declare function packageVersion(): string;