pi-better-server 0.5.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 (278) hide show
  1. package/package.json +4 -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 +37 -5
  6. package/scripts/event-publication/writer.mjs +3 -8
  7. package/scripts/measure-full-runtime/probe.mjs +4 -2
  8. package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
  9. package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
  10. package/scripts/measure-shared-reads.mjs +2 -1
  11. package/scripts/private-runtime/package-lock.json +18 -0
  12. package/scripts/private-runtime/package.json +4 -1
  13. package/scripts/source-provenance.mjs +2 -2
  14. package/scripts/test-on-pi.sh +2 -9
  15. package/src/handshake.ts +1 -1
  16. package/src/hosted-session.ts +32 -4
  17. package/src/maintenance.ts +35 -7
  18. package/src/registry.ts +28 -4
  19. package/src/runtime/attempt-invalidation.ts +54 -0
  20. package/src/runtime/background-history.ts +151 -45
  21. package/src/runtime/background-policy.ts +9 -4
  22. package/src/runtime/background-tools.ts +131 -23
  23. package/src/runtime/background.ts +351 -68
  24. package/src/runtime/cancellation.ts +28 -7
  25. package/src/runtime/catalog-sources.ts +199 -0
  26. package/src/runtime/catalog.ts +53 -21
  27. package/src/runtime/client.ts +22 -2
  28. package/src/runtime/domain/assignment-inbox.mjs +119 -0
  29. package/src/runtime/domain/assignment-observation.d.mts +1 -1
  30. package/src/runtime/domain/assignment-observation.mjs +43 -35
  31. package/src/runtime/domain/background/process-identity.mjs +20 -2
  32. package/src/runtime/domain/background/process.mjs +3 -3
  33. package/src/runtime/domain/background/registry.mjs +61 -3
  34. package/src/runtime/domain/background/types.mjs +1 -0
  35. package/src/runtime/domain/background-service/adapter-contract.domain.mjs +1 -1
  36. package/src/runtime/domain/background-service/adapter-contract.ts +1 -1
  37. package/src/runtime/domain/background-service/goal-provider.domain.mjs +35 -16
  38. package/src/runtime/domain/background-service/goal-provider.ts +31 -16
  39. package/src/runtime/domain/background-service/index.domain.mjs +6 -9
  40. package/src/runtime/domain/background-service/index.ts +6 -9
  41. package/src/runtime/domain/background-service/managed-authority.domain.mjs +6 -3
  42. package/src/runtime/domain/background-service/managed-authority.ts +5 -3
  43. package/src/runtime/domain/background-service/managed-client.domain.mjs +21 -7
  44. package/src/runtime/domain/background-service/managed-client.ts +20 -7
  45. package/src/runtime/domain/background-service/managed-frontend.domain.mjs +75 -17
  46. package/src/runtime/domain/background-service/managed-frontend.ts +62 -17
  47. package/src/runtime/domain/background-service/navigator-provider.domain.mjs +16 -5
  48. package/src/runtime/domain/background-service/navigator-provider.ts +15 -5
  49. package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
  50. package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
  51. package/src/runtime/domain/background-service/observed-waits.domain.mjs +170 -27
  52. package/src/runtime/domain/background-service/observed-waits.ts +154 -30
  53. package/src/runtime/domain/background-service/process-identity.domain.mjs +20 -2
  54. package/src/runtime/domain/background-service/process-identity.ts +18 -2
  55. package/src/runtime/domain/background-service/process.domain.mjs +3 -3
  56. package/src/runtime/domain/background-service/process.ts +3 -3
  57. package/src/runtime/domain/background-service/registry.domain.mjs +61 -3
  58. package/src/runtime/domain/background-service/registry.ts +53 -5
  59. package/src/runtime/domain/background-service/runtime.domain.mjs +32 -16
  60. package/src/runtime/domain/background-service/runtime.ts +19 -9
  61. package/src/runtime/domain/background-service/sandbox.domain.mjs +14 -15
  62. package/src/runtime/domain/background-service/sandbox.ts +14 -11
  63. package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +8 -1
  64. package/src/runtime/domain/background-service/shared-callback-batcher.ts +11 -2
  65. package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +24 -2
  66. package/src/runtime/domain/background-service/shared-navigator-panels.ts +26 -4
  67. package/src/runtime/domain/background-service/shared-navigator.domain.mjs +218 -13
  68. package/src/runtime/domain/background-service/shared-navigator.ts +197 -14
  69. package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
  70. package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +53 -41
  71. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
  72. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
  73. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
  74. package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
  75. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
  76. package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +14 -3
  77. package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
  78. package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +5 -3
  79. package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +44 -4
  80. package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +50 -2
  81. package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
  82. package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +12 -0
  83. package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +2 -0
  84. package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +2 -0
  85. package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +42 -21
  86. package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +40 -24
  87. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +21 -3
  88. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +34 -8
  89. package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
  90. package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +24 -1
  91. package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +1 -1
  92. package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +5 -1
  93. package/src/runtime/domain/background-service/shared-sandbox-core.ts +1 -1
  94. package/src/runtime/domain/background-service/shared-work-client.mjs +174 -7
  95. package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
  96. package/src/runtime/domain/background-service/supervisor/generated/process.mjs +3 -3
  97. package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +1 -1
  98. package/src/runtime/domain/background-service/task-diagnostics.ts +1 -1
  99. package/src/runtime/domain/background-service/tools.domain.mjs +31 -24
  100. package/src/runtime/domain/background-service/tools.ts +41 -38
  101. package/src/runtime/domain/background-service/types.domain.mjs +1 -0
  102. package/src/runtime/domain/background-service/types.ts +3 -1
  103. package/src/runtime/domain/background-service/work-observation.domain.mjs +46 -20
  104. package/src/runtime/domain/background-service/work-observation.ts +46 -19
  105. package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
  106. package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
  107. package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
  108. package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
  109. package/src/runtime/domain/coordinator/src/background-requests.mjs +11 -2
  110. package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
  111. package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
  112. package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
  113. package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
  114. package/src/runtime/domain/coordinator/src/schema.mjs +42 -21
  115. package/src/runtime/domain/coordinator/src/store.mjs +21 -3
  116. package/src/runtime/domain/coordinator/src/subagent-launch.mjs +23 -1
  117. package/src/runtime/domain/coordinator/src/types.mjs +1 -1
  118. package/src/runtime/domain/health-observation.d.mts +3 -1
  119. package/src/runtime/domain/health-observation.mjs +189 -190
  120. package/src/runtime/domain/log-cursor.d.mts +2 -0
  121. package/src/runtime/domain/log-cursor.mjs +85 -16
  122. package/src/runtime/domain/parse.d.mts +4 -1
  123. package/src/runtime/domain/parse.mjs +50 -5
  124. package/src/runtime/domain/sandbox-policy/README.md +61 -63
  125. package/src/runtime/domain/sandbox-policy/commands.domain.mjs +11 -8
  126. package/src/runtime/domain/sandbox-policy/commands.ts +12 -7
  127. package/src/runtime/domain/sandbox-policy/index.domain.mjs +53 -9
  128. package/src/runtime/domain/sandbox-policy/index.ts +52 -9
  129. package/src/runtime/domain/sandbox-policy/package.json +1 -1
  130. package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +5 -2
  131. package/src/runtime/domain/sandbox-policy/permission-settings.ts +9 -2
  132. package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +56 -137
  133. package/src/runtime/domain/sandbox-policy/permissions-page.ts +52 -130
  134. package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +1 -6
  135. package/src/runtime/domain/sandbox-policy/permissions.ts +1 -6
  136. package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1 -1
  137. package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +14 -1
  138. package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +12 -1
  139. package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
  140. package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
  141. package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +3 -2
  142. package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +8 -2
  143. package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +4 -3
  144. package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +5 -3
  145. package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +8 -5
  146. package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +8 -5
  147. package/src/runtime/domain/subagents/README.md +1 -1
  148. package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +12 -6
  149. package/src/runtime/domain/subagents/assignment-outcomes.ts +11 -5
  150. package/src/runtime/domain/subagents/assignment-report.domain.mjs +87 -24
  151. package/src/runtime/domain/subagents/assignment-report.ts +83 -19
  152. package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +21 -3
  153. package/src/runtime/domain/subagents/catalog-host-admission.ts +19 -3
  154. package/src/runtime/domain/subagents/catalog-preferences.ts +1 -1
  155. package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +35 -1
  156. package/src/runtime/domain/subagents/catalog-resolver.ts +35 -1
  157. package/src/runtime/domain/subagents/catalog-store.domain.mjs +20 -22
  158. package/src/runtime/domain/subagents/catalog-store.ts +27 -20
  159. package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
  160. package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
  161. package/src/runtime/domain/subagents/child-dependencies.mjs +27 -15
  162. package/src/runtime/domain/subagents/child-operations.domain.mjs +80 -2
  163. package/src/runtime/domain/subagents/child-operations.ts +80 -1
  164. package/src/runtime/domain/subagents/child-preflight.mjs +9 -2
  165. package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
  166. package/src/runtime/domain/subagents/child-process-list.ts +8 -0
  167. package/src/runtime/domain/subagents/config.domain.mjs +49 -2
  168. package/src/runtime/domain/subagents/config.ts +46 -2
  169. package/src/runtime/domain/subagents/continuation-authority.domain.mjs +5 -1
  170. package/src/runtime/domain/subagents/continuation-authority.ts +3 -1
  171. package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
  172. package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
  173. package/src/runtime/domain/subagents/extensions.mjs +11 -13
  174. package/src/runtime/domain/subagents/finalization.domain.mjs +12 -0
  175. package/src/runtime/domain/subagents/finalization.ts +15 -0
  176. package/src/runtime/domain/subagents/goal-provider.domain.mjs +44 -2
  177. package/src/runtime/domain/subagents/goal-provider.ts +44 -2
  178. package/src/runtime/domain/subagents/health-observation.domain.mjs +189 -190
  179. package/src/runtime/domain/subagents/health-observation.ts +43 -48
  180. package/src/runtime/domain/subagents/index.domain.mjs +296 -123
  181. package/src/runtime/domain/subagents/index.ts +257 -98
  182. package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
  183. package/src/runtime/domain/subagents/launch-context.ts +23 -0
  184. package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
  185. package/src/runtime/domain/subagents/log-cursor.domain.mjs +85 -16
  186. package/src/runtime/domain/subagents/log-cursor.ts +91 -15
  187. package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +2 -2
  188. package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +6 -3
  189. package/src/runtime/domain/subagents/managed-launch-client.ts +6 -3
  190. package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +222 -14
  191. package/src/runtime/domain/subagents/managed-launch-host.ts +168 -15
  192. package/src/runtime/domain/subagents/managed-launch-journal.mjs +1 -5
  193. package/src/runtime/domain/subagents/managed-launch-port.ts +4 -0
  194. package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +27 -2
  195. package/src/runtime/domain/subagents/operation-bridge-types.ts +27 -2
  196. package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
  197. package/src/runtime/domain/subagents/owned-exit.ts +12 -0
  198. package/src/runtime/domain/subagents/package.json +1 -1
  199. package/src/runtime/domain/subagents/parse.domain.mjs +50 -5
  200. package/src/runtime/domain/subagents/parse.ts +48 -6
  201. package/src/runtime/domain/subagents/permission-policy.domain.mjs +32 -8
  202. package/src/runtime/domain/subagents/permission-policy.ts +41 -8
  203. package/src/runtime/domain/subagents/process-identity.mjs +33 -0
  204. package/src/runtime/domain/subagents/registry.domain.mjs +47 -33
  205. package/src/runtime/domain/subagents/registry.ts +54 -33
  206. package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +8 -1
  207. package/src/runtime/domain/subagents/shared-callback-batcher.ts +11 -2
  208. package/src/runtime/domain/subagents/shared-catalog.domain.mjs +6 -23
  209. package/src/runtime/domain/subagents/shared-catalog.ts +6 -14
  210. package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +24 -2
  211. package/src/runtime/domain/subagents/shared-navigator-panels.ts +26 -4
  212. package/src/runtime/domain/subagents/shared-navigator.domain.mjs +218 -13
  213. package/src/runtime/domain/subagents/shared-navigator.ts +197 -14
  214. package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
  215. package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +53 -41
  216. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
  217. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
  218. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
  219. package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
  220. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
  221. package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +14 -3
  222. package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
  223. package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +5 -3
  224. package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +44 -4
  225. package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +50 -2
  226. package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
  227. package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +12 -0
  228. package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +2 -0
  229. package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +2 -0
  230. package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +42 -21
  231. package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +40 -24
  232. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +21 -3
  233. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +34 -8
  234. package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
  235. package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +24 -1
  236. package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +1 -1
  237. package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +5 -1
  238. package/src/runtime/domain/subagents/shared-sandbox-core.ts +1 -1
  239. package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +14 -1
  240. package/src/runtime/domain/subagents/shared-task-exec.ts +12 -1
  241. package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
  242. package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
  243. package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +3 -2
  244. package/src/runtime/domain/subagents/shared-task-process-list.ts +8 -2
  245. package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +4 -3
  246. package/src/runtime/domain/subagents/shared-task-sandbox.ts +5 -3
  247. package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +8 -5
  248. package/src/runtime/domain/subagents/shared-task-tools.ts +8 -5
  249. package/src/runtime/domain/subagents/shared-work-client.mjs +174 -7
  250. package/src/runtime/domain/subagents/subagent-tools.domain.mjs +22 -38
  251. package/src/runtime/domain/subagents/subagent-tools.ts +28 -34
  252. package/src/runtime/domain/subagents/task-policy.domain.mjs +1 -1
  253. package/src/runtime/domain/subagents/task-policy.ts +3 -1
  254. package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
  255. package/src/runtime/domain/subagents/timing.ts +10 -1
  256. package/src/runtime/domain/subagents/work-observation.domain.mjs +77 -16
  257. package/src/runtime/domain/subagents/work-observation.ts +71 -16
  258. package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +9 -4
  259. package/src/runtime/domain/subagents/worker-operations-host.ts +12 -4
  260. package/src/runtime/domain/subagents/worker-waits.domain.mjs +89 -35
  261. package/src/runtime/domain/subagents/worker-waits.ts +93 -34
  262. package/src/runtime/health-config.ts +27 -11
  263. package/src/runtime/log-checkpoints.ts +117 -0
  264. package/src/runtime/mutation-store.ts +5 -4
  265. package/src/runtime/queries.ts +25 -2
  266. package/src/runtime/query-executor.ts +149 -28
  267. package/src/runtime/query-worker.mjs +106 -21
  268. package/src/runtime/read-model.ts +846 -120
  269. package/src/runtime/read-watchdog-probe.ts +4 -0
  270. package/src/runtime/result-supervision.ts +188 -16
  271. package/src/runtime/source-watch.ts +175 -0
  272. package/src/runtime/subagent-launch.ts +11 -4
  273. package/src/runtime/work-budget.ts +130 -0
  274. package/src/runtime/work-client.d.mts +8 -0
  275. package/src/runtime/work-client.mjs +150 -7
  276. package/src/server.ts +104 -23
  277. package/src/session-activity.ts +26 -4
  278. package/src/version.ts +1 -1
