@roomi-fields/grillhouse 0.28.3 → 0.29.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 (68) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/bin/grillhouse.mjs +55 -14
  3. package/cadre/templates/projet/CLAUDE.md +1 -1
  4. package/cadre/templates/projet/README.md +11 -11
  5. package/cadre/templates/projet/_gitignore +2 -5
  6. package/charte.md +13 -4
  7. package/docs/ARCHITECTURE.md +260 -29
  8. package/docs/INTERFACE.md +51 -12
  9. package/package.json +1 -1
  10. package/scripts/aiguillage.mjs +324 -0
  11. package/scripts/avancement.mjs +33 -50
  12. package/scripts/circuit.mjs +558 -146
  13. package/scripts/composition-des-langages.mjs +16 -1
  14. package/scripts/conformite.mjs +16 -0
  15. package/scripts/copies-finies.mjs +171 -30
  16. package/scripts/demon.mjs +134 -21
  17. package/scripts/enveloppe/lancer.sh +13 -14
  18. package/scripts/enveloppe/travail-de-la-copie.mjs +94 -11
  19. package/scripts/etapes.mjs +1 -1
  20. package/scripts/fusion-du-changelog.mjs +0 -1
  21. package/scripts/grillhouse-maj.mjs +16 -7
  22. package/scripts/integration/file.mjs +3 -3
  23. package/scripts/integration/integrer.mjs +3 -3
  24. package/scripts/jointure.d.ts +39 -17
  25. package/scripts/langages/cargo/commandes.mjs +152 -25
  26. package/scripts/langages/cargo/composants.mjs +90 -2
  27. package/scripts/langages/cargo/exemples.mjs +68 -1
  28. package/scripts/langages/cargo/index.mjs +17 -8
  29. package/scripts/langages/cargo/migrations/0.28.4-tailles-des-tests.mjs +35 -0
  30. package/scripts/langages/cargo/sccache.mjs +54 -2
  31. package/scripts/langages/cargo/squelette.mjs +72 -3
  32. package/scripts/langages/cargo/tailles-des-tests.mjs +195 -0
  33. package/scripts/langages/cargo/tests-de-head.mjs +159 -0
  34. package/scripts/langages/python/commandes.mjs +44 -7
  35. package/scripts/langages/python/composants.mjs +33 -3
  36. package/scripts/langages/python/exemples.mjs +19 -0
  37. package/scripts/langages/python/index.mjs +4 -0
  38. package/scripts/langages/python/squelette.mjs +119 -17
  39. package/scripts/langages/typescript/exemples.mjs +16 -0
  40. package/scripts/langages/typescript/index.mjs +6 -3
  41. package/scripts/langages/typescript/regle-des-tests.mjs +13 -0
  42. package/scripts/langages/typescript/squelette.mjs +18 -2
  43. package/scripts/langages/typescript/tests-de-nuit.mjs +41 -21
  44. package/scripts/langages/typescript/verifier.mjs +82 -288
  45. package/scripts/langages/typescript/vitest-config/base.mjs +8 -9
  46. package/scripts/langages/typescript/vitest-config/cibles.mjs +92 -53
  47. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +11 -5
  48. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +4 -2
  49. package/scripts/langages/typescript/vitest-config/mesure.mjs +3 -2
  50. package/scripts/langages/typescript/vitest.nuit.config.mjs +18 -13
  51. package/scripts/lecture-unique.mjs +51 -0
  52. package/scripts/mesure/pression.mjs +9 -7
  53. package/scripts/nuit.sh +19 -12
  54. package/scripts/outil.mjs +72 -0
  55. package/scripts/paquet.mjs +39 -10
  56. package/scripts/resultats.mjs +22 -5
  57. package/scripts/services-du-noyau.mjs +8 -9
  58. package/scripts/session-start.sh +10 -1
  59. package/scripts/sortie.mjs +20 -1
  60. package/scripts/sources.mjs +3 -3
  61. package/scripts/sous-commandes.mjs +1 -0
  62. package/scripts/superviseur.mjs +369 -14
  63. package/scripts/tableau.mjs +219 -58
  64. package/scripts/verrou-de-machine.mjs +303 -58
  65. package/skills/developpeur/SKILL.md +11 -3
  66. package/skills/pitmaster/SKILL.md +58 -23
  67. package/skills/relecteur/SKILL.md +18 -6
  68. package/skills/testwriter/SKILL.md +11 -15
@@ -8,7 +8,8 @@
8
8
  // is refused, named with both languages: a package has one language. A file belongs to the
9
9
  // module of the component that holds it, the deepest (`moduleDuFichier`); a file out of every
10
10
  // component stays the core's, as with one language: the first module, in the order of the
11
- // declaration, whose answer is not null judges it (`estUnTest`, `manifestes.horsDesTests`).
11
+ // declaration, whose answer is not null judges it (`estUnTest`, `soeurDAvant`,
12
+ // `testsDeHead`, `manifestes.horsDesTests`).
12
13
  // - Whether a component plays tests, the readers of components and the components touched are
13
14
  // each module's on its own components, the results joined: a name without supplier is without
14
15
  // supplier in every module, a file out of the graph is out of every module's graph.
@@ -30,6 +31,7 @@
30
31
  import { existsSync, readFileSync } from 'node:fs';
