@roomi-fields/grillhouse 0.24.2 → 0.24.4

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.
@@ -9,7 +9,9 @@
9
9
  // judge (`aVerifier` of scripts/interfaces-contre-code.mjs; in an envelope,
10
10
  // `GRILLHOUSE_ENVELOPPE`, the components of its plan), each list line (`- …`) of the
11
11
  // `## Consommateurs` section of its `docs/INTERFACE.md` in the working tree that the section of
12
- // HEAD does not hold is a changed line (an interface absent from HEAD: all its lines). Out of a
12
+ // HEAD does not hold is a changed line (an interface absent from HEAD: all its lines). The
13
+ // section is read out of the generated part (between the marks of
14
+ // scripts/interfaces-contre-code.mjs): a bullet of an element's entry is no consumer. Out of a
13
15
  // branch `agent/…` (main, the detached copy of the integration, the CI, the night), there is no
14
16
  // lot: nothing is judged.
15
17
  // - With a changed line, the comments of the ticket are read (`bd comments <ticket> --json`, run
@@ -18,20 +20,24 @@
18
20
  // `estArbitrage`, its verdict « tranché » or the owner's answer after it) names its consumer, the first
19
21
  // name between backquotes of the line, found as it is in the comment's text. Without a changed
20
22
  // line, bd is not called.
21
- // - A changed line no arbitrage settles passes too when the section « Architecture » of the
22
- // ticket's description (`bd show <ticket> --json`, from its heading `## Architecture` to the
23
- // next heading of its level or above) names its consumer and each name the line declares, word
24
- // for word (`nommeParLArchitecture`): the ticket fixed them before the lot. The description is
25
- // read only for such a line; a description that cannot be read refuses, as the comments do.
26
- // - A refusal names `<INTERFACE.md> § Consommateurs` and the line; a refusal inscribed in the
27
- // project's debt (`grillhouse-dette.json`, see `dette.mjs`) passes, keyed by the interface and
28
- // `consommateur-sans-arbitrage`. Comments that cannot be read refuse, never inscribed.
23
+ // - A changed line no arbitrage settles passes too when the ticket's plan (`bd show <ticket>
24
+ // --json`: its title, and the sections « Architecture » and « Noms publiés » of its description,
25
+ // each from its heading to the next heading of its level or above; never the rest of the
26
+ // description, where a question or a criterion can name what the ticket keeps out) names its
27
+ // consumer and each name the lot adds to the line, word for word (`nonNommes`): the names HEAD's
28
+ // section already gives that consumer were settled before. The plan fixed them before the lot,
29
+ // as a code owner's approval covers what it reviewed. The plan is read only for such a line; one
30
+ // that cannot be read refuses, as the comments do.
31
+ // - A refusal names `<INTERFACE.md> § Consommateurs`, the line and the names the plan misses; a
32
+ // refusal inscribed in the project's debt (`grillhouse-dette.json`, see `dette.mjs`) passes,
33
+ // keyed by the interface and `consommateur-sans-arbitrage`. Comments that cannot be read refuse,
34
+ // never inscribed.
29
35
  import { spawnSync } from 'node:child_process';
30
36
  import { existsSync, readFileSync } from 'node:fs';
31
37
  import path from 'node:path';
32
38
  import { pathToFileURL } from 'node:url';
33
39
  import { trancher } from './dette.mjs';
34
- import { aVerifier } from './interfaces-contre-code.mjs';
40
+ import { aVerifier, marques } from './interfaces-contre-code.mjs';
35
41
 
36
42
  const REGLE = 'consommateur-sans-arbitrage';
37
43
 
@@ -40,60 +46,72 @@ const REGLE = 'consommateur-sans-arbitrage';
40
46
  // règles »).
41
47
  export const estArbitrage = text => /^\s*## Arbitrage\b/.test(String(text ?? ''));
42
48
 
49
+ // True when the text <text> of a comment is the owner's answer, « ## Réponse du responsable — <la
50
+ // question> », as the supervisor writes it (the skill pitmaster).
51
+ export const estReponseDuResponsable = text =>
52
+ /^\s*## Réponse du responsable\b/.test(String(text ?? ''));
53
+
43
54
  // True when the arbitrage <a> of <comments> (Beads' JSON, in their order) is settled: a line
44
55
  // `### Verdict — tranché`, or a « ## Réponse du responsable » comment after it.
