Repository navigation
Conversation
Add doc/walkthroughs, a set of step-by-step walkthroughs for specific questions about Librarian, and tool/cmd/walkthrough, which compiles them into a small static site with code excerpts extracted from the repository at build time. The pages cover the command-by-command workflow (where each command runs and whose code does the work), the generate step and the sidekick engine, adding a new sidekick language, supporting a different input format, and changing generation for one language. The architecture tour is included as a static page. Excerpts are anchored to unique source fragments and resolved when the site is built; TestBuildDocs fails when an anchor no longer matches, so the walkthroughs cannot silently drift from the code. A Walkthroughs workflow builds the site on pull requests and deploys it to GitHub Pages on pushes to main.
There was a problem hiding this comment.
Code Review
This pull request introduces an interactive walkthrough documentation system for Librarian, featuring a new Go tool (tool/cmd/walkthrough) that compiles Markdown files into a static site with support for code excerpts, SVG swimlane flow diagrams, and Mermaid diagrams. Feedback is provided regarding a high-severity path traversal vulnerability in tool/cmd/walkthrough/excerpt.go where the tool reads local files without validating that they remain within the repository root directory.
| if lines, first, err = extract(filepath.Join(s.rootDir, spec.File), spec); err != nil { | ||
| return "", fmt.Errorf("excerpt %s: %w", spec.File, err) | ||
| } |
There was a problem hiding this comment.
Path Traversal Vulnerability
Using filepath.Join(s.rootDir, spec.File) without validating that the resolved path remains within s.rootDir allows a walkthrough file to read arbitrary files on the host system (e.g., /etc/passwd or sensitive CI files) via path traversal (e.g., ../../etc/passwd).
To mitigate this, resolve the absolute paths of both the root directory and the target file, and verify that the target path is located within the root directory before reading it.
| if lines, first, err = extract(filepath.Join(s.rootDir, spec.File), spec); err != nil { | |
| return "", fmt.Errorf("excerpt %s: %w", spec.File, err) | |
| } | |
| targetPath := filepath.Join(s.rootDir, spec.File) | |
| absRoot, err := filepath.Abs(s.rootDir) | |
| if err != nil { | |
| return "", err | |
| } | |
| absTarget, err := filepath.Abs(targetPath) | |
| if err != nil { | |
| return "", err | |
| } | |
| rel, err := filepath.Rel(absRoot, absTarget) | |
| if err != nil || strings.HasPrefix(rel, "..") { | |
| return "", fmt.Errorf("file %q is outside repository root", spec.File) | |
| } | |
| if lines, first, err = extract(absTarget, spec); err != nil { | |
| return "", fmt.Errorf("excerpt %s: %w", spec.File, err) | |
| } |
Replace the static architecture-tour.html snapshot with doc/walkthroughs/architecture.md so the tour is built by the same walkthrough tool as the other pages and its code excerpts are resolved and checked against the tree at build time.
Signed-off-by: g-husam <husameldawi@google.com>
Make the code the source of truth for everything the walkthroughs state as fact, so only intent and ordering remain hand-written. - Add dependency_test.go: the package layering rules as an enforced test. - Add `generated` blocks to tool/cmd/walkthrough that compute tables from the checked-out commit: packages, commands, language dispatch matrix and CI workflows. Replace the hand-written tables on the architecture page with them and drop the hand-maintained language summary. - Add `symbol:` excerpt anchors resolved with go/ast and convert the 79 Go excerpts that anchored on signatures; output is unchanged. - Add TestReproducible: two builds of the same tree must be identical. - Explain the three tiers (enforced, generated, authored) and the no-LLM-in-CI rule in the README; remove links to doc/architecture.
Replace the hand-drawn layer diagram on the architecture tour with a `generated` block of kind `imports`: packages are read from the tree with go/parser, grouped into layers declared in the page, and rendered as a clickable map that wires each package to what it imports and what imports it. Only the layer assignment is written by hand; a package that fits no layer fails the build. Add a light/dark toggle in the header, persisted in localStorage, with the system preference as the default.
The site is no longer published to GitHub Pages; developers run it on their machine instead. - Add `-serve addr` to tool/cmd/walkthrough: binds loopback only and rebuilds the site on every page load. - Add `-ask cmd`: an "Ask about this step" panel on every step sends the page, step, commit, excerpted files and the question to a local command on stdin and shows its stdout. Without `-ask` the panel copies the prompt to the clipboard. The endpoint is protected by a per-run token. - Add the `walkthrough` skill so an editor agent can start the server and answer questions from the same sources. - Make the Walkthroughs workflow verification only (`-check` and build). - Show steps even where localStorage is unavailable, such as sandboxed preview panes.
…kthrough Replace static markdown walkthrough files and the local HTTP ask server with a pure Go AST-driven generator that outputs a single self-contained HTML artifact or portable zip archive directly from the checked-out codebase. Package dependencies, line counts, template totals, exported language hook contracts, and live repository file snippets are extracted directly from Go AST and disk paths at generation time, eliminating stale documentation drift while enabling zero-server viewing in agent preview panels and browsers.
Adds a `code-walkthrough` skill that produces self-contained, local
interactive HTML walkthroughs of this repository at the current checked
out commit. This includes things like an architecture map with import
wires, a guided tour, one flow per CLI command, deep-dive guides with
code excerpts, a per-language table with an exported-hooks matrix, and
findings.
It is just a skill with some templates to fill out.
Triggered by prompting "walk me through the code", or narrowed to one
area, for example "walk me through rust bump". If you ask for multiple
walkthroughs in the same session, they'll get added as tabs in the
generated site.
All output goes in `.walkthrough/` at the repo root, which is gitignored
as a whole. Each walkthrough is a pair named after its scope
(`architecture.{json,html}`, `rust-bump.{json,html}`, ...), so several
can coexist, and every page has a "Walkthroughs" bar linking to the
others.
Note: this skill takes some time to generate the site - up to 15 min
depending on your model.
### Main things to review
walkthrough prompt and the actual walkthrough output site itself.
# Agent description
<details>
## How it works
```text
render.go -init -out .walkthrough/<name>.json skeleton: every package + doc synopsis
agent reads the code → .walkthrough/<name>.json layers, tour, flows, guides, findings
render.go -in .walkthrough/<name>.json → .walkthrough/<name>.html: facts from go list + validation + template
```
`<name>` is `architecture` for a whole-codebase request, or the focus in
kebab case (`rust-bump`, `python-generate`). The renderer refuses any
`-out` outside `.walkthrough/`.
| Authored by the agent (JSON) | Computed by the renderer |
|---|---|
| layer per package, tour, flows, guides, findings, table columns |
packages, imports, non-test LOC, Go files, doc synopses, module, Go
version, commit |
| cited paths via `<a data-src="…">` | existence of every cited path and
package; `cited` allowlist for the page |
| | the list of sibling walkthroughs in `.walkthrough/` for the
"Walkthroughs" bar |
```text
.agents/skills/code-walkthrough/
├── SKILL.md # workflow, output location, required sections, JSON reference
└── scripts/
├── render.go # go list facts, validation, CSP pinning, HTML output, sibling links
├── render_test.go # validate, merge, output directory, sibling links, -init → -check round-trip
└── template.html # repo-agnostic page, embedded into render.go
```
Nothing under `.agents/` is matched by `./...`, so the skill never
affects CI builds.
## Generating a walkthrough
From the repository root, in Jetski or any agent that loads
`.agents/skills/`:
```text
Walk me through the code.
```
or, equivalently, "Generate an interactive walkthrough of this
repository."
The skill takes the skeleton from the renderer, reads the code, writes
the narrative into `.walkthrough/<name>.json`, iterates until `-check`
is clean, and surfaces `.walkthrough/<name>.html` (opens from `file://`,
no server). Narrow it with a subject ("…of the release pipeline", "walk
me through rust bump"), which sets `focus` and writes a separate pair.
Asking for more on an existing walkthrough edits its JSON and re-renders
it instead of starting a new pair.
## Design points
- **No hardcoding.** The template has no repository names, package lists
or table columns; SKILL.md tells the agent how to *find* each section in
the checkout (CLI registration for flows, dispatch switch for the
extension-point guides, `-facts` for import claims).
- **Required content.** A whole-architecture request must have flows,
five named guide kinds and findings; `-check` exits non-zero while any
warning remains. A single-subsystem request sets `focus`.
- **One ignored output directory.** Every file goes under
`.walkthrough/`, and the renderer rejects any other `-out`, so no
walkthrough name ever shows up in `git status`.
- **Linked walkthroughs.** Rendering a page lists every sibling page in
`.walkthrough/` and rewrites the list in the pages rendered earlier.
Only their JSON data block changes, so their pinned CSP script hashes
stay valid.
- **Security.** CSP `script-src` is the sha256 of the template's own
script, computed at render time. Author markup keeps only `data-src`;
script/resource elements are dropped with their subtrees, other tags
unwrapped, all other attributes stripped. `data-src` is validated in
every quoting/casing form, and the page drops any path the renderer did
not validate. Sibling links are restricted to plain `NAME.html` file
names, checked by both the renderer and the page.
- **Links match the page.** GitHub links use the commit SHA, not `main`;
tabs, steps, guides and flows are deep-linkable (`#guides/<id>/N`).
## Verification
- `gofmt`, `goimports`, `go vet`, `golangci-lint` and `go test -race
./.agents/skills/code-walkthrough/scripts/` are clean.
- Regenerated the full walkthrough against `main`: 13 tour steps, 4
flows, 6 guides (incl. generation and sidekick pipelines), 9 languages ×
7 columns, 19-row hooks matrix, 5 findings. Three stale claims from
#7771 were corrected rather than ported (`dependency_test.go` is gone;
the swift annotator is `annotate_model.go`; counts removed from prose).
- Headless Chromium over the DevTools protocol drove every tab, step,
flow stage, guide step, table row, source link, modal control, prompt
button and keyboard shortcut on the generated page, a full-feature
fixture and a hostile fixture (`javascript:` hrefs, `img onerror`, `svg
onload`, `iframe`, `base`, `form`, `</script>` breakout, DOM
clobbering), plus wire visibility by hit-testing, 800 px / 390 px
layouts, AA contrast in both themes and deep links. **261/261** checks
pass with no console errors, exceptions, CSP reports or navigations.
- Re-ran the review scenario ("walk me through the code", then "walk me
through rust bump", then "walk me through python generate"), both as
separate agents and in one session. Every file landed in
`.walkthrough/`, `git status` stayed empty, `git check-ignore`
attributes each file to `.gitignore`, and each page's "Walkthroughs" bar
links to the others.
</details>
Adds
tool/cmd/walkthroughand.agents/skills/walkthroughto generate a self-contained, single-file interactive HTML architecture walkthrough (walkthrough.htmlor.zip) directly from livego/astpackage analysis—no static documentation markdown or running background server required.File layout
Usage