@roomi-fields/grillhouse 0.45.1 → 0.46.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 (75) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +38 -0
  3. package/cadre/templates/projet/.github/workflows/machine-vierge.yml +101 -0
  4. package/cadre/templates/projet/CLAUDE.md +22 -5
  5. package/charte.md +45 -15
  6. package/dist/temporal/circuit/appel.d.ts +7 -0
  7. package/dist/temporal/circuit/appel.js +17 -0
  8. package/dist/temporal/circuit/appel.js.map +1 -1
  9. package/dist/temporal/circuit/client.d.ts +14 -0
  10. package/dist/temporal/circuit/client.js +17 -4
  11. package/dist/temporal/circuit/client.js.map +1 -1
  12. package/dist/temporal/circuit/commande.js +16 -4
  13. package/dist/temporal/circuit/commande.js.map +1 -1
  14. package/dist/temporal/circuit/contrat.d.ts +22 -2
  15. package/dist/temporal/circuit/contrat.js +76 -0
  16. package/dist/temporal/circuit/contrat.js.map +1 -1
  17. package/dist/temporal/circuit/deroule.js +68 -11
  18. package/dist/temporal/circuit/deroule.js.map +1 -1
  19. package/dist/temporal/file/contrat.d.ts +2 -0
  20. package/dist/temporal/tickets/activites.d.ts +1 -0
  21. package/dist/temporal/tickets/activites.js +37 -2
  22. package/dist/temporal/tickets/activites.js.map +1 -1
  23. package/dist/temporal/tickets/contrat.d.ts +14 -0
  24. package/dist/temporal/tickets/deroule.js +16 -3
  25. package/dist/temporal/tickets/deroule.js.map +1 -1
  26. package/docs/ARCHITECTURE.md +200 -54
  27. package/docs/INTERFACE.md +7 -4
  28. package/hooks/register.tsx +30 -0
  29. package/package.json +1 -1
  30. package/scripts/activites.mjs +55 -10
  31. package/scripts/attente-a-l-arret.mjs +29 -52
  32. package/scripts/attente-au-tour.mjs +8 -26
  33. package/scripts/circuit.mjs +204 -64
  34. package/scripts/circuits-cles.d.mts +9 -0
  35. package/scripts/circuits-cles.mjs +38 -0
  36. package/scripts/coeurs-dedies.mjs +4 -3
  37. package/scripts/dernier-vert.mjs +66 -2
  38. package/scripts/enveloppe/travail-de-la-copie.mjs +5 -2
  39. package/scripts/etapes.mjs +6 -1
  40. package/scripts/faits-du-circuit.mjs +22 -3
  41. package/scripts/fichiers-nommes.mjs +55 -0
  42. package/scripts/file-des-tickets.d.mts +17 -0
  43. package/scripts/file-des-tickets.mjs +39 -0
  44. package/scripts/grillhouse-maj.mjs +20 -1
  45. package/scripts/integration/file.mjs +11 -5
  46. package/scripts/integration/integrer.mjs +4 -2
  47. package/scripts/langages/cargo/clippy.mjs +16 -9
  48. package/scripts/langages/cargo/commandes.mjs +7 -2
  49. package/scripts/langages/cargo/sccache.mjs +19 -6
  50. package/scripts/langages/typescript/tests.mjs +31 -5
  51. package/scripts/langages/typescript/turbo-des-paquets.mjs +51 -3
  52. package/scripts/langages/typescript/vitest-config/changements.mjs +32 -3
  53. package/scripts/langages/typescript/vitest-config/lances.mjs +16 -0
  54. package/scripts/limite-d-usage.mjs +88 -0
  55. package/scripts/outils-cles.d.mts +13 -5
  56. package/scripts/outils-cles.mjs +157 -17
  57. package/scripts/passe-de-la-machine.mjs +26 -2
  58. package/scripts/places-de-la-machine.mjs +52 -6
  59. package/scripts/plafond-de-la-machine.d.mts +10 -2
  60. package/scripts/plafond-de-la-machine.mjs +39 -13
  61. package/scripts/reponses-du-circuit.d.mts +16 -0
  62. package/scripts/reponses-du-circuit.mjs +39 -3
  63. package/scripts/resultats.mjs +32 -11
  64. package/scripts/seances.mjs +211 -59
  65. package/scripts/session-start.sh +2 -2
  66. package/scripts/sous-commandes.mjs +5 -2
  67. package/scripts/superviseur.mjs +178 -226
  68. package/scripts/tableau.mjs +50 -37
  69. package/scripts/transitions.d.mts +22 -1
  70. package/scripts/transitions.mjs +111 -13
  71. package/scripts/workflows-du-cadre.mjs +21 -1
  72. package/skills/explorateur/SKILL.md +34 -13
  73. package/skills/pitmaster/SKILL.md +24 -20
  74. package/skills/relecteur/SKILL.md +6 -0
  75. package/skills/testwriter/SKILL.md +4 -0
