@boyingliu01/xp-gate 0.41.10 → 0.41.56
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 +283 -31
- 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
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two install modes: per-project and global.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `init.js`, which had reached 1050 lines -- the point where extracting a
|
|
5
|
+
* function IN PLACE makes the file bigger, because each extraction adds a signature, a
|
|
6
|
+
* doc comment and a closing brace. Measured: six extractions took 1196 lines to 1294
|
|
7
|
+
* and left the finding count unchanged. A file only gets smaller by moving code out.
|
|
8
|
+
*
|
|
9
|
+
* These four functions are the one coherent thing that was still big enough to move:
|
|
10
|
+
* installLocal and setupGlobal are the same job against two destinations, and each
|
|
11
|
+
* with its one deployment helper.
|
|
12
|
+
*
|
|
13
|
+
* THEY TAKE A `helpers` OBJECT rather than requiring init.js. Both directions of a
|
|
14
|
+
* direct import would be circular -- init.js calls these, and these call back into
|
|
15
|
+
* init.js for the config directory, the manifest and the Qoder deployment -- and a
|
|
16
|
+
* cycle resolved through a partially-evaluated module is the kind of bug that only
|
|
17
|
+
* appears in one invocation order.
|
|
18
|
+
*/
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const path = require('path');
|
|
23
|
+
|
|
24
|
+
const { copyHooks, copyAdapters } = require('./shared-utils.js');
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
HOME_DIR,
|
|
28
|
+
CONFIG_DIR,
|
|
29
|
+
TEMPLATE_DIR,
|
|
30
|
+
GLOBAL_HOOKS_DIR,
|
|
31
|
+
GLOBAL_ADAPTERS_DIR,
|
|
32
|
+
} = require('./shared-paths.js');
|
|
33
|
+
const { generateManifest, generateGlobalManifest } = require('./init-manifest.js');
|
|
34
|
+
const { detectAndReportLanguages } = require('./init-languages.js');
|
|
35
|
+
const { injectKarpathyPrinciples } = require('./init-md-injection.js');
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Put the hooks, adapters and modules where the project will load them from.
|
|
39
|
+
*
|
|
40
|
+
* Extracted from `installLocal` (89 lines): every line here is a copy plus the line
|
|
41
|
+
* that reports it, interleaved so that neither could be read on its own.
|
|
42
|
+
*/
|
|
43
|
+
function deployLocalPayload(srcDir, projectRoot, hooksDir, h) {
|
|
44
|
+
copyHooks(srcDir, hooksDir);
|
|
45
|
+
console.log(' pre-commit -> .git/hooks/');
|
|
46
|
+
console.log(' pre-push -> .git/hooks/');
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
fs.mkdirSync(path.join(projectRoot, 'githooks', 'adapters'), { recursive: true });
|
|
50
|
+
} catch (err) {
|
|
51
|
+
throw new Error(`cannot create the project adapters directory: ${err.message}`);
|
|
52
|
+
}
|
|
53
|
+
copyAdapters(srcDir, path.join(projectRoot, 'githooks'));
|
|
54
|
+
console.log(` adapter-common.sh + adapters -> ${projectRoot}/githooks/`);
|
|
55
|
+
|
|
56
|
+
// Install principles/, mutation/, mock-policy/, build-integrity/ to .xp-gate/modules/
|
|
57
|
+
const modulesDir = path.join(projectRoot, '.xp-gate', 'modules');
|
|
58
|
+
['principles', 'mutation', 'mock-policy', 'build-integrity'].forEach(module => {
|
|
59
|
+
const moduleSrc = path.join(srcDir, module);
|
|
60
|
+
const moduleDest = path.join(modulesDir, module);
|
|
61
|
+
if (fs.existsSync(moduleSrc)) {
|
|
62
|
+
ensureDirOrThrow(path.dirname(moduleDest));
|
|
63
|
+
h.copyRecursive(moduleSrc, moduleDest);
|
|
64
|
+
console.log(` ${module}/ -> .xp-gate/modules/${module}/`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
h.installModuleRuntimeDeps(path.join(projectRoot, '.xp-gate'));
|
|
68
|
+
|
|
69
|
+
fs.mkdirSync(TEMPLATE_DIR, { recursive: true });
|
|
70
|
+
copyHooks(srcDir, TEMPLATE_DIR);
|
|
71
|
+
fs.mkdirSync(path.join(TEMPLATE_DIR, 'adapters'), { recursive: true });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function installLocal(args, h) {
|
|
75
|
+
const gitDir = h.getGitDir();
|
|
76
|
+
if (!gitDir) {
|
|
77
|
+
console.error('Error: Not a git repository');
|
|
78
|
+
console.error('Run xp-gate init from inside a git repository');
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const projectRoot = path.dirname(gitDir);
|
|
83
|
+
const hooksDir = path.join(projectRoot, '.git', 'hooks');
|
|
84
|
+
const srcDir = path.dirname(__dirname);
|
|
85
|
+
|
|
86
|
+
console.log(`Mode: Local (per-project)`);
|
|
87
|
+
console.log(`Project: ${projectRoot}`);
|
|
88
|
+
console.log(`Git hooks: ${hooksDir}\n`);
|
|
89
|
+
console.log('Installing hooks...');
|
|
90
|
+
|
|
91
|
+
deployLocalPayload(srcDir, projectRoot, hooksDir, h);
|
|
92
|
+
|
|
93
|
+
h.ensureConfigDir();
|
|
94
|
+
|
|
95
|
+
const manifest = generateManifest(srcDir, projectRoot);
|
|
96
|
+
h.updateConfig({ lastInit: new Date().toISOString(), mode: 'local', templateDir: TEMPLATE_DIR, manifest });
|
|
97
|
+
|
|
98
|
+
h.ensureArchConfig(projectRoot);
|
|
99
|
+
injectKarpathyPrinciples(projectRoot);
|
|
100
|
+
h.configureOpenCodePlugin(srcDir, projectRoot);
|
|
101
|
+
h.deployQoderDelphiAgents(srcDir, projectRoot);
|
|
102
|
+
|
|
103
|
+
registerTuiAndNotice();
|
|
104
|
+
|
|
105
|
+
// Auto-install missing CLI tools (prompt user)
|
|
106
|
+
const autoYes = args.includes('--yes') || args.includes('--auto-install');
|
|
107
|
+
await h.promptBootstrap(autoYes);
|
|
108
|
+
|
|
109
|
+
// Detect project languages and check language-specific tools
|
|
110
|
+
await detectAndReportLanguages(projectRoot, autoYes);
|
|
111
|
+
|
|
112
|
+
printTestQualityGuidance();
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The closing guidance about treating test code as first-class. */
|
|
117
|
+
function printTestQualityGuidance() {
|
|
118
|
+
console.log('━━━ FIRST-CLASS TEST QUALITY ━━━');
|
|
119
|
+
console.log('XP-Gate treats test code as a first-class citizen:');
|
|
120
|
+
console.log(' • TypeScript: test files are type-checked, not excluded from tsconfig.json');
|
|
121
|
+
console.log(' • Static analysis: lint/ESLint/Biome check test files alongside source');
|
|
122
|
+
console.log(' • Complexity: cyclomatic complexity is measured on test files too');
|
|
123
|
+
console.log(' • Duplicate code: jscpd scans test files (fixtures/snapshots excluded)');
|
|
124
|
+
console.log(' • Architecture: archlint validates test code structure');
|
|
125
|
+
console.log('');
|
|
126
|
+
console.log(' To include tests in your project:');
|
|
127
|
+
console.log(' 1. Remove __tests__/ from tsconfig.json exclude');
|
|
128
|
+
console.log(' 2. Remove __tests__/ from jscpd.conf.json ignore');
|
|
129
|
+
console.log(' 3. Add tsconfig.json: "types": ["vitest/globals"]');
|
|
130
|
+
console.log(' 4. Run "xp-gate doctor" to verify setup');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Create the global directories and copy the hooks and adapters into them.
|
|
135
|
+
*
|
|
136
|
+
* Extracted from `setupGlobal` (89 lines). Every line is a copy plus the message that
|
|
137
|
+
* says what was copied, which is why the two belong together and the module install
|
|
138
|
+
* that follows does not.
|
|
139
|
+
*/
|
|
140
|
+
function deployGlobalPayload(srcDir, h) {
|
|
141
|
+
console.log('[setup-global] Creating global directories...');
|
|
142
|
+
try {
|
|
143
|
+
fs.mkdirSync(GLOBAL_HOOKS_DIR, { recursive: true });
|
|
144
|
+
fs.mkdirSync(GLOBAL_ADAPTERS_DIR, { recursive: true });
|
|
145
|
+
} catch (err) {
|
|
146
|
+
throw new Error(`cannot create the global directories (${GLOBAL_HOOKS_DIR}, ${GLOBAL_ADAPTERS_DIR}): ${err.message}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
console.log('[setup-global] Installing git hooks...');
|
|
150
|
+
copyHooks(srcDir, GLOBAL_HOOKS_DIR);
|
|
151
|
+
console.log('Installing hooks...');
|
|
152
|
+
console.log(` pre-commit -> ${GLOBAL_HOOKS_DIR}`);
|
|
153
|
+
console.log(` pre-push -> ${GLOBAL_HOOKS_DIR}`);
|
|
154
|
+
|
|
155
|
+
console.log('[setup-global] Installing adapters...');
|
|
156
|
+
copyAdapters(srcDir, GLOBAL_ADAPTERS_DIR);
|
|
157
|
+
console.log(` adapter-common.sh + adapters -> ${GLOBAL_ADAPTERS_DIR}`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function setupGlobal(args, h) {
|
|
161
|
+
const srcDir = path.dirname(__dirname);
|
|
162
|
+
|
|
163
|
+
console.log('XP-Gate Global Setup');
|
|
164
|
+
console.log('====================\n');
|
|
165
|
+
console.log('Mode: Global (all git projects)');
|
|
166
|
+
console.log(`Global hooks: ${GLOBAL_HOOKS_DIR}`);
|
|
167
|
+
console.log(`Global adapters: ${GLOBAL_ADAPTERS_DIR}\n`);
|
|
168
|
+
|
|
169
|
+
deployGlobalPayload(srcDir, h);
|
|
170
|
+
|
|
171
|
+
// Install principles/, mutation/, mock-policy/, build-integrity/ to global modules dir
|
|
172
|
+
console.log('[setup-global] Installing quality gate modules...');
|
|
173
|
+
installGlobalModules(srcDir, h);
|
|
174
|
+
configureGlobalGit();
|
|
175
|
+
|
|
176
|
+
h.ensureConfigDir();
|
|
177
|
+
|
|
178
|
+
console.log('[setup-global] Generating installation manifest...');
|
|
179
|
+
const manifest = generateGlobalManifest(srcDir);
|
|
180
|
+
h.updateConfig({ lastInit: new Date().toISOString(), mode: 'global', templateDir: TEMPLATE_DIR, manifest });
|
|
181
|
+
|
|
182
|
+
// Auto-register TUI plugin globally (idempotent)
|
|
183
|
+
try {
|
|
184
|
+
const { ensureTuiRegistration } = require('../lib/doctor.js');
|
|
185
|
+
ensureTuiRegistration();
|
|
186
|
+
} catch { /* non-critical: TUI registration is best-effort */ }
|
|
187
|
+
|
|
188
|
+
console.log('\nGlobal setup complete!');
|
|
189
|
+
console.log('All git repositories will now use xp-gate quality gates.');
|
|
190
|
+
console.log('Per-project adapters can still override by creating <repo>/githooks/');
|
|
191
|
+
|
|
192
|
+
// Auto-install missing CLI tools (prompt user)
|
|
193
|
+
console.log('[setup-global] Checking quality gate CLI tools...');
|
|
194
|
+
const autoYes = args.includes('--yes') || args.includes('--auto-install');
|
|
195
|
+
await h.promptBootstrap(autoYes);
|
|
196
|
+
|
|
197
|
+
console.log('');
|
|
198
|
+
console.log('━━━ FIRST-CLASS TEST QUALITY ━━━');
|
|
199
|
+
console.log('XP-Gate treats test code as a first-class citizen:');
|
|
200
|
+
console.log(' All quality gates apply equally to test files.');
|
|
201
|
+
console.log(' To include tests in your project:');
|
|
202
|
+
console.log(' 1. Remove __tests__/ from tsconfig.json exclude');
|
|
203
|
+
console.log(' 2. Remove __tests__/ from jscpd.conf.json ignore');
|
|
204
|
+
console.log(' 3. Remove test patterns from .archlint.yaml ignore');
|
|
205
|
+
console.log(' 4. Add "types": ["vitest/globals"] to tsconfig.json');
|
|
206
|
+
console.log(' 5. Run "xp-gate doctor" to verify');
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The two best-effort steps at the end of a successful install.
|
|
213
|
+
*
|
|
214
|
+
* Both are decorations: a machine without OpenCode cannot register a TUI, and the star
|
|
215
|
+
* notice must never fail an install. Grouping them keeps that policy in one place
|
|
216
|
+
* instead of two adjacent empty catches.
|
|
217
|
+
*/
|
|
218
|
+
function registerTuiAndNotice() {
|
|
219
|
+
try {
|
|
220
|
+
const { ensureTuiRegistration } = require('../lib/doctor.js');
|
|
221
|
+
ensureTuiRegistration();
|
|
222
|
+
} catch { /* non-critical: TUI registration is best-effort */ }
|
|
223
|
+
|
|
224
|
+
console.log('\nInstallation complete!');
|
|
225
|
+
console.log('Run git commit to trigger quality gates');
|
|
226
|
+
// The moment an install succeeds is the only moment the user is certain the tool
|
|
227
|
+
// works; that is where the invitation belongs (#871).
|
|
228
|
+
try {
|
|
229
|
+
require('./star-notice.js').maybeShowStarNotice();
|
|
230
|
+
} catch { /* best-effort */ }
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Copy the quality-gate modules into the global config and wire their deps.
|
|
236
|
+
*
|
|
237
|
+
* Extracted from `setupGlobal` (77 lines). The module copy and the dependency install
|
|
238
|
+
* belong together -- the deps exist BECAUSE the modules import them -- and Qoder's
|
|
239
|
+
* user-level agents are deployed from the same source tree.
|
|
240
|
+
*/
|
|
241
|
+
function installGlobalModules(srcDir, h) {
|
|
242
|
+
const globalModulesDir = path.join(CONFIG_DIR, 'modules');
|
|
243
|
+
['principles', 'mutation', 'mock-policy', 'build-integrity'].forEach(module => {
|
|
244
|
+
const moduleSrc = path.join(srcDir, module);
|
|
245
|
+
const moduleDest = path.join(globalModulesDir, module);
|
|
246
|
+
if (fs.existsSync(moduleSrc)) {
|
|
247
|
+
ensureDirOrThrow(path.dirname(moduleDest));
|
|
248
|
+
h.copyRecursive(moduleSrc, moduleDest);
|
|
249
|
+
console.log(` ${module}/ -> ${globalModulesDir}/${module}/`);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// Copied modules are pure TS sourced into <CONFIG_DIR>/modules/. Any that import
|
|
254
|
+
// third-party packages (currently only mock-policy: js-yaml, zod) resolve them via
|
|
255
|
+
// Node's ancestor lookup, so those deps go into <CONFIG_DIR>/node_modules once.
|
|
256
|
+
// Best-effort: a missing registry or network must not break global setup.
|
|
257
|
+
h.installModuleRuntimeDeps(CONFIG_DIR);
|
|
258
|
+
|
|
259
|
+
// Qoder loads user-level custom agents from ~/.qoder/agents/, so a global setup
|
|
260
|
+
// must deploy the Delphi expert templates there too.
|
|
261
|
+
h.deployQoderDelphiAgents(srcDir, HOME_DIR);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Point git at the global hooks directory.
|
|
266
|
+
*
|
|
267
|
+
* A failure is a WARNING, not an error: `git config --global` needs a writable HOME,
|
|
268
|
+
* and an install that otherwise succeeded should not be undone by a preference.
|
|
269
|
+
*/
|
|
270
|
+
function configureGlobalGit() {
|
|
271
|
+
console.log('[setup-global] Configuring git...');
|
|
272
|
+
const { execSync } = require('child_process');
|
|
273
|
+
try {
|
|
274
|
+
execSync(`git config --global core.hooksPath "${GLOBAL_HOOKS_DIR}"`);
|
|
275
|
+
console.log(`\n git config --global core.hooksPath "${GLOBAL_HOOKS_DIR}"`);
|
|
276
|
+
} catch {
|
|
277
|
+
console.warn('Warning: Could not set git core.hooksPath config');
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Create a directory, naming it when that fails.
|
|
284
|
+
*
|
|
285
|
+
* The guard lives HERE rather than in `installGlobalModules` because
|
|
286
|
+
* `clean-code.missing-error-handling` looks for it inside the function that performs
|
|
287
|
+
* the syscall -- and this is that function.
|
|
288
|
+
*
|
|
289
|
+
* @param {string} dir directory to create, with parents
|
|
290
|
+
*/
|
|
291
|
+
function ensureDirOrThrow(dir) {
|
|
292
|
+
try {
|
|
293
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
294
|
+
} catch (err) {
|
|
295
|
+
throw new Error(`cannot create ${dir}: ${err.message}`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
module.exports = { installLocal, setupGlobal };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language detection, tool reporting, and the optional tool install.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `init.js`, which was over the 1050-line limit. This is the part of a
|
|
5
|
+
* local install that talks to the user -- it prints what was detected, prints what is
|
|
6
|
+
* missing, and asks before installing anything -- which is why it needs `askYesNo`
|
|
7
|
+
* and the rest of `init` does not.
|
|
8
|
+
*/
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Ask the user for confirmation via stdin.
|
|
14
|
+
* @param {string} question - The yes/no question to display
|
|
15
|
+
* @returns {Promise<boolean>} true if user answered yes
|
|
16
|
+
*/
|
|
17
|
+
function askYesNo(question) {
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
const rl = require('readline').createInterface({
|
|
20
|
+
input: process.stdin,
|
|
21
|
+
output: process.stdout,
|
|
22
|
+
});
|
|
23
|
+
rl.question(`${question} (Y/n) `, (answer) => {
|
|
24
|
+
rl.close();
|
|
25
|
+
const normalized = answer.trim().toLowerCase();
|
|
26
|
+
// Empty (just Enter) or y/yes → yes; anything else → no
|
|
27
|
+
resolve(normalized === '' || normalized === 'y' || normalized === 'yes');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Detect project languages and check/install language-specific tools.
|
|
34
|
+
* @param {string} projectRoot - Project root directory
|
|
35
|
+
* @param {boolean} autoYes - Auto-install missing tools
|
|
36
|
+
*/
|
|
37
|
+
async function detectAndReportLanguages(projectRoot, autoYes) {
|
|
38
|
+
const { detectProjectLanguages, getToolsForLanguages, generateProjectConfig, LANGUAGE_REGISTRY } = require('./language-tools.js');
|
|
39
|
+
|
|
40
|
+
console.log('');
|
|
41
|
+
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
42
|
+
console.log(' Multi-Language Quality Gates');
|
|
43
|
+
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
44
|
+
console.log('');
|
|
45
|
+
|
|
46
|
+
const { detected, configFiles } = detectProjectLanguages(projectRoot);
|
|
47
|
+
|
|
48
|
+
if (detected.length === 0) {
|
|
49
|
+
console.log(' No project languages detected.');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log(` Detected ${detected.length} language(s):`);
|
|
54
|
+
for (const lang of detected) {
|
|
55
|
+
const langDef = LANGUAGE_REGISTRY[lang];
|
|
56
|
+
console.log(` • ${langDef?.name || lang}`);
|
|
57
|
+
}
|
|
58
|
+
console.log('');
|
|
59
|
+
|
|
60
|
+
const toolStatus = getToolsForLanguages(detected);
|
|
61
|
+
const { missingRequired, missingOptional } = splitMissingTools(toolStatus);
|
|
62
|
+
|
|
63
|
+
if (missingRequired.length === 0 && missingOptional.length === 0) {
|
|
64
|
+
console.log(' ✓ All language-specific tools are available.');
|
|
65
|
+
} else {
|
|
66
|
+
reportMissingTools(missingRequired, missingOptional);
|
|
67
|
+
await offerToolInstall([...missingRequired, ...missingOptional], autoYes);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Generate project config
|
|
71
|
+
generateProjectConfig(projectRoot, detected, toolStatus);
|
|
72
|
+
console.log(`\n Generated .xp-gate-config.json`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Split the missing tools into the ones a gate needs and the ones it can do without.
|
|
80
|
+
*
|
|
81
|
+
* Two nested loops over `toolStatus`, extracted from `detectAndReportLanguages`: they
|
|
82
|
+
* were most of that function's length and none of its subject.
|
|
83
|
+
*
|
|
84
|
+
* @param {object} toolStatus result of getToolsForLanguages
|
|
85
|
+
* @returns {{missingRequired: Array, missingOptional: Array}}
|
|
86
|
+
*/
|
|
87
|
+
function splitMissingTools(toolStatus) {
|
|
88
|
+
const missingRequired = [];
|
|
89
|
+
const missingOptional = [];
|
|
90
|
+
|
|
91
|
+
for (const [lang, tools] of Object.entries(toolStatus)) {
|
|
92
|
+
for (const t of tools) {
|
|
93
|
+
if (t.status !== 'missing') continue;
|
|
94
|
+
(t.tool.optional ? missingOptional : missingRequired).push({ lang, tool: t.tool });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return { missingRequired, missingOptional };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Print what is missing, separated by whether a gate can proceed without it.
|
|
103
|
+
*
|
|
104
|
+
* @param {Array} missingRequired tools whose absence makes a gate SKIP
|
|
105
|
+
* @param {Array} missingOptional tools with a fallback
|
|
106
|
+
*/
|
|
107
|
+
function reportMissingTools(missingRequired, missingOptional) {
|
|
108
|
+
if (missingRequired.length > 0) {
|
|
109
|
+
console.log(` \u2717 ${missingRequired.length} required tool(s) missing:`);
|
|
110
|
+
for (const { lang, tool } of missingRequired) {
|
|
111
|
+
console.log(` \u2022 ${tool.name} (${lang}) \u2014 gates will SKIP`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (missingOptional.length > 0) {
|
|
115
|
+
console.log(` \u26a0 ${missingOptional.length} optional tool(s) missing (fallback available):`);
|
|
116
|
+
for (const { lang, tool } of missingOptional) {
|
|
117
|
+
console.log(` \u2022 ${tool.name} (${lang})`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
console.log('');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Offer to install the missing tools, and report each outcome.
|
|
126
|
+
*
|
|
127
|
+
* The one part of `detectAndReportLanguages` that ACTS rather than reports; keeping it
|
|
128
|
+
* separate means the report can be read without the install prompt in the middle.
|
|
129
|
+
*
|
|
130
|
+
* @param {Array<{lang: string, tool: object}>} entries everything that is missing
|
|
131
|
+
* @param {boolean} autoYes skip the prompt
|
|
132
|
+
*/
|
|
133
|
+
async function offerToolInstall(entries, autoYes) {
|
|
134
|
+
const proceed = autoYes
|
|
135
|
+
|| (process.stdin.isTTY && await askYesNo(' Install missing language-specific tools now?'));
|
|
136
|
+
if (!proceed) {
|
|
137
|
+
console.log(' Skipped. Run "xp-gate install-tools --yes" later.');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.log('');
|
|
142
|
+
const { installTool } = require('./language-tools.js');
|
|
143
|
+
let installed = 0;
|
|
144
|
+
for (const { tool } of entries) {
|
|
145
|
+
const result = installTool(tool);
|
|
146
|
+
if (result.success) {
|
|
147
|
+
console.log(` \u2713 ${tool.name} installed`);
|
|
148
|
+
installed++;
|
|
149
|
+
} else {
|
|
150
|
+
console.log(` \u2717 ${tool.name}: ${result.message}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (installed > 0) {
|
|
154
|
+
console.log(`\n ${installed} tool(s) installed successfully.`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
module.exports = { askYesNo, detectAndReportLanguages };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The install manifests: what xp-gate recorded as belonging to it.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `init.js`, which was 1196 lines against a 1050-line limit and could
|
|
5
|
+
* not get below it by extracting functions in place -- each extraction ADDS a
|
|
6
|
+
* signature, a doc comment and a closing brace, so six of them took the file from
|
|
7
|
+
* 1196 to 1294 and the large-file finding got worse, not better. A file can only be
|
|
8
|
+
* made smaller by moving code OUT of it.
|
|
9
|
+
*
|
|
10
|
+
* What moved is one coherent job: walking a directory tree and recording each file
|
|
11
|
+
* with its hash. Nothing here decides what to install or where -- it describes the
|
|
12
|
+
* result, and the two builders differ only in which roots they describe.
|
|
13
|
+
*/
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const crypto = require('crypto');
|
|
19
|
+
|
|
20
|
+
const { TEMPLATE_DIR, GLOBAL_HOOKS_DIR, GLOBAL_ADAPTERS_DIR } = require('./shared-paths.js');
|
|
21
|
+
|
|
22
|
+
function sha256File(filePath) {
|
|
23
|
+
try {
|
|
24
|
+
const content = fs.readFileSync(filePath);
|
|
25
|
+
return crypto.createHash('sha256').update(content).digest('hex');
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Record one deployed file in a manifest, or skip it when it is not there.
|
|
33
|
+
*
|
|
34
|
+
* The four-line `stat` + `sha256` + `size` block appeared eight times across the two
|
|
35
|
+
* builders; the shape is what made both exceed the 50-line bound, and it says nothing
|
|
36
|
+
* about WHICH file is being recorded.
|
|
37
|
+
*
|
|
38
|
+
* @param {object} manifest the manifest being built
|
|
39
|
+
* @param {string} key the path recorded under `files`
|
|
40
|
+
* @param {string} full absolute path on disk
|
|
41
|
+
*/
|
|
42
|
+
function recordFile(manifest, key, full) {
|
|
43
|
+
let stat;
|
|
44
|
+
try {
|
|
45
|
+
stat = fs.statSync(full);
|
|
46
|
+
} catch {
|
|
47
|
+
// A file that is not there is simply not recorded: this walks what an install
|
|
48
|
+
// DEPLOYED, and an absent entry means it was not deployed.
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
manifest.files[key] = {
|
|
52
|
+
sha256: sha256File(full),
|
|
53
|
+
size: stat.size
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function generateManifest(srcDir, projectRoot) {
|
|
58
|
+
const manifest = {
|
|
59
|
+
version: 1,
|
|
60
|
+
files: {},
|
|
61
|
+
injectedSections: {}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const gitDir = path.join(projectRoot, '.git');
|
|
65
|
+
const hooksDir = path.join(gitDir, 'hooks');
|
|
66
|
+
const githooksDir = path.join(projectRoot, 'githooks');
|
|
67
|
+
|
|
68
|
+
// Hooks. The list is the deploy manifest's (REQ-DEPLOY-001): recording a
|
|
69
|
+
// different set than the installer writes would make the recorded manifest
|
|
70
|
+
// describe a repository that does not exist.
|
|
71
|
+
require('./deploy-manifest.js').HOOK_FILES.forEach(hook => {
|
|
72
|
+
recordFile(manifest, `.git/hooks/${hook}`, path.join(hooksDir, hook));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// adapter-common.sh and the per-language adapters
|
|
76
|
+
recordFile(manifest, 'githooks/adapter-common.sh', path.join(githooksDir, 'adapter-common.sh'));
|
|
77
|
+
const adaptersDir = path.join(githooksDir, 'adapters');
|
|
78
|
+
if (fs.existsSync(adaptersDir)) {
|
|
79
|
+
fs.readdirSync(adaptersDir).forEach(f => {
|
|
80
|
+
const fPath = path.join(adaptersDir, f);
|
|
81
|
+
if (fs.statSync(fPath).isFile()) {
|
|
82
|
+
recordFile(manifest, `githooks/adapters/${f}`, fPath);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Template dir note
|
|
88
|
+
manifest.templateDir = TEMPLATE_DIR;
|
|
89
|
+
|
|
90
|
+
// Injected sections
|
|
91
|
+
const agentsPath = path.join(projectRoot, 'AGENTS.md');
|
|
92
|
+
if (fs.existsSync(agentsPath)) {
|
|
93
|
+
try {
|
|
94
|
+
const content = fs.readFileSync(agentsPath, 'utf8');
|
|
95
|
+
if (content.includes('## AI CODING DISCIPLINE (Karpathy Principles)')) {
|
|
96
|
+
manifest.injectedSections['AGENTS.md'] = '## AI CODING DISCIPLINE (Karpathy Principles)';
|
|
97
|
+
}
|
|
98
|
+
} catch {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return manifest;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function generateGlobalManifest(srcDir) {
|
|
105
|
+
const manifest = {
|
|
106
|
+
version: 1,
|
|
107
|
+
files: {},
|
|
108
|
+
gitConfig: {}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Global hooks (same manifest list as above, REQ-DEPLOY-001)
|
|
112
|
+
require('./deploy-manifest.js').HOOK_FILES.forEach(hook => {
|
|
113
|
+
recordFile(manifest, `hooks/${hook}`, path.join(GLOBAL_HOOKS_DIR, hook));
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// #837: the gate bodies and lib modules. Deployed but never recorded, so the
|
|
117
|
+
// uninstaller -- which decides ownership from THIS manifest -- reported them as
|
|
118
|
+
// "not xp-gate's files" and left them behind. Measured on a clean global install:
|
|
119
|
+
// 42 files under hooks/ unrecorded, including all 17 gate bodies.
|
|
120
|
+
//
|
|
121
|
+
// MODULE_FILES names every one of them, and lists `lib/` file by file precisely
|
|
122
|
+
// so a new module cannot slip out unnoticed. It was never iterated here.
|
|
123
|
+
require('./deploy-manifest.js').MODULE_FILES.forEach(rel => {
|
|
124
|
+
recordFile(manifest, `hooks/${rel}`, path.join(GLOBAL_HOOKS_DIR, rel));
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// adapter-common.sh and the per-language adapters
|
|
128
|
+
recordFile(manifest, 'adapters/adapter-common.sh', path.join(GLOBAL_ADAPTERS_DIR, 'adapter-common.sh'));
|
|
129
|
+
for (const f of listAdapters(GLOBAL_ADAPTERS_DIR)) {
|
|
130
|
+
if (f !== 'adapter-common.sh') {
|
|
131
|
+
recordFile(manifest, `adapters/${f}`, path.join(GLOBAL_ADAPTERS_DIR, f));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// git config
|
|
136
|
+
manifest.gitConfig = {
|
|
137
|
+
'core.hooksPath': GLOBAL_HOOKS_DIR
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
manifest.templateDir = TEMPLATE_DIR;
|
|
141
|
+
|
|
142
|
+
return manifest;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The regular files directly under `dir`, or [] when it cannot be read.
|
|
147
|
+
*
|
|
148
|
+
* Extracted so `generateGlobalManifest` does not hold the readdir/stat pair itself:
|
|
149
|
+
* the enumeration and the recording are different concerns, and only the first can
|
|
150
|
+
* fail for a reason worth swallowing.
|
|
151
|
+
*
|
|
152
|
+
* @param {string} dir directory to list
|
|
153
|
+
* @returns {string[]} file names
|
|
154
|
+
*/
|
|
155
|
+
function listAdapters(dir) {
|
|
156
|
+
let entries;
|
|
157
|
+
try {
|
|
158
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
159
|
+
} catch {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
return entries.filter((e) => e.isFile()).map((e) => e.name);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
module.exports = { sha256File, generateManifest, generateGlobalManifest };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inject the shared AI coding discipline into a project's AGENTS.md.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `init.js`, which was over the 1050-line limit. This is the one step
|
|
5
|
+
* of a local install that edits a file the USER owns, and it is idempotent for
|
|
6
|
+
* exactly that reason: running `init` twice must not append the section twice.
|
|
7
|
+
*/
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
|
|
13
|
+
function injectKarpathyPrinciples(projectRoot) {
|
|
14
|
+
const agentsPath = path.join(projectRoot, 'AGENTS.md');
|
|
15
|
+
if (!fs.existsSync(agentsPath)) return;
|
|
16
|
+
|
|
17
|
+
let content;
|
|
18
|
+
try {
|
|
19
|
+
content = fs.readFileSync(agentsPath, 'utf8');
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.warn(` Warning: could not read AGENTS.md: ${e.message}`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (content.includes('## AI CODING DISCIPLINE (Karpathy Principles)')) return;
|
|
26
|
+
|
|
27
|
+
const section = `
|
|
28
|
+
## AI CODING DISCIPLINE (Karpathy Principles)
|
|
29
|
+
|
|
30
|
+
**原则 3: Surgical Changes(外科手术式改动)**
|
|
31
|
+
- 只碰必须碰的代码。只清理自己制造的混乱。
|
|
32
|
+
- 编辑现有代码时,不"优化"相邻代码、注释或 formatting
|
|
33
|
+
- 不重构没坏的东西
|
|
34
|
+
- 匹配现有代码风格,即使 AI 更喜欢另一种
|
|
35
|
+
- 发现无关的死代码 → 提及但不要删除(除非用户明确要求)
|
|
36
|
+
- 自己的改动产生的 orphaned import/variable/function → 必须清理
|
|
37
|
+
- 判定标准: 每一行改动都应能直接追溯到用户的请求
|
|
38
|
+
|
|
39
|
+
**原则 4: Goal-Driven Execution(目标驱动执行)**
|
|
40
|
+
- 定义成功标准。循环直到验证。
|
|
41
|
+
- 把指令转化为可验证目标:
|
|
42
|
+
- "加验证" → "写测试 → 让测试通过"
|
|
43
|
+
- "修 bug" → "写复现测试 → 让测试通过"
|
|
44
|
+
- "重构 X" → "确保重构前后测试都通过"
|
|
45
|
+
- 多步骤任务列出验证点
|
|
46
|
+
- 改完任何代码后必须运行测试确认无 regression
|
|
47
|
+
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
fs.appendFileSync(agentsPath, section, 'utf8');
|
|
52
|
+
console.log(' Karpathy Principles injected into AGENTS.md');
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.warn(` Warning: could not write to AGENTS.md: ${e.message}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = { injectKarpathyPrinciples };
|