@roomi-fields/grillhouse 0.46.0 → 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 (64) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +14 -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/CLAUDE.md +6 -0
  6. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  7. package/charte.md +17 -9
  8. package/dist/temporal/circuit/client.d.ts +14 -5
  9. package/dist/temporal/circuit/client.js +39 -9
  10. package/dist/temporal/circuit/client.js.map +1 -1
  11. package/dist/temporal/file/activites.d.ts +2 -0
  12. package/dist/temporal/file/activites.js +7 -0
  13. package/dist/temporal/file/activites.js.map +1 -1
  14. package/dist/temporal/file/contrat.d.ts +26 -18
  15. package/dist/temporal/file/contrat.js +8 -5
  16. package/dist/temporal/file/contrat.js.map +1 -1
  17. package/dist/temporal/file/deroule.d.ts +1 -1
  18. package/dist/temporal/file/deroule.js +91 -42
  19. package/dist/temporal/file/deroule.js.map +1 -1
  20. package/dist/temporal/tickets/activites.js +4 -13
  21. package/dist/temporal/tickets/activites.js.map +1 -1
  22. package/docs/ARCHITECTURE.md +117 -82
  23. package/docs/INTERFACE.md +36 -19
  24. package/hooks/register.tsx +1 -1
  25. package/package.json +1 -1
  26. package/scripts/activites.mjs +5 -11
  27. package/scripts/arbres-juges.mjs +59 -0
  28. package/scripts/avancement.mjs +2 -38
  29. package/scripts/branche-de-nuit.mjs +14 -45
  30. package/scripts/ci-de-main.mjs +273 -0
  31. package/scripts/dernier-vert.mjs +12 -8
  32. package/scripts/etapes.mjs +1 -1
  33. package/scripts/faits-du-circuit.mjs +41 -25
  34. package/scripts/integration/file.mjs +126 -587
  35. package/scripts/integration/integrer.mjs +6 -5
  36. package/scripts/langages/c/binaires.json +4 -0
  37. package/scripts/langages/c/binaires.mjs +83 -0
  38. package/scripts/langages/c/clang-format.mjs +62 -0
  39. package/scripts/langages/c/clang-tidy.mjs +93 -0
  40. package/scripts/langages/c/clang.mjs +42 -0
  41. package/scripts/langages/c/commandes.mjs +530 -0
  42. package/scripts/langages/c/composants.mjs +209 -0
  43. package/scripts/langages/c/exemples.mjs +250 -0
  44. package/scripts/langages/c/index-interfaces.mjs +77 -0
  45. package/scripts/langages/c/index.mjs +120 -0
  46. package/scripts/langages/c/lot.mjs +41 -0
  47. package/scripts/langages/c/mise-a-jour.mjs +70 -0
  48. package/scripts/langages/c/squelette.mjs +61 -0
  49. package/scripts/langages/c/verdict.mjs +99 -0
  50. package/scripts/langages/typescript/turbo-des-paquets.mjs +16 -5
  51. package/scripts/langages-des-paquets.mjs +30 -2
  52. package/scripts/langages.mjs +1 -0
  53. package/scripts/mesure/avancement.mjs +1 -1
  54. package/scripts/migrations/0.47.0-ci-de-main.mjs +48 -0
  55. package/scripts/migrations.mjs +2 -2
  56. package/scripts/session-start.sh +0 -9
  57. package/scripts/sortie.mjs +1 -1
  58. package/scripts/superviseur.mjs +146 -88
  59. package/scripts/tableau.mjs +23 -8
  60. package/skills/grill/SKILL.md +6 -5
  61. package/skills/pitmaster/SKILL.md +9 -7
  62. package/skills/redacteur/references/documents-d-un-composant.md +1 -1
  63. package/scripts/ci-des-branches.mjs +0 -93
  64. package/scripts/migrations/0.33.0-ci-des-branches-de-ticket.mjs +0 -31
