@soulbatical/tetra-dev-toolkit 1.20.0 → 2.0.0

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.
package/README.md CHANGED
@@ -17,8 +17,8 @@ npx tetra-setup
17
17
  ```
18
18
 
19
19
  This creates:
20
- - `.husky/pre-commit` — quick security checks + migration lint before every commit
21
- - `.husky/pre-push` — full security audit + RLS security gate before every push
20
+ - `.husky/pre-commit` — quick security checks before every commit
21
+ - `.husky/pre-push` — hygiene + RLS security gate before every push
22
22
  - `.github/workflows/quality.yml` — full audit on PR/push to main
23
23
  - `.tetra-quality.json` — project config (override defaults)
24
24
 
@@ -30,131 +30,67 @@ npx tetra-setup ci # GitHub Actions only
30
30
  npx tetra-setup config # Config file only
31
31
  ```
32
32
 
33
- ---
33
+ Re-running `tetra-setup hooks` on an existing project adds missing hooks without overwriting existing ones.
34
34
 
35
- ## 8-Layer Security Architecture
35
+ ---
36
36
 
37
- Every Tetra project is protected by 8 layers. From the moment a developer writes code to the moment a database query executes — every layer enforces security independently. If one layer is bypassed, the next catches it.
37
+ ## 3-Layer Security Model
38
38
 
39
- See [SECURITY.md](./SECURITY.md) for the complete architecture reference.
39
+ Every Tetra project is protected by three layers. All three must pass before code reaches production. No fallbacks. No soft warnings. Hard errors only.
40
40
 
41
41
  ```
42
- LAYER 1: CONFIG FILES Feature configs define what SHOULD happen
43
- LAYER 2: PRE-COMMIT Quick checks + migration lint on staged files
44
- LAYER 3: PRE-PUSH Full security audit (12 checks) + live RLS gate
45
- LAYER 4: MIGRATION PUSH tetra-db-push blocks unsafe SQL before Supabase
46
- LAYER 5: CI/CD TypeScript compile + tests + build
47
- LAYER 6: RUNTIME Express middleware (HTTPS, CORS, auth, rate limit, input sanitize)
48
- LAYER 7: DATABASE RLS policies enforce org/user isolation on every query
49
- LAYER 8: DB HELPERS adminDB/userDB/publicDB/systemDB enforce correct access pattern
50
- ```
42
+ LAYER 1: PRE-COMMIT (tetra-audit quick)
43
+ Blocks: hardcoded secrets, service key exposure, direct createClient imports
51
44
 
52
- ---
45
+ LAYER 2: PRE-PUSH (tetra-check-rls + tetra-audit hygiene)
46
+ Blocks: RLS violations on live DB, repo clutter, missing FORCE RLS
53
47
 
