pi-better-server 0.5.0 → 0.7.0

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 (340) hide show
  1. package/package.json +7 -3
  2. package/scripts/copy-pi-test-providers.mjs +10 -0
  3. package/scripts/event-publication/README.md +26 -0
  4. package/scripts/event-publication/commit.mjs +21 -0
  5. package/scripts/event-publication/measure.mjs +37 -5
  6. package/scripts/event-publication/writer.mjs +3 -8
  7. package/scripts/measure-full-runtime/frontend.ts +10 -2
  8. package/scripts/measure-full-runtime/probe.mjs +4 -2
  9. package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
  10. package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
  11. package/scripts/measure-full-runtime.mjs +2 -0
  12. package/scripts/measure-shared-reads.mjs +2 -1
  13. package/scripts/private-runtime/package-lock.json +18 -0
  14. package/scripts/private-runtime/package.json +4 -1
  15. package/scripts/source-provenance.mjs +2 -2
  16. package/scripts/test-on-pi.sh +2 -9
  17. package/src/handshake.ts +1 -1
  18. package/src/hosted-session.ts +32 -4
  19. package/src/maintenance.ts +35 -7
  20. package/src/registry.ts +28 -4
  21. package/src/runtime/attempt-invalidation.ts +54 -0
  22. package/src/runtime/background-history.ts +151 -45
  23. package/src/runtime/background-policy.ts +9 -4
  24. package/src/runtime/background-tools.ts +181 -27
  25. package/src/runtime/background.ts +365 -70
  26. package/src/runtime/cancellation.ts +28 -7
  27. package/src/runtime/catalog-sources.ts +199 -0
  28. package/src/runtime/catalog.ts +53 -21
  29. package/src/runtime/client.ts +22 -2
  30. package/src/runtime/domain/assignment-inbox.mjs +119 -0
  31. package/src/runtime/domain/assignment-observation.d.mts +1 -1
  32. package/src/runtime/domain/assignment-observation.mjs +43 -35
  33. package/src/runtime/domain/background/process-identity.mjs +20 -2
  34. package/src/runtime/domain/background/process.mjs +52 -14
  35. package/src/runtime/domain/background/registry.mjs +61 -3
  36. package/src/runtime/domain/background/supervisor/store.mjs +3 -3
  37. package/src/runtime/domain/background/supervisor/supervisor.mjs +9 -3
  38. package/src/runtime/domain/background/types.mjs +1 -0
  39. package/src/runtime/domain/background-service/adapter-contract.domain.mjs +1 -1
  40. package/src/runtime/domain/background-service/adapter-contract.ts +1 -1
  41. package/src/runtime/domain/background-service/goal-provider.domain.mjs +35 -16
  42. package/src/runtime/domain/background-service/goal-provider.ts +31 -16
  43. package/src/runtime/domain/background-service/index.domain.mjs +25 -9
  44. package/src/runtime/domain/background-service/index.ts +25 -9
  45. package/src/runtime/domain/background-service/managed-authority.domain.mjs +6 -3
  46. package/src/runtime/domain/background-service/managed-authority.ts +5 -3
  47. package/src/runtime/domain/background-service/managed-client.domain.mjs +21 -7
  48. package/src/runtime/domain/background-service/managed-client.ts +20 -7
  49. package/src/runtime/domain/background-service/managed-frontend.domain.mjs +159 -19
  50. package/src/runtime/domain/background-service/managed-frontend.ts +135 -19
  51. package/src/runtime/domain/background-service/navigator-provider.domain.mjs +21 -5
  52. package/src/runtime/domain/background-service/navigator-provider.ts +19 -5
  53. package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
  54. package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
  55. package/src/runtime/domain/background-service/observed-waits.domain.mjs +372 -57
  56. package/src/runtime/domain/background-service/observed-waits.ts +321 -53
  57. package/src/runtime/domain/background-service/process-identity.domain.mjs +20 -2
  58. package/src/runtime/domain/background-service/process-identity.ts +18 -2
  59. package/src/runtime/domain/background-service/process.domain.mjs +52 -14
  60. package/src/runtime/domain/background-service/process.ts +48 -14
  61. package/src/runtime/domain/background-service/registry.domain.mjs +61 -3
  62. package/src/runtime/domain/background-service/registry.ts +53 -5
  63. package/src/runtime/domain/background-service/review-settings.domain.mjs +16 -0
  64. package/src/runtime/domain/background-service/review-settings.ts +18 -0
  65. package/src/runtime/domain/background-service/runtime.domain.mjs +40 -86
  66. package/src/runtime/domain/background-service/runtime.ts +27 -82
  67. package/src/runtime/domain/background-service/sandbox.domain.mjs +14 -15
  68. package/src/runtime/domain/background-service/sandbox.ts +14 -11
  69. package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +8 -1
  70. package/src/runtime/domain/background-service/shared-callback-batcher.ts +11 -2
  71. package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +24 -2
  72. package/src/runtime/domain/background-service/shared-navigator-panels.ts +26 -4
  73. package/src/runtime/domain/background-service/shared-navigator.domain.mjs +273 -41
  74. package/src/runtime/domain/background-service/shared-navigator.ts +244 -40
  75. package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
  76. package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +53 -41
  77. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
  78. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
  79. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
  80. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
  81. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
  82. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +14 -3
  83. package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
  84. package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +5 -3
  85. package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +44 -4
  86. package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +50 -2
  87. package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
  88. package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +9 -0
  89. package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
  90. package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +12 -0
  91. package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +2 -0
  92. package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +2 -0
  93. package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +42 -21
  94. package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +40 -24
  95. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +26 -4
  96. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +40 -8
  97. package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
  98. package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +24 -1
  99. package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +1 -1
  100. package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +5 -1
  101. package/src/runtime/domain/background-service/shared-sandbox-core.ts +1 -1
  102. package/src/runtime/domain/background-service/shared-work-client.mjs +174 -7
  103. package/src/runtime/domain/background-service/stall.domain.mjs +5 -3
  104. package/src/runtime/domain/background-service/stall.ts +7 -4
  105. package/src/runtime/domain/background-service/supervised-progress.domain.mjs +42 -0
  106. package/src/runtime/domain/background-service/supervised-progress.ts +43 -0
  107. package/src/runtime/domain/background-service/supervisor/README.md +1 -4
  108. package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
  109. package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
  110. package/src/runtime/domain/background-service/supervisor/generated/process.mjs +52 -14
  111. package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +47 -4
  112. package/src/runtime/domain/background-service/supervisor/generated/store.mjs +3 -3
  113. package/src/runtime/domain/background-service/supervisor/generated/watch-fingerprint.mjs +69 -0
  114. package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +47 -4
  115. package/src/runtime/domain/background-service/supervisor/runner.ts +38 -3
  116. package/src/runtime/domain/background-service/supervisor/store.domain.mjs +3 -3
  117. package/src/runtime/domain/background-service/supervisor/store.ts +3 -3
  118. package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +9 -3
  119. package/src/runtime/domain/background-service/supervisor/supervisor.ts +6 -3
  120. package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +1 -1
  121. package/src/runtime/domain/background-service/task-diagnostics.ts +1 -1
  122. package/src/runtime/domain/background-service/tools.domain.mjs +53 -40
  123. package/src/runtime/domain/background-service/tools.ts +67 -54
  124. package/src/runtime/domain/background-service/types.domain.mjs +1 -0
  125. package/src/runtime/domain/background-service/types.ts +7 -3
  126. package/src/runtime/domain/background-service/watch-fingerprint.domain.mjs +67 -0
  127. package/src/runtime/domain/background-service/watch-fingerprint.ts +70 -0
  128. package/src/runtime/domain/background-service/work-observation.domain.mjs +46 -20
  129. package/src/runtime/domain/background-service/work-observation.ts +46 -19
  130. package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
  131. package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
  132. package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
  133. package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
  134. package/src/runtime/domain/coordinator/src/background-requests.mjs +11 -2
  135. package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
  136. package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
  137. package/src/runtime/domain/coordinator/src/outbox.mjs +7 -0
  138. package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
  139. package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
  140. package/src/runtime/domain/coordinator/src/schema.mjs +42 -21
  141. package/src/runtime/domain/coordinator/src/store.mjs +26 -4
  142. package/src/runtime/domain/coordinator/src/subagent-launch.mjs +23 -1
  143. package/src/runtime/domain/coordinator/src/types.mjs +1 -1
  144. package/src/runtime/domain/health-observation.d.mts +3 -1
  145. package/src/runtime/domain/health-observation.mjs +189 -190
  146. package/src/runtime/domain/log-cursor.d.mts +2 -0
  147. package/src/runtime/domain/log-cursor.mjs +85 -16
  148. package/src/runtime/domain/log-paths.mjs +8 -1
  149. package/src/runtime/domain/parse.d.mts +4 -1
  150. package/src/runtime/domain/parse.mjs +58 -9
  151. package/src/runtime/domain/sandbox-policy/README.md +63 -65
  152. package/src/runtime/domain/sandbox-policy/commands.domain.mjs +11 -8
  153. package/src/runtime/domain/sandbox-policy/commands.ts +12 -7
  154. package/src/runtime/domain/sandbox-policy/index.domain.mjs +53 -9
  155. package/src/runtime/domain/sandbox-policy/index.ts +52 -9
  156. package/src/runtime/domain/sandbox-policy/package.json +1 -1
  157. package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +5 -2
  158. package/src/runtime/domain/sandbox-policy/permission-settings.ts +9 -2
  159. package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +56 -137
  160. package/src/runtime/domain/sandbox-policy/permissions-page.ts +52 -130
  161. package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +1 -6
  162. package/src/runtime/domain/sandbox-policy/permissions.ts +1 -6
  163. package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1 -1
  164. package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +14 -1
  165. package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +12 -1
  166. package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
  167. package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
  168. package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +3 -2
  169. package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +8 -2
  170. package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +4 -3
  171. package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +5 -3
  172. package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +8 -5
  173. package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +8 -5
  174. package/src/runtime/domain/session-store.mjs +7 -0
  175. package/src/runtime/domain/subagents/README.md +13 -11
  176. package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +10 -7
  177. package/src/runtime/domain/subagents/assignment-outcomes.ts +9 -6
  178. package/src/runtime/domain/subagents/assignment-report.domain.mjs +109 -24
  179. package/src/runtime/domain/subagents/assignment-report.ts +103 -19
  180. package/src/runtime/domain/subagents/batch.mjs +13 -5
  181. package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +21 -3
  182. package/src/runtime/domain/subagents/catalog-host-admission.ts +19 -3
  183. package/src/runtime/domain/subagents/catalog-preferences.ts +1 -1
  184. package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +35 -1
  185. package/src/runtime/domain/subagents/catalog-resolver.ts +35 -1
  186. package/src/runtime/domain/subagents/catalog-store.domain.mjs +20 -22
  187. package/src/runtime/domain/subagents/catalog-store.ts +27 -20
  188. package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
  189. package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
  190. package/src/runtime/domain/subagents/child-dependencies.mjs +27 -15
  191. package/src/runtime/domain/subagents/child-operations.domain.mjs +80 -2
  192. package/src/runtime/domain/subagents/child-operations.ts +80 -1
  193. package/src/runtime/domain/subagents/child-preflight.mjs +9 -2
  194. package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
  195. package/src/runtime/domain/subagents/child-process-list.ts +8 -0
  196. package/src/runtime/domain/subagents/cleanup.domain.mjs +11 -2
  197. package/src/runtime/domain/subagents/cleanup.ts +10 -2
  198. package/src/runtime/domain/subagents/config.domain.mjs +54 -2
  199. package/src/runtime/domain/subagents/config.ts +53 -3
  200. package/src/runtime/domain/subagents/continuation-authority.domain.mjs +5 -1
  201. package/src/runtime/domain/subagents/continuation-authority.ts +3 -1
  202. package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
  203. package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
  204. package/src/runtime/domain/subagents/continuation.domain.mjs +4 -2
  205. package/src/runtime/domain/subagents/continuation.ts +4 -2
  206. package/src/runtime/domain/subagents/extensions.mjs +11 -13
  207. package/src/runtime/domain/subagents/failures.domain.mjs +11 -2
  208. package/src/runtime/domain/subagents/failures.ts +10 -2
  209. package/src/runtime/domain/subagents/finalization.domain.mjs +16 -1
  210. package/src/runtime/domain/subagents/finalization.ts +21 -1
  211. package/src/runtime/domain/subagents/goal-provider.domain.mjs +44 -2
  212. package/src/runtime/domain/subagents/goal-provider.ts +44 -2
  213. package/src/runtime/domain/subagents/health-observation.domain.mjs +189 -190
  214. package/src/runtime/domain/subagents/health-observation.ts +43 -48
  215. package/src/runtime/domain/subagents/index.domain.mjs +457 -182
  216. package/src/runtime/domain/subagents/index.ts +417 -155
  217. package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +515 -0
  218. package/src/runtime/domain/subagents/isolated-workspace.ts +557 -0
  219. package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
  220. package/src/runtime/domain/subagents/launch-context.ts +23 -0
  221. package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
  222. package/src/runtime/domain/subagents/list.mjs +2 -2
  223. package/src/runtime/domain/subagents/log-cursor.domain.mjs +85 -16
  224. package/src/runtime/domain/subagents/log-cursor.ts +91 -15
  225. package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +2 -2
  226. package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +27 -7
  227. package/src/runtime/domain/subagents/managed-launch-client.ts +28 -8
  228. package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +222 -14
  229. package/src/runtime/domain/subagents/managed-launch-host.ts +168 -15
  230. package/src/runtime/domain/subagents/managed-launch-journal.mjs +1 -5
  231. package/src/runtime/domain/subagents/managed-launch-port.ts +4 -0
  232. package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +27 -2
  233. package/src/runtime/domain/subagents/operation-bridge-types.ts +27 -2
  234. package/src/runtime/domain/subagents/output-payload.domain.mjs +24 -9
  235. package/src/runtime/domain/subagents/output-payload.ts +26 -12
  236. package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
  237. package/src/runtime/domain/subagents/owned-exit.ts +12 -0
  238. package/src/runtime/domain/subagents/package.json +4 -2
  239. package/src/runtime/domain/subagents/parse.domain.mjs +58 -9
  240. package/src/runtime/domain/subagents/parse.ts +57 -10
  241. package/src/runtime/domain/subagents/permission-policy.domain.mjs +32 -8
  242. package/src/runtime/domain/subagents/permission-policy.ts +41 -8
  243. package/src/runtime/domain/subagents/process-identity.mjs +33 -0
  244. package/src/runtime/domain/subagents/registry.domain.mjs +71 -51
  245. package/src/runtime/domain/subagents/registry.ts +77 -38
  246. package/src/runtime/domain/subagents/retained-result.domain.mjs +56 -0
  247. package/src/runtime/domain/subagents/retained-result.ts +65 -0
  248. package/src/runtime/domain/subagents/session-selection.domain.mjs +3 -1
  249. package/src/runtime/domain/subagents/session-selection.ts +2 -1
  250. package/src/runtime/domain/subagents/session-store.domain.mjs +7 -0
  251. package/src/runtime/domain/subagents/session-store.ts +9 -0
  252. package/src/runtime/domain/subagents/settings-page.domain.mjs +151 -107
  253. package/src/runtime/domain/subagents/settings-page.ts +147 -108
  254. package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +8 -1
  255. package/src/runtime/domain/subagents/shared-callback-batcher.ts +11 -2
  256. package/src/runtime/domain/subagents/shared-catalog.domain.mjs +28 -29
  257. package/src/runtime/domain/subagents/shared-catalog.ts +29 -21
  258. package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +24 -2
  259. package/src/runtime/domain/subagents/shared-navigator-panels.ts +26 -4
  260. package/src/runtime/domain/subagents/shared-navigator.domain.mjs +273 -41
  261. package/src/runtime/domain/subagents/shared-navigator.ts +244 -40
  262. package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
  263. package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +53 -41
  264. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
  265. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
  266. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
  267. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
  268. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
  269. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +14 -3
  270. package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
  271. package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +5 -3
  272. package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +44 -4
  273. package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +50 -2
  274. package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
  275. package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +9 -0
  276. package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
  277. package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +12 -0
  278. package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +2 -0
  279. package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +2 -0
  280. package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +42 -21
  281. package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +40 -24
  282. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +26 -4
  283. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +40 -8
  284. package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
  285. package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +24 -1
  286. package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +1 -1
  287. package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +5 -1
  288. package/src/runtime/domain/subagents/shared-sandbox-core.ts +1 -1
  289. package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +14 -1
  290. package/src/runtime/domain/subagents/shared-task-exec.ts +12 -1
  291. package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
  292. package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
  293. package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +3 -2
  294. package/src/runtime/domain/subagents/shared-task-process-list.ts +8 -2
  295. package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +4 -3
  296. package/src/runtime/domain/subagents/shared-task-sandbox.ts +5 -3
  297. package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +8 -5
  298. package/src/runtime/domain/subagents/shared-task-tools.ts +8 -5
  299. package/src/runtime/domain/subagents/shared-work-client.mjs +174 -7
  300. package/src/runtime/domain/subagents/subagent-tools.domain.mjs +22 -38
  301. package/src/runtime/domain/subagents/subagent-tools.ts +28 -34
  302. package/src/runtime/domain/subagents/task-guard.domain.mjs +14 -1
  303. package/src/runtime/domain/subagents/task-guard.ts +13 -1
  304. package/src/runtime/domain/subagents/task-policy.domain.mjs +3 -2
  305. package/src/runtime/domain/subagents/task-policy.ts +8 -2
  306. package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
  307. package/src/runtime/domain/subagents/timing.ts +10 -1
  308. package/src/runtime/domain/subagents/tools.domain.mjs +4 -8
  309. package/src/runtime/domain/subagents/tools.ts +4 -7
  310. package/src/runtime/domain/subagents/work-observation.domain.mjs +102 -17
  311. package/src/runtime/domain/subagents/work-observation.ts +91 -17
  312. package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +9 -4
  313. package/src/runtime/domain/subagents/worker-operations-host.ts +12 -4
  314. package/src/runtime/domain/subagents/worker-waits.domain.mjs +89 -35
  315. package/src/runtime/domain/subagents/worker-waits.ts +93 -34
  316. package/src/runtime/domain/subagents/workspace-files.domain.mjs +103 -0
  317. package/src/runtime/domain/subagents/workspace-files.ts +114 -0
  318. package/src/runtime/domain/subagents/workspace-scope.domain.d.mts +38 -0
  319. package/src/runtime/domain/subagents/workspace-scope.domain.mjs +5 -0
  320. package/src/runtime/domain/subagents/workspace-scope.ts +6 -0
  321. package/src/runtime/domain/subagents/worktree-feedback.domain.mjs +55 -0
  322. package/src/runtime/domain/subagents/worktree-feedback.ts +77 -0
  323. package/src/runtime/health-config.ts +27 -11
  324. package/src/runtime/log-checkpoints.ts +117 -0
  325. package/src/runtime/mutation-store.ts +5 -4
  326. package/src/runtime/queries.ts +25 -2
  327. package/src/runtime/query-executor.ts +149 -28
  328. package/src/runtime/query-worker.mjs +106 -21
  329. package/src/runtime/read-model.ts +849 -121
  330. package/src/runtime/read-watchdog-probe.ts +4 -0
  331. package/src/runtime/result-supervision.ts +188 -16
  332. package/src/runtime/root.ts +5 -2
  333. package/src/runtime/source-watch.ts +175 -0
  334. package/src/runtime/subagent-launch.ts +11 -4
  335. package/src/runtime/work-budget.ts +130 -0
  336. package/src/runtime/work-client.d.mts +8 -0
  337. package/src/runtime/work-client.mjs +150 -7
  338. package/src/server.ts +104 -23
  339. package/src/session-activity.ts +26 -4
  340. package/src/version.ts +1 -1
