@roomi-fields/grillhouse 0.29.0 → 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 (222) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +739 -0
  3. package/bin/grillhouse.mjs +79 -18
  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/docs/agents/issue-tracker.md +1 -1
  7. package/cadre/templates/projet/package.json +2 -2
  8. package/charte.md +24 -0
  9. package/dist/temporal/acte.d.ts +24 -0
  10. package/dist/temporal/acte.js +139 -0
  11. package/dist/temporal/acte.js.map +1 -0
  12. package/dist/temporal/attributs.d.ts +6 -0
  13. package/dist/temporal/attributs.js +15 -0
  14. package/dist/temporal/attributs.js.map +1 -0
  15. package/dist/temporal/circuit/activites.d.ts +13 -0
  16. package/dist/temporal/circuit/activites.js +33 -0
  17. package/dist/temporal/circuit/activites.js.map +1 -0
  18. package/dist/temporal/circuit/client.d.ts +72 -0
  19. package/dist/temporal/circuit/client.js +247 -0
  20. package/dist/temporal/circuit/client.js.map +1 -0
  21. package/dist/temporal/circuit/commande.d.ts +2 -0
  22. package/dist/temporal/circuit/commande.js +238 -0
  23. package/dist/temporal/circuit/commande.js.map +1 -0
  24. package/dist/temporal/circuit/contrat.d.ts +305 -0
  25. package/dist/temporal/circuit/contrat.js +24 -0
  26. package/dist/temporal/circuit/contrat.js.map +1 -0
  27. package/dist/temporal/circuit/deroule.d.ts +3 -0
  28. package/dist/temporal/circuit/deroule.js +540 -0
  29. package/dist/temporal/circuit/deroule.js.map +1 -0
  30. package/dist/temporal/client.d.ts +47 -0
  31. package/dist/temporal/client.js +69 -0
  32. package/dist/temporal/client.js.map +1 -0
  33. package/dist/temporal/commande.d.ts +2 -0
  34. package/dist/temporal/commande.js +95 -0
  35. package/dist/temporal/commande.js.map +1 -0
  36. package/dist/temporal/deroules.d.ts +5 -0
  37. package/dist/temporal/deroules.js +10 -0
  38. package/dist/temporal/deroules.js.map +1 -0
  39. package/dist/temporal/etat.d.ts +33 -0
  40. package/dist/temporal/etat.js +59 -0
  41. package/dist/temporal/etat.js.map +1 -0
  42. package/dist/temporal/file/activites.d.ts +10 -0
  43. package/dist/temporal/file/activites.js +25 -0
  44. package/dist/temporal/file/activites.js.map +1 -0
  45. package/dist/temporal/file/client.d.ts +4 -0
  46. package/dist/temporal/file/client.js +6 -0
  47. package/dist/temporal/file/client.js.map +1 -0
  48. package/dist/temporal/file/contrat.d.ts +158 -0
  49. package/dist/temporal/file/contrat.js +14 -0
  50. package/dist/temporal/file/contrat.js.map +1 -0
  51. package/dist/temporal/file/deroule.d.ts +15 -0
  52. package/dist/temporal/file/deroule.js +235 -0
  53. package/dist/temporal/file/deroule.js.map +1 -0
  54. package/dist/temporal/installation.d.ts +124 -0
  55. package/dist/temporal/installation.js +408 -0
  56. package/dist/temporal/installation.js.map +1 -0
  57. package/dist/temporal/places/activites.d.ts +8 -0
  58. package/dist/temporal/places/activites.js +13 -0
  59. package/dist/temporal/places/activites.js.map +1 -0
  60. package/dist/temporal/places/client.d.ts +28 -0
  61. package/dist/temporal/places/client.js +64 -0
  62. package/dist/temporal/places/client.js.map +1 -0
  63. package/dist/temporal/places/contrat.d.ts +106 -0
  64. package/dist/temporal/places/contrat.js +21 -0
  65. package/dist/temporal/places/contrat.js.map +1 -0
  66. package/dist/temporal/places/deroule.d.ts +3 -0
  67. package/dist/temporal/places/deroule.js +198 -0
  68. package/dist/temporal/places/deroule.js.map +1 -0
  69. package/dist/temporal/sonde/activites.d.ts +6 -0
  70. package/dist/temporal/sonde/activites.js +52 -0
  71. package/dist/temporal/sonde/activites.js.map +1 -0
  72. package/dist/temporal/sonde/contrat.d.ts +35 -0
  73. package/dist/temporal/sonde/contrat.js +10 -0
  74. package/dist/temporal/sonde/contrat.js.map +1 -0
  75. package/dist/temporal/sonde/deroule.d.ts +3 -0
  76. package/dist/temporal/sonde/deroule.js +39 -0
  77. package/dist/temporal/sonde/deroule.js.map +1 -0
  78. package/dist/temporal/tickets/activites.d.ts +7 -0
  79. package/dist/temporal/tickets/activites.js +81 -0
  80. package/dist/temporal/tickets/activites.js.map +1 -0
  81. package/dist/temporal/tickets/client.d.ts +10 -0
  82. package/dist/temporal/tickets/client.js +31 -0
  83. package/dist/temporal/tickets/client.js.map +1 -0
  84. package/dist/temporal/tickets/contrat.d.ts +56 -0
  85. package/dist/temporal/tickets/contrat.js +13 -0
  86. package/dist/temporal/tickets/contrat.js.map +1 -0
  87. package/dist/temporal/tickets/deroule.d.ts +3 -0
  88. package/dist/temporal/tickets/deroule.js +94 -0
  89. package/dist/temporal/tickets/deroule.js.map +1 -0
  90. package/dist/temporal/travailleur.d.ts +2 -0
  91. package/dist/temporal/travailleur.js +69 -0
  92. package/dist/temporal/travailleur.js.map +1 -0
  93. package/docs/ARCHITECTURE.md +609 -80
  94. package/docs/CADRE.md +17 -0
  95. package/docs/INTERFACE.md +134 -42
  96. package/hooks/crochet.mjs +19 -2
  97. package/hooks/hooks.json +11 -0
  98. package/package.json +16 -4
  99. package/scripts/activites.mjs +2182 -0
  100. package/scripts/aiguillage.d.mts +37 -0
  101. package/scripts/aiguillage.mjs +7 -3
  102. package/scripts/avancement.mjs +128 -16
  103. package/scripts/bilan.mjs +37 -19
  104. package/scripts/cadre.mjs +11 -2
  105. package/scripts/circuit.mjs +881 -4059
  106. package/scripts/circuits-cles.d.mts +4 -0
  107. package/scripts/circuits-cles.mjs +21 -0
  108. package/scripts/circuits-du-serveur.mjs +105 -0
  109. package/scripts/codes-de-sortie.mjs +9 -0
  110. package/scripts/commandes-composees.mjs +45 -41
  111. package/scripts/commandes-du-path.d.mts +7 -0
  112. package/scripts/commandes-du-path.mjs +25 -0
  113. package/scripts/composition-des-langages.mjs +16 -12
  114. package/scripts/conformite.mjs +6 -13
  115. package/scripts/copies-finies.mjs +52 -47
  116. package/scripts/depart-du-ticket.d.mts +53 -0
  117. package/scripts/depart-du-ticket.mjs +124 -0
  118. package/scripts/dependances-internes.mjs +115 -0
  119. package/scripts/dernier-vert.mjs +7 -15
  120. package/scripts/donnees-cles.mjs +228 -0
  121. package/scripts/droits.mjs +11 -1
  122. package/scripts/effets.mjs +352 -0
  123. package/scripts/enveloppe/enveloppe.mjs +119 -8
  124. package/scripts/enveloppe/lancer.sh +14 -18
  125. package/scripts/enveloppe/paquets-du-plan.mjs +2 -2
  126. package/scripts/enveloppe/travail-de-la-copie.mjs +5 -1
  127. package/scripts/etapes.mjs +5 -2
  128. package/scripts/faits-du-circuit.mjs +493 -0
  129. package/scripts/file-des-tickets.d.mts +21 -0
  130. package/scripts/file-des-tickets.mjs +58 -0
  131. package/scripts/flux-des-paquets.mjs +187 -0
  132. package/scripts/gardes-du-cadre.mjs +12 -2
  133. package/scripts/integration/file.mjs +475 -420
  134. package/scripts/integration/integrer.mjs +17 -19
  135. package/scripts/integration/rejeu.mjs +19 -4
  136. package/scripts/jointure.d.ts +145 -27
  137. package/scripts/langages/cargo/commandes.mjs +289 -109
  138. package/scripts/langages/cargo/composants.mjs +130 -34
  139. package/scripts/langages/cargo/exemples.mjs +12 -21
  140. package/scripts/langages/cargo/index.mjs +18 -8
  141. package/scripts/langages/cargo/sccache.mjs +8 -14
  142. package/scripts/langages/python/commandes.mjs +216 -100
  143. package/scripts/langages/python/composants.mjs +53 -21
  144. package/scripts/langages/python/exemples.mjs +6 -16
  145. package/scripts/langages/python/index.mjs +24 -8
  146. package/scripts/langages/python/lot.mjs +1 -36
  147. package/scripts/langages/typescript/construire.mjs +6 -163
  148. package/scripts/langages/typescript/exemples.mjs +3 -11
  149. package/scripts/langages/typescript/frontieres.mjs +1 -1
  150. package/scripts/langages/typescript/index.mjs +43 -61
  151. package/scripts/langages/typescript/interfaces-contre-code.mjs +4 -4
  152. package/scripts/langages/typescript/migrations/0.30.0-prefixe-des-tickets.mjs +63 -0
  153. package/scripts/langages/typescript/migrations/0.30.0-tailles-des-outils-lourds.mjs +31 -0
  154. package/scripts/langages/typescript/migrations/0.30.0-titres-nommant-un-ticket.mjs +40 -0
  155. package/scripts/langages/typescript/mise-a-jour.mjs +1 -2
  156. package/scripts/langages/typescript/tailles-des-tests.mjs +40 -9
  157. package/scripts/langages/typescript/tests-de-nuit.mjs +12 -9
  158. package/scripts/langages/typescript/tests.mjs +17 -8
  159. package/scripts/langages/typescript/titres-de-tests.mjs +297 -0
  160. package/scripts/langages/typescript/turbo-des-paquets.mjs +183 -38
  161. package/scripts/langages/typescript/verdict.mjs +1 -1
  162. package/scripts/langages/typescript/verifier.mjs +31 -11
  163. package/scripts/langages/typescript/vitest-config/base.mjs +22 -1
  164. package/scripts/langages/typescript/vitest-config/bornes.mjs +13 -0
  165. package/scripts/langages/typescript/vitest-config/cibles.mjs +36 -14
  166. package/scripts/langages/typescript/vitest-config/delais.mjs +54 -0
  167. package/scripts/langages/typescript/vitest-config/delais.setup.mjs +11 -0
  168. package/scripts/langages/typescript/vitest-config/duree.classement.mjs +100 -0
  169. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +49 -63
  170. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +3 -0
  171. package/scripts/langages/typescript/vitest.nuit.config.mjs +4 -0
  172. package/scripts/mesure/pression.mjs +3 -3
  173. package/scripts/mesure-de-la-machine.d.mts +21 -0
  174. package/scripts/mesure-de-la-machine.mjs +76 -0
  175. package/scripts/migrations/0.23.2-copies-du-cadre.mjs +8 -2
  176. package/scripts/migrations/0.30.0-ci-appelle-la-verification.mjs +120 -0
  177. package/scripts/migrations/0.31.0-paquets-dans-le-graphe.mjs +81 -0
  178. package/scripts/migrations.mjs +5 -0
  179. package/scripts/nuit.sh +10 -3
  180. package/scripts/outils-cles.d.mts +24 -0
  181. package/scripts/outils-cles.mjs +0 -1
  182. package/scripts/paquet-npm.mjs +147 -0
  183. package/scripts/paquet.mjs +73 -4
  184. package/scripts/paquets.mjs +34 -6
  185. package/scripts/passe-de-la-machine.mjs +66 -0
  186. package/scripts/places-de-la-machine.mjs +360 -0
  187. package/scripts/places-du-serveur.mjs +170 -0
  188. package/scripts/prefixe-des-tickets.mjs +68 -0
  189. package/scripts/preparation.mjs +10 -3
  190. package/scripts/registre.mjs +3 -2
  191. package/scripts/regles-des-places.d.mts +36 -0
  192. package/scripts/regles-des-places.mjs +70 -0
  193. package/scripts/reponses-du-circuit.d.mts +6 -0
  194. package/scripts/reponses-du-circuit.mjs +28 -0
  195. package/scripts/resultats.mjs +7 -9
  196. package/scripts/retirer-les-copies-finies.mjs +25 -0
  197. package/scripts/sans-reponse.d.mts +4 -0
  198. package/scripts/sans-reponse.mjs +13 -0
  199. package/scripts/seances.mjs +918 -0
  200. package/scripts/services-du-noyau.mjs +26 -8
  201. package/scripts/session-start.sh +2 -2
  202. package/scripts/sortie.mjs +3 -3
  203. package/scripts/sous-commandes.mjs +38 -9
  204. package/scripts/style-a-l-ecriture.mjs +229 -0
  205. package/scripts/superviseur.mjs +122 -111
  206. package/scripts/tableau.mjs +148 -110
  207. package/scripts/taches-du-graphe.mjs +328 -0
  208. package/scripts/ticket-du-circuit.mjs +206 -0
  209. package/scripts/transitions.d.mts +148 -0
  210. package/scripts/transitions.mjs +901 -0
  211. package/scripts/verrou-de-fichier.mjs +2 -2
  212. package/scripts/verrou-de-machine.mjs +28 -13
  213. package/skills/explorateur/SKILL.md +2 -1
  214. package/skills/pitmaster/SKILL.md +17 -18
  215. package/skills/pitmaster/references/consigne-agent.md +5 -1
  216. package/skills/release/SKILL.md +3 -3
  217. package/skills/relecteur/SKILL.md +4 -2
  218. package/skills/testwriter/SKILL.md +36 -24
  219. package/scripts/demon.mjs +0 -251
  220. package/scripts/integration/file-attente.mjs +0 -61
  221. package/scripts/langages/cargo/touches.mjs +0 -93
  222. package/scripts/langages/typescript/script-des-tests.mjs +0 -6