54
- ## CLI Tools
48
+ LAYER 3: BUILD (Railway/deploy — tetra-check-rls --errors-only)
49
+ Blocks: anything that bypassed --no-verify. Last line of defense.
50
+ ```
55
51
 
56
- | Command | Description |
57
- |---------|-------------|
58
- | `tetra-audit` | Run quality/security/hygiene checks |
59
- | `tetra-audit quick` | Quick critical checks (pre-commit) |
60
- | `tetra-audit security` | Full security suite (12 checks) |
61
- | `tetra-audit stability` | Stability suite (16 checks) |
62
- | `tetra-audit codeQuality` | Code quality suite (4 checks) |
63
- | `tetra-audit supabase` | Supabase suite (3 checks) |
64
- | `tetra-audit hygiene` | Repo hygiene suite (2 checks) |
65
- | `tetra-audit --ci` | CI mode (GitHub Actions annotations) |
66
- | `tetra-audit --json` | JSON output |
67
- | `tetra-audit --verbose` | Detailed output with fix suggestions |
68
- | `tetra-migration-lint` | Offline SQL migration linter (8 rules) |
69
- | `tetra-migration-lint --staged` | Only git-staged .sql files (pre-commit hook) |
70
- | `tetra-migration-lint --fix-suggestions` | Show fix SQL per violation |
71
- | `tetra-db-push` | Safe wrapper: lint + `supabase db push` |
72
- | `tetra-check-rls` | RLS security gate against live Supabase |
73
- | `tetra-check-rls --fix` | Generate hardening migration SQL |
74
- | `tetra-setup` | Install hooks, CI, and config |
75
- | `tetra-init` | Initialize project config files |
76
- | `tetra-dev-token` | Generate development tokens |
52
+ ### Layer 1: Pre-commit
77
53
 
78
- Exit codes: `0` = passed, `1` = failed (CRITICAL/HIGH), `2` = error. No middle ground.
54
+ Installed by `tetra-setup hooks`. Runs `tetra-audit quick` which executes critical security checks:
79
55
 
80
- ---
56
+ | Check | What it catches |
57
+ |-------|-----------------|
58
+ | Hardcoded Secrets | API keys, tokens, JWTs in source code |
59
+ | Service Key Exposure | Supabase service role keys in frontend code |
60
+ | Direct Supabase Client | `createClient()` imports outside core db wrappers |
81
61
 
82
- ## Check Suites
62
+ If any check fails, the commit is **blocked**. No `--force`, no workaround.
83
63
 
84
- ### Security (12 checks)
64
+ ### Layer 2: Pre-push (RLS Security Gate)
85
65
 
86
- | Check | Severity | What it catches |
87
- |-------|----------|-----------------|
88
- | `hardcoded-secrets` | critical | API keys, tokens, JWTs in source code |
89
- | `service-key-exposure` | critical | Supabase service role keys in frontend |
90
- | `deprecated-supabase-admin` | critical | Legacy `supabaseAdmin` patterns |
91
- | `direct-supabase-client` | critical | Direct `createClient` imports outside core wrappers |
92
- | `frontend-supabase-queries` | critical | `.from()` / `.rpc()` / `.storage` calls in frontend code |
93
- | `tetra-core-compliance` | critical | Missing configureAuth, authenticateToken, or db helpers |
94
- | `mixed-db-usage` | critical | Controller uses wrong DB helper or mixes types |
95
- | `config-rls-alignment` | critical | Feature config accessLevel does not match RLS policies |
96
- | `rpc-security-mode` | critical | SECURITY DEFINER on data RPCs (bypasses RLS) |
97
- | `route-config-alignment` | high | Route middleware does not match config accessLevel |
98
- | `systemdb-whitelist` | high | systemDB() in unauthorized contexts |
99
- | `gitignore-validation` | high | Missing .gitignore entries, tracked .env files |
100
-
101
- ### Migration Lint (8 rules)
102
-
103
- | Rule | Severity | What it catches |
104
- |------|----------|-----------------|
105
- | `DEFINER_DATA_RPC` | critical | SECURITY DEFINER on data RPCs |
106
- | `CREATE_TABLE_NO_RLS` | critical | New table without ENABLE ROW LEVEL SECURITY |
107
- | `DISABLE_RLS` | critical | ALTER TABLE ... DISABLE RLS |
108
- | `USING_TRUE_WRITE` | critical | USING(true) on INSERT/UPDATE/DELETE/ALL policies |
109
- | `GRANT_PUBLIC_ANON` | critical | GRANT write permissions to public/anon |
110
- | `RAW_SERVICE_KEY` | critical | Hardcoded JWT in migration file |
111
- | `DROP_POLICY` | high | DROP POLICY without replacement in same migration |
112
- | `POLICY_NO_WITH_CHECK` | medium | INSERT/UPDATE policy without WITH CHECK clause |
66
+ Installed by `tetra-setup hooks`. Runs before every `git push`. Two checks:
113
67
 
114
- ### Supabase (3 checks, auto-detected)
68
+ 1. **Repo hygiene** `tetra-audit hygiene` blocks clutter
69
+ 2. **RLS Security Gate** — `tetra-check-rls --errors-only` against the live Supabase database
115
70
 
116
- | Check | Severity | What it catches |
117
- |-------|----------|-----------------|
118
- | `rls-policy-audit` | critical | Tables without Row Level Security |
119
- | `rpc-param-mismatch` | critical | TypeScript `.rpc()` calls with wrong parameter names vs SQL |
120
- | `rpc-generator-origin` | high | RPC functions not generated by Tetra SQL Generator |
71
+ The RLS gate auto-detects your Doppler project from `doppler.yaml` and runs 23 checks across 6 categories:
121
72
 
122
- ### Stability (16 checks)
73
+ | Category | Checks | What it catches |
74
+ |----------|--------|-----------------|
75
+ | Foundation | 3 | Tables without RLS, missing FORCE RLS, RLS without policies |
76
+ | Policy Quality | 5 | Public role mutations, always-true policies, missing WITH CHECK |
77
+ | Auth Functions | 4 | Missing auth functions, wrong SECURITY DEFINER, bad search_path |
78
+ | Bypass Routes | 5 | SECURITY DEFINER data functions, anon grants, views bypassing RLS |
79
+ | Data Exposure | 1 | Realtime enabled on sensitive tables |
80
+ | Migration State | 4 | Non-Tetra auth patterns, missing org columns |
123
81
 
124
- | Check | Severity | What it catches |
125
- |-------|----------|-----------------|
126
- | `husky-hooks` | medium | Missing pre-commit/pre-push hooks |
127
- | `ci-pipeline` | medium | Missing or incomplete CI config |
128
- | `npm-audit` | high | Known vulnerabilities in dependencies |
129
- | `tests` | high | Missing test framework, test files, or test scripts |
130
- | `eslint-security` | high | Missing ESLint config, security plugin, or SonarJS plugin |
131
- | `typescript-strict` | medium | TypeScript strict mode not enabled |
132
- | `coverage-thresholds` | medium | No coverage thresholds configured |
133
- | `knip` | medium | Dead code: unused files, dependencies, exports |
134
- | `dependency-cruiser` | medium | Circular dependencies, architecture violations |
135
- | `dependency-automation` | medium | No Dependabot or Renovate configured |
136
- | `prettier` | low | No code formatter configured |
137
- | `conventional-commits` | low | No commit message convention enforced |
138
- | `bundle-size` | low | No bundle size monitoring |
139
- | `sast` | medium | No static application security testing |
140
- | `license-audit` | low | No license compliance checking |
141
- | `security-layers` | high | Missing security layers (auth, rate limiting, CORS, etc.) |
82
+ If the RLS gate fails, the push is **blocked**. No `--no-verify` escape — Layer 3 catches that.
142
83
 
143
- ### Code Quality (4 checks)
84
+ ### Layer 3: Build-time check
144
85
 
145
- | Check | Severity | What it catches |
146
- |-------|----------|-----------------|
147
- | `api-response-format` | medium | Non-standard response format |
148
- | `file-size` | medium | Files exceeding line limits |
149
- | `naming-conventions` | medium | Inconsistent file/dir naming |
150
- | `route-separation` | high | Business logic in route files |
86
+ Add to your Railway/deploy build command:
151
87
 
152
- ### Hygiene (2 checks)
88
+ ```bash
89
+ # Railway build command
90
+ doppler run -- npx tetra-check-rls --errors-only && npm run build
91
+ ```
153
92
 
154
- | Check | Severity | What it catches |
155
- |-------|----------|-----------------|
156
- | `file-organization` | high | Stray .md, .sh, clutter in code dirs |
157
- | `stella-compliance` | medium | Missing Stella integration |
93
+ This catches developers who bypass git hooks with `--no-verify`. If RLS is broken, the build fails, the deploy never happens.
158
94
 
159
95
  ---
160
96
 
@@ -181,194 +117,255 @@ adminDB(req) → Uses user's JWT. RLS enforces org boun
181
117
 
182
118
  A single `createClient` call with the service role key can leak data across all organizations. The db helpers enforce the security boundary at the application layer.
183
119
 
184
- ---
120
+ ### Allowed exceptions
185
121
 
186
- ## Configuration
122
+ These files MAY import `createClient` directly because they ARE the wrappers:
187
123
 
188
- Override defaults in `.tetra-quality.json`:
124
+ - `core/systemDb.ts`, `core/publicDb.ts`, `core/adminDb.ts`, `core/userDb.ts`, `core/superadminDb.ts`
125
+ - `core/Application.ts` (bootstrap)
126
+ - `features/database/services/SupabaseUserClient.ts`
127
+ - `auth/controllers/AuthController.ts` (needs `auth.admin` API)
128
+ - `backend-mcp/src/supabase-client.ts`, `org-scoped-client.ts`, `api-key-service.ts`, `http-server.ts`
129
+ - `scripts/` (not production code)
189
130
 
190
- ```json
191
- {
192
- "suites": {
193
- "security": true,
194
- "stability": true,
195
- "codeQuality": true,
196
- "supabase": "auto",
197
- "hygiene": true
198
- },
199
- "supabase": {
200
- "publicRpcFunctions": ["get_public_data"],
201
- "publicTables": ["public_lookup"],
202
- "backendOnlyTables": ["system_logs", "cron_state"],
203
- "securityDefinerWhitelist": ["auth_org_id", "auth_uid"]
204
- },
205
- "ignore": ["**/legacy/**", "**/scripts/**"]
206
- }
207
- ```
131
+ Everything else gets a **hard error** at commit time.
208
132
 
209
133
  ---
210
134
 
211
- ## New Project Checklist
135
+ ## Usage
212
136
 
213
137
  ```bash
214
- # 1. Install hooks (creates pre-commit + pre-push)
215
- npx tetra-setup hooks
216
-
217
- # 2. Run full audit
218
- npx tetra-audit
138
+ npx tetra-audit # Run all checks
139
+ npx tetra-audit security # Security checks only
140
+ npx tetra-audit stability # Stability checks only
141
+ npx tetra-audit codeQuality # Code quality checks only
142
+ npx tetra-audit supabase # Supabase checks only
143
+ npx tetra-audit hygiene # Repo hygiene checks only
144
+ npx tetra-audit quick # Quick critical checks (pre-commit)
145
+ npx tetra-audit --ci # CI mode (GitHub Actions annotations)
146
+ npx tetra-audit --json # JSON output
147
+ npx tetra-audit --verbose # Detailed output with fix suggestions
148
+ ```
219
149
 
220
- # 3. Run RLS gate manually
221
- doppler run -- npx tetra-check-rls
150
+ Exit codes: `0` = passed, `1` = failed, `2` = error. No middle ground.
222
151
 
223
- # 4. Verify migration lint works
224
- npx tetra-migration-lint
152
+ ## RLS Security Gate (standalone)
225
153
 
226
- # 5. Add to Railway build command
227
- # doppler run -- npx tetra-check-rls --errors-only && npm run build
154
+ ```bash
155
+ npx tetra-check-rls # Auto-detect from doppler.yaml
156
+ npx tetra-check-rls --url <url> --key <key> # Explicit credentials
157
+ npx tetra-check-rls --errors-only # CI/build mode
158
+ npx tetra-check-rls --json # JSON output for automation
159
+ npx tetra-check-rls --fix # Generate hardening migration SQL
160
+ npx tetra-check-rls --check-exec-sql # Verify exec_sql function is secure
228
161
  ```
229
162
 
230
- If any step fails, fix it before writing code. No exceptions.
163
+ ### Programmatic usage
164
+
165
+ ```typescript
166
+ import { runRLSCheck } from '@soulbatical/tetra-core';
167
+
168
+ const report = await runRLSCheck(supabaseServiceClient);
169
+ if (!report.passed) {
170
+ throw new Error(report.summary); // Hard error. No soft fail.
171
+ }
172
+ ```
231
173
 
232
174
  ---
233
175
 
234
- ## Claude Code statusline
176
+ ## Check Suites
235
177
 
236
- A 3-line statusline for Claude Code that shows context usage, costs, project health, and session metadata.
178
+ ### Security (6 checks)
237
179
 
238
- ### Setup
180
+ | Check | Severity | What it catches |
181
+ |-------|----------|-----------------|
182
+ | Hardcoded Secrets | critical | API keys, tokens, JWTs in source code |
183
+ | Service Key Exposure | critical | Supabase service role keys in frontend |
184
+ | Deprecated Supabase Admin | high | Legacy `supabaseAdmin` patterns |
185
+ | Direct Supabase Client | critical | Direct `createClient` imports outside core wrappers |
186
+ | SystemDB Whitelist | critical | Unauthorized service role key usage in authenticated routes |
187
+ | Gitignore Validation | high | Missing .gitignore entries, tracked .env files |
239
188
 
240
- ```bash
241
- # Symlink the script
242
- ln -sf /path/to/tetra/packages/dev-toolkit/hooks/statusline.sh ~/.claude/hooks/statusline.sh
189
+ ### Stability (3 checks)
243
190
 