@@ -27,7 +27,6 @@ import {
27
27
  import path from 'node:path';
28
28
  import { avecLAvancementDuTravail } from './avancement.mjs';
29
29
  import { A_REPASSER, MEMOIRE_COUPEE } from './codes-de-sortie.mjs';
30
- import { ecouteLesBranchesDeTicket } from './ci-des-branches.mjs';
31
30
  import { BASE_DU_LOT, DEPUIS_LE_VERT } from './dernier-vert.mjs';
32
31
  import { empreinteDEtape } from './empreinte-d-etape.mjs';
33
32
  import { BASE as GARDES_DE_LA_BASE, FICHIER as DETTE } from './dette.mjs';
@@ -1476,17 +1475,12 @@ function npm(ctx, etape, args, env = {}, cwd = ctx.copie) {
1476
1475
  }
1477
1476
 
1478
1477
  // What the passes of the circuit (its proof, its checks, its final pass) measure their tests
1479
- // against, as variables of their environment: in a project whose CI runs on a ticket's branch
1480
- // (`ecouteLesBranchesDeTicket` of scripts/ci-des-branches.mjs, read in the copy), the base of the
1481
- // lot (`GRILLHOUSE_BASE_DU_LOT`: the copy's HEAD, which main reached green by that CI), against
1482
- // which each package plays the tests related to the lot, targeted (scripts/dernier-vert.mjs), and
1483
- // the complete pass is the CI's of the ticket's branch and the night's, as Google's presubmit plays
1484
- // the tests a change affects and leaves the rest to after the submit; else none: the passes
1485
- // measure themselves against the last green, as `npm run verifier`.
1478
+ // against, as variables of their environment, in every project: the base of the lot
1479
+ // (`GRILLHOUSE_BASE_DU_LOT`: the copy's HEAD, the tip of main of its time), against which each
1480
+ // package plays the tests related to the lot, targeted (scripts/dernier-vert.mjs), and the complete
1481
+ // pass is the CI of main's and the night's, as Google's presubmit plays the tests a change affects
1482
+ // and leaves the rest to after the submit.
1486
1483
  export function mesureDesPasses(ctx) {
1487
- if (!ecouteLesBranchesDeTicket(ctx.copie)) {
1488
- return {};
1489
- }
1490
1484
  const base = laBase(ctx);
1491
1485
  return base ? { [BASE_DU_LOT]: base } : {};
1492
1486
  }
@@ -0,0 +1,59 @@
1
+ // The trees judged by a final pass: the file `<git common dir>/grillhouse/arbres-juges.json`, beside
2
+ // the last green, keeps the tree each final pass of the circuit (the queue's, on the lot laid on the
3
+ // tip of main) and each complete verification of a lot of the direct way judged green. The pre-push
4
+ // hook (scripts/branche-de-nuit.mjs) lets a commit go to main only when its tree is there, as bors
5
+ // and the merge queues enter only a tree already judged. A tree is judged whatever the commit that
6
+ // holds it: an amended or replayed commit of a judged tree is judged too.
7
+ //
8
+ // The file is shared by the copies (worktrees) of the repository, as the common directory is, and
9
+ // is written whole, atomically; a path out of git keeps nothing and judges nothing, and never throws.
10
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
11
+ import path from 'node:path';
12
+ import { sortie } from './etat-du-depot.mjs';
13
+
14
+ // The file of the repository at <racine>, null out of git.
15
+ function fichier(racine) {
16
+ const commun = sortie(racine, ['rev-parse', '--path-format=absolute', '--git-common-dir']);
17
+ return commun ? path.join(commun, 'grillhouse', 'arbres-juges.json') : null;
18
+ }
19
+
20
+ // The trees kept, in the order they were kept.
21
+ function lire(racine) {
22
+ const f = fichier(racine);
23
+ if (!f) {
24
+ return [];
25
+ }
26
+ try {
27
+ const l = JSON.parse(readFileSync(f, 'utf8'));
28
+ return Array.isArray(l) ? l.filter(a => typeof a === 'string') : [];
29
+ } catch {
30
+ return [];
31
+ }
32
+ }
33
+
34
+ /** Whether the tree <arbre> was kept as judged green, in the repository at <racine>. */
35
+ export function arbreEstJuge(racine, arbre) {
36
+ return lire(racine).includes(arbre);
37
+ }
38
+
39
+ /** The tree <arbre> kept as judged green; a tree already kept changes nothing, a path out of git does nothing. */
40
+ export function garderLArbreJuge(racine, arbre) {
41
+ const f = fichier(racine);
42
+ if (!f) {
43
+ return;
44
+ }
45
+ const gardes = lire(racine);
46
+ if (gardes.includes(arbre)) {
47
+ return;
48
+ }
49
+ mkdirSync(path.dirname(f), { recursive: true });
50
+ const provisoire = `${f}.${process.pid}`;
51
+ writeFileSync(provisoire, `${JSON.stringify([...gardes, arbre], null, 2)}\n`);
52
+ renameSync(provisoire, f);
53
+ }
54
+
55
+ /** Whether the tree of the commit <commit> was judged; an unknown commit or a path out of git, never. */
56
+ export function commitEstJuge(racine, commit) {
57
+ const arbre = sortie(racine, ['rev-parse', '--verify', '-q', `${commit}^{tree}`]);
58
+ return arbre ? arbreEstJuge(racine, arbre) : false;
59
+ }
@@ -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
+ }
@@ -34,14 +34,14 @@
34
34
  // removes at its end.
35
35
  // - `npm test` measures itself against the last green under the circuit's mark,
36
36
  // `GRILLHOUSE_DEPUIS_LE_VERT` (scripts/langages/typescript/tests.mjs, scripts/circuit.mjs); it never keeps one.
