@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.
Files changed (205) hide show
  1. package/README.md +1 -1
  2. package/assets/skill/cli-reference.md +4 -2
  3. package/assets/spa-production.json.gz +0 -0
  4. package/browser-extension/artifacts/{gno-browser-clipper-v2.14.0.zip → gno-browser-clipper-v2.16.0.zip} +0 -0
  5. package/browser-extension/artifacts/gno-browser-clipper-v2.16.0.zip.sha256 +1 -0
  6. package/browser-extension/dist/manifest.json +1 -1
  7. package/package.json +1 -1
  8. package/spec/cli.md +88 -45
  9. package/spec/db/schema.sql +45 -0
  10. package/spec/output-schemas/embed-receipt.schema.json +89 -0
  11. package/src/cli/commands/agents/commands.ts +1 -1
  12. package/src/cli/commands/ask.ts +1 -1
  13. package/src/cli/commands/context-build.ts +1 -1
  14. package/src/cli/commands/embed.ts +341 -20
  15. package/src/cli/commands/links.ts +1 -1
  16. package/src/cli/commands/mcp/install.ts +2 -2
  17. package/src/cli/commands/mcp/status.ts +1 -1
  18. package/src/cli/commands/mcp/uninstall.ts +1 -1
  19. package/src/cli/commands/query.ts +1 -1
  20. package/src/cli/commands/shared.ts +4 -4
  21. package/src/cli/commands/skill/install.ts +1 -1
  22. package/src/cli/commands/skill/paths-cmd.ts +1 -1
  23. package/src/cli/commands/skill/uninstall.ts +1 -1
  24. package/src/cli/commands/status.ts +75 -58
  25. package/src/cli/config-cache.ts +86 -0
  26. package/src/cli/globals.ts +64 -0
  27. package/src/cli/options.ts +23 -0
  28. package/src/cli/program.ts +44 -37
  29. package/src/cli/run.ts +121 -67
  30. package/src/cli/runtime-health.ts +132 -122
  31. package/src/cli/session-binding.ts +11 -2
  32. package/src/config/saver.ts +8 -0
  33. package/src/converters/adapters/browser-export/formats.ts +25 -15
  34. package/src/converters/adapters/email/adapter.ts +37 -53
  35. package/src/converters/adapters/email/html.ts +37 -20
  36. package/src/converters/adapters/email/mime.ts +71 -39
  37. package/src/converters/adapters/ical/adapter.ts +20 -12
  38. package/src/converters/adapters/jsonl/adapter.ts +8 -6
  39. package/src/converters/adapters/shared/html-text.ts +55 -37
  40. package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
  41. package/src/converters/adapters/shared/utf8-lines.ts +69 -31
  42. package/src/converters/adapters/transcript/adapter.ts +12 -7
  43. package/src/converters/adapters/xlsx/adapter.ts +10 -7
  44. package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
  45. package/src/converters/canonicalize.ts +17 -3
  46. package/src/converters/native/markdown.ts +24 -17
  47. package/src/converters/native/plaintext.ts +5 -6
  48. package/src/converters/registry.ts +130 -8
  49. package/src/core/activation-status.ts +4 -8
  50. package/src/core/change-diff.ts +38 -11
  51. package/src/core/context-compiler.ts +17 -18
  52. package/src/core/context-evidence.ts +116 -25
  53. package/src/core/context-verifier.ts +70 -31
  54. package/src/core/file-lock.ts +10 -2
  55. package/src/core/graph-analysis.ts +3 -3
  56. package/src/core/link-inventory-markdown.ts +2 -2
  57. package/src/core/links.ts +20 -87
  58. package/src/core/memory-fence.ts +16 -9
  59. package/src/core/memory-recall.ts +168 -34
  60. package/src/core/path-rules.ts +143 -0
  61. package/src/core/section-parse.ts +16 -6
  62. package/src/core/typed-metadata.ts +68 -0
  63. package/src/core/wiki-link-syntax.ts +88 -0
  64. package/src/embed/backlog.ts +173 -60
  65. package/src/embed/batch.ts +83 -12
  66. package/src/embed/resume-cursor.ts +103 -0
  67. package/src/embed/retry.ts +41 -32
  68. package/src/embed/variant-backlog.ts +697 -63
  69. package/src/embed/variant-plan.ts +41 -45
  70. package/src/embed/variant-retry.ts +157 -44
  71. package/src/index.ts +3 -3
  72. package/src/ingestion/budget-error-codes.ts +13 -0
  73. package/src/ingestion/chunker.ts +60 -49
  74. package/src/ingestion/compiled-context.ts +4 -5
  75. package/src/ingestion/convert-file.ts +1 -1
  76. package/src/ingestion/document-metadata.ts +16 -9
  77. package/src/ingestion/excluded-ranges.ts +97 -0
  78. package/src/ingestion/file-processor.ts +122 -37
  79. package/src/ingestion/frontmatter.ts +35 -7
  80. package/src/ingestion/graph-reconciliation.ts +187 -51
  81. package/src/ingestion/language.ts +66 -61
  82. package/src/ingestion/position.ts +5 -5
  83. package/src/ingestion/prepare-file.ts +50 -29
  84. package/src/ingestion/record-adapter-canonical.ts +37 -26
  85. package/src/ingestion/record-adapter.ts +46 -26
  86. package/src/ingestion/record-container.ts +121 -53
  87. package/src/ingestion/record-path.ts +5 -2
  88. package/src/ingestion/source-availability/darwin-io.ts +10 -7
  89. package/src/ingestion/source-availability/darwin-path.ts +21 -3
  90. package/src/ingestion/source-availability/readers.ts +51 -0
  91. package/src/ingestion/strip.ts +39 -105
  92. package/src/ingestion/sync.ts +692 -386
  93. package/src/ingestion/typed-metadata.ts +10 -4
  94. package/src/ingestion/walker.ts +485 -158
  95. package/src/llm/cache.ts +128 -84
  96. package/src/llm/http-inference.ts +112 -35
  97. package/src/llm/http-policy.ts +101 -0
  98. package/src/llm/httpEmbedding.ts +8 -1
  99. package/src/llm/httpGeneration.ts +5 -1
  100. package/src/llm/httpRerank.ts +5 -1
  101. package/src/llm/inference-scope.ts +15 -2
  102. package/src/llm/lazy-ports.ts +33 -3
  103. package/src/llm/lockfile.ts +34 -7
  104. package/src/llm/model-cleanup.ts +24 -0
  105. package/src/llm/native-worker/client.ts +23 -12
  106. package/src/llm/native-worker/dispatcher.ts +19 -9
  107. package/src/llm/native-worker/embedding-identity.ts +42 -16
  108. package/src/llm/native-worker/entry.ts +2 -1
  109. package/src/llm/native-worker/owner.ts +1 -0
  110. package/src/llm/native-worker/ports.ts +86 -23
  111. package/src/llm/native-worker/protocol.ts +386 -55
  112. package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
  113. package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
  114. package/src/llm/nodeLlamaCpp/generation.ts +194 -30
  115. package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
  116. package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
  117. package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
  118. package/src/llm/types.ts +14 -0
  119. package/src/mcp/context.ts +342 -23
  120. package/src/mcp/http-transport.ts +21 -3
  121. package/src/mcp/tool-profile-types.ts +62 -0
  122. package/src/mcp/tool-profile.ts +32 -56
  123. package/src/mcp/tools/context.ts +5 -1
  124. package/src/mcp/tools/index.ts +269 -191
  125. package/src/mcp/tools/links.ts +7 -5
  126. package/src/mcp/tools/query.ts +60 -37
  127. package/src/mcp/tools/vsearch.ts +25 -14
  128. package/src/pipeline/answer.ts +133 -40
  129. package/src/pipeline/claim-verification.ts +293 -189
  130. package/src/pipeline/claim-verifier.ts +6 -7
  131. package/src/pipeline/egress-lineage.ts +37 -26
  132. package/src/pipeline/exclude.ts +34 -11
  133. package/src/pipeline/expansion.ts +233 -19
  134. package/src/pipeline/filters.ts +169 -33
  135. package/src/pipeline/graph-retrieval.ts +117 -61
  136. package/src/pipeline/hybrid.ts +598 -329
  137. package/src/pipeline/hydration.ts +86 -24
  138. package/src/pipeline/intent.ts +15 -7
  139. package/src/pipeline/owner-fusion.ts +61 -19
  140. package/src/pipeline/query-language.ts +15 -2
  141. package/src/pipeline/rerank.ts +15 -22
  142. package/src/pipeline/search.ts +193 -72
  143. package/src/pipeline/snippet.ts +15 -2
  144. package/src/pipeline/temporal.ts +51 -10
  145. package/src/pipeline/vsearch.ts +250 -152
  146. package/src/publish/attachment-raster.ts +2 -16
  147. package/src/publish/encrypted-export.ts +15 -5
  148. package/src/serve/browse-tree.ts +50 -42
  149. package/src/serve/connectors.ts +2 -1
  150. package/src/serve/context.ts +13 -4
  151. package/src/serve/doc-events.ts +3 -0
  152. package/src/serve/public/app.tsx +49 -21
  153. package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
  154. package/src/serve/public/components/CaptureModal.tsx +14 -10
  155. package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
  156. package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
  157. package/src/serve/public/globals.built.css +1 -1
  158. package/src/serve/public/globals.css +19 -0
  159. package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
  160. package/src/serve/public/lib/metadata-filter.ts +234 -9
  161. package/src/serve/public/pages/Browse.tsx +61 -27
  162. package/src/serve/public/pages/DocView.tsx +44 -25
  163. package/src/serve/public/pages/GraphView.tsx +8 -3
  164. package/src/serve/resident-runtime.ts +199 -48
  165. package/src/serve/routes/api.ts +98 -67
  166. package/src/serve/routes/links.ts +18 -4
  167. package/src/serve/server.ts +1370 -1180
  168. package/src/serve/spa-bundle-source.ts +52 -27
  169. package/src/serve/status.ts +101 -52
  170. package/src/serve/watch-reconciliation-fallback.ts +11 -7
  171. package/src/serve/watch-reconciliation-shared.ts +42 -4
  172. package/src/serve/watch-reconciliation.ts +21 -8
  173. package/src/serve/watch-service-events.ts +7 -1
  174. package/src/serve/watch-service-hosts.ts +3 -1
  175. package/src/serve/watch-service.ts +46 -21
  176. package/src/serve/watch-snapshot-scan.ts +6 -15
  177. package/src/sessions/archive.ts +20 -8
  178. package/src/sessions/sanitize.ts +38 -18
  179. package/src/sessions/service.ts +180 -102
  180. package/src/store/migrations/036-vector-mirror-state.ts +83 -0
  181. package/src/store/migrations/037-performance-indexes.ts +56 -0
  182. package/src/store/migrations/index.ts +4 -0
  183. package/src/store/sqlite/adapter.ts +1217 -651
  184. package/src/store/sqlite/chunking-policy.ts +15 -1
  185. package/src/store/sqlite/eligibility.ts +110 -70
  186. package/src/store/sqlite/graph-neighbors.ts +71 -46
  187. package/src/store/sqlite/graph-reference-state.ts +27 -3
  188. package/src/store/sqlite/graph-similarity.ts +59 -12
  189. package/src/store/sqlite/metadata-predicate.ts +123 -28
  190. package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
  191. package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
  192. package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
  193. package/src/store/types.ts +32 -0
  194. package/src/store/vector/eligibility.ts +39 -0
  195. package/src/store/vector/lazy.ts +17 -0
  196. package/src/store/vector/partition-index.ts +49 -47
  197. package/src/store/vector/proof-cache.ts +103 -0
  198. package/src/store/vector/sqlite-vec.ts +230 -139
  199. package/src/store/vector/stats.ts +29 -73
  200. package/src/store/vector/status.ts +151 -52
  201. package/src/store/vector/stored-vectors.ts +131 -45
  202. package/src/store/vector/types.ts +10 -0
  203. package/src/store/vector/variant-search.ts +771 -109
  204. package/src/store/vector/variants.ts +785 -144
  205. package/browser-extension/artifacts/gno-browser-clipper-v2.14.0.zip.sha256 +0 -1
