@octopi-agent/engine 0.98.4 → 0.121.10

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 (493) hide show
  1. package/dist/builtin-model-info.js +28 -7
  2. package/dist/config-admin/agent-presets.d.ts +32 -0
  3. package/dist/config-admin/agent-presets.js +133 -0
  4. package/dist/config-admin/discover.d.ts +33 -4
  5. package/dist/config-admin/discover.js +101 -6
  6. package/dist/config-admin/env.d.ts +11 -0
  7. package/dist/config-admin/env.js +41 -0
  8. package/dist/config-admin/error-copy.d.ts +106 -0
  9. package/dist/config-admin/error-copy.js +287 -0
  10. package/dist/config-admin/i18n.d.ts +21 -0
  11. package/dist/config-admin/i18n.js +19 -0
  12. package/dist/config-admin/index.d.ts +6 -2
  13. package/dist/config-admin/index.js +3 -1
  14. package/dist/config-admin/model-presets.d.ts +14 -0
  15. package/dist/config-admin/model-presets.js +595 -70
  16. package/dist/config-admin/onboarding-apply.d.ts +71 -0
  17. package/dist/config-admin/onboarding-apply.js +235 -0
  18. package/dist/config-admin/onboarding.d.ts +154 -0
  19. package/dist/config-admin/onboarding.js +270 -0
  20. package/dist/config-admin/redact.d.ts +42 -9
  21. package/dist/config-admin/redact.js +69 -5
  22. package/dist/config-schema/agent.d.ts +40 -6
  23. package/dist/config-schema/agent.js +44 -6
  24. package/dist/config-schema/browser.d.ts +62 -0
  25. package/dist/config-schema/browser.js +89 -0
  26. package/dist/config-schema/context.d.ts +12 -37
  27. package/dist/config-schema/context.js +10 -31
  28. package/dist/config-schema/engine.d.ts +140 -164
  29. package/dist/config-schema/engine.js +10 -7
  30. package/dist/config-schema/governance.d.ts +20 -2
  31. package/dist/config-schema/governance.js +18 -3
  32. package/dist/config-schema/models.d.ts +10 -12
  33. package/dist/config-schema/models.js +16 -3
  34. package/dist/config-schema/run.d.ts +6 -2
  35. package/dist/config-schema/run.js +12 -2
  36. package/dist/config-schema/shared.d.ts +1 -3
  37. package/dist/config-schema/shared.js +4 -4
  38. package/dist/config-schema/substrate.d.ts +19 -88
  39. package/dist/config-schema/substrate.js +30 -107
  40. package/dist/config.d.ts +161 -123
  41. package/dist/config.js +109 -7
  42. package/dist/file-mode.d.ts +67 -0
  43. package/dist/file-mode.js +182 -0
  44. package/dist/fork-child.d.ts +82 -0
  45. package/dist/fork-child.js +123 -0
  46. package/dist/harness/activation/delegated-run.d.ts +42 -0
  47. package/dist/harness/activation/delegated-run.js +71 -0
  48. package/dist/harness/activation/dispatcher.js +11 -0
  49. package/dist/harness/activation/inbox.d.ts +3 -3
  50. package/dist/harness/activation/inbox.js +3 -3
  51. package/dist/harness/activation/index.d.ts +1 -0
  52. package/dist/harness/activation/run-backend.d.ts +92 -0
  53. package/dist/harness/activation/run-backend.js +16 -0
  54. package/dist/harness/activation/run-protocol.d.ts +392 -0
  55. package/dist/harness/activation/run-protocol.js +19 -0
  56. package/dist/harness/activation/runtime.d.ts +33 -0
  57. package/dist/harness/activation/runtime.js +130 -31
  58. package/dist/harness/activation/types.d.ts +20 -3
  59. package/dist/harness/agent/builder.d.ts +36 -3
  60. package/dist/harness/agent/builder.js +206 -46
  61. package/dist/harness/agent/config-bridge.d.ts +10 -1
  62. package/dist/harness/agent/config-bridge.js +24 -5
  63. package/dist/harness/agent/config-integrity.js +19 -2
  64. package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
  65. package/dist/harness/agent/registered-tool-adapter.js +67 -0
  66. package/dist/harness/agent/wire-agent-builder.d.ts +13 -3
  67. package/dist/harness/agent/wire-agent-builder.js +35 -9
  68. package/dist/harness/capabilities/document/backends/plain.js +2 -1
  69. package/dist/harness/capabilities/document/factory.d.ts +5 -0
  70. package/dist/harness/capabilities/document/factory.js +1 -0
  71. package/dist/harness/capabilities/document/legacy/factory.js +3 -2
  72. package/dist/harness/capabilities/document/port.js +6 -3
  73. package/dist/harness/capabilities/document/types.d.ts +5 -0
  74. package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +17 -0
  75. package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
  76. package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
  77. package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
  78. package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
  79. package/dist/harness/collaboration/autonomous-subsystem/loader.js +2 -1
  80. package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
  81. package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
  82. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +14 -4
  83. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +50 -41
  84. package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
  85. package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
  86. package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
  87. package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
  88. package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
  89. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +4 -1
  90. package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +7 -3
  91. package/dist/harness/collaboration/delegation/child-run.d.ts +10 -1
  92. package/dist/harness/collaboration/delegation/child-run.js +38 -6
  93. package/dist/harness/collaboration/delegation/index.d.ts +1 -1
  94. package/dist/harness/collaboration/delegation/index.js +1 -1
  95. package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
  96. package/dist/harness/collaboration/delegation/notifier.js +8 -1
  97. package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
  98. package/dist/harness/collaboration/delegation/service.d.ts +11 -4
  99. package/dist/harness/collaboration/delegation/service.js +35 -13
  100. package/dist/harness/collaboration/delegation/store.d.ts +4 -0
  101. package/dist/harness/collaboration/delegation/store.js +3 -1
  102. package/dist/harness/collaboration/delegation/types.d.ts +34 -2
  103. package/dist/harness/collaboration/delegation/types.js +22 -0
  104. package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
  105. package/dist/harness/collaboration/delegation/wiring.js +12 -1
  106. package/dist/harness/context/budget-allocator.d.ts +26 -18
  107. package/dist/harness/context/budget-allocator.js +67 -32
  108. package/dist/harness/context/capabilities/compact/engine.d.ts +44 -11
  109. package/dist/harness/context/capabilities/compact/engine.js +296 -160
  110. package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
  111. package/dist/harness/context/capabilities/compact/handover.js +7 -5
  112. package/dist/harness/context/capabilities/compact/index.d.ts +7 -2
  113. package/dist/harness/context/capabilities/compact/index.js +5 -1
  114. package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
  115. package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
  116. package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
  117. package/dist/harness/context/capabilities/compact/messages.js +91 -0
  118. package/dist/harness/context/capabilities/compact/types.d.ts +134 -19
  119. package/dist/harness/context/capabilities/compact/types.js +11 -1
  120. package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
  121. package/dist/harness/context/capabilities/compact/view-split.js +72 -0
  122. package/dist/harness/context/capabilities/summary/gate.d.ts +19 -2
  123. package/dist/harness/context/capabilities/summary/gate.js +53 -6
  124. package/dist/harness/context/capabilities/summary/port.js +0 -1
  125. package/dist/harness/context/capabilities/summary/registry.js +20 -0
  126. package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
  127. package/dist/harness/context/capabilities/summary/resolver.js +1 -6
  128. package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
  129. package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
  130. package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
  131. package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
  132. package/dist/harness/context/capabilities/summary/types.d.ts +19 -6
  133. package/dist/harness/context/constitution/default-agents.md +85 -0
  134. package/dist/harness/context/context-size-ledger.d.ts +143 -0
  135. package/dist/harness/context/context-size-ledger.js +243 -0
  136. package/dist/harness/context/default-context-engine.d.ts +290 -120
  137. package/dist/harness/context/default-context-engine.js +1555 -764
  138. package/dist/harness/context/index.d.ts +3 -2
  139. package/dist/harness/context/index.js +2 -1
  140. package/dist/harness/context/layer-health.d.ts +4 -0
  141. package/dist/harness/context/layer-health.js +4 -0
  142. package/dist/harness/context/layer-types.d.ts +72 -0
  143. package/dist/harness/context/layer-types.js +87 -2
  144. package/dist/harness/context/layers.d.ts +17 -15
  145. package/dist/harness/context/layers.js +54 -17
  146. package/dist/harness/context/message-selector.d.ts +10 -8
  147. package/dist/harness/context/message-selector.js +49 -27
  148. package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
  149. package/dist/harness/context/prefix-fingerprint.js +52 -0
  150. package/dist/harness/context/summarize.d.ts +2 -2
  151. package/dist/harness/context/summarize.js +27 -2
  152. package/dist/harness/context/system-prompt-assembler.d.ts +4 -0
  153. package/dist/harness/context/system-prompt-assembler.js +7 -3
  154. package/dist/harness/context/token-constants.d.ts +8 -6
  155. package/dist/harness/context/token-constants.js +8 -7
  156. package/dist/harness/context/token-estimate-fns.d.ts +37 -27
  157. package/dist/harness/context/token-estimate-fns.js +85 -66
  158. package/dist/harness/context/token-estimator.d.ts +27 -12
  159. package/dist/harness/context/token-estimator.js +120 -66
  160. package/dist/harness/context/token-segments.d.ts +88 -0
  161. package/dist/harness/context/token-segments.js +103 -0
  162. package/dist/harness/context/tool-result-aging.d.ts +109 -16
  163. package/dist/harness/context/tool-result-aging.js +220 -55
  164. package/dist/harness/context/tool-result-body.js +2 -0
  165. package/dist/harness/context/transform/anchors.d.ts +66 -0
  166. package/dist/harness/context/transform/anchors.js +125 -0
  167. package/dist/harness/context/transform/fold.d.ts +56 -0
  168. package/dist/harness/context/transform/fold.js +135 -0
  169. package/dist/harness/context/transform/migrate.d.ts +41 -0
  170. package/dist/harness/context/transform/migrate.js +69 -0
  171. package/dist/harness/context/transform/types.d.ts +129 -0
  172. package/dist/harness/context/transform/types.js +19 -0
  173. package/dist/harness/context/turn-envelope.d.ts +6 -3
  174. package/dist/harness/context/types.d.ts +196 -119
  175. package/dist/harness/context/types.js +25 -1
  176. package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
  177. package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
  178. package/dist/harness/extension/execution-environment/ops-audit.d.ts +1 -1
  179. package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
  180. package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
  181. package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
  182. package/dist/harness/extension/execution-environment/workspace.js +1 -1
  183. package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +28 -2
  184. package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
  185. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
  186. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
  187. package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
  188. package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
  189. package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
  190. package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
  191. package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
  192. package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
  193. package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
  194. package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
  195. package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
  196. package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
  197. package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
  198. package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
  199. package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
  200. package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
  201. package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
  202. package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
  203. package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
  204. package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
  205. package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
  206. package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
  207. package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
  208. package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
  209. package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
  210. package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
  211. package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
  212. package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
  213. package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
  214. package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
  215. package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
  216. package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +223 -222
  217. package/dist/harness/extension/plugin-ecosystem/plugins/api.js +218 -203
  218. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
  219. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
  220. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
  221. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
  222. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +78 -0
  223. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +80 -0
  224. package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
  225. package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
  226. package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
  227. package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
  228. package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
  229. package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
  230. package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +57 -114
  231. package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +279 -282
  232. package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +46 -484
  233. package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +123 -345
  234. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +50 -223
  235. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +144 -20
  236. package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +17 -0
  237. package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
  238. package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
  239. package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
  240. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
  241. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
  242. package/dist/harness/extension/plugin-ecosystem/tools/browser-types.d.ts +333 -0
  243. package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
  244. package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
  245. package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
  246. package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
  247. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
  248. package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +36 -8
  249. package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
  250. package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
  251. package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
  252. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
  253. package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
  254. package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
  255. package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
  256. package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
  257. package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
  258. package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
  259. package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
  260. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
  261. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +19 -24
  262. package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
  263. package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
  264. package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
  265. package/dist/harness/governance/accounting/usage-ledger.js +23 -1
  266. package/dist/harness/governance/credentials/db.d.ts +9 -0
  267. package/dist/harness/governance/credentials/db.js +122 -31
  268. package/dist/harness/governance/credentials/store.d.ts +68 -7
  269. package/dist/harness/governance/credentials/store.js +177 -64
  270. package/dist/harness/governance/credentials/types.d.ts +13 -2
  271. package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
  272. package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
  273. package/dist/harness/governance/index.d.ts +1 -0
  274. package/dist/harness/governance/index.js +1 -0
  275. package/dist/harness/governance/registry/db.d.ts +32 -0
  276. package/dist/harness/governance/registry/db.js +142 -0
  277. package/dist/harness/governance/registry/index.d.ts +9 -0
  278. package/dist/harness/governance/registry/index.js +9 -0
  279. package/dist/harness/governance/registry/service.d.ts +381 -0
  280. package/dist/harness/governance/registry/service.js +825 -0
  281. package/dist/harness/governance/registry/types.d.ts +77 -0
  282. package/dist/harness/governance/registry/types.js +7 -0
  283. package/dist/harness/governance/security/capability-enforcer.js +1 -2
  284. package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
  285. package/dist/harness/governance/security/default-security-guard.js +12 -1
  286. package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
  287. package/dist/harness/governance/security/risk-evaluator.js +307 -21
  288. package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
  289. package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
  290. package/dist/harness/index.d.ts +17 -15
  291. package/dist/harness/index.js +9 -9
  292. package/dist/harness/knowledge/boot-config.d.ts +57 -0
  293. package/dist/harness/knowledge/boot-config.js +52 -0
  294. package/dist/harness/knowledge/catalog-types.d.ts +2 -0
  295. package/dist/harness/knowledge/client.d.ts +77 -9
  296. package/dist/harness/knowledge/client.js +95 -24
  297. package/dist/harness/knowledge/db.d.ts +16 -0
  298. package/dist/harness/knowledge/db.js +112 -41
  299. package/dist/harness/knowledge/describe-sample.d.ts +23 -0
  300. package/dist/harness/knowledge/describe-sample.js +58 -0
  301. package/dist/harness/knowledge/describe.d.ts +8 -0
  302. package/dist/harness/knowledge/describe.js +18 -2
  303. package/dist/harness/knowledge/engine-thread.js +11 -7
  304. package/dist/harness/knowledge/grounding.js +7 -2
  305. package/dist/harness/knowledge/http-app.d.ts +15 -0
  306. package/dist/harness/knowledge/http-app.js +117 -25
  307. package/dist/harness/knowledge/http-bridge.d.ts +15 -0
  308. package/dist/harness/knowledge/http-bridge.js +19 -0
  309. package/dist/harness/knowledge/http-params.d.ts +18 -0
  310. package/dist/harness/knowledge/http-params.js +24 -0
  311. package/dist/harness/knowledge/index.d.ts +2 -0
  312. package/dist/harness/knowledge/index.js +1 -0
  313. package/dist/harness/knowledge/knowledge-serve-child.js +5 -3
  314. package/dist/harness/knowledge/purge.js +5 -2
  315. package/dist/harness/knowledge/query-service.d.ts +25 -4
  316. package/dist/harness/knowledge/query-service.js +79 -43
  317. package/dist/harness/knowledge/query-worker-client.d.ts +14 -2
  318. package/dist/harness/knowledge/query-worker-client.js +8 -3
  319. package/dist/harness/knowledge/query-worker.js +9 -5
  320. package/dist/harness/knowledge/read-http.d.ts +2 -0
  321. package/dist/harness/knowledge/read-http.js +14 -3
  322. package/dist/harness/knowledge/retriever.d.ts +1 -1
  323. package/dist/harness/knowledge/retriever.js +1 -2
  324. package/dist/harness/knowledge/serve.d.ts +14 -8
  325. package/dist/harness/knowledge/serve.js +14 -6
  326. package/dist/harness/knowledge/source-store.d.ts +101 -5
  327. package/dist/harness/knowledge/source-store.js +323 -74
  328. package/dist/harness/knowledge/start-service-process.d.ts +41 -14
  329. package/dist/harness/knowledge/start-service-process.js +67 -96
  330. package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
  331. package/dist/harness/knowledge/tenant-gate.js +167 -0
  332. package/dist/harness/knowledge/types.d.ts +7 -0
  333. package/dist/harness/knowledge/writer-service.d.ts +55 -11
  334. package/dist/harness/knowledge/writer-service.js +200 -30
  335. package/dist/harness/knowledge/writer-worker-client.d.ts +19 -11
  336. package/dist/harness/knowledge/writer-worker-client.js +40 -5
  337. package/dist/harness/knowledge/writer-worker.js +20 -5
  338. package/dist/harness/memory/backfill-trigger.d.ts +10 -3
  339. package/dist/harness/memory/backfill-trigger.js +19 -19
  340. package/dist/harness/memory/cognition-seeds.d.ts +45 -0
  341. package/dist/harness/memory/cognition-seeds.js +67 -0
  342. package/dist/harness/memory/cognition.d.ts +12 -3
  343. package/dist/harness/memory/cognition.js +55 -35
  344. package/dist/harness/memory/conceptualizer.d.ts +11 -1
  345. package/dist/harness/memory/conceptualizer.js +10 -1
  346. package/dist/harness/memory/context-slice.d.ts +42 -0
  347. package/dist/harness/memory/context-slice.js +197 -0
  348. package/dist/harness/memory/health-probe.d.ts +8 -2
  349. package/dist/harness/memory/health-probe.js +10 -13
  350. package/dist/harness/memory/index.d.ts +5 -1
  351. package/dist/harness/memory/index.js +3 -1
  352. package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
  353. package/dist/harness/memory/sqlite/agent-db.js +9 -8
  354. package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
  355. package/dist/harness/memory/sqlite/cognition-store.js +103 -45
  356. package/dist/harness/memory/sqlite/memory-store.js +4 -0
  357. package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
  358. package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
  359. package/dist/harness/memory/sqlite/wisdom-store.js +35 -10
  360. package/dist/harness/memory/types.d.ts +24 -6
  361. package/dist/harness/memory/wisdom-formation.d.ts +14 -3
  362. package/dist/harness/memory/wisdom-formation.js +85 -22
  363. package/dist/harness/memory/wisdom-gates.d.ts +14 -0
  364. package/dist/harness/memory/wisdom-gates.js +59 -19
  365. package/dist/harness/memory/wisdom.js +9 -0
  366. package/dist/harness/observability/observer/hub.d.ts +10 -0
  367. package/dist/harness/observability/observer/hub.js +120 -17
  368. package/dist/harness/observability/observer/types.d.ts +10 -6
  369. package/dist/harness/run/agent/agent.d.ts +40 -21
  370. package/dist/harness/run/agent/agent.js +67 -13
  371. package/dist/harness/run/agent/index.d.ts +1 -1
  372. package/dist/harness/run/budget/budget.d.ts +28 -10
  373. package/dist/harness/run/budget/budget.js +38 -15
  374. package/dist/harness/run/concurrency/tool-validator.js +4 -3
  375. package/dist/harness/run/model/index.d.ts +3 -1
  376. package/dist/harness/run/model/index.js +2 -1
  377. package/dist/harness/run/model/resolver.d.ts +4 -1
  378. package/dist/harness/run/model/resolver.js +36 -2
  379. package/dist/harness/run/model/run-scope.d.ts +2 -0
  380. package/dist/harness/run/model/run-scope.js +7 -0
  381. package/dist/harness/run/model/types.d.ts +22 -5
  382. package/dist/harness/run/model/types.js +3 -2
  383. package/dist/harness/run/model/window-truth.d.ts +37 -0
  384. package/dist/harness/run/model/window-truth.js +39 -0
  385. package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
  386. package/dist/harness/run/reliability/context-length-feedback.js +128 -0
  387. package/dist/harness/run/reliability/harness-events.d.ts +3 -3
  388. package/dist/harness/run/reliability/model-error-policy.js +4 -0
  389. package/dist/harness/run/reliability/run-agent.d.ts +32 -4
  390. package/dist/harness/run/reliability/run-agent.js +216 -63
  391. package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
  392. package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
  393. package/dist/harness/run/run-guard/default-run-guard.js +8 -8
  394. package/dist/harness/run/run-host.d.ts +302 -0
  395. package/dist/harness/run/run-host.js +978 -0
  396. package/dist/harness/run/run-scope.d.ts +48 -4
  397. package/dist/harness/run/run-scope.js +19 -1
  398. package/dist/harness/run/runner.d.ts +181 -39
  399. package/dist/harness/run/runner.js +654 -119
  400. package/dist/harness/session/attachments/index.d.ts +1 -0
  401. package/dist/harness/session/attachments/index.js +1 -0
  402. package/dist/harness/session/attachments/inject.d.ts +21 -10
  403. package/dist/harness/session/attachments/inject.js +76 -24
  404. package/dist/harness/session/attachments/recall-index.d.ts +70 -0
  405. package/dist/harness/session/attachments/recall-index.js +219 -0
  406. package/dist/harness/session/attachments/service.d.ts +21 -0
  407. package/dist/harness/session/attachments/service.js +258 -139
  408. package/dist/harness/session/attachments/types.d.ts +6 -0
  409. package/dist/harness/session/in-memory-store.js +13 -1
  410. package/dist/harness/session/schedules/service.d.ts +10 -2
  411. package/dist/harness/session/schedules/service.js +13 -2
  412. package/dist/harness/session/tasks/tools.js +12 -0
  413. package/dist/harness/session/transform-store.d.ts +136 -0
  414. package/dist/harness/session/transform-store.js +302 -0
  415. package/dist/harness/session/types.d.ts +11 -15
  416. package/dist/harness/shared/events/agent-event-map.d.ts +75 -13
  417. package/dist/harness/shared/events/agent-event-map.js +3 -2
  418. package/dist/harness/shared/events/scenario-events.d.ts +6 -6
  419. package/dist/harness/shared/types/agent-definition.d.ts +7 -2
  420. package/dist/index.d.ts +16 -18
  421. package/dist/index.js +9 -10
  422. package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
  423. package/dist/integration/agent-runtime/channel-message-source.js +4 -3
  424. package/dist/integration/browser/camoufox.d.ts +40 -0
  425. package/dist/integration/browser/camoufox.js +80 -0
  426. package/dist/integration/browser/index.d.ts +91 -0
  427. package/dist/integration/browser/index.js +110 -0
  428. package/dist/integration/browser/install.d.ts +47 -0
  429. package/dist/integration/browser/install.js +214 -0
  430. package/dist/integration/browser/playwright.d.ts +224 -0
  431. package/dist/integration/browser/playwright.js +925 -0
  432. package/dist/integration/browser/service.d.ts +41 -0
  433. package/dist/integration/browser/service.js +181 -0
  434. package/dist/integration/browser/stealth.d.ts +42 -0
  435. package/dist/integration/browser/stealth.js +104 -0
  436. package/dist/integration/observability/metrics.d.ts +6 -6
  437. package/dist/integration/observability/metrics.js +13 -13
  438. package/dist/integration/observability/observer-bridge.js +2 -2
  439. package/dist/integration/observability/trace-collector.d.ts +5 -5
  440. package/dist/integration/observability/trace-collector.js +34 -35
  441. package/dist/integration/observability/trace-events.d.ts +3 -3
  442. package/dist/integration/observability/trace-events.js +3 -3
  443. package/dist/integration/providers/anthropic-message-normalize.d.ts +20 -0
  444. package/dist/integration/providers/anthropic-message-normalize.js +48 -0
  445. package/dist/integration/providers/anthropic.js +41 -3
  446. package/dist/integration/providers/fetch-timeout.d.ts +17 -0
  447. package/dist/integration/providers/fetch-timeout.js +24 -0
  448. package/dist/integration/providers/openai.d.ts +8 -0
  449. package/dist/integration/providers/openai.js +48 -2
  450. package/dist/integration/providers/usage.d.ts +1 -1
  451. package/dist/integration/providers/wire-dump-diff.js +2 -1
  452. package/dist/integration/providers/wire-dump.d.ts +57 -3
  453. package/dist/integration/providers/wire-dump.js +119 -6
  454. package/dist/integration/storage/archive-manager.d.ts +20 -2
  455. package/dist/integration/storage/archive-manager.js +34 -8
  456. package/dist/integration/storage/atomic-tmp.d.ts +12 -0
  457. package/dist/integration/storage/atomic-tmp.js +36 -0
  458. package/dist/integration/storage/jsonl.d.ts +10 -1
  459. package/dist/integration/storage/jsonl.js +155 -54
  460. package/dist/integration/storage/session-index.d.ts +5 -0
  461. package/dist/integration/storage/session-index.js +25 -4
  462. package/dist/integration/tools/assemble.d.ts +50 -0
  463. package/dist/integration/tools/assemble.js +137 -0
  464. package/dist/paths.d.ts +18 -0
  465. package/dist/paths.js +36 -0
  466. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
  467. package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
  468. package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
  469. package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
  470. package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
  471. package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
  472. package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
  473. package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
  474. package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
  475. package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
  476. package/dist/subsystems/wisdom-steward/formation/config.yaml +4 -0
  477. package/dist/subsystems/wisdom-steward/formation/handler.js +27 -5
  478. package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
  479. package/package.json +14 -15
  480. package/dist/harness/context/hybrid-compressor.d.ts +0 -41
  481. package/dist/harness/context/hybrid-compressor.js +0 -159
  482. package/dist/harness/context/llm-summarizer.d.ts +0 -46
  483. package/dist/harness/context/llm-summarizer.js +0 -249
  484. package/dist/harness/context/smart-router.d.ts +0 -75
  485. package/dist/harness/context/smart-router.js +0 -118
  486. package/dist/harness/context/truncate-compressor.d.ts +0 -28
  487. package/dist/harness/context/truncate-compressor.js +0 -107
  488. package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
  489. package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
  490. package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
  491. package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
  492. package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
  493. package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
