@agwab/pi-workflow 0.1.1 → 0.1.2

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 (51) hide show
  1. package/README.md +14 -3
  2. package/agents/researcher.md +17 -7
  3. package/dist/artifact-graph-runtime.js +1 -0
  4. package/dist/compiler.js +2 -2
  5. package/dist/dynamic-generated-task-runtime.js +4 -3
  6. package/dist/dynamic-runtime-bundle.js +3 -2
  7. package/dist/extension.js +40 -1
  8. package/dist/subagent-backend.js +82 -27
  9. package/dist/tool-metadata.d.ts +1 -0
  10. package/dist/tool-metadata.js +13 -1
  11. package/dist/workflow-artifact-extension.js +3 -2
  12. package/dist/workflow-artifact-tool.js +84 -4
  13. package/dist/workflow-web-source-extension.d.ts +43 -0
  14. package/dist/workflow-web-source-extension.js +1194 -0
  15. package/dist/workflow-web-source.d.ts +171 -0
  16. package/dist/workflow-web-source.js +897 -0
  17. package/docs/usage.md +32 -18
  18. package/node_modules/@agwab/pi-subagent/package.json +1 -1
  19. package/node_modules/@agwab/pi-subagent/src/api.ts +245 -132
  20. package/node_modules/@agwab/pi-subagent/src/artifacts/result.ts +243 -163
  21. package/node_modules/@agwab/pi-subagent/src/core/constants.ts +117 -90
  22. package/node_modules/@agwab/pi-subagent/src/core/validation.ts +728 -475
  23. package/node_modules/@agwab/pi-subagent/src/orchestrate/run.ts +305 -209
  24. package/node_modules/@agwab/pi-subagent/src/runners/headless-model.ts +750 -439
  25. package/node_modules/@agwab/pi-subagent/src/runners/tmux.ts +422 -268
  26. package/package.json +2 -2
  27. package/skills/workflow-guide/scaffolds/object-tool-fallback/schemas/fetch-control.schema.json +1 -1
  28. package/skills/workflow-guide/scaffolds/object-tool-fallback/spec.json +4 -3
  29. package/src/artifact-graph-runtime.ts +1 -0
  30. package/src/compiler.ts +2 -1
  31. package/src/dynamic-generated-task-runtime.ts +4 -2
  32. package/src/dynamic-runtime-bundle.ts +3 -2
  33. package/src/extension.ts +46 -1
  34. package/src/subagent-backend.ts +121 -37
  35. package/src/tool-metadata.ts +22 -1
  36. package/src/workflow-artifact-extension.ts +3 -2
  37. package/src/workflow-artifact-tool.ts +96 -4
  38. package/src/workflow-web-source-extension.ts +1411 -0
  39. package/src/workflow-web-source.ts +1171 -0
  40. package/workflows/README.md +1 -1
  41. package/workflows/deep-research/helpers/claim-evidence-gate.mjs +474 -40
  42. package/workflows/deep-research/helpers/final-audit-packet.mjs +219 -0
  43. package/workflows/deep-research/helpers/normalize-input-packet.mjs +436 -0
  44. package/workflows/deep-research/helpers/render-executive.mjs +571 -198
  45. package/workflows/deep-research/schemas/deep-research-executive-render-control.schema.json +35 -8
  46. package/workflows/deep-research/schemas/deep-research-normalize-claims-control.schema.json +45 -4
  47. package/workflows/deep-research/schemas/deep-research-verify-claims-control.schema.json +0 -2
  48. package/workflows/deep-research/spec.json +36 -21
  49. package/workflows/deep-review/helpers/render-review-report.mjs +502 -0
  50. package/workflows/deep-review/schemas/deep-review-render-control.schema.json +50 -0
  51. package/workflows/deep-review/spec.json +22 -1
@@ -1,212 +1,292 @@
1
- import type { FailureKind, ResolvedBackend, Status } from "../core/constants.ts";
1
+ import type {
2
+ FailureKind,
3
+ ResolvedBackend,
4
+ Status,
5
+ } from "../core/constants.ts";
2
6
 
3
7
  export const RESULT_SCHEMA_VERSION = 2 as const;
4
- export const ARTIFACT_TYPES = ["result", "stdout", "stderr", "output", "worker", "worktree-status", "worktree-diff", "tool-calls", "tool-calls-summary"] as const;
8
+ export const ARTIFACT_TYPES = [
9
+ "result",
10
+ "stdout",
11
+ "stderr",
12
+ "output",
13
+ "worker",
14
+ "worktree-status",
15
+ "worktree-diff",
16
+ "tool-calls",
17
+ "tool-calls-summary",
18
+ ] as const;
5
19
  export const WORKSPACE_MODES = ["shared", "worktree", "auto"] as const;
