@roomi-fields/grillhouse 0.45.1 → 0.47.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 (114) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +52 -0
  3. package/cadre/templates/c/package.json +19 -0
  4. package/cadre/templates/projet/.github/workflows/ci.yml +34 -49
  5. package/cadre/templates/projet/.github/workflows/machine-vierge.yml +101 -0
  6. package/cadre/templates/projet/CLAUDE.md +28 -5
  7. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  8. package/charte.md +61 -23
  9. package/dist/temporal/circuit/appel.d.ts +7 -0
  10. package/dist/temporal/circuit/appel.js +17 -0
  11. package/dist/temporal/circuit/appel.js.map +1 -1
  12. package/dist/temporal/circuit/client.d.ts +28 -5
  13. package/dist/temporal/circuit/client.js +56 -13
  14. package/dist/temporal/circuit/client.js.map +1 -1
  15. package/dist/temporal/circuit/commande.js +16 -4
  16. package/dist/temporal/circuit/commande.js.map +1 -1
  17. package/dist/temporal/circuit/contrat.d.ts +22 -2
  18. package/dist/temporal/circuit/contrat.js +76 -0
  19. package/dist/temporal/circuit/contrat.js.map +1 -1
  20. package/dist/temporal/circuit/deroule.js +68 -11
  21. package/dist/temporal/circuit/deroule.js.map +1 -1
  22. package/dist/temporal/file/activites.d.ts +2 -0
  23. package/dist/temporal/file/activites.js +7 -0
  24. package/dist/temporal/file/activites.js.map +1 -1
  25. package/dist/temporal/file/contrat.d.ts +28 -18
  26. package/dist/temporal/file/contrat.js +8 -5
  27. package/dist/temporal/file/contrat.js.map +1 -1
  28. package/dist/temporal/file/deroule.d.ts +1 -1
  29. package/dist/temporal/file/deroule.js +91 -42
  30. package/dist/temporal/file/deroule.js.map +1 -1
  31. package/dist/temporal/tickets/activites.d.ts +1 -0
  32. package/dist/temporal/tickets/activites.js +37 -11
  33. package/dist/temporal/tickets/activites.js.map +1 -1
  34. package/dist/temporal/tickets/contrat.d.ts +14 -0
  35. package/dist/temporal/tickets/deroule.js +16 -3
  36. package/dist/temporal/tickets/deroule.js.map +1 -1
  37. package/docs/ARCHITECTURE.md +309 -128
  38. package/docs/INTERFACE.md +42 -22
  39. package/hooks/register.tsx +30 -0
  40. package/package.json +1 -1
  41. package/scripts/activites.mjs +60 -21
  42. package/scripts/arbres-juges.mjs +59 -0
  43. package/scripts/attente-a-l-arret.mjs +29 -52
  44. package/scripts/attente-au-tour.mjs +8 -26
  45. package/scripts/avancement.mjs +2 -38
  46. package/scripts/branche-de-nuit.mjs +14 -45
  47. package/scripts/ci-de-main.mjs +273 -0
  48. package/scripts/circuit.mjs +204 -64
  49. package/scripts/circuits-cles.d.mts +9 -0
  50. package/scripts/circuits-cles.mjs +38 -0
  51. package/scripts/coeurs-dedies.mjs +4 -3
  52. package/scripts/dernier-vert.mjs +78 -10
  53. package/scripts/enveloppe/travail-de-la-copie.mjs +5 -2
  54. package/scripts/etapes.mjs +7 -2
  55. package/scripts/faits-du-circuit.mjs +63 -28
  56. package/scripts/fichiers-nommes.mjs +55 -0
  57. package/scripts/file-des-tickets.d.mts +17 -0
  58. package/scripts/file-des-tickets.mjs +39 -0
  59. package/scripts/grillhouse-maj.mjs +20 -1
  60. package/scripts/integration/file.mjs +137 -592
  61. package/scripts/integration/integrer.mjs +10 -7
  62. package/scripts/langages/c/binaires.json +4 -0
  63. package/scripts/langages/c/binaires.mjs +83 -0
  64. package/scripts/langages/c/clang-format.mjs +62 -0
  65. package/scripts/langages/c/clang-tidy.mjs +93 -0
  66. package/scripts/langages/c/clang.mjs +42 -0
  67. package/scripts/langages/c/commandes.mjs +530 -0
  68. package/scripts/langages/c/composants.mjs +209 -0
  69. package/scripts/langages/c/exemples.mjs +250 -0
  70. package/scripts/langages/c/index-interfaces.mjs +77 -0
  71. package/scripts/langages/c/index.mjs +120 -0
  72. package/scripts/langages/c/lot.mjs +41 -0
  73. package/scripts/langages/c/mise-a-jour.mjs +70 -0
  74. package/scripts/langages/c/squelette.mjs +61 -0
  75. package/scripts/langages/c/verdict.mjs +99 -0
  76. package/scripts/langages/cargo/clippy.mjs +16 -9
  77. package/scripts/langages/cargo/commandes.mjs +7 -2
  78. package/scripts/langages/cargo/sccache.mjs +19 -6
  79. package/scripts/langages/typescript/tests.mjs +31 -5
  80. package/scripts/langages/typescript/turbo-des-paquets.mjs +67 -8
  81. package/scripts/langages/typescript/vitest-config/changements.mjs +32 -3
  82. package/scripts/langages/typescript/vitest-config/lances.mjs +16 -0
  83. package/scripts/langages-des-paquets.mjs +30 -2
  84. package/scripts/langages.mjs +1 -0
  85. package/scripts/limite-d-usage.mjs +88 -0
  86. package/scripts/mesure/avancement.mjs +1 -1
  87. package/scripts/migrations/0.47.0-ci-de-main.mjs +48 -0
  88. package/scripts/migrations.mjs +2 -2
  89. package/scripts/outils-cles.d.mts +13 -5
  90. package/scripts/outils-cles.mjs +157 -17
  91. package/scripts/passe-de-la-machine.mjs +26 -2
  92. package/scripts/places-de-la-machine.mjs +52 -6
  93. package/scripts/plafond-de-la-machine.d.mts +10 -2
  94. package/scripts/plafond-de-la-machine.mjs +39 -13
  95. package/scripts/reponses-du-circuit.d.mts +16 -0
  96. package/scripts/reponses-du-circuit.mjs +39 -3
  97. package/scripts/resultats.mjs +32 -11
  98. package/scripts/seances.mjs +211 -59
  99. package/scripts/session-start.sh +2 -11
  100. package/scripts/sortie.mjs +1 -1
  101. package/scripts/sous-commandes.mjs +5 -2
  102. package/scripts/superviseur.mjs +305 -295
  103. package/scripts/tableau.mjs +73 -45
  104. package/scripts/transitions.d.mts +22 -1
  105. package/scripts/transitions.mjs +111 -13
  106. package/scripts/workflows-du-cadre.mjs +21 -1
  107. package/skills/explorateur/SKILL.md +34 -13
  108. package/skills/grill/SKILL.md +6 -5
  109. package/skills/pitmaster/SKILL.md +33 -27
  110. package/skills/redacteur/references/documents-d-un-composant.md +1 -1
  111. package/skills/relecteur/SKILL.md +6 -0
  112. package/skills/testwriter/SKILL.md +4 -0
  113. package/scripts/ci-des-branches.mjs +0 -93
  114. package/scripts/migrations/0.33.0-ci-des-branches-de-ticket.mjs +0 -31
