@maxiaochao/pi-background-tasks 0.4.1 → 0.4.2
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/CHANGELOG.md +5 -0
- package/README.md +1 -1
- package/TESTING.md +2 -2
- package/docs/demo.gif +0 -0
- package/docs/screenshot.png +0 -0
- package/docs/shell-list.png +0 -0
- package/package.json +1 -1
- package/src/panel.ts +3 -2
- package/tests/fixtures/provider.ts +4 -4
- package/tests/media.mjs +3 -3
- package/tests/panel.mjs +33 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026-11-17 - v0.4.2
|
|
4
|
+
|
|
5
|
+
- Keep multiline shell previews compact without changing script execution
|
|
6
|
+
- Fold script line breaks and indentation into a compact, width-wrapped command preview, so setup lines do not hide the actual command. Keep the executed script unchanged.
|
|
7
|
+
|
|
3
8
|
## 2026-11-16 - v0.4.1
|
|
4
9
|
|
|
5
10
|
- Fix bottom-footer shell controls and hide the footer during task inspection
|
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ List shows running tasks and the latest 20 finished tasks, with total and omitte
|
|
|
73
73
|
A compact **`1 shell` / `N shells`** counter sits on the **bottom footer status row**, beside `editor: apply_patch` or other extension statuses. Without another status, it occupies that row alone. The existing native path, usage and model rows stay unchanged. Click the count in fullscreen mode, or press **Alt+J** in either terminal mode. One active task opens **Shell details** directly; multiple tasks open **Background**. With no active tasks, Alt+J still opens retained history.
|
|
74
74
|
|
|
75
75
|
- **List:** ↑/↓ selects a shell, Enter opens its details, and clicking a task row opens that task. Running tasks appear first, followed by **Earlier in this session**. At most eight task rows are visible; selection scrolls the retained history (latest 20 finished tasks).
|
|
76
|
-
- **Details:** `Status:`, `Runtime:` and `Command:` share a fixed value column.
|
|
76
|
+
- **Details:** `Status:`, `Runtime:` and `Command:` share a fixed value column. The command preview folds script line breaks and indentation into spaces, then wraps continuously to the panel width, up to three visual lines with an ellipsis. This is a display-only summary; the executed script is unchanged. **Output:** shows the last ten captured lines, clipped to the current width, refreshed every second. Empty output says `No output available`; truncated tails show the log path for further inspection. Finished tasks also show their exit code, reason and incomplete-capture warning when applicable.
|
|
77
77
|
- **Controls:** ← returns to the list. Esc closes either view; Enter or Space also closes details. `x` stops only the selected running shell. While either panel is open, the entire footer is hidden: path, usage, model, extension statuses and shell count. Closing restores the current footer and leaves the task running. Inspecting output in the panel does not add model messages or consume a pending completion reminder.
|
|
78
78
|
- **Counter:** recently finished tasks add `N done` for five seconds. Hiding the counter does not delete history. RPC receives an active count; print/JSON mode has no UI timer.
|
|
79
79
|
- **No `/bg` commands or Herdr integration:** the extension creates no tabs, panes or log-following processes, including when Pi itself runs inside Herdr. Task execution always uses the same local backend.
|
package/TESTING.md
CHANGED
|
@@ -14,7 +14,7 @@ Tests use Node's built-in test runner. They resolve host peers from the installe
|
|
|
14
14
|
- `output.mjs`: compares the shared 100-line/8-KiB preview with the real host Bash tool’s output, retaining unchanged small-output display parity and deliberately tighter truncation for large output. Covers line/byte limits, long lines, empty output, missing final newline, UTF-8 split across chunks, invalid UTF-8 and logs larger than 1 MiB. Checks both return paths carry the same tail, omission metadata reports total size, and full captured bytes remain on disk. The former Bash-sized display/1-MiB structured contract is retired; each retained fixture now verifies the bounded replacement.
|
|
15
15
|
- `processes.mjs`: the native backend, a multi-line Python log check, non-blocking concurrency, PID-observed process-tree cleanup, silent busy-loop timeout and the default 32 MiB disk limit.
|
|
16
16
|
- `extension.mjs`: real extension registration with fake execution/clock; schema errors, local panel inspection parity, parent-signal independence, merged busy/idle notifications, terminal-output consumption and failed-read retention, abort/error boundaries, manual-compaction-style busy intervals without agent boundaries, other extensions' draft preservation, status-only completion text with log paths and progressive-inspection guidance, no automatic stdout/stderr injection or log-file reads, a 16-KiB status/path batch cap, lossless splitting of large metadata batches, explicit timeout/empty-result status, independent missing-log and healthy-sibling manual inspections, synchronous delivery-failure retention, bottom-footer placement beside editor status, complete footer hiding/restoration around the panel, five-second retention, narrow/CJK rendering, coexistence and non-TUI modes. Checks explicit failure for an incompatible replacement footer and cleanup of the temporary zero-line capture widget. Checks fixed `model-only` exposure and separate concise declaration and task-specific start guidance, no start-text log path or redundant structured guidance field, and explicit running-task `list`/`output` availability; verifies 24-hour retention after an interrupt, output consumption while stopped, custom-wake isolation and restoration of automatic delivery by a new user-message run.
|
|
17
|
-
- `panel.mjs`: singular/plural counter, mouse hit region, screenshot-style field alignment, original multiline
|
|
17
|
+
- `panel.mjs`: singular/plural counter, mouse hit region, screenshot-style field alignment, compact continuous command previews, unchanged execution of original multiline scripts, CR/LF and indentation folding, preserved inline spaces, post-folding length limits, one-second refresh, empty/output-error states, bounded sanitized output, long commands, narrow/CJK widths, arrows/Enter/click selection, selected-ID stability across completion, `x` cancellation, closing without stopping, history paging and timer disposal. The old `viewer.mjs` was removed because all of its Herdr tab/pane/follow-script contracts are retired; local execution, process-tree cleanup and notification assertions remain in their existing suites. `extension.mjs` additionally checks no slash commands, one panel at a time, inspection not consuming reminders, and shutdown closing the panel.
|
|
18
18
|
- `media.mjs`: actual demo Python jobs stream in-place/line output and exit with 0/3 only after explicit release files; the offline provider issues exactly two direct starts, then returns without polling. This tests the fixtures used by the real recorder, not an invented screen.
|
|
19
19
|
- `notifications.mjs`: isolated real Pi with model-issued background calls, default one-at-a-time queues and an offline provider. Sequential blocking fixtures hold one native tool batch open across two waves of actual failing shell jobs. The blocking fixture runs directly or through native Codemode, but background calls always come from the model. The next model request gets one merged notification for four completions, excluding reminders for zero, one or two first-wave terminal outputs read directly by the model before the boundary; no output bodies are attached to any completion notice; no extra requests follow the final report. Complete pending-batch consumption remains covered by the deterministic extension tests. Also verifies that the model receives distinct declaration/start guidance without a Codemode suffix, and that the next request receives status/log locations without command output, and that native Codemode cannot discover or call `background_task`. The blocking tool is a fixture, not a real Herdr child. `BG_TEST_EXTENSION=/absolute/path/to/background-tasks.ts` can run the queue regressions against an older implementation.
|
|
20
20
|
- `compaction.mjs`: isolated native Pi SDK sessions call `session.compact()`, the same manual-compaction entry point used by `/compact` and RPC. Real shell jobs exit during a held offline summary request. Covers successful native compaction, a provider summary error and `abortCompaction()` cancellation; each must retain the pending completion while busy and automatically deliver status/log-location metadata once afterward, without another user prompt. Checks actual compaction lifecycle/events, saved compaction entries, completion timestamps/logs and exactly one automatic conversation request. Uses real timers and native `isIdle`/`isCompacting`, not injected busy state or replacement compaction results; no paid model call or TUI keyboard invocation of `/compact`. `BG_TEST_EXTENSION` also supports a negative-control extension.
|
|
@@ -61,7 +61,7 @@ node scripts/capture-package-media.mjs background-tasks
|
|
|
61
61
|
|
|
62
62
|
Requires Python 3, Chrome, the web-browser skill launcher, Pillow and an installed `@xterm/xterm` package. Set `XTERM_DIR` to its package directory if it is not under `~/.pi/agent/npm/node_modules/@xterm/xterm`. No Herdr or graphical desktop is required.
|
|
63
63
|
|
|
64
|
-
The recorder starts a real Pi PTY with the production extension and offline provider. By default it also loads the production Codex Edit extension; that offline model correctly selects `editor: edit`. Deterministic tests additionally cover `editor: apply_patch`. `BG_MEDIA_EDITOR=none` verifies the same flow without an editor extension. Chrome renders the actual ANSI stream through xterm.js in a recorder-owned temporary browser profile, without touching an existing skill browser. CDP sends real mouse press/release events to the shell counter and task rows, and keyboard events for selection, return, close, stop and Alt+J. It asserts that the count is on the last nonempty row beside editor status when present, with no duplicate above the footer. Both list and details hide path, usage, model and status rows; closing restores them. It also verifies aligned fields, live output, completion, cancellation, retained history and session-log cleanup. The Python bridge only transports PTY bytes; it does not draw replacement UI. Its local HTTP/WebSocket server uses a random path token and same-origin upgrade checks and is closed after the run.
|
|
64
|
+
The recorder starts a real Pi PTY with the production extension and offline provider. By default it also loads the production Codex Edit extension; that offline model correctly selects `editor: edit`. Deterministic tests additionally cover `editor: apply_patch`. `BG_MEDIA_EDITOR=none` verifies the same flow without an editor extension. Chrome renders the actual ANSI stream through xterm.js in a recorder-owned temporary browser profile, without touching an existing skill browser. CDP sends real mouse press/release events to the shell counter and task rows, and keyboard events for selection, return, close, stop and Alt+J. It asserts that the count is on the last nonempty row beside editor status when present, with no duplicate above the footer. Both list and details hide path, usage, model and status rows; closing restores them. A real four-line script with two exports must preview continuously, with the actual job command visible on the same row. It also verifies aligned fields, live output, completion, cancellation, retained history and session-log cleanup. The Python bridge only transports PTY bytes; it does not draw replacement UI. Its local HTTP/WebSocket server uses a random path token and same-origin upgrade checks and is closed after the run.
|
|
65
65
|
|
|
66
66
|
The unified media entry first runs `tests/tui-smoke.py`, then the browser/TUI recorder. `result.json`, tool events and raw screen text/screenshots are saved under `.cache/package-media/background-terminal`. The renderer builds `docs/screenshot.png`, `docs/shell-list.png` and `docs/demo.gif` from real captured states. The old Herdr pane screenshot and WebM are retired.
|
|
67
67
|
|
package/docs/demo.gif
CHANGED
|
Binary file
|
package/docs/screenshot.png
CHANGED
|
Binary file
|
package/docs/shell-list.png
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/panel.ts
CHANGED
|
@@ -143,9 +143,10 @@ export class BackgroundPanel {
|
|
|
143
143
|
private details(width: number, task: TaskSnapshot): string[] {
|
|
144
144
|
const { theme } = this;
|
|
145
145
|
const field = (name: string, value: string) => `${theme.bold(name.padEnd(10))}${value}`;
|
|
146
|
-
const
|
|
146
|
+
const preview = clean(this.tasks.command(task.id)).split("\n").map((line) => line.trim()).filter(Boolean).join(" ");
|
|
147
|
+
const commandLines = wrapTextWithAnsi(preview.slice(0, 8192), Math.max(1, width - 10));
|
|
147
148
|
const command = commandLines.slice(0, 3);
|
|
148
|
-
if (commandLines.length > 3 ||
|
|
149
|
+
if (commandLines.length > 3 || preview.length > 8192) command[command.length - 1] = truncateToWidth(command.at(-1)! + "…", Math.max(1, width - 10), "…");
|
|
149
150
|
const lines = [theme.fg("accent", theme.bold("Shell details")), "",
|
|
150
151
|
field("Status:", theme.fg(color(task), this.stopping.has(task.id) ? "stopping" : task.status)),
|
|
151
152
|
field("Runtime:", duration(task.elapsed_seconds)),
|
|
@@ -28,12 +28,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
28
28
|
const call = (args: any) => calls.push({ name: "background_task", arguments: args });
|
|
29
29
|
if (last?.role !== "toolResult") {
|
|
30
30
|
if (text.includes("Start two background demo jobs")) {
|
|
31
|
-
call({ action: "start", command: "
|
|
32
|
-
call({ action: "start", command: "
|
|
31
|
+
call({ action: "start", command: "set -e\nexport BG_DEMO=1\nexport CI=1\npython3 demo-job.py build", description: "Build progress", timeout: 120 });
|
|
32
|
+
call({ action: "start", command: "set -e\nexport BG_DEMO=1\nexport CI=1\npython3 demo-job.py tests", description: "Test suite", timeout: 120 });
|
|
33
33
|
} else if (text.includes("Start one background demo job")) {
|
|
34
|
-
call({ action: "start", command: "
|
|
34
|
+
call({ action: "start", command: "set -e\nexport BG_DEMO=1\nexport CI=1\npython3 demo-job.py build", description: "Build progress", timeout: 120 });
|
|
35
35
|
} else if (text.includes("Start the second background demo job")) {
|
|
36
|
-
call({ action: "start", command: "
|
|
36
|
+
call({ action: "start", command: "set -e\nexport BG_DEMO=1\nexport CI=1\npython3 demo-job.py tests", description: "Test suite", timeout: 120 });
|
|
37
37
|
} else if (text.includes("SMOKE_START")) {
|
|
38
38
|
call({ action: "start", command: "sleep 9; printf 'BUILD SUCCESSFUL\\n'", description: "Release build", timeout: 30 });
|
|
39
39
|
call({ action: "start", command: "sleep 300", description: "Cancel this task", timeout: 300 });
|
package/tests/media.mjs
CHANGED
|
@@ -44,8 +44,8 @@ test("offline media provider issues exactly two direct background starts, then r
|
|
|
44
44
|
for await (const event of provider.streamSimple(model, { messages: [user] })) events.push(event);
|
|
45
45
|
const calls = events.filter((event) => event.type === "toolcall_end").map((event) => event.toolCall);
|
|
46
46
|
assert.deepEqual(calls.map((call) => [call.name, call.arguments.command, call.arguments.description]), [
|
|
47
|
-
["background_task", "
|
|
48
|
-
["background_task", "
|
|
47
|
+
["background_task", "set -e\nexport BG_DEMO=1\nexport CI=1\npython3 demo-job.py build", "Build progress"],
|
|
48
|
+
["background_task", "set -e\nexport BG_DEMO=1\nexport CI=1\npython3 demo-job.py tests", "Test suite"],
|
|
49
49
|
]);
|
|
50
50
|
const next = [];
|
|
51
51
|
for await (const event of provider.streamSimple(model, { messages: [user, { role: "toolResult", toolCallId: calls[1].id, toolName: "background_task", content: [{ type: "text", text: "Started" }] }] })) next.push(event);
|
|
@@ -65,6 +65,6 @@ for (const [prompt, kind] of [
|
|
|
65
65
|
const calls = events.filter((event) => event.type === "toolcall_end").map((event) => event.toolCall);
|
|
66
66
|
assert.equal(calls.length, 1);
|
|
67
67
|
assert.equal(calls[0].name, "background_task");
|
|
68
|
-
assert.equal(calls[0].arguments.command, `
|
|
68
|
+
assert.equal(calls[0].arguments.command, `set -e\nexport BG_DEMO=1\nexport CI=1\npython3 demo-job.py ${kind}`);
|
|
69
69
|
});
|
|
70
70
|
}
|
package/tests/panel.mjs
CHANGED
|
@@ -57,7 +57,7 @@ test("compact count, singular/plural, five-second retention and bounded mouse hi
|
|
|
57
57
|
} finally { await f.close(); }
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
test("single shell opens aligned details
|
|
60
|
+
test("single shell opens aligned, compact details without changing the original script", async () => {
|
|
61
61
|
const f = fixture(); let p;
|
|
62
62
|
try {
|
|
63
63
|
const command = 'printf "hello"\nprintf "中文"';
|
|
@@ -65,7 +65,8 @@ test("single shell opens aligned details; full original multiline command is sep
|
|
|
65
65
|
assert.equal(f.tasks.command(task.id), command);
|
|
66
66
|
assert.equal(task.command, undefined);
|
|
67
67
|
p = panel(f);
|
|
68
|
-
assert.match(p.text(), /Shell details\n\n Status: running\n Runtime: 0s\n Command: printf "hello"
|
|
68
|
+
assert.match(p.text(), /Shell details\n\n Status: running\n Runtime: 0s\n Command: printf "hello" printf "中文"\n\n Output:\n No output available/);
|
|
69
|
+
assert.equal(f.calls[0].command, command);
|
|
69
70
|
f.clock.advance(209000);
|
|
70
71
|
assert.match(p.text(), /Runtime: 3m 29s/);
|
|
71
72
|
assert.ok(p.renders > 0);
|
|
@@ -80,6 +81,36 @@ test("single shell opens aligned details; full original multiline command is sep
|
|
|
80
81
|
} finally { p?.view.dispose(); await f.close(); }
|
|
81
82
|
});
|
|
82
83
|
|
|
84
|
+
test("command preview folds line breaks and indentation before width wrapping", async () => {
|
|
85
|
+
const f = fixture(); let p;
|
|
86
|
+
try {
|
|
87
|
+
const command = '\nset -e\r\n export JAVA_HOME=/opt/jdk-11.0.32\r\t export PATH="$JAVA_HOME/bin:$PATH"\n\n ./gradlew test\n';
|
|
88
|
+
const task = f.tasks.start({ command }, f.root);
|
|
89
|
+
p = panel(f);
|
|
90
|
+
assert.match(p.text(), /Command: set -e export JAVA_HOME=\/opt\/jdk-11\.0\.32 export PATH="\$JAVA_HOME\/bin:\$PATH" \.\/gradlew test\n\n Output:/);
|
|
91
|
+
assert.doesNotMatch(p.text(), /…/);
|
|
92
|
+
const narrow = p.text(64);
|
|
93
|
+
assert.match(narrow, /\.\/gradlew test/);
|
|
94
|
+
assert.doesNotMatch(narrow, /…/);
|
|
95
|
+
assert.ok(p.view.render(64).every((line) => visibleWidth(line) <= 64));
|
|
96
|
+
assert.equal(f.tasks.command(task.id), command);
|
|
97
|
+
assert.equal(f.calls[0].command, command);
|
|
98
|
+
} finally { p?.view.dispose(); await f.close(); }
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("compact preview preserves inline spaces and applies its length guard after folding", async () => {
|
|
102
|
+
const f = fixture(); let p;
|
|
103
|
+
try {
|
|
104
|
+
const command = 'printf "hello 中文"\n' + " \n\t".repeat(3000) + 'printf "done"';
|
|
105
|
+
const task = f.tasks.start({ command }, f.root);
|
|
106
|
+
p = panel(f);
|
|
107
|
+
assert.match(p.text(), /Command: printf "hello 中文" printf "done"\n\n Output:/);
|
|
108
|
+
assert.doesNotMatch(p.text(), /…/);
|
|
109
|
+
assert.equal(f.tasks.command(task.id), command);
|
|
110
|
+
assert.equal(f.calls[0].command, command);
|
|
111
|
+
} finally { p?.view.dispose(); await f.close(); }
|
|
112
|
+
});
|
|
113
|
+
|
|
83
114
|
test("multiple shells: arrow selection, click, identity across completion, x stops only selected job", async () => {
|
|
84
115
|
const f = fixture(); let p;
|
|
85
116
|
try {
|