pi-better-server 0.4.0 → 0.6.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 (597) hide show
  1. package/package.json +8 -1
  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 +87 -0
  6. package/scripts/event-publication/writer.mjs +6 -0
  7. package/scripts/measure-full-runtime/frontend.ts +24 -0
  8. package/scripts/measure-full-runtime/hosted-extension.ts +28 -0
  9. package/scripts/measure-full-runtime/probe.mjs +29 -0
  10. package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
  11. package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
  12. package/scripts/measure-full-runtime.mjs +146 -0
  13. package/scripts/measure-shared-reads/probe.mjs +26 -2
  14. package/scripts/measure-shared-reads.mjs +44 -9
  15. package/scripts/private-runtime/package-lock.json +66 -4
  16. package/scripts/private-runtime/package.json +10 -2
  17. package/scripts/source-provenance.mjs +31 -0
  18. package/scripts/test-on-pi.sh +3 -9
  19. package/src/handshake.ts +1 -1
  20. package/src/hosted-session.ts +32 -4
  21. package/src/maintenance.ts +35 -7
  22. package/src/registry.ts +28 -4
  23. package/src/runtime/attempt-invalidation.ts +54 -0
  24. package/src/runtime/background-history.ts +151 -45
  25. package/src/runtime/background-policy.ts +27 -0
  26. package/src/runtime/background-tools.ts +389 -0
  27. package/src/runtime/background.ts +410 -48
  28. package/src/runtime/cancellation.ts +28 -7
  29. package/src/runtime/catalog-sources.ts +199 -0
  30. package/src/runtime/catalog.ts +53 -21
  31. package/src/runtime/client.ts +22 -2
  32. package/src/runtime/domain/assignment-inbox.mjs +119 -0
  33. package/src/runtime/domain/assignment-observation.d.mts +1 -1
  34. package/src/runtime/domain/assignment-observation.mjs +71 -33
  35. package/src/runtime/domain/background/process-identity.mjs +20 -2
  36. package/src/runtime/domain/background/process.mjs +3 -3
  37. package/src/runtime/domain/background/registry.mjs +89 -4
  38. package/src/runtime/domain/background/types.mjs +1 -0
  39. package/src/runtime/domain/background-service/adapter-contract.domain.mjs +83 -0
  40. package/src/runtime/domain/background-service/adapter-contract.ts +70 -0
  41. package/src/runtime/domain/background-service/batch.domain.mjs +91 -0
  42. package/src/runtime/domain/background-service/batch.ts +111 -0
  43. package/src/runtime/domain/background-service/conditions.domain.mjs +94 -0
  44. package/src/runtime/domain/background-service/conditions.ts +99 -0
  45. package/src/runtime/domain/background-service/delivery-observer.domain.mjs +37 -0
  46. package/src/runtime/domain/background-service/delivery-observer.ts +42 -0
  47. package/src/runtime/domain/background-service/failures.domain.mjs +209 -0
  48. package/src/runtime/domain/background-service/failures.ts +212 -0
  49. package/src/runtime/domain/background-service/goal-provider.domain.mjs +193 -0
  50. package/src/runtime/domain/background-service/goal-provider.ts +209 -0
  51. package/src/runtime/domain/background-service/index.domain.mjs +54 -0
  52. package/src/runtime/domain/background-service/index.ts +55 -0
  53. package/src/runtime/domain/background-service/logs.domain.mjs +129 -0
  54. package/src/runtime/domain/background-service/logs.ts +134 -0
  55. package/src/runtime/domain/background-service/maintenance.domain.mjs +95 -0
  56. package/src/runtime/domain/background-service/maintenance.ts +98 -0
  57. package/src/runtime/domain/background-service/managed-authority.domain.mjs +32 -0
  58. package/src/runtime/domain/background-service/managed-authority.ts +30 -0
  59. package/src/runtime/domain/background-service/managed-client.domain.mjs +79 -0
  60. package/src/runtime/domain/background-service/managed-client.ts +73 -0
  61. package/src/runtime/domain/background-service/managed-frontend.domain.mjs +225 -0
  62. package/src/runtime/domain/background-service/managed-frontend.ts +176 -0
  63. package/src/runtime/domain/background-service/navigator-provider.domain.mjs +492 -0
  64. package/src/runtime/domain/background-service/navigator-provider.ts +485 -0
  65. package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
  66. package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
  67. package/src/runtime/domain/background-service/observed-waits.domain.mjs +4080 -0
  68. package/src/runtime/domain/background-service/observed-waits.ts +4513 -0
  69. package/src/runtime/domain/background-service/output.domain.mjs +867 -0
  70. package/src/runtime/domain/background-service/output.ts +952 -0
  71. package/src/runtime/domain/background-service/process-identity.domain.mjs +129 -0
  72. package/src/runtime/domain/background-service/process-identity.ts +134 -0
  73. package/src/runtime/domain/background-service/process.domain.mjs +512 -0
  74. package/src/runtime/domain/background-service/process.ts +532 -0
  75. package/src/runtime/domain/background-service/prompt.domain.mjs +58 -0
  76. package/src/runtime/domain/background-service/prompt.ts +72 -0
  77. package/src/runtime/domain/background-service/registry.domain.mjs +460 -0
  78. package/src/runtime/domain/background-service/registry.ts +450 -0
  79. package/src/runtime/domain/background-service/remote-task-preset.domain.mjs +67 -0
  80. package/src/runtime/domain/background-service/remote-task-preset.ts +127 -0
  81. package/src/runtime/domain/background-service/runtime.domain.mjs +1511 -0
  82. package/src/runtime/domain/background-service/runtime.ts +1636 -0
  83. package/src/runtime/domain/background-service/sandbox.domain.mjs +735 -0
  84. package/src/runtime/domain/background-service/sandbox.ts +913 -0
  85. package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +777 -0
  86. package/src/runtime/domain/background-service/shared-callback-batcher.ts +956 -0
  87. package/src/runtime/domain/background-service/shared-execution-policy.domain.mjs +50 -0
  88. package/src/runtime/domain/background-service/shared-execution-policy.ts +61 -0
  89. package/src/runtime/domain/background-service/shared-failure-observations.domain.mjs +1078 -0
  90. package/src/runtime/domain/background-service/shared-failure-observations.ts +1166 -0
  91. package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +126 -0
  92. package/src/runtime/domain/background-service/shared-harness-settings.ts +116 -0
  93. package/src/runtime/domain/background-service/shared-log-utils.domain.mjs +1223 -0
  94. package/src/runtime/domain/background-service/shared-log-utils.ts +1492 -0
  95. package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +289 -0
  96. package/src/runtime/domain/background-service/shared-navigator-panels.ts +272 -0
  97. package/src/runtime/domain/background-service/shared-navigator.domain.mjs +1930 -0
  98. package/src/runtime/domain/background-service/shared-navigator.ts +1962 -0
  99. package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
  100. package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +189 -0
  101. package/src/runtime/domain/background-service/shared-operation-coordinator/index.domain.mjs +51 -0
  102. package/src/runtime/domain/background-service/shared-operation-coordinator/index.ts +122 -0
  103. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
  104. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
  105. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +163 -0
  106. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
  107. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
  108. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
  109. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
  110. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +90 -0
  111. package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
  112. package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +139 -0
  113. package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.domain.mjs +12 -0
  114. package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.ts +79 -0
  115. package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +342 -0
  116. package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +513 -0
  117. package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
  118. package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +458 -0
  119. package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
  120. package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.ts +55 -0
  121. package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
  122. package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +140 -0
  123. package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +280 -0
  124. package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +442 -0
  125. package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +420 -0
  126. package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +441 -0
  127. package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
  128. package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.ts +239 -0
  129. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +275 -0
  130. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +585 -0
  131. package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
  132. package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +142 -0
  133. package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
  134. package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.ts +224 -0
  135. package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +25 -0
  136. package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +707 -0
  137. package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
  138. package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.ts +22 -0
  139. package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.domain.mjs +234 -0
  140. package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.ts +241 -0
  141. package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +851 -0
  142. package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +1424 -0
  143. package/src/runtime/domain/background-service/shared-permission-blocker.domain.mjs +40 -0
  144. package/src/runtime/domain/background-service/shared-permission-blocker.ts +48 -0
  145. package/src/runtime/domain/background-service/shared-render-scheduler.domain.mjs +41 -0
  146. package/src/runtime/domain/background-service/shared-render-scheduler.ts +47 -0
  147. package/src/runtime/domain/background-service/shared-sandbox-core.domain.mjs +1531 -0
  148. package/src/runtime/domain/background-service/shared-sandbox-core.ts +1757 -0
  149. package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +591 -0
  150. package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +491 -0
  151. package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +698 -0
  152. package/src/runtime/domain/background-service/shared-ssh-core/index.ts +979 -0
  153. package/src/runtime/domain/background-service/shared-stall-detector.domain.mjs +37 -0
  154. package/src/runtime/domain/background-service/shared-stall-detector.ts +69 -0
  155. package/src/runtime/domain/background-service/shared-work-client.mjs +303 -0
  156. package/src/runtime/domain/background-service/stall-attention.domain.mjs +29 -0
  157. package/src/runtime/domain/background-service/stall-attention.ts +31 -0
  158. package/src/runtime/domain/background-service/stall.domain.mjs +57 -0
  159. package/src/runtime/domain/background-service/stall.ts +57 -0
  160. package/src/runtime/domain/background-service/supervisor/README.md +111 -0
  161. package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +90 -0
  162. package/src/runtime/domain/background-service/supervisor/generated/conditions.mjs +96 -0
  163. package/src/runtime/domain/background-service/supervisor/generated/identity.mjs +95 -0
  164. package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +131 -0
  165. package/src/runtime/domain/background-service/supervisor/generated/process.mjs +514 -0
  166. package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +872 -0
  167. package/src/runtime/domain/background-service/supervisor/generated/store.mjs +609 -0
  168. package/src/runtime/domain/background-service/supervisor/generated/types.mjs +50 -0
  169. package/src/runtime/domain/background-service/supervisor/identity.domain.mjs +93 -0
  170. package/src/runtime/domain/background-service/supervisor/identity.ts +99 -0
  171. package/src/runtime/domain/background-service/supervisor/index.domain.mjs +22 -0
  172. package/src/runtime/domain/background-service/supervisor/index.ts +37 -0
  173. package/src/runtime/domain/background-service/supervisor/invocation.domain.mjs +30 -0
  174. package/src/runtime/domain/background-service/supervisor/invocation.ts +44 -0
  175. package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +870 -0
  176. package/src/runtime/domain/background-service/supervisor/runner.ts +982 -0
  177. package/src/runtime/domain/background-service/supervisor/store.domain.mjs +605 -0
  178. package/src/runtime/domain/background-service/supervisor/store.ts +651 -0
  179. package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +721 -0
  180. package/src/runtime/domain/background-service/supervisor/supervisor.ts +804 -0
  181. package/src/runtime/domain/background-service/supervisor/types.domain.mjs +48 -0
  182. package/src/runtime/domain/background-service/supervisor/types.ts +394 -0
  183. package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +60 -0
  184. package/src/runtime/domain/background-service/task-diagnostics.ts +71 -0
  185. package/src/runtime/domain/background-service/tools.domain.mjs +1050 -0
  186. package/src/runtime/domain/background-service/tools.ts +1142 -0
  187. package/src/runtime/domain/background-service/types.domain.mjs +5 -0
  188. package/src/runtime/domain/background-service/types.ts +236 -0
  189. package/src/runtime/domain/background-service/work-observation.domain.mjs +176 -0
  190. package/src/runtime/domain/background-service/work-observation.ts +144 -0
  191. package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
  192. package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
  193. package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
  194. package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
  195. package/src/runtime/domain/coordinator/src/background-parent-callbacks.mjs +65 -0
  196. package/src/runtime/domain/coordinator/src/background-requests.mjs +86 -0
  197. package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
  198. package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
  199. package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
  200. package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
  201. package/src/runtime/domain/coordinator/src/schema.mjs +73 -21
  202. package/src/runtime/domain/coordinator/src/store.mjs +32 -3
  203. package/src/runtime/domain/coordinator/src/subagent-launch.mjs +119 -0
  204. package/src/runtime/domain/coordinator/src/types.mjs +1 -1
  205. package/src/runtime/domain/coordinator/src/upgrade.mjs +22 -0
  206. package/src/runtime/domain/health-observation.d.mts +3 -1
  207. package/src/runtime/domain/health-observation.mjs +189 -190
  208. package/src/runtime/domain/log-cursor.d.mts +2 -0
  209. package/src/runtime/domain/log-cursor.mjs +85 -16
  210. package/src/runtime/domain/parse.d.mts +4 -1
  211. package/src/runtime/domain/parse.mjs +50 -5
  212. package/src/runtime/domain/sandbox-policy/README.md +633 -0
  213. package/src/runtime/domain/sandbox-policy/background-admission.domain.mjs +83 -0
  214. package/src/runtime/domain/sandbox-policy/background-admission.ts +75 -0
  215. package/src/runtime/domain/sandbox-policy/commands.domain.mjs +245 -0
  216. package/src/runtime/domain/sandbox-policy/commands.ts +336 -0
  217. package/src/runtime/domain/sandbox-policy/deny-rules.domain.mjs +440 -0
  218. package/src/runtime/domain/sandbox-policy/deny-rules.ts +620 -0
  219. package/src/runtime/domain/sandbox-policy/diagnostics-command.domain.mjs +30 -0
  220. package/src/runtime/domain/sandbox-policy/diagnostics-command.ts +27 -0
  221. package/src/runtime/domain/sandbox-policy/events.domain.mjs +49 -0
  222. package/src/runtime/domain/sandbox-policy/events.ts +85 -0
  223. package/src/runtime/domain/sandbox-policy/files.domain.mjs +153 -0
  224. package/src/runtime/domain/sandbox-policy/files.ts +224 -0
  225. package/src/runtime/domain/sandbox-policy/index.domain.mjs +289 -0
  226. package/src/runtime/domain/sandbox-policy/index.ts +386 -0
  227. package/src/runtime/domain/sandbox-policy/package.json +66 -0
  228. package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +36 -0
  229. package/src/runtime/domain/sandbox-policy/permission-settings.ts +46 -0
  230. package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +309 -0
  231. package/src/runtime/domain/sandbox-policy/permissions-page.ts +295 -0
  232. package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +98 -0
  233. package/src/runtime/domain/sandbox-policy/permissions.ts +125 -0
  234. package/src/runtime/domain/sandbox-policy/policy.domain.mjs +80 -0
  235. package/src/runtime/domain/sandbox-policy/policy.ts +102 -0
  236. package/src/runtime/domain/sandbox-policy/preferences.domain.mjs +55 -0
  237. package/src/runtime/domain/sandbox-policy/preferences.ts +82 -0
  238. package/src/runtime/domain/sandbox-policy/rules-page.domain.mjs +138 -0
  239. package/src/runtime/domain/sandbox-policy/rules-page.ts +176 -0
  240. package/src/runtime/domain/sandbox-policy/session-permissions.domain.mjs +22 -0
  241. package/src/runtime/domain/sandbox-policy/session-permissions.ts +24 -0
  242. package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +126 -0
  243. package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +116 -0
  244. package/src/runtime/domain/sandbox-policy/shared-permission-blocker.domain.mjs +40 -0
  245. package/src/runtime/domain/sandbox-policy/shared-permission-blocker.ts +48 -0
  246. package/src/runtime/domain/sandbox-policy/shared-sandbox-core.domain.mjs +1531 -0
  247. package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1757 -0
  248. package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +591 -0
  249. package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +491 -0
  250. package/src/runtime/domain/sandbox-policy/shared-task-application.domain.mjs +185 -0
  251. package/src/runtime/domain/sandbox-policy/shared-task-application.ts +185 -0
  252. package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.domain.mjs +416 -0
  253. package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.ts +409 -0
  254. package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +325 -0
  255. package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +335 -0
  256. package/src/runtime/domain/sandbox-policy/shared-task-files.domain.mjs +346 -0
  257. package/src/runtime/domain/sandbox-policy/shared-task-files.ts +342 -0
  258. package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
  259. package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
  260. package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +220 -0
  261. package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +209 -0
  262. package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +227 -0
  263. package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +224 -0
  264. package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +92 -0
  265. package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +123 -0
  266. package/src/runtime/domain/sandbox-policy/shell.domain.mjs +93 -0
  267. package/src/runtime/domain/sandbox-policy/shell.ts +129 -0
  268. package/src/runtime/domain/sandbox-policy/state.domain.mjs +307 -0
  269. package/src/runtime/domain/sandbox-policy/state.ts +408 -0
  270. package/src/runtime/domain/sandbox-policy/status.domain.mjs +64 -0
  271. package/src/runtime/domain/sandbox-policy/status.ts +76 -0
  272. package/src/runtime/domain/sandbox-policy/subagent-admission.domain.mjs +69 -0
  273. package/src/runtime/domain/sandbox-policy/subagent-admission.ts +60 -0
  274. package/src/runtime/domain/subagents/CONTEXT.md +202 -0
  275. package/src/runtime/domain/subagents/PRODUCT.md +49 -0
  276. package/src/runtime/domain/subagents/README.md +201 -0
  277. package/src/runtime/domain/subagents/agent-catalog.mjs +64 -0
  278. package/src/runtime/domain/subagents/agent-commands.domain.mjs +822 -0
  279. package/src/runtime/domain/subagents/agent-commands.ts +905 -0
  280. package/src/runtime/domain/subagents/agent-inspection.domain.mjs +398 -0
  281. package/src/runtime/domain/subagents/agent-inspection.ts +574 -0
  282. package/src/runtime/domain/subagents/agent-operations.domain.mjs +40 -0
  283. package/src/runtime/domain/subagents/agent-operations.ts +61 -0
  284. package/src/runtime/domain/subagents/agent-session-settings.domain.mjs +112 -0
  285. package/src/runtime/domain/subagents/agent-session-settings.ts +118 -0
  286. package/src/runtime/domain/subagents/agents-catalog-tool.domain.mjs +84 -0
  287. package/src/runtime/domain/subagents/agents-catalog-tool.ts +118 -0
  288. package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +276 -0
  289. package/src/runtime/domain/subagents/assignment-outcomes.ts +212 -0
  290. package/src/runtime/domain/subagents/assignment-projection.mjs +261 -0
  291. package/src/runtime/domain/subagents/assignment-report.domain.mjs +174 -0
  292. package/src/runtime/domain/subagents/assignment-report.ts +156 -0
  293. package/src/runtime/domain/subagents/batch.mjs +275 -0
  294. package/src/runtime/domain/subagents/callback-fields.domain.mjs +72 -0
  295. package/src/runtime/domain/subagents/callback-fields.ts +95 -0
  296. package/src/runtime/domain/subagents/capacity.mjs +108 -0
  297. package/src/runtime/domain/subagents/catalog-editor.domain.mjs +98 -0
  298. package/src/runtime/domain/subagents/catalog-editor.ts +125 -0
  299. package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +104 -0
  300. package/src/runtime/domain/subagents/catalog-host-admission.ts +85 -0
  301. package/src/runtime/domain/subagents/catalog-identity.domain.mjs +222 -0
  302. package/src/runtime/domain/subagents/catalog-identity.ts +258 -0
  303. package/src/runtime/domain/subagents/catalog-overlay.domain.mjs +9 -0
  304. package/src/runtime/domain/subagents/catalog-overlay.ts +10 -0
  305. package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +164 -0
  306. package/src/runtime/domain/subagents/catalog-preferences.ts +139 -0
  307. package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +366 -0
  308. package/src/runtime/domain/subagents/catalog-resolver.ts +540 -0
  309. package/src/runtime/domain/subagents/catalog-runtime.domain.mjs +570 -0
  310. package/src/runtime/domain/subagents/catalog-runtime.ts +680 -0
  311. package/src/runtime/domain/subagents/catalog-schema.domain.mjs +1331 -0
  312. package/src/runtime/domain/subagents/catalog-schema.ts +1563 -0
  313. package/src/runtime/domain/subagents/catalog-skill-edits.domain.mjs +95 -0
  314. package/src/runtime/domain/subagents/catalog-skill-edits.ts +116 -0
  315. package/src/runtime/domain/subagents/catalog-store.domain.mjs +808 -0
  316. package/src/runtime/domain/subagents/catalog-store.ts +1006 -0
  317. package/src/runtime/domain/subagents/catalog-ui.domain.mjs +651 -0
  318. package/src/runtime/domain/subagents/catalog-ui.ts +611 -0
  319. package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
  320. package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
  321. package/src/runtime/domain/subagents/child-codemode.domain.mjs +16 -0
  322. package/src/runtime/domain/subagents/child-codemode.ts +17 -0
  323. package/src/runtime/domain/subagents/child-dependencies.mjs +193 -0
  324. package/src/runtime/domain/subagents/child-incidents.domain.mjs +170 -0
  325. package/src/runtime/domain/subagents/child-incidents.ts +169 -0
  326. package/src/runtime/domain/subagents/child-operations.domain.mjs +986 -0
  327. package/src/runtime/domain/subagents/child-operations.ts +1191 -0
  328. package/src/runtime/domain/subagents/child-ownership.domain.mjs +205 -0
  329. package/src/runtime/domain/subagents/child-ownership.ts +160 -0
  330. package/src/runtime/domain/subagents/child-preflight.mjs +38 -0
  331. package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
  332. package/src/runtime/domain/subagents/child-process-list.ts +8 -0
  333. package/src/runtime/domain/subagents/child-runtime.mjs +67 -0
  334. package/src/runtime/domain/subagents/child-steer.domain.mjs +109 -0
  335. package/src/runtime/domain/subagents/child-steer.ts +102 -0
  336. package/src/runtime/domain/subagents/cleanup.domain.mjs +818 -0
  337. package/src/runtime/domain/subagents/cleanup.ts +1017 -0
  338. package/src/runtime/domain/subagents/codex-import.domain.mjs +575 -0
  339. package/src/runtime/domain/subagents/codex-import.ts +717 -0
  340. package/src/runtime/domain/subagents/completion.domain.mjs +6 -0
  341. package/src/runtime/domain/subagents/completion.mjs +152 -0
  342. package/src/runtime/domain/subagents/completion.ts +11 -0
  343. package/src/runtime/domain/subagents/config.domain.mjs +248 -0
  344. package/src/runtime/domain/subagents/config.json +15 -0
  345. package/src/runtime/domain/subagents/config.ts +328 -0
  346. package/src/runtime/domain/subagents/continuation-authority.domain.mjs +38 -0
  347. package/src/runtime/domain/subagents/continuation-authority.ts +31 -0
  348. package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
  349. package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
  350. package/src/runtime/domain/subagents/continuation.domain.mjs +942 -0
  351. package/src/runtime/domain/subagents/continuation.ts +1051 -0
  352. package/src/runtime/domain/subagents/delegation.domain.mjs +19 -0
  353. package/src/runtime/domain/subagents/delegation.ts +24 -0
  354. package/src/runtime/domain/subagents/effective-settings.domain.mjs +130 -0
  355. package/src/runtime/domain/subagents/effective-settings.ts +184 -0
  356. package/src/runtime/domain/subagents/extensions.domain.mjs +6 -0
  357. package/src/runtime/domain/subagents/extensions.mjs +164 -0
  358. package/src/runtime/domain/subagents/extensions.ts +19 -0
  359. package/src/runtime/domain/subagents/failures.domain.mjs +362 -0
  360. package/src/runtime/domain/subagents/failures.ts +319 -0
  361. package/src/runtime/domain/subagents/finalization.domain.mjs +168 -0
  362. package/src/runtime/domain/subagents/finalization.ts +218 -0
  363. package/src/runtime/domain/subagents/git-remotes.domain.mjs +351 -0
  364. package/src/runtime/domain/subagents/git-remotes.ts +413 -0
  365. package/src/runtime/domain/subagents/git-workspace.domain.mjs +337 -0
  366. package/src/runtime/domain/subagents/git-workspace.ts +430 -0
  367. package/src/runtime/domain/subagents/goal-provider.domain.mjs +125 -0
  368. package/src/runtime/domain/subagents/goal-provider.ts +132 -0
  369. package/src/runtime/domain/subagents/health-observation.domain.mjs +617 -0
  370. package/src/runtime/domain/subagents/health-observation.ts +818 -0
  371. package/src/runtime/domain/subagents/health-surface.mjs +284 -0
  372. package/src/runtime/domain/subagents/health.domain.mjs +261 -0
  373. package/src/runtime/domain/subagents/health.ts +343 -0
  374. package/src/runtime/domain/subagents/historical-attention.domain.mjs +37 -0
  375. package/src/runtime/domain/subagents/historical-attention.ts +35 -0
  376. package/src/runtime/domain/subagents/incident-model.domain.mjs +322 -0
  377. package/src/runtime/domain/subagents/incident-model.ts +358 -0
  378. package/src/runtime/domain/subagents/index.domain.mjs +4731 -0
  379. package/src/runtime/domain/subagents/index.ts +4781 -0
  380. package/src/runtime/domain/subagents/launch-abort.domain.mjs +13 -0
  381. package/src/runtime/domain/subagents/launch-abort.ts +21 -0
  382. package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
  383. package/src/runtime/domain/subagents/launch-context.ts +23 -0
  384. package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
  385. package/src/runtime/domain/subagents/lifecycle.domain.mjs +265 -0
  386. package/src/runtime/domain/subagents/lifecycle.ts +360 -0
  387. package/src/runtime/domain/subagents/list.domain.mjs +2 -0
  388. package/src/runtime/domain/subagents/list.mjs +152 -0
  389. package/src/runtime/domain/subagents/list.ts +19 -0
  390. package/src/runtime/domain/subagents/log-cursor.domain.mjs +217 -0
  391. package/src/runtime/domain/subagents/log-cursor.ts +268 -0
  392. package/src/runtime/domain/subagents/managed-background-capability.domain.mjs +10 -0
  393. package/src/runtime/domain/subagents/managed-background-capability.ts +9 -0
  394. package/src/runtime/domain/subagents/managed-failure-worker.mjs +36 -0
  395. package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +48 -0
  396. package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +75 -0
  397. package/src/runtime/domain/subagents/managed-launch-client.ts +59 -0
  398. package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +627 -0
  399. package/src/runtime/domain/subagents/managed-launch-host.ts +504 -0
  400. package/src/runtime/domain/subagents/managed-launch-journal.mjs +17 -0
  401. package/src/runtime/domain/subagents/managed-launch-ownership.domain.mjs +29 -0
  402. package/src/runtime/domain/subagents/managed-launch-ownership.ts +22 -0
  403. package/src/runtime/domain/subagents/managed-launch-port.domain.mjs +2 -0
  404. package/src/runtime/domain/subagents/managed-launch-port.ts +25 -0
  405. package/src/runtime/domain/subagents/managed-launch-recovery.domain.mjs +29 -0
  406. package/src/runtime/domain/subagents/managed-launch-recovery.ts +45 -0
  407. package/src/runtime/domain/subagents/managed-worker-bridge.domain.mjs +63 -0
  408. package/src/runtime/domain/subagents/managed-worker-bridge.ts +48 -0
  409. package/src/runtime/domain/subagents/managed-worker.mjs +13 -0
  410. package/src/runtime/domain/subagents/model-resolution-core.domain.mjs +822 -0
  411. package/src/runtime/domain/subagents/model-resolution-core.ts +1074 -0
  412. package/src/runtime/domain/subagents/model-resolution.domain.mjs +22 -0
  413. package/src/runtime/domain/subagents/model-resolution.ts +32 -0
  414. package/src/runtime/domain/subagents/navigator.domain.mjs +6 -0
  415. package/src/runtime/domain/subagents/navigator.mjs +1233 -0
  416. package/src/runtime/domain/subagents/navigator.ts +39 -0
  417. package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +1012 -0
  418. package/src/runtime/domain/subagents/operation-bridge-types.ts +1156 -0
  419. package/src/runtime/domain/subagents/outage-observations.domain.mjs +84 -0
  420. package/src/runtime/domain/subagents/outage-observations.ts +73 -0
  421. package/src/runtime/domain/subagents/output-payload.domain.mjs +767 -0
  422. package/src/runtime/domain/subagents/output-payload.ts +987 -0
  423. package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
  424. package/src/runtime/domain/subagents/owned-exit.ts +12 -0
  425. package/src/runtime/domain/subagents/package.json +86 -0
  426. package/src/runtime/domain/subagents/park-checkpoint.domain.mjs +55 -0
  427. package/src/runtime/domain/subagents/park-checkpoint.ts +61 -0
  428. package/src/runtime/domain/subagents/parse.domain.mjs +1218 -0
  429. package/src/runtime/domain/subagents/parse.ts +1451 -0
  430. package/src/runtime/domain/subagents/permission-policy.domain.mjs +232 -0
  431. package/src/runtime/domain/subagents/permission-policy.ts +291 -0
  432. package/src/runtime/domain/subagents/process-identity.mjs +33 -0
  433. package/src/runtime/domain/subagents/registry.domain.mjs +1584 -0
  434. package/src/runtime/domain/subagents/registry.ts +1904 -0
  435. package/src/runtime/domain/subagents/role-assignment.domain.mjs +104 -0
  436. package/src/runtime/domain/subagents/role-assignment.ts +141 -0
  437. package/src/runtime/domain/subagents/roles/role.architect.md +13 -0
  438. package/src/runtime/domain/subagents/roles/role.developer.md +16 -0
  439. package/src/runtime/domain/subagents/roles/role.explorer.md +13 -0
  440. package/src/runtime/domain/subagents/roles/role.product-manager.md +13 -0
  441. package/src/runtime/domain/subagents/roles/role.researcher.md +13 -0
  442. package/src/runtime/domain/subagents/roles/role.reviewer.md +13 -0
  443. package/src/runtime/domain/subagents/roles/role.writer.md +12 -0
  444. package/src/runtime/domain/subagents/sandbox.domain.mjs +64 -0
  445. package/src/runtime/domain/subagents/sandbox.ts +92 -0
  446. package/src/runtime/domain/subagents/session-selection.domain.mjs +32 -0
  447. package/src/runtime/domain/subagents/session-selection.ts +35 -0
  448. package/src/runtime/domain/subagents/session-store.domain.mjs +489 -0
  449. package/src/runtime/domain/subagents/session-store.ts +468 -0
  450. package/src/runtime/domain/subagents/settings-page.domain.mjs +313 -0
  451. package/src/runtime/domain/subagents/settings-page.ts +363 -0
  452. package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +777 -0
  453. package/src/runtime/domain/subagents/shared-callback-batcher.ts +956 -0
  454. package/src/runtime/domain/subagents/shared-catalog.domain.mjs +70 -0
  455. package/src/runtime/domain/subagents/shared-catalog.ts +61 -0
  456. package/src/runtime/domain/subagents/shared-execution-policy.domain.mjs +50 -0
  457. package/src/runtime/domain/subagents/shared-execution-policy.ts +61 -0
  458. package/src/runtime/domain/subagents/shared-failure-observations.domain.mjs +1078 -0
  459. package/src/runtime/domain/subagents/shared-failure-observations.ts +1166 -0
  460. package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +126 -0
  461. package/src/runtime/domain/subagents/shared-harness-settings.ts +116 -0
  462. package/src/runtime/domain/subagents/shared-log-utils.domain.mjs +1223 -0
  463. package/src/runtime/domain/subagents/shared-log-utils.ts +1492 -0
  464. package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +289 -0
  465. package/src/runtime/domain/subagents/shared-navigator-panels.ts +272 -0
  466. package/src/runtime/domain/subagents/shared-navigator.domain.mjs +1930 -0
  467. package/src/runtime/domain/subagents/shared-navigator.ts +1962 -0
  468. package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
  469. package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +189 -0
  470. package/src/runtime/domain/subagents/shared-operation-coordinator/index.domain.mjs +51 -0
  471. package/src/runtime/domain/subagents/shared-operation-coordinator/index.ts +122 -0
  472. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
  473. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
  474. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +163 -0
  475. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
  476. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
  477. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
  478. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
  479. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +90 -0
  480. package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
  481. package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +139 -0
  482. package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.domain.mjs +12 -0
  483. package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.ts +79 -0
  484. package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +342 -0
  485. package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +513 -0
  486. package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
  487. package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +458 -0
  488. package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
  489. package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.ts +55 -0
  490. package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
  491. package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +140 -0
  492. package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +280 -0
  493. package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +442 -0
  494. package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +420 -0
  495. package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +441 -0
  496. package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
  497. package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.ts +239 -0
  498. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +275 -0
  499. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +585 -0
  500. package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
  501. package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +142 -0
  502. package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
  503. package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.ts +224 -0
  504. package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +25 -0
  505. package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +707 -0
  506. package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
  507. package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.ts +22 -0
  508. package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.domain.mjs +234 -0
  509. package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.ts +241 -0
  510. package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +851 -0
  511. package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +1424 -0
  512. package/src/runtime/domain/subagents/shared-permission-blocker.domain.mjs +40 -0
  513. package/src/runtime/domain/subagents/shared-permission-blocker.ts +48 -0
  514. package/src/runtime/domain/subagents/shared-render-scheduler.domain.mjs +41 -0
  515. package/src/runtime/domain/subagents/shared-render-scheduler.ts +47 -0
  516. package/src/runtime/domain/subagents/shared-sandbox-core.domain.mjs +1531 -0
  517. package/src/runtime/domain/subagents/shared-sandbox-core.ts +1757 -0
  518. package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +591 -0
  519. package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +491 -0
  520. package/src/runtime/domain/subagents/shared-stall-detector.domain.mjs +37 -0
  521. package/src/runtime/domain/subagents/shared-stall-detector.ts +69 -0
  522. package/src/runtime/domain/subagents/shared-task-application.domain.mjs +185 -0
  523. package/src/runtime/domain/subagents/shared-task-application.ts +185 -0
  524. package/src/runtime/domain/subagents/shared-task-apply-patch.domain.mjs +416 -0
  525. package/src/runtime/domain/subagents/shared-task-apply-patch.ts +409 -0
  526. package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +325 -0
  527. package/src/runtime/domain/subagents/shared-task-exec.ts +335 -0
  528. package/src/runtime/domain/subagents/shared-task-files.domain.mjs +346 -0
  529. package/src/runtime/domain/subagents/shared-task-files.ts +342 -0
  530. package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
  531. package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
  532. package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +220 -0
  533. package/src/runtime/domain/subagents/shared-task-process-list.ts +209 -0
  534. package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +227 -0
  535. package/src/runtime/domain/subagents/shared-task-sandbox.ts +224 -0
  536. package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +92 -0
  537. package/src/runtime/domain/subagents/shared-task-tools.ts +123 -0
  538. package/src/runtime/domain/subagents/shared-work-client.mjs +303 -0
  539. package/src/runtime/domain/subagents/shared-worktree-context.domain.mjs +142 -0
  540. package/src/runtime/domain/subagents/shared-worktree-context.ts +158 -0
  541. package/src/runtime/domain/subagents/skill-picker.domain.mjs +316 -0
  542. package/src/runtime/domain/subagents/skill-picker.ts +353 -0
  543. package/src/runtime/domain/subagents/skills.domain.mjs +138 -0
  544. package/src/runtime/domain/subagents/skills.ts +183 -0
  545. package/src/runtime/domain/subagents/spawn.domain.mjs +72 -0
  546. package/src/runtime/domain/subagents/spawn.ts +80 -0
  547. package/src/runtime/domain/subagents/stop.domain.mjs +184 -0
  548. package/src/runtime/domain/subagents/stop.ts +217 -0
  549. package/src/runtime/domain/subagents/subagent-tools.domain.mjs +101 -0
  550. package/src/runtime/domain/subagents/subagent-tools.ts +137 -0
  551. package/src/runtime/domain/subagents/task-guard.domain.mjs +163 -0
  552. package/src/runtime/domain/subagents/task-guard.ts +144 -0
  553. package/src/runtime/domain/subagents/task-policy.domain.mjs +201 -0
  554. package/src/runtime/domain/subagents/task-policy.ts +236 -0
  555. package/src/runtime/domain/subagents/task-runtime.mjs +53 -0
  556. package/src/runtime/domain/subagents/task-tool-owner.domain.mjs +18 -0
  557. package/src/runtime/domain/subagents/task-tool-owner.ts +21 -0
  558. package/src/runtime/domain/subagents/thinking.domain.mjs +22 -0
  559. package/src/runtime/domain/subagents/thinking.ts +28 -0
  560. package/src/runtime/domain/subagents/tier-policy.domain.mjs +75 -0
  561. package/src/runtime/domain/subagents/tier-policy.ts +126 -0
  562. package/src/runtime/domain/subagents/timing-notifications.domain.mjs +51 -0
  563. package/src/runtime/domain/subagents/timing-notifications.ts +37 -0
  564. package/src/runtime/domain/subagents/timing.domain.mjs +487 -0
  565. package/src/runtime/domain/subagents/timing.ts +634 -0
  566. package/src/runtime/domain/subagents/tools.domain.mjs +558 -0
  567. package/src/runtime/domain/subagents/tools.ts +629 -0
  568. package/src/runtime/domain/subagents/widget.domain.mjs +6 -0
  569. package/src/runtime/domain/subagents/widget.mjs +246 -0
  570. package/src/runtime/domain/subagents/widget.ts +30 -0
  571. package/src/runtime/domain/subagents/work-observation.domain.mjs +316 -0
  572. package/src/runtime/domain/subagents/work-observation.ts +248 -0
  573. package/src/runtime/domain/subagents/worker-catalog.domain.mjs +120 -0
  574. package/src/runtime/domain/subagents/worker-catalog.ts +162 -0
  575. package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +1009 -0
  576. package/src/runtime/domain/subagents/worker-operations-host.ts +1238 -0
  577. package/src/runtime/domain/subagents/worker-waits.domain.mjs +2336 -0
  578. package/src/runtime/domain/subagents/worker-waits.ts +2878 -0
  579. package/src/runtime/domain/subagents/workspace-scope.domain.mjs +52 -0
  580. package/src/runtime/domain/subagents/workspace-scope.ts +50 -0
  581. package/src/runtime/health-config.ts +27 -11
  582. package/src/runtime/log-checkpoints.ts +117 -0
  583. package/src/runtime/mutation-store.ts +5 -4
  584. package/src/runtime/queries.ts +27 -3
  585. package/src/runtime/query-executor.ts +178 -34
  586. package/src/runtime/query-worker.mjs +119 -22
  587. package/src/runtime/read-model.ts +939 -113
  588. package/src/runtime/read-watchdog-probe.ts +4 -0
  589. package/src/runtime/result-supervision.ts +188 -16
  590. package/src/runtime/source-watch.ts +175 -0
  591. package/src/runtime/subagent-launch.ts +73 -0
  592. package/src/runtime/work-budget.ts +130 -0
  593. package/src/runtime/work-client.d.mts +8 -0
  594. package/src/runtime/work-client.mjs +150 -7
  595. package/src/server.ts +185 -22
  596. package/src/session-activity.ts +26 -4
  597. package/src/version.ts +1 -1