@@ -2,8 +2,8 @@
2
2
  // The stop of the session of supervision: the hook Stop of the frame's plugin runs it
3
3
  // (`grillhouse attente-a-l-arret`) when the session ends its turn, to wait for the owner. As an
4
4
  // alert not acknowledged pages again (PagerDuty), the supervisor does not go to sleep while a
5
- // circuit waits for it, or while a circuit runs with no wait to wake it (grillhouse-d4n.9: bf5
6
- // stopped on a question at 17:06, read 40 min later, on the owner's word).
5
+ // circuit waits for it (grillhouse-d4n.9: bf5 stopped on a question at 17:06, read 40 min later,
6
+ // on the owner's word). It asks for no wait: the greffon pushes the questions of the circuits.
7
7
  //
8
8
  // - Stop runs for the session itself, never for a sub-agent (SubagentStop). The session is the
9
9
  // supervisor's as for the signal of the turn (`racineDeLaSupervision` of
@@ -12,12 +12,9 @@
12
12
  // - A question of a circuit waits for the supervisor (`questionsEnAttente` of
13
13
  // scripts/superviseur.mjs, a circuit ended without its issue included): the stop is blocked
14
14
  // with each question, its ticket, its step and the command that answers it.
15
- // - A circuit of the repository runs and no wait of the questions lives (`attenteVivante` of
16
- // scripts/tableau.mjs: the lock of the wait names a live process): the stop is blocked with the
17
- // circuits that run and the wait to launch.
18
- // - Each question blocks once, by its key, and each state of the circuits running without a wait
19
- // once, by their tickets: both are noted in `.claude/worktrees/signale-a-l-arret.json`, which
20
- // keeps the questions that still wait alone, so that a stop the supervisor decides (a question
15
+ // - Each question blocks once, by its key: it is noted in `.claude/worktrees/signale-a-l-arret.json`,
16
+ // which keeps the questions that still wait alone (an older note that holds a `etat` reads
17
+ // without error, the state dropped), so that a stop the supervisor decides (a question
21
18
  // carried to the owner) is never held in a loop (`stop_hook_active` is not read; Claude Code
22
19
  // caps the blocks in a row at eight in any case, hooks.md « Stop »).
23
20
  // - The block: the reason on the error stream, exit code 2, which Claude Code gives the session as
@@ -30,42 +27,37 @@ import { pathToFileURL } from 'node:url';
30
27
  import { racineDeLaSupervision } from './attente-au-tour.mjs';
31
28
  import { circuitsDuServeur } from './circuits-du-serveur.mjs';
32
29
  import { questionsEnAttente, ticketsHorsAttente } from './superviseur.mjs';
33
- import { attenteVivante } from './tableau.mjs';
34
30
 
35
31
  // The note of what blocked the stop in the repository at <racine>.
36
32
  const noteDe = racine => path.join(racine, '.claude', 'worktrees', 'signale-a-l-arret.json');
37
33
 
34
+ // The keys of the questions the note holds; an older note's other keys are ignored.
38
35
  function lireLaNote(racine) {
39
36
  try {
40
37
  const lu = JSON.parse(readFileSync(noteDe(racine), 'utf8'));
41
38
  return {
42
39
  questions: new Set(Array.isArray(lu?.questions) ? lu.questions.map(String) : []),
43
- etat: typeof lu?.etat === 'string' ? lu.etat : null,
40
+ // Only `questions`: a note that holds another key (an older `etat`) is written again.
41
+ nette: Object.keys(lu ?? {}).join() === 'questions',
44
42
  };
45
43
  } catch {
46
- return { questions: new Set(), etat: null };
44
+ return { questions: new Set(), nette: true };
47
45
  }
48
46
  }