45
56
  export function arbitrageTranche(comments, a) {
46
57
  const tranche = /^### Verdict\s*—\s*tranché/m.test(a.text);
47
58
  return (
48
- tranche ||
49
- comments
50
- .slice(comments.indexOf(a) + 1)
51
- .some(c => /^\s*## Réponse du responsable\b/.test(c.text))
59
+ tranche || comments.slice(comments.indexOf(a) + 1).some(c => estReponseDuResponsable(c.text))
52
60
  );
53
61
  }
54
62
 
55
- // The list lines of the section `## Consommateurs` of <texte>, trimmed.
63
+ // The list lines of the section `## Consommateurs` of <texte>, trimmed, read out of its generated
64
+ // part (`marques`, scripts/interfaces-contre-code.mjs): a bullet the generator writes there (a
65
+ // parameter, a member, a fault) is never a consumer.
56
66
  function lignesConsommateurs(texte) {
67
+ const m = marques(texte);
68
+ const ecrites =
69
+ m.etat === 'ok' ? [...m.lignes.slice(0, m.debut), ...m.lignes.slice(m.fin + 1)] : m.lignes;
57
70
  const out = [];
58
71
  let dedans = false;
59
- for (const l of texte.split('\n')) {
72
+ for (const l of ecrites) {
60
73
  if (/^##\s/.test(l)) dedans = /^##\s+Consommateurs\s*$/.test(l);
61
74
  else if (dedans && /^\s*-\s+\S/.test(l)) out.push(l.trim());
62
75
  }
63
76
  return out;
64
77
  }
65
78
 
66
- // The section « Architecture » of the ticket's description <description>: its lines from its
67
- // heading (`## Architecture`) to the next heading of its level or above, or '' without one.
68
- function sectionArchitecture(description) {
79
+ // The section of the ticket's description <description> whose heading's text <titre> matches:
80
+ // its lines from its heading to the next heading of its level or above, or '' without one.
81
+ function section(description, titre) {
69
82
  const out = [];
70
83
  let niveau = 0;
71
84
  for (const l of String(description ?? '').split('\n')) {
72
- const titre = /^(#{1,6})\s+(.*)$/.exec(l);
73
- if (niveau && titre && titre[1].length <= niveau) break;
85
+ const t = /^(#{1,6})\s+(.*)$/.exec(l);
86
+ if (niveau && t && t[1].length <= niveau) break;
74
87
  if (niveau) out.push(l);
75
- else if (titre && /^Architecture\b/.test(titre[2].trim())) niveau = titre[1].length;
88
+ else if (t && titre.test(t[2].trim())) niveau = t[1].length;
76
89
  }
77
90
  return out.join('\n');
78
91
  }
79
92
 
80
- // Whether the text <texte> names the consumer and each name of the `## Consommateurs` line
81
- // <ligne> (``- `<consommateur>` : <nom>, <nom>``), word for word: each one whole, with no
82
- // character of a name (a letter, a digit, `_`, `$`, `-`) beside it; `*`, a namespace, between
83
- // backquotes.
84
- function nommeParLArchitecture(texte, ligne) {
93
+ // The consumer and the names of the `## Consommateurs` line <ligne>
94
+ // (``- `<consommateur>` : <nom>, <nom>``), or null for a line of another form.
95
+ function lireLigne(ligne) {
85
96
  const m = /^[-*]\s+`?([^`:\s]+)`?\s*:\s*(.+)$/.exec(ligne);
86
- if (!m) return false;
97
+ if (!m) return null;
87
98
  const noms = m[2]
88
99
  .split(',')
89
100
  .map(s => s.replace(/`/g, '').trim())
90
101
  .filter(Boolean);
102
+ return { consommateur: m[1], noms };
103
+ }
104
+
105
+ // The names of <noms> the text <texte> does not name word for word: each one whole, with no
106
+ // character of a name (a letter, a digit, `_`, `$`, `-`) beside it; `*`, a namespace, between
107
+ // backquotes.
108
+ function nonNommes(texte, noms) {
91
109
  const echappe = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
92
110
  const nomme = nom =>
93
111
  nom === '*'
94
112
  ? texte.includes('`*`')
95
113
  : new RegExp(`(?<![\\w$-])${echappe(nom)}(?![\\w$-])`).test(texte);
96
- return [m[1], ...noms].every(nomme);
114
+ return noms.filter(n => !nomme(n));
97
115
  }
98
116
 
99
117
  const git = (racine, ...a) => spawnSync('git', ['-C', racine, ...a], { encoding: 'utf8' });
@@ -115,9 +133,19 @@ export function verifier(racine, env = process.env) {
115
133
  if (!existsSync(iface)) continue;
116
134
  const rel = path.relative(racine, iface);
117
135
  const head = git(racine, 'show', `HEAD:${rel}`);
118
- const avant = new Set(head.status === 0 ? lignesConsommateurs(head.stdout) : []);
136
+ const lignesAvant = head.status === 0 ? lignesConsommateurs(head.stdout) : [];
137
+ const avant = new Set(lignesAvant);
138
+ // The names each consumer of HEAD's section reads.
139
+ const nomsAvant = new Map();
140
+ for (const l of lignesAvant.map(lireLigne).filter(Boolean)) {
141
+ nomsAvant.set(l.consommateur, new Set([...(nomsAvant.get(l.consommateur) ?? []), ...l.noms]));
142
+ }
119
143
  for (const ligne of lignesConsommateurs(readFileSync(iface, 'utf8'))) {
120
- if (!avant.has(ligne)) changees.push({ rel, ligne });
144
+ if (avant.has(ligne)) continue;
145
+ const lue = lireLigne(ligne);
146
+ const deja = lue && nomsAvant.get(lue.consommateur);
147
+ const ajoutes = lue ? lue.noms.filter(n => !deja?.has(n)) : null;
148
+ changees.push({ rel, ligne, lue, ajoutes });
121
149
  }
122
150
  }
123
151
  if (changees.length === 0) return [];
@@ -145,18 +173,24 @@ export function verifier(racine, env = process.env) {
145
173
  ({ ligne }) => !arbitrages.some(a => a.text.includes(consommateurDe(ligne)))
146
174
  );
147
175
  if (restantes.length === 0) return [];
148
- // The lines no arbitrage settles: the section « Architecture » of the ticket.
176
+ // The lines no arbitrage settles: the ticket's plan, its title and its sections « Architecture »
177
+ // and « Noms publiés ».
149
178
  const show = spawnSync('bd', ['show', ticket, '--json'], {
150
179
  cwd: principal,
151
180
  encoding: 'utf8',
152
181
  maxBuffer: 256 * 1024 * 1024,
153
182
  });
154
- let architecture;
183
+ let plan;
155
184
  try {
156
185
  if (show.status !== 0) {
157
186
  throw new Error(show.stderr || show.error?.message || `code ${show.status}`);
158
187
  }
159
- architecture = sectionArchitecture(JSON.parse(show.stdout || '[]')?.[0]?.description);
188
+ const t = JSON.parse(show.stdout || '[]')?.[0];
189
+ plan = [
190
+ t?.title ?? '',
191
+ section(t?.description, /^Architecture\b/),
192
+ section(t?.description, /^Noms publiés\b/),
193
+ ].join('\n');
160
194
  } catch (e) {
161
195
  return [
162
196
  {
@@ -165,13 +199,17 @@ export function verifier(racine, env = process.env) {
165
199
  ];
166
200
  }
167
201
  const constats = [];
168
- for (const { rel, ligne } of restantes) {
169
- if (nommeParLArchitecture(architecture, ligne)) continue;
202
+ for (const { rel, ligne, lue, ajoutes } of restantes) {
203
+ const manquants = lue ? nonNommes(plan, [lue.consommateur, ...ajoutes]) : null;
204
+ if (manquants?.length === 0) continue;
170
205
  const consommateur = consommateurDe(ligne);
206
+ const dit = manquants
207
+ ? ` ; le plan ne nomme pas ${manquants.map(n => `\`${n}\``).join(', ')}`
208
+ : '';
171
209
  constats.push({
172
210
  fichier: rel,
173
211
  regle: REGLE,
174
- message: `${rel} § Consommateurs : la ligne « ${ligne} » change sans arbitrage tranché au ticket ${ticket} qui nomme \`${consommateur}\`, ni section « Architecture » du ticket qui nomme ce consommateur et chaque nom de la ligne ; une dépendance entre composants se décide avant de s'écrire : un commentaire « ## Arbitrage » tranché au ticket qui nomme ce consommateur, ou l'Architecture du ticket qui la fixe.`,
212
+ message: `${rel} § Consommateurs : la ligne « ${ligne} » change sans arbitrage tranché au ticket ${ticket} qui nomme \`${consommateur}\`, ni plan du ticket (son titre, sa section « Architecture », sa section « Noms publiés ») qui nomme ce consommateur et chaque nom que le lot ajoute à la ligne${dit} ; une dépendance entre composants se décide avant de s'écrire : un commentaire « ## Arbitrage » tranché au ticket qui nomme ce consommateur, ou le plan du ticket qui la fixe.`,
175
213
  });
176
214
  }
177
215
  return constats;
@@ -8,11 +8,15 @@
8
8
  // - `c` : *
9
9
  //
10
10
  // This check reads what the production code of every component imports from every other, and
11
- // refuses (exit 1) a use that the provider's interface does not declare. A declared use that no
12
- // code makes is reported, without refusing. `*` stands for a namespace, default, re-export-all or
13
- // side-effect import. A refusal inscribed in the project's debt (`grillhouse-dette.json`, see
14
- // `dette.mjs`) passes, keyed by the provider's interface and `usage-non-declare` (`homonyme` for
15
- // two components of one name, keyed by the first path).
11
+ // refuses (exit 1) a use that the provider's interface does not declare, and a declared name that
12
+ // no code of its consumer uses, as ESLint's `no-unused-vars` refuses a name nothing uses (BP
13
+ // 320.3.2.1: « LEVEL_TYPES » declared for 020-loader, only reported, caught by its second review).
14
+ // `*` stands for a namespace, default, re-export-all or side-effect import. A refusal inscribed in
15
+ // the project's debt (`grillhouse-dette.json`, see `dette.mjs`) passes, keyed by the provider's
16
+ // interface and `usage-non-declare` or `declare-non-utilise` (`homonyme` for two components of one
17
+ // name, keyed by the first path). The debt of the new rule is inscribed once, when a project
18
+ // updates to it (scripts/migrations/0.24.4-noms-declares-inutilises.mjs); in a ticket, the name
19
+ // leaves its line.
16
20
  //
17
21
  // npx grillhouse consommateurs run from the repository root
18
22
  //
@@ -244,6 +248,10 @@ export function utilise(racine, tous = composants(racine)) {
244
248
  return out;
245
249
  }
246
250
 
251
+ // The rule of a declared name that no code of its consumer uses; its finding names its consumer
252
+ // and the name, which the migration of 0.24.4 reports line by line.
253
+ export const DECLARE_NON_UTILISE = 'declare-non-utilise';
254
+
247
255
  // The refusals of the components that share a name: one finding per name, both paths.
248
256
  function homonymes(racine) {
249
257
  const parNom = new Map();
@@ -259,15 +267,15 @@ function homonymes(racine) {
259
267
  }));
260
268
  }
