co-maintainer 0.6.5 → 0.6.7

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.
@@ -2,9 +2,11 @@ This project bundles the following third-party assets. Their licenses are
2
2
  reproduced below and apply to those assets only, not to the rest of
3
3
  co-maintainer, which is distributed under the MIT License (see LICENSE).
4
4
 
5
- 1. Outfit (font files under src/server/pages/fonts/)
5
+ 1. Outfit (font files under src/server/pages/fonts/ and docs/assets/fonts/)
6
6
  2. Lucide (icon SVGs under src/server/pages/icons/)
7
7
  3. Feather-derived icons (a subset of the Lucide icons listed below)
8
+ 4. JetBrains Mono (font file under docs/assets/fonts/)
9
+ 5. Simple Icons (brand SVGs under docs/assets/logos/)
8
10
 
9
11
 
10
12
  ================================================================================
@@ -159,3 +161,26 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
159
161
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
160
162
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
161
163
  SOFTWARE.
164
+
165
+
166
+ ================================================================================
167
+ 4. JetBrains Mono
168
+ ================================================================================
169
+
170
+ Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)
171
+
172
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
173
+ The license text is reproduced in section 1 above, and is also available
174
+ with a FAQ at: https://scripts.sil.org/OFL
175
+
176
+
177
+ ================================================================================
178
+ 5. Simple Icons
179
+ ================================================================================
180
+
181
+ The Claude, OpenAI and Google Gemini marks under docs/assets/logos/ come from
182
+ Simple Icons (https://simpleicons.org), whose SVG files are released under
183
+ CC0 1.0 Universal (https://creativecommons.org/publicdomain/zero/1.0/).
184
+
185
+ The marks themselves are trademarks of their owners. They are shown only to
186
+ name AI tools that can read co-maintainer's output, and imply no endorsement.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",
@@ -2,6 +2,7 @@ import { cacheGet, cacheSet } from "../store/cache_db.js";
2
2
  import { isNotFound, readTextFile } from "../util/runtime.js";
3
3
  import { formatError } from "../cli/error.js";
4
4
  import { recordRateLimitWait } from "../services/rate_limit.js";
5
+ import { log } from "../util/log.js";
5
6
  /** A provider call and an unusable response are both retried this many times
6
7
  * before the batch gives up and the run fails. */
7
8
  export const MAX_ATTEMPTS = 3;
@@ -66,12 +67,12 @@ export class AiBatch {
66
67
  const reason = this.validate?.(request, cached.response) ?? null;
67
68
  if (reason === null) {
68
69
  results[index] = cached.response;
69
- console.log(`[ai] cache hit ${request.job} ${id.slice(0, 8)}`);
70
+ log("ai", `cache hit ${request.job} ${id.slice(0, 8)}`);
70
71
  }
71
72
  else {
72
73
  delete this.records[id];
73
74
  await this.persist();
74
- console.log(`[ai] dropped unusable cache record ${request.job} ${id.slice(0, 8)}: ${reason}`);
75
+ log("ai", `dropped unusable cache record ${request.job} ${id.slice(0, 8)}: ${reason}`);
75
76
  pending.push({ index, id, request });
76
77
  }
77
78
  }
@@ -87,15 +88,15 @@ export class AiBatch {
87
88
  }
88
89
  }
89
90
  let cursor = 0;
90
- console.log(`[ai] queue ${requests.length} jobs · ${pending.length} pending · concurrency ${this.concurrency}`);
91
+ log("ai", `queue ${requests.length} jobs · ${pending.length} pending · concurrency ${this.concurrency}`);
91
92
  const worker = async () => {
92
93
  while (cursor < pending.length) {
93
94
  const item = pending[cursor++];
94
95
  const startedAt = Date.now();
95
- console.log(`[ai] start ${item.request.job} ${item.id.slice(0, 8)}`);
96
+ log("ai", `start ${item.request.job} ${item.id.slice(0, 8)}`);
96
97
  const heartbeat = setInterval(() => {
97
98
  const seconds = Math.round((Date.now() - startedAt) / 1000);
98
- console.log(`[ai] still running ${item.request.job} ${item.id.slice(0, 8)} · ${seconds}s`);
99
+ log("ai", `still running ${item.request.job} ${item.id.slice(0, 8)} · ${seconds}s`);
99
100
  }, 15_000);
100
101
  try {
101
102
  await this.completeUnit(item, results, usage, startedAt);
@@ -125,7 +126,7 @@ export class AiBatch {
125
126
  const limit = isRateLimit(reason)
126
127
  ? MAX_RATE_LIMIT_ATTEMPTS
127
128
  : MAX_ATTEMPTS;
128
- console.log(`[ai] call failed ${attempt}/${limit} ${item.request.job} ${item.id.slice(0, 8)}: ${reason}`);
129
+ log("ai", `call failed ${attempt}/${limit} ${item.request.job} ${item.id.slice(0, 8)}: ${reason}`);
129
130
  if (attempt < limit) {
130
131
  const wait = retryDelayMs(reason, attempt);
131
132
  if (wait > 0) {
@@ -135,24 +136,24 @@ export class AiBatch {
135
136
  reason,
136
137
  seconds: wait / 1000,
137
138
  });
138
- console.log(`[ai] waiting ${Math.round(wait / 1000)}s before retry (provider is rate limiting)`);
139
+ log("ai", `waiting ${Math.round(wait / 1000)}s before retry (provider is rate limiting)`);
139
140
  await new Promise((resolve) => setTimeout(resolve, wait));
140
141
  }
141
142
  continue;
142
143
  }
143
- console.log(`[ai] gave up ${item.request.job} ${item.id.slice(0, 8)} after ${attempt} attempts; continuing without it`);
144
+ log("ai", `gave up ${item.request.job} ${item.id.slice(0, 8)} after ${attempt} attempts; continuing without it`);
144
145
  return;
145
146
  }
146
147
  const reason = this.validate?.(item.request, response) ?? null;
147
148
  if (reason !== null && attempt < MAX_ATTEMPTS) {
148
- console.log(`[ai] output rejected ${attempt}/${MAX_ATTEMPTS} ${item.request.job} ${item.id.slice(0, 8)}: ${reason}`);
149
+ log("ai", `output rejected ${attempt}/${MAX_ATTEMPTS} ${item.request.job} ${item.id.slice(0, 8)}: ${reason}`);
149
150
  continue;
150
151
  }
151
152
  if (reason !== null) {
152
153
  // The last attempt still failed its contract. Do not cache it, so a
153
154
  // later sync retries instead of replaying the same unusable output, and
154
155
  // do not throw: the run keeps its other work.
155
- console.log(`[ai] dropping ${item.request.job} ${item.id.slice(0, 8)} after ${attempt} attempts: ${reason}`);
156
+ log("ai", `dropping ${item.request.job} ${item.id.slice(0, 8)} after ${attempt} attempts: ${reason}`);
156
157
  return;
157
158
  }
158
159
  this.records[item.id] = {
@@ -164,7 +165,7 @@ export class AiBatch {
164
165
  await this.persist();
165
166
  if (usage)
166
167
  await usage(item.request.job, response);
167
- console.log(`[ai] ${attempt === 1 ? "done" : `retried (${attempt})`} ${item.request.job} ${item.id.slice(0, 8)} · ${Math.round((Date.now() - startedAt) / 1000)}s`);
168
+ log("ai", `${attempt === 1 ? "done" : `retried (${attempt})`} ${item.request.job} ${item.id.slice(0, 8)} · ${Math.round((Date.now() - startedAt) / 1000)}s`);
168
169
  return;
169
170
  }
170
171
  }
@@ -178,12 +178,23 @@ export async function parseArgs(args) {
178
178
  arg === "--review-upstream" ||
179
179
  arg === "--disable-codegraph" ||
180
180
  arg === "--run" ||
181
+ arg === "--json" ||
181
182
  arg === "--only-request-changed-pr" ||
182
183
  arg === "--experimental-siwc")
183
184
  continue;
184
185
  if (arg.startsWith("--") && !known)
185
186
  die(unknownOptionMessage(arg, command));
186
187
  }
188
+ // `--json` must not prompt. `review` strips the flag before this parse and
189
+ // sets the same switch itself.
190
+ const json = rest.includes("--json");
191
+ if (json)
192
+ setCliInteractive(false);
193
+ // `probe --run` would print the probe and then the init on one stdout, which
194
+ // is not one JSON document.
195
+ if (json && rest.includes("--run")) {
196
+ die("--run cannot be used with --json");
197
+ }
187
198
  const explicitAi = rest.some((arg) => arg.startsWith("--ai="));
188
199
  const experimentalSiwc = rest.includes("--experimental-siwc");
189
200
  if (experimentalSiwc && explicitAi) {
@@ -292,6 +303,7 @@ export async function parseArgs(args) {
292
303
  logTime: rest.includes("--log-time"),
293
304
  reviewUpstream: rest.includes("--review-upstream"),
294
305
  run: rest.includes("--run"),
306
+ ...(json ? { json: true } : {}),
295
307
  useCodegraph: command === "review" ? !rest.includes("--disable-codegraph") : false,
296
308
  envPath,
297
309
  improveMatrix: value("improve-matrix") ?? 1,
@@ -0,0 +1,45 @@
1
+ /** `--json` for `probe`, `init` and `sync`.
2
+ *
3
+ * Help and the docs listed `--json` for these commands while the parser
4
+ * refused it, and nothing wrote a JSON result for them. Each builder returns
5
+ * the one document the command prints on stdout, in the same `schemaVersion 1`
6
+ * envelope as `review --json` and the CLI error. Progress stays on stderr.
7
+ */
8
+ import type { Estimate } from "../ai/estimate.ts";
9
+ import type { RunSummary } from "../util/run_summary.ts";
10
+ export type ProbeJsonInput = {
11
+ repo: string;
12
+ recommended: string;
13
+ research: {
14
+ pullRequests: number;
15
+ sampledPullRequests: number;
16
+ commits: number;
17
+ usefulCommits: number;
18
+ maxPrMonths: number | null;
19
+ maxCommits: number | null;
20
+ maxPullRequestChangeLines: number | null;
21
+ reasons: string[];
22
+ };
23
+ estimate: Estimate;
24
+ /** The prose cost line, kept so a missing dollar range still says why. */
25
+ costNote: string;
26
+ durationMs: number;
27
+ };
28
+ export declare function buildProbeJson(input: ProbeJsonInput): string;
29
+ export type SetupJsonInput = {
30
+ command: "init" | "sync";
31
+ repo: string;
32
+ skillPath: string;
33
+ /** Section keys this run rewrote; empty when the guide was already current. */
34
+ changed: string[];
35
+ facts: number;
36
+ pullRequests: number;
37
+ commits: number;
38
+ reviewGuide: "detailed" | "single" | "skipped";
39
+ validation: {
40
+ errors: string[];
41
+ warnings: string[];
42
+ };
43
+ summary: RunSummary;
44
+ };
45
+ export declare function buildSetupJson(input: SetupJsonInput): string;
@@ -0,0 +1,45 @@
1
+ export function buildProbeJson(input) {
2
+ const { estimate } = input;
3
+ return JSON.stringify({
4
+ schemaVersion: 1,
5
+ ok: true,
6
+ command: "probe",
7
+ repo: input.repo,
8
+ recommended: input.recommended,
9
+ research: input.research,
10
+ estimate: {
11
+ extract: estimate.extract,
12
+ synth: estimate.synth,
13
+ tokensIn: estimate.tokensIn.map(Math.round),
14
+ tokensOut: estimate.tokensOut.map(Math.round),
15
+ seconds: estimate.seconds.map(Math.round),
16
+ usd: estimate.usd ?? null,
17
+ cost: input.costNote,
18
+ basis: estimate.basis,
19
+ },
20
+ durationMs: input.durationMs,
21
+ });
22
+ }
23
+ export function buildSetupJson(input) {
24
+ const { summary } = input;
25
+ return JSON.stringify({
26
+ schemaVersion: 1,
27
+ ok: true,
28
+ command: input.command,
29
+ repo: input.repo,
30
+ skillPath: input.skillPath,
31
+ changed: input.changed,
32
+ facts: input.facts,
33
+ pullRequests: input.pullRequests,
34
+ commits: input.commits,
35
+ reviewGuide: input.reviewGuide,
36
+ validation: input.validation,
37
+ usage: {
38
+ tokensIn: summary.tokensIn,
39
+ tokensOut: summary.tokensOut,
40
+ costUsd: summary.costUsd,
41
+ costNote: summary.costNote ?? null,
42
+ },
43
+ durationMs: summary.durationMs === null ? null : Math.round(summary.durationMs),
44
+ });
45
+ }
@@ -1,10 +1,18 @@
1
1
  import { clientFor, runInitOrRemake } from "../../services/setup.js";
2
2
  import { probePlan } from "../../services/probe.js";
3
- import { log, startHeartbeat } from "../../util/log.js";
3
+ import { log, startHeartbeat, withCliLogsToStderr } from "../../util/log.js";
4
4
  import { estimateCostLine, estimateInit, readJobHistory, } from "../../ai/estimate.js";
5
5
  import { loadPrices } from "../../ai/pricing.js";
6
6
  import { cacheSet } from "../../store/cache_db.js";
7
+ import { buildProbeJson } from "../command_json.js";
7
8
  export async function runProbe(options) {
9
+ // With `--json` stdout carries the one document, so progress moves to stderr.
10
+ if (options.json)
11
+ await withCliLogsToStderr(() => probe(options));
12
+ else
13
+ await probe(options);
14
+ }
15
+ async function probe(options) {
8
16
  const operationStarted = performance.now();
9
17
  const stopHeartbeat = startHeartbeat("probing repository");
10
18
  const client = clientFor(options);
@@ -17,13 +25,6 @@ export async function runProbe(options) {
17
25
  const analysis = plan.analysis;
18
26
  const command = plan.command;
19
27
  await cacheSet("probe", options.repo, JSON.stringify(plan.report));
20
- console.log(`\nrecommended\n ${command}`);
21
- console.log("\nresearch");
22
- console.log(` PRs: ${analysis.report.pullRequests} · sampled: ${analysis.report.sampledPullRequests}`);
23
- console.log(` commits: ${analysis.report.commits} · useful: ${analysis.report.usefulCommits}`);
24
- console.log(` windows: PR months=${analysis.maxPrMonths ?? "all"} · commits=${analysis.maxCommits ?? "all"} · diff lines=${analysis.maxPullRequestChangeLines ?? "all"}`);
25
- for (const reason of analysis.reasons)
26
- console.log(` - ${reason}`);
27
28
  // The estimate is separate from the recommendation: the flags say what to
28
29
  // read, this says what that costs in time and dollars. Prices are
29
30
  // only fetched when an OpenRouter model would actually be billed, so a
@@ -46,11 +47,40 @@ export async function runProbe(options) {
46
47
  prices: prices.prices,
47
48
  history,
48
49
  });
50
+ const costLine = estimateCostLine(estimate, options.ai, needsPrices && prices.source === "unavailable");
51
+ if (options.json) {
52
+ stopHeartbeat();
53
+ console.log(buildProbeJson({
54
+ repo: options.repo,
55
+ recommended: command,
56
+ research: {
57
+ pullRequests: Number(analysis.report.pullRequests ?? 0),
58
+ sampledPullRequests: Number(analysis.report.sampledPullRequests ?? 0),
59
+ commits: Number(analysis.report.commits ?? 0),
60
+ usefulCommits: Number(analysis.report.usefulCommits ?? 0),
61
+ maxPrMonths: analysis.maxPrMonths ?? null,
62
+ maxCommits: analysis.maxCommits ?? null,
63
+ maxPullRequestChangeLines: analysis.maxPullRequestChangeLines ?? null,
64
+ reasons: analysis.reasons,
65
+ },
66
+ estimate,
67
+ costNote: costLine,
68
+ durationMs: Math.round(performance.now() - operationStarted),
69
+ }));
70
+ return;
71
+ }
72
+ console.log(`\nrecommended\n ${command}`);
73
+ console.log("\nresearch");
74
+ console.log(` PRs: ${analysis.report.pullRequests} · sampled: ${analysis.report.sampledPullRequests}`);
75
+ console.log(` commits: ${analysis.report.commits} · useful: ${analysis.report.usefulCommits}`);
76
+ console.log(` windows: PR months=${analysis.maxPrMonths ?? "all"} · commits=${analysis.maxCommits ?? "all"} · diff lines=${analysis.maxPullRequestChangeLines ?? "all"}`);
77
+ for (const reason of analysis.reasons)
78
+ console.log(` - ${reason}`);
49
79
  console.log("\nestimate");
50
80
  console.log(` AI jobs: ${estimate.extract} extract + ${estimate.synth} synth`);
51
81
  console.log(` tokens: ${range(estimate.tokensIn)} in · ${range(estimate.tokensOut)} out`);
52
82
  console.log(` time: ${secondsRange(estimate.seconds)}s`);
53
- console.log(` cost: ${estimateCostLine(estimate, options.ai, needsPrices && prices.source === "unavailable")}`);
83
+ console.log(` cost: ${costLine}`);
54
84
  console.log(` basis: ${estimate.basis === "history"
55
85
  ? "this repository's recorded jobs"
56
86
  : "the cm-dx-lab calibration"}; an estimate, not a bill`);
@@ -18,6 +18,11 @@ const OUTPUT_FLAGS = {
18
18
  { name: "log-time", description: "Print how long each phase took." },
19
19
  ],
20
20
  };
21
+ /** `serve` runs until stopped and prints no result, so it has no `--json`. */
22
+ const SERVE_OUTPUT_FLAGS = {
23
+ title: OUTPUT_FLAGS.title,
24
+ flags: OUTPUT_FLAGS.flags.filter((flag) => flag.name !== "json"),
25
+ };
21
26
  /** `review` alone can print for a CI run. */
22
27
  const REVIEW_OUTPUT_FLAGS = {
23
28
  title: OUTPUT_FLAGS.title,
@@ -209,7 +214,7 @@ export const COMMANDS = [
209
214
  },
210
215
  {
211
216
  name: "only-request-changed-pr",
212
- description: "Read only the pull requests that changed the requested files.",
217
+ description: "Read only the pull requests with at least one CHANGES_REQUESTED review.",
213
218
  },
214
219
  ],
215
220
  },
@@ -763,7 +768,7 @@ export const COMMANDS = [
763
768
  },
764
769
  ],
765
770
  },
766
- OUTPUT_FLAGS,
771
+ SERVE_OUTPUT_FLAGS,
767
772
  ],