@@ -12,10 +12,13 @@ import { KnowledgeIngest, type IngestProgressEvent } from './ingest.js';
12
12
  import type { KnowledgeSource } from './types.js';
13
13
  import type { KnowledgeJobControlState } from './job-control-state.js';
14
14
  import type { DocumentCapabilityConfig } from '../capabilities/document/factory.js';
15
+ import type { KnowledgeBootEmbed, KnowledgeBootIngest } from './boot-config.js';
15
16
  import type { EmbeddingProvider } from '../memory/sqlite/embedding.js';
16
17
  export interface WriteIdentity {
17
18
  tenantId: string;
18
19
  gatewayId: string;
20
+ /** 是否携带显式租户断言(x-octopi-tenant);归属打标区分「显式」与「token 域回落」 */
21
+ claimed?: boolean;
19
22
  }
20
23
  export interface WriteAbortStats {
21
24
  cancelledQueued: number;
@@ -33,6 +36,25 @@ export interface WriteDescribeResult {
33
36
  generatedDescription: string;
34
37
  source: string;
35
38
  }
39
+ /** gateway 代生成(B 方案)的抽样出 Service 边界形态:密钥扫描在此把关 */
40
+ export type WriteDescribeSampleResult = {
41
+ blocked: false;
42
+ meta: {
43
+ displayName: string;
44
+ kind: string;
45
+ location: string;
46
+ };
47
+ sample: string;
48
+ } | {
49
+ blocked: true;
50
+ secretHits: string[];
51
+ };
52
+ /** describe 写入口(gateway 回写 LLM 描述) */
53
+ export interface WriteDescribeInput {
54
+ description: string;
55
+ /** 缺省 'llm'(写入口的调用方是 gateway 的 LLM describe 流程) */
56
+ source?: 'llm' | 'heuristic';
57
+ }
36
58
  export interface WriteReprocessResult {
37
59
  queued: number;
38
60
  alreadyActive: number;
@@ -69,7 +91,11 @@ export interface KnowledgeWriteService {
69
91
  id: string;
70
92
  purgedFiles: number;
71
93
  }>;
72
- describeSource(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeResult | null>;
94
+ describeSource(identity: WriteIdentity, sourceId: string, input?: WriteDescribeInput): Promise<WriteDescribeResult | null>;
95
+ /** 抽样出 Service 边界(gateway 代生成取素材);密钥命中即封锁不外发 */
96
+ describeSample(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeSampleResult | null>;
97
+ /** 待 LLM 升级的源(heuristic/legacy 归因且无人工描述),供 gateway boot sweep */
98
+ listDescribePending(identity: WriteIdentity): Promise<string[]>;
73
99
  reindexSource(sourceId: string): Promise<void>;
74
100
  /** 按路径强制重解析(中止态自动 resume) */
75
101
  reprocessFiles(sourceId: string, paths: string[]): Promise<WriteReprocessResult>;
@@ -86,6 +112,10 @@ export interface KnowledgeWriteService {
86
112
  unassignProject(identity: WriteIdentity, agentId: string, projectKey: string): Promise<void>;
87
113
  hideSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
88
114
  unhideSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
115
+ /** 挂载(T3b):agent 级 include 覆盖(§6 挂载库);翻转既有隐藏 */
116
+ mountSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
117
+ /** 卸载:撤 include,回基础可见性 */
118
+ unmountSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
89
119
  replaceSessionVisibility(identity: WriteIdentity, agentId: string, sessionId: string, items: Array<{
90
120
  targetType: string;
91
121
  targetId: string;
@@ -99,7 +129,7 @@ export interface KnowledgeWriteService {
99
129
  clearSessionVisibility(identity: WriteIdentity, sessionId: string, target?: {
100
130
  targetType: 'project' | 'source';
101
131
  targetId: string;
102
- }): Promise<void>;
132
+ }, op?: 'include' | 'exclude'): Promise<void>;
103
133
  isSourceOwner(sourceId: string, gatewayId: string): Promise<boolean>;
104
134
  sourceVisibleToGateway(sourceId: string, gatewayId: string): Promise<boolean>;
105
135
  startIngestRuntime(): Promise<void>;
@@ -112,13 +142,13 @@ export interface LocalWriteDeps {
112
142
  embeddingProvider?: EmbeddingProvider | null;
113
143
  /** source.authRef 解析(SEC-3c consumer 绑定强制) */
114
144
  credentials?: import('../governance/credentials/store.js').CredentialStore | null;
115
- embed?: {
116
- enabled?: boolean;
117
- embedBatch?: number;
118
- embedMinIntervalMs?: number;
119
- embedConcurrency?: number;
120
- embedSecretPolicy?: 'allow' | 'redact' | 'skip';
121
- } | null;
145
+ embed?: KnowledgeBootEmbed | null;
146
+ /** Ingest 调参(knowledge.load / index.queue / index.files) */
147
+ ingest?: KnowledgeBootIngest | null;
148
+ /** false = 索引稳定后不自动生成 generatedDescription(knowledge.catalog.autoDescribe) */
149
+ autoDescribe?: boolean;
150
+ /** 跨租户共享闸(B-5):允许创建 visibility='public' 项目;缺省 false(fail-closed) */
151
+ allowPublic?: boolean;
122
152
  }
123
153
  /** 进程内唯一写者(测试 / :memory:)。 */
124
154
  export declare class LocalKnowledgeWriteService implements KnowledgeWriteService {
@@ -156,7 +186,17 @@ export declare class LocalKnowledgeWriteService implements KnowledgeWriteService
156
186
  id: string;
157
187
  purgedFiles: number;
158
188
  }>;
159
- describeSource(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeResult | null>;
189
+ describeSource(identity: WriteIdentity, sourceId: string, input?: WriteDescribeInput): Promise<WriteDescribeResult | null>;
190
+ describeSample(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeSampleResult | null>;
191
+ listDescribePending(identity: WriteIdentity): Promise<string[]>;
192
+ /** 启发式/封锁描述生成(无 describePort:Service 侧永不含 LLM 出网,B 方案拍板) */
193
+ private describeWithSample;
194
+ /**
195
+ * 源写权限(arch/multi-tenancy.md §6,评审 MAJ-5):
196
+ * 网关漏斗(registered_by)⊕ 租户域(tenant_id)——platform 身份 = 运维豁免;
197
+ * 租户身份只可写本域源。缺行按无约束放行(老库/投影缺失),由调用方的 not-found 路径兜底。
198
+ */
199
+ private assertSourceWritable;
160
200
  private assertSourceOwner;
161
201
  reindexSource(sourceId: string): Promise<void>;
162
202
  reprocessFiles(sourceId: string, paths: string[]): Promise<WriteReprocessResult>;
@@ -174,6 +214,8 @@ export declare class LocalKnowledgeWriteService implements KnowledgeWriteService
174
214
  unassignProject(identity: WriteIdentity, agentId: string, projectKey: string): Promise<void>;
175
215
  hideSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
176
216
  unhideSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
217
+ mountSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
218
+ unmountSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
177
219
  replaceSessionVisibility(identity: WriteIdentity, _agentId: string, sessionId: string, items: Array<{
178
220
  targetType: string;
179
221
  targetId: string;
@@ -187,10 +229,12 @@ export declare class LocalKnowledgeWriteService implements KnowledgeWriteService
187
229
  clearSessionVisibility(identity: WriteIdentity, sessionId: string, target?: {
188
230
  targetType: 'project' | 'source';
189
231
  targetId: string;
190
- }): Promise<void>;
232
+ }, op?: 'include' | 'exclude'): Promise<void>;
191
233
  isSourceOwner(sourceId: string, gatewayId: string): Promise<boolean>;
192
234
  sourceVisibleToGateway(sourceId: string, gatewayId: string): Promise<boolean>;
193
235
  startIngestRuntime(): Promise<void>;
194
236
  onProgress(cb: (evt: IngestProgressEvent) => void): () => void;
237
+ /** Writer 自产事件(describe-pending 等);归属补齐口径与 IngestProgressEvent 一致 */
238
+ private emitProgress;
195
239
  dispose(): Promise<void>;
196
240
  }
@@ -4,11 +4,14 @@
4
4
  * 生产:Writer Worker 持有 knowledge.db + ingest;API 经 RPC 调用。
5
5
  * 测试 / :memory::LocalKnowledgeWriteService 同进程实现(同一接口)。
6
6
  */
7
+ import { DEFAULT_TENANT_ID, PLATFORM_TENANT_ID } from '@octopi-agent/core/types.js';
7
8
  import { KnowledgeSourceStore } from './source-store.js';
8
9
  import { KnowledgeIndexStore } from './index-store.js';
9
10
  import { MembershipStore } from './membership-store.js';
10
11
  import { KnowledgeIngest } from './ingest.js';
11
- import { generateKnowledgeDescription } from './describe.js';
12
+ import { generateKnowledgeDescription, normalizeGeneratedDescription, } from './describe.js';
13
+ import { assembleDescribeSample, DESCRIBE_SAMPLE_MAX_CHARS } from './describe-sample.js';
14
+ import { scanSecretShapes } from './secret-scan.js';
12
15
  /** 进程内唯一写者(测试 / :memory:)。 */
13
16
  export class LocalKnowledgeWriteService {
14
17
  deps;
@@ -29,6 +32,7 @@ export class LocalKnowledgeWriteService {
29
32
  documentConfig: deps.documentConfig ?? null,
30
33
  embeddingProvider: embed?.enabled === false ? null : (deps.embeddingProvider ?? null),
31
34
  credentials: deps.credentials ?? null,
35
+ ...(deps.ingest ?? {}),
32
36
  ...(embed?.embedBatch != null ? { embedBatch: embed.embedBatch } : {}),
33
37
  ...(embed?.embedMinIntervalMs != null ? { embedMinIntervalMs: embed.embedMinIntervalMs } : {}),
34
38
  ...(embed?.embedConcurrency != null ? { embedConcurrency: embed.embedConcurrency } : {}),
@@ -98,6 +102,15 @@ export class LocalKnowledgeWriteService {
98
102
  code: 'not_resource_owner',
99
103
  });
100
104
  }
105
+ // 评审 m3:visibility='public' 是跨租户共享面动作,只接受显式 claim 'platform' 的写——
106
+ // 租户/无断言写造出的 'public' 不产生共享语义,如实拒绝而非假成功
107
+ if (input.visibility === 'public' && this.deps.allowPublic !== true) {
108
+ throw Object.assign(new Error("visibility 'public' is disabled (knowledge.projects.allowPublic=false) — public projects are cross-tenant shared assets"), { code: 'public_projects_disabled' });
109
+ }
110
+ if (input.visibility === 'public' &&
111
+ !(identity.claimed && identity.tenantId === PLATFORM_TENANT_ID)) {
112
+ throw Object.assign(new Error("visibility 'public' requires an explicit platform claim"), { code: 'visibility_requires_platform_claim' });
113
+ }
101
114
  this.sources.createProject(input.projectKey, input.displayName, {
102
115
  tenantId: identity.tenantId,
103
116
  registeredBy: identity.gatewayId,
@@ -141,11 +154,24 @@ export class LocalKnowledgeWriteService {
141
154
  delete input.registered_by;
142
155
  delete input.tenantId;
143
156
  delete input.tenant_id;
144
- const src = this.sources.register(input);
157
+ // 归属打标(arch/multi-tenancy.md §6,评审 MAJ-1 修配套):
158
+ // - claim 在场 = 显式归属(含显式 claim 'platform' = 公共库)
159
+ // - platform token 无 claim = 受信 broker 的未声明建档 → 降级 default 域(存量语义,
160
+ // 永不放大成 platform 共享)并告警
161
+ // - 租户 token 无 claim = token 域(旧语义不变)
162
+ let ownerTenant = identity.tenantId;
163
+ if (!identity.claimed && identity.tenantId === PLATFORM_TENANT_ID) {
164
+ ownerTenant = DEFAULT_TENANT_ID;
165
+ console.warn(`[Knowledge] registerSource without ownership claim stamped to "${DEFAULT_TENANT_ID}" domain; assert x-octopi-tenant to declare ownership`);
166
+ }
167
+ const src = this.sources.register(input, {
168
+ tenantId: ownerTenant,
169
+ registeredBy: identity.gatewayId,
170
+ });
145
171
  this.db.raw
146
172
  .prepare(`UPDATE knowledge_sources SET registered_by = ?, visibility = ?, tenant_id = ?
147
173
  WHERE id = ?`)
148
- .run(identity.gatewayId, typeof input.visibility === 'string' ? input.visibility : 'private', identity.tenantId, src.id);
174
+ .run(identity.gatewayId, typeof input.visibility === 'string' ? input.visibility : 'private', ownerTenant, src.id);
149
175
  void this.ingest.ingestSource(src.id, { full: true }).catch((e) => {
150
176
  console.warn(`[Knowledge] auto-ingest after register failed (${src.id}): ${e instanceof Error ? e.message : String(e)}`);
151
177
  });
@@ -153,11 +179,9 @@ export class LocalKnowledgeWriteService {
153
179
  }
154
180
  async updateSource(identity, sourceId, patch) {
155
181
  const row = this.db.raw
156
- .prepare('SELECT registered_by FROM knowledge_sources WHERE id = ?')
182
+ .prepare('SELECT registered_by, tenant_id FROM knowledge_sources WHERE id = ?')
157
183
  .get(sourceId);
158
- if (row?.registered_by && row.registered_by !== identity.gatewayId) {
159
- throw Object.assign(new Error('not source owner'), { code: 'not_resource_owner' });
160
- }
184
+ this.assertSourceWritable(identity, row, sourceId);
161
185
  const updated = this.sources.update(sourceId, patch);
162
186
  if (!updated)
163
187
  return null;
@@ -174,40 +198,102 @@ export class LocalKnowledgeWriteService {
174
198
  throw Object.assign(new Error('source not found'), { code: 'source_not_found' });
175
199
  }
176
200
  const row = this.db.raw
177
- .prepare('SELECT registered_by FROM knowledge_sources WHERE id = ?')
201
+ .prepare('SELECT registered_by, tenant_id FROM knowledge_sources WHERE id = ?')
178
202
  .get(sourceId);
179
- if (row?.registered_by && row.registered_by !== identity.gatewayId) {
180
- throw Object.assign(new Error('not source owner'), { code: 'not_resource_owner' });
181
- }
203
+ this.assertSourceWritable(identity, row, sourceId);
182
204
  // 先停在途 parse/embed:否则 purge 让出窗口内 upsert 会把 File/Chunk 再写回来
183
205
  this.ingest.abortJobs({ sourceId });
184
206
  const purged = await this.memberships.unclaimAllForSourceAsync(sourceId, (fileId) => this.index.purgeFileAsync(fileId));
185
207
  this.sources.remove(sourceId);
186
208
  return { id: sourceId, purgedFiles: purged.length };
187
209
  }
188
- async describeSource(identity, sourceId) {
210
+ async describeSource(identity, sourceId, input) {
189
211
  await this.assertSourceOwner(identity, sourceId);
190
212
  const src = this.sources.get(sourceId);
191
213
  if (!src)
192
214
  return null;
193
- const paths = this.db.raw
194
- .prepare('SELECT logical_path FROM knowledge_memberships WHERE source_id = ? ORDER BY logical_path LIMIT 20')
195
- .all(sourceId);
196
- const sample = paths.map((p) => p.logical_path).join('\n') || src.location;
197
- const r = await generateKnowledgeDescription(src, sample, { enabled: true });
198
- this.sources.update(sourceId, { generatedDescription: r.description });
215
+ if (input?.description != null) {
216
+ // 写入口(B 方案回写):调用方是 gateway 的 LLM describe 流程;内容在出 Service 前过密钥扫描,
217
+ // 但描述会进系统提示 catalog 行——写入侧强制单行归一(防多行注入伪造 catalog 行)
218
+ const text = normalizeGeneratedDescription(input.description);
219
+ if (!text) {
220
+ throw Object.assign(new Error('description empty'), { code: 'bad_request' });
221
+ }
222
+ const source = input.source === 'heuristic' ? 'heuristic' : 'llm';
223
+ this.sources.update(sourceId, {
224
+ generatedDescription: text,
225
+ generatedDescriptionSource: source,
226
+ });
227
+ return { generatedDescription: text, source };
228
+ }
229
+ const r = await this.describeWithSample(src);
230
+ this.sources.update(sourceId, {
231
+ generatedDescription: r.description,
232
+ generatedDescriptionSource: r.source === 'disabled' ? 'heuristic' : r.source,
233
+ });
199
234
  return { generatedDescription: r.description, source: r.source };
200
235
  }
236
+ async describeSample(identity, sourceId) {
237
+ await this.assertSourceOwner(identity, sourceId);
238
+ const src = this.sources.get(sourceId);
239
+ if (!src)
240
+ return null;
241
+ const sample = assembleDescribeSample(this.db, sourceId);
242
+ // 密钥形态封锁:命中即不外发样本(fail-safe,同 generateKnowledgeDescription 口径)
243
+ const secretHits = scanSecretShapes(sample);
244
+ if (secretHits.length > 0)
245
+ return { blocked: true, secretHits };
246
+ return {
247
+ blocked: false,
248
+ meta: { displayName: src.displayName, kind: src.kind, location: src.location },
249
+ sample,
250
+ };
251
+ }
252
+ async listDescribePending(identity) {
253
+ // 待升级 = 有启发式/legacy 自动描述、无人工描述、归因非 llm(legacy NULL 视为 heuristic)
254
+ const rows = this.db.raw
255
+ .prepare(`SELECT id FROM knowledge_sources
256
+ WHERE generated_description IS NOT NULL
257
+ AND description IS NULL
258
+ AND (generated_description_source IS NULL OR generated_description_source = 'heuristic')
259
+ AND status NOT IN ('removed', 'disabled')
260
+ AND (registered_by IS NULL OR registered_by = '' OR registered_by = ?)`)
261
+ .all(identity.gatewayId);
262
+ return rows.map((r) => r.id);
263
+ }
264
+ /** 启发式/封锁描述生成(无 describePort:Service 侧永不含 LLM 出网,B 方案拍板) */
265
+ describeWithSample(src) {
266
+ const sample = assembleDescribeSample(this.db, src.id);
267
+ return generateKnowledgeDescription(src, sample, {
268
+ enabled: true,
269
+ sampleChars: DESCRIBE_SAMPLE_MAX_CHARS,
270
+ });
271
+ }
272
+ /**
273
+ * 源写权限(arch/multi-tenancy.md §6,评审 MAJ-5):
274
+ * 网关漏斗(registered_by)⊕ 租户域(tenant_id)——platform 身份 = 运维豁免;
275
+ * 租户身份只可写本域源。缺行按无约束放行(老库/投影缺失),由调用方的 not-found 路径兜底。
276
+ */
277
+ assertSourceWritable(identity, row, sourceId) {
278
+ if (row?.registered_by && row.registered_by !== identity.gatewayId) {
279
+ throw Object.assign(new Error('not source owner'), { code: 'not_resource_owner' });
280
+ }
281
+ if (row?.tenant_id &&
282
+ identity.tenantId !== PLATFORM_TENANT_ID &&
283
+ row.tenant_id !== identity.tenantId) {
284
+ throw Object.assign(new Error(`source ${sourceId} belongs to another tenant domain`), {
285
+ code: 'not_resource_owner',
286
+ });
287
+ }
288
+ }
201
289
  async assertSourceOwner(identity, sourceId) {
202
290
  const row = this.db.raw
203
- .prepare('SELECT registered_by FROM knowledge_sources WHERE id = ?')
291
+ .prepare('SELECT registered_by, tenant_id FROM knowledge_sources WHERE id = ?')
204
292
  .get(sourceId);
205
293
  if (!row) {
206
294
  throw Object.assign(new Error('source not found'), { code: 'source_not_found' });
207
295
  }
208
- if (row.registered_by && row.registered_by !== identity.gatewayId) {
209
- throw Object.assign(new Error('not source owner'), { code: 'not_resource_owner' });
210
- }
296
+ this.assertSourceWritable(identity, row, sourceId);
211
297
  }
212
298
  async reindexSource(sourceId) {
213
299
  void this.ingest.ingestSource(sourceId, { full: true }).catch((e) => {
@@ -263,6 +349,12 @@ export class LocalKnowledgeWriteService {
263
349
  return true;
264
350
  }
265
351
  async assignProject(identity, agentId, projectKey) {
352
+ // 写侧防绕过(收紧配套):不可见项目的 key 不得经分配 grant 进入 agent 视图
353
+ if (!this.sources.isProjectVisibleTo(projectKey, identity)) {
354
+ throw Object.assign(new Error(`project not visible to writer: ${projectKey}`), {
355
+ code: 'project_not_visible',
356
+ });
357
+ }
266
358
  this.sources.assignProject(projectKey, agentId, identity);
267
359
  }
268
360
  async unassignProject(identity, agentId, projectKey) {
@@ -274,6 +366,30 @@ export class LocalKnowledgeWriteService {
274
366
  async unhideSource(identity, agentId, sourceId) {
275
367
  this.sources.unhideSource(agentId, sourceId, identity);
276
368
  }
369
+ async mountSource(identity, agentId, sourceId) {
370
+ // 写侧防绕过(收紧配套):不可见源不得经挂载 grant 进入 agent 视图
371
+ // (与读侧同口径:租户闸 ⊕ 网关漏斗 ⊕ 项目跨域闸,fail-loud 而非写成无效挂载)
372
+ const src = this.sources.get(sourceId);
373
+ if (!src) {
374
+ // 评审 m4:未知源 fail-loud,不静默写 include 行
375
+ throw Object.assign(new Error(`source not found: ${sourceId}`), {
376
+ code: 'source_not_found',
377
+ });
378
+ }
379
+ const visible = this.sources.isTenantVisible(src, identity) &&
380
+ this.sources.isGatewayVisible(src, identity) &&
381
+ (src.scopeRef.level !== 'project' ||
382
+ this.sources.isProjectVisible(src, src.scopeRef.key, identity));
383
+ if (!visible) {
384
+ throw Object.assign(new Error(`source not visible to writer: ${sourceId}`), {
385
+ code: 'source_not_visible',
386
+ });
387
+ }
388
+ this.sources.mountSource(agentId, sourceId, identity);
389
+ }
390
+ async unmountSource(identity, agentId, sourceId) {
391
+ this.sources.unmountSource(agentId, sourceId, identity);
392
+ }
277
393
  async replaceSessionVisibility(identity, _agentId, sessionId, items) {
278
394
  const typed = items.map((raw) => {
279
395
  const targetType = raw.targetType;
@@ -292,8 +408,8 @@ export class LocalKnowledgeWriteService {
292
408
  async setSessionVisibilityItem(identity, sessionId, item) {
293
409
  this.sources.setSessionVisibility(sessionId, item, identity);
294
410
  }
295
- async clearSessionVisibility(identity, sessionId, target) {
296
- this.sources.clearSessionVisibility(sessionId, target, identity);
411
+ async clearSessionVisibility(identity, sessionId, target, op) {
412
+ this.sources.clearSessionVisibility(sessionId, target, identity, op);
297
413
  }
298
414
  async isSourceOwner(sourceId, gatewayId) {
299
415
  return this.isOwnerRow(sourceId, gatewayId);
@@ -311,17 +427,41 @@ export class LocalKnowledgeWriteService {
311
427
  async startIngestRuntime() {
312
428
  const { sources, ingest } = this;
313
429
  ingest.onSourceSettled = (sourceId) => {
430
+ // catalog.autoDescribe=false:索引稳定后不自动生成 generatedDescription(v0.51.5 语义)
431
+ if (this.deps.autoDescribe === false)
432
+ return;
314
433
  void (async () => {
315
434
  try {
316
435
  const src = sources.get(sourceId);
317
436
  if (!src || src.description?.trim())
318
437
  return;
319
- const paths = this.db.raw
320
- .prepare('SELECT logical_path FROM knowledge_memberships WHERE source_id = ? ORDER BY logical_path LIMIT 20')
321
- .all(sourceId);
322
- const sample = paths.map((p) => p.logical_path).join('\n') || src.location;
323
- const r = await generateKnowledgeDescription(src, sample, { enabled: true });
324
- sources.update(sourceId, { generatedDescription: r.description });
438
+ // llm 归因是更高信任档:settle 不降级、不重发(B 方案 2026-11-02)
439
+ if (src.generatedDescriptionSource === 'llm')
440
+ return;
441
+ const r = await this.describeWithSample(src);
442
+ const source = r.source === 'disabled' ? 'heuristic' : r.source;
443
+ // startReconciler 每 15s 对稳态源反复触发本钩子(ingest.ts):文本与归因都
444
+ // 无变化则不写不发,掐断「每 tick 重发 describe-pending → gateway 每 tick
445
+ // LLM 升级」成本环。归因必须参与比较——blocked_secret 与 heuristic 共享同一
446
+ // 启发式文本,只比文本会让「封锁→清洁」的归因回退永远卡死(评审 P1-1)
447
+ if (src.generatedDescription === r.description &&
448
+ src.generatedDescriptionSource === source) {
449
+ return;
450
+ }
451
+ sources.update(sourceId, {
452
+ generatedDescription: r.description,
453
+ generatedDescriptionSource: source,
454
+ });
455
+ // B 方案(2026-11-02 拍板):LLM 描述由 gateway 代生成。
456
+ // 启发式落库即发升级信号;blocked_secret(抽样含密钥形态)不发——素材不得外发。
457
+ if (source === 'heuristic') {
458
+ this.emitProgress({
459
+ type: 'source',
460
+ sourceId,
461
+ status: 'describe-pending',
462
+ detail: 'llm upgrade eligible',
463
+ });
464
+ }
325
465
  }
326
466
  catch {
327
467
  /* describe 失败不影响索引 */
@@ -349,6 +489,36 @@ export class LocalKnowledgeWriteService {
349
489
  this.progressCbs.delete(cb);
350
490
  };
351
491
  }
492
+ /** Writer 自产事件(describe-pending 等);归属补齐口径与 IngestProgressEvent 一致 */
493
+ emitProgress(evt) {
494
+ let out = evt;
495
+ if (evt.sourceId && evt.registeredBy === undefined) {
496
+ try {
497
+ const row = this.db.raw
498
+ .prepare('SELECT tenant_id, registered_by, visibility FROM knowledge_sources WHERE id = ?')
499
+ .get(evt.sourceId);
500
+ if (row) {
501
+ out = {
502
+ ...evt,
503
+ tenantId: row.tenant_id,
504
+ registeredBy: row.registered_by,
505
+ visibility: row.visibility,
506
+ };
507
+ }
508
+ }
509
+ catch {
510
+ /* 源已删时保持原事件;SSE 侧按无归属放行到 fallback */
511
+ }
512
+ }
513
+ for (const cb of this.progressCbs) {
514
+ try {
515
+ cb(out);
516
+ }
517
+ catch {
518
+ /* SSE 订阅方异常不得打断 describe */
519
+ }
520
+ }
521
+ }
352
522
  async dispose() {
353
523
  this.progressCbs.clear();
354
524
  this.ingest.dispose();
@@ -1,23 +1,27 @@
1
- import type { KnowledgeWriteService, WriteIdentity, WriteAbortStats, WriteResumeStats, WriteRegisterResult, WriteDescribeResult, WriteReprocessResult } from './writer-service.js';
1
+ import type { KnowledgeWriteService, WriteIdentity, WriteAbortStats, WriteResumeStats, WriteRegisterResult, WriteDescribeResult, WriteDescribeInput, WriteDescribeSampleResult, WriteReprocessResult } from './writer-service.js';
2
2
  import type { KnowledgeSource } from './types.js';
3
3
  import type { KnowledgeJobControlState } from './job-control-state.js';
4
4
  import type { IngestProgressEvent } from './ingest.js';
5
5
  import type { DocumentCapabilityConfig } from '../capabilities/document/factory.js';
6
+ import type { KnowledgeBootEmbed, KnowledgeBootIngest } from './boot-config.js';
6
7
  export interface WorkerWriteStartOptions {
7
8
  dbPath: string;
8
9
  documentConfig?: DocumentCapabilityConfig | null;
9
- sqliteVecExtensionPath?: string;
10
+ sqliteVec?: boolean | {
11
+ extensionPath?: string;
12
+ require?: boolean;
13
+ };
14
+ /** 跨租户共享闸(B-5):允许创建 visibility='public' 项目 */
15
+ allowPublic?: boolean;
10
16
  embeddingModels?: {
11
17
  providers?: Record<string, unknown>;
12
18
  embedding?: unknown;
13
19
  } | null;
14
- embed?: {
15
- enabled?: boolean;
16
- embedBatch?: number;
17
- embedMinIntervalMs?: number;
18
- embedConcurrency?: number;
19
- embedSecretPolicy?: 'allow' | 'redact' | 'skip';
20
- } | null;
20
+ embed?: KnowledgeBootEmbed | null;
21
+ /** Ingest 调参(knowledge.load / index.queue / index.files) */
22
+ ingest?: KnowledgeBootIngest | null;
23
+ /** false = 索引稳定后不自动生成 generatedDescription(knowledge.catalog.autoDescribe) */
24
+ autoDescribe?: boolean;
21
25
  testEmbeddingStub?: boolean;
22
26
  timeoutMs?: number;
23
27
  }
@@ -64,7 +68,9 @@ export declare class WorkerWriteService implements KnowledgeWriteService {
64
68
  id: string;
65
69
  purgedFiles: number;
66
70
  }>;
67
- describeSource(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeResult | null>;
71
+ describeSource(identity: WriteIdentity, sourceId: string, input?: WriteDescribeInput): Promise<WriteDescribeResult | null>;
72
+ describeSample(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeSampleResult | null>;
73
+ listDescribePending(identity: WriteIdentity): Promise<string[]>;
68
74
  reindexSource(sourceId: string): Promise<void>;
69
75
  reprocessFiles(sourceId: string, paths: string[]): Promise<WriteReprocessResult>;
70
76
  reprocessByFilter(sourceId: string, filter?: {
@@ -80,6 +86,8 @@ export declare class WorkerWriteService implements KnowledgeWriteService {
80
86
  unassignProject(identity: WriteIdentity, agentId: string, projectKey: string): Promise<void>;
81
87
  hideSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
82
88
  unhideSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
89
+ mountSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
90
+ unmountSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
83
91
  replaceSessionVisibility(identity: WriteIdentity, agentId: string, sessionId: string, items: Array<{
84
92
  targetType: string;
85
93
  targetId: string;
@@ -93,7 +101,7 @@ export declare class WorkerWriteService implements KnowledgeWriteService {
93
101
  clearSessionVisibility(identity: WriteIdentity, sessionId: string, target?: {
94
102
  targetType: 'project' | 'source';
95
103
  targetId: string;
96
- }): Promise<void>;
104
+ }, op?: 'include' | 'exclude'): Promise<void>;
97
105
  isSourceOwner(sourceId: string, gatewayId: string): Promise<boolean>;
98
106
  sourceVisibleToGateway(sourceId: string, gatewayId: string): Promise<boolean>;
99
107
  startIngestRuntime(): Promise<void>;
@@ -90,9 +90,12 @@ export class WorkerWriteService {
90
90
  workerData: {
91
91
  dbPath: opts.dbPath,
92
92
  documentConfig: opts.documentConfig ?? null,
93
- sqliteVecExtensionPath: opts.sqliteVecExtensionPath,
93
+ sqliteVec: opts.sqliteVec,
94
+ allowPublic: opts.allowPublic,
94
95
  embeddingModels: opts.embeddingModels ?? null,
95
96
  embed: opts.embed ?? null,
97
+ ingest: opts.ingest ?? null,
98
+ autoDescribe: opts.autoDescribe,
96
99
  testEmbeddingStub: opts.testEmbeddingStub ?? false,
97
100
  },
98
101
  env: process.env,
@@ -225,9 +228,25 @@ export class WorkerWriteService {
225
228
  this.rethrow(e);
226
229
  }
227
230
  }
228
- async describeSource(identity, sourceId) {
231
+ async describeSource(identity, sourceId, input) {
229
232
  try {
230
- return (await this.call('describeSource', { identity, sourceId }));
233
+ return (await this.call('describeSource', { identity, sourceId, input }));
234
+ }
235
+ catch (e) {
236
+ this.rethrow(e);
237
+ }
238
+ }
239
+ async describeSample(identity, sourceId) {
240
+ try {
241
+ return (await this.call('describeSample', { identity, sourceId }));
242
+ }
243
+ catch (e) {
244
+ this.rethrow(e);
245
+ }
246
+ }
247
+ async listDescribePending(identity) {
248
+ try {
249
+ return (await this.call('listDescribePending', { identity }));
231
250
  }
232
251
  catch (e) {
233
252
  this.rethrow(e);
@@ -321,6 +340,22 @@ export class WorkerWriteService {
321
340
  this.rethrow(e);
322
341
  }
323
342
  }
343
+ async mountSource(identity, agentId, sourceId) {
344
+ try {
345
+ await this.call('mountSource', { identity, agentId, sourceId });
346
+ }
347
+ catch (e) {
348
+ this.rethrow(e);
349
+ }
350
+ }
351
+ async unmountSource(identity, agentId, sourceId) {
352
+ try {
353
+ await this.call('unmountSource', { identity, agentId, sourceId });
354
+ }
355
+ catch (e) {
356
+ this.rethrow(e);
357
+ }
358
+ }
324
359
  async replaceSessionVisibility(identity, agentId, sessionId, items) {
325
360
  try {
326
361
  return (await this.call('replaceSessionVisibility', {
@@ -342,9 +377,9 @@ export class WorkerWriteService {
342
377
  this.rethrow(e);
343
378
  }
344
379
  }
345
- async clearSessionVisibility(identity, sessionId, target) {
380
+ async clearSessionVisibility(identity, sessionId, target, op) {
346
381
  try {
347
- await this.call('clearSessionVisibility', { identity, sessionId, target });
382
+ await this.call('clearSessionVisibility', { identity, sessionId, target, op });
348
383
  }
349
384
  catch (e) {
350
385
  this.rethrow(e);