@caupulican/pi-adaptative 0.81.39 → 0.81.40

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 (667) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +2 -0
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +2 -0
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +2 -0
  6. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +3 -0
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +9 -0
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +290 -107
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  12. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +357 -122
  13. package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +2 -2
  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 +9 -0
  17. package/dist/cli/args.js.map +1 -1
  18. package/dist/core/agent-directory-layout.d.ts +15 -0
  19. package/dist/core/agent-directory-layout.d.ts.map +1 -0
  20. package/dist/core/agent-directory-layout.js +72 -0
  21. package/dist/core/agent-directory-layout.js.map +1 -0
  22. package/dist/core/agent-paths.d.ts +19 -2
  23. package/dist/core/agent-paths.d.ts.map +1 -1
  24. package/dist/core/agent-paths.js +67 -4
  25. package/dist/core/agent-paths.js.map +1 -1
  26. package/dist/core/agent-session-runtime.d.ts +52 -8
  27. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  28. package/dist/core/agent-session-runtime.js +397 -79
  29. package/dist/core/agent-session-runtime.js.map +1 -1
  30. package/dist/core/agent-session-services.d.ts +1 -0
  31. package/dist/core/agent-session-services.d.ts.map +1 -1
  32. package/dist/core/agent-session-services.js +1 -0
  33. package/dist/core/agent-session-services.js.map +1 -1
  34. package/dist/core/agent-session.d.ts +71 -136
  35. package/dist/core/agent-session.d.ts.map +1 -1
  36. package/dist/core/agent-session.js +477 -1318
  37. package/dist/core/agent-session.js.map +1 -1
  38. package/dist/core/autonomy/approval-gate.d.ts +3 -2
  39. package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
  40. package/dist/core/autonomy/approval-gate.js +6 -28
  41. package/dist/core/autonomy/approval-gate.js.map +1 -1
  42. package/dist/core/autonomy/bounded-completion.d.ts +1 -1
  43. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  44. package/dist/core/autonomy/bounded-completion.js +1 -1
  45. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  46. package/dist/core/autonomy/contracts.d.ts +20 -12
  47. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  48. package/dist/core/autonomy/contracts.js.map +1 -1
  49. package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
  50. package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
  51. package/dist/core/autonomy/foreground-envelope.js +8 -25
  52. package/dist/core/autonomy/foreground-envelope.js.map +1 -1
  53. package/dist/core/autonomy/gates.d.ts.map +1 -1
  54. package/dist/core/autonomy/gates.js +8 -10
  55. package/dist/core/autonomy/gates.js.map +1 -1
  56. package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
  57. package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
  58. package/dist/core/autonomy/lane-private-paths.js +16 -0
  59. package/dist/core/autonomy/lane-private-paths.js.map +1 -0
  60. package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
  61. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  62. package/dist/core/autonomy/lane-tool-surface.js +46 -8
  63. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  64. package/dist/core/autonomy/lane-tracker.d.ts +14 -0
  65. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  66. package/dist/core/autonomy/lane-tracker.js +38 -0
  67. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  68. package/dist/core/autonomy/risk-assessment.d.ts +1 -2
  69. package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
  70. package/dist/core/autonomy/risk-assessment.js +1 -123
  71. package/dist/core/autonomy/risk-assessment.js.map +1 -1
  72. package/dist/core/autonomy/session-lane-record.d.ts +4 -4
  73. package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
  74. package/dist/core/autonomy/session-lane-record.js +16 -29
  75. package/dist/core/autonomy/session-lane-record.js.map +1 -1
  76. package/dist/core/autonomy/telemetry-events.d.ts +1 -1
  77. package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
  78. package/dist/core/autonomy/telemetry-events.js +1 -1
  79. package/dist/core/autonomy/telemetry-events.js.map +1 -1
  80. package/dist/core/autonomy-telemetry.d.ts +7 -7
  81. package/dist/core/autonomy-telemetry.d.ts.map +1 -1
  82. package/dist/core/autonomy-telemetry.js +9 -9
  83. package/dist/core/autonomy-telemetry.js.map +1 -1
  84. package/dist/core/background-lane-controller.d.ts +54 -236
  85. package/dist/core/background-lane-controller.d.ts.map +1 -1
  86. package/dist/core/background-lane-controller.js +140 -1273
  87. package/dist/core/background-lane-controller.js.map +1 -1
  88. package/dist/core/capability-contract.d.ts +4 -0
  89. package/dist/core/capability-contract.d.ts.map +1 -0
  90. package/dist/core/capability-contract.js +28 -0
  91. package/dist/core/capability-contract.js.map +1 -0
  92. package/dist/core/compaction-controller.d.ts +90 -0
  93. package/dist/core/compaction-controller.d.ts.map +1 -0
  94. package/dist/core/compaction-controller.js +452 -0
  95. package/dist/core/compaction-controller.js.map +1 -0
  96. package/dist/core/compaction-support.d.ts +12 -11
  97. package/dist/core/compaction-support.d.ts.map +1 -1
  98. package/dist/core/compaction-support.js.map +1 -1
  99. package/dist/core/context/context-artifacts.d.ts +6 -2
  100. package/dist/core/context/context-artifacts.d.ts.map +1 -1
  101. package/dist/core/context/context-artifacts.js +34 -2
  102. package/dist/core/context/context-artifacts.js.map +1 -1
  103. package/dist/core/context/context-store-retention.d.ts +8 -2
  104. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  105. package/dist/core/context/context-store-retention.js +158 -35
  106. package/dist/core/context/context-store-retention.js.map +1 -1
  107. package/dist/core/context/okf-memory.d.ts.map +1 -1
  108. package/dist/core/context/okf-memory.js +9 -11
  109. package/dist/core/context/okf-memory.js.map +1 -1
  110. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
  111. package/dist/core/context/sqlite-runtime-index.js +6 -8
  112. package/dist/core/context/sqlite-runtime-index.js.map +1 -1
  113. package/dist/core/context-gc.d.ts +3 -0
  114. package/dist/core/context-gc.d.ts.map +1 -1
  115. package/dist/core/context-gc.js +10 -5
  116. package/dist/core/context-gc.js.map +1 -1
  117. package/dist/core/context-pipeline.d.ts.map +1 -1
  118. package/dist/core/context-pipeline.js +9 -4
  119. package/dist/core/context-pipeline.js.map +1 -1
  120. package/dist/core/default-tool-surface.d.ts.map +1 -1
  121. package/dist/core/default-tool-surface.js +1 -0
  122. package/dist/core/default-tool-surface.js.map +1 -1
  123. package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
  124. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
  125. package/dist/core/delegation/managed-lane-controller.js +217 -0
  126. package/dist/core/delegation/managed-lane-controller.js.map +1 -0
  127. package/dist/core/delegation/session-worker-claim.d.ts +44 -0
  128. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
  129. package/dist/core/delegation/session-worker-claim.js +98 -0
  130. package/dist/core/delegation/session-worker-claim.js.map +1 -0
  131. package/dist/core/delegation/worker-actions.d.ts +7 -5
  132. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  133. package/dist/core/delegation/worker-actions.js +20 -4
  134. package/dist/core/delegation/worker-actions.js.map +1 -1
  135. package/dist/core/delegation/{worker-result.d.ts → worker-claim.d.ts} +13 -13
  136. package/dist/core/delegation/worker-claim.d.ts.map +1 -0
  137. package/dist/core/delegation/{worker-result.js → worker-claim.js} +61 -51
  138. package/dist/core/delegation/worker-claim.js.map +1 -0
  139. package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
  140. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
  141. package/dist/core/delegation/worker-delegation-controller.js +861 -0
  142. package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
  143. package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
  144. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
  145. package/dist/core/delegation/worker-delegation-request.js +2 -0
  146. package/dist/core/delegation/worker-delegation-request.js.map +1 -0
  147. package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
  148. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
  149. package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
  150. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
  151. package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
  152. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
  153. package/dist/core/delegation/worker-execution-policy.js +160 -0
  154. package/dist/core/delegation/worker-execution-policy.js.map +1 -0
  155. package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
  156. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
  157. package/dist/core/delegation/worker-lane-projection.js +100 -0
  158. package/dist/core/delegation/worker-lane-projection.js.map +1 -0
  159. package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
  160. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
  161. package/dist/core/delegation/worker-lifecycle.js +339 -0
  162. package/dist/core/delegation/worker-lifecycle.js.map +1 -0
  163. package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
  164. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
  165. package/dist/core/delegation/worker-notification-coordinator.js +90 -0
  166. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
  167. package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
  168. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
  169. package/dist/core/delegation/worker-profile-resolver.js +113 -0
  170. package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
  171. package/dist/core/delegation/worker-runner.d.ts +25 -14
  172. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  173. package/dist/core/delegation/worker-runner.js +122 -53
  174. package/dist/core/delegation/worker-runner.js.map +1 -1
  175. package/dist/core/delegation/worker-task-label.d.ts +3 -0
  176. package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
  177. package/dist/core/delegation/worker-task-label.js +11 -0
  178. package/dist/core/delegation/worker-task-label.js.map +1 -0
  179. package/dist/core/doctor.d.ts +8 -0
  180. package/dist/core/doctor.d.ts.map +1 -1
  181. package/dist/core/doctor.js +32 -1
  182. package/dist/core/doctor.js.map +1 -1
  183. package/dist/core/extensions/index.d.ts +1 -1
  184. package/dist/core/extensions/index.d.ts.map +1 -1
  185. package/dist/core/extensions/index.js.map +1 -1
  186. package/dist/core/extensions/loader.d.ts +5 -1
  187. package/dist/core/extensions/loader.d.ts.map +1 -1
  188. package/dist/core/extensions/loader.js +50 -15
  189. package/dist/core/extensions/loader.js.map +1 -1
  190. package/dist/core/extensions/runner.d.ts.map +1 -1
  191. package/dist/core/extensions/runner.js +6 -0
  192. package/dist/core/extensions/runner.js.map +1 -1
  193. package/dist/core/extensions/storage.d.ts +8 -0
  194. package/dist/core/extensions/storage.d.ts.map +1 -0
  195. package/dist/core/extensions/storage.js +28 -0
  196. package/dist/core/extensions/storage.js.map +1 -0
  197. package/dist/core/extensions/types.d.ts +70 -21
  198. package/dist/core/extensions/types.d.ts.map +1 -1
  199. package/dist/core/extensions/types.js.map +1 -1
  200. package/dist/core/failure-corpus.d.ts +1 -15
  201. package/dist/core/failure-corpus.d.ts.map +1 -1
  202. package/dist/core/failure-corpus.js +9 -37
  203. package/dist/core/failure-corpus.js.map +1 -1
  204. package/dist/core/foreground-recovery-controller.d.ts +52 -0
  205. package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
  206. package/dist/core/foreground-recovery-controller.js +111 -0
  207. package/dist/core/foreground-recovery-controller.js.map +1 -0
  208. package/dist/core/gateways/channel-provider.d.ts +3 -0
  209. package/dist/core/gateways/channel-provider.d.ts.map +1 -1
  210. package/dist/core/gateways/channel-provider.js +31 -6
  211. package/dist/core/gateways/channel-provider.js.map +1 -1
  212. package/dist/core/goals/goal-acceptance.d.ts +11 -0
  213. package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
  214. package/dist/core/goals/goal-acceptance.js +25 -0
  215. package/dist/core/goals/goal-acceptance.js.map +1 -0
  216. package/dist/core/goals/goal-auto-continue-controller.d.ts +27 -0
  217. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
  218. package/dist/core/goals/goal-auto-continue-controller.js +93 -0
  219. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
  220. package/dist/core/goals/goal-continuation-controller.d.ts +1 -1
  221. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  222. package/dist/core/goals/goal-continuation-controller.js +10 -0
  223. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  224. package/dist/core/goals/goal-continuation-prompt.d.ts +1 -1
  225. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  226. package/dist/core/goals/goal-continuation-prompt.js +6 -6
  227. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  228. package/dist/core/goals/goal-lifecycle.d.ts +20 -0
  229. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
  230. package/dist/core/goals/goal-lifecycle.js +17 -0
  231. package/dist/core/goals/goal-lifecycle.js.map +1 -0
  232. package/dist/core/goals/goal-runtime-snapshot.d.ts +11 -9
  233. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  234. package/dist/core/goals/goal-runtime-snapshot.js +10 -8
  235. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  236. package/dist/core/goals/goal-state.d.ts +1 -0
  237. package/dist/core/goals/goal-state.d.ts.map +1 -1
  238. package/dist/core/goals/goal-state.js +7 -10
  239. package/dist/core/goals/goal-state.js.map +1 -1
  240. package/dist/core/goals/goal-tool-core.d.ts +8 -6
  241. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  242. package/dist/core/goals/goal-tool-core.js +11 -41
  243. package/dist/core/goals/goal-tool-core.js.map +1 -1
  244. package/dist/core/goals/session-goal-state.d.ts +2 -4
  245. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  246. package/dist/core/goals/session-goal-state.js +10 -33
  247. package/dist/core/goals/session-goal-state.js.map +1 -1
  248. package/dist/core/human-input.d.ts +100 -0
  249. package/dist/core/human-input.d.ts.map +1 -0
  250. package/dist/core/human-input.js +362 -0
  251. package/dist/core/human-input.js.map +1 -0
  252. package/dist/core/index.d.ts +9 -1
  253. package/dist/core/index.d.ts.map +1 -1
  254. package/dist/core/index.js +9 -1
  255. package/dist/core/index.js.map +1 -1
  256. package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
  257. package/dist/core/install-telemetry.d.ts.map +1 -0
  258. package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
  259. package/dist/core/install-telemetry.js.map +1 -0
  260. package/dist/core/keybindings.d.ts +17 -1
  261. package/dist/core/keybindings.d.ts.map +1 -1
  262. package/dist/core/keybindings.js +24 -6
  263. package/dist/core/keybindings.js.map +1 -1
  264. package/dist/core/learning/learning-audit.d.ts +2 -4
  265. package/dist/core/learning/learning-audit.d.ts.map +1 -1
  266. package/dist/core/learning/learning-audit.js +9 -29
  267. package/dist/core/learning/learning-audit.js.map +1 -1
  268. package/dist/core/learning/learning-gate.d.ts.map +1 -1
  269. package/dist/core/learning/learning-gate.js +1 -6
  270. package/dist/core/learning/learning-gate.js.map +1 -1
  271. package/dist/core/learning/session-learning-decision.d.ts +2 -4
  272. package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
  273. package/dist/core/learning/session-learning-decision.js +9 -29
  274. package/dist/core/learning/session-learning-decision.js.map +1 -1
  275. package/dist/core/memory-controller.d.ts.map +1 -1
  276. package/dist/core/memory-controller.js +4 -4
  277. package/dist/core/memory-controller.js.map +1 -1
  278. package/dist/core/model-capability.d.ts.map +1 -1
  279. package/dist/core/model-capability.js +1 -0
  280. package/dist/core/model-capability.js.map +1 -1
  281. package/dist/core/model-resolver.d.ts +1 -1
  282. package/dist/core/model-resolver.d.ts.map +1 -1
  283. package/dist/core/model-resolver.js +6 -9
  284. package/dist/core/model-resolver.js.map +1 -1
  285. package/dist/core/model-router/intent-classifier.d.ts +1 -4
  286. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  287. package/dist/core/model-router/intent-classifier.js +1 -156
  288. package/dist/core/model-router/intent-classifier.js.map +1 -1
  289. package/dist/core/model-router-controller.d.ts.map +1 -1
  290. package/dist/core/model-router-controller.js +2 -2
  291. package/dist/core/model-router-controller.js.map +1 -1
  292. package/dist/core/model-selection-controller.d.ts +4 -4
  293. package/dist/core/model-selection-controller.d.ts.map +1 -1
  294. package/dist/core/model-selection-controller.js.map +1 -1
  295. package/dist/core/model-tool-protocol.d.ts +23 -0
  296. package/dist/core/model-tool-protocol.d.ts.map +1 -0
  297. package/dist/core/model-tool-protocol.js +43 -0
  298. package/dist/core/model-tool-protocol.js.map +1 -0
  299. package/dist/core/models/adaptation-store.d.ts +4 -6
  300. package/dist/core/models/adaptation-store.d.ts.map +1 -1
  301. package/dist/core/models/adaptation-store.js +95 -83
  302. package/dist/core/models/adaptation-store.js.map +1 -1
  303. package/dist/core/models/fitness-store.d.ts +2 -12
  304. package/dist/core/models/fitness-store.d.ts.map +1 -1
  305. package/dist/core/models/fitness-store.js +84 -57
  306. package/dist/core/models/fitness-store.js.map +1 -1
  307. package/dist/core/models/host-state-store.d.ts +34 -0
  308. package/dist/core/models/host-state-store.d.ts.map +1 -0
  309. package/dist/core/models/host-state-store.js +86 -0
  310. package/dist/core/models/host-state-store.js.map +1 -0
  311. package/dist/core/orchestration/agent-resume.d.ts +24 -0
  312. package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
  313. package/dist/core/orchestration/agent-resume.js +90 -0
  314. package/dist/core/orchestration/agent-resume.js.map +1 -0
  315. package/dist/core/orchestration/capability-gateway.d.ts +61 -0
  316. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
  317. package/dist/core/orchestration/capability-gateway.js +152 -0
  318. package/dist/core/orchestration/capability-gateway.js.map +1 -0
  319. package/dist/core/orchestration/contracts.d.ts +343 -0
  320. package/dist/core/orchestration/contracts.d.ts.map +1 -0
  321. package/dist/core/orchestration/contracts.js +135 -0
  322. package/dist/core/orchestration/contracts.js.map +1 -0
  323. package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
  324. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
  325. package/dist/core/orchestration/delegation-ledger.js +197 -0
  326. package/dist/core/orchestration/delegation-ledger.js.map +1 -0
  327. package/dist/core/orchestration/event-store.d.ts +83 -0
  328. package/dist/core/orchestration/event-store.d.ts.map +1 -0
  329. package/dist/core/orchestration/event-store.js +560 -0
  330. package/dist/core/orchestration/event-store.js.map +1 -0
  331. package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
  332. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
  333. package/dist/core/orchestration/lane-tool-manifests.js +37 -0
  334. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
  335. package/dist/core/orchestration/model-binding.d.ts +15 -0
  336. package/dist/core/orchestration/model-binding.d.ts.map +1 -0
  337. package/dist/core/orchestration/model-binding.js +29 -0
  338. package/dist/core/orchestration/model-binding.js.map +1 -0
  339. package/dist/core/orchestration/policy-compiler.d.ts +49 -0
  340. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
  341. package/dist/core/orchestration/policy-compiler.js +191 -0
  342. package/dist/core/orchestration/policy-compiler.js.map +1 -0
  343. package/dist/core/orchestration/policy-gate.d.ts +18 -0
  344. package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
  345. package/dist/core/orchestration/policy-gate.js +24 -0
  346. package/dist/core/orchestration/policy-gate.js.map +1 -0
  347. package/dist/core/orchestration/profile-registry.d.ts +51 -0
  348. package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
  349. package/dist/core/orchestration/profile-registry.js +393 -0
  350. package/dist/core/orchestration/profile-registry.js.map +1 -0
  351. package/dist/core/orchestration/profile-store.d.ts +31 -0
  352. package/dist/core/orchestration/profile-store.d.ts.map +1 -0
  353. package/dist/core/orchestration/profile-store.js +136 -0
  354. package/dist/core/orchestration/profile-store.js.map +1 -0
  355. package/dist/core/orchestration/risk-budget.d.ts +9 -0
  356. package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
  357. package/dist/core/orchestration/risk-budget.js +48 -0
  358. package/dist/core/orchestration/risk-budget.js.map +1 -0
  359. package/dist/core/orchestration/task-runtime.d.ts +168 -0
  360. package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
  361. package/dist/core/orchestration/task-runtime.js +1600 -0
  362. package/dist/core/orchestration/task-runtime.js.map +1 -0
  363. package/dist/core/orchestration/work-state-projection.d.ts +32 -0
  364. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
  365. package/dist/core/orchestration/work-state-projection.js +116 -0
  366. package/dist/core/orchestration/work-state-projection.js.map +1 -0
  367. package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
  368. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
  369. package/dist/core/orchestration/worker-execution-contract.js +179 -0
  370. package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
  371. package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
  372. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
  373. package/dist/core/orchestration/worker-result-adapter.js +109 -0
  374. package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
  375. package/dist/core/process-identity.d.ts +11 -0
  376. package/dist/core/process-identity.d.ts.map +1 -0
  377. package/dist/core/process-identity.js +26 -0
  378. package/dist/core/process-identity.js.map +1 -0
  379. package/dist/core/process-matrix/codes.d.ts +14 -3
  380. package/dist/core/process-matrix/codes.d.ts.map +1 -1
  381. package/dist/core/process-matrix/codes.js.map +1 -1
  382. package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
  383. package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
  384. package/dist/core/process-matrix/resume-launcher.js +62 -0
  385. package/dist/core/process-matrix/resume-launcher.js.map +1 -0
  386. package/dist/core/process-matrix/runtime.d.ts +37 -22
  387. package/dist/core/process-matrix/runtime.d.ts.map +1 -1
  388. package/dist/core/process-matrix/runtime.js +399 -76
  389. package/dist/core/process-matrix/runtime.js.map +1 -1
  390. package/dist/core/process-matrix/store.d.ts +5 -2
  391. package/dist/core/process-matrix/store.d.ts.map +1 -1
  392. package/dist/core/process-matrix/store.js +123 -14
  393. package/dist/core/process-matrix/store.js.map +1 -1
  394. package/dist/core/process-matrix/supervisor.d.ts +10 -7
  395. package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
  396. package/dist/core/process-matrix/supervisor.js +45 -14
  397. package/dist/core/process-matrix/supervisor.js.map +1 -1
  398. package/dist/core/profile-registry.d.ts.map +1 -1
  399. package/dist/core/profile-registry.js +6 -8
  400. package/dist/core/profile-registry.js.map +1 -1
  401. package/dist/core/reflection-controller.d.ts +4 -4
  402. package/dist/core/reflection-controller.d.ts.map +1 -1
  403. package/dist/core/reflection-controller.js +2 -1
  404. package/dist/core/reflection-controller.js.map +1 -1
  405. package/dist/core/reload-blockers.d.ts.map +1 -1
  406. package/dist/core/reload-blockers.js +6 -8
  407. package/dist/core/reload-blockers.js.map +1 -1
  408. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  409. package/dist/core/research/evidence-bundle.js +1 -6
  410. package/dist/core/research/evidence-bundle.js.map +1 -1
  411. package/dist/core/research/lane-model-resolver.d.ts +33 -0
  412. package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
  413. package/dist/core/research/lane-model-resolver.js +65 -0
  414. package/dist/core/research/lane-model-resolver.js.map +1 -0
  415. package/dist/core/research/model-fitness-controller.d.ts +38 -0
  416. package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
  417. package/dist/core/research/model-fitness-controller.js +106 -0
  418. package/dist/core/research/model-fitness-controller.js.map +1 -0
  419. package/dist/core/research/model-fitness.d.ts +1 -1
  420. package/dist/core/research/model-fitness.d.ts.map +1 -1
  421. package/dist/core/research/model-fitness.js +4 -4
  422. package/dist/core/research/model-fitness.js.map +1 -1
  423. package/dist/core/research/research-gate.d.ts.map +1 -1
  424. package/dist/core/research/research-gate.js +7 -7
  425. package/dist/core/research/research-gate.js.map +1 -1
  426. package/dist/core/research/research-lane-controller.d.ts +62 -0
  427. package/dist/core/research/research-lane-controller.d.ts.map +1 -0
  428. package/dist/core/research/research-lane-controller.js +292 -0
  429. package/dist/core/research/research-lane-controller.js.map +1 -0
  430. package/dist/core/research/session-evidence-bundle.d.ts +2 -4
  431. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
  432. package/dist/core/research/session-evidence-bundle.js +10 -46
  433. package/dist/core/research/session-evidence-bundle.js.map +1 -1
  434. package/dist/core/resource-loader.d.ts.map +1 -1
  435. package/dist/core/resource-loader.js +7 -2
  436. package/dist/core/resource-loader.js.map +1 -1
  437. package/dist/core/risk-classifier.d.ts +6 -0
  438. package/dist/core/risk-classifier.d.ts.map +1 -0
  439. package/dist/core/risk-classifier.js +225 -0
  440. package/dist/core/risk-classifier.js.map +1 -0
  441. package/dist/core/runtime-builder.d.ts +26 -20
  442. package/dist/core/runtime-builder.d.ts.map +1 -1
  443. package/dist/core/runtime-builder.js +237 -178
  444. package/dist/core/runtime-builder.js.map +1 -1
  445. package/dist/core/sdk.d.ts +6 -3
  446. package/dist/core/sdk.d.ts.map +1 -1
  447. package/dist/core/sdk.js +61 -24
  448. package/dist/core/sdk.js.map +1 -1
  449. package/dist/core/session-analytics.d.ts.map +1 -1
  450. package/dist/core/session-analytics.js +28 -1
  451. package/dist/core/session-analytics.js.map +1 -1
  452. package/dist/core/session-image-store.d.ts +33 -0
  453. package/dist/core/session-image-store.d.ts.map +1 -0
  454. package/dist/core/session-image-store.js +283 -0
  455. package/dist/core/session-image-store.js.map +1 -0
  456. package/dist/core/session-role.d.ts +6 -4
  457. package/dist/core/session-role.d.ts.map +1 -1
  458. package/dist/core/session-role.js +10 -4
  459. package/dist/core/session-role.js.map +1 -1
  460. package/dist/core/session-snapshot.d.ts +34 -0
  461. package/dist/core/session-snapshot.d.ts.map +1 -0
  462. package/dist/core/session-snapshot.js +68 -0
  463. package/dist/core/session-snapshot.js.map +1 -0
  464. package/dist/core/session-supervision-runtime.d.ts +31 -0
  465. package/dist/core/session-supervision-runtime.d.ts.map +1 -0
  466. package/dist/core/session-supervision-runtime.js +97 -0
  467. package/dist/core/session-supervision-runtime.js.map +1 -0
  468. package/dist/core/settings-manager.d.ts +9 -4
  469. package/dist/core/settings-manager.d.ts.map +1 -1
  470. package/dist/core/settings-manager.js +80 -28
  471. package/dist/core/settings-manager.js.map +1 -1
  472. package/dist/core/tasks/session-task-state.d.ts +2 -4
  473. package/dist/core/tasks/session-task-state.d.ts.map +1 -1
  474. package/dist/core/tasks/session-task-state.js +10 -28
  475. package/dist/core/tasks/session-task-state.js.map +1 -1
  476. package/dist/core/tasks/task-projection.d.ts +20 -0
  477. package/dist/core/tasks/task-projection.d.ts.map +1 -0
  478. package/dist/core/tasks/task-projection.js +47 -0
  479. package/dist/core/tasks/task-projection.js.map +1 -0
  480. package/dist/core/tasks/task-state.d.ts +4 -0
  481. package/dist/core/tasks/task-state.d.ts.map +1 -1
  482. package/dist/core/tasks/task-state.js +28 -11
  483. package/dist/core/tasks/task-state.js.map +1 -1
  484. package/dist/core/tool-capability-policy.d.ts +13 -0
  485. package/dist/core/tool-capability-policy.d.ts.map +1 -0
  486. package/dist/core/tool-capability-policy.js +85 -0
  487. package/dist/core/tool-capability-policy.js.map +1 -0
  488. package/dist/core/tool-protocol-controller.d.ts +91 -0
  489. package/dist/core/tool-protocol-controller.d.ts.map +1 -0
  490. package/dist/core/tool-protocol-controller.js +512 -0
  491. package/dist/core/tool-protocol-controller.js.map +1 -0
  492. package/dist/core/tool-recovery-log-records.d.ts +2 -3
  493. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  494. package/dist/core/tool-recovery-log-records.js +9 -35
  495. package/dist/core/tool-recovery-log-records.js.map +1 -1
  496. package/dist/core/tool-selection/tool-performance-store.d.ts +3 -7
  497. package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
  498. package/dist/core/tool-selection/tool-performance-store.js +97 -138
  499. package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
  500. package/dist/core/tools/ask-question.d.ts +124 -0
  501. package/dist/core/tools/ask-question.d.ts.map +1 -0
  502. package/dist/core/tools/ask-question.js +693 -0
  503. package/dist/core/tools/ask-question.js.map +1 -0
  504. package/dist/core/tools/delegate-status.d.ts +31 -3
  505. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  506. package/dist/core/tools/delegate-status.js +149 -29
  507. package/dist/core/tools/delegate-status.js.map +1 -1
  508. package/dist/core/tools/delegate.d.ts +15 -13
  509. package/dist/core/tools/delegate.d.ts.map +1 -1
  510. package/dist/core/tools/delegate.js +108 -23
  511. package/dist/core/tools/delegate.js.map +1 -1
  512. package/dist/core/tools/extensionify.d.ts.map +1 -1
  513. package/dist/core/tools/extensionify.js +1 -0
  514. package/dist/core/tools/extensionify.js.map +1 -1
  515. package/dist/core/tools/goal.d.ts +5 -5
  516. package/dist/core/tools/goal.d.ts.map +1 -1
  517. package/dist/core/tools/goal.js +10 -10
  518. package/dist/core/tools/goal.js.map +1 -1
  519. package/dist/core/tools/model-fitness.d.ts.map +1 -1
  520. package/dist/core/tools/model-fitness.js +2 -2
  521. package/dist/core/tools/model-fitness.js.map +1 -1
  522. package/dist/core/tools/orchestration-panel.d.ts +43 -0
  523. package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
  524. package/dist/core/tools/orchestration-panel.js +168 -0
  525. package/dist/core/tools/orchestration-panel.js.map +1 -0
  526. package/dist/core/tools/run-process.d.ts +26 -0
  527. package/dist/core/tools/run-process.d.ts.map +1 -0
  528. package/dist/core/tools/run-process.js +138 -0
  529. package/dist/core/tools/run-process.js.map +1 -0
  530. package/dist/core/tools/task-steps.d.ts +2 -0
  531. package/dist/core/tools/task-steps.d.ts.map +1 -1
  532. package/dist/core/tools/task-steps.js +102 -0
  533. package/dist/core/tools/task-steps.js.map +1 -1
  534. package/dist/core/tools/tmux-dispatch.d.ts +3 -5
  535. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  536. package/dist/core/tools/tmux-dispatch.js +4 -4
  537. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  538. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
  539. package/dist/core/tools/windows-shell-engine.js +4 -6
  540. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  541. package/dist/core/util/bounded-jsonl.d.ts +10 -0
  542. package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
  543. package/dist/core/util/bounded-jsonl.js +75 -0
  544. package/dist/core/util/bounded-jsonl.js.map +1 -0
  545. package/dist/core/util/value-guards.d.ts +5 -0
  546. package/dist/core/util/value-guards.d.ts.map +1 -0
  547. package/dist/core/util/value-guards.js +12 -0
  548. package/dist/core/util/value-guards.js.map +1 -0
  549. package/dist/core/worktree-sync/store.d.ts +3 -3
  550. package/dist/core/worktree-sync/store.d.ts.map +1 -1
  551. package/dist/core/worktree-sync/store.js +10 -5
  552. package/dist/core/worktree-sync/store.js.map +1 -1
  553. package/dist/index.d.ts +13 -3
  554. package/dist/index.d.ts.map +1 -1
  555. package/dist/index.js +12 -2
  556. package/dist/index.js.map +1 -1
  557. package/dist/main.d.ts.map +1 -1
  558. package/dist/main.js +128 -44
  559. package/dist/main.js.map +1 -1
  560. package/dist/migrations.d.ts +4 -6
  561. package/dist/migrations.d.ts.map +1 -1
  562. package/dist/migrations.js +186 -28
  563. package/dist/migrations.js.map +1 -1
  564. package/dist/modes/interactive/clipboard-input.d.ts +7 -1
  565. package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
  566. package/dist/modes/interactive/clipboard-input.js +44 -6
  567. package/dist/modes/interactive/clipboard-input.js.map +1 -1
  568. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  569. package/dist/modes/interactive/components/settings-selector.js +2 -2
  570. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  571. package/dist/modes/interactive/config-backup.d.ts.map +1 -1
  572. package/dist/modes/interactive/config-backup.js +5 -4
  573. package/dist/modes/interactive/config-backup.js.map +1 -1
  574. package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
  575. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  576. package/dist/modes/interactive/extension-ui-host.js +76 -15
  577. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  578. package/dist/modes/interactive/interactive-mode.d.ts +3 -0
  579. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  580. package/dist/modes/interactive/interactive-mode.js +63 -1
  581. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  582. package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
  583. package/dist/modes/interactive/key-handlers.js +1 -1
  584. package/dist/modes/interactive/key-handlers.js.map +1 -1
  585. package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
  586. package/dist/modes/interactive/profile-menu-controller.js +7 -7
  587. package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
  588. package/dist/modes/interactive/report-commands.d.ts.map +1 -1
  589. package/dist/modes/interactive/report-commands.js +21 -0
  590. package/dist/modes/interactive/report-commands.js.map +1 -1
  591. package/dist/modes/interactive/session-flow-commands.d.ts +17 -2
  592. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  593. package/dist/modes/interactive/session-flow-commands.js +50 -17
  594. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  595. package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
  596. package/dist/modes/interactive/session-io-commands.js +16 -6
  597. package/dist/modes/interactive/session-io-commands.js.map +1 -1
  598. package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
  599. package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
  600. package/dist/modes/interactive/session-replacement-errors.js +15 -0
  601. package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
  602. package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
  603. package/dist/modes/interactive/startup-checks.js +1 -1
  604. package/dist/modes/interactive/startup-checks.js.map +1 -1
  605. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  606. package/dist/modes/rpc/rpc-mode.js +82 -23
  607. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  608. package/dist/modes/rpc/rpc-types.d.ts +15 -0
  609. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  610. package/dist/modes/rpc/rpc-types.js +138 -1
  611. package/dist/modes/rpc/rpc-types.js.map +1 -1
  612. package/dist/utils/clipboard-image.d.ts.map +1 -1
  613. package/dist/utils/clipboard-image.js +2 -13
  614. package/dist/utils/clipboard-image.js.map +1 -1
  615. package/dist/utils/clipboard-native.d.ts +1 -0
  616. package/dist/utils/clipboard-native.d.ts.map +1 -1
  617. package/dist/utils/clipboard-native.js.map +1 -1
  618. package/dist/utils/clipboard.d.ts +1 -0
  619. package/dist/utils/clipboard.d.ts.map +1 -1
  620. package/dist/utils/clipboard.js +52 -1
  621. package/dist/utils/clipboard.js.map +1 -1
  622. package/dist/utils/platform.d.ts +3 -0
  623. package/dist/utils/platform.d.ts.map +1 -0
  624. package/dist/utils/platform.js +8 -0
  625. package/dist/utils/platform.js.map +1 -0
  626. package/dist/utils/work-directory.d.ts +11 -0
  627. package/dist/utils/work-directory.d.ts.map +1 -1
  628. package/dist/utils/work-directory.js +30 -9
  629. package/dist/utils/work-directory.js.map +1 -1
  630. package/docs/UI_POLISH_ORCHESTRATION.md +44 -0
  631. package/docs/UI_QUALITY_ORCHESTRATION.md +30 -0
  632. package/docs/docs.json +4 -0
  633. package/docs/extensions.md +62 -2
  634. package/docs/harness-architecture.md +156 -0
  635. package/docs/keybindings.md +11 -1
  636. package/docs/process-matrix.md +59 -26
  637. package/docs/rpc.md +45 -2
  638. package/docs/sessions.md +15 -0
  639. package/docs/settings.md +125 -11
  640. package/docs/task-steps.md +8 -0
  641. package/docs/telemetry.md +19 -0
  642. package/docs/tmux-agent-manager.md +10 -3
  643. package/docs/ui-reference/README.md +9 -0
  644. package/docs/ui-reference/orchestration-after.txt +7 -0
  645. package/docs/ui-reference/orchestration-before.txt +7 -0
  646. package/docs/ui-reference/orchestration-reference.txt +6 -0
  647. package/docs/usage.md +14 -2
  648. package/docs/work-directory.md +19 -8
  649. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  650. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  651. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  652. package/examples/extensions/question.ts +34 -245
  653. package/examples/extensions/questionnaire.ts +41 -407
  654. package/examples/extensions/sandbox/package-lock.json +2 -2
  655. package/examples/extensions/sandbox/package.json +1 -1
  656. package/examples/extensions/with-deps/package-lock.json +2 -2
  657. package/examples/extensions/with-deps/package.json +1 -1
  658. package/npm-shrinkwrap.json +12 -12
  659. package/package.json +4 -4
  660. package/dist/core/delegation/session-worker-result.d.ts +0 -46
  661. package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
  662. package/dist/core/delegation/session-worker-result.js +0 -113
  663. package/dist/core/delegation/session-worker-result.js.map +0 -1
  664. package/dist/core/delegation/worker-result.d.ts.map +0 -1
  665. package/dist/core/delegation/worker-result.js.map +0 -1
  666. package/dist/core/telemetry.d.ts.map +0 -1
  667. package/dist/core/telemetry.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bounded-jsonl.d.ts","sourceRoot":"","sources":["../../../src/core/util/bounded-jsonl.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,kBAAkB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACnB;AAyCD,+FAA+F;AAC/F,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAQ5G;AAED,8DAA8D;AAC9D,wBAAsB,qBAAqB,CAC1C,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,kBAAkB,GACxB,OAAO,CAAC,IAAI,CAAC,CAmBf","sourcesContent":["import { appendFileSync, promises as fsPromises, readFileSync, statSync } from \"node:fs\";\nimport { withFileLock, withFileLockSync, writeFileAtomic, writeFileAtomicSync } from \"./atomic-file.ts\";\n\nexport interface BoundedJsonlLimits {\n\tmaxBytes: number;\n\ttargetBytes: number;\n\tmaxRecords: number;\n}\n\nconst asyncAppendTails = new Map<string, Promise<void>>();\n\nfunction validateLimits(limits: BoundedJsonlLimits): void {\n\tif (\n\t\t!Number.isSafeInteger(limits.maxBytes) ||\n\t\t!Number.isSafeInteger(limits.targetBytes) ||\n\t\t!Number.isSafeInteger(limits.maxRecords) ||\n\t\tlimits.maxBytes <= 0 ||\n\t\tlimits.targetBytes <= 0 ||\n\t\tlimits.targetBytes > limits.maxBytes ||\n\t\tlimits.maxRecords <= 0\n\t) {\n\t\tthrow new TypeError(\"Bounded JSONL limits require positive integers and targetBytes <= maxBytes.\");\n\t}\n}\n\nfunction retainedContent(content: string, limits: BoundedJsonlLimits): string {\n\tconst lines = content.split(\"\\n\").filter((line) => line.trim().length > 0);\n\tconst retained: string[] = [];\n\tlet retainedBytes = 0;\n\tfor (let index = lines.length - 1; index >= 0 && retained.length < limits.maxRecords; index--) {\n\t\tconst line = lines[index]!;\n\t\tconst lineBytes = Buffer.byteLength(line, \"utf-8\") + 1;\n\t\tif (lineBytes > limits.maxBytes) continue;\n\t\tif (retained.length > 0 && retainedBytes + lineBytes > limits.targetBytes) break;\n\t\tretained.push(line);\n\t\tretainedBytes += lineBytes;\n\t\tif (retainedBytes >= limits.targetBytes) break;\n\t}\n\tretained.reverse();\n\treturn retained.length > 0 ? `${retained.join(\"\\n\")}\\n` : \"\";\n}\n\nfunction serializeLine(value: unknown): string {\n\tconst encoded = JSON.stringify(value);\n\tif (encoded === undefined) throw new TypeError(\"Bounded JSONL records must be JSON-serializable values.\");\n\treturn `${encoded}\\n`;\n}\n\n/** Append one JSON record and rotate to the newest low-water tail under one exclusive lock. */\nexport function appendBoundedJsonLineSync(filePath: string, value: unknown, limits: BoundedJsonlLimits): void {\n\tvalidateLimits(limits);\n\tconst line = serializeLine(value);\n\twithFileLockSync(filePath, () => {\n\t\tappendFileSync(filePath, line, \"utf-8\");\n\t\tif (statSync(filePath).size <= limits.maxBytes) return;\n\t\twriteFileAtomicSync(filePath, retainedContent(readFileSync(filePath, \"utf-8\"), limits));\n\t});\n}\n\n/** Async counterpart of {@link appendBoundedJsonLineSync}. */\nexport async function appendBoundedJsonLine(\n\tfilePath: string,\n\tvalue: unknown,\n\tlimits: BoundedJsonlLimits,\n): Promise<void> {\n\tvalidateLimits(limits);\n\tconst line = serializeLine(value);\n\tconst previous = asyncAppendTails.get(filePath) ?? Promise.resolve();\n\tconst operation = previous\n\t\t.catch(() => undefined)\n\t\t.then(async () => {\n\t\t\tawait withFileLock(filePath, async () => {\n\t\t\t\tawait fsPromises.appendFile(filePath, line, \"utf-8\");\n\t\t\t\tif ((await fsPromises.stat(filePath)).size <= limits.maxBytes) return;\n\t\t\t\tawait writeFileAtomic(filePath, retainedContent(await fsPromises.readFile(filePath, \"utf-8\"), limits));\n\t\t\t});\n\t\t});\n\tasyncAppendTails.set(filePath, operation);\n\ttry {\n\t\tawait operation;\n\t} finally {\n\t\tif (asyncAppendTails.get(filePath) === operation) asyncAppendTails.delete(filePath);\n\t}\n}\n"]}