261
269
 
262
- // The refusals (uses no interface declares), as findings `{ fichier, regle, message }` the debt
263
- // (`dette.mjs`) judges, and the reports (declared uses no code makes). A declared consumer out of
264
- // the frame is passed over: its code is not read.
270
+ // The refusals, as findings `{ fichier, regle, message }` the debt (`dette.mjs`) judges: the uses
271
+ // no interface declares (`usage-non-declare`), and the declared names no code of their consumer
272
+ // uses (`declare-non-utilise`). A declared consumer out of the frame is passed over: its code is
273
+ // not read.
265
274
  export function verifier(racine) {
266
275
  const tous = composants(racine);
267
276
  const hors = horsCadre(racine);
268
277
  const reel = utilise(racine, tous);
269
278
  const refus = homonymes(racine);
270
- const signaux = [];
271
279
  for (const p of tous) {
272
280
  const iface = path.join(p.dir, 'docs', 'INTERFACE.md');
273
281
  const rel = path.relative(racine, iface);
@@ -289,26 +297,34 @@ export function verifier(racine) {
289
297
  const faits = utilises.get(consommateur) ?? new Set();
290
298
  for (const n of noms) {
291
299
  if (!faits.has(n))
292
- signaux.push(
293
- `${rel} déclare « ${n} » pour ${consommateur}, qu'aucun code de ${consommateur} n'utilise.`
294
- );
300
+ refus.push({
301
+ fichier: rel,
302
+ regle: DECLARE_NON_UTILISE,
303
+ consommateur,
304
+ nom: n,
305
+ message: `${rel} déclare « ${n} » pour ${consommateur}, qu'aucun code de ${consommateur} n'utilise.`,
306
+ });
295
307
  }
296
308
  }
297
309
  }
298
- return { refus, signaux };
310
+ return { refus };
299
311
  }
