Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
edc0fcd
build: import Markdown files as text
edwinyjlim Nov 10, 2026
217e141
feat(programs): bundle each orchestrator flow's agent prompts
edwinyjlim Nov 10, 2026
f3d1d0b
Merge branch 'dag/3-queue-from-frontmatter' into dag/4-prompts-in-wizard
edwinyjlim Nov 12, 2026
2a20dcc
docs(orchestrator): say which property tells a run's path
edwinyjlim Nov 12, 2026
3d99e33
Merge branch 'dag/3-queue-from-frontmatter' into dag/4-prompts-in-wizard
edwinyjlim Nov 12, 2026
cb8a965
fix(scripts): write the task graph page into a folder made for the run
edwinyjlim Nov 12, 2026
d4897c6
Merge branch 'dag/3-queue-from-frontmatter' into dag/4-prompts-in-wizard
edwinyjlim Nov 13, 2026
961f530
Merge branch 'dag/3-queue-from-frontmatter' into dag/4-prompts-in-wizard
edwinyjlim Nov 13, 2026
4729878
Merge branch 'dag/3-queue-from-frontmatter' into dag/4-prompts-in-wizard
edwinyjlim Nov 13, 2026
8b5ecba
fix(orchestrator): say to update the wizard when the menu dropped a s…
edwinyjlim Nov 13, 2026
4c3db67
Merge branch 'dag/3-queue-from-frontmatter' into dag/4-prompts-in-wizard
edwinyjlim Nov 13, 2026
4db2e81
Merge branch 'dag/3-queue-from-frontmatter' into dag/4-prompts-in-wizard
edwinyjlim Nov 13, 2026
910da28
fix(orchestrator): fetch when the bundle fails to load, and give a mi…
edwinyjlim Nov 13, 2026
5deca9f
test(programs): check every bundled prompt opens with frontmatter and…
edwinyjlim Nov 13, 2026
a2345b1
fix(scripts): draw the sink and wizard-queued tasks where the orchest…
edwinyjlim Nov 13, 2026
027031f
Merge branch 'dag/3-queue-from-frontmatter' into dag/4-prompts-in-wizard
edwinyjlim Nov 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .claude/skills/adding-skill-program/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ changing execution behavior.
`agentFlow` when its context-mill flow differs from `id`; setting it
explicitly also documents the content dependency. Keep a `run` definition so
`runProgram` executes agent work.
2. Supply the flow's seed and task prompts in context-mill, including the task
dependencies and applicable skill variants. The
2. Write the flow's task prompts in the program's `agent/` folder, one
`<type>.md` per task with its `dependsOn` and applicable skills, import them
in `agent-prompts.ts`, and set the config's `agentPrompts`; see
[agent prompts](../../../src/programs/README.md#agent-prompts). With
`wizard-agent-dag` on, the
[orchestrator](../../../src/agent/runner/sequence/orchestrator/orchestrator-runner.ts)
loads `agentFlow ?? id`, requires a seed prompt, and checks task-skill
variants before running. `run.skillId` alone does not define this flow.
reads them, queues a folder with no seed prompt from its frontmatter, and
checks task-skill variants before running. With the flag off it loads
`agentFlow ?? id` from context-mill, which must supply the same prompts and
a seed prompt. `run.skillId` alone does not define this flow.
3. Register the config: import it as
`import { config as <name> } from '@programs/<id>'` in
[program-registry.ts](../../../src/programs/program-runner/program-registry.ts) and add it
Expand Down
3 changes: 2 additions & 1 deletion .claude/skills/wizard-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ infrastructure should consume those boundaries.
| Concern | Owner |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Framework detection, context, env conventions | [FrameworkConfig](../../../src/programs/program-contract/framework-config.ts) and [framework configs](../../../src/services/frameworks/) |
| Integration instructions and orchestrator flows/tasks | [context-mill](https://github.com/PostHog/context-mill) |
| Integration instructions (skills) | [context-mill](https://github.com/PostHog/context-mill) |
| Orchestrator task graphs and task prompts | Each program's `agent/` folder when `wizard-agent-dag` is on, context-mill's copy of the flow otherwise; see [agent prompts](../../../src/programs/README.md#agent-prompts) |
| Programs: detection, runs, prerequisites and outcomes | One folder per program in [programs](../../../src/programs/), entered through its `index.ts` |
| Tools: commands that run no agent | [tools](../../../src/tools/), entered through `@tools`, with their screens in [TUI tools](../../../src/tui/tools/) |
| Program screens, flows and decks | [TUI programs](../../../src/tui/programs/) |
Expand Down
1 change: 1 addition & 0 deletions docs/error-catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ screen, debug log) keep the full detail.
| `PHW_AGENT_ORCHESTRATOR_TASKS_BLOCKED` | agent | orchestrator queue drained with blocked tasks that never ran, none failed | case-by-case |
| `PHW_AGENT_ORCHESTRATOR_SINK_INVARIANT` | agent | orchestrator plan violates sink coverage invariant | no |
| `PHW_AGENT_ORCHESTRATOR_TASK_GRAPH` | agent | orchestrator could not queue the graph a flow's frontmatter declares | no |
| `PHW_AGENT_ORCHESTRATOR_NO_PLANNER` | agent | the flow the orchestrator fetched has no planner prompt | no |
| `PHW_SETTINGS_UNFIXABLE_CONFLICT` | settings | Claude settings conflict that cannot be auto-neutralized (managed/unwritable) | no |
| `PHW_INTERNAL_UNHANDLED` | internal | catch-all: an unexpected error escaped the pipeline | yes |
| `PHW_GATEWAY_MINT_REFUSED` | gateway | the gateway-token mint refused this run (blocked, throttled, unlisted program); the server's reason is shown | no |
Expand Down
8 changes: 7 additions & 1 deletion e2e-harness/serve-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ export function startServeHost(opts: {
};
const capture = captureTui({
cmd: path.join(process.cwd(), 'node_modules/.bin/tsx'),
args: ['--tsconfig', 'tsconfig.base.json', 'scripts/tui-host.no-jest.ts'],
args: [
'--tsconfig',
'tsconfig.base.json',
'--import',
'./scripts/markdown-loader.no-jest.mjs',
'scripts/tui-host.no-jest.ts',
],
cwd: process.cwd(),
env,
cols: opts.cols,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"test:coverage": "pnpm build && vitest run --coverage",
"test:e2e": "pnpm build && ./e2e-tests/run.sh",
"test:e2e-record": "export RECORD_FIXTURES=true && pnpm build && ./e2e-tests/run.sh",
"try": "tsx --tsconfig tsconfig.base.json bin.ts",
"try": "tsx --tsconfig tsconfig.base.json --import ./scripts/markdown-loader.no-jest.mjs bin.ts",
"dev": "pnpm build && pnpm link --global && pnpm build:watch",
"test:watch": "vitest",
"prepare": "husky",
Expand All @@ -160,7 +160,8 @@
"wizard-ci-record": "tsx scripts/tui-record.no-jest.ts",
"decisions-detect": "tsx scripts/decisions-detect.no-jest.ts",
"check:decisions-bundle": "tsx scripts/check-decisions-bundle.no-jest.ts",
"record:context-mill-fixtures": "tsx scripts/record-context-mill-fixtures.no-jest.ts"
"record:context-mill-fixtures": "tsx scripts/record-context-mill-fixtures.no-jest.ts",
"visual-dags": "tsx scripts/visual-dags.no-jest.ts"
},
"lint-staged": {
".claude/settings.json": "sh -c 'printf \"\\n\\033[31mDo not commit .claude/settings.json — use .claude/settings.local.json (gitignored).\\nUnstage with: git restore --staged .claude/settings.json\\033[0m\\n\\n\" >&2 && exit 1'",
Expand Down
6 changes: 5 additions & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ are **manual, runnable tools** for headless e2e + snapshots — each is a
standalone `tsx` entry, named `*.no-jest.ts` so Vitest ignores it
(`vitest.config.ts` excludes `**/*.no-jest.*`).

Run from the repo root, e.g. `npx tsx scripts/<name>.no-jest.ts`.
Run from the repo root, e.g. `npx tsx scripts/<name>.no-jest.ts`. A script that
runs a program from source passes
`--import ./scripts/markdown-loader.no-jest.mjs` to `tsx`, so the program's
`agent/<type>.md` imports load as text.

Both e2e routes share one primitive: the **real TUI host** runs `runTui` (the
real ink render) and is driven purely by store state manipulation; a PTY parent
Expand All @@ -22,6 +25,7 @@ real ink render) and is driven purely by store state manipulation; a PTY parent
| **`tui-snapshots.no-jest.ts`** | Runs the fixed host and saves colored `SNAP_OUT/NN-<screen>.ans` frames, including within-screen progress. | `SNAP_OUT`, `APP_DIR`, `PROJECT_ID`, `POSTHOG_KEY_FILE` or `POSTHOG_PERSONAL_API_KEY` |
| **`wizard-ci-mcp.no-jest.ts`** | Stdio MCP server: `open_app`, `read_state`, `perform_action`, `render_screen`, `run_agent`. Screen output is plain text. | Spawns the host; `open_app` requires `appDir` and `projectId`, with optional `keyFile`, `apiKey`, `region` |
| **`chunk-manifest.no-jest.ts`** | Prints a structural manifest of `dist/`: per chunk, the source files it contains and the chunks it imports, hash suffixes stripped. `--summary` prints chunk names plus the sorted source set. A reading tool, nothing diffs its output. | A built `dist/` |
| **`visual-dags.no-jest.ts`** | `pnpm visual-dags`: draws every program's task graph from its `agent/` prompts' frontmatter, as the waves the orchestrator runs, and opens the page. `NO_OPEN=1` only writes it. | Nothing |
| **`wizard-ci-explore.no-jest.ts`** | `pnpm wizard-ci-explore`: opens an app, confirms setup, reads state, prints one frame, and exits. It does not run the agent. | `APP_DIR`, `PROJECT_ID`; optional `POSTHOG_KEY_FILE` |

> You usually don't call these directly — `pnpm wizard-ci-snapshots` (in
Expand Down
14 changes: 14 additions & 0 deletions scripts/markdown-hooks.no-jest.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// The load hook markdown-loader.no-jest.mjs registers: a `.md` module exports the file's text.
import { readFile } from 'node:fs/promises';

export async function load(url, context, nextLoad) {
if (!url.startsWith('file:') || !new URL(url).pathname.endsWith('.md')) {
return nextLoad(url, context);
}
const text = await readFile(new URL(url), 'utf8');
return {
format: 'module',
source: `export default ${JSON.stringify(text)};`,
shortCircuit: true,
};
}
4 changes: 4 additions & 0 deletions scripts/markdown-loader.no-jest.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// A run from source (`pnpm try`, the TUI host) loads each `.md` import as the file's text, as the build does.
import { register } from 'node:module';

register('./markdown-hooks.no-jest.mjs', import.meta.url);
8 changes: 7 additions & 1 deletion scripts/tui-snapshots.no-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ for (const k of Object.keys(env))

const cap = captureTui({
cmd: path.join(process.cwd(), 'node_modules/.bin/tsx'),
args: ['--tsconfig', 'tsconfig.base.json', 'scripts/tui-host.no-jest.ts'],
args: [
'--tsconfig',
'tsconfig.base.json',
'--import',
'./scripts/markdown-loader.no-jest.mjs',
'scripts/tui-host.no-jest.ts',
],
cwd: process.cwd(),
env,
});
Expand Down
208 changes: 208 additions & 0 deletions scripts/visual-dags.no-jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/** Draws each program's task graph from its agent prompts' frontmatter, as the waves the orchestrator runs; see scripts/README.md. */

import fs from 'fs';
import os from 'os';
import path from 'path';
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';

const PROGRAMS_DIR = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'..',
'src',
'programs',
);
/** A folder made for this run, so the page is never written to a path that already exists. */
const OUT_PATH = path.join(
fs.mkdtempSync(path.join(os.tmpdir(), 'wizard-agent-dags-')),
'wizard-agent-dags.html',
);

type Task = {
id: string;
label: string;
seed: boolean;
sink: boolean;
runnerSeeded: boolean;
dependsOn: string[];
model: string;
effort: string;
};

/** The frontmatter's scalars and inline lists, which is all a prompt declares. */
function frontmatter(text: string): Record<string, string> {
const block = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)?.[1] ?? '';
const fields: Record<string, string> = {};
for (const line of block.split(/\r?\n/)) {
const field = /^([\w-]+):\s*(.*)$/.exec(line.replace(/\s+#.*$/, ''));
if (field) fields[field[1]] = field[2].replace(/^['"]|['"]$/g, '');
}
return fields;
}

const list = (value = ''): string[] =>
value
.replace(/^\[|\]$/g, '')
.split(',')
.map((item) => item.trim())
.filter(Boolean);

/** Every program's tasks, read from its `agent/` folder. */
function loadPrograms(): Map<string, Task[]> {
const programs = new Map<string, Task[]>();
for (const program of fs.readdirSync(PROGRAMS_DIR).sort()) {
const dir = path.join(PROGRAMS_DIR, program, 'agent');
if (!fs.existsSync(dir)) continue;
const files = fs.readdirSync(dir).filter((file) => file.endsWith('.md'));
programs.set(
program,
files.sort().map((file) => {
const fields = frontmatter(
fs.readFileSync(path.join(dir, file), 'utf8'),
);
const id = fields.type || file.replace(/\.md$/, '');
return {
id,
label: fields.label || id,
seed: fields.seed === 'true',
sink: fields.sink === 'true',
runnerSeeded: fields.runnerSeeded === 'true',
dependsOn: list(fields.dependsOn),
model: (fields.model_pi ?? '').replace(/^.*\//, '') || '—',
effort: fields.effort_pi || '—',
};
}),
);
}
return programs;
}

/** A task the wizard queues itself that names no dependency: it runs after every task but the sink. */
const runsAfterTheRest = (task: Task): boolean =>
task.runnerSeeded && task.dependsOn.length === 0;

/** Tasks grouped by wave: one past a task's deepest dependency, then the tasks that wait for the rest, then the sink. */
function wavesOf(tasks: Task[]): Task[][] {
const drawn = tasks.filter((task) => !task.seed);
const byId = new Map(
drawn.filter((task) => !task.sink).map((task) => [task.id, task]),
);
const depth = new Map<string, number>();
const depthOf = (id: string): number => {
const known = depth.get(id);
if (known !== undefined) return known;
depth.set(id, 0); // guards a cycle from recursing forever
const deps = (byId.get(id)?.dependsOn ?? []).filter((dep) => byId.has(dep));
const own = deps.length ? 1 + Math.max(...deps.map(depthOf)) : 0;
depth.set(id, own);
return own;
};
const waves: Task[][] = [];
for (const task of byId.values()) {
if (!runsAfterTheRest(task)) (waves[depthOf(task.id)] ??= []).push(task);
}
return [
...waves,
drawn.filter((task) => !task.sink && runsAfterTheRest(task)),
drawn.filter((task) => task.sink),
].filter((wave) => wave?.length);
}
Comment thread
edwinyjlim marked this conversation as resolved.
Resolved

const escape = (text: string): string =>
text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');

/** What a task waits for, in words: the sink and a task that names nothing wait for more than they declare. */
function waitsFor(task: Task): string {
if (task.sink) return 'last, after every other task';
if (runsAfterTheRest(task)) return 'queued by the wizard, after the rest';
return task.dependsOn.length ? `after ${task.dependsOn.join(', ')}` : '';
}

const card = (task: Task): string => `
<div class="task${task.seed ? ' seed' : ''}">
<div class="name">${escape(task.label)}</div>
<div class="meta">${escape(task.model)} · ${escape(task.effort)}</div>
${
waitsFor(task)
? `<div class="deps">${escape(waitsFor(task))}</div>`
: ''
}
</div>`;

function sectionFor(program: string, tasks: Task[]): string {
const seed = tasks.find((task) => task.seed);
const waves = wavesOf(tasks);
const rows: string[] = [];
rows.push(
seed
? `<div class="wave"><div class="label">seed — plans the graph</div>
<div class="tasks">${card(seed)}</div></div>`
: `<div class="note">No planner: the wizard queues this graph from the frontmatter.</div>`,
);
if (seed) rows.push('<div class="arrow">↓</div>');
waves.forEach((wave, index) => {
const label = wave.length > 1 ? `${wave.length} run in parallel` : '1 task';
rows.push(`<div class="wave"><div class="label">${label}</div>
<div class="tasks">${wave.map(card).join('')}</div></div>`);
if (index < waves.length - 1) rows.push('<div class="arrow">↓</div>');
});
return `<section>
<h2>${escape(program)} <span>${tasks.length} agents · ${
waves.length
} waves</span></h2>
${rows.join('\n ')}
</section>`;
}

function render(programs: Map<string, Task[]>): string {
const sections = [...programs.entries()]
.map(([program, tasks]) => sectionFor(program, tasks))
.join('\n');
return `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Agent DAGs</title>
<style>
body { font: 15px/1.5 -apple-system, system-ui, sans-serif; margin: 2rem auto; max-width: 56rem;
color: #1d1d1f; background: #fff; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; border-bottom: 1px solid #e5e5e5; padding-bottom: .4rem; }
h2 span { font-weight: 400; color: #86868b; font-size: .85rem; }
.wave { border: 1px solid #d8d8d8; border-radius: 10px; padding: .6rem .9rem 1rem; background: #fafafa; }
.wave > .label { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
color: #86868b; margin-bottom: .6rem; }
.note { color: #6e6e73; font-size: .85rem; margin-bottom: .6rem; }
.tasks { display: flex; flex-wrap: wrap; gap: .75rem; }
.task { flex: 1 1 13rem; border: 1px solid #d8d8d8; border-radius: 8px; padding: .7rem .8rem;
background: #fff; }
.task.seed { background: #fdf2e9; border-color: #e8a33d; }
.task .name { font-weight: 600; }
.task .meta { color: #6e6e73; font-size: .8rem; margin-top: .15rem; }
.task .deps { color: #86868b; font-size: .75rem; margin-top: .3rem; }
.arrow { text-align: center; color: #b0b0b0; font-size: 1.1rem; margin: .35rem 0; }
</style>
</head>
<body>
<h1>Agent DAGs</h1>
${sections}
</body>
</html>
`;
}

const programs = loadPrograms();
fs.writeFileSync(OUT_PATH, render(programs));
Comment thread
edwinyjlim marked this conversation as resolved.
Resolved
console.log(`Wrote ${programs.size} program graphs to ${OUT_PATH}`);
if (!process.env.NO_OPEN) {
const opener =
process.platform === 'darwin'
? 'open'
: process.platform === 'win32'
? 'explorer'
: 'xdg-open';
const child = spawn(opener, [OUT_PATH], { stdio: 'ignore', detached: true });
// The page is written either way, so a missing opener only skips the open.
child.on('error', () => undefined);
child.unref();
}
Loading
Loading