@@ -0,0 +1,504 @@
1
+ import { createHash, timingSafeEqual } from "node:crypto";
2
+ import { lstatSync, mkdirSync, readFileSync, realpathSync, statSync, watch, type FSWatcher } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { createAgentSession, DefaultResourceLoader, SessionManager, SettingsManager, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
6
+ import { verifyParkCheckpoint } from "./park-checkpoint.ts";
7
+ import { intersectContinuationPermissions } from "./continuation-authority.ts";
8
+ import extension from "./index.ts";
9
+ import { bindRuntimeOutcomeStore } from "./assignment-outcomes.ts";
10
+ import { catalogSnapshotFromWire } from "./catalog-store.ts";
11
+ import { openLaunchJournal, launchDigest } from "./managed-launch-journal.mjs";
12
+ import { baseDir, nextRunId, processStartToken, listMetas, writeMeta, listActiveMetasForParent, effectiveStatus, readMeta, readParkRecord, updateParkRecord } from "./registry.ts";
13
+ import { recoverLaunchMetadata } from "./managed-launch-recovery.ts";
14
+ import { assertSubagentHandoff } from "./managed-launch-ownership.ts";
15
+ import { createOwnerCapacityGates } from "./capacity.mjs";
16
+ import { readConversationLease, releaseUnspawnedConversationLease } from "./continuation.ts";
17
+ import { Worker } from "node:worker_threads";
18
+ import { processExists } from "./spawn.ts";
19
+ import type { ManagedLaunchPort } from "./managed-launch-port.ts";
20
+
21
+ // Revocation only: the journal remains the authority. A new same-process
22
+ // manager revokes a previous worker before advancing the journal epoch.
23
+ const failureFoldRevocations = new Map<string, Int32Array>();
24
+
25
+ /** One fixed SDK adapter per runtime, not a client-selected module or transcript writer. */
26
+ export class ManagedSubagentHost {
27
+ private foldRevocation = new Int32Array(new SharedArrayBuffer(4));
28
+ private failureWorker?: Worker;
29
+ private failureWorkerError?: Error;
30
+ private failureResponse?: { resolve(): void; reject(error: Error): void };
31
+ private current: any;
32
+ private api!: ExtensionAPI;
33
+ private session: any;
34
+ private initializing?: Promise<void>;
35
+ private tail: Promise<unknown> = Promise.resolve();
36
+ private journal: ReturnType<typeof openLaunchJournal>["journal"];
37
+ private closeJournal: () => void;
38
+ private epoch: number;
39
+ private pending = 0;
40
+ private requestSequence = 0;
41
+ private requestRecords = new Map<number, any>();
42
+ private foldRecord?: { kind: string; ids: readonly string[]; lastProgressAt: number; nextDeadline: number; recovery: string };
43
+ private acceptedRequestLive = false;
44
+ private continuationWindow = { started: 0, admitted: 0 };
45
+ private continuationFailures = new Map<string, { failures: number; retryAt: number; reason: string }>();
46
+ private workerHost?: { start(ctx?: unknown): void; close(): void; advancingWaits?(): any[]; service: { continuationReady: boolean } };
47
+ private path: string;
48
+ private known = new Map<string, any>();
49
+ private healthClose?: () => void;
50
+ private healthChanged?: (id: string) => void;
51
+ private lifecycleMetrics = { passes: 0, entities: 0, deadlineLatenessMs: 0 };
52
+ private healthDue = new Map<string, number>();
53
+ private writerProofs = new Map<string, { verified: boolean; checkedAt: number; unknownSince: number }>();
54
+ lifecycleReasons() {
55
+ const now = Date.now();
56
+ const writers = [...this.known.values()].filter(meta => ["running", "orphaned"].includes(meta.status)).flatMap(meta => {
57
+ const proof = this.writerProofs.get(meta.id);
58
+ if (!proof || !proof.verified && now >= proof.unknownSince + this.verificationMs) return [];
59
+ return [{
60
+ kind: proof.verified ? "worker" : "verification", id: meta.id, owner: meta.callbackOrigin, writer: { pid: meta.pid, start: meta.pidStartTime },
61
+ management: meta.management, lastProgressAt: meta.timing?.lastProgressAt ?? meta.startedAt,
62
+ nextDeadline: proof.verified ? this.healthDue.get(meta.id) ?? null : proof.unknownSince + this.verificationMs,
63
+ recovery: proof.verified ? "current-managed-writer-supervision" : "writer-unverified-no-takeover",
64
+ }]; });
65
+ return [...this.requestRecords.values(), ...(this.foldRecord ? [{ ...this.foldRecord }] : []),
66
+ ...(this.acceptedRequestLive ? this.journal.lifecycleReasons(this.current.ownerKey, this.current.key) : []).map(reason => ({ ...reason,
67
+ management: { ...reason.management, instance: this.instance }, writerFence: 'current-managed-launch-epoch' })),
68
+ ...writers, ...(this.workerHost?.advancingWaits?.() ?? [])];
69
+ }
70
+ private observeHealth(reconcile: (ids: readonly string[]) => void) {
71
+ this.healthClose?.();
72
+ let closed = false, scheduled = false;
73
+ let timer: ReturnType<typeof setTimeout> | undefined;
74
+ const watchers: FSWatcher[] = [], dirty = new Set(this.known.keys()), signatures = new Map<string, string>();
75
+ const signature = (meta: any) => {
76
+ let log = "missing";
77
+ try { const info = statSync(meta.logPath, { bigint: true }); log = `${info.ino}:${info.size}:${info.mtimeNs}`; } catch { /* No log yet. */ }
78
+ return JSON.stringify(meta) + log;
79
+ };
80
+ const schedule = () => {
81
+ if (closed || scheduled) return;
82
+ scheduled = true;
83
+ setImmediate(() => { scheduled = false; if (!closed) pass(); });
84
+ };
85
+ const hint = (id: string) => {
86
+ const meta = readMeta(id);
87
+ if (meta?.management?.root === this.root && meta.management.instance === this.instance && meta.management.epoch === this.epoch) {
88
+ if (signatures.get(id) === signature(meta)) return;
89
+ if (!this.writerProofs.has(id)) this.writerProofs.set(id, { verified: false, checkedAt: Date.now(), unknownSince: Date.now() });
90
+ this.known.set(id, meta); dirty.add(id); schedule();
91
+ }
92
+ };
93
+ this.healthChanged = hint;
94
+ const pass = () => {
95
+ const now = Date.now();
96
+ for (const [id, due] of this.healthDue) if (due <= now) dirty.add(id);
97
+ const ids = [...dirty].slice(0, 32);
98
+ ids.forEach(id => dirty.delete(id));
99
+ if (ids.length) {
100
+ const release = this.enterControl?.();
101
+ if (this.enterControl && !release) {
102
+ ids.forEach(id => dirty.add(id));
103
+ timer = setTimeout(schedule, 1000); timer.unref(); return;
104
+ }
105
+ this.lifecycleMetrics.passes++; this.lifecycleMetrics.entities += ids.length;
106
+ for (const id of ids) this.lifecycleMetrics.deadlineLatenessMs = Math.max(this.lifecycleMetrics.deadlineLatenessMs, now - (this.healthDue.get(id) ?? now));
107
+ try { reconcile(ids); } finally { release?.(); }
108
+ for (const id of ids) {
109
+ const meta = readMeta(id);
110
+ if (meta) this.known.set(id, meta); else this.known.delete(id);
111
+ if (meta) signatures.set(id, signature(meta));
112
+ this.healthDue.delete(id);
113
+ if (!meta || !["running", "orphaned"].includes(meta.status)) {
114
+ this.writerProofs.delete(id);
115
+ if (meta?.completionCallbackPendingAt && !meta.completionCallbackSentAt && !meta.completionCallbackSuppressedAt) this.healthDue.set(id, now + 15000);
116
+ else { this.known.delete(id); signatures.delete(id); }
117
+ continue;
118
+ }
119
+ const verified = Boolean(meta.pidStartTime && processStartToken(meta.pid) === meta.pidStartTime && processExists(meta.pid));
120
+ const prior = this.writerProofs.get(id);
121
+ this.writerProofs.set(id, { verified, checkedAt: now, unknownSince: verified ? now : prior?.unknownSince ?? now });
122
+ const timing = meta.timing;
123
+ const deadlines = [now + 15000, timing?.ceilingAt,
124
+ !timing?.deadlineWakeSentAt ? timing?.deadlineAt : undefined,
125
+ timing?.steerDeliveredAt ? timing.steerDeliveredAt + timing.graceMs : undefined]
126
+ .filter((value): value is number => typeof value === "number" && value > now);
127
+ this.healthDue.set(id, Math.min(...deadlines));
128
+ }
129
+ }
130
+ if (dirty.size) schedule();
131
+ if (timer) clearTimeout(timer);
132
+ if (this.healthDue.size) {
133
+ const next = [...this.healthDue.values()].reduce((a, b) => Math.min(a, b), Infinity);
134
+ timer = setTimeout(schedule, Math.max(1, next - Date.now())); timer.unref();
135
+ }
136
+ };
137
+ try {
138
+ mkdirSync(join(baseDir(), "runs"), { recursive: true });
139
+ const watcher = watch(join(baseDir(), "runs"), { recursive: true }, (_event, file) => {
140
+ const id = file && String(file).split(/[/\\]/)[0];
141
+ if (id && /^[A-Za-z0-9_-]+$/.test(id)) hint(id);
142
+ });
143
+ watcher.on("error", () => watcher.close()); watchers.push(watcher);
144
+ } catch { /* Known active writers still have independent liveness deadlines. */ }
145
+ schedule();
146
+ return this.healthClose = () => {
147
+ closed = true; if (timer) clearTimeout(timer); watchers.forEach(watcher => watcher.close());
148
+ this.healthChanged = undefined; this.healthDue.clear();
149
+ };
150
+ }
151
+ private capacityFor = createOwnerCapacityGates(({ pid, start }: { pid: number; start: string }) =>
152
+ listActiveMetasForParent(pid).filter(meta => meta.spawnPidStartTime === start && effectiveStatus(meta) === "running").length
153
+ + this.journal.unresolvedAttempts().filter((attempt: any) => attempt.capacityOwner?.pid === pid && attempt.capacityOwner?.start === start && !readMeta(attempt.id)).length);
154
+ get busy() { return this.pending > 0 || Boolean(this.failureResponse); }
155
+ status() {
156
+ return { owner: "server", instanceId: this.instance, runtimeEpoch: this.epoch,
157
+ lifecycle: { ...this.lifecycleMetrics, activeDeadlines: this.healthDue.size },
158
+ inFlight: this.pending, failureFold: { worker: Boolean(this.failureWorker), inFlight: Boolean(this.failureResponse) }, continuationReady: this.workerHost?.service.continuationReady ?? false, continuationUnavailable: [...this.continuationFailures].map(([key, value]) => ({ key, ...value })), unresolvedAttempts: this.journal.unresolvedAttempts().filter((attempt: any) => !readMeta(attempt.id)).length };
159
+ }
160
+ constructor(private root: string, private instance: string, private catalog: any, sharedStore?: unknown, private createWorkerHost?: (pi: ExtensionAPI) => NonNullable<ManagedSubagentHost["workerHost"]>, private readPermissions?: () => unknown, private verificationMs = 30000, private enterControl?: () => (() => void) | undefined) {
161
+ this.current = { pid: process.pid, start: processStartToken(process.pid), owner: { workspace: root, sessionId: "runtime-recovery" } };
162
+ this.path = join(root, "operation-coordinator.sqlite");
163
+ const active = listMetas({ includeArchived: false });
164
+ assertSubagentHandoff(active, root);
165
+ const opened = openLaunchJournal(this.path, sharedStore);
166
+ this.journal = opened.journal;
167
+ const unbind = sharedStore ? bindRuntimeOutcomeStore(root, sharedStore as Parameters<typeof bindRuntimeOutcomeStore>[1]) : () => {};
168
+ this.closeJournal = () => { try { unbind(); } finally { opened.close(); } };
169
+ try {
170
+ for (const meta of active) {
171
+ if (meta.management?.root !== root || !processExists(meta.pid) || processStartToken(meta.pid) !== meta.pidStartTime) continue;
172
+ const attempt = this.journal.attempt(meta.id), lease = readConversationLease(meta.sessionId);
173
+ if (!attempt || attempt.sessionId !== meta.sessionId || !lease || lease.token !== attempt.lease || lease.attemptId !== meta.id) {
174
+ throw new Error(`writer-authority-unknown: ${meta.id}`);
175
+ }
176
+ }
177
+ const priorFold = failureFoldRevocations.get(root);
178
+ if (priorFold) Atomics.store(priorFold, 0, 1);
179
+ this.epoch = this.journal.epoch(instance);
180
+ failureFoldRevocations.set(root, this.foldRevocation);
181
+ // An unpublished reservation cannot have dispatched task code. Release
182
+ // only a proven-dead manager's claim before SDK reconciliation sees it.
183
+ for (const claim of (sharedStore as any)?.listResumeClaims() ?? []) {
184
+ if (!["claimed", "published"].includes(claim.state) || !/^(managed-)?subagents:/.test(claim.lease?.ownerId ?? "")) continue;
185
+ const pid = claim.lease.pid;
186
+ if (!pid) continue;
187
+ if (processExists(pid) && (!claim.lease.processStartToken || Buffer.from(processStartToken(pid) ?? "").toString("base64url") === claim.lease.processStartToken || !processStartToken(pid))) continue;
188
+ if (claim.state === "published") {
189
+ // This fixed adapter journals before spawning. Its exact old
190
+ // manager is dead and its epoch fenced; absence of a journal
191
+ // intent proves this publication never dispatched a child.
192
+ if (!claim.attemptId || this.journal.attempt(claim.attemptId) || readMeta(claim.attemptId)) continue;
193
+ const wait = (sharedStore as any).getWait({ waitId: claim.waitId, generation: claim.generation });
194
+ const prior = wait?.park?.attemptId ? readMeta(wait.park.attemptId) : undefined;
195
+ const park = prior ? readParkRecord(prior.id) : undefined;
196
+ if (!prior || prior.management?.root !== root || claim.lease.ownerId !== `managed-subagents:${prior.management.instance}` || !park?.checkpoint) continue;
197
+ if (readConversationLease(prior.sessionId) && (!claim.lease.processStartToken || !releaseUnspawnedConversationLease({
198
+ sessionId: prior.sessionId, attemptId: claim.attemptId, managerPid: pid, managerStart: claim.lease.processStartToken,
199
+ canProveUnspawned: () => { this.journal.current(this.epoch); return !this.journal.attempt(claim.attemptId) && !readMeta(claim.attemptId); },
200
+ }))) continue;
201
+ verifyParkCheckpoint({ ...park.checkpoint, version: 1, waitId: claim.waitId, generation: claim.generation });
202
+ const result = (sharedStore as any).repairFailedResume({ waitId: claim.waitId, generation: claim.generation,
203
+ claimId: claim.claimId, claimToken: claim.claimToken, attemptId: claim.attemptId, launchToken: claim.launchToken,
204
+ proof: { writerPidGone: true, writerLeaseReleased: true }, checkpointId: wait.park.checkpointId,
205
+ expectedCancelEpoch: wait.cancelEpoch, reason: "Exact managed publication never reached pre-spawn journal" });
206
+ updateParkRecord(prior.id, { phase: result.phase, resumeExitReconciledClaimId: claim.claimId });
207
+ continue;
208
+ }
209
+ (sharedStore as any).releaseResumeClaim({ waitId: claim.waitId, generation: claim.generation,
210
+ claimId: claim.claimId, claimToken: claim.claimToken, outcome: "ready",
211
+ reason: "Recovered unpublished reservation after exact manager exit" });
212
+ }
213
+ for (const attempt of this.journal.unresolvedAttempts()) {
214
+ if (readMeta(attempt.id)) continue;
215
+ const meta = recoverLaunchMetadata(attempt, { root, instance, epoch: this.epoch }, {
216
+ pidExists: processExists, startToken: processStartToken, lease: readConversationLease,
217
+ });
218
+ writeMeta(meta, { ifAbsent: true });
219
+ active.push(meta);
220
+ }
221
+ for (const intent of this.journal.pendingIntents()) {
222
+ this.journal.finishRecovery(intent.owner, intent.request_key, this.epoch, this.recoveredResult(intent));
223
+ }
224
+ for (const meta of active) {
225
+ if (meta.management?.root !== root || (meta.status !== "running" && meta.status !== "orphaned")) continue;
226
+ writeMeta({ ...meta, management: { root, instance, epoch: this.epoch },
227
+ supervisionInterruptedAt: meta.supervisionInterruptedAt ?? Date.now(), supervisionInterruptedReason: "runtime-recovery" });
228
+ }
229
+ } catch (error) {
230
+ Atomics.store(this.foldRevocation, 0, 1);
231
+ if (failureFoldRevocations.get(root) === this.foldRevocation) failureFoldRevocations.delete(root);
232
+ this.closeJournal(); throw error;
233
+ }
234
+ }
235
+ async recover() {
236
+ for (const meta of listMetas({ includeArchived: false })) if (meta.management?.root === this.root) {
237
+ this.known.set(meta.id, meta);
238
+ this.writerProofs.set(meta.id, { verified: false, checkedAt: Date.now(), unknownSince: Date.now() });
239
+ }
240
+ if (listMetas({ includeArchived: false }).some(meta => meta.management?.root === this.root)) await this.initialize();
241
+ }
242
+ private grant(authority: any) {
243
+ if (!authority || !/^[a-f0-9-]{36}$/.test(authority.id) || !/^[a-f0-9]{64}$/.test(authority.secret)) throw new Error("launch-authority-refused");
244
+ const directory = join(this.root, "subagent-launch-admission"), path = join(directory, `${authority.id}.json`);
245
+ const dir = lstatSync(directory), stat = lstatSync(path);
246
+ if (!dir.isDirectory() || dir.isSymbolicLink() || dir.uid !== process.getuid?.() || (dir.mode & 0o077)
247
+ || !stat.isFile() || stat.isSymbolicLink() || stat.uid !== dir.uid || (stat.mode & 0o077) || stat.size > 1024 * 1024) throw new Error("launch-authority-refused");
248
+ const record = JSON.parse(readFileSync(path, "utf8"));
249
+ const digest = createHash("sha256").update(authority.secret).digest("hex");
250
+ if (record.version !== 1 || record.instanceId !== this.instance || record.id !== authority.id || typeof record.secretHash !== "string"
251
+ || record.secretHash.length !== digest.length || !timingSafeEqual(Buffer.from(record.secretHash), Buffer.from(digest))
252
+ || !record.owner?.sessionId
253
+ || !Number.isSafeInteger(record.pid)
254
+ || !["subagent_spawn", "subagent_spawn_batch"].includes(record.tool) || typeof record.key !== "string" || !record.key) throw new Error("launch-authority-refused");
255
+ if (record.owner.workspace !== realpathSync(record.owner.workspace)) throw new Error("launch-authority-refused: noncanonical workspace");
256
+ if (!record.start) throw new Error("launch-authority-refused: host process start identity unavailable");
257
+ const start = processStartToken(record.pid);
258
+ if (!start) throw new Error("launch-authority-refused: server cannot verify host process start identity");
259
+ if (start !== record.start) throw new Error("launch-authority-refused: host process identity changed");
260
+ process.kill(record.pid, 0);
261
+ return record;
262
+ }
263
+ private initialize() {
264
+ return this.initializing ??= (async () => {
265
+ const host = this;
266
+ const port: ManagedLaunchPort = {
267
+ observeHealth: reconcile => host.observeHealth(reconcile),
268
+ activeProviders: () => host.current.activeProviders ?? {},
269
+ backgroundTools: () => host.current.background?.available === true ? host.current.background.tools : [],
270
+ get owner() { return { pid: host.current.pid, start: host.current.start }; },
271
+ get identity() { return { root: host.root, instance: host.instance, epoch: host.epoch }; },
272
+ continuationContext: () => host.executionContext(host.current),
273
+ dispatchContinuation: (park, run) => host.dispatchContinuation(park, run),
274
+ supervised: () => [...host.known.values()].filter(meta => port.owns(meta)),
275
+ owns: meta => meta.management?.root === host.root && meta.management?.instance === host.instance && meta.management?.epoch === host.epoch,
276
+ assertCurrent: () => host.journal.current(host.epoch),
277
+ capacity: () => host.capacityFor(host.current),
278
+ attempt: () => nextRunId(),
279
+ workerCommand: args => ({ file: process.execPath, fileArgs: [fileURLToPath(new URL("./managed-worker.mjs", import.meta.url)), ...args] }),
280
+ snapshot: async configuration => {
281
+ const command = host.catalog.connection();
282
+ command({ type: "runtime_register_catalog", cwd: host.current.owner.workspace,
283
+ sessionId: host.current.owner.sessionId, authority: host.current.catalogAuthority });
284
+ return catalogSnapshotFromWire(command({ type: "runtime_get_catalog", fresh: true, overlay: configuration.getSessionSettings?.() ?? configuration.sessionSettings }));
285
+ },
286
+ beforeSpawn: input => {
287
+ assertSubagentHandoff(listMetas({ includeArchived: false }), host.root);
288
+ if (host.current.continuation) {
289
+ const permissions = intersectContinuationPermissions(host.current.capturedPermissions, host.readPermissions?.());
290
+ if (launchDigest(permissions) !== launchDigest(host.current.permissions)) throw new Error("continuation-permissions-changed");
291
+ host.current.key = `${host.current.baseKey}:${input.id}`;
292
+ host.current.digest = launchDigest({ key: host.current.key, runId: host.current.priorRunId });
293
+ host.journal.accept(host.current.ownerKey, host.current.key, host.current.digest, host.epoch);
294
+ } else {
295
+ const fresh = host.grant(host.current.authority);
296
+ if (launchDigest(fresh) !== host.current.grantDigest) throw new Error("launch-authority-changed");
297
+ }
298
+ const preflightDigest = launchDigest(JSON.parse(readFileSync(input.preflightPath, "utf8")));
299
+ const policyDigest = input.policyPath ? launchDigest(JSON.parse(readFileSync(input.policyPath, "utf8"))) : undefined;
300
+ const attempt = host.journal.prepare(host.current.ownerKey, host.current.key, host.epoch, { ...input, preflightDigest, policyDigest,
301
+ capacityOwner: { pid: host.current.pid, start: host.current.start },
302
+ launchAuthority: host.current.launchAuthority ?? { owner: host.current.owner, pid: host.current.pid, start: host.current.start, settings: host.current.settings, model: host.current.model, projectTrusted: host.current.projectTrusted, background: host.current.background, activeProviders: host.current.activeProviders, permissions: host.current.permissions } });
303
+ return { PI_MANAGED_SUBAGENT: JSON.stringify({ path: host.path, owner: host.current.ownerKey,
304
+ key: host.current.key, epoch: host.epoch, id: input.id, token: attempt.token }) };
305
+ },
306
+ spawned: (id, pid) => { host.journal.spawned(host.current.ownerKey, host.current.key, host.epoch, id, pid, processStartToken(pid)); setImmediate(() => host.healthChanged?.(id)); },
307
+ };
308
+ const cwd = this.root;
309
+ const settingsManager = SettingsManager.inMemory({});
310
+ const resourceLoader = new DefaultResourceLoader({ cwd, agentDir: this.root, settingsManager,
311
+ noExtensions: true, noSkills: true, noContextFiles: true, noPromptTemplates: true, noThemes: true,
312
+ extensionFactories: [(pi: ExtensionAPI) => {
313
+ const registered: any[] = [];
314
+ const adapterPi = { ...pi,
315
+ registerTool: (tool: any) => { registered.push(tool); pi.registerTool(tool); },
316
+ getAllTools: () => [...registered, ...pi.getAllTools()],
317
+ } as ExtensionAPI;
318
+ this.api = adapterPi;
319
+ this.workerHost = this.createWorkerHost?.(adapterPi);
320
+ if (this.workerHost) pi.on("session_start", (_event, ctx) => this.workerHost!.start(ctx));
321
+ extension(adapterPi, port);
322
+ }] });
323
+ await resourceLoader.reload();
324
+ const created = await createAgentSession({ cwd, agentDir: this.root, settingsManager, resourceLoader,
325
+ sessionManager: SessionManager.inMemory(cwd), noTools: "all" });
326
+ this.session = created.session;
327
+ const initializationErrors: string[] = [];
328
+ await this.session.bindExtensions({ mode: "print", onError: (error: any) => {
329
+ if (!initializationErrors.length) initializationErrors.push(String(error.error ?? error.message ?? error));
330
+ } });
331
+ if (initializationErrors.length) throw new Error(`Managed launch initialization failed: ${initializationErrors.join("; ")}`);
332
+ })();
333
+ }
334
+ private executionContext(record: any) {
335
+ const ctx = this.session.extensionRunner.createContext();
336
+ const branch = [...record.settings, ...(record.owner.goalId ? [{ type: "custom", customType: "pi-better-goal", data: { kind: "set", goal: { goalId: record.owner.goalId } } }] : []), { id: record.owner.branchId }];
337
+ const model = record.model?.split("/");
338
+ return { ...ctx, cwd: record.owner.workspace, hasUI: false, isProjectTrusted: () => record.projectTrusted,
339
+ model: model ? ctx.modelRegistry.find(model[0], model.slice(1).join("/")) : undefined,
340
+ sessionManager: { getSessionId: () => record.owner.sessionId, getBranch: () => branch, getLeafId: () => record.owner.branchId,
341
+ getSessionFile: () => undefined, getEntries: () => branch } };
342
+ }
343
+ private dispatchContinuation(park: any, run: () => Promise<"resumed" | "held" | "skipped">) {
344
+ const now = Date.now();
345
+ if (now - this.continuationWindow.started >= 1000) this.continuationWindow = { started: now, admitted: 0 };
346
+ if (this.continuationWindow.admitted >= 32) return Promise.resolve("skipped" as const);
347
+ const retryKey = `${park.waitId}:${park.generation}`;
348
+ const failure = this.continuationFailures.get(retryKey);
349
+ if (failure && Date.now() < failure.retryAt) return Promise.resolve("skipped" as const);
350
+ this.continuationWindow.admitted++;
351
+ this.pending++;
352
+ const requestId = ++this.requestSequence;
353
+ this.requestRecords.set(requestId, { kind: 'continuation-request', id: requestId, waitId: park.waitId, runId: park.runId,
354
+ generation: park.generation, lastProgressAt: now, executionDeadline: null, nextDeadline: null,
355
+ recovery: 'captured-continuation-serialized-by-current-launch-journal-owner' });
356
+ let dispatched = false;
357
+ const result = this.tail.catch(() => undefined).then(async () => {
358
+ const saved = this.journal.attempt(park.runId)?.launchAuthority;
359
+ if (!saved) throw new Error("Captured continuation launch authority unavailable");
360
+ const permissions = intersectContinuationPermissions(saved.permissions, this.readPermissions?.());
361
+ const key = `continuation:${park.waitId}:${park.generation}`;
362
+ this.current = { ...saved, key, baseKey: key, priorRunId: park.runId, continuation: true, launchAuthority: saved,
363
+ capturedPermissions: saved.permissions, permissions,
364
+ ownerKey: JSON.stringify([saved.owner.workspace, saved.owner.sessionId]),
365
+ digest: launchDigest({ key, runId: park.runId }) };
366
+ this.acceptedRequestLive = true;
367
+ this.api.events.emit("pi-better-sandbox:policy", { state: "enabled", ...permissions });
368
+ dispatched = true;
369
+ const outcome = await run();
370
+ if (outcome === "resumed") this.journal.finish(this.current.ownerKey, this.current.key, this.epoch, { status: outcome });
371
+ this.continuationFailures.delete(retryKey);
372
+ return outcome;
373
+ }).catch(error => {
374
+ const failures = Math.min(6, (this.continuationFailures.get(retryKey)?.failures ?? 0) + 1);
375
+ if (this.continuationFailures.size >= 128 && !this.continuationFailures.has(retryKey)) this.continuationFailures.delete(this.continuationFailures.keys().next().value!);
376
+ this.continuationFailures.set(retryKey, { failures, retryAt: Date.now() + Math.min(30000, 1000 * 2 ** (failures - 1)), reason: String(error).slice(0, 500) });
377
+ // Let orchestration persist its existing pre-spawn hold. A skipped
378
+ // result would leave this exact generation ready despite refusal.
379
+ if (!dispatched) throw error;
380
+ return "skipped" as const;
381
+ }).finally(() => { this.requestRecords.delete(requestId); this.acceptedRequestLive = false; this.pending--; });
382
+ this.tail = result;
383
+ return result;
384
+ }
385
+ private recoveredResult(intent: { attempts: string }) {
386
+ const ids = JSON.parse(intent.attempts).map(({ id }: any) => id);
387
+ const runs = ids.map((id: string) => readMeta(id));
388
+ const status = !ids.length ? "not_launched" : runs.every(Boolean) ? "recovered" : "outcome_unknown";
389
+ return { details: { status, attempts: ids, runs: runs.filter(Boolean).map((meta: any) => ({
390
+ runId: meta.id, sessionId: meta.sessionId, status: meta.status,
391
+ })) }, content: [{ type: "text", text: `Original launch ${status}; no replacement attempt was dispatched.` }] };
392
+ }
393
+ handle(command: Record<string, unknown>, onAccepted?: (id: string) => void) {
394
+ if (Object.keys(command).some(key => !["id", "type", "authority"].includes(key))) return Promise.reject(new Error("unsupported launch field"));
395
+ this.pending++;
396
+ const requestId = ++this.requestSequence;
397
+ this.requestRecords.set(requestId, { kind: 'launch-request', id: requestId, phase: 'queued-unaccepted',
398
+ lastProgressAt: Date.now(), executionDeadline: null, nextDeadline: null,
399
+ recovery: 'validate-captured-native-authority-before-admission-no-detached-execution-lease' });
400
+ const result = this.tail.catch(() => undefined).then(async () => {
401
+ const record = this.grant(command.authority);
402
+ // A retried tool call keeps its accepted recipient even after Goal/branch edits.
403
+ const ownerKey = JSON.stringify([record.owner.workspace, record.owner.sessionId]);
404
+ const digest = launchDigest({ tool: record.tool, params: record.params });
405
+ const intent = this.journal.accept(ownerKey, record.key, digest, this.epoch);
406
+ onAccepted?.(`launch-progress:${launchDigest([ownerKey, record.key])}`);
407
+ this.requestRecords.set(requestId, { ...this.requestRecords.get(requestId), phase: 'accepted',
408
+ operation: `launch-progress:${launchDigest([ownerKey, record.key])}`, lastProgressAt: Date.now() });
409
+ if (intent.prior) {
410
+ if (intent.result) return JSON.parse(intent.result);
411
+ return this.recoveredResult(intent);
412
+ }
413
+ try {
414
+ this.current = { ...record, authority: command.authority, ownerKey, grantDigest: launchDigest(record) };
415
+ this.acceptedRequestLive = true;
416
+ await this.initialize();
417
+ this.api.events.emit("pi-better-sandbox:policy", { state: "enabled", ...record.permissions });
418
+ const context = this.executionContext(record);
419
+ const tool = this.session.extensionRunner.getToolDefinition(record.tool);
420
+ if (!tool) throw new Error("Fixed subagent adapter unavailable");
421
+ const response = await tool.execute(record.key, record.params, undefined, undefined, context);
422
+ this.journal.finish(ownerKey, record.key, this.epoch, response);
423
+ return response;
424
+ } catch (error) {
425
+ const pending = this.journal.read(ownerKey, record.key);
426
+ if (pending?.state === "accepted" && JSON.parse(pending.attempts).length === 0) {
427
+ this.journal.finish(ownerKey, record.key, this.epoch, this.recoveredResult(pending));
428
+ }
429
+ throw error;
430
+ }
431
+ }).finally(() => { this.requestRecords.delete(requestId); this.acceptedRequestLive = false; this.pending--; });
432
+ this.tail = result;
433
+ return result;
434
+ }
435
+ /** One root mechanical worker; no coordinator connection or query mutations. */
436
+ foldTerminalFailures(ids: readonly string[]): Promise<void> {
437
+ let release: (() => void) | undefined;
438
+ let physicalExit: Promise<number> | undefined;
439
+ const result = this.tail.catch(() => undefined).then(async () => {
440
+ release = this.enterControl?.();
441
+ if (this.enterControl && !release) throw new Error("runtime-overloaded: failure fold source capacity");
442
+ this.journal.current(this.epoch);
443
+ if (Atomics.load(this.foldRevocation, 0)) throw new Error("failure-fold-owner-revoked");
444
+ if (this.failureWorkerError) throw this.failureWorkerError;
445
+ if (ids.length > 128) throw new Error("failure-fold-batch-overflow");
446
+ if (!this.failureWorker) {
447
+ const worker = this.failureWorker = new Worker(new URL("./managed-failure-worker.mjs", import.meta.url), {
448
+ execArgv: [], workerData: { root: this.root, epoch: this.epoch, revocation: this.foldRevocation.buffer },
449
+ });
450
+ const fail = (error: Error) => {
451
+ this.failureWorkerError = error;
452
+ this.failureResponse?.reject(error); this.failureResponse = undefined;
453
+ };
454
+ worker.on("message", message => {
455
+ const response = this.failureResponse; this.failureResponse = undefined;
456
+ if (message.error) response?.reject(new Error(message.error)); else response?.resolve();
457
+ });
458
+ worker.on("error", fail);
459
+ worker.on("exit", code => fail(new Error(`failure-fold-worker-exited: ${code}`)));
460
+ worker.unref();
461
+ }
462
+ let timer: ReturnType<typeof setTimeout> | undefined;
463
+ try {
464
+ await new Promise<void>((resolve, reject) => {
465
+ this.failureResponse = { resolve, reject };
466
+ this.foldRecord = { kind: 'failure-fold', ids: [...ids], lastProgressAt: Date.now(), nextDeadline: Date.now() + this.verificationMs,
467
+ recovery: 'revoke-unacknowledged-fold-generation-at-existing-verification-deadline' };
468
+ timer = setTimeout(() => {
469
+ const error = new Error("failure-fold-verification-deadline: source worker did not acknowledge");
470
+ Atomics.store(this.foldRevocation, 0, 1);
471
+ this.failureWorkerError = error;
472
+ this.failureResponse = undefined;
473
+ physicalExit = this.failureWorker?.terminate();
474
+ reject(error);
475
+ }, this.verificationMs);
476
+ this.failureWorker!.postMessage({ ids });
477
+ });
478
+ } finally { this.foldRecord = undefined; if (timer) clearTimeout(timer); }
479
+ }).finally(() => {
480
+ if (physicalExit) void physicalExit.then(() => release?.(), () => undefined);
481
+ else release?.();
482
+ });
483
+ this.tail = result;
484
+ return result;
485
+ }
486
+ async close() {
487
+ this.healthClose?.();
488
+ Atomics.store(this.foldRevocation, 0, 1);
489
+ await this.tail.catch(() => undefined);
490
+ await this.failureWorker?.terminate(); this.failureWorker = undefined;
491
+ if (failureFoldRevocations.get(this.root) === this.foldRevocation) failureFoldRevocations.delete(this.root);
492
+ const session = this.session;
493
+ this.session = undefined;
494
+ const workerHost = this.workerHost;
495
+ this.workerHost = undefined;
496
+ try {
497
+ if (session) await session.extensionRunner.emit({ type: "session_shutdown", reason: "quit" });
498
+ } finally {
499
+ try { workerHost?.close(); } finally {
500
+ try { session?.dispose(); } finally { this.closeJournal(); }
501
+ }
502
+ }
503
+ }
504
+ }
@@ -0,0 +1,17 @@
1
+ // Generated fixed launch domain from packages/pi-better-subagents/managed-launch-journal.mjs. Do not edit directly.
2
+ import { openStore } from "./shared-operation-coordinator/index.domain.mjs";
3
+ export { launchDigest } from "./launch-digest.mjs";
4
+ /** Standalone callers own a store; server callers pass their shared mutation lease. */
5
+ export function openLaunchJournal(path, sharedStore) {
6
+ const store = sharedStore ?? openStore({ path });
7
+ try {
8
+ const journal = store.subagentLaunchJournal();
9
+ return { journal, close: () => { if (!sharedStore)
10
+ store.close(); } };
11
+ }
12
+ catch (error) {
13
+ if (!sharedStore)
14
+ store.close();
15
+ throw error;
16
+ }
17
+ }
@@ -0,0 +1,29 @@
1
+ // Generated fixed launch domain from packages/pi-better-subagents/managed-launch-ownership.ts. Do not edit directly.
2
+ import { realProcessProbe } from "./health.domain.mjs";
3
+ /** Management transfer never treats timeout or absent identity as proof of death. */
4
+ export function assertSubagentHandoff(metas, root, probe = realProcessProbe) {
5
+ const evidence = (pid, start) => {
6
+ if (!pid || !probe.pidExists(pid))
7
+ return "gone";
8
+ const observed = probe.startToken(pid);
9
+ if (!start || !observed)
10
+ return "unknown";
11
+ return observed === start ? "live" : "gone";
12
+ };
13
+ for (const meta of metas) {
14
+ if (meta.status !== "running" && meta.status !== "orphaned")
15
+ continue;
16
+ if (!meta.management) {
17
+ if (evidence(meta.spawnPid, meta.spawnPidStartTime) !== "gone")
18
+ throw new Error(`legacy-manager-live-or-unknown: ${meta.id}`);
19
+ if (evidence(meta.pid, meta.pidStartTime) !== "gone")
20
+ throw new Error(`legacy-writer-live-or-unknown: ${meta.id}`);
21
+ }
22
+ else {
23
+ if (meta.management.root !== root)
24
+ continue;
25
+ if (evidence(meta.pid, meta.pidStartTime) === "unknown")
26
+ throw new Error(`writer-identity-unknown: ${meta.id}`);
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,22 @@
1
+ import { realProcessProbe, type ProcessProbe } from "./health.ts";
2
+ import type { RunMeta } from "./registry.ts";
3
+
4
+ /** Management transfer never treats timeout or absent identity as proof of death. */
5
+ export function assertSubagentHandoff(metas: readonly RunMeta[], root: string, probe: Pick<ProcessProbe, "pidExists" | "startToken"> = realProcessProbe): void {
6
+ const evidence = (pid: number | undefined, start: string | undefined) => {
7
+ if (!pid || !probe.pidExists(pid)) return "gone";
8
+ const observed = probe.startToken(pid);
9
+ if (!start || !observed) return "unknown";
10
+ return observed === start ? "live" : "gone";
11
+ };
12
+ for (const meta of metas) {
13
+ if (meta.status !== "running" && meta.status !== "orphaned") continue;
14
+ if (!meta.management) {
15
+ if (evidence(meta.spawnPid, meta.spawnPidStartTime) !== "gone") throw new Error(`legacy-manager-live-or-unknown: ${meta.id}`);
16
+ if (evidence(meta.pid, meta.pidStartTime) !== "gone") throw new Error(`legacy-writer-live-or-unknown: ${meta.id}`);
17
+ } else {
18
+ if (meta.management.root !== root) continue;
19
+ if (evidence(meta.pid, meta.pidStartTime) === "unknown") throw new Error(`writer-identity-unknown: ${meta.id}`);
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,2 @@
1
+ // Generated fixed launch domain from packages/pi-better-subagents/managed-launch-port.ts. Do not edit directly.
2
+ export {};
@@ -0,0 +1,25 @@
1
+ import type { CatalogHost } from "./catalog-runtime.ts";
2
+ import type { CatalogSnapshot } from "./catalog-store.ts";
3
+ import type { RunMeta } from "./registry.ts";
4
+
5
+ /** Fixed server adapter port; never deserialized from a socket request. */
6
+ export interface ManagedLaunchPort {
7
+ observeHealth?(reconcile: (ids: readonly string[]) => void): () => void;
8
+ activeProviders?(): Record<string, string>;
9
+ backgroundTools(): readonly string[];
10
+ readonly owner: { pid: number; start?: string };
11
+ readonly identity: { root: string; instance: string; epoch: number };
12
+ continuationContext?(): import("@earendil-works/pi-coding-agent").ExtensionContext | undefined;
13
+ dispatchContinuation?(park: import("./worker-waits.ts").ParkedWait, run: () => Promise<"resumed" | "held" | "skipped">): Promise<"resumed" | "held" | "skipped">;
14
+ supervised(): RunMeta[];
15
+ owns(meta: Partial<RunMeta>): boolean;
16
+ assertCurrent(): void;
17
+ capacity(countRunning: () => number): { readonly pending: number; tryReserve(count: number, cap: number): boolean; commit(count?: number): void; release(count?: number): void };
18
+ snapshot(host: CatalogHost): Promise<CatalogSnapshot>;
19
+ attempt(): string;
20
+ workerCommand(args: string[]): { file: string; fileArgs: string[] };
21
+ beforeSpawn(input: { id: string; sessionId: string; lease: string; leasePath: string; preflightPath: string; policyPath?: string; permissions: unknown; recoveryMeta: RunMeta; recipe: NonNullable<RunMeta["recipe"]> }): Record<string, string>;
22
+ spawned(id: string, pid: number): void;
23
+ /** Private fixture/owner observation, never a serialized execution capability. */
24
+ observeExit?(id: string, completion: Promise<void>): void;
25
+ }
@@ -0,0 +1,29 @@
1
+ // Generated fixed launch domain from packages/pi-better-subagents/managed-launch-recovery.ts. Do not edit directly.
2
+ /** Called only after replacing the management epoch, fencing every old bootstrap. */
3
+ export function recoverLaunchMetadata(attempt, management, evidence, now = Date.now()) {
4
+ const frozen = attempt.recoveryMeta;
5
+ if (!frozen || frozen.id !== attempt.id || frozen.sessionId !== attempt.sessionId || frozen.management?.root !== management.root) {
6
+ throw new Error(`launch-recovery-evidence-missing: ${attempt.id}`);
7
+ }
8
+ const pid = attempt.writerPid ?? attempt.pid;
9
+ const start = attempt.writerStartTime ?? attempt.pidStartTime;
10
+ if (attempt.bootstrapped && !pid)
11
+ throw new Error(`writer-identity-unknown: ${attempt.id}`);
12
+ if (pid && evidence.pidExists(pid)) {
13
+ const observed = evidence.startToken(pid);
14
+ if (!start || !observed)
15
+ throw new Error(`writer-identity-unknown: ${attempt.id}`);
16
+ if (observed === start) {
17
+ const lease = evidence.lease(attempt.sessionId);
18
+ if (!lease || lease.token !== attempt.lease || lease.attemptId !== attempt.id) {
19
+ throw new Error(`writer-authority-unknown: ${attempt.id}`);
20
+ }
21
+ }
22
+ }
23
+ // No recorded PID and no successful bootstrap means the superseded token can
24
+ // never execute task code. A dispatched writer retains ordinary health/log
25
+ // reconciliation, including process-group evidence and interrupted streams.
26
+ return { ...frozen, management, pid: pid ?? 0,
27
+ ...(pid ? { pidStartTime: start, pgid: pid } : { status: "lost", lostAt: now, endedAt: now }),
28
+ supervisionInterruptedAt: now, supervisionInterruptedReason: "runtime-launch-recovery" };
29
+ }