mandrel 2.82.0 → 2.84.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/.agents/README.md +65 -20
- package/.agents/docs/configuration.md +40 -3
- package/.agents/docs/runbooks/mods.md +98 -54
- package/.agents/docs/workflows.md +14 -0
- package/.agents/instructions.md +4 -1
- package/.agents/mods/mandrel-status/hooks/register.tsx +579 -204
- package/.agents/mods/mandrel-status/types/index.d.ts +58 -13
- package/.agents/schemas/agentrc.schema.json +1 -1
- package/.agents/scripts/boot-sweep.js +42 -13
- package/.agents/scripts/coverage-capture.js +55 -24
- package/.agents/scripts/evidence-gate.js +7 -1
- package/.agents/scripts/generate-workflows-doc.js +14 -0
- package/.agents/scripts/lib/baselines/duplication-scanner.js +26 -2
- package/.agents/scripts/lib/bootstrap/agents-md-fold.js +99 -16
- package/.agents/scripts/lib/bootstrap/manifest.js +4 -4
- package/.agents/scripts/lib/bootstrap/project-bootstrap.js +16 -1
- package/.agents/scripts/lib/close-lock-events.js +109 -0
- package/.agents/scripts/lib/close-validation/commands.js +12 -0
- package/.agents/scripts/lib/close-validation/gates.js +6 -0
- package/.agents/scripts/lib/close-validation/process.js +5 -2
- package/.agents/scripts/lib/close-validation/runner.js +14 -4
- package/.agents/scripts/lib/codex/agents-projection.js +284 -0
- package/.agents/scripts/lib/codex/skills-projection.js +291 -0
- package/.agents/scripts/lib/config/agentrc-overlay.js +91 -0
- package/.agents/scripts/lib/config/sync-agentrc.js +39 -19
- package/.agents/scripts/lib/config-resolver.js +5 -42
- package/.agents/scripts/lib/config-settings-schema-quality.js +1 -1
- package/.agents/scripts/lib/config-settings-schema.js +1 -1
- package/.agents/scripts/lib/full-suite-lock.js +20 -0
- package/.agents/scripts/lib/full-suite-queue.js +24 -56
- package/.agents/scripts/lib/generated/agentrc-validator.js +1 -1
- package/.agents/scripts/lib/observability/source-classifier.js +2 -0
- package/.agents/scripts/lib/orchestration/review-providers/codex-cli.js +152 -0
- package/.agents/scripts/lib/orchestration/review-providers/codex.js +33 -105
- package/.agents/scripts/lib/orchestration/review-providers/provider-severity.js +30 -0
- package/.agents/scripts/lib/orchestration/review-providers/security-review.js +3 -17
- package/.agents/scripts/lib/orchestration/single-story-close/phases/close-validation.js +73 -63
- package/.agents/scripts/lib/orchestration/single-story-close/phases/reconcile-done.js +70 -0
- package/.agents/scripts/lib/orchestration/single-story-close/runner.js +3 -0
- package/.agents/scripts/lib/single-story-sweep/reconcile-closing.js +89 -0
- package/.agents/scripts/lib/supervised-suite.js +8 -28
- package/.agents/scripts/single-story-init.js +20 -5
- package/.agents/scripts/sync-agentrc.js +5 -3
- package/.agents/scripts/sync-claude-agents.js +20 -0
- package/.agents/scripts/sync-claude-commands.js +64 -27
- package/.agents/scripts/sync-codex-agents.js +36 -0
- package/.agents/scripts/sync-codex-skills.js +36 -0
- package/.agents/workflows/helpers/mandrel-sync-config.md +16 -9
- package/.agents/workflows/mandrel-update.md +2 -1
- package/README.md +167 -216
- package/docs/CHANGELOG.md +25 -0
- package/lib/cli/guarded-sync.js +3 -2
- package/lib/cli/registry.js +248 -0
- package/lib/cli/sync-agents.js +5 -2
- package/lib/cli/sync-commands.js +5 -2
- package/lib/cli/sync.js +45 -14
- package/lib/cli/uninstall.js +8 -1
- package/lib/migrations/index.js +2 -0
- package/lib/migrations/steps/2.84.0-hoist-system-prompt-block.js +64 -0
- package/package.json +3 -2
|
@@ -7,6 +7,8 @@ import type { EngineInterface, FsEntry, Register } from 'claude-code';
|
|
|
7
7
|
import { atom, read, update } from 'claude-code';
|
|
8
8
|
|
|
9
9
|
import type {
|
|
10
|
+
Attention,
|
|
11
|
+
ChipState,
|
|
10
12
|
Focus,
|
|
11
13
|
Learned,
|
|
12
14
|
PhaseRow,
|
|
@@ -14,19 +16,31 @@ import type {
|
|
|
14
16
|
Snapshot,
|
|
15
17
|
StageName,
|
|
16
18
|
StageRow,
|
|
19
|
+
Tracked,
|
|
17
20
|
} from '../types';
|
|
18
21
|
|
|
19
22
|
const REFRESH_MS = 15_000;
|
|
20
23
|
const LEARN_MS = 10 * 60_000;
|
|
21
24
|
const STALL_MS = 10 * 60_000;
|
|
22
25
|
const MIN_STALL_MS = 2 * 60_000;
|
|
26
|
+
/** How long a run ledger, or a result that did not land, stays on the band. */
|
|
23
27
|
const RECENT_MS = 2 * 60 * 60_000;
|
|
28
|
+
/** How long a landed result stays on the band. */
|
|
29
|
+
const LANDED_MS = 10 * 60_000;
|
|
24
30
|
const MIN_SAMPLES = 3;
|
|
25
31
|
const MAX_SAMPLES = 30;
|
|
26
32
|
/** Under this many body columns the band keeps only its first line. */
|
|
27
33
|
const NARROW = 80;
|
|
28
34
|
/** Cells the Hide and Details buttons take at the end of line 1. */
|
|
29
35
|
const BUTTON_CELLS = 18;
|
|
36
|
+
/** Cells the Copy button and the Open PR link take at the end of line 2. */
|
|
37
|
+
const ACTION_CELLS = 18;
|
|
38
|
+
/** The title's share of line 1. */
|
|
39
|
+
const TITLE_CELLS = 30;
|
|
40
|
+
/** Unmet acceptance ids named before `+N`. */
|
|
41
|
+
const MAX_UNMET = 4;
|
|
42
|
+
/** The longest bar in the Details pane. */
|
|
43
|
+
const BAR_CELLS = 16;
|
|
30
44
|
const PANE = 'mandrel-status';
|
|
31
45
|
|
|
32
46
|
const STAGES: StageName[] = [
|
|
@@ -49,8 +63,15 @@ const CLOSE_PHASES = [
|
|
|
49
63
|
'post-land',
|
|
50
64
|
];
|
|
51
65
|
const MERGE_PHASES = new Set(['auto-merge', 'confirm-merge']);
|
|
52
|
-
|
|
53
|
-
const
|
|
66
|
+
/** Stages the mod times itself; close and merge come from envelope phases. */
|
|
67
|
+
const LEARNED_STAGES = new Set<StageName>([
|
|
68
|
+
'start',
|
|
69
|
+
'build',
|
|
70
|
+
'check',
|
|
71
|
+
'handoff',
|
|
72
|
+
]);
|
|
73
|
+
const FAILED = new Set(['failed', 'escalated']);
|
|
74
|
+
const TERMINAL = new Set(['landed', 'blocked', 'failed', 'escalated']);
|
|
54
75
|
|
|
55
76
|
const WORKTREE = /^story-(\d+)$/;
|
|
56
77
|
const ENVELOPE = /^story-deliver-terminal-(\d+)\.json$/;
|
|
@@ -81,9 +102,17 @@ const learnedAtom = atom(
|
|
|
81
102
|
{ plugin: 'mandrel-status', key: 'learned' } as const,
|
|
82
103
|
{ at: 0, phases: {} } as Learned,
|
|
83
104
|
);
|
|
105
|
+
const stageSamples = atom(
|
|
106
|
+
{ plugin: 'mandrel-status', key: 'stageSamples' } as const,
|
|
107
|
+
{} as Partial<Record<StageName, number[]>>,
|
|
108
|
+
);
|
|
109
|
+
const tracked = atom(
|
|
110
|
+
{ plugin: 'mandrel-status', key: 'tracked' } as const,
|
|
111
|
+
null as Tracked | null,
|
|
112
|
+
);
|
|
84
113
|
const hiddenFor = atom(
|
|
85
114
|
{ plugin: 'mandrel-status', key: 'hiddenFor' } as const,
|
|
86
|
-
null as
|
|
115
|
+
null as string | null,
|
|
87
116
|
);
|
|
88
117
|
|
|
89
118
|
type Stamped = { storyId: number; mtimeMs: number };
|
|
@@ -95,13 +124,18 @@ type Ctx = {
|
|
|
95
124
|
orchestration: string;
|
|
96
125
|
files: FsEntry[];
|
|
97
126
|
now: number;
|
|
127
|
+
/** `https://github.com/<owner>/<repo>` from the merged config, when it names both. */
|
|
128
|
+
repoUrl: string | null;
|
|
98
129
|
};
|
|
99
130
|
|
|
100
131
|
type Envelope = {
|
|
101
132
|
storyId: number;
|
|
102
133
|
at: number;
|
|
103
134
|
status: string;
|
|
135
|
+
/** Where the delivery stopped, as the envelope's `phase` names it. */
|
|
136
|
+
phase: string | null;
|
|
104
137
|
prNumber: number | null;
|
|
138
|
+
prUrl: string | null;
|
|
105
139
|
checksStatus: string | null;
|
|
106
140
|
elapsedSeconds: number | null;
|
|
107
141
|
phaseDurations: Record<string, number>;
|
|
@@ -125,6 +159,8 @@ type Verdict = {
|
|
|
125
159
|
round: number;
|
|
126
160
|
met: number;
|
|
127
161
|
total: number;
|
|
162
|
+
/** 1-based ids of the criteria not `met`. */
|
|
163
|
+
unmet: number[];
|
|
128
164
|
};
|
|
129
165
|
type Handoff = {
|
|
130
166
|
at: number;
|
|
@@ -197,22 +233,34 @@ async function resolveRoot($: EngineInterface): Promise<string> {
|
|
|
197
233
|
return main ?? '.';
|
|
198
234
|
}
|
|
199
235
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
236
|
+
type Config = {
|
|
237
|
+
project?: { paths?: { tempRoot?: unknown } };
|
|
238
|
+
github?: { owner?: unknown; repo?: unknown };
|
|
239
|
+
};
|
|
205
240
|
|
|
206
|
-
/**
|
|
207
|
-
|
|
241
|
+
/**
|
|
242
|
+
* `.agentrc.local.json` wins over `.agentrc.json`, key by key; tempRoot is
|
|
243
|
+
* `temp` when neither sets it, and the repo address needs both owner and repo.
|
|
244
|
+
*/
|
|
245
|
+
async function resolveConfig(
|
|
208
246
|
$: EngineInterface,
|
|
209
247
|
root: string,
|
|
210
|
-
): Promise<string> {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
248
|
+
): Promise<{ temp: string; repoUrl: string | null }> {
|
|
249
|
+
const configs = [
|
|
250
|
+
(await readJson($, join(root, '.agentrc.local.json'))) as Config,
|
|
251
|
+
(await readJson($, join(root, '.agentrc.json'))) as Config,
|
|
252
|
+
];
|
|
253
|
+
const first = (pick: (config: Config) => unknown): string | null =>
|
|
254
|
+
configs.map((config) => str(pick(config ?? {}))).find(Boolean) ?? null;
|
|
255
|
+
const owner = first((config) => config?.github?.owner);
|
|
256
|
+
const repo = first((config) => config?.github?.repo);
|
|
257
|
+
return {
|
|
258
|
+
temp: join(
|
|
259
|
+
root,
|
|
260
|
+
first((config) => config?.project?.paths?.tempRoot) ?? 'temp',
|
|
261
|
+
),
|
|
262
|
+
repoUrl: owner && repo ? `https://github.com/${owner}/${repo}` : null,
|
|
263
|
+
};
|
|
216
264
|
}
|
|
217
265
|
|
|
218
266
|
async function listMatching(
|
|
@@ -256,10 +304,11 @@ function toEnvelope(
|
|
|
256
304
|
): Envelope | null {
|
|
257
305
|
const body = raw as {
|
|
258
306
|
status?: unknown;
|
|
307
|
+
phase?: unknown;
|
|
259
308
|
elapsedSeconds?: unknown;
|
|
260
309
|
nextCommand?: unknown;
|
|
261
310
|
phaseDurations?: unknown;
|
|
262
|
-
pr?: { number?: unknown; checksStatus?: unknown } | null;
|
|
311
|
+
pr?: { number?: unknown; url?: unknown; checksStatus?: unknown } | null;
|
|
263
312
|
blocked?: { blockClass?: unknown } | null;
|
|
264
313
|
failure?: { reason?: unknown } | null;
|
|
265
314
|
};
|
|
@@ -270,7 +319,9 @@ function toEnvelope(
|
|
|
270
319
|
storyId,
|
|
271
320
|
at,
|
|
272
321
|
status,
|
|
322
|
+
phase: str(body.phase),
|
|
273
323
|
prNumber: num(pr.number),
|
|
324
|
+
prUrl: str(pr.url),
|
|
274
325
|
checksStatus: str(pr.checksStatus),
|
|
275
326
|
elapsedSeconds: num(body.elapsedSeconds),
|
|
276
327
|
phaseDurations: durationsOf(body.phaseDurations),
|
|
@@ -374,15 +425,19 @@ async function readCheck(
|
|
|
374
425
|
if (rounds.length === 0) return null;
|
|
375
426
|
const last = rounds.reduce((a, b) => (b.round > a.round ? b : a));
|
|
376
427
|
const raw = (await readJson($, `${dir}/${last.entry.name}`)) as {
|
|
377
|
-
criteria?: { verdict?: unknown }[];
|
|
428
|
+
criteria?: { index?: unknown; verdict?: unknown }[];
|
|
378
429
|
};
|
|
379
430
|
const criteria = Array.isArray(raw?.criteria) ? raw.criteria : [];
|
|
431
|
+
const unmet = criteria.flatMap((one, at) =>
|
|
432
|
+
one?.verdict === 'met' ? [] : [(num(one?.index) ?? at) + 1],
|
|
433
|
+
);
|
|
380
434
|
return {
|
|
381
435
|
at: last.entry.mtimeMs,
|
|
382
436
|
firstAt: Math.min(...rounds.map((one) => one.entry.mtimeMs)),
|
|
383
437
|
round: last.round,
|
|
384
438
|
met: criteria.filter((one) => one?.verdict === 'met').length,
|
|
385
439
|
total: criteria.length,
|
|
440
|
+
unmet,
|
|
386
441
|
};
|
|
387
442
|
}
|
|
388
443
|
|
|
@@ -589,7 +644,20 @@ function stageStarts(ev: Evidence): Record<StageName, number | null> {
|
|
|
589
644
|
};
|
|
590
645
|
}
|
|
591
646
|
|
|
592
|
-
|
|
647
|
+
/** The learned median of a stage the mod times itself, once it has 3+ samples. */
|
|
648
|
+
function stageUsualMs(
|
|
649
|
+
samples: Partial<Record<StageName, number[]>>,
|
|
650
|
+
stage: StageName,
|
|
651
|
+
): number | null {
|
|
652
|
+
const list = LEARNED_STAGES.has(stage) ? (samples[stage] ?? []) : [];
|
|
653
|
+
return list.length >= MIN_SAMPLES ? median(list) * 1000 : null;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function stageRows(
|
|
657
|
+
ev: Evidence,
|
|
658
|
+
current: StageName,
|
|
659
|
+
samples: Partial<Record<StageName, number[]>>,
|
|
660
|
+
): StageRow[] {
|
|
593
661
|
const starts = stageStarts(ev);
|
|
594
662
|
const at = STAGES.indexOf(current);
|
|
595
663
|
return STAGES.map((name, index) => {
|
|
@@ -600,6 +668,7 @@ function stageRows(ev: Evidence, current: StageName): StageRow[] {
|
|
|
600
668
|
name,
|
|
601
669
|
startedAt: index <= at ? starts[name] : null,
|
|
602
670
|
endedAt: index < at ? (later ?? null) : null,
|
|
671
|
+
usualMs: stageUsualMs(samples, name),
|
|
603
672
|
};
|
|
604
673
|
});
|
|
605
674
|
}
|
|
@@ -614,39 +683,43 @@ function phaseOf(stage: StageName, progress: Progress | null): string | null {
|
|
|
614
683
|
const plural = (count: number, word: string): string =>
|
|
615
684
|
`${count} ${word}${count === 1 ? '' : 's'}`;
|
|
616
685
|
|
|
617
|
-
|
|
686
|
+
/** The stage name, or the stage and what it is doing: `check · round 2 · 5/6 met`. */
|
|
687
|
+
function stepOf(
|
|
618
688
|
stage: StageName,
|
|
619
689
|
ev: Evidence,
|
|
620
690
|
progress: Progress | null,
|
|
621
691
|
prNumber: number | null,
|
|
622
692
|
): string {
|
|
693
|
+
const parts: (string | null)[] = [stage];
|
|
623
694
|
switch (stage) {
|
|
624
|
-
case 'start':
|
|
625
|
-
return 'initialized';
|
|
626
695
|
case 'build':
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
: 'building';
|
|
696
|
+
if (ev.build) parts.push(plural(ev.build.count, 'commit'));
|
|
697
|
+
break;
|
|
630
698
|
case 'check':
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
699
|
+
if (ev.check)
|
|
700
|
+
parts.push(
|
|
701
|
+
`round ${ev.check.round}`,
|
|
702
|
+
`${ev.check.met}/${ev.check.total} met`,
|
|
703
|
+
);
|
|
704
|
+
break;
|
|
634
705
|
case 'handoff':
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
return `step ${ev.handoff?.step ?? 'starting'}`;
|
|
706
|
+
parts.push(progress?.phase ?? ev.handoff?.step ?? null);
|
|
707
|
+
break;
|
|
638
708
|
case 'close': {
|
|
639
709
|
const phase = progress?.phase ?? 'close-validation';
|
|
640
710
|
const gate = ev.close?.gate;
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
: `phase ${phase}`;
|
|
644
|
-
}
|
|
645
|
-
case 'merge': {
|
|
646
|
-
const pr = prNumber === null ? 'PR' : `PR #${prNumber}`;
|
|
647
|
-
return `${pr} · ${progress?.phase ?? 'waiting on merge'}`;
|
|
711
|
+
parts.push(phase === 'close-validation' && gate ? `gate ${gate}` : phase);
|
|
712
|
+
break;
|
|
648
713
|
}
|
|
714
|
+
case 'merge':
|
|
715
|
+
parts.push(
|
|
716
|
+
prNumber === null ? 'PR' : `PR #${prNumber}`,
|
|
717
|
+
progress?.phase ??
|
|
718
|
+
(ev.envelope?.status === 'pending' ? 'waiting on merge' : null),
|
|
719
|
+
);
|
|
720
|
+
break;
|
|
649
721
|
}
|
|
722
|
+
return parts.filter(Boolean).join(' · ');
|
|
650
723
|
}
|
|
651
724
|
|
|
652
725
|
/** The stall verdict: learned medians first, else the 10-minute gate-log rule. */
|
|
@@ -656,60 +729,85 @@ function stallOf(
|
|
|
656
729
|
elapsedMs: number | null,
|
|
657
730
|
usualMs: number | null,
|
|
658
731
|
now: number,
|
|
659
|
-
):
|
|
732
|
+
): boolean {
|
|
660
733
|
if (usualMs !== null && elapsedMs !== null)
|
|
661
|
-
return
|
|
662
|
-
isStalled: elapsedMs > Math.max(2 * usualMs, MIN_STALL_MS),
|
|
663
|
-
idleMinutes: null,
|
|
664
|
-
};
|
|
734
|
+
return elapsedMs > Math.max(2 * usualMs, MIN_STALL_MS);
|
|
665
735
|
const idleMs = stage === 'close' && ev.close ? now - ev.close.at : 0;
|
|
666
|
-
return idleMs > STALL_MS
|
|
667
|
-
|
|
668
|
-
|
|
736
|
+
return idleMs > STALL_MS;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function attentionOf(
|
|
740
|
+
status: string,
|
|
741
|
+
checksStatus: string | null,
|
|
742
|
+
isStalled: boolean,
|
|
743
|
+
): Attention {
|
|
744
|
+
if (status === 'landed') return 'landed';
|
|
745
|
+
if (status === 'blocked') return 'needs-you';
|
|
746
|
+
if (FAILED.has(status)) return 'failed';
|
|
747
|
+
if (checksStatus === 'failure') return 'failed';
|
|
748
|
+
return isStalled ? 'slow' : 'working';
|
|
669
749
|
}
|
|
670
750
|
|
|
671
751
|
function deriveFocus(
|
|
672
752
|
storyId: number,
|
|
673
753
|
ev: Evidence,
|
|
674
754
|
learned: Learned,
|
|
675
|
-
|
|
755
|
+
samples: Partial<Record<StageName, number[]>>,
|
|
756
|
+
ctx: Ctx,
|
|
676
757
|
): Focus {
|
|
677
758
|
const isInFlight = ev.envelope === null;
|
|
678
759
|
const { stage, progress } = pickStage(ev);
|
|
679
760
|
const phase = phaseOf(stage, progress);
|
|
680
761
|
const learnedPhase = phase ? learned.phases[phase] : undefined;
|
|
681
|
-
const usualMs =
|
|
682
|
-
learnedPhase && learnedPhase.samples >= MIN_SAMPLES
|
|
762
|
+
const usualMs = phase
|
|
763
|
+
? learnedPhase && learnedPhase.samples >= MIN_SAMPLES
|
|
683
764
|
? learnedPhase.medianSeconds * 1000
|
|
684
|
-
: null
|
|
765
|
+
: null
|
|
766
|
+
: stageUsualMs(samples, stage);
|
|
685
767
|
const phaseStart = progress?.phaseStartedAt ?? stageStarts(ev)[stage];
|
|
686
768
|
const phaseElapsedMs =
|
|
687
|
-
isInFlight && phaseStart !== null
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
769
|
+
isInFlight && phaseStart !== null
|
|
770
|
+
? Math.max(0, ctx.now - phaseStart)
|
|
771
|
+
: null;
|
|
772
|
+
const isStalled =
|
|
773
|
+
isInFlight && stallOf(stage, ev, phaseElapsedMs, usualMs, ctx.now);
|
|
691
774
|
const prNumber = ev.progress?.prNumber ?? ev.envelope?.prNumber ?? null;
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
usualSeconds: learned.phases[name]?.medianSeconds ?? null,
|
|
696
|
-
}));
|
|
775
|
+
const status = ev.envelope?.status ?? 'in-flight';
|
|
776
|
+
const checksStatus = ev.envelope?.checksStatus ?? null;
|
|
777
|
+
const inClose = stage === 'close' && ev.close !== null;
|
|
697
778
|
return {
|
|
698
779
|
storyId,
|
|
699
780
|
title: ev.init?.title ?? null,
|
|
700
|
-
status
|
|
781
|
+
status,
|
|
782
|
+
attention: attentionOf(status, checksStatus, isStalled),
|
|
701
783
|
stage,
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
closePhases
|
|
784
|
+
step: stepOf(stage, ev, progress, prNumber),
|
|
785
|
+
subject: ev.build?.subject ?? null,
|
|
786
|
+
stages: stageRows(ev, stage, samples),
|
|
787
|
+
closePhases: CLOSE_PHASES.map(
|
|
788
|
+
(name): PhaseRow => ({
|
|
789
|
+
name,
|
|
790
|
+
seconds: ev.envelope?.phaseDurations[name] ?? null,
|
|
791
|
+
usualSeconds: learned.phases[name]?.medianSeconds ?? null,
|
|
792
|
+
}),
|
|
793
|
+
),
|
|
706
794
|
prNumber,
|
|
707
|
-
|
|
795
|
+
prUrl:
|
|
796
|
+
ev.envelope?.prUrl ??
|
|
797
|
+
(prNumber !== null && ctx.repoUrl
|
|
798
|
+
? `${ctx.repoUrl}/pull/${prNumber}`
|
|
799
|
+
: null),
|
|
800
|
+
checksStatus,
|
|
708
801
|
elapsedSeconds: ev.envelope?.elapsedSeconds ?? null,
|
|
709
802
|
phaseElapsedMs,
|
|
710
803
|
usualMs,
|
|
711
|
-
|
|
712
|
-
|
|
804
|
+
phase,
|
|
805
|
+
quietMinutes:
|
|
806
|
+
inClose && ev.close
|
|
807
|
+
? Math.floor(Math.max(0, ctx.now - ev.close.at) / 60_000)
|
|
808
|
+
: null,
|
|
809
|
+
lastGate: inClose ? (ev.close?.gate ?? null) : null,
|
|
810
|
+
unmet: ev.check?.unmet ?? [],
|
|
713
811
|
problem: ev.envelope?.problem ?? null,
|
|
714
812
|
nextCommand: ev.envelope?.nextCommand ?? null,
|
|
715
813
|
followUps: ev.followUps,
|
|
@@ -757,7 +855,24 @@ async function readLedgers($: EngineInterface, ctx: Ctx): Promise<Ledger[]> {
|
|
|
757
855
|
return ledgers.sort((a, b) => b.updatedAt - a.updatedAt);
|
|
758
856
|
}
|
|
759
857
|
|
|
760
|
-
|
|
858
|
+
function chipOf(
|
|
859
|
+
id: number,
|
|
860
|
+
envelope: Envelope | undefined,
|
|
861
|
+
ledger: Ledger,
|
|
862
|
+
focus: Focus | null,
|
|
863
|
+
): ChipState {
|
|
864
|
+
const status = envelope?.status;
|
|
865
|
+
if (status === 'landed') return 'landed';
|
|
866
|
+
if (status === 'blocked') return 'needs-you';
|
|
867
|
+
if (status && FAILED.has(status)) return 'failed';
|
|
868
|
+
if (id === focus?.storyId) return 'focus';
|
|
869
|
+
return ledger.dispatched.includes(id) ? 'in-flight' : 'undispatched';
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* The newest live run ledger: chips while it runs; a roll-up once every Story
|
|
874
|
+
* has a result, kept while one did not land, else for 10 minutes.
|
|
875
|
+
*/
|
|
761
876
|
async function readRun(
|
|
762
877
|
$: EngineInterface,
|
|
763
878
|
ctx: Ctx,
|
|
@@ -765,53 +880,72 @@ async function readRun(
|
|
|
765
880
|
focus: Focus | null,
|
|
766
881
|
): Promise<RunLine | null> {
|
|
767
882
|
for (const ledger of await readLedgers($, ctx)) {
|
|
768
|
-
const
|
|
883
|
+
const results = new Map<number, Envelope>();
|
|
769
884
|
for (const stamp of envelopes.filter((one) =>
|
|
770
885
|
ledger.stories.includes(one.storyId),
|
|
771
886
|
)) {
|
|
772
887
|
const envelope = await readEnvelope($, ctx, stamp);
|
|
773
|
-
if (envelope)
|
|
888
|
+
if (envelope) results.set(stamp.storyId, envelope);
|
|
774
889
|
}
|
|
775
|
-
const
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
890
|
+
const chips = ledger.stories.map((storyId) => ({
|
|
891
|
+
storyId,
|
|
892
|
+
state: chipOf(storyId, results.get(storyId), ledger, focus),
|
|
893
|
+
}));
|
|
894
|
+
const isDone = ledger.stories.every((id) =>
|
|
895
|
+
TERMINAL.has(results.get(id)?.status ?? ''),
|
|
896
|
+
);
|
|
897
|
+
const stragglerId = ledger.stories.find(
|
|
898
|
+
(id) => results.get(id)?.status !== 'landed',
|
|
899
|
+
);
|
|
900
|
+
const ended = [...results.values()];
|
|
901
|
+
const lastAt = Math.max(0, ...ended.map((one) => one.at));
|
|
902
|
+
if (isDone && stragglerId === undefined && ctx.now - lastAt > LANDED_MS)
|
|
903
|
+
continue;
|
|
904
|
+
const straggled =
|
|
905
|
+
isDone && stragglerId !== undefined ? results.get(stragglerId) : null;
|
|
787
906
|
return {
|
|
788
|
-
landed:
|
|
907
|
+
landed: chips.filter((chip) => chip.state === 'landed').length,
|
|
789
908
|
total: ledger.stories.length,
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
909
|
+
chips,
|
|
910
|
+
isDone,
|
|
911
|
+
spanMs: isDone
|
|
912
|
+
? lastAt -
|
|
913
|
+
Math.min(
|
|
914
|
+
...ended.map((one) => one.at - (one.elapsedSeconds ?? 0) * 1000),
|
|
915
|
+
)
|
|
916
|
+
: null,
|
|
917
|
+
straggler:
|
|
918
|
+
straggled && stragglerId !== undefined
|
|
919
|
+
? {
|
|
920
|
+
storyId: stragglerId,
|
|
921
|
+
attention:
|
|
922
|
+
straggled.status === 'blocked' ? 'needs-you' : 'failed',
|
|
923
|
+
phase: straggled.phase,
|
|
924
|
+
}
|
|
925
|
+
: null,
|
|
796
926
|
};
|
|
797
927
|
}
|
|
798
928
|
return null;
|
|
799
929
|
}
|
|
800
930
|
|
|
931
|
+
/** A landed result shows for 10 minutes; any other result for 2 hours. */
|
|
932
|
+
const isShown = (envelope: Envelope, now: number): boolean =>
|
|
933
|
+
now - envelope.at <= (envelope.status === 'landed' ? LANDED_MS : RECENT_MS);
|
|
934
|
+
|
|
801
935
|
async function scan(
|
|
802
936
|
$: EngineInterface,
|
|
803
937
|
): Promise<{ next: Snapshot; latest: Envelope | null }> {
|
|
804
938
|
const root = await resolveRoot($);
|
|
805
939
|
if (!(await $.fs.exists(join(root, '.agents')).catch(() => false)))
|
|
806
940
|
return { next: EMPTY, latest: null };
|
|
807
|
-
const temp = await
|
|
941
|
+
const { temp, repoUrl } = await resolveConfig($, root);
|
|
808
942
|
const orchestration = `${temp}/orchestration`;
|
|
809
943
|
const now = await $.clock.now();
|
|
810
944
|
const [worktrees, files] = await Promise.all([
|
|
811
945
|
listMatching($, join(root, '.worktrees'), WORKTREE),
|
|
812
946
|
$.fs.list(orchestration).catch(() => []),
|
|
813
947
|
]);
|
|
814
|
-
const ctx: Ctx = { root, temp, orchestration, files, now };
|
|
948
|
+
const ctx: Ctx = { root, temp, orchestration, files, now, repoUrl };
|
|
815
949
|
const envelopes = stampFiles(files, ENVELOPE);
|
|
816
950
|
const learned = await learn($, ctx, envelopes);
|
|
817
951
|
const recent = newest(
|
|
@@ -819,34 +953,81 @@ async function scan(
|
|
|
819
953
|
);
|
|
820
954
|
const latest = recent ? await readEnvelope($, ctx, recent) : null;
|
|
821
955
|
const inFlight = pickInFlight(worktrees, envelopes);
|
|
822
|
-
const
|
|
956
|
+
const shown = latest && isShown(latest, now) ? latest : null;
|
|
957
|
+
const focusId = inFlight?.storyId ?? shown?.storyId;
|
|
823
958
|
const focus =
|
|
824
959
|
focusId === undefined
|
|
825
960
|
? null
|
|
826
961
|
: deriveFocus(
|
|
827
962
|
focusId,
|
|
828
|
-
await gather($, ctx, focusId, inFlight ? null :
|
|
963
|
+
await gather($, ctx, focusId, inFlight ? null : shown),
|
|
829
964
|
learned,
|
|
830
|
-
|
|
965
|
+
await read($, stageSamples),
|
|
966
|
+
ctx,
|
|
831
967
|
);
|
|
968
|
+
await track($, focus);
|
|
832
969
|
const run = await readRun($, ctx, envelopes, focus);
|
|
833
970
|
return { next: { focus, run, scannedAt: now }, latest };
|
|
834
971
|
}
|
|
835
972
|
|
|
836
|
-
/**
|
|
973
|
+
/**
|
|
974
|
+
* When the followed Story moves past a stage the mod times itself, keep how
|
|
975
|
+
* long that stage took; the medians of these give build, check and handoff
|
|
976
|
+
* their usual time.
|
|
977
|
+
*/
|
|
978
|
+
async function track($: EngineInterface, focus: Focus | null): Promise<void> {
|
|
979
|
+
if (focus?.status !== 'in-flight') return;
|
|
980
|
+
const held = await read($, tracked);
|
|
981
|
+
const was = held?.storyId === focus.storyId ? held.stage : null;
|
|
982
|
+
if (was === focus.stage) return;
|
|
983
|
+
await update($, tracked, () => ({
|
|
984
|
+
storyId: focus.storyId,
|
|
985
|
+
stage: focus.stage,
|
|
986
|
+
}));
|
|
987
|
+
if (was === null || STAGES.indexOf(was) > STAGES.indexOf(focus.stage)) return;
|
|
988
|
+
const row = focus.stages.find((one) => one.name === was);
|
|
989
|
+
if (!row || !LEARNED_STAGES.has(was)) return;
|
|
990
|
+
if (row.startedAt === null || row.endedAt === null) return;
|
|
991
|
+
const seconds = (row.endedAt - row.startedAt) / 1000;
|
|
992
|
+
if (seconds < 0) return;
|
|
993
|
+
await update($, stageSamples, (held) => ({
|
|
994
|
+
...held,
|
|
995
|
+
[was]: [...(held[was] ?? []), seconds].slice(-MAX_SAMPLES),
|
|
996
|
+
}));
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
/** The toast for a Story turning slow, once per Story. */
|
|
1000
|
+
function slowToast(focus: Focus): string {
|
|
1001
|
+
const where = focus.phase ?? focus.stage;
|
|
1002
|
+
const took =
|
|
1003
|
+
focus.phaseElapsedMs === null ? '' : ` ${clock(focus.phaseElapsedMs)}`;
|
|
1004
|
+
const usual =
|
|
1005
|
+
focus.usualMs === null ? '' : ` of usual ~${clock(focus.usualMs)}`;
|
|
1006
|
+
return `Story #${focus.storyId} is slow: ${where}${took}${usual}`;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/** Toasts each result and each first slow verdict once; the first scan only records. */
|
|
837
1010
|
async function announce(
|
|
838
1011
|
$: EngineInterface,
|
|
839
1012
|
latest: Envelope | null,
|
|
1013
|
+
focus: Focus | null,
|
|
840
1014
|
): Promise<void> {
|
|
841
1015
|
const seeded = await read($, isSeeded);
|
|
842
1016
|
if (!seeded) await update($, isSeeded, () => true);
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
if ((await read($, seen)).includes(key)) return;
|
|
846
|
-
await update($, seen, (list) => [...list, key].slice(-50));
|
|
847
|
-
if (seeded && ANNOUNCED.has(latest.status)) {
|
|
1017
|
+
const pending: { key: string; text: string }[] = [];
|
|
1018
|
+
if (latest && TERMINAL.has(latest.status)) {
|
|
848
1019
|
const pr = latest.prNumber ? ` (PR #${latest.prNumber})` : '';
|
|
849
|
-
|
|
1020
|
+
pending.push({
|
|
1021
|
+
key: `${latest.storyId}:${latest.at}`,
|
|
1022
|
+
text: `Story #${latest.storyId} ${latest.status}${pr}`,
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
if (focus?.attention === 'slow')
|
|
1026
|
+
pending.push({ key: `${focus.storyId}:slow`, text: slowToast(focus) });
|
|
1027
|
+
for (const one of pending) {
|
|
1028
|
+
if ((await read($, seen)).includes(one.key)) continue;
|
|
1029
|
+
await update($, seen, (list) => [...list, one.key].slice(-50));
|
|
1030
|
+
if (seeded) $.ui.toast(one.text);
|
|
850
1031
|
}
|
|
851
1032
|
}
|
|
852
1033
|
|
|
@@ -854,7 +1035,7 @@ async function refresh($: EngineInterface): Promise<void> {
|
|
|
854
1035
|
try {
|
|
855
1036
|
const { next, latest } = await scan($);
|
|
856
1037
|
await update($, snapshot, () => next);
|
|
857
|
-
await announce($, latest);
|
|
1038
|
+
await announce($, latest, next.focus);
|
|
858
1039
|
} catch {
|
|
859
1040
|
// Read-only and best effort: a failed scan leaves the last drawing up.
|
|
860
1041
|
}
|
|
@@ -862,15 +1043,43 @@ async function refresh($: EngineInterface): Promise<void> {
|
|
|
862
1043
|
|
|
863
1044
|
// --------------------------------------------------------------- drawing
|
|
864
1045
|
|
|
865
|
-
|
|
1046
|
+
const GLYPH: Record<Attention, string> = {
|
|
1047
|
+
working: '●',
|
|
1048
|
+
slow: '▲',
|
|
1049
|
+
'needs-you': '◆',
|
|
1050
|
+
failed: '✗',
|
|
1051
|
+
landed: '✓',
|
|
1052
|
+
};
|
|
1053
|
+
const COLOR: Record<Attention, string | null> = {
|
|
1054
|
+
working: null,
|
|
1055
|
+
slow: 'yellow',
|
|
1056
|
+
'needs-you': 'magenta',
|
|
1057
|
+
failed: 'red',
|
|
1058
|
+
landed: 'green',
|
|
1059
|
+
};
|
|
1060
|
+
const LABEL: Record<Attention, string> = {
|
|
1061
|
+
working: 'in flight',
|
|
1062
|
+
slow: 'slow',
|
|
1063
|
+
'needs-you': 'needs you',
|
|
1064
|
+
failed: 'failed',
|
|
1065
|
+
landed: 'landed',
|
|
1066
|
+
};
|
|
1067
|
+
const CHIP: Record<ChipState, string> = {
|
|
1068
|
+
landed: '✓',
|
|
1069
|
+
'needs-you': '◆',
|
|
1070
|
+
failed: '✗',
|
|
1071
|
+
focus: '●',
|
|
1072
|
+
'in-flight': '◐',
|
|
1073
|
+
undispatched: '○',
|
|
1074
|
+
};
|
|
866
1075
|
|
|
867
|
-
/** `
|
|
868
|
-
function
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
const minutes = Math.floor(
|
|
872
|
-
if (minutes < 60) return `${minutes}
|
|
873
|
-
return `${Math.floor(minutes / 60)}
|
|
1076
|
+
/** `0:45`, `5:39`, `1:05:00`. */
|
|
1077
|
+
function clock(ms: number): string {
|
|
1078
|
+
const total = Math.max(0, Math.round(ms / 1000));
|
|
1079
|
+
const seconds = String(total % 60).padStart(2, '0');
|
|
1080
|
+
const minutes = Math.floor(total / 60);
|
|
1081
|
+
if (minutes < 60) return `${minutes}:${seconds}`;
|
|
1082
|
+
return `${Math.floor(minutes / 60)}:${String(minutes % 60).padStart(2, '0')}:${seconds}`;
|
|
874
1083
|
}
|
|
875
1084
|
|
|
876
1085
|
/** Cut short with an ellipsis, never wrapped. */
|
|
@@ -879,85 +1088,160 @@ function cut(text: string, width: number): string {
|
|
|
879
1088
|
return width <= 1 ? '…' : `${text.slice(0, width - 1)}…`;
|
|
880
1089
|
}
|
|
881
1090
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1091
|
+
/** Six cells: one filled per finished or current stage. */
|
|
1092
|
+
const meter = (stage: StageName): string =>
|
|
1093
|
+
STAGES.map((_, index) => (index <= STAGES.indexOf(stage) ? '▰' : '▱')).join(
|
|
1094
|
+
'',
|
|
1095
|
+
);
|
|
1096
|
+
|
|
1097
|
+
const ratioOf = (focus: Focus): string | null =>
|
|
1098
|
+
focus.usualMs && focus.phaseElapsedMs !== null
|
|
1099
|
+
? `${(focus.phaseElapsedMs / focus.usualMs).toFixed(1)}×`
|
|
1100
|
+
: null;
|
|
1101
|
+
|
|
1102
|
+
/** A result that stopped the Story, as opposed to red checks on a live PR. */
|
|
1103
|
+
const isStopped = (focus: Focus): boolean =>
|
|
1104
|
+
focus.status === 'blocked' || FAILED.has(focus.status);
|
|
1105
|
+
|
|
1106
|
+
const isChecksRed = (focus: Focus): boolean =>
|
|
1107
|
+
focus.attention === 'failed' && !isStopped(focus);
|
|
1108
|
+
|
|
1109
|
+
function timeOf(focus: Focus): string {
|
|
1110
|
+
if (focus.phaseElapsedMs === null)
|
|
1111
|
+
return focus.status === 'in-flight' ? '' : focus.status;
|
|
1112
|
+
const usual = focus.usualMs === null ? '' : ` / ~${clock(focus.usualMs)}`;
|
|
1113
|
+
return `${clock(focus.phaseElapsedMs)}${usual}`;
|
|
886
1114
|
}
|
|
887
1115
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
if (focus.
|
|
1116
|
+
/** Line 1 after the Story: the outcome, the stopping point, or progress and time. */
|
|
1117
|
+
function progressOf(focus: Focus): string {
|
|
1118
|
+
if (focus.attention === 'landed') {
|
|
891
1119
|
return [
|
|
892
|
-
`landed in ${focus.elapsedSeconds === null ? '?' :
|
|
893
|
-
|
|
1120
|
+
`landed in ${focus.elapsedSeconds === null ? '?' : clock(focus.elapsedSeconds * 1000)}`,
|
|
1121
|
+
focus.prNumber === null ? null : `PR #${focus.prNumber}`,
|
|
894
1122
|
focus.followUps === null ? null : plural(focus.followUps, 'follow-up'),
|
|
895
1123
|
]
|
|
896
1124
|
.filter(Boolean)
|
|
897
1125
|
.join(' · ');
|
|
898
1126
|
}
|
|
899
|
-
if (
|
|
900
|
-
return
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
return
|
|
1127
|
+
if (isStopped(focus))
|
|
1128
|
+
return `${LABEL[focus.attention]} at ${focus.stage} · ${focus.problem ?? 'see the Story'}`;
|
|
1129
|
+
const step = isChecksRed(focus)
|
|
1130
|
+
? `merge · PR #${focus.prNumber ?? '?'} · checks failing`
|
|
1131
|
+
: focus.step;
|
|
1132
|
+
return [`${meter(focus.stage)} ${step}`, timeOf(focus)]
|
|
1133
|
+
.filter(Boolean)
|
|
1134
|
+
.join(' ');
|
|
905
1135
|
}
|
|
906
1136
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
const left = `${glyph}mandrel · #${focus.storyId}${focus.title ? ` ${focus.title}` : ''}`;
|
|
912
|
-
const right = cut(rightOf(focus), Math.max(16, Math.floor(width * 0.6)));
|
|
913
|
-
if (!right) return cut(left, width);
|
|
914
|
-
const room = Math.max(glyph.length + 14, width - right.length - 3);
|
|
915
|
-
return cut(`${cut(left, room)} · ${right}`, width);
|
|
916
|
-
}
|
|
1137
|
+
const chipsOf = (run: RunLine): string =>
|
|
1138
|
+
`run ${run.landed}/${run.total} ${run.chips
|
|
1139
|
+
.map((chip) => `${CHIP[chip.state]}${chip.storyId}`)
|
|
1140
|
+
.join(' ')}`;
|
|
917
1141
|
|
|
918
|
-
function
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1142
|
+
function headline(
|
|
1143
|
+
focus: Focus,
|
|
1144
|
+
run: RunLine | null,
|
|
1145
|
+
isNarrow: boolean,
|
|
1146
|
+
): string {
|
|
1147
|
+
const title =
|
|
1148
|
+
!isNarrow && focus.title ? ` ${cut(focus.title, TITLE_CELLS)}` : '';
|
|
1149
|
+
return [
|
|
1150
|
+
`${GLYPH[focus.attention]} #${focus.storyId}${title}`,
|
|
1151
|
+
progressOf(focus),
|
|
1152
|
+
!isNarrow && run && !run.isDone ? chipsOf(run) : null,
|
|
1153
|
+
]
|
|
1154
|
+
.filter(Boolean)
|
|
1155
|
+
.join(' ');
|
|
928
1156
|
}
|
|
929
1157
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
1158
|
+
const unmetOf = (unmet: number[]): string => {
|
|
1159
|
+
const named = unmet.slice(0, MAX_UNMET).map((id) => `AC-${id}`);
|
|
1160
|
+
const more = unmet.length - named.length;
|
|
1161
|
+
return [...named, ...(more > 0 ? [`+${more}`] : [])].join(', ');
|
|
1162
|
+
};
|
|
1163
|
+
|
|
1164
|
+
/** Line 2: only when the Story needs a look, and never repeating line 1. */
|
|
1165
|
+
function attentionLine(focus: Focus): string | null {
|
|
1166
|
+
if (focus.attention === 'slow') {
|
|
1167
|
+
const parts = [
|
|
1168
|
+
ratioOf(focus) && `${ratioOf(focus)} usual`,
|
|
1169
|
+
focus.quietMinutes ? `gate log quiet ${focus.quietMinutes}m` : null,
|
|
1170
|
+
focus.lastGate ? `last gate ${focus.lastGate}` : null,
|
|
1171
|
+
].filter(Boolean);
|
|
1172
|
+
return `↳ ${parts.length ? parts.join(' · ') : `${focus.stage} is past its usual time`}`;
|
|
1173
|
+
}
|
|
1174
|
+
if (isChecksRed(focus))
|
|
1175
|
+
return `↳ PR #${focus.prNumber ?? '?'} checks failing`;
|
|
1176
|
+
if (!isStopped(focus)) return null;
|
|
1177
|
+
const unmet =
|
|
1178
|
+
focus.stage === 'check' && focus.unmet.length
|
|
1179
|
+
? ` ${unmetOf(focus.unmet)}`
|
|
1180
|
+
: '';
|
|
1181
|
+
return `↳ ${focus.nextCommand ?? `see Story #${focus.storyId}`}${unmet}`;
|
|
940
1182
|
}
|
|
941
1183
|
|
|
942
|
-
function
|
|
943
|
-
const
|
|
944
|
-
|
|
1184
|
+
function rollupOf(run: RunLine): string {
|
|
1185
|
+
const straggler = run.straggler;
|
|
1186
|
+
const glyph = GLYPH[straggler?.attention ?? 'landed'];
|
|
1187
|
+
const span = run.spanMs === null ? '' : ` in ${clock(run.spanMs)}`;
|
|
1188
|
+
const stopped = straggler
|
|
1189
|
+
? ` · #${straggler.storyId} ${LABEL[straggler.attention]}${straggler.phase ? ` at ${straggler.phase}` : ''}`
|
|
945
1190
|
: '';
|
|
946
|
-
return
|
|
1191
|
+
return `${glyph} run ${run.landed}/${run.total} landed${span}${stopped} ${chipsOf(
|
|
1192
|
+
run,
|
|
1193
|
+
)
|
|
1194
|
+
.split(' ')
|
|
1195
|
+
.slice(1)
|
|
1196
|
+
.join(' ')}`;
|
|
947
1197
|
}
|
|
948
1198
|
|
|
949
|
-
|
|
950
|
-
|
|
1199
|
+
type Line = { text: string; color: string | null };
|
|
1200
|
+
|
|
1201
|
+
type Band = {
|
|
1202
|
+
/** `#<id>` or `run`, joined with the attention to key Hide. */
|
|
1203
|
+
key: string;
|
|
1204
|
+
attention: Attention;
|
|
1205
|
+
lines: Line[];
|
|
1206
|
+
/** The command line 2's Copy button copies. */
|
|
1207
|
+
copy: string | null;
|
|
1208
|
+
/** Where line 2's Open PR link goes. */
|
|
1209
|
+
prUrl: string | null;
|
|
1210
|
+
};
|
|
1211
|
+
|
|
1212
|
+
/** The band for a body this wide; null draws nothing. */
|
|
1213
|
+
function compose({ focus, run }: Snapshot, columns: number): Band | null {
|
|
1214
|
+
const isNarrow = columns < NARROW;
|
|
1215
|
+
const first = Math.max(20, columns - BUTTON_CELLS);
|
|
1216
|
+
if (run?.isDone && focus?.status !== 'in-flight') {
|
|
1217
|
+
const attention = run.straggler?.attention ?? 'landed';
|
|
1218
|
+
return {
|
|
1219
|
+
key: 'run',
|
|
1220
|
+
attention,
|
|
1221
|
+
lines: [{ text: cut(rollupOf(run), first), color: COLOR[attention] }],
|
|
1222
|
+
copy: null,
|
|
1223
|
+
prUrl: null,
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
951
1226
|
if (!focus) return null;
|
|
952
|
-
const color =
|
|
1227
|
+
const color = COLOR[focus.attention];
|
|
953
1228
|
const lines: Line[] = [
|
|
954
|
-
{ text: headline(focus,
|
|
1229
|
+
{ text: cut(headline(focus, run, isNarrow), first), color },
|
|
955
1230
|
];
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
if (
|
|
960
|
-
|
|
1231
|
+
const second = attentionLine(focus);
|
|
1232
|
+
const copy = isStopped(focus) ? focus.nextCommand : null;
|
|
1233
|
+
const prUrl = isChecksRed(focus) ? focus.prUrl : null;
|
|
1234
|
+
if (second) {
|
|
1235
|
+
const room = columns - (copy || prUrl ? ACTION_CELLS : 0);
|
|
1236
|
+
lines.push({ text: cut(second, Math.max(20, room)), color });
|
|
1237
|
+
}
|
|
1238
|
+
return {
|
|
1239
|
+
key: `#${focus.storyId}`,
|
|
1240
|
+
attention: focus.attention,
|
|
1241
|
+
lines,
|
|
1242
|
+
copy,
|
|
1243
|
+
prUrl,
|
|
1244
|
+
};
|
|
961
1245
|
}
|
|
962
1246
|
|
|
963
1247
|
const clockOf = (ms: number | null): string => {
|
|
@@ -968,36 +1252,111 @@ const clockOf = (ms: number | null): string => {
|
|
|
968
1252
|
.join(':');
|
|
969
1253
|
};
|
|
970
1254
|
|
|
971
|
-
/**
|
|
972
|
-
function
|
|
1255
|
+
/** A bar on one shared scale, with `▏` where the usual time falls. */
|
|
1256
|
+
function bar(tookMs: number | null, usualMs: number | null, unit: number) {
|
|
1257
|
+
if (tookMs === null || unit <= 0) return '';
|
|
1258
|
+
const cells = [...'█'.repeat(Math.round(tookMs / unit))];
|
|
1259
|
+
if (usualMs !== null) {
|
|
1260
|
+
const mark = Math.round(usualMs / unit);
|
|
1261
|
+
while (cells.length <= mark) cells.push(' ');
|
|
1262
|
+
cells[mark] = '▏';
|
|
1263
|
+
}
|
|
1264
|
+
return cells.join('').trimEnd();
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
function stageDetail(focus: Focus, name: StageName): string {
|
|
1268
|
+
if (name === 'build') return focus.subject ?? '';
|
|
1269
|
+
return name === focus.stage
|
|
1270
|
+
? focus.step.split(' · ').slice(1).join(' · ')
|
|
1271
|
+
: '';
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
function attentionRows(focus: Focus): string[] {
|
|
1275
|
+
if (focus.attention === 'slow') {
|
|
1276
|
+
const took =
|
|
1277
|
+
focus.phaseElapsedMs === null ? '—' : clock(focus.phaseElapsedMs);
|
|
1278
|
+
const usual =
|
|
1279
|
+
focus.usualMs === null ? '' : ` usual ~${clock(focus.usualMs)}`;
|
|
1280
|
+
const ratio = ratioOf(focus) ? ` ${ratioOf(focus)}` : '';
|
|
1281
|
+
const quiet = focus.quietMinutes
|
|
1282
|
+
? ` gate log quiet ${focus.quietMinutes}m`
|
|
1283
|
+
: '';
|
|
1284
|
+
return [
|
|
1285
|
+
` ▲ ${focus.phase ?? focus.stage} ${took}${usual}${ratio}${quiet}`,
|
|
1286
|
+
];
|
|
1287
|
+
}
|
|
1288
|
+
if (isChecksRed(focus))
|
|
1289
|
+
return [` ✗ PR #${focus.prNumber ?? '?'} checks failing`];
|
|
1290
|
+
if (!isStopped(focus)) return [];
|
|
1291
|
+
return [
|
|
1292
|
+
` ${GLYPH[focus.attention]} ${focus.problem ?? LABEL[focus.attention]} at ${focus.stage}`,
|
|
1293
|
+
...(focus.unmet.length ? [` unmet ${unmetOf(focus.unmet)}`] : []),
|
|
1294
|
+
` next: ${focus.nextCommand ?? `see Story #${focus.storyId}`}`,
|
|
1295
|
+
];
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
/** The Details pane: what needs a look, then the timeline against usual, then the run. */
|
|
1299
|
+
function details({ focus, run }: Snapshot, now: number): string[] {
|
|
973
1300
|
if (!focus) return ['No /mandrel-deliver Story in flight or recent.'];
|
|
974
1301
|
const at = STAGES.indexOf(focus.stage);
|
|
975
|
-
const
|
|
976
|
-
const
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1302
|
+
const rows = focus.stages.map((row, index) => {
|
|
1303
|
+
const end =
|
|
1304
|
+
row.endedAt ??
|
|
1305
|
+
(index === at && focus.status === 'in-flight' ? now : null);
|
|
1306
|
+
return {
|
|
1307
|
+
row,
|
|
1308
|
+
index,
|
|
1309
|
+
tookMs:
|
|
1310
|
+
row.startedAt !== null && end !== null ? end - row.startedAt : null,
|
|
1311
|
+
};
|
|
981
1312
|
});
|
|
982
|
-
const
|
|
983
|
-
|
|
984
|
-
:
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1313
|
+
const phases = focus.closePhases.map((phase) => ({
|
|
1314
|
+
phase,
|
|
1315
|
+
tookMs: phase.seconds === null ? null : phase.seconds * 1000,
|
|
1316
|
+
usualMs: phase.usualSeconds === null ? null : phase.usualSeconds * 1000,
|
|
1317
|
+
}));
|
|
1318
|
+
const longest = Math.max(
|
|
1319
|
+
0,
|
|
1320
|
+
...rows.flatMap((one) => [one.tookMs ?? 0, one.row.usualMs ?? 0]),
|
|
1321
|
+
...phases.flatMap((one) => [one.tookMs ?? 0, one.usualMs ?? 0]),
|
|
1322
|
+
);
|
|
1323
|
+
const unit = longest / BAR_CELLS;
|
|
1324
|
+
const total =
|
|
1325
|
+
focus.elapsedSeconds !== null
|
|
1326
|
+
? focus.elapsedSeconds * 1000
|
|
1327
|
+
: now -
|
|
1328
|
+
(focus.stages.find((row) => row.startedAt !== null)?.startedAt ?? now);
|
|
1329
|
+
const timeline = rows.flatMap(({ row, index, tookMs }) => {
|
|
1330
|
+
const mark =
|
|
1331
|
+
index < at || focus.attention === 'landed'
|
|
1332
|
+
? '✓'
|
|
1333
|
+
: index === at
|
|
1334
|
+
? GLYPH[focus.attention]
|
|
1335
|
+
: '○';
|
|
1336
|
+
const took = tookMs === null ? '' : clock(tookMs);
|
|
1337
|
+
const line = ` ${mark} ${row.name.padEnd(17)} ${clockOf(row.startedAt).padEnd(9)} ${took.padStart(7)} ${bar(tookMs, row.usualMs, unit)}`;
|
|
1338
|
+
const detail = stageDetail(focus, row.name);
|
|
1339
|
+
const head = `${line}${detail ? ` ${detail}` : ''}`.trimEnd();
|
|
1340
|
+
if (row.name !== 'close' || index > at) return [head];
|
|
1341
|
+
return [
|
|
1342
|
+
head,
|
|
1343
|
+
...phases.map(({ phase, tookMs: phaseMs, usualMs }) =>
|
|
1344
|
+
` ${phase.name.padEnd(17)} ${''.padEnd(5)} ${(phaseMs === null ? '—' : clock(phaseMs)).padStart(7)} ${bar(phaseMs, usualMs, unit)}${usualMs === null ? '' : ` ~${clock(usualMs)}`}`.trimEnd(),
|
|
1345
|
+
),
|
|
1346
|
+
];
|
|
992
1347
|
});
|
|
1348
|
+
const attention = attentionRows(focus);
|
|
993
1349
|
return [
|
|
994
|
-
|
|
995
|
-
'
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
...
|
|
999
|
-
|
|
1000
|
-
|
|
1350
|
+
`#${focus.storyId}${focus.title ? ` ${focus.title}` : ''} ${LABEL[focus.attention]} · ${clock(total)}`,
|
|
1351
|
+
...(attention.length ? ['NEEDS ATTENTION', ...attention] : []),
|
|
1352
|
+
'TIMELINE',
|
|
1353
|
+
...timeline,
|
|
1354
|
+
...(run
|
|
1355
|
+
? [
|
|
1356
|
+
`RUN ${run.landed}/${run.total} ${run.chips.map((chip) => `${CHIP[chip.state]} #${chip.storyId}`).join(' ')}`,
|
|
1357
|
+
]
|
|
1358
|
+
: []),
|
|
1359
|
+
'▏ marks the usual time; every bar shares one scale',
|
|
1001
1360
|
];
|
|
1002
1361
|
}
|
|
1003
1362
|
|
|
@@ -1018,14 +1377,16 @@ export const register: Register = (on) => {
|
|
|
1018
1377
|
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
|
|
1019
1378
|
if (e.props.hasSurvey) return next(e);
|
|
1020
1379
|
const current = await read($, snapshot);
|
|
1021
|
-
const
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
const { Box, Button, Text } = $.ui.resolve(e);
|
|
1026
|
-
const [first, ...rest] = lines;
|
|
1380
|
+
const drawn = compose(current, e.props.bodyColumns);
|
|
1381
|
+
if (!drawn) return next(e);
|
|
1382
|
+
const hideKey = `${drawn.key}:${drawn.attention}`;
|
|
1383
|
+
if ((await read($, hiddenFor)) === hideKey) return next(e);
|
|
1384
|
+
const { Box, Button, Link, Text } = $.ui.resolve(e);
|
|
1385
|
+
const [first, ...rest] = drawn.lines;
|
|
1386
|
+
if (!first) return next(e);
|
|
1027
1387
|
const style = (line: Line) =>
|
|
1028
1388
|
line.color ? { color: line.color } : { dimColor: true };
|
|
1389
|
+
const copy = drawn.copy;
|
|
1029
1390
|
return (
|
|
1030
1391
|
<Box flexDirection="column">
|
|
1031
1392
|
<Box>
|
|
@@ -1035,7 +1396,7 @@ export const register: Register = (on) => {
|
|
|
1035
1396
|
<Button
|
|
1036
1397
|
key="hide"
|
|
1037
1398
|
label="Hide"
|
|
1038
|
-
onPress={() => update($, hiddenFor, () =>
|
|
1399
|
+
onPress={() => update($, hiddenFor, () => hideKey)}
|
|
1039
1400
|
/>
|
|
1040
1401
|
<Button
|
|
1041
1402
|
key="details"
|
|
@@ -1044,9 +1405,23 @@ export const register: Register = (on) => {
|
|
|
1044
1405
|
/>
|
|
1045
1406
|
</Box>
|
|
1046
1407
|
{rest.map((line, index) => (
|
|
1047
|
-
<
|
|
1048
|
-
{line
|
|
1049
|
-
|
|
1408
|
+
<Box key={`line-${index}`}>
|
|
1409
|
+
<Text {...style(line)} wrap="truncate">
|
|
1410
|
+
{line.text}
|
|
1411
|
+
</Text>
|
|
1412
|
+
{copy ? (
|
|
1413
|
+
<Button
|
|
1414
|
+
key="copy"
|
|
1415
|
+
label="Copy"
|
|
1416
|
+
onPress={(press) => {
|
|
1417
|
+
void $.ui.copy({ text: copy, surface: press.surface });
|
|
1418
|
+
}}
|
|
1419
|
+
/>
|
|
1420
|
+
) : null}
|
|
1421
|
+
{drawn.prUrl ? (
|
|
1422
|
+
<Link key="pr" href={drawn.prUrl} label="Open PR" />
|
|
1423
|
+
) : null}
|
|
1424
|
+
</Box>
|
|
1050
1425
|
))}
|
|
1051
1426
|
</Box>
|
|
1052
1427
|
);
|
|
@@ -1057,7 +1432,7 @@ export const register: Register = (on) => {
|
|
|
1057
1432
|
const current = await read($, snapshot);
|
|
1058
1433
|
return (
|
|
1059
1434
|
<Box flexDirection="column">
|
|
1060
|
-
{details(current
|
|
1435
|
+
{details(current, current.scannedAt).map((line, index) => (
|
|
1061
1436
|
<Text key={`row-${index}`} wrap="truncate">
|
|
1062
1437
|
{line}
|
|
1063
1438
|
</Text>
|