@@ -0,0 +1,75 @@
1
+ import { appendFileSync, promises as fsPromises, readFileSync, statSync } from "node:fs";
2
+ import { withFileLock, withFileLockSync, writeFileAtomic, writeFileAtomicSync } from "./atomic-file.js";
3
+ const asyncAppendTails = new Map();
4
+ function validateLimits(limits) {
5
+ if (!Number.isSafeInteger(limits.maxBytes) ||
6
+ !Number.isSafeInteger(limits.targetBytes) ||
7
+ !Number.isSafeInteger(limits.maxRecords) ||
8
+ limits.maxBytes <= 0 ||
9
+ limits.targetBytes <= 0 ||
10
+ limits.targetBytes > limits.maxBytes ||
11
+ limits.maxRecords <= 0) {
12
+ throw new TypeError("Bounded JSONL limits require positive integers and targetBytes <= maxBytes.");
13
+ }
14
+ }
15
+ function retainedContent(content, limits) {
16
+ const lines = content.split("\n").filter((line) => line.trim().length > 0);
17
+ const retained = [];
18
+ let retainedBytes = 0;
19
+ for (let index = lines.length - 1; index >= 0 && retained.length < limits.maxRecords; index--) {
20
+ const line = lines[index];
21
+ const lineBytes = Buffer.byteLength(line, "utf-8") + 1;
22
+ if (lineBytes > limits.maxBytes)
23
+ continue;
24
+ if (retained.length > 0 && retainedBytes + lineBytes > limits.targetBytes)
25
+ break;
26
+ retained.push(line);
27
+ retainedBytes += lineBytes;
28
+ if (retainedBytes >= limits.targetBytes)
29
+ break;
30
+ }
31
+ retained.reverse();
32
+ return retained.length > 0 ? `${retained.join("\n")}\n` : "";
33
+ }
34
+ function serializeLine(value) {
35
+ const encoded = JSON.stringify(value);
36
+ if (encoded === undefined)
37
+ throw new TypeError("Bounded JSONL records must be JSON-serializable values.");
38
+ return `${encoded}\n`;
39
+ }
40
+ /** Append one JSON record and rotate to the newest low-water tail under one exclusive lock. */
41
+ export function appendBoundedJsonLineSync(filePath, value, limits) {
42
+ validateLimits(limits);
43
+ const line = serializeLine(value);
44
+ withFileLockSync(filePath, () => {
45
+ appendFileSync(filePath, line, "utf-8");
46
+ if (statSync(filePath).size <= limits.maxBytes)
47
+ return;
48
+ writeFileAtomicSync(filePath, retainedContent(readFileSync(filePath, "utf-8"), limits));
49
+ });
50
+ }
51
+ /** Async counterpart of {@link appendBoundedJsonLineSync}. */
52
+ export async function appendBoundedJsonLine(filePath, value, limits) {
53
+ validateLimits(limits);
54
+ const line = serializeLine(value);
55
+ const previous = asyncAppendTails.get(filePath) ?? Promise.resolve();
56
+ const operation = previous
57
+ .catch(() => undefined)
58
+ .then(async () => {
59
+ await withFileLock(filePath, async () => {
60
+ await fsPromises.appendFile(filePath, line, "utf-8");
61
+ if ((await fsPromises.stat(filePath)).size <= limits.maxBytes)
62
+ return;
63
+ await writeFileAtomic(filePath, retainedContent(await fsPromises.readFile(filePath, "utf-8"), limits));
64
+ });
65
+ });
66
+ asyncAppendTails.set(filePath, operation);
67
+ try {
68
+ await operation;
69
+ }
70
+ finally {
71
+ if (asyncAppendTails.get(filePath) === operation)
72
+ asyncAppendTails.delete(filePath);
73
+ }
74
+ }
75
+ //# sourceMappingURL=bounded-jsonl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bounded-jsonl.js","sourceRoot":"","sources":["../../../src/core/util/bounded-jsonl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,IAAI,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAQxG,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAyB,CAAC;AAE1D,SAAS,cAAc,CAAC,MAA0B,EAAQ;IACzD,IACC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC;QACtC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC;QACzC,CAAC,MAAM,CAAC,aA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AK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;SACtB,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QACjB,MAAM,YAAY,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC;YACxC,MAAM,UAAU,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YACrD,IAAI,CAAC,MAAM,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,QAAQ;gBAAE,OAAO;YACtE,MAAM,eAAe,CAAC,QAAQ,EAAE,eAAe,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAAA,CACvG,CAAC,CAAC;IAAA,CACH,CAAC,CAAC;IACJ,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC1C,IAAI,CAAC;QACJ,MAAM,SAAS,CAAC;IACjB,CAAC;YAAS,CAAC;QACV,IAAI,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,SAAS;YAAE,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrF,CAAC;AAAA,CACD","sourcesContent":["import { appendFileSync, promises as fsPromises, readFileSync, statSync } from \"node:fs\";\nimport { withFileLock, withFileLockSync, writeFileAtomic, writeFileAtomicSync } from \"./atomic-file.ts\";\n\nexport interface BoundedJsonlLimits {\n\tmaxBytes: number;\n\ttargetBytes: number;\n\tmaxRecords: number;\n}\n\nconst asyncAppendTails = new Map<string, Promise<void>>();\n\nfunction validateLimits(limits: BoundedJsonlLimits): void {\n\tif (\n\t\t!Number.isSafeInteger(limits.maxBytes) ||\n\t\t!Number.isSafeInteger(limits.targetBytes) ||\n\t\t!Number.isSafeInteger(limits.maxRecords) ||\n\t\tlimits.maxBytes <= 0 ||\n\t\tlimits.targetBytes <= 0 ||\n\t\tlimits.targetBytes > limits.maxBytes ||\n\t\tlimits.maxRecords <= 0\n\t) {\n\t\tthrow new TypeError(\"Bounded JSONL limits require positive integers and targetBytes <= maxBytes.\");\n\t}\n}\n\nfunction retainedContent(content: string, limits: BoundedJsonlLimits): string {\n\tconst lines = content.split(\"\\n\").filter((line) => line.trim().length > 0);\n\tconst retained: string[] = [];\n\tlet retainedBytes = 0;\n\tfor (let index = lines.length - 1; index >= 0 && retained.length < limits.maxRecords; index--) {\n\t\tconst line = lines[index]!;\n\t\tconst lineBytes = Buffer.byteLength(line, \"utf-8\") + 1;\n\t\tif (lineBytes > limits.maxBytes) continue;\n\t\tif (retained.length > 0 && retainedBytes + lineBytes > limits.targetBytes) break;\n\t\tretained.push(line);\n\t\tretainedBytes += lineBytes;\n\t\tif (retainedBytes >= limits.targetBytes) break;\n\t}\n\tretained.reverse();\n\treturn retained.length > 0 ? `${retained.join(\"\\n\")}\\n` : \"\";\n}\n\nfunction serializeLine(value: unknown): string {\n\tconst encoded = JSON.stringify(value);\n\tif (encoded === undefined) throw new TypeError(\"Bounded JSONL records must be JSON-serializable values.\");\n\treturn `${encoded}\\n`;\n}\n\n/** Append one JSON record and rotate to the newest low-water tail under one exclusive lock. */\nexport function appendBoundedJsonLineSync(filePath: string, value: unknown, limits: BoundedJsonlLimits): void {\n\tvalidateLimits(limits);\n\tconst line = serializeLine(value);\n\twithFileLockSync(filePath, () => {\n\t\tappendFileSync(filePath, line, \"utf-8\");\n\t\tif (statSync(filePath).size <= limits.maxBytes) return;\n\t\twriteFileAtomicSync(filePath, retainedContent(readFileSync(filePath, \"utf-8\"), limits));\n\t});\n}\n\n/** Async counterpart of {@link appendBoundedJsonLineSync}. */\nexport async function appendBoundedJsonLine(\n\tfilePath: string,\n\tvalue: unknown,\n\tlimits: BoundedJsonlLimits,\n): Promise<void> {\n\tvalidateLimits(limits);\n\tconst line = serializeLine(value);\n\tconst previous = asyncAppendTails.get(filePath) ?? Promise.resolve();\n\tconst operation = previous\n\t\t.catch(() => undefined)\n\t\t.then(async () => {\n\t\t\tawait withFileLock(filePath, async () => {\n\t\t\t\tawait fsPromises.appendFile(filePath, line, \"utf-8\");\n\t\t\t\tif ((await fsPromises.stat(filePath)).size <= limits.maxBytes) return;\n\t\t\t\tawait writeFileAtomic(filePath, retainedContent(await fsPromises.readFile(filePath, \"utf-8\"), limits));\n\t\t\t});\n\t\t});\n\tasyncAppendTails.set(filePath, operation);\n\ttry {\n\t\tawait operation;\n\t} finally {\n\t\tif (asyncAppendTails.get(filePath) === operation) asyncAppendTails.delete(filePath);\n\t}\n}\n"]}
@@ -0,0 +1,5 @@
1
+ /** Accepts non-null object records while excluding arrays; custom prototypes remain valid. */
2
+ export declare function isRecordObject(value: unknown): value is Record<string, unknown>;
3
+ /** Accepts only ordinary JSON-style records, including null-prototype dictionaries. */
4
+ export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
5
+ //# sourceMappingURL=value-guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-guards.d.ts","sourceRoot":"","sources":["../../../src/core/util/value-guards.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE/E;AAED,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI9E","sourcesContent":["/** Accepts non-null object records while excluding arrays; custom prototypes remain valid. */\nexport function isRecordObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** Accepts only ordinary JSON-style records, including null-prototype dictionaries. */\nexport function isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!isRecordObject(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /** Accepts non-null object records while excluding arrays; custom prototypes remain valid. */
2
+ export function isRecordObject(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
5
+ /** Accepts only ordinary JSON-style records, including null-prototype dictionaries. */
6
+ export function isPlainRecord(value) {
7
+ if (!isRecordObject(value))
8
+ return false;
9
+ const prototype = Object.getPrototypeOf(value);
10
+ return prototype === Object.prototype || prototype === null;
11
+ }
12
+ //# sourceMappingURL=value-guards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-guards.js","sourceRoot":"","sources":["../../../src/core/util/value-guards.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,MAAM,UAAU,cAAc,CAAC,KAAc,EAAoC;IAChF,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAAA,CAC5E;AAED,uFAAuF;AACvF,MAAM,UAAU,aAAa,CAAC,KAAc,EAAoC;IAC/E,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACzC,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAAA,CAC5D","sourcesContent":["/** Accepts non-null object records while excluding arrays; custom prototypes remain valid. */\nexport function isRecordObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** Accepts only ordinary JSON-style records, including null-prototype dictionaries. */\nexport function isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!isRecordObject(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n"]}
@@ -9,9 +9,9 @@
9
9
  * git by the engine (`git-engine.ts`). A deleted or corrupt store is rebuildable via reconcile --
10
10
  * every reader here treats missing/corrupt files as "absent", never as an error.
11
11
  *
12
- * Writes are tmp+rename atomic (`util/atomic-file.ts`); the audit log is append-only single-line
13
- * JSON (O_APPEND, one line per event -- atomic enough for the small records involved). The
14
- * integration lock is a mkdir-atomic directory with an owner manifest: mkdir either succeeds
12
+ * Writes are tmp+rename atomic (`util/atomic-file.ts`); the audit log uses the shared bounded JSONL
13
+ * sink, which serializes concurrent writers and atomically rotates to its newest low-water tail.
14
+ * The integration lock is a mkdir-atomic directory with an owner manifest: mkdir either succeeds
15
15
  * (lock acquired) or fails EEXIST (held), with takeover ONLY for a provably-dead same-host owner.
16
16
  */
17
17
  import type { IntegrationLockAcquisition, IntegrationLockOwner, LandingTransaction, LaneRegistration, WorktreeSyncEpoch } from "./codes.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/core/worktree-sync/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,OAAO,KAAK,EACX,0BAA0B,EAC1B,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;0FAC0F;AAC1F,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAI9C,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,CAanE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,M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CACrB;AAED,mGAAmG;AACnG,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAStE;AAyBD;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC3C,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,IAAI,CAAC,oBAAoB,EAAE,YAAY,GAAG,OAAO,CAAC,EACzD,IAAI,GAAE,mBAAwB,GAC5B,OAAO,CAAC,0BAA0B,CAAC,CA+CrC;AAED,wBAAsB,sBAAsB,CAC3C,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,mBAAwB,GAC5B,OAAO,CAAC,OAAO,CAAC,CASlB;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAErG","sourcesContent":["/**\n * Worktree-sync on-disk store: coordination state shared by EVERY process working on one repo.\n *\n * Lives under `<git-common-dir>/pi-worktree-sync/` -- all worktrees of a repository share the git\n * common dir, so the store is repo-scoped and cross-process by construction, survives `/reload`\n * and crashes, is invisible to `git status`, and needs no gitignore entry.\n *\n * The store is an INDEX, not the truth: freshness/dirtiness/progress are always re-derived from\n * git by the engine (`git-engine.ts`). A deleted or corrupt store is rebuildable via reconcile --\n * every reader here treats missing/corrupt files as \"absent\", never as an error.\n *\n * Writes are tmp+rename atomic (`util/atomic-file.ts`); the audit log is append-only single-line\n * JSON (O_APPEND, one line per event -- atomic enough for the small records involved). The\n * integration lock is a mkdir-atomic directory with an owner manifest: mkdir either succeeds\n * (lock acquired) or fails EEXIST (held), with takeover ONLY for a provably-dead same-host owner.\n */\n\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { promises as fsPromises, realpathSync } from \"node:fs\";\nimport { hostname as osHostname } from \"node:os\";\nimport { basename, dirname, join } from \"node:path\";\nimport { withFileLock, writeFileAtomic } from \"../util/atomic-file.ts\";\nimport type {\n\tIntegrationLockAcquisition,\n\tIntegrationLockOwner,\n\tLandingTransaction,\n\tLaneRegistration,\n\tWorktreeSyncEpoch,\n} from \"./codes.ts\";\n\nexport interface SyncStorePaths {\n\troot: string;\n\tepochFile: string;\n\tlandingTransactionFile: string;\n\tlanesDir: string;\n\tlockDir: string;\n\tlockOwnerFile: string;\n\tlockGuardFile: string;\n\tlifecycleLockFile: string;\n\teventsFile: string;\n}\n\n/** Grace window after which an ownerless lock dir (crash between mkdir and owner write) counts as\n * dead and may be taken over. Fresh ownerless dirs are conservatively treated as held. */\nexport const OWNERLESS_LOCK_STALE_MS = 30_000;\n\nconst STORE_DIR_NAME = \"pi-worktree-sync\";\n\nexport function syncStorePaths(gitCommonDir: string): SyncStorePaths {\n\tconst root = join(gitCommonDir, STORE_DIR_NAME);\n\treturn {\n\t\troot,\n\t\tepochFile: join(root, \"epoch.json\"),\n\t\tlandingTransactionFile: join(root, \"landing-transaction.json\"),\n\t\tlanesDir: join(root, \"lanes\"),\n\t\tlockDir: join(root, \"locks\", \"integration\"),\n\t\tlockOwnerFile: join(root, \"locks\", \"integration\", \"owner.json\"),\n\t\tlockGuardFile: join(root, \"locks\", \"integration-metadata\"),\n\t\tlifecycleLockFile: join(root, \"locks\", \"lifecycle\"),\n\t\teventsFile: join(root, \"events.jsonl\"),\n\t};\n}\n\n/**\n * Stable per-repo slug for the lane-worktree checkout root: sanitized repo basename plus 8 hex of\n * sha256 over the REALPATH of the git common dir -- same-named repos in different places cannot\n * collide, and every worktree of one repo resolves the same slug.\n */\nexport function repoSlug(repoTopLevel: string, gitCommonDir: string): string {\n\tlet canonical = gitCommonDir;\n\ttry {\n\t\tcanonical = realpathSync(gitCommonDir);\n\t} catch {\n\t\t// Unresolvable (already-deleted repo during teardown): hash the raw path deterministically.\n\t}\n\tconst hash = createHash(\"sha256\").update(canonical).digest(\"hex\").slice(0, 8);\n\tconst base = basename(repoTopLevel)\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9-]+/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\t\t.slice(0, 48);\n\treturn `${base || \"repo\"}-${hash}`;\n}\n\nasync function readJsonFile<T>(filePath: string): Promise<T | undefined> {\n\tlet raw: string;\n\ttry {\n\t\traw = await fsPromises.readFile(filePath, \"utf-8\");\n\t} catch {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\treturn JSON.parse(raw) as T;\n\t} catch {\n\t\t// Corrupt store files are treated as absent -- git remains the truth and reconcile rebuilds.\n\t\treturn undefined;\n\t}\n}\n\nexport async function readEpoch(paths: SyncStorePaths): Promise<WorktreeSyncEpoch | undefined> {\n\treturn readJsonFile<WorktreeSyncEpoch>(paths.epochFile);\n}\n\nexport async function writeEpoch(paths: SyncStorePaths, epoch: WorktreeSyncEpoch): Promise<void> {\n\tawait writeFileAtomic(paths.epochFile, `${JSON.stringify(epoch, null, \"\\t\")}\\n`);\n}\n\nexport async function readLandingTransaction(paths: SyncStorePaths): Promise<LandingTransaction | undefined> {\n\tconst value = await readJsonFile<unknown>(paths.landingTransactionFile);\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, unknown>;\n\tif (\n\t\ttypeof record.laneKey !== \"string\" ||\n\t\ttypeof record.priorMainSha !== \"string\" ||\n\t\ttypeof record.testedTipSha !== \"string\" ||\n\t\t!Array.isArray(record.changedPaths) ||\n\t\t!record.changedPaths.every((path) => typeof path === \"string\") ||\n\t\ttypeof record.changedPathsTruncated !== \"boolean\" ||\n\t\ttypeof record.lockToken !== \"string\" ||\n\t\t(record.gate !== \"passed\" && record.gate !== \"off\") ||\n\t\t(record.stage !== \"ready_to_merge\" &&\n\t\t\trecord.stage !== \"main_moved\" &&\n\t\t\trecord.stage !== \"epoch_written\" &&\n\t\t\trecord.stage !== \"audit_logged\")\n\t) {\n\t\treturn undefined;\n\t}\n\treturn record as unknown as LandingTransaction;\n}\n\nexport async function writeLandingTransaction(paths: SyncStorePaths, transaction: LandingTransaction): Promise<void> {\n\tawait writeFileAtomic(paths.landingTransactionFile, `${JSON.stringify(transaction, null, \"\\t\")}\\n`);\n}\n\nexport async function clearLandingTransaction(paths: SyncStorePaths): Promise<void> {\n\ttry {\n\t\tawait fsPromises.unlink(paths.landingTransactionFile);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t}\n}\n\nfunction laneFile(paths: SyncStorePaths, laneKey: string): string {\n\treturn join(paths.lanesDir, `${laneKey}.json`);\n}\n\nexport async function readLane(paths: SyncStorePaths, laneKey: string): Promise<LaneRegistration | undefined> {\n\treturn readJsonFile<LaneRegistration>(laneFile(paths, laneKey));\n}\n\nexport async function writeLane(paths: SyncStorePaths, lane: LaneRegistration): Promise<void> {\n\tawait writeFileAtomic(laneFile(paths, lane.laneKey), `${JSON.stringify(lane, null, \"\\t\")}\\n`);\n}\n\nexport async function listLanes(paths: SyncStorePaths): Promise<LaneRegistration[]> {\n\tlet entries: string[];\n\ttry {\n\t\tentries = await fsPromises.readdir(paths.lanesDir);\n\t} catch {\n\t\treturn [];\n\t}\n\tconst lanes: LaneRegistration[] = [];\n\tfor (const entry of entries.sort()) {\n\t\tif (!entry.endsWith(\".json\")) continue;\n\t\tconst lane = await readJsonFile<LaneRegistration>(join(paths.lanesDir, entry));\n\t\tif (lane?.laneKey) lanes.push(lane);\n\t}\n\treturn lanes;\n}\n\n/** Append one audit event as a single JSON line. `at` is stamped here so every event carries it. */\nexport async function appendAuditEvent(\n\tpaths: SyncStorePaths,\n\tevent: { event: string } & Record<string, unknown>,\n\tat: string,\n): Promise<void> {\n\tawait fsPromises.mkdir(dirname(paths.eventsFile), { recursive: true });\n\tawait fsPromises.appendFile(paths.eventsFile, `${JSON.stringify({ at, ...event })}\\n`, \"utf-8\");\n}\n\nexport interface IntegrationLockDeps {\n\t/** Injectable liveness probe (deterministic tests). Default: same-host `process.kill(pid, 0)`. */\n\tisPidAlive?: (owner: IntegrationLockOwner) => boolean;\n\tnow?: () => string;\n\tnowMs?: () => number;\n}\n\n/** Same-host pid liveness. A foreign-host owner is ALWAYS treated as alive -- never taken over. */\nexport function defaultIsPidAlive(owner: IntegrationLockOwner): boolean {\n\tif (owner.hostname !== osHostname()) return true;\n\ttry {\n\t\tprocess.kill(owner.pid, 0);\n\t\treturn true;\n\t} catch (err) {\n\t\t// EPERM means the pid exists but belongs to another user -- alive. Only ESRCH is dead.\n\t\treturn (err as NodeJS.ErrnoException).code === \"EPERM\";\n\t}\n}\n\nasync function readLockOwner(paths: SyncStorePaths): Promise<IntegrationLockOwner | undefined> {\n\treturn readJsonFile<IntegrationLockOwner>(paths.lockOwnerFile);\n}\n\nasync function tryMkdirLock(paths: SyncStorePaths): Promise<boolean> {\n\ttry {\n\t\tawait fsPromises.mkdir(paths.lockDir, { recursive: false });\n\t\treturn true;\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\t// Parent `locks/` missing on first use: create it, then retry the ATOMIC non-recursive mkdir.\n\t\t\tawait fsPromises.mkdir(dirname(paths.lockDir), { recursive: true });\n\t\t\ttry {\n\t\t\t\tawait fsPromises.mkdir(paths.lockDir, { recursive: false });\n\t\t\t\treturn true;\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}\n\n/**\n * Acquire the single integration lock (G1: landing is serialized). Non-blocking: a held lock\n * returns `{acquired:false, holder, holderAlive}` immediately -- callers surface `lock_busy` and\n * retry on their own cadence rather than spinning here. Takeover happens ONLY when the recorded\n * owner is provably dead on this host (or the lock dir is ownerless and older than\n * {@link OWNERLESS_LOCK_STALE_MS}); every takeover is audited.\n */\nexport async function acquireIntegrationLock(\n\tpaths: SyncStorePaths,\n\towner: Omit<IntegrationLockOwner, \"acquiredAt\" | \"token\">,\n\tdeps: IntegrationLockDeps = {},\n): Promise<IntegrationLockAcquisition> {\n\treturn withFileLock(paths.lockGuardFile, async () => {\n\t\tconst now = deps.now ?? (() => new Date().toISOString());\n\t\tconst nowMs = deps.nowMs ?? (() => Date.now());\n\t\tconst isPidAlive = deps.isPidAlive ?? defaultIsPidAlive;\n\t\tfor (let attempt = 0; attempt < 2; attempt++) {\n\t\t\tif (await tryMkdirLock(paths)) {\n\t\t\t\tconst token = randomUUID();\n\t\t\t\tconst manifest: IntegrationLockOwner = { ...owner, token, acquiredAt: now() };\n\t\t\t\tawait fsPromises.writeFile(paths.lockOwnerFile, `${JSON.stringify(manifest)}\\n`, \"utf-8\");\n\t\t\t\tawait appendAuditEvent(\n\t\t\t\t\tpaths,\n\t\t\t\t\t{ event: \"lock_acquired\", ...(attempt > 0 ? { takeover: true } : {}) },\n\t\t\t\t\tnow(),\n\t\t\t\t);\n\t\t\t\treturn { acquired: true, takeover: attempt > 0, token };\n\t\t\t}\n\n\t\t\tconst holder = await readLockOwner(paths);\n\t\t\tif (holder) {\n\t\t\t\tif (isPidAlive(holder)) return { acquired: false, holder, holderAlive: true };\n\t\t\t} else {\n\t\t\t\t// Ownerless dir: a crash between mkdir and the owner write. Only stale ones are dead.\n\t\t\t\tlet dirMtimeMs: number | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tdirMtimeMs = (await fsPromises.stat(paths.lockDir)).mtimeMs;\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (nowMs() - dirMtimeMs < OWNERLESS_LOCK_STALE_MS) return { acquired: false, holderAlive: true };\n\t\t\t}\n\n\t\t\t// Metadata serialization makes the stale observation and directory removal one guarded\n\t\t\t// operation; a successor cannot be removed by a stale observer.\n\t\t\tawait fsPromises.rm(paths.lockDir, { recursive: true, force: true });\n\t\t\tawait appendAuditEvent(\n\t\t\t\tpaths,\n\t\t\t\t{\n\t\t\t\t\tevent: \"lock_takeover\",\n\t\t\t\t\t...(holder ? { deadOwnerPid: holder.pid, deadOwnerLaneKey: holder.laneKey } : {}),\n\t\t\t\t},\n\t\t\t\tnow(),\n\t\t\t);\n\t\t}\n\t\tconst holder = await readLockOwner(paths);\n\t\treturn { acquired: false, holder, holderAlive: holder ? isPidAlive(holder) : true };\n\t});\n}\n\nexport async function releaseIntegrationLock(\n\tpaths: SyncStorePaths,\n\ttoken: string,\n\tdeps: IntegrationLockDeps = {},\n): Promise<boolean> {\n\treturn withFileLock(paths.lockGuardFile, async () => {\n\t\tconst now = deps.now ?? (() => new Date().toISOString());\n\t\tconst holder = await readLockOwner(paths);\n\t\tif (!holder || holder.token !== token) return false;\n\t\tawait fsPromises.rm(paths.lockDir, { recursive: true, force: true });\n\t\tawait appendAuditEvent(paths, { event: \"lock_released\" }, now());\n\t\treturn true;\n\t});\n}\n\nexport async function readLockHolder(paths: SyncStorePaths): Promise<IntegrationLockOwner | undefined> {\n\treturn readLockOwner(paths);\n}\n"]}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/core/worktree-sync/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,OAAO,KAAK,EACX,0BAA0B,EAC1B,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;0FAC0F;AAC1F,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAS9C,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,CAanE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAc3E;AAiBD,wBAAsB,SAAS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,iBAAiB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAStE;AAyBD;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC3C,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,IAAI,CAAC,oBAAoB,EAAE,YAAY,GAAG,OAAO,CAAC,EACzD,IAAI,GAAE,mBAAwB,GAC5B,OAAO,CAAC,0BAA0B,CAAC,CA+CrC;AAED,wBAAsB,sBAAsB,CAC3C,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,mBAAwB,GAC5B,OAAO,CAAC,OAAO,CAAC,CASlB;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAErG","sourcesContent":["/**\n * Worktree-sync on-disk store: coordination state shared by EVERY process working on one repo.\n *\n * Lives under `<git-common-dir>/pi-worktree-sync/` -- all worktrees of a repository share the git\n * common dir, so the store is repo-scoped and cross-process by construction, survives `/reload`\n * and crashes, is invisible to `git status`, and needs no gitignore entry.\n *\n * The store is an INDEX, not the truth: freshness/dirtiness/progress are always re-derived from\n * git by the engine (`git-engine.ts`). A deleted or corrupt store is rebuildable via reconcile --\n * every reader here treats missing/corrupt files as \"absent\", never as an error.\n *\n * Writes are tmp+rename atomic (`util/atomic-file.ts`); the audit log uses the shared bounded JSONL\n * sink, which serializes concurrent writers and atomically rotates to its newest low-water tail.\n * The integration lock is a mkdir-atomic directory with an owner manifest: mkdir either succeeds\n * (lock acquired) or fails EEXIST (held), with takeover ONLY for a provably-dead same-host owner.\n */\n\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { promises as fsPromises, realpathSync } from \"node:fs\";\nimport { hostname as osHostname } from \"node:os\";\nimport { basename, dirname, join } from \"node:path\";\nimport { withFileLock, writeFileAtomic } from \"../util/atomic-file.ts\";\nimport { appendBoundedJsonLine, type BoundedJsonlLimits } from \"../util/bounded-jsonl.ts\";\nimport type {\n\tIntegrationLockAcquisition,\n\tIntegrationLockOwner,\n\tLandingTransaction,\n\tLaneRegistration,\n\tWorktreeSyncEpoch,\n} from \"./codes.ts\";\n\nexport interface SyncStorePaths {\n\troot: string;\n\tepochFile: string;\n\tlandingTransactionFile: string;\n\tlanesDir: string;\n\tlockDir: string;\n\tlockOwnerFile: string;\n\tlockGuardFile: string;\n\tlifecycleLockFile: string;\n\teventsFile: string;\n}\n\n/** Grace window after which an ownerless lock dir (crash between mkdir and owner write) counts as\n * dead and may be taken over. Fresh ownerless dirs are conservatively treated as held. */\nexport const OWNERLESS_LOCK_STALE_MS = 30_000;\n\nconst STORE_DIR_NAME = \"pi-worktree-sync\";\nconst WORKTREE_AUDIT_EVENT_LIMITS: BoundedJsonlLimits = {\n\tmaxBytes: 4 * 1024 * 1024,\n\ttargetBytes: Math.floor(4 * 1024 * 1024 * 0.75),\n\tmaxRecords: 10_000,\n};\n\nexport function syncStorePaths(gitCommonDir: string): SyncStorePaths {\n\tconst root = join(gitCommonDir, STORE_DIR_NAME);\n\treturn {\n\t\troot,\n\t\tepochFile: join(root, \"epoch.json\"),\n\t\tlandingTransactionFile: join(root, \"landing-transaction.json\"),\n\t\tlanesDir: join(root, \"lanes\"),\n\t\tlockDir: join(root, \"locks\", \"integration\"),\n\t\tlockOwnerFile: join(root, \"locks\", \"integration\", \"owner.json\"),\n\t\tlockGuardFile: join(root, \"locks\", \"integration-metadata\"),\n\t\tlifecycleLockFile: join(root, \"locks\", \"lifecycle\"),\n\t\teventsFile: join(root, \"events.jsonl\"),\n\t};\n}\n\n/**\n * Stable per-repo slug for the lane-worktree checkout root: sanitized repo basename plus 8 hex of\n * sha256 over the REALPATH of the git common dir -- same-named repos in different places cannot\n * collide, and every worktree of one repo resolves the same slug.\n */\nexport function repoSlug(repoTopLevel: string, gitCommonDir: string): string {\n\tlet canonical = gitCommonDir;\n\ttry {\n\t\tcanonical = realpathSync(gitCommonDir);\n\t} catch {\n\t\t// Unresolvable (already-deleted repo during teardown): hash the raw path deterministically.\n\t}\n\tconst hash = createHash(\"sha256\").update(canonical).digest(\"hex\").slice(0, 8);\n\tconst base = basename(repoTopLevel)\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9-]+/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\t\t.slice(0, 48);\n\treturn `${base || \"repo\"}-${hash}`;\n}\n\nasync function readJsonFile<T>(filePath: string): Promise<T | undefined> {\n\tlet raw: string;\n\ttry {\n\t\traw = await fsPromises.readFile(filePath, \"utf-8\");\n\t} catch {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\treturn JSON.parse(raw) as T;\n\t} catch {\n\t\t// Corrupt store files are treated as absent -- git remains the truth and reconcile rebuilds.\n\t\treturn undefined;\n\t}\n}\n\nexport async function readEpoch(paths: SyncStorePaths): Promise<WorktreeSyncEpoch | undefined> {\n\treturn readJsonFile<WorktreeSyncEpoch>(paths.epochFile);\n}\n\nexport async function writeEpoch(paths: SyncStorePaths, epoch: WorktreeSyncEpoch): Promise<void> {\n\tawait writeFileAtomic(paths.epochFile, `${JSON.stringify(epoch, null, \"\\t\")}\\n`);\n}\n\nexport async function readLandingTransaction(paths: SyncStorePaths): Promise<LandingTransaction | undefined> {\n\tconst value = await readJsonFile<unknown>(paths.landingTransactionFile);\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, unknown>;\n\tif (\n\t\ttypeof record.laneKey !== \"string\" ||\n\t\ttypeof record.priorMainSha !== \"string\" ||\n\t\ttypeof record.testedTipSha !== \"string\" ||\n\t\t!Array.isArray(record.changedPaths) ||\n\t\t!record.changedPaths.every((path) => typeof path === \"string\") ||\n\t\ttypeof record.changedPathsTruncated !== \"boolean\" ||\n\t\ttypeof record.lockToken !== \"string\" ||\n\t\t(record.gate !== \"passed\" && record.gate !== \"off\") ||\n\t\t(record.stage !== \"ready_to_merge\" &&\n\t\t\trecord.stage !== \"main_moved\" &&\n\t\t\trecord.stage !== \"epoch_written\" &&\n\t\t\trecord.stage !== \"audit_logged\")\n\t) {\n\t\treturn undefined;\n\t}\n\treturn record as unknown as LandingTransaction;\n}\n\nexport async function writeLandingTransaction(paths: SyncStorePaths, transaction: LandingTransaction): Promise<void> {\n\tawait writeFileAtomic(paths.landingTransactionFile, `${JSON.stringify(transaction, null, \"\\t\")}\\n`);\n}\n\nexport async function clearLandingTransaction(paths: SyncStorePaths): Promise<void> {\n\ttry {\n\t\tawait fsPromises.unlink(paths.landingTransactionFile);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t}\n}\n\nfunction laneFile(paths: SyncStorePaths, laneKey: string): string {\n\treturn join(paths.lanesDir, `${laneKey}.json`);\n}\n\nexport async function readLane(paths: SyncStorePaths, laneKey: string): Promise<LaneRegistration | undefined> {\n\treturn readJsonFile<LaneRegistration>(laneFile(paths, laneKey));\n}\n\nexport async function writeLane(paths: SyncStorePaths, lane: LaneRegistration): Promise<void> {\n\tawait writeFileAtomic(laneFile(paths, lane.laneKey), `${JSON.stringify(lane, null, \"\\t\")}\\n`);\n}\n\nexport async function listLanes(paths: SyncStorePaths): Promise<LaneRegistration[]> {\n\tlet entries: string[];\n\ttry {\n\t\tentries = await fsPromises.readdir(paths.lanesDir);\n\t} catch {\n\t\treturn [];\n\t}\n\tconst lanes: LaneRegistration[] = [];\n\tfor (const entry of entries.sort()) {\n\t\tif (!entry.endsWith(\".json\")) continue;\n\t\tconst lane = await readJsonFile<LaneRegistration>(join(paths.lanesDir, entry));\n\t\tif (lane?.laneKey) lanes.push(lane);\n\t}\n\treturn lanes;\n}\n\n/** Append one audit event as a single JSON line. `at` is stamped here so every event carries it. */\nexport async function appendAuditEvent(\n\tpaths: SyncStorePaths,\n\tevent: { event: string } & Record<string, unknown>,\n\tat: string,\n): Promise<void> {\n\tawait appendBoundedJsonLine(paths.eventsFile, { at, ...event }, WORKTREE_AUDIT_EVENT_LIMITS);\n}\n\nexport interface IntegrationLockDeps {\n\t/** Injectable liveness probe (deterministic tests). Default: same-host `process.kill(pid, 0)`. */\n\tisPidAlive?: (owner: IntegrationLockOwner) => boolean;\n\tnow?: () => string;\n\tnowMs?: () => number;\n}\n\n/** Same-host pid liveness. A foreign-host owner is ALWAYS treated as alive -- never taken over. */\nexport function defaultIsPidAlive(owner: IntegrationLockOwner): boolean {\n\tif (owner.hostname !== osHostname()) return true;\n\ttry {\n\t\tprocess.kill(owner.pid, 0);\n\t\treturn true;\n\t} catch (err) {\n\t\t// EPERM means the pid exists but belongs to another user -- alive. Only ESRCH is dead.\n\t\treturn (err as NodeJS.ErrnoException).code === \"EPERM\";\n\t}\n}\n\nasync function readLockOwner(paths: SyncStorePaths): Promise<IntegrationLockOwner | undefined> {\n\treturn readJsonFile<IntegrationLockOwner>(paths.lockOwnerFile);\n}\n\nasync function tryMkdirLock(paths: SyncStorePaths): Promise<boolean> {\n\ttry {\n\t\tawait fsPromises.mkdir(paths.lockDir, { recursive: false });\n\t\treturn true;\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\t// Parent `locks/` missing on first use: create it, then retry the ATOMIC non-recursive mkdir.\n\t\t\tawait fsPromises.mkdir(dirname(paths.lockDir), { recursive: true });\n\t\t\ttry {\n\t\t\t\tawait fsPromises.mkdir(paths.lockDir, { recursive: false });\n\t\t\t\treturn true;\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}\n\n/**\n * Acquire the single integration lock (G1: landing is serialized). Non-blocking: a held lock\n * returns `{acquired:false, holder, holderAlive}` immediately -- callers surface `lock_busy` and\n * retry on their own cadence rather than spinning here. Takeover happens ONLY when the recorded\n * owner is provably dead on this host (or the lock dir is ownerless and older than\n * {@link OWNERLESS_LOCK_STALE_MS}); every takeover is audited.\n */\nexport async function acquireIntegrationLock(\n\tpaths: SyncStorePaths,\n\towner: Omit<IntegrationLockOwner, \"acquiredAt\" | \"token\">,\n\tdeps: IntegrationLockDeps = {},\n): Promise<IntegrationLockAcquisition> {\n\treturn withFileLock(paths.lockGuardFile, async () => {\n\t\tconst now = deps.now ?? (() => new Date().toISOString());\n\t\tconst nowMs = deps.nowMs ?? (() => Date.now());\n\t\tconst isPidAlive = deps.isPidAlive ?? defaultIsPidAlive;\n\t\tfor (let attempt = 0; attempt < 2; attempt++) {\n\t\t\tif (await tryMkdirLock(paths)) {\n\t\t\t\tconst token = randomUUID();\n\t\t\t\tconst manifest: IntegrationLockOwner = { ...owner, token, acquiredAt: now() };\n\t\t\t\tawait fsPromises.writeFile(paths.lockOwnerFile, `${JSON.stringify(manifest)}\\n`, \"utf-8\");\n\t\t\t\tawait appendAuditEvent(\n\t\t\t\t\tpaths,\n\t\t\t\t\t{ event: \"lock_acquired\", ...(attempt > 0 ? { takeover: true } : {}) },\n\t\t\t\t\tnow(),\n\t\t\t\t);\n\t\t\t\treturn { acquired: true, takeover: attempt > 0, token };\n\t\t\t}\n\n\t\t\tconst holder = await readLockOwner(paths);\n\t\t\tif (holder) {\n\t\t\t\tif (isPidAlive(holder)) return { acquired: false, holder, holderAlive: true };\n\t\t\t} else {\n\t\t\t\t// Ownerless dir: a crash between mkdir and the owner write. Only stale ones are dead.\n\t\t\t\tlet dirMtimeMs: number | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tdirMtimeMs = (await fsPromises.stat(paths.lockDir)).mtimeMs;\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (nowMs() - dirMtimeMs < OWNERLESS_LOCK_STALE_MS) return { acquired: false, holderAlive: true };\n\t\t\t}\n\n\t\t\t// Metadata serialization makes the stale observation and directory removal one guarded\n\t\t\t// operation; a successor cannot be removed by a stale observer.\n\t\t\tawait fsPromises.rm(paths.lockDir, { recursive: true, force: true });\n\t\t\tawait appendAuditEvent(\n\t\t\t\tpaths,\n\t\t\t\t{\n\t\t\t\t\tevent: \"lock_takeover\",\n\t\t\t\t\t...(holder ? { deadOwnerPid: holder.pid, deadOwnerLaneKey: holder.laneKey } : {}),\n\t\t\t\t},\n\t\t\t\tnow(),\n\t\t\t);\n\t\t}\n\t\tconst holder = await readLockOwner(paths);\n\t\treturn { acquired: false, holder, holderAlive: holder ? isPidAlive(holder) : true };\n\t});\n}\n\nexport async function releaseIntegrationLock(\n\tpaths: SyncStorePaths,\n\ttoken: string,\n\tdeps: IntegrationLockDeps = {},\n): Promise<boolean> {\n\treturn withFileLock(paths.lockGuardFile, async () => {\n\t\tconst now = deps.now ?? (() => new Date().toISOString());\n\t\tconst holder = await readLockOwner(paths);\n\t\tif (!holder || holder.token !== token) return false;\n\t\tawait fsPromises.rm(paths.lockDir, { recursive: true, force: true });\n\t\tawait appendAuditEvent(paths, { event: \"lock_released\" }, now());\n\t\treturn true;\n\t});\n}\n\nexport async function readLockHolder(paths: SyncStorePaths): Promise<IntegrationLockOwner | undefined> {\n\treturn readLockOwner(paths);\n}\n"]}
