@roomi-fields/grillhouse 0.42.0 → 0.43.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.
@@ -5,5 +5,5 @@
5
5
  "author": {
6
6
  "name": "Romain Peyrichou"
7
7
  },
8
- "version": "0.42.0"
8
+ "version": "0.43.1"
9
9
  }
package/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.43.1] - 2026-11-17
10
+
11
+ - **A lot that removes a generated file with its command enters main** (grillhouse-1k7): the integration, the queue and the move of a copy onto main played the command of every generated file a lot touches, read in main's `package.json`, even when the lot removes that file, its script and its entry of `grillhouse.engendres`: the command, whose script the lot deletes, failed, and the lot was refused (SyntHub, SH-br0.3, « python3 scripts/build_device_index.py … can't open file »). An entry the tree where the lot is applied no longer declares (`encoreDeclares` of `scripts/engendres.mjs`) is not played, and its files follow the lot: a deletion is done whatever main wrote since, any other change is applied as a file of the lot (`poserLesRetires`, `prendreLesEngendres`). The command line stays main's: a lot removes one, it writes none. **Action for projects**: none; a circuit stopped on that refusal resumes (`--reprendre`).
12
+
13
+ ## [0.43.0] - 2026-11-17
14
+
15
+ - **The day of the board counts the tokens since the day's marker, as it counts the time** (grillhouse-38t): a session still open counted in the day the part of its turns since the marker, but all the tokens of its transcript — a supervisor's session opened days ago read « jour 6 min · 37,0 M » right after `/grillhouse newday` (OSC Bridge). A measure that holds its tokens by minute now counts in the day those of the minutes since the marker (`jetonsDuJour`); a register line without them counts whole in the day it ended, as before. And the time of the supervisor's own session counts neither in the day nor in the cumul, its tokens still do: open for weeks, each of its turns counted from the request to the end of the answer, its waits included — 2 025 h of « travail » for one session of OSC Bridge, where SyntHub's whole cumul read 135 h; the time of the two figures is now the work of the agents and of the circuits. **Action for projects**: none.
16
+
17
+ - **A crate without a test does not turn the pass of its project red** (grillhouse-jhf): the skeleton of a crate (`npx grillhouse paquet`) declares its target of integration tests, `tests/it/main.rs`, with no test in it, as the charter has it; nextest, played on the whole crate, ended in error (« no tests to run »), so two crates born out of the circuit turned red the final pass of every circuit of their project until their own ticket of code entered (OSD, osd-cli and osd-formats, circuit OSD-b91.7). The day of a whole crate now plays nextest with `--no-tests=pass`; a target or a module named that plays no test stays an error. **Action for projects**: none.
18
+
19
+ - **The board writes a duration of an hour or more without spaces, and a billion tokens in G** : « 1h16 », not « 1 h 16 » (`duree` of `scripts/tableau.mjs`), on every line of the board and of the status line; a count of tokens of a billion or more is written « 1,2 G » (`k`), where it read « 1234,5 M », and a count that would round to a thousand of its unit takes the next one. **Action for projects**: none.
20
+
21
+ - **A pass never plays more test processes than the machine has cores, and is cut before the memory runs out** (grillhouse-anz): a heavy pass played half the cores as tasks side by side, each task of tests keeping Vitest's own default, every core — up to 6 × 11 test processes on 12 cores — and read the memory at its start alone. On a project whose test workers weigh 1.5 GB (BPScript, a pass replayed whole after an update), 19 of them took 28 GB, memory and swap ran out and the kernel killed the user's session, every Claude session with it. Besides, the bound of a session of an agent (`GRILLHOUSE_TRAVAILLEURS`, cores ÷ places) never reached the tests: Turborepo's strict mode drops a variable the root's `globalPassThroughEnv` does not name. Three changes: the variable joins `globalPassThroughEnv` (the generator writes it, the guard `turbo-des-paquets` demands it); a pass gives each task of tests the cores shared between the tasks of tests side by side (`travailleursDeLaPasse`: 2 workers on 12 cores and 6 tasks, 12 in all); and the run of Turborepo plays under a watch of the memory (`scripts/garde-de-la-memoire.mjs`, as earlyoom and systemd-oomd), which ends the command and every process it started when the memory available and the free swap fall together under 4 GB, or when the machine waits for its memory half of the time (`/proc/pressure/memory`, `full avg10` at 50 %, which a swap held in memory reaches first) — the pass says why and ends at 75, « à repasser », and a circuit counts that 75 as a replay (`memoire-coupee.txt` in the results of the pass), so that a pass the memory cuts again goes up to the supervisor instead of waiting without end. The share counts the packages that hold tests, not those a pass plays again: on a project of many packages where few replay, each task of tests has fewer workers than the cores left idle would allow, and cargo and pytest take the same bound in a pass (`-j`, `-n`). **Action for projects**: `npx grillhouse maj`, which writes `GRILLHOUSE_TRAVAILLEURS` in the root's `turbo.json`.
22
+
23
+ - **The board says the gesture when the command `bd` is missing** (grillhouse-4t9): a session opened under a Node where Beads is not installed (a global package of npm follows its Node: the move to Node 26 leaves it behind) showed « Tickets illisibles : spawnSync bd ENOENT » on every board, the error of the system and no gesture. The alert now says « la commande bd est absente du PATH de cette séance » with its command (`npm install -g @beads/bd`), as the session start names it under « Manque » ; any other fault of Beads keeps its first line. **Action for projects**: none; after a change of Node, install Beads again under it (`npm install -g @beads/bd`).
24
+
9
25
  ## [0.42.0] - 2026-11-16
