@roomi-fields/grillhouse 0.25.5 → 0.26.0

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 (44) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/agents/testwriter.md +1 -1
  3. package/bin/grillhouse.mjs +20 -3
  4. package/cadre/templates/cargo/package.json +3 -0
  5. package/cadre/templates/projet/.gitattributes +1 -0
  6. package/cadre/templates/projet/CLAUDE.md +6 -0
  7. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  8. package/charte.md +10 -1
  9. package/docs/ARCHITECTURE.md +91 -26
  10. package/docs/INTERFACE.md +16 -4
  11. package/hooks/register.tsx +57 -16
  12. package/package.json +9 -3
  13. package/scripts/circuit.mjs +121 -19
  14. package/scripts/copies-finies.mjs +167 -28
  15. package/scripts/crochets.mjs +9 -3
  16. package/scripts/enveloppe/enveloppe.mjs +59 -17
  17. package/scripts/enveloppe/lancer.sh +15 -22
  18. package/scripts/enveloppe/travail-de-la-copie.mjs +188 -0
  19. package/scripts/etapes.mjs +1 -1
  20. package/scripts/fusion-du-changelog.mjs +120 -0
  21. package/scripts/grillhouse-maj.mjs +19 -0
  22. package/scripts/integration/file.mjs +196 -104
  23. package/scripts/jointure.d.ts +22 -1
  24. package/scripts/langages/cargo/binaires.json +2 -1
  25. package/scripts/langages/cargo/clippy.mjs +10 -2
  26. package/scripts/langages/cargo/commandes.mjs +19 -4
  27. package/scripts/langages/cargo/composants.mjs +229 -8
  28. package/scripts/langages/cargo/index.mjs +17 -8
  29. package/scripts/langages/cargo/sccache.mjs +143 -0
  30. package/scripts/langages/cargo/verdict.mjs +50 -10
  31. package/scripts/langages/typescript/index.mjs +4 -2
  32. package/scripts/langages/typescript/regle-des-tests.mjs +37 -0
  33. package/scripts/nuit.sh +15 -1
  34. package/scripts/outils-cles.mjs +188 -0
  35. package/scripts/resultats.mjs +22 -6
  36. package/scripts/sous-commandes.mjs +16 -0
  37. package/scripts/verrou-de-machine.mjs +14 -13
  38. package/scripts/verrous/verrou.mjs +50 -14
  39. package/skills/developpeur/SKILL.md +4 -0
  40. package/skills/explorateur/SKILL.md +3 -1
  41. package/skills/pitmaster/SKILL.md +6 -2
  42. package/skills/pitmaster/references/consigne-agent.md +3 -3
  43. package/skills/relecteur/SKILL.md +6 -2
  44. package/skills/testwriter/SKILL.md +23 -6
@@ -388,7 +388,11 @@
388
388
  // handover the circuit does not read, three RENDU, then the stop); the rest of the lot it does not read again (its skill, « La relecture
389
389
  // bornée »). A blocking finding without a valid agent, or one that puts its criterion in
390
390
  // question (`critere_en_cause`), stops at « relecture-arret »; so does the third RENDU since the
391
- // ticket's last ACCEPTÉ.
391
+ // ticket's last ACCEPTÉ, and a RENDU whose finding goes to the testwriter when the plan skips
392
+ // him (`sansTests`), at that verdict, as a CI fails fast on a step it cannot run
393
+ // (`arretDuTestwriterSaute`; OSC Bridge SH-13y.1: three RENDU « Agent : testwriter » on a
394
+ // package whose tests no command of the frame plays, the developpeur relaunched on an empty
395
+ // diff each time); its question, declare the tests of the package or settle the finding.
392
396
  // - ACCEPTÉ: the integration, once the whole final pass has played on the lot accepted (its tree
393
397
  // is `verifie`); else that pass first, once, its red going to the developpeur and the lot then
394
398
  // to the reviewer again. The circuit builds the lot from the copy: the files the copy changes
@@ -412,6 +416,9 @@
412
416
  // sorts the discoveries (below), then ends at « integre », exit 0 (the queue's last word at the
413
417
  // ticket named with it, a CI it could not read); reopened (out of the queue, or a red CI), it stops at « integration », the queue's
414
418
  // last word as its reason; still in the queue, it stops at « a-repasser », the queue's reason.
419
+ // The branch out of the queue and its ticket open, as `--reprendre` finds it after a red CI, the
420
+ // queue reads the CI of the ticket's commit on main again (`file.mjs --ci <ticket>`): a rerun
421
+ // green (`gh run rerun <id> --failed`) closes the ticket, as an entry does.
415
422
  // - Then the tri of the discoveries (step 5.3, `trier`), as Chromium and Mozilla give each new
416
423
  // report a verdict before it is filed: each discovery a sheet filed is kept with the circuit's
417
424
  // results (`decouverte`: its id, its subject); without one, no session. Else one session of the
@@ -513,7 +520,8 @@
513
520
  // ticket in one short comment, `Circuit · bilan : …`, compared with the bilan before it in the
514
521
  // project.
515
522
  // - Exit codes: 0 at « integre »; 2 a malformed call; a stop, by its name (ARRETS):
516
- // 10 lancement (lancer.sh stopped before the session), 11 bloqué (a motionless transcript),
523
+ // 10 lancement (lancer.sh stopped before the session, or the tools of the project,
524
+ // `grillhouse.outils`, refused at the launch or a resumption, before any session), 11 bloqué (a motionless transcript),
517
525
  // 12 sans-fiche (twice no sheet that conforms), 13 preuve (the third proof fails), 14 controles
518
526
  // (the third developpeur of the checks or of the final pass leaves a red check, a red of the
519
527
  // final pass out of the plan or that no package of the plan holds, or reds to settle),
