@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 +235 -238
- package/bin/tetra-setup.js +2 -172
- package/lib/checks/health/index.js +0 -1
- package/lib/checks/health/scanner.js +1 -3
- package/lib/checks/health/types.js +1 -1
- package/lib/checks/hygiene/stella-compliance.js +2 -2
- package/lib/checks/security/deprecated-supabase-admin.js +6 -15
- package/lib/checks/security/direct-supabase-client.js +4 -22
- package/lib/checks/security/frontend-supabase-queries.js +1 -1
- package/lib/checks/security/hardcoded-secrets.js +2 -5
- package/lib/checks/security/systemdb-whitelist.js +27 -116
- package/lib/config.js +1 -7
- package/lib/runner.js +7 -120
- package/package.json +2 -7
- package/bin/tetra-check-peers.js +0 -359
- package/bin/tetra-db-push.js +0 -91
- package/bin/tetra-migration-lint.js +0 -317
- package/bin/tetra-security-gate.js +0 -293
- package/bin/tetra-smoke.js +0 -532
- package/lib/checks/health/smoke-readiness.js +0 -150
- package/lib/checks/security/config-rls-alignment.js +0 -637
- package/lib/checks/security/mixed-db-usage.js +0 -204
- package/lib/checks/security/rls-live-audit.js +0 -255
- package/lib/checks/security/route-config-alignment.js +0 -342
- package/lib/checks/security/rpc-security-mode.js +0 -175
- package/lib/checks/security/tetra-core-compliance.js +0 -197
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
|
|
21
|
-
- `.husky/pre-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
|
-
|
|
35
|
+
---
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
## 3-Layer Security Model
|
|
38
38
|
|
|
39
|
-
|
|
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:
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
62
|
+
If any check fails, the commit is **blocked**. No `--force`, no workaround.
|
|
83
63
|
|
|
84
|
-
###
|
|
64
|
+
### Layer 2: Pre-push (RLS Security Gate)
|
|
85
65
|
|
|
86
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
84
|
+
### Layer 3: Build-time check
|
|
144
85
|
|
|
145
|
-
|
|
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
|
-
|
|
88
|
+
```bash
|
|
89
|
+
# Railway build command
|
|
90
|
+
doppler run -- npx tetra-check-rls --errors-only && npm run build
|
|
91
|
+
```
|
|
153
92
|
|
|
154
|
-
|
|
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
|
-
|
|
122
|
+
These files MAY import `createClient` directly because they ARE the wrappers:
|
|
187
123
|
|
|
188
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
135
|
+
## Usage
|
|
212
136
|
|
|
213
137
|
```bash
|
|
214
|
-
#
|
|
215
|
-
npx tetra-
|
|
216
|
-
|
|
217
|
-
#
|
|
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
|
-
|
|
221
|
-
doppler run -- npx tetra-check-rls
|
|
150
|
+
Exit codes: `0` = passed, `1` = failed, `2` = error. No middle ground.
|
|
222
151
|
|
|
223
|
-
|
|
224
|
-
npx tetra-migration-lint
|
|
152
|
+
## RLS Security Gate (standalone)
|
|
225
153
|
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
176
|
+
## Check Suites
|
|
235
177
|
|
|
236
|
-
|
|
178
|
+
### Security (6 checks)
|
|
237
179
|
|
|
238
|
-
|
|
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
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
###
|
|
197
|
+
### Code Quality (4 checks)
|
|
254
198
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
-
|
|
206
|
+
### Supabase (3 checks, auto-detected)
|
|
262
207
|
|
|
263
|
-
|
|
|
264
|
-
|
|
265
|
-
|
|
|
266
|
-
|
|
|
267
|
-
|
|
|
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
|
-
|
|
214
|
+
### Hygiene (2 checks)
|
|
271
215
|
|
|
272
|
-
|
|
|
273
|
-
|
|
274
|
-
|
|
|
275
|
-
|
|
|
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
|
-
|
|
221
|
+
---
|
|
281
222
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
|
287
|
-
|
|
288
|
-
|
|
|
289
|
-
|
|
|
290
|
-
|
|
|
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
|
-
|
|
246
|
+
---
|
|
293
247
|
|
|
294
|
-
|
|
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
|
-
|
|
250
|
+
For hygiene issues, an auto-fix script is included:
|
|
299
251
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
|
|
256
|
+
# Execute
|
|
257
|
+
bash node_modules/@soulbatical/tetra-dev-toolkit/bin/cleanup-repos.sh --execute
|
|
258
|
+
```
|
|
307
259
|
|
|
308
260
|
---
|
|
309
261
|
|
|
310
|
-
##
|
|
262
|
+
## Configuration
|
|
311
263
|
|
|
312
|
-
|
|
264
|
+
Override defaults in `.tetra-quality.json` or `"tetra-quality"` key in `package.json`:
|
|
313
265
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
303
|
+
## New Project Checklist
|
|
333
304
|
|
|
334
|
-
|
|
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
|
-
|
|
307
|
+
```bash
|
|
308
|
+
# 1. Install hooks (creates pre-commit + pre-push)
|
|
309
|
+
npx tetra-setup hooks
|
|
340
310
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
-
|
|
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
|
-
|
|
315
|
+
# 3. Run full audit
|
|
316
|
+
npx tetra-audit
|
|
347
317
|
|
|
348
|
-
|
|
349
|
-
|
|
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
|
-
|
|
321
|
+
# 5. Add to Railway build command
|
|
322
|
+
# doppler run -- npx tetra-check-rls --errors-only && npm run build
|
|
323
|
+
```
|
|
353
324
|
|
|
354
|
-
|
|
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
|
-
|
|
327
|
+
---
|
|
359
328
|
|
|
360
|
-
|
|
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
|
|
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
|
-
|
|
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:
|
|
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`
|