Local Viewer Implementation Plan
For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
Goal: Add almanac serve, a local read-only web viewer for browsing a repo's CodeAlmanac wiki.
Architecture: The viewer is a thin HTTP layer over the existing SQLite index and markdown page files. Markdown remains canonical; the server only reads files, triggers silent reindex, and serves JSON plus static bundled UI assets. The first slice keeps editing out of scope and exposes "open/reveal path" data for the frontend to display.
Tech Stack: Node http, existing better-sqlite3 index, existing .almanac/pages storage, plain browser JavaScript/CSS static assets bundled in the npm package.
Task 1: Shared Page Query#
Files:
- Create:
src/query/page-view.ts - Modify:
src/commands/show.ts - Test:
test/viewer-query.test.ts
Steps:
- Extract the DB/page-content record fetch from
src/commands/show.tsintogetPageView(db, slug). - Export a
PageViewtype matching the existingShowRecordshape. - Update
runShowto callgetPageViewso CLI behavior and viewer data share one implementation. - Add a test that indexes a page and verifies body, topics, file refs, outgoing links, and backlinks.
- Run
npm test -- viewer-query.test.ts show.test.ts.
Task 2: Viewer API#
Files:
- Create:
src/viewer/api.ts - Test:
test/viewer-api.test.ts
Steps:
- Add
createViewerApi({ repoRoot }). - Add
overview()returning wiki title, page count, topic count, recent pages, and root topics. - Add
page(slug)returning aPageViewornull. - Add
topic(slug)returning topic metadata, parents, children, and active pages. - Add
search(query)returning active page summaries from FTS when query is present, otherwise recent pages. - Add
file(path)returning pages fromfile_refsusing the same path matching semantics assearch --mentions. - Run
npm test -- viewer-api.test.ts.
Task 3: Local Server#
Files:
- Create:
src/commands/serve.ts - Create:
src/viewer/server.ts - Create:
src/viewer/static.ts - Modify:
src/cli/register-query-commands.ts - Test:
test/serve-command.test.ts
Steps:
- Implement
startViewerServer({ repoRoot, host, port }). - Serve
/api/overview,/api/page/:slug,/api/topic/:slug,/api/search, and/api/file. - Serve static viewer assets for all non-API routes so client-side navigation works.
- Implement port
0support for tests and default3927for CLI use. - Add
runServe({ cwd, host, port, open })as the command wrapper. - Register
almanac serve --port <n> --host <host>. - Add tests for JSON route behavior and command output.
Task 4: Static Viewer UI#
Files:
- Create:
viewer/index.html - Create:
viewer/app.js - Create:
viewer/app.css - Modify:
package.json
Steps:
- Build a three-column shell: left navigation/search, central reader, right metadata rail.
- Use an OpenAlmanac-inspired warm paper palette and serif article typography.
- Render markdown headings, paragraphs, lists, code blocks, inline code, links, and
[[wikilinks]]. - Add page/topic/search/file navigation without a frontend build step.
- Add
viewerto packagefiles.
Task 5: Verification#
Files:
- Existing repo files only.
Steps:
- Run focused tests for query, API, serve, show.
- Run
npm run lint. - Run
npm test. - Run
npm run build. - Start
almanac serve --port 0through the test harness or built CLI path if needed.