@nerviq/cli 1.8.8 → 1.9.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.
@@ -1,158 +1,158 @@
1
- /**
2
- * OpenCode Freshness Operationalization
3
- *
4
- * Release gates, recurring probes, propagation checklists,
5
- * and staleness blocking for OpenCode surfaces.
6
- */
7
-
8
- const { version } = require('../../package.json');
9
-
10
- const P0_SOURCES = [
11
- {
12
- key: 'opencode-docs',
13
- label: 'OpenCode Official Docs',
14
- url: 'https://opencode.ai/docs',
15
- stalenessThresholdDays: 30,
16
- verifiedAt: null,
17
- },
18
- {
19
- key: 'opencode-config-reference',
20
- label: 'OpenCode Config Reference',
21
- url: 'https://opencode.ai/config',
22
- stalenessThresholdDays: 30,
23
- verifiedAt: null,
24
- },
25
- {
26
- key: 'opencode-github-releases',
27
- label: 'OpenCode GitHub Releases',
28
- url: 'https://github.com/sst/opencode/releases',
29
- stalenessThresholdDays: 14,
30
- verifiedAt: null,
31
- },
32
- {
33
- key: 'opencode-plugin-api',
34
- label: 'OpenCode Plugin API',
35
- url: 'https://opencode.ai/plugins',
36
- stalenessThresholdDays: 30,
37
- verifiedAt: null,
38
- },
39
- {
40
- key: 'opencode-permissions-docs',
41
- label: 'OpenCode Permissions Documentation',
42
- url: 'https://opencode.ai/permissions',
43
- stalenessThresholdDays: 30,
44
- verifiedAt: null,
45
- },
46
- ];
47
-
48
- const PROPAGATION_CHECKLIST = [
49
- {
50
- trigger: 'OpenCode release with config changes',
51
- targets: [
52
- 'src/opencode/techniques.js — update DEPRECATED_CONFIG_KEYS if keys renamed/removed',
53
- 'src/opencode/config-parser.js — update JSONC validation',
54
- 'src/opencode/governance.js — update caveats if behavior changes',
55
- 'test/opencode-check-matrix.js — update check expectations',
56
- ],
57
- },
58
- {
59
- trigger: 'New OpenCode plugin event type added',
60
- targets: [
61
- 'src/opencode/techniques.js — add to VALID_PLUGIN_EVENTS',
62
- 'src/opencode/governance.js — add to OPENCODE_PLUGIN_GOVERNANCE',
63
- 'src/opencode/setup.js — update plugins starter template',
64
- ],
65
- },
66
- {
67
- trigger: 'New OpenCode permission tool added',
68
- targets: [
69
- 'src/opencode/techniques.js — add to PERMISSIONED_TOOLS',
70
- 'src/opencode/governance.js — update permission profiles',
71
- 'src/opencode/setup.js — update default permission config',
72
- ],
73
- },
74
- {
75
- trigger: 'OpenCode MCP schema change',
76
- targets: [
77
- 'src/opencode/mcp-packs.js — update JSONC projections',
78
- 'src/opencode/techniques.js — update MCP checks',
79
- ],
80
- },
81
- {
82
- trigger: 'Known security bug fixed or new bug reported',
83
- targets: [
84
- 'src/opencode/techniques.js — update security checks (E02, E03, D05)',
85
- 'src/opencode/governance.js — update platformCaveats',
86
- 'src/opencode/freshness.js — verify against latest release',
87
- ],
88
- },
89
- ];
90
-
91
- function checkReleaseGate(sourceVerifications = {}) {
92
- const now = new Date();
93
- const results = P0_SOURCES.map(source => {
94
- const verifiedAt = sourceVerifications[source.key]
95
- ? new Date(sourceVerifications[source.key])
96
- : source.verifiedAt ? new Date(source.verifiedAt) : null;
97
-
98
- if (!verifiedAt) {
99
- return { ...source, status: 'unverified', daysStale: null };
100
- }
101
-
102
- const daysSince = Math.floor((now - verifiedAt) / (1000 * 60 * 60 * 24));
103
- const isStale = daysSince > source.stalenessThresholdDays;
104
-
105
- return {
106
- ...source,
107
- verifiedAt: verifiedAt.toISOString(),
108
- daysStale: daysSince,
109
- status: isStale ? 'stale' : 'fresh',
110
- };
111
- });
112
-
113
- return {
114
- ready: results.every(r => r.status === 'fresh'),
115
- stale: results.filter(r => r.status === 'stale' || r.status === 'unverified'),
116
- fresh: results.filter(r => r.status === 'fresh'),
117
- results,
118
- };
119
- }
120
-
121
- function formatReleaseGate(gateResult) {
122
- const lines = [
123
- `OpenCode Freshness Gate (nerviq v${version})`,
124
- '═══════════════════════════════════════',
125
- '',
126
- `Status: ${gateResult.ready ? 'READY' : 'BLOCKED'}`,
127
- `Fresh: ${gateResult.fresh.length}/${gateResult.results.length}`,
128
- '',
129
- ];
130
-
131
- for (const result of gateResult.results) {
132
- const icon = result.status === 'fresh' ? '✓' : result.status === 'stale' ? '✗' : '?';
133
- const age = result.daysStale !== null ? ` (${result.daysStale}d ago)` : ' (unverified)';
134
- lines.push(` ${icon} ${result.label}${age} — threshold: ${result.stalenessThresholdDays}d`);
135
- }
136
-
137
- if (!gateResult.ready) {
138
- lines.push('');
139
- lines.push('Action required: verify stale/unverified sources before claiming release freshness.');
140
- }
141
-
142
- return lines.join('\n');
143
- }
144
-
145
- function getPropagationTargets(triggerKeyword) {
146
- const keyword = triggerKeyword.toLowerCase();
147
- return PROPAGATION_CHECKLIST.filter(item =>
148
- item.trigger.toLowerCase().includes(keyword)
149
- );
150
- }
151
-
152
- module.exports = {
153
- P0_SOURCES,
154
- PROPAGATION_CHECKLIST,
155
- checkReleaseGate,
156
- formatReleaseGate,
157
- getPropagationTargets,
158
- };
1
+ /**
2
+ * OpenCode Freshness Operationalization
3
+ *
4
+ * Release gates, recurring probes, propagation checklists,
5
+ * and staleness blocking for OpenCode surfaces.
6
+ */
7
+
8
+ const { version } = require('../../package.json');
9
+
10
+ const P0_SOURCES = [
11
+ {
12
+ key: 'opencode-docs',
13
+ label: 'OpenCode Official Docs',
14
+ url: 'https://opencode.ai/docs',
15
+ stalenessThresholdDays: 30,
16
+ verifiedAt: '2026-04-07',
17
+ },
18
+ {
19
+ key: 'opencode-config-reference',
20
+ label: 'OpenCode Config Reference',
21
+ url: 'https://opencode.ai/docs/config/',
22
+ stalenessThresholdDays: 30,
23
+ verifiedAt: '2026-04-07',
24
+ },
25
+ {
26
+ key: 'opencode-github-releases',
27
+ label: 'OpenCode GitHub Releases',
28
+ url: 'https://github.com/sst/opencode/releases',
29
+ stalenessThresholdDays: 14,
30
+ verifiedAt: '2026-04-07',
31
+ },
32
+ {
33
+ key: 'opencode-plugin-api',
34
+ label: 'OpenCode Plugin API',
35
+ url: 'https://opencode.ai/docs/plugins/',
36
+ stalenessThresholdDays: 30,
37
+ verifiedAt: '2026-04-07',
38
+ },
39
+ {
40
+ key: 'opencode-permissions-docs',
41
+ label: 'OpenCode Permissions Documentation',
42
+ url: 'https://opencode.ai/docs/permissions/',
43
+ stalenessThresholdDays: 30,
44
+ verifiedAt: '2026-04-07',
45
+ },
46
+ ];
47
+
48
+ const PROPAGATION_CHECKLIST = [
49
+ {
50
+ trigger: 'OpenCode release with config changes',
51
+ targets: [
52
+ 'src/opencode/techniques.js — update DEPRECATED_CONFIG_KEYS if keys renamed/removed',
53
+ 'src/opencode/config-parser.js — update JSONC validation',
54
+ 'src/opencode/governance.js — update caveats if behavior changes',
55
+ 'test/opencode-check-matrix.js — update check expectations',
56
+ ],
57
+ },
58
+ {
59
+ trigger: 'New OpenCode plugin event type added',
60
+ targets: [
61
+ 'src/opencode/techniques.js — add to VALID_PLUGIN_EVENTS',
62
+ 'src/opencode/governance.js — add to OPENCODE_PLUGIN_GOVERNANCE',
63
+ 'src/opencode/setup.js — update plugins starter template',
64
+ ],
65
+ },
66
+ {
67
+ trigger: 'New OpenCode permission tool added',
68
+ targets: [
69
+ 'src/opencode/techniques.js — add to PERMISSIONED_TOOLS',
70
+ 'src/opencode/governance.js — update permission profiles',
71
+ 'src/opencode/setup.js — update default permission config',
72
+ ],
73
+ },
74
+ {
75
+ trigger: 'OpenCode MCP schema change',
76
+ targets: [
77
+ 'src/opencode/mcp-packs.js — update JSONC projections',
78
+ 'src/opencode/techniques.js — update MCP checks',
79
+ ],
80
+ },
81
+ {
82
+ trigger: 'Known security bug fixed or new bug reported',
83
+ targets: [
84
+ 'src/opencode/techniques.js — update security checks (E02, E03, D05)',
85
+ 'src/opencode/governance.js — update platformCaveats',
86
+ 'src/opencode/freshness.js — verify against latest release',
87
+ ],
88
+ },
89
+ ];
90
+
91
+ function checkReleaseGate(sourceVerifications = {}) {
92
+ const now = new Date();
93
+ const results = P0_SOURCES.map(source => {
94
+ const verifiedAt = sourceVerifications[source.key]
95
+ ? new Date(sourceVerifications[source.key])
96
+ : source.verifiedAt ? new Date(source.verifiedAt) : null;
97
+
98
+ if (!verifiedAt) {
99
+ return { ...source, status: 'unverified', daysStale: null };
100
+ }
101
+
102
+ const daysSince = Math.floor((now - verifiedAt) / (1000 * 60 * 60 * 24));
103
+ const isStale = daysSince > source.stalenessThresholdDays;
104
+
105
+ return {
106
+ ...source,
107
+ verifiedAt: verifiedAt.toISOString(),
108
+ daysStale: daysSince,
109
+ status: isStale ? 'stale' : 'fresh',
110
+ };
111
+ });
112
+
113
+ return {
114
+ ready: results.every(r => r.status === 'fresh'),
115
+ stale: results.filter(r => r.status === 'stale' || r.status === 'unverified'),
116
+ fresh: results.filter(r => r.status === 'fresh'),
117
+ results,
118
+ };
119
+ }
120
+
121
+ function formatReleaseGate(gateResult) {
122
+ const lines = [
123
+ `OpenCode Freshness Gate (nerviq v${version})`,
124
+ '═══════════════════════════════════════',
125
+ '',
126
+ `Status: ${gateResult.ready ? 'READY' : 'BLOCKED'}`,
127
+ `Fresh: ${gateResult.fresh.length}/${gateResult.results.length}`,
128
+ '',
129
+ ];
130
+
131
+ for (const result of gateResult.results) {
132
+ const icon = result.status === 'fresh' ? '✓' : result.status === 'stale' ? '✗' : '?';
133
+ const age = result.daysStale !== null ? ` (${result.daysStale}d ago)` : ' (unverified)';
134
+ lines.push(` ${icon} ${result.label}${age} — threshold: ${result.stalenessThresholdDays}d`);
135
+ }
136
+
137
+ if (!gateResult.ready) {
138
+ lines.push('');
139
+ lines.push('Action required: verify stale/unverified sources before claiming release freshness.');
140
+ }
141
+
142
+ return lines.join('\n');
143
+ }
144
+
145
+ function getPropagationTargets(triggerKeyword) {
146
+ const keyword = triggerKeyword.toLowerCase();
147
+ return PROPAGATION_CHECKLIST.filter(item =>
148
+ item.trigger.toLowerCase().includes(keyword)
149
+ );
150
+ }
151
+
152
+ module.exports = {
153
+ P0_SOURCES,
154
+ PROPAGATION_CHECKLIST,
155
+ checkReleaseGate,
156
+ formatReleaseGate,
157
+ getPropagationTargets,
158
+ };
package/src/server.js CHANGED
@@ -18,6 +18,10 @@ const SUPPORTED_PLATFORMS = new Set([
18
18
  'opencode',
19
19
  ]);