6
20
 
7
21
  export type ArtifactType = (typeof ARTIFACT_TYPES)[number];
8
22
  export type WorkspaceMode = (typeof WORKSPACE_MODES)[number];
9
23
 
10
24
  export interface ArtifactRef {
11
- type: ArtifactType;
12
- path: string;
13
- bytes?: number;
25
+ type: ArtifactType;
26
+ path: string;
27
+ bytes?: number;
14
28
  }
15
29
 
16
- export type WorktreeCleanupStatus = "not-needed" | "removed" | "kept" | "failed";
30
+ export type WorktreeCleanupStatus =
31
+ | "not-needed"
32
+ | "removed"
33
+ | "kept"
34
+ | "failed";
17
35
 
18
36
  export interface ResultWorkspace {
19
- mode: WorkspaceMode;
20
- cwd: string;
21
- worktreePath: string | null;
22
- worktreeCleanupStatus?: WorktreeCleanupStatus;
23
- worktreeStatusPath?: string;
24
- worktreeDiffPath?: string;
25
- worktreeCleanupError?: string;
37
+ mode: WorkspaceMode;
38
+ cwd: string;
39
+ worktreePath: string | null;
40
+ worktreeCleanupStatus?: WorktreeCleanupStatus;
41
+ worktreeStatusPath?: string;
42
+ worktreeDiffPath?: string;
43
+ worktreeCleanupError?: string;
26
44
  }
27
45
 
28
46
  export interface ResultSandbox {
29
- enabled: boolean;
30
- /** Network domains allowed inside the sandbox. Absent or empty means deny-all. */
31
- allowedDomains?: string[];
47
+ enabled: boolean;
48
+ /** Network domains allowed inside the sandbox. Absent or empty means deny-all. */
49
+ allowedDomains?: string[];
32
50
  }
33
51
 
34
52
  export interface ResultTmuxMetadata {
35
- sessionName: string;
36
- sessionId: string | null;
37
- paneId: string | null;
53
+ sessionName: string;
54
+ sessionId: string | null;
55
+ paneId: string | null;
38
56
  }
39
57
 
40
58
  export interface CompletionMetadata {
41
- onComplete: string | null;
42
- notified: boolean;
43
- updatesSent: number;
59
+ onComplete: string | null;
60
+ notified: boolean;
61
+ updatesSent: number;
62
+ }
63
+
64
+ export type ResultSessionDisposition =
65
+ | "created"
66
+ | "resumed"
67
+ | "ephemeral"
68
+ | "unavailable";
69
+ export type ResultSessionReason =
70
+ | "session_not_found"
71
+ | "resume_unsupported"
72
+ | "session_store_error";
73
+
74
+ export interface ResultSessionMetadata {
75
+ id?: string;
76
+ requested: boolean;
77
+ disposition: ResultSessionDisposition;
78
+ reason?: ResultSessionReason;
44
79
  }
45
80
 
46
81
  export interface ResultMetadata {
47
- contextLengthExceeded: boolean;
48
- provider?: string;
49
- model?: string;
50
- usage?: unknown;
51
- stopReason?: string;
82
+ contextLengthExceeded: boolean;
83
+ provider?: string;
84
+ model?: string;
85
+ usage?: unknown;
86
+ stopReason?: string;
87
+ parentSessionId?: string;
88
+ sessionId?: string;
89
+ session?: ResultSessionMetadata;
90
+ streamErrors?: string[];
91
+ nonFatalStreamErrors?: string[];
92
+ parseErrors?: string[];
52
93
  }
53
94
 
54
95
  export interface ResultEnvelopeInput {
55
- runId: string;
56
- attemptId: string;
57
- correlationId?: string;
58
- backend: ResolvedBackend;
59
- status: Status;
60
- failureKind?: FailureKind | null;
61
- cwd: string;
62
- startedAt?: string | Date;
63
- completedAt?: string | Date | null;
64
- durationMs?: number | null;
65
- workspace?: Partial<ResultWorkspace> | null;
66
- sandbox?: Partial<ResultSandbox> | null;
67
- exitCode?: number | null;
68
- signal?: string | null;
69
- artifacts?: ArtifactRef[];
70
- tmux?: ResultTmuxMetadata;
71
- completion?: CompletionMetadata;
72
- metadata?: Partial<ResultMetadata> | null;
73
- /** @deprecated v1 compatibility only. */
74
- taskId?: string;
96
+ runId: string;
97
+ attemptId: string;
98
+ correlationId?: string;
99
+ backend: ResolvedBackend;
100
+ status: Status;
101
+ failureKind?: FailureKind | null;
102
+ cwd: string;
103
+ startedAt?: string | Date;
104
+ completedAt?: string | Date | null;
105
+ durationMs?: number | null;
106
+ workspace?: Partial<ResultWorkspace> | null;
107
+ sandbox?: Partial<ResultSandbox> | null;
108
+ exitCode?: number | null;
109
+ signal?: string | null;
110
+ artifacts?: ArtifactRef[];
111
+ tmux?: ResultTmuxMetadata;
112
+ completion?: CompletionMetadata;
113
+ metadata?: Partial<ResultMetadata> | null;
114
+ /** @deprecated v1 compatibility only. */
115
+ taskId?: string;
75
116
  }
