@roomi-fields/grillhouse 0.53.0 → 0.54.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.
Files changed (62) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +54 -0
  3. package/cadre/templates/projet/docs/agents/issue-tracker.md +2 -2
  4. package/charte.md +12 -0
  5. package/dist/temporal/circuit/deroule.js +5 -9
  6. package/dist/temporal/circuit/deroule.js.map +1 -1
  7. package/dist/temporal/installation.d.ts +15 -2
  8. package/dist/temporal/installation.js +69 -17
  9. package/dist/temporal/installation.js.map +1 -1
  10. package/docs/INTERFACE.md +21 -1
  11. package/docs/architecture/circuit.md +3 -3
  12. package/docs/architecture/entree.md +4 -4
  13. package/docs/architecture/greffon.md +28 -17
  14. package/docs/architecture/installation.md +21 -11
  15. package/docs/architecture/machine.md +1 -1
  16. package/docs/architecture/tests.md +1 -1
  17. package/hooks/register.tsx +50 -24
  18. package/package.json +1 -1
  19. package/scripts/aiguillage.mjs +4 -2
  20. package/scripts/bd-garde.mjs +69 -0
  21. package/scripts/ci-de-main.mjs +259 -56
  22. package/scripts/circuit.mjs +20 -5
  23. package/scripts/commandes-composees.mjs +1 -1
  24. package/scripts/droits.mjs +11 -4
  25. package/scripts/file-des-tickets.mjs +27 -9
  26. package/scripts/greffons.mjs +282 -17
  27. package/scripts/langages/c/commandes.mjs +1 -1
  28. package/scripts/langages/cargo/commandes.mjs +1 -1
  29. package/scripts/langages/cargo/tailles-des-tests.mjs +115 -6
  30. package/scripts/langages/python/commandes.mjs +1 -1
  31. package/scripts/langages/typescript/code-mort.mjs +36 -3
  32. package/scripts/langages/typescript/migrations/configurations-en-commonjs.mjs +95 -24
  33. package/scripts/langages/typescript/mise-a-jour.mjs +49 -12
  34. package/scripts/langages/typescript/parcours.mjs +5 -1
  35. package/scripts/langages.d.mts +6 -0
  36. package/scripts/langages.mjs +6 -0
  37. package/scripts/lire.mjs +236 -0
  38. package/scripts/migrations/cout-des-jetons-au-registre.mjs +136 -0
  39. package/scripts/migrations/lire-un-ticket.mjs +46 -0
  40. package/scripts/migrations.mjs +4 -0
  41. package/scripts/montee.mjs +123 -47
  42. package/scripts/nuit.sh +21 -12
  43. package/scripts/registre.d.mts +7 -1
  44. package/scripts/registre.mjs +114 -102
  45. package/scripts/resultats.mjs +15 -5
  46. package/scripts/retirer-copie.sh +7 -0
  47. package/scripts/sous-commandes.mjs +1 -0
  48. package/scripts/suiveur.mjs +12 -4
  49. package/scripts/superviseur.mjs +111 -31
  50. package/scripts/tableau.mjs +527 -119
  51. package/scripts/tarifs.mjs +67 -0
  52. package/scripts/ticket-du-circuit.mjs +3 -4
  53. package/scripts/transitions.d.mts +0 -5
  54. package/scripts/transitions.mjs +3 -13
  55. package/scripts/verdict-de-la-nuit.mjs +2 -2
  56. package/skills/explorateur/SKILL.md +10 -5
  57. package/skills/mesure/SKILL.md +4 -3
  58. package/skills/pitmaster/SKILL.md +18 -4
  59. package/skills/pitmaster/references/erreurs.md +4 -2
  60. package/skills/pitmaster/references/tour.md +11 -4
  61. package/types/index.d.ts +3 -1
  62. package/scripts/base-des-workflows.mjs +0 -58
@@ -6,6 +6,8 @@
6
6
  //
7
7
  // npx grillhouse greffons [<project>] installs the declared plugins (the current directory by default)
8
8
  // npx grillhouse greffons --absents [<project>] prints what the project lacks, one line each (see below)
9
+ // npx grillhouse greffons --purger removes the entries whose folder is gone
10
+ // npx grillhouse greffons --oublier <copy> removes the entries of a working copy
9
11
  //
10
12
  // - The list is `enabledPlugins` of the project's `.claude/settings.json` (a plugin at `true`; one
11
13
  // at `false` or unlisted is left alone) and `extraKnownMarketplaces` for the marketplaces. A
@@ -22,7 +24,14 @@
22
24
  // claude added after), and its exact text when the JSON value is the same.
23
25
  // - A plugin is installed for the project when `claude plugin list --json` has an entry for it of
24
26
  // scope user, or of scope project or local whose `projectPath` is the project's root (both paths
