@boyingliu01/xp-gate 0.38.10 → 0.38.12

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.
Files changed (37) hide show
  1. package/gate-registry.sh +13 -0
  2. package/hooks/gate-entries/gate-10-entry.sh +11 -0
  3. package/hooks/gate-entries/gate-12b-entry.sh +15 -0
  4. package/hooks/gate-entries/gate-12c-entry.sh +9 -19
  5. package/hooks/gate-entries/gate-13-entry.sh +20 -0
  6. package/hooks/gate-entries/gate-7-entry.sh +15 -1
  7. package/hooks/gate-entries/gate-8-entry.sh +7 -0
  8. package/hooks/gate-registry.sh +13 -0
  9. package/lib/__tests__/baseline-completeness.test.js +264 -0
  10. package/lib/__tests__/detect-deps-dsh-profile.test.js +177 -3
  11. package/lib/baseline.js +265 -86
  12. package/lib/detect-deps.js +8 -3
  13. package/lib/doctor.js +9 -5
  14. package/lib/gate-runner.js +14 -0
  15. package/lib/install-skill.js +15 -9
  16. package/lib/mattpocock-license-verdict.json +1 -1
  17. package/lib/shared-paths.js +44 -8
  18. package/package.json +1 -1
  19. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  20. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  21. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  22. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  23. package/plugins/dsh/package.json +1 -1
  24. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  25. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  26. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  27. package/plugins/opencode/package.json +1 -1
  28. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  29. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  30. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  31. package/plugins/qoder/plugin.json +1 -1
  32. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  33. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  34. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  35. package/skills/delphi-review/AGENTS.md +1 -1
  36. package/skills/sprint-flow/AGENTS.md +1 -1
  37. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -1,9 +1,11 @@
1
1
  /**
2
- * @test REQ-635
2
+ * @test REQ-DSH-020
3
3
  * @intent `xp-gate init` 会向 ~/.dsh/skills 部署技能、npm 包也带 plugins/dsh,
4
4
  * 但 PLATFORM_PROFILES 里没有 dsh 条目,getSkillsDirs('dsh') 静默回落到
5
- * opencode 的路径,导致 DSH 机器的技能从不被解析(#635)
6
- * @covers AC-635-04, AC-635-05
5
+ * opencode 的路径,导致 DSH 机器的技能从不被解析(#635)。
6
+ * 原注释写的 @covers AC-635-04/05 在 spec 里从未存在(REQ-635 是
7
+ * normalize-lock-registry 的 lockfile 路径需求),已改指真实条目。
8
+ * @covers AC-DSH-020-01, AC-DSH-020-02, AC-DSH-020-03, AC-DSH-020-04
7
9
  */
8
10
  const fs = require('fs');
9
11
  const path = require('path');
@@ -147,3 +149,175 @@ describe('detectInstalledPlatforms (#725 detect-all)', () => {
147
149
  expect(detectInstalledPlatforms()).toEqual([]);
148
150
  });
149
151
  });
