@roomi-fields/grillhouse 0.52.0 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +96 -0
  3. package/agents/direct.md +1 -1
  4. package/cadre/templates/projet/docs/agents/issue-tracker.md +2 -2
  5. package/cadre/templates/projet/vitest.config.cjs +45 -0
  6. package/charte/superviseur.md +36 -37
  7. package/charte.md +13 -1
  8. package/dist/temporal/circuit/appel.d.ts +2 -0
  9. package/dist/temporal/circuit/appel.js +24 -2
  10. package/dist/temporal/circuit/appel.js.map +1 -1
  11. package/dist/temporal/circuit/client.d.ts +14 -5
  12. package/dist/temporal/circuit/client.js +41 -9
  13. package/dist/temporal/circuit/client.js.map +1 -1
  14. package/dist/temporal/circuit/commande.js +17 -6
  15. package/dist/temporal/circuit/commande.js.map +1 -1
  16. package/dist/temporal/circuit/contrat.d.ts +9 -0
  17. package/dist/temporal/circuit/contrat.js +6 -0
  18. package/dist/temporal/circuit/contrat.js.map +1 -1
  19. package/dist/temporal/circuit/deroule.js +29 -12
  20. package/dist/temporal/circuit/deroule.js.map +1 -1
  21. package/dist/temporal/client.d.ts +35 -1
  22. package/dist/temporal/client.js +144 -1
  23. package/dist/temporal/client.js.map +1 -1
  24. package/dist/temporal/commande.js +31 -13
  25. package/dist/temporal/commande.js.map +1 -1
  26. package/dist/temporal/etat.d.ts +3 -1
  27. package/dist/temporal/etat.js +31 -17
  28. package/dist/temporal/etat.js.map +1 -1
  29. package/dist/temporal/file/activites.js +1 -1
  30. package/dist/temporal/file/activites.js.map +1 -1
  31. package/dist/temporal/file/contrat.d.ts +4 -5
  32. package/dist/temporal/file/contrat.js +2 -2
  33. package/dist/temporal/file/contrat.js.map +1 -1
  34. package/dist/temporal/file/deroule.js +7 -5
  35. package/dist/temporal/file/deroule.js.map +1 -1
  36. package/dist/temporal/installation.d.ts +116 -53
  37. package/dist/temporal/installation.js +898 -241
  38. package/dist/temporal/installation.js.map +1 -1
  39. package/dist/temporal/nuits/deroule.js +3 -1
  40. package/dist/temporal/nuits/deroule.js.map +1 -1
  41. package/dist/temporal/places/deroule.js +2 -1
  42. package/dist/temporal/places/deroule.js.map +1 -1
  43. package/dist/temporal/sonde/deroule.js +2 -1
  44. package/dist/temporal/sonde/deroule.js.map +1 -1
  45. package/dist/temporal/tickets/deroule.js +4 -3
  46. package/dist/temporal/tickets/deroule.js.map +1 -1
  47. package/dist/temporal/travailleur.d.ts +7 -1
  48. package/dist/temporal/travailleur.js +49 -25
  49. package/dist/temporal/travailleur.js.map +1 -1
  50. package/docs/INTERFACE.md +37 -12
  51. package/docs/architecture/circuit.md +21 -18
  52. package/docs/architecture/entree.md +10 -11
  53. package/docs/architecture/greffon.md +45 -27
  54. package/docs/architecture/installation.md +92 -59
  55. package/docs/architecture/machine.md +2 -2
  56. package/docs/architecture/tests.md +15 -6
  57. package/docs/lexique.md +2 -2
  58. package/hooks/hooks.json +10 -0
  59. package/hooks/register.tsx +59 -39
  60. package/package.json +3 -2
  61. package/scripts/activites.mjs +5 -4
  62. package/scripts/aiguillage.mjs +5 -2
  63. package/scripts/bd-garde.mjs +69 -0
  64. package/scripts/ci-de-main.mjs +259 -56
  65. package/scripts/circuit.mjs +274 -47
  66. package/scripts/circuits-du-serveur.mjs +3 -2
  67. package/scripts/circuits-tenus.d.mts +7 -0
  68. package/scripts/circuits-tenus.mjs +17 -0
  69. package/scripts/commandes-composees.mjs +1 -1
  70. package/scripts/copie-de-montee.mjs +354 -0
  71. package/scripts/copies-du-depot.d.mts +13 -0
  72. package/scripts/copies-du-depot.mjs +66 -0
  73. package/scripts/copies-finies.mjs +6 -40
  74. package/scripts/crochets.mjs +16 -2
  75. package/scripts/direct.mjs +2 -2
  76. package/scripts/droits.mjs +13 -6
  77. package/scripts/engendres.mjs +5 -3
  78. package/scripts/enveloppe/travail-de-la-copie.mjs +77 -0
  79. package/scripts/etapes.mjs +11 -3
  80. package/scripts/faits-du-circuit.mjs +12 -5
  81. package/scripts/file-des-tickets.d.mts +13 -2
  82. package/scripts/file-des-tickets.mjs +71 -21
  83. package/scripts/greffons.mjs +42 -27
  84. package/scripts/grillhouse-maj.mjs +105 -85
  85. package/scripts/init.mjs +1 -1
  86. package/scripts/integration/file.mjs +5 -2
  87. package/scripts/integration/integrer.mjs +14 -4
  88. package/scripts/jointure.d.ts +16 -0
  89. package/scripts/langages/c/commandes.mjs +18 -8
  90. package/scripts/langages/cargo/commandes.mjs +88 -35
  91. package/scripts/langages/cargo/index.mjs +6 -3
  92. package/scripts/langages/cargo/sccache.mjs +15 -12
  93. package/scripts/langages/cargo/tailles-des-tests.mjs +115 -6
  94. package/scripts/langages/python/commandes.mjs +19 -9
  95. package/scripts/langages/python/squelette.mjs +2 -2
  96. package/scripts/langages/typescript/code-mort.mjs +36 -3
  97. package/scripts/langages/typescript/configurations-de-vitest.mjs +118 -0
  98. package/scripts/langages/typescript/index.mjs +2 -0
  99. package/scripts/langages/typescript/migrations/configurations-en-commonjs.mjs +370 -0
  100. package/scripts/langages/typescript/mise-a-jour.mjs +49 -12
  101. package/scripts/langages/typescript/parcours.mjs +5 -1
  102. package/scripts/langages/typescript/squelette.mjs +20 -17
  103. package/scripts/langages/typescript/tests-de-nuit.mjs +3 -3
  104. package/scripts/langages/typescript/turbo-des-paquets.mjs +24 -37
  105. package/scripts/langages/typescript/vitest-config/base.mjs +1 -1
  106. package/scripts/langages/typescript/vitest-config/bornes.mjs +1 -1
  107. package/scripts/langages/typescript/vitest-config/cibles.mjs +2 -2
  108. package/scripts/langages/typescript/{vitest.nuit.config.mjs → vitest.nuit.config.cjs} +61 -50
  109. package/scripts/langages.d.mts +6 -0
  110. package/scripts/langages.mjs +6 -0
  111. package/scripts/lire.mjs +236 -0
  112. package/scripts/mesure/pression.mjs +5 -3
  113. package/scripts/migrations/cout-des-jetons-au-registre.mjs +136 -0
  114. package/scripts/migrations/lire-un-ticket.mjs +46 -0
  115. package/scripts/migrations.mjs +4 -0
  116. package/scripts/montee.mjs +588 -0
  117. package/scripts/nuit.sh +21 -12
  118. package/scripts/outil.mjs +5 -3
  119. package/scripts/paquet-npm.mjs +22 -0
  120. package/scripts/paquet.mjs +5 -5
  121. package/scripts/pre-compact.mjs +25 -0
  122. package/scripts/registre.d.mts +7 -1
  123. package/scripts/registre.mjs +114 -102
  124. package/scripts/reponses-du-circuit.d.mts +17 -2
  125. package/scripts/reponses-du-circuit.mjs +78 -20
  126. package/scripts/resultats.mjs +55 -17
  127. package/scripts/retirer-les-copies-finies.mjs +4 -7
  128. package/scripts/seances.mjs +28 -3
  129. package/scripts/services-du-noyau.mjs +7 -2
  130. package/scripts/session-start.sh +18 -11
  131. package/scripts/sortie.mjs +4 -7
  132. package/scripts/sous-commandes.mjs +2 -0
  133. package/scripts/suiveur.mjs +12 -4
  134. package/scripts/superviseur.mjs +135 -84
  135. package/scripts/tableau.mjs +651 -224
  136. package/scripts/tarifs.mjs +67 -0
  137. package/scripts/ticket-du-circuit.mjs +25 -4
  138. package/scripts/transitions.d.mts +6 -14
  139. package/scripts/transitions.mjs +126 -49
  140. package/scripts/verdict-de-la-nuit.mjs +2 -2
  141. package/scripts/verrou-de-fichier.d.mts +11 -0
  142. package/skills/direct/SKILL.md +21 -11
  143. package/skills/explorateur/SKILL.md +16 -6
  144. package/skills/grill/SKILL.md +9 -7
  145. package/skills/grill/references/paquets.md +4 -4
  146. package/skills/mesure/SKILL.md +4 -3
  147. package/skills/pitmaster/SKILL.md +56 -35
  148. package/skills/pitmaster/references/consigne-agent.md +1 -1
  149. package/skills/pitmaster/references/erreurs.md +4 -2
  150. package/skills/pitmaster/references/tour.md +11 -4
  151. package/skills/relecteur/SKILL.md +8 -1
  152. package/skills/testwriter/SKILL.md +1 -1
  153. package/types/index.d.ts +3 -1
  154. package/cadre/templates/projet/vitest.config.ts +0 -44
  155. package/scripts/base-des-workflows.mjs +0 -58
