Skip to content

refactor(protect): stack-adapter architecture for the protect scaffolder#81

Merged
patchstackdave merged 1 commit into
mainfrom
feat/protect-install-adapters
Jul 15, 2026
Merged

refactor(protect): stack-adapter architecture for the protect scaffolder#81
patchstackdave merged 1 commit into
mainfrom
feat/protect-install-adapters

Conversation

@patchstackdave

Copy link
Copy Markdown
Contributor

Foundation for the "two-track, never-manual" install direction — reorganizes patchstack-connect protect around a per-stack adapter interface.

  • src/protect/install/index.ts (orchestrator + registry), types.ts (Adapter = { name, label, detect, wire }), util.ts (shared read/log/templatesDir), adapters/tanstack-supabase.ts (today's TanStack Start + Supabase logic, moved verbatim — scaffold / bake UUID / patch client + start / reconcile blocks).
  • runProtect now returns a structured ProtectResult{ status: 'wired', adapter, changed } or { status: 'unsupported', supported }.
  • No more silent skip: an unmatched stack logs a loud, actionable message and returns unsupported — the seam the agent-fallback track will hook into.
  • Deleted the monolithic install.ts; cli.ts + tests repointed. Templates unchanged.

Behaviorally identical for the supported stack (existing install tests all pass); +2 tests for the new result contract + escalation. 443 pass, typecheck + build clean.

Adding a new builder later = drop a file in adapters/ and register it. AST-based wire() and the agent-assisted fallback for unmatched stacks build on this.

🤖 Generated with Claude Code

Reorganize `patchstack-connect protect` around a per-stack adapter interface so more
builders/frameworks can be auto-wired, and so an unmatched stack escalates instead of
silently skipping (the "never manual install" direction).

- src/protect/install/{index,types,util}.ts + adapters/tanstack-supabase.ts
  - `Adapter` = { name, label, detect(cwd), wire(cwd, opts) }; the current TanStack Start +
    Supabase logic (scaffold / bake UUID / patch client + start / reconcile blocks) is now
    adapter #1, unchanged behaviorally.
  - index.ts registry picks the first matching adapter; `runProtect` returns a structured
    ProtectResult (`wired` + adapter + changed files, or `unsupported` + supported list).
  - **No silent skip:** an unmatched stack now logs a loud, actionable message (guard engine
    is stack-agnostic; needs a new adapter or agent-assisted install) — the seam for the
    agent-fallback track.
- Deleted the monolithic src/protect/install.ts; cli.ts + tests repointed.

Templates unchanged (still src/protect/templates → dist/protect/templates). +2 tests
(wired-result contract, escalation). 443 tests pass, typecheck + build clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderbuds

coderbuds Bot commented Jul 15, 2026

Copy link
Copy Markdown

Well-structured adapter introduction improves scaffold maintainability and clarity.

🎯 Quality: 100% Elite · 📦 Size: Medium

📈 This month: Your 33rd PR — above team average · Averaging Excellent

See how your team is trending →

@patchstackdave

Copy link
Copy Markdown
Contributor Author

/review

@patchstackdave patchstackdave merged commit 0a44e40 into main Jul 15, 2026
4 checks passed
@patchstackdave patchstackdave deleted the feat/protect-install-adapters branch July 15, 2026 15:40
patchstackdave added a commit that referenced this pull request Jul 15, 2026
Two new per-stack adapters on the #81 interface, dependency-free (anchor + #region markers,
same approach as tanstack — no AST parser, keeping dependencies:{}).

- Express: detect (express dep + an `= express()` site), scaffold the generic guard, and wire
  `app.use(patchstackMiddleware)` right after the app is created (import + region-marked insert,
  idempotent). verify() checks the guard is scaffolded + the middleware is wired.
- Next.js: detect (next dep); scaffold `middleware.ts` (+ co-located patchstack.rules.json) from a
  new template running the request-phase guard as edge middleware. An EXISTING middleware is never
  overwritten — we scaffold the rules and print a plan instead. verify() checks the managed
  middleware + rules are present.
- Registered in the orchestrator (tanstack → next → express → generic fallback); AGENT-INSTALL
  lists the newly auto-wired stacks.

+4 tests. 451 tests pass, typecheck + build clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
patchstackdave added a commit that referenced this pull request Jul 15, 2026
Two new per-stack adapters on the #81 interface, dependency-free (anchor + #region markers,
same approach as tanstack — no AST parser, keeping dependencies:{}).

- Express: detect (express dep + an `= express()` site), scaffold the generic guard, and wire
  `app.use(patchstackMiddleware)` right after the app is created (import + region-marked insert,
  idempotent). verify() checks the guard is scaffolded + the middleware is wired.
- Next.js: detect (next dep); scaffold `middleware.ts` (+ co-located patchstack.rules.json) from a
  new template running the request-phase guard as edge middleware. An EXISTING middleware is never
  overwritten — we scaffold the rules and print a plan instead. verify() checks the managed
  middleware + rules are present.
- Registered in the orchestrator (tanstack → next → express → generic fallback); AGENT-INSTALL
  lists the newly auto-wired stacks.

+4 tests. 451 tests pass, typecheck + build clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
patchstackdave added a commit that referenced this pull request Jul 15, 2026
)

* feat(protect): Express + Next.js adapters

Two new per-stack adapters on the #81 interface, dependency-free (anchor + #region markers,
same approach as tanstack — no AST parser, keeping dependencies:{}).

- Express: detect (express dep + an `= express()` site), scaffold the generic guard, and wire
  `app.use(patchstackMiddleware)` right after the app is created (import + region-marked insert,
  idempotent). verify() checks the guard is scaffolded + the middleware is wired.
- Next.js: detect (next dep); scaffold `middleware.ts` (+ co-located patchstack.rules.json) from a
  new template running the request-phase guard as edge middleware. An EXISTING middleware is never
  overwritten — we scaffold the rules and print a plan instead. verify() checks the managed
  middleware + rules are present.
- Registered in the orchestrator (tanstack → next → express → generic fallback); AGENT-INSTALL
  lists the newly auto-wired stacks.

+4 tests. 451 tests pass, typecheck + build clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* feat(protect): SvelteKit, Astro, Fastify adapters

Three more per-stack adapters (Arcjet-parity for the JS frameworks, minus NestJS/Python),
dependency-free — same anchor + #region approach, no AST parser, dependencies:{} unchanged.

- SvelteKit + Astro: seam-file-is-the-guard. New shared `seam.ts` (wireSeam/verifySeam) scaffolds
  the framework's server hook from a template (`src/hooks.server.ts` → handle, `src/middleware.ts`
  → onRequest) + co-located patchstack.rules.json. An EXISTING hook is never overwritten — scaffold
  rules + print a compose-with-sequence() plan instead.
- Fastify: register-into-app (like express). scaffoldGeneric now takes a guard-template arg so the
  Fastify plugin (builds a Request from the parsed fastify request → fetchGuard) lands as the guard;
  wire `app.register(patchstackFastify)` after the fastify() instance.
- Registered most-specific-first (tanstack → next → sveltekit → astro → fastify → express → generic).
- AGENT-INSTALL lists the newly auto-wired stacks.

+5 tests. 456 pass, typecheck + build clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants