@roomi-fields/grillhouse 0.48.0 → 0.49.1

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 (155) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +90 -0
  3. package/agents/direct.md +9 -0
  4. package/cadre/templates/projet/.github/workflows/ci.yml +11 -0
  5. package/cadre/templates/projet/.github/workflows/nuit.yml +15 -6
  6. package/cadre/templates/projet/CLAUDE.md +10 -6
  7. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  8. package/cadre/templates/turbo/paquets.json +3 -1
  9. package/cadre/templates/turbo/sans-paquets.json +3 -1
  10. package/charte.md +51 -14
  11. package/dist/temporal/acte.d.ts +9 -0
  12. package/dist/temporal/acte.js +43 -20
  13. package/dist/temporal/acte.js.map +1 -1
  14. package/dist/temporal/circuit/appel.d.ts +4 -1
  15. package/dist/temporal/circuit/appel.js +15 -1
  16. package/dist/temporal/circuit/appel.js.map +1 -1
  17. package/dist/temporal/circuit/client.d.ts +7 -1
  18. package/dist/temporal/circuit/client.js +54 -1
  19. package/dist/temporal/circuit/client.js.map +1 -1
  20. package/dist/temporal/circuit/commande.js +30 -57
  21. package/dist/temporal/circuit/commande.js.map +1 -1
  22. package/dist/temporal/circuit/contrat.d.ts +2 -1
  23. package/dist/temporal/circuit/contrat.js +2 -1
  24. package/dist/temporal/circuit/contrat.js.map +1 -1
  25. package/dist/temporal/circuit/deroule.js +9 -2
  26. package/dist/temporal/circuit/deroule.js.map +1 -1
  27. package/dist/temporal/file/contrat.d.ts +16 -2
  28. package/dist/temporal/file/contrat.js +27 -3
  29. package/dist/temporal/file/contrat.js.map +1 -1
  30. package/dist/temporal/file/deroule.js +4 -4
  31. package/dist/temporal/file/deroule.js.map +1 -1
  32. package/dist/temporal/nuits/activites.d.ts +1 -15
  33. package/dist/temporal/nuits/activites.js +3 -62
  34. package/dist/temporal/nuits/activites.js.map +1 -1
  35. package/dist/temporal/nuits/contrat.d.ts +3 -21
  36. package/dist/temporal/nuits/deroule.js +38 -74
  37. package/dist/temporal/nuits/deroule.js.map +1 -1
  38. package/dist/temporal/places/client.d.ts +3 -16
  39. package/dist/temporal/places/client.js +3 -26
  40. package/dist/temporal/places/client.js.map +1 -1
  41. package/dist/temporal/places/contrat.d.ts +15 -51
  42. package/dist/temporal/places/contrat.js +3 -13
  43. package/dist/temporal/places/contrat.js.map +1 -1
  44. package/dist/temporal/places/deroule.js +11 -61
  45. package/dist/temporal/places/deroule.js.map +1 -1
  46. package/dist/temporal/tickets/activites.js +4 -2
  47. package/dist/temporal/tickets/activites.js.map +1 -1
  48. package/dist/temporal/tickets/contrat.d.ts +2 -1
  49. package/docs/ARCHITECTURE.md +337 -120
  50. package/docs/CADRE.md +16 -13
  51. package/docs/INTERFACE.md +90 -25
  52. package/hooks/hooks.json +9 -0
  53. package/hooks/register.tsx +59 -5
  54. package/package.json +1 -1
  55. package/scripts/activites.mjs +271 -42
  56. package/scripts/aiguillage.mjs +4 -1
  57. package/scripts/bilan.mjs +125 -2
  58. package/scripts/circuit.mjs +233 -159
  59. package/scripts/circuits-cles.d.mts +3 -3
  60. package/scripts/circuits-cles.mjs +6 -5
  61. package/scripts/coeurs-dedies.mjs +4 -4
  62. package/scripts/commandes-composees.mjs +12 -5
  63. package/scripts/dette.d.ts +2 -1
  64. package/scripts/dette.mjs +49 -6
  65. package/scripts/direct.mjs +343 -0
  66. package/scripts/droits.mjs +26 -4
  67. package/scripts/effets.mjs +4 -4
  68. package/scripts/engendres.mjs +2 -1
  69. package/scripts/enveloppe/enveloppe.mjs +119 -18
  70. package/scripts/enveloppe/lancer.sh +14 -3
  71. package/scripts/enveloppe/paquets-du-plan.mjs +9 -0
  72. package/scripts/enveloppe/travail-de-la-copie.mjs +119 -21
  73. package/scripts/etapes.mjs +3 -3
  74. package/scripts/faits-du-circuit.mjs +12 -11
  75. package/scripts/fermeture-de-la-machine.d.mts +4 -4
  76. package/scripts/fermeture-de-la-machine.mjs +10 -20
  77. package/scripts/fichiers-nommes.mjs +27 -1
  78. package/scripts/file-des-tickets.d.mts +18 -1
  79. package/scripts/file-des-tickets.mjs +63 -15
  80. package/scripts/flux-de-la-nuit.mjs +38 -0
  81. package/scripts/grillhouse-maj.mjs +13 -25
  82. package/scripts/groupe-cles.d.mts +6 -0
  83. package/scripts/groupe-cles.mjs +29 -1
  84. package/scripts/integration/file.mjs +148 -37
  85. package/scripts/jointure.d.ts +20 -3
  86. package/scripts/journal-des-etats.d.mts +16 -0
  87. package/scripts/journal-des-etats.mjs +44 -2
  88. package/scripts/journal.mjs +3 -0
  89. package/scripts/langages/c/commandes.mjs +5 -5
  90. package/scripts/langages/c/composants.mjs +13 -5
  91. package/scripts/langages/cargo/commandes.mjs +5 -6
  92. package/scripts/langages/python/commandes.mjs +5 -5
  93. package/scripts/langages/python/composants.mjs +10 -2
  94. package/scripts/langages/typescript/composants.mjs +10 -3
  95. package/scripts/langages/typescript/consommateurs-arbitres.mjs +15 -3
  96. package/scripts/langages/typescript/construire.mjs +2 -0
  97. package/scripts/langages/typescript/exemples.mjs +33 -1
  98. package/scripts/langages/typescript/index.mjs +19 -0
  99. package/scripts/langages/typescript/migrations/0.49.0-tests-equipes.mjs +32 -0
  100. package/scripts/langages/typescript/tests-de-nuit.mjs +158 -32
  101. package/scripts/langages/typescript/tests-du-poste.mjs +112 -32
  102. package/scripts/langages/typescript/titres-de-tests.mjs +11 -7
  103. package/scripts/langages/typescript/turbo-des-paquets.mjs +21 -4
  104. package/scripts/langages/typescript/verifier.mjs +3 -5
  105. package/scripts/langages/typescript/verrou-des-dependances.mjs +161 -0
  106. package/scripts/langages/typescript/vitest-config/cibles.mjs +57 -6
  107. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +11 -5
  108. package/scripts/langages/typescript/vitest.nuit.config.mjs +53 -5
  109. package/scripts/machine.mjs +1 -1
  110. package/scripts/mesure/base-de-passe.mjs +2 -1
  111. package/scripts/migrations/0.49.0-reservation-de-trois-coeurs.mjs +30 -0
  112. package/scripts/migrations.mjs +2 -0
  113. package/scripts/nuit.sh +129 -3
  114. package/scripts/paquet.mjs +16 -5
  115. package/scripts/paquets.d.ts +4 -0
  116. package/scripts/paquets.mjs +57 -0
  117. package/scripts/passe-de-la-machine.mjs +4 -7
  118. package/scripts/places-de-la-machine.mjs +55 -42
  119. package/scripts/places-du-serveur.mjs +2 -2
  120. package/scripts/plafond-de-la-machine.d.mts +7 -13
  121. package/scripts/plafond-de-la-machine.mjs +19 -35
  122. package/scripts/prefixe-des-tickets.mjs +1 -1
  123. package/scripts/references-changees.mjs +159 -0
  124. package/scripts/regles-des-places.d.mts +8 -31
  125. package/scripts/regles-des-places.mjs +14 -64
  126. package/scripts/repli-de-la-nuit.mjs +183 -0
  127. package/scripts/reponses-du-circuit.d.mts +2 -2
  128. package/scripts/reponses-du-circuit.mjs +21 -12
  129. package/scripts/reprise.mjs +27 -8
  130. package/scripts/resultats.mjs +21 -9
  131. package/scripts/seances.mjs +258 -40
  132. package/scripts/services-du-noyau.mjs +4 -0
  133. package/scripts/sous-commandes.mjs +24 -7
  134. package/scripts/superviseur.mjs +185 -39
  135. package/scripts/tableau.mjs +226 -94
  136. package/scripts/taches-du-graphe.mjs +84 -4
  137. package/scripts/ticket.mjs +348 -0
  138. package/scripts/transitions.d.mts +44 -0
  139. package/scripts/transitions.mjs +188 -17
  140. package/scripts/un-commit-par-ticket.mjs +4 -3
  141. package/scripts/verdict-de-la-nuit.mjs +47 -20
  142. package/scripts/verrou-de-fichier.mjs +2 -2
  143. package/scripts/verrous/ecriture-hors-enveloppe.mjs +86 -0
  144. package/scripts/verrous/verrou.mjs +17 -1
  145. package/skills/architecte/SKILL.md +203 -0
  146. package/skills/architecte/references/exemple-d-architecture.md +159 -0
  147. package/skills/developpeur/SKILL.md +1 -1
  148. package/skills/direct/SKILL.md +57 -0
  149. package/skills/explorateur/SKILL.md +10 -6
  150. package/skills/pitmaster/SKILL.md +37 -14
  151. package/skills/pitmaster/references/consigne-agent.md +7 -1
  152. package/skills/redacteur/references/documents-d-un-composant.md +2 -1
  153. package/skills/relecteur/SKILL.md +8 -0
  154. package/skills/testwriter/SKILL.md +10 -0
  155. package/scripts/ticket.sh +0 -25
