@roomi-fields/grillhouse 0.44.0 → 0.45.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +32 -0
  3. package/cadre/templates/projet/.claude/settings.json +5 -0
  4. package/cadre/templates/projet/CLAUDE.md +15 -2
  5. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  6. package/charte.md +3 -2
  7. package/dist/temporal/circuit/client.d.ts +7 -0
  8. package/dist/temporal/circuit/client.js +12 -2
  9. package/dist/temporal/circuit/client.js.map +1 -1
  10. package/dist/temporal/commande.js +8 -1
  11. package/dist/temporal/commande.js.map +1 -1
  12. package/dist/temporal/installation.d.ts +26 -1
  13. package/dist/temporal/installation.js +113 -14
  14. package/dist/temporal/installation.js.map +1 -1
  15. package/dist/temporal/tickets/activites.js +3 -1
  16. package/dist/temporal/tickets/activites.js.map +1 -1
  17. package/docs/ARCHITECTURE.md +207 -68
  18. package/docs/INTERFACE.md +24 -16
  19. package/package.json +1 -1
  20. package/scripts/activites.mjs +66 -46
  21. package/scripts/aiguillage.mjs +1 -0
  22. package/scripts/attente-de-la-machine.mjs +312 -0
  23. package/scripts/avancement.mjs +38 -31
  24. package/scripts/bilan.mjs +30 -5
  25. package/scripts/circuit.mjs +10 -7
  26. package/scripts/codes-de-sortie.mjs +1 -1
  27. package/scripts/coeurs-dedies.mjs +427 -0
  28. package/scripts/composants-affectes.mjs +3 -1
  29. package/scripts/consommation-des-passes.mjs +382 -0
  30. package/scripts/consommation.mjs +45 -0
  31. package/scripts/copies-finies.mjs +2 -2
  32. package/scripts/depart-du-ticket.mjs +3 -1
  33. package/scripts/disque-des-copies.mjs +1 -1
  34. package/scripts/echantillonneur-de-la-passe.mjs +103 -0
  35. package/scripts/enveloppe/enveloppe.mjs +1 -11
  36. package/scripts/enveloppe/travail-de-la-copie.mjs +3 -2
  37. package/scripts/grillhouse-maj.mjs +8 -4
  38. package/scripts/integration/file.mjs +10 -4
  39. package/scripts/jointure.d.ts +20 -9
  40. package/scripts/langages/cargo/commandes.mjs +8 -8
  41. package/scripts/langages/python/commandes.mjs +7 -6
  42. package/scripts/langages/typescript/tests-de-nuit.mjs +17 -4
  43. package/scripts/langages/typescript/tests.mjs +15 -6
  44. package/scripts/langages/typescript/verifier.mjs +23 -17
  45. package/scripts/langages/typescript/vitest-config/base.mjs +3 -3
  46. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +7 -7
  47. package/scripts/mesure/base-de-passe.mjs +1 -1
  48. package/scripts/migrations/0.44.0-seuil-des-codes-de-tickets.mjs +47 -0
  49. package/scripts/migrations.mjs +2 -0
  50. package/scripts/passe-de-la-machine.mjs +456 -31
  51. package/scripts/places-de-la-machine.mjs +508 -61
  52. package/scripts/plafond-de-la-machine.d.mts +47 -2
  53. package/scripts/plafond-de-la-machine.mjs +197 -5
  54. package/scripts/preparation.mjs +1 -0
  55. package/scripts/regles-des-places.d.mts +40 -0
  56. package/scripts/regles-des-places.mjs +91 -0
  57. package/scripts/retirer-les-copies-finies.mjs +1 -1
  58. package/scripts/seances.mjs +4 -3
  59. package/scripts/services-du-noyau.mjs +3 -3
  60. package/scripts/sous-commandes.mjs +6 -7
  61. package/scripts/tableau.mjs +121 -112
  62. package/scripts/verrou-de-machine.mjs +0 -829
@@ -0,0 +1,382 @@
1
+ // What a heavy pass consumes, kept with the project: the transient scope of the user's systemd
2
+ // manager a pass runs in (`scopeSystemd`, read for `CPUUsageNSec` and `MemoryPeak`, as `systemctl
3
+ // show` and Slurm's `sacct` do), the register under `<git common dir>/grillhouse/` where each
4
+ // measure is a line added (`garderLaConsommation`), and the figures per kind of pass
5
+ // (`bilanDeLaConsommation`). The pass itself is `avecLaPasse` (./passe-de-la-machine.mjs).
6
+ import { spawn, spawnSync } from 'node:child_process';
7
+ import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
8
+ import { cpus } from 'node:os';
9
+ import path from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+
12
+ const TRANCHE_DU_CADRE = 'grillhouse.slice';
13
+
14
+ const REGISTRE = 'consommation.jsonl';
15
+ // The client of the D-Bus of the user's systemd manager, which starts the transient scope.
16
+ const CLIENT_DBUS = 'busctl';
17
+ const SAMPLEUR =fileURLToPath(new URL('./echantillonneur-de-la-passe.mjs', import.meta.url));
18
+ // systemd's "infinity" for a 64-bit counter.
19
+ const INFINI = 2n ** 64n - 1n;
20
+
21
+ /**
22
+ * The cumulated processor time (ns) and the peak of memory (bytes) a scope reports, from the
23
+ * text of `systemctl show -p CPUUsageNSec -p MemoryPeak`; null for a value systemd does not give
24
+ * (`[not set]`, its "infinity"), never zero.
25
+ * @param {string} texte
26
+ * @returns {{ cpuNs: number | null, memoirePic: number | null }}
27
+ */
28
+ export function lireLeScope(texte) {
29
+ const valeur = nom => {
30
+ const m = new RegExp(`^${nom}=(\\d+)$`, 'm').exec(texte);
31
+ if (!m) {
32
+ return null;
33
+ }
34
+ const n = BigInt(m[1]);
35
+ return n >= INFINI ? null : Number(n);
36
+ };
37
+ return { cpuNs: valeur('CPUUsageNSec'), memoirePic: valeur('MemoryPeak') };
38
+ }
39
+
40
+ /**
41
+ * The register of the project at <racine>: `consommation.jsonl` under the `grillhouse/` directory
42
+ * of its common git directory; null out of git.
43
+ * @param {string} racine
44
+ * @returns {string | null}
45
+ */
46
+ export function fichierDeConsommation(racine) {
47
+ const r = spawnSync(
48
+ 'git',
49
+ ['-C', racine, 'rev-parse', '--path-format=absolute', '--git-common-dir'],
50
+ { encoding: 'utf8' }
51
+ );
52
+ return r.status === 0 ? path.join(r.stdout.trim(), 'grillhouse', REGISTRE) : null;
53
+ }
54
+
55
+ /**
56
+ * Adds <ligne> (`{ sorte, ticket?, dureeMs, cpuNs, memoirePic, coeurs, issue, fin }`) to the
57
+ * register of <racine>; nothing out of git.
58
+ * @param {string} racine
59
+ * @param {Record<string, unknown>} ligne
60
+ */
61
+ export function garderLaConsommation(racine, ligne) {
62
+ const f = fichierDeConsommation(racine);
63
+ if (f === null) {
64
+ return;
65
+ }
66
+ mkdirSync(path.dirname(f), { recursive: true });
67
+ appendFileSync(f, `${JSON.stringify(ligne)}\n`);
68
+ }
69
+
70
+ /**
71
+ * The lines of the register of <racine>, in order; none when it is absent, a malformed line
72
+ * skipped.
73
+ * @param {string} racine
74
+ * @returns {Record<string, any>[]}
75
+ */
76
+ export function lireLaConsommation(racine) {
77
+ const f = fichierDeConsommation(racine);
78
+ let texte;
79
+ try {
80
+ texte = readFileSync(f ?? '', 'utf8');
81
+ } catch {
82
+ return [];
83
+ }
84
+ const lignes = [];
85
+ for (const l of texte.split('\n')) {
86
+ try {
87
+ const o = l.trim() === '' ? null : JSON.parse(l);
88
+ if (o && typeof o === 'object' && typeof o.sorte === 'string') {
89
+ lignes.push(o);
90
+ }
91
+ } catch {
92
+ // a malformed line is skipped
93
+ }
94
+ }
95
+ return lignes;
96
+ }
97
+
98
+ const mediane = valeurs => {
99
+ const v = [...valeurs].sort((a, b) => a - b);
100
+ const m = Math.floor(v.length / 2);
101
+ return v.length % 2 ? v[m] : (v[m - 1] + v[m]) / 2;
102
+ };
103
+
104
+ /**
105
+ * Per kind of pass, in the order of first appearance: the number of passes, the median and the
106
+ * maximum of the cores occupied (processor time ÷ duration) and of the peak of memory. A line
107
+ * whose processor time is unreadable, or whose duration is nil, is left out.
108
+ * @param {Record<string, any>[]} lignes
109
+ * @returns {{ sorte: string, passes: number, coeursMediane: number, coeursMax: number,
110
+ * memoireMediane: number, memoireMax: number }[]}
111
+ */
112
+ export function bilanDeLaConsommation(lignes) {
113
+ const parSorte = new Map();
114
+ for (const l of lignes) {
115
+ if (typeof l.cpuNs !== 'number' || !(l.dureeMs > 0)) {
116
+ continue;
117
+ }
118
+ const liste = parSorte.get(l.sorte) ?? [];
119
+ liste.push(l);
120
+ parSorte.set(l.sorte, liste);
121
+ }
122
+ return [...parSorte].map(([sorte, liste]) => {
123
+ const coeurs = liste.map(l => l.cpuNs / 1e6 / l.dureeMs);
124
+ const memoires = liste.filter(l => typeof l.memoirePic === 'number').map(l => l.memoirePic);
125
+ return {
126
+ sorte,
127
+ passes: liste.length,
128
+ coeursMediane: mediane(coeurs),
129
+ coeursMax: Math.max(...coeurs),
130
+ memoireMediane: memoires.length ? mediane(memoires) : 0,
131
+ memoireMax: memoires.length ? Math.max(...memoires) : 0,
132
+ };
133
+ });
134
+ }
135
+
136
+ /**
137
+ * The name of a kind of pass in the register: lower case, without accent, words joined by dashes
138
+ * (« Vérification » → `verification`).
139
+ * @param {string} nom
140
+ */
141
+ export function sorteDeLaPasse(nom) {
142
+ return nom
143
+ .normalize('NFD')
144
+ .replace(/\p{Diacritic}/gu, '')
145
+ .toLowerCase()
146
+ .replace(/[^a-z0-9]+/g, '-')
147
+ .replace(/^-|-$/g, '');
148
+ }
149
+
150
+ /** The cores of the machine. */
151
+ export const coeursDeLaMachine = () => cpus().length;
152
+
153
+ /**
154
+ * What the scope <unite> reports now (`lireLeScope` of `systemctl --user show`); null when the
155
+ * manager does not answer, the scope gone.
156
+ * @param {string} unite
157
+ */
158
+ export const lireLUnite = unite => {
159
+ const r = spawnSync(
160
+ 'systemctl',
161
+ ['--user', 'show', unite, '-p', 'CPUUsageNSec', '-p', 'MemoryPeak'],
162
+ { encoding: 'utf8' }
163
+ );
164
+ return r.status === 0 ? lireLeScope(r.stdout) : null;
165
+ };
166
+
167
+ /**
168
+ * The weight of a part for the CPU: 100 per core, within the 1 to 10000 range of `CPUWeight`, so
169
+ * that the weights of two parts share the cores in proportion of their cores.
170
+ * @param {{ coeurs: number }} part
171
+ * @returns {number}
172
+ */
173
+ export const poidsDeLaPart = part => Math.max(1, Math.min(10_000, part.coeurs * 100));
174
+
175
+ const un = n => (Number.isInteger(n) ? String(n) : n.toFixed(1).replace('.', ','));
176
+
177
+ /**
178
+ * What a pass consumes beyond its part, said, null when it holds to it: the cores it occupied
179
+ * (processor time ÷ duration, once the pass has played SEUIL_DE_DEPASSEMENT_MS) above
180
+ * DEPASSEMENT times its cores, or a peak of memory above its memory.
181
+ * @param {{ part: { coeurs: number, memoire: number }, cpuNs: number | null, dureeMs: number,
182
+ * memoirePic: number | null }} o
183
+ * @returns {string | null}
184
+ */
185
+ export function depasseLaPart({ part, cpuNs, dureeMs, memoirePic }) {
186
+ if (typeof cpuNs === 'number' && dureeMs >= SEUIL_DE_DEPASSEMENT_MS) {
187
+ const occupes = cpuNs / 1e6 / dureeMs;
188
+ if (occupes > part.coeurs * DEPASSEMENT) {
189
+ return `cœurs : ${un(Math.round(occupes * 10) / 10)} mesurés pour ${part.coeurs}`;
190
+ }
191
+ }
192
+ if (typeof memoirePic === 'number' && memoirePic > part.memoire) {
193
+ return `mémoire : ${un(Math.round((memoirePic / 1024 ** 3) * 10) / 10)} Go mesurés pour ${un(Math.round((part.memoire / 1024 ** 3) * 10) / 10)}`;
194
+ }
195
+ return null;
196
+ }
197
+
198
+ /** A pass consumes clearly more than its part above this ratio of its cores. */
199
+ export const DEPASSEMENT = 1.5;
200
+ /** A pass is judged on its cores once it has played this long, in ms. */
201
+ export const SEUIL_DE_DEPASSEMENT_MS = 5_000;
202
+
203
+ // Starts the sampler of a pass outside its group (./echantillonneur-de-la-passe.mjs): it reads the
204
+ // group <unite> while the pass lives, notes its last reading beside the marker, and, given the part
205
+ // of the pass, says in the file of the part when the pass exceeds it. Without a register for the
206
+ // project, nothing is started.
207
+ function demarrerLEchantillonneur({ racine, sorte, ticket, coeurs, part, unite, id }) {
208
+ const registre = fichierDeConsommation(racine);
209
+ const marqueur = registre === null ? null : path.join(path.dirname(registre), `${id}.fin`);
210
+ if (marqueur === null) {
211
+ return { marqueur, echantillonneur: null };
212
+ }
213
+ mkdirSync(path.dirname(marqueur), { recursive: true });
214
+ const echantillonneur = spawn(
215
+ process.execPath,
216
+ [
217
+ SAMPLEUR,
218
+ JSON.stringify({
219
+ unite,
220
+ pid: process.pid,
221
+ racine,
222
+ marqueur,
223
+ part,
224
+ base: { sorte, ...(ticket ? { ticket } : {}), coeurs, debut: Date.now() },
225
+ }),
226
+ ],
227
+ { detached: true, stdio: 'ignore' }
228
+ );
229
+ echantillonneur.unref();
230
+ return { marqueur, echantillonneur };
231
+ }
232
+
233
+ /**
234
+ * The group of a pass whose command is launched in it (`commandeDuGroupe` of
235
+ * ./passe-de-la-machine.mjs): `ouvrir()` starts the sampler, which reads the group named after the
236
+ * part of the pass while its command runs, and returns `{ unite, lire, clore }`: `lire()` the last
237
+ * reading the sampler noted, null without one.
238
+ * @param {{ racine: string, sorte: string, ticket?: string, coeurs: number,
239
+ * part: { id: string, coeurs: number, memoire: number, dossier: string }, mesurer?: boolean }} o
240
+ */
241
+ export function scopeDeCommande({ racine, sorte, ticket, coeurs, part, mesurer = true }) {
242
+ return {
243
+ ouvrir() {
244
+ const unite = `grillhouse-passe-${part.id}.scope`;
245
+ const { marqueur } = mesurer
246
+ ? demarrerLEchantillonneur({ racine, sorte, ticket, coeurs, part, unite, id: part.id })
247
+ : { marqueur: null };
248
+ return {
249
+ unite,
250
+ lire: () => {
251
+ try {
252
+ return marqueur === null ? null : JSON.parse(readFileSync(`${marqueur}.lecture`, 'utf8'));
253
+ } catch {
254
+ return null;
255
+ }
256
+ },
257
+ clore: () => {
258
+ if (marqueur !== null) {
259
+ writeFileSync(marqueur, '');
260
+ }
261
+ },
262
+ };
263
+ },
264
+ };
265
+ }
266
+
267
+ /**
268
+ * The real scope of a pass that is the process itself: `ouvrir()` moves this process into a
269
+ * transient scope of the user's systemd manager (`StartTransientUnit` with its PID, which its
270
+ * children inherit), the CPU weight and the memory bound of its part among its properties, after
271
+ * having started the sampler outside it (<mesurer>), and returns `{ lire, clore }`; `{ raison }`
272
+ * when no manager of the user is reachable. The scope goes when empty.
273
+ * @param {{ racine: string, sorte: string, ticket?: string, coeurs: number,
274
+ * part?: { id: string, coeurs: number, memoire: number, dossier: string } | null,
275
+ * mesurer?: boolean }} o
276
+ * @returns {{ ouvrir: () => { lire: () => ({ cpuNs: number | null, memoirePic: number | null } | null),
277
+ * clore: () => void } | { raison: string } }}
278
+ */
279
+ export function scopeSystemd({
280
+ racine,
281
+ sorte,
282
+ ticket,
283
+ coeurs,
284
+ part = null,
285
+ mesurer = true,
286
+ fils = null,
287
+ }) {
288
+ // `AllowedCPUs` of systemd is a bit mask of the threads, a byte array, the first byte the
289
+ // threads 0 to 7.
290
+ const masque = (() => {
291
+ if (!fils || fils.length === 0) {
292
+ return [];
293
+ }
294
+ const octets = new Array(Math.floor(Math.max(...fils) / 8) + 1).fill(0);
295
+ for (const f of fils) {
296
+ octets[Math.floor(f / 8)] |= 1 << f % 8;
297
+ }
298
+ return octets.map(String);
299
+ })();
300
+ return {
301
+ ouvrir() {
302
+ const id = `${process.pid}-${Date.now()}`;
303
+ const unite = `grillhouse-passe-${id}.scope`;
304
+ const { marqueur, echantillonneur } = mesurer
305
+ ? demarrerLEchantillonneur({ racine, sorte, ticket, coeurs, part, unite, id })
306
+ : { marqueur: null, echantillonneur: null };
307
+ const r = spawnSync(
308
+ CLIENT_DBUS,
309
+ [
310
+ '--user',
311
+ 'call',
312
+ 'org.freedesktop.systemd1',
313
+ '/org/freedesktop/systemd1',
314
+ 'org.freedesktop.systemd1.Manager',
315
+ 'StartTransientUnit',
316
+ 'ssa(sv)a(sa(sv))',
317
+ unite,
318
+ 'fail',
319
+ String(4 + (part ? 2 : 0) + (masque.length > 0 ? 2 : 0)),
320
+ 'PIDs',
321
+ 'au',
322
+ '1',
323
+ String(process.pid),
324
+ 'Description',
325
+ 's',
326
+ `grillhouse : passe ${sorte}`,
327
+ 'CPUAccounting',
328
+ 'b',
329
+ 'true',
330
+ 'MemoryAccounting',
331
+ 'b',
332
+ 'true',
333
+ ...(part
334
+ ? [
335
+ 'CPUWeight',
336
+ 't',
337
+ String(poidsDeLaPart(part)),
338
+ 'MemoryMax',
339
+ 't',
340
+ String(Math.floor(part.memoire)),
341
+ ]
342
+ : []),
343
+ // Under the framework slice, whose cores are not those withdrawn from the user's `app.slice`.
344
+ ...(masque.length > 0
345
+ ? [
346
+ 'Slice',
347
+ 's',
348
+ TRANCHE_DU_CADRE,
349
+ 'AllowedCPUs',
350
+ 'ay',
351
+ String(masque.length),
352
+ ...masque,
353
+ ]
354
+ : []),
355
+ '0',
356
+ ],
357
+ { encoding: 'utf8', timeout: 20_000 }
358
+ );
359
+ if (r.status !== 0) {
360
+ if (echantillonneur?.pid) {
361
+ try {
362
+ process.kill(echantillonneur.pid);
363
+ } catch {
364
+ // already gone
365
+ }
366
+ }
367
+ const dit = `${r.stderr ?? ''}${r.error?.message ?? ''}`.trim().split('\n')[0];
368
+ return {
369
+ raison: `aucun gestionnaire systemd utilisateur joignable${dit ? ` (${dit})` : ''}`,
370
+ };
371
+ }
372
+ return {
373
+ lire: () => lireLUnite(unite),
374
+ clore: () => {
375
+ if (marqueur !== null) {
376
+ writeFileSync(marqueur, '');
377
+ }
378
+ },
379
+ };
380
+ },
381
+ };
382
+ }
@@ -0,0 +1,45 @@
1
+ // `grillhouse consommation [--json]`: what the heavy passes of the project consume, per kind of
2
+ // pass, read from its register (./consommation-des-passes.mjs): the number of passes, the median
3
+ // and the maximum of the cores occupied (processor time ÷ duration) and of the peak of memory.
4
+ import { pathToFileURL } from 'node:url';
5
+ import { bilanDeLaConsommation, lireLaConsommation } from './consommation-des-passes.mjs';
6
+
7
+ const GO = 1024 ** 3;
8
+ const go = o => `${(o / GO).toFixed(1)} Go`;
9
+ const coeurs = c => c.toFixed(1);
10
+
11
+ /**
12
+ * Writes the figures of the project at <racine> through <ecrire>; returns the exit code (0).
13
+ * @param {{ args: string[], racine: string, ecrire: (texte: string) => void }} o
14
+ * @returns {number}
15
+ */
16
+ export function consommation({ args, racine, ecrire }) {
17
+ const lignes = lireLaConsommation(racine);
18
+ const rangs = bilanDeLaConsommation(lignes);
19
+ if (args.includes('--json')) {
20
+ ecrire(`${JSON.stringify(rangs)}\n`);
21
+ } else if (rangs.length === 0) {
22
+ ecrire('aucune mesure\n');
23
+ } else {
24
+ for (const r of rangs) {
25
+ // The passes of this kind that consumed clearly more than their part, the last one said.
26
+ const depassent = lignes.filter(l => l.sorte === r.sorte && l.depasse);
27
+ const depasse = depassent.length
28
+ ? ` ; ⚠ ${depassent.length} dépassent leur part (la dernière, ${depassent.at(-1).depasse})`
29
+ : '';
30
+ ecrire(
31
+ `${r.sorte} : ${r.passes} passes, cœurs occupés médiane ${coeurs(r.coeursMediane)} max ${coeurs(r.coeursMax)}, ` +
32
+ `pic de mémoire médiane ${go(r.memoireMediane)} max ${go(r.memoireMax)}${depasse}\n`
33
+ );
34
+ }
35
+ }
36
+ return 0;
37
+ }
38
+
39
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
40
+ process.exitCode = consommation({
41
+ args: process.argv.slice(2),
42
+ racine: process.cwd(),
43
+ ecrire: t => process.stdout.write(t),
44
+ });
45
+ }
@@ -48,7 +48,7 @@
48
48
  // unread, or the end of a circuit, whose act reads no server), its line says only that its
