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
@@ -1,11 +1,97 @@
1
1
  // Generated fixed launch domain from packages/pi-better-subagents/shared-navigator.ts. Do not edit directly.
2
2
  import { truncateToWidth as piTruncateToWidth, visibleWidth as piVisibleWidth } from "@earendil-works/pi-tui";
3
+ import { readHarnessSetting, updateHarnessSetting } from "./shared-harness-settings.domain.mjs";
3
4
  import { createRenderScheduler } from "./shared-render-scheduler.domain.mjs";
4
5
  import { setNavigatorPanel } from "./shared-navigator-panels.domain.mjs";
5
6
  export default function navigatorExtension() {
6
7
  // Internal shared package. Pi may scan its symlink in the extension directory
7
8
  // for sibling relative imports; loading it directly should be harmless.
8
9
  }
10
+ export function getNavigatorView() { return state().view ?? "flatten"; }
11
+ export function loadNavigatorView() {
12
+ const value = readHarnessSetting("navigatorView");
13
+ state().view = value === "tree" ? "tree" : "flatten";
14
+ }
15
+ export function setNavigatorView(value) {
16
+ if (value !== "tree" && value !== "flatten")
17
+ throw new Error("View must be tree or flatten.");
18
+ updateHarnessSetting("navigatorView", () => value);
19
+ state().view = value;
20
+ refreshBackgroundWorkNavigator();
21
+ }
22
+ /** UI time is independent of worker time; repeated refreshes never renew it. */
23
+ export function createTerminalRowRetention(retentionMs = 30_000) {
24
+ const held = new Map();
25
+ const dismissed = new Set();
26
+ return {
27
+ clear() { held.clear(); dismissed.clear(); },
28
+ dismiss(id) { held.delete(id); dismissed.add(id); },
29
+ merge(rows, now) {
30
+ const result = [];
31
+ const present = new Set(rows.map(row => row.id));
32
+ for (const id of dismissed)
33
+ if (!present.has(id))
34
+ dismissed.delete(id);
35
+ for (const row of rows) {
36
+ if (dismissed.has(row.id))
37
+ continue;
38
+ const terminal = ["completed", "succeeded", "failed", "cancelled", "killed", "lost", "timed_out"].includes(row.status);
39
+ if (!terminal) {
40
+ held.delete(row.id);
41
+ result.push(row);
42
+ continue;
43
+ }
44
+ let entry = held.get(row.id);
45
+ if (!entry) {
46
+ entry = { row, until: now + retentionMs };
47
+ held.set(row.id, entry);
48
+ }
49
+ entry.row = { ...row, expiresAt: entry.until };
50
+ if (now < entry.until)
51
+ result.push(entry.row);
52
+ }
53
+ for (const [id, entry] of held) {
54
+ if (present.has(id))
55
+ continue;
56
+ if (now < entry.until)
57
+ result.push(entry.row);
58
+ else
59
+ held.delete(id);
60
+ }
61
+ return result;
62
+ },
63
+ };
64
+ }
65
+ /** A frontend-only diagnostic, never an execution record or authority to retry. */
66
+ export async function observeNavigatorLaunch(ctx, providerId, key, name, launch) {
67
+ const scope = JSON.stringify([ctx.cwd, ctx.sessionManager?.getSessionId?.()]);
68
+ const report = (error) => {
69
+ const s = state();
70
+ if (!isNavigatorUiAvailable(s.uiCtx) || s.observationScope !== scope)
71
+ return;
72
+ const id = `launch-error-${key}`;
73
+ const primary = error instanceof Error ? error.message : String(error);
74
+ const failures = s.launchFailures ??= new Map();
75
+ const identity = rowKey(providerId, id);
76
+ failures.set(identity, { providerId, id, name, status: "failed", statusTone: "failed", kind: "launch-error", elapsed: "", primary,
77
+ secondary: "Launch failed or was not confirmed; inspect before retrying.", sortStartedAt: Date.now() });
78
+ // Diagnostics are session-local and bounded, including expired tombstones.
79
+ if (failures.size > 128)
80
+ failures.delete(failures.keys().next().value);
81
+ refreshBackgroundWorkNavigator();
82
+ };
83
+ try {
84
+ const result = await launch();
85
+ const response = result;
86
+ if (response?.isError)
87
+ report(response.content?.filter(item => item.type === "text").map(item => item.text).join("\n") || "Launch request failed");
88
+ return result;
89
+ }
90
+ catch (error) {
91
+ report(error);
92
+ throw error;
93
+ }
94
+ }
9
95
  const GLOBAL_KEY = Symbol.for("pi-better-harness.navigator.state");
