From 03aa74a9bc6c236b74eb8d6a5153ce82c71e9e63 Mon Sep 17 00:00:00 2001 From: Mikey-Ku Date: Thu, 22 Oct 2026 01:30:40 -0400 Subject: [PATCH 01/23] refactor: cut the Project panel's live tools, the extra AI presets and the write-to-folder export StackWise is about seeing and understanding the system, not running it. Gone: running and stopping the app, the SQL console, live service checks and extra-agent git worktrees (with the pg dependency); DeepSeek, OpenRouter, Groq, Mistral and the custom endpoint; and the "write it into a folder" form in Export. Kept: linking a folder, setting env values into its .env.local, the app icon, Claude, OpenAI, Gemini and Ollama, the zip export and the MCP export. --- .env.example | 7 +- CLAUDE.md | 9 +- README.md | 9 +- docs/MCP.md | 1 - package.json | 2 - pnpm-lock.yaml | 122 ------- public/brand/ai/deepseek.svg | 1 - src/ai/providers.test.ts | 24 +- src/ai/providers.ts | 7 +- src/app/api/local/route.test.ts | 59 ---- src/app/api/local/route.ts | 63 ---- src/app/api/project/route.ts | 55 +--- src/app/globals.css | 164 +--------- src/components/ConnectPanel.tsx | 1 - src/components/ProjectPanel.tsx | 541 ++------------------------------ src/components/SpecDialog.tsx | 127 -------- src/components/Workspace.tsx | 4 +- src/components/answerers.ts | 4 - src/project/git.test.ts | 81 ----- src/project/git.ts | 118 ------- src/project/local.ts | 306 ++---------------- src/project/probes.ts | 146 --------- src/project/project.test.ts | 63 ---- src/project/sql.ts | 62 ---- 24 files changed, 75 insertions(+), 1901 deletions(-) delete mode 100644 public/brand/ai/deepseek.svg delete mode 100644 src/app/api/local/route.test.ts delete mode 100644 src/app/api/local/route.ts delete mode 100644 src/project/git.test.ts delete mode 100644 src/project/git.ts delete mode 100644 src/project/probes.ts delete mode 100644 src/project/sql.ts diff --git a/.env.example b/.env.example index a1bf7df..3f2b71b 100644 --- a/.env.example +++ b/.env.example @@ -9,13 +9,8 @@ GEMINI_API_KEY= # OPENAI_MODEL=gpt-6-luna # GEMINI_MODEL=gemini-3.8-flash -# More models. Each turns on once its key (if it needs one) and its model are set. -# OPENROUTER_API_KEY= OPENROUTER_MODEL= -# GROQ_API_KEY= GROQ_MODEL= -# MISTRAL_API_KEY= MISTRAL_MODEL= +# A model running on this computer with Ollama. Turns on once its model is set. # OLLAMA_MODEL= OLLAMA_BASE_URL=http://localhost:11434/v1 -# Any other API that speaks OpenAI's chat format: -# CUSTOM_AI_BASE_URL= CUSTOM_AI_API_KEY= CUSTOM_AI_MODEL= CUSTOM_AI_LABEL= # Optional overrides. # STACKWISE_MODEL=claude-opus-5 diff --git a/CLAUDE.md b/CLAUDE.md index d28c05b..08e3daa 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -19,12 +19,12 @@ Planning tool for beginners building web apps with AI builders. A deterministic - `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 OpenAI-compatible presets for OpenRouter, Groq, Mistral, Ollama and a custom endpoint; adding a model is one entry; presets without a default model stay off until their model variable is set; answers are checked against the same Zod schemas), `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/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; adding a model is one entry; Ollama stays off until `OLLAMA_MODEL` is set; answers are checked against the same Zod schemas), `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/app/api/local/route.ts` writes a project into a folder on this computer; `src/mcp/localfiles.ts` holds the rules it follows (which folders, which files it will not replace) and is tested without a file system. - `src/mcp/` is the MCP server: `server.ts` (14 tools over the engine, plus the `pair` prompt), `pairing.ts` (agent ids, presence, wait settings, the pair instructions), `stdio.ts` (the command exported projects start), `registry.ts` (shared plans in `.stackwise/`, gitignored), `local.ts` (localhost-only guard). Routes: `src/app/api/mcp` (Streamable HTTP, stateless) and `src/app/api/pair` (the tab shares its plan, polls for agents' changes and messages, and posts your messages, via `usePairing.ts`). `src/engine/planops.ts` validates plan changes and builds reports; `src/engine/project.ts` builds the project pack (TASKS.md, agents, skills, `.mcp.json`). `src/engine/buildplan.ts` turns the canvas into ordered build tasks (parts, extras, custom parts, lines, with notes and dependencies): TASKS.md, `get_build_plan`, "Copy the build plan" and "Build this with " all read it. - `src/components/useAdvanced.ts` (the wrench in the dock) hides the ways to add extras, lines, custom and own parts and the Project panel until it's on; what a plan already has keeps its menus. -- `src/project/` is a plan's linked project folder, server-side: `detect.ts` (what kind of project, how to run it, its health URL and Java version), `envfile.ts` (reading and setting env files as text, masking), `probes.ts` (one read-only GET per service, with an example of what travels), `sql.ts` (the read-only SQL rules and connection strings, including Spring's JDBC settings), `local.ts` (the file system, `fetch`, `pg`, `node:sqlite` and the processes StackWise starts). `git.ts` gives each extra agent its own git worktree (a sibling folder on a `stackwise/` branch), reports what each changed, and merges a branch back only into a clean main copy, backing out on conflict; tested against real throwaway repos in `git.test.ts`. All pure parts are tested in `project.test.ts`. `src/app/api/project` exposes it; `ProjectPanel.tsx` is the Project panel in the dock. +- `src/project/` is a plan's linked project folder, server-side: `detect.ts` (what kind of project it is and its env and config files), `envfile.ts` (reading and setting env files as text, masking), `local.ts` (the file system: what a folder is, which env names it sets, its icon, its README's opening, and the one write, a variable into its `.env.local`). The pure parts are tested in `project.test.ts`. `src/app/api/project` exposes it; `ProjectPanel.tsx` is the Project panel in the dock. - `src/engine/extras.ts` is more than one service in a part and lines between things. An extra ("database.cache") is checked by running the rules with it in its part's place (results carry `instance`), priced, wired (a clashing env name gets the role as a prefix) and never searched. A link ("payments>app") takes the verdict of rules that read both parts and is "not checked" otherwise; on the canvas a link to the app rides on that part's line, a link between parts is its own dashed line. `recommend` appends extras' results; `planInput` carries `extras`. - `src/engine/merge.ts` merges two copies of a plan against the last copy both had (answers, parts and notes key by key); `stdio.ts` uses it so an agent editing `stackwise.plan.json` and the browser never overwrite each other. - `src/engine/review.ts` is the fact review: `reviewList` runs `recommend` for every default plan (`src/components/defaultPlans.ts`: the templates and demos) and lists first the facts the rules and scores read for their options (`factsReadFor`: required facts plus `scoreFacts` in `score.ts`), then every other fact of full options; `editFactReview` rewrites one fact's status in the file's own text (`jsontext.ts`) so a confirm is a two-line diff. `review-store.ts` (node-only) applies a decision and keeps flags in `.stackwise/review-flags.json`. `/review` and `/api/review` are local only (`localOnly`). Claude never confirms a fact there; Michael does. @@ -73,10 +73,9 @@ Planning tool for beginners building web apps with AI builders. A deterministic - Removing a part the answers need empties it (`clearSlot`) instead of dropping it, and the toast says why; a part they don't need goes away (`autoPick`). Delete removes the selected part. - Right-click menus are one list per target (`CanvasTarget` in PlanCanvas) built in `Workspace.openMenu`. Nodes, edge labels and the pane each call `onMenu`; edge labels are HTML buttons, so they need their own `onContextMenu`. - On a canvas narrower than 560px, fitting stops at 45% zoom so cards stay readable; people pan for the rest. -- `/api/local` refuses anything outside the home folder, hidden and system folders, StackWise's own folder, and never replaces an existing `.env.local`. Michael's keys are his: StackWise writes names with empty values and says which names his file is missing. +- `export_project` over MCP (`src/mcp/writeproject.ts`) refuses anything outside the home folder, hidden and system folders, StackWise's own folder, and never replaces an existing `.env.local`. Michael's keys are his: StackWise writes names with empty values and says which names his file is missing. - Never call `navigator.clipboard.readText()` from a Playwright evaluate: Chrome waits on a permission prompt and the tool hangs. Capture copied text by wrapping `writeText`. -- The Project panel never sees an env value. Names and "set or missing" come back; values go only from the page into the project's `.env.local` (created with mode 600), and from the file into a live check on this computer. Processes StackWise starts get a clean environment (PATH, HOME, JAVA_HOME and a few more), never StackWise's own, which holds its AI keys. Live checks are GETs only, and the SQL console runs one reading statement inside `BEGIN READ ONLY` with a 5 second timeout. -- Running processes live on `globalThis.__stackwiseRuns` so a hot reload doesn't lose them. They're killed as a process group, so a script's children (Maven, then Java) stop too. +- The Project panel never sees an env value. Names and "set or missing" come back; values go only from the page into the project's `.env.local` (created with mode 600). StackWise never runs the project, calls its services or reads its database: that was cut in v1 to keep the product about understanding the system. - Ties between equally scored options follow `planning.json` `tie_order` (Next.js first for frameworks), then the alphabet. `data.test.ts` checks a plain web app still gets Next.js. - Frameworks tie on every score (they're all free and portable), and ties break alphabetically, so adding a framework can change the default pick for every plan. Check `recommend` after adding one. - A plan's app logo (`plan.icon`) is a small data URL kept in the browser like the layout, never in `SharedPlan`. The Project panel picks up the project's own icon (`findIcon`: the HTML's ``, then usual file names) or resizes one the person picks to 128px (`imageToIcon`). diff --git a/README.md b/README.md index b23692e..048b8a9 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ Everything works without an API key. To have an AI read your description, answer 3. **Read the canvas.** Your app in the middle, a card per part, and a line per connection: a check means it works, `!` a warning, a cross that it doesn't. A light flows along the lines that work. Click a card for why it was picked; right-click anything for everything else; press A to add a part. 4. **Ask.** Cmd+K opens one conversation per plan. Pick who answers: an agent in your terminal, a model with a key, or StackWise's own facts. 5. **Turn on Advanced tools when you need them.** The wrench in the dock adds a second service in one part (a cache next to the database), lines between two parts (Stripe sends webhooks to your app), parts you build yourself and parts StackWise doesn't list, and the Project panel. -6. **Link your project.** The Project panel runs the app, sets environment variables, checks every service with your keys, reads the database (read only) and gives extra agents their own git worktree. -7. **Export.** A spec pack for your AI builder, or the files written straight into the project. "Copy the build plan" on the canvas menu gives the tasks alone, in order. +6. **Link your project.** The Project panel links the plan to its folder: see which of the plan's keys the project has set, set the missing ones into its `.env.local` without opening a file, and keep its `stackwise.plan.json` current. Values never come back to the page. +7. **Export.** A spec pack for your AI builder as a zip, or straight into the project over MCP. "Copy the build plan" on the canvas menu gives the tasks alone, in order. ```bash pnpm test # engine, AI (with a fake client), store, scripts and data checks @@ -111,8 +111,7 @@ Claude can check stacks, compare options, estimate costs and change the plan you - Start and stop the app from StackWise and watch its log. Its health check shows whether it's up. - Every environment variable the plan needs, marked set, missing or readable by the browser. Paste a value to write it into the project's `.env.local`; StackWise never shows it again or sends it anywhere. - Check every service with your own keys: one read-only request each, shown with the keys masked, what came back, an example of what travels on that connection, and a link to the service's status page. -- A read-only SQL console for the project's Postgres or SQLite database. -- The plan file in the project and StackWise's copy merge instead of overwriting each other, so an agent in your terminal and you in the browser can both change the plan. +- The plan file in the project and StackWise's copy merge instead of overwriting each other, so an agent in your terminal and you in the app can both change the plan. **Understanding** - Details for every part: its stats, every check with its reason and fix, the cost at your size, how it scored for your priority, a comparison table, and the sourced facts behind it, flagged when they may be out of date. @@ -161,7 +160,7 @@ src/engine/ the logic, no React, fully tested src/ai/ Claude pre-fill and explanations, optional src/components/ the workspace UI src/app/api/ status, prefill, explain, talk, keys, mcp, pair, project and local routes -src/project/ a linked project folder: run it, its env files, live checks, read-only SQL, git +src/project/ a linked project folder: what it is, its env variable names, its icon src/mcp/ the MCP server, its stdio command, and shared plans in .stackwise/ scripts/ evals, source checker, option drafter, logo fetcher evals/ eval cases (written by a person) and how to run them diff --git a/docs/MCP.md b/docs/MCP.md index 4f8592d..ff165f9 100644 --- a/docs/MCP.md +++ b/docs/MCP.md @@ -58,7 +58,6 @@ Details: Unzip it as a new project folder and run `claude` there. Claude Code asks once whether to trust the project's MCP server. -Or skip the zip: **Or write it into a folder on this computer** in the same dialog writes the files straight into a folder, plus a `.env.local` with the names and no values, and gives you the `cd ... && claude` line. It only writes inside your home folder, never inside StackWise's own folder, and never over an existing `.env.local`: your values are yours, and StackWise has no copy of them. Anything else already in the folder stays until you tick "Replace files that are already there". See `src/app/api/local/route.ts` and `src/mcp/localfiles.ts`. To bring a project's plan back into StackWise in another browser, use **Import plan file** on its `stackwise.plan.json`. It keeps the plan's id, so changes Claude makes in that project keep showing up. diff --git a/package.json b/package.json index 6045ba4..72c01ff 100644 --- a/package.json +++ b/package.json @@ -28,14 +28,12 @@ "fflate": "^0.8.3", "html-to-image": "1.11.11", "next": "16.3.4", - "pg": "^8.23.0", "react": "19.2.8", "react-dom": "19.2.8", "zod": "^4.5.4" }, "devDependencies": { "@types/node": "^25.9.5", - "@types/pg": "^8.23.1", "@types/react": "^19", "@types/react-dom": "^19", "eslint": "^9", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6b6faea..bd2d6c3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -127,9 +127,6 @@ importers: 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) - pg: - specifier: ^8.23.0 - version: 8.23.0 react: specifier: 19.2.8 version: 19.2.8 @@ -143,9 +140,6 @@ importers: '@types/node': specifier: ^25.9.5 version: 25.9.6 - '@types/pg': - specifier: ^8.23.1 - version: 8.23.1 '@types/react': specifier: ^19 version: 19.3.0 @@ -913,9 +907,6 @@ packages: '@types/node@25.9.6': resolution: {integrity: sha512-JR6Q/PV5DKFvjrGFVqQJdeG0qvsqQQLDa3TzFrqVwhqRXqwNaxPo2KYCtCQXpOdIulCouKwT7a6in9nFthBAzw==} - '@types/pg@8.23.1': - resolution: {integrity: sha512-fKVHpikPdg4GKks3JuLEhvwSyvwzF23hnabPy6DD8ljVbC7+6J5dQzdv4arV6jqq57djnMgs1HKBxX4P8aBI3A==} - '@types/react-dom@19.3.0': resolution: {integrity: sha512-ZI7bU42mZXXKHn/qNLEw2IrbiINU7X5+vfgdixBHkCNpYWXjKgfQ/P+uyGb5CjOLB9UcnTeg3rylQtV2hym44Q==} peerDependencies: @@ -2323,40 +2314,6 @@ packages: pathe@2.0.3: resolution: {integrity: sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==} - pg-cloudflare@1.4.0: - resolution: {integrity: sha512-Vo7z/6rrQYxpNRylp4Tlob2elzbh+N/MOQbxFVWCxS7oEx6jF53GTJFxK2WWpKuBRkmiin4Mt+xofFDjx09R0A==} - - pg-connection-string@2.14.0: - resolution: {integrity: sha512-XwWDGcLRGCXAR8F/AM5bG7Q+A3Wm2s6QeEjlOKZLlH3UYcguiqCWKyWXVag5TLTIjR7oOJUY8kcADaZgWPyLeg==} - - pg-int8@1.0.1: - resolution: {integrity: sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==} - engines: {node: '>=4.0.0'} - - pg-pool@3.14.0: - resolution: {integrity: sha512-gKtPkFdQPU3DksooVLi9LsjZxrsBUZIpa+7aVx+LV5pNh0KzP4Zleud2po+ConrxbuXGBJ6Hfer6hdgpIBpBaw==} - peerDependencies: - pg: '>=8.0' - - pg-protocol@1.16.0: - resolution: {integrity: sha512-sILXutLVjCLjcDuOmvhX5e2Z4cS5qG/6Bu3VkpFwdf/633ElGLpEh9bgmuI5I4sqKqkifQiGyiCcx1HdtrK7tg==} - - pg-types@2.2.0: - resolution: {integrity: sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==} - engines: {node: '>=4'} - - pg@8.23.0: - resolution: {integrity: sha512-Ip2EQCngowJLGOfCwkFhPXU7/ljlhn6Rxlmy4XYfL2Y+vyRM59+8uR2xqRWKdYmbXmxCFOAmKxBuSUCdF34qLg==} - engines: {node: '>= 16.0.0'} - peerDependencies: - pg-native: '>=3.0.1' - peerDependenciesMeta: - pg-native: - optional: true - - pgpass@1.0.5: - resolution: {integrity: sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==} - picocolors@1.1.1: resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} @@ -2384,22 +2341,6 @@ packages: resolution: {integrity: sha512-RRuzqDtt5Y9h3quz5hWhK+TPnsmVs6WwSU6LkJMeY4HstUEDuYTG8UJSdawMRzmzAtV+KEoG8N3Qg2qLy5vM/A==} engines: {node: ^10 || ^12 || >=14} - postgres-array@2.0.0: - resolution: {integrity: sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==} - engines: {node: '>=4'} - - postgres-bytea@1.0.1: - resolution: {integrity: sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ==} - engines: {node: '>=0.10.0'} - - postgres-date@1.0.7: - resolution: {integrity: sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==} - engines: {node: '>=0.10.0'} - - postgres-interval@1.2.0: - resolution: {integrity: sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==} - engines: {node: '>=0.10.0'} - prelude-ls@1.2.1: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} @@ -2576,10 +2517,6 @@ packages: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} - split2@4.2.0: - resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==} - engines: {node: '>= 10.x'} - stable-hash@0.0.5: resolution: {integrity: sha512-+L3ccpzibovGXFK+Ap/f8LOS0ahMrHTf3xu7mMLSpEGU0EO9ucaysSylKo9eRDFNhWve/y275iPmIZ4z39a9iA==} @@ -2880,10 +2817,6 @@ packages: wrappy@1.0.2: resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} - xtend@4.0.2: - resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} - engines: {node: '>=0.4'} - yallist@3.1.1: resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==} @@ -3505,12 +3438,6 @@ snapshots: dependencies: undici-types: 7.24.6 - '@types/pg@8.23.1': - dependencies: - '@types/node': 25.9.6 - pg-protocol: 1.16.0 - pg-types: 2.2.0 - '@types/react-dom@19.3.0(@types/react@19.3.0)': dependencies: '@types/react': 19.3.0 @@ -5104,41 +5031,6 @@ snapshots: pathe@2.0.3: {} - pg-cloudflare@1.4.0: - optional: true - - pg-connection-string@2.14.0: {} - - pg-int8@1.0.1: {} - - pg-pool@3.14.0(pg@8.23.0): - dependencies: - pg: 8.23.0 - - pg-protocol@1.16.0: {} - - pg-types@2.2.0: - dependencies: - pg-int8: 1.0.1 - postgres-array: 2.0.0 - postgres-bytea: 1.0.1 - postgres-date: 1.0.7 - postgres-interval: 1.2.0 - - pg@8.23.0: - dependencies: - pg-connection-string: 2.14.0 - pg-pool: 3.14.0(pg@8.23.0) - pg-protocol: 1.16.0 - pg-types: 2.2.0 - pgpass: 1.0.5 - optionalDependencies: - pg-cloudflare: 1.4.0 - - pgpass@1.0.5: - dependencies: - split2: 4.2.0 - picocolors@1.1.1: {} picomatch@2.3.2: {} @@ -5161,16 +5053,6 @@ snapshots: picocolors: 1.1.1 source-map-js: 1.2.1 - postgres-array@2.0.0: {} - - postgres-bytea@1.0.1: {} - - postgres-date@1.0.7: {} - - postgres-interval@1.2.0: - dependencies: - xtend: 4.0.2 - prelude-ls@1.2.1: {} prop-types@15.8.1: @@ -5433,8 +5315,6 @@ snapshots: source-map-js@1.2.1: {} - split2@4.2.0: {} - stable-hash@0.0.5: {} stackback@0.0.2: {} @@ -5763,8 +5643,6 @@ snapshots: wrappy@1.0.2: {} - xtend@4.0.2: {} - yallist@3.1.1: {} yocto-queue@0.1.0: {} diff --git a/public/brand/ai/deepseek.svg b/public/brand/ai/deepseek.svg deleted file mode 100644 index 8dee8c3..0000000 --- a/public/brand/ai/deepseek.svg +++ /dev/null @@ -1 +0,0 @@ -DeepSeek \ No newline at end of file diff --git a/src/ai/providers.test.ts b/src/ai/providers.test.ts index a030cb7..e0ee128 100644 --- a/src/ai/providers.test.ts +++ b/src/ai/providers.test.ts @@ -122,23 +122,15 @@ describe("Gemini", () => { }); describe("more models", () => { - it("keeps a preset off until both its key and its model are set, so no model name is guessed", () => { - const groq = (env: Record) => providerStatus(env).find((p) => p.id === "groq")!; - expect(groq({ GROQ_API_KEY: "g" })).toMatchObject({ on: false, needs: ["GROQ_MODEL"], featured: false }); - expect(groq({ GROQ_API_KEY: "g", GROQ_MODEL: "some-model" })).toMatchObject({ on: true, needs: [], baseUrl: "https://api.groq.com/openai/v1" }); - const ollama = providerStatus({ OLLAMA_MODEL: "llama4" }).find((p) => p.id === "ollama")!; - expect(ollama).toMatchObject({ on: true, baseUrl: "http://localhost:11434/v1" }); - }); - - it("sends a custom OpenAI-compatible endpoint the same prompt, asks for a JSON object, and checks the answer the same way", async () => { - const env = { CUSTOM_AI_BASE_URL: "https://llm.example.com/v1/", CUSTOM_AI_API_KEY: "ck", CUSTOM_AI_MODEL: "house-model", CUSTOM_AI_LABEL: "House model" }; - const custom = providerStatus(env).find((p) => p.id === "custom")!; - expect(custom).toMatchObject({ on: true, label: "House model" }); + it("keeps Ollama off until its model is set, so no model name is guessed, then talks to it on this computer", async () => { + const ollama = (env: Record) => providerStatus(env).find((p) => p.id === "ollama")!; + expect(ollama({})).toMatchObject({ on: false, needs: ["OLLAMA_MODEL"], featured: false }); + const env = { OLLAMA_MODEL: "llama4" }; + expect(ollama(env)).toMatchObject({ on: true, needs: [], baseUrl: "http://localhost:11434/v1" }); const { fetchImpl, calls } = fakeFetch(openaiSays(JSON.stringify(answer))); - const reply = await providerTalk(custom, brief, [], "Will my data survive?", env, fetchImpl); + const reply = await providerTalk(ollama(env), brief, [], "Will my data survive?", env, fetchImpl); expect(reply.reply).toContain("hosted database"); - expect(calls[0].url).toBe("https://llm.example.com/v1/chat/completions"); - expect(calls[0].headers.authorization).toBe("Bearer ck"); - expect(calls[0].body).toMatchObject({ model: "house-model", response_format: { type: "json_object" } }); + expect(calls[0].url).toBe("http://localhost:11434/v1/chat/completions"); + expect(calls[0].body).toMatchObject({ model: "llama4", response_format: { type: "json_object" } }); }); }); diff --git a/src/ai/providers.ts b/src/ai/providers.ts index e0b8432..985858c 100644 --- a/src/ai/providers.ts +++ b/src/ai/providers.ts @@ -37,16 +37,11 @@ export const PROVIDERS: ProviderDef[] = [ { id: "claude", label: "Claude", kind: "anthropic", keyEnv: ["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN"], modelEnv: "STACKWISE_MODEL", defaultModel: AI_MODEL }, { id: "openai", label: "OpenAI", kind: "openai-chat", keyEnv: ["OPENAI_API_KEY"], modelEnv: "OPENAI_MODEL", defaultModel: "gpt-6-luna", baseUrl: "https://api.openai.com/v1" }, { id: "gemini", label: "Gemini", kind: "gemini", keyEnv: ["GEMINI_API_KEY", "GOOGLE_API_KEY"], modelEnv: "GEMINI_MODEL", defaultModel: "gemini-3.8-flash" }, - { id: "deepseek", label: "DeepSeek", kind: "openai-chat", keyEnv: ["DEEPSEEK_API_KEY"], modelEnv: "DEEPSEEK_MODEL", defaultModel: "deepseek-chat", baseUrl: "https://api.deepseek.com/v1" }, - { id: "openrouter", label: "OpenRouter", kind: "openai-chat", keyEnv: ["OPENROUTER_API_KEY"], modelEnv: "OPENROUTER_MODEL", baseUrl: "https://openrouter.ai/api/v1" }, - { id: "groq", label: "Groq", kind: "openai-chat", keyEnv: ["GROQ_API_KEY"], modelEnv: "GROQ_MODEL", baseUrl: "https://api.groq.com/openai/v1" }, - { id: "mistral", label: "Mistral", kind: "openai-chat", keyEnv: ["MISTRAL_API_KEY"], modelEnv: "MISTRAL_MODEL", baseUrl: "https://api.mistral.ai/v1" }, { id: "ollama", label: "Ollama (on this computer)", kind: "openai-chat", keyEnv: [], modelEnv: "OLLAMA_MODEL", baseUrl: "http://localhost:11434/v1", baseUrlEnv: "OLLAMA_BASE_URL" }, - { id: "custom", label: "Custom model", kind: "openai-chat", keyEnv: ["CUSTOM_AI_API_KEY"], modelEnv: "CUSTOM_AI_MODEL", baseUrlEnv: "CUSTOM_AI_BASE_URL", labelEnv: "CUSTOM_AI_LABEL" }, ]; /** Always offered on the Connect screen, where a key can be pasted in; the rest show once they're set up. */ -export const FEATURED_PROVIDERS = ["claude", "openai", "gemini", "deepseek"]; +export const FEATURED_PROVIDERS = ["claude", "openai", "gemini"]; /** The only variables the Connect screen may write to StackWise's own .env.local: each provider's first key name. */ export const PROVIDER_KEY_NAMES = new Set(PROVIDERS.flatMap((p) => p.keyEnv.slice(0, 1))); diff --git a/src/app/api/local/route.test.ts b/src/app/api/local/route.test.ts deleted file mode 100644 index bbc3ea9..0000000 --- a/src/app/api/local/route.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -import fs from "node:fs"; -import os from "node:os"; -import path from "node:path"; -import { afterEach, describe, expect, it } from "vitest"; -import type { SharedPlan } from "@/engine/share"; -import { POST } from "./route"; - -/** Writing a project into a folder answers this computer only, and says what it would do first. */ - -const plan: SharedPlan = { - v: 1, - appName: "Bird Count", - description: "People log the birds they see.", - features: "Log a sighting", - answers: { saves_data: "yes" }, - size: "up_to_100", - priority: "spend_zero", - builderId: "claude-code", - pinned: {}, - notes: {}, -}; - -const post = (body: unknown, headers: Record = {}) => - POST(new Request("http://localhost:4310/api/local", { method: "POST", headers: { host: "localhost:4310", "content-type": "application/json", ...headers }, body: JSON.stringify(body) })); - -const target = path.join(os.homedir(), "stackwise-route-test"); - -afterEach(() => { - delete process.env.STACKWISE_PAIRING; -}); - -describe("POST /api/local", () => { - it("says what it would write, and writes nothing on a dry run", async () => { - const response = await post({ path: target, id: "p1", plan, generatedOn: "2026-09-15", dryRun: true }); - const body = await response.json(); - expect(response.status).toBe(200); - expect(body.path).toBe(target); - expect(body.folderExists).toBe(false); - expect(body.write).toEqual(expect.arrayContaining(["SPEC.md", "SETUP.md", ".env.example", ".gitignore", "stackwise.plan.json", ".env.local"])); - expect(body.wrote).toEqual([]); - expect(fs.existsSync(target)).toBe(false); - }); - - it("refuses a folder outside the home folder", async () => { - const response = await post({ path: "/etc/stackwise", id: "p1", plan, generatedOn: "2026-09-15", dryRun: true }); - expect(response.status).toBe(400); - expect((await response.json()).error).toContain("only writes inside your home folder"); - }); - - it("refuses a page on another site, and a body it can't read", async () => { - expect((await post({ path: target, id: "p1", plan, generatedOn: "2026-09-15" }, { origin: "https://evil.example" })).status).toBe(403); - expect((await post({ path: target })).status).toBe(400); - }); - - it("can be turned off with the rest of pairing", async () => { - process.env.STACKWISE_PAIRING = "off"; - expect((await post({ path: target, id: "p1", plan, generatedOn: "2026-09-15", dryRun: true })).status).toBe(404); - }); -}); diff --git a/src/app/api/local/route.ts b/src/app/api/local/route.ts deleted file mode 100644 index 97ac07d..0000000 --- a/src/app/api/local/route.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { z } from "zod"; -import { buildProjectPack, envFileText, planEnv, planInput, recommend, type SpecFile } from "@/engine"; -import { indexCatalog } from "@/engine/evaluate"; -import { loadCatalog } from "@/engine/load"; -import { sharedPlanSchema } from "@/engine/share"; -import { localOnly, readJson } from "@/mcp/local"; -import { NEVER_REPLACE } from "@/mcp/localfiles"; -import { writeProjectFolder } from "@/mcp/writeproject"; -import { createRegistry, PLAN_ID } from "@/mcp/registry"; -import { PLAN_FILE } from "@/engine/names"; - -/** - * Writing the project into a folder on this computer, instead of downloading a zip. Same files, - * plus a `.env.local` with the names it needs and no values. Only answers this computer, only - * writes inside the home folder, and never writes over an existing `.env.local`. - */ - -export const dynamic = "force-dynamic"; -export const runtime = "nodejs"; - -const bodySchema = z.object({ - path: z.string().max(1024), - id: z.string().regex(PLAN_ID), - plan: sharedPlanSchema, - generatedOn: z.string().regex(/^\d{4}-\d{2}-\d{2}$/), - /** true: say what would happen, write nothing. */ - dryRun: z.boolean().default(false), - replace: z.boolean().default(false), -}); - -export async function POST(request: Request) { - const blocked = localOnly(request); - if (blocked) return blocked; - const parsed = bodySchema.safeParse(await readJson(request)); - if (!parsed.success) return Response.json({ error: "Send { path, id, plan, generatedOn }." }, { status: 400 }); - const { plan, generatedOn, dryRun, replace } = parsed.data; - - const root = process.cwd(); - // When this plan is shared with agents, StackWise's copy takes the plan being exported, so the - // project's plan file and the shared copy start out level and the first sync loses nothing. - const registry = createRegistry(root); - const shared = !dryRun && registry.read(parsed.data.id) ? registry.savePlan(parsed.data.id, plan, "browser") : null; - - const index = indexCatalog(loadCatalog()); - const input = planInput(plan); - const { selection } = recommend(index, input, plan.pinned); - const env = planEnv(index, selection, plan.extras ?? {}); - const files: SpecFile[] = [ - ...buildProjectPack( - index, - input, - selection, - { appName: plan.appName, description: plan.description, features: plan.features, builderId: plan.builderId, generatedOn, planId: parsed.data.id, plan, version: shared?.version, updatedAt: shared?.updatedAt ?? new Date().toISOString() }, - { stackwiseRoot: root }, - ), - { name: NEVER_REPLACE, content: envFileText(env, { appName: plan.appName, generatedOn, custom: plan.custom }) }, - ]; - - const result = writeProjectFolder(parsed.data.path, files, { stackwiseRoot: root, envNames: env.map((v) => v.name), replace, dryRun }); - if ("error" in result) return Response.json({ error: result.error }, { status: 400 }); - if (shared && result.wrote.includes(PLAN_FILE)) registry.setSynced(parsed.data.id, shared.plan); - return Response.json({ ...result, command: `cd ${result.path.includes(" ") ? `"${result.path}"` : result.path}` }); -} diff --git a/src/app/api/project/route.ts b/src/app/api/project/route.ts index ee37ea3..59e321a 100644 --- a/src/app/api/project/route.ts +++ b/src/app/api/project/route.ts @@ -5,15 +5,13 @@ import { localOnly, readJson } from "@/mcp/local"; import { resolveRealFolder } from "@/mcp/writeproject"; import { projectPlanFileSchema } from "@/mcp/registry"; import { ENV_NAME } from "@/project/envfile"; -import { iconData, inspect, listRuns, probe, runLog, runSql, startRun, stopRun, writeEnv } from "@/project/local"; -import { addWorktree, changes, mergeBranch, removeWorktree, repoInfo } from "@/project/git"; -import { PROBES } from "@/project/probes"; +import { iconData, inspect, writeEnv } from "@/project/local"; import { LEGACY_PLAN_FILE, PLAN_FILE } from "@/engine/names"; /** - * A plan's linked project folder: what's in it, its env variables, live checks, the read-only SQL - * console, and the processes StackWise runs for it. Only this computer can call it, only for - * folders inside the home folder, and no env value ever comes back in a response. + * A plan's linked project folder: what's in it, which env variable names it has, its icon and its + * plan file. Only this computer can call it, only for folders inside the home folder, and no env + * value ever comes back in a response. The one write is a variable into the project's .env.local. */ export const dynamic = "force-dynamic"; @@ -23,17 +21,8 @@ const path = z.string().min(1).max(1024); const bodySchema = z.discriminatedUnion("action", [ z.object({ action: z.literal("inspect"), path }), z.object({ action: z.literal("env"), path, name: z.string().regex(ENV_NAME).max(120), value: z.string().max(8000) }), - z.object({ action: z.literal("probe"), path, ids: z.array(z.string().max(80)).min(1).max(20), healthUrl: z.string().url().optional() }), - z.object({ action: z.literal("sql"), path, query: z.string().max(10_000) }), - z.object({ action: z.literal("start"), path, command: z.string().min(1).max(500) }), - z.object({ action: z.literal("stop"), path, id: z.string().max(40) }), - z.object({ action: z.literal("runs"), path, logFor: z.string().max(40).optional(), after: z.number().int().min(0).default(0) }), z.object({ action: z.literal("icon"), path }), - z.object({ action: z.literal("git"), path }), z.object({ action: z.literal("planfile"), path }), - z.object({ action: z.literal("worktree-add"), path, agent: z.string().max(40) }), - z.object({ action: z.literal("merge"), path, branch: z.string().max(80) }), - z.object({ action: z.literal("worktree-remove"), path, worktree: z.string().max(1024) }), ]); export async function POST(request: Request) { @@ -48,30 +37,16 @@ export async function POST(request: Request) { switch (body.action) { case "inspect": - return Response.json({ ...inspect(dir), probes: Object.keys(PROBES), home: os.homedir() }); + return Response.json({ ...inspect(dir), home: os.homedir() }); case "env": { if (!inspect(dir).exists) return Response.json({ error: "That folder doesn't exist." }, { status: 404 }); try { const result = writeEnv(dir, body.name, body.value); - return Response.json({ ok: true, ...result, project: { ...inspect(dir), probes: Object.keys(PROBES) } }); + return Response.json({ ok: true, ...result, project: inspect(dir) }); } catch (error) { return Response.json({ error: error instanceof Error ? error.message : "Couldn't write .env.local." }, { status: 400 }); } } - case "probe": { - const results = await Promise.all(body.ids.map((id) => probe(dir, id, body.healthUrl))); - return Response.json({ results }); - } - case "sql": - return Response.json(await runSql(dir, body.query)); - case "start": - try { - return Response.json({ run: startRun(dir, body.command) }); - } catch (error) { - return Response.json({ error: error instanceof Error ? error.message : "Couldn't start it." }, { status: 400 }); - } - case "stop": - return Response.json({ run: stopRun(body.id) }); case "icon": { const file = inspect(dir).icon; const data = file ? iconData(dir, file) : null; @@ -87,23 +62,5 @@ export async function POST(request: Request) { return Response.json({ error: "This project has no stackwise.plan.json." }, { status: 404 }); } } - case "git": { - const info = await repoInfo(dir); - const base = info.branch ?? "HEAD"; - const worktrees = await Promise.all(info.worktrees.map(async (w) => ({ ...w, changes: w.main ? null : await changes(w.path, base) }))); - return Response.json({ ...info, worktrees }); - } - case "worktree-add": - return Response.json(await addWorktree(dir, body.agent)); - case "merge": - return Response.json(await mergeBranch(dir, body.branch)); - case "worktree-remove": { - // Only an agent's copy that git itself lists for this project, never the main one. - const listed = (await repoInfo(dir)).worktrees.find((w) => w.path === body.worktree && !w.main && w.agent); - if (!listed) return Response.json({ error: "That isn't one of this project's agent copies." }, { status: 400 }); - return Response.json(await removeWorktree(dir, listed.path)); - } - case "runs": - return Response.json({ runs: listRuns(dir), log: body.logFor ? runLog(body.logFor, body.after) : null }); } } diff --git a/src/app/globals.css b/src/app/globals.css index 411a2ba..94718cc 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -910,21 +910,11 @@ a.ws-costlines__row { .ws-envlist code { overflow-wrap: anywhere; } -/* Writing the project into a folder on this computer. */ +/* The sections under the files in the export dialog. */ .ws-local { padding-top: var(--mk-4); border-top: 1px solid var(--mk-line); } -.ws-local__row { - align-items: flex-end; -} -.ws-local__row .mk-field { - min-width: 240px; -} -.ws-local__cmd { - padding: var(--mk-2) var(--mk-3); - overflow-wrap: anywhere; -} .ws-local code { font-family: var(--mk-font-mono); font-size: var(--mk-text-xs); @@ -3121,7 +3111,7 @@ body { color: #fff; } -/* ---------- v0.9: the project panel: run, check, set variables, read the database ---------- */ +/* ---------- v0.9: the project panel: link a folder, set its variables ---------- */ .ws-proj { display: flex; flex-direction: column; @@ -3205,47 +3195,10 @@ body { align-items: center; gap: 6px; } -.ws-proj__health { - display: inline-flex; - align-items: center; - gap: 6px; - color: var(--mk-text-muted); - font-size: 12px; -} -.ws-proj__health.is-ok { - color: var(--mk-ok); -} -.ws-proj__health.is-bad { - color: var(--mk-danger); -} -.ws-proj__runrow { - display: flex; - gap: 8px; -} -.ws-proj__cmd { - flex: 1; - min-width: 0; - font-family: var(--mk-font-mono); - font-size: 12px; -} .ws-chip.is-on { background: var(--mk-accent); color: #fff; } -.ws-proj__log { - max-height: 220px; - margin: 0; - padding: 10px 12px; - overflow: auto; - border-radius: 10px; - background: #1c1c1e; - color: #e5e5ea; - font-family: var(--mk-font-mono); - font-size: 11px; - line-height: 1.45; - white-space: pre-wrap; - overflow-wrap: anywhere; -} .ws-proj__envs { display: flex; flex-direction: column; @@ -3290,84 +3243,6 @@ body { min-width: 0; font-family: var(--mk-font-mono); } -.ws-proj__probe { - border-radius: 12px; - background: var(--mk-surface-sunk); -} -.ws-proj__probe > summary, -.ws-proj__probe.is-idle { - display: flex; - align-items: center; - gap: 10px; - padding: 8px 10px; - list-style: none; - cursor: pointer; -} -.ws-proj__probe > summary::-webkit-details-marker { - display: none; -} -.ws-proj__probe.is-bad { - background: var(--mk-danger-soft); -} -.ws-proj__probetext { - display: flex; - flex: 1; - flex-direction: column; - min-width: 0; -} -.ws-proj__probetext strong { - font-size: 13px; -} -.ws-proj__probetext span { - color: var(--mk-text-muted); - font-size: 12px; - overflow-wrap: anywhere; -} -.ws-proj__code { - flex: none; - color: var(--mk-text-faint); - font-family: var(--mk-font-mono); - font-size: 11px; -} -.ws-proj__probebody { - display: flex; - flex-direction: column; - gap: 6px; - padding: 0 10px 10px; -} -.ws-proj__probebody pre, -.ws-proj__sample pre { - max-height: 200px; - margin: 0; - padding: 8px 10px; - overflow: auto; - border-radius: 8px; - background: var(--mk-surface); - font-family: var(--mk-font-mono); - font-size: 11px; - line-height: 1.4; - white-space: pre-wrap; - overflow-wrap: anywhere; -} -.ws-proj__sample { - display: grid; - grid-template-columns: 1fr; - gap: 6px; -} -.ws-proj__sql { - font-family: var(--mk-font-mono); - font-size: 12px; -} -.ws-proj__table { - max-height: 260px; - overflow: auto; -} -.ws-proj__table td, -.ws-proj__table th { - padding: 4px 8px; - font-size: 11px; - white-space: nowrap; -} .ws-node__icon { flex: none; width: 34px; @@ -3422,41 +3297,6 @@ body { font-size: 11px; overflow-wrap: anywhere; } -.ws-proj__agent { - display: flex; - flex-direction: column; - gap: 6px; - padding: 10px 12px; - border-radius: 12px; - background: var(--mk-surface-sunk); -} -.ws-proj__branch { - font-family: var(--mk-font-mono); - font-size: 11px; - color: var(--mk-text-muted); -} -.ws-proj__files ul { - margin: 4px 0 0; - padding-left: 1.1em; - font-size: 11px; -} -.ws-proj__files summary { - color: var(--mk-text-muted); - font-size: 12px; - cursor: pointer; -} -.ws-proj__addagent { - display: flex; - gap: 6px; -} -.ws-proj__addagent .mk-select { - width: auto; - flex: none; -} -.ws-proj__addagent .mk-input { - flex: 1; - min-width: 0; -} .ws-conn__logo { position: relative; display: grid; diff --git a/src/components/ConnectPanel.tsx b/src/components/ConnectPanel.tsx index 86f8be3..c61c50a 100644 --- a/src/components/ConnectPanel.tsx +++ b/src/components/ConnectPanel.tsx @@ -21,7 +21,6 @@ const KEY_PAGES: Record = { claude: "https://console.anthropic.com/settings/keys", openai: "https://platform.openai.com/api-keys", gemini: "https://aistudio.google.com/apikey", - deepseek: "https://platform.deepseek.com/api_keys", }; export function ConnectPanel({ diff --git a/src/components/ProjectPanel.tsx b/src/components/ProjectPanel.tsx index e6a9b7a..6964927 100644 --- a/src/components/ProjectPanel.tsx +++ b/src/components/ProjectPanel.tsx @@ -1,20 +1,16 @@ "use client"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import { planEnv, type SlotId } from "@/engine"; -import { agentName, pairInstructions, presence } from "@/mcp/pairing"; -import { STATE_TEXT } from "./answerers"; +import { planEnv } from "@/engine"; import { Icon } from "./icons"; -import type { Pairing } from "./usePairing"; import type { PlanModel } from "./usePlans"; -import { Logo, copyText, cx, imageToIcon } from "./ui"; +import { cx, imageToIcon } from "./ui"; /** - * The plan's project folder, live: run the app and watch its log, set environment variables - * without opening a file, check every service with the project's own keys, and read the database. - * Everything goes through /api/project, which only this computer can call. Values go from this - * page into the project's .env.local and never come back: the page only ever sees names, whether - * each is set, and masked requests. + * The plan's project folder: link it, see which of the plan's environment variables it has set, + * and set the missing ones without opening a file. Everything goes through /api/project, which + * only this computer can call. Values go from this page into the project's .env.local and never + * come back: the page only ever sees names and whether each is set. */ interface Inspection { @@ -22,41 +18,13 @@ interface Inspection { exists: boolean; framework: string | null; label: string; - commands: { label: string; command: string }[]; - healthUrl: string | null; env: { name: string; set: boolean; files: string[] }[]; configRefs: string[]; envIgnored: boolean; issues: string[]; - probes: string[]; - javaVersion?: string; icon: string | null; } -interface RunInfo { - id: string; - command: string; - running: boolean; - exitCode: number | null; - startedAt: string; -} - -interface ProbeResult { - id: string; - title: string; - ok: boolean; - status?: number; - ms?: number; - request?: { url: string; headers: Record }; - body?: string; - missing?: string[]; - error?: string; - statusPage?: string; - sample?: { sends: unknown; gets: unknown }; -} - -type SqlResult = { columns: string[]; rows: unknown[][]; truncated: boolean; ms: number; database: string } | { error: string }; - async function call(body: Record): Promise { const response = await fetch("/api/project", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }); const json = (await response.json()) as T & { error?: string }; @@ -78,7 +46,7 @@ function Section({ title, icon, children, right }: { title: string; icon: Parame ); } -/** The app's own logo: found in the project, or chosen by the person. Kept with the plan in this browser. */ +/** The app's own logo: found in the project, or chosen by the person. Kept with the plan. */ function AppLogo({ model, path, found, onToast }: { model: PlanModel; path: string; found: string | null; onToast: (message: string) => void }) { const { plan, dispatch } = model; const input = useRef(null); @@ -116,7 +84,7 @@ function AppLogo({ model, path, found, onToast }: { model: PlanModel; path: stri {found && ( <> - {" \u00b7 "} + {" · "} @@ -124,7 +92,7 @@ function AppLogo({ model, path, found, onToast }: { model: PlanModel; path: stri )} {plan.icon && ( <> - {" \u00b7 "} + {" · "} @@ -152,112 +120,6 @@ function AppLogo({ model, path, found, onToast }: { model: PlanModel; path: stri ); } -function Runner({ path, project, appOk, onChecked }: { path: string; project: Inspection; appOk: boolean | null; onChecked: () => void }) { - const [command, setCommand] = useState(project.commands[0]?.command ?? ""); - const [runs, setRuns] = useState([]); - const [log, setLog] = useState([]); - const [busy, setBusy] = useState(false); - const logRef = useRef(null); - const seen = useRef(0); - const current = runs.find((r) => r.running) ?? runs[runs.length - 1]; - - // While a run is open, ask for new log lines every second and a half. - useEffect(() => { - let stopped = false; - let timer = 0; - const tick = async () => { - try { - const body = await call<{ runs: RunInfo[]; log: { lines: string[]; total: number } | null }>({ action: "runs", path, logFor: current?.id, after: seen.current }); - if (stopped) return; - setRuns(body.runs); - if (body.log && body.log.lines.length) { - seen.current = body.log.total; - setLog((l) => [...l, ...body.log!.lines].slice(-600)); - } - } catch { - // The next tick tries again. - } - if (!stopped) timer = window.setTimeout(tick, 1500); - }; - void tick(); - return () => { - stopped = true; - window.clearTimeout(timer); - }; - }, [path, current?.id]); - - useEffect(() => { - logRef.current?.scrollTo({ top: logRef.current.scrollHeight }); - }, [log.length]); - - const start = async () => { - setBusy(true); - seen.current = 0; - setLog([]); - try { - const { run } = await call<{ run: RunInfo }>({ action: "start", path, command }); - setRuns((r) => [...r.filter((x) => x.id !== run.id), run]); - } finally { - setBusy(false); - } - }; - - return ( -
- - {appOk === null ? "Checking" : appOk ? "App is up" : "Not running"} - - - } - > -
- setCommand(e.target.value)} spellCheck={false} aria-label="Command to run" /> - - {project.commands.map((c) => ( - - ))} - - {current?.running ? ( - - ) : ( - - )} -
- {project.commands.length > 1 && ( -
- {project.commands.map((c) => ( - - ))} -
- )} - {current && ( -

- {current.running ? `Running since ${new Date(current.startedAt).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" })}` : `Stopped${current.exitCode === null ? "" : `, exit code ${current.exitCode}`}`}. -

- )} - {log.length > 0 && ( -
-          {log.join("\n")}
-        
- )} -
- ); -} - function EnvRow({ name, service, set, browser, planned, onSave }: { name: string; service?: string; set: boolean; browser: boolean; planned: boolean; onSave: (value: string) => Promise }) { const [editing, setEditing] = useState(false); const [value, setValue] = useState(""); @@ -297,315 +159,27 @@ function EnvRow({ name, service, set, browser, planned, onSave }: { name: string ); } -function ProbeRow({ result, logo, name }: { result: ProbeResult; logo: React.ReactNode; name: string }) { - return ( -
- - {logo} - - {name} - {result.ok ? result.title : (result.error ?? `Answered ${result.status}`)} - - - {result.ok ? "✓" : "×"} - - {result.status !== undefined && ( - - {result.status} · {result.ms} ms - - )} - -
- {result.request && ( - <> - Request (keys masked) -
{`GET ${result.request.url}${Object.entries(result.request.headers)
-              .map(([k, v]) => `\n${k}: ${v}`)
-              .join("")}`}
- - )} - {result.body && ( - <> - What came back -
{result.body}
- - )} - {result.sample && ( - <> - What travels on this connection (example) -
-
- Your app sends -
{JSON.stringify(result.sample.sends, null, 2)}
-
-
- It gets back -
{JSON.stringify(result.sample.gets, null, 2)}
-
-
- - )} - {result.statusPage && ( - - Their status page - - )} -
-
- ); -} - -interface GitWorktree { - path: string; - branch: string | null; - main: boolean; - agent: string | null; - changes: { uncommitted: string[]; ahead: number; committed: string[] } | null; -} - -interface GitInfo { - repo: boolean; - branch: string | null; - clean: boolean; - worktrees: GitWorktree[]; -} - -const AGENT_KINDS = [ - { id: "claude-code", label: "Claude Code" }, - { id: "codex", label: "Codex" }, - { id: "gemini-cli", label: "Gemini CLI" }, -]; - -/** - * More than one agent at once: each gets its own copy of the repo (a git worktree beside it, on - * its own branch), listens for its own messages, and gets merged back when the person says so. - */ -function Agents({ path, pairing, onToast }: { path: string; pairing: Pairing; onToast: (message: string) => void }) { - const [info, setInfo] = useState(null); - const [kind, setKind] = useState("codex"); - const [suffix, setSuffix] = useState(""); - const [confirm, setConfirm] = useState(null); - const [busy, setBusy] = useState(false); - - const load = useCallback(async () => { - try { - setInfo(await call({ action: "git", path })); - } catch { - setInfo({ repo: false, branch: null, clean: false, worktrees: [] }); - } - }, [path]); - - useEffect(() => { - let stopped = false; - let timer = 0; - const tick = async () => { - await load(); - if (!stopped) timer = window.setTimeout(tick, 5000); - }; - timer = window.setTimeout(tick, 0); - return () => { - stopped = true; - window.clearTimeout(timer); - }; - }, [load]); - - const act = async (body: Record, done: (result: Record) => string) => { - setBusy(true); - try { - const result = await call>({ path, ...body }); - onToast(typeof result.error === "string" ? `${result.error}${Array.isArray(result.conflicts) && result.conflicts.length ? ` Clashing files: ${result.conflicts.join(", ")}.` : ""}` : done(result)); - await load(); - } catch (e) { - onToast(e instanceof Error ? e.message : "That didn't work."); - } finally { - setBusy(false); - setConfirm(null); - } - }; - - if (!info) return null; - const agentId = suffix.trim() ? `${kind}-${suffix.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")}` : kind; - const copies = info.worktrees.filter((w) => !w.main && w.agent); - - return ( -
Each works in its own copy}> - {!info.repo ? ( -

This folder isn't a git repository, so agents can't get their own copies. Run git init in it to use this.

- ) : ( - <> -

- Your copy is on {info.branch ?? "a detached commit"} - {info.clean ? ", with nothing uncommitted." : ", with uncommitted changes. Commit them before merging an agent's work."} -

- {copies.map((w) => { - const state = pairing.agents[w.agent!]; - const listening = state ? presence(state, pairing.serverNow) : "not-connected"; - const changed = w.changes ? [...new Set([...w.changes.committed, ...w.changes.uncommitted])] : []; - const claude = w.agent!.startsWith("claude-code"); - const start = claude ? `cd ${w.path} && claude "/mcp__stackwise__pair ${w.agent}"` : `cd ${w.path}`; - return ( -
-
- - {agentName(w.agent!)} - {w.branch} - {STATE_TEXT[listening]} -
- - {w.path.replace(/^\/Users\/[^/]+/, "~")}. {w.changes?.ahead ?? 0} commit{w.changes?.ahead === 1 ? "" : "s"} ahead, {changed.length} file{changed.length === 1 ? "" : "s"} changed - {w.changes?.uncommitted.length ? `, ${w.changes.uncommitted.length} not committed yet` : ""}. - - {changed.length > 0 && ( -
- Files -
    - {changed.map((f) => ( -
  • - {f} -
  • - ))} -
-
- )} -
- - {confirm === w.path ? ( - - ) : ( - - )} - -
-
- ); - })} -
{ - e.preventDefault(); - void act({ action: "worktree-add", agent: agentId }, (r) => `Made a copy for ${agentName(agentId)} at ${String(r.path)}, on ${String(r.branch)}. Start the agent there and pair it.`); - }} - > - - setSuffix(e.target.value)} placeholder="name (optional), like frontend" aria-label="Name for this agent" /> - -
- - )} -
- ); -} - -function SqlConsole({ path }: { path: string }) { - const [query, setQuery] = useState("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY 1"); - const [result, setResult] = useState(null); - const [busy, setBusy] = useState(false); - const run = async () => { - setBusy(true); - try { - setResult(await call({ action: "sql", path, query })); - } catch (error) { - setResult({ error: error instanceof Error ? error.message : "The query failed." }); - } finally { - setBusy(false); - } - }; - return ( -
Read-only}> -