49
49
  // circuit has its working directory.
50
50
  // - The count of what holds the disk of a copy (`occupantsDesCopies`), which the wait for room of
51
- // a heavy pass names (scripts/verrou-de-machine.mjs): the copies of its repository, the five
51
+ // a pass names (scripts/attente-de-la-machine.mjs): the copies of its repository, the five
52
52
  // largest first, each with its ticket (the copy's folder, but the frame's copies that last and
53
53
  // Claude Code's `agent-*`), its place and that of its tools' outputs.
54
54
  // - A copy whose commits are not on main stays, its line naming the first path that has not
@@ -273,7 +273,7 @@ function ticketDeLaCopie(chemin) {
273
273
  * main tree left out, the five largest first, each with its ticket, its place and the place of
274
274
  * its tools' outputs (<ignorer>, by default the directories the module of the project's language
275
275
  * names): « .claude/worktrees/SH-ae6.2.7 (le ticket SH-ae6.2.7, 5,0 Go, dont target 4,8 Go) ».
276
- * What the wait for room on the disk of a copy names (scripts/verrou-de-machine.mjs).
276
+ * What the wait for room on the disk of a copy names (scripts/attente-de-la-machine.mjs).
277
277
  * @param {string} racine
278
278
  * @param {string[]} [ignorer]
