@withmata/blueprints 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
1
  ---
2
2
  name: audit
3
- description: Run a project health check against available blueprints (read-only analysis)
4
- allowed-tools: Read, Glob, Grep, Bash(git *), Bash(ls *)
3
+ description: Run a project health check against available blueprints (read-only analysis, with optional upgrade execution)
4
+ allowed-tools: Read, Write, Edit, Glob, Grep, Bash
5
5
  ---
6
6
 
7
7
  # Project Audit
8
8
 
9
- Run a health check against available blueprints. Analyze this project's current state and recommend improvements, missing best practices, or blueprints that could replace hand-rolled infrastructure. This command is read-only — it does not modify any files.
9
+ Run a health check against available blueprints. Analyze this project's current state, check installed blueprints for available upgrades, and recommend improvements. The analysis phase is read-only — modifications only happen if the user explicitly approves upgrades in Step 6.
10
10
 
11
11
  ## Step 1: Read Available Blueprints
12
12
 
@@ -15,22 +15,18 @@ Load all available blueprint specs to understand what is possible:
15
15
  ```
16
16
  ~/.withmata/blueprints/blueprints/discovery/product-discovery/BLUEPRINT.md
17
17
  ~/.withmata/blueprints/blueprints/foundation/monorepo-turbo/BLUEPRINT.md
18
- ~/.withmata/blueprints/blueprints/features/auth-better-auth/BLUEPRINT.md
19
- ```
20
-
21
- Also scan for any additional feature blueprints:
22
-
23
- ```
24
18
  ~/.withmata/blueprints/blueprints/features/*/BLUEPRINT.md
25
19
  ```
26
20
 
27
21
  Only consider a blueprint "available" if its BLUEPRINT.md has `Status: Complete`. If not found, run `npx @withmata/blueprints` to install.
28
22
 
23
+ For each available blueprint, also read its template files (`files/**/*`) — you'll need these for upgrade comparison in Step 4.
24
+
29
25
  ## Step 2: Read Project Context
30
26
 
31
27
  Check if `.project-context.md` exists in this project root.
32
28
 
33
- - **If it exists**: read it fully. Note which stages are complete (Discovery, Foundation, Installed Blueprints) and what choices were made.
29
+ - **If it exists**: read it fully. Note which stages are complete (Discovery, Foundation, Installed Blueprints) and what choices were made. Pay attention to `installed_at` dates for each blueprint.
34
30
  - **If it does not exist**: note this — it means either no blueprints have been used, or the project predates the blueprint system.
35
31
 
36
32
  ## Step 3: Explore the Project
@@ -75,11 +71,13 @@ Regardless of whether project context exists, explore the actual project to unde
75
71
  - Tailwind version? Check `tailwindcss` version in package.json — v3 (JS config) vs v4 (CSS config)
76
72
  - Is there a shared UI package, or are components duplicated?
77
73
  - Component library? shadcn/ui, Radix, MUI, Chakra?
74
+ - Does `shared-styles.css` have the full design system (animations, sidebar tokens, chart tokens) or just the minimal foundation version?
78
75
 
79
76
  ### 3f. Environment & Validation
80
77
 
81
- - How are env vars handled? t3-env, raw `process.env`, dotenv only?
82
- - Is there input validation? Zod, Valibot, Yup, Joi?
78
+ - How are env vars handled? t3-env with client/server split, single env.ts, raw `process.env`, dotenv only?
79
+ - Is there `.env.example` with documentation?
80
+ - Is there build-time validation (env imported in `next.config.ts`)?
83
81
 
84
82
  ### 3g. Code Quality
85
83
 
