dsh-data-domain-knowledge 0.1.0-alpha.9 → 0.1.1-alpha.2

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 (438) hide show
  1. package/README.md +118 -567
  2. package/cordis.patch.yml +5 -418
  3. package/eval/README.md +19 -8
  4. package/eval/benchmark-extraction-format.mjs +20 -0
  5. package/eval/evaluate-retrieval.mjs +17 -8
  6. package/eval/queries.example.jsonl +1 -0
  7. package/lib/client.js +4181 -3239
  8. package/lib/contract-envelope.d.ts +91 -0
  9. package/lib/contract-envelope.js +106 -0
  10. package/lib/contract-layout.d.ts +130 -0
  11. package/lib/contract-layout.js +138 -0
  12. package/lib/contract-refs.d.ts +39 -0
  13. package/lib/contract-refs.js +9 -0
  14. package/lib/contract-version.d.ts +311 -0
  15. package/lib/contract-version.js +270 -0
  16. package/lib/contract-wire.d.ts +147 -0
  17. package/lib/contract-wire.js +99 -0
  18. package/lib/contracts.d.ts +12 -0
  19. package/lib/contracts.js +12 -0
  20. package/lib/doc-page.js +2 -2
  21. package/lib/pages.js +3329 -1296
  22. package/lib/types/agent-behavior-rules.d.ts +10 -0
  23. package/lib/types/agent-behavior-rules.d.ts.map +1 -0
  24. package/lib/types/agent-behavior-rules.js +28 -0
  25. package/lib/types/agent-behavior-rules.js.map +1 -0
  26. package/lib/types/axis-registry.d.ts +37 -5
  27. package/lib/types/axis-registry.d.ts.map +1 -1
  28. package/lib/types/axis-registry.js +234 -26
  29. package/lib/types/axis-registry.js.map +1 -1
  30. package/lib/types/card-organize.d.ts +27 -12
  31. package/lib/types/card-organize.d.ts.map +1 -1
  32. package/lib/types/card-organize.js +58 -73
  33. package/lib/types/card-organize.js.map +1 -1
  34. package/lib/types/compiler/embedding-identity.d.ts +3 -0
  35. package/lib/types/compiler/embedding-identity.d.ts.map +1 -0
  36. package/lib/types/compiler/embedding-identity.js +24 -0
  37. package/lib/types/compiler/embedding-identity.js.map +1 -0
  38. package/lib/types/compiler/snapshot.d.ts +16 -0
  39. package/lib/types/compiler/snapshot.d.ts.map +1 -0
  40. package/lib/types/compiler/snapshot.js +2 -0
  41. package/lib/types/compiler/snapshot.js.map +1 -0
  42. package/lib/types/config-schema.d.ts +6 -3
  43. package/lib/types/config-schema.d.ts.map +1 -1
  44. package/lib/types/config-schema.js +6 -2
  45. package/lib/types/config-schema.js.map +1 -1
  46. package/lib/types/convert/host.d.ts +6 -5
  47. package/lib/types/convert/host.d.ts.map +1 -1
  48. package/lib/types/convert/host.js +58 -18
  49. package/lib/types/convert/host.js.map +1 -1
  50. package/lib/types/convert/ingest.d.ts +10 -1
  51. package/lib/types/convert/ingest.d.ts.map +1 -1
  52. package/lib/types/convert/ingest.js +68 -9
  53. package/lib/types/convert/ingest.js.map +1 -1
  54. package/lib/types/derive-contract.d.ts +3 -0
  55. package/lib/types/derive-contract.d.ts.map +1 -0
  56. package/lib/types/derive-contract.js +15 -0
  57. package/lib/types/derive-contract.js.map +1 -0
  58. package/lib/types/diagnosis/cards.d.ts +7 -3
  59. package/lib/types/diagnosis/cards.d.ts.map +1 -1
  60. package/lib/types/diagnosis/cards.js +13 -8
  61. package/lib/types/diagnosis/cards.js.map +1 -1
  62. package/lib/types/diagnosis/run.d.ts +4 -13
  63. package/lib/types/diagnosis/run.d.ts.map +1 -1
  64. package/lib/types/diagnosis/run.js +26 -16
  65. package/lib/types/diagnosis/run.js.map +1 -1
  66. package/lib/types/diagnosis/schema.js +2 -2
  67. package/lib/types/diagnosis/schema.js.map +1 -1
  68. package/lib/types/diagnosis/seed-source.d.ts +1 -1
  69. package/lib/types/diagnosis/seed-source.d.ts.map +1 -1
  70. package/lib/types/diagnosis/seed-source.js +5 -4
  71. package/lib/types/diagnosis/seed-source.js.map +1 -1
  72. package/lib/types/diagnosis/seed.d.ts +4 -4
  73. package/lib/types/diagnosis/seed.d.ts.map +1 -1
  74. package/lib/types/diagnosis/seed.js +6 -8
  75. package/lib/types/diagnosis/seed.js.map +1 -1
  76. package/lib/types/diagnosis/store.d.ts +24 -18
  77. package/lib/types/diagnosis/store.d.ts.map +1 -1
  78. package/lib/types/diagnosis/store.js +130 -65
  79. package/lib/types/diagnosis/store.js.map +1 -1
  80. package/lib/types/diagnosis/types.d.ts +47 -15
  81. package/lib/types/diagnosis/types.d.ts.map +1 -1
  82. package/lib/types/diagnosis/types.js.map +1 -1
  83. package/lib/types/environment/dsh-python.d.ts +77 -0
  84. package/lib/types/environment/dsh-python.d.ts.map +1 -0
  85. package/lib/types/environment/dsh-python.js +139 -0
  86. package/lib/types/environment/dsh-python.js.map +1 -0
  87. package/lib/types/environment/install.d.ts +15 -0
  88. package/lib/types/environment/install.d.ts.map +1 -0
  89. package/lib/types/environment/install.js +297 -0
  90. package/lib/types/environment/install.js.map +1 -0
  91. package/lib/types/environment/manifest.d.ts +208 -0
  92. package/lib/types/environment/manifest.d.ts.map +1 -0
  93. package/lib/types/environment/manifest.js +26 -0
  94. package/lib/types/environment/manifest.js.map +1 -0
  95. package/lib/types/environment/model-catalog.d.ts +223 -0
  96. package/lib/types/environment/model-catalog.d.ts.map +1 -0
  97. package/lib/types/environment/model-catalog.js +129 -0
  98. package/lib/types/environment/model-catalog.js.map +1 -0
  99. package/lib/types/environment/process.d.ts +10 -0
  100. package/lib/types/environment/process.d.ts.map +1 -0
  101. package/lib/types/environment/process.js +54 -0
  102. package/lib/types/environment/process.js.map +1 -0
  103. package/lib/types/environment/selection.d.ts +9 -0
  104. package/lib/types/environment/selection.d.ts.map +1 -0
  105. package/lib/types/environment/selection.js +29 -0
  106. package/lib/types/environment/selection.js.map +1 -0
  107. package/lib/types/environment/service.d.ts +64 -0
  108. package/lib/types/environment/service.d.ts.map +1 -0
  109. package/lib/types/environment/service.js +424 -0
  110. package/lib/types/environment/service.js.map +1 -0
  111. package/lib/types/environment/types.d.ts +56 -0
  112. package/lib/types/environment/types.d.ts.map +1 -0
  113. package/lib/types/environment/types.js +2 -0
  114. package/lib/types/environment/types.js.map +1 -0
  115. package/lib/types/events.d.ts +76 -0
  116. package/lib/types/events.d.ts.map +1 -0
  117. package/lib/types/events.js +52 -0
  118. package/lib/types/events.js.map +1 -0
  119. package/lib/types/extract-contract.d.ts +3 -0
  120. package/lib/types/extract-contract.d.ts.map +1 -0
  121. package/lib/types/extract-contract.js +41 -0
  122. package/lib/types/extract-contract.js.map +1 -0
  123. package/lib/types/extract-model.d.ts +5 -0
  124. package/lib/types/extract-model.d.ts.map +1 -1
  125. package/lib/types/extract-model.js.map +1 -1
  126. package/lib/types/extract-table-contract.d.ts +3 -0
  127. package/lib/types/extract-table-contract.d.ts.map +1 -0
  128. package/lib/types/extract-table-contract.js +27 -0
  129. package/lib/types/extract-table-contract.js.map +1 -0
  130. package/lib/types/extract-table.d.ts +8 -0
  131. package/lib/types/extract-table.d.ts.map +1 -0
  132. package/lib/types/extract-table.js +158 -0
  133. package/lib/types/extract-table.js.map +1 -0
  134. package/lib/types/extraction-runs.d.ts +30 -6
  135. package/lib/types/extraction-runs.d.ts.map +1 -1
  136. package/lib/types/extraction-runs.js +69 -8
  137. package/lib/types/extraction-runs.js.map +1 -1
  138. package/lib/types/fs-atomic.d.ts +0 -7
  139. package/lib/types/fs-atomic.d.ts.map +1 -1
  140. package/lib/types/fs-atomic.js +17 -2
  141. package/lib/types/fs-atomic.js.map +1 -1
  142. package/lib/types/images.d.ts +26 -0
  143. package/lib/types/images.d.ts.map +1 -0
  144. package/lib/types/images.js +196 -0
  145. package/lib/types/images.js.map +1 -0
  146. package/lib/types/index.d.ts +2 -2
  147. package/lib/types/index.d.ts.map +1 -1
  148. package/lib/types/index.js +598 -209
  149. package/lib/types/index.js.map +1 -1
  150. package/lib/types/intent/engine.d.ts +12 -4
  151. package/lib/types/intent/engine.d.ts.map +1 -1
  152. package/lib/types/intent/engine.js +43 -5
  153. package/lib/types/intent/engine.js.map +1 -1
  154. package/lib/types/intent/host.d.ts +5 -8
  155. package/lib/types/intent/host.d.ts.map +1 -1
  156. package/lib/types/intent/host.js +56 -11
  157. package/lib/types/intent/host.js.map +1 -1
  158. package/lib/types/intent/scope.d.ts +25 -0
  159. package/lib/types/intent/scope.d.ts.map +1 -0
  160. package/lib/types/intent/scope.js +116 -0
  161. package/lib/types/intent/scope.js.map +1 -0
  162. package/lib/types/intent/tools.d.ts +24 -20
  163. package/lib/types/intent/tools.d.ts.map +1 -1
  164. package/lib/types/intent/tools.js +65 -23
  165. package/lib/types/intent/tools.js.map +1 -1
  166. package/lib/types/intent/types.d.ts +11 -4
  167. package/lib/types/intent/types.d.ts.map +1 -1
  168. package/lib/types/knowledge-bases.d.ts +11 -5
  169. package/lib/types/knowledge-bases.d.ts.map +1 -1
  170. package/lib/types/knowledge-bases.js +52 -20
  171. package/lib/types/knowledge-bases.js.map +1 -1
  172. package/lib/types/knowledge-contract.d.ts +32 -0
  173. package/lib/types/knowledge-contract.d.ts.map +1 -0
  174. package/lib/types/knowledge-contract.js +116 -0
  175. package/lib/types/knowledge-contract.js.map +1 -0
  176. package/lib/types/knowledge.d.ts +31 -9
  177. package/lib/types/knowledge.d.ts.map +1 -1
  178. package/lib/types/knowledge.js +137 -60
  179. package/lib/types/knowledge.js.map +1 -1
  180. package/lib/types/layout.d.ts +10 -29
  181. package/lib/types/layout.d.ts.map +1 -1
  182. package/lib/types/layout.js +17 -36
  183. package/lib/types/layout.js.map +1 -1
  184. package/lib/types/materialize-snapshot.d.ts +49 -0
  185. package/lib/types/materialize-snapshot.d.ts.map +1 -0
  186. package/lib/types/materialize-snapshot.js +2 -0
  187. package/lib/types/materialize-snapshot.js.map +1 -0
  188. package/lib/types/migrate.d.ts +11 -0
  189. package/lib/types/migrate.d.ts.map +1 -1
  190. package/lib/types/migrate.js +83 -2
  191. package/lib/types/migrate.js.map +1 -1
  192. package/lib/types/model-text.d.ts +58 -1
  193. package/lib/types/model-text.d.ts.map +1 -1
  194. package/lib/types/model-text.js +85 -30
  195. package/lib/types/model-text.js.map +1 -1
  196. package/lib/types/oplog.d.ts.map +1 -1
  197. package/lib/types/oplog.js +7 -0
  198. package/lib/types/oplog.js.map +1 -1
  199. package/lib/types/organize-contract.d.ts +18 -0
  200. package/lib/types/organize-contract.d.ts.map +1 -0
  201. package/lib/types/organize-contract.js +82 -0
  202. package/lib/types/organize-contract.js.map +1 -0
  203. package/lib/types/pipeline/engine.d.ts +66 -0
  204. package/lib/types/pipeline/engine.d.ts.map +1 -0
  205. package/lib/types/pipeline/engine.js +352 -0
  206. package/lib/types/pipeline/engine.js.map +1 -0
  207. package/lib/types/pipeline/store.d.ts +73 -0
  208. package/lib/types/pipeline/store.d.ts.map +1 -0
  209. package/lib/types/pipeline/store.js +143 -0
  210. package/lib/types/pipeline/store.js.map +1 -0
  211. package/lib/types/pipeline/types.d.ts +102 -0
  212. package/lib/types/pipeline/types.d.ts.map +1 -0
  213. package/lib/types/pipeline/types.js +5 -0
  214. package/lib/types/pipeline/types.js.map +1 -0
  215. package/lib/types/present.d.ts +2 -0
  216. package/lib/types/present.d.ts.map +1 -1
  217. package/lib/types/present.js +9 -4
  218. package/lib/types/present.js.map +1 -1
  219. package/lib/types/preset-ids.d.ts +4 -0
  220. package/lib/types/preset-ids.d.ts.map +1 -0
  221. package/lib/types/preset-ids.js +6 -0
  222. package/lib/types/preset-ids.js.map +1 -0
  223. package/lib/types/query-analysis.d.ts +13 -1
  224. package/lib/types/query-analysis.d.ts.map +1 -1
  225. package/lib/types/query-analysis.js +62 -6
  226. package/lib/types/query-analysis.js.map +1 -1
  227. package/lib/types/recall-rank.d.ts +3 -3
  228. package/lib/types/recall-rank.d.ts.map +1 -1
  229. package/lib/types/recall-rank.js +4 -4
  230. package/lib/types/recall-rank.js.map +1 -1
  231. package/lib/types/retention.d.ts +39 -0
  232. package/lib/types/retention.d.ts.map +1 -0
  233. package/lib/types/retention.js +42 -0
  234. package/lib/types/retention.js.map +1 -0
  235. package/lib/types/retrieval/vector-index.d.ts +32 -0
  236. package/lib/types/retrieval/vector-index.d.ts.map +1 -0
  237. package/lib/types/retrieval/vector-index.js +15 -0
  238. package/lib/types/retrieval/vector-index.js.map +1 -0
  239. package/lib/types/retrieval/visibility.d.ts +6 -0
  240. package/lib/types/retrieval/visibility.d.ts.map +1 -0
  241. package/lib/types/retrieval/visibility.js +11 -0
  242. package/lib/types/retrieval/visibility.js.map +1 -0
  243. package/lib/types/runtime.d.ts +272 -27
  244. package/lib/types/runtime.d.ts.map +1 -1
  245. package/lib/types/runtime.js +2751 -537
  246. package/lib/types/runtime.js.map +1 -1
  247. package/lib/types/settings-schema.d.ts +17 -15
  248. package/lib/types/settings-schema.d.ts.map +1 -1
  249. package/lib/types/settings-schema.js +50 -47
  250. package/lib/types/settings-schema.js.map +1 -1
  251. package/lib/types/settings-volatile.d.ts +4 -4
  252. package/lib/types/settings-volatile.js +4 -4
  253. package/lib/types/source-evidence.d.ts +14 -0
  254. package/lib/types/source-evidence.d.ts.map +1 -0
  255. package/lib/types/source-evidence.js +36 -0
  256. package/lib/types/source-evidence.js.map +1 -0
  257. package/lib/types/store/axis-references.d.ts +5 -0
  258. package/lib/types/store/axis-references.d.ts.map +1 -0
  259. package/lib/types/store/axis-references.js +106 -0
  260. package/lib/types/store/axis-references.js.map +1 -0
  261. package/lib/types/store/derived.d.ts +12 -1
  262. package/lib/types/store/derived.d.ts.map +1 -1
  263. package/lib/types/store/derived.js +71 -12
  264. package/lib/types/store/derived.js.map +1 -1
  265. package/lib/types/store/knowledge-db.d.ts +31 -1
  266. package/lib/types/store/knowledge-db.d.ts.map +1 -1
  267. package/lib/types/store/knowledge-db.js +252 -18
  268. package/lib/types/store/knowledge-db.js.map +1 -1
  269. package/lib/types/store/migrate.d.ts.map +1 -1
  270. package/lib/types/store/migrate.js +17 -6
  271. package/lib/types/store/migrate.js.map +1 -1
  272. package/lib/types/trajectory-types.d.ts +172 -0
  273. package/lib/types/trajectory-types.d.ts.map +1 -0
  274. package/lib/types/trajectory-types.js +36 -0
  275. package/lib/types/trajectory-types.js.map +1 -0
  276. package/lib/types/types.d.ts +59 -27
  277. package/lib/types/types.d.ts.map +1 -1
  278. package/lib/types/types.js +6 -15
  279. package/lib/types/types.js.map +1 -1
  280. package/lib/types/wiki-finalize.d.ts +16 -0
  281. package/lib/types/wiki-finalize.d.ts.map +1 -1
  282. package/lib/types/wiki-finalize.js +26 -0
  283. package/lib/types/wiki-finalize.js.map +1 -1
  284. package/lib/types/wiki-materialize.d.ts +4 -0
  285. package/lib/types/wiki-materialize.d.ts.map +1 -1
  286. package/lib/types/wiki-materialize.js +21 -7
  287. package/lib/types/wiki-materialize.js.map +1 -1
  288. package/lib/types/wiki-trial-types.d.ts +87 -0
  289. package/lib/types/wiki-trial-types.d.ts.map +1 -1
  290. package/lib/types/wiki-trial-types.js +0 -16
  291. package/lib/types/wiki-trial-types.js.map +1 -1
  292. package/lib/types/wiki-trial.d.ts +40 -16
  293. package/lib/types/wiki-trial.d.ts.map +1 -1
  294. package/lib/types/wiki-trial.js +337 -224
  295. package/lib/types/wiki-trial.js.map +1 -1
  296. package/package.json +29 -20
  297. package/python/prepare-models.py +19 -0
  298. package/python/requirements.txt +8 -6
  299. package/scripts/doctor.mjs +13 -19
  300. package/scripts/environment.mjs +29 -0
  301. package/scripts/setup-embedding.sh +15 -5
  302. package/src/agent-behavior-rules.ts +37 -0
  303. package/src/axis-registry.ts +234 -27
  304. package/src/card-organize.ts +69 -75
  305. package/src/client/AgentBehaviorRulesCard.tsx +65 -0
  306. package/src/client/AttributionEventGuide.tsx +41 -39
  307. package/src/client/AxisRegistrySection.tsx +204 -164
  308. package/src/client/CompileDialogs.tsx +44 -29
  309. package/src/client/DeleteDocumentDialog.tsx +36 -5
  310. package/src/client/DirectoryPicker.tsx +0 -10
  311. package/src/client/EnvironmentSetup.tsx +243 -0
  312. package/src/client/ExpansionGraph.tsx +13 -7
  313. package/src/client/ExtractionTasksPage.tsx +578 -0
  314. package/src/client/GuideArchitectureCanvas.tsx +470 -0
  315. package/src/client/ImportFilesDialog.tsx +2 -13
  316. package/src/client/IntentLogic.tsx +2 -2
  317. package/src/client/IntentTab.tsx +118 -47
  318. package/src/client/KnowledgeBaseTab.tsx +277 -197
  319. package/src/client/KnowledgeLayerSection.tsx +24 -6
  320. package/src/client/KnowledgePanel.tsx +58 -93
  321. package/src/client/KnowledgeSettingsDrawer.tsx +90 -0
  322. package/src/client/ListPager.tsx +15 -5
  323. package/src/client/MaterializeTrajectoryView.tsx +124 -0
  324. package/src/client/NodeSettings.tsx +210 -89
  325. package/src/client/NormalizeTrajectoryView.tsx +136 -0
  326. package/src/client/PipelineNotice.tsx +26 -0
  327. package/src/client/PreviewSections.tsx +118 -51
  328. package/src/client/RecallPanel.tsx +89 -85
  329. package/src/client/TabGuide.tsx +159 -184
  330. package/src/client/TrialReportView.tsx +391 -214
  331. package/src/client/TypeDefinitionDrawer.tsx +150 -23
  332. package/src/client/WikiCardPreview.tsx +62 -16
  333. package/src/client/WikiFlowPanel.tsx +4 -4
  334. package/src/client/arch/NodeLogicPanel.tsx +3 -4
  335. package/src/client/arch/model.ts +6 -9
  336. package/src/client/architecture.tsx +23 -33
  337. package/src/client/attribution/AttributionGraph.tsx +10 -6
  338. package/src/client/attribution/AttributionTab.tsx +136 -84
  339. package/src/client/attribution/CaseView.tsx +3 -1
  340. package/src/client/attribution/EventView.tsx +108 -0
  341. package/src/client/attribution/RunView.tsx +2 -2
  342. package/src/client/attribution/StageChrome.tsx +34 -3
  343. package/src/client/attribution/ViewSwitch.tsx +20 -5
  344. package/src/client/attribution/graph-options.ts +47 -39
  345. package/src/client/attribution/model.ts +17 -10
  346. package/src/client/config-scope.ts +3 -3
  347. package/src/client/graph/palette.ts +165 -0
  348. package/src/client/index.ts +49 -42
  349. package/src/client/pages.css +459 -135
  350. package/src/client/pages.tsx +37 -9
  351. package/src/client/problem-domains.ts +1 -1
  352. package/src/client/session-remote.ts +9 -0
  353. package/src/client/styles.css +205 -62
  354. package/src/client/wiki-trial.ts +44 -3
  355. package/src/compiler/embedding-identity.ts +21 -0
  356. package/src/compiler/snapshot.ts +17 -0
  357. package/src/config-schema.ts +8 -3
  358. package/src/convert/host.ts +56 -21
  359. package/src/convert/ingest.ts +74 -10
  360. package/src/derive-contract.ts +14 -0
  361. package/src/diagnosis/cards.ts +13 -8
  362. package/src/diagnosis/run.ts +27 -17
  363. package/src/diagnosis/schema.ts +2 -2
  364. package/src/diagnosis/seed-source.ts +5 -4
  365. package/src/diagnosis/seed.ts +6 -8
  366. package/src/diagnosis/store.ts +138 -69
  367. package/src/diagnosis/types.ts +34 -15
  368. package/src/environment/dsh-python.ts +156 -0
  369. package/src/environment/install.ts +244 -0
  370. package/src/environment/manifest.ts +28 -0
  371. package/src/environment/model-catalog.ts +147 -0
  372. package/src/environment/process.ts +54 -0
  373. package/src/environment/selection.ts +29 -0
  374. package/src/environment/service.ts +348 -0
  375. package/src/environment/types.ts +45 -0
  376. package/src/events.ts +108 -0
  377. package/src/extract-contract.ts +42 -0
  378. package/src/extract-model.ts +10 -1
  379. package/src/extract-table-contract.ts +26 -0
  380. package/src/extract-table.ts +132 -0
  381. package/src/extraction-runs.ts +70 -11
  382. package/src/fs-atomic.ts +19 -2
  383. package/src/images.ts +203 -0
  384. package/src/index.ts +553 -205
  385. package/src/intent/README.md +8 -6
  386. package/src/intent/engine.ts +44 -6
  387. package/src/intent/host.ts +59 -18
  388. package/src/intent/scope.ts +125 -0
  389. package/src/intent/tools.ts +70 -28
  390. package/src/intent/types.ts +11 -4
  391. package/src/knowledge-bases.ts +56 -20
  392. package/src/knowledge-contract.ts +114 -0
  393. package/src/knowledge.ts +138 -69
  394. package/src/layout.ts +17 -37
  395. package/src/materialize-snapshot.ts +46 -0
  396. package/src/migrate.ts +75 -2
  397. package/src/model-text.ts +109 -4
  398. package/src/oplog.ts +7 -0
  399. package/src/organize-contract.ts +83 -0
  400. package/src/pipeline/engine.ts +323 -0
  401. package/src/pipeline/store.ts +147 -0
  402. package/src/pipeline/types.ts +93 -0
  403. package/src/present.ts +10 -4
  404. package/src/preset-ids.ts +6 -0
  405. package/src/python/embedding_worker.py +66 -2
  406. package/src/query-analysis.ts +68 -8
  407. package/src/recall-rank.ts +5 -5
  408. package/src/retention.ts +76 -0
  409. package/src/retrieval/vector-index.ts +45 -0
  410. package/src/retrieval/visibility.ts +14 -0
  411. package/src/runtime.ts +2708 -567
  412. package/src/settings-schema.ts +11 -8
  413. package/src/settings-volatile.ts +4 -4
  414. package/src/source-evidence.ts +37 -0
  415. package/src/store/axis-references.ts +96 -0
  416. package/src/store/derived.ts +70 -12
  417. package/src/store/knowledge-db.ts +248 -17
  418. package/src/store/migrate.ts +16 -6
  419. package/src/trajectory-types.ts +142 -0
  420. package/src/types.ts +61 -35
  421. package/src/wiki-finalize.ts +28 -0
  422. package/src/wiki-materialize.ts +25 -6
  423. package/src/wiki-trial-types.ts +83 -1
  424. package/src/wiki-trial.ts +357 -185
  425. package/lib/types/intent/preset-tools.d.ts +0 -37
  426. package/lib/types/intent/preset-tools.d.ts.map +0 -1
  427. package/lib/types/intent/preset-tools.js +0 -45
  428. package/lib/types/intent/preset-tools.js.map +0 -1
  429. package/preset/tita-data-agent/agent.cordis.yml +0 -394
  430. package/preset/tita-data-agent/preset.yml +0 -3
  431. package/scripts/install-agent-preset.mjs +0 -92
  432. package/scripts/sync-agent-preset.mjs +0 -188
  433. package/src/client/AgentPresetCard.tsx +0 -247
  434. package/src/client/agent-preset.ts +0 -121
  435. package/src/client/convert/ConvertPanel.tsx +0 -583
  436. package/src/client/convert/styles.css +0 -138
  437. package/src/client/convert/styles.ts +0 -49
  438. package/src/intent/preset-tools.ts +0 -48
