@roomi-fields/grillhouse 0.28.3 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +739 -0
  3. package/bin/grillhouse.mjs +128 -26
  4. package/cadre/templates/projet/.github/workflows/ci.yml +2 -13
  5. package/cadre/templates/projet/CLAUDE.md +5 -1
  6. package/cadre/templates/projet/README.md +11 -11
  7. package/cadre/templates/projet/_gitignore +2 -5
  8. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  9. package/cadre/templates/projet/package.json +2 -2
  10. package/charte.md +37 -4
  11. package/dist/temporal/acte.d.ts +24 -0
  12. package/dist/temporal/acte.js +139 -0
  13. package/dist/temporal/acte.js.map +1 -0
  14. package/dist/temporal/attributs.d.ts +6 -0
  15. package/dist/temporal/attributs.js +15 -0
  16. package/dist/temporal/attributs.js.map +1 -0
  17. package/dist/temporal/circuit/activites.d.ts +13 -0
  18. package/dist/temporal/circuit/activites.js +33 -0
  19. package/dist/temporal/circuit/activites.js.map +1 -0
  20. package/dist/temporal/circuit/client.d.ts +72 -0
  21. package/dist/temporal/circuit/client.js +247 -0
  22. package/dist/temporal/circuit/client.js.map +1 -0
  23. package/dist/temporal/circuit/commande.d.ts +2 -0
  24. package/dist/temporal/circuit/commande.js +238 -0
  25. package/dist/temporal/circuit/commande.js.map +1 -0
  26. package/dist/temporal/circuit/contrat.d.ts +305 -0
  27. package/dist/temporal/circuit/contrat.js +24 -0
  28. package/dist/temporal/circuit/contrat.js.map +1 -0
  29. package/dist/temporal/circuit/deroule.d.ts +3 -0
  30. package/dist/temporal/circuit/deroule.js +540 -0
  31. package/dist/temporal/circuit/deroule.js.map +1 -0
  32. package/dist/temporal/client.d.ts +47 -0
  33. package/dist/temporal/client.js +69 -0
  34. package/dist/temporal/client.js.map +1 -0
  35. package/dist/temporal/commande.d.ts +2 -0
  36. package/dist/temporal/commande.js +95 -0
  37. package/dist/temporal/commande.js.map +1 -0
  38. package/dist/temporal/deroules.d.ts +5 -0
  39. package/dist/temporal/deroules.js +10 -0
  40. package/dist/temporal/deroules.js.map +1 -0
  41. package/dist/temporal/etat.d.ts +33 -0
  42. package/dist/temporal/etat.js +59 -0
  43. package/dist/temporal/etat.js.map +1 -0
  44. package/dist/temporal/file/activites.d.ts +10 -0
  45. package/dist/temporal/file/activites.js +25 -0
  46. package/dist/temporal/file/activites.js.map +1 -0
  47. package/dist/temporal/file/client.d.ts +4 -0
  48. package/dist/temporal/file/client.js +6 -0
  49. package/dist/temporal/file/client.js.map +1 -0
  50. package/dist/temporal/file/contrat.d.ts +158 -0
  51. package/dist/temporal/file/contrat.js +14 -0
  52. package/dist/temporal/file/contrat.js.map +1 -0
  53. package/dist/temporal/file/deroule.d.ts +15 -0
  54. package/dist/temporal/file/deroule.js +235 -0
  55. package/dist/temporal/file/deroule.js.map +1 -0
  56. package/dist/temporal/installation.d.ts +124 -0
  57. package/dist/temporal/installation.js +408 -0
  58. package/dist/temporal/installation.js.map +1 -0
  59. package/dist/temporal/places/activites.d.ts +8 -0
  60. package/dist/temporal/places/activites.js +13 -0
  61. package/dist/temporal/places/activites.js.map +1 -0
  62. package/dist/temporal/places/client.d.ts +28 -0
  63. package/dist/temporal/places/client.js +64 -0
  64. package/dist/temporal/places/client.js.map +1 -0
  65. package/dist/temporal/places/contrat.d.ts +106 -0
  66. package/dist/temporal/places/contrat.js +21 -0
  67. package/dist/temporal/places/contrat.js.map +1 -0
  68. package/dist/temporal/places/deroule.d.ts +3 -0
  69. package/dist/temporal/places/deroule.js +198 -0
  70. package/dist/temporal/places/deroule.js.map +1 -0
  71. package/dist/temporal/sonde/activites.d.ts +6 -0
  72. package/dist/temporal/sonde/activites.js +52 -0
  73. package/dist/temporal/sonde/activites.js.map +1 -0
  74. package/dist/temporal/sonde/contrat.d.ts +35 -0
  75. package/dist/temporal/sonde/contrat.js +10 -0
  76. package/dist/temporal/sonde/contrat.js.map +1 -0
  77. package/dist/temporal/sonde/deroule.d.ts +3 -0
  78. package/dist/temporal/sonde/deroule.js +39 -0
  79. package/dist/temporal/sonde/deroule.js.map +1 -0
  80. package/dist/temporal/tickets/activites.d.ts +7 -0
  81. package/dist/temporal/tickets/activites.js +81 -0
  82. package/dist/temporal/tickets/activites.js.map +1 -0
  83. package/dist/temporal/tickets/client.d.ts +10 -0
  84. package/dist/temporal/tickets/client.js +31 -0
  85. package/dist/temporal/tickets/client.js.map +1 -0
  86. package/dist/temporal/tickets/contrat.d.ts +56 -0
  87. package/dist/temporal/tickets/contrat.js +13 -0
  88. package/dist/temporal/tickets/contrat.js.map +1 -0
  89. package/dist/temporal/tickets/deroule.d.ts +3 -0
  90. package/dist/temporal/tickets/deroule.js +94 -0
  91. package/dist/temporal/tickets/deroule.js.map +1 -0
  92. package/dist/temporal/travailleur.d.ts +2 -0
  93. package/dist/temporal/travailleur.js +69 -0
  94. package/dist/temporal/travailleur.js.map +1 -0
  95. package/docs/ARCHITECTURE.md +813 -53
  96. package/docs/CADRE.md +17 -0
  97. package/docs/INTERFACE.md +161 -30
  98. package/hooks/crochet.mjs +19 -2
  99. package/hooks/hooks.json +11 -0
  100. package/package.json +16 -4
  101. package/scripts/activites.mjs +2182 -0
  102. package/scripts/aiguillage.d.mts +37 -0
  103. package/scripts/aiguillage.mjs +328 -0
  104. package/scripts/avancement.mjs +159 -64
  105. package/scripts/bilan.mjs +37 -19
  106. package/scripts/cadre.mjs +11 -2
  107. package/scripts/circuit.mjs +888 -3654
  108. package/scripts/circuits-cles.d.mts +4 -0
  109. package/scripts/circuits-cles.mjs +21 -0
  110. package/scripts/circuits-du-serveur.mjs +105 -0
  111. package/scripts/codes-de-sortie.mjs +9 -0
  112. package/scripts/commandes-composees.mjs +45 -41
  113. package/scripts/commandes-du-path.d.mts +7 -0
  114. package/scripts/commandes-du-path.mjs +25 -0
  115. package/scripts/composition-des-langages.mjs +30 -11
  116. package/scripts/conformite.mjs +19 -10
  117. package/scripts/copies-finies.mjs +188 -42
  118. package/scripts/depart-du-ticket.d.mts +53 -0
  119. package/scripts/depart-du-ticket.mjs +124 -0
  120. package/scripts/dependances-internes.mjs +115 -0
  121. package/scripts/dernier-vert.mjs +7 -15
  122. package/scripts/donnees-cles.mjs +228 -0
  123. package/scripts/droits.mjs +11 -1
  124. package/scripts/effets.mjs +352 -0
  125. package/scripts/enveloppe/enveloppe.mjs +119 -8
  126. package/scripts/enveloppe/lancer.sh +27 -32
  127. package/scripts/enveloppe/paquets-du-plan.mjs +2 -2
  128. package/scripts/enveloppe/travail-de-la-copie.mjs +99 -12
  129. package/scripts/etapes.mjs +6 -3
  130. package/scripts/faits-du-circuit.mjs +493 -0
  131. package/scripts/file-des-tickets.d.mts +21 -0
  132. package/scripts/file-des-tickets.mjs +58 -0
  133. package/scripts/flux-des-paquets.mjs +187 -0
  134. package/scripts/fusion-du-changelog.mjs +0 -1
  135. package/scripts/gardes-du-cadre.mjs +12 -2
  136. package/scripts/grillhouse-maj.mjs +16 -7
  137. package/scripts/integration/file.mjs +477 -422
  138. package/scripts/integration/integrer.mjs +20 -22
  139. package/scripts/integration/rejeu.mjs +19 -4
  140. package/scripts/jointure.d.ts +168 -28
  141. package/scripts/langages/cargo/commandes.mjs +426 -119
  142. package/scripts/langages/cargo/composants.mjs +187 -3
  143. package/scripts/langages/cargo/exemples.mjs +75 -17
  144. package/scripts/langages/cargo/index.mjs +32 -13
  145. package/scripts/langages/cargo/migrations/0.28.4-tailles-des-tests.mjs +35 -0
  146. package/scripts/langages/cargo/sccache.mjs +62 -16
  147. package/scripts/langages/cargo/squelette.mjs +72 -3
  148. package/scripts/langages/cargo/tailles-des-tests.mjs +195 -0
  149. package/scripts/langages/cargo/tests-de-head.mjs +159 -0
  150. package/scripts/langages/python/commandes.mjs +232 -79
  151. package/scripts/langages/python/composants.mjs +65 -3
  152. package/scripts/langages/python/exemples.mjs +21 -12
  153. package/scripts/langages/python/index.mjs +25 -5
  154. package/scripts/langages/python/lot.mjs +1 -36
  155. package/scripts/langages/python/squelette.mjs +119 -17
  156. package/scripts/langages/typescript/construire.mjs +6 -163
  157. package/scripts/langages/typescript/exemples.mjs +19 -11
  158. package/scripts/langages/typescript/frontieres.mjs +1 -1
  159. package/scripts/langages/typescript/index.mjs +48 -63
  160. package/scripts/langages/typescript/interfaces-contre-code.mjs +4 -4
  161. package/scripts/langages/typescript/migrations/0.30.0-prefixe-des-tickets.mjs +63 -0
  162. package/scripts/langages/typescript/migrations/0.30.0-tailles-des-outils-lourds.mjs +31 -0
  163. package/scripts/langages/typescript/migrations/0.30.0-titres-nommant-un-ticket.mjs +40 -0
  164. package/scripts/langages/typescript/mise-a-jour.mjs +1 -2
  165. package/scripts/langages/typescript/regle-des-tests.mjs +13 -0
  166. package/scripts/langages/typescript/squelette.mjs +18 -2
  167. package/scripts/langages/typescript/tailles-des-tests.mjs +40 -9
  168. package/scripts/langages/typescript/tests-de-nuit.mjs +44 -21
  169. package/scripts/langages/typescript/tests.mjs +17 -8
  170. package/scripts/langages/typescript/titres-de-tests.mjs +297 -0
  171. package/scripts/langages/typescript/turbo-des-paquets.mjs +183 -38
  172. package/scripts/langages/typescript/verdict.mjs +1 -1
  173. package/scripts/langages/typescript/verifier.mjs +110 -296
  174. package/scripts/langages/typescript/vitest-config/base.mjs +30 -10
  175. package/scripts/langages/typescript/vitest-config/bornes.mjs +13 -0
  176. package/scripts/langages/typescript/vitest-config/cibles.mjs +123 -62
  177. package/scripts/langages/typescript/vitest-config/delais.mjs +54 -0
  178. package/scripts/langages/typescript/vitest-config/delais.setup.mjs +11 -0
  179. package/scripts/langages/typescript/vitest-config/duree.classement.mjs +100 -0
  180. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +56 -64
  181. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +7 -2
  182. package/scripts/langages/typescript/vitest-config/mesure.mjs +3 -2
  183. package/scripts/langages/typescript/vitest.nuit.config.mjs +22 -13
  184. package/scripts/lecture-unique.mjs +51 -0
  185. package/scripts/mesure/pression.mjs +11 -9
  186. package/scripts/mesure-de-la-machine.d.mts +21 -0
  187. package/scripts/mesure-de-la-machine.mjs +76 -0
  188. package/scripts/migrations/0.23.2-copies-du-cadre.mjs +8 -2
  189. package/scripts/migrations/0.30.0-ci-appelle-la-verification.mjs +120 -0
  190. package/scripts/migrations/0.31.0-paquets-dans-le-graphe.mjs +81 -0
  191. package/scripts/migrations.mjs +5 -0
  192. package/scripts/nuit.sh +29 -15
  193. package/scripts/outil.mjs +72 -0
  194. package/scripts/outils-cles.d.mts +24 -0
  195. package/scripts/outils-cles.mjs +0 -1
  196. package/scripts/paquet-npm.mjs +147 -0
  197. package/scripts/paquet.mjs +112 -14
  198. package/scripts/paquets.mjs +34 -6
  199. package/scripts/passe-de-la-machine.mjs +66 -0
  200. package/scripts/places-de-la-machine.mjs +360 -0
  201. package/scripts/places-du-serveur.mjs +170 -0
  202. package/scripts/prefixe-des-tickets.mjs +68 -0
  203. package/scripts/preparation.mjs +10 -3
  204. package/scripts/registre.mjs +3 -2
  205. package/scripts/regles-des-places.d.mts +36 -0
  206. package/scripts/regles-des-places.mjs +70 -0
  207. package/scripts/reponses-du-circuit.d.mts +6 -0
  208. package/scripts/reponses-du-circuit.mjs +28 -0
  209. package/scripts/resultats.mjs +29 -14
  210. package/scripts/retirer-les-copies-finies.mjs +25 -0
  211. package/scripts/sans-reponse.d.mts +4 -0
  212. package/scripts/sans-reponse.mjs +13 -0
  213. package/scripts/seances.mjs +918 -0
  214. package/scripts/services-du-noyau.mjs +28 -11
  215. package/scripts/session-start.sh +10 -1
  216. package/scripts/sortie.mjs +23 -4
  217. package/scripts/sources.mjs +3 -3
  218. package/scripts/sous-commandes.mjs +39 -9
  219. package/scripts/style-a-l-ecriture.mjs +229 -0
  220. package/scripts/superviseur.mjs +382 -16
  221. package/scripts/tableau.mjs +329 -130
  222. package/scripts/taches-du-graphe.mjs +328 -0
  223. package/scripts/ticket-du-circuit.mjs +206 -0
  224. package/scripts/transitions.d.mts +148 -0
  225. package/scripts/transitions.mjs +901 -0
  226. package/scripts/verrou-de-fichier.mjs +2 -2
  227. package/scripts/verrou-de-machine.mjs +322 -62
  228. package/skills/developpeur/SKILL.md +11 -3
  229. package/skills/explorateur/SKILL.md +2 -1
  230. package/skills/pitmaster/SKILL.md +62 -28
  231. package/skills/pitmaster/references/consigne-agent.md +5 -1
  232. package/skills/release/SKILL.md +3 -3
  233. package/skills/relecteur/SKILL.md +22 -8
  234. package/skills/testwriter/SKILL.md +47 -39
  235. package/scripts/demon.mjs +0 -138
  236. package/scripts/integration/file-attente.mjs +0 -61
  237. package/scripts/langages/cargo/touches.mjs +0 -93
  238. package/scripts/langages/typescript/script-des-tests.mjs +0 -6