@@ -96,9 +94,44 @@ For each blueprint listed under `## Installed Blueprints` in `.project-context.m
96
94
  - Check if each `required` dependency is also listed in Installed Blueprints
97
95
  - If a required dependency is missing, include it in the report as a recommendation
98
96
 
99
- Example finding: "auth-better-auth is installed but its required dependency db-drizzle-postgres is not. Auth created a minimal db structure that lacks the full schema-group patterns. Run `/scaffold-db` to add the complete db patterns — it will merge without overwriting auth files."
97
+ ## Step 4: Check Installed Blueprints for Upgrades
98
+
99
+ **Note on system migrations:** System-level migrations (consolidating maintenance folders, renaming legacy fields, upgrading env patterns) are handled by `/scaffold-foundation`'s upgrade mode (Step 1.6a). The audit doesn't define its own migrations — it detects that foundation has upgrades available, which includes any pending migrations. When the user approves, the audit delegates to scaffold-foundation which runs the migrations as part of its upgrade flow.
100
+
101
+ For each blueprint listed in `.project-context.md` under `## Installed Blueprints`, compare the current blueprint templates against what's installed in the project.
102
+
103
+ ### 4a. For each installed blueprint:
104
+
105
+ 1. Read the `files_created` or `files_modified` list from project context
106
+ 2. Read the `installed_at` date
107
+ 3. For each file in the blueprint's File Manifest:
108
+ - Read the current template file from `~/.withmata/blueprints/`
109
+ - Resolve placeholders (`{{SCOPE}}`, `{{APP_NAME}}`, etc.) using project context values
110
+ - Read the corresponding file in the project
111
+ - Compare them and categorize:
112
+ - **Template updated** — the blueprint template has changed, the project file matches the OLD template (upgrade available)
113
+ - **New file** — file exists in the current blueprint but not in the project (added since install)
114
+ - **Unchanged** — template matches project file (no action needed)
115
+ - **User-modified** — project file differs from both old and new templates (user customized it — flag for careful merge)
116
+
117
+ 4. Check for new dependencies in the blueprint's `package.json` templates that aren't in the project's `package.json`
118
+
119
+ ### 4b. Compile upgrade details
100
120
 
101
- ## Step 4: Generate the Audit Report
121
+ For each blueprint with available upgrades, prepare a detailed summary:
122
+
123
+ - Blueprint name and install date
124
+ - Each file with changes: what specifically changed and why it matters
125
+ - New dependencies that would be added
126
+ - Whether files are blueprint-owned (safe to replace) or user-modified (needs merge)
127
+
128
+ ### 4c. Check for foundation-level upgrades
129
+
130
+ If foundation is installed, also check:
131
+ - Are there new feature blueprints available that weren't installed? (e.g., env-t3, tailwind-v4, ui-shared-components)
132
+ - Are there structural improvements in the foundation templates?
133
+
134
+ ## Step 5: Generate the Audit Report
102
135
 
103
136
  Present findings as a structured report. Be concrete and specific — reference actual files and patterns found.
104
137
 
@@ -116,57 +149,183 @@ Present findings as a structured report. Be concrete and specific — reference
116
149
  | Foundation / Structure | [done / partial / needs work] | [Brief note] |
117
150
  | Authentication | [blueprint / hand-rolled / third-party / none] | [Brief note] |
118
151
  | Database | [Drizzle / Prisma / other / none] | [Brief note] |
119
- | Styling | [Tailwind v4 / v3 / other] | [Brief note] |
152
+ | Styling | [Tailwind v4 full / v4 minimal / v3 / other] | [Brief note] |
153
+ | UI Package | [blueprint / hand-rolled / none] | [Brief note] |
154
+ | Environment Variables | [t3-env split / t3-env single / raw process.env / none] | [Brief note] |
120
155
  | Code Quality | [good / needs attention] | [Brief note] |
121
156
 
122
- ### Recommendations
157
+ ### Blueprint Upgrades Available
158
+
159
+ For each installed blueprint with updates, show detailed information. Use plain language — explain what the change means for the project, not just what files changed:
160
+
161
+ ```
162
+ ┌─────────────────────────────────────────────────────
163
+ │ env-t3 (installed 2026-03-15)
164
+
165
+ │ What's improved:
166
+
167
+ │ • Better empty value handling
168
+ │ Your environment validation now catches a common
169
+ │ mistake: setting a variable to an empty string
170
+ │ (like DATABASE_URL=) which previously passed
171
+ │ validation but caused crashes at runtime.
172
+ │ File: src/env/server.ts
173
+
174
+ │ • Clearer documentation for teammates
175
+ │ The .env.example file now has section headers and
176
+ │ explains what each variable is for, with example
177
+ │ values for local development and production.
178
+ │ File: .env.example
179
+
180
+ │ To apply: /scaffold-env
181
+ └─────────────────────────────────────────────────────
182
+
183
+ ┌─────────────────────────────────────────────────────
184
+ │ tailwind-v4 (installed 2026-03-15)
185
+
186
+ │ What's improved:
187
+
188
+ │ • Ready for dashboards and data pages
189
+ │ New color tokens for charts and sidebar navigation
190
+ │ that work in both light and dark mode. If you build
191
+ │ any analytics pages or admin dashboards, the styling
192
+ │ is ready to go.
193
+ │ File: config/tailwind-config/shared-styles.css
194
+
195
+ │ • Cleaner scrollable areas
196
+ │ Added a utility to hide scrollbars while keeping
197
+ │ scroll functionality — useful for custom menus,
198
+ │ sidebars, and overflow containers.
199
+ │ New dependency: tailwind-scrollbar-hide
200
+
201
+ │ To apply: /scaffold-tailwind
202
+ └─────────────────────────────────────────────────────
203
+ ```
204
+
205
+ If no upgrades are available for any installed blueprint, say: "All installed blueprints are up to date — you're running the latest patterns."
206
+
207
+ ### Recommended Blueprints (Not Yet Installed)
208
+
209
+ For each available blueprint that's NOT installed and would benefit this project. Explain the value in terms a non-developer can understand — focus on what it enables for the product, not just the technical implementation:
123
210
 
