@yusukeshib/pi-babysit 0.3.16 → 0.4.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 (3) hide show
  1. package/README.md +21 -15
  2. package/index.ts +614 -170
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -33,7 +33,7 @@ reachable from anywhere (`~/.pi-babysit/<pi-session-id>/`). Two kinds:
33
33
  | kind | started by | completion | on completion |
34
34
  | ---- | ---------- | ---------- | ------------- |
35
35
  | **process** | `babysit_run { command }` | process **exit** | automatic notification message (`triggerTurn`), batched for all exits observed in the same poll — the agent may end its turn after starting and is resumed on exit, same contract as the old `process` tool |
36
- | **subagent** | `babysit_run { profile: "subagent", task }` | `agent_settled` in the RPC event stream (process stays alive) | none — the agent polls `babysit_check` or blocks on `babysit_wait`; the idle session accepts follow-up tasks |
36
+ | **subagent** | `babysit_run { profile: "subagent", task }` | `agent_settled` in the RPC event stream (worker remains reusable during its idle grace) | none — the agent polls `babysit_check` or blocks on `babysit_wait`; the idle session accepts follow-up tasks until self-reap |
37
37
 
38
38
  The **profile is a tool parameter, not a separate tool set**: domain knowledge
39
39
  (RPC bookkeeping, per-task byte offsets, parked-turn detection, PTY-safe
@@ -56,9 +56,9 @@ programs** (installers, wizards, REPLs): type with `babysit_send`
56
56
 
57
57
  | Tool | What it does |
58
58
  | ---- | ------------ |
59
- | `babysit_run` | Run any command (`command`, optional `name`/`pty`/`timeout`/`idleTimeout`/`retryOnWorkerDeath`/`notificationGroup`). Set `foreground: true` when the next step needs the result in the same tool call, avoiding a separate `babysit_wait` turn. Or start a named subagent (`profile: "subagent"`, `task`, optional `name`/`agent`/`model`/`tools`/`maxDepth` and `maxCost`/`maxTurns`/`maxToolCalls`/`maxUsageTokens` budgets). `maxDepth` defaults to 1 and can only be set by the top-level caller. Quick commands return inline; longer ones continue in the background |
60
- | `babysit_check` | Without an id, list running sessions by default (`state: "all"` includes history; `state`/`kind` filters are available). With an id, inspect one session, tail bounded recent output, or search its raw log with `pattern`; `screen: true` captures TUIs and subagents otherwise show structured live progress |
61
- | `babysit_send` | Process: type `text` / press `keys` into the PTY. Subagent: steer mid-run, or send a follow-up task when idle (`mode: auto/steer/task`) |
59
+ | `babysit_run` | Run any command (`command`, optional `name`/`pty`/`timeout`/`idleTimeout`/`retryOnWorkerDeath`/`notificationGroup`). Set `foreground: true` when the next step needs the result in the same tool call; use `returnPattern`/`returnLines`/`maxBytes` to keep noisy output bounded without a second check turn. Or start a named subagent (`profile: "subagent"`, `task`, optional `name`/`agent`/`model`/`tools`/`maxDepth` and budget fields). `maxDepth` defaults to 1. Quick commands return inline; longer ones notify in the background |
60
+ | `babysit_check` | Without an id, list sessions with state/kind filters. With an id, inspect bounded output, search with `pattern`, or capture a TUI with `screen: true`; `maxBytes` overrides the 4 KB default up to 24 KB |
61
+ | `babysit_send` | Process: type `text` / press `keys` into the PTY. Subagent: steer mid-run, or send a follow-up task when confirmed settled (`mode: auto/steer/task`); explicit task mode rejects busy, parked, or unknown state |
62
62
  | `babysit_wait` | Block until done: process exit (or `expect: "regex"` readiness marker), subagent task completion. Multi-wait: up to 32 unique `ids` + `mode: "any"\|"all"` |
63
63
  | `babysit_kill` | Terminate a session, verify terminal state, then suppress the exit notification |
64
64
 
@@ -95,10 +95,12 @@ babysit_check { id: "cargo-test", lines: 50 }
95
95
  babysit_check { id: "cargo-test", pattern: "FAIL|ERROR", lines: 50 }
96
96
  ```
97
97
 
98
- Tail and search results are capped at 200 lines, and ordinary returned tool
99
- results (including lifecycle headers) are clipped to 8 KB. A single explicitly
100
- waited-for subagent answer may use up to 24 KB; multi-session wait results default
101
- to the 8 KB inline-output limit and can opt into a larger cap with `maxBytes`.
98
+ Tail and search results are capped at 200 lines and default to a 4 KB total
99
+ result cap; `babysit_check.maxBytes` can raise or lower that per call (up to
100
+ 24 KB). A single explicitly waited-for subagent answer may use up to 24 KB;
101
+ multi-session wait results default to the 8 KB inline-output limit and can opt
102
+ into a larger cap with `maxBytes`. Foreground runs can apply `returnPattern` or
103
+ `returnLines` before output enters context, avoiding a follow-up check turn.
102
104
  Pattern search returns the latest matching lines with line numbers. Prefer a
103
105
  targeted pattern over a broad tail, and do not read a potentially large log file
104
106
  in full. Subagent crashes return structured errors plus the full log path, never
@@ -157,10 +159,14 @@ grace window (`PI_BABYSIT_REAP_AFTER`, default 120s) using the same parked-turn
157
159
  rule, so a subagent waiting on a long build is never false-killed. Give bounded
158
160
  recon/review tasks at least one cost, turn, tool-call, or token budget; omit
159
161
  budgets only for intentionally open-ended work. Optional task budgets are
160
- checked by the parent poller. On the first exceeded limit the worker
161
- is steered to stop using tools and return its best answer; if it remains active
162
- after `PI_BABYSIT_BUDGET_GRACE`, termination is verified before the task is
163
- marked budget-killed. Usage shown by check/wait is cumulative for the task.
162
+ observed by the parent poller. At 80% of a limit the worker is steered to wrap
163
+ up; reaching the configured limit starts the hard grace immediately, even if a
164
+ wedged worker cannot accept steering. An in-flight model call or parallel tool
165
+ batch can still overshoot before the next poll. If the worker remains active
166
+ after `PI_BABYSIT_BUDGET_GRACE`, termination is verified before it is marked
167
+ budget-killed. Usage shown by check/wait is cumulative, and the first terminal
168
+ wait for each task charges that nested usage exactly once to the parent Pi
169
+ session totals.
164
170
 
165
171
  ## Environment overrides
166
172
 
@@ -172,10 +178,10 @@ marked budget-killed. Usage shown by check/wait is cumulative for the task.
172
178
  | `PI_BABYSIT_VIEW_CMD` | bundled `format-stream.mjs` | live-attach pretty printer for subagent JSONL (`""` disables) |
173
179
  | `PI_BABYSIT_QUICK_GRACE` | `2s` | interactive process grace before a still-running command is returned as background work; use `foreground: true` to wait explicitly |
174
180
  | `PI_BABYSIT_REAP_AFTER` | `120s` | idle grace before a finished subagent self-exits (`off`/`none`/`0` disables) |
175
- | `PI_BABYSIT_BUDGET_GRACE` | `30s` | grace after a subagent budget is exceeded before verified termination |
181
+ | `PI_BABYSIT_BUDGET_GRACE` | `90s` | grace after a subagent budget is exceeded before verified termination |
176
182
  | `PI_BABYSIT_RPC_LOG_MODE` | `compact` | `compact` removes duplicate RPC lifecycle payloads; `standard` opts into legacy payloads |
177
- | `PI_BABYSIT_RETENTION_DAYS` | unset | when set to a positive number, remove safe terminal roots older than this at session startup |
178
- | `PI_BABYSIT_TAIL_MAX_BYTES` | `8000` | cap for explicit log tails/screens returned by `babysit_check` |
183
+ | `PI_BABYSIT_RETENTION_DAYS` | `3` | at most once per day, remove safe terminal roots older than this; set `0` to disable automatic retention |
184
+ | `PI_BABYSIT_TAIL_MAX_BYTES` | `4000` | default cap for explicit log tails/screens returned by `babysit_check`; override per call with `maxBytes` |
179
185
  | `PI_BABYSIT_INLINE_OUTPUT_MAX_BYTES` | `8000` | cap for complete process output and aggregate multi-wait results |
180
186
  | `PI_BABYSIT_NOTIFY_OUTPUT_MAX_BYTES` | `2000` | per-process output cap for unsolicited completion notifications (`0` omits all output) |
181
187
  | `PI_BABYSIT_NOTIFY_COMMAND_MAX_BYTES` | `240` | cap for each command preview in completion notifications |