@@ -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
- // once replaced (75: a failure of duration under load, which found no rest in its bound,
43
- // scripts/langages/typescript/verifier.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
34
+ // once replaced (75: the wait for the lock of the machine reached its bound,
35
+ // scripts/verrou-de-machine.mjs; neither green nor red), stays in the queue, the reason written to its
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,56 +50,52 @@
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) {
@@ -122,11 +113,6 @@ function ecrireLesEtapes(avancement, vue) {
122
113
  }
123
114
  }
124
115
 
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
116
  // The directory of the workflows GitHub reads, and the extensions it reads in it.
131
117
  const DOSSIER_DES_FLUX = '.github/workflows';
132
118
  const EXTENSIONS_DES_FLUX = /\.ya?ml$/;
@@ -213,9 +199,8 @@ export function fluxDeLaBranche(fichiers, branche) {
213
199
  .map(({ chemin }) => chemin);
214
200
  }
215
201
 
216
- // The verdicts of a reading of the CI (`lireCI`).
202
+ // The verdicts of a reading of the CI (`lireUneFoisLaCI`, then the workflow `ciDuCommit`).
217
203
  const VERTE = 'verte';
218
- const ROUGE = 'rouge';
219
204
  const SANS_CI = 'sans-ci';
220
205
  const NON_LUE = 'non-lue';
