@boyingliu01/xp-gate 0.38.32 → 0.38.34

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 (34) hide show
  1. package/adapters/gate-3.sh +39 -3
  2. package/adapters/gate-4.sh +1 -1
  3. package/adapters/iac.sh +13 -0
  4. package/adapters/php.sh +362 -0
  5. package/gate-3.sh +39 -3
  6. package/gate-4.sh +1 -1
  7. package/hooks/gate-3.sh +39 -3
  8. package/hooks/gate-4.sh +1 -1
  9. package/lib/__tests__/language-capability.test.js +291 -0
  10. package/lib/__tests__/language-tools-detect.test.js +82 -0
  11. package/lib/language-capability-surfaces.js +315 -0
  12. package/lib/language-capability.js +474 -0
  13. package/lib/language-tools.js +107 -0
  14. package/lib/mattpocock-license-verdict.json +1 -1
  15. package/package.json +1 -1
  16. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  17. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  18. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  19. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  20. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  21. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  22. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  23. package/plugins/opencode/package.json +1 -1
  24. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  25. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  26. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  27. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  28. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  29. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  30. package/principles/adapters/php.ts +77 -0
  31. package/principles/analyzer.ts +6 -0
  32. package/skills/delphi-review/AGENTS.md +1 -1
  33. package/skills/sprint-flow/AGENTS.md +1 -1
  34. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Per-gate inspection helpers for the language-capability report.
