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,63 @@
1
+ # pi-background-tasks — Mandatory Agent Gateway
2
+
3
+ **Read this before you read code, edit docs, edit code, or run anything in this package.**
4
+ This gateway is for AI agents maintaining `pi-background-tasks`. It is package-local, deterministic, and intentionally stricter than generic repo instructions.
5
+
6
+ **Logo reference:** use the package-local docs logo when present: [`docs/assets/logo.svg`](docs/assets/logo.svg). Do not invent remote logos; asset files remain asset-owner territory and must be verified in the docs/assets payload check.
7
+
8
+ ---
9
+
10
+ ## Required read-before-edit order
11
+
12
+ 1. [`docs/INDEX.md`](docs/INDEX.md) — generated package navigation index. If it is absent, stale, or not generated yet, stop relying on memory and report that the docs-engine lane must create/update it.
13
+ 2. [`docs/read-before-edit.md`](docs/read-before-edit.md) — generated source-path to owning-doc read gate. If absent or stale, run/ask for the docs-engine gate before editing production sources.
14
+ 3. The owning authored doc for the surface you are touching.
15
+
16
+ Current authored ownership map:
17
+
18
+ | Surface/source area | Owning doc |
19
+ |---|---|
20
+ | EventBus API; `src/core/extension-api.ts` | `docs/api/eventbus-v1.md` |
21
+ | Shared context projection and estimator; `src/core/context/**` | `docs/concepts/context-projection-and-budgeting.md` |
22
+ | Pi child launch resolution and durable file primitives; `src/core/pi-launch.ts`, `src/core/durable-fs.ts` | `docs/subsystems/child-launch-durability-and-safety.md` |
23
+ | Paths, artifacts, config, env, defaults, schema registry | `docs/reference/runtime-contracts.md` |
24
+ | Symptom triage | `docs/operations/troubleshooting.md` |
25
+ | QA/test operations | `docs/operations/testing.md`, then `TESTING.md`, then `TEST_PLAN.md` |
26
+ | Release/package maintenance | `docs/operations/releasing.md`, then `PUBLISHING.md` |
27
+
28
+ ---
29
+
30
+ ## Hard rules
31
+
32
+ - **Code is authority for runtime facts; docs describe code.** Do not change code to satisfy prose. When code and docs disagree, update docs or file a code-owner blocker.
33
+ - **Generated regions are not hand-edited.** Regions named `<!-- pi-docs:begin ... -->` / `<!-- pi-docs:end ... -->`, `docs/INDEX.md`, `docs/read-before-edit.md`, README generated facts, and `docs/manifest.json` belong to the docs engine.
34
+ - **No silent truncation, fallback, or route substitution.** Oversized data must be persisted with hashes or rejected loudly. Unavailable model routes, missing context windows, stale config, malformed frames, missing artifacts, and unknown schemas are hard errors.
35
+ - **Parent and child tools are distinct.** Parent tools include `bg_run`, `bg_delegate`, `bg_result`, `bg_status`, `bg_logs`, `bg_kill`, `bg_run_pi_attested`, and the public Fusion tools. Delegate children are inspect-only (`read`, `grep`, `find`, `ls`, `delegate_read_artifact`). Fusion children receive only the workflow-specific candidate tools; evaluator/merger are no-tools.
36
+ - **Frontier routing is subscription-only.** GPT/Codex and Claude-class work must use Pi subscription/OAuth channels. Never route them through metered OpenAI, Anthropic API, OpenRouter, Azure, or other paid API channels.
37
+ - **Durability and integrity are contract surfaces.** Terminal task truth is published only after output/metadata durability. Delegate/Fusion artifacts and attested Pi sidecars carry hashes and schema versions; do not replace these with best-effort writes.
38
+ - **No self-certification.** If a doc freshness or attestation mechanism exists, do not stamp the same change as verified without the required independent check. If the mechanism is absent, say so plainly.
39
+ - **Do not use Fusion tools or commands for package maintenance.** Read files and run focused local checks only.
40
+
41
+ ---
42
+
43
+ ## Runtime roots
44
+
45
+ - Task runtime: `.pi/tasks/<session-id>-<pid>/` under the active project cwd.
46
+ - Fusion runtime: `.pi/fusion/<session-id>-<pid>/<run-id>/` under the active project cwd.
47
+ - Delegate artifacts: task-owned artifact directories referenced from task metadata/result packages.
48
+ - Fusion model config: `fusion-models.json` under Pi's agent directory (`getAgentDir()`), not the project `.pi/tasks` tree.
49
+ - Package entrypoint: `extensions/background-tasks.ts` via `package.json.pi.extensions`.
50
+
51
+ ---
52
+
53
+ ## Docs generate/verify/attestation workflow
54
+
55
+ Current `package.json` exposes the docs-engine lane:
56
+
57
+ ```bash
58
+ npm run docs:generate
59
+ npm run docs:verify
60
+ npm run docs:attest/record -- <doc_id> --reviewer <identity-after-semantic-review> --verdict PASS --notes <review-notes>
61
+ ```
62
+
63
+ `npm run docs:attest` is an alias for the attestation recorder and still requires a doc id, reviewer, verdict, and notes after semantic review. Do not self-award PASS. For docs-only maintenance under a constrained operator request, use the requested focused subset (frontmatter, package-local links, targeted source/doc grep) and report that full docs verification/attestation was not run.
package/PUBLISHING.md CHANGED
@@ -1,67 +1,81 @@
1
1
  # Publishing pi-background-tasks