@@ -6,7 +6,7 @@
6
6
  // - A step (ETAPES): its number (« 2 », « 4.1 »), its title, who works there (`qui`: the role
7
7
  // agents, or AUTO for a step the circuit leads itself; none for a step that only holds its
8
8
  // sub-steps), its sub-steps (`sous`), and the step of the circuit's state it is (`etat`: the
9
- // `etape` of `.claude/worktrees/<ticket>.circuit.json`, the final pass being the checks once
9
+ // `etape` of the state the circuit writes, which the workflow of its ticket holds, the final pass being the checks once
10
10
  // `finale`). Every step runs once for the whole ticket, as a merge request has one author of
11
11
  // its tests and one of its code, one CI on the whole and one review: one session of the
12
12
  // testwriter (2) and one of the developpeur (3) carry the whole plan.
@@ -30,7 +30,7 @@
30
30
  // with no session.
31
31
  // - The question of each other stop (MONTEES, below): what goes up to the supervisor, and who
32
32
  // must answer it.
33
- import { A_REPASSER } from './mesure/pression.mjs';
33
+ import { A_REPASSER } from './codes-de-sortie.mjs';
34
34
 
35
35
  // Who works at a step the circuit leads itself, with no agent.
36
36
  export const AUTO = 'auto';
@@ -136,6 +136,7 @@ export const ARRETS = {
136
136
  questionnement: 22,
137
137
  references: 23,
138
138
  'hors-plan': 24,
139
+ inattendu: 25,
139
140
  'a-repasser': A_REPASSER,
140
141
  };
