@nerviq/cli 0.0.1 → 0.9.0-beta.2
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,603 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const { version } = require('../../package.json');
|
|
5
|
+
const { STACKS } = require('../techniques');
|
|
6
|
+
const { writeActivityArtifact, writeRollbackArtifact } = require('../activity');
|
|
7
|
+
const { CodexProjectContext } = require('./context');
|
|
8
|
+
const { recommendCodexMcpPacks, packsToToml } = require('./mcp-packs');
|
|
9
|
+
|
|
10
|
+
function detectScripts(ctx) {
|
|
11
|
+
const pkg = ctx.jsonFile('package.json');
|
|
12
|
+
if (!pkg || !pkg.scripts) return {};
|
|
13
|
+
return pkg.scripts;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function detectProjectName(ctx) {
|
|
17
|
+
const pkg = ctx.jsonFile('package.json');
|
|
18
|
+
if (pkg && pkg.name) return pkg.name;
|
|
19
|
+
return path.basename(ctx.dir);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function hasStack(stacks, key) {
|
|
23
|
+
return stacks.some((item) => item.key === key);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function buildMermaid(stacks) {
|
|
27
|
+
if (hasStack(stacks, 'nextjs')) {
|
|
28
|
+
return [
|
|
29
|
+
'```mermaid',
|
|
30
|
+
'graph TD',
|
|
31
|
+
' UI[App Router / Pages] --> Logic[Server Actions or API Routes]',
|
|
32
|
+
' Logic --> Data[Data Layer]',
|
|
33
|
+
' Data --> External[External Services / DB]',
|
|
34
|
+
'```',
|
|
35
|
+
].join('\n');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (hasStack(stacks, 'fastapi') || hasStack(stacks, 'django') || hasStack(stacks, 'python')) {
|
|
39
|
+
return [
|
|
40
|
+
'```mermaid',
|
|
41
|
+
'graph TD',
|
|
42
|
+
' API[API / CLI Entry] --> Services[Service Layer]',
|
|
43
|
+
' Services --> Models[Models / Schemas]',
|
|
44
|
+
' Models --> Data[Database or External APIs]',
|
|
45
|
+
'```',
|
|
46
|
+
].join('\n');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (hasStack(stacks, 'go')) {
|
|
50
|
+
return [
|
|
51
|
+
'```mermaid',
|
|
52
|
+
'graph TD',
|
|
53
|
+
' Cmd[cmd/ or main package] --> Internal[internal/ packages]',
|
|
54
|
+
' Internal --> Data[Storage / APIs]',
|
|
55
|
+
'```',
|
|
56
|
+
].join('\n');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (hasStack(stacks, 'rust')) {
|
|
60
|
+
return [
|
|
61
|
+
'```mermaid',
|
|
62
|
+
'graph TD',
|
|
63
|
+
' Bin[src/main.rs] --> Core[src/lib.rs]',
|
|
64
|
+
' Core --> Modules[domain / adapters / services]',
|
|
65
|
+
'```',
|
|
66
|
+
].join('\n');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return [
|
|
70
|
+
'```mermaid',
|
|
71
|
+
'graph TD',
|
|
72
|
+
' Entry[Entry Point] --> Core[Core Logic]',
|
|
73
|
+
' Core --> Data[Data / External Services]',
|
|
74
|
+
'```',
|
|
75
|
+
].join('\n');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function buildVerificationCommands(ctx) {
|
|
79
|
+
const scripts = detectScripts(ctx);
|
|
80
|
+
const commands = [];
|
|
81
|
+
|
|
82
|
+
if (scripts.test) commands.push(`- Test: \`npm test\``);
|
|
83
|
+
if (scripts.lint) commands.push(`- Lint: \`npm run lint\``);
|
|
84
|
+
if (scripts.build) commands.push(`- Build: \`npm run build\``);
|
|
85
|
+
|
|
86
|
+
if (commands.length === 0 && ctx.fileContent('pyproject.toml')) {
|
|
87
|
+
commands.push('- Test: `python -m pytest`');
|
|
88
|
+
}
|
|
89
|
+
if (commands.length === 0 && ctx.fileContent('requirements.txt')) {
|
|
90
|
+
commands.push('- Test: `python -m pytest`');
|
|
91
|
+
}
|
|
92
|
+
if (commands.length === 0 && ctx.fileContent('go.mod')) {
|
|
93
|
+
commands.push('- Test: `go test ./...`');
|
|
94
|
+
commands.push('- Build: `go build ./...`');
|
|
95
|
+
}
|
|
96
|
+
if (commands.length === 0 && ctx.fileContent('Cargo.toml')) {
|
|
97
|
+
commands.push('- Test: `cargo test`');
|
|
98
|
+
commands.push('- Build: `cargo build`');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (commands.length === 0) {
|
|
102
|
+
commands.push('- Test: add the repo test command');
|
|
103
|
+
commands.push('- Lint: add the repo lint command');
|
|
104
|
+
commands.push('- Build: add the repo build command');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return commands;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function buildCodingConventions(stacks) {
|
|
111
|
+
const lines = [];
|
|
112
|
+
|
|
113
|
+
if (hasStack(stacks, 'typescript')) {
|
|
114
|
+
lines.push('- Keep TypeScript strict and prefer typed boundaries over implicit `any`.');
|
|
115
|
+
}
|
|
116
|
+
if (hasStack(stacks, 'react') || hasStack(stacks, 'nextjs')) {
|
|
117
|
+
lines.push('- Prefer small, reviewable component changes and document risky UI state assumptions before refactors.');
|
|
118
|
+
}
|
|
119
|
+
if (hasStack(stacks, 'python') || hasStack(stacks, 'fastapi') || hasStack(stacks, 'django')) {
|
|
120
|
+
lines.push('- Prefer explicit validation, typed schemas, and focused service functions over large route handlers.');
|
|
121
|
+
}
|
|
122
|
+
if (hasStack(stacks, 'go')) {
|
|
123
|
+
lines.push('- Keep packages small, avoid cross-package cycles, and prefer table-driven tests.');
|
|
124
|
+
}
|
|
125
|
+
if (hasStack(stacks, 'rust')) {
|
|
126
|
+
lines.push('- Prefer explicit ownership-safe refactors and small module-scoped changes over broad rewrites.');
|
|
127
|
+
}
|
|
128
|
+
if (hasStack(stacks, 'terraform') || hasStack(stacks, 'kubernetes')) {
|
|
129
|
+
lines.push('- Treat infrastructure changes as high-risk: prefer diffs that are easy to plan, review, and roll back.');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (lines.length === 0) {
|
|
133
|
+
lines.push('- Prefer small, reviewable diffs and explicit reasoning over broad rewrites.');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return lines;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function buildSecurityNotes(stacks) {
|
|
140
|
+
const lines = [
|
|
141
|
+
'- Never commit secrets, tokens, or `.env` values into tracked files.',
|
|
142
|
+
'- Prefer the repo verification commands before handoff, and explain any command you could not run.',
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
if (hasStack(stacks, 'python') || hasStack(stacks, 'fastapi') || hasStack(stacks, 'django')) {
|
|
146
|
+
lines.push('- Validate auth, permissions, and data-handling changes carefully before touching production-sensitive paths.');
|
|
147
|
+
}
|
|
148
|
+
if (hasStack(stacks, 'terraform') || hasStack(stacks, 'kubernetes')) {
|
|
149
|
+
lines.push('- Review blast radius before changing infra, deployment, or cluster configuration.');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return lines;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function buildAgentsMd(ctx, stacks) {
|
|
156
|
+
const stackLabels = stacks.map((item) => item.label).join(', ') || 'General repo';
|
|
157
|
+
const verificationCommands = buildVerificationCommands(ctx);
|
|
158
|
+
const codingConventions = buildCodingConventions(stacks);
|
|
159
|
+
const securityNotes = buildSecurityNotes(stacks);
|
|
160
|
+
|
|
161
|
+
return [
|
|
162
|
+
`# ${detectProjectName(ctx)}`,
|
|
163
|
+
'',
|
|
164
|
+
'## Scope',
|
|
165
|
+
'- Primary platform: Codex CLI',
|
|
166
|
+
`- Detected stack: ${stackLabels}`,
|
|
167
|
+
'- Keep this file focused on Codex-specific guidance when the repo also uses Claude or other agents.',
|
|
168
|
+
'',
|
|
169
|
+
'## Architecture',
|
|
170
|
+
buildMermaid(stacks),
|
|
171
|
+
'- Replace the default diagram and bullets with the real entry points, boundaries, and high-risk subsystems for this repo.',
|
|
172
|
+
'',
|
|
173
|
+
'## Verification',
|
|
174
|
+
...verificationCommands,
|
|
175
|
+
'',
|
|
176
|
+
'## Coding Conventions',
|
|
177
|
+
...codingConventions,
|
|
178
|
+
'',
|
|
179
|
+
'## Review Workflow',
|
|
180
|
+
'- Use `codex review --uncommitted` before handoff on risky diffs or broad refactors.',
|
|
181
|
+
'- Explain which verification commands ran successfully and which were skipped.',
|
|
182
|
+
'- Keep working-tree expectations explicit: do not silently mix unrelated edits into the same handoff.',
|
|
183
|
+
'',
|
|
184
|
+
'## Security',
|
|
185
|
+
...securityNotes,
|
|
186
|
+
'',
|
|
187
|
+
'## Cost & Automation',
|
|
188
|
+
'- Reserve heavy reasoning or long automation chains for tasks that actually need them.',
|
|
189
|
+
'- Test Codex automation manually or in workflow_dispatch before turning it into a scheduled workflow.',
|
|
190
|
+
'',
|
|
191
|
+
'## Notes',
|
|
192
|
+
'- If this repo also uses Claude, keep Claude-specific instructions in `CLAUDE.md` and use AGENTS.md for Codex-native behavior.',
|
|
193
|
+
'- If you add repo-local skills, place them under `.agents/skills/<skill-name>/SKILL.md` and keep names kebab-case.',
|
|
194
|
+
'- If you add custom agents, keep them under `.codex/agents/*.toml` with narrow sandbox overrides.',
|
|
195
|
+
'',
|
|
196
|
+
`_Generated by nerviq v${version} for Codex. Customize this file before relying on it in production flows._`,
|
|
197
|
+
'',
|
|
198
|
+
].join('\n');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function buildConfigToml() {
|
|
202
|
+
return [
|
|
203
|
+
'profile = "safe"',
|
|
204
|
+
'model = "gpt-5.4"',
|
|
205
|
+
'model_reasoning_effort = "medium"',
|
|
206
|
+
'model_for_weak_tasks = "gpt-5.4-mini"',
|
|
207
|
+
'approval_policy = "on-request"',
|
|
208
|
+
'sandbox_mode = "workspace-write"',
|
|
209
|
+
'full_auto_error_mode = "ask-user"',
|
|
210
|
+
'project_doc_fallback_filenames = ["AGENTS.md"]',
|
|
211
|
+
'',
|
|
212
|
+
'[profiles.safe]',
|
|
213
|
+
'approval_policy = "on-request"',
|
|
214
|
+
'sandbox_mode = "workspace-write"',
|
|
215
|
+
'',
|
|
216
|
+
'[features]',
|
|
217
|
+
'codex_hooks = false',
|
|
218
|
+
'undo = false',
|
|
219
|
+
'',
|
|
220
|
+
'[history]',
|
|
221
|
+
'send_to_server = false',
|
|
222
|
+
'',
|
|
223
|
+
'[sandbox_workspace_write]',
|
|
224
|
+
'network_access = false',
|
|
225
|
+
'',
|
|
226
|
+
'[agents]',
|
|
227
|
+
'max_threads = 4',
|
|
228
|
+
'max_depth = 2',
|
|
229
|
+
'',
|
|
230
|
+
].join('\n');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function buildCodexSetupFiles(options = {}) {
|
|
234
|
+
const ctx = new CodexProjectContext(options.dir);
|
|
235
|
+
const stacks = ctx.detectStacks(STACKS);
|
|
236
|
+
const files = [];
|
|
237
|
+
|
|
238
|
+
const agentsPath = path.join(options.dir, 'AGENTS.md');
|
|
239
|
+
if (!fs.existsSync(agentsPath)) {
|
|
240
|
+
files.push({
|
|
241
|
+
path: 'AGENTS.md',
|
|
242
|
+
action: 'create',
|
|
243
|
+
content: buildAgentsMd(ctx, stacks),
|
|
244
|
+
currentState: 'AGENTS.md is missing',
|
|
245
|
+
proposedState: 'create a Codex-native AGENTS.md baseline with verification, architecture, review, and trust guidance',
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const configPath = path.join(options.dir, '.codex', 'config.toml');
|
|
250
|
+
if (!fs.existsSync(configPath)) {
|
|
251
|
+
files.push({
|
|
252
|
+
path: '.codex/config.toml',
|
|
253
|
+
action: 'create',
|
|
254
|
+
content: buildConfigToml(),
|
|
255
|
+
currentState: '.codex/config.toml is missing',
|
|
256
|
+
proposedState: 'create a safe Codex baseline config with explicit approvals, sandbox, history, network, and agents settings',
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// --- CP-04: Optional setup families ---
|
|
261
|
+
const modules = options.modules || 'all';
|
|
262
|
+
const wantModule = (name) => modules === 'all' || (Array.isArray(modules) && modules.includes(name));
|
|
263
|
+
|
|
264
|
+
// Rules starter
|
|
265
|
+
if (wantModule('rules')) {
|
|
266
|
+
const rulesDir = path.join(options.dir, '.codex', 'rules');
|
|
267
|
+
const rulesReadme = path.join(rulesDir, 'README.md');
|
|
268
|
+
if (!fs.existsSync(rulesReadme)) {
|
|
269
|
+
files.push({
|
|
270
|
+
path: '.codex/rules/README.md',
|
|
271
|
+
action: 'create',
|
|
272
|
+
family: 'codex-rules',
|
|
273
|
+
content: buildRulesStarter(),
|
|
274
|
+
currentState: '.codex/rules/ directory is missing or empty',
|
|
275
|
+
proposedState: 'create a Codex rules starter with guidance on writing sandbox-escape rules',
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Hooks scaffold (skip on Windows)
|
|
281
|
+
if (wantModule('hooks') && os.platform() !== 'win32') {
|
|
282
|
+
const hooksPath = path.join(options.dir, '.codex', 'hooks.json');
|
|
283
|
+
if (!fs.existsSync(hooksPath)) {
|
|
284
|
+
files.push({
|
|
285
|
+
path: '.codex/hooks.json',
|
|
286
|
+
action: 'create',
|
|
287
|
+
family: 'codex-hooks',
|
|
288
|
+
content: buildHooksStarter(),
|
|
289
|
+
currentState: '.codex/hooks.json is missing',
|
|
290
|
+
proposedState: 'create a Codex hooks scaffold with SessionStart example',
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Skills starter
|
|
296
|
+
if (wantModule('skills')) {
|
|
297
|
+
const skillsDir = path.join(options.dir, '.agents', 'skills');
|
|
298
|
+
const skillsReadme = path.join(skillsDir, 'README.md');
|
|
299
|
+
if (!fs.existsSync(skillsReadme) && !fs.existsSync(skillsDir)) {
|
|
300
|
+
files.push({
|
|
301
|
+
path: '.agents/skills/README.md',
|
|
302
|
+
action: 'create',
|
|
303
|
+
family: 'codex-skills',
|
|
304
|
+
content: buildSkillsStarter(),
|
|
305
|
+
currentState: '.agents/skills/ directory is missing',
|
|
306
|
+
proposedState: 'create a Codex skills starter with SKILL.md conventions and kebab-case naming guidance',
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Subagents starter
|
|
312
|
+
if (wantModule('subagents')) {
|
|
313
|
+
const agentsDir = path.join(options.dir, '.codex', 'agents');
|
|
314
|
+
if (!fs.existsSync(agentsDir)) {
|
|
315
|
+
files.push({
|
|
316
|
+
path: '.codex/agents/README.md',
|
|
317
|
+
action: 'create',
|
|
318
|
+
family: 'codex-subagents',
|
|
319
|
+
content: buildSubagentsStarter(),
|
|
320
|
+
currentState: '.codex/agents/ directory is missing',
|
|
321
|
+
proposedState: 'create a Codex custom agents starter with TOML conventions',
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// MCP starter
|
|
327
|
+
if (wantModule('mcp')) {
|
|
328
|
+
const configContent = ctx.configContent ? ctx.configContent() : '';
|
|
329
|
+
const hasMcpSection = configContent && /\[mcp_servers\./i.test(configContent);
|
|
330
|
+
if (!hasMcpSection) {
|
|
331
|
+
const domainPacks = options.domainPacks || [];
|
|
332
|
+
const mcpRecs = recommendCodexMcpPacks(stacks, domainPacks, { ctx });
|
|
333
|
+
if (mcpRecs.length > 0) {
|
|
334
|
+
const mcpToml = packsToToml(mcpRecs.map(p => p.key));
|
|
335
|
+
files.push({
|
|
336
|
+
path: '.codex/config.toml (MCP append)',
|
|
337
|
+
action: 'append',
|
|
338
|
+
family: 'codex-mcp',
|
|
339
|
+
content: mcpToml,
|
|
340
|
+
currentState: 'No MCP servers configured in .codex/config.toml',
|
|
341
|
+
proposedState: `add ${mcpRecs.length} recommended MCP packs: ${mcpRecs.map(p => p.label).join(', ')}`,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// CI / Review workflow starter
|
|
348
|
+
if (wantModule('ci')) {
|
|
349
|
+
const workflowDir = path.join(options.dir, '.github', 'workflows');
|
|
350
|
+
const codexWorkflow = path.join(workflowDir, 'codex-review.yml');
|
|
351
|
+
if (!fs.existsSync(codexWorkflow)) {
|
|
352
|
+
files.push({
|
|
353
|
+
path: '.github/workflows/codex-review.yml',
|
|
354
|
+
action: 'create',
|
|
355
|
+
family: 'codex-ci-review',
|
|
356
|
+
content: buildCiReviewStarter(),
|
|
357
|
+
currentState: 'No Codex CI review workflow exists',
|
|
358
|
+
proposedState: 'create a GitHub Actions workflow for Codex-based PR review',
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return { ctx, stacks, files };
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// --- New starter builders for CP-04 ---
|
|
367
|
+
|
|
368
|
+
function buildRulesStarter() {
|
|
369
|
+
return [
|
|
370
|
+
'# Codex Rules',
|
|
371
|
+
'',
|
|
372
|
+
'Place rule files in this directory to control Codex sandbox-escape behavior.',
|
|
373
|
+
'',
|
|
374
|
+
'## Rule format',
|
|
375
|
+
'',
|
|
376
|
+
'Each rule file should be a `.md` file with:',
|
|
377
|
+
'- A clear description of what commands the rule allows',
|
|
378
|
+
'- `match` examples showing commands that should be allowed',
|
|
379
|
+
'- `not_match` examples showing commands that should be blocked',
|
|
380
|
+
'',
|
|
381
|
+
'## Example rule',
|
|
382
|
+
'',
|
|
383
|
+
'```markdown',
|
|
384
|
+
'# Allow npm commands',
|
|
385
|
+
'',
|
|
386
|
+
'Allow npm and npx commands for package management.',
|
|
387
|
+
'',
|
|
388
|
+
'- match: `npm install`',
|
|
389
|
+
'- match: `npx jest`',
|
|
390
|
+
'- not_match: `npm publish` (requires manual approval)',
|
|
391
|
+
'```',
|
|
392
|
+
'',
|
|
393
|
+
'## Best practices',
|
|
394
|
+
'',
|
|
395
|
+
'- Use specific patterns, not wildcards',
|
|
396
|
+
'- Document the reason for each allowed command class',
|
|
397
|
+
'- Review rules when adding new workflow surfaces',
|
|
398
|
+
'',
|
|
399
|
+
`_Generated by nerviq v${version}_`,
|
|
400
|
+
'',
|
|
401
|
+
].join('\n');
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function buildHooksStarter() {
|
|
405
|
+
return JSON.stringify({
|
|
406
|
+
"$schema": "https://docs.codex.ai/hooks-schema.json",
|
|
407
|
+
"hooks": [
|
|
408
|
+
{
|
|
409
|
+
"event": "SessionStart",
|
|
410
|
+
"command": "echo 'Codex session started'",
|
|
411
|
+
"description": "Example SessionStart hook — customize or remove",
|
|
412
|
+
"timeout_ms": 5000,
|
|
413
|
+
}
|
|
414
|
+
]
|
|
415
|
+
}, null, 2) + '\n';
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function buildSkillsStarter() {
|
|
419
|
+
return [
|
|
420
|
+
'# Codex Skills',
|
|
421
|
+
'',
|
|
422
|
+
'Place skill directories here. Each skill needs a `SKILL.md` file.',
|
|
423
|
+
'',
|
|
424
|
+
'## Directory structure',
|
|
425
|
+
'',
|
|
426
|
+
'```',
|
|
427
|
+
'.agents/skills/',
|
|
428
|
+
' my-skill/',
|
|
429
|
+
' SKILL.md # Required: name, description, instructions',
|
|
430
|
+
' helpers.js # Optional: supporting files',
|
|
431
|
+
'```',
|
|
432
|
+
'',
|
|
433
|
+
'## SKILL.md format',
|
|
434
|
+
'',
|
|
435
|
+
'```markdown',
|
|
436
|
+
'---',
|
|
437
|
+
'name: my-skill',
|
|
438
|
+
'description: Short description for implicit invocation',
|
|
439
|
+
'---',
|
|
440
|
+
'',
|
|
441
|
+
'# My Skill',
|
|
442
|
+
'',
|
|
443
|
+
'Instructions for Codex when this skill is invoked.',
|
|
444
|
+
'```',
|
|
445
|
+
'',
|
|
446
|
+
'## Critical naming rules',
|
|
447
|
+
'',
|
|
448
|
+
'- Use **kebab-case** for skill directory names (e.g., `code-review`, not `CodeReview`)',
|
|
449
|
+
'- PascalCase names have 0% implicit invocation success rate',
|
|
450
|
+
'- Keep descriptions short for bounded context cost',
|
|
451
|
+
'',
|
|
452
|
+
`_Generated by nerviq v${version}_`,
|
|
453
|
+
'',
|
|
454
|
+
].join('\n');
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function buildSubagentsStarter() {
|
|
458
|
+
return [
|
|
459
|
+
'# Codex Custom Agents',
|
|
460
|
+
'',
|
|
461
|
+
'Place custom agent TOML files here.',
|
|
462
|
+
'',
|
|
463
|
+
'## Format',
|
|
464
|
+
'',
|
|
465
|
+
'```toml',
|
|
466
|
+
'name = "my-agent"',
|
|
467
|
+
'description = "What this agent does"',
|
|
468
|
+
'developer_instructions = "Detailed instructions for the agent"',
|
|
469
|
+
'',
|
|
470
|
+
'[sandbox]',
|
|
471
|
+
'mode = "workspace-write"',
|
|
472
|
+
'```',
|
|
473
|
+
'',
|
|
474
|
+
'## Configuration notes',
|
|
475
|
+
'',
|
|
476
|
+
'- `max_threads` is hardcoded at 6 (system ceiling)',
|
|
477
|
+
'- `max_depth` defaults to 1 — increase only with justification',
|
|
478
|
+
'- Per-agent sandbox overrides should be as narrow as possible',
|
|
479
|
+
'- Cloud tasks run in a different trust class than local CLI',
|
|
480
|
+
'',
|
|
481
|
+
`_Generated by nerviq v${version}_`,
|
|
482
|
+
'',
|
|
483
|
+
].join('\n');
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function buildCiReviewStarter() {
|
|
487
|
+
return [
|
|
488
|
+
'name: Codex Review',
|
|
489
|
+
'',
|
|
490
|
+
'on:',
|
|
491
|
+
' pull_request:',
|
|
492
|
+
' types: [opened, synchronize]',
|
|
493
|
+
'',
|
|
494
|
+
'permissions:',
|
|
495
|
+
' contents: read',
|
|
496
|
+
' pull-requests: write',
|
|
497
|
+
'',
|
|
498
|
+
'jobs:',
|
|
499
|
+
' codex-review:',
|
|
500
|
+
' runs-on: ubuntu-latest',
|
|
501
|
+
' steps:',
|
|
502
|
+
' - uses: actions/checkout@v4',
|
|
503
|
+
' - name: Codex Review',
|
|
504
|
+
' uses: openai/codex-action@v1',
|
|
505
|
+
' with:',
|
|
506
|
+
' safety-strategy: review-only',
|
|
507
|
+
' env:',
|
|
508
|
+
' CODEX_API_KEY: ${{ secrets.CODEX_API_KEY }}',
|
|
509
|
+
].join('\n') + '\n';
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
async function setupCodex(options) {
|
|
513
|
+
const silent = options.silent === true;
|
|
514
|
+
const { ctx, stacks, files } = buildCodexSetupFiles(options);
|
|
515
|
+
const writtenFiles = [];
|
|
516
|
+
const preservedFiles = [];
|
|
517
|
+
|
|
518
|
+
function log(message = '') {
|
|
519
|
+
if (!silent) {
|
|
520
|
+
console.log(message);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
log('');
|
|
525
|
+
log('\x1b[1m nerviq codex setup\x1b[0m');
|
|
526
|
+
log('\x1b[2m ═══════════════════════════════════════\x1b[0m');
|
|
527
|
+
if (stacks.length > 0) {
|
|
528
|
+
log(`\x1b[36m Detected: ${stacks.map((s) => s.label).join(', ')}\x1b[0m`);
|
|
529
|
+
}
|
|
530
|
+
log('');
|
|
531
|
+
|
|
532
|
+
for (const file of files) {
|
|
533
|
+
const fullPath = path.join(options.dir, file.path);
|
|
534
|
+
if (fs.existsSync(fullPath)) {
|
|
535
|
+
preservedFiles.push(file.path);
|
|
536
|
+
log(` \x1b[2m⏭️ Skipped ${file.path} (already exists — your version is kept)\x1b[0m`);
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
541
|
+
fs.writeFileSync(fullPath, file.content, 'utf8');
|
|
542
|
+
writtenFiles.push(file.path);
|
|
543
|
+
log(` \x1b[32m✅\x1b[0m Created ${file.path}`);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const skippedSet = new Set(preservedFiles);
|
|
547
|
+
if (!skippedSet.has('AGENTS.md') && fs.existsSync(path.join(options.dir, 'AGENTS.md')) && !writtenFiles.includes('AGENTS.md')) {
|
|
548
|
+
preservedFiles.push('AGENTS.md');
|
|
549
|
+
}
|
|
550
|
+
if (!skippedSet.has('.codex/config.toml') && fs.existsSync(path.join(options.dir, '.codex', 'config.toml')) && !writtenFiles.includes('.codex/config.toml')) {
|
|
551
|
+
preservedFiles.push('.codex/config.toml');
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
let rollbackArtifact = null;
|
|
555
|
+
let activityArtifact = null;
|
|
556
|
+
if (writtenFiles.length > 0) {
|
|
557
|
+
rollbackArtifact = writeRollbackArtifact(options.dir, {
|
|
558
|
+
sourcePlan: 'codex-setup',
|
|
559
|
+
createdFiles: writtenFiles,
|
|
560
|
+
patchedFiles: [],
|
|
561
|
+
rollbackInstructions: writtenFiles.map((file) => `Delete ${file}`),
|
|
562
|
+
});
|
|
563
|
+
activityArtifact = writeActivityArtifact(options.dir, 'codex-setup', {
|
|
564
|
+
platform: 'codex',
|
|
565
|
+
createdFiles: writtenFiles,
|
|
566
|
+
preservedFiles,
|
|
567
|
+
stackLabels: stacks.map((item) => item.label),
|
|
568
|
+
rollbackArtifact: rollbackArtifact.relativePath,
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
log('');
|
|
573
|
+
log(` \x1b[1m${writtenFiles.length} files created.\x1b[0m`);
|
|
574
|
+
if (preservedFiles.length > 0) {
|
|
575
|
+
log(` \x1b[2m${preservedFiles.length} existing files preserved (not overwritten).\x1b[0m`);
|
|
576
|
+
}
|
|
577
|
+
if (rollbackArtifact) {
|
|
578
|
+
log(` Rollback: \x1b[1m${rollbackArtifact.relativePath}\x1b[0m`);
|
|
579
|
+
}
|
|
580
|
+
if (activityArtifact) {
|
|
581
|
+
log(` Activity log: \x1b[1m${activityArtifact.relativePath}\x1b[0m`);
|
|
582
|
+
}
|
|
583
|
+
log('');
|
|
584
|
+
log(' Run \x1b[1mnpx nerviq --platform codex\x1b[0m to audit your Codex setup.');
|
|
585
|
+
log('');
|
|
586
|
+
|
|
587
|
+
return {
|
|
588
|
+
created: writtenFiles.length,
|
|
589
|
+
skipped: preservedFiles.length,
|
|
590
|
+
writtenFiles,
|
|
591
|
+
preservedFiles,
|
|
592
|
+
stacks,
|
|
593
|
+
rollbackArtifact: rollbackArtifact ? rollbackArtifact.relativePath : null,
|
|
594
|
+
activityArtifact: activityArtifact ? activityArtifact.relativePath : null,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
module.exports = {
|
|
599
|
+
buildAgentsMd,
|
|
600
|
+
buildConfigToml,
|
|
601
|
+
buildCodexSetupFiles,
|
|
602
|
+
setupCodex,
|
|
603
|
+
};
|