@boyingliu01/xp-gate 0.38.125 → 0.38.126
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 +34 -1
- package/adapters/gate-7.sh +15 -6
- package/bin/xp-gate.js +24 -0
- package/build-integrity/gate-10.ts +33 -8
- package/gate-3.sh +34 -1
- package/gate-registry.sh +3 -1
- package/hooks/deploy-manifest.sh +1 -0
- package/hooks/gate-3.sh +34 -1
- package/hooks/gate-entries/gate-1-entry.sh +35 -24
- package/hooks/gate-entries/gate-5-entry.sh +55 -19
- package/hooks/gate-entries/gate-6-entry.sh +15 -6
- package/hooks/gate-registry.sh +3 -1
- package/hooks/lib/gate-status.sh +164 -0
- package/hooks/lib/jscpd-run.sh +9 -1
- package/hooks/lib/native-path.sh +54 -0
- package/hooks/lib/toolchain-path.sh +38 -0
- package/hooks/pre-push +13 -4
- package/lib/__tests__/arch.test.js +7 -1
- package/lib/__tests__/audit-skip-reasons.test.ts +143 -0
- package/lib/__tests__/check-tools-list.test.js +155 -0
- package/lib/__tests__/doctor-tool-delegation.test.js +156 -0
- package/lib/__tests__/install-tools-repair.test.js +263 -0
- package/lib/__tests__/language-capability.test.js +27 -0
- package/lib/__tests__/tool-audit-collect.test.js +184 -0
- package/lib/__tests__/tool-audit-fixtures.js +87 -0
- package/lib/__tests__/tool-audit-latest.test.js +84 -0
- package/lib/__tests__/tool-audit.test.js +428 -0
- package/lib/deploy-manifest.js +1 -0
- package/lib/doctor-tool-checks.js +129 -0
- package/lib/doctor.js +15 -46
- package/lib/gate-audit.ts +80 -0
- package/lib/gate-runner.js +5 -0
- package/lib/language-capability-surfaces.js +70 -6
- package/lib/language-capability.js +3 -0
- package/lib/language-tools.js +409 -93
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/tool-audit.js +729 -0
- package/package.json +1 -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/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/AGENTS.md +1 -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/skills.test.ts +9 -0
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -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/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
package/lib/language-tools.js
CHANGED
|
@@ -10,6 +10,18 @@ const { execSync } = require('child_process');
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const path = require('path');
|
|
12
12
|
const os = require('os');
|
|
13
|
+
// The audit lives in its own module: check-tools and doctor both need the same
|
|
14
|
+
// completeness/validity/uniqueness rules, and a rule kept in two files drifts.
|
|
15
|
+
const {
|
|
16
|
+
collectGateTools,
|
|
17
|
+
auditAllTools,
|
|
18
|
+
summarizeAudit,
|
|
19
|
+
resolveLatestVersion,
|
|
20
|
+
resolveToolViaShell,
|
|
21
|
+
} = require('./tool-audit.js');
|
|
22
|
+
// Reuse doctor's own cross-language list so the two commands cannot disagree
|
|
23
|
+
// about what "the gate CLI tools" are.
|
|
24
|
+
const { GATE_CLI_TOOLS } = require('./detect-deps.js');
|
|
13
25
|
|
|
14
26
|
/**
|
|
15
27
|
* Tool definition for quality gate language tools.
|
|
@@ -1014,6 +1026,7 @@ module.exports = {
|
|
|
1014
1026
|
handleDetectLanguages,
|
|
1015
1027
|
handleCheckTools,
|
|
1016
1028
|
handleInstallTools,
|
|
1029
|
+
planToolRepairs,
|
|
1017
1030
|
getArchitectureTools,
|
|
1018
1031
|
detectBuildFileDependency,
|
|
1019
1032
|
};
|
|
@@ -1093,143 +1106,446 @@ async function handleDetectLanguages(args) {
|
|
|
1093
1106
|
* @param {string[]} args - Command arguments
|
|
1094
1107
|
* @returns {Promise<number>} Exit code
|
|
1095
1108
|
*/
|
|
1096
|
-
|
|
1097
|
-
|
|
1109
|
+
/**
|
|
1110
|
+
* Render one audit row as the status the CLI contract uses.
|
|
1111
|
+
*
|
|
1112
|
+
* A row is unusable for two different reasons and they must not be merged:
|
|
1113
|
+
* the probe failed (missing/broken), or the probe could not be interpreted.
|
|
1114
|
+
* Both are "not usable", but only the first is "not installed".
|
|
1115
|
+
*/
|
|
1116
|
+
function statusOfRow(row) {
|
|
1117
|
+
return row.available ? 'available' : 'missing';
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/** Icon for a row: present, present-but-flagged, or absent. */
|
|
1121
|
+
function iconOfRow(row) {
|
|
1122
|
+
if (!row.available) return '✗';
|
|
1123
|
+
if (row.duplicated || row.outdated) return '⚠';
|
|
1124
|
+
return '✓';
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
/** Extra qualifiers appended to a human line, e.g. "duplicate ×2, 2.14.0 → 2.15.1". */
|
|
1128
|
+
function qualifiersOfRow(row) {
|
|
1129
|
+
const parts = [];
|
|
1130
|
+
if (row.duplicated) parts.push(`DUPLICATE ×${row.distinctRealPaths.length}`);
|
|
1131
|
+
if (row.outdated && row.installedVersion && row.latestVersion) {
|
|
1132
|
+
parts.push(`${row.installedVersion} → ${row.latestVersion} available`);
|
|
1133
|
+
} else if (row.currency === 'unknown') {
|
|
1134
|
+
parts.push('version currency unknown');
|
|
1135
|
+
}
|
|
1136
|
+
// #843: say WHERE the binary was found. "Installed but not on PATH" and
|
|
1137
|
+
// "not installed" look identical in a pass/fail column and call for opposite
|
|
1138
|
+
// actions -- add it to PATH (or symlink it), versus install it.
|
|
1139
|
+
if (row.available && row.resolution === 'fallback' && row.resolvedPath) {
|
|
1140
|
+
parts.push(`found at ${row.resolvedPath} (not on PATH)`);
|
|
1141
|
+
}
|
|
1142
|
+
if (!row.available && row.validityReason) parts.push(row.validityReason);
|
|
1143
|
+
return parts.join('; ');
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* Print the audit as a human-readable list.
|
|
1148
|
+
*
|
|
1149
|
+
* One list, not one section per language: the question "is my toolchain
|
|
1150
|
+
* complete" is about the whole set. Language attribution is kept as a column so
|
|
1151
|
+
* nothing is lost.
|
|
1152
|
+
*/
|
|
1153
|
+
function printAuditReport(rows, summary) {
|
|
1154
|
+
console.log('Quality Gate Tool Audit\n');
|
|
1155
|
+
const width = Math.max(...rows.map((r) => r.name.length), 10);
|
|
1156
|
+
for (const row of rows) {
|
|
1157
|
+
const opt = row.optional ? ' (optional)' : '';
|
|
1158
|
+
const version = row.installedVersion || 'N/A';
|
|
1159
|
+
const shown = row.npxInvoked ? `${version} (via npx)` : version;
|
|
1160
|
+
const q = qualifiersOfRow(row);
|
|
1161
|
+
console.log(` ${iconOfRow(row)} ${row.name.padEnd(width)}${opt} — ${shown}${q ? ` [${q}]` : ''}`);
|
|
1162
|
+
}
|
|
1163
|
+
console.log('');
|
|
1164
|
+
console.log(
|
|
1165
|
+
`Summary: ${summary.total} tools — ${summary.missing} missing, ${summary.duplicated} duplicated, `
|
|
1166
|
+
+ `${summary.outdated} outdated, ${summary.unknown} unknown`,
|
|
1167
|
+
);
|
|
1168
|
+
if (!summary.complete) {
|
|
1169
|
+
console.log('Run `xp-gate install-tools` to install, upgrade and de-duplicate.');
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* Handle check-tools CLI command.
|
|
1175
|
+
*
|
|
1176
|
+
* Reports completeness, validity, uniqueness and currency in ONE list. The
|
|
1177
|
+
* audit is injectable so tests drive every branch without touching the network
|
|
1178
|
+
* or the real toolchain.
|
|
1179
|
+
*
|
|
1180
|
+
* @param {string[]} args - Command arguments
|
|
1181
|
+
* @param {{
|
|
1182
|
+
* projectRoot?: string,
|
|
1183
|
+
* languages?: string[]|null,
|
|
1184
|
+
* audit?: (tools: Array, deps: object) => Array,
|
|
1185
|
+
* resolveLatest?: (name: string) => string|null,
|
|
1186
|
+
* }} [options]
|
|
1187
|
+
* @returns {Promise<number>} Exit code
|
|
1188
|
+
*/
|
|
1189
|
+
async function handleCheckTools(args, options = {}) {
|
|
1190
|
+
const projectRoot = options.projectRoot || process.cwd();
|
|
1098
1191
|
const jsonOutput = args.includes('--json');
|
|
1099
|
-
let languages = parseLanguageFlag(args);
|
|
1192
|
+
let languages = options.languages !== undefined ? options.languages : parseLanguageFlag(args);
|
|
1100
1193
|
|
|
1101
1194
|
// Auto-detect if no languages specified
|
|
1102
|
-
if (
|
|
1195
|
+
if (languages === undefined || languages === null) {
|
|
1103
1196
|
const detected = detectProjectLanguages(projectRoot);
|
|
1104
1197
|
languages = detected.detected;
|
|
1105
1198
|
}
|
|
1106
1199
|
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1200
|
+
// The cross-language CLI tools are part of the answer even when no detected
|
|
1201
|
+
// language mentions them: they are what the gate SCRIPTS call directly.
|
|
1202
|
+
// The cross-language CLI tools belong to the answer when we are describing the
|
|
1203
|
+
// whole toolchain (auto-detected or --all). When the caller names languages
|
|
1204
|
+
// explicitly, they asked "what does THIS language need" and a cross-language
|
|
1205
|
+
// section would answer a different question.
|
|
1206
|
+
const explicitSelection = parseLanguageFlag(args);
|
|
1207
|
+
// An EMPTY selection is "nothing was asked for", not "ask for nothing": the
|
|
1208
|
+
// auto-detect path and `options.languages = []` must still describe the whole
|
|
1209
|
+
// toolchain, or the report silently becomes empty and reads as complete.
|
|
1210
|
+
const includeCrossLanguage = !explicitSelection || explicitSelection.length === 0
|
|
1211
|
+
|| args.includes('--all');
|
|
1212
|
+
|
|
1213
|
+
const tools = collectGateTools({
|
|
1214
|
+
registry: LANGUAGE_REGISTRY,
|
|
1215
|
+
cliTools: GATE_CLI_TOOLS,
|
|
1216
|
+
// `--all` asks about every registered tool, not just this project's.
|
|
1217
|
+
languages: args.includes('--all') ? null : (languages.length ? languages : null),
|
|
1218
|
+
}).filter((t) => includeCrossLanguage || (t.languages && t.languages.length > 0));
|
|
1219
|
+
|
|
1220
|
+
const audit = options.audit || ((list, deps) => auditAllTools(list, deps));
|
|
1221
|
+
// Resolve tools through the SAME helper the gates use (#843): a binary in
|
|
1222
|
+
// ~/.local/bin is installed even when the hook's PATH omits it, and reporting
|
|
1223
|
+
// it missing sends the reader off to install what is already there.
|
|
1224
|
+
const rows = audit(tools, {
|
|
1225
|
+
resolveLatest: options.resolveLatest || ((n) => resolveLatestVersion(n)),
|
|
1226
|
+
resolveTool: options.resolveTool || ((name) => resolveToolViaShell(name)),
|
|
1227
|
+
});
|
|
1228
|
+
const summary = summarizeAudit(rows);
|
|
1113
1229
|
|
|
1114
1230
|
if (jsonOutput) {
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1231
|
+
// CONTRACT, preserved from #468: the top level is keyed by language name and
|
|
1232
|
+
// each value is that language's tool list. Callers parse it that way, and a
|
|
1233
|
+
// shape change here silently broke them once already. The audit's new facts
|
|
1234
|
+
// (duplicates, currency, cross-language tools) therefore ride alongside in
|
|
1235
|
+
// `summary` and `crossLanguage` rather than replacing the old shape.
|
|
1236
|
+
const byLanguage = {};
|
|
1237
|
+
for (const row of rows) {
|
|
1238
|
+
for (const lang of (row.languages && row.languages.length ? row.languages : ['(cross-language)'])) {
|
|
1239
|
+
if (!byLanguage[lang]) byLanguage[lang] = [];
|
|
1240
|
+
byLanguage[lang].push({
|
|
1241
|
+
name: row.name,
|
|
1242
|
+
status: statusOfRow(row),
|
|
1243
|
+
optional: row.optional,
|
|
1244
|
+
version: row.version,
|
|
1245
|
+
gates: row.gates,
|
|
1246
|
+
duplicated: row.duplicated,
|
|
1247
|
+
paths: row.paths,
|
|
1248
|
+
outdated: row.outdated,
|
|
1249
|
+
latestVersion: row.latestVersion,
|
|
1250
|
+
currency: row.currency,
|
|
1251
|
+
reason: row.validityReason || undefined,
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1124
1254
|
}
|
|
1125
|
-
|
|
1255
|
+
// Tools the gate scripts call directly; reported once, not per language.
|
|
1256
|
+
// Only emitted when such tools exist: an always-present empty group would
|
|
1257
|
+
// add a key to a contract callers compare exactly (#468).
|
|
1258
|
+
const crossLanguage = rows
|
|
1259
|
+
.filter((r) => !r.languages || r.languages.length === 0)
|
|
1260
|
+
.map((r) => ({
|
|
1261
|
+
name: r.name,
|
|
1262
|
+
status: statusOfRow(r),
|
|
1263
|
+
optional: r.optional,
|
|
1264
|
+
version: r.version,
|
|
1265
|
+
gates: r.gates,
|
|
1266
|
+
duplicated: r.duplicated,
|
|
1267
|
+
paths: r.paths,
|
|
1268
|
+
outdated: r.outdated,
|
|
1269
|
+
latestVersion: r.latestVersion,
|
|
1270
|
+
currency: r.currency,
|
|
1271
|
+
npxInvoked: r.npxInvoked,
|
|
1272
|
+
reason: r.validityReason || undefined,
|
|
1273
|
+
}));
|
|
1274
|
+
if (crossLanguage.length > 0) byLanguage['(cross-language)'] = crossLanguage;
|
|
1275
|
+
|
|
1276
|
+
// `summary` and the flat view are additive: they appear only when asked
|
|
1277
|
+
// for, so the historical shape ({ <language>: [...] }) stays byte-identical
|
|
1278
|
+
// for callers that parse it exactly (#468).
|
|
1279
|
+
const wantsAuditFields = args.includes('--audit') || args.includes('--flat');
|
|
1280
|
+
// The flat view uses the SAME field names as the grouped view (`status`,
|
|
1281
|
+
// `version`), so a consumer can switch between them without remapping.
|
|
1282
|
+
const flatView = rows.map((r) => ({
|
|
1283
|
+
name: r.name,
|
|
1284
|
+
status: statusOfRow(r),
|
|
1285
|
+
optional: r.optional,
|
|
1286
|
+
version: r.version,
|
|
1287
|
+
installedVersion: r.installedVersion,
|
|
1288
|
+
gates: r.gates,
|
|
1289
|
+
languages: r.languages,
|
|
1290
|
+
duplicated: r.duplicated,
|
|
1291
|
+
paths: r.paths,
|
|
1292
|
+
distinctRealPaths: r.distinctRealPaths,
|
|
1293
|
+
outdated: r.outdated,
|
|
1294
|
+
latestVersion: r.latestVersion,
|
|
1295
|
+
currency: r.currency,
|
|
1296
|
+
npxInvoked: r.npxInvoked,
|
|
1297
|
+
reason: r.validityReason || undefined,
|
|
1298
|
+
}));
|
|
1299
|
+
console.log(JSON.stringify({
|
|
1300
|
+
...byLanguage,
|
|
1301
|
+
...(wantsAuditFields ? { summary } : {}),
|
|
1302
|
+
...(args.includes('--flat') ? { tools: flatView } : {}),
|
|
1303
|
+
}, null, 2));
|
|
1126
1304
|
} else {
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
let totalMissing = 0;
|
|
1305
|
+
printAuditReport(rows, summary);
|
|
1306
|
+
}
|
|
1130
1307
|
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1308
|
+
return 0;
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
/**
|
|
1312
|
+
* Paths owned by the distribution. A copy here is the SYSTEM's copy, not a
|
|
1313
|
+
* duplicate install: removing it can take unrelated software with it, and the
|
|
1314
|
+
* user asked explicitly for distro packages to be left alone (2026-11-23).
|
|
1315
|
+
*/
|
|
1316
|
+
const { SYSTEM_PATH_PREFIXES } = require('./tool-audit.js');
|
|
1317
|
+
|
|
1318
|
+
/**
|
|
1319
|
+
* Build a repair plan from audit rows. Pure: no IO, no execution.
|
|
1320
|
+
*
|
|
1321
|
+
* Rules, in the order they are applied per tool:
|
|
1322
|
+
* 1. npx-invoked tools have no PATH entity — nothing to remove.
|
|
1323
|
+
* 2. A distro-owned copy is never removed; it is reported as kept.
|
|
1324
|
+
* 3. Duplicates: keep the FIRST path (what gates execute today) and remove the
|
|
1325
|
+
* rest, so repairing does not change which binary the gates run.
|
|
1326
|
+
* 4. Missing REQUIRED tool -> install. Missing optional -> skipped and named.
|
|
1327
|
+
* 5. Outdated required tool -> upgrade.
|
|
1328
|
+
*
|
|
1329
|
+
* @param {Array} rows audit rows
|
|
1330
|
+
* @param {{definitions?: Array, systemPrefixes?: string[], platform?: string}} [options]
|
|
1331
|
+
* @returns {{actions: Array, clean: boolean}}
|
|
1332
|
+
*/
|
|
1333
|
+
function planToolRepairs(rows, options = {}) {
|
|
1334
|
+
const definitions = options.definitions || [];
|
|
1335
|
+
const platform = options.platform || process.platform;
|
|
1336
|
+
const systemPrefixes = options.systemPrefixes || SYSTEM_PATH_PREFIXES;
|
|
1337
|
+
const defByName = new Map(definitions.map((d) => [d.name, d]));
|
|
1338
|
+
const isSystemOwned = (p) => systemPrefixes.some((pre) => String(p).startsWith(pre));
|
|
1339
|
+
|
|
1340
|
+
const actions = [];
|
|
1341
|
+
for (const row of rows || []) {
|
|
1342
|
+
if (row.npxInvoked) continue;
|
|
1343
|
+
|
|
1344
|
+
const def = defByName.get(row.name);
|
|
1345
|
+
const installCmd = def && def.install
|
|
1346
|
+
? (def.install[platform] || def.install.linux || def.install.npm || null)
|
|
1347
|
+
: null;
|
|
1348
|
+
|
|
1349
|
+
// Only USER-owned duplicates are a repair. A distro copy plus a user copy is
|
|
1350
|
+
// coexistence (jq from apt vs a newer ~/.local/bin/jq), and removing either
|
|
1351
|
+
// is not a fix: the distro one can drag dependencies with it, the user one is
|
|
1352
|
+
// what the reader installed on purpose.
|
|
1353
|
+
const userCopies = (row.userCopies || row.distinctRealPaths.filter((p) => !isSystemOwned(p)));
|
|
1354
|
+
if (row.duplicated && userCopies.length > 1) {
|
|
1355
|
+
const [keep, ...rest] = userCopies;
|
|
1356
|
+
actions.push({ kind: 'keep', tool: row.name, path: keep });
|
|
1357
|
+
for (const dup of rest) {
|
|
1358
|
+
actions.push({ kind: 'remove-duplicate', tool: row.name, path: dup, keepPath: keep });
|
|
1145
1359
|
}
|
|
1146
|
-
|
|
1360
|
+
// A tool that is duplicated but otherwise current needs no install step.
|
|
1361
|
+
if (row.available && !row.outdated) continue;
|
|
1147
1362
|
}
|
|
1148
1363
|
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1364
|
+
if (!row.available) {
|
|
1365
|
+
if (row.optional) {
|
|
1366
|
+
actions.push({ kind: 'skip-optional', tool: row.name, reason: 'optional tool not installed' });
|
|
1367
|
+
} else {
|
|
1368
|
+
actions.push({ kind: 'install', tool: row.name, command: installCmd });
|
|
1369
|
+
}
|
|
1370
|
+
continue;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
if (row.outdated === true) {
|
|
1374
|
+
// MEASURED DEFECT (2026-11-23): hadolint was duplicated AND outdated. The
|
|
1375
|
+
// plan removed ~/.local/bin/hadolint, then ran an installer whose command
|
|
1376
|
+
// writes to that exact path — so the duplicate came straight back and the
|
|
1377
|
+
// repair silently achieved nothing. Detect it and say so loudly instead of
|
|
1378
|
+
// reporting a success that is not one.
|
|
1379
|
+
const removedHere = actions
|
|
1380
|
+
.filter((a) => a.kind === 'remove-duplicate' && a.tool === row.name)
|
|
1381
|
+
.map((a) => a.path);
|
|
1382
|
+
const writesToRemovedPath = Boolean(installCmd)
|
|
1383
|
+
&& removedHere.some((removedPath) => String(installCmd).includes(removedPath));
|
|
1384
|
+
actions.push({
|
|
1385
|
+
kind: 'upgrade',
|
|
1386
|
+
tool: row.name,
|
|
1387
|
+
command: installCmd,
|
|
1388
|
+
from: row.installedVersion,
|
|
1389
|
+
to: row.latestVersion,
|
|
1390
|
+
writesToRemovedPath,
|
|
1391
|
+
conflictsWith: writesToRemovedPath ? removedHere : undefined,
|
|
1392
|
+
});
|
|
1152
1393
|
}
|
|
1153
1394
|
}
|
|
1154
1395
|
|
|
1155
|
-
return 0;
|
|
1396
|
+
return { actions, clean: actions.length === 0 };
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
/** Human line for one planned action. */
|
|
1400
|
+
function describeAction(action) {
|
|
1401
|
+
switch (action.kind) {
|
|
1402
|
+
case 'remove-duplicate':
|
|
1403
|
+
return `remove duplicate ${action.tool}: ${action.path} (keeping ${action.keepPath})`;
|
|
1404
|
+
case 'keep':
|
|
1405
|
+
return `keep ${action.tool}: ${action.path}`;
|
|
1406
|
+
case 'keep-system':
|
|
1407
|
+
return `keep (system) ${action.tool}: ${action.path}`;
|
|
1408
|
+
case 'skip-optional':
|
|
1409
|
+
return `skip (optional) ${action.tool}`;
|
|
1410
|
+
case 'install':
|
|
1411
|
+
return `install ${action.tool} ← ${action.command || 'no installer known'}`;
|
|
1412
|
+
case 'upgrade':
|
|
1413
|
+
return `upgrade ${action.tool} ${action.from} → ${action.to} ← ${action.command || 'no installer known'}`;
|
|
1414
|
+
default:
|
|
1415
|
+
return `${action.kind} ${action.tool}`;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
/** Default command runner: returns {status}. Injectable so tests never execute. */
|
|
1420
|
+
function defaultRunCommand(command) {
|
|
1421
|
+
if (!command) return { status: 1, error: 'no installer command' };
|
|
1422
|
+
try {
|
|
1423
|
+
execSync(command, { stdio: 'inherit', timeout: 600000, shell: true });
|
|
1424
|
+
return { status: 0 };
|
|
1425
|
+
} catch (err) {
|
|
1426
|
+
return { status: typeof err.status === 'number' ? err.status : 1, error: String(err.message || err) };
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
/** Default file remover, used only for duplicate cleanup. */
|
|
1431
|
+
function defaultRemoveFile(target) {
|
|
1432
|
+
try {
|
|
1433
|
+
fs.rmSync(target, { force: true });
|
|
1434
|
+
return true;
|
|
1435
|
+
} catch {
|
|
1436
|
+
return false;
|
|
1437
|
+
}
|
|
1156
1438
|
}
|
|
1157
1439
|
|
|
1158
1440
|
/**
|
|
1159
1441
|
* Handle install-tools CLI command.
|
|
1442
|
+
*
|
|
1443
|
+
* Installs missing required tools, upgrades outdated ones and removes duplicate
|
|
1444
|
+
* copies so each tool ends up as one current, working entity.
|
|
1445
|
+
*
|
|
1446
|
+
* Without `--yes` nothing is executed: the plan is printed and the command says
|
|
1447
|
+
* plainly that it changed nothing. Silence there would be indistinguishable
|
|
1448
|
+
* from "the repair ran and needed no work".
|
|
1449
|
+
*
|
|
1160
1450
|
* @param {string[]} args - Command arguments
|
|
1451
|
+
* @param {{
|
|
1452
|
+
* projectRoot?: string,
|
|
1453
|
+
* languages?: string[],
|
|
1454
|
+
* audit?: (tools: Array, deps: object) => Array,
|
|
1455
|
+
* definitions?: Array,
|
|
1456
|
+
* run?: (cmd: string) => {status: number},
|
|
1457
|
+
* removeFile?: (p: string) => boolean,
|
|
1458
|
+
* }} [options]
|
|
1161
1459
|
* @returns {Promise<number>} Exit code
|
|
1162
1460
|
*/
|
|
1163
|
-
async function handleInstallTools(args) {
|
|
1164
|
-
const projectRoot = process.cwd();
|
|
1165
|
-
const dryRun = args.includes('--dry-run');
|
|
1461
|
+
async function handleInstallTools(args, options = {}) {
|
|
1462
|
+
const projectRoot = options.projectRoot || process.cwd();
|
|
1166
1463
|
const autoYes = args.includes('--yes') || args.includes('-y');
|
|
1167
|
-
|
|
1464
|
+
const run = options.run || defaultRunCommand;
|
|
1465
|
+
const removeFile = options.removeFile || defaultRemoveFile;
|
|
1168
1466
|
|
|
1169
|
-
|
|
1170
|
-
if (
|
|
1171
|
-
|
|
1172
|
-
languages = detected.detected;
|
|
1467
|
+
let languages = options.languages !== undefined ? options.languages : parseLanguageFlag(args);
|
|
1468
|
+
if (languages === undefined || languages === null) {
|
|
1469
|
+
languages = detectProjectLanguages(projectRoot).detected;
|
|
1173
1470
|
}
|
|
1174
1471
|
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1472
|
+
const tools = collectGateTools({
|
|
1473
|
+
registry: LANGUAGE_REGISTRY,
|
|
1474
|
+
cliTools: GATE_CLI_TOOLS,
|
|
1475
|
+
languages: args.includes('--all') || !languages.length ? null : languages,
|
|
1476
|
+
});
|
|
1477
|
+
|
|
1478
|
+
const audit = options.audit || ((list, deps) => auditAllTools(list, deps));
|
|
1479
|
+
const rows = audit(tools, { resolveLatest: options.resolveLatest || ((n) => resolveLatestVersion(n)) });
|
|
1480
|
+
|
|
1481
|
+
// Installer commands come from the registry entry (language) or the CLI entry.
|
|
1482
|
+
const definitions = options.definitions
|
|
1483
|
+
|| [
|
|
1484
|
+
...tools,
|
|
1485
|
+
...GATE_CLI_TOOLS.map((c) => ({ name: c.tool, install: c.install, optional: false })),
|
|
1486
|
+
];
|
|
1487
|
+
|
|
1488
|
+
const plan = planToolRepairs(rows, { definitions });
|
|
1489
|
+
if (plan.clean) {
|
|
1490
|
+
console.log('Toolchain is already up to date: nothing to install, upgrade or remove.');
|
|
1491
|
+
return 0;
|
|
1178
1492
|
}
|
|
1179
1493
|
|
|
1180
|
-
console.log('
|
|
1494
|
+
console.log('Planned toolchain changes:\n');
|
|
1495
|
+
for (const action of plan.actions) console.log(` • ${describeAction(action)}`);
|
|
1181
1496
|
console.log('');
|
|
1182
1497
|
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1498
|
+
// A repair whose parts undo each other is not a repair. Refuse to run it and
|
|
1499
|
+
// say which action conflicts, so the operator can fix the installer instead of
|
|
1500
|
+
// watching a duplicate survive a "successful" run.
|
|
1501
|
+
const conflicting = plan.actions.filter((a) => a.kind === 'upgrade' && a.writesToRemovedPath);
|
|
1502
|
+
if (conflicting.length) {
|
|
1503
|
+
for (const a of conflicting) {
|
|
1504
|
+
console.log(`CONFLICT ${a.tool}: its installer writes to ${(a.conflictsWith || []).join(', ')},`);
|
|
1505
|
+
console.log(' which this same plan removes — the duplicate would come back.');
|
|
1191
1506
|
}
|
|
1507
|
+
console.log('Refusing to apply a self-cancelling plan. Fix the installer command first.');
|
|
1508
|
+
return 1;
|
|
1192
1509
|
}
|
|
1193
1510
|
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
console.log(`Found ${missingTools.length} missing required tool(s):\n`);
|
|
1200
|
-
for (const { lang, tool } of missingTools) {
|
|
1201
|
-
const installCmd = tool.install[process.platform] || tool.install.linux || 'N/A';
|
|
1202
|
-
console.log(` • ${tool.name} (${lang})`);
|
|
1203
|
-
console.log(` Install: ${installCmd}`);
|
|
1204
|
-
}
|
|
1205
|
-
console.log('');
|
|
1206
|
-
|
|
1207
|
-
if (dryRun) {
|
|
1208
|
-
console.log('Dry run — no tools installed.');
|
|
1511
|
+
const mutating = plan.actions.filter((a) =>
|
|
1512
|
+
a.kind === 'install' || a.kind === 'upgrade' || a.kind === 'remove-duplicate');
|
|
1513
|
+
if (!mutating.length) {
|
|
1514
|
+
console.log('No changes needed for the required tools.');
|
|
1209
1515
|
return 0;
|
|
1210
1516
|
}
|
|
1211
1517
|
|
|
1212
1518
|
if (!autoYes) {
|
|
1213
|
-
console.log(
|
|
1519
|
+
console.log(`${mutating.length} change(s) planned. No changes were made — re-run with --yes to apply them.`);
|
|
1214
1520
|
return 0;
|
|
1215
1521
|
}
|
|
1216
1522
|
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1523
|
+
let failed = 0;
|
|
1524
|
+
for (const action of mutating) {
|
|
1525
|
+
if (action.kind === 'remove-duplicate') {
|
|
1526
|
+
const ok = removeFile(action.path);
|
|
1527
|
+
if (!ok) failed += 1;
|
|
1528
|
+
console.log(`${ok ? 'removed' : 'FAILED to remove'} ${action.path}`);
|
|
1529
|
+
continue;
|
|
1530
|
+
}
|
|
1531
|
+
if (!action.command) {
|
|
1532
|
+
failed += 1;
|
|
1533
|
+
console.log(`FAILED ${action.tool}: no installer command for this platform`);
|
|
1534
|
+
continue;
|
|
1535
|
+
}
|
|
1536
|
+
console.log(`> ${action.command}`);
|
|
1537
|
+
const result = run(action.command) || { status: 1 };
|
|
1538
|
+
if (result.status !== 0) {
|
|
1539
|
+
failed += 1;
|
|
1540
|
+
console.log(`FAILED ${action.tool} (exit ${result.status})`);
|
|
1230
1541
|
}
|
|
1231
1542
|
}
|
|
1232
1543
|
|
|
1233
|
-
console.log(
|
|
1234
|
-
|
|
1544
|
+
console.log('');
|
|
1545
|
+
if (failed > 0) {
|
|
1546
|
+
console.log(`${failed} of ${mutating.length} change(s) failed.`);
|
|
1547
|
+
return 1;
|
|
1548
|
+
}
|
|
1549
|
+
console.log(`Applied ${mutating.length} change(s) successfully.`);
|
|
1550
|
+
return 0;
|
|
1235
1551
|
}
|