49
47
 
50
48
  /**
51
49
  * What the stop of the session of supervision in <dossier> gets: the reason that blocks it, or
52
- * null when the stop passes (see the header). The questions and the state it gives are noted, so
53
- * that each blocks once.
50
+ * null when the stop passes (see the header). The questions it gives are noted, so that each
51
+ * blocks once.
54
52
  * @param {string} dossier the directory the session works in
55
53
  * @param {{ env?: Record<string, string | undefined>,
56
54
  * fermes?: (racine: string, ids: string[]) => Set<string> | null,
57
- * circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]>,
58
- * attenteVit?: (racine: string) => boolean }} [options]
55
+ * circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} [options]
59
56
  * @returns {Promise<string | null>}
60
57
  */
61
58
  export async function attenteALArret(
62
59
  dossier,
63
- {
64
- env = process.env,
65
- fermes = ticketsHorsAttente,
66
- circuitsDe = circuitsDuServeur,
67
- attenteVit = attenteVivante,
68
- } = {}
60
+ { env = process.env, fermes = ticketsHorsAttente, circuitsDe = circuitsDuServeur } = {}
69
61
  ) {
70
62
  const racine = racineDeLaSupervision(dossier, env);
71
63
  if (!racine) {
@@ -78,21 +70,15 @@ export async function attenteALArret(
78
70
  return null;
79
71
  }
80
72
  const questions = questionsEnAttente(racine, circuits, { fermes });
81
- const tournent = circuits
82
- .filter(c => c.vivant)
83
- .map(c => c.ticket)
84
- .sort((a, b) => a.localeCompare(b, 'en'));
85
73
  const note = lireLaNote(racine);
86
74
  const neuves = questions.filter(q => !note.questions.has(q.cle));
87
- const etat = tournent.length && !attenteVit(racine) ? `sans-attente:${tournent.join(',')}` : null;
88
- const etatNeuf = etat !== null && etat !== note.etat;
89
- if (etat !== note.etat || questions.length !== note.questions.size || neuves.length) {
75
+ if (!note.nette || questions.length !== note.questions.size || neuves.length) {
90
76
  const f = noteDe(racine);
91
77
  try {
92
78
  mkdirSync(path.dirname(f), { recursive: true });
93
79
  writeFileSync(
94
80
  `${f}.${process.pid}`,
95
- `${JSON.stringify({ questions: questions.map(q => q.cle).sort(), etat })}\n`
81
+ `${JSON.stringify({ questions: questions.map(q => q.cle).sort() })}\n`
96
82
  );
97
83
  renameSync(`${f}.${process.pid}`, f);
98
84
  } catch {
@@ -100,31 +86,22 @@ export async function attenteALArret(
100
86
  return null;
101
87
  }
102
88
  }
103
- if (!neuves.length && !etatNeuf) {
89
+ if (!neuves.length) {
104
90
  return null;
105
91
  }
106
- const blocs = [];
107
- if (neuves.length) {
108
- blocs.push(
109
- neuves.length > 1
110
- ? `Ne te mets pas en attente : ${neuves.length} circuits attendent ta réponse. Réponds à chacun, ou porte sa question au responsable en le lui disant, puis termine ton tour.`
111
- : 'Ne te mets pas en attente : un circuit attend ta réponse. Réponds-lui, ou porte sa question au responsable en le lui disant, puis termine ton tour.',
112
- ...neuves.map(q =>
113
- q.interrompu
114
- ? `- ${q.ticket} a fini sans son issue, à ${q.etape} : \`${q.commande}\`.`
115
- : [
116
- `- ${q.ticket}, à ${q.etape}, au ${q.qui} : ${q.question.replace(/\n/g, '\n ')}`,
117
- ` La réponse : \`${q.commande}\`.`,
118
- ].join('\n')
119
- )
120
- );
121
- }
122
- if (etatNeuf) {
123
- blocs.push(
124
- `${blocs.length ? '\n' : ''}Ne te mets pas en attente : ${tournent.length > 1 ? `les circuits ${tournent.join(', ')} tournent` : `le circuit ${tournent[0]} tourne`} et aucune attente des questions ne vit pour ce dépôt, rien ne te réveillera à sa question ni à sa fin. Lance l'attente des questions en arrière-plan (\`run_in_background\`), sans tube ni veille à durée : \`npx grillhouse superviseur --attendre\`, et relance-la après chaque lot traité.`
125
- );
126
- }
127
- return blocs.join('\n');
92
+ return [
93
+ neuves.length > 1
94
+ ? `Ne te mets pas en attente : ${neuves.length} circuits attendent ta réponse. Réponds à chacun, ou porte sa question au responsable en le lui disant, puis termine ton tour.`
95
+ : 'Ne te mets pas en attente : un circuit attend ta réponse. Réponds-lui, ou porte sa question au responsable en le lui disant, puis termine ton tour.',
96
+ ...neuves.map(q =>
97
+ q.interrompu
98
+ ? `- ${q.ticket} a fini sans son issue, à ${q.etape} : \`${q.commande}\`.`
99
+ : [
100
+ `- ${q.ticket}, à ${q.etape}, au ${q.qui} : ${q.question.replace(/\n/g, '\n ')}`,
101
+ ` La réponse : \`${q.commande}\`.`,
102
+ ].join('\n')
103
+ ),
104
+ ].join('\n');
128
105
  }
129
106
 
130
107
  if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
@@ -1,35 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
  // The signal of the supervisor's turn: the hook UserPromptSubmit of the mod runs it at each turn
3
3
  // of a session of supervision (`npx grillhouse attente-au-tour`), and what it writes reaches the
4
- // session. A question of a circuit must never stay mute because the wait in the background died
5
- // unseen, as a review requested on GitHub is named again until it is answered.
4
+ // session. A question of a circuit must never stay mute, as a review requested on GitHub is named
5
+ // again until it is answered.
6
6
  //
7
7
  // - It names each circuit that waits for the supervisor (`questionsEnAttente`, the one source of
8
- // the opening and of the wait), a circuit ended without its issue included: its ticket, its
9
- // question, the command that answers it, then the wait to launch again.
10
- // - A question already gone up to the wait is named again: the file of the stops gone up is not
8
+ // the opening and of the greffon's reading), a circuit ended without its issue included: its
9
+ // ticket, its question, the command that answers it. It asks for no wait and reads no lock.
10
+ // - A question already pushed by the greffon is named again: the file of the stops gone up is not
11
11
  // read.
12
- // - A wait that lives says it all: its lock (`attente-des-questions.lock`) names a live process,
13
- // and nothing is said. A lock whose process is dead counts as no wait.
14
12
  // - Out of a git repository, in an agent's copy (a worktree) and in the session of a role that
15
13
  // the circuit launches (BEADS_ACTOR set), nothing is said.
16
14
  // Exit 0, whatever it finds.
17
15
  import { spawnSync } from 'node:child_process';
18
- import { readFileSync } from 'node:fs';
19
16
  import path from 'node:path';
20
17
  import { pathToFileURL } from 'node:url';
21
18
  import { circuitsDuServeur } from './circuits-du-serveur.mjs';
22
- import { vivant } from './mesure/base-de-passe.mjs';
23
- import { questionsEnAttente, ticketsHorsAttente, verrouDeLAttente } from './superviseur.mjs';
24
-
25
- // The process that the lock of the wait of the repository at <racine> names; null without a lock.
26
- function tenant(racine) {
27
- try {
28
- return Number(/^(\d+)/.exec(readFileSync(verrouDeLAttente(racine), 'utf8'))?.[1]) || null;
29
- } catch {
30
- return null;
31
- }
32
- }
19
+ import { questionsEnAttente, ticketsHorsAttente } from './superviseur.mjs';
33
20
 
34
21
  /**
35
22
  * The root of the repository whose session of supervision works in <dossier>: null out of a git
@@ -61,8 +48,8 @@ export function racineDeLaSupervision(dossier, env = process.env) {
61
48
 
62
49
  /**
63
50
  * What the session of supervision in <dossier> reads at its turn: the circuits that wait for the
64
- * supervisor, each with its ticket, its question and the command that answers it, then the wait to
65
- * launch again; empty when a wait lives, when no circuit waits, or out of a session of supervision.
51
+ * supervisor, each with its ticket, its question and the command that answers it; empty when no
52
+ * circuit waits, or out of a session of supervision.
66
53
  * @param {string} dossier the directory the session works in
67
54
  * @param {{ env?: Record<string, string | undefined>,
68
55
  * fermes?: (racine: string, ids: string[]) => Set<string> | null,
@@ -77,10 +64,6 @@ export async function attenteAuTour(
77
64
  if (!racine) {
78
65
  return '';
79
66
  }
80
- const vit = tenant(racine);
81
- if (vit && vivant(vit)) {
82
- return '';
83
- }
84
67
  let circuits;
85
68
  try {
86
69
  circuits = await circuitsDe(racine);
@@ -103,7 +86,6 @@ export async function attenteAuTour(
103
86
  ` La réponse : \`${q.commande}\`.`,
104
87
  ].join('\n')
105
88
  ),
106
- 'Aucune attente de fond ne vit : lance-la en arrière-plan (`run_in_background`), sans tube ni veille à durée, et relance-la après chaque lot traité : `npx grillhouse superviseur --attendre`.',
107
89
  ].join('\n');
108
90
  }
109
91
 
@@ -9,14 +9,7 @@
9
9
  // (scripts/langages/typescript/verifier.mjs). The directory holds `passe.json` (`{ genre, debut,
10
10
  // precedent, totaux }`: its kind, its start, the total of the previous pass of that kind, and
11
11
  // the file of the totals where its end keeps its own), the records of its tasks (`taches/`, written by the reporter of progress of the base configuration, one
12
- // per run of Vitest, and by the queue for the steps of its CI, scripts/integration/file.mjs),
13
- // and the plans of its runs of Turborepo (`plan/`).
14
- // - The CI of a ticket's commit is read by one act at a time, each a process of its own: its
15
- // readings share one progress directory in the working directory of the ticket,
16
- // `avancement-ci` (`avancementDeLaCI`), opened by the first and emptied when a reading looks
17
- // for a run again (another CI, after a reopening), where the board reads the steps
18
- // of the run done over planned while the circuit waits for it; the next pass of the circuit
19
- // removes it with the others (`avecLAvancementDuTravail`).
12
+ // per run of Vitest), and the plans of its runs of Turborepo (`plan/`).
20
13
  // - The reading adds the records: the files done, and the files planned of the tasks started;
21
14
  // while every task the plans name has not started, the total of the previous pass of the same
22
15
  // kind stands when it is greater (a pass without a plan never knows all its tasks started).
@@ -34,7 +27,7 @@
34
27
  // progress directory in the file of its part (`nommerLAvancement`); the board reads the parts
35
28
  // held with their progress, and the waits for a part or for room (`lireLaMesure`).
36
29
  import { spawnSync } from 'node:child_process';
37
- import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs';
30
+ import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs';
38
31
  import { tmpdir } from 'node:os';
39
32
  import path from 'node:path';
40
33
  import { AVANCEMENT, ecrireAtomique, TACHES } from './mesure/avancement.mjs';
@@ -198,35 +191,6 @@ export function avancementDuTravail(travail) {
198
191
  );
199
192
  }
200
193
 
201
- /**
202
- * The progress directory of the readings of the CI of a ticket's commit, in the working directory
203
- * <travail> of its circuit, where the board reads it (`avancementDuTravail`): one for all its
204
- * readings, opened by the first, emptied when <nouvelle> (a reading that looks for its run, the
205
- * records of another run gone); null when the circuit has no working directory.
206
- * @param {string} travail
207
- * @param {{ nouvelle?: boolean, debut?: number }} [o]
208
- * @returns {string | null}
209
- */
210
- export function avancementDeLaCI(travail, { nouvelle = false, debut = Date.now() } = {}) {
211
- if (!existsSync(travail)) {
212
- return null;
213
- }
214
- const dossier = path.join(travail, `${PREFIXE}ci`);
215
- try {
216
- if (nouvelle) {
217
- rmSync(dossier, { recursive: true, force: true });
218
- }
219
- if (!existsSync(path.join(dossier, PASSE))) {
220
- mkdirSync(dossier, { recursive: true });
221
- ecrireAtomique(path.join(dossier, PASSE), { genre: null, debut, precedent: null });
222
- }
223
- } catch {
224
- // A directory that does not write leaves the queue going, without its progress.
225
- return null;
226
- }
227
- return dossier;
228
- }
229
-
230
194
  /**
231
195
  * Runs <passe> under a progress directory of the kind <genre> (null: none kept) opened in the
232
196
  * working directory <travail> of a ticket's circuit, where the board reads it
@@ -13,34 +13,31 @@
13
13
  // alone. It is a mark, not a secret: a human who sets it is trusted.
14
14
  // - Exit 0 lets the push go on; exit 1 refuses it, the reason on the standard error.
15
15
  //
16
- // The judged main: in a project whose CI runs on the ticket branches (`agent/**`,
17
- // scripts/ci-des-branches.mjs), a push to origin of the branch main is pushed to
18
- // (`grillhouse.poussee.commit`, `main` by default) carries only a commit a run of the CI concluded
19
- // green on a ticket branch, as bors and the merge queues enter only a tree already judged
20
- // (`refusSurMain`). The queue pushes such a commit; any other change goes by its ticket branch
21
- // first. The ruleset of the repository on GitHub holds the same rule on the server; a reading of
22
- // the runs that fails lets the push go, the server judging it.
23
- import { execFileSync, spawnSync } from 'node:child_process';
16
+ // The judged main: a push to origin of the branch main is pushed to (`grillhouse.poussee.commit`,
17
+ // `main` by default) carries only a commit whose tree a final pass of the circuit, or the
18
+ // verification of a lot of the direct way, judged green (scripts/arbres-juges.mjs), as bors and the
19
+ // merge queues enter only a tree already judged (`refusSurMain`), in every project. The queue
20
+ // pushes such a commit; the CI of main plays after, by batches. No CI of a ticket's branch is asked.
21
+ import { execFileSync } from 'node:child_process';
24
22
  import { existsSync, readFileSync } from 'node:fs';
25
23
  import path from 'node:path';
26
24
  import { pathToFileURL } from 'node:url';
27
- import { ecouteLesBranchesDeTicket } from './ci-des-branches.mjs';
25
+ import { commitEstJuge } from './arbres-juges.mjs';
28
26
  import { lireCommit, lirePoussee } from './poussee-cles.mjs';
29
27
 
30
28
  // A sha of zeros: the deletion of the remote branch.
31
29
  const SUPPRESSION = /^0+$/;
32
30
 
33
31
  /**
34
- * The refusals for a push to `remote` of `refs` to the branch `principale` of a project that
35
- * `ecoute` the ticket branches: each commit <jugee(sha)> does not say judged green on a ticket
36
- * branch is refused, named.
32
+ * The refusals for a push to `remote` of `refs` to the branch `principale`: each commit
33
+ * <jugee(sha)> does not say judged by a final pass or a verification is refused, named.
37
34
  * @param {string} remote
38
35
  * @param {{ sha: string, distante: string }[]} refs
39
- * @param {{ principale: string | null, ecoute: boolean, jugee: (sha: string) => boolean }} o
36
+ * @param {{ principale: string | null, jugee: (sha: string) => boolean }} o
40
37
  * @returns {string[]}
41
38
  */
42
- export function refusSurMain(remote, refs, { principale, ecoute, jugee }) {
43
- if (remote !== 'origin' || !ecoute || !principale) {
39
+ export function refusSurMain(remote, refs, { principale, jugee }) {
40
+ if (remote !== 'origin' || !principale) {
44
41
  return [];
45
42
  }
46
43
  return refs
@@ -48,37 +45,10 @@ export function refusSurMain(remote, refs, { principale, ecoute, jugee }) {
48
45
  .filter(r => !jugee(r.sha))
49
46
  .map(
50
47
  r =>
51
- `⛔ ${r.sha.slice(0, 8)} n'est jugé vert par la CI d'aucune branche de ticket : main n'avance que sur un arbre jugé. Pousse d'abord sur agent/<ticket>, attends sa CI verte, puis avance main sur ce commit.`
48
+ `⛔ ${r.sha.slice(0, 8)} n'est jugé vert par aucune passe finale ni vérification de lot : main n'avance que sur un arbre jugé. Joue \`npm run verifier\` sur ce commit (lot direct), ou laisse la file du circuit jouer sa passe finale.`
52
49
  );
53
50
  }
54
51
 
55
- /**
56
- * Whether one of the runs <runs> of a commit (`gh run list --json headBranch,conclusion`)
57
- * concluded green on a ticket branch. The conclusion is read run by run: the status filter of
58
- * GitHub's API lags its runs by minutes (grillhouse-do5e).
59
- * @param {{ headBranch?: string, conclusion?: string }[]} runs
60
- */
61
- export const jugeeDansLesRuns = runs =>
62
- runs.some(x => x.conclusion === 'success' && String(x.headBranch).startsWith('agent/'));
63
-
64
- // Whether a run of the CI concluded green on the commit <sha> on a ticket branch, read by gh in
65
- // <racine>; true when gh does not answer (the server's ruleset judges then).
66
- function jugeeParGh(racine, sha) {
67
- const r = spawnSync('gh', ['run', 'list', '--commit', sha, '--json', 'headBranch,conclusion'], {
68
- cwd: racine,
69
- encoding: 'utf8',
70
- timeout: 30_000,
71
- });
72
- if (r.status !== 0) {
73
- return true;
74
- }
75
- try {
76
- return jugeeDansLesRuns(JSON.parse(r.stdout || '[]'));
77
- } catch {
78
- return true;
79
- }
80
- }
81
-
82
52
  // The refusals for a push to `remote` of `refs` (the lines git writes) given the package.json
83
53
  // object `pkg`; an empty list lets the push go on.
84
54
  export function refus(remote, refs, pkg, env = process.env) {
@@ -117,8 +87,7 @@ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
117
87
  ...refus(process.argv[2], refs, pkg),
118
88
  ...refusSurMain(process.argv[2], refs, {
119
89
  principale: pkg ? lireCommit(pkg).commit : null,
120
- ecoute: ecouteLesBranchesDeTicket(racine),
121
- jugee: sha => jugeeParGh(racine, sha),
90
+ jugee: sha => commitEstJuge(racine, sha),
122
91
  }),
123
92
  ];
124
93
  for (const l of lignes) {
@@ -0,0 +1,273 @@
1
+ // The CI of main, read after the lots entered, as Google's TAP plays the whole suite after the
2
+ // submit, by batches of changes, and a red looks for its culprit among the lots entered since the
3
+ // last green. A lot enters main on its final pass (scripts/integration/file.mjs); the CI plays on
4
+ // main on an hourly schedule, and this module reads it:
5
+ //
6
+ // - `lireLaCiDeMain`: the latest finished pass of each workflow of the branch (`gh run list`),
7
+ // green when every one succeeded, red as soon as one failed (any conclusion but `success` and
8
+ // `cancelled`: a cancelled pass is replaced by a later one, the one before it decides), and not
9
+ // read, never silence, when gh fails, does not start, answers garbage or no pass at all.
10
+ // - `lotsDepuisLeVert`: the lots of the circuit between the last green and the tip, by git alone
11
+ // (the commits whose subject ends with « (<ticket>) »), no state kept.
12
+ // - `alerteDeLaCiDeMain` and `ligneDeLaCiDeMain`: what is told to the supervisor and shown on the
13
+ // board; a green gives no alert, it clears.
14
+ // - `ouvrirLeDefautDeMain`: the defect ticket a red opens under `a-valider`, for the owner, which
15
+ // names the red pass and the candidate lots; the search of the culprit is that ticket, which the
16
+ // supervisor launches in the circuit. A lot already closed stays closed.
17
+ import { spawnSync } from 'node:child_process';
18
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
19
+ import path from 'node:path';
20
+ import { git, sortie } from './etat-du-depot.mjs';
21
+
22
+ const COURT = 7;
23
+ const court = sha => String(sha).slice(0, COURT);
24
+ const uneLigne = t => String(t).replace(/\s+/g, ' ').trim();
25
+
26
+ /**
27
+ * The CI of the branch <branche> (main by default) read with <o.gh> in <o.racine>: `{ etat: 'verte',
28
+ * commit, passage }`, `{ etat: 'rouge', flux, passage, commit, vert }` (the workflow, its red pass,
29
+ * the commit of that pass and the commit of the last green pass of the same workflow, null when it
30
+ * never succeeded) or `{ etat: 'non-lue', raison }`.
31
+ */
32
+ export function lireLaCiDeMain(o, { branche = 'main' } = {}) {
33
+ const r = o.gh([
34
+ 'run',
35
+ 'list',
36
+ '--branch',
37
+ branche,
38
+ '--limit',
39
+ '100',
40
+ '--json',
41
+ 'databaseId,status,conclusion,workflowName,headSha',
42
+ ]);
43
+ if (r.error) {
44
+ return { etat: 'non-lue', raison: `gh ne se lance pas (${r.error.code ?? r.error.message}).` };
45
+ }
46
+ if (r.status !== 0) {
47
+ return { etat: 'non-lue', raison: `gh run list refuse :\n${`${r.stderr}${r.stdout}`.trim()}` };
48
+ }
49
+ let passages;
50
+ try {
51
+ passages = JSON.parse(r.stdout || '[]');
52
+ } catch {
53
+ return {
54
+ etat: 'non-lue',
55
+ raison: `gh run list rend une sortie illisible :\n${r.stdout.trim()}`,
56
+ };
57
+ }
58
+ const finis = (Array.isArray(passages) ? passages : [])
59
+ .filter(
60
+ p =>
61
+ p?.databaseId &&
62
+ p.workflowName &&
63
+ p.status === 'completed' &&
64
+ p.conclusion !== 'cancelled'
65
+ )
66
+ .sort((a, b) => b.databaseId - a.databaseId);
67
+ if (finis.length === 0) {
68
+ return { etat: 'non-lue', raison: `aucun passage fini de la CI sur ${branche}.` };
69
+ }
70
+ const derniers = [...new Set(finis.map(p => p.workflowName))].map(nom =>
71
+ finis.find(p => p.workflowName === nom)
72
+ );
73
+ const rouge = derniers.find(p => p.conclusion !== 'success');
74
+ if (rouge) {
75
+ const vert = finis.find(p => p.workflowName === rouge.workflowName && p.conclusion === 'success');
76
+ return {
77
+ etat: 'rouge',
78
+ flux: rouge.workflowName,
79
+ passage: String(rouge.databaseId),
80
+ commit: rouge.headSha,
81
+ vert: vert?.headSha ?? null,
82
+ };
83
+ }
84
+ const tete = derniers[0];
85
+ return { etat: 'verte', commit: tete.headSha, passage: String(tete.databaseId) };
86
+ }
87
+
88
+ // The ticket a subject « … (<ticket>) » of the circuit's commits ends with, null otherwise.
89
+ const TICKET = /\(([A-Za-z0-9]+-[A-Za-z0-9.]+)\)\s*$/;
90
+
91
+ /**
92
+ * The lots of the circuit entered on main since the last green <vert> up to <pointe>, oldest first:
93
+ * `{ commit, ticket, titre }`, read by git in <racine>. Empty at the last green itself, without a
94
+ * last green, or when it is no ancestor of the tip (a history rewritten) or unknown.
95
+ */
96
+ export function lotsDepuisLeVert(racine, { vert, pointe }) {
97
+ if (!vert || vert === pointe) {
98
+ return [];
99
+ }
100
+ if (git(racine, ['merge-base', '--is-ancestor', vert, pointe]).status !== 0) {
101
+ return [];
102
+ }
103
+ const l = sortie(racine, ['log', '--reverse', '--format=%H%x09%s', `${vert}..${pointe}`]);
104
+ if (!l) {
105
+ return [];
106
+ }
107
+ return l
108
+ .split('\n')
109
+ .map(ligne => {
110
+ const [commit, ...reste] = ligne.split('\t');
111
+ const titre = reste.join('\t');
112
+ const ticket = TICKET.exec(titre)?.[1];
113
+ return ticket ? { commit, ticket, titre } : null;
114
+ })
115
+ .filter(Boolean);
116
+ }
117
+
118
+ /**
119
+ * What a reading tells the supervisor: `{ genre, cle, texte }`, null for a green (the alert clears).
120
+ * A red names the workflow, its pass, its commit and each lot <lots> entered since the last green;
121
+ * a CI not read is the alert « CI de main non lue ».
122
+ */
123
+ export function alerteDeLaCiDeMain(lecture, lots) {
124
+ if (lecture.etat === 'verte') {
125
+ return null;
126
+ }
127
+ if (lecture.etat === 'non-lue') {
128
+ return {
129
+ genre: 'non-lue',
130
+ cle: 'non-lue',
131
+ texte: `CI de main non lue : ${uneLigne(lecture.raison)} Main n'est pas jugé tant que la CI ne se lit pas ; la file continue.`,
132
+ };
133
+ }
134
+ const depuis = lecture.vert
135
+ ? lots.length
136
+ ? `Lots entrés depuis le dernier vert (${court(lecture.vert)}) : ${lots.map(l => l.ticket).join(', ')}.`
137
+ : `aucun lot du circuit entré depuis le dernier vert (${court(lecture.vert)}).`
138
+ : 'aucun vert connu pour ce flux : les lots entrés ne se nomment pas.';
139
+ return {
140
+ genre: 'rouge',
141
+ cle: `rouge ${lecture.passage}`,
142
+ texte: `CI de main rouge : ${lecture.flux}, passage ${lecture.passage} (commit ${court(lecture.commit)}). ${depuis} La file continue d'avancer main ; la recherche du coupable est le ticket de défaut ouvert pour le responsable.`,
143
+ };
144
+ }
145
+
146
+ /** The line of the board: the last green, the red with its workflow, pass and last green, or the CI not read. */
147
+ export function ligneDeLaCiDeMain(lecture) {
148
+ if (lecture.etat === 'verte') {
149
+ return `CI de main verte (${court(lecture.commit)})`;
150
+ }
151
+ if (lecture.etat === 'non-lue') {
152
+ return `CI de main non lue : ${uneLigne(lecture.raison)}`;
153
+ }
154
+ return `CI de main rouge : ${lecture.flux}, passage ${lecture.passage}, dernier vert ${lecture.vert ? court(lecture.vert) : 'aucun vert'}`;
155
+ }
156
+
157
+ const A_VALIDER = 'a-valider';
158
+ const titreDuDefaut = l => `CI de main rouge — ${l.flux}, passage ${l.passage}`;
159
+
160
+ /**
161
+ * The defect ticket a red <lecture> opens under `a-valider` with the tools <o> (`bd` of the
162
+ * project): its title names the workflow and the red pass, its description the commit and each
163
+ * candidate lot <lots>. One ticket per pass, closed or not: a pass that already has its ticket opens
164
+ * none, and `doublon` names it. A green or a CI not read opens none (the alert says it, no defect is
165
+ * proven). `{ ouvert, doublon?, faute? }`: a creation Beads refuses is a fault named.
166
+ */
167
+ export function ouvrirLeDefautDeMain(o, lecture, lots) {
168
+ if (lecture.etat !== 'rouge') {
169
+ return { ouvert: false };
170
+ }
171
+ const titre = titreDuDefaut(lecture);
172
+ const existants = o.bd('list', '--all', '--label', A_VALIDER, '--limit', '0', '--json');
173
+ if (existants.status === 0) {
174
+ try {
175
+ const l = JSON.parse(existants.stdout || '[]');
176
+ const deja = (Array.isArray(l) ? l : []).find(t => t?.title === titre);
177
+ if (deja) {
178
+ return { ouvert: false, doublon: deja.id };
179
+ }
180
+ } catch {
181
+ // A list that does not read opens the ticket: a doublon is the lesser fault.
182
+ }
183
+ }
184
+ const candidats = lots.length
185
+ ? lots.map(l => `- ${l.ticket} (${court(l.commit)}) : ${l.titre}`).join('\n')
186
+ : "- aucun lot du circuit entré depuis le dernier vert (ou aucun vert connu).";
187
+ const description = [
188
+ `Le flux ${lecture.flux} de la CI de main est rouge : passage ${lecture.passage}, commit ${court(lecture.commit)}${lecture.vert ? `, dernier vert ${court(lecture.vert)}` : ', aucun vert connu'}.`,
189
+ '',
190
+ 'Lots candidats (entrés sur main depuis le dernier vert) :',
191
+ candidats,
192
+ '',
193
+ 'La recherche du coupable est ce ticket, que le superviseur lance dans le circuit. Un lot fautif déjà fermé reste fermé : son correctif ou son retrait est un ticket neuf. Ce défaut reste ouvert tant que ce ticket n’est pas fermé.',
194
+ ].join('\n');
195
+ const r = o.bd(
196
+ 'create',
197
+ titre,
198
+ '--type',
199
+ 'bug',
200
+ '--labels',
201
+ A_VALIDER,
202
+ '--description',
203
+ description,
204
+ '--silent'
205
+ );
206
+ if (r.status !== 0) {
207
+ return {
208
+ ouvert: false,
209
+ faute: `bd create refuse : ${uneLigne(`${r.stderr ?? ''}${r.stdout ?? ''}`)}`,
210
+ };
211
+ }
212
+ return { ouvert: true };
213
+ }
214
+
215
+ // The GitHub CLI run in the main tree <racine>.
216
+ export const ghDans =
217
+ racine =>
218
+ (args, options = {}) =>
219
+ spawnSync('gh', args, {
220
+ cwd: racine,
221
+ encoding: 'utf8',
222
+ maxBuffer: 64 * 1024 * 1024,
223
+ timeout: 30_000,
224
+ ...options,
225
+ });
226
+
227
+ // How long a reading of the CI of main stays as read, for the board and the greffon, which ask
228
+ // again and again: the CI plays hourly, GitHub need not be asked at each refresh.
229
+ const VALIDITE_DE_LA_LECTURE = 5 * 60_000;
230
+
231
+ /**
232
+ * The CI of main of the project at <racine> as the board and the supervisor read it, kept for five
233
+ * minutes in `.claude/worktrees/ci-de-main-lue.json`; null for a project with no CI to read (no
234
+ * workflow in its main tree, no remote `origin`), which shows and says nothing.
235
+ */
236
+ export function ciDeMainGardee(
237
+ racine,
238
+ { maintenant = Date.now(), gh = ghDans(racine), validite = VALIDITE_DE_LA_LECTURE } = {}
239
+ ) {
240
+ if (!existsSync(path.join(racine, '.github', 'workflows')) || !sortie(racine, ['remote', 'get-url', 'origin'])) {
241
+ return null;
242
+ }
243
+ const f = path.join(racine, '.claude', 'worktrees', 'ci-de-main-lue.json');
244
+ try {
245
+ const lu = JSON.parse(readFileSync(f, 'utf8'));
246
+ if (lu?.lecture && maintenant - lu.a < validite) {
247
+ return lu.lecture;
248
+ }
249
+ } catch {
250
+ // none yet, or unreadable: read again
251
+ }
252
+ const lecture = lireLaCiDeMain({ racine, gh });
253
+ try {
254
+ mkdirSync(path.dirname(f), { recursive: true });
255
+ writeFileSync(f, `${JSON.stringify({ a: maintenant, lecture })}\n`);
256
+ } catch {
257
+ // not kept: the next reading asks again
258
+ }
259
+ return lecture;
260
+ }
261
+
262
+ /**
263
+ * The alert of a <lecture> of the CI of the project at <racine>, its lots named by git up to the
264
+ * tip of its main tree: `{ genre, cle, texte }`, null for a green.
265
+ */
266
+ export function alerteDuProjet(racine, lecture) {
267
+ if (lecture.etat !== 'rouge') {
268
+ return alerteDeLaCiDeMain(lecture, []);
269
+ }
270
+ const pointe = sortie(racine, ['rev-parse', 'HEAD']);
271
+ const lots = pointe ? lotsDepuisLeVert(racine, { vert: lecture.vert, pointe }) : [];
272
+ return alerteDeLaCiDeMain(lecture, lots);
273
+ }