@caupulican/pi-adaptative 0.81.40 → 0.81.42

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 (599) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +1 -0
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +1 -0
  6. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +5 -1
  7. package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +3 -3
  8. package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +8 -0
  9. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +26 -3
  10. package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +3 -0
  11. package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +4 -1
  12. package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +2 -1
  13. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +2 -0
  14. package/dist/cli/args.d.ts +2 -0
  15. package/dist/cli/args.d.ts.map +1 -1
  16. package/dist/cli/args.js +22 -1
  17. package/dist/cli/args.js.map +1 -1
  18. package/dist/core/agent-paths.d.ts +38 -0
  19. package/dist/core/agent-paths.d.ts.map +1 -1
  20. package/dist/core/agent-paths.js +77 -0
  21. package/dist/core/agent-paths.js.map +1 -1
  22. package/dist/core/agent-session-contracts.d.ts +311 -0
  23. package/dist/core/agent-session-contracts.d.ts.map +1 -0
  24. package/dist/core/agent-session-contracts.js +26 -0
  25. package/dist/core/agent-session-contracts.js.map +1 -0
  26. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  27. package/dist/core/agent-session-runtime.js +3 -0
  28. package/dist/core/agent-session-runtime.js.map +1 -1
  29. package/dist/core/agent-session.d.ts +26 -405
  30. package/dist/core/agent-session.d.ts.map +1 -1
  31. package/dist/core/agent-session.js +90 -316
  32. package/dist/core/agent-session.js.map +1 -1
  33. package/dist/core/auth-storage.d.ts.map +1 -1
  34. package/dist/core/auth-storage.js +3 -1
  35. package/dist/core/auth-storage.js.map +1 -1
  36. package/dist/core/autonomy/contracts.d.ts +2 -0
  37. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  38. package/dist/core/autonomy/contracts.js.map +1 -1
  39. package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
  40. package/dist/core/autonomy/envelope-enforcement.js +4 -9
  41. package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
  42. package/dist/core/autonomy/lane-tool-surface.d.ts +3 -1
  43. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  44. package/dist/core/autonomy/lane-tool-surface.js +19 -5
  45. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  46. package/dist/core/autonomy/path-scope.d.ts +14 -0
  47. package/dist/core/autonomy/path-scope.d.ts.map +1 -1
  48. package/dist/core/autonomy/path-scope.js +37 -6
  49. package/dist/core/autonomy/path-scope.js.map +1 -1
  50. package/dist/core/background-lane-controller.d.ts +30 -2
  51. package/dist/core/background-lane-controller.d.ts.map +1 -1
  52. package/dist/core/background-lane-controller.js +33 -1
  53. package/dist/core/background-lane-controller.js.map +1 -1
  54. package/dist/core/bedrock-sso-login.d.ts +16 -0
  55. package/dist/core/bedrock-sso-login.d.ts.map +1 -0
  56. package/dist/core/bedrock-sso-login.js +98 -0
  57. package/dist/core/bedrock-sso-login.js.map +1 -0
  58. package/dist/core/compaction-controller.d.ts.map +1 -1
  59. package/dist/core/compaction-controller.js +1 -1
  60. package/dist/core/compaction-controller.js.map +1 -1
  61. package/dist/core/compaction-support.d.ts +3 -8
  62. package/dist/core/compaction-support.d.ts.map +1 -1
  63. package/dist/core/compaction-support.js +3 -3
  64. package/dist/core/compaction-support.js.map +1 -1
  65. package/dist/core/context-pipeline.d.ts +1 -1
  66. package/dist/core/context-pipeline.d.ts.map +1 -1
  67. package/dist/core/context-pipeline.js +7 -33
  68. package/dist/core/context-pipeline.js.map +1 -1
  69. package/dist/core/cost/cost-summary.d.ts.map +1 -1
  70. package/dist/core/cost/cost-summary.js +5 -3
  71. package/dist/core/cost/cost-summary.js.map +1 -1
  72. package/dist/core/cost/daily-usage.d.ts.map +1 -1
  73. package/dist/core/cost/daily-usage.js +4 -5
  74. package/dist/core/cost/daily-usage.js.map +1 -1
  75. package/dist/core/default-tool-surface.d.ts.map +1 -1
  76. package/dist/core/default-tool-surface.js +1 -0
  77. package/dist/core/default-tool-surface.js.map +1 -1
  78. package/dist/core/delegation/managed-lane-controller.d.ts +11 -1
  79. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
  80. package/dist/core/delegation/managed-lane-controller.js +84 -41
  81. package/dist/core/delegation/managed-lane-controller.js.map +1 -1
  82. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
  83. package/dist/core/delegation/session-worker-claim.js +4 -3
  84. package/dist/core/delegation/session-worker-claim.js.map +1 -1
  85. package/dist/core/delegation/worker-action-journal.d.ts +73 -0
  86. package/dist/core/delegation/worker-action-journal.d.ts.map +1 -0
  87. package/dist/core/delegation/worker-action-journal.js +297 -0
  88. package/dist/core/delegation/worker-action-journal.js.map +1 -0
  89. package/dist/core/delegation/worker-actions.d.ts +36 -1
  90. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  91. package/dist/core/delegation/worker-actions.js +171 -46
  92. package/dist/core/delegation/worker-actions.js.map +1 -1
  93. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +75 -0
  94. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -0
  95. package/dist/core/delegation/worker-agent-control-coordinator.js +218 -0
  96. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -0
  97. package/dist/core/delegation/worker-agent-control.d.ts +66 -0
  98. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -0
  99. package/dist/core/delegation/worker-agent-control.js +163 -0
  100. package/dist/core/delegation/worker-agent-control.js.map +1 -0
  101. package/dist/core/delegation/worker-attempt-executor.d.ts +80 -0
  102. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -0
  103. package/dist/core/delegation/worker-attempt-executor.js +343 -0
  104. package/dist/core/delegation/worker-attempt-executor.js.map +1 -0
  105. package/dist/core/delegation/worker-claim.d.ts +30 -0
  106. package/dist/core/delegation/worker-claim.d.ts.map +1 -1
  107. package/dist/core/delegation/worker-claim.js +205 -53
  108. package/dist/core/delegation/worker-claim.js.map +1 -1
  109. package/dist/core/delegation/worker-conversation-store.d.ts +116 -0
  110. package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -0
  111. package/dist/core/delegation/worker-conversation-store.js +442 -0
  112. package/dist/core/delegation/worker-conversation-store.js.map +1 -0
  113. package/dist/core/delegation/worker-delegation-controller.d.ts +21 -5
  114. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  115. package/dist/core/delegation/worker-delegation-controller.js +386 -251
  116. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  117. package/dist/core/delegation/worker-delegation-request.d.ts +14 -0
  118. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  119. package/dist/core/delegation/worker-delegation-request.js.map +1 -1
  120. package/dist/core/delegation/worker-dispatch-scheduler.d.ts +4 -2
  121. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
  122. package/dist/core/delegation/worker-dispatch-scheduler.js +16 -6
  123. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
  124. package/dist/core/delegation/worker-execution-policy.d.ts +2 -1
  125. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
  126. package/dist/core/delegation/worker-execution-policy.js +5 -7
  127. package/dist/core/delegation/worker-execution-policy.js.map +1 -1
  128. package/dist/core/delegation/worker-lifecycle.d.ts +44 -1
  129. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  130. package/dist/core/delegation/worker-lifecycle.js +120 -0
  131. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  132. package/dist/core/delegation/worker-process-owner.d.ts +18 -0
  133. package/dist/core/delegation/worker-process-owner.d.ts.map +1 -0
  134. package/dist/core/delegation/worker-process-owner.js +54 -0
  135. package/dist/core/delegation/worker-process-owner.js.map +1 -0
  136. package/dist/core/delegation/worker-profile-resolver.d.ts +5 -1
  137. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  138. package/dist/core/delegation/worker-profile-resolver.js +8 -0
  139. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  140. package/dist/core/delegation/worker-recovery-coordinator.d.ts +54 -0
  141. package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -0
  142. package/dist/core/delegation/worker-recovery-coordinator.js +181 -0
  143. package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -0
  144. package/dist/core/delegation/worker-resource-catalog.d.ts +32 -0
  145. package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -0
  146. package/dist/core/delegation/worker-resource-catalog.js +116 -0
  147. package/dist/core/delegation/worker-resource-catalog.js.map +1 -0
  148. package/dist/core/delegation/worker-resource-materializer.d.ts +47 -0
  149. package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -0
  150. package/dist/core/delegation/worker-resource-materializer.js +137 -0
  151. package/dist/core/delegation/worker-resource-materializer.js.map +1 -0
  152. package/dist/core/delegation/worker-runner.d.ts +3 -1
  153. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  154. package/dist/core/delegation/worker-runner.js +189 -54
  155. package/dist/core/delegation/worker-runner.js.map +1 -1
  156. package/dist/core/delegation/worker-terminal-finalizer.d.ts +23 -0
  157. package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -0
  158. package/dist/core/delegation/worker-terminal-finalizer.js +12 -0
  159. package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -0
  160. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +38 -0
  161. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -0
  162. package/dist/core/delegation/worker-write-reservation-coordinator.js +107 -0
  163. package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -0
  164. package/dist/core/delegation/worker-write-reservation.d.ts +90 -0
  165. package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -0
  166. package/dist/core/delegation/worker-write-reservation.js +348 -0
  167. package/dist/core/delegation/worker-write-reservation.js.map +1 -0
  168. package/dist/core/extension-import-authority.d.ts +6 -0
  169. package/dist/core/extension-import-authority.d.ts.map +1 -0
  170. package/dist/core/extension-import-authority.js +10 -0
  171. package/dist/core/extension-import-authority.js.map +1 -0
  172. package/dist/core/extensions/loader.d.ts.map +1 -1
  173. package/dist/core/extensions/loader.js +2 -3
  174. package/dist/core/extensions/loader.js.map +1 -1
  175. package/dist/core/extensions/runner.d.ts +3 -0
  176. package/dist/core/extensions/runner.d.ts.map +1 -1
  177. package/dist/core/extensions/runner.js +14 -5
  178. package/dist/core/extensions/runner.js.map +1 -1
  179. package/dist/core/extensions/stale-context.d.ts +2 -0
  180. package/dist/core/extensions/stale-context.d.ts.map +1 -0
  181. package/dist/core/extensions/stale-context.js +2 -0
  182. package/dist/core/extensions/stale-context.js.map +1 -0
  183. package/dist/core/extensions/types.d.ts +8 -0
  184. package/dist/core/extensions/types.d.ts.map +1 -1
  185. package/dist/core/extensions/types.js.map +1 -1
  186. package/dist/core/foreground-recovery-controller.d.ts +1 -0
  187. package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
  188. package/dist/core/foreground-recovery-controller.js +13 -13
  189. package/dist/core/foreground-recovery-controller.js.map +1 -1
  190. package/dist/core/goal-loop-controller.d.ts +14 -9
  191. package/dist/core/goal-loop-controller.d.ts.map +1 -1
  192. package/dist/core/goal-loop-controller.js +47 -75
  193. package/dist/core/goal-loop-controller.js.map +1 -1
  194. package/dist/core/goals/compact-goal-context.d.ts +11 -0
  195. package/dist/core/goals/compact-goal-context.d.ts.map +1 -0
  196. package/dist/core/goals/compact-goal-context.js +59 -0
  197. package/dist/core/goals/compact-goal-context.js.map +1 -0
  198. package/dist/core/goals/goal-acceptance.d.ts.map +1 -1
  199. package/dist/core/goals/goal-acceptance.js +2 -0
  200. package/dist/core/goals/goal-acceptance.js.map +1 -1
  201. package/dist/core/goals/goal-auto-continue-controller.d.ts +2 -1
  202. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
  203. package/dist/core/goals/goal-auto-continue-controller.js +5 -8
  204. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
  205. package/dist/core/goals/goal-continuation-controller.d.ts +2 -2
  206. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  207. package/dist/core/goals/goal-continuation-controller.js +42 -11
  208. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  209. package/dist/core/goals/goal-continuation-defaults.d.ts +4 -29
  210. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
  211. package/dist/core/goals/goal-continuation-defaults.js +4 -32
  212. package/dist/core/goals/goal-continuation-defaults.js.map +1 -1
  213. package/dist/core/goals/goal-continuation-prompt.d.ts +8 -18
  214. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  215. package/dist/core/goals/goal-continuation-prompt.js +9 -179
  216. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  217. package/dist/core/goals/goal-lifecycle.d.ts +35 -12
  218. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
  219. package/dist/core/goals/goal-lifecycle.js +98 -13
  220. package/dist/core/goals/goal-lifecycle.js.map +1 -1
  221. package/dist/core/goals/goal-record.d.ts +17 -0
  222. package/dist/core/goals/goal-record.d.ts.map +1 -0
  223. package/dist/core/goals/goal-record.js +31 -0
  224. package/dist/core/goals/goal-record.js.map +1 -0
  225. package/dist/core/goals/goal-session-controller.d.ts +42 -0
  226. package/dist/core/goals/goal-session-controller.d.ts.map +1 -0
  227. package/dist/core/goals/goal-session-controller.js +128 -0
  228. package/dist/core/goals/goal-session-controller.js.map +1 -0
  229. package/dist/core/goals/goal-state.d.ts +45 -25
  230. package/dist/core/goals/goal-state.d.ts.map +1 -1
  231. package/dist/core/goals/goal-state.js +85 -15
  232. package/dist/core/goals/goal-state.js.map +1 -1
  233. package/dist/core/goals/goal-tool-core.d.ts +1 -4
  234. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  235. package/dist/core/goals/goal-tool-core.js +49 -34
  236. package/dist/core/goals/goal-tool-core.js.map +1 -1
  237. package/dist/core/goals/session-goal-state.d.ts +18 -8
  238. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  239. package/dist/core/goals/session-goal-state.js +134 -11
  240. package/dist/core/goals/session-goal-state.js.map +1 -1
  241. package/dist/core/human-input-controller.d.ts +47 -0
  242. package/dist/core/human-input-controller.d.ts.map +1 -0
  243. package/dist/core/human-input-controller.js +181 -0
  244. package/dist/core/human-input-controller.js.map +1 -0
  245. package/dist/core/local-runtime-controller.d.ts +1 -1
  246. package/dist/core/local-runtime-controller.d.ts.map +1 -1
  247. package/dist/core/local-runtime-controller.js.map +1 -1
  248. package/dist/core/model-capability.d.ts +0 -19
  249. package/dist/core/model-capability.d.ts.map +1 -1
  250. package/dist/core/model-capability.js +0 -19
  251. package/dist/core/model-capability.js.map +1 -1
  252. package/dist/core/model-registry.d.ts +6 -1
  253. package/dist/core/model-registry.d.ts.map +1 -1
  254. package/dist/core/model-registry.js +13 -5
  255. package/dist/core/model-registry.js.map +1 -1
  256. package/dist/core/model-resolver.d.ts +16 -1
  257. package/dist/core/model-resolver.d.ts.map +1 -1
  258. package/dist/core/model-resolver.js +32 -16
  259. package/dist/core/model-resolver.js.map +1 -1
  260. package/dist/core/model-router-controller.d.ts +1 -1
  261. package/dist/core/model-router-controller.d.ts.map +1 -1
  262. package/dist/core/model-router-controller.js.map +1 -1
  263. package/dist/core/model-selection-controller.d.ts +1 -1
  264. package/dist/core/model-selection-controller.d.ts.map +1 -1
  265. package/dist/core/model-selection-controller.js.map +1 -1
  266. package/dist/core/models/model-endpoint.d.ts +3 -0
  267. package/dist/core/models/model-endpoint.d.ts.map +1 -0
  268. package/dist/core/models/model-endpoint.js +11 -0
  269. package/dist/core/models/model-endpoint.js.map +1 -0
  270. package/dist/core/orchestration/agent-resume.d.ts +2 -0
  271. package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
  272. package/dist/core/orchestration/agent-resume.js +7 -0
  273. package/dist/core/orchestration/agent-resume.js.map +1 -1
  274. package/dist/core/orchestration/attempt-usage.d.ts +28 -0
  275. package/dist/core/orchestration/attempt-usage.d.ts.map +1 -0
  276. package/dist/core/orchestration/attempt-usage.js +168 -0
  277. package/dist/core/orchestration/attempt-usage.js.map +1 -0
  278. package/dist/core/orchestration/capability-gateway.d.ts +19 -1
  279. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  280. package/dist/core/orchestration/capability-gateway.js +128 -28
  281. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  282. package/dist/core/orchestration/contracts.d.ts +35 -0
  283. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  284. package/dist/core/orchestration/contracts.js +17 -0
  285. package/dist/core/orchestration/contracts.js.map +1 -1
  286. package/dist/core/orchestration/delegation-ledger.d.ts +17 -2
  287. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
  288. package/dist/core/orchestration/delegation-ledger.js +81 -3
  289. package/dist/core/orchestration/delegation-ledger.js.map +1 -1
  290. package/dist/core/orchestration/event-store.d.ts +1 -0
  291. package/dist/core/orchestration/event-store.d.ts.map +1 -1
  292. package/dist/core/orchestration/event-store.js +78 -38
  293. package/dist/core/orchestration/event-store.js.map +1 -1
  294. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  295. package/dist/core/orchestration/profile-registry.js +81 -41
  296. package/dist/core/orchestration/profile-registry.js.map +1 -1
  297. package/dist/core/orchestration/profile-store.d.ts.map +1 -1
  298. package/dist/core/orchestration/profile-store.js +18 -4
  299. package/dist/core/orchestration/profile-store.js.map +1 -1
  300. package/dist/core/orchestration/risk-budget.d.ts +2 -0
  301. package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
  302. package/dist/core/orchestration/risk-budget.js +26 -0
  303. package/dist/core/orchestration/risk-budget.js.map +1 -1
  304. package/dist/core/orchestration/task-runtime.d.ts +13 -1
  305. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  306. package/dist/core/orchestration/task-runtime.js +127 -16
  307. package/dist/core/orchestration/task-runtime.js.map +1 -1
  308. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -1
  309. package/dist/core/orchestration/work-state-projection.js +1 -1
  310. package/dist/core/orchestration/work-state-projection.js.map +1 -1
  311. package/dist/core/orchestration/worker-execution-contract.d.ts +3 -1
  312. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
  313. package/dist/core/orchestration/worker-execution-contract.js +75 -23
  314. package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
  315. package/dist/core/orchestration/worker-result-adapter.d.ts +9 -3
  316. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
  317. package/dist/core/orchestration/worker-result-adapter.js +167 -14
  318. package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
  319. package/dist/core/package-manager.d.ts.map +1 -1
  320. package/dist/core/package-manager.js +20 -3
  321. package/dist/core/package-manager.js.map +1 -1
  322. package/dist/core/profile-filter-controller.d.ts +8 -1
  323. package/dist/core/profile-filter-controller.d.ts.map +1 -1
  324. package/dist/core/profile-filter-controller.js +23 -5
  325. package/dist/core/profile-filter-controller.js.map +1 -1
  326. package/dist/core/prompt-templates.d.ts +1 -0
  327. package/dist/core/prompt-templates.d.ts.map +1 -1
  328. package/dist/core/prompt-templates.js +18 -29
  329. package/dist/core/prompt-templates.js.map +1 -1
  330. package/dist/core/reflection-controller.d.ts +2 -2
  331. package/dist/core/reflection-controller.d.ts.map +1 -1
  332. package/dist/core/reflection-controller.js +92 -54
  333. package/dist/core/reflection-controller.js.map +1 -1
  334. package/dist/core/request-auth.d.ts +7 -0
  335. package/dist/core/request-auth.d.ts.map +1 -0
  336. package/dist/core/request-auth.js +8 -0
  337. package/dist/core/request-auth.js.map +1 -0
  338. package/dist/core/research/evidence-bundle.d.ts +20 -0
  339. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  340. package/dist/core/research/evidence-bundle.js +173 -69
  341. package/dist/core/research/evidence-bundle.js.map +1 -1
  342. package/dist/core/resource-loader.d.ts.map +1 -1
  343. package/dist/core/resource-loader.js +16 -6
  344. package/dist/core/resource-loader.js.map +1 -1
  345. package/dist/core/risk-classifier.d.ts.map +1 -1
  346. package/dist/core/risk-classifier.js +8 -0
  347. package/dist/core/risk-classifier.js.map +1 -1
  348. package/dist/core/runtime-builder.d.ts +22 -3
  349. package/dist/core/runtime-builder.d.ts.map +1 -1
  350. package/dist/core/runtime-builder.js +147 -80
  351. package/dist/core/runtime-builder.js.map +1 -1
  352. package/dist/core/sdk.d.ts.map +1 -1
  353. package/dist/core/sdk.js +7 -1
  354. package/dist/core/sdk.js.map +1 -1
  355. package/dist/core/secrets/credential-exposure-guard.d.ts +9 -0
  356. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -0
  357. package/dist/core/secrets/credential-exposure-guard.js +241 -0
  358. package/dist/core/secrets/credential-exposure-guard.js.map +1 -0
  359. package/dist/core/secrets/secret-dotenv.d.ts +27 -0
  360. package/dist/core/secrets/secret-dotenv.d.ts.map +1 -0
  361. package/dist/core/secrets/secret-dotenv.js +183 -0
  362. package/dist/core/secrets/secret-dotenv.js.map +1 -0
  363. package/dist/core/secrets/secret-vault-format.d.ts +112 -0
  364. package/dist/core/secrets/secret-vault-format.d.ts.map +1 -0
  365. package/dist/core/secrets/secret-vault-format.js +397 -0
  366. package/dist/core/secrets/secret-vault-format.js.map +1 -0
  367. package/dist/core/secrets/secret-vault.d.ts +72 -0
  368. package/dist/core/secrets/secret-vault.d.ts.map +1 -0
  369. package/dist/core/secrets/secret-vault.js +671 -0
  370. package/dist/core/secrets/secret-vault.js.map +1 -0
  371. package/dist/core/session-analytics.d.ts +4 -23
  372. package/dist/core/session-analytics.d.ts.map +1 -1
  373. package/dist/core/session-analytics.js +39 -69
  374. package/dist/core/session-analytics.js.map +1 -1
  375. package/dist/core/session-artifact-bundle.d.ts +35 -0
  376. package/dist/core/session-artifact-bundle.d.ts.map +1 -0
  377. package/dist/core/session-artifact-bundle.js +61 -0
  378. package/dist/core/session-artifact-bundle.js.map +1 -0
  379. package/dist/core/session-role.d.ts +5 -0
  380. package/dist/core/session-role.d.ts.map +1 -1
  381. package/dist/core/session-role.js +14 -1
  382. package/dist/core/session-role.js.map +1 -1
  383. package/dist/core/session-tree-navigator.d.ts +4 -6
  384. package/dist/core/session-tree-navigator.d.ts.map +1 -1
  385. package/dist/core/session-tree-navigator.js +4 -1
  386. package/dist/core/session-tree-navigator.js.map +1 -1
  387. package/dist/core/settings-manager.d.ts +1 -1
  388. package/dist/core/settings-manager.d.ts.map +1 -1
  389. package/dist/core/settings-manager.js +1 -1
  390. package/dist/core/settings-manager.js.map +1 -1
  391. package/dist/core/slash-commands.d.ts.map +1 -1
  392. package/dist/core/slash-commands.js +2 -2
  393. package/dist/core/slash-commands.js.map +1 -1
  394. package/dist/core/tool-capability-policy.d.ts.map +1 -1
  395. package/dist/core/tool-capability-policy.js +1 -0
  396. package/dist/core/tool-capability-policy.js.map +1 -1
  397. package/dist/core/tool-gate-controller.d.ts.map +1 -1
  398. package/dist/core/tool-gate-controller.js +8 -2
  399. package/dist/core/tool-gate-controller.js.map +1 -1
  400. package/dist/core/tool-protocol-controller.d.ts +2 -4
  401. package/dist/core/tool-protocol-controller.d.ts.map +1 -1
  402. package/dist/core/tool-protocol-controller.js.map +1 -1
  403. package/dist/core/tool-recovery-stats.d.ts +21 -1
  404. package/dist/core/tool-recovery-stats.d.ts.map +1 -1
  405. package/dist/core/tool-recovery-stats.js.map +1 -1
  406. package/dist/core/tools/bash.d.ts +5 -0
  407. package/dist/core/tools/bash.d.ts.map +1 -1
  408. package/dist/core/tools/bash.js +59 -5
  409. package/dist/core/tools/bash.js.map +1 -1
  410. package/dist/core/tools/delegate-status.d.ts +6 -1
  411. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  412. package/dist/core/tools/delegate-status.js +106 -25
  413. package/dist/core/tools/delegate-status.js.map +1 -1
  414. package/dist/core/tools/delegate.d.ts +9 -1
  415. package/dist/core/tools/delegate.d.ts.map +1 -1
  416. package/dist/core/tools/delegate.js +329 -69
  417. package/dist/core/tools/delegate.js.map +1 -1
  418. package/dist/core/tools/git-filter.d.ts +1 -8
  419. package/dist/core/tools/git-filter.d.ts.map +1 -1
  420. package/dist/core/tools/git-filter.js +2 -63
  421. package/dist/core/tools/git-filter.js.map +1 -1
  422. package/dist/core/tools/goal.d.ts +5 -3
  423. package/dist/core/tools/goal.d.ts.map +1 -1
  424. package/dist/core/tools/goal.js +97 -19
  425. package/dist/core/tools/goal.js.map +1 -1
  426. package/dist/core/tools/index.d.ts +1 -0
  427. package/dist/core/tools/index.d.ts.map +1 -1
  428. package/dist/core/tools/index.js +1 -0
  429. package/dist/core/tools/index.js.map +1 -1
  430. package/dist/core/tools/orchestration-panel.d.ts +1 -4
  431. package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
  432. package/dist/core/tools/orchestration-panel.js +0 -44
  433. package/dist/core/tools/orchestration-panel.js.map +1 -1
  434. package/dist/core/tools/output-accumulator.d.ts +11 -0
  435. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  436. package/dist/core/tools/output-accumulator.js +36 -3
  437. package/dist/core/tools/output-accumulator.js.map +1 -1
  438. package/dist/core/tools/python.d.ts +2 -0
  439. package/dist/core/tools/python.d.ts.map +1 -1
  440. package/dist/core/tools/python.js +3 -1
  441. package/dist/core/tools/python.js.map +1 -1
  442. package/dist/core/tools/read.d.ts.map +1 -1
  443. package/dist/core/tools/read.js +1 -1
  444. package/dist/core/tools/read.js.map +1 -1
  445. package/dist/core/tools/run-process.d.ts +1 -1
  446. package/dist/core/tools/run-process.d.ts.map +1 -1
  447. package/dist/core/tools/run-process.js +69 -9
  448. package/dist/core/tools/run-process.js.map +1 -1
  449. package/dist/core/tools/search-command-guard.d.ts +14 -0
  450. package/dist/core/tools/search-command-guard.d.ts.map +1 -0
  451. package/dist/core/tools/search-command-guard.js +333 -0
  452. package/dist/core/tools/search-command-guard.js.map +1 -0
  453. package/dist/core/tools/secret-store.d.ts +38 -0
  454. package/dist/core/tools/secret-store.d.ts.map +1 -0
  455. package/dist/core/tools/secret-store.js +412 -0
  456. package/dist/core/tools/secret-store.js.map +1 -0
  457. package/dist/core/tools/shell-command-parser.d.ts +16 -0
  458. package/dist/core/tools/shell-command-parser.d.ts.map +1 -0
  459. package/dist/core/tools/shell-command-parser.js +113 -0
  460. package/dist/core/tools/shell-command-parser.js.map +1 -0
  461. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  462. package/dist/core/tools/shell-contract-router.js +12 -5
  463. package/dist/core/tools/shell-contract-router.js.map +1 -1
  464. package/dist/core/tools/task-steps.d.ts.map +1 -1
  465. package/dist/core/tools/task-steps.js +4 -7
  466. package/dist/core/tools/task-steps.js.map +1 -1
  467. package/dist/core/util/atomic-file.d.ts +6 -2
  468. package/dist/core/util/atomic-file.d.ts.map +1 -1
  469. package/dist/core/util/atomic-file.js +4 -4
  470. package/dist/core/util/atomic-file.js.map +1 -1
  471. package/dist/core/util/bounded-file.d.ts +15 -0
  472. package/dist/core/util/bounded-file.d.ts.map +1 -0
  473. package/dist/core/util/bounded-file.js +120 -0
  474. package/dist/core/util/bounded-file.js.map +1 -0
  475. package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
  476. package/dist/core/util/bounded-jsonl.js +119 -9
  477. package/dist/core/util/bounded-jsonl.js.map +1 -1
  478. package/dist/core/util/bounded-value.d.ts +3 -0
  479. package/dist/core/util/bounded-value.d.ts.map +1 -0
  480. package/dist/core/util/bounded-value.js +12 -0
  481. package/dist/core/util/bounded-value.js.map +1 -0
  482. package/dist/core/util/value-guards.d.ts +2 -0
  483. package/dist/core/util/value-guards.d.ts.map +1 -1
  484. package/dist/core/util/value-guards.js +5 -0
  485. package/dist/core/util/value-guards.js.map +1 -1
  486. package/dist/index.d.ts +3 -2
  487. package/dist/index.d.ts.map +1 -1
  488. package/dist/index.js +2 -1
  489. package/dist/index.js.map +1 -1
  490. package/dist/main.d.ts.map +1 -1
  491. package/dist/main.js +25 -11
  492. package/dist/main.js.map +1 -1
  493. package/dist/modes/interactive/auth-dialogs-controller.d.ts +4 -0
  494. package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
  495. package/dist/modes/interactive/auth-dialogs-controller.js +60 -1
  496. package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
  497. package/dist/modes/interactive/components/activity-lane.d.ts +55 -0
  498. package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -0
  499. package/dist/modes/interactive/components/activity-lane.js +304 -0
  500. package/dist/modes/interactive/components/activity-lane.js.map +1 -0
  501. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  502. package/dist/modes/interactive/components/assistant-message.js +19 -10
  503. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  504. package/dist/modes/interactive/components/expandable-text.d.ts +12 -0
  505. package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -0
  506. package/dist/modes/interactive/components/expandable-text.js +17 -0
  507. package/dist/modes/interactive/components/expandable-text.js.map +1 -0
  508. package/dist/modes/interactive/components/extension-editor.d.ts +15 -1
  509. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  510. package/dist/modes/interactive/components/extension-editor.js +30 -21
  511. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  512. package/dist/modes/interactive/components/extension-input.d.ts +1 -0
  513. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  514. package/dist/modes/interactive/components/extension-input.js +6 -1
  515. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  516. package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
  517. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  518. package/dist/modes/interactive/components/scoped-models-selector.js +23 -14
  519. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  520. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  521. package/dist/modes/interactive/components/session-selector.js +27 -44
  522. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  523. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  524. package/dist/modes/interactive/components/settings-selector.js +4 -4
  525. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  526. package/dist/modes/interactive/components/tool-execution.d.ts +19 -11
  527. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  528. package/dist/modes/interactive/components/tool-execution.js +53 -20
  529. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  530. package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
  531. package/dist/modes/interactive/components/tool-group.js +3 -0
  532. package/dist/modes/interactive/components/tool-group.js.map +1 -1
  533. package/dist/modes/interactive/components/usage-action-selector.d.ts +16 -0
  534. package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -0
  535. package/dist/modes/interactive/components/usage-action-selector.js +46 -0
  536. package/dist/modes/interactive/components/usage-action-selector.js.map +1 -0
  537. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  538. package/dist/modes/interactive/extension-ui-host.js +1 -0
  539. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  540. package/dist/modes/interactive/external-editor.d.ts +15 -0
  541. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  542. package/dist/modes/interactive/external-editor.js +27 -19
  543. package/dist/modes/interactive/external-editor.js.map +1 -1
  544. package/dist/modes/interactive/history-reload-math.d.ts +6 -2
  545. package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
  546. package/dist/modes/interactive/history-reload-math.js +10 -5
  547. package/dist/modes/interactive/history-reload-math.js.map +1 -1
  548. package/dist/modes/interactive/interactive-event-controller.d.ts +74 -0
  549. package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -0
  550. package/dist/modes/interactive/interactive-event-controller.js +328 -0
  551. package/dist/modes/interactive/interactive-event-controller.js.map +1 -0
  552. package/dist/modes/interactive/interactive-mode.d.ts +20 -25
  553. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  554. package/dist/modes/interactive/interactive-mode.js +196 -608
  555. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  556. package/dist/modes/interactive/loaded-resources-view.d.ts +20 -0
  557. package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -0
  558. package/dist/modes/interactive/loaded-resources-view.js +147 -0
  559. package/dist/modes/interactive/loaded-resources-view.js.map +1 -0
  560. package/dist/modes/interactive/resource-display.d.ts.map +1 -1
  561. package/dist/modes/interactive/resource-display.js +8 -2
  562. package/dist/modes/interactive/resource-display.js.map +1 -1
  563. package/dist/modes/interactive/resource-shell-commands.d.ts +1 -5
  564. package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
  565. package/dist/modes/interactive/resource-shell-commands.js +0 -5
  566. package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
  567. package/dist/modes/interactive/session-flow-commands.d.ts +10 -6
  568. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  569. package/dist/modes/interactive/session-flow-commands.js +123 -70
  570. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  571. package/dist/modes/interactive/usage-commands.d.ts +34 -0
  572. package/dist/modes/interactive/usage-commands.d.ts.map +1 -0
  573. package/dist/modes/interactive/usage-commands.js +225 -0
  574. package/dist/modes/interactive/usage-commands.js.map +1 -0
  575. package/dist/utils/shell.d.ts.map +1 -1
  576. package/dist/utils/shell.js +5 -3
  577. package/dist/utils/shell.js.map +1 -1
  578. package/dist/utils/version-check.d.ts.map +1 -1
  579. package/dist/utils/version-check.js +3 -1
  580. package/dist/utils/version-check.js.map +1 -1
  581. package/docs/UI_POLISH_ORCHESTRATION.md +25 -31
  582. package/docs/UI_QUALITY_ORCHESTRATION.md +22 -24
  583. package/docs/providers.md +9 -1
  584. package/docs/tool-repair.md +3 -0
  585. package/docs/ui-reference/README.md +6 -6
  586. package/docs/ui-reference/orchestration-after.txt +14 -7
  587. package/docs/ui-reference/orchestration-before.txt +12 -6
  588. package/docs/ui-reference/orchestration-reference.txt +15 -5
  589. package/docs/usage.md +9 -1
  590. package/docs/windows.md +4 -2
  591. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  592. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  593. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  594. package/examples/extensions/sandbox/package-lock.json +2 -2
  595. package/examples/extensions/sandbox/package.json +1 -1
  596. package/examples/extensions/with-deps/package-lock.json +2 -2
  597. package/examples/extensions/with-deps/package.json +1 -1
  598. package/npm-shrinkwrap.json +13 -13
  599. package/package.json +4 -4
