indusagi-coding-agent 0.2.2 → 0.2.4

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 (59) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/entry.js +12434 -9445
  3. package/dist/guardrails.js +897 -37
  4. package/dist/index.js +14081 -11111
  5. package/dist/types/boot/heap.d.ts +31 -0
  6. package/dist/types/boot/runners/delegate-runner.d.ts +27 -1
  7. package/dist/types/boot/runners/server-mode.d.ts +71 -0
  8. package/dist/types/boot/runners/session.d.ts +26 -18
  9. package/dist/types/boot/runners/session.test.d.ts +6 -1
  10. package/dist/types/boot/server-token.d.ts +97 -0
  11. package/dist/types/capability-deck/cards/index.d.ts +1 -0
  12. package/dist/types/capability-deck/cards/task-card.d.ts +26 -2
  13. package/dist/types/capability-deck/cards/workflow-card.d.ts +55 -0
  14. package/dist/types/capability-deck/cards/workflow-card.test.d.ts +12 -0
  15. package/dist/types/capability-deck/contract.d.ts +7 -6
  16. package/dist/types/capability-deck/index.d.ts +1 -1
  17. package/dist/types/conductor/conductor.d.ts +24 -0
  18. package/dist/types/conductor/contract.d.ts +79 -7
  19. package/dist/types/conductor/index.d.ts +3 -3
  20. package/dist/types/conductor/permissions.d.ts +74 -4
  21. package/dist/types/conductor/post-edit-diagnostics.test.d.ts +8 -3
  22. package/dist/types/conductor/quota-error.d.ts +35 -0
  23. package/dist/types/conductor/signal-hub/translate.d.ts +4 -1
  24. package/dist/types/console/auth-status.d.ts +28 -0
  25. package/dist/types/console/components/AgentsView.d.ts +41 -0
  26. package/dist/types/console/components/BackgroundAgents.d.ts +63 -0
  27. package/dist/types/console/components/BackgroundAgents.test.d.ts +8 -0
  28. package/dist/types/console/components/Banner.d.ts +67 -33
  29. package/dist/types/console/components/TerminalConsole.d.ts +0 -5
  30. package/dist/types/console/components/welcome.d.ts +115 -0
  31. package/dist/types/console/components/welcome.test.d.ts +9 -0
  32. package/dist/types/console/contract.d.ts +16 -1
  33. package/dist/types/console/index.d.ts +3 -0
  34. package/dist/types/console/input/index.d.ts +1 -1
  35. package/dist/types/console/input/keymap.d.ts +2 -2
  36. package/dist/types/console/input/paste.d.ts +58 -6
  37. package/dist/types/console/overlays/approval-queue.d.ts +18 -1
  38. package/dist/types/console/overlays/boards.d.ts +55 -0
  39. package/dist/types/console/overlays/index.d.ts +1 -1
  40. package/dist/types/console/theme/adapter.d.ts +1 -1
  41. package/dist/types/console/theme/index.d.ts +1 -1
  42. package/dist/types/console/theme/palette.d.ts +10 -0
  43. package/dist/types/launch/login.d.ts +68 -0
  44. package/dist/types/launch/oauth.test.d.ts +20 -0
  45. package/dist/types/window-budget/summarize/condense.d.ts +6 -0
  46. package/dist/types/workflow-engine/agent-runner.d.ts +124 -0
  47. package/dist/types/workflow-engine/agent-runner.test.d.ts +8 -0
  48. package/dist/types/workflow-engine/display.d.ts +148 -0
  49. package/dist/types/workflow-engine/display.test.d.ts +1 -0
  50. package/dist/types/workflow-engine/engine.d.ts +183 -0
  51. package/dist/types/workflow-engine/engine.test.d.ts +1 -0
  52. package/dist/types/workflow-engine/index.d.ts +21 -0
  53. package/dist/types/workflow-engine/parse.d.ts +64 -0
  54. package/dist/types/workflow-engine/parse.test.d.ts +1 -0
  55. package/dist/types/workflow-engine/structured-output.d.ts +51 -0
  56. package/dist/types/workflow-engine/structured-output.test.d.ts +1 -0
  57. package/dist/types/workspace/brand.d.ts +1 -1
  58. package/package.json +2 -2
  59. package/dist/types/console/components/Emblem.d.ts +0 -49
