pi-worker-graph 0.1.0-dev.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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +455 -0
  3. package/SECURITY.md +54 -0
  4. package/dist/config.d.ts +25 -0
  5. package/dist/config.d.ts.map +1 -0
  6. package/dist/config.js +181 -0
  7. package/dist/config.js.map +1 -0
  8. package/dist/context.d.ts +22 -0
  9. package/dist/context.d.ts.map +1 -0
  10. package/dist/context.js +81 -0
  11. package/dist/context.js.map +1 -0
  12. package/dist/coordination.d.ts +19 -0
  13. package/dist/coordination.d.ts.map +1 -0
  14. package/dist/coordination.js +267 -0
  15. package/dist/coordination.js.map +1 -0
  16. package/dist/execution-failure.d.ts +42 -0
  17. package/dist/execution-failure.d.ts.map +1 -0
  18. package/dist/execution-failure.js +90 -0
  19. package/dist/execution-failure.js.map +1 -0
  20. package/dist/extension.d.ts +8 -0
  21. package/dist/extension.d.ts.map +1 -0
  22. package/dist/extension.js +641 -0
  23. package/dist/extension.js.map +1 -0
  24. package/dist/graph.d.ts +44 -0
  25. package/dist/graph.d.ts.map +1 -0
  26. package/dist/graph.js +292 -0
  27. package/dist/graph.js.map +1 -0
  28. package/dist/index.d.ts +16 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +8 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/json.d.ts +9 -0
  33. package/dist/json.d.ts.map +1 -0
  34. package/dist/json.js +66 -0
  35. package/dist/json.js.map +1 -0
  36. package/dist/orchestrator.d.ts +15 -0
  37. package/dist/orchestrator.d.ts.map +1 -0
  38. package/dist/orchestrator.js +473 -0
  39. package/dist/orchestrator.js.map +1 -0
  40. package/dist/output.d.ts +61 -0
  41. package/dist/output.d.ts.map +1 -0
  42. package/dist/output.js +248 -0
  43. package/dist/output.js.map +1 -0
  44. package/dist/pi-subprocess.d.ts +92 -0
  45. package/dist/pi-subprocess.d.ts.map +1 -0
  46. package/dist/pi-subprocess.js +897 -0
  47. package/dist/pi-subprocess.js.map +1 -0
  48. package/dist/run.d.ts +89 -0
  49. package/dist/run.d.ts.map +1 -0
  50. package/dist/run.js +562 -0
  51. package/dist/run.js.map +1 -0
  52. package/dist/store.d.ts +331 -0
  53. package/dist/store.d.ts.map +1 -0
  54. package/dist/store.js +1993 -0
  55. package/dist/store.js.map +1 -0
  56. package/dist/usage.d.ts +35 -0
  57. package/dist/usage.d.ts.map +1 -0
  58. package/dist/usage.js +88 -0
  59. package/dist/usage.js.map +1 -0
  60. package/docs/DECISIONS.md +221 -0
  61. package/docs/DESIGN.md +392 -0
  62. package/docs/NEXT.md +229 -0
  63. package/docs/PLAN.md +203 -0
  64. package/docs/worker-graph.example.json +12 -0
  65. package/extensions/index.ts +1 -0
  66. package/extensions/tsconfig.json +11 -0
  67. package/package.json +66 -0