221
206
 
@@ -244,407 +229,477 @@ const ghDans =
244
229
  ...options,
245
230
  });
246
231
 
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 };
232
+ /**
233
+ * The tools of the queue on the main tree <racine>, its lines said by <dire>: `{ racine,
234
+ * principale, bd, gh, dire, avancement }`, bd run under the queue's author (BEADS_ACTOR), the
235
+ * branch of the main tree (null when it is on none).
236
+ */
237
+ export function outilsDeLaFile(racine, dire, avancement = null) {
238
+ const bd = (...a) => {
239
+ const r = spawnSync('bd', a, {
240
+ cwd: racine,
241
+ encoding: 'utf8',
242
+ maxBuffer: 256 * 1024 * 1024,
243
+ env: { ...process.env, [ACTEUR]: AUTEUR_DE_LA_FILE },
244
+ });
245
+ if (r.status !== 0) process.stderr.write(`bd ${a[0]} ${a[1] ?? ''} : ${r.stderr}`);
246
+ return r;
269
247
  };
270
- const recherche = delai('GRILLHOUSE_CI_RECHERCHE_MS', RECHERCHE_CI_MS);
271
- const debut = Date.now();
272
- let passage = null;
273
- for (;;) {
248
+ const principale =
249
+ spawnSync('git', ['-C', racine, 'symbolic-ref', '--short', '-q', 'HEAD'], {
250
+ encoding: 'utf8',
251
+ }).stdout.trim() || null;
252
+ return { racine, principale, bd, gh: ghDans(racine), dire, avancement };
253
+ }
254
+
255
+ /**
256
+ * One reading of the CI of the commit <sha> pushed to <branche>, with the tools <o> (`outilsDeLaFile`),
257
+ * the run <passage> found by a reading before (null while it is looked for): `{ etat: 'sans-ci' }`
258
+ * (no workflow runs on a push to the branch), `{ etat: 'cherche' }` (no run yet), `{ etat:
259
+ * 'en-cours', passage }`, `{ etat: 'finie', passage, conclusion }`, or `{ etat: 'non-lue', raison
260
+ * }` (gh absent, refusing, or its output unreadable). The run is read at its current attempt
261
+ * (`gh run view <id>` without `--attempt`). A run found is read at once. It writes nothing to the
262
+ * ticket: `conclureLaCI` does.
263
+ */
264
+ export function lireUneFoisLaCI(o, { sha, branche, passage = null }) {
265
+ const { gh } = o;
266
+ let id = passage;
267
+ if (id === null) {
268
+ if (fluxDuCommit(o.racine, sha, branche).length === 0) return { etat: SANS_CI };
274
269
  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()}`);
270
+ if (r.error) {
271
+ return { etat: NON_LUE, raison: `gh ne se lance pas (${r.error.code ?? r.error.message}).` };
272
+ }
273
+ if (r.status !== 0) {
274
+ return { etat: NON_LUE, raison: `gh run list refuse :\n${`${r.stderr}${r.stdout}`.trim()}` };
275
+ }
277
276
  let passages = [];
278
277
  try {
279
278
  passages = JSON.parse(r.stdout || '[]');
280
279
  } catch {
281
- return nonLue(`gh run list rend une sortie illisible :\n${r.stdout.trim()}`);
280
+ return {
281
+ etat: NON_LUE,
282
+ raison: `gh run list rend une sortie illisible :\n${r.stdout.trim()}`,
283
+ };
282
284
  }
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));
285
+ const trouve = passages.find(x => x?.databaseId);
286
+ if (!trouve) return { etat: 'cherche' };
287
+ id = String(trouve.databaseId);
287
288
  }
288
- if (!passage) {
289
- return nonLue(`aucun passage de la CI pour ce commit en ${Math.round(recherche / 1000)} s.`);
289
+ const v = gh(['run', 'view', id, '--json', 'status,conclusion,jobs'], {
290
+ timeout: 60_000,
291
+ killSignal: 'SIGKILL',
292
+ });
293
+ if (v.error) {
294
+ return { etat: NON_LUE, raison: `gh ne se lance pas (${v.error.code ?? v.error.message}).` };
290
295
  }
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
- }
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.`);
313
- }
314
- attendreUnPeu(Math.min(pas, reste));
296
+ if (v.status !== 0) {
297
+ return { etat: NON_LUE, raison: `gh run view refuse :\n${`${v.stderr}${v.stdout}`.trim()}` };
298
+ }
299
+ let vue;
300
+ try {
301
+ vue = JSON.parse(v.stdout || '{}');
302
+ } catch {
303
+ return { etat: NON_LUE, raison: `gh run view rend une sortie illisible :\n${v.stdout.trim()}` };
315
304
  }
