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
@@ -11,8 +11,8 @@
11
11
  * 挑一个目录 —— 见 `layout.ts` 的三条原理。
12
12
  *
13
13
  * 注册表本身只持久化**配置**(id / name / description / rootDir),
14
- * 落到 `<dataHome>/knowledge-bases.json`,`dataHome =
15
- * process.env.TITA_DATA_AGENT_HOME || ~/.tita-data-agent`。
14
+ * 落到 `<agentRoot>/resource/knowledge-bases.json`。插件运行时会显式传入这个注册表
15
+ * 位置;没有传入时也使用固定的 DSH/Tita Agent 目录,不再回退到旧的用户目录。
16
16
  * `sourceCount` / `cardCount` / `noteCount` / `buildVersion` 都是**计算字段**,缓存在同一个 JSON 里,由 `refresh()` 从真实
17
17
  * runtime 重新统计;这样 `list()` / `get()` 保持同步签名(前端首屏直接用),
18
18
  * 路由在返回前 `await refresh()` 拿到准确值。
@@ -24,13 +24,13 @@
24
24
 
25
25
  import { existsSync, readFileSync } from 'node:fs'
26
26
  import { mkdir, rename, unlink, writeFile } from 'node:fs/promises'
27
- import { homedir } from 'node:os'
28
27
  import { dirname, join, resolve } from 'node:path'
29
28
  import {
30
- type Envelope, type KnowledgeBase, type KnowledgeConfig,
29
+ DEFAULT_COMPILE_MODEL, type CompileModelSelection, type Envelope, type KnowledgeBase, type KnowledgeConfig,
31
30
  } from './types.js'
32
31
  import { defaultKnowledgeRoot, failure, KnowledgeRuntime, success, type KnowledgeRuntimeOptions } from './runtime.js'
33
- import { knowledgeBaseRoot, memoryRoot } from './layout.js'
32
+ import { defaultAgentRoot, knowledgeBaseRoot, memoryRoot, resourceRoot } from './layout.js'
33
+ import { writeTextAtomic } from './fs-atomic.js'
34
34
 
35
35
  /** 持久化形态:配置 + 计算字段缓存分区。 */
36
36
  interface KnowledgeBaseRecord {
@@ -47,6 +47,8 @@ interface KnowledgeBaseRecord {
47
47
  * 这个库自己的判断。
48
48
  */
49
49
  extractionNote: string
50
+ /** 编译模型路由;它是注册表配置,不属于知识正文。 */
51
+ compileModel: CompileModelSelection
50
52
  createdAt: string
51
53
  updatedAt: string
52
54
  }
@@ -69,7 +71,7 @@ interface BaseStats {
69
71
  export const DEFAULT_KB_ID = 'default'
70
72
 
71
73
  export interface KnowledgeBasesOptions {
72
- /** 覆盖 `~/.tita-data-agent`;测试用临时目录,避免写用户主目录。 */
74
+ /** 注册表的备用数据目录;生产运行时使用 `registryFile` 指向 Agent 的 resource。 */
73
75
  dataHome?: string
74
76
  /** 默认库的根目录来源;插件传入由 `agentRoot` 推出来的那一格。 */
75
77
  defaultRootDir?: () => string
@@ -96,7 +98,7 @@ export interface KnowledgeBasesOptions {
96
98
  * `index.ts` 里直接 new),新建的库一律退回规则抽取:正文按 `##` 小节切,
97
99
  * 界面上只留一句「运行时没有注入模型接缝」。这跟写库 id 无关,纯粹是构造点漏了。
98
100
  */
99
- runtimeOptions?: () => Partial<KnowledgeRuntimeOptions>
101
+ runtimeOptions?: (baseId: string) => Partial<KnowledgeRuntimeOptions>
100
102
  /**
101
103
  * 覆盖注册表文件位置(默认 `<dataHome>/knowledge-bases.json`)。
102
104
  *
@@ -115,6 +117,17 @@ function textOr(input: unknown, fallback: string): string {
115
117
  return typeof input === 'string' && input.trim() ? input.trim() : fallback
116
118
  }
117
119
 
120
+ function compileModelOf(input: unknown): CompileModelSelection {
121
+ const value = record(input)
122
+ const effort = typeof value.reasoningEffort === 'string' && value.reasoningEffort.trim() ? { reasoningEffort: value.reasoningEffort.trim() } : {}
123
+ if (value.mode !== 'fixed') return { ...DEFAULT_COMPILE_MODEL, ...effort }
124
+ const provider = typeof value.provider === 'string' ? value.provider.trim() : ''
125
+ const model = typeof value.model === 'string' ? value.model.trim() : ''
126
+ // 旧版本没有这个字段,或留下了半截配置时,安全地回到 DSH 默认模型。
127
+ if (!provider || !model) return { ...DEFAULT_COMPILE_MODEL }
128
+ return { mode: 'fixed', provider, model, ...effort }
129
+ }
130
+
118
131
  function normalizeExt(value: unknown, fallback: string): string {
119
132
  const text = typeof value === 'string' ? value.trim().toLowerCase() : ''
120
133
  const ext = text || fallback
@@ -126,22 +139,13 @@ function emptyBase(id: string): KnowledgeBase {
126
139
  return {
127
140
  id, name: id, description: '', rootDir: '', isDefault: false,
128
141
  extractionNote: '',
142
+ compileModel: { ...DEFAULT_COMPILE_MODEL },
129
143
  createdAt: '', updatedAt: '', sourceCount: 0, cardCount: 0, noteCount: 0, buildVersion: 0,
130
144
  }
131
145
  }
132
146
 
133
- async function writeTextAtomic(path: string, content: string): Promise<void> {
134
- const temporary = `${path}.${process.pid}.${Date.now().toString(36)}.tmp`
135
- try {
136
- await writeFile(temporary, content, 'utf8')
137
- await rename(temporary, path)
138
- } finally {
139
- try { await unlink(temporary) } catch { /* rename already consumed it */ }
140
- }
141
- }
142
-
143
147
  export function defaultDataHome(): string {
144
- return resolve(process.env.TITA_DATA_AGENT_HOME || join(homedir(), '.tita-data-agent'))
148
+ return resourceRoot(defaultAgentRoot())
145
149
  }