@@ -9,9 +9,9 @@
9
9
  * git by the engine (`git-engine.ts`). A deleted or corrupt store is rebuildable via reconcile --
10
10
  * every reader here treats missing/corrupt files as "absent", never as an error.
11
11
  *
12
- * Writes are tmp+rename atomic (`util/atomic-file.ts`); the audit log is append-only single-line
13
- * JSON (O_APPEND, one line per event -- atomic enough for the small records involved). The
14
- * integration lock is a mkdir-atomic directory with an owner manifest: mkdir either succeeds
12
+ * Writes are tmp+rename atomic (`util/atomic-file.ts`); the audit log uses the shared bounded JSONL
13
+ * sink, which serializes concurrent writers and atomically rotates to its newest low-water tail.
14
+ * The integration lock is a mkdir-atomic directory with an owner manifest: mkdir either succeeds
15
15
  * (lock acquired) or fails EEXIST (held), with takeover ONLY for a provably-dead same-host owner.
16
16
  */
17
17
  import { createHash, randomUUID } from "node:crypto";
@@ -19,10 +19,16 @@ import { promises as fsPromises, realpathSync } from "node:fs";
19
19
  import { hostname as osHostname } from "node:os";
20
20
  import { basename, dirname, join } from "node:path";
21
21
  import { withFileLock, writeFileAtomic } from "../util/atomic-file.js";