300
312
 
301
313
  if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
302
314
  const racine = process.cwd();
303
315
  const verdict = verifier(racine);
304
316
  const { refus, lignes } = trancher(racine, 'consommateurs', verdict.refus);
305
- for (const s of verdict.signaux) process.stderr.write(`⚠️ ${s}\n`);
306
317
  for (const r of refus) process.stderr.write(`⛔ ${r.message}\n`);
307
318
  for (const l of lignes) process.stderr.write(`${l}\n`);
308
- if (refus.length) {
319
+ if (refus.some(r => r.regle !== DECLARE_NON_UTILISE)) {
320
+ process.stderr.write(
321
+ "Une consommation nouvelle se décide (le titre du ticket, sa section « Architecture » ou sa section « Noms publiés » qui la nomment, sinon l'arbitrage du superviseur), puis entre dans la section « Consommateurs » de l'interface du fournisseur.\n"
322
+ );
323
+ }
324
+ if (refus.some(r => r.regle === DECLARE_NON_UTILISE)) {
309
325
  process.stderr.write(
310
- "Une consommation nouvelle se décide (la section « Architecture » du ticket qui la nomme, sinon l'arbitrage du superviseur), puis entre dans la section « Consommateurs » de l'interface du fournisseur.\n"
326
+ "Un nom que son consommateur n'utilise plus sort de sa ligne dans la section « Consommateurs » de l'interface du fournisseur.\n"
311
327
  );
312
- process.exitCode = 1;
313
328
  }
329
+ if (refus.length) process.exitCode = 1;
314
330
  }