124
- For each recommendation:
211
+ ```
212
+ ┌─────────────────────────────────────────────────────
213
+ │ Shared UI Component Library
214
+ │ Blueprint: ui-shared-components
215
+
216
+ │ What this gives you:
217
+ │ A central place for all your buttons, forms, cards,
218
+ │ and other interface elements. When you update a
219
+ │ component here, every app in your project gets the
220
+ │ update automatically. No more copy-pasting UI code
221
+ │ between apps and watching them drift apart.
222
+
223
+ │ Includes a tool (shadcn) for quickly adding
224
+ │ professionally designed, accessible components —
225
+ │ just run one command to add a button, dialog,
226
+ │ dropdown, or any of 40+ ready-made components.
227
+
228
+ │ Ready to install: Yes
229
+ │ Requires: Tailwind design system (installed ✓)
230
+
231
+ │ To install: /scaffold-ui
232
+ └─────────────────────────────────────────────────────
233
+ ```
234
+
235
+ ### Other Recommendations
236
+
237
+ For non-blueprint recommendations (code quality, structural improvements):
125
238
 
126
239
  1. **[Priority: High/Medium/Low] [Category] — [One-line summary]**
127
240
  - **What we found:** [Specific observation referencing actual files]
128
- - **Why it matters:** [Impact on the project — explain for non-technical users too]
241
+ - **Why it matters:** [Impact — explain for non-technical users too]
129
242
  - **Action:** [Exact command or step to fix it]
130
243
 
131
- ---
132
-
133
244
  ### Recommendation Priority Guidelines
134
245
 
135
246
  **High priority** — things that block progress or create real risk:
136
247
  - No auth system and the product needs user accounts
137
248
  - No monorepo structure in a multi-workspace project
138
- - Hand-rolled auth with security gaps (plain text passwords, no CSRF, no rate limiting)
139
- - Missing environment variable validation
249
+ - Hand-rolled auth with security gaps
250
+ - Missing environment variable validation (raw `process.env` usage)
140
251
 
141
252
  **Medium priority** — things that improve quality and maintainability:
142
253
  - A blueprint could replace hand-rolled infrastructure
143
- - Missing product documentation for a project still figuring out its direction
254
+ - Missing product documentation
144
255
  - Inconsistent patterns across workspaces
145
256
  - Tailwind v3 when v4 is available
146
- - ESLint + Prettier when Biome could replace both
257
+ - Single `env.ts` instead of client/server split
147
258
 
148
259
  **Low priority** — nice-to-haves:
149
- - Blueprints in development that are not yet available (mention them as "coming soon")
150
260
  - Style preferences that do not affect functionality
151
261
  - Optimizations for mature projects
152
262
 
153
- ## Step 5: Provide Actionable Next Steps
263
+ ---
264
+
265
+ ## Step 6: Offer Actionable Upgrades
266
+
267
+ After presenting the report, offer to apply changes. This is the transition from read-only analysis to execution.
268
+
269
+ ### Present the action plan:
270
+
271
+ ```
272
+ ──────────────────────────────────────────────
273
+ Action Plan
154
274
 
155
- End the report with a clear list of what to do, in recommended order:
275
+ Blueprint upgrades (improvements to what you have):
276
+ 1. foundation — system cleanup + template updates
277
+ 2. env-t3 — better empty value handling, clearer docs
278
+ 3. tailwind-v4 — dashboard tokens, scrollbar utility
156
279
 
157
- ### Next Steps
280
+ New capabilities (not yet installed):
281
+ 4. ui-shared-components — shared component library with shadcn
158
282
 
283
+ Which would you like to apply? (numbers, "all", or "skip")
284
+ ──────────────────────────────────────────────
159
285
  ```
