@roomi-fields/grillhouse 0.29.0 → 0.30.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/CHANGELOG.md +739 -0
- package/bin/grillhouse.mjs +79 -18
- package/cadre/templates/projet/.github/workflows/ci.yml +2 -13
- package/cadre/templates/projet/CLAUDE.md +5 -1
- package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
- package/cadre/templates/projet/package.json +2 -2
- package/charte.md +24 -0
- package/dist/temporal/acte.d.ts +24 -0
- package/dist/temporal/acte.js +139 -0
- package/dist/temporal/acte.js.map +1 -0
- package/dist/temporal/attributs.d.ts +6 -0
- package/dist/temporal/attributs.js +15 -0
- package/dist/temporal/attributs.js.map +1 -0
- package/dist/temporal/circuit/activites.d.ts +13 -0
- package/dist/temporal/circuit/activites.js +33 -0
- package/dist/temporal/circuit/activites.js.map +1 -0
- package/dist/temporal/circuit/client.d.ts +72 -0
- package/dist/temporal/circuit/client.js +247 -0
- package/dist/temporal/circuit/client.js.map +1 -0
- package/dist/temporal/circuit/commande.d.ts +2 -0
- package/dist/temporal/circuit/commande.js +238 -0
- package/dist/temporal/circuit/commande.js.map +1 -0
- package/dist/temporal/circuit/contrat.d.ts +305 -0
- package/dist/temporal/circuit/contrat.js +24 -0
- package/dist/temporal/circuit/contrat.js.map +1 -0
- package/dist/temporal/circuit/deroule.d.ts +3 -0
- package/dist/temporal/circuit/deroule.js +540 -0
- package/dist/temporal/circuit/deroule.js.map +1 -0
- package/dist/temporal/client.d.ts +47 -0
- package/dist/temporal/client.js +69 -0
- package/dist/temporal/client.js.map +1 -0
- package/dist/temporal/commande.d.ts +2 -0
- package/dist/temporal/commande.js +95 -0
- package/dist/temporal/commande.js.map +1 -0
- package/dist/temporal/deroules.d.ts +5 -0
- package/dist/temporal/deroules.js +10 -0
- package/dist/temporal/deroules.js.map +1 -0
- package/dist/temporal/etat.d.ts +33 -0
- package/dist/temporal/etat.js +59 -0
- package/dist/temporal/etat.js.map +1 -0
- package/dist/temporal/file/activites.d.ts +10 -0
- package/dist/temporal/file/activites.js +25 -0
- package/dist/temporal/file/activites.js.map +1 -0
- package/dist/temporal/file/client.d.ts +4 -0
- package/dist/temporal/file/client.js +6 -0
- package/dist/temporal/file/client.js.map +1 -0
- package/dist/temporal/file/contrat.d.ts +158 -0
- package/dist/temporal/file/contrat.js +14 -0
- package/dist/temporal/file/contrat.js.map +1 -0
- package/dist/temporal/file/deroule.d.ts +15 -0
- package/dist/temporal/file/deroule.js +235 -0
- package/dist/temporal/file/deroule.js.map +1 -0
- package/dist/temporal/installation.d.ts +124 -0
- package/dist/temporal/installation.js +408 -0
- package/dist/temporal/installation.js.map +1 -0
- package/dist/temporal/places/activites.d.ts +8 -0
- package/dist/temporal/places/activites.js +13 -0
- package/dist/temporal/places/activites.js.map +1 -0
- package/dist/temporal/places/client.d.ts +28 -0
- package/dist/temporal/places/client.js +64 -0
- package/dist/temporal/places/client.js.map +1 -0
- package/dist/temporal/places/contrat.d.ts +106 -0
- package/dist/temporal/places/contrat.js +21 -0
- package/dist/temporal/places/contrat.js.map +1 -0
- package/dist/temporal/places/deroule.d.ts +3 -0
- package/dist/temporal/places/deroule.js +198 -0
- package/dist/temporal/places/deroule.js.map +1 -0
- package/dist/temporal/sonde/activites.d.ts +6 -0
- package/dist/temporal/sonde/activites.js +52 -0
- package/dist/temporal/sonde/activites.js.map +1 -0
- package/dist/temporal/sonde/contrat.d.ts +35 -0
- package/dist/temporal/sonde/contrat.js +10 -0
- package/dist/temporal/sonde/contrat.js.map +1 -0
- package/dist/temporal/sonde/deroule.d.ts +3 -0
- package/dist/temporal/sonde/deroule.js +39 -0
- package/dist/temporal/sonde/deroule.js.map +1 -0
- package/dist/temporal/tickets/activites.d.ts +7 -0
- package/dist/temporal/tickets/activites.js +81 -0
- package/dist/temporal/tickets/activites.js.map +1 -0
- package/dist/temporal/tickets/client.d.ts +10 -0
- package/dist/temporal/tickets/client.js +31 -0
- package/dist/temporal/tickets/client.js.map +1 -0
- package/dist/temporal/tickets/contrat.d.ts +56 -0
- package/dist/temporal/tickets/contrat.js +13 -0
- package/dist/temporal/tickets/contrat.js.map +1 -0
- package/dist/temporal/tickets/deroule.d.ts +3 -0
- package/dist/temporal/tickets/deroule.js +94 -0
- package/dist/temporal/tickets/deroule.js.map +1 -0
- package/dist/temporal/travailleur.d.ts +2 -0
- package/dist/temporal/travailleur.js +69 -0
- package/dist/temporal/travailleur.js.map +1 -0
- package/docs/ARCHITECTURE.md +609 -80
- package/docs/CADRE.md +17 -0
- package/docs/INTERFACE.md +134 -42
- package/hooks/crochet.mjs +19 -2
- package/hooks/hooks.json +11 -0
- package/package.json +16 -4
- package/scripts/activites.mjs +2182 -0
- package/scripts/aiguillage.d.mts +37 -0
- package/scripts/aiguillage.mjs +7 -3
- package/scripts/avancement.mjs +128 -16
- package/scripts/bilan.mjs +37 -19
- package/scripts/cadre.mjs +11 -2
- package/scripts/circuit.mjs +881 -4059
- package/scripts/circuits-cles.d.mts +4 -0
- package/scripts/circuits-cles.mjs +21 -0
- package/scripts/circuits-du-serveur.mjs +105 -0
- package/scripts/codes-de-sortie.mjs +9 -0
- package/scripts/commandes-composees.mjs +45 -41
- package/scripts/commandes-du-path.d.mts +7 -0
- package/scripts/commandes-du-path.mjs +25 -0
- package/scripts/composition-des-langages.mjs +16 -12
- package/scripts/conformite.mjs +6 -13
- package/scripts/copies-finies.mjs +52 -47
- package/scripts/depart-du-ticket.d.mts +53 -0
- package/scripts/depart-du-ticket.mjs +124 -0
- package/scripts/dependances-internes.mjs +115 -0
- package/scripts/dernier-vert.mjs +7 -15
- package/scripts/donnees-cles.mjs +228 -0
- package/scripts/droits.mjs +11 -1
- package/scripts/effets.mjs +352 -0
- package/scripts/enveloppe/enveloppe.mjs +119 -8
- package/scripts/enveloppe/lancer.sh +14 -18
- package/scripts/enveloppe/paquets-du-plan.mjs +2 -2
- package/scripts/enveloppe/travail-de-la-copie.mjs +5 -1
- package/scripts/etapes.mjs +5 -2
- package/scripts/faits-du-circuit.mjs +493 -0
- package/scripts/file-des-tickets.d.mts +21 -0
- package/scripts/file-des-tickets.mjs +58 -0
- package/scripts/flux-des-paquets.mjs +187 -0
- package/scripts/gardes-du-cadre.mjs +12 -2
- package/scripts/integration/file.mjs +475 -420
- package/scripts/integration/integrer.mjs +17 -19
- package/scripts/integration/rejeu.mjs +19 -4
- package/scripts/jointure.d.ts +145 -27
- package/scripts/langages/cargo/commandes.mjs +289 -109
- package/scripts/langages/cargo/composants.mjs +130 -34
- package/scripts/langages/cargo/exemples.mjs +12 -21
- package/scripts/langages/cargo/index.mjs +18 -8
- package/scripts/langages/cargo/sccache.mjs +8 -14
- package/scripts/langages/python/commandes.mjs +216 -100
- package/scripts/langages/python/composants.mjs +53 -21
- package/scripts/langages/python/exemples.mjs +6 -16
- package/scripts/langages/python/index.mjs +24 -8
- package/scripts/langages/python/lot.mjs +1 -36
- package/scripts/langages/typescript/construire.mjs +6 -163
- package/scripts/langages/typescript/exemples.mjs +3 -11
- package/scripts/langages/typescript/frontieres.mjs +1 -1
- package/scripts/langages/typescript/index.mjs +43 -61
- package/scripts/langages/typescript/interfaces-contre-code.mjs +4 -4
- package/scripts/langages/typescript/migrations/0.30.0-prefixe-des-tickets.mjs +63 -0
- package/scripts/langages/typescript/migrations/0.30.0-tailles-des-outils-lourds.mjs +31 -0
- package/scripts/langages/typescript/migrations/0.30.0-titres-nommant-un-ticket.mjs +40 -0
- package/scripts/langages/typescript/mise-a-jour.mjs +1 -2
- package/scripts/langages/typescript/tailles-des-tests.mjs +40 -9
- package/scripts/langages/typescript/tests-de-nuit.mjs +12 -9
- package/scripts/langages/typescript/tests.mjs +17 -8
- package/scripts/langages/typescript/titres-de-tests.mjs +297 -0
- package/scripts/langages/typescript/turbo-des-paquets.mjs +183 -38
- package/scripts/langages/typescript/verdict.mjs +1 -1
- package/scripts/langages/typescript/verifier.mjs +31 -11
- package/scripts/langages/typescript/vitest-config/base.mjs +22 -1
- package/scripts/langages/typescript/vitest-config/bornes.mjs +13 -0
- package/scripts/langages/typescript/vitest-config/cibles.mjs +36 -14
- package/scripts/langages/typescript/vitest-config/delais.mjs +54 -0
- package/scripts/langages/typescript/vitest-config/delais.setup.mjs +11 -0
- package/scripts/langages/typescript/vitest-config/duree.classement.mjs +100 -0
- package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +49 -63
- package/scripts/langages/typescript/vitest-config/machine.setup.mjs +3 -0
- package/scripts/langages/typescript/vitest.nuit.config.mjs +4 -0
- package/scripts/mesure/pression.mjs +3 -3
- package/scripts/mesure-de-la-machine.d.mts +21 -0
- package/scripts/mesure-de-la-machine.mjs +76 -0
- package/scripts/migrations/0.23.2-copies-du-cadre.mjs +8 -2
- package/scripts/migrations/0.30.0-ci-appelle-la-verification.mjs +120 -0
- package/scripts/migrations/0.31.0-paquets-dans-le-graphe.mjs +81 -0
- package/scripts/migrations.mjs +5 -0
- package/scripts/nuit.sh +10 -3
- package/scripts/outils-cles.d.mts +24 -0
- package/scripts/outils-cles.mjs +0 -1
- package/scripts/paquet-npm.mjs +147 -0
- package/scripts/paquet.mjs +73 -4
- package/scripts/paquets.mjs +34 -6
- package/scripts/passe-de-la-machine.mjs +66 -0
- package/scripts/places-de-la-machine.mjs +360 -0
- package/scripts/places-du-serveur.mjs +170 -0
- package/scripts/prefixe-des-tickets.mjs +68 -0
- package/scripts/preparation.mjs +10 -3
- package/scripts/registre.mjs +3 -2
- package/scripts/regles-des-places.d.mts +36 -0
- package/scripts/regles-des-places.mjs +70 -0
- package/scripts/reponses-du-circuit.d.mts +6 -0
- package/scripts/reponses-du-circuit.mjs +28 -0
- package/scripts/resultats.mjs +7 -9
- package/scripts/retirer-les-copies-finies.mjs +25 -0
- package/scripts/sans-reponse.d.mts +4 -0
- package/scripts/sans-reponse.mjs +13 -0
- package/scripts/seances.mjs +918 -0
- package/scripts/services-du-noyau.mjs +26 -8
- package/scripts/session-start.sh +2 -2
- package/scripts/sortie.mjs +3 -3
- package/scripts/sous-commandes.mjs +38 -9
- package/scripts/style-a-l-ecriture.mjs +229 -0
- package/scripts/superviseur.mjs +122 -111
- package/scripts/tableau.mjs +148 -110
- package/scripts/taches-du-graphe.mjs +328 -0
- package/scripts/ticket-du-circuit.mjs +206 -0
- package/scripts/transitions.d.mts +148 -0
- package/scripts/transitions.mjs +901 -0
- package/scripts/verrou-de-fichier.mjs +2 -2
- package/scripts/verrou-de-machine.mjs +28 -13
- package/skills/explorateur/SKILL.md +2 -1
- package/skills/pitmaster/SKILL.md +17 -18
- package/skills/pitmaster/references/consigne-agent.md +5 -1
- package/skills/release/SKILL.md +3 -3
- package/skills/relecteur/SKILL.md +4 -2
- package/skills/testwriter/SKILL.md +36 -24
- package/scripts/demon.mjs +0 -251
- package/scripts/integration/file-attente.mjs +0 -61
- package/scripts/langages/cargo/touches.mjs +0 -93
- package/scripts/langages/typescript/script-des-tests.mjs +0 -6
|
@@ -0,0 +1,918 @@
|
|
|
1
|
+
// The sessions of the agents as activities, as Temporal runs an activity: each session is a
|
|
2
|
+
// process group the activity launches (`jouerLeGroupe`), which sends a sign of life
|
|
3
|
+
// `{ pid, depart, seanceId }` at its launch and at each step of its watch, stops on a motionless
|
|
4
|
+
// transcript (`IMMOBILE_MS` of scripts/circuit.mjs, `ctx.immobileMs`), and, cancelled, kills its
|
|
5
|
+
// group; a launch that finds alive the group a launch before left (its last sign of life) waits
|
|
6
|
+
// for it, under the same watch, before it takes its place (`lancer`): the second attempt of
|
|
7
|
+
// `jusquALaFiche`, and the fresh session that follows a failed resumption in `seance`; the id of
|
|
8
|
+
// each session comes from its caller, which gives a new one to each session it launches. `lancer` launches one session, `jusquALaFiche` until its
|
|
9
|
+
// sheet, `seance` the testwriter's or the developpeur's on the whole ticket, with the instruction of
|
|
10
|
+
// the templates (`consigne`) and the findings of the reviewer open for its role
|
|
11
|
+
// (`constatsDeLaSeance`). The circuit (scripts/circuit.mjs) calls them (grillhouse-4nr.3).
|
|
12
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
13
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
14
|
+
import {
|
|
15
|
+
appendFileSync,
|
|
16
|
+
closeSync,
|
|
17
|
+
existsSync,
|
|
18
|
+
mkdirSync,
|
|
19
|
+
openSync,
|
|
20
|
+
readdirSync,
|
|
21
|
+
readFileSync,
|
|
22
|
+
rmSync,
|
|
23
|
+
statSync,
|
|
24
|
+
writeFileSync,
|
|
25
|
+
} from 'node:fs';
|
|
26
|
+
import path from 'node:path';
|
|
27
|
+
import { GREFFON } from './cadre.mjs';
|
|
28
|
+
import { ecrireLaListe } from './enveloppe/paquets-du-plan.mjs';
|
|
29
|
+
import { nomDuRole } from './etapes.mjs';
|
|
30
|
+
import { departDe } from './mesure/base-de-passe.mjs';
|
|
31
|
+
import { groupeVivant, signalerGroupe } from './mesure-de-la-machine.mjs';
|
|
32
|
+
import { lancementDeLaPasse } from './passe-de-la-machine.mjs';
|
|
33
|
+
import { prendreUnePlace } from './places-de-la-machine.mjs';
|
|
34
|
+
import { cleDuConstat, lireFiche, reponsesAuxConstats, schemaDeFiche } from './resultats.mjs';
|
|
35
|
+
import {
|
|
36
|
+
ACTEUR,
|
|
37
|
+
Arret,
|
|
38
|
+
AUTEUR_DU_CIRCUIT,
|
|
39
|
+
commenter,
|
|
40
|
+
derniereDe,
|
|
41
|
+
entete,
|
|
42
|
+
fichesDe,
|
|
43
|
+
fin,
|
|
44
|
+
inscrire,
|
|
45
|
+
leTicket,
|
|
46
|
+
lire,
|
|
47
|
+
nomsDe,
|
|
48
|
+
} from './ticket-du-circuit.mjs';
|
|
49
|
+
import { emettre } from './effets.mjs';
|
|
50
|
+
import { AttenteDeLaMachine } from './verrou-de-machine.mjs';
|
|
51
|
+
|
|
52
|
+
// The number of the next files of a session in the working directory <dossier> of the ticket: one
|
|
53
|
+
// past the highest its files carry (`consigne-<n>.md`, `erreurs-<n>.txt`), read
|
|
54
|
+
// at each launch, so that no counter is shared between the circuit and its activities.
|
|
55
|
+
export function prochainNumero(dossier) {
|
|
56
|
+
const lus = existsSync(dossier) ? readdirSync(dossier) : [];
|
|
57
|
+
return 1 + Math.max(0, ...lus.map(n => Number(/-(\d+)(?:\.[a-z]+)?$/.exec(n)?.[1] ?? 0)));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The id of the session of the event <evenement> under the act of <ctx>: the session
|
|
62
|
+
* `<séance>-e<essai>`, <séance> drawn from the key of its activity (`ctx.cle`) and the event, and
|
|
63
|
+
* <essai> the attempt of that activity (`ctx.essaiDeLActe`), so that two attempts never share a
|
|
64
|
+
* `--session-id`; out of an act, drawn anew. A UUID drawn from that name, as claude's
|
|
65
|
+
* `--session-id` takes it.
|
|
66
|
+
*/
|
|
67
|
+
export function idDeSeance(ctx, evenement) {
|
|
68
|
+
if (!ctx.cle) {
|
|
69
|
+
return randomUUID();
|
|
70
|
+
}
|
|
71
|
+
const nom = `${ctx.cle}:seance:${evenement}-e${ctx.essaiDeLActe ?? 1}`;
|
|
72
|
+
const h = createHash('sha256').update(nom).digest('hex');
|
|
73
|
+
const v = ((parseInt(h[16], 16) & 0x3) | 0x8).toString(16);
|
|
74
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-${v}${h.slice(17, 20)}-${h.slice(20, 32)}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// A session cancelled (the AbortSignal its caller gives), its group killed.
|
|
78
|
+
export class SeanceAnnulee extends Error {
|
|
79
|
+
constructor(role) {
|
|
80
|
+
super(`la séance du ${nomDuRole(role)} est annulée, son groupe tué.`);
|
|
81
|
+
this.name = 'SeanceAnnulee';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const FORT = ['--modele', 'opus', '--effort', 'high'];
|
|
86
|
+
|
|
87
|
+
const LANCEUR = path.join(import.meta.dirname, 'enveloppe', 'lancer.sh');
|
|
88
|
+
|
|
89
|
+
const REGISTRE = path.join(import.meta.dirname, 'registre.mjs');
|
|
90
|
+
|
|
91
|
+
// The templates of the instructions, in the skill of the supervisor, which the frame's plugin
|
|
92
|
+
// carries, read at the plugin's root (scripts/cadre.mjs).
|
|
93
|
+
const GABARIT = path.join(GREFFON, 'skills', 'pitmaster', 'references', 'consigne-agent.md');
|
|
94
|
+
|
|
95
|
+
// The latest moment a transcript of the copy moved, or 0.
|
|
96
|
+
function derniereTrace(dossier) {
|
|
97
|
+
if (!existsSync(dossier)) {
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
let m = 0;
|
|
101
|
+
for (const f of readdirSync(dossier, { recursive: true })) {
|
|
102
|
+
if (!String(f).endsWith('.jsonl')) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
m = Math.max(m, statSync(path.join(dossier, String(f))).mtimeMs);
|
|
107
|
+
} catch {
|
|
108
|
+
// A transcript removed meanwhile does not move.
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return m;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const mtime = f => {
|
|
115
|
+
try {
|
|
116
|
+
return statSync(f).mtimeMs;
|
|
117
|
+
} catch {
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Where the session <id> of <ctx> keeps its result, in the working directory of the ticket
|
|
124
|
+
* (`<copie>.travail/seances/<id>/`, as lancer.sh writes it): its exit code (`fin`), claude's JSON
|
|
125
|
+
* result (`resultat.json`) and the reason of a write out of the plan (`hors-plan`).
|
|
126
|
+
*/
|
|
127
|
+
export function rangDeLaSeance(ctx, id) {
|
|
128
|
+
const dossier = path.join(ctx.tmp, 'seances', id);
|
|
129
|
+
return {
|
|
130
|
+
dossier,
|
|
131
|
+
fin: path.join(dossier, 'fin'),
|
|
132
|
+
resultat: path.join(dossier, 'resultat.json'),
|
|
133
|
+
horsPlan: path.join(dossier, 'hors-plan'),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// The result the session ranged at <rang> left, or null without its end file.
|
|
138
|
+
function resultatRange(rang, id) {
|
|
139
|
+
if (!existsSync(rang.fin)) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
code: 0,
|
|
144
|
+
seance: Number(readFileSync(rang.fin, 'utf8').trim()),
|
|
145
|
+
bloque: false,
|
|
146
|
+
horsPlan: existsSync(rang.horsPlan) ? lire(rang.horsPlan).trim() : null,
|
|
147
|
+
erreur: null,
|
|
148
|
+
sortie: lire(rang.resultat).trim(),
|
|
149
|
+
id,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// One launch of a session: `{ code, seance, bloque, erreur, sortie, id }`, `seance` the session's
|
|
154
|
+
// exit code (from lancer.sh's end file for a session in the envelope), null when the launch
|
|
155
|
+
// stopped before it, `sortie` claude's JSON result, its sheet in `structured_output`, `id` the
|
|
156
|
+
// session whose result it is. Every
|
|
157
|
+
// session runs with the author of its role (BEADS_ACTOR). A session in the envelope, on the whole
|
|
158
|
+
// ticket (`.` its component, the plan its `--paquets`), opens under the id <ouvre> (lancer.sh
|
|
159
|
+
// --seance), or resumes the session <reprend> (lancer.sh --reprise); its result is the file
|
|
160
|
+
// lancer.sh ranges under its id (`rangDeLaSeance`).
|
|
161
|
+
// A session <horsEnveloppe> (the explorateur's, the questionneur's, the reviewer's) is claude
|
|
162
|
+
// itself, in the ticket's
|
|
163
|
+
// copy (the main tree once the copy is gone), under <droits> (`horsDeLEnveloppe`), the
|
|
164
|
+
// schema of its role's sheet and the options <session> names (its id, or the session it
|
|
165
|
+
// resumes), its instruction on its standard input and its result on its standard output, ranged
|
|
166
|
+
// under its id with its exit code as lancer.sh ranges them, added to the log under its header
|
|
167
|
+
// line, then its line written to the register, as lancer.sh does.
|
|
168
|
+
// Its launch is kept with the circuit's results (`lancement`: its role, its session id, and the
|
|
169
|
+
// <objet> of a session that is not its role's own work, `tri`), which the bilan reads to count the
|
|
170
|
+
// sessions the circuit launched (scripts/bilan.mjs). Its sign of life names the session
|
|
171
|
+
// (`seanceId`) and the launch by its <evenement> and its <relance>
|
|
172
|
+
// (`lancement:<événement>:<relance>`), which an attempt played again recognizes. Its sheet is the
|
|
173
|
+
// schema <fiche>, by default its role's. It is an activity (`jouerLeGroupe`): <signeDeVie>
|
|
174
|
+
// receives the sign of life of its group, which names the launch, <annulation> (an AbortSignal)
|
|
175
|
+
// kills it, and a group a previous attempt left running (<precedent>, its last sign of life) is
|
|
176
|
+
// waited for before the place is taken (<prendrePlace>, `prendreUnePlace` of
|
|
177
|
+
// scripts/places-de-la-machine.mjs by default). Only an attempt Temporal plays again
|
|
178
|
+
// (`ctx.essaiDeLActe` 2 or more), at the launch <precedent> names, takes, once that group has
|
|
179
|
+
// ended, the result the session of the dead attempt ranged (its `seanceId`), with no second
|
|
180
|
+
// session, and writes the launch line that died with that attempt; a session dead without a
|
|
181
|
+
// result is launched anew, under the id of this attempt. A
|
|
182
|
+
// cancelled session throws SeanceAnnulee.
|
|
183
|
+
export async function lancer(
|
|
184
|
+
ctx,
|
|
185
|
+
role,
|
|
186
|
+
consigne,
|
|
187
|
+
{
|
|
188
|
+
fort,
|
|
189
|
+
horsEnveloppe,
|
|
190
|
+
droits = [],
|
|
191
|
+
session = [],
|
|
192
|
+
ouvre,
|
|
193
|
+
reprend,
|
|
194
|
+
fiche: sorte,
|
|
195
|
+
objet,
|
|
196
|
+
signeDeVie = () => {},
|
|
197
|
+
annulation = null,
|
|
198
|
+
precedent = null,
|
|
199
|
+
evenement,
|
|
200
|
+
relance = 1,
|
|
201
|
+
prendrePlace = prendreUnePlace,
|
|
202
|
+
} = {}
|
|
203
|
+
) {
|
|
204
|
+
// The traces of the session: its transcripts and the ticket's log.
|
|
205
|
+
const traces = () => Math.max(derniereTrace(ctx.transcriptions), mtime(ctx.journal));
|
|
206
|
+
// A group a previous attempt left alive ends before this one launches (`attendreLeGroupe`).
|
|
207
|
+
if (groupeVivant(precedent)) {
|
|
208
|
+
const r = await attendreLeGroupe(precedent, { immobileMs: ctx.immobileMs, traces, annulation });
|
|
209
|
+
if (r.annulee) {
|
|
210
|
+
throw new SeanceAnnulee(role);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (annulation?.aborted) {
|
|
214
|
+
throw new SeanceAnnulee(role);
|
|
215
|
+
}
|
|
216
|
+
const id = ouvre ?? reprend ?? session[1] ?? null;
|
|
217
|
+
if (!id) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`la séance du ${nomDuRole(role)} n'a pas d'identifiant : son résultat se range sous lui.`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
// The launch's identity, the logical event it is: its event and its relaunch.
|
|
223
|
+
const identite = `lancement:${evenement}:${relance}`;
|
|
224
|
+
// Only an attempt Temporal plays again (`essaiDeLActe` 2 or more), at the launch the dead
|
|
225
|
+
// attempt made last (its sign of life names it and its session), takes the result that session
|
|
226
|
+
// ranged: no second session. Dead without a result, it is launched anew, under this id.
|
|
227
|
+
if ((ctx.essaiDeLActe ?? 1) > 1 && precedent?.lancement === identite && precedent.seanceId) {
|
|
228
|
+
const mort = resultatRange(rangDeLaSeance(ctx, precedent.seanceId), precedent.seanceId);
|
|
229
|
+
if (mort) {
|
|
230
|
+
// The launch line of the dead attempt died in memory with it: written now, under its
|
|
231
|
+
// session, which the bilan counts as the circuit's.
|
|
232
|
+
inscrire(ctx, {
|
|
233
|
+
role: AUTEUR_DU_CIRCUIT,
|
|
234
|
+
lancement: { role, seance: precedent.seanceId, ...(objet ? { objet } : {}) },
|
|
235
|
+
});
|
|
236
|
+
return mort;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const rang = rangDeLaSeance(ctx, id);
|
|
240
|
+
mkdirSync(rang.dossier, { recursive: true });
|
|
241
|
+
rmSync(rang.fin, { force: true });
|
|
242
|
+
rmSync(rang.resultat, { force: true });
|
|
243
|
+
rmSync(rang.horsPlan, { force: true });
|
|
244
|
+
inscrire(ctx, {
|
|
245
|
+
role: AUTEUR_DU_CIRCUIT,
|
|
246
|
+
lancement: { role, seance: id, ...(objet ? { objet } : {}) },
|
|
247
|
+
});
|
|
248
|
+
const numero = prochainNumero(ctx.tmp);
|
|
249
|
+
const fichier = path.join(ctx.tmp, `consigne-${numero}.md`);
|
|
250
|
+
writeFileSync(fichier, consigne);
|
|
251
|
+
// A file, not a pipe: a session whose circuit is dead writes its errors without breaking.
|
|
252
|
+
const erreurs = path.join(ctx.tmp, `erreurs-${numero}.txt`);
|
|
253
|
+
let commande;
|
|
254
|
+
let fds;
|
|
255
|
+
if (horsEnveloppe) {
|
|
256
|
+
entete(ctx, role);
|
|
257
|
+
// Its result ranged under its id, as lancer.sh ranges a session's: claude's output, then its
|
|
258
|
+
// exit code once it ends, written by the shell that runs it, which outlives a dead circuit.
|
|
259
|
+
fds = [openSync(fichier, 'r'), openSync(rang.resultat, 'w'), openSync(ctx.journal, 'a')];
|
|
260
|
+
const fiche = [
|
|
261
|
+
'--output-format',
|
|
262
|
+
'json',
|
|
263
|
+
'--json-schema',
|
|
264
|
+
JSON.stringify(schemaDeFiche(sorte ?? role)),
|
|
265
|
+
];
|
|
266
|
+
commande = {
|
|
267
|
+
cmd: 'sh',
|
|
268
|
+
args: [
|
|
269
|
+
'-c',
|
|
270
|
+
'"$@"; c=$?; echo "$c" > "$0"; exit "$c"',
|
|
271
|
+
rang.fin,
|
|
272
|
+
process.env.CLAUDE_BIN || 'claude',
|
|
273
|
+
...['-p', '--agent', role, ...fiche, ...droits, '--add-dir', ctx.tmp, ...session],
|
|
274
|
+
],
|
|
275
|
+
cwd: existsSync(ctx.copie) ? ctx.copie : ctx.racine,
|
|
276
|
+
};
|
|
277
|
+
} else {
|
|
278
|
+
fds = ['ignore', 'ignore', openSync(erreurs, 'w')];
|
|
279
|
+
commande = {
|
|
280
|
+
cmd: 'bash',
|
|
281
|
+
args: [
|
|
282
|
+
// GRILLHOUSE_LANCEUR names a launcher of trial in place of lancer.sh, as CLAUDE_BIN does claude.
|
|
283
|
+
process.env.GRILLHOUSE_LANCEUR || LANCEUR,
|
|
284
|
+
...(fort ? FORT : []),
|
|
285
|
+
...(ouvre ? ['--seance', ouvre] : []),
|
|
286
|
+
...(reprend ? ['--reprise', reprend] : []),
|
|
287
|
+
// The schema of its sheet when it is not its role's (the explorateur's gesture).
|
|
288
|
+
...(sorte ? ['--fiche', sorte] : []),
|
|
289
|
+
// The plan of the session: the packages of the title, which it writes; its component the
|
|
290
|
+
// whole copy, which it reads.
|
|
291
|
+
'--paquets',
|
|
292
|
+
ecrireLaListe(ctx.paquets),
|
|
293
|
+
ctx.ticket,
|
|
294
|
+
role,
|
|
295
|
+
'.',
|
|
296
|
+
fichier,
|
|
297
|
+
],
|
|
298
|
+
cwd: ctx.racine,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
// Each session of an agent takes a place of the machine (scripts/places-de-la-machine.mjs) at
|
|
302
|
+
// its start and gives it back at its end: the circuit holds none between two sessions, nor on a
|
|
303
|
+
// question. The wait keeps the rank of the circuit's arrival, says its reason in the log, and is
|
|
304
|
+
// bounded as the lock of the machine's: « à repasser » (75).
|
|
305
|
+
let place;
|
|
306
|
+
try {
|
|
307
|
+
place = prendrePlace({
|
|
308
|
+
ticket: ctx.ticket,
|
|
309
|
+
rang: ctx.rang ?? undefined,
|
|
310
|
+
dire: l => appendFileSync(ctx.journal, `${l}\n`),
|
|
311
|
+
});
|
|
312
|
+
} catch (e) {
|
|
313
|
+
for (const fd of new Set(fds.filter(f => typeof f === 'number'))) {
|
|
314
|
+
closeSync(fd);
|
|
315
|
+
}
|
|
316
|
+
if (!(e instanceof AttenteDeLaMachine)) {
|
|
317
|
+
throw e;
|
|
318
|
+
}
|
|
319
|
+
throw new Arret('a-repasser', e.message);
|
|
320
|
+
}
|
|
321
|
+
// The session writes at the ticket under the author of its role, and its passes play on its
|
|
322
|
+
// place (the mark of the place, `place.env`), taking none of their own.
|
|
323
|
+
// A session out of the envelope (the relecteur, which plays tests) plays them on its share of
|
|
324
|
+
// the cores, under nice and ionice; the launcher of an enveloped one does it in the envelope.
|
|
325
|
+
const lancement = horsEnveloppe
|
|
326
|
+
? lancementDeLaPasse({
|
|
327
|
+
lourde: false,
|
|
328
|
+
cmd: commande.cmd,
|
|
329
|
+
args: commande.args,
|
|
330
|
+
env: { ...process.env, ...place.env, [ACTEUR]: role },
|
|
331
|
+
})
|
|
332
|
+
: {
|
|
333
|
+
cmd: commande.cmd,
|
|
334
|
+
args: commande.args,
|
|
335
|
+
env: { ...process.env, ...place.env, [ACTEUR]: role },
|
|
336
|
+
};
|
|
337
|
+
const fermer = () => {
|
|
338
|
+
for (const fd of new Set(fds.filter(f => typeof f === 'number'))) {
|
|
339
|
+
closeSync(fd);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
const r = await jouerLeGroupe({
|
|
343
|
+
cmd: lancement.cmd,
|
|
344
|
+
args: lancement.args,
|
|
345
|
+
cwd: commande.cwd,
|
|
346
|
+
env: lancement.env,
|
|
347
|
+
stdio: fds,
|
|
348
|
+
seanceId: id,
|
|
349
|
+
lancement: identite,
|
|
350
|
+
immobileMs: ctx.immobileMs,
|
|
351
|
+
traces,
|
|
352
|
+
signeDeVie,
|
|
353
|
+
annulation,
|
|
354
|
+
lance: enfant => {
|
|
355
|
+
fermer();
|
|
356
|
+
// The place is the session's own from now on: its process and its start, so that it is
|
|
357
|
+
// freed with the session, even if the circuit dies before.
|
|
358
|
+
if (enfant.pid) {
|
|
359
|
+
place.rattacher({ pid: enfant.pid, depart: departDe(enfant.pid) });
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
if (r.pid === null && r.annulee) {
|
|
364
|
+
fermer();
|
|
365
|
+
}
|
|
366
|
+
place.rendre();
|
|
367
|
+
if (r.annulee) {
|
|
368
|
+
throw new SeanceAnnulee(role);
|
|
369
|
+
}
|
|
370
|
+
let seance;
|
|
371
|
+
let sortie;
|
|
372
|
+
let horsPlan = null;
|
|
373
|
+
if (horsEnveloppe) {
|
|
374
|
+
seance = existsSync(rang.fin)
|
|
375
|
+
? Number(readFileSync(rang.fin, 'utf8').trim())
|
|
376
|
+
: r.erreur === null
|
|
377
|
+
? r.code
|
|
378
|
+
: null;
|
|
379
|
+
sortie = lire(rang.resultat).trim();
|
|
380
|
+
appendFileSync(ctx.journal, `${sortie}\n`);
|
|
381
|
+
spawnSync(process.execPath, [REGISTRE, '--copie', ctx.copie], {
|
|
382
|
+
cwd: ctx.racine,
|
|
383
|
+
stdio: ['ignore', 'ignore', 'ignore'],
|
|
384
|
+
});
|
|
385
|
+
} else {
|
|
386
|
+
seance = existsSync(rang.fin) ? Number(readFileSync(rang.fin, 'utf8').trim()) : null;
|
|
387
|
+
sortie = lire(rang.resultat).trim();
|
|
388
|
+
horsPlan = existsSync(rang.horsPlan) ? lire(rang.horsPlan).trim() : null;
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
code: r.code,
|
|
392
|
+
seance,
|
|
393
|
+
bloque: r.bloque,
|
|
394
|
+
horsPlan,
|
|
395
|
+
erreur: r.erreur ?? lire(erreurs),
|
|
396
|
+
sortie,
|
|
397
|
+
id,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// The group of a session, as an activity of Temporal runs a process: launched detached, the
|
|
402
|
+
// leader of a process group of its own, it sends a sign of life (<signeDeVie>, `{ pid, depart,
|
|
403
|
+
// seanceId, lancement }`: the leader of the group, its start, `departDe`, the id of the session
|
|
404
|
+
// the caller gives, and the identity of its launch, <lancement>, when it has one) at its launch and at each step of its watch, then null at its end. Its traces
|
|
405
|
+
// (<traces>, the latest moment they moved) standing still for <immobileMs>, its group gets
|
|
406
|
+
// SIGTERM, then SIGKILL 5 s later (`bloque`); cancelled (<annulation>, an AbortSignal, aborted
|
|
407
|
+
// before or during the play), its group gets SIGTERM, then SIGKILL 5 s later (`annulee`), and a
|
|
408
|
+
// play cancelled before its launch launches nothing. `{ code, pid, bloque, annulee, erreur }`, `code` the exit code of
|
|
409
|
+
// the leader (null when it did not start), `erreur` the message of a launch that failed.
|
|
410
|
+
export async function jouerLeGroupe({
|
|
411
|
+
cmd,
|
|
412
|
+
args,
|
|
413
|
+
cwd,
|
|
414
|
+
env,
|
|
415
|
+
stdio = 'ignore',
|
|
416
|
+
seanceId,
|
|
417
|
+
lancement = null,
|
|
418
|
+
immobileMs,
|
|
419
|
+
traces = () => 0,
|
|
420
|
+
signeDeVie = () => {},
|
|
421
|
+
annulation = null,
|
|
422
|
+
lance = () => {},
|
|
423
|
+
}) {
|
|
424
|
+
if (annulation?.aborted) {
|
|
425
|
+
return { code: null, pid: null, bloque: false, annulee: true, erreur: null };
|
|
426
|
+
}
|
|
427
|
+
return new Promise(resolve => {
|
|
428
|
+
const enfant = spawn(cmd, args, { cwd, detached: true, stdio, env });
|
|
429
|
+
const pid = enfant.pid ?? null;
|
|
430
|
+
const vie = pid
|
|
431
|
+
? { pid, depart: departDe(pid), seanceId, ...(lancement ? { lancement } : {}) }
|
|
432
|
+
: null;
|
|
433
|
+
lance(enfant);
|
|
434
|
+
if (vie) {
|
|
435
|
+
signeDeVie(vie);
|
|
436
|
+
}
|
|
437
|
+
let bloque = false;
|
|
438
|
+
let annulee = false;
|
|
439
|
+
let fini = false;
|
|
440
|
+
let erreur = null;
|
|
441
|
+
const arreter = () => {
|
|
442
|
+
signalerGroupe(pid, 'SIGTERM');
|
|
443
|
+
setTimeout(() => signalerGroupe(pid, 'SIGKILL'), 5_000).unref();
|
|
444
|
+
};
|
|
445
|
+
const veille = pid
|
|
446
|
+
? surveiller(
|
|
447
|
+
{ immobileMs, traces },
|
|
448
|
+
() => {
|
|
449
|
+
bloque = true;
|
|
450
|
+
arreter();
|
|
451
|
+
},
|
|
452
|
+
() => signeDeVie(vie)
|
|
453
|
+
)
|
|
454
|
+
: null;
|
|
455
|
+
const surAnnulation = () => {
|
|
456
|
+
annulee = true;
|
|
457
|
+
arreter();
|
|
458
|
+
};
|
|
459
|
+
annulation?.addEventListener('abort', surAnnulation, { once: true });
|
|
460
|
+
enfant.on('error', e => {
|
|
461
|
+
erreur = e.message;
|
|
462
|
+
if (!pid) {
|
|
463
|
+
enfant.emit('close', null);
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
enfant.on('close', code => {
|
|
467
|
+
if (fini) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
fini = true;
|
|
471
|
+
if (veille) {
|
|
472
|
+
clearInterval(veille);
|
|
473
|
+
}
|
|
474
|
+
annulation?.removeEventListener('abort', surAnnulation);
|
|
475
|
+
// What remains of the group goes with its leader.
|
|
476
|
+
if (bloque || annulee) {
|
|
477
|
+
signalerGroupe(pid, 'SIGKILL');
|
|
478
|
+
}
|
|
479
|
+
signeDeVie(null);
|
|
480
|
+
resolve({ code, pid, bloque, annulee, erreur });
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// The watch of the group <pid>: each step (a quarter of <immobileMs>, between 100 ms and 30 s), the
|
|
486
|
+
// sign of life <pouls>; its traces standing still for <immobileMs>, <bloque> called once. Its
|
|
487
|
+
// interval, which the caller clears.
|
|
488
|
+
export function surveiller({ immobileMs, traces }, bloque, pouls = () => {}) {
|
|
489
|
+
let bouge = Date.now();
|
|
490
|
+
let arrete = false;
|
|
491
|
+
const pas = Math.max(100, Math.min(30_000, Math.floor(immobileMs / 4)));
|
|
492
|
+
return setInterval(() => {
|
|
493
|
+
pouls();
|
|
494
|
+
bouge = Math.max(bouge, traces());
|
|
495
|
+
if (!arrete && Date.now() - bouge >= immobileMs) {
|
|
496
|
+
arrete = true;
|
|
497
|
+
bloque();
|
|
498
|
+
}
|
|
499
|
+
}, pas);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// The wait for the group <vie> left alive, under the same watch as a session (standing still, it
|
|
503
|
+
// is killed) and <annulation> (cancelled, it is killed and the wait ends `annulee`).
|
|
504
|
+
export async function attendreLeGroupe(vie, { immobileMs, traces, annulation = null }) {
|
|
505
|
+
const tuer = () => {
|
|
506
|
+
signalerGroupe(vie.pid, 'SIGTERM');
|
|
507
|
+
setTimeout(() => signalerGroupe(vie.pid, 'SIGKILL'), 5_000).unref();
|
|
508
|
+
};
|
|
509
|
+
const veille = surveiller({ immobileMs, traces }, tuer);
|
|
510
|
+
let annulee = false;
|
|
511
|
+
const surAnnulation = () => {
|
|
512
|
+
annulee = true;
|
|
513
|
+
tuer();
|
|
514
|
+
};
|
|
515
|
+
annulation?.addEventListener('abort', surAnnulation, { once: true });
|
|
516
|
+
try {
|
|
517
|
+
while (groupeVivant(vie)) {
|
|
518
|
+
await new Promise(r => setTimeout(r, 500));
|
|
519
|
+
}
|
|
520
|
+
} finally {
|
|
521
|
+
clearInterval(veille);
|
|
522
|
+
annulation?.removeEventListener('abort', surAnnulation);
|
|
523
|
+
}
|
|
524
|
+
return { annulee: annulee || Boolean(annulation?.aborted) };
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// The template of the instruction at <rang> (0 the testwriter's and the developpeur's, 1 the
|
|
528
|
+
// reviewer's, 2 any session's on a sheet absent or out of its schema, 3 the testwriter's and the
|
|
529
|
+
// developpeur's on a resumption, 4 the questionneur's on the plan, 5 the explorateur's on the plan,
|
|
530
|
+
// 6 the explorateur's on the questions of the plan, 7 the explorateur's on the tri of the
|
|
531
|
+
// discoveries, 8 the explorateur's on the gesture of a mechanical ticket), filled with <valeurs>.
|
|
532
|
+
export function consigne(valeurs, rang = 0) {
|
|
533
|
+
const texte = readFileSync(GABARIT, 'utf8');
|
|
534
|
+
const bloc = [...texte.matchAll(/```text\n([\s\S]*?)\n```/g)][rang];
|
|
535
|
+
if (!bloc) {
|
|
536
|
+
throw new Error(`gabarit sans bloc de consigne n° ${rang + 1} : ${GABARIT}`);
|
|
537
|
+
}
|
|
538
|
+
return `${bloc[1].replace(/\{\{(\w+)\}\}/g, (m, k) => (k in valeurs ? valeurs[k] : m))}\n`;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// One session of <role> on the whole ticket: its sheet. A relaunch on its step (<tentative> past
|
|
542
|
+
// 1) that is not the last (<derniere>) resumes the agent's session the circuit keeps
|
|
543
|
+
// (<reprise>, its author and id) with the short instruction (the fourth template); its sheet
|
|
544
|
+
// refused is asked again once of that same session, as of a fresh one (`jusquALaFiche`), so the
|
|
545
|
+
// question it carries goes up (BP 320.3.9); a resumption that ends in error (a code other than 0:
|
|
546
|
+
// the session not found) falls back on a fresh and whole session, under a new id, which
|
|
547
|
+
// <retenir> gives the circuit to keep before its launch. A fresh session's instruction (the first
|
|
548
|
+
// template) carries the ticket's description and notes as they are at its launch, the packages of
|
|
549
|
+
// the plan, and the last handover of its author at the ticket. Every instruction, fresh or resumed,
|
|
550
|
+
// carries the supervisor's context of the run at its head, as its task, and the findings of the
|
|
551
|
+
// reviewer still open for its role (<constats>, which the circuit keeps), all of them, whatever the relaunch: a proof
|
|
552
|
+
// refused, red checks, a sending, a RENDU, a resumption of the supervisor (`constatsDeLaSeance`);
|
|
553
|
+
// <change> says what changed on a resumption, when it is not the proof or the checks (the
|
|
554
|
+
// integration's refusal of the lot, `refus`). Returns the sheet and the findings it leaves,
|
|
555
|
+
// which the circuit keeps: the activity writes nothing of the circuit's memory.
|
|
556
|
+
// Throws an Arret for a launch that stops before its session, a motionless session, or
|
|
557
|
+
// a session that ends twice without a sheet that conforms.
|
|
558
|
+
export async function seance(
|
|
559
|
+
ctx,
|
|
560
|
+
role,
|
|
561
|
+
{
|
|
562
|
+
tentative,
|
|
563
|
+
rapport,
|
|
564
|
+
fort,
|
|
565
|
+
derniere,
|
|
566
|
+
change,
|
|
567
|
+
seanceId,
|
|
568
|
+
lectures,
|
|
569
|
+
constats: gardes = [],
|
|
570
|
+
reprise: gardee = null,
|
|
571
|
+
retenir = () => {},
|
|
572
|
+
...activite
|
|
573
|
+
}
|
|
574
|
+
) {
|
|
575
|
+
const nom = nomDuRole(role);
|
|
576
|
+
const reprise = tentative > 1 && !derniere && gardee?.agent === role ? gardee : null;
|
|
577
|
+
const { tache, ouverts, constats, valider, repondre } = constatsDeLaSeance(
|
|
578
|
+
ctx.contexte,
|
|
579
|
+
gardes,
|
|
580
|
+
role
|
|
581
|
+
);
|
|
582
|
+
// The last sign of life of a launch of this session, which a fresh session after a failed
|
|
583
|
+
// resumption waits for while its group runs.
|
|
584
|
+
let dernierSigne = activite.precedent ?? null;
|
|
585
|
+
const suivie = {
|
|
586
|
+
...activite,
|
|
587
|
+
signeDeVie: vie => {
|
|
588
|
+
if (vie) {
|
|
589
|
+
dernierSigne = vie;
|
|
590
|
+
}
|
|
591
|
+
activite.signeDeVie?.(vie);
|
|
592
|
+
},
|
|
593
|
+
};
|
|
594
|
+
const plan = ctx.paquets.join(', ');
|
|
595
|
+
const repondu = fiche => ({ fiche, constats: fiche ? repondre(gardes, fiche) : gardes });
|
|
596
|
+
if (reprise) {
|
|
597
|
+
const courte = {
|
|
598
|
+
role: nom,
|
|
599
|
+
ticket: ctx.ticket,
|
|
600
|
+
sujet: ctx.sujet,
|
|
601
|
+
paquets: plan,
|
|
602
|
+
tentative,
|
|
603
|
+
change:
|
|
604
|
+
change ??
|
|
605
|
+
(role === 'testwriter'
|
|
606
|
+
? 'la preuve du rouge, jouée après ta séance, refuse ton lot'
|
|
607
|
+
: 'les contrôles, joués après ta séance, sont rouges'),
|
|
608
|
+
rapport: rapport ?? 'aucun',
|
|
609
|
+
tache,
|
|
610
|
+
ouverts,
|
|
611
|
+
constats,
|
|
612
|
+
};
|
|
613
|
+
const fiche = await jusquALaFiche(ctx, role, consigne(courte, 3), {
|
|
614
|
+
fort,
|
|
615
|
+
premiere: 'reprend',
|
|
616
|
+
id: reprise.seance,
|
|
617
|
+
evenement: 'reprise',
|
|
618
|
+
repli: true,
|
|
619
|
+
valider,
|
|
620
|
+
...suivie,
|
|
621
|
+
});
|
|
622
|
+
if (fiche) {
|
|
623
|
+
return repondu(fiche);
|
|
624
|
+
}
|
|
625
|
+
commenter(
|
|
626
|
+
ctx,
|
|
627
|
+
role,
|
|
628
|
+
`reprise de la séance ${reprise.seance} finie en erreur : séance neuve et entière.`
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
const lots = lectures.lots();
|
|
632
|
+
const { description, notes } = leTicket(ctx);
|
|
633
|
+
// The last handover of this agent; for a developpeur without one yet, the testwriter's last.
|
|
634
|
+
const passation =
|
|
635
|
+
derniereDe(ctx, role) ?? (role === 'developpeur' ? derniereDe(ctx, 'testwriter') : null);
|
|
636
|
+
const valeurs = {
|
|
637
|
+
role: nom,
|
|
638
|
+
depot: ctx.racine,
|
|
639
|
+
ticket: ctx.ticket,
|
|
640
|
+
sujet: ctx.sujet,
|
|
641
|
+
paquets: plan,
|
|
642
|
+
reprise:
|
|
643
|
+
tentative > 1 || ctx.reprendre || ctx.depuis || fichesDe(ctx, role).length
|
|
644
|
+
? "oui : une séance d'avant a travaillé ce ticket ; ta copie garde son travail, le rapport ci-dessous dit ce qui reste"
|
|
645
|
+
: 'non',
|
|
646
|
+
lots: lots.length
|
|
647
|
+
? `${role === 'developpeur' ? 'le lot de tests' : 'tes tests'}, déjà dans la copie : ${lots.join(', ')}`
|
|
648
|
+
: 'aucun',
|
|
649
|
+
tache,
|
|
650
|
+
description: description.trim() || 'aucune',
|
|
651
|
+
// The section of the ticket's notes, absent without notes.
|
|
652
|
+
notes: notes.trim()
|
|
653
|
+
? `\nLES NOTES DU TICKET, l'état qu'un agent d'avant y a écrit :\n\n${notes.trim()}\n`
|
|
654
|
+
: '',
|
|
655
|
+
rapport: rapport ?? 'aucun',
|
|
656
|
+
ouverts,
|
|
657
|
+
constats,
|
|
658
|
+
passation: passation?.text ?? 'aucune',
|
|
659
|
+
references: lectures
|
|
660
|
+
.references()
|
|
661
|
+
.map(r => `- ${r.nom} : ${r.fichiers.map(f => `\`${f}\``).join(', ')}`)
|
|
662
|
+
.join('\n'),
|
|
663
|
+
};
|
|
664
|
+
retenir({ agent: role, seance: seanceId });
|
|
665
|
+
return repondu(
|
|
666
|
+
await jusquALaFiche(ctx, role, consigne(valeurs), {
|
|
667
|
+
fort,
|
|
668
|
+
valider,
|
|
669
|
+
id: seanceId,
|
|
670
|
+
evenement: 'neuve',
|
|
671
|
+
...suivie,
|
|
672
|
+
precedent: dernierSigne,
|
|
673
|
+
})
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// The findings of the reviewer open for <role> among <constats>, as a session of the run whose
|
|
678
|
+
// supervisor's context is <contexte> (`--contexte`, with `--depuis`, `--reprendre` or
|
|
679
|
+
// `--etendre`) receives them, as a review its author relaunches on a change he frames keeps its
|
|
680
|
+
// open threads in sight without blocking on them (BP 320.14.2.3: the context after the rule of
|
|
681
|
+
// the answers, a session that worked an old finding only, its sheet refused, « sans-livraison »
|
|
682
|
+
// twice). With a context, the context heads the instruction as its task (`tache`); the findings
|
|
683
|
+
// open at the launch of the run (`enContexte`, `auLancement`) are its context, after the others
|
|
684
|
+
// under their own heading, and a developpeur's sheet FAIT is not refused for want of an answer to
|
|
685
|
+
// one of them; every other finding, without a context or stated by a RENDU within the run, is its
|
|
686
|
+
// task, and his sheet FAIT answers each by its title, refused without one (`valider`,
|
|
687
|
+
// `reponsesAuxConstats`). Either way, each answer a developpeur's sheet gives is kept with its
|
|
688
|
+
// finding (`repondre`, `avecLesReponses`).
|
|
689
|
+
export function constatsDeLaSeance(contexte, constats, role) {
|
|
690
|
+
const siens = (constats ?? []).filter(c => c.role === role);
|
|
691
|
+
const anciens = siens.filter(c => c.enContexte);
|
|
692
|
+
const neufs = siens.filter(c => !c.enContexte);
|
|
693
|
+
const titres = role === 'developpeur' ? neufs.map(c => c.titre) : [];
|
|
694
|
+
const enContexte = `les constats ouverts au lancement de la passe du superviseur, donnés en contexte : ta tâche est celle du superviseur, ci-dessus ; chacun reste ouvert jusqu'à la relecture qui le juge levé, et ta fiche n'a pas à répondre à chacun`;
|
|
695
|
+
const titre =
|
|
696
|
+
'LES CONSTATS DU RELECTEUR QUI RESTENT OUVERTS pour ton rôle, ' +
|
|
697
|
+
(anciens.length && !neufs.length ? enContexte : "chacun jusqu'à la relecture qui le juge levé");
|
|
698
|
+
const texte =
|
|
699
|
+
anciens.length && neufs.length
|
|
700
|
+
? `${texteDesOuverts(neufs)}\n\nPUIS ${enContexte} :\n\n${texteDesOuverts(anciens, neufs.length)}`
|
|
701
|
+
: texteDesOuverts(siens);
|
|
702
|
+
return {
|
|
703
|
+
tache: contexte
|
|
704
|
+
? `TA TÂCHE, que le superviseur te donne ; elle passe avant le ticket, le rapport${anciens.length ? ' et les constats donnés en contexte' : ''} ci-dessous :\n\n${contexte}\n\n`
|
|
705
|
+
: '',
|
|
706
|
+
ouverts: titre,
|
|
707
|
+
constats: texte,
|
|
708
|
+
valider: f => reponsesAuxConstats(f, titres),
|
|
709
|
+
repondre: (tous, fiche) =>
|
|
710
|
+
role === 'developpeur' && siens.length ? avecLesReponses(tous, fiche) : tous,
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// The findings <constats> as a run launched with the supervisor's context <contexte> holds them:
|
|
715
|
+
// each one open at its launch marked `enContexte`, as the threads already open when the author
|
|
716
|
+
// relaunches a review on a change he frames; without a context, none. A finding a RENDU states
|
|
717
|
+
// within the run comes without the mark (`constatsOuverts`), and is the session's task again.
|
|
718
|
+
export const auLancement = (contexte, constats) =>
|
|
719
|
+
(constats ?? []).map(c => {
|
|
720
|
+
const { enContexte: _ancien, ...reste } = c;
|
|
721
|
+
return contexte ? { ...reste, enContexte: true } : reste;
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
// The findings <constats>, each finding of the developpeur that his sheet <fiche> answers (by its
|
|
725
|
+
// title, numbered or not: `cleDuConstat`) with its answer `{ etat, raison, piece }`, as a thread
|
|
726
|
+
// of a review keeps the author's reply under its comment.
|
|
727
|
+
function avecLesReponses(constats, fiche) {
|
|
728
|
+
const parTitre = new Map((fiche.reponses ?? []).map(r => [cleDuConstat(r.titre), r]));
|
|
729
|
+
return (constats ?? []).map(c => {
|
|
730
|
+
const r = c.role === 'developpeur' ? parTitre.get(c.titre) : undefined;
|
|
731
|
+
if (!r) {
|
|
732
|
+
return c;
|
|
733
|
+
}
|
|
734
|
+
return {
|
|
735
|
+
...c,
|
|
736
|
+
reponse: { etat: r.etat, ...(r.raison ? { raison: r.raison } : {}), piece: r.piece },
|
|
737
|
+
};
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// The launch <r> of a session of <role>, or the Arret it is: a session its lock stopped on a
|
|
742
|
+
// write out of the plan (« hors-plan », the write as its piece), a motionless session
|
|
743
|
+
// (« bloqué »), a launch that stops before its session (« lancement »).
|
|
744
|
+
export function seanceLancee(ctx, role, r) {
|
|
745
|
+
if (r.horsPlan) {
|
|
746
|
+
throw new Arret(
|
|
747
|
+
'hors-plan',
|
|
748
|
+
`Le crochet de la séance du ${nomDuRole(role)} l'arrête sur une écriture hors du plan du ticket (ses paquets : ${ctx.paquets.join(', ')}) :\n\n${r.horsPlan}`,
|
|
749
|
+
{ piece: r.horsPlan }
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
if (r.bloque) {
|
|
753
|
+
const minutes = Math.round(ctx.immobileMs / 60_000);
|
|
754
|
+
throw new Arret(
|
|
755
|
+
'bloqué',
|
|
756
|
+
`La transcription de la séance du ${role} n'a pas bougé en ${minutes ? `${minutes} min` : `${ctx.immobileMs} ms`} : la séance est arrêtée. Les dernières lignes du journal :\n\n${fin(lire(ctx.journal), 40)}`
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
if (r.seance === null) {
|
|
760
|
+
throw new Arret(
|
|
761
|
+
'lancement',
|
|
762
|
+
`Le lanceur s'arrête avant la séance du ${role} (code ${r.code}).\n${r.erreur.trim()}\n\n${fin(lire(ctx.journal), 20)}`
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// The relaunch of the event <evenement> the dead attempt <precedent> of <ctx> made last (2, its
|
|
768
|
+
// resumption, or 1), when this attempt is one Temporal plays again and that session ranged its
|
|
769
|
+
// result; else 1.
|
|
770
|
+
function relanceDeLaMorte(ctx, evenement, precedent) {
|
|
771
|
+
if ((ctx.essaiDeLActe ?? 1) < 2 || !precedent?.seanceId) {
|
|
772
|
+
return 1;
|
|
773
|
+
}
|
|
774
|
+
if (!existsSync(rangDeLaSeance(ctx, precedent.seanceId).fin)) {
|
|
775
|
+
return 1;
|
|
776
|
+
}
|
|
777
|
+
return precedent.lancement === `lancement:${evenement}:2` ? 2 : 1;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
// The session of <role> with the instruction <texte>, its sheet read in its result
|
|
781
|
+
// (scripts/resultats.mjs): the sheet, kept with the ticket's sheets, its discoveries filed. A
|
|
782
|
+
// session that ends without a sheet that conforms (none, one out of its schema, a code other than
|
|
783
|
+
// 0) is resumed once, the same session, with the short instruction that names what lacks (the
|
|
784
|
+
// third template). The session opens under the id <id>, which its caller gives (a caller that plays
|
|
785
|
+
// an attempt again gives the same, and the session resumes), or resumes it with <premiere>
|
|
786
|
+
// « reprend »; with <repli> (a resumption), a session that ends in error returns null, for a
|
|
787
|
+
// fresh session in its place. Throws an Arret for a launch that stops before its session, a
|
|
788
|
+
// motionless session, or twice no sheet that conforms (« sans-fiche »). <avec> joins its fields
|
|
789
|
+
// to the sheet's entry (the lot a review read); <valider>(sheet, attempt) names what makes a sheet
|
|
790
|
+
// out of conformity beyond its schema at that attempt (an unknown package of a plan, an answer
|
|
791
|
+
// without a line for a question put, a discovery without its verdict), or null. <fiche> names its
|
|
792
|
+
// sheet's schema when it is not its role's (`tri`), and <objet> its launch (`lancer`). Its sign of
|
|
793
|
+
// life (<signeDeVie>), its cancellation (<annulation>) and the group of an attempt before
|
|
794
|
+
// (<precedent>) go to each launch, `lancer`, the one place that waits for a group still alive:
|
|
795
|
+
// its second launch passes the group of its first. <surLaSeance> receives the id of the session
|
|
796
|
+
// whose sheet it keeps (the dead attempt's when it took that one up).
|
|
797
|
+
export async function jusquALaFiche(ctx, role, texte, options = {}) {
|
|
798
|
+
const {
|
|
799
|
+
premiere = 'ouvre',
|
|
800
|
+
id,
|
|
801
|
+
evenement,
|
|
802
|
+
avec = {},
|
|
803
|
+
valider = () => null,
|
|
804
|
+
repli = false,
|
|
805
|
+
surLaSeance = () => {},
|
|
806
|
+
...reste
|
|
807
|
+
} = options;
|
|
808
|
+
if (!id) {
|
|
809
|
+
throw new Error(
|
|
810
|
+
`la séance du ${nomDuRole(role)} n'a pas d'identifiant : il vient de l'appelant (\`id\`).`
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
if (!evenement) {
|
|
814
|
+
throw new Error(
|
|
815
|
+
`la séance du ${nomDuRole(role)} n'a pas d'événement (\`evenement\`) : il nomme ses lancements.`
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
// The session its relaunch resumes: the one whose result came back, the dead attempt's when this
|
|
819
|
+
// attempt took it up.
|
|
820
|
+
let courante = id;
|
|
821
|
+
const ouvrir = mode =>
|
|
822
|
+
reste.horsEnveloppe
|
|
823
|
+
? { session: [mode === 'ouvre' ? '--session-id' : '--resume', courante] }
|
|
824
|
+
: { [mode]: courante };
|
|
825
|
+
let lu = null;
|
|
826
|
+
// The last sign of life of a launch, which the next one waits for while its group runs.
|
|
827
|
+
let derniere = reste.precedent ?? null;
|
|
828
|
+
// An attempt Temporal plays again starts at the launch the dead attempt made last, its
|
|
829
|
+
// relaunch of this event whatever its rank, when that session ranged its result (`lancer`).
|
|
830
|
+
const premier = relanceDeLaMorte(ctx, evenement, derniere);
|
|
831
|
+
const signeDeVie = vie => {
|
|
832
|
+
if (vie) {
|
|
833
|
+
derniere = vie;
|
|
834
|
+
}
|
|
835
|
+
reste.signeDeVie?.(vie);
|
|
836
|
+
};
|
|
837
|
+
for (let essai = premier; essai <= 2; essai++) {
|
|
838
|
+
const courte = () => consigne({ ticket: ctx.ticket, sujet: ctx.sujet, erreur: lu.erreur }, 2);
|
|
839
|
+
const r = await lancer(ctx, role, essai === 1 || !lu ? texte : courte(), {
|
|
840
|
+
...reste,
|
|
841
|
+
precedent: derniere,
|
|
842
|
+
evenement,
|
|
843
|
+
relance: essai,
|
|
844
|
+
signeDeVie,
|
|
845
|
+
...ouvrir(essai === 1 ? premiere : 'reprend'),
|
|
846
|
+
});
|
|
847
|
+
seanceLancee(ctx, role, r);
|
|
848
|
+
courante = r.id ?? courante;
|
|
849
|
+
if (repli && r.seance !== 0) {
|
|
850
|
+
return null;
|
|
851
|
+
}
|
|
852
|
+
lu =
|
|
853
|
+
r.seance === 0
|
|
854
|
+
? lireSaFiche(ctx, reste.fiche ?? role, r.sortie)
|
|
855
|
+
: { erreur: `la séance finit en erreur (code ${r.seance})` };
|
|
856
|
+
const faute = lu.fiche ? valider(lu.fiche, essai) : null;
|
|
857
|
+
if (faute) {
|
|
858
|
+
lu = { erreur: `fiche non conforme : ${faute}` };
|
|
859
|
+
}
|
|
860
|
+
if (lu.fiche) {
|
|
861
|
+
// The session that gave it, which a resumption of it names (the plan's answer).
|
|
862
|
+
surLaSeance(courante);
|
|
863
|
+
return garder(ctx, role, lu.fiche, avec);
|
|
864
|
+
}
|
|
865
|
+
if (essai === 1) {
|
|
866
|
+
commenter(ctx, role, `séance finie sans fiche conforme : ${lu.erreur} ; reprise une fois.`);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
throw new Arret(
|
|
870
|
+
'sans-fiche',
|
|
871
|
+
`Deux fois, la séance du ${nomDuRole(role)} finit sans fiche conforme : ${lu.erreur}. Le journal du ticket : ${ctx.journal}`
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// The sheet of schema <sorte> (a role's, or the tri's) in the output <sortie> of its session
|
|
876
|
+
// (`lireFiche`), each file piece of it checked in the ticket's copy, or in the main tree before the
|
|
877
|
+
// copy exists and once the integration removed it, and each piece of the ticket in its description.
|
|
878
|
+
export const lireSaFiche = (ctx, sorte, sortie) =>
|
|
879
|
+
lireFiche(sorte, sortie, {
|
|
880
|
+
copie: existsSync(ctx.copie) ? ctx.copie : ctx.racine,
|
|
881
|
+
ticket: leTicket(ctx).description,
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
// The sheet <fiche> of <role>, kept with the ticket's sheets, <avec> joined to its entry, each of
|
|
885
|
+
// its discoveries filed closed under the ticket (the effect `decouverte`), its components the
|
|
886
|
+
// packages of the plan, and kept with the circuit's results (`decouverte`: its id and its subject),
|
|
887
|
+
// which the tri reads; returns it. A body `@<fichier>` is read from its file (from the main tree),
|
|
888
|
+
// so that the effect carries its text.
|
|
889
|
+
export function garder(ctx, role, fiche, avec) {
|
|
890
|
+
inscrire(ctx, { role, fiche, ...avec });
|
|
891
|
+
// The components of the plan, read once a discovery is to be filed.
|
|
892
|
+
const composants = () => nomsDe(ctx, ctx.paquets).join(', ');
|
|
893
|
+
for (const d of fiche.decouvertes ?? []) {
|
|
894
|
+
const corps = d.corps.startsWith('@')
|
|
895
|
+
? readFileSync(path.resolve(ctx.racine, d.corps.slice(1)), 'utf8').trimEnd()
|
|
896
|
+
: d.corps;
|
|
897
|
+
emettre(ctx, {
|
|
898
|
+
genre: 'decouverte',
|
|
899
|
+
role: AUTEUR_DU_CIRCUIT,
|
|
900
|
+
sujet: d.sujet,
|
|
901
|
+
corps,
|
|
902
|
+
composants: composants(),
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
return fiche;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// The findings <constats> as an agent's instruction carries them, each under its heading, with
|
|
909
|
+
// what it holds, its body and its piece, numbered after <avant>; « aucun » without one.
|
|
910
|
+
export const texteDesOuverts = (constats, avant = 0) =>
|
|
911
|
+
constats.length
|
|
912
|
+
? constats
|
|
913
|
+
.map(
|
|
914
|
+
(c, i) =>
|
|
915
|
+
`### Constat ${avant + i + 1} — ${c.titre}\nBloquant : ${c.regle}\n${c.corps}${c.piece ? `\nPièce : ${c.piece}` : ''}`
|
|
916
|
+
)
|
|
917
|
+
.join('\n\n')
|
|
918
|
+
: 'aucun';
|