@roomi-fields/grillhouse 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +769 -0
  3. package/agents/developpeur.md +0 -1
  4. package/agents/explorateur.md +0 -1
  5. package/agents/questionneur.md +0 -1
  6. package/agents/testwriter.md +0 -1
  7. package/bin/grillhouse.mjs +79 -18
  8. package/cadre/templates/projet/.github/workflows/ci.yml +2 -13
  9. package/cadre/templates/projet/CLAUDE.md +5 -1
  10. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  11. package/cadre/templates/projet/package.json +2 -2
  12. package/charte.md +24 -0
  13. package/dist/temporal/acte.d.ts +24 -0
  14. package/dist/temporal/acte.js +139 -0
  15. package/dist/temporal/acte.js.map +1 -0
  16. package/dist/temporal/attributs.d.ts +6 -0
  17. package/dist/temporal/attributs.js +15 -0
  18. package/dist/temporal/attributs.js.map +1 -0
  19. package/dist/temporal/circuit/activites.d.ts +13 -0
  20. package/dist/temporal/circuit/activites.js +33 -0
  21. package/dist/temporal/circuit/activites.js.map +1 -0
  22. package/dist/temporal/circuit/client.d.ts +72 -0
  23. package/dist/temporal/circuit/client.js +247 -0
  24. package/dist/temporal/circuit/client.js.map +1 -0
  25. package/dist/temporal/circuit/commande.d.ts +2 -0
  26. package/dist/temporal/circuit/commande.js +238 -0
  27. package/dist/temporal/circuit/commande.js.map +1 -0
  28. package/dist/temporal/circuit/contrat.d.ts +305 -0
  29. package/dist/temporal/circuit/contrat.js +30 -0
  30. package/dist/temporal/circuit/contrat.js.map +1 -0
  31. package/dist/temporal/circuit/deroule.d.ts +3 -0
  32. package/dist/temporal/circuit/deroule.js +540 -0
  33. package/dist/temporal/circuit/deroule.js.map +1 -0
  34. package/dist/temporal/client.d.ts +47 -0
  35. package/dist/temporal/client.js +69 -0
  36. package/dist/temporal/client.js.map +1 -0
  37. package/dist/temporal/commande.d.ts +2 -0
  38. package/dist/temporal/commande.js +94 -0
  39. package/dist/temporal/commande.js.map +1 -0
  40. package/dist/temporal/deroules.d.ts +5 -0
  41. package/dist/temporal/deroules.js +10 -0
  42. package/dist/temporal/deroules.js.map +1 -0
  43. package/dist/temporal/etat.d.ts +33 -0
  44. package/dist/temporal/etat.js +59 -0
  45. package/dist/temporal/etat.js.map +1 -0
  46. package/dist/temporal/file/activites.d.ts +10 -0
  47. package/dist/temporal/file/activites.js +25 -0
  48. package/dist/temporal/file/activites.js.map +1 -0
  49. package/dist/temporal/file/client.d.ts +4 -0
  50. package/dist/temporal/file/client.js +6 -0
  51. package/dist/temporal/file/client.js.map +1 -0
  52. package/dist/temporal/file/contrat.d.ts +158 -0
  53. package/dist/temporal/file/contrat.js +14 -0
  54. package/dist/temporal/file/contrat.js.map +1 -0
  55. package/dist/temporal/file/deroule.d.ts +15 -0
  56. package/dist/temporal/file/deroule.js +235 -0
  57. package/dist/temporal/file/deroule.js.map +1 -0
  58. package/dist/temporal/installation.d.ts +120 -0
  59. package/dist/temporal/installation.js +386 -0
  60. package/dist/temporal/installation.js.map +1 -0
  61. package/dist/temporal/places/activites.d.ts +8 -0
  62. package/dist/temporal/places/activites.js +13 -0
  63. package/dist/temporal/places/activites.js.map +1 -0
  64. package/dist/temporal/places/client.d.ts +28 -0
  65. package/dist/temporal/places/client.js +64 -0
  66. package/dist/temporal/places/client.js.map +1 -0
  67. package/dist/temporal/places/contrat.d.ts +106 -0
  68. package/dist/temporal/places/contrat.js +21 -0
  69. package/dist/temporal/places/contrat.js.map +1 -0
  70. package/dist/temporal/places/deroule.d.ts +3 -0
  71. package/dist/temporal/places/deroule.js +198 -0
  72. package/dist/temporal/places/deroule.js.map +1 -0
  73. package/dist/temporal/sonde/activites.d.ts +6 -0
  74. package/dist/temporal/sonde/activites.js +52 -0
  75. package/dist/temporal/sonde/activites.js.map +1 -0
  76. package/dist/temporal/sonde/contrat.d.ts +35 -0
  77. package/dist/temporal/sonde/contrat.js +10 -0
  78. package/dist/temporal/sonde/contrat.js.map +1 -0
  79. package/dist/temporal/sonde/deroule.d.ts +3 -0
  80. package/dist/temporal/sonde/deroule.js +39 -0
  81. package/dist/temporal/sonde/deroule.js.map +1 -0
  82. package/dist/temporal/tickets/activites.d.ts +7 -0
  83. package/dist/temporal/tickets/activites.js +81 -0
  84. package/dist/temporal/tickets/activites.js.map +1 -0
  85. package/dist/temporal/tickets/client.d.ts +10 -0
  86. package/dist/temporal/tickets/client.js +31 -0
  87. package/dist/temporal/tickets/client.js.map +1 -0
  88. package/dist/temporal/tickets/contrat.d.ts +56 -0
  89. package/dist/temporal/tickets/contrat.js +13 -0
  90. package/dist/temporal/tickets/contrat.js.map +1 -0
  91. package/dist/temporal/tickets/deroule.d.ts +3 -0
  92. package/dist/temporal/tickets/deroule.js +94 -0
  93. package/dist/temporal/tickets/deroule.js.map +1 -0
  94. package/dist/temporal/travailleur.d.ts +2 -0
  95. package/dist/temporal/travailleur.js +69 -0
  96. package/dist/temporal/travailleur.js.map +1 -0
  97. package/docs/ARCHITECTURE.md +646 -87
  98. package/docs/CADRE.md +27 -0
  99. package/docs/INTERFACE.md +139 -42
  100. package/hooks/crochet.mjs +19 -2
  101. package/hooks/hooks.json +11 -0
  102. package/package.json +16 -4
  103. package/scripts/activites.mjs +2255 -0
  104. package/scripts/aiguillage.d.mts +37 -0
  105. package/scripts/aiguillage.mjs +40 -14
  106. package/scripts/avancement.mjs +155 -26
  107. package/scripts/bilan.mjs +137 -43
  108. package/scripts/cadre.mjs +16 -4
  109. package/scripts/circuit.mjs +993 -4075
  110. package/scripts/circuits-cles.d.mts +4 -0
  111. package/scripts/circuits-cles.mjs +21 -0
  112. package/scripts/circuits-du-serveur.mjs +105 -0
  113. package/scripts/codes-de-sortie.mjs +9 -0
  114. package/scripts/commandes-composees.mjs +45 -41
  115. package/scripts/commandes-du-path.d.mts +7 -0
  116. package/scripts/commandes-du-path.mjs +25 -0
  117. package/scripts/composants-affectes.mjs +64 -21
  118. package/scripts/composition-des-langages.mjs +18 -12
  119. package/scripts/conformite.mjs +56 -28
  120. package/scripts/copies-finies.mjs +52 -47
  121. package/scripts/depart-du-ticket.d.mts +53 -0
  122. package/scripts/depart-du-ticket.mjs +124 -0
  123. package/scripts/dependances-internes.mjs +121 -0
  124. package/scripts/dernier-vert.mjs +61 -34
  125. package/scripts/dette.mjs +32 -11
  126. package/scripts/donnees-cles.mjs +244 -0
  127. package/scripts/droits.mjs +51 -16
  128. package/scripts/effets.mjs +352 -0
  129. package/scripts/empreinte-d-etape.mjs +17 -0
  130. package/scripts/engendres.mjs +15 -5
  131. package/scripts/enveloppe/enveloppe.mjs +259 -55
  132. package/scripts/enveloppe/lancer.sh +14 -18
  133. package/scripts/enveloppe/paquets-du-plan.mjs +2 -2
  134. package/scripts/enveloppe/travail-de-la-copie.mjs +41 -13
  135. package/scripts/etapes.mjs +5 -2
  136. package/scripts/faits-du-circuit.mjs +493 -0
  137. package/scripts/file-des-tickets.d.mts +21 -0
  138. package/scripts/file-des-tickets.mjs +58 -0
  139. package/scripts/flux-des-paquets.mjs +201 -0
  140. package/scripts/gardes-du-cadre.mjs +21 -5
  141. package/scripts/init.mjs +11 -4
  142. package/scripts/integration/file.mjs +544 -434
  143. package/scripts/integration/integrer.mjs +87 -43
  144. package/scripts/integration/rejeu.mjs +45 -13
  145. package/scripts/jointure.d.ts +151 -28
  146. package/scripts/langages/cargo/commandes.mjs +383 -124
  147. package/scripts/langages/cargo/composants.mjs +154 -42
  148. package/scripts/langages/cargo/exemples.mjs +12 -21
  149. package/scripts/langages/cargo/index.mjs +22 -8
  150. package/scripts/langages/cargo/sccache.mjs +8 -14
  151. package/scripts/langages/cargo/tests-de-head.mjs +25 -9
  152. package/scripts/langages/python/commandes.mjs +218 -100
  153. package/scripts/langages/python/composants.mjs +53 -21
  154. package/scripts/langages/python/exemples.mjs +6 -16
  155. package/scripts/langages/python/index.mjs +28 -8
  156. package/scripts/langages/python/lot.mjs +1 -36
  157. package/scripts/langages/typescript/chemins-des-tests.mjs +6 -2
  158. package/scripts/langages/typescript/composants.mjs +9 -3
  159. package/scripts/langages/typescript/consommateurs-arbitres.mjs +40 -14
  160. package/scripts/langages/typescript/consommateurs.mjs +39 -14
  161. package/scripts/langages/typescript/construire.mjs +6 -163
  162. package/scripts/langages/typescript/elements-du-lot.mjs +36 -12
  163. package/scripts/langages/typescript/exemples.mjs +3 -11
  164. package/scripts/langages/typescript/frontieres.mjs +66 -22
  165. package/scripts/langages/typescript/index-interfaces.mjs +36 -13
  166. package/scripts/langages/typescript/index.mjs +50 -61
  167. package/scripts/langages/typescript/interfaces-contre-code.mjs +113 -45
  168. package/scripts/langages/typescript/lecteurs.mjs +36 -11
  169. package/scripts/langages/typescript/migrations/0.23.0-config-vitest.mjs +15 -5
  170. package/scripts/langages/typescript/migrations/0.25.0-chemins-des-tests.mjs +6 -2
  171. package/scripts/langages/typescript/migrations/0.25.0-tailles-des-tests.mjs +6 -2
  172. package/scripts/langages/typescript/migrations/0.30.0-prefixe-des-tickets.mjs +63 -0
  173. package/scripts/langages/typescript/migrations/0.30.0-tailles-des-outils-lourds.mjs +33 -0
  174. package/scripts/langages/typescript/migrations/0.30.0-titres-nommant-un-ticket.mjs +40 -0
  175. package/scripts/langages/typescript/mise-a-jour.mjs +1 -2
  176. package/scripts/langages/typescript/parcours.mjs +12 -4
  177. package/scripts/langages/typescript/regle-des-tests.mjs +9 -3
  178. package/scripts/langages/typescript/resumes.mjs +9 -3
  179. package/scripts/langages/typescript/tailles-des-tests.mjs +93 -20
  180. package/scripts/langages/typescript/tests-de-nuit.mjs +15 -10
  181. package/scripts/langages/typescript/tests.mjs +40 -15
  182. package/scripts/langages/typescript/titres-de-tests.mjs +320 -0
  183. package/scripts/langages/typescript/turbo-des-paquets.mjs +327 -81
  184. package/scripts/langages/typescript/verdict.mjs +4 -2
  185. package/scripts/langages/typescript/verifier.mjs +58 -20
  186. package/scripts/langages/typescript/vitest-config/avancement.reporter.mjs +15 -5
  187. package/scripts/langages/typescript/vitest-config/base.mjs +29 -3
  188. package/scripts/langages/typescript/vitest-config/bornes.mjs +13 -0
  189. package/scripts/langages/typescript/vitest-config/changements.mjs +21 -8
  190. package/scripts/langages/typescript/vitest-config/cibles.mjs +36 -14
  191. package/scripts/langages/typescript/vitest-config/delais.mjs +60 -0
  192. package/scripts/langages/typescript/vitest-config/delais.setup.mjs +11 -0
  193. package/scripts/langages/typescript/vitest-config/duree.classement.mjs +108 -0
  194. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +56 -59
  195. package/scripts/langages/typescript/vitest-config/lances.mjs +83 -27
  196. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +10 -0
  197. package/scripts/langages/typescript/vitest-config/resultats.mjs +3 -1
  198. package/scripts/langages/typescript/vitest.nuit.config.mjs +4 -0
  199. package/scripts/lint-des-scripts.mjs +58 -0
  200. package/scripts/mesure/base-de-passe.mjs +117 -25
  201. package/scripts/mesure/pression.mjs +12 -6
  202. package/scripts/mesure-de-la-machine.d.mts +21 -0
  203. package/scripts/mesure-de-la-machine.mjs +76 -0
  204. package/scripts/migrations/0.23.0-charte-importee.mjs +6 -2
  205. package/scripts/migrations/0.23.0-crochets-de-seance.mjs +25 -8
  206. package/scripts/migrations/0.23.0-marche-du-projet.mjs +18 -6
  207. package/scripts/migrations/0.23.2-copies-du-cadre.mjs +56 -18
  208. package/scripts/migrations/0.24.12-tri-des-decouvertes.mjs +6 -2
  209. package/scripts/migrations/0.25.0-script-des-tests.mjs +15 -5
  210. package/scripts/migrations/0.30.0-ci-appelle-la-verification.mjs +124 -0
  211. package/scripts/migrations/0.31.0-paquets-dans-le-graphe.mjs +81 -0
  212. package/scripts/migrations.mjs +5 -0
  213. package/scripts/nuit.sh +25 -3
  214. package/scripts/outil.mjs +3 -1
  215. package/scripts/outils-cles.d.mts +24 -0
  216. package/scripts/outils-cles.mjs +18 -8
  217. package/scripts/paquet-npm.mjs +157 -0
  218. package/scripts/paquet.mjs +73 -4
  219. package/scripts/paquets.mjs +46 -10
  220. package/scripts/passe-de-la-machine.mjs +71 -0
  221. package/scripts/places-de-la-machine.mjs +414 -0
  222. package/scripts/places-du-serveur.mjs +170 -0
  223. package/scripts/prefixe-des-tickets.mjs +68 -0
  224. package/scripts/preparation.mjs +25 -8
  225. package/scripts/registre.mjs +9 -4
  226. package/scripts/regles-des-places.d.mts +36 -0
  227. package/scripts/regles-des-places.mjs +70 -0
  228. package/scripts/reponses-du-circuit.d.mts +6 -0
  229. package/scripts/reponses-du-circuit.mjs +28 -0
  230. package/scripts/reprise.mjs +66 -0
  231. package/scripts/resultats.mjs +112 -46
  232. package/scripts/retirer-les-copies-finies.mjs +25 -0
  233. package/scripts/sans-reponse.d.mts +4 -0
  234. package/scripts/sans-reponse.mjs +13 -0
  235. package/scripts/seances.mjs +936 -0
  236. package/scripts/services-du-noyau.mjs +27 -8
  237. package/scripts/session-start.sh +2 -2
  238. package/scripts/sortie.mjs +3 -3
  239. package/scripts/sous-commandes.mjs +41 -10
  240. package/scripts/style-a-l-ecriture.mjs +260 -0
  241. package/scripts/superviseur.mjs +122 -111
  242. package/scripts/tableau.mjs +180 -117
  243. package/scripts/taches-du-graphe.mjs +348 -0
  244. package/scripts/ticket-du-circuit.mjs +216 -0
  245. package/scripts/transitions.d.mts +148 -0
  246. package/scripts/transitions.mjs +1018 -0
  247. package/scripts/verrou-de-fichier.mjs +8 -4
  248. package/scripts/verrou-de-machine.mjs +150 -51
  249. package/scripts/verrous/commande.mjs +50 -17
  250. package/scripts/verrous/ticket-du-sous-agent.mjs +9 -3
  251. package/scripts/verrous/verrou.mjs +42 -14
  252. package/skills/explorateur/SKILL.md +9 -2
  253. package/skills/grill/SKILL.md +1 -1
  254. package/skills/mesure/SKILL.md +3 -0
  255. package/skills/pitmaster/SKILL.md +17 -18
  256. package/skills/pitmaster/references/consigne-agent.md +5 -1
  257. package/skills/release/SKILL.md +3 -3
  258. package/skills/relecteur/SKILL.md +5 -3
  259. package/skills/testwriter/SKILL.md +49 -31
  260. package/scripts/demon.mjs +0 -251
  261. package/scripts/integration/file-attente.mjs +0 -61
  262. package/scripts/langages/cargo/touches.mjs +0 -93
  263. package/scripts/langages/typescript/script-des-tests.mjs +0 -6
