@roomi-fields/grillhouse 0.51.0 → 0.52.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 (60) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +20 -0
  3. package/charte/plan.md +47 -0
  4. package/charte/preuve.md +39 -0
  5. package/charte/superviseur.md +61 -0
  6. package/charte/tests.md +38 -0
  7. package/charte.md +22 -177
  8. package/dist/temporal/circuit/client.d.ts +1 -2
  9. package/dist/temporal/circuit/client.js +1 -2
  10. package/dist/temporal/circuit/client.js.map +1 -1
  11. package/docs/INTERFACE.md +4 -3
  12. package/docs/architecture/circuit.md +2 -2
  13. package/docs/architecture/entree.md +1 -1
  14. package/docs/architecture/greffon.md +43 -18
  15. package/docs/architecture/installation.md +17 -7
  16. package/docs/architecture/machine.md +30 -3
  17. package/docs/architecture/tests.md +8 -3
  18. package/docs/lexique.md +10 -1
  19. package/hooks/hooks.json +0 -10
  20. package/hooks/register.tsx +91 -3
  21. package/package.json +2 -1
  22. package/scripts/activites.mjs +20 -5
  23. package/scripts/aiguillage.mjs +0 -1
  24. package/scripts/attente-au-tour.mjs +2 -3
  25. package/scripts/bilan.mjs +116 -56
  26. package/scripts/bilans-gardes.mjs +37 -0
  27. package/scripts/circuit.mjs +3 -1
  28. package/scripts/direct.mjs +1 -1
  29. package/scripts/droits.mjs +115 -36
  30. package/scripts/entree-de-seance.mjs +35 -0
  31. package/scripts/enveloppe/enveloppe.mjs +23 -16
  32. package/scripts/enveloppe/lancer.sh +32 -22
  33. package/scripts/enveloppe/travail-de-la-copie.mjs +77 -0
  34. package/scripts/jointure.d.ts +2 -1
  35. package/scripts/langages/python/commandes.mjs +50 -7
  36. package/scripts/langages/python/squelette.mjs +2 -1
  37. package/scripts/langages/typescript/index.mjs +12 -12
  38. package/scripts/langages/typescript/turbo-des-paquets.mjs +52 -2
  39. package/scripts/langages/typescript/verifier.mjs +27 -2
  40. package/scripts/migrations/serveurs-de-l-index.mjs +1 -1
  41. package/scripts/migrations/suivi-du-superviseur-retire.mjs +56 -0
  42. package/scripts/migrations.mjs +2 -0
  43. package/scripts/nuit.sh +3 -2
  44. package/scripts/paquet.mjs +1 -1
  45. package/scripts/resultats.mjs +2 -2
  46. package/scripts/seances.mjs +53 -26
  47. package/scripts/session-start.sh +8 -6
  48. package/scripts/sortie-de-seance.mjs +70 -0
  49. package/scripts/sous-commandes.mjs +0 -1
  50. package/scripts/superviseur.mjs +373 -155
  51. package/scripts/tableau.mjs +127 -49
  52. package/skills/explorateur/SKILL.md +2 -2
  53. package/skills/grill/SKILL.md +3 -2
  54. package/skills/pitmaster/SKILL.md +68 -34
  55. package/skills/pitmaster/references/cadre.md +1 -1
  56. package/skills/pitmaster/references/tour.md +6 -5
  57. package/skills/relecteur/SKILL.md +1 -1
  58. package/skills/testwriter/SKILL.md +2 -2
  59. package/cadre/templates/projet/pitmaster/SUIVI.md +0 -22
  60. package/scripts/attente-a-l-arret.mjs +0 -114
@@ -3,7 +3,7 @@
3
3
  // Mechanism: greffon.md, §5.1 and §5.2. Played by the session start (scripts/session-start.sh),
4
4
  // which writes what it says to the session.
5
5
  //
6
- // npx grillhouse superviseur <racine>
6
+ // npx grillhouse superviseur <racine> [<source>]
7
7
  //
8
8
  // - Out of a git repository, in an agent's copy (a worktree whose git directory is not the common
9
9
  // one) and in a session of a role that the circuit launches (BEADS_ACTOR set), nothing is taken
@@ -12,11 +12,16 @@
12
12
  // copies, taken through scripts/verrou-de-fichier.mjs for the session's own process: the first
13
13
  // process above this one named `claude`, whatever stands between them; without one, the first
14
14
  // that is not a shell (sh, bash, dash, zsh). It holds as long as that process lives.
15
- // - Free, or held by a process that is gone: taken, nothing said. Held by the session itself (a
16
- // compaction or a /clear): kept, nothing said, circuits included. Held by another live session:
17
- // the section « ## Un autre superviseur tient ce dépôt » names its process and since when, and
18
- // asks to say so to the owner and to launch no circuit.
19
- // - The session whose opening takes the lock (`circuitsALOuverture`) receives « ## Les questions
15
+ // - <source> is the one of the SessionStart hook (`startup` without one). Free, or held by a
16
+ // process that is gone: taken. Held by the session itself: kept, and nothing is said after a
17
+ // compaction or a resume. After a /clear, the session that holds the lock receives « ## Reprise
18
+ // de la supervision après un /clear » (load `grillhouse:pitmaster`, take up the note of
19
+ // resumption, no whole round, put the owner's pending question again at the first turn), then
20
+ // what a session that takes the lock receives. Held by another live session: the section « ## Un
21
+ // autre superviseur tient ce dépôt » names its process and since when, and asks to say so to the
22
+ // owner and to launch no circuit. A declared milestone ends with the context that declared it: it
23
+ // is removed at every opening of the holder but after a compaction.
24
+ // - The session whose opening takes the lock (`ouvertureDuSuperviseur`) receives « ## Les questions
20
25
  // des circuits », then, when the repository has circuits (read from the Temporal server in one
21
26
  // call, scripts/circuits-du-serveur.mjs), « ## Les circuits du dépôt »: each circuit that runs;
22
27
  // each circuit stopped on a question, with the command that answers it; each circuit ended