20
20
 
21
+ function envelope(data) {
22
+ return { data, meta: { version, timestamp: new Date().toISOString() } };
23
+ }
24
+
21
25
  function sendJson(res, statusCode, payload) {
22
26
  const body = JSON.stringify(payload, null, 2);
23
27
  res.writeHead(statusCode, {
@@ -57,6 +61,11 @@ function createServer(options = {}) {
57
61
  const baseDir = path.resolve(options.baseDir || process.cwd());
58
62
 
59
63
  return http.createServer(async (req, res) => {
64
+ res.setHeader('Access-Control-Allow-Origin', '*');
65
+ res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
66
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
67
+ if (req.method === 'OPTIONS') { res.writeHead(204); res.end(); return; }
68
+
60
69
  const requestUrl = new URL(req.url || '/', 'http://127.0.0.1');
61
70
 
62
71
  if (req.method !== 'GET') {
@@ -66,16 +75,16 @@ function createServer(options = {}) {
66
75
 
67
76
  try {
68
77
  if (requestUrl.pathname === '/api/health') {
69
- sendJson(res, 200, {
78
+ sendJson(res, 200, envelope({
70
79
  status: 'ok',
71
80
  version,
72
81
  checks: getCatalog().length,
73
- });
82
+ }));
74
83
  return;
75
84
  }
76
85
 
77
86
  if (requestUrl.pathname === '/api/catalog') {
78
- sendJson(res, 200, getCatalog());
87
+ sendJson(res, 200, envelope(getCatalog()));
79
88
  return;
80
89
  }
81
90
 
@@ -83,14 +92,14 @@ function createServer(options = {}) {
83
92
  const dir = resolveRequestDir(baseDir, requestUrl.searchParams.get('dir'));
84
93
  const platform = normalizePlatform(requestUrl.searchParams.get('platform'));
85
94
  const result = await audit({ dir, platform, silent: true });
86
- sendJson(res, 200, result);
95
+ sendJson(res, 200, envelope(result));
87
96
  return;
88
97
  }
89
98
 
90
99
  if (requestUrl.pathname === '/api/harmony') {
91
100
  const dir = resolveRequestDir(baseDir, requestUrl.searchParams.get('dir'));
92
101
  const result = await harmonyAudit({ dir, silent: true });
93
- sendJson(res, 200, result);
102
+ sendJson(res, 200, envelope(result));
94
103
  return;
95
104
  }
96
105
 
package/src/setup.js CHANGED
@@ -10,6 +10,7 @@ const { ProjectContext } = require('./context');
10
10
  const { audit } = require('./audit');
11
11
  const { buildSettingsForProfile } = require('./governance');
12
12
  const { getMcpPackPreflight } = require('./mcp-packs');
13
+ const { writeRollbackArtifact } = require('./activity');
13
14
  const { setupCodex } = require('./codex/setup');
14
15
 
15
16
  // ============================================================
@@ -797,14 +798,21 @@ try {
797
798
  } catch (e) { /* linter not available or failed - non-blocking */ }
798
799
  `,
799
800
  'protect-secrets.js': `#!/usr/bin/env node
800
- // PreToolUse hook - blocks reads of secret files
801
+ // PreToolUse hook - blocks reads of secret files (Read/Write/Edit AND Bash)
801
802
  let input = '';
802
803
  process.stdin.on('data', d => input += d);
803
804
  process.stdin.on('end', () => {
804
805
  try {
805
806
  const data = JSON.parse(input);
807
+ // Check file_path (for Read/Write/Edit)
806
808
  const fp = (data.tool_input && data.tool_input.file_path) || '';
807
- if (/\\.env$|\\.env\\.|secrets[\\/\\\\]|credentials|\\.pem$|\\.key$/i.test(fp)) {
809
+ // Check command (for Bash)
810
+ const cmd = (data.tool_input && data.tool_input.command) || '';
811
+
812
+ const secretPattern = /\\.env($|\\.)|secrets[\\/\\\\]|credentials|\\.pem$|\\.key$/i;
813
+ const bashSecretPattern = /\\bcat\\s+\\.env|\\bless\\s+\\.env|\\bhead\\s+\\.env|\\btail\\s+\\.env|\\bgrep\\b.*\\.env|\\bcp\\s+\\.env|\\bmv\\s+\\.env|\\bbase64\\s+\\.env|\\bxxd\\s+\\.env|secrets\\/|credentials|\\.pem\\b|\\.key\\b/i;
814
+
815
+ if (secretPattern.test(fp) || bashSecretPattern.test(cmd)) {
808
816
  console.log(JSON.stringify({ decision: 'block', reason: 'Blocked: accessing secret/credential files is not allowed.' }));
809
817
  } else {
810
818
  console.log(JSON.stringify({ decision: 'allow' }));
@@ -1143,6 +1151,17 @@ async function setup(options) {
1143
1151
  const mcpPreflightWarnings = getMcpPackPreflight(options.mcpPacks || [])
1144
1152
  .filter(item => item.missingEnvVars.length > 0);
1145
1153
 
1154
+ // Snapshot settings.json before any changes for rollback support
1155
+ const settingsPathForSnapshot = path.join(options.dir, '.claude/settings.json');
1156
+ let settingsSnapshotBefore = null;
1157
+ if (fs.existsSync(settingsPathForSnapshot)) {
1158
+ try {
1159
+ settingsSnapshotBefore = fs.readFileSync(settingsPathForSnapshot, 'utf8');
1160
+ } catch (_) {
1161
+ // Ignore read errors
1162
+ }
1163
+ }
1164
+
1146
1165
  function log(message = '') {
1147
1166
  if (!silent) {
1148
1167
  console.log(message);
@@ -1260,7 +1279,17 @@ async function setup(options) {
1260
1279
  }
1261
1280
  // Merge all fields from newSettings into existing, preserving existing values
1262
1281
  if (newSettings.hooks) existingSettings.hooks = newSettings.hooks;
1263
- if (newSettings.permissions) existingSettings.permissions = { ...existingSettings.permissions, ...newSettings.permissions };
1282
+ if (newSettings.permissions) {
1283
+ existingSettings.permissions = existingSettings.permissions || {};
1284
+ // MERGE deny rules: keep existing + add new (deduplicate)
1285
+ const existingDeny = existingSettings.permissions.deny || [];
1286
+ const newDeny = newSettings.permissions.deny || [];
1287
+ existingSettings.permissions.deny = [...new Set([...existingDeny, ...newDeny])];
1288
+ // Only set defaultMode if not already set
1289
+ if (!existingSettings.permissions.defaultMode && newSettings.permissions.defaultMode) {
1290
+ existingSettings.permissions.defaultMode = newSettings.permissions.defaultMode;
1291
+ }
1292
+ }
1264
1293
  if (newSettings.mcpServers) existingSettings.mcpServers = { ...existingSettings.mcpServers, ...newSettings.mcpServers };
1265
1294
  if (newSettings.nerviqSetup) existingSettings.nerviqSetup = { ...existingSettings.nerviqSetup, ...newSettings.nerviqSetup };
1266
1295
  fs.writeFileSync(settingsPath, JSON.stringify(existingSettings, null, 2), 'utf8');
@@ -1302,6 +1331,29 @@ async function setup(options) {
1302
1331
  log(' Run \x1b[1mnpx nerviq audit\x1b[0m to check your score.');
1303
1332
  log('');
1304
1333
 
1334
+ // Write rollback artifact so setup can be undone
1335
+ let rollbackId = null;
1336
+ if (writtenFiles.length > 0) {
1337
+ const patchedFiles = [];
1338
+ // If settings.json was modified (not newly created), record the before-snapshot
1339
+ if (settingsSnapshotBefore !== null && writtenFiles.includes('.claude/settings.json')) {
1340
+ patchedFiles.push({
1341
+ file: '.claude/settings.json',
1342
+ before: settingsSnapshotBefore,
1343
+ });
1344
+ }
1345
+ const rollbackArtifact = writeRollbackArtifact(options.dir, {
1346
+ sourcePlan: 'setup',
1347
+ createdFiles: writtenFiles.filter(f => {
1348
+ // Exclude patched files from createdFiles list
1349
+ return !patchedFiles.some(p => p.file === f);
1350
+ }),
1351
+ patchedFiles,
1352
+ rollbackInstructions: ['Use nerviq rollback to undo this setup'],
1353
+ });
1354
+ rollbackId = rollbackArtifact.id;
1355
+ }
1356
+
1305
1357
  return {
1306
1358
  created,
1307
1359
  skipped,
@@ -1309,6 +1361,7 @@ async function setup(options) {
1309
1361
  preservedFiles,
1310
1362
  stacks,
1311
1363
  mcpPreflightWarnings,
1364
+ rollbackId,
1312
1365
  };
1313
1366
  }
1314
1367
 
package/src/techniques.js CHANGED
@@ -954,6 +954,119 @@ const TECHNIQUES = {
954
954
  template: null
955
955
  },
956
956
 
957
+ // --- Dockerfile best practices (Issue #8) ---
958
+
959
+ dockerMultiStage: {
960
+ id: 39902,
961
+ name: 'Dockerfile uses multi-stage build',
962
+ check: (ctx) => {
963
+ const df = findProjectFiles(ctx, /^Dockerfile$/i);
964
+ if (df.length === 0) return null;
965
+ const content = ctx.fileContent(df[0]) || '';
966
+ return (content.match(/^FROM\s/gim) || []).length >= 2;
967
+ },
968
+ impact: 'medium',
969
+ rating: 3,
970
+ category: 'devops',
971
+ fix: 'Use multi-stage builds in Dockerfile to reduce image size and avoid leaking build tools into production.',
972
+ template: null
973
+ },
974
+
975
+ dockerignoreExists: {
976
+ id: 39903,
977
+ name: '.dockerignore includes node_modules and .env',
978
+ check: (ctx) => {
979
+ if (!ctx.files.some(f => /^Dockerfile/i.test(f))) return null;
980
+ const di = ctx.fileContent('.dockerignore') || '';
981
+ return di.includes('node_modules') && /\.env/i.test(di);
982
+ },
983
+ impact: 'high',
984
+ rating: 4,
985
+ category: 'devops',
986
+ fix: 'Add .dockerignore with node_modules, .env, and other sensitive/large files to keep images small and secure.',
987
+ template: null
988
+ },
989
+
990
+ dockerNoSecrets: {
991
+ id: 39904,
992
+ name: 'Dockerfile has no secrets in build args',
993
+ check: (ctx) => {
994
+ const df = findProjectFiles(ctx, /^Dockerfile$/i);
995
+ if (df.length === 0) return null;
996
+ const content = ctx.fileContent(df[0]) || '';
997
+ return !/ARG\s+(PASSWORD|SECRET|TOKEN|API_KEY|PRIVATE_KEY)/i.test(content);
998
+ },
999
+ impact: 'critical',
1000
+ rating: 5,
1001
+ category: 'devops',
1002
+ fix: 'Never pass secrets via ARG in Dockerfile — use runtime environment variables or secret mounts instead.',
1003
+ template: null
1004
+ },
1005
+
1006
+ // --- Terraform checks (Issue #10) ---
1007
+
1008
+ terraformFmt: {
1009
+ id: 39705,
1010
+ name: 'Terraform formatting configured',
1011
+ check: (ctx) => {
1012
+ if (!ctx.files.some(f => /\.tf$/.test(f))) return null;
1013
+ const ci = readProjectFiles(ctx, /\.(yml|yaml)$/i, 10);
1014
+ const makefileContent = ctx.fileContent('Makefile') || '';
1015
+ const preCommit = ctx.fileContent('.pre-commit-config.yaml') || '';
1016
+ return /terraform\s+fmt/i.test(ci) || /terraform\s+fmt/i.test(makefileContent) || /terraform_fmt/i.test(preCommit);
1017
+ },
1018
+ impact: 'medium',
1019
+ rating: 3,
1020
+ category: 'devops',
1021
+ fix: 'Add `terraform fmt` to CI or pre-commit hooks to enforce consistent formatting.',
1022
+ template: null
1023
+ },
1024
+
1025
+ terraformDirIgnored: {
1026
+ id: 39706,
1027
+ name: '.terraform directory in .gitignore',
1028
+ check: (ctx) => {
1029
+ if (!ctx.files.some(f => /\.tf$/.test(f))) return null;
1030
+ const gi = ctx.fileContent('.gitignore') || '';
1031
+ return /\.terraform/i.test(gi);
1032
+ },
1033
+ impact: 'high',
1034
+ rating: 4,
1035
+ category: 'devops',
1036
+ fix: 'Add .terraform/ to .gitignore — it contains provider binaries and should not be committed.',
1037
+ template: null
1038
+ },
1039
+
1040
+ terraformStateNotCommitted: {
1041
+ id: 39707,
1042
+ name: 'Terraform state file not committed',
1043
+ check: (ctx) => {
1044
+ if (!ctx.files.some(f => /\.tf$/.test(f))) return null;
1045
+ return !ctx.files.some(f => /terraform\.tfstate$/i.test(f));
1046
+ },
1047
+ impact: 'critical',
1048
+ rating: 5,
1049
+ category: 'devops',
1050
+ fix: 'Never commit terraform.tfstate — it may contain secrets. Use a remote backend (S3, GCS, Terraform Cloud).',
1051
+ template: null
1052
+ },
1053
+
1054
+ terraformBackendConfigured: {
1055
+ id: 39708,
1056
+ name: 'Terraform remote backend configured',
1057
+ check: (ctx) => {
1058
+ const tfFiles = findProjectFiles(ctx, /\.tf$/);
1059
+ if (tfFiles.length === 0) return null;
1060
+ const allTf = tfFiles.slice(0, 10).map(f => ctx.fileContent(f) || '').join('\n');
1061
+ return /backend\s+"(s3|gcs|azurerm|remote|cloud|consul|http)"/i.test(allTf);
1062
+ },
1063
+ impact: 'high',
1064
+ rating: 4,
1065
+ category: 'devops',
1066
+ fix: 'Configure a remote backend in Terraform (S3, GCS, Terraform Cloud) for team collaboration and state locking.',
1067
+ template: null
1068
+ },
1069
+
957
1070
  // ============================================================
958
1071
  // === PROJECT HYGIENE (category: 'hygiene') ==================
959
1072
  // ============================================================