@open-agent-toolkit/cli 0.1.13 → 0.1.14
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/assets/agents/oat-reviewer.md +54 -10
- package/assets/docs/workflows/projects/reviews.md +21 -2
- package/assets/docs/workflows/skills/index.md +2 -0
- package/assets/public-package-versions.json +4 -4
- package/assets/skills/oat-project-review-provide-remote/SKILL.md +354 -0
- package/assets/skills/oat-project-review-receive/SKILL.md +7 -10
- package/assets/skills/oat-project-review-receive-remote/SKILL.md +4 -4
- package/assets/skills/oat-review-provide-remote/SKILL.md +273 -0
- package/assets/skills/oat-review-receive/SKILL.md +6 -6
- package/assets/skills/oat-review-receive-remote/SKILL.md +5 -5
- package/dist/commands/init/tools/shared/skill-manifest.d.ts +2 -2
- package/dist/commands/init/tools/shared/skill-manifest.d.ts.map +1 -1
- package/dist/commands/init/tools/shared/skill-manifest.js +2 -0
- package/dist/review-remote/body-builder.d.ts +79 -0
- package/dist/review-remote/body-builder.d.ts.map +1 -0
- package/dist/review-remote/body-builder.js +103 -0
- package/dist/review-remote/capability-probe.d.ts +61 -0
- package/dist/review-remote/capability-probe.d.ts.map +1 -0
- package/dist/review-remote/capability-probe.js +87 -0
- package/dist/review-remote/line-mapper.d.ts +81 -0
- package/dist/review-remote/line-mapper.d.ts.map +1 -0
- package/dist/review-remote/line-mapper.js +165 -0
- package/dist/review-remote/marker-parser.d.ts +44 -0
- package/dist/review-remote/marker-parser.d.ts.map +1 -0
- package/dist/review-remote/marker-parser.js +97 -0
- package/dist/review-remote/narrowing.d.ts +81 -0
- package/dist/review-remote/narrowing.d.ts.map +1 -0
- package/dist/review-remote/narrowing.js +90 -0
- package/dist/review-remote/project-resolver.d.ts +46 -0
- package/dist/review-remote/project-resolver.d.ts.map +1 -0
- package/dist/review-remote/project-resolver.js +60 -0
- package/dist/review-remote/reviewer-dispatch.d.ts +108 -0
- package/dist/review-remote/reviewer-dispatch.d.ts.map +1 -0
- package/dist/review-remote/reviewer-dispatch.js +153 -0
- package/dist/review-remote/worktree.d.ts +62 -0
- package/dist/review-remote/worktree.d.ts.map +1 -0
- package/dist/review-remote/worktree.js +117 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability-probe.d.ts","sourceRoot":"","sources":["../../src/review-remote/capability-probe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC9B,4DAA4D;IAC5D,EAAE,EAAE,OAAO,CAAC;IACZ,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;AAEvD,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,eAAe,GAAG,SAAS,CAAC;AAEvE,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,OAAO,EAAE,cAAc,CAAC;IACxB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AA4CD;;;;;;GAMG;AACH,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE,SAAS,EAChB,KAAK,CAAC,EAAE,UAAU,GACjB,OAAO,CAAC,gBAAgB,CAAC,CA2B3B"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability probe for the optional `agent-reviews` posting flow (see design.md
|
|
3
|
+
* → Error Handling → Capability probe).
|
|
4
|
+
*
|
|
5
|
+
* The provide-remote skills prefer `agent-reviews` for tooling symmetry IF it
|
|
6
|
+
* exposes a "post / submit a full PR review" flow. The probe runs a
|
|
7
|
+
* non-mutating `agent-reviews --help` once, parses the help text for such a
|
|
8
|
+
* flag, and caches the result for the run. `gh api` is always the safe
|
|
9
|
+
* fallback — the probe never fails the skill.
|
|
10
|
+
*
|
|
11
|
+
* Empirical current-state finding (probed 2026-05-29, `agent-reviews@1.0.2`):
|
|
12
|
+
* the CLI exposes list/detail/watch commands plus `--reply <id>` for replying
|
|
13
|
+
* to existing comments, but NO command or flag that posts a full PR review. So
|
|
14
|
+
* the probe returns `not-supported` today and the skill posts via `gh api`.
|
|
15
|
+
* The probe is forward-compatible: when `agent-reviews` gains a posting flow,
|
|
16
|
+
* this parser recognizes it without a code change to the skill.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Candidate flag tokens that, if present in the help text, indicate a
|
|
20
|
+
* full-review posting flow. Reply-to-comment flags (`--reply`) are deliberately
|
|
21
|
+
* excluded — replying to an existing comment is not posting a review.
|
|
22
|
+
*
|
|
23
|
+
* The intent-specific tokens (`--post-review`, `--submit-review`) come first;
|
|
24
|
+
* the generic `--review`/`--post` are kept as broad fallbacks. The generic
|
|
25
|
+
* tokens carry a small forward-compat false-positive risk: a future
|
|
26
|
+
* `agent-reviews` could add `--review` with an unrelated meaning (e.g.
|
|
27
|
+
* "show a review"), which the probe would report as `supported`. That risk is
|
|
28
|
+
* accepted here because `gh api` remains the safe posting path even when the
|
|
29
|
+
* probe mis-detects an `agent-reviews` posting flow — a false positive degrades
|
|
30
|
+
* to the same fallback as `unknown`, it never drops or corrupts a review.
|
|
31
|
+
*/
|
|
32
|
+
const POSTING_FLAG_CANDIDATES = [
|
|
33
|
+
'--post-review',
|
|
34
|
+
'--submit-review',
|
|
35
|
+
'--review',
|
|
36
|
+
'--post',
|
|
37
|
+
];
|
|
38
|
+
/** Extract the first posting flag present in the help text, or `undefined`. */
|
|
39
|
+
function findPostingFlag(helpText) {
|
|
40
|
+
for (const flag of POSTING_FLAG_CANDIDATES) {
|
|
41
|
+
// Word-boundary-ish match: the flag followed by whitespace, `=`, or EOL, so
|
|
42
|
+
// `--post` does not spuriously match `--post-review` (and vice versa) and a
|
|
43
|
+
// substring of an unrelated token never matches.
|
|
44
|
+
const pattern = new RegExp(`(?:^|\\s)${escapeRegExp(flag)}(?=$|[\\s=])`, 'm');
|
|
45
|
+
if (pattern.test(helpText)) {
|
|
46
|
+
return flag;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
function escapeRegExp(value) {
|
|
52
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Probe whether `agent-reviews` supports posting a full PR review.
|
|
56
|
+
*
|
|
57
|
+
* @param probe injectable `agent-reviews --help` runner.
|
|
58
|
+
* @param cache optional per-run cache; when provided, the probe runs at most
|
|
59
|
+
* once and subsequent calls return the cached result.
|
|
60
|
+
*/
|
|
61
|
+
export async function probeAgentReviewsPosting(probe, cache) {
|
|
62
|
+
if (cache?.result !== undefined) {
|
|
63
|
+
return cache.result;
|
|
64
|
+
}
|
|
65
|
+
let outcome;
|
|
66
|
+
try {
|
|
67
|
+
outcome = await probe();
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// A rejecting probe is treated the same as an errored one: unknown.
|
|
71
|
+
outcome = { ok: false, stdout: '' };
|
|
72
|
+
}
|
|
73
|
+
let result;
|
|
74
|
+
if (!outcome.ok) {
|
|
75
|
+
result = { posting: 'unknown' };
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const flag = findPostingFlag(outcome.stdout);
|
|
79
|
+
result = flag
|
|
80
|
+
? { posting: 'supported', flag }
|
|
81
|
+
: { posting: 'not-supported' };
|
|
82
|
+
}
|
|
83
|
+
if (cache) {
|
|
84
|
+
cache.result = result;
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline-comment line-mapping validator (see design.md → Error Handling →
|
|
3
|
+
* Inline-comment line mapping).
|
|
4
|
+
*
|
|
5
|
+
* GitHub's `POST /repos/:owner/:repo/pulls/:N/reviews` rejects inline comments
|
|
6
|
+
* at file:line positions not present in the PR diff. Before adding a finding to
|
|
7
|
+
* the `comments[]` payload, the caller classifies it against the parsed hunk
|
|
8
|
+
* ranges. Out-of-diff findings are NOT silently dropped or shifted — the caller
|
|
9
|
+
* downgrades them to a top-level "Findings outside the PR diff" subsection.
|
|
10
|
+
*
|
|
11
|
+
* Two parsers feed one classifier with a single shared {@link HunkRange} shape:
|
|
12
|
+
* - {@link parsePullFilesPatch} for the per-file `patch` field of
|
|
13
|
+
* `gh api /repos/.../pulls/<N>/files` (rich-context mode).
|
|
14
|
+
* - {@link parseUnifiedDiff} for `gh pr diff <N>` (diff-only fallback mode).
|
|
15
|
+
*/
|
|
16
|
+
/** A single diff hunk's old- and new-side ranges. Shared by both parsers. */
|
|
17
|
+
export interface HunkRange {
|
|
18
|
+
/** 1-based start line on the old (LEFT) side. */
|
|
19
|
+
oldStart: number;
|
|
20
|
+
/** Line count on the old side. */
|
|
21
|
+
oldCount: number;
|
|
22
|
+
/** 1-based start line on the new (RIGHT) side. */
|
|
23
|
+
newStart: number;
|
|
24
|
+
/** Line count on the new side. */
|
|
25
|
+
newCount: number;
|
|
26
|
+
/** Pre-rename path, when the owning file was renamed. */
|
|
27
|
+
previousFilename?: string;
|
|
28
|
+
}
|
|
29
|
+
/** A finding location to classify against a file's hunk ranges. */
|
|
30
|
+
export interface FindingLocation {
|
|
31
|
+
file: string;
|
|
32
|
+
line: number;
|
|
33
|
+
/** Set when the finding is explicitly about removed code (LEFT side). */
|
|
34
|
+
removed?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface InDiffClassification {
|
|
37
|
+
status: 'in-diff';
|
|
38
|
+
side: 'RIGHT' | 'LEFT';
|
|
39
|
+
line: number;
|
|
40
|
+
}
|
|
41
|
+
export interface OutOfDiffClassification {
|
|
42
|
+
status: 'out-of-diff';
|
|
43
|
+
/** Original file reference, carried through for the downgrade subsection. */
|
|
44
|
+
file: string;
|
|
45
|
+
/** Original line reference, carried through for the downgrade subsection. */
|
|
46
|
+
line: number;
|
|
47
|
+
}
|
|
48
|
+
export type FindingClassification = InDiffClassification | OutOfDiffClassification;
|
|
49
|
+
/**
|
|
50
|
+
* Parse the `patch` field of a single `gh api .../pulls/<N>/files` entry into
|
|
51
|
+
* its hunk ranges. Returns `[]` for an empty patch (e.g., a binary file, whose
|
|
52
|
+
* entry has no `patch`).
|
|
53
|
+
*
|
|
54
|
+
* Caller contract for renamed files: a `gh api .../files` entry carries the
|
|
55
|
+
* pre-rename path in a sibling `previous_filename` field, NOT in `patch`. This
|
|
56
|
+
* parser only sees `patch`, so it cannot populate `HunkRange.previousFilename`
|
|
57
|
+
* in rich-context (gh api) mode. When a finding is reported against the
|
|
58
|
+
* pre-rename path, the caller must remap it to the entry's post-rename
|
|
59
|
+
* `filename` (using the JSON `previous_filename`) before calling
|
|
60
|
+
* `classifyFinding` — otherwise the finding is treated as out-of-diff. (The
|
|
61
|
+
* `gh pr diff` path handles this internally: `parseUnifiedDiff` records
|
|
62
|
+
* `previousFilename` from the `rename from` header.)
|
|
63
|
+
*/
|
|
64
|
+
export declare function parsePullFilesPatch(patch: string): HunkRange[];
|
|
65
|
+
/**
|
|
66
|
+
* Parse a full `gh pr diff <N>` unified diff into a map of post-image file path
|
|
67
|
+
* → hunk ranges. Renamed files are keyed under their post-rename path with
|
|
68
|
+
* `previousFilename` recorded; binary files map to an empty array.
|
|
69
|
+
*/
|
|
70
|
+
export declare function parseUnifiedDiff(diff: string): Record<string, HunkRange[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Classify a finding against a file's hunk ranges.
|
|
73
|
+
*
|
|
74
|
+
* A line inside any hunk's new-side range is `in-diff` on the `RIGHT` side
|
|
75
|
+
* (additions/context); when the finding is explicitly about removed code it is
|
|
76
|
+
* mapped to the `LEFT` side instead. A line outside every hunk — or a file with
|
|
77
|
+
* no ranges (binary) — is `out-of-diff`, carrying the original `file:line` so
|
|
78
|
+
* the caller can downgrade it without mutating the source finding.
|
|
79
|
+
*/
|
|
80
|
+
export declare function classifyFinding(finding: FindingLocation, ranges: HunkRange[]): FindingClassification;
|
|
81
|
+
//# sourceMappingURL=line-mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-mapper.d.ts","sourceRoot":"","sources":["../../src/review-remote/line-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,6EAA6E;AAC7E,MAAM,WAAW,SAAS;IACxB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,aAAa,CAAC;IACtB,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,qBAAqB,GAC7B,oBAAoB,GACpB,uBAAuB,CAAC;AAkB5B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAY9D;AAUD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CA+E1E;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,SAAS,EAAE,GAClB,qBAAqB,CAevB"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline-comment line-mapping validator (see design.md → Error Handling →
|
|
3
|
+
* Inline-comment line mapping).
|
|
4
|
+
*
|
|
5
|
+
* GitHub's `POST /repos/:owner/:repo/pulls/:N/reviews` rejects inline comments
|
|
6
|
+
* at file:line positions not present in the PR diff. Before adding a finding to
|
|
7
|
+
* the `comments[]` payload, the caller classifies it against the parsed hunk
|
|
8
|
+
* ranges. Out-of-diff findings are NOT silently dropped or shifted — the caller
|
|
9
|
+
* downgrades them to a top-level "Findings outside the PR diff" subsection.
|
|
10
|
+
*
|
|
11
|
+
* Two parsers feed one classifier with a single shared {@link HunkRange} shape:
|
|
12
|
+
* - {@link parsePullFilesPatch} for the per-file `patch` field of
|
|
13
|
+
* `gh api /repos/.../pulls/<N>/files` (rich-context mode).
|
|
14
|
+
* - {@link parseUnifiedDiff} for `gh pr diff <N>` (diff-only fallback mode).
|
|
15
|
+
*/
|
|
16
|
+
/** Matches a unified-diff hunk header: `@@ -a,b +c,d @@`. */
|
|
17
|
+
const HUNK_HEADER_PATTERN = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
|
|
18
|
+
function parseHunkHeader(line) {
|
|
19
|
+
const match = line.match(HUNK_HEADER_PATTERN);
|
|
20
|
+
if (!match) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const oldStart = Number(match[1]);
|
|
24
|
+
// A missing count means 1 per unified-diff convention.
|
|
25
|
+
const oldCount = match[2] === undefined ? 1 : Number(match[2]);
|
|
26
|
+
const newStart = Number(match[3]);
|
|
27
|
+
const newCount = match[4] === undefined ? 1 : Number(match[4]);
|
|
28
|
+
return { oldStart, oldCount, newStart, newCount };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse the `patch` field of a single `gh api .../pulls/<N>/files` entry into
|
|
32
|
+
* its hunk ranges. Returns `[]` for an empty patch (e.g., a binary file, whose
|
|
33
|
+
* entry has no `patch`).
|
|
34
|
+
*
|
|
35
|
+
* Caller contract for renamed files: a `gh api .../files` entry carries the
|
|
36
|
+
* pre-rename path in a sibling `previous_filename` field, NOT in `patch`. This
|
|
37
|
+
* parser only sees `patch`, so it cannot populate `HunkRange.previousFilename`
|
|
38
|
+
* in rich-context (gh api) mode. When a finding is reported against the
|
|
39
|
+
* pre-rename path, the caller must remap it to the entry's post-rename
|
|
40
|
+
* `filename` (using the JSON `previous_filename`) before calling
|
|
41
|
+
* `classifyFinding` — otherwise the finding is treated as out-of-diff. (The
|
|
42
|
+
* `gh pr diff` path handles this internally: `parseUnifiedDiff` records
|
|
43
|
+
* `previousFilename` from the `rename from` header.)
|
|
44
|
+
*/
|
|
45
|
+
export function parsePullFilesPatch(patch) {
|
|
46
|
+
if (!patch) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
const ranges = [];
|
|
50
|
+
for (const line of patch.split('\n')) {
|
|
51
|
+
const hunk = parseHunkHeader(line);
|
|
52
|
+
if (hunk) {
|
|
53
|
+
ranges.push(hunk);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return ranges;
|
|
57
|
+
}
|
|
58
|
+
/** Strip a leading `a/` or `b/` diff prefix from a path token. */
|
|
59
|
+
function stripDiffPrefix(path) {
|
|
60
|
+
if (path.startsWith('a/') || path.startsWith('b/')) {
|
|
61
|
+
return path.slice(2);
|
|
62
|
+
}
|
|
63
|
+
return path;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Parse a full `gh pr diff <N>` unified diff into a map of post-image file path
|
|
67
|
+
* → hunk ranges. Renamed files are keyed under their post-rename path with
|
|
68
|
+
* `previousFilename` recorded; binary files map to an empty array.
|
|
69
|
+
*/
|
|
70
|
+
export function parseUnifiedDiff(diff) {
|
|
71
|
+
const byFile = {};
|
|
72
|
+
if (!diff) {
|
|
73
|
+
return byFile;
|
|
74
|
+
}
|
|
75
|
+
const lines = diff.split('\n');
|
|
76
|
+
let currentFile = null;
|
|
77
|
+
let previousFilename;
|
|
78
|
+
let renameFrom;
|
|
79
|
+
const ensureFile = (path) => {
|
|
80
|
+
if (!byFile[path]) {
|
|
81
|
+
byFile[path] = [];
|
|
82
|
+
}
|
|
83
|
+
return byFile[path];
|
|
84
|
+
};
|
|
85
|
+
for (const line of lines) {
|
|
86
|
+
if (line.startsWith('diff --git ')) {
|
|
87
|
+
// `diff --git a/<old> b/<new>` — default the file to the new path.
|
|
88
|
+
const parts = line.slice('diff --git '.length).trim().split(' ');
|
|
89
|
+
const newPath = parts.length >= 2 ? stripDiffPrefix(parts[parts.length - 1]) : null;
|
|
90
|
+
currentFile = newPath;
|
|
91
|
+
previousFilename = undefined;
|
|
92
|
+
renameFrom = undefined;
|
|
93
|
+
if (currentFile) {
|
|
94
|
+
ensureFile(currentFile);
|
|
95
|
+
}
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (line.startsWith('rename from ')) {
|
|
99
|
+
renameFrom = line.slice('rename from '.length).trim();
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (line.startsWith('rename to ')) {
|
|
103
|
+
const renameTo = line.slice('rename to '.length).trim();
|
|
104
|
+
// Re-key under the post-rename path and drop the placeholder key.
|
|
105
|
+
if (currentFile && currentFile !== renameTo) {
|
|
106
|
+
delete byFile[currentFile];
|
|
107
|
+
}
|
|
108
|
+
currentFile = renameTo;
|
|
109
|
+
previousFilename = renameFrom;
|
|
110
|
+
ensureFile(currentFile);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (line.startsWith('+++ ')) {
|
|
114
|
+
const token = line.slice('+++ '.length).trim();
|
|
115
|
+
if (token !== '/dev/null') {
|
|
116
|
+
const path = stripDiffPrefix(token);
|
|
117
|
+
if (path && path !== currentFile) {
|
|
118
|
+
if (currentFile) {
|
|
119
|
+
delete byFile[currentFile];
|
|
120
|
+
}
|
|
121
|
+
currentFile = path;
|
|
122
|
+
ensureFile(currentFile);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (line.startsWith('Binary files ')) {
|
|
128
|
+
// Binary file: no hunks, keep the (already-ensured) empty array.
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const hunk = parseHunkHeader(line);
|
|
132
|
+
if (hunk && currentFile) {
|
|
133
|
+
if (previousFilename) {
|
|
134
|
+
hunk.previousFilename = previousFilename;
|
|
135
|
+
}
|
|
136
|
+
ensureFile(currentFile).push(hunk);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return byFile;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Classify a finding against a file's hunk ranges.
|
|
143
|
+
*
|
|
144
|
+
* A line inside any hunk's new-side range is `in-diff` on the `RIGHT` side
|
|
145
|
+
* (additions/context); when the finding is explicitly about removed code it is
|
|
146
|
+
* mapped to the `LEFT` side instead. A line outside every hunk — or a file with
|
|
147
|
+
* no ranges (binary) — is `out-of-diff`, carrying the original `file:line` so
|
|
148
|
+
* the caller can downgrade it without mutating the source finding.
|
|
149
|
+
*/
|
|
150
|
+
export function classifyFinding(finding, ranges) {
|
|
151
|
+
for (const range of ranges) {
|
|
152
|
+
if (finding.removed) {
|
|
153
|
+
const oldEnd = range.oldStart + range.oldCount - 1;
|
|
154
|
+
if (finding.line >= range.oldStart && finding.line <= oldEnd) {
|
|
155
|
+
return { status: 'in-diff', side: 'LEFT', line: finding.line };
|
|
156
|
+
}
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const newEnd = range.newStart + range.newCount - 1;
|
|
160
|
+
if (finding.line >= range.newStart && finding.line <= newEnd) {
|
|
161
|
+
return { status: 'in-diff', side: 'RIGHT', line: finding.line };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { status: 'out-of-diff', file: finding.file, line: finding.line };
|
|
165
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser for the posted-review-body marker block.
|
|
3
|
+
*
|
|
4
|
+
* The marker block is an HTML comment opened by `<!-- oat-review-metadata`
|
|
5
|
+
* carrying simple single-line YAML-ish scalars (see design.md → Data Models →
|
|
6
|
+
* Posted-review-body). GitHub renders the comment as nothing but preserves it
|
|
7
|
+
* across round-trips, so it is the durable routing channel between the
|
|
8
|
+
* provide-remote skills (writers) and the receive-remote skills (readers).
|
|
9
|
+
*
|
|
10
|
+
* This is intentionally a tolerant single-line scalar parser — NOT a full YAML
|
|
11
|
+
* parser. The schema is flat (no nested structures), so a line-oriented reader
|
|
12
|
+
* is sufficient and avoids a dependency the schema does not need.
|
|
13
|
+
*/
|
|
14
|
+
/** Token that opens the marker comment block. */
|
|
15
|
+
export declare const MARKER_BLOCK_OPEN = "oat-review-metadata";
|
|
16
|
+
export type ReviewInvocation = 'manual' | 'auto';
|
|
17
|
+
export interface MarkerBlock {
|
|
18
|
+
/** Always `true` for an OAT provide-remote review; the discriminator. */
|
|
19
|
+
oat_provide_remote: true;
|
|
20
|
+
/** Full 40-char hex SHA of the reviewed PR HEAD. */
|
|
21
|
+
oat_review_head_sha: string;
|
|
22
|
+
/** Scope token (`pNN`, `final`, …) or the `ad-hoc` sentinel. */
|
|
23
|
+
oat_review_scope: string;
|
|
24
|
+
/**
|
|
25
|
+
* Project path — present only on the project rail. Key existence (not a
|
|
26
|
+
* `null` value) discriminates project rail from ad-hoc rail.
|
|
27
|
+
*/
|
|
28
|
+
oat_project?: string;
|
|
29
|
+
/** How the review was invoked. Defaults to `manual` when omitted. */
|
|
30
|
+
oat_review_invocation: ReviewInvocation;
|
|
31
|
+
/** Forward-compat bag for unknown marker keys. Omitted when none seen. */
|
|
32
|
+
extras?: Record<string, string>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse the first OAT marker block out of a posted-review body.
|
|
36
|
+
*
|
|
37
|
+
* Returns `null` when the body is not an OAT provide-remote review — either
|
|
38
|
+
* because no marker block exists, because `oat_provide_remote` is not `true`,
|
|
39
|
+
* or because the recorded head SHA is not a valid 40-char hex SHA (a value the
|
|
40
|
+
* caller could not safely narrow against; returning null lets the caller fall
|
|
41
|
+
* back to full-scope review).
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseMarkerBlock(body: string): MarkerBlock | null;
|
|
44
|
+
//# sourceMappingURL=marker-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marker-parser.d.ts","sourceRoot":"","sources":["../../src/review-remote/marker-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,iDAAiD;AACjD,eAAO,MAAM,iBAAiB,wBAAwB,CAAC;AAavD,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEjD,MAAM,WAAW,WAAW;IAC1B,yEAAyE;IACzE,kBAAkB,EAAE,IAAI,CAAC;IACzB,oDAAoD;IACpD,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gEAAgE;IAChE,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qEAAqE;IACrE,qBAAqB,EAAE,gBAAgB,CAAC;IACxC,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAUD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAqEjE"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser for the posted-review-body marker block.
|
|
3
|
+
*
|
|
4
|
+
* The marker block is an HTML comment opened by `<!-- oat-review-metadata`
|
|
5
|
+
* carrying simple single-line YAML-ish scalars (see design.md → Data Models →
|
|
6
|
+
* Posted-review-body). GitHub renders the comment as nothing but preserves it
|
|
7
|
+
* across round-trips, so it is the durable routing channel between the
|
|
8
|
+
* provide-remote skills (writers) and the receive-remote skills (readers).
|
|
9
|
+
*
|
|
10
|
+
* This is intentionally a tolerant single-line scalar parser — NOT a full YAML
|
|
11
|
+
* parser. The schema is flat (no nested structures), so a line-oriented reader
|
|
12
|
+
* is sufficient and avoids a dependency the schema does not need.
|
|
13
|
+
*/
|
|
14
|
+
/** Token that opens the marker comment block. */
|
|
15
|
+
export const MARKER_BLOCK_OPEN = 'oat-review-metadata';
|
|
16
|
+
/**
|
|
17
|
+
* Matches the first `<!-- oat-review-metadata ... -->` HTML comment block.
|
|
18
|
+
* Non-greedy body capture so a later comment in prose never wins.
|
|
19
|
+
*/
|
|
20
|
+
const MARKER_BLOCK_PATTERN = new RegExp(`<!--\\s*${MARKER_BLOCK_OPEN}\\s*([\\s\\S]*?)-->`);
|
|
21
|
+
/** A full 40-character lowercase/uppercase hex SHA. */
|
|
22
|
+
const FULL_SHA_PATTERN = /^[0-9a-fA-F]{40}$/;
|
|
23
|
+
const KNOWN_KEYS = new Set([
|
|
24
|
+
'oat_provide_remote',
|
|
25
|
+
'oat_review_head_sha',
|
|
26
|
+
'oat_review_scope',
|
|
27
|
+
'oat_project',
|
|
28
|
+
'oat_review_invocation',
|
|
29
|
+
]);
|
|
30
|
+
/**
|
|
31
|
+
* Parse the first OAT marker block out of a posted-review body.
|
|
32
|
+
*
|
|
33
|
+
* Returns `null` when the body is not an OAT provide-remote review — either
|
|
34
|
+
* because no marker block exists, because `oat_provide_remote` is not `true`,
|
|
35
|
+
* or because the recorded head SHA is not a valid 40-char hex SHA (a value the
|
|
36
|
+
* caller could not safely narrow against; returning null lets the caller fall
|
|
37
|
+
* back to full-scope review).
|
|
38
|
+
*/
|
|
39
|
+
export function parseMarkerBlock(body) {
|
|
40
|
+
if (!body) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const match = body.match(MARKER_BLOCK_PATTERN);
|
|
44
|
+
if (!match || match[1] === undefined) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const raw = {};
|
|
48
|
+
for (const line of match[1].split('\n')) {
|
|
49
|
+
const trimmed = line.trim();
|
|
50
|
+
if (trimmed === '') {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const sep = trimmed.indexOf(':');
|
|
54
|
+
if (sep === -1) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const key = trimmed.slice(0, sep).trim().toLowerCase();
|
|
58
|
+
const value = trimmed.slice(sep + 1).trim();
|
|
59
|
+
if (key === '') {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
raw[key] = value;
|
|
63
|
+
}
|
|
64
|
+
if (raw['oat_provide_remote'] !== 'true') {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const headSha = raw['oat_review_head_sha'];
|
|
68
|
+
if (!headSha || !FULL_SHA_PATTERN.test(headSha)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const scope = raw['oat_review_scope'];
|
|
72
|
+
if (!scope) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const invocationRaw = raw['oat_review_invocation'];
|
|
76
|
+
const oat_review_invocation = invocationRaw === 'auto' ? 'auto' : 'manual';
|
|
77
|
+
const block = {
|
|
78
|
+
oat_provide_remote: true,
|
|
79
|
+
oat_review_head_sha: headSha,
|
|
80
|
+
oat_review_scope: scope,
|
|
81
|
+
oat_review_invocation,
|
|
82
|
+
};
|
|
83
|
+
// Project key existence (not a null value) discriminates the rail.
|
|
84
|
+
if ('oat_project' in raw && raw['oat_project'] !== '') {
|
|
85
|
+
block.oat_project = raw['oat_project'];
|
|
86
|
+
}
|
|
87
|
+
const extras = {};
|
|
88
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
89
|
+
if (!KNOWN_KEYS.has(key)) {
|
|
90
|
+
extras[key] = value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (Object.keys(extras).length > 0) {
|
|
94
|
+
block.extras = extras;
|
|
95
|
+
}
|
|
96
|
+
return block;
|
|
97
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-review narrowing filter + stale-SHA guard (see design.md → Component
|
|
3
|
+
* Design + Error Handling → Stale prior-review SHA).
|
|
4
|
+
*
|
|
5
|
+
* Given the PR's prior provide-remote reviews and a `(rail, project, scope)`
|
|
6
|
+
* tuple, pick the most recent matching review and decide whether the current
|
|
7
|
+
* pass can narrow to `<prior_sha>..<HEAD>`. The guard runs existence + ancestry
|
|
8
|
+
* checks (via an injected {@link GitInvoker}) before declaring a narrowing
|
|
9
|
+
* range, so a rebased/force-pushed/shallow prior SHA never produces a
|
|
10
|
+
* misleading partial range.
|
|
11
|
+
*/
|
|
12
|
+
import type { ReviewInvocation } from './marker-parser.js';
|
|
13
|
+
export type ReviewRail = 'ad-hoc' | 'project';
|
|
14
|
+
/** A prior provide-remote review, distilled from its parsed marker block. */
|
|
15
|
+
export interface PriorReview {
|
|
16
|
+
/** Full 40-char SHA recorded by the prior review. */
|
|
17
|
+
headSha: string;
|
|
18
|
+
/** Scope token or the `ad-hoc` sentinel. */
|
|
19
|
+
scope: string;
|
|
20
|
+
/** Project path — present only for project-rail reviews. */
|
|
21
|
+
project?: string;
|
|
22
|
+
invocation: ReviewInvocation;
|
|
23
|
+
/** ISO-8601 review submission timestamp, used for descending sort. */
|
|
24
|
+
submittedAt: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Narrow git surface needed by the guard. Callers pass a worktree-bound
|
|
28
|
+
* implementation (rich-context mode) or a fetch-capable one (diff-only mode);
|
|
29
|
+
* tests pass stubs.
|
|
30
|
+
*/
|
|
31
|
+
export interface GitInvoker {
|
|
32
|
+
/** `git cat-file -e <sha>` — does the object exist locally? */
|
|
33
|
+
objectExists(sha: string): Promise<boolean>;
|
|
34
|
+
/** `git merge-base --is-ancestor <sha> <head>` — reachable from HEAD? */
|
|
35
|
+
isAncestor(sha: string, head: string): Promise<boolean>;
|
|
36
|
+
/** `git fetch origin <sha>:<ref>` — fetch a single ref (diff-only mode). */
|
|
37
|
+
fetchRef(sha: string): Promise<boolean>;
|
|
38
|
+
}
|
|
39
|
+
export interface NarrowingInput {
|
|
40
|
+
reviews: PriorReview[];
|
|
41
|
+
rail: ReviewRail;
|
|
42
|
+
/** Resolved project path on the project rail; `null` on the ad-hoc rail. */
|
|
43
|
+
project: string | null;
|
|
44
|
+
/** Current scope token, or `ad-hoc`. */
|
|
45
|
+
scope: string;
|
|
46
|
+
/** Current PR HEAD SHA. */
|
|
47
|
+
headSha: string;
|
|
48
|
+
git: GitInvoker;
|
|
49
|
+
/** `--narrow` was passed explicitly: guard failure becomes a hard error. */
|
|
50
|
+
forceNarrow?: boolean;
|
|
51
|
+
/** `workflow.autoNarrowReReviewScope === true`: never prompt. */
|
|
52
|
+
autoNarrow?: boolean;
|
|
53
|
+
/** Diff-only mode (no ephemeral worktree): fetch the single ref first. */
|
|
54
|
+
diffOnly?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export type FullScopeReason = 'no-prior-review' | 'stale-sha';
|
|
57
|
+
export interface NarrowRangeResult {
|
|
58
|
+
kind: 'narrow-range';
|
|
59
|
+
priorSha: string;
|
|
60
|
+
headSha: string;
|
|
61
|
+
/** Whether the caller still owes the user a confirm prompt. */
|
|
62
|
+
prompted: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface FullScopeFallbackResult {
|
|
65
|
+
kind: 'full-scope-fallback';
|
|
66
|
+
reason: FullScopeReason;
|
|
67
|
+
/** The stale SHA that triggered the fallback, when applicable. */
|
|
68
|
+
priorSha?: string;
|
|
69
|
+
prompted: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface HardErrorResult {
|
|
72
|
+
kind: 'hard-error';
|
|
73
|
+
reason: 'stale-sha';
|
|
74
|
+
priorSha: string;
|
|
75
|
+
}
|
|
76
|
+
export type NarrowingResult = NarrowRangeResult | FullScopeFallbackResult | HardErrorResult;
|
|
77
|
+
/**
|
|
78
|
+
* Pick the narrowing target for the current re-review pass.
|
|
79
|
+
*/
|
|
80
|
+
export declare function pickNarrowingTarget(input: NarrowingInput): Promise<NarrowingResult>;
|
|
81
|
+
//# sourceMappingURL=narrowing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"narrowing.d.ts","sourceRoot":"","sources":["../../src/review-remote/narrowing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9C,6EAA6E;AAC7E,MAAM,WAAW,WAAW;IAC1B,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,gBAAgB,CAAC;IAC7B,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,+DAA+D;IAC/D,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,yEAAyE;IACzE,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACxD,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,IAAI,EAAE,UAAU,CAAC;IACjB,4EAA4E;IAC5E,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,UAAU,CAAC;IAChB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iEAAiE;IACjE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG,WAAW,CAAC;AAE9D,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,cAAc,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,qBAAqB,CAAC;IAC5B,MAAM,EAAE,eAAe,CAAC;IACxB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,eAAe,GACvB,iBAAiB,GACjB,uBAAuB,GACvB,eAAe,CAAC;AAiDpB;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC,eAAe,CAAC,CAuC1B"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-review narrowing filter + stale-SHA guard (see design.md → Component
|
|
3
|
+
* Design + Error Handling → Stale prior-review SHA).
|
|
4
|
+
*
|
|
5
|
+
* Given the PR's prior provide-remote reviews and a `(rail, project, scope)`
|
|
6
|
+
* tuple, pick the most recent matching review and decide whether the current
|
|
7
|
+
* pass can narrow to `<prior_sha>..<HEAD>`. The guard runs existence + ancestry
|
|
8
|
+
* checks (via an injected {@link GitInvoker}) before declaring a narrowing
|
|
9
|
+
* range, so a rebased/force-pushed/shallow prior SHA never produces a
|
|
10
|
+
* misleading partial range.
|
|
11
|
+
*/
|
|
12
|
+
/** Does a prior review match the current `(rail, project, scope)` tuple? */
|
|
13
|
+
function matchesTuple(review, input) {
|
|
14
|
+
if (input.rail === 'ad-hoc') {
|
|
15
|
+
// Ad-hoc: scope sentinel must match AND there must be no project key.
|
|
16
|
+
return review.scope === 'ad-hoc' && review.project === undefined;
|
|
17
|
+
}
|
|
18
|
+
// Project rail: same project AND same scope.
|
|
19
|
+
return (review.project !== undefined &&
|
|
20
|
+
review.project === input.project &&
|
|
21
|
+
review.scope === input.scope);
|
|
22
|
+
}
|
|
23
|
+
function mostRecentMatch(input) {
|
|
24
|
+
const matches = input.reviews.filter((r) => matchesTuple(r, input));
|
|
25
|
+
if (matches.length === 0) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
// Descending by submission time — newest matching review wins.
|
|
29
|
+
matches.sort((a, b) => b.submittedAt.localeCompare(a.submittedAt));
|
|
30
|
+
return matches[0];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Run the two-step stale-SHA guard. In diff-only mode, attempt a single-ref
|
|
34
|
+
* fetch before re-checking existence. Returns true only when the prior SHA both
|
|
35
|
+
* exists locally and is an ancestor of the current PR HEAD.
|
|
36
|
+
*/
|
|
37
|
+
async function guardPasses(priorSha, input) {
|
|
38
|
+
let exists = await input.git.objectExists(priorSha);
|
|
39
|
+
if (!exists && input.diffOnly) {
|
|
40
|
+
const fetched = await input.git.fetchRef(priorSha);
|
|
41
|
+
if (!fetched) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
exists = await input.git.objectExists(priorSha);
|
|
45
|
+
}
|
|
46
|
+
if (!exists) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return input.git.isAncestor(priorSha, input.headSha);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Pick the narrowing target for the current re-review pass.
|
|
53
|
+
*/
|
|
54
|
+
export async function pickNarrowingTarget(input) {
|
|
55
|
+
const prior = mostRecentMatch(input);
|
|
56
|
+
if (!prior) {
|
|
57
|
+
return {
|
|
58
|
+
kind: 'full-scope-fallback',
|
|
59
|
+
reason: 'no-prior-review',
|
|
60
|
+
prompted: false,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const passed = await guardPasses(prior.headSha, input);
|
|
64
|
+
if (passed) {
|
|
65
|
+
return {
|
|
66
|
+
kind: 'narrow-range',
|
|
67
|
+
priorSha: prior.headSha,
|
|
68
|
+
headSha: input.headSha,
|
|
69
|
+
// Auto-narrow skips the prompt; otherwise the caller still confirms.
|
|
70
|
+
prompted: !input.autoNarrow,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Guard failed. The user explicitly asked to narrow → hard error.
|
|
74
|
+
if (input.forceNarrow) {
|
|
75
|
+
return {
|
|
76
|
+
kind: 'hard-error',
|
|
77
|
+
reason: 'stale-sha',
|
|
78
|
+
priorSha: prior.headSha,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// Otherwise fall back to full scope. Auto-narrow surfaces this as the
|
|
82
|
+
// auto-fallback notice (no prompt); manual mode does not prompt here either —
|
|
83
|
+
// the fallback is informational.
|
|
84
|
+
return {
|
|
85
|
+
kind: 'full-scope-fallback',
|
|
86
|
+
reason: 'stale-sha',
|
|
87
|
+
priorSha: prior.headSha,
|
|
88
|
+
prompted: false,
|
|
89
|
+
};
|
|
90
|
+
}
|