@gmickel/gno 2.14.0 → 2.16.0
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/README.md +1 -1
- package/assets/skill/cli-reference.md +4 -2
- package/assets/spa-production.json.gz +0 -0
- package/browser-extension/artifacts/{gno-browser-clipper-v2.14.0.zip → gno-browser-clipper-v2.16.0.zip} +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.16.0.zip.sha256 +1 -0
- package/browser-extension/dist/manifest.json +1 -1
- package/package.json +1 -1
- package/spec/cli.md +88 -45
- package/spec/db/schema.sql +45 -0
- package/spec/output-schemas/embed-receipt.schema.json +89 -0
- package/src/cli/commands/agents/commands.ts +1 -1
- package/src/cli/commands/ask.ts +1 -1
- package/src/cli/commands/context-build.ts +1 -1
- package/src/cli/commands/embed.ts +341 -20
- package/src/cli/commands/links.ts +1 -1
- package/src/cli/commands/mcp/install.ts +2 -2
- package/src/cli/commands/mcp/status.ts +1 -1
- package/src/cli/commands/mcp/uninstall.ts +1 -1
- package/src/cli/commands/query.ts +1 -1
- package/src/cli/commands/shared.ts +4 -4
- package/src/cli/commands/skill/install.ts +1 -1
- package/src/cli/commands/skill/paths-cmd.ts +1 -1
- package/src/cli/commands/skill/uninstall.ts +1 -1
- package/src/cli/commands/status.ts +75 -58
- package/src/cli/config-cache.ts +86 -0
- package/src/cli/globals.ts +64 -0
- package/src/cli/options.ts +23 -0
- package/src/cli/program.ts +44 -37
- package/src/cli/run.ts +121 -67
- package/src/cli/runtime-health.ts +132 -122
- package/src/cli/session-binding.ts +11 -2
- package/src/config/saver.ts +8 -0
- package/src/converters/adapters/browser-export/formats.ts +25 -15
- package/src/converters/adapters/email/adapter.ts +37 -53
- package/src/converters/adapters/email/html.ts +37 -20
- package/src/converters/adapters/email/mime.ts +71 -39
- package/src/converters/adapters/ical/adapter.ts +20 -12
- package/src/converters/adapters/jsonl/adapter.ts +8 -6
- package/src/converters/adapters/shared/html-text.ts +55 -37
- package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
- package/src/converters/adapters/shared/utf8-lines.ts +69 -31
- package/src/converters/adapters/transcript/adapter.ts +12 -7
- package/src/converters/adapters/xlsx/adapter.ts +10 -7
- package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
- package/src/converters/canonicalize.ts +17 -3
- package/src/converters/native/markdown.ts +24 -17
- package/src/converters/native/plaintext.ts +5 -6
- package/src/converters/registry.ts +130 -8
- package/src/core/activation-status.ts +4 -8
- package/src/core/change-diff.ts +38 -11
- package/src/core/context-compiler.ts +17 -18
- package/src/core/context-evidence.ts +116 -25
- package/src/core/context-verifier.ts +70 -31
- package/src/core/file-lock.ts +10 -2
- package/src/core/graph-analysis.ts +3 -3
- package/src/core/link-inventory-markdown.ts +2 -2
- package/src/core/links.ts +20 -87
- package/src/core/memory-fence.ts +16 -9
- package/src/core/memory-recall.ts +168 -34
- package/src/core/path-rules.ts +143 -0
- package/src/core/section-parse.ts +16 -6
- package/src/core/typed-metadata.ts +68 -0
- package/src/core/wiki-link-syntax.ts +88 -0
- package/src/embed/backlog.ts +173 -60
- package/src/embed/batch.ts +83 -12
- package/src/embed/resume-cursor.ts +103 -0
- package/src/embed/retry.ts +41 -32
- package/src/embed/variant-backlog.ts +697 -63
- package/src/embed/variant-plan.ts +41 -45
- package/src/embed/variant-retry.ts +157 -44
- package/src/index.ts +3 -3
- package/src/ingestion/budget-error-codes.ts +13 -0
- package/src/ingestion/chunker.ts +60 -49
- package/src/ingestion/compiled-context.ts +4 -5
- package/src/ingestion/convert-file.ts +1 -1
- package/src/ingestion/document-metadata.ts +16 -9
- package/src/ingestion/excluded-ranges.ts +97 -0
- package/src/ingestion/file-processor.ts +122 -37
- package/src/ingestion/frontmatter.ts +35 -7
- package/src/ingestion/graph-reconciliation.ts +187 -51
- package/src/ingestion/language.ts +66 -61
- package/src/ingestion/position.ts +5 -5
- package/src/ingestion/prepare-file.ts +50 -29
- package/src/ingestion/record-adapter-canonical.ts +37 -26
- package/src/ingestion/record-adapter.ts +46 -26
- package/src/ingestion/record-container.ts +121 -53
- package/src/ingestion/record-path.ts +5 -2
- package/src/ingestion/source-availability/darwin-io.ts +10 -7
- package/src/ingestion/source-availability/darwin-path.ts +21 -3
- package/src/ingestion/source-availability/readers.ts +51 -0
- package/src/ingestion/strip.ts +39 -105
- package/src/ingestion/sync.ts +692 -386
- package/src/ingestion/typed-metadata.ts +10 -4
- package/src/ingestion/walker.ts +485 -158
- package/src/llm/cache.ts +128 -84
- package/src/llm/http-inference.ts +112 -35
- package/src/llm/http-policy.ts +101 -0
- package/src/llm/httpEmbedding.ts +8 -1
- package/src/llm/httpGeneration.ts +5 -1
- package/src/llm/httpRerank.ts +5 -1
- package/src/llm/inference-scope.ts +15 -2
- package/src/llm/lazy-ports.ts +33 -3
- package/src/llm/lockfile.ts +34 -7
- package/src/llm/model-cleanup.ts +24 -0
- package/src/llm/native-worker/client.ts +23 -12
- package/src/llm/native-worker/dispatcher.ts +19 -9
- package/src/llm/native-worker/embedding-identity.ts +42 -16
- package/src/llm/native-worker/entry.ts +2 -1
- package/src/llm/native-worker/owner.ts +1 -0
- package/src/llm/native-worker/ports.ts +86 -23
- package/src/llm/native-worker/protocol.ts +386 -55
- package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
- package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
- package/src/llm/nodeLlamaCpp/generation.ts +194 -30
- package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
- package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
- package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
- package/src/llm/types.ts +14 -0
- package/src/mcp/context.ts +342 -23
- package/src/mcp/http-transport.ts +21 -3
- package/src/mcp/tool-profile-types.ts +62 -0
- package/src/mcp/tool-profile.ts +32 -56
- package/src/mcp/tools/context.ts +5 -1
- package/src/mcp/tools/index.ts +269 -191
- package/src/mcp/tools/links.ts +7 -5
- package/src/mcp/tools/query.ts +60 -37
- package/src/mcp/tools/vsearch.ts +25 -14
- package/src/pipeline/answer.ts +133 -40
- package/src/pipeline/claim-verification.ts +293 -189
- package/src/pipeline/claim-verifier.ts +6 -7
- package/src/pipeline/egress-lineage.ts +37 -26
- package/src/pipeline/exclude.ts +34 -11
- package/src/pipeline/expansion.ts +233 -19
- package/src/pipeline/filters.ts +169 -33
- package/src/pipeline/graph-retrieval.ts +117 -61
- package/src/pipeline/hybrid.ts +598 -329
- package/src/pipeline/hydration.ts +86 -24
- package/src/pipeline/intent.ts +15 -7
- package/src/pipeline/owner-fusion.ts +61 -19
- package/src/pipeline/query-language.ts +15 -2
- package/src/pipeline/rerank.ts +15 -22
- package/src/pipeline/search.ts +193 -72
- package/src/pipeline/snippet.ts +15 -2
- package/src/pipeline/temporal.ts +51 -10
- package/src/pipeline/vsearch.ts +250 -152
- package/src/publish/attachment-raster.ts +2 -16
- package/src/publish/encrypted-export.ts +15 -5
- package/src/serve/browse-tree.ts +50 -42
- package/src/serve/connectors.ts +2 -1
- package/src/serve/context.ts +13 -4
- package/src/serve/doc-events.ts +3 -0
- package/src/serve/public/app.tsx +49 -21
- package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
- package/src/serve/public/components/CaptureModal.tsx +14 -10
- package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
- package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
- package/src/serve/public/globals.built.css +1 -1
- package/src/serve/public/globals.css +19 -0
- package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
- package/src/serve/public/lib/metadata-filter.ts +234 -9
- package/src/serve/public/pages/Browse.tsx +61 -27
- package/src/serve/public/pages/DocView.tsx +44 -25
- package/src/serve/public/pages/GraphView.tsx +8 -3
- package/src/serve/resident-runtime.ts +199 -48
- package/src/serve/routes/api.ts +98 -67
- package/src/serve/routes/links.ts +18 -4
- package/src/serve/server.ts +1370 -1180
- package/src/serve/spa-bundle-source.ts +52 -27
- package/src/serve/status.ts +101 -52
- package/src/serve/watch-reconciliation-fallback.ts +11 -7
- package/src/serve/watch-reconciliation-shared.ts +42 -4
- package/src/serve/watch-reconciliation.ts +21 -8
- package/src/serve/watch-service-events.ts +7 -1
- package/src/serve/watch-service-hosts.ts +3 -1
- package/src/serve/watch-service.ts +46 -21
- package/src/serve/watch-snapshot-scan.ts +6 -15
- package/src/sessions/archive.ts +20 -8
- package/src/sessions/sanitize.ts +38 -18
- package/src/sessions/service.ts +180 -102
- package/src/store/migrations/036-vector-mirror-state.ts +83 -0
- package/src/store/migrations/037-performance-indexes.ts +56 -0
- package/src/store/migrations/index.ts +4 -0
- package/src/store/sqlite/adapter.ts +1217 -651
- package/src/store/sqlite/chunking-policy.ts +15 -1
- package/src/store/sqlite/eligibility.ts +110 -70
- package/src/store/sqlite/graph-neighbors.ts +71 -46
- package/src/store/sqlite/graph-reference-state.ts +27 -3
- package/src/store/sqlite/graph-similarity.ts +59 -12
- package/src/store/sqlite/metadata-predicate.ts +123 -28
- package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
- package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
- package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
- package/src/store/types.ts +32 -0
- package/src/store/vector/eligibility.ts +39 -0
- package/src/store/vector/lazy.ts +17 -0
- package/src/store/vector/partition-index.ts +49 -47
- package/src/store/vector/proof-cache.ts +103 -0
- package/src/store/vector/sqlite-vec.ts +230 -139
- package/src/store/vector/stats.ts +29 -73
- package/src/store/vector/status.ts +151 -52
- package/src/store/vector/stored-vectors.ts +131 -45
- package/src/store/vector/types.ts +10 -0
- package/src/store/vector/variant-search.ts +771 -109
- package/src/store/vector/variants.ts +785 -144
- package/browser-extension/artifacts/gno-browser-clipper-v2.14.0.zip.sha256 +0 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** Single-process ownership boundary shared by serve and daemon surfaces. */
|
|
2
2
|
|
|
3
|
-
// node:
|
|
4
|
-
import {
|
|
3
|
+
// node:fs watch: Bun has no recursive/directory watcher API with explicit close().
|
|
4
|
+
import { type FSWatcher, watch as fsWatch } from "node:fs";
|
|
5
|
+
// node:path basename/dirname/join/resolve have no Bun path utility equivalents.
|
|
6
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
5
7
|
|
|
6
8
|
import type { Config } from "../config/types";
|
|
7
9
|
import type { WriteLockHandle } from "../core/file-lock";
|
|
@@ -12,6 +14,7 @@ import type { HttpMcpTransportStatus } from "../mcp/http-transport";
|
|
|
12
14
|
import type { SessionAutomationRunResult } from "../sessions/types";
|
|
13
15
|
import type { DocumentEventBus } from "./doc-events";
|
|
14
16
|
import type { EmbedResult, EmbedScheduler } from "./embed-scheduler";
|
|
17
|
+
import type { FindingsPassResult, FindingsScheduler } from "./findings-pass";
|
|
15
18
|
import type { ContextHolder } from "./routes/api";
|
|
16
19
|
import type { ResidentStatus } from "./status-model";
|
|
17
20
|
import type {
|
|
@@ -36,11 +39,6 @@ import { SavedCapsuleReverificationScheduler } from "../core/capsule-reverificat
|
|
|
36
39
|
import { collectionEgressPolicyEpoch } from "../core/collection-egress-policy-service";
|
|
37
40
|
import { authorizeCurrentEgress } from "../core/egress-authorization";
|
|
38
41
|
import { acquireWriteLock } from "../core/file-lock";
|
|
39
|
-
import {
|
|
40
|
-
deleteFindingsRunState,
|
|
41
|
-
findingsRunStatePath,
|
|
42
|
-
resolveFindingsSchedule,
|
|
43
|
-
} from "../core/findings-run-state";
|
|
44
42
|
import { JobManager } from "../core/job-manager";
|
|
45
43
|
import { recordContentMutation } from "../core/mutation-generations";
|
|
46
44
|
import {
|
|
@@ -73,7 +71,6 @@ import {
|
|
|
73
71
|
type ServerContext,
|
|
74
72
|
} from "./context";
|
|
75
73
|
import { createEmbedScheduler, embedSchedulerIssues } from "./embed-scheduler";
|
|
76
|
-
import { FindingsScheduler, type FindingsPassResult } from "./findings-pass";
|
|
77
74
|
import { AdmissionController, ReaderGate } from "./resident-admission";
|
|
78
75
|
import { ResidentBackgroundWork } from "./resident-background-work";
|
|
79
76
|
import { disposeResidentResources } from "./resident-shutdown";
|
|
@@ -88,8 +85,10 @@ import {
|
|
|
88
85
|
import { CollectionWatchService as DefaultCollectionWatchService } from "./watch-service";
|
|
89
86
|
|
|
90
87
|
const OWNER_LOCK_TIMEOUT_MS = 0;
|
|
91
|
-
/**
|
|
92
|
-
const
|
|
88
|
+
/** Safety fallback interval if directory fs.watch fails on the config parent. */
|
|
89
|
+
const CONFIG_REFRESH_FALLBACK_INTERVAL_MS = 60_000;
|
|
90
|
+
/** Coalesce bursty editor/atomic-rename events from the config directory watcher. */
|
|
91
|
+
const CONFIG_WATCH_DEBOUNCE_MS = 50;
|
|
93
92
|
|
|
94
93
|
export type ResidentMode = "serve" | "daemon";
|
|
95
94
|
|
|
@@ -251,9 +250,23 @@ export async function startResidentRuntime(
|
|
|
251
250
|
if (!initialized)
|
|
252
251
|
return { success: false, error: "GNO not initialized. Run: gno init" };
|
|
253
252
|
|
|
253
|
+
const paths = (deps.getConfigPaths ?? getConfigPaths)();
|
|
254
|
+
const actualConfigPath = resolve(options.configPath ?? paths.configFile);
|
|
255
|
+
const readConfigStampAt = async (
|
|
256
|
+
filePath: string
|
|
257
|
+
): Promise<string | undefined> => {
|
|
258
|
+
try {
|
|
259
|
+
const stat = await Bun.file(filePath).stat();
|
|
260
|
+
return `${stat.ino}:${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}`;
|
|
261
|
+
} catch {
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const startupStampBefore = await readConfigStampAt(actualConfigPath);
|
|
254
266
|
const configResult = await (deps.loadConfig ?? loadConfig)(
|
|
255
267
|
options.configPath
|
|
256
268
|
);
|
|
269
|
+
const startupStampAfter = await readConfigStampAt(actualConfigPath);
|
|
257
270
|
if (!configResult.ok)
|
|
258
271
|
return { success: false, error: configResult.error.message };
|
|
259
272
|
for (const warning of formatConfigWarnings(configResult.warnings))
|
|
@@ -267,10 +280,11 @@ export async function startResidentRuntime(
|
|
|
267
280
|
}
|
|
268
281
|
|
|
269
282
|
const mode: ResidentMode = options.mode ?? "serve";
|
|
270
|
-
const
|
|
271
|
-
mode === "daemon"
|
|
272
|
-
|
|
273
|
-
|
|
283
|
+
const findingsRunStateMod =
|
|
284
|
+
mode === "daemon" ? await import("../core/findings-run-state") : null;
|
|
285
|
+
const findingsResolution = findingsRunStateMod
|
|
286
|
+
? findingsRunStateMod.resolveFindingsSchedule(initialConfig)
|
|
287
|
+
: ({ ok: true, enabled: false } as const);
|
|
274
288
|
if (!findingsResolution.ok) {
|
|
275
289
|
return { success: false, error: findingsResolution.error };
|
|
276
290
|
}
|
|
@@ -290,8 +304,6 @@ export async function startResidentRuntime(
|
|
|
290
304
|
}
|
|
291
305
|
|
|
292
306
|
const store = deps.storeFactory?.() ?? new SqliteAdapter();
|
|
293
|
-
const paths = (deps.getConfigPaths ?? getConfigPaths)();
|
|
294
|
-
const actualConfigPath = resolve(options.configPath ?? paths.configFile);
|
|
295
307
|
store.setConfigPath(actualConfigPath);
|
|
296
308
|
const openResult = await store.open(
|
|
297
309
|
dbPath,
|
|
@@ -438,26 +450,30 @@ export async function startResidentRuntime(
|
|
|
438
450
|
const backgroundWork = new ResidentBackgroundWork(
|
|
439
451
|
() => !disposed && admission.accepting
|
|
440
452
|
);
|
|
441
|
-
const findingsStatePath = findingsRunStatePath(dbPath);
|
|
442
453
|
let findingsScheduler: FindingsScheduler | null = null;
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
454
|
+
if (findingsRunStateMod) {
|
|
455
|
+
const findingsStatePath = findingsRunStateMod.findingsRunStatePath(dbPath);
|
|
456
|
+
if (findingsResolution.enabled) {
|
|
457
|
+
const { FindingsScheduler: FindingsSchedulerCtor } =
|
|
458
|
+
await import("./findings-pass");
|
|
459
|
+
findingsScheduler = new FindingsSchedulerCtor({
|
|
460
|
+
deps: {
|
|
461
|
+
store,
|
|
462
|
+
getConfig: () => ctxHolder.config,
|
|
463
|
+
schedule: findingsResolution.schedule,
|
|
464
|
+
dbPath,
|
|
465
|
+
indexName: canonicalizeIndexName(options.index ?? DEFAULT_INDEX_NAME),
|
|
466
|
+
statePath: findingsStatePath,
|
|
467
|
+
},
|
|
468
|
+
startBackgroundWork: (operation) => backgroundWork.start(operation),
|
|
469
|
+
onResult: options.onFindingsResult,
|
|
470
|
+
});
|
|
471
|
+
await findingsScheduler.start();
|
|
472
|
+
} else {
|
|
473
|
+
// Findings are off: a state file from an earlier configuration would
|
|
474
|
+
// otherwise keep reporting a schedule that no longer exists.
|
|
475
|
+
await findingsRunStateMod.deleteFindingsRunState(findingsStatePath);
|
|
476
|
+
}
|
|
461
477
|
}
|
|
462
478
|
// Session automation drains only in daemon mode on an archive config;
|
|
463
479
|
// `serve` never runs admitted hook work or schedules.
|
|
@@ -514,24 +530,74 @@ export async function startResidentRuntime(
|
|
|
514
530
|
// while the file's identity, size and times match the last good load. Any
|
|
515
531
|
// write, rename, chmod or delete changes the stamp, so a broken file is
|
|
516
532
|
// still reported, never served stale.
|
|
517
|
-
|
|
518
|
-
|
|
533
|
+
const configStamp = (): Promise<string | undefined> =>
|
|
534
|
+
readConfigStampAt(instance.configPath);
|
|
535
|
+
// Seed the stamp only when the file was verified unchanged across the
|
|
536
|
+
// initial config read (and default loader was used). If the file changed
|
|
537
|
+
// mid-load or between load and watcher install, leave undefined or reconcile
|
|
538
|
+
// once after installing the watcher so replacements are never masked.
|
|
539
|
+
let loadedConfigStamp: string | undefined =
|
|
540
|
+
!deps.loadConfig &&
|
|
541
|
+
startupStampBefore !== undefined &&
|
|
542
|
+
startupStampBefore === startupStampAfter
|
|
543
|
+
? startupStampAfter
|
|
544
|
+
: undefined;
|
|
545
|
+
// Another client may index a collection the served config omits after this
|
|
546
|
+
// runtime started; requests fail instead of reading it. Memoize clean checks
|
|
547
|
+
// by (PRAGMA data_version, total_changes, configRef) on committed reads only.
|
|
548
|
+
let cachedCleanStaleCheck: {
|
|
549
|
+
dataVersion: number;
|
|
550
|
+
totalChanges: number;
|
|
551
|
+
configRef: Config;
|
|
552
|
+
} | null = null;
|
|
553
|
+
const readDbVersionTuple = (): {
|
|
554
|
+
dataVersion: number;
|
|
555
|
+
totalChanges: number;
|
|
556
|
+
} | null => {
|
|
519
557
|
try {
|
|
520
|
-
|
|
521
|
-
|
|
558
|
+
if (typeof Reflect.get(store, "getRawDb") !== "function") {
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
const db = store.getRawDb();
|
|
562
|
+
if (db.inTransaction) {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
const row = db
|
|
566
|
+
.query<{ dv: number; tc: number }, []>(
|
|
567
|
+
"SELECT (SELECT * FROM pragma_data_version) AS dv, total_changes() AS tc"
|
|
568
|
+
)
|
|
569
|
+
.get();
|
|
570
|
+
return row ? { dataVersion: row.dv, totalChanges: row.tc } : null;
|
|
522
571
|
} catch {
|
|
523
|
-
return
|
|
572
|
+
return null;
|
|
524
573
|
}
|
|
525
574
|
};
|
|
526
|
-
// Another client may index a collection the served config omits after this
|
|
527
|
-
// runtime started; requests fail instead of reading it.
|
|
528
575
|
const assertServedCollections = (): void => {
|
|
576
|
+
const configRef = ctxHolder.config;
|
|
577
|
+
const dbVersion = readDbVersionTuple();
|
|
578
|
+
if (
|
|
579
|
+
dbVersion &&
|
|
580
|
+
cachedCleanStaleCheck &&
|
|
581
|
+
cachedCleanStaleCheck.configRef === configRef &&
|
|
582
|
+
cachedCleanStaleCheck.dataVersion === dbVersion.dataVersion &&
|
|
583
|
+
cachedCleanStaleCheck.totalChanges === dbVersion.totalChanges
|
|
584
|
+
) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
529
587
|
const stale = store.staleIndexedCollections(
|
|
530
|
-
|
|
588
|
+
configRef.collections.map(({ name }) => name)
|
|
531
589
|
);
|
|
532
590
|
if (stale.length > 0) {
|
|
591
|
+
cachedCleanStaleCheck = null;
|
|
533
592
|
throw new StaleCollectionsError(staleCollectionsMessage(stale));
|
|
534
593
|
}
|
|
594
|
+
if (dbVersion) {
|
|
595
|
+
cachedCleanStaleCheck = {
|
|
596
|
+
dataVersion: dbVersion.dataVersion,
|
|
597
|
+
totalChanges: dbVersion.totalChanges,
|
|
598
|
+
configRef,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
535
601
|
};
|
|
536
602
|
const refreshConfig = (): Promise<void> => {
|
|
537
603
|
configRefresh ??= (async () => {
|
|
@@ -772,7 +838,7 @@ export async function startResidentRuntime(
|
|
|
772
838
|
dispose(closeSurface) {
|
|
773
839
|
if (disposal) return disposal;
|
|
774
840
|
disposed = true;
|
|
775
|
-
|
|
841
|
+
stopConfigMonitoring();
|
|
776
842
|
admission.stop();
|
|
777
843
|
jobManager.stop();
|
|
778
844
|
// A file mid-preparation fails now instead of holding shutdown.
|
|
@@ -826,9 +892,17 @@ export async function startResidentRuntime(
|
|
|
826
892
|
};
|
|
827
893
|
};
|
|
828
894
|
mcpContext.getResidentStatus = () => runtime.getStatus();
|
|
829
|
-
// Without requests (a headless daemon) the watcher still follows
|
|
895
|
+
// Without requests (a headless daemon) the watcher still follows config edits
|
|
896
|
+
// via fs.watch on the config parent directory (handling both in-place edits
|
|
897
|
+
// and atomic temp-file renames), falling back to a 60s timer only if fs.watch
|
|
898
|
+
// is unavailable or errors.
|
|
830
899
|
let lastRefreshError: string | undefined;
|
|
831
|
-
|
|
900
|
+
let configWatcher: FSWatcher | null = null;
|
|
901
|
+
let configWatchDebounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
902
|
+
let configRefreshFallbackTimer: ReturnType<typeof setInterval> | null = null;
|
|
903
|
+
|
|
904
|
+
const triggerBackgroundConfigRefresh = (): void => {
|
|
905
|
+
if (disposed) return;
|
|
832
906
|
backgroundWork.start(async () => {
|
|
833
907
|
try {
|
|
834
908
|
await refreshConfig();
|
|
@@ -844,7 +918,84 @@ export async function startResidentRuntime(
|
|
|
844
918
|
lastRefreshError = message;
|
|
845
919
|
}
|
|
846
920
|
});
|
|
847
|
-
}
|
|
848
|
-
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
const ensureFallbackRefreshTimer = (): void => {
|
|
924
|
+
if (disposed || configRefreshFallbackTimer) return;
|
|
925
|
+
configRefreshFallbackTimer = setInterval(
|
|
926
|
+
triggerBackgroundConfigRefresh,
|
|
927
|
+
CONFIG_REFRESH_FALLBACK_INTERVAL_MS
|
|
928
|
+
);
|
|
929
|
+
configRefreshFallbackTimer.unref?.();
|
|
930
|
+
};
|
|
931
|
+
|
|
932
|
+
const stopConfigMonitoring = (): void => {
|
|
933
|
+
if (configWatchDebounceTimer) {
|
|
934
|
+
clearTimeout(configWatchDebounceTimer);
|
|
935
|
+
configWatchDebounceTimer = null;
|
|
936
|
+
}
|
|
937
|
+
if (configRefreshFallbackTimer) {
|
|
938
|
+
clearInterval(configRefreshFallbackTimer);
|
|
939
|
+
configRefreshFallbackTimer = null;
|
|
940
|
+
}
|
|
941
|
+
if (configWatcher) {
|
|
942
|
+
try {
|
|
943
|
+
configWatcher.close();
|
|
944
|
+
} catch {
|
|
945
|
+
// Ignore watcher close errors during shutdown
|
|
946
|
+
}
|
|
947
|
+
configWatcher = null;
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
const configDir = dirname(actualConfigPath);
|
|
952
|
+
const configFileName = basename(actualConfigPath);
|
|
953
|
+
try {
|
|
954
|
+
configWatcher = fsWatch(
|
|
955
|
+
configDir,
|
|
956
|
+
{ persistent: false },
|
|
957
|
+
(_eventType, filename) => {
|
|
958
|
+
if (disposed) return;
|
|
959
|
+
const changedName =
|
|
960
|
+
typeof filename === "string"
|
|
961
|
+
? basename(filename)
|
|
962
|
+
: filename
|
|
963
|
+
? basename(String(filename))
|
|
964
|
+
: null;
|
|
965
|
+
if (changedName !== null && changedName !== configFileName) {
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
if (configWatchDebounceTimer) {
|
|
969
|
+
clearTimeout(configWatchDebounceTimer);
|
|
970
|
+
}
|
|
971
|
+
configWatchDebounceTimer = setTimeout(() => {
|
|
972
|
+
configWatchDebounceTimer = null;
|
|
973
|
+
triggerBackgroundConfigRefresh();
|
|
974
|
+
}, CONFIG_WATCH_DEBOUNCE_MS);
|
|
975
|
+
configWatchDebounceTimer.unref?.();
|
|
976
|
+
}
|
|
977
|
+
);
|
|
978
|
+
configWatcher.on("error", () => {
|
|
979
|
+
if (configWatcher) {
|
|
980
|
+
try {
|
|
981
|
+
configWatcher.close();
|
|
982
|
+
} catch {
|
|
983
|
+
// Ignore close errors after watcher failure
|
|
984
|
+
}
|
|
985
|
+
configWatcher = null;
|
|
986
|
+
}
|
|
987
|
+
ensureFallbackRefreshTimer();
|
|
988
|
+
});
|
|
989
|
+
} catch {
|
|
990
|
+
ensureFallbackRefreshTimer();
|
|
991
|
+
}
|
|
992
|
+
// Reconcile once after installing the watcher in case the config file was
|
|
993
|
+
// replaced between startup load and watcher registration.
|
|
994
|
+
if (
|
|
995
|
+
loadedConfigStamp === undefined ||
|
|
996
|
+
(await configStamp()) !== loadedConfigStamp
|
|
997
|
+
) {
|
|
998
|
+
triggerBackgroundConfigRefresh();
|
|
999
|
+
}
|
|
849
1000
|
return { success: true, runtime };
|
|
850
1001
|
}
|
package/src/serve/routes/api.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { readdir, realpath } from "node:fs/promises";
|
|
9
9
|
// node:path has no Bun equivalent
|
|
10
|
+
import * as nodePath from "node:path";
|
|
10
11
|
import { posix as pathPosix } from "node:path";
|
|
11
12
|
|
|
12
13
|
import type {
|
|
@@ -60,7 +61,7 @@ import { resolveCollectionScope } from "../../core/collection-scope";
|
|
|
60
61
|
import {
|
|
61
62
|
type ConnectorVerificationCode,
|
|
62
63
|
getConnectorVerificationRemediation,
|
|
63
|
-
} from "../../core/connector-
|
|
64
|
+
} from "../../core/connector-policy";
|
|
64
65
|
import {
|
|
65
66
|
buildEditableCopyContent,
|
|
66
67
|
deriveEditableCopyRelPath,
|
|
@@ -821,7 +822,6 @@ async function resolveAbsoluteDocPath(
|
|
|
821
822
|
return null;
|
|
822
823
|
}
|
|
823
824
|
|
|
824
|
-
const nodePath = await import("node:path"); // no bun equivalent
|
|
825
825
|
let safeRelPath: string;
|
|
826
826
|
try {
|
|
827
827
|
safeRelPath = validateRelPath(doc.recordSourcePath ?? doc.relPath);
|
|
@@ -853,7 +853,6 @@ export async function isPathWithinRoot(
|
|
|
853
853
|
candidate: string,
|
|
854
854
|
realpathFn: RealpathFn = realpath
|
|
855
855
|
): Promise<boolean> {
|
|
856
|
-
const nodePath = await import("node:path"); // no bun equivalent
|
|
857
856
|
const relative = nodePath.relative(root, candidate);
|
|
858
857
|
const lexicallyWithin =
|
|
859
858
|
relative === "" ||
|
|
@@ -906,48 +905,81 @@ async function listCollectionRelPaths(
|
|
|
906
905
|
}
|
|
907
906
|
|
|
908
907
|
const BROWSE_HIDDEN_DIRS = new Set([".git", ".obsidian", "node_modules"]);
|
|
908
|
+
const BROWSE_FOLDER_SCAN_CONCURRENCY = 16;
|
|
909
909
|
|
|
910
910
|
async function listCollectionFolders(
|
|
911
911
|
collections: Array<{ name: string; path: string }>
|
|
912
912
|
): Promise<Array<{ collection: string; path: string }>> {
|
|
913
913
|
const folders: Array<{ collection: string; path: string }> = [];
|
|
914
|
+
const queue: Array<{
|
|
915
|
+
collection: string;
|
|
916
|
+
rootPath: string;
|
|
917
|
+
relativePath: string;
|
|
918
|
+
}> = collections.map((collection) => ({
|
|
919
|
+
collection: collection.name,
|
|
920
|
+
rootPath: collection.path,
|
|
921
|
+
relativePath: "",
|
|
922
|
+
}));
|
|
914
923
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
924
|
+
if (queue.length === 0) {
|
|
925
|
+
return folders;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
let cursor = 0;
|
|
929
|
+
let active = 0;
|
|
930
|
+
|
|
931
|
+
await new Promise<void>((resolve) => {
|
|
932
|
+
const drain = (): void => {
|
|
933
|
+
while (active < BROWSE_FOLDER_SCAN_CONCURRENCY && cursor < queue.length) {
|
|
934
|
+
const task = queue[cursor++]!;
|
|
935
|
+
active += 1;
|
|
936
|
+
const currentPath = task.relativePath
|
|
937
|
+
? `${task.rootPath}/${task.relativePath}`
|
|
938
|
+
: task.rootPath;
|
|
939
|
+
readdir(currentPath, { withFileTypes: true })
|
|
940
|
+
.then((entries) => {
|
|
941
|
+
for (const entry of entries) {
|
|
942
|
+
if (!entry.isDirectory()) {
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
if (
|
|
946
|
+
entry.name.startsWith(".") ||
|
|
947
|
+
BROWSE_HIDDEN_DIRS.has(entry.name)
|
|
948
|
+
) {
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
const nextRelativePath = task.relativePath
|
|
952
|
+
? `${task.relativePath}/${entry.name}`
|
|
953
|
+
: entry.name;
|
|
954
|
+
folders.push({
|
|
955
|
+
collection: task.collection,
|
|
956
|
+
path: normalizeBrowsePath(nextRelativePath),
|
|
957
|
+
});
|
|
958
|
+
queue.push({
|
|
959
|
+
collection: task.collection,
|
|
960
|
+
rootPath: task.rootPath,
|
|
961
|
+
relativePath: nextRelativePath,
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
})
|
|
965
|
+
.catch(() => {
|
|
966
|
+
// Unreadable directories are ignored, matching previous behavior.
|
|
967
|
+
})
|
|
968
|
+
.finally(() => {
|
|
969
|
+
active -= 1;
|
|
970
|
+
if (cursor < queue.length) {
|
|
971
|
+
drain();
|
|
972
|
+
} else if (active === 0) {
|
|
973
|
+
resolve();
|
|
974
|
+
}
|
|
975
|
+
});
|
|
933
976
|
}
|
|
934
|
-
if (
|
|
935
|
-
|
|
977
|
+
if (active === 0 && cursor >= queue.length) {
|
|
978
|
+
resolve();
|
|
936
979
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
folders.push({
|
|
941
|
-
collection,
|
|
942
|
-
path: normalizeBrowsePath(nextRelativePath),
|
|
943
|
-
});
|
|
944
|
-
await walk(collection, rootPath, nextRelativePath);
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
for (const collection of collections) {
|
|
949
|
-
await walk(collection.name, collection.path);
|
|
950
|
-
}
|
|
980
|
+
};
|
|
981
|
+
drain();
|
|
982
|
+
});
|
|
951
983
|
|
|
952
984
|
return folders;
|
|
953
985
|
}
|
|
@@ -1489,8 +1521,7 @@ export async function handleCreateCollection(
|
|
|
1489
1521
|
}
|
|
1490
1522
|
|
|
1491
1523
|
// Derive name from path if not provided
|
|
1492
|
-
const
|
|
1493
|
-
const name = body.name || path.basename(body.path);
|
|
1524
|
+
const name = body.name || nodePath.basename(body.path);
|
|
1494
1525
|
|
|
1495
1526
|
// Persist config and sync to DB (mutation happens inside with fresh config)
|
|
1496
1527
|
const syncResult = await applyConfigChangeTyped<Collection>(
|
|
@@ -2109,19 +2140,19 @@ export async function handleDocs(
|
|
|
2109
2140
|
export async function handleBrowseTree(
|
|
2110
2141
|
store: SqliteAdapter
|
|
2111
2142
|
): Promise<Response> {
|
|
2112
|
-
const
|
|
2113
|
-
store.getCollections(),
|
|
2114
|
-
store.listActiveDocumentsForBrowse(),
|
|
2115
|
-
]);
|
|
2116
|
-
|
|
2143
|
+
const collectionsResult = await store.getCollections();
|
|
2117
2144
|
if (!collectionsResult.ok) {
|
|
2118
2145
|
return errorResponse("RUNTIME", collectionsResult.error.message, 500);
|
|
2119
2146
|
}
|
|
2147
|
+
|
|
2148
|
+
const [documentsResult, folders] = await Promise.all([
|
|
2149
|
+
store.listActiveDocumentsForBrowse(),
|
|
2150
|
+
listCollectionFolders(collectionsResult.value),
|
|
2151
|
+
]);
|
|
2120
2152
|
if (!documentsResult.ok) {
|
|
2121
2153
|
return errorResponse("RUNTIME", documentsResult.error.message, 500);
|
|
2122
2154
|
}
|
|
2123
2155
|
|
|
2124
|
-
const folders = await listCollectionFolders(collectionsResult.value);
|
|
2125
2156
|
const collections = buildBrowseTree(
|
|
2126
2157
|
collectionsResult.value,
|
|
2127
2158
|
documentsResult.value,
|
|
@@ -2195,6 +2226,18 @@ export async function handleDocsAutocomplete(
|
|
|
2195
2226
|
const collection = url.searchParams.get("collection") || undefined;
|
|
2196
2227
|
const limit = Math.min(Number(url.searchParams.get("limit") ?? "8") || 8, 20);
|
|
2197
2228
|
|
|
2229
|
+
if (typeof store.searchDocumentsForAutocomplete === "function") {
|
|
2230
|
+
const result = await store.searchDocumentsForAutocomplete({
|
|
2231
|
+
query,
|
|
2232
|
+
collection,
|
|
2233
|
+
limit,
|
|
2234
|
+
});
|
|
2235
|
+
if (!result.ok) {
|
|
2236
|
+
return errorResponse("RUNTIME", result.error.message, 500);
|
|
2237
|
+
}
|
|
2238
|
+
return jsonResponse({ docs: result.value });
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2198
2241
|
const result = await store.listDocuments(collection);
|
|
2199
2242
|
if (!result.ok) {
|
|
2200
2243
|
return errorResponse("RUNTIME", result.error.message, 500);
|
|
@@ -2250,29 +2293,23 @@ export async function handleDoc(
|
|
|
2250
2293
|
}
|
|
2251
2294
|
|
|
2252
2295
|
const doc = docResult.value;
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2296
|
+
const [contentResult, tagsResult, source, successor] = await Promise.all([
|
|
2297
|
+
doc.mirrorHash ? store.getContent(doc.mirrorHash) : Promise.resolve(null),
|
|
2298
|
+
store.getTagsForDoc(doc.id),
|
|
2299
|
+
buildSourceMeta(config.collections, doc),
|
|
2300
|
+
supersedingUri(store, doc.uri),
|
|
2301
|
+
]);
|
|
2261
2302
|
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
if (tagsResult.ok) {
|
|
2266
|
-
tags = tagsResult.value.map((t) => t.tag);
|
|
2303
|
+
let content: string | null = null;
|
|
2304
|
+
if (contentResult && contentResult.ok && contentResult.value) {
|
|
2305
|
+
content = contentResult.value;
|
|
2267
2306
|
}
|
|
2268
2307
|
|
|
2308
|
+
const tags = tagsResult.ok ? tagsResult.value.map((t) => t.tag) : [];
|
|
2269
2309
|
const contentAvailable = content !== null;
|
|
2270
2310
|
const capabilities = capabilitiesForDocument(doc, contentAvailable);
|
|
2271
|
-
const source = await buildSourceMeta(config.collections, doc);
|
|
2272
2311
|
const record = projectRecordEvidenceMetadata(doc);
|
|
2273
2312
|
const relPath = doc.recordSourcePath ?? doc.relPath;
|
|
2274
|
-
|
|
2275
|
-
const successor = await supersedingUri(store, doc.uri);
|
|
2276
2313
|
const responseData = {
|
|
2277
2314
|
...(successor ? { supersededBy: successor } : {}),
|
|
2278
2315
|
docid: doc.docid,
|
|
@@ -2509,7 +2546,6 @@ export async function handleDocAsset(
|
|
|
2509
2546
|
);
|
|
2510
2547
|
}
|
|
2511
2548
|
|
|
2512
|
-
const nodePath = await import("node:path"); // no bun equivalent
|
|
2513
2549
|
const candidate = nodePath.resolve(
|
|
2514
2550
|
nodePath.dirname(resolvedDoc.fullPath),
|
|
2515
2551
|
assetPath
|
|
@@ -2789,7 +2825,6 @@ export async function handleRenameDoc(
|
|
|
2789
2825
|
return errorResponse("VALIDATION", "New name matches current file");
|
|
2790
2826
|
}
|
|
2791
2827
|
|
|
2792
|
-
const nodePath = await import("node:path"); // no bun equivalent
|
|
2793
2828
|
const nextFullPath = nodePath.join(collection.path, target.nextRelPath);
|
|
2794
2829
|
|
|
2795
2830
|
try {
|
|
@@ -3171,7 +3206,6 @@ export async function handleMoveDoc(
|
|
|
3171
3206
|
);
|
|
3172
3207
|
}
|
|
3173
3208
|
|
|
3174
|
-
const nodePath = await import("node:path"); // no bun equivalent
|
|
3175
3209
|
const nextFullPath = nodePath.join(collection.path, target.nextRelPath);
|
|
3176
3210
|
|
|
3177
3211
|
try {
|
|
@@ -3311,7 +3345,6 @@ export async function handleDuplicateDoc(
|
|
|
3311
3345
|
);
|
|
3312
3346
|
}
|
|
3313
3347
|
|
|
3314
|
-
const nodePath = await import("node:path"); // no bun equivalent
|
|
3315
3348
|
const nextFullPath = nodePath.join(collection.path, plan.nextRelPath);
|
|
3316
3349
|
|
|
3317
3350
|
try {
|
|
@@ -3395,7 +3428,6 @@ export async function handleCreateFolder(
|
|
|
3395
3428
|
parentPath: body.parentPath,
|
|
3396
3429
|
name: body.name,
|
|
3397
3430
|
});
|
|
3398
|
-
const nodePath = await import("node:path"); // no bun equivalent
|
|
3399
3431
|
const fullPath = nodePath.join(collection.path, folderPath);
|
|
3400
3432
|
await createFolderPath(fullPath);
|
|
3401
3433
|
return jsonResponse({
|
|
@@ -4463,7 +4495,6 @@ export async function handleCreateDoc(
|
|
|
4463
4495
|
|
|
4464
4496
|
const normalizedRelPath = createPlan.relPath;
|
|
4465
4497
|
|
|
4466
|
-
const nodePath = await import("node:path"); // no bun equivalent
|
|
4467
4498
|
const fullPath = nodePath.join(collection.path, normalizedRelPath);
|
|
4468
4499
|
|
|
4469
4500
|
if (createPlan.openedExisting) {
|
|
@@ -419,10 +419,24 @@ export async function handleDocSimilar(
|
|
|
419
419
|
return errorResponse("RUNTIME", searchResult.error.message, 500);
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
//
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
422
|
+
// Hydrate only the documents owning returned hits (targeted json_each SQL)
|
|
423
|
+
// rather than loading the entire documents table.
|
|
424
|
+
const hitDocumentIds = [
|
|
425
|
+
...new Set(searchResult.value.flatMap((r) => r.documentIds ?? [])),
|
|
426
|
+
];
|
|
427
|
+
const hitMirrorHashes = [
|
|
428
|
+
...new Set(
|
|
429
|
+
searchResult.value.filter((r) => !r.documentIds).map((r) => r.mirrorHash)
|
|
430
|
+
),
|
|
431
|
+
];
|
|
432
|
+
const docsResult =
|
|
433
|
+
typeof store.listDocumentsForSimilarity === "function"
|
|
434
|
+
? await store.listDocumentsForSimilarity({
|
|
435
|
+
documentIds: hitDocumentIds,
|
|
436
|
+
mirrorHashes: hitMirrorHashes,
|
|
437
|
+
collection: crossCollection ? undefined : doc.collection,
|
|
438
|
+
})
|
|
439
|
+
: await store.listDocuments(crossCollection ? undefined : doc.collection);
|
|
426
440
|
if (!docsResult.ok) {
|
|
427
441
|
return errorResponse("RUNTIME", docsResult.error.message, 500);
|
|
428
442
|
}
|