141
142
 
@@ -276,6 +277,8 @@ export const MONTEES = Object.fromEntries(
276
277
  'La régénération des références change un fichier qu’aucune référence n’écrit, ou sa commande échoue (ses écarts ci-dessus) : qui corrige la référence ou le lot ?',
277
278
  'hors-plan':
278
279
  'La séance écrit hors du plan du ticket : le plan s’étend-il à ce paquet (`--etendre`), ou l’écriture est-elle refusée (`--reprendre` avec son contexte) ?',
280
+ inattendu:
281
+ 'Une exception que le circuit ne prévoit pas (une lecture de la copie, une commande, un fichier illisible) l’a arrêté : sa cause se lève-t-elle, pour reprendre (`--reprendre`, qui écrit de nouveau cet arrêt si la cause reste), ou le circuit s’arrête-t-il ?',
279
282
  }).map(([arret, question]) => [arret, { question: `${question} ${REPONSES}`, qui: SUPERVISEUR }])
280
283
  );
281
284
 
@@ -0,0 +1,493 @@
1
+ #!/usr/bin/env node
2
+ // One act of the circuit of a ticket for its workflow under Temporal (src/temporal/circuit/), in a
3
+ // process of its own, as Buildkite's agent and GitLab's runner play each job in a child process:
4
+ // the circuit's code waits on its passes synchronously, so the worker that awaits this process
5
+ // keeps serving, and sends its heartbeats, while the act plays. The worker's activities
6
+ // (src/temporal/circuit/activites.ts) start it in the main tree of the repository:
7
+ //
8
+ // node scripts/faits-du-circuit.mjs <acte> (its input in JSON on the standard input)
9
+ //
10
+ // Each sign of life of a session goes out as a line `vie <json>`, and the act's outcome as the
11
+ // last line, `resultat <json>`. SIGTERM cancels the act: the session it leads ends, its group
12
+ // killed (scripts/seances.mjs). The act ends with its worker: once the worker is gone, it exits
13
+ // at once, the group of its session left running, which the attempt played again waits for.
14
+ //
15
+ // The acts of a ticket write nothing outside themselves (docs/ARCHITECTURE.md, « une activité, un
16
+ // effet, une clé »): each gathers the effects the circuit's code emits (scripts/effets.mjs) and
17
+ // gives them back with its outcome (`effets`), its own readings seeing those it already emitted;
18
+ // the workflow then plays each one in an activity of its own, the act `effet`, under the key of
19
+ // that activity (`cle`: its workflow, its run, its activity, the same for each of its attempts).
20
+ // A fact (the act `fait`) is read again on an attempt played again: a reading, a measure, a pass
21
+ // of the checks, a regeneration and the integration (no second commit for a lot already in the
22
+ // queue) replay without harm. Under the opening and a fact, a session draws its id from the key of
23
+ // its activity, its event and the attempt of the activity (`idDeSeance` of scripts/seances.mjs,
24
+ // `<séance>-e<essai>`), and ranges its result under it (`rangDeLaSeance`). Only an attempt Temporal plays again (its
25
+ // attempt 2 or more, `essai`), at the launch the dead attempt made last, takes the result of a
26
+ // session the dead attempt launched in its envelope once its group has ended, with no second
27
+ // session (scripts/seances.mjs `lancer`); a session out of the envelope (the explorateur's, the
28
+ // questionneur's, the reviewer's), which writes nothing in the lot, is launched again. The acts of
29
+ // the queue of a project follow the same model: each of their gestures replays without harm (main
30
+ // moved onto a lot already on main enters it, a ticket closed stays closed, a commit pushed is
31
+ // pushed again as it is), and their comments are effects they give back, which the workflow of
32
+ // the queue writes one per activity (`effet-de-la-file`).
33
+ //
34
+ // The acts, each on the context the circuit builds for a run (`contexte` of scripts/circuit.mjs)
35
+ // and the memory the workflow holds:
36
+ //
37
+ // - `ouvrir`, the opening of a run up to its plan (`ouvrirJusquAuPlan`), first or on the
38
+ // supervisor's answer to a stop, the state of a circuit stopped on his word read from its file;
39
+ // - `plan`, one step of the plan (`unPasDuPlan`: the explorateur, the questionneur, the answer,
40
+ // the conclusion playing with the last), which the workflow decides (`pasDuPlan`);
41
+ // - `preparer`, the start of a step (`commencerLEtape`) and the copy prepared on the tip of main
42
+ // before its pass (`avantLaPasse`);
43
+ // - `fait`, the fact a decision asks for (`lireLeFait`), an Arret it raises given back as such;
44
+ // - `effets`, the effects of a decision (`appliquer`), then the end of its step (`finirLEtape`);
45
+ // - `arret`, a stop written (`publierLArret`), its question gone up (`monter`) unless it is a
46
+ // « a-repasser » the workflow plays again, the end of its step, then the end of the run
47
+ // (`aLaFin`);
48
+ // - `fin`, the end of a run integrated; `arreter`, the stop on the supervisor's word (`arreter`);
49
+ // - `effet`, one effect an act gave back, written under the key of its activity (`ecrireLEffet`):
50
+ // an effect not written has its outcome, said on the error output or the failure of its
51
+ // activity;
52
+ // - the acts of the queue of a project (scripts/integration/file.mjs, grillhouse-4nr.8): `situer`,
53
+ // where the lot of a ticket stands (`situerLeLot`); `avancer`, main moved onto its branch
54
+ // (`avancerMain`), the ticket told of a branch out of the queue or kept (`direLIssue`);
55
+ // `fermer`, the ticket closed and main pushed (`fermerLEntree`); `ci`, one reading of the CI of
56
+ // a commit (`lireUneFoisLaCI`); `conclure`, the CI concluded at the ticket (`conclureLaCI`);
57
+ // `effet-de-la-file`, one effect they gave back, under the key of its activity. Their lines go
58
+ // to the error output.
59
+ import { appendFileSync, readFileSync } from 'node:fs';
60
+ import path from 'node:path';
61
+ import { pathToFileURL } from 'node:url';
62
+ import {
63
+ aLaFin,
64
+ appliquer,
65
+ commencerLEtape,
66
+ finirLEtape,
67
+ arretDe,
68
+ arreter,
69
+ avantLaPasse,
70
+ contexte,
71
+ ecrireEtat,
72
+ finirLOuverture,
73
+ lireLeFait,
74
+ MEMOIRE,
75
+ monter,
76
+ ouvrirJusquAuPlan,
77
+ publierLArret,
78
+ unPasDuPlan,
79
+ } from './circuit.mjs';
80
+ import {
81
+ avancerMain,
82
+ conclureLaCI,
83
+ direLIssue,
84
+ fermerLEntree,
85
+ lireUneFoisLaCI,
86
+ outilsDeLaFile,
87
+ situerLeLot,
88
+ } from './integration/file.mjs';
89
+ import { avancementDeLaCI, avecLAvancementDuTravail } from './avancement.mjs';
90
+ import { ecrireLEffet } from './effets.mjs';
91
+ import { Arret, geste } from './ticket-du-circuit.mjs';
92
+
93
+ // What the workflow keeps of the circuit's memory besides the decisions': the session a relaunch
94
+ // resumes, the rank of arrival, the sort of the ticket, what the opening reads of the project's
95
+ // package.json (its tools, its data, its generated files), which every pass of a later act plays
96
+ // with, each act in a process of its own, and the supervisor's context of the
97
+ // run (`contexte`), which each session of the run reads at the head of its instruction; a context
98
+ // the act is given (an answer's, a motive) is kept over it.
99
+ const GARDEE = [
100
+ ...MEMOIRE,
101
+ 'reprise',
102
+ 'rang',
103
+ 'sorte',
104
+ 'outils',
105
+ 'donnees',
106
+ 'engendres',
107
+ 'contexte',
108
+ ];
109
+
110
+ // The bases of the passes of the contexts this act opened, which its end removes, its death
111
+ // before its `finally` included.
112
+ const bases = new Set();
113
+
114
+ const dire = (genre, valeur) => process.stdout.write(`${genre} ${JSON.stringify(valeur)}\n`);
115
+
116
+ // The context of a run of the circuit of <ticket> with the options <options>, its memory
117
+ // <memoire>: its ports say each sign of life on the standard output, and the effects it emits are
118
+ // gathered (`rendus`), which the act gives back.
119
+ // The supervisor's session of the act being played (`superviseur` of its input, the entry of the
120
+ // workflow), which `leContexte` gives each context: one act per process. An act after the opening
121
+ // passes the plan its workflow holds (`paquets`): its context reads only the
122
+ // subject of the title, since the integration removes the copy while the circuit still runs.
123
+ let superviseurDeLActe = null;
124
+
125
+ function leContexte(ticket, memoire = {}, options = {}) {
126
+ const ctx = contexte({
127
+ ticket,
128
+ reprendre: false,
129
+ contexte: null,
130
+ depuis: null,
131
+ etendre: null,
132
+ arreter: false,
133
+ ...options,
134
+ });
135
+ Object.assign(ctx, laMemoireReprise(memoire, options));
136
+ bases.add(ctx.base);
137
+ ctx.superviseur = superviseurDeLActe;
138
+ ctx.rendus = [];
139
+ ctx.constats = [...(ctx.constats ?? [])];
140
+ ctx.ports = { signeDeVie: vie => dire('vie', vie) };
141
+ return ctx;
142
+ }
143
+
144
+ // The tools of the queue on the main tree <racine> (the act plays there), its lines on the error
145
+ // output, the progress directory <avancement> of a reading of the CI, the effects it emits
146
+ // gathered (`rendus`), which the act gives back.
147
+ const laFile = (racine, avancement = null) => {
148
+ const o = outilsDeLaFile(racine, l => process.stderr.write(`${l}\n`), avancement);
149
+ o.rendus = [];
150
+ return o;
151
+ };
152
+
153
+ /** The memory of <ctx> the workflow keeps from one act to the next. */
154
+ export const laMemoire = ctx => Object.fromEntries(GARDEE.map(k => [k, ctx[k] ?? null]));
155
+
156
+ /**
157
+ * What a context takes back of the memory <memoire> the workflow kept, but what the act is given
158
+ * (<options>: an answer's context, a motive).
159
+ */
160
+ export const laMemoireReprise = (memoire, options = {}) =>
161
+ Object.fromEntries(GARDEE.filter(k => k in memoire && !(k in options)).map(k => [k, memoire[k]]));
162
+
163
+ // The stop the state of <ctx> names once `monter` wrote it, at the state <etat>.
164
+ const arretDeLEtat = (ctx, code, etat) => ({
165
+ code,
166
+ nom: ctx.courant?.raison ?? null,
167
+ question: ctx.courant?.question ?? null,
168
+ etat: { ...etat, raison: ctx.courant?.raison ?? null },
169
+ });
170
+
171
+ // The options of a run on the supervisor's answer <reponse>.
172
+ const optionsDe = reponse => {
173
+ if (!reponse) {
174
+ return {};
175
+ }
176
+ const contexteDuSuperviseur = reponse.contexte ?? null;
177
+ if (reponse.genre === 'reprendre') {
178
+ return { reprendre: true, contexte: contexteDuSuperviseur };
179
+ }
180
+ if (reponse.genre === 'depuis') {
181
+ return { depuis: reponse.role, contexte: contexteDuSuperviseur };
182
+ }
183
+ return { etendre: reponse.paquets, contexte: contexteDuSuperviseur };
184
+ };
185
+
186
+ // The act <f> on the context <ctx>: its outcome and the effects it emitted (`effets`), its bases
187
+ // closed.
188
+ async function rendre(ctx, f) {
189
+ try {
190
+ const valeur = await f();
191
+ return { ...(valeur ?? {}), effets: ctx.rendus };
192
+ } finally {
193
+ ctx.base.fermer();
194
+ }
195
+ }
196
+
197
+ // The acts, each on its input; each returns its outcome.
198
+ const ACTES = {
199
+ async ouvrir({ ticket, memoire, reponse, arrete, cle, essai }) {
200
+ const ctx = leContexte(ticket, memoire, optionsDe(reponse));
201
+ // The key of its activity and its attempt name the sessions of the plan (`idDeSeance`).
202
+ ctx.cle = cle ?? null;
203
+ ctx.essaiDeLActe = essai ?? 1;
204
+ return rendre(ctx, () => ouvrirSur(ctx, memoire, arrete));
205
+ },
206
+ // One step of the plan (`unPasDuPlan`): the state of the plan that follows, the opening once it
207
+ // passes, or its stop gone up.
208
+ async plan({ ticket, memoire, reponse, pas, plan, cle, essai }) {
209
+ const ctx = leContexte(ticket, memoire, optionsDe(reponse));
210
+ ctx.cle = cle ?? null;
211
+ ctx.essaiDeLActe = essai ?? 1;
212
+ ctx.contexte = plan.contexte ?? ctx.contexte ?? null;
213
+ return rendre(ctx, async () => {
214
+ const r = await unPasDuPlan(ctx, pas, plan.etat);
215
+ if ('code' in r) {
216
+ aLaFin(ctx, r.code);
217
+ return { arret: arretDeLEtat(ctx, r.code, ctx.courant ?? {}) };
218
+ }
219
+ if (r.passe) {
220
+ finirLOuverture(ctx, plan.debut);
221
+ return { ouverture: lOuverture(ctx, plan.debut) };
222
+ }
223
+ return { plan: { ...plan, etat: r.plan, memoire: laMemoire(ctx) } };
224
+ });
225
+ },
226
+ async preparer({ ticket, memoire, etape, paquets }) {
227
+ const ctx = leContexte(ticket, memoire, { paquets });
228
+ return rendre(ctx, () => {
229
+ const { etat, menee } = commencerLEtape(ctx, etape);
230
+ const pointe = avantLaPasse(ctx, etape.etape, ctx.regeneration ?? null);
231
+ if (pointe.arret) {
232
+ const { nom, rapport, piece, question } = pointe.arret;
233
+ return { arret: { leve: { nom, rapport, piece, question } }, etat, menee };
234
+ }
235
+ if (pointe.avancee) {
236
+ appendFileSync(ctx.journal, 'la copie avance sur la pointe de main avant la passe.\n');
237
+ }
238
+ return { memoire: { regeneration: pointe.regeneration ?? null }, etat, menee };
239
+ });
240
+ },
241
+ async fait(
242
+ { ticket, memoire, fait, parametres, faits, sorte, paquets, precedent, cle, essai },
243
+ annulation
244
+ ) {
245
+ const ctx = leContexte(ticket, memoire, { paquets });
246
+ ctx.sorte = sorte;
247
+ // A fact is read again on an attempt played again: the key of its activity names its sessions
248
+ // (`idDeSeance`), and its attempt says whether Temporal plays it again (`lancer` of
249
+ // scripts/seances.mjs).
250
+ ctx.cle = cle ?? null;
251
+ ctx.essaiDeLActe = essai ?? 1;
252
+ return rendre(ctx, async () => {
253
+ const avec = fait === 'seance' ? { ...parametres, precedent, annulation } : parametres;
254
+ try {
255
+ const valeur = await lireLeFait(ctx, fait, avec, faits);
256
+ return { valeur: valeur ?? null, memoire: laMemoire(ctx) };
257
+ } catch (e) {
258
+ if (!(e instanceof Arret)) {
259
+ throw e;
260
+ }
261
+ const { nom, rapport, rouges, motif, resultat, piece, question, qui, etape } = e;
262
+ return {
263
+ leve: { nom, rapport, rouges, motif, resultat, piece, question, qui, etape },
264
+ memoire: laMemoire(ctx),
265
+ };
266
+ }
267
+ });
268
+ },
269
+ async effets({ ticket, memoire, effets, menee, paquets }) {
270
+ const ctx = leContexte(ticket, memoire, { paquets });
271
+ return rendre(ctx, () => {
272
+ for (const e of effets) {
273
+ appliquer(ctx, e);
274
+ }
275
+ finirLEtape(ctx, menee ?? null);
276
+ return null;
277
+ });
278
+ },
279
+ async arret({ ticket, memoire, arret, etat, monter: aMonter, paquets, menee }) {
280
+ const ctx = leContexte(ticket, memoire, { paquets });
281
+ return rendre(ctx, () => {
282
+ const a = publierLArret(ctx, erreurDe(ctx, arret), etat);
283
+ finirLEtape(ctx, menee ?? null);
284
+ if (a.nom === 'a-repasser' && !aMonter) {
285
+ geste(ctx, 'a-repasser');
286
+ aLaFin(ctx, a.code);
287
+ return { code: a.code, nom: a.nom, question: null, etat: { ...a.etat, raison: a.nom } };
288
+ }
289
+ const code = monter(ctx, a);
290
+ aLaFin(ctx, code);
291
+ return arretDeLEtat(ctx, code, a.etat);
292
+ });
293
+ },
294
+ async fin({ ticket, memoire, etat, paquets }) {
295
+ const ctx = leContexte(ticket, memoire, { paquets });
296
+ return rendre(ctx, () => {
297
+ ecrireEtat(ctx, { ...etat, etape: 'integre', code: 0 });
298
+ aLaFin(ctx, 0);
299
+ return null;
300
+ });
301
+ },
302
+ async arreter({ ticket, memoire, etat, contexte: motif }) {
303
+ const ctx = leContexte(ticket, memoire, { arreter: true, contexte: motif ?? null });
304
+ return rendre(ctx, async () => {
305
+ await arreter(ctx, { ...etat, ...laMemoire(ctx) });
306
+ return null;
307
+ });
308
+ },
309
+ // One effect an act gave back, under the key of its activity, with the outcome of the
310
+ // circuit when it is not written (`ecrireLEffet`): said at the last attempt of its activity
311
+ // (`derniere`), tried again by Temporal before it, or the act fails.
312
+ async effet({ ticket, effet, cle, derniere }) {
313
+ const ctx = contexte({
314
+ ticket,
315
+ reprendre: false,
316
+ contexte: null,
317
+ depuis: null,
318
+ etendre: null,
319
+ arreter: true,
320
+ });
321
+ bases.add(ctx.base);
322
+ try {
323
+ ecrireLEffet(ctx, effet, cle ?? null, { reessayer: derniere === false });
324
+ return null;
325
+ } finally {
326
+ ctx.base.fermer();
327
+ }
328
+ },
329
+ };
330
+
331
+ // The opening of a run of <ctx> on the stopped state <arrete>, which the workflow holds (null at
332
+ // the first launch, and for a circuit the server no longer holds, reopened by --depuis), up to its
333
+ // plan: the plan still to write goes to the workflow (`plan`), which plays each of its steps (the
334
+ // act `plan`).
335
+ async function ouvrirSur(ctx, memoire, arrete) {
336
+ const lu = arrete ?? null;
337
+ if (lu) {
338
+ // What the stopped run kept and the new workflow of the answer does not hold yet.
339
+ for (const k of GARDEE) {
340
+ if (!(k in memoire) && lu[k] !== undefined) {
341
+ ctx[k] = lu[k];
342
+ }
343
+ }
344
+ }
345
+ const e = lu ? { ...lu, rang: memoire.rang ?? lu.rang ?? null } : null;
346
+ const o = await ouvrirJusquAuPlan(ctx, e);
347
+ if ('code' in o) {
348
+ aLaFin(ctx, o.code);
349
+ return { arret: arretDeLEtat(ctx, o.code, ctx.courant ?? {}) };
350
+ }
351
+ if (o.plan) {
352
+ return {
353
+ plan: {
354
+ etat: o.plan,
355
+ debut: o.debut,
356
+ contexte: ctx.contexte ?? null,
357
+ memoire: laMemoire(ctx),
358
+ },
359
+ };
360
+ }
361
+ finirLOuverture(ctx, o.debut);
362
+ return { ouverture: lOuverture(ctx, o.debut) };
363
+ }
364
+
365
+ // The opening of the run of <ctx> at the step <debut>, as the workflow keeps it.
366
+ const lOuverture = (ctx, debut) => ({
367
+ debut,
368
+ memoire: laMemoire(ctx),
369
+ ticket: {
370
+ id: ctx.ticket,
371
+ paquets: ctx.paquets,
372
+ sorte: ctx.sorte ?? null,
373
+ copie: ctx.copie,
374
+ },
375
+ });
376
+
377
+ // The exception of the stop <arret> the workflow hands the act `arret` (an Arret raised, an
378
+ // exception of an activity, a stop a decision returned).
379
+ function erreurDe(ctx, arret) {
380
+ if (arret.leve) {
381
+ const { nom, rapport, ...options } = arret.leve;
382
+ return new Arret(nom, rapport, options);
383
+ }
384
+ if (arret.inattendu) {
385
+ const erreur = new Error(arret.inattendu.message);
386
+ erreur.stack = arret.inattendu.pile ?? erreur.stack;
387
+ return erreur;
388
+ }
389
+ return arretDe(ctx, arret);
390
+ }
391
+
392
+ // The acts of the queue, each on its input: those that write give back their effects (`effets`).
393
+ Object.assign(ACTES, {
394
+ async situer({ racine, ticket }) {
395
+ return situerLeLot(laFile(racine), ticket);
396
+ },
397
+ // The replay of the ticket's branch on main writes the progress of its `npm run verifier` in
398
+ // the working directory of the ticket, where the board reads it while the circuit waits for the
399
+ // queue (`avecLAvancementDuTravail`, the kind `file`); a lot entered keeps it until the queue is done
400
+ // with the ticket closed, which removes the working directory (`retirerLeTravail`).
401
+ async avancer({ racine, ticket, branche }) {
402
+ const o = laFile(racine);
403
+ const entree = { ticket, branche };
404
+ const travail = path.join(racine, '.claude', 'worktrees', `${ticket}.travail`);
405
+ const r = avecLAvancementDuTravail(
406
+ travail,
407
+ { racine, genre: 'file', garder: lu => Boolean(lu.entre) },
408
+ () => avancerMain(o, entree)
409
+ );
410
+ return { ...(r.entre ? r : { issue: direLIssue(o, entree, r) }), effets: o.rendus };
411
+ },
412
+ async fermer({ racine, ticket, branche, commit }) {
413
+ const o = laFile(racine);
414
+ return { ...fermerLEntree(o, { ticket, branche, commit }), effets: o.rendus };
415
+ },
416
+ // A reading of the CI writes the steps of its run done over planned in the working directory of
417
+ // the ticket, where the board reads them (scripts/avancement.mjs `avancementDeLaCI`); one that
418
+ // looks for its run (no run found yet) empties the records of another.
419
+ async ci({ racine, ticket, sha, branche, passage }) {
420
+ const travail = path.join(racine, '.claude', 'worktrees', `${ticket}.travail`);
421
+ const avancement = avancementDeLaCI(travail, { nouvelle: passage === null });
422
+ return lireUneFoisLaCI(laFile(racine, avancement), { sha, branche, passage });
423
+ },
424
+ async conclure({ racine, ...e }) {
425
+ const o = laFile(racine);
426
+ return { ...conclureLaCI(o, e), effets: o.rendus };
427
+ },
428
+ // One effect an act of the queue gave back, under the key of its activity, with the outcome of
429
+ // the queue when it is not written (`ecrireLEffet`).
430
+ async 'effet-de-la-file'({ racine, effet, cle, derniere }) {
431
+ ecrireLEffet(
432
+ outilsDeLaFile(racine, l => process.stderr.write(`${l}\n`)),
433
+ effet,
434
+ cle,
435
+ {
436
+ reessayer: derniere === false,
437
+ }
438
+ );
439
+ return null;
440
+ },
441
+ });
442
+
443
+ /**
444
+ * The error <e> of an act as it goes to its activity (src/temporal/acte.ts): its message, its
445
+ * stack, and whether Temporal tries it again (`reessayable`, an effect not written before its last
446
+ * attempt, `EffetNonEcrit` of scripts/effets.mjs).
447
+ */
448
+ export const erreurDeLActe = e => ({
449
+ message: String(e?.message ?? e),
450
+ pile: String(e?.stack ?? e),
451
+ reessayable: e?.reessayable === true,
452
+ });
453
+
454
+ /** Plays the act <acte> on <entree>; <annulation> cancels it. */
455
+ export async function jouerLActe(acte, entree, annulation) {
456
+ const f = ACTES[acte];
457
+ if (!f) {
458
+ throw new Error(`acte inconnu du circuit : ${acte}`);
459
+ }
460
+ superviseurDeLActe = entree?.superviseur ?? null;
461
+ return f(entree, annulation);
462
+ }
463
+
464
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
465
+ // The act ends with its worker, its bases removed, the group of its session left running: the
466
+ // worker gone (its process another's parent), or its output closed.
467
+ const finir = () => {
468
+ for (const b of bases) {
469
+ b.fermer();
470
+ }
471
+ // The worker gone, its output is closed: nothing to drain, and the act ends at once, the group
472
+ // of its session left running for the attempt played again (not `exitCode`, which would wait
473
+ // for that session).
474
+ // eslint-disable-next-line no-process-exit
475
+ process.exit(1);
476
+ };
477
+ process.stdout.on('error', finir);
478
+ const annulation = new AbortController();
479
+ process.on('SIGTERM', () => annulation.abort());
480
+ const travailleur = process.ppid;
481
+ setInterval(() => {
482
+ if (process.ppid !== travailleur) {
483
+ finir();
484
+ }
485
+ }, 1000).unref();
486
+ try {
487
+ const entree = JSON.parse(readFileSync(0, 'utf8'));
488
+ dire('resultat', await jouerLActe(process.argv[2], entree, annulation.signal));
489
+ } catch (e) {
490
+ dire('erreur', erreurDeLActe(e));
491
+ process.exitCode = 1;
492
+ }
493
+ }
@@ -0,0 +1,21 @@
1
+ // The types of the rule of the queue of the tickets of a project (./file-des-tickets.mjs), which
2
+ // the queue of the tickets under Temporal (src/temporal/tickets/) imports.
3
+
4
+ /** A ticket as Beads gives it. */
5
+ export interface TicketDeBeads {
6
+ id: string;
7
+ status: string;
8
+ priority?: number;
9
+ labels?: string[];
10
+ created_at?: string;
11
+ dependencies?: Array<{ type: string; depends_on_id: string }>;
12
+ }
13
+
14
+ /** The tickets of <tous> that start now, in the order they start. */
15
+ export function ticketsAPartir<T extends TicketDeBeads>(
16
+ tous: T[],
17
+ o?: { enCours?: Set<string> }
18
+ ): T[];
19
+
20
+ /** Every ticket of the project at <racine>, the closed ones too, as Beads gives them; throws on a Beads that fails. */
21
+ export function lireLesTickets(racine: string): TicketDeBeads[];
@@ -0,0 +1,58 @@
1
+ // The rule of the queue of the tickets of a project: the tickets the owner validated (label
2
+ // `circuit`) whose dependencies are all closed start by themselves, by Beads priority, as Zuul and
3
+ // the merge queues start a change once what it depends on has merged. The queue of the tickets
4
+ // under Temporal (src/temporal/tickets/) reads the tickets and applies this rule.
5
+ //
6
+ // - A ticket starts when it is open, labelled `circuit`, with no circuit already on it, and when
7
+ // every dependency of the type `blocks` is closed: a dependency out of the list read (an unknown
8
+ // ticket) holds it back, a `parent-child` or `related` link does not.
9
+ // - The order is the Beads priority (0 first), then the creation (the oldest first).
10
+ // - A ticket whose dependency is open stays: the board says « attend <ticket> » (scripts/tableau.mjs).
11
+ import { spawnSync } from 'node:child_process';
12
+
13
+ /**
14
+ * The tickets of <tous> that start now, in the order they start.
15
+ * @param {Array<{ id: string, status: string, priority?: number, labels?: string[],
16
+ * created_at?: string, dependencies?: Array<{ type: string, depends_on_id: string }> }>} tous
17
+ * every ticket of the project, the closed ones too
18
+ * @param {{ enCours?: Set<string> }} [o] `enCours`, the tickets whose circuit already runs
19
+ * @returns {typeof tous}
20
+ */
21
+ export function ticketsAPartir(tous, { enCours = new Set() } = {}) {
22
+ const fermes = new Set(tous.filter(t => t.status === 'closed').map(t => t.id));
23
+ return tous
24
+ .filter(
25
+ t =>
26
+ t.status === 'open' &&
27
+ (t.labels ?? []).includes('circuit') &&
28
+ !enCours.has(t.id) &&
29
+ (t.dependencies ?? []).every(d => d.type !== 'blocks' || fermes.has(d.depends_on_id))
30
+ )
31
+ .sort(
32
+ (a, b) =>
33
+ (a.priority ?? 2) - (b.priority ?? 2) ||
34
+ Date.parse(a.created_at ?? '') - Date.parse(b.created_at ?? '') ||
35
+ a.id.localeCompare(b.id, 'en')
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Every ticket of the project at <racine>, the closed ones too, as Beads gives them; a Beads that
41
+ * fails or a list that does not parse throws, its reason named (`bd list`), never an empty list.
42
+ */
43
+ export function lireLesTickets(racine) {
44
+ const r = spawnSync('bd', ['list', '--all', '--limit', '0', '--json'], {
45
+ cwd: racine,
46
+ encoding: 'utf8',
47
+ maxBuffer: 256 * 1024 * 1024,
48
+ });
49
+ if (r.status !== 0) {
50
+ const raison = `${r.stderr ?? ''}`.trim() || r.error?.message || `code ${r.status}`;
51
+ throw new Error(`les tickets ne se lisent pas (bd list) : ${raison}`);
52
+ }
53
+ try {
54
+ return JSON.parse(r.stdout);
55
+ } catch (e) {
56
+ throw new Error(`les tickets ne se lisent pas (bd list) : ${e.message}`);
57
+ }
58
+ }