package/docs/PLAN.md ADDED
@@ -0,0 +1,203 @@
1
+ # Implementation plan
2
+
3
+ ## Goal
4
+
5
+ Deliver a small installable Pi package that runs writable worker tasks as a DAG in
6
+ one shared checkout, propagates compact context over dependency edges, and lets
7
+ the parent orchestrator review and request revisions.
8
+
9
+ ## Phase 0 — Repository foundation
10
+
11
+ - [x] Establish product boundaries, design, and decisions.
12
+ - [x] Select the `pi-worker-graph` package name and MIT license.
13
+ - [x] Add package metadata, TypeScript configuration, Biome, and `node:test`
14
+ scripts.
15
+ - [x] Add an inert Pi extension entry point for safe local package loading.
16
+ - [x] Document one command for formatting, linting, typechecking, and tests.
17
+ - [x] Document the tested Pi version when the extension first imports Pi APIs.
18
+ - [x] Select one-shot JSON-mode subprocesses for MVP worker execution.
19
+
20
+ Acceptance:
21
+
22
+ - `npm run check` runs formatting checks, lint, typechecking, and tests.
23
+ - `npm run build` emits the public graph library.
24
+ - Pi can load the local package without registering functional tools.
25
+
26
+ ## Phase 1 — Pure graph domain
27
+
28
+ - [x] Graph types and normalization.
29
+ - [x] Duplicate, missing, empty, and self-edge validation.
30
+ - [x] Cycle detection.
31
+ - [x] Deterministic ready-frontier calculation.
32
+ - [x] Explicit node transitions and completion detection.
33
+ - [x] Failed and aborted dependency blocking.
34
+
35
+ Acceptance tests cover:
36
+
37
+ - empty and single-node graphs;
38
+ - flat, chain, diamond, and multi-frontier graphs;
39
+ - duplicate IDs, unknown dependencies, self-edges, and cycles;
40
+ - invalid concurrency;
41
+ - descendant blocking while unrelated branches continue;
42
+ - deterministic ordering and immutable inputs.
43
+
44
+ ## Phase 2 — Run store
45
+
46
+ The record lifecycle is complete: ownership protects the active graph
47
+ lifecycle, and coordination, retained artifacts, and cleanup are all in place.
48
+ Report and edge-context overflow stay fail-closed rather than truncating into
49
+ an artifact (D19).
50
+
51
+ Implement run-scoped persistence outside the target checkout:
52
+
53
+ - [x] immutable versioned graph definition;
54
+ - [x] parent-owned node and attempt status;
55
+ - [x] immutable node outputs;
56
+ - [x] bounded text artifacts;
57
+ - [x] per-attempt usage accounting, and a run total derived from it;
58
+ - [x] immutable events and directed messages;
59
+ - [x] restrictive permissions and atomic publication;
60
+ - [x] exclusive run ownership for active graph lifecycles;
61
+ - [x] bounded reads with explicit malformed and overflow errors;
62
+ - [x] bounded retained-run count with atomic capacity reservation;
63
+ - [x] deliberate artifact publication through the final-report tool;
64
+ - [x] explicit cleanup of a named run with its capacity slot.
65
+
66
+ Acceptance tests:
67
+
68
+ - concurrent processes publish events without lost records;
69
+ - interrupted temporary writes are ignored safely;
70
+ - malformed records fail visibly without hiding valid records;
71
+ - runs cannot be mixed accidentally;
72
+ - deleting a run releases its capacity slot and readmits work;
73
+ - a run an orchestrator holds is never deleted;
74
+ - task IDs cannot escape their run directory;
75
+ - the default state root is outside the target checkout.
76
+
77
+ ## Phase 3 — Worker execution adapter
78
+
79
+ The transport-independent interface and fake-backed runner are complete. Select
80
+ and implement a Pi transport only after reviewing the applicable Pi APIs.
81
+
82
+ Implement one bounded execution path behind a testable interface:
83
+
84
+ - [x] define a narrow asynchronous execution function;
85
+ - [x] pass working directory, task identity, payload, and direct prerequisites;
86
+ - [x] enforce task, dependency, concurrency, payload, output, context, and time
87
+ limits;
88
+ - [x] propagate abort signals and sanitize thrown executor failures;
89
+ - [x] resolve explicit worker profiles and authentication through Pi;
90
+ - [x] start isolated child contexts in the requested working directory;
91
+ - [x] apply explicit worker tool allowlists;
92
+ - [x] stream bounded redacted progress and capture usage;
93
+ - [x] clean up child process trees through the selected adapter;
94
+ - [x] prevent recursive graph spawning.
95
+
96
+ Transport-independent tests use fake executors and verify:
97
+
98
+ - working directory, task, payload, and prerequisite context propagation;
99
+ - bounded concurrency, output, context, runtime, and cancellation;
100
+ - thrown and malformed executor results become bounded node failures.
101
+
102
+ The selected Pi adapter must additionally verify:
103
+
104
+ - profile and authentication resolution;
105
+ - provider and tool failures become node failures;
106
+ - no child receives graph-spawning capabilities;
107
+ - no child session state is written into the target checkout.
108
+
109
+ ## Phase 4 — DAG execution and edge context
110
+
111
+ Connect the scheduler to worker execution:
112
+
113
+ - [x] run ready nodes up to the configured concurrency limit;
114
+ - [x] persist terminal results before opening the next frontier;
115
+ - [x] pass named direct-prerequisite outputs to downstream execution;
116
+ - [x] block descendants of failed prerequisites;
117
+ - [x] return deterministic aggregate graph and node status;
118
+ - [x] validate the versioned structured worker output contract;
119
+ - [x] serialize canonical named prerequisite-report blocks;
120
+ - [x] return retained artifact references in the parent-facing result.
121
+
122
+ Acceptance tests:
123
+
124
+ - independent nodes overlap in wall-clock time;
125
+ - dependent nodes never start early;
126
+ - each node sees exactly its declared prerequisite outputs;
127
+ - unrelated branches continue after another branch fails;
128
+ - a retained artifact is named in the result but never projected into it;
129
+ - report and prerequisite-context overflow fail the node rather than truncate.
130
+
131
+ ## Phase 5 — Coordination tools
132
+
133
+ Register child-only tools for:
134
+
135
+ - [x] publishing decisions, interfaces, risks, conflicts, handoffs, and progress;
136
+ - [x] querying relevant events with cursors;
137
+ - [x] sending and reading directed messages;
138
+ - [x] submitting a structured final report.
139
+
140
+ Acceptance tests:
141
+
142
+ - workers can exchange a directed message by polling;
143
+ - irrelevant events are not injected automatically;
144
+ - every event retains task and run provenance;
145
+ - oversized entries are rejected explicitly;
146
+ - successful reports satisfy the versioned schema.
147
+
148
+ ## Phase 6 — Orchestrator mode
149
+
150
+ Implement:
151
+
152
+ - [x] explicit on, status, and off commands;
153
+ - [x] operator-only run-store listing, usage, and deletion subcommands;
154
+ - [x] an opt-in startup flag;
155
+ - [x] session setting snapshot and restoration, covering the active tools and an
156
+ optionally configured parent model and thinking level;
157
+ - [x] orchestrator guidance for decomposition, bounded overlap, review, validation,
158
+ and repair delegation;
159
+ - [x] bounded graph progress through tool updates.
160
+
161
+ Acceptance tests:
162
+
163
+ - normal Pi behavior is unchanged while mode is off;
164
+ - entering mode applies configured behavior and removes direct write tools;
165
+ - leaving restores prior settings;
166
+ - session resume restores mode state;
167
+ - child sessions do not enter orchestrator mode.
168
+
169
+ ## Phase 7 — Feedback and recovery
170
+
171
+ - Define attempt and interrupted-run state.
172
+ - Persist child sessions if the selected execution adapter supports resumption.
173
+ - Let the orchestrator issue focused review feedback.
174
+ - Record attempts without losing prior outputs.
175
+ - Add explicit retry and recovery controls.
176
+
177
+ Acceptance tests:
178
+
179
+ - feedback receives the intended prior context;
180
+ - workers see the live shared checkout and intervening events;
181
+ - retries never duplicate a running attempt;
182
+ - recovery distinguishes succeeded, failed, blocked, and interrupted nodes.
183
+
184
+ ## Phase 8 — Package trial and release
185
+
186
+ - [x] Add versioned installation instructions.
187
+ - Run a controlled same-tree exercise with intentional minor overlap.
188
+ - Verify routing with at least two configurable model/provider profiles.
189
+ - Compare duration, conflicts, usage, and review findings with a sequential run.
190
+ - [x] Document limitations and safe operating guidance.
191
+ - [x] Pack and load the production artifact in a provider-free Pi session.
192
+ - Publish a tagged prerelease before a stable release.
193
+
194
+ ## Explicitly deferred
195
+
196
+ - Vector or semantic memory.
197
+ - Cross-machine coordination.
198
+ - A remote broker service.
199
+ - Automatic worktrees or Git mutations.
200
+ - Recursive worker trees.
201
+ - A general-purpose workflow language.
202
+ - Dynamic graph mutation.
203
+ - Live steering between workers.
@@ -0,0 +1,12 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "maxRetainedRuns": 64,
4
+ "profiles": {
5
+ "worker": {
6
+ "provider": "anthropic",
7
+ "model": "claude-haiku-4-5",
8
+ "thinkingLevel": "medium",
9
+ "tools": ["read", "grep", "find", "ls", "bash", "edit", "write"]
10
+ }
11
+ }
12
+ }
@@ -0,0 +1 @@
1
+ export { default } from "../dist/extension.js";
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "..",
5
+ "noEmit": true,
6
+ "declaration": false,
7
+ "declarationMap": false,
8
+ "sourceMap": false
9
+ },
10
+ "include": ["./**/*.ts"]
11
+ }
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "pi-worker-graph",
3
+ "version": "0.1.0-dev.0",
4
+ "description": "A DAG-first worker orchestration runtime for Pi",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/JavePreem/pi-worker-graph.git"
10
+ },
11
+ "keywords": [
12
+ "pi-package",
13
+ "coding-agent",
14
+ "dag",
15
+ "orchestration",
16
+ "workers"
17
+ ],
18
+ "files": [
19
+ "dist",
20
+ "docs",
21
+ "extensions",
22
+ "LICENSE",
23
+ "README.md",
24
+ "SECURITY.md"
25
+ ],
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ }
33
+ },
34
+ "engines": {
35
+ "node": ">=22.19.0"
36
+ },
37
+ "scripts": {
38
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
39
+ "prebuild": "npm run clean",
40
+ "build": "tsc -p tsconfig.json",
41
+ "typecheck": "tsc -p test/tsconfig.json --noEmit",
42
+ "typecheck:extensions": "tsc -p extensions/tsconfig.json",
43
+ "pretest": "node -e \"require('node:fs').rmSync('.test-dist', { recursive: true, force: true })\"",
44
+ "test": "tsc -p test/tsconfig.json && node --test .test-dist/test/*.test.js",
45
+ "format": "biome format --write .",
46
+ "lint": "biome lint .",
47
+ "check": "biome check . && npm run typecheck && npm test",
48
+ "prepack": "npm run check && npm run build && npm run typecheck:extensions"
49
+ },
50
+ "pi": {
51
+ "extensions": [
52
+ "./extensions/index.ts"
53
+ ]
54
+ },
55
+ "peerDependencies": {
56
+ "@earendil-works/pi-coding-agent": "*",
57
+ "typebox": "*"
58
+ },
59
+ "devDependencies": {
60
+ "@biomejs/biome": "2.5.12",
61
+ "@earendil-works/pi-coding-agent": "0.85.1",
62
+ "@types/node": "22.19.19",
63
+ "typebox": "1.3.7",
64
+ "typescript": "5.9.3"
65
+ }
66
+ }