160
- # Run these in order — each one is independent, stop whenever you want
161
286
 
162
- 1. [command] # [what it does and why]
163
- 2. [command] # [what it does and why]
164
- ...
287
+ Foundation upgrades always run first when selected — they include system migrations (like consolidating maintenance folders) that other upgrades may depend on.
288
+
289
+ ### On user response:
290
+
291
+ - **"all"** — run everything in dependency order: foundation first, then other upgrades, then new installs last
292
+ - **Specific numbers** — run only the selected ones, still in the correct order
293
+ - **"skip"** — end the audit without making changes
294
+
295
+ ### Execution order:
296
+
297
+ 1. **Foundation upgrades first** — includes system migrations that clean up legacy patterns
298
+ 2. **Other blueprint upgrades** — in dependency order (env, tailwind, db, auth)
299
+ 3. **New blueprint installs** — in dependency order (tailwind before UI, db before auth)
300
+
301
+ For each approved action:
302
+ 1. Announce what's happening in plain language: "Upgrading your environment variable setup..."
303
+ 2. For system migrations: execute the migration directly (consolidate files, rename fields)
304
+ 3. For blueprint upgrades/installs: follow that scaffold skill's upgrade mode (Step 1.6)
305
+ 4. Report result: "Done — updated 2 files, your env setup now catches empty values"
306
+ 5. Move to next
307
+
308
+ ### After all upgrades:
309
+
310
+ Present a final summary:
311
+
165
312
  ```
313
+ ──────────────────────────────────────────────
314
+ What was done
166
315
 
167
- For blueprint commands, use the slash command format: `/discover`, `/scaffold-foundation`, `/scaffold-auth`
316
+ Blueprint upgrades:
317
+ ✓ foundation — consolidated maintenance rules,
318
+ cleaned up legacy patterns
319
+ ✓ env-t3 — updated server.ts, .env.example
320
+ ✓ tailwind-v4 — updated shared-styles.css, added
321
+ tailwind-scrollbar-hide
168
322
 
169
- For non-blueprint improvements, include the actual shell commands or instructions.
323
+ Skipped:
324
+ ○ ui-shared-components — not selected
325
+
326
+ Next: run pnpm install to pick up new dependencies.
327
+ ──────────────────────────────────────────────
328
+ ```
170
329
 
171
330
  ## Tone Guidelines
172
331
 
@@ -174,12 +333,13 @@ For non-blueprint improvements, include the actual shell commands or instruction
174
333
  - **Be warm and accessible.** The user may be non-technical. Explain WHY something matters, not just what to do.
175
334
  - **Be specific.** "Your auth looks hand-rolled" is not helpful. "I found JWT signing in `lib/auth.ts` without CSRF protection — the auth blueprint handles this with Better Auth's built-in security" is helpful.
176
335
  - **Separate facts from opinions.** "You are using ESLint + Prettier" is a fact. "Biome could replace both with simpler config" is a recommendation — label it as such.
177
- - **Do not overwhelm.** Lead with the 3-5 most impactful recommendations. If there are many findings, prioritize.
336
+ - **Do not overwhelm.** Lead with the most impactful findings. If everything is up to date and nothing is missing, keep the report short.
178
337
  - **Celebrate what is done well.** If something follows best practices, acknowledge it briefly.
179
338
 
180
339
  ## Important Notes
181
340
 
182
- - This command is **read-only**. It does not modify any files it only reads and reports.
183
- - Only recommend blueprints with `Status: Complete`. Mention planned blueprints (tailwind-v4, ui-shared-components) as "coming soon" if relevant, but do not suggest running commands for them.
341
+ - Steps 1–5 are read-only analysis. Step 6 is the only step that modifies files, and only with user approval.
342
+ - Only recommend blueprints with `Status: Complete`.
184
343
  - If the project is empty or brand new, keep the report short: "This is a fresh project. Here is where to start." and suggest `/discover` or `/scaffold-foundation`.
