From 4343e8760b1f30bd8ae538982b9746f9208c0d02 Mon Sep 17 00:00:00 2001 From: Mikey-Ku Date: Thu, 22 Oct 2026 13:38:46 -0400 Subject: [PATCH 01/10] feat: Settings sections in the sidebar, the docs as a document page, and the docs brought up to date Shell takes a page's own sections (sections prop) and lists them in the sidebar under the pages: Settings' Account, General, Appearance, Models and Agents live there now instead of a second nav inside the page. /docs renders the repo's README and docs/*.md with marked on the server, one section per file, with each file's headings as chips (folded past 16), links between docs rewritten to their sections and the app's icon served by the app; the packaged app copies the Markdown into the bundle so the page works there too. The sidebar's foot link goes to GitHub. DEMO.md no longer mentions the old Connect step or the All applications menu; LEARNING.md's map covers build plans, test plans, the narrator, layers, MCP and the Mac app. --- CLAUDE.md | 2 +- docs/DATA.md | 2 +- docs/DEMO.md | 10 +- docs/LEARNING.md | 15 ++- electron/pack.cjs | 4 + package.json | 1 + pnpm-lock.yaml | 10 ++ src/app/docs/DocsView.tsx | 90 +++++++++++++++ src/app/docs/docs.css | 184 ++++++++++++++++++++++++++++++ src/app/docs/page.tsx | 101 ++++++++++++++++ src/app/settings/SettingsView.tsx | 25 ++-- src/app/shell.css | 25 ++++ src/components/Shell.tsx | 33 +++++- 13 files changed, 468 insertions(+), 34 deletions(-) create mode 100644 src/app/docs/DocsView.tsx create mode 100644 src/app/docs/docs.css create mode 100644 src/app/docs/page.tsx diff --git a/CLAUDE.md b/CLAUDE.md index 8fafdb6..2e17ef7 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -23,7 +23,7 @@ Planning tool for beginners building web apps with AI builders. A deterministic - `src/ai/` is server-only: `config.ts` (model, client, errors), `providers.ts` (the registry of built-in AIs: Claude, OpenAI, Gemini, and Ollama on this computer; each has a key name, a model name (`STACKWISE_MODEL`, `OPENAI_MODEL`, ...) and the models Settings offers; adding a model is one entry; Ollama stays off until `OLLAMA_MODEL` is set; answers are checked against the same Zod schemas). The Claude model is `aiModel()` in `config.ts`, read on every call so a pick in Settings applies at once, `prefill.ts`, `explain.ts`, `talk.ts` (each has a Claude path and a `provider*` path), `rate-limit.ts`. Routes in `src/app/api/` take an optional `provider`, pick the first with a key (Claude first) when it's left out, and always fall back to keywords or a template. - `src/components/store.ts` is all plan state as a pure reducer (plans, undo/redo, import, migration from v1); `usePlans.ts` wires it to the engine. `answerers.ts` is the one list of who can answer (terminal agents, built-in AIs, StackWise facts), read by `ConnectPanel.tsx` (the first screen and the connection pill in the top bar), and `AskPanel.tsx`. `templates.ts` holds the starting points by kind of app (web, iOS, Android, both, AI, store, internal tool), applied with `applyTemplate`. `AddPart.tsx` is the n8n-style picker (A key, the + in the dock and on the app card). `Workspace.tsx` puts the canvas full screen and floats everything over it: the top bar, the dock, one left panel (Overview, Parts, Checklist, Learn), Details on the right, the planner sheet, the Ask panel, and the right-click menus (built there, rendered by `ContextMenu.tsx`). - `src/local/` is this computer: `home.ts` (`~/.stackwise` or `STACKWISE_HOME`: `profile.json`, `library.json`, `plans/`, `isDesktop`, `MCP_URL`), `scan.ts` (projects found one level under the profile's folders), `agents.ts` (which coding agents are installed, from `which` and `--version`, and whether Claude Code points at StackWise, read from `~/.claude.json`). Routes: `/api/profile`, `/api/library` (the browser store's copy of every plan goes to disk; `src/components/library.ts` merges the two, newest per plan wins, and `savedStore.ts` pushes and pulls), `/api/projects`, `/api/agents` (connect runs `claude mcp add --transport http --scope user stackwise `). -- `src/components/Shell.tsx` and `src/app/shell.css` are the sidebar pages: `/projects` (`ProjectsView.tsx`: your plans, found projects, examples; rendered on the server from `readDiskLibrary` and `readMe` in `src/local/`, then the browser's copy of the store joins in with `adoptLibrary`, so the page comes up whole), `/settings` (`SettingsView.tsx`: sections picked from a list on the left and kept in the URL hash: Account, General, Appearance, Models (who answers in Ask; a key and a model per built-in AI, both saved through `/api/keys`), Agents (coding agent cards, Connect, the MCP server)), `/learn` (`LearnView.tsx`, with its table of contents where Settings has its section list), and `/review`. The canvas stays full screen on `/`. +- `src/components/Shell.tsx` and `src/app/shell.css` are the sidebar pages: `/projects` (`ProjectsView.tsx`: your plans, found projects, examples; rendered on the server from `readDiskLibrary` and `readMe` in `src/local/`, then the browser's copy of the store joins in with `adoptLibrary`, so the page comes up whole), `/settings` (`SettingsView.tsx`: sections picked from a list on the left and kept in the URL hash: Account, General, Appearance, Models (who answers in Ask; a key and a model per built-in AI, both saved through `/api/keys`), Agents (coding agent cards, Connect, the MCP server)), `/learn` (`LearnView.tsx`), `/docs` (`src/app/docs/`: the repo's README and docs/*.md rendered with `marked` on the server, one section per file, headings given ids, links to other docs rewritten to their section; `electron/pack.cjs` copies the Markdown into the bundle so the page works in the app), and `/review`. A page's own sections (Settings' Account, General...; the docs' files) go in the sidebar under the pages through `Shell`'s `sections` prop. The canvas stays full screen on `/`. - `electron/main.cjs` starts the standalone server (packaged: `Resources/standalone/server.js` run with `ELECTRON_RUN_AS_NODE`; in development, `pnpm dev`), waits for it, opens the window and the menu bar item, and kills the server's process group on quit. `preload.cjs` sets `html[data-desktop]`, which the CSS uses for the title bar inset. `after-pack.cjs` copies the standalone into the bundle; `electron/package.json` is the builder project (no dependencies, so only four files are packed). - `src/engine/layers.ts` is the four layers around the app (runs, people, data, outside): `layerOf`, `layeredLayout` (tidy up) and `layerBox` (the zone drawn behind each layer, a `zone` node in `PlanCanvas.tsx` that nothing can select or drag). - `src/engine/narrate.ts` turns two moments of a plan into the chat's narration of a change: what changed, as if the person typed it, then what it did (parts and why, checks that appeared or went away, verdict, cost), from `planDiff` and the facts alone. `Workspace` keeps the last moment in a ref and posts the two turns on every plan change (not on a plan switch). diff --git a/docs/DATA.md b/docs/DATA.md index 76e583b..f716583 100644 --- a/docs/DATA.md +++ b/docs/DATA.md @@ -104,7 +104,7 @@ Neither one marks a fact `verified`. Only a person does. The review page does this one fact at a time: run `pnpm dev`, open `/review` (or "Review facts" in the plan menu), and work down the list with J and K, Y for "Matches the source" and N for "Something's off". -- **What comes first.** The facts the default plans rest on: StackWise plans every template and the Pitchwell example, and for each option they end up with it lists the facts the rules and the ranking read (the part's `required_facts` and the score's criteria). The facts used by the most defaults are at the top. "All" adds every other fact of a fully researched option. The Overview says how many facts behind the open plan are reviewed. +- **What comes first.** The facts the default plans rest on: StackWise plans every template and the Pitchwell example, and for each option they end up with it lists the facts the rules and the ranking read (the part's `required_facts` and the score's criteria). The facts used by the most defaults are at the top. "All" adds every other fact of a fully researched option. - **"Matches the source"** sets `status` to `"verified"` and adds `"reviewed": ""` under it. Nothing else in the file changes, so the diff is those two lines. - **"Something's off"** leaves the fact a draft (a verified one goes back to draft) and saves your note in `.stackwise/review-flags.json`, which is gitignored. Fix `value` and `note`, update `retrieved`, then confirm it on the page, which clears the flag. - `pnpm check:sources --apply` drops `reviewed` from any fact whose value it changes, since the review was of the old value. diff --git a/docs/DEMO.md b/docs/DEMO.md index 42c0115..f36f5ab 100644 --- a/docs/DEMO.md +++ b/docs/DEMO.md @@ -2,7 +2,7 @@ One run through StackWise for a video, a class or an interview. It works with no API key and no agent connected; the steps that need Claude Code say so. -**Before you start:** `pnpm dev`, open http://localhost:4310 in a fresh browser profile (or clear site data), and skip Connect. +**Before you start:** open StackWise (the Mac app, or `pnpm dev` and http://localhost:4310), press **New project** on the Projects page, and leave the chat pane open on the left: it narrates every change as you go. ## 0:00 The problem (15 seconds) @@ -20,20 +20,20 @@ One run through StackWise for a video, a class or an interview. It works with no ## 0:35 Read the plan (25 seconds) 1. The canvas: the app in the middle, a card per part, a line per connection with a check. -2. The pill at the top: monthly cost and how many problems. +2. The toolbar at the top: monthly cost and how many problems. The chat pane on the left has already written up what the plan did with each answer. 3. Click **Stripe**. Details shows the stats at this size, the fee per sale, and the check "You handle sales tax", with its source. ## 1:00 Break it on purpose (20 seconds) 1. Right-click **Firestore**, **Switch to**, **SQLite file**. Hosting quietly moves from Netlify to Fly.io: SQLite keeps its data in a file, so StackWise re-plans the host to one with a permanent disk. 2. Right-click **Fly.io**, **Switch to**, **Netlify**, to force the bad pairing. The line between them turns red: "Your data would disappear". Netlify gives the app no permanent disk, so anything people save is lost on the next deploy. The fix and the sources are in Details. -3. Press Cmd+Z twice. It's back. +3. Press Cmd+Z twice. It's back. Each step is in the chat as a line from you and an explanation from the facts. "No AI decided that. A rule read two facts, the host's disk and where the database keeps its data, each with a source, and the search picked around it until I forced it." ## 1:20 Ask (15 seconds) -Right-click **Stripe**, **Ask about this**, and click **Which keys does it need?** The answer comes from StackWise's own facts: the variable names, where each value comes from, and which one the browser can read. +Right-click **Stripe**, **Ask about this**, and press **Which keys does it need?** in the chat pane. With the provider set to StackWise (no AI), the answer comes from StackWise's own facts: the variable names, where each value comes from, and which one the browser can read. Switch the provider bubble to Claude to have a model explain the same brief. ## 1:35 Hand it to a builder (25 seconds) @@ -47,4 +47,4 @@ Right-click **Stripe**, **Ask about this**, and click **Which keys does it need? ## Longer version -Open **All applications** from the plan menu and **Open example** on Pitchwell: a dozen parts, a note on every one, and one warning to walk through. Turn on **Advanced tools** (the wrench in the dock) to show a second service in one part and a line drawn between two parts. +On the **Projects** page, open the Pitchwell example: a dozen parts, a note on every one, and one warning to walk through. Turn on **Advanced tools** (the wrench in the dock) to show a second service in one part and a line drawn between two parts. Settings, Models shows how a key and a model are set per provider; Settings, Agents connects Claude Code in one press. diff --git a/docs/LEARNING.md b/docs/LEARNING.md index b6b9205..0141e87 100644 --- a/docs/LEARNING.md +++ b/docs/LEARNING.md @@ -21,10 +21,15 @@ Facts about services live in JSON files; rules read those facts to decide whethe | 9 | `src/engine/summary.ts`, `src/ai/explain.ts` | The plan brief, explained by a template or by Claude. | | 10 | `src/engine/spec.ts`, `decisions.ts`, `checklist.ts` | The spec pack, the decision record and the build checklist. | | 10b | `src/engine/wiring.ts` | What runs along each line: the environment variables the app reads to reach each service, and the `.env` file text. | -| 10c | `src/engine/talk.ts`, `src/ai/talk.ts` | Talking one part through: the brief for that part, answers from StackWise's facts, or Claude answering from the brief. | -| 11 | `src/components/store.ts` | Every saved plan, undo and redo, share links and imports, as a pure reducer. | -| 12 | `src/components/*` | The workspace: planner, canvas, options, details, Learn, Checklist. | -| 13 | `scripts/*` | Evals, the source checker and the option drafter. | +| 10c | `src/engine/talk.ts`, `src/ai/talk.ts` | Talking one part through: the brief for that part, answers from StackWise's facts, or a model answering from the brief. | +| 10d | `src/engine/buildplan.ts`, `testplan.ts` | The canvas as ordered build tasks, and a test plan for each: what to check, how to keep the real service out, what not to test. | +| 10e | `src/engine/narrate.ts` | What a change did, for the chat pane: the parts that changed and why, the checks that appeared or went away, the cost before and after. | +| 10f | `src/engine/layers.ts` | The four layers the canvas groups parts into: where it runs, people, data, outside services. | +| 11 | `src/components/store.ts` | Every saved plan, undo and redo, share links and imports, as a pure reducer; `~/.stackwise` on disk is the record (`src/local/`). | +| 12 | `src/components/*`, `src/app/*` | The workspace (canvas, chat pane, panels) and the pages (Projects, Settings, Learn, Documentation, Review). | +| 13 | `src/mcp/*` | The MCP server: 15 tools over the engine, pairing with a coding agent, shared plans. | +| 14 | `electron/*` | The Mac app around it all. | +| 15 | `scripts/*` | Evals, the source checker and the option drafter. | ## Following one app through @@ -35,7 +40,7 @@ Say the description is: *"A booking app for my barber shop. Customers log in, pi 3. **Needed slots.** `neededSlots` turns yes answers into parts: login adds Login and Database, paying adds Payments, uploads add File storage, email adds Email, your own address adds Domain name, pulling data from other websites adds Web scraping, and wanting usage numbers or error alerts adds Analytics or Error monitoring. Framework and Hosting are always needed. Background jobs and a phone app are optional parts you add yourself. 4. **Search.** `recommend` tries combinations of fully researched options for those parts and keeps the best total. A blocked pair costs 1000 points, so it loses unless nothing else works. 5. **Verdicts.** For the winning plan, `evaluatePlan` runs every rule. If the host can't run scheduled jobs and there's no jobs service, "No built-in way to run things on a schedule" appears; drag a jobs service onto the canvas and it clears. -6. **Canvas.** Each card shows the worst verdict touching that part. The line from the app shows that part's own checks. Problems between two parts get their own dashed line. +6. **Canvas.** Each card shows the worst verdict touching that part, in one of four layers around the app. The line from the app shows that part's own checks. Problems between two parts get their own dashed line. Every change lands in the chat pane as a line from you and an explanation from the facts (`narrate.ts`). 7. **Leaving.** The spec pack lists the stack with its strongest reasons, turns every warning and note with builder guidance into a rule, orders the build, renames environment variables for your framework, and writes a decision record for every part. The Checklist panel tracks the same steps as you do them. ## Ideas to be able to explain diff --git a/electron/pack.cjs b/electron/pack.cjs index 32ac251..5834fa1 100644 --- a/electron/pack.cjs +++ b/electron/pack.cjs @@ -27,6 +27,10 @@ for (const [from, to] of [ fs.rmSync(path.join(out, to), { recursive: true, force: true }); fs.cpSync(path.join(root, from), path.join(out, to), { recursive: true, dereference: true }); } +// The Documentation page reads the repo's Markdown, so it comes along (the text, not the images). +fs.mkdirSync(path.join(out, "docs"), { recursive: true }); +fs.copyFileSync(path.join(root, "README.md"), path.join(out, "README.md")); +for (const name of fs.readdirSync(path.join(root, "docs")).filter((f) => f.endsWith(".md"))) fs.copyFileSync(path.join(root, "docs", name), path.join(out, "docs", name)); // Nothing of the person's goes into the bundle: no keys, no state. for (const stray of [".env.local", ".env", ".stackwise"]) fs.rmSync(path.join(out, stray), { recursive: true, force: true }); diff --git a/package.json b/package.json index c35f9b6..c246f11 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@xyflow/react": "^12.11.0", "fflate": "^0.8.3", "html-to-image": "1.11.11", + "marked": "^18.1.1", "next": "16.3.4", "react": "19.2.8", "react-dom": "19.2.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b69eff8..daf7285 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -124,6 +124,9 @@ importers: html-to-image: specifier: 1.11.11 version: 1.11.11 + marked: + specifier: ^18.1.1 + version: 18.1.1 next: specifier: 16.3.4 version: 16.3.4(@babel/core@7.29.7(supports-color@7.2.0))(@types/node@25.9.6)(react-dom@19.2.8(react@19.2.8))(react@19.2.8) @@ -2599,6 +2602,11 @@ packages: magic-string@0.30.21: resolution: {integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==} + marked@18.1.1: + resolution: {integrity: sha512-zEGgrtUG8crk+TrMacJSVABU4DYDDkS8uqgU3ohrn/2fW9C2AEfUrO3m6IhpIpQpl7YcVpiXXC9cSMWDANT3dg==} + engines: {node: '>= 20'} + hasBin: true + matcher@3.0.0: resolution: {integrity: sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==} engines: {node: '>=10'} @@ -6251,6 +6259,8 @@ snapshots: dependencies: '@jridgewell/sourcemap-codec': 1.6.0 + marked@18.1.1: {} + matcher@3.0.0: dependencies: escape-string-regexp: 4.0.0 diff --git a/src/app/docs/DocsView.tsx b/src/app/docs/DocsView.tsx new file mode 100644 index 0000000..358297b --- /dev/null +++ b/src/app/docs/DocsView.tsx @@ -0,0 +1,90 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { Shell, type Me, type ShellSections } from "@/components/Shell"; + +/** + * The documentation, as a document: every Markdown file in the repo's docs, rendered in order on + * one page, with the documents as sections in the sidebar and each document's headings under its + * title. The hash picks a section (/docs#mcp), and the sidebar follows as you scroll. + */ + +export interface Doc { + id: string; + title: string; + file: string; + html: string; + headings: { id: string; text: string }[]; +} + +/** Past this many headings (the decisions, one per heading), the contents fold up behind a line. */ +const MANY_HEADINGS = 16; + +function Contents({ doc }: { doc: Doc }) { + return ( + + ); +} + +export default function DocsView({ me, docs, repo }: { me: Me | null; docs: Doc[]; repo: string }) { + const [active, setActive] = useState(docs[0]?.id ?? "overview"); + + // The sidebar follows the section in view. + useEffect(() => { + const sections = docs.map((d) => document.getElementById(d.id)).filter((el): el is HTMLElement => Boolean(el)); + if (sections.length === 0) return; + const observer = new IntersectionObserver( + (entries) => { + const seen = entries.filter((e) => e.isIntersecting).sort((a, b) => a.boundingClientRect.top - b.boundingClientRect.top); + if (seen[0]) setActive(seen[0].target.id); + }, + { rootMargin: "-20% 0px -70% 0px" }, + ); + for (const el of sections) observer.observe(el); + return () => observer.disconnect(); + }, [docs]); + + const sidebar: ShellSections = { title: "Documentation", items: docs.map((d) => ({ id: d.id, label: d.title, href: `/docs#${d.id}`, active: active === d.id })) }; + + return ( + +
+
+

Documentation

+

+ The same files as in the repo, read from this copy of StackWise. Edit them on{" "} + + GitHub + + . +

+
+
+ {docs.map((doc) => ( +
+
+

{doc.title}

+ + {doc.file} + +
+ {doc.headings.length > 1 && doc.headings.length <= MANY_HEADINGS && } + {doc.headings.length > MANY_HEADINGS && ( +
+ Contents, {doc.headings.length} headings + +
+ )} + {/* The repo's own Markdown, rendered on the server; nothing here comes from a person's input. */} +
+
+ ))} +
+ ); +} diff --git a/src/app/docs/docs.css b/src/app/docs/docs.css new file mode 100644 index 0000000..12cb639 --- /dev/null +++ b/src/app/docs/docs.css @@ -0,0 +1,184 @@ +/* The documentation page: the repo's Markdown as readable documents, one section per file. */ +.doc { + display: flex; + flex-direction: column; + gap: 18px; + max-width: 780px; + padding-top: 28px; + border-top: 0.5px solid var(--ws-glass-line); + scroll-margin-top: 24px; +} +.doc:first-of-type { + padding-top: 0; + border-top: 0; +} +.doc__head { + display: flex; + flex-wrap: wrap; + align-items: baseline; + justify-content: space-between; + gap: 8px 16px; +} +.doc__title { + margin: 0; + font-size: 26px; + font-weight: 700; + letter-spacing: -0.02em; +} +.doc__file code { + color: var(--mk-text-faint); + font-family: var(--mk-font-mono); + font-size: 12px; +} +.doc__toc { + display: flex; + flex-wrap: wrap; + gap: 6px; +} +.doc__toc a { + padding: 4px 10px; + border-radius: 999px; + background: var(--ws-fill); + color: var(--mk-text-muted); + font-size: 12.5px; + text-decoration: none; +} +.doc__toc a:hover { + background: var(--ws-fill-hover); + color: var(--mk-text); +} +.doc__contents summary { + cursor: pointer; + color: var(--mk-text-muted); + font-size: 13px; + user-select: none; +} +.doc__contents[open] summary { + margin-bottom: 10px; +} + +/* The body: the Markdown's own structure, in the app's type. */ +.doc__body { + font-size: 15px; + line-height: 1.6; + overflow-wrap: anywhere; +} +.doc__body > :first-child { + margin-top: 0; +} +.doc__body h2 { + margin: 0 0 6px; + font-size: 22px; + font-weight: 700; + letter-spacing: -0.02em; +} +.doc__body h3 { + margin: 32px 0 8px; + font-size: 18px; + font-weight: 650; + letter-spacing: -0.01em; + scroll-margin-top: 24px; +} +.doc__body h4 { + margin: 24px 0 6px; + font-size: 15px; + font-weight: 650; + scroll-margin-top: 24px; +} +.doc__body h5, +.doc__body h6 { + margin: 18px 0 4px; + font-size: 14px; + font-weight: 650; +} +.doc__body p { + margin: 0 0 14px; +} +.doc__body ul, +.doc__body ol { + margin: 0 0 14px; + padding-left: 1.4em; +} +.doc__body li { + margin: 4px 0; +} +.doc__body li > p { + margin: 0; +} +.doc__body a { + color: var(--mk-accent); + text-decoration: none; +} +.doc__body a:hover { + text-decoration: underline; +} +.doc__body strong { + font-weight: 650; +} +.doc__body code { + padding: 1px 5px; + border-radius: 5px; + background: var(--mk-surface-sunk); + font-family: var(--mk-font-mono); + font-size: 0.86em; +} +.doc__body pre { + margin: 0 0 16px; + padding: 12px 14px; + overflow-x: auto; + border-radius: 12px; + background: var(--mk-surface-sunk); + font-size: 12.5px; + line-height: 1.5; +} +.doc__body pre code { + padding: 0; + background: transparent; + font-size: inherit; +} +.doc__body blockquote { + margin: 0 0 14px; + padding: 2px 14px; + border-left: 3px solid var(--mk-line-strong); + color: var(--mk-text-muted); +} +.doc__body table { + width: 100%; + margin: 0 0 18px; + border-collapse: collapse; + font-size: 14px; +} +.doc__body th, +.doc__body td { + padding: 8px 10px; + border-bottom: 0.5px solid var(--ws-glass-line); + text-align: left; + vertical-align: top; +} +.doc__body th { + color: var(--mk-text-muted); + font-weight: 600; +} +.doc__body img { + max-width: 100%; + height: auto; + margin: 4px 0 16px; + border-radius: 12px; + border: 0.5px solid var(--ws-glass-line); +} +.doc__body hr { + margin: 24px 0; + border: 0; + border-top: 0.5px solid var(--ws-glass-line); +} +.doc__body p:has(> img:only-child) { + text-align: center; +} +@media (max-width: 720px) { + .doc__body { + font-size: 14.5px; + } + .doc__title { + font-size: 22px; + } +} diff --git a/src/app/docs/page.tsx b/src/app/docs/page.tsx new file mode 100644 index 0000000..f75ff9f --- /dev/null +++ b/src/app/docs/page.tsx @@ -0,0 +1,101 @@ +import fs from "node:fs"; +import path from "node:path"; +import type { Metadata } from "next"; +import { Marked, type Tokens } from "marked"; +import { readMe } from "@/local/home"; +import DocsView, { type Doc } from "./DocsView"; +import "../shell.css"; +import "./docs.css"; + +export const metadata: Metadata = { + title: "Documentation | StackWise", + description: "StackWise's documentation: the overview, the MCP tools, the facts and rules, how it works, the decisions and the demo.", +}; + +// The docs are files in the repo; read them on every request so an edit shows on refresh. +export const dynamic = "force-dynamic"; + +/** The documents, in reading order. Each is a Markdown file in the repo, shown as one section. */ +const DOCS: { id: string; title: string; file: string }[] = [ + { id: "overview", title: "Overview", file: "README.md" }, + { id: "mcp", title: "MCP and agents", file: "docs/MCP.md" }, + { id: "data", title: "Facts and rules", file: "docs/DATA.md" }, + { id: "how", title: "How it works", file: "docs/LEARNING.md" }, + { id: "decisions", title: "Decisions", file: "docs/DECISIONS.md" }, + { id: "demo", title: "The demo", file: "docs/DEMO.md" }, +]; + +const REPO = "https://github.com/Mikey-Ku/StackWise"; +const RAW = "https://raw.githubusercontent.com/Mikey-Ku/StackWise/main"; + +const slug = (text: string) => + text + .toLowerCase() + .replace(/<[^>]+>/g, "") + .replace(/[^a-z0-9]+/g, "-") + .replace(/^-|-$/g, ""); + +/** + * A link inside a doc: another doc becomes its section here (its own anchors too), a repo file + * opens on GitHub, the web stays the web. Heading ids carry the document's id, so a `#heading` + * link inside a document points at that document's heading. + */ +function rewriteHref(href: string, from: string): string { + if (/^(https?:|mailto:)/.test(href)) return href; + const [file, anchor] = href.split("#"); + if (!file) return `#${from}-${anchor ?? ""}`; + const clean = file.replace(/^(\.\.?\/)+/, ""); + const doc = DOCS.find((d) => d.file === clean || d.file === `docs/${clean}`); + if (doc) return `/docs#${anchor ? `${doc.id}-${anchor}` : doc.id}`; + return `${REPO}/blob/main/${clean.replace(/^\//, "")}`; +} + +/** An image in a doc: the app's own icon is served by the app; anything else in the repo comes from GitHub. */ +const imageSrc = (href: string) => (/^(https?:|data:)/.test(href) ? href : href.replace(/^\.?\//, "") === "src/app/icon.svg" ? "/icon.svg" : `${RAW}/${href.replace(/^\.?\//, "")}`); + +function render(id: string, markdown: string): { html: string; headings: { id: string; text: string }[] } { + const headings: { id: string; text: string }[] = []; + const marked = new Marked({ gfm: true }); + marked.use({ + renderer: { + heading({ tokens, depth }: Tokens.Heading) { + const text = this.parser.parseInline(tokens); + const anchor = `${id}-${slug(text)}`; + if (depth === 2) headings.push({ id: anchor, text: text.replace(/<[^>]+>/g, "") }); + // The file's own title is the section's title in the sidebar; inside, start one level down. + const level = Math.min(6, depth + 1); + return `${text}\n`; + }, + link({ href, title, tokens }: Tokens.Link) { + const text = this.parser.parseInline(tokens); + const to = rewriteHref(href, id); + const external = /^https?:/.test(to); + return `${text}`; + }, + image({ href, title, text }: Tokens.Image) { + return `${text}`; + }, + }, + }); + // GitHub's blocks (light and dark screenshots) are plain HTML in the file: keep the + // light one. Raw tags point at files in the repo too, so their src gets the same treatment. + const source = markdown + .replace(/[\s\S]*?(]*>)[\s\S]*?<\/picture>/g, "$1") + .replace(/(]*?src=")([^"]+)(")/g, (_m, before: string, src: string, after: string) => `${before}${imageSrc(src)}${after}`); + const html = marked.parse(source) as string; + return { html, headings }; +} + +export default function DocsPage() { + const docs: Doc[] = DOCS.flatMap((doc) => { + let text: string; + try { + text = fs.readFileSync(path.join(process.cwd(), doc.file), "utf8"); + } catch { + return []; + } + const { html, headings } = render(doc.id, text); + return [{ id: doc.id, title: doc.title, file: doc.file, html, headings }]; + }); + return ; +} diff --git a/src/app/settings/SettingsView.tsx b/src/app/settings/SettingsView.tsx index dd73394..20fcaea 100644 --- a/src/app/settings/SettingsView.tsx +++ b/src/app/settings/SettingsView.tsx @@ -6,7 +6,7 @@ import { providersOf, recipientsFor, saveDefaultAnswerer, saveProviderSetting, S import { KeyForm } from "@/components/ConnectPanel"; import { Icon, type IconName } from "@/components/icons"; import type { AiStatus, ProviderInfo } from "@/components/Planner"; -import { Shell, shortPath, useMe, type Me } from "@/components/Shell"; +import { Shell, shortPath, useMe, type Me, type ShellSections } from "@/components/Shell"; import { useTheme, type Theme } from "@/components/ThemeSwitch"; import { copyText, cx } from "@/components/ui"; import { FEATURED_AGENTS, pairInstructions } from "@/mcp/pairing"; @@ -351,30 +351,19 @@ export default function SettingsView({ builders, priorities, sizes }: { builders ); + const sidebar: ShellSections = { title: "Settings", items: SECTIONS.map((s) => ({ id: s.id, label: s.label, href: `/settings#${s.id}`, icon: s.icon, active: section === s.id, onSelect: () => show(s.id) })) }; + return ( - +
-