@@ -24,9 +29,25 @@
24
29
  // written, else `--depuis <testwriter|developpeur> --contexte <texte>`); a server that does not
25
30
  // answer is said; then « ## La file des tickets », the tickets of the queue without their
26
31
  // section « ## Architecture », which the queue never starts (scripts/file-des-tickets.mjs).
32
+ // Last, « ## La note de reprise » gives the note of resumption, when one is written.
27
33
  // Exit 0, whatever it finds.
28
34
  //
29
- // npx grillhouse superviseur --relever [<dossier>]
35
+ // npx grillhouse superviseur --jalon <fichier>
36
+ // npx grillhouse superviseur --question <fichier>
37
+ //
38
+ // - Played by the session that holds the lock, from the root of the repository. The note of
39
+ // resumption, one per repository, is `<git common dir>/grillhouse-reprise.md`. `--jalon` replaces
40
+ // it whole by the text of <fichier> and declares a milestone, which replaces the one before
41
+ // (`<git common dir>/grillhouse-jalon.json`); `--question` adds the text at its end, creating it,
42
+ // and declares nothing. Exit 2 and the reason on the error stream, nothing written, on a file
43
+ // that is absent or empty, a session that does not hold the lock, a session of a role or a copy.
44
+ //
45
+ // npx grillhouse superviseur --renouveler <dossier> <arretA> <messageA>
46
+ //
47
+ // - Played by the greffon at each period: writes the message of resumption when the renewal is due
48
+ // (`renouvellement`), nothing otherwise.
49
+ //
50
+ // npx grillhouse superviseur --relever [<dossier>] [--compaction]
30
51
  //
31
52
  // - One reading of the circuits for the greffon (mods/grillhouse/hooks/register.tsx), which runs
32
53
  // it at each period and submits what it writes. It reads and writes nothing unless the session
@@ -34,26 +55,30 @@
34
55
  // reads. It writes the message (`texteDesQuestions`) when `relever` gives something, nothing
35
56
  // otherwise; exit 1 and the fault on the error stream when `grillhouse.rappel` of the project is
36
57
  // at fault, or when the reading of another project of the group fails, the message of the others
37
- // then written all the same.
58
+ // then written all the same. The message ends with the request to write the note and declare a
59
+ // milestone after a compaction (`--compaction`), and once for each night
60
+ // (`grillhouse.plageDeNuit`) at a reading where no question of a circuit waits for the
61
+ // supervisor.
38
62
  // - `superviseur --lue <dossier> <lueA> <envoyeesAvant>` marks read the questions sent up to
39
63
  // `envoyeesAvant`; `superviseur --chez-le-responsable <dossier> <ticket>` marks a question
40
64
  // carried to the owner: silent until the circuit answers.
41
65
  // - `relever` is the one function of the reading, of the re-presentation and of the file of the
42
66
  // stops gone up: a question that never went up, or was read <rappelMs> ago (`grillhouse.rappel`
43
67
  // minutes, 10 by default, scripts/circuits-cles.mjs), is given once per due time while its
44
- // circuit stands on the same stop; one answered leaves the file
68
+ // circuit stands on the same stop; one addressed to the owner goes up once, without reminder,
69
+ // and the opening lists it; one answered leaves the file
45
70
  // `.claude/worktrees/questions-remontees.json`. A stop is kept there by its ticket, the run of
46
71
  // its workflow, the rank of its question in that run and its stop, with the times of the first
47
- // going up and of the last presentation. The end of a circuit integrated is given once
48
- // (`integre`), kept in `.claude/worktrees/integrations-rendues.json`, and the alert of the CI of
49
- // main (a red, or a CI not read, scripts/ci-de-main.mjs) once per passage
50
- // (`.claude/worktrees/ci-de-main-rendue.json`), cleared at the next green.
72
+ // going up and of the last presentation. The alert of the CI of main (a red, or a CI not read,
73
+ // scripts/ci-de-main.mjs) is given once per passage (`.claude/worktrees/ci-de-main-rendue.json`),
74
+ // cleared at the next green. A circuit integrated gives nothing: it is read on the board.
51
75
  // - The reading covers the project and each other project of its group (`grillhouse.groupe`) that
52
76
  // no other live session of supervision holds, each under its name and its folder.
53
77
  import { spawnSync } from 'node:child_process';
