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,19 +1,41 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { truncateToWidth as piTruncateToWidth, visibleWidth as piVisibleWidth } from "@earendil-works/pi-tui";
3
+ import { readHarnessSetting, updateHarnessSetting } from "./shared-harness-settings.ts";
3
4
  import type { Component } from "@earendil-works/pi-tui";
4
5
  import { createRenderScheduler, type RenderScheduler } from "./shared-render-scheduler.ts";
5
- import { setNavigatorPanel } from "./shared-navigator-panels.ts";
6
+ import { setNavigatorPanel, type NavigatorPanelLayout } from "./shared-navigator-panels.ts";
6
7
 
7
8
  export default function navigatorExtension(): void {
8
9
  // Internal shared package. Pi may scan its symlink in the extension directory
9
10
  // for sibling relative imports; loading it directly should be harmless.
10
11
  }
11
12
 
13
+ export type NavigatorView = "tree" | "flatten";
14
+ export function getNavigatorView(): NavigatorView { return state().view ?? "flatten"; }
15
+ export function loadNavigatorView(): void {
16
+ const value = readHarnessSetting("navigatorView");
17
+ state().view = value === "tree" ? "tree" : "flatten";
18
+ }
19
+ export function setNavigatorView(value: string): void {
20
+ if (value !== "tree" && value !== "flatten") throw new Error("View must be tree or flatten.");
21
+ updateHarnessSetting("navigatorView", () => value);
22
+ state().view = value;
23
+ refreshBackgroundWorkNavigator();
24
+ }
25
+
12
26
  export type BackgroundWorkStatusTone = "running" | "success" | "failed" | "warning" | "muted";
13
27
 
