@demlik/backlog-sweep 0.0.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @demlik/backlog-sweep
2
2
 
3
3
  Ask TypeSafe **Jev** whether each open GitHub issue is still needed. `backlog-sweep` gathers evidence
4
- per issue and writes one proposal per issue — keep, close, close as a duplicate, or review. It closes
5
- nothing; a human reads the file and acts.
4
+ per issue and writes one proposal per issue. It closes nothing and labels nothing; a human reads the
5
+ file and acts.
6
6
 
7
7
  ```sh
8
8
  npm install -D @demlik/backlog-sweep
@@ -15,13 +15,44 @@ be logged in):
15
15
 
16
16
  - the issue's title, labels, dates, body and last two comments;
17
17
  - the paths it mentions that are still in the tree, and those that are gone — a path counts when it
18
- starts at a folder at the root of this repository;
19
- - linked pull requests and issues, and commits on `--ref` that reference it;
18
+ starts at a folder at the root of this repository — and `allMentionedPathsGone`;
19
+ - linked pull requests, each with its state (`open`, `merged` or `closed-unmerged`) and its
20
+ `relation` to the issue (`closes` or `partial`), and `linkedPullRequestClosedUnmerged`;
21
+ - linked issues, and commits on `--ref` that reference it;
20
22
  - the three most similar issues, open or closed, by TF-IDF over their titles and bodies.
21
23
 
22
24
  Jev answers one verdict — `still_needed`, `already_done`, `obsolete`, `duplicate` or `unclear` —
23
- and, for each similar issue, whether it is the same defect. Below 0.8 confidence, or on a duplicate
24
- with no confident match, the proposal is `review`.
25
+ and, for each similar issue, whether it is the same defect.
26
+
27
+ ## What Jev decides, and what only evidence decides
28
+
29
+ Jev judges meaning. Whether a close is proposed is decided by facts the tool computes itself. The
30
+ split comes from a 40-issue seeded sample graded blind against the code: `keep` was right 21 of 21
31
+ times, both confident `already_done` closes were wrong, and the pairwise duplicate answers held up.
32
+
33
+ - **Jev is reliable on** `still_needed`, which becomes `keep`, and on the pairwise duplicate
34
+ judgement — is this issue the same concrete defect as that one.
35
+ - **`already_done` is a verify hint, never a close on its own.** An open issue whose closing pull
36
+ request merged would normally have been closed by GitHub already, so an open issue that looks done
37
+ needs a check in code. Jev answering `already_done` confidently about an issue whose merged pull
38
+ request only said "Part of #N" is exactly the mistake this rule exists for.
39
+ - **Computed, not judged:** whether a linked pull request closes the issue or only references it
40
+ (`relation`, from GitHub's `closingIssuesReferences` and the closing keywords in the pull
41
+ request's body), whether every path the issue mentions is gone from the ref
42
+ (`allMentionedPathsGone`), and whether every linked pull request was closed without merging
43
+ (`linkedPullRequestClosedUnmerged`).
44
+ - **A `close` is proposed only on one of those computed facts**, and the proposal names it as its
45
+ `basis`.
46
+
47
+ ## Proposals
48
+
49
+ | Kind | When |
50
+ |---|---|
51
+ | `keep` | `still_needed` at or above 0.8 confidence. |
52
+ | `verify` | `already_done` below 0.8, or at or above 0.8 with no merged pull request that closes the issue. Carries every linked pull request with its number, state and relation, and the commits on the ref that reference the issue — what a human checks. |
53
+ | `close` | `already_done` at or above 0.8 beside a merged pull request whose relation is `closes` (basis: that pull request), or `obsolete` at or above 0.8 when `allMentionedPathsGone` or `linkedPullRequestClosedUnmerged` holds (basis: the fact that held). |
54
+ | `close_duplicate` | `duplicate` at or above 0.8 with a similar issue Jev also calls a duplicate at or above 0.8. |
55
+ | `review` | `still_needed`, `obsolete` or `duplicate` below 0.8, `unclear`, a duplicate with no confident match, or an `obsolete` that no computed fact backs. |
25
56
 
26
57
  ## Jev credentials
27
58
 
@@ -46,9 +77,47 @@ backlog-sweep --repo acme/widgets --ref origin/main
46
77
  | `--concurrency <n>` | `6` | |
47
78
 
48
79
  The verdict file is rewritten after every answer, so a killed run resumes; an issue is asked again
49
- only when its `updatedAt` moved.
80
+ only when its `updatedAt` moved. A cached answer keeps the similar-issue candidates Jev compared, so
81
+ its duplicate answers stay bound to the issues they judged; the rest of its evidence and its
82
+ proposal are recomputed on every run.
83
+
84
+ ## Finding duplicate groups
85
+
86
+ ```sh
87
+ backlog-sweep duplicates --repo acme/widgets
88
+ ```
89
+
90
+ Finds groups of open issues that are the same concrete defect, across the whole open backlog. The
91
+ first stage is deterministic: each open issue not excluded by `--exclude-label` is paired with its
92
+ nearest open neighbours by TF-IDF, and the pairs are deduplicated. The second stage asks Jev one
93
+ duplicate / related / different question per pair; only `duplicate` at or above 0.8 confirms a
94
+ pair, and confirmed pairs that share an issue join one group. It closes nothing and labels nothing.
95
+
96
+ | Flag | Default | |
97
+ |---|---|---|
98
+ | `--repo <owner/name>` | the checkout's `origin` remote | |
99
+ | `--out <file>` | `.backlog-sweep/duplicates.json` | Relative to the repository root. |
100
+ | `--exclude-label <name>` | `type:epic`, `status:awaiting-release` | The same rule the sweep uses. |
101
+ | `--neighbours <n>` | `5` | Nearest open issues paired with each issue. |
102
+ | `--model <id>` | `jev-1.13.0` | |
103
+ | `--concurrency <n>` | `6` | |
104
+
105
+ The output file holds `candidates` (pairs asked), `unanswered` (pairs whose Jev call failed, which
106
+ confirm nothing), and `groups`: each lists its issues' numbers, titles and URLs, and the confirming
107
+ pairs with their confidence.
108
+
109
+ ## Tried and dropped
110
+
111
+ Two other approaches were tested on a real backlog and did not work. Do not re-run them.
112
+
113
+ - **A text-only "is this worth filing" gate.** Judging an issue from its own text alone scored an
114
+ AUC of 0.52 on 300 historical issues — no better than chance.
115
+ - **Sorting issues into outcome buckets after filing.** It agreed with a blind grader on about 65%
116
+ of issues (90% on the clear-cut ones), too little to act on.
50
117
 
51
118
  ## As a library
52
119
 
53
120
  `runBacklogSweep` takes the issues and a `JevClient` as arguments; `propose` is the pure rule that
54
- turns Jev's answers into a proposal.
121
+ turns Jev's answers and the computed evidence into a proposal, and `pullRelation` is the pure rule
122
+ for a pull request's relation. `findDuplicateGroups` takes the open issues and a `JevClient` and
123
+ returns the duplicate groups; `candidatePairs` is its deterministic first stage.
package/dist/bin.js CHANGED
@@ -1,27 +1,34 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  DEFAULT_MODEL,
4
+ DEFAULT_NEIGHBOURS,
5
+ PROPOSAL_KINDS,
4
6
  fetchClosedIssues,
5
7
  fetchOpenIssues,
6
8
  fetchPost,
9
+ findDuplicateGroups,
7
10
  git,
8
11
  httpJevClient,
12
+ pairQuestions,
9
13
  questions,
10
14
  requireApiKey,
11
15
  resolveRepo,
12
16
  runBacklogSweep,
13
17
  snapshotRepo
14
- } from "./chunk-2P555A6E.js";
18
+ } from "./chunk-JO6CUW25.js";
15
19
 
16
20
  // src/bin.ts
17
- import { isAbsolute, resolve } from "path";
21
+ import { mkdirSync, writeFileSync } from "fs";
22
+ import { dirname, isAbsolute, resolve } from "path";
18
23
  import { parseArgs } from "util";
19
24
  var DEFAULT_OUT = ".backlog-sweep/verdicts.json";
25
+ var DEFAULT_DUPLICATES_OUT = ".backlog-sweep/duplicates.json";
20
26
  var DEFAULT_EXCLUDED = ["type:epic", "status:awaiting-release"];
21
27
  var USAGE = `backlog-sweep [options]
