@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.
- package/README.md +32 -30
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,62 +1,64 @@
|
|
|
1
1
|
# @tduyng/pi-shell
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
##
|
|
5
|
+
## What it costs
|
|
6
6
|
|
|
7
|
-
|
|
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
|
|
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
|
|
21
|
+
Reads new bytes since the last read, through a byte cursor.
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
+
## Waking only when asked
|
|
38
40
|
|
|
39
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
47
|
+
## Reading a log without drowning in it
|
|
46
48
|
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
55
|
+
## Footer
|
|
54
56
|
|
|
55
|
-
|
|
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
|
-
##
|
|
59
|
+
## Lifecycle
|
|
58
60
|
|
|
59
|
-
Each
|
|
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
|
-
|
|
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.
|
|
4
|
-
"description": "
|
|
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",
|