25
- // resolved); the entry's state (enabled, errors) is not read.
27
+ // resolved); the entry's state (enabled, errors) is not read. That list is the account's, of every
28
+ // project, of any size, and `claude` filters none of it: a process of this script (`--lire`)
29
+ // reads it as it comes and hands over the entries that install for the project alone. A reading
30
+ // that fails says its cause (the delay, the signal, the return code and what claude wrote).
31
+ // - The registry of Claude Code (`plugins/installed_plugins.json` under `CLAUDE_CONFIG_DIR`, else
32
+ // `~/.claude`) loses entries of scope local alone, written there directly as `claude plugin
33
+ // uninstall` runs in a folder that is gone: those of a removed copy (scripts/retirer-copie.sh,
34
+ // `--oublier`) and those whose folder is gone (the montée, scripts/montee.mjs, `--purger`).
26
35
  // - A failure has its line on the error output, naming the plugin and the command that installs it
27
36
  // (a failed add: the marketplace's command, then the plugin's; a mod left at another version than
28
37
  // the package's: both versions and the command that aligns them — behind, after its update, `claude
@@ -41,11 +50,19 @@
41
50
  // montée to its version, `npx grillhouse maj <mod's version>`. A version that is not
42
51
  // x.y.z (a plugin whose manifest carries none) and a script without its package's package.json
43
52
  // beside it compare nothing.
44
- import { spawnSync } from 'node:child_process';
45
- import { existsSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
53
+ import { spawn, spawnSync } from 'node:child_process';
54
+ import {
55
+ existsSync,
56
+ readFileSync,
57
+ realpathSync,
58
+ renameSync,
59
+ statSync,
60
+ writeFileSync,
61
+ } from 'node:fs';
62
+ import os from 'node:os';
46
63
  import path from 'node:path';
47
64
  import { isDeepStrictEqual } from 'node:util';
48
- import { pathToFileURL } from 'node:url';
65
+ import { fileURLToPath, pathToFileURL } from 'node:url';
49
66
 
50
67
  const DELAI_LECTURE_MS = 5000;
51
68
 
@@ -58,17 +75,37 @@ function resolu(p) {
58
75
  }
59
76
  }
60
77
 
61
- // Runs claude; `absent` is true when the command does not exist, `delai` when it was stopped.
78
+ // Runs claude, its output read whole, whatever its size.
62
79
  function claude(args, options = {}) {
63
- const r = spawnSync('claude', args, { encoding: 'utf8', ...options });
80
+ const r = spawnSync('claude', args, { encoding: 'utf8', maxBuffer: Infinity, ...options });
64
81
  return {
65
82
  ok: r.status === 0 && !r.error,
66
83
  absent: r.error?.code === 'ENOENT',
67
84
  delai: r.error?.code === 'ETIMEDOUT',
85
+ status: r.status,
86
+ signal: r.signal,
87
+ code: r.error?.code,
68
88
  stdout: r.stdout ?? '',
89
+ stderr: r.stderr ?? '',
69
90
  };
70
91
  }
71
92
 
93
+ // The answer of a reading that failed: its command and its true cause.
94
+ function echecDeLecture(args, r, delai) {
95
+ const dit = r.stderr.trim().split('\n').at(-1);
96
+ const cause = r.delai
97
+ ? `interrompu après ${delai / 1000} s`
98
+ : `échoue (${
99
+ r.signal
100
+ ? `signal ${r.signal}`
101
+ : typeof r.status === 'number'
102
+ ? `code ${r.status}${dit ? ` : ${dit}` : ''}`
103
+ : r.code
104
+ })`;
105
+ return { erreur: `\`claude ${args.join(' ')} --json\` ${cause}`, delai: r.delai };
106
+ }
107
+
108
+ const illisible = args => ({ erreur: `\`claude ${args.join(' ')} --json\` rend un JSON illisible` });
72
109
  // The declaration of the project: `{ plugins: [id], marches: {name: {source}} }`, or `{ erreur }`.
