@boyingliu01/xp-gate 0.41.9 → 0.41.52
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/adapters/gate-3.sh +28 -1
- package/adapters/gate-6-layers.sh +18 -1
- package/bin/xp-gate.js +13 -0
- package/gate-3.sh +28 -1
- package/gate-6-layers.sh +18 -1
- package/gates/python-health.ts +74 -26
- package/gates/test-layers.ts +94 -9
- package/hooks/gate-3.sh +28 -1
- package/hooks/gate-6-layers.sh +18 -1
- package/hooks/gate-entries/gate-11-entry.sh +21 -0
- package/hooks/gate-entries/gate-2-entry.sh +15 -0
- package/hooks/install.sh +15 -3
- package/hooks/pre-commit +90 -13
- package/hooks/pre-push +10 -1
- package/hooks/sprint-gate.sh +101 -13
- package/lib/check-alignment-runner.cjs +97 -0
- package/lib/check.js +6 -0
- package/lib/crap-cli.js +14 -6
- package/lib/delphi-setup.js +13 -0
- package/lib/doctor-tui.js +205 -102
- package/lib/doctor.js +146 -7
- package/lib/gate-runner.js +14 -3
- package/lib/init-install.js +299 -0
- package/lib/init-languages.js +158 -0
- package/lib/init-manifest.js +165 -0
- package/lib/init-md-injection.js +58 -0
- package/lib/init.js +134 -500
- package/lib/install-skill.js +66 -1
- package/lib/layer-baseline.cjs +94 -0
- package/lib/mattpocock-license-verdict.json +7 -0
- package/lib/uninstall-skills.js +140 -0
- package/lib/uninstall.js +41 -100
- package/lib/update-skill.js +9 -1
- package/package.json +3 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/delphi-review/INSTALL.md +22 -3
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/references/definition-of-done.md +2 -2
- package/plugins/claude-code/skills/sprint-flow/references/phase-3-build.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/references/phase-4-verify.md +2 -2
- package/plugins/claude-code/skills/sprint-flow/references/phase-6-close.md +17 -0
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/lib/delphi-evidence.d.ts +59 -0
- package/plugins/dsh/lib/delphi-evidence.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-evidence.js +128 -0
- package/plugins/dsh/lib/delphi-finding.d.ts +123 -0
- package/plugins/dsh/lib/delphi-finding.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-finding.js +332 -0
- package/plugins/dsh/lib/delphi-findings-parse.d.ts +29 -0
- package/plugins/dsh/lib/delphi-findings-parse.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-findings-parse.js +138 -0
- package/plugins/dsh/lib/delphi-ledger.d.ts +55 -0
- package/plugins/dsh/lib/delphi-ledger.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-ledger.js +124 -0
- package/plugins/dsh/lib/delphi-run.d.ts +7 -0
- package/plugins/dsh/lib/delphi-run.d.ts.map +1 -1
- package/plugins/dsh/lib/delphi-run.js +48 -18
- package/plugins/dsh/lib/delphi-seats.d.ts +34 -0
- package/plugins/dsh/lib/delphi-seats.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-seats.js +40 -0
- package/plugins/dsh/lib/evidence.d.ts +21 -0
- package/plugins/dsh/lib/evidence.d.ts.map +1 -1
- package/plugins/dsh/lib/evidence.js +3 -0
- package/plugins/dsh/lib/index.d.ts.map +1 -1
- package/plugins/dsh/lib/index.js +12 -0
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/delphi-review/INSTALL.md +22 -3
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/references/definition-of-done.md +2 -2
- package/plugins/dsh/skills/sprint-flow/references/phase-3-build.md +1 -1
- package/plugins/dsh/skills/sprint-flow/references/phase-4-verify.md +2 -2
- package/plugins/dsh/skills/sprint-flow/references/phase-6-close.md +17 -0
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/src/delphi-evidence.test.ts +100 -0
- package/plugins/dsh/src/delphi-evidence.ts +201 -0
- package/plugins/dsh/src/delphi-finding.test.ts +333 -0
- package/plugins/dsh/src/delphi-finding.ts +446 -0
- package/plugins/dsh/src/delphi-findings-parse.test.ts +100 -0
- package/plugins/dsh/src/delphi-findings-parse.ts +158 -0
- package/plugins/dsh/src/delphi-findings.test.ts +4 -0
- package/plugins/dsh/src/delphi-ledger.test.ts +210 -0
- package/plugins/dsh/src/delphi-ledger.ts +158 -0
- package/plugins/dsh/src/delphi-run.test.ts +71 -68
- package/plugins/dsh/src/delphi-run.ts +80 -24
- package/plugins/dsh/src/delphi-seats.test.ts +117 -0
- package/plugins/dsh/src/delphi-seats.ts +50 -0
- package/plugins/dsh/src/evidence-findings.test.ts +75 -0
- package/plugins/dsh/src/evidence.ts +25 -0
- package/plugins/dsh/src/index.ts +14 -0
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/delphi-review/INSTALL.md +22 -3
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/references/definition-of-done.md +2 -2
- package/plugins/opencode/skills/sprint-flow/references/phase-3-build.md +1 -1
- package/plugins/opencode/skills/sprint-flow/references/phase-4-verify.md +2 -2
- package/plugins/opencode/skills/sprint-flow/references/phase-6-close.md +17 -0
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/delphi-review/INSTALL.md +22 -3
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/references/definition-of-done.md +2 -2
- package/plugins/qoder/skills/sprint-flow/references/phase-3-build.md +1 -1
- package/plugins/qoder/skills/sprint-flow/references/phase-4-verify.md +2 -2
- package/plugins/qoder/skills/sprint-flow/references/phase-6-close.md +17 -0
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/principles/index.ts +50 -1
- package/scripts/delphi-config-read.cjs +43 -6
- package/scripts/delphi-external-review.cjs +69 -12
- package/scripts/delphi-prompts.cjs +47 -1
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/delphi-review/INSTALL.md +22 -3
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/sprint-flow/references/definition-of-done.md +2 -2
- package/skills/sprint-flow/references/phase-3-build.md +1 -1
- package/skills/sprint-flow/references/phase-4-verify.md +2 -2
- package/skills/sprint-flow/references/phase-6-close.md +17 -0
- package/skills/test-specification-alignment/AGENTS.md +1 -1
- package/sprint-gate.sh +101 -13
- package/mutation/stryker-types.ts +0 -14
package/lib/init.js
CHANGED
|
@@ -13,15 +13,26 @@ const {
|
|
|
13
13
|
GLOBAL_ADAPTERS_DIR,
|
|
14
14
|
} = require('./shared-paths.js');
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Copy a file or directory tree.
|
|
18
|
+
*
|
|
19
|
+
* Guarded so a failure names the path it was working on: the recursive form reports
|
|
20
|
+
* whichever entry failed, and "ENOENT" with no path is the least useful error an
|
|
21
|
+
* installer can produce.
|
|
22
|
+
*/
|
|
16
23
|
function copyRecursive(src, dest) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
try {
|
|
25
|
+
const stat = fs.statSync(src);
|
|
26
|
+
if (stat.isDirectory()) {
|
|
27
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
28
|
+
fs.readdirSync(src).forEach(entry => {
|
|
29
|
+
copyRecursive(path.join(src, entry), path.join(dest, entry));
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
fs.copyFileSync(src, dest);
|
|
33
|
+
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
throw new Error(`cannot copy ${src} to ${dest}: ${err.message}`);
|
|
25
36
|
}
|
|
26
37
|
}
|
|
27
38
|
|
|
@@ -29,6 +40,12 @@ function copyRecursive(src, dest) {
|
|
|
29
40
|
// modules run via `npx tsx` from <CONFIG_DIR>/modules/<module>, these must be
|
|
30
41
|
// resolvable from an ancestor directory, so they are installed once into
|
|
31
42
|
// <CONFIG_DIR>/node_modules. Keep in sync with each module's imports.
|
|
43
|
+
|
|
44
|
+
const { sha256File, generateManifest, generateGlobalManifest } = require('./init-manifest.js');
|
|
45
|
+
const { askYesNo, detectAndReportLanguages } = require('./init-languages.js');
|
|
46
|
+
const { injectKarpathyPrinciples } = require('./init-md-injection.js');
|
|
47
|
+
const { installLocal, setupGlobal } = require('./init-install.js');
|
|
48
|
+
|
|
32
49
|
const MODULE_RUNTIME_DEPS = { 'js-yaml': '^5.2.2', 'zod': '^4.4.3' };
|
|
33
50
|
|
|
34
51
|
function installModuleRuntimeDeps(configDir) {
|
|
@@ -108,8 +125,13 @@ function getGitDir() {
|
|
|
108
125
|
}
|
|
109
126
|
}
|
|
110
127
|
|
|
128
|
+
/** Create the config directory, naming it when that fails. */
|
|
111
129
|
function ensureConfigDir() {
|
|
112
|
-
|
|
130
|
+
try {
|
|
131
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
132
|
+
} catch (err) {
|
|
133
|
+
throw new Error(`cannot create the config directory ${CONFIG_DIR}: ${err.message}`);
|
|
134
|
+
}
|
|
113
135
|
}
|
|
114
136
|
|
|
115
137
|
function updateConfig(updates) {
|
|
@@ -123,134 +145,6 @@ function updateConfig(updates) {
|
|
|
123
145
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
124
146
|
}
|
|
125
147
|
|
|
126
|
-
function sha256File(filePath) {
|
|
127
|
-
try {
|
|
128
|
-
const content = fs.readFileSync(filePath);
|
|
129
|
-
return crypto.createHash('sha256').update(content).digest('hex');
|
|
130
|
-
} catch {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function generateManifest(srcDir, projectRoot) {
|
|
136
|
-
const manifest = {
|
|
137
|
-
version: 1,
|
|
138
|
-
files: {},
|
|
139
|
-
injectedSections: {}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const gitDir = path.join(projectRoot, '.git');
|
|
143
|
-
const hooksDir = path.join(gitDir, 'hooks');
|
|
144
|
-
const githooksDir = path.join(projectRoot, 'githooks');
|
|
145
|
-
|
|
146
|
-
// Hooks. The list is the deploy manifest's (REQ-DEPLOY-001): recording a
|
|
147
|
-
// different set than the installer writes would make the recorded manifest
|
|
148
|
-
// describe a repository that does not exist.
|
|
149
|
-
require('./deploy-manifest.js').HOOK_FILES.forEach(hook => {
|
|
150
|
-
const hookPath = path.join(hooksDir, hook);
|
|
151
|
-
if (fs.existsSync(hookPath)) {
|
|
152
|
-
const stat = fs.statSync(hookPath);
|
|
153
|
-
manifest.files[`.git/hooks/${hook}`] = {
|
|
154
|
-
sha256: sha256File(hookPath),
|
|
155
|
-
size: stat.size
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// adapter-common.sh
|
|
161
|
-
const adapterCommonPath = path.join(githooksDir, 'adapter-common.sh');
|
|
162
|
-
if (fs.existsSync(adapterCommonPath)) {
|
|
163
|
-
const stat = fs.statSync(adapterCommonPath);
|
|
164
|
-
manifest.files['githooks/adapter-common.sh'] = {
|
|
165
|
-
sha256: sha256File(adapterCommonPath),
|
|
166
|
-
size: stat.size
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Adapter scripts
|
|
171
|
-
const adaptersDir = path.join(githooksDir, 'adapters');
|
|
172
|
-
if (fs.existsSync(adaptersDir)) {
|
|
173
|
-
fs.readdirSync(adaptersDir).forEach(f => {
|
|
174
|
-
const fPath = path.join(adaptersDir, f);
|
|
175
|
-
if (fs.statSync(fPath).isFile()) {
|
|
176
|
-
const stat = fs.statSync(fPath);
|
|
177
|
-
manifest.files[`githooks/adapters/${f}`] = {
|
|
178
|
-
sha256: sha256File(fPath),
|
|
179
|
-
size: stat.size
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Template dir note
|
|
186
|
-
manifest.templateDir = TEMPLATE_DIR;
|
|
187
|
-
|
|
188
|
-
// Injected sections
|
|
189
|
-
const agentsPath = path.join(projectRoot, 'AGENTS.md');
|
|
190
|
-
if (fs.existsSync(agentsPath)) {
|
|
191
|
-
try {
|
|
192
|
-
const content = fs.readFileSync(agentsPath, 'utf8');
|
|
193
|
-
if (content.includes('## AI CODING DISCIPLINE (Karpathy Principles)')) {
|
|
194
|
-
manifest.injectedSections['AGENTS.md'] = '## AI CODING DISCIPLINE (Karpathy Principles)';
|
|
195
|
-
}
|
|
196
|
-
} catch {}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return manifest;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function generateGlobalManifest(srcDir) {
|
|
203
|
-
const manifest = {
|
|
204
|
-
version: 1,
|
|
205
|
-
files: {},
|
|
206
|
-
gitConfig: {}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// Global hooks (same manifest list as above, REQ-DEPLOY-001)
|
|
210
|
-
require('./deploy-manifest.js').HOOK_FILES.forEach(hook => {
|
|
211
|
-
const hookPath = path.join(GLOBAL_HOOKS_DIR, hook);
|
|
212
|
-
if (fs.existsSync(hookPath)) {
|
|
213
|
-
const stat = fs.statSync(hookPath);
|
|
214
|
-
manifest.files[`hooks/${hook}`] = {
|
|
215
|
-
sha256: sha256File(hookPath),
|
|
216
|
-
size: stat.size
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
// adapter-common.sh
|
|
222
|
-
const adapterCommonPath = path.join(GLOBAL_ADAPTERS_DIR, 'adapter-common.sh');
|
|
223
|
-
if (fs.existsSync(adapterCommonPath)) {
|
|
224
|
-
const stat = fs.statSync(adapterCommonPath);
|
|
225
|
-
manifest.files['adapters/adapter-common.sh'] = {
|
|
226
|
-
sha256: sha256File(adapterCommonPath),
|
|
227
|
-
size: stat.size
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Adapter scripts
|
|
232
|
-
if (fs.existsSync(GLOBAL_ADAPTERS_DIR)) {
|
|
233
|
-
fs.readdirSync(GLOBAL_ADAPTERS_DIR).forEach(f => {
|
|
234
|
-
const fPath = path.join(GLOBAL_ADAPTERS_DIR, f);
|
|
235
|
-
if (fs.statSync(fPath).isFile() && f !== 'adapter-common.sh') {
|
|
236
|
-
const stat = fs.statSync(fPath);
|
|
237
|
-
manifest.files[`adapters/${f}`] = {
|
|
238
|
-
sha256: sha256File(fPath),
|
|
239
|
-
size: stat.size
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// git config
|
|
246
|
-
manifest.gitConfig = {
|
|
247
|
-
'core.hooksPath': GLOBAL_HOOKS_DIR
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
manifest.templateDir = TEMPLATE_DIR;
|
|
251
|
-
|
|
252
|
-
return manifest;
|
|
253
|
-
}
|
|
254
148
|
|
|
255
149
|
function printCliToolStatus() {
|
|
256
150
|
const available = [];
|
|
@@ -314,25 +208,6 @@ function probeGitleaksNotice(checkTool, log = console.log) {
|
|
|
314
208
|
return { available: false };
|
|
315
209
|
}
|
|
316
210
|
|
|
317
|
-
/**
|
|
318
|
-
* Ask the user for confirmation via stdin.
|
|
319
|
-
* @param {string} question - The yes/no question to display
|
|
320
|
-
* @returns {Promise<boolean>} true if user answered yes
|
|
321
|
-
*/
|
|
322
|
-
function askYesNo(question) {
|
|
323
|
-
return new Promise((resolve) => {
|
|
324
|
-
const rl = require('readline').createInterface({
|
|
325
|
-
input: process.stdin,
|
|
326
|
-
output: process.stdout,
|
|
327
|
-
});
|
|
328
|
-
rl.question(`${question} (Y/n) `, (answer) => {
|
|
329
|
-
rl.close();
|
|
330
|
-
const normalized = answer.trim().toLowerCase();
|
|
331
|
-
// Empty (just Enter) or y/yes → yes; anything else → no
|
|
332
|
-
resolve(normalized === '' || normalized === 'y' || normalized === 'yes');
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
211
|
|
|
337
212
|
/**
|
|
338
213
|
* Prompt the user to auto-install missing CLI quality-gate tools.
|
|
@@ -473,10 +348,34 @@ function ensureGitignoreEntries(root) {
|
|
|
473
348
|
* Initialize XP-Gate in the current project.
|
|
474
349
|
* @param {string[]} args - CLI arguments
|
|
475
350
|
*/
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
351
|
+
/**
|
|
352
|
+
* The functions the install modes call back into.
|
|
353
|
+
*
|
|
354
|
+
* Passed as a value rather than imported by `init-install.js`: that module needs these
|
|
355
|
+
* and this one needs the install modes, and a require cycle between them would resolve
|
|
356
|
+
* differently depending on which module loaded first.
|
|
357
|
+
*/
|
|
358
|
+
function installHelpers() {
|
|
359
|
+
return {
|
|
360
|
+
copyRecursive,
|
|
361
|
+
installModuleRuntimeDeps,
|
|
362
|
+
ensureConfigDir,
|
|
363
|
+
updateConfig,
|
|
364
|
+
ensureArchConfig,
|
|
365
|
+
deployQoderDelphiAgents,
|
|
366
|
+
configureOpenCodePlugin,
|
|
367
|
+
getGitDir,
|
|
368
|
+
promptBootstrap,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
479
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Print what the machine has, before anything is installed.
|
|
374
|
+
*
|
|
375
|
+
* Extracted from `init` (90 lines). None of this decides what the install does; it
|
|
376
|
+
* reports what was found and provisions the platform dependencies those gates need.
|
|
377
|
+
*/
|
|
378
|
+
async function reportEnvironment() {
|
|
480
379
|
// Check bash availability (required for shell hooks)
|
|
481
380
|
console.log('Checking bash availability...');
|
|
482
381
|
const bashCheck = checkBash();
|
|
@@ -501,35 +400,45 @@ async function init(args) {
|
|
|
501
400
|
const platform = detectPlatform();
|
|
502
401
|
console.log(`Platform: ${platform}\n`);
|
|
503
402
|
await checkAndInstallDeps(platform);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Create the lint baseline a local install needs for the Boy Scout rule.
|
|
407
|
+
*
|
|
408
|
+
* A failure is reported and swallowed: the baseline is an optimisation, and an install
|
|
409
|
+
* that otherwise succeeded should not fail because one file could not be written.
|
|
410
|
+
*/
|
|
411
|
+
async function createLintBaseline() {
|
|
412
|
+
try {
|
|
413
|
+
const { createBaseline } = require('./baseline.js');
|
|
414
|
+
console.log('\nCreating lint baseline (Boy Scout Rule)...');
|
|
415
|
+
const baseline = await createBaseline();
|
|
416
|
+
console.log(`\u2705 Lint baseline created \u2014 ${Object.keys(baseline).length} files tracked.`);
|
|
417
|
+
} catch (e) {
|
|
418
|
+
console.log(`\u2139\ufe0f Lint baseline creation skipped: ${e.message}`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
async function init(args) {
|
|
423
|
+
console.log('XP-Gate Initialization');
|
|
424
|
+
console.log('====================\n');
|
|
425
|
+
|
|
426
|
+
await reportEnvironment();
|
|
504
427
|
|
|
505
428
|
const installMode = args.includes('--global') ? 'global' :
|
|
506
429
|
args.includes('--core-only') ? 'local' :
|
|
507
430
|
args.includes('--full') ? 'local' : null;
|
|
508
431
|
|
|
509
432
|
if (!installMode) { printUsage(); return 0; }
|
|
510
|
-
|
|
511
|
-
|
|
433
|
+
const helpers = installHelpers();
|
|
434
|
+
if (installMode === 'global') return setupGlobal(args, helpers);
|
|
435
|
+
const code = await installLocal(args, helpers);
|
|
512
436
|
// #767: installLocal writes adapters, .xp-gate/ and the generated config into the
|
|
513
437
|
// project. Without ignore rules every one of those shows up as an untracked entry,
|
|
514
438
|
// and the file-hygiene/debt gates then treat generated output as uncommitted
|
|
515
439
|
// source — a zero-tolerance Gate 6 BLOCK the user cannot repair except by hand.
|
|
516
440
|
// Done AFTER the install so it only claims files that actually exist.
|
|
517
441
|
if (code === 0) {
|
|
518
|
-
// Root comes from getGitDir(), the SAME resolution installLocal used. Reading
|
|
519
|
-
// process.cwd() instead would write .gitignore to whatever subdirectory the
|
|
520
|
-
// user happened to run from while the adapters landed at the repo root — the
|
|
521
|
-
// rules would then guard the wrong tree.
|
|
522
|
-
//
|
|
523
|
-
// A failure here is a WARNING with a repair hint, never a silent skip: a
|
|
524
|
-
// read-only checkout leaves the user in exactly the #767 state, so exiting 0
|
|
525
|
-
// quietly would hide the defect this closes.
|
|
526
|
-
//
|
|
527
|
-
// Only filesystem errors are downgraded. A TypeError or a bad-regex bug in the
|
|
528
|
-
// helper is a defect in xp-gate, not a permissions problem, and telling the
|
|
529
|
-
// user to `chmod` would send them after the wrong thing — those rethrow.
|
|
530
|
-
// The failure check is on the error CODE, not on a message substring: getGitDir()
|
|
531
|
-
// signals "not a repo" by returning null, so there is no message to match and
|
|
532
|
-
// matching one would break the moment its wording changed.
|
|
533
442
|
const FS_ERROR_CODES = new Set(['EACCES', 'EPERM', 'EROFS', 'EBUSY', 'ENOSPC', 'EISDIR', 'ENOTDIR']);
|
|
534
443
|
const gitDir = getGitDir();
|
|
535
444
|
if (!gitDir) {
|
|
@@ -550,106 +459,13 @@ async function init(args) {
|
|
|
550
459
|
}
|
|
551
460
|
// Always create lint baseline for local installs (Boy Scout Rule needs it)
|
|
552
461
|
// --baseline flag is now a no-op (baseline is always created)
|
|
553
|
-
if (code === 0)
|
|
554
|
-
try {
|
|
555
|
-
const { createBaseline } = require('./baseline.js');
|
|
556
|
-
console.log('\nCreating lint baseline (Boy Scout Rule)...');
|
|
557
|
-
const baseline = await createBaseline();
|
|
558
|
-
console.log(`\u2705 Lint baseline created \u2014 ${Object.keys(baseline).length} files tracked.`);
|
|
559
|
-
} catch (e) {
|
|
560
|
-
console.log(`\u2139\ufe0f Lint baseline creation skipped: ${e.message}`);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
462
|
+
if (code === 0) await createLintBaseline();
|
|
563
463
|
return code;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* Detect project languages and check/install language-specific tools.
|
|
568
|
-
* @param {string} projectRoot - Project root directory
|
|
569
|
-
* @param {boolean} autoYes - Auto-install missing tools
|
|
570
|
-
*/
|
|
571
|
-
async function detectAndReportLanguages(projectRoot, autoYes) {
|
|
572
|
-
const { detectProjectLanguages, getToolsForLanguages, generateProjectConfig, LANGUAGE_REGISTRY } = require('./language-tools.js');
|
|
573
|
-
|
|
574
|
-
console.log('');
|
|
575
|
-
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
576
|
-
console.log(' Multi-Language Quality Gates');
|
|
577
|
-
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
578
|
-
console.log('');
|
|
579
|
-
|
|
580
|
-
const { detected, configFiles } = detectProjectLanguages(projectRoot);
|
|
581
|
-
|
|
582
|
-
if (detected.length === 0) {
|
|
583
|
-
console.log(' No project languages detected.');
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
console.log(` Detected ${detected.length} language(s):`);
|
|
588
|
-
for (const lang of detected) {
|
|
589
|
-
const langDef = LANGUAGE_REGISTRY[lang];
|
|
590
|
-
console.log(` • ${langDef?.name || lang}`);
|
|
591
|
-
}
|
|
592
|
-
console.log('');
|
|
593
|
-
|
|
594
|
-
const toolStatus = getToolsForLanguages(detected);
|
|
595
|
-
const missingRequired = [];
|
|
596
|
-
const missingOptional = [];
|
|
597
|
-
|
|
598
|
-
for (const [lang, tools] of Object.entries(toolStatus)) {
|
|
599
|
-
for (const t of tools) {
|
|
600
|
-
if (t.status === 'missing') {
|
|
601
|
-
if (t.tool.optional) {
|
|
602
|
-
missingOptional.push({ lang, tool: t.tool });
|
|
603
|
-
} else {
|
|
604
|
-
missingRequired.push({ lang, tool: t.tool });
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
if (missingRequired.length === 0 && missingOptional.length === 0) {
|
|
611
|
-
console.log(' ✓ All language-specific tools are available.');
|
|
612
|
-
} else {
|
|
613
|
-
if (missingRequired.length > 0) {
|
|
614
|
-
console.log(` ✗ ${missingRequired.length} required tool(s) missing:`);
|
|
615
|
-
for (const { lang, tool } of missingRequired) {
|
|
616
|
-
console.log(` • ${tool.name} (${lang}) — gates will SKIP`);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
if (missingOptional.length > 0) {
|
|
620
|
-
console.log(` ⚠ ${missingOptional.length} optional tool(s) missing (fallback available):`);
|
|
621
|
-
for (const { lang, tool } of missingOptional) {
|
|
622
|
-
console.log(` • ${tool.name} (${lang})`);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
console.log('');
|
|
626
|
-
|
|
627
|
-
if (autoYes || (process.stdin.isTTY && await askYesNo(' Install missing language-specific tools now?'))) {
|
|
628
|
-
console.log('');
|
|
629
|
-
const { installTool } = require('./language-tools.js');
|
|
630
|
-
let installed = 0;
|
|
631
|
-
for (const { lang, tool } of [...missingRequired, ...missingOptional]) {
|
|
632
|
-
const result = installTool(tool);
|
|
633
|
-
if (result.success) {
|
|
634
|
-
console.log(` ✓ ${tool.name} installed`);
|
|
635
|
-
installed++;
|
|
636
|
-
} else {
|
|
637
|
-
console.log(` ✗ ${tool.name}: ${result.message}`);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
if (installed > 0) {
|
|
641
|
-
console.log(`\n ${installed} tool(s) installed successfully.`);
|
|
642
|
-
}
|
|
643
|
-
} else {
|
|
644
|
-
console.log(' Skipped. Run "xp-gate install-tools --yes" later.');
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
464
|
|
|
648
|
-
|
|
649
|
-
generateProjectConfig(projectRoot, detected, toolStatus);
|
|
650
|
-
console.log(`\n Generated .xp-gate-config.json`);
|
|
465
|
+
return code;
|
|
651
466
|
}
|
|
652
467
|
|
|
468
|
+
|
|
653
469
|
/**
|
|
654
470
|
* Write the default architecture config so Gate 6's precondition holds
|
|
655
471
|
* (REQ-DEPLOY-003).
|
|
@@ -694,185 +510,6 @@ function ensureArchConfig(projectRoot) {
|
|
|
694
510
|
}
|
|
695
511
|
}
|
|
696
512
|
|
|
697
|
-
async function installLocal(args) {
|
|
698
|
-
const gitDir = getGitDir();
|
|
699
|
-
if (!gitDir) {
|
|
700
|
-
console.error('Error: Not a git repository');
|
|
701
|
-
console.error('Run xp-gate init from inside a git repository');
|
|
702
|
-
return 1;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
const projectRoot = path.dirname(gitDir);
|
|
706
|
-
const hooksDir = path.join(projectRoot, '.git', 'hooks');
|
|
707
|
-
const srcDir = path.dirname(__dirname);
|
|
708
|
-
|
|
709
|
-
console.log(`Mode: Local (per-project)`);
|
|
710
|
-
console.log(`Project: ${projectRoot}`);
|
|
711
|
-
console.log(`Git hooks: ${hooksDir}\n`);
|
|
712
|
-
console.log('Installing hooks...');
|
|
713
|
-
|
|
714
|
-
copyHooks(srcDir, hooksDir);
|
|
715
|
-
console.log(' pre-commit -> .git/hooks/');
|
|
716
|
-
console.log(' pre-push -> .git/hooks/');
|
|
717
|
-
|
|
718
|
-
fs.mkdirSync(path.join(projectRoot, 'githooks', 'adapters'), { recursive: true });
|
|
719
|
-
copyAdapters(srcDir, path.join(projectRoot, 'githooks'));
|
|
720
|
-
console.log(` adapter-common.sh + adapters -> ${projectRoot}/githooks/`);
|
|
721
|
-
|
|
722
|
-
// Install principles/, mutation/, mock-policy/, build-integrity/ to .xp-gate/modules/
|
|
723
|
-
const modulesDir = path.join(projectRoot, '.xp-gate', 'modules');
|
|
724
|
-
['principles', 'mutation', 'mock-policy', 'build-integrity'].forEach(module => {
|
|
725
|
-
const moduleSrc = path.join(srcDir, module);
|
|
726
|
-
const moduleDest = path.join(modulesDir, module);
|
|
727
|
-
if (fs.existsSync(moduleSrc)) {
|
|
728
|
-
fs.mkdirSync(path.dirname(moduleDest), { recursive: true });
|
|
729
|
-
copyRecursive(moduleSrc, moduleDest);
|
|
730
|
-
console.log(` ${module}/ -> .xp-gate/modules/${module}/`);
|
|
731
|
-
}
|
|
732
|
-
});
|
|
733
|
-
installModuleRuntimeDeps(path.join(projectRoot, '.xp-gate'));
|
|
734
|
-
|
|
735
|
-
fs.mkdirSync(TEMPLATE_DIR, { recursive: true });
|
|
736
|
-
copyHooks(srcDir, TEMPLATE_DIR);
|
|
737
|
-
fs.mkdirSync(path.join(TEMPLATE_DIR, 'adapters'), { recursive: true });
|
|
738
|
-
|
|
739
|
-
ensureConfigDir();
|
|
740
|
-
|
|
741
|
-
const manifest = generateManifest(srcDir, projectRoot);
|
|
742
|
-
updateConfig({ lastInit: new Date().toISOString(), mode: 'local', templateDir: TEMPLATE_DIR, manifest });
|
|
743
|
-
|
|
744
|
-
ensureArchConfig(projectRoot);
|
|
745
|
-
injectKarpathyPrinciples(projectRoot);
|
|
746
|
-
configureOpenCodePlugin(srcDir, projectRoot);
|
|
747
|
-
deployQoderDelphiAgents(srcDir, projectRoot);
|
|
748
|
-
|
|
749
|
-
// Auto-register TUI plugin globally (idempotent)
|
|
750
|
-
try {
|
|
751
|
-
const { ensureTuiRegistration } = require('../lib/doctor.js');
|
|
752
|
-
ensureTuiRegistration();
|
|
753
|
-
} catch { /* non-critical: TUI registration is best-effort */ }
|
|
754
|
-
|
|
755
|
-
console.log('\nInstallation complete!');
|
|
756
|
-
console.log('Run git commit to trigger quality gates');
|
|
757
|
-
// The moment an install succeeds is the only moment the user is certain the
|
|
758
|
-
// tool works; that is where the invitation belongs (#871). Wrapped because a
|
|
759
|
-
// decoration must never fail an install.
|
|
760
|
-
try {
|
|
761
|
-
require('./star-notice.js').maybeShowStarNotice();
|
|
762
|
-
} catch { /* best-effort */ }
|
|
763
|
-
|
|
764
|
-
// Auto-install missing CLI tools (prompt user)
|
|
765
|
-
const autoYes = args.includes('--yes') || args.includes('--auto-install');
|
|
766
|
-
await promptBootstrap(autoYes);
|
|
767
|
-
|
|
768
|
-
// Detect project languages and check language-specific tools
|
|
769
|
-
await detectAndReportLanguages(projectRoot, autoYes);
|
|
770
|
-
|
|
771
|
-
console.log('━━━ FIRST-CLASS TEST QUALITY ━━━');
|
|
772
|
-
console.log('XP-Gate treats test code as a first-class citizen:');
|
|
773
|
-
console.log(' • TypeScript: test files are type-checked, not excluded from tsconfig.json');
|
|
774
|
-
console.log(' • Static analysis: lint/ESLint/Biome check test files alongside source');
|
|
775
|
-
console.log(' • Complexity: cyclomatic complexity is measured on test files too');
|
|
776
|
-
console.log(' • Duplicate code: jscpd scans test files (fixtures/snapshots excluded)');
|
|
777
|
-
console.log(' • Architecture: archlint validates test code structure');
|
|
778
|
-
console.log('');
|
|
779
|
-
console.log(' To include tests in your project:');
|
|
780
|
-
console.log(' 1. Remove __tests__/ from tsconfig.json exclude');
|
|
781
|
-
console.log(' 2. Remove __tests__/ from jscpd.conf.json ignore');
|
|
782
|
-
console.log(' 3. Add tsconfig.json: "types": ["vitest/globals"]');
|
|
783
|
-
console.log(' 4. Run "xp-gate doctor" to verify setup');
|
|
784
|
-
return 0;
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
async function setupGlobal(args) {
|
|
788
|
-
const srcDir = path.dirname(__dirname);
|
|
789
|
-
|
|
790
|
-
console.log('XP-Gate Global Setup');
|
|
791
|
-
console.log('====================\n');
|
|
792
|
-
console.log('Mode: Global (all git projects)');
|
|
793
|
-
console.log(`Global hooks: ${GLOBAL_HOOKS_DIR}`);
|
|
794
|
-
console.log(`Global adapters: ${GLOBAL_ADAPTERS_DIR}\n`);
|
|
795
|
-
|
|
796
|
-
console.log('[setup-global] Creating global directories...');
|
|
797
|
-
fs.mkdirSync(GLOBAL_HOOKS_DIR, { recursive: true });
|
|
798
|
-
fs.mkdirSync(GLOBAL_ADAPTERS_DIR, { recursive: true });
|
|
799
|
-
|
|
800
|
-
console.log('[setup-global] Installing git hooks...');
|
|
801
|
-
copyHooks(srcDir, GLOBAL_HOOKS_DIR);
|
|
802
|
-
console.log('Installing hooks...');
|
|
803
|
-
console.log(` pre-commit -> ${GLOBAL_HOOKS_DIR}`);
|
|
804
|
-
console.log(` pre-push -> ${GLOBAL_HOOKS_DIR}`);
|
|
805
|
-
|
|
806
|
-
console.log('[setup-global] Installing adapters...');
|
|
807
|
-
copyAdapters(srcDir, GLOBAL_ADAPTERS_DIR);
|
|
808
|
-
console.log(` adapter-common.sh + adapters -> ${GLOBAL_ADAPTERS_DIR}`);
|
|
809
|
-
|
|
810
|
-
// Install principles/, mutation/, mock-policy/, build-integrity/ to global modules dir
|
|
811
|
-
console.log('[setup-global] Installing quality gate modules...');
|
|
812
|
-
const globalModulesDir = path.join(CONFIG_DIR, 'modules');
|
|
813
|
-
['principles', 'mutation', 'mock-policy', 'build-integrity'].forEach(module => {
|
|
814
|
-
const moduleSrc = path.join(srcDir, module);
|
|
815
|
-
const moduleDest = path.join(globalModulesDir, module);
|
|
816
|
-
if (fs.existsSync(moduleSrc)) {
|
|
817
|
-
fs.mkdirSync(path.dirname(moduleDest), { recursive: true });
|
|
818
|
-
copyRecursive(moduleSrc, moduleDest);
|
|
819
|
-
console.log(` ${module}/ -> ${globalModulesDir}/${module}/`);
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
|
|
823
|
-
// Copied modules are pure TS sourced into <CONFIG_DIR>/modules/. Any of them
|
|
824
|
-
// that import third-party packages (currently only mock-policy: js-yaml, zod)
|
|
825
|
-
// resolve them via Node's ancestor lookup up from the module location, so we
|
|
826
|
-
// install those deps into <CONFIG_DIR>/node_modules once. Best-effort: a
|
|
827
|
-
// missing register/network must not break global setup.
|
|
828
|
-
installModuleRuntimeDeps(CONFIG_DIR);
|
|
829
|
-
|
|
830
|
-
// Qoder loads user-level custom agents from ~/.qoder/agents/, so a global
|
|
831
|
-
// setup must deploy the Delphi expert templates there as well.
|
|
832
|
-
deployQoderDelphiAgents(srcDir, HOME_DIR);
|
|
833
|
-
|
|
834
|
-
console.log('[setup-global] Configuring git...');
|
|
835
|
-
const { execSync } = require('child_process');
|
|
836
|
-
try {
|
|
837
|
-
execSync(`git config --global core.hooksPath "${GLOBAL_HOOKS_DIR}"`);
|
|
838
|
-
console.log(`\n git config --global core.hooksPath "${GLOBAL_HOOKS_DIR}"`);
|
|
839
|
-
} catch (e) {
|
|
840
|
-
console.warn('Warning: Could not set git core.hooksPath config');
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
ensureConfigDir();
|
|
844
|
-
|
|
845
|
-
console.log('[setup-global] Generating installation manifest...');
|
|
846
|
-
const manifest = generateGlobalManifest(srcDir);
|
|
847
|
-
updateConfig({ lastInit: new Date().toISOString(), mode: 'global', templateDir: TEMPLATE_DIR, manifest });
|
|
848
|
-
|
|
849
|
-
// Auto-register TUI plugin globally (idempotent)
|
|
850
|
-
try {
|
|
851
|
-
const { ensureTuiRegistration } = require('../lib/doctor.js');
|
|
852
|
-
ensureTuiRegistration();
|
|
853
|
-
} catch { /* non-critical: TUI registration is best-effort */ }
|
|
854
|
-
|
|
855
|
-
console.log('\nGlobal setup complete!');
|
|
856
|
-
console.log('All git repositories will now use xp-gate quality gates.');
|
|
857
|
-
console.log('Per-project adapters can still override by creating <repo>/githooks/');
|
|
858
|
-
|
|
859
|
-
// Auto-install missing CLI tools (prompt user)
|
|
860
|
-
console.log('[setup-global] Checking quality gate CLI tools...');
|
|
861
|
-
const autoYes = args.includes('--yes') || args.includes('--auto-install');
|
|
862
|
-
await promptBootstrap(autoYes);
|
|
863
|
-
|
|
864
|
-
console.log('');
|
|
865
|
-
console.log('━━━ FIRST-CLASS TEST QUALITY ━━━');
|
|
866
|
-
console.log('XP-Gate treats test code as a first-class citizen:');
|
|
867
|
-
console.log(' All quality gates apply equally to test files.');
|
|
868
|
-
console.log(' To include tests in your project:');
|
|
869
|
-
console.log(' 1. Remove __tests__/ from tsconfig.json exclude');
|
|
870
|
-
console.log(' 2. Remove __tests__/ from jscpd.conf.json ignore');
|
|
871
|
-
console.log(' 3. Remove test patterns from .archlint.yaml ignore');
|
|
872
|
-
console.log(' 4. Add "types": ["vitest/globals"] to tsconfig.json');
|
|
873
|
-
console.log(' 5. Run "xp-gate doctor" to verify');
|
|
874
|
-
return 0;
|
|
875
|
-
}
|
|
876
513
|
|
|
877
514
|
/**
|
|
878
515
|
* Qoder Custom Agents must bind their model as "[DisplayName](modelId)"; a bare
|
|
@@ -927,8 +564,14 @@ function warnUnusableQoderAgent(file, boundId, bundledId) {
|
|
|
927
564
|
* @param {Object<string, string|null>|null} bundled - modelId per bundled template, null if unbundled
|
|
928
565
|
*/
|
|
929
566
|
function auditDeployedQoderAgents(agentsDestDir, bundled) {
|
|
930
|
-
|
|
931
|
-
|
|
567
|
+
let entries;
|
|
568
|
+
try {
|
|
569
|
+
entries = fs.readdirSync(agentsDestDir).filter(f => f.endsWith('.md'));
|
|
570
|
+
} catch {
|
|
571
|
+
// No directory means nothing was deployed; there is nothing to audit.
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
for (const file of entries) {
|
|
932
575
|
// Unrelated user agents are none of our business; only Delphi experts are.
|
|
933
576
|
if (!file.startsWith('delphi-') && !(bundled && file in bundled)) continue;
|
|
934
577
|
const destFile = path.join(agentsDestDir, file);
|
|
@@ -947,9 +590,16 @@ function auditDeployedQoderAgents(agentsDestDir, bundled) {
|
|
|
947
590
|
* @returns {Object<string, string|null>|null} file → modelId, null when not bundled
|
|
948
591
|
*/
|
|
949
592
|
function readBundledQoderTemplates(agentSrcDir) {
|
|
950
|
-
|
|
593
|
+
let entries;
|
|
594
|
+
try {
|
|
595
|
+
entries = fs.readdirSync(agentSrcDir).filter(f => f.endsWith('.md'));
|
|
596
|
+
} catch {
|
|
597
|
+
// No bundled agents at all: null tells the caller "not bundled", which keeps it
|
|
598
|
+
// from auditing templates that do not exist.
|
|
599
|
+
return null;
|
|
600
|
+
}
|
|
951
601
|
const bundled = {};
|
|
952
|
-
for (const file of
|
|
602
|
+
for (const file of entries) {
|
|
953
603
|
bundled[file] = readQoderModelId(path.join(agentSrcDir, file));
|
|
954
604
|
}
|
|
955
605
|
return bundled;
|
|
@@ -966,7 +616,11 @@ function readBundledQoderTemplates(agentSrcDir) {
|
|
|
966
616
|
function deployQoderTemplates(agentSrcDir, agentsDestDir, bundled) {
|
|
967
617
|
const summary = { deployed: 0, skipped: 0, rejected: 0 };
|
|
968
618
|
if (!bundled) return summary;
|
|
969
|
-
|
|
619
|
+
try {
|
|
620
|
+
fs.mkdirSync(agentsDestDir, { recursive: true });
|
|
621
|
+
} catch (err) {
|
|
622
|
+
throw new Error(`cannot create the Qoder agents directory ${agentsDestDir}: ${err.message}`);
|
|
623
|
+
}
|
|
970
624
|
for (const file of Object.keys(bundled)) {
|
|
971
625
|
const srcFile = path.join(agentSrcDir, file);
|
|
972
626
|
if (fs.existsSync(path.join(agentsDestDir, file))) {
|
|
@@ -1126,55 +780,35 @@ function configureOpenCodePlugin(srcDir, projectRoot) {
|
|
|
1126
780
|
}
|
|
1127
781
|
}
|
|
1128
782
|
|
|
1129
|
-
function injectKarpathyPrinciples(projectRoot) {
|
|
1130
|
-
const agentsPath = path.join(projectRoot, 'AGENTS.md');
|
|
1131
|
-
if (!fs.existsSync(agentsPath)) return;
|
|
1132
|
-
|
|
1133
|
-
let content;
|
|
1134
|
-
try {
|
|
1135
|
-
content = fs.readFileSync(agentsPath, 'utf8');
|
|
1136
|
-
} catch (e) {
|
|
1137
|
-
console.warn(` Warning: could not read AGENTS.md: ${e.message}`);
|
|
1138
|
-
return;
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
if (content.includes('## AI CODING DISCIPLINE (Karpathy Principles)')) return;
|
|
1142
|
-
|
|
1143
|
-
const section = `
|
|
1144
|
-
## AI CODING DISCIPLINE (Karpathy Principles)
|
|
1145
|
-
|
|
1146
|
-
**原则 3: Surgical Changes(外科手术式改动)**
|
|
1147
|
-
- 只碰必须碰的代码。只清理自己制造的混乱。
|
|
1148
|
-
- 编辑现有代码时,不"优化"相邻代码、注释或 formatting
|
|
1149
|
-
- 不重构没坏的东西
|
|
1150
|
-
- 匹配现有代码风格,即使 AI 更喜欢另一种
|
|
1151
|
-
- 发现无关的死代码 → 提及但不要删除(除非用户明确要求)
|
|
1152
|
-
- 自己的改动产生的 orphaned import/variable/function → 必须清理
|
|
1153
|
-
- 判定标准: 每一行改动都应能直接追溯到用户的请求
|
|
1154
|
-
|
|
1155
|
-
**原则 4: Goal-Driven Execution(目标驱动执行)**
|
|
1156
|
-
- 定义成功标准。循环直到验证。
|
|
1157
|
-
- 把指令转化为可验证目标:
|
|
1158
|
-
- "加验证" → "写测试 → 让测试通过"
|
|
1159
|
-
- "修 bug" → "写复现测试 → 让测试通过"
|
|
1160
|
-
- "重构 X" → "确保重构前后测试都通过"
|
|
1161
|
-
- 多步骤任务列出验证点
|
|
1162
|
-
- 改完任何代码后必须运行测试确认无 regression
|
|
1163
|
-
|
|
1164
|
-
`;
|
|
1165
|
-
|
|
1166
|
-
try {
|
|
1167
|
-
fs.appendFileSync(agentsPath, section, 'utf8');
|
|
1168
|
-
console.log(' Karpathy Principles injected into AGENTS.md');
|
|
1169
|
-
} catch (e) {
|
|
1170
|
-
console.warn(` Warning: could not write to AGENTS.md: ${e.message}`);
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
783
|
|
|
1174
784
|
// setupGlobal is exported so the global-install wiring (agents deployed to the
|
|
1175
785
|
// real HOME) can be audited under a sandboxed HOME, not just asserted to exist
|
|
1176
786
|
// — the historical miss was "local deployed, global did not" (#417, #429).
|
|
787
|
+
/**
|
|
788
|
+
* `setupGlobal` with the helpers injected.
|
|
789
|
+
*
|
|
790
|
+
* `init-install.js` takes them as a parameter to avoid a require cycle; this wrapper
|
|
791
|
+
* keeps that an implementation detail, so a caller (or a test) does not have to build
|
|
792
|
+
* the object to run a global install.
|
|
793
|
+
*
|
|
794
|
+
* @param {string[]} args CLI argv
|
|
795
|
+
*/
|
|
796
|
+
function runSetupGlobal(args) {
|
|
797
|
+
return setupGlobal(args, installHelpers());
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* `installLocal` with the helpers injected. See runSetupGlobal.
|
|
802
|
+
*
|
|
803
|
+
* @param {string[]} args CLI argv
|
|
804
|
+
*/
|
|
805
|
+
function runInstallLocal(args) {
|
|
806
|
+
return installLocal(args, installHelpers());
|
|
807
|
+
}
|
|
808
|
+
|
|
1177
809
|
module.exports = {
|
|
810
|
+
runSetupGlobal,
|
|
811
|
+
runInstallLocal,
|
|
1178
812
|
init,
|
|
1179
813
|
promptBootstrap,
|
|
1180
814
|
installModuleRuntimeDeps,
|