@@ -0,0 +1,124 @@
1
+ /**
2
+ * createWorkflowAgentRunner — the live {@link WorkflowAgentRunner} that makes the
3
+ * `workflow` tool's `agent()` global spawn real subagents.
4
+ *
5
+ * The pure {@link "./engine"} engine delegates every `agent(prompt, opts)` call
6
+ * to an injected {@link WorkflowAgentRunner}; this module supplies the production
7
+ * implementation. Each subagent run spins a *fresh, isolated* framework
8
+ * {@link Agent} — the same `facade/bot` Agent the conductor and the `task`
9
+ * delegate-runner drive — bound to the parent's model id and credential
10
+ * resolver, given the `'authoring'` capability deck.
11
+ *
12
+ * Two properties matter:
13
+ *
14
+ * 1. **Recursion guard.** The deck is built via `provisionDeck("authoring", …)`,
15
+ * whose profile EXCLUDES the app-novel cards — including the new `workflow`
16
+ * card (registered all-profile-only in {@link "../capability-deck"}). A
17
+ * workflow subagent therefore cannot itself call `workflow` (nor `task`).
18
+ *
19
+ * 2. **Structured output.** When the script passes `opts.schema`, the runner
20
+ * adds the {@link createStructuredOutputTool} `structured_output` tool to the
21
+ * deck and appends the pi "final action MUST be structured_output" contract
22
+ * to the prompt. Because the framework `AgentToolResult` has no `terminate`
23
+ * flag, the tool does NOT end the loop early — the runner instead runs the
24
+ * subagent to completion, then returns `capture.value` (throwing if the
25
+ * subagent never called it). With no schema it returns the final assistant
26
+ * text (the {@link finalAssistantText} pattern, identical to delegate-runner).
27
+ *
28
+ * Cancellation is forwarded: an already-aborted signal short-circuits and an
29
+ * abort raised mid-run calls `agent.abort()`.
30
+ *
31
+ * The model catalog/matcher is built ONCE at create time (the conductor pattern);
32
+ * each `run()` resolves the per-call `opts.model` (falling back to the runner's
33
+ * default `modelId`) against that single matcher. The `spawn` option is a pure
34
+ * test seam — a unit test drives the runner with an in-memory fake instead of a
35
+ * real network round-trip.
36
+ */
37
+ import { type AgentMessage, type SessionPermissionPolicy } from "../conductor";
38
+ import { type AgentTool } from "../capability-deck";
39
+ import { type AgentEvent } from "indusagi/agent";
40
+ import type { WorkflowAgentRunner } from "./engine";
41
+ /**
42
+ * The minimal subagent surface the runner drives.
43
+ *
44
+ * A real framework {@link Agent} satisfies this structurally; a test passes a
45
+ * lightweight fake via {@link WorkflowAgentRunnerOptions.spawn}. Only the pieces
46
+ * the runner touches are named.
47
+ */
48
+ export interface WorkflowSubAgent {
49
+ prompt(input: string): Promise<void>;
50
+ abort(): void;
51
+ /**
52
+ * Subscribe to the framework `Agent` event stream; returns an unsubscribe
53
+ * thunk. Optional on the structural fake — when absent the runner simply skips
54
+ * live activity reporting (the run still completes and returns its result).
55
+ */
56
+ subscribe?(fn: (event: AgentEvent) => void): () => void;
57
+ readonly state: {
58
+ messages: readonly AgentMessage[];
59
+ error?: string;
60
+ usage?: unknown;
61
+ };
62
+ }
63
+ /** The deck of tools handed to a spawned subagent. */
64
+ export interface WorkflowSpawnContext {
65
+ /** The base tools for this run (the `'authoring'` deck, recursion-guarded). */
66
+ readonly tools: AgentTool[];
67
+ /** The resolved system prompt for this subagent. */
68
+ readonly systemPrompt: string;
69
+ }
70
+ /** Configuration for {@link createWorkflowAgentRunner}. */
71
+ export interface WorkflowAgentRunnerOptions {
72
+ /** The default model id a subagent runs under when the script names none. */
73
+ readonly modelId: string;
74
+ /** The working directory the subagent's deck is scoped to. */
75
+ readonly cwd: string;
76
+ /**
77
+ * Per-call credential resolver, forwarded to the framework `Agent` unchanged.
78
+ * Omitted from the agent options entirely when undefined so the framework
79
+ * env-var lookup still wins.
80
+ */
81
+ readonly getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
82
+ /**
83
+ * The base system prompt prepended to every subagent. A sensible default is
84
+ * used when omitted.
85
+ */
86
+ readonly system?: string;
87
+ /**
88
+ * Test seam: build the subagent instead of constructing a real framework
89
+ * `Agent`. When omitted the runner uses `new Agent`.
90
+ */
91
+ readonly spawn?: (prompt: string, context: WorkflowSpawnContext) => WorkflowSubAgent;
92
+ /**
93
+ * Resolve the current server-tier gateway routing map (provider -> gateway
94
+ * base url). Called FRESH on every `run()` — never cached — so a mid-session
95
+ * `/login` (to "Indus Server") is always picked up on the very next subagent
96
+ * call. Mirrors {@link getApiKey}, which is likewise invoked per-request
97
+ * rather than resolved once at construction.
98
+ */
99
+ readonly getGatewayBaseUrls?: () => Promise<Record<string, string>>;
100
+ /**
101
+ * The parent session's live permission policy: the SAME mutable rule list the
102
+ * parent gate reads plus a live getter onto the conductor's current mode. When
103
+ * present, every spawned workflow subagent runs under a RESOLVER-LESS gate
104
+ * built from it — deny/ask rules, plan-mode enforcement, and the
105
+ * catastrophic-bash blocklist apply per inner tool call, and a mid-run mode
106
+ * switch (Shift+Tab) retargets the very next subagent tool call. A subagent
107
+ * cannot prompt, so an `ask` decision deterministically denies. Absent (a bare
108
+ * test construction), the subagent runs ungated as before.
109
+ */
110
+ readonly permissionPolicy?: SessionPermissionPolicy;
111
+ }
112
+ /**
113
+ * Build a live {@link WorkflowAgentRunner} the host wires into the deck context.
114
+ *
115
+ * The model catalog/matcher is built once up front (the conductor pattern); each
116
+ * `run()` resolves `opts.model ?? modelId` against it. A schema request wires the
117
+ * `structured_output` capture tool and the structured contract; a model that does
118
+ * not resolve throws out of `run()` so the engine maps it to an `agent ... failed`
119
+ * log + a `null` branch (the engine's per-branch failure-to-null semantics).
120
+ *
121
+ * @param opts the model id, cwd, credential/system, and optional test seam
122
+ * @returns a runner satisfying the engine's {@link WorkflowAgentRunner} contract
123
+ */
124
+ export declare function createWorkflowAgentRunner(opts: WorkflowAgentRunnerOptions): WorkflowAgentRunner;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * createWorkflowAgentRunner — focused unit tests driven through the `spawn` seam.
3
+ *
4
+ * No model is resolved and no network is touched: each test passes an in-memory
5
+ * fake subagent via `opts.spawn`, so the test exercises the runner's prompt
6
+ * assembly, structured-output capture, final-text extraction, and abort wiring.
7
+ */
8
+ export {};
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Workflow progress snapshot model + text renderer.
3
+ *
4
+ * The engine emits lifecycle callbacks (phase started, agent started/ended,
5
+ * log) which a host folds into a {@link WorkflowSnapshot}. This module owns the
6
+ * snapshot's pure data shape, the two pure recompute helpers, and the
7
+ * `renderWorkflowText` / `renderWorkflowLines` renderers that turn a snapshot
8
+ * into the `◆ Workflow:` progress tree shown live in the tool result.
9
+ *
10
+ * The renderer is a verbatim behavioral port of pi-dynamic-workflows'
11
+ * `src/display.ts` — same `◆ Workflow: name (x/y done)` header, same per-phase
12
+ * `▶/✓` markers with `done/total · running · errors · skipped` counts, same
13
+ * ` #id <glyph> label` subagent rows, same status glyphs
14
+ * (`○ queued`, `● running`, `✓ done`, `✗ error`, `- skipped`), same "Unphased"
15
+ * group, same trailing `log:` lines.
16
+ *
17
+ * Unlike pi, this file carries NO framework-UI bindings (no `ExtensionContext`,
18
+ * no widget display). The card/console wiring that consumes these renderers
19
+ * lands in stage 2; here we expose only the pure snapshot + string surface.
20
+ */
21
+ import type { WorkflowMeta } from "./parse";
22
+ /** Lifecycle status of a single workflow subagent row. */
23
+ export type WorkflowAgentStatus = "queued" | "running" | "done" | "error" | "skipped";
24
+ /** One subagent's row in the live progress tree. */
25
+ export interface WorkflowAgentSnapshot {
26
+ /** 1-based id, the order the agent started in. */
27
+ id: number;
28
+ /** Short human label for the agent (defaulted from phase + index if absent). */
29
+ label: string;
30
+ /** The phase the agent belongs to, if any. */
31
+ phase?: string;
32
+ /** The task prompt the agent was given. */
33
+ prompt: string;
34
+ /** Current lifecycle status. */
35
+ status: WorkflowAgentStatus;
36
+ /** Optional short preview of the agent's result. */
37
+ resultPreview?: string;
38
+ /** Optional error summary when the agent failed or was skipped. */
39
+ error?: string;
40
+ /** Wall-clock ms when the subagent started (for the live elapsed counter). */
41
+ startedAt?: number;
42
+ /** Wall-clock ms when the subagent settled (caps the elapsed counter). */
43
+ endedAt?: number;
44
+ /** Cumulative input tokens the subagent has spent. */
45
+ tokensIn?: number;
46
+ /** Cumulative output tokens the subagent has spent. */
47
+ tokensOut?: number;
48
+ /** How many tool calls the subagent has started. */
49
+ toolCount?: number;
50
+ /** The tool the subagent is running right now, if any. */
51
+ currentTool?: string;
52
+ /** The last tool the subagent finished (when nothing is running). */
53
+ lastTool?: string;
54
+ }
55
+ /** The full live progress model for one workflow run. */
56
+ export interface WorkflowSnapshot {
57
+ /** Workflow name (from `meta.name`). */
58
+ name: string;
59
+ /** Workflow description (from `meta.description`). */
60
+ description?: string;
61
+ /** Declared/observed phase titles, in order. */
62
+ phases: string[];
63
+ /** The phase currently active (last `phase()` call). */
64
+ currentPhase?: string;
65
+ /** Log lines emitted via `log()`. */
66
+ logs: string[];
67
+ /** Every subagent row, in start order. */
68
+ agents: WorkflowAgentSnapshot[];
69
+ /** Total agents seen. */
70
+ agentCount: number;
71
+ /** Agents currently running. */
72
+ runningCount: number;
73
+ /** Agents finished successfully. */
74
+ doneCount: number;
75
+ /** Agents that errored. */
76
+ errorCount: number;
77
+ /** Total run duration once complete. */
78
+ durationMs?: number;
79
+ /** The workflow's final returned value once complete. */
80
+ result?: unknown;
81
+ }
82
+ /** Tunables for the text renderer (how much of the tree to show). */
83
+ export interface WorkflowDisplayOptions {
84
+ /** Max subagent rows shown per phase (most recent kept). Default 8. */
85
+ maxAgents?: number;
86
+ /** Max trailing log lines shown. Default 2. */
87
+ maxLogs?: number;
88
+ /** Append a short result preview to each agent row. Default false. */
89
+ showResultPreviews?: boolean;
90
+ /**
91
+ * Soft cap on total tree lines for the LIVE render. Default 9 — headroom under
92
+ * the framework `TaskPanel` 10-line clamp so a running agent is never cut off
93
+ * by a trailing `…`. Completed phases collapse to one line each, and if the
94
+ * tree is still over budget the OLDEST completed phases collapse into a single
95
+ * `… N earlier phases done` line (running/current phases are never collapsed).
96
+ * Pass a large value (e.g. the settled/final render, or Ctrl+O expand) to show
97
+ * everything in full.
98
+ */
99
+ maxLines?: number;
100
+ }
101
+ /**
102
+ * Build an empty snapshot for a freshly parsed workflow `meta`.
103
+ *
104
+ * @param meta the workflow header
105
+ */
106
+ export declare function createWorkflowSnapshot(meta: WorkflowMeta): WorkflowSnapshot;
107
+ /**
108
+ * Recompute the derived counts (`agentCount`/`runningCount`/`doneCount`/
109
+ * `errorCount`) from the `agents` array. Pure — returns a new snapshot.
110
+ *
111
+ * @param snapshot the snapshot whose counts to refresh
112
+ */
113
+ export declare function recomputeWorkflowSnapshot(snapshot: WorkflowSnapshot): WorkflowSnapshot;
114
+ /**
115
+ * Render the snapshot as the `◆ Workflow:` progress tree (array of lines).
116
+ *
117
+ * The per-agent metrics segment (elapsed seconds, token spend, tool activity) is
118
+ * computed at render time from `now` so the seconds tick on every render even
119
+ * during a long silent tool call. Keep `now` an explicit param so the renderer
120
+ * stays pure and testable.
121
+ *
122
+ * @param snapshot the progress model
123
+ * @param options render tunables
124
+ * @param now the current wall-clock ms used to compute live elapsed seconds
125
+ */
126
+ export declare function renderWorkflowLines(snapshot: WorkflowSnapshot, options?: WorkflowDisplayOptions, now?: number): string[];
127
+ /**
128
+ * Render the snapshot as a single string for the tool result.
129
+ *
130
+ * For the LIVE (not-completed) render the `◆ Workflow:` header already says the
131
+ * run is in progress, so no extra header line is added — this saves a line under
132
+ * the framework `TaskPanel` 10-line clamp. The final (completed) render keeps the
133
+ * explicit `Workflow completed` header.
134
+ *
135
+ * @param snapshot the progress model
136
+ * @param completed whether the run has finished
137
+ * @param options render tunables
138
+ * @param now the current wall-clock ms used to compute live elapsed seconds
139
+ */
140
+ export declare function renderWorkflowText(snapshot: WorkflowSnapshot, completed?: boolean, options?: WorkflowDisplayOptions, now?: number): string;
141
+ /**
142
+ * One-line preview of an arbitrary result value (string passthrough, else
143
+ * JSON), truncated to `max` chars. Used to fill `resultPreview`.
144
+ *
145
+ * @param value the result to preview
146
+ * @param max max preview length
147
+ */
148
+ export declare function preview(value: unknown, max?: number): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,183 @@
1
+ /**
2
+ * runWorkflow — the deterministic workflow orchestration engine.
3
+ *
4
+ * A workflow script is plain JavaScript (parsed by {@link parseWorkflowScript})
5
+ * that orchestrates a fan-out of subagents. The engine evaluates the script's
6
+ * body inside a Node `vm` sandbox seeded with a small, frozen global surface:
7
+ *
8
+ * - `agent(prompt, opts?)` — spawn one subagent, awaitable, returns its
9
+ * result (string, or the validated `opts.schema`
10
+ * object). Runs under a FIFO concurrency limiter.
11
+ * - `parallel(thunks)` — run an array of `() => Promise` thunks and wait
12
+ * for ALL of them (a barrier); results in input
13
+ * order; a failed branch logs and yields `null`.
14
+ * - `pipeline(items, …st)` — run each item through the stages sequentially,
15
+ * while different items proceed independently
16
+ * (NO cross-item barrier); a failed stage logs and
17
+ * yields `null` for that item.
18
+ * - `phase(title)` — open/activate a named progress group.
19
+ * - `log(message)` — append a log line.
20
+ * - `args` — the caller-supplied JSON value.
21
+ * - `budget` — `{ total, spent(), remaining() }` token budget.
22
+ * - `cwd` — the working directory string.
23
+ * - frozen `console` — routed into `log`.
24
+ *
25
+ * The actual subagent spawn is NOT owned here: the engine delegates each
26
+ * `agent()` call to an injected {@link WorkflowAgentRunner} (stage 2 supplies a
27
+ * real one backed by a fresh framework `Agent`; tests pass an in-memory fake).
28
+ * This is the spawn seam that keeps the engine pure and network-free.
29
+ *
30
+ * Behavioral port of pi-dynamic-workflows' `runWorkflow`
31
+ * (pi-dynamic-workflows/src/workflow.ts): same concurrency cap formula, same
32
+ * FIFO limiter, same pending-run tracking + final `Promise.allSettled`, same
33
+ * per-branch failure-to-null semantics, same budget loop, same abort handling,
34
+ * same structured-clone guard on the result, same default agent labels.
35
+ */
36
+ import { type WorkflowMeta } from "./parse";
37
+ /**
38
+ * Live activity metrics for one running subagent.
39
+ *
40
+ * Folded by the {@link WorkflowAgentRunner} from the framework `Agent`'s event
41
+ * stream and forwarded — via {@link WorkflowAgentRunOptions.onActivity} → the
42
+ * engine's {@link WorkflowRunOptions.onAgentActivity} — into that agent's row in
43
+ * the live `◆ Workflow:` progress tree.
44
+ */
45
+ export interface WorkflowAgentActivity {
46
+ /** Cumulative input tokens spent so far. */
47
+ tokensIn: number;
48
+ /** Cumulative output tokens spent so far. */
49
+ tokensOut: number;
50
+ /** How many tool calls the subagent has started. */
51
+ toolCount: number;
52
+ /** The tool the subagent is running right now, if any. */
53
+ currentTool?: string;
54
+ /** The last tool the subagent finished (when nothing is running). */
55
+ lastTool?: string;
56
+ }
57
+ /** Options the engine hands a {@link WorkflowAgentRunner} for one subagent. */
58
+ export interface WorkflowAgentRunOptions {
59
+ /** The resolved, human-readable label for this subagent run. */
60
+ label: string;
61
+ /** The phase this subagent belongs to, if any. */
62
+ phase?: string;
63
+ /**
64
+ * Optional JSON-Schema / TypeBox schema the subagent's result must satisfy.
65
+ * When present the runner returns the validated object; when absent it returns
66
+ * the subagent's final assistant text as a string. Left as `unknown` so the
67
+ * engine stays decoupled from any particular schema library.
68
+ */
69
+ schema?: unknown;
70
+ /** Extra system guidance the engine derived (phase/model/type/isolation). */
71
+ instructions?: string;
72
+ /** Requested model id, if the script passed `opts.model`. */
73
+ model?: string;
74
+ /** Requested subagent profile/type, if the script passed `opts.agentType`. */
75
+ agentType?: string;
76
+ /** Requested isolation mode, if the script passed `opts.isolation`. */
77
+ isolation?: "worktree";
78
+ /** Abort signal forwarded from the workflow run. */
79
+ signal?: AbortSignal;
80
+ /**
81
+ * Called whenever the subagent's live activity changes (a tool starts/ends or
82
+ * a turn settles with token spend). The runner folds this from the framework
83
+ * `Agent` event stream; the engine forwards it to
84
+ * {@link WorkflowRunOptions.onAgentActivity}. Optional — a test fake may omit it.
85
+ */
86
+ onActivity?: (metrics: WorkflowAgentActivity) => void;
87
+ }
88
+ /**
89
+ * The minimal contract the engine needs to spawn a subagent.
90
+ *
91
+ * Stage 2 implements this against a fresh, isolated framework `Agent` (the
92
+ * delegate-runner spawn pattern): resolve the model, build the authoring deck,
93
+ * prompt to completion, then read either the structured-output capture or the
94
+ * final assistant text. Tests implement it with an in-memory fake so the engine
95
+ * can be exercised with no network.
96
+ */
97
+ export interface WorkflowAgentRunner {
98
+ /**
99
+ * Run one subagent task and resolve with its result.
100
+ *
101
+ * @param prompt the task prompt
102
+ * @param options the resolved run options (label, schema, signal, …)
103
+ * @returns the subagent's result — a string, or the validated schema object
104
+ */
105
+ run(prompt: string, options: WorkflowAgentRunOptions): Promise<unknown>;
106
+ }
107
+ /** Per-subagent option bag accepted by the in-sandbox `agent()` global. */
108
+ export interface AgentOptions {
109
+ /** Short unique label for the run (2-5 words); defaulted when absent. */
110
+ label?: string;
111
+ /** Override the phase this agent is attributed to. */
112
+ phase?: string;
113
+ /** Result schema; when present the agent returns the validated object. */
114
+ schema?: unknown;
115
+ /** Requested model id. */
116
+ model?: string;
117
+ /** Requested isolation mode. */
118
+ isolation?: "worktree";
119
+ /** Requested subagent profile/type. */
120
+ agentType?: string;
121
+ }
122
+ /** Options for {@link runWorkflow}. */
123
+ export interface WorkflowRunOptions {
124
+ /** The injected subagent runner (required to actually spawn). */
125
+ agentRunner: WorkflowAgentRunner;
126
+ /** The JSON value exposed to the script as global `args`. */
127
+ args?: unknown;
128
+ /** The working directory exposed to the script as `cwd`/`process.cwd()`. */
129
+ cwd?: string;
130
+ /** Max concurrent subagents; clamped to `[1, 16]`. */
131
+ concurrency?: number;
132
+ /** Optional token budget; `null`/absent means unbounded. */
133
+ tokenBudget?: number | null;
134
+ /** Abort signal — aborts pending and future subagent spawns. */
135
+ signal?: AbortSignal;
136
+ /** Called for each `log()` / console line. */
137
+ onLog?: (message: string) => void;
138
+ /** Called when a new phase is activated. */
139
+ onPhase?: (title: string) => void;
140
+ /** Called just before a subagent starts. */
141
+ onAgentStart?: (event: {
142
+ id: number;
143
+ label: string;
144
+ phase?: string;
145
+ prompt: string;
146
+ }) => void;
147
+ /** Called when a subagent ends (`result === null` means it failed). */
148
+ onAgentEnd?: (event: {
149
+ id: number;
150
+ label: string;
151
+ phase?: string;
152
+ result: unknown;
153
+ }) => void;
154
+ /**
155
+ * Called whenever a running subagent's live activity changes (tool start/end,
156
+ * settled turn token spend). `id` is the 1-based start-order id that matches
157
+ * the `id` on the corresponding {@link onAgentStart} / {@link onAgentEnd} event.
158
+ */
159
+ onAgentActivity?: (id: number, metrics: WorkflowAgentActivity) => void;
160
+ }
161
+ /** The structured result of a completed workflow run. */
162
+ export interface WorkflowRunResult<T = unknown> {
163
+ /** The validated workflow header. */
164
+ meta: WorkflowMeta;
165
+ /** The script's returned value (structured-clone checked). */
166
+ result: T;
167
+ /** All log lines emitted during the run, in order. */
168
+ logs: string[];
169
+ /** All phases observed during the run, in order. */
170
+ phases: string[];
171
+ /** Total subagents spawned. */
172
+ agentCount: number;
173
+ /** Wall-clock duration of the run. */
174
+ durationMs: number;
175
+ }
176
+ /**
177
+ * Parse and run a deterministic workflow script to completion.
178
+ *
179
+ * @param script the raw workflow JavaScript (first statement: `export const meta`)
180
+ * @param options the injected runner plus run configuration / callbacks
181
+ * @returns the meta, the script's returned value, and run telemetry
182
+ */
183
+ export declare function runWorkflow<T = unknown>(script: string, options: WorkflowRunOptions): Promise<WorkflowRunResult<T>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ /**
2
+ * workflow-engine — the pure, network-free orchestration core for the `workflow`
3
+ * dynamic-workflow tool.
4
+ *
5
+ * This barrel exposes the engine subsystem only: the deterministic script
6
+ * parser, the `structured_output` capture tool, the progress snapshot model +
7
+ * text renderer, and the `runWorkflow` engine with its injectable
8
+ * {@link WorkflowAgentRunner} spawn seam. The card and console wiring (the real
9
+ * runner backed by a fresh framework `Agent`, the `tool_update` product signal,
10
+ * and `APP_NOVEL_CARDS` registration) live in stage 2 and consume these exports.
11
+ */
12
+ export type { ParsedWorkflow, WorkflowMeta, WorkflowMetaPhase, } from "./parse";
13
+ export { NONDETERMINISM_ERROR, parseWorkflowScript } from "./parse";
14
+ export type { StructuredOutputCapture, StructuredOutputToolOptions, } from "./structured-output";
15
+ export { createStructuredOutputTool } from "./structured-output";
16
+ export type { WorkflowAgentSnapshot, WorkflowAgentStatus, WorkflowDisplayOptions, WorkflowSnapshot, } from "./display";
17
+ export { createWorkflowSnapshot, preview, recomputeWorkflowSnapshot, renderWorkflowLines, renderWorkflowText, } from "./display";
18
+ export type { AgentOptions, WorkflowAgentActivity, WorkflowAgentRunner, WorkflowAgentRunOptions, WorkflowRunOptions, WorkflowRunResult, } from "./engine";
19
+ export { runWorkflow } from "./engine";
20
+ export type { WorkflowAgentRunnerOptions, WorkflowSubAgent, WorkflowSpawnContext, } from "./agent-runner";
21
+ export { createWorkflowAgentRunner } from "./agent-runner";
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Workflow script parser — extract and validate the leading `meta` export,
3
+ * enforce determinism, and hand back the runnable sandbox body.
4
+ *
5
+ * A workflow script is plain JavaScript whose FIRST statement must be
6
+ * `export const meta = { ... }` (an object literal). This module:
7
+ *
8
+ * 1. locates that leading export with a lexer-free, dependency-free scan,
9
+ * 2. evaluates ONLY the `{ ... }` literal in a frozen, empty Node `vm`
10
+ * sandbox (no globals reachable, so the literal cannot call into
11
+ * anything), capturing the resulting plain object as {@link WorkflowMeta},
12
+ * 3. validates the meta shape (name/description required, optional
13
+ * whenToUse/phases),
14
+ * 4. enforces the determinism guard over the WHOLE script source —
15
+ * `Date.now()`, `Math.random()`, and `new Date()` are rejected so a
16
+ * workflow always produces the same orchestration plan, and
17
+ * 5. strips the `export const meta = …;` statement so the remaining `body`
18
+ * runs as an ordinary async function body inside the engine sandbox.
19
+ *
20
+ * This is a dependency-free port of pi's acorn-based `parseWorkflowScript`
21
+ * (pi-dynamic-workflows/src/workflow.ts). It deliberately does NOT pull in
22
+ * `acorn`: the only thing the engine needs to read out of the source is the
23
+ * leading literal, which a sandboxed `Function`/`vm` evaluation of that one
24
+ * expression handles safely, and the determinism guard is a source string-scan
25
+ * over the call/`new` forms pi's AST walk rejected.
26
+ */
27
+ /** One declared phase in the upfront `meta.phases` outline. */
28
+ export interface WorkflowMetaPhase {
29
+ /** Human title for the phase row. */
30
+ title: string;
31
+ /** Optional one-line elaboration of what the phase does. */
32
+ detail?: string;
33
+ /** Optional model hint the phase prefers (documentation only). */
34
+ model?: string;
35
+ }
36
+ /** The validated `export const meta = { … }` header of a workflow script. */
37
+ export interface WorkflowMeta {
38
+ /** Short snake_case identifier for the workflow. */
39
+ name: string;
40
+ /** Non-empty human description of what the workflow accomplishes. */
41
+ description: string;
42
+ /** Optional guidance on when a model should reach for this workflow. */
43
+ whenToUse?: string;
44
+ /** Optional upfront outline; live progress is still driven by `phase()`. */
45
+ phases?: WorkflowMetaPhase[];
46
+ }
47
+ /** The result of {@link parseWorkflowScript}: validated meta + runnable body. */
48
+ export interface ParsedWorkflow {
49
+ /** The validated workflow header. */
50
+ meta: WorkflowMeta;
51
+ /** The script with the leading `export const meta = …` statement removed. */
52
+ body: string;
53
+ }
54
+ /** Message raised when a script reaches for a non-deterministic primitive. */
55
+ export declare const NONDETERMINISM_ERROR = "Workflow scripts must be deterministic: Date.now()/Math.random()/new Date() are unavailable";
56
+ /**
57
+ * Parse a workflow script into its validated {@link WorkflowMeta} and the
58
+ * runnable `body` (the script with the meta export removed).
59
+ *
60
+ * @param script the raw workflow JavaScript source
61
+ * @throws if the first statement is not `export const meta = {literal}`, if the
62
+ * meta fails validation, or if the source uses a non-deterministic primitive
63
+ */
64
+ export declare function parseWorkflowScript(script: string): ParsedWorkflow;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ /**
2
+ * structured_output — the per-subagent "final answer channel" tool.
3
+ *
4
+ * A workflow subagent that needs to return a machine-readable result is given a
5
+ * tool named `structured_output` whose `parameters` ARE the caller-supplied
6
+ * TypeBox schema. When the subagent calls it, the framework has already
7
+ * validated the arguments against that schema, so `execute` simply records the
8
+ * validated value into a shared {@link StructuredOutputCapture} and returns a
9
+ * normal {@link AgentToolResult}.
10
+ *
11
+ * Difference from pi's version (pi-dynamic-workflows/src/structured-output.ts):
12
+ * the indus-code-rebuild framework `AgentToolResult` has NO `terminate` flag
13
+ * (see {@link "indusagi/agent"} `AgentToolResult`), so this tool does NOT end
14
+ * the subagent's loop early. The stage-2 runner instead runs the subagent to
15
+ * completion and reads `capture.value` afterward. This file is therefore a
16
+ * plain {@link AgentTool} object literal (no `defineTool`, no `terminate`).
17
+ */
18
+ import type { Static, TSchema } from "@sinclair/typebox";
19
+ import type { AgentTool } from "../capability-deck";
20
+ /**
21
+ * Mutable sink the {@link createStructuredOutputTool} tool writes into. The
22
+ * runner constructs one per subagent run, passes it in, and reads `value` after
23
+ * the subagent finishes.
24
+ */
25
+ export interface StructuredOutputCapture<T = unknown> {
26
+ /** The last validated payload the subagent submitted, if any. */
27
+ value: T | undefined;
28
+ /** Whether `structured_output` was ever called during the run. */
29
+ called: boolean;
30
+ }
31
+ /** Options for {@link createStructuredOutputTool}. */
32
+ export interface StructuredOutputToolOptions<TSchemaDef extends TSchema> {
33
+ /** The TypeBox schema the subagent's result must satisfy. */
34
+ schema: TSchemaDef;
35
+ /** The capture sink the validated result is recorded into. */
36
+ capture: StructuredOutputCapture<Static<TSchemaDef>>;
37
+ /** Override the tool name (defaults to `structured_output`). */
38
+ name?: string;
39
+ }
40
+ /**
41
+ * Build the `structured_output` capture tool for one subagent run.
42
+ *
43
+ * The returned tool's `parameters` are exactly `schema`, so the framework
44
+ * validates the subagent's arguments before `execute` runs; `execute` then
45
+ * records them into `capture` and acknowledges. Idempotent in the sense that a
46
+ * second call simply overwrites `capture.value` with the newer payload.
47
+ *
48
+ * @param options the result schema, the capture sink, and an optional name
49
+ * @returns an {@link AgentTool} whose parameters mirror the caller schema
50
+ */
51
+ export declare function createStructuredOutputTool<TSchemaDef extends TSchema>({ schema, capture, name, }: StructuredOutputToolOptions<TSchemaDef>): AgentTool<TSchemaDef, Static<TSchemaDef>>;
@@ -23,4 +23,4 @@ export declare const BRAND: Brand;
23
23
  * Single source of truth: bump this one line per release. Co-located with the
24
24
  * brand so `boot` reads it without importing the index barrel.
25
25
  */
26
- export declare const VERSION = "0.2.0";
26
+ export declare const VERSION = "0.2.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "indusagi-coding-agent",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Indusagi coding agent — a terminal-first AI coding agent, built from scratch on the indusagi framework.",
5
5
  "author": "Varun Israni",
6
6
  "license": "MIT",
@@ -57,7 +57,7 @@
57
57
  "@sinclair/typebox": "^0.34.49",
58
58
  "chalk": "^5.6.2",
59
59
  "highlight.js": "^11.11.1",
60
- "indusagi": "^0.13.1",
60
+ "indusagi": "^0.13.3",
61
61
  "ink": "^5.2.1",
62
62
  "jiti": "^2.7.0",
63
63
  "marked": "^18.0.4",