10
26
 
11
27
  - **The guard refuses a style script of the root that launches the packages again** (grillhouse-6dt): the root keeps its own files (grillhouse-44b.9), and the guard `turbo-des-paquets` refused a root `lint` or `format:check` that names a file a package holds, but read paths alone; a script that delegates to the packages (`npm run lint --workspaces --if-present`, `-w <paquet>`, `turbo run lint`) names none and passed, so the root task `//#lint` played the style of every package a second time, the packages out of the frame included — BPScript's update went red on « ⛔ //#lint (code 1) », no guard naming the script. The guard now refuses such a script by its name, with the gesture. **Action for projects**: a project whose root `lint` or `format:check` launches its packages removes it, or reduces it to the files of the root; Turborepo plays the script of each package.
@@ -37,7 +37,7 @@ interface publiée…>. Le cadre et l'architecture montent toujours (charte comm
37
37
 
38
38
  ## Commandes
39
39
 
40
- - `npm test` (Turborepo : construction, puis tests ; une tâche dont rien n'a bougé est relue de son cache, `npm run test:forcer` rejoue) · `npm test -- <chemins>` (un lancement ciblé : chaque chemin écrit depuis la racine, joué dans son paquet, avec les constructions dont ses tests dépendent, relues du cache ; ses tests rejouent dès que bouge ce qu'ils importent ; un lancement qui ne joue aucun test échoue ; un test de nuit nommé est refusé, la nuit seule le joue ; une mesure de temps — un banc, un témoin de temps — se joue quand son propre fichier est nommé, sous la mesure du temps) · `npm run verifier` (après la construction, les gardes du cadre, celles du projet — son script `gardes` —, le typage de chaque paquet — son script `typecheck`, ses sources et ses tests —, la mise en forme et le lint de la racine — ses scripts `format:check` et `lint`, joués quand ils existent — et les tests, côte à côte, sous le verrou de la machine, sans aucune mesure de temps, que joue la nuit seule : ce que jouent l'intégration, la file, la CI et la nuit ; mesuré contre le dernier vert, un paquet rejoué joue les tests que Vitest relie aux fichiers changés depuis, tous quand un changement sort de son graphe ; 0 vert, 1 rouge, un délai dépassé compris ; 75 quand l'attente du verrou de la machine ou de place sous /tmp atteint sa borne) · `npm run verifier -- --tout` (la passe complète, chaque test joué pour de vrai : ce que joue la nuit) · `npm run verifier -- --gardes` (les gardes, la mise en forme et le lint, même verdict : ce que joue le relecteur) · `npm run typecheck` · `npm run lint` · `npm run format:check`.
40
+ - `npm test` (Turborepo : construction, puis tests ; une tâche dont rien n'a bougé est relue de son cache, `npm run test:forcer` rejoue) · `npm test -- <chemins>` (un lancement ciblé : chaque chemin écrit depuis la racine, joué dans son paquet, avec les constructions dont ses tests dépendent, relues du cache ; ses tests rejouent dès que bouge ce qu'ils importent ; un lancement qui ne joue aucun test échoue ; un test de nuit nommé est refusé, la nuit seule le joue ; une mesure de temps — un banc, un témoin de temps — se joue quand son propre fichier est nommé, sous la mesure du temps) · `npm run verifier` (après la construction, les gardes du cadre, celles du projet — son script `gardes` —, le typage de chaque paquet — son script `typecheck`, ses sources et ses tests —, la mise en forme et le lint de la racine — ses scripts `format:check` et `lint`, joués quand ils existent — et les tests, côte à côte, sous le verrou de la machine, sans aucune mesure de temps, que joue la nuit seule : ce que jouent l'intégration, la file, la CI et la nuit ; mesuré contre le dernier vert, un paquet rejoué joue les tests que Vitest relie aux fichiers changés depuis, tous quand un changement sort de son graphe ; 0 vert, 1 rouge, un délai dépassé compris ; 75 quand l'attente du verrou de la machine ou de place sous /tmp atteint sa borne, ou quand la veille de la mémoire coupe la passe avant que le système ne tue) · `npm run verifier -- --tout` (la passe complète, chaque test joué pour de vrai : ce que joue la nuit) · `npm run verifier -- --gardes` (les gardes, la mise en forme et le lint, même verdict : ce que joue le relecteur) · `npm run typecheck` · `npm run lint` · `npm run format:check`.
41
41
  - Préfixe des tickets : `<prefixe>-`.