10
96
  const FACTORY_MARK = "__piBetterHarnessNavigatorFactory";
11
97
  const FACTORY_REFRESH = "__piBetterHarnessNavigatorRefresh";
@@ -96,6 +182,20 @@ export function ensureBackgroundWorkNavigator(ctx, deps, owner) {
96
182
  if (!isNavigatorUiAvailable(ctx))
97
183
  return;
98
184
  const s = state();
185
+ if (s.view === undefined) {
186
+ try {
187
+ loadNavigatorView();
188
+ }
189
+ catch {
190
+ s.view = "flatten";
191
+ }
192
+ }
193
+ const scope = JSON.stringify([ctx.cwd, ctx.sessionManager?.getSessionId?.()]);
194
+ if (s.observationScope !== scope) {
195
+ s.terminalRows?.clear();
196
+ s.launchFailures?.clear();
197
+ }
198
+ s.observationScope = scope;
99
199
  s.uiCtx = ctx;
100
200
  s.uiOwner = owner;
101
201
  s.deps = {
@@ -142,6 +242,9 @@ export function disposeBackgroundWorkNavigator(ctx, owner) {
142
242
  stopMainListWidget();
143
243
  const activeCtx = ctx ?? s.uiCtx;
144
244
  s.uiCtx = undefined;
245
+ s.terminalRows?.clear();
246
+ s.launchFailures?.clear();
247
+ s.observationScope = undefined;
145
248
  s.uiOwner = undefined;
146
249
  if (activeCtx && isNavigatorUiAvailable(activeCtx)) {
147
250
  try {
@@ -243,7 +346,7 @@ function refreshMainListWidget() {
243
346
  }
244
347
  if (!s.mainListWidgetInstalled) {
245
348
  try {
246
- setNavigatorPanel(ctx, MAIN_LIST_WIDGET_KEY, (tui, theme) => createMainListWidget(tui, theme, deps), { placement: "aboveEditor" });
349
+ setNavigatorPanel(ctx, MAIN_LIST_WIDGET_KEY, (tui, theme, layout) => createMainListWidget(tui, theme, deps, layout), { placement: "aboveEditor" });
247
350
  s.mainListWidgetInstalled = true;
248
351
  }
249
352
  catch { /* ignore */ }
@@ -266,7 +369,7 @@ const BACK_TO_MAIN = "← main (Esc)";
266
369
  const BACK_TARGET = "back-to-main";
267
370
  function highlightPointerTarget(theme, line, width) {
268
371
  const colors = theme;
269
- return colors?.bg?.("selectedBg", line + " ".repeat(Math.max(0, width - visibleWidth(line))))
372
+ return colors?.bg?.("selectedBg", line + " ".repeat(Math.max(0, width - piVisibleWidth(line))))
270
373
  ?? themeFgFromTheme(theme)("accent", line);
271
374
  }
272
375
  function createPointerNavigation(targetAt, activate) {
@@ -301,7 +404,7 @@ function createPointerNavigation(targetAt, activate) {
301
404
  },
302
405
  };
303
406
  }
304
- function createMainListWidget(tui, theme, deps) {
407
+ function createMainListWidget(tui, theme, deps, panelLayout = { availableRows: () => Infinity }) {
305
408
  const requestRender = () => tui.requestRender?.();
306
409
  state().mainListRequestRender = requestRender;
307
410
  // navigatorId per rendered line, so a pointer row resolves by structure, never by row text.
@@ -339,8 +442,23 @@ function createMainListWidget(tui, theme, deps) {
339
442
  }
340
443
  lineWidth = renderWidth(width);
341
444
  // The leading gap line belongs to the widget too, so its slot stays ownerless.
445
+ let rawLines = ["", ...layout.lines];
342
446
  lineOwners = [undefined, ...layout.owners];
343
- const lines = ["", ...layout.lines].map((line, index) => pointer.hovered && lineOwners[index] === pointer.hovered ? highlightPointerTarget(theme, line, lineWidth) : line);
447
+ const budget = Math.max(0, Math.floor(panelLayout.availableRows()));
448
+ if (rawLines.length > budget) {
449
+ const selected = state().mainListFocused ? lineOwners.indexOf(state().mainListSelectedId) : -1;
450
+ const count = Math.max(0, budget - 1);
451
+ const start = selected >= 0 ? Math.max(0, Math.min(selected - Math.floor(count / 2), rawLines.length - count)) : 2;
452
+ rawLines = rawLines.slice(start, start + count);
453
+ lineOwners = lineOwners.slice(start, start + count);
454
+ const visible = new Set(lineOwners.filter(Boolean));
455
+ if (budget > 0) {
456
+ const hidden = rows.length - visible.size;
457
+ rawLines.push(deps.truncate(hidden ? ` +${hidden} tasks` : ` ${rows.length} tasks`, renderWidth(width)));
458
+ lineOwners.push(undefined);
459
+ }
460
+ }
461
+ const lines = rawLines.map((line, index) => pointer.hovered && lineOwners[index] === pointer.hovered ? highlightPointerTarget(theme, line, lineWidth) : line);
344
462
  state().lastMainListLines = lines;
345
463
  return lines;
346
464
  },
@@ -383,6 +501,12 @@ function listRows(now = Date.now()) {
383
501
  catch {
384
502
  providerRows = [];
385
503
  }
504
+ providerRows = [...providerRows, ...[...(state().launchFailures?.values() ?? [])].filter(row => row.providerId === provider.id)];
505
+ const retention = state().terminalRows ??= new Map();
506
+ if (!retention.has(provider.id))
507
+ retention.set(provider.id, createTerminalRowRetention());
508
+ if (isNavigatorUiAvailable(state().uiCtx))
509
+ providerRows = retention.get(provider.id).merge(providerRows, now);
386
510
  const orderedProviderRows = [...providerRows].sort((a, b) => b.sortStartedAt - a.sortStartedAt || rowDisplayName(a).localeCompare(rowDisplayName(b)));
387
511
  let showSection = orderedProviderRows.length > 0 || provider.parentRow !== undefined;
388
512
  try {
@@ -391,7 +515,7 @@ function listRows(now = Date.now()) {
391
515
  catch {
392
516
  showSection = false;
393
517
  }
394
- if (!showSection)
518
+ if (!showSection && !(getNavigatorView() === "tree" && provider.parentRow))
395
519
  continue;
396
520
  let parentRow = null;
397
521
  try {
@@ -412,7 +536,51 @@ function listRows(now = Date.now()) {
412
536
  rows.push({ ...row, navigatorId: rowKey(provider.id, row.id), providerLabel: provider.label });
413
537
  }
414
538
  }
415
- return rows;
539
+ const conversations = mergeAgentAttempts(rows);
540
+ return getNavigatorView() === "tree" ? treeRows(conversations) : conversations;
541
+ }
542
+ /** A resumed execution is still the same agent in either layout. */
543
+ export function mergeAgentAttempts(rows) {
544
+ const latest = new Map();
545
+ for (const row of rows) {
546
+ if (row.providerId !== "subagents" || !row.agentId)
547
+ continue;
548
+ const previous = latest.get(row.agentId);
549
+ if (!previous || row.sortStartedAt > previous.sortStartedAt
550
+ || (row.sortStartedAt === previous.sortStartedAt && row.id > previous.id))
551
+ latest.set(row.agentId, row);
552
+ }
553
+ return rows.filter(row => row.providerId !== "subagents" || !row.agentId || latest.get(row.agentId) === row);
554
+ }
555
+ /** Two levels only: agents are peers, tasks attach by captured conversation. */
556
+ export function treeRows(rows) {
557
+ const agents = new Map();
558
+ for (const row of rows.filter(row => row.providerId === "subagents")) {
559
+ const key = row.agentId ?? row.id;
560
+ const prior = agents.get(key);
561
+ if (!prior || row.sortStartedAt > prior.sortStartedAt)
562
+ agents.set(key, row);
563
+ }
564
+ const tasks = rows.filter(row => row.providerId !== "subagents");
565
+ const ordered = [...agents.entries()].sort(([a], [b]) => a === "main" ? -1 : b === "main" ? 1 : 0);
566
+ const result = [], attached = new Set();
567
+ for (const [key, agent] of ordered) {
568
+ const children = tasks.filter(row => (row.parentAgentId ?? "main") === key);
569
+ result.push({ ...agent, treeDepth: 0 });
570
+ children.forEach((row, i) => { result.push({ ...row, treeDepth: 1, lastChild: i === children.length - 1 }); attached.add(row); });
571
+ }
572
+ // Never hide live work when its owner's observation has not arrived yet.
573
+ const missing = new Map();
574
+ for (const row of tasks)
575
+ if (!attached.has(row)) {
576
+ const key = row.parentAgentId ?? "main";
577
+ missing.set(key, [...(missing.get(key) ?? []), row]);
578
+ }
579
+ for (const [key, children] of missing)
580
+ children.forEach((row, i) => result.push({ ...row,
581
+ treeDepth: 1, lastChild: i === children.length - 1,
582
+ ownerGroupLabel: i === 0 ? (key === "main" ? "Main" : `Agent ${key} · not running`) : undefined }));
583
+ return result;
416
584
  }
417
585
  function rowDisplayName(row) {
418
586
  return singleLine(row.name || row.id);
@@ -476,6 +644,17 @@ function buildMainListLayout(rows, width, truncate, fg, options = {}) {
476
644
  lines.push(line);
477
645
  owners.push(owner);
478
646
  };
647
+ if (getNavigatorView() === "tree") {
648
+ push(providerGroupLabel("work", fg));
649
+ for (const row of rows) {
650
+ if (row.ownerGroupLabel)
651
+ push(` ${dim(row.ownerGroupLabel, fg)}`);
652
+ push(formatMainListRow(row, options.focused === true && row.navigatorId === options.selectedId, fg, width), row.navigatorId);
653
+ }
654
+ push("");
655
+ push(shortcutsLine(options.focused === true, fg));
656
+ return { lines: lines.map(line => safeTruncate(line, width, truncate)), owners };
657
+ }
479
658
  const grouped = new Map();
480
659
  for (const row of rows) {
481
660
  const existing = grouped.get(row.providerLabel) ?? [];
@@ -502,8 +681,9 @@ function buildMainListLayout(rows, width, truncate, fg, options = {}) {
502
681
  return { lines: lines.map((line) => safeTruncate(line, width, truncate)), owners };
503
682
  }
504
683
  function shortcutsLine(focused, fg) {
684
+ const selected = state().mainListRows?.find(row => row.navigatorId === state().mainListSelectedId);
505
685
  const keys = focused
506
- ? "↑↓ switch · Enter detail · x stop · Esc unfocus"
686
+ ? `↑↓ switch · Enter detail${selected?.readOnly || selected?.parentRow ? "" : " · x stop"} · Esc unfocus`
507
687
  : "← work navigator";
508
688
  return dim(keys, fg);
509
689
  }
@@ -512,22 +692,22 @@ function providerGroupLabel(label, fg) {
512
692
  return fg("warning", normalized);
513
693
  }
514
694
  function formatMainListRow(row, selected, fg, width) {
515
- const prefix = selected ? fg("accent", "› ") : " ";
695
+ const prefix = (selected ? fg("accent", "› ") : " ") + (row.treeDepth === 1 ? dim(` ${row.lastChild ? "└─" : "├─"} `, fg) : "");
516
696
  const name = row.name || row.id;
517
697
  const indicator = statusIndicator(row);
518
698
  const status = fg(indicator.color, indicator.glyph);
519
699
  const elapsed = singleLine(row.elapsed || "-");
520
700
  const available = Math.max(24, width || MAIN_LIST_FALLBACK_WIDTH);
521
- const elapsedWidth = Math.min(Math.max(visibleWidth(elapsed), 4), 12);
701
+ const elapsedWidth = Math.min(Math.max(piVisibleWidth(elapsed), 4), 12);
522
702
  const statusWidth = 2;
523
- const leftPrefixWidth = visibleWidth(prefix) + statusWidth + 1;
703
+ const leftPrefixWidth = piVisibleWidth(prefix) + statusWidth + 1;
524
704
  const maxNameWidth = Math.max(8, Math.floor(available * 0.36));
525
705
  const nameWidth = Math.max(8, Math.min(44, maxNameWidth, available - leftPrefixWidth - elapsedWidth - 10));
526
706
  const rightWidth = Math.max(8, available - leftPrefixWidth - nameWidth - 1);
527
707
  const summaryWidth = Math.max(1, rightWidth - elapsedWidth - 1);
528
708
  const left = `${prefix}${fit(status, statusWidth)} ${fit(name, nameWidth)}`;
529
709
  const right = `${dim(fitRight(rowSummary(row), summaryWidth), fg)} ${fitRight(elapsed, elapsedWidth)}`;
530
- const gap = Math.max(1, available - visibleWidth(left) - visibleWidth(right));
710
+ const gap = Math.max(1, available - piVisibleWidth(left) - piVisibleWidth(right));
531
711
  return `${left}${" ".repeat(gap)}${right}`;
532
712
  }
533
713
  function statusGlyph(row) {
@@ -545,16 +725,20 @@ function statusIndicator(row, now = Date.now()) {
545
725
  void now;
546
726
  if (row.statusTone !== "running")
547
727
  return { glyph: statusGlyph(row), color: toneColor(row.statusTone, row.status) };
548
- return { glyph: RUNNING_DOT_GLYPH, color: "accent" };
728
+ const glyph = row.treeDepth === 1 && row.providerId === "background-tasks" ? ">_" : RUNNING_DOT_GLYPH;
729
+ return { glyph, color: "accent" };
549
730
  }
550
731
  function mainListSignature(rows, options = {}) {
551
732
  return JSON.stringify({
733
+ view: getNavigatorView(),
552
734
  focused: options.focused === true,
553
735
  closeHint: options.closeHint ?? null,
554
736
  selectedId: options.focused === true ? options.selectedId ?? null : null,
555
737
  rows: rows.map((row) => ({
556
738
  navigatorId: row.navigatorId,
557
739
  providerLabel: row.providerLabel,
740
+ parentAgentId: row.parentAgentId,
741
+ agentId: row.agentId,
558
742
  parentRow: row.parentRow === true,
559
743
  providerId: row.providerId,
560
744
  id: row.id,
@@ -578,6 +762,9 @@ function stableFacts(facts) {
578
762
  return (facts ?? []).filter((fact) => !/\bleft$/.test(singleLine(fact)));
579
763
  }
580
764
  function rowSummary(row) {
765
+ if (getNavigatorView() === "tree" && row.providerId === "background-tasks") {
766
+ return [singleLine(row.status).replaceAll("_", " "), ...(row.facts ?? []).map(singleLine)].join(" · ");
767
+ }
581
768
  if (row.providerId === "subagents") {
582
769
  const attention = row.facts?.map(singleLine).filter(Boolean);
583
770
  if (attention?.length)
@@ -622,16 +809,16 @@ function rowSummary(row) {
622
809
  }
623
810
  function fit(value, width) {
624
811
  const str = singleLine(value);
625
- const visible = visibleWidth(str);
626
- if (visible >= width)
627
- return truncateVisible(str, width);
812
+ const visible = piVisibleWidth(str);
813
+ if (visible > width)
814
+ return piTruncateToWidth(str, width);
628
815
  return str + " ".repeat(width - visible);
629
816
  }
630
817
  function fitRight(value, width) {
631
818
  const str = singleLine(value);
632
- const visible = visibleWidth(str);
633
- if (visible >= width)
634
- return truncateVisible(str, width);
819
+ const visible = piVisibleWidth(str);
820
+ if (visible > width)
821
+ return piTruncateToWidth(str, width);
635
822
  return " ".repeat(width - visible) + str;
636
823
  }
637
824
  function singleLine(value) {
@@ -646,6 +833,9 @@ function prepareDetail(navigatorId, options) {
646
833
  }
647
834
  function detailFor(navigatorId, now = Date.now(), options) {
648
835
  const { providerId, id } = splitRowKey(navigatorId);
836
+ const failed = state().launchFailures?.get(navigatorId);
837
+ if (failed)
838
+ return { providerId, id, title: failed.name ?? "Launch failed", status: "failed", statusTone: "failed", metadata: [], evidence: { label: "Launch error", text: failed.primary } };
649
839
  const provider = state().providers.get(providerId);
650
840
  if (!provider)
651
841
  return null;
@@ -657,20 +847,29 @@ function detailFor(navigatorId, now = Date.now(), options) {
657
847
  }
658
848
  }
659
849
  function closeFor(row) {
660
- if (row.parentRow)
850
+ if (row.parentRow || row.readOnly)
661
851
  return { action: "not-closable", providerId: row.providerId, id: row.id };
662
852
  const provider = state().providers.get(row.providerId);
853
+ if (state().launchFailures?.delete(row.navigatorId)) {
854
+ state().terminalRows?.get(row.providerId)?.dismiss(row.id);
855
+ return { action: "dismissed", providerId: row.providerId, id: row.id };
856
+ }
663
857
  if (!provider)
664
858
  return { action: "missing", providerId: row.providerId, id: row.id };
665
859
  try {
666
- return provider.close(row.id);
860
+ const outcome = provider.close(row.id);
861
+ if (["dismissed", "stopped-and-dismissed"].includes(outcome.action)
862
+ || outcome.action === "requested" && ["completed", "succeeded", "failed", "cancelled", "killed", "lost", "timed_out"].includes(row.status)) {
863
+ state().terminalRows?.get(row.providerId)?.dismiss(row.id);
864
+ }
865
+ return outcome;
667
866
  }
668
867
  catch {
669
868
  return { action: "missing", providerId: row.providerId, id: row.id };
670
869
  }
671
870
  }
672
871
  function closeHintFor(row) {
673
- if (!row || row.parentRow)
872
+ if (!row || row.parentRow || row.readOnly)
674
873
  return null;
675
874
  const provider = state().providers.get(row.providerId);
676
875
  if (!provider)
@@ -702,29 +901,49 @@ function installNavigatorEditor(ui, deps) {
702
901
  function wrapEditor(inner, deps) {
703
902
  if (inner && typeof inner.render === "function")
704
903
  state().editorComponent = inner;
904
+ const methods = new Map();
905
+ const replacements = new Map();
705
906
  const proxy = new Proxy(inner, {
706
907
  get(target, prop) {
908
+ const value = Reflect.get(target, prop);
909
+ if (typeof value !== "function" || replacements.get(prop) === value)
910
+ return value;
911
+ const cached = methods.get(prop);
912
+ if (cached && cached.original === value)
913
+ return cached.exposed;
914
+ // Capture the method before another editor decorator replaces it.
915
+ // A decorator can retain this wrapper and call it as its delegate.
916
+ let exposed = value.bind(target);
707
917
  if (prop === "handleInput") {
708
- return (data) => {
918
+ exposed = (data) => {
709
919
  if (target.getText?.() === "" && handleMainListInput(data, deps)) {
710
920
  return;
711
921
  }
712
- target.handleInput(data);
922
+ value.call(target, data);
713
923
  };
714
924
  }
715
- if (prop === "render" && typeof target.render === "function") {
716
- return (...args) => {
925
+ if (prop === "render") {
926
+ exposed = (...args) => {
717
927
  const s = state();
718
928
  if (s.editorFocusTarget === proxy)
719
929
  s.editorRenders = (s.editorRenders ?? 0) + 1;
720
- return target.render(...args);
930
+ return value.apply(target, args);
721
931
  };
722
932
  }
723
- const value = Reflect.get(target, prop);
724
- return typeof value === "function" ? value.bind(target) : value;
933
+ methods.set(prop, { original: value, exposed });
934
+ return exposed;
725
935
  },
726
936
  set(target, prop, value) {
727
- return Reflect.set(target, prop, value);
937
+ const cached = methods.get(prop);
938
+ const restoring = cached !== undefined && value === cached.exposed;
939
+ if (!Reflect.set(target, prop, restoring ? cached.original : value))
940
+ return false;
941
+ // Preserve replacement identity so the installing decorator can undo it.
942
+ if (!restoring && typeof value === "function")
943
+ replacements.set(prop, value);
944
+ else
945
+ replacements.delete(prop);
946
+ return true;
728
947
  },
729
948
  });
730
949
  // Pi mounts and focuses whatever the factory returns; an extension that
@@ -734,6 +953,10 @@ function wrapEditor(inner, deps) {
734
953
  }
735
954
  function handleMainListInput(data, deps) {
736
955
  const s = state();
956
+ if (!s.mainListFocused && deps.isOpenTrigger(data)) {
957
+ for (const provider of s.providers.values())
958
+ provider.onOpen?.();
959
+ }
737
960
  const rows = listRows();
738
961
  if (rows.length === 0) {
739
962
  // Every row is gone, but an overlay that lost focus may still be mounted: Esc still closes it.
@@ -813,7 +1036,7 @@ function dismissOverlay() {
813
1036
  }
814
1037
  function handleMainListCloseKey() {
815
1038
  const row = selectedMainListRow();
816
- if (!row || row.parentRow)
1039
+ if (!row || row.parentRow || row.readOnly)
817
1040
  return;
818
1041
  const s = state();
819
1042
  const now = Date.now();
@@ -855,6 +1078,8 @@ function openNavigator() {
855
1078
  const deps = s.deps;
856
1079
  if (!ctx || !deps || !isNavigatorUiAvailable(ctx))
857
1080
  return;
1081
+ for (const provider of s.providers.values())
1082
+ provider.onOpen?.();
858
1083
  const rows = listRows();
859
1084
  if (rows.length === 0)
860
1085
  return;
@@ -932,6 +1157,8 @@ function openNavigator() {
932
1157
  catch { /* keep foreground usable */ }
933
1158
  }
934
1159
  function createOverlayComponent(initialRows, deps, tui, theme, done, onClosed, initialDetailId) {
1160
+ let editorRendersSeen = state().editorRenders ?? 0;
1161
+ let sawLiveEditor = liveEditorMounted(tui) === true;
935
1162
  // The overlay only ever shows one row's detail; the rail below it is the list.
936
1163
  const overlayState = { rows: initialRows, selected: 0 };
937
1164
  let logTailRows = DEFAULT_LOG_TAIL_ROWS;
@@ -1056,7 +1283,7 @@ function createOverlayComponent(initialRows, deps, tui, theme, done, onClosed, i
1056
1283
  }
1057
1284
  function handleCloseKey() {
1058
1285
  const row = selectedRow();
1059
- if (!row || row.parentRow)
1286
+ if (!row || row.parentRow || row.readOnly)
1060
1287
  return;
1061
1288
  const now = Date.now();
1062
1289
  if (closeArm?.id === row.navigatorId && now >= closeArm.armedAt && now < closeArm.armedAt + CLOSE_ARM_MS) {
@@ -1091,19 +1318,24 @@ function createOverlayComponent(initialRows, deps, tui, theme, done, onClosed, i
1091
1318
  closeArmTimer.unref?.();
1092
1319
  requestRender();
1093
1320
  }
1094
- let editorRendersSeen;
1095
1321
  /**
1096
- * Our editor wrapper was uninstalled: close, since no key of ours can reach this overlay again and
1097
- * it would cover the editor that replaced ours (#332). An extension that composes the editor inside
1098
- * its own non-container component still renders ours, so the wrapper also counts as live while it
1099
- * rendered since the previous overlay frame (Pi renders the editor before it composites overlays).
1322
+ * Close when a replacement editor takes over while the sheet is open (#332).
1323
+ * A wrapper inside another extension's editor still counts as live if it rendered since
1324
+ * the last overlay frame. Pi renders the editor before it composites overlays.
1100
1325
  */
1101
1326
  function closeIfEditorReplaced() {
1102
- const rendersBefore = editorRendersSeen;
1103
1327
  const renders = state().editorRenders ?? 0;
1328
+ const rendered = renders !== editorRendersSeen;
1104
1329
  editorRendersSeen = renders;
1105
- state().editorRenderedLastFrame = rendersBefore === undefined ? undefined : renders !== rendersBefore;
1106
- if (closed || liveEditorMounted(tui) !== false || rendersBefore === undefined || renders !== rendersBefore)
1330
+ state().editorRenderedLastFrame = rendered;
1331
+ if (closed)
1332
+ return;
1333
+ const mounted = liveEditorMounted(tui);
1334
+ if (rendered || mounted === true) {
1335
+ sawLiveEditor = true;
1336
+ return;
1337
+ }
1338
+ if (mounted !== false || !sawLiveEditor)
1107
1339
  return;
1108
1340
  // Not from inside pi-tui's render pass: hiding an overlay there would change the stack it is drawing.
1109
1341
  queueMicrotask(() => {
@@ -1634,10 +1866,10 @@ function fill(glyph, label, width) {
1634
1866
  return prefix + glyph.repeat(w - visibleWidth(prefix));
1635
1867
  }
1636
1868
  function safeTruncate(line, width, truncate) {
1637
- if (visibleWidth(line) <= width)
1869
+ if (piVisibleWidth(line) <= width)
1638
1870
  return line;
1639
1871
  const cut = truncate(line, width);
1640
- return visibleWidth(cut) > width ? truncateVisible(cut, width) : cut;
1872
+ return piVisibleWidth(cut) > width ? piTruncateToWidth(cut, width) : cut;
1641
1873
  }
1642
1874
  const ANSI_RE = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
1643
1875
  const FORMATTING_PREFIX_RE = new RegExp(`^(?:${ANSI_RE.source}|<\\/?[a-zA-Z][\\w-]*>|</>)`);