14
28
  export type BackgroundWorkRow = {
15
29
  providerId: string;
16
30
  id: string;
31
+ /** Stable worker conversation identity, independent of execution attempts. */
32
+ agentId?: string;
33
+ parentAgentId?: string;
34
+ readOnly?: boolean;
35
+ treeDepth?: number;
36
+ lastChild?: boolean;
37
+
38
+ ownerGroupLabel?: string;
17
39
  name?: string;
18
40
  model?: string;
19
41
  effort?: string;
@@ -70,9 +92,65 @@ export type BackgroundWorkProvider = {
70
92
  close(id: string): BackgroundWorkCloseOutcome;
71
93
  /** Return true when this detail handled the key. The navigator refreshes the sheet. */
72
94
  handleDetailInput?(id: string, data: string): boolean;
95
+ /** An explicit navigator interaction may attach a deferred work subscription. */
96
+ onOpen?(): void;
73
97
  onVisibleChanged?(notify: () => void): () => void;
74
98
  };
75
99
 
100
+ /** UI time is independent of worker time; repeated refreshes never renew it. */
101
+ export function createTerminalRowRetention(retentionMs = 30_000) {
102
+ const held = new Map<string, { row: BackgroundWorkRow; until: number }>();
103
+ const dismissed = new Set<string>();
104
+ return {
105
+ clear() { held.clear(); dismissed.clear(); },
106
+ dismiss(id: string) { held.delete(id); dismissed.add(id); },
107
+ merge(rows: BackgroundWorkRow[], now: number): BackgroundWorkRow[] {
108
+ const result: BackgroundWorkRow[] = [];
109
+ const present = new Set(rows.map(row => row.id));
110
+ for (const id of dismissed) if (!present.has(id)) dismissed.delete(id);
111
+ for (const row of rows) {
112
+ if (dismissed.has(row.id)) continue;
113
+ const terminal = ["completed", "succeeded", "failed", "cancelled", "killed", "lost", "timed_out"].includes(row.status);
114
+ if (!terminal) { held.delete(row.id); result.push(row); continue; }
115
+ let entry = held.get(row.id);
116
+ if (!entry) { entry = {row, until: now + retentionMs}; held.set(row.id, entry); }
117
+ entry.row = {...row, expiresAt: entry.until};
118
+ if (now < entry.until) result.push(entry.row);
119
+ }
120
+ for (const [id, entry] of held) {
121
+ if (present.has(id)) continue;
122
+ if (now < entry.until) result.push(entry.row);
123
+ else held.delete(id);
124
+ }
125
+ return result;
126
+ },
127
+ };
128
+ }
129
+
130
+ /** A frontend-only diagnostic, never an execution record or authority to retry. */
131
+ export async function observeNavigatorLaunch<T>(ctx: ExtensionContext, providerId: string, key: string, name: string, launch: () => Promise<T>): Promise<T> {
132
+ const scope = JSON.stringify([ctx.cwd, ctx.sessionManager?.getSessionId?.()]);
133
+ const report = (error: unknown) => {
134
+ const s = state();
135
+ if (!isNavigatorUiAvailable(s.uiCtx) || s.observationScope !== scope) return;
136
+ const id = `launch-error-${key}`;
137
+ const primary = error instanceof Error ? error.message : String(error);
138
+ const failures = s.launchFailures ??= new Map();
139
+ const identity = rowKey(providerId, id);
140
+ failures.set(identity, {providerId, id, name, status: "failed", statusTone: "failed", kind: "launch-error", elapsed: "", primary,
141
+ secondary: "Launch failed or was not confirmed; inspect before retrying.", sortStartedAt: Date.now()});
142
+ // Diagnostics are session-local and bounded, including expired tombstones.
143
+ if (failures.size > 128) failures.delete(failures.keys().next().value!);
144
+ refreshBackgroundWorkNavigator();
145
+ };
146
+ try {
147
+ const result = await launch();
148
+ const response = result as {isError?: boolean; content?: {type: string; text?: string}[]};
149
+ if (response?.isError) report(response.content?.filter(item => item.type === "text").map(item => item.text).join("\n") || "Launch request failed");
150
+ return result;
151
+ } catch (error) { report(error); throw error; }
152
+ }
153
+
76
154
  type HostDeps = {
77
155
  createDefaultEditor: (tui: unknown, theme: unknown, keybindings: unknown) => unknown;
78
156
  isOpenTrigger: (data: string) => boolean;
@@ -83,6 +161,10 @@ type HostDeps = {
83
161
 
84
162
  type NavigatorState = {
85
163
  providers: Map<string, BackgroundWorkProvider>;
164
+ view?: NavigatorView;
165
+ terminalRows?: Map<string, ReturnType<typeof createTerminalRowRetention>>;
166
+ launchFailures?: Map<string, BackgroundWorkRow>;
167
+ observationScope?: string;
86
168
  registrationTokens?: Map<string, symbol>;
87
169
  unsubscribers: Map<string, () => void>;
88
170
  uiCtx?: ExtensionContext;
@@ -202,6 +284,10 @@ export function applyCloseConfirmFooter(ui: { setStatus(key: string, value: stri
202
284
  export function ensureBackgroundWorkNavigator(ctx: ExtensionContext, deps: HostDeps, owner?: symbol): void {
203
285
  if (!isNavigatorUiAvailable(ctx)) return;
204
286
  const s = state();
287
+ if (s.view === undefined) { try { loadNavigatorView(); } catch { s.view = "flatten"; } }
288
+ const scope = JSON.stringify([ctx.cwd, ctx.sessionManager?.getSessionId?.()]);
289
+ if (s.observationScope !== scope) { s.terminalRows?.clear(); s.launchFailures?.clear(); }
290
+ s.observationScope = scope;
205
291
  s.uiCtx = ctx;
206
292
  s.uiOwner = owner;
207
293
  s.deps = {
@@ -239,6 +325,9 @@ export function disposeBackgroundWorkNavigator(ctx?: ExtensionContext, owner?: s
239
325
  stopMainListWidget();
240
326
  const activeCtx = ctx ?? s.uiCtx;
241
327
  s.uiCtx = undefined;
328
+ s.terminalRows?.clear();
329
+ s.launchFailures?.clear();
330
+ s.observationScope = undefined;
242
331
  s.uiOwner = undefined;
243
332
  if (activeCtx && isNavigatorUiAvailable(activeCtx)) {
244
333
  try { setNavigatorPanel(activeCtx, MAIN_LIST_WIDGET_KEY, undefined); } catch { /* ignore */ }
@@ -328,7 +417,7 @@ function refreshMainListWidget(): void {
328
417
  }
329
418
  if (!s.mainListWidgetInstalled) {
330
419
  try {
331
- setNavigatorPanel(ctx, MAIN_LIST_WIDGET_KEY, (tui: { requestRender?(): void }, theme: unknown) => createMainListWidget(tui, theme, deps), { placement: "aboveEditor" });
420
+ setNavigatorPanel(ctx, MAIN_LIST_WIDGET_KEY, (tui: { requestRender?(): void }, theme: unknown, layout) => createMainListWidget(tui, theme, deps, layout), { placement: "aboveEditor" });
332
421
  s.mainListWidgetInstalled = true;
333
422
  } catch { /* ignore */ }
334
423
  }
@@ -371,7 +460,7 @@ const BACK_TARGET = "back-to-main";
371
460
 
372
461
  function highlightPointerTarget(theme: unknown, line: string, width: number): string {
373
462
  const colors = theme as { bg?(color: string, value: string): string } | undefined;
374
- return colors?.bg?.("selectedBg", line + " ".repeat(Math.max(0, width - visibleWidth(line))))
463
+ return colors?.bg?.("selectedBg", line + " ".repeat(Math.max(0, width - piVisibleWidth(line))))
375
464
  ?? themeFgFromTheme(theme)("accent", line);
376
465
  }
377
466
 
@@ -406,7 +495,7 @@ function createPointerNavigation(targetAt: (event: WidgetMouseEvent) => string |
406
495
  };
407
496
  }
408
497
 
409
- function createMainListWidget(tui: { requestRender?(): void }, theme: unknown, deps: HostDeps): MainListWidget {
498
+ function createMainListWidget(tui: { requestRender?(): void }, theme: unknown, deps: HostDeps, panelLayout: NavigatorPanelLayout = { availableRows: () => Infinity }): MainListWidget {
410
499
  const requestRender = () => tui.requestRender?.();
411
500
  state().mainListRequestRender = requestRender;
412
501
  // navigatorId per rendered line, so a pointer row resolves by structure, never by row text.
@@ -439,8 +528,23 @@ function createMainListWidget(tui: { requestRender?(): void }, theme: unknown, d
439
528
  if (hint) { layout.lines.push(deps.truncate(` ${hint}`, renderWidth(width))); layout.owners.push(undefined); }
440
529
  lineWidth = renderWidth(width);
441
530
  // The leading gap line belongs to the widget too, so its slot stays ownerless.
531
+ let rawLines = ["", ...layout.lines];
442
532
  lineOwners = [undefined, ...layout.owners];
443
- const lines = ["", ...layout.lines].map((line, index) =>
533
+ const budget = Math.max(0, Math.floor(panelLayout.availableRows()));
534
+ if (rawLines.length > budget) {
535
+ const selected = state().mainListFocused ? lineOwners.indexOf(state().mainListSelectedId) : -1;
536
+ const count = Math.max(0, budget - 1);
537
+ const start = selected >= 0 ? Math.max(0, Math.min(selected - Math.floor(count / 2), rawLines.length - count)) : 2;
538
+ rawLines = rawLines.slice(start, start + count);
539
+ lineOwners = lineOwners.slice(start, start + count);
540
+ const visible = new Set(lineOwners.filter(Boolean));
541
+ if (budget > 0) {
542
+ const hidden = rows.length - visible.size;
543
+ rawLines.push(deps.truncate(hidden ? ` +${hidden} tasks` : ` ${rows.length} tasks`, renderWidth(width)));
544
+ lineOwners.push(undefined);
545
+ }
546
+ }
547
+ const lines = rawLines.map((line, index) =>
444
548
  pointer.hovered && lineOwners[index] === pointer.hovered ? highlightPointerTarget(theme, line, lineWidth) : line);
445
549
  state().lastMainListLines = lines;
446
550
  return lines;
@@ -483,10 +587,14 @@ function listRows(now = Date.now()): InternalRow[] {
483
587
  for (const provider of providers()) {
484
588
  let providerRows: BackgroundWorkRow[] = [];
485
589
  try { providerRows = provider.listRows(now) ?? []; } catch { providerRows = []; }
590
+ providerRows = [...providerRows, ...[...(state().launchFailures?.values() ?? [])].filter(row => row.providerId === provider.id)];
591
+ const retention = state().terminalRows ??= new Map();
592
+ if (!retention.has(provider.id)) retention.set(provider.id, createTerminalRowRetention());
593
+ if (isNavigatorUiAvailable(state().uiCtx)) providerRows = retention.get(provider.id)!.merge(providerRows, now);
486
594
  const orderedProviderRows = [...providerRows].sort((a, b) => b.sortStartedAt - a.sortStartedAt || rowDisplayName(a).localeCompare(rowDisplayName(b)));
487
595
  let showSection = orderedProviderRows.length > 0 || provider.parentRow !== undefined;
488
596
  try { showSection = provider.showSection?.(orderedProviderRows, now) ?? showSection; } catch { showSection = false; }
489
- if (!showSection) continue;
597
+ if (!showSection && !(getNavigatorView() === "tree" && provider.parentRow)) continue;
490
598
  let parentRow: BackgroundWorkRow | null = null;
491
599
  try { parentRow = provider.parentRow?.(now) ?? null; } catch { parentRow = null; }
492
600
  if (parentRow) {
@@ -501,7 +609,48 @@ function listRows(now = Date.now()): InternalRow[] {
501
609
  rows.push({ ...row, navigatorId: rowKey(provider.id, row.id), providerLabel: provider.label });
502
610
  }
503
611
  }
504
- return rows;
612
+ const conversations = mergeAgentAttempts(rows);
613
+ return getNavigatorView() === "tree" ? treeRows(conversations) : conversations;
614
+ }
615
+
616
+ /** A resumed execution is still the same agent in either layout. */
617
+ export function mergeAgentAttempts<T extends BackgroundWorkRow>(rows: T[]): T[] {
618
+ const latest = new Map<string, T>();
619
+ for (const row of rows) {
620
+ if (row.providerId !== "subagents" || !row.agentId) continue;
621
+ const previous = latest.get(row.agentId);
622
+ if (!previous || row.sortStartedAt > previous.sortStartedAt
623
+ || (row.sortStartedAt === previous.sortStartedAt && row.id > previous.id)) latest.set(row.agentId, row);
624
+ }
625
+ return rows.filter(row => row.providerId !== "subagents" || !row.agentId || latest.get(row.agentId) === row);
626
+ }
627
+
628
+ /** Two levels only: agents are peers, tasks attach by captured conversation. */
629
+ export function treeRows<T extends BackgroundWorkRow>(rows: T[]): T[] {
630
+ const agents = new Map<string, T>();
631
+ for (const row of rows.filter(row => row.providerId === "subagents")) {
632
+ const key = row.agentId ?? row.id;
633
+ const prior = agents.get(key);
634
+ if (!prior || row.sortStartedAt > prior.sortStartedAt) agents.set(key, row);
635
+ }
636
+ const tasks = rows.filter(row => row.providerId !== "subagents");
637
+ const ordered = [...agents.entries()].sort(([a], [b]) => a === "main" ? -1 : b === "main" ? 1 : 0);
638
+ const result: T[] = [], attached = new Set<T>();
639
+ for (const [key, agent] of ordered) {
640
+ const children = tasks.filter(row => (row.parentAgentId ?? "main") === key);
641
+ result.push({...agent, treeDepth: 0});
642
+ children.forEach((row, i) => { result.push({...row, treeDepth: 1, lastChild: i === children.length - 1}); attached.add(row); });
643
+ }
644
+ // Never hide live work when its owner's observation has not arrived yet.
645
+ const missing = new Map<string, T[]>();
646
+ for (const row of tasks) if (!attached.has(row)) {
647
+ const key = row.parentAgentId ?? "main";
648
+ missing.set(key, [...(missing.get(key) ?? []), row]);
649
+ }
650
+ for (const [key, children] of missing) children.forEach((row, i) => result.push({...row,
651
+ treeDepth: 1, lastChild: i === children.length - 1,
652
+ ownerGroupLabel: i === 0 ? (key === "main" ? "Main" : `Agent ${key} · not running`) : undefined}));
653
+ return result;
505
654
  }
506
655
 
507
656
  function rowDisplayName(row: Pick<BackgroundWorkRow, "name" | "id">): string {
@@ -582,6 +731,15 @@ function buildMainListLayout(
582
731
  lines.push(line);
583
732
  owners.push(owner);
584
733
  };
734
+ if (getNavigatorView() === "tree") {
735
+ push(providerGroupLabel("work", fg));
736
+ for (const row of rows) {
737
+ if (row.ownerGroupLabel) push(` ${dim(row.ownerGroupLabel, fg)}`);
738
+ push(formatMainListRow(row, options.focused === true && row.navigatorId === options.selectedId, fg, width), row.navigatorId);
739
+ }
740
+ push(""); push(shortcutsLine(options.focused === true, fg));
741
+ return {lines: lines.map(line => safeTruncate(line, width, truncate)), owners};
742
+ }
585
743
  const grouped = new Map<string, InternalRow[]>();
586
744
  for (const row of rows) {
587
745
  const existing = grouped.get(row.providerLabel) ?? [];
@@ -606,8 +764,9 @@ function buildMainListLayout(
606
764
  }
607
765
 
608
766
  function shortcutsLine(focused: boolean, fg: (color: string, value: string) => string): string {
767
+ const selected = state().mainListRows?.find(row => row.navigatorId === state().mainListSelectedId);
609
768
  const keys = focused
610
- ? "↑↓ switch · Enter detail · x stop · Esc unfocus"
769
+ ? `↑↓ switch · Enter detail${selected?.readOnly || selected?.parentRow ? "" : " · x stop"} · Esc unfocus`
611
770
  : "← work navigator";
612
771
  return dim(keys, fg);
613
772
  }
@@ -618,22 +777,22 @@ function providerGroupLabel(label: string, fg: (color: string, value: string) =>
618
777
  }
619
778
 
620
779
  function formatMainListRow(row: InternalRow, selected: boolean, fg: (color: string, value: string) => string, width: number): string {
621
- const prefix = selected ? fg("accent", "› ") : " ";
780
+ const prefix = (selected ? fg("accent", "› ") : " ") + (row.treeDepth === 1 ? dim(` ${row.lastChild ? "└─" : "├─"} `, fg) : "");
622
781
  const name = row.name || row.id;
623
782
  const indicator = statusIndicator(row);
624
783
  const status = fg(indicator.color, indicator.glyph);
625
784
  const elapsed = singleLine(row.elapsed || "-");
626
785
  const available = Math.max(24, width || MAIN_LIST_FALLBACK_WIDTH);
627
- const elapsedWidth = Math.min(Math.max(visibleWidth(elapsed), 4), 12);
786
+ const elapsedWidth = Math.min(Math.max(piVisibleWidth(elapsed), 4), 12);
628
787
  const statusWidth = 2;
629
- const leftPrefixWidth = visibleWidth(prefix) + statusWidth + 1;
788
+ const leftPrefixWidth = piVisibleWidth(prefix) + statusWidth + 1;
630
789
  const maxNameWidth = Math.max(8, Math.floor(available * 0.36));
631
790
  const nameWidth = Math.max(8, Math.min(44, maxNameWidth, available - leftPrefixWidth - elapsedWidth - 10));
632
791
  const rightWidth = Math.max(8, available - leftPrefixWidth - nameWidth - 1);
633
792
  const summaryWidth = Math.max(1, rightWidth - elapsedWidth - 1);
634
793
  const left = `${prefix}${fit(status, statusWidth)} ${fit(name, nameWidth)}`;
635
794
  const right = `${dim(fitRight(rowSummary(row), summaryWidth), fg)} ${fitRight(elapsed, elapsedWidth)}`;
636
- const gap = Math.max(1, available - visibleWidth(left) - visibleWidth(right));
795
+ const gap = Math.max(1, available - piVisibleWidth(left) - piVisibleWidth(right));
637
796
  return `${left}${" ".repeat(gap)}${right}`;
638
797
  }
639
798
 
@@ -648,17 +807,21 @@ function statusGlyph(row: InternalRow): string {
648
807
  function statusIndicator(row: InternalRow, now = Date.now()): { glyph: string; color: string } {
649
808
  void now;
650
809
  if (row.statusTone !== "running") return { glyph: statusGlyph(row), color: toneColor(row.statusTone, row.status) };
651
- return { glyph: RUNNING_DOT_GLYPH, color: "accent" };
810
+ const glyph = row.treeDepth === 1 && row.providerId === "background-tasks" ? ">_" : RUNNING_DOT_GLYPH;
811
+ return { glyph, color: "accent" };
652
812
  }
653
813
 
654
814
  function mainListSignature(rows: InternalRow[], options: { selectedId?: string; focused?: boolean; closeHint?: string | null } = {}): string {
655
815
  return JSON.stringify({
816
+ view: getNavigatorView(),
656
817
  focused: options.focused === true,
657
818
  closeHint: options.closeHint ?? null,
658
819
  selectedId: options.focused === true ? options.selectedId ?? null : null,
659
820
  rows: rows.map((row) => ({
660
821
  navigatorId: row.navigatorId,
661
822
  providerLabel: row.providerLabel,
823
+ parentAgentId: row.parentAgentId,
824
+ agentId: row.agentId,
662
825
  parentRow: row.parentRow === true,
663
826
  providerId: row.providerId,
664
827
  id: row.id,
@@ -684,6 +847,9 @@ function stableFacts(facts: string[] | undefined): string[] {
684
847
  }
685
848
 
686
849
  function rowSummary(row: InternalRow): string {
850
+ if (getNavigatorView() === "tree" && row.providerId === "background-tasks") {
851
+ return [singleLine(row.status).replaceAll("_", " "), ...(row.facts ?? []).map(singleLine)].join(" · ");
852
+ }
687
853
  if (row.providerId === "subagents") {
688
854
  const attention = row.facts?.map(singleLine).filter(Boolean);
689
855
  if (attention?.length) return `${singleLine(row.status)} · ${attention.join(" · ")}`;
@@ -713,15 +879,15 @@ function rowSummary(row: InternalRow): string {
713
879
 
714
880
  function fit(value: string, width: number): string {
715
881
  const str = singleLine(value);
716
- const visible = visibleWidth(str);
717
- if (visible >= width) return truncateVisible(str, width);
882
+ const visible = piVisibleWidth(str);
883
+ if (visible > width) return piTruncateToWidth(str, width);
718
884
  return str + " ".repeat(width - visible);
719
885
  }
720
886
 
721
887
  function fitRight(value: string, width: number): string {
722
888
  const str = singleLine(value);
723
- const visible = visibleWidth(str);
724
- if (visible >= width) return truncateVisible(str, width);
889
+ const visible = piVisibleWidth(str);
890
+ if (visible > width) return piTruncateToWidth(str, width);
725
891
  return " ".repeat(width - visible) + str;
726
892
  }
727
893
 
@@ -736,20 +902,33 @@ function prepareDetail(navigatorId: string, options?: {logTailLines?: number}):
736
902
 
737
903
  function detailFor(navigatorId: string, now = Date.now(), options?: { logTailLines?: number }): BackgroundWorkDetail | null {
738
904
  const { providerId, id } = splitRowKey(navigatorId);
905
+ const failed = state().launchFailures?.get(navigatorId);
906
+ if (failed) return {providerId, id, title: failed.name ?? "Launch failed", status: "failed", statusTone: "failed", metadata: [], evidence: {label: "Launch error", text: failed.primary}};
739
907
  const provider = state().providers.get(providerId);
740
908
  if (!provider) return null;
741
909
  try { return provider.detail(id, now, options); } catch { return null; }
742
910
  }
743
911
 
744
912
  function closeFor(row: InternalRow): BackgroundWorkCloseOutcome {
745
- if (row.parentRow) return { action: "not-closable", providerId: row.providerId, id: row.id };
913
+ if (row.parentRow || row.readOnly) return { action: "not-closable", providerId: row.providerId, id: row.id };
746
914
  const provider = state().providers.get(row.providerId);
915
+ if (state().launchFailures?.delete(row.navigatorId)) {
916
+ state().terminalRows?.get(row.providerId)?.dismiss(row.id);
917
+ return {action: "dismissed", providerId: row.providerId, id: row.id};
918
+ }
747
919
  if (!provider) return { action: "missing", providerId: row.providerId, id: row.id };
748
- try { return provider.close(row.id); } catch { return { action: "missing", providerId: row.providerId, id: row.id }; }
920
+ try {
921
+ const outcome = provider.close(row.id);
922
+ if (["dismissed", "stopped-and-dismissed"].includes(outcome.action)
923
+ || outcome.action === "requested" && ["completed", "succeeded", "failed", "cancelled", "killed", "lost", "timed_out"].includes(row.status)) {
924
+ state().terminalRows?.get(row.providerId)?.dismiss(row.id);
925
+ }
926
+ return outcome;
927
+ } catch { return { action: "missing", providerId: row.providerId, id: row.id }; }
749
928
  }
750
929
 
751
930
  function closeHintFor(row: InternalRow | undefined): string | null {
752
- if (!row || row.parentRow) return null;
931
+ if (!row || row.parentRow || row.readOnly) return null;
753
932
  const provider = state().providers.get(row.providerId);
754
933
  if (!provider) return null;
755
934
  try { return `${provider.armCloseLabel(row)} ${row.name || row.id}`; } catch { return null; }
@@ -775,28 +954,43 @@ function installNavigatorEditor(ui: any, deps: HostDeps): unknown {
775
954
 
776
955
  function wrapEditor(inner: any, deps: HostDeps): unknown {
777
956
  if (inner && typeof inner.render === "function") state().editorComponent = inner as Component;
957
+ const methods = new Map<PropertyKey, { original: Function; exposed: Function }>();
958
+ const replacements = new Map<PropertyKey, Function>();
778
959
  const proxy: any = new Proxy(inner, {
779
960
  get(target, prop) {
961
+ const value = Reflect.get(target, prop);
962
+ if (typeof value !== "function" || replacements.get(prop) === value) return value;
963
+ const cached = methods.get(prop);
964
+ if (cached && cached.original === value) return cached.exposed;
965
+ // Capture the method before another editor decorator replaces it.
966
+ // A decorator can retain this wrapper and call it as its delegate.
967
+ let exposed = value.bind(target);
780
968
  if (prop === "handleInput") {
781
- return (data: string) => {
969
+ exposed = (data: string) => {
782
970
  if (target.getText?.() === "" && handleMainListInput(data, deps)) {
783
971
  return;
784
972
  }
785
- target.handleInput(data);
973
+ value.call(target, data);
786
974
  };
787
975
  }
788
- if (prop === "render" && typeof target.render === "function") {
789
- return (...args: unknown[]) => {
976
+ if (prop === "render") {
977
+ exposed = (...args: unknown[]) => {
790
978
  const s = state();
791
979
  if (s.editorFocusTarget === proxy) s.editorRenders = (s.editorRenders ?? 0) + 1;
792
- return target.render(...args);
980
+ return value.apply(target, args);
793
981
  };
794
982
  }
795
- const value = Reflect.get(target, prop);
796
- return typeof value === "function" ? value.bind(target) : value;
983
+ methods.set(prop, { original: value, exposed });
984
+ return exposed;
797
985
  },
798
986
  set(target, prop, value) {
799
- return Reflect.set(target, prop, value);
987
+ const cached = methods.get(prop);
988
+ const restoring = cached !== undefined && value === cached.exposed;
989
+ if (!Reflect.set(target, prop, restoring ? cached.original : value)) return false;
990
+ // Preserve replacement identity so the installing decorator can undo it.
991
+ if (!restoring && typeof value === "function") replacements.set(prop, value);
992
+ else replacements.delete(prop);
993
+ return true;
800
994
  },
801
995
  });
802
996
  // Pi mounts and focuses whatever the factory returns; an extension that
@@ -807,6 +1001,9 @@ function wrapEditor(inner: any, deps: HostDeps): unknown {
807
1001
 
808
1002
  function handleMainListInput(data: string, deps: HostDeps): boolean {
809
1003
  const s = state();
1004
+ if (!s.mainListFocused && deps.isOpenTrigger(data)) {
1005
+ for (const provider of s.providers.values()) provider.onOpen?.();
1006
+ }
810
1007
  const rows = listRows();
811
1008
  if (rows.length === 0) {
812
1009
  // Every row is gone, but an overlay that lost focus may still be mounted: Esc still closes it.
@@ -876,7 +1073,7 @@ function dismissOverlay(): void {
876
1073
 
877
1074
  function handleMainListCloseKey(): void {
878
1075
  const row = selectedMainListRow();
879
- if (!row || row.parentRow) return;
1076
+ if (!row || row.parentRow || row.readOnly) return;
880
1077
  const s = state();
881
1078
  const now = Date.now();
882
1079
  const arm = s.mainListCloseArm;
@@ -917,6 +1114,7 @@ function openNavigator(): void {
917
1114
  const ctx = s.uiCtx;
918
1115
  const deps = s.deps;
919
1116
  if (!ctx || !deps || !isNavigatorUiAvailable(ctx)) return;
1117
+ for (const provider of s.providers.values()) provider.onOpen?.();
920
1118
  const rows = listRows();
921
1119
  if (rows.length === 0) return;
922
1120
  const selectedId = selectedMainListRow()?.navigatorId ?? rows[0]!.navigatorId;
@@ -991,6 +1189,8 @@ function createOverlayComponent(
991
1189
  onClosed: () => void,
992
1190
  initialDetailId: string,
993
1191
  ) {
1192
+ let editorRendersSeen = state().editorRenders ?? 0;
1193
+ let sawLiveEditor = liveEditorMounted(tui) === true;
994
1194
  // The overlay only ever shows one row's detail; the rail below it is the list.
995
1195
  const overlayState: OverlayState = { rows: initialRows, selected: 0 };
996
1196
  let logTailRows: number = DEFAULT_LOG_TAIL_ROWS;
@@ -1113,7 +1313,7 @@ function createOverlayComponent(
1113
1313
 
1114
1314
  function handleCloseKey(): void {
1115
1315
  const row = selectedRow();
1116
- if (!row || row.parentRow) return;
1316
+ if (!row || row.parentRow || row.readOnly) return;
1117
1317
  const now = Date.now();
1118
1318
  if (closeArm?.id === row.navigatorId && now >= closeArm.armedAt && now < closeArm.armedAt + CLOSE_ARM_MS) {
1119
1319
  clearCloseArm();
@@ -1148,19 +1348,23 @@ function createOverlayComponent(
1148
1348
  requestRender();
1149
1349
  }
1150
1350
 
1151
- let editorRendersSeen: number | undefined;
1152
1351
  /**
1153
- * Our editor wrapper was uninstalled: close, since no key of ours can reach this overlay again and
1154
- * it would cover the editor that replaced ours (#332). An extension that composes the editor inside
1155
- * its own non-container component still renders ours, so the wrapper also counts as live while it
1156
- * rendered since the previous overlay frame (Pi renders the editor before it composites overlays).
1352
+ * Close when a replacement editor takes over while the sheet is open (#332).
1353
+ * A wrapper inside another extension's editor still counts as live if it rendered since
1354
+ * the last overlay frame. Pi renders the editor before it composites overlays.
1157
1355
  */
1158
1356
  function closeIfEditorReplaced(): void {
1159
- const rendersBefore = editorRendersSeen;
1160
1357
  const renders = state().editorRenders ?? 0;
1358
+ const rendered = renders !== editorRendersSeen;
1161
1359
  editorRendersSeen = renders;
1162
- state().editorRenderedLastFrame = rendersBefore === undefined ? undefined : renders !== rendersBefore;
1163
- if (closed || liveEditorMounted(tui) !== false || rendersBefore === undefined || renders !== rendersBefore) return;
1360
+ state().editorRenderedLastFrame = rendered;
1361
+ if (closed) return;
1362
+ const mounted = liveEditorMounted(tui);
1363
+ if (rendered || mounted === true) {
1364
+ sawLiveEditor = true;
1365
+ return;
1366
+ }
1367
+ if (mounted !== false || !sawLiveEditor) return;
1164
1368
  // Not from inside pi-tui's render pass: hiding an overlay there would change the stack it is drawing.
1165
1369
  queueMicrotask(() => {
1166
1370
  if (closed) return;
@@ -1687,9 +1891,9 @@ function fill(glyph: string, label: string, width: number): string {
1687
1891
  }
1688
1892
 
1689
1893
  function safeTruncate(line: string, width: number, truncate: (s: string, width: number) => string): string {
1690
- if (visibleWidth(line) <= width) return line;
1894
+ if (piVisibleWidth(line) <= width) return line;
1691
1895
  const cut = truncate(line, width);
1692
- return visibleWidth(cut) > width ? truncateVisible(cut, width) : cut;
1896
+ return piVisibleWidth(cut) > width ? piTruncateToWidth(cut, width) : cut;
1693
1897
  }
1694
1898
 
1695
1899
  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");