@@ -18,31 +18,68 @@
18
18
  * cursor skips ahead rather than falling permanently behind, and
19
19
  * `truncated` reports that bytes were never seen.
20
20
  */
21
- import { closeSync, openSync, readSync, statSync } from "node:fs";
21
+ import { closeSync, openSync, readSync, statSync, fstatSync } from "node:fs";
22
22
  /** Bytes of the log head kept to detect a rewrite behind our back. */
23
23
  const HEAD_SAMPLE_BYTES = 256;
24
+ export const logReadMetrics = { bytes: 0, reads: 0, parsedEvents: 0, displayFolded: 0, healthFolded: 0 };
25
+ let batch;
26
+ /** Share identical ranges and decoding only during a synchronous observation. */
27
+ export function withLogReadBatch(observe) {
28
+ const previous = batch;
29
+ batch = { reads: new Map(), events: new Map(), ranges: new Map() };
30
+ try {
31
+ return observe();
32
+ }
33
+ finally {
34
+ batch = previous;
35
+ }
36
+ }
37
+ export function parseLogEvent(line) {
38
+ if (batch?.events.has(line))
39
+ return batch.events.get(line);
40
+ const event = JSON.parse(line);
41
+ logReadMetrics.parsedEvents++;
42
+ batch?.events.set(line, event);
43
+ return event;
44
+ }
24
45
  /** Default ceiling on a single read: also the cold-start tail window. */
