@tduyng/pi-shell 0.0.2 → 0.0.3

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 (2) hide show
  1. package/README.md +32 -30
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,62 +1,64 @@
1
1
  # @tduyng/pi-shell
2
2
 
3
- Background shell execution for pi. One `bg` tool covers the full lifecycle: start, read output, kill, and list tasks.
3
+ Park a long command in the background and get woken when it matters. One `bg` tool covers start, read, kill, and list.
4
4
 
5
- ## The bg tool
5
+ ## What it costs
6
6
 
7
- A single tool with an `action` field. Each `bg` task runs in the current working directory with a fresh shell, like pi's own bash. There is no persistent shell session.
7
+ `bg` is 197 tokens a request for the whole lifecycle, where four tools would have cost four schemas.
8
+
9
+ The saving is in the wait, not the schema. A test suite, a build, or a dev server run for minutes and then return a log nobody reads whole. This tool holds the bytes and hands the model the tail it asked for, so a five minute build does not become a five minute stall in the transcript.
10
+
11
+ ## The tool
12
+
13
+ One tool with an `action` field. Each task runs in the current working directory with a fresh shell, like pi's own bash. There is no persistent shell session.
8
14
 
9
15
  ### start
10
16
 
11
- Spawns a detached command. Returns `task_id` (8-char UUID prefix), `pid`, and the absolute `log` path. stdout and stderr stream to a log file at `<agentDir>/shell-logs/<taskId>.log`. The task runs silently until you ask about it. Optional `timeout` caps the task (max 600 seconds). Default is no timeout.
17
+ Spawns a detached command and returns `task_id` (an 8-character UUID prefix), `pid`, and the absolute log `path`. stdout and stderr stream to `<agentDir>/shell-logs/<taskId>.log`. The task runs silently until you ask about it. An optional `timeout` caps it at 600 seconds, with no timeout by default.
12
18
 
13
19
  ### output
14
20
 
15
- Reads new bytes since the last read using a byte cursor. The `wait` parameter controls behavior:
21
+ Reads new bytes since the last read, through a byte cursor.
16
22
 
17
- - `"now"`: returns immediately with whatever is available.
18
- - `"next_write"`: parks the agent until the first new byte appears, then wakes it with the new output.
19
- - `"exit"`: parks the agent until the process ends, then delivers the verdict plus the unread tail.
23
+ | `wait` | Behaviour |
24
+ | --- | --- |
25
+ | `now` | Return whatever is available |
26
+ | `next_write` | Park the agent until the first new byte, then wake it |
27
+ | `exit` | Park the agent until the process ends, then deliver the verdict and the unread tail |
20
28
 
21
- The cursor never advances on wake reads, so a later `bg` output call still sees every byte from the stored offset onward.
29
+ A wake read does not advance the cursor, so a later `output` still sees every byte from the stored offset.
22
30
 
23
31
  ### kill
24
32
 
25
- Sends SIGTERM to the process group, polls every 50ms for up to 1 second, then escalates to SIGKILL. Accepts `task_id`, raw `pid`, or `port` (resolved to a pid via `lsof -ti`).
33
+ SIGTERM to the process group, polled every 50ms for up to a second, then SIGKILL. Takes a `task_id`, a raw `pid`, or a `port` resolved through `lsof -ti`.
26
34
 
27
35
  ### status
28
36
 
29
- Lists all tasks with id, pid, state (running, exited, killed), cursor offset, and the first 80 characters of the command.
30
-
31
- ## Honest exits
32
-
33
- Pi 0.99 already reports a signal-killed command as a failure. Its bash backend returns `128 + signal` for a child that died without an exit code, and raises when a command ends with neither an exit code nor a signal. This extension does not override that backend.
34
-
35
- `shell-process.test.ts` runs `kill -9` against pi's own bash tool and asserts a nonzero result in the 128+n family, so a pi release that reintroduces the silent success fails here.
37
+ Every task with id, pid, state (running, exited, killed), cursor offset, and the first 80 characters of the command.
36
38
 
37
- A `tool_result` handler annotates the two cases where the exit code alone cannot tell the model what happened. An exit 1 from `grep`, `rg`, or `find` means no matches, and a command killed by its timeout did not finish cleanly. Each note stops the model from retrying a search that already succeeded.
39
+ ## Waking only when asked
38
40
 
39
- ## Middle-out output view
41
+ Only a task the model parked on, through `wait: "exit"` or `wait: "next_write"`, injects a message when it finishes. A burst of exits coalesces into one message on a byte budget: 8 KB total by default, at least 1 KB per task. The wake carries the exit verdict, the unread tail, and the log path, so the model gets the result without a read-back.
40
42
 