@@ -0,0 +1,138 @@
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).
4
+ //
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
+ // - The caller (no variable): it launches a relay, its own script again, in a session of its own,
9
+ // and waits for it; then it reads the daemon's output in a directory of its own
10
+ // (`<tmpdir>/grillhouse-sortie-du-circuit-XXXXXX`, apart from the bases of the runs, which a sweep
11
+ // reads) and relays it to its own streams while it waits, every PAS_MS; once the daemon's code is
12
+ // 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.
15
+ // - The relay: it launches the daemon, its own script again, in a session of its own (setsid), its
16
+ // output to the directory, writes its pid there and ends at once: the daemon's parent becomes the
17
+ // 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.
19
+ // - 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';
22
+ import {
23
+ existsSync,
24
+ mkdtempSync,
25
+ openSync,
26
+ readFileSync,
27
+ renameSync,
28
+ rmSync,
29
+ writeFileSync,
30
+ } from 'node:fs';
31
+ import os from 'node:os';
32
+ import path from 'node:path';
33
+ import { vivant } from './vitest-config/base-de-passe.mjs';
34
+
35
+ // The variable that carries, to the relay and then to the daemon, its role, the directory of the
36
+ // daemon's output and the caller's process.
37
+ const DETACHE = 'GRILLHOUSE_CIRCUIT_DETACHE';
38
+ // How often the caller reads the daemon's output and end.
39
+ const PAS_MS = 100;
40
+
41
+ const lire = f => (existsSync(f) ? readFileSync(f, 'utf8') : '');
42
+
43
+ // The caller: see the header.
44
+ async function appeler(script, argv) {
45
+ const dossier = mkdtempSync(path.join(os.tmpdir(), 'grillhouse-sortie-du-circuit-'));
46
+ const f = nom => path.join(dossier, nom);
47
+ try {
48
+ const relais = spawn(process.execPath, [script, ...argv], {
49
+ detached: true,
50
+ stdio: 'ignore',
51
+ env: {
52
+ ...process.env,
53
+ [DETACHE]: JSON.stringify({ role: 'relais', dossier, appelant: process.pid }),
54
+ },
55
+ });
56
+ await new Promise(r => {
57
+ relais.on('error', r);
58
+ relais.on('close', r);
59
+ });
60
+ const pid = Number(lire(f('pid')));
61
+ const lus = { sortie: 0, erreurs: 0 };
62
+ const recopier = () => {
63
+ for (const [nom, flux] of [
64
+ ['sortie', process.stdout],
65
+ ['erreurs', process.stderr],
66
+ ]) {
67
+ if (!existsSync(f(nom))) {
68
+ continue;
69
+ }
70
+ const tout = readFileSync(f(nom));
71
+ if (tout.length > lus[nom]) {
72
+ flux.write(tout.subarray(lus[nom]));
73
+ }
74
+ lus[nom] = tout.length;
75
+ }
76
+ };
77
+ for (;;) {
78
+ // The code is written after the last line: once it is there, the output is read to its end.
79
+ const fini = existsSync(f('code'));
80
+ recopier();
81
+ if (fini) {
82
+ return Number(lire(f('code')));
83
+ }
84
+ if (!pid || !vivant(pid)) {
85
+ recopier();
86
+ if (existsSync(f('code'))) {
87
+ return Number(lire(f('code')));
88
+ }
89
+ process.stderr.write(`⛔ le circuit (processus ${pid || '?'}) finit sans code de fin.\n`);
90
+ return 1;
91
+ }
92
+ await new Promise(r => setTimeout(r, PAS_MS));
93
+ }
94
+ } finally {
95
+ rmSync(dossier, { recursive: true, force: true });
96
+ }
97
+ }
98
+
99
+ // The relay: see the header.
100
+ function relayer(script, argv, { dossier, appelant }) {
101
+ const sortie = openSync(path.join(dossier, 'sortie'), 'a');
102
+ const erreurs = openSync(path.join(dossier, 'erreurs'), 'a');
103
+ const demon = spawn(process.execPath, [script, ...argv], {
104
+ detached: true,
105
+ stdio: ['ignore', sortie, erreurs],
106
+ env: { ...process.env, [DETACHE]: JSON.stringify({ role: 'demon', dossier, appelant }) },
107
+ });
108
+ writeFileSync(path.join(dossier, 'pid'), String(demon.pid ?? ''));
109
+ demon.unref();
110
+ return 0;
111
+ }
112
+
113
+ // The daemon: see the header.
114
+ async function demon(argv, main, { dossier, appelant }) {
115
+ process.on('exit', code => {
116
+ if (!vivant(appelant)) {
117
+ rmSync(dossier, { recursive: true, force: true });
118
+ return;
119
+ }
120
+ const provisoire = path.join(dossier, `code.${process.pid}`);
121
+ writeFileSync(provisoire, String(code ?? 1));
122
+ renameSync(provisoire, path.join(dossier, 'code'));
123
+ });
124
+ return await main(argv);
125
+ }
126
+
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) {
129
+ const lu = process.env[DETACHE] ? JSON.parse(process.env[DETACHE]) : null;
130
+ delete process.env[DETACHE];
131
+ if (lu?.role === 'relais') {
132
+ return relayer(script, argv, lu);
133
+ }
134
+ if (lu?.role === 'demon') {
135
+ return await demon(argv, main, lu);
136
+ }
137
+ return await appeler(script, argv);
138
+ }
@@ -128,6 +128,12 @@ export const ARRETS = {
128
128
  export const EXPLORATEUR = 'explorateur';
129
129
  export const QUESTIONNEUR = 'questionneur';
130
130
 
131
+ // A role by its agent's name: an agent of the frame's plugin is named bare or scoped by the
132
+ // plugin (`grillhouse:<rôle>`), as Claude Code names a plugin's agents and the register writes
133
+ // them; the board and the bilan read a role this one way.
134
+ export const roleDeLAgent = nom =>
135
+ typeof nom === 'string' ? nom.replace(/^grillhouse:/, '') : null;
136
+
131
137
  // A role in words.
132
138
  const NOMS = { developpeur: 'développeur' };
133
139
  export const nomDuRole = role => NOMS[role] ?? role;
@@ -248,7 +254,7 @@ export const MONTEES = Object.fromEntries(
248
254
  questionnement:
249
255
  'Des questions du plan restent ouvertes après la réponse de l’explorateur : le plan change-t-il (`bd update`), ou reste-t-il tel quel ? `--reprendre` le fait passer tel qu’il est alors.',
250
256
  references:
251
- 'La régénération des références change une référence du projet que le plan ne nomme pas, un fichier qu’aucune référence n’écrit, ou sa commande échoue : le plan les nomme-t-il, ou qui corrige le lot ?',
257
+ 'La régénération des références change un fichier qu’aucune référence n’écrit, ou sa commande échoue (ses écarts ci-dessus) : qui corrige la référence ou le lot ?',
252
258
  'hors-plan':
253
259
  'La séance écrit hors du plan du ticket : le plan s’étend-il à ce paquet (`--etendre`), ou l’écriture est-elle refusée (`--reprendre` avec son contexte) ?',
254
260
  }).map(([arret, question]) => [arret, { question: `${question} ${REPONSES}`, qui: SUPERVISEUR }])