76
117
 
77
118
  export interface ResultEnvelope {
78
- schemaVersion: typeof RESULT_SCHEMA_VERSION;
79
- runId: string;
80
- attemptId: string;
81
- correlationId?: string;
82
- backend: ResolvedBackend;
83
- status: Status;
84
- failureKind: FailureKind | null;
85
- cwd: string;
86
- startedAt: string;
87
- completedAt: string | null;
88
- durationMs: number | null;
89
- workspace: ResultWorkspace;
90
- sandbox: ResultSandbox;
91
- exitCode: number | null;
92
- signal: string | null;
93
- artifacts: ArtifactRef[];
94
- metadata: ResultMetadata;
95
- tmux?: ResultTmuxMetadata;
96
- completion?: CompletionMetadata;
97
- /** @deprecated v1 compatibility only. */
98
- taskId?: string;
119
+ schemaVersion: typeof RESULT_SCHEMA_VERSION;
120
+ runId: string;
121
+ attemptId: string;
122
+ correlationId?: string;
123
+ backend: ResolvedBackend;
124
+ status: Status;
125
+ failureKind: FailureKind | null;
126
+ cwd: string;
127
+ startedAt: string;
128
+ completedAt: string | null;
129
+ durationMs: number | null;
130
+ workspace: ResultWorkspace;
131
+ sandbox: ResultSandbox;
132
+ exitCode: number | null;
133
+ signal: string | null;
134
+ artifacts: ArtifactRef[];
135
+ metadata: ResultMetadata;
136
+ tmux?: ResultTmuxMetadata;
137
+ completion?: CompletionMetadata;
138
+ /** @deprecated v1 compatibility only. */
139
+ taskId?: string;
99
140
  }
100
141
 
101
142
  function toIsoTimestamp(value: string | Date, fieldName: string): string {
102
- const date = typeof value === "string" ? new Date(value) : value;
103
- if (Number.isNaN(date.getTime())) {
104
- throw new Error(`${fieldName} must be a valid ISO timestamp or Date.`);
105
- }
106
- return date.toISOString();
143
+ const date = typeof value === "string" ? new Date(value) : value;
144
+ if (Number.isNaN(date.getTime())) {
145
+ throw new Error(`${fieldName} must be a valid ISO timestamp or Date.`);
146
+ }
147
+ return date.toISOString();
107
148
  }
108
149
 
