@roomi-fields/grillhouse 0.25.4 → 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 (48) 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 +107 -19
  10. package/docs/INTERFACE.md +19 -5
  11. package/hooks/register.tsx +57 -16
  12. package/package.json +9 -3
  13. package/scripts/circuit.mjs +244 -66
  14. package/scripts/copies-finies.mjs +345 -0
  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 +26 -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 +77 -22
  27. package/scripts/langages/cargo/composants.mjs +236 -9
  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 +52 -11
  31. package/scripts/langages/typescript/consommateurs.mjs +10 -2
  32. package/scripts/langages/typescript/index.mjs +4 -2
  33. package/scripts/langages/typescript/lecteurs.mjs +13 -4
  34. package/scripts/langages/typescript/references-par-les-types.mjs +5 -1
  35. package/scripts/langages/typescript/regle-des-tests.mjs +37 -0
  36. package/scripts/nuit.sh +25 -0
  37. package/scripts/outils-cles.mjs +188 -0
  38. package/scripts/resultats.mjs +26 -7
  39. package/scripts/retirer-copie.sh +2 -1
  40. package/scripts/sous-commandes.mjs +16 -0
  41. package/scripts/verrou-de-machine.mjs +14 -13
  42. package/scripts/verrous/verrou.mjs +50 -14
  43. package/skills/developpeur/SKILL.md +14 -2
  44. package/skills/explorateur/SKILL.md +3 -1
  45. package/skills/pitmaster/SKILL.md +10 -3
  46. package/skills/pitmaster/references/consigne-agent.md +11 -10
  47. package/skills/relecteur/SKILL.md +13 -2
  48. package/skills/testwriter/SKILL.md +23 -6
