pi-better-server 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (597) hide show
  1. package/package.json +8 -1
  2. package/scripts/copy-pi-test-providers.mjs +10 -0
  3. package/scripts/event-publication/README.md +26 -0
  4. package/scripts/event-publication/commit.mjs +21 -0
  5. package/scripts/event-publication/measure.mjs +87 -0
  6. package/scripts/event-publication/writer.mjs +6 -0
  7. package/scripts/measure-full-runtime/frontend.ts +24 -0
  8. package/scripts/measure-full-runtime/hosted-extension.ts +28 -0
  9. package/scripts/measure-full-runtime/probe.mjs +29 -0
  10. package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
  11. package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
  12. package/scripts/measure-full-runtime.mjs +146 -0
  13. package/scripts/measure-shared-reads/probe.mjs +26 -2
  14. package/scripts/measure-shared-reads.mjs +44 -9
  15. package/scripts/private-runtime/package-lock.json +66 -4
  16. package/scripts/private-runtime/package.json +10 -2
  17. package/scripts/source-provenance.mjs +31 -0
  18. package/scripts/test-on-pi.sh +3 -9
  19. package/src/handshake.ts +1 -1
  20. package/src/hosted-session.ts +32 -4
  21. package/src/maintenance.ts +35 -7
  22. package/src/registry.ts +28 -4
  23. package/src/runtime/attempt-invalidation.ts +54 -0
  24. package/src/runtime/background-history.ts +151 -45
  25. package/src/runtime/background-policy.ts +27 -0
  26. package/src/runtime/background-tools.ts +389 -0
  27. package/src/runtime/background.ts +410 -48
  28. package/src/runtime/cancellation.ts +28 -7
  29. package/src/runtime/catalog-sources.ts +199 -0
  30. package/src/runtime/catalog.ts +53 -21
  31. package/src/runtime/client.ts +22 -2
  32. package/src/runtime/domain/assignment-inbox.mjs +119 -0
  33. package/src/runtime/domain/assignment-observation.d.mts +1 -1
  34. package/src/runtime/domain/assignment-observation.mjs +71 -33
  35. package/src/runtime/domain/background/process-identity.mjs +20 -2
  36. package/src/runtime/domain/background/process.mjs +3 -3
  37. package/src/runtime/domain/background/registry.mjs +89 -4
  38. package/src/runtime/domain/background/types.mjs +1 -0
  39. package/src/runtime/domain/background-service/adapter-contract.domain.mjs +83 -0
  40. package/src/runtime/domain/background-service/adapter-contract.ts +70 -0
  41. package/src/runtime/domain/background-service/batch.domain.mjs +91 -0
  42. package/src/runtime/domain/background-service/batch.ts +111 -0
  43. package/src/runtime/domain/background-service/conditions.domain.mjs +94 -0
  44. package/src/runtime/domain/background-service/conditions.ts +99 -0
  45. package/src/runtime/domain/background-service/delivery-observer.domain.mjs +37 -0
  46. package/src/runtime/domain/background-service/delivery-observer.ts +42 -0
  47. package/src/runtime/domain/background-service/failures.domain.mjs +209 -0
  48. package/src/runtime/domain/background-service/failures.ts +212 -0
  49. package/src/runtime/domain/background-service/goal-provider.domain.mjs +193 -0
  50. package/src/runtime/domain/background-service/goal-provider.ts +209 -0
  51. package/src/runtime/domain/background-service/index.domain.mjs +54 -0
  52. package/src/runtime/domain/background-service/index.ts +55 -0
  53. package/src/runtime/domain/background-service/logs.domain.mjs +129 -0
  54. package/src/runtime/domain/background-service/logs.ts +134 -0
  55. package/src/runtime/domain/background-service/maintenance.domain.mjs +95 -0
  56. package/src/runtime/domain/background-service/maintenance.ts +98 -0
  57. package/src/runtime/domain/background-service/managed-authority.domain.mjs +32 -0
  58. package/src/runtime/domain/background-service/managed-authority.ts +30 -0
  59. package/src/runtime/domain/background-service/managed-client.domain.mjs +79 -0
  60. package/src/runtime/domain/background-service/managed-client.ts +73 -0
  61. package/src/runtime/domain/background-service/managed-frontend.domain.mjs +225 -0
  62. package/src/runtime/domain/background-service/managed-frontend.ts +176 -0
  63. package/src/runtime/domain/background-service/navigator-provider.domain.mjs +492 -0
  64. package/src/runtime/domain/background-service/navigator-provider.ts +485 -0
  65. package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
  66. package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
  67. package/src/runtime/domain/background-service/observed-waits.domain.mjs +4080 -0
  68. package/src/runtime/domain/background-service/observed-waits.ts +4513 -0
  69. package/src/runtime/domain/background-service/output.domain.mjs +867 -0
  70. package/src/runtime/domain/background-service/output.ts +952 -0
  71. package/src/runtime/domain/background-service/process-identity.domain.mjs +129 -0
  72. package/src/runtime/domain/background-service/process-identity.ts +134 -0
  73. package/src/runtime/domain/background-service/process.domain.mjs +512 -0
  74. package/src/runtime/domain/background-service/process.ts +532 -0
  75. package/src/runtime/domain/background-service/prompt.domain.mjs +58 -0
  76. package/src/runtime/domain/background-service/prompt.ts +72 -0
  77. package/src/runtime/domain/background-service/registry.domain.mjs +460 -0
  78. package/src/runtime/domain/background-service/registry.ts +450 -0
  79. package/src/runtime/domain/background-service/remote-task-preset.domain.mjs +67 -0
  80. package/src/runtime/domain/background-service/remote-task-preset.ts +127 -0
  81. package/src/runtime/domain/background-service/runtime.domain.mjs +1511 -0
  82. package/src/runtime/domain/background-service/runtime.ts +1636 -0
  83. package/src/runtime/domain/background-service/sandbox.domain.mjs +735 -0
  84. package/src/runtime/domain/background-service/sandbox.ts +913 -0
  85. package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +777 -0
  86. package/src/runtime/domain/background-service/shared-callback-batcher.ts +956 -0
  87. package/src/runtime/domain/background-service/shared-execution-policy.domain.mjs +50 -0
  88. package/src/runtime/domain/background-service/shared-execution-policy.ts +61 -0
  89. package/src/runtime/domain/background-service/shared-failure-observations.domain.mjs +1078 -0
  90. package/src/runtime/domain/background-service/shared-failure-observations.ts +1166 -0
  91. package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +126 -0
  92. package/src/runtime/domain/background-service/shared-harness-settings.ts +116 -0
  93. package/src/runtime/domain/background-service/shared-log-utils.domain.mjs +1223 -0
  94. package/src/runtime/domain/background-service/shared-log-utils.ts +1492 -0
  95. package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +289 -0
  96. package/src/runtime/domain/background-service/shared-navigator-panels.ts +272 -0
  97. package/src/runtime/domain/background-service/shared-navigator.domain.mjs +1930 -0
  98. package/src/runtime/domain/background-service/shared-navigator.ts +1962 -0
  99. package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
  100. package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +189 -0
  101. package/src/runtime/domain/background-service/shared-operation-coordinator/index.domain.mjs +51 -0
  102. package/src/runtime/domain/background-service/shared-operation-coordinator/index.ts +122 -0
  103. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
  104. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
  105. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +163 -0
  106. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
  107. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
  108. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
  109. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
  110. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +90 -0
  111. package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
  112. package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +139 -0
  113. package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.domain.mjs +12 -0
  114. package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.ts +79 -0
  115. package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +342 -0
  116. package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +513 -0
  117. package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
  118. package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +458 -0
  119. package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
  120. package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.ts +55 -0
  121. package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
  122. package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +140 -0
  123. package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +280 -0
  124. package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +442 -0
  125. package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +420 -0
  126. package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +441 -0
  127. package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
  128. package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.ts +239 -0
  129. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +275 -0
  130. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +585 -0
  131. package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
  132. package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +142 -0
  133. package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
  134. package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.ts +224 -0
  135. package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +25 -0
  136. package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +707 -0
  137. package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
  138. package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.ts +22 -0
  139. package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.domain.mjs +234 -0
  140. package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.ts +241 -0
  141. package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +851 -0
  142. package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +1424 -0
  143. package/src/runtime/domain/background-service/shared-permission-blocker.domain.mjs +40 -0
  144. package/src/runtime/domain/background-service/shared-permission-blocker.ts +48 -0
  145. package/src/runtime/domain/background-service/shared-render-scheduler.domain.mjs +41 -0
  146. package/src/runtime/domain/background-service/shared-render-scheduler.ts +47 -0
  147. package/src/runtime/domain/background-service/shared-sandbox-core.domain.mjs +1531 -0
  148. package/src/runtime/domain/background-service/shared-sandbox-core.ts +1757 -0
  149. package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +591 -0
  150. package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +491 -0
  151. package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +698 -0
  152. package/src/runtime/domain/background-service/shared-ssh-core/index.ts +979 -0
  153. package/src/runtime/domain/background-service/shared-stall-detector.domain.mjs +37 -0
  154. package/src/runtime/domain/background-service/shared-stall-detector.ts +69 -0
  155. package/src/runtime/domain/background-service/shared-work-client.mjs +303 -0
  156. package/src/runtime/domain/background-service/stall-attention.domain.mjs +29 -0
  157. package/src/runtime/domain/background-service/stall-attention.ts +31 -0
  158. package/src/runtime/domain/background-service/stall.domain.mjs +57 -0
  159. package/src/runtime/domain/background-service/stall.ts +57 -0
  160. package/src/runtime/domain/background-service/supervisor/README.md +111 -0
  161. package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +90 -0
  162. package/src/runtime/domain/background-service/supervisor/generated/conditions.mjs +96 -0
  163. package/src/runtime/domain/background-service/supervisor/generated/identity.mjs +95 -0
  164. package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +131 -0
  165. package/src/runtime/domain/background-service/supervisor/generated/process.mjs +514 -0
  166. package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +872 -0
  167. package/src/runtime/domain/background-service/supervisor/generated/store.mjs +609 -0
  168. package/src/runtime/domain/background-service/supervisor/generated/types.mjs +50 -0
  169. package/src/runtime/domain/background-service/supervisor/identity.domain.mjs +93 -0
  170. package/src/runtime/domain/background-service/supervisor/identity.ts +99 -0
  171. package/src/runtime/domain/background-service/supervisor/index.domain.mjs +22 -0
  172. package/src/runtime/domain/background-service/supervisor/index.ts +37 -0
  173. package/src/runtime/domain/background-service/supervisor/invocation.domain.mjs +30 -0
  174. package/src/runtime/domain/background-service/supervisor/invocation.ts +44 -0
  175. package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +870 -0
  176. package/src/runtime/domain/background-service/supervisor/runner.ts +982 -0
  177. package/src/runtime/domain/background-service/supervisor/store.domain.mjs +605 -0
  178. package/src/runtime/domain/background-service/supervisor/store.ts +651 -0
  179. package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +721 -0
  180. package/src/runtime/domain/background-service/supervisor/supervisor.ts +804 -0
  181. package/src/runtime/domain/background-service/supervisor/types.domain.mjs +48 -0
  182. package/src/runtime/domain/background-service/supervisor/types.ts +394 -0
  183. package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +60 -0
  184. package/src/runtime/domain/background-service/task-diagnostics.ts +71 -0
  185. package/src/runtime/domain/background-service/tools.domain.mjs +1050 -0
  186. package/src/runtime/domain/background-service/tools.ts +1142 -0
  187. package/src/runtime/domain/background-service/types.domain.mjs +5 -0
  188. package/src/runtime/domain/background-service/types.ts +236 -0
  189. package/src/runtime/domain/background-service/work-observation.domain.mjs +176 -0
  190. package/src/runtime/domain/background-service/work-observation.ts +144 -0
  191. package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
  192. package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
  193. package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
  194. package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
  195. package/src/runtime/domain/coordinator/src/background-parent-callbacks.mjs +65 -0
  196. package/src/runtime/domain/coordinator/src/background-requests.mjs +86 -0
  197. package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
  198. package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
  199. package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
  200. package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
  201. package/src/runtime/domain/coordinator/src/schema.mjs +73 -21
  202. package/src/runtime/domain/coordinator/src/store.mjs +32 -3
  203. package/src/runtime/domain/coordinator/src/subagent-launch.mjs +119 -0
  204. package/src/runtime/domain/coordinator/src/types.mjs +1 -1
  205. package/src/runtime/domain/coordinator/src/upgrade.mjs +22 -0
  206. package/src/runtime/domain/health-observation.d.mts +3 -1
  207. package/src/runtime/domain/health-observation.mjs +189 -190
  208. package/src/runtime/domain/log-cursor.d.mts +2 -0
  209. package/src/runtime/domain/log-cursor.mjs +85 -16
  210. package/src/runtime/domain/parse.d.mts +4 -1
  211. package/src/runtime/domain/parse.mjs +50 -5
  212. package/src/runtime/domain/sandbox-policy/README.md +633 -0
  213. package/src/runtime/domain/sandbox-policy/background-admission.domain.mjs +83 -0
  214. package/src/runtime/domain/sandbox-policy/background-admission.ts +75 -0
  215. package/src/runtime/domain/sandbox-policy/commands.domain.mjs +245 -0
  216. package/src/runtime/domain/sandbox-policy/commands.ts +336 -0
  217. package/src/runtime/domain/sandbox-policy/deny-rules.domain.mjs +440 -0
  218. package/src/runtime/domain/sandbox-policy/deny-rules.ts +620 -0
  219. package/src/runtime/domain/sandbox-policy/diagnostics-command.domain.mjs +30 -0
  220. package/src/runtime/domain/sandbox-policy/diagnostics-command.ts +27 -0
  221. package/src/runtime/domain/sandbox-policy/events.domain.mjs +49 -0
  222. package/src/runtime/domain/sandbox-policy/events.ts +85 -0
  223. package/src/runtime/domain/sandbox-policy/files.domain.mjs +153 -0
  224. package/src/runtime/domain/sandbox-policy/files.ts +224 -0
  225. package/src/runtime/domain/sandbox-policy/index.domain.mjs +289 -0
  226. package/src/runtime/domain/sandbox-policy/index.ts +386 -0
  227. package/src/runtime/domain/sandbox-policy/package.json +66 -0
  228. package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +36 -0
  229. package/src/runtime/domain/sandbox-policy/permission-settings.ts +46 -0
  230. package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +309 -0
  231. package/src/runtime/domain/sandbox-policy/permissions-page.ts +295 -0
  232. package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +98 -0
  233. package/src/runtime/domain/sandbox-policy/permissions.ts +125 -0
  234. package/src/runtime/domain/sandbox-policy/policy.domain.mjs +80 -0
  235. package/src/runtime/domain/sandbox-policy/policy.ts +102 -0
  236. package/src/runtime/domain/sandbox-policy/preferences.domain.mjs +55 -0
  237. package/src/runtime/domain/sandbox-policy/preferences.ts +82 -0
  238. package/src/runtime/domain/sandbox-policy/rules-page.domain.mjs +138 -0
  239. package/src/runtime/domain/sandbox-policy/rules-page.ts +176 -0
  240. package/src/runtime/domain/sandbox-policy/session-permissions.domain.mjs +22 -0
  241. package/src/runtime/domain/sandbox-policy/session-permissions.ts +24 -0
  242. package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +126 -0
  243. package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +116 -0
  244. package/src/runtime/domain/sandbox-policy/shared-permission-blocker.domain.mjs +40 -0
  245. package/src/runtime/domain/sandbox-policy/shared-permission-blocker.ts +48 -0
  246. package/src/runtime/domain/sandbox-policy/shared-sandbox-core.domain.mjs +1531 -0
  247. package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1757 -0
  248. package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +591 -0
  249. package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +491 -0
  250. package/src/runtime/domain/sandbox-policy/shared-task-application.domain.mjs +185 -0
  251. package/src/runtime/domain/sandbox-policy/shared-task-application.ts +185 -0
  252. package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.domain.mjs +416 -0
  253. package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.ts +409 -0
  254. package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +325 -0
  255. package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +335 -0
  256. package/src/runtime/domain/sandbox-policy/shared-task-files.domain.mjs +346 -0
  257. package/src/runtime/domain/sandbox-policy/shared-task-files.ts +342 -0
  258. package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
  259. package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
  260. package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +220 -0
  261. package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +209 -0
  262. package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +227 -0
  263. package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +224 -0
  264. package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +92 -0
  265. package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +123 -0
  266. package/src/runtime/domain/sandbox-policy/shell.domain.mjs +93 -0
  267. package/src/runtime/domain/sandbox-policy/shell.ts +129 -0
  268. package/src/runtime/domain/sandbox-policy/state.domain.mjs +307 -0
  269. package/src/runtime/domain/sandbox-policy/state.ts +408 -0
  270. package/src/runtime/domain/sandbox-policy/status.domain.mjs +64 -0
  271. package/src/runtime/domain/sandbox-policy/status.ts +76 -0
  272. package/src/runtime/domain/sandbox-policy/subagent-admission.domain.mjs +69 -0
  273. package/src/runtime/domain/sandbox-policy/subagent-admission.ts +60 -0
  274. package/src/runtime/domain/subagents/CONTEXT.md +202 -0
  275. package/src/runtime/domain/subagents/PRODUCT.md +49 -0
  276. package/src/runtime/domain/subagents/README.md +201 -0
  277. package/src/runtime/domain/subagents/agent-catalog.mjs +64 -0
  278. package/src/runtime/domain/subagents/agent-commands.domain.mjs +822 -0
  279. package/src/runtime/domain/subagents/agent-commands.ts +905 -0
  280. package/src/runtime/domain/subagents/agent-inspection.domain.mjs +398 -0
  281. package/src/runtime/domain/subagents/agent-inspection.ts +574 -0
  282. package/src/runtime/domain/subagents/agent-operations.domain.mjs +40 -0
  283. package/src/runtime/domain/subagents/agent-operations.ts +61 -0
  284. package/src/runtime/domain/subagents/agent-session-settings.domain.mjs +112 -0
  285. package/src/runtime/domain/subagents/agent-session-settings.ts +118 -0
  286. package/src/runtime/domain/subagents/agents-catalog-tool.domain.mjs +84 -0
  287. package/src/runtime/domain/subagents/agents-catalog-tool.ts +118 -0
  288. package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +276 -0
  289. package/src/runtime/domain/subagents/assignment-outcomes.ts +212 -0
  290. package/src/runtime/domain/subagents/assignment-projection.mjs +261 -0
  291. package/src/runtime/domain/subagents/assignment-report.domain.mjs +174 -0
  292. package/src/runtime/domain/subagents/assignment-report.ts +156 -0
  293. package/src/runtime/domain/subagents/batch.mjs +275 -0
  294. package/src/runtime/domain/subagents/callback-fields.domain.mjs +72 -0
  295. package/src/runtime/domain/subagents/callback-fields.ts +95 -0
  296. package/src/runtime/domain/subagents/capacity.mjs +108 -0
  297. package/src/runtime/domain/subagents/catalog-editor.domain.mjs +98 -0
  298. package/src/runtime/domain/subagents/catalog-editor.ts +125 -0
  299. package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +104 -0
  300. package/src/runtime/domain/subagents/catalog-host-admission.ts +85 -0
  301. package/src/runtime/domain/subagents/catalog-identity.domain.mjs +222 -0
  302. package/src/runtime/domain/subagents/catalog-identity.ts +258 -0
  303. package/src/runtime/domain/subagents/catalog-overlay.domain.mjs +9 -0
  304. package/src/runtime/domain/subagents/catalog-overlay.ts +10 -0
  305. package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +164 -0
  306. package/src/runtime/domain/subagents/catalog-preferences.ts +139 -0
  307. package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +366 -0
  308. package/src/runtime/domain/subagents/catalog-resolver.ts +540 -0
  309. package/src/runtime/domain/subagents/catalog-runtime.domain.mjs +570 -0
  310. package/src/runtime/domain/subagents/catalog-runtime.ts +680 -0
  311. package/src/runtime/domain/subagents/catalog-schema.domain.mjs +1331 -0
  312. package/src/runtime/domain/subagents/catalog-schema.ts +1563 -0
  313. package/src/runtime/domain/subagents/catalog-skill-edits.domain.mjs +95 -0
  314. package/src/runtime/domain/subagents/catalog-skill-edits.ts +116 -0
  315. package/src/runtime/domain/subagents/catalog-store.domain.mjs +808 -0
  316. package/src/runtime/domain/subagents/catalog-store.ts +1006 -0
  317. package/src/runtime/domain/subagents/catalog-ui.domain.mjs +651 -0
  318. package/src/runtime/domain/subagents/catalog-ui.ts +611 -0
  319. package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
  320. package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
  321. package/src/runtime/domain/subagents/child-codemode.domain.mjs +16 -0
  322. package/src/runtime/domain/subagents/child-codemode.ts +17 -0
  323. package/src/runtime/domain/subagents/child-dependencies.mjs +193 -0
  324. package/src/runtime/domain/subagents/child-incidents.domain.mjs +170 -0
  325. package/src/runtime/domain/subagents/child-incidents.ts +169 -0
  326. package/src/runtime/domain/subagents/child-operations.domain.mjs +986 -0
  327. package/src/runtime/domain/subagents/child-operations.ts +1191 -0
  328. package/src/runtime/domain/subagents/child-ownership.domain.mjs +205 -0
  329. package/src/runtime/domain/subagents/child-ownership.ts +160 -0
  330. package/src/runtime/domain/subagents/child-preflight.mjs +38 -0
  331. package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
  332. package/src/runtime/domain/subagents/child-process-list.ts +8 -0
  333. package/src/runtime/domain/subagents/child-runtime.mjs +67 -0
  334. package/src/runtime/domain/subagents/child-steer.domain.mjs +109 -0
  335. package/src/runtime/domain/subagents/child-steer.ts +102 -0
  336. package/src/runtime/domain/subagents/cleanup.domain.mjs +818 -0
  337. package/src/runtime/domain/subagents/cleanup.ts +1017 -0
  338. package/src/runtime/domain/subagents/codex-import.domain.mjs +575 -0
  339. package/src/runtime/domain/subagents/codex-import.ts +717 -0
  340. package/src/runtime/domain/subagents/completion.domain.mjs +6 -0
  341. package/src/runtime/domain/subagents/completion.mjs +152 -0
  342. package/src/runtime/domain/subagents/completion.ts +11 -0
  343. package/src/runtime/domain/subagents/config.domain.mjs +248 -0
  344. package/src/runtime/domain/subagents/config.json +15 -0
  345. package/src/runtime/domain/subagents/config.ts +328 -0
  346. package/src/runtime/domain/subagents/continuation-authority.domain.mjs +38 -0
  347. package/src/runtime/domain/subagents/continuation-authority.ts +31 -0
  348. package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
  349. package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
  350. package/src/runtime/domain/subagents/continuation.domain.mjs +942 -0
  351. package/src/runtime/domain/subagents/continuation.ts +1051 -0
  352. package/src/runtime/domain/subagents/delegation.domain.mjs +19 -0
  353. package/src/runtime/domain/subagents/delegation.ts +24 -0
  354. package/src/runtime/domain/subagents/effective-settings.domain.mjs +130 -0
  355. package/src/runtime/domain/subagents/effective-settings.ts +184 -0
  356. package/src/runtime/domain/subagents/extensions.domain.mjs +6 -0
  357. package/src/runtime/domain/subagents/extensions.mjs +164 -0
  358. package/src/runtime/domain/subagents/extensions.ts +19 -0
  359. package/src/runtime/domain/subagents/failures.domain.mjs +362 -0
  360. package/src/runtime/domain/subagents/failures.ts +319 -0
  361. package/src/runtime/domain/subagents/finalization.domain.mjs +168 -0
  362. package/src/runtime/domain/subagents/finalization.ts +218 -0
  363. package/src/runtime/domain/subagents/git-remotes.domain.mjs +351 -0
  364. package/src/runtime/domain/subagents/git-remotes.ts +413 -0
  365. package/src/runtime/domain/subagents/git-workspace.domain.mjs +337 -0
  366. package/src/runtime/domain/subagents/git-workspace.ts +430 -0
  367. package/src/runtime/domain/subagents/goal-provider.domain.mjs +125 -0
  368. package/src/runtime/domain/subagents/goal-provider.ts +132 -0
  369. package/src/runtime/domain/subagents/health-observation.domain.mjs +617 -0
  370. package/src/runtime/domain/subagents/health-observation.ts +818 -0
  371. package/src/runtime/domain/subagents/health-surface.mjs +284 -0
  372. package/src/runtime/domain/subagents/health.domain.mjs +261 -0
  373. package/src/runtime/domain/subagents/health.ts +343 -0
  374. package/src/runtime/domain/subagents/historical-attention.domain.mjs +37 -0
  375. package/src/runtime/domain/subagents/historical-attention.ts +35 -0
  376. package/src/runtime/domain/subagents/incident-model.domain.mjs +322 -0
  377. package/src/runtime/domain/subagents/incident-model.ts +358 -0
  378. package/src/runtime/domain/subagents/index.domain.mjs +4731 -0
  379. package/src/runtime/domain/subagents/index.ts +4781 -0
  380. package/src/runtime/domain/subagents/launch-abort.domain.mjs +13 -0
  381. package/src/runtime/domain/subagents/launch-abort.ts +21 -0
  382. package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
  383. package/src/runtime/domain/subagents/launch-context.ts +23 -0
  384. package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
  385. package/src/runtime/domain/subagents/lifecycle.domain.mjs +265 -0
  386. package/src/runtime/domain/subagents/lifecycle.ts +360 -0
  387. package/src/runtime/domain/subagents/list.domain.mjs +2 -0
  388. package/src/runtime/domain/subagents/list.mjs +152 -0
  389. package/src/runtime/domain/subagents/list.ts +19 -0
  390. package/src/runtime/domain/subagents/log-cursor.domain.mjs +217 -0
  391. package/src/runtime/domain/subagents/log-cursor.ts +268 -0
  392. package/src/runtime/domain/subagents/managed-background-capability.domain.mjs +10 -0
  393. package/src/runtime/domain/subagents/managed-background-capability.ts +9 -0
  394. package/src/runtime/domain/subagents/managed-failure-worker.mjs +36 -0
  395. package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +48 -0
  396. package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +75 -0
  397. package/src/runtime/domain/subagents/managed-launch-client.ts +59 -0
  398. package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +627 -0
  399. package/src/runtime/domain/subagents/managed-launch-host.ts +504 -0
  400. package/src/runtime/domain/subagents/managed-launch-journal.mjs +17 -0
  401. package/src/runtime/domain/subagents/managed-launch-ownership.domain.mjs +29 -0
  402. package/src/runtime/domain/subagents/managed-launch-ownership.ts +22 -0
  403. package/src/runtime/domain/subagents/managed-launch-port.domain.mjs +2 -0
  404. package/src/runtime/domain/subagents/managed-launch-port.ts +25 -0
  405. package/src/runtime/domain/subagents/managed-launch-recovery.domain.mjs +29 -0
  406. package/src/runtime/domain/subagents/managed-launch-recovery.ts +45 -0
  407. package/src/runtime/domain/subagents/managed-worker-bridge.domain.mjs +63 -0
  408. package/src/runtime/domain/subagents/managed-worker-bridge.ts +48 -0
  409. package/src/runtime/domain/subagents/managed-worker.mjs +13 -0
  410. package/src/runtime/domain/subagents/model-resolution-core.domain.mjs +822 -0
  411. package/src/runtime/domain/subagents/model-resolution-core.ts +1074 -0
  412. package/src/runtime/domain/subagents/model-resolution.domain.mjs +22 -0
  413. package/src/runtime/domain/subagents/model-resolution.ts +32 -0
  414. package/src/runtime/domain/subagents/navigator.domain.mjs +6 -0
  415. package/src/runtime/domain/subagents/navigator.mjs +1233 -0
  416. package/src/runtime/domain/subagents/navigator.ts +39 -0
  417. package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +1012 -0
  418. package/src/runtime/domain/subagents/operation-bridge-types.ts +1156 -0
  419. package/src/runtime/domain/subagents/outage-observations.domain.mjs +84 -0
  420. package/src/runtime/domain/subagents/outage-observations.ts +73 -0
  421. package/src/runtime/domain/subagents/output-payload.domain.mjs +767 -0
  422. package/src/runtime/domain/subagents/output-payload.ts +987 -0
  423. package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
  424. package/src/runtime/domain/subagents/owned-exit.ts +12 -0
  425. package/src/runtime/domain/subagents/package.json +86 -0
  426. package/src/runtime/domain/subagents/park-checkpoint.domain.mjs +55 -0
  427. package/src/runtime/domain/subagents/park-checkpoint.ts +61 -0
  428. package/src/runtime/domain/subagents/parse.domain.mjs +1218 -0
  429. package/src/runtime/domain/subagents/parse.ts +1451 -0
  430. package/src/runtime/domain/subagents/permission-policy.domain.mjs +232 -0
  431. package/src/runtime/domain/subagents/permission-policy.ts +291 -0
  432. package/src/runtime/domain/subagents/process-identity.mjs +33 -0
  433. package/src/runtime/domain/subagents/registry.domain.mjs +1584 -0
  434. package/src/runtime/domain/subagents/registry.ts +1904 -0
  435. package/src/runtime/domain/subagents/role-assignment.domain.mjs +104 -0
  436. package/src/runtime/domain/subagents/role-assignment.ts +141 -0
  437. package/src/runtime/domain/subagents/roles/role.architect.md +13 -0
  438. package/src/runtime/domain/subagents/roles/role.developer.md +16 -0
  439. package/src/runtime/domain/subagents/roles/role.explorer.md +13 -0
  440. package/src/runtime/domain/subagents/roles/role.product-manager.md +13 -0
  441. package/src/runtime/domain/subagents/roles/role.researcher.md +13 -0
  442. package/src/runtime/domain/subagents/roles/role.reviewer.md +13 -0
  443. package/src/runtime/domain/subagents/roles/role.writer.md +12 -0
  444. package/src/runtime/domain/subagents/sandbox.domain.mjs +64 -0
  445. package/src/runtime/domain/subagents/sandbox.ts +92 -0
  446. package/src/runtime/domain/subagents/session-selection.domain.mjs +32 -0
  447. package/src/runtime/domain/subagents/session-selection.ts +35 -0
  448. package/src/runtime/domain/subagents/session-store.domain.mjs +489 -0
  449. package/src/runtime/domain/subagents/session-store.ts +468 -0
  450. package/src/runtime/domain/subagents/settings-page.domain.mjs +313 -0
  451. package/src/runtime/domain/subagents/settings-page.ts +363 -0
  452. package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +777 -0
  453. package/src/runtime/domain/subagents/shared-callback-batcher.ts +956 -0
  454. package/src/runtime/domain/subagents/shared-catalog.domain.mjs +70 -0
  455. package/src/runtime/domain/subagents/shared-catalog.ts +61 -0
  456. package/src/runtime/domain/subagents/shared-execution-policy.domain.mjs +50 -0
  457. package/src/runtime/domain/subagents/shared-execution-policy.ts +61 -0
  458. package/src/runtime/domain/subagents/shared-failure-observations.domain.mjs +1078 -0
  459. package/src/runtime/domain/subagents/shared-failure-observations.ts +1166 -0
  460. package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +126 -0
  461. package/src/runtime/domain/subagents/shared-harness-settings.ts +116 -0
  462. package/src/runtime/domain/subagents/shared-log-utils.domain.mjs +1223 -0
  463. package/src/runtime/domain/subagents/shared-log-utils.ts +1492 -0
  464. package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +289 -0
  465. package/src/runtime/domain/subagents/shared-navigator-panels.ts +272 -0
  466. package/src/runtime/domain/subagents/shared-navigator.domain.mjs +1930 -0
  467. package/src/runtime/domain/subagents/shared-navigator.ts +1962 -0
  468. package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
  469. package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +189 -0
  470. package/src/runtime/domain/subagents/shared-operation-coordinator/index.domain.mjs +51 -0
  471. package/src/runtime/domain/subagents/shared-operation-coordinator/index.ts +122 -0
  472. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
  473. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
  474. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +163 -0
  475. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
  476. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
  477. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
  478. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
  479. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +90 -0
  480. package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
  481. package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +139 -0
  482. package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.domain.mjs +12 -0
  483. package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.ts +79 -0
  484. package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +342 -0
  485. package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +513 -0
  486. package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
  487. package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +458 -0
  488. package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
  489. package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.ts +55 -0
  490. package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
  491. package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +140 -0
  492. package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +280 -0
  493. package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +442 -0
  494. package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +420 -0
  495. package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +441 -0
  496. package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
  497. package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.ts +239 -0
  498. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +275 -0
  499. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +585 -0
  500. package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
  501. package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +142 -0
  502. package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
  503. package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.ts +224 -0
  504. package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +25 -0
  505. package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +707 -0
  506. package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
  507. package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.ts +22 -0
  508. package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.domain.mjs +234 -0
  509. package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.ts +241 -0
  510. package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +851 -0
  511. package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +1424 -0
  512. package/src/runtime/domain/subagents/shared-permission-blocker.domain.mjs +40 -0
  513. package/src/runtime/domain/subagents/shared-permission-blocker.ts +48 -0
  514. package/src/runtime/domain/subagents/shared-render-scheduler.domain.mjs +41 -0
  515. package/src/runtime/domain/subagents/shared-render-scheduler.ts +47 -0
  516. package/src/runtime/domain/subagents/shared-sandbox-core.domain.mjs +1531 -0
  517. package/src/runtime/domain/subagents/shared-sandbox-core.ts +1757 -0
  518. package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +591 -0
  519. package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +491 -0
  520. package/src/runtime/domain/subagents/shared-stall-detector.domain.mjs +37 -0
  521. package/src/runtime/domain/subagents/shared-stall-detector.ts +69 -0
  522. package/src/runtime/domain/subagents/shared-task-application.domain.mjs +185 -0
  523. package/src/runtime/domain/subagents/shared-task-application.ts +185 -0
  524. package/src/runtime/domain/subagents/shared-task-apply-patch.domain.mjs +416 -0
  525. package/src/runtime/domain/subagents/shared-task-apply-patch.ts +409 -0
  526. package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +325 -0
  527. package/src/runtime/domain/subagents/shared-task-exec.ts +335 -0
  528. package/src/runtime/domain/subagents/shared-task-files.domain.mjs +346 -0
  529. package/src/runtime/domain/subagents/shared-task-files.ts +342 -0
  530. package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
  531. package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
  532. package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +220 -0
  533. package/src/runtime/domain/subagents/shared-task-process-list.ts +209 -0
  534. package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +227 -0
  535. package/src/runtime/domain/subagents/shared-task-sandbox.ts +224 -0
  536. package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +92 -0
  537. package/src/runtime/domain/subagents/shared-task-tools.ts +123 -0
  538. package/src/runtime/domain/subagents/shared-work-client.mjs +303 -0
  539. package/src/runtime/domain/subagents/shared-worktree-context.domain.mjs +142 -0
  540. package/src/runtime/domain/subagents/shared-worktree-context.ts +158 -0
  541. package/src/runtime/domain/subagents/skill-picker.domain.mjs +316 -0
  542. package/src/runtime/domain/subagents/skill-picker.ts +353 -0
  543. package/src/runtime/domain/subagents/skills.domain.mjs +138 -0
  544. package/src/runtime/domain/subagents/skills.ts +183 -0
  545. package/src/runtime/domain/subagents/spawn.domain.mjs +72 -0
  546. package/src/runtime/domain/subagents/spawn.ts +80 -0
  547. package/src/runtime/domain/subagents/stop.domain.mjs +184 -0
  548. package/src/runtime/domain/subagents/stop.ts +217 -0
  549. package/src/runtime/domain/subagents/subagent-tools.domain.mjs +101 -0
  550. package/src/runtime/domain/subagents/subagent-tools.ts +137 -0
  551. package/src/runtime/domain/subagents/task-guard.domain.mjs +163 -0
  552. package/src/runtime/domain/subagents/task-guard.ts +144 -0
  553. package/src/runtime/domain/subagents/task-policy.domain.mjs +201 -0
  554. package/src/runtime/domain/subagents/task-policy.ts +236 -0
  555. package/src/runtime/domain/subagents/task-runtime.mjs +53 -0
  556. package/src/runtime/domain/subagents/task-tool-owner.domain.mjs +18 -0
  557. package/src/runtime/domain/subagents/task-tool-owner.ts +21 -0
  558. package/src/runtime/domain/subagents/thinking.domain.mjs +22 -0
  559. package/src/runtime/domain/subagents/thinking.ts +28 -0
  560. package/src/runtime/domain/subagents/tier-policy.domain.mjs +75 -0
  561. package/src/runtime/domain/subagents/tier-policy.ts +126 -0
  562. package/src/runtime/domain/subagents/timing-notifications.domain.mjs +51 -0
  563. package/src/runtime/domain/subagents/timing-notifications.ts +37 -0
  564. package/src/runtime/domain/subagents/timing.domain.mjs +487 -0
  565. package/src/runtime/domain/subagents/timing.ts +634 -0
  566. package/src/runtime/domain/subagents/tools.domain.mjs +558 -0
  567. package/src/runtime/domain/subagents/tools.ts +629 -0
  568. package/src/runtime/domain/subagents/widget.domain.mjs +6 -0
  569. package/src/runtime/domain/subagents/widget.mjs +246 -0
  570. package/src/runtime/domain/subagents/widget.ts +30 -0
  571. package/src/runtime/domain/subagents/work-observation.domain.mjs +316 -0
  572. package/src/runtime/domain/subagents/work-observation.ts +248 -0
  573. package/src/runtime/domain/subagents/worker-catalog.domain.mjs +120 -0
  574. package/src/runtime/domain/subagents/worker-catalog.ts +162 -0
  575. package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +1009 -0
  576. package/src/runtime/domain/subagents/worker-operations-host.ts +1238 -0
  577. package/src/runtime/domain/subagents/worker-waits.domain.mjs +2336 -0
  578. package/src/runtime/domain/subagents/worker-waits.ts +2878 -0
  579. package/src/runtime/domain/subagents/workspace-scope.domain.mjs +52 -0
  580. package/src/runtime/domain/subagents/workspace-scope.ts +50 -0
  581. package/src/runtime/health-config.ts +27 -11
  582. package/src/runtime/log-checkpoints.ts +117 -0
  583. package/src/runtime/mutation-store.ts +5 -4
  584. package/src/runtime/queries.ts +27 -3
  585. package/src/runtime/query-executor.ts +178 -34
  586. package/src/runtime/query-worker.mjs +119 -22
  587. package/src/runtime/read-model.ts +939 -113
  588. package/src/runtime/read-watchdog-probe.ts +4 -0
  589. package/src/runtime/result-supervision.ts +188 -16
  590. package/src/runtime/source-watch.ts +175 -0
  591. package/src/runtime/subagent-launch.ts +73 -0
  592. package/src/runtime/work-budget.ts +130 -0
  593. package/src/runtime/work-client.d.mts +8 -0
  594. package/src/runtime/work-client.mjs +150 -7
  595. package/src/server.ts +185 -22
  596. package/src/session-activity.ts +26 -4
  597. package/src/version.ts +1 -1
