pi-background-tasks 0.7.7 → 1.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 (72) hide show
  1. package/BACKGROUND-TASKS-INSTRUCTIONS.md +63 -0
  2. package/PUBLISHING.md +43 -29
  3. package/README.md +234 -385
  4. package/TESTING.md +15 -9
  5. package/TEST_PLAN.md +46 -13
  6. package/docs/INDEX.md +157 -0
  7. package/docs/api/eventbus-v1.md +166 -0
  8. package/docs/assets/architecture.svg +78 -0
  9. package/docs/assets/footer-dock.svg +47 -0
  10. package/docs/assets/logo.svg +49 -0
  11. package/docs/attestations.json +189 -0
  12. package/docs/choose-a-workflow.md +98 -0
  13. package/docs/commands/bg-clear.md +70 -0
  14. package/docs/commands/bg-update.md +82 -0
  15. package/docs/commands/bg.md +90 -0
  16. package/docs/commands/fusion-models.md +70 -0
  17. package/docs/commands/fusion.md +69 -0
  18. package/docs/commands/jobs.md +74 -0
  19. package/docs/commands/kill.md +82 -0
  20. package/docs/commands/logs.md +90 -0
  21. package/docs/commands/task-manager.md +109 -0
  22. package/docs/concepts/completion-delivery.md +66 -0
  23. package/docs/concepts/context-projection-and-budgeting.md +79 -0
  24. package/docs/getting-started.md +122 -0
  25. package/docs/manifest.json +1825 -0
  26. package/docs/operations/configuration.md +110 -0
  27. package/docs/operations/releasing.md +67 -0
  28. package/docs/operations/testing.md +101 -0
  29. package/docs/operations/troubleshooting.md +38 -0
  30. package/docs/read-before-edit.md +94 -0
  31. package/docs/reference/runtime-contracts.md +213 -0
  32. package/docs/reference/shortcuts-and-dock.md +70 -0
  33. package/docs/subsystems/attested-pi-runs.md +141 -0
  34. package/docs/subsystems/background-task-runtime.md +85 -0
  35. package/docs/subsystems/child-launch-durability-and-safety.md +57 -0
  36. package/docs/subsystems/delegation.md +190 -0
  37. package/docs/subsystems/docs-freshness-gate.md +26 -0
  38. package/docs/subsystems/fusion.md +121 -0
  39. package/docs/subsystems/host-ui-and-telemetry.md +83 -0
  40. package/docs/tools/bg_delegate.md +193 -0
  41. package/docs/tools/bg_kill.md +114 -0
  42. package/docs/tools/bg_logs.md +133 -0
  43. package/docs/tools/bg_result.md +120 -0
  44. package/docs/tools/bg_run.md +168 -0
  45. package/docs/tools/bg_run_pi_attested.md +170 -0
  46. package/docs/tools/bg_status.md +111 -0
  47. package/docs/tools/fusion_investigate.md +116 -0
  48. package/docs/tools/fusion_reason.md +75 -0
  49. package/docs/tools/fusion_research.md +162 -0
  50. package/docs/tools/fusion_validate.md +206 -0
  51. package/logo.png +0 -0
  52. package/package.json +29 -6
  53. package/src/core/delegate/budget.ts +1 -1
  54. package/src/core/delegate/launch.ts +6 -0
  55. package/src/core/fusion/artifacts.ts +80 -5
  56. package/src/core/fusion/budget.ts +129 -28
  57. package/src/core/fusion/child-protocol.ts +82 -0
  58. package/src/core/fusion/clean-context.ts +91 -0
  59. package/src/core/fusion/config.ts +124 -35
  60. package/src/core/fusion/context.ts +33 -6
  61. package/src/core/fusion/evaluation.ts +392 -15
  62. package/src/core/fusion/orchestrator.ts +274 -25
  63. package/src/core/fusion/pi-child.ts +635 -10
  64. package/src/core/fusion/prompts.ts +167 -6
  65. package/src/core/fusion/source-policy.ts +257 -0
  66. package/src/core/fusion/types.ts +232 -5
  67. package/src/core/fusion/web-fetch.ts +993 -0
  68. package/src/core/fusion/workflows.ts +184 -0
  69. package/src/extension.ts +3 -3
  70. package/src/fusion-child-extension.ts +370 -54
  71. package/src/fusion-extension.ts +625 -125
  72. package/src/testing/normalize.ts +0 -22