@@ -0,0 +1,159 @@
1
+ // The difference of the reference files a lot changes, as the review of a snapshot (the snapshots
2
+ // of Jest and insta, the review of the goldens of Chromium) shows the difference of each file:
3
+ // measured by git between the base of the lot and the lot kept (`git diff --numstat`), summarised
4
+ // by name of field for a JSON file, so that the reviewer judges the change of a reference on the
5
+ // tree, not on what the agent declares.
6
+ import { spawnSync } from 'node:child_process';
7
+ import { couvertPar } from './engendres.mjs';
8
+
9
+ // The most fields the text of a difference lists per file, the rest counted.
10
+ const CHAMPS_MAX = 40;
11
+
12
+ const objet = v => v !== null && typeof v === 'object' && !Array.isArray(v);
13
+
14
+ const egales = (a, b) => JSON.stringify(a) === JSON.stringify(b);
15
+
16
+ /**
17
+ * The difference of two JSON texts by name of field: `[{ champ, changees, ajoutees, retirees }]`,
18
+ * the fields whose values changed, were added or removed (an object descended into by its keys, a
19
+ * list by its positions, its extra or missing elements counted under the name of the list), in the
20
+ * order they first appear; an empty list for two equal documents; null when a text is no JSON.
21
+ * @param {string} avant
22
+ * @param {string} apres
23
+ * @returns {{ champ: string, changees: number, ajoutees: number, retirees: number }[] | null}
24
+ */
25
+ export function resumeJson(avant, apres) {
26
+ let a;
27
+ let b;
28
+ try {
29
+ a = JSON.parse(avant);
30
+ b = JSON.parse(apres);
31
+ } catch {
32
+ return null;
33
+ }
34
+ const champs = new Map();
35
+ const compter = (nom, sorte, n = 1) => {
36
+ const c = champs.get(nom) ?? { champ: nom, changees: 0, ajoutees: 0, retirees: 0 };
37
+ c[sorte] += n;
38
+ champs.set(nom, c);
39
+ };
40
+ const descendre = (x, y, nom) => {
41
+ if (Array.isArray(x) && Array.isArray(y)) {
42
+ for (let i = 0; i < Math.min(x.length, y.length); i++) {
43
+ descendre(x[i], y[i], nom);
44
+ }
45
+ if (y.length > x.length) {
46
+ compter(nom, 'ajoutees', y.length - x.length);
47
+ } else if (x.length > y.length) {
48
+ compter(nom, 'retirees', x.length - y.length);
49
+ }
50
+ } else if (objet(x) && objet(y)) {
51
+ for (const k of new Set([...Object.keys(x), ...Object.keys(y)])) {
52
+ if (!(k in y)) {
53
+ compter(k, 'retirees');
54
+ } else if (!(k in x)) {
55
+ compter(k, 'ajoutees');
56
+ } else {
57
+ descendre(x[k], y[k], k);
58
+ }
59
+ }
60
+ } else if (!egales(x, y)) {
61
+ compter(nom, 'changees');
62
+ }
63
+ };
64
+ descendre(a, b, '(racine)');
65
+ return [...champs.values()];
66
+ }
67
+
68
+ const git = (copie, args) =>
69
+ spawnSync('git', ['-C', copie, ...args], { encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
70
+
71
+ // The text of <fichier> at <commit>, or null when it is not there.
72
+ const texteA = (copie, commit, fichier) => {
73
+ const r = git(copie, ['show', `${commit}:${fichier}`]);
74
+ return r.status === 0 ? r.stdout : null;
75
+ };
76
+
77
+ /**
78
+ * The reference files the lot changes, measured by git between <base> and <lot> in <copie>: each
79
+ * `{ fichier, ajoutees, retirees, champs }`, its lines added and removed, and for a JSON file
80
+ * present on both sides its fields (`resumeJson`), else null. A reference file is one that a
81
+ * reference of <references> (`lesReferences`: `fichiers` and `entiers`) covers.
82
+ * @param {{ copie: string, references: { fichiers: string[], entiers?: string[] }[], base: string, lot: string }} o
83
+ * @returns {{ fichier: string, ajoutees: number, retirees: number, champs: { champ: string, changees: number, ajoutees: number, retirees: number }[] | null }[]}
84
+ */
85
+ export function differencesDesReferences({ copie, references, base, lot }) {
86
+ const motifs = references.flatMap(r => [...(r.fichiers ?? []), ...(r.entiers ?? [])]);
87
+ if (!motifs.length) {
88
+ return [];
89
+ }
90
+ const r = git(copie, ['diff', '--numstat', '--no-renames', '-z', base, lot]);
91
+ if (r.status !== 0) {
92
+ return [];
93
+ }
94
+ const sorties = [];
95
+ for (const entree of r.stdout.split('\0')) {
96
+ const m = /^(\d+|-)\t(\d+|-)\t(.+)$/s.exec(entree);
97
+ if (!m || !couvertPar(motifs, m[3])) {
98
+ continue;
99
+ }
100
+ const fichier = m[3];
101
+ let champs = null;
102
+ if (fichier.endsWith('.json')) {
103
+ const avant = texteA(copie, base, fichier);
104
+ const apres = texteA(copie, lot, fichier);
105
+ champs = avant !== null && apres !== null ? resumeJson(avant, apres) : null;
106
+ }
107
+ sorties.push({
108
+ fichier,
109
+ ajoutees: m[1] === '-' ? 0 : Number(m[1]),
110
+ retirees: m[2] === '-' ? 0 : Number(m[2]),
111
+ champs,
112
+ });
113
+ }
114
+ return sorties.sort((x, y) => x.fichier.localeCompare(y.fichier));
115
+ }
116
+
117
+ const ligneDuChamp = c =>
118
+ `${c.champ} : ${[
119
+ c.changees && `${c.changees} changées`,
120
+ c.ajoutees && `${c.ajoutees} ajoutées`,
121
+ c.retirees && `${c.retirees} retirées`,
122
+ ]
123
+ .filter(Boolean)
124
+ .join(', ')}`;
125
+
126
+ /**
127
+ * The text the reviewer reads: each changed reference file with its lines (`+a −b`) and, for a
128
+ * JSON file, a line per field; « aucun » when the lot changes no reference.
129
+ * @param {{ fichier: string, ajoutees: number, retirees: number, champs: any[] | null }[]} diffs
130
+ */
131
+ export function texteDesDifferences(diffs) {
132
+ if (!diffs.length) {
133
+ return 'aucun';
134
+ }
135
+ return diffs
136
+ .map(d => {
137
+ const champs = d.champs ?? [];
138
+ const reste = champs.length - CHAMPS_MAX;
139
+ return [
140
+ `- ${d.fichier} (+${d.ajoutees} −${d.retirees})`,
141
+ ...champs.slice(0, CHAMPS_MAX).map(c => ` - ${ligneDuChamp(c)}`),
142
+ ...(reste > 0 ? [` - … ${reste} autres champs`] : []),
143
+ ].join('\n');
144
+ })
145
+ .join('\n');
146
+ }
147
+
148
+ /**
149
+ * The line of the commit message: « Références changées (N) : <fichier> (+a −b), … », empty when
150
+ * the lot changes no reference.
151
+ * @param {{ fichier: string, ajoutees: number, retirees: number }[]} diffs
152
+ */
153
+ export function ligneDesReferences(diffs) {
154
+ return diffs.length
155
+ ? `Références changées (${diffs.length}) : ${diffs
156
+ .map(d => `${d.fichier} (+${d.ajoutees} −${d.retirees})`)
157
+ .join(', ')}`
158
+ : '';
159
+ }
@@ -5,8 +5,6 @@
5
5
  export const MEMOIRE_MIN: number;
6
6
 
7
7
  export const VARIABLE_ESPACEMENT: string;
8
- /** The jeton of the reservation of the machine by the night, which the passes of the night carry. */
9
- export const VARIABLE_JETON: string;
10
8
  /** The gap between two starts when GRILLHOUSE_ESPACEMENT_MS names none, in ms. */
11
9
  export const ESPACEMENT_MS: number;
12
10
  /** The gap between two starts under <env>, in ms. */
@@ -35,10 +33,9 @@ export function refusDeLaPlace(
35
33
  rang: number;
36
34
  ticket?: string | null;
37
35
  raison?: string;
38
- jeton?: string | null;
39
36
  }[];
40
37
  dernier: number;
41
- reservation?: { jeton: string; auteur?: 'nuit' | 'superviseur' } | null;
38
+ reservation?: ReservationDeLaMachine | null;
42
39
  },
43
40
  o: {
44
41
  id: string;
@@ -47,7 +44,6 @@ export function refusDeLaPlace(
47
44
  espacementMs: number;
48
45
  maintenant: number;
49
46
  mesurer: () => MesureDeLaMachine;
50
- jeton?: string | null;
51
47
  }
52
48
  ): string | null;
53
49
 
@@ -90,46 +86,27 @@ export function refusDePart(
90
86
  mesurer: () => MesureDeLaMachine;
91
87
  dediee?: boolean;
92
88
  /** The reservation of the machine read this turn, null without. */
93
- reservation?: { auteur?: 'nuit' | 'superviseur'; jeton: string } | null;
94
- /** The jeton of the night the pass carries (its variable), null without. */
95
- jeton?: string | null;
89
+ reservation?: ReservationDeLaMachine | null;
96
90
  }
97
91
  ): string | null;