146
150
 
147
151
  export class KnowledgeBases {
@@ -243,7 +247,7 @@ export class KnowledgeBases {
243
247
  // 逻辑的单元测试)留空,runtime 会退回知识树里的 `04_memory`。
244
248
  ...(this.options.agentRoot ? { memoryRoot: memoryRoot(this.options.agentRoot(), base.id) } : {}),
245
249
  // 0044:宿主级能力(模型接缝)必须一起带过来,否则非默认库静默退回规则抽取。
246
- ...(this.options.runtimeOptions?.() ?? {}),
250
+ ...(this.options.runtimeOptions?.(base.id) ?? {}),
247
251
  })
248
252
  runtime.baseId = base.id
249
253
  this.runtimes.set(key, runtime)
@@ -268,6 +272,15 @@ export class KnowledgeBases {
268
272
  this.runtimes.clear()
269
273
  }
270
274
 
275
+ /** Volatile settings apply to every cached base, including non-default bases. */
276
+ updateRuntimeConfig(config: Partial<import('./types.js').RuntimeKnowledgeConfig>): void {
277
+ for (const runtime of this.runtimes.values()) runtime.updateConfig(config)
278
+ }
279
+
280
+ reloadResources(): void {
281
+ for (const runtime of this.runtimes.values()) runtime.reloadResources()
282
+ }
283
+
271
284
  // ------------------------------------------------------------- 统计刷新
272
285
 
273
286
  /**
@@ -324,6 +337,7 @@ export class KnowledgeBases {
324
337
  rootDir,
325
338
  isDefault: false,
326
339
  extractionNote: '',
340
+ compileModel: { ...DEFAULT_COMPILE_MODEL },
327
341
  createdAt: now,
328
342
  updatedAt: now,
329
343
  }
@@ -337,12 +351,23 @@ export class KnowledgeBases {
337
351
  * 更新名称 / 描述 / 坐标提取备注。
338
352
  *
339
353
  */