@@ -0,0 +1,90 @@
1
+ ---
2
+ doc_id: commands/bg
3
+ audience: user
4
+ mode: mixed
5
+ review_policy: contract
6
+ stability: stable
7
+ covers_surfaces: [command:bg]
8
+ covers_sources: []
9
+ ---
10
+ # `/bg`
11
+
12
+ <!-- pi-docs:begin name="command-contract-bg" generator="scripts/docs/generate.mjs" -->
13
+ | Command | Description | Provenance |
14
+ | --- | --- | --- |
15
+ | `/bg` | Start a shell command as a tracked background task: /bg [--agent] [--name "Task name"] <command> | `src/extension.ts:506` |
16
+ <!-- pi-docs:end name="command-contract-bg" -->
17
+
18
+ Start a shell command as a tracked background task from the command line.
19
+
20
+ ## Synopsis
21
+
22
+
23
+ `/bg [--agent|--llm-agent] [--script|--no-agent] [--name <name>|-n <name>] [--] <command>`
24
+
25
+ `--name=<name>` and `-n=<name>` are also accepted. Quoted names are parsed by the extension before the remaining bytes become the shell command.
26
+
27
+ ## When to use
28
+
29
+ Use `/bg` for user-driven long-running commands where you want a footer entry, output file, and display notification, but **not** an automatic agent follow-up turn. For agent-driven launches, prefer [`bg_run`](../tools/bg_run.md) because its default completion delivery wakes the agent.
30
+
31
+ ## Defaults
32
+
33
+ - `isAgent`: `false`; set `--agent`/`--llm-agent` only when the command launches a Pi/LLM agent whose telemetry should be wrapped.
34
+ - `--script`/`--no-agent`: forces `isAgent:false` after earlier flags.
35
+ - `notifyOnCompletion`: `true`.
36
+ - `triggerOnCompletion`: `false` for `/bg`, so completion is display-only by default.
37
+ - Task name: explicit `--name` if present, otherwise derived from the command.
38
+
39
+ ## Lifecycle
40
+
41
+ The command returns after the child process is spawned and reports task id, output path, and command. Terminal statuses are exactly `running`, `completed`, `failed`, or `killed`. A finished footer badge remains visible until that task's detail view is opened or [`/bg-clear`](bg-clear.md) marks unseen finished tasks seen.
42
+
43
+ ## Examples
44
+
45
+ ```text
46
+ /bg --name "Docs build" npm run docs
47
+ /bg --agent --name "Child Pi" pi -p "summarize this repo"
48
+ /bg --name="Server" -- npm run dev -- --host 127.0.0.1
49
+ ```
50
+
51
+ ## Output/result
52
+
53
+ Start notification:
54
+
55
+ ```text
56
+ Started <task-name> (<task-id>)
57
+ Output: .pi/tasks/<session>-<pid>/<task-id>.output
58
+ Command: <command>
59
+ ```
60
+
61
+ Completion is delivered as a durable `background-task-notification` custom message when notifications are enabled, but `/bg` sets `triggerOnCompletion:false` so it does not start a provider follow-up turn.
62
+
63
+ ## Errors
64
+
65
+ - Empty command: `Background command is empty`.
66
+ - Missing or unterminated `--name`: `requires a task name`.
67
+ - Shell/spawn errors fail the task loudly and write failure metadata.
68
+ - Unknown shell policy on Windows can reject the launch before a task is created.
69
+
70
+ ## Runtime artifacts
71
+
72
+ Outputs and metadata are written under `.pi/tasks/<session-id>-<pid>/` as `<task-id>.output` and `<task-id>.json`. Model-visible log reads are bounded; the full output path is preserved in notices.
73
+
74
+ ## Safety boundaries
75
+
76
+ Shell commands are **not sandboxed**. They run in the current project cwd through the platform shell selected by the runtime. `/bg` tracks and kills the child process/tree, but does not restrict filesystem, network, or subprocess behavior.
77
+
78
+ ## Related docs
79
+
80
+ - [`bg_run`](../tools/bg_run.md)
81
+ - [`/jobs`](jobs.md)
82
+ - [`/logs`](logs.md)
83
+ - [`/kill`](kill.md)
84
+ - [`/bg-clear`](bg-clear.md)
85
+ - [Background task runtime](../subsystems/background-task-runtime.md)
86
+ - [Completion delivery](../concepts/completion-delivery.md)
87
+
88
+ ## Source ownership/reference
89
+
90
+ Surface registration lives in `src/extension.ts`; argument parsing and lifecycle behavior are owned by [background-task-runtime](../subsystems/background-task-runtime.md).
@@ -0,0 +1,70 @@
1
+ ---
2
+ doc_id: commands/fusion-models
3
+ audience: user
4
+ mode: mixed
5
+ review_policy: contract
6
+ stability: stable
7
+ covers_surfaces: [command:fusion-models]
8
+ covers_sources: []
9
+ ---
10
+ # `/fusion-models`
11
+
12
+ <!-- pi-docs:begin name="command-contract-fusion-models" generator="scripts/docs/generate.mjs" -->
13
+ | Command | Description | Provenance |
14
+ | --- | --- | --- |
15
+ | `/fusion-models` | Open the five-slot global fusion model selector. | `src/fusion-extension.ts:914` |
16
+ <!-- pi-docs:end name="command-contract-fusion-models" -->
17
+
18
+ Open the global Fusion model selector.
19
+
20
+ ## Availability
21
+
22
+ `/fusion-models` is **TUI-only**. RPC, JSON, print, and other non-TUI modes reject it; non-UI command contexts throw an error instead of relying on a no-op notification path.
23
+
24
+ ## Slots
25
+
26
+ The selector edits exactly five global slots:
27
+
28
+ 1. `Candidate 1`
29
+ 2. `Candidate 2`
30
+ 3. `Candidate 3`
31
+ 4. `Evaluator`
32
+ 5. `Merger`
33
+
34
+ Duplicate model selections are allowed. `$current` is the default for every slot and resolves at run time to Pi's current model; it is available only when a current model exists and is available to child Pi. Slash-containing model ids are stored as `provider/model-id` strings.
35
+
36
+ ## UI behavior
37
+
38
+ The selector starts from the loaded config or the default all-`$current` config. It lists:
39
+
40
+ - `$current` first, with the current provider/model in the description when known;
41
+ - currently available registry models sorted by `provider/model`;
42
+ - configured-but-unavailable selections, marked unavailable, so stale configs can still be seen and replaced.
43
+
44
+ In the five-slot view, arrow keys move, Enter opens the model list, `r` resets the draft to defaults, `s` saves, and Esc or `q` cancels without saving. In the model-choice view, arrow keys move, typed text—including `q`—filters the list, Backspace edits the filter, Enter chooses and returns to the slots, and Esc returns to the slots without changing that slot.
45
+
46
+ ## Persistence and conflicts
47
+
48
+ The config file is `fusion-models.json` in Pi's agent directory (`fusionModelConfigPath()`). Its schema is closed:
49
+
50
+ ```json
51
+ {
52
+ "schema_version": "pi-background-tasks.fusion-models.v1",
53
+ "candidates": ["$current", "$current", "$current"],
54
+ "evaluator": "$current",
55
+ "merger": "$current"
56
+ }
57
+ ```
58
+
59
+ Loads reject invalid JSON, unknown keys, wrong schema version, blank selections, surrounding whitespace, unqualified configured selections, and candidate arrays that do not contain exactly three entries.
60
+
61
+ Saves are durable and revision-safe: the parent captures the file revision hash on load, takes a lock next to the config, verifies the on-disk revision still matches, then atomically replaces the file. If another process changes the file first, the save fails with a config-conflict error shown inside the selector; it does not overwrite concurrent work. Lock acquisition times out loudly after 10 seconds.
62
+
63
+ ## Route admission
64
+
65
+ At run time every slot is resolved through the available model registry. Frontier routes are accepted only through the Pi subscription OAuth path for `anthropic` or `openai-codex` and only on trusted subscription endpoints. Direct OpenAI/OpenRouter/Azure/frontier API-key routes, endpoint/header overrides of subscription auth, unavailable models, missing current model, and missing positive context windows fail before child creation. There is no fallback, model substitution, or tier bump.
66
+
67
+ ## Related
68
+
69
+ - Command using the selected routes: [`fusion.md`](fusion.md)
70
+ - Behavioral owner/troubleshooting: [`../subsystems/fusion.md`](../subsystems/fusion.md)
@@ -0,0 +1,69 @@
1
+ ---
2
+ doc_id: commands/fusion
3
+ audience: user
4
+ mode: mixed
5
+ review_policy: contract
6
+ stability: stable
7
+ covers_surfaces: [command:fusion]
8
+ covers_sources: []
9
+ ---
10
+ # `/fusion`
11
+
12
+ <!-- pi-docs:begin name="command-contract-fusion" generator="scripts/docs/generate.mjs" -->
13
+ | Command | Description | Provenance |
14
+ | --- | --- | --- |
15
+ | `/fusion` | Run fixed-purpose Fusion reason (no candidate tools) and append the merged result directly. | `src/fusion-extension.ts:891` |
16
+ <!-- pi-docs:end name="command-contract-fusion" -->
17
+
18
+ Run the fixed-purpose Fusion **reason** workflow from the command line.
19
+
20
+ ## Synopsis
21
+
22
+ `/fusion <prompt>`
23
+
24
+ `/fusion` with no arguments opens Pi's multiline editor in UI-capable modes. If the editor is cancelled or the edited text is blank after trimming, Fusion returns without spawning children.
25
+
26
+ ## Current v1 behavior
27
+
28
+ `/fusion` is shorthand for `fusion_reason({prompt})`:
29
+
30
+ - the public workflow is always `reason`;
31
+ - there is no capability or mode argument;
32
+ - candidate children run without tools;
33
+ - evaluator, conditional evaluator-repair, and merger children also run without tools;
34
+ - the request is captured as a versioned visible-conversation projection, not as a raw transcript.
35
+
36
+ The retired `fusion_brainstorm` public tool is not registered and is removed from active tools on session start. Historical completed v4 result messages can still render, but `/fusion` never reactivates the retired surface.
37
+
38
+ ## Conversation input
39
+
40
+ Reason/session-projection input uses schema `pi-background-tasks.fusion-input.v5`. The child-facing input contains:
41
+
42
+ - `request.text` with the exact command prompt;
43
+ - request authority `directive_over_projected_conversation` for the command path;
44
+ - the parent system prompt inside the versioned session-projection context;
45
+ - visible user/assistant text entries preserved verbatim;
46
+ - deterministic omission receipts for assistant thinking, tool calls, and text/image tool results.
47
+
48
+ Omitted payload bytes are not summarized or previewed for the children. If a fact exists only inside omitted tool output, restate it in the prompt.
49
+
50
+ ## Result delivery
51
+
52
+ After a successful run, `/fusion` appends two custom messages without asking the parent model to rewrite the answer:
53
+
54
+ 1. a hidden `fusion-request` record for the command request/run id;
55
+ 2. a visible `fusion-result` record whose content is the merger's exact text and whose details include run id, artifact directory, model summary, usage/cost, evaluator-attempt count, and budget metadata.
56
+
57
+ In TUI mode `/fusion` uses a cancellable loader. Cancelling aborts the active child process tree and records a cancelled run when a run directory exists.
58
+
59
+ ## Calls and failure shape
60
+
61
+ A successful run uses three candidate children, one blind evaluator, and one merger. If the first evaluator response is invalid JSON or violates the closed evaluation schema, Fusion performs exactly one evaluator-repair attempt before failing or continuing. Therefore a successful run may have five or six child invocations; preflight failures launch zero children, and candidate/evaluator/merge failures stop the workflow rather than substituting another model.
62
+
63
+ Failures are reported as `Fusion failed: ...`; tool/stage errors include the artifact directory when one exists. Prompt-budget forecast failures happen before child creation. Child cancellation, timeout, output caps, model-route admission failures, invalid evaluator JSON after repair, invalid compact child metadata, and invalid tool-call audits are loud failures.
64
+
65
+ ## Related
66
+
67
+ - Tool equivalent: [`../tools/fusion_reason.md`](../tools/fusion_reason.md)
68
+ - Model selector: [`fusion-models.md`](fusion-models.md)
69
+ - Behavioral owner/troubleshooting: [`../subsystems/fusion.md`](../subsystems/fusion.md)
@@ -0,0 +1,74 @@
1
+ ---
2
+ doc_id: commands/jobs
3
+ audience: user
4
+ mode: mixed
5
+ review_policy: contract
6
+ stability: stable
7
+ covers_surfaces: [command:jobs]
8
+ covers_sources: []
9
+ ---
10
+ # `/jobs`
11
+
12
+ <!-- pi-docs:begin name="command-contract-jobs" generator="scripts/docs/generate.mjs" -->
13
+ | Command | Description | Provenance |
14
+ | --- | --- | --- |
15
+ | `/jobs` | List running and recent background tasks | `src/extension.ts:594` |
16
+ <!-- pi-docs:end name="command-contract-jobs" -->
17
+
18
+ List running and recent background tasks.
19
+
20
+ ## Synopsis
21
+
22
+
23
+ `/jobs`
24
+
25
+ ## When to use
26
+
27
+ Use `/jobs` for a point-in-time textual snapshot when the interactive task manager is unavailable or unnecessary.
28
+
29
+ ## Defaults
30
+
31
+ No arguments. It lists all tasks currently retained by this extension runtime: running tasks plus recent finished tasks not pruned from the in-memory registry.
32
+
33
+ ## Lifecycle
34
+
35
+ Tasks have exactly these statuses: `running`, `completed`, `failed`, `killed`. Finished tasks are kept as recent history up to the runtime's recent-task retention limit; running tasks are preserved when pruning old finished tasks.
36
+
37
+ ## Examples
38
+
39
+ ```text
40
+ /jobs
41
+ ```
42
+
43
+ ## Output/result
44
+
45
+ If no tasks exist:
46
+
47
+ ```text
48
+ No background tasks in this Pi extension runtime.
49
+ ```
50
+
51
+ Otherwise each task line includes status icon, id, status, age, optional exit code, optional pid, task-owned telemetry summaries when reported, display name, optional error, and a following `output: <path>` line.
52
+
53
+ ## Errors
54
+
55
+ No task-resolution errors; it formats the current registry contents.
56
+
57
+ ## Runtime artifacts
58
+
59
+ `/jobs` reads in-memory task snapshots. It points at `.pi/tasks/<session-id>-<pid>/<task-id>.output` but does not read output bytes.
60
+
61
+ ## Safety boundaries
62
+
63
+ Read-only inspection. It does not wait, poll, kill, or modify tasks.
64
+
65
+ ## Related docs
66
+
67
+ - [`/logs`](logs.md)
68
+ - [`/kill`](kill.md)
69
+ - [`bg_status`](../tools/bg_status.md)
70
+ - [Background task runtime](../subsystems/background-task-runtime.md)
71
+
72
+ ## Source ownership/reference
73
+
74
+ Surface registration lives in `src/extension.ts`; snapshot formatting is owned by [background-task-runtime](../subsystems/background-task-runtime.md).
@@ -0,0 +1,82 @@
1
+ ---
2
+ doc_id: commands/kill
3
+ audience: user
4
+ mode: mixed
5
+ review_policy: contract
6
+ stability: stable
7
+ covers_surfaces: [command:kill]
8
+ covers_sources: []
9
+ ---
10
+ # `/kill`
11
+
12
+ <!-- pi-docs:begin name="command-contract-kill" generator="scripts/docs/generate.mjs" -->
13
+ | Command | Description | Provenance |
14
+ | --- | --- | --- |
15
+ | `/kill` | Stop a running background task: /kill <id> | `src/extension.ts:638` |
16
+ <!-- pi-docs:end name="command-contract-kill" -->
17
+
18
+ Stop a running background task.
19
+
20
+ ## Synopsis
21
+
22
+
23
+ `/kill <task-id-or-prefix>`
24
+
25
+ ## When to use
26
+
27
+ Use `/kill` when a tracked background task is no longer needed or is hung. Use [`bg_kill`](../tools/bg_kill.md) for the same operation from an agent tool call.
28
+
29
+ ## Defaults
30
+
31
+ No defaults beyond task id/prefix resolution. Prefixes must be unambiguous.
32
+
33
+ ## Lifecycle
34
+
35
+ Only `running` tasks can be killed. A successful user kill sets terminal status `killed` and records the task output path. Trying to kill a `completed`, `failed`, or already `killed` task fails loudly.
36
+
37
+ ## Examples
38
+
39
+ ```text
40
+ /kill b12345678
41
+ /kill b1234
42
+ ```
43
+
44
+ ## Output/result
45
+
46
+ ```text
47
+ Killed <task-name> (<task-id>). Output: .pi/tasks/.../<task-id>.output
48
+ ```
49
+
50
+ ## Errors
51
+
52
+ - Missing id: `Task ID is required`.
53
+ - Unknown id/prefix: `Unknown background task ID: <id>`.
54
+ - Ambiguous prefix: lists matching task ids.
55
+ - Non-running task: `Task <id> is <status>, not running`.
56
+ - Kill failure: platform-specific loud error.
57
+
58
+ Errors are shown as `Background kill error: ...`.
59
+
60
+ ## Runtime artifacts
61
+
62
+ The task's output file and metadata remain in `.pi/tasks/...`. Termination notices and errors may be appended to the output and metadata.
63
+
64
+ ## Safety boundaries
65
+
66
+ Process termination differs by platform:
67
+
68
+ - POSIX first targets the detached process group with `SIGTERM`, falls back to the child handle, and escalates to `SIGKILL` after the grace window.
69
+ - Windows uses `taskkill.exe /PID <pid> /T`, then `/F` after the grace window. Force failure is surfaced loudly because descendant processes may have leaked.
70
+
71
+ Shell commands are not sandboxed; killing controls only tracked process handles/trees.
72
+
73
+ ## Related docs
74
+
75
+ - [`bg_kill`](../tools/bg_kill.md)
76
+ - [`/jobs`](jobs.md)
77
+ - [`/logs`](logs.md)
78
+ - [Background task runtime](../subsystems/background-task-runtime.md)
79
+
80
+ ## Source ownership/reference
81
+
82
+ Surface registration lives in `src/extension.ts`; process termination is owned by [background-task-runtime](../subsystems/background-task-runtime.md).
@@ -0,0 +1,90 @@
1
+ ---
2
+ doc_id: commands/logs
3
+ audience: user
4
+ mode: mixed
5
+ review_policy: contract
6
+ stability: stable
7
+ covers_surfaces: [command:logs]
8
+ covers_sources: []
9
+ ---
10
+ # `/logs`
11
+
12
+ <!-- pi-docs:begin name="command-contract-logs" generator="scripts/docs/generate.mjs" -->
13
+ | Command | Description | Provenance |
14
+ | --- | --- | --- |
15
+ | `/logs` | Show bounded output from a background task: /logs <id> [maxBytes] | `src/extension.ts:607` |
16
+ <!-- pi-docs:end name="command-contract-logs" -->
17
+
18
+ Show bounded output from a background task.
19
+
20
+ ## Synopsis
21
+
22
+
23
+ `/logs <task-id-or-prefix> [maxBytes]`
24
+
25
+ Slash-command logs always read the tail.
26
+
27
+ ## When to use
28
+
29
+ Use `/logs` when you need task output in the host UI. For agent tool calls, use [`bg_logs`](../tools/bg_logs.md) and avoid repeated calls as a waiting loop.
30
+
31
+ ## Defaults
32
+
33
+ - `maxBytes`: defaults to the model-safe log cap, currently up to 50 KiB.
34
+ - Values are normalized to an integer in `[1, MAX_LOG_BYTES]`; invalid numbers use the default.
35
+ - `tail`: always `true` for `/logs`.
36
+
37
+ ## Lifecycle
38
+
39
+ `/logs` is a point-in-time read of the output file. It does not subscribe, follow, or poll. Running tasks may produce more output after the read.
40
+
41
+ ## Examples
42
+
43
+ ```text
44
+ /logs b12345678
45
+ /logs b1234 2000
46
+ ```
47
+
48
+ ## Output/result
49
+
50
+ The notification contains output text. If truncated, a notice is prepended for tail reads:
51
+
52
+ ```text
53
+ [Showing tail <bytes-read> of <total>; <omitted> omitted. Full output: .pi/tasks/.../<task-id>.output]
54
+ ```
55
+
56
+ If not truncated, the result ends with:
57
+
58
+ ```text
59
+ [Full output: .pi/tasks/.../<task-id>.output]
60
+ ```
61
+
62
+ The full output path is preserved even when model-visible bytes are bounded.
63
+
64
+ ## Errors
65
+
66
+ - Missing id: `Task ID is required`.
67
+ - Unknown id/prefix: `Unknown background task ID: <id>`.
68
+ - Ambiguous prefix: lists matching task ids.
69
+ - Missing output file: `Output file does not exist for <id>: <path>`.
70
+
71
+ Errors are shown as `Background logs error: ...`.
72
+
73
+ ## Runtime artifacts
74
+
75
+ Reads `.pi/tasks/<session-id>-<pid>/<task-id>.output`; does not modify output or metadata.
76
+
77
+ ## Safety boundaries
78
+
79
+ Read-only bounded inspection. It is not a polling primitive and should not be used merely to wait for completion.
80
+
81
+ ## Related docs
82
+
83
+ - [`bg_logs`](../tools/bg_logs.md)
84
+ - [`/jobs`](jobs.md)
85
+ - [`/kill`](kill.md)
86
+ - [Background task runtime](../subsystems/background-task-runtime.md)
87
+
88
+ ## Source ownership/reference
89
+
90
+ Surface registration lives in `src/extension.ts`; bounded log reading is owned by [background-task-runtime](../subsystems/background-task-runtime.md).
@@ -0,0 +1,109 @@
1
+ ---
2
+ doc_id: commands/task-manager
3
+ audience: user
4
+ mode: mixed
5
+ review_policy: contract
6
+ stability: stable
7
+ covers_surfaces: [command:bg-tasks, command:tasks]
8
+ covers_sources: []
9
+ ---
10
+ # `/tasks` and `/bg-tasks`
11
+
12
+ <!-- pi-docs:begin name="command-contract-tasks-bg-tasks" generator="scripts/docs/generate.mjs" -->
13
+ | Command | Description | Provenance |
14
+ | --- | --- | --- |
15
+ | `/tasks` | Open the Claude-like background task manager UI | `src/extension.ts:532` |
16
+ | `/bg-tasks` | Open the background task manager UI | `src/extension.ts:540` |
17
+ <!-- pi-docs:end name="command-contract-tasks-bg-tasks" -->
18
+
19
+ Open the interactive background task manager. `/tasks` and `/bg-tasks` are aliases.
20
+
21
+ ## Synopsis
22
+
23
+
24
+ `/tasks [exact-task-id]`
25
+
26
+ `/bg-tasks [exact-task-id]`
27
+
28
+ ## When to use
29
+
30
+ Use the task manager when you want the host UI: select tasks, inspect a live output tail, stop one or all running tasks, rerun a task, copy/show an output path, or review recent finished task history.
31
+
32
+ ## Defaults
33
+
34
+ - No argument opens the list view.
35
+ - An exact task id opens detail view for that task and marks it seen in the footer. Unlike `/logs`, `/kill`, and the task tools, this optional UI argument is not prefix-resolved.
36
+ - If there are no running tasks but finished history exists, the list opens in history mode.
37
+
38
+ ## Lifecycle
39
+
40
+ The manager is an overlay dock. Opening it sets the footer hint to `focused` and temporarily hides the `/bg-clear` hint; closing returns the footer to the normal `Shift↓` hint. Opening a finished task's detail view marks that task seen. Merely opening the list or closing the dock does **not** clear other finished badges; use [`/bg-clear`](bg-clear.md) to clear them together.
41
+
42
+ List view sorts tasks as running, failed, killed, then completed; within a status, newest terminal/start time appears first. Status labels shown in the UI are `running`, `error` for `failed`, `stopped` for `killed`, and `done` for `completed`.
43
+
44
+ ## Examples
45
+
46
+ ```text
47
+ /tasks
48
+ /bg-tasks b1234
49
+ ```
50
+
51
+ ## Output/result
52
+
53
+ This command opens UI only. In non-interactive mode, it emits an error notification:
54
+
55
+ ```text
56
+ Background task manager requires an interactive Pi UI. Use /jobs, /logs, or the bg_status/bg_logs tools in non-interactive mode.
57
+ ```
58
+
59
+ ## Controls
60
+
61
+ List view:
62
+
63
+ - `↑`/`↓`: select.
64
+ - `PgUp`/`PgDn`: page selection.
65
+ - `Enter`/`→`: open output detail.
66
+ - `k`: stop selected running task.
67
+ - `a`, `A`, or `K`: stop all running tasks; press again to confirm.
68
+ - `h`: show/hide history.
69
+ - `R`: rerun selected task with notification enabled and wake disabled.
70
+ - `c`/`C`: show output path.
71
+ - `Esc`, `q`, `Q`, `x`, `X`: close.
72
+
73
+ Detail view:
74
+
75
+ - `←`: return to list.
76
+ - `↑`/`↓`/`PgUp`/`PgDn`: scroll output.
77
+ - `r`: refresh and resume following tail.
78
+ - `k`: stop running task.
79
+ - `R`: rerun task.
80
+ - `c`/`C`: show output path.
81
+ - close keys are the same as list view.
82
+
83
+ ## Detail output tail semantics
84
+
85
+ The detail view reads a UI-only tail buffer of 128 KiB once per second while following. It displays 12 output lines. Scrolling up pauses live following and freezes the buffer so the view stays stable. Scrolling/pageing back to the bottom resumes follow mode; `r` also resumes follow and refreshes. This UI tail is larger than the model-facing log cap and is separate from [`bg_logs`](../tools/bg_logs.md).
86
+
87
+ ## Errors
88
+
89
+ Stop, stop-all, rerun, and output-read failures are reported inside the dock as action messages. A missing output file appears as `Output file not found: <path>`.
90
+
91
+ ## Runtime artifacts
92
+
93
+ The manager reads task snapshots and output files from the current extension runtime. It does not reattach to detached historical OS processes after Pi shutdown/reload.
94
+
95
+ ## Safety boundaries
96
+
97
+ Stopping uses the same runtime kill path as [`/kill`](kill.md) and [`bg_kill`](../tools/bg_kill.md). Shell commands are not sandboxed; the manager only controls tracked tasks.
98
+
99
+ ## Related docs
100
+
101
+ - [Shortcuts and dock](../reference/shortcuts-and-dock.md)
102
+ - [`/jobs`](jobs.md)
103
+ - [`/logs`](logs.md)
104
+ - [`/kill`](kill.md)
105
+ - [Host UI and telemetry](../subsystems/host-ui-and-telemetry.md)
106
+
107
+ ## Source ownership/reference
108
+
109
+ Surface registration and dock wiring live in `src/extension.ts`; UI behavior is implemented in `src/ui/background-tasks-manager.ts` and owned by [host-ui-and-telemetry](../subsystems/host-ui-and-telemetry.md).
@@ -0,0 +1,66 @@
1
+ ---
2
+ doc_id: concepts/completion-delivery
3
+ audience: agent
4
+ mode: authored
5
+ review_policy: contract
6
+ stability: stable
7
+ covers_surfaces: [renderer:background-task-notification]
8
+ covers_sources: []
9
+ ---
10
+ # Completion delivery
11
+
12
+ Background tasks can finish silently, notify the terminal, or notify and wake the agent. The flags are task-owned.
13
+
14
+ ## Delivery modes
15
+
16
+ | `notifyOnCompletion` | `triggerOnCompletion` | Actual mode |
17
+ |---|---:|---|
18
+ | `true` | `true` | Durable terminal notification and automatic follow-up turn. Default for [`bg_run`](../tools/bg_run.md). |
19
+ | `true` | `false` | Durable terminal notification only; no provider follow-up. Default for [`/bg`](../commands/bg.md). |
20
+ | `false` | `true` | Manual monitoring; `triggerOnCompletion` has no effect without a notification. |
21
+ | `false` | `false` | Manual monitoring. |
22
+
23
+ ## Critical behavior
24
+
25
+ - `/bg` is display-only by default: it sets `notifyOnCompletion:true` and `triggerOnCompletion:false`.
26
+ - `bg_run` defaults to durable notification plus follow-up turn: `notifyOnCompletion:true` and `triggerOnCompletion:true`.
27
+ - `bg_status` and `bg_logs` are point-in-time inspection tools, not polling primitives.
28
+ - A received `<background-task-notification>` is metadata-backed terminal-status truth. The output stream has finished/closed, but ordinary `.output` bytes are not explicitly fsynced. Do not call `bg_status` only to reconfirm status; call `bg_logs` only if output bytes are needed.
29
+
30
+ ## Notification payload
31
+
32
+ When enabled and not during shutdown, terminal completion sends a custom message with:
33
+
34
+ - `<task-id>`
35
+ - `<task-name>`
36
+ - `<status>` (`completed`, `failed`, or `killed`)
37
+ - optional `<exit-code>`
38
+ - optional `<error>`
39
+ - `<output-file>`
40
+ - `<summary>`
41
+ - `<guidance>` that says terminal state and output metadata are durable and not to reconfirm with `bg_status`.
42
+
43
+ The structured details contain the task snapshot, including delivery flags and `notified` state.
44
+
45
+ ## Agent guidance
46
+
47
+ After default `bg_run`, continue only independent useful work. If there is no such work, briefly acknowledge and end the turn; the follow-up notification will wake the agent. Do not sleep, poll `bg_status`, or repeatedly read `bg_logs` merely to wait.
48
+
49
+ If either completion flag was intentionally disabled, manual inspection is allowed when deliberate, but still avoid tight polling.
50
+
51
+ ## Failures and suppression
52
+
53
+ If notification send fails, the task resets `notified:false` and logs the error; it does not silently pretend delivery happened. During Pi session shutdown/reload, notifications are suppressed while running tasks are killed.
54
+
55
+ ## Related docs
56
+
57
+ - [`bg_run`](../tools/bg_run.md)
58
+ - [`bg_status`](../tools/bg_status.md)
59
+ - [`bg_logs`](../tools/bg_logs.md)
60
+ - [`/bg`](../commands/bg.md)
61
+ - [Background task runtime](../subsystems/background-task-runtime.md)
62
+ - [Host UI and telemetry](../subsystems/host-ui-and-telemetry.md)
63
+
64
+ ## Source ownership/reference
65
+
66
+ Delivery receipt text is derived by runtime helpers and sent by extension registration; primary behavioral ownership is split between [background-task-runtime](../subsystems/background-task-runtime.md) and [host-ui-and-telemetry](../subsystems/host-ui-and-telemetry.md).