98
92
 
99
93
  /** Why a pass waits under the supervisor's closure of the machine. */
100
94
  export const RAISON_DE_LA_FERMETURE: string;
101
- /** Why a pass without the jeton of the night waits under its reservation. */
102
- export const RAISON_DE_LA_NUIT: string;
103
95
 
104
96
  /** A place of a circuit not given by its project's queue for this long is gone, in ms: 10 min. */
105
97
  export const PERIME_MS: number;
106
98
 
107
- /** The reservation of the machine: the night's (absent author) or the supervisor's closure. */
99
+ /** The reservation of the machine: the supervisor's closure, the only one. */
108
100
  export interface ReservationDeLaMachine {
109
- auteur?: 'nuit' | 'superviseur';
110
- jeton: string;
101
+ auteur?: 'superviseur';
111
102
  depuis: number;
112
- /** The night's last beat; the supervisor's closure has none. */
113
- battement?: number;
114
103
  }
115
104
 
116
- /** The phase of a reservation: none without one, waiting, under way (night) or empty (closure). */
105
+ /** The phase of the closure: none without one, waiting (a place is held) or empty. */
117
106
  export function phaseDeLaReservation(etat: {
118
- prises: readonly { id?: string; jeton?: string | null }[];
119
- reservation?: { jeton: string; auteur?: 'nuit' | 'superviseur' } | null;
120
- }): 'attend' | 'en cours' | 'vide' | null;
121
-
122
- /** The phase of the night on the places: none without a reservation or under a closure. */
123
- export function phaseDeLaNuit(etat: {
124
- prises: readonly { id?: string; jeton?: string | null }[];
125
- reservation?: { jeton: string; auteur?: 'nuit' | 'superviseur' } | null;
126
- }): 'attend' | 'en cours' | null;
127
-
128
- /** Whether a reservation's last beat is PERIME_MS old at <maintenant>; a closure never is. */
129
- export function reservationPerimee(
130
- reservation: { battement?: number; auteur?: 'nuit' | 'superviseur' },
131
- maintenant: number
132
- ): boolean;
107
+ prises: readonly object[];
108
+ reservation?: ReservationDeLaMachine | null;
109
+ }): 'attend' | 'vide' | null;
133
110
 