279
279
  * @returns {string}
@@ -107,7 +107,9 @@ export function ticketAuLancement(racine, id, { arreter = false, bd = null, plan
107
107
  ((...a) => spawnSync('bd', a, { cwd: racine, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 }))
108
108
  )('show', id, '--json');
109
109
  if (show.status !== 0) {
110
- throw new DepartRefuse(`ticket ${id} illisible : ${show.stderr}`);
110
+ throw new DepartRefuse(
111
+ `ticket ${id} illisible : ${show.error?.message ?? show.stderr ?? ''}`.trim()
112
+ );
111
113
  }
112
114
  const ticket = ticketAuDepart(id, show.stdout, { arreter });
113
115
  const copie = path.join(racine, '.claude', 'worktrees', id);
@@ -20,7 +20,7 @@ import {
20
20
  } from 'node:fs';
21
21
  import path from 'node:path';
22
22
  import { langagesDe } from './langages.mjs';
23
- import { LIBRE_MIN } from './verrou-de-machine.mjs';
23
+ import { LIBRE_MIN } from './attente-de-la-machine.mjs';
24
24
 
25
25
  const GO = 1024 ** 3;
26
26
  /** The expected size of a copy of a project that declares no language, before any measure. */
@@ -0,0 +1,103 @@
1
+ // The sampler of a heavy pass, a process apart outside its scope: while the pass lives it reads the
2
+ // scope again and keeps the last reading; when the pass has gone without writing its final line
3
+ // (SIGKILL, the watch of the memory), it writes the line « interrompue » with that reading. Started
4
+ // by `scopeSystemd` (./consommation-des-passes.mjs); a pass that ends by itself leaves the marker
5
+ // file `<id>.fin` the sampler removes.
6
+ import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
7
+ import path from 'node:path';
8
+ import { pathToFileURL } from 'node:url';
9
+ import { depasseLaPart, garderLaConsommation, lireLUnite } from './consommation-des-passes.mjs';
10
+ import { ecrireAtomique } from './mesure/avancement.mjs';
11
+
12
+ const PERIODE_MS = 1000;
13
+
14
+ /**
15
+ * Samples the pass behind <port> until it is over, then writes its line if it left none.
16
+ * @param {{
17
+ * base: { sorte: string, ticket?: string, coeurs: number, debut: number },
18
+ * lire: () => ({ cpuNs: number | null, memoirePic: number | null } | null),
19
+ * vivante: () => boolean,
20
+ * finale: () => boolean,
21
+ * noter: (l: { cpuNs: number | null, memoirePic: number | null }) => void,
22
+ * garder: (l: Record<string, unknown>) => void,
23
+ * maintenant: () => number,
24
+ * dormir: () => void,
25
+ * }} port `vivante`, whether the pass goes on; `finale`, whether it wrote its final line
26
+ */
27
+ export function echantillonner({ base, lire, vivante, finale, noter, garder, maintenant, dormir }) {
28
+ let derniere = null;
29
+ while (vivante()) {
30
+ const l = lire();
31
+ if (l && (l.cpuNs !== null || l.memoirePic !== null)) {
32
+ derniere = l;
33
+ noter(l);
34
+ }
35
+ dormir();
36
+ }
37
+ if (finale()) {
38
+ return;
39
+ }
40
+ const fin = maintenant();
41
+ garder({
42
+ sorte: base.sorte,
43
+ ...(base.ticket ? { ticket: base.ticket } : {}),
44
+ dureeMs: fin - base.debut,
45
+ cpuNs: derniere?.cpuNs ?? null,
46
+ memoirePic: derniere?.memoirePic ?? null,
47
+ coeurs: base.coeurs,
48
+ issue: 'interrompue',
49
+ fin: new Date(fin).toISOString(),
50
+ });
51
+ }
52
+
53
+ const vit = pid => {
54
+ try {
55
+ process.kill(pid, 0);
56
+ return true;
57
+ } catch (e) {
58
+ return e.code === 'EPERM';
59
+ }
60
+ };
61
+
62
+ // Says in the file of the part <part> (`{ dossier, id, coeurs, memoire }` of the parts of the
63
+ // machine) what the pass consumes beyond it, from the reading <l> and the start of the pass; the
64
+ // file is left as it is when the pass holds to its part or its file is gone.
65
+ function signalerLeDepassement(part, base, l) {
66
+ const f = path.join(part.dossier, `${part.id}.json`);
67
+ try {
68
+ const p = JSON.parse(readFileSync(f, 'utf8'));
69
+ const depasse = depasseLaPart({
70
+ part,
71
+ cpuNs: l.cpuNs,
72
+ dureeMs: Date.now() - base.debut,
73
+ memoirePic: l.memoirePic,
74
+ });
75
+ if (depasse !== (p.depasse ?? null)) {
76
+ ecrireAtomique(f, depasse === null ? { ...p, depasse: undefined } : { ...p, depasse });
77
+ }
78
+ } catch {
79
+ // the part is given back: nothing to say
80
+ }
81
+ }
82
+
83
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
84
+ const { unite, pid, racine, marqueur, base, part } = JSON.parse(process.argv[2]);
85
+ const attente = new Int32Array(new SharedArrayBuffer(4));
86
+ echantillonner({
87
+ base,
88
+ lire: () => lireLUnite(unite),
89
+ vivante: () => vit(pid) && !existsSync(marqueur),
90
+ finale: () => existsSync(marqueur),
91
+ noter: l => {
92
+ writeFileSync(`${marqueur}.lecture`, JSON.stringify(l));
93
+ if (part) {
94
+ signalerLeDepassement(part, base, l);
95
+ }
96
+ },
97
+ garder: l => garderLaConsommation(racine, l),
98
+ maintenant: Date.now,
99
+ dormir: () => Atomics.wait(attente, 0, 0, PERIODE_MS),
100
+ });
101
+ rmSync(marqueur, { force: true });
102
+ rmSync(`${marqueur}.lecture`, { force: true });
103
+ }
@@ -130,7 +130,7 @@ import {
130
130
  export { paquetsDuLangage };
131
131
  import { cacheDesOutils, installer, versionDeLOutil } from '../aiguillage.mjs';
132
132
  import { ouvrirBase } from '../mesure/base-de-passe.mjs';
133
- import { travailleursDe, VARIABLE_TENUE } from '../places-de-la-machine.mjs';
133
+ import { sousNiceEtIonice, travailleursDe, VARIABLE_TENUE } from '../places-de-la-machine.mjs';
134
134
  import { donneesDe } from '../donnees-cles.mjs';
135
135
  import { outilsDe } from '../outils-cles.mjs';
136
136
 
@@ -299,16 +299,6 @@ export function environnementDeLaSeance(
299
299
  };
300
300
  }