@@ -1,10 +1,15 @@
1
1
  // The answers a circuit accepts from the supervisor, by the status of its workflow, with no input
2
2
  // nor output: the one rule the client (src/temporal/circuit/client.ts: its refusals and the
3
- // circuits it reads), the opening, the wait, the board and the line of a stop name.
3
+ // circuits it reads), the opening, the wait, the board and the line of a stop name; and the
4
+ // answer `--mecanique`, which turns the sort of a ticket stopped on the testwriter.
5
+ import { CODE, GESTE, TESTS } from './transitions.mjs';
4
6
 
5
7
  /** The statuses of a workflow ended without its issue. */
6
8
  export const SANS_ISSUE = new Set(['TERMINATED', 'FAILED', 'TIMED_OUT', 'CANCELLED']);
7
9
 
10
+ /** The stops of the testwriter that `--mecanique` answers: his question, his blocked word. */
11
+ export const ARRETS_DU_TESTWRITER = ['besoin', 'hors-portee'];
12
+
8
13
  /**
9
14
  * The answers accepted for the circuit of <ticket> whose workflow has the status <statut>, a state
10
15
  * written in its memo or not (<ecrit>), each a command between backquotes after the first, which
@@ -22,7 +27,38 @@ export function lesReponses(ticket, statut, ecrit) {
22
27
  return ecrit ? `${circuit} --reprendre\` ou \`${depuis}` : `${circuit} ${depuis}`;
23
28
  }
24
29
  const etendre = '--etendre <paquet>';
30
+ const mecanique = '--mecanique [<commande>] --contexte <raison>';
25
31
  return statut === 'RUNNING'
26
- ? `${circuit} --reprendre\`, \`${depuis}\`, \`${etendre}\`, \`--reporter <heure>\` ou \`--arreter`
27
- : `${circuit} --reprendre\`, \`${depuis}\` ou \`${etendre}`;
32
+ ? `${circuit} --reprendre\`, \`${depuis}\`, \`${mecanique}\`, \`${etendre}\`, \`--reporter <heure>\` ou \`--arreter`
33
+ : `${circuit} --reprendre\`, \`${depuis}\`, \`${mecanique}\` ou \`${etendre}`;
34
+ }
35
+
36
+ /**
37
+ * The answer `--mecanique [<commande>] --contexte <raison>` to the stop <etat> (`{ etape, raison }`)
38
+ * of a ticket of sort <sorte>: a refusal `{ refus }` unless the ticket is stopped on the testwriter
39
+ * (his question or his blocked word) with a reason, its sort not already mechanical; else the sort
40
+ * it becomes and the step the circuit resumes at, the plan kept as it is. With a <commande>, the
41
+ * gesture a command plays: sort mécanique, 1.1. Without, the gesture written by hand: sort
42
+ * comportement « inchangé », the developpeur writes and the existing suite makes the proof.
43
+ * @param {{ etat: { etape: string, raison?: string | null }, sorte: { genre: string },
44
+ * commande: string | null, contexte: string | null }} o
45
+ * @returns {{ refus: string } | { sorte: object, suivant: { etape: string } }}
46
+ */
47
+ export function reponseMecanique({ etat, sorte, commande, contexte }) {
48
+ if (etat?.etape !== TESTS || !ARRETS_DU_TESTWRITER.includes(etat.raison ?? '')) {
49
+ return {
50
+ refus: `--mecanique répond à un arrêt du testwriter (besoin ou hors-portee) : le circuit est à ${etat?.etape ?? 'aucun état'}${etat?.raison ? `, arrêté sur ${etat.raison}` : ''}.`,
51
+ };
52
+ }
53
+ const raison = String(contexte ?? '').trim();
54
+ if (!raison) {
55
+ return { refus: '--mecanique attend sa raison en --contexte.' };
56
+ }
57
+ if (sorte?.genre === 'mécanique') {
58
+ return { refus: 'le ticket est déjà mécanique : sa commande est celle de son plan.' };
59
+ }
60
+ const geste = String(commande ?? '').trim();
61
+ return geste
62
+ ? { sorte: { genre: 'mécanique', raison, commande: geste }, suivant: { etape: GESTE } }
63
+ : { sorte: { genre: 'comportement', raison, comportement: 'inchangé' }, suivant: { etape: CODE } };
28
64
  }