185
- - If everything looks good, say so: "This project is in great shape. No immediate recommendations."
344
+ - If everything is up to date and no recommendations apply: "This project is in great shape. All blueprints are current, no upgrades available."
345
+ - When executing upgrades in Step 6, defer to each scaffold skill's own upgrade mode logic. The audit skill orchestrates but doesn't duplicate the upgrade implementation.
@@ -220,7 +220,7 @@ List anything that can't be automated (aggregated from all stages).
220
220
  Suggest next steps in terms of product progress, not just technical tasks. Reference specific commands:
221
221
 
222
222
  - "The product thesis identified [pillar] as a core pillar — `/scaffold-auth` wires in the user accounts and access control to support that."
223
- - "Other feature blueprints coming soon: UI components, database, Tailwind theming."
223
+ - "Run `/audit` to see all available blueprints and what would benefit your project."
224
224
  - "Start building the core product experience — the [archetype]'s primary workflow."
225
225
 
226
226
  ---
@@ -33,7 +33,48 @@ Check if `.project-context.md` exists in the target project root:
33
33
  When project context provides clear answers, skip the corresponding questions in Step 3. For example:
34
34
  - Context says `server_framework: hono` -> do not ask about server framework
35
35
  - Context says `npm_scope: "@acme"` -> use `@acme` for package references
36
- - Context has `auth-better-auth` in Installed Blueprints -> warn about existing install
36
+ - Context has `auth-better-auth` in Installed Blueprints -> switch to upgrade mode (Step 1.6)
37
+
38
+ ## Step 1.6: Upgrade Mode
39
+
40
+ If `auth-better-auth` is found in `.project-context.md` under `## Installed Blueprints`, switch to upgrade mode.
41
+
42
+ 1. **Read installed state** — from project context, get `files_created`, `choices` (plugins, providers, framework), and `installed_at`
43
+ 2. **Compare templates against installed files** — auth files are heavily customized, so be extra conservative:
44
+ - **Blueprint-owned (safe to update):**
45
+ - Auth client setup (`auth-client.ts`) — compare client plugin configuration pattern
46
+ - Client schemas (`schema/auth.ts`, `schema/organization.ts`) — compare Zod validation patterns
47
+ - Client types (`types/organization.ts`) — compare type definitions
48
+ - **Partially user-owned (merge carefully):**
49
+ - Server auth config (`auth.ts`) — compare plugin setup, but users add custom plugins. Merge new patterns, don't replace.
50
+ - Middleware (`middleware.ts`, `route-protection.ts`) — users customize routes. Only update structural patterns.
51
+ - Env vars — merge into env schema files if env-t3 is installed (add new auth vars, keep existing ones).
52
+ - **User-owned (never touch):**
53
+ - Auth database schema (`auth-schema.ts`) — auto-generated by Better Auth
54
+ - Drizzle config for auth — user-maintained schema file list
55
+ - Custom hooks, context providers with user business logic
56
+ 3. **Present findings:**
57
+ ```
58
+ auth-better-auth was installed on <date>. Checking for updates...
59
+
60
+ Updated templates:
61
+ ☐ auth-client.ts — updated client plugin configuration
62
+ ☐ schema/auth.ts — updated Zod validation
63
+
64
+ Merge candidates (will preserve your customizations):
65
+ ☐ server auth.ts — new plugin option available
66
+ ☐ middleware.ts — updated middleware pattern
67
+
68
+ User-owned (never touched):
69
+ ✓ auth-schema.ts, drizzle config, custom hooks
70
+
71
+ Apply updates?
72
+ ```
73
+ 4. **Apply selectively** — for merge candidates, show the user what's new and let them decide. For auth config, highlight new plugin options or security improvements.
74
+ 5. **Update project context** — update `installed_at` date
75
+ 6. **Skip to Output Summary**
76
+
77
+ **Important:** Auth is the most user-customized blueprint. Most files will have been modified. Upgrade mode should focus on: new plugin options, security improvements, updated patterns. Never replace files wholesale — always merge or show diffs.
37
78
 
38
79
  ## Step 1.7: Check Blueprint Dependencies
39
80
 
@@ -138,7 +179,7 @@ Based on the project structure, project context, and user answers, adapt the blu
138
179
  - Replace `{{APP_NAME}}`, `{{EMAIL_FROM}}`, `{{SCOPE}}`
139
180
  - Copy/adapt `files/server/auth-db.ts` -> `apis/server/src/db/auth.ts`
140
181
  - Copy/adapt `files/server/middleware.ts` -> `apis/server/src/middleware/auth.ts`