Settings

-

Saved in {me ? shortPath(me.dir, me.home) : "~/.stackwise"} on this computer.

+

{current.label}

+

{current.blurb}

-
- - +
-
-

{current.label}

-

{current.blurb}

-
{section === "account" && ( <> diff --git a/src/app/shell.css b/src/app/shell.css index 28f7102..45b8401 100644 --- a/src/app/shell.css +++ b/src/app/shell.css @@ -343,6 +343,28 @@ body:has(.shell) { margin-top: 12px; } +/* A page's own sections in the sidebar, under the pages. */ +.shell-subnav { + display: flex; + flex-direction: column; + gap: 2px; + padding-top: 6px; + border-top: 0.5px solid var(--ws-glass-line); +} +.shell-subnav__title { + margin: 8px 0 4px; + padding: 0 10px; + color: var(--mk-text-faint); + font-size: 11px; + font-weight: 600; + letter-spacing: 0.04em; + text-transform: uppercase; +} +.shell-subnav__item { + width: 100%; + font-size: 13.5px; +} + /* Found under your folders: a quieter card than a plan. */ .apps-card--found .apps-icon { background: var(--mk-surface-sunk); @@ -414,6 +436,9 @@ html[data-desktop] .shell-side .shell-me { gap: 40px; align-items: start; } +.set-layout--one { + grid-template-columns: minmax(0, 1fr); +} .set-nav { position: sticky; top: 44px; diff --git a/src/components/Shell.tsx b/src/components/Shell.tsx index ea52f89..95ffb06 100644 --- a/src/components/Shell.tsx +++ b/src/components/Shell.tsx @@ -47,10 +47,17 @@ export const shortPath = (p: string, home: string | undefined) => (home && p.sta const NAV: { href: string; label: string; icon: IconName }[] = [ { href: "/projects", label: "Projects", icon: "grid" }, { href: "/learn", label: "Learn", icon: "learn" }, + { href: "/docs", label: "Documentation", icon: "info" }, { href: "/review", label: "Review facts", icon: "checklist" }, ]; -export function Shell({ me, children }: { me: Me | null; children: React.ReactNode }) { +/** A page's own sections, shown in the sidebar under the pages: Settings' Account, General and so on. */ +export interface ShellSections { + title: string; + items: { id: string; label: string; href: string; active?: boolean; icon?: IconName; onSelect?: () => void }[]; +} + +export function Shell({ me, sections, children }: { me: Me | null; sections?: ShellSections; children: React.ReactNode }) { const pathname = usePathname() ?? ""; const name = me?.profile.name.trim() || me?.account || ""; const initial = (name || "S").slice(0, 1).toUpperCase(); @@ -78,10 +85,28 @@ export function Shell({ me, children }: { me: Me | null; children: React.ReactNo ))} + {sections && ( + + )}
- - - Documentation + + + GitHub From e1affa90d954262d62622b39e6128826bb3e01fb Mon Sep 17 00:00:00 2001 From: Mikey-Ku Date: Thu, 22 Oct 2026 13:50:04 -0400 Subject: [PATCH 02/10] fix: keep the repo out of the Mac app's standalone build Next's output file tracing followed the docs page's read of path.join(process.cwd(), doc.file) and copied the whole working folder into the standalone: the git history, release/ with the last dmg and the private CLAUDE.local.md, and the dmg went from 135 MB to 555 MB. The read now starts from docsRoot(), a lookup the bundler can't fold and the tracer can't evaluate (a plain x || process.cwd() was folded back to process.cwd()), so it traces nothing and pack.cjs copies the Markdown itself. Reads whose folder the tracer can't see had been tracing **/ globs over the repo all along, which put the copies of data/ inside release/, an empty .git and the old .stackwise/ into every dmg so far. In standalone mode next.config.ts now excludes those folders from every trace, and pack.cjs fails the build if .git or release/ turn up in the standalone. Verified from a copy of the app outside the repo: 45 MB of standalone, the pages served, no env files. --- CLAUDE.md | 1 + electron/pack.cjs | 8 ++++++++ next.config.ts | 12 +++++++++++- src/app/docs/page.tsx | 13 ++++++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 2e17ef7..b6caf09 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -94,5 +94,6 @@ Planning tool for beginners building web apps with AI builders. A deterministic - Side panels are 380px (Details) and 360px (left), 330px under 900px. Anything new in Details or the palette needs to wrap; long URLs and env var names in the checklist use `overflow-wrap: anywhere`. - Never run `claude mcp get` or `claude mcp list` from inside the server: Claude Code health-checks StackWise's MCP address while answering, and the request that spawned it is holding the server, so both wait forever. `/api/agents` reads `~/.claude.json` instead, and every other spawn is async. - The Mac app: `extraResources` in electron-builder leaves out `node_modules`, so `after-pack.cjs` copies the standalone into the bundle itself. pnpm's symlinks have to stay symlinks (Node resolves a package's dependencies from where the link points; copied as plain folders, next loses `@swc/helpers`), so `pack.cjs` copies with `cp -R` and makes every absolute link relative. Test the packaged server from outside the repo (copy the .app somewhere else first): inside it, a missing `node_modules` resolves to the repo's and hides the problem. +- Next's output file tracing follows every `fs` read it can evaluate, and copies what it finds into the standalone build. Two shapes bite. A known folder with a variable file (`path.join(process.cwd(), doc.file)`, the docs page) traces the whole working folder: `.git`, `release/` with the last dmg, `CLAUDE.local.md`, and the dmg went from 135 MB to 555 MB. A folder it can't see (a parameter, the home folder) becomes a `**/` glob over the repo, which matched the copies of `data/` inside `release/`, the empty `.git` and the old `.stackwise/`. So: the docs read starts from `docsRoot()` in `src/app/docs/page.tsx`, a lookup the bundler can't fold and the tracer can't evaluate (a plain `x || process.cwd()` was folded back to `process.cwd()`); `next.config.ts` excludes `.git`, `release/` and `.stackwise/` from every trace in standalone mode; `pack.cjs` copies `data/`, `public/`, the docs and README itself and fails the build if `.git` or `release` turn up in the standalone. Run `pnpm app:build` as one command: `node electron/pack.cjs | tail` followed by `&&` hides its exit code and the builder packs the bad folder. - The Mac app's window loads its page only after the server answers `/api/status`, and retries a load that fails. A `loadURL` sent while the server was still starting failed with ECONNREFUSED, and Electron shows nothing for a failed load: a blank gray window that never recovers. The window is created visible; created hidden and shown on `ready-to-show`, a page that never painted never fired it. - The browser store is a cache of `~/.stackwise`; the files are the record. A plan an agent changed (`updatedBy: "claude"`, newer) isn't overwritten by the browser's older copy, and deleting a plan has to go to disk too (`deletePlanOnDisk`), or it comes back on the next pull. Nothing is pushed to disk before the page has pulled the library once (`synced` in `savedStore.ts`): a fresh browser's blank starting plan, saved a moment after mount, used to land in the library as one more "Untitled app". A plan made on the Projects page is flushed (`flushStore`) before the canvas opens it, or the canvas's pull would drop it as blank. diff --git a/electron/pack.cjs b/electron/pack.cjs index 5834fa1..087250e 100644 --- a/electron/pack.cjs +++ b/electron/pack.cjs @@ -33,6 +33,14 @@ fs.copyFileSync(path.join(root, "README.md"), path.join(out, "README.md")); for (const name of fs.readdirSync(path.join(root, "docs")).filter((f) => f.endsWith(".md"))) fs.copyFileSync(path.join(root, "docs", name), path.join(out, "docs", name)); // Nothing of the person's goes into the bundle: no keys, no state. for (const stray of [".env.local", ".env", ".stackwise"]) fs.rmSync(path.join(out, stray), { recursive: true, force: true }); +// Next's file tracing follows fs reads it can evaluate. A read of `path.join(process.cwd(), )` +// once traced the whole repo into the standalone (`.git`, `release/` with the last dmg, private +// notes) and the dmg grew four times. If any of these is here, a page is reading files that way. +const leaked = [".git", "release", "CLAUDE.local.md", "CLAUDE.md", "evals", "scripts", "electron"].filter((name) => fs.existsSync(path.join(out, name))); +if (leaked.length) { + console.error(`The standalone build contains the repo (${leaked.join(", ")}): a page reads files from process.cwd() with a variable path, so Next traced the whole folder. Read through a root the tracer can't evaluate (see docsRoot in src/app/docs/page.tsx).`); + process.exit(1); +} let relinked = 0; const bad = []; diff --git a/next.config.ts b/next.config.ts index 81244af..d89895a 100644 --- a/next.config.ts +++ b/next.config.ts @@ -2,7 +2,17 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { // The Mac app runs the built site as a standalone server (electron/main.cjs). pnpm build stays as it is. - ...(process.env.STACKWISE_STANDALONE ? { output: "standalone" as const, outputFileTracingRoot: __dirname } : {}), + ...(process.env.STACKWISE_STANDALONE + ? { + output: "standalone" as const, + outputFileTracingRoot: __dirname, + // Next copies into the standalone every file a page's fs reads can be traced to. A read whose + // folder it can't evaluate (a project folder, the home folder) becomes a `**/` glob over + // this repo, which matched the copies of data/ inside release/ (the last app build), the empty + // .git and the old .stackwise. None of that belongs in the app; pack.cjs copies data/ itself. + outputFileTracingExcludes: { "*": [".git/**", "**/.git", "release/**", ".stackwise/**"] }, + } + : {}), devIndicators: false, // next dev would otherwise write its own AGENTS.md and CLAUDE.md blocks into this repo. agentRules: false, diff --git a/src/app/docs/page.tsx b/src/app/docs/page.tsx index f75ff9f..0ff2429 100644 --- a/src/app/docs/page.tsx +++ b/src/app/docs/page.tsx @@ -15,6 +15,17 @@ export const metadata: Metadata = { // The docs are files in the repo; read them on every request so an edit shows on refresh. export const dynamic = "force-dynamic"; +/** + * Where the Markdown is: the working folder (the repo, or the standalone folder in the Mac app, + * where pack.cjs copies the files). Written this way on purpose: Next's output file tracing + * follows every `fs.readFileSync(path.join(process.cwd(), ...))` it can evaluate, and with a + * variable file name it traced the whole working folder into the standalone build (the git + * history, the last dmg, private notes). A plain `a || process.cwd()` was folded back to + * `process.cwd()` by the bundler; a lookup in an array is something neither it nor the tracer + * evaluates, so the read traces nothing and pack.cjs copies the files itself. + */ +const docsRoot = () => [process.env.STACKWISE_DOCS_ROOT, process.cwd()].find(Boolean) as string; + /** The documents, in reading order. Each is a Markdown file in the repo, shown as one section. */ const DOCS: { id: string; title: string; file: string }[] = [ { id: "overview", title: "Overview", file: "README.md" }, @@ -90,7 +101,7 @@ export default function DocsPage() { const docs: Doc[] = DOCS.flatMap((doc) => { let text: string; try { - text = fs.readFileSync(path.join(process.cwd(), doc.file), "utf8"); + text = fs.readFileSync(path.join(docsRoot(), doc.file), "utf8"); } catch { return []; } From 8d1277568c74e016b3d9077c17b428ec565b92e6 Mon Sep 17 00:00:00 2001 From: Mikey-Ku Date: Thu, 22 Oct 2026 19:02:28 -0400 Subject: [PATCH 03/10] feat: Learn joins the Documentation page as its first group Learn and the docs were two pages with two structures for the same job. Now /docs is one document in two sidebar groups. Learn comes first, from data/learn.json: Start here (the layers), Parts of an app (one entry per part, with its chips for how to choose, common mistakes, key terms and further reading) and the Glossary (folded contents, 50 terms); then the project's docs as before. Every section has the same shape: title, the file it comes from, its headings as chips, the body. Shell takes more than one group of sections. The Learn page is gone; /learn redirects to /docs and the hash (#part-, #term-) comes along, so the canvas's zone labels, the dock's Learn button, Learn more on a part and the Mac app's Help menu all land where they did. Help, Documentation opens the page in the app now, with the GitHub link beside it. --- CLAUDE.md | 6 +- README.md | 2 +- electron/main.cjs | 2 +- next.config.ts | 7 +- src/app/docs/DocsView.tsx | 254 ++++++++++++-- src/app/docs/docs.css | 269 ++++++++++++++ src/app/docs/page.tsx | 26 +- src/app/learn/LearnView.tsx | 382 -------------------- src/app/learn/learn.css | 640 ---------------------------------- src/app/learn/page.tsx | 39 --- src/components/PlanCanvas.tsx | 2 +- src/components/Shell.tsx | 19 +- src/components/Workspace.tsx | 6 +- 13 files changed, 539 insertions(+), 1115 deletions(-) delete mode 100644 src/app/learn/LearnView.tsx delete mode 100644 src/app/learn/learn.css delete mode 100644 src/app/learn/page.tsx diff --git a/CLAUDE.md b/CLAUDE.md index b6caf09..ce1b7ab 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -16,14 +16,14 @@ Planning tool for beginners building web apps with AI builders. A deterministic ## Map - `data/` is the product's knowledge. `src/engine/load.ts` parses it with `schema.ts`; `integrity.ts` holds the cross-file checks `data.test.ts` enforces. -- `src/engine/talk.ts` builds the brief for talking one part through (connection, setup, checks, cost, facts, alternatives with verdicts, the note), answers from it without Claude (`answerFromFacts`), and drafts notes. `src/ai/talk.ts` asks Claude with that brief; `src/app/api/talk` falls back to the facts. `src/components/AskPanel.tsx` is the one place to talk to AI: a chat pane docked on the left of the canvas (Cmd+K, the Ask button, double-click, right-click "Ask about this"), one conversation per plan, with starters when it's empty and a composer whose answerer menu sends each message to a terminal agent, a built-in AI (with a model picker beside it), or StackWise's facts. On a window 1100px or wider a left panel (Overview, Parts, Checklist, Project, Learn) floats beside it (`.ws[data-ask="open"] .ws-float--left`); narrower than that, opening one closes the other (`roomForBoth`, `openPanel`, `toggleAsk` in Workspace). While the pane opens or closes, `data-settling` on `.ws` turns on 240ms transitions for the canvas, bar, dock, sheet and panel, so nothing pops; dragging the pane's edge stays immediate. `NoteEditor.tsx` is the note, in Details and in a connection. +- `src/engine/talk.ts` builds the brief for talking one part through (connection, setup, checks, cost, facts, alternatives with verdicts, the note), answers from it without Claude (`answerFromFacts`), and drafts notes. `src/ai/talk.ts` asks Claude with that brief; `src/app/api/talk` falls back to the facts. `src/components/AskPanel.tsx` is the one place to talk to AI: a chat pane docked on the left of the canvas (Cmd+K, the Ask button, double-click, right-click "Ask about this"), one conversation per plan, with starters when it's empty and a composer whose answerer menu sends each message to a terminal agent, a built-in AI (with a model picker beside it), or StackWise's facts. On a window 1100px or wider a left panel (Overview, Parts, Checklist, Project) floats beside it (`.ws[data-ask="open"] .ws-float--left`); narrower than that, opening one closes the other (`roomForBoth`, `openPanel`, `toggleAsk` in Workspace). While the pane opens or closes, `data-settling` on `.ws` turns on 240ms transitions for the canvas, bar, dock, sheet and panel, so nothing pops; dragging the pane's edge stays immediate. `NoteEditor.tsx` is the note, in Details and in a connection. - `src/engine/wiring.ts` turns a stack into connections and the environment variables that travel along each one (names, where each value comes from, whether the browser can read it), plus the `.env` file text. It never holds a value. - `src/engine/evaluate.ts` produces verdicts. `score.ts` ranks and searches (branch and bound, tested against brute force; domains rank on first-year and renewal price, payments on the fee from a $20 sale). `cost.ts` adds yearly and one-time costs (domains, `planning.json` `fees`) and counts a shared plan once (`shared_plans`, or one option in two parts). `followups.ts` picks questions. `stats.ts` turns facts into the stats on cards, nodes, Details, Compare and the strip above the canvas. `cost.ts`, `spec.ts`, `checklist.ts`, `decisions.ts`, `share.ts`, `staleness.ts`, `summary.ts`, `prefill.ts` do what their names say. - `data/logos.json` says where each logo comes from (Simple Icons slug or the service's site); `scripts/logos.ts` fetches them into `public/logos/`, which is committed. `Logo` in `src/components/ui.tsx` falls back to a letter if a file is missing. - `src/ai/` is server-only: `config.ts` (model, client, errors), `providers.ts` (the registry of built-in AIs: Claude, OpenAI, Gemini, and Ollama on this computer; each has a key name, a model name (`STACKWISE_MODEL`, `OPENAI_MODEL`, ...) and the models Settings offers; adding a model is one entry; Ollama stays off until `OLLAMA_MODEL` is set; answers are checked against the same Zod schemas). The Claude model is `aiModel()` in `config.ts`, read on every call so a pick in Settings applies at once, `prefill.ts`, `explain.ts`, `talk.ts` (each has a Claude path and a `provider*` path), `rate-limit.ts`. Routes in `src/app/api/` take an optional `provider`, pick the first with a key (Claude first) when it's left out, and always fall back to keywords or a template. -- `src/components/store.ts` is all plan state as a pure reducer (plans, undo/redo, import, migration from v1); `usePlans.ts` wires it to the engine. `answerers.ts` is the one list of who can answer (terminal agents, built-in AIs, StackWise facts), read by `ConnectPanel.tsx` (the first screen and the connection pill in the top bar), and `AskPanel.tsx`. `templates.ts` holds the starting points by kind of app (web, iOS, Android, both, AI, store, internal tool), applied with `applyTemplate`. `AddPart.tsx` is the n8n-style picker (A key, the + in the dock and on the app card). `Workspace.tsx` puts the canvas full screen and floats everything over it: the top bar, the dock, one left panel (Overview, Parts, Checklist, Learn), Details on the right, the planner sheet, the Ask panel, and the right-click menus (built there, rendered by `ContextMenu.tsx`). +- `src/components/store.ts` is all plan state as a pure reducer (plans, undo/redo, import, migration from v1); `usePlans.ts` wires it to the engine. `answerers.ts` is the one list of who can answer (terminal agents, built-in AIs, StackWise facts), read by `ConnectPanel.tsx` (the first screen and the connection pill in the top bar), and `AskPanel.tsx`. `templates.ts` holds the starting points by kind of app (web, iOS, Android, both, AI, store, internal tool), applied with `applyTemplate`. `AddPart.tsx` is the n8n-style picker (A key, the + in the dock and on the app card). `Workspace.tsx` puts the canvas full screen and floats everything over it: the top bar, the dock, one left panel (Overview, Parts, Checklist, Project), Details on the right, the planner sheet, the Ask panel, and the right-click menus (built there, rendered by `ContextMenu.tsx`). - `src/local/` is this computer: `home.ts` (`~/.stackwise` or `STACKWISE_HOME`: `profile.json`, `library.json`, `plans/`, `isDesktop`, `MCP_URL`), `scan.ts` (projects found one level under the profile's folders), `agents.ts` (which coding agents are installed, from `which` and `--version`, and whether Claude Code points at StackWise, read from `~/.claude.json`). Routes: `/api/profile`, `/api/library` (the browser store's copy of every plan goes to disk; `src/components/library.ts` merges the two, newest per plan wins, and `savedStore.ts` pushes and pulls), `/api/projects`, `/api/agents` (connect runs `claude mcp add --transport http --scope user stackwise `). -- `src/components/Shell.tsx` and `src/app/shell.css` are the sidebar pages: `/projects` (`ProjectsView.tsx`: your plans, found projects, examples; rendered on the server from `readDiskLibrary` and `readMe` in `src/local/`, then the browser's copy of the store joins in with `adoptLibrary`, so the page comes up whole), `/settings` (`SettingsView.tsx`: sections picked from a list on the left and kept in the URL hash: Account, General, Appearance, Models (who answers in Ask; a key and a model per built-in AI, both saved through `/api/keys`), Agents (coding agent cards, Connect, the MCP server)), `/learn` (`LearnView.tsx`), `/docs` (`src/app/docs/`: the repo's README and docs/*.md rendered with `marked` on the server, one section per file, headings given ids, links to other docs rewritten to their section; `electron/pack.cjs` copies the Markdown into the bundle so the page works in the app), and `/review`. A page's own sections (Settings' Account, General...; the docs' files) go in the sidebar under the pages through `Shell`'s `sections` prop. The canvas stays full screen on `/`. +- `src/components/Shell.tsx` and `src/app/shell.css` are the sidebar pages: `/projects` (`ProjectsView.tsx`: your plans, found projects, examples; rendered on the server from `readDiskLibrary` and `readMe` in `src/local/`, then the browser's copy of the store joins in with `adoptLibrary`, so the page comes up whole), `/settings` (`SettingsView.tsx`: sections picked from a list on the left and kept in the URL hash: Account, General, Appearance, Models (who answers in Ask; a key and a model per built-in AI, both saved through `/api/keys`), Agents (coding agent cards, Connect, the MCP server)), `/docs` (`src/app/docs/`: one document in two groups. Learn first, from `data/learn.json`: Start here (the layers), Parts of an app (one entry per part, `#part-`), Glossary (`#term-`); then the project's docs, the README and docs/*.md rendered with `marked` on the server, one section per file, headings given ids and shown as chips (folded past 16), links to other docs rewritten to their section; `electron/pack.cjs` copies the Markdown into the bundle so the page works in the app; `/learn` redirects there and the hash comes along), and `/review`. A page's own sections (Settings' Account, General...; the docs' files) go in the sidebar under the pages through `Shell`'s `sections` prop. The canvas stays full screen on `/`. - `electron/main.cjs` starts the standalone server (packaged: `Resources/standalone/server.js` run with `ELECTRON_RUN_AS_NODE`; in development, `pnpm dev`), waits for it, opens the window and the menu bar item, and kills the server's process group on quit. `preload.cjs` sets `html[data-desktop]`, which the CSS uses for the title bar inset. `after-pack.cjs` copies the standalone into the bundle; `electron/package.json` is the builder project (no dependencies, so only four files are packed). - `src/engine/layers.ts` is the four layers around the app (runs, people, data, outside): `layerOf`, `layeredLayout` (tidy up) and `layerBox` (the zone drawn behind each layer, a `zone` node in `PlanCanvas.tsx` that nothing can select or drag). - `src/engine/narrate.ts` turns two moments of a plan into the chat's narration of a change: what changed, as if the person typed it, then what it did (parts and why, checks that appeared or went away, verdict, cost), from `planDiff` and the facts alone. `Workspace` keeps the last moment in a ref and posts the two turns on every plan change (not on a plan switch). diff --git a/README.md b/README.md index f68ce54..cf25691 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Everything works without an API key. For an AI that reads your description, answ 3. **Read the canvas.** Your app in the middle, with its parts in four layers: where it runs (hosting, domain), people (login, payments, email, a phone app), data (database, files, background jobs), and outside services (AI, scraping, data sources, automations, analytics, monitoring). A check on a line means the connection works, `!` a warning, a cross that it doesn't, `?` that a fact is missing. A light flows along the lines that work. Drag any part where you want it; Tidy up puts the layers back. 4. **Click anything.** A card opens Details: why it was picked, every check with its reason and fix, the cost at your size, a comparison with the alternatives, and the facts behind it with their sources. A line shows what travels on it: the environment variables your code reads to reach that service. Right-click for everything else: ask, swap, let StackWise pick, learn, build this with your agent. 5. **Ask** (Cmd+K). A chat pane beside the canvas, one conversation per plan. Pick who answers in the composer: a coding agent in your terminal, a built-in AI with a key (and which of its models), or StackWise's own facts, which need nothing. -6. **The dock.** Overview (problems, close calls, accounts, cost at every size), Parts (every service by part, dragged onto the canvas; 101 options, 80 fully researched), Checklist (accounts, keys and build steps to tick off) and Learn (what each part of an app is, what matters when choosing, a glossary). +6. **The dock.** Overview (problems, close calls, accounts, cost at every size), Parts (every service by part, dragged onto the canvas; 101 options, 80 fully researched), Checklist (accounts, keys and build steps to tick off) and Learn (the documentation, opened at the parts of an app: what each is, what matters when choosing, a glossary). 7. **Settings.** Account (your name, where plans live), General (what a new plan starts with, the folders StackWise looks in), Appearance, Models (who answers in Ask; a key and a model per built-in AI) and Agents (your coding agents, one Connect button for Claude Code, and the MCP server's status). 8. **Build it.** Connect your agent and tell it to build from the plan, or export a project pack: the spec, setup, decisions, tasks with their tests, `.env.example`, and for Claude Code an agent per part, skills and `.mcp.json`. diff --git a/electron/main.cjs b/electron/main.cjs index f76c875..8c2d7f9 100644 --- a/electron/main.cjs +++ b/electron/main.cjs @@ -168,7 +168,7 @@ function appMenu() { { role: "editMenu" }, { role: "viewMenu" }, { role: "windowMenu" }, - { label: "Help", submenu: [{ label: "Documentation", click: () => shell.openExternal("https://github.com/Mikey-Ku/StackWise#readme") }, { label: "Learn", click: () => (showWindow(), win && win.loadURL(`${URL}/learn`)) }] }, + { label: "Help", submenu: [{ label: "Documentation", click: () => (showWindow(), win && win.loadURL(`${URL}/docs`)) }, { label: "StackWise on GitHub", click: () => shell.openExternal("https://github.com/Mikey-Ku/StackWise") }] }, ]), ); } diff --git a/next.config.ts b/next.config.ts index d89895a..701c997 100644 --- a/next.config.ts +++ b/next.config.ts @@ -16,9 +16,12 @@ const nextConfig: NextConfig = { devIndicators: false, // next dev would otherwise write its own AGENTS.md and CLAUDE.md blocks into this repo. agentRules: false, - // The applications page became Projects. + // The applications page became Projects; Learn joined the Documentation page (the hash, #part- or #term-, comes along). async redirects() { - return [{ source: "/apps", destination: "/projects", permanent: true }]; + return [ + { source: "/apps", destination: "/projects", permanent: true }, + { source: "/learn", destination: "/docs", permanent: true }, + ]; }, // No other site may show StackWise in a frame: a page could otherwise trick clicks on Start or Export. async headers() { diff --git a/src/app/docs/DocsView.tsx b/src/app/docs/DocsView.tsx index 358297b..5560d3b 100644 --- a/src/app/docs/DocsView.tsx +++ b/src/app/docs/DocsView.tsx @@ -1,14 +1,27 @@ "use client"; -import { useEffect, useState } from "react"; +import { Fragment, useEffect, useState, type ReactNode } from "react"; import { Shell, type Me, type ShellSections } from "@/components/Shell"; +import type { Learn, LearnLink, SlotId } from "@/engine/schema"; /** - * The documentation, as a document: every Markdown file in the repo's docs, rendered in order on - * one page, with the documents as sections in the sidebar and each document's headings under its - * title. The hash picks a section (/docs#mcp), and the sidebar follows as you scroll. + * The documentation, as one document. First how a web app fits together, in plain words, from + * data/learn.json (start here, the parts of an app, the glossary); then the repo's own Markdown + * docs. Every section has the same shape: a title, the file it comes from, its headings as chips, + * the body. The sidebar lists the sections in two groups and follows the one in view. The hash + * picks a section (/docs#mcp), a part (#part-database) or a term (#term-api). */ +type SlotEntry = NonNullable; +export type LearnPart = SlotEntry & { id: SlotId; label: string }; +export type LearnTerm = Learn["terms"][string] & { id: string; usedIn: { id: SlotId; label: string }[] }; +export type StartHere = NonNullable; +export interface LearnContent { + startHere: StartHere | null; + parts: LearnPart[]; + terms: LearnTerm[]; +} + export interface Doc { id: string; title: string; @@ -17,27 +30,214 @@ export interface Doc { headings: { id: string; text: string }[]; } -/** Past this many headings (the decisions, one per heading), the contents fold up behind a line. */ +type Heading = { id: string; text: string }; + +/** Past this many headings (the decisions, the glossary), the contents fold up behind a line. */ const MANY_HEADINGS = 16; +const LEARN_FILE = "data/learn.json"; -function Contents({ doc }: { doc: Doc }) { - return ( -
+ {learn.startHere && } + {learn.parts.length > 0 && } + {learn.terms.length > 0 && } {docs.map((doc) => ( -
-
-

{doc.title}

- - {doc.file} - -
- {doc.headings.length > 1 && doc.headings.length <= MANY_HEADINGS && } - {doc.headings.length > MANY_HEADINGS && ( -
- Contents, {doc.headings.length} headings - -
- )} + {/* The repo's own Markdown, rendered on the server; nothing here comes from a person's input. */}
-
+ ))} ); diff --git a/src/app/docs/docs.css b/src/app/docs/docs.css index 12cb639..99ed124 100644 --- a/src/app/docs/docs.css +++ b/src/app/docs/docs.css @@ -182,3 +182,272 @@ font-size: 22px; } } + +/* ---------- The Learn sections (data/learn.json), in the same body style ---------- */ +.doc__body .doc-lead { + margin: 0 0 14px; + font-size: 17px; + line-height: 1.5; + color: var(--mk-text); + text-wrap: pretty; +} +.doc-eyebrow { + margin: 0 0 6px; + font-size: 13px; + font-weight: 600; + color: var(--accent); +} +.doc-block { + margin-top: 24px; +} +.doc-block > p { + margin: 0; + color: var(--mk-text-muted); +} +.doc__body .doc-label { + margin: 0 0 10px; + font-size: 13px; + font-weight: 600; + letter-spacing: 0.01em; + color: var(--mk-text-muted); +} +.doc-anchor { + color: inherit !important; +} +.doc-anchor:hover { + text-decoration: none !important; +} + +/* One part: its own block under the section, with the heading the deep links point at. */ +.doc-part { + margin-top: 32px; + padding-top: 28px; + border-top: 0.5px solid var(--ws-glass-line); + scroll-margin-top: 24px; +} +.doc__body .doc-part h3 { + margin-top: 0; +} + +.doc-grid { + margin-top: 24px; + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 16px; +} +.doc-card { + padding: 18px 20px 16px; + border-radius: var(--mk-radius-lg); + background: var(--mk-surface); + border: 1px solid var(--mk-line); + box-shadow: var(--mk-shadow-1); +} +.doc-card--warn { + background: color-mix(in srgb, var(--mk-warn) 5%, var(--mk-surface)); + border-color: color-mix(in srgb, var(--mk-warn) 22%, var(--mk-line)); +} +.doc__body .doc-list { + list-style: none; + margin: 0; + padding: 0; + display: grid; + gap: 10px; +} +.doc__body .doc-list li { + position: relative; + margin: 0; + padding-left: 26px; + font-size: 14.5px; + line-height: 1.5; +} +.doc-list li::before { + content: ""; + position: absolute; + left: 0; + top: 3px; + width: 16px; + height: 16px; + border-radius: 50%; + background-position: center; + background-repeat: no-repeat; + background-size: 10px; +} +.doc-list--check li::before { + background-color: var(--mk-accent-soft); + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2 5.2 4.1 7.2 8 3' fill='none' stroke='%23007aff' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); +} +.doc-list--warn li::before { + background-color: var(--mk-warn-soft); + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M5 2.2v3.4' stroke='%23e07b00' stroke-width='1.6' stroke-linecap='round'/%3E%3Ccircle cx='5' cy='7.7' r='0.9' fill='%23e07b00'/%3E%3C/svg%3E"); +} + +/* Further reading: a card per link, the publisher above the title. */ +.doc__body .doc-links { + list-style: none; + margin: 0; + padding: 0; + display: grid; + grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); + gap: 12px; +} +.doc__body .doc-links li { + margin: 0; +} +.doc__body .doc-link { + position: relative; + display: flex; + flex-direction: column; + gap: 4px; + height: 100%; + padding: 12px 38px 12px 14px; + border-radius: var(--mk-radius-lg); + border: 1px solid var(--mk-line); + background: var(--mk-surface); + color: var(--mk-text); + text-decoration: none; + transition: + border-color var(--mk-dur-fast) var(--mk-ease), + box-shadow var(--mk-dur-fast) var(--mk-ease); +} +.doc__body .doc-link:hover { + border-color: color-mix(in srgb, var(--accent) 45%, var(--mk-line)); + box-shadow: var(--mk-shadow-1); + text-decoration: none; +} +.doc-link__source { + font-size: 12px; + font-weight: 600; + color: var(--mk-text-muted); +} +.doc-link__title { + font-size: 14px; + font-weight: 500; + line-height: 1.35; +} +.doc-link__arrow { + position: absolute; + right: 12px; + top: 14px; + color: var(--mk-text-faint); +} +.doc-link:hover .doc-link__arrow { + color: var(--accent); +} + +/* Start here: the layers, numbered. */ +.doc__body .doc-layers { + list-style: none; + margin: 0; + padding: 0; + display: grid; + gap: 12px; +} +.doc__body .doc-layer { + display: grid; + grid-template-columns: 32px minmax(0, 1fr); + gap: 16px; + margin: 0; + padding: 16px 20px; + border-radius: var(--mk-radius-lg); + background: var(--mk-surface); + border: 1px solid var(--mk-line); + box-shadow: var(--mk-shadow-1); +} +.doc-layer__num { + display: grid; + place-items: center; + width: 32px; + height: 32px; + border-radius: 50%; + background: var(--mk-accent-soft); + color: var(--accent); + font-weight: 700; + font-size: 14px; +} +.doc__body .doc-layer__name { + margin: 4px 0; + font-size: 16px; + font-weight: 600; + letter-spacing: -0.01em; +} +.doc__body .doc-layer p { + margin: 0; + font-size: 14.5px; + line-height: 1.5; + color: var(--mk-text-muted); +} +.doc__body .doc-layer .doc-layer__rule { + margin-top: 8px; + color: var(--mk-text); + font-weight: 500; +} + +/* The glossary: a definition list, each term the target of a deep link. */ +.doc__body .doc-terms { + margin: 0; + border-top: 1px solid var(--mk-line); +} +.doc-term { + display: grid; + grid-template-columns: 200px minmax(0, 1fr); + gap: 24px; + padding: 18px 0; + border-bottom: 1px solid var(--mk-line); + scroll-margin-top: 24px; +} +.doc-term:target { + margin: 0 -16px; + padding: 18px 16px; + border-radius: var(--mk-radius-lg); + background: var(--mk-accent-soft); + border-bottom-color: transparent; +} +.doc-term dt { + font-size: 15.5px; + font-weight: 600; + letter-spacing: -0.01em; +} +.doc-term dd { + margin: 0; +} +.doc__body .doc-term dd p { + margin: 0; + font-size: 14.5px; + line-height: 1.55; +} +.doc-term__matters { + margin-top: 8px !important; + color: var(--mk-text-muted); +} +.doc-term__label { + font-weight: 600; + color: var(--mk-text); +} +.doc-term__foot { + display: flex; + flex-wrap: wrap; + gap: 6px 16px; + margin-top: 10px; + font-size: 13px; + color: var(--mk-text-muted); +} +.doc-term__foot a { + color: var(--mk-text-muted); +} +.doc-term__foot a:hover { + color: var(--accent); +} + +@media (max-width: 720px) { + .doc-grid { + grid-template-columns: minmax(0, 1fr); + } + .doc-term { + grid-template-columns: minmax(0, 1fr); + gap: 6px; + } + .doc-term:target { + margin: 0; + padding: 18px 12px; + } +} diff --git a/src/app/docs/page.tsx b/src/app/docs/page.tsx index 0ff2429..a6511be 100644 --- a/src/app/docs/page.tsx +++ b/src/app/docs/page.tsx @@ -2,17 +2,18 @@ import fs from "node:fs"; import path from "node:path"; import type { Metadata } from "next"; import { Marked, type Tokens } from "marked"; +import { loadCatalog } from "@/engine/load"; import { readMe } from "@/local/home"; -import DocsView, { type Doc } from "./DocsView"; +import DocsView, { type Doc, type LearnContent, type LearnPart, type LearnTerm } from "./DocsView"; import "../shell.css"; import "./docs.css"; export const metadata: Metadata = { title: "Documentation | StackWise", - description: "StackWise's documentation: the overview, the MCP tools, the facts and rules, how it works, the decisions and the demo.", + description: "How a web app fits together, in plain words: every part, how to choose one, the mistakes beginners make, a glossary. Then StackWise's own docs: the overview, the MCP tools, the facts and rules, the decisions and the demo.", }; -// The docs are files in the repo; read them on every request so an edit shows on refresh. +// The docs are files in the repo (data/learn.json, the Markdown); read them on every request so an edit shows on refresh. export const dynamic = "force-dynamic"; /** @@ -26,7 +27,7 @@ export const dynamic = "force-dynamic"; */ const docsRoot = () => [process.env.STACKWISE_DOCS_ROOT, process.cwd()].find(Boolean) as string; -/** The documents, in reading order. Each is a Markdown file in the repo, shown as one section. */ +/** The project's documents, in reading order. Each is a Markdown file in the repo, shown as one section. */ const DOCS: { id: string; title: string; file: string }[] = [ { id: "overview", title: "Overview", file: "README.md" }, { id: "mcp", title: "MCP and agents", file: "docs/MCP.md" }, @@ -97,6 +98,21 @@ function render(id: string, markdown: string): { html: string; headings: { id: s return { html, headings }; } +/** The teaching content from data/learn.json: the layers to start with, one entry per part, the glossary. */ +function learnContent(): LearnContent { + const catalog = loadCatalog(); + const { learn } = catalog; + const parts: LearnPart[] = catalog.slots.flatMap((slot) => { + const entry = learn.slots[slot.id]; + return entry ? [{ id: slot.id, label: slot.label, ...entry }] : []; + }); + // Each term lists the parts that use it, so the glossary links back to them. + const terms: LearnTerm[] = Object.entries(learn.terms) + .map(([id, t]) => ({ id, ...t, usedIn: parts.filter((p) => p.terms.includes(id)).map((p) => ({ id: p.id, label: p.label })) })) + .sort((a, b) => a.term.localeCompare(b.term, "en", { sensitivity: "base" })); + return { startHere: learn.start_here ?? null, parts, terms }; +} + export default function DocsPage() { const docs: Doc[] = DOCS.flatMap((doc) => { let text: string; @@ -108,5 +124,5 @@ export default function DocsPage() { const { html, headings } = render(doc.id, text); return [{ id: doc.id, title: doc.title, file: doc.file, html, headings }]; }); - return ; + return ; } diff --git a/src/app/learn/LearnView.tsx b/src/app/learn/LearnView.tsx deleted file mode 100644 index 4023b89..0000000 --- a/src/app/learn/LearnView.tsx +++ /dev/null @@ -1,382 +0,0 @@ -"use client"; - -import Link from "next/link"; -import { Fragment, useEffect, useMemo, useRef, useState, type MouseEvent, type ReactNode } from "react"; -import { Shell, type Me } from "@/components/Shell"; -import type { Learn, LearnLink, SlotId } from "@/engine/schema"; - -type SlotEntry = NonNullable; -export type LearnPart = SlotEntry & { id: SlotId; label: string }; -export type LearnTerm = Learn["terms"][string] & { id: string; usedIn: { id: SlotId; label: string }[] }; -type StartHere = NonNullable; - -const partHaystack = (p: LearnPart) => [p.label, p.what, p.why, ...p.choosing, ...p.watch_for, ...p.read_more.map((l) => `${l.title} ${l.source}`)].join(" ").toLowerCase(); -const termHaystack = (t: LearnTerm) => [t.id, t.term, t.plain, t.matters].join(" ").toLowerCase(); -const startHaystack = (s: StartHere) => [s.title, s.summary, ...s.layers.flatMap((l) => [l.name, l.plain, l.rule])].join(" ").toLowerCase(); - -/** Wraps each match of the search in , so people see why a section is still showing. */ -function Hi({ text, q }: { text: string; q: string }) { - if (!q) return <>{text}; - const parts = text.split(new RegExp(`(${q.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})`, "ig")); - return ( - <> - {parts.map((part, i) => (i % 2 === 1 ? {part} : {part}))} - - ); -} - -function ReadMore({ links }: { links: LearnLink[] }) { - return ( - - ); -} - -function Toc({ parts, active, showStart, showGlossary, onPick }: { parts: LearnPart[]; active: string; showStart: boolean; showGlossary: boolean; onPick?: () => void }) { - const item = (id: string, label: ReactNode, index?: number) => ( -
  • - - {index !== undefined && {String(index + 1).padStart(2, "0")}} - {label} - -
  • - ); - return ( - - ); -} - -export function LearnView({ me, startHere, parts, terms, sourceCount }: { me: Me | null; startHere: StartHere | null; parts: LearnPart[]; terms: LearnTerm[]; sourceCount: number }) { - const [query, setQuery] = useState(""); - const [active, setActive] = useState("start-here"); - const pendingHash = useRef(null); - const searchRef = useRef(null); - const mobileToc = useRef(null); - const q = query.trim().toLowerCase(); - - const termNames = useMemo(() => new Map(terms.map((t) => [t.id, t.term])), [terms]); - const shownParts = useMemo(() => (q ? parts.filter((p) => partHaystack(p).includes(q)) : parts), [parts, q]); - const shownTerms = useMemo(() => (q ? terms.filter((t) => termHaystack(t).includes(q)) : terms), [terms, q]); - const showStart = Boolean(startHere) && (!q || startHaystack(startHere!).includes(q)); - const partIndex = useMemo(() => new Map(parts.map((p, i) => [p.id, i])), [parts]); - - // "/" jumps to the search box, like most docs sites. - useEffect(() => { - const onKey = (e: KeyboardEvent) => { - const target = e.target as HTMLElement | null; - if (e.key !== "/" || e.metaKey || e.ctrlKey || target?.closest("input, textarea, [contenteditable]")) return; - e.preventDefault(); - searchRef.current?.focus(); - }; - window.addEventListener("keydown", onKey); - return () => window.removeEventListener("keydown", onKey); - }, []); - - // Highlight the section being read: the last one whose top has passed just under the sticky bars. - useEffect(() => { - let frame = 0; - const update = () => { - frame = 0; - const line = parseFloat(getComputedStyle(document.documentElement).scrollPaddingTop) + 16 || 96; - let current = ""; - for (const section of document.querySelectorAll("[data-toc]")) { - if (section.getBoundingClientRect().top <= line) current = section.id; - else break; - } - setActive(current || document.querySelector("[data-toc]")?.id || ""); - }; - const onScroll = () => { - if (!frame) frame = requestAnimationFrame(update); - }; - onScroll(); - window.addEventListener("scroll", onScroll, { passive: true }); - window.addEventListener("resize", onScroll); - return () => { - cancelAnimationFrame(frame); - window.removeEventListener("scroll", onScroll); - window.removeEventListener("resize", onScroll); - }; - }, [shownParts, showStart, shownTerms.length]); - - // A term link clicked while searching clears the search first, then scrolls once the term is back. - useEffect(() => { - const hash = pendingHash.current; - if (q || !hash) return; - pendingHash.current = null; - document.getElementById(hash.slice(1))?.scrollIntoView({ block: "start" }); - history.replaceState(null, "", hash); - }, [q]); - - const jump = (e: MouseEvent) => { - if (!q) return; - e.preventDefault(); - pendingHash.current = e.currentTarget.getAttribute("href"); - setQuery(""); - }; - - const closeMobileToc = () => { - if (mobileToc.current) mobileToc.current.open = false; - }; - - const nothing = q && !showStart && shownParts.length === 0 && shownTerms.length === 0; - - return ( - -
    - - Skip to content - - -
    - - -
    -
    -

    StackWise Learn

    -

    The parts of a web app, in plain words

    -

    What each part does, how to pick one, the mistakes beginners make, and the best places to read more. Written for people building with AI tools.

    -
      -
    • - {parts.length} parts -
    • -
    • - {terms.length} terms -
    • -
    • - {sourceCount} sources -
    • -
    -
    - - setQuery(e.target.value)} - /> - -
    - {q && ( -

    - {shownParts.length} {shownParts.length === 1 ? "part" : "parts"} and {shownTerms.length} {shownTerms.length === 1 ? "term" : "terms"} match “{query.trim()}”. -

    - )} -
    - -
    - On this page - 0} onPick={closeMobileToc} /> -
    - - {nothing && ( -
    -

    Nothing matches “{query.trim()}”.

    - -
    - )} - - {startHere && showStart && ( -
    -

    Start here

    -

    - -

    -

    - -

    -
      - {startHere.layers.map((layer, i) => ( -
    1. - {i + 1} -
      -

      - -

      -

      - -

      -

      - -

      -
      -
    2. - ))} -
    - {startHere.read_more.length > 0 && ( -
    -

    Further reading

    - -
    - )} -
    - )} - - {shownParts.map((part) => ( -
    -

    Part {String((partIndex.get(part.id) ?? 0) + 1).padStart(2, "0")}

    -

    - - - -

    -

    - -

    - -
    -

    Why you need it

    -

    - -

    -
    - -
    -
    -

    How to choose

    -
      - {part.choosing.map((line) => ( -
    • - -
    • - ))} -
    -
    -
    -

    Common mistakes

    -
      - {part.watch_for.map((line) => ( -
    • - -
    • - ))} -
    -
    -
    - - {part.terms.length > 0 && ( -
    -

    Key terms

    - -
    - )} - - {part.read_more.length > 0 && ( -
    -

    Further reading

    - -
    - )} -
    - ))} - - {shownTerms.length > 0 && ( -
    -

    Reference

    -

    Glossary

    -

    The words you'll meet in docs, dashboards and AI answers.

    -
    - {shownTerms.map((t) => ( -
    -
    - - - -
    -
    -

    - -

    -

    - Why it matters -

    - {(t.read_more.length > 0 || t.usedIn.length > 0) && ( -
    - {t.usedIn.length > 0 && ( - - Used in{" "} - {t.usedIn.map((p, i) => ( - - {i > 0 && ", "} - - {p.label} - - - ))} - - )} - {t.read_more.map((link) => ( - - {link.source}: {link.title} - - - ))} -
    - )} -
    -
    - ))} -
    -
    - )} - -
    -

    Links go to the original publishers and open in a new tab. StackWise checks your plan against sourced facts; these pages explain the ideas behind those checks.

    - - Back to your plan - -
    -
    -
    -
    -
    - ); -} diff --git a/src/app/learn/learn.css b/src/app/learn/learn.css deleted file mode 100644 index 114b329..0000000 --- a/src/app/learn/learn.css +++ /dev/null @@ -1,640 +0,0 @@ -/* The Learn page (/learn): a docs-style page with a sticky table of contents. It reads the theme's - tokens (theme-apple.css over mk-ui.css), so light and dark follow the system like the planner. - The planner locks the body for its full-screen canvas; this page scrolls normally. */ - -html:has(.learn), -body:has(.learn) { - height: auto; - overflow: visible; -} -html:has(.learn) { - scroll-padding-top: 24px; -} -@media (prefers-reduced-motion: no-preference) { - html:has(.learn) { - scroll-behavior: smooth; - } -} - -/* Inside the shell (sidebar, scrolling page), with the table of contents where Settings has its section list. */ -.learn { - --learn-top-h: 0px; - --learn-toc-w: 196px; - color: var(--mk-text); - overflow-wrap: break-word; -} -.learn a { - color: inherit; -} -.learn mark { - background: color-mix(in srgb, var(--accent) 22%, transparent); - color: inherit; - border-radius: 3px; - padding: 0 1px; -} - -.learn-skip { - position: absolute; - left: 12px; - top: -48px; - z-index: 20; - padding: 8px 12px; - border-radius: var(--mk-radius); - background: var(--mk-surface); - box-shadow: var(--mk-shadow-2); -} -.learn-skip:focus { - top: 12px; -} - -/* ---------- Layout ---------- */ -.learn-shell { - display: grid; - grid-template-columns: var(--learn-toc-w) minmax(0, 1fr); - gap: 40px; - align-items: start; -} -.learn-main { - min-width: 0; - max-width: 780px; - padding: 0 0 48px; -} - -/* ---------- Table of contents ---------- */ -.learn-toc__inner { - position: sticky; - top: 44px; - max-height: calc(100vh - 60px); - overflow-y: auto; - padding: 0 8px 24px 0; - overscroll-behavior: contain; -} -.learn-toc__heading { - margin: 20px 0 6px; - padding: 0 10px; - font-size: 12px; - font-weight: 600; - color: var(--mk-text-muted); -} -.learn-toc__list { - list-style: none; - margin: 0; - padding: 0; - display: grid; - gap: 1px; -} -.learn-toc__link { - display: flex; - align-items: baseline; - gap: 10px; - padding: 7px 10px; - border-radius: 10px; - font-size: 14px; - font-weight: 500; - line-height: 1.35; - color: var(--mk-text) !important; - text-decoration: none; - transition: - background var(--mk-dur-fast) var(--mk-ease), - color var(--mk-dur-fast) var(--mk-ease); -} -.learn-toc__link:hover { - background: var(--ws-fill); - color: var(--mk-text) !important; -} -.learn-toc__link.is-active { - background: var(--ws-fill-strong, var(--ws-fill)); - color: var(--mk-text) !important; - font-weight: 600; -} -.learn-toc__num { - flex: none; - width: 18px; - font-family: var(--mk-font-mono); - font-size: 11px; - color: var(--mk-text-faint); -} -.learn-toc__link.is-active .learn-toc__num { - color: inherit; -} - -.learn-toc-mobile { - display: none; -} - -/* ---------- Hero and search ---------- */ -.learn-hero { - padding-bottom: 36px; - border-bottom: 1px solid var(--mk-line); -} -.learn-eyebrow { - margin: 0 0 8px; - font-size: 13px; - font-weight: 600; - color: var(--accent); - letter-spacing: 0; -} -.learn-title { - margin: 0; - font-family: var(--mk-font-display); - font-size: clamp(30px, 4.6vw, 44px); - line-height: 1.08; - font-weight: 700; - letter-spacing: -0.03em; - text-wrap: balance; -} -.learn-lead { - margin: 16px 0 0; - max-width: 62ch; - font-size: 18px; - line-height: 1.5; - color: var(--mk-text-muted); - text-wrap: pretty; -} -.learn-stats { - list-style: none; - margin: 20px 0 0; - padding: 0; - display: flex; - flex-wrap: wrap; - gap: 8px; -} -.learn-stats li { - padding: 4px 12px; - border-radius: var(--mk-radius-full); - background: var(--ws-fill); - font-size: 13px; - color: var(--mk-text-muted); -} -.learn-stats strong { - color: var(--mk-text); - font-weight: 600; -} -.learn-search { - position: relative; - margin-top: 28px; - max-width: 520px; - color: var(--mk-text-faint); -} -.learn-search > svg { - position: absolute; - left: 14px; - top: 50%; - transform: translateY(-50%); - pointer-events: none; -} -.learn .learn-search__input { - --mk-ctl-h: 44px; - width: 100%; - padding-left: 40px; - padding-right: 44px; - font-size: 16px; - border-radius: var(--mk-radius-lg); - background: var(--mk-surface); - box-shadow: var(--mk-shadow-1); -} -.learn-search__kbd { - position: absolute; - right: 12px; - top: 50%; - transform: translateY(-50%); - min-width: 22px; - padding: 1px 6px; - border: 1px solid var(--mk-line-strong); - border-radius: 6px; - font-family: var(--mk-font-mono); - font-size: 12px; - text-align: center; - color: var(--mk-text-muted); - background: var(--mk-surface-2); -} -.learn-search__input:focus + .learn-search__kbd, -.learn-search__input:not(:placeholder-shown) + .learn-search__kbd { - display: none; -} -.learn-search__count { - margin: 12px 0 0; - font-size: 14px; - color: var(--mk-text-muted); -} -.learn-empty { - margin-top: 40px; - padding: 28px; - border: 1px dashed var(--mk-line-strong); - border-radius: var(--mk-radius-lg); - text-align: center; - color: var(--mk-text-muted); -} -.learn-empty p { - margin: 0 0 12px; -} - -/* ---------- Sections ---------- */ -.learn-section { - padding: 56px 0 48px; - border-bottom: 1px solid var(--mk-line); -} -.learn-section:last-of-type { - border-bottom: 0; -} -.learn-h2 { - margin: 0; - font-family: var(--mk-font-display); - font-size: clamp(24px, 3.2vw, 30px); - line-height: 1.15; - font-weight: 700; - letter-spacing: -0.025em; -} -.learn-anchor { - text-decoration: none; -} -.learn-anchor:hover { - text-decoration: underline; - text-decoration-color: var(--mk-line-strong); - text-underline-offset: 4px; -} -.learn-what { - margin: 12px 0 0; - font-size: 18px; - line-height: 1.5; - color: var(--mk-text); - text-wrap: pretty; -} -.learn-block { - margin-top: 28px; -} -.learn-block > p { - margin: 0; - font-size: 16px; - line-height: 1.6; - color: var(--mk-text-muted); -} -.learn-h3 { - margin: 0 0 10px; - font-size: 13px; - font-weight: 600; - letter-spacing: 0.01em; - color: var(--mk-text-muted); -} - -.learn-grid { - margin-top: 28px; - display: grid; - grid-template-columns: repeat(2, minmax(0, 1fr)); - gap: 16px; -} -.learn-card { - padding: 20px 20px 18px; - border-radius: var(--mk-radius-lg); - background: var(--mk-surface); - border: 1px solid var(--mk-line); - box-shadow: var(--mk-shadow-1); -} -.learn-card--warn { - background: color-mix(in srgb, var(--mk-warn) 5%, var(--mk-surface)); - border-color: color-mix(in srgb, var(--mk-warn) 22%, var(--mk-line)); -} -.learn-list { - list-style: none; - margin: 0; - padding: 0; - display: grid; - gap: 10px; -} -.learn-list li { - position: relative; - padding-left: 26px; - font-size: 15px; - line-height: 1.5; -} -.learn-list li::before { - content: ""; - position: absolute; - left: 0; - top: 3px; - width: 16px; - height: 16px; - border-radius: 50%; - background-position: center; - background-repeat: no-repeat; - background-size: 10px; -} -.learn-list--check li::before { - background-color: var(--mk-accent-soft); - -webkit-mask: none; - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2 5.2 4.1 7.2 8 3' fill='none' stroke='%23007aff' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); -} -.learn-list--warn li::before { - background-color: var(--mk-warn-soft); - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M5 2.2v3.4' stroke='%23e07b00' stroke-width='1.6' stroke-linecap='round'/%3E%3Ccircle cx='5' cy='7.7' r='0.9' fill='%23e07b00'/%3E%3C/svg%3E"); -} - -.learn-chips { - list-style: none; - margin: 0; - padding: 0; - display: flex; - flex-wrap: wrap; - gap: 8px; -} -.learn-chip { - display: inline-flex; - align-items: center; - min-height: 30px; - padding: 4px 12px; - border-radius: var(--mk-radius-full); - background: var(--ws-fill); - font-size: 14px; - font-weight: 500; - text-decoration: none; - transition: background var(--mk-dur-fast) var(--mk-ease); -} -.learn-chip:hover { - background: var(--ws-fill-hover); -} - -/* Further reading: cards with the publisher on top, like a docs site's "related" links. */ -.learn-links { - list-style: none; - margin: 0; - padding: 0; - display: grid; - grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); - gap: 12px; -} -.learn-link { - position: relative; - display: flex; - flex-direction: column; - gap: 4px; - height: 100%; - padding: 14px 40px 14px 16px; - border-radius: var(--mk-radius-lg); - border: 1px solid var(--mk-line); - background: var(--mk-surface); - text-decoration: none; - transition: - border-color var(--mk-dur-fast) var(--mk-ease), - box-shadow var(--mk-dur-fast) var(--mk-ease), - transform var(--mk-dur-fast) var(--mk-ease); -} -.learn-link:hover { - border-color: color-mix(in srgb, var(--accent) 45%, var(--mk-line)); - box-shadow: var(--mk-shadow-1); -} -.learn-link:focus-visible, -.learn-chip:focus-visible, -.learn-toc__link:focus-visible { - outline: none; - box-shadow: var(--mk-focus-ring); -} -.learn-link__source { - font-size: 12px; - font-weight: 600; - color: var(--mk-text-muted); -} -.learn-link__title { - font-size: 15px; - font-weight: 500; - line-height: 1.35; - color: var(--mk-text); -} -.learn-link__arrow { - position: absolute; - right: 14px; - top: 16px; - color: var(--mk-text-faint); - transition: color var(--mk-dur-fast) var(--mk-ease); -} -.learn-link:hover .learn-link__arrow { - color: var(--accent); -} - -/* ---------- Start here ---------- */ -.learn-layers { - list-style: none; - margin: 28px 0 0; - padding: 0; - display: grid; - gap: 12px; -} -.learn-layer { - display: grid; - grid-template-columns: 32px minmax(0, 1fr); - gap: 16px; - padding: 18px 20px; - border-radius: var(--mk-radius-lg); - background: var(--mk-surface); - border: 1px solid var(--mk-line); - box-shadow: var(--mk-shadow-1); -} -.learn-layer__num { - display: grid; - place-items: center; - width: 32px; - height: 32px; - border-radius: 50%; - background: var(--mk-accent-soft); - color: var(--accent); - font-weight: 700; - font-size: 14px; -} -.learn-layer__name { - margin: 4px 0 4px; - font-size: 17px; - font-weight: 600; - letter-spacing: -0.01em; -} -.learn-layer p { - margin: 0; - font-size: 15px; - line-height: 1.5; - color: var(--mk-text-muted); -} -.learn-layer .learn-layer__rule { - margin-top: 8px; - color: var(--mk-text); - font-weight: 500; -} - -/* ---------- Glossary ---------- */ -.learn-terms { - margin: 28px 0 0; - display: grid; - gap: 0; - border-top: 1px solid var(--mk-line); -} -.learn-term { - display: grid; - grid-template-columns: 200px minmax(0, 1fr); - gap: 24px; - padding: 20px 0; - border-bottom: 1px solid var(--mk-line); -} -.learn-term:target { - margin: 0 -16px; - padding: 20px 16px; - border-radius: var(--mk-radius-lg); - background: var(--mk-accent-soft); - border-bottom-color: transparent; -} -.learn-term dt { - font-size: 16px; - font-weight: 600; - letter-spacing: -0.01em; -} -.learn-term dd { - margin: 0; -} -.learn-term dd p { - margin: 0; - font-size: 15px; - line-height: 1.55; -} -.learn-term .learn-term__matters { - margin-top: 8px; - color: var(--mk-text-muted); -} -.learn-term__label { - font-weight: 600; - color: var(--mk-text); -} -.learn-term__foot { - margin-top: 10px; - display: flex; - flex-wrap: wrap; - gap: 6px 16px; - font-size: 13px; - color: var(--mk-text-muted); -} -.learn-term__used a { - color: var(--accent); - text-decoration: none; -} -.learn-term__used a:hover, -.learn-term__read:hover { - text-decoration: underline; -} -.learn-term__read { - display: inline-flex; - align-items: center; - gap: 4px; - color: var(--accent) !important; - text-decoration: none; -} - -.learn-foot { - margin-top: 48px; - padding-top: 24px; - border-top: 1px solid var(--mk-line); - display: flex; - flex-wrap: wrap; - align-items: center; - justify-content: space-between; - gap: 16px; - font-size: 13px; - color: var(--mk-text-muted); -} -.learn-foot p { - margin: 0; - max-width: 56ch; -} -.learn-foot .mk-btn { - text-decoration: none; -} - -/* ---------- Smaller screens ---------- */ -@media (max-width: 899px) { - html:has(.learn) { - scroll-padding-top: 124px; - } - .learn-shell { - display: block; - } - .learn-toc { - display: none; - } - .learn-main { - max-width: none; - padding-top: 32px; - } - .learn-toc-mobile { - display: block; - position: sticky; - top: 8px; - z-index: 5; - margin-top: 24px; - border-radius: var(--mk-radius-lg); - background: var(--ws-glass-strong); - -webkit-backdrop-filter: var(--ws-blur); - backdrop-filter: var(--ws-blur); - border: 1px solid var(--ws-glass-line); - box-shadow: var(--mk-shadow-1); - } - .learn-toc-mobile > summary { - display: flex; - align-items: center; - justify-content: space-between; - padding: 12px 16px; - font-size: 14px; - font-weight: 600; - cursor: pointer; - list-style: none; - } - .learn-toc-mobile > summary::-webkit-details-marker { - display: none; - } - .learn-toc-mobile > summary::after { - content: ""; - width: 8px; - height: 8px; - border-right: 1.8px solid var(--mk-text-muted); - border-bottom: 1.8px solid var(--mk-text-muted); - transform: rotate(45deg) translateY(-2px); - transition: transform var(--mk-dur-fast) var(--mk-ease); - } - .learn-toc-mobile[open] > summary::after { - transform: rotate(-135deg) translateY(-2px); - } - .learn-toc-mobile nav { - max-height: 60vh; - overflow-y: auto; - padding: 0 8px 12px; - } - .learn-toc-mobile .learn-toc__heading:first-child { - margin-top: 4px; - } - .learn-term { - grid-template-columns: 160px minmax(0, 1fr); - } -} - -@media (max-width: 640px) { - .learn-lead, - .learn-what { - font-size: 17px; - } - .learn-grid { - grid-template-columns: minmax(0, 1fr); - } - .learn-links { - grid-template-columns: minmax(0, 1fr); - } - .learn-section { - padding-top: 40px; - padding-bottom: 36px; - } - .learn-card, - .learn-layer { - padding: 16px; - } - .learn-term { - grid-template-columns: minmax(0, 1fr); - gap: 6px; - } - .learn-term:target { - margin: 0 -8px; - padding: 16px 8px; - } -} - diff --git a/src/app/learn/page.tsx b/src/app/learn/page.tsx deleted file mode 100644 index f08234a..0000000 --- a/src/app/learn/page.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import type { Metadata } from "next"; -import { loadCatalog } from "@/engine/load"; -import { readMe } from "@/local/home"; -import { LearnView, type LearnPart, type LearnTerm } from "./LearnView"; -import "../shell.css"; -import "./learn.css"; - -// Read /data on every request, like the planner, so edits to learn.json show up on refresh. -export const dynamic = "force-dynamic"; - -export const metadata: Metadata = { - title: "Learn | StackWise", - description: "Every part of a web app in plain words: what it does, how to choose one, the mistakes beginners make, and where to read more.", -}; - -/** - * The Learn page: the teaching content from data/learn.json as a docs-style page. Deep links are - * `/learn#part-`, `/learn#term-` and `/learn#start-here`. - */ -export default function LearnPage() { - const catalog = loadCatalog(); - const { learn } = catalog; - - const parts: LearnPart[] = catalog.slots.flatMap((slot) => { - const entry = learn.slots[slot.id]; - return entry ? [{ id: slot.id, label: slot.label, ...entry }] : []; - }); - - // Each term lists the parts that use it, so the glossary links back to them. - const terms: LearnTerm[] = Object.entries(learn.terms) - .map(([id, t]) => ({ id, ...t, usedIn: parts.filter((p) => p.terms.includes(id)).map((p) => ({ id: p.id, label: p.label })) })) - .sort((a, b) => a.term.localeCompare(b.term, "en", { sensitivity: "base" })); - - const sources = new Set( - [...(learn.start_here?.read_more ?? []), ...parts.flatMap((p) => p.read_more), ...terms.flatMap((t) => t.read_more)].map((link) => link.source), - ); - - return ; -} diff --git a/src/components/PlanCanvas.tsx b/src/components/PlanCanvas.tsx index a184db2..a8b96c9 100644 --- a/src/components/PlanCanvas.tsx +++ b/src/components/PlanCanvas.tsx @@ -442,7 +442,7 @@ interface ZoneData extends Record { function ZoneNode({ data }: NodeProps>) { return ( diff --git a/src/components/Shell.tsx b/src/components/Shell.tsx index 95ffb06..4d78817 100644 --- a/src/components/Shell.tsx +++ b/src/components/Shell.tsx @@ -46,18 +46,21 @@ export const shortPath = (p: string, home: string | undefined) => (home && p.sta const NAV: { href: string; label: string; icon: IconName }[] = [ { href: "/projects", label: "Projects", icon: "grid" }, - { href: "/learn", label: "Learn", icon: "learn" }, { href: "/docs", label: "Documentation", icon: "info" }, { href: "/review", label: "Review facts", icon: "checklist" }, ]; -/** A page's own sections, shown in the sidebar under the pages: Settings' Account, General and so on. */ +/** + * A page's own sections, shown in the sidebar under the pages: Settings' Account, General and so + * on. A page can have more than one group (the documentation: Learn, then the project's docs). + */ export interface ShellSections { title: string; items: { id: string; label: string; href: string; active?: boolean; icon?: IconName; onSelect?: () => void }[]; } -export function Shell({ me, sections, children }: { me: Me | null; sections?: ShellSections; children: React.ReactNode }) { +export function Shell({ me, sections, children }: { me: Me | null; sections?: ShellSections | ShellSections[]; children: React.ReactNode }) { + const groups = sections ? [sections].flat() : []; const pathname = usePathname() ?? ""; const name = me?.profile.name.trim() || me?.account || ""; const initial = (name || "S").slice(0, 1).toUpperCase(); @@ -85,10 +88,10 @@ export function Shell({ me, sections, children }: { me: Me | null; sections?: Sh ))} - {sections && ( -