@@ -522,8 +530,8 @@
522
530
  // second developpeur session that `--depuis developpeur` launched on the lot the integration
523
531
  // refused and that changes nothing; or
524
532
  // the developpeur's same sending to the testwriter twice in a row, on the same red output of the
525
- // checks, no green checks between them), 16 relecture-arret (a finding without a valid agent, one on a criterion, the third
526
- // RENDU), 17 integration (the integration script refuses the lot, or the queue reopens the
533
+ // checks, no green checks between them), 16 relecture-arret (a finding without a valid agent, one to the testwriter the plan skips,
534
+ // one on a criterion, the third RENDU), 17 integration (the integration script refuses the lot, or the queue reopens the
527
535
  // ticket), 19 hors-portee (a testwriter or developpeur whose sheet says BLOQUÉ, without a
528
536
  // sending to the testwriter, or a developpeur's FAIT with criteria out of the plan), 20 besoin (a testwriter or developpeur whose sheet says BESOIN, a
529
537
  // reviewer whose sheet carries a `question`, or a ticket labelled `arbitrage` whose arbitrage
@@ -557,6 +565,7 @@ import { pathToFileURL } from 'node:url';
557
565
  import { stripVTControlCharacters } from 'node:util';
558
566
  import { ecrireLeBilan } from './bilan.mjs';
559
567
  import { DEPUIS_LE_VERT } from './dernier-vert.mjs';
568
+ import { avecLesOutils, outilsDe } from './outils-cles.mjs';
560
569
  import { commandesPermises, optionsDuRole } from './droits.mjs';
561
570
  import {
562
571
  ecrireLaListe,
@@ -585,6 +594,7 @@ import { FICHIER as DETTE } from './dette.mjs';
585
594
  import {
586
595
  A_ELAGUER,
587
596
  bloquantsDeLaFiche,
597
+ cleDuConstat,
588
598
  conformiteDuLot,
589
599
  conformiteDuTri,
590
600
  lireFiche,
@@ -612,6 +622,7 @@ import { A_REPASSER } from './mesure/pression.mjs';
612
622
  import { departDe, leMemeVivant, ouvrirBase, vivant } from './mesure/base-de-passe.mjs';
613
623
  import { GREFFON } from './cadre.mjs';
614
624
  import { executerEnDemon } from './demon.mjs';
625
+ import { retirerLesCopiesDuDepot } from './copies-finies.mjs';
615
626
 
616
627
  // The time a session's transcripts may stand still before the circuit stops it.
617
628
  export const IMMOBILE_MS = 20 * 60 * 1000;
@@ -1430,10 +1441,10 @@ export const auLancement = (contexte, constats) =>
1430
1441
  });
1431
1442
 
1432
1443
  // The findings <constats>, each finding of the developpeur that his sheet <fiche> answers (by its
