@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
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Host-owned contribution instance tracking for factory-backed kinds
3
+ * (providers, channels). Not exported through the author SDK; authors reach it
4
+ * only through `PluginApi.getContributionInstance`.
5
+ *
6
+ * Lifecycle model: an instance is born when the Host **accepts** the factory
7
+ * product (post-validation, i.e. exactly what the Host routes to) and dies by
8
+ * one of two triggers:
9
+ * - physical: the Host calls its lifecycle method (`stop()` for channels,
10
+ * `dispose()` for providers) — recorded when the call is *requested*,
11
+ * regardless of outcome, because the Host will not revive it either way;
12
+ * - logical: a newer instance is accepted for the same contribution key and
13
+ * label (config hot-reload replace). The superseded instance may still serve
14
+ * draining in-flight work; it is simply no longer returned by lookup.
15
+ *
16
+ * Storage follows the staging pattern: one table per PluginApi, created by the
17
+ * host loader, so a plugin can only ever see instances of its own
18
+ * contributions.
19
+ */
20
+ const tables = new WeakMap();
21
+ /** Called only by the host when constructing an author API. */
22
+ export function createInstanceTable(api) {
23
+ const table = new ContributionInstanceTable();
24
+ tables.set(api, table);
25
+ return table;
26
+ }
27
+ /** Read the host-owned instance table of one author API. */
28
+ export function readInstanceTable(api) {
29
+ const table = tables.get(api);
30
+ if (!table)
31
+ throw new Error('PluginApi was not created by the host loader');
32
+ return table;
33
+ }
34
+ export class ContributionInstanceTable {
35
+ entries = [];
36
+ /**
37
+ * Record one Host-accepted instance and wrap its retirement method so the
38
+ * entry retires together with the instance. Wrapping happens here — the
39
+ * single registration path — so every Host teardown call site is covered
40
+ * without explicit retire calls.
41
+ *
42
+ * Acceptance semantics:
43
+ * - a newer instance for the same (kind, key, label) supersedes the previous
44
+ * one (config hot-reload replace); the superseded entry is marked retired;
45
+ * - re-accepting the *same* object (singleton factories) refreshes its label
46
+ * instead of double-registering it;
47
+ * - an instance that cannot be tracked is **not registered**: a non-object
48
+ * product, a frozen/sealed object whose retirement method cannot be
49
+ * wrapped, or (channels) a product without `stop` — in every case the
50
+ * Host's own contract validation is the authority that reports the broken
51
+ * adapter, and this method never invents methods it does not own.
52
+ *
53
+ * @param opts - Instance identity and retirement wiring
54
+ * @returns Whether the instance was registered (tracked)
55
+ */
56
+ attach(opts) {
57
+ const target = opts.instance;
58
+ // Callables are valid contract objects; only primitives/null are not.
59
+ if (typeof target !== 'object' && typeof target !== 'function')
60
+ return false;
61
+ if (target === null || target === undefined)
62
+ return false;
63
+ const same = this.entries.find((entry) => entry.kind === opts.kind && entry.key === opts.key && entry.instance === target);
64
+ if (same) {
65
+ // Re-acceptance (e.g. a singleton factory product that was retired and
66
+ // is being served again): the instance is live again as of now.
67
+ same.label = opts.label;
68
+ same.state = 'live';
69
+ return true;
70
+ }
71
+ const original = target[opts.retireMethod];
72
+ const entry = {
73
+ kind: opts.kind,
74
+ key: opts.key,
75
+ label: opts.label,
76
+ instance: target,
77
+ state: 'live',
78
+ superseded: [],
79
+ };
80
+ const retire = () => {
81
+ entry.state = 'retired';
82
+ };
83
+ if (typeof original === 'function') {
84
+ try {
85
+ target[opts.retireMethod] = function (...args) {
86
+ retire();
87
+ return original.apply(target, args);
88
+ };
89
+ }
90
+ catch {
91
+ // Frozen/sealed instance: retirement cannot be tracked. Leaving it
92
+ // unregistered keeps lookup honest ("never instantiated") instead of
93
+ // handing out an instance the Host has already stopped.
94
+ return false;
95
+ }
96
+ }
97
+ else if (opts.defineRetire) {
98
+ try {
99
+ target[opts.retireMethod] = retire;
100
+ }
101
+ catch {
102
+ return false;
103
+ }
104
+ }
105
+ else {
106
+ // Missing mandatory lifecycle method: a broken adapter. The Host's
107
+ // contract validation reports it; never patch `stop` here or that check
108
+ // would stop being honest. Untracked for the same reason as frozen.
109
+ return false;
110
+ }
111
+ // Logical retirement of the superseded instance (recorded for rollback),
112
+ // then prune retired tombstones to one per (kind, key) — lookup only
113
+ // distinguishes "was retired" from "never instantiated", so one tombstone
114
+ // is enough. Pruned tombstones stay reachable through `superseded`.
115
+ for (const prior of this.entries) {
116
+ if (prior.kind === opts.kind && prior.key === opts.key && prior.label === opts.label && prior.state === 'live') {
117
+ prior.state = 'retired';
118
+ entry.superseded.push(prior);
119
+ }
120
+ }
121
+ const retired = this.entries.filter((e) => e.kind === opts.kind && e.key === opts.key && e.state === 'retired');
122
+ for (const tomb of retired.slice(0, -1)) {
123
+ this.entries.splice(this.entries.indexOf(tomb), 1);
124
+ }
125
+ this.entries.push(entry);
126
+ return true;
127
+ }
128
+ /**
129
+ * Every recorded entry for one contribution key (live and retired).
130
+ *
131
+ * @param kind - Contribution kind
132
+ * @param key - Contribution key
133
+ * @returns Matching entries in instantiation order
134
+ */
135
+ find(kind, key) {
136
+ return this.entries.filter((entry) => entry.kind === kind && entry.key === key);
137
+ }
138
+ /**
139
+ * Logical retirement by instance identity — called by the Host when it
140
+ * stops routing to an instance (removal, hot-reload replace, config reset).
141
+ * Idempotent; the wrapped lifecycle method remains the physical backstop.
142
+ *
143
+ * @param instance - The instance object the Host stopped routing to
144
+ */
145
+ retireByInstance(instance) {
146
+ for (const entry of this.entries) {
147
+ if (entry.instance === instance)
148
+ entry.state = 'retired';
149
+ }
150
+ }
151
+ /**
152
+ * Roll back an acceptance of an instance that was validated but never
153
+ * installed (the Host aborted before routing to it). Removes its entry and
154
+ * resurrects the entries it superseded, so "live" again matches what the
155
+ * Host serves. No-op once the entry is not the current live one.
156
+ *
157
+ * @param instance - The accepted-but-never-installed instance
158
+ */
159
+ discardByInstance(instance) {
160
+ const entry = this.entries.find((e) => e.instance === instance);
161
+ if (!entry || entry.state !== 'live')
162
+ return;
163
+ this.entries.splice(this.entries.indexOf(entry), 1);
164
+ for (const prior of entry.superseded) {
165
+ prior.state = 'live';
166
+ if (!this.entries.includes(prior))
167
+ this.entries.push(prior);
168
+ }
169
+ }
170
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Declarative contribution-kind table — the single source of truth for the
3
+ * plugin contribution pipeline semantics: staging uniqueness, reserved ids,
4
+ * publish ownership, manifest claims, manifest uniqueness and manifest↔
5
+ * registration reconciliation.
6
+ *
7
+ * Adding a contribution kind = one descriptor here + the typed surfaces
8
+ * (PluginApi.registerXxx signature, staging slot, record type/getter, manifest
9
+ * schema field). The staging write path (`push`, via `stageContribution`) and
10
+ * the staged-entry read path (`forEachStaged`, which pairs entries with their
11
+ * keys) both live on the descriptor, so the key↔entry pairing and the
12
+ * uniqueness checks cannot be bypassed or forgotten per kind.
13
+ *
14
+ * Hooks are the deliberate semantic exception (multi-handler per name, no
15
+ * cross-plugin ownership), but their staging write path — priority-sorted Map
16
+ * insert — is also owned here (`hooks.push`), not by `PluginApi.on`.
17
+ */
18
+ import type { ContributionInstanceTable } from './contribution-instances.js';
19
+ import type { OrderedHookEntry, PluginChannelRegistration, PluginCommandRegistration, PluginProviderRegistration, PluginToolContribution } from './api.js';
20
+ import type { HookServiceRegistration } from '../hooks/types.js';
21
+ import type { PluginManifest } from './manifest.js';
22
+ import type { StagedContributions } from './staging.js';
23
+ /** Field name shared by the manifest `contributes` block and the staging slot. */
24
+ export type ContributionField = 'tools' | 'commands' | 'hooks' | 'services' | 'providers' | 'channels';
25
+ /**
26
+ * Published-record slots. Records are uniformly `{ pluginId, ...entry }`
27
+ * (hooks entries already carry `pluginId`, so they are stored verbatim). The
28
+ * registry's typed getters return these slots; their declared record types are
29
+ * structurally identical, so drift is caught at compile time.
30
+ */
31
+ export interface ContributionSink {
32
+ tools: ({
33
+ pluginId: string;
34
+ } & PluginToolContribution)[];
35
+ commands: ({
36
+ pluginId: string;
37
+ } & PluginCommandRegistration)[];
38
+ hooks: OrderedHookEntry[];
39
+ services: ({
40
+ pluginId: string;
41
+ } & HookServiceRegistration)[];
42
+ providers: ({
43
+ pluginId: string;
44
+ } & PluginProviderRegistration)[];
45
+ channels: ({
46
+ pluginId: string;
47
+ } & PluginChannelRegistration)[];
48
+ }
49
+ /** Host-private hook that factory-backed records carry (see record.acceptInstance). */
50
+ export interface ContributionInstanceHostHook {
51
+ /**
52
+ * Register the Host-accepted instance (birth) with its config identity.
53
+ *
54
+ * @param instance - The accepted factory product
55
+ * @param label - Config identity of this instantiation
56
+ * @returns Whether the instance is retirement-trackable; false means it was
57
+ * not registered (frozen/sealed) and the Host should surface the
58
+ * degradation — lookup will report it as never instantiated
59
+ */
60
+ acceptInstance(instance: object, label: string): boolean;
61
+ }
62
+ export interface ContributionKind<TEntry extends object> {
63
+ /** Manifest `contributes.<field>` / staging slot name. */
64
+ readonly field: ContributionField;
65
+ /**
66
+ * Singular label used in diagnostics and ownership keys ("provider"). The
67
+ * ownership key prefix (`tool:`, `provider:`, …) IS this label — changing it
68
+ * changes conflict identity, so treat labels as stable identifiers.
69
+ */
70
+ readonly label: string;
71
+ /** Whether one key may be owned by only one plugin (hooks chain across plugins). */
72
+ readonly globallyUnique: boolean;
73
+ /** Whether one plugin may stage the same key only once (hooks allow many handlers). */
74
+ readonly perPluginUnique: boolean;
75
+ /** Ids plugins may never claim (built-in adapters). */
76
+ readonly reservedIds: readonly string[];
77
+ /** Unique key of one staged entry. */
78
+ keyOf(entry: TEntry): string;
79
+ /** Keys declared in the manifest `contributes` block (raw, unnormalized). */
80
+ declaredKeys(manifest: PluginManifest): string[];
81
+ /**
82
+ * Iterate staged entries paired with their keys — the read side's single
83
+ * path. The pairing is computed inside the descriptor, so consumers cannot
84
+ * observe a key without its entry or vice versa.
85
+ */
86
+ forEachStaged(slot: StagedContributions, visit: (key: string, entry: TEntry) => void): void;
87
+ /** Stage one entry — the write side's single path (hooks: priority-sorted Map insert). */
88
+ push(slot: StagedContributions, entry: TEntry): void;
89
+ /** Append one published record to the registry sink. */
90
+ collect(sink: ContributionSink, pluginId: string, entry: TEntry): void;
91
+ /**
92
+ * Factory-backed kinds only: extend the staged entry with the host-private
93
+ * `acceptInstance` hook so the Host can register the instance it accepted
94
+ * (birth) and the table can track its retirement. The wiring lives here,
95
+ * like `push`, so a new factory kind cannot silently produce untracked
96
+ * instances — the return type makes the hook mandatory at compile time.
97
+ */
98
+ bindInstances?(entry: TEntry, instances: ContributionInstanceTable): TEntry & ContributionInstanceHostHook;
99
+ /** Kind-specific manifest checks beyond per-kind key uniqueness. */
100
+ assertManifestExtras?(manifest: PluginManifest): void;
101
+ /** Kind-specific manifest↔registration reconciliation beyond key matching. */
102
+ reconcileExtra?(manifest: PluginManifest, slot: StagedContributions): void;
103
+ }
104
+ /**
105
+ * Every contribution kind in manifest-schema order. Iteration order is
106
+ * observable in first-failure diagnostics and record ordering — keep it aligned
107
+ * with the `contributes` schema field order.
108
+ */
109
+ export declare const CONTRIBUTION_KINDS: readonly ContributionKind<object>[];
110
+ /** Typed staging slots for the author-facing register methods. */
111
+ export declare const TOOL_KIND: ContributionKind<PluginToolContribution>;
112
+ export declare const COMMAND_KIND: ContributionKind<PluginCommandRegistration>;
113
+ export declare const HOOK_KIND: ContributionKind<OrderedHookEntry>;
114
+ export declare const SERVICE_KIND: ContributionKind<HookServiceRegistration>;
115
+ export declare const PROVIDER_KIND: ContributionKind<PluginProviderRegistration>;
116
+ export declare const CHANNEL_KIND: ContributionKind<PluginChannelRegistration>;
117
+ /**
118
+ * Reject a manifest key list containing duplicates.
119
+ *
120
+ * @param values - Declared contribution keys
121
+ * @param field - Manifest field path for the error message
122
+ */
123
+ export declare function assertUnique(values: readonly string[], field: string): void;
124
+ /**
125
+ * Enforce per-kind key uniqueness of the manifest `contributes` block, plus
126
+ * kind-specific manifest checks.
127
+ *
128
+ * @param manifest - Plugin manifest
129
+ * @throws Error naming the first duplicated key
130
+ */
131
+ export declare function assertManifestKeysUnique(manifest: PluginManifest): void;
132
+ /**
133
+ * Reject a contribution key a plugin may never claim (built-in adapters).
134
+ *
135
+ * @param pluginId - Staging plugin
136
+ * @param kind - Contribution kind being staged
137
+ * @param key - Normalized contribution key
138
+ */
139
+ export declare function assertClaimable(pluginId: string, kind: ContributionKind<object>, key: string): void;
140
+ /**
141
+ * Reject a duplicate key staged twice by one plugin.
142
+ *
143
+ * @param pluginId - Staging plugin
144
+ * @param kind - Contribution kind being staged
145
+ * @param slot - The plugin's staging area
146
+ * @param key - Normalized contribution key
147
+ */
148
+ export declare function assertStagingKeyFree(pluginId: string, kind: ContributionKind<object>, slot: StagedContributions, key: string): void;
149
+ /**
150
+ * The staging write path shared by every register method: reserved-id and
151
+ * per-plugin uniqueness checks, then the kind's own staging insert.
152
+ *
153
+ * @param pluginId - Staging plugin
154
+ * @param kind - Contribution kind being staged
155
+ * @param slot - The plugin's staging area
156
+ * @param entry - Contribution entry to stage
157
+ */
158
+ export declare function stageContribution<TEntry extends object>(pluginId: string, kind: ContributionKind<TEntry>, slot: StagedContributions, entry: TEntry): void;
159
+ /**
160
+ * Manifest-side ownership claim strings ("provider:openai-compat") used by the
161
+ * loader's cross-plugin conflict detection. Kinds without cross-plugin
162
+ * ownership (hooks) declare no claims.
163
+ *
164
+ * @param kind - Contribution kind
165
+ * @param manifest - Candidate manifest
166
+ * @returns Claim strings for every declared key of the kind
167
+ */
168
+ export declare function declaredClaims(kind: ContributionKind<object>, manifest: PluginManifest): string[];
169
+ /**
170
+ * Reconcile the manifest `contributes` block against what the plugin actually
171
+ * staged: both directions must match exactly, then kind-specific checks run.
172
+ *
173
+ * @param kind - Contribution kind
174
+ * @param manifest - Plugin manifest
175
+ * @param slot - The plugin's staging area
176
+ * @throws Error naming the first mismatched key
177
+ */
178
+ export declare function assertManifestCoverage(kind: ContributionKind<object>, manifest: PluginManifest, slot: StagedContributions): void;
@@ -0,0 +1,314 @@
1
+ /**
2
+ * Declarative contribution-kind table — the single source of truth for the
3
+ * plugin contribution pipeline semantics: staging uniqueness, reserved ids,
4
+ * publish ownership, manifest claims, manifest uniqueness and manifest↔
5
+ * registration reconciliation.
6
+ *
7
+ * Adding a contribution kind = one descriptor here + the typed surfaces
8
+ * (PluginApi.registerXxx signature, staging slot, record type/getter, manifest
9
+ * schema field). The staging write path (`push`, via `stageContribution`) and
10
+ * the staged-entry read path (`forEachStaged`, which pairs entries with their
11
+ * keys) both live on the descriptor, so the key↔entry pairing and the
12
+ * uniqueness checks cannot be bypassed or forgotten per kind.
13
+ *
14
+ * Hooks are the deliberate semantic exception (multi-handler per name, no
15
+ * cross-plugin ownership), but their staging write path — priority-sorted Map
16
+ * insert — is also owned here (`hooks.push`), not by `PluginApi.on`.
17
+ */
18
+ import { BUILTIN_CHANNEL_IDS } from '../channel-types.js';
19
+ const tools = {
20
+ field: 'tools',
21
+ label: 'tool',
22
+ globallyUnique: true,
23
+ perPluginUnique: true,
24
+ reservedIds: [],
25
+ keyOf: (entry) => entry.definition.name,
26
+ declaredKeys: (manifest) => manifest.contributes?.tools ?? [],
27
+ forEachStaged: (slot, visit) => {
28
+ for (const entry of slot.tools)
29
+ visit(entry.definition.name, entry);
30
+ },
31
+ push: (slot, entry) => {
32
+ slot.tools.push(entry);
33
+ },
34
+ collect: (sink, pluginId, entry) => {
35
+ sink.tools.push({ pluginId, ...entry });
36
+ },
37
+ };
38
+ const commands = {
39
+ field: 'commands',
40
+ label: 'command',
41
+ globallyUnique: true,
42
+ perPluginUnique: true,
43
+ reservedIds: [],
44
+ keyOf: (entry) => entry.name,
45
+ declaredKeys: (manifest) => (manifest.contributes?.commands ?? []).map((command) => command.name),
46
+ forEachStaged: (slot, visit) => {
47
+ for (const entry of slot.commands)
48
+ visit(entry.name, entry);
49
+ },
50
+ push: (slot, entry) => {
51
+ slot.commands.push(entry);
52
+ },
53
+ collect: (sink, pluginId, entry) => {
54
+ sink.commands.push({ pluginId, ...entry });
55
+ },
56
+ assertManifestExtras: (manifest) => {
57
+ for (const command of manifest.contributes?.commands ?? []) {
58
+ assertUnique(command.sessionOps ?? [], `contributes.commands.${command.name}.sessionOps`);
59
+ }
60
+ },
61
+ reconcileExtra: (manifest, slot) => {
62
+ const declared = new Map((manifest.contributes?.commands ?? []).map((command) => [command.name, command.sessionOps ?? []]));
63
+ for (const command of slot.commands) {
64
+ const expected = declared.get(command.name) ?? [];
65
+ const actual = command.sessionOps ?? [];
66
+ if (JSON.stringify([...expected].sort()) !== JSON.stringify([...actual].sort())) {
67
+ throw new Error(`Command "${command.name}" sessionOps differ from manifest`);
68
+ }
69
+ }
70
+ },
71
+ };
72
+ const hooks = {
73
+ field: 'hooks',
74
+ label: 'hook',
75
+ globallyUnique: false,
76
+ perPluginUnique: false,
77
+ reservedIds: [],
78
+ keyOf: (entry) => entry.hookName,
79
+ declaredKeys: (manifest) => manifest.contributes?.hooks ?? [],
80
+ forEachStaged: (slot, visit) => {
81
+ for (const [hookName, entries] of slot.hooks) {
82
+ for (const entry of entries)
83
+ visit(hookName, entry);
84
+ }
85
+ },
86
+ push: (slot, entry) => {
87
+ const entries = [...(slot.hooks.get(entry.hookName) ?? []), entry];
88
+ entries.sort((a, b) => b.priority - a.priority);
89
+ slot.hooks.set(entry.hookName, entries);
90
+ },
91
+ collect: (sink, _pluginId, entry) => {
92
+ // Invariant: entry.pluginId is stamped with PluginApi.id at registration
93
+ // (api.ts `on`), and publish only ever iterates that plugin's own staging.
94
+ sink.hooks.push(entry);
95
+ },
96
+ };
97
+ const services = {
98
+ field: 'services',
99
+ label: 'service',
100
+ globallyUnique: true,
101
+ perPluginUnique: true,
102
+ reservedIds: [],
103
+ keyOf: (entry) => entry.serviceId,
104
+ declaredKeys: (manifest) => manifest.contributes?.services ?? [],
105
+ forEachStaged: (slot, visit) => {
106
+ for (const entry of slot.services)
107
+ visit(entry.serviceId, entry);
108
+ },
109
+ push: (slot, entry) => {
110
+ slot.services.push(entry);
111
+ },
112
+ collect: (sink, pluginId, entry) => {
113
+ sink.services.push({ pluginId, ...entry });
114
+ },
115
+ };
116
+ const providers = {
117
+ field: 'providers',
118
+ label: 'provider',
119
+ globallyUnique: true,
120
+ perPluginUnique: true,
121
+ reservedIds: [],
122
+ keyOf: (entry) => entry.id,
123
+ declaredKeys: (manifest) => manifest.contributes?.providers ?? [],
124
+ forEachStaged: (slot, visit) => {
125
+ for (const entry of slot.providers)
126
+ visit(entry.id, entry);
127
+ },
128
+ push: (slot, entry) => {
129
+ slot.providers.push(entry);
130
+ },
131
+ collect: (sink, pluginId, entry) => {
132
+ sink.providers.push({ pluginId, ...entry });
133
+ },
134
+ bindInstances: (entry, instances) => ({
135
+ ...entry,
136
+ // The Host calls acceptInstance after validating the factory product
137
+ // (config.ts::createProviderFromConfig) — birth means Host acceptance.
138
+ acceptInstance: (instance, label) => instances.attach({
139
+ kind: 'provider',
140
+ key: entry.id,
141
+ label,
142
+ instance,
143
+ retireMethod: 'dispose',
144
+ // dispose is optional on ModelProvider — define it as a retirement
145
+ // marker so Host teardown always retires the registry entry.
146
+ defineRetire: true,
147
+ }),
148
+ }),
149
+ };
150
+ const channels = {
151
+ field: 'channels',
152
+ label: 'channel',
153
+ globallyUnique: true,
154
+ perPluginUnique: true,
155
+ reservedIds: BUILTIN_CHANNEL_IDS,
156
+ keyOf: (entry) => entry.id,
157
+ declaredKeys: (manifest) => manifest.contributes?.channels ?? [],
158
+ forEachStaged: (slot, visit) => {
159
+ for (const entry of slot.channels)
160
+ visit(entry.id, entry);
161
+ },
162
+ push: (slot, entry) => {
163
+ slot.channels.push(entry);
164
+ },
165
+ collect: (sink, pluginId, entry) => {
166
+ sink.channels.push({ pluginId, ...entry });
167
+ },
168
+ bindInstances: (entry, instances) => ({
169
+ ...entry,
170
+ // The Host calls acceptInstance after validating the factory product
171
+ // (config.ts::createChannelAdapterFromConfig) — birth means Host acceptance.
172
+ acceptInstance: (instance, label) => instances.attach({
173
+ kind: 'channel',
174
+ key: entry.id,
175
+ label,
176
+ instance,
177
+ retireMethod: 'stop',
178
+ // stop is mandatory on ChannelAdapter — never add it here, or the
179
+ // Host's contract validation would stop reporting broken adapters.
180
+ defineRetire: false,
181
+ }),
182
+ }),
183
+ };
184
+ /**
185
+ * Every contribution kind in manifest-schema order. Iteration order is
186
+ * observable in first-failure diagnostics and record ordering — keep it aligned
187
+ * with the `contributes` schema field order.
188
+ */
189
+ export const CONTRIBUTION_KINDS = [
190
+ tools,
191
+ commands,
192
+ hooks,
193
+ services,
194
+ providers,
195
+ channels,
196
+ ];
197
+ /** Typed staging slots for the author-facing register methods. */
198
+ export const TOOL_KIND = tools;
199
+ export const COMMAND_KIND = commands;
200
+ export const HOOK_KIND = hooks;
201
+ export const SERVICE_KIND = services;
202
+ export const PROVIDER_KIND = providers;
203
+ export const CHANNEL_KIND = channels;
204
+ function capitalize(label) {
205
+ return label.charAt(0).toUpperCase() + label.slice(1);
206
+ }
207
+ /**
208
+ * Reject a manifest key list containing duplicates.
209
+ *
210
+ * @param values - Declared contribution keys
211
+ * @param field - Manifest field path for the error message
212
+ */
213
+ export function assertUnique(values, field) {
214
+ if (new Set(values).size !== values.length) {
215
+ throw new Error(`Plugin manifest ${field} contains duplicate entries`);
216
+ }
217
+ }
218
+ /**
219
+ * Enforce per-kind key uniqueness of the manifest `contributes` block, plus
220
+ * kind-specific manifest checks.
221
+ *
222
+ * @param manifest - Plugin manifest
223
+ * @throws Error naming the first duplicated key
224
+ */
225
+ export function assertManifestKeysUnique(manifest) {
226
+ for (const kind of CONTRIBUTION_KINDS) {
227
+ assertUnique(kind.declaredKeys(manifest), `contributes.${kind.field}`);
228
+ kind.assertManifestExtras?.(manifest);
229
+ }
230
+ }
231
+ /**
232
+ * Reject a contribution key a plugin may never claim (built-in adapters).
233
+ *
234
+ * @param pluginId - Staging plugin
235
+ * @param kind - Contribution kind being staged
236
+ * @param key - Normalized contribution key
237
+ */
238
+ export function assertClaimable(pluginId, kind, key) {
239
+ if (kind.reservedIds.includes(key)) {
240
+ throw new Error(`Plugin "${pluginId}" cannot register ${kind.label} "${key}": reserved by built-in adapters`);
241
+ }
242
+ }
243
+ /**
244
+ * Reject a duplicate key staged twice by one plugin.
245
+ *
246
+ * @param pluginId - Staging plugin
247
+ * @param kind - Contribution kind being staged
248
+ * @param slot - The plugin's staging area
249
+ * @param key - Normalized contribution key
250
+ */
251
+ export function assertStagingKeyFree(pluginId, kind, slot, key) {
252
+ if (!kind.perPluginUnique)
253
+ return;
254
+ let duplicate = false;
255
+ kind.forEachStaged(slot, (stagedKey) => {
256
+ if (stagedKey === key)
257
+ duplicate = true;
258
+ });
259
+ if (duplicate) {
260
+ throw new Error(`Plugin "${pluginId}" registered duplicate ${kind.label} "${key}"`);
261
+ }
262
+ }
263
+ /**
264
+ * The staging write path shared by every register method: reserved-id and
265
+ * per-plugin uniqueness checks, then the kind's own staging insert.
266
+ *
267
+ * @param pluginId - Staging plugin
268
+ * @param kind - Contribution kind being staged
269
+ * @param slot - The plugin's staging area
270
+ * @param entry - Contribution entry to stage
271
+ */
272
+ export function stageContribution(pluginId, kind, slot, entry) {
273
+ const key = kind.keyOf(entry);
274
+ assertClaimable(pluginId, kind, key);
275
+ assertStagingKeyFree(pluginId, kind, slot, key);
276
+ kind.push(slot, entry);
277
+ }
278
+ /**
279
+ * Manifest-side ownership claim strings ("provider:openai-compat") used by the
280
+ * loader's cross-plugin conflict detection. Kinds without cross-plugin
281
+ * ownership (hooks) declare no claims.
282
+ *
283
+ * @param kind - Contribution kind
284
+ * @param manifest - Candidate manifest
285
+ * @returns Claim strings for every declared key of the kind
286
+ */
287
+ export function declaredClaims(kind, manifest) {
288
+ if (!kind.globallyUnique)
289
+ return [];
290
+ return kind.declaredKeys(manifest).map((key) => `${kind.label}:${key}`);
291
+ }
292
+ /**
293
+ * Reconcile the manifest `contributes` block against what the plugin actually
294
+ * staged: both directions must match exactly, then kind-specific checks run.
295
+ *
296
+ * @param kind - Contribution kind
297
+ * @param manifest - Plugin manifest
298
+ * @param slot - The plugin's staging area
299
+ * @throws Error naming the first mismatched key
300
+ */
301
+ export function assertManifestCoverage(kind, manifest, slot) {
302
+ const declared = new Set(kind.declaredKeys(manifest));
303
+ const actual = new Set();
304
+ kind.forEachStaged(slot, (key) => actual.add(key));
305
+ for (const key of actual) {
306
+ if (!declared.has(key))
307
+ throw new Error(`${capitalize(kind.label)} "${key}" is not declared in manifest`);
308
+ }
309
+ for (const key of declared) {
310
+ if (!actual.has(key))
311
+ throw new Error(`Declared ${kind.label} "${key}" was not registered`);
312
+ }
313
+ kind.reconcileExtra?.(manifest, slot);
314
+ }