@roomi-fields/grillhouse 0.24.2 → 0.24.3

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;
@@ -307,7 +307,7 @@ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
307
307
  for (const l of lignes) process.stderr.write(`${l}\n`);
308
308
  if (refus.length) {
309
309
  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"
310
+ "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"
311
311
  );
312
312
  process.exitCode = 1;
313
313
  }
@@ -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;
@@ -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
 
@@ -46,6 +46,9 @@
46
46
  // keeps as they are; the packages in the title as it names its components (a package name or a
47
47
  // path), the list the envelope of every later session writes; the open questions, a change or
48
48
  // a removal of a criterion written among them, go up to the supervisor (explorateur);
49
+ // - `ecartes` (`composant`, `raison`): the components of the survey the plan does not touch,
50
+ // which the circuit writes at the ticket; each other component of the survey the circuit
51
+ // plays is in the packages (explorateur);
49
52
  // - `reponses` (`numero` of the question, `reponse` CHANGE or GARDE, `texte`): the explorateur's
50
53
  // one answer to the questionneur, which the circuit writes at the ticket; a question without
51
54
  // an answer stays open (explorateur);
@@ -167,6 +170,16 @@ const FICHES = {
167
170
  texte('Un paquet, comme le titre le nomme : le nom de son paquet, ou son chemin.'),
168
171
  'Les paquets à toucher, le fournisseur d’abord ; le circuit les écrit au titre, et chaque séance n’écrit qu’eux.'
169
172
  ),
