@roomi-fields/grillhouse 0.24.1 → 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.
@@ -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;
@@ -19,7 +19,7 @@
19
19
  // the project keeps the version it recorded, so that the next update plays that migration again.
20
20
  // Last, after the update and the regeneration, what stays to the project (`restes` of a
21
21
  // migration played, scripts/migrations.mjs: in 0.24.0, a file that still calls a former copy of
22
- // the frame) is reported on the standard output, « reste au projet », with no effect on the exit
22
+ // the frame; in 0.24.2, API Extractor still declared by the project) is reported on the standard output, « reste au projet », with no effect on the exit
23
23
  // code nor on the version recorded.
24
24
  // - The frame copies no file into a project: its scripts are the package's, its skills, agents,
25
25
  // hooks of Claude Code, common charter and meta-frame the plugin's, which the package carries
@@ -65,15 +65,17 @@
65
65
  // A `turbo.json` present is never written again by the update; only the generator of the
66
66
  // packages' turbo.json (below) writes in it the `dependsOn` of the guard tasks, and adds one it
67
67
  // lacks.
68
- // - The tools the frame's checks run as commands (API Extractor, whose TSDoc base the project's
69
- // `tsdoc.json` extends, dependency-cruiser, knip, Turborepo) are added to the project's
70
- // `devDependencies` at the version the template's `devDependencies` give; a tool the project
71
- // already declares in `dependencies`, `devDependencies` or `optionalDependencies` keeps its
72
- // declaration, one a previous version added stays, and `devDependencies` are written sorted by
73
- // name. The report names each tool added and `npm install`, which installs them. What the
74
- // package's scripts import, it declares itself (its `dependencies`, and Vitest and TypeScript as
75
- // peers). A project without `packageManager` receives the template's (Turborepo requires it), and
76
- // a `.gitignore` that does not ignore `.turbo/` (Turborepo's runs and cache) receives the line.
68
+ // - The tools the frame's checks run as commands (dependency-cruiser, knip, Turborepo) are added
69
+ // to the project's `devDependencies` at the version the template's `devDependencies` give; a
70
+ // tool the project already declares in `dependencies`, `devDependencies` or
71
+ // `optionalDependencies` keeps its declaration, one a previous version added stays, and
72
+ // `devDependencies` are written sorted by name. The report names each tool added and
73
+ // `npm install`, which installs them. What the package's scripts import, it declares itself (its
74
+ // `dependencies`, API Extractor among them; Vitest and TypeScript as peers), as npm leaves to a
75
+ // package what it imports; the project's `tsdoc.json` extends the package's TSDoc base
76
+ // (`@roomi-fields/grillhouse/tsdoc-base.json`), which extends API Extractor's. A project without
77
+ // `packageManager` receives the template's (Turborepo requires it), and a `.gitignore` that does
78
+ // not ignore `.turbo/` (Turborepo's runs and cache) receives the line.
77
79
  // - A project that runs Vitest (its `test` script names it, or `vitest` is in the `dependencies` or
78
80
  // `devDependencies` of its root `package.json` or of one of its packages, the workspaces as npm
79
81
  // maps them, read by `paquets` of scripts/paquets.mjs, the frame's one list of the
@@ -158,7 +160,7 @@ export const LIGNE_ETAT = '"$CLAUDE_PROJECT_DIR/node_modules/.bin/grillhouse" li
158
160
 
159
161
  // The frame's tools a project runs as commands: their names are the frame's, their versions are
160
162
  // read in the template.
161
- const OUTILS_DU_CADRE = ['@microsoft/api-extractor', 'dependency-cruiser', 'knip', 'turbo'];
163
+ const OUTILS_DU_CADRE = ['dependency-cruiser', 'knip', 'turbo'];
162
164
  // The root scripts of the tests, written together from the template.
163
165
  const SCRIPTS_DES_TESTS = ['test', 'test:vitest', 'test:forcer', 'verifier'];
164
166
  const CHAMPS_INSTALLES = ['dependencies', 'devDependencies', 'optionalDependencies'];
@@ -27,7 +27,8 @@
27
27
  // named, not rewritten.
28
28
  // - A dependency of the project's root that a copy removed imported, that the package declares in
29
29
  // its own `dependencies`, that the template of a project does not declare, and that no source of
30
- // the project still imports, is named, not removed: the project decides.
30
+ // the project still imports, is named, not removed: the project decides. API Extractor is named
31
+ // by the migration of 0.24.2 alone (`DU_PAQUET` of 0.24.2-api-extractor-du-paquet.mjs), once.
31
32
  // - A project without `fichiers.txt` and `empreintes.json` is not written: a second pass finds
32
33
  // neither, or finds only the copies left to the project, which it names again.
33
34
  import { createHash } from 'node:crypto';