@@ -0,0 +1,345 @@
1
+ #!/usr/bin/env node
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) 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).
7
+ //
8
+ // node scripts/copies-finies.mjs [<copie à garder>…] from the main tree of the repository
9
+ //
10
+ // - The night's copy (`.claude/worktrees/nuit`) is always left out: the night prepares and
11
+ // removes its own.
12
+ // - First `git worktree prune`: a copy whose folder is gone leaves the list. Then each copy
13
+ // `git worktree list` names, the main tree and the copies named on the command line (the
14
+ // night's) left out, passes through scripts/retirer-copie.sh, without `--jetable`: a copy whose
15
+ // local work has all entered main by its content goes, with its `<copie>.travail`; a refused
16
+ // copy (work that has not entered, a lock) stays, intact, its line naming the refusal.
17
+ // - A copy a running circuit holds stays without passing, even without work: its ticket in
18
+ // progress (the copy's folder bears the ticket's id, `.claude/worktrees/<ticket>`, as the
19
+ // circuit and the launcher name it; read by `bd list --status in_progress`), the working
20
+ // directory of its circuit (`<copie>.travail`, which lives as long as the ticket,
21
+ // scripts/circuit.mjs), or, for the integration copy and the queue copy
22
+ // (`.claude/worktrees/integration`, `.claude/worktrees/file`), their lock in git's common
23
+ // directory (`integration.lock`, `file-integration.lock`, scripts/integration/). Tickets in
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.
27
+ // - A copy whose commits are not on main stays, its line naming the first path that has not
28
+ // entered: retirer-copie.sh judges the local work alone, so the copy's HEAD is judged first, as
29
+ // the removal judges local work: each path HEAD changed since its base with main holds the
30
+ // content and the mode a commit of main after that base gave it (a cherry-pick or a rebase
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 »).
45
+ // - The branch of a copy removed goes (`git branch -D`), its content being HEAD's, on main; main
46
+ // and a branch another copy holds stay.
47
+ // - One line per copy removed or kept, on the output, which the night adds to its log. The exit is
48
+ // 0 whatever is removed or kept: the removal never changes the night's verdict.
49
+ import { spawnSync } from 'node:child_process';
50
+ import { existsSync, lstatSync, realpathSync, rmSync } from 'node:fs';
51
+ import path from 'node:path';
52
+ import { pathToFileURL } from 'node:url';
53
+ import { PILOTE } from './fusion-du-changelog.mjs';
54
+ import { langageDe } from './langages.mjs';
55
+
56
+ const RETIRER = path.join(import.meta.dirname, 'retirer-copie.sh');
57
+ const PRINCIPALE = 'main';
58
+ // The copies of the integration and of the queue, each held while its lock stands.
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');
64
+
65
+ const lancer = (dossier, cmd, args) =>
66
+ spawnSync(cmd, args, { cwd: dossier, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
67
+ const git = (dossier, ...args) => lancer(dossier, 'git', args);
68
+ const reel = p => {
69
+ try {
70
+ return realpathSync(p);
71
+ } catch {
72
+ return path.resolve(p);
73
+ }
74
+ };
75
+
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.
78
+ function lesCopies(racine) {
79
+ return git(racine, 'worktree', 'list', '--porcelain')
80
+ .stdout.split('\n\n')
81
+ .map(bloc => bloc.split('\n'))
82
+ .filter(l => l[0]?.startsWith('worktree '))
83
+ .map(l => ({
84
+ chemin: l[0].slice('worktree '.length),
85
+ tete: l.find(x => x.startsWith('HEAD '))?.slice('HEAD '.length),
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,
89
+ }));
90
+ }
91
+
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) {
94
+ const nom = path.basename(chemin);
95
+ if (existsSync(`${chemin}.travail`)) {
96
+ return `son circuit a son dossier ${nom}.travail`;
97
+ }
98
+ if (enCours.has(nom)) {
99
+ return `le ticket ${nom} est en cours`;
100
+ }
101
+ if (raison !== null) {
102
+ return `elle est verrouillée${raison ? ` (${raison})` : ''}`;
103
+ }
104
+ const verrou = VERROUS[nom];
105
+ if (verrou && path.dirname(chemin).endsWith(path.join('.claude', 'worktrees'))) {
106
+ if (existsSync(path.join(commun, verrou))) {
107
+ return `le verrou ${verrou} est posé`;
108
+ }
109
+ }
110
+ return null;
111
+ }
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
+
132
+ // The first path the commit or branch <b> changed since its base with main whose content no commit of 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`).
135
+ function pasEntre(racine, b) {
136
+ const base = git(racine, 'merge-base', b, PRINCIPALE);
137
+ if (base.status !== 0) {
138
+ return `ses commits n'ont pas de base commune avec ${PRINCIPALE}`;
139
+ }
140
+ const depuis = base.stdout.trim();
141
+ const chemins = git(racine, 'diff', '--name-only', '-z', '--no-renames', depuis, b)
142
+ .stdout.split('\0')
143
+ .filter(Boolean);
144
+ for (const p of chemins) {
145
+ const tenu = git(racine, 'ls-tree', b, '--', p).stdout.trim();
146
+ const [mode, , id] = tenu ? tenu.split(/\s+/) : ['000000', '', '0'];
147
+ const donnes = git(
148
+ racine,
149
+ 'log',
150
+ `${b}..${PRINCIPALE}`,
151
+ '--no-renames',
152
+ '--format=',
153
+ '--raw',
154
+ '--no-abbrev',
155
+ '--',
156
+ p
157
+ ).stdout.split('\n');
158
+ const entre = donnes.some(l => {
159
+ const [, m, , i] = l.split(/\s+/);
160
+ return m === mode && (i === id || (id === '0' && /^0+$/.test(i ?? '')));
161
+ });
162
+ if (!entre && !(fusionneParLePilote(racine, p) && entreesSurMain(racine, depuis, b, p))) {
163
+ return `${p} n'est pas sur ${PRINCIPALE}`;
164
+ }
165
+ }
166
+ return null;
167
+ }
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
+
208
+ /**
209
+ * Removes the copies of the repository at <racine> whose content is on main; returns one line per
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`).
216
+ */
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();
224
+ if (enCours === null) {
225
+ return ['✗ les tickets en cours ne se lisent pas (bd list) : aucune copie n’est retirée.'];
226
+ }
227
+ git(racine, 'worktree', 'prune');
228
+ const commun = git(
229
+ racine,
230
+ 'rev-parse',
231
+ '--path-format=absolute',
232
+ '--git-common-dir'
233
+ ).stdout.trim();
234
+ const copies = lesCopies(racine).slice(1);
235
+ const ici = reel(racine);
236
+ const vu = c => (path.relative(ici, reel(c)).startsWith('..') ? c : path.relative(ici, reel(c)));
237
+ const lignes = [];
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;
249
+ if (ecartees.has(reel(chemin))) {
250
+ continue;
251
+ }
252
+ const raison = tenue(copie, enCours, commun);
253
+ if (raison) {
254
+ lignes.push(`· copie gardée : ${vu(chemin)} (${place(chemin)}) : ${raison}.`);
255
+ continue;
256
+ }
257
+ const commits = tete ? pasEntre(racine, tete) : null;
258
+ if (commits) {
259
+ lignes.push(`${gardee(chemin, `ses commits ne sont pas entrés, ${commits}`)}.`);
260
+ continue;
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
+ }
268
+ const r = lancer(racine, 'bash', [RETIRER, chemin]);
269
+ if (r.status !== 0) {
270
+ const refus = String(r.stderr || r.stdout)
271
+ .trim()
272
+ .split('\n');
273
+ lignes.push(gardee(chemin, refus.join('\n ')));
274
+ continue;
275
+ }
276
+ let ligne = `✓ copie retirée : ${vu(chemin)}`;
277
+ if (branche && branche !== PRINCIPALE) {
278
+ const tenante = lesCopies(racine).find(c => c.branche === branche);
279
+ if (tenante) {
280
+ ligne += ` ; sa branche ${branche} reste : la copie ${vu(tenante.chemin)} la tient`;
281
+ } else {
282
+ const d = git(racine, 'branch', '-D', branche);
283
+ ligne +=
284
+ d.status === 0
285
+ ? ` ; sa branche ${branche} supprimée`
286
+ : ` ; sa branche ${branche} reste : ${d.stderr.trim()}`;
287
+ }
288
+ }
289
+ lignes.push(`${ligne}.`);
290
+ }
291
+ return lignes;
292
+ }
293
+
294
+ // The ids of the tickets of status <statut>, null when they do not read within LECTURE_MS.
295
+ const LECTURE_MS = 60_000;
296
+ function tickets(racine, statut) {
297
+ const r = spawnSync('bd', ['list', '--status', statut, '--limit', '0', '--json'], {
298
+ cwd: racine,
299
+ encoding: 'utf8',
300
+ maxBuffer: 256 * 1024 * 1024,
301
+ timeout: LECTURE_MS,
302
+ });
303
+ if (r.status !== 0) {
304
+ return null;
305
+ }
306
+ try {
307
+ return new Set((JSON.parse(r.stdout || '[]') ?? []).map(t => String(t.id)));
308
+ } catch {
309
+ return null;
310
+ }
311
+ }
312
+
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),
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));
342
+ if (lignes.length) {
343
+ process.stdout.write(`${lignes.join('\n')}\n`);
344
+ }
345
+ }
@@ -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);
@@ -33,6 +33,18 @@
33
33
  // `~/.claude`, `~/.claude.json`, the npm cache, the paths of `MAISON_EN_LECTURE` (claude, node,