141
- - Merge auth env vars into `apis/server/src/env.ts`
182
+ - Merge auth env vars into `apis/server/src/env.ts` (if env-t3 is installed, this uses `@t3-oss/env-core` with Zod schemas — add vars to the `server` schema object)
142
183
 
143
184
  **If single-repo:**
144
185
  - Copy/adapt `files/server/auth.ts` -> `src/lib/auth/index.ts`
@@ -146,7 +187,7 @@ Based on the project structure, project context, and user answers, adapt the blu
146
187
  - Adjust DB import to use direct path: `import { db } from "@/db/auth/client"` or `#db/auth/client`
147
188
  - Copy/adapt `files/server/auth-db.ts` -> `src/lib/db/auth.ts`
148
189
  - Default to Next.js API routes (no separate Hono server)
149
- - Merge auth env vars into existing `env.ts` (or create one)
190
+ - Merge auth env vars into existing env files. If env-t3 is installed (check for `src/env/server.ts`), add server vars to `src/env/server.ts` and client vars to `src/env/client.ts`. Otherwise merge into `env.ts` (or create one).
150
191
 
151
192
  **Both:**
152
193
  - If the project uses a different server framework than Hono, adapt the middleware while keeping the core `auth.api.getSession({ headers })` pattern
@@ -204,6 +245,7 @@ Append an entry to `.project-context.md` under `## Installed Blueprints`:
204
245
  ```yaml
205
246
  ### auth-better-auth
206
247
  blueprint: auth-better-auth
248
+ installed_at: <date>
207
249
  choices:
208
250
  database: <user's choice>
209
251
  auth_db_isolation: <separate|shared>
@@ -228,17 +270,21 @@ Also append any significant architectural decisions to the `## Architecture Deci
228
270
 
229
271
  ### Create Maintenance Skill
230
272
 
231
- Create a project-level maintenance skill for the auth blueprint:
273
+ Append to the shared project-level maintenance skill at `<project>/.claude/skills/project-maintenance/SKILL.md`.
232
274
 
233
- **File:** `<project>/.claude/skills/auth-maintenance/SKILL.md`
275
+ If the file does not exist, create it with frontmatter:
234
276
 
235
277
  ```yaml
236
278
  ---
237
- name: auth-maintenance
238
- description: Maintenance rules for Better Auth. Invoke when modifying auth config, providers, session settings, or auth schema.
279
+ name: project-maintenance
280
+ description: Maintenance rules for all installed blueprints. Invoke when modifying schemas, env vars, auth config, workspace configs, UI components, or Tailwind tokens.
239
281
  user-invocable: false
240
282
  ---
283
+ ```
284
+
285
+ Then append:
241
286
 
287
+ ```markdown
242
288
  ### auth-better-auth maintenance
243
289
  - After modifying Better Auth server config, plugins, or providers: run `pnpm auth:generate && pnpm auth:migrate`
244
290
  - After updating `better-auth` package: run `pnpm auth:generate`, check for schema changes, migrate if needed
@@ -248,6 +294,8 @@ user-invocable: false
248
294
  - Never edit the auto-generated auth schema directly — modify the Better Auth config and regenerate
249
295
  ```
250
296
 
297
+ If a `### auth-better-auth maintenance` section already exists in the file, skip — do not duplicate.
298
+
251
299
  ## Step 6: Output Summary
252
300
 
253
301
  After scaffolding, provide the user with a clear summary:
@@ -32,9 +32,44 @@ Check if `.project-context.md` exists in the target project root:
32
32
 
33
33
  When project context provides clear answers, skip the corresponding questions in Step 3. For example:
34
34
  - Context says `npm_scope: "@acme"` -> use `@acme` for package references
35
- - Context has `db-drizzle-postgres` in Installed Blueprints -> warn about existing install
35
+ - Context has `db-drizzle-postgres` in Installed Blueprints -> switch to upgrade mode (Step 1.6)
36
36
  - Context has `auth-better-auth` installed -> `packages/db/` likely exists already
37
37
 
