@roomi-fields/grillhouse 0.53.0 → 0.54.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +54 -0
  3. package/cadre/templates/projet/docs/agents/issue-tracker.md +2 -2
  4. package/charte.md +12 -0
  5. package/dist/temporal/circuit/deroule.js +5 -9
  6. package/dist/temporal/circuit/deroule.js.map +1 -1
  7. package/dist/temporal/installation.d.ts +15 -2
  8. package/dist/temporal/installation.js +69 -17
  9. package/dist/temporal/installation.js.map +1 -1
  10. package/docs/INTERFACE.md +21 -1
  11. package/docs/architecture/circuit.md +3 -3
  12. package/docs/architecture/entree.md +4 -4
  13. package/docs/architecture/greffon.md +28 -17
  14. package/docs/architecture/installation.md +21 -11
  15. package/docs/architecture/machine.md +1 -1
  16. package/docs/architecture/tests.md +1 -1
  17. package/hooks/register.tsx +50 -24
  18. package/package.json +1 -1
  19. package/scripts/aiguillage.mjs +4 -2
  20. package/scripts/bd-garde.mjs +69 -0
  21. package/scripts/ci-de-main.mjs +259 -56
  22. package/scripts/circuit.mjs +20 -5
  23. package/scripts/commandes-composees.mjs +1 -1
  24. package/scripts/droits.mjs +11 -4
  25. package/scripts/file-des-tickets.mjs +27 -9
  26. package/scripts/greffons.mjs +282 -17
  27. package/scripts/langages/c/commandes.mjs +1 -1
  28. package/scripts/langages/cargo/commandes.mjs +1 -1
  29. package/scripts/langages/cargo/tailles-des-tests.mjs +115 -6
  30. package/scripts/langages/python/commandes.mjs +1 -1
  31. package/scripts/langages/typescript/code-mort.mjs +36 -3
  32. package/scripts/langages/typescript/migrations/configurations-en-commonjs.mjs +95 -24
  33. package/scripts/langages/typescript/mise-a-jour.mjs +49 -12
  34. package/scripts/langages/typescript/parcours.mjs +5 -1
  35. package/scripts/langages.d.mts +6 -0
  36. package/scripts/langages.mjs +6 -0
  37. package/scripts/lire.mjs +236 -0
  38. package/scripts/migrations/cout-des-jetons-au-registre.mjs +136 -0
  39. package/scripts/migrations/lire-un-ticket.mjs +46 -0
  40. package/scripts/migrations.mjs +4 -0
  41. package/scripts/montee.mjs +123 -47
  42. package/scripts/nuit.sh +21 -12
  43. package/scripts/registre.d.mts +7 -1
  44. package/scripts/registre.mjs +114 -102
  45. package/scripts/resultats.mjs +15 -5
  46. package/scripts/retirer-copie.sh +7 -0
  47. package/scripts/sous-commandes.mjs +1 -0
  48. package/scripts/suiveur.mjs +12 -4
  49. package/scripts/superviseur.mjs +111 -31
  50. package/scripts/tableau.mjs +527 -119
  51. package/scripts/tarifs.mjs +67 -0
  52. package/scripts/ticket-du-circuit.mjs +3 -4
  53. package/scripts/transitions.d.mts +0 -5
  54. package/scripts/transitions.mjs +3 -13
  55. package/scripts/verdict-de-la-nuit.mjs +2 -2
  56. package/skills/explorateur/SKILL.md +10 -5
  57. package/skills/mesure/SKILL.md +4 -3
  58. package/skills/pitmaster/SKILL.md +18 -4
  59. package/skills/pitmaster/references/erreurs.md +4 -2
  60. package/skills/pitmaster/references/tour.md +11 -4
  61. package/types/index.d.ts +3 -1
  62. package/scripts/base-des-workflows.mjs +0 -58
@@ -16,7 +16,16 @@
16
16
  // questions that wait for the owner), one « ❓ » line per such question, « file » (the queues),
17
17
  // « en cours » (in progress, done, deferred; a circuit launched and not integrated is in
18
18
  // progress, not done); these lines once per project on a board of several. Then the day's
19
- // discoveries, and the day's and cumulative time and tokens.
19
+ // discoveries, and the day's line and the cumul's, each its time, its tokens and its cost.
20
+ // - Spending: the tokens of the day and of the cumul add every billed kind (input, output, cache
21
+ // written and read), and their cost is the register's `cout`. Each agent counts once, by its
22
+ // latest line, or by its transcript when that holds a spending the register lacks (no line, an
23
+ // agent running again, a response after its latest line); the day takes the responses dated
24
+ // since its marker, an agent without a transcript whole the day of its end. A sum that lacks the
25
+ // cost of an agent that spent tokens says its known cost, « ≥ 12 $ ». A response present in
26
+ // several transcripts of the project, named by its message's id and its request's id, counts once
27
+ // (`retenuesAilleurs`). A transcript silent for 30 minutes keeps in the cache its spending and
28
+ // the responses it shares alone (`lireLesDepenses`).
20
29
  // - AGENTS: the tree of the steps (scripts/etapes.mjs), one block per step and sub-step. A ticket
21
30
  // stands at a step only by its circuit or by an agent that runs on it; a ticket in the queue,
22
31
  // its circuit not launched, stands at no step. A circuit (scripts/circuit.mjs) launched and not
@@ -46,7 +55,7 @@
46
55
  // sub-agent or a session whose transcript moved in the last 2 minutes. With an end in the
47
56
  // register, an agent runs again only when an incoming message follows its latest end strictly.
48
57
  // A sub-agent also runs while its last tool call awaits its answer, its transcript having
49
- // moved in the last 30 minutes; the board reads no transcript older than 30 minutes.
58
+ // moved in the last 30 minutes; the running view reads no transcript older than 30 minutes.
50
59
  // - Time: a transcript's working time is the union of its turns (`horsDuTour` leaves out what a
51
60
  // resumption writes before its incoming message), read where the board stopped, its reading in
52
61
  // the cache file. A ticket's time adds the steps its circuit leads itself (the register's lines
@@ -64,16 +73,18 @@
64
73
  // cœurs · 26 réservés sur 28 · 4 Go réservés, limite 8 Go · <durée> » for a wait. The block at
65
74
  // the head of AGENTS (`lignesDesParts`) keeps the budget taken, « Parts · 2 passes · 6 sur 8
66
75
  // cœurs · 11 sur 16 Go », which counts
67
- // every pass that holds a part, a ticket the board does not show included, then the passes with
68
- // no ticket (« 🔒 <sorte> · <projet> · 4 cœurs · 8 Go »), then each wait in the order of its
69
- // rank (« ⏳ <sorte> · <projet> · attend <raison> »). Such a line is marked `avancement`, which
70
- // the pane measures again more often.
76
+ // every pass of the machine that holds a part, a ticket the board does not show and another
77
+ // project's pass included, then the passes with no ticket of the board's project (the
78
+ // session's, `ici`; « 🔒 <sorte> · <projet> · 4 cœurs · 8 Go »), then their waits in the order of
79
+ // their rank (« ⏳ <sorte> · <projet> · attend <raison> »). Such a line is marked `avancement`,
80
+ // which the pane measures again more often.
71
81
  // - Signs: a ticket's line in AGENTS takes one of three, by the tone of its state: ▶ its step
