@thebattlearena/corner 0.10.1-beta.78 → 0.10.1-beta.80
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/README.md +69 -1
- package/package.json +2 -2
- package/ring/agents/cornerman.md +7 -0
- package/ring/hooks/hooks.json +1 -1
- package/ring/scripts/arch-gate.mjs +407 -0
- package/ring/scripts/brief-guard.mjs +46 -2
- package/ring/scripts/brief.mjs +46 -2
- package/ring/scripts/config.mjs +24 -0
- package/ring/scripts/engram-memory.mjs +213 -0
- package/ring/scripts/engram.mjs +318 -0
- package/ring/scripts/findings.mjs +37 -4
- package/ring/scripts/judges-card.mjs +180 -7
- package/ring/scripts/mask-guard.mjs +33 -0
- package/ring/scripts/relay.mjs +127 -0
- package/ring/scripts/review-blocks.mjs +232 -0
- package/ring/scripts/tech-plan-log.mjs +34 -2
- package/ring/skills/no-surrender/SKILL.md +5 -0
- package/ring/skills/referee/SKILL.md +24 -3
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
// in its second field (`<file:line> — R11 — …`); X0 when none covers it.
|
|
10
10
|
// node findings.mjs clean <pr> --range <from>..<to> the cornerman found nothing in that range
|
|
11
11
|
// node findings.mjs applied <pr> F<n>[,F<m>…] <sha> the wrestler applied it in that commit
|
|
12
|
-
// node findings.mjs discard <pr> F<n>[,…] --id D<k> --reason "<why>"
|
|
13
|
-
// node findings.mjs ticket <pr> F<n>[,…] --ticket <id|"to file"> --reason "<why>"
|
|
12
|
+
// node findings.mjs discard <pr> F<n>[,…] --id D<k> --reason "<why>" [--judge "<what the human said>"]
|
|
13
|
+
// node findings.mjs ticket <pr> F<n>[,…] --ticket <id|"to file"> --reason "<why>" [--judge "…"]
|
|
14
|
+
// (--judge is required when a finding cites a rule of `findingsNeedJudge`, P14 by default)
|
|
14
15
|
// node findings.mjs escalate <pr> F<n>[,…] sent to the human; waits on their answer
|
|
15
16
|
// node findings.mjs shown <pr> F<n>[,…] --in "<where the human saw it>"
|
|
16
17
|
// node findings.mjs audit <pr> [--full] counts; --full writes findings-audit.md
|
|
@@ -41,6 +42,7 @@ import {
|
|
|
41
42
|
readState,
|
|
42
43
|
repoSlug,
|
|
43
44
|
} from './config.mjs';
|
|
45
|
+
import { syncAfter } from './engram.mjs';
|
|
44
46
|
import { record } from './live.mjs';
|
|
45
47
|
import {
|
|
46
48
|
citedRules,
|
|
@@ -499,6 +501,21 @@ function applied([pr, ...argv]) {
|
|
|
499
501
|
console.log(`${ids.join(', ')} applied in ${full.slice(0, 9)}`);
|
|
500
502
|
}
|
|
501
503
|
|
|
504
|
+
/**
|
|
505
|
+
* The findings among `ids` that cite a rule the referee may not settle alone (`findingsNeedJudge`):
|
|
506
|
+
* by the rule the referee recorded or by the rule field of the line. PURE.
|
|
507
|
+
*/
|
|
508
|
+
export function needJudge(findings, ids, rules) {
|
|
509
|
+
const guarded = new Set(rules ?? []);
|
|
510
|
+
return findings.filter(
|
|
511
|
+
(finding) =>
|
|
512
|
+
ids.includes(finding.id) &&
|
|
513
|
+
[finding.rule, ...(citedRules(finding.text) ?? [])].some((rule) =>
|
|
514
|
+
guarded.has(rule),
|
|
515
|
+
),
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
|
|
502
519
|
/** Settled by the referee alone: the ledger, decisions.md and the judges card all say so. */
|
|
503
520
|
function settleAlone(pr, argv, kind) {
|
|
504
521
|
const { values, rest } = flags(argv);
|
|
@@ -510,7 +527,21 @@ function settleAlone(pr, argv, kind) {
|
|
|
510
527
|
throw new Error('a discard needs the decision that took it: --id D<k>');
|
|
511
528
|
if (kind === 'ticket' && !values.ticket?.trim())
|
|
512
529
|
throw new Error('a ticket needs its id, or --ticket "to file"');
|
|
513
|
-
const { dir } = bout(pr);
|
|
530
|
+
const { dir, state } = bout(pr);
|
|
531
|
+
const judge = values.judge?.trim();
|
|
532
|
+
const { config } = loadConfig(projectDir(), {
|
|
533
|
+
contract: false,
|
|
534
|
+
venue: state.venue ?? 'backend',
|
|
535
|
+
});
|
|
536
|
+
const guarded = needJudge(
|
|
537
|
+
readLedger(dir).findings,
|
|
538
|
+
ids,
|
|
539
|
+
config.findingsNeedJudge,
|
|
540
|
+
);
|
|
541
|
+
if (guarded.length && !judge)
|
|
542
|
+
throw new Error(
|
|
543
|
+
`${guarded.map((f) => f.id).join(', ')} cite${guarded.length === 1 ? 's' : ''} a rule the referee may not settle alone (${(config.findingsNeedJudge ?? []).join(', ')}): fix it, escalate it, or add --judge "<what the human said>"`,
|
|
544
|
+
);
|
|
514
545
|
const at = now();
|
|
515
546
|
const change =
|
|
516
547
|
kind === 'discard'
|
|
@@ -522,7 +553,7 @@ function settleAlone(pr, argv, kind) {
|
|
|
522
553
|
for (const finding of settled)
|
|
523
554
|
appendFileSync(
|
|
524
555
|
join(dir, 'decisions.md'),
|
|
525
|
-
`- ${at} · ${values.id ?? finding.id} · referee · cornerman finding ${finding.id} ${verb}: ${reason} · «${finding.text}»\n`,
|
|
556
|
+
`- ${at} · ${values.id ?? finding.id} · ${judge ? 'judge' : 'referee'} · cornerman finding ${finding.id} ${verb}: ${reason}${judge ? ` (the human: ${judge})` : ''} · «${finding.text}»\n`,
|
|
526
557
|
);
|
|
527
558
|
const cardPath = join(dir, 'judges-card.md');
|
|
528
559
|
if (existsSync(cardPath)) {
|
|
@@ -623,6 +654,8 @@ if (isMain(import.meta.url)) {
|
|
|
623
654
|
}
|
|
624
655
|
try {
|
|
625
656
|
run(rest);
|
|
657
|
+
// An X0 finding and its status go to Engram (quiet without it).
|
|
658
|
+
if (command !== 'audit') await syncAfter(rest[0]);
|
|
626
659
|
} catch (error) {
|
|
627
660
|
console.error(`findings: ${error.message}`);
|
|
628
661
|
process.exit(1);
|
|
@@ -50,6 +50,17 @@
|
|
|
50
50
|
// State lives in ~/.claude/ring/<owner>/<repo>/<pr>/ (RING_HOME overrides the root), never in the
|
|
51
51
|
// session scratchpad: that one is wiped when the session restarts. state.json stays minimal (worktree, branch, base, lastReviewed,
|
|
52
52
|
// active, venue); a state without venue is a backend bout, from before venues existed; round-bells are read from GitHub and the tip from git, so they never go stale here.
|
|
53
|
+
import { archConfig, archStatus, SETUP_HINT } from './arch-gate.mjs';
|
|
54
|
+
import {
|
|
55
|
+
conceptsSinceRelay,
|
|
56
|
+
liveLines,
|
|
57
|
+
relayDue,
|
|
58
|
+
undecidedProposals,
|
|
59
|
+
withConceptClosed,
|
|
60
|
+
withProposalDecision,
|
|
61
|
+
wrestlerIds,
|
|
62
|
+
} from './relay.mjs';
|
|
63
|
+
import { resumeSection } from './compact-hook.mjs';
|
|
53
64
|
import { boutFormatGate } from './format-gate.mjs';
|
|
54
65
|
import { execFileSync } from 'node:child_process';
|
|
55
66
|
import {
|
|
@@ -103,7 +114,9 @@ import {
|
|
|
103
114
|
unloggedEscalationNotice,
|
|
104
115
|
} from './preparation.mjs';
|
|
105
116
|
import { handOffWarning, withChronicleUrl } from './sparring-chronicle.mjs';
|
|
106
|
-
import {
|
|
117
|
+
import { refereeRecall, syncAfter } from './engram.mjs';
|
|
118
|
+
import { estimateFacts, reviewTurn } from './review-blocks.mjs';
|
|
119
|
+
import { parsePlan, PLAN, planItem } from './tech-plan.mjs';
|
|
107
120
|
import { addPlanItem, setPlanState } from './tech-plan-log.mjs';
|
|
108
121
|
import { logPageVerdicts } from './verdicts-log.mjs';
|
|
109
122
|
import { DEFAULT_VENUE } from './venues.mjs';
|
|
@@ -237,10 +250,24 @@ function open(argv) {
|
|
|
237
250
|
dir,
|
|
238
251
|
}),
|
|
239
252
|
);
|
|
253
|
+
warnWithoutArchGate(worktree, venue);
|
|
240
254
|
console.log(dir);
|
|
241
255
|
}
|
|
242
256
|
|
|
243
|
-
|
|
257
|
+
/** A bout in a repo with no architecture gate reviews layers only by eye: say so when it opens. */
|
|
258
|
+
function warnWithoutArchGate(worktree, venue) {
|
|
259
|
+
try {
|
|
260
|
+
const config = archConfig(worktree, venue);
|
|
261
|
+
if (archStatus(worktree, config).configured) return;
|
|
262
|
+
console.error(
|
|
263
|
+
`judges-card: WARNING: this repo has no architecture gate, so layer and dependency rules are reviewed only by eye; ${SETUP_HINT}.`,
|
|
264
|
+
);
|
|
265
|
+
} catch {
|
|
266
|
+
// The warning is advice: a repo the gate cannot read still gets its bout.
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async function summary([pr]) {
|
|
244
271
|
const dir = currentDir(pr);
|
|
245
272
|
const state = readState(dir);
|
|
246
273
|
const tip = git(state.worktree, ['rev-parse', 'HEAD']);
|
|
@@ -283,6 +310,38 @@ function summary([pr]) {
|
|
|
283
310
|
read('judges-card.md').trim(),
|
|
284
311
|
].join('\n'),
|
|
285
312
|
);
|
|
313
|
+
const { config } = loadConfig(projectDir(), {
|
|
314
|
+
contract: false,
|
|
315
|
+
venue: state.venue ?? DEFAULT_VENUE,
|
|
316
|
+
});
|
|
317
|
+
const review = reviewTurn(dir, config.humanReviewEvery, (n, to, ref) =>
|
|
318
|
+
setPlanState(dir, n, to, ref),
|
|
319
|
+
);
|
|
320
|
+
console.log(
|
|
321
|
+
[
|
|
322
|
+
'',
|
|
323
|
+
'## Human review by blocks (PR Review Lab, bout mode)',
|
|
324
|
+
review.applied.length
|
|
325
|
+
? `verdicts applied now: ${review.applied.join(' · ')}`
|
|
326
|
+
: 'no new verdicts',
|
|
327
|
+
review.waiting.length
|
|
328
|
+
? `waiting on the judge: ${review.waiting.map((item) => `B${item.n} «${item.title}»`).join(', ')}`
|
|
329
|
+
: 'no block waits on the judge',
|
|
330
|
+
review.due ?? '',
|
|
331
|
+
].join('\n'),
|
|
332
|
+
);
|
|
333
|
+
const learned = await refereeRecall(config, {
|
|
334
|
+
slug: repoSlug(projectDir()),
|
|
335
|
+
pr,
|
|
336
|
+
});
|
|
337
|
+
if (learned)
|
|
338
|
+
console.log(
|
|
339
|
+
[
|
|
340
|
+
'',
|
|
341
|
+
'## Learned in earlier bouts of this repo (Engram: fouls not to repeat, verdicts, precedents)',
|
|
342
|
+
learned,
|
|
343
|
+
].join('\n'),
|
|
344
|
+
);
|
|
286
345
|
}
|
|
287
346
|
|
|
288
347
|
/**
|
|
@@ -535,14 +594,29 @@ function plan([pr, target, ...rest]) {
|
|
|
535
594
|
: 'a point with that origin is already in the plan',
|
|
536
595
|
);
|
|
537
596
|
}
|
|
597
|
+
if (target === 'estimate') {
|
|
598
|
+
const [n] = rest;
|
|
599
|
+
const point = planItem(parsePlan(readFileSync(join(dir, PLAN), 'utf8')), n);
|
|
600
|
+
const estimated = setPlanState(dir, point.n, point.state, null, undefined, {
|
|
601
|
+
estimate: estimateFacts({
|
|
602
|
+
priority: value('--priority'),
|
|
603
|
+
minutes: value('--minutes'),
|
|
604
|
+
}),
|
|
605
|
+
});
|
|
606
|
+
return void console.log(
|
|
607
|
+
`B${estimated.n} «${estimated.title}»: priority ${estimated.facts.priority ?? '—'} · ${estimated.facts.estimateMin ?? '—'} min`,
|
|
608
|
+
);
|
|
609
|
+
}
|
|
538
610
|
const [state] = rest;
|
|
539
611
|
if (!target || !state)
|
|
540
612
|
throw new Error(
|
|
541
|
-
'usage: plan <pr> <n|title> <pendiente|espera al juez|en curso|hecho> [--ref <sha|round-bell>] | add … | list',
|
|
613
|
+
'usage: plan <pr> <n|title> <pendiente|espera al juez|en curso|hecho> [--ref <sha|round-bell>] [--range A..B] | estimate <n> --minutes <m> [--priority 1-4] | add … | list',
|
|
542
614
|
);
|
|
543
|
-
const changed = setPlanState(dir, target, state, value('--ref')
|
|
615
|
+
const changed = setPlanState(dir, target, state, value('--ref'), undefined, {
|
|
616
|
+
range: value('--range'),
|
|
617
|
+
});
|
|
544
618
|
console.log(
|
|
545
|
-
`${changed.n}. ${changed.title}: ${changed.from} → ${changed.to} at ${localStamp(new Date())}`,
|
|
619
|
+
`${changed.n}. ${changed.title}: ${changed.from} → ${changed.to} at ${localStamp(new Date())}${changed.facts.range && changed.to === 'espera al juez' ? ` · range ${changed.facts.range}` : ''}`,
|
|
546
620
|
);
|
|
547
621
|
}
|
|
548
622
|
|
|
@@ -609,6 +683,11 @@ function close([pr]) {
|
|
|
609
683
|
const dir = currentDir(pr);
|
|
610
684
|
const blocked = auditBlocks(readLedger(dir), { closing: true });
|
|
611
685
|
if (blocked) throw new Error(`bout #${pr} does not close yet: ${blocked}`);
|
|
686
|
+
const proposals = undecidedProposals(
|
|
687
|
+
readFileSync(join(dir, 'judges-card.md'), 'utf8'),
|
|
688
|
+
);
|
|
689
|
+
if (proposals)
|
|
690
|
+
throw new Error(`bout #${pr} does not close yet: ${proposals}`);
|
|
612
691
|
const state = readState(dir);
|
|
613
692
|
const tip = state.lastApproved ?? state.lastReviewed;
|
|
614
693
|
if (tip) {
|
|
@@ -859,8 +938,99 @@ function playByPlayUrl([pr, url]) {
|
|
|
859
938
|
);
|
|
860
939
|
}
|
|
861
940
|
|
|
941
|
+
/**
|
|
942
|
+
* A concept closed after its review: recorded, and the wrestlers that carried it retired. The next
|
|
943
|
+
* concept goes to a fresh wrestler; every `relayEvery` concepts the referee relays first.
|
|
944
|
+
*/
|
|
945
|
+
function concept([pr, name, ...argv]) {
|
|
946
|
+
const { range } = options(argv);
|
|
947
|
+
const dir = currentDir(pr);
|
|
948
|
+
const state = readState(dir);
|
|
949
|
+
const next = withConceptClosed(state, {
|
|
950
|
+
name,
|
|
951
|
+
range,
|
|
952
|
+
at: new Date().toISOString(),
|
|
953
|
+
wrestlers: wrestlerIds(liveLines(dir)),
|
|
954
|
+
});
|
|
955
|
+
writeState(dir, next);
|
|
956
|
+
const { config } = loadConfig(projectDir(), {
|
|
957
|
+
contract: false,
|
|
958
|
+
venue: state.venue ?? DEFAULT_VENUE,
|
|
959
|
+
});
|
|
960
|
+
const steps = [
|
|
961
|
+
`concept ${next.concepts.length} «${name}» closed (${range}); ${next.retiredWrestlers.length} wrestler(s) retired: do not send them the next concept.`,
|
|
962
|
+
relayDue(next, config.relayEvery)
|
|
963
|
+
? `Relay first (${conceptsSinceRelay(next)} concepts since the last one): rewrite the card's «How to resume» so a new session or a compaction resumes from it, then judges-card.mjs relay ${pr}. brief.mjs briefs no wrestler until then.`
|
|
964
|
+
: null,
|
|
965
|
+
`Next concept: brief.mjs wrestler ${pr} --mode resume --vars <file with nextConcept>, launched with prompt "ring-brief: <path>".`,
|
|
966
|
+
];
|
|
967
|
+
console.log(steps.filter(Boolean).join('\n'));
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/** The referee's relay: the card's «How to resume» is current, written after the last concept. */
|
|
971
|
+
function relay([pr]) {
|
|
972
|
+
const dir = currentDir(pr);
|
|
973
|
+
const state = readState(dir);
|
|
974
|
+
const last = (state.concepts ?? []).at(-1);
|
|
975
|
+
const cardPath = join(dir, 'judges-card.md');
|
|
976
|
+
const resume = resumeSection(readFileSync(cardPath, 'utf8'), 20000);
|
|
977
|
+
const names = last
|
|
978
|
+
? [
|
|
979
|
+
last.name,
|
|
980
|
+
last.range,
|
|
981
|
+
...last.range.split('..').filter((sha) => sha.length >= 7),
|
|
982
|
+
]
|
|
983
|
+
: [];
|
|
984
|
+
if (last && !names.some((name) => name && resume.includes(name)))
|
|
985
|
+
throw new Error(
|
|
986
|
+
`the card's «How to resume» does not mention the last concept («${last.name}», ${last.range}): write where the bout is, what is next and what waits on the human, then relay`,
|
|
987
|
+
);
|
|
988
|
+
if (last && statSync(cardPath).mtimeMs < Date.parse(last.at))
|
|
989
|
+
throw new Error(
|
|
990
|
+
`the card was not touched since concept «${last.name}» closed: rewrite its «How to resume» first`,
|
|
991
|
+
);
|
|
992
|
+
const next = {
|
|
993
|
+
...state,
|
|
994
|
+
relays: [
|
|
995
|
+
...(state.relays ?? []),
|
|
996
|
+
{
|
|
997
|
+
at: new Date().toISOString(),
|
|
998
|
+
afterConcepts: (state.concepts ?? []).length,
|
|
999
|
+
},
|
|
1000
|
+
],
|
|
1001
|
+
};
|
|
1002
|
+
writeState(dir, next);
|
|
1003
|
+
console.log(
|
|
1004
|
+
`relay recorded after ${(state.concepts ?? []).length} concept(s); the next wrestler can be briefed.`,
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/** A rulebook proposal of the card, accepted or rejected with its reason. */
|
|
1009
|
+
function proposal([pr, n, verdict, ...argv]) {
|
|
1010
|
+
const { why } = options(argv);
|
|
1011
|
+
const dir = currentDir(pr);
|
|
1012
|
+
const cardPath = join(dir, 'judges-card.md');
|
|
1013
|
+
const decided = { accept: 'accepted', reject: 'rejected' }[verdict];
|
|
1014
|
+
if (!decided)
|
|
1015
|
+
throw new Error('usage: proposal <pr> <n> accept|reject --why "<why>"');
|
|
1016
|
+
writeFileSync(
|
|
1017
|
+
cardPath,
|
|
1018
|
+
withProposalDecision(
|
|
1019
|
+
readFileSync(cardPath, 'utf8'),
|
|
1020
|
+
n,
|
|
1021
|
+
decided,
|
|
1022
|
+
why,
|
|
1023
|
+
new Date().toISOString().slice(0, 10),
|
|
1024
|
+
),
|
|
1025
|
+
);
|
|
1026
|
+
console.log(`proposal ${n} ${decided}`);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
862
1029
|
const COMMANDS = {
|
|
863
1030
|
open,
|
|
1031
|
+
concept,
|
|
1032
|
+
relay,
|
|
1033
|
+
proposal,
|
|
864
1034
|
'play-by-play-url': playByPlayUrl,
|
|
865
1035
|
'page-answers': pageAnswers,
|
|
866
1036
|
'page-verdicts': pageVerdicts,
|
|
@@ -880,12 +1050,15 @@ if (isMain(import.meta.url)) {
|
|
|
880
1050
|
const run = COMMANDS[command];
|
|
881
1051
|
if (!run) {
|
|
882
1052
|
console.error(
|
|
883
|
-
'Usage: node judges-card.mjs open|summary|log|did|list|path|close|approve-contract|title-defense|play-by-play-url|page-answers|page-verdicts|plan …',
|
|
1053
|
+
'Usage: node judges-card.mjs open|summary|log|did|list|path|close|concept|relay|proposal|approve-contract|title-defense|play-by-play-url|page-answers|page-verdicts|plan …',
|
|
884
1054
|
);
|
|
885
1055
|
process.exit(1);
|
|
886
1056
|
}
|
|
887
1057
|
try {
|
|
888
|
-
run(rest);
|
|
1058
|
+
await run(rest);
|
|
1059
|
+
// What the bout learned goes to Engram after each command that may change it (quiet without it).
|
|
1060
|
+
if (['log', 'concept', 'relay', 'proposal', 'close'].includes(command))
|
|
1061
|
+
await syncAfter(rest[0]);
|
|
889
1062
|
} catch (error) {
|
|
890
1063
|
console.error(`judges-card: ${error.message}`);
|
|
891
1064
|
process.exit(1);
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
//
|
|
11
11
|
// Exit 2 with the reason blocks the command. If the guard itself fails while a bout may be active,
|
|
12
12
|
// it blocks too: a guard that cannot evaluate must not let the command through.
|
|
13
|
+
import { boutArchGate } from './arch-gate.mjs';
|
|
13
14
|
import { boutFormatGate } from './format-gate.mjs';
|
|
14
15
|
import { execFileSync } from 'node:child_process';
|
|
15
16
|
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
@@ -881,6 +882,18 @@ const gitRules = [
|
|
|
881
882
|
return `The PR branch ${branch} only receives formatted work: ${reason}`;
|
|
882
883
|
},
|
|
883
884
|
},
|
|
885
|
+
{
|
|
886
|
+
// Third line: what goes up to the PR branch adds no import a layer may not make (P14).
|
|
887
|
+
when: (git, ctx) =>
|
|
888
|
+
git.sub === 'push' && ctx.archBeforePush(git, pushRefspecs(git, ctx)),
|
|
889
|
+
reason: (git, ctx) => {
|
|
890
|
+
const { branch, reason } = ctx.archBeforePush(
|
|
891
|
+
git,
|
|
892
|
+
pushRefspecs(git, ctx),
|
|
893
|
+
);
|
|
894
|
+
return `The PR branch ${branch} only receives work that respects the repo's layers: ${reason}`;
|
|
895
|
+
},
|
|
896
|
+
},
|
|
884
897
|
{
|
|
885
898
|
when: (git, ctx) =>
|
|
886
899
|
git.sub === 'push' && ctx.findingsBeforePush(git, pushRefspecs(git, ctx)),
|
|
@@ -1283,6 +1296,8 @@ function judgeSegment(segment, words, cwd, ctx) {
|
|
|
1283
1296
|
ctx.findingsBeforePushAt(context.path(push.dir), refspecs),
|
|
1284
1297
|
formatBeforePush: (push, refspecs) =>
|
|
1285
1298
|
ctx.formatBeforePushAt(context.path(push.dir), refspecs),
|
|
1299
|
+
archBeforePush: (push, refspecs) =>
|
|
1300
|
+
ctx.archBeforePushAt(context.path(push.dir), refspecs),
|
|
1286
1301
|
isBackupBranch: (push, target) =>
|
|
1287
1302
|
ctx
|
|
1288
1303
|
.backupBranchesAt(context.path(push.dir))
|
|
@@ -1574,6 +1589,24 @@ function realContext(cwd) {
|
|
|
1574
1589
|
}
|
|
1575
1590
|
return null;
|
|
1576
1591
|
},
|
|
1592
|
+
// The first push to a bout's PR branch whose range adds an import its layers forbid, or null.
|
|
1593
|
+
// A repo with no gate configured passes (judges-card open warned about it).
|
|
1594
|
+
archBeforePushAt: (dir, refspecs) => {
|
|
1595
|
+
const slug = insideGitRepo(dirOf(dir)) ? slugOf(dirOf(dir)) : null;
|
|
1596
|
+
if (!slug) return null;
|
|
1597
|
+
for (const { source, target } of refspecs) {
|
|
1598
|
+
const bout = boutsOf(slug).find(({ state }) => state.branch === target);
|
|
1599
|
+
if (!bout || source === null) continue;
|
|
1600
|
+
const sha = git(dirOf(dir), [
|
|
1601
|
+
'rev-parse',
|
|
1602
|
+
'--verify',
|
|
1603
|
+
`${source}^{commit}`,
|
|
1604
|
+
]);
|
|
1605
|
+
const { refusal } = boutArchGate(bout.state, sha);
|
|
1606
|
+
if (refusal) return { branch: target, reason: refusal };
|
|
1607
|
+
}
|
|
1608
|
+
return null;
|
|
1609
|
+
},
|
|
1577
1610
|
contractApprovals: (where) => {
|
|
1578
1611
|
const slug = slugWhere(where);
|
|
1579
1612
|
if (!slug) return {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// The bout's continuity: one fresh wrestler per concept, the referee's relay every few concepts, and
|
|
2
|
+
// no close while a rulebook proposal waits for its decision. Zero-dependency.
|
|
3
|
+
//
|
|
4
|
+
// A wrestler that carried a concept carries its context too: after `judges-card.mjs concept`, the
|
|
5
|
+
// next concept goes to a new wrestler (`brief.mjs wrestler <pr> --mode resume`), and brief-guard
|
|
6
|
+
// warns (or blocks) a SendMessage to a retired one. Every `relayEvery` concepts the referee rewrites
|
|
7
|
+
// the card's «how to resume» and records it (`judges-card.mjs relay`): until then brief.mjs does not
|
|
8
|
+
// brief the next wrestler, so a compaction (the SessionStart hook puts that section back) or a new
|
|
9
|
+
// session always resumes from a card that is current. `judges-card.mjs close` refuses while a
|
|
10
|
+
// proposal of «For the rulebook / precedents» (an X0 included) has no decision.
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
|
|
14
|
+
import { LIVE_LOG } from './live.mjs';
|
|
15
|
+
|
|
16
|
+
export const PROPOSALS = 'For the rulebook / precedents';
|
|
17
|
+
const DECIDED = /→\s*(accepted|rejected)\b/;
|
|
18
|
+
|
|
19
|
+
const sectionOf = (lines, heading) => {
|
|
20
|
+
const start = lines.findIndex((line) => line.startsWith(`## ${heading}`));
|
|
21
|
+
if (start < 0) return null;
|
|
22
|
+
const rest = lines.findIndex((line, i) => i > start && /^##\s/.test(line));
|
|
23
|
+
return { start, end: rest < 0 ? lines.length : rest };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The proposals of the card's «For the rulebook / precedents» section, in order: each item is a
|
|
28
|
+
* `- ` line with its indented continuation, minus the template's `- <…>` placeholder. PURE.
|
|
29
|
+
*/
|
|
30
|
+
export function proposalsOf(card) {
|
|
31
|
+
const lines = String(card ?? '').split('\n');
|
|
32
|
+
const section = sectionOf(lines, PROPOSALS);
|
|
33
|
+
if (!section) return [];
|
|
34
|
+
const items = [];
|
|
35
|
+
let current = null;
|
|
36
|
+
for (let i = section.start + 1; i < section.end; i += 1) {
|
|
37
|
+
const line = lines[i];
|
|
38
|
+
if (line.startsWith('- ')) {
|
|
39
|
+
current = line.startsWith('- <') ? null : { at: i, text: line };
|
|
40
|
+
if (current) items.push(current);
|
|
41
|
+
} else if (current && /^\s+\S/.test(line)) current.text += `\n${line}`;
|
|
42
|
+
else current = null;
|
|
43
|
+
}
|
|
44
|
+
return items.map((item, index) => ({
|
|
45
|
+
n: index + 1,
|
|
46
|
+
line: item.at,
|
|
47
|
+
text: item.text,
|
|
48
|
+
decided: DECIDED.test(item.text),
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The card with proposal `n` (1-based) decided: `→ accepted|rejected (<at>): <why>`. PURE. */
|
|
53
|
+
export function withProposalDecision(card, n, verdict, why, at) {
|
|
54
|
+
if (!['accepted', 'rejected'].includes(verdict))
|
|
55
|
+
throw new Error('a proposal is accept or reject');
|
|
56
|
+
if (!why?.trim()) throw new Error('a decision on a proposal needs --why');
|
|
57
|
+
const proposal = proposalsOf(card).find((item) => item.n === Number(n));
|
|
58
|
+
if (!proposal) throw new Error(`there is no proposal ${n} in the card`);
|
|
59
|
+
if (proposal.decided)
|
|
60
|
+
throw new Error(`proposal ${n} is already decided: ${proposal.text}`);
|
|
61
|
+
const lines = String(card).split('\n');
|
|
62
|
+
lines[proposal.line] =
|
|
63
|
+
`${lines[proposal.line]} → ${verdict} (${at}): ${why.trim()}`;
|
|
64
|
+
return lines.join('\n');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Why the bout cannot close for its proposals, or null. PURE. */
|
|
68
|
+
export function undecidedProposals(card) {
|
|
69
|
+
const open = proposalsOf(card).filter((item) => !item.decided);
|
|
70
|
+
if (!open.length) return null;
|
|
71
|
+
return `${open.length} rulebook proposal(s) without a decision: ${open
|
|
72
|
+
.map((item) => `${item.n}. ${item.text.split('\n')[0].slice(2, 120)}`)
|
|
73
|
+
.join(
|
|
74
|
+
' · ',
|
|
75
|
+
)}. Decide each with judges-card.mjs proposal <pr> <n> accept|reject --why "<why>" (an accepted one goes to the precedents in its own PR)`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Concepts closed since the last relay. PURE. */
|
|
79
|
+
export const conceptsSinceRelay = (state) => {
|
|
80
|
+
const concepts = state.concepts ?? [];
|
|
81
|
+
const last = (state.relays ?? []).at(-1);
|
|
82
|
+
return last ? concepts.length - last.afterConcepts : concepts.length;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** Is a relay due before the next wrestler? `every` null or 0 turns it off. PURE. */
|
|
86
|
+
export const relayDue = (state, every) =>
|
|
87
|
+
Boolean(every) && conceptsSinceRelay(state) >= every;
|
|
88
|
+
|
|
89
|
+
/** The wrestler agent ids a bout's live feed has seen (what a concept close retires). PURE. */
|
|
90
|
+
export function wrestlerIds(lines) {
|
|
91
|
+
const ids = new Set();
|
|
92
|
+
for (const line of lines) {
|
|
93
|
+
try {
|
|
94
|
+
const event = JSON.parse(line);
|
|
95
|
+
const id = /^agent (\S+)$/.exec(event.note ?? '')?.[1];
|
|
96
|
+
if (event.actor === 'luchador' && id) ids.add(id);
|
|
97
|
+
} catch {
|
|
98
|
+
// A torn line is skipped.
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return [...ids];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The state after a concept closes: the concept recorded and its wrestlers retired. PURE. */
|
|
105
|
+
export function withConceptClosed(state, { name, range, at, wrestlers }) {
|
|
106
|
+
if (!name?.trim()) throw new Error('a concept needs its name');
|
|
107
|
+
if (!/^\S+\.\.\S+$/.test(range ?? ''))
|
|
108
|
+
throw new Error('a concept needs its reviewed range: --range <from>..<to>');
|
|
109
|
+
return {
|
|
110
|
+
...state,
|
|
111
|
+
concepts: [...(state.concepts ?? []), { name: name.trim(), range, at }],
|
|
112
|
+
retiredWrestlers: [
|
|
113
|
+
...new Set([...(state.retiredWrestlers ?? []), ...wrestlers]),
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The live lines of a bout, or none. */
|
|
119
|
+
export function liveLines(dir) {
|
|
120
|
+
try {
|
|
121
|
+
return readFileSync(join(dir, LIVE_LOG), 'utf8')
|
|
122
|
+
.split('\n')
|
|
123
|
+
.filter(Boolean);
|
|
124
|
+
} catch {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
}
|