134
111
  /** Why a place waits under the supervisor's closure. */
135
112
  export const RAISON_FERMEE: string;
@@ -10,8 +10,6 @@
10
10
  export const MEMOIRE_MIN = 4 * 1024 ** 3;
11
11
 
12
12
  export const VARIABLE_ESPACEMENT = 'GRILLHOUSE_ESPACEMENT_MS';
13
- /** The jeton of the reservation of the machine by the night, which the passes of the night carry. */
14
- export const VARIABLE_JETON = 'GRILLHOUSE_JETON_DE_LA_NUIT';
15
13
  /** Why a place waits under the closure of the machine by the supervisor (`cordon` of kubectl). */
16
14
  export const RAISON_FERMEE =
17
15
  'machine fermée par le superviseur : la place est donnée à la réouverture';
@@ -81,24 +79,16 @@ export function admission({ coeurs, charge, memoireLibre }) {
81
79
  */
82
80
  export function refusDeLaPlace(
83
81
  etat,
84
- { id, rang, plafond, espacementMs, maintenant, mesurer, jeton = null }
82
+ { id, rang, plafond, espacementMs, maintenant, mesurer }
85
83
  ) {
86
- const reservation = etat.reservation ?? null;
87
- // The supervisor's closure gives no place to anyone, its own jeton included: no pass nor session
88
- // carries it.
89
- if (reservation?.auteur === 'superviseur') {
84
+ // The supervisor's closure, the only reservation of the machine, gives no place to anyone.
85
+ if (etat.reservation) {
90
86
  return RAISON_FERMEE;
91
87
  }
92
- if (reservation && jeton !== reservation.jeton) {
93
- return 'la nuit tient la machine : la place est donnée à la fin des nuits';
94
- }
95
88
  if (etat.prises.length >= plafond) {
96
89
  return `aucune place libre : ${etat.prises.length} prises sur ${plafond}`;
97
90
  }
98
- // Under a reservation, only the waits of the night count for the turn: the others wait for it.
99
- const avant = etat.attentes.find(
100
- a => a.id !== id && a.rang < rang && (!reservation || (a.jeton ?? null) === reservation.jeton)
101
- );
91
+ const avant = etat.attentes.find(a => a.id !== id && a.rang < rang);
102
92
  if (avant) {
103
93
  return `place réservée : ${avant.ticket ?? 'un départ'} est arrivé avant et attend (${avant.raison})`;
104
94
  }
@@ -166,16 +156,13 @@ export function admissionDePart({ part, budget, prises, mesure }) {
166
156
 
167
157
  /** Why a pass waits under the supervisor's closure of the machine. */
168
158
  export const RAISON_DE_LA_FERMETURE = 'machine fermée par le superviseur';
169
- /** Why a pass without the jeton of the night waits under its reservation. */
170
- export const RAISON_DE_LA_NUIT = 'la nuit tient la machine';
171
159
 
172
160
  /**
173
161
  * Why the pass <id> of the rank <rang> does not take its part <part> now on the state <etat>
174
162
  * (`prises`, `attentes`), null when it does: its part does not fit in the <budget>; a wait of a
175
163
  * lower rank, alive, which keeps its turn (the measure of the frame has the lower rank of a
176
164
  * project's, then the order of arrival); the admission at the load and the memory <mesurer> gives
177
- * (read only when the part and the turn pass). The night asks for the whole budget as its part: it
178
- * plays alone. A measure of time (<dediee>) asks for dedicated cores: when they lack, its refusal
165
+ * (read only when the part and the turn pass). A measure of time (<dediee>) asks for dedicated cores: when they lack, its refusal
179
166
  * says « cœurs dédiés » and names the passes that hold them; a pass that comes after it waits
180
167
  * behind it, its rank reserved, and one measure plays at a time, whatever its part would fit in the free cores; once it plays, an
181
168
  * ordinary pass whose part fits in the cores left goes on.
@@ -188,17 +175,11 @@ export const RAISON_DE_LA_NUIT = 'la nuit tient la machine';
188
175
  */
189
176
  export function refusDePart(
190
177
  etat,
191
- { id, rang, part, budget, mesurer, dediee = false, reservation = null, jeton = null }
178
+ { id, rang, part, budget, mesurer, dediee = false, reservation = null }
192
179
  ) {
193
- // A closed machine gives no new work (`cordon` of kubectl): the supervisor's closure refuses
194
- // every pass, whatever its jeton; the night's reservation refuses the pass without its jeton.
180
+ // A closed machine gives no new work (`cordon` of kubectl): the supervisor's closure refuses every pass.
195
181
  if (reservation) {
196
- if (reservation.auteur === 'superviseur') {
197
- return RAISON_DE_LA_FERMETURE;
198
- }
199
- if (jeton !== reservation.jeton) {
200
- return RAISON_DE_LA_NUIT;
201
- }
182
+ return RAISON_DE_LA_FERMETURE;
202
183
  }
203
184
  const prises = etat.prises.filter(p => p.id !== id);
204
185
  // Two measures of time never play side by side: each would be the load the other is judged on.
@@ -226,50 +207,19 @@ export function refusDePart(
226
207
  export const PERIME_MS = 10 * 60_000;
227
208
 
228
209
  /**
229
- * The phase of a reservation of the machine, whoever its author: null without a reservation;
230
- * `'attend'` while a place is held that is not one of the night's passes (the stages under way
231
- * finish); then `'en cours'` for the night, `'vide'` for the supervisor's closure (it holds no
232
- * place itself: every place held waits to be given back).
233
- * @param {{ prises: { jeton?: string | null }[],
234
- * reservation?: { jeton: string, auteur?: 'nuit' | 'superviseur' } | null }} etat
235
- * @returns {'attend' | 'en cours' | 'vide' | null}
210
+ * The phase of the supervisor's closure of the machine: null without one; `'attend'` while a place
211
+ * is held (the stages under way finish); then `'vide'` (it holds no place itself: every place held
212
+ * waits to be given back).
213
+ * @param {{ prises: object[], reservation?: object | null }} etat
214
+ * @returns {'attend' | 'vide' | null}
236
215
  */
237
216
  export function phaseDeLaReservation({ prises, reservation = null }) {
238
217
  if (!reservation) {
239
218
  return null;
240
219
  }
241
- if (reservation.auteur === 'superviseur') {
242
- return prises.length > 0 ? 'attend' : 'vide';
243
- }
244
- return prises.some(p => (p.jeton ?? null) !== reservation.jeton) ? 'attend' : 'en cours';
220
+ return prises.length > 0 ? 'attend' : 'vide';
245
221
  }
246
222
 
247
- /**
248
- * The phase of the night on a state of the places: that of its reservation, null without one or
249
- * when the reservation is the supervisor's closure, which is not a night.
250
- * @param {{ prises: { jeton?: string | null }[],
251
- * reservation?: { jeton: string, auteur?: 'nuit' | 'superviseur' } | null }} etat
252
- * @returns {'attend' | 'en cours' | null}
253
- */
254
- export function phaseDeLaNuit(etat) {
255
- if (etat.reservation?.auteur === 'superviseur') {
256
- return null;
257
- }
258
- const phase = phaseDeLaReservation(etat);
259
- return phase === 'vide' ? null : phase;
260
- }
261
-
262
- /**
263
- * Whether a reservation of the machine is out of date at <maintenant>: its last beat, the one the
264
- * workflow of the nights renews, is PERIME_MS old, as a place of a circuit is. The supervisor's
265
- * closure has no beat and never goes out of date, as `cordon` has no delay.
266
- * @param {{ battement?: number, auteur?: 'nuit' | 'superviseur' }} reservation
267
- * @param {number} maintenant
268
- * @returns {boolean}
269
- */
270
- export const reservationPerimee = (reservation, maintenant) =>
271
- reservation.auteur !== 'superviseur' && maintenant - (reservation.battement ?? 0) >= PERIME_MS;
272
-
273
223
  /**
274
224
  * The places of the circuits of the machine once a demand comes, as Buildkite bounds its pipelines
275
225
  * in one fleet of agents. The queue of the project <racine> gives its circuits active <vivants>
@@ -0,0 +1,183 @@
1
+ // The fallback of the night of Grillhouse: the night of PC3 (scripts/nuit.sh) reads, by `gh`, the jobs
2
+ // of the day's Nuit flow, and decides tranche by tranche what PC3 plays in place of PC2, as a queue
3
+ // of agents falls back on another capacity (Buildkite) when no agent takes the job in time.
4
+ //
5
+ // - A tranche finished on PC2, green or red, is never replayed.
6
+ // - A tranche whose job has not started 60 minutes after the hour of the flow is cancelled and
7
+ // played on PC3, on its part; a tranche started then interrupted (cancelled, a runner lost, never
8
+ // started) counts as not played and plays whole again.
9
+ // - A tranche that runs, or waits for less than 60 minutes, stays at PC2.
10
+ // - The statement says which tranches played where: `pc2` the finished ones, `pc3` the replayed.
11
+ // - The measures of time: when the project's flow declares a job that plays them (`mesures`, see
12
+ // scripts/flux-de-la-nuit.mjs), the statement says its state (`mesures`: `verte`, `rouge`, `en-cours`,
13
+ // or `a-rejouer` when the job was interrupted or never came and the flow is over: PC3 plays them).
14
+ // - The flow read is the one of the commit the night plays: a run of another commit counts for none,
15
+ // and with no run of that commit every tranche, and the measures, play on PC3.
16
+ //
17
+ // node repli-de-la-nuit.mjs <dépôt owner/nom> <nombre de tranches> [<identifiant du flux>] [<commit>] the
18
+ // decision as JSON, the run cancelled (`gh run cancel`) when a tranche waited too long; a run that
19
+ // waits for its group of concurrence, with no job yet, counts every tranche as not started
20
+ import { spawnSync } from 'node:child_process';
21
+ import { fileURLToPath } from 'node:url';
22
+ import path from 'node:path';
23
+
24
+ /** The minutes a tranche may wait for its job to start before PC3 plays it. */
25
+ export const ATTENTE_MAX_MINUTES = 60;
26
+
27
+ const MESURES = /^mesures\b/;
28
+ const TRANCHE = /^tranches\b.*?(\d+)\)\s*$/;
29
+ // The conclusions of a job that started or was cancelled without finishing its tranche.
30
+ const INTERROMPUES = new Set(['cancelled', 'skipped', 'startup_failure']);
31
+
32
+ /**
33
+ * The decision on the tranches of a Nuit flow.
34
+ * @param {{ jobs: { name: string, status: string, conclusion: string | null, startedAt: string | null }[], heureDuFlux: string, maintenant: string, fluxTermine?: boolean }} o
35
+ * `jobs` the jobs of the run as `gh run view --json jobs` gives them, `heureDuFlux` the hour the
36
+ * flow was created, `maintenant` the present hour, both ISO, `fluxTermine` whether the run is over.
37
+ * @returns {{ aRejouer: number[], aAnnuler: number[], enAttente: number[], pc2: number[], pc3: number[], mesures: 'verte' | 'rouge' | 'en-cours' | 'a-rejouer' }}
38
+ */
39
+ export function choisirLeRepli({ jobs, heureDuFlux, maintenant, fluxTermine = false }) {
40
+ const attente = Date.parse(maintenant) - Date.parse(heureDuFlux);
41
+ const d = {
42
+ aRejouer: [],
43
+ aAnnuler: [],
44
+ enAttente: [],
45
+ enCours: [],
46
+ rouges: [],
47
+ pc2: [],
48
+ pc3: [],
49
+ };
50
+ const tranches = jobs
51
+ .map(j => ({ j, n: Number(TRANCHE.exec(j.name)?.[1]) }))
52
+ .filter(({ n }) => Number.isInteger(n) && n > 0)
53
+ .sort((a, b) => a.n - b.n);
54
+ for (const { j, n } of tranches) {
55
+ if (j.status === 'completed') {
56
+ if (INTERROMPUES.has(j.conclusion ?? '')) {
57
+ d.aRejouer.push(n);
58
+ } else {
59
+ d.pc2.push(n);
60
+ if (j.conclusion !== 'success') {
61
+ d.rouges.push(n);
62
+ }
63
+ }
64
+ } else if (j.startedAt || j.status === 'in_progress') {
65
+ d.pc2.push(n);
66
+ d.enCours.push(n);
67
+ } else if (attente >= ATTENTE_MAX_MINUTES * 60_000) {
68
+ d.aAnnuler.push(n);
69
+ d.aRejouer.push(n);
70
+ } else {
71
+ d.enAttente.push(n);
72
+ }
73
+ }
74
+ d.pc3 = [...d.aRejouer];
75
+ d.mesures = etatDesMesures(
76
+ jobs.find(j => MESURES.test(j.name)),
77
+ d.aAnnuler.length > 0 || fluxTermine
78
+ );
79
+ return d;
80
+ }
81
+
82
+ // The state of the measures job <j> of the flow: its verdict once finished, `en-cours` while it
83
+ // waits or runs, `a-rejouer` when it was interrupted, or never came and <termine> (the flow is over
84
+ // or cancelled).
85
+ function etatDesMesures(j, termine) {
86
+ if (!j) {
87
+ return termine ? 'a-rejouer' : 'en-cours';
88
+ }
89
+ if (j.status !== 'completed') {
90
+ return termine ? 'a-rejouer' : 'en-cours';
91
+ }
92
+ if (INTERROMPUES.has(j.conclusion ?? '')) {
93
+ return 'a-rejouer';
94
+ }
95
+ return j.conclusion === 'success' ? 'verte' : 'rouge';
96
+ }
97
+
98
+ function gh(args) {
99
+ const r = spawnSync('gh', args, { encoding: 'utf8' });
100
+ if (r.status !== 0) {
101
+ throw new Error(`gh ${args.join(' ')} : ${r.stderr || r.error?.message || r.status}`);
102
+ }
103
+ return r.stdout;
104
+ }
105
+
106
+ /**
107
+ * The id of the latest Nuit run of <commit> (any latest run when <commit> is empty), undefined when
108
+ * the flow has none for it.
109
+ */
110
+ function fluxDuCommit(depot, commit) {
111
+ const runs = JSON.parse(
112
+ gh([
113
+ 'run',
114
+ 'list',
115
+ '-R',
116
+ depot,
117
+ '--workflow',
118
+ 'nuit.yml',
119
+ '--limit',
120
+ '20',
121
+ '--json',
122
+ 'databaseId,headSha',
123
+ ])
124
+ );
125
+ return runs.find(r => !commit || r.headSha === commit)?.databaseId;
126
+ }
127
+
128
+ if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
129
+ const [depot, tranches, identifiant, commit] = process.argv.slice(2);
130
+ const n = Number(tranches) || 0;
131
+ // No run of the commit the night plays: the flow played none of it, PC3 plays every tranche.
132
+ const rien = () => {
133
+ const toutes = Array.from({ length: n }, (_, i) => i + 1);
134
+ return {
135
+ aRejouer: toutes,
136
+ aAnnuler: [],
137
+ enAttente: [],
138
+ enCours: [],
139
+ rouges: [],
140
+ pc2: [],
141
+ pc3: toutes,
142
+ mesures: 'a-rejouer',
143
+ };
144
+ };
145
+ try {
146
+ const id = identifiant || fluxDuCommit(depot, commit);
147
+ if (!id) {
148
+ process.stdout.write(`${JSON.stringify({ ...rien(), flux: null })}\n`);
149
+ } else {
150
+ const run = JSON.parse(
151
+ gh(['run', 'view', String(id), '-R', depot, '--json', 'jobs,createdAt,status,headSha'])
152
+ );
153
+ if (commit && run.headSha !== commit) {
154
+ process.stdout.write(`${JSON.stringify({ ...rien(), flux: null })}\n`);
155
+ } else {
156
+ // A run that waits for the group of concurrence has no job yet: each of its tranches is
157
+ // a job not started.
158
+ const jobs =
159
+ run.jobs.length === 0 && run.status !== 'completed'
160
+ ? Array.from({ length: Number(tranches) || 0 }, (_, i) => ({
161
+ name: `tranches (26.x, ${i + 1})`,
162
+ status: 'queued',
163
+ conclusion: null,
164
+ startedAt: null,
165
+ }))
166
+ : run.jobs;
167
+ const d = choisirLeRepli({
168
+ jobs,
169
+ heureDuFlux: run.createdAt,
170
+ maintenant: new Date().toISOString(),
171
+ fluxTermine: run.status === 'completed',
172
+ });
173
+ if (d.aAnnuler.length > 0) {
174
+ gh(['run', 'cancel', String(id), '-R', depot]);
175
+ }
176
+ process.stdout.write(`${JSON.stringify({ ...d, flux: id })}\n`);
177
+ }
178
+ }
179
+ } catch (e) {
180
+ process.stderr.write(`⛔ repli de la nuit : ${e.message}\n`);
181
+ process.exitCode = 1;
182
+ }
183
+ }
@@ -6,8 +6,8 @@ export const SANS_ISSUE: Set<string>;
6
6
  export function lesReponses(ticket: string, statut: string, ecrit: boolean): string;
7
7
  /** The hour `bd update --defer` receives for `--reporter <heure>`, and the phrase of its texts. */
8
8
  export function heureDuReport(heure: string, maintenant: Date): { defer: string; quand: string };
9
- /** The stops of the testwriter that `--mecanique` answers. */
10
- export const ARRETS_DU_TESTWRITER: string[];
9
+ /** The stops `--mecanique` answers, by the step they stand at: the testwriter's, the proof's. */
10
+ export const ARRETS_DE_LA_BASCULE: Record<string, string[]>;
11
11
  /** The sort of a ticket, as the plan says it (scripts/resultats.mjs `sorteDuPlan`). */
12
12
  export interface SorteDuTicket {
13
13
  genre: string;
@@ -1,14 +1,19 @@
1
1
  // The answers a circuit accepts from the supervisor, by the status of its workflow, with no input
2
2
  // nor output: the one rule the client (src/temporal/circuit/client.ts: its refusals and the
3
3
  // circuits it reads), the opening, the wait, the board and the line of a stop name; and the
4
- // answer `--mecanique`, which turns the sort of a ticket stopped on the testwriter.
5
- import { CODE, GESTE, TESTS } from './transitions.mjs';
4
+ // answer `--mecanique`, which turns the sort of a ticket stopped on the testwriter or on the proof
5
+ // of the red.
6
+ import { CODE, GESTE, PREUVE, TESTS } from './transitions.mjs';
6
7
 
7
8
  /** The statuses of a workflow ended without its issue. */
8
9
  export const SANS_ISSUE = new Set(['TERMINATED', 'FAILED', 'TIMED_OUT', 'CANCELLED']);
9
10
 
10
- /** The stops of the testwriter that `--mecanique` answers: his question, his blocked word. */
11
- export const ARRETS_DU_TESTWRITER = ['besoin', 'hors-portee'];
11
+ /**
12
+ * The stops `--mecanique` answers, by the step they stand at: the testwriter's question and his
13
+ * blocked word, and the proof of the red that refuses the lot of tests, both the sign that no
14
+ * honest test can turn red before the lot.
15
+ */
16
+ export const ARRETS_DE_LA_BASCULE = { [TESTS]: ['besoin', 'hors-portee'], [PREUVE]: ['preuve'] };
12
17
 
13
18
  /**
14
19
  * The answers accepted for the circuit of <ticket> whose workflow has the status <statut>, a state
@@ -28,16 +33,19 @@ export function lesReponses(ticket, statut, ecrit) {
28
33
  }
29
34
  const etendre = '--etendre <paquet>';
30
35
  const mecanique = '--mecanique [<commande>] --contexte <raison>';
36
+ // The question carried to the owner: it stays quiet until the circuit answers.
37
+ const chez = '--chez-le-responsable';
31
38
  return statut === 'RUNNING'
32
- ? `${circuit} --reprendre\`, \`${depuis}\`, \`${mecanique}\`, \`${etendre}\`, \`--reporter <heure>\` ou \`--arreter`
33
- : `${circuit} --reprendre\`, \`${depuis}\`, \`${mecanique}\` ou \`${etendre}`;
39
+ ? `${circuit} --reprendre\`, \`${depuis}\`, \`${mecanique}\`, \`${etendre}\`, \`--reporter <heure>\`, \`${chez}\` ou \`--arreter`
40
+ : `${circuit} --reprendre\`, \`${depuis}\`, \`${mecanique}\`, \`${etendre}\` ou \`${chez}`;
34
41
  }
35
42
 
36
43
  /**
37
44
  * The hour of a deferral (`--reporter <heure>`): a lone hour (`H:MM` or `HH:MM`, 0-23 and 00-59)
38
45
  * aims at its next occurrence in the machine's local time, today when strictly after <maintenant>
39
- * (to the second), else tomorrow, and is handed to `bd update --defer` as `AAAA-MM-JJ HH:MM`; any
40
- * other form goes to bd as written. `quand` is the phrase of the texts (« reportée <quand> »).
46
+ * (to the second), else tomorrow, and is handed to `bd update --defer` as `AAAA-MM-JJTHH:MM:00`,
47
+ * the form bd reads as that wall time (bd 1.2.2 reads `2026-11-22 14:00` as 11:22, the month and
48
+ * the day taken for the hour); any other form goes to bd as written. `quand` is the phrase of the texts (« reportée <quand> »).
41
49
  * @param {string} heure
42
50
  * @param {Date} maintenant
43
51
  * @returns {{ defer: string, quand: string }}
@@ -55,14 +63,15 @@ export function heureDuReport(heure, maintenant) {
55
63
  }
56
64
  const deux = (n) => String(n).padStart(2, '0');
57
65
  const hhmm = `${deux(cible.getHours())}:${deux(cible.getMinutes())}`;
58
- const defer = `${cible.getFullYear()}-${deux(cible.getMonth() + 1)}-${deux(cible.getDate())} ${hhmm}`;
66
+ const defer = `${cible.getFullYear()}-${deux(cible.getMonth() + 1)}-${deux(cible.getDate())}T${hhmm}:00`;
59
67
  return { defer, quand: demain ? `à demain ${hhmm}` : `au ${heure}` };
60
68
  }
61
69
 
62
70
  /**
63
71
  * The answer `--mecanique [<commande>] --contexte <raison>` to the stop <etat> (`{ etape, raison }`)
64
72
  * of a ticket of sort <sorte>: a refusal `{ refus }` unless the ticket is stopped on the testwriter
65
- * (his question or his blocked word) with a reason, its sort not already mechanical; else the sort
73
+ * (his question or his blocked word) or on the proof of the red (`ARRETS_DE_LA_BASCULE`) with a
74
+ * reason, its sort not already mechanical; else the sort
66
75
  * it becomes and the step the circuit resumes at, the plan kept as it is. With a <commande>, the
67
76
  * gesture a command plays: sort mécanique, 1.1. Without, the gesture written by hand: sort
68
77
  * comportement « inchangé », the developpeur writes and the existing suite makes the proof.
@@ -71,9 +80,9 @@ export function heureDuReport(heure, maintenant) {
71
80
  * @returns {{ refus: string } | { sorte: object, suivant: { etape: string } }}
72
81
  */
73
82
  export function reponseMecanique({ etat, sorte, commande, contexte }) {
74
- if (etat?.etape !== TESTS || !ARRETS_DU_TESTWRITER.includes(etat.raison ?? '')) {
83
+ if (!ARRETS_DE_LA_BASCULE[etat?.etape]?.includes(etat.raison ?? '')) {
75
84
  return {
76
- refus: `--mecanique répond à un arrêt du testwriter (besoin ou hors-portee) : le circuit est à ${etat?.etape ?? 'aucun état'}${etat?.raison ? `, arrêté sur ${etat.raison}` : ''}.`,
85
+ refus: `--mecanique répond à un arrêt du testwriter (besoin ou hors-portee) ou de la preuve du rouge (preuve) : le circuit est à ${etat?.etape ?? 'aucun état'}${etat?.raison ? `, arrêté sur ${etat.raison}` : ''}.`,
77
86
  };
78
87
  }
79
88
  const raison = String(contexte ?? '').trim();