340
- async update(id: string, patch: { name?: string; description?: string; extractionNote?: string }): Promise<Envelope<KnowledgeBase>> {
354
+ async update(id: string, patch: { name?: string; description?: string; extractionNote?: string; compileModel?: CompileModelSelection }): Promise<Envelope<KnowledgeBase>> {
341
355
  this.ensureLoaded()
342
356
  const base = this.records.find(item => item.id === id)
343
357
  if (!base) return failure(emptyBase(id), 'BASE_NOT_FOUND', `知识库不存在: ${id}`, true)
344
358
  // 守卫必须基于精确的实时计数,不能用可能过期的缓存。
345
359
  await this.refreshOne(base)
360
+ let nextCompileModel = base.compileModel
361
+ if (patch.compileModel !== undefined) {
362
+ if (patch.compileModel.mode !== 'default' && patch.compileModel.mode !== 'fixed') {
363
+ return failure(this.view(base), 'COMPILE_MODEL_INVALID', '编译模型 mode 只能是 default 或 fixed', false, '从编译模型选择项中选择“跟随 DSH 默认模型”或一个固定模型。')
364
+ }
365
+ const selected = compileModelOf(patch.compileModel)
366
+ if (patch.compileModel.mode === 'fixed' && selected.mode !== 'fixed') {
367
+ return failure(this.view(base), 'COMPILE_MODEL_INVALID', '固定编译模型必须同时提供 provider 和 model', false, '从当前 DSH 模型目录中选择一个可用模型。')
368
+ }
369
+ nextCompileModel = selected
370
+ }
346
371
  if (patch.name !== undefined) {
347
372
  const name = String(patch.name).trim()
348
373
  if (!name) return failure(this.view(base), 'NAME_REQUIRED', 'name 不能为空', false)
@@ -351,6 +376,7 @@ export class KnowledgeBases {
351
376
  if (patch.description !== undefined) base.description = String(patch.description)
352
377
  // 长度上限不是配额,是防呆:这条备注逐字进每一次抽取的提示词,几万字会把文档挤出去。
353
378
  if (patch.extractionNote !== undefined) base.extractionNote = String(patch.extractionNote).slice(0, 4000)
379
+ base.compileModel = nextCompileModel
354
380
  base.updatedAt = new Date().toISOString()
355
381
  await this.refreshOne(base)
356
382
  await this.persist()
@@ -366,6 +392,12 @@ export class KnowledgeBases {
366
392
  return this.records.find(item => item.id === id)?.extractionNote ?? ''
367
393
  }
368
394
 
395
+ /** 当前知识库的编译模型路由。不存在的库回到默认路由,避免读路径抛错。 */
396
+ compileModelOf(id: string): CompileModelSelection {
397
+ this.ensureLoaded()
398
+ return { ...(this.records.find(item => item.id === id)?.compileModel ?? DEFAULT_COMPILE_MODEL) }
399
+ }
400
+
369
401
  /**
370
402
  * 删除知识库。
371
403
  *
@@ -410,6 +442,7 @@ export class KnowledgeBases {
410
442
  rootDir: base.isDefault ? this.defaultRootDir() : base.rootDir,
411
443
  isDefault: base.isDefault,
412
444
  extractionNote: base.extractionNote,
445
+ compileModel: { ...base.compileModel },
413
446
  createdAt: base.createdAt,
414
447
  updatedAt: base.updatedAt,
415
448
  sourceCount: stats?.sourceCount ?? 0,
@@ -428,6 +461,7 @@ export class KnowledgeBases {
428
461
  rootDir: this.defaultRootDir(),
429
462
  isDefault: true,
430
463
  extractionNote: '',
464
+ compileModel: { ...DEFAULT_COMPILE_MODEL },
431
465
  createdAt: now,
432
466
  updatedAt: now,
433
467
  }
@@ -468,6 +502,7 @@ export class KnowledgeBases {
468
502
  isDefault: true,
469
503
  rootDir: seed.rootDir,
470
504
  name: existing.name || seed.name,
505
+ compileModel: existing.compileModel ?? seed.compileModel,
471
506
  }
472
507
  }
473
508
  }
@@ -488,6 +523,7 @@ export class KnowledgeBases {
488
523
  isDefault: value.isDefault === true || id === this.defaultId,
489
524
  // 0068 之前存下来的注册表里没有这个键:算空串,不报错,也不影响别的字段。
490
525
  extractionNote: typeof value.extractionNote === 'string' ? value.extractionNote : '',
526
+ compileModel: compileModelOf(value.compileModel),
491
527
  createdAt: typeof value.createdAt === 'string' && value.createdAt ? value.createdAt : now,
492
528
  updatedAt: typeof value.updatedAt === 'string' && value.updatedAt ? value.updatedAt : now,
493
529
  }
@@ -0,0 +1,114 @@
1
+ /** Browser-safe Knowledge contracts. Axis semantics remain in axis-contract.ts. */
2
+ export type KnowledgeKind = 'fact' | 'procedure' | 'case'
3
+ export type WikiKind = 'fact' | 'way'
4
+
5
+ export interface ProcedureContent {
6
+ question: string
7
+ appliesWhen: string[]
8
+ method: string[]
9
+ resultChecks: string[]
10
+ limitations: string[]
11
+ completeness: 'complete' | 'partial' | 'reference_only'
12
+ caseRefs: Array<{ id: string; version: number }>
13
+ }
14
+
15
+ export interface KnowledgeContent {
16
+ conditions?: string[]
17
+ procedure?: ProcedureContent
18
+ }
19
+
20
+ export function wikiProjection(kind: KnowledgeKind, coordinate: { objectId: string; actionId: string; sceneId: string }): { objectId: string; actionId: string; sceneId: string } | undefined {
21
+ if (kind === 'case' || !coordinate.objectId || (kind === 'procedure' && !coordinate.actionId)) return undefined
22
+ return { objectId: coordinate.objectId, actionId: kind === 'procedure' ? coordinate.actionId : '', sceneId: '' }
23
+ }
24
+
25
+ export function procedureText(value: ProcedureContent): string {
26
+ return [value.question, value.appliesWhen.length ? `适用条件:${value.appliesWhen.join(';')}` : '',
27
+ value.method.map((step, index) => { const prefix = `${index + 1}. `; return prefix + step.replace(/\n/g, `\n${' '.repeat(prefix.length)}`) }).join('\n'),
28
+ value.resultChecks.length ? `结果检查:${value.resultChecks.join(';')}` : '',
29
+ value.limitations.length ? `边界:${value.limitations.join(';')}` : ''].filter(Boolean).join('\n\n')
30
+ }
31
+
32
+ type Row = Record<string, unknown>
33
+ const row = (v: unknown): Row => v !== null && typeof v === 'object' && !Array.isArray(v) ? v as Row : {}
34
+ const rows = (v: unknown): Row[] => Array.isArray(v) ? v.map(row) : []
35
+ function list(v: unknown): unknown[] {
36
+ if (typeof v === 'string') { const p: unknown = JSON.parse(v || '[]'); if (!Array.isArray(p)) throw new Error('列表字段必须为数组'); return p }
37
+ if (v === null || v === undefined) return []
38
+ if (!Array.isArray(v)) throw new Error('列表字段必须为数组')
39
+ return v
40
+ }
41
+ const strings = (v: unknown): string[] => list(v).map(x => { if (typeof x === 'string') return x; if (typeof row(x).text === 'string') return row(x).text as string; throw new Error('列表项必须为字符串或包含 text 的对象') }).map(x => x.trim()).filter(Boolean)
42
+
43
+ /** Adapt v2 wire records to the existing evidence/axis resolver; legacy reports remain readable. */
44
+ export function normalizeKnowledgeExtraction(value: unknown): unknown {
45
+ const input = row(value)
46
+ if (!('facts' in input) && !('procedures' in input) && !('cases' in input)) return value
47
+ for (const key of ['facts', 'procedures', 'cases']) if (!Array.isArray(input[key])) throw new Error(`抽取缺少 ${key} 数组`)
48
+ const evidence = new Map<string, Row>()
49
+ for (const entry of rows(input.evidence)) {
50
+ const id = typeof entry.id === 'string' ? entry.id.trim() : ''
51
+ if (!id || evidence.has(id) || typeof entry.quote !== 'string' || !entry.quote.trim()) throw new Error('引文 ID 重复、为空或缺少 quote')
52
+ evidence.set(id, entry)
53
+ }
54
+ const refs = (item: Row): Row[] => {
55
+ if (Array.isArray(item.sources)) {
56
+ const sources = rows(item.sources)
57
+ if (!sources.length || sources.some(source => typeof source.quote !== 'string' || !source.quote.trim())) throw new Error('记录缺少有效来源引文')
58
+ return sources
59
+ }
60
+ const ids = typeof item.evidence === 'string' ? item.evidence.trim().split(/\s+/).filter(Boolean) : list(item.evidence)
61
+ if (!ids.length) throw new Error('记录缺少 evidence 引用')
62
+ return ids.map(id => {
63
+ const e = evidence.get(String(id))
64
+ if (!e || typeof e.quote !== 'string' || !e.quote.trim()) throw new Error(`引文 ${String(id)} 不存在或为空`)
65
+ return { quote: e.quote, heading_path: strings(e.heading_path) }
66
+ })
67
+ }
68
+ const seen = new Set<string>()
69
+ const checkId = (v: Row): void => {
70
+ const id = String(v.id ?? '').trim()
71
+ if (!id || seen.has(id)) throw new Error('Knowledge 局部 ID 为空或重复')
72
+ seen.add(id)
73
+ }
74
+ const knowledge = rows(input.facts).map(f => {
75
+ checkId(f)
76
+ return { ...f, scope_identity: true, kind: 'fact', data: strings(f.conditions).length ? { conditions: strings(f.conditions) } : {}, sources: refs(f) }
77
+ })
78
+ for (const p of rows(input.procedures)) {
79
+ checkId(p)
80
+ const completeness = p.completeness
81
+ if (!['complete', 'partial', 'reference_only'].includes(String(completeness))) throw new Error(`Procedure ${p.id} completeness 不合法`)
82
+ if (list(p.case_refs).length) throw new Error('抽取阶段不能生成 Case 版本引用,请使用独立提炼阶段')
83
+ const method = list(p.method)
84
+ const stepSources = method.flatMap(step => typeof step === 'string' ? [] : refs(row(step)))
85
+ const procedure: ProcedureContent = {
86
+ question: String(p.question ?? '').trim(), appliesWhen: strings(p.applies_when), method: strings(method),
87
+ resultChecks: strings(p.result_checks), limitations: [...strings(p.limitations), ...strings(p.missing)],
88
+ completeness: completeness as ProcedureContent['completeness'],
89
+ caseRefs: list(p.case_refs).map(ref => ({ id: String(row(ref).id ?? ''), version: Number(row(ref).version ?? 0) })),
90
+ }
91
+ if (!procedure.question || (procedure.completeness === 'complete' && procedure.method.length === 0)) throw new Error(`Procedure ${p.id} 缺少问题或完整方法`)
92
+ knowledge.push({ ...p, scope_identity: true, kind: 'procedure', text: procedureText(procedure), data: { procedure }, sources: [...refs(p), ...stepSources] } as typeof knowledge[number])
93
+ }
94
+ const caseIds = new Set(rows(input.cases).map(c => c.id))
95
+ const timelineKeys = new Set<string>()
96
+ for (const step of rows(input.timeline)) {
97
+ if (!caseIds.has(step.case_id)) throw new Error('时间线引用不存在的 Case')
98
+ const key = `${step.case_id}:${step.order}`
99
+ if (!Number.isInteger(step.order) || Number(step.order) < 1 || timelineKeys.has(key)) throw new Error('时间线顺序必须为不重复的正整数')
100
+ timelineKeys.add(key)
101
+ }
102
+ const events = rows(input.cases).map(c => {
103
+ checkId(c)
104
+ const timeline = Array.isArray(c.timeline) ? rows(c.timeline) : rows(input.timeline).filter(step => step.case_id === c.id)
105
+ if (timeline.some(step => !['observation', 'check', 'action', 'result', 'conclusion'].includes(String(step.type)))) throw new Error('Case 时间线类型不合法')
106
+ const rootCause = typeof c.root_cause === 'string' ? c.root_cause ? { text: c.root_cause, status: c.root_cause_status } : null : c.root_cause
107
+ return { ...c, coordinate: c.coordinate ?? { object_mention: c.object, action_mention: c.action, scene_mention: c.scene },
108
+ missing: strings(c.missing), root_cause: rootCause, sources: refs(c),
109
+ timeline: timeline.map(step => ({ ...step, sources: refs(step) })) }
110
+ })
111
+ return { ...input, knowledge, events,
112
+ ...Object.fromEntries(['objects', 'actions', 'scenes'].map(key => [key, rows(input[key]).map(a => ({ ...a,
113
+ parent_mention: a.parent_mention ?? a.parent, evidence: typeof a.evidence === 'string' && !evidence.has(a.evidence) ? a.evidence : refs(a).map(e => e.quote).join('\n') }))])) }
114
+ }