@roomi-fields/grillhouse 0.50.3 → 0.52.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 (150) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +68 -0
  3. package/agents/developpeur.md +1 -1
  4. package/agents/direct.md +1 -1
  5. package/agents/explorateur.md +1 -1
  6. package/agents/questionneur.md +1 -1
  7. package/agents/relecteur.md +1 -1
  8. package/agents/testwriter.md +1 -1
  9. package/cadre/templates/c/package.json +1 -0
  10. package/cadre/templates/cargo/package.json +1 -0
  11. package/cadre/templates/python/package.json +1 -0
  12. package/charte/plan.md +47 -0
  13. package/charte/preuve.md +39 -0
  14. package/charte/superviseur.md +61 -0
  15. package/charte/tests.md +38 -0
  16. package/charte.md +39 -189
  17. package/dist/machine/part-par-sorte.d.ts +16 -0
  18. package/dist/machine/part-par-sorte.js +36 -0
  19. package/dist/machine/part-par-sorte.js.map +1 -0
  20. package/dist/temporal/circuit/appel.js +1 -1
  21. package/dist/temporal/circuit/appel.js.map +1 -1
  22. package/dist/temporal/circuit/client.d.ts +4 -4
  23. package/dist/temporal/circuit/client.js +38 -16
  24. package/dist/temporal/circuit/client.js.map +1 -1
  25. package/dist/temporal/circuit/contrat.d.ts +11 -7
  26. package/dist/temporal/circuit/contrat.js +5 -9
  27. package/dist/temporal/circuit/contrat.js.map +1 -1
  28. package/dist/temporal/circuit/deroule.js +18 -6
  29. package/dist/temporal/circuit/deroule.js.map +1 -1
  30. package/dist/temporal/commande.js +12 -3
  31. package/dist/temporal/commande.js.map +1 -1
  32. package/dist/temporal/installation.d.ts +54 -3
  33. package/dist/temporal/installation.js +187 -17
  34. package/dist/temporal/installation.js.map +1 -1
  35. package/dist/temporal/places/client.d.ts +5 -1
  36. package/dist/temporal/places/client.js +23 -11
  37. package/dist/temporal/places/client.js.map +1 -1
  38. package/docs/ARCHITECTURE.md +23 -2700
  39. package/docs/INTERFACE.md +26 -10
  40. package/docs/architecture/circuit.md +61 -14
  41. package/docs/architecture/entree.md +21 -8
  42. package/docs/architecture/greffon.md +49 -20
  43. package/docs/architecture/installation.md +46 -17
  44. package/docs/architecture/machine.md +79 -39
  45. package/docs/architecture/tests.md +59 -16
  46. package/docs/lexique.md +163 -0
  47. package/hooks/hooks.json +0 -10
  48. package/hooks/register.tsx +92 -4
  49. package/package.json +2 -1
  50. package/scripts/activites.mjs +105 -65
  51. package/scripts/aiguillage.mjs +15 -8
  52. package/scripts/attente-au-tour.mjs +2 -3
  53. package/scripts/attente-de-la-machine.mjs +4 -8
  54. package/scripts/avancement.mjs +12 -8
  55. package/scripts/bilan.mjs +126 -63
  56. package/scripts/bilans-gardes.mjs +37 -0
  57. package/scripts/branche-de-nuit.mjs +2 -2
  58. package/scripts/ci-de-main.mjs +18 -21
  59. package/scripts/circuit.mjs +89 -44
  60. package/scripts/circuits-du-serveur.mjs +5 -5
  61. package/scripts/composants-affectes.mjs +30 -12
  62. package/scripts/composition-des-langages.mjs +5 -3
  63. package/scripts/conformite.mjs +1 -1
  64. package/scripts/consommation-des-passes.mjs +8 -6
  65. package/scripts/copies-finies.mjs +3 -14
  66. package/scripts/depart-du-ticket.d.mts +8 -2
  67. package/scripts/depart-du-ticket.mjs +26 -8
  68. package/scripts/direct.mjs +158 -72
  69. package/scripts/droits.mjs +165 -208
  70. package/scripts/engendres.mjs +3 -14
  71. package/scripts/entree-de-seance.mjs +35 -0
  72. package/scripts/enveloppe/enveloppe.mjs +98 -46
  73. package/scripts/enveloppe/lancer.sh +90 -66
  74. package/scripts/enveloppe/paquets-du-plan.mjs +38 -11
  75. package/scripts/enveloppe/travail-de-la-copie.mjs +192 -3
  76. package/scripts/etapes.mjs +84 -22
  77. package/scripts/faits-du-circuit.mjs +8 -2
  78. package/scripts/grillhouse-maj.mjs +43 -18
  79. package/scripts/groupe-cles.d.mts +15 -0
  80. package/scripts/groupe-cles.mjs +77 -2
  81. package/scripts/init.mjs +9 -2
  82. package/scripts/integration/rejeu.mjs +8 -1
  83. package/scripts/jointure.d.ts +24 -4
  84. package/scripts/langages/c/index.mjs +5 -2
  85. package/scripts/langages/cargo/commandes.mjs +35 -15
  86. package/scripts/langages/cargo/composants.mjs +45 -3
  87. package/scripts/langages/cargo/index.mjs +6 -3
  88. package/scripts/langages/python/commandes.mjs +50 -7
  89. package/scripts/langages/python/index.mjs +5 -2
  90. package/scripts/langages/python/squelette.mjs +2 -1
  91. package/scripts/langages/typescript/chemins-des-tests.mjs +1 -1
  92. package/scripts/langages/typescript/index.mjs +16 -14
  93. package/scripts/langages/typescript/mise-a-jour.mjs +1 -1
  94. package/scripts/langages/typescript/rapports-aux-lignes.mjs +74 -0
  95. package/scripts/langages/typescript/turbo-des-paquets.mjs +151 -38
  96. package/scripts/langages/typescript/verdict.mjs +29 -3
  97. package/scripts/langages/typescript/verifier.mjs +28 -3
  98. package/scripts/langages/typescript/vitest-config/changements.mjs +8 -6
  99. package/scripts/langages/typescript/vitest-config/lances.mjs +15 -32
  100. package/scripts/langages.mjs +54 -4
  101. package/scripts/matieres-lues.mjs +1 -1
  102. package/scripts/mesure/base-de-passe.mjs +32 -90
  103. package/scripts/migrations/serveurs-de-l-index.mjs +79 -0
  104. package/scripts/migrations/suivi-du-superviseur-retire.mjs +56 -0
  105. package/scripts/migrations.mjs +23 -7
  106. package/scripts/nuit.sh +3 -2
  107. package/scripts/paquet.mjs +1 -1
  108. package/scripts/paquets.d.ts +3 -0
  109. package/scripts/paquets.mjs +88 -1
  110. package/scripts/passe-de-la-machine.mjs +109 -36
  111. package/scripts/places-de-la-machine.mjs +81 -29
  112. package/scripts/plafond-de-la-machine.d.mts +2 -5
  113. package/scripts/plafond-de-la-machine.mjs +9 -9
  114. package/scripts/reprise.mjs +42 -13
  115. package/scripts/resultats.mjs +78 -56
  116. package/scripts/retirer-les-copies-finies.mjs +1 -1
  117. package/scripts/seances.mjs +471 -133
  118. package/scripts/services-du-noyau.mjs +9 -1
  119. package/scripts/session-start.sh +22 -7
  120. package/scripts/sortie-de-seance.mjs +70 -0
  121. package/scripts/sortie.mjs +37 -6
  122. package/scripts/sous-commandes.mjs +0 -3
  123. package/scripts/superviseur.mjs +400 -162
  124. package/scripts/tableau.mjs +188 -65
  125. package/scripts/transitions.d.mts +25 -2
  126. package/scripts/transitions.mjs +137 -29
  127. package/scripts/verrous/ecriture-hors-enveloppe.mjs +31 -9
  128. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  129. package/skills/developpeur/SKILL.md +38 -15
  130. package/skills/direct/SKILL.md +29 -9
  131. package/skills/domain-modeling/GLOSSARY-FORMAT.md +9 -9
  132. package/skills/domain-modeling/SKILL.md +14 -12
  133. package/skills/explorateur/SKILL.md +32 -8
  134. package/skills/grill/SKILL.md +3 -2
  135. package/skills/pitmaster/SKILL.md +80 -50
  136. package/skills/pitmaster/references/cadre.md +1 -1
  137. package/skills/pitmaster/references/consigne-agent.md +12 -11
  138. package/skills/pitmaster/references/tour.md +6 -5
  139. package/skills/relecteur/SKILL.md +13 -6
  140. package/skills/systematic-debugging/SKILL.md +281 -0
  141. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  142. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  143. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  144. package/skills/systematic-debugging/find-polluter.sh +72 -0
  145. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  146. package/skills/testwriter/SKILL.md +37 -31
  147. package/cadre/templates/projet/pitmaster/SUIVI.md +0 -22
  148. package/scripts/attente-a-l-arret.mjs +0 -114
  149. package/scripts/verrous/commande.mjs +0 -214
  150. package/scripts/verrous/verrou.mjs +0 -311