244
- # Add to ~/.claude/settings.json
245
- {
246
- "statusLine": {
247
- "type": "command",
248
- "command": "~/.claude/hooks/statusline.sh"
249
- }
250
- }
251
- ```
191
+ | Check | Severity | What it catches |
192
+ |-------|----------|-----------------|
193
+ | Husky Hooks | medium | Missing pre-commit/pre-push hooks |
194
+ | CI Pipeline | medium | Missing or incomplete CI config |
195
+ | NPM Audit | high | Known vulnerabilities in dependencies |
252
196
 
253
- ### What it shows
197
+ ### Code Quality (4 checks)
254
198
 
255
- ```
256
- repo: vibecodingacademy tasks: 3 open / 12 done started by: user cmux: workspace:308 ⠂ Claude Code
257
- opus ██████░░░░░░░░░ 44% context: 89K / 200K 99% cached this turn: +7K
258
- $3.76 5m20s (api: 3m5s) lines: +47 -12 turn #5 main* v2.1.73
259
- ```
199
+ | Check | Severity | What it catches |
200
+ |-------|----------|-----------------|
201
+ | API Response Format | medium | Non-standard response format |
202
+ | File Size | medium | Files exceeding line limits |
203
+ | Naming Conventions | medium | Inconsistent file/dir naming |
204
+ | Route Separation | high | Business logic in route files |
260
205
 
261
- **Line 1 project dashboard**
206
+ ### Supabase (3 checks, auto-detected)
262
207
 
263
- | Field | Source | Description |
264
- |-------|--------|-------------|
265
- | `repo:` | `workspace.project_dir` | Current project directory name |
266
- | `tasks:` | `.ralph/@fix_plan.md` | Open/done task count from Ralph fix plan |
267
- | `started by:` | Process tree + cmux | `user`, `monica`, `ralph`, `cursor`, `vscode` |
268
- | `cmux:` | `cmux identify` + `cmux list-workspaces` | Workspace ref and name (only in cmux terminal) |
208
+ | Check | Severity | What it catches |
209
+ |-------|----------|-----------------|
210
+ | RLS Policy Audit | critical | Tables without Row Level Security |
211
+ | RPC Param Mismatch | critical | TypeScript `.rpc()` calls with wrong parameter names vs SQL |
212
+ | RPC Generator Origin | high | RPC functions not generated by Tetra SQL Generator |
269
213
 
270
- **Line 2 — context window**
214
+ ### Hygiene (2 checks)
271
215
 
272
- | Field | Source | Description |
273
- |-------|--------|-------------|
274
- | Model | `model.id` | Short name: `opus`, `sonnet`, `haiku` |
275
- | Progress bar | `context_window.used_percentage` | 15-char bar, green <50%, yellow 50-80%, red >80% |
276
- | `context:` | input + cache tokens | Effective tokens in window vs max |
277
- | `cached` | `cache_read / context` | % of context served from prompt cache (saves cost) |
278
- | `this turn:` | Delta from previous turn | Token growth this turn (helps spot expensive hooks) |
216
+ | Check | Severity | What it catches |
217
+ |-------|----------|-----------------|
218
+ | File Organization | high | Stray .md, .sh, clutter in code dirs |
219
+ | Stella Compliance | medium | Missing Stella integration |
279
220
 
280
- **Line 3 — session stats**
221
+ ---
281
222
 
282
- | Field | Source | Description |
283
- |-------|--------|-------------|
284
- | Cost | `cost.total_cost_usd` | Session cost so far |
285
- | Duration | `cost.total_duration_ms` | Wall clock time |
286
- | API time | `cost.total_api_duration_ms` | Time spent waiting for API responses |
287
- | Lines | `cost.total_lines_added/removed` | Code changes this session |
288
- | Turn | Delta tracker | Number of assistant responses |
289
- | Branch | `git branch` | Current branch, `*` if dirty |
290
- | Version | `version` | Claude Code version |
223
+ ## Health Checks
224
+
225
+ Scored assessment (0-N points) used by the Ralph Manager dashboard:
226
+
227
+ | Check | Max | What it measures |
228
+ |-------|-----|------------------|
229
+ | File Organization | 6pt | Docs in /docs, scripts in /scripts, clean root & code dirs |
230
+ | Git | 4pt | Clean working tree, branch hygiene, commit frequency |
231
+ | Gitignore | 3pt | Critical entries present |
232
+ | CLAUDE.md | 3pt | Project instructions for AI assistants |
233
+ | Secrets | 3pt | No exposed secrets |
234
+ | Tests | 4pt | Test framework, coverage, test files |
235
+ | Naming Conventions | 5pt | File/dir naming consistency |
236
+ | Infrastructure YML | 3pt | Railway/Docker config |
237
+ | Doppler Compliance | 2pt | Secrets management via Doppler |
238
+ | MCP Servers | 2pt | MCP configuration |
239
+ | Stella Integration | 2pt | Stella package integration |
240
+ | Quality Toolkit | 2pt | Tetra dev-toolkit installed |
241
+ | Repo Visibility | 1pt | Private repo |
242
+ | RLS Audit | 3pt | Row Level Security policies |
243
+ | Plugins | 2pt | Claude Code plugin config |
244
+ | VinciFox Widget | 1pt | Widget installation |
291
245
 
292
- ### How "started by" detection works
246
+ ---
293
247
 
294
- 1. If running in cmux: checks workspace name — `monica:*` → `monica`
295
- 2. Fallback: walks the process tree looking for `ralph`, `cursor`, `code` (VS Code)
296
- 3. Default: `user` (manual terminal session)
248
+ ## Auto-fix: Cleanup Script
297
249
 
298
- ### Task colors
250
+ For hygiene issues, an auto-fix script is included:
299
251
 
300
- | Color | Meaning |
301
- |-------|---------|
302
- | Green | 0 open tasks (all done) |
303
- | Yellow | 1-10 open tasks |
304
- | Red | 10+ open tasks |
252
+ ```bash
253
+ # Dry run (shows what would change)
254
+ bash node_modules/@soulbatical/tetra-dev-toolkit/bin/cleanup-repos.sh
305
255
 