@@ -16,7 +16,8 @@
16
16
  // `RENDU` at the start of a comment of the author `relecteur`; another author's is none) and, when labelled `arbitrage`, each arbitrage
17
17
  // (`estArbitrage`: a « ## Arbitrage » comment, the supervisor's) is settled
18
18
  // (`arbitrageTranche`: `### Verdict — tranché`, or a « ## Réponse du
19
- // responsable » comment after it);
19
+ // responsable » comment after it): `refusArbitrage`, the one rule of the label, which the
20
+ // circuit plays too at its launch and at each resumption (scripts/circuit.mjs);
20
21
  // 2. the lots: the tests lot touches only what the testwriter writes (`isTesterFile`: test files
21
22
  // and the shared test material), the code lot none of it;
22
23
  // 3. the main tree: every file of the lots is unmodified there; the ticket's copy is on its
@@ -107,15 +108,24 @@ export function refusVerdicts(ticket, comments) {
107
108
  if (verdictDe(dernier) !== 'ACCEPTÉ') {
108
109
  return `${id} n'a pas le verdict ACCEPTÉ du relecteur pour dernier verdict.`;
109
110
  }
110
- if ((ticket.labels ?? []).includes('arbitrage')) {
111
- const arbitrages = comments.filter(c => estArbitrage(c.text));
112
- if (arbitrages.length === 0)
113
- return `${id} est étiqueté arbitrage sans commentaire « Arbitrage ».`;
114
- for (const a of arbitrages) {
115
- if (!arbitrageTranche(comments, a)) {
116
- const titre = a.text.trim().split('\n')[0];
117
- return `${id} : « ${titre} » n'est ni tranché ni répondu par le responsable.`;
118
- }
111
+ return refusArbitrage(ticket, comments);
112
+ }
113
+
114
+ // The refusal for the arbitrage of one ticket, or null: a ticket labelled `arbitrage` holds a
115
+ // « ## Arbitrage » comment, and each one is settled or answered by the owner. The one rule of the
116
+ // label, which the integration plays after the verdict and the circuit at its launch and at each
117
+ // resumption (scripts/circuit.mjs), as a CI refuses a pull request without its required label
118
+ // before it runs a job. `ticket` and `comments` are Beads' JSON.
119
+ export function refusArbitrage(ticket, comments) {
120
+ if (!(ticket.labels ?? []).includes('arbitrage')) return null;
121
+ const id = ticket.id;
122
+ const arbitrages = comments.filter(c => estArbitrage(c.text));
123
+ if (arbitrages.length === 0)
124
+ return `${id} est étiqueté arbitrage sans commentaire « Arbitrage ».`;
125
+ for (const a of arbitrages) {
126
+ if (!arbitrageTranche(comments, a)) {
127
+ const titre = a.text.trim().split('\n')[0];
128
+ return `${id} : « ${titre} » n'est ni tranché ni répondu par le responsable.`;
119
129
  }
120
130
  }
121
131
  return null;
@@ -0,0 +1,48 @@
1
+ // From 0.24.4 the guard of the consumers refuses a declared name that no code of its consumer uses
2
+ // (`declare-non-utilise`, scripts/consommateurs.mjs), which it only reported before, as ESLint's
3
+ // `no-unused-vars` refuses a name nothing uses. A project that updates holds such names already
4
+ // (BPScript: 26 names on 11 lines of 4 interfaces), and its main would turn red at its next pass
5
+ // without a word. As a codemod reports what it leaves, the update names them, and the command that
6
+ // inscribes them as the project's known debt, once, at the passage of the rule (dette.mjs, as
7
+ // ESLint's `--suppress-all`); in a ticket afterwards, the guard says to take the name out of its
8
+ // line.
9
+ //
10
+ // - The migration changes no file (`migrer` returns no line): the project decides between the
11
+ // debt and the edit of its interfaces.
12
+ // - What stays to the project (`restes`): one line per line of a `## Consommateurs` section that
13
+ // declares names its consumer does not use, beyond what `grillhouse-dette.json` already inscribes
14
+ // (`juger` of dette.mjs), its interface, its consumer and those names; then the line of the
15
+ // command, `npm run grillhouse:dette:inscrire`. Nothing once the debt holds them, or once the
16
+ // names are gone.
17
+ import { juger, lire } from '../dette.mjs';
18
+ import { DECLARE_NON_UTILISE, verifier } from '../consommateurs.mjs';
19
+
20
+ export const version = '0.24.4';
21
+ export const nom = 'noms déclarés inutilisés';
22
+
23
+ /** The lines of the declared names the new rule refuses in the project at <projet>, and the command. */
24
+ export function restes(projet) {
25
+ const constats = verifier(projet).refus.filter(r => r.regle === DECLARE_NON_UTILISE);
26
+ const { refus } = juger(lire(projet), 'consommateurs', constats);
27
+ if (refus.length === 0) {
28
+ return [];
29
+ }
30
+ const parLigne = new Map();
31
+ for (const r of refus) {
32
+ const cle = `${r.fichier}\0${r.consommateur}`;
33
+ parLigne.set(cle, [...(parLigne.get(cle) ?? []), r.nom]);
34
+ }
35
+ const lignes = [...parLigne].map(([cle, noms]) => {
36
+ const [fichier, consommateur] = cle.split('\0');
37
+ return `${fichier} § Consommateurs, \`${consommateur}\` : ${noms.join(', ')}, qu'aucun code de ${consommateur} n'utilise`;
38
+ });
39
+ return [
40
+ ...lignes,
41
+ `la garde des consommateurs refuse désormais ces ${refus.length} noms : \`npm run grillhouse:dette:inscrire\` les inscrit dans grillhouse-dette.json, la dette connue du projet, ou chaque nom sort de sa ligne`,
42
+ ];
43
+ }
44
+
45
+ /** Changes nothing: the names are reported by `restes`. */
46
+ export function migrer() {
47
+ return [];
48
+ }
@@ -26,6 +26,7 @@ import * as marcheDuProjet from './migrations/0.23.0-marche-du-projet.mjs';
26
26
  import * as copiesDuCadre from './migrations/0.23.2-copies-du-cadre.mjs';
27
27
  import * as circuitSimplifie from './migrations/0.24.0-circuit-simplifie.mjs';
28
28
  import * as apiExtractorDuPaquet from './migrations/0.24.2-api-extractor-du-paquet.mjs';
29
+ import * as nomsDeclaresInutilises from './migrations/0.24.4-noms-declares-inutilises.mjs';
29
30
 
30
31
  /** The migrations of the package. */
31
32
  export const MIGRATIONS = [
@@ -36,6 +37,7 @@ export const MIGRATIONS = [
36
37
  copiesDuCadre,
37
38
  circuitSimplifie,
38
39
  apiExtractorDuPaquet,
40
+ nomsDeclaresInutilises,
39
41
  ];
40
42
 
41
43
  /**
@@ -10,8 +10,12 @@
10
10
  // reads in CLAUDE_PROJECT_DIR, else in its input's `cwd`), the agent, its ticket (« TON TICKET : »),
11
11
  // its role,
12
12
  // its start and end, its working time and the turns it sums (start and end in milliseconds, the
13
- // waits for a message left out), its tokens, its cache reads and its cost when the session wrote
14
- // one. All of it is read from the agent's transcript; the agent declares nothing.
13
+ // waits for a message left out), its tokens, its cache reads and its cost. All of it is read from
14
+ // the agent's transcript; the agent declares nothing.
15
+ // - The cost is the total the session writes, as ccusage keeps it; without one, or with a total of
16
+ // 0 for tokens spent (a sub-agent's transcript holds none), it is the usage of each model at its
17
+ // tariff (`TARIFS`), as Claude Code reckons it. A model without a tariff that spent tokens leaves
18
+ // such a cost unknown (null).
15
19
  // - The register is `~/.claude/grillhouse/registre.jsonl` (GRILLHOUSE_REGISTRE replaces it): the
16
20
  // envelope of a role agent leaves it writable.
17
21
  // - A hook never stops the session, and never waits for a transcript: it hands the fields of its
@@ -36,7 +40,8 @@ import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync } from
36
40
  import os from 'node:os';
37
41
  import path from 'node:path';
38
42
  import { pathToFileURL } from 'node:url';
39
- import { lireFichier, ROLE_DU_CIRCUIT, roleDeLAgent, roleDuMeta, tourne } from './tableau.mjs';
43
+ import { roleDeLAgent } from './etapes.mjs';
44
+ import { lireFichier, ROLE_DU_CIRCUIT, roleDuMeta, tourne } from './tableau.mjs';
40
45
  import { lacherVerrou, prendreVerrou } from './verrou-de-fichier.mjs';
41
46
 
42
47
  const REGISTRE =
@@ -77,6 +82,34 @@ export function source(input) {
77
82
  };
78
83
  }
79
84
 
85
+ // The tariffs of the models the frame's agents run on, in dollars per million tokens: the input,
86
+ // the output, a read of the cache, a write of the cache kept five minutes, and one kept an hour.
87
+ // Those of Sonnet 5.5 and Opus 5.5 give the total Claude Code wrote for each of the 25 sessions of
88
+ // BPScript 320.8, to the thousandth.
89
+ export const TARIFS = {
90
+ 'claude-sonnet-5-5': { entree: 2, sortie: 10, lecture: 0.1, ecriture5m: 2.5, ecriture1h: 4 },
91
+ 'claude-opus-5-5': { entree: 4, sortie: 20, lecture: 0.2, ecriture5m: 5, ecriture1h: 8 },
92
+ 'claude-haiku-4-5': { entree: 1, sortie: 5, lecture: 0.1, ecriture5m: 1.25, ecriture1h: 2 },
93
+ };
94
+
95
+ // The cost of the usage by model <modeles> (`{ <modèle>: { entree, sortie, lecture, ecriture5m,
96
+ // ecriture1h } }`, tokens), or null when a model without a tariff spent tokens.
97
+ export function coutDe(modeles) {
98
+ let cout = 0;
99
+ for (const [modele, u] of Object.entries(modeles ?? {})) {
100
+ const parts = Object.entries(u);
101
+ if (parts.every(([, n]) => !n)) {
102
+ continue;
103
+ }
104
+ const tarif = TARIFS[modele];
105
+ if (!tarif) {
106
+ return null;
107
+ }
108
+ cout += parts.reduce((m, [k, n]) => m + n * (tarif[k] ?? 0), 0) / 1e6;
109
+ }
110
+ return cout;
111
+ }
112
+
80
113
  // The register's line for this hook input and the reading `t` of its transcript (`lireFichier` or
81
114
  // `lireTranscription`), or null. `projet` is the main tree of the session.
82
115
  export function ligne(input, t, projet) {
@@ -95,7 +128,8 @@ export function ligne(input, t, projet) {
95
128
  tours: t.tours,
96
129
  jetons: t.jetons,
97
130
  cache: t.cache,
98
- cout: t.cout,
131
+ // The total the session wrote; none, or 0, reckoned on its tokens (0 without any).
132
+ cout: t.cout || coutDe(t.modeles),
99
133
  };
100
134
  }
101
135