@roomi-fields/grillhouse 0.51.0 → 0.53.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 +68 -0
- package/agents/direct.md +1 -1
- package/cadre/templates/projet/vitest.config.cjs +45 -0
- package/charte/plan.md +47 -0
- package/charte/preuve.md +39 -0
- package/charte/superviseur.md +60 -0
- package/charte/tests.md +38 -0
- package/charte.md +23 -178
- package/dist/temporal/circuit/appel.d.ts +2 -0
- package/dist/temporal/circuit/appel.js +24 -2
- package/dist/temporal/circuit/appel.js.map +1 -1
- package/dist/temporal/circuit/client.d.ts +15 -7
- package/dist/temporal/circuit/client.js +42 -11
- package/dist/temporal/circuit/client.js.map +1 -1
- package/dist/temporal/circuit/commande.js +17 -6
- package/dist/temporal/circuit/commande.js.map +1 -1
- package/dist/temporal/circuit/contrat.d.ts +9 -0
- package/dist/temporal/circuit/contrat.js +6 -0
- package/dist/temporal/circuit/contrat.js.map +1 -1
- package/dist/temporal/circuit/deroule.js +25 -4
- package/dist/temporal/circuit/deroule.js.map +1 -1
- package/dist/temporal/client.d.ts +35 -1
- package/dist/temporal/client.js +144 -1
- package/dist/temporal/client.js.map +1 -1
- package/dist/temporal/commande.js +31 -13
- package/dist/temporal/commande.js.map +1 -1
- package/dist/temporal/etat.d.ts +3 -1
- package/dist/temporal/etat.js +31 -17
- package/dist/temporal/etat.js.map +1 -1
- package/dist/temporal/file/activites.js +1 -1
- package/dist/temporal/file/activites.js.map +1 -1
- package/dist/temporal/file/contrat.d.ts +4 -5
- package/dist/temporal/file/contrat.js +2 -2
- package/dist/temporal/file/contrat.js.map +1 -1
- package/dist/temporal/file/deroule.js +7 -5
- package/dist/temporal/file/deroule.js.map +1 -1
- package/dist/temporal/installation.d.ts +103 -53
- package/dist/temporal/installation.js +842 -237
- package/dist/temporal/installation.js.map +1 -1
- package/dist/temporal/nuits/deroule.js +3 -1
- package/dist/temporal/nuits/deroule.js.map +1 -1
- package/dist/temporal/places/deroule.js +2 -1
- package/dist/temporal/places/deroule.js.map +1 -1
- package/dist/temporal/sonde/deroule.js +2 -1
- package/dist/temporal/sonde/deroule.js.map +1 -1
- package/dist/temporal/tickets/deroule.js +4 -3
- package/dist/temporal/tickets/deroule.js.map +1 -1
- package/dist/temporal/travailleur.d.ts +7 -1
- package/dist/temporal/travailleur.js +49 -25
- package/dist/temporal/travailleur.js.map +1 -1
- package/docs/INTERFACE.md +20 -14
- package/docs/architecture/circuit.md +19 -16
- package/docs/architecture/entree.md +8 -9
- package/docs/architecture/greffon.md +54 -20
- package/docs/architecture/installation.md +99 -60
- package/docs/architecture/machine.md +31 -4
- package/docs/architecture/tests.md +22 -8
- package/docs/lexique.md +12 -3
- package/hooks/hooks.json +10 -10
- package/hooks/register.tsx +84 -2
- package/package.json +4 -2
- package/scripts/activites.mjs +25 -9
- package/scripts/aiguillage.mjs +1 -1
- package/scripts/attente-au-tour.mjs +2 -3
- package/scripts/bilan.mjs +116 -56
- package/scripts/bilans-gardes.mjs +37 -0
- package/scripts/circuit.mjs +256 -42
- package/scripts/circuits-du-serveur.mjs +3 -2
- package/scripts/circuits-tenus.d.mts +7 -0
- package/scripts/circuits-tenus.mjs +17 -0
- package/scripts/copie-de-montee.mjs +354 -0
- package/scripts/copies-du-depot.d.mts +13 -0
- package/scripts/copies-du-depot.mjs +66 -0
- package/scripts/copies-finies.mjs +6 -40
- package/scripts/crochets.mjs +16 -2
- package/scripts/direct.mjs +2 -2
- package/scripts/droits.mjs +117 -38
- package/scripts/engendres.mjs +5 -3
- package/scripts/entree-de-seance.mjs +35 -0
- package/scripts/enveloppe/enveloppe.mjs +23 -16
- package/scripts/enveloppe/lancer.sh +32 -22
- package/scripts/enveloppe/travail-de-la-copie.mjs +154 -0
- package/scripts/etapes.mjs +11 -3
- package/scripts/faits-du-circuit.mjs +12 -5
- package/scripts/file-des-tickets.d.mts +13 -2
- package/scripts/file-des-tickets.mjs +44 -12
- package/scripts/greffons.mjs +42 -27
- package/scripts/grillhouse-maj.mjs +105 -85
- package/scripts/init.mjs +1 -1
- package/scripts/integration/file.mjs +5 -2
- package/scripts/integration/integrer.mjs +14 -4
- package/scripts/jointure.d.ts +18 -1
- package/scripts/langages/c/commandes.mjs +17 -7
- package/scripts/langages/cargo/commandes.mjs +87 -34
- package/scripts/langages/cargo/index.mjs +6 -3
- package/scripts/langages/cargo/sccache.mjs +15 -12
- package/scripts/langages/python/commandes.mjs +68 -15
- package/scripts/langages/python/squelette.mjs +4 -3
- package/scripts/langages/typescript/configurations-de-vitest.mjs +118 -0
- package/scripts/langages/typescript/index.mjs +14 -12
- package/scripts/langages/typescript/migrations/configurations-en-commonjs.mjs +299 -0
- package/scripts/langages/typescript/squelette.mjs +20 -17
- package/scripts/langages/typescript/tests-de-nuit.mjs +3 -3
- package/scripts/langages/typescript/turbo-des-paquets.mjs +76 -39
- package/scripts/langages/typescript/verifier.mjs +27 -2
- package/scripts/langages/typescript/vitest-config/base.mjs +1 -1
- package/scripts/langages/typescript/vitest-config/bornes.mjs +1 -1
- package/scripts/langages/typescript/vitest-config/cibles.mjs +2 -2
- package/scripts/langages/typescript/{vitest.nuit.config.mjs → vitest.nuit.config.cjs} +61 -50
- package/scripts/mesure/pression.mjs +5 -3
- package/scripts/migrations/serveurs-de-l-index.mjs +1 -1
- package/scripts/migrations/suivi-du-superviseur-retire.mjs +56 -0
- package/scripts/migrations.mjs +2 -0
- package/scripts/montee.mjs +524 -0
- package/scripts/nuit.sh +3 -2
- package/scripts/outil.mjs +5 -3
- package/scripts/paquet-npm.mjs +22 -0
- package/scripts/paquet.mjs +5 -5
- package/scripts/pre-compact.mjs +25 -0
- package/scripts/reponses-du-circuit.d.mts +17 -2
- package/scripts/reponses-du-circuit.mjs +78 -20
- package/scripts/resultats.mjs +42 -14
- package/scripts/retirer-les-copies-finies.mjs +4 -7
- package/scripts/seances.mjs +81 -29
- package/scripts/services-du-noyau.mjs +7 -2
- package/scripts/session-start.sh +19 -10
- package/scripts/sortie-de-seance.mjs +70 -0
- package/scripts/sortie.mjs +4 -7
- package/scripts/sous-commandes.mjs +1 -1
- package/scripts/superviseur.mjs +417 -159
- package/scripts/tableau.mjs +249 -152
- package/scripts/ticket-du-circuit.mjs +22 -0
- package/scripts/transitions.d.mts +6 -9
- package/scripts/transitions.mjs +123 -36
- package/scripts/verrou-de-fichier.d.mts +11 -0
- package/skills/direct/SKILL.md +21 -11
- package/skills/explorateur/SKILL.md +8 -3
- package/skills/grill/SKILL.md +11 -8
- package/skills/grill/references/paquets.md +4 -4
- package/skills/pitmaster/SKILL.md +99 -53
- package/skills/pitmaster/references/cadre.md +1 -1
- package/skills/pitmaster/references/consigne-agent.md +1 -1
- package/skills/pitmaster/references/tour.md +6 -5
- package/skills/relecteur/SKILL.md +9 -2
- package/skills/testwriter/SKILL.md +3 -3
- package/cadre/templates/projet/pitmaster/SUIVI.md +0 -22
- package/cadre/templates/projet/vitest.config.ts +0 -44
- package/scripts/attente-a-l-arret.mjs +0 -114
package/scripts/superviseur.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Mechanism: greffon.md, §5.1 and §5.2. Played by the session start (scripts/session-start.sh),
|
|
4
4
|
// which writes what it says to the session.
|
|
5
5
|
//
|
|
6
|
-
// npx grillhouse superviseur <racine>
|
|
6
|
+
// npx grillhouse superviseur <racine> [<source>]
|
|
7
7
|
//
|
|
8
8
|
// - Out of a git repository, in an agent's copy (a worktree whose git directory is not the common
|
|
9
9
|
// one) and in a session of a role that the circuit launches (BEADS_ACTOR set), nothing is taken
|
|
@@ -12,11 +12,19 @@
|
|
|
12
12
|
// copies, taken through scripts/verrou-de-fichier.mjs for the session's own process: the first
|
|
13
13
|
// process above this one named `claude`, whatever stands between them; without one, the first
|
|
14
14
|
// that is not a shell (sh, bash, dash, zsh). It holds as long as that process lives.
|
|
15
|
-
// -
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
15
|
+
// - <source> is the one of the SessionStart hook (`startup` without one). Free, or held by a
|
|
16
|
+
// process that is gone: taken. Held by the session itself: kept, and nothing is said after a
|
|
17
|
+
// resume. After a /clear, the session that holds the lock receives « ## Reprise de la
|
|
18
|
+
// supervision après un /clear » (load `grillhouse:pitmaster`, take up the note of resumption, no
|
|
19
|
+
// whole round, put the owner's pending question again at the first turn), and after a compaction
|
|
20
|
+
// « ## Reprise de la supervision après un compactage » (the same, with: finish the work in hand,
|
|
21
|
+
// hold the summary as more recent than the note on what came after it, put the pending question
|
|
22
|
+
// again if it still waits); then what a session that takes the lock receives. Held by another
|
|
23
|
+
// live session: the section « ## Un autre superviseur tient ce dépôt » names its process and
|
|
24
|
+
// since when, and asks to say so to the owner and to launch no circuit. A declared milestone ends
|
|
25
|
+
// with the context that declared it: it is removed at every opening of the holder. The hook
|
|
26
|
+
// plays no opening for the compaction of a subagent (scripts/session-start.sh).
|
|
27
|
+
// - The session whose opening takes the lock (`ouvertureDuSuperviseur`) receives « ## Les questions
|
|
20
28
|
// des circuits », then, when the repository has circuits (read from the Temporal server in one
|
|
21
29
|
// call, scripts/circuits-du-serveur.mjs), « ## Les circuits du dépôt »: each circuit that runs;
|
|
22
30
|
// each circuit stopped on a question, with the command that answers it; each circuit ended
|
|
@@ -24,8 +32,30 @@
|
|
|
24
32
|
// written, else `--depuis <testwriter|developpeur> --contexte <texte>`); a server that does not
|
|
25
33
|
// answer is said; then « ## La file des tickets », the tickets of the queue without their
|
|
26
34
|
// section « ## Architecture », which the queue never starts (scripts/file-des-tickets.mjs).
|
|
35
|
+
// Last, « ## La note de reprise » gives the note of resumption, when one is written.
|
|
27
36
|
// Exit 0, whatever it finds.
|
|
28
37
|
//
|
|
38
|
+
// npx grillhouse superviseur --jalon <fichier>
|
|
39
|
+
// npx grillhouse superviseur --question <fichier>
|
|
40
|
+
//
|
|
41
|
+
// - Played by the session that holds the lock, from the root of the repository. The note of
|
|
42
|
+
// resumption, one per repository, is `<git common dir>/grillhouse-reprise.md`. `--jalon` replaces
|
|
43
|
+
// it whole by the text of <fichier> and declares a milestone, which replaces the one before
|
|
44
|
+
// (`<git common dir>/grillhouse-jalon.json`); `--question` adds the text at its end, creating it,
|
|
45
|
+
// and declares nothing. Exit 2 and the reason on the error stream, nothing written, on a file
|
|
46
|
+
// that is absent or empty, a session that does not hold the lock, a session of a role or a copy.
|
|
47
|
+
//
|
|
48
|
+
// npx grillhouse superviseur --renouveler <dossier> <arretA> <messageA>
|
|
49
|
+
//
|
|
50
|
+
// - Played by the greffon at each period: writes the line `{"reprise": <message>}` when the session
|
|
51
|
+
// is to be compacted (`renouvellement`: the message of resumption at a milestone that is due,
|
|
52
|
+
// empty after 55 minutes of idleness), nothing otherwise.
|
|
53
|
+
//
|
|
54
|
+
// npx grillhouse pre-compact
|
|
55
|
+
//
|
|
56
|
+
// - Played by the PreCompact hook (scripts/pre-compact.mjs): the instructions of the summary of a
|
|
57
|
+
// compaction (`consignesDuResume`).
|
|
58
|
+
//
|
|
29
59
|
// npx grillhouse superviseur --relever [<dossier>]
|
|
30
60
|
//
|
|
31
61
|
// - One reading of the circuits for the greffon (mods/grillhouse/hooks/register.tsx), which runs
|
|
@@ -34,26 +64,29 @@
|
|
|
34
64
|
// reads. It writes the message (`texteDesQuestions`) when `relever` gives something, nothing
|
|
35
65
|
// otherwise; exit 1 and the fault on the error stream when `grillhouse.rappel` of the project is
|
|
36
66
|
// at fault, or when the reading of another project of the group fails, the message of the others
|
|
37
|
-
// then written all the same.
|
|
67
|
+
// then written all the same. The message ends, once for each night (`grillhouse.plageDeNuit`),
|
|
68
|
+
// with the request to write the note and declare a milestone, at a reading where no question of a
|
|
69
|
+
// circuit waits for the supervisor.
|
|
38
70
|
// - `superviseur --lue <dossier> <lueA> <envoyeesAvant>` marks read the questions sent up to
|
|
39
71
|
// `envoyeesAvant`; `superviseur --chez-le-responsable <dossier> <ticket>` marks a question
|
|
40
72
|
// carried to the owner: silent until the circuit answers.
|
|
41
73
|
// - `relever` is the one function of the reading, of the re-presentation and of the file of the
|
|
42
74
|
// stops gone up: a question that never went up, or was read <rappelMs> ago (`grillhouse.rappel`
|
|
43
75
|
// minutes, 10 by default, scripts/circuits-cles.mjs), is given once per due time while its
|
|
44
|
-
// circuit stands on the same stop; one
|
|
76
|
+
// circuit stands on the same stop; one addressed to the owner goes up once, without reminder,
|
|
77
|
+
// and the opening lists it; one answered leaves the file
|
|
45
78
|
// `.claude/worktrees/questions-remontees.json`. A stop is kept there by its ticket, the run of
|
|
46
79
|
// its workflow, the rank of its question in that run and its stop, with the times of the first
|
|
47
|
-
// going up and of the last presentation. The
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
// (`.claude/worktrees/ci-de-main-rendue.json`), cleared at the next green.
|
|
80
|
+
// going up and of the last presentation. The alert of the CI of main (a red, or a CI not read,
|
|
81
|
+
// scripts/ci-de-main.mjs) is given once per passage (`.claude/worktrees/ci-de-main-rendue.json`),
|
|
82
|
+
// cleared at the next green. A circuit integrated gives nothing: it is read on the board.
|
|
51
83
|
// - The reading covers the project and each other project of its group (`grillhouse.groupe`) that
|
|
52
84
|
// no other live session of supervision holds, each under its name and its folder.
|
|
53
85
|
import { spawnSync } from 'node:child_process';
|
|
54
|
-
import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
86
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
55
87
|
import path from 'node:path';
|
|
56
88
|
import { pathToFileURL } from 'node:url';
|
|
89
|
+
import { nuitEnCours, plageDeNuit } from './bilan.mjs';
|
|
57
90
|
import { lireEtOuvrirLeDefautDeMain } from './ci-de-main.mjs';
|
|
58
91
|
import { lacherVerrou, prendreVerrou } from './verrou-de-fichier.mjs';
|
|
59
92
|
import { vivant } from './mesure/base-de-passe.mjs';
|
|
@@ -67,7 +100,14 @@ import {
|
|
|
67
100
|
} from './tableau.mjs';
|
|
68
101
|
import { rappelDuProjet, reglageDuRappel } from './circuits-cles.mjs';
|
|
69
102
|
import { lireGroupe } from './groupe-cles.mjs';
|
|
70
|
-
import {
|
|
103
|
+
import {
|
|
104
|
+
etapeDuCircuit,
|
|
105
|
+
libelle,
|
|
106
|
+
REPONSES,
|
|
107
|
+
RESPONSABLE,
|
|
108
|
+
sansLesReponses,
|
|
109
|
+
SUPERVISEUR,
|
|
110
|
+
} from './etapes.mjs';
|
|
71
111
|
import { sigleDuProjet } from './sigle-du-projet.mjs';
|
|
72
112
|
import {
|
|
73
113
|
enFileSansArchitecture,
|
|
@@ -75,9 +115,23 @@ import {
|
|
|
75
115
|
lireLesExternes,
|
|
76
116
|
lireLesTickets,
|
|
77
117
|
lotEstSurMain,
|
|
118
|
+
reporteJusqua,
|
|
78
119
|
} from './file-des-tickets.mjs';
|
|
79
120
|
|
|
80
121
|
const VERROU_SUPERVISEUR = 'grillhouse-superviseur.lock';
|
|
122
|
+
// In the common directory of git: the note of resumption of the supervisor, its declared milestone,
|
|
123
|
+
// and the start of the last night whose request was given.
|
|
124
|
+
const NOTE_DE_REPRISE = 'grillhouse-reprise.md';
|
|
125
|
+
const JALON = 'grillhouse-jalon.json';
|
|
126
|
+
const DEMANDE_DE_NUIT = 'grillhouse-demande-de-nuit.json';
|
|
127
|
+
// The message the greffon submits once the compaction of a milestone is installed; the note, the
|
|
128
|
+
// questions and the circuits come with the opening.
|
|
129
|
+
const MESSAGE_DE_REPRISE =
|
|
130
|
+
"Reprends la supervision : ta séance vient d'être compactée au jalon que tu as déclaré. L'ouverture te donne la note de reprise, les questions et les circuits : suis-la.";
|
|
131
|
+
// How long a session without a turn stays before it is compacted: its prompt cache lasts one hour.
|
|
132
|
+
const INACTIVITE_MS = 55 * 60_000;
|
|
133
|
+
// The output of a hook of Claude Code stays under this many characters.
|
|
134
|
+
const PLAFOND_DU_CROCHET = 10_000;
|
|
81
135
|
const COQUILLES = new Set(['sh', 'bash', 'dash', 'zsh']);
|
|
82
136
|
// The name of the process of a session of the engine.
|
|
83
137
|
const MOTEUR = 'claude';
|
|
@@ -140,15 +194,10 @@ function estAuDessus(pid) {
|
|
|
140
194
|
return false;
|
|
141
195
|
}
|
|
142
196
|
|
|
143
|
-
// The time in ms of <texte>, a `defer_until` as Beads writes it: the local wall time of the
|
|
144
|
-
// machine, followed by a « Z » it does not mean (`bd update --defer 17:30` gives `…T17:30:00Z`);
|
|
145
|
-
// NaN without one.
|
|
146
|
-
const heureMurale = texte => Date.parse(String(texte ?? '').replace(/Z$/, ''));
|
|
147
|
-
|
|
148
197
|
/**
|
|
149
198
|
* Of the tickets <tickets> (as `bd show --json` gives them), the ids of those whose question does
|
|
150
199
|
* not wait for the supervisor at <maintenant> (ms): closed, or deferred to a later time
|
|
151
|
-
* (`
|
|
200
|
+
* (`reporteJusqua` of ./file-des-tickets.mjs), as a review's snooze hides a request until its
|
|
152
201
|
* hour, then shows it again.
|
|
153
202
|
* @param {{ id: string, status?: string, defer_until?: string }[]} tickets
|
|
154
203
|
* @param {number} maintenant
|
|
@@ -157,7 +206,7 @@ const heureMurale = texte => Date.parse(String(texte ?? '').replace(/Z$/, ''));
|
|
|
157
206
|
export function horsAttente(tickets, maintenant) {
|
|
158
207
|
return new Set(
|
|
159
208
|
tickets
|
|
160
|
-
.filter(t => t.status === 'closed' ||
|
|
209
|
+
.filter(t => t.status === 'closed' || reporteJusqua(t, maintenant) !== null)
|
|
161
210
|
.map(t => t.id)
|
|
162
211
|
);
|
|
163
212
|
}
|
|
@@ -194,21 +243,6 @@ const ou = c => {
|
|
|
194
243
|
// of the circuits (scripts/tableau.mjs reads it: its alerts).
|
|
195
244
|
const etatsDe = racine => path.join(racine, '.claude', 'worktrees');
|
|
196
245
|
|
|
197
|
-
// The integrations given by the waits of the repository at <racine>: `depuis`, the time (ms) of
|
|
198
|
-
// the last reading of the last wait, from which an integration is new; `rendues`, the keys of the
|
|
199
|
-
// integrations it gave, ended at that time or after. Absent or unreadable: none since <maintenant>.
|
|
200
|
-
const integrationsDe = racine => path.join(etatsDe(racine), 'integrations-rendues.json');
|
|
201
|
-
function lireLesIntegrations(racine, maintenant) {
|
|
202
|
-
try {
|
|
203
|
-
const lu = JSON.parse(readFileSync(integrationsDe(racine), 'utf8'));
|
|
204
|
-
if (Number.isFinite(lu?.depuis) && Array.isArray(lu?.rendues)) {
|
|
205
|
-
return { depuis: lu.depuis, rendues: new Set(lu.rendues.map(String)) };
|
|
206
|
-
}
|
|
207
|
-
} catch {
|
|
208
|
-
// none yet
|
|
209
|
-
}
|
|
210
|
-
return { depuis: maintenant, rendues: new Set() };
|
|
211
|
-
}
|
|
212
246
|
// The alert of the CI of main of the project at <racine> (scripts/ci-de-main.mjs), read for the
|
|
213
247
|
// supervisor: `{ cle, texte }` for a red or a CI not read, null for a green (the alert clears),
|
|
214
248
|
// undefined for a project with no CI to read. The lots entered since the last green are named by
|
|
@@ -264,19 +298,6 @@ function releverLaCiDeMain(racine, alerte, toutes) {
|
|
|
264
298
|
];
|
|
265
299
|
}
|
|
266
300
|
|
|
267
|
-
// A file that cannot be written never costs the batch: the next wait reads the former one.
|
|
268
|
-
function ecrireLesIntegrations(racine, depuis, rendues) {
|
|
269
|
-
const f = integrationsDe(racine);
|
|
270
|
-
try {
|
|
271
|
-
mkdirSync(path.dirname(f), { recursive: true });
|
|
272
|
-
const provisoire = `${f}.${process.pid}`;
|
|
273
|
-
writeFileSync(provisoire, `${JSON.stringify({ depuis, rendues: [...rendues].sort() })}\n`);
|
|
274
|
-
renameSync(provisoire, f);
|
|
275
|
-
} catch {
|
|
276
|
-
// kept as it was
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
301
|
// The file of the stops gone up as text: each stop with its key, its times, and its reading and its
|
|
281
302
|
// mark when it has them, sorted by key.
|
|
282
303
|
const enTexteDesRemontees = liste =>
|
|
@@ -357,23 +378,22 @@ export function marquerChezLeResponsable(racine, { cle, depuisA }) {
|
|
|
357
378
|
}
|
|
358
379
|
|
|
359
380
|
/**
|
|
360
|
-
* One reading of the circuits <circuits>
|
|
381
|
+
* One reading of the circuits <circuits> of the repository at <racine>,
|
|
361
382
|
* at <maintenant> ms, under the lock of the file of the stops gone up; what the greffon of the
|
|
362
383
|
* session of supervision submits, and the opening lists. Each stop that waits for the supervisor
|
|
363
|
-
* and never went up, or whose last presentation is <rappelMs> ms old or more (
|
|
364
|
-
*
|
|
384
|
+
* and never went up, or whose last presentation is <rappelMs> ms old or more, is given (a
|
|
385
|
+
* question addressed to the owner goes up once and is never given again; <toutes>: every
|
|
386
|
+
* one), its ticket <fermes> gives closed left out (bd is asked of those alone); a stop
|
|
365
387
|
* given is presented now, and one that goes up has its `depuis` set now. The file is written whole
|
|
366
388
|
* with the stops that still stand, their circuit waiting for the supervisor: a question answered
|
|
367
|
-
* so leaves it, and the next stop of its circuit is new. The
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* result is the questions given, each marked `representee` when it comes back, then the ends, then
|
|
372
|
-
* the alert of the CI of main.
|
|
389
|
+
* so leaves it, and the next stop of its circuit is new. The alert of the CI of main <ciDeMain>
|
|
390
|
+
* (`{ cle, texte }`; null at a green, which clears it; undefined when it is not read, which keeps
|
|
391
|
+
* what was given) is given once per passage. A circuit integrated gives nothing. The result is the
|
|
392
|
+
* questions given, each marked `representee` when it comes back, then the alert of the CI of main.
|
|
373
393
|
* @param {string} racine
|
|
374
394
|
* @param {import('./circuits-du-serveur.mjs').CircuitDuServeur[]} circuits
|
|
375
395
|
* @param {{ fermes: (racine: string, ids: string[]) => Set<string> | null, maintenant: number, rappelMs: number, toutes?: boolean, ciDeMain?: { cle: string, texte: string } | null }} options
|
|
376
|
-
* @returns {{ ticket: string, etape: string, question: string, qui: string, commande: string, cle: string, representee?: boolean
|
|
396
|
+
* @returns {{ ticket: string, etape: string, question: string, qui: string, commande: string, cle: string, representee?: boolean }[]}
|
|
377
397
|
*/
|
|
378
398
|
export function relever(
|
|
379
399
|
racine,
|
|
@@ -386,34 +406,21 @@ export function relever(
|
|
|
386
406
|
// Held for one reading of the circuits: older than that, abandoned.
|
|
387
407
|
prendreVerrou(verrou, { attendre: true, perime: 30_000 });
|
|
388
408
|
try {
|
|
389
|
-
const { depuis: depuisIntegrations, rendues } = lireLesIntegrations(racine, maintenant);
|
|
390
|
-
const integres = circuits
|
|
391
|
-
.filter(
|
|
392
|
-
c => c.integre && c.fin !== null && c.fin >= depuisIntegrations && !rendues.has(cleDe(c))
|
|
393
|
-
)
|
|
394
|
-
.map(enFin)
|
|
395
|
-
.sort((a, b) => a.ticket.localeCompare(b.ticket, 'en'));
|
|
396
|
-
const fins = new Map(circuits.map(c => [cleDe(c), c.fin]));
|
|
397
|
-
ecrireLesIntegrations(
|
|
398
|
-
racine,
|
|
399
|
-
maintenant,
|
|
400
|
-
[...rendues, ...integres.map(i => i.cle)].filter(
|
|
401
|
-
k => (fins.get(k) ?? -Infinity) >= maintenant
|
|
402
|
-
)
|
|
403
|
-
);
|
|
404
409
|
const rouges = ciDeMain === undefined ? [] : releverLaCiDeMain(racine, ciDeMain, toutes);
|
|
405
|
-
circuits = circuits.filter(c => !c.integre);
|
|
406
410
|
const avant = new Map(lireLesRemontees(racine, maintenant).map(r => [r.cle, r]));
|
|
407
411
|
const debout = questionsEnAttente(racine, circuits, { fermes: aucunFerme });
|
|
408
|
-
// A question comes back from its reading, never from its sending: one read,
|
|
409
|
-
// owner, whose delay has passed since its reading. One still in
|
|
410
|
-
//
|
|
412
|
+
// A question comes back from its reading, never from its sending: one read, waiting for the
|
|
413
|
+
// supervisor, not carried to the owner, whose delay has passed since its reading. One still in
|
|
414
|
+
// the queue (sent, unread), addressed to the owner or carried to him is never given again.
|
|
411
415
|
const aRendre = debout.filter(q => {
|
|
412
416
|
const r = avant.get(q.cle);
|
|
413
417
|
return (
|
|
414
418
|
toutes ||
|
|
415
419
|
!r ||
|
|
416
|
-
(
|
|
420
|
+
(q.qui !== RESPONSABLE &&
|
|
421
|
+
estLue(r) &&
|
|
422
|
+
r.chez === undefined &&
|
|
423
|
+
maintenant - r.lue >= rappelMs)
|
|
417
424
|
);
|
|
418
425
|
});
|
|
419
426
|
const fermesDe = aRendre.length
|
|
@@ -449,7 +456,7 @@ export function relever(
|
|
|
449
456
|
})
|
|
450
457
|
);
|
|
451
458
|
ecrireLesRemontees(racine, ecrit, debout.length === 0 && avant.size === 0);
|
|
452
|
-
return [...rendu, ...
|
|
459
|
+
return [...rendu, ...rouges];
|
|
453
460
|
} finally {
|
|
454
461
|
lacherVerrou(verrou);
|
|
455
462
|
}
|
|
@@ -471,17 +478,6 @@ const enQuestion = c => ({
|
|
|
471
478
|
arret: c.arret,
|
|
472
479
|
});
|
|
473
480
|
|
|
474
|
-
// The end of the circuit <c> integrated, given once by the wait: its ticket, its step, and its key.
|
|
475
|
-
const enFin = c => ({
|
|
476
|
-
ticket: c.ticket,
|
|
477
|
-
etape: '5 Intégration',
|
|
478
|
-
question: 'son lot est sur main.',
|
|
479
|
-
qui: SUPERVISEUR,
|
|
480
|
-
commande: '',
|
|
481
|
-
cle: cleDe(c),
|
|
482
|
-
integre: true,
|
|
483
|
-
});
|
|
484
|
-
|
|
485
481
|
// Of the circuits <lus> of the repository at <racine>, those whose ticket <fermes> does not give
|
|
486
482
|
// closed, sorted by ticket.
|
|
487
483
|
function enAttente(lus, racine, fermes) {
|
|
@@ -578,19 +574,13 @@ export const ligneDeQuestion = (q, o = {}) => {
|
|
|
578
574
|
/**
|
|
579
575
|
* The message the greffon submits to the session of supervision for the questions <questions> of
|
|
580
576
|
* one reading (`relever`), and the lines of the opening: for each one, its ticket, step, who must
|
|
581
|
-
* answer it, its question and the command that answers it
|
|
582
|
-
* (`
|
|
583
|
-
*
|
|
584
|
-
* @param {{ ticket: string, etape: string, question: string, qui: string, commande: string, representee?: boolean, integre?: boolean }[]} questions
|
|
577
|
+
* answer it, its question and the command that answers it. A question presented again
|
|
578
|
+
* (`representee`) says that it still waits for an answer.
|
|
579
|
+
* @param {{ ticket: string, etape: string, question: string, qui: string, commande: string, representee?: boolean }[]} questions
|
|
585
580
|
* @returns {string}
|
|
586
581
|
*/
|
|
587
582
|
export function texteDesQuestions(questions, o = {}) {
|
|
588
|
-
|
|
589
|
-
const attente = questions.filter(q => !q.integre);
|
|
590
|
-
return [
|
|
591
|
-
...attente.map(q => ligneDeQuestion(q, o)),
|
|
592
|
-
...fins.map(q => `${o.sigle ? `[${o.sigle}] ` : ''}Intégré · ${q.ticket}`),
|
|
593
|
-
].join('\n');
|
|
583
|
+
return questions.map(q => ligneDeQuestion(q, o)).join('\n');
|
|
594
584
|
}
|
|
595
585
|
|
|
596
586
|
/**
|
|
@@ -638,7 +628,6 @@ export async function circuitsALOuverture(
|
|
|
638
628
|
? `${e.message} : les circuits ne se lisent pas.`
|
|
639
629
|
: `Les circuits ne se lisent pas : ${message}.`;
|
|
640
630
|
}
|
|
641
|
-
ecrireLesIntegrations(racine, Date.now(), []);
|
|
642
631
|
const ouverteA = Date.now();
|
|
643
632
|
const questions = circuits
|
|
644
633
|
? relever(racine, circuits, {
|
|
@@ -647,7 +636,7 @@ export async function circuitsALOuverture(
|
|
|
647
636
|
rappelMs: rappelDuProjet(racine) * 60_000,
|
|
648
637
|
toutes: true,
|
|
649
638
|
ciDeMain: ciDeMainDe(racine),
|
|
650
|
-
})
|
|
639
|
+
})
|
|
651
640
|
: [];
|
|
652
641
|
// The opening lists every question that waits: the session reads them, and their reminder runs
|
|
653
642
|
// from now (a question sent to a closed session, or whose message was never recognised, included).
|
|
@@ -682,7 +671,7 @@ export async function circuitsALOuverture(
|
|
|
682
671
|
);
|
|
683
672
|
return [
|
|
684
673
|
'## Les questions des circuits',
|
|
685
|
-
"Le greffon de ta séance pousse dans la file de tes messages chaque question neuve d'un circuit du dépôt, quel que soit son lanceur
|
|
674
|
+
"Le greffon de ta séance pousse dans la file de tes messages chaque question neuve d'un circuit du dépôt, quel que soit son lanceur ; il n'y a aucune attente à lancer. Une question sans réponse au superviseur revient une fois lue, à intervalle réglable depuis sa lecture (`grillhouse.rappel`, 10 min par défaut) : ta réponse au circuit l'acquitte, et répondue elle ne revient plus ; une question que tu as portée au responsable se tait par `npx grillhouse circuit <ticket> --chez-le-responsable`, jusqu'à la réponse du circuit ; une question adressée au responsable part une fois, pour que tu la lui portes, et ne revient pas. Tu ne te mets pas en attente du responsable tant qu'une question d'un circuit attend ta réponse. Les questions en attente sont listées ci-dessous.",
|
|
686
675
|
...(panne ? ['', '## Les circuits du dépôt', panne] : []),
|
|
687
676
|
...(nommes.length ? ['', '## Les circuits du dépôt', ...nommes.map(n => n.ligne)] : []),
|
|
688
677
|
...(questions.length ? ['', `Les réponses à une question : ${REPONSES}`] : []),
|
|
@@ -705,41 +694,256 @@ const git = (racine, ...args) =>
|
|
|
705
694
|
encoding: 'utf8',
|
|
706
695
|
});
|
|
707
696
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
* @param {{ env?: Record<string, string | undefined> }} options
|
|
713
|
-
* @returns {Promise<string>}
|
|
714
|
-
*/
|
|
715
|
-
async function superviseur(racine, { env = process.env } = {}) {
|
|
697
|
+
// Where the session of supervision of the directory <dossier> stands: the common directory of git
|
|
698
|
+
// and the lock; `refus` says why <dossier> or the session has none (a role's session, out of git, a
|
|
699
|
+
// copy).
|
|
700
|
+
function depotDuSuperviseur(dossier, env) {
|
|
716
701
|
if (env.BEADS_ACTOR) {
|
|
717
|
-
return '
|
|
702
|
+
return { refus: "la séance d'un rôle ne supervise pas" };
|
|
718
703
|
}
|
|
719
|
-
const r = git(
|
|
704
|
+
const r = git(dossier, '--git-dir', '--git-common-dir');
|
|
720
705
|
if (r.status !== 0) {
|
|
721
|
-
return '
|
|
706
|
+
return { refus: `${dossier} n'est pas dans un dépôt git` };
|
|
722
707
|
}
|
|
723
708
|
const [dossierGit, commun] = r.stdout.trim().split('\n');
|
|
724
709
|
if (path.resolve(dossierGit) !== path.resolve(commun)) {
|
|
710
|
+
return { refus: 'une copie de ticket ne supervise pas : joue la commande à la racine du dépôt' };
|
|
711
|
+
}
|
|
712
|
+
return { commun, verrou: path.join(commun, VERROU_SUPERVISEUR) };
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// The process the lock <verrou> names; null when no lock reads.
|
|
716
|
+
function tenantDe(verrou) {
|
|
717
|
+
try {
|
|
718
|
+
const pid = Number(/^(\d+)/.exec(readFileSync(verrou, 'utf8'))?.[1]);
|
|
719
|
+
return Number.isInteger(pid) ? pid : null;
|
|
720
|
+
} catch {
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// `depotDuSuperviseur` for the session that holds the lock alone, its process in `tenant`.
|
|
726
|
+
function laSeanceQuiTient(dossier, env) {
|
|
727
|
+
const depot = depotDuSuperviseur(dossier, env);
|
|
728
|
+
if (depot.refus) {
|
|
729
|
+
return depot;
|
|
730
|
+
}
|
|
731
|
+
const tenant = tenantDe(depot.verrou);
|
|
732
|
+
return tenant !== null && estAuDessus(tenant)
|
|
733
|
+
? { ...depot, tenant }
|
|
734
|
+
: { refus: 'cette séance ne tient pas le verrou du superviseur' };
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// Writes <texte> whole into <f>, by a rename.
|
|
738
|
+
function ecrireEntier(f, texte) {
|
|
739
|
+
const provisoire = `${f}.${process.pid}`;
|
|
740
|
+
writeFileSync(provisoire, texte);
|
|
741
|
+
renameSync(provisoire, f);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function lireJson(f) {
|
|
745
|
+
try {
|
|
746
|
+
return JSON.parse(readFileSync(f, 'utf8'));
|
|
747
|
+
} catch {
|
|
748
|
+
return null;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
function lireTexte(f) {
|
|
753
|
+
try {
|
|
754
|
+
return readFileSync(f, 'utf8');
|
|
755
|
+
} catch {
|
|
725
756
|
return '';
|
|
726
757
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// The gesture of the holder of the lock on the note: <ecrire> is given its session and the text of
|
|
761
|
+
// <fichier>. Code 2 and the reason, nothing written, when the session or the file is refused.
|
|
762
|
+
function surLaNote(dossier, fichier, env, ecrire) {
|
|
763
|
+
const session = laSeanceQuiTient(dossier, env);
|
|
764
|
+
if (session.refus) {
|
|
765
|
+
return { code: 2, raison: session.refus };
|
|
766
|
+
}
|
|
767
|
+
let texte;
|
|
768
|
+
try {
|
|
769
|
+
texte = readFileSync(fichier, 'utf8');
|
|
770
|
+
} catch {
|
|
771
|
+
return { code: 2, raison: `le fichier ${fichier} ne se lit pas` };
|
|
772
|
+
}
|
|
773
|
+
if (!texte.trim()) {
|
|
774
|
+
return { code: 2, raison: `le fichier ${fichier} est vide` };
|
|
775
|
+
}
|
|
776
|
+
ecrire(session, texte);
|
|
777
|
+
return { code: 0, raison: '' };
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* The session that holds the lock of the supervisor of <dossier> declares a milestone: the text of
|
|
782
|
+
* <fichier> replaces its note of resumption whole, and the milestone, which holds for the context
|
|
783
|
+
* that declares it, replaces the one before (`superviseur --jalon`).
|
|
784
|
+
* @param {string} dossier
|
|
785
|
+
* @param {string} fichier
|
|
786
|
+
* @param {{ env?: Record<string, string | undefined> }} [options]
|
|
787
|
+
* @returns {Promise<{ code: number, raison: string }>} code 2 and its reason, nothing written, on a
|
|
788
|
+
* refusal
|
|
789
|
+
*/
|
|
790
|
+
export async function declarerLeJalon(dossier, fichier, { env = process.env } = {}) {
|
|
791
|
+
return surLaNote(dossier, fichier, env, ({ commun, tenant }, texte) => {
|
|
792
|
+
ecrireEntier(path.join(commun, NOTE_DE_REPRISE), texte);
|
|
793
|
+
ecrireEntier(path.join(commun, JALON), `${JSON.stringify({ declareA: Date.now(), tenant })}\n`);
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* The session that holds the lock adds the text of <fichier> at the end of its note of resumption,
|
|
799
|
+
* which it creates when there is none; no milestone is declared (`superviseur --question`).
|
|
800
|
+
* @param {string} dossier
|
|
801
|
+
* @param {string} fichier
|
|
802
|
+
* @param {{ env?: Record<string, string | undefined> }} [options]
|
|
803
|
+
* @returns {Promise<{ code: number, raison: string }>} code 2 and its reason, nothing written, on a
|
|
804
|
+
* refusal
|
|
805
|
+
*/
|
|
806
|
+
export async function ajouterLaQuestion(dossier, fichier, { env = process.env } = {}) {
|
|
807
|
+
return surLaNote(dossier, fichier, env, ({ commun }, texte) => {
|
|
808
|
+
const note = path.join(commun, NOTE_DE_REPRISE);
|
|
809
|
+
const avant = lireTexte(note);
|
|
810
|
+
const joint = avant ? `${avant.replace(/\n*$/, '')}\n\n` : '';
|
|
811
|
+
ecrireEntier(note, `${joint}${texte}`);
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Whether the session of supervision of <dossier> is to be compacted (`superviseur --renouveler`),
|
|
817
|
+
* the session holding the lock: at a milestone it declared, once a quiet Stop (<arretA>, ms, 0
|
|
818
|
+
* without one) is later than it, with the message of resumption; else once that Stop is 55 minutes
|
|
819
|
+
* old, with an empty message, a note or a milestone or not. A message of the owner (<messageA>, ms,
|
|
820
|
+
* 0 without one) later than the declaration cancels the milestone. The reading keeps a milestone
|
|
821
|
+
* that is due: the opening that follows the compaction removes it.
|
|
822
|
+
* @param {string} dossier
|
|
823
|
+
* @param {{ arretA: number, messageA: number, env?: Record<string, string | undefined> }} options
|
|
824
|
+
* @returns {Promise<{ reprise: string } | null>} null when nothing is to be done
|
|
825
|
+
*/
|
|
826
|
+
export async function renouvellement(dossier, { arretA, messageA, env = process.env }) {
|
|
827
|
+
const session = laSeanceQuiTient(dossier, env);
|
|
828
|
+
if (session.refus) {
|
|
829
|
+
return null;
|
|
830
|
+
}
|
|
831
|
+
const f = path.join(session.commun, JALON);
|
|
832
|
+
const jalon = lireJson(f);
|
|
833
|
+
if (jalon && jalon.tenant === session.tenant) {
|
|
834
|
+
if (messageA > jalon.declareA) {
|
|
835
|
+
rmSync(f, { force: true });
|
|
836
|
+
} else if (arretA > jalon.declareA) {
|
|
837
|
+
return { reprise: MESSAGE_DE_REPRISE };
|
|
734
838
|
}
|
|
735
|
-
}
|
|
736
|
-
|
|
839
|
+
}
|
|
840
|
+
return arretA > 0 && Date.now() - arretA >= INACTIVITE_MS ? { reprise: '' } : null;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* The instructions of the summary of a compaction of the session of supervision of <dossier>
|
|
845
|
+
* (`grillhouse pre-compact`): the file of the note of resumption, the request to keep what it says
|
|
846
|
+
* and what the conversation holds of more recent, then its text, cut so that the whole stays under
|
|
847
|
+
* the cap of a hook's output. Empty without a note, for a session that does not hold the lock, a
|
|
848
|
+
* session of a role or a copy.
|
|
849
|
+
* @param {string} dossier
|
|
850
|
+
* @param {{ env?: Record<string, string | undefined> }} [options]
|
|
851
|
+
* @returns {string}
|
|
852
|
+
*/
|
|
853
|
+
export function consignesDuResume(dossier, { env = process.env } = {}) {
|
|
854
|
+
const session = laSeanceQuiTient(dossier, env);
|
|
855
|
+
if (session.refus) {
|
|
856
|
+
return '';
|
|
857
|
+
}
|
|
858
|
+
const note = path.join(session.commun, NOTE_DE_REPRISE);
|
|
859
|
+
const texte = lireTexte(note).trimEnd();
|
|
860
|
+
if (!texte) {
|
|
861
|
+
return '';
|
|
862
|
+
}
|
|
863
|
+
const tete = [
|
|
864
|
+
`La note de reprise de la supervision est au fichier \`${note}\`.`,
|
|
865
|
+
"Garde dans le résumé ce qu'elle dit et ce que la conversation porte de plus récent qu'elle. Son texte :",
|
|
866
|
+
'',
|
|
867
|
+
'',
|
|
868
|
+
].join('\n');
|
|
869
|
+
const coupe = '\n[Note coupée : lis son fichier en entier.]';
|
|
870
|
+
// One character is left to the newline the command ends with.
|
|
871
|
+
const place = PLAFOND_DU_CROCHET - 2 - tete.length;
|
|
872
|
+
return texte.length <= place
|
|
873
|
+
? `${tete}${texte}`
|
|
874
|
+
: `${tete}${texte.slice(0, Math.max(0, place - coupe.length))}${coupe}`;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// The section the opening gives of the note of resumption <note>; empty when none is written.
|
|
878
|
+
function laNote(note) {
|
|
879
|
+
const texte = lireTexte(note).trimEnd();
|
|
880
|
+
return texte
|
|
881
|
+
? [
|
|
882
|
+
'## La note de reprise',
|
|
883
|
+
`Elle est au fichier \`${note}\` : lis-le en entier si ce texte est coupé.`,
|
|
884
|
+
'',
|
|
885
|
+
texte,
|
|
886
|
+
].join('\n')
|
|
887
|
+
: '';
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// What the opening that follows a /clear or a compaction asks, before the circuits and the note, by
|
|
891
|
+
// the source of the SessionStart hook.
|
|
892
|
+
const REPRISES = {
|
|
893
|
+
clear: [
|
|
894
|
+
'## Reprise de la supervision après un /clear',
|
|
895
|
+
'Charge la compétence `grillhouse:pitmaster`, puis reprends la note de reprise donnée plus bas ; ne fais aucun tour complet.',
|
|
896
|
+
'À ton premier tour, quel que soit le message qui l’ouvre, repose au responsable la question que la note tient en attente.',
|
|
897
|
+
].join('\n'),
|
|
898
|
+
compact: [
|
|
899
|
+
'## Reprise de la supervision après un compactage',
|
|
900
|
+
'Charge la compétence `grillhouse:pitmaster`, puis reprends la note de reprise donnée plus bas ; ne fais aucun tour complet, et finis le travail en cours.',
|
|
901
|
+
'Tiens le résumé du compactage pour plus récent que la note sur ce qui lui est postérieur.',
|
|
902
|
+
'Repose au responsable la question que la note tient en attente, si elle attend encore.',
|
|
903
|
+
].join('\n'),
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* The check of the supervisor at the opening of a session in <dossier> (greffon.md, §5.2): what it
|
|
908
|
+
* says (empty when nothing), the lock taken when it is free. <source> is the one of the
|
|
909
|
+
* SessionStart hook. The session that takes the lock, and the holder after a /clear or a
|
|
910
|
+
* compaction, receive the circuits and the note of resumption; every opening of the holder removes
|
|
911
|
+
* the declared milestone.
|
|
912
|
+
* @param {string} dossier the directory the session opens in
|
|
913
|
+
* @param {{ source?: string, env?: Record<string, string | undefined>, circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} [options]
|
|
914
|
+
* @returns {Promise<string>}
|
|
915
|
+
*/
|
|
916
|
+
export async function ouvertureDuSuperviseur(
|
|
917
|
+
dossier,
|
|
918
|
+
{ source = 'startup', env = process.env, circuitsDe = circuitsDuServeur } = {}
|
|
919
|
+
) {
|
|
920
|
+
const depot = depotDuSuperviseur(dossier, env);
|
|
921
|
+
if (depot.refus) {
|
|
737
922
|
return '';
|
|
738
923
|
}
|
|
739
|
-
|
|
740
|
-
|
|
924
|
+
const { commun, verrou } = depot;
|
|
925
|
+
const moi = seance();
|
|
926
|
+
const tenait = tenantDe(verrou) === moi;
|
|
927
|
+
if (!tenait && !prendreVerrou(verrou, { attendre: false, pid: moi })) {
|
|
928
|
+
return unAutreSuperviseur(verrou, moi);
|
|
929
|
+
}
|
|
930
|
+
rmSync(path.join(commun, JALON), { force: true });
|
|
931
|
+
const reprise = Object.hasOwn(REPRISES, source) ? REPRISES[source] : '';
|
|
932
|
+
if (tenait && !reprise) {
|
|
933
|
+
return '';
|
|
741
934
|
}
|
|
742
|
-
|
|
935
|
+
return [
|
|
936
|
+
reprise,
|
|
937
|
+
await circuitsALOuverture(path.dirname(commun), { circuitsDe }),
|
|
938
|
+
laNote(path.join(commun, NOTE_DE_REPRISE)),
|
|
939
|
+
]
|
|
940
|
+
.filter(Boolean)
|
|
941
|
+
.join('\n\n');
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// The section a session receives when another live one holds the lock <verrou>; empty when none does.
|
|
945
|
+
function unAutreSuperviseur(verrou, moi) {
|
|
946
|
+
const autre = tenantDe(verrou);
|
|
743
947
|
if (!autre || autre === moi || !vivant(autre)) {
|
|
744
948
|
return '';
|
|
745
949
|
}
|
|
@@ -755,10 +959,36 @@ async function superviseur(racine, { env = process.env } = {}) {
|
|
|
755
959
|
].join('\n');
|
|
756
960
|
}
|
|
757
961
|
|
|
962
|
+
// Whether a question of the circuits <circuits> of the repository at <racine> waits for the
|
|
963
|
+
// supervisor, read or not: neither addressed to the owner, nor carried to him, nor deferred to a
|
|
964
|
+
// later time, its ticket open. null when the tickets do not read.
|
|
965
|
+
function uneQuestionAttend(racine, circuits) {
|
|
966
|
+
const chez = new Set(
|
|
967
|
+
lireLesRemontees(racine, Date.now())
|
|
968
|
+
.filter(r => r.chez !== undefined)
|
|
969
|
+
.map(r => r.cle)
|
|
970
|
+
);
|
|
971
|
+
const debout = circuits.filter(
|
|
972
|
+
c => attendLeSuperviseur(c) && c.qui !== RESPONSABLE && !chez.has(cleDe(c))
|
|
973
|
+
);
|
|
974
|
+
if (!debout.length) {
|
|
975
|
+
return false;
|
|
976
|
+
}
|
|
977
|
+
const hors = ticketsHorsAttente(
|
|
978
|
+
racine,
|
|
979
|
+
debout.map(c => c.ticket)
|
|
980
|
+
);
|
|
981
|
+
return hors === null ? null : debout.some(c => !hors.has(c.ticket));
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// The request the reading submits to the session, for the reason <raison>.
|
|
985
|
+
const demandeDuJalon = raison =>
|
|
986
|
+
`Jalon · ${raison} : écris ta note de reprise et déclare le jalon (compétence \`grillhouse:pitmaster\`), par \`npx grillhouse superviseur --jalon <fichier>\`.`;
|
|
987
|
+
|
|
758
988
|
/**
|
|
759
989
|
* One reading for the greffon of the session of supervision of the repository at <racine>
|
|
760
990
|
* (`npx grillhouse superviseur --relever`): the message of what `relever` gives (the questions of
|
|
761
|
-
* the circuits due, the
|
|
991
|
+
* the circuits due, the reds of main), empty when it gives nothing, when the
|
|
762
992
|
* circuits do not read, or when the session that runs it is not the one that holds the lock of the
|
|
763
993
|
* supervisor (a role's session, an agent's copy, another project's, a session that took no lock).
|
|
764
994
|
* The interval of the re-presentation is the key `grillhouse.rappel` of the project, applied at
|
|
@@ -767,9 +997,11 @@ async function superviseur(racine, { env = process.env } = {}) {
|
|
|
767
997
|
* the name and the folder of that project, where its answers are played, with that project's own
|
|
768
998
|
* interval and state. A fault in the reading of one of these projects costs the others nothing: it
|
|
769
999
|
* is thrown once all are read, each project at fault named with its reason, the message of the
|
|
770
|
-
* others in the `texte` of the error.
|
|
1000
|
+
* others in the `texte` of the error. Last comes the request to write the note of resumption and
|
|
1001
|
+
* declare a milestone, once for each night of the project (`grillhouse.plageDeNuit`), at a reading
|
|
1002
|
+
* where every project read says that no question waits for the supervisor.
|
|
771
1003
|
* @param {string} racine
|
|
772
|
-
* @param {{ env?: Record<string, string | undefined>, circuitsDe?: (racine: string
|
|
1004
|
+
* @param {{ env?: Record<string, string | undefined>, circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} [options]
|
|
773
1005
|
* @returns {Promise<string>}
|
|
774
1006
|
* @throws {Error} `grillhouse.rappel` of the project of the session is at fault, named with its
|
|
775
1007
|
* value; or the reading of another project of the group failed (its `texte`: the others' message)
|
|
@@ -778,42 +1010,41 @@ export async function releverPourLeGreffon(
|
|
|
778
1010
|
racine,
|
|
779
1011
|
{ env = process.env, circuitsDe = circuitsDuServeur } = {}
|
|
780
1012
|
) {
|
|
781
|
-
|
|
1013
|
+
const depot = depotDuSuperviseur(racine, env);
|
|
1014
|
+
if (depot.refus) {
|
|
782
1015
|
return '';
|
|
783
1016
|
}
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
}
|
|
788
|
-
const [dossierGit, commun] = r.stdout.trim().split('\n');
|
|
789
|
-
if (path.resolve(dossierGit) !== path.resolve(commun)) {
|
|
790
|
-
return '';
|
|
791
|
-
}
|
|
792
|
-
const verrou = path.join(commun, VERROU_SUPERVISEUR);
|
|
793
|
-
let tenant = null;
|
|
794
|
-
try {
|
|
795
|
-
tenant = Number(/^(\d+)/.exec(readFileSync(verrou, 'utf8'))?.[1]);
|
|
796
|
-
} catch {
|
|
1017
|
+
const { commun, verrou } = depot;
|
|
1018
|
+
let tenant = tenantDe(verrou);
|
|
1019
|
+
if (tenant === null) {
|
|
797
1020
|
return '';
|
|
798
1021
|
}
|
|
799
1022
|
// A lock whose process is gone is taken over, as the opening does: the session that reads holds it.
|
|
800
|
-
if (
|
|
1023
|
+
if (!estAuDessus(tenant) && !vivant(tenant)) {
|
|
801
1024
|
const moi = seance();
|
|
802
1025
|
tenant = prendreVerrou(verrou, { attendre: false, pid: moi }) ? moi : null;
|
|
803
1026
|
}
|
|
804
|
-
if (
|
|
1027
|
+
if (tenant === null || !estAuDessus(tenant)) {
|
|
805
1028
|
return '';
|
|
806
1029
|
}
|
|
807
|
-
const
|
|
1030
|
+
const demandeNocturne = path.join(commun, DEMANDE_DE_NUIT);
|
|
1031
|
+
const nuit = nuitEnCours(Date.now(), plageDeNuit(racine));
|
|
1032
|
+
const aDemander = nuit !== null && lireJson(demandeNocturne)?.nuit !== nuit;
|
|
1033
|
+
const parts = [await leReleveDe(racine, circuitsDe, { nocturne: aDemander })];
|
|
808
1034
|
const fautes = [];
|
|
809
1035
|
for (const p of voisinsSansSuperviseur(racine)) {
|
|
810
1036
|
try {
|
|
811
|
-
parts.push(await leReleveDe(p.chemin, circuitsDe, true));
|
|
1037
|
+
parts.push(await leReleveDe(p.chemin, circuitsDe, { voisin: true, nocturne: aDemander }));
|
|
812
1038
|
} catch (e) {
|
|
813
1039
|
fautes.push(`${path.basename(p.chemin)} : ${e.message}`);
|
|
814
1040
|
}
|
|
815
1041
|
}
|
|
816
|
-
|
|
1042
|
+
let demande = '';
|
|
1043
|
+
if (aDemander && !fautes.length && parts.every(p => p.attend === false)) {
|
|
1044
|
+
ecrireEntier(demandeNocturne, `${JSON.stringify({ nuit })}\n`);
|
|
1045
|
+
demande = demandeDuJalon('la nuit a commencé');
|
|
1046
|
+
}
|
|
1047
|
+
const texte = [...parts.map(p => p.texte), demande].filter(Boolean).join('\n\n');
|
|
817
1048
|
if (fautes.length) {
|
|
818
1049
|
throw Object.assign(new Error(fautes.join('\n')), { texte });
|
|
819
1050
|
}
|
|
@@ -829,20 +1060,22 @@ function paquetDe(racine) {
|
|
|
829
1060
|
}
|
|
830
1061
|
}
|
|
831
1062
|
|
|
832
|
-
//
|
|
833
|
-
//
|
|
834
|
-
//
|
|
835
|
-
//
|
|
836
|
-
|
|
1063
|
+
// One reading of the project at <racine>, under its own interval (`grillhouse.rappel`) and its own
|
|
1064
|
+
// state of the questions presented: `texte`, its message, empty when it gives nothing or when its
|
|
1065
|
+
// circuits do not read; `attend`, read for the request of the night (<o.nocturne>), whether a
|
|
1066
|
+
// question waits for the supervisor (`uneQuestionAttend`), null when unknown. A faulty interval
|
|
1067
|
+
// throws, the project of the session named (a neighbour is named by the caller, as for any fault of
|
|
1068
|
+
// its reading).
|
|
1069
|
+
async function leReleveDe(racine, circuitsDe, { voisin = false, nocturne = false } = {}) {
|
|
837
1070
|
const { minutes, faute } = reglageDuRappel(paquetDe(racine));
|
|
838
1071
|
if (faute) {
|
|
839
1072
|
throw new Error(voisin ? faute : `${path.basename(racine)} : ${faute}`);
|
|
840
1073
|
}
|
|
841
1074
|
let circuits;
|
|
842
1075
|
try {
|
|
843
|
-
circuits = await circuitsDe(racine
|
|
1076
|
+
circuits = await circuitsDe(racine);
|
|
844
1077
|
} catch {
|
|
845
|
-
return '';
|
|
1078
|
+
return { texte: '', attend: null };
|
|
846
1079
|
}
|
|
847
1080
|
const lot = relever(racine, circuits, {
|
|
848
1081
|
fermes: ticketsHorsAttente,
|
|
@@ -854,7 +1087,10 @@ async function leReleveDe(racine, circuitsDe, voisin = false) {
|
|
|
854
1087
|
const projet = voisin
|
|
855
1088
|
? { sigle: sigleDuProjet(racine).sigle ?? path.basename(racine), dossier: racine }
|
|
856
1089
|
: {};
|
|
857
|
-
return
|
|
1090
|
+
return {
|
|
1091
|
+
texte: lot.length ? texteDesQuestions(lot, projet) : '',
|
|
1092
|
+
attend: nocturne ? uneQuestionAttend(racine, circuits) : null,
|
|
1093
|
+
};
|
|
858
1094
|
}
|
|
859
1095
|
|
|
860
1096
|
// The other projects of the group of the project at <racine> (`grillhouse.groupe`) that no other
|
|
@@ -889,7 +1125,27 @@ function racineDe(dossier) {
|
|
|
889
1125
|
}
|
|
890
1126
|
|
|
891
1127
|
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
892
|
-
if (process.argv[2] === '--
|
|
1128
|
+
if (process.argv[2] === '--jalon' || process.argv[2] === '--question') {
|
|
1129
|
+
// superviseur --jalon|--question <fichier> : played from the root of the repository.
|
|
1130
|
+
const geste = process.argv[2] === '--jalon' ? declarerLeJalon : ajouterLaQuestion;
|
|
1131
|
+
const { code, raison } = process.argv[3]
|
|
1132
|
+
? await geste(process.cwd(), process.argv[3])
|
|
1133
|
+
: { code: 2, raison: 'le fichier manque' };
|
|
1134
|
+
if (raison) {
|
|
1135
|
+
process.stderr.write(`${process.argv[2]} : ${raison}.\n`);
|
|
1136
|
+
}
|
|
1137
|
+
process.exitCode = code;
|
|
1138
|
+
} else if (process.argv[2] === '--renouveler') {
|
|
1139
|
+
// superviseur --renouveler <dossier> <arretA> <messageA> (the greffon, at each period).
|
|
1140
|
+
const [, , , dossier, arretA, messageA] = process.argv;
|
|
1141
|
+
const rendu = await renouvellement(dossier ?? process.cwd(), {
|
|
1142
|
+
arretA: Number(arretA),
|
|
1143
|
+
messageA: Number(messageA),
|
|
1144
|
+
});
|
|
1145
|
+
if (rendu) {
|
|
1146
|
+
process.stdout.write(`${JSON.stringify(rendu)}\n`);
|
|
1147
|
+
}
|
|
1148
|
+
} else if (process.argv[2] === '--relever') {
|
|
893
1149
|
try {
|
|
894
1150
|
const texte = await releverPourLeGreffon(racineDe(process.argv[3] ?? process.cwd()));
|
|
895
1151
|
if (texte) {
|
|
@@ -936,7 +1192,9 @@ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
|
936
1192
|
}
|
|
937
1193
|
}
|
|
938
1194
|
} else {
|
|
939
|
-
const texte = await
|
|
1195
|
+
const texte = await ouvertureDuSuperviseur(process.argv[2] ?? process.cwd(), {
|
|
1196
|
+
source: process.argv[3] || undefined,
|
|
1197
|
+
});
|
|
940
1198
|
if (texte) {
|
|
941
1199
|
process.stdout.write(`${texte}\n`);
|
|
942
1200
|
}
|