@futurelastic/colab-handbook 1.22.0-rc.3 → 1.22.0-rc.5
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/package.json +1 -1
- package/tools/colab +277 -39
- package/tools/lib/ci-forgejo.js +53 -1
- package/tools/lib/claim-comments.js +6 -5
- package/tools/lib/claim-identity.js +19 -2
- package/tools/lib/claim-takeover.js +167 -0
- package/tools/lib/codec/claim.d.ts +3 -0
- package/tools/lib/codec/claim.js +15 -5
- package/tools/lib/codec/samples.json +21 -0
- package/tools/lib/factories.js +3 -1
- package/tools/lib/git.js +23 -1
- package/tools/lib/ship-handoff.js +102 -20
- package/tools/lib/tracker-fake.js +20 -4
- package/tools/lib/tracker-github.js +8 -0
- package/tools/lib/tracker-scenarios.json +17 -1
- package/tools/lib/tracker.js +12 -3
package/package.json
CHANGED
package/tools/colab
CHANGED
|
@@ -64,7 +64,10 @@ const axisAuthority = require('./lib/axis-authority');
|
|
|
64
64
|
const writesAuthority = require('./lib/writes-authority');
|
|
65
65
|
const claimIdentity = require('./lib/claim-identity');
|
|
66
66
|
const claimComments = require('./lib/claim-comments');
|
|
67
|
+
const factoriesLib = require('./lib/factories'); // #739
|
|
68
|
+
const claimTakeover = require('./lib/claim-takeover'); // #744
|
|
67
69
|
const codec = require('./lib/codec');
|
|
70
|
+
const factories = require('./lib/factories');
|
|
68
71
|
const machine = require('./lib/machine');
|
|
69
72
|
const targetSync = require('./lib/ship-target-sync');
|
|
70
73
|
const shipBatch = require('./lib/ship-batch');
|
|
@@ -340,6 +343,58 @@ function commentHost(repoAbs) {
|
|
|
340
343
|
* `ioreg` spawn only for commands that actually write or compare a claim. */
|
|
341
344
|
function myMachineId() { return machine.localMachine().id || null; }
|
|
342
345
|
|
|
346
|
+
/**
|
|
347
|
+
* #743 — this machine's FACTORY in `repoAbs`, from `.github/factories.yml` (#739) as committed on
|
|
348
|
+
* TRUNK — never the checkout's working tree or the branch being worked on, so no branch can name its
|
|
349
|
+
* own machine into a factory (CONVENTIONS §5, *Factories*). The machine is looked up by its LABEL
|
|
350
|
+
* (`branchName.machineLabel(HOST)` — `Box_A.local` → `box-a`), the same name the claim lock's
|
|
351
|
+
* `Machine:` trailer and a `branchPrefix: machine` branch carry.
|
|
352
|
+
*
|
|
353
|
+
* Returns `{ id, reason }`: `id` '' when there is no file (one team, nothing to name), the file is
|
|
354
|
+
* invalid (fail closed — it names nobody), or it does not list this machine. Read once per repo per
|
|
355
|
+
* process: one `git show`, and the answer cannot change under a running command.
|
|
356
|
+
*/
|
|
357
|
+
const _factoryCache = new Map();
|
|
358
|
+
function factoryFor(repoAbs) {
|
|
359
|
+
if (_factoryCache.has(repoAbs)) return _factoryCache.get(repoAbs);
|
|
360
|
+
const label = branchName.machineLabel(HOST);
|
|
361
|
+
let out = { id: '', reason: 'no-file', machine: label };
|
|
362
|
+
const trunk = resolveTrunk(repoAbs, projectDoc(repoAbs));
|
|
363
|
+
if (trunk) {
|
|
364
|
+
let remote = null;
|
|
365
|
+
try { remote = git.remoteFor(repoAbs); } catch (_) { remote = null; }
|
|
366
|
+
const refs = [trunk, ...(remote ? [`${remote}/${trunk}`] : [])];
|
|
367
|
+
let text = null;
|
|
368
|
+
for (const ref of refs) {
|
|
369
|
+
const r = git.git(['show', `${ref}:${factories.PATH}`], repoAbs);
|
|
370
|
+
if (r.ok) { text = r.stdout; out.ref = ref; break; }
|
|
371
|
+
}
|
|
372
|
+
if (text !== null) {
|
|
373
|
+
const parsed = factories.parseFactories(text);
|
|
374
|
+
const id = parsed.valid ? factories.factoryOfMachine(parsed, label) : null;
|
|
375
|
+
out = id ? { ...out, id, reason: 'listed' }
|
|
376
|
+
: { ...out, reason: parsed.valid ? 'unlisted' : 'invalid', findings: parsed.findings || [] };
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
_factoryCache.set(repoAbs, out);
|
|
380
|
+
return out;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** #743 — the factory id a claim/hand-off written from here names, or ''. Warns once when trunk HAS a
|
|
384
|
+
* factories file that names nobody for this machine — a claim then names no factory, and a reader
|
|
385
|
+
* degrades to comparing it by login and machine alone. */
|
|
386
|
+
const _factoryWarned = new Set();
|
|
387
|
+
function myFactory(repoAbs) {
|
|
388
|
+
const f = factoryFor(repoAbs);
|
|
389
|
+
if ((f.reason === 'unlisted' || f.reason === 'invalid') && !_factoryWarned.has(repoAbs)) {
|
|
390
|
+
_factoryWarned.add(repoAbs);
|
|
391
|
+
warn(f.reason === 'invalid'
|
|
392
|
+
? `${factories.PATH} on ${f.ref} is invalid (${(f.findings || [])[0] || 'see colab audit'}) — it names no factory, so this claim names none (#743)`
|
|
393
|
+
: `${factories.PATH} on ${f.ref} lists no factory for machine "${f.machine}" — this claim names no factory (#743)`);
|
|
394
|
+
}
|
|
395
|
+
return f.id;
|
|
396
|
+
}
|
|
397
|
+
|
|
343
398
|
/**
|
|
344
399
|
* Resolve the session id for this invocation: --session flag > COLAB_SESSION env >
|
|
345
400
|
* a DERIVED person identity (#528) > '' (absent, never an error). Free-form — any stable id for
|
|
@@ -545,12 +600,13 @@ function wtStatus(wt) { return (wt && wt.status) || 'running'; }
|
|
|
545
600
|
* supplies what the codec deliberately does not hold — the clock and the machine digest. `-` stands
|
|
546
601
|
* for "no branch"/"no worktree" (#53, it used to be the word `trunk`). `host` is the raw hostname
|
|
547
602
|
* where the destination may name it, the `h:` token where it may not (#369, `commentHost`); the
|
|
548
|
-
* comparable identity is the machine digest beside it (#327), omitted when no id resolved.
|
|
603
|
+
* comparable identity is the machine digest beside it (#327), omitted when no id resolved. `factory`
|
|
604
|
+
* (#743) is this machine's factory from trunk's `.github/factories.yml`, omitted when none is named.
|
|
549
605
|
*/
|
|
550
|
-
function claimCommentBody(wtName, branch, session, sessionName, host = HOST) {
|
|
606
|
+
function claimCommentBody(wtName, branch, session, sessionName, host = HOST, factory = '') {
|
|
551
607
|
return codec.encodeClaim({
|
|
552
608
|
worktree: wtName, branch, host, at: nowISO(),
|
|
553
|
-
machine: machine.machineToken(myMachineId()) || '', session, sessionName,
|
|
609
|
+
machine: machine.machineToken(myMachineId()) || '', factory, session, sessionName,
|
|
554
610
|
});
|
|
555
611
|
}
|
|
556
612
|
|
|
@@ -765,9 +821,9 @@ function settleTrackerPending(repoAbs, nums, missed, owner) {
|
|
|
765
821
|
* login+host is invisible to the check above. Read the comments too and look for exactly that.
|
|
766
822
|
* A read failure (null) is skipped, never treated as free.
|
|
767
823
|
*/
|
|
768
|
-
function ghClaimConflicts(repoAbs, nums, myLogin, myHost, mySession, comps, myMachine = null) {
|
|
824
|
+
function ghClaimConflicts(repoAbs, nums, myLogin, myHost, mySession, comps, myMachine = null, myFactoryId = '') {
|
|
769
825
|
comps = comps || claimIdentity.DEFAULT_COMPONENTS;
|
|
770
|
-
const me = { login: myLogin, host: myHost, session: mySession || '', machine: myMachine || '' };
|
|
826
|
+
const me = { login: myLogin, host: myHost, session: mySession || '', machine: myMachine || '', factory: myFactoryId || '' };
|
|
771
827
|
const out = [];
|
|
772
828
|
for (const num of nums) {
|
|
773
829
|
const info = git.ghIssueView(repoAbs, num, ['assignees', 'labels', 'comments']);
|
|
@@ -792,6 +848,11 @@ function ghClaimConflicts(repoAbs, nums, myLogin, myHost, mySession, comps, myMa
|
|
|
792
848
|
// different place to hold work in, while a session knob only ever distinguished co-tenants.
|
|
793
849
|
{
|
|
794
850
|
const live = liveClaimComments(info.comments || [], comps);
|
|
851
|
+
// #743: OUR OWN login held by ANOTHER FACTORY — two teams on one forge login (#739). The
|
|
852
|
+
// assignee set says nothing about it, and the machine check below may not either (two teams'
|
|
853
|
+
// machines can share a hostname). Checked first: it is the more specific finding.
|
|
854
|
+
const otherFactory = live.find((c) => c.login === myLogin && !claimIdentity.sameFactory(c, me));
|
|
855
|
+
if (otherFactory) { out.push({ num, assignees, otherFactory }); continue; }
|
|
795
856
|
const other = live.find((c) => c.login === myLogin && !claimIdentity.sameHost(c, me));
|
|
796
857
|
if (other) { out.push({ num, assignees, otherMachine: other }); continue; }
|
|
797
858
|
}
|
|
@@ -839,7 +900,11 @@ function printRefusal(localConf, ghConf, remoteConf = []) {
|
|
|
839
900
|
` #${c.num} local: worktree "${h.worktree || '-'}" · branch ${h.branch || '-'} · host ${h.host}${sess} · since ${String(h.created).slice(0, 10)}\n`);
|
|
840
901
|
}
|
|
841
902
|
for (const c of ghConf) {
|
|
842
|
-
if (c.
|
|
903
|
+
if (c.otherFactory) {
|
|
904
|
+
const o = c.otherFactory;
|
|
905
|
+
const id = displayIdentity(o.sessionName, o.session);
|
|
906
|
+
process.stderr.write(` #${c.num} GitHub: live claim comment by factory ${o.factory} (host ${o.host}${id ? ` · session ${id}` : ''}) — same account, another factory (#743)\n`);
|
|
907
|
+
} else if (c.otherMachine) {
|
|
843
908
|
const o = c.otherMachine;
|
|
844
909
|
const id = displayIdentity(o.sessionName, o.session);
|
|
845
910
|
process.stderr.write(` #${c.num} GitHub: live claim comment from another machine (host ${o.host}${id ? ` · session ${id}` : ''}) — same account (#325)\n`);
|
|
@@ -876,7 +941,9 @@ function printTakeover(localConf, ghConf, remoteConf = []) {
|
|
|
876
941
|
print(` --force: taking over #${c.num} from worktree "${h.worktree || '-'}" (host ${h.host}${sess}, since ${String(h.created).slice(0, 10)})`);
|
|
877
942
|
}
|
|
878
943
|
for (const c of ghConf) {
|
|
879
|
-
if (c.
|
|
944
|
+
if (c.otherFactory) {
|
|
945
|
+
print(` --force: taking over #${c.num} from factory ${c.otherFactory.factory}'s claim under this account (host ${c.otherFactory.host}, #743)`);
|
|
946
|
+
} else if (c.otherMachine) {
|
|
880
947
|
print(` --force: taking over #${c.num} from this account's claim on another machine (host ${c.otherMachine.host})`);
|
|
881
948
|
} else if (c.cotenant) {
|
|
882
949
|
const id = displayIdentity(c.cotenant.sessionName, c.cotenant.session) || c.cotenant.identity;
|
|
@@ -889,9 +956,113 @@ function printTakeover(localConf, ghConf, remoteConf = []) {
|
|
|
889
956
|
}
|
|
890
957
|
}
|
|
891
958
|
|
|
959
|
+
/**
|
|
960
|
+
* #744 — `.github/factories.yml` as committed on trunk (`<remote>/<trunk>`, else local `<trunk>`),
|
|
961
|
+
* fetched first so a file landed since this clone's last fetch is not missed. Never the checkout's
|
|
962
|
+
* or a branch's copy: a branch that could edit the file could make itself the holder's factory.
|
|
963
|
+
* `{ present, ref, parsed? }`.
|
|
964
|
+
*/
|
|
965
|
+
function factoriesAtTrunk(repoAbs) {
|
|
966
|
+
const trunk = resolveTrunk(repoAbs, projectDoc(repoAbs));
|
|
967
|
+
if (!trunk) return { present: false, ref: null };
|
|
968
|
+
let remote = null;
|
|
969
|
+
try { remote = git.claimRemote(repoAbs); } catch (_) { remote = null; }
|
|
970
|
+
if (remote) git.git(['fetch', '--quiet', '--no-tags', remote, trunk], repoAbs, { timeoutMs: 60_000 });
|
|
971
|
+
for (const ref of [remote ? `${remote}/${trunk}` : null, trunk].filter(Boolean)) {
|
|
972
|
+
if (!git.git(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`], repoAbs).ok) continue;
|
|
973
|
+
const r = git.git(['show', `${ref}:${factoriesLib.PATH}`], repoAbs);
|
|
974
|
+
if (!r.ok) return { present: false, ref };
|
|
975
|
+
return { present: true, ref, parsed: factoriesLib.parseFactories(r.stdout) };
|
|
976
|
+
}
|
|
977
|
+
return { present: false, ref: null };
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* #744 — the cross-factory bar on a `--force` takeover, shared by `colab claim` and `colab worktree
|
|
982
|
+
* new --issues`. Runs only once `--force` was given over a refusal. For every issue whose holder is
|
|
983
|
+
* not proven to be this machine's factory (tools/lib/claim-takeover.js `isCrossFactory`), the
|
|
984
|
+
* takeover needs the holder STALE (no activity for claimTakeover.STALE_DAYS days) AND a human
|
|
985
|
+
* (`COLAB_HUMAN=1` with `--answered-by`). No factories file on trunk → `{ ok: true, cross: [] }`,
|
|
986
|
+
* exactly the behaviour before this. Prints its own refusal; the caller only returns 1.
|
|
987
|
+
*/
|
|
988
|
+
function crossFactoryGate(repoAbs, nums, { localConf = [], ghConf = [], remoteConf = [], answeredBy = null } = {}) {
|
|
989
|
+
const file = factoriesAtTrunk(repoAbs);
|
|
990
|
+
if (!file.present) return { ok: true, cross: [] };
|
|
991
|
+
const mine = claimTakeover.factoryOfMachineName(file.parsed, HOST);
|
|
992
|
+
const colabHuman = process.env.COLAB_HUMAN === '1';
|
|
993
|
+
const nowMs = Date.now();
|
|
994
|
+
const cross = [];
|
|
995
|
+
const refused = [];
|
|
996
|
+
for (const num of nums) {
|
|
997
|
+
const holders = [
|
|
998
|
+
...remoteConf.filter((c) => c.num === num).map((c) => ({ kind: 'remote', c })),
|
|
999
|
+
...ghConf.filter((c) => c.num === num).map((c) => ({ kind: 'gh', c })),
|
|
1000
|
+
];
|
|
1001
|
+
if (!holders.length) continue; // only this machine's own state holds it (or nothing does)
|
|
1002
|
+
const factoriesOf = holders.map((h) => claimTakeover.holderFactory(file.parsed, h.kind, h.c, mine));
|
|
1003
|
+
if (!claimTakeover.isCrossFactory(file, mine, factoriesOf)) continue;
|
|
1004
|
+
const times = [];
|
|
1005
|
+
for (const { kind, c } of holders) {
|
|
1006
|
+
if (kind === 'remote') {
|
|
1007
|
+
const ref = c.lock ? git.claimLockRef(num) : c.claimRef ? git.claimRef(c.branch) : `refs/heads/${c.branch}`;
|
|
1008
|
+
times.push(git.remoteRefCommitTime(repoAbs, c.remote, ref, c.fullSha || c.sha));
|
|
1009
|
+
} else {
|
|
1010
|
+
const cm = claimTakeover.holderComment(c);
|
|
1011
|
+
times.push(cm && cm.at ? Date.parse(cm.at) : null);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
const last = claimTakeover.lastActivity(times);
|
|
1015
|
+
const st = claimTakeover.staleness(last, nowMs);
|
|
1016
|
+
const holderFactory = [...new Set(factoriesOf.filter(Boolean))].join(', ') || null;
|
|
1017
|
+
const v = claimTakeover.takeoverVerdict({ colabHuman, answeredBy, stale: st.stale });
|
|
1018
|
+
const row = { num, mine, holderFactory, last, idleDays: st.idleDays, missing: v.missing, valid: !!(file.parsed && file.parsed.valid) };
|
|
1019
|
+
cross.push(row);
|
|
1020
|
+
if (!v.ok) refused.push(row);
|
|
1021
|
+
}
|
|
1022
|
+
if (refused.length) {
|
|
1023
|
+
process.stderr.write(`✗ Refusing --force — taking over another factory's claim (${factoriesLib.PATH} on ${file.ref}) needs both a stale holder and a human (#744):\n`);
|
|
1024
|
+
for (const r of refused) {
|
|
1025
|
+
const who = r.valid ? `factory ${r.holderFactory || '(unknown — no record ties the holder to a factory)'}` : `a holder (the factories file is INVALID, so nobody is proven your factory: ${file.parsed.findings[0]})`;
|
|
1026
|
+
const since = r.last ? `last activity ${new Date(r.last).toISOString().slice(0, 10)} (${r.idleDays} day${r.idleDays === 1 ? '' : 's'} ago)` : 'last activity unreadable (never treated as stale)';
|
|
1027
|
+
process.stderr.write(` #${r.num} held by ${who}; this machine is ${r.mine ? `factory ${r.mine}` : 'in no factory'}; ${since}\n`);
|
|
1028
|
+
if (r.missing.includes('stale')) process.stderr.write(` not stale: a takeover needs no activity on the claim for ${claimTakeover.STALE_DAYS} days — ask its holder to release it instead\n`);
|
|
1029
|
+
if (r.missing.includes('human')) process.stderr.write(' needs a human: COLAB_HUMAN=1 colab claim <N> --force --answered-by "<your name>" (no field, flag or project.yml value lowers this bar)\n');
|
|
1030
|
+
}
|
|
1031
|
+
return { ok: false, cross };
|
|
1032
|
+
}
|
|
1033
|
+
for (const r of cross) {
|
|
1034
|
+
print(` --force: #${r.num} is another factory's claim (${r.holderFactory || 'holder unproven'}), idle ${r.idleDays} days — taken over by ${r.mine ? `factory ${r.mine}` : 'this machine'}, answered by ${answeredBy} (COLAB_HUMAN=1, #744)`);
|
|
1035
|
+
}
|
|
1036
|
+
return { ok: true, cross };
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
/**
|
|
1040
|
+
* #744 — after a `--force` takeover has taken the locks: remove the displaced holder's legacy claim
|
|
1041
|
+
* refs (`refs/claims/<branch>`, #550). The lock itself was already overwritten under a lease on the
|
|
1042
|
+
* holder's sha; a real branch is never deleted — it carries commits. A cross-factory takeover also
|
|
1043
|
+
* leaves one comment on the issue naming who answered for it. Best effort, like every other
|
|
1044
|
+
* release-side write: a failure warns with the command.
|
|
1045
|
+
*/
|
|
1046
|
+
function afterForcedTakeover(repoAbs, remoteConf, cross, answeredBy) {
|
|
1047
|
+
const seen = new Set();
|
|
1048
|
+
for (const c of remoteConf || []) {
|
|
1049
|
+
if (!c.claimRef || seen.has(c.branch)) continue;
|
|
1050
|
+
seen.add(c.branch);
|
|
1051
|
+
const r = git.deleteClaimRef(repoAbs, c.remote, c.branch);
|
|
1052
|
+
if (r.ok && !r.absent) print(` removed the displaced holder's claim ref ${c.remote} ${git.claimRef(c.branch)} (#744)`);
|
|
1053
|
+
else if (!r.ok) warnDeferred(`could not remove the displaced holder's claim ref ${c.remote} ${git.claimRef(c.branch)} (${String(r.stderr || '').split('\n')[0]}) — delete it by hand: git push ${c.remote} --delete ${git.claimRef(c.branch)}`);
|
|
1054
|
+
}
|
|
1055
|
+
for (const r of cross || []) {
|
|
1056
|
+
const body = `⚠️ Cross-factory takeover (#744): this claim, held by ${r.holderFactory ? `factory \`${r.holderFactory}\`` : 'a holder no record ties to a factory'} ` +
|
|
1057
|
+
`with no activity for ${r.idleDays} days, was taken over by ${r.mine ? `factory \`${r.mine}\`` : 'a machine in no factory'} — answered by ${answeredBy} (COLAB_HUMAN=1).`;
|
|
1058
|
+
const c = git.ghIssueComment(repoAbs, r.num, body);
|
|
1059
|
+
if (!c.ok) warn(`could not post the takeover note on #${r.num} (${String(c.stderr || '').split('\n')[0] || c.code})`);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
|
|
892
1063
|
/** Post the claim comment (best-effort: a failure warns but never fails the claim). */
|
|
893
1064
|
function postClaimComment(repoAbs, num, wtName, branch, session, sessionName) {
|
|
894
|
-
const r = git.ghIssueComment(repoAbs, num, claimCommentBody(wtName, branch, session, sessionName, commentHost(repoAbs)));
|
|
1065
|
+
const r = git.ghIssueComment(repoAbs, num, claimCommentBody(wtName, branch, session, sessionName, commentHost(repoAbs), myFactory(repoAbs)));
|
|
895
1066
|
if (!r.ok) warn(`could not post claim comment on #${num} (${r.stderr.split('\n')[0] || r.code}) — claim stands`);
|
|
896
1067
|
}
|
|
897
1068
|
|
|
@@ -1004,7 +1175,7 @@ function commentAndTieBreak(repoAbs, nums, owner) {
|
|
|
1004
1175
|
postClaimComment(repoAbs, num, owner.wtName, owner.branch, owner.session, owner.sessionName);
|
|
1005
1176
|
const info = git.ghIssueView(repoAbs, num, ['comments']);
|
|
1006
1177
|
if (!info || !Array.isArray(info.comments)) continue; // can't read comments → keep the claim
|
|
1007
|
-
const verdict = tieBreakVerdict(info.comments, owner.myLogin, HOST, owner.session, comps, myMachineId());
|
|
1178
|
+
const verdict = tieBreakVerdict(info.comments, owner.myLogin, HOST, owner.session, comps, myMachineId(), myFactory(repoAbs));
|
|
1008
1179
|
if (verdict.lost) {
|
|
1009
1180
|
yieldIssue(repoAbs, num, verdict.winner, owner.myLogin, owner.session || null);
|
|
1010
1181
|
const w = verdict.winner;
|
|
@@ -1096,12 +1267,20 @@ Options:
|
|
|
1096
1267
|
(never probed — a human lead only). Default: auto-detect (an agent session's
|
|
1097
1268
|
long-lived process, verified alive + a proven ancestor; else the parent shell,
|
|
1098
1269
|
exactly as before). Also settable via COLAB_PLACE_PID.
|
|
1099
|
-
--force take over a claim held by another worktree / GitHub user (logged, never silent)
|
|
1270
|
+
--force take over a claim held by another worktree / GitHub user (logged, never silent).
|
|
1271
|
+
The displaced holder's legacy claim ref (refs/claims/<branch>) is removed; its
|
|
1272
|
+
lock is overwritten; a branch with commits is never deleted (#744).
|
|
1273
|
+
ANOTHER FACTORY's claim (.github/factories.yml on trunk — any foreign holder not
|
|
1274
|
+
proven to be this machine's factory, and every holder when the file is invalid)
|
|
1275
|
+
needs BOTH: no activity on the claim for 5 days (the newest of the commits on
|
|
1276
|
+
its lock, claim ref or branch and its claim comments) AND a human — COLAB_HUMAN=1
|
|
1277
|
+
with --answered-by. No factories file → unchanged (#744).
|
|
1278
|
+
--answered-by <n> with COLAB_HUMAN=1 and --force: the human who answers for a cross-factory takeover
|
|
1100
1279
|
`;
|
|
1101
1280
|
|
|
1102
1281
|
function cmdClaim(argv) {
|
|
1103
1282
|
const opts = parseArgs(argv, {
|
|
1104
|
-
values: { '--repo': 'repo', '--worktree': 'worktree', '--branch': 'branch', '--session': 'session', '--session-name': 'sessionName', '--pid': 'pid' },
|
|
1283
|
+
values: { '--repo': 'repo', '--worktree': 'worktree', '--branch': 'branch', '--session': 'session', '--session-name': 'sessionName', '--pid': 'pid', '--answered-by': 'answeredBy' },
|
|
1105
1284
|
flags: { '--force': 'force', '-h': 'help', '--help': 'help' },
|
|
1106
1285
|
});
|
|
1107
1286
|
if (opts.help || opts._.length === 0) return print(HELP_CLAIM);
|
|
@@ -1180,10 +1359,14 @@ function cmdClaim(argv) {
|
|
|
1180
1359
|
if (remoteCheck.mode === 'no-remote') warn('no git remote — this claim is recorded on this machine only; no other machine can see it');
|
|
1181
1360
|
const remoteConf = remoteCheck.conflicts;
|
|
1182
1361
|
const localConf = localClaimConflicts(st0, repoAbs, nums, wtName);
|
|
1183
|
-
const ghConf = gh ? ghClaimConflicts(repoAbs, nums, myLogin, HOST, session, comps, myMachineId()) : [];
|
|
1362
|
+
const ghConf = gh ? ghClaimConflicts(repoAbs, nums, myLogin, HOST, session, comps, myMachineId(), myFactory(repoAbs)) : [];
|
|
1184
1363
|
if (!gh && remoteCheck.mode === 'ok') warn(`gh not usable here (${ghUnusableWhy(repoAbs)}) — refusal checked the remote and this machine; the tracker half will be PENDING`);
|
|
1364
|
+
let crossTakeover = [];
|
|
1185
1365
|
if (remoteConf.length || localConf.length || ghConf.length) {
|
|
1186
1366
|
if (!opts.force) { printRefusal(localConf, ghConf, remoteConf); return 1; }
|
|
1367
|
+
const gate = crossFactoryGate(repoAbs, nums, { localConf, ghConf, remoteConf, answeredBy: opts.answeredBy || null });
|
|
1368
|
+
if (!gate.ok) return 1;
|
|
1369
|
+
crossTakeover = gate.cross;
|
|
1187
1370
|
printTakeover(localConf, ghConf, remoteConf);
|
|
1188
1371
|
}
|
|
1189
1372
|
|
|
@@ -1238,6 +1421,7 @@ function cmdClaim(argv) {
|
|
|
1238
1421
|
if (lockTake.taken.includes(num)) print(` took claim lock ${remoteCheck.remote} ${l.ref} (#741)`);
|
|
1239
1422
|
else if (l.adopted) print(` claim lock ${remoteCheck.remote} ${l.ref} was already taken on this machine for this work — adopted (#741)`);
|
|
1240
1423
|
}
|
|
1424
|
+
if (opts.force && (remoteConf.length || crossTakeover.length)) afterForcedTakeover(repoAbs, remoteConf, crossTakeover, opts.answeredBy || null);
|
|
1241
1425
|
|
|
1242
1426
|
// #389: measured outside the lock (git, not state) — see the attach branch inside the mutation.
|
|
1243
1427
|
const existingDir = wtName ? existingWorktreeFor(repoAbs, wtName, branch) : null;
|
|
@@ -6048,7 +6232,9 @@ dependency symlinking, dev-server restarts) live in OPTIONAL repo hooks, not her
|
|
|
6048
6232
|
--session-name <s> short human label for tables/messages (env COLAB_SESSION_NAME)
|
|
6049
6233
|
--pid <n|none> the new worktree's place-claim liveness anchor (#288) — same meaning as
|
|
6050
6234
|
\`colab claim\`'s --pid; default: auto-detect (env COLAB_PLACE_PID too)
|
|
6051
|
-
--force take over issues already claimed by another worktree / GitHub user
|
|
6235
|
+
--force take over issues already claimed by another worktree / GitHub user —
|
|
6236
|
+
another factory's claim needs a 5-day-stale holder AND COLAB_HUMAN=1 with
|
|
6237
|
+
--answered-by <name>, exactly as 'colab claim --force' (see colab claim -h, #744)
|
|
6052
6238
|
Claimed issues are ENFORCED: if --issues names an issue already held (locally on another
|
|
6053
6239
|
worktree, or on GitHub by someone else) the command REFUSES before building anything,
|
|
6054
6240
|
unless --force. On success each issue gets a "🔒 Claimed" comment + the tie-break runs;
|
|
@@ -6250,7 +6436,7 @@ function uncommittedWork(wtPath) {
|
|
|
6250
6436
|
|
|
6251
6437
|
function cmdWorktreeNew(argv) {
|
|
6252
6438
|
const opts = parseArgs(argv, {
|
|
6253
|
-
values: { '--issues': 'issues', '--ports': 'ports', '--range': 'range', '--at': 'at', '--name': 'name', '--trunk': 'trunk', '--base': 'base', '--repo': 'repo', '--session': 'session', '--session-name': 'sessionName', '--pid': 'pid' },
|
|
6439
|
+
values: { '--issues': 'issues', '--ports': 'ports', '--range': 'range', '--at': 'at', '--name': 'name', '--trunk': 'trunk', '--base': 'base', '--repo': 'repo', '--session': 'session', '--session-name': 'sessionName', '--pid': 'pid', '--answered-by': 'answeredBy' },
|
|
6254
6440
|
aliases: { '--issue': '--issues' },
|
|
6255
6441
|
flags: { '--force': 'force', '-h': 'help', '--help': 'help' },
|
|
6256
6442
|
});
|
|
@@ -6296,6 +6482,7 @@ function cmdWorktreeNew(argv) {
|
|
|
6296
6482
|
|
|
6297
6483
|
// ---- REFUSAL: don't build a worktree around issues someone else already holds ----
|
|
6298
6484
|
let remoteCheck = null;
|
|
6485
|
+
let crossTakeover = [];
|
|
6299
6486
|
if (issues.length) {
|
|
6300
6487
|
const st0 = state.loadState();
|
|
6301
6488
|
// #325: the remote first — the branch on it is the claim record every machine reads.
|
|
@@ -6303,10 +6490,13 @@ function cmdWorktreeNew(argv) {
|
|
|
6303
6490
|
if (remoteCheck.mode === 'unreachable') { printRemoteUnreachable(remoteCheck, 'worktree and its claims'); return 1; }
|
|
6304
6491
|
if (remoteCheck.mode === 'no-remote') warn('no git remote — these claims are recorded on this machine only; no other machine can see them');
|
|
6305
6492
|
const localConf = localClaimConflicts(st0, repoAbs, issues, name);
|
|
6306
|
-
const ghConf = gh ? ghClaimConflicts(repoAbs, issues, myLogin, HOST, session, comps, myMachineId()) : [];
|
|
6493
|
+
const ghConf = gh ? ghClaimConflicts(repoAbs, issues, myLogin, HOST, session, comps, myMachineId(), myFactory(repoAbs)) : [];
|
|
6307
6494
|
if (!gh && remoteCheck.mode === 'ok') warn(`gh not usable here (${ghUnusableWhy(repoAbs)}) — refusal checked the remote and this machine; the tracker half will be PENDING`);
|
|
6308
6495
|
if (remoteCheck.conflicts.length || localConf.length || ghConf.length) {
|
|
6309
6496
|
if (!opts.force) { printRefusal(localConf, ghConf, remoteCheck.conflicts); return 1; }
|
|
6497
|
+
const gate = crossFactoryGate(repoAbs, issues, { localConf, ghConf, remoteConf: remoteCheck.conflicts, answeredBy: opts.answeredBy || null });
|
|
6498
|
+
if (!gate.ok) return 1;
|
|
6499
|
+
crossTakeover = gate.cross;
|
|
6310
6500
|
printTakeover(localConf, ghConf, remoteCheck.conflicts);
|
|
6311
6501
|
}
|
|
6312
6502
|
}
|
|
@@ -6410,6 +6600,7 @@ function cmdWorktreeNew(argv) {
|
|
|
6410
6600
|
else if (l.adopted) print(` claim lock ${remoteCheck.remote} ${l.ref} was already taken on this machine for this work — adopted (#741)`);
|
|
6411
6601
|
else print(` claim lock ${remoteCheck.remote} ${l.ref} is already this machine's — kept`);
|
|
6412
6602
|
}
|
|
6603
|
+
if (opts.force && remoteCheck && (remoteCheck.conflicts.length || crossTakeover.length)) afterForcedTakeover(repoAbs, remoteCheck.conflicts, crossTakeover, opts.answeredBy || null);
|
|
6413
6604
|
|
|
6414
6605
|
// How far behind trunk the line is, as INFORMATION — never a threshold. A long-lived line is
|
|
6415
6606
|
// expected to diverge; a refusal (or a warning with a number in it) would fire on every healthy
|
|
@@ -11403,8 +11594,8 @@ function ciCureTrailerLine(cureVerdict, branch, trunk) {
|
|
|
11403
11594
|
return `CI-Cure: branch ${branch} over-red ${trunk}@${shortSha(cureVerdict.redSha)} evidence ${shortSha(cureVerdict.evidenceSha)}${via}${admittedSuffix}${progressSuffix}`;
|
|
11404
11595
|
}
|
|
11405
11596
|
|
|
11406
|
-
const HELP_SHIP = `colab ship [--repo <path>] [--worktree <name> | --branch <br> | --direct] [--message "<msg>"] [--refs <N[,M]>] [--keep-worktree] [--delete-branch | --keep-branch] [--adopt | --handoff <
|
|
11407
|
-
colab ship --batch <b1,b2[@<handoff-
|
|
11597
|
+
const HELP_SHIP = `colab ship [--repo <path>] [--worktree <name> | --branch <br> | --direct] [--message "<msg>"] [--refs <N[,M]>] [--keep-worktree] [--delete-branch | --keep-branch] [--adopt | --handoff <ref>] [--answered-by <name>] [--session <id>] [--session-name <s>] [--dry] [--json]
|
|
11598
|
+
colab ship --batch <b1,b2[@<handoff-ref>][,…]> [--split] [--onto ship-batch/<sha7>] [--repo <path>] [--keep-worktree] [--delete-branch | --keep-branch] [--session <id>] [--session-name <s>] [--dry [--json]]
|
|
11408
11599
|
|
|
11409
11600
|
The ONE sanctioned door for code-wrap Phase B: squash-merge a session branch into the BASE IT WAS
|
|
11410
11601
|
CUT FROM — trunk for an ordinary session, or the declared integration line recorded on its worktree
|
|
@@ -11516,19 +11707,23 @@ here, or pass --adopt if it genuinely has no issue — the squash then carries a
|
|
|
11516
11707
|
still a legitimate zero. --adopt never bypasses a branch that names issues.
|
|
11517
11708
|
|
|
11518
11709
|
A HAND-OFF (#578) is the non-force door for a branch whose claim lives on ANOTHER machine:
|
|
11519
|
-
\`colab ship --branch <br> --handoff <
|
|
11520
|
-
|
|
11710
|
+
\`colab ship --branch <br> --handoff <ref>\`, where <ref> names the executor's hand-off comment
|
|
11711
|
+
forge-neutrally — \`<forge-host>/<owner>/<repo>#<N>@comment:<id>\` (#740) — or by its URL
|
|
11712
|
+
(…/issues/<N>#issuecomment-<id>, kept as an alias). Either is resolved through the repo's tracker
|
|
11713
|
+
adapter: the GitHub tracker, or on a Forgejo remote the forge engine (reads only — colab writes no
|
|
11714
|
+
claim comment there, #678, so the claim below must come from the adopter's tracker layer). With zero claims here, ship takes the issue set from the branch
|
|
11521
11715
|
name's trailing run once the hand-off proves all of: the comment is on one of THIS repo's issues,
|
|
11522
11716
|
one the branch carries; it names the branch and a sha that is the remote branch's CURRENT head (a
|
|
11523
11717
|
branch that moved after its hand-off needs a new one — except by base-sync merges, #579, below); and every issue the branch carries has a
|
|
11524
11718
|
live \`🔒 Claimed\` comment on that branch, posted by the hand-off's author before it. Nothing is
|
|
11525
11719
|
claimed or taken over here: the executor keeps its claim, worktree and branch until it confirms
|
|
11526
|
-
the land, the shipped branch is kept, the squash carries \`Colab-Handoff: <
|
|
11720
|
+
the land, the shipped branch is kept, the squash carries \`Colab-Handoff: <ref> @ <sha>\` (always the
|
|
11721
|
+
neutral form, whichever one was given), and each
|
|
11527
11722
|
🚢 comment names the hand-off. Any check failing refuses (exit 1); --force is never involved, and
|
|
11528
11723
|
the human takeover (\`colab claim --force\`) stays the only other way in. Not with --adopt
|
|
11529
11724
|
or --direct, and not when this machine already holds a claim on the branch.
|
|
11530
11725
|
|
|
11531
|
-
IN A BATCH (#591) the hand-off rides its member: \`--batch b1,b2@<
|
|
11726
|
+
IN A BATCH (#591) the hand-off rides its member: \`--batch b1,b2@<ref>\` (split on the first @).
|
|
11532
11727
|
That member is verified by this SAME door — same checks, same refusal text, which drops it from
|
|
11533
11728
|
the batch while the rest build — then joins the combined run with no sync of its own; its squash
|
|
11534
11729
|
carries the Colab-Handoff trailer, and the land reads the door back from that commit. Repeat the
|
|
@@ -11540,7 +11735,7 @@ the base in, push) — and the hand-off still verifies, because the commits betw
|
|
|
11540
11735
|
sha and the new head are each a PURE base-sync merge: two parents, the second already on the base,
|
|
11541
11736
|
and a tree equal to git's own conflict-free merge of the two. A fix-up, a rebase, or a merge whose
|
|
11542
11737
|
conflict was resolved by hand is not one, and still needs a new hand-off from the executor. The
|
|
11543
|
-
trailer then reads \`Colab-Handoff: <
|
|
11738
|
+
trailer then reads \`Colab-Handoff: <ref> @ <handed-off sha> (synced to <head> by N base merge(s))\`.
|
|
11544
11739
|
|
|
11545
11740
|
UNATTACHED CLAIMS (#319). A claim taken with no --worktree and no --branch (\`colab claim <N>
|
|
11546
11741
|
--session <id>\`) is carried by a branch ship only when BOTH hold: its session equals this ship's
|
|
@@ -13638,7 +13833,7 @@ function cmdShipDryJson(opts) {
|
|
|
13638
13833
|
// #591: the verified hand-off (or its refusal), so `ship --batch` puts this member's
|
|
13639
13834
|
// Colab-Handoff trailer on its squash and words a refusal exactly as the single door does.
|
|
13640
13835
|
...(handoff ? { handoff: handoff.ok
|
|
13641
|
-
? { ok: true, url: handoff.url, sha: handoff.sha, handedOff: handoff.handedOff, syncMerges: handoff.syncMerges || 0 }
|
|
13836
|
+
? { ok: true, url: handoff.url, ref: handoff.ref, sha: handoff.sha, handedOff: handoff.handedOff, syncMerges: handoff.syncMerges || 0 }
|
|
13642
13837
|
: { ok: false, reason: handoff.reason, detail: handoff.detail } } : {}),
|
|
13643
13838
|
};
|
|
13644
13839
|
// #373: `ship --batch` reads each member through this SAME function — handed the body, not stdout.
|
|
@@ -14735,7 +14930,7 @@ function autonomyGatePayload(gate) {
|
|
|
14735
14930
|
|
|
14736
14931
|
/** The sha a branch name resolves to, local first, else origin's copy (#324's remote-only shape). */
|
|
14737
14932
|
/**
|
|
14738
|
-
* #578 — `--handoff <comment
|
|
14933
|
+
* #578 — `--handoff <ref>` (#740: neutral reference or comment URL): verify the executor's recorded hand-off and, when it holds, take
|
|
14739
14934
|
* the session's issue set from it (tools/lib/ship-handoff.js says what it must prove). Returns null
|
|
14740
14935
|
* without --handoff, the failing verdict on a refusal, the passing one after mutating `sess`.
|
|
14741
14936
|
*
|
|
@@ -14749,17 +14944,12 @@ function applyShipHandoff(repoAbs, sess, opts, trunk) {
|
|
|
14749
14944
|
throw new UserError(`--handoff is the door for a branch with NO claim on this machine, and this machine holds ${sess.issues.map((n) => '#' + n).join(' ')} ` +
|
|
14750
14945
|
`for ${sess.branch} — ship it without --handoff`);
|
|
14751
14946
|
}
|
|
14752
|
-
|
|
14753
|
-
|
|
14754
|
-
|
|
14755
|
-
|
|
14756
|
-
|
|
14757
|
-
|
|
14758
|
-
const j = JSON.parse(r.stdout);
|
|
14759
|
-
comment = { body: j.body || '', login: (j.user && j.user.login) || '', createdAt: j.created_at || '', htmlUrl: j.html_url || '' };
|
|
14760
|
-
} catch (_) { comment = null; }
|
|
14761
|
-
}
|
|
14762
|
-
}
|
|
14947
|
+
// #740: a neutral reference (<forge-host>/<owner>/<repo>#<N>@comment:<id>) or the comment's URL, both
|
|
14948
|
+
// resolved through the repo's tracker adapter — the Forgejo forge engine on a forge remote (#678), the
|
|
14949
|
+
// GitHub tracker otherwise — so no read below reaches for one forge's API by hand.
|
|
14950
|
+
const u = shipHandoff.parseHandoffRef(opts.handoff);
|
|
14951
|
+
const reader = forgeCi(repoAbs) || tracker.forRepo(repoAbs);
|
|
14952
|
+
const comment = u ? reader.commentView(u.commentId) : null;
|
|
14763
14953
|
// The head check must read the remote as it is NOW, not a tracking ref from whenever this clone last fetched.
|
|
14764
14954
|
const remote = git.remoteFor(repoAbs);
|
|
14765
14955
|
if (u && comment) git.git(['fetch', '--quiet', remote, `+refs/heads/${sess.branch}:refs/remotes/${remote}/${sess.branch}`], repoAbs);
|
|
@@ -14775,13 +14965,18 @@ function applyShipHandoff(repoAbs, sess, opts, trunk) {
|
|
|
14775
14965
|
const issueStates = {}; // #647: an issue closed before the hand-off needs no claim — read state too
|
|
14776
14966
|
if (u && comment) {
|
|
14777
14967
|
for (const n of shipguard.branchIssueNumbers(sess.branch)) {
|
|
14778
|
-
const info =
|
|
14968
|
+
const info = reader.issueView(n, ['comments', 'state', 'closedAt']);
|
|
14779
14969
|
claimsByIssue[n] = info ? liveClaimComments(info.comments || []).map((c) => ({ ...c })) : null;
|
|
14780
14970
|
if (info) issueStates[n] = { state: info.state || '', closedAt: info.closedAt || '' };
|
|
14781
14971
|
}
|
|
14782
14972
|
}
|
|
14783
14973
|
const v = shipHandoff.handoffVerdict({ url: opts.handoff, comment, branch: sess.branch, refs, claimsByIssue, syncChain,
|
|
14784
14974
|
issueStates, refNumbers: refsFlagNumbers(opts.refs) });
|
|
14975
|
+
if (!v.ok && v.reason === 'no-executor-claim' && reader.kind === 'forgejo') {
|
|
14976
|
+
// #740: reads only on a forge (#678) — colab posts no 🔒 claim comment there, so the claim this door
|
|
14977
|
+
// checks exists only where the adopter's own tracker layer writes one in colab's claim format.
|
|
14978
|
+
return { ...v, detail: `${v.detail}. On a ${reader.kind} remote colab writes no claim comment (#678): a hand-off verifies there only where the adopter's tracker layer posts the executor's 🔒 claim in colab's format` };
|
|
14979
|
+
}
|
|
14785
14980
|
if (!v.ok) return v;
|
|
14786
14981
|
sess.issues = v.issues;
|
|
14787
14982
|
sess.handoff = v;
|
|
@@ -14789,7 +14984,8 @@ function applyShipHandoff(repoAbs, sess, opts, trunk) {
|
|
|
14789
14984
|
sess.handoffRefs = new Set(v.refIssues || []);
|
|
14790
14985
|
// #372: the implementer is the executor that handed off — name it, never leave it reading as the shipper.
|
|
14791
14986
|
const claimed = v.issues.find((n) => !sess.handoffRefs.has(n));
|
|
14792
|
-
const ex = (claimsByIssue[claimed] || []).find((c) => c.branch === sess.branch && c.login === v.executor.login
|
|
14987
|
+
const ex = (claimsByIssue[claimed] || []).find((c) => c.branch === sess.branch && c.login === v.executor.login
|
|
14988
|
+
&& shipHandoff.sameFactory(c.factory, v.executor.factory)); // #743: the same login under another factory is another holder
|
|
14793
14989
|
if (ex && (ex.session || ex.sessionName)) sess.holder = { session: ex.session || '', sessionName: ex.sessionName || '' };
|
|
14794
14990
|
return v;
|
|
14795
14991
|
}
|
|
@@ -14870,7 +15066,7 @@ function cmdShip(argv) {
|
|
|
14870
15066
|
if (shippedBranch.conflictingFlags(opts)) throw new UserError('--delete-branch and --keep-branch contradict each other — pass one (see `colab ship --help`, #368)');
|
|
14871
15067
|
// #578: a hand-off names ONE branch; trunk-direct has no branch for it to name. #591: in a batch the
|
|
14872
15068
|
// hand-off rides its member (`--batch b1,b2@<url>`), so a bare --handoff beside --batch names no one.
|
|
14873
|
-
if (opts.handoff && opts.batch) throw new UserError('--handoff names one --branch ship; in a batch, attach it to its member: --batch <b1>,<b2>@<hand-off-
|
|
15069
|
+
if (opts.handoff && opts.batch) throw new UserError('--handoff names one --branch ship; in a batch, attach it to its member: --batch <b1>,<b2>@<hand-off-ref> (#591, see `colab ship --help`)');
|
|
14874
15070
|
if (opts.handoff && opts.direct) throw new UserError('--handoff applies to one --branch ship — not to --direct (see `colab ship --help`)');
|
|
14875
15071
|
if (opts.split && !opts.batch) throw new UserError('--split applies to a red combined run of --batch only (#557) — run `colab ship --batch <b1,b2,…> --split` with the members the red batch carries');
|
|
14876
15072
|
if (opts.onto && !opts.batch) throw new UserError('--onto applies to --batch only (#605) — run `colab ship --batch <b1,b2,…> --onto ship-batch/<sha7>`');
|
|
@@ -16331,7 +16527,7 @@ function cmdShipBatch(opts) {
|
|
|
16331
16527
|
const batchRead = { verifying: verifyRuns.parsePolicy(doc) };
|
|
16332
16528
|
const trunk = resolveTrunk(repoAbs, doc);
|
|
16333
16529
|
if (!trunk) throw new UserError('Could not determine trunk branch (set project.yml trunk:)');
|
|
16334
|
-
// #591: a member built on another machine names its hand-off inline — `<branch>@<hand-off-
|
|
16530
|
+
// #591: a member built on another machine names its hand-off inline — `<branch>@<hand-off-ref>` (#740).
|
|
16335
16531
|
const entries = shipHandoff.parseBatchEntries(opts.batch === true ? '' : opts.batch);
|
|
16336
16532
|
if (entries.errors.length) throw new UserError(`--batch: ${entries.errors.join('; ')}`);
|
|
16337
16533
|
const members = entries.members;
|
|
@@ -18071,6 +18267,44 @@ function cmdInstructionFiles(argv) {
|
|
|
18071
18267
|
return 0;
|
|
18072
18268
|
}
|
|
18073
18269
|
|
|
18270
|
+
const HELP_FACTORY = `colab factory [--repo <path>] [--json]
|
|
18271
|
+
|
|
18272
|
+
This machine's FACTORY in a repo (#743): the id \`.github/factories.yml\` (#739), as committed on
|
|
18273
|
+
TRUNK, lists this machine under — the id a 🔒 claim comment written from here carries
|
|
18274
|
+
(\`· factory \\\`<id>\\\`\`) and the one code-wrap's hand-off marker names (\`factory=<id>\`).
|
|
18275
|
+
The machine is looked up by its label (the hostname's first label, lower-cased, \`[a-z0-9-]\` only),
|
|
18276
|
+
the name the claim lock's \`Machine:\` trailer carries.
|
|
18277
|
+
|
|
18278
|
+
exit 0 the file lists this machine; prints the id
|
|
18279
|
+
exit 1 no factories file on trunk (one team — name no factory), the file is invalid
|
|
18280
|
+
(it names nobody), or it does not list this machine — prints why, on stderr
|
|
18281
|
+
--json { factory, reason: listed|no-file|invalid|unlisted, machine, ref, findings? }
|
|
18282
|
+
`;
|
|
18283
|
+
|
|
18284
|
+
function cmdFactory(argv) {
|
|
18285
|
+
const opts = parseArgs(argv, {
|
|
18286
|
+
values: { '--repo': 'repo' },
|
|
18287
|
+
flags: { '--json': 'json', '-h': 'help', '--help': 'help' },
|
|
18288
|
+
});
|
|
18289
|
+
if (opts.help) return print(HELP_FACTORY);
|
|
18290
|
+
const repoAbs = resolveRepo(opts);
|
|
18291
|
+
if (!git.repoRoot(repoAbs)) throw new UserError(`${repoAbs} is not a git repo — run it inside the repo, or pass --repo <path>`);
|
|
18292
|
+
const f = factoryFor(repoAbs);
|
|
18293
|
+
if (opts.json) {
|
|
18294
|
+
print(JSON.stringify({ factory: f.id || null, reason: f.reason, machine: f.machine, ref: f.ref || null,
|
|
18295
|
+
...(f.findings && f.findings.length ? { findings: f.findings } : {}) }, null, 2));
|
|
18296
|
+
return f.id ? 0 : 1;
|
|
18297
|
+
}
|
|
18298
|
+
if (f.id) { print(f.id); return 0; }
|
|
18299
|
+
const why = {
|
|
18300
|
+
'no-file': `no ${factories.PATH} on trunk — one team; a claim names no factory`,
|
|
18301
|
+
invalid: `${factories.PATH} on ${f.ref} is invalid — it names nobody (${(f.findings || [])[0] || 'see colab audit'})`,
|
|
18302
|
+
unlisted: `${factories.PATH} on ${f.ref} lists no factory for machine "${f.machine}"`,
|
|
18303
|
+
}[f.reason] || f.reason;
|
|
18304
|
+
process.stderr.write(`colab factory: ${why}\n`);
|
|
18305
|
+
return 1;
|
|
18306
|
+
}
|
|
18307
|
+
|
|
18074
18308
|
function cmdHolders(argv) {
|
|
18075
18309
|
const opts = parseArgs(argv, {
|
|
18076
18310
|
values: { '--repo': 'repo', '--base': 'base' },
|
|
@@ -18759,6 +18993,9 @@ Commands:
|
|
|
18759
18993
|
holders <path> [--base B] [--json] who else is holding <path> — refs that touched it and
|
|
18760
18994
|
have not landed on the base (filters the raw git-log
|
|
18761
18995
|
one-liner through \`landed\`'s content classification)
|
|
18996
|
+
factory [--json] this machine's factory in the repo, from trunk's
|
|
18997
|
+
.github/factories.yml (#743) — what a claim and a
|
|
18998
|
+
hand-off marker name
|
|
18762
18999
|
instruction-files [--base B | --staged] [--json]
|
|
18763
19000
|
CLAUDE.md is only @AGENTS.md + tool blocks? ratcheted:
|
|
18764
19001
|
fails only where the change touches it or would regress
|
|
@@ -18855,6 +19092,7 @@ function main(argv) {
|
|
|
18855
19092
|
case 'trunk-ci': return cmdTrunkCi(rest);
|
|
18856
19093
|
case 'ci-wait': return cmdCiWait(rest);
|
|
18857
19094
|
case 'holders': return cmdHolders(rest);
|
|
19095
|
+
case 'factory': return cmdFactory(rest);
|
|
18858
19096
|
case 'instruction-files': return cmdInstructionFiles(rest);
|
|
18859
19097
|
case 'promote': return cmdPromote(rest);
|
|
18860
19098
|
case 'deliver': return cmdDeliver(rest);
|
package/tools/lib/ci-forgejo.js
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* runsAtRef — the rows at a batch head (#742): the same status read, ignoring the ref;
|
|
11
11
|
* issueListAll — a READ of every issue (switch markers, the release hold, an existing tracking
|
|
12
12
|
* record), in the GitHub adapter's shape; nothing here writes an issue;
|
|
13
|
+
* issueView / commentView — (#740) READS of one issue (its comments and state: the executor's
|
|
14
|
+
* claim a hand-off land checks) and of one comment by id (the hand-off itself);
|
|
13
15
|
* releaseView / releaseCreate — the release object for a tag (`/releases`).
|
|
14
16
|
* Plus three reads that are NOT contract (forge-shaped, like the GitHub adapter's raw run lists):
|
|
15
17
|
* `ciRunsAt` (the status rows at a commit), `ciRunsSince` (rows for every commit on a branch since a
|
|
@@ -143,6 +145,16 @@ function issueShape(i) {
|
|
|
143
145
|
};
|
|
144
146
|
}
|
|
145
147
|
|
|
148
|
+
/** One comment from Forgejo's comment API → the GitHub adapter's comment shape (`gh issue view --json comments`). Pure. */
|
|
149
|
+
function commentShape(c) {
|
|
150
|
+
return {
|
|
151
|
+
author: { login: (c && c.user && c.user.login) || '' },
|
|
152
|
+
body: c && c.body != null ? String(c.body) : '',
|
|
153
|
+
createdAt: (c && c.created_at) || null,
|
|
154
|
+
url: (c && c.html_url) || null,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
146
158
|
function pick(o, fields) {
|
|
147
159
|
if (!Array.isArray(fields) || !fields.length) return o;
|
|
148
160
|
const out = {};
|
|
@@ -257,6 +269,46 @@ function create(repoAbs, eng) {
|
|
|
257
269
|
return result(true, { data: out.slice(0, limit).map((i) => pick(i, fields)) });
|
|
258
270
|
},
|
|
259
271
|
|
|
272
|
+
/**
|
|
273
|
+
* One issue (tracker contract, #740): the GitHub adapter's shape, narrowed to `fields`; null when it
|
|
274
|
+
* could not be read (absent, any failed read). `comments` costs a second, paged
|
|
275
|
+
* read, so it is made only when asked for — and a partial comment list is null, never a short list.
|
|
276
|
+
*/
|
|
277
|
+
issueView: (num, fields = null) => {
|
|
278
|
+
const r = httpGet(`${base}/issues/${Number(num)}`, eng.tokenEnv);
|
|
279
|
+
if (r.status !== 200) return null;
|
|
280
|
+
let i;
|
|
281
|
+
try { i = JSON.parse(r.body); } catch (_) { return null; }
|
|
282
|
+
if (!i || typeof i !== 'object' || Array.isArray(i)) return null;
|
|
283
|
+
const out = issueShape(i);
|
|
284
|
+
if (Array.isArray(fields) && fields.includes('comments')) {
|
|
285
|
+
const comments = [];
|
|
286
|
+
for (let page = 1; ; page++) {
|
|
287
|
+
if (page > MAX_PAGES) return null; // more comments than we read: never a partial claim read
|
|
288
|
+
const c = httpGet(`${base}/issues/${Number(num)}/comments?page=${page}&limit=${PAGE_LIMIT}`, eng.tokenEnv);
|
|
289
|
+
if (c.status !== 200) return null;
|
|
290
|
+
let list;
|
|
291
|
+
try { list = JSON.parse(c.body); } catch (_) { return null; }
|
|
292
|
+
if (!Array.isArray(list)) return null;
|
|
293
|
+
for (const x of list) comments.push(commentShape(x));
|
|
294
|
+
if (list.length < PAGE_LIMIT) break;
|
|
295
|
+
}
|
|
296
|
+
out.comments = comments;
|
|
297
|
+
}
|
|
298
|
+
return pick(out, fields);
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
/** One issue comment by id (tracker contract, #740): `{ body, login, createdAt, htmlUrl }`, null when unread. */
|
|
302
|
+
commentView: (id) => {
|
|
303
|
+
if (!/^\d+$/.test(String(id || ''))) return null;
|
|
304
|
+
const r = httpGet(`${base}/issues/comments/${String(id)}`, eng.tokenEnv);
|
|
305
|
+
if (r.status !== 200) return null;
|
|
306
|
+
let c;
|
|
307
|
+
try { c = JSON.parse(r.body); } catch (_) { return null; }
|
|
308
|
+
if (!c || typeof c !== 'object' || Array.isArray(c)) return null;
|
|
309
|
+
return { body: c.body == null ? '' : String(c.body), login: (c.user && c.user.login) || '', createdAt: c.created_at || '', htmlUrl: c.html_url || '' };
|
|
310
|
+
},
|
|
311
|
+
|
|
260
312
|
/** #681, not contract: the issues blocking issue `num` — `[{ number, state, closedAt }]`, null when unread. */
|
|
261
313
|
blockedBy: (num) => {
|
|
262
314
|
const r = httpGet(`${base}/issues/${Number(num)}/dependencies?limit=${PAGE_LIMIT}`, eng.tokenEnv);
|
|
@@ -303,4 +355,4 @@ function notGreen(rows) {
|
|
|
303
355
|
.map((x) => ({ name: x.workflowName || 'unnamed', status: x.status, conclusion: x.conclusion || null }));
|
|
304
356
|
}
|
|
305
357
|
|
|
306
|
-
module.exports = { create, withFetcher, statusRow, rowsFromPages, notGreen, issueShape, PAGE_LIMIT };
|
|
358
|
+
module.exports = { create, withFetcher, statusRow, rowsFromPages, notGreen, issueShape, commentShape, PAGE_LIMIT };
|