@@ -35,10 +36,11 @@ import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'no
35
36
  import path from 'node:path';
36
37
  import { CADRE, PAQUET } from '../cadre.mjs';
37
38
  import { paquets } from '../paquets.mjs';
38
- import { sources } from '../sources.mjs';
39
+ import { importe, sources } from '../sources.mjs';
39
40
  import { SOUS_COMMANDES } from '../sous-commandes.mjs';
40
41
  import { formesAnterieures } from './0.23.0-config-vitest.mjs';
41
42
  import { deRoleSupprime } from './0.24.0-circuit-simplifie.mjs';
43
+ import { dependanceDuPaquet, DU_PAQUET } from './0.24.2-api-extractor-du-paquet.mjs';
42
44
 
43
45
  export const version = '0.23.2';
44
46
  export const nom = 'copies du cadre';
@@ -56,12 +58,6 @@ const GENERE = /^\/\/ Généré par `[^`\n]*turbo-des-paquets[^`\n]*`/;
56
58
 
57
59
  const hacher = octets => createHash('sha256').update(octets).digest('hex');
58
60
  const lireJson = f => JSON.parse(readFileSync(f, 'utf8'));
59
- const echapper = t => t.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
60
- // Whether the source text <texte> imports the package <dep> (or a path into it).
61
- const importe = (texte, dep) =>
62
- new RegExp(
63
- `(?:\\bfrom\\s*|\\bimport\\s*\\(?\\s*|\\brequire\\s*\\(\\s*)(['"])${echapper(dep)}(?:/[^'"]*)?\\1`
64
- ).test(texte);
65
61
 
66
62
  // The subcommand that runs each script of the package, by the path of its former copy.
67
63
  const PAR_COPIE = new Map(Object.entries(SOUS_COMMANDES).map(([n, s]) => [`scripts/${s}`, n]));
@@ -188,14 +184,12 @@ export function migrer(projet) {
188
184
  const duPaquet = Object.keys(lireJson(path.join(PAQUET, 'package.json')).dependencies ?? {});
189
185
  const gabarit = lireJson(path.join(CADRE, GABARIT, 'package.json'));
190
186
  const textes = sources(projet).map(f => readFileSync(path.join(projet, f), 'utf8'));
191
- for (const dep of duPaquet) {
187
+ for (const dep of duPaquet.filter(d => d !== DU_PAQUET)) {
192
188
  if (!CHAMPS.some(c => pkg[c]?.[dep] !== undefined)) continue;
193
189
  if (CHAMPS.some(c => gabarit[c]?.[dep] !== undefined)) continue;
194
190
  if (![...retires.values()].some(t => importe(t, dep))) continue;
195
191
  if (textes.some(t => importe(t, dep))) continue;
196
- sortie.push(
197
- `package.json : la dépendance ${dep} n'est plus importée que par le paquet, qui la déclare lui-même ; \`npm uninstall ${dep}\` la retire si le projet n'en a pas l'usage`
198
- );
192
+ sortie.push(dependanceDuPaquet(dep));
199
193
  }
200
194
  return sortie;
201
195
  }
@@ -0,0 +1,68 @@
1
+ // API Extractor is the package's dependency, not the project's: the package imports it as a library
2
+ // (scripts/interfaces-contre-code.mjs) and declares it in its own `dependencies`, and no command of
3
+ // a project runs it, as npm leaves to a package what it imports. The update of 0.23.0 to 0.24.1
4
+ // added it to the devDependencies of a project's root as a tool the project runs, and
5
+ // `grillhouse code-mort` then refused it as a development dependency without use. The project's
6
+ // `tsdoc.json` extended its TSDoc base, resolved only when npm hoists API Extractor to the root:
7
+ // the package now publishes its own base (`tsdoc-base.json`, which extends API Extractor's), as a
8
+ // rig of Rushstack carries the base configuration beside the dependency it names.
9
+ //
10
+ // - The `tsdoc.json` of the project's root whose `extends` names the base of API Extractor
11
+ // (ANCIENNE_BASE) extends the package's (BASE): that name is rewritten in place, the rest of the
12
+ // file kept byte for byte. A `tsdoc.json` that extends another base, or none, is not written.
13
+ // - What stays to the project (`restes`, which the update plays after its own update, so after the
14
+ // rewrite above): a root `package.json` that declares `@microsoft/api-extractor`
15
+ // (`dependencies`, `devDependencies` or `optionalDependencies`), while no source of the project
16
+ // imports it (scripts/sources.mjs), hears the line of the other dependencies only the package
17
+ // imports (`dependanceDuPaquet`), with `npm uninstall`. The dependency is named, never removed:
18
+ // the project decides. The migration of the copies (0.23.2-copies-du-cadre.mjs) leaves it to this
19
+ // one (DU_PAQUET), so that it is named once.
20
+ // - A project already in the new form is not written, and a second pass returns no line.
21
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
22
+ import path from 'node:path';
23
+ import { importe, sources } from '../sources.mjs';
24
+
25
+ export const version = '0.24.2';
26
+ export const nom = 'API Extractor du paquet';
27
+
28
+ /** The dependency this migration names, which the migration of the copies leaves to it. */
29
+ export const DU_PAQUET = '@microsoft/api-extractor';
30
+ const CHAMPS = ['dependencies', 'devDependencies', 'optionalDependencies'];
31
+ const TSDOC = 'tsdoc.json';
32
+ const ANCIENNE_BASE = `${DU_PAQUET}/extends/tsdoc-base.json`;
33
+ const BASE = '@roomi-fields/grillhouse/tsdoc-base.json';
34
+
35
+ /** The line that names <dep>, a dependency of a project only the package imports. */
36
+ export const dependanceDuPaquet = dep =>
37
+ `package.json : la dépendance ${dep} n'est plus importée que par le paquet, qui la déclare lui-même ; \`npm uninstall ${dep}\` la retire si le projet n'en a pas l'usage`;
38
+
39
+ /** The line naming API Extractor when the project at <projet> declares it without importing it. */
40
+ export function restes(projet) {
41
+ const f = path.join(projet, 'package.json');
42
+ if (!existsSync(f)) {
43
+ return [];
44
+ }
45
+ const pkg = JSON.parse(readFileSync(f, 'utf8'));
46
+ if (!CHAMPS.some(c => pkg[c]?.[DU_PAQUET] !== undefined)) {
47
+ return [];
48
+ }
49
+ const importee = sources(projet).some(s =>
50
+ importe(readFileSync(path.join(projet, s), 'utf8'), DU_PAQUET)
51
+ );
52
+ return importee ? [] : [dependanceDuPaquet(DU_PAQUET)];
53
+ }
54
+
55
+ /** Brings the `extends` of the project's tsdoc.json at <projet> to the package's base. */
56
+ export function migrer(projet) {
57
+ const f = path.join(projet, TSDOC);
58
+ if (!existsSync(f)) {
59
+ return [];
60
+ }
61
+ const texte = readFileSync(f, 'utf8');
62
+ const { extends: bases } = JSON.parse(texte);
63
+ if (!Array.isArray(bases) || !bases.includes(ANCIENNE_BASE)) {
64
+ return [];
65
+ }
66
+ writeFileSync(f, texte.replace(`"${ANCIENNE_BASE}"`, `"${BASE}"`));
67
+ return [`${TSDOC} : hérite de ${BASE}, la base TSDoc du paquet, au lieu de ${ANCIENNE_BASE}`];
68
+ }
@@ -25,6 +25,7 @@ import * as crochetsDeSeance from './migrations/0.23.0-crochets-de-seance.mjs';
25
25
  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
+ import * as apiExtractorDuPaquet from './migrations/0.24.2-api-extractor-du-paquet.mjs';
28
29
 
29
30
  /** The migrations of the package. */
30
31
  export const MIGRATIONS = [
@@ -34,6 +35,7 @@ export const MIGRATIONS = [
34
35
  charteImportee,
35
36
  copiesDuCadre,
36
37
  circuitSimplifie,
38
+ apiExtractorDuPaquet,
37
39
  ];
38
40
 
39
41
  /**
@@ -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
  {
@@ -1,7 +1,7 @@
1
1
  // The source files of a project, as the migrations read them (scripts/migrations/): each `.ts`,
2
2
  // `.mts`, `.cts`, `.js`, `.mjs`, `.cjs` under its root, as a path from it, the directories of
3
3
  // tools and of what is installed or built (node_modules, .git, dist, coverage, .turbo, .claude,
4
- // .beads, .codegraph, .rtfm) left out.
4
+ // .beads, .codegraph, .rtfm) left out; and whether a source text imports a package (`importe`).
5
5
  import { readdirSync } from 'node:fs';
6
6
  import path from 'node:path';
7
7
 
@@ -26,3 +26,10 @@ export function sources(racine, rel = '') {
26
26
  return e.isFile() && EXTENSIONS.test(e.name) ? [r] : [];
27
27
  });
28
28
  }
29
+
30
+ const echapper = t => t.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
31
+ /** Whether the source text <texte> imports the package <dep> (or a path into it). */
32
+ export const importe = (texte, dep) =>
33
+ new RegExp(
34
+ `(?:\\bfrom\\s*|\\bimport\\s*\\(?\\s*|\\brequire\\s*\\(\\s*)(['"])${echapper(dep)}(?:/[^'"]*)?\\1`
35
+ ).test(texte);
@@ -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 {