@@ -0,0 +1,88 @@
1
+ /** Select a saved, installed worker closure without changing the server owner. */
2
+ import { readFileSync, realpathSync, statSync } from "node:fs";
3
+ import { basename, dirname, join, normalize, sep } from "node:path";
4
+
5
+ const DOMAIN = join("src", "runtime", "domain", "subagents");
6
+ type Recipe = { runtimeRoot?: string; baseExtensionArgs?: readonly string[]; extensionArgs?: readonly string[] };
7
+ type Command = { file: string; fileArgs: string[] };
8
+
9
+ export function managedRuntimeRoot(domain: string): string | undefined {
10
+ if (!domain.endsWith(`${sep}${DOMAIN}`)) return undefined;
11
+ const root = domain.slice(0, -(DOMAIN.length + 1));
12
+ return basename(dirname(root)) === "releases" && /^[a-f0-9]{64}$/.test(basename(root)) ? root : undefined;
13
+ }
14
+
15
+ export interface ContinuationRuntime {
16
+ root: string;
17
+ mapPath(path: string): string;
18
+ mapArgs(args: readonly string[]): string[];
19
+ command(command: Command): Command;
20
+ }
21
+
22
+ /**
23
+ * Only sibling, published releases are eligible. User extensions retain their
24
+ * original identity check. Permission policy is still generated by the current
25
+ * server; a saved runtime does not grandfather its previous permission grants.
26
+ * Published releases are retained by the installer (it removes staging only).
27
+ * Any future release GC must treat LaunchRecipe.runtimeRoot as a reference.
28
+ */
29
+ export function selectContinuationRuntime(options: { currentDir: string; recipe?: Recipe }): ContinuationRuntime | undefined {
30
+ const current = managedRuntimeRoot(options.currentDir);
31
+ if (!current || !options.recipe) return undefined;
32
+ const recipe = options.recipe;
33
+ // Upgrade recipes written before runtimeRoot existed using the mandatory
34
+ // harness control, never a user-selected/custom extension path.
35
+ const args = recipe.baseExtensionArgs ?? recipe.extensionArgs ?? [];
36
+ const steer = args.find((value, index) => args[index - 1] === "--extension" && value.endsWith(`${sep}${DOMAIN}${sep}child-steer.ts`));
37
+ const saved = recipe.runtimeRoot ?? (steer ? managedRuntimeRoot(dirname(steer)) : undefined);
38
+ if (!saved || saved === current) return undefined;
39
+ const unavailable = (detail: string): never => {
40
+ throw new Error(`Cannot resume: saved runtime ${basename(saved)} unavailable (${detail}). Restore that release or explicitly launch a replacement conversation; no worker was started.`);
41
+ };
42
+ if (normalize(saved) !== saved || dirname(saved) !== dirname(current) || !/^[a-f0-9]{64}$/.test(basename(saved))) {
43
+ return unavailable("not a sibling managed release");
44
+ }
45
+ function manifest(root: string) {
46
+ let value;
47
+ try {
48
+ if (realpathSync(root) !== root) return unavailable("release path is not canonical");
49
+ value = JSON.parse(readFileSync(join(root, "runtime.json"), "utf8"));
50
+ } catch { return unavailable("missing or unreadable release manifest"); }
51
+ if (value.format !== 1 || value.root !== root || value.build?.contentId !== basename(root)
52
+ || value.node !== join(root, "node/bin/node") || value.installRoot !== dirname(dirname(root))) {
53
+ return unavailable("invalid release manifest");
54
+ }
55
+ return value;
56
+ }
57
+ const before = manifest(saved), now = manifest(current);
58
+ // These releases share the existing v1 worker admission/policy/bridge wire
59
+ // formats. Refuse SDK, Node, platform or protocol transitions rather than
60
+ // assuming that a new server can host any historic worker.
61
+ if (before.build.protocolVersion !== 1 || now.build.protocolVersion !== 1
62
+ || ["piSdkVersion", "nodeVersion", "platform"].some(key => !before.build[key] || before.build[key] !== now.build[key])) {
63
+ throw new Error(`Cannot resume: saved runtime ${basename(saved)} is incompatible with the current worker protocol, SDK or platform. Explicit replacement is required; no worker was started.`);
64
+ }
65
+ function required(path: string, directory = false): string {
66
+ try {
67
+ const stat = statSync(path);
68
+ if (realpathSync(path) !== path || !(stat.isFile() || directory && stat.isDirectory())) return unavailable("worker file is missing or redirected");
69
+ } catch { return unavailable("worker file is missing or unreadable"); }
70
+ return path;
71
+ }
72
+ const node = required(before.node);
73
+ const mapPath = (path: string): string => path.startsWith(`${current}${sep}`)
74
+ ? required(join(saved, path.slice(current.length + 1)), true) : path;
75
+ return {
76
+ root: saved,
77
+ mapPath,
78
+ mapArgs: values => values.map((value, index) => values[index - 1] === "--extension" ? mapPath(value) : value),
79
+ command: command => {
80
+ // Only executable slots are rewritten. A prompt or arbitrary CLI
81
+ // value that happens to contain a runtime path must stay untouched.
82
+ const fileArgs = [...command.fileArgs];
83
+ fileArgs[0] = mapPath(fileArgs[0]!);
84
+ if (basename(fileArgs[0]!) === "task-runtime.mjs") fileArgs[1] = mapPath(fileArgs[1]!);
85
+ return { file: node, fileArgs };
86
+ },
87
+ };
88
+ }
@@ -1,4 +1,5 @@
1
1
  // Generated fixed launch domain from packages/pi-better-subagents/continuation.ts. Do not edit directly.