301
301
 
302
- /**
303
- * The command <commande> placed under `nice` then `ionice`, so a session of an agent yields the
304
- * CPU and the disk to the rest of the machine (its command kept whole at the end).
305
- * @param {string[]} commande
306
- * @returns {string[]}
307
- */
308
- export function sousNiceEtIonice(commande) {
309
- return ['nice', '-n', '10', 'ionice', '-c', '2', '-n', '7', ...commande];
310
- }
311
-
312
302
  /**
313
303
  * What `envelopper` launches for a session: `bwrap` with the arguments <argsBwrap> of the plan, then
314
304
  * <commande> under `nice` and `ionice`, behind the test of the variables that name a path; and the
@@ -538,8 +538,9 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
538
538
  const reste = iRole >= 0 ? tout.filter((_, i) => i !== iRole && i !== iRole + 1) : tout;
539
539
  let ecrit;
540
540
  if (geste === 'preparer' && role) {
541
- const { langageDe } = await import('../langages.mjs');
542
- ecrit = ecritPar(role, f => langageDe(copie).estUnTest(f, copie));
541
+ // The launch of a session goes on in a copy its tool no longer loads (`langageDeLaCopie`).
542
+ const { langageDeLaCopie } = await import('../langages.mjs');
543
+ ecrit = ecritPar(role, f => langageDeLaCopie(copie).estUnTest(f, copie));
543
544
  }
544
545
  const r =
545
546
  geste === 'reporter' && reste.length === 2
@@ -41,9 +41,10 @@
41
41
  // project's own an earlier update wrote (scripts/migrations/0.23.0-marche-du-projet.mjs).
42
42
  // - The status line is a setting of the project, as Husky writes the project's own configuration:
43
43
  // in a project whose `.claude/settings.json` exists, `statusLine` becomes the frame's
44
- // (`"$CLAUDE_PROJECT_DIR/node_modules/.bin/grillhouse" ligne-etat`) when it is absent or names
45
- // the frame's status line (`ligne-etat`, whatever its former form); a status line of the
46
- // project's own stays. The settings keep their other keys, in their order.
44
+ // (`"$CLAUDE_PROJECT_DIR/node_modules/.bin/grillhouse" ligne-etat`, `refreshInterval` 10: the line
45
+ // redraws on a clock, as a session at rest sends no event) when it is absent or names the
46
+ // frame's status line (`ligne-etat`, whatever its former form), which is then rewritten whole;
47
+ // a status line of the project's own stays. The settings keep their other keys, in their order.
47
48
  // - `package.json`, when there is one: the version of the frame it is brought to
48
49
  // (`grillhouse.version`, the package's version once no migration leaves anything to do), the
49
50
  // frame's npm scripts (`tableau`,
@@ -176,6 +177,9 @@ const PREPARE = 'grillhouse hooks';
176
177
 
177
178
  /** The frame's status line, as the settings of a project run it. */
