From 34871032b7567ab8641218d983af46771514597f Mon Sep 17 00:00:00 2001 From: Dave Jong Date: Wed, 15 Jul 2026 17:00:59 +0200 Subject: [PATCH] feat(protect): generic scaffold + wiring plan + `protect --check` (infra-free agent loop) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close the "unmatched stack" gap without a hosted server or saas/hub: the CLI itself is the channel to the builder's agent (it already runs the CLI and reads stdout). - Unmatched stack no longer returns bare "unsupported" — `runProtect` scaffolds a framework-agnostic guard (templates/generic-guard.ts → src/patchstack/{guard.ts,rules.json}) and prints a wiring plan with best-effort server-entry detection (candidate files + Express). The generic guard exposes protectFetch(handler) (Web-Fetch) and patchstackMiddleware (Node/Express). - `protect --check` (runVerify): inspects the app and reports whether the guard is wired, exit 1 if not — the feedback half of a wire-then-verify loop the agent (or CI) drives. Adapters own their verify(); the generic path checks the guard is scaffolded AND imported into a source file. - Adapter interface gains verify(); tanstack-supabase implements it (guard/client/start checks). - AGENT-INSTALL documents the loop: auto-wire known stacks; otherwise scaffold → wire per plan → `--check` to confirm. No MCP, no backend — all in the npm package. +3 tests (generic scaffold+plan, verify not-wired→wired, tanstack verify). Verified end-to-end via the shipped CLI. 447 tests pass, typecheck + build clean. Co-Authored-By: Claude Opus 4.8 --- AGENT-INSTALL.md | 2 +- src/cli.ts | 21 ++- .../install/adapters/tanstack-supabase.ts | 20 ++- src/protect/install/generic.ts | 123 ++++++++++++++++++ src/protect/install/index.ts | 31 +++-- src/protect/install/types.ts | 20 +++ src/protect/templates/generic-guard.ts | 48 +++++++ tests/protect/install.test.ts | 25 ++-- tests/protect/verify-and-plan.test.ts | 53 ++++++++ 9 files changed, 314 insertions(+), 29 deletions(-) create mode 100644 src/protect/install/generic.ts create mode 100644 src/protect/templates/generic-guard.ts create mode 100644 tests/protect/verify-and-plan.test.ts diff --git a/AGENT-INSTALL.md b/AGENT-INSTALL.md index 2b556bf..7c72d2e 100644 --- a/AGENT-INSTALL.md +++ b/AGENT-INSTALL.md @@ -8,7 +8,7 @@ This versioned reference ships inside `@patchstack/connect` and documents each s - It reads the project's **dependency list only** — from the lockfile (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`) or, on bun projects (`bun.lock`/`bun.lockb`), by enumerating the installed packages under `node_modules/` — and sends package names + versions to Patchstack for vulnerability matching. No source code, no env var values, no file paths, no git history. (`mark-build` additionally stamps built HTML with a coarse stack descriptor that may include hosting-related env variable *names* — e.g. `VERCEL`, `CF_PAGES` — never their values.) - **`scan` makes one source edit, and only after a successful post:** it adds (or updates) the disclosure widget's `