@octopi-agent/engine 0.97.15 → 0.102.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 (369) hide show
  1. package/dist/config-schema/agent.d.ts +37 -5
  2. package/dist/config-schema/agent.js +24 -4
  3. package/dist/config-schema/context.d.ts +6 -36
  4. package/dist/config-schema/context.js +4 -28
  5. package/dist/config-schema/engine.d.ts +61 -160
  6. package/dist/config-schema/engine.js +1 -5
  7. package/dist/config-schema/governance.d.ts +10 -1
  8. package/dist/config-schema/governance.js +38 -1
  9. package/dist/config-schema/models.d.ts +2 -8
  10. package/dist/config-schema/models.js +0 -2
  11. package/dist/config-schema/run.d.ts +2 -2
  12. package/dist/config-schema/run.js +2 -2
  13. package/dist/config-schema/shared.d.ts +0 -3
  14. package/dist/config-schema/shared.js +0 -2
  15. package/dist/config-schema/substrate.d.ts +14 -88
  16. package/dist/config-schema/substrate.js +22 -107
  17. package/dist/config.d.ts +45 -113
  18. package/dist/config.js +8 -2
  19. package/dist/harness/activation/dispatcher.js +7 -0
  20. package/dist/harness/activation/inbox.d.ts +3 -3
  21. package/dist/harness/activation/inbox.js +3 -3
  22. package/dist/harness/activation/runtime.js +13 -5
  23. package/dist/harness/activation/types.d.ts +2 -2
  24. package/dist/harness/agent/builder.d.ts +34 -2
  25. package/dist/harness/agent/builder.js +189 -58
  26. package/dist/harness/agent/config-bridge.js +9 -2
  27. package/dist/harness/agent/config-integrity.d.ts +66 -0
  28. package/dist/harness/agent/config-integrity.js +108 -2
  29. package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
  30. package/dist/harness/agent/wire-agent-builder.js +31 -7
  31. package/dist/harness/capabilities/document/factory.d.ts +5 -0
  32. package/dist/harness/capabilities/document/factory.js +1 -0
  33. package/dist/harness/capabilities/document/port.js +6 -3
  34. package/dist/harness/capabilities/document/types.d.ts +5 -0
  35. package/dist/harness/collaboration/autonomous-subsystem/index.d.ts +2 -2
  36. package/dist/harness/collaboration/autonomous-subsystem/index.js +1 -1
  37. package/dist/harness/collaboration/autonomous-subsystem/loader.js +4 -1
  38. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
  39. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +21 -4
  40. package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
  41. package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
  42. package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
  43. package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
  44. package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
  45. package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.d.ts +40 -0
  46. package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.js +59 -0
  47. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
  48. package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +2 -0
  49. package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -0
  50. package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +1 -1
  51. package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +12 -3
  52. package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
  53. package/dist/harness/collaboration/delegation/child-run.js +4 -4
  54. package/dist/harness/collaboration/delegation/index.d.ts +1 -1
  55. package/dist/harness/collaboration/delegation/index.js +1 -1
  56. package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
  57. package/dist/harness/collaboration/delegation/notifier.js +8 -1
  58. package/dist/harness/collaboration/delegation/service.d.ts +2 -0
  59. package/dist/harness/collaboration/delegation/service.js +2 -1
  60. package/dist/harness/collaboration/delegation/store.d.ts +2 -0
  61. package/dist/harness/collaboration/delegation/store.js +2 -1
  62. package/dist/harness/collaboration/delegation/types.d.ts +23 -2
  63. package/dist/harness/collaboration/delegation/types.js +22 -0
  64. package/dist/harness/collaboration/delegation/wiring.js +11 -1
  65. package/dist/harness/context/budget-allocator.d.ts +26 -18
  66. package/dist/harness/context/budget-allocator.js +67 -32
  67. package/dist/harness/context/capabilities/compact/engine.d.ts +0 -6
  68. package/dist/harness/context/capabilities/compact/engine.js +169 -121
  69. package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
  70. package/dist/harness/context/capabilities/compact/handover.js +7 -5
  71. package/dist/harness/context/capabilities/compact/index.d.ts +5 -1
  72. package/dist/harness/context/capabilities/compact/index.js +4 -0
  73. package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
  74. package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
  75. package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
  76. package/dist/harness/context/capabilities/compact/messages.js +91 -0
  77. package/dist/harness/context/capabilities/compact/types.d.ts +76 -11
  78. package/dist/harness/context/capabilities/compact/types.js +11 -1
  79. package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
  80. package/dist/harness/context/capabilities/compact/view-split.js +72 -0
  81. package/dist/harness/context/capabilities/summary/port.js +0 -1
  82. package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
  83. package/dist/harness/context/capabilities/summary/resolver.js +4 -9
  84. package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
  85. package/dist/harness/context/capabilities/summary/types.d.ts +4 -7
  86. package/dist/harness/context/context-size-ledger.d.ts +143 -0
  87. package/dist/harness/context/context-size-ledger.js +236 -0
  88. package/dist/harness/context/default-context-engine.d.ts +195 -119
  89. package/dist/harness/context/default-context-engine.js +1241 -743
  90. package/dist/harness/context/index.d.ts +2 -2
  91. package/dist/harness/context/index.js +1 -1
  92. package/dist/harness/context/layer-types.d.ts +15 -0
  93. package/dist/harness/context/layer-types.js +14 -1
  94. package/dist/harness/context/layers.d.ts +16 -19
  95. package/dist/harness/context/layers.js +42 -14
  96. package/dist/harness/context/message-selector.d.ts +10 -8
  97. package/dist/harness/context/message-selector.js +49 -27
  98. package/dist/harness/context/summarize.d.ts +3 -3
  99. package/dist/harness/context/summarize.js +11 -4
  100. package/dist/harness/context/system-prompt-assembler.d.ts +4 -0
  101. package/dist/harness/context/system-prompt-assembler.js +3 -1
  102. package/dist/harness/context/token-constants.d.ts +8 -6
  103. package/dist/harness/context/token-constants.js +8 -7
  104. package/dist/harness/context/token-estimate-fns.d.ts +37 -27
  105. package/dist/harness/context/token-estimate-fns.js +85 -66
  106. package/dist/harness/context/token-estimator.d.ts +27 -12
  107. package/dist/harness/context/token-estimator.js +120 -66
  108. package/dist/harness/context/token-segments.d.ts +88 -0
  109. package/dist/harness/context/token-segments.js +103 -0
  110. package/dist/harness/context/tool-result-aging.d.ts +6 -1
  111. package/dist/harness/context/tool-result-aging.js +16 -5
  112. package/dist/harness/context/tool-result-body.js +2 -0
  113. package/dist/harness/context/transform/anchors.d.ts +66 -0
  114. package/dist/harness/context/transform/anchors.js +125 -0
  115. package/dist/harness/context/transform/fold.d.ts +56 -0
  116. package/dist/harness/context/transform/fold.js +135 -0
  117. package/dist/harness/context/transform/migrate.d.ts +41 -0
  118. package/dist/harness/context/transform/migrate.js +69 -0
  119. package/dist/harness/context/transform/types.d.ts +129 -0
  120. package/dist/harness/context/transform/types.js +19 -0
  121. package/dist/harness/context/turn-envelope.d.ts +6 -3
  122. package/dist/harness/context/types.d.ts +127 -117
  123. package/dist/harness/extension/execution-environment/effect-policy.d.ts +24 -2
  124. package/dist/harness/extension/execution-environment/effect-policy.js +30 -0
  125. package/dist/harness/extension/execution-environment/ops-audit.d.ts +7 -3
  126. package/dist/harness/extension/execution-environment/ops-audit.js +11 -12
  127. package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
  128. package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
  129. package/dist/harness/extension/execution-environment/undo-log.d.ts +6 -2
  130. package/dist/harness/extension/execution-environment/undo-log.js +31 -10
  131. package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -1
  132. package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
  133. package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
  134. package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
  135. package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
  136. package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
  137. package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
  138. package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
  139. package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
  140. package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
  141. package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
  142. package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
  143. package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
  144. package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
  145. package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
  146. package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
  147. package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
  148. package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
  149. package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
  150. package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
  151. package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
  152. package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
  153. package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
  154. package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
  155. package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
  156. package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
  157. package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
  158. package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +83 -249
  159. package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
  160. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
  161. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -0
  162. package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
  163. package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
  164. package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
  165. package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
  166. package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
  167. package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
  168. package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +50 -117
  169. package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
  170. package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
  171. package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
  172. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
  173. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
  174. package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -0
  175. package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
  176. package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
  177. package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
  178. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
  179. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
  180. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +17 -24
  181. package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
  182. package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +3 -9
  183. package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +3 -6
  184. package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +9 -5
  185. package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +9 -130
  186. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +122 -14
  187. package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +4 -13
  188. package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +25 -11
  189. package/dist/harness/extension/plugin-ecosystem/tools/platform.js +168 -62
  190. package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
  191. package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
  192. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
  193. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +11 -2
  194. package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
  195. package/dist/harness/governance/accounting/usage-ledger.js +23 -1
  196. package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
  197. package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
  198. package/dist/harness/governance/security/capability-enforcer.js +1 -2
  199. package/dist/harness/governance/security/default-risk-policy.d.ts +1 -0
  200. package/dist/harness/governance/security/default-risk-policy.js +1 -0
  201. package/dist/harness/governance/security/default-security-guard.js +9 -0
  202. package/dist/harness/governance/security/index.d.ts +1 -0
  203. package/dist/harness/governance/security/index.js +2 -0
  204. package/dist/harness/governance/security/risk-evaluator.js +13 -0
  205. package/dist/harness/governance/security/risk-types.d.ts +12 -0
  206. package/dist/harness/governance/security/shell-parser-fallback.d.ts +29 -0
  207. package/dist/harness/governance/security/shell-parser-fallback.js +410 -0
  208. package/dist/harness/governance/security/shell-parser-shared.d.ts +83 -0
  209. package/dist/harness/governance/security/shell-parser-shared.js +188 -0
  210. package/dist/harness/governance/security/shell-parser-treesitter.d.ts +52 -0
  211. package/dist/harness/governance/security/shell-parser-treesitter.js +370 -0
  212. package/dist/harness/governance/security/shell-parser.d.ts +23 -10
  213. package/dist/harness/governance/security/shell-parser.js +37 -496
  214. package/dist/harness/governance/security/vendor/README.md +24 -0
  215. package/dist/harness/governance/security/vendor/tree-sitter-bash.LICENSE.txt +21 -0
  216. package/dist/harness/governance/security/vendor/tree-sitter-bash.wasm +0 -0
  217. package/dist/harness/index.d.ts +12 -12
  218. package/dist/harness/index.js +7 -7
  219. package/dist/harness/knowledge/boot-config.d.ts +55 -0
  220. package/dist/harness/knowledge/boot-config.js +50 -0
  221. package/dist/harness/knowledge/catalog-types.d.ts +2 -0
  222. package/dist/harness/knowledge/client.d.ts +24 -2
  223. package/dist/harness/knowledge/client.js +19 -5
  224. package/dist/harness/knowledge/db.js +5 -0
  225. package/dist/harness/knowledge/describe-sample.d.ts +23 -0
  226. package/dist/harness/knowledge/describe-sample.js +58 -0
  227. package/dist/harness/knowledge/describe.d.ts +8 -0
  228. package/dist/harness/knowledge/describe.js +18 -2
  229. package/dist/harness/knowledge/engine-thread.js +6 -0
  230. package/dist/harness/knowledge/grounding.js +3 -1
  231. package/dist/harness/knowledge/http-app.js +35 -4
  232. package/dist/harness/knowledge/http-params.d.ts +18 -0
  233. package/dist/harness/knowledge/http-params.js +24 -0
  234. package/dist/harness/knowledge/index.d.ts +2 -0
  235. package/dist/harness/knowledge/index.js +1 -0
  236. package/dist/harness/knowledge/knowledge-serve-child.js +3 -0
  237. package/dist/harness/knowledge/purge.js +5 -2
  238. package/dist/harness/knowledge/query-service.d.ts +13 -2
  239. package/dist/harness/knowledge/query-service.js +4 -2
  240. package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
  241. package/dist/harness/knowledge/query-worker-client.js +4 -2
  242. package/dist/harness/knowledge/query-worker.js +4 -2
  243. package/dist/harness/knowledge/read-http.js +5 -1
  244. package/dist/harness/knowledge/serve.d.ts +8 -7
  245. package/dist/harness/knowledge/serve.js +9 -0
  246. package/dist/harness/knowledge/source-store.js +26 -3
  247. package/dist/harness/knowledge/start-service-process.d.ts +15 -7
  248. package/dist/harness/knowledge/start-service-process.js +21 -9
  249. package/dist/harness/knowledge/types.d.ts +7 -0
  250. package/dist/harness/knowledge/writer-service.d.ts +37 -9
  251. package/dist/harness/knowledge/writer-service.js +120 -14
  252. package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
  253. package/dist/harness/knowledge/writer-worker-client.js +20 -2
  254. package/dist/harness/knowledge/writer-worker.js +9 -1
  255. package/dist/harness/memory/index.d.ts +6 -2
  256. package/dist/harness/memory/index.js +4 -1
  257. package/dist/harness/memory/memory-events.d.ts +25 -0
  258. package/dist/harness/memory/memory-events.js +38 -0
  259. package/dist/harness/memory/sqlite/agent-db.js +15 -0
  260. package/dist/harness/memory/sqlite/wisdom-store.d.ts +7 -2
  261. package/dist/harness/memory/sqlite/wisdom-store.js +86 -12
  262. package/dist/harness/memory/steward-policy.d.ts +3 -0
  263. package/dist/harness/memory/steward-policy.js +1 -1
  264. package/dist/harness/memory/types.d.ts +47 -7
  265. package/dist/harness/memory/wisdom-attribution.d.ts +136 -0
  266. package/dist/harness/memory/wisdom-attribution.js +287 -0
  267. package/dist/harness/memory/wisdom-events.d.ts +37 -0
  268. package/dist/harness/memory/wisdom-events.js +61 -0
  269. package/dist/harness/memory/wisdom-formation.d.ts +31 -1
  270. package/dist/harness/memory/wisdom-formation.js +130 -33
  271. package/dist/harness/memory/wisdom-gates.d.ts +14 -0
  272. package/dist/harness/memory/wisdom-gates.js +59 -19
  273. package/dist/harness/memory/wisdom.d.ts +7 -2
  274. package/dist/harness/memory/wisdom.js +49 -2
  275. package/dist/harness/observability/observer/hub.js +25 -15
  276. package/dist/harness/observability/observer/types.d.ts +10 -6
  277. package/dist/harness/run/agent/agent.d.ts +40 -21
  278. package/dist/harness/run/agent/agent.js +66 -13
  279. package/dist/harness/run/agent/index.d.ts +1 -1
  280. package/dist/harness/run/budget/budget.d.ts +28 -10
  281. package/dist/harness/run/budget/budget.js +38 -15
  282. package/dist/harness/run/model/index.d.ts +3 -1
  283. package/dist/harness/run/model/index.js +2 -1
  284. package/dist/harness/run/model/resolver.d.ts +4 -1
  285. package/dist/harness/run/model/resolver.js +36 -2
  286. package/dist/harness/run/model/run-scope.d.ts +2 -0
  287. package/dist/harness/run/model/run-scope.js +7 -0
  288. package/dist/harness/run/model/types.d.ts +22 -5
  289. package/dist/harness/run/model/types.js +3 -2
  290. package/dist/harness/run/model/window-truth.d.ts +37 -0
  291. package/dist/harness/run/model/window-truth.js +39 -0
  292. package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
  293. package/dist/harness/run/reliability/context-length-feedback.js +128 -0
  294. package/dist/harness/run/reliability/harness-events.d.ts +3 -3
  295. package/dist/harness/run/reliability/model-error-policy.js +4 -0
  296. package/dist/harness/run/reliability/run-agent.d.ts +10 -4
  297. package/dist/harness/run/reliability/run-agent.js +137 -53
  298. package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
  299. package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
  300. package/dist/harness/run/run-guard/default-run-guard.js +8 -8
  301. package/dist/harness/run/run-scope.d.ts +41 -4
  302. package/dist/harness/run/runner.d.ts +71 -31
  303. package/dist/harness/run/runner.js +368 -106
  304. package/dist/harness/session/attachments/index.d.ts +1 -0
  305. package/dist/harness/session/attachments/index.js +1 -0
  306. package/dist/harness/session/attachments/inject.d.ts +21 -10
  307. package/dist/harness/session/attachments/inject.js +76 -24
  308. package/dist/harness/session/attachments/recall-index.d.ts +70 -0
  309. package/dist/harness/session/attachments/recall-index.js +219 -0
  310. package/dist/harness/session/attachments/service.d.ts +21 -0
  311. package/dist/harness/session/attachments/service.js +258 -139
  312. package/dist/harness/session/attachments/types.d.ts +6 -0
  313. package/dist/harness/session/transform-store.d.ts +136 -0
  314. package/dist/harness/session/transform-store.js +302 -0
  315. package/dist/harness/session/types.d.ts +2 -2
  316. package/dist/harness/shared/events/agent-event-map.d.ts +46 -13
  317. package/dist/harness/shared/events/agent-event-map.js +3 -2
  318. package/dist/harness/shared/events/scenario-events.d.ts +6 -6
  319. package/dist/harness/shared/paths/glob.d.ts +52 -0
  320. package/dist/harness/shared/paths/glob.js +218 -0
  321. package/dist/harness/shared/paths/index.d.ts +84 -0
  322. package/dist/harness/shared/paths/index.js +179 -0
  323. package/dist/harness/shared/types/agent-definition.d.ts +1 -2
  324. package/dist/index.d.ts +14 -17
  325. package/dist/index.js +7 -9
  326. package/dist/integration/observability/metrics.d.ts +6 -6
  327. package/dist/integration/observability/metrics.js +13 -13
  328. package/dist/integration/observability/observer-bridge.js +2 -2
  329. package/dist/integration/observability/trace-collector.d.ts +5 -5
  330. package/dist/integration/observability/trace-collector.js +34 -35
  331. package/dist/integration/observability/trace-events.d.ts +3 -3
  332. package/dist/integration/observability/trace-events.js +3 -3
  333. package/dist/integration/providers/anthropic.js +14 -1
  334. package/dist/integration/providers/openai.js +7 -1
  335. package/dist/integration/providers/usage.d.ts +1 -1
  336. package/dist/integration/providers/wire-dump.d.ts +1 -1
  337. package/dist/integration/storage/archive-manager.d.ts +6 -0
  338. package/dist/integration/storage/archive-manager.js +10 -0
  339. package/dist/integration/storage/jsonl.d.ts +1 -1
  340. package/dist/integration/storage/jsonl.js +18 -16
  341. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +4 -2
  342. package/dist/subsystems/cognition-steward/conceptualize/handler.js +12 -20
  343. package/dist/subsystems/memory-steward/backfill/config.yaml +4 -2
  344. package/dist/subsystems/memory-steward/backfill/handler.js +44 -52
  345. package/dist/subsystems/wisdom-steward/attribute/SUBSYSTEM.md +24 -0
  346. package/dist/subsystems/wisdom-steward/attribute/config.yaml +60 -0
  347. package/dist/subsystems/wisdom-steward/attribute/handler.d.ts +23 -0
  348. package/dist/subsystems/wisdom-steward/attribute/handler.js +167 -0
  349. package/dist/subsystems/wisdom-steward/evaluate/handler.js +3 -1
  350. package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
  351. package/dist/subsystems/wisdom-steward/formation/config.yaml +13 -5
  352. package/dist/subsystems/wisdom-steward/formation/handler.js +39 -23
  353. package/dist/subsystems/wisdom-steward/govern/config.yaml +1 -1
  354. package/dist/subsystems/wisdom-steward/govern/handler.js +4 -0
  355. package/package.json +16 -14
  356. package/dist/harness/context/hybrid-compressor.d.ts +0 -41
  357. package/dist/harness/context/hybrid-compressor.js +0 -159
  358. package/dist/harness/context/llm-summarizer.d.ts +0 -46
  359. package/dist/harness/context/llm-summarizer.js +0 -249
  360. package/dist/harness/context/smart-router.d.ts +0 -75
  361. package/dist/harness/context/smart-router.js +0 -118
  362. package/dist/harness/context/truncate-compressor.d.ts +0 -28
  363. package/dist/harness/context/truncate-compressor.js +0 -107
  364. package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
  365. package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
  366. package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
  367. package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
  368. package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
  369. package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