38
+ ## Step 1.6: Upgrade Mode
39
+
40
+ If `db-drizzle-postgres` is found in `.project-context.md` under `## Installed Blueprints`, switch to upgrade mode.
41
+
42
+ 1. **Read installed state** — from project context, get `files_created`, `choices` (schema group, connection helper), and `installed_at`
43
+ 2. **Compare templates against installed files** — only compare blueprint-owned files, NOT user schema files:
44
+ - `packages/db/package.json` — compare exports pattern, scripts, dependencies. Look for new scripts, updated dep versions.
45
+ - `packages/db/tsconfig.json` — compare TypeScript config.
46
+ - `packages/db/.env.example` — compare env documentation.
47
+ - `drizzle/<group>/drizzle.config.ts` — compare config pattern (but NOT the schema file list — that's user-maintained).
48
+ - `src/<group>/client.ts` — compare connection helper pattern (if included).
49
+ - `src/scripts/seed.ts` — compare seed script pattern.
50
+ 3. **Present findings:**
51
+ ```
52
+ db-drizzle-postgres was installed on <date>. Checking for updates...
53
+
54
+ Updated templates:
55
+ ☐ packages/db/package.json — new scripts or updated dependencies
56
+ ☐ drizzle/<group>/drizzle.config.ts — updated config pattern
57
+
58
+ Unchanged:
59
+ ✓ packages/db/tsconfig.json — no changes
60
+
61
+ User-owned (never touched):
62
+ ✓ src/<group>/*.ts — your schema files
63
+ ✓ drizzle/<group>/*.sql — your migrations
64
+
65
+ Apply updates?
66
+ ```
67
+ 4. **Apply selectively** — merge new scripts/deps into `package.json` without overwriting existing ones. For `drizzle.config.ts`, only update structural patterns — never modify the user's schema file list.
68
+ 5. **Update project context** — update `installed_at` date
69
+ 6. **Skip to Step 6 (Output Summary)**
70
+
71
+ **Important:** Schema files (`src/<group>/*.ts`), migration files (`drizzle/<group>/*.sql`), barrel exports (`index.ts`), and the `.env` file are all user-owned. Upgrade mode must never touch these.
72
+
38
73
  ## Step 2: Understand the Target Project
39
74
 
40
75
  Before making any changes, explore the target project to understand:
@@ -166,6 +201,7 @@ Append an entry to `.project-context.md` under `## Installed Blueprints`:
166
201
  ```yaml
167
202
  ### db-drizzle-postgres
168
203
  blueprint: db-drizzle-postgres
204
+ installed_at: <date>
169
205
  choices:
170
206
  schema_group: <group name>
171
207
  include_example: <true|false>
@@ -195,17 +231,21 @@ If `.project-context.md` does not exist, create it with the standard header and
195
231
 
196
232
  ### Create Maintenance Skill
197
233
 
198
- Create a project-level maintenance skill for the database blueprint:
234
+ Append to the shared project-level maintenance skill at `<project>/.claude/skills/project-maintenance/SKILL.md`.
199
235
 
200
- **File:** `<project>/.claude/skills/db-maintenance/SKILL.md`
236
+ If the file does not exist, create it with frontmatter:
201
237
 
202
238
  ```yaml
203
239
  ---
204
- name: db-maintenance
205
- description: Maintenance rules for Drizzle + PostgreSQL database. Invoke when modifying schemas, adding entities, or running migrations.
240
+ name: project-maintenance
241
+ description: Maintenance rules for all installed blueprints. Invoke when modifying schemas, env vars, auth config, workspace configs, UI components, or Tailwind tokens.
206
242
  user-invocable: false
207
243
  ---
244
+ ```
208
245
 
246
+ Then append:
247
+
248
+ ```markdown
209
249
  ### db-drizzle-postgres maintenance
210
250
  - After creating a new schema file: add it to `drizzle/<group>/drizzle.config.ts` schema array AND the group's `index.ts` barrel export
211
251
  - After any schema change: run `pnpm <group>:generate && pnpm <group>:migrate`
@@ -214,6 +254,8 @@ user-invocable: false
214
254
  - Never use glob patterns in drizzle.config.ts schema — always list files explicitly, excluding index.ts
215
255
  ```
216
256
 
257
+ If a `### db-drizzle-postgres maintenance` section already exists in the file, skip — do not duplicate.
258
+
217
259
  ## Step 6: Output Summary
218
260
 
219
261
  After scaffolding, provide the user with a clear summary:
@@ -32,7 +32,43 @@ Check if `.project-context.md` exists in the target project root:
32
32
 
33
33
  When project context provides clear answers, skip the corresponding questions in Step 3. For example:
34
34
  - Context has `auth-better-auth` installed -> pre-populate auth env vars
35
- - Context has `env-t3` in Installed Blueprints -> warn about existing install
35
+ - Context has `env-t3` in Installed Blueprints -> switch to upgrade mode (Step 1.6)
36
+
37
+ ## Step 1.6: Upgrade Mode
38
+
39
+ If `env-t3` is found in `.project-context.md` under `## Installed Blueprints`, switch to upgrade mode instead of a fresh install.
40
+
41
+ 1. **Read installed state** — from project context, get the `files_created` list and `choices` (env locations, apps configured)
42
+ 2. **Compare templates against installed files** — for each file in the blueprint's File Manifest:
43
+ - Read the current template from `~/.withmata/blueprints/blueprints/features/env-t3/files/`
44
+ - Resolve `{{APP_NAME}}` using project context
45
+ - Read the corresponding file in the project
46
+ - Categorize:
47
+ - **Updated** — template has changed (new Zod patterns, new structure)
48
+ - **New** — file exists in current blueprint but not in the project (e.g., new backend env template)
49
+ - **Unchanged** — template matches installed file (skip)
50
+ - **User-modified** — file differs from both the old and new templates (user added their own env vars — this is expected and normal for env files)
51
+ 3. **Present findings:**
52
+ ```
53
+ env-t3 was installed on <date>. Checking for updates...
54
+
55
+ Updated templates:
56
+ ☐ src/env/server.ts — updated Zod patterns
57
+ ☐ .env.example — new documentation sections
58
+
59
+ New files available:
60
+ ☐ apis/server/src/env.ts — backend env validation (not set up previously)
61
+
62
+ User-customized (will merge, not replace):
63
+ ✓ src/env/client.ts — you've added custom vars (keeping yours)
64
+
65
+ Apply updates?
66
+ ```
67
+ 4. **Apply selectively** — for user-modified env files (which is most of them), merge new structural patterns while preserving user-added variables. Never delete user env vars.
68
+ 5. **Update project context** — update `installed_at` date
69
+ 6. **Skip to Step 6 (Output Summary)**
70
+
71
+ **Important:** Env files are almost always user-modified (users add their own variables). Upgrade mode for env should focus on structural changes (new `// CONFIGURE:` sections, updated Zod patterns, new `emptyStringAsUndefined` options) rather than replacing the whole file.
36
72
 
37
73
  ## Step 2: Understand the Target Project
38
74
 
@@ -140,6 +176,7 @@ Append an entry to `.project-context.md` under `## Installed Blueprints`:
140
176
  ```yaml
141
177
  ### env-t3
142
178
  blueprint: env-t3
179
+ installed_at: <date>
143
180
  choices:
144
181
  nextjs_env_location: src/env/
145
182
  backend_env_location: src/env.ts
@@ -156,17 +193,21 @@ If `.project-context.md` does not exist, create it with the standard header and
156
193
 
157
194
  ### Create Maintenance Skill
158
195
 
159
- Create a project-level maintenance skill for the env blueprint:
196
+ Append to the shared project-level maintenance skill at `<project>/.claude/skills/project-maintenance/SKILL.md`.
160
197
 
161
- **File:** `<project>/.claude/skills/env-maintenance/SKILL.md`
198
+ If the file does not exist, create it with frontmatter:
162
199
 
163
200
  ```yaml
164
201
  ---
165
- name: env-maintenance
166
- description: Maintenance rules for T3 Env validated environment variables. Invoke when adding, removing, or modifying environment variables.
202
+ name: project-maintenance
203
+ description: Maintenance rules for all installed blueprints. Invoke when modifying schemas, env vars, auth config, workspace configs, UI components, or Tailwind tokens.
167
204
  user-invocable: false
168
205
  ---
206
+ ```
169
207
 
208
+ Then append:
209
+
210
+ ```markdown
170
211
  ### env-t3 maintenance
171
212
  - After adding a new env var: add it to the env schema file (client.ts or server.ts), `.env.example`, and `.env.local`
172
213
  - NEXT_PUBLIC_* vars go in env/client.ts with explicit runtimeEnv mapping; server vars go in env/server.ts
@@ -175,6 +216,8 @@ user-invocable: false
175
216
  - Keep .env.example documented with section headers and local/production hints
176
217
  ```
177
218
 
219
+ If a `### env-t3 maintenance` section already exists in the file, skip — do not duplicate.
220
+
178
221
  ## Step 6: Output Summary
179
222
 
180
223
  After scaffolding, provide the user with a clear summary: