@roomi-fields/grillhouse 0.28.3 → 0.30.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 (238) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +739 -0
  3. package/bin/grillhouse.mjs +128 -26
  4. package/cadre/templates/projet/.github/workflows/ci.yml +2 -13
  5. package/cadre/templates/projet/CLAUDE.md +5 -1
  6. package/cadre/templates/projet/README.md +11 -11
  7. package/cadre/templates/projet/_gitignore +2 -5
  8. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  9. package/cadre/templates/projet/package.json +2 -2
  10. package/charte.md +37 -4
  11. package/dist/temporal/acte.d.ts +24 -0
  12. package/dist/temporal/acte.js +139 -0
  13. package/dist/temporal/acte.js.map +1 -0
  14. package/dist/temporal/attributs.d.ts +6 -0
  15. package/dist/temporal/attributs.js +15 -0
  16. package/dist/temporal/attributs.js.map +1 -0
  17. package/dist/temporal/circuit/activites.d.ts +13 -0
  18. package/dist/temporal/circuit/activites.js +33 -0
  19. package/dist/temporal/circuit/activites.js.map +1 -0
  20. package/dist/temporal/circuit/client.d.ts +72 -0
  21. package/dist/temporal/circuit/client.js +247 -0
  22. package/dist/temporal/circuit/client.js.map +1 -0
  23. package/dist/temporal/circuit/commande.d.ts +2 -0
  24. package/dist/temporal/circuit/commande.js +238 -0
  25. package/dist/temporal/circuit/commande.js.map +1 -0
  26. package/dist/temporal/circuit/contrat.d.ts +305 -0
  27. package/dist/temporal/circuit/contrat.js +24 -0
  28. package/dist/temporal/circuit/contrat.js.map +1 -0
  29. package/dist/temporal/circuit/deroule.d.ts +3 -0
  30. package/dist/temporal/circuit/deroule.js +540 -0
  31. package/dist/temporal/circuit/deroule.js.map +1 -0
  32. package/dist/temporal/client.d.ts +47 -0
  33. package/dist/temporal/client.js +69 -0
  34. package/dist/temporal/client.js.map +1 -0
  35. package/dist/temporal/commande.d.ts +2 -0
  36. package/dist/temporal/commande.js +95 -0
  37. package/dist/temporal/commande.js.map +1 -0
  38. package/dist/temporal/deroules.d.ts +5 -0
  39. package/dist/temporal/deroules.js +10 -0
  40. package/dist/temporal/deroules.js.map +1 -0
  41. package/dist/temporal/etat.d.ts +33 -0
  42. package/dist/temporal/etat.js +59 -0
  43. package/dist/temporal/etat.js.map +1 -0
  44. package/dist/temporal/file/activites.d.ts +10 -0
  45. package/dist/temporal/file/activites.js +25 -0
  46. package/dist/temporal/file/activites.js.map +1 -0
  47. package/dist/temporal/file/client.d.ts +4 -0
  48. package/dist/temporal/file/client.js +6 -0
  49. package/dist/temporal/file/client.js.map +1 -0
  50. package/dist/temporal/file/contrat.d.ts +158 -0
  51. package/dist/temporal/file/contrat.js +14 -0
  52. package/dist/temporal/file/contrat.js.map +1 -0
  53. package/dist/temporal/file/deroule.d.ts +15 -0
  54. package/dist/temporal/file/deroule.js +235 -0
  55. package/dist/temporal/file/deroule.js.map +1 -0
  56. package/dist/temporal/installation.d.ts +124 -0
  57. package/dist/temporal/installation.js +408 -0
  58. package/dist/temporal/installation.js.map +1 -0
  59. package/dist/temporal/places/activites.d.ts +8 -0
  60. package/dist/temporal/places/activites.js +13 -0
  61. package/dist/temporal/places/activites.js.map +1 -0
  62. package/dist/temporal/places/client.d.ts +28 -0
  63. package/dist/temporal/places/client.js +64 -0
  64. package/dist/temporal/places/client.js.map +1 -0
  65. package/dist/temporal/places/contrat.d.ts +106 -0
  66. package/dist/temporal/places/contrat.js +21 -0
  67. package/dist/temporal/places/contrat.js.map +1 -0
  68. package/dist/temporal/places/deroule.d.ts +3 -0
  69. package/dist/temporal/places/deroule.js +198 -0
  70. package/dist/temporal/places/deroule.js.map +1 -0
  71. package/dist/temporal/sonde/activites.d.ts +6 -0
  72. package/dist/temporal/sonde/activites.js +52 -0
  73. package/dist/temporal/sonde/activites.js.map +1 -0
  74. package/dist/temporal/sonde/contrat.d.ts +35 -0
  75. package/dist/temporal/sonde/contrat.js +10 -0
  76. package/dist/temporal/sonde/contrat.js.map +1 -0
  77. package/dist/temporal/sonde/deroule.d.ts +3 -0
  78. package/dist/temporal/sonde/deroule.js +39 -0
  79. package/dist/temporal/sonde/deroule.js.map +1 -0
  80. package/dist/temporal/tickets/activites.d.ts +7 -0
  81. package/dist/temporal/tickets/activites.js +81 -0
  82. package/dist/temporal/tickets/activites.js.map +1 -0
  83. package/dist/temporal/tickets/client.d.ts +10 -0
  84. package/dist/temporal/tickets/client.js +31 -0
  85. package/dist/temporal/tickets/client.js.map +1 -0
  86. package/dist/temporal/tickets/contrat.d.ts +56 -0
  87. package/dist/temporal/tickets/contrat.js +13 -0
  88. package/dist/temporal/tickets/contrat.js.map +1 -0
  89. package/dist/temporal/tickets/deroule.d.ts +3 -0
  90. package/dist/temporal/tickets/deroule.js +94 -0
  91. package/dist/temporal/tickets/deroule.js.map +1 -0
  92. package/dist/temporal/travailleur.d.ts +2 -0
  93. package/dist/temporal/travailleur.js +69 -0
  94. package/dist/temporal/travailleur.js.map +1 -0
  95. package/docs/ARCHITECTURE.md +813 -53
  96. package/docs/CADRE.md +17 -0
  97. package/docs/INTERFACE.md +161 -30
  98. package/hooks/crochet.mjs +19 -2
  99. package/hooks/hooks.json +11 -0
  100. package/package.json +16 -4
  101. package/scripts/activites.mjs +2182 -0
  102. package/scripts/aiguillage.d.mts +37 -0
  103. package/scripts/aiguillage.mjs +328 -0
  104. package/scripts/avancement.mjs +159 -64
  105. package/scripts/bilan.mjs +37 -19
  106. package/scripts/cadre.mjs +11 -2
  107. package/scripts/circuit.mjs +888 -3654
  108. package/scripts/circuits-cles.d.mts +4 -0
  109. package/scripts/circuits-cles.mjs +21 -0
  110. package/scripts/circuits-du-serveur.mjs +105 -0
  111. package/scripts/codes-de-sortie.mjs +9 -0
  112. package/scripts/commandes-composees.mjs +45 -41
  113. package/scripts/commandes-du-path.d.mts +7 -0
  114. package/scripts/commandes-du-path.mjs +25 -0
  115. package/scripts/composition-des-langages.mjs +30 -11
  116. package/scripts/conformite.mjs +19 -10
  117. package/scripts/copies-finies.mjs +188 -42
  118. package/scripts/depart-du-ticket.d.mts +53 -0
  119. package/scripts/depart-du-ticket.mjs +124 -0
  120. package/scripts/dependances-internes.mjs +115 -0
  121. package/scripts/dernier-vert.mjs +7 -15
  122. package/scripts/donnees-cles.mjs +228 -0
  123. package/scripts/droits.mjs +11 -1
  124. package/scripts/effets.mjs +352 -0
  125. package/scripts/enveloppe/enveloppe.mjs +119 -8
  126. package/scripts/enveloppe/lancer.sh +27 -32
  127. package/scripts/enveloppe/paquets-du-plan.mjs +2 -2
  128. package/scripts/enveloppe/travail-de-la-copie.mjs +99 -12
  129. package/scripts/etapes.mjs +6 -3
  130. package/scripts/faits-du-circuit.mjs +493 -0
  131. package/scripts/file-des-tickets.d.mts +21 -0
  132. package/scripts/file-des-tickets.mjs +58 -0
  133. package/scripts/flux-des-paquets.mjs +187 -0
  134. package/scripts/fusion-du-changelog.mjs +0 -1
  135. package/scripts/gardes-du-cadre.mjs +12 -2
  136. package/scripts/grillhouse-maj.mjs +16 -7
  137. package/scripts/integration/file.mjs +477 -422
  138. package/scripts/integration/integrer.mjs +20 -22
  139. package/scripts/integration/rejeu.mjs +19 -4
  140. package/scripts/jointure.d.ts +168 -28
  141. package/scripts/langages/cargo/commandes.mjs +426 -119
  142. package/scripts/langages/cargo/composants.mjs +187 -3
  143. package/scripts/langages/cargo/exemples.mjs +75 -17
  144. package/scripts/langages/cargo/index.mjs +32 -13
  145. package/scripts/langages/cargo/migrations/0.28.4-tailles-des-tests.mjs +35 -0
  146. package/scripts/langages/cargo/sccache.mjs +62 -16
  147. package/scripts/langages/cargo/squelette.mjs +72 -3
  148. package/scripts/langages/cargo/tailles-des-tests.mjs +195 -0
  149. package/scripts/langages/cargo/tests-de-head.mjs +159 -0
  150. package/scripts/langages/python/commandes.mjs +232 -79
  151. package/scripts/langages/python/composants.mjs +65 -3
  152. package/scripts/langages/python/exemples.mjs +21 -12
  153. package/scripts/langages/python/index.mjs +25 -5
  154. package/scripts/langages/python/lot.mjs +1 -36
  155. package/scripts/langages/python/squelette.mjs +119 -17
  156. package/scripts/langages/typescript/construire.mjs +6 -163
  157. package/scripts/langages/typescript/exemples.mjs +19 -11
  158. package/scripts/langages/typescript/frontieres.mjs +1 -1
  159. package/scripts/langages/typescript/index.mjs +48 -63
  160. package/scripts/langages/typescript/interfaces-contre-code.mjs +4 -4
  161. package/scripts/langages/typescript/migrations/0.30.0-prefixe-des-tickets.mjs +63 -0
  162. package/scripts/langages/typescript/migrations/0.30.0-tailles-des-outils-lourds.mjs +31 -0
  163. package/scripts/langages/typescript/migrations/0.30.0-titres-nommant-un-ticket.mjs +40 -0
  164. package/scripts/langages/typescript/mise-a-jour.mjs +1 -2
  165. package/scripts/langages/typescript/regle-des-tests.mjs +13 -0
  166. package/scripts/langages/typescript/squelette.mjs +18 -2
  167. package/scripts/langages/typescript/tailles-des-tests.mjs +40 -9
  168. package/scripts/langages/typescript/tests-de-nuit.mjs +44 -21
  169. package/scripts/langages/typescript/tests.mjs +17 -8
  170. package/scripts/langages/typescript/titres-de-tests.mjs +297 -0
  171. package/scripts/langages/typescript/turbo-des-paquets.mjs +183 -38
  172. package/scripts/langages/typescript/verdict.mjs +1 -1
  173. package/scripts/langages/typescript/verifier.mjs +110 -296
  174. package/scripts/langages/typescript/vitest-config/base.mjs +30 -10
  175. package/scripts/langages/typescript/vitest-config/bornes.mjs +13 -0
  176. package/scripts/langages/typescript/vitest-config/cibles.mjs +123 -62
  177. package/scripts/langages/typescript/vitest-config/delais.mjs +54 -0
  178. package/scripts/langages/typescript/vitest-config/delais.setup.mjs +11 -0
  179. package/scripts/langages/typescript/vitest-config/duree.classement.mjs +100 -0
  180. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +56 -64
  181. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +7 -2
  182. package/scripts/langages/typescript/vitest-config/mesure.mjs +3 -2
  183. package/scripts/langages/typescript/vitest.nuit.config.mjs +22 -13
  184. package/scripts/lecture-unique.mjs +51 -0
  185. package/scripts/mesure/pression.mjs +11 -9
  186. package/scripts/mesure-de-la-machine.d.mts +21 -0
  187. package/scripts/mesure-de-la-machine.mjs +76 -0
  188. package/scripts/migrations/0.23.2-copies-du-cadre.mjs +8 -2
  189. package/scripts/migrations/0.30.0-ci-appelle-la-verification.mjs +120 -0
  190. package/scripts/migrations/0.31.0-paquets-dans-le-graphe.mjs +81 -0
  191. package/scripts/migrations.mjs +5 -0
  192. package/scripts/nuit.sh +29 -15
  193. package/scripts/outil.mjs +72 -0
  194. package/scripts/outils-cles.d.mts +24 -0
  195. package/scripts/outils-cles.mjs +0 -1
  196. package/scripts/paquet-npm.mjs +147 -0
  197. package/scripts/paquet.mjs +112 -14
  198. package/scripts/paquets.mjs +34 -6
  199. package/scripts/passe-de-la-machine.mjs +66 -0
  200. package/scripts/places-de-la-machine.mjs +360 -0
  201. package/scripts/places-du-serveur.mjs +170 -0
  202. package/scripts/prefixe-des-tickets.mjs +68 -0
  203. package/scripts/preparation.mjs +10 -3
  204. package/scripts/registre.mjs +3 -2
  205. package/scripts/regles-des-places.d.mts +36 -0
  206. package/scripts/regles-des-places.mjs +70 -0
  207. package/scripts/reponses-du-circuit.d.mts +6 -0
  208. package/scripts/reponses-du-circuit.mjs +28 -0
  209. package/scripts/resultats.mjs +29 -14
  210. package/scripts/retirer-les-copies-finies.mjs +25 -0
  211. package/scripts/sans-reponse.d.mts +4 -0
  212. package/scripts/sans-reponse.mjs +13 -0
  213. package/scripts/seances.mjs +918 -0
  214. package/scripts/services-du-noyau.mjs +28 -11
  215. package/scripts/session-start.sh +10 -1
  216. package/scripts/sortie.mjs +23 -4
  217. package/scripts/sources.mjs +3 -3
  218. package/scripts/sous-commandes.mjs +39 -9
  219. package/scripts/style-a-l-ecriture.mjs +229 -0
  220. package/scripts/superviseur.mjs +382 -16
  221. package/scripts/tableau.mjs +329 -130
  222. package/scripts/taches-du-graphe.mjs +328 -0
  223. package/scripts/ticket-du-circuit.mjs +206 -0
  224. package/scripts/transitions.d.mts +148 -0
  225. package/scripts/transitions.mjs +901 -0
  226. package/scripts/verrou-de-fichier.mjs +2 -2
  227. package/scripts/verrou-de-machine.mjs +322 -62
  228. package/skills/developpeur/SKILL.md +11 -3
  229. package/skills/explorateur/SKILL.md +2 -1
  230. package/skills/pitmaster/SKILL.md +62 -28
  231. package/skills/pitmaster/references/consigne-agent.md +5 -1
  232. package/skills/release/SKILL.md +3 -3
  233. package/skills/relecteur/SKILL.md +22 -8
  234. package/skills/testwriter/SKILL.md +47 -39
  235. package/scripts/demon.mjs +0 -138
  236. package/scripts/integration/file-attente.mjs +0 -61
  237. package/scripts/langages/cargo/touches.mjs +0 -93
  238. package/scripts/langages/typescript/script-des-tests.mjs +0 -6