@@ -40,7 +40,7 @@ import {
40
40
  } from "./archive";
41
41
  import { readAutomationStatus } from "./automation-status";
42
42
  import { canonicalConfigPath, writeIndexBinding } from "./binding";
43
- import { redactionStamp, sanitizeValue } from "./sanitize";
43
+ import { redactionStamp, sanitizeValue, ThreadSanitizer } from "./sanitize";
44
44
  import {
45
45
  archiveCollection,
46
46
  protectedRoots,
@@ -92,6 +92,29 @@ import {
92
92
  const IMPORT_LOCK_WAIT_MS = 2_000;
93
93
  const DISCOVERY_UNIT_LIMIT = 20_000;
94
94
  const PATH_SOURCE_PREFIX = "path-";
95
+ const FINGERPRINT_CONCURRENCY = 16;
96
+
97
+ async function mapWithConcurrency<T, R>(
98
+ items: readonly T[],
99
+ concurrency: number,
100
+ worker: (item: T, index: number) => Promise<R>
101
+ ): Promise<R[]> {
102
+ if (items.length === 0) return [];
103
+ const results = Array.from<R>({ length: items.length });
104
+ let nextIndex = 0;
105
+ const workerCount = Math.min(concurrency, items.length);
106
+ await Promise.all(
107
+ Array.from({ length: workerCount }, async () => {
108
+ while (true) {
109
+ const index = nextIndex;
110
+ nextIndex += 1;
111
+ if (index >= items.length) return;
112
+ results[index] = await worker(items[index]!, index);
113
+ }
114
+ })
115
+ );
116
+ return results;
117
+ }
95
118
 
96
119
  export interface SessionsServiceDeps {
97
120
  config: Config;
@@ -349,10 +372,11 @@ export class SessionsService {
349
372
  collection: source.collection,
350
373
  projects: source.projects ?? [],
351
374
  });
352
- // One batch of stats: status stays responsive while an import runs
353
- // in the same process.
354
- const fingerprints = await Promise.all(
355
- units.map((unit) => unitFingerprint(unit).catch(() => ""))
375
+ // Bounded batch of stats: status stays responsive without FD spikes.
376
+ const fingerprints = await mapWithConcurrency(
377
+ units,
378
+ FINGERPRINT_CONCURRENCY,
379
+ (unit) => unitFingerprint(unit).catch(() => "")
356
380
  );
357
381
  for (const [index, unit] of units.entries()) {
358
382
  const key = unitKey(source.id, unit.locator);
@@ -607,6 +631,11 @@ export class SessionsService {
607
631
  const changed = new Map<string, Set<string>>();
608
632
  const excluded = protectedRoots(sessions);
609
633
  const redaction = { literals: sessions.redaction?.literals ?? [] };
634
+ const sharedSanitizer = new ThreadSanitizer(redaction);
635
+ const sanitizeLocator = (value: string): string => {
636
+ sharedSanitizer.reset();
637
+ return sharedSanitizer.sanitize(value);
638
+ };
610
639
  const stamp = redactionStamp(redaction);
611
640
  // Units whose state changed this run; reverted if the index sync fails so
612
641
  // completion is only recorded once the archive is searchable.
@@ -667,9 +696,7 @@ export class SessionsService {
667
696
  recordUnit({
668
697
  sourceId: source.id,
669
698
  harness: null,
670
- locator: selectedFile
671
- ? sanitizeValue(basename(root), redaction)
672
- : ".",
699
+ locator: selectedFile ? sanitizeLocator(basename(root)) : ".",
673
700
  outcome: "unsupported",
674
701
  reason: "format_not_recognised",
675
702
  threads: 0,
@@ -713,9 +740,7 @@ export class SessionsService {
713
740
  sourceId: source.id,
714
741
  harness: source.harness,
715
742
  locator:
716
- entry.locator === null
717
- ? "."
718
- : sanitizeValue(entry.locator, redaction),
743
+ entry.locator === null ? "." : sanitizeLocator(entry.locator),
719
744
  outcome: "failed",
720
745
  reason: entry.reason,
721
746
  threads: 0,
@@ -725,97 +750,147 @@ export class SessionsService {
725
750
  }
726
751
  const present = new Set<string>();
727
752
  const destinations = destinationsStamp(source);
728
- for (const found of enumerated.units) {
729
- const key = unitKey(source.id, found.locator);
730
- // Receipts, warnings and checkpoint state show the locator with the
731
- // owner's redaction applied; identity stays in the opaque key.
732
- const unit: SessionUnit = {
733
- ...found,
734
- locator: sanitizeValue(found.locator, redaction),
735
- };
736
- if (present.has(key)) {
737
- // Two units with the same locator would share archive files.
738
- counts.failed += 1;
739
- recordUnit({
740
- sourceId: source.id,
741
- harness: unit.harness,
742
- locator: unit.locator,
743
- outcome: "failed",
744
- reason: "unit_conflict",
745
- threads: 0,
746
- turns: 0,
747
- collections: [],
748
- });
749
- continue;
750
- }
751
- present.add(key);
752
- let fingerprint: string;
753
- try {
754
- fingerprint = await unitFingerprint(unit);
755
- } catch (error) {
756
- counts.failed += 1;
757
- recordUnit({
758
- sourceId: source.id,
759
- harness: unit.harness,
760
- locator: unit.locator,
761
- outcome: "failed",
762
- reason: unitReason(error),
763
- threads: 0,
764
- turns: 0,
765
- collections: [],
766
- });
767
- continue;
768
- }
769
- const previous = sourceState.units[key];
770
- const current =
771
- previous?.status === "complete" &&
772
- previous.fingerprint === fingerprint &&
773
- previous.parser ===
774
- SESSION_PARSERS[previous.harness ?? unit.harness] &&
775
- previous.redaction === stamp &&
776
- previous.destinations === destinations &&
777
- previous.format === SESSION_ARCHIVE_FORMAT_VERSION;
778
- if (current) {
779
- // Already archived and up to date: reported, not re-read.
780
- counts.unchanged += previous.threads.length;
781
- continue;
782
- }
783
- if (options.limit !== undefined && processed >= options.limit) {
784
- deferred += 1;
785
- continue;
786
- }
787
- processed += 1;
788
- if (unit.size > SESSION_LIMITS.maxSourceBytes) {
789
- counts.skippedPolicy += 1;
790
- recordUnit({
791
- sourceId: source.id,
792
- harness: unit.harness,
793
- locator: unit.locator,
794
- outcome: "skipped_policy",
795
- reason: "over_limit",
796
- threads: 0,
797
- turns: 0,
798
- collections: [],
753
+ // Fingerprint in bounded lookahead windows; if an earlier unit in a window
754
+ // is imported (advancing wall-clock time), re-stat a prefetched match before
755
+ // skipping it so live appends to archived sessions are never missed.
756
+ for (
757
+ let windowStart = 0;
758
+ windowStart < enumerated.units.length;
759
+ windowStart += FINGERPRINT_CONCURRENCY
760
+ ) {
761
+ const windowUnits = enumerated.units.slice(
762
+ windowStart,
763
+ windowStart + FINGERPRINT_CONCURRENCY
764
+ );
765
+ const fingerprinted = await mapWithConcurrency(
766
+ windowUnits,
767
+ FINGERPRINT_CONCURRENCY,
768
+ async (found) => {
769
+ try {
770
+ return {
771
+ ok: true as const,
772
+ fingerprint: await unitFingerprint(found),
773
+ };
774
+ } catch (error) {
775
+ return { ok: false as const, error };
776
+ }
777
+ }
778
+ );
779
+ let importedInWindow = false;
780
+ for (let i = 0; i < windowUnits.length; i += 1) {
781
+ const found = windowUnits[i]!;
782
+ const fp = fingerprinted[i]!;
783
+ const key = unitKey(source.id, found.locator);
784
+ if (present.has(key)) {
785
+ // Two units with the same locator would share archive files.
786
+ counts.failed += 1;
787
+ recordUnit({
788
+ sourceId: source.id,
789
+ harness: found.harness,
790
+ locator: sanitizeLocator(found.locator),
791
+ outcome: "failed",
792
+ reason: "unit_conflict",
793
+ threads: 0,
794
+ turns: 0,
795
+ collections: [],
796
+ });
797
+ continue;
798
+ }
799
+ present.add(key);
800
+ if (!fp.ok) {
801
+ counts.failed += 1;
802
+ recordUnit({
803
+ sourceId: source.id,
804
+ harness: found.harness,
805
+ locator: sanitizeLocator(found.locator),
806
+ outcome: "failed",
807
+ reason: unitReason(fp.error),
808
+ threads: 0,
809
+ turns: 0,
810
+ collections: [],
811
+ });
812
+ continue;
813
+ }
814
+ let fingerprint = fp.fingerprint;
815
+ const previous = sourceState.units[key];
816
+ let current =
817
+ previous?.status === "complete" &&
818
+ previous.fingerprint === fingerprint &&
819
+ previous.parser ===
820
+ SESSION_PARSERS[previous.harness ?? found.harness] &&
821
+ previous.redaction === stamp &&
822
+ previous.destinations === destinations &&
823
+ previous.format === SESSION_ARCHIVE_FORMAT_VERSION;
824
+ if (current && previous && importedInWindow) {
825
+ try {
826
+ fingerprint = await unitFingerprint(found);
827
+ current = previous.fingerprint === fingerprint;
828
+ } catch (error) {
829
+ counts.failed += 1;
830
+ recordUnit({
831
+ sourceId: source.id,
832
+ harness: found.harness,
833
+ locator: sanitizeLocator(found.locator),
834
+ outcome: "failed",
835
+ reason: unitReason(error),
836
+ threads: 0,
837
+ turns: 0,
838
+ collections: [],
839
+ });
840
+ continue;
841
+ }
842
+ }
843
+ if (current && previous) {
844
+ // Already archived and up to date: reported, not re-read or sanitized.
845
+ counts.unchanged += previous.threads.length;
846
+ continue;
847
+ }
848
+ if (options.limit !== undefined && processed >= options.limit) {
849
+ deferred += 1;
850
+ continue;
851
+ }
852
+ processed += 1;
853
+ importedInWindow = true;
854
+ // Receipts, warnings and checkpoint state show the locator with the
855
+ // owner's redaction applied; identity stays in the opaque key.
856
+ const unit: SessionUnit = {
857
+ ...found,
858
+ locator: sanitizeLocator(found.locator),
859
+ };
860
+ if (unit.size > SESSION_LIMITS.maxSourceBytes) {
861
+ counts.skippedPolicy += 1;
862
+ recordUnit({
863
+ sourceId: source.id,
864
+ harness: unit.harness,
865
+ locator: unit.locator,
866
+ outcome: "skipped_policy",
867
+ reason: "over_limit",
868
+ threads: 0,
869
+ turns: 0,
870
+ collections: [],
871
+ });
872
+ continue;
873
+ }
874
+ touched.push({ units: sourceState.units, key });
875
+ const outcome = await this.importUnit({
876
+ source,
877
+ unit,
878
+ key,
879
+ destinations,
880
+ fingerprint,
881
+ previous,
882
+ sourceState,
883
+ dryRun: options.dryRun,
884
+ redaction,
885
+ redactionStampValue: stamp,
886
+ sharedSanitizer,
887
+ counts,
888
+ turns,
889
+ markChanged,
890
+ pendingWithdrawals,
799
891
  });
800
- continue;
892
+ recordUnit(outcome);
801
893
  }
802
- touched.push({ units: sourceState.units, key });
803
- const outcome = await this.importUnit({
804
- source,
805
- unit,
806
- key,
807
- destinations,
808
- fingerprint,
809
- previous,
810
- sourceState,
811
- dryRun: options.dryRun,
812
- redaction,
813
- counts,
814
- turns,
815
- markChanged,
816
- pendingWithdrawals,
817
- });
818
- recordUnit(outcome);
819
894
  }
820
895
 
821
896
  // Units whose source vanished keep their archive. Stale redaction is
@@ -823,7 +898,7 @@ export class SessionsService {
823
898
  for (const [key, unitState] of Object.entries(sourceState.units)) {
824
899
  if (present.has(key)) continue;
825
900
  // Retained locators follow the current redaction policy too.
826
- const locator = sanitizeValue(unitState.locator, redaction);
901
+ const locator = sanitizeLocator(unitState.locator);
827
902
  if (!options.dryRun) unitState.locator = locator;
828
903
  if (unitState.redaction !== stamp && !options.dryRun) {
829
904
  const previousStamp = unitState.redaction;
@@ -939,6 +1014,8 @@ export class SessionsService {
939
1014
  sourceState: SourceState;
940
1015
  dryRun: boolean;
941
1016
  redaction: { literals: readonly string[] };
1017
+ redactionStampValue: string;
1018
+ sharedSanitizer: ThreadSanitizer;
942
1019
  counts: SessionImportCounts;
943
1020
  turns: SessionTurnCounts;
944
1021
  markChanged: (collection: string, relPath: string) => void;
@@ -963,7 +1040,7 @@ export class SessionsService {
963
1040
  fingerprint: options.fingerprint,
964
1041
  status: "failed",
965
1042
  parser: null,
966
- redaction: redactionStamp(options.redaction),
1043
+ redaction: options.redactionStampValue,
967
1044
  destinations: options.destinations,
968
1045
  format: SESSION_ARCHIVE_FORMAT_VERSION,
969
1046
  threads: options.previous?.threads ?? [],
@@ -1084,6 +1161,7 @@ export class SessionsService {
1084
1161
  unitLocator: unit.locator,
1085
1162
  parser: parsed.parser,
1086
1163
  redaction: options.redaction,
1164
+ sanitizer: options.sharedSanitizer,
1087
1165
  });
1088
1166
  if (rendered.overLimit) {
1089
1167
  withhold(
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Migration: track whether each partition's vec0 mirror may be stale.
3
+ *
4
+ * `VectorVariantStore` keeps the vec0 mirror in step with `vector_variants`
5
+ * in the same transaction as every write it makes, and leaves this mark as it
6
+ * found it. Any other change to stored vectors (raw SQL, older tools, a write
7
+ * made while sqlite-vec was unavailable) fires these triggers and removes the
8
+ * partition's clean mark. `syncIndex()` and a verified activation mark it clean, so
9
+ * the end of an embed pass can skip re-verifying an activated partition while
10
+ * its mirror is known to be current, instead of scanning the whole index.
11
+ *
12
+ * @module src/store/migrations/036-vector-mirror-state
13
+ */
14
+
15
+ import type { Database } from "bun:sqlite";
16
+
17
+ import type { Migration } from "./runner";
18
+
19
+ export const migration: Migration = {
20
+ version: 36,
21
+ name: "vector_mirror_state",
22
+
23
+ up(db: Database): void {
24
+ // A partition is clean only while it has a row with dirty = 0. Triggers
25
+ // only delete rows, which never conflicts, so an outer statement's
26
+ // conflict clause (UPDATE OR IGNORE, INSERT OR REPLACE) cannot cancel the
27
+ // invalidation. The BEFORE triggers also invalidate partitions whose rows
28
+ // a REPLACE would displace (their delete triggers do not fire unless
29
+ // recursive_triggers is on). Each conflict is its own unique-key lookup:
30
+ // as one OR, statistics gathered while vector_variants was small made
31
+ // SQLite scan the table's index on every write.
32
+ db.exec(`
33
+ CREATE TABLE IF NOT EXISTS vector_mirror_state (
34
+ partition_id TEXT PRIMARY KEY,
35
+ dirty INTEGER NOT NULL CHECK (dirty IN (0, 1))
36
+ );
37
+ CREATE TRIGGER IF NOT EXISTS vector_variants_mirror_before_insert
38
+ BEFORE INSERT ON vector_variants BEGIN
39
+ DELETE FROM vector_mirror_state WHERE partition_id IN (
40
+ SELECT partition_id FROM vector_variants
41
+ WHERE variant_id = NEW.variant_id
42
+ UNION ALL
43
+ SELECT partition_id FROM vector_variants
44
+ WHERE partition_id = NEW.partition_id AND input_hash = NEW.input_hash
45
+ );
46
+ END;
47
+ CREATE TRIGGER IF NOT EXISTS vector_variants_mirror_insert
48
+ AFTER INSERT ON vector_variants BEGIN
49
+ DELETE FROM vector_mirror_state WHERE partition_id = NEW.partition_id;
50
+ END;
51
+ CREATE TRIGGER IF NOT EXISTS vector_variants_mirror_before_update
52
+ BEFORE UPDATE ON vector_variants BEGIN
53
+ DELETE FROM vector_mirror_state WHERE partition_id IN (
54
+ SELECT partition_id FROM vector_variants
55
+ WHERE variant_id = NEW.variant_id
56
+ UNION ALL
57
+ SELECT partition_id FROM vector_variants
58
+ WHERE partition_id = NEW.partition_id AND input_hash = NEW.input_hash
59
+ );
60
+ END;
61
+ CREATE TRIGGER IF NOT EXISTS vector_variants_mirror_update
62
+ AFTER UPDATE ON vector_variants BEGIN
63
+ DELETE FROM vector_mirror_state
64
+ WHERE partition_id IN (OLD.partition_id, NEW.partition_id);
65
+ END;
66
+ CREATE TRIGGER IF NOT EXISTS vector_variants_mirror_delete
67
+ AFTER DELETE ON vector_variants BEGIN
68
+ DELETE FROM vector_mirror_state WHERE partition_id = OLD.partition_id;
69
+ END;
70
+ `);
71
+ },
72
+
73
+ down(db: Database): void {
74
+ db.exec(`
75
+ DROP TRIGGER IF EXISTS vector_variants_mirror_before_insert;
76
+ DROP TRIGGER IF EXISTS vector_variants_mirror_insert;
77
+ DROP TRIGGER IF EXISTS vector_variants_mirror_before_update;
78
+ DROP TRIGGER IF EXISTS vector_variants_mirror_update;
79
+ DROP TRIGGER IF EXISTS vector_variants_mirror_delete;
80
+ DROP TABLE IF EXISTS vector_mirror_state;
81
+ `);
82
+ },
83
+ };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Migration: add covering and lookup indexes for vector owners, traces,
3
+ * document listing, and tag counts; drop strictly redundant left-prefix indexes.
4
+ *
5
+ * @module src/store/migrations/037-performance-indexes
6
+ */
7
+
8
+ import type { Database } from "bun:sqlite";
9
+
10
+ import type { Migration } from "./runner";
11
+
12
+ export const migration: Migration = {
13
+ version: 37,
14
+ name: "performance_indexes",
15
+
16
+ up(db: Database): void {
17
+ db.exec(`
18
+ CREATE INDEX IF NOT EXISTS idx_vector_owners_partition_variant
19
+ ON vector_owners(partition_id, variant_id, mirror_hash, seq, document_id);
20
+ CREATE INDEX IF NOT EXISTS idx_vector_owners_doc_part
21
+ ON vector_owners(document_id, partition_id, seq, mirror_hash, variant_id);
22
+ CREATE INDEX IF NOT EXISTS idx_vector_owners_mirror_seq
23
+ ON vector_owners(mirror_hash, seq);
24
+ CREATE INDEX IF NOT EXISTS idx_retrieval_traces_created
25
+ ON retrieval_traces(created_at_ms DESC, trace_id ASC);
26
+ CREATE INDEX IF NOT EXISTS idx_documents_collection_mtime
27
+ ON documents(collection, source_mtime DESC, id ASC)
28
+ WHERE active = 1;
29
+ DROP INDEX IF EXISTS idx_doc_tags_tag;
30
+ CREATE INDEX IF NOT EXISTS idx_doc_tags_tag_doc
31
+ ON doc_tags(tag, document_id);
32
+ DROP INDEX IF EXISTS idx_chunks_mirror_hash;
33
+ DROP INDEX IF EXISTS idx_doc_links_source_doc;
34
+ DROP INDEX IF EXISTS idx_doc_edges_src_type;
35
+ DROP INDEX IF EXISTS idx_doc_edges_dst_type;
36
+ DROP INDEX IF EXISTS idx_vectors_model;
37
+ `);
38
+ },
39
+
40
+ down(db: Database): void {
41
+ db.exec(`
42
+ DROP INDEX IF EXISTS idx_vector_owners_partition_variant;
43
+ DROP INDEX IF EXISTS idx_vector_owners_doc_part;
44
+ DROP INDEX IF EXISTS idx_vector_owners_mirror_seq;
45
+ DROP INDEX IF EXISTS idx_retrieval_traces_created;
46
+ DROP INDEX IF EXISTS idx_documents_collection_mtime;
47
+ DROP INDEX IF EXISTS idx_doc_tags_tag_doc;
48
+ CREATE INDEX IF NOT EXISTS idx_doc_tags_tag ON doc_tags(tag);
49
+ CREATE INDEX IF NOT EXISTS idx_chunks_mirror_hash ON content_chunks(mirror_hash);
50
+ CREATE INDEX IF NOT EXISTS idx_doc_links_source_doc ON doc_links(source_doc_id);
51
+ CREATE INDEX IF NOT EXISTS idx_doc_edges_src_type ON doc_edges(src_doc_id, edge_type);
52
+ CREATE INDEX IF NOT EXISTS idx_doc_edges_dst_type ON doc_edges(dst_doc_id, edge_type);
53
+ CREATE INDEX IF NOT EXISTS idx_vectors_model ON content_vectors(model);
54
+ `);
55
+ },
56
+ };
@@ -49,6 +49,8 @@ import { migration as m032 } from "./032-vector-runtime-callers";
49
49
  import { migration as m033 } from "./033-drop-documents-active-index";
50
50
  import { migration as m034 } from "./034-collection-link-workspace";
51
51
  import { migration as m035 } from "./035-vector-length-index";
52
+ import { migration as m036 } from "./036-vector-mirror-state";
53
+ import { migration as m037 } from "./037-performance-indexes";
52
54
 
53
55
  /** All migrations in order */
54
56
  export const migrations = [
@@ -87,4 +89,6 @@ export const migrations = [
87
89
  m033,
88
90
  m034,
89
91
  m035,
92
+ m036,
93
+ m037,
90
94
  ];