@agwab/pi-workflow 0.2.1 → 0.4.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 (119) hide show
  1. package/README.md +3 -1
  2. package/dist/artifact-graph-runtime.d.ts +1 -1
  3. package/dist/artifact-graph-runtime.js +10 -5
  4. package/dist/artifact-graph-schema.js +127 -5
  5. package/dist/compiler.js +52 -19
  6. package/dist/dynamic-generated-task-runtime.js +3 -1
  7. package/dist/dynamic-profiles.d.ts +1 -1
  8. package/dist/engine-run-graph.d.ts +3 -0
  9. package/dist/engine-run-graph.js +194 -4
  10. package/dist/engine.d.ts +5 -0
  11. package/dist/engine.js +389 -41
  12. package/dist/extension.d.ts +2 -1
  13. package/dist/extension.js +30 -8
  14. package/dist/index.d.ts +11 -3
  15. package/dist/index.js +6 -1
  16. package/dist/prompt-json.d.ts +7 -0
  17. package/dist/prompt-json.js +13 -0
  18. package/dist/roles.d.ts +1 -1
  19. package/dist/roles.js +5 -8
  20. package/dist/store.d.ts +20 -1
  21. package/dist/store.js +139 -35
  22. package/dist/strings.d.ts +11 -0
  23. package/dist/strings.js +24 -0
  24. package/dist/subagent-backend.js +710 -40
  25. package/dist/types.d.ts +107 -1
  26. package/dist/verification-ontology.d.ts +31 -0
  27. package/dist/verification-ontology.js +66 -0
  28. package/dist/workflow-artifact-tool.js +5 -6
  29. package/dist/workflow-artifacts.d.ts +7 -0
  30. package/dist/workflow-artifacts.js +55 -4
  31. package/dist/workflow-fetch-cache-extension.d.ts +1 -0
  32. package/dist/workflow-fetch-cache-extension.js +57 -9
  33. package/dist/workflow-metrics.d.ts +113 -0
  34. package/dist/workflow-metrics.js +272 -0
  35. package/dist/workflow-output-artifacts.js +5 -3
  36. package/dist/workflow-partial-output.d.ts +45 -0
  37. package/dist/workflow-partial-output.js +205 -0
  38. package/dist/workflow-progress-health.js +42 -10
  39. package/dist/workflow-runtime.js +10 -1
  40. package/dist/workflow-view.js +3 -1
  41. package/dist/workflow-web-source-extension.js +194 -52
  42. package/dist/workflow-web-source.d.ts +2 -1
  43. package/dist/workflow-web-source.js +109 -30
  44. package/docs/usage.md +76 -29
  45. package/node_modules/@agwab/pi-subagent/README.md +3 -3
  46. package/node_modules/@agwab/pi-subagent/api.mjs +1 -0
  47. package/node_modules/@agwab/pi-subagent/docs/usage.md +63 -12
  48. package/node_modules/@agwab/pi-subagent/package.json +2 -2
  49. package/node_modules/@agwab/pi-subagent/src/api.ts +54 -1
  50. package/node_modules/@agwab/pi-subagent/src/artifacts/registry.ts +9 -4
  51. package/node_modules/@agwab/pi-subagent/src/artifacts/result.ts +8 -0
  52. package/node_modules/@agwab/pi-subagent/src/core/constants.ts +9 -0
  53. package/node_modules/@agwab/pi-subagent/src/core/validation.ts +21 -0
  54. package/node_modules/@agwab/pi-subagent/src/index.ts +1046 -576
  55. package/node_modules/@agwab/pi-subagent/src/orchestrate/async.ts +279 -156
  56. package/node_modules/@agwab/pi-subagent/src/orchestrate/interrupt.ts +165 -89
  57. package/node_modules/@agwab/pi-subagent/src/orchestrate/reconcile.ts +111 -65
  58. package/node_modules/@agwab/pi-subagent/src/orchestrate/run-ref.ts +219 -0
  59. package/node_modules/@agwab/pi-subagent/src/orchestrate/run.ts +88 -8
  60. package/node_modules/@agwab/pi-subagent/src/orchestrate/status.ts +614 -298
  61. package/node_modules/@agwab/pi-subagent/src/panel.ts +1356 -560
  62. package/node_modules/@agwab/pi-subagent/src/runners/headless-model.ts +53 -5
  63. package/node_modules/@agwab/pi-subagent/src/runners/tmux.ts +13 -6
  64. package/package.json +2 -2
  65. package/skills/workflow-guide/SKILL.md +1 -0
  66. package/src/artifact-graph-runtime.ts +19 -13
  67. package/src/artifact-graph-schema.ts +143 -3
  68. package/src/cli.mjs +52 -0
  69. package/src/compiler.ts +63 -18
  70. package/src/dynamic-generated-task-runtime.ts +3 -1
  71. package/src/dynamic-profiles.ts +1 -1
  72. package/src/engine-run-graph.ts +246 -4
  73. package/src/engine.ts +545 -38
  74. package/src/extension.ts +36 -6
  75. package/src/index.ts +52 -1
  76. package/src/prompt-json.ts +13 -0
  77. package/src/roles.ts +6 -9
  78. package/src/store.ts +194 -42
  79. package/src/strings.ts +38 -0
  80. package/src/subagent-backend.ts +921 -62
  81. package/src/types.ts +116 -2
  82. package/src/verification-ontology.ts +88 -0
  83. package/src/workflow-artifact-tool.ts +5 -7
  84. package/src/workflow-artifacts.ts +83 -3
  85. package/src/workflow-fetch-cache-extension.ts +78 -13
  86. package/src/workflow-metrics.ts +478 -0
  87. package/src/workflow-output-artifacts.ts +5 -3
  88. package/src/workflow-partial-output.ts +299 -0
  89. package/src/workflow-progress-health.ts +47 -15
  90. package/src/workflow-runtime.ts +18 -2
  91. package/src/workflow-view.ts +2 -1
  92. package/src/workflow-web-source-extension.ts +654 -232
  93. package/src/workflow-web-source.ts +153 -39
  94. package/workflows/README.md +7 -25
  95. package/workflows/deep-research/batched-verification.spec.json +253 -0
  96. package/workflows/deep-research/helpers/batch-verification-candidates.mjs +136 -0
  97. package/workflows/deep-research/helpers/claim-evidence-gate.mjs +229 -36
  98. package/workflows/deep-research/helpers/final-audit-packet.mjs +1 -4
  99. package/workflows/deep-research/helpers/normalize-input-packet.mjs +81 -2
  100. package/workflows/deep-research/helpers/render-executive.mjs +40 -26
  101. package/workflows/deep-research/helpers/sanitize-verification-candidates.mjs +89 -15
  102. package/workflows/deep-research/helpers/shadow-select-verification.mjs +229 -0
  103. package/workflows/deep-research/helpers/verification-ontology.mjs +77 -0
  104. package/workflows/deep-research/schemas/deep-research-executive-render-control.schema.json +3 -3
  105. package/workflows/deep-research/schemas/deep-research-research-questions-control.schema.json +38 -0
  106. package/workflows/deep-research/schemas/deep-research-sanitize-claims-control.schema.json +63 -0
  107. package/workflows/deep-research/schemas/deep-research-verify-claims-batch-control.schema.json +47 -0
  108. package/workflows/deep-research/schemas/deep-research-verify-claims-control.schema.json +13 -3
  109. package/workflows/deep-research/spec.json +32 -12
  110. package/workflows/impact-review/spec.json +3 -3
  111. package/workflows/spec-review/helpers/spec-review-pipeline.mjs +1 -8
  112. package/dist/dynamic-loader.d.ts +0 -25
  113. package/dist/dynamic-loader.js +0 -13
  114. package/skills/workflow-guide/scaffolds/dag-required-reads/spec.json.validate.stderr +0 -0
  115. package/skills/workflow-guide/scaffolds/dag-required-reads/spec.json.validate.stdout +0 -13
  116. package/src/dynamic-loader.ts +0 -49
  117. package/workflows/impact-review/schemas/docs-release-impact-control.schema.json +0 -42
  118. package/workflows/impact-review/schemas/security-performance-impact-control.schema.json +0 -42
  119. package/workflows/impact-review/schemas/state-data-impact-control.schema.json +0 -42
