co-maintainer 0.6.11 → 0.6.13
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 +71 -78
- package/dist/package.json +2 -1
- package/dist/src/ai/anthropic.js +6 -6
- package/dist/src/ai/oauth/sign-in-with-chatgpt.js +7 -4
- package/dist/src/ai/openai.d.ts +2 -2
- package/dist/src/ai/openai.js +15 -6
- package/dist/src/ai/openrouter.js +3 -3
- package/dist/src/cli/commands/set.js +5 -15
- package/dist/src/cli/error.d.ts +7 -0
- package/dist/src/cli/error.js +28 -5
- package/dist/src/config.d.ts +3 -0
- package/dist/src/server/auth.js +8 -1
- package/dist/src/store/app_db.d.ts +3 -1
- package/dist/src/store/app_db.js +7 -2
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,110 +1,100 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://www.npmjs.com/package/co-maintainer)
|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
2
5
|
|
|
3
|
-
|
|
6
|
+

|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
[Docs](https://co-maintainer.com/docs/getting-started.html) ·
|
|
7
|
-
[Cloud](https://cloud.co-maintainer.com) (hosted, free, early access, invite only for now)
|
|
8
|
+
# co-maintainer
|
|
8
9
|
|
|
9
|
-
An
|
|
10
|
+
An open source PR reviewer that learns how your repo is reviewed, then reviews like that.
|
|
10
11
|
|
|
11
|
-
It
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
implementation, testing, review, and release decisions.
|
|
12
|
+
It reads your code, your merged PRs and the review comments on them, and writes
|
|
13
|
+
review guides as plain Markdown. Every review follows those guides. It runs on
|
|
14
|
+
your machine or on your own server, with your own model key.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
[Website](https://co-maintainer.com/?utm_source=github&utm_content=readme) ·
|
|
17
|
+
[Docs](https://co-maintainer.com/docs/getting-started.html?utm_source=github&utm_content=readme) ·
|
|
18
|
+
[Newsletter](https://buttondown.com/murat)
|
|
17
19
|
|
|
18
20
|
```sh
|
|
19
21
|
npm install -g co-maintainer
|
|
22
|
+
|
|
23
|
+
co-maintainer probe owner/repo # reads only, spends nothing
|
|
24
|
+
co-maintainer init owner/repo --include-codebase --include-pull-requests \
|
|
25
|
+
--max-pr-months=12 --max-commits=500
|
|
26
|
+
co-maintainer review owner/repo 123 # review a pull request
|
|
20
27
|
```
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
> [!TIP]
|
|
30
|
+
> `co-maintainer review` with no arguments reviews your local branch before you
|
|
31
|
+
> open the PR. `co-maintainer serve` runs the GitHub App and a dashboard for every
|
|
32
|
+
> repository on your own server.
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
<img src="docs/assets/readme/spacer.gif" width="1" height="48"/>
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
co-maintainer probe owner/repo --auth=gh
|
|
36
|
+
## What it does
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
<table>
|
|
39
|
+
<tr>
|
|
40
|
+
<td><img src="docs/assets/readme/01-finding.png" alt="A P1 finding on PR 54"></td>
|
|
41
|
+
<td><img src="docs/assets/readme/02-ask.png" alt="Asking the reviewer what it meant"></td>
|
|
42
|
+
</tr>
|
|
43
|
+
<tr>
|
|
44
|
+
<td><img src="docs/assets/readme/03-carry-over.png" alt="New, still open and closed findings"></td>
|
|
45
|
+
<td><img src="docs/assets/readme/04-policy.png" alt="Review policy options"></td>
|
|
46
|
+
</tr>
|
|
47
|
+
<tr>
|
|
48
|
+
<td><img src="docs/assets/readme/05-probe.png" alt="probe output before init"></td>
|
|
49
|
+
<td><img src="docs/assets/readme/06-json.png" alt="review --json output for agents"></td>
|
|
50
|
+
</tr>
|
|
51
|
+
</table>
|
|
35
52
|
|
|
36
|
-
|
|
53
|
+
<img src="docs/assets/readme/spacer.gif" width="1" height="32"/>
|
|
37
54
|
|
|
38
|
-
|
|
39
|
-
co-maintainer review --json # machine-readable stdout, logs on stderr
|
|
40
|
-
co-maintainer review --output=github # annotations and a job summary inside GitHub Actions
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Settings live in `config.json`, so a flag you use every time can be saved once:
|
|
55
|
+
## How it works
|
|
44
56
|
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
```mermaid
|
|
58
|
+
flowchart LR
|
|
59
|
+
A[Your repo<br>code, PRs, review comments] --> B[init]
|
|
60
|
+
B --> C[Review guides<br>plain Markdown]
|
|
61
|
+
C --> D[review]
|
|
62
|
+
E[New merged PRs] --> F[sync] --> C
|
|
51
63
|
```
|
|
52
64
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
A low model reads the history and extracts evidence. A high model writes the
|
|
66
|
+
guides and does the review. You pick both models. Read what it learned with
|
|
67
|
+
`co-maintainer view`.
|
|
56
68
|
|
|
57
|
-
|
|
58
|
-
full CLI help. Every guide the CLI writes is also readable from the dashboard,
|
|
59
|
-
and the dashboard keeps its guides separate from the CLI's. See
|
|
60
|
-
[dashboard.md](docs/md/dashboard.md).
|
|
69
|
+
<img src="docs/assets/readme/spacer.gif" width="1" height="32"/>
|
|
61
70
|
|
|
62
|
-
##
|
|
71
|
+
## Pricing
|
|
63
72
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
| Solo | Team | Company |
|
|
74
|
+
| ------------------- | ----------------------------------------- | --------------------------------- |
|
|
75
|
+
| $0 | $0 per seat | $0 forever |
|
|
76
|
+
| The CLI on a laptop | One server, guides shared with `--remote` | Your infrastructure, MIT licensed |
|
|
67
77
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
| Result quality against OCR | 2 to 3x better |
|
|
71
|
-
| Speed against OCR | 2 to 8x faster |
|
|
72
|
-
| Tokens per review against OCR | 70 to 200x fewer |
|
|
73
|
-
| Cost per review against OCR | 60 to 270x cheaper |
|
|
78
|
+
You only pay your model provider. No telemetry from the CLI, `serve` or the
|
|
79
|
+
dashboard. How we earn: donations and thanks.
|
|
74
80
|
|
|
75
|
-
|
|
76
|
-
xychart-beta
|
|
77
|
-
title "Monthly PR Review Cost by Developer Count"
|
|
78
|
-
x-axis [1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 100]
|
|
79
|
-
y-axis "Monthly Cost ($)" 0 --> 13000
|
|
80
|
-
line "OCR" [129.6, 648, 1296, 2592, 3888, 5184, 6480, 7776, 9072, 10368, 12960]
|
|
81
|
-
line "co-maintainer" [2, 10, 20, 40, 60, 80, 100, 120, 140, 160, 200]
|
|
82
|
-
```
|
|
81
|
+
<img src="docs/assets/readme/spacer.gif" width="1" height="32"/>
|
|
83
82
|
|
|
84
|
-
|
|
83
|
+
## Benchmark
|
|
85
84
|
|
|
86
|
-
|
|
85
|
+
`core_v3`: 30 PRs in one target repo, 14 with seeded defects and 16 clean
|
|
86
|
+
controls, so precision is measured too.
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
deliberately seeded, hand-verified defects in a dedicated target repo. Half of
|
|
92
|
-
the PRs are kept as defect-free controls, so precision is measurable too, not
|
|
93
|
-
just recall. Full breakdown, per-PR results, and methodology:
|
|
94
|
-
[`benchmark/core_v3/README.md`](benchmark/core_v3/README.md).
|
|
88
|
+
| Recall | Precision | F1 | Cost / PR | Time / PR |
|
|
89
|
+
| ------ | --------- | ----- | --------- | --------- |
|
|
90
|
+
| 0.857 | 0.353 | 0.500 | $0.0045 | 28.9s |
|
|
95
91
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
| PRs reviewed | 30 (14 defective, 16 control) | one target repo |
|
|
99
|
-
| F1 | 0.500 | against seeded defects only |
|
|
100
|
-
| Precision | 0.353 | 1.00 false positive per control PR |
|
|
101
|
-
| Recall | 0.857 | 12 of 14 defects found |
|
|
102
|
-
| Avg cost / PR | $0.0045 | low and high model together |
|
|
103
|
-
| Avg time / PR | 28.9s | sequential, no concurrency |
|
|
92
|
+
deepseek-v4-flash + gpt-5.6-luna, judge gpt-5.6-luna, 2026-09-14. A small
|
|
93
|
+
dataset, read it as a signal. Details: [`benchmark/core_v3`](benchmark/core_v3/README.md).
|
|
104
94
|
|
|
105
|
-
|
|
95
|
+
<img src="docs/assets/readme/spacer.gif" width="1" height="32"/>
|
|
106
96
|
|
|
107
|
-
|
|
97
|
+
## Development
|
|
108
98
|
|
|
109
99
|
```sh
|
|
110
100
|
npm install
|
|
@@ -114,4 +104,7 @@ npm run docs:build # rebuild docs/ from docs/md/
|
|
|
114
104
|
npm run e2e # end-to-end CLI loop
|
|
115
105
|
npm run review-local-e2e # fake-AI local review loop
|
|
116
106
|
npm run dashboard:smoke # browser smoke test
|
|
107
|
+
npm run e2e:simulate # init in a simulated GitHub, see CONTRIBUTING.md
|
|
117
108
|
```
|
|
109
|
+
|
|
110
|
+
Made by [Murat Kirazkaya](https://muratkirazkaya.com). If it helps you, a star or a thank you is how this project gets paid.
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "co-maintainer",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.13",
|
|
4
4
|
"description": "An imitator of yours, A PR review tool like co-maintainer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"swe-prbench-prepare": "node benchmark/swe-prbench/prepare_dataset.ts",
|
|
55
55
|
"e2e": "node scripts/e2e.ts",
|
|
56
56
|
"e2e:fake": "node scripts/e2e_fake.ts",
|
|
57
|
+
"e2e:simulate": "node scripts/e2e_simulate.ts",
|
|
57
58
|
"review-local-e2e": "node scripts/review_local_e2e.ts",
|
|
58
59
|
"docs:build": "node scripts/build_docs.ts",
|
|
59
60
|
"pack:smoke": "node scripts/pack_smoke.ts",
|
package/dist/src/ai/anthropic.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getEnv } from "../util/runtime.js";
|
|
2
2
|
import { outputLimitError } from "./provider.js";
|
|
3
|
-
import { CliError, EXIT_RUNTIME, EXIT_USAGE, networkFailure, } from "../cli/error.js";
|
|
3
|
+
import { CliError, EXIT_RUNTIME, EXIT_USAGE, networkFailure, readBody, } from "../cli/error.js";
|
|
4
4
|
/** Required on every Messages request and the only version the errors below
|
|
5
5
|
* are written against. */
|
|
6
6
|
export const ANTHROPIC_VERSION = "2023-06-01";
|
|
@@ -251,20 +251,20 @@ export class AnthropicProvider {
|
|
|
251
251
|
// only a hint (the prompt also asks for a fenced JSON block), so one retry
|
|
252
252
|
// without it beats failing the review outright.
|
|
253
253
|
if (response.status === 400 && request.responseFormat) {
|
|
254
|
-
const detail = await response
|
|
254
|
+
const detail = await readBody(this.endpoint, response);
|
|
255
255
|
if (/output_config|json_schema|structured/i.test(detail)) {
|
|
256
256
|
const { responseFormat: _dropped, ...withoutSchema } = request;
|
|
257
257
|
response = await this.post(messagesBody(this.model, withoutSchema));
|
|
258
258
|
if (response.ok) {
|
|
259
|
-
return parseMessagesBody((await response
|
|
259
|
+
return parseMessagesBody(JSON.parse(await readBody(this.endpoint, response)), this.model);
|
|
260
260
|
}
|
|
261
|
-
throw anthropicError(this.model, response.status, await response
|
|
261
|
+
throw anthropicError(this.model, response.status, await readBody(this.endpoint, response));
|
|
262
262
|
}
|
|
263
263
|
throw anthropicError(this.model, response.status, detail);
|
|
264
264
|
}
|
|
265
265
|
if (!response.ok) {
|
|
266
|
-
throw anthropicError(this.model, response.status, await response
|
|
266
|
+
throw anthropicError(this.model, response.status, await readBody(this.endpoint, response));
|
|
267
267
|
}
|
|
268
|
-
return parseMessagesBody((await response
|
|
268
|
+
return parseMessagesBody(JSON.parse(await readBody(this.endpoint, response)), this.model);
|
|
269
269
|
}
|
|
270
270
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { createHash, createPublicKey, randomBytes, randomUUID, verify, } from "node:crypto";
|
|
16
16
|
import { spawn } from "node:child_process";
|
|
17
17
|
import { createServer } from "node:http";
|
|
18
|
-
import { CliError, EXIT_RUNTIME, EXIT_USAGE, networkFailure, } from "../../cli/error.js";
|
|
18
|
+
import { CliError, EXIT_RUNTIME, EXIT_USAGE, networkFailure, readBody, } from "../../cli/error.js";
|
|
19
19
|
import { getConfigDir } from "../../config.js";
|
|
20
20
|
import { chmod, getEnv, isNotFound, mkdir, readTextFileSync, remove, writeTextFile, } from "../../util/runtime.js";
|
|
21
21
|
import { parseResponsesBody, readResponsesStream, responsesBody, } from "../openai.js";
|
|
@@ -45,6 +45,9 @@ function accountBase() {
|
|
|
45
45
|
function apiBase() {
|
|
46
46
|
return (getEnv("CM_SIWC_API_URL") ?? "https://api.openai.com/v1").replace(/\/$/, "");
|
|
47
47
|
}
|
|
48
|
+
function responsesEndpoint() {
|
|
49
|
+
return `${apiBase()}/responses`;
|
|
50
|
+
}
|
|
48
51
|
export function credentialsDir() {
|
|
49
52
|
return getEnv("CM_SIWC_DIR") ?? `${getConfigDir()}/co-maintainer/oauth`;
|
|
50
53
|
}
|
|
@@ -516,7 +519,7 @@ export class SignInWithChatGptProvider {
|
|
|
516
519
|
this.model = normalizeModel(model);
|
|
517
520
|
}
|
|
518
521
|
async post(accessToken, request) {
|
|
519
|
-
const endpoint =
|
|
522
|
+
const endpoint = responsesEndpoint();
|
|
520
523
|
try {
|
|
521
524
|
return await fetch(endpoint, {
|
|
522
525
|
method: "POST",
|
|
@@ -539,10 +542,10 @@ export class SignInWithChatGptProvider {
|
|
|
539
542
|
response = await this.post(creds.access_token, request);
|
|
540
543
|
}
|
|
541
544
|
if (!response.ok) {
|
|
542
|
-
const detail = await
|
|
545
|
+
const detail = await readBody(responsesEndpoint(), response);
|
|
543
546
|
throw await planError(creds, this.model, response.status, detail);
|
|
544
547
|
}
|
|
545
|
-
const json = await readResponsesStream(response);
|
|
548
|
+
const json = await readResponsesStream(response, responsesEndpoint());
|
|
546
549
|
if (json.status === "failed") {
|
|
547
550
|
const error = (json.error ?? {});
|
|
548
551
|
throw await planError(creds, this.model, Number(error.status ?? 400), JSON.stringify({ error }));
|
package/dist/src/ai/openai.d.ts
CHANGED
|
@@ -49,8 +49,8 @@ export declare function parseResponsesBody(json: Json, model: string, provider?:
|
|
|
49
49
|
* fills it). The terminal response supplies `usage` and `status`; the
|
|
50
50
|
* collected items supply `output`, so the shared {@link parseResponsesBody}
|
|
51
51
|
* sees the same shape on both routes. A stream with no terminal response
|
|
52
|
-
* throws. */
|
|
53
|
-
export declare function readResponsesStream(response: Response): Promise<Json>;
|
|
52
|
+
* throws, and one cut mid-way names `url`'s host. */
|
|
53
|
+
export declare function readResponsesStream(response: Response, url: string): Promise<Json>;
|
|
54
54
|
export declare class OpenAiProvider implements AiProvider {
|
|
55
55
|
readonly supportsTools = true;
|
|
56
56
|
private readonly endpoint;
|
package/dist/src/ai/openai.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getEnv } from "../util/runtime.js";
|
|
2
2
|
import { outputLimitError, withoutRefusedPart } from "./provider.js";
|
|
3
|
-
import { CliError, EXIT_RUNTIME, EXIT_USAGE, networkFailure, } from "../cli/error.js";
|
|
3
|
+
import { CliError, EXIT_RUNTIME, EXIT_USAGE, connectionCut, networkFailure, readBody, } from "../cli/error.js";
|
|
4
4
|
/** `CM_OPENAI_URL` points at a local fake in tests. Unset means the real
|
|
5
5
|
* endpoint, so production behavior is unchanged. */
|
|
6
6
|
export function openAiBase() {
|
|
@@ -171,8 +171,8 @@ export function parseResponsesBody(json, model, provider = "openai") {
|
|
|
171
171
|
* fills it). The terminal response supplies `usage` and `status`; the
|
|
172
172
|
* collected items supply `output`, so the shared {@link parseResponsesBody}
|
|
173
173
|
* sees the same shape on both routes. A stream with no terminal response
|
|
174
|
-
* throws. */
|
|
175
|
-
export async function readResponsesStream(response) {
|
|
174
|
+
* throws, and one cut mid-way names `url`'s host. */
|
|
175
|
+
export async function readResponsesStream(response, url) {
|
|
176
176
|
if (!response.body) {
|
|
177
177
|
throw new Error("OpenAI returned no response body to stream");
|
|
178
178
|
}
|
|
@@ -182,7 +182,16 @@ export async function readResponsesStream(response) {
|
|
|
182
182
|
let terminal;
|
|
183
183
|
const items = [];
|
|
184
184
|
for (;;) {
|
|
185
|
-
|
|
185
|
+
let chunk;
|
|
186
|
+
try {
|
|
187
|
+
chunk = await reader.read();
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
if (error instanceof TypeError)
|
|
191
|
+
throw connectionCut(url, error);
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
const { done, value } = chunk;
|
|
186
195
|
if (done)
|
|
187
196
|
break;
|
|
188
197
|
buffer += decoder.decode(value, { stream: true });
|
|
@@ -256,9 +265,9 @@ export class OpenAiProvider {
|
|
|
256
265
|
for (;;) {
|
|
257
266
|
const response = await this.post(responsesBody(this.model, current));
|
|
258
267
|
if (response.ok) {
|
|
259
|
-
return parseResponsesBody((await response
|
|
268
|
+
return parseResponsesBody(JSON.parse(await readBody(this.endpoint, response)), this.model);
|
|
260
269
|
}
|
|
261
|
-
const detail = await response
|
|
270
|
+
const detail = await readBody(this.endpoint, response);
|
|
262
271
|
const lighter = response.status === 400
|
|
263
272
|
? withoutRefusedPart(current, detail, /text\.format|json_schema|structured/i)
|
|
264
273
|
: undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { chatBody, parseChatResponse, withoutRefusedPart } from "./provider.js";
|
|
2
2
|
import { getEnv } from "../util/runtime.js";
|
|
3
|
-
import { CliError, EXIT_RUNTIME, EXIT_USAGE, networkFailure, } from "../cli/error.js";
|
|
3
|
+
import { CliError, EXIT_RUNTIME, EXIT_USAGE, networkFailure, readBody, } from "../cli/error.js";
|
|
4
4
|
/** `CM_OPENROUTER_URL` points the provider at a local fake in tests. It is
|
|
5
5
|
* only a default override: with the env unset the real endpoint is used, so
|
|
6
6
|
* nothing changes for users. */
|
|
@@ -79,9 +79,9 @@ export class OpenRouterProvider {
|
|
|
79
79
|
for (;;) {
|
|
80
80
|
const response = await this.post(chatBody(this.model, current));
|
|
81
81
|
if (response.ok) {
|
|
82
|
-
return parseChatResponse((await response
|
|
82
|
+
return parseChatResponse(JSON.parse(await readBody(this.host.endpoint, response)), this.host.provider, this.model);
|
|
83
83
|
}
|
|
84
|
-
const detail = await response
|
|
84
|
+
const detail = await readBody(this.host.endpoint, response);
|
|
85
85
|
const lighter = response.status === 400
|
|
86
86
|
? withoutRefusedPart(current, detail, /response_format|json_schema|structured/i)
|
|
87
87
|
: undefined;
|
|
@@ -2,9 +2,7 @@ import { readConfig, configPath, savedKeyProvider, writeRepoConfig, writeUserCon
|
|
|
2
2
|
import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../../review/system_prompt.js";
|
|
3
3
|
import { canonicalRepoName } from "../../util/repo_name.js";
|
|
4
4
|
import { hashPassword, passwordProblem } from "../../util/password.js";
|
|
5
|
-
import {
|
|
6
|
-
import { appDbPath, closeAppDb, openAppDb } from "../../store/app_db.js";
|
|
7
|
-
import { existsSync } from "node:fs";
|
|
5
|
+
import { nowIso } from "../../util/time.js";
|
|
8
6
|
import { readTextFile } from "../../util/runtime.js";
|
|
9
7
|
import { verifyAnthropic, verifyOpenAi, verifyOpenRouter, } from "../../ai/verify.js";
|
|
10
8
|
import { verifyOpenCode } from "../../ai/opencode.js";
|
|
@@ -354,23 +352,15 @@ export async function runSet(args) {
|
|
|
354
352
|
console.error(`[set] could not verify the key and model (${result.reason}); saved anyway.`);
|
|
355
353
|
}
|
|
356
354
|
}
|
|
357
|
-
await writeUserConfig(patch);
|
|
358
355
|
// A changed password, allowed user, or sign-in method must not leave old
|
|
359
|
-
// dashboard sessions valid.
|
|
360
|
-
//
|
|
356
|
+
// dashboard sessions valid. A running `serve` holds app.db, so instead of
|
|
357
|
+
// deleting sessions here the change time goes into config.json and
|
|
358
|
+
// `verifySession` refuses every session issued before it.
|
|
361
359
|
const credentialChanged = patch.dashboardPasswordHash !== undefined ||
|
|
362
360
|
patch.passwordAuthDisabled !== undefined ||
|
|
363
361
|
patch.githubAuthEnabled !== undefined ||
|
|
364
362
|
patch.githubOAuthAllowedUser !== undefined;
|
|
365
|
-
|
|
366
|
-
await openAppDb();
|
|
367
|
-
try {
|
|
368
|
-
deleteAllSessions();
|
|
369
|
-
}
|
|
370
|
-
finally {
|
|
371
|
-
await closeAppDb();
|
|
372
|
-
}
|
|
373
|
-
}
|
|
363
|
+
await writeUserConfig(credentialChanged ? { ...patch, credentialsChangedAt: nowIso() } : patch);
|
|
374
364
|
const summary = Object.entries(patch).map(([key, value]) => value === undefined
|
|
375
365
|
? `${key} (unset)`
|
|
376
366
|
: `${key}=${secretFields.has(key) ? "•".repeat(8) : value}`);
|
package/dist/src/cli/error.d.ts
CHANGED
|
@@ -37,3 +37,10 @@ export declare function formatError(error: unknown): string;
|
|
|
37
37
|
/** A failed `fetch` as a message that names the host and the cause.
|
|
38
38
|
* Node's own text is only `fetch failed`, which says neither. */
|
|
39
39
|
export declare function networkFailure(url: string, error: unknown): CliError;
|
|
40
|
+
/** A response whose body stopped arriving, as a message that names the host
|
|
41
|
+
* and the cause. The host was reached, so "Could not reach" would be wrong,
|
|
42
|
+
* and Node's own text is only `terminated`, which says neither. */
|
|
43
|
+
export declare function connectionCut(url: string, error: unknown): CliError;
|
|
44
|
+
/** Reads a response body. fetch rejects with a `TypeError` when the
|
|
45
|
+
* connection closes mid-body; that becomes {@link connectionCut}. */
|
|
46
|
+
export declare function readBody(url: string, response: Response): Promise<string>;
|
package/dist/src/cli/error.js
CHANGED
|
@@ -49,16 +49,39 @@ export function formatError(error) {
|
|
|
49
49
|
}
|
|
50
50
|
return error instanceof Error ? error.message : String(error);
|
|
51
51
|
}
|
|
52
|
+
function hostOf(url) {
|
|
53
|
+
try {
|
|
54
|
+
return new URL(url).host;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Keep the raw value when it does not parse.
|
|
58
|
+
return url;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
52
61
|
/** A failed `fetch` as a message that names the host and the cause.
|
|
53
62
|
* Node's own text is only `fetch failed`, which says neither. */
|
|
54
63
|
export function networkFailure(url, error) {
|
|
55
64
|
const code = error.cause?.code;
|
|
56
|
-
|
|
65
|
+
return new CliError("network_failed", `Could not reach ${hostOf(url)}${code ? `: ${code}` : "."}`, undefined, EXIT_RUNTIME);
|
|
66
|
+
}
|
|
67
|
+
/** A response whose body stopped arriving, as a message that names the host
|
|
68
|
+
* and the cause. The host was reached, so "Could not reach" would be wrong,
|
|
69
|
+
* and Node's own text is only `terminated`, which says neither. */
|
|
70
|
+
export function connectionCut(url, error) {
|
|
71
|
+
const cause = error
|
|
72
|
+
.cause;
|
|
73
|
+
const detail = [cause?.code, cause?.message].filter(Boolean).join(": ");
|
|
74
|
+
return new CliError("connection_cut", `${hostOf(url)} closed the connection before the answer was complete${detail ? ` (${detail}).` : "."}`, "The request reached the provider and the answer was cut off. Run the command again.", EXIT_RUNTIME);
|
|
75
|
+
}
|
|
76
|
+
/** Reads a response body. fetch rejects with a `TypeError` when the
|
|
77
|
+
* connection closes mid-body; that becomes {@link connectionCut}. */
|
|
78
|
+
export async function readBody(url, response) {
|
|
57
79
|
try {
|
|
58
|
-
|
|
80
|
+
return await response.text();
|
|
59
81
|
}
|
|
60
|
-
catch {
|
|
61
|
-
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof TypeError)
|
|
84
|
+
throw connectionCut(url, error);
|
|
85
|
+
throw error;
|
|
62
86
|
}
|
|
63
|
-
return new CliError("network_failed", `Could not reach ${host}${code ? `: ${code}` : "."}`, undefined, EXIT_RUNTIME);
|
|
64
87
|
}
|
package/dist/src/config.d.ts
CHANGED
|
@@ -71,6 +71,9 @@ export type UserConfig = {
|
|
|
71
71
|
githubAuthEnabled?: boolean;
|
|
72
72
|
/** scrypt hash of the dashboard password, never the password itself. */
|
|
73
73
|
dashboardPasswordHash?: string;
|
|
74
|
+
/** When `set` last changed a sign-in credential. Dashboard sessions issued
|
|
75
|
+
* before it are refused. */
|
|
76
|
+
credentialsChangedAt?: string;
|
|
74
77
|
defaults?: {
|
|
75
78
|
maxCommits?: number;
|
|
76
79
|
maxPrMonths?: number;
|
package/dist/src/server/auth.js
CHANGED
|
@@ -125,7 +125,14 @@ export async function createSession() {
|
|
|
125
125
|
}
|
|
126
126
|
export async function verifySession(token) {
|
|
127
127
|
const session = getSession(await sha256Hex(token));
|
|
128
|
-
|
|
128
|
+
if (!session)
|
|
129
|
+
return undefined;
|
|
130
|
+
// Read per check, like the password hash, so a credential changed with
|
|
131
|
+
// `co-maintainer set` signs everyone out without restarting `serve`.
|
|
132
|
+
const changedAt = readConfig().credentialsChangedAt;
|
|
133
|
+
if (changedAt && session.created_at < changedAt)
|
|
134
|
+
return undefined;
|
|
135
|
+
return { username: session.username };
|
|
129
136
|
}
|
|
130
137
|
export async function logout(token) {
|
|
131
138
|
deleteSession(await sha256Hex(token));
|
|
@@ -8,7 +8,9 @@ export declare function appDbPath(): string;
|
|
|
8
8
|
export declare function appDbLockPath(): string;
|
|
9
9
|
/** Where the backup taken before a migration lives, and what it covers. */
|
|
10
10
|
export declare function backupPaths(): BackupPaths;
|
|
11
|
-
/** The pid holding the database lock, or `undefined` when nothing live does.
|
|
11
|
+
/** The pid holding the database lock, or `undefined` when nothing live does.
|
|
12
|
+
* Our own pid is never another holder: in a container `serve` gets the same
|
|
13
|
+
* pid on every start, so a lock left by a hard stop names the new process. */
|
|
12
14
|
export declare function liveLockPid(): Promise<number | undefined>;
|
|
13
15
|
export declare function releaseLock(): Promise<void>;
|
|
14
16
|
export declare function isAppDbOpen(): boolean;
|
package/dist/src/store/app_db.js
CHANGED
|
@@ -47,7 +47,9 @@ async function lastVersion() {
|
|
|
47
47
|
throw error;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
/** The pid holding the database lock, or `undefined` when nothing live does.
|
|
50
|
+
/** The pid holding the database lock, or `undefined` when nothing live does.
|
|
51
|
+
* Our own pid is never another holder: in a container `serve` gets the same
|
|
52
|
+
* pid on every start, so a lock left by a hard stop names the new process. */
|
|
51
53
|
export async function liveLockPid() {
|
|
52
54
|
let pid;
|
|
53
55
|
try {
|
|
@@ -57,7 +59,10 @@ export async function liveLockPid() {
|
|
|
57
59
|
if (!isNotFound(error))
|
|
58
60
|
throw error;
|
|
59
61
|
}
|
|
60
|
-
return pid !== undefined &&
|
|
62
|
+
return pid !== undefined &&
|
|
63
|
+
Number.isInteger(pid) &&
|
|
64
|
+
pid !== process.pid &&
|
|
65
|
+
isProcessAlive(pid)
|
|
61
66
|
? pid
|
|
62
67
|
: undefined;
|
|
63
68
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "co-maintainer",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.13",
|
|
4
4
|
"description": "An imitator of yours, A PR review tool like co-maintainer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"swe-prbench-prepare": "node benchmark/swe-prbench/prepare_dataset.ts",
|
|
55
55
|
"e2e": "node scripts/e2e.ts",
|
|
56
56
|
"e2e:fake": "node scripts/e2e_fake.ts",
|
|
57
|
+
"e2e:simulate": "node scripts/e2e_simulate.ts",
|
|
57
58
|
"review-local-e2e": "node scripts/review_local_e2e.ts",
|
|
58
59
|
"docs:build": "node scripts/build_docs.ts",
|
|
59
60
|
"pack:smoke": "node scripts/pack_smoke.ts",
|