@@ -0,0 +1,633 @@
1
+ # pi-better-sandbox
2
+
3
+ Sandbox permissions for Pi's foreground tools, detached subagents, and local background tasks. See the [sandbox tool-loading and permission contract](../../docs/adr/0027-sandbox-tools-and-permissions.md).
4
+
5
+ ![Pi Better Sandbox package preview](https://raw.githubusercontent.com/1aboveio/pi-better-harness/main/docs/images/package-gallery/pi-better-sandbox.png)
6
+
7
+ It is installed by default with [`pi-better-harness`](https://github.com/1aboveio/pi-better-harness/tree/main/packages/pi-better-harness#readme), and can be installed on its own:
8
+
9
+ ```sh
10
+ pi install npm:pi-better-sandbox
11
+ ```
12
+
13
+ Either way you keep starting Pi the way you always have — `pi`. There is
14
+ no launcher or wrapper command. Main, Subagents, and Background tasks all start
15
+ inactive in fresh settings. Saved global profiles and session choices, including
16
+ enabled switches, keep their values. Open `/sandbox` to change any column, or use
17
+ `/sandbox on` for the current Main session. Edits apply immediately and are
18
+ saved to the current session branch. **Ctrl+S** saves all three profiles as
19
+ defaults for new sessions.
20
+
21
+ Press **Tab** to switch between **Tool loading** and **Use permissions**. Tool
22
+ loading lists the active Main tools and the providers for ordinary subagent
23
+ defaults. A role, explicit tool list, or exclusion changes the selection for a
24
+ particular launch. Local Background tasks launch commands through the Background
25
+ adapter. Use permissions shows resource rules for the three profiles.
26
+
27
+ ```text
28
+ Tool loading Use permissions Tab switch
29
+ Sandbox permissions Main Subagents Background tasks
30
+
31
+ Sandbox Off Off Off
32
+
33
+ Project files - - -
34
+ Outside project - - -
35
+ Stored credentials - - -
36
+ Run applications - - -
37
+ Shell scripts - - -
38
+ Command time limit - - -
39
+ Network access - - -
40
+ Process access - - -
41
+
42
+ ↑↓ Select · ←→ Column · Space Toggle · ctrl+s Save default · Esc Back
43
+ ```
44
+
45
+ Loading a tool for a task permits that task to call it. The role, tool list and
46
+ exclusions determine what loads. The active profile governs each operation.
47
+
48
+ Editable workers get `apply_patch` by default. With Subagents On, Harness binds
49
+ the guarded adapter and checks every patch target against the file rules.
50
+ Extension tools use the selected provider. A configured worker mapping or an
51
+ active user-installed provider can supply the implementation. The child verifies
52
+ its source before dispatch. Known network tools require Network access On.
53
+ Extension code runs inside the trusted Pi process, outside guarded file operations.
54
+
55
+ Project files and Outside project cycle through four levels:
56
+
57
+ | Level | Meaning |
58
+ | ----- | ------- |
59
+ | Off | No access. |
60
+ | Read | Read only. |
61
+ | Write | Read, create, and overwrite in place; removal is restricted, with the exceptions below. |
62
+ | Write & delete | Full access, including removal. This was called "Read / write"; saved settings keep it. |
63
+
64
+ Stored credentials uses the same labels but offers only **Off**, **Read**, and
65
+ **Write & delete**. Subagents default to Write & delete; Main retains Read.
66
+ Explicit saved defaults and session profiles are preserved, including Read and
67
+ Off. Changing the built-in default does not upgrade existing profiles.
68
+
69
+ Whatever these rows say, removal is always allowed in **temp**, **hidden
70
+ directories and files directly under your home** (`~/.cache`, `~/.gradle`,
71
+ `~/.npm`, …), and **git worktree folders** (`.worktrees/`, `*-worktrees/`). The
72
+ deny list below still wins there.
73
+
74
+ **Write blocks rename-based saves.** The kernel treats "rename a temp file over
75
+ an existing file" as removing that file. Under Write, git commits and editors or
76
+ package managers that save atomically fail outside those disposable places. Pi's
77
+ own `write` and `edit` tools write in place and keep working. Choose Write &
78
+ delete for a place where that matters. The table shows this hint when you
79
+ select the row.
80
+
81
+ **Outside project = Write** (the Subagents default) lets tasks write across your
82
+ home directory and temp, so tool caches just work with no per-tool setup. It
83
+ retains fixed protections that are not configurable per tool:
84
+
85
+ - **Credentials** follow the independent Stored credentials row. The Subagents
86
+ `Write & delete` default permits reading, modifying, and removing the files
87
+ listed below plus `~/Library/Keychains`,
88
+ `~/.claude/.credentials.json`, `~/.claude.json`, `~/.gnupg`,
89
+ `~/.codex/auth.json`, `~/.cargo/credentials(.toml)`, `~/.pgpass`, and
90
+ `~/.config/rclone`, subject to stricter protected-path rules. Set the row to
91
+ Read to deny credential writes or Off to hide them. Writable credentials let
92
+ CLIs such as `gcloud` update database permissions and refresh token state even
93
+ for read-only cloud queries. This also lets tasks alter or delete credentials;
94
+ it is not a read-only authentication capability.
95
+ - **Code that runs later** cannot be written, removed, or renamed: shell startup
96
+ files (`.bashrc`, `.zshrc`, `.profile`, and the rest), `~/.config/fish`,
97
+ `~/.gitconfig`, `~/.config/git`, `~/.config/systemd/user`,
98
+ `~/.config/autostart`, `~/.pi` (or `$PI_CODING_AGENT_DIR`), `~/.claude`,
99
+ `~/.agents`, `~/Library/LaunchAgents`, `~/.local/bin`, `~/bin`,
100
+ `~/.git-templates`, `~/.oh-my-zsh/custom`, `~/.gradle/init.d`,
101
+ and `~/.cargo/config(.toml)`. These stay readable, because subagents read skills from them.
102
+ Their parent folders can't be removed or renamed either, so you can clean
103
+ inside `~/.gradle` but not delete `~/.gradle` itself.
104
+ - **Harness state** (the subagent and background-task registries, run and
105
+ control directories, and task-runtime provenance) cannot be written, removed,
106
+ or renamed.
107
+
108
+ Every protected entry is guarded under the literal path under home, every symlink hop
109
+ on the way to its target, and the target itself. So a dotfiles manager's links
110
+ (stow, chezmoi), including chains of links, can't be swapped or retargeted. A
111
+ link whose target is missing protects that target too: it can't be created.
112
+
113
+ **Git config and hooks under home are not protected**, so git keeps working:
114
+ `git init`, `git clone` and `git worktree add` copy hook samples into `.git/hooks`.
115
+ A task can therefore plant code that a later git command runs, through any
116
+ repository's `.git/hooks` or `.git/config` (`core.hooksPath`, `core.fsmonitor`,
117
+ `diff.external`, filters, aliases), submodule hooks in `.git/modules/*/hooks`,
118
+ `gitdir:` redirects, or files that `~/.gitconfig` pulls in with `[include]`.
119
+ `~/.gitconfig`, `~/.config/git`, and `~/.git-templates` themselves stay protected. Add your own paths to the deny list with `/sandbox deny add <path>`. Under
120
+ Write, those paths are also protected from removal and renaming.
121
+
122
+ Space applies every change immediately, including higher permission levels,
123
+ capabilities switched on, and a sandbox switched off. `ctrl+s` saves the
124
+ defaults from any row on the first press, and the note names anything that
125
+ loosened. Enter only folds tool groups; it never saves defaults. The focused
126
+ row has a full-width background and bold text; the selected profile cell
127
+ also uses inverse styling. No model
128
+ tool can change these settings. Space toggles switches and cycles Command time
129
+ limit through 1 min, 5 min, 10 min, 30 min, and No limit. Detail cells under an
130
+ Off sandbox display a dimmed `-` and cannot be changed; their values return when
131
+ the sandbox is enabled again. When Run applications is Off, Shell scripts and
132
+ Command time limit are likewise dimmed and retain their values.
133
+
134
+ Run applications is the master switch for task command execution. With it On,
135
+ Shell scripts Off blocks `bash`, user-entered `!` and `!!` commands, and direct
136
+ launches of shell interpreters, including aliases. The guarded `run_application`
137
+ tool takes `executable: string`, `args: string[]`, and optional `timeout: number`,
138
+ and launches directly inside the OS sandbox without a shell. Applications such
139
+ as `pnpm` and `pytest` can still run scripts internally; this setting does not
140
+ prevent all descendant shells or guarantee an application finishes.
141
+
142
+ Direct execution requires Node.js with `process.execve` (22.15+ or 24+) so an
143
+ unsupported executable cannot fall back to a shell. Older runtimes refuse the
144
+ launch rather than weaken the restriction.
145
+
146
+ Command time limit is a hard maximum for each command: a model cannot raise it
147
+ or bypass it by omitting a timeout, and a smaller requested timeout wins. Cleanup
148
+ covers ordinary process-group descendants, not deliberately daemonized processes.
149
+ The default is Shell scripts On and No limit; all three Sandbox switches default
150
+ Off. To use direct-only Subagents with a 10-minute limit, set Subagents → Sandbox
151
+ On, Run applications On, Shell scripts Off, and Command time limit to 10 min,
152
+ then press Ctrl+S to save those defaults. New subagent and background launches
153
+ capture their policy; running work keeps its launch policy.
154
+
155
+ ### Platforms
156
+
157
+ | | macOS (Seatbelt) | Linux (Bubblewrap) | Windows |
158
+ | - | - | - | - |
159
+ | Outside project = Write | Writes across home and temp. Removal and renaming refused outside the disposable places. | Fallback: ordinary top-level home folders (`~/projects`, `~/Documents`, …) and home itself are **read-only**. Dot entries, temp, worktree folders (found within three levels of home), and the workspace are writable, removal included. A directory holding a protected symlink (typically `~/.config` with a stow link such as `~/.config/git`) keeps its existing entries writable but refuses new top-level entries. A protected symlink pointing at nothing can get an empty read-only placeholder that stays on disk; the launch says so, and you remove the placeholder before creating the real target. | No backend: confined launches fail closed. |
160
+ | Project files = Write | Enforced. | **Refused at launch** (bind mounts cannot separate removal from writing). Use Write & delete or Read. | No backend. |
161
+ | Deny list | Path rules, matched ignoring case on every volume (as Seatbelt does). | Credentials masked by empty mode-000 mounts. Code that runs later is bound read-only. | No backend. |
162
+
163
+ Linux could separate removal from writing with Landlock (5.19+), but nothing
164
+ here can apply it: Node has no binding and `bwrap` does not expose it. Windows
165
+ could use NTFS `DELETE` rights with a restricted token or AppContainer, which
166
+ would need a native launcher. Both are tracked as follow-ups; see
167
+ [ADR 0008](../../docs/adr/0008-write-without-delete.md).
168
+
169
+ ### Recovery snapshot (macOS)
170
+
171
+ When a confined subagent or background task starts with Outside project =
172
+ Write or Write & delete, the harness starts `tmutil localsnapshot` in the
173
+ background. That is an APFS local snapshot and needs no administrator rights.
174
+ Write can still empty or re-permission files in place, and Write & delete can
175
+ remove them. It takes at most one per 15 minutes per Pi process. The run never
176
+ waits for it. A failure shows as a warning (subagents) or a task-log line
177
+ (background tasks). Set `PI_SANDBOX_RECOVERY_SNAPSHOT=off` to turn it off.
178
+
179
+ Local snapshots are purgeable, so treat them as a recovery aid, not a backup.
180
+ The Seatbelt profile leaves Mach IPC to system daemons open, which is why
181
+ `security` and `tmutil` work inside the sandbox. It also means a hostile task
182
+ could likely delete these snapshots. Restore from one with Time Machine or
183
+ `tmutil restore`.
184
+
185
+ **Stored credentials currently means known credential files.** It covers SSH,
186
+ AWS, GitHub CLI, Google Cloud CLI, Azure, Kubernetes, Docker, npm, netrc, Git
187
+ credentials, and Pi's file-based auth. These rules override ordinary file access.
188
+ OS vault services such as Keychain and Secret Service, and tokens inherited in
189
+ environment variables, are excluded. Write & delete may be needed by a CLI that
190
+ refreshes a token or updates its credential database. This row applies
191
+ independently of Project files and Outside project.
192
+
193
+ **Process access** uses **Off** or **Read** (default for fresh profiles).
194
+ Main and Subagents control the fixed `process_list` tool. Its Read setting
195
+ returns current-user process IDs and names only, with optional
196
+ literal name filtering and a bounded result limit. It does not expose command
197
+ arguments, environment variables, debugger attachment, signals, termination,
198
+ or emulator/ADB operations. Explicit saved values are preserved, and legacy
199
+ saved profiles without this setting stay Off until a human enables Read;
200
+ subagents snapshot the setting at launch. Use `/sandbox status` to see Main's
201
+ `process_list` setting and where this session got it. While Main confinement is
202
+ Off, its retained Process access setting cannot deny the fixed inventory tool.
203
+ To change the value for confined use, edit **Main > Process access** in `/sandbox`
204
+ (Main confinement must be On to edit the detail rows).
205
+ No restart is needed for a local edit. Defaults saved in another session do not
206
+ change an already running session, and reloading a saved branch restores its
207
+ branch settings. Start a new session to use the saved defaults instead.
208
+
209
+ A worker launch reports confinement and Process access separately. A fresh
210
+ worker uses the current session's Subagents profile unless the launch requests
211
+ confinement explicitly. A continuation keeps its saved recipe's confinement
212
+ choice but applies the current Subagents permissions only if that profile is On.
213
+ Switching Subagents confinement Off does not unconfine a saved confined recipe:
214
+ its task sandbox uses the default permissions with guarded Process Read, subject
215
+ to any independent captured authority. If the current profile requires
216
+ confinement but the recipe is unconfined, the continuation is refused. Start a
217
+ new run for a new recipe. A continuation cannot silently drop `process_list`
218
+ if the saved loadout requires it and an active profile sets Process access Off.
219
+
220
+ Background tasks uses this row for explicit task-status process diagnostics, not
221
+ `process_list`. An active Background tasks profile must allow Process Read.
222
+ Those diagnostics check a registered
223
+ PID's start identity and can report state, CPU time and wait evidence without
224
+ arguments or environment values. They are unavailable under Main confinement;
225
+ no unconfined fallback runs. Task confinement remains the policy recorded when
226
+ the task launched, independent of current diagnostic permission.
227
+
228
+ The inventory helper uses a fixed system `pgrep` command under the existing
229
+ kernel policy, without a shell or model-controlled arguments. It can work with
230
+ Run applications Off because it is a fixed read-only adapter, not
231
+ general command execution. No sandbox restrictions are relaxed. The control
232
+ governs this adapter only: it does not make arbitrary shell process inspection
233
+ impossible when commands are enabled. Windows has no supported inventory backend.
234
+ Linux still requires a supported permission profile with visible process metadata;
235
+ hidden-root profiles without `/proc` fail rather than gaining a new host mount.
236
+
237
+ On macOS, `/bin/ps` is setuid and can be refused at execution by Seatbelt even
238
+ when process information reads are allowed. Enabling Process access provides
239
+ `process_list`. With Run applications enabled, Main and Subagents also prepend
240
+ a runtime-owned `ps` compatibility entry to task command PATH. It supports only
241
+ `ps -p PID -o lstart= -o comm=` for a current-user process, preserving the system
242
+ command's timestamp/path output. Unsupported arguments fail explicitly; callers
243
+ that reset PATH or use absolute `/bin/ps` retain the OS restriction.
244
+
245
+ The compatibility entry is compiled once per session control directory from
246
+ fixed harness source with `/usr/bin/clang` (Xcode Command Line Tools required).
247
+ It is non-setuid, protected from task writes, integrity-checked before reuse,
248
+ and runs inside the same sandbox. It checks UID, executable path and stable
249
+ kernel start time before emitting output; no argv, environment or process control
250
+ is exposed. The legacy text format has second-level start-time precision and is
251
+ not a durable process handle. Process Off does not install the entry; it remains
252
+ an adapter control, not a syscall-wide prohibition. Compiler failure leaves an
253
+ explicitly unavailable entry and does not block unrelated commands. Install the
254
+ toolchain and restart the session to retry. Linux and Background execution are
255
+ unchanged. No raw `/bin/ps` or unconfined fallback is authorized.
256
+
257
+ File and shell operations use the kernel: macOS uses Seatbelt (`sandbox-exec`)
258
+ and Linux uses Bubblewrap (`bwrap`). `read`, `write`, and `edit` keep Pi's normal
259
+ tool behavior and mutation queues, while a fixed worker performs filesystem
260
+ syscalls under the selected policy. Canonical checks explain denials; kernel
261
+ enforcement also protects against a symlink changing between checking and use.
262
+ The confined file worker rejects files over 8 MiB instead of silently truncating
263
+ them; larger-file processing can use a confined command when commands are On.
264
+
265
+ ## What is confined, and what is not
266
+
267
+ Pi is the trusted runtime. It can lock configuration/authentication files,
268
+ connect to its provider, and persist sessions. Main and Subagents permissions
269
+ apply to task operations. Subagents can start with task Network access or Run
270
+ applications Off. The fixed file worker remains available according
271
+ to the file permissions even when task commands are Off.
272
+
273
+ The task executor provides private scratch through `TMPDIR`, `TMP`, and `TEMP`.
274
+ Outside Read and Write & delete also retain explicit runtime write exceptions for
275
+ `/tmp` (canonical `/private/tmp` on macOS), the current user's macOS temporary
276
+ directory, and that user's Security.framework MDS cache. MDS access lets CLI
277
+ Keychain retrieval initialize and refresh its cache; it does not restrict the
278
+ Keychain API to reads. Other users' caches and arbitrary outside `*.lock` files
279
+ are not writable. Credential-file and Pi control-path protections still win.
280
+ Outside Off does not expose these host runtime directories.
281
+
282
+ The currently admitted model-tool implementations are `read`, `write`, `edit`,
283
+ `bash`, and guarded `run_application`, plus, for Subagents, the guarded `apply_patch` and selected extension tools
284
+ with verified providers. User-entered `!` and `!!` commands use the same
285
+ shell policy. Other model-callable tools require a verified execution adapter
286
+ and are refused while that actor's sandbox is enabled; enabling network alone
287
+ does not admit them. Subagent launch output identifies requested tools that are
288
+ unavailable, with the reason. Main
289
+ remains Off by default, so its ordinary orchestration tools remain available
290
+ unless the user enables Main confinement.
291
+
292
+ Pi and installed runtime extensions remain trusted code, including their
293
+ initialization, provider hooks, and internal `pi.exec` calls. The tool gate is
294
+ not a sandbox around malicious runtime extensions. Loaded runtime code,
295
+ configuration, and policy/control files are protected from task writes, even
296
+ under broader file grants. Task access to `~/.pi` does not receive a blanket
297
+ write allowance or lock-file exception.
298
+
299
+ Local confinement cannot govern a remote host's filesystem. SSH tools are
300
+ available to confined Subagents when selected with a verified provider and Network access On. They run outside local task rules.
301
+ Main SSH tools, and unadmitted MCP, scripting, background, and nested-agent
302
+ tools, still lack admission adapters and fail closed under an enabled actor
303
+ profile. SSH through confined `bash` receives local file, credential, and network
304
+ restrictions; remote effects remain outside the local filesystem policy.
305
+
306
+ Verified first-party Background tools have a separate, versioned admission
307
+ adapter. It checks the loaded extension's canonical source and exact current
308
+ schema identity before admitting local spawn/watch and explicit registry
309
+ operations. Background's column controls the executable, independently of
310
+ Main's commands switch. Missing or incompatible adapters fail closed when
311
+ Background confinement is enabled, even with Main Off. Remote stop receives no
312
+ local-adapter exemption under Main confinement. See [ADR 0017](../../docs/adr/0017-background-adapter-admission.md).
313
+
314
+ Overriding `write` and `edit` changes nothing you can see: the parameter
315
+ schemas, prompt guidance, call rendering, write previews, edit diffs, result
316
+ details, mutation queueing, and cancellation are Pi's own. Only the filesystem
317
+ operations underneath them are replaced.
318
+
319
+ ## Local Permission Diagnostics
320
+
321
+ Opt in with `/sandbox diagnostics on`. Saved in global `settings.json`, this
322
+ collects redacted local observations from foreground guards, guarded file
323
+ operations, and background launch preflight, plus redacted worker reports.
324
+ Collection is off by default and never changes permissions or uploads data.
325
+
326
+ - `/sandbox diagnostics status`: show collection state and retained evidence.
327
+ - `/sandbox diagnostics summary`: group denials and observed recoveries.
328
+ - `/sandbox diagnostics export`: write a redacted local JSON export for sharing.
329
+ - `/sandbox diagnostics off`: stop collection without deleting retained evidence.
330
+
331
+ The bounded journal lives under `<agent-dir>/diagnostics/sandbox`: at most 2,000
332
+ observations, 1 MiB, and 30 days. Records contain resource categories, package
333
+ version, platform/backend, and installation-keyed fingerprints, not raw commands,
334
+ paths, file contents, or output. Export excludes the fingerprint key.
335
+
336
+ Confirmed policy refusals are separate from `EACCES`/`EPERM` observations, which
337
+ do not prove the sandbox caused the failure. Confined workers relay fixed,
338
+ redacted reports to their parent, which records them as `agent-reported`; workers
339
+ never receive write access to the global journal. Worker retry correlations stay
340
+ within the reporting worker. Arbitrary shell output and nonzero exits are not
341
+ classified. Recovery is an observed success, not authorization for broader
342
+ permissions or remote access. Summaries disclose journal gaps and retention
343
+ losses; collection failures that prevent a write may not persist.
344
+
345
+ Storage contention is bounded and never overrides a writer's lock by age. If an
346
+ abruptly terminated collector leaves `events.jsonl.lock`, collection warns and
347
+ stops writing. Stop every collector before manually removing that empty lock
348
+ directory. Existing evidence is retained; enforcement is unaffected.
349
+
350
+ ## Commands
351
+
352
+ ```text
353
+ /sandbox open the permission table (text status outside TUI)
354
+ /sandbox on enable protection for operations started from now on
355
+ /sandbox off turn protection off for this session (interactive confirmation)
356
+ /sandbox default on persist opt-in and enable it now
357
+ /sandbox default off persist opt-out (interactive confirmation)
358
+ /sandbox deny list show the write-denied paths
359
+ /sandbox deny add <path> stop allowing writes to a path
360
+ /sandbox deny remove <path> allow writes to a path again
361
+ /sandbox deny reset drop your changes and restore the packaged defaults
362
+ /sandbox rules open the write-denied paths editor
363
+ ```
364
+
365
+ Sandbox status is not displayed in the footer. Use `/sandbox` to inspect the
366
+ permission table, or the text status report outside the TUI. Explicitly enabled
367
+ sessions still warn when protection cannot be applied. Status reports describe
368
+ what the runtime actually resolved, including the backend and executable, never
369
+ what was merely configured.
370
+
371
+ `/sandbox off` and `/sandbox default off` need interactive confirmation and are
372
+ refused outright when there is no interactive UI. There is no tool for changing
373
+ sandbox state or its rules, so the model cannot change confinement or edit the
374
+ paths it is confined away from.
375
+
376
+ ## Write-denied paths
377
+
378
+ Three paths are denied out of the box — `.git/hooks`, `.env`, and `.env.local`,
379
+ relative to whichever project you are in. They live in the package's source, so
380
+ installing writes no settings file anywhere.
381
+
382
+ Rules are paths, not patterns. Write one of three ways:
383
+
384
+ | You type | It means |
385
+ | ------------------- | --------------------------------------------------- |
386
+ | `build/artifacts` | that path inside **every** project you open |
387
+ | `~/.aws` | that path under your home directory |
388
+ | `/etc/hosts` | exactly that path |
389
+
390
+ A relative rule is stored as a template and resolved against each project, which
391
+ is why one global rule set is enough — there is no per-project database. Lists
392
+ and the editor always show the canonical absolute path a rule currently resolves
393
+ to. A directory denies its whole subtree; a file denies that exact file, whether
394
+ or not it exists yet.
395
+
396
+ `/sandbox rules` opens a compact keyboard-driven editor over the same rules:
397
+ arrow keys to move, enter to remove the highlighted rule, or pick *Add* to type
398
+ a new one and *Restore the packaged defaults* to start over. The slash commands
399
+ and the editor are two front ends over one validation and persistence module, so
400
+ they cannot disagree.
401
+
402
+ Changes take effect for shell commands and file mutations started after them.
403
+ A command already running keeps the rules it launched with.
404
+
405
+ ### Where your rules live
406
+
407
+ Your changes are written to `~/.pi/agent/settings.json` (under
408
+ `$PI_CODING_AGENT_DIR` when you set one), in the `piBetterHarness` namespace:
409
+
410
+ ```json
411
+ {
412
+ "piBetterHarness": {
413
+ "sandboxDenyRules": {
414
+ "version": 1,
415
+ "denyWrite": [".env", ".env.local", ".git/hooks", "build/artifacts"]
416
+ }
417
+ }
418
+ }
419
+ ```
420
+
421
+ The override key appears the first time you add or remove a rule, or when an
422
+ existing legacy override is migrated; installation alone writes nothing.
423
+ `/sandbox deny reset` sets `sandboxDenyRules` to `null` and puts the defaults
424
+ shipped by the installed package version back in force. The sentinel prevents a
425
+ retained legacy file from being imported again and does not store a stale copy
426
+ of the packaged defaults. Other Pi and harness settings remain unchanged.
427
+
428
+ If the file cannot be read, the packaged defaults stay in force, the problem is
429
+ reported, and rule changes are refused until you fix the override or reset it —
430
+ a typo is never quietly turned into a lost rule set. If the whole `settings.json`
431
+ file is invalid JSON, repair it by hand first; a deny reset cannot discard other
432
+ settings to repair the file.
433
+
434
+ ### What is refused, and why
435
+
436
+ - **Empty entries and patterns** (`*.pem`, `src/**/x`) — rules are concrete
437
+ paths; a pattern would silently match nothing.
438
+ - **Duplicates**, however they are spelled: `.env`, `./.env`, the absolute path,
439
+ or a symlink pointing at the same file all resolve to one canonical path.
440
+ - **Overlaps**, in both directions. A path already inside a denied directory
441
+ would change nothing; a directory that would swallow a narrower rule names
442
+ that rule so you can remove it deliberately instead of losing it silently.
443
+ - **A rule that contains the project root** — `.`, `..`, `/`, or `~` when your
444
+ project lives under home. Denying it would make every write in the project
445
+ fail. `/sandbox off` is the thing you actually want there.
446
+
447
+ A global rule that turns out to contain the root of a *different* project stays
448
+ in your rule set but is held out in that project, with a message saying so.
449
+
450
+ ### Upgrading
451
+
452
+ Sandbox defaults now share global `settings.json` under `piBetterHarness`:
453
+ `sandbox` stores version 1 activation preferences, `sandboxPermissions` stores
454
+ version 1 permission profiles, and `sandboxDenyRules` stores the rule override.
455
+ On first read of a missing key, the corresponding validated legacy file in
456
+ `extensions/` is imported: `pi-better-sandbox-preferences.json`,
457
+ `pi-better-sandbox-permissions.json`, or `pi-better-sandbox.json`. Legacy files
458
+ are left untouched. An existing global key always wins, including the deny-rule
459
+ `null` sentinel; invalid global values are reported, not replaced by legacy data.
460
+ Updates use locked atomic replacement and preserve unrelated Pi settings and
461
+ other harness keys.
462
+
463
+ Fresh configurations now start all three sandbox switches Off. Saved enabled
464
+ profiles stay enabled, and session choices still restore on resume, fork, reload,
465
+ and tree navigation. No saved permissions are reset by the new activation default.
466
+ Standalone subagents also default to unconfined without published settings;
467
+ `sandbox:true` still requests kernel confinement, and `sandbox:false` cannot
468
+ bypass a human-enabled Subagents profile.
469
+
470
+ A version 1 global or session permission record without `background` inherits a
471
+ copy of its existing Main profile, including its switch and every permission.
472
+ Migration preserves the existing behavior and does not link future edits.
473
+ Saving defaults or a session edit writes the separate `background` profile.
474
+ An explicitly malformed Background tasks profile fails closed; it is never
475
+ replaced by Main or fresh defaults.
476
+
477
+ A saved permission profile keeps its values: a saved `read-write` is now shown as Write & delete, and a saved
478
+ Subagents Outside project = Read stays Read. Only a fresh configuration, or
479
+ **Ctrl+S** after you choose Write, uses the new Subagents default. To
480
+ adopt it, open `/sandbox`, set Subagents → Outside project to Write, and save.
481
+
482
+ `~/.pi/agent/sandbox.json` (`filesystem.allowWrite`, `allowRead`,
483
+ `network.allowedDomains`) is the format of Pi's example sandbox extension. This
484
+ package never reads it, and it has no effect on the harness.
485
+
486
+ ## Lifecycle
487
+
488
+ All three sandbox switches are inactive in fresh settings. Permission edits, including
489
+ Sandbox switches and `/sandbox on|off`, auto-persist as Pi custom entries on the
490
+ current session branch, not as global defaults. Resume, fork, reload and session
491
+ tree navigation restore the latest policy on the active branch. A branch with
492
+ no permission entry and a new session inherit saved global settings. Invalid
493
+ persisted session policy fails closed rather than falling back to defaults.
494
+ Ctrl+S writes all three profiles to `piBetterHarness.sandboxPermissions` in global
495
+ `settings.json`. When no saved profile exists, the Main switch inherits the
496
+ activation preference from `piBetterHarness.sandbox`, including migrated legacy
497
+ activation preferences. Background tasks initially inherits that Main profile.
498
+ `/sandbox default on|off` remains available and updates only Main's saved switch.
499
+ After migration, Main changes never change Background tasks. Enable Background
500
+ tasks while Main is Off to confine new local background launches independently.
501
+ Running tasks keep their launch policy. The Subagents column and Tools section
502
+ remain independent and unchanged.
503
+ Failed default saves leave the current session's edits intact. Write-deny rules
504
+ retain their global persistence in `piBetterHarness.sandboxDenyRules` through
505
+ `/sandbox deny` and `/sandbox rules`. Session entries and runtime control-plane
506
+ protections are unchanged.
507
+
508
+ Toggles apply to operations launched after the change. A command already running
509
+ keeps the policy it launched with.
510
+
511
+ ## Fail-closed behaviour
512
+
513
+ While the sandbox is explicitly or persistently enabled and a backend cannot be
514
+ applied, protected commands and file mutations are **blocked** rather than run
515
+ unprotected:
516
+
517
+ - No backend on this platform (`unavailable`).
518
+ - A launch directory too broad to confine — `/` or your home directory
519
+ (`failed`). Relaunch Pi from the directory you are actually working in, or
520
+ turn the sandbox off on purpose.
521
+ - A backend that was selected but failed to start. It is never retried directly.
522
+
523
+ ## Paths, symlinks and denied files
524
+
525
+ The launch directory is canonicalized at session start, so reaching a project
526
+ through a symlink does not widen what is writable. Denied entries are
527
+ canonicalized the same way: a directory denies its whole subtree, a file denies
528
+ that exact file, and an alias pointing at a denied file is denied too.
529
+
530
+ ## Platform support
531
+
532
+ | Platform | Backend | Requirement |
533
+ | -------- | --------------------------- | ---------------------------- |
534
+ | macOS | Seatbelt (`sandbox-exec`) | ships with the OS |
535
+ | Linux | Bubblewrap (`bwrap`) | install `bubblewrap` |
536
+ | Other | none | protected commands are blocked |
537
+
538
+ A detached subagent gets a private session/temp directory for Pi's runtime
539
+ state. This directory stays writable even with Outside project set to Read or
540
+ Off; other runs' state and the parent's launch metadata are not included.
541
+ Read access to system executable and library directories, device I/O, and root
542
+ directory metadata/listing remains available so a process can start. On macOS,
543
+ the allowance excludes the broad `/System/Volumes` tree.
544
+
545
+ Linux currently refuses combinations it cannot safely mount: hiding the
546
+ project or credential files inside a visible whole-filesystem bind, writing
547
+ credential stores under a read-only outside root, a writable outside root
548
+ (Write & delete) with protected paths, and Project files = Write. These launch errors preserve the selected restrictions.
549
+ The macOS permission combinations are covered by real-kernel tests; Linux
550
+ mount behavior requires a Linux runner with Bubblewrap and user namespaces.
551
+
552
+ ### macOS setuid executable limitation
553
+
554
+ Seatbelt-sandboxed processes cannot execute setuid/setgid binaries, even with
555
+ an `(allow default)` profile. On the verified host, `/bin/ps` and `/usr/bin/top`
556
+ are setuid-root binaries. A shell attempting to run `/bin/ps` reports
557
+ `Operation not permitted` and exits 126. This is an OS-level execution
558
+ restriction, not a harness command deny rule, a filesystem permission failure,
559
+ or evidence that Run applications is Off.
560
+
561
+ Read-only reproduction (verified on 2026-10-04):
562
+
563
+ ```sh
564
+ ls -l /bin/ps /usr/bin/top
565
+ /usr/bin/sandbox-exec -p '(version 1) (allow default)' \
566
+ /bin/bash -c '/bin/ps -p $$ -o pid,ppid,comm'
567
+ ```
568
+
569
+ The second command fails with `/bin/bash: /bin/ps: Operation not permitted`
570
+ and exit 126; the same `ps` query outside Seatbelt succeeds. Launching `ps`
571
+ directly through `sandbox-exec` instead reports `execvp()` failure and exit 71.
572
+ Changing the requested output fields or adding a profile allowance for `ps`
573
+ does not remove this limitation.
574
+
575
+ When process inspection is a prerequisite for safe work, do not interpret the
576
+ denial as an empty process list. Hold the dependent operation until an
577
+ authorized coordinator or environment custodian supplies a fresh snapshot
578
+ and explicit ownership handoff from outside the task sandbox. Prefer
579
+ `pid,ppid,pgid,lstart,comm` over full command arguments, which may expose
580
+ secrets. Do not disable the sandbox or modify/copy privileged executables to
581
+ work around the denial. A trusted process-inspection adapter would require
582
+ separate implementation; this package does not currently provide one.
583
+
584
+ See the [session evidence](../../docs/sandbox-session-validation.md#macos-process-inspection-follow-up)
585
+ and [documented setuid/setgid limitation](https://github.com/navikt/cplt/blob/main/docs/known-impacts.md).
586
+
587
+ ## For other extensions
588
+
589
+ The effective policy is published as a frozen snapshot on Pi's extension event
590
+ bus. It carries policy and status only — never a way to run anything.
591
+
592
+ The top-level fields still describe Main. The additive `background` field
593
+ contains the independently computed local Background tasks launch policy:
594
+
595
+ ```ts
596
+ type BackgroundSandboxPolicy = {
597
+ state: "enabled" | "disabled" | "unavailable" | "failed";
598
+ writableRoot: string | undefined;
599
+ denyWrite: readonly string[];
600
+ reason: string;
601
+ permissions?: Readonly<SandboxPermissionProfile>;
602
+ };
603
+ ```
604
+
605
+ `permissions` has the same shape as the existing foreground profile: `enabled`,
606
+ `projectFiles`, `outsideProject`, `storedCredentials`, `commands`, `shell`,
607
+ `commandTimeoutSeconds`, `network`, and `processAccess`. The additive `shell`
608
+ and `commandTimeoutSeconds` fields default to `true` and `null` for legacy
609
+ profiles; the settings envelope remains version 1. It is present after settings load. `background`, its
610
+ `denyWrite` array, and its permission object are frozen copies. Background
611
+ checks the backend, project root, and runtime-path safety independently of Main;
612
+ Main Off does not suppress a requested Background sandbox. `inactive` is
613
+ published as `disabled`. Invalid loaded policy fails both profiles closed.
614
+
615
+ The existing `pi-better-sandbox:policy-request` channel republishes both profiles.
616
+ Consumers should snapshot `policy.background` at launch. Consumers must support the new restrictions before applying them. Incompatible
617
+ older subagent or background consumers are rejected when a restrictive policy
618
+ would otherwise be dropped.
619
+
620
+ ```ts
621
+ import {
622
+ FOREGROUND_SANDBOX_POLICY_CHANNEL,
623
+ FOREGROUND_SANDBOX_POLICY_REQUEST_CHANNEL,
624
+ type ForegroundSandboxPolicyEvent,
625
+ } from "pi-better-sandbox";
626
+
627
+ pi.events.on(FOREGROUND_SANDBOX_POLICY_CHANNEL, (policy) => {
628
+ // Snapshot it at launch time; a running operation keeps its launch policy.
629
+ });
630
+
631
+ // Loaded late and missed the last publication? Ask for the current one.
632
+ pi.events.emit(FOREGROUND_SANDBOX_POLICY_REQUEST_CHANNEL, undefined);
633
+ ```