2
+ import { hasWorkspaceCheckpoint } from "./isolated-workspace.domain.mjs";
2
3
  /**
3
4
  * Subagent continuation.
4
5
  *
@@ -452,7 +453,8 @@ export function planContinuation(options) {
452
453
  catch {
453
454
  workspaceIsDir = false;
454
455
  }
455
- if (!workspaceIsDir)
456
+ const recoverable = !workspaceIsDir && recipe.workspace && hasWorkspaceCheckpoint(recipe.workspace);
457
+ if (!workspaceIsDir && !recoverable)
456
458
  throw refusal(id, `its workspace ${recipe.cwd} is missing.`);
457
459
  if (recipe.sandboxDir !== undefined) {
458
460
  let sandboxIsDir = false;
@@ -462,7 +464,7 @@ export function planContinuation(options) {
462
464
  catch {
463
465
  sandboxIsDir = false;
464
466
  }
465
- if (!sandboxIsDir)
467
+ if (!sandboxIsDir && !recoverable)
466
468
  throw refusal(id, `its sandbox workspace ${recipe.sandboxDir} is missing.`);
467
469
  }
468
470
  const lookup = findSavedConversation({
@@ -1,3 +1,4 @@
1
+ import { hasWorkspaceCheckpoint } from "./isolated-workspace.ts";
1
2
  /**
2
3
  * Subagent continuation.
3
4
  *
@@ -536,11 +537,12 @@ export function planContinuation(options: {
536
537
 
537
538
  let workspaceIsDir = false;
538
539
  try { workspaceIsDir = statSync(recipe.cwd).isDirectory(); } catch { workspaceIsDir = false; }
539
- if (!workspaceIsDir) throw refusal(id, `its workspace ${recipe.cwd} is missing.`);
540
+ const recoverable = !workspaceIsDir && recipe.workspace && hasWorkspaceCheckpoint(recipe.workspace);
541
+ if (!workspaceIsDir && !recoverable) throw refusal(id, `its workspace ${recipe.cwd} is missing.`);
540
542
  if (recipe.sandboxDir !== undefined) {
541
543
  let sandboxIsDir = false;
542
544
  try { sandboxIsDir = statSync(recipe.sandboxDir).isDirectory(); } catch { sandboxIsDir = false; }
543
- if (!sandboxIsDir) throw refusal(id, `its sandbox workspace ${recipe.sandboxDir} is missing.`);
545
+ if (!sandboxIsDir && !recoverable) throw refusal(id, `its sandbox workspace ${recipe.sandboxDir} is missing.`);
544
546
  }
545
547
 
546
548
  const lookup: ConversationLookup = findSavedConversation({
@@ -34,7 +34,7 @@
34
34
  * A builtin needs no extension, so it never counts as unmapped.
35
35
  */