54
- import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
78
+ import { mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
55
79
  import path from 'node:path';
56
80
  import { pathToFileURL } from 'node:url';
81
+ import { nuitEnCours, plageDeNuit } from './bilan.mjs';
57
82
  import { lireEtOuvrirLeDefautDeMain } from './ci-de-main.mjs';
58
83
  import { lacherVerrou, prendreVerrou } from './verrou-de-fichier.mjs';
59
84
  import { vivant } from './mesure/base-de-passe.mjs';
@@ -67,7 +92,14 @@ import {
67
92
  } from './tableau.mjs';
68
93
  import { rappelDuProjet, reglageDuRappel } from './circuits-cles.mjs';
69
94
  import { lireGroupe } from './groupe-cles.mjs';
70
- import { etapeDuCircuit, libelle, REPONSES, sansLesReponses, SUPERVISEUR } from './etapes.mjs';
95
+ import {
96
+ etapeDuCircuit,
97
+ libelle,
98
+ REPONSES,
99
+ RESPONSABLE,
100
+ sansLesReponses,
101
+ SUPERVISEUR,
102
+ } from './etapes.mjs';
71
103
  import { sigleDuProjet } from './sigle-du-projet.mjs';
72
104
  import {
73
105
  enFileSansArchitecture,
@@ -78,6 +110,15 @@ import {
78
110
  } from './file-des-tickets.mjs';
79
111
 
80
112
  const VERROU_SUPERVISEUR = 'grillhouse-superviseur.lock';
113
+ // In the common directory of git: the note of resumption of the supervisor, its declared milestone,
114
+ // and the start of the last night whose request was given.
115
+ const NOTE_DE_REPRISE = 'grillhouse-reprise.md';
116
+ const JALON = 'grillhouse-jalon.json';
117
+ const DEMANDE_DE_NUIT = 'grillhouse-demande-de-nuit.json';
118
+ // The message the greffon submits once the /clear of a renewal is done; the note, the questions and
119
+ // the circuits come with the opening.
120
+ const MESSAGE_DE_REPRISE =
121
+ "Reprends la supervision : ta séance vient de se renouveler au jalon que tu as déclaré. L'ouverture te donne la note de reprise, les questions et les circuits : suis-la.";
81
122
  const COQUILLES = new Set(['sh', 'bash', 'dash', 'zsh']);
82
123
  // The name of the process of a session of the engine.
83
124
  const MOTEUR = 'claude';
@@ -194,21 +235,6 @@ const ou = c => {
194
235
  // of the circuits (scripts/tableau.mjs reads it: its alerts).
195
236
  const etatsDe = racine => path.join(racine, '.claude', 'worktrees');
196
237
 
197
- // The integrations given by the waits of the repository at <racine>: `depuis`, the time (ms) of
198
- // the last reading of the last wait, from which an integration is new; `rendues`, the keys of the
199
- // integrations it gave, ended at that time or after. Absent or unreadable: none since <maintenant>.
200
- const integrationsDe = racine => path.join(etatsDe(racine), 'integrations-rendues.json');
201
- function lireLesIntegrations(racine, maintenant) {
202
- try {
203
- const lu = JSON.parse(readFileSync(integrationsDe(racine), 'utf8'));
204
- if (Number.isFinite(lu?.depuis) && Array.isArray(lu?.rendues)) {
205
- return { depuis: lu.depuis, rendues: new Set(lu.rendues.map(String)) };
206
- }
207
- } catch {
208
- // none yet
209
- }
210
- return { depuis: maintenant, rendues: new Set() };
211
- }
212
238
  // The alert of the CI of main of the project at <racine> (scripts/ci-de-main.mjs), read for the
213
239
  // supervisor: `{ cle, texte }` for a red or a CI not read, null for a green (the alert clears),
214
240
  // undefined for a project with no CI to read. The lots entered since the last green are named by
@@ -264,19 +290,6 @@ function releverLaCiDeMain(racine, alerte, toutes) {
264
290
  ];
265
291
  }
266
292
 
267
- // A file that cannot be written never costs the batch: the next wait reads the former one.
268
- function ecrireLesIntegrations(racine, depuis, rendues) {
269
- const f = integrationsDe(racine);
270
- try {
271
- mkdirSync(path.dirname(f), { recursive: true });
272
- const provisoire = `${f}.${process.pid}`;
273
- writeFileSync(provisoire, `${JSON.stringify({ depuis, rendues: [...rendues].sort() })}\n`);
274
- renameSync(provisoire, f);
275
- } catch {
276
- // kept as it was
277
- }
278
- }
279
-
280
293
  // The file of the stops gone up as text: each stop with its key, its times, and its reading and its
281
294
  // mark when it has them, sorted by key.
282
295
  const enTexteDesRemontees = liste =>
@@ -357,23 +370,22 @@ export function marquerChezLeResponsable(racine, { cle, depuisA }) {
357
370
  }
358
371
 
359
372
  /**
360
- * One reading of the circuits <circuits> (those integrated included) of the repository at <racine>,
373
+ * One reading of the circuits <circuits> of the repository at <racine>,
361
374
  * at <maintenant> ms, under the lock of the file of the stops gone up; what the greffon of the
362
375
  * session of supervision submits, and the opening lists. Each stop that waits for the supervisor
363
- * and never went up, or whose last presentation is <rappelMs> ms old or more (<toutes>: every
364
- * one), is given, its ticket <fermes> gives closed left out (bd is asked of those alone); a stop
376
+ * and never went up, or whose last presentation is <rappelMs> ms old or more, is given (a
377
+ * question addressed to the owner goes up once and is never given again; <toutes>: every
378
+ * one), its ticket <fermes> gives closed left out (bd is asked of those alone); a stop
365
379
  * given is presented now, and one that goes up has its `depuis` set now. The file is written whole
366
380
  * with the stops that still stand, their circuit waiting for the supervisor: a question answered
367
- * so leaves it, and the next stop of its circuit is new. The end of a circuit integrated since the
368
- * last reading is given once (`integre`; the file of the integrations holds the time of that
369
- * reading), and the alert of the CI of main <ciDeMain> (`{ cle, texte }`; null at a green, which
370
- * clears it; undefined when it is not read, which keeps what was given) once per passage. The
371
- * result is the questions given, each marked `representee` when it comes back, then the ends, then
372
- * the alert of the CI of main.
381
+ * so leaves it, and the next stop of its circuit is new. The alert of the CI of main <ciDeMain>
382
+ * (`{ cle, texte }`; null at a green, which clears it; undefined when it is not read, which keeps
383
+ * what was given) is given once per passage. A circuit integrated gives nothing. The result is the
384
+ * questions given, each marked `representee` when it comes back, then the alert of the CI of main.
373
385
  * @param {string} racine
374
386
  * @param {import('./circuits-du-serveur.mjs').CircuitDuServeur[]} circuits
375
387
  * @param {{ fermes: (racine: string, ids: string[]) => Set<string> | null, maintenant: number, rappelMs: number, toutes?: boolean, ciDeMain?: { cle: string, texte: string } | null }} options
376
- * @returns {{ ticket: string, etape: string, question: string, qui: string, commande: string, cle: string, representee?: boolean, integre?: boolean }[]}
388
+ * @returns {{ ticket: string, etape: string, question: string, qui: string, commande: string, cle: string, representee?: boolean }[]}
377
389
  */
378
390
  export function relever(
379
391
  racine,
@@ -386,34 +398,21 @@ export function relever(
386
398
  // Held for one reading of the circuits: older than that, abandoned.
387
399
  prendreVerrou(verrou, { attendre: true, perime: 30_000 });
388
400
  try {
389
- const { depuis: depuisIntegrations, rendues } = lireLesIntegrations(racine, maintenant);
390
- const integres = circuits
391
- .filter(
392
- c => c.integre && c.fin !== null && c.fin >= depuisIntegrations && !rendues.has(cleDe(c))
393
- )
394
- .map(enFin)
395
- .sort((a, b) => a.ticket.localeCompare(b.ticket, 'en'));
396
- const fins = new Map(circuits.map(c => [cleDe(c), c.fin]));
397
- ecrireLesIntegrations(
398
- racine,
399
- maintenant,
400
- [...rendues, ...integres.map(i => i.cle)].filter(
401
- k => (fins.get(k) ?? -Infinity) >= maintenant
402
- )
403
- );
404
401
  const rouges = ciDeMain === undefined ? [] : releverLaCiDeMain(racine, ciDeMain, toutes);
405
- circuits = circuits.filter(c => !c.integre);
406
402
  const avant = new Map(lireLesRemontees(racine, maintenant).map(r => [r.cle, r]));
407
403
  const debout = questionsEnAttente(racine, circuits, { fermes: aucunFerme });
408
- // A question comes back from its reading, never from its sending: one read, not carried to the
409
- // owner, whose delay has passed since its reading. One still in the queue (sent, unread) or
410
- // carried to the owner is never given again.
404
+ // A question comes back from its reading, never from its sending: one read, waiting for the
405
+ // supervisor, not carried to the owner, whose delay has passed since its reading. One still in
406
+ // the queue (sent, unread), addressed to the owner or carried to him is never given again.
411
407
  const aRendre = debout.filter(q => {
412
408
  const r = avant.get(q.cle);
413
409
  return (
414
410
  toutes ||
415
411
  !r ||
416
- (estLue(r) && r.chez === undefined && maintenant - r.lue >= rappelMs)
412
+ (q.qui !== RESPONSABLE &&
413
+ estLue(r) &&
414
+ r.chez === undefined &&
415
+ maintenant - r.lue >= rappelMs)
417
416
  );
418
417
  });
419
418
  const fermesDe = aRendre.length
@@ -449,7 +448,7 @@ export function relever(
449
448
  })
450
449
  );
451
450
  ecrireLesRemontees(racine, ecrit, debout.length === 0 && avant.size === 0);
452
- return [...rendu, ...integres, ...rouges];
451
+ return [...rendu, ...rouges];
453
452
  } finally {
454
453
  lacherVerrou(verrou);
455
454
  }
@@ -471,17 +470,6 @@ const enQuestion = c => ({
471
470
  arret: c.arret,
472
471
  });
473
472
 
474
- // The end of the circuit <c> integrated, given once by the wait: its ticket, its step, and its key.
475
- const enFin = c => ({
476
- ticket: c.ticket,
477
- etape: '5 Intégration',
478
- question: 'son lot est sur main.',
479
- qui: SUPERVISEUR,
480
- commande: '',
481
- cle: cleDe(c),
482
- integre: true,
483
- });
484
-
485
473
  // Of the circuits <lus> of the repository at <racine>, those whose ticket <fermes> does not give
486
474
  // closed, sorted by ticket.
487
475
  function enAttente(lus, racine, fermes) {
@@ -578,19 +566,13 @@ export const ligneDeQuestion = (q, o = {}) => {
578
566
  /**
579
567
  * The message the greffon submits to the session of supervision for the questions <questions> of
580
568
  * one reading (`relever`), and the lines of the opening: for each one, its ticket, step, who must
581
- * answer it, its question and the command that answers it; then each end of a circuit integrated
582
- * (`integre`), its ticket and its step. A question presented again (`representee`) says that it
583
- * still waits for an answer.
584
- * @param {{ ticket: string, etape: string, question: string, qui: string, commande: string, representee?: boolean, integre?: boolean }[]} questions
569
+ * answer it, its question and the command that answers it. A question presented again
570
+ * (`representee`) says that it still waits for an answer.
571
+ * @param {{ ticket: string, etape: string, question: string, qui: string, commande: string, representee?: boolean }[]} questions
585
572
  * @returns {string}
586
573
  */
587
574
  export function texteDesQuestions(questions, o = {}) {
588
- const fins = questions.filter(q => q.integre);
589
- const attente = questions.filter(q => !q.integre);
590
- return [
591
- ...attente.map(q => ligneDeQuestion(q, o)),
592
- ...fins.map(q => `${o.sigle ? `[${o.sigle}] ` : ''}Intégré · ${q.ticket}`),
593
- ].join('\n');
575
+ return questions.map(q => ligneDeQuestion(q, o)).join('\n');
594
576
  }
595
577
 
596
578
  /**
@@ -638,7 +620,6 @@ export async function circuitsALOuverture(
638
620
  ? `${e.message} : les circuits ne se lisent pas.`
639
621
  : `Les circuits ne se lisent pas : ${message}.`;
640
622
  }
641
- ecrireLesIntegrations(racine, Date.now(), []);
642
623
  const ouverteA = Date.now();
643
624
  const questions = circuits
644
625
  ? relever(racine, circuits, {
@@ -647,7 +628,7 @@ export async function circuitsALOuverture(
647
628
  rappelMs: rappelDuProjet(racine) * 60_000,
648
629
  toutes: true,
649
630
  ciDeMain: ciDeMainDe(racine),
650
- }).filter(q => !q.integre)
631
+ })
651
632
  : [];
652
633
  // The opening lists every question that waits: the session reads them, and their reminder runs
653
634
  // from now (a question sent to a closed session, or whose message was never recognised, included).
@@ -682,7 +663,7 @@ export async function circuitsALOuverture(
682
663
  );
683
664
  return [
684
665
  '## Les questions des circuits',
685
- "Le greffon de ta séance pousse dans la file de tes messages chaque question neuve d'un circuit du dépôt, quel que soit son lanceur, et chaque fin de circuit, une fois ; il n'y a aucune attente à lancer. Une question sans réponse revient une fois lue, à intervalle réglable depuis sa lecture (`grillhouse.rappel`, 10 min par défaut) : ta réponse au circuit l'acquitte, et répondue elle ne revient plus ; une question que tu as portée au responsable se tait par `npx grillhouse circuit <ticket> --chez-le-responsable`, jusqu'à la réponse du circuit. Tu ne te mets pas en attente du responsable tant qu'une question d'un circuit attend ta réponse : le crochet de fin de tour te le rappelle. Les questions en attente sont listées ci-dessous.",
666
+ "Le greffon de ta séance pousse dans la file de tes messages chaque question neuve d'un circuit du dépôt, quel que soit son lanceur ; il n'y a aucune attente à lancer. Une question sans réponse au superviseur revient une fois lue, à intervalle réglable depuis sa lecture (`grillhouse.rappel`, 10 min par défaut) : ta réponse au circuit l'acquitte, et répondue elle ne revient plus ; une question que tu as portée au responsable se tait par `npx grillhouse circuit <ticket> --chez-le-responsable`, jusqu'à la réponse du circuit ; une question adressée au responsable part une fois, pour que tu la lui portes, et ne revient pas. Tu ne te mets pas en attente du responsable tant qu'une question d'un circuit attend ta réponse. Les questions en attente sont listées ci-dessous.",
686
667
  ...(panne ? ['', '## Les circuits du dépôt', panne] : []),
687
668
  ...(nommes.length ? ['', '## Les circuits du dépôt', ...nommes.map(n => n.ligne)] : []),
688
669
  ...(questions.length ? ['', `Les réponses à une question : ${REPONSES}`] : []),
@@ -705,41 +686,213 @@ const git = (racine, ...args) =>
705
686
  encoding: 'utf8',
706
687
  });
707
688
 
689
+ // Where the session of supervision of the directory <dossier> stands: the common directory of git
690
+ // and the lock; `refus` says why <dossier> or the session has none (a role's session, out of git, a
691
+ // copy).
692
+ function depotDuSuperviseur(dossier, env) {
693
+ if (env.BEADS_ACTOR) {
694
+ return { refus: "la séance d'un rôle ne supervise pas" };
695
+ }
696
+ const r = git(dossier, '--git-dir', '--git-common-dir');
697
+ if (r.status !== 0) {
698
+ return { refus: `${dossier} n'est pas dans un dépôt git` };
699
+ }
700
+ const [dossierGit, commun] = r.stdout.trim().split('\n');
701
+ if (path.resolve(dossierGit) !== path.resolve(commun)) {
702
+ return { refus: 'une copie de ticket ne supervise pas : joue la commande à la racine du dépôt' };
703
+ }
704
+ return { commun, verrou: path.join(commun, VERROU_SUPERVISEUR) };
705
+ }
706
+
707
+ // The process the lock <verrou> names; null when no lock reads.
708
+ function tenantDe(verrou) {
709
+ try {
710
+ const pid = Number(/^(\d+)/.exec(readFileSync(verrou, 'utf8'))?.[1]);
711
+ return Number.isInteger(pid) ? pid : null;
712
+ } catch {
713
+ return null;
714
+ }
715
+ }
716
+
717
+ // `depotDuSuperviseur` for the session that holds the lock alone, its process in `tenant`.
718
+ function laSeanceQuiTient(dossier, env) {
719
+ const depot = depotDuSuperviseur(dossier, env);
720
+ if (depot.refus) {
721
+ return depot;
722
+ }
723
+ const tenant = tenantDe(depot.verrou);
724
+ return tenant !== null && estAuDessus(tenant)
725
+ ? { ...depot, tenant }
726
+ : { refus: 'cette séance ne tient pas le verrou du superviseur' };
727
+ }
728
+
729
+ // Writes <texte> whole into <f>, by a rename.
730
+ function ecrireEntier(f, texte) {
731
+ const provisoire = `${f}.${process.pid}`;
732
+ writeFileSync(provisoire, texte);
733
+ renameSync(provisoire, f);
734
+ }
735
+
736
+ function lireJson(f) {
737
+ try {
738
+ return JSON.parse(readFileSync(f, 'utf8'));
739
+ } catch {
740
+ return null;
741
+ }
742
+ }
743
+
744
+ function lireTexte(f) {
745
+ try {
746
+ return readFileSync(f, 'utf8');
747
+ } catch {
748
+ return '';
749
+ }
750
+ }
751
+
752
+ // The gesture of the holder of the lock on the note: <ecrire> is given its session and the text of
753
+ // <fichier>. Code 2 and the reason, nothing written, when the session or the file is refused.
754
+ function surLaNote(dossier, fichier, env, ecrire) {
755
+ const session = laSeanceQuiTient(dossier, env);
756
+ if (session.refus) {
757
+ return { code: 2, raison: session.refus };
758
+ }
759
+ let texte;
760
+ try {
761
+ texte = readFileSync(fichier, 'utf8');
762
+ } catch {
763
+ return { code: 2, raison: `le fichier ${fichier} ne se lit pas` };
764
+ }
765
+ if (!texte.trim()) {
766
+ return { code: 2, raison: `le fichier ${fichier} est vide` };
767
+ }
768
+ ecrire(session, texte);
769
+ return { code: 0, raison: '' };
770
+ }
771
+
772
+ /**
773
+ * The session that holds the lock of the supervisor of <dossier> declares a milestone: the text of
774
+ * <fichier> replaces its note of resumption whole, and the milestone, which holds for the context
775
+ * that declares it, replaces the one before (`superviseur --jalon`).
776
+ * @param {string} dossier
777
+ * @param {string} fichier
778
+ * @param {{ env?: Record<string, string | undefined> }} [options]
779
+ * @returns {Promise<{ code: number, raison: string }>} code 2 and its reason, nothing written, on a
780
+ * refusal
781
+ */
782
+ export async function declarerLeJalon(dossier, fichier, { env = process.env } = {}) {
783
+ return surLaNote(dossier, fichier, env, ({ commun, tenant }, texte) => {
784
+ ecrireEntier(path.join(commun, NOTE_DE_REPRISE), texte);
785
+ ecrireEntier(path.join(commun, JALON), `${JSON.stringify({ declareA: Date.now(), tenant })}\n`);
786
+ });
787
+ }
788
+
708
789
  /**
709
- * The check of the supervisor at the opening of a session in <racine>: what it says (empty when
710
- * nothing), the lock taken when it is free.
711
- * @param {string} racine the directory the session opens in
712
- * @param {{ env?: Record<string, string | undefined> }} options
790
+ * The session that holds the lock adds the text of <fichier> at the end of its note of resumption,
791
+ * which it creates when there is none; no milestone is declared (`superviseur --question`).
792
+ * @param {string} dossier
793
+ * @param {string} fichier
794
+ * @param {{ env?: Record<string, string | undefined> }} [options]
795
+ * @returns {Promise<{ code: number, raison: string }>} code 2 and its reason, nothing written, on a
796
+ * refusal
797
+ */
798
+ export async function ajouterLaQuestion(dossier, fichier, { env = process.env } = {}) {
799
+ return surLaNote(dossier, fichier, env, ({ commun }, texte) => {
800
+ const note = path.join(commun, NOTE_DE_REPRISE);
801
+ const avant = lireTexte(note);
802
+ const joint = avant ? `${avant.replace(/\n*$/, '')}\n\n` : '';
803
+ ecrireEntier(note, `${joint}${texte}`);
804
+ });
805
+ }
806
+
807
+ /**
808
+ * The message of resumption when the renewal of the session of supervision of <dossier> is due,
809
+ * empty otherwise (`superviseur --renouveler`): the session holds the lock, a milestone it declared
810
+ * stands, and a quiet Stop (<arretA>, ms, 0 without one) is later than it. A message of the owner
811
+ * (<messageA>, ms, 0 without one) later than the declaration cancels the milestone. The reading
812
+ * keeps a milestone that is due: the opening that follows the /clear removes it.
813
+ * @param {string} dossier
814
+ * @param {{ arretA: number, messageA: number, env?: Record<string, string | undefined> }} options
713
815
  * @returns {Promise<string>}
714
816
  */
715
- async function superviseur(racine, { env = process.env } = {}) {
716
- if (env.BEADS_ACTOR) {
817
+ export async function renouvellement(dossier, { arretA, messageA, env = process.env }) {
818
+ const session = laSeanceQuiTient(dossier, env);
819
+ if (session.refus) {
717
820
  return '';
718
821
  }
719
- const r = git(racine, '--git-dir', '--git-common-dir');
720
- if (r.status !== 0) {
822
+ const f = path.join(session.commun, JALON);
823
+ const jalon = lireJson(f);
824
+ if (!jalon || jalon.tenant !== session.tenant) {
721
825
  return '';
722
826
  }
723
- const [dossierGit, commun] = r.stdout.trim().split('\n');
724
- if (path.resolve(dossierGit) !== path.resolve(commun)) {
827
+ if (messageA > jalon.declareA) {
828
+ rmSync(f, { force: true });
725
829
  return '';
726
830
  }
727
- const verrou = path.join(commun, VERROU_SUPERVISEUR);
728
- const moi = seance();
729
- const tenant = () => {
730
- try {
731
- return Number(/^(\d+)/.exec(readFileSync(verrou, 'utf8'))?.[1]);
732
- } catch {
733
- return null;
734
- }
735
- };
736
- if (tenant() === moi) {
831
+ return arretA > jalon.declareA ? MESSAGE_DE_REPRISE : '';
832
+ }
833
+
834
+ // The section the opening gives of the note of resumption <note>; empty when none is written.
835
+ function laNote(note) {
836
+ const texte = lireTexte(note).trimEnd();
837
+ return texte
838
+ ? [
839
+ '## La note de reprise',
840
+ `Elle est au fichier \`${note}\` : lis-le en entier si ce texte est coupé.`,
841
+ '',
842
+ texte,
843
+ ].join('\n')
844
+ : '';
845
+ }
846
+
847
+ // What the opening that follows a /clear asks, before the circuits and the note.
848
+ const APRES_CLEAR = [
849
+ '## Reprise de la supervision après un /clear',
850
+ 'Charge la compétence `grillhouse:pitmaster`, puis reprends la note de reprise donnée plus bas ; ne fais aucun tour complet.',
851
+ 'À ton premier tour, quel que soit le message qui l’ouvre, repose au responsable la question que la note tient en attente.',
852
+ ].join('\n');
853
+
854
+ /**
855
+ * The check of the supervisor at the opening of a session in <dossier> (greffon.md, §5.2): what it
856
+ * says (empty when nothing), the lock taken when it is free. <source> is the one of the
857
+ * SessionStart hook. The session that takes the lock, and the holder after a /clear, receive the
858
+ * circuits and the note of resumption; every opening of the holder but after a compaction removes
859
+ * the declared milestone.
860
+ * @param {string} dossier the directory the session opens in
861
+ * @param {{ source?: string, env?: Record<string, string | undefined>, circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} [options]
862
+ * @returns {Promise<string>}
863
+ */
864
+ export async function ouvertureDuSuperviseur(
865
+ dossier,
866
+ { source = 'startup', env = process.env, circuitsDe = circuitsDuServeur } = {}
867
+ ) {
868
+ const depot = depotDuSuperviseur(dossier, env);
869
+ if (depot.refus) {
737
870
  return '';
738
871
  }
739
- if (prendreVerrou(verrou, { attendre: false, pid: moi })) {
740
- return circuitsALOuverture(path.dirname(commun));
872
+ const { commun, verrou } = depot;
873
+ const moi = seance();
874
+ const tenait = tenantDe(verrou) === moi;
875
+ if (!tenait && !prendreVerrou(verrou, { attendre: false, pid: moi })) {
876
+ return unAutreSuperviseur(verrou, moi);
877
+ }
878
+ if (source !== 'compact') {
879
+ rmSync(path.join(commun, JALON), { force: true });
880
+ }
881
+ if (tenait && source !== 'clear') {
882
+ return '';
741
883
  }
742
- const autre = tenant();
884
+ return [
885
+ source === 'clear' ? APRES_CLEAR : '',
886
+ await circuitsALOuverture(path.dirname(commun), { circuitsDe }),
887
+ laNote(path.join(commun, NOTE_DE_REPRISE)),
888
+ ]
889
+ .filter(Boolean)
890
+ .join('\n\n');
891
+ }
892
+
893
+ // The section a session receives when another live one holds the lock <verrou>; empty when none does.
894
+ function unAutreSuperviseur(verrou, moi) {
895
+ const autre = tenantDe(verrou);
743
896
  if (!autre || autre === moi || !vivant(autre)) {
744
897
  return '';
745
898
  }
@@ -755,10 +908,36 @@ async function superviseur(racine, { env = process.env } = {}) {
755
908
  ].join('\n');
756
909
  }
757
910
 
911
+ // Whether a question of the circuits <circuits> of the repository at <racine> waits for the
912
+ // supervisor, read or not: neither addressed to the owner, nor carried to him, nor deferred to a
913
+ // later time, its ticket open. null when the tickets do not read.
914
+ function uneQuestionAttend(racine, circuits) {
915
+ const chez = new Set(
916
+ lireLesRemontees(racine, Date.now())
917
+ .filter(r => r.chez !== undefined)
918
+ .map(r => r.cle)
919
+ );
920
+ const debout = circuits.filter(
921
+ c => attendLeSuperviseur(c) && c.qui !== RESPONSABLE && !chez.has(cleDe(c))
922
+ );
923
+ if (!debout.length) {
924
+ return false;
925
+ }
926
+ const hors = ticketsHorsAttente(
927
+ racine,
928
+ debout.map(c => c.ticket)
929
+ );
930
+ return hors === null ? null : debout.some(c => !hors.has(c.ticket));
931
+ }
932
+
933
+ // The request the reading submits to the session, for the reason <raison>.
934
+ const demandeDuJalon = raison =>
935
+ `Jalon · ${raison} : écris ta note de reprise et déclare le jalon (compétence \`grillhouse:pitmaster\`), par \`npx grillhouse superviseur --jalon <fichier>\`.`;
936
+
758
937
  /**
759
938
  * One reading for the greffon of the session of supervision of the repository at <racine>
760
939
  * (`npx grillhouse superviseur --relever`): the message of what `relever` gives (the questions of
761
- * the circuits due, the ends of circuits, the reds of main), empty when it gives nothing, when the
940
+ * the circuits due, the reds of main), empty when it gives nothing, when the
762
941
  * circuits do not read, or when the session that runs it is not the one that holds the lock of the
763
942
  * supervisor (a role's session, an agent's copy, another project's, a session that took no lock).
764
943
  * The interval of the re-presentation is the key `grillhouse.rappel` of the project, applied at
@@ -767,53 +946,61 @@ async function superviseur(racine, { env = process.env } = {}) {
767
946
  * the name and the folder of that project, where its answers are played, with that project's own
768
947
  * interval and state. A fault in the reading of one of these projects costs the others nothing: it
769
948
  * is thrown once all are read, each project at fault named with its reason, the message of the
770
- * others in the `texte` of the error.
949
+ * others in the `texte` of the error. Last comes the request to write the note of resumption and
950
+ * declare a milestone: after a compaction (<compaction>), and once for each night of the project
951
+ * (`grillhouse.plageDeNuit`) at a reading where every project read says that no question waits for
952
+ * the supervisor.
771
953
  * @param {string} racine
772
- * @param {{ env?: Record<string, string | undefined>, circuitsDe?: (racine: string, options?: { integres?: boolean }) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} [options]
954
+ * @param {{ env?: Record<string, string | undefined>, compaction?: boolean, circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} [options]
773
955
  * @returns {Promise<string>}
774
956
  * @throws {Error} `grillhouse.rappel` of the project of the session is at fault, named with its
775
957
  * value; or the reading of another project of the group failed (its `texte`: the others' message)
776
958
  */
777
959
  export async function releverPourLeGreffon(
778
960
  racine,
779
- { env = process.env, circuitsDe = circuitsDuServeur } = {}
961
+ { env = process.env, circuitsDe = circuitsDuServeur, compaction = false } = {}
780
962
  ) {
781
- if (env.BEADS_ACTOR) {
782
- return '';
783
- }
784
- const r = git(racine, '--git-dir', '--git-common-dir');
785
- if (r.status !== 0) {
963
+ const depot = depotDuSuperviseur(racine, env);
964
+ if (depot.refus) {
786
965
  return '';
787
966
  }
788
- const [dossierGit, commun] = r.stdout.trim().split('\n');
789
- if (path.resolve(dossierGit) !== path.resolve(commun)) {
790
- return '';
791
- }
792
- const verrou = path.join(commun, VERROU_SUPERVISEUR);
793
- let tenant = null;
794
- try {
795
- tenant = Number(/^(\d+)/.exec(readFileSync(verrou, 'utf8'))?.[1]);
796
- } catch {
967
+ const { commun, verrou } = depot;
968
+ let tenant = tenantDe(verrou);
969
+ if (tenant === null) {
797
970
  return '';
798
971
  }
799
972
  // A lock whose process is gone is taken over, as the opening does: the session that reads holds it.
800
- if (Number.isInteger(tenant) && !estAuDessus(tenant) && !vivant(tenant)) {
973
+ if (!estAuDessus(tenant) && !vivant(tenant)) {
801
974
  const moi = seance();
802
975
  tenant = prendreVerrou(verrou, { attendre: false, pid: moi }) ? moi : null;
803
976
  }
804
- if (!Number.isInteger(tenant) || !estAuDessus(tenant)) {
977
+ if (tenant === null || !estAuDessus(tenant)) {
805
978
  return '';
806
979
  }
807
- const parts = [await leReleveDe(racine, circuitsDe)];
980
+ const demandeNocturne = path.join(commun, DEMANDE_DE_NUIT);
981
+ const nuit = nuitEnCours(Date.now(), plageDeNuit(racine));
982
+ const aDemander = nuit !== null && lireJson(demandeNocturne)?.nuit !== nuit;
983
+ const apresCompaction = compaction ? demandeDuJalon('une compaction a eu lieu') : '';
984
+ const parts = [];
985
+ try {
986
+ parts.push(await leReleveDe(racine, circuitsDe, { nocturne: aDemander }));
987
+ } catch (e) {
988
+ throw Object.assign(e, { texte: apresCompaction });
989
+ }
808
990
  const fautes = [];
809
991
  for (const p of voisinsSansSuperviseur(racine)) {
810
992
  try {
811
- parts.push(await leReleveDe(p.chemin, circuitsDe, true));
993
+ parts.push(await leReleveDe(p.chemin, circuitsDe, { voisin: true, nocturne: aDemander }));
812
994
  } catch (e) {
813
995
  fautes.push(`${path.basename(p.chemin)} : ${e.message}`);
814
996
  }
815
997
  }
816
- const texte = parts.filter(Boolean).join('\n\n');
998
+ let demande = apresCompaction;
999
+ if (aDemander && !fautes.length && parts.every(p => p.attend === false)) {
1000
+ ecrireEntier(demandeNocturne, `${JSON.stringify({ nuit })}\n`);
1001
+ demande ||= demandeDuJalon('la nuit a commencé');
1002
+ }
1003
+ const texte = [...parts.map(p => p.texte), demande].filter(Boolean).join('\n\n');
817
1004
  if (fautes.length) {
818
1005
  throw Object.assign(new Error(fautes.join('\n')), { texte });
819
1006
  }
@@ -829,20 +1016,22 @@ function paquetDe(racine) {
829
1016
  }
830
1017
  }
831
1018
 
832
- // The message of one reading of the project at <racine>, under its own interval
833
- // (`grillhouse.rappel`) and its own state of the questions presented; empty when it gives nothing
834
- // or when its circuits do not read. A faulty interval throws, the project of the session named
835
- // (a neighbour is named by the caller, as for any fault of its reading).
836
- async function leReleveDe(racine, circuitsDe, voisin = false) {
1019
+ // One reading of the project at <racine>, under its own interval (`grillhouse.rappel`) and its own
1020
+ // state of the questions presented: `texte`, its message, empty when it gives nothing or when its
1021
+ // circuits do not read; `attend`, read for the request of the night (<o.nocturne>), whether a
1022
+ // question waits for the supervisor (`uneQuestionAttend`), null when unknown. A faulty interval
1023
+ // throws, the project of the session named (a neighbour is named by the caller, as for any fault of
1024
+ // its reading).
1025
+ async function leReleveDe(racine, circuitsDe, { voisin = false, nocturne = false } = {}) {
837
1026
  const { minutes, faute } = reglageDuRappel(paquetDe(racine));
838
1027
  if (faute) {
839
1028
  throw new Error(voisin ? faute : `${path.basename(racine)} : ${faute}`);
840
1029
  }
841
1030
  let circuits;
842
1031
  try {
843
- circuits = await circuitsDe(racine, { integres: true });
1032
+ circuits = await circuitsDe(racine);
844
1033
  } catch {
845
- return '';
1034
+ return { texte: '', attend: null };
846
1035
  }
847
1036
  const lot = relever(racine, circuits, {
848
1037
  fermes: ticketsHorsAttente,
@@ -854,7 +1043,10 @@ async function leReleveDe(racine, circuitsDe, voisin = false) {
854
1043
  const projet = voisin
855
1044
  ? { sigle: sigleDuProjet(racine).sigle ?? path.basename(racine), dossier: racine }
856
1045
  : {};
857
- return lot.length ? texteDesQuestions(lot, projet) : '';
1046
+ return {
1047
+ texte: lot.length ? texteDesQuestions(lot, projet) : '',
1048
+ attend: nocturne ? uneQuestionAttend(racine, circuits) : null,
1049
+ };
858
1050
  }
859
1051
 
860
1052
  // The other projects of the group of the project at <racine> (`grillhouse.groupe`) that no other
@@ -889,9 +1081,33 @@ function racineDe(dossier) {
889
1081
  }
890
1082
 
891
1083
  if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
892
- if (process.argv[2] === '--relever') {
1084
+ if (process.argv[2] === '--jalon' || process.argv[2] === '--question') {
1085
+ // superviseur --jalon|--question <fichier> : played from the root of the repository.
1086
+ const geste = process.argv[2] === '--jalon' ? declarerLeJalon : ajouterLaQuestion;
1087
+ const { code, raison } = process.argv[3]
1088
+ ? await geste(process.cwd(), process.argv[3])
1089
+ : { code: 2, raison: 'le fichier manque' };
1090
+ if (raison) {
1091
+ process.stderr.write(`${process.argv[2]} : ${raison}.\n`);
1092
+ }
1093
+ process.exitCode = code;
1094
+ } else if (process.argv[2] === '--renouveler') {
1095
+ // superviseur --renouveler <dossier> <arretA> <messageA> (the greffon, at each period).
1096
+ const [, , , dossier, arretA, messageA] = process.argv;
1097
+ const texte = await renouvellement(dossier ?? process.cwd(), {
1098
+ arretA: Number(arretA),
1099
+ messageA: Number(messageA),
1100
+ });
1101
+ if (texte) {
1102
+ process.stdout.write(`${texte}\n`);
1103
+ }
1104
+ } else if (process.argv[2] === '--relever') {
1105
+ const args = process.argv.slice(3);
1106
+ const dossier = args.find(a => a !== '--compaction') ?? process.cwd();
893
1107
  try {
894
- const texte = await releverPourLeGreffon(racineDe(process.argv[3] ?? process.cwd()));
1108
+ const texte = await releverPourLeGreffon(racineDe(dossier), {
1109
+ compaction: args.includes('--compaction'),
1110
+ });
895
1111
  if (texte) {
896
1112
  process.stdout.write(`${texte}\n`);
897
1113
  }
@@ -936,7 +1152,9 @@ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
936
1152
  }
937
1153
  }
938
1154
  } else {
939
- const texte = await superviseur(process.argv[2] ?? process.cwd());
1155
+ const texte = await ouvertureDuSuperviseur(process.argv[2] ?? process.cwd(), {
1156
+ source: process.argv[3] || undefined,
1157
+ });
940
1158
  if (texte) {
941
1159
  process.stdout.write(`${texte}\n`);
942
1160
  }