@@ -12,18 +12,53 @@
12
12
  // copies, taken through scripts/verrou-de-fichier.mjs for the session's own process: the first
13
13
  // process above this one that is not a shell (sh, bash, dash, zsh), the claude of the session.
14
14
  // It holds as long as that process lives: a lock whose process is gone is taken over.
15
- // - Free, or held by a process that is gone: taken, nothing said. Held by the session itself (a
16
- // session reopened in the same process): kept, nothing said. Held by another live session: the
15
+ // - Free, or held by a process that is gone: taken, nothing said of it. Held by the session itself
16
+ // (a session reopened in the same process, by a compaction or a /clear): kept, nothing said of
17
+ // it, circuits included. Held by another live session: the
17
18
  // lock stays, and the section « ## Un autre superviseur tient ce dépôt » names its process and
18
19
  // since when it holds the lock, and asks to say so to the owner and to launch no circuit
19
20
  // (skill pitmaster, « Au lancement de la séance »).
21
+ // - The session whose opening takes the lock (not one that keeps it) receives
22
+ // (`circuitsALOuverture`) the section « ## L'attente des questions », which asks it to launch the
23
+ // wait of the questions in the background (`--attendre`, below) without waiting for the owner's
24
+ // word, then, when the repository has some (read from the Temporal server in one call,
25
+ // scripts/circuits-du-serveur.mjs), « ## Les circuits du dépôt »: each circuit that runs, named;
26
+ // each circuit stopped on a question, with its question and the command that answers it; each
27
+ // circuit ended without its issue, with the command that resumes it (`--reprendre` from its last
28
+ // state written, else `--depuis <testwriter|developpeur> --contexte <texte>`), which the
29
+ // supervisor launches without waiting for the owner's word; their ticket open, and the stopped
30
+ // and the ended ones then gone up; a server that does not answer is said. A circuit
31
+ // runs on the worker of the project, apart from the sessions, its launch returns at once, and its
32
+ // question wakes the supervisor by the wait alone (grillhouse-mwz: SyntHub's SH-br0.1 stopped
33
+ // 27 s after a relaunch of its session, read only on a word of the owner). The queue of the
34
+ // tickets under Temporal (src/temporal/tickets/) launches the tickets `circuit`, not the opening.
20
35
  // Exit 0, whatever it finds.