@@ -134,6 +134,28 @@ export function packageJsonDuPaquet(nom, chemin) {
134
134
  return `${JSON.stringify(p, null, 2)}\n`;
135
135
  }
136
136
 
137
+ /**
138
+ * The gesture by hand that makes the package <nom> of the folder <dossier> (absolute) a package of
139
+ * the graph of the project at <racine>: its package.json, given in full (`packageJsonDuPaquet`),
140
+ * and its entry in the `workspaces` of the root when no pattern selects it. Null for the root
141
+ * itself, which no entry makes a package of the graph.
142
+ * @param {string} racine
143
+ * @param {string} dossier
144
+ * @param {string} nom
145
+ */
146
+ export function gesteDuPackageJson(racine, dossier, nom) {
147
+ const chemin = path.relative(racine, dossier).split(path.sep).join('/');
148
+ if (chemin === '') {
149
+ return null;
150
+ }
151
+ const f = path.join(racine, 'package.json');
152
+ const inscrit = existsSync(f) && selectionne(JSON.parse(readFileSync(f, 'utf8')), chemin);
153
+ const espaces = inscrit
154
+ ? ''
155
+ : `, puis inscris \`${chemin}\` aux \`workspaces\` du package.json de la racine (aucun motif ne le sélectionne)`;
156
+ return `à la main, écris \`${chemin}/package.json\`${espaces}. Son contenu :\n${packageJsonDuPaquet(nom, chemin)}`;
157
+ }
158
+
137
159
  /**
138
160
  * The text of the root package.json <texte> with <chemin> entered in its `workspaces`; null when
139
161
  * its patterns select the folder already.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- // The creation of a package, out of the circuit: the third of the four times of a package's birth
3
- // (the common charter, module superviseur, « Un paquet naît hors du circuit »: the grill, the writing of its row and its
4
- // documents, this command, then a ticket of code), as the generators of Nx and `cargo new --lib`
5
- // write one. A skeleton has neither behaviour nor test. The mechanism is installation.md §3.1
2
+ // The creation of a package: the third of the four times of a package's birth (the common charter,
3
+ // module superviseur, « Un paquet naît en quatre temps »: the grill, the writing of its row and its
4
+ // documents, this command, played by the agent of a direct ticket, then a ticket of code), as the
5
+ // generators of Nx and `cargo new --lib` write one. A skeleton has neither behaviour nor test. The mechanism is installation.md §3.1
6
6
  // (« Création d'un paquet »), tests.md §5.6, in packages/grillhouse/docs/architecture/.
7
7
  //
8
8
  // npx grillhouse paquet <chemin> from the root of the project, <chemin> from it
@@ -314,7 +314,7 @@ export function creerPaquet(racine, chemin, { source = CADRE, executer = lancer,
314
314
  const code = executer(commande, args, path.join(racine, dossier));
315
315
  if (code !== 0) {
316
316
  echecs.push(
317
- `\`${[commande, ...args].join(' ')}\` (${dossier}) échoue, code ${code} ; lance-le, puis \`npx grillhouse maj\`.`
317
+ `\`${[commande, ...args].join(' ')}\` (${dossier}) échoue, code ${code} ; relance-la dans ${dossier}.`
318
318
  );
319
319
  }
320
320
  };
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ // The PreCompact hook of the frame's plugin (`grillhouse pre-compact`): what it writes on its
3
+ // standard output joins the instructions of the summary of a compaction, manual, automatic or asked
4
+ // by a plugin. For the session that holds the lock of the supervisor of the project, with a note of
5
+ // resumption, it writes them (`consignesDuResume`, scripts/superviseur.mjs). It exits 0 and writes
6
+ // nothing otherwise, on the compaction of a subagent (an input that bears `agent_id`) and on an
7
+ // input it cannot read. Mechanism: greffon.md, §5.2.
8
+ import { readFileSync } from 'node:fs';
9
+ import { consignesDuResume } from './superviseur.mjs';
10
+
11
+ function entree() {
12
+ try {
13
+ return JSON.parse(readFileSync(0, 'utf8'));
14
+ } catch {
15
+ return null;
16
+ }
17
+ }
18
+
19
+ const e = entree();
20
+ if (e && !e.agent_id) {
21
+ const texte = consignesDuResume(process.env.CLAUDE_PROJECT_DIR || process.cwd());
22
+ if (texte) {
23
+ process.stdout.write(`${texte}\n`);
24
+ }
25
+ }
@@ -20,6 +20,8 @@ export interface Tarif {
20
20
  lecture: number;
21
21
  ecriture5m: number;
22
22
  ecriture1h: number;
23
+ /** The upper tier, of a request of more than `au` input tokens, cache included. */
24
+ palier?: Omit<Tarif, 'palier'> & { au: number };
23
25
  }