152
+
153
+ /**
154
+ * @test REQ-DSH-020
155
+ * @intent #635 只给 PLATFORM_PROFILES 补了 dsh 条目,detectPlatform() 本身仍只
156
+ * 可能返回 qoder / claude-code / opencode。只有 DSH 的机器上,所有持有
157
+ * 该结果的调用方(install-skill、checkDeps、getTemplateDir)都瞄向
158
+ * ~/.config/opencode —— 一个 running agent 不读、也可能不存在的位置。
159
+ * `~/.dsh/profiles` 与 `~/.dsh/.shim` 是 DSH 独有目录,可作为可靠标记。
160
+ * @covers AC-DSH-020-01, AC-DSH-020-02, AC-DSH-020-03, AC-DSH-020-04
161
+ */
162
+ describe('detectPlatform() resolves dsh (#635 follow-up)', () => {
163
+ let tmpHome;
164
+ let originalHome;
165
+
166
+ const load = () => {
167
+ vi.resetModules();
168
+ delete require.cache[require.resolve('../shared-paths')];
169
+ return require('../shared-paths');
170
+ };
171
+
172
+ beforeEach(() => {
173
+ originalHome = process.env.HOME;
174
+ tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-platdsh-'));
175
+ process.env.HOME = tmpHome;
176
+ });
177
+
178
+ afterEach(() => {
179
+ process.env.HOME = originalHome;
180
+ fs.rmSync(tmpHome, { recursive: true, force: true });
181
+ });
182
+
183
+ // AC-DSH-020-01
184
+ it('returns dsh when ~/.dsh/profiles exists', () => {
185
+ fs.mkdirSync(path.join(tmpHome, '.dsh', 'profiles'), { recursive: true });
186
+ expect(load().detectPlatform()).toBe('dsh');
187
+ });
188
+
189
+ it('returns dsh when only ~/.dsh/.shim exists', () => {
190
+ fs.mkdirSync(path.join(tmpHome, '.dsh', '.shim'), { recursive: true });
191
+ expect(load().detectPlatform()).toBe('dsh');
192
+ });
193
+
194
+ it('does not return dsh when neither dsh marker exists', () => {
195
+ // A bare ~/.dsh/skills is NOT a marker: every platform has a skills/ dir,
196
+ // so keying on it would steal opencode/qoder machines.
197
+ fs.mkdirSync(path.join(tmpHome, '.dsh', 'skills'), { recursive: true });
198
+ expect(load().detectPlatform()).not.toBe('dsh');
199
+ });
200
+
201
+ it('still falls back to opencode on an empty home', () => {
202
+ expect(load().detectPlatform()).toBe('opencode');
203
+ });
204
+
205
+ // AC-DSH-020-02: DSH wins over the other markers — it is the agent whose
206
+ // skills/ the user is actually reading, so installs must land there.
207
+ it('prefers dsh over qoder and claude-code when all markers coexist', () => {
208
+ fs.mkdirSync(path.join(tmpHome, '.dsh', 'profiles'), { recursive: true });
209
+ fs.mkdirSync(path.join(tmpHome, '.qoder'), { recursive: true });
210
+ fs.mkdirSync(path.join(tmpHome, '.claude', 'skills'), { recursive: true });
211
+ expect(load().detectPlatform()).toBe('dsh');
212
+ });
213
+
214
+ // AC-DSH-020-02: the pre-existing precedence must survive — removing the DSH
215
+ // markers must restore qoder > claude-code > opencode exactly as before.
216
+ it('leaves qoder/claude-code/opencode precedence intact without dsh markers', () => {
217
+ fs.mkdirSync(path.join(tmpHome, '.qoder'), { recursive: true });
218
+ fs.mkdirSync(path.join(tmpHome, '.claude', 'skills'), { recursive: true });
219
+ expect(load().detectPlatform()).toBe('qoder');
220
+
221
+ fs.rmSync(path.join(tmpHome, '.qoder'), { recursive: true, force: true });
222
+ expect(load().detectPlatform()).toBe('claude-code');
223
+
224
+ fs.rmSync(path.join(tmpHome, '.claude'), { recursive: true, force: true });
225
+ expect(load().detectPlatform()).toBe('opencode');
226
+ });
227
+
228
+ // AC-DSH-020-04
229
+ it('getTemplateDir() targets ~/.dsh, not the opencode fallback', () => {
230
+ fs.mkdirSync(path.join(tmpHome, '.dsh', 'profiles'), { recursive: true });
231
+ const dir = load().getTemplateDir();
232
+ expect(dir).toBe(path.join(tmpHome, '.dsh', 'git-hooks-template'));
233
+ expect(dir).not.toContain(path.join('.config', 'opencode'));
234
+ });
235
+ });
236
+
237
+ /**
238
+ * @test REQ-DSH-020
239
+ * @intent install-skill 曾维护第二份平台→目录表(getSkillsDir),#635 给
240
+ * PLATFORM_PROFILES 加 dsh 后它没跟着改,仍在 DSH-only 机器上返回
241
+ * ~/.config/opencode/skills。改为从 getSkillsDirs() 派生,消除第二事实源。
242
+ * @covers AC-DSH-020-03
243
+ */
244
+ describe('install-skill resolves its target through PLATFORM_PROFILES', () => {
245
+ let tmpHome;
246
+ let originalHome;
247
+
248
+ beforeEach(() => {
249
+ originalHome = process.env.HOME;
250
+ tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-installdsh-'));
251
+ process.env.HOME = tmpHome;
252
+ vi.resetModules();
253
+ delete require.cache[require.resolve('../install-skill')];
254
+ delete require.cache[require.resolve('../detect-deps')];
255
+ delete require.cache[require.resolve('../shared-paths')];
256
+ });
257
+
258
+ afterEach(() => {
259
+ process.env.HOME = originalHome;
260
+ fs.rmSync(tmpHome, { recursive: true, force: true });
261
+ });
262
+
263
+ // The regression that actually bit (#635 follow-up), pinned end-to-end:
264
+ // `installSkill()` calls `checkDeps(detectPlatform())` BEFORE it resolves any
265
+ // target directory. When detection fell through to opencode on a DSH machine,
266
+ // the dependency probe looked in `~/.config/opencode/skills`, found nothing,
267
+ // and the command aborted with "superpowers is required but not installed" --
268
+ // no skill was ever written, so a test that only asserted the write target
269
+ // would have passed while the reported bug stayed live.
270
+ //
271
+ // Mutation-checked: making detectPlatform() skip the DSH markers turns the
272
+ // `code` assertion back to 1 with "superpowers is required".
273
+ it('passes the dependency check when deps live under a DSH-only ~/.dsh/skills', async () => {
274
+ const BUNDLED = path.join(__dirname, '..', '..', 'skills');
275
+ if (!fs.existsSync(BUNDLED)) return; // packaged build not generated in this tree
276
+
277
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-depcheck-'));
278
+ try {
279
+ fs.mkdirSync(path.join(home, '.dsh', 'profiles'), { recursive: true });
280
+ const dshSkills = path.join(home, '.dsh', 'skills');
281
+ // Deps are installed where DSH keeps skills -- and nowhere else. The old
282
+ // opencode fallback therefore cannot see them.
283
+ for (const dep of ['superpowers', 'gstack']) {
284
+ const dir = path.join(dshSkills, dep);
285
+ fs.mkdirSync(dir, { recursive: true });
286
+ fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({ version: '2.0.0' }));
287
+ }
288
+
289
+ process.env.HOME = home;
290
+ vi.resetModules();
291
+ delete require.cache[require.resolve('../install-skill')];
292
+ delete require.cache[require.resolve('../detect-deps')];
293
+ delete require.cache[require.resolve('../shared-paths')];
294
+
295
+ const { detectPlatform } = require('../shared-paths');
296
+ const { checkDeps } = require('../detect-deps');
297
+ // The load-bearing assertion: detection must name dsh so the probe looks
298
+ // in the tree the deps were actually installed into.
299
+ expect(detectPlatform()).toBe('dsh');
300
+ expect(await checkDeps(detectPlatform())).toEqual({ ok: true });
301
+ // Anti-vacuity: the same tree is invisible to the platform the pre-fix
302
+ // code would have selected.
303
+ expect(await checkDeps('opencode')).toEqual({ ok: false, missing: 'superpowers' });
304
+ } finally {
305
+ process.env.HOME = originalHome;
306
+ fs.rmSync(home, { recursive: true, force: true });
307
+ vi.resetModules();
308
+ delete require.cache[require.resolve('../install-skill')];
309
+ delete require.cache[require.resolve('../detect-deps')];
310
+ delete require.cache[require.resolve('../shared-paths')];
311
+ }
312
+ });
313
+
314
+ // A bare ~/.dsh/skills must not steal an opencode machine — restated here
315
+ // because this is exactly the case the duplicated table got wrong.
316
+ it('does not target ~/.dsh/skills when only that directory exists', () => {
317
+ fs.mkdirSync(path.join(tmpHome, '.dsh', 'skills'), { recursive: true });
318
+ const { detectPlatform } = require('../shared-paths');
319
+ const { getSkillsDirs } = require('../detect-deps');
320
+
321
+ expect(getSkillsDirs(detectPlatform())[0]).not.toBe(path.join(tmpHome, '.dsh', 'skills'));
322
+ });
323
+ });
package/lib/baseline.js CHANGED
@@ -38,15 +38,164 @@ function parseArgs(subargs) {
38
38
  /**
39
39
  * Run a lint tool and return its JSON output.
40
40
  */
41
- function runToolJson(toolCmd, pipeToJsonFlag) {
42
- try {
43
- const cmd = `${toolCmd} ${pipeToJsonFlag}`;
44
- return execSync(cmd, { encoding: 'utf8', maxBuffer: 10 * 1024 * 1024 }).trim();
45
- } catch (e) {
46
- // Lint tools exit non-zero when they find issues - that's expected
47
- if (e.stdout) return e.stdout.trim();
48
- return '';
41
+ // How many paths to pass to a linter in one call.
42
+ //
43
+ // A single argv built from every source file is not a style problem, it is a
44
+ // correctness one: this repo has 652 TS/JS files and the joined list measured
45
+ // 31,917 characters against a Windows limit around 8,191. The call always failed,
46
+ // the failure was swallowed, and the baseline recorded zero eslint entries -- so
47
+ // Gate 1 compared every TS/JS file against a baseline of nothing.
48
+ //
49
+ // 100 paths keeps the argv in the low thousands of characters even for deep
50
+ // paths, well clear of the limit on every platform.
51
+ const LINT_BATCH_SIZE = 100;
52
+
53
+ /**
54
+ * Run a lint tool over a list of paths, in batches, and return its findings.
55
+ *
56
+ * Returns an object rather than a bare string so the caller can tell apart the
57
+ * two states that used to be identical: "the tool ran and found nothing" versus
58
+ * "the tool could not be evaluated". Collapsing them is how a baselining command
59
+ * reports success while having measured nothing.
60
+ *
61
+ * @param {string[]} files project-relative paths
62
+ * @param {(batch: string[]) => string} buildCmd builds the command line for a batch
63
+ * @param {string} jsonFlag flag that makes the tool emit JSON on stdout
64
+ * @returns {{results: any[], errors: string[]}} parsed per-batch results, or a
65
+ * list of failure messages. An empty `results` with a non-empty `errors` means
66
+ * "not evaluated", never "clean".
67
+ */
68
+ function runLintInBatches(files, buildCmd, jsonFlag) {
69
+ const results = [];
70
+ const errors = [];
71
+
72
+ for (let i = 0; i < files.length; i += LINT_BATCH_SIZE) {
73
+ const batch = files.slice(i, i + LINT_BATCH_SIZE);
74
+ let stdout;
75
+ try {
76
+ stdout = execSync(`${buildCmd(batch)} ${jsonFlag}`, {
77
+ encoding: 'utf8',
78
+ maxBuffer: 10 * 1024 * 1024,
79
+ });
80
+ } catch (e) {
81
+ // Non-zero exit is the tool's normal answer when it FOUND something, and
82
+ // its stdout still carries the JSON. Only an empty stdout is a failure.
83
+ stdout = e.stdout;
84
+ if (!stdout || !String(stdout).trim()) {
85
+ errors.push(formatToolFailure(e));
86
+ continue;
87
+ }
88
+ }
89
+ const trimmed = String(stdout).trim();
90
+ if (!trimmed) continue;
91
+ try {
92
+ const parsed = JSON.parse(trimmed);
93
+ if (Array.isArray(parsed)) results.push(...parsed);
94
+ } catch {
95
+ errors.push(`linter returned unparseable output for ${batch.length} file(s)`);
96
+ }
97
+ }
98
+
99
+ return { results, errors };
100
+ }
101
+
102
+ /**
103
+ * Resolve a tool installed in `node_modules/.bin` to something execSync can run.
104
+ *
105
+ * `fs.existsSync('node_modules/.bin/eslint')` is not enough on Windows, and the
106
+ * path it returns cannot be executed there at all. Measured on this machine:
107
+ *
108
+ * node_modules/.bin/eslint -> cmd.exe reports "'node_modules' is not
109
+ * recognized" (a relative path is not an
110
+ * executable name to cmd)
111
+ * node node_modules/.bin/eslint -> SyntaxError, because the extensionless
112
+ * entry is a POSIX sh wrapper
113
+ * node_modules/.bin/eslint.cmd -> same "not recognized" failure
114
+ * absolute path to eslint.cmd -> works (v10.3.0)
115
+ *
116
+ * So the resolution has to produce an ABSOLUTE path and pick the platform's
117
+ * launcher: `.cmd` on Windows, the bare script elsewhere.
118
+ *
119
+ * @param {string} name tool name, e.g. 'eslint'
120
+ * @param {string} [cwd] directory to resolve against
121
+ * @returns {string|null} absolute path to an executable, or null
122
+ */
123
+ function resolveLocalBin(name, cwd = process.cwd()) {
124
+ const binDir = path.join(cwd, 'node_modules', '.bin');
125
+ const candidates = process.platform === 'win32'
126
+ ? [`${name}.cmd`, name]
127
+ : [name];
128
+
129
+ for (const candidate of candidates) {
130
+ const full = path.join(binDir, candidate);
131
+ try {
132
+ if (fs.existsSync(full)) return full;
133
+ } catch {
134
+ // Unreadable candidate -- try the next one.
135
+ }
136
+ }
137
+ return null;
138
+ }
139
+
140
+ /**
141
+ * Format a resolved binary for use inside a shell command line.
142
+ *
143
+ * The path is quoted because node_modules can live under a directory with spaces
144
+ * ("C:\Program Files\..."), which would otherwise split into several args.
145
+ */
146
+ function quoteBin(bin) {
147
+ return `"${bin}"`;
148
+ }
149
+
150
+ /** One-line reason a tool run failed, from the error object execSync threw. */
151
+ function formatToolFailure(err) {
152
+ const stderr = err && err.stderr ? String(err.stderr).trim() : '';
153
+ if (stderr) {
154
+ // The Windows "command line is too long" case prints exactly this; naming it
155
+ // is what turns an invisible defect into a one-line diagnosis.
156
+ return stderr.split('\n')[0].trim();
49
157
  }
158
+ const msg = err && err.message ? String(err.message) : 'unknown error';
159
+ const status = err && typeof err.status === 'number' ? ` (exit ${err.status})` : '';
160
+ return `${msg.split('\n')[0].trim()}${status}`;
161
+ }
162
+
163
+ /**
164
+ * Report a linter that could not be evaluated.
165
+ *
166
+ * Silence is what let "TypeScript was never baselined" survive in this repo: the
167
+ * command printed a cheerful "✅ Baseline created" while 652 files had contributed
168
+ * nothing. A warning is the minimum contract -- the caller can still finish, but
169
+ * the user is told which language went unmeasured and why.
170
+ *
171
+ * @param {string} tool
172
+ * @param {string[]} errors
173
+ */
174
+ function recordFailures(tool, errors) {
175
+ if (!errors || errors.length === 0) return;
176
+ const unique = [...new Set(errors)];
177
+ const shown = unique.slice(0, 3).join('; ');
178
+ const more = unique.length > 3 ? ` (+${unique.length - 3} more)` : '';
179
+ console.warn(`⚠️ ${tool}: could not evaluate ${errors.length} batch(es) — ${shown}${more}`);
180
+ console.warn(` Files covered by a failed batch are absent from the baseline, not clean.`);
181
+ }
182
+
183
+ /**
184
+ * Match a linter's reported path back to one of the files we asked about.
185
+ *
186
+ * Returns null rather than undefined when nothing matches. The previous version
187
+ * used the result of `Array.prototype.find` as an object key, which stringifies
188
+ * an unmatched lookup to the literal key "undefined" -- one bogus baseline entry
189
+ * that made "71 files tracked" print for 70 real files.
190
+ *
191
+ * @param {string} reportedPath absolute or relative path from the tool
192
+ * @param {string[]} candidates the files handed to the tool
193
+ * @returns {string|null}
194
+ */
195
+ function matchResultToFile(reportedPath, candidates) {
196
+ if (!reportedPath) return null;
197
+ const normalized = String(reportedPath).replace(/\\/g, '/');
198
+ return candidates.find(f => normalized.endsWith(f)) || null;
50
199
  }
51
200
 
52
201
  /**
@@ -129,64 +278,84 @@ async function createBaseline() {
129
278
  // TypeScript/JavaScript — ESLint
130
279
  const tsFiles = findFilesByExt(['.ts', '.tsx', '.js', '.jsx']);
131
280
  if (tsFiles.length > 0) {
132
- try {
133
- const eslintConfigExists = fs.existsSync('.eslintrc.json') ||
134
- fs.existsSync('.eslintrc.js') ||
135
- fs.existsSync('.eslintrc.cjs') ||
136
- fs.existsSync('eslint.config.js');
137
- const eslintBin = fs.existsSync('node_modules/.bin/eslint') ? 'node_modules/.bin/eslint' : null;
138
-
139
- if (eslintConfigExists && (eslintBin || execSync('npx eslint --version', { encoding: 'utf8' }))) {
140
- const eslintCmd = eslintBin || 'npx eslint';
141
- const output = runToolJson(`${eslintCmd} ${tsFiles.join(' ')}`, '-f json --no-warn-ignored');
142
- if (output && output !== '[]') {
143
- const parsed = JSON.parse(output);
144
- for (const fileResult of parsed) {
145
- const relativePath = fileResult.filePath;
146
- const fileName = tsFiles.find(f => relativePath.endsWith(f));
147
- if (!fileName) continue;
148
-
149
- baseline[fileName] = {
150
- eslint: {
151
- warnings: fileResult.warningCount || 0,
152
- errors: fileResult.errorCount || 0,
153
- },
154
- totalWarnings: fileResult.warningCount || 0,
155
- lastAnalyzed: new Date().toISOString(),
156
- };
157
- }
158
- }
281
+ const eslintConfigExists = fs.existsSync('.eslintrc.json') ||
282
+ fs.existsSync('.eslintrc.js') ||
283
+ fs.existsSync('.eslintrc.cjs') ||
284
+ fs.existsSync('eslint.config.js');
285
+ const eslintBin = resolveLocalBin('eslint');
286
+
287
+ let eslintAvailable = Boolean(eslintBin);
288
+ if (!eslintAvailable) {
289
+ try {
290
+ execSync('npx eslint --version', { encoding: 'utf8', stdio: 'pipe' });
291
+ eslintAvailable = true;
292
+ } catch {
293
+ eslintAvailable = false;
159
294
  }
160
- } catch {
161
- // ESLint unavailable — skip
295
+ }
296
+
297
+ if (eslintConfigExists && eslintAvailable) {
298
+ const eslintCmd = eslintBin ? quoteBin(eslintBin) : 'npx eslint';
299
+ const { results, errors } = runLintInBatches(
300
+ tsFiles,
301
+ batch => `${eslintCmd} ${batch.map(f => `"${f}"`).join(' ')}`,
302
+ '-f json --no-warn-ignored'
303
+ );
304
+ recordFailures('eslint', errors);
305
+ for (const fileResult of results) {
306
+ const fileName = matchResultToFile(fileResult.filePath, tsFiles);
307
+ if (!fileName) continue;
308
+
309
+ baseline[fileName] = {
310
+ eslint: {
311
+ warnings: fileResult.warningCount || 0,
312
+ errors: fileResult.errorCount || 0,
313
+ },
314
+ totalWarnings: fileResult.warningCount || 0,
315
+ lastAnalyzed: new Date().toISOString(),
316
+ };
317
+ }
318
+ } else if (tsFiles.length > 0 && !eslintConfigExists) {
319
+ // Not a failure: a project without an eslint config has nothing to
320
+ // baseline. Staying quiet here is correct; the silent-catch defect was
321
+ // about masking errors, not about projects that legitimately have no tool.
162
322
  }
163
323
  }
164
324
 
165
325
  // Python — ruff
166
326
  const pyFiles = findFilesByExt(['.py']);
167
327
  if (pyFiles.length > 0) {
328
+ let ruffAvailable = false;
168
329
  try {
169
- execSync('ruff --version', { encoding: 'utf8' });
170
- const output = runToolJson(`ruff check ${pyFiles.join(' ')}`, '--output-format json');
171
- if (output && output !== '[]') {
172
- const parsed = JSON.parse(output);
173
- for (const fileResult of parsed) {
174
- if (!baseline[fileResult.file]) {
175
- const messages = fileResult.messages || [];
176
- baseline[fileResult.file] = {
177
- ruff: { warnings: messages.length, errors: 0 },
178
- totalWarnings: messages.length,
179
- lastAnalyzed: new Date().toISOString(),
180
- };
181
- } else {
182
- const messages = fileResult.messages || [];
183
- baseline[fileResult.file].ruff = { warnings: messages.length, errors: 0 };
184
- baseline[fileResult.file].totalWarnings += messages.length;
185
- }
330
+ execSync('ruff --version', { encoding: 'utf8', stdio: 'pipe' });
331
+ ruffAvailable = true;
332
+ } catch {
333
+ ruffAvailable = false;
334
+ }
335
+
336
+ if (ruffAvailable) {
337
+ const { results, errors } = runLintInBatches(
338
+ pyFiles,
339
+ batch => `ruff check ${batch.map(f => `"${f}"`).join(' ')}`,
340
+ '--output-format json'
341
+ );
342
+ recordFailures('ruff', errors);
343
+ for (const fileResult of results) {
344
+ // A result that names no file cannot be recorded against one. Skipping it
345
+ // is the fix for the literal "undefined" key this used to write.
346
+ if (!fileResult.file) continue;
347
+ const messages = fileResult.messages || [];
348
+ if (!baseline[fileResult.file]) {
349
+ baseline[fileResult.file] = {
350
+ ruff: { warnings: messages.length, errors: 0 },
351
+ totalWarnings: messages.length,
352
+ lastAnalyzed: new Date().toISOString(),
353
+ };
354
+ } else {
355
+ baseline[fileResult.file].ruff = { warnings: messages.length, errors: 0 };
356
+ baseline[fileResult.file].totalWarnings += messages.length;
186
357
  }
187
358
  }
188
- } catch {
189
- // Ruff unavailable — skip
190
359
  }
191
360
  }
192
361
 
@@ -232,39 +401,49 @@ async function createBaseline() {
232
401
  // Shell — shellcheck
233
402
  const shFiles = findShellScripts();
234
403
  if (shFiles.length > 0) {
404
+ let shAvailable = false;
235
405
  try {
236
- execSync('shellcheck --version', { encoding: 'utf8' });
237
- const output = runToolJson(`shellcheck -f json ${shFiles.join(' ')}`, '');
238
- if (output && output !== '[]') {
239
- const parsed = JSON.parse(output);
240
- const warningsByFile = {};
241
- for (const item of parsed) {
242
- const matchedFile = shFiles.find(f => item.file.endsWith(f));
243
- if (!matchedFile) continue;
244
- if (!warningsByFile[matchedFile]) {
245
- warningsByFile[matchedFile] = { warnings: 0, errors: 0 };
246
- }
247
- if (item.level === 'error') {
248
- warningsByFile[matchedFile].errors++;
249
- } else {
250
- warningsByFile[matchedFile].warnings++;
251
- }
406
+ execSync('shellcheck --version', { encoding: 'utf8', stdio: 'pipe' });
407
+ shAvailable = true;
408
+ } catch {
409
+ shAvailable = false;
410
+ }
411
+
412
+ if (shAvailable) {
413
+ // Same batching as the other tools: one argv for every shell script in the
414
+ // repo is the same platform-limit hazard, even though this repo happens to
415
+ // sit under the threshold today.
416
+ const { results, errors } = runLintInBatches(
417
+ shFiles,
418
+ batch => `shellcheck -f json ${batch.map(f => `"${f}"`).join(' ')}`,
419
+ ''
420
+ );
421
+ recordFailures('shellcheck', errors);
422
+ const warningsByFile = {};
423
+ for (const item of results) {
424
+ const matchedFile = matchResultToFile(item.file, shFiles);
425
+ if (!matchedFile) continue;
426
+ if (!warningsByFile[matchedFile]) {
427
+ warningsByFile[matchedFile] = { warnings: 0, errors: 0 };
252
428
  }
253
- for (const [file, counts] of Object.entries(warningsByFile)) {
254
- if (baseline[file]) {
255
- baseline[file].shellcheck = counts;
256
- baseline[file].totalWarnings += counts.warnings;
257
- } else {
258
- baseline[file] = {
259
- shellcheck: counts,
260
- totalWarnings: counts.warnings,
261
- lastAnalyzed: new Date().toISOString(),
262
- };
263
- }
429
+ if (item.level === 'error') {
430
+ warningsByFile[matchedFile].errors++;
431
+ } else {
432
+ warningsByFile[matchedFile].warnings++;
433
+ }
434
+ }
435
+ for (const [file, counts] of Object.entries(warningsByFile)) {
436
+ if (baseline[file]) {
437
+ baseline[file].shellcheck = counts;
438
+ baseline[file].totalWarnings += counts.warnings;
439
+ } else {
440
+ baseline[file] = {
441
+ shellcheck: counts,
442
+ totalWarnings: counts.warnings,
443
+ lastAnalyzed: new Date().toISOString(),
444
+ };
264
445
  }
265
446
  }
266
- } catch {
267
- // shellcheck unavailable — skip
268
447
  }
269
448
  }
270
449
 
@@ -468,4 +647,4 @@ Examples:
468
647
  }
469
648
  }
470
649
 
471
- module.exports = { handleBaseline, createBaseline, showBaseline, resetBaseline, diffBaseline, countBaselineByTool, compareBaselines, findShellScripts };
650
+ module.exports = { handleBaseline, createBaseline, showBaseline, resetBaseline, diffBaseline, countBaselineByTool, compareBaselines, findShellScripts, resolveLocalBin };
@@ -278,9 +278,14 @@ const PLATFORM_PROFILES = {
278
278
  // plugins/dsh (`@boyingliu01/dsh-plugin-xp-gate`), and
279
279
  // scripts/sync-package-content.js lists `dsh` among PLUGINS — but this entry
280
280
  // was missing, so getSkillsDirs('dsh') fell through to the opencode paths and
281
- // DSH skills were never resolved. detectPlatform() still never returns 'dsh'
282
- // (there is no marker it could key on that opencode's would not also match),
283
- // so callers that must cover DSH ask for it by name.
281
+ // DSH skills were never resolved.
282
+ //
283
+ // #635 follow-up: detectPlatform() now returns 'dsh' too (it keys on
284
+ // `~/.dsh/profiles` / `~/.dsh/.shim`, which no other platform writes). Before
285
+ // that, callers holding its result still targeted `~/.config/opencode` on a
286
+ // DSH-only machine, and `install-skill` failed its dependency check against
287
+ // that phantom directory. Callers that must cover every platform regardless
288
+ // of which one is "current" still ask by name, via detectInstalledPlatforms().
284
289
  dsh: {
285
290
  skillsDirs: [
286
291
  ['.dsh', 'skills'],
package/lib/doctor.js CHANGED
@@ -3427,12 +3427,16 @@ async function doctorDelphi(options = {}) {
3427
3427
  // an old local repo" became a downgrade (#414 B4). Every bundled file is
3428
3428
  // compared, not just SKILL.md — the install script copies *.json and
3429
3429
  // references/ too, and B4-style drift hits those equally (#414 R1 MI-03).
3430
+ //
3431
+ // #635 follow-up: this was a THIRD hand-written platform→directory table
3432
+ // (after PLATFORM_PROFILES and install-skill's own), and it had no `dsh` arm,
3433
+ // so on a DSH machine it resolved to `~/.config/opencode/skills/delphi-review`
3434
+ // — a directory that does not exist. `otherDeployedSkillDirs()` below rescued
3435
+ // the parity check, but the runner-locate check further down read this path
3436
+ // directly and never consulted the full platform set. Derive it instead, so
3437
+ // the mapping has one source of truth and a new platform needs no edit here.
3430
3438
  const platform = detectPlatform();
3431
- const installedSkillDir = platform === 'qoder'
3432
- ? path.join(HOME_DIR(), '.qoder', 'skills', 'delphi-review')
3433
- : platform === 'claude-code'
3434
- ? path.join(HOME_DIR(), '.claude', 'skills', 'delphi-review')
3435
- : path.join(HOME_DIR(), '.config', 'opencode', 'skills', 'delphi-review');
3439
+ const installedSkillDir = path.join(getSkillsDirs(platform)[0], 'delphi-review');
3436
3440
  // Injectable for tests (#414 R3 FC-01/FC-02): the empty-bundle branch is a
3437
3441
  // real failure mode and must be drivable without mutating the package.
3438
3442
  const bundledSkillDir = options.bundledSkillDir || path.join(PKG_DIR, 'skills', 'delphi-review');
@@ -697,6 +697,20 @@ const GATE_REGISTRY = {
697
697
  preCommitOnly: true,
698
698
  reason: 'File hygiene inspects the staged diff, which only exists inside the hook',
699
699
  },
700
+ '12b': {
701
+ name: 'Mirror Parity',
702
+ description: 'canonical hook sources match their published src/npm-package mirrors (#654)',
703
+ aliases: ['mirror', 'mirror-parity', '12b'],
704
+ preCommitOnly: true,
705
+ reason: 'Mirror parity compares the staged pair of files against their canonical copies',
706
+ },
707
+ '12c': {
708
+ name: 'Probe Discipline',
709
+ description: 'no gate answers "is this tool installed?" by querying a registry',
710
+ aliases: ['probe', 'probe-discipline', '12c'],
711
+ preCommitOnly: true,
712
+ reason: 'Probe discipline scans hook sources in the staged change set',
713
+ },
700
714
  '13': {
701
715
  name: 'Compiler Strictness',
702
716
  description: 'gcc/g++ -Wall -Wextra, javac -Xlint, Maven/Gradle warnings on changed files',