@quintinshaw/pi-dynamic-workflows 1.8.0 → 1.9.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.
package/README.md CHANGED
@@ -51,7 +51,8 @@ Press `Esc` to cancel a running run; active subagents are aborted and surfaced a
51
51
  Ask for a background workflow (the model passes `background: true`) and it runs without blocking your session. Manage it with the `/workflows` command:
52
52
 
53
53
  ```text
54
- /workflows # list runs (default)
54
+ /workflows # open the interactive navigator (plain list in print mode)
55
+ /workflows list # force the plain-text list
55
56
  /workflows status <id> # watch a running run live (status bar), prints result when done
56
57
  /workflows stop <id> # abort a running run
57
58
  /workflows pause <id> # pause a running run
@@ -147,7 +148,8 @@ Scripts run inside a Node `vm` sandbox. Intentionally unavailable: `Date.now()`,
147
148
  - **Structured output** — JSON-Schema-validated subagent results
148
149
  - **Real token & cost accounting** — read from each subagent's SDK session (input / output / total / cost), with a character estimate only as fallback when a provider reports no usage; `budget` gates on the real total
149
150
  - **Real per-agent / per-phase model routing** — `opts.model` and `meta.phases[].model` actually select the model (resolved against your authed model registry), with graceful fallback
150
- - **`/workflows` command** — list, inspect, stop, pause, **resume**, and remove background runs; runs started with `background: true` are reachable from the command
151
+ - **`/workflows` interactive navigator** — `/workflows` opens a focused TUI you drill through with the keyboard (runs → phases → agents → agent detail): `↑/↓` (or `j/k`) select, `enter`/`→` open, `esc`/`←` back, `j/k` scroll detail, `p` pause/resume, `x` stop, `s` save, `q` quit. In print/RPC mode it falls back to plain text
152
+ - **Live task panel + background delivery** — while a `background: true` run is going, a "Workflows running" panel sits below the input (focus it and press `enter` to open the navigator); when the run finishes, its result is delivered back into the conversation so your paused task continues
151
153
  - **Bundled `/deep-research` & `/adversarial-review`** — `/deep-research` runs real web searches (via built-in `web_search` / `web_fetch` tools), extracts claims, cross-checks them across sources, and reports only what survived; `/adversarial-review` investigates a task then has independent skeptics try to refute each finding, keeping only those that clear an agreement threshold
152
154
  - **Saved workflows as `/<name>`** — save a run's script with `/workflows save <name>` and it becomes a reusable slash command; arguments are parsed (`key=value` and positionals) and passed through as `args`
153
155
  - **Nested `workflow()`** — call `await workflow('saved-name', args)` inside a script to run a saved workflow inline; nesting is one level deep and shares the parent's concurrency limiter, agent counter, and token budget so the global caps hold
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export { createRunPersistence, generateRunId } from "./run-persistence.js";
20
20
  export { parseCommandArgs, registerAllSavedWorkflows, registerSavedWorkflow, } from "./saved-commands.js";
21
21
  export type { StructuredOutputCapture, StructuredOutputToolOptions } from "./structured-output.js";
22
22
  export { createStructuredOutputTool } from "./structured-output.js";
23
+ export { installResultDelivery, installTaskPanel, type TaskPanelOptions } from "./task-panel.js";
23
24
  export { createWebFetchTool, createWebSearchTool, createWebTools } from "./web-tools.js";
24
25
  export type { AgentOptions, JournalEntry, SharedRuntime, WorkflowMeta, WorkflowMetaPhase, WorkflowRunOptions, WorkflowRunResult, } from "./workflow.js";
25
26
  export { parseWorkflowScript, runWorkflow } from "./workflow.js";
@@ -30,5 +31,6 @@ export type { SavedWorkflow, WorkflowStorage } from "./workflow-saved.js";
30
31
  export { createWorkflowStorage } from "./workflow-saved.js";
31
32
  export type { WorkflowToolInput, WorkflowToolOptions } from "./workflow-tool.js";
32
33
  export { createWorkflowTool } from "./workflow-tool.js";
34
+ export { keyToAction, type NavAction, NavigatorModel, NavigatorState, openWorkflowNavigator, renderNavigator, type ViewKind, } from "./workflow-ui.js";
33
35
  export type { Worktree } from "./worktree.js";
34
36
  export { createWorktree, removeWorktree } from "./worktree.js";
package/dist/index.js CHANGED
@@ -11,10 +11,12 @@ export { buildModelRoutingInstructions, parseModelRoutingFromMeta, resolveModelF
11
11
  export { createRunPersistence, generateRunId } from "./run-persistence.js";
12
12
  export { parseCommandArgs, registerAllSavedWorkflows, registerSavedWorkflow, } from "./saved-commands.js";
13
13
  export { createStructuredOutputTool } from "./structured-output.js";
14
+ export { installResultDelivery, installTaskPanel } from "./task-panel.js";
14
15
  export { createWebFetchTool, createWebSearchTool, createWebTools } from "./web-tools.js";
15
16
  export { parseWorkflowScript, runWorkflow } from "./workflow.js";
16
17
  export { registerWorkflowCommands } from "./workflow-commands.js";
17
18
  export { WorkflowManager } from "./workflow-manager.js";
18
19
  export { createWorkflowStorage } from "./workflow-saved.js";
19
20
  export { createWorkflowTool } from "./workflow-tool.js";
21
+ export { keyToAction, NavigatorModel, NavigatorState, openWorkflowNavigator, renderNavigator, } from "./workflow-ui.js";
20
22
  export { createWorktree, removeWorktree } from "./worktree.js";
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Background-run UX, mirroring Claude Code:
3
+ * - A live task panel below the input lists in-progress runs while you keep working.
4
+ * Focus it (↓) and press enter to open the full navigator.
5
+ * - When a background run finishes, its result is delivered back into the
6
+ * conversation so the paused task continues with the outcome.
7
+ */
8
+ import type { ExtensionAPI, ExtensionUIContext } from "@earendil-works/pi-coding-agent";
9
+ import type { WorkflowManager } from "./workflow-manager.js";
10
+ import type { WorkflowStorage } from "./workflow-saved.js";
11
+ export interface TaskPanelOptions {
12
+ storage?: WorkflowStorage;
13
+ cwd?: string;
14
+ }
15
+ /**
16
+ * Deliver a background run's result into the conversation when it completes or
17
+ * fails. Set up once per extension; idempotent via an internal guard.
18
+ */
19
+ export declare function installResultDelivery(pi: ExtensionAPI, manager: WorkflowManager): void;
20
+ /**
21
+ * Install the live "workflows running" panel below the editor. Re-rendered on
22
+ * every manager event; focus + enter opens the navigator.
23
+ */
24
+ export declare function installTaskPanel(pi: ExtensionAPI, manager: WorkflowManager, ui: ExtensionUIContext, opts?: TaskPanelOptions): void;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Background-run UX, mirroring Claude Code:
3
+ * - A live task panel below the input lists in-progress runs while you keep working.
4
+ * Focus it (↓) and press enter to open the full navigator.
5
+ * - When a background run finishes, its result is delivered back into the
6
+ * conversation so the paused task continues with the outcome.
7
+ */
8
+ import { parseKey } from "@earendil-works/pi-tui";
9
+ import { openWorkflowNavigator } from "./workflow-ui.js";
10
+ const RUN_EVENTS = ["agentStart", "agentEnd", "phase", "log", "complete", "error", "stopped", "paused", "resumed"];
11
+ function deliverText(run) {
12
+ const r = run.result?.result;
13
+ const body = r && typeof r.report === "string" && r.report.trim() ? r.report : JSON.stringify(run.result?.result, null, 2);
14
+ const tokens = run.result?.tokenUsage ? ` · ${run.result.tokenUsage.total.toLocaleString()} tokens` : "";
15
+ const agents = run.result?.agentCount ?? run.snapshot.agentCount;
16
+ return `✓ Workflow "${run.snapshot.name}" finished (${agents} agents${tokens}).\n\n${body}`;
17
+ }
18
+ /**
19
+ * Deliver a background run's result into the conversation when it completes or
20
+ * fails. Set up once per extension; idempotent via an internal guard.
21
+ */
22
+ export function installResultDelivery(pi, manager) {
23
+ if (manager.__deliveryInstalled)
24
+ return;
25
+ manager.__deliveryInstalled = true;
26
+ manager.on("complete", ({ runId }) => {
27
+ const run = manager.getRun(runId);
28
+ if (run)
29
+ void pi.sendMessage({ customType: "workflow-result", content: deliverText(run), display: true });
30
+ });
31
+ manager.on("error", ({ runId, error }) => {
32
+ void pi.sendMessage({
33
+ customType: "workflow-result",
34
+ content: `✗ Workflow ${runId} failed: ${error?.message ?? "unknown error"}`,
35
+ display: true,
36
+ });
37
+ });
38
+ }
39
+ function renderPanel(manager, theme, focused) {
40
+ const active = manager.listRuns().filter((r) => r.status === "running" || r.status === "paused");
41
+ if (!active.length)
42
+ return [];
43
+ const rows = active.map((r) => {
44
+ const live = manager.getRun(r.runId);
45
+ const agents = live?.snapshot.agents ?? r.agents;
46
+ const done = agents.filter((a) => a.status === "done").length;
47
+ const icon = r.status === "paused" ? "⏸" : "◆";
48
+ const phase = live?.snapshot.currentPhase ? ` · ${live.snapshot.currentPhase}` : "";
49
+ return ` ${icon} ${r.workflowName} ${done}/${agents.length} agents${phase}`;
50
+ });
51
+ const hint = focused
52
+ ? theme.fg("accent", " enter: open · esc: back")
53
+ : theme.fg("dim", " ↓ then enter, or /workflows, to open");
54
+ return [theme.bold(`Workflows running (${active.length}):`), ...rows, hint];
55
+ }
56
+ /**
57
+ * Install the live "workflows running" panel below the editor. Re-rendered on
58
+ * every manager event; focus + enter opens the navigator.
59
+ */
60
+ export function installTaskPanel(pi, manager, ui, opts = {}) {
61
+ ui.setWidget("workflow-tasks", (tui, theme) => {
62
+ const onEvent = () => tui.requestRender();
63
+ for (const ev of RUN_EVENTS)
64
+ manager.on(ev, onEvent);
65
+ const comp = {
66
+ focused: false,
67
+ render: () => renderPanel(manager, theme, comp.focused ?? false),
68
+ handleInput: (data) => {
69
+ const key = parseKey(data);
70
+ if (key === "enter" || key === "return" || key === "right") {
71
+ void openWorkflowNavigator(pi, manager, ui, opts);
72
+ }
73
+ },
74
+ invalidate: () => { },
75
+ dispose: () => {
76
+ for (const ev of RUN_EVENTS)
77
+ manager.off(ev, onEvent);
78
+ },
79
+ };
80
+ return comp;
81
+ }, { placement: "belowEditor" });
82
+ }
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { recomputeWorkflowSnapshot, renderWorkflowText } from "./display.js";
6
6
  import { registerSavedWorkflow } from "./saved-commands.js";
7
+ import { openWorkflowNavigator } from "./workflow-ui.js";
7
8
  const STATUS_ICON = {
8
9
  pending: "·",
9
10
  running: "◆",
@@ -110,7 +111,18 @@ export function registerWorkflowCommands(pi, manager, opts = {}) {
110
111
  const id = parts[1];
111
112
  const print = (text) => pi.sendMessage({ customType: "workflows", content: text, display: true });
112
113
  switch (sub) {
114
+ case "ui":
113
115
  case "list": {
116
+ // Interactive navigator when a UI is available; plain text otherwise
117
+ // (print/RPC mode) or when the user explicitly asks for `list`.
118
+ if (sub !== "list" && ctx.hasUI) {
119
+ await openWorkflowNavigator(pi, manager, ctx.ui, { storage: opts.storage, cwd: opts.cwd });
120
+ return;
121
+ }
122
+ if (parts.length === 0 && ctx.hasUI) {
123
+ await openWorkflowNavigator(pi, manager, ctx.ui, { storage: opts.storage, cwd: opts.cwd });
124
+ return;
125
+ }
114
126
  const runs = manager.listRuns();
115
127
  if (!runs.length) {
116
128
  await print("No workflow runs yet. Start one with a background workflow (background: true).");
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Interactive `/workflows` navigator, modeled on Claude Code's view:
3
+ *
4
+ * runs ──enter──▶ phases ──enter──▶ agents ──enter──▶ agent detail
5
+ * ◀──esc─── ◀──esc──── ◀──esc────
6
+ *
7
+ * Keys: ↑/↓ (or j/k) select · enter/→ drill in · esc/← back (esc at top closes)
8
+ * p pause/resume · x stop · r restart · s save · q quit
9
+ *
10
+ * The state machine and line rendering are pure and unit-tested; the pi-tui
11
+ * Component shell (openWorkflowNavigator) wires them to live manager events.
12
+ */
13
+ import type { ExtensionAPI, ExtensionUIContext } from "@earendil-works/pi-coding-agent";
14
+ import type { WorkflowAgentSnapshot } from "./display.js";
15
+ import type { WorkflowManager } from "./workflow-manager.js";
16
+ import type { WorkflowStorage } from "./workflow-saved.js";
17
+ /** Minimal theme surface so rendering is testable without the real Theme class. */
18
+ export interface ThemeLike {
19
+ fg(color: string, text: string): string;
20
+ bold(text: string): string;
21
+ }
22
+ export type ViewKind = "runs" | "phases" | "agents" | "detail";
23
+ interface RunRow {
24
+ runId: string;
25
+ name: string;
26
+ status: string;
27
+ done: number;
28
+ total: number;
29
+ tokens: number;
30
+ }
31
+ interface PhaseRow {
32
+ title: string;
33
+ done: number;
34
+ total: number;
35
+ tokens: number;
36
+ }
37
+ interface AgentRow {
38
+ id: number;
39
+ label: string;
40
+ status: string;
41
+ phase?: string;
42
+ tokens?: number;
43
+ }
44
+ /** Reads run/phase/agent data from the manager, preferring live snapshots. */
45
+ export declare class NavigatorModel {
46
+ private readonly manager;
47
+ constructor(manager: Pick<WorkflowManager, "listRuns" | "getRun">);
48
+ private snapshot;
49
+ runs(): RunRow[];
50
+ runName(runId: string): string;
51
+ runStatus(runId: string): string;
52
+ phases(runId: string): PhaseRow[];
53
+ agents(runId: string, phase: string): AgentRow[];
54
+ agentDetail(runId: string, agentId: number): WorkflowAgentSnapshot | undefined;
55
+ }
56
+ /** Navigation state machine: a stack of (view, cursor) frames plus detail scroll. */
57
+ export declare class NavigatorState {
58
+ private stack;
59
+ scroll: number;
60
+ private top;
61
+ get kind(): ViewKind;
62
+ get cursor(): number;
63
+ get runId(): string | undefined;
64
+ get phase(): string | undefined;
65
+ get agentId(): number | undefined;
66
+ get depth(): number;
67
+ /** Clamp the cursor to [0, count). */
68
+ clamp(count: number): void;
69
+ move(delta: number, count: number): void;
70
+ /** Drill into the selected item. Returns true if the view changed. */
71
+ drill(model: NavigatorModel): boolean;
72
+ /** Pop one level. Returns false when already at the top (caller should close). */
73
+ back(): boolean;
74
+ /** The runId the current view acts on (for pause/stop/save). */
75
+ activeRunId(model: NavigatorModel): string | undefined;
76
+ }
77
+ /** Build the lines for the current view. Pure: depends only on state + model + theme. */
78
+ export declare function renderNavigator(state: NavigatorState, model: NavigatorModel, width: number, theme?: ThemeLike): string[];
79
+ /** What a key press should do. Pure mapping from a parsed key id to an action. */
80
+ export type NavAction = {
81
+ type: "move";
82
+ delta: number;
83
+ } | {
84
+ type: "drill";
85
+ } | {
86
+ type: "back";
87
+ } | {
88
+ type: "close";
89
+ } | {
90
+ type: "pause";
91
+ } | {
92
+ type: "stop";
93
+ } | {
94
+ type: "restart";
95
+ } | {
96
+ type: "save";
97
+ } | {
98
+ type: "none";
99
+ };
100
+ export declare function keyToAction(keyId: string | undefined, kind: ViewKind): NavAction;
101
+ export interface NavigatorOptions {
102
+ storage?: WorkflowStorage;
103
+ cwd?: string;
104
+ }
105
+ /**
106
+ * Open the interactive `/workflows` navigator as a focused overlay. Resolves when
107
+ * the user closes it (esc at the top level, or `q`).
108
+ */
109
+ export declare function openWorkflowNavigator(pi: ExtensionAPI, manager: WorkflowManager, ui: ExtensionUIContext, opts?: NavigatorOptions): Promise<void>;
110
+ export {};