36
36
  // codemode is supplied by the harness child adapter, not a discovered package.
37
- export const BUILTIN_TOOLS = ["read", "bash", "edit", "write", "codemode"];
37
+ export const BUILTIN_TOOLS = ["read", "bash", "edit", "write", "grep", "find", "ls", "codemode"];
38
38
  /** Marker spec meaning "this extension's own package" (for allow_nested). */
39
39
  export const SELF_SPEC = "self";
40
40
  /**
@@ -87,11 +87,11 @@ export function toolList(tools) {
87
87
  * @returns {{mode: "isolated"|"clean"|"inherit", specs: string[], unmapped: string[], reasons: Record<string,string[]>}}
88
88
  * mode — "isolated" passes --no-extensions + explicit -e (the default);
89
89
  * "clean" passes --no-extensions with no -e;
90
- * "inherit" passes neither (operator opt-out, NOT model-selectable).
90
+ * "inherit" keeps discovery and adds explicitly selected mappings.
91
91
  * specs — extension specs to load, deduped, in a stable order.
92
92
  * unmapped — requested tools that are neither builtin nor mapped to an
93
- * extension. They simply will not exist in the child; surfaced so
94
- * the human sees it instead of the child silently lacking a tool.
93
+ * extension. Admission rejects a known missing required provider.
94
+ * Preflight verifies registrations supplied by loaded extensions.
95
95
  * reasons — spec -> what pulled it in, for the spawn diagnostic.
96
96
  */