24
26
 
25
27
  /** A line of the register. */
@@ -60,7 +62,6 @@ export function ligne(
60
62
  tours: [number, number][];
61
63
  jetons: number;
62
64
  cache: number;
63
- cout?: number | null;
64
65
  modeles?: Record<string, Partial<Tarif>>;
65
66
  },
66
67
  projet: string
@@ -86,5 +87,10 @@ export function aRattraper(
86
87
  maintenant?: number
87
88
  ): EntreeDuCrochet[];
88
89
  export function ecrire(l: LigneDuRegistre): boolean;
90
+ export function depenseJusqua(
91
+ lectures: ({ reponses: object[] } | undefined)[],
92
+ fin: number
93
+ ): { jetons: number; cache: number; modeles: Record<string, object>; ecartee: boolean };
94
+ export function ecrireLaLigne(input: EntreeDuCrochet, projet: string, home?: string): boolean;
89
95
  export function transcriptionsDeLaCopie(copie: string, home: string): string;
90
96
  export function deLaCopie(copie: string, home: string, connus: Set<string>): EntreeDuCrochet[];
@@ -14,16 +14,22 @@
14
14
  // its role, its start and end, its working time and the turns it sums (start and end in
15
15
  // milliseconds, the waits for a message left out), its tokens, its cache reads and its cost. All