@@ -68,11 +68,12 @@
68
68
  // language, the architecture, a gap to the reference, or no answer (BP 328: a question the
69
69
  // ticket settled stopped the plan) (explorateur);
70
70
  // - `sorte` (`genre` mécanique or comportement, its `raison`, the `commande` a mechanical ticket
71
- // plays, and, for a comportement, `comportement` changé or inchangé): as Google's large-scale
72
- // changes let a tool make a change that a verification and a review judge (Rosie, ClangMR),
73
- // a ticket the plan says mechanical skips the testwriter, the proof and the developpeur, and
74
- // under a plan « comportement inchangé » every green of the proof is expected and the
75
- // developpeur writes the code; a sort
71
+ // plays, and, for a comportement, `comportement` changé, tests-adaptés or inchangé): as
72
+ // Google's large-scale changes let a tool make a change that a verification and a review
73
+ // judge (Rosie, ClangMR), a ticket the plan says mechanical skips the testwriter, the proof
74
+ // and the developpeur; under « tests-adaptés » the testwriter writes and every green of the
75
+ // proof is expected, then the developpeur writes; under « inchangé » (a gesture written by
76
+ // hand) the developpeur alone writes, no testwriter; a sort
76
77
  // absent, out of its kinds, or without its reason or its command is comportement, the whole
77
78
  // circuit (`sorteDuPlan`, grillhouse-sos) (explorateur);
78
79
  // - `ecartes` (`composant`, `raison`): the components of the survey the plan does not touch,
@@ -213,6 +214,10 @@ const VERDICTS_PROUVES = ['traitee', 'a-porter'];
213
214
  // The sorts of a ticket the explorateur judges at the plan (grillhouse-sos): a gesture without new
214
215
  // behaviour, which its command makes, or a change of behaviour, which the circuit of code makes.
215
216
  export const SORTES = ['mécanique', 'comportement'];
217
+ // The values of the field `comportement` of a plan of sort comportement: changé (the testwriter
218
+ // writes, a red is required), tests-adaptés (the testwriter writes, the proof accepts every
219
+ // green), inchangé (a gesture written by hand: the developpeur alone, no testwriter).
220
+ export const COMPORTEMENTS = ['changé', 'tests-adaptés', 'inchangé'];
216
221
 
217
222
  // The schema of the sheet of each role the circuit leads, and of the tri of the discoveries
218
223
  // (`tri`), the explorateur's after the queue.
@@ -241,9 +246,9 @@ const FICHES = {
241
246
  ),
242
247
  comportement: {
243
248
  type: 'string',
244
- enum: ['changé', 'inchangé'],
249
+ enum: COMPORTEMENTS,
245
250
  description:
246
- 'comportement : inchangé quand le lot ne change aucun comportement que ses tests mesurent (un test adapté, un seuil relevé dans un test) ; changé sinon.',
251
+ 'comportement : changé quand un test honnête peut rougir avant le lot (le testwriter écrit, un rouge est exigé) ; tests-adaptés quand le lot adapte des tests ou relève un seuil dans un test sans comportement neuf (le testwriter écrit, la preuve accepte chaque vert) ; inchangé pour un geste écrit à la main (commentaires, code supprimé…) : le développeur seul, sans testwriter, la suite existante faisant la preuve. Le doute vaut changé.',
247
252
  },
248
253
  },
249
254
  ['genre', 'raison'],
@@ -333,6 +338,12 @@ const FICHES = {
333
338
  ),
334
339
  'Les tests du lot qui portent le travail du ticket : la preuve du rouge exige qu’ils échouent avant le code.'
335
340
  ),
341
+ motif: {
342
+ type: 'string',
343
+ enum: ['aucun-comportement'],
344
+ description:
345
+ 'BESOIN ou BLOQUÉ : aucun comportement n’est à tester, aucun test honnête ne peut rougir avant le lot ; le superviseur bascule le ticket en circuit court (`--mecanique`).',
346
+ },
336
347
  ...DECOUVERTES,
337
348
  },
338
349
  ['statut']
