@roomi-fields/grillhouse 0.29.0 → 0.31.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 (263) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +769 -0
  3. package/agents/developpeur.md +0 -1
  4. package/agents/explorateur.md +0 -1
  5. package/agents/questionneur.md +0 -1
  6. package/agents/testwriter.md +0 -1
  7. package/bin/grillhouse.mjs +79 -18
  8. package/cadre/templates/projet/.github/workflows/ci.yml +2 -13
  9. package/cadre/templates/projet/CLAUDE.md +5 -1
  10. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  11. package/cadre/templates/projet/package.json +2 -2
  12. package/charte.md +24 -0
  13. package/dist/temporal/acte.d.ts +24 -0
  14. package/dist/temporal/acte.js +139 -0
  15. package/dist/temporal/acte.js.map +1 -0
  16. package/dist/temporal/attributs.d.ts +6 -0
  17. package/dist/temporal/attributs.js +15 -0
  18. package/dist/temporal/attributs.js.map +1 -0
  19. package/dist/temporal/circuit/activites.d.ts +13 -0
  20. package/dist/temporal/circuit/activites.js +33 -0
  21. package/dist/temporal/circuit/activites.js.map +1 -0
  22. package/dist/temporal/circuit/client.d.ts +72 -0
  23. package/dist/temporal/circuit/client.js +247 -0
  24. package/dist/temporal/circuit/client.js.map +1 -0
  25. package/dist/temporal/circuit/commande.d.ts +2 -0
  26. package/dist/temporal/circuit/commande.js +238 -0
  27. package/dist/temporal/circuit/commande.js.map +1 -0
  28. package/dist/temporal/circuit/contrat.d.ts +305 -0
  29. package/dist/temporal/circuit/contrat.js +30 -0
  30. package/dist/temporal/circuit/contrat.js.map +1 -0
  31. package/dist/temporal/circuit/deroule.d.ts +3 -0
  32. package/dist/temporal/circuit/deroule.js +540 -0
  33. package/dist/temporal/circuit/deroule.js.map +1 -0
  34. package/dist/temporal/client.d.ts +47 -0
  35. package/dist/temporal/client.js +69 -0
  36. package/dist/temporal/client.js.map +1 -0
  37. package/dist/temporal/commande.d.ts +2 -0
  38. package/dist/temporal/commande.js +94 -0
  39. package/dist/temporal/commande.js.map +1 -0
  40. package/dist/temporal/deroules.d.ts +5 -0
  41. package/dist/temporal/deroules.js +10 -0
  42. package/dist/temporal/deroules.js.map +1 -0
  43. package/dist/temporal/etat.d.ts +33 -0
  44. package/dist/temporal/etat.js +59 -0
  45. package/dist/temporal/etat.js.map +1 -0
  46. package/dist/temporal/file/activites.d.ts +10 -0
  47. package/dist/temporal/file/activites.js +25 -0
  48. package/dist/temporal/file/activites.js.map +1 -0
  49. package/dist/temporal/file/client.d.ts +4 -0
  50. package/dist/temporal/file/client.js +6 -0
  51. package/dist/temporal/file/client.js.map +1 -0
  52. package/dist/temporal/file/contrat.d.ts +158 -0
  53. package/dist/temporal/file/contrat.js +14 -0
  54. package/dist/temporal/file/contrat.js.map +1 -0
  55. package/dist/temporal/file/deroule.d.ts +15 -0
  56. package/dist/temporal/file/deroule.js +235 -0
  57. package/dist/temporal/file/deroule.js.map +1 -0
  58. package/dist/temporal/installation.d.ts +120 -0
  59. package/dist/temporal/installation.js +386 -0
  60. package/dist/temporal/installation.js.map +1 -0
  61. package/dist/temporal/places/activites.d.ts +8 -0
  62. package/dist/temporal/places/activites.js +13 -0
  63. package/dist/temporal/places/activites.js.map +1 -0
  64. package/dist/temporal/places/client.d.ts +28 -0
  65. package/dist/temporal/places/client.js +64 -0
  66. package/dist/temporal/places/client.js.map +1 -0
  67. package/dist/temporal/places/contrat.d.ts +106 -0
  68. package/dist/temporal/places/contrat.js +21 -0
  69. package/dist/temporal/places/contrat.js.map +1 -0
  70. package/dist/temporal/places/deroule.d.ts +3 -0
  71. package/dist/temporal/places/deroule.js +198 -0
  72. package/dist/temporal/places/deroule.js.map +1 -0
  73. package/dist/temporal/sonde/activites.d.ts +6 -0
  74. package/dist/temporal/sonde/activites.js +52 -0
  75. package/dist/temporal/sonde/activites.js.map +1 -0
  76. package/dist/temporal/sonde/contrat.d.ts +35 -0
  77. package/dist/temporal/sonde/contrat.js +10 -0
  78. package/dist/temporal/sonde/contrat.js.map +1 -0
  79. package/dist/temporal/sonde/deroule.d.ts +3 -0
  80. package/dist/temporal/sonde/deroule.js +39 -0
  81. package/dist/temporal/sonde/deroule.js.map +1 -0
  82. package/dist/temporal/tickets/activites.d.ts +7 -0
  83. package/dist/temporal/tickets/activites.js +81 -0
  84. package/dist/temporal/tickets/activites.js.map +1 -0
  85. package/dist/temporal/tickets/client.d.ts +10 -0
  86. package/dist/temporal/tickets/client.js +31 -0
  87. package/dist/temporal/tickets/client.js.map +1 -0
  88. package/dist/temporal/tickets/contrat.d.ts +56 -0
  89. package/dist/temporal/tickets/contrat.js +13 -0
  90. package/dist/temporal/tickets/contrat.js.map +1 -0
  91. package/dist/temporal/tickets/deroule.d.ts +3 -0
  92. package/dist/temporal/tickets/deroule.js +94 -0
  93. package/dist/temporal/tickets/deroule.js.map +1 -0
  94. package/dist/temporal/travailleur.d.ts +2 -0
  95. package/dist/temporal/travailleur.js +69 -0
  96. package/dist/temporal/travailleur.js.map +1 -0
  97. package/docs/ARCHITECTURE.md +646 -87
  98. package/docs/CADRE.md +27 -0
  99. package/docs/INTERFACE.md +139 -42
  100. package/hooks/crochet.mjs +19 -2
  101. package/hooks/hooks.json +11 -0
  102. package/package.json +16 -4
  103. package/scripts/activites.mjs +2255 -0
  104. package/scripts/aiguillage.d.mts +37 -0
  105. package/scripts/aiguillage.mjs +40 -14
  106. package/scripts/avancement.mjs +155 -26
  107. package/scripts/bilan.mjs +137 -43
  108. package/scripts/cadre.mjs +16 -4
  109. package/scripts/circuit.mjs +993 -4075
  110. package/scripts/circuits-cles.d.mts +4 -0
  111. package/scripts/circuits-cles.mjs +21 -0
  112. package/scripts/circuits-du-serveur.mjs +105 -0
  113. package/scripts/codes-de-sortie.mjs +9 -0
  114. package/scripts/commandes-composees.mjs +45 -41
  115. package/scripts/commandes-du-path.d.mts +7 -0
  116. package/scripts/commandes-du-path.mjs +25 -0
  117. package/scripts/composants-affectes.mjs +64 -21
  118. package/scripts/composition-des-langages.mjs +18 -12
  119. package/scripts/conformite.mjs +56 -28
  120. package/scripts/copies-finies.mjs +52 -47
  121. package/scripts/depart-du-ticket.d.mts +53 -0
  122. package/scripts/depart-du-ticket.mjs +124 -0
  123. package/scripts/dependances-internes.mjs +121 -0
  124. package/scripts/dernier-vert.mjs +61 -34
  125. package/scripts/dette.mjs +32 -11
  126. package/scripts/donnees-cles.mjs +244 -0
  127. package/scripts/droits.mjs +51 -16
  128. package/scripts/effets.mjs +352 -0
  129. package/scripts/empreinte-d-etape.mjs +17 -0
  130. package/scripts/engendres.mjs +15 -5
  131. package/scripts/enveloppe/enveloppe.mjs +259 -55
  132. package/scripts/enveloppe/lancer.sh +14 -18
  133. package/scripts/enveloppe/paquets-du-plan.mjs +2 -2
  134. package/scripts/enveloppe/travail-de-la-copie.mjs +41 -13
  135. package/scripts/etapes.mjs +5 -2
  136. package/scripts/faits-du-circuit.mjs +493 -0
  137. package/scripts/file-des-tickets.d.mts +21 -0
  138. package/scripts/file-des-tickets.mjs +58 -0
  139. package/scripts/flux-des-paquets.mjs +201 -0
  140. package/scripts/gardes-du-cadre.mjs +21 -5
  141. package/scripts/init.mjs +11 -4
  142. package/scripts/integration/file.mjs +544 -434
  143. package/scripts/integration/integrer.mjs +87 -43
  144. package/scripts/integration/rejeu.mjs +45 -13
  145. package/scripts/jointure.d.ts +151 -28
  146. package/scripts/langages/cargo/commandes.mjs +383 -124
  147. package/scripts/langages/cargo/composants.mjs +154 -42
  148. package/scripts/langages/cargo/exemples.mjs +12 -21
  149. package/scripts/langages/cargo/index.mjs +22 -8
  150. package/scripts/langages/cargo/sccache.mjs +8 -14
  151. package/scripts/langages/cargo/tests-de-head.mjs +25 -9
  152. package/scripts/langages/python/commandes.mjs +218 -100
  153. package/scripts/langages/python/composants.mjs +53 -21
  154. package/scripts/langages/python/exemples.mjs +6 -16
  155. package/scripts/langages/python/index.mjs +28 -8
  156. package/scripts/langages/python/lot.mjs +1 -36
  157. package/scripts/langages/typescript/chemins-des-tests.mjs +6 -2
  158. package/scripts/langages/typescript/composants.mjs +9 -3
  159. package/scripts/langages/typescript/consommateurs-arbitres.mjs +40 -14
  160. package/scripts/langages/typescript/consommateurs.mjs +39 -14
  161. package/scripts/langages/typescript/construire.mjs +6 -163
  162. package/scripts/langages/typescript/elements-du-lot.mjs +36 -12
  163. package/scripts/langages/typescript/exemples.mjs +3 -11
  164. package/scripts/langages/typescript/frontieres.mjs +66 -22
  165. package/scripts/langages/typescript/index-interfaces.mjs +36 -13
  166. package/scripts/langages/typescript/index.mjs +50 -61
  167. package/scripts/langages/typescript/interfaces-contre-code.mjs +113 -45
  168. package/scripts/langages/typescript/lecteurs.mjs +36 -11
  169. package/scripts/langages/typescript/migrations/0.23.0-config-vitest.mjs +15 -5
  170. package/scripts/langages/typescript/migrations/0.25.0-chemins-des-tests.mjs +6 -2
  171. package/scripts/langages/typescript/migrations/0.25.0-tailles-des-tests.mjs +6 -2
  172. package/scripts/langages/typescript/migrations/0.30.0-prefixe-des-tickets.mjs +63 -0
  173. package/scripts/langages/typescript/migrations/0.30.0-tailles-des-outils-lourds.mjs +33 -0
  174. package/scripts/langages/typescript/migrations/0.30.0-titres-nommant-un-ticket.mjs +40 -0
  175. package/scripts/langages/typescript/mise-a-jour.mjs +1 -2
  176. package/scripts/langages/typescript/parcours.mjs +12 -4
  177. package/scripts/langages/typescript/regle-des-tests.mjs +9 -3
  178. package/scripts/langages/typescript/resumes.mjs +9 -3
  179. package/scripts/langages/typescript/tailles-des-tests.mjs +93 -20
  180. package/scripts/langages/typescript/tests-de-nuit.mjs +15 -10
  181. package/scripts/langages/typescript/tests.mjs +40 -15
  182. package/scripts/langages/typescript/titres-de-tests.mjs +320 -0
  183. package/scripts/langages/typescript/turbo-des-paquets.mjs +327 -81
  184. package/scripts/langages/typescript/verdict.mjs +4 -2
  185. package/scripts/langages/typescript/verifier.mjs +58 -20
  186. package/scripts/langages/typescript/vitest-config/avancement.reporter.mjs +15 -5
  187. package/scripts/langages/typescript/vitest-config/base.mjs +29 -3
  188. package/scripts/langages/typescript/vitest-config/bornes.mjs +13 -0
  189. package/scripts/langages/typescript/vitest-config/changements.mjs +21 -8
  190. package/scripts/langages/typescript/vitest-config/cibles.mjs +36 -14
  191. package/scripts/langages/typescript/vitest-config/delais.mjs +60 -0
  192. package/scripts/langages/typescript/vitest-config/delais.setup.mjs +11 -0
  193. package/scripts/langages/typescript/vitest-config/duree.classement.mjs +108 -0
  194. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +56 -59
  195. package/scripts/langages/typescript/vitest-config/lances.mjs +83 -27
  196. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +10 -0
  197. package/scripts/langages/typescript/vitest-config/resultats.mjs +3 -1
  198. package/scripts/langages/typescript/vitest.nuit.config.mjs +4 -0
  199. package/scripts/lint-des-scripts.mjs +58 -0
  200. package/scripts/mesure/base-de-passe.mjs +117 -25
  201. package/scripts/mesure/pression.mjs +12 -6
  202. package/scripts/mesure-de-la-machine.d.mts +21 -0
  203. package/scripts/mesure-de-la-machine.mjs +76 -0
  204. package/scripts/migrations/0.23.0-charte-importee.mjs +6 -2
  205. package/scripts/migrations/0.23.0-crochets-de-seance.mjs +25 -8
  206. package/scripts/migrations/0.23.0-marche-du-projet.mjs +18 -6
  207. package/scripts/migrations/0.23.2-copies-du-cadre.mjs +56 -18
  208. package/scripts/migrations/0.24.12-tri-des-decouvertes.mjs +6 -2
  209. package/scripts/migrations/0.25.0-script-des-tests.mjs +15 -5
  210. package/scripts/migrations/0.30.0-ci-appelle-la-verification.mjs +124 -0
  211. package/scripts/migrations/0.31.0-paquets-dans-le-graphe.mjs +81 -0
  212. package/scripts/migrations.mjs +5 -0
  213. package/scripts/nuit.sh +25 -3
  214. package/scripts/outil.mjs +3 -1
  215. package/scripts/outils-cles.d.mts +24 -0
  216. package/scripts/outils-cles.mjs +18 -8
  217. package/scripts/paquet-npm.mjs +157 -0
  218. package/scripts/paquet.mjs +73 -4
  219. package/scripts/paquets.mjs +46 -10
  220. package/scripts/passe-de-la-machine.mjs +71 -0
  221. package/scripts/places-de-la-machine.mjs +414 -0
  222. package/scripts/places-du-serveur.mjs +170 -0
  223. package/scripts/prefixe-des-tickets.mjs +68 -0
  224. package/scripts/preparation.mjs +25 -8
  225. package/scripts/registre.mjs +9 -4
  226. package/scripts/regles-des-places.d.mts +36 -0
  227. package/scripts/regles-des-places.mjs +70 -0
  228. package/scripts/reponses-du-circuit.d.mts +6 -0
  229. package/scripts/reponses-du-circuit.mjs +28 -0
  230. package/scripts/reprise.mjs +66 -0
  231. package/scripts/resultats.mjs +112 -46
  232. package/scripts/retirer-les-copies-finies.mjs +25 -0
  233. package/scripts/sans-reponse.d.mts +4 -0
  234. package/scripts/sans-reponse.mjs +13 -0
  235. package/scripts/seances.mjs +936 -0
  236. package/scripts/services-du-noyau.mjs +27 -8
  237. package/scripts/session-start.sh +2 -2
  238. package/scripts/sortie.mjs +3 -3
  239. package/scripts/sous-commandes.mjs +41 -10
  240. package/scripts/style-a-l-ecriture.mjs +260 -0
  241. package/scripts/superviseur.mjs +122 -111
  242. package/scripts/tableau.mjs +180 -117
  243. package/scripts/taches-du-graphe.mjs +348 -0
  244. package/scripts/ticket-du-circuit.mjs +216 -0
  245. package/scripts/transitions.d.mts +148 -0
  246. package/scripts/transitions.mjs +1018 -0
  247. package/scripts/verrou-de-fichier.mjs +8 -4
  248. package/scripts/verrou-de-machine.mjs +150 -51
  249. package/scripts/verrous/commande.mjs +50 -17
  250. package/scripts/verrous/ticket-du-sous-agent.mjs +9 -3
  251. package/scripts/verrous/verrou.mjs +42 -14
  252. package/skills/explorateur/SKILL.md +9 -2
  253. package/skills/grill/SKILL.md +1 -1
  254. package/skills/mesure/SKILL.md +3 -0
  255. package/skills/pitmaster/SKILL.md +17 -18
  256. package/skills/pitmaster/references/consigne-agent.md +5 -1
  257. package/skills/release/SKILL.md +3 -3
  258. package/skills/relecteur/SKILL.md +5 -3
  259. package/skills/testwriter/SKILL.md +49 -31
  260. package/scripts/demon.mjs +0 -251
  261. package/scripts/integration/file-attente.mjs +0 -61
  262. package/scripts/langages/cargo/touches.mjs +0 -93
  263. package/scripts/langages/typescript/script-des-tests.mjs +0 -6