316
- if (vue.conclusion === 'success') {
317
- o.dire(`✓ CI de ${court} verte (passage ${id})`);
318
- return { verdict: VERTE, passage: id };
305
+ ecrireLesEtapes(o.avancement, vue);
306
+ if (vue?.status === 'completed') {
307
+ return { etat: 'finie', passage: id, conclusion: vue.conclusion ?? null };
319
308
  }
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 };
309
+ return { etat: 'en-cours', passage: id };
331
310
  }
332
311
 
333
312
  /**
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.
313
+ * The working directory of the circuit of <ticket> in the main tree of <o> removed, once the queue
314
+ * is done with the ticket closed: as the workspace of a pipeline, it lives as long as the ticket.
343
315
  */
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.`
358
- );
359
- }
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.`
316
+ export function retirerLeTravail(o, ticket) {
317
+ rmSync(path.join(o.racine, '.claude', 'worktrees', `${ticket}.travail`), {
318
+ recursive: true,
319
+ force: true,
320
+ });
321
+ }
322
+
323
+ /**
324
+ * The CI of the commit <sha> of the ticket <ticket> concluded with the tools <o>, its verdict
325
+ * <verdict> (VERTE, `rouge`, SANS_CI or NON_LUE), its run <passage> and the reason <raison> of a CI
326
+ * not read, after the queue's entry, or read again (<relue>, on `--reprendre`): what is said to the
327
+ * ticket and what becomes of it. No CI, the ticket is told so in one line; not read, it is told
328
+ * why; red, its comment gives the address of the run and the end of its failed log, and the
329
+ * queue's entry reopens it (read again, it stays open). Green or no CI read again, the ticket
330
+ * closes « intégré : <commit> », its run named. `{ etat, raison }`: `ferme` or `rouvert`, as the
331
+ * circuit reads the issue of the queue (src/temporal/file/deroule.ts); `ferme`, the working
332
+ * directory of its circuit is removed (`retirerLeTravail`).
333
+ */
334
+ export function conclureLaCI(
335
+ o,
336
+ { ticket, sha, branche, verdict, passage = null, raison = null, relue = false }
337
+ ) {
338
+ const court = sha.slice(0, 7);
339
+ const commenter = texte => commenterAu(o, ticket, texte);
340
+ if (verdict === SANS_CI) {
341
+ 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.`;
342
+ commenter(texte);
343
+ o.dire(`✓ ${texte}`);
344
+ } else if (verdict === NON_LUE) {
345
+ commenter(`## CI non lue\n\nLa CI de ${court} n'a pas été lue : ${raison}`);
346
+ o.dire(`⚠ CI de ${court} non lue : ${raison}`);
347
+ } else if (verdict === VERTE) {
348
+ o.dire(`✓ CI de ${court} verte (passage ${passage})`);
349
+ } else {
350
+ const { gh } = o;
351
+ const url =
352
+ gh(['run', 'view', passage, '--json', 'url', '--jq', '.url']).stdout?.trim() || passage;
353
+ const journal = `${gh(['run', 'view', passage, '--log-failed']).stdout ?? ''}`
354
+ .trim()
355
+ .split('\n')
356
+ .slice(-60)
357
+ .join('\n');
358
+ commenter(
359
+ `## 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.`
367
360
  );
361
+ o.dire(`✗ CI de ${court} rouge (passage ${passage}) : ${ticket} rouvert`);
362
+ if (!relue) o.bd('reopen', ticket);
363
+ return { etat: 'rouvert', raison: `La CI de ${court} est rouge : ${url}` };
368
364
  }
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.`);
365
+ if (!relue) {
366
+ retirerLeTravail(o, ticket);
367
+ return {
368
+ etat: 'ferme',
369
+ raison:
370
+ verdict === NON_LUE ? `${INTEGRE}${court} ; CI non lue : ${raison}` : `${INTEGRE}${court}`,
371
+ };
374
372
  }
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}`);
373
+ if (verdict === NON_LUE) return { etat: 'rouvert', raison: `CI non relue : ${raison}` };
374
+ o.bd('close', ticket, '--reason', `${INTEGRE}${court}`);
375
+ if (passage) {
376
+ commenter(
377
+ `## CI relue\n\nLa CI de ${court} sur ${o.principale} est verte au dernier essai du passage ${passage} : le ticket se ferme.`
378
+ );
387
379
  }