22
+ import { appendBoundedJsonLine } from "../util/bounded-jsonl.js";
22
23
  /** Grace window after which an ownerless lock dir (crash between mkdir and owner write) counts as
23
24
  * dead and may be taken over. Fresh ownerless dirs are conservatively treated as held. */
24
25
  export const OWNERLESS_LOCK_STALE_MS = 30_000;
25
26
  const STORE_DIR_NAME = "pi-worktree-sync";
27
+ const WORKTREE_AUDIT_EVENT_LIMITS = {
28
+ maxBytes: 4 * 1024 * 1024,
29
+ targetBytes: Math.floor(4 * 1024 * 1024 * 0.75),
30
+ maxRecords: 10_000,
31
+ };
26
32
  export function syncStorePaths(gitCommonDir) {
27
33
  const root = join(gitCommonDir, STORE_DIR_NAME);
28
34
  return {
@@ -142,8 +148,7 @@ export async function listLanes(paths) {
142
148
  }
143
149
  /** Append one audit event as a single JSON line. `at` is stamped here so every event carries it. */
144
150
  export async function appendAuditEvent(paths, event, at) {
145
- await fsPromises.mkdir(dirname(paths.eventsFile), { recursive: true });
146
- await fsPromises.appendFile(paths.eventsFile, `${JSON.stringify({ at, ...event })}\n`, "utf-8");
151
+ await appendBoundedJsonLine(paths.eventsFile, { at, ...event }, WORKTREE_AUDIT_EVENT_LIMITS);
147
152
  }
148
153
  /** Same-host pid liveness. A foreign-host owner is ALWAYS treated as alive -- never taken over. */
149
154
  export function defaultIsPidAlive(owner) {
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/core/worktree-sync/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,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n * Lives under `<git-common-dir>/pi-worktree-sync/` -- all worktrees of a repository share the git\n * common dir, so the store is repo-scoped and cross-process by construction, survives `/reload`\n * and crashes, is invisible to `git status`, and needs no gitignore entry.\n *\n * The store is an INDEX, not the truth: freshness/dirtiness/progress are always re-derived from\n * git by the engine (`git-engine.ts`). A deleted or corrupt store is rebuildable via reconcile --\n * every reader here treats missing/corrupt files as \"absent\", never as an error.\n *\n * Writes are tmp+rename atomic (`util/atomic-file.ts`); the audit log is append-only single-line\n * JSON (O_APPEND, one line per event -- atomic enough for the small records involved). The\n * integration lock is a mkdir-atomic directory with an owner manifest: mkdir either succeeds\n * (lock acquired) or fails EEXIST (held), with takeover ONLY for a provably-dead same-host owner.\n */\n\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { promises as fsPromises, realpathSync } from \"node:fs\";\nimport { hostname as osHostname } from \"node:os\";\nimport { basename, dirname, join } from \"node:path\";\nimport { withFileLock, writeFileAtomic } from \"../util/atomic-file.ts\";\nimport type {\n\tIntegrationLockAcquisition,\n\tIntegrationLockOwner,\n\tLandingTransaction,\n\tLaneRegistration,\n\tWorktreeSyncEpoch,\n} from \"./codes.ts\";\n\nexport interface SyncStorePaths {\n\troot: string;\n\tepochFile: string;\n\tlandingTransactionFile: string;\n\tlanesDir: string;\n\tlockDir: string;\n\tlockOwnerFile: string;\n\tlockGuardFile: string;\n\tlifecycleLockFile: string;\n\teventsFile: string;\n}\n\n/** Grace window after which an ownerless lock dir (crash between mkdir and owner write) counts as\n * dead and may be taken over. Fresh ownerless dirs are conservatively treated as held. */\nexport const OWNERLESS_LOCK_STALE_MS = 30_000;\n\nconst STORE_DIR_NAME = \"pi-worktree-sync\";\n\nexport function syncStorePaths(gitCommonDir: string): SyncStorePaths {\n\tconst root = join(gitCommonDir, STORE_DIR_NAME);\n\treturn {\n\t\troot,\n\t\tepochFile: join(root, \"epoch.json\"),\n\t\tlandingTransactionFile: join(root, \"landing-transaction.json\"),\n\t\tlanesDir: join(root, \"lanes\"),\n\t\tlockDir: join(root, \"locks\", \"integration\"),\n\t\tlockOwnerFile: join(root, \"locks\", \"integration\", \"owner.json\"),\n\t\tlockGuardFile: join(root, \"locks\", \"integration-metadata\"),\n\t\tlifecycleLockFile: join(root, \"locks\", \"lifecycle\"),\n\t\teventsFile: join(root, \"events.jsonl\"),\n\t};\n}\n\n/**\n * Stable per-repo slug for the lane-worktree checkout root: sanitized repo basename plus 8 hex of\n * sha256 over the REALPATH of the git common dir -- same-named repos in different places cannot\n * collide, and every worktree of one repo resolves the same slug.\n */\nexport function repoSlug(repoTopLevel: string, gitCommonDir: string): string {\n\tlet canonical = gitCommonDir;\n\ttry {\n\t\tcanonical = realpathSync(gitCommonDir);\n\t} catch {\n\t\t// Unresolvable (already-deleted repo during teardown): hash the raw path deterministically.\n\t}\n\tconst hash = createHash(\"sha256\").update(canonical).digest(\"hex\").slice(0, 8);\n\tconst base = basename(repoTopLevel)\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9-]+/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\t\t.slice(0, 48);\n\treturn `${base || \"repo\"}-${hash}`;\n}\n\nasync function readJsonFile<T>(filePath: string): Promise<T | undefined> {\n\tlet raw: string;\n\ttry {\n\t\traw = await fsPromises.readFile(filePath, \"utf-8\");\n\t} catch {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\treturn JSON.parse(raw) as T;\n\t} catch {\n\t\t// Corrupt store files are treated as absent -- git remains the truth and reconcile rebuilds.\n\t\treturn undefined;\n\t}\n}\n\nexport async function readEpoch(paths: SyncStorePaths): Promise<WorktreeSyncEpoch | undefined> {\n\treturn readJsonFile<WorktreeSyncEpoch>(paths.epochFile);\n}\n\nexport async function writeEpoch(paths: SyncStorePaths, epoch: WorktreeSyncEpoch): Promise<void> {\n\tawait writeFileAtomic(paths.epochFile, `${JSON.stringify(epoch, null, \"\\t\")}\\n`);\n}\n\nexport async function readLandingTransaction(paths: SyncStorePaths): Promise<LandingTransaction | undefined> {\n\tconst value = await readJsonFile<unknown>(paths.landingTransactionFile);\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, unknown>;\n\tif (\n\t\ttypeof record.laneKey !== \"string\" ||\n\t\ttypeof record.priorMainSha !== \"string\" ||\n\t\ttypeof record.testedTipSha !== \"string\" ||\n\t\t!Array.isArray(record.changedPaths) ||\n\t\t!record.changedPaths.every((path) => typeof path === \"string\") ||\n\t\ttypeof record.changedPathsTruncated !== \"boolean\" ||\n\t\ttypeof record.lockToken !== \"string\" ||\n\t\t(record.gate !== \"passed\" && record.gate !== \"off\") ||\n\t\t(record.stage !== \"ready_to_merge\" &&\n\t\t\trecord.stage !== \"main_moved\" &&\n\t\t\trecord.stage !== \"epoch_written\" &&\n\t\t\trecord.stage !== \"audit_logged\")\n\t) {\n\t\treturn undefined;\n\t}\n\treturn record as unknown as LandingTransaction;\n}\n\nexport async function writeLandingTransaction(paths: SyncStorePaths, transaction: LandingTransaction): Promise<void> {\n\tawait writeFileAtomic(paths.landingTransactionFile, `${JSON.stringify(transaction, null, \"\\t\")}\\n`);\n}\n\nexport async function clearLandingTransaction(paths: SyncStorePaths): Promise<void> {\n\ttry {\n\t\tawait fsPromises.unlink(paths.landingTransactionFile);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t}\n}\n\nfunction laneFile(paths: SyncStorePaths, laneKey: string): string {\n\treturn join(paths.lanesDir, `${laneKey}.json`);\n}\n\nexport async function readLane(paths: SyncStorePaths, laneKey: string): Promise<LaneRegistration | undefined> {\n\treturn readJsonFile<LaneRegistration>(laneFile(paths, laneKey));\n}\n\nexport async function writeLane(paths: SyncStorePaths, lane: LaneRegistration): Promise<void> {\n\tawait writeFileAtomic(laneFile(paths, lane.laneKey), `${JSON.stringify(lane, null, \"\\t\")}\\n`);\n}\n\nexport async function listLanes(paths: SyncStorePaths): Promise<LaneRegistration[]> {\n\tlet entries: string[];\n\ttry {\n\t\tentries = await fsPromises.readdir(paths.lanesDir);\n\t} catch {\n\t\treturn [];\n\t}\n\tconst lanes: LaneRegistration[] = [];\n\tfor (const entry of entries.sort()) {\n\t\tif (!entry.endsWith(\".json\")) continue;\n\t\tconst lane = await readJsonFile<LaneRegistration>(join(paths.lanesDir, entry));\n\t\tif (lane?.laneKey) lanes.push(lane);\n\t}\n\treturn lanes;\n}\n\n/** Append one audit event as a single JSON line. `at` is stamped here so every event carries it. */\nexport async function appendAuditEvent(\n\tpaths: SyncStorePaths,\n\tevent: { event: string } & Record<string, unknown>,\n\tat: string,\n): Promise<void> {\n\tawait fsPromises.mkdir(dirname(paths.eventsFile), { recursive: true });\n\tawait fsPromises.appendFile(paths.eventsFile, `${JSON.stringify({ at, ...event })}\\n`, \"utf-8\");\n}\n\nexport interface IntegrationLockDeps {\n\t/** Injectable liveness probe (deterministic tests). Default: same-host `process.kill(pid, 0)`. */\n\tisPidAlive?: (owner: IntegrationLockOwner) => boolean;\n\tnow?: () => string;\n\tnowMs?: () => number;\n}\n\n/** Same-host pid liveness. A foreign-host owner is ALWAYS treated as alive -- never taken over. */\nexport function defaultIsPidAlive(owner: IntegrationLockOwner): boolean {\n\tif (owner.hostname !== osHostname()) return true;\n\ttry {\n\t\tprocess.kill(owner.pid, 0);\n\t\treturn true;\n\t} catch (err) {\n\t\t// EPERM means the pid exists but belongs to another user -- alive. Only ESRCH is dead.\n\t\treturn (err as NodeJS.ErrnoException).code === \"EPERM\";\n\t}\n}\n\nasync function readLockOwner(paths: SyncStorePaths): Promise<IntegrationLockOwner | undefined> {\n\treturn readJsonFile<IntegrationLockOwner>(paths.lockOwnerFile);\n}\n\nasync function tryMkdirLock(paths: SyncStorePaths): Promise<boolean> {\n\ttry {\n\t\tawait fsPromises.mkdir(paths.lockDir, { recursive: false });\n\t\treturn true;\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\t// Parent `locks/` missing on first use: create it, then retry the ATOMIC non-recursive mkdir.\n\t\t\tawait fsPromises.mkdir(dirname(paths.lockDir), { recursive: true });\n\t\t\ttry {\n\t\t\t\tawait fsPromises.mkdir(paths.lockDir, { recursive: false });\n\t\t\t\treturn true;\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}\n\n/**\n * Acquire the single integration lock (G1: landing is serialized). Non-blocking: a held lock\n * returns `{acquired:false, holder, holderAlive}` immediately -- callers surface `lock_busy` and\n * retry on their own cadence rather than spinning here. Takeover happens ONLY when the recorded\n * owner is provably dead on this host (or the lock dir is ownerless and older than\n * {@link OWNERLESS_LOCK_STALE_MS}); every takeover is audited.\n */\nexport async function acquireIntegrationLock(\n\tpaths: SyncStorePaths,\n\towner: Omit<IntegrationLockOwner, \"acquiredAt\" | \"token\">,\n\tdeps: IntegrationLockDeps = {},\n): Promise<IntegrationLockAcquisition> {\n\treturn withFileLock(paths.lockGuardFile, async () => {\n\t\tconst now = deps.now ?? (() => new Date().toISOString());\n\t\tconst nowMs = deps.nowMs ?? (() => Date.now());\n\t\tconst isPidAlive = deps.isPidAlive ?? defaultIsPidAlive;\n\t\tfor (let attempt = 0; attempt < 2; attempt++) {\n\t\t\tif (await tryMkdirLock(paths)) {\n\t\t\t\tconst token = randomUUID();\n\t\t\t\tconst manifest: IntegrationLockOwner = { ...owner, token, acquiredAt: now() };\n\t\t\t\tawait fsPromises.writeFile(paths.lockOwnerFile, `${JSON.stringify(manifest)}\\n`, \"utf-8\");\n\t\t\t\tawait appendAuditEvent(\n\t\t\t\t\tpaths,\n\t\t\t\t\t{ event: \"lock_acquired\", ...(attempt > 0 ? { takeover: true } : {}) },\n\t\t\t\t\tnow(),\n\t\t\t\t);\n\t\t\t\treturn { acquired: true, takeover: attempt > 0, token };\n\t\t\t}\n\n\t\t\tconst holder = await readLockOwner(paths);\n\t\t\tif (holder) {\n\t\t\t\tif (isPidAlive(holder)) return { acquired: false, holder, holderAlive: true };\n\t\t\t} else {\n\t\t\t\t// Ownerless dir: a crash between mkdir and the owner write. Only stale ones are dead.\n\t\t\t\tlet dirMtimeMs: number | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tdirMtimeMs = (await fsPromises.stat(paths.lockDir)).mtimeMs;\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (nowMs() - dirMtimeMs < OWNERLESS_LOCK_STALE_MS) return { acquired: false, holderAlive: true };\n\t\t\t}\n\n\t\t\t// Metadata serialization makes the stale observation and directory removal one guarded\n\t\t\t// operation; a successor cannot be removed by a stale observer.\n\t\t\tawait fsPromises.rm(paths.lockDir, { recursive: true, force: true });\n\t\t\tawait appendAuditEvent(\n\t\t\t\tpaths,\n\t\t\t\t{\n\t\t\t\t\tevent: \"lock_takeover\",\n\t\t\t\t\t...(holder ? { deadOwnerPid: holder.pid, deadOwnerLaneKey: holder.laneKey } : {}),\n\t\t\t\t},\n\t\t\t\tnow(),\n\t\t\t);\n\t\t}\n\t\tconst holder = await readLockOwner(paths);\n\t\treturn { acquired: false, holder, holderAlive: holder ? isPidAlive(holder) : true };\n\t});\n}\n\nexport async function releaseIntegrationLock(\n\tpaths: SyncStorePaths,\n\ttoken: string,\n\tdeps: IntegrationLockDeps = {},\n): Promise<boolean> {\n\treturn withFileLock(paths.lockGuardFile, async () => {\n\t\tconst now = deps.now ?? (() => new Date().toISOString());\n\t\tconst holder = await readLockOwner(paths);\n\t\tif (!holder || holder.token !== token) return false;\n\t\tawait fsPromises.rm(paths.lockDir, { recursive: true, force: true });\n\t\tawait appendAuditEvent(paths, { event: \"lock_released\" }, now());\n\t\treturn true;\n\t});\n}\n\nexport async function readLockHolder(paths: SyncStorePaths): Promise<IntegrationLockOwner | undefined> {\n\treturn readLockOwner(paths);\n}\n"]}
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/core/worktree-sync/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO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AAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACrE,MAAM,gBAAgB,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC;IAAA,CACZ,CAAC,CAAC;AAAA,CACH;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,KAAqB,EAA6C;IACtG,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAAA,CAC5B","sourcesContent":["/**\n * Worktree-sync on-disk store: coordination state shared by EVERY process working on one repo.\n *\n * Lives under `<git-common-dir>/pi-worktree-sync/` -- all worktrees of a repository share the git\n * common dir, so the store is repo-scoped and cross-process by construction, survives `/reload`\n * and crashes, is invisible to `git status`, and needs no gitignore entry.\n *\n * The store is an INDEX, not the truth: freshness/dirtiness/progress are always re-derived from\n * git by the engine (`git-engine.ts`). A deleted or corrupt store is rebuildable via reconcile --\n * every reader here treats missing/corrupt files as \"absent\", never as an error.\n *\n * Writes are tmp+rename atomic (`util/atomic-file.ts`); the audit log uses the shared bounded JSONL\n * sink, which serializes concurrent writers and atomically rotates to its newest low-water tail.\n * The integration lock is a mkdir-atomic directory with an owner manifest: mkdir either succeeds\n * (lock acquired) or fails EEXIST (held), with takeover ONLY for a provably-dead same-host owner.\n */\n\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { promises as fsPromises, realpathSync } from \"node:fs\";\nimport { hostname as osHostname } from \"node:os\";\nimport { basename, dirname, join } from \"node:path\";\nimport { withFileLock, writeFileAtomic } from \"../util/atomic-file.ts\";\nimport { appendBoundedJsonLine, type BoundedJsonlLimits } from \"../util/bounded-jsonl.ts\";\nimport type {\n\tIntegrationLockAcquisition,\n\tIntegrationLockOwner,\n\tLandingTransaction,\n\tLaneRegistration,\n\tWorktreeSyncEpoch,\n} from \"./codes.ts\";\n\nexport interface SyncStorePaths {\n\troot: string;\n\tepochFile: string;\n\tlandingTransactionFile: string;\n\tlanesDir: string;\n\tlockDir: string;\n\tlockOwnerFile: string;\n\tlockGuardFile: string;\n\tlifecycleLockFile: string;\n\teventsFile: string;\n}\n\n/** Grace window after which an ownerless lock dir (crash between mkdir and owner write) counts as\n * dead and may be taken over. Fresh ownerless dirs are conservatively treated as held. */\nexport const OWNERLESS_LOCK_STALE_MS = 30_000;\n\nconst STORE_DIR_NAME = \"pi-worktree-sync\";\nconst WORKTREE_AUDIT_EVENT_LIMITS: BoundedJsonlLimits = {\n\tmaxBytes: 4 * 1024 * 1024,\n\ttargetBytes: Math.floor(4 * 1024 * 1024 * 0.75),\n\tmaxRecords: 10_000,\n};\n\nexport function syncStorePaths(gitCommonDir: string): SyncStorePaths {\n\tconst root = join(gitCommonDir, STORE_DIR_NAME);\n\treturn {\n\t\troot,\n\t\tepochFile: join(root, \"epoch.json\"),\n\t\tlandingTransactionFile: join(root, \"landing-transaction.json\"),\n\t\tlanesDir: join(root, \"lanes\"),\n\t\tlockDir: join(root, \"locks\", \"integration\"),\n\t\tlockOwnerFile: join(root, \"locks\", \"integration\", \"owner.json\"),\n\t\tlockGuardFile: join(root, \"locks\", \"integration-metadata\"),\n\t\tlifecycleLockFile: join(root, \"locks\", \"lifecycle\"),\n\t\teventsFile: join(root, \"events.jsonl\"),\n\t};\n}\n\n/**\n * Stable per-repo slug for the lane-worktree checkout root: sanitized repo basename plus 8 hex of\n * sha256 over the REALPATH of the git common dir -- same-named repos in different places cannot\n * collide, and every worktree of one repo resolves the same slug.\n */\nexport function repoSlug(repoTopLevel: string, gitCommonDir: string): string {\n\tlet canonical = gitCommonDir;\n\ttry {\n\t\tcanonical = realpathSync(gitCommonDir);\n\t} catch {\n\t\t// Unresolvable (already-deleted repo during teardown): hash the raw path deterministically.\n\t}\n\tconst hash = createHash(\"sha256\").update(canonical).digest(\"hex\").slice(0, 8);\n\tconst base = basename(repoTopLevel)\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9-]+/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\t\t.slice(0, 48);\n\treturn `${base || \"repo\"}-${hash}`;\n}\n\nasync function readJsonFile<T>(filePath: string): Promise<T | undefined> {\n\tlet raw: string;\n\ttry {\n\t\traw = await fsPromises.readFile(filePath, \"utf-8\");\n\t} catch {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\treturn JSON.parse(raw) as T;\n\t} catch {\n\t\t// Corrupt store files are treated as absent -- git remains the truth and reconcile rebuilds.\n\t\treturn undefined;\n\t}\n}\n\nexport async function readEpoch(paths: SyncStorePaths): Promise<WorktreeSyncEpoch | undefined> {\n\treturn readJsonFile<WorktreeSyncEpoch>(paths.epochFile);\n}\n\nexport async function writeEpoch(paths: SyncStorePaths, epoch: WorktreeSyncEpoch): Promise<void> {\n\tawait writeFileAtomic(paths.epochFile, `${JSON.stringify(epoch, null, \"\\t\")}\\n`);\n}\n\nexport async function readLandingTransaction(paths: SyncStorePaths): Promise<LandingTransaction | undefined> {\n\tconst value = await readJsonFile<unknown>(paths.landingTransactionFile);\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, unknown>;\n\tif (\n\t\ttypeof record.laneKey !== \"string\" ||\n\t\ttypeof record.priorMainSha !== \"string\" ||\n\t\ttypeof record.testedTipSha !== \"string\" ||\n\t\t!Array.isArray(record.changedPaths) ||\n\t\t!record.changedPaths.every((path) => typeof path === \"string\") ||\n\t\ttypeof record.changedPathsTruncated !== \"boolean\" ||\n\t\ttypeof record.lockToken !== \"string\" ||\n\t\t(record.gate !== \"passed\" && record.gate !== \"off\") ||\n\t\t(record.stage !== \"ready_to_merge\" &&\n\t\t\trecord.stage !== \"main_moved\" &&\n\t\t\trecord.stage !== \"epoch_written\" &&\n\t\t\trecord.stage !== \"audit_logged\")\n\t) {\n\t\treturn undefined;\n\t}\n\treturn record as unknown as LandingTransaction;\n}\n\nexport async function writeLandingTransaction(paths: SyncStorePaths, transaction: LandingTransaction): Promise<void> {\n\tawait writeFileAtomic(paths.landingTransactionFile, `${JSON.stringify(transaction, null, \"\\t\")}\\n`);\n}\n\nexport async function clearLandingTransaction(paths: SyncStorePaths): Promise<void> {\n\ttry {\n\t\tawait fsPromises.unlink(paths.landingTransactionFile);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t}\n}\n\nfunction laneFile(paths: SyncStorePaths, laneKey: string): string {\n\treturn join(paths.lanesDir, `${laneKey}.json`);\n}\n\nexport async function readLane(paths: SyncStorePaths, laneKey: string): Promise<LaneRegistration | undefined> {\n\treturn readJsonFile<LaneRegistration>(laneFile(paths, laneKey));\n}\n\nexport async function writeLane(paths: SyncStorePaths, lane: LaneRegistration): Promise<void> {\n\tawait writeFileAtomic(laneFile(paths, lane.laneKey), `${JSON.stringify(lane, null, \"\\t\")}\\n`);\n}\n\nexport async function listLanes(paths: SyncStorePaths): Promise<LaneRegistration[]> {\n\tlet entries: string[];\n\ttry {\n\t\tentries = await fsPromises.readdir(paths.lanesDir);\n\t} catch {\n\t\treturn [];\n\t}\n\tconst lanes: LaneRegistration[] = [];\n\tfor (const entry of entries.sort()) {\n\t\tif (!entry.endsWith(\".json\")) continue;\n\t\tconst lane = await readJsonFile<LaneRegistration>(join(paths.lanesDir, entry));\n\t\tif (lane?.laneKey) lanes.push(lane);\n\t}\n\treturn lanes;\n}\n\n/** Append one audit event as a single JSON line. `at` is stamped here so every event carries it. */\nexport async function appendAuditEvent(\n\tpaths: SyncStorePaths,\n\tevent: { event: string } & Record<string, unknown>,\n\tat: string,\n): Promise<void> {\n\tawait appendBoundedJsonLine(paths.eventsFile, { at, ...event }, WORKTREE_AUDIT_EVENT_LIMITS);\n}\n\nexport interface IntegrationLockDeps {\n\t/** Injectable liveness probe (deterministic tests). Default: same-host `process.kill(pid, 0)`. */\n\tisPidAlive?: (owner: IntegrationLockOwner) => boolean;\n\tnow?: () => string;\n\tnowMs?: () => number;\n}\n\n/** Same-host pid liveness. A foreign-host owner is ALWAYS treated as alive -- never taken over. */\nexport function defaultIsPidAlive(owner: IntegrationLockOwner): boolean {\n\tif (owner.hostname !== osHostname()) return true;\n\ttry {\n\t\tprocess.kill(owner.pid, 0);\n\t\treturn true;\n\t} catch (err) {\n\t\t// EPERM means the pid exists but belongs to another user -- alive. Only ESRCH is dead.\n\t\treturn (err as NodeJS.ErrnoException).code === \"EPERM\";\n\t}\n}\n\nasync function readLockOwner(paths: SyncStorePaths): Promise<IntegrationLockOwner | undefined> {\n\treturn readJsonFile<IntegrationLockOwner>(paths.lockOwnerFile);\n}\n\nasync function tryMkdirLock(paths: SyncStorePaths): Promise<boolean> {\n\ttry {\n\t\tawait fsPromises.mkdir(paths.lockDir, { recursive: false });\n\t\treturn true;\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\t// Parent `locks/` missing on first use: create it, then retry the ATOMIC non-recursive mkdir.\n\t\t\tawait fsPromises.mkdir(dirname(paths.lockDir), { recursive: true });\n\t\t\ttry {\n\t\t\t\tawait fsPromises.mkdir(paths.lockDir, { recursive: false });\n\t\t\t\treturn true;\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}\n\n/**\n * Acquire the single integration lock (G1: landing is serialized). Non-blocking: a held lock\n * returns `{acquired:false, holder, holderAlive}` immediately -- callers surface `lock_busy` and\n * retry on their own cadence rather than spinning here. Takeover happens ONLY when the recorded\n * owner is provably dead on this host (or the lock dir is ownerless and older than\n * {@link OWNERLESS_LOCK_STALE_MS}); every takeover is audited.\n */\nexport async function acquireIntegrationLock(\n\tpaths: SyncStorePaths,\n\towner: Omit<IntegrationLockOwner, \"acquiredAt\" | \"token\">,\n\tdeps: IntegrationLockDeps = {},\n): Promise<IntegrationLockAcquisition> {\n\treturn withFileLock(paths.lockGuardFile, async () => {\n\t\tconst now = deps.now ?? (() => new Date().toISOString());\n\t\tconst nowMs = deps.nowMs ?? (() => Date.now());\n\t\tconst isPidAlive = deps.isPidAlive ?? defaultIsPidAlive;\n\t\tfor (let attempt = 0; attempt < 2; attempt++) {\n\t\t\tif (await tryMkdirLock(paths)) {\n\t\t\t\tconst token = randomUUID();\n\t\t\t\tconst manifest: IntegrationLockOwner = { ...owner, token, acquiredAt: now() };\n\t\t\t\tawait fsPromises.writeFile(paths.lockOwnerFile, `${JSON.stringify(manifest)}\\n`, \"utf-8\");\n\t\t\t\tawait appendAuditEvent(\n\t\t\t\t\tpaths,\n\t\t\t\t\t{ event: \"lock_acquired\", ...(attempt > 0 ? { takeover: true } : {}) },\n\t\t\t\t\tnow(),\n\t\t\t\t);\n\t\t\t\treturn { acquired: true, takeover: attempt > 0, token };\n\t\t\t}\n\n\t\t\tconst holder = await readLockOwner(paths);\n\t\t\tif (holder) {\n\t\t\t\tif (isPidAlive(holder)) return { acquired: false, holder, holderAlive: true };\n\t\t\t} else {\n\t\t\t\t// Ownerless dir: a crash between mkdir and the owner write. Only stale ones are dead.\n\t\t\t\tlet dirMtimeMs: number | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tdirMtimeMs = (await fsPromises.stat(paths.lockDir)).mtimeMs;\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (nowMs() - dirMtimeMs < OWNERLESS_LOCK_STALE_MS) return { acquired: false, holderAlive: true };\n\t\t\t}\n\n\t\t\t// Metadata serialization makes the stale observation and directory removal one guarded\n\t\t\t// operation; a successor cannot be removed by a stale observer.\n\t\t\tawait fsPromises.rm(paths.lockDir, { recursive: true, force: true });\n\t\t\tawait appendAuditEvent(\n\t\t\t\tpaths,\n\t\t\t\t{\n\t\t\t\t\tevent: \"lock_takeover\",\n\t\t\t\t\t...(holder ? { deadOwnerPid: holder.pid, deadOwnerLaneKey: holder.laneKey } : {}),\n\t\t\t\t},\n\t\t\t\tnow(),\n\t\t\t);\n\t\t}\n\t\tconst holder = await readLockOwner(paths);\n\t\treturn { acquired: false, holder, holderAlive: holder ? isPidAlive(holder) : true };\n\t});\n}\n\nexport async function releaseIntegrationLock(\n\tpaths: SyncStorePaths,\n\ttoken: string,\n\tdeps: IntegrationLockDeps = {},\n): Promise<boolean> {\n\treturn withFileLock(paths.lockGuardFile, async () => {\n\t\tconst now = deps.now ?? (() => new Date().toISOString());\n\t\tconst holder = await readLockOwner(paths);\n\t\tif (!holder || holder.token !== token) return false;\n\t\tawait fsPromises.rm(paths.lockDir, { recursive: true, force: true });\n\t\tawait appendAuditEvent(paths, { event: \"lock_released\" }, now());\n\t\treturn true;\n\t});\n}\n\nexport async function readLockHolder(paths: SyncStorePaths): Promise<IntegrationLockOwner | undefined> {\n\treturn readLockOwner(paths);\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -5,21 +5,31 @@ export { getAgentDir, VERSION } from "./config.ts";
5
5
  export { AgentSession, type AgentSessionConfig, type AgentSessionEvent, type AgentSessionEventListener, type ModelCycleResult, type ParsedSkillBlock, type PromptOptions, parseSkillBlock, type SessionStats, } from "./core/agent-session.ts";
6
6
  export { type ApiKeyCredential, type AuthCredential, type AuthStatus, AuthStorage, type AuthStorageBackend, FileAuthStorageBackend, InMemoryAuthStorageBackend, type OAuthCredential, } from "./core/auth-storage.ts";
7
7
  export { createEventBus, type EventBus, type EventBusController } from "./core/event-bus.ts";
8
- export type { AgentEndEvent, AgentStartEvent, AgentToolResult, AgentToolUpdateCallback, AppKeybinding, AutocompleteProviderFactory, BashToolCallEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, BeforeProviderRequestEvent, BeforeProviderRequestEventResult, BuildSystemPromptOptions, CompactOptions, ContextEvent, ContextUsage, CustomToolCallEvent, EditToolCallEvent, ExecOptions, ExecResult, Extension, ExtensionActions, ExtensionAPI, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFlag, ExtensionHandler, ExtensionRuntime, ExtensionShortcut, ExtensionUIContext, ExtensionUIDialogOptions, ExtensionWidgetOptions, FindToolCallEvent, GrepToolCallEvent, InputEvent, InputEventResult, InputSource, KeybindingsManager, LoadExtensionsResult, LsToolCallEvent, MessageRenderer, MessageRenderOptions, ProviderConfig, ProviderModelConfig, ReadToolCallEvent, RegisteredCommand, RegisteredTool, ResolvedCommand, SessionBeforeCompactEvent, SessionBeforeForkEvent, SessionBeforeSwitchEvent, SessionBeforeTreeEvent, SessionCompactEvent, SessionShutdownEvent, SessionStartEvent, SessionTreeEvent, SlashCommandInfo, SlashCommandSource, SourceInfo, TerminalInputHandler, ToolCallEvent, ToolCallEventResult, ToolDefinition, ToolExecutionMode, ToolInfo, ToolRenderResultOptions, ToolResultEvent, TurnEndEvent, TurnStartEvent, UserBashEvent, UserBashEventResult, WidgetPlacement, WorkingIndicatorOptions, WriteToolCallEvent, } from "./core/extensions/index.ts";
8
+ export type { AgentEndEvent, AgentStartEvent, AgentToolResult, AgentToolUpdateCallback, AppKeybinding, AutocompleteProviderFactory, BashToolCallEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, BeforeProviderRequestEvent, BeforeProviderRequestEventResult, BuildSystemPromptOptions, CompactOptions, ContextEvent, ContextUsage, CustomToolCallEvent, EditToolCallEvent, ExecOptions, ExecResult, Extension, ExtensionActions, ExtensionAPI, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFlag, ExtensionHandler, ExtensionRuntime, ExtensionShortcut, ExtensionStorage, ExtensionUIContext, ExtensionUIDialogOptions, ExtensionWidgetOptions, ExtensionWorkRunOptions, FindToolCallEvent, GrepToolCallEvent, InputEvent, InputEventResult, InputSource, KeybindingsManager, LoadExtensionsResult, LsToolCallEvent, MessageRenderer, MessageRenderOptions, ProviderConfig, ProviderModelConfig, ReadToolCallEvent, RegisteredCommand, RegisteredTool, ResolvedCommand, SessionBeforeCompactEvent, SessionBeforeForkEvent, SessionBeforeSwitchEvent, SessionBeforeTreeEvent, SessionCompactEvent, SessionShutdownEvent, SessionStartEvent, SessionTreeEvent, SlashCommandInfo, SlashCommandSource, SourceInfo, TerminalInputHandler, ToolCallEvent, ToolCallEventResult, ToolDefinition, ToolExecutionMode, ToolInfo, ToolRenderResultOptions, ToolResultEvent, TurnEndEvent, TurnStartEvent, UserBashEvent, UserBashEventResult, WidgetPlacement, WorkingIndicatorOptions, WriteToolCallEvent, } from "./core/extensions/index.ts";
9
9
  export { createExtensionRuntime, defineTool, discoverAndLoadExtensions, ExtensionRunner, isBashToolResult, isEditToolResult, isFindToolResult, isGrepToolResult, isLsToolResult, isReadToolResult, isToolCallEventType, isWriteToolResult, wrapRegisteredTool, wrapRegisteredTools, } from "./core/extensions/index.ts";
10
10
  export type { ReadonlyFooterDataProvider } from "./core/footer-data-provider.ts";
11
11
  export { appendRunRecord, type ConfidenceMode, type ConfidenceResult, cleanupImprovementSandbox, compareMetric, computeMadConfidence, createImprovementDecisionTool, createImprovementLoopTool, createImprovementSandbox, decideImprovement, exportImprovementSandboxPatch, type GitStatusEntry, type ImprovementDecision, type ImprovementDecisionInput, type ImprovementDecisionReason, type ImprovementDecisionResult, type ImprovementLoopConfig, type ImprovementLoopExec, type ImprovementLoopInitInput, type ImprovementLoopPaths, type ImprovementLoopRecordInput, type ImprovementLoopState, type ImprovementLoopStatusInput, type ImprovementLoopToolAction, type ImprovementLoopToolDetails, type ImprovementMeasurementCommandResult, type ImprovementMeasurementResult, type ImprovementRunRecord, type ImprovementSandboxCleanupInput, type ImprovementSandboxCreateInput, type ImprovementSandboxExportInput, type ImprovementSandboxRecord, improvementLoopPaths, initImprovementLoop, type LowConfidenceAction, type MetricComparison, type MetricDirection, median, medianAbsoluteDeviation, metricMapFromOutput, type OwnedDiscardPlan, type OwnedDiscardPlanInput, parseGitPorcelainStatus, parseMetricLines, planOwnedDiscard, readImprovementLoopState, readRunRecords, recordImprovementRun, runImprovementMeasurement, selectPrimaryMetric, serializeRunRecord, } from "./core/improvement-loop.ts";
12
12
  export { ModelRegistry } from "./core/model-registry.ts";
13
+ export * from "./core/orchestration/capability-gateway.ts";
14
+ export * from "./core/orchestration/contracts.ts";
15
+ export * from "./core/orchestration/event-store.ts";
16
+ export * from "./core/orchestration/model-binding.ts";
17
+ export * from "./core/orchestration/policy-compiler.ts";
18
+ export * from "./core/orchestration/profile-registry.ts";
19
+ export * from "./core/orchestration/profile-store.ts";
20
+ export * from "./core/orchestration/task-runtime.ts";
13
21
  export type { PackageManager, PathMetadata, ProgressCallback, ProgressEvent, ResolvedPaths, ResolvedResource, } from "./core/package-manager.ts";
14
22
  export { DefaultPackageManager } from "./core/package-manager.ts";
23
+ export { PI_ORCHESTRATION_AGENT_ID_ENV } from "./core/process-identity.ts";
15
24
  export { ACTIVE_TURN_TTL_MS, AUTO_RELOAD_COORDINATOR_TTL_MS, describeReloadSession, getPendingReloadBlockers, getReloadCoordinationDir, isReloadSessionProcessAlive, type PendingReloadBlockers, type ReloadBlockerOptions, type ReloadSessionRecord, } from "./core/reload-blockers.ts";
16
25
  export type { ResourceCollision, ResourceDiagnostic, ResourceLoader } from "./core/resource-loader.ts";
17
26
  export { DefaultResourceLoader, loadProjectContextFiles } from "./core/resource-loader.ts";
18
27
  export { mergeResourceProfileMap, mergeResourceProfileSettings, parseResourceProfileBlocks, parseResourceProfileInput, parseResourceProfileJson, stripResourceProfileBlocks, } from "./core/resource-profile-blocks.ts";
19
- export { AgentSessionRuntime, type AgentSessionRuntimeDiagnostic, type AgentSessionServices, type CreateAgentSessionFromServicesOptions, type CreateAgentSessionOptions, type CreateAgentSessionResult, type CreateAgentSessionRuntimeFactory, type CreateAgentSessionRuntimeResult, type CreateAgentSessionServicesOptions, createAgentSession, createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, createBashTool, createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, type PromptTemplate, } from "./core/sdk.ts";
28
+ export { AgentSessionRuntime, type AgentSessionRuntimeDiagnostic, type AgentSessionRuntimeResource, type AgentSessionServices, type AgentSessionSwitchOptions, type CreateAgentSessionFromServicesOptions, type CreateAgentSessionOptions, type CreateAgentSessionResult, type CreateAgentSessionRuntimeFactory, type CreateAgentSessionRuntimeResult, type CreateAgentSessionServicesOptions, createAgentSession, createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, createBashTool, createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, type PromptTemplate, SessionReplacementCallbackError, SessionReplacementRuntimeError, } from "./core/sdk.ts";
20
29
  export { type CompactionSettings, type DirectoryResourceProfileInfo, getDirectoryResourceProfileInfo, type ImageSettings, matchesResourceProfilePattern, type PackageSource, type ResourceProfileFilterSettings, type ResourceProfileKind, type ResourceProfileSettings, type RetrySettings, SettingsManager, type SettingsManagerCreateOptions, } from "./core/settings-manager.ts";
21
30
  export { formatSkillsForPrompt, type LoadSkillsFromDirOptions, type LoadSkillsResult, loadSkills, loadSkillsFromDir, type Skill, type SkillFrontmatter, } from "./core/skills.ts";
22
31
  export { createSyntheticSourceInfo } from "./core/source-info.ts";
32
+ export { type AskQuestion, type AskQuestionAnswer, AskQuestionDialog, type AskQuestionStopReason, type AskQuestionToolDetails, type AskQuestionToolInput, type AskQuestionToolOptions, createAskQuestionToolDefinition, } from "./core/tools/ask-question.ts";
23
33
  export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type BashToolDetails, type BashToolInput, type BashToolOptions, createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLocalBashOperations, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type EditOperations, type EditToolDetails, type EditToolInput, type EditToolOptions, type FindOperations, type FindToolDetails, type FindToolInput, type FindToolOptions, formatSize, type GrepOperations, type GrepToolDetails, type GrepToolInput, type GrepToolOptions, type LsOperations, type LsToolDetails, type LsToolInput, type LsToolOptions, type ReadOperations, type ReadToolDetails, type ReadToolInput, type ReadToolOptions, type ToolsOptions, type TruncationOptions, type TruncationResult, truncateHead, truncateLine, truncateTail, type WriteOperations, type WriteToolInput, type WriteToolOptions, withFileMutationQueue, } from "./core/tools/index.ts";
