@nicknisi/pi-workflows 0.2.0 → 0.2.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.
package/README.md CHANGED
@@ -51,7 +51,7 @@ Names are bare file stems (`research`, not `research.js`, never a path — `..`
51
51
 
52
52
  ## Runs are visible
53
53
 
54
- Every `agent()` call spawns through `@nicknisi/pi-shared`'s subagent runtime with `artifactsDir` set to `~/.pi/agent/subagent-runs/` and namespace `workflows`, so child spawns appear in the `fleet` tool / `/fleet` command from `@nicknisi/pi-subagents`. `status <runId>` and `stop <runId>` here read from / cancel via the same runtime's run records — no parallel store. `stop` cancels in-flight spawns through a live `runId → AbortController` registry (mirroring subagents' cascading-cancellation); a run belonging to a different host process is reported as not cancellable from here.
54
+ Every `agent()` call spawns through `@nicknisi/pi-shared`'s subagent runtime with `artifactsDir` set to `~/.pi/agent/subagent-runs/`, namespace `workflows`, and the owning Pi session recorded. Active children therefore appear in that session's default `fleet` view; settled and machine-wide records remain available through the fleet's explicit `all` scope. `status <runId>` and `stop <runId>` here read from / cancel via the same runtime's run records — no parallel store. `stop` cancels in-flight spawns through a live `runId → AbortController` registry (mirroring subagents' cascading-cancellation); a run belonging to a different host process is reported as not cancellable from here.
55
55
 
56
56
  ## Migration from `@quintinshaw/pi-dynamic-workflows`
57
57
 
package/dist/index.js CHANGED
@@ -53,11 +53,12 @@ function spawnCancellable(cancellables, runtime, opts, externalSignal) {
53
53
  });
54
54
  return Object.assign(done, { runId });
55
55
  }
56
- function makeSpawnFn(cancellables, runtime, cwd, externalSignal) {
56
+ function makeSpawnFn(cancellables, runtime, cwd, ownerSession, externalSignal) {
57
57
  return async (opts) => {
58
58
  const spawnOpts = {
59
59
  prompt: opts.prompt,
60
60
  cwd,
61
+ ...(ownerSession !== undefined ? { ownerSession } : {}),
61
62
  ...(opts.agent !== undefined ? { agent: opts.agent } : {}),
62
63
  ...(opts.model !== undefined ? { model: opts.model } : {}),
63
64
  ...(opts.systemPrompt !== undefined ? { systemPrompt: opts.systemPrompt } : {}),
@@ -367,7 +368,7 @@ export default function workflows(pi) {
367
368
  timedOut = true;
368
369
  controller.abort();
369
370
  }, timeoutMs);
370
- const spawnFn = makeSpawnFn(cancellables, runtime, ctx.cwd, controller.signal);
371
+ const spawnFn = makeSpawnFn(cancellables, runtime, ctx.cwd, ctx.sessionManager.getSessionFile(), controller.signal);
371
372
  const timeoutPromise = new Promise((_, reject) => {
372
373
  controller.signal.addEventListener('abort', () => reject(new Error(timedOut
373
374
  ? `Timed out after ${timeoutMs}ms (in-flight subagents were aborted)`
@@ -472,7 +473,7 @@ async function cmdWf(args, ctx, runtime, cancellables) {
472
473
  }
473
474
  ctx.ui.setStatus('workflows', `running ${name}…`);
474
475
  try {
475
- const spawnFn = makeSpawnFn(cancellables, runtime, ctx.cwd, ctx.signal ?? undefined);
476
+ const spawnFn = makeSpawnFn(cancellables, runtime, ctx.cwd, ctx.sessionManager.getSessionFile(), ctx.signal ?? undefined);
476
477
  const result = await runScript({ script: src, args: parsedArgs, spawn: spawnFn, cwd: ctx.cwd });
477
478
  ctx.ui.notify(formatRunResult(result, name), 'info');
478
479
  }
package/index.ts CHANGED
@@ -88,12 +88,14 @@ function makeSpawnFn(
88
88
  cancellables: Cancellables,
89
89
  runtime: SubagentRuntime,
90
90
  cwd: string,
91
+ ownerSession: string | undefined,
91
92
  externalSignal: AbortSignal | undefined,
92
93
  ): EngineSpawnFn {
93
94
  return async (opts: EngineSpawnOptions): Promise<EngineSpawnResult> => {
94
95
  const spawnOpts: SpawnOptions = {
95
96
  prompt: opts.prompt,
96
97
  cwd,
98
+ ...(ownerSession !== undefined ? { ownerSession } : {}),
97
99
  ...(opts.agent !== undefined ? { agent: opts.agent } : {}),
98
100
  ...(opts.model !== undefined ? { model: opts.model } : {}),
99
101
  ...(opts.systemPrompt !== undefined ? { systemPrompt: opts.systemPrompt } : {}),
@@ -412,7 +414,13 @@ export default function workflows(pi: ExtensionAPI): void {
412
414
  timedOut = true;
413
415
  controller.abort();
414
416
  }, timeoutMs);
415
- const spawnFn = makeSpawnFn(cancellables, runtime, ctx.cwd, controller.signal);
417
+ const spawnFn = makeSpawnFn(
418
+ cancellables,
419
+ runtime,
420
+ ctx.cwd,
421
+ ctx.sessionManager.getSessionFile(),
422
+ controller.signal,
423
+ );
416
424
  const timeoutPromise = new Promise<never>((_, reject) => {
417
425
  controller.signal.addEventListener(
418
426
  'abort',
@@ -531,7 +539,13 @@ async function cmdWf(
531
539
  }
532
540
  ctx.ui.setStatus('workflows', `running ${name}…`);
533
541
  try {
534
- const spawnFn = makeSpawnFn(cancellables, runtime, ctx.cwd, ctx.signal ?? undefined);
542
+ const spawnFn = makeSpawnFn(
543
+ cancellables,
544
+ runtime,
545
+ ctx.cwd,
546
+ ctx.sessionManager.getSessionFile(),
547
+ ctx.signal ?? undefined,
548
+ );
535
549
  const result = await runScript({ script: src, args: parsedArgs, spawn: spawnFn, cwd: ctx.cwd });
536
550
  ctx.ui.notify(formatRunResult(result, name), 'info');
537
551
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicknisi/pi-workflows",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Model-facing front door to the first-party workflow engine — run JS workflow scripts over the subagent runtime, replacing the third-party @quintinshaw/pi-dynamic-workflows extension",
5
5
  "keywords": [
6
6
  "pi",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "typebox": "^1.1.0",
31
- "@nicknisi/pi-shared": "0.4.0"
31
+ "@nicknisi/pi-shared": "0.5.1"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@earendil-works/pi-coding-agent": "*"