768
773
  examples: ["co-maintainer serve --port=5000"],
769
774
  },
@@ -116,7 +116,7 @@ export async function githubFetch(url, init) {
116
116
  reason: `secondary rate limit (HTTP ${response.status})`,
117
117
  seconds: retryAfter,
118
118
  });
119
- console.log(`[github] secondary rate limit, waiting ${retryAfter}s (attempt ${attempt} of 3)`);
119
+ log("github", `secondary rate limit, waiting ${retryAfter}s (attempt ${attempt} of 3)`);
120
120
  await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
121
121
  continue;
122
122
  }
@@ -1,4 +1,5 @@
1
1
  import { AiBatch } from "../ai/batch.js";
2
+ import { log } from "../util/log.js";
2
3
  /** A fact read out of a single pull request describes that request, not the
3
4
  * repository. `origin` is absent on facts written before the field existed, so
4
5
  * those count as repository policy. */
@@ -213,7 +214,7 @@ export async function synthesizeReviewGuides(provider, repo, ai, model, concurre
213
214
  const full = cleanGuide(fullResponse?.text ?? "");
214
215
  if (!full) {
215
216
  // Not a failure: SKILL.md and CODEBASE.md are written anyway.
216
- console.log("[ai] synth_guide produced nothing usable; skipping the guide");
217
+ log("ai", "synth_guide produced nothing usable; skipping the guide");
217
218
  return undefined;
218
219
  }
219
220
  const fullLines = full.split("\n").length;
@@ -1,6 +1,7 @@
1
1
  import { AiBatch } from "../ai/batch.js";
2
2
  import { isPullRequestFact } from "./guide.js";
3
3
  import { sectionAllowsPrFacts, sectionTitles } from "./sections.js";
4
+ import { log } from "../util/log.js";
4
5
  const allowedSections = new Set([
5
6
  "identity",
6
7
  "devloop",
@@ -371,7 +372,7 @@ ${files}`, 2_200));
371
372
  return true;
372
373
  }));
373
374
  if (index % 10 === 0 || index === responses.length - 1) {
374
- console.log(`[ai] extract units ${index + 1}/${responses.length}`);
375
+ log("ai", `extract units ${index + 1}/${responses.length}`);
375
376
  }
376
377
  }
377
378
  return facts;