34
34
  // git and the session's tools) and the repository. No socket of the session comes back. Of
35
35
  // the machine's credentials, only claude's own are in sight.
36
+ // - The tools of the project (`grillhouse.outils` of the package.json of the main tree, never of
37
+ // the copy, so that an agent never opens a path for its next session; `{ "<VARIABLE>":
38
+ // "<chemin>" }`, read by scripts/outils-cles.mjs), as Bazel declares what an action sees out of
39
+ // its sandbox and the environment it gets: each path comes back read-only after the declared
40
+ // paths of the home, before the copy and the packages of the plan, which come back in writing
41
+ // over it, and each variable reaches the session, the path resolved. A tool never covers a mount
42
+ // of the envelope: a path is refused when it is `/`, the home or holds it, holds the main tree,
43
+ // `/tmp`, the temporary directories, `~/.claude`, the scratchpads, the npm cache or a session
44
+ // directory, or lies under a hidden directory of the first level of the home (`~/.ssh`,
45
+ // `~/.gnupg`, `~/.aws`, `~/.config`…) but `~/.local` and `~/.cache`, or lies under or holds the
46
+ // keyrings `~/.local/share/keyrings`; a link is judged by its target too. A faulty key refuses the
47
+ // envelope, by its name, before anything is prepared.
36
48
  // - The session gets only the environment the envelope declares (`environnementDeLaSeance`), as