3
+ *
4
+ * One function per gate surface, each returning the single row it produces.
5
+ * Split out of a 264-line inspectLanguage() after Gate 4 measured it: the
6
+ * original passed the report but failed clean-code.long-function (max 50
7
+ * lines), and a report that cannot itself pass the gate it explains has no
8
+ * standing to explain anything.
9
+ *
10
+ * Every helper takes (lang, exts, ctx) and returns one row. `ctx.read(rel)`
11
+ * returns the file text or null, so "unreadable" is distinguishable from
12
+ * "empty" -- an unreadable file is not evidence of wiring.
13
+ */
14
+
15
+ /** The four functions pre-commit calls directly on a language adapter (#688). */
16
+ function inspectAdapterSurface(deps, lang, exts, ctx) {
17
+ const adapterPath = `githooks/adapters/${lang}.sh`;
18
+ if (ctx.root === null) return deps.row('adapter', lang, deps.STATE.UNKNOWN, 'githooks/ not found');
19
+ const adapter = ctx.read(adapterPath);
20
+ if (adapter === null) {
21
+ return deps.row('adapter', lang, deps.STATE.NOT_IMPLEMENTED, `${adapterPath} missing`);
22
+ }
23
+ const required = ['run_static_analysis', 'run_lint', 'run_tests', 'run_coverage'];
24
+ const missing = required.filter((fn) => !deps.definitionAndCall(adapter, fn).defined);
25
+ return missing.length === 0
26
+ ? deps.row('adapter', lang, deps.STATE.CHECKED, `${adapterPath}: 4/4 functions`)
27
+ : deps.row('adapter', lang, deps.STATE.NOT_WIRED, `${adapterPath} lacks ${missing.join(', ')}`);
28
+ }
29
+
30
+ /** Gate 0: does detection emit this language? */
31
+ function inspectGate0(deps, lang, exts, ctx) {
32
+ const src = ctx.read('githooks/gate-entries/gate-0-entry.sh');
33
+ if (src === null) return deps.row('gate0-detect', lang, deps.STATE.UNKNOWN, 'gate-0-entry.sh unreadable');
34
+ return deps.hasLanguageKey(src, lang)
35
+ ? deps.row('gate0-detect', lang, deps.STATE.CHECKED, `_detect_ext_lang emits ${lang}`)
36
+ : deps.row('gate0-detect', lang, deps.STATE.NOT_WIRED, `no _detect_ext_lang arm adds ${lang}`);
37
+ }
38
+
39
+ /**
40
+ * Gate 1: the CHANGED-FILE SHORT-CIRCUIT is the decisive list. A language
41
+ * missing from this alternation makes Gate 1 stand down before it looks at any
42
+ * adapter, which is the exact #798 shape.
43
+ */
44
+ function inspectGate1(deps, lang, exts, ctx) {
45
+ const src = ctx.read('githooks/gate-entries/gate-1-entry.sh');
46
+ if (src === null) return deps.row('gate-1', lang, deps.STATE.UNKNOWN, 'gate-1-entry.sh unreadable');
47
+ // Read the `any_changed_files_match "\.(...)$"` call specifically: the file
48
+ // contains several longer alternations (shell shebang handling) that would
49
+ // match the token by accident.
50
+ const scLine = src.split('\n').find((l) => l.includes('any_changed_files_match "\\\.(')) || '';
51
+ const wired = deps.anyAlternationHas(scLine, exts);
52
+ return deps.row(
53
+ 'gate-1',
54
+ lang,
55
+ wired ? deps.STATE.CHECKED : deps.STATE.NOT_WIRED,
56
+ wired
57
+ ? 'present in the changed-file short-circuit'
58
+ : 'ABSENT from the changed-file short-circuit: Gate 1 stands down before the adapter runs',
59
+ );
60
+ }
61
+
62
+ /** Gate 2: duplicate code. A dedicated `<lang>)` arm wins over the generic list. */
63
+ function inspectGate2(deps, lang, exts, ctx) {
64
+ const src = ctx.read('githooks/gate-entries/gate-2-entry.sh');
65
+ if (src === null) return deps.row('gate-2', lang, deps.STATE.UNKNOWN, 'gate-2-entry.sh unreadable');
66
+ if (deps.hasLanguageKey(src, lang)) {
67
+ return deps.row('gate-2', lang, deps.STATE.CHECKED, `dedicated "${lang})" arm`);
68
+ }
69
+ const inList = deps.anyAlternationHas(src, exts);
70
+ return inList
71
+ ? deps.row(
72
+ 'gate-2',
73
+ lang,
74
+ deps.STATE.CHECKED,
75
+ 'generic jscpd arm lists the extension (see C3: empty list prints PASS)',
76
+ )
77
+ : deps.row(
78
+ 'gate-2',
79
+ lang,
80
+ deps.STATE.NOT_WIRED,
81
+ `"${lang})" arm absent and extension not in the generic list`,
82
+ );
83
+ }
84
+
85
+ /**
86
+ * Gate 3: the lizard population. The extension must appear in the gate at all;
87
+ * whether the CURRENT repo’s baseline also declares it depends on whether that
88
+ * repo HAS the language, so that second fact is reported as evidence, not folded
89
+ * into the state -- it would otherwise make every language absent from this
90
+ * repo report NOT WIRED, which is a fact about the repo, not about the wiring.
91
+ */
92
+ function inspectGate3(deps, lang, exts, ctx) {
93
+ const gate3 = ctx.read('githooks/adapters/gate-3.sh');
94
+ if (gate3 === null) {
95
+ return deps.row('gate-3', lang, deps.STATE.UNKNOWN, 'gate-3.sh unreadable');
96
+ }
97
+ // Scan the WHOLE file: the extension has been listed in more than one
98
+ // alternation over time and a name-bound reader went silently blank once.
99
+ const wired = deps.anyAlternationHas(gate3, exts);
100
+ if (!wired) {
101
+ return deps.row(
102
+ 'gate-3',
103
+ lang,
104
+ deps.STATE.NOT_WIRED,
105
+ 'lizard population EXCLUDES the extension',
106
+ );
107
+ }
108
+ // Evidence only: does this repo's baseline score the language? A baseline
109
+ // written before the language existed legitimately omits it (#617 declares the
110
+ // population it was written from), and that is not a wiring defect.
111
+ let note = '';
112
+ const baseline = ctx.read('.ccn-baseline.json');
113
+ if (baseline !== null) {
114
+ try {
115
+ const declared = JSON.parse(baseline)?.population?.extensions || [];
116
+ if (!exts.some((e) => declared.includes(`.${e}`))) {
117
+ note =
118
+ ' (no baseline entry in THIS repo: the population is derived from the files that exist, so nothing here is scored until such code is added)';
119
+ }
120
+ } catch {
121
+ note = ' (.ccn-baseline.json is not valid JSON)';
122
+ }
123
+ }
124
+ return deps.row('gate-3', lang, deps.STATE.CHECKED, `lizard population includes the extension${note}`);
125
+ }
126
+
127
+ /**
128
+ * Gate 4: BOTH the filter and the analyzer map. Accepting a file in the filter
129
+ * and dropping it in the map is the #717 defect: the gate reports a clean run
130
+ * over code it never opened.
131
+ */
132
+ function inspectGate4(deps, lang, exts, ctx) {
133
+ const gate = ctx.read('githooks/adapters/gate-4.sh');
134
+ const analyzer = ctx.read('src/principles/analyzer.ts');
135
+ if (gate === null) return deps.row('gate-4', lang, deps.STATE.UNKNOWN, 'gate-4.sh unreadable');
136
+ if (analyzer === null) {
137
+ return deps.row('gate-4', lang, deps.STATE.UNKNOWN, 'src/principles/analyzer.ts unreadable');
138
+ }
139
+ const filterLine = gate.split('\n').find((l) => l.includes('PRINCIPLES_FILES=')) || '';
140
+ const inFilter = deps.anyAlternationHas(filterLine, exts);
141
+ const inMap = exts.some((e) => analyzer.includes(`'.${e}':`));
142
+ if (inFilter && inMap) {
143
+ return deps.row('gate-4', lang, deps.STATE.CHECKED, 'filter + analyzer.ts adapterMap both present');
144
+ }
145
+ if (inFilter && !inMap) {
146
+ return deps.row(
147
+ 'gate-4',
148
+ lang,
149
+ deps.STATE.NOT_WIRED,
150
+ 'FILTER ACCEPTS IT, analyzer.ts adapterMap has no entry -> file accepted then dropped (#717)',
151
+ );
152
+ }
153
+ if (!inFilter && inMap) {
154
+ return deps.row(
155
+ 'gate-4',
156
+ lang,
157
+ deps.STATE.NOT_WIRED,
158
+ 'adapterMap has an entry but the filter rejects the extension: the adapter is unreachable',
159
+ );
160
+ }
161
+ return deps.row('gate-4', lang, deps.STATE.NOT_WIRED, 'extension absent from gate-4.sh PRINCIPLES_FILES');
162
+ }
163
+
164
+ /** Gate 5: test/coverage entry. An absent extension takes the #763 skip. */
165
+ function inspectGate5(deps, lang, exts, ctx) {
166
+ const src = ctx.read('githooks/gate-entries/gate-5-entry.sh');
167
+ if (src === null) return deps.row('gate-5', lang, deps.STATE.UNKNOWN, 'gate-5-entry.sh unreadable');
168
+ const ceLine = src.split('\n').find((l) => l.includes('CODE_EXTENSIONS=')) || '';
169
+ const wired = deps.anyAlternationHas(ceLine, exts);
170
+ return wired
171
+ ? deps.row('gate-5', lang, deps.STATE.CHECKED, 'CODE_EXTENSIONS includes the extension')
172
+ : deps.row(
173
+ 'gate-5',
174
+ lang,
175
+ deps.STATE.NOT_WIRED,
176
+ 'ABSENT from CODE_EXTENSIONS: a commit touching only this language takes the "no code files changed" skip (#763)',
177
+ );
178
+ }
179
+
180
+ /** Gate 6: architecture detector arm. */
181
+ function inspectGate6(deps, lang, exts, ctx) {
182
+ const src = ctx.read('githooks/gate-entries/gate-6-entry.sh');
183
+ if (src === null) return deps.row('gate-6', lang, deps.STATE.UNKNOWN, 'gate-6-entry.sh unreadable');
184
+ return deps.hasLanguageKey(src, lang)
185
+ ? deps.row('gate-6', lang, deps.STATE.CHECKED, `"${lang})" arm present`)
186
+ : deps.row('gate-6', lang, deps.STATE.NOT_IMPLEMENTED, `no "${lang})" arm: falls to the no-detector branch`);
187
+ }
188
+
189
+ /** Gate 9: build integrity arm. */
190
+ function inspectGate9(deps, lang, exts, ctx) {
191
+ const src = ctx.read('githooks/gate-entries/gate-9-entry.sh');
192
+ if (src === null) return deps.row('gate-9', lang, deps.STATE.UNKNOWN, 'gate-9-entry.sh unreadable');
193
+ return deps.hasLanguageKey(src, lang)
194
+ ? deps.row('gate-9', lang, deps.STATE.CHECKED, `"${lang})" arm present`)
195
+ : deps.row('gate-9', lang, deps.STATE.NOT_IMPLEMENTED, 'no build arm: this language is SKIPped with no verdict');
196
+ }
197
+
198
+ /**
199
+ * Gate 10: SAST ruleset. The measured question is whether ANY loaded ruleset
200
+ * can analyse the language, which is why the baseline list is consulted rather
201
+ * than the mere presence of a `p/` directory.
202
+ */
203
+ function inspectGate10(deps, lang, exts, ctx) {
204
+ const hasRuleset = ctx.root !== null && ctx.read(`sast/rulesets/p/${lang}`) !== null;
205
+ if (hasRuleset) return deps.row('gate-10', lang, deps.STATE.CHECKED, `dedicated p/${lang} ruleset`);
206
+ if (deps.SAST_BASELINE_LANGUAGES.has(lang)) {
207
+ return deps.row('gate-10', lang, deps.STATE.CHECKED, 'covered by the p/security-audit baseline ruleset');
208
+ }
209
+ return deps.row(
210
+ 'gate-10',
211
+ lang,
212
+ deps.STATE.UNKNOWN,
213
+ `no p/${lang} ruleset and the language is NOT in the p/security-audit baseline as measured: verify whether any loaded ruleset can analyse it before claiming coverage`,
214
+ );
215
+ }
216
+
217
+ /** Gate 13: compiler strictness -- DEFINED (adapter) AND INVOKED (entry). */
218
+ function inspectGate13(deps, lang, exts, ctx) {
219
+ const strictness = ctx.read('githooks/adapters/gate-13-compiler-strictness.sh');
220
+ const entry13 = ctx.read('githooks/gate-entries/gate-13-entry.sh');
221
+ if (strictness === null || entry13 === null) {
222
+ return deps.row('gate-13', lang, deps.STATE.UNKNOWN, 'gate-13 files unreadable');
223
+ }
224
+ const fnName = `gate13_run_${lang}_analysis`;
225
+ const { defined } = deps.definitionAndCall(strictness, fnName);
226
+ const { called } = deps.definitionAndCall(entry13, fnName);
227
+ if (!defined) {
228
+ return deps.row('gate-13', lang, deps.STATE.NOT_IMPLEMENTED, `${fnName}() not defined`);
229
+ }
230
+ if (!called) {
231
+ return deps.row(
232
+ 'gate-13',
233
+ lang,
234
+ deps.STATE.NOT_WIRED,
235
+ `${fnName}() DEFINED BUT NEVER CALLED - the exact C# defect (#717 section 8)`,
236
+ );
237
+ }
238
+ return deps.row('gate-13', lang, deps.STATE.CHECKED, `${fnName}() defined and invoked`);
239
+ }
240
+
241
+ /** CLI registry: LANGUAGE_REGISTRY key. */
242
+ function inspectRegistry(deps, lang, exts, ctx) {
243
+ const langTools = ctx.read('src/npm-package/lib/language-tools.js');
244
+ if (langTools === null) {
245
+ return deps.row('cli-registry', lang, deps.STATE.UNKNOWN, 'language-tools.js unreadable');
246
+ }
247
+ // [#731] The original pattern was `^\s{2}${lang}:\s*\{` with the `m` flag,
248
+ // and it NEVER matched: under `m`, `\s` matches the newline that `^` just
249
+ // anchored to, so `^\s{2}` demanded a blank line followed by another whitespace
250
+ // run. Measured: `new RegExp('^\\s{2}csharp:\\s*\\{','m').test(src)` was false
251
+ // against a file whose line 306 is literally ` csharp: {`. Every language was
252
+ // therefore reported NOT WIRED here, including ones whose entry exists --
253
+ // a false accusation that hid the real gaps by making them all look alike.
254
+ // `[ \t]{2}` is what the pattern meant: two spaces of indentation.
255
+ const registered = new RegExp(`^[ \\t]{2}${lang}:[ \\t]*\\{`, 'm').test(langTools);
256
+ return deps.row(
257
+ 'cli-registry',
258
+ lang,
259
+ registered ? deps.STATE.CHECKED : deps.STATE.NOT_WIRED,
260
+ registered
261
+ ? 'LANGUAGE_REGISTRY entry present'
262
+ : 'ABSENT from LANGUAGE_REGISTRY: detect-languages omits it, and the hook trusts that config without an extension fallback (#730)',
263
+ );
264
+ }
265
+
266
+ /**
267
+ * CI detection. `.github/workflows/` keeps a private copy of the detection
268
+ * chain, so a language present locally can still be invisible to CI -- the
269
+ * duplication is the reason this surface is checked separately.
270
+ */
271
+ function inspectCiDetection(deps, lang, exts, ctx) {
272
+ const src = ctx.read('.github/workflows/quality-gates.yml');
273
+ if (src === null) {
274
+ return deps.row('ci-detect', lang, deps.STATE.UNKNOWN, 'quality-gates.yml unreadable');
275
+ }
276
+ return deps.hasLanguageKey(src, lang)
277
+ ? deps.row('ci-detect', lang, deps.STATE.CHECKED, 'CI detection chain names the language')
278
+ : deps.row('ci-detect', lang, deps.STATE.NOT_WIRED, 'CI keeps a private copy of the chain and omits it');
279
+ }
280
+
281
+ /** The ordered surface list, one entry per checkable surface. */
282
+ const SURFACE_CHECKS = [
283
+ ['adapter', inspectAdapterSurface],
284
+ ['gate0-detect', inspectGate0],
285
+ ['gate-1', inspectGate1],
286
+ ['gate-2', inspectGate2],
287
+ ['gate-3', inspectGate3],
288
+ ['gate-4', inspectGate4],
289
+ ['gate-5', inspectGate5],
290
+ ['gate-6', inspectGate6],
291
+ ['gate-9', inspectGate9],
292
+ ['gate-10', inspectGate10],
293
+ ['gate-13', inspectGate13],
294
+ ['cli-registry', inspectRegistry],
295
+ ['ci-detect', inspectCiDetection],
296
+ ];
297
+
298
+ /**
299
+ * Inspect every surface for one language.
300
+ *
301
+ * @param {string} lang
302
+ * @param {{root: string|null, read: (rel: string) => string|null}} ctx
303
+ * @returns {Array<{surface: string, language: string, state: string, evidence: string}>}
304
+ */
305
+ function inspectLanguage(deps, lang, ctx) {
306
+ const spec = deps.LANGUAGES ? deps.LANGUAGES[lang] : null;
307
+ const exts = spec ? spec.extensions : [lang];
308
+ return SURFACE_CHECKS.map(([, check]) => check(deps, lang, exts, ctx));
309
+ }
310
+
311
+
312
+ module.exports = {
313
+ inspectLanguage,
314
+ SURFACE_CHECKS,
315
+ };