42
42
  - La politique de poussée : la clé `grillhouse.poussee` du `package.json` (`commit` : la branche où
43
43
  part chaque commit, main par défaut ; `nuit` : la branche où la nuit pousse son commit vert ;
@@ -59,8 +59,9 @@ interface publiée…>. Le cadre et l'architecture montent toujours (charte comm
59
59
  chaque motif depuis la racine : un fichier qu'un lecteur ne peut pas construire, une page lue
60
60
  sur GitHub ou une somme de contrôle publiée ; l'intégration, la file et l'avance d'une copie
61
61
  sur main ne le fusionnent pas, elles prennent la version de main et rejouent sa commande sur le
62
- lot appliqué ; lue dans l'arbre principal ; une clé sans commande, sans fichiers ou avec un
63
- motif hors du dépôt est refusée par son nom avant tout travail).
62
+ lot appliqué ; lue dans l'arbre principal ; une entrée que le lot retire de la clé n'est plus
63
+ rejouée, et ses fichiers suivent le lot, leur suppression comprise ; une clé sans commande, sans
64
+ fichiers ou avec un motif hors du dépôt est refusée par son nom avant tout travail).
64
65
  - Le nombre de circuits à la fois : la clé `grillhouse.circuits` du `package.json` (un entier
65
66
  ≥ 1, **1** quand elle est absente : les circuits actifs du projet à la fois, que la file des
66
67
  tickets tient ; un circuit arrêté sur une question rend sa place, et repris, la redemande avant
@@ -5,7 +5,8 @@
5
5
  "GRILLHOUSE_RESULTATS",
6
6
  "GRILLHOUSE_CHANGEMENTS",
7
7
  "GRILLHOUSE_AVANCEMENT",
8
- "TMPDIR"
8
+ "TMPDIR",
9
+ "GRILLHOUSE_TRAVAILLEURS"
9
10
  ],