@@ -0,0 +1,348 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { existsSync, mkdirSync, unlinkSync, watch } from "node:fs";
3
+ import { basename, dirname } from "node:path";
4
+ import { stateFile } from "../agent-paths.js";
5
+ import { canonicalPathScopeIdentity, isPathWithinScope, pathScopesOverlap, safeRealpathSync, } from "../autonomy/path-scope.js";
6
+ import { withFileLockSync, writeFileAtomicSync } from "../util/atomic-file.js";
7
+ import { readBoundedTextFileSync } from "../util/bounded-file.js";
8
+ import { requireBoundedTrimmedText } from "../util/bounded-value.js";
9
+ import { parseLocalWorkerProcessOwnerId } from "./worker-process-owner.js";
10
+ const SCHEMA_VERSION = 1;
11
+ const MAX_IDENTIFIER_CHARS = 256;
12
+ const MAX_PATH_CHARS = 4096;
13
+ const MAX_SCOPES = 32;
14
+ const MAX_RESERVATIONS = 64;
15
+ const MAX_FILE_BYTES = 128 * 1024;
16
+ const availabilityListeners = new Map();
17
+ function positiveFencingToken(value) {
18
+ if (!Number.isSafeInteger(value) || value < 1)
19
+ throw new TypeError("Fencing token must be a positive safe integer.");
20
+ return value;
21
+ }
22
+ /**
23
+ * Prefer a real path for filesystem-backed scopes, but preserve a foreign lexical path family
24
+ * (for example a Windows drive path inspected from WSL) so shared path-scope helpers retain
25
+ * their documented Windows drive/UNC comparison semantics.
26
+ */
27
+ function canonicalRealOrLexicalPath(value, label) {
28
+ const lexical = canonicalPathScopeIdentity(requireBoundedTrimmedText(value, MAX_PATH_CHARS, label));
29
+ const resolved = safeRealpathSync(lexical);
30
+ return pathScopesOverlap(lexical, resolved) ? canonicalPathScopeIdentity(resolved) : lexical;
31
+ }
32
+ function canonicalWorkspace(workspace) {
33
+ const repositoryRoot = canonicalRealOrLexicalPath(workspace.repositoryRoot, "Repository root");
34
+ const executionRoot = canonicalRealOrLexicalPath(workspace.executionRoot, "Execution root");
35
+ const isolatedWorktreeId = workspace.isolatedWorktreeId
36
+ ? requireBoundedTrimmedText(workspace.isolatedWorktreeId, MAX_IDENTIFIER_CHARS, "Isolated worktree id")
37
+ : undefined;
38
+ const isPrimaryExecutionRoot = isPathWithinScope(executionRoot, repositoryRoot) && isPathWithinScope(repositoryRoot, executionRoot);
39
+ if (isPrimaryExecutionRoot && isolatedWorktreeId) {
40
+ throw new TypeError("An isolated worktree execution root must differ from the shared repository root.");
41
+ }
42
+ if (!isPrimaryExecutionRoot && !isolatedWorktreeId) {
43
+ throw new TypeError("A non-primary execution root requires an explicit isolated worktree identity.");
44
+ }
45
+ return {
46
+ repositoryRoot,
47
+ executionRoot,
48
+ executionIdentity: isolatedWorktreeId ? `isolated:${executionRoot}` : `shared:${repositoryRoot}`,
49
+ ...(isolatedWorktreeId ? { isolatedWorktreeId } : {}),
50
+ };
51
+ }
52
+ function reservationFile(agentDir, repositoryRoot) {
53
+ const digest = createHash("sha256")
54
+ .update("pi-worker-write-reservations-v1")
55
+ .update("\0")
56
+ .update(repositoryRoot)
57
+ .digest("hex");
58
+ return stateFile(agentDir, "orchestration", "worker-write-reservations", `${digest}.json`);
59
+ }
60
+ function notifyAvailability(filePath) {
61
+ for (const listener of availabilityListeners.get(filePath) ?? [])
62
+ queueMicrotask(listener);
63
+ }
64
+ function leaseFromRecord(filePath, record) {
65
+ return {
66
+ filePath,
67
+ reservationId: record.reservationId,
68
+ parentSessionId: record.parentSessionId,
69
+ ownerId: record.ownerId,
70
+ taskId: record.taskId,
71
+ attemptId: record.attemptId,
72
+ fencingToken: record.fencingToken,
73
+ repositoryRoot: record.repositoryRoot,
74
+ executionRoot: record.executionRoot,
75
+ executionIdentity: record.executionIdentity,
76
+ ...(record.isolatedWorktreeId ? { isolatedWorktreeId: record.isolatedWorktreeId } : {}),
77
+ writeScopes: [...record.writeScopes],
78
+ };
79
+ }
80
+ function stringField(value, label, maximum) {
81
+ if (typeof value !== "string")
82
+ throw new Error(`Worker write reservation ${label} is invalid.`);
83
+ return requireBoundedTrimmedText(value, maximum, `Worker write reservation ${label}`);
84
+ }
85
+ function localOwnerId(value) {
86
+ const ownerId = stringField(value, "owner id", MAX_IDENTIFIER_CHARS);
87
+ if (!parseLocalWorkerProcessOwnerId(ownerId))
88
+ throw new Error("Worker write reservation owner id is invalid.");
89
+ return ownerId;
90
+ }
91
+ function parseReservation(value, repositoryRoot) {
92
+ if (!value || typeof value !== "object" || Array.isArray(value))
93
+ throw new Error("Worker write reservation entry is invalid.");
94
+ const entry = value;
95
+ const fencingToken = entry.fencingToken;
96
+ if (typeof fencingToken !== "number")
97
+ throw new Error("Worker write reservation fencing token is invalid.");
98
+ const parsedRepositoryRoot = stringField(entry.repositoryRoot, "repository root", MAX_PATH_CHARS);
99
+ if (parsedRepositoryRoot !== repositoryRoot)
100
+ throw new Error("Worker write reservation repository root conflicts with its store.");
101
+ if (!Array.isArray(entry.writeScopes) || entry.writeScopes.length === 0 || entry.writeScopes.length > MAX_SCOPES) {
102
+ throw new Error("Worker write reservation scopes are invalid.");
103
+ }
104
+ const writeScopes = entry.writeScopes.map((scope) => stringField(scope, "write scope", MAX_PATH_CHARS));
105
+ const isolatedWorktreeId = entry.isolatedWorktreeId === undefined
106
+ ? undefined
107
+ : stringField(entry.isolatedWorktreeId, "isolated worktree id", MAX_IDENTIFIER_CHARS);
108
+ return {
109
+ reservationId: stringField(entry.reservationId, "id", MAX_IDENTIFIER_CHARS),
110
+ parentSessionId: stringField(entry.parentSessionId, "parent session", MAX_IDENTIFIER_CHARS),
111
+ ownerId: localOwnerId(entry.ownerId),
112
+ taskId: stringField(entry.taskId, "task", MAX_IDENTIFIER_CHARS),
113
+ attemptId: stringField(entry.attemptId, "attempt", MAX_IDENTIFIER_CHARS),
114
+ fencingToken: positiveFencingToken(fencingToken),
115
+ repositoryRoot: parsedRepositoryRoot,
116
+ executionRoot: stringField(entry.executionRoot, "execution root", MAX_PATH_CHARS),
117
+ executionIdentity: stringField(entry.executionIdentity, "execution identity", MAX_PATH_CHARS),
118
+ ...(isolatedWorktreeId ? { isolatedWorktreeId } : {}),
119
+ writeScopes,
120
+ createdAt: stringField(entry.createdAt, "created time", MAX_IDENTIFIER_CHARS),
121
+ };
122
+ }
123
+ function parseStore(raw, repositoryRoot) {
124
+ if (Buffer.byteLength(raw, "utf-8") > MAX_FILE_BYTES)
125
+ throw new Error("Worker write reservation store exceeds its byte limit.");
126
+ let value;
127
+ try {
128
+ value = JSON.parse(raw);
129
+ }
130
+ catch {
131
+ throw new Error("Worker write reservation store is unreadable; refusing concurrent write admission.");
132
+ }
133
+ if (!value || typeof value !== "object" || Array.isArray(value))
134
+ throw new Error("Worker write reservation store is invalid.");
135
+ const store = value;
136
+ if (store.schemaVersion !== SCHEMA_VERSION)
137
+ throw new Error("Worker write reservation store schema is unsupported.");
138
+ if (stringField(store.repositoryRoot, "store repository root", MAX_PATH_CHARS) !== repositoryRoot) {
139
+ throw new Error("Worker write reservation store root conflicts with the requested workspace.");
140
+ }
141
+ if (!Array.isArray(store.reservations) || store.reservations.length > MAX_RESERVATIONS) {
142
+ throw new Error("Worker write reservation store entries are invalid.");
143
+ }
144
+ const reservations = store.reservations.map((entry) => parseReservation(entry, repositoryRoot));
145
+ if (new Set(reservations.map((entry) => entry.reservationId)).size !== reservations.length) {
146
+ throw new Error("Worker write reservation store contains duplicate reservation identities.");
147
+ }
148
+ return { schemaVersion: SCHEMA_VERSION, repositoryRoot, reservations };
149
+ }
150
+ function writeStore(filePath, store) {
151
+ const serialized = `${JSON.stringify(store)}\n`;
152
+ if (Buffer.byteLength(serialized, "utf-8") > MAX_FILE_BYTES) {
153
+ throw new Error("Worker write reservation store would exceed its byte limit.");
154
+ }
155
+ writeFileAtomicSync(filePath, serialized, { mode: 0o600 });
156
+ }
157
+ function overlappingReservationIds(reservations, executionIdentity, writeScopes) {
158
+ const matches = [];
159
+ for (const reservation of reservations) {
160
+ if (reservation.executionIdentity !== executionIdentity)
161
+ continue;
162
+ if (reservation.writeScopes.some((reservedScope) => writeScopes.some((requestedScope) => pathScopesOverlap(reservedScope, requestedScope)))) {
163
+ matches.push(reservation.reservationId);
164
+ }
165
+ }
166
+ return matches;
167
+ }
168
+ /**
169
+ * Cross-process, agent-owned admission seam for concurrent worker mutations. It owns only
170
+ * reservations; lifecycle, process liveness, and terminal status remain controller concerns.
171
+ */
172
+ export class WorkerWriteReservationStore {
173
+ agentDir;
174
+ watchDirectory;
175
+ constructor(options) {
176
+ this.agentDir = requireBoundedTrimmedText(options.agentDir, MAX_PATH_CHARS, "Agent directory");
177
+ this.watchDirectory = options.watchDirectory ?? watch;
178
+ }
179
+ acquire(request) {
180
+ if (request.access === "read")
181
+ return { kind: "granted" };
182
+ if (request.access !== "write")
183
+ throw new TypeError("Worker write reservation access must be read or write.");
184
+ if (request.writeScopes.length === 0 || request.writeScopes.length > MAX_SCOPES) {
185
+ throw new TypeError(`Write reservations require from 1 through ${MAX_SCOPES} write scopes.`);
186
+ }
187
+ const workspace = canonicalWorkspace(request.workspace);
188
+ const writeScopes = [
189
+ ...new Set(request.writeScopes.map((scope) => canonicalRealOrLexicalPath(scope, "Write scope"))),
190
+ ].sort();
191
+ if (writeScopes.some((scope) => !isPathWithinScope(scope, workspace.executionRoot))) {
192
+ throw new TypeError("Write reservation scopes must be within the execution root.");
193
+ }
194
+ const parentSessionId = requireBoundedTrimmedText(request.parentSessionId, MAX_IDENTIFIER_CHARS, "Parent session id");
195
+ const ownerId = localOwnerId(request.ownerId);
196
+ const taskId = requireBoundedTrimmedText(request.taskId, MAX_IDENTIFIER_CHARS, "Task id");
197
+ const attemptId = requireBoundedTrimmedText(request.attemptId, MAX_IDENTIFIER_CHARS, "Attempt id");
198
+ const fencingToken = positiveFencingToken(request.fencingToken);
199
+ const filePath = reservationFile(this.agentDir, workspace.repositoryRoot);
200
+ return withFileLockSync(filePath, () => {
201
+ const store = this.readLocked(filePath, workspace.repositoryRoot);
202
+ const matchingAttempt = store.reservations.find((reservation) => reservation.parentSessionId === parentSessionId &&
203
+ reservation.ownerId === ownerId &&
204
+ reservation.taskId === taskId &&
205
+ reservation.attemptId === attemptId &&
206
+ reservation.fencingToken === fencingToken);
207
+ if (matchingAttempt) {
208
+ if (matchingAttempt.executionIdentity !== workspace.executionIdentity ||
209
+ matchingAttempt.isolatedWorktreeId !== workspace.isolatedWorktreeId ||
210
+ matchingAttempt.writeScopes.length !== writeScopes.length ||
211
+ matchingAttempt.writeScopes.some((scope, index) => scope !== writeScopes[index])) {
212
+ return { kind: "blocked", reasonCode: "attempt_reservation_conflict" };
213
+ }
214
+ return { kind: "granted", lease: leaseFromRecord(filePath, matchingAttempt) };
215
+ }
216
+ const conflicts = overlappingReservationIds(store.reservations, workspace.executionIdentity, writeScopes);
217
+ if (conflicts.length > 0) {
218
+ return { kind: "blocked", reasonCode: "overlapping_write_scope", conflictingReservationIds: conflicts };
219
+ }
220
+ if (store.reservations.length >= MAX_RESERVATIONS)
221
+ return { kind: "blocked", reasonCode: "reservation_capacity_reached" };
222
+ const record = {
223
+ reservationId: randomUUID(),
224
+ parentSessionId,
225
+ ownerId,
226
+ taskId,
227
+ attemptId,
228
+ fencingToken,
229
+ repositoryRoot: workspace.repositoryRoot,
230
+ executionRoot: workspace.executionRoot,
231
+ executionIdentity: workspace.executionIdentity,
232
+ ...(workspace.isolatedWorktreeId ? { isolatedWorktreeId: workspace.isolatedWorktreeId } : {}),
233
+ writeScopes,
234
+ createdAt: new Date().toISOString(),
235
+ };
236
+ store.reservations.push(record);
237
+ writeStore(filePath, store);
238
+ return { kind: "granted", lease: leaseFromRecord(filePath, record) };
239
+ });
240
+ }
241
+ release(lease) {
242
+ const repositoryRoot = requireBoundedTrimmedText(lease.repositoryRoot, MAX_PATH_CHARS, "Lease repository root");
243
+ const ownerId = localOwnerId(lease.ownerId);
244
+ const expectedFilePath = reservationFile(this.agentDir, repositoryRoot);
245
+ if (lease.filePath !== expectedFilePath)
246
+ throw new TypeError("Worker write reservation lease does not belong to this agent state.");
247
+ return withFileLockSync(expectedFilePath, () => {
248
+ const store = this.readLocked(expectedFilePath, repositoryRoot);
249
+ const index = store.reservations.findIndex((reservation) => reservation.reservationId === lease.reservationId);
250
+ if (index < 0) {
251
+ const supersedingReservation = store.reservations.some((reservation) => reservation.parentSessionId === lease.parentSessionId &&
252
+ reservation.ownerId === ownerId &&
253
+ reservation.taskId === lease.taskId &&
254
+ reservation.fencingToken > lease.fencingToken);
255
+ return { kind: supersedingReservation ? "stale_fence" : "not_found" };
256
+ }
257
+ const record = store.reservations[index];
258
+ if (record.parentSessionId !== lease.parentSessionId ||
259
+ record.ownerId !== ownerId ||
260
+ record.taskId !== lease.taskId ||
261
+ record.attemptId !== lease.attemptId ||
262
+ record.fencingToken !== lease.fencingToken ||
263
+ record.executionIdentity !== lease.executionIdentity ||
264
+ record.isolatedWorktreeId !== lease.isolatedWorktreeId) {
265
+ return { kind: "stale_fence" };
266
+ }
267
+ store.reservations.splice(index, 1);
268
+ if (store.reservations.length === 0)
269
+ unlinkSync(expectedFilePath);
270
+ else
271
+ writeStore(expectedFilePath, store);
272
+ notifyAvailability(expectedFilePath);
273
+ return { kind: "released" };
274
+ });
275
+ }
276
+ /** Event-driven cross-process wakeup for queued write admission; caller owns disposal. */
277
+ watchAvailability(workspace, listener) {
278
+ const canonical = canonicalWorkspace(workspace);
279
+ const filePath = reservationFile(this.agentDir, canonical.repositoryRoot);
280
+ const listeners = availabilityListeners.get(filePath) ?? new Set();
281
+ availabilityListeners.set(filePath, listeners);
282
+ listeners.add(listener);
283
+ const directory = dirname(filePath);
284
+ mkdirSync(directory, { recursive: true });
285
+ let scheduled = false;
286
+ const schedule = () => {
287
+ if (scheduled)
288
+ return;
289
+ scheduled = true;
290
+ queueMicrotask(() => {
291
+ scheduled = false;
292
+ listener();
293
+ });
294
+ };
295
+ const watcher = this.watchDirectory(directory, { persistent: false }, (_eventType, fileName) => {
296
+ // Node may omit a filename (notably on Windows), or provide a Buffer when the watcher is
297
+ // configured that way. An unknown filename is conservatively treated as a wake signal: the
298
+ // scheduler re-evaluates durable admission, so this cannot grant access by itself.
299
+ if (fileName === null) {
300
+ schedule();
301
+ return;
302
+ }
303
+ const normalizedName = Buffer.isBuffer(fileName) ? fileName.toString("utf-8") : fileName;
304
+ if (normalizedName === basename(filePath))
305
+ schedule();
306
+ });
307
+ return () => {
308
+ listeners.delete(listener);
309
+ if (listeners.size === 0)
310
+ availabilityListeners.delete(filePath);
311
+ watcher.close();
312
+ };
313
+ }
314
+ recover(request) {
315
+ const workspace = canonicalWorkspace(request.workspace);
316
+ const filePath = reservationFile(this.agentDir, workspace.repositoryRoot);
317
+ const evidence = new Map();
318
+ for (const observation of request.evidence) {
319
+ const reservationId = requireBoundedTrimmedText(observation.reservationId, MAX_IDENTIFIER_CHARS, "Reservation evidence id");
320
+ if (observation.state !== "live" && observation.state !== "not_live" && observation.state !== "unknown") {
321
+ throw new TypeError("Reservation evidence state must be live, not_live, or unknown.");
322
+ }
323
+ if (evidence.has(reservationId))
324
+ throw new TypeError("Reservation evidence must not repeat an identity.");
325
+ evidence.set(reservationId, observation.state);
326
+ }
327
+ return withFileLockSync(filePath, () => {
328
+ const store = this.readLocked(filePath, workspace.repositoryRoot);
329
+ const outcomes = store.reservations
330
+ .filter((reservation) => reservation.executionIdentity === workspace.executionIdentity)
331
+ .map((reservation) => {
332
+ const state = evidence.get(reservation.reservationId);
333
+ return {
334
+ kind: state === "live" ? "active" : state === "not_live" ? "stale" : "inspection_required",
335
+ reservationId: reservation.reservationId,
336
+ lease: leaseFromRecord(filePath, reservation),
337
+ };
338
+ });
339
+ return { outcomes };
340
+ });
341
+ }
342
+ readLocked(filePath, repositoryRoot) {
343
+ if (!existsSync(filePath))
344
+ return { schemaVersion: SCHEMA_VERSION, repositoryRoot, reservations: [] };
345
+ return parseStore(readBoundedTextFileSync(filePath, MAX_FILE_BYTES, "Worker write reservation store"), repositoryRoot);
346
+ }
347
+ }
348
+ //# sourceMappingURL=worker-write-reservation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-write-reservation.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-write-reservation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAkB,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EACN,0BAA0B,EAC1B,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAE3E,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,oBAAoB,GAAG,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AW,CAAC,iBAAiB,KAAK,SAAS,CAAC,iBAAiB,CAAC;iBACtF,GAAG,CAAC,CAAC,WAAW,EAAyC,EAAE,CAAC;gBAC5D,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;gBACtD,OAAO;oBACN,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,qBAAqB;oBAC1F,aAAa,EAAE,WAAW,CAAC,aAAa;oBACxC,KAAK,EAAE,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC;iBAC7C,CAAC;YAAA,CACF,CAAC,CAAC;YACJ,OAAO,EAAE,QAAQ,EAAE,CAAC;QAAA,CACpB,CAAC,CAAC;IAAA,CACH;IAEO,UAAU,CAAC,QAAgB,EAAE,cAAsB,EAA6B;QACvF,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;QACtG,OAAO,UAAU,CAChB,uBAAuB,CAAC,QAAQ,EAAE,cAAc,EAAE,gCAAgC,CAAC,EACnF,cAAc,CACd,CAAC;IAAA,CACF;CACD","sourcesContent":["import { createHash, randomUUID } from \"node:crypto\";\nimport { existsSync, type FSWatcher, mkdirSync, unlinkSync, watch } from \"node:fs\";\nimport { basename, dirname } from \"node:path\";\nimport { stateFile } from \"../agent-paths.ts\";\nimport {\n\tcanonicalPathScopeIdentity,\n\tisPathWithinScope,\n\tpathScopesOverlap,\n\tsafeRealpathSync,\n} from \"../autonomy/path-scope.ts\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\nimport { readBoundedTextFileSync } from \"../util/bounded-file.ts\";\nimport { requireBoundedTrimmedText } from \"../util/bounded-value.ts\";\nimport { parseLocalWorkerProcessOwnerId } from \"./worker-process-owner.ts\";\n\nconst SCHEMA_VERSION = 1;\nconst MAX_IDENTIFIER_CHARS = 256;\nconst MAX_PATH_CHARS = 4096;\nconst MAX_SCOPES = 32;\nconst MAX_RESERVATIONS = 64;\nconst MAX_FILE_BYTES = 128 * 1024;\nconst availabilityListeners = new Map<string, Set<() => void>>();\n\ntype WatchDirectory = (\n\tdirectory: string,\n\toptions: { persistent: boolean },\n\tlistener: (eventType: string, fileName: string | Buffer | null) => void,\n) => FSWatcher;\n\nexport interface WorkerWriteReservationWorkspace {\n\t/** Canonical repository/workspace root shared by primary and isolated worktrees. */\n\trepositoryRoot: string;\n\t/** Actual checkout used by this attempt. A non-primary checkout requires an isolation identity. */\n\texecutionRoot: string;\n\t/** Durable worktree identity supplied by the worktree owner, never a model-provided label. */\n\tisolatedWorktreeId?: string;\n}\n\nexport interface WorkerWriteReservationRequest {\n\tparentSessionId: string;\n\t/** Exact pi-owned process instance that acquired this reservation. */\n\townerId: string;\n\ttaskId: string;\n\tattemptId: string;\n\tfencingToken: number;\n\taccess: \"read\" | \"write\";\n\tworkspace: WorkerWriteReservationWorkspace;\n\t/** Absolute authorized write roots. They are resolved before persistence. */\n\twriteScopes: readonly string[];\n}\n\nexport interface WorkerWriteReservationLease {\n\tfilePath: string;\n\treservationId: string;\n\tparentSessionId: string;\n\townerId: string;\n\ttaskId: string;\n\tattemptId: string;\n\tfencingToken: number;\n\trepositoryRoot: string;\n\texecutionRoot: string;\n\texecutionIdentity: string;\n\tisolatedWorktreeId?: string;\n\twriteScopes: readonly string[];\n}\n\nexport type WorkerWriteReservationAcquireResult =\n\t| { kind: \"granted\"; lease?: WorkerWriteReservationLease }\n\t| {\n\t\t\tkind: \"blocked\";\n\t\t\treasonCode: \"overlapping_write_scope\" | \"attempt_reservation_conflict\" | \"reservation_capacity_reached\";\n\t\t\tconflictingReservationIds?: readonly string[];\n\t };\n\nexport type WorkerWriteReservationReleaseResult =\n\t| { kind: \"released\" }\n\t| { kind: \"stale_fence\" }\n\t| { kind: \"not_found\" };\n\nexport type WorkerWriteReservationEvidenceState = \"live\" | \"not_live\" | \"unknown\";\n\nexport interface WorkerWriteReservationRecoveryEvidence {\n\treservationId: string;\n\tstate: WorkerWriteReservationEvidenceState;\n}\n\nexport interface WorkerWriteReservationRecoveryRequest {\n\tworkspace: WorkerWriteReservationWorkspace;\n\t/** Caller-owned lease observations. This store never polls process state or worker output. */\n\tevidence: readonly WorkerWriteReservationRecoveryEvidence[];\n}\n\nexport interface WorkerWriteReservationRecoveryOutcome {\n\tkind: \"active\" | \"stale\" | \"inspection_required\";\n\treservationId: string;\n\tlease: WorkerWriteReservationLease;\n}\n\ninterface PersistedReservation {\n\treservationId: string;\n\tparentSessionId: string;\n\townerId: string;\n\ttaskId: string;\n\tattemptId: string;\n\tfencingToken: number;\n\trepositoryRoot: string;\n\texecutionRoot: string;\n\texecutionIdentity: string;\n\tisolatedWorktreeId?: string;\n\twriteScopes: string[];\n\tcreatedAt: string;\n}\n\ninterface PersistedReservationStore {\n\tschemaVersion: number;\n\trepositoryRoot: string;\n\treservations: PersistedReservation[];\n}\n\ninterface CanonicalWorkspace {\n\trepositoryRoot: string;\n\texecutionRoot: string;\n\texecutionIdentity: string;\n\tisolatedWorktreeId?: string;\n}\n\nfunction positiveFencingToken(value: number): number {\n\tif (!Number.isSafeInteger(value) || value < 1) throw new TypeError(\"Fencing token must be a positive safe integer.\");\n\treturn value;\n}\n\n/**\n * Prefer a real path for filesystem-backed scopes, but preserve a foreign lexical path family\n * (for example a Windows drive path inspected from WSL) so shared path-scope helpers retain\n * their documented Windows drive/UNC comparison semantics.\n */\nfunction canonicalRealOrLexicalPath(value: string, label: string): string {\n\tconst lexical = canonicalPathScopeIdentity(requireBoundedTrimmedText(value, MAX_PATH_CHARS, label));\n\tconst resolved = safeRealpathSync(lexical);\n\treturn pathScopesOverlap(lexical, resolved) ? canonicalPathScopeIdentity(resolved) : lexical;\n}\n\nfunction canonicalWorkspace(workspace: WorkerWriteReservationWorkspace): CanonicalWorkspace {\n\tconst repositoryRoot = canonicalRealOrLexicalPath(workspace.repositoryRoot, \"Repository root\");\n\tconst executionRoot = canonicalRealOrLexicalPath(workspace.executionRoot, \"Execution root\");\n\tconst isolatedWorktreeId = workspace.isolatedWorktreeId\n\t\t? requireBoundedTrimmedText(workspace.isolatedWorktreeId, MAX_IDENTIFIER_CHARS, \"Isolated worktree id\")\n\t\t: undefined;\n\tconst isPrimaryExecutionRoot =\n\t\tisPathWithinScope(executionRoot, repositoryRoot) && isPathWithinScope(repositoryRoot, executionRoot);\n\tif (isPrimaryExecutionRoot && isolatedWorktreeId) {\n\t\tthrow new TypeError(\"An isolated worktree execution root must differ from the shared repository root.\");\n\t}\n\tif (!isPrimaryExecutionRoot && !isolatedWorktreeId) {\n\t\tthrow new TypeError(\"A non-primary execution root requires an explicit isolated worktree identity.\");\n\t}\n\treturn {\n\t\trepositoryRoot,\n\t\texecutionRoot,\n\t\texecutionIdentity: isolatedWorktreeId ? `isolated:${executionRoot}` : `shared:${repositoryRoot}`,\n\t\t...(isolatedWorktreeId ? { isolatedWorktreeId } : {}),\n\t};\n}\n\nfunction reservationFile(agentDir: string, repositoryRoot: string): string {\n\tconst digest = createHash(\"sha256\")\n\t\t.update(\"pi-worker-write-reservations-v1\")\n\t\t.update(\"\\0\")\n\t\t.update(repositoryRoot)\n\t\t.digest(\"hex\");\n\treturn stateFile(agentDir, \"orchestration\", \"worker-write-reservations\", `${digest}.json`);\n}\n\nfunction notifyAvailability(filePath: string): void {\n\tfor (const listener of availabilityListeners.get(filePath) ?? []) queueMicrotask(listener);\n}\n\nfunction leaseFromRecord(filePath: string, record: PersistedReservation): WorkerWriteReservationLease {\n\treturn {\n\t\tfilePath,\n\t\treservationId: record.reservationId,\n\t\tparentSessionId: record.parentSessionId,\n\t\townerId: record.ownerId,\n\t\ttaskId: record.taskId,\n\t\tattemptId: record.attemptId,\n\t\tfencingToken: record.fencingToken,\n\t\trepositoryRoot: record.repositoryRoot,\n\t\texecutionRoot: record.executionRoot,\n\t\texecutionIdentity: record.executionIdentity,\n\t\t...(record.isolatedWorktreeId ? { isolatedWorktreeId: record.isolatedWorktreeId } : {}),\n\t\twriteScopes: [...record.writeScopes],\n\t};\n}\n\nfunction stringField(value: unknown, label: string, maximum: number): string {\n\tif (typeof value !== \"string\") throw new Error(`Worker write reservation ${label} is invalid.`);\n\treturn requireBoundedTrimmedText(value, maximum, `Worker write reservation ${label}`);\n}\n\nfunction localOwnerId(value: unknown): string {\n\tconst ownerId = stringField(value, \"owner id\", MAX_IDENTIFIER_CHARS);\n\tif (!parseLocalWorkerProcessOwnerId(ownerId)) throw new Error(\"Worker write reservation owner id is invalid.\");\n\treturn ownerId;\n}\n\nfunction parseReservation(value: unknown, repositoryRoot: string): PersistedReservation {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new Error(\"Worker write reservation entry is invalid.\");\n\tconst entry = value as Record<string, unknown>;\n\tconst fencingToken = entry.fencingToken;\n\tif (typeof fencingToken !== \"number\") throw new Error(\"Worker write reservation fencing token is invalid.\");\n\tconst parsedRepositoryRoot = stringField(entry.repositoryRoot, \"repository root\", MAX_PATH_CHARS);\n\tif (parsedRepositoryRoot !== repositoryRoot)\n\t\tthrow new Error(\"Worker write reservation repository root conflicts with its store.\");\n\tif (!Array.isArray(entry.writeScopes) || entry.writeScopes.length === 0 || entry.writeScopes.length > MAX_SCOPES) {\n\t\tthrow new Error(\"Worker write reservation scopes are invalid.\");\n\t}\n\tconst writeScopes = entry.writeScopes.map((scope) => stringField(scope, \"write scope\", MAX_PATH_CHARS));\n\tconst isolatedWorktreeId =\n\t\tentry.isolatedWorktreeId === undefined\n\t\t\t? undefined\n\t\t\t: stringField(entry.isolatedWorktreeId, \"isolated worktree id\", MAX_IDENTIFIER_CHARS);\n\treturn {\n\t\treservationId: stringField(entry.reservationId, \"id\", MAX_IDENTIFIER_CHARS),\n\t\tparentSessionId: stringField(entry.parentSessionId, \"parent session\", MAX_IDENTIFIER_CHARS),\n\t\townerId: localOwnerId(entry.ownerId),\n\t\ttaskId: stringField(entry.taskId, \"task\", MAX_IDENTIFIER_CHARS),\n\t\tattemptId: stringField(entry.attemptId, \"attempt\", MAX_IDENTIFIER_CHARS),\n\t\tfencingToken: positiveFencingToken(fencingToken),\n\t\trepositoryRoot: parsedRepositoryRoot,\n\t\texecutionRoot: stringField(entry.executionRoot, \"execution root\", MAX_PATH_CHARS),\n\t\texecutionIdentity: stringField(entry.executionIdentity, \"execution identity\", MAX_PATH_CHARS),\n\t\t...(isolatedWorktreeId ? { isolatedWorktreeId } : {}),\n\t\twriteScopes,\n\t\tcreatedAt: stringField(entry.createdAt, \"created time\", MAX_IDENTIFIER_CHARS),\n\t};\n}\n\nfunction parseStore(raw: string, repositoryRoot: string): PersistedReservationStore {\n\tif (Buffer.byteLength(raw, \"utf-8\") > MAX_FILE_BYTES)\n\t\tthrow new Error(\"Worker write reservation store exceeds its byte limit.\");\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(raw);\n\t} catch {\n\t\tthrow new Error(\"Worker write reservation store is unreadable; refusing concurrent write admission.\");\n\t}\n\tif (!value || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new Error(\"Worker write reservation store is invalid.\");\n\tconst store = value as Record<string, unknown>;\n\tif (store.schemaVersion !== SCHEMA_VERSION) throw new Error(\"Worker write reservation store schema is unsupported.\");\n\tif (stringField(store.repositoryRoot, \"store repository root\", MAX_PATH_CHARS) !== repositoryRoot) {\n\t\tthrow new Error(\"Worker write reservation store root conflicts with the requested workspace.\");\n\t}\n\tif (!Array.isArray(store.reservations) || store.reservations.length > MAX_RESERVATIONS) {\n\t\tthrow new Error(\"Worker write reservation store entries are invalid.\");\n\t}\n\tconst reservations = store.reservations.map((entry) => parseReservation(entry, repositoryRoot));\n\tif (new Set(reservations.map((entry) => entry.reservationId)).size !== reservations.length) {\n\t\tthrow new Error(\"Worker write reservation store contains duplicate reservation identities.\");\n\t}\n\treturn { schemaVersion: SCHEMA_VERSION, repositoryRoot, reservations };\n}\n\nfunction writeStore(filePath: string, store: PersistedReservationStore): void {\n\tconst serialized = `${JSON.stringify(store)}\\n`;\n\tif (Buffer.byteLength(serialized, \"utf-8\") > MAX_FILE_BYTES) {\n\t\tthrow new Error(\"Worker write reservation store would exceed its byte limit.\");\n\t}\n\twriteFileAtomicSync(filePath, serialized, { mode: 0o600 });\n}\n\nfunction overlappingReservationIds(\n\treservations: readonly PersistedReservation[],\n\texecutionIdentity: string,\n\twriteScopes: readonly string[],\n): string[] {\n\tconst matches: string[] = [];\n\tfor (const reservation of reservations) {\n\t\tif (reservation.executionIdentity !== executionIdentity) continue;\n\t\tif (\n\t\t\treservation.writeScopes.some((reservedScope) =>\n\t\t\t\twriteScopes.some((requestedScope) => pathScopesOverlap(reservedScope, requestedScope)),\n\t\t\t)\n\t\t) {\n\t\t\tmatches.push(reservation.reservationId);\n\t\t}\n\t}\n\treturn matches;\n}\n\n/**\n * Cross-process, agent-owned admission seam for concurrent worker mutations. It owns only\n * reservations; lifecycle, process liveness, and terminal status remain controller concerns.\n */\nexport class WorkerWriteReservationStore {\n\tprivate readonly agentDir: string;\n\tprivate readonly watchDirectory: WatchDirectory;\n\n\tconstructor(options: { agentDir: string; watchDirectory?: WatchDirectory }) {\n\t\tthis.agentDir = requireBoundedTrimmedText(options.agentDir, MAX_PATH_CHARS, \"Agent directory\");\n\t\tthis.watchDirectory = options.watchDirectory ?? watch;\n\t}\n\n\tacquire(request: WorkerWriteReservationRequest): WorkerWriteReservationAcquireResult {\n\t\tif (request.access === \"read\") return { kind: \"granted\" };\n\t\tif (request.access !== \"write\") throw new TypeError(\"Worker write reservation access must be read or write.\");\n\t\tif (request.writeScopes.length === 0 || request.writeScopes.length > MAX_SCOPES) {\n\t\t\tthrow new TypeError(`Write reservations require from 1 through ${MAX_SCOPES} write scopes.`);\n\t\t}\n\t\tconst workspace = canonicalWorkspace(request.workspace);\n\t\tconst writeScopes = [\n\t\t\t...new Set(request.writeScopes.map((scope) => canonicalRealOrLexicalPath(scope, \"Write scope\"))),\n\t\t].sort();\n\t\tif (writeScopes.some((scope) => !isPathWithinScope(scope, workspace.executionRoot))) {\n\t\t\tthrow new TypeError(\"Write reservation scopes must be within the execution root.\");\n\t\t}\n\t\tconst parentSessionId = requireBoundedTrimmedText(\n\t\t\trequest.parentSessionId,\n\t\t\tMAX_IDENTIFIER_CHARS,\n\t\t\t\"Parent session id\",\n\t\t);\n\t\tconst ownerId = localOwnerId(request.ownerId);\n\t\tconst taskId = requireBoundedTrimmedText(request.taskId, MAX_IDENTIFIER_CHARS, \"Task id\");\n\t\tconst attemptId = requireBoundedTrimmedText(request.attemptId, MAX_IDENTIFIER_CHARS, \"Attempt id\");\n\t\tconst fencingToken = positiveFencingToken(request.fencingToken);\n\t\tconst filePath = reservationFile(this.agentDir, workspace.repositoryRoot);\n\n\t\treturn withFileLockSync(filePath, () => {\n\t\t\tconst store = this.readLocked(filePath, workspace.repositoryRoot);\n\t\t\tconst matchingAttempt = store.reservations.find(\n\t\t\t\t(reservation) =>\n\t\t\t\t\treservation.parentSessionId === parentSessionId &&\n\t\t\t\t\treservation.ownerId === ownerId &&\n\t\t\t\t\treservation.taskId === taskId &&\n\t\t\t\t\treservation.attemptId === attemptId &&\n\t\t\t\t\treservation.fencingToken === fencingToken,\n\t\t\t);\n\t\t\tif (matchingAttempt) {\n\t\t\t\tif (\n\t\t\t\t\tmatchingAttempt.executionIdentity !== workspace.executionIdentity ||\n\t\t\t\t\tmatchingAttempt.isolatedWorktreeId !== workspace.isolatedWorktreeId ||\n\t\t\t\t\tmatchingAttempt.writeScopes.length !== writeScopes.length ||\n\t\t\t\t\tmatchingAttempt.writeScopes.some((scope, index) => scope !== writeScopes[index])\n\t\t\t\t) {\n\t\t\t\t\treturn { kind: \"blocked\", reasonCode: \"attempt_reservation_conflict\" };\n\t\t\t\t}\n\t\t\t\treturn { kind: \"granted\", lease: leaseFromRecord(filePath, matchingAttempt) };\n\t\t\t}\n\t\t\tconst conflicts = overlappingReservationIds(store.reservations, workspace.executionIdentity, writeScopes);\n\t\t\tif (conflicts.length > 0) {\n\t\t\t\treturn { kind: \"blocked\", reasonCode: \"overlapping_write_scope\", conflictingReservationIds: conflicts };\n\t\t\t}\n\t\t\tif (store.reservations.length >= MAX_RESERVATIONS)\n\t\t\t\treturn { kind: \"blocked\", reasonCode: \"reservation_capacity_reached\" };\n\t\t\tconst record: PersistedReservation = {\n\t\t\t\treservationId: randomUUID(),\n\t\t\t\tparentSessionId,\n\t\t\t\townerId,\n\t\t\t\ttaskId,\n\t\t\t\tattemptId,\n\t\t\t\tfencingToken,\n\t\t\t\trepositoryRoot: workspace.repositoryRoot,\n\t\t\t\texecutionRoot: workspace.executionRoot,\n\t\t\t\texecutionIdentity: workspace.executionIdentity,\n\t\t\t\t...(workspace.isolatedWorktreeId ? { isolatedWorktreeId: workspace.isolatedWorktreeId } : {}),\n\t\t\t\twriteScopes,\n\t\t\t\tcreatedAt: new Date().toISOString(),\n\t\t\t};\n\t\t\tstore.reservations.push(record);\n\t\t\twriteStore(filePath, store);\n\t\t\treturn { kind: \"granted\", lease: leaseFromRecord(filePath, record) };\n\t\t});\n\t}\n\n\trelease(lease: WorkerWriteReservationLease): WorkerWriteReservationReleaseResult {\n\t\tconst repositoryRoot = requireBoundedTrimmedText(lease.repositoryRoot, MAX_PATH_CHARS, \"Lease repository root\");\n\t\tconst ownerId = localOwnerId(lease.ownerId);\n\t\tconst expectedFilePath = reservationFile(this.agentDir, repositoryRoot);\n\t\tif (lease.filePath !== expectedFilePath)\n\t\t\tthrow new TypeError(\"Worker write reservation lease does not belong to this agent state.\");\n\t\treturn withFileLockSync(expectedFilePath, () => {\n\t\t\tconst store = this.readLocked(expectedFilePath, repositoryRoot);\n\t\t\tconst index = store.reservations.findIndex((reservation) => reservation.reservationId === lease.reservationId);\n\t\t\tif (index < 0) {\n\t\t\t\tconst supersedingReservation = store.reservations.some(\n\t\t\t\t\t(reservation) =>\n\t\t\t\t\t\treservation.parentSessionId === lease.parentSessionId &&\n\t\t\t\t\t\treservation.ownerId === ownerId &&\n\t\t\t\t\t\treservation.taskId === lease.taskId &&\n\t\t\t\t\t\treservation.fencingToken > lease.fencingToken,\n\t\t\t\t);\n\t\t\t\treturn { kind: supersedingReservation ? \"stale_fence\" : \"not_found\" };\n\t\t\t}\n\t\t\tconst record = store.reservations[index];\n\t\t\tif (\n\t\t\t\trecord.parentSessionId !== lease.parentSessionId ||\n\t\t\t\trecord.ownerId !== ownerId ||\n\t\t\t\trecord.taskId !== lease.taskId ||\n\t\t\t\trecord.attemptId !== lease.attemptId ||\n\t\t\t\trecord.fencingToken !== lease.fencingToken ||\n\t\t\t\trecord.executionIdentity !== lease.executionIdentity ||\n\t\t\t\trecord.isolatedWorktreeId !== lease.isolatedWorktreeId\n\t\t\t) {\n\t\t\t\treturn { kind: \"stale_fence\" };\n\t\t\t}\n\t\t\tstore.reservations.splice(index, 1);\n\t\t\tif (store.reservations.length === 0) unlinkSync(expectedFilePath);\n\t\t\telse writeStore(expectedFilePath, store);\n\t\t\tnotifyAvailability(expectedFilePath);\n\t\t\treturn { kind: \"released\" };\n\t\t});\n\t}\n\n\t/** Event-driven cross-process wakeup for queued write admission; caller owns disposal. */\n\twatchAvailability(workspace: WorkerWriteReservationWorkspace, listener: () => void): () => void {\n\t\tconst canonical = canonicalWorkspace(workspace);\n\t\tconst filePath = reservationFile(this.agentDir, canonical.repositoryRoot);\n\t\tconst listeners = availabilityListeners.get(filePath) ?? new Set<() => void>();\n\t\tavailabilityListeners.set(filePath, listeners);\n\t\tlisteners.add(listener);\n\t\tconst directory = dirname(filePath);\n\t\tmkdirSync(directory, { recursive: true });\n\t\tlet scheduled = false;\n\t\tconst schedule = () => {\n\t\t\tif (scheduled) return;\n\t\t\tscheduled = true;\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tscheduled = false;\n\t\t\t\tlistener();\n\t\t\t});\n\t\t};\n\t\tconst watcher = this.watchDirectory(directory, { persistent: false }, (_eventType, fileName) => {\n\t\t\t// Node may omit a filename (notably on Windows), or provide a Buffer when the watcher is\n\t\t\t// configured that way. An unknown filename is conservatively treated as a wake signal: the\n\t\t\t// scheduler re-evaluates durable admission, so this cannot grant access by itself.\n\t\t\tif (fileName === null) {\n\t\t\t\tschedule();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst normalizedName = Buffer.isBuffer(fileName) ? fileName.toString(\"utf-8\") : fileName;\n\t\t\tif (normalizedName === basename(filePath)) schedule();\n\t\t});\n\t\treturn () => {\n\t\t\tlisteners.delete(listener);\n\t\t\tif (listeners.size === 0) availabilityListeners.delete(filePath);\n\t\t\twatcher.close();\n\t\t};\n\t}\n\n\trecover(request: WorkerWriteReservationRecoveryRequest): { outcomes: WorkerWriteReservationRecoveryOutcome[] } {\n\t\tconst workspace = canonicalWorkspace(request.workspace);\n\t\tconst filePath = reservationFile(this.agentDir, workspace.repositoryRoot);\n\t\tconst evidence = new Map<string, WorkerWriteReservationEvidenceState>();\n\t\tfor (const observation of request.evidence) {\n\t\t\tconst reservationId = requireBoundedTrimmedText(\n\t\t\t\tobservation.reservationId,\n\t\t\t\tMAX_IDENTIFIER_CHARS,\n\t\t\t\t\"Reservation evidence id\",\n\t\t\t);\n\t\t\tif (observation.state !== \"live\" && observation.state !== \"not_live\" && observation.state !== \"unknown\") {\n\t\t\t\tthrow new TypeError(\"Reservation evidence state must be live, not_live, or unknown.\");\n\t\t\t}\n\t\t\tif (evidence.has(reservationId)) throw new TypeError(\"Reservation evidence must not repeat an identity.\");\n\t\t\tevidence.set(reservationId, observation.state);\n\t\t}\n\t\treturn withFileLockSync(filePath, () => {\n\t\t\tconst store = this.readLocked(filePath, workspace.repositoryRoot);\n\t\t\tconst outcomes = store.reservations\n\t\t\t\t.filter((reservation) => reservation.executionIdentity === workspace.executionIdentity)\n\t\t\t\t.map((reservation): WorkerWriteReservationRecoveryOutcome => {\n\t\t\t\t\tconst state = evidence.get(reservation.reservationId);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tkind: state === \"live\" ? \"active\" : state === \"not_live\" ? \"stale\" : \"inspection_required\",\n\t\t\t\t\t\treservationId: reservation.reservationId,\n\t\t\t\t\t\tlease: leaseFromRecord(filePath, reservation),\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\treturn { outcomes };\n\t\t});\n\t}\n\n\tprivate readLocked(filePath: string, repositoryRoot: string): PersistedReservationStore {\n\t\tif (!existsSync(filePath)) return { schemaVersion: SCHEMA_VERSION, repositoryRoot, reservations: [] };\n\t\treturn parseStore(\n\t\t\treadBoundedTextFileSync(filePath, MAX_FILE_BYTES, \"Worker write reservation store\"),\n\t\t\trepositoryRoot,\n\t\t);\n\t}\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { SettingsManager } from "./settings-manager.ts";
2
+ export type ExtensionImportAuthority = "explicit" | "profile";
3
+ export declare function hasProfileExtensionImportAuthority(settingsManager: SettingsManager): boolean;
4
+ /** Single import-boundary policy shared by startup discovery, reconciliation, and live loading. */
5
+ export declare function isExtensionPathAllowedForImport(settingsManager: SettingsManager, extensionPath: string, authority: ExtensionImportAuthority, baseDir?: string): boolean;
6
+ //# sourceMappingURL=extension-import-authority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-import-authority.d.ts","sourceRoot":"","sources":["../../src/core/extension-import-authority.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,MAAM,wBAAwB,GAAG,UAAU,GAAG,SAAS,CAAC;AAE9D,wBAAgB,kCAAkC,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAE5F;AAED,mGAAmG;AACnG,wBAAgB,+BAA+B,CAC9C,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,wBAAwB,EACnC,OAAO,SAAK,GACV,OAAO,CAGT","sourcesContent":["import type { SettingsManager } from \"./settings-manager.ts\";\n\nexport type ExtensionImportAuthority = \"explicit\" | \"profile\";\n\nexport function hasProfileExtensionImportAuthority(settingsManager: SettingsManager): boolean {\n\treturn settingsManager.getActiveResourceProfileNames().length > 0;\n}\n\n/** Single import-boundary policy shared by startup discovery, reconciliation, and live loading. */\nexport function isExtensionPathAllowedForImport(\n\tsettingsManager: SettingsManager,\n\textensionPath: string,\n\tauthority: ExtensionImportAuthority,\n\tbaseDir = \"\",\n): boolean {\n\tif (authority === \"profile\" && !hasProfileExtensionImportAuthority(settingsManager)) return false;\n\treturn settingsManager.isResourceAllowedByProfile(\"extensions\", extensionPath, baseDir);\n}\n"]}
@@ -0,0 +1,10 @@
1
+ export function hasProfileExtensionImportAuthority(settingsManager) {
2
+ return settingsManager.getActiveResourceProfileNames().length > 0;
3
+ }
4
+ /** Single import-boundary policy shared by startup discovery, reconciliation, and live loading. */
5
+ export function isExtensionPathAllowedForImport(settingsManager, extensionPath, authority, baseDir = "") {
6
+ if (authority === "profile" && !hasProfileExtensionImportAuthority(settingsManager))
7
+ return false;
8
+ return settingsManager.isResourceAllowedByProfile("extensions", extensionPath, baseDir);
9
+ }
10
+ //# sourceMappingURL=extension-import-authority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-import-authority.js","sourceRoot":"","sources":["../../src/core/extension-import-authority.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,kCAAkC,CAAC,eAAgC,EAAW;IAC7F,OAAO,eAAe,CAAC,6BAA6B,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAAA,CAClE;AAED,mGAAmG;AACnG,MAAM,UAAU,+BAA+B,CAC9C,eAAgC,EAChC,aAAqB,EACrB,SAAmC,EACnC,OAAO,GAAG,EAAE,EACF;IACV,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,kCAAkC,CAAC,eAAe,CAAC;QAAE,OAAO,KAAK,CAAC;IAClG,OAAO,eAAe,CAAC,0BAA0B,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;AAAA,CACxF","sourcesContent":["import type { SettingsManager } from \"./settings-manager.ts\";\n\nexport type ExtensionImportAuthority = \"explicit\" | \"profile\";\n\nexport function hasProfileExtensionImportAuthority(settingsManager: SettingsManager): boolean {\n\treturn settingsManager.getActiveResourceProfileNames().length > 0;\n}\n\n/** Single import-boundary policy shared by startup discovery, reconciliation, and live loading. */\nexport function isExtensionPathAllowedForImport(\n\tsettingsManager: SettingsManager,\n\textensionPath: string,\n\tauthority: ExtensionImportAuthority,\n\tbaseDir = \"\",\n): boolean {\n\tif (authority === \"profile\" && !hasProfileExtensionImportAuthority(settingsManager)) return false;\n\treturn settingsManager.isResourceAllowedByProfile(\"extensions\", extensionPath, baseDir);\n}\n"]}