@stablekernel/pi-background-run 0.3.0 → 0.5.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.
- package/README.md +108 -23
- package/extension/index.test.ts +1320 -50
- package/extension/index.ts +842 -230
- package/package.json +1 -1
- package/skill/run-bg/SKILL.md +32 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stablekernel/pi-background-run",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Run long shell commands detached in the background for pi; get woken on completion. Output lands in a file; context stays clean.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/skill/run-bg/SKILL.md
CHANGED
|
@@ -30,8 +30,9 @@ no polling.
|
|
|
30
30
|
|---|---|
|
|
31
31
|
| Start | `bgrun(command: "make test-short", name: "unit-tests")` → `started: <job-id>` (name is an optional short label; use it so jobs are recognizable in `bgstatus`, the status widget, and wake messages) |
|
|
32
32
|
| Status | `bgstatus(<job-id>)` for one job, or `bgstatus()` for this session's running jobs — finished jobs are hidden by default; pass `includeDone: true` to list them |
|
|
33
|
-
| Tail | `bgtail(<job-id>, 40)` |
|
|
34
|
-
|
|
|
33
|
+
| Tail | `bgtail(<job-id>, 40)` — first read: last-40 tail; later reads: only lines appended since (delta tailing) |
|
|
34
|
+
| Grep | `bggrep(<job-id>, "pattern", context?)` — line-numbered matches, capped and condensed; default pattern = generic failure signatures (override when you know the format) |
|
|
35
|
+
| Clean | `bgclean()` for this session's old logs; `bgclean all` to sweep every session's (default 7-day retention) |
|
|
35
36
|
|
|
36
37
|
## Workflow
|
|
37
38
|
|
|
@@ -51,10 +52,11 @@ no polling.
|
|
|
51
52
|
|
|
52
53
|
### Reading results without flooding context
|
|
53
54
|
|
|
54
|
-
- **Quick peek (≤40 lines):** call `bgtail` with the job id and `lines: 40` — strips the `__BGRUN_EXIT__` marker.
|
|
55
|
+
- **Quick peek (≤40 lines):** call `bgtail` with the job id and `lines: 40` — strips the `__BGRUN_EXIT__` marker. The first read returns the last-40 tail; repeat reads return only lines appended since your last read (delta tailing) — polling a running job is nearly free.
|
|
56
|
+
- **Failure extraction:** `bggrep(<job-id>, "pattern")` — line-numbered matches with optional context lines, capped and condensed. Works on global jobs dirs that `ctx_execute_file` cannot reach (it runs inside the extension). Pass your own pattern whenever you know the tool's output format; the default only catches common failure signatures.
|
|
55
57
|
- **Whole-log failure analysis:** `ctx_execute_file` on the log path:
|
|
56
58
|
|
|
57
|
-
```
|
|
59
|
+
```javascript
|
|
58
60
|
ctx_execute_file(
|
|
59
61
|
path: "~/.pi-bgrun/jobs/<JOB>.log",
|
|
60
62
|
language: "javascript",
|
|
@@ -67,8 +69,22 @@ no polling.
|
|
|
67
69
|
|
|
68
70
|
A 10 000-line `make test` log collapses to a ~30-line summary in context.
|
|
69
71
|
|
|
70
|
-
**
|
|
71
|
-
|
|
72
|
+
**Why `bggrep` instead of `bash grep` on the log?**
|
|
73
|
+
|
|
74
|
+
- `bash grep` output is uncapped — a retry-storm log can dump thousands of
|
|
75
|
+
matching lines (megabytes) straight into context, and staying safe depends
|
|
76
|
+
on remembering `| head` on every single call. `bggrep` is bounded by design
|
|
77
|
+
(~50 matches, ~2KB/line, ~8KB).
|
|
78
|
+
- It takes the job id — no log-path reconstruction, no shell-quoting of the
|
|
79
|
+
regex — and works on any jobs dir, including global logs that
|
|
80
|
+
project-sandboxed `ctx_execute_file` cannot reach.
|
|
81
|
+
- Output is self-describing: match count, line numbers, `…[N skipped]…` gap
|
|
82
|
+
markers, `— none` for no-match.
|
|
83
|
+
|
|
84
|
+
Plain `grep` via bash is fine only for a one-off search you know is tiny.
|
|
85
|
+
|
|
86
|
+
**Never `cat`, `Read`, `bash cat`, or `bash grep` a full bgrun log.** Always
|
|
87
|
+
`bgtail`, `bggrep`, or `ctx_execute_file`.
|
|
72
88
|
|
|
73
89
|
## After a pi restart or session switch
|
|
74
90
|
|
|
@@ -85,9 +101,15 @@ no polling.
|
|
|
85
101
|
|
|
86
102
|
- Call the tools; never hand-roll `nohup … &` inline.
|
|
87
103
|
- One job = one id. Multiple concurrent jobs are fine — each has its own log.
|
|
88
|
-
- Logs live in `~/.pi-bgrun/jobs` (override with `PI_BGRUN_DIR`).
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
- Logs live in `~/.pi-bgrun/jobs` (override with `PI_BGRUN_DIR`). A **relative**
|
|
105
|
+
`jobsDir` in the project config (e.g. `.pi-bgrun/jobs`) puts logs inside the
|
|
106
|
+
project — auto-ignored via `.git/info/exclude` — which keeps them reachable
|
|
107
|
+
for project-sandboxed analysis tools like `ctx_execute_file`.
|
|
108
|
+
- Cleanup: `bgclean` removes only THIS session's old logs; `bgclean all`
|
|
109
|
+
sweeps every session's. Auto-sweeps at session start/shutdown are
|
|
110
|
+
session-scoped plus a global orphan pass (default on — removes finished
|
|
111
|
+
week-old logs from crashed/abandoned sessions; disable with
|
|
112
|
+
`globalAutoClean: false` / `PI_BGRUN_GLOBAL_AUTO_CLEAN=0`). Retention is
|
|
113
|
+
`cleanupDays` (default 7, configurable).
|
|
92
114
|
- To stop a running job, use `bash` with `kill <pid>` (the pid is in the `bgstatus`
|
|
93
115
|
output). There is no `bgkill` tool.
|