@@ -1,17 +1,9 @@
1
- #!/usr/bin/env node
2
- // The queue: brings the branches `agent/<ticket>` the integration committed onto main, one at a time,
3
- // in their order of arrival (scripts/integration/file-attente.mjs). Run from the main tree by the
4
- // circuit of a ticket (scripts/circuit.mjs), once it has put the ticket's branch in the queue, and
5
- // by the supervisor by hand.
1
+ // The gestures of the queue, which brings the branches `agent/<ticket>` the integration committed
2
+ // onto main, one at a time: the workflow of the queue of a project (`file:<racine>`,
3
+ // src/temporal/file/deroule.ts) plays them, each in an act of its own (scripts/faits-du-circuit.mjs),
4
+ // for the entries the circuits of the tickets send it at their step 5.2, in their order of arrival.
6
5
  //
7
- // npx grillhouse file [--ci <ticket>]
8
- //
9
- // No argument, or `--ci <ticket>` (below; exit 2 and the usage otherwise). It takes the branches waiting one by one until none is
10
- // left, then exits 0, whatever became of each branch. A queue launched while another runs exits 0 at
11
- // once, refusing nothing: the running queue takes the branch that arrived (it reads the entries
12
- // again before it lets go of its lock, `.git/file-integration.lock`).
13
- //
14
- // For each branch, against the main of the moment:
6
+ // For each branch, against the main of the moment (`avancerMain`):
15
7
  // - main is an ancestor of the branch (main has not moved since its base): main moves forward onto
16
8
  // the branch (`merge --ff-only`), nothing replayed;
17
9
  // - main has moved: the branch is replaced on main in the queue's own copy
@@ -36,17 +28,20 @@
36
28
  // - a branch that does not replace (the files in conflict) or whose `npm run verifier` is red once
37
29
  // replaced leaves the queue: its ticket loses `en-file`, reopens with a comment that
38
30
  // names the files or ends with the output of the tests, and the branch stays where it is, for
39
- // the relaunch of its ticket (scripts/enveloppe/lancer.sh);
31
+ // the resumption of its circuit;
40
32
  // - a branch whose replay cannot be done (the copy does not get ready, main does not take the
41
33
  // branch, the main tree holds a file of the lot), or whose `npm run verifier` is « à repasser »
42
34
  // once replaced (75: the wait for the lock of the machine reached its bound,
43
35
  // scripts/verrou-de-machine.mjs; neither green nor red), stays in the queue, the reason written to its
44
- // ticket, which is neither reopened nor closed, and the queue goes on; the next queue takes it
45
- // again. Any other code than 0 and 75 is red.
46
- // At its entry on main, the branch's ticket closes « intégré : <commit> », loses `en-file`, the
47
- // working directory of its circuit (`.claude/worktrees/<ticket>.travail`, scripts/circuit.mjs),
48
- // which lives as long as the ticket, is removed, and the branch is deleted; a branch git does not delete (its copy still in place) is written to the
49
- // ticket, which closes all the same. Then main is pushed to origin, on the branch
36
+ // ticket, which is neither reopened nor closed, and the queue goes on; the circuit of the ticket
37
+ // stops at « a-repasser », and its resumption sends the branch again. Any other code than 0 and
38
+ // 75 is red.
39
+ // At its entry on main, the branch's ticket closes « intégré : <commit> », loses `en-file`, and the
40
+ // branch is deleted; a branch git does not delete (its copy still in place) is written to the
41
+ // ticket, which closes all the same. The working directory of its circuit
42
+ // (`.claude/worktrees/<ticket>.travail`, scripts/circuit.mjs), which lives as long as the ticket
43
+ // and holds the progress the board reads, the CI's included, is removed when the queue is done
44
+ // with the ticket closed: its CI concluded, or its push not made (`retirerLeTravail`). Then main is pushed to origin, on the branch
50
45
  // `grillhouse.poussee.commit` of main's package.json (`main` without the key); a refused push is