1433
- // title) with its answer `{ etat, raison, piece }`, as a thread of a review keeps the author's
1434
- // reply under its comment.
1444
+ // title, numbered or not: `cleDuConstat`) with its answer `{ etat, raison, piece }`, as a thread
1445
+ // of a review keeps the author's reply under its comment.
1435
1446
  function avecLesReponses(constats, fiche) {
1436
- const parTitre = new Map((fiche.reponses ?? []).map(r => [r.titre, r]));
1447
+ const parTitre = new Map((fiche.reponses ?? []).map(r => [cleDuConstat(r.titre), r]));
1437
1448
  return (constats ?? []).map(c => {
1438
1449
  const r = c.role === 'developpeur' ? parTitre.get(c.titre) : undefined;
1439
1450
  if (!r) return c;
@@ -2037,11 +2048,40 @@ function regenerer(ctx, noms, notes = [], avantLaPasse = false, refusAuLot = fal
2037
2048
  };
2038
2049
  }
2039
2050
 
2051
+ // The environment of a pass of the circuit (the proof, the checks, the final pass, a command of a
2052
+ // reference): <base>, the launcher's under the lock of the machine, with the tools of the project
2053
+ // (`ctx.outils`, `grillhouse.outils`, read at the launch) whatever <base> holds, then <env>.
2054
+ export const environnementDeLaPasse = (ctx, base, env = {}) => ({
2055
+ ...avecLesOutils(ctx.outils ?? {}, base),
2056
+ ...env,
2057
+ });
2058
+
2059
+ // The tools of the project whose main tree is <racine>, read at the launch of a run:
2060
+ // `{ outils }`, or `{ arret }`, the stop « lancement » that goes up to the supervisor before any
2061
+ // session (its code, name, report, piece and question), the faults of the key named.
2062
+ export function outilsAuLancement(racine) {
2063
+ try {
2064
+ return { outils: outilsDe(racine) };
2065
+ } catch (err) {
2066
+ const rapport = `La clé grillhouse.outils du package.json est refusée :\n${err.message}`;
2067
+ return {
2068
+ arret: {
2069
+ code: ARRETS.lancement,
2070
+ nom: 'lancement',
2071
+ rapport,
2072
+ piece: `$ npm pkg get grillhouse.outils\n${rapport}`,
2073
+ question: `${rapport}\nLa clé se corrige au package.json du projet, puis \`--reprendre\`.`,
2074
+ },
2075
+ };
2076
+ }
2077
+ }
2078
+
2040
2079
  // One command of a reference, run by the shell at the root of the copy, out of the envelope,
2041
2080
  // under the lock of the machine, its output added to the log: `{ code, panne, sortie }`, its exit
2042
2081
  // code, whether it failed for real, whatever it judges (the command not found or not executable,
2043
2082
  // 126, 127, as the shell says it; killed by a signal, the shell's 128 + its number; or the lock of
2044
- // the machine not taken), and what it wrote to the log.
2083
+ // the machine not taken), and what it wrote to the log. It runs in the environment of a pass
2084
+ // (`environnementDeLaPasse`).
2045
2085
  function commandeDeReference(ctx, commande) {
2046
2086
  entete(ctx, 'references');
2047
2087
  appendFileSync(ctx.journal, `$ ${commande}\n`);
@@ -2050,7 +2090,12 @@ function commandeDeReference(ctx, commande) {
2050
2090
  const fd = openSync(ctx.journal, 'a');
2051
2091
  try {
2052
2092
  const r = avecLaMachine(
2053
- env => spawnSync('sh', ['-c', commande], { cwd: ctx.copie, stdio: ['ignore', fd, fd], env }),
2093
+ env =>
2094
+ spawnSync('sh', ['-c', commande], {
2095
+ cwd: ctx.copie,
2096
+ stdio: ['ignore', fd, fd],
2097
+ env: environnementDeLaPasse(ctx, env),
2098
+ }),
2054
2099
  { racine: ctx.copie, dire: l => appendFileSync(ctx.journal, `${l}\n`) }
2055
2100
  );
2056
2101
  const code = r.status ?? 1;
@@ -2172,13 +2217,35 @@ export function constatsOuverts(ctx, fiche, texte) {
2172
2217
  }
2173
2218
  return { titre: c.titre, regle: c.regle, role: c.role, corps: c.corps, piece: c.piece };
2174
2219
  });
2175
- const leves = new Set((fiche.suivi ?? []).filter(s => s.etat === 'levé').map(s => s.titre));
2220
+ const leves = new Set(
2221
+ (fiche.suivi ?? []).filter(s => s.etat === 'levé').map(s => cleDuConstat(s.titre))
2222
+ );
2176
2223
  const restes = (ctx.constats ?? [])
2177
2224
  .filter(c => !leves.has(c.titre) && !neufs.some(n => n.titre === c.titre))
2178
2225
  .map(c => Object.fromEntries(Object.entries(c).filter(([k]) => k !== 'reponse')));
2179
2226
  return [...restes, ...neufs];
2180
2227
  }
2181
2228
 
2229
+ // The stop for the findings open in <ctx> that go to the testwriter when the plan skips him
2230
+ // (`sansTests`), or null: no new pass treats them, as a CI fails fast on a step it cannot run
2231
+ // (grillhouse-26x). An Arret `relecture-arret` whose report names each finding, the role skipped
2232
+ // and why, then the verdict <texte>; its piece, the findings' pieces; its question, declare the
2233
+ // tests of the package or settle the finding.
2234
+ export function arretDuTestwriterSaute(ctx, texte) {
2235
+ const auTestwriter = ouverts(ctx, 'testwriter');
2236
+ if (!auTestwriter.length || !sansTests(ctx)) return null;
2237
+ const titres = auTestwriter.map(c => `« ${c.titre} »`).join(', ');
2238
+ const plan = ctx.paquets.join(', ');
2239
+ return new Arret(
2240
+ 'relecture-arret',
2241
+ `Le relecteur adresse au testwriter ${titres}, quand le plan saute le testwriter : aucun paquet du plan ne joue de tests (${plan}).\n\nLe verdict :\n\n${texte}`,
2242
+ {
2243
+ piece: auTestwriter.map(c => c.piece ?? c.titre).join('\n'),
2244
+ question: `Le constat ${titres} va au testwriter, que le plan (${plan}) saute : déclarer les tests du paquet au cadre, puis \`--reprendre\`, ou trancher le constat (\`--depuis developpeur --contexte\`, ou \`--arreter\`).`,
2245
+ }
2246
+ );
2247
+ }
2248
+
2182
2249
  // The integration of the lot: its two patches, its message and the references that write files in
2183
2250
  // full (`--references`, from `lesReferences`, the one list), written from the copy, then
2184
2251
  // scripts/integration/integrer.mjs from the main tree, its output added to the log. A run « à
@@ -2243,18 +2310,35 @@ function integrer(ctx) {
2243
2310
  return r;
2244
2311
  }
2245
2312
 
2313
+ // The arguments of the queue at 5.2 for the ticket <ticket>, whether its branch is in the queue
2314
+ // (<enFile>) and its status in Beads (<statut>): none, the queue as it is, while the branch waits
2315
+ // in it or once the ticket is closed; `--ci <ticket>` for a branch out of the queue and a ticket
2316
+ // open, a red CI reopened it, which the queue reads again (`relireCI` of
2317
+ // scripts/integration/file.mjs), as a merge queue judges the last attempt of the checks.
2318
+ export const argumentsDeLaFile = ({ ticket, enFile, statut }) =>
2319
+ enFile || statut === 'closed' ? [] : ['--ci', ticket];
2320
+
2246
2321
  // The queue (scripts/integration/file.mjs), launched from the main tree and waited for, its output
2247
2322
  // added to the log; then the state it leaves to the ticket: `{ etat, raison }`, `etat` ferme (the
2248
2323
  // ticket closed, its branch on main and its CI read), en-file (the branch still in the queue, the
2249
2324
  // queue's reason) or rouvert (out of the queue, or a red CI, the queue's last comment). A queue
2250
- // already running exits 0 at once: it takes the branch, and the state is read at its end too.
2325
+ // already running exits 0 at once: it takes the branch, and the state is read at its end too. A
2326
+ // branch out of the queue with its ticket open (a red CI reopened it, then `--reprendre`) runs the
2327
+ // queue's reading of the CI again instead (`argumentsDeLaFile`).
2251
2328
  function file(ctx) {
2252
2329
  const motsDeLaFile = () => passations(ctx).filter(c => c.author === AUTEUR_DE_LA_FILE);
2253
2330
  const avant = motsDeLaFile().length;
2331
+ const branche = `agent/${ctx.ticket}`;
2332
+ const avantLaFile = ctx.bd('show', ctx.ticket, '--json');
2333
+ const args = argumentsDeLaFile({
2334
+ ticket: ctx.ticket,
2335
+ enFile: lireEntrees(ctx.racine).some(e => e.branche === branche),
2336
+ statut: avantLaFile.status === 0 ? (JSON.parse(avantLaFile.stdout)[0]?.status ?? null) : null,
2337
+ });
2254
2338
  entete(ctx, 'file');
2255
- appendFileSync(ctx.journal, `$ node ${FILE}\n`);
2339
+ appendFileSync(ctx.journal, `$ node ${[FILE, ...args].join(' ')}\n`);
2256
2340
  const x = avecAvancement(ctx, null, avancement =>
2257
- spawnSync(process.execPath, [FILE], {
2341
+ spawnSync(process.execPath, [FILE, ...args], {
2258
2342
  cwd: ctx.racine,
2259
2343
  encoding: 'utf8',
2260
2344
  maxBuffer: 256 * 1024 * 1024,
@@ -2262,7 +2346,6 @@ function file(ctx) {
2262
2346
  })
2263
2347
  );
2264
2348
  appendFileSync(ctx.journal, `${x.stdout ?? ''}${x.stderr ?? ''}`);
2265
- const branche = `agent/${ctx.ticket}`;
2266
2349
  // Another queue that runs takes the branch: the circuit waits for its end.
2267
2350
  while (lireEntrees(ctx.racine).some(e => e.branche === branche) && fileEnCours(ctx)) {
2268
2351
  attendreUnPeu(5_000);
@@ -2534,7 +2617,8 @@ function paquetDe(liste, fichier) {
2534
2617
  // (scripts/verrou-de-machine.mjs), its wait written to the log, and passes it to the
2535
2618
  // `npm run verifier` it runs. A wait that stops (its bound, 75; a lock held by an ancestor, 1) is
2536
2619
  // the command's code, its message in the log. Once it holds the lock, the pass plays under a
2537
- // progress directory of its own (`avancement`), of the kind `genreDeLaPasse` names.
2620
+ // progress directory of its own (`avancement`), of the kind `genreDeLaPasse` names. It plays in
2621
+ // the environment of a pass (`environnementDeLaPasse`).
2538
2622
  function npm(ctx, etape, args, env = {}) {
2539
2623
  entete(ctx, etape);
2540
2624
  const dossier = mkdtempSync(path.join(ctx.base.dossier, 'resultats-'));
@@ -2548,13 +2632,12 @@ function npm(ctx, etape, args, env = {}) {
2548
2632
  spawnSync('npm', args, {
2549
2633
  cwd: ctx.copie,
2550
2634
  stdio: ['ignore', fd, fd],
2551
- env: {
2552
- ...envMachine,
2635
+ env: environnementDeLaPasse(ctx, envMachine, {
2553
2636
  ...env,
2554
2637
  [RESULTATS]: dossier,
2555
2638
  [AVANCEMENT]: avancement,
2556
2639
  ...(args[0] === 'test' ? { [DEPUIS_LE_VERT]: '1' } : {}),
2557
- },
2640
+ }),
2558
2641
  })
2559
2642
  ),
2560
2643
  { racine: ctx.copie, dire: l => appendFileSync(ctx.journal, `${l}\n`) }
@@ -3659,6 +3742,8 @@ async function derouler(ctx, debut) {
3659
3742
  );
3660
3743
  }
3661
3744
  ctx.constats = constatsOuverts(ctx, v.fiche, v.texte);
3745
+ const saute = arretDuTestwriterSaute(ctx, v.texte);
3746
+ if (saute) throw saute;
3662
3747
  const auTestwriter = ouverts(ctx, 'testwriter').length > 0;
3663
3748
  etape = auTestwriter ? TESTS : CODE;
3664
3749
  tentative = 1;
@@ -3865,7 +3950,10 @@ function depart(ctx, e) {
3865
3950
  // (`montee`: its code, its stop and the supervisor's session that ran it, `superviseur`, when
3866
3951
  // Claude Code names it), from which the bilan measures the wait to the run that answers it, the
3867
3952
  // owner's when he writes in that session meanwhile, then the ticket's bilan at the ticket
3868
- // (scripts/bilan.mjs); a bilan it cannot write leaves the code as it is.
3953
+ // (scripts/bilan.mjs); a bilan it cannot write leaves the code as it is. Then the removal of the
3954
+ // finished copies of the repository (scripts/copies-finies.mjs), as a CI cleans its workspaces at
3955
+ // the end of each pipeline, not only the night's: its lines added to the log and written on the
3956
+ // error stream, each kept copy with the place it holds; it never changes the code.
3869
3957
  function aLaFin(ctx, code) {
3870
3958
  try {
3871
3959
  if (code !== 0) {
@@ -3884,6 +3972,15 @@ function aLaFin(ctx, code) {
3884
3972
  } catch (e) {
3885
3973
  process.stderr.write(`⚠️ bilan non écrit au ticket : ${e.message}\n`);
3886
3974
  }
3975
+ try {
3976
+ const lignes = retirerLesCopiesDuDepot(ctx.racine);
3977
+ if (lignes.length) {
3978
+ appendFileSync(ctx.journal, `${lignes.join('\n')}\n`);
3979
+ process.stderr.write(`${lignes.join('\n')}\n`);
3980
+ }
3981
+ } catch (e) {
3982
+ process.stderr.write(`⚠️ copies finies non retirées : ${e.message}\n`);
3983
+ }
3887
3984
  return code;
3888
3985
  }
3889
3986
 
@@ -4442,6 +4539,11 @@ export async function main(argv) {
4442
4539
  })
4443
4540
  );
4444
4541
  }
4542
+ // The tools of the project, which every pass of the circuit plays with: a faulty key stops the
4543
+ // run before any session, by its name.
4544
+ const lancement = outilsAuLancement(ctx.racine);
4545
+ if (lancement.arret) return aLaFin(ctx, monter(ctx, { ...lancement.arret, etat: d }));
4546
+ ctx.outils = lancement.outils;
4445
4547
  // From the testwriter: the plan, which the explorateur writes and the questionneur reads once.
4446
4548
  if (d.etape === TESTS) {
4447
4549
  const arret = await lePlan(ctx);
@@ -1,10 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  // The removal of the working copies whose content is on main, run by the night once its steps
3
- // are played (scripts/nuit.sh), as `git worktree prune` and the workspace cleanup at the end of a
4
- // CI pipeline (Jenkins « Workspace Cleanup »): no copy outlives the entry of its content on main.
3
+ // are played (scripts/nuit.sh) and at the end of each circuit (scripts/circuit.mjs,
4
+ // `retirerLesCopiesDuDepot`), as `git worktree prune` and the workspace cleanup at the end of a
5
+ // CI pipeline (Jenkins « Workspace Cleanup »): no copy outlives the entry of its content on main,
6
+ // and no target directory its ticket (grillhouse-cyr: 34 GB of target/ under synthhub's copies).
5
7
  //
6
8
  // node scripts/copies-finies.mjs [<copie à garder>…] from the main tree of the repository
7
9
  //
10
+ // - The night's copy (`.claude/worktrees/nuit`) is always left out: the night prepares and
11
+ // removes its own.
8
12
  // - First `git worktree prune`: a copy whose folder is gone leaves the list. Then each copy
9
13
  // `git worktree list` names, the main tree and the copies named on the command line (the
10
14
  // night's) left out, passes through scripts/retirer-copie.sh, without `--jetable`: a copy whose
@@ -17,25 +21,46 @@
17
21
  // scripts/circuit.mjs), or, for the integration copy and the queue copy
18
22
  // (`.claude/worktrees/integration`, `.claude/worktrees/file`), their lock in git's common
19
23
  // directory (`integration.lock`, `file-integration.lock`, scripts/integration/). Tickets in
20
- // progress that do not read, or not within a minute, hold every copy: none is removed.
24
+ // progress that do not read, or not within a minute, hold every copy: none is removed. They are
25
+ // read only when a copy is left to judge: a repository with no copy but the night's calls no bd.
26
+ // A locked copy (`git worktree lock`, as Claude Code locks the copy of a live agent) stays too.
21
27
  // - A copy whose commits are not on main stays, its line naming the first path that has not
22
28
  // entered: retirer-copie.sh judges the local work alone, so the copy's HEAD is judged first, as
23
29
  // the removal judges local work: each path HEAD changed since its base with main holds the
24
30
  // content and the mode a commit of main after that base gave it (a cherry-pick or a rebase
25
31
  // counts, not the commit's identity). A detached HEAD's commits thus never become unreachable.
32
+ // A file the CHANGELOG's merge driver merges (`.gitattributes`, `merge=grillhouse-changelog`,
33
+ // scripts/fusion-du-changelog.mjs) enters main merged with the entries of the lots beside it:
34
+ // it counts as entered once each line not blank its commits added is a line of it on main.
35
+ // - The link `node_modules` of a copy to the main tree's install is no work: when it is all the
36
+ // local work of the copy, it goes before scripts/retirer-copie.sh judges the copy, which goes;
37
+ // beside other work, the copy keeps it, refused with its work.
38
+ // - A copy kept that no circuit holds, its ticket closed (read by `bd list --status closed`, once,
39
+ // the copy's folder bearing its id), loses what the tools of its languages wrote there,
40
+ // untracked by git (`git ls-files --others --directory`): each directory the module of the
41
+ // project's language names (`ignorer`: cargo's `target`, typescript's `.turbo`), and each
42
+ // `node_modules`, a link or a directory; its tracked work stays. A copy whose ticket is in
43
+ // progress, or open, keeps everything.
44
+ // - The line of each copy kept names the place it holds, as `du -sk` counts it (« 2,7 Go »).
26
45
  // - The branch of a copy removed goes (`git branch -D`), its content being HEAD's, on main; main
27
46
  // and a branch another copy holds stay.
28
47
  // - One line per copy removed or kept, on the output, which the night adds to its log. The exit is
29
48
  // 0 whatever is removed or kept: the removal never changes the night's verdict.
30
49
  import { spawnSync } from 'node:child_process';
31
- import { existsSync, realpathSync } from 'node:fs';
50
+ import { existsSync, lstatSync, realpathSync, rmSync } from 'node:fs';
32
51
  import path from 'node:path';
33
52
  import { pathToFileURL } from 'node:url';
53
+ import { PILOTE } from './fusion-du-changelog.mjs';
54
+ import { langageDe } from './langages.mjs';
34
55
 
35
56
  const RETIRER = path.join(import.meta.dirname, 'retirer-copie.sh');
36
57
  const PRINCIPALE = 'main';
37
58
  // The copies of the integration and of the queue, each held while its lock stands.
38
59
  const VERROUS = { integration: 'integration.lock', file: 'file-integration.lock' };
60
+ // The install of a copy: a link to the main tree's, or its own directory.
61
+ const INSTALLATION = 'node_modules';
62
+ // The copy of the night, its own to prepare and to remove (scripts/nuit.sh).
63
+ const NUIT = path.join('.claude', 'worktrees', 'nuit');
39
64
 
40
65
  const lancer = (dossier, cmd, args) =>
41
66
  spawnSync(cmd, args, { cwd: dossier, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
@@ -48,7 +73,8 @@ const reel = p => {
48
73
  }
49
74
  };
50
75
 
51
- // The copies `git worktree list` names: `{ chemin, tete, branche }`, the main tree first.
76
+ // The copies `git worktree list` names: `{ chemin, tete, branche, verrou }`, the main tree first;
77
+ // `verrou` the reason of a locked copy (`git worktree lock`), null for one unlocked.
52
78
  function lesCopies(racine) {
53
79
  return git(racine, 'worktree', 'list', '--porcelain')
54
80
  .stdout.split('\n\n')
@@ -58,11 +84,13 @@ function lesCopies(racine) {
58
84
  chemin: l[0].slice('worktree '.length),
59
85
  tete: l.find(x => x.startsWith('HEAD '))?.slice('HEAD '.length),
60
86
  branche: l.find(x => x.startsWith('branch refs/heads/'))?.slice('branch refs/heads/'.length),
87
+ verrou:
88
+ l.find(x => x === 'locked' || x.startsWith('locked '))?.slice('locked '.length) ?? null,
61
89
  }));
62
90
  }
63
91
 
64
- // What holds <chemin> for a running circuit, or null.
65
- function tenue(chemin, enCours, commun) {
92
+ // What holds the copy <chemin> for a running circuit or a live process (its lock), or null.
93
+ function tenue({ chemin, verrou: raison }, enCours, commun) {
66
94
  const nom = path.basename(chemin);
67
95
  if (existsSync(`${chemin}.travail`)) {
68
96
  return `son circuit a son dossier ${nom}.travail`;
@@ -70,6 +98,9 @@ function tenue(chemin, enCours, commun) {
70
98
  if (enCours.has(nom)) {
71
99
  return `le ticket ${nom} est en cours`;
72
100
  }
101
+ if (raison !== null) {
102
+ return `elle est verrouillée${raison ? ` (${raison})` : ''}`;
103
+ }
73
104
  const verrou = VERROUS[nom];
74
105
  if (verrou && path.dirname(chemin).endsWith(path.join('.claude', 'worktrees'))) {
75
106
  if (existsSync(path.join(commun, verrou))) {
@@ -79,14 +110,35 @@ function tenue(chemin, enCours, commun) {
79
110
  return null;
80
111
  }
81
112
 
113
+ // Whether <p> is merged by the frame's driver of the CHANGELOG (`.gitattributes`, `merge=<PILOTE>`).
114
+ const fusionneParLePilote = (racine, p) =>
115
+ git(racine, 'check-attr', 'merge', '--', p).stdout.trim().endsWith(`: merge: ${PILOTE}`);
116
+
117
+ // Whether each entry (a line not blank) the commits of <b> added to <p> since <base> is a line of
118
+ // <p> on main: a file the driver merges enters main merged with the entries of the lots beside it,
119
+ // never as the copy holds it.
120
+ function entreesSurMain(racine, base, b, p) {
121
+ const ajoutees = git(racine, 'diff', '-U0', '--no-renames', base, b, '--', p)
122
+ .stdout.split('\n')
123
+ .filter(l => l.startsWith('+') && !l.startsWith('+++') && l.slice(1).trim());
124
+ const surMain = git(racine, 'show', `${PRINCIPALE}:${p}`);
125
+ if (surMain.status !== 0) {
126
+ return false;
127
+ }
128
+ const lignes = new Set(surMain.stdout.split('\n'));
129
+ return ajoutees.every(l => lignes.has(l.slice(1)));
130
+ }
131
+
82
132
  // The first path the commit or branch <b> changed since its base with main whose content no commit of main
83
- // after that base gave, or null when all its content is on main.
133
+ // after that base gave, or null when all its content is on main. A file the CHANGELOG's driver
134
+ // merges counts as entered once each of its entries is on main (`entreesSurMain`).
84
135
  function pasEntre(racine, b) {
85
136
  const base = git(racine, 'merge-base', b, PRINCIPALE);
86
137
  if (base.status !== 0) {
87
138
  return `ses commits n'ont pas de base commune avec ${PRINCIPALE}`;
88
139
  }
89
- const chemins = git(racine, 'diff', '--name-only', '-z', '--no-renames', base.stdout.trim(), b)
140
+ const depuis = base.stdout.trim();
141
+ const chemins = git(racine, 'diff', '--name-only', '-z', '--no-renames', depuis, b)
90
142
  .stdout.split('\0')
91
143
  .filter(Boolean);
92
144
  for (const p of chemins) {
@@ -107,19 +159,68 @@ function pasEntre(racine, b) {
107
159
  const [, m, , i] = l.split(/\s+/);
108
160
  return m === mode && (i === id || (id === '0' && /^0+$/.test(i ?? '')));
109
161
  });
110
- if (!entre) {
162
+ if (!entre && !(fusionneParLePilote(racine, p) && entreesSurMain(racine, depuis, b, p))) {
111
163
  return `${p} n'est pas sur ${PRINCIPALE}`;
112
164
  }
113
165
  }
114
166
  return null;
115
167
  }
116
168
 
169
+ // The place <chemin> holds on the disk, as `du` counts it (a link not followed): « 2,7 Go ».
170
+ function place(chemin) {
171
+ const ko = Number.parseInt(lancer(chemin, 'du', ['-sk', chemin]).stdout, 10);
172
+ if (!Number.isFinite(ko)) {
173
+ return '? Go';
174
+ }
175
+ const [valeur, unite] =
176
+ ko >= 1024 * 1024 ? [ko / 1024 / 1024, 'Go'] : ko >= 1024 ? [ko / 1024, 'Mo'] : [ko, 'Ko'];
177
+ const texte = unite === 'Ko' ? String(valeur) : valeur.toFixed(1).replace('.', ',');
178
+ return `${texte} ${unite}`;
179
+ }
180
+
181
+ // What the tools of the languages wrote in the copy <chemin>, untracked by git: each directory of
182
+ // <ignorer> and each install (`node_modules`, a link or a directory), wherever git lists it as
183
+ // untracked; their paths from the copy.
184
+ function sortiesDesOutils(chemin, ignorer) {
185
+ const noms = new Set([...ignorer, INSTALLATION]);
186
+ return git(chemin, 'ls-files', '-z', '--others', '--directory')
187
+ .stdout.split('\0')
188
+ .map(p => p.replace(/\/$/, ''))
189
+ .filter(p => p && noms.has(path.basename(p)));
190
+ }
191
+
192
+ // Whether the link `node_modules` is the only local work of the copy <chemin>, as
193
+ // scripts/retirer-copie.sh reads it (`git status`, submodules included).
194
+ function seulLeLien(chemin) {
195
+ const r = git(chemin, 'status', '--porcelain', '-z', '--ignore-submodules=none');
196
+ return r.status === 0 && r.stdout === `?? ${INSTALLATION}\0`;
197
+ }
198
+
199
+ // Removes from the copy <chemin> what the tools of the languages wrote there; their paths.
200
+ function retirerLesSorties(chemin, ignorer) {
201
+ const retirees = sortiesDesOutils(chemin, ignorer);
202
+ for (const p of retirees) {
203
+ rmSync(path.join(chemin, p), { recursive: true, force: true });
204
+ }
205
+ return retirees;
206
+ }
207
+
117
208
  /**
118
209
  * Removes the copies of the repository at <racine> whose content is on main; returns one line per
119
- * copy removed or kept. <garder> names the copies left out (the night's); <enCours> the ids of the
120
- * tickets in progress, null when they do not read.
210
+ * copy removed or kept, a kept copy's with the place it holds. <garder> names the copies left out
211
+ * (the night's); <lireEnCours> reads the ids of the tickets in progress, null when they do not
212
+ * read: called once, and only when a copy is left to judge, as a cleanup with nothing to clean
213
+ * asks nothing; <lireFermes> reads the ids of the tickets closed, called once, when a copy is kept
214
+ * that no circuit holds. A copy kept whose ticket is closed loses what the tools of its languages
215
+ * wrote there (<ignorer>, the directories the module of the language names, and `node_modules`).
121
216
  */
122
- export function retirerLesCopiesFinies(racine, { garder = [], enCours }) {
217
+ export function retirerLesCopiesFinies(racine, { garder = [], lireEnCours, lireFermes, ignorer }) {
218
+ const [principale, ...listees] = lesCopies(racine);
219
+ const ecartees = new Set([principale?.chemin, ...garder].filter(Boolean).map(reel));
220
+ if (listees.every(c => ecartees.has(reel(c.chemin)))) {
221
+ return [];
222
+ }
223
+ const enCours = lireEnCours();
123
224
  if (enCours === null) {
124
225
  return ['✗ les tickets en cours ne se lisent pas (bd list) : aucune copie n’est retirée.'];
125
226
  }
@@ -130,31 +231,46 @@ export function retirerLesCopiesFinies(racine, { garder = [], enCours }) {
130
231
  '--path-format=absolute',
131
232
  '--git-common-dir'
132
233
  ).stdout.trim();
133
- const [principale, ...copies] = lesCopies(racine);
134
- const ecartees = new Set([principale?.chemin, ...garder].filter(Boolean).map(reel));
234
+ const copies = lesCopies(racine).slice(1);
135
235
  const ici = reel(racine);
136
236
  const vu = c => (path.relative(ici, reel(c)).startsWith('..') ? c : path.relative(ici, reel(c)));
137
237
  const lignes = [];
138
- for (const { chemin, tete, branche } of copies) {
238
+ let fermes;
239
+ // The line of the copy <chemin> kept for <raison>: what it lost when its ticket is closed, then
240
+ // the place it holds.
241
+ const gardee = (chemin, raison) => {
242
+ fermes ??= lireFermes() ?? new Set();
243
+ const perdues = fermes.has(path.basename(chemin)) ? retirerLesSorties(chemin, ignorer) : [];
244
+ const perte = perdues.length ? ` ; son ticket est fermé : ${perdues.join(', ')} retirés` : '';
245
+ return `· copie gardée : ${vu(chemin)} (${place(chemin)}) : ${raison}${perte}`;
246
+ };
247
+ for (const copie of copies) {
248
+ const { chemin, tete, branche } = copie;
139
249
  if (ecartees.has(reel(chemin))) {
140
250
  continue;
141
251
  }
142
- const raison = tenue(chemin, enCours, commun);
252
+ const raison = tenue(copie, enCours, commun);
143
253
  if (raison) {
144
- lignes.push(`· copie gardée : ${vu(chemin)} : ${raison}.`);
254
+ lignes.push(`· copie gardée : ${vu(chemin)} (${place(chemin)}) : ${raison}.`);
145
255
  continue;
146
256
  }
147
257
  const commits = tete ? pasEntre(racine, tete) : null;
148
258
  if (commits) {
149
- lignes.push(`· copie gardée : ${vu(chemin)} : ses commits ne sont pas entrés, ${commits}.`);
259
+ lignes.push(`${gardee(chemin, `ses commits ne sont pas entrés, ${commits}`)}.`);
150
260
  continue;
151
261
  }
262
+ // The copy's link to the main tree's install is no work: when it is all the copy carries, it
263
+ // goes, and the copy with it; beside other work, the copy is judged with it, and keeps it.
264
+ const lien = path.join(chemin, INSTALLATION);
265
+ if (lstatSync(lien, { throwIfNoEntry: false })?.isSymbolicLink() && seulLeLien(chemin)) {
266
+ rmSync(lien);
267
+ }
152
268
  const r = lancer(racine, 'bash', [RETIRER, chemin]);
153
269
  if (r.status !== 0) {
154
270
  const refus = String(r.stderr || r.stdout)
155
271
  .trim()
156
272
  .split('\n');
157
- lignes.push(`· copie gardée : ${vu(chemin)} : ${refus.join('\n ')}`);
273
+ lignes.push(gardee(chemin, refus.join('\n ')));
158
274
  continue;
159
275
  }
160
276
  let ligne = `✓ copie retirée : ${vu(chemin)}`;
@@ -175,10 +291,10 @@ export function retirerLesCopiesFinies(racine, { garder = [], enCours }) {
175
291
  return lignes;
176
292
  }
177
293
 
178
- // The ids of the tickets in progress, null when they do not read within LECTURE_MS.
294
+ // The ids of the tickets of status <statut>, null when they do not read within LECTURE_MS.
179
295
  const LECTURE_MS = 60_000;
180
- function ticketsEnCours(racine) {
181
- const r = spawnSync('bd', ['list', '--status', 'in_progress', '--limit', '0', '--json'], {
296
+ function tickets(racine, statut) {
297
+ const r = spawnSync('bd', ['list', '--status', statut, '--limit', '0', '--json'], {
182
298
  cwd: racine,
183
299
  encoding: 'utf8',
184
300
  maxBuffer: 256 * 1024 * 1024,
@@ -194,12 +310,35 @@ function ticketsEnCours(racine) {
194
310
  }
195
311
  }
196
312
 
197
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
198
- const racine = process.cwd();
199
- const lignes = retirerLesCopiesFinies(racine, {
200
- garder: process.argv.slice(2),
201
- enCours: ticketsEnCours(racine),
313
+ // The directories the tools of the project's language write (`ignorer` of its module), none for a
314
+ // project that declares no language.
315
+ function ignoresDuLangage(racine) {
316
+ try {
317
+ return langageDe(racine).ignorer;
318
+ } catch {
319
+ return [];
320
+ }
321
+ }
322
+
323
+ /**
324
+ * The removal of the copies of the repository at <racine> (`retirerLesCopiesFinies`), the copy of
325
+ * the night and the copies <garder> left out, the tickets read by bd: what the night and the end
326
+ * of each circuit (scripts/circuit.mjs) run. Its lines.
327
+ * @param {string} racine the main tree
328
+ * @param {string[]} [garder]
329
+ * @returns {string[]}
330
+ */
331
+ export function retirerLesCopiesDuDepot(racine, garder = []) {
332
+ return retirerLesCopiesFinies(racine, {
333
+ garder: [path.join(racine, NUIT), ...garder],
334
+ lireEnCours: () => tickets(racine, 'in_progress'),
335
+ lireFermes: () => tickets(racine, 'closed'),
336
+ ignorer: ignoresDuLangage(racine),
202
337
  });
338
+ }
339
+
340
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
341
+ const lignes = retirerLesCopiesDuDepot(process.cwd(), process.argv.slice(2));
203
342
  if (lignes.length) {
204
343
  process.stdout.write(`${lignes.join('\n')}\n`);
205
344
  }
@@ -2,13 +2,14 @@
2
2
  // The frame's git hooks, on Husky's model: the project's `prepare`, which npm runs at its install,
3
3
  // places them, and each calls the project's command, `grillhouse hook <nom>`.
4
4
  //
5
- // npx grillhouse hooks [<project>] places both hooks (the current directory by default)
5
+ // npx grillhouse hooks [<project>] places both hooks and the merge driver of the
6
+ // CHANGELOG (the current directory by default)
6
7
  // npx grillhouse hooks --absents [<project>] prints the name of each absent hook, one per line
7
8
  //
8
9
  // - commit-msg: « un ticket fermé garde sa livraison ; un ticket rouvert reçoit ses corrections » (scripts/un-commit-par-ticket.mjs).
9
10
  // - pre-push: the night branch guard (scripts/branche-de-nuit.mjs).
10
11
  // - A hook lives in the folder git reads for the project (`git rev-parse --git-path hooks`, which
11
- // follows `core.hooksPath`, Beads' `.beads/hooks` included); the configuration is never changed
12
+ // follows `core.hooksPath`, Beads' `.beads/hooks` included); `core.hooksPath` is never changed
12
13
  // here. The update of the frame (scripts/grillhouse-maj.mjs) places them by the same function.
13
14
  // - The frame's lines run `node_modules/.bin/grillhouse` of the project, the package installed;
14
15
  // without it they do nothing and let the hook go on, as Husky's lines do without Husky.
@@ -19,10 +20,14 @@
19
20
  // stay as they are. The frame's lines never end the hook early (no `exec` of a command), so the
20
21
  // lines that follow still run.
21
22
  // - A hook is absent when it is missing from that folder or lacks the current lines of the frame.
23
+ // - The merge driver of the CHANGELOG (scripts/fusion-du-changelog.mjs) is written in the
24
+ // repository's configuration by the same function, `poserCrochets`, which each `npm install`
25
+ // runs, as git asks a driver's command of the configuration, never of a versioned file.
22
26
  import { execFileSync } from 'node:child_process';
23
27
  import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
24
28
  import path from 'node:path';
25
29
  import { pathToFileURL } from 'node:url';
30
+ import { poserLePilote } from './fusion-du-changelog.mjs';
26
31
 
27
32
  // The project's command, which the frame's lines run.
28
33
  const COMMANDE = '_gh_commande="$(git rev-parse --show-toplevel)/node_modules/.bin/grillhouse"';
@@ -102,8 +107,9 @@ function poserCrochet(projet, nom) {
102
107
  return ecrit ? f : null;
103
108
  }
104
109
 
105
- /** Places both frame hooks in the project; returns the paths written. */
110
+ /** Places both frame hooks and the merge driver of the CHANGELOG in the project; returns the paths written. */
106
111
  export function poserCrochets(projet) {
112
+ poserLePilote(projet);
107
113
  return Object.keys(CROCHETS)
108
114
  .map(nom => poserCrochet(projet, nom))
109
115
  .filter(Boolean);