@pi-unipi/unipi 2.7.1 → 2.8.1

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 (64) hide show
  1. package/package.json +2 -1
  2. package/packages/autocomplete/src/constants.ts +36 -0
  3. package/packages/background-tasks/README.md +87 -0
  4. package/packages/background-tasks/extensions/anthropic-attribution.ts +1 -0
  5. package/packages/background-tasks/extensions/delegate-child.ts +1 -0
  6. package/packages/background-tasks/extensions/fusion-child.ts +1 -0
  7. package/packages/background-tasks/package.json +40 -0
  8. package/packages/background-tasks/src/anthropic-attribution-path.ts +21 -0
  9. package/packages/background-tasks/src/anthropic-attribution.ts +1983 -0
  10. package/packages/background-tasks/src/attested-pi-run.ts +612 -0
  11. package/packages/background-tasks/src/child-process.ts +55 -0
  12. package/packages/background-tasks/src/common.ts +8 -0
  13. package/packages/background-tasks/src/config.ts +292 -0
  14. package/packages/background-tasks/src/context-parent-snapshot.ts +142 -0
  15. package/packages/background-tasks/src/context-token-budget.ts +903 -0
  16. package/packages/background-tasks/src/context-visible-conversation-v2.ts +551 -0
  17. package/packages/background-tasks/src/delegate/artifacts.ts +487 -0
  18. package/packages/background-tasks/src/delegate/budget.ts +415 -0
  19. package/packages/background-tasks/src/delegate/hook-contract.ts +154 -0
  20. package/packages/background-tasks/src/delegate/launch.ts +497 -0
  21. package/packages/background-tasks/src/delegate/result-package.ts +459 -0
  22. package/packages/background-tasks/src/delegate/runner.ts +449 -0
  23. package/packages/background-tasks/src/delegate/seed.ts +423 -0
  24. package/packages/background-tasks/src/delegate/types.ts +323 -0
  25. package/packages/background-tasks/src/delegate-child-extension.ts +978 -0
  26. package/packages/background-tasks/src/delegate-extension.ts +806 -0
  27. package/packages/background-tasks/src/durable-fs.ts +386 -0
  28. package/packages/background-tasks/src/extension-api.ts +548 -0
  29. package/packages/background-tasks/src/fusion/artifacts.ts +967 -0
  30. package/packages/background-tasks/src/fusion/budget.ts +1162 -0
  31. package/packages/background-tasks/src/fusion/child-protocol.ts +305 -0
  32. package/packages/background-tasks/src/fusion/claude-cache.ts +207 -0
  33. package/packages/background-tasks/src/fusion/clean-context.ts +91 -0
  34. package/packages/background-tasks/src/fusion/config.ts +449 -0
  35. package/packages/background-tasks/src/fusion/context.ts +265 -0
  36. package/packages/background-tasks/src/fusion/evaluation.ts +800 -0
  37. package/packages/background-tasks/src/fusion/orchestrator.ts +1288 -0
  38. package/packages/background-tasks/src/fusion/output-contract.ts +34 -0
  39. package/packages/background-tasks/src/fusion/pi-child.ts +2373 -0
  40. package/packages/background-tasks/src/fusion/prompts.ts +345 -0
  41. package/packages/background-tasks/src/fusion/result-package.ts +959 -0
  42. package/packages/background-tasks/src/fusion/source-policy.ts +257 -0
  43. package/packages/background-tasks/src/fusion/types.ts +1139 -0
  44. package/packages/background-tasks/src/fusion/web-fetch.ts +1060 -0
  45. package/packages/background-tasks/src/fusion/workflows.ts +184 -0
  46. package/packages/background-tasks/src/fusion-child-extension.ts +1052 -0
  47. package/packages/background-tasks/src/fusion-extension.ts +1293 -0
  48. package/packages/background-tasks/src/index.ts +295 -0
  49. package/packages/background-tasks/src/pi-launch.ts +225 -0
  50. package/packages/background-tasks/src/registry.ts +2424 -0
  51. package/packages/background-tasks/src/settings-overlay.ts +208 -0
  52. package/packages/background-tasks/src/task-manager.ts +774 -0
  53. package/packages/background-tasks/src/tools.ts +532 -0
  54. package/packages/background-tasks/src/turndown.d.ts +15 -0
  55. package/packages/background-tasks/src/types.ts +963 -0
  56. package/packages/background-tasks/src/ui/fusion-model-selector.ts +322 -0
  57. package/packages/background-tasks/src/windows-taskkill.ts +250 -0
  58. package/packages/subagents/skills/subagents/SKILL.md +2 -2
  59. package/packages/subagents/skills/subagents/references/constraints-and-recipes.md +1 -1
  60. package/packages/subagents/skills/subagents/references/execution-controls.md +1 -1
  61. package/packages/subagents/skills/subagents/references/management-authoring-rpc.md +1 -1
  62. package/packages/subagents/skills/subagents/references/prompting-and-roles.md +1 -1
  63. package/packages/unipi/bundled.js +18647 -1256
  64. package/packages/unipi/index.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/unipi",
3
- "version": "2.7.1",
3
+ "version": "2.8.1",
4
4
  "description": "All-in-one extension suite for Pi coding agent",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -83,6 +83,7 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "@pi-unipi/ask-user": "2.6.1",
86
+ "@pi-unipi/background-tasks": "2.6.3",
86
87
  "@pi-unipi/btw": "2.6.1",
87
88
  "@pi-unipi/command-enchantment": "2.6.1",
88
89
  "@pi-unipi/compactor": "2.6.1",
@@ -34,6 +34,8 @@ export const PACKAGE_ORDER: string[] = [
34
34
  "updater",
35
35
  "input-shortcuts",
36
36
  "image",
37
+ "subagents",
38
+ "background-tasks",
37
39
  ];
38
40
 
39
41
  // ─── Package Colors ──────────────────────────────────────────────────
@@ -56,6 +58,8 @@ export const PACKAGE_COLORS: Record<string, string> = {
56
58
  updater: `${ESC}[93m`, // Bright Yellow
57
59
  "input-shortcuts": `${ESC}[95m`, // Bright Magenta
58
60
  image: `${ESC}[35m`, // Magenta
61
+ subagents: `${ESC}[34m`, // Blue
62
+ "background-tasks": `${ESC}[91m`, // Bright Red
59
63
  };
60
64
 
61
65
  // ─── Command Registry ────────────────────────────────────────────────
@@ -134,6 +138,20 @@ export const COMMAND_REGISTRY: Record<string, string> = {
134
138
  "unipi:subagents-doctor": "subagents",
135
139
  "unipi:subagents-guide": "subagents",
136
140
 
141
+ // background-tasks (8 commands)
142
+ "unipi:bg": "background-tasks",
143
+ "unipi:bg-clear": "background-tasks",
144
+ "unipi:bg-tasks": "background-tasks",
145
+ "unipi:bg-settings": "background-tasks",
146
+ "unipi:bg-update": "background-tasks",
147
+ "unipi:tasks": "background-tasks",
148
+ "unipi:jobs": "background-tasks",
149
+ "unipi:kill": "background-tasks",
150
+ "unipi:logs": "background-tasks",
151
+ "unipi:claude-cache": "background-tasks",
152
+ "unipi:fusion": "background-tasks",
153
+ "unipi:fusion-models": "background-tasks",
154
+
137
155
  // info (2 commands)
138
156
  "unipi:info": "info",
139
157
  "unipi:info-settings": "info",
@@ -288,6 +306,22 @@ export const COMMAND_DESCRIPTIONS: Record<string, string> = {
288
306
  "unipi:updater-settings": "Configure updater — check interval and auto-update",
289
307
 
290
308
  "unipi:stash-settings": "Open input shortcuts settings — customize keybindings",
309
+
310
+ "unipi:bg": "Start a shell command as a tracked background task",
311
+ "unipi:bg-clear": "Clear finished background task footer notices",
312
+ "unipi:bg-tasks": "Open the background task manager UI",
313
+ "unipi:bg-settings": "Open background-tasks settings (master toggle, defaults)",
314
+ "unipi:bg-update": "Show installed background-tasks version and update instructions",
315
+ "unipi:tasks": "Open the background task manager UI",
316
+ "unipi:jobs": "List running and recent background tasks",
317
+ "unipi:kill": "Stop a running background task: /unipi:kill <id>",
318
+ "unipi:logs": "Show bounded output from a background task",
319
+ "unipi:claude-cache": "Show or set Claude cache retention for this session",
320
+ "unipi:fusion": "Run the Fusion reason workflow with a prompt",
321
+ "unipi:fusion-models": "Open the Fusion five-slot model selector",
322
+ "unipi:subagents-fleet": "Open the subagents fleet view",
323
+ "unipi:subagents-doctor": "Diagnose subagents configuration",
324
+ "unipi:subagents-guide": "Show the subagents usage guide",
291
325
  };
292
326
 
293
327
  // ─── Package Display Names ───────────────────────────────────────────
@@ -310,4 +344,6 @@ export const PACKAGE_LABELS: Record<string, string> = {
310
344
  updater: "updater",
311
345
  "input-shortcuts": "input-shortcuts",
312
346
  image: "image",
347
+ subagents: "subagents",
348
+ "background-tasks": "background-tasks",
313
349
  };
@@ -0,0 +1,87 @@
1
+ # @pi-unipi/background-tasks
2
+
3
+ Background tasks for UniPi — a full adoption of
4
+ [pi-background-tasks](https://github.com/ismailsaleekh/pi-background-tasks) into the
5
+ unipi conventions: durable background shell jobs, read-only delegated agents,
6
+ attested Pi runs, fixed-purpose multi-model Fusion workflows, and package-owned
7
+ Anthropic subscription attribution.
8
+
9
+ ## Master toggle
10
+
11
+ One config key disables the entire module — no tools, no commands, no hooks, no UI:
12
+
13
+ ```json
14
+ // ~/.unipi/config/background-tasks.json (global)
15
+ // <workspace>/.unipi/config/background-tasks.json (override; workspace wins)
16
+ {
17
+ "enabled": true
18
+ }
19
+ ```
20
+
21
+ Open `/unipi:bg-settings` for the interactive settings overlay (master toggle,
22
+ defaults, output caps, delegate/fusion defaults).
23
+
24
+ ## Surfaces
25
+
26
+ ### Tools (reference names kept)
27
+
28
+ | Tool | Purpose |
29
+ | --- | --- |
30
+ | `bg_run` | Start a named long-running shell command; terminal notification wakes a follow-up turn by default |
31
+ | `bg_status` / `bg_logs` / `bg_kill` | Point-in-time inspection, bounded log reads, stop — never polling primitives |
32
+ | `bg_delegate` + `bg_result` | One read-only child Pi agent seeded with a frozen projection of this conversation; hash-verified answer retrieval |
33
+ | `bg_run_pi_attested` | Evidence-oriented direct Pi spawn with local hashes and route attestation |
34
+ | `fusion_reason` | 3 candidates → blind evaluator → merger on the session projection |
35
+ | `fusion_investigate` / `fusion_research` / `fusion_validate` | Fixed-purpose multi-model workflows on clean-task input (inspect tools / caller-URL research / advisory review) |
36
+
37
+ ### Commands (our namespace)
38
+
39
+ `/unipi:bg`, `/unipi:bg-clear`, `/unipi:bg-tasks`, `/unipi:bg-update`,
40
+ `/unipi:tasks`, `/unipi:jobs`, `/unipi:kill`, `/unipi:logs`,
41
+ `/unipi:bg-settings`, `/unipi:fusion`, `/unipi:fusion-models`,
42
+ `/unipi:claude-cache`.
43
+
44
+ Shortcuts: `Shift↓` opens the task manager dock; `Ctrl+Alt+C` clears finished notices.
45
+
46
+ ## Storage layout (ours — never `.pi/`)
47
+
48
+ - Runtime artifacts (task output/metadata): `$TMPDIR/unipi-bg-tasks/<session>-<pid>-<nonce>/`
49
+ - Durable delegate artifacts: `<workspace>/.unipi/delegate/<session>-<pid>/<task-id>/`
50
+ - Durable fusion artifacts: `<workspace>/.unipi/fusion/<session>-<pid>/<run-id>/`
51
+ - Config: `~/.unipi/config/background-tasks.json` + workspace override
52
+ - Fusion model config: five-slot selector persisted through `/unipi:fusion-models`
53
+
54
+ ## Environment
55
+
56
+ `UNIPI_BG_*` prefix (replaces the reference `PI_BG_*`):
57
+ `UNIPI_BG_TMP_DIR`, `UNIPI_BG_MAX_OUTPUT_BYTES`, `UNIPI_BG_SHELL`,
58
+ `UNIPI_BG_SHELL_PATH`, `UNIPI_BG_DISABLE_PI_TELEMETRY`, `UNIPI_BG_DELEGATE_*`.
59
+
60
+ ## Completion delivery
61
+
62
+ | `notifyOnCompletion` | `triggerOnCompletion` | Mode |
63
+ | --- | --- | --- |
64
+ | true (default) | true (bg_run default) | Durable terminal notification + automatic follow-up turn |
65
+ | true | false (`/unipi:bg` default) | Notification only |
66
+ | false | — | Manual monitoring |
67
+
68
+ Treat `<background-task-notification>` as durable terminal truth — do not poll.
69
+
70
+ ## Attribution
71
+
72
+ `extensions/anthropic-attribution.ts` loads first (provider-gated): Claude Code
73
+ subscription OAuth attribution, exact-match system-prompt sanitization, and
74
+ cache-retention policy for Anthropic routes. Duplicate installed copies resolve
75
+ ownership through an EventBus claim; later copies go inert.
76
+
77
+ ## Differences from the reference
78
+
79
+ - Commands live in the `/unipi:*` namespace; env prefix is `UNIPI_BG_*`.
80
+ - Runtime artifacts under the OS temp root (per-registry nonce) and durable
81
+ delegate/fusion artifacts under workspace `.unipi/` — never `.pi/`.
82
+ - The reference's `update-check` footer surface is dropped (unipi's updater
83
+ module owns updates).
84
+ - `agent_settled` / `before_provider_headers` hooks register defensively on our
85
+ pi SDK with an `agent_end` settlement fallback.
86
+
87
+ ISC-licensed reference: Copyright Ismail <ismailsalikhodjaev@gmail.com>.
@@ -0,0 +1 @@
1
+ export { default } from '../src/anthropic-attribution.js';
@@ -0,0 +1 @@
1
+ export { default } from '../src/delegate-child-extension.js';
@@ -0,0 +1 @@
1
+ export { default } from '../src/fusion-child-extension.js';
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@pi-unipi/background-tasks",
3
+ "version": "2.6.3",
4
+ "description": "Background tasks for UniPi \u2014 durable shell jobs, delegated agents, attested Pi runs, and fixed-purpose Fusion workflows",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "scripts": {
9
+ "test": "npx tsx --test src/__tests__/*.test.ts"
10
+ },
11
+ "dependencies": {
12
+ "@earendil-works/pi-ai": "^0.80.0",
13
+ "@pi-unipi/core": "2.6.1",
14
+ "turndown": "^7.2.4"
15
+ },
16
+ "devDependencies": {
17
+ "@types/turndown": "^5.0.6",
18
+ "typescript": "^5.8.3"
19
+ },
20
+ "peerDependencies": {
21
+ "@earendil-works/pi-coding-agent": "^0.80.0",
22
+ "@earendil-works/pi-tui": "^0.80.0",
23
+ "typebox": "^1.1.38"
24
+ },
25
+ "files": [
26
+ "src/**/*.ts",
27
+ "src/**/*.json",
28
+ "extensions/*.ts",
29
+ "README.md"
30
+ ],
31
+ "pi": {
32
+ "extensions": [
33
+ "./extensions/anthropic-attribution.ts",
34
+ "./src/index.ts"
35
+ ],
36
+ "skills": [],
37
+ "prompts": [],
38
+ "themes": []
39
+ }
40
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @pi-unipi/background-tasks — Anthropic attribution extension path
3
+ *
4
+ * Resolves this package's own attribution extension entry so isolated child Pi
5
+ * processes can load it explicitly. Mirrors the reference layout:
6
+ * extensions/anthropic-attribution.ts re-exports src/anthropic-attribution.ts.
7
+ */
8
+
9
+ import { dirname, resolve } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import { existsSync } from "node:fs";
12
+
13
+ export function resolveAnthropicAttributionExtensionPath(): string {
14
+ // src/anthropic-attribution-path.ts -> packages/background-tasks/extensions/
15
+ const here = dirname(fileURLToPath(import.meta.url));
16
+ const candidate = resolve(here, "..", "extensions", "anthropic-attribution.ts");
17
+ if (!existsSync(candidate)) {
18
+ throw new Error(`Anthropic attribution extension is missing: ${candidate}`);
19
+ }
20
+ return candidate;
21
+ }