41
- Large logs are truncated to a head and tail, defaulting to 8KB total, with an exact omitted-byte count in between. The read window per side is 16KB, split on UTF-8 sequence boundaries so characters are never cut mid-byte. The full log stays on disk at the path always shown in results.
43
+ The wake fires from the `onExit` callback through `queueMicrotask` rather than polling. A wake that lands mid-turn goes to the follow-up queue and is delivered at the next `agent_settled`.
42
44
 
43
- ## Wake on exit
45
+ A task parked on `wait: "exit"` also gets a silence check. Every 30 seconds it reads the log size, and after 10 minutes with no new bytes the agent is woken once with the elapsed time and the log path. It fires again only after output resumes and stops again. No model call runs for the check.
44
46
 
45
- Only a task the model parked on (via `wait: "exit"` or `wait: "next_write"`) injects a user message when it finishes. A burst of exits coalesces into one message sharing a byte budget: default 8KB total, minimum 1KB per task. The wake carries the exit verdict, the unread tail, and the full log path per task, so the model gets the result without a read-back.
47
+ ## Reading a log without drowning in it
46
48
 
47
- The wake fires from the `onExit` callback via `queueMicrotask`, not from polling. If the agent is mid-turn, the wake lands in the follow-up queue and is delivered at the next `agent_settled` boundary.
49
+ Large output is cut to a head and a tail, 8 KB total by default, with the exact omitted byte count between them. Each side reads up to 16 KB, split on UTF-8 sequence boundaries so a character is never cut mid-byte. The full log stays on disk at the path every result shows.
48
50
 
49
- ## Stall check
51
+ A `tool_result` handler annotates the two cases where an exit code cannot say what happened: exit 1 from `grep`, `rg`, or `find` means no matches, and a command killed by its timeout did not finish cleanly. Each note stops the model retrying a search that already succeeded.
50
52
 
51
- A task the model parked on with `wait: "exit"` also gets a silence check. Every 30 seconds it reads the log size. After 10 minutes with no new bytes, the agent is woken once with the elapsed time and the log path. The wake fires again only after output resumes and stops again. No model call runs for the check.
53
+ pi already reports a signal-killed command as a failure: its bash backend returns `128 + signal` and raises when a command ends with neither an exit code nor a signal. `shell-process.test.ts` runs `kill -9` against pi's own bash tool and asserts a nonzero result in that family, so a pi release that reintroduces the silent success fails here.
52
54
 
53
- ## Footer indicator
55
+ ## Footer
54
56
 
55
- The footer shows a dot and the live task count (e.g. "2 bg running") while any background task is active. It clears when the last task exits.
57
+ A dot and the live count while any task runs, for example `2 bg running`. It clears when the last one exits.
56
58
 
57
- ## Task lifecycle
59
+ ## Lifecycle
58
60
 
59
- Each `bg` task is in-memory only. It dies with the pi process. Persisted session entries record the command, log path, and start time so the model can read the log after a reload. The live process handle is gone. Detached grandchildren that inherit the shell's stdout keep writing to the log after the shell exits. The log stream stays open until both the stdout and stderr pipes close. Ending it on the first close would drop data the second pipe still delivers.
61
+ Each task is in-memory and dies with the pi process. The session records the command, log path, and start time, so the model can still read the log after a reload, even though the process handle is gone. Detached grandchildren that inherit the shell's stdout keep writing after the shell exits, and the log stream closes only when both pipes close, since ending it on the first close would drop data the second one still delivers.
60
62
 
61
63
  ## Install
62
64
 
@@ -68,4 +70,4 @@ Local checkout: `pi install /path/to/dotfiles/pi/agent/extensions/pi-shell`
68
70
 
69
71
  ## Configure
70
72
 
71
- - `SHELL`: set to `0`, `false`, `no`, or `off` to disable the extension entirely.
73
+ `SHELL`, set to `0`, `false`, `no`, or `off`, disables the extension.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tduyng/pi-shell",
3
- "version": "0.0.2",
4
- "description": "Background processes the agent parks on: one bg tool with start/output/kill/status, cursor reads that never re-read bytes, and a runtime wake-up when a task exits.",
3
+ "version": "0.0.3",
4
+ "description": "One bg tool for background processes, woken on exit, with cursor reads that never re-read bytes.",
5
5
  "keywords": [
6
6
  "pi",
7
7
  "pi-package",