73
110
  function declaration(projet) {
74
111
  const f = path.join(projet, '.claude', 'settings.json');
@@ -95,10 +132,7 @@ function lireListe(args, delai) {
95
132
  return { absent: true };
96
133
  }
97
134
  if (!r.ok) {
98
- return {
99
- erreur: `\`claude ${args.join(' ')} --json\` ${r.delai ? 'interrompu' : 'échoue'}`,
100
- delai: r.delai,
101
- };
135
+ return echecDeLecture(args, r, delai);
102
136
  }
103
137
  try {
104
138
  const v = JSON.parse(r.stdout);
@@ -108,9 +142,221 @@ function lireListe(args, delai) {
108
142
  } catch {
109
143
  // unreadable, below
110
144
  }
111
- return { erreur: `\`claude ${args.join(' ')} --json\` rend un JSON illisible` };
145
+ return illisible(args);
146
+ }
147
+
148
+ // Reads the text of a JSON array of objects piece by piece, one object parsed at a time, and holds
149
+ // those `garder` accepts alone: `lire(text)` each piece, then `fin()`, the objects held, or null
150
+ // when the text is no such array.
151
+ function filtreDeListe(garder) {
152
+ const tenus = [];
153
+ let lieu = 'avant';
154
+ let objet = '';
155
+ let profondeur = 0;
156
+ let chaine = false;
157
+ let echappe = false;
158
+ let faux = false;
159
+ const dansLObjet = c => {
160
+ objet += c;
161
+ if (chaine) {
162
+ chaine = echappe || c !== '"';
163
+ echappe = !echappe && c === '\\';
164
+ } else if (c === '"') {
165
+ chaine = true;
166
+ } else if (c === '{' || c === '[') {
167
+ profondeur++;
168
+ } else if (c === '}' || c === ']') {
169
+ profondeur--;
170
+ if (profondeur === 0) {
171
+ try {
172
+ const v = JSON.parse(objet);
173
+ if (garder(v)) {
174
+ tenus.push(v);
175
+ }
176
+ } catch {
177
+ faux = true;
178
+ }
179
+ objet = '';
180
+ }
181
+ }
182
+ };
183
+ const entreLesObjets = c => {
184
+ if (c === '[' && lieu === 'avant') {
185
+ lieu = 'dans';
186
+ } else if (c === ']' && lieu === 'dans') {
187
+ lieu = 'apres';
188
+ } else if (c === '{' && lieu === 'dans') {
189
+ profondeur = 1;
190
+ objet = c;
191
+ } else if (c !== ',' && c.trim() !== '') {
192
+ faux = true;
193
+ }
194
+ };
195
+ return {
196
+ lire(texte) {
197
+ for (const c of texte) {
198
+ (profondeur > 0 ? dansLObjet : entreLesObjets)(c);
199
+ }
200
+ },
201
+ fin: () => (!faux && lieu === 'apres' && profondeur === 0 ? tenus : null),
202
+ };
203
+ }
204
+
205
+ // `greffons.mjs --lire <root> <delay>`, the process of `lireGreffons`: runs `claude plugin list
206
+ // --json`, stopped after <delay> ms (0: never), reads its output as it comes, and writes the
207
+ // answer, which holds the entries that install a plugin for the project at <root> alone.
208
+ function filtrerLaListe(racine, delai) {
209
+ const args = ['plugin', 'list'];
210
+ const filtre = filtreDeListe(e => installePourLeProjet([e], e.id, racine));
211
+ const r = { delai: false, stderr: '' };
212
+ const p = spawn('claude', [...args, '--json'], { stdio: ['ignore', 'pipe', 'pipe'] });
213
+ const minuterie =
214
+ delai > 0 &&
215
+ setTimeout(() => {
216
+ r.delai = true;
217
+ p.kill('SIGKILL');
218
+ p.stdout.destroy();
219
+ p.stderr.destroy();
220
+ }, delai);
221
+ p.stdout.setEncoding('utf8').on('data', t => filtre.lire(t));
222
+ p.stderr.setEncoding('utf8').on('data', t => {
223
+ r.stderr = `${r.stderr}${t}`.slice(-2000);
224
+ });
225
+ p.on('error', e => {
226
+ r.code = e.code;
227
+ });
228
+ p.on('close', (status, signal) => {
229
+ clearTimeout(minuterie);
230
+ const liste = filtre.fin();
231
+ let reponse;
232
+ if (r.code === 'ENOENT') {
233
+ reponse = { absent: true };
234
+ } else if (r.delai || r.code || status !== 0) {
235
+ reponse = echecDeLecture(args, { ...r, status, signal }, delai);
236
+ } else {
237
+ reponse = liste ? { liste } : illisible(args);
238
+ }
239
+ process.stdout.write(JSON.stringify(reponse));
240
+ });
241
+ }
242
+
243
+ // The entries of `claude plugin list --json` that install a plugin for the project at `racine`:
244
+ // `{ liste }`, `{ absent }` or `{ erreur, delai }`. The list is the account's, of every project, and
245
+ // `claude` filters none of it: a process apart reads it as it comes and answers the project's
246
+ // entries alone, so no script here holds the whole list.
247
+ function lireGreffons(racine, delai = 0) {
248
+ const r = spawnSync(
249
+ process.execPath,
250
+ [fileURLToPath(import.meta.url), '--lire', racine, String(delai)],
251
+ { encoding: 'utf8', maxBuffer: Infinity }
252
+ );
253
+ try {
254
+ return JSON.parse(r.stdout);
255
+ } catch {
256
+ const cause = r.error?.message || r.stderr?.trim() || `code ${r.status}`;
257
+ return { erreur: `la lecture de la liste des greffons échoue (${cause})` };
258
+ }
259
+ }
260
+
261
+ // The registry where Claude Code records the plugins installed, of the whole account.
262
+ const fichierDuRegistre = () =>
263
+ path.join(
264
+ process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude'),
265
+ 'plugins',
266
+ 'installed_plugins.json'
267
+ );
268
+
269
+ // Removes from the registry the entries of scope local whose `projectPath` `retirer` accepts, and
270
+ // returns how many: `claude plugin uninstall` runs in the project's folder, which is gone here. An
271
+ // id left without entry goes; a registry with nothing to remove, or none, is not written. Throws,
272
+ // the file untouched, on one that does not read or of another version.
273
+ function retirerLesInscriptions(retirer) {
274
+ const f = fichierDuRegistre();
275
+ if (!existsSync(f)) {
276
+ return 0;
277
+ }
278
+ let registre;
279
+ try {
280
+ registre = JSON.parse(readFileSync(f, 'utf8'));
281
+ } catch {
282
+ // unreadable, below
283
+ }
284
+ if (registre?.version !== 2 || typeof registre.plugins !== 'object' || !registre.plugins) {
285
+ throw new Error(
286
+ `le registre des greffons ${f} n'a pas la forme attendue (version 2) : aucune inscription n'est retirée.`
287
+ );
288
+ }
289
+ let retirees = 0;
290
+ for (const [id, entrees] of Object.entries(registre.plugins)) {
291
+ if (!Array.isArray(entrees)) {
292
+ continue;
293
+ }
294
+ const reste = entrees.filter(
295
+ e => !(e?.scope === 'local' && typeof e.projectPath === 'string' && retirer(e.projectPath))
296
+ );
297
+ if (reste.length === entrees.length) {
298
+ continue;
299
+ }
300
+ retirees += entrees.length - reste.length;
301
+ if (reste.length === 0) {
302
+ delete registre.plugins[id];
303
+ } else {
304
+ registre.plugins[id] = reste;
305
+ }
306
+ }
307
+ if (retirees > 0) {
308
+ // Written aside then renamed, onto the file a link names: a reader never sees half of it.
309
+ const cible = realpathSync(f);
310
+ const aCote = `${cible}.${process.pid}.tmp`;
311
+ writeFileSync(aCote, JSON.stringify(registre, null, 2), { mode: statSync(cible).mode });
312
+ renameSync(aCote, cible);
313
+ }
314
+ return retirees;
315
+ }
316
+
317
+ // The path resolved through the links of the part of it that exists, a removed folder's included.
318
+ function reelMemeParti(p) {
319
+ const absolu = path.resolve(p);
320
+ try {
321
+ return realpathSync(absolu);
322
+ } catch {
323
+ const parent = path.dirname(absolu);
324
+ return parent === absolu ? absolu : path.join(reelMemeParti(parent), path.basename(absolu));
325
+ }
112
326
  }
113
327
 
328
+ // True when nothing stands at `p`; a path that does not read (rights, a mount) stands.
329
+ function disparu(p) {
330
+ try {
331
+ statSync(p);
332
+ return false;
333
+ } catch (e) {
334
+ return e.code === 'ENOENT' || e.code === 'ENOTDIR';
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Removes the entries of scope local that name the working copy at `copie`, or a folder in it, and
340
+ * returns how many.
341
+ * @param {string} copie
342
+ */
343
+ export function oublierLaCopie(copie) {
344
+ const cible = reelMemeParti(copie);
345
+ return retirerLesInscriptions(p => {
346
+ const r = reelMemeParti(p);
347
+ return r === cible || r.startsWith(`${cible}${path.sep}`);
348
+ });
349
+ }
350
+
351
+ /** Removes the entries of scope local whose folder is gone, and returns how many. */
352
+ export function purgerLesInscriptions() {
353
+ return retirerLesInscriptions(p => path.isAbsolute(p) && disparu(p));
354
+ }
355
+
356
+ /** The line that says `n` entries removed. */
357
+ export const direLesRetraits = n =>
358
+ `${n} inscription${n > 1 ? 's' : ''} de greffons de portée locale retirée${n > 1 ? 's' : ''}`;
359
+
114
360
  // True when the entries hold the plugin for the project (scope user, or project/local at its root).
115
361
  function installePourLeProjet(entrees, id, racine) {
116
362
  return entrees.some(
@@ -203,7 +449,7 @@ function installer(projet, { declarations = projet, seulement, version }) {
203
449
  return [];
204
450
  }
205
451
  const lignes = [];
206
- const lecturePlugins = lireListe(['plugin', 'list'], undefined);
452
+ const lecturePlugins = lireGreffons(racine);
207
453
  if (lecturePlugins.absent) {
208
454
  return d.plugins.map(
209
455
  id =>
@@ -211,7 +457,7 @@ function installer(projet, { declarations = projet, seulement, version }) {
211
457
  );
212
458
  }
213
459
  if (lecturePlugins.erreur) {
214
- return [`${lecturePlugins.erreur} : aucun greffon n'est installé.`];
460
+ return [`${lecturePlugins.erreur} : rien n'est installé.`];
215
461
  }
216
462
  const lectureMarches = lireListe(['plugin', 'marketplace', 'list'], undefined);
217
463
  if (lectureMarches.erreur) {
@@ -259,7 +505,7 @@ function installer(projet, { declarations = projet, seulement, version }) {
259
505
  // then read again. Returns the line of a mod that stays at another version, with the command that
260
506
  // aligns it (`ecart`); none when the versions agree or compare nothing.
261
507
  function aligner(racine, declares, version) {
262
- const lecture = lireListe(['plugin', 'list'], undefined);
508
+ const lecture = lireGreffons(racine);
263
509
  const avant = lecture.liste ? ecart(lecture.liste, declares, racine, version) : null;
264
510
  if (!avant) {
265
511
  return [];
@@ -267,7 +513,7 @@ function aligner(racine, declares, version) {
267
513
  let reste = avant;
268
514
  if (avant.derriere) {
269
515
  const r = claude(['plugin', 'update', avant.id, '--scope', avant.scope], { cwd: racine });
270
- const relue = r.ok ? lireListe(['plugin', 'list'], undefined) : {};
516
+ const relue = r.ok ? lireGreffons(racine) : {};
271
517
  reste = relue.liste ? ecart(relue.liste, declares, racine, version) : avant;
272
518
  }
273
519
  if (!reste) {
@@ -299,7 +545,7 @@ export function greffonsAbsents(projet) {
299
545
  if (d.plugins.length === 0) {
300
546
  return [];
301
547
  }
302
- const lecture = lireListe(['plugin', 'list'], DELAI_LECTURE_MS);
548
+ const lecture = lireGreffons(racine, DELAI_LECTURE_MS);
303
549
  if (lecture.absent) {
304
550
  return ['claude'];
305
551
  }
@@ -364,11 +610,30 @@ function plusAncienne(a, b) {
364
610
  return false;
365
611
  }
366
612
 
613
+ // The gestures on the registry, `--purger` and `--oublier <copie>`: their line, or their failure.
614
+ function surLeRegistre(geste) {
615
+ try {
616
+ const n = geste();
617
+ if (n > 0) {
618
+ process.stdout.write(`${direLesRetraits(n)}.\n`);
619
+ }
620
+ } catch (e) {
621
+ process.stderr.write(`${e.message}\n`);
622
+ process.exitCode = 1;
623
+ }
624
+ }
625
+
367
626
  if (process.argv[1] && import.meta.url === pathToFileURL(resolu(process.argv[1])).href) {
368
627
  const args = process.argv.slice(2);
369
628
  const absents = args[0] === '--absents';
370
629
  const projet = path.resolve((absents ? args[1] : args[0]) ?? '.');
371
- if (absents) {
630
+ if (args[0] === '--lire') {
631
+ filtrerLaListe(args[1], Number(args[2]));
632
+ } else if (args[0] === '--purger') {
633
+ surLeRegistre(purgerLesInscriptions);
634
+ } else if (args[0] === '--oublier' && args[1]) {
635
+ surLeRegistre(() => oublierLaCopie(args[1]));
636
+ } else if (absents) {
372
637
  const lignes = greffonsAbsents(projet);
373
638
  if (lignes.length > 0) {
374
639
  process.stdout.write(`${lignes.join('\n')}\n`);
@@ -42,6 +42,7 @@ import path from 'node:path';
42
42
  import { fileURLToPath, pathToFileURL } from 'node:url';
43
43
  import { RESULTATS } from '../../resultats.mjs';
44
44
  import {
45
+ A_REPASSER,
45
46
  AttenteDeLaMachine,
46
47
  avecLaPasse,
47
48
  cheminsDeLaTache,
@@ -80,7 +81,6 @@ const OUTIL = 'turbo';
80
81
  const RACINE = '//';
81
82
  /** The constructions of CMake, one directory per package, at the root. */
82
83
  export const CONSTRUCTION = '.build-cmake';
83
- const A_REPASSER = 75;
84
84
 
85
85
  /** The guards of the module: each its name and its script beside this one. */
86
86
  export const GARDES = [
@@ -151,6 +151,7 @@ import path from 'node:path';
151
151
  import { fileURLToPath, pathToFileURL } from 'node:url';
152
152
  import { RESULTATS } from '../../resultats.mjs';
153
153
  import {
154
+ A_REPASSER,
154
155
  AttenteDeLaMachine,
155
156
  attendreLeRepos,
156
157
  surUnePart,
@@ -200,7 +201,6 @@ export const NOMS = [
200
201
  ];
201
202
  // The task runner of the graph of the packages.
202
203
  const OUTIL = 'turbo';
203
- const A_REPASSER = 75;
204
204
  // The exit code of nextest when its filter keeps no test (NO_TESTS_RUN).
205
205
  const AUCUN_TEST = 4;
206
206
  // What the night out of the poste says of a filter that keeps no test: green.
@@ -19,8 +19,8 @@
19
19
  // files under `src/`; a crate of the product it uses is not read: what it starts is its own.
20
20
  // - large (`grand`): it starts a process (`std::process`, `tokio::process`, `assert_cmd`, `duct`,
21
21
  // `xshell`), mounts a trial repository (git's `init`, `clone` or `worktree add`, as an
22
- // argument or a command, or git2's `Repository::init` and `Repository::clone`) and starts
23
- // there something else than git (`Command::new` of a binary of the product, `cargo_bin`,
22
+ // argument of a call of git or in a command, or git2's `Repository::init` and
23
+ // `Repository::clone`) and starts there something else than git (`Command::new` of a binary of the product, `cargo_bin`,
24
24
  // `cmd!` of another program);
25
25
  // - medium (`moyen`): it starts a process;
26
26
  // - small (`petit`): it starts none.
@@ -46,10 +46,30 @@ export const GRAND_DE_JOUR = 'grand-de-jour';
46
46
 
47
47
  // The use of a way to start a process.
48
48
  const PROCESSUS = /\b(?:std|tokio|async_std)::process\b|\b(?:assert_cmd|duct|xshell)\b/;
49
- // A trial repository mounted: git's `init`, `clone` or `worktree add`, as an argument or a command;
50
- // git2's `Repository::init` or `Repository::clone`.
49
+ // A trial repository mounted without an argument of a call: git's `init`, `clone` or `worktree add`
50
+ // in a command, or git2's `Repository::init` or `Repository::clone`.
51
51
  const DEPOT_D_ESSAI =
52
- /"(?:init|clone)"|\bgit\s+(?:-C\s+\S+\s+)?(?:init|clone)\b|"worktree"\s*,\s*"add"|\bworktree\s+add\b|\bRepository::(?:init|clone)\w*\s*\(/;
52
+ /\bgit\s+(?:-[Cc]\s+\S+\s+)*(?:init|clone|worktree\s+add)\b|\bRepository::(?:init|clone)\w*\s*\(/;
53
+ // The same three as the arguments of a call of git (`appelsDeGit`), in one list or one by one.
54
+ const ARGUMENT_DE_DEPOT = /"(?:init|clone)"|"worktree"(?:\s*,|\s*\)\s*\.arg\s*\()\s*"add"/;
55
+ // A comment, a string (raw or not) or a character, whose brackets and semicolons are no code.
56
+ const HORS_DU_CODE =
57
+ /\/\/[^\n]*|\/\*[\s\S]*?\*\/|\br(#*)"[\s\S]*?"\1|"(?:\\[\s\S]|[^"\\])*"|'(?:\\[^']+|[^\\'\n])'/g;
58
+ // The command of git, `Command::new("git")`.
59
+ const COMMANDE_GIT = /\bCommand::new\s*\(\s*r?#*"git"/g;
60
+ // The name a statement binds to the expression that follows it, `let mut c: Command = `.
61
+ const NOM_LIE =
62
+ /\blet\s+(?:mut\s+)?([A-Za-z_]\w*)\s*(?::\s*[\w:<>]+\s*)?=\s*(?:[A-Za-z_]\w*(?:::|\.))*$/;
63
+ // The next method of a chain, up to its parenthesis.
64
+ const METHODE = /\s*(?:\?|\.\s*await\b)?\s*\.\s*([A-Za-z_]\w*)\s*(?:::\s*<[^()]*>\s*)?\(/y;
65
+ // The return type of a function that gives a command.
66
+ const REND_UNE_COMMANDE = /->[^{]*\bCommand\b/;
67
+ // A call of git by its parentheses: a function or a macro named after git (`git(`, `run_git(`), or
68
+ // whose program is git (`cmd!("git", …)`, `cmd("git", …)`).
69
+ const APPEL_DE_GIT =
70
+ /\b(?:[A-Za-z0-9]+_)*git(?:_[A-Za-z0-9]+)*!?\s*\(|\b\w+!?\s*\(\s*(?=(?:[A-Za-z_]\w*\s*,\s*)?r?#*"git"\s*,)/g;
71
+ // A function and its parameters, up to the brace of its body.
72
+ const FONCTION = /\bfn\s+([A-Za-z_]\w*)([^{;]*(?:;[^{;\]]*\][^{;]*)*)\{/g;
53
73
  // A call that starts a process, its program captured: `Command::new(<programme>`, assert_cmd's
54
74
  // `cargo_bin(<binaire>`, the macro `cmd!` of duct (`cmd!("git", …)`) and of xshell (`cmd!(sh,
55
75
  // "git …")`).
@@ -94,6 +114,93 @@ function fichierDuModule(f, nom, chemin, lire) {
94
114
  return ordre.find(c => lire(c) !== null) ?? null;
95
115
  }
96
116
 
117
+ // Where the code open at <debut> in <code> (its comments and strings blanked) ends: the bracket
118
+ // that closes it (`groupe`), the `;` that ends the statement (`instruction`), or the bracket that
119
+ // closes the block around (`bloc`).
120
+ function finDe(code, debut, portee = 'groupe') {
121
+ let ouverts = 0;
122
+ for (let i = debut; i < code.length; i++) {
123
+ if ('([{'.includes(code[i])) {
124
+ ouverts++;
125
+ } else if (')]}'.includes(code[i])) {
126
+ ouverts--;
127
+ if (ouverts < 0 || (ouverts === 0 && portee === 'groupe')) {
128
+ return i;
129
+ }
130
+ } else if (portee === 'instruction' && ouverts === 0 && code[i] === ';') {
131
+ return i;
132
+ }
133
+ }
134
+ return code.length;
135
+ }
136
+
137
+ // The `arg` and `args` of the method chain that follows <fin> in <texte> (<code>, its comments and
138
+ // strings blanked), each `.arg(…)`; empty for none.
139
+ function argumentsEnChaine(texte, code, fin) {
140
+ let args = '';
141
+ for (let i = fin; ;) {
142
+ METHODE.lastIndex = i;
143
+ const m = METHODE.exec(code);
144
+ if (!m) {
145
+ return args;
146
+ }
147
+ const ouvre = i + m[0].length - 1;
148
+ i = finDe(code, ouvre) + 1;
149
+ if (m[1] === 'arg' || m[1] === 'args') {
150
+ args += `.${m[1]}${texte.slice(ouvre, i)}`;
151
+ }
152
+ }
153
+ }
154
+
155
+ // The `arg` and `args` of the name <nom>, from <debut> to the end of its block or to the statement
156
+ // that binds it again, put end to end.
157
+ function argumentsDuNom(texte, code, nom, debut) {
158
+ const bloc = code.slice(debut, finDe(code, debut, 'bloc'));
159
+ const autre = bloc.search(new RegExp(`\\blet\\s+(?:mut\\s+)?${nom}\\b`));
160
+ const portee = autre < 0 ? bloc : bloc.slice(0, autre);
161
+ return [...portee.matchAll(new RegExp(`(?<![\\w.])${nom}\\b(?=\\s*\\.)`, 'g'))]
162
+ .map(a => argumentsEnChaine(texte, code, debut + a.index + nom.length))
163
+ .join('');
164
+ }
165
+
166
+ // The text of each call of git in <texte>: the parentheses of a call named after git or running it,
167
+ // and those of a call of a function of the text that passes its arguments to a command of git; and
168
+ // the `arg` and `args` of a command of git (`Command::new("git")`, a call named after git, or a
169
+ // call of a function of the text that returns such a command), chained on it or on the name it is
170
+ // bound to.
171
+ function appelsDeGit(texte) {
172
+ const code = texte.replace(HORS_DU_CODE, s => s.replace(/[^\n]/g, s.startsWith('/') ? ' ' : '_'));
173
+ const appels = [];
174
+ // The calls <motif> finds: their parentheses when <passe>, and the arguments of the command
175
+ // they give.
176
+ const suivre = (motif, passe) => {
177
+ for (const m of texte.matchAll(motif)) {
178
+ const ouvre = m.index + m[0].indexOf('(');
179
+ const fin = finDe(code, ouvre);
180
+ if (passe) {
181
+ appels.push(texte.slice(ouvre, fin));
182
+ }
183
+ appels.push(argumentsEnChaine(texte, code, fin + 1));
184
+ const lie = NOM_LIE.exec(code.slice(Math.max(0, m.index - 200), m.index));
185
+ if (lie) {
186
+ const suite = finDe(code, m.index, 'instruction') + 1;
187
+ appels.push(argumentsDuNom(texte, code, lie[1], suite));
188
+ }
189
+ }
190
+ };
191
+ suivre(COMMANDE_GIT, false);
192
+ suivre(APPEL_DE_GIT, true);
193
+ for (const m of code.matchAll(FONCTION)) {
194
+ const corps = texte.slice(m.index, finDe(code, m.index + m[0].length - 1));
195
+ const passe = /\b(?:str|String|OsStr)\b/.test(m[2]);
196
+ const rend = REND_UNE_COMMANDE.test(m[2]);
197
+ if ((passe || rend) && corps.search(COMMANDE_GIT) >= 0) {
198
+ suivre(new RegExp(`\\b${m[1]}\\s*\\(`, 'g'), passe);
199
+ }
200
+ }
201
+ return appels;
202
+ }
203
+
97
204
  /**
98
205
  * The size of the test file <fichier> (absolute), read by <lire> (a path → its text, null when it
99
206
  * does not read), the crates of the shared test material <matieres> (`[{ nom, fichiers }]`, `nom`
@@ -129,7 +236,9 @@ export function classer(fichier, lire = lireLeDisque, matieres = []) {
129
236
  const tout = textes.join('\n');
130
237
  const processus = PROCESSUS.test(tout);
131
238
  const autreQueGit = [...tout.matchAll(APPEL)].some(m => !GIT.test((m[1] ?? m[2] ?? m[3]).trim()));
132
- if (processus && autreQueGit && DEPOT_D_ESSAI.test(tout)) {
239
+ const depot = () =>
240
+ DEPOT_D_ESSAI.test(tout) || appelsDeGit(tout).some(a => ARGUMENT_DE_DEPOT.test(a));
241
+ if (processus && autreQueGit && depot()) {
133
242
  return 'grand';
134
243
  }
135
244
  return processus ? 'moyen' : 'petit';
@@ -91,6 +91,7 @@ import path from 'node:path';
91
91
  import { fileURLToPath, pathToFileURL } from 'node:url';
92
92
  import { RESULTATS } from '../../resultats.mjs';
93
93
  import {
94
+ A_REPASSER,
94
95
  AttenteDeLaMachine,
95
96
  surUnePart,
96
97
  avecLaPasse,
@@ -133,7 +134,6 @@ export const NOMS = [
133
134
  ];
134
135
  // The task runner of the graph of the packages.
135
136
  const OUTIL = 'turbo';
136
- const A_REPASSER = 75;
137
137
  const RACINE = '//';
138
138
  /** The night tests, which the day leaves out. */
139
139
  export const DE_NUIT = '*_nuit_test.py';
@@ -7,7 +7,9 @@
7
7
  // project's debt (`grillhouse-dette.json`, see `dette.mjs`) passes, keyed by its file and knip's
8
8
  // kind of issue (`files`, `exports`, `types`, `dependencies`…).
9
9
  // - A knip that measured nothing (it failed, or its output is not its report) refuses too: an
10
- // empty green is the worst green.
10
+ // empty green is the worst green. So does a partial measure, before the debt is judged: a run
11
+ // that writes « ERROR: Error loading <file> » on stderr, its report readable or not, or that
12
+ // ends on another exit code than 0 and 1.
11
13
  // - A finding that is not dead (a format's full table, a public name a consumer outside the
12
14
  // repository reads) leaves by its name in `knip.json`, with its reason, never by a wide pattern.
13
15
  // - The packages listed out of the frame (`docs/agents/hors-cadre.txt`, read by `horsCadre` of
@@ -43,6 +45,7 @@ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'no
43
45
  import { tmpdir } from 'node:os';
44
46
  import path from 'node:path';
45
47
  import { pathToFileURL } from 'node:url';
48
+ import { stripVTControlCharacters } from 'node:util';
46
49
  import { fournisseursDuPaquet } from '../../services-du-noyau.mjs';
47
50
  import { horsCadre, paquets as paquetsDuDepot } from '../../paquets.mjs';
48
51
  import { MODE, trancher } from '../../dette.mjs';
@@ -348,9 +351,35 @@ function knip(racine, config, include) {
348
351
  }
349
352
  }
350
353
 
354
+ // Why the runs of knip <passes> (spawn results) measured only a part of the repository, as the
355
+ // lines of the refusal; null when every run is complete. First every « ERROR: Error loading » line
356
+ // any of them writes on stderr, colour sequences taken off: knip then reports without what that
357
+ // configuration declares. Else the first run that ends on another exit code than 0 (nothing found)
358
+ // and 1 (findings), or without one, with what it says.
359
+ function mesureIncomplete(passes) {
360
+ const nonCharges = new Set(
361
+ passes
362
+ .flatMap(p => stripVTControlCharacters(p.stderr ?? '').split(/\r?\n/))
363
+ .filter(l => l.includes('ERROR: Error loading '))
364
+ );
365
+ if (nonCharges.size) {
366
+ return [
367
+ "⛔ CODE MORT — knip n'a pas chargé une configuration : sa mesure est incomplète, et la dette ne l'absorbe pas. La configuration que knip nomme se corrige pour qu'il la charge, ou son greffon se règle dans knip.json avec sa raison.",
368
+ ...[...nonCharges].map(l => ` ${l}`),
369
+ ];
370
+ }
371
+ const fautive = passes.find(p => p.status !== 0 && p.status !== 1);
372
+ if (!fautive) {
373
+ return null;
374
+ }
375
+ const fin = fautive.status ?? fautive.signal ?? fautive.error?.code;
376
+ const dit = fautive.stderr || fautive.error?.message || fautive.stdout || '';
377
+ return [`⛔ CODE MORT — knip n'a pas fini sa mesure (fin : ${fin}) :\n${dit}`];
378
+ }
379
+
351
380
  // The report of the dead-code check at <racine>: `lignes`, what the command writes on stderr (each
352
- // refusal and the debt's lines), and `code`, its exit code (1 on a refusal or a knip it cannot
353
- // read). The functional core of the command: it runs knip and git and reads the project's debt, and
381
+ // refusal and the debt's lines), and `code`, its exit code (1 on a refusal, a knip it cannot read
382
+ // or an incomplete measure, which the debt is then never judged on). The functional core of the command: it runs knip and git and reads the project's debt, and
354
383
  // writes nothing to the standard streams; the command below is its shell. The refusals reach SARIF
355
384
  // through `trancher` under the results directory <env> names (scripts/resultats.mjs); without it none
356
385
  // is written, and the debt's mode is <env>'s `GRILLHOUSE_DETTE`.
@@ -394,6 +423,10 @@ export async function codeMort(racine, env = process.env) {
394
423
  DEPS.join(',')
395
424
  )
396
425
  : null;
426
+ const incomplete = mesureIncomplete(second ? [premier, second] : [premier]);
427
+ if (incomplete) {
428
+ return { lignes: [...lignes, ...incomplete], code: 1 };
429
+ }
397
430
  const c2 = second ? constats(second.stdout ?? '', DEPS) : null;
398
431
  let c = null;
399
432
  if (c1 && (c2 || !second)) {