31
32
  import path from 'node:path';
32
33
  import { fileURLToPath } from 'node:url';
34
+ import { luUneFois } from './lecture-unique.mjs';
33
35
 
34
36
  // The scripts of the commands above the composition, named by their paths, never imported: the
35
37
  // one that plays a composed command (./commandes-composees.mjs), and the index of the interfaces
@@ -102,6 +104,15 @@ const sous = (dossier, abs) => abs === dossier || abs.startsWith(`${dossier}${pa
102
104
  * @param {string} racine
103
105
  */
104
106
  export function composantsRanges(modules, racine) {
107
+ // Read once in a scope of readings done once (./lecture-unique.mjs): a sweep asks the module of
108
+ // every file of a folder.
109
+ return luUneFois(`composants ${modules.map(m => m.nom).join('+')} ${path.resolve(racine)}`, () =>
110
+ rangerLesComposants(modules, racine)
111
+ );
112
+ }
113
+
114
+ // The components of `composantsRanges`, read at each call.
115
+ function rangerLesComposants(modules, racine) {
105
116
  const ranges = modules.flatMap(module =>
106
117
  module.composants(racine).map(composant => ({ composant, module }))
107
118
  );
@@ -259,6 +270,10 @@ export function composer(modules) {
259
270
  },
260
271
  estUnTest: (chemin, racine) =>
261
272
  premiereReponse(modules, racine, chemin, m => m.estUnTest(chemin, racine)),
273
+ soeurDAvant: (chemin, racine) =>
274
+ premiereReponse(modules, racine, chemin, m => m.soeurDAvant(chemin, racine)),
275
+ testsDeHead: (chemin, racine, lire, options) =>
276
+ premiereReponse(modules, racine, chemin, m => m.testsDeHead(chemin, racine, lire, options)),
262
277
  manifestes: {
263
278
  verrous: unique(modules.flatMap(m => m.manifestes.verrous)),
264
279
  horsDesTests: (chemin, racine, avant, apres) =>
@@ -24,6 +24,11 @@
24
24
  // - verdict: each task neither green nor unplayed (« à repasser » at 75, red otherwise), the one
25
25
  // that plays the tests marked, and each test failed;
26
26
  // - estUnTest: each path the testwriter writes, with what it is (`joue`, `test`, `matiere`);
27
+ // - versionDeHead (`soeurDAvant`, `testsDeHead`): each path that has a sibling for HEAD's version,
28
+ // with it, said when the sibling is the path itself or lies in another folder, and each path
29
+ // whose names of tests the module reads in HEAD's version (the entry a path, or `{ chemin,
30
+ // textes }`, HEAD's text of each file by its path), with them, said when it has both; the
31
+ // entry's expected siblings are names the module's tool plays, of their file's class;
27
32
  // - fichiersEngendres: each generated file whose check finds a gap;
28
33
  // - gardes: each guard named that the module does not play, and each script it plays that does
29
34
  // not exist;
@@ -154,6 +159,17 @@ export function cas(langage, exemples, { dans = tmpdir() } = {}) {
154
159
  if (c === null) return [];
155
160
  return [`${chemin} : ${['joue', 'test', 'matiere'].filter(k => c[k]).join(', ')}`];
156
161
  }),
162
+ versionDeHead: entrees =>
163
+ entrees.flatMap(x => {
164
+ const { chemin, textes = {} } = typeof x === 'string' ? { chemin: x } : x;
165
+ const s = langage.soeurDAvant(chemin, e.racine);
166
+ const noms = langage.testsDeHead(chemin, e.racine, f => textes[f] ?? null);
167
+ if (s !== null && noms !== null) return [`${chemin} : une sœur et des noms lus`];
168
+ if (noms !== null) return [`${chemin} : ${noms.join(', ') || 'aucun test'}`];
169
+ if (s === null) return [];
170
+ const aCote = s !== chemin && path.dirname(s) === path.dirname(chemin);
171
+ return [aCote ? `${chemin} → ${s}` : `${chemin} → ${s} : pas à côté du fichier`];
172
+ }),
157
173
  fichiersEngendres: racine =>
158
174
  langage
159
175
  .fichiersEngendres(racine)
@@ -1,14 +1,22 @@
1
- #!/usr/bin/env node
2
1
  // The removal of the working copies whose content is on main, run by the night once its steps
3
2
  // are played (scripts/nuit.sh) and at the end of each circuit (scripts/circuit.mjs,
4
3
  // `retirerLesCopiesDuDepot`), as `git worktree prune` and the workspace cleanup at the end of a
5
4
  // CI pipeline (Jenkins « Workspace Cleanup »): no copy outlives the entry of its content on main,
6
5
  // and no target directory its ticket (grillhouse-cyr: 34 GB of target/ under synthhub's copies).
7
6
  //
8
- // node scripts/copies-finies.mjs [<copie à garder>…] from the main tree of the repository
7
+ // node scripts/copies-finies.mjs [<copie finie de jouer>…] from the main tree of the repository
9
8
  //
10
9
  // - The night's copy (`.claude/worktrees/nuit`) is always left out: the night prepares and
11
10
  // removes its own.
11
+ // - A copy named on the command line (the night's, by scripts/nuit.sh once its steps are played)
12
+ // is left out too, and pruned: its owner has played its pass in it, so it loses what the tools
13
+ // of its languages wrote there (`ignorer`), its install (`node_modules`) kept, as its next
14
+ // preparation would (`git clean -x -e node_modules`). Its line names each output removed with
15
+ // the place it held (« target retiré (2,9 Go) »). The copy of the integration and that of the
16
+ // queue, kept that no lock holds, lose them the same way: a copy that lasts holds between its
17
+ // passes none of the outputs its next pass would remove anyway, and at most one pass's
18
+ // (grillhouse-k5y: 2.9 GB in the night's, 4.8 GB in the integration's of SyntHub). The night's
19
+ // copy named by no one is never touched: a night may play in it.
12
20
  // - First `git worktree prune`: a copy whose folder is gone leaves the list. Then each copy
13
21
  // `git worktree list` names, the main tree and the copies named on the command line (the
14
22
  // night's) left out, passes through scripts/retirer-copie.sh, without `--jetable`: a copy whose
@@ -24,6 +32,16 @@
24
32
  // progress that do not read, or not within a minute, hold every copy: none is removed. They are
25
33
  // read only when a copy is left to judge: a repository with no copy but the night's calls no bd.
26
34
  // A locked copy (`git worktree lock`, as Claude Code locks the copy of a live agent) stays too.
35
+ // A copy whose circuit no longer runs (its `<copie>.travail` there, the state
36
+ // `<copie>.circuit.json` naming a process gone, `leMemeVivant`), its ticket still open, stays,
37
+ // its code and commits untouched, and its line says so with the place it holds and that of each
38
+ // of its tools' outputs (« son circuit ne tourne plus (son processus 4242 est parti) ; target y
39
+ // tient 5,1 Go ; son code et ses commits restent »): 5.2 GB of SyntHub's SH-cgi.8.2 were kept
40
+ // so under the words of a running circuit (grillhouse-k5y).
41
+ // - The count of what holds the disk of a copy (`occupantsDesCopies`), which the wait for room of
42
+ // a heavy pass names (scripts/verrou-de-machine.mjs): the copies of its repository, the five
43
+ // largest first, each with its ticket (the copy's folder, but the frame's copies that last and
44
+ // Claude Code's `agent-*`), its place and that of its tools' outputs.
27
45
  // - A copy whose commits are not on main stays, its line naming the first path that has not
28
46
  // entered: retirer-copie.sh judges the local work alone, so the copy's HEAD is judged first, as
29
47
  // the removal judges local work: each path HEAD changed since its base with main holds the
@@ -54,12 +72,12 @@
54
72
  // output, which the night adds to its log. The exit is
55
73
  // 0 whatever is removed or kept: the removal never changes the night's verdict.
56
74
  import { spawnSync } from 'node:child_process';
57
- import { existsSync, lstatSync, realpathSync, rmSync } from 'node:fs';
75
+ import { existsSync, lstatSync, readFileSync, realpathSync, rmSync } from 'node:fs';
58
76
  import path from 'node:path';
59
77
  import { pathToFileURL } from 'node:url';
60
78
  import { PILOTE } from './fusion-du-changelog.mjs';
61
79
  import { langageDe } from './langages.mjs';
62
- import { balayerLesTickets } from './mesure/base-de-passe.mjs';
80
+ import { balayerLesTickets, leMemeVivant } from './mesure/base-de-passe.mjs';
63
81
 
64
82
  const RETIRER = path.join(import.meta.dirname, 'retirer-copie.sh');
65
83
  const PRINCIPALE = 'main';
@@ -67,8 +85,14 @@ const PRINCIPALE = 'main';
67
85
  const VERROUS = { integration: 'integration.lock', file: 'file-integration.lock' };
68
86
  // The install of a copy: a link to the main tree's, or its own directory.
69
87
  const INSTALLATION = 'node_modules';
88
+ // The folder of the copies of a repository, from its main tree.
89
+ const COPIES = path.join('.claude', 'worktrees');
70
90
  // The copy of the night, its own to prepare and to remove (scripts/nuit.sh).
71
- const NUIT = path.join('.claude', 'worktrees', 'nuit');
91
+ const NUIT = path.join(COPIES, 'nuit');
92
+ // The frame's copies that last, each prepared again before its pass, every untracked file removed
93
+ // (`git clean -x`, scripts/nuit.sh and scripts/integration/rejeu.mjs): the night's, the
94
+ // integration's, the queue's. Their folder bears no ticket.
95
+ const DURABLES = new Set(['nuit', ...Object.keys(VERROUS)]);
72
96
 
73
97
  const lancer = (dossier, cmd, args) =>
74
98
  spawnSync(cmd, args, { cwd: dossier, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
@@ -97,10 +121,26 @@ function lesCopies(racine) {
97
121
  }));
98
122
  }