109
- function normalizeDuration(value: number | null | undefined): number | null | undefined {
110
- if (value === undefined) return undefined;
111
- if (value === null) return null;
112
- if (!Number.isFinite(value) || value < 0) {
113
- throw new Error("durationMs must be a non-negative finite number when provided.");
114
- }
115
- return value;
150
+ function normalizeDuration(
151
+ value: number | null | undefined,
152
+ ): number | null | undefined {
153
+ if (value === undefined) return undefined;
154
+ if (value === null) return null;
155
+ if (!Number.isFinite(value) || value < 0) {
156
+ throw new Error(
157
+ "durationMs must be a non-negative finite number when provided.",
158
+ );
159
+ }
160
+ return value;
116
161
  }
117
162
 
118
163
  function normalizeWorkspace(input: ResultEnvelopeInput): ResultWorkspace {
119
- const workspace = input.workspace ?? {};
120
- return {
121
- mode: workspace.mode ?? "shared",
122
- cwd: workspace.cwd ?? input.cwd,
123
- worktreePath: workspace.worktreePath ?? null,
124
- ...(workspace.worktreeCleanupStatus === undefined ? {} : { worktreeCleanupStatus: workspace.worktreeCleanupStatus }),
125
- ...(workspace.worktreeStatusPath === undefined ? {} : { worktreeStatusPath: workspace.worktreeStatusPath }),
126
- ...(workspace.worktreeDiffPath === undefined ? {} : { worktreeDiffPath: workspace.worktreeDiffPath }),
127
- ...(workspace.worktreeCleanupError === undefined ? {} : { worktreeCleanupError: workspace.worktreeCleanupError }),
128
- };
164
+ const workspace = input.workspace ?? {};
165
+ return {
166
+ mode: workspace.mode ?? "shared",
167
+ cwd: workspace.cwd ?? input.cwd,
168
+ worktreePath: workspace.worktreePath ?? null,
169
+ ...(workspace.worktreeCleanupStatus === undefined
170
+ ? {}
171
+ : { worktreeCleanupStatus: workspace.worktreeCleanupStatus }),
172
+ ...(workspace.worktreeStatusPath === undefined
173
+ ? {}
174
+ : { worktreeStatusPath: workspace.worktreeStatusPath }),
175
+ ...(workspace.worktreeDiffPath === undefined
176
+ ? {}
177
+ : { worktreeDiffPath: workspace.worktreeDiffPath }),
178
+ ...(workspace.worktreeCleanupError === undefined
179
+ ? {}
180
+ : { worktreeCleanupError: workspace.worktreeCleanupError }),
181
+ };
129
182
  }
130
183
 
131
184
  function normalizeSandbox(input: ResultEnvelopeInput): ResultSandbox {
132
- if (input.sandbox === undefined || input.sandbox === null) {
133
- return { enabled: false };
134
- }
185
+ if (input.sandbox === undefined || input.sandbox === null) {
186
+ return { enabled: false };
187
+ }
135
188
 
136
- return {
137
- enabled: input.sandbox.enabled ?? true,
138
- ...(input.sandbox.allowedDomains === undefined || input.sandbox.allowedDomains.length === 0 ? {} : { allowedDomains: input.sandbox.allowedDomains }),
139
- };
189
+ return {
190
+ enabled: input.sandbox.enabled ?? true,
191
+ ...(input.sandbox.allowedDomains === undefined ||
192
+ input.sandbox.allowedDomains.length === 0
193
+ ? {}
194
+ : { allowedDomains: input.sandbox.allowedDomains }),
195
+ };
140
196
  }
141
197
 
142
198
  function normalizeMetadata(input: ResultEnvelopeInput): ResultMetadata {
143
- const metadata = input.metadata ?? {};
144
- return {
145
- contextLengthExceeded: metadata.contextLengthExceeded ?? false,
146
- ...(metadata.provider === undefined ? {} : { provider: metadata.provider }),
147
- ...(metadata.model === undefined ? {} : { model: metadata.model }),
148
- ...(metadata.usage === undefined ? {} : { usage: metadata.usage }),
149
- ...(metadata.stopReason === undefined ? {} : { stopReason: metadata.stopReason }),
150
- };
199
+ const metadata = input.metadata ?? {};
200
+ return {
201
+ contextLengthExceeded: metadata.contextLengthExceeded ?? false,
202
+ ...(metadata.provider === undefined ? {} : { provider: metadata.provider }),
203
+ ...(metadata.model === undefined ? {} : { model: metadata.model }),
204
+ ...(metadata.usage === undefined ? {} : { usage: metadata.usage }),
205
+ ...(metadata.stopReason === undefined
206
+ ? {}
207
+ : { stopReason: metadata.stopReason }),
208
+ ...(metadata.parentSessionId === undefined
209
+ ? {}
210
+ : { parentSessionId: metadata.parentSessionId }),
211
+ ...(metadata.sessionId === undefined
212
+ ? {}
213
+ : { sessionId: metadata.sessionId }),
214
+ ...(metadata.session === undefined ? {} : { session: metadata.session }),
215
+ ...(metadata.streamErrors === undefined
216
+ ? {}
217
+ : { streamErrors: metadata.streamErrors }),
218
+ ...(metadata.nonFatalStreamErrors === undefined
219
+ ? {}
220
+ : { nonFatalStreamErrors: metadata.nonFatalStreamErrors }),
221
+ ...(metadata.parseErrors === undefined
222
+ ? {}
223
+ : { parseErrors: metadata.parseErrors }),
224
+ };
151
225
  }
152
226
 
153
227
  function dedupeArtifactRefs(refs: ArtifactRef[]): ArtifactRef[] {
154
- const seen = new Set<string>();
155
- const deduped: ArtifactRef[] = [];
156
-
157
- for (const ref of refs) {
158
- const key = `${ref.type}:${ref.path}`;
159
- if (seen.has(key)) continue;
160
- seen.add(key);
161
- deduped.push(ref);
162
- }
163
-
164
- return deduped;
165
- }
166
-
167
- export function mergeArtifactRefs(...groups: readonly ArtifactRef[][]): ArtifactRef[] {
168
- return dedupeArtifactRefs(groups.flat());
169
- }
170
-
171
- export function createResultEnvelope(input: ResultEnvelopeInput): ResultEnvelope {
172
- const startedAt = toIsoTimestamp(input.startedAt ?? new Date(), "startedAt");
173
- const completedAt =
174
- input.completedAt === undefined
175
- ? input.status === "pending" || input.status === "running"
176
- ? null
177
- : new Date().toISOString()
178
- : input.completedAt === null
179
- ? null
180
- : toIsoTimestamp(input.completedAt, "completedAt");
181
-
182
- const explicitDurationMs = normalizeDuration(input.durationMs);
183
- const durationMs =
184
- explicitDurationMs !== undefined
185
- ? explicitDurationMs
186
- : completedAt === null
187
- ? null
188
- : Math.max(0, Date.parse(completedAt) - Date.parse(startedAt));
189
-
190
- return {
191
- schemaVersion: RESULT_SCHEMA_VERSION,
192
- runId: input.runId,
193
- attemptId: input.attemptId,
194
- ...(input.correlationId === undefined ? {} : { correlationId: input.correlationId }),
195
- backend: input.backend,
196
- status: input.status,
197
- failureKind: input.failureKind ?? null,
198
- cwd: input.cwd,
199
- startedAt,
200
- completedAt,
201
- durationMs,
202
- workspace: normalizeWorkspace(input),
203
- sandbox: normalizeSandbox(input),
204
- exitCode: input.exitCode ?? null,
205
- signal: input.signal ?? null,
206
- artifacts: dedupeArtifactRefs(input.artifacts ?? []),
207
- metadata: normalizeMetadata(input),
208
- ...(input.tmux === undefined ? {} : { tmux: input.tmux }),
209
- ...(input.completion === undefined ? {} : { completion: input.completion }),
210
- ...(input.taskId === undefined ? {} : { taskId: input.taskId }),
211
- };
228
+ const seen = new Set<string>();
229
+ const deduped: ArtifactRef[] = [];
230
+
231
+ for (const ref of refs) {
232
+ const key = `${ref.type}:${ref.path}`;
233
+ if (seen.has(key)) continue;
234
+ seen.add(key);
235
+ deduped.push(ref);
236
+ }
237
+
238
+ return deduped;
239
+ }
240
+
241
+ export function mergeArtifactRefs(
242
+ ...groups: readonly ArtifactRef[][]
243
+ ): ArtifactRef[] {
244
+ return dedupeArtifactRefs(groups.flat());
245
+ }
246
+
247
+ export function createResultEnvelope(
248
+ input: ResultEnvelopeInput,
249
+ ): ResultEnvelope {
250
+ const startedAt = toIsoTimestamp(input.startedAt ?? new Date(), "startedAt");
251
+ const completedAt =
252
+ input.completedAt === undefined
253
+ ? input.status === "pending" || input.status === "running"
254
+ ? null
255
+ : new Date().toISOString()
256
+ : input.completedAt === null
257
+ ? null
258
+ : toIsoTimestamp(input.completedAt, "completedAt");
259
+
260
+ const explicitDurationMs = normalizeDuration(input.durationMs);
261
+ const durationMs =
262
+ explicitDurationMs !== undefined
263
+ ? explicitDurationMs
264
+ : completedAt === null
265
+ ? null
266
+ : Math.max(0, Date.parse(completedAt) - Date.parse(startedAt));
267
+
268
+ return {
269
+ schemaVersion: RESULT_SCHEMA_VERSION,
270
+ runId: input.runId,
271
+ attemptId: input.attemptId,
272
+ ...(input.correlationId === undefined
273
+ ? {}
274
+ : { correlationId: input.correlationId }),
275
+ backend: input.backend,
276
+ status: input.status,
277
+ failureKind: input.failureKind ?? null,
278
+ cwd: input.cwd,
279
+ startedAt,
280
+ completedAt,
281
+ durationMs,
282
+ workspace: normalizeWorkspace(input),
283
+ sandbox: normalizeSandbox(input),
284
+ exitCode: input.exitCode ?? null,
285
+ signal: input.signal ?? null,
286
+ artifacts: dedupeArtifactRefs(input.artifacts ?? []),
287
+ metadata: normalizeMetadata(input),
288
+ ...(input.tmux === undefined ? {} : { tmux: input.tmux }),
289
+ ...(input.completion === undefined ? {} : { completion: input.completion }),
290
+ ...(input.taskId === undefined ? {} : { taskId: input.taskId }),
291
+ };
212
292
  }