@jagreehal/shepherd 0.13.1 → 0.13.2
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/package.json +1 -1
- package/skills/swarm/references/formats.md +4 -1
- package/src/summary.ts +52 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jagreehal/shepherd",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "Agent skills that drive a PR to merge-ready: a review swarm, thread triage, CI repair, and a loop that hands the result to stamp.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "github:jagreehal/shepherd",
|
|
@@ -84,7 +84,10 @@ read takes, 1 (a minute) to 5 (an hour or more). Draw a `diagram` only when the
|
|
|
84
84
|
change has a flow a reader would otherwise reconstruct (a request path, a state
|
|
85
85
|
machine, data moving between modules); leave it empty for a helper function.
|
|
86
86
|
The new fields are optional: a round without them renders as before. A field
|
|
87
|
-
written as `null` reads as absent and takes its default.
|
|
87
|
+
written as `null` reads as absent and takes its default. Write `evidence` as
|
|
88
|
+
the object above; text that labels its input, expected and actual result is
|
|
89
|
+
read too. A finding without a `title` takes its body's first sentence, and
|
|
90
|
+
`line` with `line_end` reads as `"line-line_end"`.
|
|
88
91
|
The renderers hold the round to what they can check. A `url`, `reintroduces`
|
|
89
92
|
or still-open link that names no review comment on the PR, or is not a
|
|
90
93
|
GitHub URL, loses its link.
|
package/src/summary.ts
CHANGED
|
@@ -23,11 +23,52 @@ const flag = (fallback: boolean) => z.boolean().nullish().transform((v) => v ??
|
|
|
23
23
|
|
|
24
24
|
const EvidenceParts = z.object({ input: z.string().min(1), expected: z.string().min(1), actual: z.string().min(1) });
|
|
25
25
|
|
|
26
|
-
/**
|
|
26
|
+
/** The body's first sentence or line, up to 100 characters. */
|
|
27
|
+
function firstSentence(body: string): string {
|
|
28
|
+
const sentence = body.trim().split(/(?<=[.!?])\s|\n/)[0] ?? "";
|
|
29
|
+
|
|
30
|
+
return sentence.length > 100 ? `${sentence.slice(0, 99).trimEnd()}…` : sentence;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// A label with any bold around it (`**Input:**`, `**Input**:`, `__Input:__`), so emphasis is read off the label alone.
|
|
34
|
+
const label = (words: string) => new RegExp(String.raw`(?:\*\*|__)?(?<![a-z0-9])(?:${words})(?:\*\*|__)?\s*[:=](?:\*\*|__)?`, "i");
|
|
35
|
+
|
|
36
|
+
// The labels a worked example uses for its three parts, with the synonyms models reach for.
|
|
37
|
+
const EVIDENCE_LABELS = {
|
|
38
|
+
input: label("input|given|for input|when called with"),
|
|
39
|
+
expected: label("expected|expect|should (?:be|return)|wanted|want"),
|
|
40
|
+
actual: label("actual|got|returns|result|observed"),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A worked example written as text, such as `Input: "Ada Lovelace" | Expected: "Ada" | Actual: "Lovelace"`: each label
|
|
45
|
+
* found in any order and case, bold around a label ignored, and any separator (`,` `;` `|` `·` `→` `->` ` - ` or a line
|
|
46
|
+
* break) between the parts. A label inside a quoted value is part of that value, and each value keeps its own
|
|
47
|
+
* characters, so `-1` and a closing `;` stay. The three parts, or nothing when a label is missing.
|
|
48
|
+
*/
|
|
27
49
|
function evidenceFromLine(line: string) {
|
|
28
|
-
|
|
50
|
+
// Blank each quoted value to its own length, so a label inside a quote stays part of the value and positions match.
|
|
51
|
+
const unquoted = line.replaceAll(/"(?:\\.|[^"\\\n])*"|`(?:\\.|[^`\\\n])*`|(?<![a-z0-9])'(?:\\.|[^'\\\n])*'/gi, (quoted) => " ".repeat(quoted.length));
|
|
52
|
+
|
|
53
|
+
const found = Object.entries(EVIDENCE_LABELS).flatMap(([part, pattern]) => {
|
|
54
|
+
const m = pattern.exec(unquoted);
|
|
29
55
|
|
|
30
|
-
|
|
56
|
+
return m ? [{ part, start: m.index, from: m.index + m[0].length }] : [];
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (found.length < 3) return undefined;
|
|
60
|
+
const ordered = [...found].sort((a, b) => a.start - b.start);
|
|
61
|
+
|
|
62
|
+
// One separator comes off a value that runs into the next label on the same line; a line break is separator enough.
|
|
63
|
+
const valueOf = (raw: string, last: boolean) => {
|
|
64
|
+
const value = raw.trim();
|
|
65
|
+
|
|
66
|
+
return last || /\n\s*$/.test(raw) ? value : value.replace(/\s*(?:[|,;·→]|[-=]>|(?<=\s)-)$/, "");
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const parts = Object.fromEntries(ordered.map((p, i) => [p.part, valueOf(line.slice(p.from, ordered[i + 1]?.start ?? line.length), i === ordered.length - 1)]));
|
|
70
|
+
|
|
71
|
+
return parts.input && parts.expected && parts.actual ? { input: parts.input, expected: parts.expected, actual: parts.actual } : undefined;
|
|
31
72
|
}
|
|
32
73
|
|
|
33
74
|
const VERDICT_ALIAS = alias({ changes_needed: "changes", approve_with_nits: "nits", looks_good: "good", approve: "good", approved: "good" });
|
|
@@ -64,6 +105,12 @@ const Finding = z.object({
|
|
|
64
105
|
checked: z.array(z.object({ command: z.string(), result: z.string() })).nullish().transform((v) => v ?? []),
|
|
65
106
|
docs: z.array(z.object({ url: z.string().regex(/^https:\/\/[^\s()<>`]+$/), title: z.string() })).nullish().transform((v) => v ?? []), // the documentation the claim rests on
|
|
66
107
|
reintroduces: absent(z.string().regex(THREAD_URL)).catch(undefined), // a resolved thread whose fix this change undoes
|
|
108
|
+
// A range written as `line` and `line_end` reads as "line-line_end".
|
|
109
|
+
line_end: absent(z.union([z.number().int().positive(), z.string().regex(/^[1-9]\d*$/).transform(Number)])),
|
|
110
|
+
}).transform(({ line_end: last, ...f }) => {
|
|
111
|
+
const start = /^\d+$/.test(String(f.line)) ? Number(f.line) : undefined;
|
|
112
|
+
|
|
113
|
+
return last !== undefined && start !== undefined && last > start ? { ...f, line: `${start}-${last}` } : f;
|
|
67
114
|
});
|
|
68
115
|
|
|
69
116
|
export const SummaryInput = z.object({
|
|
@@ -204,6 +251,8 @@ export function checkedRound(raw: SummaryInput, threads?: ReadonlySet<string>, r
|
|
|
204
251
|
|
|
205
252
|
for (const f of s.findings) {
|
|
206
253
|
f.convergent &&= f.lens.includes("+");
|
|
254
|
+
// A finding without a title takes its first sentence, so a reader can triage it by the title alone.
|
|
255
|
+
f.title ||= firstSentence(f.body);
|
|
207
256
|
f.url = real(f.url);
|
|
208
257
|
f.reintroduces = real(f.reintroduces);
|
|
209
258
|
|