37
49
  // sudo's env_reset and bwrap's --clearenv give it: the base of a login session, claude's own
38
50
  // configuration and credentials (`ANTHROPIC_*`, `CLAUDE_CODE_OAUTH_TOKEN`), the author of its
@@ -81,6 +93,10 @@
81
93
  // the session, as Bazel writes a test's logs out of its source: what is written there leaves no
82
94
  // trace. The envelope creates each of them on disk, empty, before the session, so that bwrap
83
95
  // mounts over it inside the read-only package.
96
+ // - The lock files of the versions at the root of the copy (`manifestes.verrous` of the module of
97
+ // the language: cargo's Cargo.lock), which a run of the tests brings in line with the
98
+ // dependencies of the tests the testwriter declares, come back in writing for the `testwriter`
99
+ // alone, when the plan leaves the root read-only and the file exists.
84
100
  // - The exit codes are named in `codes.mjs`.
85
101
  import { execFileSync, spawnSync } from 'node:child_process';
86
102
  import {
@@ -106,8 +122,9 @@ import {
106
122
 
107
123
  export { paquetsDuLangage };
108
124
  import { ouvrirBase } from '../mesure/base-de-passe.mjs';
125
+ import { outilsDe } from '../outils-cles.mjs';
109
126
 
110
- // The role that writes the package of the shared test material.
127
+ // The role that writes the package of the shared test material and the lock files of the versions.
111
128
  const ROLE_MATIERE = 'testwriter';
112
129
  // The directories <sorties> of <dir>, each relative to it.
113
130
  // One that a symbolic link carries out of <dir> (a `node_modules` linked to another tree's) is
@@ -214,8 +231,10 @@ export function dossierDeTravail(copie, env = process.env) {
214
231
  // envelope mounts in writing, `npm_config_ignore_scripts` set to `true` (npm runs no lifecycle
215
232
  // script: a `prepare` that writes under the read-only `.git` would fail `npm install`; the
216
233
  // launcher installs outside the session), `TMPDIR` set to the session's working directory
217
- // <travail>, and `GRILLHOUSE_ENVELOPPE` set to the plan <paquets>. Nothing else of <env> enters.
218
- export function environnementDeLaSeance(env, { cacheNpm, paquets, travail }) {
234
+ // <travail>, and `GRILLHOUSE_ENVELOPPE` set to the plan <paquets>; with them, each tool of the
235
+ // project <outils> (`grillhouse.outils`), its variable set to its path. Nothing else of <env>
236
+ // enters.
237
+ export function environnementDeLaSeance(env, { cacheNpm, paquets, travail, outils = {} }) {
219
238
  const declare = nom =>
220
239
  ENVIRONNEMENT_DECLARE.includes(nom) ||
221
240
  VARIABLES_DE_CHEMIN.includes(nom) ||
@@ -223,6 +242,7 @@ export function environnementDeLaSeance(env, { cacheNpm, paquets, travail }) {
223
242
  const garde = Object.entries(env).filter(([nom, v]) => v !== undefined && declare(nom));
224
243
  return {
225
244
  ...Object.fromEntries(garde),
245
+ ...outils,
226
246
  npm_config_cache: cacheNpm,
227
247
  npm_config_ignore_scripts: 'true',
228
248
  TMPDIR: travail,
@@ -239,8 +259,9 @@ function commandeEprouvee(commande) {
239
259
  // The mounts outside the copy, in bwrap's order: an empty `/tmp`; the home that holds
240
260
  // `~/.claude` and the session directories, empty and sealed; the copy's scratchpads, the npm
241
261
  // cache and `~/.claude` in writing; the throwaway `~/.claude.json`; over them, what the session
242
- // reads without writing; the copy's project directory, in writing; last, the declared paths of
243
- // the home, read-only.
262
+ // reads without writing; the copy's project directory, in writing; the declared paths of the
263
+ // home, read-only; last, the path of each tool of the project <outils>, read-only (the plan mounts
264
+ // the copy and its written packages after them).
244
265
  export function montagesDeLaSeance({
245
266
  cacheNpm,
246
267
  claude,
@@ -248,6 +269,7 @@ export function montagesDeLaSeance({
248
269
  etatJetable,
249
270
  scratchpads,
250
271
  sessions = [],
272
+ outils = {},
251
273
  }) {
252
274
  const maison = path.dirname(claude);
253
275
  return [
@@ -258,6 +280,7 @@ export function montagesDeLaSeance({
258
280
  ...CLAUDE_EN_LECTURE.map(nom => ({ chemin: path.join(claude, nom), ecriture: false })),
259
281
  { chemin: projet, ecriture: true },
260
282
  ...MAISON_EN_LECTURE.map(rel => ({ chemin: path.join(maison, rel), ecriture: false })),
283
+ ...Object.values(outils).map(chemin => ({ chemin, ecriture: false })),
261
284
  ];
262
285
  }
263
286
 
@@ -396,7 +419,8 @@ export function jugerComposant({ depot, composant, paquets = [] }, fs) {
396
419
  // (`montagesDeLaSeance`); an emptied one marked `scelle` is sealed read-only once every mount
397
420
  // inside it is made. `matieres` lists the packages of the shared test material, relative to the
398
421
  // copy (`matieres` of the module of the language); `role` is the agent's role, and only the
399
- // `testwriter` writes them. `magasins` lists the stores written by every run, the agent's included
422
+ // `testwriter` writes them, and the lock files of the versions `verrous`, from the root of the copy.
423
+ // `magasins` lists the stores written by every run, the agent's included
400
424
  // (the module's, `sortiesDuLangage`: Turborepo's `<main tree>/.turbo/cache`, cargo's registry,
401
425
  // git dependencies, advisories and lock files in the home); one that does not exist is not
402
426
  // mounted. `lectures` lists what the language's tools read (cargo's home, rustup's toolchains),
@@ -414,6 +438,7 @@ export function jugerComposant({ depot, composant, paquets = [] }, fs) {
414
438
  * paquets?: string[],
415
439
  * role?: string,
416
440
  * matieres?: string[],
441
+ * verrous?: string[],
417
442
  * montages?: { chemin: string, source?: string, ecriture?: boolean, vide?: boolean, scelle?: boolean, lien?: string }[],
418
443
  * magasins?: string[],
419
444
  * lectures?: string[],
@@ -430,6 +455,7 @@ export function plan(
430
455
  paquets = [],
431
456
  role,
432
457
  matieres = [],
458
+ verrous = [],
433
459
  montages = [],
434
460
  magasins = [],
435
461
  lectures = [],
@@ -508,6 +534,11 @@ export function plan(
508
534
  const d = path.join(copie, e);
509
535
  args.push('--bind', d, d);
510
536
  }
537
+ // The lock files of the versions, which a run of the testwriter's tests brings in line with
538
+ // the dependencies of his tests, are written by him alone.
539
+ for (const v of verrous.map(v => path.join(copie, v))) {
540
+ if (role === ROLE_MATIERE && fs.existe(v)) args.push('--bind', v, v);
541
+ }
511
542
  }
512
543
  for (const m of matieres.map(m => path.join(copie, m))) {
513
544
  args.push(role === ROLE_MATIERE ? '--bind' : '--ro-bind', m, m);
@@ -547,17 +578,8 @@ function envelopper(argv) {
547
578
  // [A-Za-z0-9] turned into a dash; it is created here so that bwrap mounts it in writing.
548
579
  const enTirets = copie.replace(/[^A-Za-z0-9]/g, '-');
549
580
  const projet = path.join(claude, 'projects', enTirets);
550
- mkdirSync(projet, { recursive: true });
551
581
  const scratchpads = scratchpadsDe(copie);
552
- // The session's working directory, created here inside the scratchpads that bwrap mounts.
553
582
  const travail = dossierDeTravail(copie);
554
- mkdirSync(travail, { recursive: true });
555
- // `~/.claude.json` holds the permissions and servers of every project: it enters the session
556
- // as a throwaway copy, in a base of its own removed on exit and swept when the envelope is
557
- // killed (../mesure/base-de-passe.mjs).
558
- const temporaire = ouvrirBase('enveloppe');
559
- const etatJetable = path.join(temporaire.dossier, 'claude.json');
560
- if (existsSync(`${claude}.json`)) copyFileSync(`${claude}.json`, etatJetable);
561
583
  // The session directories of this user that exist: the XDG one and the systemd one.
562
584
  const sessions = [
563
585
  ...new Set(
@@ -566,8 +588,27 @@ function envelopper(argv) {
566
588
  .map(d => path.resolve(d))
567
589
  ),
568
590
  ];
591
+ // The tools of the project, judged before anything is prepared: none holds a mount.
592
+ let outils;
593
+ try {
594
+ outils = outilsDe(copie, {
595
+ montages: [copie, claude, scratchpads, cacheNpm, TEMPORAIRE, ...sessions],
596
+ });
597
+ } catch (e) {
598
+ process.stderr.write(`⛔ ENVELOPPE REFUSÉE — ${e.message}\n`);
599
+ return CODE_REFUS;
600
+ }
601
+ mkdirSync(projet, { recursive: true });
602
+ // The session's working directory, created here inside the scratchpads that bwrap mounts.
603
+ mkdirSync(travail, { recursive: true });
604
+ // `~/.claude.json` holds the permissions and servers of every project: it enters the session
605
+ // as a throwaway copy, in a base of its own removed on exit and swept when the envelope is
606
+ // killed (../mesure/base-de-passe.mjs).
607
+ const temporaire = ouvrirBase('enveloppe');
608
+ const etatJetable = path.join(temporaire.dossier, 'claude.json');
609
+ if (existsSync(`${claude}.json`)) copyFileSync(`${claude}.json`, etatJetable);
569
610
  const montages = avecLiens(
570
- montagesDeLaSeance({ cacheNpm, claude, projet, etatJetable, scratchpads, sessions }),
611
+ montagesDeLaSeance({ cacheNpm, claude, projet, etatJetable, scratchpads, sessions, outils }),
571
612
  lienSurDisque
572
613
  );
573
614
  const langage = langageDe(copie);
@@ -614,6 +655,7 @@ function envelopper(argv) {
614
655
  paquets,
615
656
  role,
616
657
  matieres,
658
+ verrous: langage.manifestes.verrous,
617
659
  montages,
618
660
  magasins,
619
661
  lectures,
@@ -629,7 +671,7 @@ function envelopper(argv) {
629
671
  } else {
630
672
  const r = spawnSync('bwrap', [...args, ...commandeEprouvee(commande)], {
631
673
  stdio: 'inherit',
632
- env: environnementDeLaSeance(process.env, { cacheNpm, paquets, travail }),
674
+ env: environnementDeLaSeance(process.env, { cacheNpm, paquets, travail, outils }),
633
675
  });
634
676
  if (r.error) process.stderr.write(`⛔ ENVELOPPE IMPOSSIBLE — ${r.error.message}\n`);
635
677
  code = r.error ? CODE_REFUS : (r.status ?? 1);
@@ -40,10 +40,13 @@
40
40
  # again from main. A ticket whose branch is still in the integration queue is not launched:
41
41
  # the refusal goes to the log, which names the queue, CODE_COPIE, before any copy is made.
42
42
  # Moving forward keeps
43
- # the work in progress of the copy: git stashes it, fast-forwards, and reapplies it
44
- # (`--autostash`). A refusal, such as commits of the agent on its branch, goes to the log and
45
- # stops the launch, CODE_COPIE; so does a reapplication that conflicts: the log names each file
46
- # in conflict, the work stays in git's stash, and no agent starts on a half-merged copy. Its
43
+ # the work in progress of the copy in the copy, never in git's stash, which every copy of the
44
+ # repository shares: it is set aside as a lot, the copy fast-forwards, and the lot is applied
45
+ # three ways, as the lot of a branch sent back is (scripts/enveloppe/travail-de-la-copie.mjs).
46
+ # A refusal, such as commits of the agent on its branch or conflicts left unresolved, goes to
47
+ # the log and stops the launch, CODE_COPIE; so does a reapplication that conflicts: the log
48
+ # names the copy and each file in conflict, the conflicts stay marked in the copy's files and
49
+ # unmerged in its index, and no agent starts on a half-merged copy. Its
47
50
  # submodules go through the common preparation (scripts/sous-modules.sh): before moving forward,
48
51
  # a submodule carrying local work stops the launch, CODE_COPIE, its log naming it, the work in
49
52
  # place; then every submodule is set at the commit of HEAD, before any installation, except one the
@@ -185,38 +188,28 @@ echec=$(mktemp)
185
188
  if [ ! -d "$copie" ]; then
186
189
  tete=$(git -C "$racine" rev-parse HEAD) || exit 1
187
190
  branche="agent/$ticket"
188
- lot=
191
+ base= pointe=
189
192
  if git -C "$racine" rev-parse --verify -q "refs/heads/$branche" > /dev/null; then
190
193
  # A branch already there: the queue sent it back, or it was left without a commit. Its lot,
191
194
  # when it carries one, goes back as local work on main; the branch returns to main.
192
195
  if [ "$(git -C "$racine" rev-list --count "$tete..$branche")" -gt 0 ]; then
193
196
  base=$(git -C "$racine" merge-base "$tete" "$branche") || exit 1
194
- lot=$(mktemp) || exit 1
195
- git -C "$racine" diff --binary "$base" "$branche" > "$lot" || exit 1
197
+ pointe=$(git -C "$racine" rev-parse "$branche") || exit 1
196
198
  fi
197
199
  git -C "$racine" branch -q -f "$branche" "$tete" || exit 1
198
200
  git -C "$racine" worktree add -q "$copie" "$branche" || exit 1
199
201
  else
200
202
  git -C "$racine" worktree add -q -b "$branche" "$copie" HEAD || exit 1
201
203
  fi
202
- if [ -n "$lot" ]; then
203
- # The lot is applied three ways: a conflict is marked in the file, the rest of the lot is
204
- # there. The index is left as HEAD has it, so that all of it is local work.
205
- git -C "$copie" apply --3way "$lot" || [ -n "$(git -C "$copie" ls-files -u)" ] || exit 1
206
- git -C "$copie" reset -q || exit 1
207
- rm -f "$lot"
204
+ if [ -n "$pointe" ]; then
205
+ # The lot as local work, a conflict marked in its file (travail-de-la-copie.mjs).
206
+ node "$ici/travail-de-la-copie.mjs" reporter "$copie" "$base" "$pointe" || exit 1
208
207
  fi
209
208
  else
210
209
  bash "$ici/../sous-modules.sh" garde "$copie" || exit 1
211
- git -C "$copie" merge -q --ff-only --autostash "$(git -C "$racine" rev-parse HEAD)" || exit 1
212
- # A conflicting reapplication exits 0: the unmerged files are what tells it.
213
- conflits=$(git -C "$copie" diff --name-only --diff-filter=U) || exit 1
214
- if [ -n "$conflits" ]; then
215
- echo "⛔ Le travail en cours de la copie entre en conflit avec main ; il reste dans la remise de git (git stash list)."
216
- echo "Fichiers en conflit :"
217
- sed 's/^/ /' <<<"$conflits"
218
- exit 1
219
- fi
210
+ # The work in progress moves with the copy, in the copy: a conflict stops the launch, marked
211
+ # in the files, the log naming each one (travail-de-la-copie.mjs).
212
+ node "$ici/travail-de-la-copie.mjs" avancer "$copie" "$(git -C "$racine" rev-parse HEAD)" || exit 1
220
213
  fi
221
214
  # The list the pose fixes is the one every mount gets, whatever the installation rewrites.
222
215
  partages=$(bash "$ici/../sous-modules.sh" pose "$copie") || exit 1