--- name: view-run description: >- Generate a visual, LangSmith-style HTML view of an sdlc-graph run from its state file (docs/graph-runs//state.json) — the graph with the current node highlighted, next-step guards, the transition trace, milestones, retry counters vs bounds, and the skipped-gate ledger. Produces a self-contained snapshot HTML (openable and shareable anywhere). One invocation, no arguments: it works on the current directory, and asks which subproject when more than one has runs. Use this skill WHENEVER the user wants to SEE a graph run — "show me the run", "where is the graph now", "visualize the state", "open the run viewer", "what's the current state of the sdlc run", "generate the run report page" — or asks to watch a run live. allowed-tools: Read, Write, Bash, Glob disable-model-invocation: false --- # View Run ## Goal Turn `docs/graph-runs//state.json` into something a human can *look at*: the run's position on the graph, what can fire next and why, the full trace, and the ledger — without reading JSON. ## Use When - The user wants to **see** a run rather than read its JSON — *"show me the run"*, *"where is the graph now"*, *"visualize the state"*, *"open the run viewer"*, *"what's the current state"*. - They ask to **watch** a run as it happens, or for a page they can leave open. - **`sdlc-graph` triggers this at run start** when the plugin is installed — that is the common case, and it expects the printed summary relayed verbatim. - They want a **shareable snapshot** of a finished run to attach to a review or a report. ## Do Not Use When - **Nothing has run yet.** No `docs/graph-runs/*/state.json` means there is nothing to render; say so rather than producing an empty page. - **The question is "is this run sound?"** — that is the graph's own eval suite and the trail in `history[]`. This skill renders what the file says; it does not judge it. - **Something needs changing.** This skill is read-only with respect to the run, always. ## Inputs **None.** One invocation, always scoped to **the current working directory**. Everything else is discovered — or asked. ## Workflow ### 1. Discover runs under the current directory ```bash find . -maxdepth 6 -path '*/docs/graph-runs/*/state.json' \ -not -path '*/node_modules/*' -not -path '*/.git/*' -not -path '*/.worktrees/*' 2>/dev/null ``` Group the hits by **project directory** — the path prefix before `/docs/graph-runs/`. - **No hits** → say so and stop. **Do not invent a state file** — a run that never started has nothing to view. - **One project** → proceed with it. - **More than one project** (a monorepo, nested test repos) → **ask the user which directory**, listing each project dir with its newest run id and that run's `status` so the choice is informed. Never pick a subproject silently — the newest file across projects is exactly how the wrong project's run gets rendered. Within the chosen project, use the **newest** `docs/graph-runs/*/state.json` — and *say which one* so a stale pick is visible. If the user's message named a specific run, prefer that match over newest. ### 2. Sanity-check it, honestly Read the JSON. If it fails to parse, report the parse error and stop. If `schema_version` is absent or not `5`, still generate — the viewer shows what it can, and an older file degrades to blank fields rather than wrong ones — but **say which version the file was written against**, and say it first. The graph itself is stricter: a mismatch there is an unconditional halt with no migration path, so a viewer quietly rendering a stale file is showing a run the graph would refuse to resume. ### 3. Generate the snapshot The template is `${CLAUDE_PLUGIN_ROOT}/skills/view-run/viewer/run-viewer.html`. It contains an injection slot: ```js const INLINE=/*__STATE__*/null/*__END__*/ ``` Replace the `null` between the markers with the state JSON, and write the result **next to the state file** as `docs/graph-runs//view.html`: All paths below are **relative to the chosen project directory** from step 1 — in a monorepo the state file lives under the subproject, and the snapshot belongs beside it: ```bash python3 - "${CLAUDE_PLUGIN_ROOT}/skills/view-run/viewer/run-viewer.html" \ "/docs/graph-runs//state.json" "/docs/graph-runs//view.html" <<'PY' import sys, json tpl, state, out = sys.argv[1], sys.argv[2], sys.argv[3] s = open(tpl).read() data = json.dumps(json.load(open(state))) # parse first: invalid JSON must fail HERE # The slot is inside a ` # ANYWHERE — inside a JS string included. json.dumps escapes neither `<` nor `/`, so an observation # reading `fixed the parser ` used to truncate the script, kill boot(), # and execute the rest as markup. These three escapes are legal inside a JS string literal and # JSON.parse back to the identical characters, so the snapshot is unchanged and can no longer close # its own tag. Run data is data: it reaches the DOM through esc(), never as markup. data = data.replace("<", "\\u003c").replace(">", "\\u003e").replace("&", "\\u0026") marker_a, marker_b = "/*__STATE__*/", "/*__END__*/" i, j = s.index(marker_a) + len(marker_a), s.index(marker_b) open(out, "w").write(s[:i] + data + s[j:]) print("wrote", out) PY ``` The snapshot is **fully self-contained** — no server, no polling, works from `file://`, safe to attach or archive. Its stall banner is disabled (a snapshot is a moment, not a feed), and its sidebar shows exactly one run, the one baked in. Both are expected, not defects. ### 4. Deliver it - Send the generated file to the user (rendered, not as a download card, when the client supports it). - On macOS, also offer: `open docs/graph-runs//view.html`. ### 5. Live mode — the default when a server can run **Live is preferred; the snapshot is the fallback and the archive format.** Check whether this project's viewer server is already up (sdlc-graph starts one per project at run start when this plugin is installed). If not, start the **bundled server — ~120 lines, zero dependencies, shipped in this plugin**: **First, ensure the env file — the configuration must be explicit on disk, never implicit.** 1. **No `sdlc-graph-viewer.env` in the project root** → create it from the example, **filled in**: ```bash # /sdlc-graph-viewer.env — written by view-run, resolved values, no placeholders PROJECT_DIR= RUNS_DIR= # usually $PROJECT_DIR/docs/graph-runs POLL_MS=1000 HOST=127.0.0.1 # PORT unset on purpose -> stable per-project derived port ``` Defaults are fine — the point is that **every value the server will use is written down**, so any agent (or human) can read one file and know exactly what is configured. Nothing secret goes in it; committing it is safe. 2. **File already exists** → read it and **verify `PROJECT_DIR` points at this project**. It does → use it untouched (the user's `PORT`/`POLL_MS` choices stand). It points elsewhere → say so, and start with an inline `PROJECT_DIR=` override (env beats file) rather than silently rewriting the user's file. Then start the server from the project root — it auto-loads `./sdlc-graph-viewer.env`: ```bash cd "" && node "${CLAUDE_PLUGIN_ROOT}/skills/view-run/server/server.mjs" & ``` **Configuration is a native `.env` file — nothing is ever edited in code.** The server loads `$SDLC_GRAPH_VIEWER_ENV`, else `./sdlc-graph-viewer.env` if present, via Node's own `process.loadEnvFile` — so real environment variables always beat the file (env > file > default): ```bash # sdlc-graph-viewer.env PROJECT_DIR=/abs/path/to/project # where the project lives (default: cwd) RUNS_DIR=/abs/path/to/docs/graph-runs # where the run DIRECTORIES live (default: $PROJECT_DIR/docs/graph-runs) PORT=8477 # fixed port (default: stable derived per-project port) POLL_MS=500 # page poll interval (default: 1000) HOST=127.0.0.1 # bind address (default: localhost only) VIEWER_HTML=/abs/path.html # viewer page (default: the bundled viewer/run-viewer.html) PORT_BASE=8400 PORT_RANGE=400 PORT_RETRIES=20 # derived-port parameters ``` **Every setting the server uses comes from the environment** — the code holds only the defaults above; no path, suffix, or address is assumed anywhere else. The pages read `POLL_MS` from `GET /api/config` at load — with a 1000ms fallback, so snapshot and drag-drop modes stay fully serverless. The printed summary names which env file (or `defaults + env`) is in force. **The env file is the contract between agent and server.** The skill fills it at spawn (step above) precisely so nothing about the running server is implicit: what an agent must provide to have the HTML + server running is exactly that file's contents, and reading it back is how anyone verifies the configuration. Later user requests ("set the port to 9000") edit the same file — copy-and-fill from `server/sdlc-graph-viewer.env.example` for any variable not yet present, never hand-written from memory. It prints the summary — project, **its own per-project port**, home, live-view and API URLs, and which config is in force. **Relay it as a complete block, never partially** — every one of these lines, every time a server is started or found already running: ``` ● sdlc-graph-viewer — port home http://localhost:/ (the run list is the app's own sidebar) live view http://localhost:/view?state=/api/runs//state runs api http://localhost:/api/runs config · or: defaults (no env file — example at ${CLAUDE_PLUGIN_ROOT}/skills/view-run/server/sdlc-graph-viewer.env.example) viewer stop kill ``` A summary missing the port, a URL, or the config location is an incomplete delivery of this skill. > **If the server prints `cannot read the viewer page` and exits, that is the whole diagnosis** — > `VIEWER_HTML` (or the bundled default) does not resolve to a readable file. It fails at spawn on > purpose: a server whose only page is missing used to bind its port anyway and answer `404 not > found` on `/` and `/view` while every `/api/*` route worked, which reads as a bad URL rather than > a broken install and sends people hunting the wrong thing. The page polls the state JSON every **1s, forever — even after `DONE`**. **One server per project, never shared**; a second project gets a second server on its own port. **Tell the user what is running and how to stop it** whenever you started a server. ## Output Contract - `docs/graph-runs//view.html` — a self-contained snapshot of the named run, delivered to the user. - Live mode: the **complete summary block** — project, port, all three URLs, the config file in force (or "defaults" plus where the example lives), and how to stop the server. All of it, every time. - Any anomaly seen while generating (parse error, missing `schema_version`, `RUNNING` with a quiet file) **stated, not smoothed over**. ## Validation Before telling the user it is done: - **The page opens standalone, and that is now a command, not a squint:** `python3 ${CLAUDE_PLUGIN_ROOT}/skills/view-run/evals/sync/graph_sync.py` — its `page-loads-nothing-external` check looks for markup or code that FETCHES at load time (`