306
- Projects without `.ralph/@fix_plan.md` don't show the tasks field.
256
+ # Execute
257
+ bash node_modules/@soulbatical/tetra-dev-toolkit/bin/cleanup-repos.sh --execute
258
+ ```
307
259
 
308
260
  ---
309
261
 
310
- ## Changelog
262
+ ## Configuration
311
263
 
312
- ### 1.16.0
264
+ Override defaults in `.tetra-quality.json` or `"tetra-quality"` key in `package.json`:
313
265
 
314
- **New: Full Stability Suite (16 checks)**
315
- - Stability suite expanded from 3 → 16 checks via health check adapter
316
- - New checks: tests, eslint-security, typescript-strict, coverage-thresholds, knip, dependency-cruiser, dependency-automation, prettier, conventional-commits, bundle-size, sast, license-audit, security-layers
317
- - `tetra-audit stability` now catches missing test infrastructure, dead code, formatting, and security layer gaps
318
- - Health checks (score-based) automatically adapted to runner format (pass/fail)
319
- - RPC generator: SECURITY DEFINER → SECURITY INVOKER for all data RPCs
320
- - Migration lint: expanded whitelist for legitimate DEFINER functions
321
- - Mixed DB checker: fixed regex that matched `superadminDB` as `adminDB`
322
- - Route config checker: support `@tetra-audit-ignore` directive
266
+ ```json
267
+ {
268
+ "suites": {
269
+ "security": true,
270
+ "stability": true,
271
+ "codeQuality": true,
272
+ "supabase": "auto",
273
+ "hygiene": true
274
+ },
275
+ "supabase": {
276
+ "publicRpcFunctions": ["get_public_data"],
277
+ "publicTables": ["public_lookup"]
278
+ },
279
+ "stability": {
280
+ "allowedVulnerabilities": {
281
+ "critical": 0,
282
+ "high": 0,
283
+ "moderate": 10
284
+ }
285
+ }
286
+ }
287
+ ```
288
+
289
+ ---
290
+
291
+ ## CLI Tools
323
292
 
324
- ### 1.15.0
293
+ | Command | Description |
294
+ |---------|-------------|
295
+ | `tetra-audit` | Run quality/security/hygiene checks |
296
+ | `tetra-setup` | Install hooks, CI, and config |
297
+ | `tetra-check-rls` | RLS security gate against live Supabase |
298
+ | `tetra-init` | Initialize project config files |
299
+ | `tetra-dev-token` | Generate development tokens |
325
300
 
326
- **New: Migration Lint + DB Push Guard**
327
- - `tetra-migration-lint` — offline SQL migration linter (8 rules)
328
- - `tetra-db-push` — safe wrapper around `supabase db push` (lint first, push second)
329
- - Pre-commit hook now lints staged `.sql` files automatically
330
- - Rules: DEFINER on data RPCs, CREATE TABLE without RLS, DISABLE RLS, USING(true) writes, GRANT public/anon, DROP POLICY without replacement, missing WITH CHECK, hardcoded JWT
301
+ ---
331
302
 
332
- ### 1.14.0
303
+ ## New Project Checklist
333
304
 
334
- **New: Config-RLS Alignment + Route-Config Alignment + RPC Security Mode**
335
- - `config-rls-alignment` — verifies feature config accessLevel matches RLS policies on the table
336
- - `route-config-alignment` — verifies route middleware matches config accessLevel (admin routes need auth middleware)
337
- - `rpc-security-mode` — scans ALL RPCs for SECURITY DEFINER (must be INVOKER unless whitelisted)
305
+ After `npm install` in a new Tetra project:
338
306
 
339
- ### 1.13.0
307
+ ```bash
308
+ # 1. Install hooks (creates pre-commit + pre-push)
309
+ npx tetra-setup hooks
340
310
 
