@avantf/dsh-mem 0.6.4 → 0.8.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 (150) hide show
  1. package/README.md +19 -10
  2. package/lib/client.js +1665 -3466
  3. package/lib/dsh-build.json +6 -5
  4. package/lib/engine/graph-recall/in-memory.d.ts +93 -0
  5. package/lib/engine/graph-recall/index.d.ts +22 -0
  6. package/lib/engine/graph-recall/traverse.d.ts +119 -0
  7. package/lib/engine/graph-recall/types.d.ts +188 -0
  8. package/lib/engine/mem/config/config_files.d.ts +1 -1
  9. package/lib/engine/mem/config/loader.d.ts +2 -3
  10. package/lib/engine/mem/config/paths.d.ts +2 -13
  11. package/lib/engine/mem/db/dao/contradictions.d.ts +4 -22
  12. package/lib/engine/mem/db/dao/entities.d.ts +80 -7
  13. package/lib/engine/mem/db/dao/fact_sources.d.ts +3 -13
  14. package/lib/engine/mem/db/dao/facts.d.ts +311 -56
  15. package/lib/engine/mem/db/dao/triples.d.ts +1 -26
  16. package/lib/engine/mem/db/graph.d.ts +249 -0
  17. package/lib/engine/mem/db/journal_notes.d.ts +35 -0
  18. package/lib/engine/mem/db/migrations.d.ts +9 -0
  19. package/lib/engine/mem/db/port.d.ts +22 -3
  20. package/lib/engine/mem/db/schema.d.ts +119 -0
  21. package/lib/engine/mem/db/tokenizer.d.ts +9 -0
  22. package/lib/engine/mem/dbdrivers/fake/driver.d.ts +75 -0
  23. package/lib/engine/mem/dbdrivers/fake/index.d.ts +7 -0
  24. package/lib/engine/mem/dbdrivers/fake/surface.d.ts +34 -0
  25. package/lib/engine/mem/dbdrivers/fake/transport.d.ts +61 -0
  26. package/lib/engine/mem/dbdrivers/sqlite/connection.d.ts +14 -0
  27. package/lib/engine/mem/dbdrivers/sqlite/contradictions.d.ts +35 -0
  28. package/lib/engine/mem/dbdrivers/sqlite/dao/index.d.ts +16 -0
  29. package/lib/engine/mem/dbdrivers/sqlite/driver.d.ts +54 -0
  30. package/lib/engine/mem/dbdrivers/sqlite/facts.d.ts +117 -0
  31. package/lib/engine/mem/dbdrivers/sqlite/index.d.ts +6 -0
  32. package/lib/engine/mem/dbdrivers/sqlite/migrations.d.ts +15 -0
  33. package/lib/engine/mem/dbdrivers/sqlite/relations.d.ts +62 -0
  34. package/lib/engine/mem/dbdrivers/sqlite/search.d.ts +56 -0
  35. package/lib/engine/mem/dbdrivers/sqlite/sources.d.ts +37 -0
  36. package/lib/engine/mem/defaults.d.ts +3 -4
  37. package/lib/engine/mem/dispatch.d.ts +7 -32
  38. package/lib/engine/mem/entities/extract.d.ts +44 -47
  39. package/lib/engine/mem/eval/derived_runner.d.ts +6 -1
  40. package/lib/engine/mem/eval/relation_gold.d.ts +251 -0
  41. package/lib/engine/mem/eval/write_metrics.d.ts +1 -1
  42. package/lib/engine/mem/facts_io.d.ts +328 -0
  43. package/lib/engine/mem/index.d.ts +10 -2
  44. package/lib/engine/mem/interfaces/capabilities.d.ts +30 -0
  45. package/lib/engine/mem/interfaces/common.d.ts +11 -0
  46. package/lib/engine/mem/interfaces/errors.d.ts +65 -0
  47. package/lib/engine/mem/interfaces/index.d.ts +18 -0
  48. package/lib/engine/mem/interfaces/migrations.d.ts +21 -0
  49. package/lib/engine/mem/interfaces/repositories.d.ts +471 -0
  50. package/lib/engine/mem/interfaces/search_index.d.ts +113 -0
  51. package/lib/engine/mem/interfaces/storage_backend.d.ts +84 -0
  52. package/lib/engine/mem/interfaces/storage_driver.d.ts +43 -0
  53. package/lib/engine/mem/interfaces/version.d.ts +34 -0
  54. package/lib/engine/mem/lifecycle/contradiction.d.ts +2 -2
  55. package/lib/engine/mem/maintenance_paths.d.ts +41 -0
  56. package/lib/engine/mem/modelBootstrap.d.ts +1 -1
  57. package/lib/engine/mem/relations/confidence.d.ts +39 -0
  58. package/lib/engine/mem/relations/extract.d.ts +128 -0
  59. package/lib/engine/mem/relations/index.d.ts +32 -0
  60. package/lib/engine/mem/relations/name-quality.d.ts +78 -0
  61. package/lib/engine/mem/relations/normalize.d.ts +275 -0
  62. package/lib/engine/mem/relations/patterns.d.ts +67 -0
  63. package/lib/engine/mem/relations/statement.d.ts +88 -0
  64. package/lib/engine/mem/relations/types.d.ts +79 -0
  65. package/lib/engine/mem/runtime.d.ts +117 -90
  66. package/lib/engine/mem/storage/create.d.ts +42 -0
  67. package/lib/engine/mem/storage/errors.d.ts +65 -0
  68. package/lib/engine/mem/storage/index.d.ts +15 -0
  69. package/lib/engine/mem/storage/ports.d.ts +472 -0
  70. package/lib/engine/mem/storage/registry.d.ts +37 -0
  71. package/lib/engine/mem/storage/sqlite.d.ts +28 -0
  72. package/lib/engine/mem/store/common.d.ts +1 -1
  73. package/lib/engine/mem/store/entity_leg.d.ts +59 -2
  74. package/lib/engine/mem/store/entity_sweep.d.ts +4 -3
  75. package/lib/engine/mem/store/explicit_relations.d.ts +52 -0
  76. package/lib/engine/mem/store/facts_restore.d.ts +124 -0
  77. package/lib/engine/mem/store/floors.d.ts +4 -1
  78. package/lib/engine/mem/store/graph_reader.d.ts +146 -0
  79. package/lib/engine/mem/store/hybrid.d.ts +50 -13
  80. package/lib/engine/mem/store/kinds.d.ts +47 -0
  81. package/lib/engine/mem/store/legs.d.ts +24 -29
  82. package/lib/engine/mem/store/lexical.d.ts +36 -45
  83. package/lib/engine/mem/store/memory.d.ts +486 -82
  84. package/lib/engine/mem/store/recall_policy.d.ts +49 -0
  85. package/lib/engine/mem/store/relation_backfill.d.ts +210 -0
  86. package/lib/engine/mem/store/relation_planner.d.ts +191 -0
  87. package/lib/engine/mem/store/secret_guard.d.ts +0 -1
  88. package/lib/engine/mem/store/self_query.d.ts +4 -2
  89. package/lib/engine/mem/store/time_filter.d.ts +121 -0
  90. package/lib/engine/mem/store/titles.d.ts +52 -0
  91. package/lib/engine/mem/store/vector_repair.d.ts +44 -54
  92. package/lib/engine/mem-contract/config.d.ts +44 -38
  93. package/lib/engine/mem-contract/text.d.ts +1 -1
  94. package/lib/engine/mem-contract/tools.d.ts +184 -117
  95. package/lib/engine/mem-contract/types.d.ts +364 -288
  96. package/lib/index.js +13898 -11500
  97. package/lib/interface-version.json +1 -1
  98. package/lib/types/client/index.d.ts +2 -2
  99. package/lib/types/client/index.d.ts.map +1 -1
  100. package/lib/types/client/paging.d.ts +3 -12
  101. package/lib/types/client/paging.d.ts.map +1 -1
  102. package/lib/types/client/summarize.d.ts.map +1 -1
  103. package/lib/types/command.d.ts +61 -0
  104. package/lib/types/command.d.ts.map +1 -0
  105. package/lib/types/envinit-bootstrap.d.ts +1 -1
  106. package/lib/types/envinit.d.ts +2 -6
  107. package/lib/types/envinit.d.ts.map +1 -1
  108. package/lib/types/hints.d.ts +28 -24
  109. package/lib/types/hints.d.ts.map +1 -1
  110. package/lib/types/index.d.ts +21 -40
  111. package/lib/types/index.d.ts.map +1 -1
  112. package/lib/types/inject.d.ts +3 -2
  113. package/lib/types/inject.d.ts.map +1 -1
  114. package/lib/types/interface_gate.d.ts +9 -9
  115. package/lib/types/prompt.d.ts +17 -41
  116. package/lib/types/prompt.d.ts.map +1 -1
  117. package/lib/types/provision.d.ts +3 -0
  118. package/lib/types/provision.d.ts.map +1 -1
  119. package/lib/types/remote.d.ts +23 -9
  120. package/lib/types/remote.d.ts.map +1 -1
  121. package/lib/types/render.d.ts +3 -3
  122. package/lib/types/tool_schema.d.ts +4 -0
  123. package/lib/types/tool_schema.d.ts.map +1 -1
  124. package/lib/types/vectorMigration.d.ts +5 -7
  125. package/lib/types/vectorMigration.d.ts.map +1 -1
  126. package/package.json +16 -15
  127. package/lib/engine/mem/config/domains.d.ts +0 -20
  128. package/lib/engine/mem/db/dao/chunks.d.ts +0 -231
  129. package/lib/engine/mem/db/dao/documents.d.ts +0 -51
  130. package/lib/engine/mem/db/hash.d.ts +0 -2
  131. package/lib/engine/mem/db/knowledge.d.ts +0 -17
  132. package/lib/engine/mem/eval/index.d.ts +0 -4
  133. package/lib/engine/mem/git.d.ts +0 -73
  134. package/lib/engine/mem/router.d.ts +0 -51
  135. package/lib/engine/mem/store/doc_files.d.ts +0 -125
  136. package/lib/engine/mem/store/document_text.d.ts +0 -47
  137. package/lib/engine/mem/store/ingest_guard.d.ts +0 -25
  138. package/lib/engine/mem/store/knowledge.d.ts +0 -598
  139. package/lib/engine/mem/store/source_picker.d.ts +0 -43
  140. package/lib/engine/mem-retrieval/adapters/local_reranker.d.ts +0 -52
  141. package/lib/engine/mem-retrieval/adapters/none_reranker.d.ts +0 -10
  142. package/lib/engine/mem-retrieval/rerank.d.ts +0 -13
  143. package/lib/types/client/domains.d.ts +0 -53
  144. package/lib/types/client/domains.d.ts.map +0 -1
  145. package/lib/types/client/ingest.d.ts +0 -24
  146. package/lib/types/client/ingest.d.ts.map +0 -1
  147. package/lib/types/open.d.ts +0 -77
  148. package/lib/types/open.d.ts.map +0 -1
  149. package/lib/types/reconcile.d.ts +0 -64
  150. package/lib/types/reconcile.d.ts.map +0 -1
@@ -1,15 +1,13 @@
1
1
  /**
2
- * The sync relevance probe behind the plugin's conditional hints (DESIGN §12).
2
+ * The LEXICAL TERM SET and its term-count probe.
3
3
  *
4
- * WHY THIS IS LEXICAL, AND WHY IT MUST BE SYNC. The hint has to be in place *before* the step's
5
- * prompt is assembled — `dsh-agent-loop`'s `preStep` calls `systemPrompt.assemble()` immediately
6
- * after the message is admitted, and the section/context provider that renders the hint is
7
- * SYNCHRONOUS (it cannot await). Of the retrieval legs, only the FTS one is synchronous: the
8
- * semantic leg needs an `encode()`, and a warm encode is ~10–20 ms, which loses the race and lands
9
- * the hint one step late — i.e. after the model already decided whether to call a tool. So the
10
- * gate is a lexical one, and paraphrase-style questions score 0 here. That is the accepted trade:
11
- * it stays SILENT when unsure, and the always-on usage sections remain the fallback that tells the
12
- * model to query anyway.
4
+ * NOT the hint's decision any more. The conditional hint is `AvantfRuntime.wouldFind`, which runs
5
+ * the SAME retrieval pipeline as the tools and answers "would it return a hit?" (DESIGN §12). This
6
+ * module used to be that decision's cheap first half; it now provides the term definition the
7
+ * retrieval legs and floors consume ({@link relevanceTerms} / {@link gradedTerms} /
8
+ * {@link substringTerms}) plus a diagnostic term-count probe ({@link looksRelevant} /
9
+ * {@link probeStoreTerms}) that the regression test uses to show what the OLD hint would have
10
+ * answered (`test/retrieve.spec.ts`, shape B: lexical hit blocked by `min_score`).
13
11
  *
14
12
  * THE BAR, AND HOW IT WAS MEASURED. Terms are latin/digit words of >= 5 chars plus every CJK
15
13
  * 3-gram (the FTS tables are trigram-tokenised, so a 2-char CJK term cannot be expressed and a
@@ -24,36 +22,27 @@
24
22
  * would not have saved it; BOTH the floor and the two-term bar are load-bearing. Hence
25
23
  * `matched >= 2`, with the margin between 2 and 1 rather than a tuned threshold inside a
26
24
  * continuum. A single-word query (`cgroup`) scores 1 and stays silent on purpose: one term is not
27
- * evidence.
25
+ * evidence. The numbers stay here as the record of that calibration; the hint no longer branches
26
+ * on them.
28
27
  *
29
- * THE SHORT-CJK FALLBACK (and why the hint probe does NOT use it). The trigram index has no term
30
- * shorter than three characters — measured on the live store: `fts5vocab` over `facts_fts` holds
31
- * 27906 distinct terms and EVERY one is 3 characters (and a 2-char `MATCH` returns nothing, even as
32
- * a prefix query). So a 2-char CJK query produces no FTS term at all and that leg is empty by
33
- * construction. The FTS LEG therefore falls back to the one finer predicate the FTS5 trigram TABLE
34
- * does expose: `content LIKE '%…%'`, which matches a 2-char run by scanning (no index can serve a
35
- * 2-char pattern). See {@link substringTerms} / {@link gradedTerms}.
28
+ * THE SHORT-CJK FALLBACK. The trigram index has no term shorter than three characters — measured on
29
+ * the live store: `fts5vocab` over `facts_fts` holds 27906 distinct terms and EVERY one is 3
30
+ * characters (and a 2-char `MATCH` returns nothing, even as a prefix query). So a 2-char CJK query
31
+ * produces no FTS term at all and that leg is empty by construction. The FTS LEG therefore falls
32
+ * back to the one finer predicate the FTS5 trigram TABLE does expose: `content LIKE '%…%'`, which
33
+ * matches a 2-char run by scanning (no index can serve a 2-char pattern). See
34
+ * {@link substringTerms} / {@link gradedTerms}.
36
35
  *
37
- * The conditional-hint probe deliberately keeps the index-expressible terms only: it is
38
- * SYNCHRONOUS and runs on every step's prompt assembly, so it must stay a bounded number of
39
- * `LIMIT 1` index lookups — an O(corpus) scan per 2-char term would put a full scan on the prompt
40
- * path. Behaviour is unchanged there: a 2-char query scored 0 matched terms before and still does
41
- * (`{terms: 0, matched: 0}`), so the hint stays silent exactly as it did.
36
+ * The term-count probe keeps the index-expressible terms only: it is a bounded number of
37
+ * `LIMIT 1` index lookups, never an O(corpus) scan — there is no prompt-path budget reason for that
38
+ * any more, but it is still the right cost for a diagnostic.
42
39
  */
43
- import { type FtsTokenizer } from '../db/tokenizer.js';
40
+ import type { Awaitable } from '../interfaces/common.js';
44
41
  /** How many of an input's terms a store holds. `terms === 0` means the input had nothing to test. */
45
42
  export interface LexicalProbe {
46
43
  terms: number;
47
44
  matched: number;
48
45
  }
49
- /**
50
- * Which stores hold something relevant — the ONE answer the plugin's hint layer consumes.
51
- *
52
- * A boolean on purpose: `kb_query` retrieves from BOTH stores, so the hint only has to decide
53
- * "worth mentioning or not". Which store matched is nobody's business downstream — and asking for
54
- * it cost a distinction the probe would have to keep alive in two places.
55
- */
56
- export type RelevanceHit = boolean;
57
46
  /**
58
47
  * The distinct terms of `text` that the FTS tables can express.
59
48
  *
@@ -92,28 +81,30 @@ export declare function substringTerms(text: string, cap?: number): string[];
92
81
  */
93
82
  export declare function gradedTerms(text: string, cap?: number): string[];
94
83
  /**
95
- * The gate itself: is this store worth telling the model about?
84
+ * The old hint's bar, kept as the lexical ORACLE the regression test compares against: does this
85
+ * store hold at least two of the text's distinct terms?
96
86
  *
97
87
  * Two distinct terms is the measured bar (see the module comment). Deliberately not "at least one"
98
88
  * — a single hit is what a common word produces — and deliberately not a score threshold, because
99
89
  * bm25 sums over OR'd terms and therefore rewards a long question for merely containing many
100
- * 3-grams.
90
+ * 3-grams. NOTHING on the retrieval or hint path branches on this: `wouldFind` asks the retrieval
91
+ * pipeline itself, and a lexical hit that cannot reach `min_score` must NOT fire the hint.
101
92
  */