2
2
 
3
- Release checklist for npm publishing and standalone git publishing. The current release candidate is 0.7.7; version 0.7.0 introduced the Fusion public surfaces (`/fusion`, `/fusion-models`, `fusion_brainstorm`) in addition to the background-task surfaces. Do not advertise the GitHub install target until the standalone repository has the exact release commit and tag.
3
+ Release checklist for npm publishing and standalone git publishing.
4
+
5
+ The release version is always read from `package.json`:
6
+
7
+ ```bash
8
+ # From the pi-background-tasks package root:
9
+ VERSION=$(node -p "require('./package.json').version")
10
+ printf 'pi-background-tasks@%s\n' "$VERSION"
11
+ ```
12
+
13
+ Observed standalone git tags currently stop at `v0.6.0`; do **not** advertise a `v$VERSION` git install target until that tag exists in the standalone package repository.
4
14
 
5
15
  ## Preconditions
6
16
 
7
17
  - npm account with publish rights for `pi-background-tasks`.
8
- - Standalone GitHub repository, expected: `github.com/ismailsaleekh/pi-background-tasks`.
9
- - Clean worktree.
10
- - Final repair commit present in the standalone package repository; do not push from automated repair runs unless the operator explicitly requests it.
18
+ - Standalone GitHub repository: `github.com/ismailsaleekh/pi-background-tasks`.
19
+ - Clean worktree and final release commit in the standalone package repository.
20
+ - Frontier model evidence, if any, uses Pi subscription/OAuth channels only; never metered APIs.
21
+ - No automated publish, push, or tag from repair runs unless the operator explicitly requests it.
11
22
 
12
- ## Verify
23
+ ## Ordinary release checks
13
24
 
14
25
  ```bash
15
- cd packages/pi-background-tasks
16
- npm run test
17
- npm run test:full
26
+ npm run typecheck
27
+ npm run test:type-safety
28
+ npm run test:unit
29
+ npm run test:sdk
30
+ npm run test:rpc
31
+ npm run test:component
32
+ npm run test:package
33
+ npm run test:hook-contract
18
34
  npm run smoke
19
35
  npm run smoke:large-context
36
+ npm run docs:verify
37
+ npm run payload:check
38
+ # On a tag ref only: GITHUB_REF_TYPE=tag GITHUB_REF_NAME=v$VERSION npm run release:check-version
20
39
  npm run pack:dry-run
21
40
  npm run test:compat
22
41
  npm view pi-background-tasks name version --json
23
42
  ```
24
43
 