16
16
  // of it is read from the agent's transcript; the agent declares nothing.
17
- // - The cost is the total the session writes, as ccusage keeps it; without one, or with a total of
18
- // 0 for tokens spent (a sub-agent's transcript holds none), it is the usage of each model at its
19
- // tariff (`TARIFS`), as Claude Code reckons it. A model without a tariff that spent tokens leaves
20
- // such a cost unknown (null).
17
+ // - The cost is the price of the transcript's own tokens, as ccusage reckons it: each response at
18
+ // the tariff of its model (`TARIFS`, scripts/tarifs.mjs), each kind of token its own. The total a
19
+ // session writes (`cost-state`), which holds the spending of its sub-agents, is left aside. A
20
+ // model without a tariff that spent tokens leaves the cost unknown (null).
21
+ // - The tokens, the cache reads and the cost of a line are those of all the transcripts of its
22
+ // agent up to its end, without the responses another transcript of the project retains
23
+ // (`lireSansLesRetenuesAilleurs` in tableau.mjs): the board keeps one line per agent, and the
24
+ // lines it adds count each response once. Its time, turns, start and end count the whole
25
+ // transcript of its stop.
21
26
  // - The register is `~/.claude/grillhouse/registre.jsonl` (GRILLHOUSE_REGISTRE replaces it): the
22
27
  // envelope of a role agent leaves it writable.
23
28
  // - A hook never stops the session, and never waits for a transcript: it hands the fields of its
24
29
  // input that the line reads to a detached process (`--ecrire`) and ends at once, within Claude
25
- // Code's hook time limit. The detached process reads the transcript in chunks (`lireFichier` in
26
- // tableau.mjs), never whole; a transcript it cannot read writes nothing.
30
+ // Code's hook time limit. The detached process reads the transcripts in chunks
31
+ // (`lireSansLesRetenuesAilleurs` in tableau.mjs), never whole; a transcript it cannot read writes
32
+ // nothing. `--rattraper` and `--copie` read the project's transcripts once for all their lines.
27
33
  // - One stop has one line: the write holds the register's lock (`prendreVerrou`, judged by the
28
34
  // lock's age, since a role agent's envelope and the outside do not share process numbers),
29
35
  // and skips a line whose agent and end the register already holds. The hook and
@@ -42,12 +48,20 @@ import os from 'node:os';
42
48
  import path from 'node:path';
43
49
  import { pathToFileURL } from 'node:url';
44
50
  import { roleDeLAgent } from './etapes.mjs';
45
- import { lireFichier, ROLE_DE_LA_NUIT, ROLE_DU_CIRCUIT, roleDuMeta, tourne } from './tableau.mjs';
51
+ import {
52
+ lireSansLesRetenuesAilleurs,
53
+ ROLE_DE_LA_NUIT,
54
+ ROLE_DU_CIRCUIT,
55
+ roleDuMeta,
56
+ tourne,
57
+ transcriptionsDuProjet,
58
+ } from './tableau.mjs';
59
+ import { coutDe, TARIFS } from './tarifs.mjs';
46
60
  import { lacherVerrou, prendreVerrou } from './verrou-de-fichier.mjs';
47
61
 
48
62
  import { REGISTRE } from './adresse-du-registre.mjs';
49
63
 
50
- export { REGISTRE };
64
+ export { coutDe, REGISTRE, TARIFS };
51
65
 
52
66
  // The transcript and the role the hook's input names: a sub-agent's sits next to the session's.
53
67
  export function source(input) {
@@ -83,36 +97,9 @@ export function source(input) {
83
97
  };
84
98
  }
85
99
 