388
- return 0;
380
+ o.dire(`✓ ${ticket} fermé : ${court} est sur ${o.principale}`);
381
+ retirerLeTravail(o, ticket);
382
+ return { etat: 'ferme', raison: `${INTEGRE}${court}` };
389
383
  }
390
384
 
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()
385
+ /**
386
+ * Where the lot of the ticket <ticket> stands, with the tools <o>: `{ statut, raison, aEntrer,
387
+ * commit, branche, surOrigin, raisonOrigin, faute }`, its status in Beads and its reason of
388
+ * closure, whether its branch `agent/<ticket>` holds a lot ahead of main (which enters by the
389
+ * queue), the commit of main that delivers it (`lotSurMain`, null without one), the branch it was
390
+ * pushed to (`grillhouse.poussee.commit`), whether that commit is on that branch of origin
391
+ * (`surOrigin`: « oui », « non » for a closure that failed before its push, or « inconnu » when
392
+ * origin does not answer, `raisonOrigin` its reason), and the fault of that key (null when it
393
+ * reads).
394
+ */
395
+ export function situerLeLot(o, ticket) {
396
+ const show = o.bd('show', ticket, '--json');
397
+ const t = show.status === 0 ? (JSON.parse(show.stdout)[0] ?? {}) : {};
398
+ const git = (...a) => spawnSync('git', ['-C', o.racine, ...a], { encoding: 'utf8' });
399
+ const paquet = git('show', `refs/heads/${o.principale}:package.json`);
400
+ const { commit: branche, faute } = lireCommit(
401
+ paquet.status === 0 ? JSON.parse(paquet.stdout) : null
407
402
  );
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;
403
+ const enAvance = git(
404
+ 'rev-list',
405
+ '--count',
406
+ `refs/heads/${o.principale}..refs/heads/agent/${ticket}`
407
+ );
408
+ const commit = lotSurMain(o, ticket);
409
+ const origine =
410
+ commit && !faute ? surOrigin(o, commit, branche) : { surOrigin: 'non', raison: null };
411
+ return {
412
+ statut: t.status ?? null,
413
+ raison: t.close_reason ?? null,
414
+ aEntrer: enAvance.status === 0 && Number(enAvance.stdout.trim()) > 0,
415
+ commit,
416
+ branche: faute ? null : branche,
417
+ surOrigin: origine.surOrigin,
418
+ raisonOrigin: origine.raison,
419
+ faute: faute ?? null,
419
420
  };
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');
421
+ }
432
422
 
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}`);
423
+ // Whether the commit <commit> is on the branch <branche> of origin, with the tools <o>: « oui »,
424
+ // « non », or « inconnu » when origin does not answer (`git ls-remote`, without a prompt, as the
425
+ // push) or its tip is not known here (`merge-base --is-ancestor` neither 0 nor 1), its reason
426
+ // named: a place that does not read is never « not pushed ».
427
+ function surOrigin(o, commit, branche) {
428
+ const ls = spawnSync(
429
+ 'git',
430
+ ['-C', o.racine, 'ls-remote', '--heads', 'origin', `refs/heads/${branche}`],
431
+ {
432
+ encoding: 'utf8',
433
+ env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
434
+ }
435
+ );
436
+ if (ls.status !== 0) {
437
+ const raison =
438
+ `${ls.stderr ?? ''}`.trim().split('\n')[0] || ls.error?.message || `code ${ls.status}`;
439
+ return { surOrigin: 'inconnu', raison: `git ls-remote origin ${branche} : ${raison}` };
440
+ }
441
+ const pointe = ls.stdout.split(/\s/)[0] ?? '';
442
+ if (!pointe) return { surOrigin: 'non', raison: null };
443
+ // `--is-ancestor` answers 0 (an ancestor) or 1 (not one); any other code (the tip of origin
444
+ // unknown here, 128) does not say: « inconnu », its reason named.
445
+ const git = (...a) => spawnSync('git', ['-C', o.racine, ...a], { encoding: 'utf8' });
446
+ const ancetre = git('merge-base', '--is-ancestor', commit, pointe);
447
+ if (ancetre.status === 0) return { surOrigin: 'oui', raison: null };
448
+ if (ancetre.status === 1) return { surOrigin: 'non', raison: null };
449
+ const raison =
450
+ `${ancetre.stderr ?? ''}`.trim().split('\n')[0] ||
451
+ ancetre.error?.message ||
452
+ `code ${ancetre.status}`;
453
+ return {
454
+ surOrigin: 'inconnu',
455
+ raison: `git merge-base --is-ancestor ${commit.slice(0, 7)} origin/${branche} : ${raison}`,
458
456
  };
457
+ }
459
458
 
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}` };
459
+ // The commit of main that delivers the ticket <ticket> (its title line names it,
460
+ // `commitsDelivering` of ../un-commit-par-ticket.mjs, the prefix read from bd), the last one, in
461
+ // full; null without one.
462
+ function lotSurMain(o, ticket) {
463
+ const git = (...a) => spawnSync('git', ['-C', o.racine, ...a], { encoding: 'utf8' });
464
+ const prefixe = o.bd('config', 'get', 'issue_prefix').stdout?.trim() ?? '';
465
+ return (
466
+ commitsDelivering(ticket, prefixe, gitLog(o.racine))
467
+ .map(c => git('rev-parse', '--verify', '-q', `${c}^{commit}`).stdout.trim())
468
+ .find(
469
+ c => c && git('merge-base', '--is-ancestor', c, `refs/heads/${o.principale}`).status === 0
470
+ ) ?? null
471
+ );
472
+ }
473
+
474
+ // The branch of <entree> replaced on the main <tete> in the queue's own copy, replayed, with the
475
+ // tools <o>: { nouveau } (the commit to move main onto), or { sortie: [titre, détail] } (it leaves
476
+ // the queue), or { garde } (it stays, the reason).
477
+ function rejouer(o, tip, tete, ticketRejoue = null) {
478
+ const { racine, dire } = o;
479
+ const copie = path.join(racine, '.claude', 'worktrees', 'file');
480
+ if (existsSync(copie)) spawnSync('git', ['-C', copie, 'rebase', '--abort'], { encoding: 'utf8' });
481
+ // The keys of the project, before any work: its generated files and its tools.
482
+ let engendres;
483
+ let env;
484
+ try {
485
+ engendres = engendresDe(racine);
486
+ env = avecLesDonnees(donneesDe(racine), avecLesOutils(outilsDe(racine), process.env));
487
+ } catch (e) {
488
+ return { garde: `une clé grillhouse du package.json est refusée :\n${e.message}` };
489
+ }
490
+ const ouverte = ouvrirCopie({ racine, copie, ref: tete, dire });
491
+ if (ouverte.refus) return { garde: ouverte.refus };
492
+ const { dansCopie, monter, installer, tester } = ouverte;
493
+ if (dansCopie('checkout', '-q', '--detach', tip).status !== 0)
494
+ return { garde: `la copie ne prend pas ${tip.slice(0, 7)}` };
495
+ // A conflict on generated files the project declares only is no conflict: main's version is
496
+ // taken, and their command writes them again once the branch is replaced (below).
497
+ let rebase = dansCopie('rebase', tete);
498
+ let tours = Number(dansCopie('rev-list', '--count', `${tete}..${tip}`).stdout.trim()) || 1;
499
+ while (rebase.status !== 0) {
500
+ const conflits = dansCopie('diff', '--name-only', '--diff-filter=U')
501
+ .stdout.split('\n')
502
+ .filter(Boolean);
503
+ const engendresSeuls =
504
+ tours-- > 0 &&
505
+ conflits.length > 0 &&
506
+ conflits.every(f => engendres.some(e => couvertPar(e.entiers, f))) &&
507
+ dansCopie('checkout', '--ours', '--', ...conflits).status === 0 &&
508
+ dansCopie('add', '--', ...conflits).status === 0;
509
+ if (!engendresSeuls) {
510
+ dansCopie('rebase', '--abort');
511
+ return {
512
+ sortie: [
513
+ 'elle ne se replace pas sur main.',
514
+ conflits.length
515
+ ? `Fichiers en conflit :\n${conflits.map(f => ` ${f}`).join('\n')}`
516
+ : `Sortie de git :\n${rebase.stdout}${rebase.stderr}`,
517
+ ],
518
+ };
473
519
  }
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');
520
+ rebase = dansCopie('-c', 'core.editor=true', 'rebase', '--continue');
521
+ }
522
+ const installation = installer();
523
+ if (installation) {
524
+ return { sortie: [installation, "Le verrou de la branche replacée ne s'installe pas."] };
525
+ }
526
+ const touches = touchesPar(
527
+ engendres,
528
+ dansCopie('diff', '--name-only', '--no-renames', '-z', tete, 'HEAD')
529
+ .stdout.split('\0')
530
+ .filter(Boolean)
531
+ );
532
+ if (touches.length) {
533
+ const refus = regenerer({
534
+ refs: touches.map(e => ({ ...e, cadre: false })),
535
+ dansCopie,
536
+ lancer: commande =>
537
+ spawnSync('bash', monter('sh', '-c', commande), {
538
+ cwd: copie,
539
+ encoding: 'utf8',
540
+ maxBuffer: 256 * 1024 * 1024,
541
+ env,
542
+ }),
543
+ });
544
+ if (refus) return { sortie: ['ses fichiers engendrés ne se régénèrent pas sur main.', refus] };
545
+ if (dansCopie('diff', '--cached', '--quiet').status !== 0) {
546
+ const corrige = dansCopie('commit', '-q', '--amend', '--no-edit', '--no-verify');
547
+ if (corrige.status !== 0) {
495
548
  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
- ],
549
+ garde: `ses fichiers régénérés n'entrent pas dans son commit :\n${corrige.stderr}`,
502
550
  };
503
551
  }
504
- rebase = dansCopie('-c', 'core.editor=true', 'rebase', '--continue');
505
552
  }
