co-maintainer 0.7.2-beta.1 → 0.7.3
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/dist/package.json +2 -1
- package/dist/src/ai/anthropic.d.ts +1 -1
- package/dist/src/ai/anthropic.js +1 -1
- package/dist/src/ai/batch.d.ts +1 -1
- package/dist/src/ai/batch.js +3 -3
- package/dist/src/ai/copy_rule.d.ts +7 -0
- package/dist/src/ai/copy_rule.js +23 -0
- package/dist/src/ai/estimate.js +3 -3
- package/dist/src/ai/fake.js +2 -1
- package/dist/src/ai/mermaid.js +1 -0
- package/dist/src/ai/oauth/registry.d.ts +1 -1
- package/dist/src/ai/oauth/sign-in-with-chatgpt.d.ts +4 -4
- package/dist/src/ai/oauth/sign-in-with-chatgpt.js +6 -6
- package/dist/src/ai/openai.d.ts +3 -3
- package/dist/src/ai/openai.js +4 -4
- package/dist/src/ai/openrouter.d.ts +1 -1
- package/dist/src/ai/openrouter.js +1 -1
- package/dist/src/ai/pricing.js +1 -1
- package/dist/src/ai/provider.d.ts +2 -0
- package/dist/src/ai/provider.js +8 -2
- package/dist/src/ai/verify.d.ts +1 -1
- package/dist/src/ai/verify.js +1 -1
- package/dist/src/cli/args.js +1 -1
- package/dist/src/cli/command_json.d.ts +4 -2
- package/dist/src/cli/command_json.js +1 -0
- package/dist/src/cli/commands/config.d.ts +1 -1
- package/dist/src/cli/commands/config.js +1 -1
- package/dist/src/cli/commands/oauth.js +1 -1
- package/dist/src/cli/commands/probe.js +1 -1
- package/dist/src/cli/commands/review.js +2 -0
- package/dist/src/cli/commands/serve.d.ts +1 -1
- package/dist/src/cli/commands/serve.js +1 -1
- package/dist/src/cli/commands/set.d.ts +1 -1
- package/dist/src/cli/commands/set.js +23 -6
- package/dist/src/cli/commands/view.js +2 -2
- package/dist/src/cli/error.d.ts +1 -1
- package/dist/src/cli/error.js +1 -1
- package/dist/src/cli/pr_carry.d.ts +2 -0
- package/dist/src/cli/pr_carry.js +2 -2
- package/dist/src/cli/prompt.d.ts +2 -2
- package/dist/src/cli/prompt.js +3 -3
- package/dist/src/cli/review_args.js +2 -2
- package/dist/src/cli/review_carry.d.ts +3 -1
- package/dist/src/cli/review_carry.js +5 -3
- package/dist/src/cli/review_result.d.ts +13 -5
- package/dist/src/cli/review_result.js +19 -9
- package/dist/src/config.d.ts +20 -11
- package/dist/src/config.js +3 -3
- package/dist/src/github/app.d.ts +1 -1
- package/dist/src/github/app.js +1 -1
- package/dist/src/github/app_manifest.d.ts +1 -1
- package/dist/src/github/app_manifest.js +1 -1
- package/dist/src/github/client.d.ts +1 -1
- package/dist/src/github/client.js +1 -1
- package/dist/src/github/collect.d.ts +7 -1
- package/dist/src/github/collect.js +41 -16
- package/dist/src/github/gh.js +2 -2
- package/dist/src/github/jwt.d.ts +1 -1
- package/dist/src/github/jwt.js +1 -1
- package/dist/src/github/oauth.js +2 -2
- package/dist/src/knowledge/facts.js +3 -3
- package/dist/src/knowledge/guide.d.ts +24 -1
- package/dist/src/knowledge/guide.js +46 -16
- package/dist/src/knowledge/guide_ids.d.ts +9 -0
- package/dist/src/knowledge/guide_ids.js +26 -7
- package/dist/src/knowledge/probe.js +1 -1
- package/dist/src/knowledge/rule_changes.d.ts +18 -0
- package/dist/src/knowledge/rule_changes.js +41 -0
- package/dist/src/knowledge/rules.d.ts +11 -0
- package/dist/src/knowledge/rules.js +10 -1
- package/dist/src/knowledge/skill.js +1 -1
- package/dist/src/knowledge/stable_ids.d.ts +29 -0
- package/dist/src/knowledge/stable_ids.js +90 -0
- package/dist/src/knowledge/synthesis.d.ts +13 -1
- package/dist/src/knowledge/synthesis.js +94 -26
- package/dist/src/knowledge/types.d.ts +16 -0
- package/dist/src/local/carry_over_store.d.ts +1 -1
- package/dist/src/local/carry_over_store.js +1 -1
- package/dist/src/local/codegraph_prepare.js +1 -1
- package/dist/src/local/git_ops.js +1 -1
- package/dist/src/local/review_local.js +6 -5
- package/dist/src/local/review_lock.d.ts +1 -1
- package/dist/src/pr/checkout.d.ts +3 -3
- package/dist/src/pr/checkout.js +7 -7
- package/dist/src/pr/codegraph_tool_args.d.ts +1 -1
- package/dist/src/pr/codegraph_tool_args.js +1 -1
- package/dist/src/pr/findings.d.ts +3 -0
- package/dist/src/pr/findings.js +29 -10
- package/dist/src/pr/findings_json.d.ts +2 -2
- package/dist/src/pr/findings_json.js +15 -2
- package/dist/src/pr/github_revision.js +1 -1
- package/dist/src/pr/review_copy.d.ts +2 -3
- package/dist/src/pr/review_copy.js +2 -3
- package/dist/src/pr/reviewer.d.ts +7 -3
- package/dist/src/pr/reviewer.js +26 -26
- package/dist/src/pr/scope.d.ts +8 -8
- package/dist/src/pr/scope.js +4 -4
- package/dist/src/pr/snapshot.d.ts +2 -2
- package/dist/src/remote/client.js +4 -3
- package/dist/src/remote/schema.d.ts +1 -1
- package/dist/src/remote/schema.js +1 -1
- package/dist/src/remote/server/body.d.ts +1 -1
- package/dist/src/remote/server/body.js +1 -1
- package/dist/src/remote/server/guides.js +1 -1
- package/dist/src/remote/validate.js +1 -1
- package/dist/src/review/blocking.d.ts +3 -3
- package/dist/src/review/blocking.js +2 -2
- package/dist/src/review/carry_over.d.ts +9 -1
- package/dist/src/review/carry_over.js +10 -2
- package/dist/src/review/diagram.js +7 -6
- package/dist/src/review/engine.d.ts +1 -1
- package/dist/src/review/guides.js +1 -1
- package/dist/src/review/references.d.ts +68 -0
- package/dist/src/review/references.js +176 -0
- package/dist/src/review/system_prompt.d.ts +1 -1
- package/dist/src/review/system_prompt.js +1 -1
- package/dist/src/server/api/jobs.js +2 -2
- package/dist/src/server/api/repos.js +1 -1
- package/dist/src/server/app.js +1 -1
- package/dist/src/server/auth.d.ts +3 -3
- package/dist/src/server/auth.js +9 -4
- package/dist/src/server/http.js +5 -5
- package/dist/src/server/pages/activity.js +1 -1
- package/dist/src/server/pages/add_repo.js +1 -0
- package/dist/src/server/pages/client.d.ts +2 -2
- package/dist/src/server/pages/client.js +2 -2
- package/dist/src/server/pages/home.d.ts +1 -1
- package/dist/src/server/pages/home.js +1 -1
- package/dist/src/server/pages/icons.d.ts +1 -1
- package/dist/src/server/pages/icons.js +1 -1
- package/dist/src/server/pages/layout.d.ts +2 -2
- package/dist/src/server/pages/layout.js +3 -3
- package/dist/src/server/pages/pr.js +4 -0
- package/dist/src/server/pages/rate_limit_waits.js +2 -2
- package/dist/src/server/pages/references.d.ts +2 -0
- package/dist/src/server/pages/references.js +55 -0
- package/dist/src/server/pages/repo.js +26 -0
- package/dist/src/server/pages/repo_settings.js +1 -0
- package/dist/src/server/pages/router.js +3 -2
- package/dist/src/server/pages/styles.d.ts +2 -2
- package/dist/src/server/pages/styles.js +2 -2
- package/dist/src/server/pages/ui.d.ts +1 -1
- package/dist/src/server/pages/ui.js +2 -2
- package/dist/src/server/webhook/index.js +1 -1
- package/dist/src/services/clear.d.ts +2 -2
- package/dist/src/services/clear.js +2 -2
- package/dist/src/services/dashboard.d.ts +2 -0
- package/dist/src/services/dashboard.js +2 -0
- package/dist/src/services/probe.js +1 -1
- package/dist/src/services/push_review.js +4 -1
- package/dist/src/services/remote_review.js +5 -2
- package/dist/src/services/remote_review_abort.d.ts +1 -1
- package/dist/src/services/remote_review_abort.js +1 -1
- package/dist/src/services/remote_tokens.js +1 -1
- package/dist/src/services/replies.js +0 -2
- package/dist/src/services/review.d.ts +3 -5
- package/dist/src/services/review.js +43 -18
- package/dist/src/services/rules_build.d.ts +20 -1
- package/dist/src/services/rules_build.js +85 -6
- package/dist/src/services/setup.d.ts +2 -2
- package/dist/src/services/setup.js +36 -11
- package/dist/src/services/watch_comments.js +1 -2
- package/dist/src/services/watch_notes.js +1 -3
- package/dist/src/store/app_db.d.ts +1 -1
- package/dist/src/store/app_db.js +2 -2
- package/dist/src/store/findings.d.ts +2 -0
- package/dist/src/store/findings.js +3 -3
- package/dist/src/store/jobs.d.ts +2 -2
- package/dist/src/store/jobs.js +3 -3
- package/dist/src/store/migrations.d.ts +2 -2
- package/dist/src/store/migrations.js +35 -18
- package/dist/src/store/rows.d.ts +4 -2
- package/dist/src/store/rows.js +1 -1
- package/dist/src/store/rule_events.d.ts +15 -0
- package/dist/src/store/rule_events.js +20 -0
- package/dist/src/store/sessions.d.ts +1 -1
- package/dist/src/store/sessions.js +2 -2
- package/dist/src/store/sqlite.js +2 -2
- package/dist/src/tools/codegraph.d.ts +1 -1
- package/dist/src/tools/codegraph.js +3 -3
- package/dist/src/tools/codegraph_exec.d.ts +1 -1
- package/dist/src/tools/codegraph_exec.js +1 -1
- package/dist/src/types.d.ts +6 -2
- package/dist/src/util/keyed_lock.d.ts +1 -1
- package/dist/src/util/keyed_lock.js +1 -1
- package/dist/src/util/log.js +1 -1
- package/dist/src/util/redact.js +2 -1
- package/dist/src/util/run_summary.d.ts +3 -3
- package/dist/src/util/run_summary.js +3 -3
- package/dist/src/util/runtime.d.ts +4 -4
- package/dist/src/util/runtime.js +5 -5
- package/dist/src/util/time.d.ts +1 -1
- package/dist/src/util/time.js +1 -1
- package/package.json +2 -1
package/dist/src/github/jwt.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* KEY"). Web Crypto's `importKey("pkcs8", ...)` only takes PKCS#8. The two
|
|
3
3
|
* differ by a fixed 26-byte wrapper around the same PKCS#1 bytes: a version
|
|
4
4
|
* INTEGER, the rsaEncryption AlgorithmIdentifier, and an OCTET STRING tag
|
|
5
|
-
* around the PKCS#1 payload
|
|
5
|
+
* around the PKCS#1 payload, this file builds that wrapper by hand rather
|
|
6
6
|
* than pulling in an ASN.1 library for one fixed structure. */
|
|
7
7
|
export declare function pkcs1ToPkcs8(pkcs1: Uint8Array): Uint8Array;
|
|
8
8
|
export declare function importAppPrivateKey(pem: string): Promise<CryptoKey>;
|
package/dist/src/github/jwt.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* KEY"). Web Crypto's `importKey("pkcs8", ...)` only takes PKCS#8. The two
|
|
3
3
|
* differ by a fixed 26-byte wrapper around the same PKCS#1 bytes: a version
|
|
4
4
|
* INTEGER, the rsaEncryption AlgorithmIdentifier, and an OCTET STRING tag
|
|
5
|
-
* around the PKCS#1 payload
|
|
5
|
+
* around the PKCS#1 payload, this file builds that wrapper by hand rather
|
|
6
6
|
* than pulling in an ASN.1 library for one fixed structure. */
|
|
7
7
|
const RSA_ALGORITHM_IDENTIFIER = Uint8Array.from([
|
|
8
8
|
0x30,
|
package/dist/src/github/oauth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/** The user-to-server side of a GitHub App's OAuth flow
|
|
2
|
-
* GitHub"
|
|
1
|
+
/** The user-to-server side of a GitHub App's OAuth flow, "Sign in with
|
|
2
|
+
* GitHub", reusing the App's own client ID/secret. No separate OAuth App
|
|
3
3
|
* is needed. */
|
|
4
4
|
import { githubFetch } from "./client.js";
|
|
5
5
|
export function githubAuthorizeUrl(clientId, redirectUri, state) {
|
|
@@ -95,7 +95,7 @@ function sourceModuleClaim(path, content) {
|
|
|
95
95
|
return undefined;
|
|
96
96
|
return `\`${path}\` contains ${symbols
|
|
97
97
|
.map((symbol) => `\`${symbol}\``)
|
|
98
|
-
.join(", ")}
|
|
98
|
+
.join(", ")}. Keep related changes in this module.`;
|
|
99
99
|
}
|
|
100
100
|
function commandPrefix(source) {
|
|
101
101
|
if (source.tree.some((path) => /pnpm-lock\.yaml$/.test(path)))
|
|
@@ -316,7 +316,7 @@ export function extractFacts(source, options) {
|
|
|
316
316
|
if (examples.length) {
|
|
317
317
|
add(facts, fact("style", `Recent commit examples: ${examples
|
|
318
318
|
.map((message) => `\`${message.slice(0, 100)}\``)
|
|
319
|
-
.join("
|
|
319
|
+
.join(", ")}.`, "commit history", 2));
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
const currentPaths = new Set(source.tree);
|
|
@@ -327,7 +327,7 @@ export function extractFacts(source, options) {
|
|
|
327
327
|
const files = counts(changedFiles).slice(0, 10);
|
|
328
328
|
add(facts, fact("review-bar", `Frequently changed files include ${files
|
|
329
329
|
.map(([path]) => `\`${path}\``)
|
|
330
|
-
.join(", ")}
|
|
330
|
+
.join(", ")}. Check nearby tests and workflows before editing.`, "pull request files", 2));
|
|
331
331
|
}
|
|
332
332
|
return [...facts.values()];
|
|
333
333
|
}
|
|
@@ -8,6 +8,12 @@ export type ReviewDocuments = {
|
|
|
8
8
|
* findings it merges. */
|
|
9
9
|
rules?: (GuideRule & {
|
|
10
10
|
pullRequests: number[];
|
|
11
|
+
/** The review comment links of the merged findings, when they were
|
|
12
|
+
* kept. A pull request with no link here shows as plain text. */
|
|
13
|
+
links?: {
|
|
14
|
+
pr: number;
|
|
15
|
+
url: string;
|
|
16
|
+
}[];
|
|
11
17
|
})[];
|
|
12
18
|
/** Check lines and how many of them got an id, per file. */
|
|
13
19
|
counts?: GuideFileCount[];
|
|
@@ -33,8 +39,25 @@ export declare function validateGuide(text: string, options?: {
|
|
|
33
39
|
/** The pull requests behind each finding in `guideMaterial`, by position, so
|
|
34
40
|
* finding `n` is `[n - 1]`. A review finding's evidence is `PR #12`. */
|
|
35
41
|
export declare function findingPullRequests(facts: Fact[]): number[][];
|
|
42
|
+
/** The review comment links behind each finding in `guideMaterial`, by
|
|
43
|
+
* position like `findingPullRequests`. Never sent to the model. */
|
|
44
|
+
export declare function findingLinks(facts: Fact[]): {
|
|
45
|
+
pr: number;
|
|
46
|
+
url: string;
|
|
47
|
+
}[][];
|
|
48
|
+
/** The last build's guide rules as the guide prompt sees them: id and text,
|
|
49
|
+
* never a pull request or a date. Empty when there were none, so a first
|
|
50
|
+
* build sends the same prompt as before. */
|
|
51
|
+
export declare function previousRulesMaterial(previous: Record<string, {
|
|
52
|
+
text: string;
|
|
53
|
+
}> | undefined): string;
|
|
36
54
|
/** Builds the review method with the high model. Returns `undefined` below the
|
|
37
55
|
* signal threshold, which is a data condition, not an AI failure. There is no
|
|
38
56
|
* deterministic fallback: a failed or unusable generation fails the run. */
|
|
39
|
-
export declare function synthesizeReviewGuides(provider: AiProvider, repo: string, ai: Options["ai"], model: string, concurrency: number, facts: Fact[], usage?: UsageSink
|
|
57
|
+
export declare function synthesizeReviewGuides(provider: AiProvider, repo: string, ai: Options["ai"], model: string, concurrency: number, facts: Fact[], usage?: UsageSink,
|
|
58
|
+
/** The last build's `RULES.json` rules, so the AI can say which old rule a
|
|
59
|
+
* new line goes against. */
|
|
60
|
+
previousRules?: Record<string, {
|
|
61
|
+
text: string;
|
|
62
|
+
}>): Promise<ReviewDocuments | undefined>;
|
|
40
63
|
export {};
|
|
@@ -17,7 +17,7 @@ const MAX_CHECK_LINES = 400;
|
|
|
17
17
|
* broad as that window. */
|
|
18
18
|
const MAX_FINDINGS = 160;
|
|
19
19
|
/** How strongly a finding recurs. Repository policy (`current`) outranks
|
|
20
|
-
* repeated history, which outranks a single example
|
|
20
|
+
* repeated history, which outranks a single example. Weight and evidence count
|
|
21
21
|
* break ties. This is the guide's only ordering signal: rules carry no
|
|
22
22
|
* priority. */
|
|
23
23
|
function recurrence(item) {
|
|
@@ -25,7 +25,7 @@ function recurrence(item) {
|
|
|
25
25
|
return scope * 1000 + item.weight * 10 + item.evidence.length;
|
|
26
26
|
}
|
|
27
27
|
/** Approval/merge narration is not a rule. The extraction prompt already
|
|
28
|
-
* forbids it
|
|
28
|
+
* forbids it. This drops any that slips through, without touching the many
|
|
29
29
|
* findings that legitimately begin "Reviewers should require …". */
|
|
30
30
|
function isNarrative(claim) {
|
|
31
31
|
return (/\bLGTM\b/i.test(claim) ||
|
|
@@ -34,7 +34,7 @@ function isNarrative(claim) {
|
|
|
34
34
|
}
|
|
35
35
|
/** The review findings the guide is built from: a concrete rule with an impact
|
|
36
36
|
* and an action. Nothing is dropped for being a single PR's finding, because
|
|
37
|
-
* the point of the guide is the specifics
|
|
37
|
+
* the point of the guide is the specifics. Recurrence only orders them. */
|
|
38
38
|
function guideFindings(facts) {
|
|
39
39
|
return facts
|
|
40
40
|
.filter((item) => item.sectionKey === "review" &&
|
|
@@ -107,7 +107,7 @@ export function validateGuide(text, options = {}) {
|
|
|
107
107
|
return `fewer than ${minPasses} passes`;
|
|
108
108
|
}
|
|
109
109
|
if (areas.length > maxPasses) {
|
|
110
|
-
return `too many passes (${areas.length})
|
|
110
|
+
return `too many passes (${areas.length}), consolidate related areas`;
|
|
111
111
|
}
|
|
112
112
|
for (const area of areas) {
|
|
113
113
|
const name = area.split("\n")[0].trim();
|
|
@@ -129,7 +129,7 @@ export function validateGuide(text, options = {}) {
|
|
|
129
129
|
}
|
|
130
130
|
/** The findings handed to the synthesis, as a flat list. Earlier this was
|
|
131
131
|
* pre-grouped by the extraction's own `class` label, which made the model emit
|
|
132
|
-
* one pass per finding (24 areas in the skunk run)
|
|
132
|
+
* one pass per finding (24 areas in the skunk run). A flat list lets it cluster
|
|
133
133
|
* related findings into a small set of coherent passes instead. */
|
|
134
134
|
function guideMaterial(facts) {
|
|
135
135
|
const findings = guideFindings(facts)
|
|
@@ -160,9 +160,16 @@ export function findingPullRequests(facts) {
|
|
|
160
160
|
})),
|
|
161
161
|
]);
|
|
162
162
|
}
|
|
163
|
+
/** The review comment links behind each finding in `guideMaterial`, by
|
|
164
|
+
* position like `findingPullRequests`. Never sent to the model. */
|
|
165
|
+
export function findingLinks(facts) {
|
|
166
|
+
return guideFindings(facts)
|
|
167
|
+
.slice(0, MAX_FINDINGS)
|
|
168
|
+
.map((item) => item.links ?? []);
|
|
169
|
+
}
|
|
163
170
|
const GUIDE_SYSTEM = `You write a code-review method for an unfamiliar open-source repository.
|
|
164
171
|
Ground every check in the supplied findings. Never invent a file, path, command, or policy. Never write a pull-request number, a commit id, a reviewer name, a mention, a quoted comment, or an attribution. Never add a priority tag. Never tell the reader to run a command.`;
|
|
165
|
-
const CONSOLIDATE = `- Consolidate the findings into a small set of coherent passes: group related findings, merge near-duplicates, and use between 3 and 12 passes. Represent every finding
|
|
172
|
+
const CONSOLIDATE = `- Consolidate the findings into a small set of coherent passes: group related findings, merge near-duplicates, and use between 3 and 12 passes. Represent every finding. Never drop one to hit the pass count.
|
|
166
173
|
- Name each pass in Title Case. Never a lowercase slug such as "test-cleanup".
|
|
167
174
|
- Every rule is a general invariant a future change must satisfy, not a description of one past fix. Keep the specific case only as the example under it.`;
|
|
168
175
|
const CHECK_SHAPE = `- Under each pass, write each rule as one general invariant line, then its concrete case indented under it:
|
|
@@ -172,7 +179,23 @@ const CHECK_SHAPE = `- Under each pass, write each rule as one general invariant
|
|
|
172
179
|
- End each pass with \`**Exit check:**\` followed by its obligations, one per line, so a reviewer who sees only a diff can apply the rule:
|
|
173
180
|
- \`<trigger: a path, glob, or symbol>\` → <what must also change or be verified>
|
|
174
181
|
- Order passes and rules by how often the findings recur, most first. Prefer the general rule over a one-off, and keep the one-off as the example under it.`;
|
|
175
|
-
|
|
182
|
+
/** The last build's guide rules as the guide prompt sees them: id and text,
|
|
183
|
+
* never a pull request or a date. Empty when there were none, so a first
|
|
184
|
+
* build sends the same prompt as before. */
|
|
185
|
+
export function previousRulesMaterial(previous) {
|
|
186
|
+
const rules = Object.entries(previous ?? {})
|
|
187
|
+
.filter(([id]) => /^R[1-9]\d*$/.test(id))
|
|
188
|
+
.sort(([a], [b]) => Number(a.slice(1)) - Number(b.slice(1)))
|
|
189
|
+
.map(([id, entry]) => ({ id, rule: entry.text }));
|
|
190
|
+
return rules.length ? JSON.stringify(rules, null, 2) : "";
|
|
191
|
+
}
|
|
192
|
+
function fullGuideRequest(material, previous = "") {
|
|
193
|
+
const overturns = previous
|
|
194
|
+
? `
|
|
195
|
+
- PREVIOUS RULES lists the rules of the last build by id. When a rule line you write requires the opposite of a previous rule, put \`(overturns R4)\` with that id right before the line's bracket. Name only a previous rule the line clearly contradicts, never one it only rewords or extends.`
|
|
196
|
+
: "";
|
|
197
|
+
// Before FINDINGS, so the findings stay the last block of the prompt.
|
|
198
|
+
const previousBlock = previous ? `PREVIOUS RULES:\n${previous}\n\n` : "";
|
|
176
199
|
return {
|
|
177
200
|
job: "synth_guide",
|
|
178
201
|
maxTokens: 16_000,
|
|
@@ -182,10 +205,10 @@ function fullGuideRequest(material) {
|
|
|
182
205
|
- Start with one \`#\` title, one sentence of purpose, and one line on how to use the method.
|
|
183
206
|
${CONSOLIDATE}
|
|
184
207
|
${CHECK_SHAPE}
|
|
185
|
-
- End every rule line with the numbers of the findings it merges, in square brackets, for example [3, 17]. Each finding has a "number". Put these brackets on no other line
|
|
208
|
+
- End every rule line with the numbers of the findings it merges, in square brackets, for example [3, 17]. Each finding has a "number". Put these brackets on no other line.${overturns}
|
|
186
209
|
- No priority tags. No commands. No code fences. Return only the Markdown.
|
|
187
210
|
|
|
188
|
-
FINDINGS:
|
|
211
|
+
${previousBlock}FINDINGS:
|
|
189
212
|
${material}`,
|
|
190
213
|
};
|
|
191
214
|
}
|
|
@@ -220,7 +243,10 @@ function withTrailingNewline(text) {
|
|
|
220
243
|
/** Builds the review method with the high model. Returns `undefined` below the
|
|
221
244
|
* signal threshold, which is a data condition, not an AI failure. There is no
|
|
222
245
|
* deterministic fallback: a failed or unusable generation fails the run. */
|
|
223
|
-
export async function synthesizeReviewGuides(provider, repo, ai, model, concurrency, facts, usage
|
|
246
|
+
export async function synthesizeReviewGuides(provider, repo, ai, model, concurrency, facts, usage,
|
|
247
|
+
/** The last build's `RULES.json` rules, so the AI can say which old rule a
|
|
248
|
+
* new line goes against. */
|
|
249
|
+
previousRules) {
|
|
224
250
|
const findings = guideFindings(facts);
|
|
225
251
|
if (findings.length <= 2)
|
|
226
252
|
return undefined;
|
|
@@ -228,29 +254,30 @@ export async function synthesizeReviewGuides(provider, repo, ai, model, concurre
|
|
|
228
254
|
// No validator: the guide is kept as written. Losing the run over format is
|
|
229
255
|
// not worth it, and a later `sync` reuses the cached text.
|
|
230
256
|
const queue = new AiBatch(provider, repo, Math.max(1, concurrency), `${ai}:v3:${model}:guide`);
|
|
231
|
-
const [fullResponse] = await queue.run([fullGuideRequest(material)], usage);
|
|
257
|
+
const [fullResponse] = await queue.run([fullGuideRequest(material, previousRulesMaterial(previousRules))], usage);
|
|
232
258
|
const full = cleanGuide(fullResponse?.text ?? "");
|
|
233
259
|
if (!full) {
|
|
234
260
|
// Not a failure: SKILL.md and CODEBASE.md are written anyway.
|
|
235
|
-
log("ai", "synth_guide produced nothing usable
|
|
261
|
+
log("ai", "synth_guide produced nothing usable, skipping the guide");
|
|
236
262
|
return undefined;
|
|
237
263
|
}
|
|
238
264
|
const sources = findingPullRequests(facts);
|
|
265
|
+
const links = findingLinks(facts);
|
|
239
266
|
const fullLines = full.split("\n").length;
|
|
240
267
|
if (fullLines <= DETAIL_THRESHOLD_LINES) {
|
|
241
|
-
return withRuleIds(withTrailingNewline(full), undefined, sources);
|
|
268
|
+
return withRuleIds(withTrailingNewline(full), undefined, sources, links);
|
|
242
269
|
}
|
|
243
270
|
// The short guide is asked from the full method with its finding brackets
|
|
244
271
|
// still on, so it can carry them over to the lines it summarizes.
|
|
245
272
|
const [shortResponse] = await queue.run([shortGuideRequest(material, full)], usage);
|
|
246
273
|
const short = cleanGuide(shortResponse?.text ?? "");
|
|
247
274
|
if (!short)
|
|
248
|
-
return withRuleIds(withTrailingNewline(full), undefined, sources);
|
|
249
|
-
return withRuleIds(withTrailingNewline(short), full, sources);
|
|
275
|
+
return withRuleIds(withTrailingNewline(full), undefined, sources, links);
|
|
276
|
+
return withRuleIds(withTrailingNewline(short), full, sources, links);
|
|
250
277
|
}
|
|
251
278
|
/** Replaces the finding brackets with `R` ids and attaches each id's pull
|
|
252
279
|
* requests. */
|
|
253
|
-
function withRuleIds(guide, detailed, sources) {
|
|
280
|
+
function withRuleIds(guide, detailed, sources, links = []) {
|
|
254
281
|
const assigned = assignGuideIds(guide, detailed, sources.length);
|
|
255
282
|
return {
|
|
256
283
|
guide: assigned.guide,
|
|
@@ -260,6 +287,9 @@ function withRuleIds(guide, detailed, sources) {
|
|
|
260
287
|
pullRequests: [
|
|
261
288
|
...new Set(rule.findings.flatMap((n) => sources[n - 1] ?? [])),
|
|
262
289
|
].sort((a, b) => a - b),
|
|
290
|
+
links: rule.findings
|
|
291
|
+
.flatMap((n) => links[n - 1] ?? [])
|
|
292
|
+
.filter((link, index, all) => all.findIndex((other) => other.url === link.url) === index),
|
|
263
293
|
})),
|
|
264
294
|
counts: assigned.counts,
|
|
265
295
|
};
|
|
@@ -5,12 +5,21 @@ export type GuideRule = {
|
|
|
5
5
|
text: string;
|
|
6
6
|
/** 1-based numbers of the findings the line merges, sorted. */
|
|
7
7
|
findings: number[];
|
|
8
|
+
/** Previous rule ids the guide AI said this line goes against, from an
|
|
9
|
+
* `(overturns R4)` note before the bracket. The note is removed from the
|
|
10
|
+
* line. Code checks the ids exist and the new rule is newer. */
|
|
11
|
+
overturns?: string[];
|
|
8
12
|
};
|
|
9
13
|
export type GuideFileCount = {
|
|
10
14
|
file: string;
|
|
11
15
|
rules: number;
|
|
12
16
|
withIds: number;
|
|
13
17
|
};
|
|
18
|
+
/** The line without its overturns note, and the ids it named. */
|
|
19
|
+
export declare function takeOverturns(line: string): {
|
|
20
|
+
line: string;
|
|
21
|
+
ids: string[];
|
|
22
|
+
};
|
|
14
23
|
/** Gives every check line that ends in a usable source list an `R` id,
|
|
15
24
|
* numbered in file order. With a detailed guide, its lines are numbered first
|
|
16
25
|
* and a short-guide line with the same finding set shares that id. A line with
|
|
@@ -32,6 +32,18 @@ function takeSourceBracket(line) {
|
|
|
32
32
|
function setKey(numbers) {
|
|
33
33
|
return numbers.join(",");
|
|
34
34
|
}
|
|
35
|
+
/** `(overturns R4, R7)` right before the source bracket. */
|
|
36
|
+
const OVERTURNS = /\s*\(overturns\s+(R[1-9]\d*(?:\s*,\s*R[1-9]\d*)*)\)\s*$/;
|
|
37
|
+
/** The line without its overturns note, and the ids it named. */
|
|
38
|
+
export function takeOverturns(line) {
|
|
39
|
+
const match = OVERTURNS.exec(line);
|
|
40
|
+
if (!match)
|
|
41
|
+
return { line, ids: [] };
|
|
42
|
+
return {
|
|
43
|
+
line: line.slice(0, match.index),
|
|
44
|
+
ids: [...new Set(match[1].split(",").map((id) => id.trim()))],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
35
47
|
function ruleText(line) {
|
|
36
48
|
return line.replace(/^- /, "").replaceAll("`", "").trim();
|
|
37
49
|
}
|
|
@@ -54,7 +66,8 @@ function rewrite(text, file, findingCount, idFor) {
|
|
|
54
66
|
if (valid.length === 0)
|
|
55
67
|
return taken.line;
|
|
56
68
|
withIds++;
|
|
57
|
-
|
|
69
|
+
const note = takeOverturns(taken.line);
|
|
70
|
+
return `${note.line} [${idFor(valid, note.line, note.ids)}]`;
|
|
58
71
|
});
|
|
59
72
|
return { text: lines.join("\n"), count: { file, rules, withIds } };
|
|
60
73
|
}
|
|
@@ -65,22 +78,28 @@ function rewrite(text, file, findingCount, idFor) {
|
|
|
65
78
|
export function assignGuideIds(guide, detailed, findingCount) {
|
|
66
79
|
const rules = [];
|
|
67
80
|
const bySet = new Map();
|
|
68
|
-
const add = (file, numbers, line) => {
|
|
81
|
+
const add = (file, numbers, line, overturns = []) => {
|
|
69
82
|
const id = `R${rules.length + 1}`;
|
|
70
|
-
rules.push({
|
|
83
|
+
rules.push({
|
|
84
|
+
id,
|
|
85
|
+
file,
|
|
86
|
+
text: ruleText(line),
|
|
87
|
+
findings: numbers,
|
|
88
|
+
...(overturns.length ? { overturns } : {}),
|
|
89
|
+
});
|
|
71
90
|
return id;
|
|
72
91
|
};
|
|
73
92
|
if (detailed === undefined) {
|
|
74
|
-
const single = rewrite(guide, GUIDE_FILE, findingCount, (numbers, line) => add(GUIDE_FILE, numbers, line));
|
|
93
|
+
const single = rewrite(guide, GUIDE_FILE, findingCount, (numbers, line, overturns) => add(GUIDE_FILE, numbers, line, overturns));
|
|
75
94
|
return { guide: single.text, rules, counts: [single.count] };
|
|
76
95
|
}
|
|
77
|
-
const full = rewrite(detailed, DETAILED_GUIDE_FILE, findingCount, (numbers, line) => {
|
|
78
|
-
const id = add(DETAILED_GUIDE_FILE, numbers, line);
|
|
96
|
+
const full = rewrite(detailed, DETAILED_GUIDE_FILE, findingCount, (numbers, line, overturns) => {
|
|
97
|
+
const id = add(DETAILED_GUIDE_FILE, numbers, line, overturns);
|
|
79
98
|
if (!bySet.has(setKey(numbers)))
|
|
80
99
|
bySet.set(setKey(numbers), id);
|
|
81
100
|
return id;
|
|
82
101
|
});
|
|
83
|
-
const short = rewrite(guide, GUIDE_FILE, findingCount, (numbers, line) => bySet.get(setKey(numbers)) ?? add(GUIDE_FILE, numbers, line));
|
|
102
|
+
const short = rewrite(guide, GUIDE_FILE, findingCount, (numbers, line, overturns) => bySet.get(setKey(numbers)) ?? add(GUIDE_FILE, numbers, line, overturns));
|
|
84
103
|
return {
|
|
85
104
|
guide: short.text,
|
|
86
105
|
detailed: full.text,
|
|
@@ -102,7 +102,7 @@ export function analyzeProbe(meta, pulls, detailSamples, commits) {
|
|
|
102
102
|
(30.44 * 24 * 60 * 60 * 1_000)
|
|
103
103
|
: Infinity;
|
|
104
104
|
reasons.push(releaseAgeMonths <= 18
|
|
105
|
-
? `A release from ${latestReleaseAt.slice(0, 10)} is recent
|
|
105
|
+
? `A release from ${latestReleaseAt.slice(0, 10)} is recent. Use the last ${maxPrMonths} months to prioritize the current contribution and release process.`
|
|
106
106
|
: `The last ${maxPrMonths} months cover at least 85% of pull requests. Older history is a minority.`);
|
|
107
107
|
}
|
|
108
108
|
else if (pulls.length) {
|
|
@@ -40,3 +40,21 @@ export declare function compareRules(previous: Record<string, RuleEntry> | undef
|
|
|
40
40
|
/** `2 rules added (#402, #407) · 1 rewritten (R12, #340 joined) · 1 dropped
|
|
41
41
|
* (#101 left the window)`, or `no rule changed`. */
|
|
42
42
|
export declare function ruleChangeLine(changes: RuleChanges): string;
|
|
43
|
+
export type Contradiction = {
|
|
44
|
+
/** The old rule. */
|
|
45
|
+
id: string;
|
|
46
|
+
/** The new rule that goes against it. */
|
|
47
|
+
by: string;
|
|
48
|
+
/** The new rule's pull requests, `#340`. */
|
|
49
|
+
sources: string[];
|
|
50
|
+
/** The newest merge date of the new rule, `YYYY-MM-DD`. */
|
|
51
|
+
newest: string;
|
|
52
|
+
/** False when the old id is still in this build. */
|
|
53
|
+
dropped: boolean;
|
|
54
|
+
};
|
|
55
|
+
/** The old rules the guide AI said a new rule goes against, kept only when
|
|
56
|
+
* the old rule existed and the new rule's newest pull request was merged
|
|
57
|
+
* after the old rule's newest one. Without both dates nothing is claimed. */
|
|
58
|
+
export declare function contradictions(previous: Record<string, RuleEntry> | undefined, next: Record<string, RuleEntry>, overturns: Map<string, string[]>): Contradiction[];
|
|
59
|
+
/** `R4 dropped, R9 goes against it (#340, 2026-03)`. */
|
|
60
|
+
export declare function contradictionLine(item: Contradiction): string;
|
|
@@ -96,3 +96,44 @@ export function ruleChangeLine(changes) {
|
|
|
96
96
|
}
|
|
97
97
|
return parts.length > 0 ? parts.join(" · ") : "no rule changed";
|
|
98
98
|
}
|
|
99
|
+
function newestDate(entry) {
|
|
100
|
+
const dates = entry.sources.flatMap((source) => "pr" in source && source.mergedAt ? [source.mergedAt] : []);
|
|
101
|
+
return dates.length ? dates.sort().at(-1) : undefined;
|
|
102
|
+
}
|
|
103
|
+
/** The old rules the guide AI said a new rule goes against, kept only when
|
|
104
|
+
* the old rule existed and the new rule's newest pull request was merged
|
|
105
|
+
* after the old rule's newest one. Without both dates nothing is claimed. */
|
|
106
|
+
export function contradictions(previous, next, overturns) {
|
|
107
|
+
const found = [];
|
|
108
|
+
for (const [by, ids] of overturns) {
|
|
109
|
+
const entry = next[by];
|
|
110
|
+
if (!entry)
|
|
111
|
+
continue;
|
|
112
|
+
const newest = newestDate(entry);
|
|
113
|
+
if (!newest)
|
|
114
|
+
continue;
|
|
115
|
+
for (const id of ids) {
|
|
116
|
+
const old = previous?.[id];
|
|
117
|
+
if (!old || id === by)
|
|
118
|
+
continue;
|
|
119
|
+
const oldNewest = newestDate(old);
|
|
120
|
+
if (!oldNewest || newest <= oldNewest)
|
|
121
|
+
continue;
|
|
122
|
+
found.push({
|
|
123
|
+
id,
|
|
124
|
+
by,
|
|
125
|
+
sources: labels(entry),
|
|
126
|
+
newest,
|
|
127
|
+
dropped: !(id in next),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return found;
|
|
132
|
+
}
|
|
133
|
+
/** `R4 dropped, R9 goes against it (#340, 2026-03)`. */
|
|
134
|
+
export function contradictionLine(item) {
|
|
135
|
+
const evidence = `${listed(item.sources, 3)}, ${item.newest.slice(0, 7)}`;
|
|
136
|
+
return item.dropped
|
|
137
|
+
? `${item.id} dropped, ${item.by} goes against it (${evidence})`
|
|
138
|
+
: `${item.by} goes against ${item.id} (${evidence})`;
|
|
139
|
+
}
|
|
@@ -16,6 +16,10 @@ export declare const DETAILED_GUIDE_FILE = "PR_REVIEW_DETAILED_GUIDE.md";
|
|
|
16
16
|
export type RuleSource = {
|
|
17
17
|
pr: number;
|
|
18
18
|
mergedAt?: string;
|
|
19
|
+
/** The review comment the rule came from. Missing when the pull
|
|
20
|
+
* request was read before links were kept, or the rule came from its
|
|
21
|
+
* body or diff. */
|
|
22
|
+
url?: string;
|
|
19
23
|
} | {
|
|
20
24
|
path: string;
|
|
21
25
|
line: number;
|
|
@@ -35,6 +39,13 @@ export type RulesFile = {
|
|
|
35
39
|
schemaVersion: 1;
|
|
36
40
|
builtAt: string;
|
|
37
41
|
rules: Record<string, RuleEntry>;
|
|
42
|
+
/** The highest number ever given per kind, so a dropped id is never given
|
|
43
|
+
* to another rule. Missing in files written before ids were kept stable:
|
|
44
|
+
* the highest id in `rules` stands in. */
|
|
45
|
+
lastIds?: {
|
|
46
|
+
R: number;
|
|
47
|
+
I: number;
|
|
48
|
+
};
|
|
38
49
|
};
|
|
39
50
|
/** Ids are `R` for guide rules and `I` for instruction rules, then a number.
|
|
40
51
|
* `C` is kept for built-in checks. */
|
|
@@ -18,7 +18,8 @@ function isSource(value) {
|
|
|
18
18
|
return false;
|
|
19
19
|
const record = value;
|
|
20
20
|
if (typeof record.pr === "number") {
|
|
21
|
-
return record.mergedAt === undefined || typeof record.mergedAt === "string"
|
|
21
|
+
return ((record.mergedAt === undefined || typeof record.mergedAt === "string") &&
|
|
22
|
+
(record.url === undefined || typeof record.url === "string"));
|
|
22
23
|
}
|
|
23
24
|
return typeof record.path === "string" && typeof record.line === "number";
|
|
24
25
|
}
|
|
@@ -58,10 +59,18 @@ export function parseRules(text) {
|
|
|
58
59
|
sources,
|
|
59
60
|
};
|
|
60
61
|
}
|
|
62
|
+
const last = record.lastIds;
|
|
63
|
+
const lastIds = last &&
|
|
64
|
+
typeof last === "object" &&
|
|
65
|
+
Number.isInteger(last.R) &&
|
|
66
|
+
Number.isInteger(last.I)
|
|
67
|
+
? { R: Number(last.R), I: Number(last.I) }
|
|
68
|
+
: undefined;
|
|
61
69
|
return {
|
|
62
70
|
schemaVersion: 1,
|
|
63
71
|
builtAt: typeof record.builtAt === "string" ? record.builtAt : "",
|
|
64
72
|
rules,
|
|
73
|
+
...(lastIds ? { lastIds } : {}),
|
|
65
74
|
};
|
|
66
75
|
}
|
|
67
76
|
function idNumber(id) {
|
|
@@ -101,7 +101,7 @@ export async function assembleSkill(repo, facts, previousMarkdown, previousHashe
|
|
|
101
101
|
const canonicalHeading = `## ${sectionTitles[key] ?? key}`;
|
|
102
102
|
const override = overrides[key]?.trim();
|
|
103
103
|
// The codebase sections hold a link, not text, so the skill never takes a
|
|
104
|
-
// synthesized override for them
|
|
104
|
+
// synthesized override for them. The override goes to CODEBASE.md instead.
|
|
105
105
|
const hasOverride = Boolean(override) && !codebaseSectionKeys.has(key);
|
|
106
106
|
if (!hasOverride &&
|
|
107
107
|
previousMarkdown &&
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Rule ids that stay the same across builds.
|
|
2
|
+
*
|
|
3
|
+
* A build numbers its rules from 1 (`R1`, `I1`, ...). A review that cited
|
|
4
|
+
* `R4` must still point at the same rule after the next `sync`, so the fresh
|
|
5
|
+
* numbers are mapped onto the last build's ids before anything is written:
|
|
6
|
+
* a rule that shares a source with an old rule keeps that rule's id (it is the
|
|
7
|
+
* same rule, maybe reworded), a rule with no match gets the next number ever
|
|
8
|
+
* given, and a dropped id is never given again. */
|
|
9
|
+
import { type RuleEntry, type RuleSource } from "./rules.ts";
|
|
10
|
+
export type FreshRule = {
|
|
11
|
+
id: string;
|
|
12
|
+
text: string;
|
|
13
|
+
sources: RuleSource[];
|
|
14
|
+
/** Old ids this rule may not take, such as the rule it overturns. */
|
|
15
|
+
avoid?: string[];
|
|
16
|
+
};
|
|
17
|
+
/** Maps each fresh id to its stable id, and returns the new highest number.
|
|
18
|
+
* A fresh rule may keep an old id when it shares a source with that rule, or
|
|
19
|
+
* else has the same text. The ids are matched as a whole, not first come
|
|
20
|
+
* first served: a rule that could keep two ids gives way to a later rule that
|
|
21
|
+
* can keep only one of them, so as many ids as possible stay the same. Among
|
|
22
|
+
* its options a rule tries the one with the most shared sources first. */
|
|
23
|
+
export declare function stableIds(kind: "R" | "I", fresh: FreshRule[], previous: Record<string, RuleEntry> | undefined, lastId: number | undefined): {
|
|
24
|
+
ids: Map<string, string>;
|
|
25
|
+
lastId: number;
|
|
26
|
+
};
|
|
27
|
+
/** Rewrites the `[R1]` / `[I1]` id at the end of each line in one pass, so a
|
|
28
|
+
* rename such as R1 to R2 and R2 to R5 never collides. */
|
|
29
|
+
export declare function renameIdsInMarkdown(markdown: string, ids: Map<string, string>): string;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** Rule ids that stay the same across builds.
|
|
2
|
+
*
|
|
3
|
+
* A build numbers its rules from 1 (`R1`, `I1`, ...). A review that cited
|
|
4
|
+
* `R4` must still point at the same rule after the next `sync`, so the fresh
|
|
5
|
+
* numbers are mapped onto the last build's ids before anything is written:
|
|
6
|
+
* a rule that shares a source with an old rule keeps that rule's id (it is the
|
|
7
|
+
* same rule, maybe reworded), a rule with no match gets the next number ever
|
|
8
|
+
* given, and a dropped id is never given again. */
|
|
9
|
+
import { sourceLabel } from "./rules.js";
|
|
10
|
+
/** The highest id number of one kind in `rules`. */
|
|
11
|
+
function highest(rules, kind) {
|
|
12
|
+
let max = 0;
|
|
13
|
+
for (const id of Object.keys(rules)) {
|
|
14
|
+
if (id.startsWith(kind))
|
|
15
|
+
max = Math.max(max, Number(id.slice(1)) || 0);
|
|
16
|
+
}
|
|
17
|
+
return max;
|
|
18
|
+
}
|
|
19
|
+
/** Maps each fresh id to its stable id, and returns the new highest number.
|
|
20
|
+
* A fresh rule may keep an old id when it shares a source with that rule, or
|
|
21
|
+
* else has the same text. The ids are matched as a whole, not first come
|
|
22
|
+
* first served: a rule that could keep two ids gives way to a later rule that
|
|
23
|
+
* can keep only one of them, so as many ids as possible stay the same. Among
|
|
24
|
+
* its options a rule tries the one with the most shared sources first. */
|
|
25
|
+
export function stableIds(kind, fresh, previous, lastId) {
|
|
26
|
+
const old = Object.entries(previous ?? {})
|
|
27
|
+
.filter(([id]) => id.startsWith(kind))
|
|
28
|
+
.map(([id, entry]) => ({
|
|
29
|
+
id,
|
|
30
|
+
text: entry.text,
|
|
31
|
+
sources: new Set(entry.sources.map(sourceLabel)),
|
|
32
|
+
}));
|
|
33
|
+
const rules = fresh.filter((rule, index) => fresh.findIndex((item) => item.id === rule.id) === index);
|
|
34
|
+
// Each rule's old ids it may keep, best first.
|
|
35
|
+
const options = rules.map((rule) => {
|
|
36
|
+
const labels = rule.sources.map(sourceLabel);
|
|
37
|
+
return old
|
|
38
|
+
.flatMap((item, order) => {
|
|
39
|
+
if (rule.avoid?.includes(item.id))
|
|
40
|
+
return [];
|
|
41
|
+
const shared = labels.filter((label) => item.sources.has(label)).length;
|
|
42
|
+
// Same text with no shared source still counts, below any shared
|
|
43
|
+
// source: an instruction line that moved down a file is the same rule.
|
|
44
|
+
const score = shared > 0 ? shared : item.text === rule.text ? 0.5 : 0;
|
|
45
|
+
return score > 0 ? [{ id: item.id, score, order }] : [];
|
|
46
|
+
})
|
|
47
|
+
.sort((a, b) => b.score - a.score || a.order - b.order)
|
|
48
|
+
.map((option) => option.id);
|
|
49
|
+
});
|
|
50
|
+
// Augmenting paths: a rule takes a free id, or moves the rule holding one
|
|
51
|
+
// of its options to another id that rule may keep.
|
|
52
|
+
const holder = new Map();
|
|
53
|
+
const kept = new Map();
|
|
54
|
+
const place = (index, seen) => {
|
|
55
|
+
for (const id of options[index]) {
|
|
56
|
+
if (seen.has(id))
|
|
57
|
+
continue;
|
|
58
|
+
seen.add(id);
|
|
59
|
+
const current = holder.get(id);
|
|
60
|
+
if (current === undefined || place(current, seen)) {
|
|
61
|
+
holder.set(id, index);
|
|
62
|
+
kept.set(index, id);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
68
|
+
for (let index = 0; index < rules.length; index++)
|
|
69
|
+
place(index, new Set());
|
|
70
|
+
let next = Math.max(lastId ?? 0, highest(previous ?? {}, kind));
|
|
71
|
+
const ids = new Map();
|
|
72
|
+
for (const [index, rule] of rules.entries()) {
|
|
73
|
+
const id = kept.get(index);
|
|
74
|
+
if (id)
|
|
75
|
+
ids.set(rule.id, id);
|
|
76
|
+
else {
|
|
77
|
+
next++;
|
|
78
|
+
ids.set(rule.id, `${kind}${next}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { ids, lastId: next };
|
|
82
|
+
}
|
|
83
|
+
/** Rewrites the `[R1]` / `[I1]` id at the end of each line in one pass, so a
|
|
84
|
+
* rename such as R1 to R2 and R2 to R5 never collides. */
|
|
85
|
+
export function renameIdsInMarkdown(markdown, ids) {
|
|
86
|
+
return markdown.replace(/\[([RI][1-9]\d*)\](?=[ \t]*$)/gm, (whole, id) => {
|
|
87
|
+
const renamed = ids.get(id);
|
|
88
|
+
return renamed ? `[${renamed}]` : whole;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import type { AiProvider, AiResponse, Options } from "../types.ts";
|
|
2
|
-
import type { Fact, Source } from "./types.ts";
|
|
2
|
+
import type { Fact, PullRequest, Source } from "./types.ts";
|
|
3
3
|
type UsageSink = (job: string, response: AiResponse) => Promise<void>;
|
|
4
|
+
/** Whether the pull request was read with comment links. A row cached before
|
|
5
|
+
* links were kept has none, and keeps the old extract prompt so its cached
|
|
6
|
+
* answer is still used. */
|
|
7
|
+
export declare function hasCommentLinks(pr: PullRequest): boolean;
|
|
8
|
+
/** The comment ids of a linked pull request (`c1` issue comment, `r1` inline
|
|
9
|
+
* review comment, `v1` review) and the link behind each. */
|
|
10
|
+
export declare function commentIds(pr: PullRequest): Map<string, string>;
|
|
11
|
+
/** The extract prompt for one pull request. A pull request read before
|
|
12
|
+
* comment links were kept gets the exact old text, so its cached answer still
|
|
13
|
+
* hits. A linked one numbers its comments and asks which ones a finding rests
|
|
14
|
+
* on. */
|
|
15
|
+
export declare function extractPrompt(pr: PullRequest): string;
|
|
4
16
|
export type SynthesisResult = Record<string, string>;
|
|
5
17
|
export declare function extractAiFacts(provider: AiProvider, repo: string, source: Source, options: Options, usage?: UsageSink): Promise<Fact[]>;
|
|
6
18
|
export declare function enrichFacts(provider: AiProvider, repo: string, base: Fact[], source: Source, options: Options, usage?: UsageSink): Promise<Fact[]>;
|