co-maintainer 0.5.4 → 0.6.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/dist/package.json +1 -1
- package/dist/src/ai/batch.d.ts +19 -16
- package/dist/src/ai/batch.js +68 -46
- package/dist/src/cli/args.js +2 -2
- package/dist/src/cli/commands/config.d.ts +1 -1
- package/dist/src/cli/commands/config.js +2 -0
- package/dist/src/cli/commands/registry.js +38 -17
- package/dist/src/cli/commands/review.js +2 -1
- package/dist/src/cli/commands/set.js +14 -1
- package/dist/src/cli/review_args.js +1 -0
- package/dist/src/config.d.ts +4 -0
- package/dist/src/github/collect.js +19 -1
- package/dist/src/knowledge/guide.d.ts +19 -4
- package/dist/src/knowledge/guide.js +222 -87
- package/dist/src/knowledge/skill.d.ts +4 -5
- package/dist/src/knowledge/skill.js +27 -35
- package/dist/src/knowledge/synthesis.d.ts +0 -13
- package/dist/src/knowledge/synthesis.js +176 -84
- package/dist/src/knowledge/types.d.ts +22 -0
- package/dist/src/pr/codegraph_tools.d.ts +13 -3
- package/dist/src/pr/codegraph_tools.js +26 -7
- package/dist/src/pr/reviewer.d.ts +4 -0
- package/dist/src/pr/reviewer.js +12 -1
- package/dist/src/services/remote_review.js +1 -1
- package/dist/src/services/review.js +1 -1
- package/dist/src/services/setup.js +63 -53
- package/dist/src/tools/codegraph.d.ts +15 -0
- package/dist/src/tools/codegraph.js +59 -24
- package/dist/src/types.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,106 +1,241 @@
|
|
|
1
|
+
import { AiBatch } from "../ai/batch.js";
|
|
1
2
|
/** A fact read out of a single pull request describes that request, not the
|
|
2
3
|
* repository. `origin` is absent on facts written before the field existed, so
|
|
3
4
|
* those count as repository policy. */
|
|
4
5
|
export function isPullRequestFact(item) {
|
|
5
6
|
return item.origin === "pull-request";
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
/** Above this many lines the full method is split into the short reviewer file
|
|
9
|
+
* plus `PR_REVIEW_DETAILED_GUIDE.md`. */
|
|
10
|
+
const DETAIL_THRESHOLD_LINES = 30;
|
|
11
|
+
const MAX_GUIDE_LINES = 600;
|
|
12
|
+
const MAX_CHECK_LINES = 400;
|
|
13
|
+
/** Findings handed to one synthesis call. A repository with more is truncated
|
|
14
|
+
* by recurrence: the most repeated reach the model, and the guide is only as
|
|
15
|
+
* broad as that window. */
|
|
16
|
+
const MAX_FINDINGS = 160;
|
|
17
|
+
/** How strongly a finding recurs. Repository policy (`current`) outranks
|
|
18
|
+
* repeated history, which outranks a single example; weight and evidence count
|
|
19
|
+
* break ties. This is the guide's only ordering signal: rules carry no
|
|
20
|
+
* priority. */
|
|
21
|
+
function recurrence(item) {
|
|
22
|
+
const scope = { current: 3, "repeated-history": 2, "historical-example": 1 }[item.scope] ?? 0;
|
|
23
|
+
return scope * 1000 + item.weight * 10 + item.evidence.length;
|
|
16
24
|
}
|
|
17
|
-
|
|
25
|
+
/** Approval/merge narration is not a rule. The extraction prompt already
|
|
26
|
+
* forbids it; this drops any that slips through, without touching the many
|
|
27
|
+
* findings that legitimately begin "Reviewers should require …". */
|
|
28
|
+
function isNarrative(claim) {
|
|
29
|
+
return (/\bLGTM\b/i.test(claim) ||
|
|
30
|
+
/^(the reviewer|a reviewer|reviewers?) (approved|merged|commented|replied|left)\b/i.test(claim) ||
|
|
31
|
+
/\b(was merged|has been merged|approved at)\b/i.test(claim));
|
|
32
|
+
}
|
|
33
|
+
/** The review findings the guide is built from: a concrete rule with an impact
|
|
34
|
+
* and an action. Nothing is dropped for being a single PR's finding, because
|
|
35
|
+
* the point of the guide is the specifics; recurrence only orders them. */
|
|
36
|
+
function guideFindings(facts) {
|
|
18
37
|
return facts
|
|
19
|
-
.filter((item) => item.sectionKey === "review
|
|
20
|
-
item.
|
|
21
|
-
|
|
22
|
-
|
|
38
|
+
.filter((item) => item.sectionKey === "review" &&
|
|
39
|
+
Boolean(item.impact) &&
|
|
40
|
+
Boolean(item.action) &&
|
|
41
|
+
!isNarrative(item.claim))
|
|
42
|
+
.sort((a, b) => recurrence(b) - recurrence(a) || a.claim.localeCompare(b.claim));
|
|
43
|
+
}
|
|
44
|
+
/** The selected review findings before the frequency threshold is applied.
|
|
45
|
+
* Exported so `init` can tell the user how far short of the threshold a
|
|
46
|
+
* repository is instead of silently skipping the guide. */
|
|
47
|
+
export function reviewSignalCount(facts) {
|
|
48
|
+
return guideFindings(facts).length;
|
|
23
49
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
50
|
+
const VAGUE = /^(inspect|check whether|look at|consider|review the|ensure that|make sure)\b/i;
|
|
51
|
+
/** The guide's concreteness contract. Returns `null` when usable, else the
|
|
52
|
+
* reason the batch retries on. This is the context-loss detector: a rule that
|
|
53
|
+
* could sit in any repository's guide fails it, and it also forces the guide to
|
|
54
|
+
* be a small set of coherent passes rather than one area per finding. */
|
|
55
|
+
export function validateGuide(text, options = {}) {
|
|
56
|
+
const minChecks = options.minChecks ?? 8;
|
|
57
|
+
const minPasses = options.minPasses ?? 3;
|
|
58
|
+
const maxPasses = options.maxPasses ?? 12;
|
|
59
|
+
if (!/^#\s+\S/m.test(text))
|
|
60
|
+
return "no title";
|
|
61
|
+
if (!/^##\s+\S/m.test(text))
|
|
62
|
+
return "no areas";
|
|
63
|
+
const lines = text.split("\n");
|
|
64
|
+
if (lines.length > MAX_GUIDE_LINES)
|
|
65
|
+
return "too long";
|
|
66
|
+
if (/\bPR\s*#?\s*\d+/i.test(text))
|
|
67
|
+
return "contains a pull-request number";
|
|
68
|
+
if (/(^|\s)[\u2014\u2013]\s*\S/.test(text))
|
|
69
|
+
return "contains an attribution";
|
|
70
|
+
if (/@[A-Za-z0-9_-]{2,}/.test(text))
|
|
71
|
+
return "contains a mention";
|
|
72
|
+
if (/^\s*>/m.test(text))
|
|
73
|
+
return "contains a quote";
|
|
74
|
+
if (text.includes("```"))
|
|
75
|
+
return "contains a code fence";
|
|
76
|
+
if (/(^|\s)\$\s/m.test(text))
|
|
77
|
+
return "contains a shell prompt";
|
|
78
|
+
if (/\b(?:TODO|TBD)\b/i.test(text))
|
|
79
|
+
return "contains a placeholder";
|
|
80
|
+
if (/\b(?=[0-9a-f]*[0-9])(?=[0-9a-f]*[a-f])[0-9a-f]{7,40}\b/i.test(text)) {
|
|
81
|
+
return "contains a commit id";
|
|
82
|
+
}
|
|
83
|
+
if (/\bP[0-3]\b|\[P[0-3]\]/.test(text))
|
|
84
|
+
return "contains a priority tag";
|
|
85
|
+
const bullets = lines.filter((line) => /^- /.test(line));
|
|
86
|
+
const isLink = (line) => /\]\(/.test(line);
|
|
87
|
+
const isCheck = (line) => / · /.test(line);
|
|
88
|
+
const isObligation = (line) => / → /.test(line);
|
|
89
|
+
// A top-level bullet is a check (`rule · why`), an obligation
|
|
90
|
+
// (`trigger → must-do`), or the short file's link to the detailed file. A
|
|
91
|
+
// bare "Inspect X" is none of them. Indented example lines are ignored.
|
|
92
|
+
const bare = bullets.find((line) => !isLink(line) && !isCheck(line) && !isObligation(line));
|
|
93
|
+
if (bare)
|
|
94
|
+
return `bullet without a reason or obligation: ${bare.slice(0, 60)}`;
|
|
95
|
+
const checks = bullets.filter((line) => isCheck(line) && !isLink(line));
|
|
96
|
+
if (checks.length > MAX_CHECK_LINES)
|
|
97
|
+
return "too many checks";
|
|
98
|
+
if (checks.length < minChecks)
|
|
99
|
+
return "too few concrete checks";
|
|
100
|
+
const vague = checks.find((line) => VAGUE.test(line.replace(/^-\s*/, "")));
|
|
101
|
+
if (vague)
|
|
102
|
+
return `vague check: ${vague.slice(0, 60)}`;
|
|
103
|
+
const areas = text.split(/^## /m).slice(1);
|
|
104
|
+
if (areas.length < minPasses) {
|
|
105
|
+
return `fewer than ${minPasses} passes`;
|
|
106
|
+
}
|
|
107
|
+
if (areas.length > maxPasses) {
|
|
108
|
+
return `too many passes (${areas.length}); consolidate related areas`;
|
|
109
|
+
}
|
|
110
|
+
for (const area of areas) {
|
|
111
|
+
const name = area.split("\n")[0].trim();
|
|
112
|
+
// A raw class label ("test-cleanup") is not a pass name.
|
|
113
|
+
if (/^[a-z0-9][a-z0-9_-]*$/.test(name)) {
|
|
114
|
+
return `unnormalized pass name: ${name}`;
|
|
115
|
+
}
|
|
116
|
+
const areaChecks = (area.match(/^- .*/gm) ?? []).filter((line) => isCheck(line) && !isLink(line));
|
|
117
|
+
if (areaChecks.length < 1) {
|
|
118
|
+
return `pass "${name}" has no concrete check`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// The exit check is asked for per pass but not enforced: the model
|
|
122
|
+
// occasionally omits one, and rejecting the whole guide for that is worse
|
|
123
|
+
// than a missing line.
|
|
124
|
+
if (!/\*\*Exit check:\*\*/.test(text))
|
|
125
|
+
return "no exit check";
|
|
126
|
+
return null;
|
|
28
127
|
}
|
|
29
|
-
/** The
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
128
|
+
/** The findings handed to the synthesis, as a flat list. Earlier this was
|
|
129
|
+
* pre-grouped by the extraction's own `class` label, which made the model emit
|
|
130
|
+
* one pass per finding (24 areas in the skunk run); a flat list lets it cluster
|
|
131
|
+
* related findings into a small set of coherent passes instead. */
|
|
132
|
+
function guideMaterial(facts) {
|
|
133
|
+
const findings = guideFindings(facts)
|
|
134
|
+
.slice(0, MAX_FINDINGS)
|
|
135
|
+
.map((item) => ({
|
|
136
|
+
class: (item.class ?? "general").trim() || "general",
|
|
137
|
+
rule: item.claim,
|
|
138
|
+
...(item.trigger ? { trigger: item.trigger } : {}),
|
|
139
|
+
...(item.location ? { location: item.location } : {}),
|
|
140
|
+
impact: item.impact,
|
|
141
|
+
action: item.action,
|
|
142
|
+
repeats: item.evidence.length,
|
|
143
|
+
}));
|
|
144
|
+
return JSON.stringify(findings, null, 2);
|
|
33
145
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
146
|
+
const GUIDE_SYSTEM = `You write a code-review method for an unfamiliar open-source repository.
|
|
147
|
+
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.`;
|
|
148
|
+
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.
|
|
149
|
+
- Name each pass in Title Case. Never a lowercase slug such as "test-cleanup".
|
|
150
|
+
- 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.`;
|
|
151
|
+
const CHECK_SHAPE = `- Under each pass, write each rule as one general invariant line, then its concrete case indented under it:
|
|
152
|
+
- <when <trigger> changes, <obligation>, or every <surface> must ...> · <why it matters here>
|
|
153
|
+
- <the concrete case: what changed and where>
|
|
154
|
+
- Give each pass a \`**Goal:**\` line and an \`**Applies to:**\` line.
|
|
155
|
+
- 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:
|
|
156
|
+
- \`<trigger: a path, glob, or symbol>\` → <what must also change or be verified>
|
|
157
|
+
- 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.`;
|
|
158
|
+
function fullGuideRequest(material) {
|
|
159
|
+
return {
|
|
160
|
+
job: "synth_guide",
|
|
161
|
+
maxTokens: 16_000,
|
|
162
|
+
reasoningEffort: "high",
|
|
163
|
+
system: GUIDE_SYSTEM,
|
|
164
|
+
prompt: `Write a Markdown review method from these review findings.
|
|
165
|
+
- Start with one \`#\` title, one sentence of purpose, and one line on how to use the method.
|
|
166
|
+
${CONSOLIDATE}
|
|
167
|
+
${CHECK_SHAPE}
|
|
168
|
+
- No priority tags. No commands. No code fences. Return only the Markdown.
|
|
57
169
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
170
|
+
FINDINGS:
|
|
171
|
+
${material}`,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function shortGuideRequest(material, full) {
|
|
175
|
+
return {
|
|
176
|
+
job: "synth_guide_short",
|
|
177
|
+
maxTokens: 8_000,
|
|
178
|
+
reasoningEffort: "high",
|
|
179
|
+
system: GUIDE_SYSTEM,
|
|
180
|
+
prompt: `Write the short, reviewer-facing checklist from the full method below.
|
|
181
|
+
- Start with one \`#\` title, one sentence, then a plain line (not a bullet) linking to
|
|
182
|
+
[PR_REVIEW_DETAILED_GUIDE.md](PR_REVIEW_DETAILED_GUIDE.md) for the full method.
|
|
183
|
+
${CONSOLIDATE}
|
|
184
|
+
- Keep the highest-value checks, one per line, in the same shape:
|
|
185
|
+
- <what to check or require> · <why it matters here>
|
|
186
|
+
- End every pass with \`**Exit check:** <one line>\`.
|
|
187
|
+
- No priority tags, commands, pull-request numbers, ids, names, mentions or quotes.
|
|
188
|
+
- Do not use fenced code blocks. Return only the Markdown.
|
|
61
189
|
|
|
62
|
-
|
|
190
|
+
FULL METHOD:
|
|
191
|
+
${full}
|
|
63
192
|
|
|
64
|
-
|
|
65
|
-
|
|
193
|
+
FINDINGS:
|
|
194
|
+
${material}`,
|
|
195
|
+
};
|
|
66
196
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
export function reviewSignalCount(facts) {
|
|
71
|
-
return reviewFacts(facts).length;
|
|
197
|
+
function withTrailingNewline(text) {
|
|
198
|
+
const trimmed = text.trim();
|
|
199
|
+
return trimmed.endsWith("\n") ? trimmed : `${trimmed}\n`;
|
|
72
200
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
201
|
+
/** Builds the review method with the high model. Returns `undefined` below the
|
|
202
|
+
* signal threshold, which is a data condition, not an AI failure. There is no
|
|
203
|
+
* deterministic fallback: a failed or unusable generation fails the run. */
|
|
204
|
+
export async function synthesizeReviewGuides(provider, repo, ai, model, concurrency, facts, usage) {
|
|
205
|
+
const findings = guideFindings(facts);
|
|
206
|
+
if (findings.length <= 2)
|
|
207
|
+
return undefined;
|
|
208
|
+
const material = guideMaterial(facts);
|
|
209
|
+
// No validator: the guide is kept as written. Losing the run over format is
|
|
210
|
+
// not worth it, and a later `sync` reuses the cached text.
|
|
211
|
+
const queue = new AiBatch(provider, repo, Math.max(1, concurrency), `${ai}:v3:${model}:guide`);
|
|
212
|
+
const [fullResponse] = await queue.run([fullGuideRequest(material)], usage);
|
|
213
|
+
const full = cleanGuide(fullResponse?.text ?? "");
|
|
214
|
+
if (!full) {
|
|
215
|
+
// Not a failure: SKILL.md and CODEBASE.md are written anyway.
|
|
216
|
+
console.log("[ai] synth_guide produced nothing usable; skipping the guide");
|
|
76
217
|
return undefined;
|
|
77
|
-
const detailed = detailedDocument(detailedFacts(facts).slice(0, 120));
|
|
78
|
-
const detailedLines = detailed.trimEnd().split("\n").length;
|
|
79
|
-
if (detailedLines <= 100) {
|
|
80
|
-
return {
|
|
81
|
-
guide: `# PR review guide
|
|
82
|
-
|
|
83
|
-
Use this checklist before requesting review. These expectations occurred in
|
|
84
|
-
more than two selected pull-request review signals.
|
|
85
|
-
|
|
86
|
-
## Before requesting review
|
|
87
|
-
|
|
88
|
-
${selected.map((fact) => `- ${fact.claim}`).join("\n")}
|
|
89
|
-
`,
|
|
90
|
-
};
|
|
91
218
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
219
|
+
const fullLines = full.split("\n").length;
|
|
220
|
+
if (fullLines <= DETAIL_THRESHOLD_LINES) {
|
|
221
|
+
return { guide: withTrailingNewline(full) };
|
|
222
|
+
}
|
|
223
|
+
const [shortResponse] = await queue.run([shortGuideRequest(material, full)], usage);
|
|
224
|
+
const short = cleanGuide(shortResponse?.text ?? "");
|
|
225
|
+
if (!short)
|
|
226
|
+
return { guide: withTrailingNewline(full) };
|
|
227
|
+
return { guide: withTrailingNewline(short), detailed: full };
|
|
228
|
+
}
|
|
229
|
+
/** Strips a wrapping code fence and the tokens a guide must never carry (a
|
|
230
|
+
* priority tag, a mention, a pull-request number), so an otherwise good guide is
|
|
231
|
+
* cleaned rather than rejected. */
|
|
232
|
+
function cleanGuide(text) {
|
|
233
|
+
return text
|
|
234
|
+
.replace(/^```[a-zA-Z0-9_-]*\s*/, "")
|
|
235
|
+
.replace(/\s*```$/, "")
|
|
236
|
+
.replace(/\[\s*P[0-3]\s*\]/gi, "")
|
|
237
|
+
.replace(/@[A-Za-z0-9_-]{2,}/g, "")
|
|
238
|
+
.replace(/\bPR\s*#?\s*\d+\b/gi, "the change")
|
|
239
|
+
.replace(/[ \t]{2,}/g, " ")
|
|
240
|
+
.trim();
|
|
106
241
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Fact } from "./types.ts";
|
|
2
|
-
/** The full text of the sections that live in `CODEBASE.md
|
|
3
|
-
* only links to that file, so this is the
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
export declare function codebaseBody(facts: Fact[], overrides?: Record<string, string>): string;
|
|
2
|
+
/** The full text of the sections that live in `CODEBASE.md`, each authored by
|
|
3
|
+
* the synthesis job. The skill itself only links to that file, so this is the
|
|
4
|
+
* single place the codebase guidance is written out. */
|
|
5
|
+
export declare function codebaseBody(overrides?: Record<string, string>): string;
|
|
7
6
|
/** Slices an assembled skill's `## Heading` sections back out by section key,
|
|
8
7
|
* from `<!-- section:key -->` markers or (fallback) canonical heading text. */
|
|
9
8
|
export declare function extractSections(markdown: string): Record<string, string>;
|
|
@@ -1,51 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { codebaseSectionKeys, sectionAllowsPrFacts, sectionKeys, sectionTitles, } from "./sections.js";
|
|
1
|
+
import { codebaseSectionKeys, sectionKeys, sectionTitles } from "./sections.js";
|
|
3
2
|
function sectionFacts(facts, key) {
|
|
4
3
|
return facts
|
|
5
4
|
.filter((item) => item.sectionKey === key)
|
|
6
5
|
.sort((a, b) => b.weight - a.weight);
|
|
7
6
|
}
|
|
8
|
-
/** Facts a section may state. A fact read out of a single pull request is that
|
|
9
|
-
* request's narrative, not a rule, so only `review-bar` may use it. Facts
|
|
10
|
-
* written before `origin` existed count as repository policy. */
|
|
11
|
-
function usableFacts(facts, key) {
|
|
12
|
-
const items = sectionFacts(facts, key);
|
|
13
|
-
return sectionAllowsPrFacts(key)
|
|
14
|
-
? items
|
|
15
|
-
: items.filter((item) => !isPullRequestFact(item));
|
|
16
|
-
}
|
|
17
7
|
/** The link that stands in for a codebase section's text. */
|
|
18
8
|
function isCodebaseLink(section) {
|
|
19
9
|
return section.includes("[CODEBASE.md](CODEBASE.md)");
|
|
20
10
|
}
|
|
21
|
-
|
|
11
|
+
/** A codebase section in the skill is a link to `CODEBASE.md`, never text.
|
|
12
|
+
* Every other section's body is authored by the synthesis job: there is no
|
|
13
|
+
* deterministic fact renderer, so a section with no AI output is omitted. */
|
|
14
|
+
function render(key) {
|
|
22
15
|
if (codebaseSectionKeys.has(key)) {
|
|
23
16
|
return `## ${sectionTitles[key] ?? key}\n\nSee [CODEBASE.md](CODEBASE.md).`;
|
|
24
17
|
}
|
|
25
|
-
|
|
26
|
-
if (!items.length)
|
|
27
|
-
return "";
|
|
28
|
-
return `## ${sectionTitles[key] ?? key}\n\n${items.map((item) => `- ${item.claim}`).join("\n")}`;
|
|
18
|
+
return "";
|
|
29
19
|
}
|
|
30
|
-
function codebaseSectionText(key,
|
|
20
|
+
function codebaseSectionText(key, overrides) {
|
|
31
21
|
const override = overrides[key]?.trim();
|
|
32
22
|
if (override && hasBullets(override) && !isCodebaseLink(override)) {
|
|
33
23
|
return cleanSection(override);
|
|
34
24
|
}
|
|
35
|
-
|
|
36
|
-
if (!items.length)
|
|
37
|
-
return "";
|
|
38
|
-
return `## ${sectionTitles[key] ?? key}\n\n${items
|
|
39
|
-
.map((item) => `- ${item.claim}`)
|
|
40
|
-
.join("\n")}`;
|
|
25
|
+
return "";
|
|
41
26
|
}
|
|
42
|
-
/** The full text of the sections that live in `CODEBASE.md
|
|
43
|
-
* only links to that file, so this is the
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
export function codebaseBody(facts, overrides = {}) {
|
|
27
|
+
/** The full text of the sections that live in `CODEBASE.md`, each authored by
|
|
28
|
+
* the synthesis job. The skill itself only links to that file, so this is the
|
|
29
|
+
* single place the codebase guidance is written out. */
|
|
30
|
+
export function codebaseBody(overrides = {}) {
|
|
47
31
|
return [...codebaseSectionKeys]
|
|
48
|
-
.map((key) => codebaseSectionText(key,
|
|
32
|
+
.map((key) => codebaseSectionText(key, overrides))
|
|
49
33
|
.filter(Boolean)
|
|
50
34
|
.join("\n\n");
|
|
51
35
|
}
|
|
@@ -110,16 +94,15 @@ export async function assembleSkill(repo, facts, previousMarkdown, previousHashe
|
|
|
110
94
|
const changed = [];
|
|
111
95
|
const keys = sectionKeys.filter((key) => facts.some((item) => item.sectionKey === key));
|
|
112
96
|
for (const key of keys) {
|
|
113
|
-
const content = render(key
|
|
114
|
-
if (!content)
|
|
115
|
-
continue;
|
|
97
|
+
const content = render(key);
|
|
116
98
|
const relevant = sectionFacts(facts, key);
|
|
117
99
|
const sectionHash = await hash(JSON.stringify(relevant.map(hashInput)));
|
|
118
100
|
hashes[key] = sectionHash;
|
|
119
101
|
const canonicalHeading = `## ${sectionTitles[key] ?? key}`;
|
|
102
|
+
const override = overrides[key]?.trim();
|
|
120
103
|
// The codebase sections hold a link, not text, so the skill never takes a
|
|
121
104
|
// synthesized override for them; the override goes to CODEBASE.md instead.
|
|
122
|
-
const hasOverride =
|
|
105
|
+
const hasOverride = Boolean(override) && !codebaseSectionKeys.has(key);
|
|
123
106
|
if (!hasOverride &&
|
|
124
107
|
previousMarkdown &&
|
|
125
108
|
previousHashes[key] === sectionHash &&
|
|
@@ -132,8 +115,17 @@ export async function assembleSkill(repo, facts, previousMarkdown, previousHashe
|
|
|
132
115
|
continue;
|
|
133
116
|
}
|
|
134
117
|
const section = hasOverride ? overrides[key] : content;
|
|
135
|
-
|
|
136
|
-
|
|
118
|
+
if (!section) {
|
|
119
|
+
// A dirty text section the synthesis job did not return (a dropped unit):
|
|
120
|
+
// keep the previous body rather than dropping the section silently.
|
|
121
|
+
const prior = previous?.[key];
|
|
122
|
+
if (prior?.startsWith(canonicalHeading)) {
|
|
123
|
+
sections[key] = cleanSection(prior);
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
// A codebase section is a link, not a bullet list, and is kept even though
|
|
128
|
+
// it has no bullets.
|
|
137
129
|
if (!isCodebaseLink(section) && !hasBullets(section))
|
|
138
130
|
continue;
|
|
139
131
|
sections[key] = section;
|
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
import type { SkippedUnit } from "../ai/batch.ts";
|
|
2
1
|
import type { AiProvider, AiResponse, Options } from "../types.ts";
|
|
3
2
|
import type { Fact, Source } from "./types.ts";
|
|
4
3
|
type UsageSink = (job: string, response: AiResponse) => Promise<void>;
|
|
5
|
-
export type SkippedUnits = SkippedUnit[];
|
|
6
4
|
export type SynthesisResult = Record<string, string>;
|
|
7
5
|
export declare function extractAiFacts(provider: AiProvider, repo: string, source: Source, options: Options, usage?: UsageSink): Promise<Fact[]>;
|
|
8
|
-
export declare function extractAiFactsWithReport(provider: AiProvider, repo: string, source: Source, options: Options, usage?: UsageSink): Promise<{
|
|
9
|
-
facts: Fact[];
|
|
10
|
-
skipped: SkippedUnit[];
|
|
11
|
-
}>;
|
|
12
|
-
/** Same as {@link extractAiFacts}, but also reports what the batch skipped so
|
|
13
|
-
* the caller can put it in the final `[done]` line. */
|
|
14
|
-
export declare function enrichFactsWithReport(provider: AiProvider, repo: string, base: Fact[], source: Source, options: Options, usage?: UsageSink): Promise<{
|
|
15
|
-
facts: Fact[];
|
|
16
|
-
skipped: SkippedUnit[];
|
|
17
|
-
}>;
|
|
18
6
|
export declare function enrichFacts(provider: AiProvider, repo: string, base: Fact[], source: Source, options: Options, usage?: UsageSink): Promise<Fact[]>;
|
|
19
7
|
export declare function synthesizeSections(provider: AiProvider, repo: string, facts: Fact[], _previousMarkdown: string | undefined, ai: Options["ai"], model: string, concurrency: number, usage?: UsageSink, onlySections?: Set<string>): Promise<{
|
|
20
8
|
overrides: Record<string, string>;
|
|
21
|
-
skipped: SkippedUnit[];
|
|
22
9
|
}>;
|
|
23
10
|
export {};
|