@roomi-fields/grillhouse 0.25.5 → 0.26.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.
- package/.claude-plugin/plugin.json +1 -1
- package/agents/testwriter.md +1 -1
- package/bin/grillhouse.mjs +20 -3
- package/cadre/templates/cargo/package.json +3 -0
- package/cadre/templates/projet/.gitattributes +1 -0
- package/cadre/templates/projet/CLAUDE.md +6 -0
- package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
- package/charte.md +10 -1
- package/docs/ARCHITECTURE.md +91 -26
- package/docs/INTERFACE.md +16 -4
- package/hooks/register.tsx +57 -16
- package/package.json +9 -3
- package/scripts/circuit.mjs +121 -19
- package/scripts/copies-finies.mjs +167 -28
- package/scripts/crochets.mjs +9 -3
- package/scripts/enveloppe/enveloppe.mjs +59 -17
- package/scripts/enveloppe/lancer.sh +15 -22
- package/scripts/enveloppe/travail-de-la-copie.mjs +188 -0
- package/scripts/etapes.mjs +1 -1
- package/scripts/fusion-du-changelog.mjs +120 -0
- package/scripts/grillhouse-maj.mjs +19 -0
- package/scripts/integration/file.mjs +196 -104
- package/scripts/jointure.d.ts +22 -1
- package/scripts/langages/cargo/binaires.json +2 -1
- package/scripts/langages/cargo/clippy.mjs +10 -2
- package/scripts/langages/cargo/commandes.mjs +19 -4
- package/scripts/langages/cargo/composants.mjs +229 -8
- package/scripts/langages/cargo/index.mjs +17 -8
- package/scripts/langages/cargo/sccache.mjs +143 -0
- package/scripts/langages/cargo/verdict.mjs +50 -10
- package/scripts/langages/typescript/index.mjs +4 -2
- package/scripts/langages/typescript/regle-des-tests.mjs +37 -0
- package/scripts/nuit.sh +15 -1
- package/scripts/outils-cles.mjs +188 -0
- package/scripts/resultats.mjs +22 -6
- package/scripts/sous-commandes.mjs +16 -0
- package/scripts/verrou-de-machine.mjs +14 -13
- package/scripts/verrous/verrou.mjs +50 -14
- package/skills/developpeur/SKILL.md +4 -0
- package/skills/explorateur/SKILL.md +3 -1
- package/skills/pitmaster/SKILL.md +6 -2
- package/skills/pitmaster/references/consigne-agent.md +3 -3
- package/skills/relecteur/SKILL.md +6 -2
- package/skills/testwriter/SKILL.md +23 -6
|
@@ -33,6 +33,18 @@
|
|
|
33
33
|
// `~/.claude`, `~/.claude.json`, the npm cache, the paths of `MAISON_EN_LECTURE` (claude, node,
|
|
34
34
|
// git and the session's tools) and the repository. No socket of the session comes back. Of
|
|
35
35
|
// the machine's credentials, only claude's own are in sight.
|
|
36
|
+
// - The tools of the project (`grillhouse.outils` of the package.json of the main tree, never of
|
|
37
|
+
// the copy, so that an agent never opens a path for its next session; `{ "<VARIABLE>":
|
|
38
|
+
// "<chemin>" }`, read by scripts/outils-cles.mjs), as Bazel declares what an action sees out of
|
|
39
|
+
// its sandbox and the environment it gets: each path comes back read-only after the declared
|
|
40
|
+
// paths of the home, before the copy and the packages of the plan, which come back in writing
|
|
41
|
+
// over it, and each variable reaches the session, the path resolved. A tool never covers a mount
|
|
42
|
+
// of the envelope: a path is refused when it is `/`, the home or holds it, holds the main tree,
|
|
43
|
+
// `/tmp`, the temporary directories, `~/.claude`, the scratchpads, the npm cache or a session
|
|
44
|
+
// directory, or lies under a hidden directory of the first level of the home (`~/.ssh`,
|
|
45
|
+
// `~/.gnupg`, `~/.aws`, `~/.config`…) but `~/.local` and `~/.cache`, or lies under or holds the
|
|
46
|
+
// keyrings `~/.local/share/keyrings`; a link is judged by its target too. A faulty key refuses the
|
|
47
|
+
// envelope, by its name, before anything is prepared.
|
|
36
48
|
// - The session gets only the environment the envelope declares (`environnementDeLaSeance`), as
|
|
37
49
|
// sudo's env_reset and bwrap's --clearenv give it: the base of a login session, claude's own
|
|
38
50
|
// configuration and credentials (`ANTHROPIC_*`, `CLAUDE_CODE_OAUTH_TOKEN`), the author of its
|
|
@@ -81,6 +93,10 @@
|
|
|
81
93
|
// the session, as Bazel writes a test's logs out of its source: what is written there leaves no
|
|
82
94
|
// trace. The envelope creates each of them on disk, empty, before the session, so that bwrap
|
|
83
95
|
// mounts over it inside the read-only package.
|
|
96
|
+
// - The lock files of the versions at the root of the copy (`manifestes.verrous` of the module of
|
|
97
|
+
// the language: cargo's Cargo.lock), which a run of the tests brings in line with the
|
|
98
|
+
// dependencies of the tests the testwriter declares, come back in writing for the `testwriter`
|
|
99
|
+
// alone, when the plan leaves the root read-only and the file exists.
|
|
84
100
|
// - The exit codes are named in `codes.mjs`.
|
|
85
101
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
86
102
|
import {
|
|
@@ -106,8 +122,9 @@ import {
|
|
|
106
122
|
|
|
107
123
|
export { paquetsDuLangage };
|
|
108
124
|
import { ouvrirBase } from '../mesure/base-de-passe.mjs';
|
|
125
|
+
import { outilsDe } from '../outils-cles.mjs';
|
|
109
126
|
|
|
110
|
-
// The role that writes the package of the shared test material.
|
|
127
|
+
// The role that writes the package of the shared test material and the lock files of the versions.
|
|
111
128
|
const ROLE_MATIERE = 'testwriter';
|
|
112
129
|
// The directories <sorties> of <dir>, each relative to it.
|
|
113
130
|
// One that a symbolic link carries out of <dir> (a `node_modules` linked to another tree's) is
|
|
@@ -214,8 +231,10 @@ export function dossierDeTravail(copie, env = process.env) {
|
|
|
214
231
|
// envelope mounts in writing, `npm_config_ignore_scripts` set to `true` (npm runs no lifecycle
|
|
215
232
|
// script: a `prepare` that writes under the read-only `.git` would fail `npm install`; the
|
|
216
233
|
// launcher installs outside the session), `TMPDIR` set to the session's working directory
|
|
217
|
-
// <travail>, and `GRILLHOUSE_ENVELOPPE` set to the plan <paquets
|
|
218
|
-
|
|
234
|
+
// <travail>, and `GRILLHOUSE_ENVELOPPE` set to the plan <paquets>; with them, each tool of the
|
|
235
|
+
// project <outils> (`grillhouse.outils`), its variable set to its path. Nothing else of <env>
|
|
236
|
+
// enters.
|
|
237
|
+
export function environnementDeLaSeance(env, { cacheNpm, paquets, travail, outils = {} }) {
|
|
219
238
|
const declare = nom =>
|
|
220
239
|
ENVIRONNEMENT_DECLARE.includes(nom) ||
|
|
221
240
|
VARIABLES_DE_CHEMIN.includes(nom) ||
|
|
@@ -223,6 +242,7 @@ export function environnementDeLaSeance(env, { cacheNpm, paquets, travail }) {
|
|
|
223
242
|
const garde = Object.entries(env).filter(([nom, v]) => v !== undefined && declare(nom));
|
|
224
243
|
return {
|
|
225
244
|
...Object.fromEntries(garde),
|
|
245
|
+
...outils,
|
|
226
246
|
npm_config_cache: cacheNpm,
|
|
227
247
|
npm_config_ignore_scripts: 'true',
|
|
228
248
|
TMPDIR: travail,
|
|
@@ -239,8 +259,9 @@ function commandeEprouvee(commande) {
|
|
|
239
259
|
// The mounts outside the copy, in bwrap's order: an empty `/tmp`; the home that holds
|
|
240
260
|
// `~/.claude` and the session directories, empty and sealed; the copy's scratchpads, the npm
|
|
241
261
|
// cache and `~/.claude` in writing; the throwaway `~/.claude.json`; over them, what the session
|
|
242
|
-
// reads without writing; the copy's project directory, in writing;
|
|
243
|
-
//
|
|
262
|
+
// reads without writing; the copy's project directory, in writing; the declared paths of the
|
|
263
|
+
// home, read-only; last, the path of each tool of the project <outils>, read-only (the plan mounts
|
|
264
|
+
// the copy and its written packages after them).
|
|
244
265
|
export function montagesDeLaSeance({
|
|
245
266
|
cacheNpm,
|
|
246
267
|
claude,
|
|
@@ -248,6 +269,7 @@ export function montagesDeLaSeance({
|
|
|
248
269
|
etatJetable,
|
|
249
270
|
scratchpads,
|
|
250
271
|
sessions = [],
|
|
272
|
+
outils = {},
|
|
251
273
|
}) {
|
|
252
274
|
const maison = path.dirname(claude);
|
|
253
275
|
return [
|
|
@@ -258,6 +280,7 @@ export function montagesDeLaSeance({
|
|
|
258
280
|
...CLAUDE_EN_LECTURE.map(nom => ({ chemin: path.join(claude, nom), ecriture: false })),
|
|
259
281
|
{ chemin: projet, ecriture: true },
|
|
260
282
|
...MAISON_EN_LECTURE.map(rel => ({ chemin: path.join(maison, rel), ecriture: false })),
|
|
283
|
+
...Object.values(outils).map(chemin => ({ chemin, ecriture: false })),
|
|
261
284
|
];
|
|
262
285
|
}
|
|
263
286
|
|
|
@@ -396,7 +419,8 @@ export function jugerComposant({ depot, composant, paquets = [] }, fs) {
|
|
|
396
419
|
// (`montagesDeLaSeance`); an emptied one marked `scelle` is sealed read-only once every mount
|
|
397
420
|
// inside it is made. `matieres` lists the packages of the shared test material, relative to the
|
|
398
421
|
// copy (`matieres` of the module of the language); `role` is the agent's role, and only the
|
|
399
|
-
// `testwriter` writes them
|
|
422
|
+
// `testwriter` writes them, and the lock files of the versions `verrous`, from the root of the copy.
|
|
423
|
+
// `magasins` lists the stores written by every run, the agent's included
|
|
400
424
|
// (the module's, `sortiesDuLangage`: Turborepo's `<main tree>/.turbo/cache`, cargo's registry,
|
|
401
425
|
// git dependencies, advisories and lock files in the home); one that does not exist is not
|
|
402
426
|
// mounted. `lectures` lists what the language's tools read (cargo's home, rustup's toolchains),
|
|
@@ -414,6 +438,7 @@ export function jugerComposant({ depot, composant, paquets = [] }, fs) {
|
|
|
414
438
|
* paquets?: string[],
|
|
415
439
|
* role?: string,
|
|
416
440
|
* matieres?: string[],
|
|
441
|
+
* verrous?: string[],
|
|
417
442
|
* montages?: { chemin: string, source?: string, ecriture?: boolean, vide?: boolean, scelle?: boolean, lien?: string }[],
|
|
418
443
|
* magasins?: string[],
|
|
419
444
|
* lectures?: string[],
|
|
@@ -430,6 +455,7 @@ export function plan(
|
|
|
430
455
|
paquets = [],
|
|
431
456
|
role,
|
|
432
457
|
matieres = [],
|
|
458
|
+
verrous = [],
|
|
433
459
|
montages = [],
|
|
434
460
|
magasins = [],
|
|
435
461
|
lectures = [],
|
|
@@ -508,6 +534,11 @@ export function plan(
|
|
|
508
534
|
const d = path.join(copie, e);
|
|
509
535
|
args.push('--bind', d, d);
|
|
510
536
|
}
|
|
537
|
+
// The lock files of the versions, which a run of the testwriter's tests brings in line with
|
|
538
|
+
// the dependencies of his tests, are written by him alone.
|
|
539
|
+
for (const v of verrous.map(v => path.join(copie, v))) {
|
|
540
|
+
if (role === ROLE_MATIERE && fs.existe(v)) args.push('--bind', v, v);
|
|
541
|
+
}
|
|
511
542
|
}
|
|
512
543
|
for (const m of matieres.map(m => path.join(copie, m))) {
|
|
513
544
|
args.push(role === ROLE_MATIERE ? '--bind' : '--ro-bind', m, m);
|
|
@@ -547,17 +578,8 @@ function envelopper(argv) {
|
|
|
547
578
|
// [A-Za-z0-9] turned into a dash; it is created here so that bwrap mounts it in writing.
|
|
548
579
|
const enTirets = copie.replace(/[^A-Za-z0-9]/g, '-');
|
|
549
580
|
const projet = path.join(claude, 'projects', enTirets);
|
|
550
|
-
mkdirSync(projet, { recursive: true });
|
|
551
581
|
const scratchpads = scratchpadsDe(copie);
|
|
552
|
-
// The session's working directory, created here inside the scratchpads that bwrap mounts.
|
|
553
582
|
const travail = dossierDeTravail(copie);
|
|
554
|
-
mkdirSync(travail, { recursive: true });
|
|
555
|
-
// `~/.claude.json` holds the permissions and servers of every project: it enters the session
|
|
556
|
-
// as a throwaway copy, in a base of its own removed on exit and swept when the envelope is
|
|
557
|
-
// killed (../mesure/base-de-passe.mjs).
|
|
558
|
-
const temporaire = ouvrirBase('enveloppe');
|
|
559
|
-
const etatJetable = path.join(temporaire.dossier, 'claude.json');
|
|
560
|
-
if (existsSync(`${claude}.json`)) copyFileSync(`${claude}.json`, etatJetable);
|
|
561
583
|
// The session directories of this user that exist: the XDG one and the systemd one.
|
|
562
584
|
const sessions = [
|
|
563
585
|
...new Set(
|
|
@@ -566,8 +588,27 @@ function envelopper(argv) {
|
|
|
566
588
|
.map(d => path.resolve(d))
|
|
567
589
|
),
|
|
568
590
|
];
|
|
591
|
+
// The tools of the project, judged before anything is prepared: none holds a mount.
|
|
592
|
+
let outils;
|
|
593
|
+
try {
|
|
594
|
+
outils = outilsDe(copie, {
|
|
595
|
+
montages: [copie, claude, scratchpads, cacheNpm, TEMPORAIRE, ...sessions],
|
|
596
|
+
});
|
|
597
|
+
} catch (e) {
|
|
598
|
+
process.stderr.write(`⛔ ENVELOPPE REFUSÉE — ${e.message}\n`);
|
|
599
|
+
return CODE_REFUS;
|
|
600
|
+
}
|
|
601
|
+
mkdirSync(projet, { recursive: true });
|
|
602
|
+
// The session's working directory, created here inside the scratchpads that bwrap mounts.
|
|
603
|
+
mkdirSync(travail, { recursive: true });
|
|
604
|
+
// `~/.claude.json` holds the permissions and servers of every project: it enters the session
|
|
605
|
+
// as a throwaway copy, in a base of its own removed on exit and swept when the envelope is
|
|
606
|
+
// killed (../mesure/base-de-passe.mjs).
|
|
607
|
+
const temporaire = ouvrirBase('enveloppe');
|
|
608
|
+
const etatJetable = path.join(temporaire.dossier, 'claude.json');
|
|
609
|
+
if (existsSync(`${claude}.json`)) copyFileSync(`${claude}.json`, etatJetable);
|
|
569
610
|
const montages = avecLiens(
|
|
570
|
-
montagesDeLaSeance({ cacheNpm, claude, projet, etatJetable, scratchpads, sessions }),
|
|
611
|
+
montagesDeLaSeance({ cacheNpm, claude, projet, etatJetable, scratchpads, sessions, outils }),
|
|
571
612
|
lienSurDisque
|
|
572
613
|
);
|
|
573
614
|
const langage = langageDe(copie);
|
|
@@ -614,6 +655,7 @@ function envelopper(argv) {
|
|
|
614
655
|
paquets,
|
|
615
656
|
role,
|
|
616
657
|
matieres,
|
|
658
|
+
verrous: langage.manifestes.verrous,
|
|
617
659
|
montages,
|
|
618
660
|
magasins,
|
|
619
661
|
lectures,
|
|
@@ -629,7 +671,7 @@ function envelopper(argv) {
|
|
|
629
671
|
} else {
|
|
630
672
|
const r = spawnSync('bwrap', [...args, ...commandeEprouvee(commande)], {
|
|
631
673
|
stdio: 'inherit',
|
|
632
|
-
env: environnementDeLaSeance(process.env, { cacheNpm, paquets, travail }),
|
|
674
|
+
env: environnementDeLaSeance(process.env, { cacheNpm, paquets, travail, outils }),
|
|
633
675
|
});
|
|
634
676
|
if (r.error) process.stderr.write(`⛔ ENVELOPPE IMPOSSIBLE — ${r.error.message}\n`);
|
|
635
677
|
code = r.error ? CODE_REFUS : (r.status ?? 1);
|
|
@@ -40,10 +40,13 @@
|
|
|
40
40
|
# again from main. A ticket whose branch is still in the integration queue is not launched:
|
|
41
41
|
# the refusal goes to the log, which names the queue, CODE_COPIE, before any copy is made.
|
|
42
42
|
# Moving forward keeps
|
|
43
|
-
# the work in progress of the copy
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
43
|
+
# the work in progress of the copy in the copy, never in git's stash, which every copy of the
|
|
44
|
+
# repository shares: it is set aside as a lot, the copy fast-forwards, and the lot is applied
|
|
45
|
+
# three ways, as the lot of a branch sent back is (scripts/enveloppe/travail-de-la-copie.mjs).
|
|
46
|
+
# A refusal, such as commits of the agent on its branch or conflicts left unresolved, goes to
|
|
47
|
+
# the log and stops the launch, CODE_COPIE; so does a reapplication that conflicts: the log
|
|
48
|
+
# names the copy and each file in conflict, the conflicts stay marked in the copy's files and
|
|
49
|
+
# unmerged in its index, and no agent starts on a half-merged copy. Its
|
|
47
50
|
# submodules go through the common preparation (scripts/sous-modules.sh): before moving forward,
|
|
48
51
|
# a submodule carrying local work stops the launch, CODE_COPIE, its log naming it, the work in
|
|
49
52
|
# place; then every submodule is set at the commit of HEAD, before any installation, except one the
|
|
@@ -185,38 +188,28 @@ echec=$(mktemp)
|
|
|
185
188
|
if [ ! -d "$copie" ]; then
|
|
186
189
|
tete=$(git -C "$racine" rev-parse HEAD) || exit 1
|
|
187
190
|
branche="agent/$ticket"
|
|
188
|
-
|
|
191
|
+
base= pointe=
|
|
189
192
|
if git -C "$racine" rev-parse --verify -q "refs/heads/$branche" > /dev/null; then
|
|
190
193
|
# A branch already there: the queue sent it back, or it was left without a commit. Its lot,
|
|
191
194
|
# when it carries one, goes back as local work on main; the branch returns to main.
|
|
192
195
|
if [ "$(git -C "$racine" rev-list --count "$tete..$branche")" -gt 0 ]; then
|
|
193
196
|
base=$(git -C "$racine" merge-base "$tete" "$branche") || exit 1
|
|
194
|
-
|
|
195
|
-
git -C "$racine" diff --binary "$base" "$branche" > "$lot" || exit 1
|
|
197
|
+
pointe=$(git -C "$racine" rev-parse "$branche") || exit 1
|
|
196
198
|
fi
|
|
197
199
|
git -C "$racine" branch -q -f "$branche" "$tete" || exit 1
|
|
198
200
|
git -C "$racine" worktree add -q "$copie" "$branche" || exit 1
|
|
199
201
|
else
|
|
200
202
|
git -C "$racine" worktree add -q -b "$branche" "$copie" HEAD || exit 1
|
|
201
203
|
fi
|
|
202
|
-
if [ -n "$
|
|
203
|
-
# The lot
|
|
204
|
-
|
|
205
|
-
git -C "$copie" apply --3way "$lot" || [ -n "$(git -C "$copie" ls-files -u)" ] || exit 1
|
|
206
|
-
git -C "$copie" reset -q || exit 1
|
|
207
|
-
rm -f "$lot"
|
|
204
|
+
if [ -n "$pointe" ]; then
|
|
205
|
+
# The lot as local work, a conflict marked in its file (travail-de-la-copie.mjs).
|
|
206
|
+
node "$ici/travail-de-la-copie.mjs" reporter "$copie" "$base" "$pointe" || exit 1
|
|
208
207
|
fi
|
|
209
208
|
else
|
|
210
209
|
bash "$ici/../sous-modules.sh" garde "$copie" || exit 1
|
|
211
|
-
|
|
212
|
-
#
|
|
213
|
-
|
|
214
|
-
if [ -n "$conflits" ]; then
|
|
215
|
-
echo "⛔ Le travail en cours de la copie entre en conflit avec main ; il reste dans la remise de git (git stash list)."
|
|
216
|
-
echo "Fichiers en conflit :"
|
|
217
|
-
sed 's/^/ /' <<<"$conflits"
|
|
218
|
-
exit 1
|
|
219
|
-
fi
|
|
210
|
+
# The work in progress moves with the copy, in the copy: a conflict stops the launch, marked
|
|
211
|
+
# in the files, the log naming each one (travail-de-la-copie.mjs).
|
|
212
|
+
node "$ici/travail-de-la-copie.mjs" avancer "$copie" "$(git -C "$racine" rev-parse HEAD)" || exit 1
|
|
220
213
|
fi
|
|
221
214
|
# The list the pose fixes is the one every mount gets, whatever the installation rewrites.
|
|
222
215
|
partages=$(bash "$ici/../sous-modules.sh" pose "$copie") || exit 1
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The local work of an agent's copy carried onto main, for the launcher (./lancer.sh), in the copy
|
|
3
|
+
// alone: git's stash (refs/stash) is common to every copy of a repository, so the work never goes
|
|
4
|
+
// there; the copy keeps it, as a merge or a rebase in conflict does (its conflicts marked in the
|
|
5
|
+
// files, the unmerged entries in its own index).
|
|
6
|
+
//
|
|
7
|
+
// node scripts/enveloppe/travail-de-la-copie.mjs reporter <copie> <base> <pointe>
|
|
8
|
+
// node scripts/enveloppe/travail-de-la-copie.mjs avancer <copie> <cible>
|
|
9
|
+
//
|
|
10
|
+
// - `reporter`: the lot from <base> to <pointe> (`git diff --binary`), a branch the queue sent
|
|
11
|
+
// back, becomes local work of the copy: applied three ways (`git apply --3way`), a conflict
|
|
12
|
+
// marked in its file, the rest of the lot there; the index is then left as HEAD has it, so that
|
|
13
|
+
// all of it is local work. Exit 0, the conflicts included: the agent's session resolves them.
|
|
14
|
+
// - `avancer`: the copy moves forward to <cible> (the main tree's HEAD) by a fast-forward, its
|
|
15
|
+
// local work kept by the same application: the work as a lot (`git diff --binary HEAD`, the
|
|
16
|
+
// submodules left out, which the launcher sets afterwards; untracked files stay in place), the
|
|
17
|
+
// copy brought back to HEAD, moved forward, the lot applied three ways. The lot waits in the
|
|
18
|
+
// copy's own git directory (`git rev-parse --git-dir`, `grillhouse-travail.patch`) while the
|
|
19
|
+
// copy moves, and goes once it is applied.
|
|
20
|
+
// - Applied without conflict: the index is left as HEAD has it; exit 0.
|
|
21
|
+
// - In conflict: the copy stays as `git merge` leaves it, the conflicts marked in the files and
|
|
22
|
+
// unmerged in the index; the output names the copy and each file in conflict; exit 1.
|
|
23
|
+
// - A copy whose lot still waits in its git directory (git refused it whole, as a deletion of
|
|
24
|
+
// a file main changed) is not touched: the output names the file and how to take it back;
|
|
25
|
+
// exit 1. So no relaunch loses it.
|
|
26
|
+
// - A copy still in conflict (unmerged entries in its index) or whose branch carries commits
|
|
27
|
+
// main has not (no fast-forward) is not touched; the output says why; exit 1. A fast-forward
|
|
28
|
+
// that fails after the work is set aside (an untracked file in the way) gives the work back
|
|
29
|
+
// on HEAD; exit 1.
|
|
30
|
+
// - A copy at <cible> already, or without local work, simply fast-forwards; exit 0.
|
|
31
|
+
import { spawnSync } from 'node:child_process';
|
|
32
|
+
import { existsSync, rmSync, writeFileSync } from 'node:fs';
|
|
33
|
+
import path from 'node:path';
|
|
34
|
+
import { pathToFileURL } from 'node:url';
|
|
35
|
+
|
|
36
|
+
const LOT = 'grillhouse-travail.patch';
|
|
37
|
+
|
|
38
|
+
const git = (copie, args, input) =>
|
|
39
|
+
spawnSync('git', ['-C', copie, ...args], { input, maxBuffer: 1024 * 1024 * 1024 });
|
|
40
|
+
const texte = r => String(r.stderr || r.stdout).trim();
|
|
41
|
+
const lignes = r =>
|
|
42
|
+
String(r.stdout)
|
|
43
|
+
.split('\n')
|
|
44
|
+
.map(l => l.trim())
|
|
45
|
+
.filter(Boolean);
|
|
46
|
+
|
|
47
|
+
// The files of <copie> unmerged in its index.
|
|
48
|
+
const enConflit = copie => lignes(git(copie, ['diff', '--name-only', '--diff-filter=U']));
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Applies the lot <lot> (a Buffer of `git diff --binary`) three ways to <copie>; returns the files
|
|
52
|
+
* in conflict, null when git refuses the lot outright.
|
|
53
|
+
* @param {string} copie
|
|
54
|
+
* @param {Buffer} lot
|
|
55
|
+
*/
|
|
56
|
+
function appliquer(copie, lot) {
|
|
57
|
+
const r = git(copie, ['apply', '--3way', '-'], lot);
|
|
58
|
+
const conflits = enConflit(copie);
|
|
59
|
+
return r.status === 0 || conflits.length ? conflits : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The lot from <base> to <pointe> as local work of <copie>; returns `{ ok, message }`.
|
|
64
|
+
* @param {string} copie
|
|
65
|
+
* @param {{ base: string, pointe: string }} o
|
|
66
|
+
*/
|
|
67
|
+
export function reporter(copie, { base, pointe }) {
|
|
68
|
+
const d = git(copie, ['diff', '--binary', base, pointe]);
|
|
69
|
+
if (d.status !== 0) {
|
|
70
|
+
return { ok: false, message: `⛔ Le lot de ${base} à ${pointe} ne se lit pas : ${texte(d)}` };
|
|
71
|
+
}
|
|
72
|
+
if (appliquer(copie, d.stdout) === null) {
|
|
73
|
+
return { ok: false, message: `⛔ Le lot ne s'applique pas à la copie ${copie}.` };
|
|
74
|
+
}
|
|
75
|
+
const r = git(copie, ['reset', '-q']);
|
|
76
|
+
return r.status === 0 ? { ok: true, message: '' } : { ok: false, message: texte(r) };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const conflit = (copie, conflits, entete) =>
|
|
80
|
+
[entete, 'Fichiers en conflit :', ...conflits.map(f => ` ${f}`)].join('\n');
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Moves <copie> forward to <cible>, its local work kept in the copy; returns `{ ok, message }`.
|
|
84
|
+
* @param {string} copie
|
|
85
|
+
* @param {string} cible
|
|
86
|
+
*/
|
|
87
|
+
export function avancer(copie, cible) {
|
|
88
|
+
const restants = enConflit(copie);
|
|
89
|
+
if (restants.length) {
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
message: conflit(
|
|
93
|
+
copie,
|
|
94
|
+
restants,
|
|
95
|
+
`⛔ La copie ${copie} garde des conflits non résolus ; ils se résolvent dans la copie avant une relance.`
|
|
96
|
+
),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const garde = path.join(
|
|
100
|
+
path.resolve(copie, String(git(copie, ['rev-parse', '--git-dir']).stdout).trim()),
|
|
101
|
+
LOT
|
|
102
|
+
);
|
|
103
|
+
if (existsSync(garde)) {
|
|
104
|
+
return {
|
|
105
|
+
ok: false,
|
|
106
|
+
message: `⛔ Le travail de la copie ${copie} attend dans ${garde}, que git n'a pas pu remettre en place ; il se reprend à la main (git apply --3way ${garde}, ou il se jette), puis le fichier se retire, avant une relance.`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const tete = String(git(copie, ['rev-parse', 'HEAD']).stdout).trim();
|
|
110
|
+
const vise = git(copie, ['rev-parse', '--verify', `${cible}^{commit}`]);
|
|
111
|
+
if (vise.status !== 0) {
|
|
112
|
+
return { ok: false, message: `⛔ ${cible} ne nomme aucun commit : ${texte(vise)}` };
|
|
113
|
+
}
|
|
114
|
+
if (tete === String(vise.stdout).trim()) {
|
|
115
|
+
return { ok: true, message: '' };
|
|
116
|
+
}
|
|
117
|
+
if (git(copie, ['merge-base', '--is-ancestor', 'HEAD', cible]).status !== 0) {
|
|
118
|
+
// git's own refusal, which touches nothing: no fast-forward is possible.
|
|
119
|
+
const refus = git(copie, ['merge', '-q', '--ff-only', cible]);
|
|
120
|
+
return {
|
|
121
|
+
ok: false,
|
|
122
|
+
message: `⛔ La copie ${copie} ne peut pas avancer sur main : sa branche porte des commits que main n'a pas (${texte(refus)}) ; son travail reste en place.`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const d = git(copie, ['diff', '--binary', '--ignore-submodules=all', 'HEAD']);
|
|
126
|
+
if (d.status !== 0) {
|
|
127
|
+
return { ok: false, message: `⛔ Le travail de la copie ne se lit pas : ${texte(d)}` };
|
|
128
|
+
}
|
|
129
|
+
if (d.stdout.length === 0) {
|
|
130
|
+
const ff = git(copie, ['merge', '-q', '--ff-only', cible]);
|
|
131
|
+
return ff.status === 0 ? { ok: true, message: '' } : { ok: false, message: texte(ff) };
|
|
132
|
+
}
|
|
133
|
+
writeFileSync(garde, d.stdout);
|
|
134
|
+
const remis = git(copie, ['reset', '-q', '--hard']);
|
|
135
|
+
const ff = remis.status === 0 ? git(copie, ['merge', '-q', '--ff-only', cible]) : remis;
|
|
136
|
+
if (ff.status !== 0) {
|
|
137
|
+
const rendu = appliquer(copie, d.stdout);
|
|
138
|
+
if (rendu !== null && rendu.length === 0 && git(copie, ['reset', '-q']).status === 0) {
|
|
139
|
+
rmSync(garde, { force: true });
|
|
140
|
+
return {
|
|
141
|
+
ok: false,
|
|
142
|
+
message: `⛔ La copie ${copie} ne peut pas avancer sur main : ${texte(ff)}\nSon travail reste en place.`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
ok: false,
|
|
147
|
+
message: `⛔ La copie ${copie} ne peut pas avancer sur main : ${texte(ff)}\nSon travail ne se remet pas en place ; il reste dans ${garde}.`,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const conflits = appliquer(copie, d.stdout);
|
|
151
|
+
if (conflits === null) {
|
|
152
|
+
return {
|
|
153
|
+
ok: false,
|
|
154
|
+
message: `⛔ Le travail de la copie ${copie} ne s'applique pas sur main ; il reste dans ${garde}.`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
rmSync(garde, { force: true });
|
|
158
|
+
if (conflits.length) {
|
|
159
|
+
return {
|
|
160
|
+
ok: false,
|
|
161
|
+
message: conflit(
|
|
162
|
+
copie,
|
|
163
|
+
conflits,
|
|
164
|
+
`⛔ Le travail en cours de la copie entre en conflit avec main ; il reste dans la copie ${copie}, ses conflits marqués dans ses fichiers.`
|
|
165
|
+
),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const r = git(copie, ['reset', '-q']);
|
|
169
|
+
return r.status === 0 ? { ok: true, message: '' } : { ok: false, message: texte(r) };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
173
|
+
const [geste, copie, ...reste] = process.argv.slice(2);
|
|
174
|
+
const r =
|
|
175
|
+
geste === 'reporter' && reste.length === 2
|
|
176
|
+
? reporter(copie, { base: reste[0], pointe: reste[1] })
|
|
177
|
+
: geste === 'avancer' && reste.length === 1
|
|
178
|
+
? avancer(copie, reste[0])
|
|
179
|
+
: {
|
|
180
|
+
ok: false,
|
|
181
|
+
message:
|
|
182
|
+
'usage: travail-de-la-copie.mjs reporter <copie> <base> <pointe> | avancer <copie> <cible>',
|
|
183
|
+
};
|
|
184
|
+
if (r.message) {
|
|
185
|
+
process.stdout.write(`${r.message}\n`);
|
|
186
|
+
}
|
|
187
|
+
process.exitCode = r.ok ? 0 : 1;
|
|
188
|
+
}
|
package/scripts/etapes.mjs
CHANGED
|
@@ -251,7 +251,7 @@ export const MONTEES = Object.fromEntries(
|
|
|
251
251
|
'sans-livraison':
|
|
252
252
|
'Le développeur ne change rien et le rouge reste : avec quel contexte le lever, ou le plan doit-il changer ?',
|
|
253
253
|
'relecture-arret':
|
|
254
|
-
'La relecture ne rend pas le lot à un agent (un constat sans destinataire valide, un critère en cause, ou la troisième relecture rendue) : que devient le plan, et qui reprend ?',
|
|
254
|
+
'La relecture ne rend pas le lot à un agent (un constat sans destinataire valide, un constat au testwriter que le plan saute, un critère en cause, ou la troisième relecture rendue) : que devient le plan, et qui reprend ?',
|
|
255
255
|
integration:
|
|
256
256
|
'L’intégration refuse le lot, ou la file rouvre le ticket : que corrige le lot, et qui le reprend ?',
|
|
257
257
|
'hors-portee':
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The frame's merge driver of the CHANGELOG, on the model of gnulib's git-merge-changelog: two
|
|
3
|
+
// lots that each add an entry under the same heading both keep their entry, wherever git merges
|
|
4
|
+
// three ways (the integration's `git apply --3way --index`, the relaunch's `git apply --3way`, the
|
|
5
|
+
// copy's `git merge --ff-only --autostash`, a rebase, a cherry-pick).
|
|
6
|
+
//
|
|
7
|
+
// grillhouse fusion-du-changelog <base> <nous> <eux> git's %O %A %B; writes the result in <nous>
|
|
8
|
+
//
|
|
9
|
+
// - The project's `.gitattributes` names the driver for CHANGELOG.md (ATTRIBUT); git runs the
|
|
10
|
+
// command the repository's configuration gives it (`merge.grillhouse-changelog.driver`), which
|
|
11
|
+
// `poserLePilote` writes with the git hooks (`poserCrochets`, scripts/crochets.mjs), which
|
|
12
|
+
// `grillhouse hooks` (the project's `prepare`, at each `npm install`) and the update of the frame
|
|
13
|
+
// (scripts/grillhouse-maj.mjs, which writes the attribute) run. The command is the main
|
|
14
|
+
// tree's `node_modules/.bin/grillhouse`, found from git's common directory, so that a copy
|
|
15
|
+
// writes the same; without it, git's own merge (`git merge-file`) marks the conflict as git
|
|
16
|
+
// would.
|
|
17
|
+
// - The merge is git's (`git merge-file --diff3`). A conflict whose base is empty is two additions
|
|
18
|
+
// at the same place: both are kept, ours first, then theirs, each word for word. Any other
|
|
19
|
+
// conflict (a line changed on both sides, an addition beside a line the other side changes)
|
|
20
|
+
// stays one: <nous> receives git's marks, and the exit code is 1, as git expects of a driver.
|
|
21
|
+
import { spawnSync } from 'node:child_process';
|
|
22
|
+
import { writeFileSync } from 'node:fs';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
import { pathToFileURL } from 'node:url';
|
|
25
|
+
|
|
26
|
+
/** The name of the driver, as `.gitattributes` and the configuration name it. */
|
|
27
|
+
export const PILOTE = 'grillhouse-changelog';
|
|
28
|
+
/** The line of `.gitattributes` that gives the CHANGELOG to the driver. */
|
|
29
|
+
export const ATTRIBUT = `CHANGELOG.md merge=${PILOTE}`;
|
|
30
|
+
|
|
31
|
+
// The marks of the merge the driver reads: longer than any line of a CHANGELOG starts with.
|
|
32
|
+
const TAILLE = 40;
|
|
33
|
+
const DEBUT = `${'<'.repeat(TAILLE)} `;
|
|
34
|
+
const BASE = `${'|'.repeat(TAILLE)} `;
|
|
35
|
+
const MILIEU = '='.repeat(TAILLE);
|
|
36
|
+
const FIN = `${'>'.repeat(TAILLE)} `;
|
|
37
|
+
|
|
38
|
+
const etiquettes = ['-L', 'ours', '-L', 'base', '-L', 'theirs'];
|
|
39
|
+
|
|
40
|
+
// The text of the merge of <nous> and <eux> from <base> when each conflict is two additions, else
|
|
41
|
+
// null.
|
|
42
|
+
function lesAjouts(base, nous, eux) {
|
|
43
|
+
const r = spawnSync(
|
|
44
|
+
'git',
|
|
45
|
+
['merge-file', '-p', '--diff3', `--marker-size=${TAILLE}`, ...etiquettes, nous, base, eux],
|
|
46
|
+
{ encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 }
|
|
47
|
+
);
|
|
48
|
+
if (r.status === null || r.status < 0 || r.status > 127) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const sortie = [];
|
|
52
|
+
let partie = null;
|
|
53
|
+
let conflit = { nous: [], base: [], eux: [] };
|
|
54
|
+
for (const ligne of r.stdout.split(/(?<=\n)/)) {
|
|
55
|
+
const nue = ligne.replace(/\r?\n$/, '');
|
|
56
|
+
if (partie === null && nue.startsWith(DEBUT)) {
|
|
57
|
+
partie = 'nous';
|
|
58
|
+
} else if (partie === 'nous' && nue.startsWith(BASE)) {
|
|
59
|
+
partie = 'base';
|
|
60
|
+
} else if (partie === 'base' && nue === MILIEU) {
|
|
61
|
+
partie = 'eux';
|
|
62
|
+
} else if (partie === 'eux' && nue.startsWith(FIN)) {
|
|
63
|
+
if (conflit.base.length > 0) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
sortie.push(...conflit.nous, ...conflit.eux);
|
|
67
|
+
partie = null;
|
|
68
|
+
conflit = { nous: [], base: [], eux: [] };
|
|
69
|
+
} else if (partie === null) {
|
|
70
|
+
sortie.push(ligne);
|
|
71
|
+
} else {
|
|
72
|
+
conflit[partie].push(ligne);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return partie === null ? sortie.join('') : null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Merges <nous> and <eux> from <base> (paths), the result written in <nous>: 0 when every conflict
|
|
80
|
+
* is two additions, kept both; else 1, <nous> holding git's marks.
|
|
81
|
+
*/
|
|
82
|
+
export function fusionner(base, nous, eux) {
|
|
83
|
+
const texte = lesAjouts(base, nous, eux);
|
|
84
|
+
if (texte !== null) {
|
|
85
|
+
writeFileSync(nous, texte);
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
const r = spawnSync('git', ['merge-file', ...etiquettes, nous, base, eux]);
|
|
89
|
+
return r.status === 0 ? 0 : 1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Writes the driver in the configuration of the git repository at <projet> (see the header);
|
|
94
|
+
* nothing outside a repository. Returns whether it is written.
|
|
95
|
+
*/
|
|
96
|
+
export function poserLePilote(projet) {
|
|
97
|
+
const git = (...a) => spawnSync('git', ['-C', projet, ...a], { encoding: 'utf8' });
|
|
98
|
+
const commun = git('rev-parse', '--path-format=absolute', '--git-common-dir');
|
|
99
|
+
if (commun.status !== 0) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
const commande = path.join(path.dirname(commun.stdout.trim()), 'node_modules/.bin/grillhouse');
|
|
103
|
+
const pilote =
|
|
104
|
+
`c='${commande}'; if [ -x "$c" ]; then "$c" fusion-du-changelog %O %A %B; ` +
|
|
105
|
+
`else git merge-file ${etiquettes.join(' ')} %A %O %B; fi`;
|
|
106
|
+
return (
|
|
107
|
+
git('config', '--local', `merge.${PILOTE}.name`, 'the CHANGELOG of Grillhouse').status === 0 &&
|
|
108
|
+
git('config', '--local', `merge.${PILOTE}.driver`, pilote).status === 0
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
113
|
+
const [base, nous, eux] = process.argv.slice(2);
|
|
114
|
+
if (!base || !nous || !eux) {
|
|
115
|
+
process.stderr.write('usage: grillhouse fusion-du-changelog <base> <nous> <eux>\n');
|
|
116
|
+
process.exitCode = 2;
|
|
117
|
+
} else {
|
|
118
|
+
process.exitCode = fusionner(base, nous, eux);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -99,6 +99,10 @@
|
|
|
99
99
|
// `prepare`) also runs, in the hooks folder git reads for the project (`core.hooksPath`, else the
|
|
100
100
|
// default one; the configuration stays). A hook of the project keeps its lines, which still run;
|
|
101
101
|
// the frame's lines of a former version give way to the current ones.
|
|
102
|
+
// - The merge driver of the CHANGELOG (scripts/fusion-du-changelog.mjs): a `.gitattributes`
|
|
103
|
+
// without the line `CHANGELOG.md merge=grillhouse-changelog` receives it, after its own lines,
|
|
104
|
+
// and the driver's command is written in the repository's configuration with the hooks
|
|
105
|
+
// (scripts/crochets.mjs): two lots that each add an entry under the same heading both enter main.
|
|
102
106
|
// - The plugins: after the files, the command line installs the plugins the project's settings
|
|
103
107
|
// declare, for the project, by scripts/greffons.mjs (the mechanism `grillhouse init` also calls;
|
|
104
108
|
// `mettreAJour` itself never calls claude), and brings the frame's mod to the package's version,
|
|
@@ -132,6 +136,7 @@ import path from 'node:path';
|
|
|
132
136
|
import { pathToFileURL } from 'node:url';
|
|
133
137
|
import { CADRE, VERSION } from './cadre.mjs';
|
|
134
138
|
import { poserCrochets } from './crochets.mjs';
|
|
139
|
+
import { ATTRIBUT } from './fusion-du-changelog.mjs';
|
|
135
140
|
import { installerGreffons } from './greffons.mjs';
|
|
136
141
|
import { migrer, restesAuProjet } from './migrations.mjs';
|
|
137
142
|
import { LANGAGES, langage, langageDe, langagesDeclares, langagesTrouves } from './langages.mjs';
|
|
@@ -189,6 +194,19 @@ function ignorer(projet) {
|
|
|
189
194
|
}
|
|
190
195
|
}
|
|
191
196
|
|
|
197
|
+
// Adds to the `.gitattributes` of the project at <projet> the line that gives its CHANGELOG to the
|
|
198
|
+
// frame's merge driver (ATTRIBUT, scripts/fusion-du-changelog.mjs), when no line is it; its own
|
|
199
|
+
// lines stay.
|
|
200
|
+
function attribuer(projet) {
|
|
201
|
+
const f = path.join(projet, '.gitattributes');
|
|
202
|
+
const texte = existsSync(f) ? readFileSync(f, 'utf8') : '';
|
|
203
|
+
if (texte.split('\n').some(l => l.trim() === ATTRIBUT)) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const fin = texte === '' || texte.endsWith('\n') ? '' : '\n';
|
|
207
|
+
writeFileSync(f, `${texte}${fin}${ATTRIBUT}\n`);
|
|
208
|
+
}
|
|
209
|
+
|
|
192
210
|
// <deps> written sorted by name, as npm writes them.
|
|
193
211
|
const trie = deps =>
|
|
194
212
|
Object.fromEntries(Object.entries(deps).sort(([a], [b]) => a.localeCompare(b, 'en')));
|
|
@@ -369,6 +387,7 @@ export function mettreAJour(projet, source, { inscrite = VERSION } = {}) {
|
|
|
369
387
|
bilan.ligneEtat = reglerLigneEtat(projet);
|
|
370
388
|
bilan.greffon = declarerGreffon(projet);
|
|
371
389
|
poserCrochets(projet);
|
|
390
|
+
attribuer(projet);
|
|
372
391
|
return bilan;
|
|
373
392
|
}
|
|
374
393
|
|