@nerviq/cli 1.8.9 → 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/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
  // ============================================================