diff --git a/.claude/scripts/hooks/post-edit-quality.sh b/.claude/scripts/hooks/post-edit-quality.sh new file mode 100755 index 0000000..88cd1c2 --- /dev/null +++ b/.claude/scripts/hooks/post-edit-quality.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +# ============================================================ +# post-edit-quality.sh +# Claude Code PostToolUse hook — 每次编辑 .py 文件后自动检查 +# +# 触发时机:Claude 每次执行 Write/Edit 后 +# 作用:对被修改的文件执行复杂度和风格检查 +# 退出码:0 = 通过,非0 = 报告问题(非阻塞,Claude 会看到反馈) +# +# 配置方法:在 .claude/settings.local.json 中注册: +# "hooks": { +# "PostToolUse": [ +# { "matcher": "Write|Edit", "command": "bash scripts/hooks/post-edit-quality.sh" } +# ] +# } +# ============================================================ +set -euo pipefail + +# <填写: 项目 Conda 环境路径> +# PROJ_ENV="/home//miniconda3/envs//bin" +# [[ -d "$PROJ_ENV" ]] && export PATH="$PROJ_ENV:$PATH" + +INPUT=$(cat) +FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""') + +# 只检查 .py 文件 +if [[ ! "$FILE_PATH" == *.py ]]; then + exit 0 +fi + +# 只检查存在的文件 +if [[ ! -f "$FILE_PATH" ]]; then + exit 0 +fi + +ERRORS="" +WARNINGS="" + +# ── 1. Ruff 格式 + lint 检查 ── +if command -v ruff &> /dev/null; then + RUFF_OUTPUT=$(ruff check "$FILE_PATH" 2>&1 || true) + if [[ -n "$RUFF_OUTPUT" ]]; then + ERRORS+="[ruff] 风格/lint 问题:\n$RUFF_OUTPUT\n\n" + fi +fi + +# ── 2. Radon 圈复杂度(只报告 C 级及以下) ── +if command -v radon &> /dev/null; then + RADON_OUTPUT=$(radon cc "$FILE_PATH" -n C -s 2>&1 || true) + if echo "$RADON_OUTPUT" | grep -qE '^\s+[FMC]\s'; then + ERRORS+="[radon] 圈复杂度过高(≥C):\n$RADON_OUTPUT\n\n" + fi +fi + +# ── 3. 文件行数检查(warning,不阻塞)── +LINE_COUNT=$(wc -l < "$FILE_PATH") +if [[ "$LINE_COUNT" -gt 200 ]]; then + WARNINGS+="[行数] $FILE_PATH 有 ${LINE_COUNT} 行,超过 200 行建议上限。\n\n" +fi + +# ── 4. 禁止裸 except ── +if grep -nE '^\s*except\s*:\s*$|^\s*except\s+Exception\s*:\s*pass' "$FILE_PATH" 2>/dev/null; then + ERRORS+="[安全] 检测到裸 except 或 except Exception: pass,请捕获具体异常类型。\n\n" +fi + +# ── 5. 禁止硬编码敏感信息 ── +if grep -nEi "(api_key|secret|password|token)\s*=\s*[\"'][^\"']+[\"']" "$FILE_PATH" 2>/dev/null; then + ERRORS+="[安全] 疑似硬编码敏感信息,请使用环境变量或 .env 文件。\n\n" +fi + +# ── 输出结果 ── +if [[ -n "$WARNINGS" ]]; then + echo -e "⚠️ Warnings($FILE_PATH,不阻塞):\n" >&2 + echo -e "$WARNINGS" >&2 +fi + +if [[ -n "$ERRORS" ]]; then + echo -e "❌ 代码质量检查发现问题($FILE_PATH):\n" >&2 + echo -e "$ERRORS" >&2 + exit 1 +fi + +exit 0 diff --git a/.claude/scripts/hooks/pre-commit-guard.sh b/.claude/scripts/hooks/pre-commit-guard.sh new file mode 100755 index 0000000..83e5d2c --- /dev/null +++ b/.claude/scripts/hooks/pre-commit-guard.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +# ============================================================ +# pre-commit-guard.sh +# Claude Code PreToolUse hook — 拦截 git commit,执行全量检查 +# +# 触发时机:Claude 尝试执行 git commit 之前 +# 作用:阻塞提交直到所有质量门禁通过 +# 退出码:0 = 放行,2 = 阻塞(Claude 必须先修复问题) +# +# 配置方法:在 .claude/settings.local.json 中注册: +# "hooks": { +# "PreToolUse": [ +# { "matcher": "Bash", "command": "bash scripts/hooks/pre-commit-guard.sh" } +# ] +# } +# ============================================================ +set -euo pipefail + +# <填写: 项目 Conda 环境路径> +# PROJ_ENV="/home//miniconda3/envs//bin" +# [[ -d "$PROJ_ENV" ]] && export PATH="$PROJ_ENV:$PATH" + +INPUT=$(cat) +COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // ""') + +# 只拦截 git commit 命令 +if ! echo "$COMMAND" | grep -qE '^\s*git\s+commit'; then + exit 0 +fi + +ERRORS="" +WARNINGS="" + +# <填写: 核心代码目录,如 core/> +CODE_DIR="core" + +# ── 1. 项目结构检查(按需取消注释) ── +# 检查根目录是否有不该存在的 .py +# for pyfile in *.py; do +# [[ "$pyfile" == "*.py" ]] && break +# if [[ "$pyfile" != "main.py" && "$pyfile" != "conftest.py" ]]; then +# ERRORS+="[结构] 根目录不该有: $pyfile(应移至 $CODE_DIR/)\n" +# fi +# done + +# ── 2. 全量代码质量检查 ── +if [[ -d "$CODE_DIR" ]] && command -v ruff &> /dev/null; then + RUFF_OUTPUT=$(ruff check "$CODE_DIR" 2>&1 || true) + if [[ -n "$RUFF_OUTPUT" ]]; then + ERROR_COUNT=$(echo "$RUFF_OUTPUT" | wc -l) + ERRORS+="[ruff] $CODE_DIR/ 中有 ${ERROR_COUNT} 个问题。运行 ruff check $CODE_DIR/ 查看详情。\n" + fi +fi + +if [[ -d "$CODE_DIR" ]] && command -v radon &> /dev/null; then + RADON_OUTPUT=$(radon cc "$CODE_DIR" -n C -s 2>&1 || true) + if echo "$RADON_OUTPUT" | grep -qE '^\s+[FMC]\s'; then + ERRORS+="[radon] 存在圈复杂度 ≥ C 的函数:\n$RADON_OUTPUT\n" + fi +fi + +# ── 3. 文件行数检查 ── +if [[ -d "$CODE_DIR" ]]; then + while IFS= read -r pyfile; do + lines=$(wc -l < "$pyfile") + if [[ "$lines" -gt 200 ]]; then + WARNINGS+="[行数] $pyfile 有 ${lines} 行,超过 200 行建议上限。\n" + fi + done < <(find "$CODE_DIR" -name "*.py" 2>/dev/null || true) +fi + +# ── 4. 测试检查 ── +if command -v pytest &> /dev/null && [[ -d "tests" ]]; then + TEST_OUTPUT=$(pytest tests/ --tb=line -q 2>&1 || true) + if echo "$TEST_OUTPUT" | grep -qE 'failed|error'; then + FAILED=$(echo "$TEST_OUTPUT" | tail -1) + ERRORS+="[测试] 有测试未通过:$FAILED\n" + fi +fi + +# ── 判定结果 ── +if [[ -n "$WARNINGS" ]]; then + echo -e "⚠️ Warnings(不阻塞):\n" >&2 + echo -e "$WARNINGS" >&2 +fi + +if [[ -n "$ERRORS" ]]; then + echo -e "❌ 提交被阻塞 — 请先修复以下问题:\n" >&2 + echo -e "$ERRORS" >&2 + echo -e "修复完成后重新执行 git commit。" >&2 + exit 2 +fi + +echo "✅ 所有检查通过,允许提交。" +exit 0 diff --git a/.claude/skills/brainstorming/SKILL.md b/.claude/skills/brainstorming/SKILL.md new file mode 100644 index 0000000..ff12709 --- /dev/null +++ b/.claude/skills/brainstorming/SKILL.md @@ -0,0 +1,189 @@ +--- +name: brainstorming +description: "You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation." +--- + +# Brainstorming Ideas Into Designs + +Help turn ideas into fully formed designs and specs through natural collaborative dialogue. + +Start by understanding the current project context, then ask questions one at a time to refine the idea. Once you understand what you're building, present the design and get user approval. + + +Do NOT invoke any implementation skill, write any code, scaffold any project, or take any implementation action until you have presented a design and the user has approved it. This applies to EVERY project regardless of perceived simplicity. + + +## Anti-Pattern: "This Is Too Simple To Need A Design" + +Every project goes through this process. A todo list, a single-function utility, a config change — all of them. "Simple" projects are where unexamined assumptions cause the most wasted work. The design can be short (a few sentences for truly simple projects), but you MUST present it and get approval. + +## Checklist + +You MUST create a task for each of these items and complete them in order: + +1. **Explore project context** — check files, docs, recent commits +2. **Offer visual companion** (if topic will involve visual questions) — this is its own message, not combined with a clarifying question. See the Visual Companion section below. +3. **Ask clarifying questions** — one at a time, understand purpose/constraints/success criteria +4. **Propose 2-3 approaches** — with trade-offs and your recommendation +5. **Present design** — in sections scaled to their complexity, get user approval after each section +6. **Write design doc** — save to `research-wiki/designs/YYYY-MM-DD--design.md` and commit +7. **Spec self-review** — quick inline check for placeholders, contradictions, ambiguity, scope (see below) +7.5. **Codex design review** — independent Codex review via `/codex:rescue --fresh --wait`, verify findings, apply accepted fixes inline (see below) +8. **User reviews written spec** — ask user to review the spec file before proceeding +9. **Transition to implementation** — invoke writing-plans skill to create implementation plan + +## Process Flow + +```dot +digraph brainstorming { + "Explore project context" [shape=box]; + "Visual questions ahead?" [shape=diamond]; + "Offer Visual Companion\n(own message, no other content)" [shape=box]; + "Ask clarifying questions" [shape=box]; + "Propose 2-3 approaches" [shape=box]; + "Present design sections" [shape=box]; + "User approves design?" [shape=diamond]; + "Write design doc" [shape=box]; + "Spec self-review\n(fix inline)" [shape=box]; + "Codex design review\n(/codex:rescue --fresh --wait, fix inline)" [shape=box]; + "User reviews spec?" [shape=diamond]; + "Invoke writing-plans skill" [shape=doublecircle]; + + "Explore project context" -> "Visual questions ahead?"; + "Visual questions ahead?" -> "Offer Visual Companion\n(own message, no other content)" [label="yes"]; + "Visual questions ahead?" -> "Ask clarifying questions" [label="no"]; + "Offer Visual Companion\n(own message, no other content)" -> "Ask clarifying questions"; + "Ask clarifying questions" -> "Propose 2-3 approaches"; + "Propose 2-3 approaches" -> "Present design sections"; + "Present design sections" -> "User approves design?"; + "User approves design?" -> "Present design sections" [label="no, revise"]; + "User approves design?" -> "Write design doc" [label="yes"]; + "Write design doc" -> "Spec self-review\n(fix inline)"; + "Spec self-review\n(fix inline)" -> "Codex design review\n(/codex:rescue --fresh --wait, fix inline)"; + "Codex design review\n(/codex:rescue --fresh --wait, fix inline)" -> "User reviews spec?"; + "User reviews spec?" -> "Write design doc" [label="changes requested"]; + "User reviews spec?" -> "Invoke writing-plans skill" [label="approved"]; +} +``` + +**The terminal state is invoking writing-plans.** Do NOT invoke frontend-design, mcp-builder, or any other implementation skill. The ONLY skill you invoke after brainstorming is writing-plans. + +## The Process + +**Understanding the idea:** + +- Check out the current project state first (files, docs, recent commits) +- **代码检索(graphify)**:在查阅现有代码结构前,先跑 `/graphify . --update` 刷新知识图谱(增量合并:改代码免费、改文档才 LLM),再优先用 `/graphify query "<问题>"` / `graphify path` / `graphify explain` 做结构化检索,而非盲读文件。若 `graphify-out/graph.json` 不存在,提示人类先手动 `/graphify .`;未建图前不阻断,降级为常规文件阅读。 +- Before asking detailed questions, assess scope: if the request describes multiple independent subsystems (e.g., "build a platform with chat, file storage, billing, and analytics"), flag this immediately. Don't spend questions refining details of a project that needs to be decomposed first. +- If the project is too large for a single spec, help the user decompose into sub-projects: what are the independent pieces, how do they relate, what order should they be built? Then brainstorm the first sub-project through the normal design flow. Each sub-project gets its own spec → plan → implementation cycle. +- For appropriately-scoped projects, ask questions one at a time to refine the idea +- Prefer multiple choice questions when possible, but open-ended is fine too +- Only one question per message - if a topic needs more exploration, break it into multiple questions +- Focus on understanding: purpose, constraints, success criteria + +**Exploring approaches:** + +- Propose 2-3 different approaches with trade-offs +- Present options conversationally with your recommendation and reasoning +- Lead with your recommended option and explain why + +**Presenting the design:** + +- Once you believe you understand what you're building, present the design +- Scale each section to its complexity: a few sentences if straightforward, up to 200-300 words if nuanced +- Ask after each section whether it looks right so far +- Cover: architecture, components, data flow, error handling, testing +- Be ready to go back and clarify if something doesn't make sense + +**Design for isolation and clarity:** + +- Break the system into smaller units that each have one clear purpose, communicate through well-defined interfaces, and can be understood and tested independently +- For each unit, you should be able to answer: what does it do, how do you use it, and what does it depend on? +- Can someone understand what a unit does without reading its internals? Can you change the internals without breaking consumers? If not, the boundaries need work. +- Smaller, well-bounded units are also easier for you to work with - you reason better about code you can hold in context at once, and your edits are more reliable when files are focused. When a file grows large, that's often a signal that it's doing too much. + +**Working in existing codebases:** + +- Explore the current structure before proposing changes. Follow existing patterns. +- Where existing code has problems that affect the work (e.g., a file that's grown too large, unclear boundaries, tangled responsibilities), include targeted improvements as part of the design - the way a good developer improves code they're working in. +- Don't propose unrelated refactoring. Stay focused on what serves the current goal. + +## After the Design + +**Documentation:** + +- Write the validated design (spec) to `research-wiki/designs/YYYY-MM-DD--design.md` + - (User preferences for spec location override this default) +- Use elements-of-style:writing-clearly-and-concisely skill if available +- Commit the design document to git + +**Spec Self-Review:** +After writing the spec document, look at it with fresh eyes: + +1. **Placeholder scan:** Any "TBD", "TODO", incomplete sections, or vague requirements? Fix them. +2. **Internal consistency:** Do any sections contradict each other? Does the architecture match the feature descriptions? +3. **Scope check:** Is this focused enough for a single implementation plan, or does it need decomposition? +4. **Ambiguity check:** Could any requirement be interpreted two different ways? If so, pick one and make it explicit. + +Fix any issues inline. No need to re-review — just fix and move on. + +**Codex Design Review:** +After your self-review passes, get an independent second opinion from Codex before the human gate: + +> 用 `/codex:rescue --fresh --wait` 把"用户需求溯源 + 设计全文"交 Codex 独立审查(只读),要求逐条核对需求覆盖、内部一致性、与 CLAUDE.md/既有设计的冲突,按 Critical/Important/Minor 返回必改项。 + +Verify each finding against the codebase (do not blindly accept). Apply the accepted fixes inline, then proceed to the User Review Gate. The human gate is preserved. + +**User Review Gate:** +After the spec review loop passes, ask the user to review the written spec before proceeding: + +> "Spec written and committed to ``. Please review it and let me know if you want to make any changes before we start writing out the implementation plan." + +Wait for the user's response. If they request changes, make them and re-run the spec review loop. Only proceed once the user approves. + +**Implementation:** + +- Invoke the writing-plans skill to create a detailed implementation plan +- Do NOT invoke any other skill. writing-plans is the next step. + +## Key Principles + +- **One question at a time** - Don't overwhelm with multiple questions +- **Multiple choice preferred** - Easier to answer than open-ended when possible +- **YAGNI ruthlessly** - Remove unnecessary features from all designs +- **Explore alternatives** - Always propose 2-3 approaches before settling +- **Incremental validation** - Present design, get approval before moving on +- **Be flexible** - Go back and clarify when something doesn't make sense + +## Visual Companion + +A browser-based companion for showing mockups, diagrams, and visual options during brainstorming. Available as a tool — not a mode. Accepting the companion means it's available for questions that benefit from visual treatment; it does NOT mean every question goes through the browser. + +**Offering the companion:** When you anticipate that upcoming questions will involve visual content (mockups, layouts, diagrams), offer it once for consent: +> "Some of what we're working on might be easier to explain if I can show it to you in a web browser. I can put together mockups, diagrams, comparisons, and other visuals as we go. This feature is still new and can be token-intensive. Want to try it? (Requires opening a local URL)" + +**This offer MUST be its own message.** Do not combine it with clarifying questions, context summaries, or any other content. The message should contain ONLY the offer above and nothing else. Wait for the user's response before continuing. If they decline, proceed with text-only brainstorming. + +**Per-question decision:** Even after the user accepts, decide FOR EACH QUESTION whether to use the browser or the terminal. The test: **would the user understand this better by seeing it than reading it?** + +- **Use the browser** for content that IS visual — mockups, wireframes, layout comparisons, architecture diagrams, side-by-side visual designs +- **Use the terminal** for content that is text — requirements questions, conceptual choices, tradeoff lists, A/B/C/D text options, scope decisions + +A question about a UI topic is not automatically a visual question. "What does personality mean in this context?" is a conceptual question — use the terminal. "Which wizard layout works better?" is a visual question — use the browser. + +If they agree to the companion, read the detailed guide before proceeding: +`skills/brainstorming/visual-companion.md` + +## Wiki Integration + +**Precondition**: `research-wiki/` directory exists (skip this section entirely if it does not). + +**Trigger**: When a design is approved and the design document is being written. + +**Output path**: Design docs are saved to `research-wiki/designs/` instead of `docs/superpowers/specs/`. + +**Steps**: +1. Run `.claude/tools/research_wiki.py add_entity research-wiki/ --type design --id --title ""` to create the design entity +2. Append the chosen approach, key decision rationale, rejected alternatives, and why they were rejected to the generated page +3. If the design is related to an idea, run `.claude/tools/research_wiki.py add_edge research-wiki/ --from "design:" --to "idea:" --type refines --evidence "..."` +4. Run `.claude/tools/research_wiki.py rebuild_index research-wiki/` diff --git a/.claude/skills/brainstorming/spec-document-reviewer-prompt.md b/.claude/skills/brainstorming/spec-document-reviewer-prompt.md new file mode 100644 index 0000000..f9b0e2e --- /dev/null +++ b/.claude/skills/brainstorming/spec-document-reviewer-prompt.md @@ -0,0 +1,49 @@ +# Spec Document Reviewer Prompt Template + +Use this template when dispatching a spec document reviewer subagent. + +**Purpose:** Verify the spec is complete, consistent, and ready for implementation planning. + +**Dispatch after:** Spec document is written to docs/superpowers/specs/ + +``` +Task tool (general-purpose): + description: "Review spec document" + prompt: | + You are a spec document reviewer. Verify this spec is complete and ready for planning. + + **Spec to review:** [SPEC_FILE_PATH] + + ## What to Check + + | Category | What to Look For | + |----------|------------------| + | Completeness | TODOs, placeholders, "TBD", incomplete sections | + | Consistency | Internal contradictions, conflicting requirements | + | Clarity | Requirements ambiguous enough to cause someone to build the wrong thing | + | Scope | Focused enough for a single plan — not covering multiple independent subsystems | + | YAGNI | Unrequested features, over-engineering | + + ## Calibration + + **Only flag issues that would cause real problems during implementation planning.** + A missing section, a contradiction, or a requirement so ambiguous it could be + interpreted two different ways — those are issues. Minor wording improvements, + stylistic preferences, and "sections less detailed than others" are not. + + Approve unless there are serious gaps that would lead to a flawed plan. + + ## Output Format + + ## Spec Review + + **Status:** Approved | Issues Found + + **Issues (if any):** + - [Section X]: [specific issue] - [why it matters for planning] + + **Recommendations (advisory, do not block approval):** + - [suggestions for improvement] +``` + +**Reviewer returns:** Status, Issues (if any), Recommendations \ No newline at end of file diff --git a/.claude/skills/brainstorming/visual-companion.md b/.claude/skills/brainstorming/visual-companion.md new file mode 100644 index 0000000..89ebc6a --- /dev/null +++ b/.claude/skills/brainstorming/visual-companion.md @@ -0,0 +1,287 @@ +# Visual Companion Guide + +Browser-based visual brainstorming companion for showing mockups, diagrams, and options. + +## When to Use + +Decide per-question, not per-session. The test: **would the user understand this better by seeing it than reading it?** + +**Use the browser** when the content itself is visual: + +- **UI mockups** — wireframes, layouts, navigation structures, component designs +- **Architecture diagrams** — system components, data flow, relationship maps +- **Side-by-side visual comparisons** — comparing two layouts, two color schemes, two design directions +- **Design polish** — when the question is about look and feel, spacing, visual hierarchy +- **Spatial relationships** — state machines, flowcharts, entity relationships rendered as diagrams + +**Use the terminal** when the content is text or tabular: + +- **Requirements and scope questions** — "what does X mean?", "which features are in scope?" +- **Conceptual A/B/C choices** — picking between approaches described in words +- **Tradeoff lists** — pros/cons, comparison tables +- **Technical decisions** — API design, data modeling, architectural approach selection +- **Clarifying questions** — anything where the answer is words, not a visual preference + +A question *about* a UI topic is not automatically a visual question. "What kind of wizard do you want?" is conceptual — use the terminal. "Which of these wizard layouts feels right?" is visual — use the browser. + +## How It Works + +The server watches a directory for HTML files and serves the newest one to the browser. You write HTML content to `screen_dir`, the user sees it in their browser and can click to select options. Selections are recorded to `state_dir/events` that you read on your next turn. + +**Content fragments vs full documents:** If your HTML file starts with `/.superpowers/brainstorm/` for the session directory. + +**Note:** Pass the project root as `--project-dir` so mockups persist in `.superpowers/brainstorm/` and survive server restarts. Without it, files go to `/tmp` and get cleaned up. Remind the user to add `.superpowers/` to `.gitignore` if it's not already there. + +**Launching the server by platform:** + +**Claude Code (macOS / Linux):** +```bash +# Default mode works — the script backgrounds the server itself +scripts/start-server.sh --project-dir /path/to/project +``` + +**Claude Code (Windows):** +```bash +# Windows auto-detects and uses foreground mode, which blocks the tool call. +# Use run_in_background: true on the Bash tool call so the server survives +# across conversation turns. +scripts/start-server.sh --project-dir /path/to/project +``` +When calling this via the Bash tool, set `run_in_background: true`. Then read `$STATE_DIR/server-info` on the next turn to get the URL and port. + +**Codex:** +```bash +# Codex reaps background processes. The script auto-detects CODEX_CI and +# switches to foreground mode. Run it normally — no extra flags needed. +scripts/start-server.sh --project-dir /path/to/project +``` + +**Gemini CLI:** +```bash +# Use --foreground and set is_background: true on your shell tool call +# so the process survives across turns +scripts/start-server.sh --project-dir /path/to/project --foreground +``` + +**Other environments:** The server must keep running in the background across conversation turns. If your environment reaps detached processes, use `--foreground` and launch the command with your platform's background execution mechanism. + +If the URL is unreachable from your browser (common in remote/containerized setups), bind a non-loopback host: + +```bash +scripts/start-server.sh \ + --project-dir /path/to/project \ + --host 0.0.0.0 \ + --url-host localhost +``` + +Use `--url-host` to control what hostname is printed in the returned URL JSON. + +## The Loop + +1. **Check server is alive**, then **write HTML** to a new file in `screen_dir`: + - Before each write, check that `$STATE_DIR/server-info` exists. If it doesn't (or `$STATE_DIR/server-stopped` exists), the server has shut down — restart it with `start-server.sh` before continuing. The server auto-exits after 30 minutes of inactivity. + - Use semantic filenames: `platform.html`, `visual-style.html`, `layout.html` + - **Never reuse filenames** — each screen gets a fresh file + - Use Write tool — **never use cat/heredoc** (dumps noise into terminal) + - Server automatically serves the newest file + +2. **Tell user what to expect and end your turn:** + - Remind them of the URL (every step, not just first) + - Give a brief text summary of what's on screen (e.g., "Showing 3 layout options for the homepage") + - Ask them to respond in the terminal: "Take a look and let me know what you think. Click to select an option if you'd like." + +3. **On your next turn** — after the user responds in the terminal: + - Read `$STATE_DIR/events` if it exists — this contains the user's browser interactions (clicks, selections) as JSON lines + - Merge with the user's terminal text to get the full picture + - The terminal message is the primary feedback; `state_dir/events` provides structured interaction data + +4. **Iterate or advance** — if feedback changes current screen, write a new file (e.g., `layout-v2.html`). Only move to the next question when the current step is validated. + +5. **Unload when returning to terminal** — when the next step doesn't need the browser (e.g., a clarifying question, a tradeoff discussion), push a waiting screen to clear the stale content: + + ```html + +
+

Continuing in terminal...

+
+ ``` + + This prevents the user from staring at a resolved choice while the conversation has moved on. When the next visual question comes up, push a new content file as usual. + +6. Repeat until done. + +## Writing Content Fragments + +Write just the content that goes inside the page. The server wraps it in the frame template automatically (header, theme CSS, selection indicator, and all interactive infrastructure). + +**Minimal example:** + +```html +

Which layout works better?

+

Consider readability and visual hierarchy

+ +
+
+
A
+
+

Single Column

+

Clean, focused reading experience

+
+
+
+
B
+
+

Two Column

+

Sidebar navigation with main content

+
+
+
+``` + +That's it. No ``, no CSS, no `