25
46
  export const DEFAULT_MAX_READ_BYTES = 32 * 1024 * 1024; // 32 MiB
26
47
  function errText(err) {
27
48
  return err instanceof Error ? err.message : String(err);
28
49
  }
29
- function readAt(fd, position, length) {
50
+ function readAt(fd, position, length, path) {
30
51
  const buf = Buffer.allocUnsafe(length);
52
+ const ranges = batch?.ranges.get(path) ?? [];
31
53
  let filled = 0;
32
54
  while (filled < length) {
33
- const n = readSync(fd, buf, filled, length - filled, position + filled);
55
+ const at = position + filled;
56
+ const cached = ranges.find(range => range.start <= at && range.start + range.data.length > at);
57
+ if (cached) {
58
+ const offset = at - cached.start;
59
+ const n = Math.min(length - filled, cached.data.length - offset);
60
+ cached.data.copy(buf, filled, offset, offset + n);
61
+ filled += n;
62
+ continue;
63
+ }
64
+ const next = Math.min(position + length, ...ranges.filter(range => range.start > at).map(range => range.start));
65
+ const n = readSync(fd, buf, filled, next - at, at);
34
66
  if (n <= 0)
35
67
  break;
68
+ if (batch) {
69
+ ranges.push({ start: at, data: buf.subarray(filled, filled + n) });
70
+ batch.ranges.set(path, ranges);
71
+ }
36
72
  filled += n;
73
+ logReadMetrics.bytes += n;
37
74
  }
38
75
  return filled === length ? buf : buf.subarray(0, filled);
39
76
  }
40
77
  /** Head sample as a byte-exact string, for rewrite detection. */
41
- function readHead(fd, size) {
78
+ function readHead(fd, size, path) {
42
79
  const length = Math.min(HEAD_SAMPLE_BYTES, size);
43
80
  if (length <= 0)
44
81
  return "";
45
- return readAt(fd, 0, length).toString("latin1");
82
+ return readAt(fd, 0, length, path).toString("latin1");
46
83
  }
47
84
  /**
48
85
  * Same log? Compare the prefix both samples cover, so a head that is still
@@ -62,7 +99,17 @@ function headsAgree(previous, current) {
62
99
  * Passing `previous: undefined` starts cold: the last `maxBytes` of the log,
63
100
  * with the leading partial line dropped.
64
101
  */
65
- export function readAppendedLines(path, previous, maxBytes = DEFAULT_MAX_READ_BYTES) {
102
+ export function readAppendedLines(path, previous, maxBytes = DEFAULT_MAX_READ_BYTES, cumulative = false) {
103
+ const key = JSON.stringify([path, previous, maxBytes, cumulative]);
104
+ const cached = batch?.reads.get(key);
105
+ if (cached)
106
+ return cached;
107
+ const result = readLines(path, previous, maxBytes, cumulative);
108
+ batch?.reads.set(key, result);
109
+ return result;
110
+ }
111
+ function readLines(path, previous, maxBytes, cumulative) {
112
+ logReadMetrics.reads++;
66
113
  const empty = (error) => ({
67
114
  lines: [],
68
115
  cursor: previous ?? { offset: 0, head: "" },
@@ -86,54 +133,76 @@ export function readAppendedLines(path, previous, maxBytes = DEFAULT_MAX_READ_BY
86
133
  return empty(errText(err));
87
134
  }
88
135
  try {
89
- const head = readHead(fd, size);
136
+ const info = fstatSync(fd);
137
+ size = info.size;
138
+ const generation = `${info.dev}:${info.ino}:${info.birthtimeMs}`;
139
+ const head = readHead(fd, size, path);
90
140
  // A log that shrank or whose head changed is a different log: the old
91
141
  // offset would point into unrelated bytes. Compare only the prefix the
92
142
  // two samples share, so a log still shorter than the sample window is
93
143
  // not "rewritten" every time it grows.
94
144
  const resumable = previous !== undefined
145
+ && (previous.generation === undefined || previous.generation === generation)
146
+ && !(previous.size === size && previous.modified !== undefined && previous.modified !== info.mtimeMs)
95
147
  && previous.offset <= size
96
148
  && headsAgree(previous.head, head);
97
149
  const restarted = previous !== undefined && !resumable;
150
+ let coverageStart = resumable ? previous.coverageStart ?? 0 : 0;
151
+ let missing = resumable ? previous.missing : undefined;
152
+ let skipLeading = resumable ? previous.skipLeading : false;
153
+ const cursor = (offset) => ({ offset, head, generation, size, modified: info.mtimeMs, coverageStart, missing, skipLeading });
98
154
  let start = resumable ? previous.offset : 0;
99
155
  let truncated = false;
100
- if (size - start > maxBytes) {
156
+ if (!cumulative && size - start > maxBytes) {
101
157
  // Skip ahead instead of lagging: a chatty log must not push the
102
158
  // cursor permanently into the past.
103
159
  start = size - maxBytes;
160
+ coverageStart = start;
161
+ missing = [missing?.[0] ?? (resumable ? previous.offset : 0), start];
104
162
  truncated = true;
105
163
  }
106
164
  // We begin mid-line whenever bytes were skipped.
107
- const startedMidLine = truncated;
165
+ const startedMidLine = truncated || skipLeading;
108
166
  if (size === start) {
109
- return { lines: [], cursor: { offset: start, head }, totalBytes: size, truncated, restarted };
167
+ return { lines: [], cursor: cursor(start), totalBytes: size, truncated, restarted };
110
168
  }
111
- const buf = readAt(fd, start, size - start);
169
+ const end = cumulative ? Math.min(size, start + maxBytes) : size;
170
+ const buf = readAt(fd, start, end - start, path);
112
171
  const lastNewline = buf.lastIndexOf(0x0a);
113
172
  if (lastNewline === -1) {
114
173
  // No complete line yet. Hold position so the line can finish —
115
174
  // unless it is an oversized partial we already skipped into, which
116
175
  // would otherwise be re-read forever.
117
- const offset = startedMidLine ? start + buf.length : start;
176
+ const oversized = cumulative && end < size;
177
+ if (oversized)
178
+ missing = [missing?.[0] ?? start, end];
179
+ if (oversized)
180
+ skipLeading = true;
181
+ const offset = startedMidLine || oversized ? start + buf.length : start;
118
182
  const partial = startedMidLine ? undefined : buf.toString("utf-8");
119
- return { lines: [], partial, cursor: { offset, head }, totalBytes: size, truncated, restarted };
183
+ return { lines: [], partial: oversized ? undefined : partial, cursor: cursor(offset), totalBytes: size, truncated: truncated || oversized, restarted, more: end < size };
120
184
  }
121
185
  const text = buf.subarray(0, lastNewline + 1).toString("utf-8");
122
186
  const lines = text.split("\n");
123
187
  lines.pop(); // trailing "" after the final newline
124
- if (startedMidLine)
188
+ if (startedMidLine) {
125
189
  lines.shift(); // partial first line
190
+ missing = [missing?.[0] ?? 0, start + buf.indexOf(0x0a) + 1];
191
+ coverageStart = Math.max(coverageStart, missing[1]);
192
+ skipLeading = false;
193
+ }
126
194
  // Anything after the final newline is unterminated: hand it over
127
195
  // separately rather than pretending it is a line.
128
196
  const trailing = buf.subarray(lastNewline + 1);
129
- const partial = trailing.length > 0 ? trailing.toString("utf-8") : undefined;
197
+ const partial = end === size && trailing.length > 0 ? trailing.toString("utf-8") : undefined;
130
198
  return {
131
199
  lines,
132
200
  partial,
133
- cursor: { offset: start + lastNewline + 1, head },
201
+ cursor: cursor(start + lastNewline + 1),
134
202
  totalBytes: size,
135
203
  truncated,
136
204
  restarted,
205
+ more: end < size,
137
206
  };
138
207
  }
139
208
  catch (err) {
@@ -1,2 +1,5 @@
1
- export function parseRun(id: string, options?: { logPath?: string }): { usage: any; toolCalls: string[] };
1
+ export function parseRun(id: string, options?: { logPath?: string; states?: Map<any, any>; summaryOnly?: boolean }): { usage: any; toolCalls: string[]; diagnostics: string[] };
2
+ export function encodeParseLogState(state: any): any;
3
+ export function decodeParseLogState(state: any): any;
4
+ export function parseRunDisplay(id: string, options: { logPath?: string; states: Map<any, any>; summaryOnly?: boolean }): { usage: any; tool: string; diagnostics: string[] };
2
5
  export function readRunTranscript(id: string, options?: { logPath?: string }): any;
@@ -22,7 +22,7 @@
22
22
  */
23
23
  import { closeSync, openSync, readSync, statSync, } from "node:fs";
24
24
  import { readBoundedTail, tailTerminalDisplay } from "./shared-log-utils.mjs";
25
- import { readAppendedLines } from "./log-cursor.mjs";
25
+ import { readAppendedLines, parseLogEvent, logReadMetrics } from "./log-cursor.mjs";
26
26
  import { logPathFor } from "./log-paths.mjs";
27
27
  const DEFAULT_PARSE_TAIL_BYTES = 32 * 1024 * 1024; // 32 MiB
28
28
  const DEFAULT_RAW_TAIL_BYTES = 256 * 1024; // 256 KiB
@@ -885,6 +885,15 @@ function peekType(line) {
885
885
  /** Runs tracked at once; a backstop against unbounded state, not a policy. */
886
886
  const MAX_TRACKED_PARSE_RUNS = 64;
887
887
  const parseStates = new Map();
888
+ export function encodeParseLogState(state) {
889
+ return { ...state, openToolCalls: [...state.openToolCalls] };
890
+ }
891
+ export function decodeParseLogState(saved) {
892
+ if (!saved?.usage || !Array.isArray(saved.openToolCalls) || !Array.isArray(saved.toolCalls)
893
+ || !Number.isSafeInteger(saved.cursor?.offset) || saved.cursor.offset < 0)
894
+ throw new Error("Invalid display checkpoint");
895
+ return { ...saved, openToolCalls: new Map(saved.openToolCalls) };
896
+ }
888
897
  /** Forget a run's accumulated parse (or all of them). */
889
898
  export function resetParseRunCursor(id) {
890
899
  if (id === undefined)
@@ -974,7 +983,7 @@ function selectParsableLines(lines) {
974
983
  }
975
984
  function tryParse(line) {
976
985
  try {
977
- return JSON.parse(line);
986
+ return parseLogEvent(line);
978
987
  }
979
988
  catch {
980
989
  return undefined;
@@ -995,6 +1004,7 @@ function activityTextOf(e) {
995
1004
  }
996
1005
  /** Fold one event into the run's accumulated state. */
997
1006
  function foldParseEvent(state, e) {
1007
+ logReadMetrics.displayFolded++;
998
1008
  const type = e.type;
999
1009
  state.sawAnyEvent = true;
1000
1010
  // Authoritative final answer: the last assistant message at run end.
@@ -1093,16 +1103,29 @@ function foldParseEvent(state, e) {
1093
1103
  */
1094
1104
  export function parseRun(id, options = {}) {
1095
1105
  const key = options.logPath ?? id;
1096
- const previous = parseStates.get(key);
1097
- const read = readAppendedLines(options.logPath ?? logPathFor(id), previous?.cursor, maxParseBytes());
1106
+ const states = options.states ?? parseStates;
1107
+ const previous = states.get(key);
1108
+ const path = options.logPath ?? logPathFor(id);
1109
+ let catchUp = false;
1110
+ if (options.summaryOnly) {
1111
+ try {
1112
+ catchUp = statSync(path).size > 1024 * 1024;
1113
+ }
1114
+ catch { /* read reports errors */ }
1115
+ }
1116
+ const read = readAppendedLines(path, previous?.cursor, catchUp ? Math.min(maxParseBytes(), 1024 * 1024) : maxParseBytes(), catchUp);
1098
1117
  const state = read.restarted || !previous ? freshState(read.cursor) : previous;
1099
1118
  state.cursor = read.cursor;
1119
+ state.catchingUp = read.more;
1100
1120
  if (read.totalBytes > 0)
1101
1121
  state.totalBytes = read.totalBytes;
1102
1122
  if (read.truncated)
1103
1123
  state.windowTruncated = true;
1104
1124
  state.error = read.error;
1105
- rememberParseState(key, state);
1125
+ if (options.states)
1126
+ states.set(key, state);
1127
+ else
1128
+ rememberParseState(key, state);
1106
1129
  if (read.error !== undefined) {
1107
1130
  return {
1108
1131
  finalText: "", lastActivity: "", toolCalls: [], unmatchedToolCalls: [], sawEnd: false,
@@ -1112,6 +1135,11 @@ export function parseRun(id, options = {}) {
1112
1135
  }
1113
1136
  for (const { event } of selectParsableLines(read.lines))
1114
1137
  foldParseEvent(state, event);
1138
+ if (options.summaryOnly) {
1139
+ state.finalText = "";
1140
+ state.lastActivity = "";
1141
+ state.toolCalls = state.toolCalls.slice(-256);
1142
+ }
1115
1143
  // A log whose final line was never terminated — a writer mid-event, or one
1116
1144
  // that simply did not end with a newline — still has to be readable. Fold it
1117
1145
  // into a COPY: the cursor has not consumed those bytes, so the same line
@@ -1123,6 +1151,10 @@ export function parseRun(id, options = {}) {
1123
1151
  foldParseEvent(view, event);
1124
1152
  }
1125
1153
  const diagnostics = [];
1154
+ if (state.catchingUp)
1155
+ diagnostics.push(`Usage catch-up pending after byte ${state.cursor.offset} of ${state.totalBytes}.`);
1156
+ if (options.summaryOnly && state.cursor.missing)
1157
+ diagnostics.push(`Incomplete usage: missing bytes [${state.cursor.missing[0]}, ${state.cursor.missing[1]}).`);
1126
1158
  if (view.windowTruncated) {
1127
1159
  diagnostics.push(`Log truncated: this session began reading at the last ${fmtBytes(maxParseBytes())} ` +
1128
1160
  `of ${fmtBytes(view.totalBytes)}. Events before that point are not counted in tokens/tools.`);
@@ -1149,6 +1181,19 @@ export function parseRun(id, options = {}) {
1149
1181
  diagnostics,
1150
1182
  };
1151
1183
  }
1184
+ /** Keep only the incremental facts needed by task-list displays. Detail reads use their own cursor. */
1185
+ export function parseRunDisplay(id, options) {
1186
+ const parsed = parseRun(id, options);
1187
+ const state = options.states.get(options.logPath ?? id);
1188
+ if (state) {
1189
+ state.finalText = "";
1190
+ state.lastActivity = "";
1191
+ state.toolCalls = state.toolCalls.slice(-1);
1192
+ state.openToolCalls.clear();
1193
+ state.modelError = undefined;
1194
+ }
1195
+ return { usage: parsed.usage, tool: parsed.toolCalls.at(-1) ?? "", diagnostics: parsed.diagnostics };
1196
+ }
1152
1197
  /** Build the human-readable body for subagent_output. Exported for unit testing. */
1153
1198
  export function formatSubagentOutputBody(head, tools, parsedBody, rawTail, diagnostics) {
1154
1199
  let body;
@@ -1,6 +1,6 @@
1
1
  # pi-better-sandbox
2
2
 
3
- Sandbox permissions for Pi's foreground tools, detached subagents, and local background tasks.
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
4
 
5
5
  ![Pi Better Sandbox package preview](https://raw.githubusercontent.com/1aboveio/pi-better-harness/main/docs/images/package-gallery/pi-better-sandbox.png)
6
6
 
@@ -18,7 +18,14 @@ enabled switches, keep their values. Open `/sandbox` to change any column, or us
18
18
  saved to the current session branch. **Ctrl+S** saves all three profiles as
19
19
  defaults for new sessions.
20
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
+
21
27
  ```text
28
+ Tool loading Use permissions Tab switch
22
29
  Sandbox permissions Main Subagents Background tasks
23
30
 
24
31
  Sandbox Off Off Off
@@ -32,62 +39,18 @@ Command time limit - - -
32
39
  Network access - - -
33
40
  Process access - - -
34
41
 
35
- Subagents · Tools
36
- Guarded (follows the file rules)
37
- [x] apply_patch harness adapter
38
- Trusted (runs outside the file rules)
39
- > [x] @juicesharp/rpiv-web-tools 2/2
40
- > [ ] <other installed package> 0/1
41
-
42
- ↑↓ Select · ←→ Column/fold · Space Toggle · ctrl+s Save default · Enter Fold · Esc Back
42
+ ↑↓ Select · ←→ Column · Space Toggle · ctrl+s Save default · Esc Back
43
43
  ```
44
44
 
45
- **Subagents · Tools** picks the extension tools a confined subagent may use:
46
-
47
- - **Guarded** tools go through the same guarded file operations as `write` and
48
- `edit`, so the rows above govern them. `apply_patch` applies Codex-style
49
- patches; deletes and moves follow the removal rules, and a patch is checked in
50
- full before any file changes.
51
- - **Trusted** tools are the other tools your Pi has loaded, listed with their
52
- package. A ticked one is loaded into the subagent and runs in its Pi process,
53
- **outside the file rules**. One Space toggles it immediately. It is admitted
54
- only from the package you ticked. Known network tool names are refused while
55
- Network access is Off: `web_fetch`, `web_search`, `firecrawl_scrape`, `firecrawl_extract`, `mcp`, `mcpScript`, `remote_bash`,
56
- `ssh_profile`, `ssh_mux`, and any `mcp__*` name. That is a name list, not a network sandbox.
57
-
58
- Trusted tools use two levels: a package/provider group, then its individual tools.
59
- Non-MCP tools are grouped by exact owning package; `mcp__<provider>__...` tools
60
- are grouped by provider and owning package together. Groups start collapsed.
61
- File-backed extensions explicitly marked `builtin` by Pi display as `built-in`,
62
- not their package path (which can be `.`). This is a display label only: saved
63
- choices and admission still use the original owning package. An unmarked `.`
64
- package is not built-in, and an unavailable saved tool keeps its package label
65
- until Pi reports its provenance again. Core tools with synthetic source paths
66
- remain excluded from trusted candidates.
67
- `>` means collapsed and `v` means expanded. Their checkbox shows `[x]` when
68
- all children are selected, `[-]` when some are selected, and `[ ]` when none
69
- are; the count is selected/total. Right expands a group. Left collapses a group,
70
- or moves from a child to its parent and collapses it. Enter folds the selected
71
- group. Space on a group selects all children when none or only some are selected,
72
- or deselects them all when all are selected. Every toggle applies on one Space;
73
- Ctrl+S saves defaults and reports anything loosened. Only individual tool
74
- entries are saved, never a package/provider wildcard or the open/closed state.
75
-
76
- Defaults: `apply_patch`, `web_fetch`, and `web_search` on; everything else off.
77
- The `pi-better-ssh` trusted group offers `ssh_profile`, `remote_bash`, and
78
- `ssh_mux`, all off by default. Expand it with Right and toggle individual tools
79
- with Space, or toggle the group to select all three. Keep Subagents Network
80
- access On. A ticked tool automatically loads its owning extension into new
81
- subagents; no separate extension mapping is needed. Default launches include
82
- ticked tools; an explicit spawn `tools` list must include the SSH tools needed,
83
- and `clean:true` does not load extensions. Ctrl+S saves these choices for new
84
- sessions. Running subagents keep their launch policy.
85
-
86
- Trusted SSH tools run outside local file, credential-file, and command rules;
87
- remote effects are not confined either. Only enable them when you trust the
88
- extension and the subagent's access to your SSH configuration and credentials.
89
- Other harness packages remain excluded from trusted candidates.
90
- See [ADR 0009](../../docs/adr/0009-guarded-and-trusted-subagent-tools.md).
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.
91
54
 
92
55
  Project files and Outside project cycle through four levels:
93
56
 
@@ -234,9 +197,29 @@ literal name filtering and a bounded result limit. It does not expose command
234
197
  arguments, environment variables, debugger attachment, signals, termination,
235
198
  or emulator/ADB operations. Explicit saved values are preserved, and legacy
236
199
  saved profiles without this setting stay Off until a human enables Read;
237
- subagents snapshot the setting at launch. Background tasks uses this row for
238
- explicit task-status process diagnostics, not `process_list`. Those diagnostics
239
- require current Read in both Main and Background tasks. They check a registered
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
240
223
  PID's start identity and can report state, CPU time and wait evidence without
241
224
  arguments or environment values. They are unavailable under Main confinement;
242
225
  no unconfined fallback runs. Task confinement remains the policy recorded when
@@ -253,7 +236,23 @@ hidden-root profiles without `/proc` fail rather than gaining a new host mount.
253
236
 
254
237
  On macOS, `/bin/ps` is setuid and can be refused at execution by Seatbelt even
255
238
  when process information reads are allowed. Enabling Process access provides
256
- `process_list`; it does not authorize raw `/bin/ps` or an unconfined workaround.
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.
257
256
 
258
257
  File and shell operations use the kernel: macOS uses Seatbelt (`sandbox-exec`)
259
258
  and Linux uses Bubblewrap (`bwrap`). `read`, `write`, and `edit` keep Pi's normal
@@ -281,8 +280,8 @@ are not writable. Credential-file and Pi control-path protections still win.
281
280
  Outside Off does not expose these host runtime directories.
282
281
 
283
282
  The currently admitted model-tool implementations are `read`, `write`, `edit`,
284
- `bash`, and guarded `run_application`, plus, for Subagents, the guarded `apply_patch` and the trusted tools
285
- ticked under Subagents · Tools. User-entered `!` and `!!` commands use the same
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
286
285
  shell policy. Other model-callable tools require a verified execution adapter
287
286
  and are refused while that actor's sandbox is enabled; enabling network alone
288
287
  does not admit them. Subagent launch output identifies requested tools that are
@@ -298,8 +297,7 @@ under broader file grants. Task access to `~/.pi` does not receive a blanket
298
297
  write allowance or lock-file exception.
299
298
 
300
299
  Local confinement cannot govern a remote host's filesystem. SSH tools are
301
- available to confined Subagents only when explicitly ticked as trusted under
302
- Subagents · Tools, with Network access On. They run outside local task rules.
300
+ available to confined Subagents when selected with a verified provider and Network access On. They run outside local task rules.
303
301
  Main SSH tools, and unadmitted MCP, scripting, background, and nested-agent
304
302
  tools, still lack admission adapters and fail closed under an enabled actor
305
303
  profile. SSH through confined `bash` receives local file, credential, and network
@@ -20,6 +20,7 @@ export const SANDBOX_COMMAND_DESCRIPTION = "Configure Main, Subagents, and Backg
20
20
  const USAGE = [
21
21
  "Usage:",
22
22
  " /sandbox",
23
+ " /sandbox status",
23
24
  " /sandbox on",
24
25
  " /sandbox off",
25
26
  " /sandbox default on",
@@ -53,7 +54,7 @@ const DEFAULT_OFF_MESSAGE = [
53
54
  ].join("\n");
54
55
  const RESET_TITLE = "Restore the packaged write-deny defaults?";
55
56
  /** Build the `/sandbox` handler. Exported so its behaviour is directly testable. */
56
- export function createSandboxCommandHandler({ controller, denyRules, onStateChange, setDefault, setSessionEnabled, openPermissions, }) {
57
+ export function createSandboxCommandHandler({ controller, denyRules, onStateChange, setDefault, setSessionEnabled, describeProcessAccess, openPermissions, }) {
57
58
  return async function handleSandboxCommand(args, ctx) {
58
59
  // Only the verbs are case-folded. Everything after them is a path, and
59
60
  // paths are case-sensitive on the filesystems this package supports.
@@ -65,12 +66,13 @@ export function createSandboxCommandHandler({ controller, denyRules, onStateChan
65
66
  await handleDiagnosticsCommand(rest, ctx);
66
67
  return;
67
68
  }
68
- if (subcommand === "") {
69
- if (openPermissions && ctx.mode === "tui") {
70
- await openPermissions(ctx);
71
- return;
72
- }
73
- ctx.ui.notify(formatSandboxReport(controller.status()), "info");
69
+ if (subcommand === "" && openPermissions && ctx.mode === "tui") {
70
+ await openPermissions(ctx);
71
+ return;
72
+ }
73
+ if (subcommand === "" || subcommand === "status") {
74
+ const status = controller.status();
75
+ ctx.ui.notify([formatSandboxReport(status), describeProcessAccess?.(status)].filter(Boolean).join("\n\n"), "info");
74
76
  return;
75
77
  }
76
78
  if (subcommand === "on") {
@@ -198,9 +200,10 @@ function announce(ctx, change) {
198
200
  throw error;
199
201
  }
200
202
  }
201
- const SUBCOMMANDS = ["on", "off", "default", "deny", "rules", "diagnostics"];
203
+ const SUBCOMMANDS = ["on", "off", "default", "deny", "rules", "diagnostics", "status"];
202
204
  const DENY_ACTIONS = ["list", "add", "remove", "reset"];
203
205
  const COMPLETION_DESCRIPTIONS = {
206
+ status: "Show effective Main sandbox and process-tool access",
204
207
  on: "Enable confinement for this session",
205
208
  off: "Disable confinement for this session",
206
209
  default: "Change the persistent activation default",
@@ -33,6 +33,7 @@ export const SANDBOX_COMMAND_DESCRIPTION =
33
33
  const USAGE = [
34
34
  "Usage:",
35
35
  " /sandbox",
36
+ " /sandbox status",
36
37
  " /sandbox on",
37
38
  " /sandbox off",
38
39
  " /sandbox default on",
@@ -84,6 +85,7 @@ export type SandboxCommandDeps = {
84
85
  setDefault: (enabled: boolean) => ForegroundSandboxStatus;
85
86
  /** Persist the session change before mutating enforcement. */
86
87
  setSessionEnabled?: (enabled: boolean) => ForegroundSandboxStatus;
88
+ describeProcessAccess?: (status: ForegroundSandboxStatus) => string;
87
89
  openPermissions?: (ctx: ExtensionCommandContext) => Promise<void>;
88
90
  };
89
91
 
@@ -94,6 +96,7 @@ export function createSandboxCommandHandler({
94
96
  onStateChange,
95
97
  setDefault,
96
98
  setSessionEnabled,
99
+ describeProcessAccess,
97
100
  openPermissions,
98
101
  }: SandboxCommandDeps) {
99
102
  return async function handleSandboxCommand(
@@ -112,12 +115,13 @@ export function createSandboxCommandHandler({
112
115
  return;
113
116
  }
114
117
 
115
- if (subcommand === "") {
116
- if (openPermissions && ctx.mode === "tui") {
117
- await openPermissions(ctx);
118
- return;
119
- }
120
- ctx.ui.notify(formatSandboxReport(controller.status()), "info");
118
+ if (subcommand === "" && openPermissions && ctx.mode === "tui") {
119
+ await openPermissions(ctx);
120
+ return;
121
+ }
122
+ if (subcommand === "" || subcommand === "status") {
123
+ const status = controller.status();
124
+ ctx.ui.notify([formatSandboxReport(status), describeProcessAccess?.(status)].filter(Boolean).join("\n\n"), "info");
121
125
  return;
122
126
  }
123
127
 
@@ -280,10 +284,11 @@ function announce(ctx: ExtensionCommandContext, change: () => DenyRuleReport): v
280
284
  }
281
285
  }
282
286
 
283
- const SUBCOMMANDS = ["on", "off", "default", "deny", "rules", "diagnostics"] as const;
287
+ const SUBCOMMANDS = ["on", "off", "default", "deny", "rules", "diagnostics", "status"] as const;
284
288
  const DENY_ACTIONS = ["list", "add", "remove", "reset"] as const;
285
289
 
286
290
  const COMPLETION_DESCRIPTIONS: Readonly<Record<string, string>> = {
291
+ status: "Show effective Main sandbox and process-tool access",
287
292
  on: "Enable confinement for this session",
288
293
  off: "Disable confinement for this session",
289
294
  default: "Change the persistent activation default",