@@ -1,10 +1,16 @@
1
1
  import { resolve } from "node:path";
2
2
  import { loadAgentByName, type AgentDefinition } from "./agents.ts";
3
- import type { ResultEnvelope } from "./artifacts/index.ts";
3
+ import {
4
+ appendRunEvent,
5
+ type ResultEnvelope,
6
+ type RunEvent,
7
+ } from "./artifacts/index.ts";
4
8
  import type {
5
9
  ExecutionMode,
10
+ FailureKind,
6
11
  ResolveInput,
7
12
  ResolvedBackend,
13
+ Status,
8
14
  } from "./core/constants.ts";
9
15
  import { resolveBackend } from "./core/resolver.ts";
10
16
  import { validateResolveInput } from "./core/validation.ts";
@@ -22,6 +28,7 @@ import {
22
28
  type ReconcileSubagentRunOptions as ReconcileRunOptions,
23
29
  type ReconcileSubagentRunResult,
24
30
  } from "./orchestrate/reconcile.ts";
31
+ import { resolveRunRef } from "./orchestrate/run-ref.ts";
25
32
  import {
26
33
  runParallelSubagentTasks,
27
34
  runSubagentTask,
@@ -50,6 +57,16 @@ export type WaitForSubagentOptions = WaitForRunOptions;
50
57
  export type InterruptSubagentOptions = InterruptRunOptions;
51
58
  export type ReconcileSubagentOptions = ReconcileRunOptions;
52
59
 
60
+ export interface RecordSubagentChildEventOptions extends RunStatusRef {
61
+ event: "started" | "updated" | "completed" | "failed" | "cancelled";
62
+ childRunId: string;
63
+ workflowRunId?: string;
64
+ childTaskId?: string;
65
+ status?: Status;
66
+ failureKind?: FailureKind | string | null;
67
+ message?: string;
68
+ }
69
+
53
70
  export class SubagentValidationError extends Error {
54
71
  readonly failureKind = "validation" as const;
55
72
  readonly backend?: ResolvedBackend;
@@ -269,6 +286,40 @@ export async function reconcileSubagentRun(
269
286
  return await reconcileRun(options);
270
287
  }
271
288
 
289
+ function defaultChildStatus(
290
+ event: RecordSubagentChildEventOptions["event"],
291
+ ): Status {
292
+ if (event === "started" || event === "updated") return "running";
293
+ if (event === "completed") return "completed";
294
+ if (event === "cancelled") return "cancelled";
295
+ return "failed";
296
+ }
297
+
298
+ export async function recordSubagentChildEvent(
299
+ options: RecordSubagentChildEventOptions,
300
+ ): Promise<RunEvent> {
301
+ const {
302
+ event,
303
+ childRunId,
304
+ workflowRunId,
305
+ childTaskId,
306
+ failureKind,
307
+ message,
308
+ } = options;
309
+ const ref = await resolveRunRef(options);
310
+ return await appendRunEvent(ref, {
311
+ type: `child.${event}`,
312
+ status: options.status ?? defaultChildStatus(event),
313
+ ...(message === undefined ? {} : { message }),
314
+ data: {
315
+ childRunId,
316
+ ...(workflowRunId === undefined ? {} : { workflowRunId }),
317
+ ...(childTaskId === undefined ? {} : { taskId: childTaskId }),
318
+ ...(failureKind === undefined ? {} : { failureKind }),
319
+ },
320
+ });
321
+ }
322
+
272
323
  export type {
273
324
  ArtifactRef,
274
325
  CompletionMetadata,
@@ -294,6 +345,8 @@ export type { InterruptRunResult } from "./orchestrate/interrupt.ts";
294
345
  export type { ReconcileSubagentRunResult } from "./orchestrate/reconcile.ts";
295
346
  export type { ParallelRunResult } from "./orchestrate/run.ts";
296
347
  export type {
348
+ RunChildFailureSummary,
349
+ RunChildSummary,
297
350
  RunLogRef,
298
351
  RunLogsSnapshot,
299
352
  RunStatusRef,
@@ -18,6 +18,11 @@ export type RunEventType =
18
18
  | "run.cancelled"
19
19
  | "run.interrupt_requested"
20
20
  | "run.mark_background"
21
+ | "child.started"
22
+ | "child.updated"
23
+ | "child.completed"
24
+ | "child.failed"
25
+ | "child.cancelled"
21
26
  | "attempt.started"
22
27
  | "attempt.process_started"
23
28
  | "attempt.heartbeat"
@@ -716,11 +721,11 @@ export async function readRunEvents(ref: RunRef, limit = 50): Promise<RunEvent[]
716
721
  const paths = runPaths(ref);
717
722
  try {
718
723
  const text = await readFile(paths.eventsPath, "utf8");
719
- return text
724
+ const lines = text
720
725
  .split(/\r?\n/)
721
- .filter(Boolean)
722
- .slice(-limit)
723
- .map((line) => JSON.parse(line) as RunEvent);
726
+ .filter(Boolean);
727
+ const selected = Number.isFinite(limit) ? lines.slice(-limit) : lines;
728
+ return selected.map((line) => JSON.parse(line) as RunEvent);
724
729
  } catch (error) {
725
730
  if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return [];
726
731
  throw error;
@@ -80,6 +80,7 @@ export interface ResultSessionMetadata {
80
80
 
81
81
  export interface ResultMetadata {
82
82
  contextLengthExceeded: boolean;
83
+ contextOverflowRecovered?: boolean;
83
84
  provider?: string;
84
85
  model?: string;
85
86
  usage?: unknown;
@@ -89,6 +90,7 @@ export interface ResultMetadata {
89
90
  session?: ResultSessionMetadata;
90
91
  streamErrors?: string[];
91
92
  nonFatalStreamErrors?: string[];
93
+ recoveredStreamErrors?: string[];
92
94
  parseErrors?: string[];
93
95
  }
94
96
 
@@ -199,6 +201,9 @@ function normalizeMetadata(input: ResultEnvelopeInput): ResultMetadata {
199
201
  const metadata = input.metadata ?? {};
200
202
  return {
201
203
  contextLengthExceeded: metadata.contextLengthExceeded ?? false,
204
+ ...(metadata.contextOverflowRecovered === undefined
205
+ ? {}
206
+ : { contextOverflowRecovered: metadata.contextOverflowRecovered }),
202
207
  ...(metadata.provider === undefined ? {} : { provider: metadata.provider }),
203
208
  ...(metadata.model === undefined ? {} : { model: metadata.model }),
204
209
  ...(metadata.usage === undefined ? {} : { usage: metadata.usage }),
@@ -218,6 +223,9 @@ function normalizeMetadata(input: ResultEnvelopeInput): ResultMetadata {
218
223
  ...(metadata.nonFatalStreamErrors === undefined
219
224
  ? {}
220
225
  : { nonFatalStreamErrors: metadata.nonFatalStreamErrors }),
226
+ ...(metadata.recoveredStreamErrors === undefined
227
+ ? {}
228
+ : { recoveredStreamErrors: metadata.recoveredStreamErrors }),
221
229
  ...(metadata.parseErrors === undefined
222
230
  ? {}
223
231
  : { parseErrors: metadata.parseErrors }),
@@ -16,6 +16,11 @@ export const FAILURE_KINDS = [
16
16
  "sandbox",
17
17
  "rpc",
18
18
  "model",
19
+ "provider_error",
20
+ "model_error",
21
+ "output_schema_error",
22
+ "guard_failure",
23
+ "user_cancelled",
19
24
  "tool",
20
25
  "exit",
21
26
  "parse",
@@ -109,6 +114,10 @@ export interface ResolveInput {
109
114
  mode?: ExecutionMode;
110
115
  tasks?: SubagentTaskInput[];
111
116
  concurrency?: number;
117
+ /** Stop scheduling additional parallel siblings after the first failed result. */
118
+ failFast?: boolean;
119
+ /** Abort already-running parallel siblings after the first failed result. Implies fail-fast scheduling. */
120
+ cancelSiblingsOnFailure?: boolean;
112
121
  asyncDependency?: AsyncDependency;
113
122
  workspace?: WorkspaceInput | WorkspaceMode;
114
123
  worktree?: boolean | string;
@@ -572,6 +572,27 @@ export function validateResolveInput(
572
572
  input.concurrency = concurrency;
573
573
  }
574
574
 
575
+ if (raw.failFast !== undefined) {
576
+ const failFast = validateBoolean(
577
+ raw.failFast,
578
+ "failFast",
579
+ backendForKnownFailure,
580
+ );
581
+ if (typeof failFast !== "boolean") return failFast;
582
+ input.failFast = failFast;
583
+ }
584
+
585
+ if (raw.cancelSiblingsOnFailure !== undefined) {
586
+ const cancelSiblingsOnFailure = validateBoolean(
587
+ raw.cancelSiblingsOnFailure,
588
+ "cancelSiblingsOnFailure",
589
+ backendForKnownFailure,
590
+ );
591
+ if (typeof cancelSiblingsOnFailure !== "boolean")
592
+ return cancelSiblingsOnFailure;
593
+ input.cancelSiblingsOnFailure = cancelSiblingsOnFailure;
594
+ }
595
+
575
596
  if (raw.chain !== undefined) {
576
597
  return failure(
577
598
  'chain mode is not supported by pi-subagent; use mode:"parallel" for fanout or have the parent orchestrate sequencing.',