506
- const installation = installer();
507
- if (installation) {
508
- return { sortie: [installation, "Le verrou de la branche replacée ne s'installe pas."] };
553
+ dire(`✓ fichiers engendrés régénérés sur main : ${touches.map(e => e.nom).join(', ')}`);
554
+ }
555
+ dire('— npm run verifier (construction, gardes, tests)');
556
+ const t = tester({ sorte: 'File', ticket: ticketRejoue });
557
+ if (t.status === A_REPASSER) {
558
+ return {
559
+ 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.`,
560
+ };
561
+ }
562
+ if (t.status !== 0) {
563
+ const fin = `${t.stdout}${t.stderr}`.trim().split('\n').slice(-40).join('\n');
564
+ return { sortie: ['ses tests sont rouges une fois la branche replacée.', fin] };
565
+ }
566
+ return { nouveau: dansCopie('rev-parse', 'HEAD').stdout.trim() };
567
+ }
568
+
569
+ /**
570
+ * Main moved onto the branch of <entree> (`{ ticket, branche }`) with the tools <o>, against the
571
+ * main of the moment, without a word to the ticket: `{ entre: { commit } }`, main at <commit>;
572
+ * `{ sortie: [titre, détail] }` (it leaves the queue: gone, not replaced, red once replaced);
573
+ * `{ garde }` (it stays in the queue, the reason); `{ ecartee: true }` (nothing ahead of main). A
574
+ * lot already on main (the branch points at the commit of main that delivers its ticket, or each
575
+ * of its commits has its equivalent on main, or the branch is gone), as an attempt played again
576
+ * after its worker died finds it, is entered: main does not move again.
577
+ */
578
+ export function avancerMain(o, entree) {
579
+ const git = (...args) => spawnSync('git', ['-C', o.racine, ...args], { encoding: 'utf8' });
580
+ const refPrincipale = `refs/heads/${o.principale}`;
581
+ const tip = git('rev-parse', '--verify', '-q', `refs/heads/${entree.branche}`).stdout.trim();
582
+ const livre = lotSurMain(o, entree.ticket);
583
+ // A lot on main whose branch is gone (a closure that failed after its deletion) is entered.
584
+ if (!tip)
585
+ return livre ? { entre: { commit: livre } } : { sortie: ["la branche n'existe plus.", ''] };
586
+ const enAvance = Number(git('rev-list', '--count', `${refPrincipale}..${tip}`).stdout.trim());
587
+ // The lot is on main when the branch points at the commit of main that delivers the ticket
588
+ // (main moved onto it by fast-forward), or when each commit of the branch has its equivalent on
589
+ // main (the same patch, git cherry), the replay a rebase wrote: a lot of before of a ticket
590
+ // reopened is neither, its branch at main's or ahead of it by new commits.
591
+ if (livre) {
592
+ const cerise = git('cherry', refPrincipale, tip).stdout.split('\n').filter(Boolean);
593
+ const rejeu = enAvance > 0 && cerise.length > 0 && cerise.every(l => l.startsWith('- '));
594
+ if (tip === livre || rejeu) return { entre: { commit: livre } };
595
+ }
596
+ if (enAvance === 0) return { ecartee: true };
597
+ for (let essai = 0; essai < ESSAIS_PAR_BRANCHE; essai++) {
598
+ const tete = git('rev-parse', refPrincipale).stdout.trim();
599
+ let nouveau = tip;
600
+ if (git('merge-base', '--is-ancestor', tete, tip).status !== 0) {
601
+ const r = rejouer(o, tip, tete, entree.ticket);
602
+ if (!r.nouveau) return r;
603
+ nouveau = r.nouveau;
509
604
  }
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
- }
605
+ if (nouveau !== tete) {
606
+ const avance = git('merge', '-q', '--ff-only', nouveau);
607
+ if (avance.status !== 0) {
608
+ if (git('rev-parse', refPrincipale).stdout.trim() !== tete) continue;
609
+ return {
610
+ garde:
611
+ `${o.principale} n'avance pas sur ${nouveau.slice(0, 7)} :\n${avance.stdout}${avance.stderr}`.trim(),
612
+ };
537
613
  }
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 : un échec de durée sous charge, sans repos dans la borne. Ni vert ni rouge ; la prochaine file la rejoue.`,
545
- };
546
- }
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] };
550
614
  }
551
- return { nouveau: dansCopie('rev-parse', 'HEAD').stdout.trim() };
552
- };
615
+ return { entre: { commit: nouveau } };
616
+ }
617
+ return { garde: `${o.principale} bouge sans cesse : cinq essais n'ont pas suffi.` };
618
+ }
553
619
 
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}`);
620
+ /**
621
+ * The ticket of <entree> (`{ ticket, branche, commit }`) entered on main at <commit>, with the
622
+ * tools <o>: it closes « intégré : <commit> » and loses `en-file` (a ticket already closed is left
623
+ * as it is), <apresLaFermeture> runs (the queue on its file removes its entry there), the branch is
624
+ * deleted, then main is pushed to origin on the branch `grillhouse.poussee.commit` of main's
625
+ * package.json; a push not made ends the queue's work on the ticket, and removes the working
626
+ * directory of its circuit (`retirerLeTravail`), which the conclusion of its CI removes otherwise. Each of its gestures replays without
627
+ * harm (a ticket closed is left closed, a branch gone stays gone, a commit pushed is pushed again
628
+ * as it is), and never reopens the ticket; its comments are effects (`commenterAu`), which the
629
+ * workflow of the queue writes once each. `{ poussee, raison }`: the branch pushed to, or null and
630
+ * why, in one line (`enUneLigne`), its comment at the ticket whole.
631
+ */
632
+ export function fermerLEntree(o, entree, apresLaFermeture = () => {}) {
633
+ const { racine } = o;
634
+ const git = (...args) => spawnSync('git', ['-C', racine, ...args], { encoding: 'utf8' });
635
+ const court = entree.commit.slice(0, 7);
636
+ const commenter = texte => commenterAu(o, entree.ticket, texte);
637
+ const show = o.bd('show', entree.ticket, '--json');
638
+ const statut = show.status === 0 ? (JSON.parse(show.stdout)[0]?.status ?? null) : null;
639
+ if (statut !== 'closed') {
640
+ o.bd('update', entree.ticket, '--remove-label', 'en-file');
641
+ o.bd('close', entree.ticket, '--reason', `${INTEGRE}${court}`);
642
+ }
643
+ apresLaFermeture();
644
+ o.dire(`✓ ${entree.branche} entre sur ${o.principale} : ${court}`);
645
+ if (git('rev-parse', '--verify', '-q', `refs/heads/${entree.branche}`).status === 0) {
565
646
  const efface = git('branch', '-D', entree.branche);
566
647
  if (efface.status !== 0) {
567
648
  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()}`