24
34
  export { jaccard, runSkillAudit, type SkillAuditReport, type SkillSummary, tokenize, } from "./core/tools/skill-audit.ts";
25
35
  export { hasProjectTrustInputs, type ProjectTrustDecision, ProjectTrustStore } from "./core/trust-manager.ts";
@@ -32,5 +42,5 @@ export { parseFrontmatter, stripFrontmatter } from "./utils/frontmatter.ts";
32
42
  export { convertToPng } from "./utils/image-convert.ts";
33
43
  export { formatDimensionNote, type ResizedImage, resizeImage } from "./utils/image-resize.ts";
34
44
  export { getShellConfig } from "./utils/shell.ts";
35
- export { type AcquireWorkRunOptions, acquireWorkRun, createWorkRunId, getProcessWorkRun, getWorkRoot, getWorkRunDir, getWorkTenantDir, PI_WORK_ROOT_ENV, pruneWorkTenant, type WorkRetentionOptions, type WorkRunLease, } from "./utils/work-directory.ts";
45
+ export { type AcquireWorkRunOptions, acquireWorkRun, assertPortablePathSegment, boundedWorkRetention, createWorkRunId, getProcessWorkRun, getWorkRoot, getWorkRunDir, getWorkTenantDir, PI_WORK_ROOT_ENV, pruneWorkTenant, type WorkRetentionOptions, type WorkRunLease, } from "./utils/work-directory.ts";
36
46
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,mBAAmB,EACnB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,sBAAsB,EACtB,8BAA8B,EAC9B,OAAO,EACP,2BAA2B,E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AE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACN,KAAK,qBAAqB,EAC1B,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,KAAK,oBAAoB,EACzB,KAAK,YAAY,GACjB,MAAM,2BAA2B,CAAC","sourcesContent":["// Core session management\n\nexport { convertToLlm } from \"@caupulican/pi-agent-core\";\n// Compaction\nexport {\n\ttype BranchPreparation,\n\ttype BranchSummaryEntry,\n\ttype BranchSummaryResult,\n\tbuildSessionContext,\n\ttype CollectEntriesResult,\n\ttype CompactionEntry,\n\ttype CompactionResult,\n\tCURRENT_SESSION_VERSION,\n\ttype CustomEntry,\n\ttype CustomMessageEntry,\n\ttype CutPointResult,\n\tcalculateContextTokens,\n\tcollectEntriesForBranchSummary,\n\tcompact,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateTokens,\n\ttype FileEntry,\n\ttype FileOperations,\n\tfindCutPoint,\n\tfindTurnStartIndex,\n\ttype GenerateBranchSummaryOptions,\n\tgenerateBranchSummary,\n\tgenerateSummary,\n\tgetLastAssistantUsage,\n\tgetLatestCompactionEntry,\n\ttype ModelChangeEntry,\n\tmigrateSessionEntries,\n\ttype NewSessionOptions,\n\tparseSessionEntries,\n\tprepareBranchEntries,\n\ttype SessionContext,\n\ttype SessionEntry,\n\ttype SessionEntryBase,\n\ttype SessionHeader,\n\ttype SessionInfo,\n\ttype SessionInfoEntry,\n\tSessionManager,\n\ttype SessionMessageEntry,\n\tserializeConversation,\n\tshouldCompact,\n\ttype ThinkingLevelChangeEntry,\n} from \"@caupulican/pi-agent-core/node\";\nexport { type Args, parseArgs } from \"./cli/args.ts\";\n// Config paths\nexport { getAgentDir, VERSION } from \"./config.ts\";\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype ModelCycleResult,\n\ttype ParsedSkillBlock,\n\ttype PromptOptions,\n\tparseSkillBlock,\n\ttype SessionStats,\n} from \"./core/agent-session.ts\";\n// Auth and model registry\nexport {\n\ttype ApiKeyCredential,\n\ttype AuthCredential,\n\ttype AuthStatus,\n\tAuthStorage,\n\ttype AuthStorageBackend,\n\tFileAuthStorageBackend,\n\tInMemoryAuthStorageBackend,\n\ttype OAuthCredential,\n} from \"./core/auth-storage.ts\";\nexport { createEventBus, type EventBus, type EventBusController } from \"./core/event-bus.ts\";\n// Extension system\nexport type {\n\tAgentEndEvent,\n\tAgentStartEvent,\n\tAgentToolResult,\n\tAgentToolUpdateCallback,\n\tAppKeybinding,\n\tAutocompleteProviderFactory,\n\tBashToolCallEvent,\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tBeforeProviderRequestEvent,\n\tBeforeProviderRequestEventResult,\n\tBuildSystemPromptOptions,\n\tCompactOptions,\n\tContextEvent,\n\tContextUsage,\n\tCustomToolCallEvent,\n\tEditToolCallEvent,\n\tExecOptions,\n\tExecResult,\n\tExtension,\n\tExtensionActions,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionCommandContextActions,\n\tExtensionContext,\n\tExtensionContextActions,\n\tExtensionError,\n\tExtensionEvent,\n\tExtensionFactory,\n\tExtensionFlag,\n\tExtensionHandler,\n\tExtensionRuntime,\n\tExtensionShortcut,\n\tExtensionUIContext,\n\tExtensionUIDialogOptions,\n\tExtensionWidgetOptions,\n\tFindToolCallEvent,\n\tGrepToolCallEvent,\n\tInputEvent,\n\tInputEventResult,\n\tInputSource,\n\tKeybindingsManager,\n\tLoadExtensionsResult,\n\tLsToolCallEvent,\n\tMessageRenderer,\n\tMessageRenderOptions,\n\tProviderConfig,\n\tProviderModelConfig,\n\tReadToolCallEvent,\n\tRegisteredCommand,\n\tRegisteredTool,\n\tResolvedCommand,\n\tSessionBeforeCompactEvent,\n\tSessionBeforeForkEvent,\n\tSessionBeforeSwitchEvent,\n\tSessionBeforeTreeEvent,\n\tSessionCompactEvent,\n\tSessionShutdownEvent,\n\tSessionStartEvent,\n\tSessionTreeEvent,\n\tSlashCommandInfo,\n\tSlashCommandSource,\n\tSourceInfo,\n\tTerminalInputHandler,\n\tToolCallEvent,\n\tToolCallEventResult,\n\tToolDefinition,\n\tToolExecutionMode,\n\tToolInfo,\n\tToolRenderResultOptions,\n\tToolResultEvent,\n\tTurnEndEvent,\n\tTurnStartEvent,\n\tUserBashEvent,\n\tUserBashEventResult,\n\tWidgetPlacement,\n\tWorkingIndicatorOptions,\n\tWriteToolCallEvent,\n} from \"./core/extensions/index.ts\";\nexport {\n\tcreateExtensionRuntime,\n\tdefineTool,\n\tdiscoverAndLoadExtensions,\n\tExtensionRunner,\n\tisBashToolResult,\n\tisEditToolResult,\n\tisFindToolResult,\n\tisGrepToolResult,\n\tisLsToolResult,\n\tisReadToolResult,\n\tisToolCallEventType,\n\tisWriteToolResult,\n\twrapRegisteredTool,\n\twrapRegisteredTools,\n} from \"./core/extensions/index.ts\";\n// Footer data provider (git branch + extension statuses - data not otherwise available to extensions)\nexport type { ReadonlyFooterDataProvider } from \"./core/footer-data-provider.ts\";\nexport {\n\tappendRunRecord,\n\ttype ConfidenceMode,\n\ttype ConfidenceResult,\n\tcleanupImprovementSandbox,\n\tcompareMetric,\n\tcomputeMadConfidence,\n\tcreateImprovementDecisionTool,\n\tcreateImprovementLoopTool,\n\tcreateImprovementSandbox,\n\tdecideImprovement,\n\texportImprovementSandboxPatch,\n\ttype GitStatusEntry,\n\ttype ImprovementDecision,\n\ttype ImprovementDecisionInput,\n\ttype ImprovementDecisionReason,\n\ttype ImprovementDecisionResult,\n\ttype ImprovementLoopConfig,\n\ttype ImprovementLoopExec,\n\ttype ImprovementLoopInitInput,\n\ttype ImprovementLoopPaths,\n\ttype ImprovementLoopRecordInput,\n\ttype ImprovementLoopState,\n\ttype ImprovementLoopStatusInput,\n\ttype ImprovementLoopToolAction,\n\ttype ImprovementLoopToolDetails,\n\ttype ImprovementMeasurementCommandResult,\n\ttype ImprovementMeasurementResult,\n\ttype ImprovementRunRecord,\n\ttype ImprovementSandboxCleanupInput,\n\ttype ImprovementSandboxCreateInput,\n\ttype ImprovementSandboxExportInput,\n\ttype ImprovementSandboxRecord,\n\timprovementLoopPaths,\n\tinitImprovementLoop,\n\ttype LowConfidenceAction,\n\ttype MetricComparison,\n\ttype MetricDirection,\n\tmedian,\n\tmedianAbsoluteDeviation,\n\tmetricMapFromOutput,\n\ttype OwnedDiscardPlan,\n\ttype OwnedDiscardPlanInput,\n\tparseGitPorcelainStatus,\n\tparseMetricLines,\n\tplanOwnedDiscard,\n\treadImprovementLoopState,\n\treadRunRecords,\n\trecordImprovementRun,\n\trunImprovementMeasurement,\n\tselectPrimaryMetric,\n\tserializeRunRecord,\n} from \"./core/improvement-loop.ts\";\nexport { ModelRegistry } from \"./core/model-registry.ts\";\nexport type {\n\tPackageManager,\n\tPathMetadata,\n\tProgressCallback,\n\tProgressEvent,\n\tResolvedPaths,\n\tResolvedResource,\n} from \"./core/package-manager.ts\";\nexport { DefaultPackageManager } from \"./core/package-manager.ts\";\nexport {\n\tACTIVE_TURN_TTL_MS,\n\tAUTO_RELOAD_COORDINATOR_TTL_MS,\n\tdescribeReloadSession,\n\tgetPendingReloadBlockers,\n\tgetReloadCoordinationDir,\n\tisReloadSessionProcessAlive,\n\ttype PendingReloadBlockers,\n\ttype ReloadBlockerOptions,\n\ttype ReloadSessionRecord,\n} from \"./core/reload-blockers.ts\";\nexport type { ResourceCollision, ResourceDiagnostic, ResourceLoader } from \"./core/resource-loader.ts\";\nexport { DefaultResourceLoader, loadProjectContextFiles } from \"./core/resource-loader.ts\";\nexport {\n\tmergeResourceProfileMap,\n\tmergeResourceProfileSettings,\n\tparseResourceProfileBlocks,\n\tparseResourceProfileInput,\n\tparseResourceProfileJson,\n\tstripResourceProfileBlocks,\n} from \"./core/resource-profile-blocks.ts\";\n// SDK for programmatic usage\nexport {\n\tAgentSessionRuntime,\n\ttype AgentSessionRuntimeDiagnostic,\n\ttype AgentSessionServices,\n\ttype CreateAgentSessionFromServicesOptions,\n\ttype CreateAgentSessionOptions,\n\ttype CreateAgentSessionResult,\n\ttype CreateAgentSessionRuntimeFactory,\n\ttype CreateAgentSessionRuntimeResult,\n\ttype CreateAgentSessionServicesOptions,\n\t// Factory\n\tcreateAgentSession,\n\tcreateAgentSessionFromServices,\n\tcreateAgentSessionRuntime,\n\tcreateAgentSessionServices,\n\tcreateBashTool,\n\t// Tool factories (for custom cwd)\n\tcreateCodingTools,\n\tcreateEditTool,\n\tcreateFindTool,\n\tcreateGrepTool,\n\tcreateLsTool,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateWriteTool,\n\ttype PromptTemplate,\n} from \"./core/sdk.ts\";\nexport {\n\ttype CompactionSettings,\n\ttype DirectoryResourceProfileInfo,\n\tgetDirectoryResourceProfileInfo,\n\ttype ImageSettings,\n\tmatchesResourceProfilePattern,\n\ttype PackageSource,\n\ttype ResourceProfileFilterSettings,\n\ttype ResourceProfileKind,\n\ttype ResourceProfileSettings,\n\ttype RetrySettings,\n\tSettingsManager,\n\ttype SettingsManagerCreateOptions,\n} from \"./core/settings-manager.ts\";\n// Skills\nexport {\n\tformatSkillsForPrompt,\n\ttype LoadSkillsFromDirOptions,\n\ttype LoadSkillsResult,\n\tloadSkills,\n\tloadSkillsFromDir,\n\ttype Skill,\n\ttype SkillFrontmatter,\n} from \"./core/skills.ts\";\nexport { createSyntheticSourceInfo } from \"./core/source-info.ts\";\n// Tools\nexport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashToolDefinition,\n\tcreateEditToolDefinition,\n\tcreateFindToolDefinition,\n\tcreateGrepToolDefinition,\n\tcreateLocalBashOperations,\n\tcreateLsToolDefinition,\n\tcreateReadToolDefinition,\n\tcreateWriteToolDefinition,\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n\tformatSize,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n\ttype ToolsOptions,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n\ttype WriteOperations,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n\twithFileMutationQueue,\n} from \"./core/tools/index.ts\";\n// Skill-audit primitives — exported so extensions (e.g. continuous-learning) can reuse the native\n// Jaccard overlap audit via `import { runSkillAudit } from \"@caupulican/pi-adaptative\"` instead of\n// carrying a duplicate copy.\nexport {\n\tjaccard,\n\trunSkillAudit,\n\ttype SkillAuditReport,\n\ttype SkillSummary,\n\ttokenize,\n} from \"./core/tools/skill-audit.ts\";\nexport { hasProjectTrustInputs, type ProjectTrustDecision, ProjectTrustStore } from \"./core/trust-manager.ts\";\n// Main entry point\nexport { type MainOptions, main } from \"./main.ts\";\n// Run modes for programmatic SDK usage\nexport {\n\tInteractiveMode,\n\ttype InteractiveModeOptions,\n\ttype ModelInfo,\n\ttype PrintModeOptions,\n\tRpcClient,\n\ttype RpcClientOptions,\n\ttype RpcCommand,\n\ttype RpcEventListener,\n\ttype RpcResponse,\n\ttype RpcSessionState,\n\trunPrintMode,\n\trunRpcMode,\n} from \"./modes/index.ts\";\n// UI components for extensions\nexport {\n\tArminComponent,\n\tAssistantMessageComponent,\n\tBashExecutionComponent,\n\tBorderedLoader,\n\tBranchSummaryMessageComponent,\n\tCompactionSummaryMessageComponent,\n\tCustomEditor,\n\tCustomMessageComponent,\n\tDynamicBorder,\n\tExtensionEditorComponent,\n\tExtensionInputComponent,\n\tExtensionSelectorComponent,\n\tFooterComponent,\n\tkeyHint,\n\tkeyText,\n\tLoginDialogComponent,\n\tModelSelectorComponent,\n\tOAuthSelectorComponent,\n\ttype RenderDiffOptions,\n\trawKeyHint,\n\trenderDiff,\n\trenderTitleBadge,\n\trenderToolTitle,\n\tSessionSelectorComponent,\n\ttype SettingsCallbacks,\n\ttype SettingsConfig,\n\tSettingsSelectorComponent,\n\tShowImagesSelectorComponent,\n\tSkillInvocationMessageComponent,\n\tThemeSelectorComponent,\n\tThinkingSelectorComponent,\n\tTitleBadgeComponent,\n\ttype TitleBadgeOptions,\n\ttype TitleBadgeSegment,\n\ttype TitleBadgeStatus,\n\tToolExecutionComponent,\n\ttype ToolExecutionOptions,\n\tToolTitleComponent,\n\ttype ToolTitleOptions,\n\ttype ToolTitleSegment,\n\ttype ToolTitleStatus,\n\tTreeSelectorComponent,\n\ttitleBadge,\n\ttoolTitle,\n\ttruncateToVisualLines,\n\tUserMessageComponent,\n\tUserMessageSelectorComponent,\n\ttype VisualTruncateResult,\n} from \"./modes/interactive/components/index.ts\";\n// Theme utilities for custom tools and extensions\nexport {\n\tgetLanguageFromPath,\n\tgetMarkdownTheme,\n\tgetSelectListTheme,\n\tgetSettingsListTheme,\n\thighlightCode,\n\tinitTheme,\n\tTheme,\n\ttype ThemeColor,\n} from \"./modes/interactive/theme/theme.ts\";\n// Clipboard utilities\nexport { copyToClipboard } from \"./utils/clipboard.ts\";\nexport { parseFrontmatter, stripFrontmatter } from \"./utils/frontmatter.ts\";\nexport { convertToPng } from \"./utils/image-convert.ts\";\nexport { formatDimensionNote, type ResizedImage, resizeImage } from \"./utils/image-resize.ts\";\n// Shell utilities\nexport { getShellConfig } from \"./utils/shell.ts\";\nexport {\n\ttype AcquireWorkRunOptions,\n\tacquireWorkRun,\n\tcreateWorkRunId,\n\tgetProcessWorkRun,\n\tgetWorkRoot,\n\tgetWorkRunDir,\n\tgetWorkTenantDir,\n\tPI_WORK_ROOT_ENV,\n\tpruneWorkTenant,\n\ttype WorkRetentionOptions,\n\ttype WorkRunLease,\n} from \"./utils/work-directory.ts\";\n"]}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,mBAAmB,EACnB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,sBAAsB,EACtB,8BAA8B,EAC9B,OAAO,EACP,2BAA2B,EAC3B,cAAc,EACd,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,YAAY,EACZ,kBAAkB,EAClB,KAAK,4BAA4B,EACjC,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACrB,wBAAwB,EACxB,KAAK,gBAAgB,EACrB,qBAAqB,EACrB,KAAK,iBAAiB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,cAAc,EACd,KAAK,mBAAmB,EACxB,qBAAqB,EACrB,aAAa,EACb,KAAK,wBAAwB,GAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,KAAK,IAAI,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACN,YAAY,EACZ,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,aAA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B,EAChB,gBAAgB,EAChB,eAAe,EACf,KAAK,oBAAoB,EACzB,KAAK,YAAY,GACjB,MAAM,2BAA2B,CAAC","sourcesContent":["// Core session management\n\nexport { convertToLlm } from \"@caupulican/pi-agent-core\";\n// Compaction\nexport {\n\ttype BranchPreparation,\n\ttype BranchSummaryEntry,\n\ttype BranchSummaryResult,\n\tbuildSessionContext,\n\ttype CollectEntriesResult,\n\ttype CompactionEntry,\n\ttype CompactionResult,\n\tCURRENT_SESSION_VERSION,\n\ttype CustomEntry,\n\ttype CustomMessageEntry,\n\ttype CutPointResult,\n\tcalculateContextTokens,\n\tcollectEntriesForBranchSummary,\n\tcompact,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateTokens,\n\ttype FileEntry,\n\ttype FileOperations,\n\tfindCutPoint,\n\tfindTurnStartIndex,\n\ttype GenerateBranchSummaryOptions,\n\tgenerateBranchSummary,\n\tgenerateSummary,\n\tgetLastAssistantUsage,\n\tgetLatestCompactionEntry,\n\ttype ModelChangeEntry,\n\tmigrateSessionEntries,\n\ttype NewSessionOptions,\n\tparseSessionEntries,\n\tprepareBranchEntries,\n\ttype SessionContext,\n\ttype SessionEntry,\n\ttype SessionEntryBase,\n\ttype SessionHeader,\n\ttype SessionInfo,\n\ttype SessionInfoEntry,\n\tSessionManager,\n\ttype SessionMessageEntry,\n\tserializeConversation,\n\tshouldCompact,\n\ttype ThinkingLevelChangeEntry,\n} from \"@caupulican/pi-agent-core/node\";\nexport { type Args, parseArgs } from \"./cli/args.ts\";\n// Config paths\nexport { getAgentDir, VERSION } from \"./config.ts\";\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype ModelCycleResult,\n\ttype ParsedSkillBlock,\n\ttype PromptOptions,\n\tparseSkillBlock,\n\ttype SessionStats,\n} from \"./core/agent-session.ts\";\n// Auth and model registry\nexport {\n\ttype ApiKeyCredential,\n\ttype AuthCredential,\n\ttype AuthStatus,\n\tAuthStorage,\n\ttype AuthStorageBackend,\n\tFileAuthStorageBackend,\n\tInMemoryAuthStorageBackend,\n\ttype OAuthCredential,\n} from \"./core/auth-storage.ts\";\nexport { createEventBus, type EventBus, type EventBusController } from \"./core/event-bus.ts\";\n// Extension system\nexport type {\n\tAgentEndEvent,\n\tAgentStartEvent,\n\tAgentToolResult,\n\tAgentToolUpdateCallback,\n\tAppKeybinding,\n\tAutocompleteProviderFactory,\n\tBashToolCallEvent,\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tBeforeProviderRequestEvent,\n\tBeforeProviderRequestEventResult,\n\tBuildSystemPromptOptions,\n\tCompactOptions,\n\tContextEvent,\n\tContextUsage,\n\tCustomToolCallEvent,\n\tEditToolCallEvent,\n\tExecOptions,\n\tExecResult,\n\tExtension,\n\tExtensionActions,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionCommandContextActions,\n\tExtensionContext,\n\tExtensionContextActions,\n\tExtensionError,\n\tExtensionEvent,\n\tExtensionFactory,\n\tExtensionFlag,\n\tExtensionHandler,\n\tExtensionRuntime,\n\tExtensionShortcut,\n\tExtensionStorage,\n\tExtensionUIContext,\n\tExtensionUIDialogOptions,\n\tExtensionWidgetOptions,\n\tExtensionWorkRunOptions,\n\tFindToolCallEvent,\n\tGrepToolCallEvent,\n\tInputEvent,\n\tInputEventResult,\n\tInputSource,\n\tKeybindingsManager,\n\tLoadExtensionsResult,\n\tLsToolCallEvent,\n\tMessageRenderer,\n\tMessageRenderOptions,\n\tProviderConfig,\n\tProviderModelConfig,\n\tReadToolCallEvent,\n\tRegisteredCommand,\n\tRegisteredTool,\n\tResolvedCommand,\n\tSessionBeforeCompactEvent,\n\tSessionBeforeForkEvent,\n\tSessionBeforeSwitchEvent,\n\tSessionBeforeTreeEvent,\n\tSessionCompactEvent,\n\tSessionShutdownEvent,\n\tSessionStartEvent,\n\tSessionTreeEvent,\n\tSlashCommandInfo,\n\tSlashCommandSource,\n\tSourceInfo,\n\tTerminalInputHandler,\n\tToolCallEvent,\n\tToolCallEventResult,\n\tToolDefinition,\n\tToolExecutionMode,\n\tToolInfo,\n\tToolRenderResultOptions,\n\tToolResultEvent,\n\tTurnEndEvent,\n\tTurnStartEvent,\n\tUserBashEvent,\n\tUserBashEventResult,\n\tWidgetPlacement,\n\tWorkingIndicatorOptions,\n\tWriteToolCallEvent,\n} from \"./core/extensions/index.ts\";\nexport {\n\tcreateExtensionRuntime,\n\tdefineTool,\n\tdiscoverAndLoadExtensions,\n\tExtensionRunner,\n\tisBashToolResult,\n\tisEditToolResult,\n\tisFindToolResult,\n\tisGrepToolResult,\n\tisLsToolResult,\n\tisReadToolResult,\n\tisToolCallEventType,\n\tisWriteToolResult,\n\twrapRegisteredTool,\n\twrapRegisteredTools,\n} from \"./core/extensions/index.ts\";\n// Footer data provider (git branch + extension statuses - data not otherwise available to extensions)\nexport type { ReadonlyFooterDataProvider } from \"./core/footer-data-provider.ts\";\nexport {\n\tappendRunRecord,\n\ttype ConfidenceMode,\n\ttype ConfidenceResult,\n\tcleanupImprovementSandbox,\n\tcompareMetric,\n\tcomputeMadConfidence,\n\tcreateImprovementDecisionTool,\n\tcreateImprovementLoopTool,\n\tcreateImprovementSandbox,\n\tdecideImprovement,\n\texportImprovementSandboxPatch,\n\ttype GitStatusEntry,\n\ttype ImprovementDecision,\n\ttype ImprovementDecisionInput,\n\ttype ImprovementDecisionReason,\n\ttype ImprovementDecisionResult,\n\ttype ImprovementLoopConfig,\n\ttype ImprovementLoopExec,\n\ttype ImprovementLoopInitInput,\n\ttype ImprovementLoopPaths,\n\ttype ImprovementLoopRecordInput,\n\ttype ImprovementLoopState,\n\ttype ImprovementLoopStatusInput,\n\ttype ImprovementLoopToolAction,\n\ttype ImprovementLoopToolDetails,\n\ttype ImprovementMeasurementCommandResult,\n\ttype ImprovementMeasurementResult,\n\ttype ImprovementRunRecord,\n\ttype ImprovementSandboxCleanupInput,\n\ttype ImprovementSandboxCreateInput,\n\ttype ImprovementSandboxExportInput,\n\ttype ImprovementSandboxRecord,\n\timprovementLoopPaths,\n\tinitImprovementLoop,\n\ttype LowConfidenceAction,\n\ttype MetricComparison,\n\ttype MetricDirection,\n\tmedian,\n\tmedianAbsoluteDeviation,\n\tmetricMapFromOutput,\n\ttype OwnedDiscardPlan,\n\ttype OwnedDiscardPlanInput,\n\tparseGitPorcelainStatus,\n\tparseMetricLines,\n\tplanOwnedDiscard,\n\treadImprovementLoopState,\n\treadRunRecords,\n\trecordImprovementRun,\n\trunImprovementMeasurement,\n\tselectPrimaryMetric,\n\tserializeRunRecord,\n} from \"./core/improvement-loop.ts\";\nexport { ModelRegistry } from \"./core/model-registry.ts\";\nexport * from \"./core/orchestration/capability-gateway.ts\";\nexport * from \"./core/orchestration/contracts.ts\";\nexport * from \"./core/orchestration/event-store.ts\";\nexport * from \"./core/orchestration/model-binding.ts\";\nexport * from \"./core/orchestration/policy-compiler.ts\";\nexport * from \"./core/orchestration/profile-registry.ts\";\nexport * from \"./core/orchestration/profile-store.ts\";\nexport * from \"./core/orchestration/task-runtime.ts\";\nexport type {\n\tPackageManager,\n\tPathMetadata,\n\tProgressCallback,\n\tProgressEvent,\n\tResolvedPaths,\n\tResolvedResource,\n} from \"./core/package-manager.ts\";\nexport { DefaultPackageManager } from \"./core/package-manager.ts\";\nexport { PI_ORCHESTRATION_AGENT_ID_ENV } from \"./core/process-identity.ts\";\nexport {\n\tACTIVE_TURN_TTL_MS,\n\tAUTO_RELOAD_COORDINATOR_TTL_MS,\n\tdescribeReloadSession,\n\tgetPendingReloadBlockers,\n\tgetReloadCoordinationDir,\n\tisReloadSessionProcessAlive,\n\ttype PendingReloadBlockers,\n\ttype ReloadBlockerOptions,\n\ttype ReloadSessionRecord,\n} from \"./core/reload-blockers.ts\";\nexport type { ResourceCollision, ResourceDiagnostic, ResourceLoader } from \"./core/resource-loader.ts\";\nexport { DefaultResourceLoader, loadProjectContextFiles } from \"./core/resource-loader.ts\";\nexport {\n\tmergeResourceProfileMap,\n\tmergeResourceProfileSettings,\n\tparseResourceProfileBlocks,\n\tparseResourceProfileInput,\n\tparseResourceProfileJson,\n\tstripResourceProfileBlocks,\n} from \"./core/resource-profile-blocks.ts\";\n// SDK for programmatic usage\nexport {\n\tAgentSessionRuntime,\n\ttype AgentSessionRuntimeDiagnostic,\n\ttype AgentSessionRuntimeResource,\n\ttype AgentSessionServices,\n\ttype AgentSessionSwitchOptions,\n\ttype CreateAgentSessionFromServicesOptions,\n\ttype CreateAgentSessionOptions,\n\ttype CreateAgentSessionResult,\n\ttype CreateAgentSessionRuntimeFactory,\n\ttype CreateAgentSessionRuntimeResult,\n\ttype CreateAgentSessionServicesOptions,\n\t// Factory\n\tcreateAgentSession,\n\tcreateAgentSessionFromServices,\n\tcreateAgentSessionRuntime,\n\tcreateAgentSessionServices,\n\tcreateBashTool,\n\t// Tool factories (for custom cwd)\n\tcreateCodingTools,\n\tcreateEditTool,\n\tcreateFindTool,\n\tcreateGrepTool,\n\tcreateLsTool,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateWriteTool,\n\ttype PromptTemplate,\n\tSessionReplacementCallbackError,\n\tSessionReplacementRuntimeError,\n} from \"./core/sdk.ts\";\nexport {\n\ttype CompactionSettings,\n\ttype DirectoryResourceProfileInfo,\n\tgetDirectoryResourceProfileInfo,\n\ttype ImageSettings,\n\tmatchesResourceProfilePattern,\n\ttype PackageSource,\n\ttype ResourceProfileFilterSettings,\n\ttype ResourceProfileKind,\n\ttype ResourceProfileSettings,\n\ttype RetrySettings,\n\tSettingsManager,\n\ttype SettingsManagerCreateOptions,\n} from \"./core/settings-manager.ts\";\n// Skills\nexport {\n\tformatSkillsForPrompt,\n\ttype LoadSkillsFromDirOptions,\n\ttype LoadSkillsResult,\n\tloadSkills,\n\tloadSkillsFromDir,\n\ttype Skill,\n\ttype SkillFrontmatter,\n} from \"./core/skills.ts\";\nexport { createSyntheticSourceInfo } from \"./core/source-info.ts\";\nexport {\n\ttype AskQuestion,\n\ttype AskQuestionAnswer,\n\tAskQuestionDialog,\n\ttype AskQuestionStopReason,\n\ttype AskQuestionToolDetails,\n\ttype AskQuestionToolInput,\n\ttype AskQuestionToolOptions,\n\tcreateAskQuestionToolDefinition,\n} from \"./core/tools/ask-question.ts\";\n// Tools\nexport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashToolDefinition,\n\tcreateEditToolDefinition,\n\tcreateFindToolDefinition,\n\tcreateGrepToolDefinition,\n\tcreateLocalBashOperations,\n\tcreateLsToolDefinition,\n\tcreateReadToolDefinition,\n\tcreateWriteToolDefinition,\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n\tformatSize,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n\ttype ToolsOptions,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n\ttype WriteOperations,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n\twithFileMutationQueue,\n} from \"./core/tools/index.ts\";\n// Skill-audit primitives — exported so extensions (e.g. continuous-learning) can reuse the native\n// Jaccard overlap audit via `import { runSkillAudit } from \"@caupulican/pi-adaptative\"` instead of\n// carrying a duplicate copy.\nexport {\n\tjaccard,\n\trunSkillAudit,\n\ttype SkillAuditReport,\n\ttype SkillSummary,\n\ttokenize,\n} from \"./core/tools/skill-audit.ts\";\nexport { hasProjectTrustInputs, type ProjectTrustDecision, ProjectTrustStore } from \"./core/trust-manager.ts\";\n// Main entry point\nexport { type MainOptions, main } from \"./main.ts\";\n// Run modes for programmatic SDK usage\nexport {\n\tInteractiveMode,\n\ttype InteractiveModeOptions,\n\ttype ModelInfo,\n\ttype PrintModeOptions,\n\tRpcClient,\n\ttype RpcClientOptions,\n\ttype RpcCommand,\n\ttype RpcEventListener,\n\ttype RpcResponse,\n\ttype RpcSessionState,\n\trunPrintMode,\n\trunRpcMode,\n} from \"./modes/index.ts\";\n// UI components for extensions\nexport {\n\tArminComponent,\n\tAssistantMessageComponent,\n\tBashExecutionComponent,\n\tBorderedLoader,\n\tBranchSummaryMessageComponent,\n\tCompactionSummaryMessageComponent,\n\tCustomEditor,\n\tCustomMessageComponent,\n\tDynamicBorder,\n\tExtensionEditorComponent,\n\tExtensionInputComponent,\n\tExtensionSelectorComponent,\n\tFooterComponent,\n\tkeyHint,\n\tkeyText,\n\tLoginDialogComponent,\n\tModelSelectorComponent,\n\tOAuthSelectorComponent,\n\ttype RenderDiffOptions,\n\trawKeyHint,\n\trenderDiff,\n\trenderTitleBadge,\n\trenderToolTitle,\n\tSessionSelectorComponent,\n\ttype SettingsCallbacks,\n\ttype SettingsConfig,\n\tSettingsSelectorComponent,\n\tShowImagesSelectorComponent,\n\tSkillInvocationMessageComponent,\n\tThemeSelectorComponent,\n\tThinkingSelectorComponent,\n\tTitleBadgeComponent,\n\ttype TitleBadgeOptions,\n\ttype TitleBadgeSegment,\n\ttype TitleBadgeStatus,\n\tToolExecutionComponent,\n\ttype ToolExecutionOptions,\n\tToolTitleComponent,\n\ttype ToolTitleOptions,\n\ttype ToolTitleSegment,\n\ttype ToolTitleStatus,\n\tTreeSelectorComponent,\n\ttitleBadge,\n\ttoolTitle,\n\ttruncateToVisualLines,\n\tUserMessageComponent,\n\tUserMessageSelectorComponent,\n\ttype VisualTruncateResult,\n} from \"./modes/interactive/components/index.ts\";\n// Theme utilities for custom tools and extensions\nexport {\n\tgetLanguageFromPath,\n\tgetMarkdownTheme,\n\tgetSelectListTheme,\n\tgetSettingsListTheme,\n\thighlightCode,\n\tinitTheme,\n\tTheme,\n\ttype ThemeColor,\n} from \"./modes/interactive/theme/theme.ts\";\n// Clipboard utilities\nexport { copyToClipboard } from \"./utils/clipboard.ts\";\nexport { parseFrontmatter, stripFrontmatter } from \"./utils/frontmatter.ts\";\nexport { convertToPng } from \"./utils/image-convert.ts\";\nexport { formatDimensionNote, type ResizedImage, resizeImage } from \"./utils/image-resize.ts\";\n// Shell utilities\nexport { getShellConfig } from \"./utils/shell.ts\";\nexport {\n\ttype AcquireWorkRunOptions,\n\tacquireWorkRun,\n\tassertPortablePathSegment,\n\tboundedWorkRetention,\n\tcreateWorkRunId,\n\tgetProcessWorkRun,\n\tgetWorkRoot,\n\tgetWorkRunDir,\n\tgetWorkTenantDir,\n\tPI_WORK_ROOT_ENV,\n\tpruneWorkTenant,\n\ttype WorkRetentionOptions,\n\ttype WorkRunLease,\n} from \"./utils/work-directory.ts\";\n"]}
package/dist/index.js CHANGED
@@ -12,7 +12,16 @@ export { createEventBus } from "./core/event-bus.js";
12
12
  export { createExtensionRuntime, defineTool, discoverAndLoadExtensions, ExtensionRunner, isBashToolResult, isEditToolResult, isFindToolResult, isGrepToolResult, isLsToolResult, isReadToolResult, isToolCallEventType, isWriteToolResult, wrapRegisteredTool, wrapRegisteredTools, } from "./core/extensions/index.js";