173
+ ecartes: liste(
174
+ objet(
175
+ {
176
+ composant: texte('Un composant du relevé, comme le relevé le nomme.'),
177
+ raison: texte('Pourquoi le plan n’y touche pas.'),
178
+ },
179
+ ['composant', 'raison']
180
+ ),
181
+ 'Les composants du relevé que le plan ne touche pas, chacun avec sa raison ; chaque autre composant du relevé est dans tes paquets.'
182
+ ),
170
183
  questions: liste(
171
184
  objet(
172
185
  {
@@ -17,9 +17,9 @@
17
17
  // roles of the flow that ran on it and the reviewer's last verdict (`ACCEPTÉ` or `RENDU` at the
18
18
  // start of a comment).
19
19
  // - Circuits: one entry per open ticket whose circuit (scripts/circuit.mjs) runs or stopped, read
20
- // in its state `.claude/worktrees/<ticket>.circuit.json`: it runs while the process
21
- // `npx grillhouse circuit <ticket>` runs, and stands at the step of its state, with its
22
- // attempt, every step one for the whole ticket; while the explorateur or
20
+ // in its state `.claude/worktrees/<ticket>.circuit.json`: it runs while the process its state
21
+ // names runs (`processus`, the same one by its start `depart`), and stands at the step of its
22
+ // state, with its attempt, every step one for the whole ticket; while the explorateur or
23
23
  // the questionneur works on its plan (its state names that work, `questionnement`, of the
24
24
  // plan), it stands at the plan (1); stopped on a question for the supervisor (its state names it,
25
25
  // `question`), it stands under the stopped step after a line « ⤷ Question · <qui> », who must
@@ -92,12 +92,14 @@ import {
92
92
  libelle,
93
93
  QUESTIONNEUR,
94
94
  quiDe,
95
+ roleDeLAgent,
95
96
  SUITE,
96
97
  SUPERVISEUR,
97
98
  } from './etapes.mjs';
98
99
  import { bilansGardes, enBref } from './bilan.mjs';
99
100
  import { verdictDe } from './integration/verdict.mjs';
100
101
  import { lireAvancement, lireLaMesure } from './avancement.mjs';
102
+ import { leMemeVivant } from './vitest-config/base-de-passe.mjs';
101
103
 
102
104
  const MINUTE = 60_000;
103
105
  export const SILENCE = 10 * MINUTE;
@@ -113,10 +115,6 @@ const PLACE_DU_SUJET = 10;
113
115
  // The role of a register line that a step of a circuit writes (scripts/circuit.mjs): no agent,
114
116
  // no role of the flow.
115
117
  export const ROLE_DU_CIRCUIT = 'circuit';
116
- // A role by its agent's name: an agent of the frame's plugin is named bare or scoped by the
117
- // plugin (`grillhouse:<rôle>`), as Claude Code names a plugin's agents.
118
- export const roleDeLAgent = nom =>
119
- typeof nom === 'string' ? nom.replace(/^grillhouse:/, '') : null;
120
118
  // A sub-agent's role from its meta file: the type it was spawned as; a named agent's `agentType`
121
119
  // is its name.
122
120
  export const roleDuMeta = m =>
@@ -166,7 +164,8 @@ function entrant(e) {
166
164
 
167
165
  // The reading of a transcript is a state that lines are added to, one JSON object per line: it
168
166
  // holds the tokens, the turns, the start and end, the last incoming message, the ticket, the role,
169
- // the cost and the last tool call, and it is plain JSON, so the board keeps it between two
167
+ // the cost (the total a session writes), the usage by model (which the register prices when the
168
+ // total lacks, scripts/registre.mjs) and the last tool call, and it is plain JSON, so the board keeps it between two
170
169
  // measures and reads only what was appended. A turn is bounded by the earliest and the latest date
171
170
  // of its events, whatever their order in the file; the first one holds the events before the first
172
171
  // incoming message, each next one opens at an incoming message and holds the events up to the next.
@@ -179,6 +178,7 @@ const etatNeuf = () => ({
179
178
  ticket: null,
180
179
  role: null,
181
180
  cout: null,
181
+ modeles: {},
182
182
  appel: null,
183
183
  reponses: [],
184
184
  tours: [],
@@ -268,6 +268,22 @@ function avancer(etat, texte) {
268
268
  etat.jetons +=
269
269
  (u.input_tokens ?? 0) + (u.output_tokens ?? 0) + (u.cache_creation_input_tokens ?? 0);
270
270
  etat.cache += u.cache_read_input_tokens ?? 0;
271
+ // The usage of the message's model: a write of the cache by its duration, one without them
272
+ // of five minutes, the default of the API.
273
+ const ecrit = u.cache_creation_input_tokens ?? 0;
274
+ const uneHeure = u.cache_creation?.ephemeral_1h_input_tokens ?? 0;
275
+ const m = (etat.modeles[String(e.message?.model ?? '')] ??= {
276
+ entree: 0,
277
+ sortie: 0,
278
+ lecture: 0,
279
+ ecriture5m: 0,
280
+ ecriture1h: 0,
281
+ });
282
+ m.entree += u.input_tokens ?? 0;
283
+ m.sortie += u.output_tokens ?? 0;
284
+ m.lecture += u.cache_read_input_tokens ?? 0;
285
+ m.ecriture5m += u.cache_creation?.ephemeral_5m_input_tokens ?? ecrit - uneHeure;
286
+ m.ecriture1h += uneHeure;
271
287
  }
272
288
  etat.vus = [...vus];
273
289
  etat.reponses = [...reponses];
@@ -276,7 +292,8 @@ function avancer(etat, texte) {
276
292
 
277
293
  // The measures of a state: the tokens, the turns and their working time (the union of the turns,
278
294
  // the waits left out), the start (the oldest date) and the end (the latest), the ticket, the role
279
- // (a session launched with `--agent`) and the cost (the total a session writes). `entre` is the
295
+ // (a session launched with `--agent`), the cost (the total a session writes) and the usage by
296
+ // model. `entre` is the
280
297
  // time of the latest incoming message, or null; `attend` tells whether the last tool call still
281
298
  // awaits its answer, the call and its answer paired by their identifier.
282
299
  const mesurer = etat => ({
@@ -291,6 +308,7 @@ const mesurer = etat => ({
291
308
  ticket: etat.ticket || null,
292
309
  role: etat.role,
293
310
  cout: etat.cout,
311
+ modeles: structuredClone(etat.modeles),
294
312
  });
295
313
 
296
314
  // The measures of the transcript text `texte` held in memory.
@@ -555,25 +573,16 @@ export function lireVivant({ racine, home, prefix, maintenant, ps, cache = {} })
555
573
  }
556
574
 
557
575
  // The circuits of the repository at <racine>: each state `.claude/worktrees/<ticket>.circuit.json`
558
- // scripts/circuit.mjs writes, but those at « integre », with `vivant` when `ps` (`pid etimes args`
559
- // per line) shows its process, `grillhouse circuit <ticket>` (the command the supervisor
560
- // launches, `npx grillhouse circuit <ticket>`), `questionnement` the object of the work on the plan
576
+ // scripts/circuit.mjs writes, but those at « integre », with `vivant` when the process its state
577
+ // names lives (`processus`, the same one by its start `depart`: a circuit is a daemon, apart from
578
+ // the command that launched it), `questionnement` the object of the work on the plan
561
579
  // under way (`plan`), null without one, `question` the whole question of a circuit ended on one
562
580
  // and `qui` who must answer it (`superviseur` or `responsable`), null without one,
563
581
  // the counters of its bounded loops (`boucles`, by their key), the progress of the automatic pass under way (`avancement`, read in the directory its state
564
582
  // names, scripts/avancement.mjs: `{ faits, prevus, dernier }`, null without one). A state that
565
583
  // does not parse is left out.
566
- export function lireCircuits({ racine, prefix, ps }) {
584
+ export function lireCircuits({ racine }) {
567
585
  const dossier = path.join(racine, '.claude', 'worktrees');
568
- const motif = new RegExp(`grillhouse circuit (${prefix}-[A-Za-z0-9]+(?:\\.[0-9]+)*)(?:\\s|$)`);
569
- const enVie = new Set();
570
- for (const ligne of ps.split('\n')) {
571
- const m = /^\s*\d+\s+\d+\s+(.*)$/.exec(ligne);
572
- const e = m && motif.exec(m[1]);
573
- if (e) {
574
- enVie.add(e[1]);
575
- }
576
- }
577
586
  const out = [];
578
587
  for (const f of fichiers(dossier, '.circuit.json')) {
579
588
  let e;
@@ -602,7 +611,7 @@ export function lireCircuits({ racine, prefix, ps }) {
602
611
  typeof e.mene === 'string' && !Number.isNaN(Date.parse(e.mene)) ? Date.parse(e.mene) : null,
603
612
  avancement:
604
613
  typeof e.avancement?.dossier === 'string' ? lireAvancement(e.avancement.dossier) : null,
605
- vivant: enVie.has(ticket),
614
+ vivant: leMemeVivant(e.processus, e.depart),
606
615
  });
607
616
  }
608
617
  return out;
@@ -1715,7 +1724,7 @@ export function tableau(racine, { home = os.homedir(), maintenant = Date.now() }
1715
1724
  ps,
1716
1725
  cache,
1717
1726
  });
1718
- const circuits = lireCircuits({ racine, prefix: prefix || '[A-Za-z0-9_]+', ps });
1727
+ const circuits = lireCircuits({ racine });
1719
1728
  try {
1720
1729
  if (fichierCache) {
1721
1730
  writeFileSync(
@@ -37,6 +37,26 @@ import path from 'node:path';
37
37
  const PREFIXE = 'grillhouse-';
38
38
  const PROPRIETAIRE = '.grillhouse-base';
39
39
 
40
+ /**
41
+ * The start time of the process `pid`, in clock ticks since boot: field 22 of `/proc/<pid>/stat`
42
+ * (after the command, itself free to hold spaces and parentheses); null when it does not read.
43
+ * With its number, it names one process, as a number alone does not once it is reused.
44
+ */
45
+ export function departDe(pid) {
46
+ try {
47
+ const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
48
+ const depart = stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19];
49
+ return depart && /^\d+$/.test(depart) ? depart : null;
50
+ } catch {
51
+ return null;
52
+ }
53
+ }
54
+
55
+ /** Whether the process `pid` lives and is the one that started at `depart` (departDe). */
56
+ export function leMemeVivant(pid, depart) {
57
+ return Number.isInteger(pid) && typeof depart === 'string' && departDe(pid) === depart;
58
+ }
59
+
40
60
  /** Whether the process `pid` exists. */
41
61
  export function vivant(pid) {
42
62
  try {