72
82
  // works (cyan; ▷ in a short circuit, ✎ in a direct one, by its view, `circuit`); ⏸ it waits,
73
83
  // the reason on its right (« attend une place », « verrou », « disque », « démarre » in grey,
74
84
  // waiting for the machine; « question au superviseur », « question au responsable », « arrêté »
75
85
  // in yellow, waiting for someone); ⛔ it stopped on a fault or its pass is frozen (red). At
76
- // the head of AGENTS, 🔒 and ⏳ for a pass with no ticket, 🌙 the night under way. Alerts:
86
+ // the head of AGENTS, 🔒 and ⏳ for a pass with no ticket of the board's project, 🌙 the night
87
+ // under way. Alerts:
77
88
  // 💤 a ticket claimed with nothing running, 🌙 a red night, ⚠ the others.
78
89
  // A sign is followed by a space; the width of a line counts its columns (`colonnes`), ⏳ and ⛔
79
90
  // two.
@@ -90,6 +101,7 @@ import {
90
101
  openSync,
91
102
  readdirSync,
92
103
  readFileSync,
104
+ realpathSync,
93
105
  readSync,
94
106
  renameSync,
95
107
  statSync,
@@ -112,9 +124,11 @@ import {
112
124
  SUPERVISEUR,
113
125
  } from './etapes.mjs';
114
126
  import { echecDeLOutil } from './aiguillage.mjs';
127
+ import { bdAAppeler, garderBd } from './bd-garde.mjs';
115
128
  import { maxDuProjet } from './circuits-cles.mjs';
116
129
  import { bilansGardes, enBref } from './bilans-gardes.mjs';
117
130
  import { REGISTRE } from './adresse-du-registre.mjs';
131
+ import { cleDuTarif, coutDe } from './tarifs.mjs';
118
132
  import { lireLaMesure } from './avancement.mjs';
119
133
  import {
120
134
  alerteDeDeclenchement,
@@ -292,14 +306,17 @@ const etatNeuf = () => ({
292
306
  entre: null,
293
307
  ticket: null,
294
308
  role: null,
295
- cout: null,
296
309
  modeles: {},
297
310
  appel: null,
298
311
  reponses: [],
299
312
  tours: [],
300
313
  recu: false,
301
- vus: [],
314
+ sorties: [],
315
+ partagees: {},
316
+ sans: [],
302
317
  minutes: {},
318
+ couts: {},
319
+ derniereDepense: null,
303
320
  });
304
321
 
305
322
  // The union of intervals, ordered by date: no instant is in two of them.
@@ -333,9 +350,73 @@ function tourDeLUsage(u) {
333
350
  return Object.values(tour).every(n => Number.isFinite(n)) ? tour : null;
334
351
  }
335
352
 
336
- // Adds the lines of `texte` to the state `etat`, which it returns.
337
- function avancer(etat, texte) {
338
- const vus = new Set(etat.vus);
353
+ // A response is the same from one transcript to another by the pair of its message's id and its
354
+ // request's id, as ccusage names it; without one of them it is its transcript's own. A replay of a
355
+ // sidechain under another request id, which ccusage merges, stays apart: the key is that pair alone,
356
+ // and none was seen on a machine.
357
+ const cleEntreTranscriptions = e =>
358
+ e.message?.id && e.requestId ? `${e.message.id} ${e.requestId}` : null;
359
+
360
+ // What ranks a copy of a response against its other copies, each part the larger the better: off a
361
+ // sidechain, its tokens of the four kinds, its detail of the write of the cache (`cache_creation`).
362
+ // ccusage's last tie-breakers, the speed and the written cost, are not read: they tell apart no
363
+ // copies the cost of the frame, reckoned from the tokens, distinguishes.
364
+ const rangDeLaCopie = (e, u) => [
365
+ e.isSidechain === true ? 0 : 1,
366
+ (u.input_tokens ?? 0) +
367
+ (u.output_tokens ?? 0) +
368
+ (u.cache_creation_input_tokens ?? 0) +
369
+ (u.cache_read_input_tokens ?? 0),
370
+ u.cache_creation ? 1 : 0,
371
+ ];
372
+
373
+ // The order of two copies of a response (`{ rang, naissance, f }`: its rank, its file's date of
374
+ // creation and path), the retained one first. At equal usage the file created first wins, before
375
+ // the first path, unlike ccusage: the register only adds lines, so a copy created later must not
376
+ // take a response from a line already written.
377
+ const devant = (a, b) =>
378
+ b.rang[0] - a.rang[0] ||
379
+ b.rang[1] - a.rang[1] ||
380
+ b.rang[2] - a.rang[2] ||
381
+ a.naissance - b.naissance ||
382
+ (a.f < b.f ? -1 : a.f > b.f ? 1 : 0);
383
+
384
+ // The responses each transcript of `copies` (`{ f, naissance, partagees }`) holds and another one of
385
+ // them retains: by file, their keys, sorted. A file that loses none is absent.
386
+ function retenuesAilleurs(copies) {
387
+ const retenues = new Map();
388
+ for (const { f, naissance, partagees } of copies) {
389
+ for (const [cle, rang] of Object.entries(partagees)) {
390
+ const copie = { rang, naissance, f };
391
+ const avant = retenues.get(cle);
392
+ if (!avant || devant(copie, avant) < 0) {
393
+ retenues.set(cle, copie);
394
+ }
395
+ }
396
+ }
397
+ const out = new Map();
398
+ for (const { f, partagees } of copies) {
399
+ const perdues = Object.keys(partagees).filter(cle => retenues.get(cle).f !== f);
400
+ if (perdues.length > 0) {
401
+ out.set(f, perdues.sort());
402
+ }
403
+ }
404
+ return out;
405
+ }
406
+
407
+ // Adds the lines of `texte` to the state `etat`, which it returns. A response, known by the
408
+ // identifier of its message (else of its request), is written over one or several lines: as ccusage
409
+ // reads them, its output is the largest one read, whatever their order, and its input and cache
410
+ // count once, from its first line; `etat.sorties` keeps for each its output counted, its key of
411
+ // tariff, that of the whole request, and its key from one transcript to another. Its tokens, cache,
412
+ // cost and minutes leave out the responses `etat.sans` names, retained by another transcript; its
413
+ // time and turns count every line. `depense` receives what each line counts: its date (NaN without
414
+ // one), its key of tariff, its usage (on a following line, the extra output alone) and
415
+ // `{ jetons, cache, partagee }`, its tokens (the input, the output and the writes of the cache),
416
+ // its cache reads and its key from one transcript to another.
417
+ function avancer(etat, texte, depense) {
418
+ const sorties = new Map(etat.sorties);
419
+ const sans = new Set(etat.sans);
339
420
  const reponses = new Set(etat.reponses);
340
421
  for (const ligne of texte.split('\n')) {
341
422
  if (!ligne.trim()) {
@@ -350,9 +431,6 @@ function avancer(etat, texte) {
350
431
  if (e.type === 'agent-setting') {
351
432
  etat.role ??= e.agentSetting ?? null;
352
433
  }
353
- if (e.type === 'cost-state' && typeof e.totalCostUSD === 'number') {
354
- etat.cout = e.totalCostUSD;
355
- }
356
434
  const t = e.timestamp ? Date.parse(e.timestamp) : NaN;
357
435
  if (!Number.isNaN(t)) {
358
436
  etat.premier = etat.premier === null ? t : Math.min(etat.premier, t);
@@ -402,50 +480,75 @@ function avancer(etat, texte) {
402
480
  etat.premierTour = tourDeLUsage(e.message.usage);
403
481
  }
404
482
  const u = e.message?.usage;
483
+ if (!u) {
484
+ continue;
485
+ }
405
486
  const id = e.message?.id ?? e.requestId;
406
- if (!u || (id && vus.has(id))) {
487
+ const vue = id ? sorties.get(id) : undefined;
488
+ const sortie = u.output_tokens ?? 0;
489
+ if (vue && sortie <= vue.sortie) {
407
490
  continue;
408
491
  }
492
+ // The usage of the response: a write of the cache by its duration, one without them of five
493
+ // minutes, the default of the API.
494
+ const ecrit = vue ? 0 : (u.cache_creation_input_tokens ?? 0);
495
+ const uneHeure = vue ? 0 : (u.cache_creation?.ephemeral_1h_input_tokens ?? 0);
496
+ const usage = {
497
+ entree: vue ? 0 : (u.input_tokens ?? 0),
498
+ sortie: sortie - (vue?.sortie ?? 0),
499
+ lecture: vue ? 0 : (u.cache_read_input_tokens ?? 0),
500
+ ecriture5m: vue ? 0 : (u.cache_creation?.ephemeral_5m_input_tokens ?? ecrit - uneHeure),
501
+ ecriture1h: uneHeure,
502
+ };
503
+ const cle = vue?.cle ?? cleDuTarif(String(e.message?.model ?? ''), usage);
504
+ const partagee = vue ? vue.partagee : cleEntreTranscriptions(e);
409
505
  if (id) {
410
- vus.add(id);
506
+ sorties.set(id, { sortie, cle, partagee });
411
507
  }
412
- const n = (u.input_tokens ?? 0) + (u.output_tokens ?? 0) + (u.cache_creation_input_tokens ?? 0);
413
- etat.jetons += n;
414
- // The tokens by minute of their message, of which the board counts in the day those since its
415
- // marker; a state kept before them starts its own.
416
- if (!Number.isNaN(t)) {
417
- etat.minutes ??= {};
418
- const minute = Math.floor(t / 60_000);
419
- etat.minutes[minute] = (etat.minutes[minute] ?? 0) + n;
420
- }
421
- etat.cache += u.cache_read_input_tokens ?? 0;
422
- // The usage of the message's model: a write of the cache by its duration, one without them
423
- // of five minutes, the default of the API.
424
- const ecrit = u.cache_creation_input_tokens ?? 0;
425
- const uneHeure = u.cache_creation?.ephemeral_1h_input_tokens ?? 0;
426
- const m = (etat.modeles[String(e.message?.model ?? '')] ??= {
508
+ if (partagee) {
509
+ // The line of the largest output ranks the copy.
510
+ etat.partagees[partagee] = rangDeLaCopie(e, u);
511
+ if (sans.has(partagee)) {
512
+ continue;
513
+ }
514
+ }
515
+ const jetons = usage.entree + usage.sortie + ecrit;
516
+ etat.jetons += jetons;
517
+ etat.cache += usage.lecture;
518
+ const m = (etat.modeles[cle] ??= {
427
519
  entree: 0,
428
520
  sortie: 0,
429
521
  lecture: 0,
430
522
  ecriture5m: 0,
431
523
  ecriture1h: 0,
432
524
  });
433
- m.entree += u.input_tokens ?? 0;
434
- m.sortie += u.output_tokens ?? 0;
435
- m.lecture += u.cache_read_input_tokens ?? 0;
436
- m.ecriture5m += u.cache_creation?.ephemeral_5m_input_tokens ?? ecrit - uneHeure;
437
- m.ecriture1h += uneHeure;
525
+ for (const [part, n] of Object.entries(usage)) {
526
+ m[part] += n;
527
+ }
528
+ depense?.(t, cle, usage, { jetons, cache: usage.lecture, partagee });
529
+ // The billed tokens (every kind) and their cost by minute of their line, of which the
530
+ // board counts in the day those since its marker; a null cost, unknown, stays so.
531
+ const factures = Object.values(usage).reduce((s, n) => s + n, 0);
532
+ if (!Number.isNaN(t) && factures > 0) {
533
+ const minute = Math.floor(t / 60_000);
534
+ etat.minutes[minute] = (etat.minutes[minute] ?? 0) + factures;
535
+ const cout = coutDe({ [cle]: usage });
536
+ const avant = etat.couts[minute] === undefined ? 0 : etat.couts[minute];
537
+ etat.couts[minute] = avant === null || cout === null ? null : avant + cout;
538
+ etat.derniereDepense = Math.max(etat.derniereDepense ?? t, t);
539
+ }
438
540
  }
439
- etat.vus = [...vus];
541
+ etat.sorties = [...sorties];
440
542
  etat.reponses = [...reponses];
441
543
  return etat;
442
544
  }
443
545
 
444
546
  // The measures of a state: the tokens, the turns and their working time (the union of the turns,
445
547
  // the waits left out), the start (the oldest date) and the end (the latest), the ticket, the role
446
- // (a session launched with `--agent`), the cost (the total a session writes), the usage by
447
- // model and the one of the first response of a model (`premierTour`, null without a readable
448
- // one). `entre` is the
548
+ // (a session launched with `--agent`), the usage by key of tariff (scripts/tarifs.mjs), the billed
549
+ // tokens and their cost by minute, the date of the latest response that spent tokens
550
+ // (`derniereDepense`, or null) and the usage of the first response of a model (`premierTour`, null
551
+ // without a readable one). `entre` is the
449
552
  // time of the latest incoming message, or null; `attend` tells whether the last tool call still
450
553
  // awaits its answer, the call and its answer paired by their identifier.
451
554
  const mesurer = etat => ({
@@ -459,9 +562,10 @@ const mesurer = etat => ({
459
562
  attend: etat.appel !== null && !etat.reponses.includes(etat.appel),
460
563
  ticket: etat.ticket || null,
461
564
  role: etat.role,
462
- cout: etat.cout,
463
565
  modeles: structuredClone(etat.modeles),
464
- minutes: { ...(etat.minutes ?? {}) },
566
+ minutes: { ...etat.minutes },
567
+ couts: { ...etat.couts },
568
+ derniereDepense: etat.derniereDepense,
465
569
  premierTour: etat.premierTour ? { ...etat.premierTour } : null,
466
570
  });
467
571
 
@@ -481,6 +585,59 @@ function parAgent(registre) {
481
585
  return [...derniere.values()];
482
586
  }
483
587
 
588
+ // The sum of the spendings `l` (each `{ jetons, cout }`, its billed tokens and its cost, null
589
+ // unknown): the tokens, the known cost, and whether the cost of one that spent tokens is missing
590
+ // (`partiel`).
591
+ const additionner = l =>
592
+ l.reduce(
593
+ (s, x) => ({
594
+ jetons: s.jetons + x.jetons,
595
+ cout: s.cout + (x.cout ?? 0),
596
+ partiel: s.partiel || Boolean(x.partiel) || (x.cout === null && x.jetons > 0),
597
+ }),
598
+ { jetons: 0, cout: 0, partiel: false }
599
+ );
600
+
601
+ // The billed tokens and the cost of the day (since the marker <jour>) and of the cumul, each agent
602
+ // counted once: by its latest line of the register (<registre>), or by the reading of its
603
+ // transcript (<depenses>, else its measure as it runs, <vivants>) when that holds a spending the
604
+ // register lacks: no line, an agent running again (<repris>), or a response after its latest
605
+ // line. The day takes of a read agent the responses dated since the marker; an agent without a
606
+ // transcript counts whole the day of its latest line.
607
+ function sommeDesDepenses({ registre, vivants, repris, depenses, maintenant, jour }) {
608
+ const lignesDe = new Map(registre.map(r => [r.agent, r]));
609
+ // An agent's measure as it runs counts without a line, or running again; a finished one with a
610
+ // line, only by the reading of its transcript.
611
+ const courants = vivants.filter(v => !lignesDe.has(v.agent) || repris.has(v.agent));
612
+ const lus = new Map([...courants, ...depenses].map(x => [x.agent, x]));
613
+ const depuis = Math.floor(jour / MINUTE);
614
+ const facture = x => ({ jetons: (x.jetons ?? 0) + (x.cache ?? 0), cout: x.cout ?? null });
615
+ const duCumul = [];
616
+ const duJour = [];
617
+ for (const agent of new Set([...lignesDe.keys(), ...lus.keys()])) {
618
+ const inscrit = lignesDe.get(agent);
619
+ const lu = lus.get(agent);
620
+ const parLui =
621
+ lu &&
622
+ (!inscrit ||
623
+ repris.has(agent) ||
624
+ (lu.derniereDepense ?? -Infinity) > Date.parse(inscrit.fin));
625
+ const entier = facture(parLui ? lu : inscrit);
626
+ duCumul.push(entier);
627
+ if (lu?.minutes) {
628
+ const minutes = Object.keys(lu.minutes).filter(m => Number(m) >= depuis);
629
+ const couts = minutes.map(m => lu.couts?.[m] ?? null);
630
+ duJour.push({
631
+ jetons: minutes.reduce((s, m) => s + lu.minutes[m], 0),
632
+ cout: couts.includes(null) ? null : couts.reduce((s, c) => s + c, 0),
633
+ });
634
+ } else if ((parLui ? maintenant : Date.parse(inscrit.fin)) >= jour) {
635
+ duJour.push(entier);
636
+ }
637
+ }
638
+ return { jour: additionner(duJour), cumul: additionner(duCumul) };
639
+ }
640
+
484
641
  // The intervals of <intervalles> (ordered, apart) out of those of <retires> (ordered, apart).
485
642
  function sauf(intervalles, retires) {
486
643
  const out = [];
@@ -549,8 +706,9 @@ function lireDepuis(f, decalage, taille) {
549
706
  const MORCEAU = 1_048_576;
550
707
 
551
708
  // Adds the lines of `f` between the bytes `decalage` and `taille` to the state `etat`, chunk by
552
- // chunk so the file is never held whole, and returns the bytes it consumed.
553
- function avancerDepuis(etat, f, decalage, taille) {
709
+ // chunk so the file is never held whole, and returns the bytes it consumed. `trier` keeps of each
710
+ // chunk the lines it reads.
711
+ function avancerDepuis(etat, f, decalage, taille, depense, trier) {
554
712
  let position = decalage;
555
713
  let pas = MORCEAU;
556
714
  while (position < taille) {
@@ -563,27 +721,119 @@ function avancerDepuis(etat, f, decalage, taille) {
563
721
  pas *= 2;
564
722
  continue;
565
723
  }
566
- avancer(etat, texte);
724
+ avancer(etat, trier ? trier(texte) : texte, depense);
567
725
  position += lus;
568
726
  pas = MORCEAU;
569
727
  }
570
728
  return position - decalage;
571
729
  }
572
730
 
573
- // The measures of the transcript file `f`, read in chunks. Throws when the file cannot be read.
574
- export function lireFichier(f) {
731
+ // The measures of the transcript file `f`, read in chunks, what each line counts handed to
732
+ // `depense` (`avancer`). Throws when the file cannot be read.
733
+ export function lireFichier(f, depense) {
734
+ return mesurer(etatDe(f, { depense }));
735
+ }
736
+
737
+ // The reading state of the whole file `f`.
738
+ function etatDe(f, { depense, trier } = {}) {
575
739
  const etat = etatNeuf();
576
- avancerDepuis(etat, f, 0, statSync(f).size);
577
- return mesurer(etat);
740
+ avancerDepuis(etat, f, 0, statSync(f).size, depense, trier);
741
+ return etat;
742
+ }
743
+
744
+ // The lines of `texte` that name one of the requests `requetes`.
745
+ function lignesDesRequetes(texte, requetes) {
746
+ const lignes = new Map();
747
+ for (const m of texte.matchAll(/"requestId"\s*:\s*"([^"]+)"/g)) {
748
+ if (requetes.has(m[1])) {
749
+ const debut = texte.lastIndexOf('\n', m.index) + 1;
750
+ const fin = texte.indexOf('\n', m.index);
751
+ lignes.set(debut, texte.slice(debut, fin < 0 ? texte.length : fin));
752
+ }
753
+ }
754
+ return [...lignes.values()].join('\n');
755
+ }
756
+
757
+ const cheminReel = f => {
758
+ try {
759
+ return realpathSync(f);
760
+ } catch {
761
+ return f;
762
+ }
763
+ };
764
+
765
+ // The readings of the transcripts `cibles` (files), whose responses another transcript retains,
766
+ // among them and the files `autres`, are marked: by file, `{ mesures, reponses }`, the measures of
767
+ // the whole transcript and each of its responses (`{ quand, cle, usage, jetons, cache, ailleurs }`,
768
+ // `ailleurs` when retained by another). Two paths of one file share its reading. Of the other files, only the lines that name a request of the targets are parsed, and a
769
+ // file last written before the targets began holds none of their copies. A file that cannot be read
770
+ // is left out. The register (scripts/registre.mjs) and its migration read by it.
771
+ export function lireSansLesRetenuesAilleurs(cibles, autres) {
772
+ const lues = new Map();
773
+ for (const f of cibles) {
774
+ if (lues.has(cheminReel(f))) {
775
+ continue;
776
+ }
777
+ try {
778
+ const reponses = [];
779
+ const etat = etatDe(f, {
780
+ depense: (quand, cle, usage, plus) => reponses.push({ quand, cle, usage, ...plus }),
781
+ });
782
+ lues.set(cheminReel(f), { f, naissance: statSync(f).birthtimeMs, etat, reponses });
783
+ } catch {
784
+ // A transcript it cannot read has no measure.
785
+ }
786
+ }
787
+ const requetes = new Set();
788
+ let depuis = Infinity;
789
+ for (const { etat } of lues.values()) {
790
+ for (const cle of Object.keys(etat.partagees)) {
791
+ requetes.add(cle.slice(cle.indexOf(' ') + 1));
792
+ depuis = Math.min(depuis, etat.premier ?? -Infinity);
793
+ }
794
+ }
795
+ const copies = [...lues.values()].map(({ f, naissance, etat }) => ({
796
+ f,
797
+ naissance,
798
+ partagees: etat.partagees,
799
+ }));
800
+ for (const f of requetes.size > 0 ? autres : []) {
801
+ try {
802
+ const { mtimeMs, birthtimeMs } = statSync(f);
803
+ if (mtimeMs < depuis || lues.has(cheminReel(f))) {
804
+ continue;
805
+ }
806
+ const { partagees } = etatDe(f, { trier: texte => lignesDesRequetes(texte, requetes) });
807
+ copies.push({ f, naissance: birthtimeMs, partagees });
808
+ } catch {
809
+ // A transcript it cannot read retains nothing.
810
+ }
811
+ }
812
+ const ailleurs = retenuesAilleurs(copies);
813
+ const lectures = new Map();
814
+ for (const [reel, { f, etat, reponses }] of lues) {
815
+ const sans = new Set(ailleurs.get(f));
816
+ lectures.set(reel, {
817
+ mesures: mesurer(etat),
818
+ reponses: reponses.map(r => ({ ...r, ailleurs: sans.has(r.partagee) })),
819
+ });
820
+ }
821
+ return new Map(
822
+ cibles.flatMap(f => {
823
+ const lecture = lectures.get(cheminReel(f));
824
+ return lecture ? [[f, lecture]] : [];
825
+ })
826
+ );
578
827
  }
579
828
 
580
829
  // A transcript read where it stopped: `cache` maps a file to its reading state and the byte it
581
- // reached. A transcript only grows; one that became shorter is read again from its start.
830
+ // reached. A transcript only grows; one that became shorter is read again from its start, like one
831
+ // whose kept state lacks the output counted of each response or the responses it shares.
582
832
  const lecteur = cache => f => {
583
833
  try {
584
834
  const taille = statSync(f).size;
585
835
  let { etat, decalage } = cache[f] ?? {};
586
- if (!etat || taille < decalage) {
836
+ if (!etat?.sorties || !etat.partagees || taille < decalage) {
587
837
  etat = etatNeuf();
588
838
  decalage = 0;
589
839
  }
@@ -632,6 +882,134 @@ export function tourne(f, maintenant, sousAgent) {
632
882
  return age < RECENT || (sousAgent && age <= SANS_AGENT && appelEnAttente(f));
633
883
  }
634
884
 
885
+ // The transcripts of the agents of the project at <racine>, in the home <home>: the sessions of
886
+ // its folder and of its agents' copies, and their sub-agents, each its file (`f`), its agent, its
887
+ // folder (`dossier`, `propre` for the project's own) and, for a sub-agent, its session's file
888
+ // (`session`). The board and the register (scripts/registre.mjs) read them.
889
+ export function transcriptionsDuProjet(racine, home) {
890
+ const projets = path.join(home, '.claude', 'projects');
891
+ if (!existsSync(projets)) {
892
+ return [];
893
+ }
894
+ const propre = enTirets(racine);
895
+ const copies = `${enTirets(path.join(racine, '.claude', 'worktrees'))}-`;
896
+ const out = [];
897
+ for (const d of readdirSync(projets)) {
898
+ if (d !== propre && !d.startsWith(copies)) {
899
+ continue;
900
+ }
901
+ const dossier = path.join(projets, d);
902
+ const commun = { dossier, propre: d === propre };
903
+ for (const s of readdirSync(dossier, { withFileTypes: true })) {
904
+ if (s.isDirectory()) {
905
+ for (const f of fichiers(path.join(dossier, s.name, 'subagents'), '.jsonl')) {
906
+ const agent = path.basename(f, '.jsonl').replace(/^agent-/, '');
907
+ const session = path.join(dossier, `${s.name}.jsonl`);
908
+ out.push({ ...commun, f, agent, session });
909
+ }
910
+ } else if (s.name.endsWith('.jsonl')) {
911
+ const f = path.join(dossier, s.name);
912
+ out.push({ ...commun, f, agent: path.basename(f, '.jsonl'), session: null });
913
+ }
914
+ }
915
+ }
916
+ return out;
917
+ }
918
+
919
+ // What a transcript's measures `lu` say of its spending.
920
+ const depenseDe = ({ jetons, cache, modeles, minutes, couts, derniereDepense }) => ({
921
+ jetons,
922
+ cache,
923
+ cout: coutDe(modeles),
924
+ minutes,
925
+ couts,
926
+ derniereDepense,
927
+ });
928
+
929
+ // The count of the responses (`avancer`) under which the cache keeps the spending of a silent
930
+ // transcript and the responses it shares: one kept under another is read again.
931
+ const COMPTE = 'plus grande sortie, une fois par projet';
932
+
933
+ // The spendings `a` and `b` of two transcripts of one agent, added: no response counts in both.
934
+ function ensembleDesDepenses(a, b) {
935
+ const minutes = { ...a.minutes };
936
+ const couts = { ...a.couts };
937
+ for (const [m, n] of Object.entries(b.minutes)) {
938
+ couts[m] =
939
+ minutes[m] === undefined
940
+ ? b.couts[m]
941
+ : couts[m] === null || b.couts[m] === null
942
+ ? null
943
+ : couts[m] + b.couts[m];
944
+ minutes[m] = (minutes[m] ?? 0) + n;
945
+ }
946
+ const dates = [a.derniereDepense, b.derniereDepense].filter(d => d !== null);
947
+ return {
948
+ jetons: a.jetons + b.jetons,
949
+ cache: a.cache + b.cache,
950
+ cout: a.cout === null || b.cout === null ? null : a.cout + b.cout,
951
+ minutes,
952
+ couts,
953
+ derniereDepense: dates.length > 0 ? Math.max(...dates) : null,
954
+ };
955
+ }
956
+
957
+ // The spending of each agent of the project, read from its transcripts, by `cache`: a transcript
958
+ // that moved in the last 30 minutes is read where it stopped (`lecteur`), an older one keeps its
959
+ // spending and the responses it shares, read again whole should it grow. A response present in
960
+ // several transcripts counts once, in the copy retained among those present (`retenuesAilleurs`):
961
+ // a transcript whose responses retained elsewhere changed is read again whole, without them. The
962
+ // transcripts of one agent add up.
963
+ export function lireLesDepenses({ racine, home, maintenant, cache = {} }) {
964
+ const lire = lecteur(cache);
965
+ const lues = [];
966
+ for (const { f, agent } of transcriptionsDuProjet(racine, home)) {
967
+ let stat;
968
+ try {
969
+ stat = statSync(f);
970
+ } catch {
971
+ continue;
972
+ }
973
+ const gardee = cache[f]?.compte === COMPTE && cache[f].taille === stat.size ? cache[f] : null;
974
+ let { depense, partagees, sans } = gardee ?? {};
975
+ if (!gardee) {
976
+ const lu = lire(f);
977
+ if (!lu) {
978
+ continue;
979
+ }
980
+ depense = depenseDe(lu);
981
+ ({ partagees, sans } = cache[f].etat);
982
+ }
983
+ const muette = Boolean(gardee) || maintenant - stat.mtimeMs > SANS_AGENT;
984
+ const naissance = stat.birthtimeMs;
985
+ lues.push({ f, agent, naissance, taille: stat.size, muette, depense, partagees, sans });
986
+ }
987
+ const ailleurs = retenuesAilleurs(lues);
988
+ const depenses = new Map();
989
+ for (const x of lues) {
990
+ const sans = ailleurs.get(x.f) ?? [];
991
+ let { depense, partagees } = x;
992
+ if (sans.join('\n') !== x.sans.join('\n')) {
993
+ cache[x.f] = { etat: { ...etatNeuf(), sans }, decalage: 0 };
994
+ const lu = lire(x.f);
995
+ if (!lu) {
996
+ continue;
997
+ }
998
+ depense = depenseDe(lu);
999
+ ({ partagees } = cache[x.f].etat);
1000
+ }
1001
+ if (x.muette) {
1002
+ cache[x.f] = { depense, taille: x.taille, partagees, sans, compte: COMPTE };
1003
+ }
1004
+ const avant = depenses.get(x.agent);
1005
+ depenses.set(x.agent, {
1006
+ agent: x.agent,
1007
+ ...(avant ? ensembleDesDepenses(avant, depense) : depense),
1008
+ });
1009
+ }
1010
+ return [...depenses.values()];
1011
+ }
1012
+
635
1013
  // A sub-agent's meta file (next to its transcript `f`), or {}.
636
1014
  const metaDe = f => {
637
1015
  try {
@@ -678,7 +1056,7 @@ export function lireVivant({ racine, home, prefix, maintenant, ps, cache = {} })
678
1056
  silence: dernier ? maintenant - dernier.mtime : null,
679
1057
  entre: lu?.entre ?? null,
680
1058
  jetons: lu?.jetons ?? 0,
681
- minutes: lu?.minutes,
1059
+ ...(lu ? depenseDe(lu) : {}),
682
1060
  travail: lu?.travail ?? 0,
683
1061
  tours: lu?.tours ?? [],
684
1062
  });
@@ -694,8 +1072,7 @@ export function lireVivant({ racine, home, prefix, maintenant, ps, cache = {} })
694
1072
  ligne: false,
695
1073
  depuis: lu.premier ?? maintenant,
696
1074
  entre: lu.entre,
697
- jetons: lu.jetons,
698
- minutes: lu.minutes,
1075
+ ...depenseDe(lu),
699
1076
  travail: lu.travail,
700
1077
  tours: lu.tours,
701
1078
  });
@@ -719,8 +1096,7 @@ export function lireVivant({ racine, home, prefix, maintenant, ps, cache = {} })
719
1096
  ligne: false,
720
1097
  depuis: lu.premier ?? maintenant,
721
1098
  entre: lu.entre,
722
- jetons: lu.jetons,
723
- minutes: lu.minutes,
1099
+ ...depenseDe(lu),
724
1100
  travail: lu.travail,
725
1101
  tours: lu.tours,
726
1102
  });
@@ -844,7 +1220,11 @@ const goDe = octets => chiffre(Math.round((octets / 1024 ** 3) * 10) / 10);
844
1220
  // The limit of the part of a pass, after its reservation: « , limite 7,5 Go », « , sans limite »
845
1221
  // for a session; nothing for a part that names none.
846
1222
  const limiteDite = p =>
847
- p.limite === undefined ? '' : p.limite === null ? ', sans limite' : `, limite ${goDe(p.limite)} Go`;
1223
+ p.limite === undefined
1224
+ ? ''
1225
+ : p.limite === null
1226
+ ? ', sans limite'
1227
+ : `, limite ${goDe(p.limite)} Go`;
848
1228
  // What a pass that waits asks of the memory, its reservation and its limit.
849
1229
  const demandeDite = p =>
850
1230
  p.limite === undefined ? '' : ` · ${goDe(p.memoire ?? 0)} Go réservés${limiteDite(p)}`;
@@ -859,7 +1239,8 @@ const demandeDite = p =>
859
1239
  * « ⏳ <sorte> · <projet> · <qui> · attend <raison> · 2 Go réservés, limite 10 Go », what it waits
860
1240
  * for (cores, memory, load) with its figures, then what it asks of the memory.
861
1241
  * <masquer> leaves out the lines of the passes it names (those of a ticket, shown on its line or
862
- * not shown at all: the count keeps them), <court> gives the ticket as the board names it.
1242
+ * not shown at all, and those without a ticket of another project: the count keeps them),
1243
+ * <court> gives the ticket as the board names it.
863
1244
  * @param {{ budget: { coeurs: number, memoire: number }, prises: DUnePart[], attentes: DUnePart[],
864
1245
  * masquer?: (p: DUnePart) => boolean, court?: (ticket: string) => string }} o
865
1246
  * @returns {string[]}
@@ -925,6 +1306,7 @@ export function assembler({
925
1306
  racine = null,
926
1307
  registre: lignesDuRegistre,
927
1308
  vivants,
1309
+ depenses = [],
928
1310
  circuits = [],
929
1311
  maintenant,
930
1312
  jour,
@@ -1130,24 +1512,22 @@ export function assembler({
1130
1512
  travail: l.reduce((s, x) => s + (x.travail ?? 0), 0),
1131
1513
  jetons: l.reduce((s, x) => s + (x.jetons ?? 0), 0),
1132
1514
  });
1133
- // A measure with its turns counts in the day the parts since the day's marker of their union,
1134
- // and, with its tokens by minute, those spent since it: a session opened days ago counts in the
1135
- // day what it did today, time and tokens alike. A register line written without them counts
1136
- // whole in the day it ended.
1515
+ // A measure with its turns counts in the day the parts since the day's marker of their union:
1516
+ // a session opened days ago counts in the day what it did today. A register line written without
1517
+ // them counts whole in the day it ended.
1137
1518
  const partDuJour = tours =>
1138
1519
  reunir(tours).reduce((s, [debut, fin]) => s + Math.max(0, fin - Math.max(debut, jour)), 0);
1139
- const jetonsDuJour = minutes =>
1140
- Object.entries(minutes).reduce(
1141
- (s, [minute, n]) => s + (Number(minute) >= Math.floor(jour / MINUTE) ? n : 0),
1142
- 0
1143
- );
1144
1520
  const duJour = mesures
1145
1521
  .filter(m => m.quand >= jour)
1146
- .map(m => ({
1147
- ...m,
1148
- ...(m.tours ? { travail: partDuJour(m.tours) } : {}),
1149
- ...(m.minutes ? { jetons: jetonsDuJour(m.minutes) } : {}),
1150
- }));
1522
+ .map(m => ({ ...m, ...(m.tours ? { travail: partDuJour(m.tours) } : {}) }));
1523
+ const depensesDuProjet = sommeDesDepenses({
1524
+ registre,
1525
+ vivants,
1526
+ repris,
1527
+ depenses,
1528
+ maintenant,
1529
+ jour,
1530
+ });
1151
1531
  // The discoveries (label `decouverte`): each counts in one case, the first that
1152
1532
  // applies. « rejetés » and « validés » count only since the day's marker <jour>; « new » and
1153
1533
  // « →check », states that await the owner, do not filter by it.
@@ -1186,8 +1566,14 @@ export function assembler({
1186
1566
  const sansLeTempsDuSuperviseur = l => l.map(m => (m.ticket || m.role ? m : { ...m, travail: 0 }));
1187
1567
  const global = {
1188
1568
  compteurs,
1189
- jour: somme(sansLeTempsDuSuperviseur(duJour)),
1190
- cumul: somme(sansLeTempsDuSuperviseur(mesures)),
1569
+ jour: {
1570
+ travail: somme(sansLeTempsDuSuperviseur(duJour)).travail,
1571
+ ...depensesDuProjet.jour,
1572
+ },
1573
+ cumul: {
1574
+ travail: somme(sansLeTempsDuSuperviseur(mesures)).travail,
1575
+ ...depensesDuProjet.cumul,
1576
+ },
1191
1577
  decouvertes,
1192
1578
  };
1193
1579
 
@@ -1616,6 +2002,12 @@ export const k = n =>
1616
2002
  : n >= 1e3
1617
2003
  ? `${Math.round(n / 1e3)} k`
1618
2004
  : `${n}`;
2005
+ // A cost in whole dollars, its thousands apart; a partial one, « ≥ » before the known cost.
2006
+ const dollars = (cout, partiel) => {
2007
+ // A known cost marked partial is a floor: never rounded up.
2008
+ const entiers = partiel ? Math.floor(cout + 1e-6) : Math.round(cout);
2009
+ return `${partiel ? '≥ ' : ''}${String(entiers).replace(/\B(?=(\d{3})+$)/g, ' ')} $`;
2010
+ };
1619
2011
  export const duree = ms => {
1620
2012
  const min = Math.round(ms / MINUTE);
1621
2013
  return min < 60 ? `${min} min` : `${Math.floor(min / 60)}h${String(min % 60).padStart(2, '0')}`;
@@ -2036,6 +2428,21 @@ export function lignes(t, nom, largeur = LARGEUR, groupes = {}) {
2036
2428
  },
2037
2429
  ];
2038
2430
  };
2431
+ // The day's and the cumul's lines of <m> (`{ jour, cumul }`), each its working time, its billed
2432
+ // tokens and its cost.
2433
+ const lignesDesMesures = m => {
2434
+ for (const tete of ['jour', 'cumul']) {
2435
+ const x = { travail: 0, jetons: 0, cout: 0, partiel: false, ...m[tete] };
2436
+ L(
2437
+ cadre(
2438
+ `${tete} ${duree(x.travail)} · ${k(x.jetons)} · ${dollars(x.cout, x.partiel)}`,
2439
+ '',
2440
+ largeur
2441
+ ),
2442
+ TONS.mesure
2443
+ );
2444
+ }
2445
+ };
2039
2446
  if (plusieurs) {
2040
2447
  // The lines of each project, as one project's board says them: « toi » under its label, its
2041
2448
  // questions with the label on each, « file » and « en cours » aligned below; or the fault that
@@ -2059,18 +2466,9 @@ export function lignes(t, nom, largeur = LARGEUR, groupes = {}) {
2059
2466
  ),
2060
2467
  TONS.mesure
2061
2468
  );
2062
- // The day's and the cumulative work time and tokens, summed across the projects, as one
2063
- // project's board shows its own: a multi-root board sums the figures of its roots.
2064
- const m = t.jour ?? { travail: 0, jetons: 0 };
2065
- const mc = t.cumul ?? { travail: 0, jetons: 0 };
2066
- L(
2067
- cadre(
2068
- `jour ${duree(m.travail)} · ${k(m.jetons)} · cumul ${duree(mc.travail)} · ${k(mc.jetons)}`,
2069
- '',
2070
- largeur
2071
- ),
2072
- TONS.mesure
2073
- );
2469
+ // The day's and the cumul's lines, summed across the projects, as one project's board shows
2470
+ // its own: a multi-root board sums the figures of its roots.
2471
+ lignesDesMesures(t);
2074
2472
  } else {
2075
2473
  const g = t.global;
2076
2474
  const c = g.compteurs;
@@ -2089,14 +2487,7 @@ export function lignes(t, nom, largeur = LARGEUR, groupes = {}) {
2089
2487
  ),
2090
2488
  TONS.mesure
2091
2489
  );
2092
- L(
2093
- cadre(
2094
- `jour ${duree(g.jour.travail)} · ${k(g.jour.jetons)} · cumul ${duree(g.cumul.travail)} · ${k(g.cumul.jetons)}`,
2095
- '',
2096
- largeur
2097
- ),
2098
- TONS.mesure
2099
- );
2490
+ lignesDesMesures(g);
2100
2491
  }
2101
2492
  // An alert of several projects' board names its ticket by its whole id.
2102
2493
  for (const a of t.alertes) {
@@ -2194,7 +2585,8 @@ export function lignes(t, nom, largeur = LARGEUR, groupes = {}) {
2194
2585
  // The parts of the machine (`lireLaMesure`, `lignesDesParts`): the budget taken, then who holds
2195
2586
  // a part and who waits for what; the part of each ticket shown stands on its line
2196
2587
  // (`etatsDAgents`), a ticket's pass the board does not show nowhere but in the count, the pass
2197
- // without a ticket here. A reserve of the user that is faulty is said by its name.
2588
+ // without a ticket of the board's project (`ici`) here, another project's nowhere but in the
2589
+ // count. A reserve of the user that is faulty is said by its name.
2198
2590
  const m = t.machine;
2199
2591
  if (m?.faute) {
2200
2592
  poser({
@@ -2207,7 +2599,7 @@ export function lignes(t, nom, largeur = LARGEUR, groupes = {}) {
2207
2599
  budget: m.budget,
2208
2600
  prises: m.prises,
2209
2601
  attentes: m.attentes,
2210
- masquer: p => Boolean(p.ticket),
2602
+ masquer: p => Boolean(p.ticket) || p.ici === false,
2211
2603
  court: courtDuTicket,
2212
2604
  })) {
2213
2605
  poser({
@@ -2790,14 +3182,15 @@ export function ligneEtat(t, voisins = []) {
2790
3182
 
2791
3183
  /**
2792
3184
  * The fault of a call of Beads that threw <e>, as an alert says it: the command `bd` missing from
2793
- * the PATH with its gesture, as the session start names it; else the first line of its error
2794
- * output, else of its message.
3185
+ * the PATH, with its gesture, the process that called it and its PATH; else the first line of its
3186
+ * error output, else of its message.
2795
3187
  * @param {unknown} e
3188
+ * @param {{ pid?: number, chemins?: string }} [appelant]
2796
3189
  * @returns {string}
2797
3190
  */
2798
- export function fauteDeBeads(e) {
3191
+ export function fauteDeBeads(e, { pid = process.pid, chemins = process.env.PATH ?? '' } = {}) {
2799
3192
  if (/** @type {{ code?: string }} */ (e)?.code === 'ENOENT') {
2800
- return 'la commande bd est absente du PATH de cette séance : `npm install -g @beads/bd`';
3193
+ return `la commande bd est absente du PATH du processus ${pid} qui mesure le tableau (\`npm install -g @beads/bd\`) — PATH : ${chemins}`;
2801
3194
  }
2802
3195
  const message =
2803
3196
  String(/** @type {{ stderr?: unknown }} */ (e)?.stderr ?? '').trim() ||
@@ -2805,14 +3198,24 @@ export function fauteDeBeads(e) {
2805
3198
  return message.split('\n')[0];
2806
3199
  }
2807
3200
 
2808
- // The answer of Beads to <args> in the repository at <racine>, as JSON (`liste`), or its fault
2809
- // (`faute`, `fauteDeBeads`).
2810
- const bdJson = (racine, ...args) => {
3201
+ /**
3202
+ * The answer of Beads to <args> in the repository at <racine>, as JSON (`liste`), or its fault
3203
+ * (`faute`, `fauteDeBeads`). The path of `bd` is kept in, or taken back from, the common git
3204
+ * directory <commun> (`bdAAppeler`, scripts/bd-garde.mjs).
3205
+ * @param {string} racine
3206
+ * @param {string | null} commun
3207
+ * @param {...string} args
3208
+ * @returns {{ liste: any[], faute: string | null }}
3209
+ */
3210
+ export const bdJson = (racine, commun, ...args) => {
3211
+ garderBd(commun);
3212
+ const bd = bdAAppeler(commun);
2811
3213
  try {
2812
3214
  return {
2813
3215
  liste: JSON.parse(
2814
- execFileSync('bd', [...args, '--json'], {
3216
+ execFileSync(bd.commande, [...args, '--json'], {
2815
3217
  cwd: racine,
3218
+ env: bd.env,
2816
3219
  encoding: 'utf8',
2817
3220
  stdio: ['ignore', 'pipe', 'pipe'],
2818
3221
  maxBuffer: 256 * 1024 * 1024,
@@ -2954,7 +3357,7 @@ function lire(
2954
3357
  const registre = existsSync(REGISTRE) ? lireRegistre(readFileSync(REGISTRE, 'utf8'), racine) : [];
2955
3358
  const commun = dossierCommun(racine);
2956
3359
  // The tickets and the circuits, each the last reading that succeeded when this one failed.
2957
- const lesTickets = bdJson(racine, 'list', '--all', '--limit', '0');
3360
+ const lesTickets = bdJson(racine, commun, 'list', '--all', '--limit', '0');
2958
3361
  const tickets = lectureGardee(
2959
3362
  commun,
2960
3363
  'tickets',
@@ -2975,6 +3378,9 @@ function lire(
2975
3378
  } catch {
2976
3379
  cache = {};
2977
3380
  }
3381
+ // The spendings first: they settle which responses each transcript leaves out, which the running
3382
+ // agents' readings then follow.
3383
+ const depenses = lireLesDepenses({ racine, home, maintenant, cache });
2978
3384
  const vivants = lireVivant({
2979
3385
  racine,
2980
3386
  home,
@@ -3008,6 +3414,7 @@ function lire(
3008
3414
  racine: commun ? path.dirname(commun) : racine,
3009
3415
  registre,
3010
3416
  vivants,
3417
+ depenses,
3011
3418
  circuits: lesCircuitsLus.liste,
3012
3419
  maintenant,
3013
3420
  jour,
@@ -3056,16 +3463,15 @@ export function ensemble(lus) {
3056
3463
  const marquer = projet => x => ({ ...x, projet });
3057
3464
  const noeud = projet => n => ({ ...n, projet, enfants: n.enfants.map(noeud(projet)) });
3058
3465
  const tous = cle => lisibles.flatMap(l => (l.t[cle] ?? []).map(marquer(l.etiquette)));
3059
- // The sum, across the projects, of a measure of `global` (`jour` or `cumul`): its work time and
3060
- // its tokens added.
3061
- const sommeDesMesures = cle =>
3062
- lisibles.reduce(
3063
- (s, l) => ({
3064
- travail: s.travail + (l.t.global[cle]?.travail ?? 0),
3065
- jetons: s.jetons + (l.t.global[cle]?.jetons ?? 0),
3066
- }),
3067
- { travail: 0, jetons: 0 }
3068
- );
3466
+ // The sum, across the projects, of a measure of `global` (`jour` or `cumul`): its work time,
3467
+ // its tokens and its cost added, partial when one project's is.
3468
+ const sommeDesMesures = cle => {
3469
+ const l = lisibles.map(x => x.t.global[cle] ?? {});
3470
+ return {
3471
+ travail: l.reduce((s, m) => s + (m.travail ?? 0), 0),
3472
+ ...additionner(l.map(m => ({ jetons: 0, cout: 0, ...m }))),
3473
+ };
3474
+ };
3069
3475
  return {
3070
3476
  projets: lus.map(l =>
3071
3477
  l.t
@@ -3111,8 +3517,8 @@ export function ensemble(lus) {
3111
3517
  },
3112
3518
  { new: 0, check: 0, rejetes: 0, valides: 0 }
3113
3519
  ),
3114
- // The day's and the cumulative work time and tokens, summed across the projects (each project's
3115
- // own `global.jour`/`global.cumul`), for the board's time-and-token line of several projects.
3520
+ // The day's and the cumulative work time, tokens and cost, summed across the projects (each
3521
+ // project's own `global.jour`/`global.cumul`), for their lines on a board of several.
3116
3522
  jour: sommeDesMesures('jour'),
3117
3523
  cumul: sommeDesMesures('cumul'),
3118
3524
  etats: premier.t.etats.map(e => ({
@@ -3183,7 +3589,7 @@ export function nommerLesProjets(machine, noms, ici = null) {
3183
3589
  // The board of the repository at <racine>; with <projets>, the folders of other projects, the
3184
3590
  // board of them all (`ensemble`), named « <dépôt> + <projet> + … », with the folder of each
3185
3591
  // ticket's project (`dossiers`), where the pane runs Beads for it. The status line is the
3186
- // session's project's alone. Each project's circuits are read by <circuitsDe> (lists of the
3592
+ // session's project's alone, as is the command of Beads (`bd`). Each project's circuits are read by <circuitsDe> (lists of the
3187
3593
  // Temporal server that it filters, scripts/circuits-du-serveur.mjs, by default), and the night under way on the
3188
3594
  // machine by <nuitDe> (`nuitDuServeur` by default); a night that does not read shows none.
3189
3595
  /**
@@ -3330,6 +3736,8 @@ export async function tableau(
3330
3736
  maintenant
3331
3737
  ),
3332
3738
  etat,
3739
+ // The command by which the pane calls Beads, resolved and checked at this measure.
3740
+ bd: bdAAppeler(ici.commun).commande,
3333
3741
  ...(projets.length
3334
3742
  ? {
3335
3743
  dossiers: Object.fromEntries(