25
- `npm run test:compat` covers exact Pi `0.75.5`, `0.81.1`, `0.82.1`, and `0.83.0`. For each version it verifies the resolved `typebox` is Pi's bundled peer (not a private or nested copy) and scans the installed package bytes for TypeBox APIs removed in the 1.3.x line.
44
+ `npm run test:full` is the full interactive gate (default gate plus PTY and agent-loop). Run it when certifying full TUI/agent-loop behavior, not for docs-only maintenance.
26
45
 
27
- `pi-background-tasks` is already published; bump `package.json` before each npm publish.
46
+ ## Payload verification
47
+
48
+ Use `npm pack --dry-run --json --ignore-scripts` output as the payload source of truth for payload inspection. Verify that `extensions/`, `src/`, `docs/`, `README.md`, `TESTING.md`, `TEST_PLAN.md`, `PUBLISHING.md`, `BACKGROUND-TASKS-INSTRUCTIONS.md`, root `logo.png`, and `LICENSE` match current `package.json.files`, and that tests/scripts/local `.pi` artifacts/node_modules/nested tarballs are excluded.
28
49
 
29
50
  ## Publish to npm
30
51
 
52
+ Only after operator approval:
53
+
31
54
  ```bash
32
- cd packages/pi-background-tasks
33
55
  npm login
34
56
  npm publish --access public
35
57
  ```
36
58
 
37
- Pi install smoke after publish:
59
+ Post-publish smoke with isolated Pi state:
38
60
 
39
61
  ```bash
40
- PI_CODING_AGENT_DIR=$(mktemp -d) pi -e npm:pi-background-tasks@0.7.7 --offline --no-tools --no-session -p "/jobs"
41
- pi install npm:pi-background-tasks@0.7.7
62
+ PI_CODING_AGENT_DIR=$(mktemp -d) pi -e npm:pi-background-tasks@$VERSION --offline --no-tools --no-session -p "/jobs"
63
+ pi install npm:pi-background-tasks@$VERSION
42
64
  ```
43
65
 
44
- ## Publish to git
66
+ ## Standalone git tag certification
45
67
 
46
- Because Pi git package installs treat the repository root as the package root, do not point Pi at the `ai-pipeline` monorepo root for this package. Push the contents of `packages/pi-background-tasks/` to a standalone repository.
68
+ Pi git package installs treat the repository root as the package root. Do not point Pi at the `ai-pipeline` monorepo root for this package.
47
69
 
48
- ```bash
49
- cd packages/pi-background-tasks
50
- git status --short --branch
51
- git log --oneline -3
52
- git remote -v
53
- git push origin main
54
- git tag v0.7.7
55
- git push origin v0.7.7
56
- ```
70
+ Before any git install instructions are published, verify in the standalone repo that tag `v$VERSION` exists and points at the release commit. `npm run release:check-version` requires an explicit tag ref (`GITHUB_REF_TYPE=tag`, `GITHUB_REF_NAME=v$VERSION`) and never publishes. If the tag does not exist, the git channel is not certified for this release.
57
71
 
58
- Pi install smoke after git tag, using an isolated Pi agent directory so no local checkout or user `~/.pi` state is involved:
72
+ Git install smoke only after the tag exists:
59
73
 
60
74
  ```bash
61
- PI_CODING_AGENT_DIR=$(mktemp -d) pi -e git:github.com/ismailsaleekh/pi-background-tasks@v0.7.7 --offline --no-tools --no-session -p "/jobs"
62
- pi install git:github.com/ismailsaleekh/pi-background-tasks@v0.7.7
75
+ PI_CODING_AGENT_DIR=$(mktemp -d) pi -e git:github.com/ismailsaleekh/pi-background-tasks@v$VERSION --offline --no-tools --no-session -p "/jobs"
76
+ pi install git:github.com/ismailsaleekh/pi-background-tasks@v$VERSION
63
77
  ```
64
78
 
65
79
  ## pi.dev/packages
66
80
 
67
- The package includes the `pi-package` keyword and a `pi.extensions` manifest. After npm publish, it should be discoverable by pi.dev package indexing. If it does not appear automatically, submit/refresh the package according to the pi.dev package-gallery process.
81
+ The package includes the `pi-package` keyword and a `pi.extensions` manifest. After npm publish, it should be discoverable by pi.dev package indexing. If it does not appear automatically, refresh according to the package-gallery process.