178
179
  export const LIGNE_ETAT = '"$CLAUDE_PROJECT_DIR/node_modules/.bin/grillhouse" ligne-etat';
180
+ // Seconds between two redraws of the status line: at rest a session sends no event (`refreshInterval`
181
+ // of Claude Code's `statusLine`).
182
+ const REDESSIN_LIGNE_ETAT = 10;
179
183
 
180
184
  const CHAMPS_INSTALLES = ['dependencies', 'devDependencies', 'optionalDependencies'];
181
185
 
@@ -260,7 +264,7 @@ function reglerLigneEtat(projet) {
260
264
  if (actuelle !== undefined && !commande.includes('ligne-etat')) {
261
265
  return false;
262
266
  }
263
- const voulue = { type: 'command', command: LIGNE_ETAT };
267
+ const voulue = { type: 'command', command: LIGNE_ETAT, refreshInterval: REDESSIN_LIGNE_ETAT };
264
268
  if (JSON.stringify(actuelle) === JSON.stringify(voulue)) {
265
269
  return false;
266
270
  }
@@ -372,10 +372,11 @@ export const TITRE_DU_FLUX_ROUGE = '## Flux de main rouge';
372
372
  /**
373
373
  * Each reading due of the workflows of main read once, without waiting, with the tools <o> at
374
374
  * <maintenant> ms and the bounds <ci> (`rechercheMs`, `attenteMs`, from the push of main). A workflow
375
- * red (any conclusion but `success`) reopens the ticket of the commit pushed under the label
376
- * `flux-rouge`, a comment giving the address of the run, and closes the reading; green, it says
377
- * nothing; with no run past the search bound, a run unfinished past the wait bound, or `gh`
378
- * failing, a comment names the workflow and why, nothing is reopened. A reading with a workflow
375
+ * red (any conclusion but `success` and `cancelled`) reopens the ticket of the commit pushed
376
+ * under the label `flux-rouge`, a comment giving the address of the run, and closes the reading;
377
+ * green, it says nothing; with no run past the search bound, a run unfinished past the wait bound,
378
+ * a run cancelled (a later run of its concurrency group replaced it, or a person stopped it), or
379
+ * `gh` failing, a comment names the workflow and why, nothing is reopened. A reading with a workflow
379
380
  * still to come stays due. `{ dues }`: the readings still due.
380
381
  */
381
382
  export function relireLesLecturesDues(o, { maintenant, ci }) {
@@ -429,6 +430,11 @@ export function relireLesLecturesDues(o, { maintenant, ci }) {
429
430
  } else {
430
431
  encore.push(f);
431
432
  }
433
+ } else if (v.conclusion === 'cancelled') {
434
+ nonJuge(
435
+ f.nom,
436
+ `le passage ${id} a été annulé (remplacé par un passage plus récent, ou arrêté à la main).`
437
+ );
432
438
  } else if (v.conclusion !== 'success') {
433
439
  rouge = { nom: f.nom, id };
434
440
  break;