13
13
  export { appendRunRecord, cleanupImprovementSandbox, compareMetric, computeMadConfidence, createImprovementDecisionTool, createImprovementLoopTool, createImprovementSandbox, decideImprovement, exportImprovementSandboxPatch, improvementLoopPaths, initImprovementLoop, median, medianAbsoluteDeviation, metricMapFromOutput, parseGitPorcelainStatus, parseMetricLines, planOwnedDiscard, readImprovementLoopState, readRunRecords, recordImprovementRun, runImprovementMeasurement, selectPrimaryMetric, serializeRunRecord, } from "./core/improvement-loop.js";
14
14
  export { ModelRegistry } from "./core/model-registry.js";
15
+ export * from "./core/orchestration/capability-gateway.js";
16
+ export * from "./core/orchestration/contracts.js";
17
+ export * from "./core/orchestration/event-store.js";
18
+ export * from "./core/orchestration/model-binding.js";
19
+ export * from "./core/orchestration/policy-compiler.js";
20
+ export * from "./core/orchestration/profile-registry.js";
21
+ export * from "./core/orchestration/profile-store.js";
22
+ export * from "./core/orchestration/task-runtime.js";
15
23
  export { DefaultPackageManager } from "./core/package-manager.js";
24
+ export { PI_ORCHESTRATION_AGENT_ID_ENV } from "./core/process-identity.js";
16
25
  export { ACTIVE_TURN_TTL_MS, AUTO_RELOAD_COORDINATOR_TTL_MS, describeReloadSession, getPendingReloadBlockers, getReloadCoordinationDir, isReloadSessionProcessAlive, } from "./core/reload-blockers.js";
