@osdlc/repo-cleaner 0.20.4 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +545 -165
  3. package/dist/approval.d.ts +91 -0
  4. package/dist/approval.js +233 -0
  5. package/dist/archive.d.ts +87 -0
  6. package/dist/archive.js +252 -0
  7. package/dist/branches.d.ts +4 -4
  8. package/dist/branches.js +56 -43
  9. package/dist/clean.d.ts +30 -70
  10. package/dist/clean.js +251 -197
  11. package/dist/cli.d.ts +16 -10
  12. package/dist/cli.js +252 -103
  13. package/dist/discover.d.ts +28 -7
  14. package/dist/discover.js +185 -42
  15. package/dist/index.d.ts +6 -3
  16. package/dist/index.js +5 -2
  17. package/dist/landing.d.ts +10 -5
  18. package/dist/landing.js +15 -16
  19. package/dist/plan.d.ts +18 -11
  20. package/dist/plan.js +33 -13
  21. package/dist/processes.d.ts +19 -9
  22. package/dist/processes.js +51 -25
  23. package/dist/providers/github.d.ts +21 -3
  24. package/dist/providers/github.js +149 -27
  25. package/dist/providers/gitlab.js +37 -17
  26. package/dist/providers/index.d.ts +1 -1
  27. package/dist/providers/index.js +1 -1
  28. package/dist/providers/types.d.ts +15 -2
  29. package/dist/prs.d.ts +19 -10
  30. package/dist/prs.js +21 -13
  31. package/dist/receipt.d.ts +68 -3
  32. package/dist/receipt.js +30 -3
  33. package/dist/reference.d.ts +1 -1
  34. package/dist/reference.js +93 -50
  35. package/dist/remote-mirror.d.ts +2 -1
  36. package/dist/remote-mirror.js +3 -14
  37. package/dist/render.d.ts +17 -2
  38. package/dist/render.js +80 -13
  39. package/dist/scope.d.ts +15 -0
  40. package/dist/scope.js +125 -0
  41. package/dist/size.d.ts +20 -0
  42. package/dist/size.js +34 -0
  43. package/dist/status-line.js +1 -0
  44. package/dist/step-board.js +6 -4
  45. package/dist/sweep.d.ts +45 -18
  46. package/dist/sweep.js +151 -127
  47. package/dist/types.d.ts +89 -10
  48. package/dist/types.js +50 -6
  49. package/dist/util.d.ts +2 -0
  50. package/dist/util.js +25 -0
  51. package/dist/version.generated.d.ts +1 -1
  52. package/dist/version.generated.js +1 -1
  53. package/dist/worktrees.js +87 -11
  54. package/package.json +6 -5
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * What the sweep must know about a repository before it can classify anything:
3
- * where its main checkout is, what its default branch is called, which remote
4
- * to measure against, and which provider can be asked about pull requests.
3
+ * where its main checkout is, its default remote and branch, the remotes whose
4
+ * branches it judges and their default branches, and which provider can be
5
+ * asked about each remote's pull requests.
5
6
  */
6
7
  import { type Git } from '@osdlc/typed-git';
7
8
  import type { CommandRunner } from '@osdlc/command-seam';