@@ -1,114 +0,0 @@
1
- #!/usr/bin/env node
2
- // The stop of the session of supervision: the hook Stop of the frame's plugin runs it
3
- // (`grillhouse attente-a-l-arret`) when the session ends its turn: the supervisor does not end its
4
- // turn while a circuit waits for it, as an alert not acknowledged pages again (PagerDuty). It asks
5
- // for no wait: the greffon pushes the questions of the circuits (greffon.md, §5.1).
6
- //
7
- // - Stop runs for the session itself, never for a sub-agent (SubagentStop). The session is the
8
- // supervisor's as for the signal of the turn (`racineDeLaSupervision` of
9
- // scripts/attente-au-tour.mjs): out of a git repository, in an agent's copy and in the session
10
- // of a role the circuit launches, the stop passes.
11
- // - A question of a circuit waits for the supervisor (`questionsEnAttente` of
12
- // scripts/superviseur.mjs, a circuit ended without its issue included): the stop is blocked
13
- // with each question, its ticket, its step and the command that answers it.
14
- // - Each question blocks once, by its key: it is noted in `.claude/worktrees/signale-a-l-arret.json`,
15
- // which keeps the questions that still wait alone (a note that holds an `etat` reads without
16
- // error, the state dropped), so that a stop the supervisor decides (a question carried to the
17
- // owner) is never held in a loop (`stop_hook_active` is not read; Claude Code caps the blocks
18
- // in a row at eight in any case, hooks.md « Stop »).
19
- // - The block: the reason on the error stream, exit code 2, which Claude Code gives the session as
20
- // its next instruction (hooks.md, « Exit code 2 behavior per event »).
21
- // - A server that does not answer, a note that cannot be written, an input that is no JSON: the
22
- // stop passes, exit 0.
23
- import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
24
- import path from 'node:path';
25
- import { pathToFileURL } from 'node:url';
26
- import { racineDeLaSupervision } from './attente-au-tour.mjs';
27
- import { circuitsDuServeur } from './circuits-du-serveur.mjs';
28
- import { ligneDeQuestion, questionsEnAttente, ticketsHorsAttente } from './superviseur.mjs';
29
-
30
- // The note of what blocked the stop in the repository at <racine>.
31
- const noteDe = racine => path.join(racine, '.claude', 'worktrees', 'signale-a-l-arret.json');
32
-
33
- // The keys of the questions the note holds; an older note's other keys are ignored.
34
- function lireLaNote(racine) {
35
- try {
36
- const lu = JSON.parse(readFileSync(noteDe(racine), 'utf8'));
37
- return {
38
- questions: new Set(Array.isArray(lu?.questions) ? lu.questions.map(String) : []),
39
- // Only `questions`: a note that holds another key (an older `etat`) is written again.
40
- nette: Object.keys(lu ?? {}).join() === 'questions',
41
- };
42
- } catch {
43
- return { questions: new Set(), nette: true };
44
- }
45
- }
46
-
47
- /**
48
- * What the stop of the session of supervision in <dossier> gets: the reason that blocks it, or
49
- * null when the stop passes (see the header). The questions it gives are noted, so that each
50
- * blocks once.
51
- * @param {string} dossier the directory the session works in
52
- * @param {{ env?: Record<string, string | undefined>,
53
- * fermes?: (racine: string, ids: string[]) => Set<string> | null,
54
- * circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} [options]
55
- * @returns {Promise<string | null>}
56
- */
57
- export async function attenteALArret(
58
- dossier,
59
- { env = process.env, fermes = ticketsHorsAttente, circuitsDe = circuitsDuServeur } = {}
60
- ) {
61
- const racine = racineDeLaSupervision(dossier, env);
62
- if (!racine) {
63
- return null;
64
- }
65
- let circuits;
66
- try {
67
- circuits = await circuitsDe(racine);
68
- } catch {
69
- return null;
70
- }
71
- const questions = questionsEnAttente(racine, circuits, { fermes });
72
- const note = lireLaNote(racine);
73
- const neuves = questions.filter(q => !note.questions.has(q.cle));
74
- if (!note.nette || questions.length !== note.questions.size || neuves.length) {
75
- const f = noteDe(racine);
76
- try {
77
- mkdirSync(path.dirname(f), { recursive: true });
78
- writeFileSync(
79
- `${f}.${process.pid}`,
80
- `${JSON.stringify({ questions: questions.map(q => q.cle).sort() })}\n`
81
- );
82
- renameSync(`${f}.${process.pid}`, f);
83
- } catch {
84
- // A note that cannot be written would block at each stop: the stop passes.
85
- return null;
86
- }
87
- }
88
- if (!neuves.length) {
89
- return null;
90
- }
91
- return [
92
- neuves.length > 1
93
- ? `Ne te mets pas en attente : ${neuves.length} circuits attendent ta réponse. Réponds à chacun, ou porte sa question au responsable en le lui disant, puis termine ton tour.`
94
- : 'Ne te mets pas en attente : un circuit attend ta réponse. Réponds-lui, ou porte sa question au responsable en le lui disant, puis termine ton tour.',
95
- ...neuves.map(q =>
96
- q.interrompu
97
- ? `- ${q.ticket} a fini sans son issue, à ${q.etape} : \`${q.commande}\`.`
98
- : ligneDeQuestion(q)
99
- ),
100
- ].join('\n');
101
- }
102
-
103
- if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
104
- let raison = null;
105
- try {
106
- raison = await attenteALArret(process.cwd());
107
- } catch {
108
- // A fault lets the stop pass.
109
- }
110
- if (raison) {
111
- process.stderr.write(`${raison}\n`);
112
- process.exitCode = 2;
113
- }
114
- }
@@ -1,214 +0,0 @@
1
- #!/usr/bin/env node
2
- // The lock of the commands of a role that writes (the testwriter, the developpeur): a PreToolUse hook
3
- // on Bash, which the settings of its session declare (scripts/droits.mjs). It reads the hook's JSON
4
- // on stdin and refuses, exit code 2 and its reason on stderr, a command whose shell writes a file
5
- // out of the session's temporary directory: an output redirection (`>`, `>>`, `>|`, `&>`, `1>`…)
6
- // or `tee`. A file of the repository is written by the tools of writing (Write, Edit), which the
7
- // role's write lock (verrou.mjs) judges; a rule of Claude Code does not see a redirection, and a
8
- // session in its envelope runs without the check of writes. Architecture:
9
- // docs/architecture/machine.md (§3.1, §5.5 « Les verrous dans la séance »).
10
- //
11
- // - Allowed targets: the null and standard devices (`/dev/null`, `/dev/stdout`, `/dev/stderr`,
12
- // `/dev/fd/…`), a duplication of a descriptor (`2>&1`, `>&2`), and a path under the temporary
13
- // directory (`os.tmpdir()`, the envelope's TMPDIR), written plainly or by `$TMPDIR`/`${TMPDIR}`.
14
- // A relative path is judged from the command's working directory (the input's `cwd`). A target
15
- // that names any other variable or a substitution cannot be judged, and is refused.
16
- // - What quotes hold, and the body of a here-document, is text: a `>` there redirects nothing.
17
- // - An input it cannot read, or another tool, passes: a hook never stops the session on its own
18
- // failure.
19
- import { readFileSync } from 'node:fs';
20
- import { tmpdir } from 'node:os';
21
- import path from 'node:path';
22
- import { pathToFileURL } from 'node:url';
23
-
24
- const PERIPHERIQUES = /^\/dev\/(null|stdout|stderr|tty|fd\/\d+)$/;
25
-
26
- // The targets of the files <commande> writes by the shell, `$TMPDIR` read as <tmp>: each
27
- // `{ cible, brute }`, `cible` the word once its quotes are read, null when a variable or a
28
- // substitution keeps it unknown.
29
- function ecrituresDuShell(commande, tmp = tmpdir()) {
30
- const out = [];
31
- const n = commande.length;
32
- let i = 0;
33
- // The here-documents whose bodies start at the next line.
34
- let documents = [];
35
- // A word from <j>: its text with quotes read, whether it holds an expansion, and where it ends.
36
- const mot = j => {
37
- let texte = '';
38
- let inconnu = false;
39
- while (j < n && /\s/.test(commande[j]) && commande[j] !== '\n') {
40
- j++;
41
- }
42
- while (j < n && !/[\s;&|<>()]/.test(commande[j])) {
43
- const c = commande[j];
44
- if (c === "'") {
45
- const f = commande.indexOf("'", j + 1);
46
- texte += commande.slice(j + 1, f < 0 ? n : f);
47
- j = f < 0 ? n : f + 1;
48
- } else if (c === '"') {
49
- let k = j + 1;
50
- while (k < n && commande[k] !== '"') {
51
- if (commande[k] === '\\') {
52
- k++;
53
- } else if (commande[k] === '$' || commande[k] === '`') {
54
- inconnu = true;
55
- }
56
- texte += commande[k] ?? '';
57
- k++;
58
- }
59
- j = k + 1;
60
- } else if (c === '\\') {
61
- texte += commande[j + 1] ?? '';
62
- j += 2;
63
- } else {
64
- if (c === '$' || c === '`') {
65
- inconnu = true;
66
- }
67
- texte += c;
68
- j++;
69
- }
70
- }
71
- return { texte, inconnu, fin: j };
72
- };
73
- const cible = w => {
74
- const variable = /^\$(\{TMPDIR\}|TMPDIR)(\/.*)?$/.exec(w.texte);
75
- if (variable) {
76
- return { cible: path.join(tmp, variable[2] ?? ''), brute: w.texte };
77
- }
78
- return { cible: w.inconnu ? null : w.texte, brute: w.texte };
79
- };
80
- while (i < n) {
81
- const c = commande[i];
82
- if (c === '\n' && documents.length) {
83
- // The bodies of the here-documents opened on the line just ended.
84
- let j = i + 1;
85
- for (const fin of documents) {
86
- while (j < n) {
87
- const e = commande.indexOf('\n', j);
88
- const ligne = commande.slice(j, e < 0 ? n : e);
89
- j = e < 0 ? n : e + 1;
90
- if (ligne.replace(/^\t+/, '') === fin) {
91
- break;
92
- }
93
- }
94
- }
95
- documents = [];
96
- i = j;
97
- continue;
98
- }
99
- if (c === "'") {
100
- const f = commande.indexOf("'", i + 1);
101
- i = f < 0 ? n : f + 1;
102
- continue;
103
- }
104
- if (c === '"') {
105
- let k = i + 1;
106
- while (k < n && commande[k] !== '"') {
107
- k += commande[k] === '\\' ? 2 : 1;
108
- }
109
- i = k + 1;
110
- continue;
111
- }
112
- if (c === '\\') {
113
- i += 2;
114
- continue;
115
- }
116
- if (c === '<' && commande[i + 1] === '<' && commande[i + 2] !== '<') {
117
- const w = mot(i + (commande[i + 2] === '-' ? 3 : 2));
118
- if (w.texte) {
119
- documents.push(w.texte);
120
- }
121
- i = w.fin;
122
- continue;
123
- }
124
- if (c === '>') {
125
- let j = i + 1;
126
- if (commande[j] === '>' || commande[j] === '|') {
127
- j++;
128
- }
129
- // A duplication of a descriptor, `>&2`, writes no file.
130
- if (commande[j] === '&') {
131
- i = j + 1;
132
- continue;
133
- }
134
- const w = mot(j);
135
- if (w.texte) {
136
- out.push(cible(w));
137
- }
138
- i = w.fin;
139
- continue;
140
- }
141
- if (c === '&' && commande[i + 1] === '>') {
142
- const w = mot(i + (commande[i + 2] === '>' ? 3 : 2));
143
- if (w.texte) {
144
- out.push(cible(w));
145
- }
146
- i = w.fin;
147
- continue;
148
- }
149
- // `tee` as a command word: each of its operands is a file it writes.
150
- if (/[a-z]/.test(c) && (i === 0 || /[\s;&|(]/.test(commande[i - 1]))) {
151
- const w = mot(i);
152
- if (w.texte === 'tee') {
153
- let j = w.fin;
154
- for (;;) {
155
- const a = mot(j);
156
- if (!a.texte) {
157
- break;
158
- }
159
- if (!a.texte.startsWith('-')) {
160
- out.push(cible(a));
161
- }
162
- j = a.fin;
163
- }
164
- i = j;
165
- } else {
166
- i = Math.max(w.fin, i + 1);
167
- }
168
- continue;
169
- }
170
- i++;
171
- }
172
- return out;
173
- }
174
-
175
- // The reason the command of this hook input is refused, or null when it passes.
176
- export function refusDeCommande(input, { tmp = tmpdir() } = {}) {
177
- if (input?.tool_name !== 'Bash') {
178
- return null;
179
- }
180
- const commande = String(input.tool_input?.command ?? '');
181
- const cwd = input.cwd ?? process.cwd();
182
- const interieur = f => {
183
- const rel = path.relative(path.resolve(tmp), f);
184
- return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
185
- };
186
- const enTrop = ecrituresDuShell(commande, tmp).filter(({ cible }) => {
187
- if (cible === null) {
188
- return true;
189
- }
190
- if (PERIPHERIQUES.test(cible)) {
191
- return false;
192
- }
193
- const absolu = path.resolve(cwd, cible);
194
- return !interieur(absolu);
195
- });
196
- if (!enTrop.length) {
197
- return null;
198
- }
199
- return `Le shell n'écrit pas les fichiers du dépôt (${enTrop.map(e => e.brute).join(', ')}) : un fichier s'écrit par l'outil Write ou Edit, que le verrou de ton rôle juge ; un fichier temporaire va dans ${tmp}.`;
200
- }
201
-
202
- const direct = import.meta.url === pathToFileURL(process.argv[1] ?? '').href;
203
- if (direct) {
204
- let raison = null;
205
- try {
206
- raison = refusDeCommande(JSON.parse(readFileSync(0, 'utf8')));
207
- } catch {
208
- // An input it cannot read passes.
209
- }
210
- if (raison) {
211
- process.stderr.write(`${raison}\n`);
212
- process.exitCode = 2;
213
- }
214
- }
@@ -1,311 +0,0 @@
1
- #!/usr/bin/env node
2
- // The write lock of a role agent: a PreToolUse hook declared in the settings of its session
3
- // (scripts/droits.mjs: `npx grillhouse verrou <role>`). It reads the hook's JSON on stdin and refuses a
4
- // file write the role does not own, with exit code 2 and its reason on stderr. Architecture:
5
- // docs/architecture/machine.md (§3.1, §5.5 « Les verrous dans la séance »).
6
- //
7
- // - A path under the system temp directory (the session scratchpad) is always writable.
8
- // - testwriter writes the files it owns, those the rule of a test file of the module of the
9
- // project's language classes (`estUnTest`, scripts/jointure.d.ts, scripts/langages.mjs): its test
10
- // files, the helpers of its folders of tests, and every file of a package of the shared test
11
- // material. Of the manifests, it writes what the module declares its (`manifestes`): a write of
12
- // a component's manifest whose only change from the file on disk lies in the part of its tests
13
- // (`horsDesTests` empty; the text after an Edit or a MultiEdit is the file's with its
14
- // replacements), and the lock files of the versions; any other change of a manifest is refused,
15
- // the path and each part named. A file of code is judged the same way when the module declares
16
- // a part of it the tests' (cargo: the test module of a file of `src/`).
17
- // - The repository root is that of the git repository holding the written file, whatever the
18
- // agent's working directory; a file outside any repository is read against the working directory.
19
- // A project that declares no language (the column « Langage » of its docs/ARCHITECTURE.md) is
20
- // refused, exit code 2, the column named: the lock cannot judge its writes, and a hook that
21
- // throws would let them pass.
22
- // - developpeur writes none of the testwriter's files, and no other file until its ticket's
23
- // description holds a "## Architecture" section (`sansArchitecture`, which the start of the
24
- // circuit reads too). The ticket is the "TON TICKET : <id>" line of the agent's
25
- // launch prompt, read from its transcript.
26
- // - direct writes tests and code of its plan together (a ticket led by `npx grillhouse direct`).
27
- // - In an envelope (`GRILLHOUSE_ENVELOPPE`, the packages of the plan, scripts/enveloppe/
28
- // paquets-du-plan.mjs), a write in the copy out of the packages the plan writes (`ecritsDuPlan`
29
- // on the components of the module of the language, `paquetsDuLangage`, as the envelope reads them)
30
- // and out of the shared test material, whose rule is the one above, and for the testwriter out
31
- // of the lock files of the versions (`manifestes.verrous`), stops the session: the hook answers Claude Code's
32
- // `continue: false`, the tool refused (`permissionDecision: deny`), its reason naming the file's
33
- // package and the plan, and leaves that reason in the session's working directory
34
- // (`MARQUE_HORS_PLAN` under TMPDIR), which the launcher hands to the circuit. The mount of the
35
- // envelope refuses the same write to any tool; the hook says why, and stops.
36
- import { execFileSync } from 'node:child_process';
37
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
38
- import { tmpdir } from 'node:os';
39
- import path from 'node:path';
40
- import { pathToFileURL } from 'node:url';
41
- import {
42
- ecritsDuPlan,
43
- MARQUE_HORS_PLAN,
44
- MARQUE_HORS_PLAN_FAIT,
45
- paquetQuiTient,
46
- paquetsDeLEnveloppe,
47
- paquetsDuLangage,
48
- testsEtendusDeLEnveloppe,
49
- } from '../enveloppe/paquets-du-plan.mjs';
50
- import { langageDeLaCopie } from '../langages.mjs';
51
-
52
- const WRITE_TOOLS = new Set(['Write', 'Edit', 'MultiEdit', 'NotebookEdit']);
53
-
54
- // True when <file> lies strictly under the directory <dir>.
55
- function isInside(file, dir) {
56
- const rel = path.relative(path.resolve(dir), file);
57
- return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
58
- }
59
-
60
- // The refusal of the ticket <id> whose <description> holds no "## Architecture" section, or null:
61
- // the one rule the developer's lock and the start of the circuit (scripts/circuit.mjs) read.
62
- export function sansArchitecture(id, description) {
63
- return /^##\s+Architecture\b/m.test(String(description ?? ''))
64
- ? null
65
- : `Le ticket ${id} n'a pas sa section « ## Architecture » : le code attend l'architecture. Rends la question au superviseur.`;
66
- }
67
-
68
- const isScratch = (file, tmp = tmpdir()) => isInside(file, tmp);
69
-
70
- // The root of the git repository (or worktree) that holds the absolute path <file>, read from its
71
- // nearest existing directory; null when no repository holds it.
72
- export function racineDe(file) {
73
- let dir = path.dirname(file);
74
- while (!existsSync(dir)) {
75
- const parent = path.dirname(dir);
76
- if (parent === dir) {
77
- return null;
78
- }
79
- dir = parent;
80
- }
81
- try {
82
- return execFileSync('git', ['-C', dir, 'rev-parse', '--show-toplevel'], {
83
- encoding: 'utf8',
84
- stdio: 'pipe',
85
- }).trim();
86
- } catch {
87
- return null;
88
- }
89
- }
90
-
91
- // The role that writes the tests, the shared test material and the lock files of the versions.
92
- const TESTWRITER = 'testwriter';
93
-
94
- // The stop of a write of <role> out of the plan of the envelope <env>, `{ paquet, raison }`, or
95
- // null: a write in the repository holding the file, out of the packages the plan writes, out of
96
- // the shared test material and, for the testwriter, out of the lock files of the versions.
97
- export function horsDuPlan(input, { tmp = tmpdir(), env = process.env, role = null } = {}) {
98
- const plan = paquetsDeLEnveloppe(env);
99
- if (!plan || !WRITE_TOOLS.has(input.tool_name)) {
100
- return null;
101
- }
102
- const raw = input.tool_input?.file_path ?? input.tool_input?.notebook_path;
103
- if (!raw) {
104
- return null;
105
- }
106
- const file = path.resolve(input.cwd ?? process.cwd(), raw);
107
- if (isScratch(file, tmp)) {
108
- return null;
109
- }
110
- const copie = racineDe(file);
111
- if (!copie) {
112
- return null;
113
- }
114
- const langage = langageDeLaCopie(copie);
115
- const liste = paquetsDuLangage(langage, copie);
116
- const ecrits = ecritsDuPlan(plan, liste);
117
- const rel = path.relative(copie, file);
118
- if (ecrits.includes('.') || ecrits.some(d => rel.startsWith(`${d}/`))) {
119
- return null;
120
- }
121
- if (langage.estUnTest(file, copie)?.matiere) {
122
- return null;
123
- }
124
- if (role === TESTWRITER && langage.manifestes.verrous.includes(rel)) {
125
- return null;
126
- }
127
- // The test files of a reader package the circuit extended the plan to (`testsEtendus`, given to
128
- // the testwriter's envelope alone): never its code nor its manifest.
129
- if (
130
- role === TESTWRITER &&
131
- testsEtendusDeLEnveloppe(env).some(d => rel.startsWith(`${d}/`)) &&
132
- langage.estUnTest(file, copie)?.test
133
- ) {
134
- return null;
135
- }
136
- const tenant = paquetQuiTient(rel, liste);
137
- const paquet = tenant === '.' ? 'la racine du dépôt' : tenant;
138
- return {
139
- paquet,
140
- chemin: rel,
141
- racine: tenant === '.',
142
- raison: `⛔ hors-plan — ${rel} est dans ${paquet}, hors des paquets du plan (${plan.join(', ')}) : ta séance s'arrête là, et le superviseur étend le plan ou refuse l'écriture.`,
143
- };
144
- }
145
-
146
- // The text of the file at <file>, null when there is none.
147
- const lu = file => (existsSync(file) ? readFileSync(file, 'utf8') : null);
148
-
149
- // The text the write <input> leaves at <file>: a Write's content, the file's text with each
150
- // replacement of an Edit or a MultiEdit, as Claude Code applies them; null for another tool.
151
- function texteApres(input, file) {
152
- const t = input.tool_input ?? {};
153
- const remplacer = (texte, e) =>
154
- e.replace_all
155
- ? texte.split(e.old_string ?? '').join(e.new_string ?? '')
156
- : texte.replace(e.old_string ?? '', () => e.new_string ?? '');
157
- if (input.tool_name === 'Write') {
158
- return t.content ?? '';
159
- }
160
- if (input.tool_name === 'Edit') {
161
- return remplacer(lu(file) ?? '', t);
162
- }
163
- if (input.tool_name === 'MultiEdit') {
164
- return (t.edits ?? []).reduce(remplacer, lu(file) ?? '');
165
- }
166
- return null;
167
- }
168
-
169
- // The ticket id of the launch prompt. A sub-agent's prompt opens its own transcript, next to the
170
- // session's; an agent launched as its own session (`claude --agent`) has it in the session's.
171
- function ticketOf(input) {
172
- if (!input.transcript_path) {
173
- return null;
174
- }
175
- const transcript = input.agent_id
176
- ? path.join(
177
- input.transcript_path.replace(/\.jsonl$/, ''),
178
- 'subagents',
179
- `agent-${input.agent_id}.jsonl`
180
- )
181
- : input.transcript_path;
182
- let first;
183
- try {
184
- first = readFileSync(transcript, 'utf8')
185
- .split('\n')
186
- .filter(Boolean)
187
- .map(l => JSON.parse(l))
188
- .find(e => e.type === 'user');
189
- } catch {
190
- return null;
191
- }
192
- const content = first?.message?.content;
193
- const text = Array.isArray(content) ? content.map(c => c.text ?? '').join('\n') : content;
194
- const m = /TON TICKET\s*:\s*([A-Za-z0-9_.-]+)/.exec(text ?? '');
195
- return m ? m[1] : null;
196
- }
197
-
198
- function ticketDescription(id, cwd) {
199
- try {
200
- const out = execFileSync('bd', ['show', id, '--json'], {
201
- cwd,
202
- encoding: 'utf8',
203
- stdio: 'pipe',
204
- maxBuffer: 256 * 1024 * 1024,
205
- });
206
- return JSON.parse(out)[0]?.description ?? null;
207
- } catch {
208
- return null;
209
- }
210
- }
211
-
212
- // The refusal reason for this hook input, or null when the write is allowed.
213
- export function refusal(role, input, { tmp = tmpdir(), describe = ticketDescription } = {}) {
214
- if (!WRITE_TOOLS.has(input.tool_name)) {
215
- return null;
216
- }
217
- const raw = input.tool_input?.file_path ?? input.tool_input?.notebook_path;
218
- if (!raw) {
219
- return null;
220
- }
221
- const cwd = input.cwd ?? process.cwd();
222
- const file = path.resolve(cwd, raw);
223
- if (isScratch(file, tmp)) {
224
- return null;
225
- }
226
- const racine = racineDe(file) ?? cwd;
227
- const langage = langageDeLaCopie(racine);
228
- const classe = langage.estUnTest(file, racine);
229
- const testwriter = classe !== null;
230
-
231
- if (role === TESTWRITER) {
232
- if (testwriter || langage.manifestes.verrous.includes(path.relative(racine, file))) {
233
- return null;
234
- }
235
- const apres = texteApres(input, file);
236
- const hors =
237
- apres === null ? null : langage.manifestes.horsDesTests(file, racine, lu(file), apres);
238
- if (hors?.length === 0) {
239
- return null;
240
- }
241
- const regle =
242
- "Le testwriter écrit seulement des fichiers de test, la matière de test partagée et, d'un manifeste ou d'un fichier de code, la part de ses tests";
243
- return hors
244
- ? `${regle} ; ce changement de ${raw} touche aussi ${hors.join(', ')}. Le reste du fichier revient au développeur.`
245
- : `${regle} ; ${raw} n'est rien de cela. Le code revient au développeur.`;
246
- }
247
- if (role === 'developpeur') {
248
- if (testwriter) {
249
- return classe.test
250
- ? `Les tests appartiennent au testwriter : ${raw} est un fichier de test. Un test faux se signale au superviseur.`
251
- : `La matière de test partagée appartient au testwriter : ${raw} en fait partie. Un besoin de matière se signale au superviseur.`;
252
- }
253
- const id = ticketOf(input);
254
- if (!id) {
255
- return 'Ton ticket est introuvable : ton message de lancement porte « TON TICKET : <id> ».';
256
- }
257
- const description = describe(id, input.cwd);
258
- if (description === null) {
259
- return `Le ticket ${id} est illisible par bd.`;
260
- }
261
- return sansArchitecture(id, description);
262
- }
263
- if (role === 'direct') {
264
- // The agent of a direct writes tests and code together; the envelope of its plan (`horsDuPlan`)
265
- // bounds its writes, and its ticket needs no « ## Architecture » section.
266
- return null;
267
- }
268
- return `Rôle inconnu du verrou : ${role}.`;
269
- }
270
-
271
- if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
272
- const input = JSON.parse(readFileSync(0, 'utf8'));
273
- // A project the lock cannot judge (no language declared, scripts/langages.mjs) is refused, as a
274
- // hook that throws exits 1, which Claude Code lets pass.
275
- let stop = null;
276
- let reason = null;
277
- try {
278
- stop = horsDuPlan(input, { role: process.argv[2] });
279
- if (!stop) {
280
- reason = refusal(process.argv[2], input);
281
- }
282
- } catch (e) {
283
- reason = e.message;
284
- }
285
- if (stop) {
286
- // The mark for the circuit; the stop below is the hook's answer, mark or not.
287
- try {
288
- writeFileSync(path.join(tmpdir(), MARQUE_HORS_PLAN), stop.raison);
289
- writeFileSync(
290
- path.join(tmpdir(), MARQUE_HORS_PLAN_FAIT),
291
- JSON.stringify({ chemin: stop.chemin, paquet: stop.paquet, racine: stop.racine })
292
- );
293
- } catch {
294
- // A working directory gone leaves no mark; the session still stops.
295
- }
296
- process.stdout.write(
297
- `${JSON.stringify({
298
- continue: false,
299
- stopReason: stop.raison,
300
- hookSpecificOutput: {
301
- hookEventName: 'PreToolUse',
302
- permissionDecision: 'deny',
303
- permissionDecisionReason: stop.raison,
304
- },
305
- })}\n`
306
- );
307
- } else if (reason) {
308
- process.stderr.write(reason + '\n');
309
- process.exitCode = 2;
310
- }
311
- }