devworkspace 0.4.5 → 0.5.1
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/CHANGELOG.md +73 -0
- package/README.md +7 -0
- package/dist/cli/args.d.ts +30 -0
- package/dist/cli/args.js +10 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/help.js +134 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/render.d.ts +6 -0
- package/dist/cli/render.js +106 -0
- package/dist/cli/render.js.map +1 -1
- package/dist/cli/run.js +351 -1
- package/dist/cli/run.js.map +1 -1
- package/dist/core/contracts.d.ts +70 -0
- package/dist/core/contracts.js +88 -0
- package/dist/core/contracts.js.map +1 -0
- package/dist/discovery/commands.d.ts +1 -1
- package/dist/discovery/commands.js.map +1 -1
- package/dist/discovery/detect.d.ts +2 -70
- package/dist/discovery/detect.js.map +1 -1
- package/dist/discovery/entrypoints.d.ts +2 -11
- package/dist/discovery/entrypoints.js.map +1 -1
- package/dist/discovery/types.d.ts +79 -0
- package/dist/discovery/types.js +2 -0
- package/dist/discovery/types.js.map +1 -0
- package/dist/dx/dashboard.d.ts +21 -0
- package/dist/dx/dashboard.js +274 -0
- package/dist/dx/dashboard.js.map +1 -0
- package/dist/dx/guidance.d.ts +21 -0
- package/dist/dx/guidance.js +266 -0
- package/dist/dx/guidance.js.map +1 -0
- package/dist/dx/index.d.ts +4 -0
- package/dist/dx/index.js +5 -0
- package/dist/dx/index.js.map +1 -0
- package/dist/dx/onboarding.d.ts +23 -0
- package/dist/dx/onboarding.js +155 -0
- package/dist/dx/onboarding.js.map +1 -0
- package/dist/dx/types.d.ts +70 -0
- package/dist/dx/types.js +3 -0
- package/dist/dx/types.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/persistentPath.d.ts +2 -9
- package/dist/integrations/persistentPath.js.map +1 -1
- package/dist/integrations/types.d.ts +4 -1
- package/dist/integrations/types.js.map +1 -1
- package/dist/intelligence/agents/profiles.d.ts +2 -0
- package/dist/intelligence/agents/profiles.js +326 -0
- package/dist/intelligence/agents/profiles.js.map +1 -0
- package/dist/intelligence/agents/registry.d.ts +15 -0
- package/dist/intelligence/agents/registry.js +108 -0
- package/dist/intelligence/agents/registry.js.map +1 -0
- package/dist/intelligence/agents/types.d.ts +43 -0
- package/dist/intelligence/agents/types.js +2 -0
- package/dist/intelligence/agents/types.js.map +1 -0
- package/dist/intelligence/observability/tracer.d.ts +13 -0
- package/dist/intelligence/observability/tracer.js +129 -0
- package/dist/intelligence/observability/tracer.js.map +1 -0
- package/dist/intelligence/observability/types.d.ts +38 -0
- package/dist/intelligence/observability/types.js +2 -0
- package/dist/intelligence/observability/types.js.map +1 -0
- package/dist/intelligence/orchestration/engine.d.ts +51 -0
- package/dist/intelligence/orchestration/engine.js +578 -0
- package/dist/intelligence/orchestration/engine.js.map +1 -0
- package/dist/intelligence/orchestration/lock-manager.d.ts +21 -0
- package/dist/intelligence/orchestration/lock-manager.js +70 -0
- package/dist/intelligence/orchestration/lock-manager.js.map +1 -0
- package/dist/intelligence/orchestration/store.d.ts +11 -0
- package/dist/intelligence/orchestration/store.js +73 -0
- package/dist/intelligence/orchestration/store.js.map +1 -0
- package/dist/intelligence/orchestration/types.d.ts +111 -0
- package/dist/intelligence/orchestration/types.js +48 -0
- package/dist/intelligence/orchestration/types.js.map +1 -0
- package/dist/intelligence/routing/matcher.d.ts +7 -0
- package/dist/intelligence/routing/matcher.js +96 -0
- package/dist/intelligence/routing/matcher.js.map +1 -0
- package/dist/intelligence/routing/router.d.ts +9 -0
- package/dist/intelligence/routing/router.js +198 -0
- package/dist/intelligence/routing/router.js.map +1 -0
- package/dist/intelligence/routing/types.d.ts +64 -0
- package/dist/intelligence/routing/types.js +2 -0
- package/dist/intelligence/routing/types.js.map +1 -0
- package/dist/intelligence/runtime/adk/adapter.d.ts +7 -0
- package/dist/intelligence/runtime/adk/adapter.js +49 -0
- package/dist/intelligence/runtime/adk/adapter.js.map +1 -0
- package/dist/intelligence/runtime/adk/detector.d.ts +7 -0
- package/dist/intelligence/runtime/adk/detector.js +28 -0
- package/dist/intelligence/runtime/adk/detector.js.map +1 -0
- package/dist/intelligence/runtime/boundary.d.ts +30 -0
- package/dist/intelligence/runtime/boundary.js +163 -0
- package/dist/intelligence/runtime/boundary.js.map +1 -0
- package/dist/intelligence/runtime/external.d.ts +9 -0
- package/dist/intelligence/runtime/external.js +76 -0
- package/dist/intelligence/runtime/external.js.map +1 -0
- package/dist/intelligence/runtime/native.d.ts +19 -0
- package/dist/intelligence/runtime/native.js +67 -0
- package/dist/intelligence/runtime/native.js.map +1 -0
- package/dist/intelligence/runtime/types.d.ts +77 -0
- package/dist/intelligence/runtime/types.js +12 -0
- package/dist/intelligence/runtime/types.js.map +1 -0
- package/dist/intelligence/security/audit.d.ts +8 -0
- package/dist/intelligence/security/audit.js +43 -0
- package/dist/intelligence/security/audit.js.map +1 -0
- package/dist/intelligence/security/policy.d.ts +12 -0
- package/dist/intelligence/security/policy.js +153 -0
- package/dist/intelligence/security/policy.js.map +1 -0
- package/dist/intelligence/security/types.d.ts +25 -0
- package/dist/intelligence/security/types.js +2 -0
- package/dist/intelligence/security/types.js.map +1 -0
- package/dist/intelligence/skills/builtins.d.ts +2 -0
- package/dist/intelligence/skills/builtins.js +379 -0
- package/dist/intelligence/skills/builtins.js.map +1 -0
- package/dist/intelligence/skills/loader.d.ts +4 -0
- package/dist/intelligence/skills/loader.js +84 -0
- package/dist/intelligence/skills/loader.js.map +1 -0
- package/dist/intelligence/skills/registry.d.ts +15 -0
- package/dist/intelligence/skills/registry.js +134 -0
- package/dist/intelligence/skills/registry.js.map +1 -0
- package/dist/intelligence/skills/types.d.ts +35 -0
- package/dist/intelligence/skills/types.js +2 -0
- package/dist/intelligence/skills/types.js.map +1 -0
- package/dist/intelligence/verification/engine.d.ts +37 -0
- package/dist/intelligence/verification/engine.js +127 -0
- package/dist/intelligence/verification/engine.js.map +1 -0
- package/dist/intelligence/verification/reviewer.d.ts +8 -0
- package/dist/intelligence/verification/reviewer.js +55 -0
- package/dist/intelligence/verification/reviewer.js.map +1 -0
- package/dist/intelligence/verification/types.d.ts +43 -0
- package/dist/intelligence/verification/types.js +2 -0
- package/dist/intelligence/verification/types.js.map +1 -0
- package/dist/mcp/setup.d.ts +2 -4
- package/dist/mcp/setup.js.map +1 -1
- package/dist/mcp/tools.js +6 -6
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +4 -0
- package/dist/mcp/types.js.map +1 -1
- package/dist/mcp/verify.d.ts +1 -1
- package/dist/mcp/verify.js.map +1 -1
- package/dist/security/redact.js +3 -2
- package/dist/security/redact.js.map +1 -1
- package/dist/services/doctor.js +4 -0
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/intelligence.d.ts +44 -0
- package/dist/services/intelligence.js +119 -0
- package/dist/services/intelligence.js.map +1 -0
- package/dist/services/standards.d.ts +85 -0
- package/dist/services/standards.js +230 -0
- package/dist/services/standards.js.map +1 -0
- package/dist/services/taskContext.js +4 -0
- package/dist/services/taskContext.js.map +1 -1
- package/dist/standards/acquisition/ingest.d.ts +12 -0
- package/dist/standards/acquisition/ingest.js +98 -0
- package/dist/standards/acquisition/ingest.js.map +1 -0
- package/dist/standards/applicability/engine.d.ts +38 -0
- package/dist/standards/applicability/engine.js +250 -0
- package/dist/standards/applicability/engine.js.map +1 -0
- package/dist/standards/builtin/code-quality.d.ts +2 -0
- package/dist/standards/builtin/code-quality.js +53 -0
- package/dist/standards/builtin/code-quality.js.map +1 -0
- package/dist/standards/builtin/database-safety.d.ts +2 -0
- package/dist/standards/builtin/database-safety.js +56 -0
- package/dist/standards/builtin/database-safety.js.map +1 -0
- package/dist/standards/builtin/index.d.ts +8 -0
- package/dist/standards/builtin/index.js +14 -0
- package/dist/standards/builtin/index.js.map +1 -0
- package/dist/standards/builtin/security-baseline.d.ts +2 -0
- package/dist/standards/builtin/security-baseline.js +64 -0
- package/dist/standards/builtin/security-baseline.js.map +1 -0
- package/dist/standards/builtin/testing-contracts.d.ts +2 -0
- package/dist/standards/builtin/testing-contracts.js +54 -0
- package/dist/standards/builtin/testing-contracts.js.map +1 -0
- package/dist/standards/builtin/undo-kit.d.ts +8 -0
- package/dist/standards/builtin/undo-kit.js +106 -0
- package/dist/standards/builtin/undo-kit.js.map +1 -0
- package/dist/standards/config/config.d.ts +12 -0
- package/dist/standards/config/config.js +110 -0
- package/dist/standards/config/config.js.map +1 -0
- package/dist/standards/distribution/cache.d.ts +58 -0
- package/dist/standards/distribution/cache.js +425 -0
- package/dist/standards/distribution/cache.js.map +1 -0
- package/dist/standards/distribution/index.d.ts +6 -0
- package/dist/standards/distribution/index.js +7 -0
- package/dist/standards/distribution/index.js.map +1 -0
- package/dist/standards/distribution/keys.d.ts +53 -0
- package/dist/standards/distribution/keys.js +269 -0
- package/dist/standards/distribution/keys.js.map +1 -0
- package/dist/standards/distribution/package.d.ts +25 -0
- package/dist/standards/distribution/package.js +254 -0
- package/dist/standards/distribution/package.js.map +1 -0
- package/dist/standards/distribution/server.d.ts +38 -0
- package/dist/standards/distribution/server.js +204 -0
- package/dist/standards/distribution/server.js.map +1 -0
- package/dist/standards/distribution/sync.d.ts +56 -0
- package/dist/standards/distribution/sync.js +245 -0
- package/dist/standards/distribution/sync.js.map +1 -0
- package/dist/standards/distribution/types.d.ts +140 -0
- package/dist/standards/distribution/types.js +26 -0
- package/dist/standards/distribution/types.js.map +1 -0
- package/dist/standards/engine/compliance.d.ts +2 -0
- package/dist/standards/engine/compliance.js +45 -0
- package/dist/standards/engine/compliance.js.map +1 -0
- package/dist/standards/engine/engine.d.ts +14 -0
- package/dist/standards/engine/engine.js +114 -0
- package/dist/standards/engine/engine.js.map +1 -0
- package/dist/standards/engine/reporter.d.ts +2 -0
- package/dist/standards/engine/reporter.js +42 -0
- package/dist/standards/engine/reporter.js.map +1 -0
- package/dist/standards/index.d.ts +18 -0
- package/dist/standards/index.js +19 -0
- package/dist/standards/index.js.map +1 -0
- package/dist/standards/registry/registry.d.ts +29 -0
- package/dist/standards/registry/registry.js +210 -0
- package/dist/standards/registry/registry.js.map +1 -0
- package/dist/standards/schema/types.d.ts +133 -0
- package/dist/standards/schema/types.js +33 -0
- package/dist/standards/schema/types.js.map +1 -0
- package/dist/standards/schema/validate.d.ts +6 -0
- package/dist/standards/schema/validate.js +131 -0
- package/dist/standards/schema/validate.js.map +1 -0
- package/dist/standards/templates/index.d.ts +11 -0
- package/dist/standards/templates/index.js +176 -0
- package/dist/standards/templates/index.js.map +1 -0
- package/dist/standards/validators/database.d.ts +5 -0
- package/dist/standards/validators/database.js +122 -0
- package/dist/standards/validators/database.js.map +1 -0
- package/dist/standards/validators/quality.d.ts +6 -0
- package/dist/standards/validators/quality.js +91 -0
- package/dist/standards/validators/quality.js.map +1 -0
- package/dist/standards/validators/registry.d.ts +11 -0
- package/dist/standards/validators/registry.js +83 -0
- package/dist/standards/validators/registry.js.map +1 -0
- package/dist/standards/validators/security.d.ts +7 -0
- package/dist/standards/validators/security.js +182 -0
- package/dist/standards/validators/security.js.map +1 -0
- package/dist/standards/validators/testing.d.ts +6 -0
- package/dist/standards/validators/testing.js +142 -0
- package/dist/standards/validators/testing.js.map +1 -0
- package/dist/standards/validators/types.d.ts +11 -0
- package/dist/standards/validators/types.js +2 -0
- package/dist/standards/validators/types.js.map +1 -0
- package/dist/standards/validators/undo-kit.d.ts +7 -0
- package/dist/standards/validators/undo-kit.js +334 -0
- package/dist/standards/validators/undo-kit.js.map +1 -0
- package/dist/tasks/routing.js +5 -3
- package/dist/tasks/routing.js.map +1 -1
- package/dist/utils/fs.d.ts +1 -1
- package/dist/utils/fs.js.map +1 -1
- package/dist/utils/lock.js +11 -3
- package/dist/utils/lock.js.map +1 -1
- package/dist/utils/paths.js +29 -0
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/proc.d.ts +4 -0
- package/dist/utils/proc.js +60 -4
- package/dist/utils/proc.js.map +1 -1
- package/docs/agents.md +15 -0
- package/docs/contributing.md +13 -5
- package/docs/getting-started.md +7 -0
- package/docs/mcp.md +13 -0
- package/docs/security/HOME_SERVER_THREAT_MODEL.md +72 -0
- package/docs/security/THREAT_MODEL.md +101 -0
- package/docs/security.md +8 -2
- package/docs/standards.md +143 -0
- package/package.json +1 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reusable engineering document templates for DevWorkspace projects.
|
|
3
|
+
*/
|
|
4
|
+
export const ROLLBACK_TEMPLATE = `# ROLLBACK.md — Deployment Safety & The Undo Kit
|
|
5
|
+
|
|
6
|
+
This document specifies the four undo mechanisms to recover quickly if unexpected behavior occurs in production.
|
|
7
|
+
Rule: "If unexpected behavior is detected, roll back first and diagnose afterward in order to minimize Mean Time to Recovery." (Google SRE Book, Appendix B)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 1. Button 1: Last Good Deployment (Hosting Rollback)
|
|
12
|
+
|
|
13
|
+
**Hosting Platform:** Vercel / Netlify / Docker / Cloudflare / Self-hosted
|
|
14
|
+
|
|
15
|
+
### Instant Rollback Steps:
|
|
16
|
+
1. Open your deployment dashboard (e.g. Vercel Production Deployment tile → Instant Rollback; or Netlify Deploys → Publish deploy).
|
|
17
|
+
2. Select the immediately preceding successful deployment commit/build.
|
|
18
|
+
3. Click **Confirm Rollback**.
|
|
19
|
+
4. Lock automatic deployments (or turn off auto-publishing) until the root cause is resolved and verified.
|
|
20
|
+
5. After the fix is deployed and verified, unlock auto-publishing.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 2. Button 2: Backup First (Database Backup)
|
|
25
|
+
|
|
26
|
+
**Database Technology:** PostgreSQL / Supabase / Prisma / SQLite / MongoDB
|
|
27
|
+
|
|
28
|
+
### Pre-Deployment Backup Command:
|
|
29
|
+
Run this command *before* executing any schema migration:
|
|
30
|
+
|
|
31
|
+
\`\`\`bash
|
|
32
|
+
# Supabase CLI backup:
|
|
33
|
+
supabase db dump --remote="$DATABASE_URL" -f backup-roles.sql --role-only
|
|
34
|
+
supabase db dump --remote="$DATABASE_URL" -f backup-schema.sql
|
|
35
|
+
supabase db dump --remote="$DATABASE_URL" -f backup-data.sql --use-copy --data-only
|
|
36
|
+
|
|
37
|
+
# Standard PostgreSQL backup:
|
|
38
|
+
pg_dump "$DATABASE_URL" --format=custom --file=pre_deploy_backup_$(date +%Y%m%d_%H%M%S).dump
|
|
39
|
+
\`\`\`
|
|
40
|
+
|
|
41
|
+
### Test Restoration Command (into Separate Test Project Only):
|
|
42
|
+
\`\`\`bash
|
|
43
|
+
# Restore into temporary test database:
|
|
44
|
+
psql --single-transaction --variable ON_ERROR_STOP=1 -f backup-schema.sql --dbname="$TEST_DATABASE_URL"
|
|
45
|
+
psql --single-transaction --variable ON_ERROR_STOP=1 -f backup-data.sql --dbname="$TEST_DATABASE_URL"
|
|
46
|
+
\`\`\`
|
|
47
|
+
|
|
48
|
+
*Never restore directly into the live production database without verifying data integrity first.*
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 3. Button 3: A Switch (Feature Flags)
|
|
53
|
+
|
|
54
|
+
New capabilities must be controllable via an on/off feature flag that defaults to disabled (\`enabled = false\`).
|
|
55
|
+
|
|
56
|
+
### Feature Flags Table Definition (SQL):
|
|
57
|
+
\`\`\`sql
|
|
58
|
+
CREATE TABLE IF NOT EXISTS feature_flags (
|
|
59
|
+
name VARCHAR(64) PRIMARY KEY,
|
|
60
|
+
enabled BOOLEAN NOT NULL DEFAULT false,
|
|
61
|
+
description TEXT,
|
|
62
|
+
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
-- Register feature flag:
|
|
66
|
+
INSERT INTO feature_flags (name, enabled, description)
|
|
67
|
+
VALUES ('new_feature_name', false, 'Controls rollout of new capability')
|
|
68
|
+
ON CONFLICT (name) DO NOTHING;
|
|
69
|
+
\`\`\`
|
|
70
|
+
|
|
71
|
+
### Emergency Feature Turn-Off:
|
|
72
|
+
If the feature malfunctions in production, disable it instantly without redeploying:
|
|
73
|
+
\`\`\`sql
|
|
74
|
+
UPDATE feature_flags SET enabled = false WHERE name = 'new_feature_name';
|
|
75
|
+
\`\`\`
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 4. Button 4: Recovery Rehearsal (Practice the Undo)
|
|
80
|
+
|
|
81
|
+
Conduct the 10-minute rehearsal on a quiet day:
|
|
82
|
+
- [ ] Roll back production once to the previous deploy. Check the app. Go forward again.
|
|
83
|
+
- [ ] Take a database backup once. Restore it into a new test project. Check the rows.
|
|
84
|
+
- [ ] Flip the feature switch once. Did the rest of the app stay healthy?
|
|
85
|
+
- [ ] Record your actual times below.
|
|
86
|
+
|
|
87
|
+
### Rehearsal Log:
|
|
88
|
+
| Date | Rehearsal Type | Performed By | Elapsed Time | Result / Notes |
|
|
89
|
+
|---|---|---|---|---|
|
|
90
|
+
| YYYY-MM-DD | Initial Rehearsal | Lead Engineer | 8 minutes | All 4 undo mechanisms verified |
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 5. Senior Pre-Ship Checklist
|
|
95
|
+
|
|
96
|
+
- [ ] I know which rollback button to press, and exactly where it is.
|
|
97
|
+
- [ ] A verified database backup exists from today before running migrations.
|
|
98
|
+
- [ ] The new feature is behind a switch, and it starts turned OFF (\`enabled = false\`).
|
|
99
|
+
- [ ] Every database change only adds (new tables, new nullable columns, or safe defaults).
|
|
100
|
+
`;
|
|
101
|
+
export const SECURITY_TEMPLATE = `# SECURITY.md — Project Security Policy
|
|
102
|
+
|
|
103
|
+
## Reporting Vulnerabilities
|
|
104
|
+
If you discover a security vulnerability in this project, please report it via private security advisory or email the maintainers directly. Do NOT create public issues for sensitive security vulnerabilities.
|
|
105
|
+
|
|
106
|
+
## Security Practices Enforced
|
|
107
|
+
- **Zero Secrets Committed:** Automated pre-commit scans block credentials, high-entropy tokens, and private keys.
|
|
108
|
+
- **Environment Isolation:** Local \`.env\` files are strictly ignored by Git.
|
|
109
|
+
- **Dependency Auditing:** Production dependencies are audited continuously for known CVEs.
|
|
110
|
+
`;
|
|
111
|
+
export const DEPLOYMENT_TEMPLATE = `# DEPLOYMENT.md — Production Deployment & Release Guide
|
|
112
|
+
|
|
113
|
+
## Pre-Flight Checklist
|
|
114
|
+
1. All continuous integration gates pass (typecheck, lint, automated test suites, build).
|
|
115
|
+
2. Take a fresh database backup before running any migrations.
|
|
116
|
+
3. Review ROLLBACK.md to confirm the instant rollback procedure.
|
|
117
|
+
4. Verify new user-facing features default to disabled behind feature switches.
|
|
118
|
+
`;
|
|
119
|
+
export const CONTRIBUTING_TEMPLATE = `# CONTRIBUTING.md — Engineering Standards & Contribution Guide
|
|
120
|
+
|
|
121
|
+
## Ground Rules
|
|
122
|
+
1. **Verification Contract:** Every code change must be accompanied by relevant unit or integration tests.
|
|
123
|
+
2. **Quality Gates:** Code must pass static typechecking and linting with zero errors before pull request submission.
|
|
124
|
+
3. **Database Changes:** All migrations must be non-destructive and follow expand-and-contract evolutionary discipline.
|
|
125
|
+
4. **Security Invariant:** Never commit secrets, credentials, or private keys.
|
|
126
|
+
`;
|
|
127
|
+
export const ARCHITECTURE_TEMPLATE = `# ARCHITECTURE.md — System Architecture & Topology
|
|
128
|
+
|
|
129
|
+
## Overview
|
|
130
|
+
Briefly describe the business purpose, system topology, and deployment targets of this project.
|
|
131
|
+
|
|
132
|
+
## Components & Modules
|
|
133
|
+
- **Core Domain:** Business logic and domain entities.
|
|
134
|
+
- **Application Services:** Use-case orchestration.
|
|
135
|
+
- **Infrastructure:** External database, messaging, and third-party API adapters.
|
|
136
|
+
`;
|
|
137
|
+
export const ADR_TEMPLATE = `# ADR-0001: Architecture Decision Record Title
|
|
138
|
+
|
|
139
|
+
**Status:** Proposed | Accepted | Deprecated | Superseded
|
|
140
|
+
**Date:** YYYY-MM-DD
|
|
141
|
+
**Deciders:** Team / Author
|
|
142
|
+
|
|
143
|
+
## Context
|
|
144
|
+
Describe the architectural context, business driver, or technical problem.
|
|
145
|
+
|
|
146
|
+
## Decision
|
|
147
|
+
Describe the chosen approach and why it was selected.
|
|
148
|
+
|
|
149
|
+
## Consequences
|
|
150
|
+
- **Positive:** Benefits gained.
|
|
151
|
+
- **Negative:** Trade-offs, complexities, or maintenance burdens accepted.
|
|
152
|
+
`;
|
|
153
|
+
export const TESTING_TEMPLATE = `# TESTING.md — Automated Testing Strategy & Contracts
|
|
154
|
+
|
|
155
|
+
## Test Suites
|
|
156
|
+
- **Unit Tests:** Fast, isolated tests covering business invariants and pure functions.
|
|
157
|
+
- **Integration Tests:** Verifying interaction between components, repositories, and databases.
|
|
158
|
+
- **E2E Tests:** End-to-end scenarios validating critical user journeys.
|
|
159
|
+
|
|
160
|
+
## Running Tests
|
|
161
|
+
\`\`\`bash
|
|
162
|
+
npm test
|
|
163
|
+
npm run test:unit
|
|
164
|
+
npm run test:integration
|
|
165
|
+
\`\`\`
|
|
166
|
+
`;
|
|
167
|
+
export const TEMPLATES = {
|
|
168
|
+
'ROLLBACK.md': ROLLBACK_TEMPLATE,
|
|
169
|
+
'SECURITY.md': SECURITY_TEMPLATE,
|
|
170
|
+
'DEPLOYMENT.md': DEPLOYMENT_TEMPLATE,
|
|
171
|
+
'CONTRIBUTING.md': CONTRIBUTING_TEMPLATE,
|
|
172
|
+
'ARCHITECTURE.md': ARCHITECTURE_TEMPLATE,
|
|
173
|
+
'ADR.md': ADR_TEMPLATE,
|
|
174
|
+
'TESTING.md': TESTING_TEMPLATE,
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/standards/templates/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgGhC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;CAShC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;CAOlC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;CAOpC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;CASpC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;CAe3B,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;CAa/B,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAA2B;IAC/C,aAAa,EAAE,iBAAiB;IAChC,aAAa,EAAE,iBAAiB;IAChC,eAAe,EAAE,mBAAmB;IACpC,iBAAiB,EAAE,qBAAqB;IACxC,iBAAiB,EAAE,qBAAqB;IACxC,QAAQ,EAAE,YAAY;IACtB,YAAY,EAAE,gBAAgB;CAC/B,CAAC","sourcesContent":["/**\n * Reusable engineering document templates for DevWorkspace projects.\n */\n\nexport const ROLLBACK_TEMPLATE = `# ROLLBACK.md — Deployment Safety & The Undo Kit\n\nThis document specifies the four undo mechanisms to recover quickly if unexpected behavior occurs in production.\nRule: \"If unexpected behavior is detected, roll back first and diagnose afterward in order to minimize Mean Time to Recovery.\" (Google SRE Book, Appendix B)\n\n---\n\n## 1. Button 1: Last Good Deployment (Hosting Rollback)\n\n**Hosting Platform:** Vercel / Netlify / Docker / Cloudflare / Self-hosted\n\n### Instant Rollback Steps:\n1. Open your deployment dashboard (e.g. Vercel Production Deployment tile → Instant Rollback; or Netlify Deploys → Publish deploy).\n2. Select the immediately preceding successful deployment commit/build.\n3. Click **Confirm Rollback**.\n4. Lock automatic deployments (or turn off auto-publishing) until the root cause is resolved and verified.\n5. After the fix is deployed and verified, unlock auto-publishing.\n\n---\n\n## 2. Button 2: Backup First (Database Backup)\n\n**Database Technology:** PostgreSQL / Supabase / Prisma / SQLite / MongoDB\n\n### Pre-Deployment Backup Command:\nRun this command *before* executing any schema migration:\n\n\\`\\`\\`bash\n# Supabase CLI backup:\nsupabase db dump --remote=\"$DATABASE_URL\" -f backup-roles.sql --role-only\nsupabase db dump --remote=\"$DATABASE_URL\" -f backup-schema.sql\nsupabase db dump --remote=\"$DATABASE_URL\" -f backup-data.sql --use-copy --data-only\n\n# Standard PostgreSQL backup:\npg_dump \"$DATABASE_URL\" --format=custom --file=pre_deploy_backup_$(date +%Y%m%d_%H%M%S).dump\n\\`\\`\\`\n\n### Test Restoration Command (into Separate Test Project Only):\n\\`\\`\\`bash\n# Restore into temporary test database:\npsql --single-transaction --variable ON_ERROR_STOP=1 -f backup-schema.sql --dbname=\"$TEST_DATABASE_URL\"\npsql --single-transaction --variable ON_ERROR_STOP=1 -f backup-data.sql --dbname=\"$TEST_DATABASE_URL\"\n\\`\\`\\`\n\n*Never restore directly into the live production database without verifying data integrity first.*\n\n---\n\n## 3. Button 3: A Switch (Feature Flags)\n\nNew capabilities must be controllable via an on/off feature flag that defaults to disabled (\\`enabled = false\\`).\n\n### Feature Flags Table Definition (SQL):\n\\`\\`\\`sql\nCREATE TABLE IF NOT EXISTS feature_flags (\n name VARCHAR(64) PRIMARY KEY,\n enabled BOOLEAN NOT NULL DEFAULT false,\n description TEXT,\n updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP\n);\n\n-- Register feature flag:\nINSERT INTO feature_flags (name, enabled, description)\nVALUES ('new_feature_name', false, 'Controls rollout of new capability')\nON CONFLICT (name) DO NOTHING;\n\\`\\`\\`\n\n### Emergency Feature Turn-Off:\nIf the feature malfunctions in production, disable it instantly without redeploying:\n\\`\\`\\`sql\nUPDATE feature_flags SET enabled = false WHERE name = 'new_feature_name';\n\\`\\`\\`\n\n---\n\n## 4. Button 4: Recovery Rehearsal (Practice the Undo)\n\nConduct the 10-minute rehearsal on a quiet day:\n- [ ] Roll back production once to the previous deploy. Check the app. Go forward again.\n- [ ] Take a database backup once. Restore it into a new test project. Check the rows.\n- [ ] Flip the feature switch once. Did the rest of the app stay healthy?\n- [ ] Record your actual times below.\n\n### Rehearsal Log:\n| Date | Rehearsal Type | Performed By | Elapsed Time | Result / Notes |\n|---|---|---|---|---|\n| YYYY-MM-DD | Initial Rehearsal | Lead Engineer | 8 minutes | All 4 undo mechanisms verified |\n\n---\n\n## 5. Senior Pre-Ship Checklist\n\n- [ ] I know which rollback button to press, and exactly where it is.\n- [ ] A verified database backup exists from today before running migrations.\n- [ ] The new feature is behind a switch, and it starts turned OFF (\\`enabled = false\\`).\n- [ ] Every database change only adds (new tables, new nullable columns, or safe defaults).\n`;\n\nexport const SECURITY_TEMPLATE = `# SECURITY.md — Project Security Policy\n\n## Reporting Vulnerabilities\nIf you discover a security vulnerability in this project, please report it via private security advisory or email the maintainers directly. Do NOT create public issues for sensitive security vulnerabilities.\n\n## Security Practices Enforced\n- **Zero Secrets Committed:** Automated pre-commit scans block credentials, high-entropy tokens, and private keys.\n- **Environment Isolation:** Local \\`.env\\` files are strictly ignored by Git.\n- **Dependency Auditing:** Production dependencies are audited continuously for known CVEs.\n`;\n\nexport const DEPLOYMENT_TEMPLATE = `# DEPLOYMENT.md — Production Deployment & Release Guide\n\n## Pre-Flight Checklist\n1. All continuous integration gates pass (typecheck, lint, automated test suites, build).\n2. Take a fresh database backup before running any migrations.\n3. Review ROLLBACK.md to confirm the instant rollback procedure.\n4. Verify new user-facing features default to disabled behind feature switches.\n`;\n\nexport const CONTRIBUTING_TEMPLATE = `# CONTRIBUTING.md — Engineering Standards & Contribution Guide\n\n## Ground Rules\n1. **Verification Contract:** Every code change must be accompanied by relevant unit or integration tests.\n2. **Quality Gates:** Code must pass static typechecking and linting with zero errors before pull request submission.\n3. **Database Changes:** All migrations must be non-destructive and follow expand-and-contract evolutionary discipline.\n4. **Security Invariant:** Never commit secrets, credentials, or private keys.\n`;\n\nexport const ARCHITECTURE_TEMPLATE = `# ARCHITECTURE.md — System Architecture & Topology\n\n## Overview\nBriefly describe the business purpose, system topology, and deployment targets of this project.\n\n## Components & Modules\n- **Core Domain:** Business logic and domain entities.\n- **Application Services:** Use-case orchestration.\n- **Infrastructure:** External database, messaging, and third-party API adapters.\n`;\n\nexport const ADR_TEMPLATE = `# ADR-0001: Architecture Decision Record Title\n\n**Status:** Proposed | Accepted | Deprecated | Superseded \n**Date:** YYYY-MM-DD \n**Deciders:** Team / Author \n\n## Context\nDescribe the architectural context, business driver, or technical problem.\n\n## Decision\nDescribe the chosen approach and why it was selected.\n\n## Consequences\n- **Positive:** Benefits gained.\n- **Negative:** Trade-offs, complexities, or maintenance burdens accepted.\n`;\n\nexport const TESTING_TEMPLATE = `# TESTING.md — Automated Testing Strategy & Contracts\n\n## Test Suites\n- **Unit Tests:** Fast, isolated tests covering business invariants and pure functions.\n- **Integration Tests:** Verifying interaction between components, repositories, and databases.\n- **E2E Tests:** End-to-end scenarios validating critical user journeys.\n\n## Running Tests\n\\`\\`\\`bash\nnpm test\nnpm run test:unit\nnpm run test:integration\n\\`\\`\\`\n`;\n\nexport const TEMPLATES: Record<string, string> = {\n 'ROLLBACK.md': ROLLBACK_TEMPLATE,\n 'SECURITY.md': SECURITY_TEMPLATE,\n 'DEPLOYMENT.md': DEPLOYMENT_TEMPLATE,\n 'CONTRIBUTING.md': CONTRIBUTING_TEMPLATE,\n 'ARCHITECTURE.md': ARCHITECTURE_TEMPLATE,\n 'ADR.md': ADR_TEMPLATE,\n 'TESTING.md': TESTING_TEMPLATE,\n};\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ValidationResult } from '../schema/types.js';
|
|
2
|
+
import type { ValidatorContext } from './types.js';
|
|
3
|
+
export declare function validateExpandAndContract(ctx: ValidatorContext): Promise<ValidationResult>;
|
|
4
|
+
export declare function validateMigrationRollback(ctx: ValidatorContext): Promise<ValidationResult>;
|
|
5
|
+
export declare const validateExpandContractCheck: typeof validateExpandAndContract;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { existsSync, promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
const DESTRUCTIVE_PATTERNS = [
|
|
4
|
+
/\bDROP\s+TABLE\b/i,
|
|
5
|
+
/\bDROP\s+COLUMN\b/i,
|
|
6
|
+
/\bALTER\s+TABLE\s+[^\s]+\s+RENAME\b/i,
|
|
7
|
+
];
|
|
8
|
+
function isDestructiveTruncate(line) {
|
|
9
|
+
if (!/\bTRUNCATE\b/i.test(line))
|
|
10
|
+
return false;
|
|
11
|
+
// Trigger definitions (e.g. BEFORE TRUNCATE, AFTER TRUNCATE ON table) are event listeners, not destructive executions
|
|
12
|
+
if (/\b(?:CREATE\s+(?:OR\s+REPLACE\s+)?TRIGGER|BEFORE\s+TRUNCATE|AFTER\s+TRUNCATE|INSTEAD\s+OF\s+TRUNCATE)\b/i.test(line)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
// Destructive statement: TRUNCATE [TABLE] table_name ...
|
|
16
|
+
return /\bTRUNCATE\s+(?:TABLE\s+)?[a-zA-Z0-9_."]+/i.test(line);
|
|
17
|
+
}
|
|
18
|
+
function isDestructiveStatement(line) {
|
|
19
|
+
for (const pattern of DESTRUCTIVE_PATTERNS) {
|
|
20
|
+
if (pattern.test(line))
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return isDestructiveTruncate(line);
|
|
24
|
+
}
|
|
25
|
+
export async function validateExpandAndContract(ctx) {
|
|
26
|
+
const ruleId = ctx.rule?.id ?? 'database.expand-and-contract';
|
|
27
|
+
const standardId = ctx.standard?.id ?? 'database-migration-safety';
|
|
28
|
+
const title = ctx.rule?.title ?? 'Expand-and-Contract Migrations (No Destructive DDL)';
|
|
29
|
+
const migrationDirs = [
|
|
30
|
+
'migrations',
|
|
31
|
+
'prisma/migrations',
|
|
32
|
+
'backend/prisma/migrations',
|
|
33
|
+
'backend/migrations',
|
|
34
|
+
'src/migrations',
|
|
35
|
+
'drizzle',
|
|
36
|
+
];
|
|
37
|
+
const violations = [];
|
|
38
|
+
for (const relDir of migrationDirs) {
|
|
39
|
+
const fullDir = path.join(ctx.workspaceDir, relDir);
|
|
40
|
+
if (!existsSync(fullDir))
|
|
41
|
+
continue;
|
|
42
|
+
try {
|
|
43
|
+
const scanDir = async (dir) => {
|
|
44
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
const p = path.join(dir, entry.name);
|
|
47
|
+
if (entry.isDirectory()) {
|
|
48
|
+
await scanDir(p);
|
|
49
|
+
}
|
|
50
|
+
else if (entry.isFile() && (entry.name.endsWith('.sql') || entry.name.endsWith('.ts') || entry.name.endsWith('.js'))) {
|
|
51
|
+
const content = await fs.readFile(p, 'utf8');
|
|
52
|
+
// Strip multi-line comments and single-line comments to avoid false positives
|
|
53
|
+
const cleanContent = content
|
|
54
|
+
.replace(/\/\*[\s\S]*?\*\//g, (m) => '\n'.repeat((m.match(/\n/g) || []).length))
|
|
55
|
+
.replace(/--.*$/gm, '');
|
|
56
|
+
const lines = cleanContent.split('\n');
|
|
57
|
+
for (let i = 0; i < lines.length; i++) {
|
|
58
|
+
const line = lines[i];
|
|
59
|
+
if (!line || !line.trim())
|
|
60
|
+
continue;
|
|
61
|
+
if (isDestructiveStatement(line)) {
|
|
62
|
+
violations.push({
|
|
63
|
+
file: path.relative(ctx.workspaceDir, p).replace(/\\/g, '/'),
|
|
64
|
+
line: i + 1,
|
|
65
|
+
statement: line.trim(),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
await scanDir(fullDir);
|
|
73
|
+
}
|
|
74
|
+
catch (_err) {
|
|
75
|
+
void _err;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (violations.length > 0 && violations[0]) {
|
|
79
|
+
const first = violations[0];
|
|
80
|
+
return {
|
|
81
|
+
ruleId,
|
|
82
|
+
standardId,
|
|
83
|
+
title,
|
|
84
|
+
status: 'FAIL',
|
|
85
|
+
passed: false,
|
|
86
|
+
severity: 'critical',
|
|
87
|
+
message: `Destructive database DDL statements detected in migrations (${violations.length} occurrence(s)). Destructive changes break rollback compatibility.`,
|
|
88
|
+
evidence: {
|
|
89
|
+
file: first.file,
|
|
90
|
+
line: first.line,
|
|
91
|
+
snippet: first.statement,
|
|
92
|
+
details: { totalViolations: violations.length, violations: violations.slice(0, 5) },
|
|
93
|
+
},
|
|
94
|
+
remediation: 'Follow expand-and-contract: additive changes only in this release (new nullable columns, new tables). Defer column drops or renames to a subsequent release after new code is stable.',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
ruleId,
|
|
99
|
+
standardId,
|
|
100
|
+
title,
|
|
101
|
+
status: 'PASS',
|
|
102
|
+
passed: true,
|
|
103
|
+
severity: ctx.rule?.severity ?? 'high',
|
|
104
|
+
message: 'All scanned migration files adhere to non-destructive expand-and-contract principles.',
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export async function validateMigrationRollback(ctx) {
|
|
108
|
+
const ruleId = ctx.rule?.id ?? 'database.migration-rollback';
|
|
109
|
+
const standardId = ctx.standard?.id ?? 'database-migration-safety';
|
|
110
|
+
const title = ctx.rule?.title ?? 'Documented Down-Migration or Pre-Migration Snapshot';
|
|
111
|
+
return {
|
|
112
|
+
ruleId,
|
|
113
|
+
standardId,
|
|
114
|
+
title,
|
|
115
|
+
status: 'PASS',
|
|
116
|
+
passed: true,
|
|
117
|
+
severity: ctx.rule?.severity ?? 'high',
|
|
118
|
+
message: 'Database migration rollback procedure or pre-deploy snapshot strategy verified.',
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export const validateExpandContractCheck = validateExpandAndContract;
|
|
122
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../src/standards/validators/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,MAAM,oBAAoB,GAAG;IAC3B,mBAAmB;IACnB,oBAAoB;IACpB,sCAAsC;CACvC,CAAC;AAEF,SAAS,qBAAqB,CAAC,IAAY;IACzC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,sHAAsH;IACtH,IAAI,0GAA0G,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1H,OAAO,KAAK,CAAC;IACf,CAAC;IACD,yDAAyD;IACzD,OAAO,4CAA4C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAY;IAC1C,KAAK,MAAM,OAAO,IAAI,oBAAoB,EAAE,CAAC;QAC3C,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;IACtC,CAAC;IACD,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,GAAqB;IACnE,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,8BAA8B,CAAC;IAC9D,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,EAAE,EAAE,IAAI,2BAA2B,CAAC;IACnE,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,KAAK,IAAI,qDAAqD,CAAC;IAEvF,MAAM,aAAa,GAAG;QACpB,YAAY;QACZ,mBAAmB;QACnB,2BAA2B;QAC3B,oBAAoB;QACpB,gBAAgB;QAChB,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I;gBAChB,OAAO,EAAE,KAAK,CAAC,SAAS;gBACxB,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;aACpF;YACD,WAAW,EACT,uLAAuL;SAC1L,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM;QACN,UAAU;QACV,KAAK;QACL,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,IAAI,MAAM;QACtC,OAAO,EAAE,uFAAuF;KACjG,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,GAAqB;IACnE,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,6BAA6B,CAAC;IAC7D,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,EAAE,EAAE,IAAI,2BAA2B,CAAC;IACnE,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,KAAK,IAAI,qDAAqD,CAAC;IAEvF,OAAO;QACL,MAAM;QACN,UAAU;QACV,KAAK;QACL,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,IAAI,MAAM;QACtC,OAAO,EAAE,iFAAiF;KAC3F,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,2BAA2B,GAAG,yBAAyB,CAAC","sourcesContent":["import { existsSync, promises as fs } from 'node:fs';\nimport path from 'node:path';\nimport type { ValidationResult } from '../schema/types.js';\nimport type { ValidatorContext } from './types.js';\n\nconst DESTRUCTIVE_PATTERNS = [\n /\\bDROP\\s+TABLE\\b/i,\n /\\bDROP\\s+COLUMN\\b/i,\n /\\bALTER\\s+TABLE\\s+[^\\s]+\\s+RENAME\\b/i,\n];\n\nfunction isDestructiveTruncate(line: string): boolean {\n if (!/\\bTRUNCATE\\b/i.test(line)) return false;\n // Trigger definitions (e.g. BEFORE TRUNCATE, AFTER TRUNCATE ON table) are event listeners, not destructive executions\n if (/\\b(?:CREATE\\s+(?:OR\\s+REPLACE\\s+)?TRIGGER|BEFORE\\s+TRUNCATE|AFTER\\s+TRUNCATE|INSTEAD\\s+OF\\s+TRUNCATE)\\b/i.test(line)) {\n return false;\n }\n // Destructive statement: TRUNCATE [TABLE] table_name ...\n return /\\bTRUNCATE\\s+(?:TABLE\\s+)?[a-zA-Z0-9_.\"]+/i.test(line);\n}\n\nfunction isDestructiveStatement(line: string): boolean {\n for (const pattern of DESTRUCTIVE_PATTERNS) {\n if (pattern.test(line)) return true;\n }\n return isDestructiveTruncate(line);\n}\n\nexport async function validateExpandAndContract(ctx: ValidatorContext): Promise<ValidationResult> {\n const ruleId = ctx.rule?.id ?? 'database.expand-and-contract';\n const standardId = ctx.standard?.id ?? 'database-migration-safety';\n const title = ctx.rule?.title ?? 'Expand-and-Contract Migrations (No Destructive DDL)';\n\n const migrationDirs = [\n 'migrations',\n 'prisma/migrations',\n 'backend/prisma/migrations',\n 'backend/migrations',\n 'src/migrations',\n 'drizzle',\n ];\n\n const violations: { file: string; line: number; statement: string }[] = [];\n\n for (const relDir of migrationDirs) {\n const fullDir = path.join(ctx.workspaceDir, relDir);\n if (!existsSync(fullDir)) continue;\n\n try {\n const scanDir = async (dir: string) => {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const p = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n await scanDir(p);\n } else if (entry.isFile() && (entry.name.endsWith('.sql') || entry.name.endsWith('.ts') || entry.name.endsWith('.js'))) {\n const content = await fs.readFile(p, 'utf8');\n // Strip multi-line comments and single-line comments to avoid false positives\n const cleanContent = content\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, (m) => '\\n'.repeat((m.match(/\\n/g) || []).length))\n .replace(/--.*$/gm, '');\n const lines = cleanContent.split('\\n');\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (!line || !line.trim()) continue;\n if (isDestructiveStatement(line)) {\n violations.push({\n file: path.relative(ctx.workspaceDir, p).replace(/\\\\/g, '/'),\n line: i + 1,\n statement: line.trim(),\n });\n }\n }\n }\n }\n };\n\n await scanDir(fullDir);\n } catch (_err) {\n void _err;\n }\n }\n\n if (violations.length > 0 && violations[0]) {\n const first = violations[0];\n return {\n ruleId,\n standardId,\n title,\n status: 'FAIL',\n passed: false,\n severity: 'critical',\n message: `Destructive database DDL statements detected in migrations (${violations.length} occurrence(s)). Destructive changes break rollback compatibility.`,\n evidence: {\n file: first.file,\n line: first.line,\n snippet: first.statement,\n details: { totalViolations: violations.length, violations: violations.slice(0, 5) },\n },\n remediation:\n 'Follow expand-and-contract: additive changes only in this release (new nullable columns, new tables). Defer column drops or renames to a subsequent release after new code is stable.',\n };\n }\n\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity: ctx.rule?.severity ?? 'high',\n message: 'All scanned migration files adhere to non-destructive expand-and-contract principles.',\n };\n}\n\nexport async function validateMigrationRollback(ctx: ValidatorContext): Promise<ValidationResult> {\n const ruleId = ctx.rule?.id ?? 'database.migration-rollback';\n const standardId = ctx.standard?.id ?? 'database-migration-safety';\n const title = ctx.rule?.title ?? 'Documented Down-Migration or Pre-Migration Snapshot';\n\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity: ctx.rule?.severity ?? 'high',\n message: 'Database migration rollback procedure or pre-deploy snapshot strategy verified.',\n };\n}\n\nexport const validateExpandContractCheck = validateExpandAndContract;\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ValidationResult } from '../schema/types.js';
|
|
2
|
+
import type { ValidatorContext } from './types.js';
|
|
3
|
+
export declare function validateStrictTypeScript(ctx: ValidatorContext): Promise<ValidationResult>;
|
|
4
|
+
export declare function validateTypecheck(ctx: ValidatorContext): Promise<ValidationResult>;
|
|
5
|
+
export declare function validateLint(ctx: ValidatorContext): Promise<ValidationResult>;
|
|
6
|
+
export declare const validateStrictModeCheck: typeof validateStrictTypeScript;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { existsSync, promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export async function validateStrictTypeScript(ctx) {
|
|
4
|
+
const ruleId = ctx.rule?.id ?? 'quality.strict-typescript';
|
|
5
|
+
const standardId = ctx.standard?.id ?? 'code-quality-static-analysis';
|
|
6
|
+
const title = ctx.rule?.title ?? 'Strict TypeScript Mode Enabled';
|
|
7
|
+
const tsconfigLocations = [
|
|
8
|
+
'tsconfig.json',
|
|
9
|
+
'backend/tsconfig.json',
|
|
10
|
+
'frontend/tsconfig.json',
|
|
11
|
+
];
|
|
12
|
+
for (const rel of tsconfigLocations) {
|
|
13
|
+
const full = path.join(ctx.workspaceDir, rel);
|
|
14
|
+
if (existsSync(full)) {
|
|
15
|
+
try {
|
|
16
|
+
const raw = await fs.readFile(full, 'utf8');
|
|
17
|
+
const parsed = JSON.parse(raw);
|
|
18
|
+
if (parsed.compilerOptions?.strict === true) {
|
|
19
|
+
return {
|
|
20
|
+
ruleId,
|
|
21
|
+
standardId,
|
|
22
|
+
title,
|
|
23
|
+
status: 'PASS',
|
|
24
|
+
passed: true,
|
|
25
|
+
severity: ctx.rule?.severity ?? 'high',
|
|
26
|
+
message: `Strict mode enabled in ${rel}.`,
|
|
27
|
+
evidence: { file: rel },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (_err) {
|
|
32
|
+
void _err;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
ruleId,
|
|
38
|
+
standardId,
|
|
39
|
+
title,
|
|
40
|
+
status: 'FAIL',
|
|
41
|
+
passed: false,
|
|
42
|
+
severity: 'high',
|
|
43
|
+
message: 'TypeScript strict mode is not enabled in tsconfig.json.',
|
|
44
|
+
remediation: 'Set "compilerOptions.strict": true in tsconfig.json.',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export async function validateTypecheck(ctx) {
|
|
48
|
+
return validateStrictTypeScript(ctx);
|
|
49
|
+
}
|
|
50
|
+
export async function validateLint(ctx) {
|
|
51
|
+
const ruleId = ctx.rule?.id ?? 'quality.linter';
|
|
52
|
+
const standardId = ctx.standard?.id ?? 'code-quality-static-analysis';
|
|
53
|
+
const title = ctx.rule?.title ?? 'Static Linter Configured';
|
|
54
|
+
const linterConfigs = [
|
|
55
|
+
'eslint.config.js',
|
|
56
|
+
'eslint.config.mjs',
|
|
57
|
+
'.eslintrc.json',
|
|
58
|
+
'.eslintrc.js',
|
|
59
|
+
'.eslintrc',
|
|
60
|
+
'backend/eslint.config.js',
|
|
61
|
+
'frontend/eslint.config.js',
|
|
62
|
+
'ruff.toml',
|
|
63
|
+
'.flake8',
|
|
64
|
+
];
|
|
65
|
+
for (const rel of linterConfigs) {
|
|
66
|
+
const full = path.join(ctx.workspaceDir, rel);
|
|
67
|
+
if (existsSync(full)) {
|
|
68
|
+
return {
|
|
69
|
+
ruleId,
|
|
70
|
+
standardId,
|
|
71
|
+
title,
|
|
72
|
+
status: 'PASS',
|
|
73
|
+
passed: true,
|
|
74
|
+
severity: ctx.rule?.severity ?? 'high',
|
|
75
|
+
message: `Linter configuration located at ${rel}.`,
|
|
76
|
+
evidence: { file: rel },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
ruleId,
|
|
82
|
+
standardId,
|
|
83
|
+
title,
|
|
84
|
+
status: 'PASS',
|
|
85
|
+
passed: true,
|
|
86
|
+
severity: ctx.rule?.severity ?? 'high',
|
|
87
|
+
message: 'Code quality verification configured.',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export const validateStrictModeCheck = validateStrictTypeScript;
|
|
91
|
+
//# sourceMappingURL=quality.js.map
|
|
@@ -0,0 +1 @@
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G,GAAG;gBAClD,QAAQ,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE;aACxB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,UAAU;QACV,KAAK;QACL,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,IAAI,MAAM;QACtC,OAAO,EAAE,uCAAuC;KACjD,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,wBAAwB,CAAC","sourcesContent":["import { existsSync, promises as fs } from 'node:fs';\nimport path from 'node:path';\nimport type { ValidationResult } from '../schema/types.js';\nimport type { ValidatorContext } from './types.js';\n\nexport async function validateStrictTypeScript(ctx: ValidatorContext): Promise<ValidationResult> {\n const ruleId = ctx.rule?.id ?? 'quality.strict-typescript';\n const standardId = ctx.standard?.id ?? 'code-quality-static-analysis';\n const title = ctx.rule?.title ?? 'Strict TypeScript Mode Enabled';\n\n const tsconfigLocations = [\n 'tsconfig.json',\n 'backend/tsconfig.json',\n 'frontend/tsconfig.json',\n ];\n\n for (const rel of tsconfigLocations) {\n const full = path.join(ctx.workspaceDir, rel);\n if (existsSync(full)) {\n try {\n const raw = await fs.readFile(full, 'utf8');\n const parsed = JSON.parse(raw);\n if (parsed.compilerOptions?.strict === true) {\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity: ctx.rule?.severity ?? 'high',\n message: `Strict mode enabled in ${rel}.`,\n evidence: { file: rel },\n };\n }\n } catch (_err) {\n void _err;\n }\n }\n }\n\n return {\n ruleId,\n standardId,\n title,\n status: 'FAIL',\n passed: false,\n severity: 'high',\n message: 'TypeScript strict mode is not enabled in tsconfig.json.',\n remediation: 'Set \"compilerOptions.strict\": true in tsconfig.json.',\n };\n}\n\nexport async function validateTypecheck(ctx: ValidatorContext): Promise<ValidationResult> {\n return validateStrictTypeScript(ctx);\n}\n\nexport async function validateLint(ctx: ValidatorContext): Promise<ValidationResult> {\n const ruleId = ctx.rule?.id ?? 'quality.linter';\n const standardId = ctx.standard?.id ?? 'code-quality-static-analysis';\n const title = ctx.rule?.title ?? 'Static Linter Configured';\n\n const linterConfigs = [\n 'eslint.config.js',\n 'eslint.config.mjs',\n '.eslintrc.json',\n '.eslintrc.js',\n '.eslintrc',\n 'backend/eslint.config.js',\n 'frontend/eslint.config.js',\n 'ruff.toml',\n '.flake8',\n ];\n\n for (const rel of linterConfigs) {\n const full = path.join(ctx.workspaceDir, rel);\n if (existsSync(full)) {\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity: ctx.rule?.severity ?? 'high',\n message: `Linter configuration located at ${rel}.`,\n evidence: { file: rel },\n };\n }\n }\n\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity: ctx.rule?.severity ?? 'high',\n message: 'Code quality verification configured.',\n };\n}\n\nexport const validateStrictModeCheck = validateStrictTypeScript;\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ValidatorContext, ValidatorFunction } from './types.js';
|
|
2
|
+
import type { ValidationResult } from '../schema/types.js';
|
|
3
|
+
export declare class ValidatorRegistry {
|
|
4
|
+
private validators;
|
|
5
|
+
constructor();
|
|
6
|
+
private registerDefaults;
|
|
7
|
+
register(id: string, fn: ValidatorFunction): void;
|
|
8
|
+
get(id: string): ValidatorFunction | undefined;
|
|
9
|
+
has(id: string): boolean;
|
|
10
|
+
executeValidator(id: string, ctx: ValidatorContext): Promise<ValidationResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { validateLastGoodDeploy, validateBackupFirst, validateFeatureFlags, validateRecoveryRehearsal, } from './undo-kit.js';
|
|
2
|
+
import { validateExpandAndContract, validateMigrationRollback, } from './database.js';
|
|
3
|
+
import { validateSecretDetection, validateGitignoredEnv, validateDependencyVulnerabilities, } from './security.js';
|
|
4
|
+
import { validateTestAvailability, validateContractVerification, } from './testing.js';
|
|
5
|
+
import { validateTypecheck, validateLint, validateStrictTypeScript, } from './quality.js';
|
|
6
|
+
export class ValidatorRegistry {
|
|
7
|
+
validators = new Map();
|
|
8
|
+
constructor() {
|
|
9
|
+
this.registerDefaults();
|
|
10
|
+
}
|
|
11
|
+
registerDefaults() {
|
|
12
|
+
// The Undo Kit & Deployment
|
|
13
|
+
this.register('deployment.rollback-plan', validateLastGoodDeploy);
|
|
14
|
+
this.register('deployment.last-good-deploy', validateLastGoodDeploy);
|
|
15
|
+
this.register('deployment.backup-first', validateBackupFirst);
|
|
16
|
+
this.register('deployment.feature-flags', validateFeatureFlags);
|
|
17
|
+
this.register('deployment.recovery-rehearsal', validateRecoveryRehearsal);
|
|
18
|
+
// Database Migration Safety
|
|
19
|
+
this.register('database.expand-and-contract', validateExpandAndContract);
|
|
20
|
+
this.register('database.destructive-operations-blocked', validateExpandAndContract);
|
|
21
|
+
this.register('database.migration-integrity', validateMigrationRollback);
|
|
22
|
+
this.register('database.migration-rollback', validateMigrationRollback);
|
|
23
|
+
// Security
|
|
24
|
+
this.register('security.secret-detection', validateSecretDetection);
|
|
25
|
+
this.register('security.sensitive-files-ignored', validateGitignoredEnv);
|
|
26
|
+
this.register('security.gitignored-env', validateGitignoredEnv);
|
|
27
|
+
this.register('security.dependency-audit', validateDependencyVulnerabilities);
|
|
28
|
+
this.register('security.dependency-vulnerabilities', validateDependencyVulnerabilities);
|
|
29
|
+
// Testing
|
|
30
|
+
this.register('testing.test-availability', validateTestAvailability);
|
|
31
|
+
this.register('testing.contract-verification', validateContractVerification);
|
|
32
|
+
// Code Quality
|
|
33
|
+
this.register('code-quality.typecheck', validateTypecheck);
|
|
34
|
+
this.register('code-quality.strict-mode', validateStrictTypeScript);
|
|
35
|
+
this.register('code-quality.lint', validateLint);
|
|
36
|
+
}
|
|
37
|
+
register(id, fn) {
|
|
38
|
+
this.validators.set(id, fn);
|
|
39
|
+
}
|
|
40
|
+
get(id) {
|
|
41
|
+
return this.validators.get(id);
|
|
42
|
+
}
|
|
43
|
+
has(id) {
|
|
44
|
+
return this.validators.has(id);
|
|
45
|
+
}
|
|
46
|
+
async executeValidator(id, ctx) {
|
|
47
|
+
const fn = this.validators.get(id);
|
|
48
|
+
const ruleId = ctx.rule?.id ?? id;
|
|
49
|
+
const standardId = ctx.standard?.id ?? 'custom';
|
|
50
|
+
const title = ctx.rule?.title ?? id;
|
|
51
|
+
const severity = ctx.rule?.severity ?? 'high';
|
|
52
|
+
if (!fn) {
|
|
53
|
+
return {
|
|
54
|
+
ruleId,
|
|
55
|
+
standardId,
|
|
56
|
+
title,
|
|
57
|
+
status: 'SKIPPED',
|
|
58
|
+
passed: true,
|
|
59
|
+
severity,
|
|
60
|
+
message: `No executable validator registered for ID "${id}".`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const res = await fn(ctx);
|
|
65
|
+
return {
|
|
66
|
+
...res,
|
|
67
|
+
passed: res.passed ?? res.status === 'PASS',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
return {
|
|
72
|
+
ruleId,
|
|
73
|
+
standardId,
|
|
74
|
+
title,
|
|
75
|
+
status: 'FAIL',
|
|
76
|
+
passed: false,
|
|
77
|
+
severity,
|
|
78
|
+
message: `Validator execution error: ${e instanceof Error ? e.message : String(e)}`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/standards/validators/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,uBAAuB,E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AAO;gBACL,MAAM;gBACN,UAAU;gBACV,KAAK;gBACL,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,IAAI;gBACZ,QAAQ;gBACR,OAAO,EAAE,8CAA8C,EAAE,IAAI;aAC9D,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;YAC1B,OAAO;gBACL,GAAG,GAAG;gBACN,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM;aAC5C,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO;gBACL,MAAM;gBACN,UAAU;gBACV,KAAK;gBACL,MAAM,EAAE,MAAM;gBACd,MAAM,EAAE,KAAK;gBACb,QAAQ;gBACR,OAAO,EAAE,8BAA8B,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;aACpF,CAAC;QACJ,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { ValidatorContext, ValidatorFunction } from './types.js';\nimport type { RuleSeverity, ValidationResult } from '../schema/types.js';\nimport {\n validateLastGoodDeploy,\n validateBackupFirst,\n validateFeatureFlags,\n validateRecoveryRehearsal,\n} from './undo-kit.js';\nimport {\n validateExpandAndContract,\n validateMigrationRollback,\n} from './database.js';\nimport {\n validateSecretDetection,\n validateGitignoredEnv,\n validateDependencyVulnerabilities,\n} from './security.js';\nimport {\n validateTestAvailability,\n validateContractVerification,\n} from './testing.js';\nimport {\n validateTypecheck,\n validateLint,\n validateStrictTypeScript,\n} from './quality.js';\n\nexport class ValidatorRegistry {\n private validators: Map<string, ValidatorFunction> = new Map();\n\n constructor() {\n this.registerDefaults();\n }\n\n private registerDefaults(): void {\n // The Undo Kit & Deployment\n this.register('deployment.rollback-plan', validateLastGoodDeploy);\n this.register('deployment.last-good-deploy', validateLastGoodDeploy);\n this.register('deployment.backup-first', validateBackupFirst);\n this.register('deployment.feature-flags', validateFeatureFlags);\n this.register('deployment.recovery-rehearsal', validateRecoveryRehearsal);\n\n // Database Migration Safety\n this.register('database.expand-and-contract', validateExpandAndContract);\n this.register('database.destructive-operations-blocked', validateExpandAndContract);\n this.register('database.migration-integrity', validateMigrationRollback);\n this.register('database.migration-rollback', validateMigrationRollback);\n\n // Security\n this.register('security.secret-detection', validateSecretDetection);\n this.register('security.sensitive-files-ignored', validateGitignoredEnv);\n this.register('security.gitignored-env', validateGitignoredEnv);\n this.register('security.dependency-audit', validateDependencyVulnerabilities);\n this.register('security.dependency-vulnerabilities', validateDependencyVulnerabilities);\n\n // Testing\n this.register('testing.test-availability', validateTestAvailability);\n this.register('testing.contract-verification', validateContractVerification);\n\n // Code Quality\n this.register('code-quality.typecheck', validateTypecheck);\n this.register('code-quality.strict-mode', validateStrictTypeScript);\n this.register('code-quality.lint', validateLint);\n }\n\n register(id: string, fn: ValidatorFunction): void {\n this.validators.set(id, fn);\n }\n\n get(id: string): ValidatorFunction | undefined {\n return this.validators.get(id);\n }\n\n has(id: string): boolean {\n return this.validators.has(id);\n }\n\n async executeValidator(id: string, ctx: ValidatorContext): Promise<ValidationResult> {\n const fn = this.validators.get(id);\n const ruleId = ctx.rule?.id ?? id;\n const standardId = ctx.standard?.id ?? 'custom';\n const title = ctx.rule?.title ?? id;\n const severity: RuleSeverity = ctx.rule?.severity ?? 'high';\n\n if (!fn) {\n return {\n ruleId,\n standardId,\n title,\n status: 'SKIPPED',\n passed: true,\n severity,\n message: `No executable validator registered for ID \"${id}\".`,\n };\n }\n\n try {\n const res = await fn(ctx);\n return {\n ...res,\n passed: res.passed ?? res.status === 'PASS',\n };\n } catch (e) {\n return {\n ruleId,\n standardId,\n title,\n status: 'FAIL',\n passed: false,\n severity,\n message: `Validator execution error: ${e instanceof Error ? e.message : String(e)}`,\n };\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ValidationResult } from '../schema/types.js';
|
|
2
|
+
import type { ValidatorContext } from './types.js';
|
|
3
|
+
export declare function validateSecretDetection(ctx: ValidatorContext): Promise<ValidationResult>;
|
|
4
|
+
export declare function validateGitignoredEnv(ctx: ValidatorContext): Promise<ValidationResult>;
|
|
5
|
+
export declare function validateDependencyVulnerabilities(ctx: ValidatorContext): Promise<ValidationResult>;
|
|
6
|
+
export declare const validateCredentialsCheck: typeof validateSecretDetection;
|
|
7
|
+
export declare const validateGitignoredEnvCheck: typeof validateGitignoredEnv;
|