37
- // - The circuit's passes, in a project whose CI runs on a ticket's branch, measure themselves
38
- // against the base of their lot (`lot`, the variable `GRILLHOUSE_BASE_DU_LOT` that the circuit
39
- // gives to `npm test` and `npm run verifier`): the copy's HEAD, which main reached green by that
40
- // CI, as Google's presubmit plays the tests a change affects. Their changes carry the mark
37
+ // - The circuit's passes, in every project, measure themselves against the base of their lot
38
+ // (`lot`, the variable `GRILLHOUSE_BASE_DU_LOT` that the circuit gives to `npm test` and
39
+ // `npm run verifier`, and the queue to its final pass): the copy's HEAD, the tip of main of its
40
+ // time, as Google's presubmit plays the tests a change affects. Their changes carry the mark
41
41
  // `cible`: each package plays the tests Vitest relates to them, a file out of its graph playing
42
42
  // neither the whole package nor the tests that read it by its path
43
- // (scripts/langages/typescript/vitest-config/changements.mjs); the complete pass is the CI's and
44
- // the night's. Such a pass keeps no green.
43
+ // (scripts/langages/typescript/vitest-config/changements.mjs); the complete pass is the CI's of
44
+ // main and the night's. Such a pass keeps no green.
45
45
  // - Only the measure of the changed files and the keeping of the green live here: the files go to
46
46
  // `vitest --changed`, and no module of language chooses the packages it plays by the last green
47
47
  // (the tests of a crate or a Python project are tasks of Turborepo, which its cache selects).
@@ -51,6 +51,7 @@ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'nod
51
51
  import { createRequire } from 'node:module';
52
52
  import os from 'node:os';
53
53
  import path from 'node:path';
54
+ import { garderLArbreJuge } from './arbres-juges.mjs';
54
55
  import { etatDuDepot, fichierSous, git, SHA, sortie } from './etat-du-depot.mjs';
55
56
  // The variable that names the file of the changes since the last green, which the runner of the
56
57
  // tests of the module of the language reads in each package.
@@ -122,8 +123,11 @@ function lireLaBase(etat, base) {
122
123
  return { commit, arbre, branche: null };
123
124
  }
124
125
 
125
- // Keeps <etat> (etatDuDepot) as the last green of its branch, of main when HEAD is detached.
126
+ // Keeps <etat> (etatDuDepot) as the last green of its branch, of main when HEAD is detached; its
127
+ // tree is judged too (scripts/arbres-juges.mjs): the complete verification of a lot of the direct
128
+ // way is what lets its commit go to main.
126
129
  export function garderLeVert(etat) {
130
+ garderLArbreJuge(etat.racine, etat.arbre);
127
131
  const branche = etat.branche ?? etat.main;
128
132
  const f = branche ? fichierDuVert(etat.racine, branche) : null;
129
133
  if (!f) {
@@ -296,7 +300,7 @@ export function mesure(racine, { tout = false, base, lot, dans = os.tmpdir() } =
296
300
  etat: donnee ? null : etat,
297
301
  env: { [CHANGEMENTS]: fichier },
298
302
  ligne: cible
299
- ? `↳ depuis la base du lot ${vert.commit.slice(0, 7)} : ${n} fichier(s) changé(s) ; chaque paquet rejoué joue les tests que ses changements atteignent, la passe complète à la CI de la branche et à la nuit.`
303
+ ? `↳ depuis la base du lot ${vert.commit.slice(0, 7)} : ${n} fichier(s) changé(s) ; chaque paquet rejoué joue les tests que ses changements atteignent, la passe complète à la CI de main et à la nuit.`
300
304
  : donnee
301
305
  ? `↳ depuis la base ${vert.commit.slice(0, 7)} : ${n} fichier(s) changé(s) ; chaque paquet rejoué joue les tests que ses changements atteignent.`
302
306
  : `↳ depuis le dernier vert de ${vert.branche} (${vert.commit.slice(0, 12)}, arbre ${vert.arbre.slice(0, 12)}) : ${n} fichier(s) changé(s) ; chaque paquet rejoué joue les tests que ses changements atteignent.`,
@@ -98,7 +98,7 @@ export const ETAPES = [
98
98
  etat: null,
99
99
  sous: [
100
100
  { numero: '5.1', titre: 'Commit', qui: [AUTO], etat: 'integration' },
101
- { numero: '5.2', titre: 'File : main, poussée, CI', qui: [AUTO], etat: 'file' },
101
+ { numero: '5.2', titre: 'File : passe finale, main', qui: [AUTO], etat: 'file' },
102
102
  // The tri of the discoveries of the ticket, on the lot entered on main (grillhouse-0yu.5).
103
103
  { numero: '5.3', titre: 'Tri des découvertes', qui: [EXPLORATEUR], etat: 'tri' },
104
104
  ],