22
28
 
23
29
  Gather evidence for every open issue of a GitHub repository and ask Jev whether each is still
24
- needed. Writes one verdict per issue; closing anything is a human's call.
30
+ needed. Writes one proposal per issue \u2014 keep, verify, close, close_duplicate or review. It closes
31
+ nothing; closing anything is a human's call.
25
32
 
26
33
  --repo <owner/name> repository to sweep (default: this checkout's origin remote)
27
34
  --ref <ref> tree the evidence is read from (default: origin/main)
@@ -30,8 +37,25 @@ var USAGE = `backlog-sweep [options]
30
37
  --sample <n> judge a seeded random sample of n issues
31
38
  --seed <n> seed for --sample (default: 4498)
32
39
  --model <id> Jev model (default: ${DEFAULT_MODEL})
40
+ --concurrency <n> calls in flight (default: 6)
41
+
42
+ backlog-sweep duplicates [options]
43
+
44
+ Group open issues that are the same concrete defect: each issue's nearest open neighbours by
45
+ TF-IDF become candidate pairs, Jev judges each pair, and a confident duplicate joins two issues.
46
+ It closes nothing and labels nothing.
47
+
48
+ --repo <owner/name> repository to read (default: this checkout's origin remote)
49
+ --out <file> duplicate groups (default: ${DEFAULT_DUPLICATES_OUT})
50
+ --exclude-label <name> skip issues with this label (repeatable; default: ${DEFAULT_EXCLUDED.join(", ")})
51
+ --neighbours <n> nearest open issues paired with each issue (default: ${DEFAULT_NEIGHBOURS})
52
+ --model <id> Jev model (default: ${DEFAULT_MODEL})
33
53
  --concurrency <n> calls in flight (default: 6)`;
34
- async function main(argv, cwd) {
54
+ var log = (line) => console.error(line);
55
+ function outPathOf(root, out) {
56
+ return isAbsolute(out) ? out : resolve(root, out);
57
+ }
58
+ async function sweep(argv, cwd) {
35
59
  const { values } = parseArgs({
36
60
  args: [...argv],
37
61
  options: {
@@ -53,9 +77,8 @@ async function main(argv, cwd) {
53
77
  const root = git(cwd, ["rev-parse", "--show-toplevel"]).trim();
54
78
  const repo = resolveRepo(values.repo, cwd);
55
79
  const [owner = "", name = ""] = repo.split("/");
56
- const outPath = isAbsolute(values.out) ? values.out : resolve(root, values.out);
80
+ const outPath = outPathOf(root, values.out);
57
81
  const apiKey = requireApiKey();
58
- const log = (line) => console.error(line);
59
82
  log(`snapshotting ${values.ref}\u2026`);
60
83
  const snapshot = snapshotRepo(root, values.ref);
61
84
  log(`fetching open and closed issues of ${repo}\u2026`);
@@ -74,7 +97,7 @@ async function main(argv, cwd) {
74
97
  concurrency: Number(values.concurrency),
75
98
  log
76
99
  });
77
- const tally = /* @__PURE__ */ new Map();
100
+ const tally = new Map(PROPOSAL_KINDS.map((kind) => [kind, 0]));
78
101
  for (const r of rows)
79
102
  tally.set(r.proposal.kind, (tally.get(r.proposal.kind) ?? 0) + 1);
80
103
  const input = rows.reduce((n, r) => n + r.usage.input_tokens, 0);
@@ -82,6 +105,57 @@ async function main(argv, cwd) {
82
105
  `${JSON.stringify(Object.fromEntries(tally))} input tokens ${input} \u2192 ${outPath}`
83
106
  );
84
107
  }
108
+ async function duplicates(argv, cwd) {
109
+ const { values } = parseArgs({
110
+ args: [...argv],
111
+ options: {
112
+ repo: { type: "string" },
113
+ out: { type: "string", default: DEFAULT_DUPLICATES_OUT },
114
+ "exclude-label": { type: "string", multiple: true },
115
+ neighbours: { type: "string", default: String(DEFAULT_NEIGHBOURS) },
116
+ model: { type: "string", default: DEFAULT_MODEL },
117
+ concurrency: { type: "string", default: "6" },
118
+ help: { type: "boolean", short: "h" }
119
+ }
120
+ });
121
+ if (values.help === true) {
122
+ console.log(USAGE);
123
+ return;
124
+ }
125
+ const neighbours = Number(values.neighbours);
126
+ if (!Number.isInteger(neighbours) || neighbours < 1)
127
+ throw new Error(
128
+ `--neighbours takes a positive integer, got ${values.neighbours}`
129
+ );
130
+ const root = git(cwd, ["rev-parse", "--show-toplevel"]).trim();
131
+ const repo = resolveRepo(values.repo, cwd);
132
+ const [owner = "", name = ""] = repo.split("/");
133
+ const outPath = outPathOf(root, values.out);
134
+ const apiKey = requireApiKey();
135
+ log(`fetching open issues of ${repo}\u2026`);
136
+ const report = await findDuplicateGroups({
137
+ open: fetchOpenIssues(owner, name),
138
+ jev: httpJevClient({
139
+ questions: pairQuestions,
140
+ model: values.model,
141
+ post: fetchPost(apiKey)
142
+ }),
143
+ excludeLabels: values["exclude-label"] ?? DEFAULT_EXCLUDED,
144
+ neighbours,
145
+ concurrency: Number(values.concurrency),
146
+ log
147
+ });
148
+ mkdirSync(dirname(outPath), { recursive: true });
149
+ writeFileSync(outPath, `${JSON.stringify(report, null, 1)}
150
+ `);
151
+ log(
152
+ `${report.candidates} pairs asked, ${report.unanswered.length} unanswered, ${report.groups.length} groups, input tokens ${report.inputTokens} \u2192 ${outPath}`
153
+ );
154
+ }
155
+ function main(argv, cwd) {
156
+ const [command, ...rest] = argv;
157
+ return command === "duplicates" ? duplicates(rest, cwd) : sweep(argv, cwd);
158
+ }
85
159
  main(process.argv.slice(2), process.cwd()).catch((error) => {
86
160
  console.error(
87
161
  `backlog-sweep: ${error instanceof Error ? error.message : String(error)}
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { isAbsolute, resolve } from \"node:path\";\nimport { parseArgs } from \"node:util\";\nimport { fetchClosedIssues, fetchOpenIssues } from \"./github.js\";\nimport {\n DEFAULT_MODEL,\n fetchPost,\n httpJevClient,\n requireApiKey,\n} from \"./jev.js\";\nimport { git, resolveRepo, snapshotRepo } from \"./repo.js\";\nimport { runBacklogSweep } from \"./run.js\";\nimport { questions } from \"./verdict.js\";\n\nconst DEFAULT_OUT = \".backlog-sweep/verdicts.json\";\nconst DEFAULT_EXCLUDED = [\"type:epic\", \"status:awaiting-release\"];\n\nconst USAGE = `backlog-sweep [options]\n\n Gather evidence for every open issue of a GitHub repository and ask Jev whether each is still\n needed. Writes one verdict per issue; closing anything is a human's call.\n\n --repo <owner/name> repository to sweep (default: this checkout's origin remote)\n --ref <ref> tree the evidence is read from (default: origin/main)\n --out <file> verdict file (default: ${DEFAULT_OUT})\n --exclude-label <name> skip issues with this label (repeatable; default: ${DEFAULT_EXCLUDED.join(\", \")})\n --sample <n> judge a seeded random sample of n issues\n --seed <n> seed for --sample (default: 4498)\n --model <id> Jev model (default: ${DEFAULT_MODEL})\n --concurrency <n> calls in flight (default: 6)`;\n\nasync function main(argv: readonly string[], cwd: string): Promise<void> {\n const { values } = parseArgs({\n args: [...argv],\n options: {\n repo: { type: \"string\" },\n ref: { type: \"string\", default: \"origin/main\" },\n out: { type: \"string\", default: DEFAULT_OUT },\n \"exclude-label\": { type: \"string\", multiple: true },\n sample: { type: \"string\" },\n seed: { type: \"string\", default: \"4498\" },\n model: { type: \"string\", default: DEFAULT_MODEL },\n concurrency: { type: \"string\", default: \"6\" },\n help: { type: \"boolean\", short: \"h\" },\n },\n });\n if (values.help === true) {\n console.log(USAGE);\n return;\n }\n const root = git(cwd, [\"rev-parse\", \"--show-toplevel\"]).trim();\n const repo = resolveRepo(values.repo, cwd);\n const [owner = \"\", name = \"\"] = repo.split(\"/\");\n const outPath = isAbsolute(values.out)\n ? values.out\n : resolve(root, values.out);\n const apiKey = requireApiKey();\n const log = (line: string) => console.error(line);\n\n log(`snapshotting ${values.ref}…`);\n const snapshot = snapshotRepo(root, values.ref);\n log(`fetching open and closed issues of ${repo}…`);\n const rows = await runBacklogSweep({\n snapshot,\n open: fetchOpenIssues(owner, name),\n closed: fetchClosedIssues(repo),\n jev: httpJevClient({\n questions,\n model: values.model,\n post: fetchPost(apiKey),\n }),\n outPath,\n excludeLabels: values[\"exclude-label\"] ?? DEFAULT_EXCLUDED,\n ...(values.sample === undefined\n ? {}\n : { sample: { size: Number(values.sample), seed: Number(values.seed) } }),\n concurrency: Number(values.concurrency),\n log,\n });\n\n const tally = new Map<string, number>();\n for (const r of rows)\n tally.set(r.proposal.kind, (tally.get(r.proposal.kind) ?? 0) + 1);\n const input = rows.reduce((n, r) => n + r.usage.input_tokens, 0);\n log(\n `${JSON.stringify(Object.fromEntries(tally))} input tokens ${input} → ${outPath}`,\n );\n}\n\nmain(process.argv.slice(2), process.cwd()).catch((error: unknown) => {\n console.error(\n `backlog-sweep: ${error instanceof Error ? error.message : String(error)}\\n(backlog-sweep --help for usage)`,\n );\n process.exitCode = 1;\n});\n"],"mappings":";;;;;;;;;;;;;;;;AACA,SAAS,YAAY,eAAe;AACpC,SAAS,iBAAiB;AAY1B,IAAM,cAAc;AACpB,IAAM,mBAAmB,CAAC,aAAa,yBAAyB;AAEhE,IAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mDAOqC,WAAW;AAAA,8EACgB,iBAAiB,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA,gDAGzD,aAAa;AAAA;AAG7D,eAAe,KAAK,MAAyB,KAA4B;AACvE,QAAM,EAAE,OAAO,IAAI,UAAU;AAAA,IAC3B,MAAM,CAAC,GAAG,IAAI;AAAA,IACd,SAAS;AAAA,MACP,MAAM,EAAE,MAAM,SAAS;AAAA,MACvB,KAAK,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA,MAC9C,KAAK,EAAE,MAAM,UAAU,SAAS,YAAY;AAAA,MAC5C,iBAAiB,EAAE,MAAM,UAAU,UAAU,KAAK;AAAA,MAClD,QAAQ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AED,QAAM,QAAQ,oBAAI,IAAoB;AACtC,aAAW,KAAK;AACd,UAAM,IAAI,EAAE,SAAS,OAAO,MAAM,IAAI,EAAE,SAAS,IAAI,KAAK,KAAK,CAAC;AAClE,QAAM,QAAQ,KAAK,OAAO,CAAC,GAAG,MAAM,IAAI,EAAE,MAAM,cAAc,CAAC;AAC/D;AAAA,IACE,GAAG,KAAK,UAAU,OAAO,YAAY,KAAK,CAAC,CAAC,iBAAiB,KAAK,WAAM,OAAO;AAAA,EACjF;AACF;AAEA,KAAK,QAAQ,KAAK,MAAM,CAAC,GAAG,QAAQ,IAAI,CAAC,EAAE,MAAM,CAAC,UAAmB;AACnE,UAAQ;AAAA,IACN,kBAAkB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA;AAAA,EAC1E;AACA,UAAQ,WAAW;AACrB,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { parseArgs } from \"node:util\";\nimport { DEFAULT_NEIGHBOURS, findDuplicateGroups } from \"./duplicates.js\";\nimport { fetchClosedIssues, fetchOpenIssues } from \"./github.js\";\nimport {\n DEFAULT_MODEL,\n fetchPost,\n httpJevClient,\n requireApiKey,\n} from \"./jev.js\";\nimport { git, resolveRepo, snapshotRepo } from \"./repo.js\";\nimport { runBacklogSweep } from \"./run.js\";\nimport { PROPOSAL_KINDS, pairQuestions, questions } from \"./verdict.js\";\n\nconst DEFAULT_OUT = \".backlog-sweep/verdicts.json\";\nconst DEFAULT_DUPLICATES_OUT = \".backlog-sweep/duplicates.json\";\nconst DEFAULT_EXCLUDED = [\"type:epic\", \"status:awaiting-release\"];\n\nconst USAGE = `backlog-sweep [options]\n\n Gather evidence for every open issue of a GitHub repository and ask Jev whether each is still\n needed. Writes one proposal per issue — keep, verify, close, close_duplicate or review. It closes\n nothing; closing anything is a human's call.\n\n --repo <owner/name> repository to sweep (default: this checkout's origin remote)\n --ref <ref> tree the evidence is read from (default: origin/main)\n --out <file> verdict file (default: ${DEFAULT_OUT})\n --exclude-label <name> skip issues with this label (repeatable; default: ${DEFAULT_EXCLUDED.join(\", \")})\n --sample <n> judge a seeded random sample of n issues\n --seed <n> seed for --sample (default: 4498)\n --model <id> Jev model (default: ${DEFAULT_MODEL})\n --concurrency <n> calls in flight (default: 6)\n\nbacklog-sweep duplicates [options]\n\n Group open issues that are the same concrete defect: each issue's nearest open neighbours by\n TF-IDF become candidate pairs, Jev judges each pair, and a confident duplicate joins two issues.\n It closes nothing and labels nothing.\n\n --repo <owner/name> repository to read (default: this checkout's origin remote)\n --out <file> duplicate groups (default: ${DEFAULT_DUPLICATES_OUT})\n --exclude-label <name> skip issues with this label (repeatable; default: ${DEFAULT_EXCLUDED.join(\", \")})\n --neighbours <n> nearest open issues paired with each issue (default: ${DEFAULT_NEIGHBOURS})\n --model <id> Jev model (default: ${DEFAULT_MODEL})\n --concurrency <n> calls in flight (default: 6)`;\n\nconst log = (line: string) => console.error(line);\n\nfunction outPathOf(root: string, out: string): string {\n return isAbsolute(out) ? out : resolve(root, out);\n}\n\nasync function sweep(argv: readonly string[], cwd: string): Promise<void> {\n const { values } = parseArgs({\n args: [...argv],\n options: {\n repo: { type: \"string\" },\n ref: { type: \"string\", default: \"origin/main\" },\n out: { type: \"string\", default: DEFAULT_OUT },\n \"exclude-label\": { type: \"string\", multiple: true },\n sample: { type: \"string\" },\n seed: { type: \"string\", default: \"4498\" },\n model: { type: \"string\", default: DEFAULT_MODEL },\n concurrency: { type: \"string\", default: \"6\" },\n help: { type: \"boolean\", short: \"h\" },\n },\n });\n if (values.help === true) {\n console.log(USAGE);\n return;\n }\n const root = git(cwd, [\"rev-parse\", \"--show-toplevel\"]).trim();\n const repo = resolveRepo(values.repo, cwd);\n const [owner = \"\", name = \"\"] = repo.split(\"/\");\n const outPath = outPathOf(root, values.out);\n const apiKey = requireApiKey();\n\n log(`snapshotting ${values.ref}…`);\n const snapshot = snapshotRepo(root, values.ref);\n log(`fetching open and closed issues of ${repo}…`);\n const rows = await runBacklogSweep({\n snapshot,\n open: fetchOpenIssues(owner, name),\n closed: fetchClosedIssues(repo),\n jev: httpJevClient({\n questions,\n model: values.model,\n post: fetchPost(apiKey),\n }),\n outPath,\n excludeLabels: values[\"exclude-label\"] ?? DEFAULT_EXCLUDED,\n ...(values.sample === undefined\n ? {}\n : { sample: { size: Number(values.sample), seed: Number(values.seed) } }),\n concurrency: Number(values.concurrency),\n log,\n });\n\n const tally = new Map(PROPOSAL_KINDS.map((kind) => [kind, 0]));\n for (const r of rows)\n tally.set(r.proposal.kind, (tally.get(r.proposal.kind) ?? 0) + 1);\n const input = rows.reduce((n, r) => n + r.usage.input_tokens, 0);\n log(\n `${JSON.stringify(Object.fromEntries(tally))} input tokens ${input} → ${outPath}`,\n );\n}\n\nasync function duplicates(argv: readonly string[], cwd: string): Promise<void> {\n const { values } = parseArgs({\n args: [...argv],\n options: {\n repo: { type: \"string\" },\n out: { type: \"string\", default: DEFAULT_DUPLICATES_OUT },\n \"exclude-label\": { type: \"string\", multiple: true },\n neighbours: { type: \"string\", default: String(DEFAULT_NEIGHBOURS) },\n model: { type: \"string\", default: DEFAULT_MODEL },\n concurrency: { type: \"string\", default: \"6\" },\n help: { type: \"boolean\", short: \"h\" },\n },\n });\n if (values.help === true) {\n console.log(USAGE);\n return;\n }\n const neighbours = Number(values.neighbours);\n if (!Number.isInteger(neighbours) || neighbours < 1)\n throw new Error(\n `--neighbours takes a positive integer, got ${values.neighbours}`,\n );\n const root = git(cwd, [\"rev-parse\", \"--show-toplevel\"]).trim();\n const repo = resolveRepo(values.repo, cwd);\n const [owner = \"\", name = \"\"] = repo.split(\"/\");\n const outPath = outPathOf(root, values.out);\n const apiKey = requireApiKey();\n\n log(`fetching open issues of ${repo}…`);\n const report = await findDuplicateGroups({\n open: fetchOpenIssues(owner, name),\n jev: httpJevClient({\n questions: pairQuestions,\n model: values.model,\n post: fetchPost(apiKey),\n }),\n excludeLabels: values[\"exclude-label\"] ?? DEFAULT_EXCLUDED,\n neighbours,\n concurrency: Number(values.concurrency),\n log,\n });\n mkdirSync(dirname(outPath), { recursive: true });\n writeFileSync(outPath, `${JSON.stringify(report, null, 1)}\\n`);\n log(\n `${report.candidates} pairs asked, ${report.unanswered.length} unanswered, ${report.groups.length} groups, input tokens ${report.inputTokens} → ${outPath}`,\n );\n}\n\nfunction main(argv: readonly string[], cwd: string): Promise<void> {\n const [command, ...rest] = argv;\n return command === \"duplicates\" ? duplicates(rest, cwd) : sweep(argv, cwd);\n}\n\nmain(process.argv.slice(2), process.cwd()).catch((error: unknown) => {\n console.error(\n `backlog-sweep: ${error instanceof Error ? error.message : String(error)}\\n(backlog-sweep --help for usage)`,\n );\n process.exitCode = 1;\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,SAAS,WAAW,qBAAqB;AACzC,SAAS,SAAS,YAAY,eAAe;AAC7C,SAAS,iBAAiB;AAa1B,IAAM,cAAc;AACpB,IAAM,yBAAyB;AAC/B,IAAM,mBAAmB,CAAC,aAAa,yBAAyB;AAEhE,IAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mDAQqC,WAAW;AAAA,8EACgB,iBAAiB,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA,gDAGzD,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uDAUN,sBAAsB;AAAA,8EACC,iBAAiB,KAAK,IAAI,CAAC;AAAA,iFACxB,kBAAkB;AAAA,gDACnD,aAAa;AAAA;AAG7D,IAAM,MAAM,CAAC,SAAiB,QAAQ,MAAM,IAAI;AAEhD,SAAS,UAAU,MAAc,KAAqB;AACpD,SAAO,WAAW,GAAG,IAAI,MAAM,QAAQ,MAAM,GAAG;AAClD;AAEA,eAAe,MAAM,MAAyB,KAA4B;AACxE,QAAM,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