102
93
  export declare function looksRelevant(probe: LexicalProbe): boolean;
103
94
  /**
104
95
  * Count how many of `text`'s terms ONE store holds.
105
96
  *
106
- * The loop both stores used to carry verbatim. `holds` is handed the raw TERM, not a built MATCH
107
- * expression: turning a term into a query depends on the tokenizer the store's FTS table was actually
108
- * built with (see `db/tokenizer.ts`), which is the store's business, not this module's. Each store
109
- * asks its own table with `LIMIT 1` — the question is whether a term exists at all, not where it ranks. `stopAt` lets a caller that only asks "≥ 2?" stop early (`relevance()` does, and the prompt
110
- * path is synchronous); the default keeps an exact count for the calibration recorded above.
97
+ * The loop both stores used to carry verbatim. `holds` is handed the raw TERM: turning a term into
98
+ * an index expression depends on the backend and its tokenizer, which is the backend's business
99
+ * (DB-3 made that explicit — the adapter owns the query builder). Each store asks its own index
100
+ * with `LIMIT 1` — the question is whether a term exists at all, not where it ranks. `stopAt` lets a
101
+ * caller that only asks "≥ 2?" stop early; the default keeps an exact count for the calibration
102
+ * recorded above.
111
103
  */
112
- export declare function probeTerms(text: string, holds: (term: string) => boolean, stopAt?: number): LexicalProbe;
104
+ export declare function probeTerms(text: string, holds: (term: string) => Awaitable<boolean>, stopAt?: number): Promise<LexicalProbe>;
113
105
  /**
114
- * The store probe both stores' `lexicalProbe` used to spell out verbatim: build THIS store's MATCH
115
- * expression for one term (the tokenizer is a property of the store's FTS table) and ask that
116
- * table whether anything holds it. `probeTerms` owns the term set and the counting; this owns the
117
- * one part that has to differ, which is now a single `holds` closure per store.
106
+ * The store probe both stores' `lexicalProbe` used to spell out verbatim: ask THIS store's index
107
+ * whether anything holds a term. `probeTerms` owns the term set and the counting; this owns the one
108
+ * part that has to differ, which is now a single `holds` closure per store.
118
109
  */
119
- export declare function probeStoreTerms(text: string, tokenizer: FtsTokenizer, holds: (ftsQuery: string) => boolean, stopAt?: number): LexicalProbe;
110
+ export declare function probeStoreTerms(text: string, holds: (term: string) => Awaitable<boolean>, stopAt?: number): Promise<LexicalProbe>;