@@ -0,0 +1,170 @@
1
+ // The places of the machine read and taken on the Temporal server, in a process of its own, so
2
+ // that a synchronous caller (scripts/places-de-la-machine.mjs) waits for them as it waits for a
3
+ // lock: the workflow of the machine (src/temporal/places/deroule.ts) holds them, its client
4
+ // (src/temporal/places/client.ts) speaks to it.
5
+ //
6
+ // node places-du-serveur.mjs rang
7
+ // node places-du-serveur.mjs prendre <demande>
8
+ // node places-du-serveur.mjs rendre <id>
9
+ // node places-du-serveur.mjs rattacher <id> <pid> <depart>
10
+ // node places-du-serveur.mjs lire
11
+ //
12
+ // - Each mode first starts the workflow of the machine when none runs (`demarrerLesPlaces`, on the
13
+ // task queue of the worker of the machine), its ceiling GRILLHOUSE_PLACES and its spacing
14
+ // GRILLHOUSE_ESPACEMENT_MS (scripts/places-de-la-machine.mjs).
15
+ // - `rang` writes the next rank of arrival of the machine, which a circuit draws at its launch.
16
+ // - `prendre` asks for a place for <demande> (JSON: `{ pid, depart, ticket, rang, borneMs,
17
+ // rappelMs }`, the process that holds it), then waits for it: each line it says, at the start of
18
+ // a wait and every <rappelMs>, is one JSON line `{ dire }` on the standard output, then the place
19
+ // given, `{ id, rang }`. At the bound <borneMs>, the request is withdrawn, its line said, exit 75.
20
+ // - `rendre` gives the place <id> back (or withdraws its request), `rattacher` names the process
21
+ // that holds it; `lire` writes the places as the board reads them (`{ plafond, prises, attentes
22
+ // }`).
23
+ // - A server that does not answer within 5 s, or a client not built, is said on the error stream,
24
+ // exit 1; a malformed call, exit 2.
25
+ import { randomUUID } from 'node:crypto';
26
+ import { existsSync } from 'node:fs';
27
+ import path from 'node:path';
28
+ import { pathToFileURL } from 'node:url';
29
+ import { A_REPASSER } from './codes-de-sortie.mjs';
30
+ import { duree } from './regles-des-places.mjs';
31
+
32
+ const DIST = path.join(import.meta.dirname, '..', 'dist', 'temporal');
33
+ // How long a call waits for the server to answer.
34
+ const DELAI_MS = 5_000;
35
+ // How often a wait reads its request again.
36
+ const VEILLE_MS = 250;
37
+
38
+ // The ceiling and the spacing of the machine under <env>, as scripts/places-de-la-machine.mjs reads
39
+ // them; the workflow's veille, a second.
40
+ const entreeDe = async env => {
41
+ const { plafondDe, espacementDe } = await import('./places-de-la-machine.mjs');
42
+ return { plafond: plafondDe(env), espacementMs: espacementDe(env), veilleMs: 1_000 };
43
+ };
44
+
45
+ const MODES = { rang: 0, prendre: 1, rendre: 1, rattacher: 3, lire: 0 };
46
+ const ecrire = o => process.stdout.write(`${JSON.stringify(o)}\n`);
47
+
48
+ // The wait of the request <id> for its place, under the handle <h> of the workflow of the
49
+ // machine, its lines said: 0 once given, 75 at the bound <borneMs>, the request withdrawn.
50
+ async function attendreLaPlace(c, places, { h, id, rang, borneMs, rappelMs, sous, LA_DEMANDE }) {
51
+ const debut = Date.now();
52
+ let dit = null;
53
+ for (;;) {
54
+ const e = await sous(() => h.query(LA_DEMANDE, id));
55
+ if (e.etat === 'donnee') {
56
+ if (dit !== null) {
57
+ ecrire({ dire: `✓ place prise après ${duree(Date.now() - debut)}.` });
58
+ }
59
+ ecrire({ id, rang });
60
+ return 0;
61
+ }
62
+ if (e.etat === 'inconnue') {
63
+ throw new Error(`la demande de place ${id} n'est plus : retirée, ou son processus a disparu`);
64
+ }
65
+ const t = Date.now();
66
+ if (t - debut >= borneMs) {
67
+ await sous(() => places.rendreLaPlace(c.client, id));
68
+ ecrire({
69
+ dire: `⏱ attente de place bornée à ${duree(borneMs)} (GRILLHOUSE_ATTENTE_MACHINE_MS) : ${e.raison} ; à repasser (code ${A_REPASSER}).`,
70
+ });
71
+ return A_REPASSER;
72
+ }
73
+ if (dit === null) {
74
+ ecrire({ dire: `⏳ attente d'une place : ${e.raison} ; ${duree(borneMs)} au plus.` });
75
+ dit = t;
76
+ } else if (t - dit >= rappelMs) {
77
+ ecrire({ dire: `⏳ attente d'une place depuis ${duree(t - debut)} : ${e.raison}.` });
78
+ dit = t;
79
+ }
80
+ await new Promise(r => setTimeout(r, VEILLE_MS));
81
+ }
82
+ }
83
+
84
+ // The call <mode> with <args>: its exit code.
85
+ async function principal(mode, args) {
86
+ if (!Object.hasOwn(MODES, mode ?? '') || args.length !== MODES[mode]) {
87
+ process.stderr.write(
88
+ 'usage : places-du-serveur.mjs rang | prendre <demande> | rendre <id> | rattacher <id> <pid> <depart> | lire\n'
89
+ );
90
+ return 2;
91
+ }
92
+ if (!existsSync(path.join(DIST, 'places', 'client.js'))) {
93
+ process.stderr.write(
94
+ `le client Temporal n'est pas construit (${DIST}) : la construction du paquet le pose, \`npm run build --workspace @roomi-fields/grillhouse\`.\n`
95
+ );
96
+ return 1;
97
+ }
98
+ const depuisDist = (...p) => import(pathToFileURL(path.join(DIST, ...p)).href);
99
+ const { ouvrirLeClient } = await depuisDist('client.js');
100
+ const { FILE_DE_LA_MACHINE } = await depuisDist('installation.js');
101
+ const { ID_DES_PLACES, LA_DEMANDE, PRENDRE } = await depuisDist('places', 'contrat.js');
102
+ const places = await depuisDist('places', 'client.js');
103
+ const c = ouvrirLeClient();
104
+ const sous = f => c.client.connection.withDeadline(Date.now() + DELAI_MS, f);
105
+ try {
106
+ try {
107
+ await sous(async () =>
108
+ places.demarrerLesPlaces(c.client, await entreeDe(process.env), {
109
+ file: FILE_DE_LA_MACHINE,
110
+ })
111
+ );
112
+ } catch (x) {
113
+ if (x?.name !== 'WorkflowExecutionAlreadyStartedError') {
114
+ throw x;
115
+ }
116
+ }
117
+ if (mode === 'rang') {
118
+ ecrire(await sous(() => places.tirerUnRangParTemporal(c.client)));
119
+ } else if (mode === 'rendre') {
120
+ await sous(() => places.rendreLaPlace(c.client, args[0]));
121
+ } else if (mode === 'rattacher') {
122
+ const [id, pid, depart] = args;
123
+ await sous(() =>
124
+ places.rattacherLaPlace(c.client, id, {
125
+ pid: Number(pid),
126
+ depart: depart === 'null' ? null : depart,
127
+ })
128
+ );
129
+ } else if (mode === 'lire') {
130
+ ecrire(await sous(() => places.lireLesPlaces(c.client)));
131
+ } else {
132
+ const { borneMs, rappelMs, ...demande } = JSON.parse(args[0]);
133
+ const h = c.client.workflow.getHandle(ID_DES_PLACES);
134
+ const id = randomUUID();
135
+ const { rang } = await sous(() =>
136
+ h.executeUpdate(PRENDRE, { args: [{ ...demande, id }], updateId: id })
137
+ );
138
+ return await attendreLaPlace(c, places, {
139
+ h,
140
+ id,
141
+ rang,
142
+ borneMs,
143
+ rappelMs,
144
+ sous,
145
+ LA_DEMANDE,
146
+ });
147
+ }
148
+ return 0;
149
+ } catch (x) {
150
+ process.stderr.write(
151
+ `les places de la machine ne se lisent pas sur le serveur Temporal (${c.adresse}) : ${x?.message ?? x}${x?.cause?.message ? ` (${x.cause.message})` : ''} ; le serveur est requis sur le poste (\`npx grillhouse temporal installer\`).\n`
152
+ );
153
+ return 1;
154
+ } finally {
155
+ await c.fermer();
156
+ }
157
+ }
158
+
159
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
160
+ const [mode, ...args] = process.argv.slice(2);
161
+ principal(mode, args).then(
162
+ code => {
163
+ process.exitCode = code;
164
+ },
165
+ x => {
166
+ process.stderr.write(`${x?.stack ?? x}\n`);
167
+ process.exitCode = 1;
168
+ }
169
+ );
170
+ }
@@ -0,0 +1,68 @@
1
+ // The prefix of the tickets of a project, in the key `issue-prefix` of its committed
2
+ // `.beads/config.yaml`, the one place a CI reads it (it has no `bd`): the guard of the titles of the
3
+ // tests reads it there (scripts/langages/typescript/titres-de-tests.mjs). `bd init` writes the key
4
+ // commented out and keeps the prefix in its database, so the frame writes the key itself, by one
5
+ // function: the preparation of a new project (./preparation.mjs) and the update of a project
6
+ // (the migration 0.30.0 « préfixe des tickets »).
7
+ import { readFileSync, writeFileSync } from 'node:fs';
8
+ import path from 'node:path';
9
+
10
+ export const CONFIG_BEADS = '.beads/config.yaml';
11
+
12
+ // The key `issue-prefix`, not commented out, and one written empty.
13
+ const CLE = /^issue-prefix:\s*(?:"([^"]*)"|'([^']*)'|([^\s#]+))\s*(?:#.*)?$/m;
14
+ const CLE_VIDE = /^issue-prefix:\s*(?:""|'')?\s*(?:#.*)?$/m;
15
+ // The value of the key in <texte>, '' without one.
16
+ const valeurDe = texte => {
17
+ const m = CLE.exec(texte);
18
+ return m ? (m[1] ?? m[2] ?? m[3] ?? '') : '';
19
+ };
20
+
21
+ /**
22
+ * The prefix of the tickets of the repository at <racine>, read from the key `issue-prefix` of its
23
+ * committed file of Beads, never from `bd` (absent in a CI). Throws an error that names the file or
24
+ * the key when it is missing, so that nothing is counted by halves.
25
+ * @param {string} racine
26
+ * @returns {string}
27
+ */
28
+ export function prefixe(racine) {
29
+ let texte;
30
+ try {
31
+ texte = readFileSync(path.join(racine, CONFIG_BEADS), 'utf8');
32
+ } catch {
33
+ throw new Error(
34
+ `${CONFIG_BEADS} manque : le préfixe des tickets s'y lit (clé \`issue-prefix\`), jamais par bd.`
35
+ );
36
+ }
37
+ const valeur = valeurDe(texte);
38
+ if (!valeur) {
39
+ throw new Error(
40
+ `${CONFIG_BEADS} n'a pas la clé \`issue-prefix\` (une ligne commentée n'est pas la clé) : le préfixe des tickets s'y lit.`
41
+ );
42
+ }
43
+ return valeur;
44
+ }
45
+
46
+ /**
47
+ * Writes the key `issue-prefix: "<valeur>"` in the `.beads/config.yaml` of the repository at
48
+ * <racine>, which exists: a key written empty is replaced, an absent one added at the end; a key
49
+ * that already holds a value is left. Returns the line written, or null when nothing was written.
50
+ * @param {string} racine
51
+ * @param {string} valeur
52
+ * @returns {string | null}
53
+ */
54
+ export function ecrireLePrefixe(racine, valeur) {
55
+ const f = path.join(racine, CONFIG_BEADS);
56
+ const texte = readFileSync(f, 'utf8');
57
+ if (valeurDe(texte)) {
58
+ return null;
59
+ }
60
+ const ligne = `issue-prefix: "${valeur}"`;
61
+ writeFileSync(
62
+ f,
63
+ CLE_VIDE.test(texte)
64
+ ? texte.replace(CLE_VIDE, ligne)
65
+ : `${texte}${texte.endsWith('\n') || texte === '' ? '' : '\n'}${ligne}\n`
66
+ );
67
+ return ligne;
68
+ }
@@ -4,7 +4,10 @@
4
4
  // - git: the directory becomes a repository when it is none.
5
5
  // - Beads, the ticket store the skills work from: the tool (`bd`, installed by
6
6
  // `npm install -g @beads/bd` when absent), then the store, under the prefix given, else the
7
- // store's own, else the directory's name; the repository's `beads.role` is `maintainer`.
7
+ // store's own, else the directory's name; the repository's `beads.role` is `maintainer`. That
8
+ // prefix is written in the key `issue-prefix` of `.beads/config.yaml`, which `bd init` leaves
9
+ // commented out and the guard of the titles of the tests reads (`ecrireLePrefixe` of
10
+ // ./prefixe-des-tickets.mjs, as the update writes it).
8
11
  // - CodeGraph, the code knowledge graph the skills query (the MCP server of `.mcp.json`): the tool
9
12
  // (installed by `npm install -g @colbymchenry/codegraph` when absent) and the index of the code.
10
13
  // - The folder git reads the hooks from: `core.hooksPath` set to Beads' (`.beads/hooks`) when the
@@ -17,11 +20,15 @@
17
20
  import { execFileSync, spawnSync } from 'node:child_process';
18
21
  import { existsSync } from 'node:fs';
19
22
  import path from 'node:path';
23
+ import { trouverDansLePath } from './commandes-du-path.mjs';
20
24
  import { installerGreffons } from './greffons.mjs';
25
+ import { ecrireLePrefixe } from './prefixe-des-tickets.mjs';
21
26
 
22
27
  // The prefix of the tickets: the one given, else the store's own, else the directory's name.
23
28
  function prefixeDe(projet, donne) {
24
- if (donne) return donne;
29
+ if (donne) {
30
+ return donne;
31
+ }
25
32
  if (existsSync(path.join(projet, '.beads'))) {
26
33
  const r = spawnSync('bd', ['config', 'get', 'issue_prefix'], {
27
34
  cwd: projet,
@@ -29,7 +36,9 @@ function prefixeDe(projet, donne) {
29
36
  maxBuffer: 256 * 1024 * 1024,
30
37
  });
31
38
  const existant = (r.stdout ?? '').trim();
32
- if (r.status === 0 && existant !== '' && !existant.includes('(')) return existant;
39
+ if (r.status === 0 && existant !== '' && !existant.includes('(')) {
40
+ return existant;
41
+ }
33
42
  }
34
43
  return path
35
44
  .basename(projet)
@@ -40,11 +49,13 @@ function prefixeDe(projet, donne) {
40
49
  // Runs <commande> in <projet>, its output this process's; throws on a failure.
41
50
  const lancer = (projet, commande, args) =>
42
51
  execFileSync(commande, args, { cwd: projet, stdio: 'inherit' });
43
- const present = commande => spawnSync('sh', ['-c', `command -v ${commande}`]).status === 0;
52
+ const present = commande => trouverDansLePath(commande) !== null;
44
53
 
45
54
  // A global tool of the preparation, installed by npm when absent.
46
55
  function outil(commande, paquet) {
47
- if (present(commande)) return;
56
+ if (present(commande)) {
57
+ return;
58
+ }
48
59
  try {
49
60
  execFileSync('npm', ['install', '-g', paquet], { stdio: 'inherit' });
50
61
  } catch {
@@ -64,7 +75,10 @@ export function preparer(projet, prefixe) {
64
75
  }
65
76
  outil('bd', '@beads/bd');
66
77
  outil('codegraph', '@colbymchenry/codegraph');
67
- if (!existsSync(path.join(projet, '.codegraph'))) lancer(projet, 'codegraph', ['init', projet]);
78
+ if (!existsSync(path.join(projet, '.codegraph'))) {
79
+ lancer(projet, 'codegraph', ['init', projet]);
80
+ }
81
+ const lePrefixe = prefixeDe(projet, prefixe);
68
82
  lancer(projet, 'bd', [
69
83
  'init',
70
84
  '--init-if-missing',
@@ -72,13 +86,16 @@ export function preparer(projet, prefixe) {
72
86
  '--skip-agents',
73
87
  '--quiet',
74
88
  '--prefix',
75
- prefixeDe(projet, prefixe),
89
+ lePrefixe,
76
90
  ]);
91
+ ecrireLePrefixe(projet, lePrefixe);
77
92
  lancer(projet, 'git', ['config', 'beads.role', 'maintainer']);
78
93
  const r = spawnSync('git', ['-C', projet, 'config', 'core.hooksPath'], { encoding: 'utf8' });
79
94
  if ((r.stdout ?? '').trim() === '') {
80
95
  lancer(projet, 'git', ['config', 'core.hooksPath', '.beads/hooks']);
81
96
  }
82
- if (existsSync(path.join(projet, 'package.json'))) lancer(projet, 'npm', ['install']);
97
+ if (existsSync(path.join(projet, 'package.json'))) {
98
+ lancer(projet, 'npm', ['install']);
99
+ }
83
100
  return installerGreffons(projet);
84
101
  }
@@ -225,7 +225,8 @@ export function aRattraper(racine, home, connus, maintenant = Date.now()) {
225
225
  // time of one read and one append.
226
226
  const PERIME = 30_000;
227
227
 
228
- // Appends `l` to the register unless it already holds the line of this agent's end. Returns whether
228
+ // Appends `l` to the register unless it already holds the line of this agent's end, or the line of
229
+ // its key (`cle`, a gesture of an act of the circuit under Temporal played again). Returns whether
229
230
  // it wrote. The check and the append happen under the register's lock.
230
231
  export function ecrire(l) {
231
232
  mkdirSync(path.dirname(REGISTRE), { recursive: true });
@@ -236,7 +237,7 @@ export function ecrire(l) {
236
237
  for (const x of deja.split('\n')) {
237
238
  try {
238
239
  const e = JSON.parse(x);
239
- if (e.agent === l.agent && e.fin === l.fin) {
240
+ if ((l.cle && e.cle === l.cle) || (e.agent === l.agent && e.fin === l.fin)) {
240
241
  return false;
241
242
  }
242
243
  } catch {
@@ -348,10 +349,14 @@ if (direct && process.argv.includes('--rattraper')) {
348
349
  } else if (direct) {
349
350
  try {
350
351
  const input = JSON.parse(readFileSync(0, 'utf8'));
351
- const retenu = Object.fromEntries(CHAMPS.filter(c => input[c] != null).map(c => [c, input[c]]));
352
+ const retenu = Object.fromEntries(
353
+ CHAMPS.filter(c => input[c] !== null && input[c] !== undefined).map(c => [c, input[c]])
354
+ );
352
355
  // The directory the session opened in: the last directory of its shell (`cwd`) may lie where
353
356
  // git finds no repository, a mount of the envelope, where git stops at the boundary.
354
- if (process.env.CLAUDE_PROJECT_DIR) retenu.projet_dir = process.env.CLAUDE_PROJECT_DIR;
357
+ if (process.env.CLAUDE_PROJECT_DIR) {
358
+ retenu.projet_dir = process.env.CLAUDE_PROJECT_DIR;
359
+ }
355
360
  spawn(process.execPath, [process.argv[1], '--ecrire', JSON.stringify(retenu)], {
356
361
  detached: true,
357
362
  stdio: 'ignore',
@@ -0,0 +1,36 @@
1
+ // The types of the rules of the places of the machine (./regles-des-places.mjs), which the
2
+ // workflow of the machine under Temporal (src/temporal/places/) imports.
3
+
4
+ /** The memory a start wants free, in bytes: 4 GB. */
5
+ export const MEMOIRE_MIN: number;
6
+
7
+ /** A duration as a line says it: seconds under 2 min, else minutes. */
8
+ export function duree(ms: number): string;
9
+
10
+ /** What the machine gives at a moment: its cores, its load over one minute, its free memory. */
11
+ export interface MesureDeLaMachine {
12
+ coeurs: number;
13
+ charge: number;
14
+ /** In bytes. */
15
+ memoireLibre: number;
16
+ }
17
+
18
+ /** Whether a start is admitted at this load and this free memory; a refusal says why. */
19
+ export function admission(m: MesureDeLaMachine): { ok: true } | { ok: false; raison: string };
20
+
21
+ /** Why a taking does not pass now on a state of the places, null when it passes. */
22
+ export function refusDeLaPlace(
23
+ etat: {
24
+ prises: readonly unknown[];
25
+ attentes: readonly { id: string; rang: number; ticket?: string | null; raison?: string }[];
26
+ dernier: number;
27
+ },
28
+ o: {
29
+ id: string;
30
+ rang: number;
31
+ plafond: number;
32
+ espacementMs: number;
33
+ maintenant: number;
34
+ mesurer: () => MesureDeLaMachine;
35
+ }
36
+ ): string | null;
@@ -0,0 +1,70 @@
1
+ // The rules of the places of the machine, with no input nor output: whether a start is admitted
2
+ // at a load and a free memory, as `make -l` admits it, and why a taking does not pass now. The
3
+ // workflow of the machine (src/temporal/places/, grillhouse-4nr.7) holds the places of the machine
4
+ // and decides by them; a session or a pass takes its place there by
5
+ // scripts/places-de-la-machine.mjs. The workflow bundles this module, which imports nothing. What
6
+ // the machine gives, its load and its memory, is measured by scripts/mesure-de-la-machine.mjs.
7
+
8
+ /** The memory a start wants free, in bytes: 4 GB. */
9
+ export const MEMOIRE_MIN = 4 * 1024 ** 3;
10
+
11
+ // 11.2 → « 11,2 », 4 → « 4 ».
12
+ const nombre = n => (Number.isInteger(n) ? String(n) : n.toFixed(1).replace('.', ','));
13
+
14
+ /**
15
+ * A duration as a line says it: seconds under 2 min, else minutes.
16
+ * @param {number} ms
17
+ * @returns {string}
18
+ */
19
+ export const duree = ms =>
20
+ ms < 120_000 ? `${Math.round(ms / 1000)} s` : `${Math.round(ms / 60_000)} min`;
21
+
22
+ /**
23
+ * Whether a start is admitted at this load and this free memory, as `make -l` admits it: the load
24
+ * under the number of cores, and at least MEMOIRE_MIN free. A refusal says why.
25
+ * @param {{ coeurs: number, charge: number, memoireLibre: number }} o `memoireLibre` in bytes
26
+ * @returns {{ ok: true } | { ok: false, raison: string }}
27
+ */
28
+ export function admission({ coeurs, charge, memoireLibre }) {
29
+ if (charge >= coeurs) {
30
+ return { ok: false, raison: `charge de la machine ${nombre(charge)} sur ${coeurs} cœurs` };
31
+ }
32
+ if (memoireLibre < MEMOIRE_MIN) {
33
+ return {
34
+ ok: false,
35
+ raison: `mémoire libre ${nombre(memoireLibre / 1024 ** 3)} Go, sous les ${MEMOIRE_MIN / 1024 ** 3} Go demandés`,
36
+ };
37
+ }
38
+ return { ok: true };
39
+ }
40
+
41
+ /**
42
+ * Why the taking <id> of the rank <rang> does not pass now on the state <etat> (`prises`,
43
+ * `attentes`, `dernier`, the time of the last start), null when it passes: no free place under
44
+ * <plafond>; a wait of a lower rank alive, which keeps its turn between projects; the admission at
45
+ * the load and the memory <mesurer> gives (read only when the place and the turn pass); two starts
46
+ * closer than <espacementMs> at the time <maintenant>.
47
+ * @param {{ prises: object[], attentes: { id: string, rang: number, ticket?: string | null,
48
+ * raison?: string }[], dernier: number }} etat
49
+ * @param {{ id: string, rang: number, plafond: number, espacementMs: number, maintenant: number,
50
+ * mesurer: () => { coeurs: number, charge: number, memoireLibre: number } }} o
51
+ * @returns {string | null}
52
+ */
53
+ export function refusDeLaPlace(etat, { id, rang, plafond, espacementMs, maintenant, mesurer }) {
54
+ if (etat.prises.length >= plafond) {
55
+ return `aucune place libre : ${etat.prises.length} prises sur ${plafond}`;
56
+ }
57
+ const avant = etat.attentes.find(a => a.id !== id && a.rang < rang);
58
+ if (avant) {
59
+ return `place réservée : ${avant.ticket ?? 'un départ'} est arrivé avant et attend (${avant.raison})`;
60
+ }
61
+ const a = admission(mesurer());
62
+ if (!a.ok) {
63
+ return a.raison;
64
+ }
65
+ const ecoule = maintenant - etat.dernier;
66
+ if (ecoule < espacementMs) {
67
+ return `espacement des départs : le dernier date de ${duree(ecoule)}, ${duree(espacementMs)} au moins`;
68
+ }
69
+ return null;
70
+ }
@@ -0,0 +1,6 @@
1
+ // The types of ./reponses-du-circuit.mjs, for the frame's TypeScript (src/temporal/circuit/client.ts).
2
+
3
+ /** The statuses of a workflow ended without its issue. */
4
+ export const SANS_ISSUE: Set<string>;
5
+ /** The answers accepted for the circuit of <ticket> whose workflow has the status <statut>. */
6
+ export function lesReponses(ticket: string, statut: string, ecrit: boolean): string;
@@ -0,0 +1,28 @@
1
+ // The answers a circuit accepts from the supervisor, by the status of its workflow, with no input
2
+ // nor output: the one rule the client (src/temporal/circuit/client.ts: its refusals and the
3
+ // circuits it reads), the opening, the wait, the board and the line of a stop name.
4
+
5
+ /** The statuses of a workflow ended without its issue. */
6
+ export const SANS_ISSUE = new Set(['TERMINATED', 'FAILED', 'TIMED_OUT', 'CANCELLED']);
7
+
8
+ /**
9
+ * The answers accepted for the circuit of <ticket> whose workflow has the status <statut>, a state
10
+ * written in its memo or not (<ecrit>), each a command between backquotes after the first, which
11
+ * has none: ended without its issue, `--reprendre` from that state or `--depuis`; running, every
12
+ * answer; stopped on the supervisor's word, all but `--arreter`.
13
+ * @param {string} ticket
14
+ * @param {string} statut
15
+ * @param {boolean} ecrit
16
+ * @returns {string}
17
+ */
18
+ export function lesReponses(ticket, statut, ecrit) {
19
+ const circuit = `npx grillhouse circuit ${ticket}`;
20
+ const depuis = '--depuis <testwriter|developpeur> --contexte <texte>';
21
+ if (SANS_ISSUE.has(statut)) {
22
+ return ecrit ? `${circuit} --reprendre\` ou \`${depuis}` : `${circuit} ${depuis}`;
23
+ }
24
+ const etendre = '--etendre <paquet>';
25
+ return statut === 'RUNNING'
26
+ ? `${circuit} --reprendre\`, \`${depuis}\`, \`${etendre}\` ou \`--arreter`
27
+ : `${circuit} --reprendre\`, \`${depuis}\` ou \`${etendre}`;
28
+ }
@@ -0,0 +1,66 @@
1
+ // The resumption of the circuit at the step that carries a red, with no input nor output (as
2
+ // scripts/transitions.mjs): the attribution of a red to the step that carries it and the step where
3
+ // `--depuis` resumes. Mature model: « Re-run failed jobs » of GitHub Actions (the red job and what
4
+ // depends on it replay). The fingerprint of a step, which hashes with `node:crypto`, is in
5
+ // scripts/empreinte-d-etape.mjs, on the side of the activities.
6
+ import { SUITE } from './etapes.mjs';
7
+
8
+ const etatDe = n => SUITE.find(e => e.numero === n).etat;
9
+
10
+ /**
11
+ * The step that carries the red whose places are <lieux> (`{ paquet, fichier, gardes }`), by the
12
+ * files the red names against what the testwriter (`portes.tests`) and the developpeur
13
+ * (`portes.code`) wrote: `{ etape, fichiers, motif? }`. A test file that a guard or the style
14
+ * refuses (`gardes` not empty) is the testwriter's, the earliest step (the developpeur replays
15
+ * after him); a test that fails (no guard) and a file of code are the developpeur's. A red that
16
+ * names no file, or a file nobody wrote, is never attributed (`etape` null, its `motif` said): it
17
+ * goes up.
18
+ */
19
+ export function attribuerLeRouge({ lieux, portes }) {
20
+ const avecFichier = (lieux ?? []).filter(l => typeof l.fichier === 'string' && l.fichier);
21
+ const nommes = [...new Set(avecFichier.map(l => l.fichier))];
22
+ if (!nommes.length) {
23
+ return { etape: null, fichiers: [], motif: 'le rouge ne nomme aucun fichier' };
24
+ }
25
+ const tests = new Set(portes.tests);
26
+ const code = new Set(portes.code);
27
+ const inconnus = nommes.filter(f => !tests.has(f) && !code.has(f));
28
+ if (inconnus.length) {
29
+ return {
30
+ etape: null,
31
+ fichiers: [],
32
+ motif: `le rouge nomme ${inconnus.join(', ')}, que ni le testwriter ni le développeur ne portent`,
33
+ };
34
+ }
35
+ const refuses = nommes.filter(
36
+ f => tests.has(f) && avecFichier.some(l => l.fichier === f && (l.gardes ?? []).length > 0)
37
+ );
38
+ return refuses.length
39
+ ? { etape: 'testwriter', fichiers: refuses.length === nommes.length ? refuses : nommes }
40
+ : { etape: 'developpeur', fichiers: nommes };
41
+ }
42
+
43
+ // The steps `--depuis` names, each with the state it resumes at.
44
+ const DEPARTS = {
45
+ testwriter: () => ({ etape: etatDe('2'), tentative: 1, finale: false }),
46
+ preuve: () => ({ etape: etatDe('2.1'), tentative: 1, finale: false }),
47
+ developpeur: () => ({ etape: etatDe('3'), tentative: 1, finale: false }),
48
+ controles: () => ({ etape: etatDe('3.1'), tentative: 0, finale: false }),
49
+ 'passe-finale': () => ({ etape: etatDe('3.1'), tentative: 0, finale: true }),
50
+ };
51
+
52
+ /** The steps `--depuis` names. */
53
+ export const ETAPES_DE_REPRISE = Object.keys(DEPARTS);
54
+
55
+ /**
56
+ * The state `--depuis <nom>` resumes at: that step and the ones after it, no fingerprint kept
57
+ * (`verts` empty), so nothing is read back.
58
+ */
59
+ export function departDepuis(nom) {
60
+ if (!Object.hasOwn(DEPARTS, nom)) {
61
+ throw new Error(
62
+ `--depuis attend une étape du ticket : ${ETAPES_DE_REPRISE.join(', ')} (reçu « ${nom} »).`
63
+ );
64
+ }
65
+ return { ...DEPARTS[nom](), rapport: null, verts: {} };
66
+ }