@@ -383,6 +394,12 @@ const FICHES = {
383
394
  relecteur: objet(
384
395
  {
385
396
  verdict: { type: 'string', enum: ['ACCEPTÉ', 'RENDU'] },
397
+ motif: {
398
+ type: 'string',
399
+ enum: ['comportement-change'],
400
+ description:
401
+ 'RENDU d’un lot du circuit court dont le comportement du produit change : le circuit reprend le ticket à 2 Tests sur le même plan, sa sorte changée en comportement.',
402
+ },
386
403
  conformite: liste(
387
404
  objet(
388
405
  {
@@ -505,8 +522,8 @@ export const schemaDeFiche = role => FICHES[role] ?? null;
505
522
 
506
523
  // The sort of the ticket the explorateur's sheet of the plan <fiche> says (`sorte`): `{ genre:
507
524
  // 'mécanique', raison, commande }` for a mechanical ticket with its reason and its command; else
508
- // `{ genre: 'comportement', raison, inchange }`, `inchange` for a plan « comportement inchangé »
509
- // with its reason. A sort absent, out of its kinds or without what it needs is comportement, the
525
+ // `{ genre: 'comportement', raison, comportement }`, `comportement` one of COMPORTEMENTS, changé
526
+ // when absent, unknown or without its reason. A sort absent, out of its kinds or without what it needs is comportement, the
510
527
  // whole circuit, as a doubt goes to the circuit (grillhouse-sos).
511
528
  export function sorteDuPlan(fiche) {
512
529
  const s = fiche?.sorte;
@@ -515,8 +532,12 @@ export function sorteDuPlan(fiche) {
515
532
  if (raison && s.genre === 'mécanique' && plein(s.commande)) {
516
533
  return { genre: 'mécanique', raison, commande: s.commande.trim() };
517
534
  }
518
- const inchange = Boolean(raison) && s.genre === 'comportement' && s.comportement === 'inchangé';
519
- return { genre: 'comportement', raison, inchange };
535
+ const valeur = raison && s.genre === 'comportement' ? s.comportement : null;
536
+ return {
537
+ genre: 'comportement',
538
+ raison,
539
+ comportement: COMPORTEMENTS.includes(valeur) ? valeur : 'changé',
540
+ };
520
541
  }
521
542
 
522
543
  // The errors of <valeur> against <schema>, each naming its field by its path <ou>.
@@ -25,6 +25,7 @@ import {
25
25
  } from 'node:fs';
26
26
  import path from 'node:path';
27
27
  import { GREFFON } from './cadre.mjs';
28
+ import { avecLeFichierDuPoste, configurationDuPoste } from './fichier-du-poste.mjs';
28
29
  import { ecrireLaListe } from './enveloppe/paquets-du-plan.mjs';
29
30
  import { nomDuRole } from './etapes.mjs';
30
31
  import { departDe } from './mesure/base-de-passe.mjs';
@@ -47,6 +48,8 @@ import {
47
48
  nomsDe,
48
49
  } from './ticket-du-circuit.mjs';
49
50
  import { emettre } from './effets.mjs';
51
+ import { fichierNommeAuTicket } from './fichiers-nommes.mjs';
52
+ import { limiteDUsage } from './limite-d-usage.mjs';
50
53
  import { AttenteDeLaMachine } from './attente-de-la-machine.mjs';
51
54
 
52
55
  // The number of the next files of a session in the working directory <dossier> of the ticket: one
@@ -257,12 +260,15 @@ export async function lancer(
257
260
  // A file, not a pipe: a session whose circuit is dead writes its errors without breaking.
258
261
  const erreurs = path.join(ctx.tmp, `erreurs-${numero}.txt`);
259
262
  let commande;
260
- let fds;
263
+ // Its result ranged under its id, as lancer.sh ranges a session's: claude's output, then its
264
+ // exit code once it ends, written by the shell that runs it, which outlives a dead circuit.
265
+ const ouvrirLesFds = () =>
266
+ horsEnveloppe
267
+ ? [openSync(fichier, 'r'), openSync(rang.resultat, 'w'), openSync(ctx.journal, 'a')]
268
+ : ['ignore', 'ignore', openSync(erreurs, 'w')];
269
+ let fds = ouvrirLesFds();
261
270
  if (horsEnveloppe) {
262
271
  entete(ctx, role);
263
- // Its result ranged under its id, as lancer.sh ranges a session's: claude's output, then its
264
- // exit code once it ends, written by the shell that runs it, which outlives a dead circuit.
265
- fds = [openSync(fichier, 'r'), openSync(rang.resultat, 'w'), openSync(ctx.journal, 'a')];
266
272
  const fiche = [
267
273
  '--output-format',
268
274
  'json',
@@ -281,7 +287,6 @@ export async function lancer(
281
287
  cwd: existsSync(ctx.copie) ? ctx.copie : ctx.racine,
282
288
  };
283
289
  } else {
284
- fds = ['ignore', 'ignore', openSync(erreurs, 'w')];
285
290
  commande = {
286
291
  cmd: 'bash',
287
292
  args: [
@@ -324,58 +329,74 @@ export async function lancer(
324
329
  }
325
330
  throw new Arret('a-repasser', e.message);
326
331
  }
332
+ // The key of the API (`cleDeLAPI`): taken for the first attempt, never for the second.
333
+ const cle = cleDeLAPI();
334
+ const fermer = () => {
335
+ for (const fd of new Set(fds.filter(f => typeof f === 'number'))) {
336
+ closeSync(fd);
337
+ }
338
+ };
327
339
  // The session writes at the ticket under the author of its role (the mark of its place,
328
340
  // `place.env`); the passes it plays out of the envelope take their own part of the machine,
329
341
  // those it plays in its envelope none (its place covers them).
330
342
  // A session out of the envelope (the relecteur, which plays tests) plays them on its share of
331
343
  // the cores, under nice and ionice; the launcher of an enveloped one does it in the envelope.
332
- const lancement = horsEnveloppe
333
- ? lancementDeLaPasse({
334
- lourde: false,
335
- cmd: commande.cmd,
336
- args: commande.args,
337
- env: { ...process.env, ...place.env, [ACTEUR]: role },
338
- })
339
- : {
340
- cmd: commande.cmd,
341
- args: commande.args,
342
- env: { ...process.env, ...place.env, [ACTEUR]: role },
343
- };
344
- const fermer = () => {
345
- for (const fd of new Set(fds.filter(f => typeof f === 'number'))) {
346
- closeSync(fd);
344
+ const jouer = async base => {
345
+ const env = { ...base, ...place.env, [ACTEUR]: role };
346
+ const lancement = horsEnveloppe
347
+ ? lancementDeLaPasse({ lourde: false, cmd: commande.cmd, args: commande.args, env })
348
+ : { cmd: commande.cmd, args: commande.args, env };
349
+ const r = await jouerLeGroupe({
350
+ cmd: lancement.cmd,
351
+ args: lancement.args,
352
+ cwd: commande.cwd,
353
+ env: lancement.env,
354
+ stdio: fds,
355
+ seanceId: id,
356
+ lancement: identite,
357
+ immobileMs: ctx.immobileMs,
358
+ traces,
359
+ signeDeVie,
360
+ annulation,
361
+ lance: enfant => {
362
+ fermer();
363
+ // The place is the session's own from now on: its process and its start, so that it is
364
+ // freed with the session, even if the circuit dies before.
365
+ if (enfant.pid) {
366
+ place.rattacher({ pid: enfant.pid, depart: departDe(enfant.pid) });
367
+ }
368
+ },
369
+ });
370
+ if (r.pid === null && r.annulee) {
371
+ fermer();
372
+ }
373
+ if (r.annulee) {
374
+ place.rendre();
375
+ throw new SeanceAnnulee(role);
347
376
  }
377
+ return r;
348
378
  };
349
- const r = await jouerLeGroupe({
350
- cmd: lancement.cmd,
351
- args: lancement.args,
352
- cwd: commande.cwd,
353
- env: lancement.env,
354
- stdio: fds,
355
- seanceId: id,
356
- lancement: identite,
357
- immobileMs: ctx.immobileMs,
358
- traces,
359
- signeDeVie,
360
- annulation,
361
- lance: enfant => {
362
- fermer();
363
- // The place is the session's own from now on: its process and its start, so that it is
364
- // freed with the session, even if the circuit dies before.
365
- if (enfant.pid) {
366
- place.rattacher({ pid: enfant.pid, depart: departDe(enfant.pid) });
367
- }
368
- },
369
- });
370
- if (r.pid === null && r.annulee) {
371
- fermer();
379
+ let r = await jouer(cle?.env ?? process.env);
380
+ let sortie = lireLaSortie(rang);
381
+ const motif = cle ? motifDeRefus(sortie) : null;
382
+ if (cle && motif) {
383
+ // The API refused the key: the session plays again, once, on the subscription, under the same
384
+ // id, which the refused attempt opened: claude refuses a second `--session-id` of it
385
+ // (« already in use »), so the relaunch resumes it (`--resume`, `--reprise` of the launcher).
386
+ // The refusal is neither a failure nor a second session.
387
+ noterLeMois(ctx, cle.dossier, motif);
388
+ commande.args = commande.args.map(a =>
389
+ a === '--session-id' ? '--resume' : a === '--seance' ? '--reprise' : a
390
+ );
391
+ rmSync(rang.fin, { force: true });
392
+ rmSync(rang.resultat, { force: true });
393
+ fds = ouvrirLesFds();
394
+ const { ANTHROPIC_API_KEY: _cle, ...sansCle } = process.env;
395
+ r = await jouer(sansCle);
396
+ sortie = lireLaSortie(rang);
372
397
  }
373
398
  place.rendre();
374
- if (r.annulee) {
375
- throw new SeanceAnnulee(role);
376
- }
377
399
  let seance;
378
- let sortie;
379
400
  let horsPlan = null;
380
401
  let ecriture = null;
381
402
  if (horsEnveloppe) {
@@ -384,7 +405,6 @@ export async function lancer(
384
405
  : r.erreur === null
385
406
  ? r.code
386
407
  : null;
387
- sortie = lire(rang.resultat).trim();
388
408
  appendFileSync(ctx.journal, `${sortie}\n`);
389
409
  spawnSync(process.execPath, [REGISTRE, '--copie', ctx.copie], {
390
410
  cwd: ctx.racine,
@@ -392,7 +412,6 @@ export async function lancer(
392
412
  });
393
413
  } else {
394
414
  seance = existsSync(rang.fin) ? Number(readFileSync(rang.fin, 'utf8').trim()) : null;
395
- sortie = lire(rang.resultat).trim();
396
415
  horsPlan = existsSync(rang.horsPlan) ? lire(rang.horsPlan).trim() : null;
397
416
  ecriture = ecritureRangee(rang);
398
417
  }
@@ -408,6 +427,73 @@ export async function lancer(
408
427
  };
409
428
  }
410
429
 
430
+ // The text a session ranged as its result, `lancer` reads it at the end of each attempt.
431
+ function lireLaSortie(rang) {
432
+ return lire(rang.resultat).trim();
433
+ }
434
+
435
+ // The API key of the poste (`api.env` of the frame's directory of configuration), applied to the
436
+ // environment of the circuit as the files of the poste are (`avecLeFichierDuPoste`): null when the
437
+ // circuit's environment already holds a key, when the month is noted (`api-epuise-AAAA-MM`, a
438
+ // file of presence whose existence alone is tested) or when the file is absent. Its `env` is the
439
+ // environment of the first attempt; its `dossier` the one the month is noted in.
440
+ function cleDeLAPI() {
441
+ const dossier = configurationDuPoste(process.env);
442
+ if (dossier === null || process.env.ANTHROPIC_API_KEY !== undefined) {
443
+ return null;
444
+ }
445
+ if (existsSync(path.join(dossier, `api-epuise-${leMois()}`))) {
446
+ return null;
447
+ }
448
+ const env = avecLeFichierDuPoste(process.env, { fichier: 'api.env' });
449
+ return env === process.env ? null : { env, dossier };
450
+ }
451
+
452
+ // The month of the day, `AAAA-MM`.
453
+ function leMois() {
454
+ const d = new Date();
455
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`;
456
+ }
457
+
458
+ // Why the API refused a session, from its result: only a JSON result of claude in error whose
459
+ // status or text is the empty credit's (400) or the refused key's (401) counts; any other result,
460
+ // a transient error of the API included, is null and follows the path of the failed sessions.
461
+ function motifDeRefus(sortie) {
462
+ let r;
463
+ try {
464
+ r = JSON.parse(sortie);
465
+ } catch {
466
+ return null;
467
+ }
468
+ // The probed form of a refusal: `is_error` true, `terminal_reason` "api_error", the API's status.
469
+ if (r?.is_error !== true || r.terminal_reason !== 'api_error') {
470
+ return null;
471
+ }
472
+ const texte = typeof r.result === 'string' ? r.result : '';
473
+ if (r.api_error_status === 401) {
474
+ return 'clé refusée';
475
+ }
476
+ if (r.api_error_status === 402 || texte.toLowerCase().includes('credit balance is too low')) {
477
+ return 'crédit épuisé';
478
+ }
479
+ return null;
480
+ }
481
+
482
+ // Notes the month in its file of presence, by an exclusive write: of the sessions refused together,
483
+ // the first to create it writes the line of the log, the others none.
484
+ function noterLeMois(ctx, dossier, motif) {
485
+ const mois = leMois();
486
+ try {
487
+ writeFileSync(path.join(dossier, `api-epuise-${mois}`), '', { flag: 'wx' });
488
+ } catch {
489
+ return;
490
+ }
491
+ appendFileSync(
492
+ ctx.journal,
493
+ `la clé d'API est ${motif} : la séance repart sur l'abonnement, sans clé jusqu'à la fin de ${mois}\n`
494
+ );
495
+ }
496
+
411
497
  // The group of a session, as an activity of Temporal runs a process: launched detached, the
412
498
  // leader of a process group of its own, it sends a sign of life (<signeDeVie>, `{ pid, depart,
413
499
  // seanceId, lancement }`: the leader of the group, its start, `departDe`, the id of the session
@@ -770,7 +856,9 @@ function ecritureRangee(rang) {
770
856
  return existsSync(rang.horsPlanFait) ? JSON.parse(lire(rang.horsPlanFait)) : null;
771
857
  }
772
858
 
773
- // The launch <r> of a session of <role>, or the Arret it is: a session its lock stopped on a
859
+ // The launch <r> of a session of <role>: `{ etendre: { paquet, chemin, piece } }` for a write out
860
+ // of the plan in a file the ticket names (the plan extends, the session resumes), nothing for a
861
+ // session that went its way, or the Arret it is: a session its lock stopped on a
774
862
  // write out of the plan (« hors-plan », the write as its piece), a motionless session
775
863
  // (« bloqué »), a launch that stops before its session (« lancement »).
776
864
  export function seanceLancee(ctx, role, r) {
@@ -778,6 +866,22 @@ export function seanceLancee(ctx, role, r) {
778
866
  // The lock's structured write: the first line of the report names the path and its package;
779
867
  // the question carries the command (none for the root, which no package holds).
780
868
  const ecriture = r.ecriture;
869
+ // A file the ticket's description names (its « Architecture » or a criterion) extends the plan
870
+ // to its package without a stop; the root, and the documents the responsable owns, still go up.
871
+ // A ticket that does not read names nothing: the stop goes up as it did.
872
+ let nomme = null;
873
+ if (ecriture && !ecriture.racine && typeof ctx.bd === 'function') {
874
+ try {
875
+ nomme = fichierNommeAuTicket(leTicket(ctx).description, ecriture.chemin);
876
+ } catch {
877
+ nomme = null;
878
+ }
879
+ }
880
+ if (nomme) {
881
+ return {
882
+ etendre: { paquet: ecriture.paquet, chemin: ecriture.chemin, piece: nomme.piece },
883
+ };
884
+ }
781
885
  const nom = ecriture ? (ecriture.racine ? 'la racine du dépôt' : ecriture.paquet) : null;
782
886
  const dit = ecriture ? `${ecriture.chemin} est dans ${nom}` : null;
783
887
  const question = !ecriture
@@ -815,6 +919,24 @@ export function seanceLancee(ctx, role, r) {
815
919
  }
816
920
  }
817
921
 
922
+ // The size in bytes of the ticket's log, 0 without it: where a launch's own lines begin.
923
+ function tailleDuJournal(ctx) {
924
+ try {
925
+ return statSync(ctx.journal).size;
926
+ } catch {
927
+ return 0;
928
+ }
929
+ }
930
+
931
+ // The lines the ticket's log gained since <depuis> bytes: the end of the log the launch wrote.
932
+ function finDuJournal(ctx, depuis) {
933
+ try {
934
+ return readFileSync(ctx.journal).subarray(depuis).toString('utf8');
935
+ } catch {
936
+ return '';
937
+ }
938
+ }
939
+
818
940
  // The relaunch of the event <evenement> the dead attempt <precedent> of <ctx> made last (2, its
819
941
  // resumption, or 1), when this attempt is one Temporal plays again and that session ranged its
820
942
  // result; else 1.
@@ -885,17 +1007,47 @@ export async function jusquALaFiche(ctx, role, texte, options = {}) {
885
1007
  }
886
1008
  reste.signeDeVie?.(vie);
887
1009
  };
1010
+ // The instruction of a resumption after the plan extended to a package the ticket names: the
1011
+ // session goes on where its lock stopped it, and the launch is neither a first nor a second.
1012
+ let etendu = null;
888
1013
  for (let essai = premier; essai <= 2; essai++) {
889
1014
  const courte = () => consigne({ ticket: ctx.ticket, sujet: ctx.sujet, erreur: lu.erreur }, 2);
890
- const r = await lancer(ctx, role, essai === 1 || !lu ? texte : courte(), {
891
- ...reste,
892
- precedent: derniere,
893
- evenement,
894
- relance: essai,
895
- signeDeVie,
896
- ...ouvrir(essai === 1 ? premiere : 'reprend'),
897
- });
898
- seanceLancee(ctx, role, r);
1015
+ const avantLeJournal = tailleDuJournal(ctx);
1016
+ const r = await lancer(
1017
+ ctx,
1018
+ role,
1019
+ etendu ?? (essai === 1 || !lu ? texte : courte()),
1020
+ {
1021
+ ...reste,
1022
+ precedent: derniere,
1023
+ evenement,
1024
+ relance: essai,
1025
+ signeDeVie,
1026
+ ...ouvrir(etendu || essai > 1 ? 'reprend' : premiere),
1027
+ }
1028
+ );
1029
+ etendu = null;
1030
+ // The usage limit stops a session that does not end on its own: neither a sheet missing nor a
1031
+ // sheet to resume, the circuit waits for the hour the usage returns (« limite-d-usage »).
1032
+ const limite =
1033
+ !r.horsPlan && r.seance !== 0
1034
+ ? limiteDUsage({ resultat: r.sortie, journal: finDuJournal(ctx, avantLeJournal) })
1035
+ : null;
1036
+ if (limite) {
1037
+ throw new Arret(
1038
+ 'limite-d-usage',
1039
+ `La séance du ${nomDuRole(role)} est arrêtée par la limite d'usage ; elle reprend ${limite.lisible ? `à l'heure que la limite donne (${new Date(limite.reprise).toISOString()})` : "dans une heure, la limite ne donne aucune heure lisible"}.`,
1040
+ { resultat: limite }
1041
+ );
1042
+ }
1043
+ const extension =seanceLancee(ctx, role, r)?.etendre;
1044
+ if (extension) {
1045
+ ctx.etendreEnVol(extension);
1046
+ courante = r.id ?? courante;
1047
+ etendu = `Le plan du ticket s'étend à ${extension.paquet} (${extension.piece}) : le crochet qui t'a arrêté sur ${extension.chemin} le laisse maintenant passer. Reprends ta tâche là où il t'a arrêté.`;
1048
+ essai--;
1049
+ continue;
1050
+ }
899
1051
  courante = r.id ?? courante;
900
1052
  if (repli && r.seance !== 0) {
901
1053
  return null;
@@ -40,8 +40,8 @@
40
40
  #
41
41
  # One supervisor per project (scripts/superviseur.mjs): the session takes the lock of its
42
42
  # repository, and, when its opening takes the lock (not when it keeps it, after a compaction or a
43
- # /clear), receives the section « L'attente des questions », the wait to launch in the background,
44
- # then « Les circuits du dépôt » when there are some: each circuit that runs, each one stopped on a
43
+ # /clear), receives the section « Les questions des circuits » (the greffon pushes the questions, the answer
44
+ # acknowledges them; no wait to launch), then « Les circuits du dépôt » when there are some: each circuit that runs, each one stopped on a
45
45
  # question with its question and the command that answers it, each one whose workflow ended
46
46
  # without its issue with the command that resumes it; a second session, while the first one lives, receives first the section « Un autre
47
47
  # superviseur tient ce dépôt », which asks it to say so to the owner and to launch no circuit. An
@@ -22,7 +22,7 @@ import path from 'node:path';
22
22
  import { fileURLToPath } from 'node:url';
23
23
  import { langageDe } from './langages.mjs';
24
24
  import { avecLesDonnees, donneesDe } from './donnees-cles.mjs';
25
- import { avecLesOutils, outilsDe } from './outils-cles.mjs';
25
+ import { avecLesOutils, empreintesDe, outilsDe } from './outils-cles.mjs';
26
26
 
27
27
  const SCRIPTS = path.dirname(fileURLToPath(import.meta.url));
28
28
 
@@ -155,7 +155,10 @@ export function environnementDe(nom, racine = process.cwd(), env = process.env)
155
155
  return env;
156
156
  }
157
157
  const poste = langageDe(racine).environnementDuPoste(env);
158
- return avecLesDonnees(donneesDe(racine), avecLesOutils(outilsDe(racine), poste));
158
+ return avecLesDonnees(
159
+ donneesDe(racine),
160
+ avecLesOutils(outilsDe(racine), poste, empreintesDe(racine))
161
+ );
159
162
  }
160
163
 
161
164
  // The script of each subcommand in the project at <racine>, where a former copy of the frame lay