17
26
  export { DefaultResourceLoader, loadProjectContextFiles } from "./core/resource-loader.js";
18
27
  export { mergeResourceProfileMap, mergeResourceProfileSettings, parseResourceProfileBlocks, parseResourceProfileInput, parseResourceProfileJson, stripResourceProfileBlocks, } from "./core/resource-profile-blocks.js";
@@ -21,11 +30,12 @@ export { AgentSessionRuntime,
21
30
  // Factory
22
31
  createAgentSession, createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, createBashTool,
23
32
  // Tool factories (for custom cwd)
24
- createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, } from "./core/sdk.js";
33
+ createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, SessionReplacementCallbackError, SessionReplacementRuntimeError, } from "./core/sdk.js";
25
34
  export { getDirectoryResourceProfileInfo, matchesResourceProfilePattern, SettingsManager, } from "./core/settings-manager.js";
26
35
  // Skills
27
36
  export { formatSkillsForPrompt, loadSkills, loadSkillsFromDir, } from "./core/skills.js";
28
37
  export { createSyntheticSourceInfo } from "./core/source-info.js";
38
+ export { AskQuestionDialog, createAskQuestionToolDefinition, } from "./core/tools/ask-question.js";
29
39
  // Tools
30
40
  export { createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLocalBashOperations, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead, truncateLine, truncateTail, withFileMutationQueue, } from "./core/tools/index.js";
31
41
  // Skill-audit primitives — exported so extensions (e.g. continuous-learning) can reuse the native
@@ -48,5 +58,5 @@ export { convertToPng } from "./utils/image-convert.js";
48
58
  export { formatDimensionNote, resizeImage } from "./utils/image-resize.js";
49
59
  // Shell utilities
50
60
  export { getShellConfig } from "./utils/shell.js";
51
- export { acquireWorkRun, createWorkRunId, getProcessWorkRun, getWorkRoot, getWorkRunDir, getWorkTenantDir, PI_WORK_ROOT_ENV, pruneWorkTenant, } from "./utils/work-directory.js";
61
+ export { acquireWorkRun, assertPortablePathSegment, boundedWorkRetention, createWorkRunId, getProcessWorkRun, getWorkRoot, getWorkRunDir, getWorkTenantDir, PI_WORK_ROOT_ENV, pruneWorkTenant, } from "./utils/work-directory.js";
52
62
  //# sourceMappingURL=index.js.map