10
11
  "tasks": {
11
12
  "build": {
@@ -5,7 +5,8 @@
5
5
  "GRILLHOUSE_RESULTATS",
6
6
  "GRILLHOUSE_CHANGEMENTS",
7
7
  "GRILLHOUSE_AVANCEMENT",
8
- "TMPDIR"
8
+ "TMPDIR",
9
+ "GRILLHOUSE_TRAVAILLEURS"
9
10
  ],
10
11
  "tasks": {
11
12
  "build": {
@@ -298,7 +298,8 @@ L'intégration, la file qui replace une branche sur main et l'avance d'une copie
298
298
  (`travail-de-la-copie.mjs`, comme le report d'une branche renvoyée) ne fusionnent pas ces
299
299
  fichiers : un lot qui touche l'un d'eux ou ce qu'il lit prend la version de main, puis la commande
300
300
  rejoue hors de l'enveloppe, avec les outils du projet, sur le lot appliqué, et ce qu'elle écrit
301
- entre dans le lot ; la passe finale (4.2) ne les régénère que si un rouge d'une passe tombe
301
+ entre dans le lot ; une entrée que le lot retire de la clé ne se rejoue pas, et ses fichiers
302
+ suivent le lot, leur suppression comprise, comme un genrule de Bazel retiré avec sa sortie ; la passe finale (4.2) ne les régénère que si un rouge d'une passe tombe
302
303
  dans leurs fichiers. L'intégration régénère aussi une référence du cadre dès que le lot touche ce
303
304
  qu'elle lit : l'index des interfaces se refait quand un `INTERFACE.md` change. Un conflit sur tout autre fichier
304
305
  refuse le lot ; une commande en échec, sa commande et sa sortie nommées, ou un fichier changé
@@ -963,7 +964,10 @@ nombre de cœurs et si 4 Go au moins sont libres, deux départs étant espacés
963
964
  espacement), garde le rang d'arrivée du circuit (pris à son lancement) et s'arrête à la borne de
964
965
  l'attente du verrou, 75. Chaque séance joue ses tests sur max(1, cœurs ÷ places) travailleurs
965
966
  (`GRILLHOUSE_TRAVAILLEURS`, lu par le module de chaque langage : `maxWorkers` de Vitest, `-j` de
966
- cargo et nextest, `-n` de pytest), sous `nice` et `ionice` ; une passe lourde garde tous les cœurs.
967
+ cargo et nextest, `-n` de pytest), sous `nice` et `ionice` ; la variable atteint chaque tâche par le
968
+ `globalPassThroughEnv` de la racine, que le mode strict de Turborepo exige. Une passe lourde partage
969
+ les cœurs entre ses tâches de tests côte à côte : les processus de tests d'une passe ne dépassent
970
+ jamais le nombre de cœurs.
967
971
  Une passe lourde prend sa place, puis le verrou exclusif de la machine ; une passe ciblée part
968
972
  pendant qu'une passe lourde tient le verrou.
969
973
 
@@ -996,7 +1000,14 @@ reprend, comme le serveur de tâches de GNU make. L'attente a une borne, 60 min
996
1000
  (`GRILLHOUSE_ATTENTE_MACHINE_MS`), plus longue que la plus longue passe complète mesurée : au-delà,
997
1001
  la mesure s'arrête « à repasser » (code 75), comme `flock -w`. Un verrou tenu par un ancêtre de
998
1002
  celui qui attend est un blocage : l'attente le dit tout de suite et s'arrête, rouge. La passe
999
- borne ses tâches côte à côte à la moitié des cœurs. Ainsi une mesure rend le résultat du code, et
1003
+ borne ses tâches côte à côte à la moitié des cœurs, et les travailleurs de chaque tâche de tests aux
1004
+ cœurs partagés entre elles (`travailleursDeLaPasse`). Elle joue sous la veille de la mémoire
1005
+ (`scripts/garde-de-la-memoire.mjs`, comme earlyoom et systemd-oomd) : quand la mémoire disponible et
1006
+ l'échange libre passent ensemble sous 4 Go, ou que la machine attend sa mémoire la moitié du temps
1007
+ (`/proc/pressure/memory`, `full avg10` à 50 %), la veille arrête la commande et chaque processus
1008
+ qu'elle a lancé ; la passe dit pourquoi et finit « à repasser » (75), avant que le noyau ne tue. Ce
1009
+ 75 n'est pas une attente de la machine : le circuit le compte comme un rejeu (`memoire-coupee.txt`
1010
+ dans les résultats de la passe), et une passe coupée de nouveau monte au superviseur. Ainsi une mesure rend le résultat du code, et
1000
1011
  non celui d'une autre mesure à côté, et aucune passe ne reste figée sans le dire.
1001
1012
 
1002
1013
  **Le cadre passe avant les projets** : une mesure jouée dans le dépôt du cadre lui-même (le
package/docs/INTERFACE.md CHANGED
@@ -366,10 +366,11 @@ l'interruption), la pression de la machine et son verrou, les places de la machi
366
366
  l'environnement de ses enfants, son code de sortie, ou celui de l'attente qui s'arrête, 75 à sa
367
367
  borne, 1 pour un serveur qui ne répond pas ; `avecLaMachineEtUnePlace` : une passe lourde, la place
368
368
  puis le verrou ; aucune place dans la CI ni dans l'enveloppe d'un agent, que couvre la place de sa
369
- séance), les travailleurs d'une séance
370
- (`travailleursDeLaSeance(env)` : le nombre que donne `GRILLHOUSE_TRAVAILLEURS`, max(1, cœurs ÷
371
- places), que le module passe à son outil — `maxWorkers`, `-j`, `-n` — ou `null` pour une passe
372
- lourde, qui garde tous les cœurs ; une valeur fautive est refusée par son nom), le dernier vert, le
369
+ séance), les travailleurs des tests d'une tâche
370
+ (`travailleursDeLaSeance(env)` : le nombre que donne `GRILLHOUSE_TRAVAILLEURS`, que posent une
371
+ séance (max(1, cœurs ÷ places)) et une passe lourde (les cœurs partagés entre ses tâches de tests
372
+ côte à côte), et que le module passe à son outil — `maxWorkers`, `-j`, `-n` — ou `null` sans la
373
+ variable, l'outil gardant son défaut ; une valeur fautive est refusée par son nom), le dernier vert, le
373
374
  registre des résultats (`registre-des-resultats.mjs` : `garderLeRegistre(etat, rapports)`, les
374
375
  tests verts de chaque fichier d'une passe, que la passe complète écrit quand `GRILLHOUSE_RESULTATS`
375
376
  nomme son dossier de résultats ; `lireLeRegistre(racine)`, le registre de la branche quand son
@@ -71,10 +71,16 @@ const etat = atom({ plugin: 'grillhouse', key: 'etat' } as const, {
71
71
  } as Etat)
72
72
 
73
73
  export const k = (n: number) =>
74
- n >= 1e6 ? `${(n / 1e6).toFixed(1).replace('.', ',')} M` : n >= 1e3 ? `${Math.round(n / 1e3)} k` : `${n}`
74
+ n >= 999.95e6
75
+ ? `${(n / 1e9).toFixed(1).replace('.', ',')} G`
76
+ : n >= 999.5e3
77
+ ? `${(n / 1e6).toFixed(1).replace('.', ',')} M`
78
+ : n >= 1e3
79
+ ? `${Math.round(n / 1e3)} k`
80
+ : `${n}`
75
81
  export const duree = (ms: number) => {
76
82
  const min = Math.round(ms / 60_000)
77
- return min < 60 ? `${min} min` : `${Math.floor(min / 60)} h ${String(min % 60).padStart(2, '0')}`
83
+ return min < 60 ? `${min} min` : `${Math.floor(min / 60)}h${String(min % 60).padStart(2, '0')}`
78
84
  }
79
85
  const STATUTS: Record<string, string> = {
80
86
  open: 'ouvert',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomi-fields/grillhouse",
3
- "version": "0.42.0",
3
+ "version": "0.43.1",
4
4
  "description": "Roomi's Grillhouse: the frame's scripts, called by one command, grillhouse <sous-commande>",
5
5
  "keywords": [
6
6
  "claude-code",
@@ -26,7 +26,7 @@ import {
26
26
  } from 'node:fs';
27
27
  import path from 'node:path';
28
28
  import { avecLAvancementDuTravail } from './avancement.mjs';
29
- import { A_REPASSER } from './codes-de-sortie.mjs';
29
+ import { A_REPASSER, MEMOIRE_COUPEE } from './codes-de-sortie.mjs';
30
30
  import { ecouteLesBranchesDeTicket } from './ci-des-branches.mjs';
31
31
  import { BASE_DU_LOT, DEPUIS_LE_VERT } from './dernier-vert.mjs';
32
32
  import { empreinteDEtape } from './empreinte-d-etape.mjs';
@@ -1405,7 +1405,7 @@ function npm(ctx, etape, args, env = {}, cwd = ctx.copie) {
1405
1405
  const oublier = nommerLAvancement({ env: envMachine, dossier: avancement });
1406
1406
  try {
1407
1407
  // A targeted pass plays on its share of the cores under nice and ionice; a heavy one
1408
- // keeps every core.
1408
+ // shares the cores between its own tasks of tests.
1409
1409
  const lancement = lancementDeLaPasse({
1410
1410
  lourde,
1411
1411
  cmd: 'npm',
@@ -1440,8 +1440,11 @@ function npm(ctx, etape, args, env = {}, cwd = ctx.copie) {
1440
1440
  }
1441
1441
  );
1442
1442
  const code = r.status ?? 1;
1443
- // The 75 of `npm run verifier` is its wait for the lock or for room under /tmp at its bound.
1444
- return { code, dossier, attente: finale && code === A_REPASSER };
1443
+ // The 75 of `npm run verifier` is its wait for the lock or for room under /tmp at its bound,
1444
+ // which waits again without counting; cut by the watch of its memory (MEMOIRE_COUPEE in its
1445
+ // results), it is a replay that counts.
1446
+ const coupee = existsSync(path.join(dossier, MEMOIRE_COUPEE));
1447
+ return { code, dossier, attente: finale && code === A_REPASSER && !coupee };
1445
1448
  } catch (e) {
1446
1449
  if (!(e instanceof AttenteDeLaMachine)) {
1447
1450
  throw e;
@@ -1949,7 +1952,8 @@ export function controles(ctx, finale, restreinte = null, reportes = null, fichi
1949
1952
  : commandesDuPlan(ctx, liste, fichiers);
1950
1953
  const resultats = commandes.map(({ args, env }) => {
1951
1954
  let r = npm(ctx, 'controles', args, env);
1952
- // The 75 of verifier is final (its wait for the lock reached its bound); a command of the
1955
+ // The 75 of verifier is final (its wait for the lock reached its bound, or the watch of its
1956
+ // memory cut it); a command of the
1953
1957
  // checks plays once more, the gesture `rejeu`.
1954
1958
  if (r.code === A_REPASSER && !finale) {
1955
1959
  geste(ctx, 'rejeu');
@@ -7,3 +7,9 @@
7
7
  // wait of the lock of the machine at its bound (scripts/verrou-de-machine.mjs), a stop of the
8
8
  // circuit that a gesture settles (scripts/etapes.mjs, ARRETS).
9
9
  export const A_REPASSER = 75;
10
+
11
+ /**
12
+ * The file a pass cut by the watch of its memory (scripts/garde-de-la-memoire.mjs) leaves in its
13
+ * results directory, its reason inside: its 75 is no wait of the machine, and counts as a replay.
14
+ */
15
+ export const MEMOIRE_COUPEE = 'memoire-coupee.txt';
@@ -22,6 +22,10 @@
22
22
  // (scripts/integration/file.mjs) and the move of a copy onto main
23
23
  // (scripts/enveloppe/travail-de-la-copie.mjs) call it on the tree where they applied the lot,
24
24
  // main's version of each file taken.
25
+ // - `encoreDeclares` keeps the generated files the tree where the lot is applied still declares, by
26
+ // their names: as a genrule of Bazel removed with its output in one change plays no more, the
27
+ // one a lot removes from the key is not played, and its files follow the lot, their deletion
28
+ // too. The command line stays main's: a lot removes one, it writes none.
25
29
  import { existsSync, readFileSync } from 'node:fs';
26
30
  import path from 'node:path';
27
31
  import { arbrePrincipal } from './outils-cles.mjs';
@@ -124,6 +128,134 @@ export function engendresDe(dir) {
124
128
  return engendres;
125
129
  }
126
130
 
131
+ // The names the text <texte> of a package.json declares under `grillhouse.engendres`, or null when
132
+ // it does not read.
133
+ function nomsDeclares(texte) {
134
+ try {
135
+ const declares = JSON.parse(texte)?.grillhouse?.engendres;
136
+ return new Set(
137
+ declares && typeof declares === 'object' && !Array.isArray(declares)
138
+ ? Object.keys(declares)
139
+ : []
140
+ );
141
+ } catch {
142
+ return null;
143
+ }
144
+ }
145
+
146
+ /**
147
+ * The generated files of <engendres> that the package.json of the tree <arbre>, where a lot is
148
+ * applied, still declares under their names. When it does not read (absent, or in conflict), the
149
+ * two versions of the conflict decide (<etages>, `{ base, lot }`, the text of the package.json
150
+ * before the lot and with it): the lot removes the ones its base declares and it does not. All of
151
+ * them when nothing reads.
152
+ * @template {{ nom: string }} E
153
+ * @param {E[]} engendres
154
+ * @param {string} arbre
155
+ * @param {(() => { base: string, lot: string }) | null} [etages]
156
+ * @returns {E[]}
157
+ */
158
+ export function encoreDeclares(engendres, arbre, etages = null) {
159
+ let texte = null;
160
+ try {
161
+ texte = readFileSync(path.join(arbre, 'package.json'), 'utf8');
162
+ } catch {
163
+ return engendres;
164
+ }
165
+ const noms = nomsDeclares(texte);
166
+ if (noms) {
167
+ return engendres.filter(e => noms.has(e.nom));
168
+ }
169
+ const { base, lot } = etages?.() ?? { base: '', lot: '' };
170
+ const avant = nomsDeclares(base);
171
+ const avec = nomsDeclares(lot);
172
+ return avant && avec ? engendres.filter(e => !avant.has(e.nom) || avec.has(e.nom)) : engendres;
173
+ }
174
+
175
+ /**
176
+ * What the lots applied in the tree <arbre> ask of the references <references> (`{ nom, entiers }`,
177
+ * those of the project, <duProjet>, among them): `suivis`, the files of <entiers> (the files of
178
+ * the lots a reference writes in full, left out of their application) that follow the lots, the
179
+ * ones no reference still declared writes; `rejouees`, the references of <touchees> (those the
180
+ * lots touch) still declared, whose commands play. A reference of the frame is always declared.
181
+ * @template {{ nom: string, entiers: string[] }} R
182
+ * @param {{ references: R[], duProjet: R[], entiers: string[], touchees: R[], arbre: string }} o
183
+ * @returns {{ suivis: string[], rejouees: R[] }}
184
+ */
185
+ export function partDesLots({ references, duProjet, entiers, touchees, arbre }) {
186
+ const declares = encoreDeclares(duProjet, arbre);
187
+ const retire = r => duProjet.includes(r) && !declares.includes(r);
188
+ return {
189
+ suivis: entiers.filter(f => !references.some(r => !retire(r) && couvertPar(r.entiers, f))),
190
+ rejouees: touchees.filter(r => !retire(r)),
191
+ };
192
+ }
193
+
194
+ /**
195
+ * The generated files of <engendres> still declared in the tree <arbre> that the lot of
196
+ * <fichiers> touches: those whose commands play once the lot is applied there.
197
+ * @template {{ nom: string, entiers: string[], lit: string[] }} E
198
+ * @param {E[]} engendres
199
+ * @param {string} arbre
200
+ * @param {string[]} fichiers
201
+ * @returns {E[]}
202
+ */
203
+ export const aRejouer = (engendres, arbre, fichiers) =>
204
+ touchesPar(encoreDeclares(engendres, arbre), fichiers);
205
+
206
+ /**
207
+ * Applies to the tree of <dansCopie> (git in the tree) the files <fichiers> of the lots <lots>
208
+ * (patch files) that an earlier application left out, those of a generated file the lots remove
209
+ * from the key: a deletion is done whatever main's version is, any other change is applied three
210
+ * ways, to the index too. Null, or the refusal.
211
+ * @param {{ lots: string[], fichiers: string[], dansCopie: (...args: string[]) => import('node:child_process').SpawnSyncReturns<string> }} o
212
+ * @returns {string | null}
213
+ */
214
+ export function poserLesRetires({ lots, fichiers, dansCopie }) {
215
+ if (!fichiers.length) {
216
+ return null;
217
+ }
218
+ const seuls = fichiers.map(f => `--include=${f}`);
219
+ for (const p of lots) {
220
+ const supprimes = dansCopie('apply', '--summary', ...seuls, p)
221
+ .stdout.split('\n')
222
+ .map(l => /^ delete mode \d+ (.+)$/.exec(l)?.[1])
223
+ .filter(f => f !== undefined && fichiers.includes(f));
224
+ if (
225
+ supprimes.length &&
226
+ dansCopie('rm', '-q', '-f', '--ignore-unmatch', '--', ...supprimes).status !== 0
227
+ ) {
228
+ return `Les fichiers que le lot ${p} supprime ne se retirent pas :\n${supprimes.map(f => ` ${f}`).join('\n')}`;
229
+ }
230
+ const restent = fichiers.filter(f => !supprimes.includes(f)).map(f => `--include=${f}`);
231
+ if (restent.length) {
232
+ const r = dansCopie('apply', '--3way', '--index', '--allow-empty', ...restent, p);
233
+ if (r.status !== 0) {
234
+ return `Le lot ${p} ne s'applique pas :\n${r.stdout}${r.stderr}`;
235
+ }
236
+ }
237
+ }
238
+ return null;
239
+ }
240
+
241
+ /**
242
+ * Resolves the conflicts <conflits> of a rebase stopped in the tree of <dansCopie>, each on a file
243
+ * a generated file writes in full: main's version (`--ours`, the base of the rebase) for one of
244
+ * <vivants>, the generated files the tree still declares; the branch's version, its deletion too,
245
+ * for the others. Whether every conflict is resolved.
246
+ * @param {{ conflits: string[], vivants: { entiers: string[] }[], dansCopie: (...args: string[]) => import('node:child_process').SpawnSyncReturns<string> }} o
247
+ */
248
+ export function prendreLesEngendres({ conflits, vivants, dansCopie }) {
249
+ const prendre = (cote, f) =>
250
+ dansCopie('checkout', cote, '--', f).status === 0 && dansCopie('add', '--', f).status === 0;
251
+ return conflits.every(f =>
252
+ vivants.some(e => couvertPar(e.entiers, f))
253
+ ? prendre('--ours', f)
254
+ : prendre('--theirs', f) ||
255
+ dansCopie('rm', '-q', '-f', '--ignore-unmatch', '--', f).status === 0
256
+ );
257
+ }
258
+
127
259
  /**
128
260
  * The generated files of <engendres> the lot of <fichiers> touches: one of the files it writes in
129
261
  * full, or one it reads.
@@ -70,7 +70,7 @@ import { spawnSync } from 'node:child_process';
70
70
  import { existsSync, readFileSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs';
71
71
  import path from 'node:path';
72
72
  import { pathToFileURL } from 'node:url';
73
- import { couvertPar, engendresDe, regenerer, touchesPar } from '../engendres.mjs';
73
+ import { couvertPar, encoreDeclares, engendresDe, regenerer, touchesPar } from '../engendres.mjs';
74
74
  import { avecLesDonnees, donneesDe } from '../donnees-cles.mjs';
75
75
  import { avecLesOutils, outilsDe } from '../outils-cles.mjs';
76
76
 
@@ -121,7 +121,9 @@ function lesCles(copie) {
121
121
  * deletion of a file main changed), whose patches are `restant`. With <cles> (`lesCles`), the
122
122
  * generated files the lot (or one of <autres>, the copy's untracked files) touches are left out,
123
123
  * then written again by their command once the lot applies without conflict; `refus`, a command
124
- * that fails.
124
+ * that fails. A generated file the lot removes from the key (`encoreDeclares`) follows the lot
125
+ * instead: its deletion is done, any other change applied as a file of the lot, its command not
126
+ * played.
125
127
  * @param {string} copie
126
128
  * @param {Buffer} lot
127
129
  * @param {{ engendres: any[], env: NodeJS.ProcessEnv } | null} [cles]
@@ -136,14 +138,11 @@ function appliquer(copie, lot, cles = null, autres = []) {
136
138
  const conflits = [];
137
139
  const enAttente = [];
138
140
  const gardes = [];
139
- for (const morceau of morceauxDuLot(lot)) {
140
- const noms = fichiersDuLot(copie, morceau);
141
- if (noms.length && noms.every(f => exclus.includes(f))) {
142
- continue;
143
- }
141
+ const laisses = [];
142
+ const poser = (morceau, noms) => {
144
143
  const r = git(copie, ['apply', '--3way', '--allow-empty', '-'], morceau);
145
144
  if (r.status === 0) {
146
- continue;
145
+ return;
147
146
  }
148
147
  const marques = enConflit(copie).filter(f => noms.includes(f));
149
148
  if (marques.length) {
@@ -152,13 +151,38 @@ function appliquer(copie, lot, cles = null, autres = []) {
152
151
  enAttente.push(...noms.slice(-1));
153
152
  gardes.push(morceau);
154
153
  }
154
+ };
155
+ for (const morceau of morceauxDuLot(lot)) {
156
+ const noms = fichiersDuLot(copie, morceau);
157
+ if (noms.length && noms.every(f => exclus.includes(f))) {
158
+ laisses.push({ morceau, noms });
159
+ continue;
160
+ }
161
+ poser(morceau, noms);
162
+ }
163
+ // The generated files the lot removes from the key follow the lot: main's version is not kept.
164
+ // A package.json left in conflict is read at the two versions of its conflict in the index.
165
+ const etage = n => String(git(copie, ['show', `:${n}:package.json`]).stdout);
166
+ const vivants = encoreDeclares(touches, copie, () => ({ base: etage(1), lot: etage(3) }));
167
+ for (const { morceau, noms } of laisses) {
168
+ if (noms.every(f => vivants.some(e => couvertPar(e.entiers, f)))) {
169
+ continue;
170
+ }
171
+ if (/^deleted file mode /m.test(morceau.toString('latin1'))) {
172
+ if (git(copie, ['rm', '-q', '-f', '--ignore-unmatch', '--', ...noms]).status !== 0) {
173
+ enAttente.push(...noms.slice(-1));
174
+ gardes.push(morceau);
175
+ }
176
+ } else {
177
+ poser(morceau, noms);
178
+ }
155
179
  }
156
180
  const restant = Buffer.concat(gardes);
157
- if (conflits.length || enAttente.length || !touches.length || !cles) {
181
+ if (conflits.length || enAttente.length || !vivants.length || !cles) {
158
182
  return { conflits, enAttente, restant };
159
183
  }
160
184
  const refus = regenerer({
161
- refs: touches.map(e => ({ ...e, cadre: false })),
185
+ refs: vivants.map(e => ({ ...e, cadre: false })),
162
186
  lancer: commande =>
163
187
  spawnSync('bash', ['-c', commande], {
164
188
  cwd: copie,