99
123
 
100
- // What holds the copy <chemin> for a running circuit or a live process (its lock), or null.
101
- function tenue({ chemin, verrou: raison }, enCours, commun) {
124
+ const lireJson = f => {
125
+ try {
126
+ return JSON.parse(readFileSync(f, 'utf8'));
127
+ } catch {
128
+ return null;
129
+ }
130
+ };
131
+
132
+ // What holds the copy <chemin> for a running circuit or a live process (its lock), or null. A
133
+ // copy whose circuit no longer runs (the state `<copie>.circuit.json` beside its `.travail` names
134
+ // a process gone, scripts/circuit.mjs) stays held, and its line names the place its tools'
135
+ // outputs (<ignorer>) hold there.
136
+ function tenue({ chemin, verrou: raison }, enCours, commun, ignorer) {
102
137
  const nom = path.basename(chemin);
103
138
  if (existsSync(`${chemin}.travail`)) {
139
+ const etat = lireJson(`${chemin}.circuit.json`);
140
+ if (etat && !leMemeVivant(etat.processus, etat.depart)) {
141
+ const sorties = placeDesSorties(chemin, ignorer).map(s => ` ; ${s}`);
142
+ return `son circuit ne tourne plus (son processus ${etat.processus} est parti)${sorties.join('')} ; son code et ses commits restent`;
143
+ }
104
144
  return `son circuit a son dossier ${nom}.travail`;
105
145
  }
106
146
  if (enCours.has(nom)) {
@@ -174,9 +214,15 @@ function pasEntre(racine, b) {
174
214
  return null;
175
215
  }
176
216
 
177
- // The place <chemin> holds on the disk, as `du` counts it (a link not followed): « 2,7 Go ».
178
- function place(chemin) {
179
- const ko = Number.parseInt(lancer(chemin, 'du', ['-sk', chemin]).stdout, 10);
217
+ // The kilobytes <chemin> holds on the disk, as `du -sk` counts them (a link not followed); NaN
218
+ // when it does not read.
219
+ const kilooctets = chemin => Number.parseInt(lancer(chemin, 'du', ['-sk', chemin]).stdout, 10);
220
+
221
+ // The place <chemin> holds on the disk, as `du` counts it: « 2,7 Go ».
222
+ const place = chemin => texteDePlace(kilooctets(chemin));
223
+
224
+ // The place of <ko> kilobytes in words: « 2,7 Go », « 12 Ko ».
225
+ function texteDePlace(ko) {
180
226
  if (!Number.isFinite(ko)) {
181
227
  return '? Go';
182
228
  }
@@ -197,6 +243,58 @@ function sortiesDesOutils(chemin, ignorer) {
197
243
  .filter(p => p && noms.has(path.basename(p)));
198
244
  }
199
245
 
246
+ // The tools' outputs of the copy <chemin> but its install (<ignorer>), each with its place:
247
+ // « target y tient 4,8 Go ».
248
+ const placeDesSorties = (chemin, ignorer) =>
249
+ sortiesDesOutils(chemin, ignorer)
250
+ .filter(p => path.basename(p) !== INSTALLATION)
251
+ .map(p => `${p} y tient ${place(path.join(chemin, p))}`);
252
+
253
+ // The ticket the copy at <chemin> bears by its folder (`.claude/worktrees/<ticket>`, as the
254
+ // circuit and the launcher name it); null for the frame's copies that last and for Claude Code's
255
+ // (`agent-*`).
256
+ function ticketDeLaCopie(chemin) {
257
+ const nom = path.basename(chemin);
258
+ return path.dirname(chemin).endsWith(COPIES) && !DURABLES.has(nom) && !nom.startsWith('agent-')
259
+ ? nom
260
+ : null;
261
+ }
262
+
263
+ /**
264
+ * What holds the disk of the repository whose copy or main tree is <racine>: its copies, the
265
+ * main tree left out, the five largest first, each with its ticket, its place and the place of
266
+ * its tools' outputs (<ignorer>, by default the directories the module of the project's language
267
+ * names): « .claude/worktrees/SH-ae6.2.7 (le ticket SH-ae6.2.7, 5,0 Go, dont target 4,8 Go) ».
268
+ * What the wait for room on the disk of a copy names (scripts/verrou-de-machine.mjs).
269
+ * @param {string} racine
270
+ * @param {string[]} [ignorer]
271
+ * @returns {string}
272
+ */
273
+ export function occupantsDesCopies(racine, ignorer) {
274
+ const [principale, ...copies] = lesCopies(racine);
275
+ if (!principale) {
276
+ return `aucune copie de dépôt sous ${racine}`;
277
+ }
278
+ if (!copies.length) {
279
+ return `aucune copie de ${principale.chemin} hors son arbre principal`;
280
+ }
281
+ const noms = ignorer ?? ignoresDuLangage(principale.chemin);
282
+ const ici = reel(principale.chemin);
283
+ return copies
284
+ .map(({ chemin }) => ({ chemin, ko: kilooctets(chemin) }))
285
+ .sort((a, b) => (b.ko || 0) - (a.ko || 0))
286
+ .slice(0, 5)
287
+ .map(({ chemin, ko }) => {
288
+ const vu = path.relative(ici, reel(chemin));
289
+ const ticket = ticketDeLaCopie(chemin);
290
+ const dont = sortiesDesOutils(chemin, noms)
291
+ .filter(p => path.basename(p) !== INSTALLATION)
292
+ .map(p => `${p} ${place(path.join(chemin, p))}`);
293
+ return `${vu.startsWith('..') ? chemin : vu} (${ticket ? `le ticket ${ticket}, ` : ''}${texteDePlace(ko)}${dont.length ? `, dont ${dont.join(', ')}` : ''})`;
294
+ })
295
+ .join(', ');
296
+ }
297
+
200
298
  // Whether the link `node_modules` is the only local work of the copy <chemin>, as
201
299
  // scripts/retirer-copie.sh reads it (`git status`, submodules included).
202
300
  function seulLeLien(chemin) {
@@ -204,15 +302,29 @@ function seulLeLien(chemin) {
204
302
  return r.status === 0 && r.stdout === `?? ${INSTALLATION}\0`;
205
303
  }
206
304
 
207
- // Removes from the copy <chemin> what the tools of the languages wrote there; their paths.
208
- function retirerLesSorties(chemin, ignorer) {
209
- const retirees = sortiesDesOutils(chemin, ignorer);
305
+ // Removes from the copy <chemin> what the tools of the languages wrote there, its install
306
+ // (`node_modules`) but with <installation> false; their paths.
307
+ function retirerLesSorties(chemin, ignorer, { installation = true } = {}) {
308
+ const retirees = sortiesDesOutils(chemin, ignorer).filter(
309
+ p => installation || path.basename(p) !== INSTALLATION
310
+ );
210
311
  for (const p of retirees) {
211
312
  rmSync(path.join(chemin, p), { recursive: true, force: true });
212
313
  }
213
314
  return retirees;
214
315
  }
215
316
 
317
+ // Removes from the frame's copy that lasts at <chemin> its tools' outputs, its install kept, as
318
+ // its next preparation would (`git clean -x -e node_modules`): « target retiré (4,8 Go) », each.
319
+ function elaguer(chemin, ignorer) {
320
+ const places = new Map(
321
+ sortiesDesOutils(chemin, ignorer).map(p => [p, place(path.join(chemin, p))])
322
+ );
323
+ return retirerLesSorties(chemin, ignorer, { installation: false }).map(
324
+ p => `${p} retiré (${places.get(p)})`
325
+ );
326
+ }
327
+
216
328
  /**
217
329
  * Removes the copies of the repository at <racine> whose content is on main; returns one line per
218
330
  * copy removed or kept, a kept copy's with the place it holds. <garder> names the copies left out
@@ -221,16 +333,37 @@ function retirerLesSorties(chemin, ignorer) {
221
333
  * asks nothing; <lireFermes> reads the ids of the tickets closed, called once, when a copy is kept
222
334
  * that no circuit holds. A copy kept whose ticket is closed loses what the tools of its languages
223
335
  * wrote there (<ignorer>, the directories the module of the language names, and `node_modules`).
336
+ * <elaguer> names copies left out too, whose owner has played its pass (the night's own): each
337
+ * loses its tools' outputs, its install kept; so does a copy of the integration or of the queue
338
+ * kept that no lock holds.
224
339
  */
225
- export function retirerLesCopiesFinies(racine, { garder = [], lireEnCours, lireFermes, ignorer }) {
340
+ export function retirerLesCopiesFinies(
341
+ racine,
342
+ { garder = [], elaguer: aElaguer = [], lireEnCours, lireFermes, ignorer }
343
+ ) {
226
344
  const [principale, ...listees] = lesCopies(racine);
227
- const ecartees = new Set([principale?.chemin, ...garder].filter(Boolean).map(reel));
345
+ const ici = reel(racine);
346
+ const vu = c => (path.relative(ici, reel(c)).startsWith('..') ? c : path.relative(ici, reel(c)));
347
+ const elaguees = new Set(aElaguer.map(reel));
348
+ const lignes = [];
349
+ for (const { chemin } of listees) {
350
+ if (elaguees.has(reel(chemin))) {
351
+ const retirees = elaguer(chemin, ignorer);
352
+ if (retirees.length) {
353
+ lignes.push(`✓ copie élaguée : ${vu(chemin)} : ${retirees.join(', ')}.`);
354
+ }
355
+ }
356
+ }
357
+ const ecartees = new Set([principale?.chemin, ...garder, ...aElaguer].filter(Boolean).map(reel));
228
358
  if (listees.every(c => ecartees.has(reel(c.chemin)))) {
229
- return [];
359
+ return lignes;
230
360
  }
231
361
  const enCours = lireEnCours();
232
362
  if (enCours === null) {
233
- return ['✗ les tickets en cours ne se lisent pas (bd list) : aucune copie n’est retirée.'];
363
+ return [
364
+ ...lignes,
365
+ '✗ les tickets en cours ne se lisent pas (bd list) : aucune copie n’est retirée.',
366
+ ];
234
367
  }
235
368
  git(racine, 'worktree', 'prune');
236
369
  const commun = git(
@@ -240,15 +373,21 @@ export function retirerLesCopiesFinies(racine, { garder = [], lireEnCours, lireF
240
373
  '--git-common-dir'
241
374
  ).stdout.trim();
242
375
  const copies = lesCopies(racine).slice(1);
243
- const ici = reel(racine);
244
- const vu = c => (path.relative(ici, reel(c)).startsWith('..') ? c : path.relative(ici, reel(c)));
245
- const lignes = [];
246
376
  let fermes;
247
- // The line of the copy <chemin> kept for <raison>: what it lost when its ticket is closed, then
248
- // the place it holds.
377
+ // The line of the copy <chemin> kept for <raison>: what it lost when its ticket is closed, or,
378
+ // for the copy of the integration or of the queue, its tools' outputs, which its next
379
+ // preparation removes; then the place it holds.
249
380
  const gardee = (chemin, raison) => {
381
+ const nom = path.basename(chemin);
382
+ if (Object.hasOwn(VERROUS, nom) && path.dirname(chemin).endsWith(COPIES)) {
383
+ const retirees = elaguer(chemin, ignorer);
384
+ const perte = retirees.length
385
+ ? ` ; sa prochaine préparation l'efface : ${retirees.join(', ')}`
386
+ : '';
387
+ return `· copie gardée : ${vu(chemin)} (${place(chemin)}) : ${raison}${perte}`;
388
+ }
250
389
  fermes ??= lireFermes() ?? new Set();
251
- const perdues = fermes.has(path.basename(chemin)) ? retirerLesSorties(chemin, ignorer) : [];
390
+ const perdues = fermes.has(nom) ? retirerLesSorties(chemin, ignorer) : [];
252
391
  const perte = perdues.length ? ` ; son ticket est fermé : ${perdues.join(', ')} retirés` : '';
253
392
  return `· copie gardée : ${vu(chemin)} (${place(chemin)}) : ${raison}${perte}`;
254
393
  };
@@ -257,7 +396,7 @@ export function retirerLesCopiesFinies(racine, { garder = [], lireEnCours, lireF
257
396
  if (ecartees.has(reel(chemin))) {
258
397
  continue;
259
398
  }
260
- const raison = tenue(copie, enCours, commun);
399
+ const raison = tenue(copie, enCours, commun, ignorer);
261
400
  if (raison) {
262
401
  lignes.push(`· copie gardée : ${vu(chemin)} (${place(chemin)}) : ${raison}.`);
263
402
  continue;
@@ -330,16 +469,18 @@ function ignoresDuLangage(racine) {
330
469
 
331
470
  /**
332
471
  * The removal of the copies of the repository at <racine> (`retirerLesCopiesFinies`), the copy of
333
- * the night and the copies <garder> left out, the tickets read by bd, then of the temporary
334
- * directories of its closed tickets (`balayerLesTickets`): what the night and the end of each
335
- * circuit (scripts/circuit.mjs) run. Its lines.
472
+ * the night left out, the copies <finies> left out and pruned, their owner having played its pass
473
+ * in them (the night's own, which scripts/nuit.sh names), the tickets read by bd, then of the
474
+ * temporary directories of its closed tickets (`balayerLesTickets`): what the night and the end
475
+ * of each circuit (scripts/circuit.mjs) run. Its lines.
336
476
  * @param {string} racine the main tree
337
- * @param {string[]} [garder]
477
+ * @param {string[]} [finies]
338
478
  * @returns {string[]}
339
479
  */
340
- export function retirerLesCopiesDuDepot(racine, garder = []) {
480
+ export function retirerLesCopiesDuDepot(racine, finies = []) {
341
481
  const lignes = retirerLesCopiesFinies(racine, {
342
- garder: [path.join(racine, NUIT), ...garder],
482
+ garder: [path.join(racine, NUIT)],
483
+ elaguer: finies,
343
484
  lireEnCours: () => tickets(racine, 'in_progress'),
344
485
  lireFermes: () => tickets(racine, 'closed'),
345
486
  ignorer: ignoresDuLangage(racine),
package/scripts/demon.mjs CHANGED
@@ -1,24 +1,35 @@
1
- // A command run as a daemon, as daemon(3) and `setsid --fork` make one: the circuit of a ticket
2
- // (scripts/circuit.mjs) runs so, and goes on to its end when the session that launched it ends
3
- // (BP 320.8: the circuit, a background command of the supervisor's session, died with it).
1
+ // A command run as a daemon, as daemon(3) and `setsid --fork` make one, in a unit of its own as
2
+ // `systemd-run --user` starts one: the circuit of a ticket (scripts/circuit.mjs) runs so, and goes
3
+ // on to its end when the session that launched it ends, or when the group of control that holds
4
+ // that session is killed (grillhouse-mwz: on 2026-11-01, systemd-oomd killed the scope of the tmux
5
+ // pane of BPScript's supervisor, 94 processes, two circuits among them, daemons apart from the
6
+ // session's tree; BP 320.8 before: the circuit, a background command of the session, died with it).
4
7
  //
5
- // - `executerEnDemon(script, argv, main)` is the entry of the script <script>, run with the
6
- // arguments <argv>; it returns the exit code of its process. It plays one of three roles, which
7
- // the variable DETACHE carries from one to the next.
8
+ // - `executerEnDemon(script, argv, main, { unite })` is the entry of the script <script>, run with
9
+ // the arguments <argv>; it returns the exit code of its process. It plays one of three roles,
10
+ // which the variable DETACHE carries from one to the next. <unite> names the daemon's unit.
8
11
  // - The caller (no variable): it launches a relay, its own script again, in a session of its own,
9
12
  // and waits for it; then it reads the daemon's output in a directory of its own
10
13
  // (`<tmpdir>/grillhouse-sortie-du-circuit-XXXXXX`, apart from the bases of the runs, which a sweep
11
14
  // reads) and relays it to its own streams while it waits, every PAS_MS; once the daemon's code is
12
15
  // there, written after its last line, it reads the output to its end, then ends on that code. A
13
- // daemon gone without a code ends the caller at 1, said. A caller that dies leaves the daemon
14
- // running.
16
+ // daemon gone without a code ends the caller at 1, said. A daemon that gives the hand back
17
+ // (`rendreLaMain`, as `systemctl start` returns once its unit has started) ends the caller at 0
18
+ // once its output so far is relayed, and goes on alone (grillhouse-pq6: the supervisor's launch
19
+ // of a circuit returns at once, and the circuit's question wakes it by the wait of the
20
+ // questions, scripts/superviseur.mjs). A caller that dies leaves the daemon running.
15
21
  // - The relay: it launches the daemon, its own script again, in a session of its own (setsid), its
16
22
  // output to the directory, writes its pid there and ends at once: the daemon's parent becomes the
17
23
  // system's, so that the daemon is neither in the caller's process group nor under it in the tree
18
- // of processes, which the end of a session of Claude Code kills.
24
+ // of processes, which the end of a session of Claude Code kills. When the user's systemd answers
25
+ // (`systemdUtilisateur`), the daemon starts through `systemd-run --user --scope`, which runs it
26
+ // in place, its process and environment kept, in a scope of its own
27
+ // (`<unite>-<pid of the relay>.scope`, under app.slice), out of the group of control of its
28
+ // caller (the scope of a terminal or of a tmux pane), which systemd stops whole; without it, as
29
+ // in the envelope of the agents, it starts as it is.
19
30
  // - The daemon: it runs <main>(<argv>); at its exit, its code is written for the caller, or the
20
- // directory removed when the caller is gone.
21
- import { spawn } from 'node:child_process';
31
+ // directory removed when the caller is gone or has the hand back.
32
+ import { spawn, spawnSync } from 'node:child_process';
22
33
  import {
23
34
  existsSync,
24
35
  mkdtempSync,
@@ -40,8 +51,37 @@ const PAS_MS = 100;
40
51
 
41
52
  const lire = f => (existsSync(f) ? readFileSync(f, 'utf8') : '');
42
53
 
54
+ // The directory of the caller of this daemon while it waits, null once the hand is given back or
55
+ // out of a daemon.
56
+ let aRendre = null;
57
+ // The caller of this daemon, null out of a daemon.
58
+ let appelantDuDemon = null;
59
+
60
+ // The environment in which systemd-run reaches the user's systemd: the directory of the user's
61
+ // runtime, `/run/user/<uid>` as pam_systemd sets it, when the environment does not give it (a task
62
+ // of Turborepo passes on neither it nor the address of the bus).
63
+ const pourSystemd = () => ({
64
+ ...process.env,
65
+ XDG_RUNTIME_DIR: process.env.XDG_RUNTIME_DIR ?? `/run/user/${process.getuid?.()}`,
66
+ });
67
+
68
+ let systemd = null;
69
+ /** Whether the user's systemd starts a scope (`systemd-run --user --scope true` ends at 0), read once. */
70
+ export function systemdUtilisateur() {
71
+ systemd ??=
72
+ spawnSync('systemd-run', ['--user', '--scope', '--quiet', '--collect', '--', 'true'], {
73
+ stdio: 'ignore',
74
+ timeout: 5000,
75
+ env: pourSystemd(),
76
+ }).status === 0;
77
+ return systemd;
78
+ }
79
+
80
+ // A name of unit of systemd from <nom>: each character it refuses becomes `_`.
81
+ const nomDUnite = nom => String(nom).replace(/[^A-Za-z0-9:_.-]/g, '_');
82
+
43
83
  // The caller: see the header.
44
- async function appeler(script, argv) {
84
+ async function appeler(script, argv, unite) {
45
85
  const dossier = mkdtempSync(path.join(os.tmpdir(), 'grillhouse-sortie-du-circuit-'));
46
86
  const f = nom => path.join(dossier, nom);
47
87
  try {
@@ -50,7 +90,7 @@ async function appeler(script, argv) {
50
90
  stdio: 'ignore',
51
91
  env: {
52
92
  ...process.env,
53
- [DETACHE]: JSON.stringify({ role: 'relais', dossier, appelant: process.pid }),
93
+ [DETACHE]: JSON.stringify({ role: 'relais', dossier, appelant: process.pid, unite }),
54
94
  },
55
95
  });
56
96
  await new Promise(r => {
@@ -75,12 +115,17 @@ async function appeler(script, argv) {
75
115
  }
76
116
  };
77
117
  for (;;) {
78
- // The code is written after the last line: once it is there, the output is read to its end.
118
+ // The code is written after the last line: once it is there, the output is read to its end;
119
+ // the hand given back (`rendreLaMain`) is written after the daemon's line that says so.
79
120
  const fini = existsSync(f('code'));
121
+ const rendue = existsSync(f('rendu'));
80
122
  recopier();
81
123
  if (fini) {
82
124
  return Number(lire(f('code')));
83
125
  }
126
+ if (rendue) {
127
+ return 0;
128
+ }
84
129
  if (!pid || !vivant(pid)) {
85
130
  recopier();
86
131
  if (existsSync(f('code'))) {
@@ -97,13 +142,30 @@ async function appeler(script, argv) {
97
142
  }
98
143
 
99
144
  // The relay: see the header.
100
- function relayer(script, argv, { dossier, appelant }) {
145
+ function relayer(script, argv, { dossier, appelant, unite }) {
101
146
  const sortie = openSync(path.join(dossier, 'sortie'), 'a');
102
147
  const erreurs = openSync(path.join(dossier, 'erreurs'), 'a');
103
- const demon = spawn(process.execPath, [script, ...argv], {
148
+ const commande = [process.execPath, script, ...argv];
149
+ const aPart = systemdUtilisateur();
150
+ const [programme, ...args] = aPart
151
+ ? [
152
+ 'systemd-run',
153
+ '--user',
154
+ '--scope',
155
+ '--quiet',
156
+ '--collect',
157
+ `--unit=${nomDUnite(`${unite}-${process.pid}`)}`,
158
+ '--',
159
+ ...commande,
160
+ ]
161
+ : commande;
162
+ const demon = spawn(programme, args, {
104
163
  detached: true,
105
164
  stdio: ['ignore', sortie, erreurs],
106
- env: { ...process.env, [DETACHE]: JSON.stringify({ role: 'demon', dossier, appelant }) },
165
+ env: {
166
+ ...(aPart ? pourSystemd() : process.env),
167
+ [DETACHE]: JSON.stringify({ role: 'demon', dossier, appelant }),
168
+ },
107
169
  });
108
170
  writeFileSync(path.join(dossier, 'pid'), String(demon.pid ?? ''));
109
171
  demon.unref();
@@ -112,8 +174,10 @@ function relayer(script, argv, { dossier, appelant }) {
112
174
 
113
175
  // The daemon: see the header.
114
176
  async function demon(argv, main, { dossier, appelant }) {
177
+ aRendre = dossier;
178
+ appelantDuDemon = appelant;
115
179
  process.on('exit', code => {
116
- if (!vivant(appelant)) {
180
+ if (!vivant(appelant) || !existsSync(dossier)) {
117
181
  rmSync(dossier, { recursive: true, force: true });
118
182
  return;
119
183
  }
@@ -124,8 +188,57 @@ async function demon(argv, main, { dossier, appelant }) {
124
188
  return await main(argv);
125
189
  }
126
190
 
127
- /** The entry of <script> run with <argv> as a daemon, <main> its run: the exit code. */
128
- export async function executerEnDemon(script, argv, main) {
191
+ /**
192
+ * Whether this process is the daemon of a script run by `executerEnDemon`, read before it runs.
193
+ * @returns {boolean}
194
+ */
195
+ export function estLeDemon() {
196
+ try {
197
+ return JSON.parse(process.env[DETACHE] ?? 'null')?.role === 'demon';
198
+ } catch {
199
+ return false;
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Whether what this process writes on its error stream now reaches a reader: in a daemon, while
205
+ * it has not given the hand back (`rendreLaMain`) and its caller, which relays it, lives; out of a
206
+ * daemon, always, its output its caller's own (grillhouse-pq6.1: the circuit inscribes the
207
+ * question it says there as gone up, scripts/superviseur.mjs).
208
+ * @returns {boolean}
209
+ */
210
+ export function sortieLue() {
211
+ return appelantDuDemon === null || (aRendre !== null && vivant(appelantDuDemon));
212
+ }
213
+
214
+ /**
215
+ * Gives the hand back to the caller of this daemon, as `systemctl start` returns once its unit has
216
+ * started: <message> on the daemon's error stream, which the caller relays, then the caller ends
217
+ * at 0, and the daemon goes on alone, its output no longer read. Once per daemon; nothing out of
218
+ * a daemon (a run in its caller's own process).
219
+ * @param {string} message the line the caller relays last
220
+ * @returns {boolean} whether a caller got the hand back
221
+ */
222
+ export function rendreLaMain(message) {
223
+ if (aRendre === null) {
224
+ return false;
225
+ }
226
+ const dossier = aRendre;
227
+ aRendre = null;
228
+ process.stderr.write(message);
229
+ try {
230
+ writeFileSync(path.join(dossier, 'rendu'), '');
231
+ } catch {
232
+ return false;
233
+ }
234
+ return true;
235
+ }
236
+
237
+ /**
238
+ * The entry of <script> run with <argv> as a daemon, <main> its run, in the unit <unite>: the exit
239
+ * code.
240
+ */
241
+ export async function executerEnDemon(script, argv, main, { unite = path.basename(script) } = {}) {
129
242
  const lu = process.env[DETACHE] ? JSON.parse(process.env[DETACHE]) : null;
130
243
  delete process.env[DETACHE];
131
244
  if (lu?.role === 'relais') {
@@ -134,5 +247,5 @@ export async function executerEnDemon(script, argv, main) {
134
247
  if (lu?.role === 'demon') {
135
248
  return await demon(argv, main, lu);
136
249
  }
137
- return await appeler(script, argv);
250
+ return await appeler(script, argv, unite);
138
251
  }