97
97
  export function resolveExtensions(a = {}) {
@@ -107,13 +107,11 @@ export function resolveExtensions(a = {}) {
107
107
  };
108
108
  // allow_nested is honored in every mode: it is an explicit caller request,
109
109
  // and without our own package loaded the child has no subagent tools at all.
110
- if (a.allowNested)
110
+ const inherit = cfg.inheritExtensions === true;
111
+ if (a.allowNested && !inherit)
111
112
  add(SELF_SPEC, "allow_nested");
112
- if (cfg.inheritExtensions === true) {
113
- return { mode: "inherit", specs: [], unmapped: [], reasons: {} };
114
- }
115
113
  if (a.clean === true) {
116
- return { mode: "clean", specs, unmapped: [], reasons };
114
+ return { mode: inherit ? "inherit" : "clean", specs, unmapped: [], reasons };
117
115
  }
118
116
  const toolMap = cfg.toolExtensions ?? {};
119
117
  const unmapped = [];
@@ -122,13 +120,15 @@ export function resolveExtensions(a = {}) {
122
120
  continue;
123
121
  const mapped = toSpecList(toolMap[tool]);
124
122
  if (mapped.length === 0) {
125
- if (!unmapped.includes(tool))
123
+ if (!inherit && !unmapped.includes(tool))
126
124
  unmapped.push(tool);
127
125
  continue;
128
126
  }
129
127
  for (const spec of mapped)
130
128
  add(spec, `tool:${tool}`);
131
129
  }
130
+ if (inherit)
131
+ return { mode: "inherit", specs, unmapped, reasons };
132
132
  // Model auth is not tool-shaped: xai/grok needs pi-xai-oauth loaded or the
133
133
  // child cannot authenticate at all, whatever tools it was granted. A user
134
134
  // entry for a provider wins over the built-in one, including an empty list
@@ -150,9 +150,7 @@ export function resolveExtensions(a = {}) {
150
150
  * @returns {{args: string[], missing: string[]}}
151
151
  */
152
152
  export function extensionArgs(resolution, resolvePath) {
153
- if (resolution.mode === "inherit")
154
- return { args: [], missing: [] };
155
- const args = ["--no-extensions"];
153
+ const args = resolution.mode === "inherit" ? [] : ["--no-extensions"];
156
154
  const missing = [];
157
155
  for (const spec of resolution.specs) {
158
156
  const path = resolvePath(spec);
@@ -1,5 +1,6 @@
1
1
  // Generated fixed launch domain from packages/pi-better-subagents/failures.ts. Do not edit directly.
2
- import { closeSync, fstatSync, openSync, readSync } from "node:fs";
2
+ import { resultDir } from "./session-store.domain.mjs";
3
+ import { existsSync, closeSync, fstatSync, openSync, readSync } from "node:fs";
3
4
  import { join } from "node:path";
4
5
  import { logPathFor, runDir, taskRuntimeTrust } from "./registry.domain.mjs";
5
6
  import { activeFailures, actionableFailures, disposeIncidents, failureIdentity, findIncident, formatFailureSummary, formatTerminalFailureFacts, markFailureAttentionDelivered, observeFailures, pendingFailureAttention, readFailureState } from "./shared-failure-observations.domain.mjs";
@@ -16,7 +17,10 @@ const workerDiagnostics = new SandboxDiagnostics({ context: "worker",
16
17
  });
17
18
  export { formatFailureSummary, pendingFailureAttention, markFailureAttentionDelivered, toolOperation };
18
19
  export const failurePath = (id) => join(runDir(id), "failures.jsonl");
19
- export const readRunFailures = (id) => readFailureState(failurePath(id));
20
+ export function readRunFailures(id) {
21
+ const retained = !existsSync(runDir(id)) && resultDir(id);
22
+ return readFailureState(retained ? join(retained, "failures.jsonl") : failurePath(id));
23
+ }
20
24
  const scans = new Map();
21
25
  /** When each run's trust first could not be read, for the bounded wait (#325). */
22
26
  const trustUnknownSince = new Map();
@@ -176,6 +180,11 @@ function exactRuleLeftovers(path, prior) {
176
180
  /** Scan complete source records, independent of the finite progress/transcript tail. */
177
181
  export function collectRunFailures(id, cwd, terminal = false, assertCurrent = () => { }) {
178
182
  assertCurrent();
183
+ if (!existsSync(runDir(id))) {
184
+ const retained = resultDir(id);
185
+ if (retained && existsSync(join(retained, "result.json")))
186
+ return readRunFailures(id);
187
+ }
179
188
  const path = failurePath(id);
180
189
  let fd;
181
190
  try {
@@ -1,4 +1,5 @@
1
- import { closeSync, fstatSync, openSync, readSync } from "node:fs";
1
+ import { resultDir } from "./session-store.ts";
2
+ import { existsSync, closeSync, fstatSync, openSync, readSync } from "node:fs";
2
3
  import { join } from "node:path";
3
4
  import { logPathFor, runDir, taskRuntimeTrust } from "./registry.ts";
4
5
  import { activeFailures, actionableFailures, disposeIncidents, failureIdentity, findIncident, formatFailureSummary, formatTerminalFailureFacts, markFailureAttentionDelivered,
@@ -18,7 +19,10 @@ const workerDiagnostics = new SandboxDiagnostics({ context: "worker",
18
19
 
19
20
  export { formatFailureSummary, pendingFailureAttention, markFailureAttentionDelivered, toolOperation };
20
21
  export const failurePath = (id: string) => join(runDir(id), "failures.jsonl");
21
- export const readRunFailures = (id: string): FailureState => readFailureState(failurePath(id));
22
+ export function readRunFailures(id: string): FailureState {
23
+ const retained = !existsSync(runDir(id)) && resultDir(id);
24
+ return readFailureState(retained ? join(retained, "failures.jsonl") : failurePath(id));
25
+ }
22
26
  interface Scan {
23
27
  offset: number; head: string; identity: string; model: IncidentModel; retry?: number;
24
28
  /**
@@ -162,6 +166,10 @@ function exactRuleLeftovers(path: string, prior: FailureState): Set<string> {
162
166
  /** Scan complete source records, independent of the finite progress/transcript tail. */
163
167
  export function collectRunFailures(id: string, cwd: string, terminal = false, assertCurrent: () => void = () => {}): FailureState {
164
168
  assertCurrent();
169
+ if (!existsSync(runDir(id))) {
170
+ const retained = resultDir(id);
171
+ if (retained && existsSync(join(retained, "result.json"))) return readRunFailures(id);
172
+ }
165
173
  const path = failurePath(id);
166
174
  let fd: number;
167
175
  try { fd = openSync(logPathFor(id), "r"); }
@@ -15,6 +15,18 @@ import { parseRunForLifecycle } from "./parse.domain.mjs";
15
15
  import { canExitFinalize, effectiveStatus, isFinalResultStatus, readMeta, updateParkRecord, writeMeta, } from "./registry.domain.mjs";
16
16
  import { fmtElapsed, fmtSpend } from "./widget.domain.mjs";
17
17
  import { evaluateParkDisposition } from "./worker-waits.domain.mjs";
18
+ import { reconcileRun } from "./health.domain.mjs";
19
+ /** The current management owner calls this only for an interrupted, unobserved writer. */
20
+ export function reconcileInterruptedRun(meta, probe, now, hooks = {}) {
21
+ const reconciliation = reconcileRun(meta, probe, now);
22
+ if ((meta.status === "running" || meta.status === "orphaned") && meta.supervisionInterruptedAt !== undefined && reconciliation.status === "lost") {
23
+ const run = parseRunForLifecycle(meta.id);
24
+ if (run.sawEnd && run.unmatchedToolCalls.length === 0) {
25
+ return { reconciliation, finalization: finalizeRun(meta.id, null, { ...hooks, recoveredWriterExit: true }) };
26
+ }
27
+ }
28
+ return { reconciliation };
29
+ }
18
30
  /**
19
31
  * Finalize a run once its child exits. Idempotent: a run already marked
20
32
  * terminal is left alone. Persists lifecycle classification + failureReason
@@ -59,7 +71,10 @@ export function finalizeRun(id, code, hooks = {}) {
59
71
  // and the recorded wait is held for its owner.
60
72
  const park = evaluateParkDisposition({
61
73
  runId: id,
62
- cleanExit: code === 0 && !outcome.incomplete && !outcome.diagnostics.modelError,
74
+ // Preserve a verified staged checkpoint for post-restart park recovery.
75
+ // The coordinator still requires writer-exit and lease-release proof.
76
+ cleanExit: (code === 0 || (code === null && hooks.recoveredWriterExit === true))
77
+ && completed && !outcome.incomplete && !outcome.diagnostics.modelError,
63
78
  });
64
79
  const parked = park.parked && park.record !== undefined;
65
80
  if (parked && park.record) {
@@ -26,8 +26,11 @@ import {
26
26
  } from "./registry.ts";
27
27
  import { fmtElapsed, fmtSpend } from "./widget.ts";
28
28
  import { evaluateParkDisposition, type ParkDisposition } from "./worker-waits.ts";
29
+ import { reconcileRun, type ProcessProbe, type ReconcileResult } from "./health.ts";
29
30
 
30
31
  export interface FinalizeHooks {
32
+ /** Recovery proved the original writer gone; the exit observer was lost. */
33
+ recoveredWriterExit?: boolean;
31
34
  renderWidget?: () => void;
32
35
  notify?: (message: string, level: "info" | "warning") => void;
33
36
  sendMessage?: (
@@ -45,6 +48,20 @@ export interface FinalizeResult {
45
48
  park?: ParkDisposition;
46
49
  }
47
50
 
51
+ /** The current management owner calls this only for an interrupted, unobserved writer. */
52
+ export function reconcileInterruptedRun(meta: RunMeta, probe: ProcessProbe, now: number, hooks: FinalizeHooks = {}): {
53
+ reconciliation: ReconcileResult; finalization?: FinalizeResult;
54
+ } {
55
+ const reconciliation = reconcileRun(meta, probe, now);
56
+ if ((meta.status === "running" || meta.status === "orphaned") && meta.supervisionInterruptedAt !== undefined && reconciliation.status === "lost") {
57
+ const run = parseRunForLifecycle(meta.id);
58
+ if (run.sawEnd && run.unmatchedToolCalls.length === 0) {
59
+ return { reconciliation, finalization: finalizeRun(meta.id, null, { ...hooks, recoveredWriterExit: true }) };
60
+ }
61
+ }
62
+ return { reconciliation };
63
+ }
64
+
48
65
  /**
49
66
  * Finalize a run once its child exits. Idempotent: a run already marked
50
67
  * terminal is left alone. Persists lifecycle classification + failureReason
@@ -92,7 +109,10 @@ export function finalizeRun(
92
109
  // and the recorded wait is held for its owner.
93
110
  const park = evaluateParkDisposition({
94
111
  runId: id,
95
- cleanExit: code === 0 && !outcome.incomplete && !outcome.diagnostics.modelError,
112
+ // Preserve a verified staged checkpoint for post-restart park recovery.
113
+ // The coordinator still requires writer-exit and lease-release proof.
114
+ cleanExit: (code === 0 || (code === null && hooks.recoveredWriterExit === true))
115
+ && completed && !outcome.incomplete && !outcome.diagnostics.modelError,
96
116
  });
97
117
  const parked = park.parked && park.record !== undefined;
98
118
  if (parked && park.record) {
@@ -1,4 +1,5 @@
1
1
  // Generated fixed launch domain from packages/pi-better-subagents/goal-provider.ts. Do not edit directly.
2
+ import { activateWorkObservation, hasWorkObservationContext, workObservation, onWorkObservation } from "./work-observation.domain.mjs";
2
3
  import { belongsToOrigin, effectiveStatus, isPendingPark, listMetasForParent, onMetaChanged, readParkRecord, } from "./registry.domain.mjs";
3
4
  const GOAL_READY_EVENT = "pi-better-goal:ready";
4
5
  const GOAL_REGISTER_PROVIDER_EVENT = "pi-better-goal:register-provider";
@@ -30,13 +31,40 @@ function parkActivity(meta) {
30
31
  ...(record.resumedBy ? { resumedBy: record.resumedBy } : {}),
31
32
  };
32
33
  }
34
+ function observedActivity(observed, ctx) {
35
+ if (observed?.status !== "ready")
36
+ throw new Error(observed?.reason ?? "Subagent activity is unverified");
37
+ return {
38
+ providerId: "subagents", label: "Subagents", nextDeadline: observed.nextDeadline ?? null,
39
+ items: observed.rows.filter((row) => !ctx || (belongsToOrigin(row.meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() }) &&
40
+ (!row.meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === row.meta.callbackOrigin.branchId)))).map((row) => {
41
+ const status = row.assignment.state;
42
+ const active = status === "running" || status === "waiting";
43
+ return { id: row.meta.id, label: row.meta.name, status, active, terminal: !active,
44
+ attention: !active && status !== "completed", unhealthy: row.meta.status === "orphaned",
45
+ startedAt: row.meta.startedAt, endedAt: row.meta.endedAt,
46
+ details: { assignment: row.assignment, sourceRevision: row.sourceRevision } };
47
+ }),
48
+ };
49
+ }
33
50
  export function registerSubagentsGoalProvider(pi) {
34
51
  const emitProvider = () => {
35
52
  pi.events?.emit(GOAL_REGISTER_PROVIDER_EVENT, {
36
53
  id: "subagents",
37
54
  label: "Subagents",
38
55
  scope: "session",
39
- getActivity: (ctx) => {
56
+ activityVersion: 1,
57
+ getActivity: (ctx, options) => {
58
+ const observed = workObservation();
59
+ if (!observed && options?.cachedOnly) {
60
+ return { providerId: "subagents", coverage: "unverified", items: [], nextDeadline: null };
61
+ }
62
+ if (!observed && hasWorkObservationContext()) {
63
+ return activateWorkObservation().then(() => observedActivity(workObservation(), ctx));
64
+ }
65
+ if (observed) {
66
+ return observedActivity(observed, ctx);
67
+ }
40
68
  let sessionId;
41
69
  try {
42
70
  sessionId = ctx?.sessionManager?.getSessionId();
@@ -47,9 +75,11 @@ export function registerSubagentsGoalProvider(pi) {
47
75
  const origin = ctx ? { cwd: ctx.cwd, sessionId } : undefined;
48
76
  return {
49
77
  providerId: "subagents",
78
+ nextDeadline: null,
50
79
  label: "Subagents",
51
80
  items: listMetasForParent(process.pid)
52
81
  .filter((meta) => !origin || belongsToOrigin(meta, origin))
82
+ .filter((meta) => !ctx || !meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId))
53
83
  .map((meta) => {
54
84
  const status = effectiveStatus(meta);
55
85
  const active = status === "running" || status === "orphaned";
@@ -72,7 +102,19 @@ export function registerSubagentsGoalProvider(pi) {
72
102
  }),
73
103
  };
74
104
  },
75
- onActivityChanged: onMetaChanged,
105
+ onActivityChanged: (notify, ctx) => {
106
+ const offObservation = onWorkObservation(notify);
107
+ const offMeta = onMetaChanged((meta) => {
108
+ if (ctx && meta) {
109
+ if (!belongsToOrigin(meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() }))
110
+ return;
111
+ if (meta.callbackOrigin?.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId))
112
+ return;
113
+ }
114
+ notify();
115
+ });
116
+ return () => { offObservation(); offMeta(); };
117
+ },
76
118
  });
77
119
  };
78
120
  if (!goalReadySubscriptions.has(pi)) {
@@ -1,4 +1,5 @@
1
1
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import { activateWorkObservation, hasWorkObservationContext, workObservation, onWorkObservation } from "./work-observation.ts";
2
3
  import {
3
4
  belongsToOrigin,
4
5
  effectiveStatus,
@@ -38,13 +39,42 @@ function parkActivity(meta: Parameters<typeof effectiveStatus>[0]): Record<strin
38
39
  };
39
40
  }
40
41
 
42
+ function observedActivity(observed: any, ctx?: ExtensionContext) {
43
+ if (observed?.status !== "ready") throw new Error(observed?.reason ?? "Subagent activity is unverified");
44
+ return {
45
+ providerId: "subagents", label: "Subagents", nextDeadline: observed.nextDeadline ?? null,
46
+ items: observed.rows.filter((row: any) => !ctx || (
47
+ belongsToOrigin(row.meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() }) &&
48
+ (!row.meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === row.meta.callbackOrigin.branchId))
49
+ )).map((row: any) => {
50
+ const status = row.assignment.state;
51
+ const active = status === "running" || status === "waiting";
52
+ return { id: row.meta.id, label: row.meta.name, status, active, terminal: !active,
53
+ attention: !active && status !== "completed", unhealthy: row.meta.status === "orphaned",
54
+ startedAt: row.meta.startedAt, endedAt: row.meta.endedAt,
55
+ details: { assignment: row.assignment, sourceRevision: row.sourceRevision } };
56
+ }),
57
+ };
58
+ }
59
+
41
60
  export function registerSubagentsGoalProvider(pi: ExtensionAPI): void {
42
61
  const emitProvider = (): void => {
43
62
  pi.events?.emit(GOAL_REGISTER_PROVIDER_EVENT, {
44
63
  id: "subagents",
45
64
  label: "Subagents",
46
65
  scope: "session",
47
- getActivity: (ctx?: ExtensionContext) => {
66
+ activityVersion: 1,
67
+ getActivity: (ctx?: ExtensionContext, options?: { cachedOnly?: boolean }) => {
68
+ const observed = workObservation();
69
+ if (!observed && options?.cachedOnly) {
70
+ return { providerId: "subagents", coverage: "unverified", items: [], nextDeadline: null };
71
+ }
72
+ if (!observed && hasWorkObservationContext()) {
73
+ return activateWorkObservation().then(() => observedActivity(workObservation(), ctx));
74
+ }
75
+ if (observed) {
76
+ return observedActivity(observed, ctx);
77
+ }
48
78
  let sessionId: string | undefined;
49
79
  try {
50
80
  sessionId = ctx?.sessionManager?.getSessionId();
@@ -54,9 +84,11 @@ export function registerSubagentsGoalProvider(pi: ExtensionAPI): void {
54
84
  const origin = ctx ? { cwd: ctx.cwd, sessionId } : undefined;
55
85
  return {
56
86
  providerId: "subagents",
87
+ nextDeadline: null,
57
88
  label: "Subagents",
58
89
  items: listMetasForParent(process.pid)
59
90
  .filter((meta) => !origin || belongsToOrigin(meta, origin))
91
+ .filter((meta) => !ctx || !meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId))
60
92
  .map((meta) => {
61
93
  const status = effectiveStatus(meta);
62
94
  const active = status === "running" || status === "orphaned";
@@ -79,7 +111,17 @@ export function registerSubagentsGoalProvider(pi: ExtensionAPI): void {
79
111
  }),
80
112
  };
81
113
  },
82
- onActivityChanged: onMetaChanged,
114
+ onActivityChanged: (notify: () => void, ctx?: ExtensionContext) => {
115
+ const offObservation = onWorkObservation(notify);
116
+ const offMeta = onMetaChanged((meta) => {
117
+ if (ctx && meta) {
118
+ if (!belongsToOrigin(meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() })) return;
119
+ if (meta.callbackOrigin?.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId)) return;
120
+ }
121
+ notify();
122
+ });
123
+ return () => { offObservation(); offMeta(); };
124
+ },
83
125
  });
84
126
  };
85
127
  if (!goalReadySubscriptions.has(pi)) {