You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+127-7Lines changed: 127 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -198,16 +198,87 @@ To make your version of a tool usable with a one-line `npx` command:
198
198
your project directory
199
199
3. Now you can run it with `npx yourpackagename`
200
200
201
-
# Workflow queue
201
+
# Wizard execution flow
202
+
203
+
## Full lifecycle
204
+
205
+
When a user runs `npx @posthog/wizard`, here's what happens end-to-end:
206
+
207
+
### 1. CLI parsing and framework detection (`bin.ts` → `src/run.ts`)
208
+
209
+
`bin.ts` parses CLI args, checks Node version, and calls `runWizard()` in `src/run.ts`. The run function detects the project framework (Next.js, React, etc.) by inspecting `package.json` and project structure, then loads the matching `FrameworkConfig` from `src/frameworks/`.
210
+
211
+
### 2. TUI startup and UI flow (`src/ui/tui/start-tui.ts`)
212
+
213
+
The TUI renders and the user progresses through screens. Screen order is driven by a `Workflow` — an ordered list of `WorkflowStep` objects defined in `src/lib/workflows/posthog-integration.ts`. Each step declares which screen it owns and when that screen is complete.
214
+
215
+
The workflow is converted to `FlowEntry[]` via `workflowToFlowEntries()` and fed to the router. The router walks the entries, skipping completed/hidden screens, and returns the first incomplete one. This is reactive — every session mutation re-resolves the active screen.
216
+
217
+
**Gate steps** block downstream code. The `intro` step has `gate: 'setup'` — `bin.ts` awaits `store.setupComplete` before proceeding. The `health-check` step has `gate: 'health'` — `bin.ts` awaits `store.healthGateComplete`.
218
+
219
+
### 3. Agent runner (`src/lib/agent-runner.ts`)
220
+
221
+
Once gates resolve, `runAgentWizard()` runs. This is where the queue takes over:
222
+
223
+
**Bootstrap query** — A standalone query tells the agent to load the skill menu, pick and install a skill, read SKILL.md, and emit the installed skill ID via `[WIZARD-SKILL-ID] <id>`. The model does NOT know about the queue — it just prepares the skill.
224
+
225
+
**SKILL.md parsing** — After bootstrap, the runner reads `.claude/skills/<id>/SKILL.md` from disk and parses the `workflow` array from its YAML frontmatter using `parseWorkflowStepsFromSkillMd()`. This produces a `WorkflowStepSeed[]` with step ids, reference filenames, and display titles.
226
+
227
+
**Queue seeding** — `createPostBootstrapQueue(steps)` builds a `WizardWorkflowQueue` from the parsed steps plus an `env-vars` step at the end. The queue is set on the store via `getUI().setWorkQueue(queue)` so the TUI can display it and dynamically enqueue new work.
228
+
229
+
**Execution loop** — The runner pops items from the queue one at a time:
Each `runAgent` call continues the same conversation via `resumeSessionId`. The model sees one prompt per step — either "read and follow this reference file" (for workflow items) or "set up environment variables" (for env-vars). The stop hook only fires the remark/feature-queue on the last item.
237
+
238
+
### 4. TUI progress tracking
239
+
240
+
During the run, the RunScreen displays a stage-grouped progress list. Stage headers come from queue item labels (which come from SKILL.md frontmatter titles). Nested tasks come from the agent's `TodoWrite` tool calls. When the runner advances to a new queue item, `setCurrentQueueItem()` fires, the store clears the task list, and the previous item moves to the completed list.
241
+
242
+
The queue is reactive on the store — `enqueue()` and `dequeue()` trigger `emitChange()` which re-renders the UI immediately.
202
243
203
-
The wizard executes agent work through a queue-backed runner. Instead of one monolithic prompt, each workflow step is a separate continued query.
244
+
### 5. Post-run (`agent-runner.ts` after loop)
204
245
205
-
## How it works
246
+
After the queue drains: error handling, env var upload to hosting providers, outro data construction, analytics shutdown.
206
247
207
-
1.**Bootstrap** runs first as a standalone query — installs the skill and emits the skill ID.
208
-
2. The runner reads `SKILL.md` from the installed skill and parses the `workflow` array from its YAML frontmatter to discover the step list.
209
-
3. A `WizardWorkflowQueue` is seeded from those steps plus an `env-vars` step at the end.
210
-
4. The runner pops items from the queue and issues one continued query per item, preserving the conversation across steps.
0 commit comments