Analyze — Tour Spec Authoring
Read input artifact(s) and write a tour-spec.json that the renderer consumes. Hand off to learning-guide:render at the end.
Trigger phrases
- "create a learning guide for X"
- "make an interactive tour"
- "generate onboarding doc"
- "build a learning module from this session"
Inputs to collect from the user
- Source artifact path(s) — required. One or more files/folders.
- Output directory — default
<input-parent>/learning/. - Archetype hint — optional; auto-detect with these rules:
- Filename ends
.observations.mdOR YAML frontmatter containssession_date:→planning-session. - Input is a directory of source files with no obvious doc layer →
codebase. - Input contains "Phase 1", "Phase 2", "rollout", "blockers" structure →
refactor-plan. - Otherwise →
generic.
- Filename ends
- Language — auto-detect from input text dominance; require >80% single-locale tokens to commit, otherwise default
en. Always state the detected language and offer an override before drafting.
Flow
- Resolve inputs. Confirm path(s) and output dir before reading anything large. Reject non-existent paths.
- Pick archetype. Auto-detect, state the choice, ask the user to confirm or override.
- Load archetype reference. Read
references/archetype-<name>.md. - Survey the input.
- Codebase: structured exploration — entry points, module map, control flow.
- Doc: top-to-bottom read.
- Session: lift decisions, blockers, files-touched.
- Discover embedded sources. Look for user-authored markdown referenced from the input (links, frontmatter
artifacts:lists, sibling.mdfiles). If none found AND archetype iscodebaseorgeneric, plan to synthesizetour-companion.mdperreferences/synthesis-contract.md. - Discover external link tokens. Scan input for ticket/issue patterns. Ask the user for URL templates (e.g.,
TICKET-→https://tracker.example.com/browse/TICKET-{id}). Templates must start withhttp://,https://, ormailto:and contain{id}— the renderer rejects other schemes. - Discover cross-ref patterns. Per
references/cross-ref-design.md. Propose only token-shaped patterns; bare words are forbidden. Show the user the proposed list, get confirmation. - Draft the tour spec. Follow the archetype's section outline. Each section gets a markdown body, optional inline quiz. Synthesize
tour-companion.mdif planned in step 5. Usereferences/spec-authoring.mdforbody_mdstyle. - Quality gates. Before handoff, verify:
- Every section has non-empty
body_md. - Every section with
level >= 2has aparent(the renderer rejects a spec that violates this — the JSON Schema only hints it for editors). - Every cross-ref pattern uses a non-bare-word token shape, names an existing source, AND its
anchor_formatresolves to a heading in that source. Heading anchors are bare slugs with nosection-prefix (seereferences/cross-ref-design.md). - Every
external_linkstemplate starts with an allowed scheme (http(s):///mailto:) and contains{id}. - Every quiz
answer_indexis in[0, options.length-1]. - Mermaid blocks parse as valid (best-effort regex on the first non-blank line).
- Every section has non-empty
- Hand off to render. Invoke
learning-guide:renderwith the spec path. No "shall I render?" gate — render is cheap and idempotent.
Re-invocation behavior
If tour-spec.json already exists at the target path, ask:
"Existing spec found. Update it (preserve your edits), regenerate from scratch, or just re-render?"
- Update mode — preserve
sections[].body_md,sections[].quiz,final_quiz,glossaryverbatim. Refreshembedded_sources,external_links,cross_ref_patternsonly when input artifacts have changed since the spec'smtime. All other top-level fields refresh. Conflicts are surfaced as a numbered list before write. - Regenerate — delete the existing spec, re-run from step 1.
- Re-render only — invoke
learning-guide:render; skip analyze entirely.
References
references/archetype-codebase.md,references/archetype-planning-session.md,references/archetype-refactor-plan.md,references/archetype-generic.mdreferences/spec-authoring.md—body_mdstyle and field rules.references/cross-ref-design.md— pattern shapes and slug algorithm.references/synthesis-contract.md—tour-companion.mdskeleton.