36
+ //
37
+ // npx grillhouse superviseur --attendre [<dossier>]
38
+ //
39
+ // - The wait of the session of supervision (`attendreUneQuestion`), which the supervisor keeps in
40
+ // the background, one at a time, the one way a question of a circuit wakes the session (the
41
+ // owner's decision, grillhouse-pq6): it ends only when a question of a circuit appears that never
42
+ // went up (`questionsEnAttente`, the one source of the questions that wait for the supervisor,
43
+ // which the opening reads too), whatever launched the circuit (alone, in a queue, by another
44
+ // session), and writes each one, its ticket, step, question and the command that answers it;
45
+ // the end of its task wakes the session, which spends nothing while it waits (grillhouse-pq6:
46
+ // SyntHub's SH-ae6.5.2, SH-ae6.5.6 and SH-br0.1.5, launched by a queue, waited hours on their
47
+ // question). The stops gone up, by a wait or named at the opening, are kept in
48
+ // `.claude/worktrees/questions-remontees.json`, each one by its ticket, the run of its workflow,
49
+ // the rank of its question in that run and its stop: one never wakes the session twice, a
50
+ // session closed then opened again finds every one that waits, and one answered leaves them.
51
+ // Exit 0 on its
52
+ // questions, 1 when another wait already runs (`.claude/worktrees/attente-des-questions.lock`).
21
53
  import { spawnSync } from 'node:child_process';
22
- import { readFileSync, statSync } from 'node:fs';
54
+ import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
23
55
  import path from 'node:path';
24
56
  import { pathToFileURL } from 'node:url';
25
- import { prendreVerrou } from './verrou-de-fichier.mjs';
57
+ import { lacherVerrou, prendreVerrou } from './verrou-de-fichier.mjs';
26
58
  import { vivant } from './mesure/base-de-passe.mjs';
59
+ import { circuitsDuServeur, ServeurMuet } from './circuits-du-serveur.mjs';
60
+ import { attendLeSuperviseur } from './tableau.mjs';
61
+ import { etapeDuCircuit, libelle, SUPERVISEUR } from './etapes.mjs';
27
62
 
28
63
  const VERROU_SUPERVISEUR = 'grillhouse-superviseur.lock';
29
64
  const COQUILLES = new Set(['sh', 'bash', 'dash', 'zsh']);
@@ -46,13 +81,312 @@ function seance(depart = process.ppid) {
46
81
  let pid = depart;
47
82
  for (let i = 0; i < 32 && pid > 1; i++) {
48
83
  const p = processus(pid);
49
- if (!p) return depart;
50
- if (!COQUILLES.has(p.nom)) return pid;
84
+ if (!p) {
85
+ return depart;
86
+ }
87
+ if (!COQUILLES.has(p.nom)) {
88
+ return pid;
89
+ }
51
90
  pid = p.parent;
52
91
  }
53
92
  return depart;
54
93
  }
55
94
 
95
+ // Of the tickets <ids> of the repository at <racine>, those that bd gives closed; none when bd does
96
+ // not read them.
97
+ function ticketsFermes(racine, ids) {
98
+ const r = spawnSync('bd', ['show', ...ids, '--json'], {
99
+ cwd: racine,
100
+ encoding: 'utf8',
101
+ timeout: 5000,
102
+ maxBuffer: 256 * 1024 * 1024,
103
+ });
104
+ try {
105
+ return new Set(
106
+ JSON.parse(r.stdout)
107
+ .filter(t => t.status === 'closed')
108
+ .map(t => t.id)
109
+ );
110
+ } catch {
111
+ return new Set();
112
+ }
113
+ }
114
+
115
+ // One stop of the circuit <c>: its ticket, the run of its workflow (`run`), the rank of its
116
+ // question in that run (`numero`) and its stop, so that the next stop of a circuit resumed is
117
+ // another one.
118
+ const cleDe = c => [c.ticket, c.run, c.numero, c.arret ?? 'interrompu'].join(':');
119
+
120
+ // The step where the circuit <c> stands, in words (« 3.1 Contrôles »), else its state's.
121
+ const ou = c => {
122
+ const e = etapeDuCircuit({ ...c, raison: c.arret });
123
+ return e ? libelle(e) : c.etape;
124
+ };
125
+
126
+ // The file of the stops gone up to the session of supervision of the repository at <racine>, and
127
+ // the lock of its one wait, beside the states of the circuits.
128
+ const etatsDe = racine => path.join(racine, '.claude', 'worktrees');
129
+ const remonteesDe = racine => path.join(etatsDe(racine), 'questions-remontees.json');
130
+ const verrouDeLAttente = racine => path.join(etatsDe(racine), 'attente-des-questions.lock');
131
+
132
+ // The stops gone up to the session of supervision of the repository at <racine>: their keys.
133
+ function lireRemontees(racine) {
134
+ try {
135
+ const lu = JSON.parse(readFileSync(remonteesDe(racine), 'utf8'));
136
+ return new Set(Array.isArray(lu?.remontees) ? lu.remontees.map(String) : []);
137
+ } catch {
138
+ return new Set();
139
+ }
140
+ }
141
+
142
+ // The stops gone up of the repository at <racine>, its circuits <circuits> read, under the lock
143
+ // of their file: <faire>(<avant>, those gone up before) returns the keys it makes go up (`cles`)
144
+ // and what it gives (`rendu`); the file is written whole with them and those of <avant> whose stop
145
+ // still stands, its circuit waiting for the supervisor. A question answered so leaves them. Its
146
+ // `rendu`.
147
+ function remonter(racine, circuits, faire) {
148
+ const f = remonteesDe(racine);
149
+ mkdirSync(path.dirname(f), { recursive: true });
150
+ const verrou = `${f}.verrou`;
151
+ // Held for one reading of the circuits: older than that, abandoned.
152
+ prendreVerrou(verrou, { attendre: true, perime: 30_000 });
153
+ try {
154
+ const avant = lireRemontees(racine);
155
+ const { cles, rendu } = faire(avant);
156
+ const debout = new Set(circuits.filter(attendLeSuperviseur).map(cleDe));
157
+ const apres = new Set([...cles, ...[...avant].filter(c => debout.has(c))]);
158
+ if (avant.size !== apres.size || [...apres].some(c => !avant.has(c))) {
159
+ const provisoire = `${f}.${process.pid}`;
160
+ writeFileSync(provisoire, `${JSON.stringify({ remontees: [...apres].sort() }, null, 2)}\n`);
161
+ renameSync(provisoire, f);
162
+ }
163
+ return rendu;
164
+ } finally {
165
+ lacherVerrou(verrou);
166
+ }
167
+ }
168
+
169
+ // The question that waits for the supervisor from the circuit <c>: its ticket, its step, its
170
+ // question, who must answer it, the command that answers it, and its stop's key.
171
+ const enQuestion = c => ({
172
+ ticket: c.ticket,
173
+ etape: ou(c),
174
+ question:
175
+ c.question ??
176
+ `arrêt ${c.arret}${c.code === null ? '' : ` (code ${c.code})`}${c.raison ? ` : ${c.raison}` : ''}`,
177
+ qui: c.qui ?? SUPERVISEUR,
178
+ // The answers the client accepts, as it gives them (src/temporal/circuit/client.ts).
179
+ commande: c.reponse,
180
+ cle: cleDe(c),
181
+ interrompu: c.interrompu,
182
+ arret: c.arret,
183
+ });
184
+
185
+ // Of the circuits <lus> of the repository at <racine>, those whose ticket <fermes> does not give
186
+ // closed, sorted by ticket.
187
+ function enAttente(lus, racine, fermes) {
188
+ const ferme = lus.length
189
+ ? fermes(
190
+ racine,
191
+ lus.map(c => c.ticket)
192
+ )
193
+ : new Set();
194
+ return lus
195
+ .filter(c => !ferme.has(c.ticket))
196
+ .sort((a, b) => a.ticket.localeCompare(b.ticket, 'en'));
197
+ }
198
+
199
+ /**
200
+ * The questions that wait for the supervisor among the circuits <circuits> of the repository at
201
+ * <racine> (scripts/circuits-du-serveur.mjs), the one source of the opening
202
+ * (`circuitsALOuverture`) and of the wait (`attendreUneQuestion`), by the rule the board's
203
+ * « ⤷ Question » reads too (scripts/tableau.mjs `attendLeSuperviseur`): each circuit stopped on a
204
+ * question (any stop but the supervisor's own « arrete », « à repasser » included) or ended
205
+ * without its issue, those whose stop's key <sauf> holds left out, then those whose ticket
206
+ * <fermes> gives closed (bd is asked of the others alone), sorted by ticket. Each one says whether
207
+ * its circuit ended without its issue (`interrompu`) and its stop (`arret`).
208
+ * @param {string} racine the root of the repository
209
+ * @param {import('./circuits-du-serveur.mjs').CircuitDuServeur[]} circuits
210
+ * @param {{ fermes?: (racine: string, ids: string[]) => Set<string>, sauf?: Set<string> }} options
211
+ * @returns {{ ticket: string, etape: string, question: string, qui: string, commande: string, cle: string, interrompu: boolean, arret: string | null }[]}
212
+ */
213
+ export function questionsEnAttente(
214
+ racine,
215
+ circuits,
216
+ { fermes = ticketsFermes, sauf = new Set() } = {}
217
+ ) {
218
+ return enAttente(
219
+ circuits.filter(c => attendLeSuperviseur(c) && !sauf.has(cleDe(c))),
220
+ racine,
221
+ fermes
222
+ ).map(enQuestion);
223
+ }
224
+
225
+ // No ticket closed: the questions read without asking bd.
226
+ const aucunFerme = () => new Set();
227
+
228
+ // The questions of the repository at <racine>, its circuits <circuits> read, that never went up
229
+ // (`questionsEnAttente`): returned, and now gone up; a question answered (its circuit runs again,
230
+ // or ended) leaves those gone up, and one whose ticket <fermes> gives closed goes up without a
231
+ // word. bd is asked of the new ones alone.
232
+ function releverLesNeuves(racine, circuits, fermes) {
233
+ return remonter(racine, circuits, avant => ({
234
+ cles: questionsEnAttente(racine, circuits, { fermes: aucunFerme }).map(q => q.cle),
235
+ rendu: questionsEnAttente(racine, circuits, { fermes, sauf: avant }),
236
+ }));
237
+ }
238
+
239
+ /**
240
+ * The wait of the session of supervision of the repository at <racine> (`npx grillhouse
241
+ * superviseur --attendre`, which the supervisor keeps in the background, as a review requested on
242
+ * GitHub or Gerrit's attention set calls the one a change waits for): it ends only when a question
243
+ * that never went up waits for the supervisor (`questionsEnAttente`), whatever launched its
244
+ * circuit, and gives those questions, now gone up; a question already gone up (by a wait, or named
245
+ * at the opening) never ends it again, a question answered leaves those gone up, and the normal end
246
+ * of a circuit is never one. It reads the circuits every <pas> ms by <circuitsDe> (one call to the
247
+ * Temporal server, scripts/circuits-du-serveur.mjs, by default), as the UI of Temporal refreshes
248
+ * its list; a reading that fails (the server down) is tried again at the next step, the questions
249
+ * gone up kept. The session spends nothing while it waits. One wait at a time per repository: a
250
+ * second one is refused while the first runs. Its <signal> ends it with no question.
251
+ * @param {{ racine: string, fermes?: (racine: string, ids: string[]) => Set<string>, pas?: number, signal?: AbortSignal, circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} options
252
+ * @returns {Promise<{ ticket: string, etape: string, question: string, qui: string, commande: string, cle: string }[]>}
253
+ * @throws {Error} another wait runs
254
+ */
255
+ export async function attendreUneQuestion({
256
+ racine,
257
+ fermes = ticketsFermes,
258
+ pas = 5_000,
259
+ signal,
260
+ circuitsDe = circuitsDuServeur,
261
+ }) {
262
+ mkdirSync(etatsDe(racine), { recursive: true });
263
+ const verrou = verrouDeLAttente(racine);
264
+ if (!prendreVerrou(verrou, { attendre: false })) {
265
+ let qui = '';
266
+ try {
267
+ qui = ` (processus ${/^(\d+)/.exec(readFileSync(verrou, 'utf8'))?.[1] ?? '?'})`;
268
+ } catch {
269
+ // the lock is gone meanwhile
270
+ }
271
+ throw new Error(
272
+ `Une attente des questions tourne déjà pour ce dépôt${qui}, ${verrou} : une seule à la fois.`
273
+ );
274
+ }
275
+ try {
276
+ while (!signal?.aborted) {
277
+ let circuits = null;
278
+ try {
279
+ circuits = await circuitsDe(racine);
280
+ } catch {
281
+ circuits = null;
282
+ }
283
+ if (circuits && !signal?.aborted) {
284
+ const neuves = releverLesNeuves(racine, circuits, fermes);
285
+ if (neuves.length) {
286
+ return neuves;
287
+ }
288
+ }
289
+ await attendre(pas, signal);
290
+ }
291
+ return [];
292
+ } finally {
293
+ lacherVerrou(verrou);
294
+ }
295
+ }
296
+
297
+ // Waits <ms> ms, or until <signal> ends the wait.
298
+ const attendre = (ms, signal) =>
299
+ new Promise(resolve => {
300
+ const fin = () => {
301
+ clearTimeout(minuteur);
302
+ resolve();
303
+ };
304
+ const minuteur = setTimeout(fin, ms);
305
+ signal?.addEventListener('abort', fin, { once: true });
306
+ });
307
+
308
+ /**
309
+ * The text that wakes the session of supervision on the questions <questions>: for each one, its
310
+ * ticket, step, who must answer it, its question and the command that answers it; then the wait to
311
+ * launch again once they are answered.
312
+ * @param {{ ticket: string, etape: string, question: string, qui: string, commande: string }[]} questions
313
+ * @returns {string}
314
+ */
315
+ export function texteDesQuestions(questions) {
316
+ return [
317
+ questions.length > 1 ? '## Questions neuves des circuits' : "## Question neuve d'un circuit",
318
+ ...questions.map(q =>
319
+ [
320
+ `- ${q.ticket}, à ${q.etape}, au ${q.qui} : ${q.question.replace(/\n/g, '\n ')}`,
321
+ ` La réponse : \`${q.commande}\`.`,
322
+ ].join('\n')
323
+ ),
324
+ "Une fois répondu, relance l'attente en arrière-plan (`run_in_background`) : `npx grillhouse superviseur --attendre`.",
325
+ ].join('\n');
326
+ }
327
+
328
+ /**
329
+ * The section a session of supervision receives at its opening in <racine>, when it takes the lock:
330
+ * the wait of the questions to launch in the background (`npx grillhouse superviseur --attendre`),
331
+ * the one way a question of a circuit wakes the session; then the circuits of the repository,
332
+ * those whose ticket <fermes> gives closed left out: each one that runs, named; each one stopped on
333
+ * a question (a stop other than the supervisor's own « arrete »), with its question and the command
334
+ * that answers it; each one ended without its issue, with the command that resumes it. The
335
+ * stopped and the ended ones are then gone up: the wait does not give them again.
336
+ * @param {string} racine the root of the repository
337
+ * The circuits are read once, by <circuitsDe> (one call to the Temporal server,
338
+ * scripts/circuits-du-serveur.mjs, by default); a server that does not answer is said, and no
339
+ * question goes up.
340
+ * @param {{ fermes?: (racine: string, ids: string[]) => Set<string>,
341
+ * circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} options
342
+ * @returns {Promise<string>}
343
+ */
344
+ export async function circuitsALOuverture(
345
+ racine,
346
+ { fermes = ticketsFermes, circuitsDe = circuitsDuServeur } = {}
347
+ ) {
348
+ let circuits = null;
349
+ let panne = null;
350
+ try {
351
+ circuits = await circuitsDe(racine);
352
+ } catch (e) {
353
+ const message = String(e?.message ?? e).split('\n')[0];
354
+ panne =
355
+ e instanceof ServeurMuet
356
+ ? `${e.message} : les circuits ne se lisent pas.`
357
+ : `Les circuits ne se lisent pas : ${message}.`;
358
+ }
359
+ const questions = circuits
360
+ ? remonter(racine, circuits, () => {
361
+ const q = questionsEnAttente(racine, circuits, { fermes });
362
+ return { cles: q.map(x => x.cle), rendu: q };
363
+ })
364
+ : [];
365
+ const tournent = enAttente(
366
+ (circuits ?? []).filter(c => c.vivant),
367
+ racine,
368
+ fermes
369
+ ).map(c => ({ ticket: c.ticket, ligne: `- ${c.ticket} tourne, à ${ou(c)}.` }));
370
+ const enLigne = q => ({
371
+ ticket: q.ticket,
372
+ ligne: q.interrompu
373
+ ? `- ${q.ticket} a fini sans son issue (aucun arrêt écrit), à ${q.etape} : relance-le sans attendre le mot du responsable, \`${q.commande}\`.`
374
+ : [
375
+ `- ${q.ticket} est arrêté sur une question (${q.arret}), à ${q.etape}, au ${q.qui} : ${q.question.replace(/\n/g, '\n ')}`,
376
+ ` La réponse : \`${q.commande}\`.`,
377
+ ].join('\n'),
378
+ });
379
+ const nommes = [...tournent, ...questions.map(enLigne)].sort((a, b) =>
380
+ a.ticket.localeCompare(b.ticket, 'en')
381
+ );
382
+ return [
383
+ "## L'attente des questions",
384
+ "Dès ta première réponse, sans attendre le mot du responsable, lance en arrière-plan (`run_in_background`) l'attente des questions : `npx grillhouse superviseur --attendre`. Elle se termine sur la question neuve d'un circuit, quel que soit son lanceur, et te réveille ainsi ; un lancement de circuit rend la main tout de suite, et la fin normale d'un circuit ne te réveille pas : le panneau la montre.",
385
+ ...(panne ? ['', '## Les circuits du dépôt', panne] : []),
386
+ ...(nommes.length ? ['', '## Les circuits du dépôt', ...nommes.map(n => n.ligne)] : []),
387
+ ].join('\n');
388
+ }
389
+
56
390
  const git = (racine, ...args) =>
57
391
  spawnSync('git', ['-C', racine, 'rev-parse', '--path-format=absolute', ...args], {
58
392
  encoding: 'utf8',
@@ -63,14 +397,20 @@ const git = (racine, ...args) =>
63
397
  * nothing), the lock taken when it is free.
64
398
  * @param {string} racine the directory the session opens in
65
399
  * @param {{ env?: Record<string, string | undefined> }} options
66
- * @returns {string}
400
+ * @returns {Promise<string>}
67
401
  */
68
- function superviseur(racine, { env = process.env } = {}) {
69
- if (env.BEADS_ACTOR) return '';
402
+ async function superviseur(racine, { env = process.env } = {}) {
403
+ if (env.BEADS_ACTOR) {
404
+ return '';
405
+ }
70
406
  const r = git(racine, '--git-dir', '--git-common-dir');
71
- if (r.status !== 0) return '';
407
+ if (r.status !== 0) {
408
+ return '';
409
+ }
72
410
  const [dossierGit, commun] = r.stdout.trim().split('\n');
73
- if (path.resolve(dossierGit) !== path.resolve(commun)) return '';
411
+ if (path.resolve(dossierGit) !== path.resolve(commun)) {
412
+ return '';
413
+ }
74
414
  const verrou = path.join(commun, VERROU_SUPERVISEUR);
75
415
  const moi = seance();
76
416
  const tenant = () => {
@@ -80,10 +420,16 @@ function superviseur(racine, { env = process.env } = {}) {
80
420
  return null;
81
421
  }
82
422
  };
83
- if (tenant() === moi) return '';
84
- if (prendreVerrou(verrou, { attendre: false, pid: moi })) return '';
423
+ if (tenant() === moi) {
424
+ return '';
425
+ }
426
+ if (prendreVerrou(verrou, { attendre: false, pid: moi })) {
427
+ return circuitsALOuverture(path.dirname(commun));
428
+ }
85
429
  const autre = tenant();
86
- if (!autre || autre === moi || !vivant(autre)) return '';
430
+ if (!autre || autre === moi || !vivant(autre)) {
431
+ return '';
432
+ }
87
433
  let depuis = '';
88
434
  try {
89
435
  depuis = `, depuis le ${statSync(verrou).mtime.toLocaleString('fr-FR')}`;
@@ -96,7 +442,27 @@ function superviseur(racine, { env = process.env } = {}) {
96
442
  ].join('\n');
97
443
  }
98
444
 
445
+ // The root of the repository at <dossier>, its main tree for a copy; <dossier> out of git.
446
+ function racineDe(dossier) {
447
+ const r = git(dossier, '--git-common-dir');
448
+ return r.status === 0 ? path.dirname(r.stdout.trim()) : dossier;
449
+ }
450
+
99
451
  if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
100
- const texte = superviseur(process.argv[2] ?? process.cwd());
101
- if (texte) process.stdout.write(`${texte}\n`);
452
+ if (process.argv[2] === '--attendre') {
453
+ try {
454
+ const questions = await attendreUneQuestion({
455
+ racine: racineDe(process.argv[3] ?? process.cwd()),
456
+ });
457
+ process.stdout.write(`${texteDesQuestions(questions)}\n`);
458
+ } catch (e) {
459
+ process.stderr.write(`${e.message}\n`);
460
+ process.exitCode = 1;
461
+ }
462
+ } else {
463
+ const texte = await superviseur(process.argv[2] ?? process.cwd());
464
+ if (texte) {
465
+ process.stdout.write(`${texte}\n`);
466
+ }
467
+ }
102
468
  }