51
46
  // written to the ticket and does not stop the queue.
52
47
  // Once pushed, the queue reads the CI of the commit pushed, as a merge queue waits for its checks.
@@ -55,60 +50,58 @@
55
50
  // branch it pushes to (`fluxDeLaBranche`, the files `.github/workflows/*.yml` and `*.yaml`, their
56
51
  // `on` and its filters as GitHub reads them); with none, the ticket is told in one line that
57
52
  // there is no CI for that branch, and nothing is waited for. A workflow the queue cannot judge (a
58
- // file it cannot read, a filter on the paths) counts as one that runs. With one, it looks for its
59
- // run (`gh run list --commit <sha> --json databaseId,status,conclusion`) for 2 min at most
60
- // (GRILLHOUSE_CI_RECHERCHE_MS replaces it, in milliseconds), the time the CI takes to create it,
61
- // then reads it (`gh run view <id> --json status,conclusion,jobs`) every 10 s
62
- // (GRILLHOUSE_CI_PAS_MS), as `gh run watch` does, until it completes, for 30 min at most
63
- // (GRILLHOUSE_CI_ATTENTE_MS): green on the conclusion `success`, red on any other. Under the
64
- // circuit's progress directory (GRILLHOUSE_AVANCEMENT, scripts/avancement.mjs), each reading writes
65
- // there the steps of the run done over planned, which the board shows; the queue's own runs of
66
- // `npm run verifier` play out of it. A red CI reopens the ticket (`bd reopen`), its comment giving the
67
- // address of the run (`gh run view <id> --json url`) and the end of `gh run view <id>
68
- // --log-failed`. Without `gh`, without a run found, with `gh` refusing or past the 30 min, the
69
- // ticket is told that the CI was not read, and why, and stays closed. The run is read at its current
70
- // attempt (`gh run view <id>` without `--attempt`), as a merge queue judges the last attempt of a
71
- // commit's checks.
72
- // `--ci <ticket>` reads again the CI of a ticket a red CI reopened, which the circuit runs at 5.2
73
- // on `--reprendre` (scripts/circuit.mjs, `argumentsDeLaFile`), once the supervisor had the failed
74
- // jobs run again (`gh run rerun <id> --failed`): the commit of main that delivers the ticket, its
75
- // CI read as above (`relireCI`); green, the ticket closes « intégré : <commit> », the run named at
76
- // it; red or not read, it stays open, the reading at the ticket. A flaky test has no path of its
77
- // own: the red comment gives the charter's rule, a test known red goes into quarantine in the test
78
- // itself, with the ticket that fixes it. It takes no lock: it does not move main.
53
+ // file it cannot read, a filter on the paths) counts as one that runs. With one, each reading
54
+ // (`lireUneFoisLaCI`) looks for its run (`gh run list --commit <sha> --json
55
+ // databaseId,status,conclusion`), then reads it (`gh run view <id> --json status,conclusion,jobs`),
56
+ // as `gh run watch` does; the workflow of the CI of the commit spaces the readings and bounds the
57
+ // search and the wait (`ciDuCommit`). Green on the conclusion `success`, red on any other. Under
58
+ // the circuit's progress directory (scripts/avancement.mjs), each reading writes there the steps
59
+ // of the run done over planned, which the board shows. A red CI reopens the ticket (`bd reopen`),
60
+ // its comment giving the address of the run (`gh run view <id> --json url`) and the end of `gh run
61
+ // view <id> --log-failed` (`conclureLaCI`). Without `gh`, without a run found, with `gh` refusing
62
+ // or past the wait, the ticket is told that the CI was not read, and why, and stays closed. The
63
+ // run is read at its current attempt (`gh run view <id>` without `--attempt`), as a merge queue
64
+ // judges the last attempt of a commit's checks: after a red CI, `--reprendre` reads again the CI
65
+ // of the ticket's commit on main (`situerLeLot`), once the supervisor had the failed jobs run
66
+ // again (`gh run rerun <id> --failed`); green, the ticket closes « intégré : <commit> », the run
67
+ // named at it; red or not read, it stays open, the reading at the ticket. A flaky test has no path
68
+ // of its own: the red comment gives the charter's rule, a test known red goes into quarantine in
69
+ // the test itself, with the ticket that fixes it.
79
70
  // Every comment and change of the queue at a ticket is written under the author `file`, which bd
80
71
  // reads in BEADS_ACTOR, as the circuit writes its own lines under `circuit`.
81
72
  import { spawnSync } from 'node:child_process';
82
73
  import { existsSync, rmSync } from 'node:fs';
83
74
  import { createRequire } from 'node:module';
84
75
  import path from 'node:path';
85
- import { pathToFileURL } from 'node:url';
86
76
  import { couvertPar, engendresDe, regenerer, touchesPar } from '../engendres.mjs';
77
+ import { avecLesDonnees, donneesDe } from '../donnees-cles.mjs';
87
78
  import { avecLesOutils, outilsDe } from '../outils-cles.mjs';
88
79
  import { lireCommit } from '../poussee-cles.mjs';
89
80
  import { commitsDelivering, gitLog } from '../un-commit-par-ticket.mjs';
90
- import { attendreUnPeu, lacherVerrou, prendreVerrou } from '../verrou-de-fichier.mjs';
91
- import { dossierCommun, lireEntrees, retirerEntree } from './file-attente.mjs';
92
81
  import { ouvrirCopie } from './rejeu.mjs';
93
- import { A_REPASSER } from '../mesure/pression.mjs';
94
- import { AVANCEMENT, ecrireTache } from '../mesure/avancement.mjs';
82
+ import { A_REPASSER } from '../codes-de-sortie.mjs';
83
+ import { ecrireTache } from '../mesure/avancement.mjs';
84
+ import { ACTEUR, emettre } from '../effets.mjs';
85
+ import { enUneLigne } from '../ticket-du-circuit.mjs';
95
86
 
96
87
  const ESSAIS_PAR_BRANCHE = 5;
97
- // The variable in which bd reads the author of a comment, and the queue's author.
98
- const ACTEUR = 'BEADS_ACTOR';
88
+ // The queue's author.
99
89
  export const AUTEUR_DE_LA_FILE = 'file';
90
+
91
+ // The comment <texte> at <ticket> with the tools <o>, by the queue: the effect `commentaire`
92
+ // (../effets.mjs), written at once by the queue on its file, gathered by an act of the queue under
93
+ // Temporal, which the workflow writes in an activity of its own, under its key.
94
+ const commenterAu = (o, ticket, texte) =>
95
+ emettre(o, { genre: 'commentaire', ticket, texte, auteur: AUTEUR_DE_LA_FILE });
100
96
  // The reason of the closure of a ticket the queue brought onto main, before its commit, which the
101
97
  // circuit reads to name that commit (scripts/circuit.mjs, the tri of the discoveries).
102
98
  export const INTEGRE = 'intégré : ';
103
- // How long the queue looks for the run of the CI, then waits for it.
104
- const RECHERCHE_CI_MS = 2 * 60 * 1000;
105
- const ATTENTE_CI_MS = 30 * 60 * 1000;
106
- // The gap between two readings of the run, as `gh run watch` reads it again.
107
- const PAS_CI_MS = 10 * 1000;
108
99
  // The steps done over planned of the view <vue> of a run (`gh run view --json jobs`), written to
109
100
  // the progress directory <avancement> as the record `etapes-de-la-ci`; nothing without one.
110
101
  function ecrireLesEtapes(avancement, vue) {
111
- if (!avancement) return;
102
+ if (!avancement) {
103
+ return;
104
+ }
112
105
  const etapes = (Array.isArray(vue?.jobs) ? vue.jobs : []).flatMap(j =>
113
106
  Array.isArray(j?.steps) ? j.steps : []
114
107
  );
@@ -122,11 +115,6 @@ function ecrireLesEtapes(avancement, vue) {
122
115
  }
123
116
  }
124
117
 
125
- const delai = (variable, defaut) => {
126
- const v = Number(process.env[variable]);
127
- return Number.isFinite(v) && process.env[variable] !== '' && v >= 0 ? v : defaut;
128
- };
129
-
130
118
  // The directory of the workflows GitHub reads, and the extensions it reads in it.
131
119
  const DOSSIER_DES_FLUX = '.github/workflows';
132
120
  const EXTENSIONS_DES_FLUX = /\.ya?ml$/;
