@nerviq/cli 0.0.1 → 0.9.0-beta.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 +181 -0
- package/LICENSE +21 -0
- package/README.md +447 -0
- package/bin/cli.js +749 -0
- package/content/case-study-template.md +91 -0
- package/content/claims-governance.md +37 -0
- package/content/claude-code/audit-repo/SKILL.md +20 -0
- package/content/claude-native-integration.md +60 -0
- package/content/devto-article.json +9 -0
- package/content/launch-posts.md +226 -0
- package/content/pilot-rollout-kit.md +30 -0
- package/content/release-checklist.md +31 -0
- package/package.json +53 -4
- package/src/activity.js +529 -0
- package/src/aider/activity.js +226 -0
- package/src/aider/config-parser.js +166 -0
- package/src/aider/context.js +158 -0
- package/src/aider/deep-review.js +316 -0
- package/src/aider/domain-packs.js +278 -0
- package/src/aider/freshness.js +168 -0
- package/src/aider/governance.js +253 -0
- package/src/aider/interactive.js +334 -0
- package/src/aider/mcp-packs.js +98 -0
- package/src/aider/patch.js +214 -0
- package/src/aider/plans.js +186 -0
- package/src/aider/premium.js +360 -0
- package/src/aider/setup.js +404 -0
- package/src/aider/techniques.js +1323 -0
- package/src/analyze.js +821 -0
- package/src/audit.js +1003 -0
- package/src/badge.js +13 -0
- package/src/benchmark.js +339 -0
- package/src/claudex-sync.json +7 -0
- package/src/codex/activity.js +324 -0
- package/src/codex/config-parser.js +183 -0
- package/src/codex/context.js +221 -0
- package/src/codex/deep-review.js +493 -0
- package/src/codex/domain-packs.js +372 -0
- package/src/codex/freshness.js +167 -0
- package/src/codex/governance.js +192 -0
- package/src/codex/interactive.js +618 -0
- package/src/codex/mcp-packs.js +660 -0
- package/src/codex/patch.js +209 -0
- package/src/codex/plans.js +251 -0
- package/src/codex/premium.js +614 -0
- package/src/codex/setup.js +603 -0
- package/src/codex/techniques.js +2649 -0
- package/src/context.js +272 -0
- package/src/copilot/activity.js +309 -0
- package/src/copilot/config-parser.js +226 -0
- package/src/copilot/context.js +197 -0
- package/src/copilot/deep-review.js +346 -0
- package/src/copilot/domain-packs.js +350 -0
- package/src/copilot/freshness.js +197 -0
- package/src/copilot/governance.js +222 -0
- package/src/copilot/interactive.js +406 -0
- package/src/copilot/mcp-packs.js +572 -0
- package/src/copilot/patch.js +238 -0
- package/src/copilot/plans.js +253 -0
- package/src/copilot/premium.js +450 -0
- package/src/copilot/setup.js +488 -0
- package/src/copilot/techniques.js +1822 -0
- package/src/cursor/activity.js +301 -0
- package/src/cursor/config-parser.js +265 -0
- package/src/cursor/context.js +236 -0
- package/src/cursor/deep-review.js +334 -0
- package/src/cursor/domain-packs.js +346 -0
- package/src/cursor/freshness.js +214 -0
- package/src/cursor/governance.js +229 -0
- package/src/cursor/interactive.js +391 -0
- package/src/cursor/mcp-packs.js +571 -0
- package/src/cursor/patch.js +243 -0
- package/src/cursor/plans.js +254 -0
- package/src/cursor/premium.js +468 -0
- package/src/cursor/setup.js +488 -0
- package/src/cursor/techniques.js +1786 -0
- package/src/deep-review.js +345 -0
- package/src/domain-packs.js +364 -0
- package/src/formatters/sarif.js +115 -0
- package/src/gemini/activity.js +402 -0
- package/src/gemini/config-parser.js +275 -0
- package/src/gemini/context.js +221 -0
- package/src/gemini/deep-review.js +559 -0
- package/src/gemini/domain-packs.js +371 -0
- package/src/gemini/freshness.js +204 -0
- package/src/gemini/governance.js +201 -0
- package/src/gemini/interactive.js +860 -0
- package/src/gemini/mcp-packs.js +658 -0
- package/src/gemini/patch.js +229 -0
- package/src/gemini/plans.js +269 -0
- package/src/gemini/premium.js +759 -0
- package/src/gemini/setup.js +692 -0
- package/src/gemini/techniques.js +2084 -0
- package/src/governance.js +523 -0
- package/src/harmony/advisor.js +383 -0
- package/src/harmony/audit.js +303 -0
- package/src/harmony/canon.js +444 -0
- package/src/harmony/cli.js +331 -0
- package/src/harmony/drift.js +401 -0
- package/src/harmony/governance.js +313 -0
- package/src/harmony/memory.js +238 -0
- package/src/harmony/sync.js +458 -0
- package/src/harmony/watch.js +336 -0
- package/src/index.js +256 -0
- package/src/insights.js +119 -0
- package/src/interactive.js +118 -0
- package/src/mcp-packs.js +597 -0
- package/src/opencode/activity.js +286 -0
- package/src/opencode/config-parser.js +109 -0
- package/src/opencode/context.js +247 -0
- package/src/opencode/deep-review.js +313 -0
- package/src/opencode/domain-packs.js +240 -0
- package/src/opencode/freshness.js +158 -0
- package/src/opencode/governance.js +159 -0
- package/src/opencode/interactive.js +392 -0
- package/src/opencode/mcp-packs.js +474 -0
- package/src/opencode/patch.js +184 -0
- package/src/opencode/plans.js +231 -0
- package/src/opencode/premium.js +413 -0
- package/src/opencode/setup.js +449 -0
- package/src/opencode/techniques.js +1713 -0
- package/src/plans.js +655 -0
- package/src/secret-patterns.js +30 -0
- package/src/setup.js +1274 -0
- package/src/synergy/adaptive.js +261 -0
- package/src/synergy/compensation.js +156 -0
- package/src/synergy/evidence.js +193 -0
- package/src/synergy/learning.js +184 -0
- package/src/synergy/patterns.js +227 -0
- package/src/synergy/ranking.js +83 -0
- package/src/synergy/report.js +163 -0
- package/src/synergy/routing.js +152 -0
- package/src/techniques.js +1354 -0
- package/src/watch.js +229 -0
- package/src/windsurf/activity.js +302 -0
- package/src/windsurf/config-parser.js +267 -0
- package/src/windsurf/context.js +249 -0
- package/src/windsurf/deep-review.js +337 -0
- package/src/windsurf/domain-packs.js +348 -0
- package/src/windsurf/freshness.js +215 -0
- package/src/windsurf/governance.js +231 -0
- package/src/windsurf/interactive.js +388 -0
- package/src/windsurf/mcp-packs.js +535 -0
- package/src/windsurf/patch.js +231 -0
- package/src/windsurf/plans.js +247 -0
- package/src/windsurf/premium.js +467 -0
- package/src/windsurf/setup.js +471 -0
- package/src/windsurf/techniques.js +1758 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Plans — Proposal families for OpenCode setup
|
|
3
|
+
*
|
|
4
|
+
* Families: opencode-agents-md, opencode-config, opencode-permissions,
|
|
5
|
+
* opencode-plugins, opencode-skills, opencode-mcp, opencode-ci
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { version } = require('../../package.json');
|
|
10
|
+
const { audit } = require('../audit');
|
|
11
|
+
const { analyzeProject } = require('../analyze');
|
|
12
|
+
const { buildOpenCodeSetupFiles } = require('./setup');
|
|
13
|
+
const { getOpenCodeMcpPreflight } = require('./mcp-packs');
|
|
14
|
+
|
|
15
|
+
function maturityFromScore(score) {
|
|
16
|
+
if (score >= 81) return 'mature';
|
|
17
|
+
if (score >= 61) return 'solid';
|
|
18
|
+
if (score >= 41) return 'developing';
|
|
19
|
+
if (score >= 21) return 'weak';
|
|
20
|
+
return 'raw';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function triggerMatchesFile(result, filePath) {
|
|
24
|
+
if (filePath === 'AGENTS.md') {
|
|
25
|
+
return result.file === 'AGENTS.md' || result.category === 'instructions' || result.category === 'quality-deep';
|
|
26
|
+
}
|
|
27
|
+
if (filePath === 'opencode.json') {
|
|
28
|
+
return result.file === 'opencode.json' || ['config', 'permissions', 'plugins', 'mcp', 'agents'].includes(result.category);
|
|
29
|
+
}
|
|
30
|
+
if (filePath === '.opencode/plugins/README.md') {
|
|
31
|
+
return result.category === 'plugins';
|
|
32
|
+
}
|
|
33
|
+
if (filePath === '.opencode/commands/README.md') {
|
|
34
|
+
return result.category === 'skills' || result.category === 'commands';
|
|
35
|
+
}
|
|
36
|
+
if (filePath === 'opencode.json (MCP append)') {
|
|
37
|
+
return result.category === 'mcp';
|
|
38
|
+
}
|
|
39
|
+
if (filePath === '.github/workflows/opencode-review.yml') {
|
|
40
|
+
return result.category === 'ci';
|
|
41
|
+
}
|
|
42
|
+
return result.file === filePath;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function uniqueValues(items = []) {
|
|
46
|
+
return [...new Set(items.filter(Boolean))];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function buildDomainPackGuidance(report) {
|
|
50
|
+
return (report.recommendedDomainPacks || []).map((pack) => ({
|
|
51
|
+
key: pack.key,
|
|
52
|
+
label: pack.label,
|
|
53
|
+
useWhen: pack.useWhen,
|
|
54
|
+
matchReasons: pack.matchReasons || [],
|
|
55
|
+
recommendedModules: pack.recommendedModules || [],
|
|
56
|
+
recommendedProposalFamilies: pack.recommendedProposalFamilies || [],
|
|
57
|
+
recommendedSurfaces: pack.recommendedSurfaces || [],
|
|
58
|
+
benchmarkFocus: pack.benchmarkFocus || [],
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function selectPackContext(filePath, domainPackGuidance = []) {
|
|
63
|
+
return domainPackGuidance
|
|
64
|
+
.filter((pack) => {
|
|
65
|
+
if (!Array.isArray(pack.recommendedSurfaces) || pack.recommendedSurfaces.length === 0) return true;
|
|
66
|
+
return pack.recommendedSurfaces.some((surface) => filePath === surface || filePath.startsWith(surface));
|
|
67
|
+
})
|
|
68
|
+
.map((pack) => ({
|
|
69
|
+
key: pack.key,
|
|
70
|
+
label: pack.label,
|
|
71
|
+
why: pack.matchReasons[0] || pack.useWhen,
|
|
72
|
+
recommendedModules: (pack.recommendedModules || []).slice(0, 3),
|
|
73
|
+
recommendedProposalFamilies: (pack.recommendedProposalFamilies || []).slice(0, 3),
|
|
74
|
+
benchmarkFocus: (pack.benchmarkFocus || []).slice(0, 2),
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const PROPOSAL_FAMILIES = {
|
|
79
|
+
'AGENTS.md': {
|
|
80
|
+
id: 'opencode-agents-md',
|
|
81
|
+
title: 'Create OpenCode AGENTS.md baseline',
|
|
82
|
+
module: 'instructions',
|
|
83
|
+
risk: 'low',
|
|
84
|
+
confidence: 'high',
|
|
85
|
+
},
|
|
86
|
+
'opencode.json': {
|
|
87
|
+
id: 'opencode-config',
|
|
88
|
+
title: 'Create OpenCode config baseline',
|
|
89
|
+
module: 'config',
|
|
90
|
+
risk: 'medium',
|
|
91
|
+
confidence: 'high',
|
|
92
|
+
},
|
|
93
|
+
'.opencode/plugins/README.md': {
|
|
94
|
+
id: 'opencode-plugins',
|
|
95
|
+
title: 'Create OpenCode plugins starter',
|
|
96
|
+
module: 'plugins',
|
|
97
|
+
risk: 'low',
|
|
98
|
+
confidence: 'high',
|
|
99
|
+
},
|
|
100
|
+
'.opencode/commands/README.md': {
|
|
101
|
+
id: 'opencode-skills',
|
|
102
|
+
title: 'Create OpenCode commands/skills starter',
|
|
103
|
+
module: 'skills',
|
|
104
|
+
risk: 'low',
|
|
105
|
+
confidence: 'high',
|
|
106
|
+
},
|
|
107
|
+
'opencode.json (MCP append)': {
|
|
108
|
+
id: 'opencode-mcp',
|
|
109
|
+
title: 'Add recommended MCP packs to OpenCode config',
|
|
110
|
+
module: 'mcp',
|
|
111
|
+
risk: 'medium',
|
|
112
|
+
confidence: 'high',
|
|
113
|
+
},
|
|
114
|
+
'.github/workflows/opencode-review.yml': {
|
|
115
|
+
id: 'opencode-ci',
|
|
116
|
+
title: 'Create OpenCode CI review workflow',
|
|
117
|
+
module: 'ci',
|
|
118
|
+
risk: 'medium',
|
|
119
|
+
confidence: 'medium',
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
function resolveProposalFamily(file) {
|
|
124
|
+
const familyFromFile = file.family
|
|
125
|
+
? Object.values(PROPOSAL_FAMILIES).find(f => f.id === file.family)
|
|
126
|
+
: null;
|
|
127
|
+
return familyFromFile || PROPOSAL_FAMILIES[file.path] || {
|
|
128
|
+
id: 'opencode-unknown',
|
|
129
|
+
title: `Create ${file.path}`,
|
|
130
|
+
module: 'unknown',
|
|
131
|
+
risk: 'medium',
|
|
132
|
+
confidence: 'low',
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function proposalForFile(file, auditResult, domainPackGuidance = []) {
|
|
137
|
+
const triggers = auditResult.results
|
|
138
|
+
.filter((result) => result.passed === false && triggerMatchesFile(result, file.path))
|
|
139
|
+
.sort((a, b) => {
|
|
140
|
+
const weight = { critical: 3, high: 2, medium: 1, low: 0 };
|
|
141
|
+
return (weight[b.impact] || 0) - (weight[a.impact] || 0);
|
|
142
|
+
})
|
|
143
|
+
.slice(0, 6)
|
|
144
|
+
.map((result) => ({ key: result.key, name: result.name, impact: result.impact, fix: result.fix }));
|
|
145
|
+
|
|
146
|
+
const packContext = selectPackContext(file.path, domainPackGuidance);
|
|
147
|
+
const familyMeta = resolveProposalFamily(file);
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
id: familyMeta.id,
|
|
151
|
+
title: familyMeta.title,
|
|
152
|
+
module: familyMeta.module,
|
|
153
|
+
risk: familyMeta.risk,
|
|
154
|
+
confidence: familyMeta.confidence,
|
|
155
|
+
triggers,
|
|
156
|
+
rationale: uniqueValues([
|
|
157
|
+
...triggers.map((item) => item.fix),
|
|
158
|
+
...packContext.map((item) => `Supports ${item.label} rollout guidance: ${item.why}`),
|
|
159
|
+
]),
|
|
160
|
+
packContext,
|
|
161
|
+
files: [{
|
|
162
|
+
path: file.path,
|
|
163
|
+
action: file.action,
|
|
164
|
+
currentState: file.currentState,
|
|
165
|
+
proposedState: file.proposedState,
|
|
166
|
+
content: file.content,
|
|
167
|
+
preview: file.content.split('\n').slice(0, 12).join('\n'),
|
|
168
|
+
diffPreview: [
|
|
169
|
+
'--- missing',
|
|
170
|
+
`+++ ${file.path}`,
|
|
171
|
+
...file.content.split('\n').slice(0, 12).map((line) => `+${line}`),
|
|
172
|
+
].join('\n'),
|
|
173
|
+
}],
|
|
174
|
+
readyToApply: true,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function buildOpenCodeProposalBundle(options) {
|
|
179
|
+
const auditResult = await audit({ ...options, platform: 'opencode', silent: true });
|
|
180
|
+
const analysisReport = await analyzeProject({ ...options, platform: 'opencode', mode: 'suggest-only' });
|
|
181
|
+
const domainPackGuidance = buildDomainPackGuidance(analysisReport);
|
|
182
|
+
const { files } = buildOpenCodeSetupFiles(options);
|
|
183
|
+
const proposals = files.map((file) => proposalForFile(file, auditResult, domainPackGuidance));
|
|
184
|
+
|
|
185
|
+
// MCP preflight warnings
|
|
186
|
+
const mcpProposal = proposals.find(p => p.id === 'opencode-mcp');
|
|
187
|
+
let mcpPreflightWarnings = [];
|
|
188
|
+
if (mcpProposal) {
|
|
189
|
+
const mcpFile = files.find(f => f.family === 'opencode-mcp');
|
|
190
|
+
if (mcpFile && mcpFile.content) {
|
|
191
|
+
const packKeyMatches = mcpFile.content.match(/"(\w[\w-]*)"\s*:/g) || [];
|
|
192
|
+
const detectedKeys = packKeyMatches.map(m => m.replace(/"/g, '').replace(':', '').trim());
|
|
193
|
+
mcpPreflightWarnings = getOpenCodeMcpPreflight(detectedKeys)
|
|
194
|
+
.filter(p => !p.safe)
|
|
195
|
+
.map(p => ({ key: p.key, label: p.label, warning: p.warning }));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
schemaVersion: 2,
|
|
201
|
+
generatedBy: `nerviq@${version}`,
|
|
202
|
+
createdAt: new Date().toISOString(),
|
|
203
|
+
platform: 'opencode',
|
|
204
|
+
directory: options.dir,
|
|
205
|
+
projectSummary: {
|
|
206
|
+
name: path.basename(options.dir),
|
|
207
|
+
score: auditResult.score,
|
|
208
|
+
organicScore: auditResult.organicScore,
|
|
209
|
+
maturity: maturityFromScore(auditResult.score),
|
|
210
|
+
domains: analysisReport.projectSummary.domains || [],
|
|
211
|
+
},
|
|
212
|
+
strengthsPreserved: auditResult.results
|
|
213
|
+
.filter((item) => item.passed === true)
|
|
214
|
+
.slice(0, 5)
|
|
215
|
+
.map((item) => item.name),
|
|
216
|
+
topNextActions: auditResult.topNextActions,
|
|
217
|
+
recommendedDomainPacks: domainPackGuidance,
|
|
218
|
+
proposalFamilies: [...new Set(proposals.map(p => p.id))],
|
|
219
|
+
optionalModules: analysisReport.optionalModules || [],
|
|
220
|
+
riskNotes: uniqueValues([
|
|
221
|
+
...(analysisReport.riskNotes || []),
|
|
222
|
+
...((auditResult.platformCaveats || []).map((item) => item.message)),
|
|
223
|
+
]),
|
|
224
|
+
mcpPreflightWarnings,
|
|
225
|
+
proposals,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
module.exports = {
|
|
230
|
+
buildOpenCodeProposalBundle,
|
|
231
|
+
};
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Premium Operator UX
|
|
3
|
+
*
|
|
4
|
+
* Three subsystems:
|
|
5
|
+
* 1. Multi-Pack Composition Engine — merge domain + MCP packs with dedup, conflict resolution
|
|
6
|
+
* 2. CI Template Library — 5 GitHub Actions workflow templates for OpenCode automation
|
|
7
|
+
* 3. Adoption Signal Gate — activate features based on local usage telemetry
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const { OPENCODE_DOMAIN_PACKS } = require('./domain-packs');
|
|
12
|
+
const { OPENCODE_MCP_PACKS } = require('./mcp-packs');
|
|
13
|
+
const { getOpenCodeHistory } = require('./activity');
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// 1. Multi-Pack Composition Engine
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
const PACK_DEPENDENCY_ORDER = [
|
|
20
|
+
'baseline-general',
|
|
21
|
+
'backend-api',
|
|
22
|
+
'frontend-ui',
|
|
23
|
+
'infra-platform',
|
|
24
|
+
'monorepo',
|
|
25
|
+
'enterprise-governed',
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const PACK_SPECIFICITY = {
|
|
29
|
+
'baseline-general': 0,
|
|
30
|
+
'backend-api': 2,
|
|
31
|
+
'frontend-ui': 2,
|
|
32
|
+
'infra-platform': 3,
|
|
33
|
+
'monorepo': 3,
|
|
34
|
+
'enterprise-governed': 4,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const DEFAULT_SIZE_BUDGET = 16000;
|
|
38
|
+
|
|
39
|
+
function lookupDomainPack(key) {
|
|
40
|
+
return OPENCODE_DOMAIN_PACKS.find(p => p.key === key) || null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function lookupMcpPack(key) {
|
|
44
|
+
return OPENCODE_MCP_PACKS.find(p => p.key === key) || null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function composePacks(domainPackKeys = [], mcpPackKeys = [], options = {}) {
|
|
48
|
+
const sizeBudget = options.sizeBudget || DEFAULT_SIZE_BUDGET;
|
|
49
|
+
const warnings = [];
|
|
50
|
+
|
|
51
|
+
// Resolve domain packs
|
|
52
|
+
const seenDomainKeys = new Set();
|
|
53
|
+
const rawDomainPacks = [];
|
|
54
|
+
for (const key of domainPackKeys) {
|
|
55
|
+
if (seenDomainKeys.has(key)) continue;
|
|
56
|
+
seenDomainKeys.add(key);
|
|
57
|
+
const pack = lookupDomainPack(key);
|
|
58
|
+
if (!pack) { warnings.push(`Domain pack "${key}" not found, skipped.`); continue; }
|
|
59
|
+
rawDomainPacks.push(pack);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
rawDomainPacks.sort((a, b) => {
|
|
63
|
+
const orderA = PACK_DEPENDENCY_ORDER.indexOf(a.key);
|
|
64
|
+
const orderB = PACK_DEPENDENCY_ORDER.indexOf(b.key);
|
|
65
|
+
return (orderA === -1 ? 99 : orderA) - (orderB === -1 ? 99 : orderB);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const moduleOwner = new Map();
|
|
69
|
+
for (const pack of rawDomainPacks) {
|
|
70
|
+
const specificity = PACK_SPECIFICITY[pack.key] ?? 1;
|
|
71
|
+
for (const mod of pack.recommendedModules || []) {
|
|
72
|
+
const existing = moduleOwner.get(mod);
|
|
73
|
+
if (!existing || specificity > existing.specificity) {
|
|
74
|
+
moduleOwner.set(mod, { key: pack.key, specificity });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const allSurfaces = new Set();
|
|
80
|
+
for (const pack of rawDomainPacks) {
|
|
81
|
+
for (const surface of pack.recommendedSurfaces || []) allSurfaces.add(surface);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const allProposalFamilies = new Set();
|
|
85
|
+
for (const pack of rawDomainPacks) {
|
|
86
|
+
for (const family of pack.recommendedProposalFamilies || []) allProposalFamilies.add(family);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Resolve MCP packs
|
|
90
|
+
const seenMcpKeys = new Set();
|
|
91
|
+
const resolvedMcpPacks = [];
|
|
92
|
+
for (const key of mcpPackKeys) {
|
|
93
|
+
if (seenMcpKeys.has(key)) continue;
|
|
94
|
+
seenMcpKeys.add(key);
|
|
95
|
+
const pack = lookupMcpPack(key);
|
|
96
|
+
if (!pack) { warnings.push(`MCP pack "${key}" not found, skipped.`); continue; }
|
|
97
|
+
resolvedMcpPacks.push(pack);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const mergedEnabledTools = new Set();
|
|
101
|
+
for (const pack of resolvedMcpPacks) {
|
|
102
|
+
for (const tool of pack.enabledTools || []) mergedEnabledTools.add(tool);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const mergedRequiredAuth = new Set();
|
|
106
|
+
for (const pack of resolvedMcpPacks) {
|
|
107
|
+
for (const auth of pack.requiredAuth || []) mergedRequiredAuth.add(auth);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const estimatedSize = estimateCompositionSize(rawDomainPacks, resolvedMcpPacks);
|
|
111
|
+
const overBudget = estimatedSize > sizeBudget;
|
|
112
|
+
if (overBudget) {
|
|
113
|
+
warnings.push(`Combined size (~${estimatedSize} chars) exceeds budget (${sizeBudget}). Consider removing lower-priority packs.`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
domainPacks: rawDomainPacks.map(p => ({
|
|
118
|
+
key: p.key,
|
|
119
|
+
label: p.label,
|
|
120
|
+
modulesOwned: [...moduleOwner.entries()].filter(([, owner]) => owner.key === p.key).map(([mod]) => mod),
|
|
121
|
+
})),
|
|
122
|
+
mcpPacks: resolvedMcpPacks.map(p => ({
|
|
123
|
+
key: p.key,
|
|
124
|
+
label: p.label,
|
|
125
|
+
serverName: p.serverName,
|
|
126
|
+
trustLevel: p.trustLevel,
|
|
127
|
+
})),
|
|
128
|
+
merged: {
|
|
129
|
+
surfaces: [...allSurfaces],
|
|
130
|
+
proposalFamilies: [...allProposalFamilies],
|
|
131
|
+
modules: [...moduleOwner.entries()].map(([mod, owner]) => ({ module: mod, owner: owner.key })),
|
|
132
|
+
enabledTools: [...mergedEnabledTools].sort(),
|
|
133
|
+
requiredAuth: [...mergedRequiredAuth].sort(),
|
|
134
|
+
},
|
|
135
|
+
budget: { estimatedSize, limit: sizeBudget, overBudget, utilization: Math.round((estimatedSize / sizeBudget) * 100) },
|
|
136
|
+
warnings,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function estimateCompositionSize(domainPacks, mcpPacks) {
|
|
141
|
+
let size = 0;
|
|
142
|
+
for (const pack of domainPacks) {
|
|
143
|
+
size += (pack.label || '').length + (pack.useWhen || '').length + (pack.adoption || '').length;
|
|
144
|
+
size += JSON.stringify(pack.recommendedModules || []).length;
|
|
145
|
+
size += JSON.stringify(pack.benchmarkFocus || []).length;
|
|
146
|
+
}
|
|
147
|
+
for (const pack of mcpPacks) {
|
|
148
|
+
size += (pack.label || '').length + (pack.description || '').length;
|
|
149
|
+
size += JSON.stringify(pack.jsoncProjection || {}).length;
|
|
150
|
+
size += JSON.stringify(pack.enabledTools || []).length;
|
|
151
|
+
}
|
|
152
|
+
return size;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
// 2. CI Template Library
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
|
|
159
|
+
const CI_TEMPLATES = [
|
|
160
|
+
{
|
|
161
|
+
key: 'opencode-pr-review',
|
|
162
|
+
label: 'OpenCode PR Review',
|
|
163
|
+
filename: 'opencode-pr-review.yml',
|
|
164
|
+
description: 'Runs OpenCode review on pull request diffs.',
|
|
165
|
+
trigger: 'pull_request',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
key: 'opencode-issue-triage',
|
|
169
|
+
label: 'OpenCode Issue Triage',
|
|
170
|
+
filename: 'opencode-issue-triage.yml',
|
|
171
|
+
description: 'Classifies and labels new issues using OpenCode.',
|
|
172
|
+
trigger: 'issues.opened',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
key: 'opencode-scheduled-audit',
|
|
176
|
+
label: 'OpenCode Scheduled Audit',
|
|
177
|
+
filename: 'opencode-scheduled-audit.yml',
|
|
178
|
+
description: 'Weekly deep review of the codebase with OpenCode.',
|
|
179
|
+
trigger: 'schedule (cron)',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
key: 'opencode-test-gen',
|
|
183
|
+
label: 'OpenCode Test Generation',
|
|
184
|
+
filename: 'opencode-test-gen.yml',
|
|
185
|
+
description: 'Generates test stubs for newly added files.',
|
|
186
|
+
trigger: 'pull_request',
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
key: 'opencode-docs-sync',
|
|
190
|
+
label: 'OpenCode Docs Sync',
|
|
191
|
+
filename: 'opencode-docs-sync.yml',
|
|
192
|
+
description: 'Checks for documentation staleness.',
|
|
193
|
+
trigger: 'schedule (cron)',
|
|
194
|
+
},
|
|
195
|
+
];
|
|
196
|
+
|
|
197
|
+
const TEMPLATE_CONTENT = {
|
|
198
|
+
'opencode-pr-review': `# OpenCode PR Review — generated by nerviq
|
|
199
|
+
name: OpenCode PR Review
|
|
200
|
+
|
|
201
|
+
on:
|
|
202
|
+
pull_request:
|
|
203
|
+
types: [opened, synchronize]
|
|
204
|
+
|
|
205
|
+
permissions:
|
|
206
|
+
contents: read
|
|
207
|
+
pull-requests: write
|
|
208
|
+
|
|
209
|
+
env:
|
|
210
|
+
OPENCODE_DISABLE_AUTOUPDATE: "1"
|
|
211
|
+
|
|
212
|
+
jobs:
|
|
213
|
+
opencode-review:
|
|
214
|
+
runs-on: ubuntu-latest
|
|
215
|
+
timeout-minutes: 15
|
|
216
|
+
env:
|
|
217
|
+
ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
|
|
218
|
+
steps:
|
|
219
|
+
- uses: actions/checkout@v4
|
|
220
|
+
with:
|
|
221
|
+
fetch-depth: 0
|
|
222
|
+
- name: Install OpenCode
|
|
223
|
+
run: npm install -g opencode
|
|
224
|
+
- name: Run Review
|
|
225
|
+
run: |
|
|
226
|
+
DIFF=$(git diff \${{ github.event.pull_request.base.sha }}..\${{ github.sha }})
|
|
227
|
+
echo "$DIFF" | opencode run --format json "Review this diff"
|
|
228
|
+
`,
|
|
229
|
+
|
|
230
|
+
'opencode-issue-triage': `# OpenCode Issue Triage — generated by nerviq
|
|
231
|
+
name: OpenCode Issue Triage
|
|
232
|
+
|
|
233
|
+
on:
|
|
234
|
+
issues:
|
|
235
|
+
types: [opened]
|
|
236
|
+
|
|
237
|
+
permissions:
|
|
238
|
+
issues: write
|
|
239
|
+
|
|
240
|
+
env:
|
|
241
|
+
OPENCODE_DISABLE_AUTOUPDATE: "1"
|
|
242
|
+
|
|
243
|
+
jobs:
|
|
244
|
+
triage:
|
|
245
|
+
runs-on: ubuntu-latest
|
|
246
|
+
timeout-minutes: 5
|
|
247
|
+
env:
|
|
248
|
+
ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
|
|
249
|
+
steps:
|
|
250
|
+
- uses: actions/checkout@v4
|
|
251
|
+
- name: Install OpenCode
|
|
252
|
+
run: npm install -g opencode
|
|
253
|
+
- name: Classify Issue
|
|
254
|
+
run: |
|
|
255
|
+
opencode run --format json "Classify this issue: \${{ github.event.issue.title }}"
|
|
256
|
+
`,
|
|
257
|
+
|
|
258
|
+
'opencode-scheduled-audit': `# OpenCode Scheduled Audit — generated by nerviq
|
|
259
|
+
name: OpenCode Scheduled Audit
|
|
260
|
+
|
|
261
|
+
on:
|
|
262
|
+
schedule:
|
|
263
|
+
- cron: '0 9 * * 1'
|
|
264
|
+
workflow_dispatch: {}
|
|
265
|
+
|
|
266
|
+
permissions:
|
|
267
|
+
contents: read
|
|
268
|
+
issues: write
|
|
269
|
+
|
|
270
|
+
env:
|
|
271
|
+
OPENCODE_DISABLE_AUTOUPDATE: "1"
|
|
272
|
+
|
|
273
|
+
jobs:
|
|
274
|
+
audit:
|
|
275
|
+
runs-on: ubuntu-latest
|
|
276
|
+
timeout-minutes: 30
|
|
277
|
+
env:
|
|
278
|
+
ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
|
|
279
|
+
steps:
|
|
280
|
+
- uses: actions/checkout@v4
|
|
281
|
+
with:
|
|
282
|
+
fetch-depth: 0
|
|
283
|
+
- name: Install OpenCode
|
|
284
|
+
run: npm install -g opencode
|
|
285
|
+
- name: Run Audit
|
|
286
|
+
run: opencode run --format json "Run a deep code quality audit"
|
|
287
|
+
`,
|
|
288
|
+
|
|
289
|
+
'opencode-test-gen': `# OpenCode Test Generation — generated by nerviq
|
|
290
|
+
name: OpenCode Test Generation
|
|
291
|
+
|
|
292
|
+
on:
|
|
293
|
+
pull_request:
|
|
294
|
+
types: [opened, synchronize]
|
|
295
|
+
|
|
296
|
+
permissions:
|
|
297
|
+
contents: read
|
|
298
|
+
pull-requests: write
|
|
299
|
+
|
|
300
|
+
env:
|
|
301
|
+
OPENCODE_DISABLE_AUTOUPDATE: "1"
|
|
302
|
+
|
|
303
|
+
jobs:
|
|
304
|
+
test-gen:
|
|
305
|
+
runs-on: ubuntu-latest
|
|
306
|
+
timeout-minutes: 10
|
|
307
|
+
env:
|
|
308
|
+
ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
|
|
309
|
+
steps:
|
|
310
|
+
- uses: actions/checkout@v4
|
|
311
|
+
with:
|
|
312
|
+
fetch-depth: 0
|
|
313
|
+
- name: Install OpenCode
|
|
314
|
+
run: npm install -g opencode
|
|
315
|
+
- name: Generate Tests
|
|
316
|
+
run: |
|
|
317
|
+
FILES=$(git diff --name-only --diff-filter=A \${{ github.event.pull_request.base.sha }}..\${{ github.sha }})
|
|
318
|
+
for file in $FILES; do
|
|
319
|
+
opencode run --format json "Generate tests for $file"
|
|
320
|
+
done
|
|
321
|
+
`,
|
|
322
|
+
|
|
323
|
+
'opencode-docs-sync': `# OpenCode Docs Sync — generated by nerviq
|
|
324
|
+
name: OpenCode Docs Sync
|
|
325
|
+
|
|
326
|
+
on:
|
|
327
|
+
schedule:
|
|
328
|
+
- cron: '0 10 * * 3'
|
|
329
|
+
workflow_dispatch: {}
|
|
330
|
+
|
|
331
|
+
permissions:
|
|
332
|
+
contents: read
|
|
333
|
+
issues: write
|
|
334
|
+
|
|
335
|
+
env:
|
|
336
|
+
OPENCODE_DISABLE_AUTOUPDATE: "1"
|
|
337
|
+
|
|
338
|
+
jobs:
|
|
339
|
+
docs-check:
|
|
340
|
+
runs-on: ubuntu-latest
|
|
341
|
+
timeout-minutes: 10
|
|
342
|
+
env:
|
|
343
|
+
ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
|
|
344
|
+
steps:
|
|
345
|
+
- uses: actions/checkout@v4
|
|
346
|
+
with:
|
|
347
|
+
fetch-depth: 0
|
|
348
|
+
- name: Install OpenCode
|
|
349
|
+
run: npm install -g opencode
|
|
350
|
+
- name: Check Staleness
|
|
351
|
+
run: opencode run --format json "Check documentation freshness for README.md and docs/"
|
|
352
|
+
`,
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
function getCiTemplate(templateKey) {
|
|
356
|
+
const meta = CI_TEMPLATES.find(t => t.key === templateKey);
|
|
357
|
+
if (!meta) return null;
|
|
358
|
+
return TEMPLATE_CONTENT[templateKey] || null;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// ---------------------------------------------------------------------------
|
|
362
|
+
// 3. Adoption Signal Gate
|
|
363
|
+
// ---------------------------------------------------------------------------
|
|
364
|
+
|
|
365
|
+
const GATE_THRESHOLDS = {
|
|
366
|
+
'ci-templates': { metric: 'auditCount', threshold: 3, description: 'Activate CI templates after 3+ audits.' },
|
|
367
|
+
'mcp-advanced': { metric: 'auditCount', threshold: 5, description: 'Activate advanced MCP packs after 5+ audits.' },
|
|
368
|
+
'multi-pack': { metric: 'auditCount', threshold: 2, description: 'Activate multi-pack composition after 2+ audits.' },
|
|
369
|
+
'trend-reports': { metric: 'auditCount', threshold: 3, description: 'Activate trend reports after 3+ snapshots.' },
|
|
370
|
+
'governance-upgrade': { metric: 'averageScore', threshold: 70, description: 'Suggest governance upgrade when average score > 70.' },
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
function checkAdoptionGate(gateKey, dir) {
|
|
374
|
+
const gate = GATE_THRESHOLDS[gateKey];
|
|
375
|
+
if (!gate) {
|
|
376
|
+
return { activated: false, current: 0, threshold: 0, gate: gateKey, description: `Unknown gate "${gateKey}".` };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const history = getOpenCodeHistory(dir, 100);
|
|
380
|
+
let current = 0;
|
|
381
|
+
|
|
382
|
+
switch (gate.metric) {
|
|
383
|
+
case 'auditCount':
|
|
384
|
+
current = history.length;
|
|
385
|
+
break;
|
|
386
|
+
case 'averageScore': {
|
|
387
|
+
const scores = history.map(e => e.summary?.score).filter(s => typeof s === 'number');
|
|
388
|
+
current = scores.length > 0 ? Math.round(scores.reduce((a, b) => a + b, 0) / scores.length) : 0;
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
default:
|
|
392
|
+
current = 0;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return {
|
|
396
|
+
activated: current >= gate.threshold,
|
|
397
|
+
current,
|
|
398
|
+
threshold: gate.threshold,
|
|
399
|
+
gate: gateKey,
|
|
400
|
+
description: gate.description,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
module.exports = {
|
|
405
|
+
composePacks,
|
|
406
|
+
getCiTemplate,
|
|
407
|
+
CI_TEMPLATES,
|
|
408
|
+
checkAdoptionGate,
|
|
409
|
+
GATE_THRESHOLDS,
|
|
410
|
+
PACK_DEPENDENCY_ORDER,
|
|
411
|
+
PACK_SPECIFICITY,
|
|
412
|
+
DEFAULT_SIZE_BUDGET,
|
|
413
|
+
};
|