86
- // The tariffs of the models the frame's agents run on, in dollars per million tokens: the input,
87
- // the output, a read of the cache, a write of the cache kept five minutes, and one kept an hour.
88
- // Those of Sonnet 5.5 and Opus 5.5 give the total Claude Code wrote for each of the 25 sessions of
89
- // BPScript 320.8, to the thousandth.
90
- export const TARIFS = {
91
- 'claude-sonnet-5-5': { entree: 2, sortie: 10, lecture: 0.1, ecriture5m: 2.5, ecriture1h: 4 },
92
- 'claude-opus-5-5': { entree: 4, sortie: 20, lecture: 0.2, ecriture5m: 5, ecriture1h: 8 },
93
- 'claude-haiku-4-5': { entree: 1, sortie: 5, lecture: 0.1, ecriture5m: 1.25, ecriture1h: 2 },
94
- };
95
-
96
- // The cost of the usage by model <modeles> (`{ <modèle>: { entree, sortie, lecture, ecriture5m,
97
- // ecriture1h } }`, tokens), or null when a model without a tariff spent tokens.
98
- export function coutDe(modeles) {
99
- let cout = 0;
100
- for (const [modele, u] of Object.entries(modeles ?? {})) {
101
- const parts = Object.entries(u);
102
- if (parts.every(([, n]) => !n)) {
103
- continue;
104
- }
105
- const tarif = TARIFS[modele];
106
- if (!tarif) {
107
- return null;
108
- }
109
- cout += parts.reduce((m, [k, n]) => m + n * (tarif[k] ?? 0), 0) / 1e6;
110
- }
111
- return cout;
112
- }
113
-
114
- // The register's line for this hook input and the reading `t` of its transcript (`lireFichier` or
115
- // `lireTranscription`), or null. `projet` is the main tree of the session.
100
+ // The register's line for this hook input and the reading `t` of its transcript (`lireFichier`,
101
+ // `lireTranscription` or `lireSansLesRetenuesAilleurs`), or null. `projet` is the main tree of the
102
+ // session.
116
103
  export function ligne(input, t, projet) {
117
104
  const { role, agent } = source(input);
118
105
  if (t.premier === null) {
@@ -129,8 +116,8 @@ export function ligne(input, t, projet) {
129
116
  tours: t.tours,
130
117
  jetons: t.jetons,
131
118
  cache: t.cache,
132
- // The total the session wrote; none, or 0, reckoned on its tokens (0 without any).
133
- cout: t.cout || coutDe(t.modeles),
119
+ // The price of the transcript's own tokens (0 without any).
120
+ cout: coutDe(t.modeles),
134
121
  };
135
122
  }
136
123
 
@@ -177,7 +164,7 @@ export function ligneDeNuit({ projet, quand, raison, sommet, reference }) {
177
164
  }
178
165
 
179
166
  // The main tree of a directory: an agent's copy belongs to the repository it was made from.
180
- function arbrePrincipal(dir) {
167
+ export function arbrePrincipal(dir) {
181
168
  try {
182
169
  const commun = execFileSync(
183
170
  'git',
@@ -197,49 +184,23 @@ const enTirets = p => p.replace(/[^A-Za-z0-9]/g, '-');
197
184
 
198
185
  // The hook inputs of the project's finished agents that `connus` (agent ids) does not hold.
199
186
  export function aRattraper(racine, home, connus, maintenant = Date.now()) {
200
- const projets = path.join(home, '.claude', 'projects');
201
- if (!existsSync(projets)) {
202
- return [];
203
- }
204
187
  const out = [];
205
- const fini = (f, sousAgent) => !tourne(f, maintenant, sousAgent);
206
- const jsonl = d => (existsSync(d) ? readdirSync(d).filter(n => n.endsWith('.jsonl')) : []);
207
- const propre = path.join(projets, enTirets(racine));
208
- const copies = `${enTirets(path.join(racine, '.claude', 'worktrees'))}-`;
209
- for (const d of readdirSync(projets)) {
210
- const dir = path.join(projets, d);
211
- if (d !== enTirets(racine) && !d.startsWith(copies)) {
188
+ for (const { f, agent, session, propre } of transcriptionsDuProjet(racine, home)) {
189
+ // The sub-agents caught up are those of the project's own sessions.
190
+ if ((session && !propre) || connus.has(agent) || tourne(f, maintenant, Boolean(session))) {
212
191
  continue;
213
192
  }
214
- for (const n of jsonl(dir)) {
215
- const f = path.join(dir, n);
216
- const session = n.replace(/\.jsonl$/, '');
217
- if (!connus.has(session) && fini(f, false)) {
218
- out.push({
219
- hook_event_name: 'SessionEnd',
220
- transcript_path: f,
221
- session_id: session,
222
- cwd: racine,
223
- });
224
- }
225
- if (dir !== propre) {
226
- continue;
227
- }
228
- const sous = path.join(dir, session, 'subagents');
229
- for (const m of jsonl(sous)) {
230
- const agent = m.replace(/^agent-/, '').replace(/\.jsonl$/, '');
231
- const g = path.join(sous, m);
232
- if (!connus.has(agent) && fini(g, true)) {
233
- out.push({
193
+ out.push(
194
+ session
195
+ ? {
234
196
  hook_event_name: 'SubagentStop',
235
- transcript_path: f,
197
+ transcript_path: session,
236
198
  agent_id: agent,
237
- agent_transcript_path: g,
199
+ agent_transcript_path: f,
238
200
  cwd: racine,
239
- });
240
- }
241
- }
242
- }
201
+ }
202
+ : { hook_event_name: 'SessionEnd', transcript_path: f, session_id: agent, cwd: racine }
203
+ );
243
204
  }
244
205
  return out;
245
206
  }
@@ -274,16 +235,80 @@ export function ecrire(l) {
274
235
  }
275
236
  }
276
237
 
277
- // Reads the transcript of `input` in chunks and writes its line; false when nothing was written.
278
- function ecrireLaLigne(input, projet) {
279
- const { transcription } = source(input);
280
- if (!transcription || !existsSync(transcription)) {
281
- return false;
238
+ // What an agent spent up to `fin` in the readings `lectures` of its transcripts
239
+ // (`lireSansLesRetenuesAilleurs`), without the responses another transcript retains, so that each
240
+ // counts once: its tokens, its cache reads, its usage by key of tariff, and `ecartee` when one of
241
+ // those responses is retained elsewhere. A transcript without a reading counts nothing.
242
+ export function depenseJusqua(lectures, fin) {
243
+ const depense = { jetons: 0, cache: 0, modeles: {}, ecartee: false };
244
+ // One file named by two paths has one reading.
245
+ for (const { reponses } of new Set(lectures.filter(Boolean))) {
246
+ for (const r of reponses) {
247
+ if (r.quand > fin) {
248
+ continue;
249
+ }
250
+ if (r.ailleurs) {
251
+ depense.ecartee = true;
252
+ continue;
253
+ }
254
+ depense.jetons += r.jetons;
255
+ depense.cache += r.cache;
256
+ const m = (depense.modeles[r.cle] ??= {});
257
+ for (const [part, n] of Object.entries(r.usage)) {
258
+ m[part] = (m[part] ?? 0) + n;
259
+ }
260
+ }
282
261
  }
283
- const l = ligne(input, lireFichier(transcription), projet);
284
- return l ? ecrire(l) : false;
262
+ return depense;
285
263
  }
286
264
 
265
+ // Reads the transcripts of the agents of `inputs` and writes their lines: the time, the turns, the
266
+ // start and the end of the input's transcript, the spending of all the agent's transcripts in the
267
+ // project `projet` of the home `home` up to that end (`depenseJusqua`). Returns how many were
268
+ // written. A line that cannot be read or written leaves the others.
269
+ function ecrireLesLignes(inputs, projet, home) {
270
+ const presentes = inputs
271
+ .map(input => ({ input, ...source(input) }))
272
+ .filter(({ transcription }) => transcription && existsSync(transcription));
273
+ if (presentes.length === 0) {
274
+ return 0;
275
+ }
276
+ const duProjet = transcriptionsDuProjet(projet, home);
277
+ const attendues = presentes.map(({ input, transcription, agent }) => ({
278
+ input,
279
+ f: transcription,
280
+ siennes: [transcription, ...duProjet.filter(x => x.agent === agent).map(x => x.f)],
281
+ }));
282
+ const lues = lireSansLesRetenuesAilleurs(
283
+ attendues.flatMap(({ siennes }) => siennes),
284
+ duProjet.map(({ f }) => f)
285
+ );
286
+ let n = 0;
287
+ for (const { input, f, siennes } of attendues) {
288
+ try {
289
+ const lu = lues.get(f);
290
+ const l = lu && ligne(input, lu.mesures, projet);
291
+ if (!l) {
292
+ continue;
293
+ }
294
+ const { jetons, cache, modeles } = depenseJusqua(
295
+ siennes.map(x => lues.get(x)),
296
+ Date.parse(l.fin)
297
+ );
298
+ if (ecrire({ ...l, jetons, cache, cout: coutDe(modeles) })) {
299
+ n++;
300
+ }
301
+ } catch {
302
+ // A line it cannot write waits for the next catch-up.
303
+ }
304
+ }
305
+ return n;
306
+ }
307
+
308
+ // Writes the line of the agent of `input`; false when nothing was written.
309
+ export const ecrireLaLigne = (input, projet, home = os.homedir()) =>
310
+ ecrireLesLignes([input], projet, home) === 1;
311
+
287
312
  // The directory where Claude Code keeps the transcripts of the sessions of an agent's copy
288
313
  // (`copie`), in the home <home>: its path in dashes under `~/.claude/projects`. The circuit
289
314
  // (scripts/circuit.mjs) watches it.
@@ -342,26 +367,13 @@ const CHAMPS = [
342
367
  const direct = import.meta.url === pathToFileURL(process.argv[1] ?? '').href;
343
368
  if (direct && process.argv.includes('--rattraper')) {
344
369
  const racine = arbrePrincipal(process.cwd());
345
- let n = 0;
346
- for (const input of aRattraper(racine, os.homedir(), connusDuRegistre())) {
347
- try {
348
- if (ecrireLaLigne(input, racine)) {
349
- n++;
350
- }
351
- } catch {
352
- // A transcript it cannot read waits for the next catch-up.
353
- }
354
- }
370
+ const inputs = aRattraper(racine, os.homedir(), connusDuRegistre());
371
+ const n = ecrireLesLignes(inputs, racine, os.homedir());
355
372
  process.stdout.write(`${n} agent(s) fini(s) ajouté(s) au registre.\n`);
356
373
  } else if (direct && process.argv[2] === '--copie') {
357
374
  const copie = path.resolve(process.argv[3] ?? '.');
358
- for (const input of deLaCopie(copie, os.homedir(), connusDuRegistre())) {
359
- try {
360
- ecrireLaLigne(input, arbrePrincipal(copie));
361
- } catch {
362
- // A transcript it cannot read writes nothing.
363
- }
364
- }
375
+ const inputs = deLaCopie(copie, os.homedir(), connusDuRegistre());
376
+ ecrireLesLignes(inputs, arbrePrincipal(copie), os.homedir());
365
377
  } else if (direct && process.argv[2] === '--ecrire') {
366
378
  try {
367
379
  const input = JSON.parse(process.argv[3]);
@@ -4,8 +4,13 @@
4
4
  export const SANS_ISSUE: Set<string>;
5
5
  /** The answers accepted for the circuit of <ticket> whose workflow has the status <statut>. */
6
6
  export function lesReponses(ticket: string, statut: string, ecrit: boolean): string;
7
- /** The hour `bd update --defer` receives for `--reporter <heure>`, and the phrase of its texts. */
8
- export function heureDuReport(heure: string, maintenant: Date): { defer: string; quand: string };
7
+ /** The refusal of an hour of deferral, which cites the forms accepted. */
8
+ export const REFUS_DE_L_HEURE: string;
9
+ /** The hour `bd update --defer` receives for `--reporter <heure>`, and the phrase of its texts; null refused. */
10
+ export function heureDuReport(
11
+ heure: string,
12
+ maintenant: Date
13
+ ): { defer: string; quand: string } | null;
9
14
  /** The stops `--mecanique` answers, by the step they stand at: the testwriter's, the proof's. */
10
15
  export const ARRETS_DE_LA_BASCULE: Record<string, string[]>;
11
16
  /** The sort of a ticket, as the plan says it (scripts/resultats.mjs `sorteDuPlan`). */
@@ -15,6 +20,16 @@ export interface SorteDuTicket {
15
20
  comportement?: 'changé' | 'tests-adaptés' | 'inchangé';
16
21
  commande?: string;
17
22
  }
23
+ /** The answer `--planifier` to the stop <etat>: a refusal, or nothing. */
24
+ export function reponsePlanifier(o: {
25
+ etat: {
26
+ etape: string;
27
+ raison?: string | null;
28
+ motif?: string | null;
29
+ circuit?: string | null;
30
+ } | null;
31
+ contexte: string | null;
32
+ }): { refus?: string };
18
33
  /** The answer `--mecanique` to the stop <etat> of a ticket of sort <sorte>: a refusal, or its new sort and step. */
19
34
  export function reponseMecanique(o: {
20
35
  etat: { etape: string; raison?: string | null } | null;
@@ -3,8 +3,9 @@
3
3
  // nor output: the one rule the client (src/temporal/circuit/client.ts: its refusals and the
4
4
  // circuits it reads), the opening, the wait, the board and the line of a stop name; and the
5
5
  // answer `--mecanique`, which turns the sort of a ticket stopped on the testwriter or on the proof
6
- // of the red.
6
+ // of the red; and the answer `--planifier`, which switches a direct circuit to the plan.
7
7
  import { refusDeLaCommande } from './commande-du-plan.mjs';
8
+ import { DEMANDE_UN_PLAN } from './etapes.mjs';
8
9
  import { CODE, GESTE, PREUVE, TESTS } from './transitions.mjs';
9
10
 
10
11
  /** The statuses of a workflow ended without its issue. */
@@ -35,38 +36,72 @@ export function lesReponses(ticket, statut, ecrit) {
35
36
  }
36
37
  const etendre = '--etendre <paquet>';
37
38
  const mecanique = '--mecanique [<commande>] --contexte <raison>';
39
+ const planifier = '--planifier --contexte <raison>';
38
40
  // The question carried to the owner: it stays quiet until the circuit answers.
39
41
  const chez = '--chez-le-responsable';
40
42
  return statut === 'RUNNING'
41
- ? `${circuit} --reprendre\`, \`${depuis}\`, \`${mecanique}\`, \`${etendre}\`, \`--reporter <heure>\`, \`${chez}\` ou \`--arreter`
43
+ ? `${circuit} --reprendre\`, \`${depuis}\`, \`${mecanique}\`, \`${planifier}\`, \`${etendre}\`, \`--reporter <heure>\`, \`${chez}\` ou \`--arreter`
42
44
  : `${circuit} --reprendre\`, \`${depuis}\`, \`${mecanique}\`, \`${etendre}\` ou \`${chez}`;
43
45
  }
44
46
 
45
- /**
46
- * The hour of a deferral (`--reporter <heure>`): a lone hour (`H:MM` or `HH:MM`, 0-23 and 00-59)
47
- * aims at its next occurrence in the machine's local time, today when strictly after <maintenant>
48
- * (to the second), else tomorrow, and is handed to `bd update --defer` as `AAAA-MM-JJTHH:MM:00`,
49
- * the form bd reads as that wall time (bd reads a space-separated `AAAA-MM-JJ HH:MM` with the
50
- * month and the day taken for the hour); any other form goes to bd as written. `quand` is the phrase of the texts (« reportée <quand> »).
51
- * @param {string} heure
52
- * @param {Date} maintenant
53
- * @returns {{ defer: string, quand: string }}
54
- */
55
- export function heureDuReport(heure, maintenant) {
56
- const lue = /^(\d{1,2}):([0-5]\d)$/.exec(heure);
57
- if (!lue || Number(lue[1]) > 23) {
58
- return { defer: heure, quand: `au ${heure}` };
47
+ /** The refusal of an hour of deferral, which cites the forms accepted. */
48
+ export const REFUS_DE_L_HEURE =
49
+ '--reporter attend son heure, à venir : H:MM, AAAA-MM-JJ, AAAA-MM-JJ HH:MM, AAAA-MM-JJTHH:MM, +6h (en heures) ou +2d (en jours).';
50
+
51
+ const deux = n => String(n).padStart(2, '0');
52
+ // The local wall time of <d> as bd reads it, `AAAA-MM-JJTHH:MM:00`.
53
+ const pourBd = d =>
54
+ `${d.getFullYear()}-${deux(d.getMonth() + 1)}-${deux(d.getDate())}T${deux(d.getHours())}:${deux(d.getMinutes())}:00`;
55
+
56
+ // The next occurrence of the lone hour <heures>:<minutes> after <maintenant>.
57
+ function prochaine(heure, heures, minutes, maintenant) {
58
+ if (heures > 23) {
59
+ return null;
59
60
  }
60
61
  const cible = new Date(maintenant);
61
- cible.setHours(Number(lue[1]), Number(lue[2]), 0, 0);
62
+ cible.setHours(heures, minutes, 0, 0);
62
63
  const demain = cible.getTime() <= maintenant.getTime();
63
64
  if (demain) {
64
65
  cible.setDate(cible.getDate() + 1);
65
66
  }
66
- const deux = (n) => String(n).padStart(2, '0');
67
67
  const hhmm = `${deux(cible.getHours())}:${deux(cible.getMinutes())}`;
68
- const defer = `${cible.getFullYear()}-${deux(cible.getMonth() + 1)}-${deux(cible.getDate())}T${hhmm}:00`;
69
- return { defer, quand: demain ? `à demain ${hhmm}` : `au ${heure}` };
68
+ return { defer: pourBd(cible), quand: demain ? `à demain ${hhmm}` : `au ${heure}` };
69
+ }
70
+
71
+ /**
72
+ * The hour of a deferral (`--reporter <heure>`), read here alone: what `bd update --defer`
73
+ * receives and the phrase of the texts (« reportée <quand> »), or null for a form refused, an
74
+ * impossible date or hour, or a time not strictly after <maintenant>. A lone hour (`H:MM` or
75
+ * `HH:MM`) aims at its next occurrence in the machine's local time, today when strictly after
76
+ * <maintenant> (to the second), else tomorrow. A date (`AAAA-MM-JJ`, at midnight) and a date and
77
+ * hour (`AAAA-MM-JJ HH:MM` or `AAAA-MM-JJTHH:MM`) go to bd as `AAAA-MM-JJTHH:MM:00`, the form it
78
+ * reads as that wall time (bd reads a space-separated one with the month and the day taken for the
79
+ * hour). The durations `+<n>h` and `+<n>d` go as written.
80
+ * @param {string} heure
81
+ * @param {Date} maintenant
82
+ * @returns {{ defer: string, quand: string } | null}
83
+ */
84
+ export function heureDuReport(heure, maintenant) {
85
+ const seule = /^(\d{1,2}):([0-5]\d)$/.exec(heure);
86
+ if (seule) {
87
+ return prochaine(heure, Number(seule[1]), Number(seule[2]), maintenant);
88
+ }
89
+ const quand = `au ${heure}`;
90
+ const duree = /^\+(\d+)[hd]$/.exec(heure);
91
+ if (duree) {
92
+ return Number(duree[1]) > 0 ? { defer: heure, quand } : null;
93
+ }
94
+ const date = /^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2}))?$/.exec(heure);
95
+ if (!date) {
96
+ return null;
97
+ }
98
+ const [, annee, mois, jour, heures = '00', minutes = '00'] = date;
99
+ const cible = new Date(maintenant);
100
+ cible.setFullYear(Number(annee), Number(mois) - 1, Number(jour));
101
+ cible.setHours(Number(heures), Number(minutes), 0, 0);
102
+ // A date or an hour that does not exist rolls over to another one.
103
+ const defer = `${annee}-${mois}-${jour}T${heures}:${minutes}:00`;
104
+ return pourBd(cible) === defer && cible > maintenant ? { defer, quand } : null;
70
105
  }
71
106
 
72
107
  /**
@@ -103,3 +138,26 @@ export function reponseMecanique({ etat, sorte, commande, contexte }) {
103
138
  ? { sorte: { genre: 'mécanique', raison, commande: geste }, suivant: { etape: GESTE } }
104
139
  : { sorte: { genre: 'comportement', raison, comportement: 'inchangé' }, suivant: { etape: CODE } };
105
140
  }
141
+
142
+ /**
143
+ * The answer `--planifier --contexte <raison>` to the stop <etat> (`{ raison, motif, circuit }`,
144
+ * circuit.md §5.6): a refusal `{ refus }` unless a direct circuit is stopped on « besoin » or
145
+ * « hors-portee » with the motif « demande-un-plan », and with a reason; else `{}`.
146
+ * @param {{ etat: { etape: string, raison?: string | null, motif?: string | null,
147
+ * circuit?: string | null } | null, contexte: string | null }} o
148
+ * @returns {{ refus?: string }}
149
+ */
150
+ export function reponsePlanifier({ etat, contexte }) {
151
+ if (
152
+ etat?.motif !== DEMANDE_UN_PLAN ||
153
+ !['besoin', 'hors-portee'].includes(etat.raison ?? '') ||
154
+ (etat.circuit && etat.circuit !== 'direct')
155
+ ) {
156
+ return {
157
+ refus: `--planifier répond à un arrêt (besoin ou hors-portee) d’un circuit direct au motif « ${DEMANDE_UN_PLAN} » : le circuit est à ${etat?.etape ?? 'aucun état'}${etat?.raison ? `, arrêté sur ${etat.raison}` : ''}.`,
158
+ };
159
+ }
160
+ return String(contexte ?? '').trim()
161
+ ? {}
162
+ : { refus: '--planifier attend sa raison en --contexte.' };
163
+ }