@@ -151,7 +139,9 @@ function motifDeGitHub(motif) {
151
139
  re += c;
152
140
  } else if (c === '[') {
153
141
  const fin = motif.indexOf(']', i + 1);
154
- if (fin < 0) throw new Error(`motif sans fin : ${motif}`);
142
+ if (fin < 0) {
143
+ throw new Error(`motif sans fin : ${motif}`);
144
+ }
155
145
  re += motif.slice(i, fin + 1);
156
146
  i = fin;
157
147
  } else {
@@ -167,23 +157,35 @@ function motifDeGitHub(motif) {
167
157
  // `tags` or `tags-ignore` alone run on no branch. A filter on the paths, or a form the queue does
168
158
  // not judge, counts as one that runs.
169
159
  function pousseeSurLaBranche(push, branche) {
170
- if (push === null || push === undefined) return true;
171
- if (typeof push !== 'object' || Array.isArray(push)) return true;
172
- if (push.paths || push['paths-ignore']) return true;
160
+ if (push === null || push === undefined) {
161
+ return true;
162
+ }
163
+ if (typeof push !== 'object' || Array.isArray(push)) {
164
+ return true;
165
+ }
166
+ if (push.paths || push['paths-ignore']) {
167
+ return true;
168
+ }
173
169
  const { branches, 'branches-ignore': ignorees } = push;
174
- if (branches && ignorees) return true;
170
+ if (branches && ignorees) {
171
+ return true;
172
+ }
175
173
  const motifs = l => (Array.isArray(l) ? l : [l]).map(String);
176
174
  if (branches) {
177
175
  let dedans = false;
178
176
  for (const m of motifs(branches)) {
179
177
  const negatif = m.startsWith('!');
180
- if (motifDeGitHub(negatif ? m.slice(1) : m).test(branche)) dedans = !negatif;
178
+ if (motifDeGitHub(negatif ? m.slice(1) : m).test(branche)) {
179
+ dedans = !negatif;
180
+ }
181
181
  }
182
182
  return dedans;
183
183
  }
184
184
  if (ignorees) {
185
185
  const l = motifs(ignorees);
186
- if (l.some(m => m.startsWith('!'))) return true;
186
+ if (l.some(m => m.startsWith('!'))) {
187
+ return true;
188
+ }
187
189
  return !l.some(m => motifDeGitHub(m).test(branche));
188
190
  }
189
191
  return !(push.tags || push['tags-ignore']);
@@ -195,16 +197,23 @@ function pousseeSurLaBranche(push, branche) {
195
197
  export function fluxDeLaBranche(fichiers, branche) {
196
198
  return fichiers
197
199
  .filter(({ texte }) => {
198
- if (texte === null) return true;
200
+ if (texte === null) {
201
+ return true;
202
+ }
199
203
  try {
200
204
  // Loaded only for a workflow to read: a project without one, or before its `npm install`,
201
205
  // runs its queue without the library (which, absent, counts the workflow as one that runs).
202
206
  const require = createRequire(import.meta.url);
203
207
  const on = require('yaml').parse(texte)?.on;
204
- if (typeof on === 'string') return on === 'push';
205
- if (Array.isArray(on)) return on.includes('push');
206
- if (on && typeof on === 'object')
208
+ if (typeof on === 'string') {
209
+ return on === 'push';
210
+ }
211
+ if (Array.isArray(on)) {
212
+ return on.includes('push');
213
+ }
214
+ if (on && typeof on === 'object') {
207
215
  return 'push' in on && pousseeSurLaBranche(on.push, branche);
216
+ }
208
217
  return false;
209
218
  } catch {
210
219
  return true;
@@ -213,9 +222,8 @@ export function fluxDeLaBranche(fichiers, branche) {
213
222
  .map(({ chemin }) => chemin);
214
223
  }
215
224
 
216
- // The verdicts of a reading of the CI (`lireCI`).
225
+ // The verdicts of a reading of the CI (`lireUneFoisLaCI`, then the workflow `ciDuCommit`).
217
226
  const VERTE = 'verte';
218
- const ROUGE = 'rouge';
219
227
  const SANS_CI = 'sans-ci';
220
228
  const NON_LUE = 'non-lue';
221
229
 
@@ -244,407 +252,509 @@ const ghDans =
244
252
  ...options,
245
253
  });
246
254
 
247
- // The CI of the commit <sha> pushed to <branche>, for the ticket <ticket>, read with the tools <o>
248
- // (`{ racine, principale, bd, gh, dire, avancement }`: the main tree, its branch, bd, the GitHub
249
- // CLI, a line of the output, the progress directory or null): `{ verdict, passage }`, the verdict
250
- // VERTE, ROUGE, SANS_CI or NON_LUE, and the id of the run read. The run is read by `gh run view
251
- // <id>`, which gives its current attempt: a run whose failed jobs were run again
252
- // (`gh run rerun <id> --failed`) is judged on that attempt, as a merge queue judges the last
253
- // attempt of a commit's checks. No CI, red or not read, the ticket is told so; green, nothing is
254
- // written to it.
255
- function lireCI(o, ticket, sha, branche) {
256
- const court = sha.slice(0, 7);
257
- const commenter = texte => o.bd('comments', 'add', ticket, texte);
258
- if (fluxDuCommit(o.racine, sha, branche).length === 0) {
259
- const texte = `Aucune CI pour origin/${branche} : aucun flux de ${DOSSIER_DES_FLUX} de ${court} ne se lance sur la branche ${branche}, la file n'en attend pas.`;
260
- commenter(texte);
261
- o.dire(`✓ ${texte}`);
262
- return { verdict: SANS_CI, passage: null };
263
- }
264
- const { gh } = o;
265
- const nonLue = raison => {
266
- commenter(`## CI non lue\n\nLa CI de ${court} n'a pas été lue : ${raison}`);
267
- o.dire(`⚠ CI de ${court} non lue : ${raison}`);
268
- return { verdict: NON_LUE, passage: null };
255
+ /**
256
+ * The tools of the queue on the main tree <racine>, its lines said by <dire>: `{ racine,
257
+ * principale, bd, gh, dire, avancement }`, bd run under the queue's author (BEADS_ACTOR), the
258
+ * branch of the main tree (null when it is on none).
259
+ */
260
+ export function outilsDeLaFile(racine, dire, avancement = null) {
261
+ const bd = (...a) => {
262
+ const r = spawnSync('bd', a, {
263
+ cwd: racine,
264
+ encoding: 'utf8',
265
+ maxBuffer: 256 * 1024 * 1024,
266
+ env: { ...process.env, [ACTEUR]: AUTEUR_DE_LA_FILE },
267
+ });
268
+ if (r.status !== 0) {
269
+ process.stderr.write(`bd ${a[0]} ${a[1] ?? ''} : ${r.stderr}`);
270
+ }
271
+ return r;
269
272
  };
270
- const recherche = delai('GRILLHOUSE_CI_RECHERCHE_MS', RECHERCHE_CI_MS);
271
- const debut = Date.now();
272
- let passage = null;
273
- for (;;) {
273
+ const principale =
274
+ spawnSync('git', ['-C', racine, 'symbolic-ref', '--short', '-q', 'HEAD'], {
275
+ encoding: 'utf8',
276
+ }).stdout.trim() || null;
277
+ return { racine, principale, bd, gh: ghDans(racine), dire, avancement };
278
+ }
279
+
280
+ /**
281
+ * One reading of the CI of the commit <sha> pushed to <branche>, with the tools <o> (`outilsDeLaFile`),
282
+ * the run <passage> found by a reading before (null while it is looked for): `{ etat: 'sans-ci' }`
283
+ * (no workflow runs on a push to the branch), `{ etat: 'cherche' }` (no run yet), `{ etat:
284
+ * 'en-cours', passage }`, `{ etat: 'finie', passage, conclusion }`, or `{ etat: 'non-lue', raison
285
+ * }` (gh absent, refusing, or its output unreadable). The run is read at its current attempt
286
+ * (`gh run view <id>` without `--attempt`). A run found is read at once. It writes nothing to the
287
+ * ticket: `conclureLaCI` does.
288
+ */
289
+ export function lireUneFoisLaCI(o, { sha, branche, passage = null }) {
290
+ const { gh } = o;
291
+ let id = passage;
292
+ if (id === null) {
293
+ if (fluxDuCommit(o.racine, sha, branche).length === 0) {
294
+ return { etat: SANS_CI };
295
+ }
274
296
  const r = gh(['run', 'list', '--commit', sha, '--json', 'databaseId,status,conclusion']);
275
- if (r.error) return nonLue(`gh ne se lance pas (${r.error.code ?? r.error.message}).`);
276
- if (r.status !== 0) return nonLue(`gh run list refuse :\n${`${r.stderr}${r.stdout}`.trim()}`);
297
+ if (r.error) {
298
+ return { etat: NON_LUE, raison: `gh ne se lance pas (${r.error.code ?? r.error.message}).` };
299
+ }
300
+ if (r.status !== 0) {
301
+ return { etat: NON_LUE, raison: `gh run list refuse :\n${`${r.stderr}${r.stdout}`.trim()}` };
302
+ }
277
303
  let passages = [];
278
304
  try {
279
305
  passages = JSON.parse(r.stdout || '[]');
280
306
  } catch {
281
- return nonLue(`gh run list rend une sortie illisible :\n${r.stdout.trim()}`);
282
- }
283
- passage = passages.find(x => x?.databaseId);
284
- const reste = recherche - (Date.now() - debut);
285
- if (passage || reste <= 0) break;
286
- attendreUnPeu(Math.min(10_000, reste));
287
- }
288
- if (!passage) {
289
- return nonLue(`aucun passage de la CI pour ce commit en ${Math.round(recherche / 1000)} s.`);
290
- }
291
- const id = String(passage.databaseId);
292
- const attente = delai('GRILLHOUSE_CI_ATTENTE_MS', ATTENTE_CI_MS);
293
- const pas = delai('GRILLHOUSE_CI_PAS_MS', PAS_CI_MS);
294
- const limite = Date.now() + attente;
295
- let vue = null;
296
- for (;;) {
297
- const v = gh(['run', 'view', id, '--json', 'status,conclusion,jobs'], {
298
- timeout: 60_000,
299
- killSignal: 'SIGKILL',
300
- });
301
- if (v.error) return nonLue(`gh ne se lance pas (${v.error.code ?? v.error.message}).`);
302
- if (v.status !== 0) return nonLue(`gh run view refuse :\n${`${v.stderr}${v.stdout}`.trim()}`);
303
- try {
304
- vue = JSON.parse(v.stdout || '{}');
305
- } catch {
306
- return nonLue(`gh run view rend une sortie illisible :\n${v.stdout.trim()}`);
307
+ return {
308
+ etat: NON_LUE,
309
+ raison: `gh run list rend une sortie illisible :\n${r.stdout.trim()}`,
310
+ };
307
311
  }
308
- ecrireLesEtapes(o.avancement, vue);
309
- if (vue?.status === 'completed') break;
310
- const reste = limite - Date.now();
311
- if (reste <= 0) {
312
- return nonLue(`le passage ${id} n'a pas fini en ${Math.round(attente / 60_000)} min.`);
312
+ const trouve = passages.find(x => x?.databaseId);
313
+ if (!trouve) {
314
+ return { etat: 'cherche' };
313
315
  }
314
- attendreUnPeu(Math.min(pas, reste));
315
- }
316
- if (vue.conclusion === 'success') {
317
- o.dire(`✓ CI de ${court} verte (passage ${id})`);
318
- return { verdict: VERTE, passage: id };
319
- }
320
- const url = gh(['run', 'view', id, '--json', 'url', '--jq', '.url']).stdout?.trim() || id;
321
- const journal = `${gh(['run', 'view', id, '--log-failed']).stdout ?? ''}`
322
- .trim()
323
- .split('\n')
324
- .slice(-60)
325
- .join('\n');
326
- commenter(
327
- `## CI rouge\n\nLa CI de ${court} sur ${o.principale} est rouge : ${url}\n\nLa fin de gh run view ${id} --log-failed :\n\n${journal}\n\nLe ticket est rouvert : sa correction entre sous son numéro. Un rejeu vert de la même CI (\`gh run rerun ${id} --failed\`), puis \`--reprendre\` du circuit, le ferme ; un test connu instable se met en quarantaine dans le test, avec le ticket qui le corrige.`
328
- );
329
- o.dire(`✗ CI de ${court} rouge (passage ${id}) : ${ticket} rouvert`);
330
- return { verdict: ROUGE, passage: id };
316
+ id = String(trouve.databaseId);
317
+ }
318
+ const v = gh(['run', 'view', id, '--json', 'status,conclusion,jobs'], {
319
+ timeout: 60_000,
320
+ killSignal: 'SIGKILL',
321
+ });
322
+ if (v.error) {
323
+ return { etat: NON_LUE, raison: `gh ne se lance pas (${v.error.code ?? v.error.message}).` };
324
+ }
325
+ if (v.status !== 0) {
326
+ return { etat: NON_LUE, raison: `gh run view refuse :\n${`${v.stderr}${v.stdout}`.trim()}` };
327
+ }
328
+ let vue;
329
+ try {
330
+ vue = JSON.parse(v.stdout || '{}');
331
+ } catch {
332
+ return { etat: NON_LUE, raison: `gh run view rend une sortie illisible :\n${v.stdout.trim()}` };
333
+ }
334
+ ecrireLesEtapes(o.avancement, vue);
335
+ if (vue?.status === 'completed') {
336
+ return { etat: 'finie', passage: id, conclusion: vue.conclusion ?? null };
337
+ }
338
+ return { etat: 'en-cours', passage: id };
331
339
  }
332
340
 
333
341
  /**
334
- * The CI of the ticket's commit on main read again, with the tools <o> (`{ racine, principale,
335
- * ticket, bd, gh, dire, avancement }`, as `lireCI`), for a ticket a red CI reopened: as a merge
336
- * queue judges the last attempt of a commit's checks, a run whose failed jobs were run again green
337
- * is green. The commit is the last of main that delivers the ticket (its title line names it,
338
- * `commitsDelivering` of ../un-commit-par-ticket.mjs, the prefix read from bd); green, or no CI
339
- * for the branch pushed to, the ticket closes as an entry closes it (« intégré : <commit> »), its
340
- * run named at the ticket; red or not read, it stays open, the reading at the ticket. No commit of
341
- * main delivering it, or its branch `agent/<ticket>` still ahead of main (a lot not yet on main),
342
- * the ticket is told that the CI is not read again. Exit 0.
342
+ * The working directory of the circuit of <ticket> in the main tree of <o> removed, once the queue
343
+ * is done with the ticket closed: as the workspace of a pipeline, it lives as long as the ticket.
343
344
  */
344
- export function relireCI(o) {
345
- const { racine, principale, ticket } = o;
346
- const git = (...a) => spawnSync('git', ['-C', racine, ...a], { encoding: 'utf8' });
347
- const nonRelue = raison => {
348
- o.bd('comments', 'add', ticket, `## CI non relue\n\n${raison}`);
349
- o.dire(`⚠ CI non relue : ${raison}`);
350
- return 0;
351
- };
352
- const refPrincipale = `refs/heads/${principale}`;
353
- const branche = `agent/${ticket}`;
354
- const enAvance = git('rev-list', '--count', `${refPrincipale}..refs/heads/${branche}`);
355
- if (enAvance.status === 0 && Number(enAvance.stdout.trim()) > 0) {
356
- return nonRelue(
357
- `La branche ${branche} a des commits hors de ${principale} : son lot n'est pas sur ${principale}, la file n'en relit pas la CI.`
345
+ export function retirerLeTravail(o, ticket) {
346
+ rmSync(path.join(o.racine, '.claude', 'worktrees', `${ticket}.travail`), {
347
+ recursive: true,
348
+ force: true,
349
+ });
350
+ }
351
+
352
+ /**
353
+ * The CI of the commit <sha> of the ticket <ticket> concluded with the tools <o>, its verdict
354
+ * <verdict> (VERTE, `rouge`, SANS_CI or NON_LUE), its run <passage> and the reason <raison> of a CI
355
+ * not read, after the queue's entry, or read again (<relue>, on `--reprendre`): what is said to the
356
+ * ticket and what becomes of it. No CI, the ticket is told so in one line; not read, it is told
357
+ * why; red, its comment gives the address of the run and the end of its failed log, and the
358
+ * queue's entry reopens it (read again, it stays open). Green or no CI read again, the ticket
359
+ * closes « intégré : <commit> », its run named. `{ etat, raison }`: `ferme` or `rouvert`, as the
360
+ * circuit reads the issue of the queue (src/temporal/file/deroule.ts); `ferme`, the working
361
+ * directory of its circuit is removed (`retirerLeTravail`).
362
+ */
363
+ export function conclureLaCI(
364
+ o,
365
+ { ticket, sha, branche, verdict, passage = null, raison = null, relue = false }
366
+ ) {
367
+ const court = sha.slice(0, 7);
368
+ const commenter = texte => commenterAu(o, ticket, texte);
369
+ if (verdict === SANS_CI) {
370
+ const texte = `Aucune CI pour origin/${branche} : aucun flux de ${DOSSIER_DES_FLUX} de ${court} ne se lance sur la branche ${branche}, la file n'en attend pas.`;
371
+ commenter(texte);
372
+ o.dire(`✓ ${texte}`);
373
+ } else if (verdict === NON_LUE) {
374
+ commenter(`## CI non lue\n\nLa CI de ${court} n'a pas été lue : ${raison}`);
375
+ o.dire(`⚠ CI de ${court} non lue : ${raison}`);
376
+ } else if (verdict === VERTE) {
377
+ o.dire(`✓ CI de ${court} verte (passage ${passage})`);
378
+ } else {
379
+ const { gh } = o;
380
+ const url =
381
+ gh(['run', 'view', passage, '--json', 'url', '--jq', '.url']).stdout?.trim() || passage;
382
+ const journal = `${gh(['run', 'view', passage, '--log-failed']).stdout ?? ''}`
383
+ .trim()
384
+ .split('\n')
385
+ .slice(-60)
386
+ .join('\n');
387
+ commenter(
388
+ `## CI rouge\n\nLa CI de ${court} sur ${o.principale} est rouge : ${url}\n\nLa fin de gh run view ${passage} --log-failed :\n\n${journal}\n\nLe ticket est rouvert : sa correction entre sous son numéro. Un rejeu vert de la même CI (\`gh run rerun ${passage} --failed\`), puis \`--reprendre\` du circuit, le ferme ; un test connu instable se met en quarantaine dans le test, avec le ticket qui le corrige.`
358
389
  );
390
+ o.dire(`✗ CI de ${court} rouge (passage ${passage}) : ${ticket} rouvert`);
391
+ if (!relue) {
392
+ o.bd('reopen', ticket);
393
+ }
394
+ return { etat: 'rouvert', raison: `La CI de ${court} est rouge : ${url}` };
359
395
  }
360
- const prefixe = o.bd('config', 'get', 'issue_prefix').stdout?.trim() ?? '';
361
- const sha = commitsDelivering(ticket, prefixe, gitLog(racine))
362
- .map(c => git('rev-parse', '--verify', '-q', `${c}^{commit}`).stdout.trim())
363
- .find(c => c && git('merge-base', '--is-ancestor', c, refPrincipale).status === 0);
364
- if (!sha) {
365
- return nonRelue(
366
- `Aucun commit de ${principale} ne livre ${ticket} : la file n'a pas de CI à relire.`
367
- );
396
+ if (!relue) {
397
+ retirerLeTravail(o, ticket);
398
+ return {
399
+ etat: 'ferme',
400
+ raison:
401
+ verdict === NON_LUE ? `${INTEGRE}${court} ; CI non lue : ${raison}` : `${INTEGRE}${court}`,
402
+ };
368
403
  }
369
- const court = sha.slice(0, 7);
370
- const paquet = git('show', `${refPrincipale}:package.json`);
371
- const { commit, faute } = lireCommit(paquet.status === 0 ? JSON.parse(paquet.stdout) : null);
372
- if (faute) {
373
- return nonRelue(`grillhouse.poussee.commit vaut ${faute}, pas un nom de branche.`);
374
- }
375
- const ci = lireCI(o, ticket, sha, commit);
376
- if (ci.verdict === VERTE || ci.verdict === SANS_CI) {
377
- o.bd('close', ticket, '--reason', `${INTEGRE}${court}`);
378
- if (ci.passage) {
379
- o.bd(
380
- 'comments',
381
- 'add',
382
- ticket,
383
- `## CI relue\n\nLa CI de ${court} sur ${principale} est verte au dernier essai du passage ${ci.passage} : le ticket se ferme.`
384
- );
385
- }
386
- o.dire(`✓ ${ticket} fermé : ${court} est sur ${principale}`);
404
+ if (verdict === NON_LUE) {
405
+ return { etat: 'rouvert', raison: `CI non relue : ${raison}` };
387
406
  }
388
- return 0;
407
+ o.bd('close', ticket, '--reason', `${INTEGRE}${court}`);
408
+ if (passage) {
409
+ commenter(
410
+ `## CI relue\n\nLa CI de ${court} sur ${o.principale} est verte au dernier essai du passage ${passage} : le ticket se ferme.`
411
+ );
412
+ }
413
+ o.dire(`✓ ${ticket} fermé : ${court} est sur ${o.principale}`);
414
+ retirerLeTravail(o, ticket);
415
+ return { etat: 'ferme', raison: `${INTEGRE}${court}` };
389
416
  }
390
417
 
391
- function main(argv) {
392
- const relecture = argv.length === 2 && argv[0] === '--ci' && argv[1] ? argv[1] : null;
393
- if (argv.length && !relecture) {
394
- process.stderr.write('usage: file.mjs [--ci <ticket>]\n');
395
- return 2;
396
- }
397
- // The progress directory of the circuit's step (scripts/avancement.mjs), where the queue writes
398
- // the steps of the CI; its own runs of `npm run verifier` play out of it, as measures of their
399
- // own.
400
- const avancement = process.env[AVANCEMENT] || null;
401
- delete process.env[AVANCEMENT];
402
- // The main tree, from git's common directory: launched from a copy, the queue still works on it.
403
- const racine = path.dirname(
404
- spawnSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], {
405
- encoding: 'utf8',
406
- }).stdout.trim()
418
+ /**
419
+ * Where the lot of the ticket <ticket> stands, with the tools <o>: `{ statut, raison, aEntrer,
420
+ * commit, branche, surOrigin, raisonOrigin, faute }`, its status in Beads and its reason of
421
+ * closure, whether its branch `agent/<ticket>` holds a lot ahead of main (which enters by the
422
+ * queue), the commit of main that delivers it (`lotSurMain`, null without one), the branch it was
423
+ * pushed to (`grillhouse.poussee.commit`), whether that commit is on that branch of origin
424
+ * (`surOrigin`: « oui », « non » for a closure that failed before its push, or « inconnu » when
425
+ * origin does not answer, `raisonOrigin` its reason), and the fault of that key (null when it
426
+ * reads).
427
+ */
428
+ export function situerLeLot(o, ticket) {
429
+ const show = o.bd('show', ticket, '--json');
430
+ const t = show.status === 0 ? (JSON.parse(show.stdout)[0] ?? {}) : {};
431
+ const git = (...a) => spawnSync('git', ['-C', o.racine, ...a], { encoding: 'utf8' });
432
+ const paquet = git('show', `refs/heads/${o.principale}:package.json`);
433
+ const { commit: branche, faute } = lireCommit(
434
+ paquet.status === 0 ? JSON.parse(paquet.stdout) : null
407
435
  );
408
- const git = (...args) => spawnSync('git', ['-C', racine, ...args], { encoding: 'utf8' });
409
- // bd runs under the queue's author (BEADS_ACTOR), apart from the supervisor's and the owner's.
410
- const bd = (...a) => {
411
- const r = spawnSync('bd', a, {
412
- cwd: racine,
413
- encoding: 'utf8',
414
- maxBuffer: 256 * 1024 * 1024,
415
- env: { ...process.env, [ACTEUR]: AUTEUR_DE_LA_FILE },
416
- });
417
- if (r.status !== 0) process.stderr.write(`bd ${a[0]} ${a[1] ?? ''} : ${r.stderr}`);
418
- return r;
436
+ const enAvance = git(
437
+ 'rev-list',
438
+ '--count',
439
+ `refs/heads/${o.principale}..refs/heads/agent/${ticket}`
440
+ );
441
+ const commit = lotSurMain(o, ticket);
442
+ const origine =
443
+ commit && !faute ? surOrigin(o, commit, branche) : { surOrigin: 'non', raison: null };
444
+ return {
445
+ statut: t.status ?? null,
446
+ raison: t.close_reason ?? null,
447
+ aEntrer: enAvance.status === 0 && Number(enAvance.stdout.trim()) > 0,
448
+ commit,
449
+ branche: faute ? null : branche,
450
+ surOrigin: origine.surOrigin,
451
+ raisonOrigin: origine.raison,
452
+ faute: faute ?? null,
419
453
  };
420
- const dire = s => process.stdout.write(`${s}\n`);
421
- const principale = git('symbolic-ref', '--short', '-q', 'HEAD').stdout.trim();
422
- if (!principale) {
423
- process.stderr.write("⛔ L'arbre principal n'est pas sur une branche.\n");
424
- return 1;
425
- }
426
- // The tools of the reading of the CI, the queue's and its reading again.
427
- const lecture = { racine, principale, bd, gh: ghDans(racine), dire, avancement };
428
- if (relecture) return relireCI({ ...lecture, ticket: relecture });
429
- const refPrincipale = `refs/heads/${principale}`;
430
- const copie = path.join(racine, '.claude', 'worktrees', 'file');
431
- const verrou = path.join(dossierCommun(racine), 'file-integration.lock');
454
+ }
432
455
 
433
- const commenter = (ticket, texte) => bd('comments', 'add', ticket, texte);
434
- // The branch leaves the queue and stays in place; its ticket reopens.
435
- const sortir = (entree, titre, detail) => {
436
- const texte = `## Sortie de la file\n\nLa branche ${entree.branche} ne peut pas entrer sur ${principale} : ${titre}\n${detail}\n\nLa branche reste en place ; la relance du ticket remet son lot en travail local sur ${principale}.`;
437
- bd('update', entree.ticket, '--status', 'open', '--remove-label', 'en-file');
438
- bd('comments', 'add', entree.ticket, texte);
439
- retirerEntree(entree);
440
- dire(`✗ ${entree.branche} sort de la file : ${titre}`);
441
- };
442
- // The branch has nothing ahead of main: it leaves the queue, its ticket stays as it is and loses
443
- // `en-file`.
444
- const ecarter = entree => {
445
- const texte = `## Sortie de la file\n\nLa branche ${entree.branche} n'a rien en avance sur ${principale} : elle n'entre pas, et le ticket reste ouvert.`;
446
- bd('update', entree.ticket, '--remove-label', 'en-file');
447
- bd('comments', 'add', entree.ticket, texte);
448
- retirerEntree(entree);
449
- dire(`⚠ ${entree.branche} n'a rien en avance sur ${principale} : elle sort de la file`);
450
- };
451
- // The branch stays in the queue, the reason written to its ticket.
452
- const garder = (entree, raison) => {
453
- commenter(
454
- entree.ticket,
455
- `## La file garde la branche\n\nLa branche ${entree.branche} reste en file : ${raison}`
456
- );
457
- dire(`⚠ ${entree.branche} reste en file : ${raison}`);
456
+ // Whether the commit <commit> is on the branch <branche> of origin, with the tools <o>: « oui »,
457
+ // « non », or « inconnu » when origin does not answer (`git ls-remote`, without a prompt, as the
458
+ // push) or its tip is not known here (`merge-base --is-ancestor` neither 0 nor 1), its reason
459
+ // named: a place that does not read is never « not pushed ».
460
+ function surOrigin(o, commit, branche) {
461
+ const ls = spawnSync(
462
+ 'git',
463
+ ['-C', o.racine, 'ls-remote', '--heads', 'origin', `refs/heads/${branche}`],
464
+ {
465
+ encoding: 'utf8',
466
+ env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
467
+ }
468
+ );
469
+ if (ls.status !== 0) {
470
+ const raison =
471
+ `${ls.stderr ?? ''}`.trim().split('\n')[0] || ls.error?.message || `code ${ls.status}`;
472
+ return { surOrigin: 'inconnu', raison: `git ls-remote origin ${branche} : ${raison}` };
473
+ }
474
+ const pointe = ls.stdout.split(/\s/)[0] ?? '';
475
+ if (!pointe) {
476
+ return { surOrigin: 'non', raison: null };
477
+ }
478
+ // `--is-ancestor` answers 0 (an ancestor) or 1 (not one); any other code (the tip of origin
479
+ // unknown here, 128) does not say: « inconnu », its reason named.
480
+ const git = (...a) => spawnSync('git', ['-C', o.racine, ...a], { encoding: 'utf8' });
481
+ const ancetre = git('merge-base', '--is-ancestor', commit, pointe);
482
+ if (ancetre.status === 0) {
483
+ return { surOrigin: 'oui', raison: null };
484
+ }
485
+ if (ancetre.status === 1) {
486
+ return { surOrigin: 'non', raison: null };
487
+ }
488
+ const raison =
489
+ `${ancetre.stderr ?? ''}`.trim().split('\n')[0] ||
490
+ ancetre.error?.message ||
491
+ `code ${ancetre.status}`;
492
+ return {
493
+ surOrigin: 'inconnu',
494
+ raison: `git merge-base --is-ancestor ${commit.slice(0, 7)} origin/${branche} : ${raison}`,
458
495
  };
496
+ }
459
497
 
460
- // The branch replaced on main, replayed: { nouveau } (the commit to move main onto), or
461
- // { sortie: [titre, détail] } (it leaves the queue), or { garde } (it stays, the reason).
462
- const rejouer = (tip, tete) => {
463
- if (existsSync(copie))
464
- spawnSync('git', ['-C', copie, 'rebase', '--abort'], { encoding: 'utf8' });
465
- // The keys of the project, before any work: its generated files and its tools.
466
- let engendres;
467
- let env;
468
- try {
469
- engendres = engendresDe(racine);
470
- env = avecLesOutils(outilsDe(racine), process.env);
471
- } catch (e) {
472
- return { garde: `une clé grillhouse du package.json est refusée :\n${e.message}` };
498
+ // The commit of main that delivers the ticket <ticket> (its title line names it,
499
+ // `commitsDelivering` of ../un-commit-par-ticket.mjs, the prefix read from bd), the last one, in
500
+ // full; null without one.
501
+ function lotSurMain(o, ticket) {
502
+ const git = (...a) => spawnSync('git', ['-C', o.racine, ...a], { encoding: 'utf8' });
503
+ const prefixe = o.bd('config', 'get', 'issue_prefix').stdout?.trim() ?? '';
504
+ return (
505
+ commitsDelivering(ticket, prefixe, gitLog(o.racine))
506
+ .map(c => git('rev-parse', '--verify', '-q', `${c}^{commit}`).stdout.trim())
507
+ .find(
508
+ c => c && git('merge-base', '--is-ancestor', c, `refs/heads/${o.principale}`).status === 0
509
+ ) ?? null
510
+ );
511
+ }
512
+
513
+ // The branch of <entree> replaced on the main <tete> in the queue's own copy, replayed, with the
514
+ // tools <o>: { nouveau } (the commit to move main onto), or { sortie: [titre, détail] } (it leaves
515
+ // the queue), or { garde } (it stays, the reason).
516
+ function rejouer(o, tip, tete, ticketRejoue = null) {
517
+ const { racine, dire } = o;
518
+ const copie = path.join(racine, '.claude', 'worktrees', 'file');
519
+ if (existsSync(copie)) {
520
+ spawnSync('git', ['-C', copie, 'rebase', '--abort'], { encoding: 'utf8' });
521
+ }
522
+ // The keys of the project, before any work: its generated files and its tools.
523
+ let engendres;
524
+ let env;
525
+ try {
526
+ engendres = engendresDe(racine);
527
+ env = avecLesDonnees(donneesDe(racine), avecLesOutils(outilsDe(racine), process.env));
528
+ } catch (e) {
529
+ return { garde: `une clé grillhouse du package.json est refusée :\n${e.message}` };
530
+ }
531
+ const ouverte = ouvrirCopie({ racine, copie, ref: tete, dire });
532
+ if (ouverte.refus) {
533
+ return { garde: ouverte.refus };
534
+ }
535
+ const { dansCopie, monter, installer, tester } = ouverte;
536
+ if (dansCopie('checkout', '-q', '--detach', tip).status !== 0) {
537
+ return { garde: `la copie ne prend pas ${tip.slice(0, 7)}` };
538
+ }
539
+ // A conflict on generated files the project declares only is no conflict: main's version is
540
+ // taken, and their command writes them again once the branch is replaced (below).
541
+ let rebase = dansCopie('rebase', tete);
542
+ let tours = Number(dansCopie('rev-list', '--count', `${tete}..${tip}`).stdout.trim()) || 1;
543
+ while (rebase.status !== 0) {
544
+ const conflits = dansCopie('diff', '--name-only', '--diff-filter=U')
545
+ .stdout.split('\n')
546
+ .filter(Boolean);
547
+ const engendresSeuls =
548
+ tours-- > 0 &&
549
+ conflits.length > 0 &&
550
+ conflits.every(f => engendres.some(e => couvertPar(e.entiers, f))) &&
551
+ dansCopie('checkout', '--ours', '--', ...conflits).status === 0 &&
552
+ dansCopie('add', '--', ...conflits).status === 0;
553
+ if (!engendresSeuls) {
554
+ dansCopie('rebase', '--abort');
555
+ return {
556
+ sortie: [
557
+ 'elle ne se replace pas sur main.',
558
+ conflits.length
559
+ ? `Fichiers en conflit :\n${conflits.map(f => ` ${f}`).join('\n')}`
560
+ : `Sortie de git :\n${rebase.stdout}${rebase.stderr}`,
561
+ ],
562
+ };
563
+ }
564
+ rebase = dansCopie('-c', 'core.editor=true', 'rebase', '--continue');
565
+ }
566
+ const installation = installer();
567
+ if (installation) {
568
+ return { sortie: [installation, "Le verrou de la branche replacée ne s'installe pas."] };
569
+ }
570
+ const touches = touchesPar(
571
+ engendres,
572
+ dansCopie('diff', '--name-only', '--no-renames', '-z', tete, 'HEAD')
573
+ .stdout.split('\0')
574
+ .filter(Boolean)
575
+ );
576
+ if (touches.length) {
577
+ const refus = regenerer({
578
+ refs: touches.map(e => ({ ...e, cadre: false })),
579
+ dansCopie,
580
+ lancer: commande =>
581
+ spawnSync('bash', monter('sh', '-c', commande), {
582
+ cwd: copie,
583
+ encoding: 'utf8',
584
+ maxBuffer: 256 * 1024 * 1024,
585
+ env,
586
+ }),
587
+ });
588
+ if (refus) {
589
+ return { sortie: ['ses fichiers engendrés ne se régénèrent pas sur main.', refus] };
473
590
  }
474
- const ouverte = ouvrirCopie({ racine, copie, ref: tete, dire });
475
- if (ouverte.refus) return { garde: ouverte.refus };
476
- const { dansCopie, monter, installer, tester } = ouverte;
477
- if (dansCopie('checkout', '-q', '--detach', tip).status !== 0)
478
- return { garde: `la copie ne prend pas ${tip.slice(0, 7)}` };
479
- // A conflict on generated files the project declares only is no conflict: main's version is
480
- // taken, and their command writes them again once the branch is replaced (below).
481
- let rebase = dansCopie('rebase', tete);
482
- let tours = Number(dansCopie('rev-list', '--count', `${tete}..${tip}`).stdout.trim()) || 1;
483
- while (rebase.status !== 0) {
484
- const conflits = dansCopie('diff', '--name-only', '--diff-filter=U')
485
- .stdout.split('\n')
486
- .filter(Boolean);
487
- const engendresSeuls =
488
- tours-- > 0 &&
489
- conflits.length > 0 &&
490
- conflits.every(f => engendres.some(e => couvertPar(e.entiers, f))) &&
491
- dansCopie('checkout', '--ours', '--', ...conflits).status === 0 &&
492
- dansCopie('add', '--', ...conflits).status === 0;
493
- if (!engendresSeuls) {
494
- dansCopie('rebase', '--abort');
591
+ if (dansCopie('diff', '--cached', '--quiet').status !== 0) {
592
+ const corrige = dansCopie('commit', '-q', '--amend', '--no-edit', '--no-verify');
593
+ if (corrige.status !== 0) {
495
594
  return {
496
- sortie: [
497
- 'elle ne se replace pas sur main.',
498
- conflits.length
499
- ? `Fichiers en conflit :\n${conflits.map(f => ` ${f}`).join('\n')}`
500
- : `Sortie de git :\n${rebase.stdout}${rebase.stderr}`,
501
- ],
595
+ garde: `ses fichiers régénérés n'entrent pas dans son commit :\n${corrige.stderr}`,
502
596
  };
503
597
  }
504
- rebase = dansCopie('-c', 'core.editor=true', 'rebase', '--continue');
505
598
  }
506
- const installation = installer();
507
- if (installation) {
508
- return { sortie: [installation, "Le verrou de la branche replacée ne s'installe pas."] };
599
+ dire(`✓ fichiers engendrés régénérés sur main : ${touches.map(e => e.nom).join(', ')}`);
600
+ }
601
+ dire('— npm run verifier (construction, gardes, tests)');
602
+ const t = tester({ sorte: 'File', ticket: ticketRejoue });
603
+ if (t.status === A_REPASSER) {
604
+ return {
605
+ garde: `son \`npm run verifier\` est à repasser (code ${A_REPASSER}) une fois replacée : l'attente de la machine a atteint sa borne. Ni vert ni rouge ; la prochaine file la rejoue.`,
606
+ };
607
+ }
608
+ if (t.status !== 0) {
609
+ const fin = `${t.stdout}${t.stderr}`.trim().split('\n').slice(-40).join('\n');
610
+ return { sortie: ['ses tests sont rouges une fois la branche replacée.', fin] };
611
+ }
612
+ return { nouveau: dansCopie('rev-parse', 'HEAD').stdout.trim() };
613
+ }
614
+
615
+ /**
616
+ * Main moved onto the branch of <entree> (`{ ticket, branche }`) with the tools <o>, against the
617
+ * main of the moment, without a word to the ticket: `{ entre: { commit } }`, main at <commit>;
618
+ * `{ sortie: [titre, détail] }` (it leaves the queue: gone, not replaced, red once replaced);
619
+ * `{ garde }` (it stays in the queue, the reason); `{ ecartee: true }` (nothing ahead of main). A
620
+ * lot already on main (the branch points at the commit of main that delivers its ticket, or each
621
+ * of its commits has its equivalent on main, or the branch is gone), as an attempt played again
622
+ * after its worker died finds it, is entered: main does not move again.
623
+ */
624
+ export function avancerMain(o, entree) {
625
+ const git = (...args) => spawnSync('git', ['-C', o.racine, ...args], { encoding: 'utf8' });
626
+ const refPrincipale = `refs/heads/${o.principale}`;
627
+ const tip = git('rev-parse', '--verify', '-q', `refs/heads/${entree.branche}`).stdout.trim();
628
+ const livre = lotSurMain(o, entree.ticket);
629
+ // A lot on main whose branch is gone (a closure that failed after its deletion) is entered.
630
+ if (!tip) {
631
+ return livre ? { entre: { commit: livre } } : { sortie: ["la branche n'existe plus.", ''] };
632
+ }
633
+ const enAvance = Number(git('rev-list', '--count', `${refPrincipale}..${tip}`).stdout.trim());
634
+ // The lot is on main when the branch points at the commit of main that delivers the ticket
635
+ // (main moved onto it by fast-forward), or when each commit of the branch has its equivalent on
636
+ // main (the same patch, git cherry), the replay a rebase wrote: a lot of before of a ticket
637
+ // reopened is neither, its branch at main's or ahead of it by new commits.
638
+ if (livre) {
639
+ const cerise = git('cherry', refPrincipale, tip).stdout.split('\n').filter(Boolean);
640
+ const rejeu = enAvance > 0 && cerise.length > 0 && cerise.every(l => l.startsWith('- '));
641
+ if (tip === livre || rejeu) {
642
+ return { entre: { commit: livre } };
509
643
  }
510
- const touches = touchesPar(
511
- engendres,
512
- dansCopie('diff', '--name-only', '--no-renames', '-z', tete, 'HEAD')
513
- .stdout.split('\0')
514
- .filter(Boolean)
515
- );
516
- if (touches.length) {
517
- const refus = regenerer({
518
- refs: touches.map(e => ({ ...e, cadre: false })),
519
- dansCopie,
520
- lancer: commande =>
521
- spawnSync('bash', monter('sh', '-c', commande), {
522
- cwd: copie,
523
- encoding: 'utf8',
524
- maxBuffer: 256 * 1024 * 1024,
525
- env,
526
- }),
527
- });
528
- if (refus)
529
- return { sortie: ['ses fichiers engendrés ne se régénèrent pas sur main.', refus] };
530
- if (dansCopie('diff', '--cached', '--quiet').status !== 0) {
531
- const corrige = dansCopie('commit', '-q', '--amend', '--no-edit', '--no-verify');
532
- if (corrige.status !== 0) {
533
- return {
534
- garde: `ses fichiers régénérés n'entrent pas dans son commit :\n${corrige.stderr}`,
535
- };
536
- }
644
+ }
645
+ if (enAvance === 0) {
646
+ return { ecartee: true };
647
+ }
648
+ for (let essai = 0; essai < ESSAIS_PAR_BRANCHE; essai++) {
649
+ const tete = git('rev-parse', refPrincipale).stdout.trim();
650
+ let nouveau = tip;
651
+ if (git('merge-base', '--is-ancestor', tete, tip).status !== 0) {
652
+ const r = rejouer(o, tip, tete, entree.ticket);
653
+ if (!r.nouveau) {
654
+ return r;
537
655
  }
538
- dire(`✓ fichiers engendrés régénérés sur main : ${touches.map(e => e.nom).join(', ')}`);
539
- }
540
- dire('— npm run verifier (construction, gardes, tests)');
541
- const t = tester();
542
- if (t.status === A_REPASSER) {
543
- return {
544
- garde: `son \`npm run verifier\` est à repasser (code ${A_REPASSER}) une fois replacée : l'attente de la machine a atteint sa borne. Ni vert ni rouge ; la prochaine file la rejoue.`,
545
- };
656
+ nouveau = r.nouveau;
546
657
  }
547
- if (t.status !== 0) {
548
- const fin = `${t.stdout}${t.stderr}`.trim().split('\n').slice(-40).join('\n');
549
- return { sortie: ['ses tests sont rouges une fois la branche replacée.', fin] };
658
+ if (nouveau !== tete) {
659
+ const avance = git('merge', '-q', '--ff-only', nouveau);
660
+ if (avance.status !== 0) {
661
+ if (git('rev-parse', refPrincipale).stdout.trim() !== tete) {
662
+ continue;
663
+ }
664
+ return {
665
+ garde:
666
+ `${o.principale} n'avance pas sur ${nouveau.slice(0, 7)} :\n${avance.stdout}${avance.stderr}`.trim(),
667
+ };
668
+ }
550
669
  }
551
- return { nouveau: dansCopie('rev-parse', 'HEAD').stdout.trim() };
552
- };
670
+ return { entre: { commit: nouveau } };
671
+ }
672
+ return { garde: `${o.principale} bouge sans cesse : cinq essais n'ont pas suffi.` };
673
+ }
553
674
 
554
- // Main is at <nouveau>: the ticket closes, the branch is deleted, main is pushed.
555
- const entrer = (entree, nouveau) => {
556
- const court = nouveau.slice(0, 7);
557
- bd('update', entree.ticket, '--remove-label', 'en-file');
558
- bd('close', entree.ticket, '--reason', `${INTEGRE}${court}`);
559
- rmSync(path.join(racine, '.claude', 'worktrees', `${entree.ticket}.travail`), {
560
- recursive: true,
561
- force: true,
562
- });
563
- retirerEntree(entree);
564
- dire(`✓ ${entree.branche} entre sur ${principale} : ${court}`);
675
+ /**
676
+ * The ticket of <entree> (`{ ticket, branche, commit }`) entered on main at <commit>, with the
677
+ * tools <o>: it closes « intégré : <commit> » and loses `en-file` (a ticket already closed is left
678
+ * as it is), <apresLaFermeture> runs (the queue on its file removes its entry there), the branch is
679
+ * deleted, then main is pushed to origin on the branch `grillhouse.poussee.commit` of main's
680
+ * package.json; a push not made ends the queue's work on the ticket, and removes the working
681
+ * directory of its circuit (`retirerLeTravail`), which the conclusion of its CI removes otherwise. Each of its gestures replays without
682
+ * harm (a ticket closed is left closed, a branch gone stays gone, a commit pushed is pushed again
683
+ * as it is), and never reopens the ticket; its comments are effects (`commenterAu`), which the
684
+ * workflow of the queue writes once each. `{ poussee, raison }`: the branch pushed to, or null and
685
+ * why, in one line (`enUneLigne`), its comment at the ticket whole.
686
+ */
687
+ export function fermerLEntree(o, entree, apresLaFermeture = () => {}) {
688
+ const { racine } = o;
689
+ const git = (...args) => spawnSync('git', ['-C', racine, ...args], { encoding: 'utf8' });
690
+ const court = entree.commit.slice(0, 7);
691
+ const commenter = texte => commenterAu(o, entree.ticket, texte);
692
+ const show = o.bd('show', entree.ticket, '--json');
693
+ const statut = show.status === 0 ? (JSON.parse(show.stdout)[0]?.status ?? null) : null;
694
+ if (statut !== 'closed') {
695
+ o.bd('update', entree.ticket, '--remove-label', 'en-file');
696
+ o.bd('close', entree.ticket, '--reason', `${INTEGRE}${court}`);
697
+ }
698
+ apresLaFermeture();
699
+ o.dire(`✓ ${entree.branche} entre sur ${o.principale} : ${court}`);
700
+ if (git('rev-parse', '--verify', '-q', `refs/heads/${entree.branche}`).status === 0) {
565
701
  const efface = git('branch', '-D', entree.branche);
566
702
  if (efface.status !== 0) {
567
703
  commenter(
568
- entree.ticket,
569
- `La branche ${entree.branche} reste en place après son entrée sur ${principale} (${efface.stderr.trim()}) : sa copie est encore en place. Le ticket est fermé.`
570
- );
571
- dire(`⚠ ${entree.branche} n'est pas effacée`);
572
- }
573
- const paquet = git('show', `${refPrincipale}:package.json`);
574
- const { commit, faute } = lireCommit(paquet.status === 0 ? JSON.parse(paquet.stdout) : null);
575
- if (faute) {
576
- commenter(
577
- entree.ticket,
578
- `Poussée non faite : grillhouse.poussee.commit vaut ${faute}, pas un nom de branche.`
579
- );
580
- return;
581
- }
582
- const pousse = spawnSync(
583
- 'git',
584
- ['-C', racine, 'push', 'origin', `${nouveau}:refs/heads/${commit}`],
585
- { encoding: 'utf8', env: { ...process.env, GIT_TERMINAL_PROMPT: '0' } }
586
- );
587
- if (pousse.status !== 0) {
588
- commenter(
589
- entree.ticket,
590
- `La poussée de ${court} vers origin/${commit} (grillhouse.poussee.commit) est refusée :\n${pousse.stderr.trim()}`
704
+ `La branche ${entree.branche} reste en place après son entrée sur ${o.principale} (${efface.stderr.trim()}) : sa copie est encore en place. Le ticket est fermé.`
591
705
  );
592
- dire(`⚠ poussée de ${court} refusée`);
593
- } else {
594
- dire(`✓ poussée : ${court} est sur origin/${commit}`);
595
- const ci = lireCI(lecture, entree.ticket, nouveau, commit);
596
- if (ci.verdict === ROUGE) bd('reopen', entree.ticket);
597
- }
598
- };
599
-
600
- // One branch of the queue, against the main of the moment.
601
- const traiter = entree => {
602
- const tip = git('rev-parse', '--verify', '-q', `refs/heads/${entree.branche}`).stdout.trim();
603
- if (!tip) return sortir(entree, "la branche n'existe plus.", '');
604
- if (Number(git('rev-list', '--count', `${refPrincipale}..${tip}`).stdout.trim()) === 0)
605
- return ecarter(entree);
606
- for (let essai = 0; essai < ESSAIS_PAR_BRANCHE; essai++) {
607
- const tete = git('rev-parse', refPrincipale).stdout.trim();
608
- let nouveau = tip;
609
- if (git('merge-base', '--is-ancestor', tete, tip).status !== 0) {
610
- const r = rejouer(tip, tete);
611
- if (r.sortie) return sortir(entree, ...r.sortie);
612
- if (r.garde) return garder(entree, r.garde);
613
- nouveau = r.nouveau;
614
- }
615
- if (nouveau !== tete) {
616
- const avance = git('merge', '-q', '--ff-only', nouveau);
617
- if (avance.status !== 0) {
618
- if (git('rev-parse', refPrincipale).stdout.trim() !== tete) continue;
619
- return garder(
620
- entree,
621
- `${principale} n'avance pas sur ${nouveau.slice(0, 7)} :\n${avance.stdout}${avance.stderr}`.trim()
622
- );
623
- }
624
- }
625
- return entrer(entree, nouveau);
626
- }
627
- return garder(entree, `${principale} bouge sans cesse : cinq essais n'ont pas suffi.`);
628
- };
629
-
630
- const vues = new Set();
631
- for (;;) {
632
- if (!prendreVerrou(verrou, { attendre: false })) return 0;
633
- try {
634
- for (;;) {
635
- const entree = lireEntrees(racine).find(e => !vues.has(e.fichier));
636
- if (!entree) break;
637
- vues.add(entree.fichier);
638
- traiter(entree);
639
- }
640
- } finally {
641
- lacherVerrou(verrou);
706
+ o.dire(`⚠ ${entree.branche} n'est pas effacée`);
642
707
  }
643
- // An entry written while the lock was let go has no queue running to take it.
644
- if (!lireEntrees(racine).some(e => !vues.has(e.fichier))) return 0;
645
708
  }
709
+ const paquet = git('show', `refs/heads/${o.principale}:package.json`);
710
+ const { commit, faute } = lireCommit(paquet.status === 0 ? JSON.parse(paquet.stdout) : null);
711
+ if (faute) {
712
+ const raison = `Poussée non faite : grillhouse.poussee.commit vaut ${faute}, pas un nom de branche.`;
713
+ commenter(raison);
714
+ retirerLeTravail(o, entree.ticket);
715
+ return { poussee: null, raison: enUneLigne(raison) };
716
+ }
717
+ const pousse = spawnSync(
718
+ 'git',
719
+ ['-C', racine, 'push', 'origin', `${entree.commit}:refs/heads/${commit}`],
720
+ { encoding: 'utf8', env: { ...process.env, GIT_TERMINAL_PROMPT: '0' } }
721
+ );
722
+ if (pousse.status !== 0) {
723
+ const raison = `La poussée de ${court} vers origin/${commit} (grillhouse.poussee.commit) est refusée :\n${pousse.stderr.trim()}`;
724
+ commenter(raison);
725
+ o.dire(`⚠ poussée de ${court} refusée`);
726
+ retirerLeTravail(o, entree.ticket);
727
+ return { poussee: null, raison: enUneLigne(raison) };
728
+ }
729
+ o.dire(`✓ poussée : ${court} est sur origin/${commit}`);
730
+ return { poussee: commit, raison: null };
646
731
  }
647
732
 
648
- if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
649
- process.exitCode = main(process.argv.slice(2));
733
+ /**
734
+ * What the outcome <r> of `avancerMain` for <entree> says to its ticket, with the tools <o>: a
735
+ * branch out of the queue reopens it, its files or its red named; a branch set aside loses
736
+ * `en-file`, the ticket left open; a branch kept, the reason. `{ etat, raison }`: `rouvert` or
737
+ * `en-file`, as the circuit reads the queue.
738
+ */
739
+ export function direLIssue(o, entree, r) {
740
+ const commenter = texte => commenterAu(o, entree.ticket, texte);
741
+ if (r.sortie) {
742
+ const [titre, detail] = r.sortie;
743
+ const texte = `## Sortie de la file\n\nLa branche ${entree.branche} ne peut pas entrer sur ${o.principale} : ${titre}\n${detail}\n\nLa branche reste en place ; la relance du ticket remet son lot en travail local sur ${o.principale}.`;
744
+ o.bd('update', entree.ticket, '--status', 'open', '--remove-label', 'en-file');
745
+ commenter(texte);
746
+ o.dire(`✗ ${entree.branche} sort de la file : ${titre}`);
747
+ return { etat: 'rouvert', raison: texte };
748
+ }
749
+ if (r.ecartee) {
750
+ const texte = `## Sortie de la file\n\nLa branche ${entree.branche} n'a rien en avance sur ${o.principale} : elle n'entre pas, et le ticket reste ouvert.`;
751
+ o.bd('update', entree.ticket, '--remove-label', 'en-file');
752
+ commenter(texte);
753
+ o.dire(`⚠ ${entree.branche} n'a rien en avance sur ${o.principale} : elle sort de la file`);
754
+ return { etat: 'rouvert', raison: texte };
755
+ }
756
+ const texte = `## La file garde la branche\n\nLa branche ${entree.branche} reste en file : ${r.garde}`;
757
+ commenter(texte);
758
+ o.dire(`⚠ ${entree.branche} reste en file : ${r.garde}`);
759
+ return { etat: 'en-file', raison: texte };
650
760
  }