649
+ `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
650
  );
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);
651
+ o.dire(`⚠ ${entree.branche} n'est pas effacée`);
642
652
  }
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
653
  }
654
+ const paquet = git('show', `refs/heads/${o.principale}:package.json`);
655
+ const { commit, faute } = lireCommit(paquet.status === 0 ? JSON.parse(paquet.stdout) : null);
656
+ if (faute) {
657
+ const raison = `Poussée non faite : grillhouse.poussee.commit vaut ${faute}, pas un nom de branche.`;
658
+ commenter(raison);
659
+ retirerLeTravail(o, entree.ticket);
660
+ return { poussee: null, raison: enUneLigne(raison) };
661
+ }
662
+ const pousse = spawnSync(
663
+ 'git',
664
+ ['-C', racine, 'push', 'origin', `${entree.commit}:refs/heads/${commit}`],
665
+ { encoding: 'utf8', env: { ...process.env, GIT_TERMINAL_PROMPT: '0' } }
666
+ );
667
+ if (pousse.status !== 0) {
668
+ const raison = `La poussée de ${court} vers origin/${commit} (grillhouse.poussee.commit) est refusée :\n${pousse.stderr.trim()}`;
669
+ commenter(raison);
670
+ o.dire(`⚠ poussée de ${court} refusée`);
671
+ retirerLeTravail(o, entree.ticket);
672
+ return { poussee: null, raison: enUneLigne(raison) };
673
+ }
674
+ o.dire(`✓ poussée : ${court} est sur origin/${commit}`);
675
+ return { poussee: commit, raison: null };
646
676
  }