@@ -31,7 +31,9 @@ import { createEnvInfoTool } from './env-info.js';
31
31
  import { createProcessListTool } from './process-tools.js';
32
32
  import { createPrivExecTool } from './privileged-tool.js';
33
33
  import { createDocumentProbeTool, createDocumentReadTool } from './document-tools.js';
34
- import { isUnderSessionUndoRoot, defaultPathEnv, isPathUnderRoots, isUnderAttachmentRoot, resolvePlatformShell, resolveReadableToolPath, resolveToolPath, } from './platform.js';
34
+ import { containmentOptions, defaultPathEnv, isPathUnderRoots, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolvePlatformShell, resolveReadableToolPath, resolveToolPath, } from './platform.js';
35
+ import { readFileNoFollow } from '../../../shared/paths/index.js';
36
+ import { matchesDenyPattern } from '../../../shared/paths/glob.js';
35
37
  /**
36
38
  * Shell 工具 — 执行 shell 命令
37
39
  *
@@ -112,10 +114,7 @@ export function createShellTool(options) {
112
114
  notReversedPayload = { reason: 'shell_journal_off' };
113
115
  }
114
116
  const resolvedShell = resolvePlatformShell();
115
- const resolvedCwd = resolveToolPath(cwd, context?.cwd, {
116
- allowRoots: context?.pathRoots,
117
- containment: context?.pathContainment,
118
- });
117
+ const resolvedCwd = resolveToolPath(cwd, context?.cwd, containmentOptions(context));
119
118
  // D2-a: always ProcessSandbox (jail backend when probed, else supervised).
120
119
  const { createProcessSandbox } = await import('../../execution-environment/sandbox.js');
121
120
  const sandbox = await createProcessSandbox({
@@ -324,14 +323,13 @@ export function createFileReadTool(options) {
324
323
  const pathModule = await import('node:path');
325
324
  const rawPath = args.path;
326
325
  const cwd = context?.cwd ?? process.cwd();
327
- const path = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots, {
328
- allowRoots: context?.pathRoots,
329
- containment: context?.pathContainment,
330
- });
326
+ const path = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots, containmentOptions(context));
331
327
  const offset = args.offset ?? 1;
332
328
  const limit = args.limit ?? 2000;
333
329
  try {
334
- const content = await readFile(path, 'utf-8');
330
+ const content = context?.refuseFinalSymlink
331
+ ? await readFileNoFollow(path, 'utf8')
332
+ : await readFile(path, 'utf-8');
335
333
  const lines = content.split('\n');
336
334
  const totalLines = lines.length;
337
335
  const start = Math.max(0, offset - 1);
@@ -411,10 +409,7 @@ export function createFileWriteTool() {
411
409
  const { dirname } = await import('node:path');
412
410
  const rawPath = args.path;
413
411
  const cwd = context?.cwd ?? process.cwd();
414
- const path = resolveToolPath(rawPath, cwd, {
415
- allowRoots: context?.pathRoots,
416
- containment: context?.pathContainment,
417
- });
412
+ const path = resolveToolPath(rawPath, cwd, containmentOptions(context));
418
413
  if (isUnderAttachmentRoot(path, context?.attachmentRoots)) {
419
414
  throw new Error('session attachments are read-only; cannot write to attachments root');
420
415
  }
@@ -446,10 +441,10 @@ export function createFileWriteTool() {
446
441
  throw new Error('file_effects_not_configured: file_write requires ToolExecutionContext.fileEffects');
447
442
  }
448
443
  if (append) {
449
- await effects.appendFile(path, content);
444
+ await effects.appendFile(path, content, { refuseFinalSymlink: context?.refuseFinalSymlink === true });
450
445
  }
451
446
  else {
452
- await effects.writeFile(path, content);
447
+ await effects.writeFile(path, content, { refuseFinalSymlink: context?.refuseFinalSymlink === true });
453
448
  }
454
449
  return {
455
450
  path,
@@ -491,10 +486,7 @@ export function createFileDeleteTool() {
491
486
  const { readFile, rm, stat } = await import('node:fs/promises');
492
487
  const rawPath = args.path;
493
488
  const cwd = context?.cwd ?? process.cwd();
494
- const path = resolveToolPath(rawPath, cwd, {
495
- allowRoots: context?.pathRoots,
496
- containment: context?.pathContainment,
497
- });
489
+ const path = resolveToolPath(rawPath, cwd, containmentOptions(context));
498
490
  if (isUnderAttachmentRoot(path, context?.attachmentRoots)) {
499
491
  throw new Error('session attachments are read-only; cannot delete from attachments root');
500
492
  }
@@ -645,10 +637,7 @@ export function createFileListTool(options) {
645
637
  const { join, relative } = await import('node:path');
646
638
  const rawPath = args.path ?? '.';
647
639
  const cwd = context?.cwd ?? process.cwd();
648
- const basePath = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots, {
649
- allowRoots: context?.pathRoots,
650
- containment: context?.pathContainment,
651
- });
640
+ const basePath = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots, containmentOptions(context));
652
641
  // 找文件意图(带 pattern)默认递归;显式 recursive:false 仍只列本层
653
642
  const hasPattern = Boolean(args.pattern?.trim());
654
643
  const recursive = args.recursive === undefined && hasPattern
@@ -658,6 +647,7 @@ export function createFileListTool(options) {
658
647
  const maxEntries = Math.min(Math.max(args.maxEntries ?? 500, 1), 2000);
659
648
  const maxDepth = Math.min(Math.max(args.maxDepth ?? 4, 1), 8);
660
649
  const entries = [];
650
+ const denylist = context?.pathDenylist ?? [];
661
651
  let totalCount = 0;
662
652
  let entryCapped = false;
663
653
  let depthCapped = false;
@@ -674,6 +664,9 @@ export function createFileListTool(options) {
674
664
  return;
675
665
  const fullPath = join(dir, item.name);
676
666
  const relativePath = relative(basePath, fullPath);
667
+ // Denied names are not even enumerated: existence and size are data too.
668
+ if (denylist.length > 0 && matchesDenyPattern(relativePath.split('\\').join('/'), denylist))
669
+ continue;
677
670
  if (recursive && item.isDirectory() && SKIP_DIR_NAMES.has(item.name))
678
671
  continue;
679
672
  // pattern 只过滤列出的条目;递归时目录始终下钻(否则 recursive+*.md 进不了子目录)
@@ -10,7 +10,7 @@
10
10
  * 工具与 `DelegateService` 分离:服务可被嵌入方直接用,不经 LLM 工具面。
11
11
  */