341
- **New: Mixed DB Usage Detection**
342
- - `mixed-db-usage` controllers must use exactly ONE DB helper type matching their naming convention
343
- - AdminController adminDB only, UserController → userDB only, etc.
344
- - Detects systemDB misuse when authenticated user context is available
311
+ # 2. Verify hooks are active
312
+ cat .husky/pre-commit # Should contain tetra-audit quick
313
+ cat .husky/pre-push # Should contain tetra-check-rls
345
314
 
346
- ### 1.12.0
315
+ # 3. Run full audit
316
+ npx tetra-audit
347
317
 
348
- **New: Tetra Core Compliance**
349
- - `tetra-core-compliance` if a project has @soulbatical/tetra-core, it MUST use configureAuth, authenticateToken, and db helpers
350
- - No more "skipped" checks — if tetra-core is a dependency, ALL security checks run
318
+ # 4. Run RLS gate manually once
319
+ doppler run -- npx tetra-check-rls
351
320
 
352
- ### 1.11.0
321
+ # 5. Add to Railway build command
322
+ # doppler run -- npx tetra-check-rls --errors-only && npm run build
323
+ ```
353
324
 
354
- **New: Frontend Supabase Queries check**
355
- - `frontend-supabase-queries` — blocks `.from()`, `.rpc()`, `.storage` in frontend code
356
- - Frontend MUST use API client, never query Supabase directly
325
+ If any step fails, fix it before writing code. No exceptions.
357
326
 
358
- ### 1.10.0
327
+ ---
359
328
 
360
- **Improved: RLS Policy Audit**
361
- - Tables with RLS ON but 0 policies now flagged as CRITICAL (was HIGH)
362
- - New config: `supabase.backendOnlyTables` for tables that intentionally have no policies
329
+ ## Changelog
363
330
 
364
331
  ### 1.9.0
365
332
 
366
- **New: Direct Supabase Client check + 3-Layer Security Model**
333
+ **New: Direct Supabase Client check (CRITICAL)**
334
+ - Added `direct-supabase-client` check in security suite
335
+ - Blocks any `createClient` import from `@supabase/supabase-js` outside core db wrappers
336
+ - Hard error at commit time — no fallback, no override
337
+ - Type-only imports (`import type { SupabaseClient }`) are allowed
338
+ - Allowed files whitelist: core wrappers, auth controller, MCP server internals, scripts
339
+
340
+ **New: 3-Layer Security Model documentation**
341
+ - Layer 1: Pre-commit (tetra-audit quick)
342
+ - Layer 2: Pre-push (tetra-check-rls + hygiene)
343
+ - Layer 3: Build-time (tetra-check-rls --errors-only in Railway)
344
+ - Complete Supabase Client Architecture docs with the 5 db helpers
345
+
346
+ **Improved: prepublishOnly hooks**
347
+ - tetra-core: `npm run build && npm run typecheck` before publish
348
+ - tetra-dev-toolkit: `npm test` before publish
349
+
350
+ ### 1.3.0 (2025-02-21)
367
351
 
368
- ### 1.3.0
352
+ **New: Hygiene suite**
353
+ - Added `tetra-audit hygiene` — detects stray docs, scripts, clutter in code dirs
354
+ - Added `cleanup-repos.sh` auto-fix script in `bin/`
355
+ - `tetra-setup hooks` now creates pre-push hook with hygiene gate
356
+ - Re-running `tetra-setup hooks` on existing repos adds hygiene check without overwriting
369
357
 
370
- **New: Hygiene suite + RPC Param Mismatch check**
358
+ **New: RPC Param Mismatch check**
359
+ - Added `rpc-param-mismatch` check in supabase suite
360
+ - Statically compares `.rpc()` calls in TypeScript with SQL function parameter names
361
+ - Catches PGRST202 errors before they hit production
371
362
 
372
363
  ### 1.2.0
373
364
 
374
365
  - Initial public version
366
+ - Security suite: hardcoded secrets, service key exposure, deprecated admin, systemdb whitelist, gitignore
367
+ - Stability suite: husky hooks, CI pipeline, npm audit
368
+ - Code quality suite: API response format
369
+ - Supabase suite: RLS policy audit
370
+ - Health checks: 16 checks, max 37pt
371
+ - CLI: `tetra-audit`, `tetra-setup`, `tetra-dev-token`