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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-failure.d.ts","sourceRoot":"","sources":["../src/execution-failure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,MAAM,MAAM,wBAAwB,GAChC,oBAAoB,GACpB,iBAAiB,GACjB,SAAS,GACT,UAAU,GACV,cAAc,GACd,UAAU,GACV,aAAa,GACb,gBAAgB,GAChB,kBAAkB,GAClB,oBAAoB,GACpB,SAAS,CAAC;AAiBd;;;;;;;;;;;GAWG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;IACxC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;gBAGpC,IAAI,EAAE,wBAAwB,EAC9B,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,SAAS;CAUpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAS3E;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CASxE;AAED,6EAA6E;AAC7E,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAO7E"}
@@ -0,0 +1,90 @@
1
+ import { parseTaskUsage } from "./usage.js";
2
+ const FAILURE_DIAGNOSTICS = Object.freeze({
3
+ invalid_assignment: "Worker assignment is invalid",
4
+ invalid_profile: "Worker profile is invalid",
5
+ startup: "Pi worker process failed to start",
6
+ protocol: "Pi worker emitted an invalid event stream",
7
+ output_limit: "Pi worker event stream exceeded its output limit",
8
+ provider: "Pi worker provider request failed",
9
+ report_tool: "Pi worker final-report tool failed",
10
+ missing_report: "Pi worker did not submit a final report",
11
+ report_not_final: "Pi worker kept working after its final report",
12
+ unresolved_command: "Pi worker command could not be resolved",
13
+ process: "Pi worker process failed",
14
+ });
15
+ /**
16
+ * Allowlisted executor failure. Diagnostics come from the fixed table above, so
17
+ * an executor can describe why a task failed without any provider text, tool
18
+ * output, or repository content reaching persisted run state.
19
+ *
20
+ * `taskId` is only set by whole-graph validation, where the failing task is
21
+ * known before any worker starts.
22
+ *
23
+ * `usage` is what the attempt had already spent when it failed. A failed
24
+ * worker is still a worker that consumed tokens, so an executor that accounts
25
+ * for its own spend reports it here rather than losing it with the failure.
26
+ */
27
+ export class TaskExecutionFailure extends Error {
28
+ code;
29
+ diagnostics;
30
+ taskId;
31
+ usage;
32
+ constructor(code, taskId, usage) {
33
+ const diagnostics = FAILURE_DIAGNOSTICS[code];
34
+ super(diagnostics);
35
+ this.name = "TaskExecutionFailure";
36
+ this.code = code;
37
+ this.diagnostics = diagnostics;
38
+ this.taskId = taskId;
39
+ this.usage = usage;
40
+ }
41
+ }
42
+ /**
43
+ * Resolves the allowlisted diagnostics for an executor rejection, or
44
+ * `undefined` when the rejection is not a recognized failure.
45
+ *
46
+ * Third-party executors may be bundled against a separate copy of this module,
47
+ * which defeats `instanceof`. The fallback matches the reported code against
48
+ * the allowlist rather than trusting any caller-supplied text, so a duplicated
49
+ * module cannot widen what reaches run state.
50
+ */
51
+ export function taskExecutionDiagnostics(error) {
52
+ if (error instanceof TaskExecutionFailure)
53
+ return error.diagnostics;
54
+ if (!(error instanceof Error) || error.name !== "TaskExecutionFailure") {
55
+ return undefined;
56
+ }
57
+ const code = error.code;
58
+ return typeof code === "string" && Object.hasOwn(FAILURE_DIAGNOSTICS, code)
59
+ ? FAILURE_DIAGNOSTICS[code]
60
+ : undefined;
61
+ }
62
+ /**
63
+ * Reads the usage an executor attributed to a failed attempt, if any.
64
+ *
65
+ * Validated rather than trusted, and read defensively for the same reason
66
+ * `taskExecutionDiagnostics` is: the rejection may come from a separate copy
67
+ * of this module. Unusable numbers are dropped rather than persisted.
68
+ */
69
+ export function taskExecutionUsage(error) {
70
+ if (!(error instanceof Error) || error.name !== "TaskExecutionFailure") {
71
+ return undefined;
72
+ }
73
+ try {
74
+ return parseTaskUsage(error.usage);
75
+ }
76
+ catch {
77
+ return undefined;
78
+ }
79
+ }
80
+ /** Reads the task attributed to a whole-graph validation failure, if any. */
81
+ export function taskExecutionFailureTaskId(error) {
82
+ if (error instanceof TaskExecutionFailure)
83
+ return error.taskId;
84
+ if (!(error instanceof Error) || error.name !== "TaskExecutionFailure") {
85
+ return undefined;
86
+ }
87
+ const taskId = error.taskId;
88
+ return typeof taskId === "string" ? taskId : undefined;
89
+ }
90
+ //# sourceMappingURL=execution-failure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-failure.js","sourceRoot":"","sources":["../src/execution-failure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAe5C,MAAM,mBAAmB,GACvB,MAAM,CAAC,MAAM,CAAC;IACZ,kBAAkB,EAAE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AC,mBAAmB,CAAC,IAAgC,CAAC;QACvD,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;QACvE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,cAAc,CAAE,KAAsC,CAAC,KAAK,CAAC,CAAC;IACvE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,0BAA0B,CAAC,KAAc;IACvD,IAAI,KAAK,YAAY,oBAAoB;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC;IAC/D,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;QACvE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAI,KAAuC,CAAC,MAAM,CAAC;IAC/D,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACzD,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { type WorkerGraphOrchestratorDependencies } from "./orchestrator.js";
3
+ export declare const WORKER_REPORT_TOOL_NAME = "worker_graph_report";
4
+ export declare const SWARM_COMMAND_NAME = "swarm";
5
+ export declare const SWARM_FLAG_NAME = "swarm";
6
+ /** Pi package entry point with mutually exclusive worker and parent roles. */
7
+ export default function registerWorkerGraph(pi: ExtensionAPI, dependencies?: Partial<WorkerGraphOrchestratorDependencies>): void;
8
+ //# sourceMappingURL=extension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAIlB,MAAM,iCAAiC,CAAC;AAQzC,OAAO,EAGL,KAAK,mCAAmC,EACzC,MAAM,mBAAmB,CAAC;AAsD3B,eAAO,MAAM,uBAAuB,wBAAwB,CAAC;AAC7D,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAC1C,eAAO,MAAM,eAAe,UAAU,CAAC;AAmVvC,8EAA8E;AAC9E,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,EAAE,EAAE,YAAY,EAChB,YAAY,GAAE,OAAO,CAAC,mCAAmC,CAAM,GAC9D,IAAI,CAwZN"}