@boyingliu01/xp-gate 0.36.1 → 0.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapters/cpp.sh +78 -10
- package/adapters/csharp.sh +58 -3
- package/adapters/gate-3.sh +15 -5
- package/adapters/gate-8.sh +131 -9
- package/adapters/typescript.sh +32 -8
- package/build-integrity/__tests__/import-resolver.test.ts +257 -0
- package/build-integrity/__tests__/quote-masker.test.ts +177 -0
- package/build-integrity/gate-10.ts +127 -9
- package/build-integrity/quote-masker.ts +266 -0
- package/gate-10.sh +66 -0
- package/gate-12-file-hygiene.sh +15 -7
- package/gate-13-compiler-strictness.sh +81 -1
- package/gate-3.sh +15 -5
- package/gate-6-layers.sh +375 -0
- package/gate-8.sh +131 -9
- package/hooks/gate-10.sh +66 -0
- package/hooks/gate-12-file-hygiene.sh +15 -7
- package/hooks/gate-13-compiler-strictness.sh +81 -1
- package/hooks/gate-3.sh +15 -5
- package/hooks/gate-6-layers.sh +375 -0
- package/hooks/gate-8.sh +131 -9
- package/hooks/gate-registry.sh +2 -2
- package/hooks/hook-module-resolution.sh +1 -1
- package/hooks/lib/assertion-quality.sh +8 -2
- package/hooks/lib/ccn-ratchet.sh +10 -0
- package/hooks/lib/layer-baseline.cjs +88 -0
- package/hooks/lib/typecheck.sh +28 -5
- package/hooks/pre-commit +376 -53
- package/hooks/pre-push +46 -13
- package/lib/__tests__/agent-runtime-journal.test.js +1 -1
- package/lib/__tests__/arch.test.js +9 -0
- package/lib/__tests__/audit-cli-contract.test.ts +1 -1
- package/lib/__tests__/check-alignment-reasons.test.mjs +11 -1
- package/lib/__tests__/check-all-skip-accounting.test.js +1 -1
- package/lib/__tests__/detect-deps-gate-identity.test.js +135 -0
- package/lib/__tests__/detect-deps.test.js +2 -1
- package/lib/__tests__/doctor-469-hook-env.test.js +7 -1
- package/lib/__tests__/doctor-arch-tools.test.js +169 -0
- package/lib/__tests__/doctor-delphi.test.js +1 -1
- package/lib/__tests__/doctor-drift-round2.test.js +4 -1
- package/lib/__tests__/doctor-executed-surface.test.js +45 -24
- package/lib/__tests__/doctor-module-drift.test.js +13 -7
- package/lib/__tests__/doctor-module-resolution-parity.test.js +74 -2
- package/lib/__tests__/doctor-tui-skill-freshness.test.js +21 -6
- package/lib/__tests__/doctor.test.js +17 -0
- package/lib/__tests__/gate-runner-tsx-invocation.test.js +149 -0
- package/lib/__tests__/gate-runner.test.js +23 -7
- package/lib/__tests__/init-gitignore.test.js +204 -0
- package/lib/__tests__/init.test.js +24 -3
- package/lib/__tests__/language-tools-build-file-install.test.js +82 -0
- package/lib/__tests__/language-tools-detect.test.js +61 -0
- package/lib/__tests__/mirror-sync.test.js +2 -0
- package/lib/__tests__/phase-transition.test.js +19 -1
- package/lib/__tests__/sprint-status-rework.test.js +32 -12
- package/lib/__tests__/test-alignment-range-guard.test.ts +82 -0
- package/lib/__tests__/test-alignment.test.ts +13 -3
- package/lib/__tests__/update-skill.test.js +2 -2
- package/lib/detect-deps.js +7 -1
- package/lib/doctor.js +81 -17
- package/lib/gate-runner.js +101 -7
- package/lib/hook-module-resolution.js +18 -6
- package/lib/init.js +136 -1
- package/lib/language-tools.js +217 -1
- package/lib/layer-baseline.cjs +88 -0
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/principles.js +21 -6
- package/lib/test-alignment.ts +452 -55
- package/mock-policy/AGENTS.md +1 -1
- package/mutation/AGENTS.md +1 -1
- package/package.json +2 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/.delphi-config.json.example +34 -24
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/delphi-review/INSTALL.md +29 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/.delphi-config.json.example +34 -24
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/delphi-review/INSTALL.md +29 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/src/client.test.ts +1 -1
- package/plugins/dsh/src/command.test.ts +1 -1
- package/plugins/dsh/src/contract.test.ts +1 -1
- package/plugins/dsh/src/credentials.test.ts +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +34 -24
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/delphi-review/INSTALL.md +29 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/.delphi-config.json.example +34 -24
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/delphi-review/INSTALL.md +29 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/principles/AGENTS.md +1 -1
- package/principles/__tests__/config-arch-group.test.ts +106 -0
- package/principles/__tests__/config-enforcement.test.ts +1 -1
- package/principles/adapters/control-nesting.ts +572 -0
- package/principles/adapters/csharp.ts +73 -42
- package/principles/adapters/java.ts +9 -5
- package/principles/adapters/typescript.ts +138 -176
- package/principles/config.ts +37 -2
- package/principles/index.ts +57 -4
- package/principles/reporter.ts +99 -65
- package/principles/rules/arch/__tests__/dependency.test.ts +180 -0
- package/principles/rules/arch/__tests__/naming.test.ts +133 -0
- package/principles/rules/arch/__tests__/shared.test.ts +113 -0
- package/principles/rules/arch/dependency.ts +264 -0
- package/principles/rules/arch/naming.ts +188 -0
- package/principles/rules/arch/shared.ts +169 -0
- package/principles/rules/exports.ts +26 -0
- package/principles/rules/index.ts +11 -18
- package/scripts/__tests__/sync-package-content.test.js +23 -1
- package/scripts/sync-package-content.js +8 -2
- package/skills/delphi-review/.delphi-config.json.example +34 -24
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/delphi-review/INSTALL.md +29 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
package/lib/gate-runner.js
CHANGED
|
@@ -356,11 +356,103 @@ function resolveGateCwd(targetPath) {
|
|
|
356
356
|
* plain argv, no shell, no batch wrapper.
|
|
357
357
|
*/
|
|
358
358
|
function resolveNpxInvocation(args) {
|
|
359
|
-
const npxCli =
|
|
360
|
-
if (
|
|
359
|
+
const npxCli = findNpxCli();
|
|
360
|
+
if (npxCli) return [process.execPath, [npxCli, ...args]];
|
|
361
361
|
return ['npx', args];
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
/**
|
|
365
|
+
* npm's own shell-free entry point (`npx-cli.js`), or null.
|
|
366
|
+
*
|
|
367
|
+
* The previous form looked only in `dirname(process.execPath)/node_modules/npm`,
|
|
368
|
+
* which is the layout of a Node installed from the Windows MSI or the official
|
|
369
|
+
* tarball. GitHub's `actions/setup-node` on Linux runs node from
|
|
370
|
+
* `/opt/hostedtoolcache/node/<version>/x64/bin/node`, where npm's library lives
|
|
371
|
+
* under `lib/node_modules/npm` instead — so the probe missed, the fallback became
|
|
372
|
+
* a bare `npx`, and that is unresolvable without a shell on Windows and a PATH hop
|
|
373
|
+
* everywhere else. CI caught it as two red assertions; the same install shape
|
|
374
|
+
* would have made the gate spawn the wrong thing on a developer's Linux box.
|
|
375
|
+
*
|
|
376
|
+
* Searches the same way `findTsxCli` does — one directory at a time, both the
|
|
377
|
+
* plain and the `lib/` npm layout — because "npm sits next to node" is an
|
|
378
|
+
* assumption about how Node was packaged, not a guarantee.
|
|
379
|
+
*/
|
|
380
|
+
function findNpxCli() {
|
|
381
|
+
let dir = path.dirname(process.execPath);
|
|
382
|
+
for (let depth = 0; depth < TSX_SEARCH_DEPTH; depth += 1) {
|
|
383
|
+
for (const npmRoot of ['node_modules', path.join('lib', 'node_modules')]) {
|
|
384
|
+
const candidate = path.join(dir, npmRoot, 'npm', 'bin', 'npx-cli.js');
|
|
385
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
386
|
+
}
|
|
387
|
+
const parent = path.dirname(dir);
|
|
388
|
+
if (parent === dir) break;
|
|
389
|
+
dir = parent;
|
|
390
|
+
}
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* How deep to look for a hoisted `node_modules/tsx` before giving up.
|
|
396
|
+
*
|
|
397
|
+
* Four is enough for the layouts that actually occur — `<repo>/node_modules`,
|
|
398
|
+
* `<repo>/src/npm-package/node_modules`, a git worktree's shared parent, and one
|
|
399
|
+
* level of monorepo nesting — without turning a miss into an unbounded walk up to
|
|
400
|
+
* the filesystem root.
|
|
401
|
+
*/
|
|
402
|
+
const TSX_SEARCH_DEPTH = 4;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* The nearest installed `tsx` CLI entry, or null.
|
|
406
|
+
*
|
|
407
|
+
* #779: every TypeScript gate used to be launched as `npx -y tsx <entry> --run`, and
|
|
408
|
+
* `npx -y` re-resolves where the package lives on EVERY call. Measured on this
|
|
409
|
+
* machine: `npx -y tsx --version` takes 4547-5811 ms while `node <tsx-cli> --version`
|
|
410
|
+
* takes 787-821 ms. That is ~4 s of pure package-resolution paid once per TS gate,
|
|
411
|
+
* and `xp-gate check --all` runs several — which is how a one-file project reached
|
|
412
|
+
* 117 s (the /tmp measurement in the governance review).
|
|
413
|
+
*
|
|
414
|
+
* Searching upward matters because the CLI is normally invoked from a CONSUMER
|
|
415
|
+
* project whose `node_modules` lives at the project root, while the gate module is
|
|
416
|
+
* resolved from the xp-gate install.
|
|
417
|
+
*
|
|
418
|
+
* @param {string} [cwd] directory to start from; defaults to process.cwd()
|
|
419
|
+
* @returns {string|null}
|
|
420
|
+
*/
|
|
421
|
+
function findTsxCli(cwd = process.cwd()) {
|
|
422
|
+
let dir = path.resolve(cwd);
|
|
423
|
+
for (let depth = 0; depth < TSX_SEARCH_DEPTH; depth += 1) {
|
|
424
|
+
const candidate = path.join(dir, 'node_modules', 'tsx', 'dist', 'cli.mjs');
|
|
425
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
426
|
+
const parent = path.dirname(dir);
|
|
427
|
+
if (parent === dir) break;
|
|
428
|
+
dir = parent;
|
|
429
|
+
}
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* The executable + argv for running one TypeScript gate module.
|
|
435
|
+
*
|
|
436
|
+
* Prefers `node <tsx-cli> <args>`: no shim, no shell, no network, and no repeated
|
|
437
|
+
* package resolution. Falls back to npm's own `npx-cli.js` (still under the current
|
|
438
|
+
* node binary, still shell-free) only when no tsx is installed — the shape
|
|
439
|
+
* `resolveNpxInvocation` already guarantees.
|
|
440
|
+
*
|
|
441
|
+
* A `tsx/` directory with no `dist/cli.mjs` is treated as "not installed": a
|
|
442
|
+
* half-written install would otherwise be spawned and fail with a message about
|
|
443
|
+
* missing files, which reads like a gate defect rather than an install one.
|
|
444
|
+
*
|
|
445
|
+
* @param {string[]} args tsx argv (entry path, then the gate's own flags)
|
|
446
|
+
* @param {{cwd?: string}} [opts]
|
|
447
|
+
* @returns {{command: string, args: string[], viaNpx: boolean}}
|
|
448
|
+
*/
|
|
449
|
+
function resolveTsxInvocation(args, opts = {}) {
|
|
450
|
+
const tsxCli = findTsxCli(opts.cwd);
|
|
451
|
+
if (tsxCli) return { command: process.execPath, args: [tsxCli, ...args], viaNpx: false };
|
|
452
|
+
const [command, argv] = resolveNpxInvocation(['-y', 'tsx', ...args]);
|
|
453
|
+
return { command, args: argv, viaNpx: true };
|
|
454
|
+
}
|
|
455
|
+
|
|
364
456
|
/**
|
|
365
457
|
* A project-local gate variant, if the project declares one.
|
|
366
458
|
*
|
|
@@ -431,7 +523,7 @@ function runTsGate(gateModule, targetPath, opts = {}) {
|
|
|
431
523
|
return GATE_NOT_RUN;
|
|
432
524
|
}
|
|
433
525
|
|
|
434
|
-
const args = [
|
|
526
|
+
const args = [impl.entry, '--run'];
|
|
435
527
|
if (targetPath) args.push('--cwd', targetPath);
|
|
436
528
|
|
|
437
529
|
// spawnSync reports a spawn failure (npx missing) on `error`, throws only on a
|
|
@@ -443,7 +535,9 @@ function runTsGate(gateModule, targetPath, opts = {}) {
|
|
|
443
535
|
// malformed argv, and reports a killed child (timeout, signal) as a null status.
|
|
444
536
|
// All three mean "the gate did not report a verdict", which must not be read as
|
|
445
537
|
// success: a gate that never ran is not a gate that passed.
|
|
446
|
-
|
|
538
|
+
// #779: node + tsx's own CLI, not `npx -y tsx`. Same no-shell guarantee, no
|
|
539
|
+
// per-gate package re-resolution (~4 s saved per TS gate).
|
|
540
|
+
const { command, args: commandArgs, viaNpx } = resolveTsxInvocation(args, { cwd: targetCwd });
|
|
447
541
|
try {
|
|
448
542
|
const result = spawnSync(command, commandArgs, {
|
|
449
543
|
stdio: 'inherit',
|
|
@@ -451,12 +545,12 @@ function runTsGate(gateModule, targetPath, opts = {}) {
|
|
|
451
545
|
timeout: TS_GATE_TIMEOUT_MS,
|
|
452
546
|
});
|
|
453
547
|
if (result.error) {
|
|
454
|
-
console.error(`Gate ${gateModule}: failed to run npx
|
|
548
|
+
console.error(`Gate ${gateModule}: failed to run tsx (${viaNpx ? 'npx fallback' : 'local cli'}): ${result.error.message}`);
|
|
455
549
|
return 1;
|
|
456
550
|
}
|
|
457
551
|
return result.status === null ? 1 : result.status;
|
|
458
552
|
} catch (err) {
|
|
459
|
-
console.error(`Gate ${gateModule}: could not spawn npx
|
|
553
|
+
console.error(`Gate ${gateModule}: could not spawn tsx (${viaNpx ? 'npx fallback' : 'local cli'}): ${err.message}`);
|
|
460
554
|
return 1;
|
|
461
555
|
}
|
|
462
556
|
}
|
|
@@ -798,4 +892,4 @@ async function runGate(gateId, targetPath, opts = {}) {
|
|
|
798
892
|
return 1;
|
|
799
893
|
}
|
|
800
894
|
|
|
801
|
-
module.exports = { findConsumerGateVariant, GATE_REGISTRY, GATE_NOT_RUN, getGateInfo, getAllGates, runGate, resolveAlias, getAliases, runGateAdapter, findTsGateEntry, resolveGateScript, SOURCE_FILE_EXTENSIONS, resolveAllModeChangedFiles, describeEmptyChangedFiles, describeChangedFilesScope };
|
|
895
|
+
module.exports = { findConsumerGateVariant, GATE_REGISTRY, GATE_NOT_RUN, getGateInfo, getAllGates, runGate, resolveAlias, getAliases, runGateAdapter, findTsGateEntry, resolveGateScript, resolveTsxInvocation, findTsxCli, SOURCE_FILE_EXTENSIONS, resolveAllModeChangedFiles, describeEmptyChangedFiles, describeChangedFilesScope };
|
|
@@ -91,19 +91,31 @@ const GATE_RESOLUTION_ORDER = Object.freeze([
|
|
|
91
91
|
* tree every later lookup searches, so it must have one definition.
|
|
92
92
|
*
|
|
93
93
|
* `probe` is the file whose presence in `base` makes that tier win.
|
|
94
|
+
*
|
|
95
|
+
* PRECEDENCE IS PROJECT-FIRST, on purpose. The two install modes exist to make
|
|
96
|
+
* the global copy a DEFAULT, not an override: a repo that never ran
|
|
97
|
+
* `xp-gate init` gets the global gate suite, and a repo that carries its own
|
|
98
|
+
* `githooks/` gets that one instead. The tiers used to be tried global-first,
|
|
99
|
+
* which made every per-project `githooks/` unreachable on any machine with a
|
|
100
|
+
* global install -- including this repo, whose own gate scripts therefore never
|
|
101
|
+
* ran while `git log` said they had. A project copy that cannot win is not a
|
|
102
|
+
* customisation, it is dead weight (#495 AC-495-23).
|
|
103
|
+
*
|
|
104
|
+
* Narrow -> broad: project (specific to this repo) beats global (machine-wide
|
|
105
|
+
* default) beats the hook's own directory (last resort).
|
|
94
106
|
*/
|
|
95
107
|
const ADAPTER_DIR_ORDER = Object.freeze([
|
|
96
108
|
Object.freeze({
|
|
97
|
-
tier_id: '
|
|
98
|
-
base: '
|
|
109
|
+
tier_id: 'project',
|
|
110
|
+
base: 'PROJECT_GITHOOKS',
|
|
99
111
|
probe: 'adapter-common.sh',
|
|
100
|
-
comment: '
|
|
112
|
+
comment: '<repo>/githooks — per-project init; OVERRIDES the global install',
|
|
101
113
|
}),
|
|
102
114
|
Object.freeze({
|
|
103
|
-
tier_id: '
|
|
104
|
-
base: '
|
|
115
|
+
tier_id: 'global',
|
|
116
|
+
base: 'GLOBAL_ADAPTER_DIR',
|
|
105
117
|
probe: 'adapter-common.sh',
|
|
106
|
-
comment: '
|
|
118
|
+
comment: '~/.config/xp-gate/adapters — global install (the default)',
|
|
107
119
|
}),
|
|
108
120
|
Object.freeze({
|
|
109
121
|
tier_id: 'script',
|
package/lib/init.js
CHANGED
|
@@ -374,6 +374,102 @@ async function promptBootstrap(autoYes) {
|
|
|
374
374
|
return 0;
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
+
/**
|
|
378
|
+
* Ignore rules for the files `init` generates or installs into a project.
|
|
379
|
+
*
|
|
380
|
+
* Every entry here is a MACHINE-SPECIFIC artefact: adapter copies keyed to this
|
|
381
|
+
* machine's tool paths, module mirrors regenerated on demand, the generated
|
|
382
|
+
* language config, and tool liveness markers. None is project source, so none
|
|
383
|
+
* belongs in the user's history.
|
|
384
|
+
*
|
|
385
|
+
* Deliberately EXCLUDED (they really are source and must stay commit-able):
|
|
386
|
+
* githooks/pre-commit, githooks/pre-push, githooks/gate-*.sh,
|
|
387
|
+
* githooks/adapter-common.sh, githooks/gate-registry.sh, githooks/lib/
|
|
388
|
+
* -- the hook entrypoints a user may customise, and the registry that binds gate
|
|
389
|
+
* names to the files that run them.
|
|
390
|
+
* @returns {string[]} ignore patterns to add when absent
|
|
391
|
+
*/
|
|
392
|
+
function gitignoreEntriesForInit() {
|
|
393
|
+
return [
|
|
394
|
+
'# xp-gate: generated by `xp-gate init` — machine-specific, not project source',
|
|
395
|
+
'.xp-gate-config.json',
|
|
396
|
+
'.xp-gate/modules/',
|
|
397
|
+
'.xp-gate/node_modules/',
|
|
398
|
+
'.xp-gate/package.json',
|
|
399
|
+
'.xp-gate/package-lock.json',
|
|
400
|
+
'.xp-gate/debt-breakdown.json',
|
|
401
|
+
'.xp-gate/full-audit/',
|
|
402
|
+
'.xp-gate/lint-baseline.json',
|
|
403
|
+
'.xp-gate/audit.jsonl',
|
|
404
|
+
'.xp-gate/audit.pending.jsonl',
|
|
405
|
+
'.xp-gate/bypass-audit.jsonl',
|
|
406
|
+
'.xp-gate/quality-status/',
|
|
407
|
+
'.xp-gate/reports/',
|
|
408
|
+
'.xp-gate/tmp/',
|
|
409
|
+
'.qoder/agents/',
|
|
410
|
+
'opencode.json',
|
|
411
|
+
'# xp-gate: per-language adapter copies installed into this project',
|
|
412
|
+
'githooks/cpp.sh',
|
|
413
|
+
'githooks/csharp.sh',
|
|
414
|
+
'githooks/dart.sh',
|
|
415
|
+
'githooks/flutter.sh',
|
|
416
|
+
'githooks/go.sh',
|
|
417
|
+
'githooks/iac.sh',
|
|
418
|
+
'githooks/java.sh',
|
|
419
|
+
'githooks/kotlin.sh',
|
|
420
|
+
'githooks/objectivec.sh',
|
|
421
|
+
'githooks/powershell.sh',
|
|
422
|
+
'githooks/python.sh',
|
|
423
|
+
'githooks/shell.sh',
|
|
424
|
+
'githooks/swift.sh',
|
|
425
|
+
'githooks/typescript.sh',
|
|
426
|
+
'githooks/adapters/gate-*.sh',
|
|
427
|
+
];
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Add the init ignore rules to <root>/.gitignore, skipping any already present.
|
|
432
|
+
*
|
|
433
|
+
* Appends rather than rewrites: a user's own rules (and their ordering) are
|
|
434
|
+
* theirs. Comparison is on the bare pattern so a rule already written with
|
|
435
|
+
* slightly different surrounding whitespace is still recognised, and re-running
|
|
436
|
+
* `init` is a no-op instead of appending a second block.
|
|
437
|
+
* @param {string} root - project root
|
|
438
|
+
* @returns {string[]} patterns actually added (empty when nothing was missing)
|
|
439
|
+
*/
|
|
440
|
+
function ensureGitignoreEntries(root) {
|
|
441
|
+
const gitignorePath = path.join(root, '.gitignore');
|
|
442
|
+
const existing = fs.existsSync(gitignorePath) ? fs.readFileSync(gitignorePath, 'utf8') : '';
|
|
443
|
+
// Compare on the trimmed line for BOTH rules and comments. Excluding comments
|
|
444
|
+
// from `present` (an earlier version did) made every comment look missing, so
|
|
445
|
+
// each run appended a fresh copy of the section headers while `added` stayed
|
|
446
|
+
// empty — the file grew on every `init` and the idempotency test passed anyway.
|
|
447
|
+
const present = new Set(existing.split(/\r?\n/).map((l) => l.trim()).filter(Boolean));
|
|
448
|
+
const missing = gitignoreEntriesForInit().filter((line) => !present.has(line));
|
|
449
|
+
if (missing.length === 0) return [];
|
|
450
|
+
const prefix = existing.length > 0 && !existing.endsWith('\n') ? '\n' : '';
|
|
451
|
+
const block = `${prefix}${existing.length > 0 ? '\n' : ''}${missing.join('\n')}\n`;
|
|
452
|
+
// Write via a temp file + rename. A plain writeFileSync truncates first, so an
|
|
453
|
+
// ENOSPC or a killed process mid-write would leave the user's .gitignore
|
|
454
|
+
// truncated — destroying rules we promised to preserve, in a file we do not own.
|
|
455
|
+
// rename() is atomic within a directory: the file is either the old content or
|
|
456
|
+
// the complete new content.
|
|
457
|
+
const tmpPath = `${gitignorePath}.xp-gate-tmp`;
|
|
458
|
+
try {
|
|
459
|
+
fs.writeFileSync(tmpPath, existing + block);
|
|
460
|
+
fs.renameSync(tmpPath, gitignorePath);
|
|
461
|
+
} catch (e) {
|
|
462
|
+
try { fs.rmSync(tmpPath, { force: true }); } catch { /* best effort */ }
|
|
463
|
+
throw e;
|
|
464
|
+
}
|
|
465
|
+
// Report only rules, not the explanatory comments.
|
|
466
|
+
return missing.filter((line) => !line.startsWith('#'));
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Initialize XP-Gate in the current project.
|
|
471
|
+
* @param {string[]} args - CLI arguments
|
|
472
|
+
*/
|
|
377
473
|
async function init(args) {
|
|
378
474
|
console.log('XP-Gate Initialization');
|
|
379
475
|
console.log('====================\n');
|
|
@@ -410,6 +506,45 @@ async function init(args) {
|
|
|
410
506
|
if (!installMode) { printUsage(); return 0; }
|
|
411
507
|
if (installMode === 'global') return setupGlobal(args);
|
|
412
508
|
const code = await installLocal(args);
|
|
509
|
+
// #767: installLocal writes adapters, .xp-gate/ and the generated config into the
|
|
510
|
+
// project. Without ignore rules every one of those shows up as an untracked entry,
|
|
511
|
+
// and the file-hygiene/debt gates then treat generated output as uncommitted
|
|
512
|
+
// source — a zero-tolerance Gate 6 BLOCK the user cannot repair except by hand.
|
|
513
|
+
// Done AFTER the install so it only claims files that actually exist.
|
|
514
|
+
if (code === 0) {
|
|
515
|
+
// Root comes from getGitDir(), the SAME resolution installLocal used. Reading
|
|
516
|
+
// process.cwd() instead would write .gitignore to whatever subdirectory the
|
|
517
|
+
// user happened to run from while the adapters landed at the repo root — the
|
|
518
|
+
// rules would then guard the wrong tree.
|
|
519
|
+
//
|
|
520
|
+
// A failure here is a WARNING with a repair hint, never a silent skip: a
|
|
521
|
+
// read-only checkout leaves the user in exactly the #767 state, so exiting 0
|
|
522
|
+
// quietly would hide the defect this closes.
|
|
523
|
+
//
|
|
524
|
+
// Only filesystem errors are downgraded. A TypeError or a bad-regex bug in the
|
|
525
|
+
// helper is a defect in xp-gate, not a permissions problem, and telling the
|
|
526
|
+
// user to `chmod` would send them after the wrong thing — those rethrow.
|
|
527
|
+
// The failure check is on the error CODE, not on a message substring: getGitDir()
|
|
528
|
+
// signals "not a repo" by returning null, so there is no message to match and
|
|
529
|
+
// matching one would break the moment its wording changed.
|
|
530
|
+
const FS_ERROR_CODES = new Set(['EACCES', 'EPERM', 'EROFS', 'EBUSY', 'ENOSPC', 'EISDIR', 'ENOTDIR']);
|
|
531
|
+
const gitDir = getGitDir();
|
|
532
|
+
if (!gitDir) {
|
|
533
|
+
console.warn('\u26a0\ufe0f Could not update .gitignore: not inside a git repository');
|
|
534
|
+
} else {
|
|
535
|
+
try {
|
|
536
|
+
const added = ensureGitignoreEntries(path.dirname(gitDir));
|
|
537
|
+
if (added.length > 0) {
|
|
538
|
+
console.log(`\u2705 .gitignore updated \u2014 ${added.length} xp-gate entr${added.length === 1 ? 'y' : 'ies'} added (generated files are not project source).`);
|
|
539
|
+
}
|
|
540
|
+
} catch (e) {
|
|
541
|
+
if (!FS_ERROR_CODES.has(e.code)) throw e;
|
|
542
|
+
console.warn(`\u26a0\ufe0f Could not update .gitignore: ${e.message}`);
|
|
543
|
+
console.warn(' Generated files will show as untracked and can trip the file-hygiene gate.');
|
|
544
|
+
console.warn(' Make .gitignore writable and re-run `xp-gate init --full`, or add the rules by hand.');
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
413
548
|
// Always create lint baseline for local installs (Boy Scout Rule needs it)
|
|
414
549
|
// --baseline flag is now a no-op (baseline is always created)
|
|
415
550
|
if (code === 0) {
|
|
@@ -985,4 +1120,4 @@ function injectKarpathyPrinciples(projectRoot) {
|
|
|
985
1120
|
// setupGlobal is exported so the global-install wiring (agents deployed to the
|
|
986
1121
|
// real HOME) can be audited under a sandboxed HOME, not just asserted to exist
|
|
987
1122
|
// — the historical miss was "local deployed, global did not" (#417, #429).
|
|
988
|
-
module.exports = { init, promptBootstrap, installModuleRuntimeDeps, deployQoderDelphiAgents, configureQoderDelphiAgents, readQoderModelId, setupGlobal, probeGitleaksNotice };
|
|
1123
|
+
module.exports = { init, promptBootstrap, installModuleRuntimeDeps, deployQoderDelphiAgents, configureQoderDelphiAgents, readQoderModelId, setupGlobal, probeGitleaksNotice, ensureGitignoreEntries, gitignoreEntriesForInit };
|
package/lib/language-tools.js
CHANGED
|
@@ -50,6 +50,28 @@ const LANGUAGE_REGISTRY = {
|
|
|
50
50
|
optional: false,
|
|
51
51
|
gates: ['Gate 1 (Code Quality)'],
|
|
52
52
|
},
|
|
53
|
+
{
|
|
54
|
+
name: '@archlinter/cli',
|
|
55
|
+
checkCmd: 'npx --no-install archlint --version',
|
|
56
|
+
install: {
|
|
57
|
+
darwin: 'npm install --save-dev @archlinter/cli',
|
|
58
|
+
linux: 'npm install --save-dev @archlinter/cli',
|
|
59
|
+
win32: 'npm install --save-dev @archlinter/cli',
|
|
60
|
+
},
|
|
61
|
+
optional: true,
|
|
62
|
+
gates: ['Gate 4 (Architecture)'],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'dependency-cruiser',
|
|
66
|
+
checkCmd: 'npx --no-install depcruise --version',
|
|
67
|
+
install: {
|
|
68
|
+
darwin: 'npm install --save-dev dependency-cruiser',
|
|
69
|
+
linux: 'npm install --save-dev dependency-cruiser',
|
|
70
|
+
win32: 'npm install --save-dev dependency-cruiser',
|
|
71
|
+
},
|
|
72
|
+
optional: true,
|
|
73
|
+
gates: ['Gate 4 (Architecture)'],
|
|
74
|
+
},
|
|
53
75
|
],
|
|
54
76
|
},
|
|
55
77
|
|
|
@@ -113,6 +135,17 @@ const LANGUAGE_REGISTRY = {
|
|
|
113
135
|
optional: true,
|
|
114
136
|
gates: ['Gate 1 (Code Formatting)'],
|
|
115
137
|
},
|
|
138
|
+
{
|
|
139
|
+
name: 'import-linter',
|
|
140
|
+
checkCmd: 'lint-imports --version',
|
|
141
|
+
install: {
|
|
142
|
+
darwin: 'pip install import-linter',
|
|
143
|
+
linux: 'pip install import-linter',
|
|
144
|
+
win32: 'pip install import-linter',
|
|
145
|
+
},
|
|
146
|
+
optional: true,
|
|
147
|
+
gates: ['Gate 4 (Architecture)'],
|
|
148
|
+
},
|
|
116
149
|
],
|
|
117
150
|
},
|
|
118
151
|
|
|
@@ -165,6 +198,19 @@ const LANGUAGE_REGISTRY = {
|
|
|
165
198
|
optional: true,
|
|
166
199
|
gates: ['Gate 1 (Code Quality)'],
|
|
167
200
|
},
|
|
201
|
+
{
|
|
202
|
+
// A BUILD dependency, not a CLI: there is no `archunit` binary to probe,
|
|
203
|
+
// so checkCmd cannot work here. Detected by scanning the build files.
|
|
204
|
+
name: 'archunit',
|
|
205
|
+
detectBy: 'build-file',
|
|
206
|
+
install: {
|
|
207
|
+
darwin: 'add "com.tngtech.archunit:archunit-junit5" to pom.xml / build.gradle',
|
|
208
|
+
linux: 'add "com.tngtech.archunit:archunit-junit5" to pom.xml / build.gradle',
|
|
209
|
+
win32: 'add "com.tngtech.archunit:archunit-junit5" to pom.xml / build.gradle',
|
|
210
|
+
},
|
|
211
|
+
optional: true,
|
|
212
|
+
gates: ['Gate 4 (Architecture)'],
|
|
213
|
+
},
|
|
168
214
|
],
|
|
169
215
|
},
|
|
170
216
|
|
|
@@ -195,6 +241,17 @@ const LANGUAGE_REGISTRY = {
|
|
|
195
241
|
optional: true,
|
|
196
242
|
gates: ['Gate 1 (Code Quality)'],
|
|
197
243
|
},
|
|
244
|
+
{
|
|
245
|
+
name: 'arch-go',
|
|
246
|
+
checkCmd: 'arch-go --version',
|
|
247
|
+
install: {
|
|
248
|
+
darwin: 'go install github.com/fdaines/arch-go@latest',
|
|
249
|
+
linux: 'go install github.com/fdaines/arch-go@latest',
|
|
250
|
+
win32: 'go install github.com/fdaines/arch-go@latest',
|
|
251
|
+
},
|
|
252
|
+
optional: true,
|
|
253
|
+
gates: ['Gate 4 (Architecture)'],
|
|
254
|
+
},
|
|
198
255
|
],
|
|
199
256
|
},
|
|
200
257
|
|
|
@@ -225,6 +282,56 @@ const LANGUAGE_REGISTRY = {
|
|
|
225
282
|
optional: true,
|
|
226
283
|
gates: ['Gate 1 (Code Quality)'],
|
|
227
284
|
},
|
|
285
|
+
{
|
|
286
|
+
// Konsist is a build dependency too -- see the Java ArchUnit note above.
|
|
287
|
+
name: 'konsist',
|
|
288
|
+
detectBy: 'build-file',
|
|
289
|
+
install: {
|
|
290
|
+
darwin: 'add "com.lemonappdev:konsist" to build.gradle(.kts)',
|
|
291
|
+
linux: 'add "com.lemonappdev:konsist" to build.gradle(.kts)',
|
|
292
|
+
win32: 'add "com.lemonappdev:konsist" to build.gradle(.kts)',
|
|
293
|
+
},
|
|
294
|
+
optional: true,
|
|
295
|
+
gates: ['Gate 4 (Architecture)'],
|
|
296
|
+
},
|
|
297
|
+
],
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
// #730: C# was supported by every gate (adapter, principles engine, Gate 4/5/6/10/13
|
|
301
|
+
// arms) but absent here, so `detect-languages` produced a config WITHOUT csharp.
|
|
302
|
+
// A hook that reads the generated config trusts it and does not fall back to
|
|
303
|
+
// extension sniffing, so C# was never routed — the whole feature was invisible in
|
|
304
|
+
// exactly the mixed .NET+JS repos it targets (the dsh-aot-runner shape: .csproj plus
|
|
305
|
+
// ~900 lines of JS). Registry membership is what makes detection emit the entry.
|
|
306
|
+
csharp: {
|
|
307
|
+
name: 'C#/.NET',
|
|
308
|
+
extensions: ['cs', 'csx'],
|
|
309
|
+
// `.csproj`/`.sln` are SUFFIXES of project-specific filenames (Foo.csproj), so
|
|
310
|
+
// they must be written as globs — the matcher only globs entries containing '*'
|
|
311
|
+
// and otherwise stats the exact name, which would never find DshAotRunner.csproj.
|
|
312
|
+
// Directory.Build.props carries repo-wide MSBuild settings; global.json pins the
|
|
313
|
+
// SDK, so a repo with only that plus sources still deserves the C# arm.
|
|
314
|
+
configFiles: ['*.csproj', '*.sln', '*.csproj.user', 'Directory.Build.props', 'global.json'],
|
|
315
|
+
tools: [
|
|
316
|
+
{
|
|
317
|
+
// The adapter drives everything through the SDK: `dotnet format` for Gate 1,
|
|
318
|
+
// `dotnet build -warnaserror` for Gate 13, `dotnet test` for Gate 5.
|
|
319
|
+
name: 'dotnet',
|
|
320
|
+
checkCmd: 'dotnet --version',
|
|
321
|
+
install: {
|
|
322
|
+
darwin: 'brew install --cask dotnet-sdk',
|
|
323
|
+
linux: 'See https://learn.microsoft.com/dotnet/core/install/linux',
|
|
324
|
+
win32: 'winget install Microsoft.DotNet.SDK.8',
|
|
325
|
+
},
|
|
326
|
+
optional: false,
|
|
327
|
+
gates: ['Gate 1 (Code Quality)', 'Gate 5 (Tests + Coverage)', 'Gate 13 (Compiler Strictness)'],
|
|
328
|
+
},
|
|
329
|
+
// No second C# entry for coverage. `dotnet test --collect` supplies it, and
|
|
330
|
+
// the only project-provided detector this module implements is
|
|
331
|
+
// `detectBy: 'build-file'`, which reads ARCH_DEPENDENCY_COORDINATES — a table
|
|
332
|
+
// with no C# entry. Listing coverlet under a detectBy value nothing consumes
|
|
333
|
+
// would make check-tools probe a tool with no checkCmd and report a
|
|
334
|
+
// permanently-missing entry for a dependency that is already satisfied.
|
|
228
335
|
],
|
|
229
336
|
},
|
|
230
337
|
|
|
@@ -590,7 +697,11 @@ function getToolsForLanguages(languages) {
|
|
|
590
697
|
result[lang] = [];
|
|
591
698
|
|
|
592
699
|
for (const tool of langDef.tools) {
|
|
593
|
-
|
|
700
|
+
// Build-file tools have no binary to probe; running checkCmd on them
|
|
701
|
+
// would report "missing" permanently (#689 AC-3).
|
|
702
|
+
const status = tool.detectBy === 'build-file'
|
|
703
|
+
? detectBuildFileDependency(lang)
|
|
704
|
+
: checkTool(tool.name, tool.checkCmd);
|
|
594
705
|
result[lang].push({
|
|
595
706
|
tool,
|
|
596
707
|
status: status.available ? 'available' : 'missing',
|
|
@@ -608,6 +719,23 @@ function getToolsForLanguages(languages) {
|
|
|
608
719
|
* @returns {{success: boolean, message: string}}
|
|
609
720
|
*/
|
|
610
721
|
function installTool(toolDef) {
|
|
722
|
+
// A build-file tool has no installer to run: `detectBy: 'build-file'` exists
|
|
723
|
+
// because ArchUnit and Konsist are libraries with no CLI to probe, and their
|
|
724
|
+
// `install` field holds an instruction written for a human. Handing that
|
|
725
|
+
// prose to execSync made `doctor --fix --install-tools` print
|
|
726
|
+
// `'add' is not recognized as an internal or external command` on every Java
|
|
727
|
+
// machine, and on POSIX actually shell it. Report the guidance and start no
|
|
728
|
+
// process (#689 review, found by Delphi Round 1).
|
|
729
|
+
if (toolDef.detectBy === 'build-file') {
|
|
730
|
+
const guidance = toolDef.install[process.platform] || toolDef.install.linux || '';
|
|
731
|
+
return {
|
|
732
|
+
success: false,
|
|
733
|
+
message:
|
|
734
|
+
`${toolDef.name} is a build-file library, not a CLI: no install command is runnable. ` +
|
|
735
|
+
`Add it manually -- ${guidance}`,
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
|
|
611
739
|
const platform = process.platform;
|
|
612
740
|
const installCmd = toolDef.install[platform] || toolDef.install.linux;
|
|
613
741
|
|
|
@@ -682,6 +810,92 @@ function readProjectConfig(projectRoot) {
|
|
|
682
810
|
}
|
|
683
811
|
}
|
|
684
812
|
|
|
813
|
+
/**
|
|
814
|
+
* Files that declare a build dependency. The version catalog is included because
|
|
815
|
+
* a Gradle project may describe the coordinate ONLY there, never in
|
|
816
|
+
* build.gradle.kts -- checking just the build script would report a genuinely
|
|
817
|
+
* installed tool as missing (AC-689-06).
|
|
818
|
+
*
|
|
819
|
+
* Only the ROOT of the project is scanned: a multi-module build aggregates its
|
|
820
|
+
* dependencies at the root, and walking every submodule would cost a directory
|
|
821
|
+
* traversal per language for no gain (AC-689-09).
|
|
822
|
+
*/
|
|
823
|
+
const BUILD_FILE_CANDIDATES = [
|
|
824
|
+
'pom.xml',
|
|
825
|
+
'build.gradle',
|
|
826
|
+
'build.gradle.kts',
|
|
827
|
+
'gradle/libs.versions.toml',
|
|
828
|
+
];
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* The coordinate each language's architecture tool is declared under.
|
|
832
|
+
*
|
|
833
|
+
* Split per language on purpose: Konsist is a Kotlin tool, but nothing stops a
|
|
834
|
+
* Java project from also depending on it. Matching a single shared list would
|
|
835
|
+
* let one language's declaration turn another language's row green, so doctor
|
|
836
|
+
* would stop reporting the real gap (AC-689-07).
|
|
837
|
+
*/
|
|
838
|
+
const ARCH_DEPENDENCY_COORDINATES = {
|
|
839
|
+
java: 'com.tngtech.archunit',
|
|
840
|
+
kotlin: 'com.lemonappdev',
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Whether a build-file-declared architecture tool is present.
|
|
845
|
+
*
|
|
846
|
+
* Tools with `detectBy: 'build-file'` have no CLI to probe -- ArchUnit and
|
|
847
|
+
* Konsist are libraries. Probing them with checkCmd reports "missing" forever,
|
|
848
|
+
* which is what #689 is about: doctor told Java users their architecture tool
|
|
849
|
+
* was absent no matter what they did.
|
|
850
|
+
*
|
|
851
|
+
* @param {string} lang - Language key from LANGUAGE_REGISTRY
|
|
852
|
+
* @param {string} [projectRoot] - Project root; defaults to cwd
|
|
853
|
+
* @returns {{available: boolean, version: string, path: string|null}}
|
|
854
|
+
*/
|
|
855
|
+
function detectBuildFileDependency(lang, projectRoot) {
|
|
856
|
+
const root = projectRoot || process.cwd();
|
|
857
|
+
const coordinate = ARCH_DEPENDENCY_COORDINATES[lang];
|
|
858
|
+
if (!coordinate) return { available: false, version: 'N/A', path: null };
|
|
859
|
+
|
|
860
|
+
for (const relPath of BUILD_FILE_CANDIDATES) {
|
|
861
|
+
const candidate = path.join(root, relPath);
|
|
862
|
+
if (!fs.existsSync(candidate)) continue;
|
|
863
|
+
let contents;
|
|
864
|
+
try {
|
|
865
|
+
contents = fs.readFileSync(candidate, 'utf-8');
|
|
866
|
+
} catch {
|
|
867
|
+
// An unreadable build file is not evidence the tool is absent, but it is
|
|
868
|
+
// not evidence it is present either. Try the next candidate rather than
|
|
869
|
+
// claiming either way.
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
if (contents.includes(coordinate)) {
|
|
873
|
+
return { available: true, version: `declared in ${relPath}`, path: candidate };
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
return { available: false, version: 'N/A', path: null };
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* The architecture tools registered for each language.
|
|
881
|
+
*
|
|
882
|
+
* "Architecture tool" is recognised by its Gate 4 label rather than by a second
|
|
883
|
+
* parallel list: one source of truth means a tool cannot be registered and
|
|
884
|
+
* simultaneously missing from the doctor view.
|
|
885
|
+
*
|
|
886
|
+
* @returns {Object<string, Array>} language -> tool definitions
|
|
887
|
+
*/
|
|
888
|
+
function getArchitectureTools() {
|
|
889
|
+
const result = {};
|
|
890
|
+
for (const [lang, langDef] of Object.entries(LANGUAGE_REGISTRY)) {
|
|
891
|
+
const arch = langDef.tools.filter(tool =>
|
|
892
|
+
tool.gates.some(gate => gate.includes('Architecture'))
|
|
893
|
+
);
|
|
894
|
+
if (arch.length > 0) result[lang] = arch;
|
|
895
|
+
}
|
|
896
|
+
return result;
|
|
897
|
+
}
|
|
898
|
+
|
|
685
899
|
module.exports = {
|
|
686
900
|
LANGUAGE_REGISTRY,
|
|
687
901
|
detectProjectLanguages,
|
|
@@ -693,6 +907,8 @@ module.exports = {
|
|
|
693
907
|
handleDetectLanguages,
|
|
694
908
|
handleCheckTools,
|
|
695
909
|
handleInstallTools,
|
|
910
|
+
getArchitectureTools,
|
|
911
|
+
detectBuildFileDependency,
|
|
696
912
|
};
|
|
697
913
|
|
|
698
914
|
/**
|