@futurelastic/colab-handbook 1.12.0-rc.48 → 1.12.0-rc.50

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 CHANGED
@@ -27,5 +27,5 @@
27
27
  "engines": {
28
28
  "node": ">=18"
29
29
  },
30
- "version": "1.12.0-rc.48"
30
+ "version": "1.12.0-rc.50"
31
31
  }
package/tools/colab CHANGED
@@ -129,7 +129,8 @@ function resolveRepo(opts) {
129
129
  * `.github/project.yml` into the main checkout when run from inside a worktree it was supposed
130
130
  * to target — silently violating "the main checkout stays on trunk at rest" (#258). This
131
131
  * mirrors the `opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null)` pattern
132
- * already used at most other cmd* call sites, as a named, reusable resolver.
132
+ * once used at most other cmd* call sites (normalised since #487 — resolveRepoOrCwd), as a named,
133
+ * reusable resolver for the one question that genuinely wants the caller's own tree.
133
134
  */
134
135
  function resolveWorkingRepo(opts) {
135
136
  let r = opts.repo;
@@ -154,16 +155,60 @@ function knownRepos(config) {
154
155
  return extra;
155
156
  }
156
157
 
157
- /** Find a single claim by issue number, optionally constrained to a repo. */
158
+ /**
159
+ * The repo a lookup with no --repo is about: --repo (normalised) or the MAIN root of cwd, or null.
160
+ *
161
+ * #487: this used to be spelled `resolveRepoOrCwd(opts)`
162
+ * at a dozen call sites — normalised with --repo, NOT normalised without it. Run from inside a
163
+ * linked worktree, the bare form answered with the worktree's own root, so a release looked up
164
+ * `<worktree>#N` while the claim sat under `<mainRoot>#N`. Every one of those sites is about repo
165
+ * STATE or the tracker (claims, ports, grants, events), never a committable file — for that,
166
+ * resolveWorkingRepo() is the deliberate exception.
167
+ */
168
+ function resolveRepoOrCwd(opts) {
169
+ return opts.repo ? resolveRepo(opts) : (git.mainRepoRoot(process.cwd()) || null);
170
+ }
171
+
172
+ /**
173
+ * The main checkout a claim row belongs to, given the path in its key (or its `repo` field).
174
+ *
175
+ * #487: an older writer (`claims --sync` run from inside a linked worktree) keyed rows by the
176
+ * WORKTREE's path. Those rows outlive the worktree, and the path no longer exists, so nothing could
177
+ * resolve it back to its repo — `release` missed them with and without --repo, forever. A path that
178
+ * exists resolves through git; a vanished one is attributed to the nearest existing ancestor's main
179
+ * root, but only when that ancestor IS a repo the path sits inside — never a guess across repos.
180
+ */
181
+ function claimHomeRoot(p) {
182
+ if (!p) return p;
183
+ if (fs.existsSync(p)) return git.mainRepoRoot(p) || p;
184
+ let dir = path.dirname(p);
185
+ while (dir && dir !== path.dirname(dir) && !fs.existsSync(dir)) dir = path.dirname(dir);
186
+ const root = dir && fs.existsSync(dir) ? git.mainRepoRoot(dir) : null;
187
+ return root && p.startsWith(`${root}${path.sep}`) ? root : p;
188
+ }
189
+
190
+ /** Does the claim key `k` belong to `repoAbs` (a main root)? Includes legacy worktree-keyed rows (#487). */
191
+ function claimKeyInRepo(k, repoAbs) {
192
+ if (k.startsWith(`${repoAbs}#`)) return true;
193
+ const keyPath = k.slice(0, k.lastIndexOf('#'));
194
+ return keyPath.startsWith(`${repoAbs}${path.sep}`) && claimHomeRoot(keyPath) === repoAbs;
195
+ }
196
+
197
+ /**
198
+ * Find a single claim by issue number, optionally constrained to a repo. `repo` in the result is
199
+ * the claim's MAIN root — for a legacy worktree-keyed row (#487) that is not `claim.repo`, which
200
+ * names a directory that may no longer exist; anything talking to the tracker must use `repo`.
201
+ */
158
202
  function findClaim(st, num, repoAbs) {
159
203
  const matches = Object.entries(st.claims).filter(([, c]) => normIssueNum(c.issue) === num);
160
- const scoped = repoAbs ? matches.filter(([k]) => k.startsWith(`${repoAbs}#`)) : matches;
204
+ const scoped = repoAbs ? matches.filter(([k]) => claimKeyInRepo(k, repoAbs)) : matches;
161
205
  if (scoped.length === 0) return null;
162
206
  if (scoped.length > 1) {
163
- const repos = scoped.map(([k]) => shortRepo(k.split('#')[0])).join(', ');
207
+ const repos = scoped.map(([k]) => shortRepo(k.slice(0, k.lastIndexOf('#')))).join(', ');
164
208
  throw new UserError(`Issue #${num} is claimed in multiple repos (${repos}) — disambiguate with --repo`);
165
209
  }
166
- return { key: scoped[0][0], claim: scoped[0][1] };
210
+ const [key, claim] = scoped[0];
211
+ return { key, claim, repo: repoAbs || claimHomeRoot(claim.repo || key.slice(0, key.lastIndexOf('#'))) };
167
212
  }
168
213
 
169
214
  function isGhUsable(repoAbs) {
@@ -2183,7 +2228,7 @@ function cmdRelease(argv) {
2183
2228
  });
2184
2229
  if (opts.help || opts._.length === 0) return print(HELP_RELEASE);
2185
2230
  const num = normIssueNum(opts._[0]);
2186
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
2231
+ const repoAbs = resolveRepoOrCwd(opts);
2187
2232
 
2188
2233
  // #164: look the claim up WITHOUT deleting it yet — the gh write below can fail (GraphQL AND
2189
2234
  // REST both rate-limited, network down, ...), and deleting first would clear the one local
@@ -2209,7 +2254,7 @@ function cmdRelease(argv) {
2209
2254
  * Returns { ghFailed, worktree, remaining }.
2210
2255
  */
2211
2256
  function releaseFoundClaim(num, found, opts = {}) {
2212
- const repo = found.claim.repo;
2257
+ const repo = found.repo || found.claim.repo; // #487: the MAIN root, even for a legacy worktree-keyed row
2213
2258
  const wtName = found.claim.worktree;
2214
2259
 
2215
2260
  let ghFailed = false;
@@ -2332,7 +2377,7 @@ function cmdIssueFiled(argv) {
2332
2377
  });
2333
2378
  if (opts.help || opts._.length === 0) return print(HELP_ISSUE_FILED);
2334
2379
  const num = normIssueNum(opts._[0]);
2335
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
2380
+ const repoAbs = resolveRepoOrCwd(opts);
2336
2381
  if (!repoAbs) throw new UserError('not inside a git repo — pass --repo <path>');
2337
2382
 
2338
2383
  pushEvent('issue-filed', { repo: repoAbs, issue: num });
@@ -2504,7 +2549,7 @@ function cmdGateRecorded(argv) {
2504
2549
  });
2505
2550
  if (opts.help) return print(HELP_GATE_RECORDED);
2506
2551
 
2507
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.mainRepoRoot(process.cwd()) || null);
2552
+ const repoAbs = resolveRepoOrCwd(opts);
2508
2553
  if (!repoAbs) throw new UserError('not inside a git repo — pass --repo <path>');
2509
2554
 
2510
2555
  let wtName = opts.worktree || null;
@@ -3278,7 +3323,7 @@ function cmdReadiness(argv) {
3278
3323
  });
3279
3324
  if (opts.help || opts._.length === 0) return print(HELP_READINESS);
3280
3325
  const num = normIssueNum(opts._[0]);
3281
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
3326
+ const repoAbs = resolveRepoOrCwd(opts);
3282
3327
  if (!repoAbs) throw new UserError('not inside a git repo — pass --repo <path>');
3283
3328
 
3284
3329
  // No local fallback, on purpose. A claim can degrade to local-only because it also has a fast
@@ -3478,7 +3523,7 @@ function cmdBlocked(argv) {
3478
3523
  });
3479
3524
  if (argErr) throw new UserError(argErr);
3480
3525
 
3481
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
3526
+ const repoAbs = resolveRepoOrCwd(opts);
3482
3527
  if (!repoAbs) throw new UserError('not inside a git repo — pass --repo <path>');
3483
3528
 
3484
3529
  if (!isGhUsable(repoAbs)) {
@@ -3739,7 +3784,7 @@ function cmdMigrationGrant(argv) {
3739
3784
  return 1;
3740
3785
  }
3741
3786
 
3742
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
3787
+ const repoAbs = resolveRepoOrCwd(opts);
3743
3788
  if (!repoAbs) throw new UserError('not inside a git repo — pass --repo <path>');
3744
3789
 
3745
3790
  // Argument validation and local ref resolution run BEFORE isGhUsable, deliberately — they are
@@ -3945,7 +3990,7 @@ function cmdMigrationGrantRevoke(repoAbs, num) {
3945
3990
  }
3946
3991
 
3947
3992
  function cmdMigrationGrantList(opts) {
3948
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
3993
+ const repoAbs = resolveRepoOrCwd(opts);
3949
3994
  if (!repoAbs) throw new UserError('not inside a git repo — pass --repo <path>');
3950
3995
  if (!isGhUsable(repoAbs)) {
3951
3996
  throw new UserError(`gh not usable here (${ghUnusableWhy(repoAbs)}) — cannot list migration grants`);
@@ -4080,7 +4125,7 @@ function cmdDecision(argv) {
4080
4125
  throw new UserError('--ruled-by <name> is required — names the human whose call this is, never the typist (CONVENTIONS.md §5, Provenance)');
4081
4126
  }
4082
4127
 
4083
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
4128
+ const repoAbs = resolveRepoOrCwd(opts);
4084
4129
  if (!repoAbs) throw new UserError('not inside a git repo — pass --repo <path>');
4085
4130
 
4086
4131
  if (!isGhUsable(repoAbs)) {
@@ -4226,7 +4271,7 @@ function cmdDecisionReopen(repoAbs, num, opts, body) {
4226
4271
  }
4227
4272
 
4228
4273
  function cmdDecisionList(opts) {
4229
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
4274
+ const repoAbs = resolveRepoOrCwd(opts);
4230
4275
  if (!repoAbs) throw new UserError('not inside a git repo — pass --repo <path>');
4231
4276
  if (!isGhUsable(repoAbs)) {
4232
4277
  throw new UserError(`gh not usable here (${ghUnusableWhy(repoAbs)}) — cannot list decisions`);
@@ -4450,7 +4495,7 @@ function cmdCiGrant(argv) {
4450
4495
  return 1;
4451
4496
  }
4452
4497
 
4453
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
4498
+ const repoAbs = resolveRepoOrCwd(opts);
4454
4499
  if (!repoAbs) throw new UserError('not inside a git repo — pass --repo <path>');
4455
4500
 
4456
4501
  // Argument validation and local ref resolution BEFORE isGhUsable — same reasoning as
@@ -4576,7 +4621,7 @@ function cmdCiGrantRevoke(repoAbs, num) {
4576
4621
  }
4577
4622
 
4578
4623
  function cmdCiGrantList(opts) {
4579
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
4624
+ const repoAbs = resolveRepoOrCwd(opts);
4580
4625
  if (!repoAbs) throw new UserError('not inside a git repo — pass --repo <path>');
4581
4626
  if (!isGhUsable(repoAbs)) {
4582
4627
  throw new UserError(`gh not usable here (${ghUnusableWhy(repoAbs)}) — cannot list CI grants`);
@@ -4683,8 +4728,11 @@ function syncClaims({ prune = false } = {}) {
4683
4728
  if (!git.ghAvailable()) { warn('gh not available — --sync skipped'); return; }
4684
4729
  const st = state.loadState();
4685
4730
  // repos represented locally + repos with a resolvable remote (#301: not necessarily `origin`)
4686
- const repos = new Set(Object.values(st.claims).map((c) => c.repo));
4687
- const cur = git.repoRoot(process.cwd());
4731
+ // #487: every repo here is a MAIN root. This was the writer of the worktree-keyed rows nothing could
4732
+ // release: from inside a linked worktree, repoRoot(cwd) is the worktree, so every assigned issue
4733
+ // was re-added as `<worktree>#N` — a second row beside the real `<mainRoot>#N`, outliving the dir.
4734
+ const repos = new Set(Object.values(st.claims).map((c) => claimHomeRoot(c.repo)).filter(Boolean));
4735
+ const cur = git.mainRepoRoot(process.cwd());
4688
4736
  if (cur) repos.add(cur);
4689
4737
 
4690
4738
  const added = [], removed = [];
@@ -4711,7 +4759,7 @@ function syncClaims({ prune = false } = {}) {
4711
4759
  }
4712
4760
  // local → GH: REMOVE stale local claims ONLY when --prune is given
4713
4761
  if (prune) {
4714
- const localForRepo = Object.entries(st.claims).filter(([k]) => k.startsWith(`${repoAbs}#`));
4762
+ const localForRepo = Object.entries(st.claims).filter(([k]) => claimKeyInRepo(k, repoAbs));
4715
4763
  for (const [key, c] of localForRepo) {
4716
4764
  const num = normIssueNum(c.issue);
4717
4765
  if (!assignedSet.has(num)) {
@@ -4844,7 +4892,7 @@ function cmdPortAlloc(argv) {
4844
4892
  const config = state.loadConfig();
4845
4893
  const count = opts.count ? parseInt(opts.count, 10) : 1;
4846
4894
  if (!Number.isInteger(count) || count < 1) throw new UserError('--count must be a positive integer');
4847
- const explicitRepo = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
4895
+ const explicitRepo = resolveRepoOrCwd(opts);
4848
4896
  const atPorts = parseAtPorts(opts);
4849
4897
 
4850
4898
  // For range resolution, a --worktree owner's repo wins over cwd (its project.yml window applies).
@@ -4891,7 +4939,7 @@ function cmdPortFree(argv) {
4891
4939
  flags: { '-h': 'help', '--help': 'help' },
4892
4940
  });
4893
4941
  if (opts.help) return print(HELP_PORT);
4894
- const repoAbs = opts.repo ? resolveRepo(opts) : (git.repoRoot(process.cwd()) || null);
4942
+ const repoAbs = resolveRepoOrCwd(opts);
4895
4943
 
4896
4944
  const freed = state.mutate((st) => {
4897
4945
  let targets = [];
@@ -7678,7 +7726,10 @@ function adoptGitExtras(repoAbs, opts = {}) {
7678
7726
  // #449: `git ls-files` for the migrations candidate scan (adopt never asks `migrations:`).
7679
7727
  const ls = git.git(['ls-files'], repoAbs);
7680
7728
  const trackedFiles = ls.ok ? ls.stdout.split('\n').filter(Boolean) : undefined;
7681
- return { trunk, trunkSource, hooksPath, hooksDirFiles, trackedFiles, fork: adoptDetectFork(repoAbs, opts) };
7729
+ // #483: the fork's own owner, from origin's URL — what an inherited CODEOWNERS team is compared to.
7730
+ const originUrl = git.git(['remote', 'get-url', 'origin'], repoAbs);
7731
+ const ownOrg = originUrl.ok ? codeowners.remoteOwner(originUrl.stdout) : null;
7732
+ return { trunk, trunkSource, hooksPath, hooksDirFiles, trackedFiles, fork: adoptDetectFork(repoAbs, opts), ownOrg };
7682
7733
  }
7683
7734
 
7684
7735
  /**
@@ -7932,6 +7983,12 @@ function printAdoptReport(report, repoAbs, verify, localFinish) {
7932
7983
  print(`stack candidates: ${report.detected.stackCandidates.length ? report.detected.stackCandidates.join(', ') : '(none found)'}`);
7933
7984
  print(`declared ports: ${fmtVal(report.detected.ports)}`);
7934
7985
  if (report.fork) print(`fork of an upstream: yes — ${report.fork.source === 'flag' ? '--fork' : `remote "${report.fork.remote}" ${report.fork.url}`} (step 5 is the append-only block, §9 "A fork of an upstream")`);
7986
+ if (report.inheritedCodeowners) {
7987
+ const ic = report.inheritedCodeowners;
7988
+ print(`⚠ inherited CODEOWNERS: ${ic.path} names ${ic.teams.join(', ')} — team(s) of an org other than ${ic.ownOrg}. ` +
7989
+ 'colab ship ignores them on this fork, so they gate no landing here; write the fork\'s own owners into that file ' +
7990
+ '(a fork patch) if some paths here should need a review (§2 "Core paths", #483)');
7991
+ }
7935
7992
  print(`legacy tier letter, derived from (production, deploy): ${report.legacyTierLetter ?? '(undetermined — production is set but deploy matches none of push-main/tag/manual)'}`);
7936
7993
  print('');
7937
7994
  print('Derived consequences:');
@@ -9924,7 +9981,8 @@ Options:
9924
9981
  instead — an unattended caller must NOT read it as a no-op. "pr-pending"
9925
9982
  (#350) means a real run would open/reuse a PR and PAUSE (exit 3) — additive
9926
9983
  keys \`coreReview\` ({ active, verdict, inertReason, codeownersPath, corePaths,
9927
- headSha, pr, approval }) and \`machineTrailer\` ("Machine: <label>") say why.
9984
+ ignoredOwners (#483: a fork's inherited foreign-org teams), headSha, pr,
9985
+ approval }) and \`machineTrailer\` ("Machine: <label>") say why.
9928
9986
  \`machineTrailer\` is null whenever the trailer is omitted (#367), and
9929
9987
  \`machineTrailerDecision\` ({ include, reason, visibility, room, failClosed },
9930
9988
  null on evidence-close) says which way the squash will go and why.
@@ -11763,6 +11821,19 @@ function readTargetCodeowners(repoAbs, target) {
11763
11821
  return null;
11764
11822
  }
11765
11823
 
11824
+ /**
11825
+ * #483: is this repo a fork, and which org owns it? The fork test is adopt's own (#449: a remote named
11826
+ * `upstream` whose URL differs from origin's), so adopt and ship never disagree about the shape; the
11827
+ * owner is read from this repo's remote URL. Either unknown → `{ fork: false }`, nothing is dropped.
11828
+ */
11829
+ function codeownersForkContext(repoAbs) {
11830
+ if (!adoptDetectFork(repoAbs)) return { fork: false, ownOrg: null };
11831
+ const name = git.remoteInfo(repoAbs).name || 'origin';
11832
+ const u = git.git(['remote', 'get-url', name], repoAbs);
11833
+ const ownOrg = u.ok ? codeowners.remoteOwner(u.stdout) : null;
11834
+ return { fork: !!ownOrg, ownOrg };
11835
+ }
11836
+
11766
11837
  function branchChangedPathsNoRenames(repoAbs, base, ref) {
11767
11838
  const r = git.git(['diff', '--name-only', '--no-renames', `${base}...${ref}`], repoAbs);
11768
11839
  return r.ok ? r.stdout.split('\n').map((s) => s.trim()).filter(Boolean) : null;
@@ -11806,21 +11877,30 @@ function shipDirectCoreReview(repoAbs, gh, trunk, since) {
11806
11877
  }
11807
11878
  }
11808
11879
  }
11809
- return codeowners.directVerdict({ files: [before, readTargetCodeowners(repoAbs, trunk)], authors, changed });
11880
+ return codeowners.directVerdict({ files: [before, readTargetCodeowners(repoAbs, trunk)], authors, changed, fork: codeownersForkContext(repoAbs) });
11810
11881
  }
11811
11882
 
11812
11883
  function shipCoreReview(repoAbs, gh, target, branch) {
11813
- const out = { active: false, inertReason: null, codeownersPath: null, warnings: [], corePaths: [],
11884
+ const out = { active: false, inertReason: null, codeownersPath: null, warnings: [], corePaths: [], ignoredOwners: [],
11814
11885
  pr: null, approval: null, headSha: null, authors: [], verdict: 'inert', detail: '' };
11815
11886
  const file = readTargetCodeowners(repoAbs, target);
11816
11887
  if (!file) { out.inertReason = `no CODEOWNERS on ${target}`; out.detail = `inert: ${out.inertReason}`; return out; }
11817
11888
  out.codeownersPath = file.path;
11818
- const { rules, warnings } = codeowners.parse(file.text);
11819
- out.warnings = warnings;
11889
+ const parsedFile = codeowners.parse(file.text);
11890
+ out.warnings = parsedFile.warnings;
11891
+ // #483: on a fork, teams of another org (inherited from the upstream) bind nothing here.
11892
+ const forkCtx = codeownersForkContext(repoAbs);
11893
+ const { rules, dropped } = codeowners.dropForeignTeams(parsedFile.rules, forkCtx);
11894
+ out.ignoredOwners = dropped;
11895
+ if (dropped.length) out.warnings = [...out.warnings, codeowners.foreignNote(dropped, forkCtx)];
11820
11896
  const parsed = branchName.parse(branch);
11821
11897
  out.authors = [...new Set([gh ? git.ghCurrentLogin() : null, parsed && parsed.login].filter(Boolean))];
11822
11898
  const inert = codeowners.inert(rules, out.authors);
11823
- if (inert.inert) { out.inertReason = inert.reason; out.detail = `inert: ${inert.reason}`; return out; }
11899
+ if (inert.inert) {
11900
+ out.inertReason = dropped.length ? `${inert.reason} once the fork's inherited foreign-org teams are ignored (#483)` : inert.reason;
11901
+ out.detail = `inert: ${out.inertReason}`;
11902
+ return out;
11903
+ }
11824
11904
  out.active = true;
11825
11905
  const ref = shipRefFor(repoAbs, branch);
11826
11906
  out.headSha = git.git(['rev-parse', ref], repoAbs).stdout || null;
@@ -11881,7 +11961,7 @@ function coreReviewPayload(cr) {
11881
11961
  if (!cr) return null;
11882
11962
  return {
11883
11963
  active: cr.active, verdict: cr.verdict, inertReason: cr.inertReason, codeownersPath: cr.codeownersPath,
11884
- corePaths: cr.corePaths.map((c) => c.path), headSha: cr.headSha,
11964
+ ignoredOwners: cr.ignoredOwners || [], corePaths: cr.corePaths.map((c) => c.path), headSha: cr.headSha,
11885
11965
  pr: cr.pr ? { number: cr.pr.number, url: cr.pr.url, state: cr.pr.state } : null,
11886
11966
  approval: cr.approval,
11887
11967
  };
@@ -12522,7 +12602,8 @@ function cmdShip(argv) {
12522
12602
  if (coreReview.verdict === 'approved') {
12523
12603
  const reviewed = new Set(coreReview.corePaths.map((c) => c.path));
12524
12604
  const nowChanged = branchChangedPathsNoRenames(repoAbs, mergeRef, sess.branch) || [];
12525
- const { rules } = codeowners.parse((readTargetCodeowners(repoAbs, target) || {}).text || '');
12605
+ const { rules } = codeowners.dropForeignTeams(
12606
+ codeowners.parse((readTargetCodeowners(repoAbs, target) || {}).text || '').rules, codeownersForkContext(repoAbs));
12526
12607
  const unreviewed = codeowners.corePaths(rules, nowChanged).filter((c) => !reviewed.has(c.path));
12527
12608
  if (unreviewed.length) {
12528
12609
  cleanupEphemeral();
@@ -212,6 +212,25 @@ function deriveConsequences({ exposure, writes, room }) {
212
212
  // ---------------------------------------------------------------------- §9 remainder checklist
213
213
 
214
214
  const migrationPaths = require('./migration-paths.js');
215
+ const codeowners = require('./codeowners.js');
216
+
217
+ /**
218
+ * #483 — on a fork, the CODEOWNERS teams that belong to another org: inherited from the upstream,
219
+ * unable to review here, and therefore ignored by `colab ship`'s core-path reader (CONVENTIONS.md
220
+ * §2, *Core paths*). Adopt names them so the fork owner learns at adoption time, not at the first
221
+ * ship, that the inherited file is inert until the fork writes its own. Null when there is nothing
222
+ * to say: not a fork, the fork's owner unknown, no CODEOWNERS, or no foreign team in it.
223
+ */
224
+ function detectInheritedCodeowners(io, fork, ownOrg) {
225
+ if (!fork || !ownOrg) return null;
226
+ for (const p of codeowners.CODEOWNERS_PATHS) {
227
+ const text = io.readFile(p);
228
+ if (text === null || text === undefined) continue;
229
+ const teams = codeowners.foreignTeams(codeowners.parse(text).rules, { fork: true, ownOrg });
230
+ return teams.length ? { path: p, ownOrg, teams } : null;
231
+ }
232
+ return null;
233
+ }
215
234
 
216
235
  /**
217
236
  * #449 — the agent workflow an upstream ships inside the fork: entries under `.claude/skills/`
@@ -412,6 +431,7 @@ function detect(io, extra = {}) {
412
431
  // `upstream` whose URL differs from origin's) or takes `--fork`/`--no-fork`; null = not a fork.
413
432
  const fork = (extra && extra.fork) || null;
414
433
  const upstreamAgentFiles = fork ? detectUpstreamAgentFiles(io) : [];
434
+ const inheritedCodeowners = detectInheritedCodeowners(io, fork, (extra && extra.ownOrg) || null);
415
435
  // Only when the CLI handed over `git ls-files` — a pure-io caller without it gets no step-2 line
416
436
  // rather than a false "none detected".
417
437
  const migrations = extra && Array.isArray(extra.trackedFiles)
@@ -434,6 +454,7 @@ function detect(io, extra = {}) {
434
454
  consequences,
435
455
  fork,
436
456
  upstreamAgentFiles,
457
+ inheritedCodeowners,
437
458
  migrations,
438
459
  remaining: remainingSteps({ migrations, fork, upstreamAgentFiles }),
439
460
  };
@@ -1039,6 +1060,7 @@ function renderAgentsStub() {
1039
1060
  }
1040
1061
 
1041
1062
  module.exports = {
1063
+ detectInheritedCodeowners,
1042
1064
  renderClaudeShell,
1043
1065
  renderAgentsStub,
1044
1066
  ROW_NAMES,
@@ -121,6 +121,62 @@ function inert(rules, authors) {
121
121
  return { inert: false, reason: `CODEOWNERS names ${others.join(', ')}` };
122
122
  }
123
123
 
124
+ /**
125
+ * #483 — the owner (user or org) of a forge remote URL, lowercased, or null when the URL has no
126
+ * `<owner>/<repo>` shape this can read. Handles `https://host/owner/repo(.git)`,
127
+ * `ssh://git@host[:port]/owner/repo` and the scp form `git@host:owner/repo`.
128
+ */
129
+ function remoteOwner(url) {
130
+ const s = String(url || '').trim().replace(/\/+$/, '').replace(/\.git$/, '');
131
+ let m = /^[a-z][a-z0-9+.-]*:\/\/[^/]+\/([^/]+)\/[^/]+$/i.exec(s);
132
+ if (!m) m = /^[^@/\s]+@[^:/\s]+:([^/]+)\/[^/]+$/.exec(s);
133
+ return m ? m[1].toLowerCase() : null;
134
+ }
135
+
136
+ const TEAM_RE = /^@([^/\s@]+)\/[^/\s]+$/;
137
+
138
+ /**
139
+ * #483 — the owner tokens a FORK must not be bound by: teams (`@org/team`) of an org other than
140
+ * the fork's own owner (`ownOrg`). A fork inherits the upstream's CODEOWNERS unchanged, and a team
141
+ * of another org cannot review in the fork at all, so honouring it would turn every landing into a
142
+ * human gate nobody here decided on (CONVENTIONS.md §2, *Core paths*, "A fork's inherited
143
+ * CODEOWNERS").
144
+ *
145
+ * Narrow on purpose — every doubt still resolves toward review: not a fork, or the fork's owner
146
+ * unknown, drops nothing; a login or an email is never dropped (a person can be a collaborator
147
+ * anywhere); a team of the fork's own org is kept.
148
+ */
149
+ function foreignTeams(rules, { fork, ownOrg } = {}) {
150
+ if (!fork || !ownOrg) return [];
151
+ const own = String(ownOrg).toLowerCase();
152
+ const out = new Set();
153
+ for (const r of rules || []) {
154
+ for (const o of r.owners) {
155
+ const m = TEAM_RE.exec(o);
156
+ if (m && m[1].toLowerCase() !== own) out.add(o);
157
+ }
158
+ }
159
+ return [...out];
160
+ }
161
+
162
+ /**
163
+ * #483 — `rules` with `foreignTeams` removed from every rule's owners. A rule left with no owner
164
+ * stays in place and, like an ownerless line, carves its paths out (the last match still wins), so
165
+ * an inherited `* @upstream/team` leaves the fork's own later lines exactly as they were.
166
+ * Returns `{ rules, dropped }`; `dropped` is `[]` (and `rules` the input) when nothing applies.
167
+ */
168
+ function dropForeignTeams(rules, ctx) {
169
+ const dropped = foreignTeams(rules, ctx);
170
+ if (!dropped.length) return { rules, dropped };
171
+ const gone = new Set(dropped);
172
+ return { rules: (rules || []).map((r) => ({ ...r, owners: r.owners.filter((o) => !gone.has(o)) })), dropped };
173
+ }
174
+
175
+ /** #483: the one-line reason a fork's foreign teams were ignored — shared by every reader. */
176
+ function foreignNote(dropped, ctx) {
177
+ return `fork of an upstream: ignored ${dropped.join(', ')} — team(s) of an org other than ${ctx.ownOrg}, inherited and unable to review here (#483)`;
178
+ }
179
+
124
180
  /**
125
181
  * Has a PR been approved by someone other than its author, AT `headSha`?
126
182
  *
@@ -168,8 +224,10 @@ function approvalVerdict(reviews, { prAuthor, authors = [], headSha }) {
168
224
  * rule is inert only when every file present is inert. Identical texts count once.
169
225
  * `changed`: every path the unit's commits touched, or null when they could not be listed. Null
170
226
  * refuses while the rule is active: an unbounded unit cannot be shown to avoid core paths.
227
+ * `fork`: `{ fork, ownOrg }` (#483) — on a fork, teams of another org are dropped from both files
228
+ * before anything else is read (`dropForeignTeams`). Absent = nothing dropped.
171
229
  */
172
- function directVerdict({ files, authors, changed }) {
230
+ function directVerdict({ files, authors, changed, fork = null }) {
173
231
  const out = { active: false, inertReason: null, codeownersPath: null, warnings: [], corePaths: [], verdict: 'inert', detail: '' };
174
232
  const seen = new Set();
175
233
  const present = (files || []).filter((f) => f && !seen.has(f.text) && seen.add(f.text));
@@ -178,8 +236,11 @@ function directVerdict({ files, authors, changed }) {
178
236
  const inertReasons = [];
179
237
  const activeReasons = [];
180
238
  for (const f of present) {
181
- const { rules, warnings } = parse(f.text);
182
- for (const w of warnings) out.warnings.push(`${f.path}@${f.ref}: ${w}`);
239
+ const parsed = parse(f.text);
240
+ for (const w of parsed.warnings) out.warnings.push(`${f.path}@${f.ref}: ${w}`);
241
+ // #483: a fork's inherited foreign-org teams bind neither file.
242
+ const { rules, dropped } = dropForeignTeams(parsed.rules, fork || {});
243
+ if (dropped.length) out.warnings.push(`${f.path}@${f.ref}: ${foreignNote(dropped, fork)}`);
183
244
  const iv = inert(rules, authors);
184
245
  if (iv.inert) { inertReasons.push(`${f.path}@${f.ref}: ${iv.reason}`); continue; }
185
246
  out.active = true;
@@ -205,4 +266,7 @@ function directVerdict({ files, authors, changed }) {
205
266
  return out;
206
267
  }
207
268
 
208
- module.exports = { CODEOWNERS_PATHS, parse, compile, ownerOf, corePaths, inert, approvalVerdict, directVerdict };
269
+ module.exports = {
270
+ CODEOWNERS_PATHS, parse, compile, ownerOf, corePaths, inert, approvalVerdict, directVerdict,
271
+ remoteOwner, foreignTeams, dropForeignTeams, foreignNote,
272
+ };