@@ -283,6 +283,45 @@ def encode_multimodal(model_wrapper: Any, items: list[dict[str, Any]], device: s
283
283
  return outputs
284
284
 
285
285
 
286
+ def text_windows(tokenizer, text: str, budget: int, overlap: int = 48) -> list[str]:
287
+ """Physical windows only. The host retains the complete logical H2 section."""
288
+ ids = tokenizer.encode(text, add_special_tokens=False)
289
+ if len(ids) <= budget:
290
+ return [text]
291
+ step = max(1, budget - min(overlap, budget // 4))
292
+ windows = []
293
+ for start in range(0, len(ids), step):
294
+ windows.append(tokenizer.decode(ids[start:start + budget], skip_special_tokens=True))
295
+ if start + budget >= len(ids):
296
+ break
297
+ return windows
298
+
299
+
300
+ def embedding_tokenizer(model):
301
+ if has_official_path(model):
302
+ tokenizer = getattr(model[0].processor, "tokenizer", None)
303
+ else:
304
+ tokenizer = getattr(model, "tokenizer", None)
305
+ if tokenizer is None:
306
+ raise RuntimeError("EMBEDDING_TOKENIZER_UNAVAILABLE")
307
+ return tokenizer
308
+
309
+
310
+ def split_inputs(request: dict[str, Any]) -> dict[str, Any]:
311
+ model, _ = cached_model(str(request["model"]), str(request.get("device") or "auto"))
312
+ tokenizer = embedding_tokenizer(model)
313
+ limit = min(int(getattr(model, "max_seq_length", 512) or 512), 512)
314
+ windows = []
315
+ for item in request.get("inputs", []):
316
+ prefix = str(item.get("prefix") or "")
317
+ prefix_size = len(tokenizer.encode(prefix, add_special_tokens=False))
318
+ budget = limit - prefix_size - 16
319
+ if budget < 64:
320
+ raise ValueError("EMBEDDING_SECTION_TITLE_TOO_LONG")
321
+ windows.append([prefix + "\n\n" + part for part in text_windows(tokenizer, str(item.get("text") or ""), budget)])
322
+ return {"ok": True, "windows": windows, "tokenLimit": limit}
323
+
324
+
286
325
  def encode(request: dict[str, Any]) -> dict[str, Any]:
287
326
  model_name = str(request.get("model") or "ewin-reg/WeMM-Embedding-2B-Quantized")
288
327
  requested_device = str(request.get("device") or "auto")
@@ -334,6 +373,9 @@ def encode(request: dict[str, Any]) -> dict[str, Any]:
334
373
  str(item.get("text") or "") if isinstance(item, dict) else str(item)
335
374
  for item in batch
336
375
  ]
376
+ limit = int(getattr(model, "max_seq_length", 512) or 512)
377
+ if any(len(model.tokenizer.encode(text, add_special_tokens=True)) > limit for text in generic_batch):
378
+ raise ValueError("EMBEDDING_INPUT_TOO_LONG: split H2 text or shorten the current subquestion")
337
379
  encoded = model.encode(
338
380
  generic_batch,
339
381
  batch_size=batch_size,
@@ -454,9 +496,29 @@ def rerank(request: dict[str, Any]) -> dict[str, Any]:
454
496
  if not isinstance(documents, list) or not documents:
455
497
  raise ValueError("rerank requires a non-empty documents array")
456
498
  model, device, health = cached_reranker(model_name, requested_device)
457
- pairs = [(query, str(document)) for document in documents]
499
+ tokenizer = model.tokenizer
500
+ limit = min(int(getattr(model, "max_length", 512) or 512), 512)
501
+ query_size = len(tokenizer.encode(query, add_special_tokens=False))
502
+ budget = limit - query_size - 16
503
+ if budget < 64:
504
+ raise ValueError("RERANK_QUERY_TOO_LONG: shorten the current subquestion")
505
+ pairs = []
506
+ owners = []
507
+ for owner, document in enumerate(documents):
508
+ title, separator, body = str(document).partition("\n\n")
509
+ prefix = title + "\n\n" if separator else ""
510
+ content = body if separator else title
511
+ document_budget = budget - len(tokenizer.encode(prefix, add_special_tokens=False))
512
+ if document_budget < 32:
513
+ raise ValueError("RERANK_SECTION_TITLE_TOO_LONG")
514
+ for window in text_windows(tokenizer, content, document_budget):
515
+ pairs.append((query, prefix + window))
516
+ owners.append(owner)
458
517
  with redirect_stdout(sys.stderr):
459
- scores = predict_raw(model, pairs)
518
+ raw_scores = predict_raw(model, pairs)
519
+ scores = [float("-inf")] * len(documents)
520
+ for owner, score in zip(owners, raw_scores):
521
+ scores[owner] = max(scores[owner], float(score))
460
522
  return {
461
523
  "ok": True,
462
524
  "device": device,
@@ -476,6 +538,8 @@ def main() -> None:
476
538
  # selects the path and both models are cached per process.
477
539
  if str(request.get("task") or "") == "rerank":
478
540
  emit(rerank(request))
541
+ elif str(request.get("task") or "") == "split":
542
+ emit(split_inputs(request))
479
543
  else:
480
544
  emit(encode(request))
481
545
  except Exception as exc: # return machine-readable errors to the Host
@@ -1,4 +1,4 @@
1
- import type { AxisEntity, AxisKind } from './axis-registry.js'
1
+ import type { AxisEntity, AxisKind, AxisRelation } from './axis-registry.js'
2
2
  import { normalizeAxisName } from './axis-registry.js'
3
3
  import type { CardCoordinate } from './types.js'
4
4
 
@@ -20,6 +20,14 @@ export interface QueryCoordinateCandidate {
20
20
  matchedAxes: AxisKind[]
21
21
  }
22
22
 
23
+ export interface QueryRelationCandidate extends QueryCoordinateCandidate {
24
+ relationId: string
25
+ relationType: 'related_to'
26
+ matchedObjectId: string
27
+ relatedObjectId: string
28
+ evidence: string
29
+ }
30
+
23
31
  export interface QueryAnalysis {
24
32
  query: string
25
33
  intent: { id: QueryIntent; confidence: number }
@@ -92,10 +100,11 @@ function coordinateCandidates(
92
100
  axes: Record<AxisKind, QueryAxisMatch[]>,
93
101
  cards: CoordinateCard[],
94
102
  ): QueryCoordinateCandidate[] {
95
- const byKind: Record<AxisKind, Map<string, QueryAxisMatch>> = {
96
- object: new Map(axes.object.map(item => [item.id, item])),
97
- action: new Map(axes.action.map(item => [item.id, item])),
98
- scene: new Map(axes.scene.map(item => [item.id, item])),
103
+ const byKind: Record<AxisKind, Map<string, number>> = {
104
+ object: new Map(), action: new Map(), scene: new Map(),
105
+ }
106
+ for (const kind of ['object', 'action', 'scene'] as const) {
107
+ for (const match of axes[kind]) byKind[kind].set(match.id, match.confidence)
99
108
  }
100
109
  const fields: Array<[AxisKind, keyof CardCoordinate]> = [
101
110
  ['object', 'objectId'], ['action', 'actionId'], ['scene', 'sceneId'],
@@ -105,10 +114,10 @@ function coordinateCandidates(
105
114
  const matchedAxes: AxisKind[] = []
106
115
  let score = 0
107
116
  for (const [kind, field] of fields) {
108
- const match = byKind[kind].get(card.coordinate[field])
109
- if (match === undefined) continue
117
+ const confidence = byKind[kind].get(card.coordinate[field])
118
+ if (confidence === undefined) continue
110
119
  matchedAxes.push(kind)
111
- score += match.confidence
120
+ score += confidence
112
121
  }
113
122
  if (matchedAxes.length === 0) return []
114
123
  // 匹配多个轴的卡片优先,但只匹配一个轴也要可召回,不能硬过滤。
@@ -117,6 +126,57 @@ function coordinateCandidates(
117
126
  }).sort((left, right) => right.score - left.score || left.cardKey.localeCompare(right.cardKey))
118
127
  }
119
128
 
129
+ /**
130
+ * 一跳 related_to 关系候选。关系只拓展对象轴,不把 scopeId 当层级;
131
+ * 关联候选进入独立召回路,后续仍由多路融合与重排判断相关性。
132
+ */
133
+ export function relationCandidates(
134
+ analysis: QueryAnalysis,
135
+ relations: AxisRelation[],
136
+ cards: CoordinateCard[],
137
+ ): QueryRelationCandidate[] {
138
+ const matchedObjects = analysis.axes.object
139
+ if (matchedObjects.length === 0 || relations.length === 0) return []
140
+ const matchedById = new Map(matchedObjects.map(item => [item.id, item]))
141
+ const related = new Map<string, { matchedObjectId: string; score: number; relation: AxisRelation }>()
142
+ for (const relation of relations) {
143
+ if (relation.relationType !== 'related_to') continue
144
+ const left = matchedById.get(relation.fromId)
145
+ const right = matchedById.get(relation.toId)
146
+ if (left !== undefined && right !== undefined) continue
147
+ const matched = left ?? right
148
+ if (matched === undefined) continue
149
+ const relatedObjectId = left ? relation.toId : relation.fromId
150
+ if (matched.id === relatedObjectId) continue
151
+ const score = matched.confidence * 0.65
152
+ const previous = related.get(relatedObjectId)
153
+ if (previous === undefined || score > previous.score) {
154
+ related.set(relatedObjectId, { matchedObjectId: matched.id, score, relation })
155
+ }
156
+ }
157
+ const byCard = new Map<string, QueryRelationCandidate>()
158
+ for (const card of cards) {
159
+ const relatedObjectId = card.coordinate?.objectId
160
+ if (!relatedObjectId) continue
161
+ const match = related.get(relatedObjectId)
162
+ if (match === undefined) continue
163
+ const candidate: QueryRelationCandidate = {
164
+ cardKey: card.cardKey,
165
+ coordinate: card.coordinate!,
166
+ score: match.score,
167
+ matchedAxes: ['object'],
168
+ relationId: match.relation.id,
169
+ relationType: match.relation.relationType,
170
+ matchedObjectId: match.matchedObjectId,
171
+ relatedObjectId,
172
+ evidence: match.relation.evidence,
173
+ }
174
+ const previous = byCard.get(card.cardKey)
175
+ if (previous === undefined || candidate.score > previous.score) byCard.set(card.cardKey, candidate)
176
+ }
177
+ return [...byCard.values()].sort((left, right) => right.score - left.score || left.cardKey.localeCompare(right.cardKey))
178
+ }
179
+
120
180
  export function analyzeQuery(query: string, entities: RegistryEntity[], cards: CoordinateCard[]): QueryAnalysis {
121
181
  const axes: Record<AxisKind, QueryAxisMatch[]> = {
122
182
  object: matchEntities(query, 'object', entities),
@@ -34,8 +34,8 @@ export interface RrfOptions {
34
34
  /**
35
35
  * 名次级融合(Reciprocal Rank Fusion)。
36
36
  *
37
- * **为什么不用分数加权和**:三路的分数是三个不同的量纲 —— 关键词是归一化 BM25、
38
- * 向量是余弦、图谱是命中分/最大命中分。把它们乘权重相加,等于假设「0.5 的关键词分」
37
+ * **为什么不用分数加权和**:四路的分数来自不同刻度 —— 关键词是归一化 BM25、
38
+ * 向量是余弦、坐标与关系路是解析置信分。把它们乘权重相加,等于假设「0.5 的关键词分」
39
39
  * 与「0.5 的余弦」一样好,而这个假设没有任何依据。0030 的实际后果就是:向量路输出
40
40
  * 常数时,hybrid 的 55% 权重全是噪声,排序退化成 `unitId` 字典序(实测 4 条命中
41
41
  * 分数完全相同:`0.2753 = 0.5 × 0.55`)。
@@ -47,7 +47,7 @@ export function rrfFuse(rankings: Partial<Record<RecallRoute, RouteRanking[]>>,
47
47
  const { k, weights } = options
48
48
  const ranks = new Map<string, Partial<Record<RecallRoute, number>>>()
49
49
  const scores = new Map<string, number>()
50
- const order: RecallRoute[] = ['coordinate', 'fts', 'vector', 'graph']
50
+ const order: RecallRoute[] = ['coordinate', 'relation', 'fts', 'vector', 'graph']
51
51
  for (const route of order) {
52
52
  const list = rankings[route]
53
53
  if (!list || list.length === 0) continue
@@ -260,8 +260,8 @@ export function selectContext<T>(items: T[], options: MmrOptions<T>): T[] {
260
260
  }
261
261
 
262
262
  /** `match` 字段由名次推导:多个候选路命中 = hybrid。 */
263
- export function matchOf(ranks: Partial<Record<RecallRoute, number>>): 'fts' | 'vector' | 'coordinate' | 'graph' | 'hybrid' {
264
- const used = (['coordinate', 'fts', 'vector', 'graph'] as RecallRoute[]).filter(route => ranks[route] !== undefined)
263
+ export function matchOf(ranks: Partial<Record<RecallRoute, number>>): 'fts' | 'vector' | 'coordinate' | 'relation' | 'graph' | 'hybrid' {
264
+ const used = (['coordinate', 'relation', 'fts', 'vector', 'graph'] as RecallRoute[]).filter(route => ranks[route] !== undefined)
265
265
  if (used.length >= 2) return 'hybrid'
266
266
  return used[0] ?? 'fts'
267
267
  }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * 保留上限(0070)。
3
+ *
4
+ * 文档里写着保留策略(「命名永久 + 最近 100 + 每日末版;机器版本只活到硬上限」),
5
+ * 而代码里对这几张表一条 `DELETE` 都没有:`revision` / `blob` / `tree` / `operations` /
6
+ * `pipeline_extractions` / `pipeline_events` 只增不减。这个模块把**新数据**的上限补上。
7
+ *
8
+ * ## 为什么是「水位 + 上限」,而不是直接按条数删
9
+ *
10
+ * 上限一旦生效,第一次裁剪就会把库里**已有的**历史删掉 —— 那是不可逆的,而用户的决定是
11
+ * 「只对新数据加上限,不动存量」。所以每张表第一次裁剪时先把当前最大键记成**水位**:
12
+ * 水位以下的既有行永不删除;水位以上的新行按上限保留。代价是总量变成
13
+ * 「升级那一刻的存量 + 上限」,而不是「上限」—— 这是「不动存量」能给出的最强的界。
14
+ *
15
+ * ## 键列的要求
16
+ *
17
+ * `key` 必须是单调递增的整数列(`rowid` 或自增 `seq`)。用时间戳当键不行:同一毫秒里
18
+ * 两行的顺序不确定,裁剪会随机丢一行。
19
+ */
20
+ import type { SqliteDatabase } from './fts.js'
21
+
22
+ export interface RetentionSpec {
23
+ /** 表名。内插进 SQL,所以调用方只能传常量。 */
24
+ table: string
25
+ /** 单调递增的整数键列,例如 `rowid` 或 `seq`。 */
26
+ key: string
27
+ /** 水位以上保留多少行;`0` 表示水位以上的匹配行全部删掉(用于回收无引用的 blob)。 */
28
+ keep: number
29
+ /** 额外的行条件(可含子查询)。同样只允许常量 SQL。 */
30
+ where?: string
31
+ /** 分组表达式:给了就是「每组保留 keep 行」,而不是全表保留。 */
32
+ groupBy?: string
33
+ }
34
+
35
+ /** 水位表的表名。它跟着所在的那个库走(审计库与 knowledge.db 各有一份)。 */
36
+ const FLOOR_TABLE = 'retention_floor'
37
+
38
+ function ensureFloors(db: SqliteDatabase): void {
39
+ db.exec(`CREATE TABLE IF NOT EXISTS ${FLOOR_TABLE} (name TEXT PRIMARY KEY, floor INTEGER NOT NULL, at TEXT NOT NULL)`)
40
+ }
41
+
42
+ function floorOf(db: SqliteDatabase, name: string, table: string, key: string): number {
43
+ const row = db.prepare(`SELECT floor FROM ${FLOOR_TABLE} WHERE name = ?`).get(name) as { floor?: unknown } | undefined
44
+ if (row !== undefined) return Number(row.floor ?? 0)
45
+ const max = Number((db.prepare(`SELECT COALESCE(MAX(${key}), 0) AS m FROM ${table}`).get() as { m?: unknown } | undefined)?.m ?? 0)
46
+ db.prepare(`INSERT OR IGNORE INTO ${FLOOR_TABLE}(name, floor, at) VALUES (?, ?, ?)`).run(name, max, new Date().toISOString())
47
+ return max
48
+ }
49
+
50
+ /**
51
+ * 裁掉水位以上的超限行,返回删掉的行数。
52
+ *
53
+ * 幂等且可反复调用:没有超限时最多花一次索引区间计数。
54
+ */
55
+ export function applyRetention(db: SqliteDatabase, name: string, spec: RetentionSpec): number {
56
+ ensureFloors(db)
57
+ const floor = floorOf(db, name, spec.table, spec.key)
58
+ const filter = spec.where === undefined ? '' : ` AND (${spec.where})`
59
+ const above = Number((db.prepare(`SELECT COUNT(*) AS n FROM ${spec.table} WHERE ${spec.key} > ?${filter}`).get(floor) as { n?: unknown } | undefined)?.n ?? 0)
60
+ if (above <= spec.keep) return 0
61
+ if (spec.groupBy === undefined) {
62
+ const changes = spec.keep <= 0
63
+ ? db.prepare(`DELETE FROM ${spec.table} WHERE ${spec.key} > ?${filter}`).run(floor)
64
+ : db.prepare(`DELETE FROM ${spec.table} WHERE ${spec.key} > ? AND ${spec.key} < (
65
+ SELECT ${spec.key} FROM ${spec.table} WHERE ${spec.key} > ?${filter} ORDER BY ${spec.key} DESC LIMIT 1 OFFSET ?
66
+ )${filter}`).run(floor, floor, spec.keep - 1)
67
+ return Number((changes as { changes?: unknown })?.changes ?? 0)
68
+ }
69
+ const changes = db.prepare(`DELETE FROM ${spec.table} WHERE ${spec.key} IN (
70
+ SELECT ${spec.key} FROM (
71
+ SELECT ${spec.key}, ROW_NUMBER() OVER (PARTITION BY ${spec.groupBy} ORDER BY ${spec.key} DESC) AS rn
72
+ FROM ${spec.table} WHERE ${spec.key} > ?${filter}
73
+ ) WHERE rn > ?
74
+ )`).run(floor, spec.keep)
75
+ return Number((changes as { changes?: unknown })?.changes ?? 0)
76
+ }
@@ -0,0 +1,45 @@
1
+ import type { KnowledgeConfig } from '../types.js'
2
+ import type { DerivedDb } from '../store/derived.js'
3
+
4
+ export interface VectorItem {
5
+ unitId: string
6
+ parentUnitId?: string
7
+ contentHash: string
8
+ }
9
+
10
+ export interface VectorManifest {
11
+ version: number
12
+ createdAt: string
13
+ provider: KnowledgeConfig['embeddingProvider']
14
+ model: string
15
+ modelFingerprint?: string
16
+ /**
17
+ * 编码实现的指纹(0031)。旧清单没有这个字段 → 视为不兼容,于是修复编码器之后
18
+ * 一定触发一次真正的重编码,而不是把旧向量按 contentHash 复用回来。
19
+ */
20
+ encoder?: string
21
+ device: string
22
+ dimension: number
23
+ quantization: 'binary+hamming+int8'
24
+ itemCount: number
25
+ items: VectorItem[]
26
+ }
27
+
28
+ export interface LoadedVectorIndex {
29
+ manifest: VectorManifest
30
+ binary: Buffer
31
+ int8: Buffer
32
+ }
33
+
34
+ /** Validate a generation's BLOBs before either reuse or query. */
35
+ export function decodeVectorIndex(loaded: ReturnType<DerivedDb['vectorIndex']>, encoder: string): LoadedVectorIndex | null {
36
+ if (!loaded) return null
37
+ const manifest = loaded.manifest as VectorManifest
38
+ if (!manifest || manifest.quantization !== 'binary+hamming+int8' || manifest.encoder !== encoder
39
+ || !Number.isInteger(manifest.dimension) || manifest.dimension < 8 || manifest.dimension % 8 !== 0
40
+ || !Number.isInteger(manifest.itemCount) || !Array.isArray(manifest.items)
41
+ || manifest.itemCount !== manifest.items.length
42
+ || loaded.binary.length !== manifest.itemCount * Math.ceil(manifest.dimension / 8)
43
+ || loaded.int8.length !== manifest.itemCount * manifest.dimension) return null
44
+ return { ...loaded, manifest }
45
+ }
@@ -0,0 +1,14 @@
1
+ import type { ContextGraph } from '../types.js'
2
+ import type { KnowledgeDb } from '../store/knowledge-db.js'
3
+
4
+ export function liveGraphKeys(db: KnowledgeDb): Set<string> {
5
+ const rows = db.raw("SELECT entity_type AS type, entity_id AS id FROM card UNION SELECT 'source' AS type, entity_id AS id FROM source").all() as Array<{ type: string; id: string }>
6
+ return new Set(rows.map(row => `${row.type}:${row.id}`))
7
+ }
8
+
9
+ /** A retained generation must not restore entities that the user deleted. */
10
+ export function visibleGraph(graph: ContextGraph, live: Set<string>): ContextGraph {
11
+ const nodes = graph.nodes.filter(node => live.has(`${node.type}:${node.id}`))
12
+ const keys = new Set(nodes.map(node => `${node.type}:${node.id}`))
13
+ return { nodes, edges: graph.edges.filter(edge => keys.has(String(edge.from)) && keys.has(String(edge.to))) }
14
+ }