647
677
 
648
- if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
649
- process.exitCode = main(process.argv.slice(2));
678
+ /**
679
+ * What the outcome <r> of `avancerMain` for <entree> says to its ticket, with the tools <o>: a
680
+ * branch out of the queue reopens it, its files or its red named; a branch set aside loses
681
+ * `en-file`, the ticket left open; a branch kept, the reason. `{ etat, raison }`: `rouvert` or
682
+ * `en-file`, as the circuit reads the queue.
683
+ */
684
+ export function direLIssue(o, entree, r) {
685
+ const commenter = texte => commenterAu(o, entree.ticket, texte);
686
+ if (r.sortie) {
687
+ const [titre, detail] = r.sortie;
688
+ 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}.`;
689
+ o.bd('update', entree.ticket, '--status', 'open', '--remove-label', 'en-file');
690
+ commenter(texte);
691
+ o.dire(`✗ ${entree.branche} sort de la file : ${titre}`);
692
+ return { etat: 'rouvert', raison: texte };
693
+ }
694
+ if (r.ecartee) {
695
+ 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.`;
696
+ o.bd('update', entree.ticket, '--remove-label', 'en-file');
697
+ commenter(texte);
698
+ o.dire(`⚠ ${entree.branche} n'a rien en avance sur ${o.principale} : elle sort de la file`);
699
+ return { etat: 'rouvert', raison: texte };
700
+ }
701
+ const texte = `## La file garde la branche\n\nLa branche ${entree.branche} reste en file : ${r.garde}`;
702
+ commenter(texte);
703
+ o.dire(`⚠ ${entree.branche} reste en file : ${r.garde}`);
704
+ return { etat: 'en-file', raison: texte };
650
705
  }