12
12
  import { DelegateResolutionError } from '../../../collaboration/delegation/service.js';
13
- import { isTerminalDelegationStatus } from '../../../collaboration/delegation/types.js';
13
+ import { DEFAULT_DELEGATION_OUTPUT_CHARS, isTerminalDelegationStatus, } from '../../../collaboration/delegation/types.js';
14
14
  /** 委派单摘要(进 LLM 结果,字段名 snake_case 对齐其他工具) */
15
15
  function delegationSummary(d) {
16
16
  return {
@@ -115,14 +115,19 @@ export function createDelegateDispatchTool(service) {
115
115
  enum: ['clean', 'fork'],
116
116
  description: "Context mode. 'clean' (default) starts the child with no parent history; 'fork' passes your message history for background.",
117
117
  },
118
- max_turns: {
118
+ max_steps: {
119
119
  type: 'number',
120
- description: 'Turn budget for the child run (intersected with the target ceiling)',
120
+ description: 'Step budget for the child run (model rounds; intersected with the target ceiling)',
121
121
  },
122
122
  max_tokens: {
123
123
  type: 'number',
124
124
  description: 'Token budget for the child run (intersected with the target ceiling)',
125
125
  },
126
+ max_output_chars: {
127
+ type: 'number',
128
+ description: 'Truncation cap (chars) for the auto-returned result notice <output>. ' +
129
+ `Default ${DEFAULT_DELEGATION_OUTPUT_CHARS}. The full output is collectable via delegate_get (not subject to this cap).`,
130
+ },
126
131
  timeout_ms: {
127
132
  type: 'number',
128
133
  description: 'Delegation timeout in milliseconds',
@@ -140,8 +145,11 @@ export function createDelegateDispatchTool(service) {
140
145
  }
141
146
  const contextMode = args.context === 'fork' ? 'fork' : 'clean';
142
147
  const timeoutMs = args.timeout_ms != null ? Number(args.timeout_ms) : undefined;
143
- const maxTurns = args.max_turns != null ? Number(args.max_turns) : undefined;
148
+ const maxSteps = args.max_steps != null ? Number(args.max_steps) : undefined;
144
149
  const maxTokens = args.max_tokens != null ? Number(args.max_tokens) : undefined;
150
+ // 非法值不在工具层静默丢弃(m6):透传给 dispatch,由 normalizeMaxOutputChars
151
+ // fail loud——错误经下方 catch 以 ok:false 回给 LLM,形成反馈闭环
152
+ const maxOutputChars = args.max_output_chars != null ? Number(args.max_output_chars) : undefined;
145
153
  try {
146
154
  const { delegation, resolvedAgentId } = await service.dispatch({
147
155
  parent: {
@@ -154,11 +162,12 @@ export function createDelegateDispatchTool(service) {
154
162
  target: agent ? { agentId: agent } : { trait },
155
163
  task: String(args.task ?? ''),
156
164
  input: String(args.input ?? ''),
165
+ maxOutputChars,
157
166
  context: contextMode,
158
167
  // D1:传快照而非活数组引用——父 run 在子起跑后仍会 append
159
168
  parentMessages: contextMode === 'fork' ? context.messages.map((m) => ({ ...m })) : undefined,
160
- budget: maxTurns != null || maxTokens != null || timeoutMs != null
161
- ? { maxTurns, maxTokens, timeoutMs }
169
+ budget: maxSteps != null || maxTokens != null || timeoutMs != null
170
+ ? { maxSteps, maxTokens, timeoutMs }
162
171
  : undefined,
163
172
  timeoutMs,
164
173
  });
@@ -206,8 +215,9 @@ export function createDelegateListTool(service) {
206
215
  status,
207
216
  activeOnly,
208
217
  });
209
- // 列表是只读概览:不 markSurfaced。结果可能被 ToolResultValidator 截断,
210
- // 「标已送达」只留给明确取回单条全文的 delegate_get,宁可提示多留也不误消音
218
+ // 列表是只读概览:不 markSurfaced。结果体量无委派层上限(专用工具结果截断器
219
+ // 尚未接线——记债见 CHANGELOG v0.102.10),「标已送达」只留给明确取回单条全文的
220
+ // delegate_get,宁可提示多留也不误消音
211
221
  return {
212
222
  delegations: items.map(delegationSummary),
213
223
  total: items.length,
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 只消费 DocumentPort;业务/设计知识留在 skill。
5
5
  */
6
- import { resolveReadableToolPath } from './platform.js';
6
+ import { containmentOptions, resolveReadableToolPath, } from './platform.js';
7
7
  /**
8
8
  * document_read — 抽取 PDF/Office 为 Markdown
9
9
  *
@@ -44,10 +44,7 @@ export function createDocumentReadTool(options) {
44
44
  }
45
45
  const rawPath = String(args.path ?? '');
46
46
  const cwd = context?.cwd ?? process.cwd();
47
- const path = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots, {
48
- allowRoots: context?.pathRoots,
49
- containment: context?.pathContainment,
50
- });
47
+ const path = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots, containmentOptions(context));
51
48
  try {
52
49
  const result = await port.extract({
53
50
  path,
@@ -135,10 +132,7 @@ export function createDocumentProbeTool(options) {
135
132
  }
136
133
  const rawPath = String(args.path ?? '');
137
134
  const cwd = context?.cwd ?? process.cwd();
138
- const path = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots, {
139
- allowRoots: context?.pathRoots,
140
- containment: context?.pathContainment,
141
- });
135
+ const path = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots, containmentOptions(context));
142
136
  try {
143
137
  const probe = await port.probe({ path, name: path });
144
138
  const caps = await port.capabilities();
@@ -10,7 +10,7 @@
10
10
  * - dry-run 预览模式
11
11
  * - 编辑后自动返回周围上下文
12
12
  */
13
- import { isPathUnderRoots, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, } from './platform.js';
13
+ import { containmentOptions, isPathUnderRoots, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, } from './platform.js';
14
14
  import { gateEffect } from '../../execution-environment/effect-policy.js';
15
15
  import { detectEol, oldTextCandidates, toEol } from './eol.js';
16
16
  export function createFileEditTool() {
@@ -51,10 +51,7 @@ export function createFileEditTool() {
51
51
  const { readFile } = await import('node:fs/promises');
52
52
  const rawPath = args.path;
53
53
  const cwd = context.cwd ?? process.cwd();
54
- const path = resolveToolPath(rawPath, cwd, {
55
- allowRoots: context.pathRoots,
56
- containment: context.pathContainment,
57
- });
54
+ const path = resolveToolPath(rawPath, cwd, containmentOptions(context));
58
55
  if (isUnderAttachmentRoot(path, context.attachmentRoots)) {
59
56
  throw new Error('session attachments are read-only; cannot edit attachments root');
60
57
  }
@@ -136,7 +133,7 @@ export function createFileEditTool() {
136
133
  if (!effects) {
137
134
  throw new Error('file_effects_not_configured: file_edit requires ToolExecutionContext.fileEffects');
138
135
  }
139
- await effects.writeFile(path, newContent);
136
+ await effects.writeFile(path, newContent, { refuseFinalSymlink: context?.refuseFinalSymlink === true });
140
137
  }
141
138
  return {
142
139
  path,
@@ -1,11 +1,9 @@
1
- import { isPathUnderRoots, isUnderAttachmentRoot, resolveToolPath, isUnderSessionUndoRoot, } from './platform.js';
1
+ import { containmentOptions, isPathUnderRoots, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, } from './platform.js';
2
2
  import { gateEffect } from '../../execution-environment/effect-policy.js';
3
+ import { isFinalSymlink } from '../../../shared/paths/index.js';
3
4
  function resolveSafePath(rawPath, context, label) {
4
5
  const cwd = context?.cwd ?? process.cwd();
5
- const path = resolveToolPath(rawPath, cwd, {
6
- allowRoots: context?.pathRoots,
7
- containment: context?.pathContainment,
8
- });
6
+ const path = resolveToolPath(rawPath, cwd, containmentOptions(context));
9
7
  if (isUnderAttachmentRoot(path, context?.attachmentRoots)) {
10
8
  throw new Error(`session attachments are read-only; cannot ${label} under attachments root`);
11
9
  }
@@ -256,6 +254,12 @@ export function createFileCopyTool() {
256
254
  await effects.recordCreate(to, after);
257
255
  }
258
256
  // Binary-safe copy (images, Office, etc.)
257
+ // `copyFile` opens the destination with O_TRUNC and would follow a symlink
258
+ // planted at `to`, writing outside the root. It also bypasses
259
+ // `effects.writeFile`, so the final-component guard must be applied here.
260
+ if (context?.refuseFinalSymlink === true && isFinalSymlink(to)) {
261
+ throw new Error(`path_forbidden: "${to}" final component is a symlink (refuseFinalSymlink)`);
262
+ }
259
263
  await copyFile(from, to);
260
264
  return {
261
265
  from,
@@ -21,7 +21,8 @@
21
21
  * - 零结果时返回 diagnostics + hints,便于调用方自纠
22
22
  */
23
23
  import { resolveSupportBinding, } from '../../../context/capabilities/summary/index.js';
24
- import { resolveToolPath } from './platform.js';
24
+ import { containmentOptions, resolveToolPath, } from './platform.js';
25
+ import { globToPathRegex, matchesDenyPattern } from '../../../shared/paths/glob.js';
25
26
  /** 需要忽略的目录 */
26
27
  const IGNORED_DIRS = new Set([
27
28
  'node_modules', '.git', '.svn', '.hg', 'dist', 'build',
@@ -117,10 +118,7 @@ export function createFileSearchTool(options) {
117
118
  const { basename, extname, join, relative } = await import('node:path');
118
119
  const rawRoot = args.path;
119
120
  const rootPath = rawRoot
120
- ? resolveToolPath(rawRoot, context.cwd ?? process.cwd(), {
121
- allowRoots: context.pathRoots,
122
- containment: context.pathContainment,
123
- })
121
+ ? resolveToolPath(rawRoot, context.cwd ?? process.cwd(), containmentOptions(context))
124
122
  : (context.cwd ?? process.cwd());
125
123
  const terms = collectPatternTerms(args);
126
124
  const patternMode = resolvePatternMode(args);
@@ -153,6 +151,12 @@ export function createFileSearchTool(options) {
153
151
  async function considerFile(fullPath, relPath) {
154
152
  if (truncated)
155
153
  return;
154
+ // Denylist applies per file, not just to the `path` argument: this tool
155
+ // walks a tree and returns file *contents*, so a denied name would
156
+ // otherwise be readable here while `file_read` refuses it.
157
+ const denylist = context.pathDenylist ?? [];
158
+ if (denylist.length > 0 && matchesDenyPattern(relPath, denylist))
159
+ return;
156
160
  filesSeen += 1;
157
161
  // glob 过滤:root 相对路径(无 `/` 的模式等价于任意深度 globstar)
158
162
  if (fileFilter && !fileFilter.test(relPath))
@@ -574,131 +578,6 @@ async function searchFileLines(options) {
574
578
  }
575
579
  }
576
580
  // ── glob 编译 ──
577
- /**
578
- * 将路径 glob 编译为正则(匹配 root 相对路径)
579
- *
580
- * 语义对齐 rg/git:
581
- * - `**` 跨目录;`*` / `?` 不跨 `/`
582
- * - 无 `/` 的模式(如 `*.md`)等价于任意深度的 globstar 匹配
583
- * - 支持 `{a,b}` 花括号(可多组)
584
- *
585
- * @param glob - glob 模式
586
- * @returns 整串匹配相对路径的正则(大小写不敏感)
587
- */
588
- function globToPathRegex(glob) {
589
- const trimmed = glob.trim();
590
- if (!trimmed)
591
- throw new Error('glob must be non-empty');
592
- const normalized = trimmed.includes('/') ? trimmed : `**/${trimmed}`;
593
- const source = globToSource(normalized);
594
- return new RegExp(`^${source}$`, 'i');
595
- }
596
- /**
597
- * 将(已规范化)glob 片段编译为正则源
598
- *
599
- * @param glob - 含路径分隔符的 glob
600
- * @returns 正则源片段(无首尾锚点)
601
- */
602
- function globToSource(glob) {
603
- let out = '';
604
- let i = 0;
605
- while (i < glob.length) {
606
- const ch = glob[i];
607
- // `\*` `\?` 等 → 字面量
608
- if (ch === '\\' && i + 1 < glob.length && '*?[]{}\\/!'.includes(glob[i + 1])) {
609
- out += escapeRegex(glob[i + 1]);
610
- i += 2;
611
- continue;
612
- }
613
- if (ch === '*' && glob[i + 1] === '*') {
614
- i += 2;
615
- if (glob[i] === '/') {
616
- i += 1;
617
- // `**/` → 任意深度前缀(含零层)
618
- out += '(?:.*/)?';
619
- }
620
- else {
621
- out += '.*';
622
- }
623
- continue;
624
- }
625
- if (ch === '*') {
626
- i += 1;
627
- out += '[^/]*';
628
- continue;
629
- }
630
- if (ch === '?') {
631
- i += 1;
632
- out += '[^/]';
633
- continue;
634
- }
635
- if (ch === '{') {
636
- const end = findBraceEnd(glob, i);
637
- if (end === -1) {
638
- out += '\\{';
639
- i += 1;
640
- continue;
641
- }
642
- const alts = splitBraceAlts(glob.slice(i + 1, end));
643
- out += `(?:${alts.map((alt) => globToSource(alt)).join('|')})`;
644
- i = end + 1;
645
- continue;
646
- }
647
- if ('.+^$()|[]'.includes(ch)) {
648
- out += `\\${ch}`;
649
- }
650
- else {
651
- out += ch;
652
- }
653
- i += 1;
654
- }
655
- return out;
656
- }
657
- /**
658
- * 找到配对的 `}`(跳过嵌套 `{}`)
659
- *
660
- * @param glob - glob 字符串
661
- * @param openIndex - `{` 下标
662
- * @returns 配对 `}` 下标;无则 -1
663
- */
664
- function findBraceEnd(glob, openIndex) {
665
- let depth = 0;
666
- for (let i = openIndex; i < glob.length; i++) {
667
- if (glob[i] === '{')
668
- depth += 1;
669
- else if (glob[i] === '}') {
670
- depth -= 1;
671
- if (depth === 0)
672
- return i;
673
- }
674
- }
675
- return -1;
676
- }
677
- /**
678
- * 拆分花括号内的顶层逗号备选
679
- *
680
- * @param body - `{}` 内部
681
- * @returns 备选列表
682
- */
683
- function splitBraceAlts(body) {
684
- const alts = [];
685
- let depth = 0;
686
- let current = '';
687
- for (const ch of body) {
688
- if (ch === '{')
689
- depth += 1;
690
- if (ch === '}')
691
- depth -= 1;
692
- if (ch === ',' && depth === 0) {
693
- alts.push(current);
694
- current = '';
695
- continue;
696
- }
697
- current += ch;
698
- }
699
- alts.push(current);
700
- return alts;
701
- }
702
581
  // ── L1 输出收缩(F1-B1:结构化硬顶,零 LLM) ──
703
582
  /**
704
583
  * L1 结构化收缩:把 matches 清单体压进预算,定位符(file+line)永远全保
@@ -1,14 +1,12 @@
1
1
  import { gateEffect } from '../../execution-environment/effect-policy.js';
2
- import { resolveToolPath, isUnderAttachmentRoot, isUnderSessionUndoRoot } from './platform.js';
2
+ import { containmentOptions, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, } from './platform.js';
3
3
  import { detectEol, toEol } from './eol.js';
4
4
  import { assertSafeRef } from './allowlisted-run.js';
5
+ import { matchesDenyPattern } from '../../../shared/paths/glob.js';
5
6
  import { runGit } from './git-runner.js';
6
7
  function resolveCwd(context, raw) {
7
8
  const cwd = raw ?? context?.cwd ?? process.cwd();
8
- const abs = resolveToolPath(cwd, context?.cwd, {
9
- allowRoots: context?.pathRoots,
10
- containment: context?.pathContainment,
11
- });
9
+ const abs = resolveToolPath(cwd, context?.cwd, containmentOptions(context));
12
10
  if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
13
11
  throw new Error('session attachments are read-only; cannot run git under attachments root');
14
12
  }
@@ -18,10 +16,7 @@ function resolveCwd(context, raw) {
18
16
  return abs;
19
17
  }
20
18
  function assertPathSafe(raw, context, label) {
21
- const abs = resolveToolPath(raw, context?.cwd, {
22
- allowRoots: context?.pathRoots,
23
- containment: context?.pathContainment,
24
- });
19
+ const abs = resolveToolPath(raw, context?.cwd, containmentOptions(context));
25
20
  if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
26
21
  throw new Error(`session attachments are read-only; cannot ${label} under attachments root`);
27
22
  }
@@ -43,6 +38,12 @@ function toGitPathspec(raw, context, label) {
43
38
  if (!isMagic) {
44
39
  return assertPathSafe(raw, context, label);
45
40
  }
41
+ const denylist = context?.pathDenylist ?? [];
42
+ // A glob pathspec is matched by git, not by us, so we cannot prove it excludes
43
+ // denied paths. Fail closed instead of shipping an unverifiable allow.
44
+ if (denylist.length > 0) {
45
+ throw new Error(`pathspec_glob_forbidden: glob pathspec "${raw}" cannot be checked against pathDenylist; pass explicit paths`);
46
+ }
46
47
  if (raw.startsWith('/') ||
47
48
  raw.startsWith('\\\\') ||
48
49
  (process.platform === 'win32' && /^[A-Za-z]:[\\/]/.test(raw))) {
@@ -56,9 +57,116 @@ function toGitPathspec(raw, context, label) {
56
57
  }
57
58
  return raw;
58
59
  }
59
- function toText(result) {
60
+ /**
61
+ * Decode a git-quoted path (`"a\tb"`) into its literal spelling.
62
+ *
63
+ * @param token - path token straight from git output
64
+ * @returns the path git meant, without the a/ or b/ side prefix
65
+ */
66
+ function unquoteGitPath(token) {
67
+ const body = token.startsWith('"') && token.endsWith('"')
68
+ ? token.slice(1, -1).replace(/\\(.)/g, '$1')
69
+ : token;
70
+ return body.replace(/^[ab]\//, '');
71
+ }
72
+ /**
73
+ * Split the arguments of a `diff --git a/<path> b/<path>` header.
74
+ *
75
+ * @param rest - header text after `diff --git `
76
+ * @returns path tokens, still quoted when git quoted them
77
+ */
78
+ function splitDiffHeader(rest) {
79
+ const tokens = [];
80
+ let index = 0;
81
+ while (index < rest.length) {
82
+ if (rest[index] === ' ') {
83
+ index += 1;
84
+ continue;
85
+ }
86
+ let token = '';
87
+ while (index < rest.length && rest[index] !== ' ') {
88
+ if (rest[index] === '"') {
89
+ token += '"';
90
+ index += 1;
91
+ while (index < rest.length) {
92
+ if (rest[index] === '\\' && index + 1 < rest.length) {
93
+ token += rest[index] + rest[index + 1];
94
+ index += 2;
95
+ continue;
96
+ }
97
+ token += rest[index];
98
+ if (rest[index] === '"') {
99
+ index += 1;
100
+ break;
101
+ }
102
+ index += 1;
103
+ }
104
+ continue;
105
+ }
106
+ token += rest[index];
107
+ index += 1;
108
+ }
109
+ tokens.push(token);
110
+ }
111
+ return tokens;
112
+ }
113
+ /**
114
+ * Drop git output that names or contains denied paths.
115
+ *
116
+ * `git_diff` / `git_show` emit file *contents* keyed by section headers, and
117
+ * `git_status` emits bare paths, so path arguments alone are not enough: a
118
+ * deployment that denies `.env*` must not get that content back through VCS.
119
+ * Truncated diffs cannot be verified section by section, so they are refused
120
+ * rather than returned unverified.
121
+ *
122
+ * @param text - raw git stdout
123
+ * @param truncated - whether the runner cut the output
124
+ * @param patterns - denylist globs
125
+ * @param kind - output shape
126
+ * @returns filtered stdout
127
+ */
128
+ function filterGitOutput(text, truncated, patterns, kind) {
129
+ if (patterns.length === 0)
130
+ return text;
131
+ const lines = text.split('\n');
132
+ if (kind === 'status') {
133
+ return lines
134
+ .filter((line) => {
135
+ if (line.startsWith('##') || line.length < 4)
136
+ return true;
137
+ const raw = line.slice(3);
138
+ const target = raw.includes(' -> ') ? raw.slice(raw.lastIndexOf(' -> ') + 4) : raw;
139
+ return !matchesDenyPattern(unquoteGitPath(target.trim()), patterns);
140
+ })
141
+ .join('\n');
142
+ }
143
+ if (truncated) {
144
+ throw new Error('path_forbidden: git output was truncated, so pathDenylist could not be verified; narrow the request');
145
+ }
146
+ let dropping = false;
147
+ const kept = [];
148
+ for (const line of lines) {
149
+ if (line.startsWith('diff --git ')) {
150
+ const paths = splitDiffHeader(line.slice('diff --git '.length)).map(unquoteGitPath);
151
+ dropping = paths.some((path) => matchesDenyPattern(path, patterns));
152
+ }
153
+ else if (/^ .+?\s+\|\s+\d+/.test(line)) {
154
+ // `--stat` rows are single lines, not sections; test the named path.
155
+ const path = unquoteGitPath(line.trim().split(/\s+\|\s+/)[0].trim());
156
+ if (matchesDenyPattern(path, patterns))
157
+ continue;
158
+ }
159
+ if (!dropping)
160
+ kept.push(line);
161
+ }
162
+ return kept.join('\n');
163
+ }
164
+ function toText(result, context, contentKind) {
165
+ const stdout = contentKind
166
+ ? filterGitOutput(result.stdout, result.truncated, context?.pathDenylist ?? [], contentKind)
167
+ : result.stdout;
60
168
  return {
61
- stdout: result.stdout,
169
+ stdout,
62
170
  stderr: result.stderr,
63
171
  exitCode: result.exitCode,
64
172
  durationMs: result.durationMs,
@@ -95,7 +203,7 @@ export function createGitStatusTool() {
95
203
  '--untracked-files=all',
96
204
  ...pathArgs,
97
205
  ]);
98
- return { ...toText(result), cwd };
206
+ return { ...toText(result, context, 'status'), cwd };
99
207
  },
100
208
  };
101
209
  }
@@ -147,7 +255,7 @@ export function createGitDiffTool() {
147
255
  gitArgs.push('--', ...paths.map((p) => toGitPathspec(p, context, 'diff')));
148
256
  }
149
257
  const result = await runGit(context, cwd, gitArgs, { timeoutMs: 120_000 });
150
- return { ...toText(result), cwd, mode };
258
+ return { ...toText(result, context, 'diff'), cwd, mode };
151
259
  },
152
260
  };
153
261
  }
@@ -215,7 +323,7 @@ export function createGitShowTool() {
215
323
  gitArgs.push('--stat');
216
324
  gitArgs.push(rev);
217
325
  const result = await runGit(context, cwd, gitArgs, { timeoutMs: 120_000 });
218
- return { ...toText(result), cwd, revision: rev };
326
+ return { ...toText(result, context, 'diff'), cwd, revision: rev };
219
327
  },
220
328
  };
221
329
  }
@@ -11,15 +11,12 @@
11
11
  import { tmpdir } from 'node:os';
12
12
  import { join } from 'node:path';
13
13
  import { gateEffect } from '../../execution-environment/effect-policy.js';
14
- import { isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, findExecutable, } from './platform.js';
14
+ import { containmentOptions, findExecutable, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, } from './platform.js';
15
15
  import { runAllowlistedArgv } from './allowlisted-run.js';
16
16
  import { resolveNodeToolCommand } from './platform.js';
17
17
  function resolveCwd(context, raw) {
18
18
  const cwd = raw ?? context?.cwd ?? process.cwd();
19
- const abs = resolveToolPath(cwd, context?.cwd, {
20
- allowRoots: context?.pathRoots,
21
- containment: context?.pathContainment,
22
- });
19
+ const abs = resolveToolPath(cwd, context?.cwd, containmentOptions(context));
23
20
  if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
24
21
  throw new Error('session attachments are read-only; cannot run package tools under attachments root');
25
22
  }
@@ -29,10 +26,7 @@ function resolveCwd(context, raw) {
29
26
  return abs;
30
27
  }
31
28
  function assertPathSafe(raw, context, label) {
32
- const abs = resolveToolPath(raw, context?.cwd, {
33
- allowRoots: context?.pathRoots,
34
- containment: context?.pathContainment,
35
- });
29
+ const abs = resolveToolPath(raw, context?.cwd, containmentOptions(context));
36
30
  if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
37
31
  throw new Error(`session attachments are read-only; cannot ${label} under attachments root`);
38
32
  }
@@ -235,10 +229,7 @@ export function createProjectRunTool() {
235
229
  if (!script || !/^[A-Za-z0-9][A-Za-z0-9:._-]*$/.test(script)) {
236
230
  throw new Error(`project_run: invalid script name "${script}"`);
237
231
  }
238
- const pkgPath = resolveToolPath('package.json', cwd, {
239
- allowRoots: context?.pathRoots,
240
- containment: context?.pathContainment,
241
- });
232
+ const pkgPath = resolveToolPath('package.json', cwd, containmentOptions(context));
242
233
  const { pkg } = await readPackageJson(pkgPath);
243
234
  const scripts = (pkg.scripts ?? {});
244
235
  if (typeof scripts[script] !== 'string') {