@@ -21,13 +22,26 @@ export declare class DiscoveryFailed extends Error {
21
22
  * Read `hint`'s repository.
22
23
  *
23
24
  * The root is normalised through `--git-common-dir`, so pointing the sweep at
24
- * a linked worktree inventories the repository that worktree belongs to. The
25
- * default branch comes from the remote's own HEAD, falling back to probing
26
- * `main` then `master` — a remote whose HEAD was never set is an ordinary
27
- * state, not a failure.
25
+ * a linked worktree inventories the repository that worktree belongs to.
26
+ *
27
+ * The default remote is `origin`, else the remote the local default branch
28
+ * tracks, else the only remote; a repository with several remotes and none of
29
+ * those has none. The local default branch comes from the default remote's
30
+ * own HEAD, falling back to probing `main` then `master` — a remote whose HEAD
31
+ * was never set is an ordinary state, not a failure.
32
+ *
33
+ * `remotes` names the remotes whose branches are judged: a name, `''` for the
34
+ * default remote, `*` for every remote. A name the repository lacks, or `''`
35
+ * where several remotes leave no default, fails the repository; `''` in a
36
+ * repository with no remote names none. Their default branches are
37
+ * read here when their refs are on disk; {@link resolveRemoteDefaults} reads
38
+ * the rest after the fetch.
28
39
  */
29
40
  export declare function discoverRepo(hint: string, opts: {
30
- remote?: string | null;
41
+ /** The remotes whose branches are judged. Default none. */
42
+ remotes?: readonly string[] | undefined;
43
+ /** The remote whose default branch every row is judged against instead. */
44
+ against?: string | null | undefined;
31
45
  /** False is `provider: 'none'`, whatever `provider` says. */
32
46
  allowProvider?: boolean;
33
47
  /** Which provider to ask for pull requests. Defaults to `auto`, by the remote's host. */
@@ -39,3 +53,10 @@ export declare function discoverRepo(hint: string, opts: {
39
53
  /** The providers to choose from. Defaults to {@link providers} over `gh` and `glab`. */
40
54
  providers?: Record<ProviderName, PrProvider> | undefined;
41
55
  }): RepoInfo;
56
+ /**
57
+ * `info` with the default branch of every remote other than the default one
58
+ * read, after the fetch, so a remote fetched for the first time has its refs.
59
+ * Throws {@link DiscoveryFailed} for one it cannot tell: a remote's default
60
+ * branch is never a candidate, so the sweep must know which it is.
61
+ */
62
+ export declare function resolveRemoteDefaults(info: RepoInfo, git: Git): RepoInfo;
package/dist/discover.js CHANGED
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * What the sweep must know about a repository before it can classify anything:
3
- * where its main checkout is, what its default branch is called, which remote
4
- * to measure against, and which provider can be asked about pull requests.
3
+ * where its main checkout is, its default remote and branch, the remotes whose
4
+ * branches it judges and their default branches, and which provider can be
5
+ * asked about each remote's pull requests.
5
6
  */
6
7
  import { parseRemoteRepo } from '@osdlc/typed-git';
7
- import { forgeTarget, probeProvider, providers, } from "./providers/index.js";
8
+ import { chooseProvider, forgeTarget, probeProvider, providers, } from "./providers/index.js";
8
9
  /**
9
10
  * Thrown when a path names no repository, or names one whose default branch
10
11
  * cannot be determined. A single-repository caller lets it propagate; a
@@ -21,14 +22,23 @@ export class DiscoveryFailed extends Error {
21
22
  * Read `hint`'s repository.
22
23
  *
23
24
  * The root is normalised through `--git-common-dir`, so pointing the sweep at
24
- * a linked worktree inventories the repository that worktree belongs to. The
25
- * default branch comes from the remote's own HEAD, falling back to probing
26
- * `main` then `master` — a remote whose HEAD was never set is an ordinary
27
- * state, not a failure.
25
+ * a linked worktree inventories the repository that worktree belongs to.
26
+ *
27
+ * The default remote is `origin`, else the remote the local default branch
28
+ * tracks, else the only remote; a repository with several remotes and none of
29
+ * those has none. The local default branch comes from the default remote's
30
+ * own HEAD, falling back to probing `main` then `master` — a remote whose HEAD
31
+ * was never set is an ordinary state, not a failure.
32
+ *
33
+ * `remotes` names the remotes whose branches are judged: a name, `''` for the
34
+ * default remote, `*` for every remote. A name the repository lacks, or `''`
35
+ * where several remotes leave no default, fails the repository; `''` in a
36
+ * repository with no remote names none. Their default branches are
37
+ * read here when their refs are on disk; {@link resolveRemoteDefaults} reads
38
+ * the rest after the fetch.
28
39
  */
29
40
  export function discoverRepo(hint, opts) {
30
41
  const { git, gh } = opts;
31
- const remoteHint = opts.remote ?? null;
32
42
  const allowProvider = opts.allowProvider ?? true;
33
43
  // `topLevel()` answers null for exit 128 only — "this is not a repository",
34
44
  // which is the answer to the question. Any other git failure throws.
@@ -38,67 +48,200 @@ export function discoverRepo(hint, opts) {
38
48
  // Pointing the sweep at a linked worktree inventories the repository that
39
49
  // worktree belongs to, not the worktree alone.
40
50
  const root = git.at(top).mainCheckout() ?? top;
51
+ const at = git.at(root);
41
52
  // We are provably inside a repository by now, so a failure here is a
42
53
  // failure, not "no remotes".
43
- const remotes = git.at(root).remote();
44
- let remote = null;
45
- if (remoteHint !== null && remotes.includes(remoteHint))
46
- remote = remoteHint;
47
- if (remote === null) {
48
- if (remotes.includes('origin'))
49
- remote = 'origin';
50
- else if (remotes.length > 0)
51
- remote = remotes[0];
52
- }
53
- let mainBranch = '';
54
- if (remote !== null) {
55
- // Null when the remote's HEAD was never set — an ordinary state, not a
56
- // failure; fall through to the main/master probe.
57
- const head = git.at(root).symbolicRef(`refs/remotes/${remote}/HEAD`);
58
- const prefix = `refs/remotes/${remote}/`;
59
- if (head?.startsWith(prefix))
60
- mainBranch = head.slice(prefix.length);
61
- }
62
- if (!mainBranch) {
54
+ const all = at.remotes();
55
+ const remote = defaultRemote(at, all);
56
+ let mainBranch = remote === null ? null : remoteHead(at, remote);
57
+ if (mainBranch === null) {
63
58
  for (const candidate of ['main', 'master']) {
64
- if (git.at(root).resolveRef(candidate) !== null) {
59
+ if (at.resolveRef(candidate) !== null) {
65
60
  mainBranch = candidate;
66
61
  break;
67
62
  }
68
63
  }
69
64
  }
70
- if (!mainBranch)
65
+ if (mainBranch === null) {
71
66
  throw new DiscoveryFailed(`could not determine the default branch of ${root}`);
72
- // A short name for the report's header, so a fan-out over long paths stays
73
- // readable. It also keys duplicate checkouts.
74
- const url = remote === null ? null : git.at(root).try.remoteGetUrl(remote);
75
- const slug = url === null ? null : remoteSlugOf(url);
76
- const remoteUrl = url?.ok === true && typeof url.value === 'string' ? url.value : null;
77
- const currentBranch = git.at(root).headRef() ?? '';
67
+ }
68
+ const names = [];
69
+ for (const asked of opts.remotes ?? []) {
70
+ if (asked === '*')
71
+ names.push(...all);
72
+ else if (asked === '') {
73
+ // A repository with no remote has no remote branches, which is no error
74
+ // in a sweep across many checkouts.
75
+ if (remote === null && all.length === 0)
76
+ continue;
77
+ if (remote === null) {
78
+ throw new DiscoveryFailed(`${root} has no default remote (no origin, and ${all.length} remotes); name one with --remote=<name>`);
79
+ }
80
+ names.push(remote);
81
+ }
82
+ else if (all.includes(asked))
83
+ names.push(asked);
84
+ else
85
+ throw new DiscoveryFailed(`${root} has no remote named ${asked}`);
86
+ }
87
+ const against = opts.against ?? null;
88
+ if (against !== null && !all.includes(against)) {
89
+ throw new DiscoveryFailed(`--against ${against}: ${root} has no remote of that name`);
90
+ }
78
91
  // Installed and signed in are probed separately: "not installed" and "not
79
92
  // authenticated" send a person somewhere different.
80
93
  const choice = allowProvider ? (opts.provider ?? 'auto') : 'none';
81
- const target = forgeTarget(remoteUrl);
82
- const provider = probeProvider(choice, root, target, opts.providers ?? providers({ gh, glab: opts.glab }));
94
+ const known = probedOnce(opts.providers ?? providers({ gh, glab: opts.glab }));
95
+ const scoped = [...new Set(names)];
96
+ const urls = new Map();
97
+ const touched = [
98
+ ...new Set([
99
+ ...(remote === null ? [] : [remote]),
100
+ ...scoped,
101
+ ...(against === null ? [] : [against]),
102
+ ]),
103
+ ];
104
+ for (const name of touched) {
105
+ const url = at.try.remoteGetUrl(name);
106
+ urls.set(name, url.ok && typeof url.value === 'string' ? url.value : null);
107
+ }
108
+ const urlOf = (name) => urls.get(name) ?? null;
109
+ if (choice === 'github' || choice === 'gitlab') {
110
+ const kinds = new Set(scoped
111
+ .map((name) => chooseProvider('auto', forgeTarget(urlOf(name))))
112
+ .filter((k) => k !== null));
113
+ if (kinds.size > 1) {
114
+ throw new DiscoveryFailed(`--provider ${choice} would ask one forge about remotes on ${[...kinds].join(' and ')} hosts; leave --provider at auto`);
115
+ }
116
+ }
117
+ // With no default remote, the local rows' provider is the one `choice`
118
+ // names for no host: none for `auto`.
119
+ const probe = (name) => probeProvider(choice, root, forgeTarget(name === null ? null : urlOf(name)), known);
120
+ // A short name for the report's header, so a fan-out over long paths stays
121
+ // readable. It also keys duplicate checkouts.
122
+ const slug = remote === null ? null : remoteSlugOf(urlOf(remote));
123
+ const provider = probe(remote);
83
124
  return {
84
125
  root,
85
126
  slug,
86
127
  mainBranch,
87
128
  remote,
88
- currentBranch,
129
+ currentBranch: at.headRef() ?? '',
89
130
  provider,
90
- fetched: false,
131
+ fetchedRemotes: [],
132
+ allRemotes: all,
133
+ // Another remote's default branch is read after the fetch, by
134
+ // resolveRemoteDefaults: until then it is ''. Only a judged remote's
135
+ // provider is asked.
136
+ remotes: touched.map((name) => ({
137
+ name,
138
+ judged: scoped.includes(name),
139
+ defaultBranch: name === remote ? mainBranch : '',
140
+ slug: remoteSlugOf(urlOf(name)),
141
+ provider: name === remote ? provider : scoped.includes(name) ? probe(name) : null,
142
+ })),
143
+ against,
144
+ };
145
+ }
146
+ /**
147
+ * `all` with each provider's probe asked once per host: it answers whether
148
+ * the CLI is installed and signed in, which does not change from one remote
149
+ * on that host to the next.
150
+ */
151
+ function probedOnce(all) {
152
+ const answers = new Map();
153
+ const wrap = (p) => ({
154
+ ...p,
155
+ probe(root, target) {
156
+ const key = `${p.name}\0${target.host ?? ''}`;
157
+ let answer = answers.get(key);
158
+ if (answer === undefined) {
159
+ answer = p.probe(root, target);
160
+ answers.set(key, answer);
161
+ }
162
+ return answer;
163
+ },
164
+ });
165
+ return { github: wrap(all.github), gitlab: wrap(all.gitlab) };
166
+ }
167
+ /**
168
+ * `info` with the default branch of every remote other than the default one
169
+ * read, after the fetch, so a remote fetched for the first time has its refs.
170
+ * Throws {@link DiscoveryFailed} for one it cannot tell: a remote's default
171
+ * branch is never a candidate, so the sweep must know which it is.
172
+ */
173
+ export function resolveRemoteDefaults(info, git) {
174
+ const at = git.at(info.root);
175
+ const unread = info.remotes.filter((r) => r.defaultBranch === '').map((r) => r.name);
176
+ const defaults = remoteDefaults(at, unread);
177
+ const known = (name, branch) => {
178
+ if (branch !== '')
179
+ return branch;
180
+ const found = defaults.get(name) ?? null;
181
+ if (found === null) {
182
+ const fix = at.refs(`refs/remotes/${name}/`).length === 0
183
+ ? `it has no remote-tracking refs: fetch it (\`--fetch\`, or judge its branches with \`--remote=${name}\` without \`--offline\`)`
184
+ : `set it with \`git remote set-head ${name} --auto\``;
185
+ throw new DiscoveryFailed(`could not tell the default branch of remote ${name}; ${fix}`);
186
+ }
187
+ return found;
188
+ };
189
+ return {
190
+ ...info,
191
+ remotes: info.remotes.map((r) => ({ ...r, defaultBranch: known(r.name, r.defaultBranch) })),
91
192
  };
92
193
  }
194
+ /** `origin`, else the remote the local `main` or `master` tracks, else the only remote; null otherwise. */
195
+ function defaultRemote(at, all) {
196
+ if (all.includes('origin'))
197
+ return 'origin';
198
+ for (const branch of ['main', 'master']) {
199
+ const tracked = at.configGet(`branch.${branch}.remote`);
200
+ if (tracked && all.includes(tracked))
201
+ return tracked;
202
+ }
203
+ return all.length === 1 ? all[0] : null;
204
+ }
205
+ /** What `refs/remotes/<remote>/HEAD` points at, or null when it was never set. */
206
+ function remoteHead(at, remote) {
207
+ const head = at.symbolicRef(`refs/remotes/${remote}/HEAD`);
208
+ const prefix = `refs/remotes/${remote}/`;
209
+ return head?.startsWith(prefix) === true ? head.slice(prefix.length) : null;
210
+ }
211
+ /**
212
+ * Each of `remotes`' default branches: what `refs/remotes/<remote>/HEAD`
213
+ * points at, else `main`, then `master`, where the remote has them; null for
214
+ * none. One `for-each-ref` reads them all, where asking each remote took up to
215
+ * three calls.
216
+ */
217
+ function remoteDefaults(at, remotes) {
218
+ const out = new Map();
219
+ if (remotes.length === 0)
220
+ return out;
221
+ const lines = at.forEachRef(remotes.map((r) => `refs/remotes/${r}/`), { format: '%(refname)%09%(symref)' });
222
+ const refs = new Map(lines.map((line) => {
223
+ const [ref = '', target = ''] = line.split('\t');
224
+ return [ref, target];
225
+ }));
226
+ for (const remote of remotes) {
227
+ const prefix = `refs/remotes/${remote}/`;
228
+ // Whole ref names, so `origin/mirror/main` is never `origin`'s `main`.
229
+ const head = refs.get(`${prefix}HEAD`);
230
+ const fromHead = head?.startsWith(prefix) === true ? head.slice(prefix.length) : null;
231
+ const found = fromHead ?? ['main', 'master'].find((b) => refs.has(`${prefix}${b}`)) ?? null;
232
+ out.set(remote, found);
233
+ }
234
+ return out;
235
+ }
93
236
  /**
94
237
  * `owner/name` for a github.com remote, `host/owner/name` for any other, or
95
238
  * null when the URL names no repository. The host keeps two hosts' `a/b`
96
239
  * apart.
97
240
  */
98
241
  function remoteSlugOf(url) {
99
- if (!url.ok || url.value === undefined || url.value === null)
242
+ if (url === null)
100
243
  return null;
101
- const remote = parseRemoteRepo(url.value);
244
+ const remote = parseRemoteRepo(url);
102
245
  if (remote === null)
103
246
  return null;
104
247
  const slug = `${remote.owner}/${remote.repo}`;
package/dist/index.d.ts CHANGED
@@ -15,10 +15,13 @@
15
15
  */
16
16
  export { sweep, inspectWorktree, type Runners, type SweepOptions } from './sweep.ts';
17
17
  export { PLAN_VERSION, plan, readPlan, writePlan, type Plan, type PlanRepo, type PlanRow, } from './plan.ts';
18
- export { check, run, type Allow, type Approval, type CheckOptions, type Preview, type ResolvedApproval, type Resolved, type RunOptions, } from './clean.ts';
19
- export { RECEIPT_VERSION, ReceiptSchema, type DropReason, type Dropped, type Receipt, type Step, } from './receipt.ts';
18
+ export { DEFAULT_MAX_FILE_BYTES, type ArchiveOptions, type LeftOut } from './archive.ts';
19
+ export { type Allow, type Approval, type ResolvedApproval, type Resolved } from './approval.ts';
20
+ export { check, run, type CheckOptions, type Preview, type RunOptions } from './clean.ts';
21
+ export { RECEIPT_VERSION, ReceiptSchema, type DropReason, type Dropped, type ArchiveRecord, type Receipt, type Step, } from './receipt.ts';
20
22
  export { render, type RunSummary, type Style } from './render.ts';
23
+ export { formatBytes, sizeOf, type SizeOfOptions } from './size.ts';
21
24
  export { defaultProcessProbe, type ProcessHolder, type ProcessProbe } from './processes.ts';
22
25
  export { providers, type PrProvider, type ProviderChoice } from './providers/index.ts';
23
26
  export type { Annotate } from './hooks.ts';
24
- export { KINDS, RISKS, RepoCleanerError, type Action, type Blocker, type BranchEvidence, type BranchRow, type Bucket, type Counts, type ErrorCode, type Kind, type LandingEvidence, type PrEvidence, type RemoteEvidence, type RemoteRow, type RepoInfo, type RepoNote, type RepoSweep, type Risk, type Row, type RowId, type SubmoduleEvidence, type Sweep, type SweepProgress, type SweptWith, type Verdict, type WorktreeEvidence, type WorktreeRow, } from './types.ts';
27
+ export { KINDS, RISKS, RepoCleanerError, judgedRemotes, landedFor, refOf, type Action, type Blocker, type BranchEvidence, type BranchRow, type Bucket, type Counts, type ErrorCode, type Kind, type LandedAgainst, type LandingEvidence, type PrEvidence, type RemoteEvidence, type RemoteInfo, type RemoteRow, type RepoInfo, type RepoNote, type RepoSweep, type Reclaimable, type Risk, type Row, type RowId, type SubmoduleEvidence, type Sweep, type SweepProgress, type SweptWith, type Verdict, type WorktreeEvidence, type WorktreeRow, } from './types.ts';
package/dist/index.js CHANGED
@@ -15,9 +15,12 @@
15
15
  */
16
16
  export { sweep, inspectWorktree } from "./sweep.js";
17
17
  export { PLAN_VERSION, plan, readPlan, writePlan, } from "./plan.js";
18
- export { check, run, } from "./clean.js";
18
+ export { DEFAULT_MAX_FILE_BYTES } from "./archive.js";
19
+ export {} from "./approval.js";
20
+ export { check, run } from "./clean.js";
19
21
  export { RECEIPT_VERSION, ReceiptSchema, } from "./receipt.js";
20
22
  export { render } from "./render.js";
23
+ export { formatBytes, sizeOf } from "./size.js";
21
24
  export { defaultProcessProbe } from "./processes.js";
22
25
  export { providers } from "./providers/index.js";
23
- export { KINDS, RISKS, RepoCleanerError, } from "./types.js";
26
+ export { KINDS, RISKS, RepoCleanerError, judgedRemotes, landedFor, refOf, } from "./types.js";
package/dist/landing.d.ts CHANGED
@@ -24,7 +24,12 @@
24
24
  * and a patch that is empty all end the same way: no evidence.
25
25
  */
26
26
  import type { Git } from '@osdlc/typed-git';
27
- import { type LandingEvidence, type PRInfo, type PrEvidenceGap, type RepoInfo } from './types.ts';
27
+ import type { LandingEvidence, PRInfo, PrEvidenceGap } from './types.ts';
28
+ /** Where a tip is judged: the repository's root, and the ref its work must be on (`origin/main`). */
29
+ export interface Onto {
30
+ root: string;
31
+ ref: string;
32
+ }
28
33
  /** Which check showed that the work is on the landed ref. */
29
34
  export type LandingCheck =
30
35
  /** Every commit on the branch has a patch-equivalent commit on the landed ref (rebase merge, cherry-pick). */
@@ -66,17 +71,17 @@ export type Landing = {
66
71
  * returns `{ check: null, unmatched: [] }`: a check that cannot finish is not
67
72
  * evidence.
68
73
  */
69
- export declare function assessLanding(repo: RepoInfo, tip: string, git: Git, prHead?: string | null): Landing;
74
+ export declare function assessLanding(onto: Onto, tip: string, git: Git, prHead?: string | null): Landing;
70
75
  /**
71
76
  * The patch-equivalence verdict for a branch the first two signals did not
72
77
  * settle. A merged PR at an earlier head lets the check trust that head's
73
78
  * squash merge and look at the commits after it.
74
79
  */
75
- export declare function judgeLanding(repo: RepoInfo, tip: string, pr: PRInfo | undefined, gap: PrEvidenceGap | null, git: Git): Landing;
80
+ export declare function judgeLanding(onto: Onto, tip: string, pr: PRInfo | undefined, gap: PrEvidenceGap | null, git: Git): Landing;
76
81
  /** True when the verdict is a patch match that the content check agreed with, so no grant is needed. */
77
82
  export declare function landingConfirmed(landing: Landing | null): boolean;
78
83
  /** {@link assessLanding}, reduced to the check that passed, or null. */
79
- export declare function patchEquivalent(repo: RepoInfo, tip: string, git: Git, prHead?: string | null): LandingCheck | null;
84
+ export declare function patchEquivalent(onto: Onto, tip: string, git: Git, prHead?: string | null): LandingCheck | null;
80
85
  /** Write the landing evidence into a row's evidence. */
81
86
  export declare function recordLanding(evidence: LandingEvidence, landing: Landing): void;
82
87
  /**
@@ -87,4 +92,4 @@ export declare function confirmationNote(landing: Extract<Landing, {
87
92
  check: LandingCheck;
88
93
  }>): string;
89
94
  /** One sentence naming the commits that kept a partly landed branch from counting, or null. */
90
- export declare function unmatchedSentence(landing: Landing, repo: RepoInfo): string | null;
95
+ export declare function unmatchedSentence(landing: Landing, ref: string): string | null;
package/dist/landing.js CHANGED
@@ -23,7 +23,6 @@
23
23
  * shallow clone, a missing merge base, a commit that is not on the landed ref
24
24
  * and a patch that is empty all end the same way: no evidence.
25
25
  */
26
- import { landedRef, } from "./types.js";
27
26
  /** Cap on {@link Landing} `unmatched`. */
28
27
  const UNMATCHED_SHOWN = 10;
29
28
  /**
@@ -123,14 +122,14 @@ function describeCommits(at, range, shas) {
123
122
  .map((parts) => parts.slice(1).join(' ').trim())
124
123
  .slice(0, UNMATCHED_SHOWN);
125
124
  }
126
- function assess(repo, tip, git, prHead) {
127
- const at = git.at(repo.root);
125
+ function assess(onto, tip, git, prHead) {
126
+ const at = git.at(onto.root);
128
127
  const none = { check: null, unmatched: [] };
129
128
  // A shallow clone cuts history short, so the merge base and the commit list
130
129
  // are not the real ones. Anything but a plain "false" is read as shallow.
131
130
  if (at.revParse('--is-shallow-repository', CALL) !== 'false')
132
131
  return none;
133
- const landed = at.resolveRef(landedRef(repo), CALL);
132
+ const landed = at.resolveRef(onto.ref, CALL);
134
133
  const tipSha = at.resolveRef(`${tip}^{commit}`, CALL);
135
134
  if (landed === null || tipSha === null)
136
135
  return none;
@@ -183,10 +182,10 @@ function contentConfirmed(at, landed, tipSha) {
183
182
  return landedTree !== null && landedTree === merged.tree;
184
183
  }
185
184
  /** {@link contentConfirmed} for `tip` against the landed ref; any error is false. */
186
- function confirm(repo, tip, git) {
185
+ function confirm(onto, tip, git) {
187
186
  try {
188
- const at = git.at(repo.root);
189
- const landed = at.resolveRef(landedRef(repo), CALL);
187
+ const at = git.at(onto.root);
188
+ const landed = at.resolveRef(onto.ref, CALL);
190
189
  const tipSha = at.resolveRef(`${tip}^{commit}`, CALL);
191
190
  return landed !== null && tipSha !== null && contentConfirmed(at, landed, tipSha);
192
191
  }
@@ -208,34 +207,34 @@ function confirm(repo, tip, git) {
208
207
  * returns `{ check: null, unmatched: [] }`: a check that cannot finish is not
209
208
  * evidence.
210
209
  */
211
- export function assessLanding(repo, tip, git, prHead = null) {
210
+ export function assessLanding(onto, tip, git, prHead = null) {
212
211
  let verdict;
213
212
  try {
214
- verdict = assess(repo, tip, git, prHead);
213
+ verdict = assess(onto, tip, git, prHead);
215
214
  }
216
215
  catch {
217
216
  return { check: null, unmatched: [] };
218
217
  }
219
218
  if (verdict.check === null)
220
219
  return verdict;
221
- return { check: verdict.check, confirmed: confirm(repo, tip, git) };
220
+ return { check: verdict.check, confirmed: confirm(onto, tip, git) };
222
221
  }
223
222
  /**
224
223
  * The patch-equivalence verdict for a branch the first two signals did not
225
224
  * settle. A merged PR at an earlier head lets the check trust that head's
226
225
  * squash merge and look at the commits after it.
227
226
  */
228
- export function judgeLanding(repo, tip, pr, gap, git) {
227
+ export function judgeLanding(onto, tip, pr, gap, git) {
229
228
  const prHead = pr !== undefined && gap === 'head-moved' ? pr.headOid : null;
230
- return assessLanding(repo, tip, git, prHead);
229
+ return assessLanding(onto, tip, git, prHead);
231
230
  }
232
231
  /** True when the verdict is a patch match that the content check agreed with, so no grant is needed. */
233
232
  export function landingConfirmed(landing) {
234
233
  return landing !== null && landing.check !== null && landing.confirmed;
235
234
  }
236
235
  /** {@link assessLanding}, reduced to the check that passed, or null. */
237
- export function patchEquivalent(repo, tip, git, prHead = null) {
238
- return assessLanding(repo, tip, git, prHead).check;
236
+ export function patchEquivalent(onto, tip, git, prHead = null) {
237
+ return assessLanding(onto, tip, git, prHead).check;
239
238
  }
240
239
  /** Write the landing evidence into a row's evidence. */
241
240
  export function recordLanding(evidence, landing) {
@@ -258,8 +257,8 @@ export function confirmationNote(landing) {
258
257
  : 'content not confirmed by merge-tree, so abandon-unmerged is required';
259
258
  }
260
259
  /** One sentence naming the commits that kept a partly landed branch from counting, or null. */
261
- export function unmatchedSentence(landing, repo) {
260
+ export function unmatchedSentence(landing, ref) {
262
261
  if (landing.check !== null || landing.unmatched.length === 0)
263
262
  return null;
264
- return `Part of the work is on \`${landedRef(repo)}\`, but these commits are not (no patch-equivalent commit): ${landing.unmatched.join('; ')}.`;
263
+ return `Part of the work is on \`${ref}\`, but these commits are not (no patch-equivalent commit): ${landing.unmatched.join('; ')}.`;
265
264
  }
package/dist/plan.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { z } from 'zod';
7
7
  import { type Row, type Sweep } from './types.ts';
8
- export declare const PLAN_VERSION = 2;
8
+ export declare const PLAN_VERSION = 3;
9
9
  /** A row id, `<kind>:<name>` with a name; shared by the plan and the receipt. */
10
10
  export declare const RowIdSchema: z.ZodCustom<`worktree:${string}` | `branch:${string}` | `remote:${string}`, `worktree:${string}` | `branch:${string}` | `remote:${string}`>;
11
11
  export declare const PlanRowSchema: z.ZodObject<{
@@ -24,6 +24,7 @@ export declare const PlanRowSchema: z.ZodObject<{
24
24
  risks: z.ZodArray<z.ZodEnum<{
25
25
  "abandon-unmerged": "abandon-unmerged";
26
26
  "discard-changes": "discard-changes";
27
+ "discard-archived": "discard-archived";
27
28
  "confirm-open-pr": "confirm-open-pr";
28
29
  }>>;
29
30
  fingerprint: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -31,7 +32,8 @@ export declare const PlanRowSchema: z.ZodObject<{
31
32
  export type PlanRow = z.infer<typeof PlanRowSchema>;
32
33
  export declare const PlanRepoSchema: z.ZodObject<{
33
34
  root: z.ZodString;
34
- fetched: z.ZodBoolean;
35
+ remotes: z.ZodArray<z.ZodString>;
36
+ fetched: z.ZodArray<z.ZodString>;
35
37
  rows: z.ZodArray<z.ZodObject<{
36
38
  id: z.ZodCustom<`worktree:${string}` | `branch:${string}` | `remote:${string}`, `worktree:${string}` | `branch:${string}` | `remote:${string}`>;
37
39
  verdict: z.ZodEnum<{
@@ -48,6 +50,7 @@ export declare const PlanRepoSchema: z.ZodObject<{
48
50
  risks: z.ZodArray<z.ZodEnum<{
49
51
  "abandon-unmerged": "abandon-unmerged";
50
52
  "discard-changes": "discard-changes";
53
+ "discard-archived": "discard-archived";
51
54
  "confirm-open-pr": "confirm-open-pr";
52
55
  }>>;
53
56
  fingerprint: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -55,7 +58,7 @@ export declare const PlanRepoSchema: z.ZodObject<{
55
58
  }, z.core.$strip>;
56
59
  export type PlanRepo = z.infer<typeof PlanRepoSchema>;
57
60
  export declare const PlanSchema: z.ZodObject<{
58
- version: z.ZodLiteral<2>;
61
+ version: z.ZodLiteral<3>;
59
62
  createdAt: z.ZodString;
60
63
  options: z.ZodObject<{
61
64
  only: z.ZodArray<z.ZodEnum<{
@@ -63,20 +66,22 @@ export declare const PlanSchema: z.ZodObject<{
63
66
  branch: "branch";
64
67
  remote: "remote";
65
68
  }>>;
66
- remote: z.ZodBoolean;
69
+ remotes: z.ZodArray<z.ZodString>;
70
+ fetch: z.ZodBoolean;
67
71
  offline: z.ZodBoolean;
68
72
  against: z.ZodNullable<z.ZodString>;
69
73
  provider: z.ZodEnum<{
74
+ auto: "auto";
70
75
  github: "github";
71
76
  gitlab: "gitlab";
72
- auto: "auto";
73
77
  none: "none";
74
78
  }>;
75
79
  branch: z.ZodNullable<z.ZodString>;
76
80
  }, z.core.$strip>;
77
81
  repos: z.ZodArray<z.ZodObject<{
78
82
  root: z.ZodString;
79
- fetched: z.ZodBoolean;
83
+ remotes: z.ZodArray<z.ZodString>;
84
+ fetched: z.ZodArray<z.ZodString>;
80
85
  rows: z.ZodArray<z.ZodObject<{
81
86
  id: z.ZodCustom<`worktree:${string}` | `branch:${string}` | `remote:${string}`, `worktree:${string}` | `branch:${string}` | `remote:${string}`>;
82
87
  verdict: z.ZodEnum<{
@@ -93,6 +98,7 @@ export declare const PlanSchema: z.ZodObject<{
93
98
  risks: z.ZodArray<z.ZodEnum<{
94
99
  "abandon-unmerged": "abandon-unmerged";
95
100
  "discard-changes": "discard-changes";
101
+ "discard-archived": "discard-archived";
96
102
  "confirm-open-pr": "confirm-open-pr";
97
103
  }>>;
98
104
  fingerprint: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -101,11 +107,12 @@ export declare const PlanSchema: z.ZodObject<{
101
107
  }, z.core.$strip>;
102
108
  export type Plan = z.infer<typeof PlanSchema>;
103
109
  /**
104
- * The evidence a row's verdict rests on. A branch: its sha and its PR's number
105
- * and state. A worktree: HEAD, branch, how much unlanded work it holds, whether
106
- * its lock was stale, whether it is on disk, and each submodule's state, so a
107
- * lock taken or revived after planning, a directory that came back, or a
108
- * submodule that changed, drops the row.
110
+ * The evidence a row's verdict rests on. Every row: the default branch it was
111
+ * judged against. A branch: its sha and its PR's number and state. A worktree:
112
+ * HEAD, branch, how much unlanded work it holds, whether its lock was stale,
113
+ * whether it is on disk, each submodule's state, and the remote branches that
114
+ * hold HEAD, so a lock taken or revived after planning, a directory that came
115
+ * back, or a submodule that changed, drops the row.
109
116
  */
110
117
  export declare function fingerprint(row: Row): Record<string, unknown>;
111
118
  /** Equal fingerprints, treating a missing key as null. */