peaks-loop 4.1.10 → 4.1.11
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/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +43 -0
- package/dist/cli/commands/code-review-commands.d.ts +1 -1
- package/dist/cli/commands/code-review-commands.js +23 -37
- package/dist/cli/commands/code-review-ocr-delegate-record.d.ts +3 -0
- package/dist/cli/commands/code-review-ocr-delegate-record.js +73 -0
- package/dist/cli/commands/code-review-ocr-delegate.d.ts +12 -0
- package/dist/cli/commands/code-review-ocr-delegate.js +140 -0
- package/dist/cli/commands/code-review-run-ocr-18.d.ts +11 -0
- package/dist/cli/commands/code-review-run-ocr-18.js +127 -0
- package/dist/services/lint/detect-ocr-18.js +1 -1
- package/dist/services/lint/ocr-18-acquire.d.ts +1 -1
- package/dist/services/lint/ocr-18-acquire.js +2 -2
- package/dist/services/lint/ocr-18-allowlist.d.ts +30 -0
- package/dist/services/lint/ocr-18-allowlist.js +165 -0
- package/dist/services/lint/ocr-18-delegate-packet.d.ts +84 -0
- package/dist/services/lint/ocr-18-delegate-packet.js +175 -0
- package/dist/services/lint/ocr-18-delegate-payload.d.ts +67 -0
- package/dist/services/lint/ocr-18-delegate-payload.js +208 -0
- package/dist/services/lint/ocr-18-delegate-record.d.ts +42 -0
- package/dist/services/lint/ocr-18-delegate-record.js +223 -0
- package/dist/services/lint/ocr-18-language-routing.d.ts +96 -0
- package/dist/services/lint/ocr-18-language-routing.js +148 -0
- package/dist/services/lint/ocr-18-multi.d.ts +54 -0
- package/dist/services/lint/ocr-18-multi.js +184 -0
- package/dist/services/lint/ocr-multilang-adapter.d.ts +45 -7
- package/dist/services/lint/ocr-multilang-adapter.js +133 -94
- package/package.json +10 -10
- package/skills/bee/peaks-rd/SKILL.md +32 -0
- package/skills/bee/peaks-rd/references/ocr-multilang-1.8.md +314 -111
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OCR 1.x multi-language review: detect which routed languages a git range
|
|
3
|
+
* touches, run `ocr review` ONCE for the whole change set, and group the
|
|
4
|
+
* returned comments by language.
|
|
5
|
+
*
|
|
6
|
+
* A Python+Go change costs one review, not two. A range with no routed language
|
|
7
|
+
* skips the invocation entirely — spawning OCR to discover there is nothing to
|
|
8
|
+
* review is exactly the cost this guard exists to avoid.
|
|
9
|
+
*/
|
|
10
|
+
import { spawnSync } from 'node:child_process';
|
|
11
|
+
import { buildReviewArgs, emptyByLanguage, invokeOcr, parseComments, summarize } from './ocr-multilang-adapter.js';
|
|
12
|
+
import { languageForPath } from './ocr-18-language-routing.js';
|
|
13
|
+
/** 16 MiB — the largest `git diff --name-only` list this repo reviews. */
|
|
14
|
+
const GIT_MAX_BUFFER = 16_777_216;
|
|
15
|
+
/**
|
|
16
|
+
* A ref is handed to git as its own argv entry. No valid revision starts with
|
|
17
|
+
* `-`, but an option-shaped value would let a caller inject a git flag
|
|
18
|
+
* (`--output=…`), so it is refused at the boundary rather than passed through.
|
|
19
|
+
*/
|
|
20
|
+
function checkedRef(value, flag) {
|
|
21
|
+
if (value.startsWith('-'))
|
|
22
|
+
throw new Error(`invalid ${flag} value: ${value}`);
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function changedFiles(cwd, range) {
|
|
26
|
+
const git = (args) => {
|
|
27
|
+
// `windowsHide` on every spawn (repo convention) — the child is a console app.
|
|
28
|
+
const result = spawnSync('git', [...args], {
|
|
29
|
+
cwd,
|
|
30
|
+
encoding: 'utf8',
|
|
31
|
+
windowsHide: true,
|
|
32
|
+
maxBuffer: GIT_MAX_BUFFER
|
|
33
|
+
});
|
|
34
|
+
if (result.error !== undefined && result.error !== null) {
|
|
35
|
+
throw new Error(`git ${args.join(' ')} failed: ${result.error.message}`);
|
|
36
|
+
}
|
|
37
|
+
if (result.status !== 0) {
|
|
38
|
+
const stderr = typeof result.stderr === 'string' ? result.stderr.trim() : '';
|
|
39
|
+
throw new Error(`git ${args.join(' ')} failed: ${stderr || `exit ${String(result.status)}`}`);
|
|
40
|
+
}
|
|
41
|
+
const stdout = typeof result.stdout === 'string' ? result.stdout : '';
|
|
42
|
+
return stdout
|
|
43
|
+
.split('\n')
|
|
44
|
+
.map((line) => line.trim())
|
|
45
|
+
.filter((line) => line.length > 0);
|
|
46
|
+
};
|
|
47
|
+
if (range.commit !== undefined) {
|
|
48
|
+
// `--commit` reviews one commit against its parent; `git show` is that diff
|
|
49
|
+
// and also works for a root commit.
|
|
50
|
+
return git([
|
|
51
|
+
'show',
|
|
52
|
+
'--pretty=format:',
|
|
53
|
+
'--name-only',
|
|
54
|
+
'--diff-filter=ACMR',
|
|
55
|
+
checkedRef(range.commit, '--commit')
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
if (range.from !== undefined || range.to !== undefined) {
|
|
59
|
+
const refs = [];
|
|
60
|
+
if (range.from !== undefined)
|
|
61
|
+
refs.push(checkedRef(range.from, '--from'));
|
|
62
|
+
if (range.to !== undefined)
|
|
63
|
+
refs.push(checkedRef(range.to, '--to'));
|
|
64
|
+
return git(['diff', '--name-only', '--diff-filter=ACMR', ...refs, '--']);
|
|
65
|
+
}
|
|
66
|
+
// The workspace, as `ocr review` defaults to it: staged + unstaged tracked
|
|
67
|
+
// changes vs HEAD, plus untracked files. Missing the untracked half would let
|
|
68
|
+
// a brand-new source file skip the review it is about to be part of.
|
|
69
|
+
return [
|
|
70
|
+
...git(['diff', '--name-only', '--diff-filter=ACMR', 'HEAD', '--']),
|
|
71
|
+
...git(['ls-files', '--others', '--exclude-standard'])
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Which routed languages (and which unrouted files) the requested range touches.
|
|
76
|
+
*
|
|
77
|
+
* @throws when git cannot answer — "could not detect" must not read as "nothing
|
|
78
|
+
* to review", so the caller is given the choice of what to say.
|
|
79
|
+
*/
|
|
80
|
+
export function detectLanguages(cwd, range = {}) {
|
|
81
|
+
const files = [...new Set(changedFiles(cwd, range))];
|
|
82
|
+
const languages = new Set();
|
|
83
|
+
const unsupportedFiles = [];
|
|
84
|
+
for (const file of files) {
|
|
85
|
+
const language = languageForPath(file);
|
|
86
|
+
if (language === null)
|
|
87
|
+
unsupportedFiles.push(file);
|
|
88
|
+
else
|
|
89
|
+
languages.add(language);
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
languages: [...languages].sort(),
|
|
93
|
+
changedFileCount: files.length,
|
|
94
|
+
unsupportedFiles
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function groupByLanguage(findings) {
|
|
98
|
+
const byLanguage = new Map();
|
|
99
|
+
const routed = [];
|
|
100
|
+
const unrouted = [];
|
|
101
|
+
for (const finding of findings) {
|
|
102
|
+
const language = languageForPath(finding.filePath);
|
|
103
|
+
if (language === null) {
|
|
104
|
+
unrouted.push(finding);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
routed.push(finding);
|
|
108
|
+
const bucket = byLanguage.get(language) ?? [];
|
|
109
|
+
bucket.push(finding);
|
|
110
|
+
byLanguage.set(language, bucket);
|
|
111
|
+
}
|
|
112
|
+
return { byLanguage, routed, unrouted };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Every requested/detected language gets an entry, so a clean language is a
|
|
116
|
+
* visible zero; a language that only appears in the findings is kept as well
|
|
117
|
+
* rather than dropped for not having been detected.
|
|
118
|
+
*/
|
|
119
|
+
function reportsFor(grouped, requested) {
|
|
120
|
+
const order = [...new Set([...requested, ...grouped.byLanguage.keys()])];
|
|
121
|
+
return order.map((language) => {
|
|
122
|
+
const bucket = grouped.byLanguage.get(language) ?? [];
|
|
123
|
+
return { language, findings: bucket, count: bucket.length };
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function countsFor(grouped) {
|
|
127
|
+
const counts = { ...emptyByLanguage() };
|
|
128
|
+
for (const [language, bucket] of grouped.byLanguage)
|
|
129
|
+
counts[language] = bucket.length;
|
|
130
|
+
return counts;
|
|
131
|
+
}
|
|
132
|
+
/** A result for an outcome that has no per-language reports — and so no zero. */
|
|
133
|
+
function stopped(base, state, start, rawOutput) {
|
|
134
|
+
return {
|
|
135
|
+
...base,
|
|
136
|
+
state,
|
|
137
|
+
languages: [],
|
|
138
|
+
unroutedFindings: [],
|
|
139
|
+
summary: null,
|
|
140
|
+
durationMs: Date.now() - start,
|
|
141
|
+
rawOutput
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* One review for the whole change set, findings grouped by language.
|
|
146
|
+
*
|
|
147
|
+
* The four outcomes a caller must be able to tell apart:
|
|
148
|
+
* 1. a language reported with findings (`count` > 0);
|
|
149
|
+
* 2. a language reported with count 0 while the state is `ok` — it ran and was clean;
|
|
150
|
+
* 3. `unsupportedFiles` — the file is in the diff but the CLI does not review it
|
|
151
|
+
* as a routed language (with state `no-routed-language` when that is ALL
|
|
152
|
+
* the range holds);
|
|
153
|
+
* 4. a state of `ocr18-missing` / `execution-failed` with `languages: []` — it
|
|
154
|
+
* never ran, so there is no zero to mistake for a clean result.
|
|
155
|
+
*/
|
|
156
|
+
export function runOcr18Multi(options) {
|
|
157
|
+
const start = Date.now();
|
|
158
|
+
const detection = detectLanguages(options.cwd, options);
|
|
159
|
+
const base = {
|
|
160
|
+
detected: detection.languages,
|
|
161
|
+
changedFileCount: detection.changedFileCount,
|
|
162
|
+
unsupportedFiles: detection.unsupportedFiles
|
|
163
|
+
};
|
|
164
|
+
// No routed language ⇒ no review. Spawning OCR to discover there is nothing
|
|
165
|
+
// to review is exactly the cost this guard exists to avoid.
|
|
166
|
+
if (detection.languages.length === 0)
|
|
167
|
+
return stopped(base, 'no-routed-language', start, '');
|
|
168
|
+
const invoked = invokeOcr(buildReviewArgs(options), options.cwd, options.timeoutMs);
|
|
169
|
+
if (!invoked.ok)
|
|
170
|
+
return stopped(base, invoked.state, start, invoked.rawOutput);
|
|
171
|
+
const parsed = invoked.stdout.trim().length === 0 ? { ok: true, findings: [] } : parseComments(invoked.stdout);
|
|
172
|
+
if (!parsed.ok)
|
|
173
|
+
return stopped(base, 'execution-failed', start, invoked.stderr || invoked.stdout);
|
|
174
|
+
const grouped = groupByLanguage(parsed.findings);
|
|
175
|
+
return {
|
|
176
|
+
...base,
|
|
177
|
+
state: 'ok',
|
|
178
|
+
languages: reportsFor(grouped, options.languages ?? detection.languages),
|
|
179
|
+
unroutedFindings: grouped.unrouted,
|
|
180
|
+
summary: summarize(grouped.routed, countsFor(grouped)),
|
|
181
|
+
durationMs: Date.now() - start,
|
|
182
|
+
rawOutput: invoked.stdout
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
3
|
-
export type
|
|
4
|
-
export type Ocr18State = 'ok' | 'ocr18-missing' | 'binary-missing' | 'llm-config-missing' | 'execution-failed' | 'language-unsupported';
|
|
1
|
+
import { type Ocr18Language } from './ocr-18-language-routing.js';
|
|
2
|
+
export declare const OCR_18_PACKAGE = "@alibaba-group/open-code-review@1.13.1";
|
|
3
|
+
export type Ocr18State = 'ok' | 'no-routed-language' | 'ocr18-missing' | 'binary-missing' | 'llm-config-missing' | 'execution-failed' | 'language-unsupported';
|
|
5
4
|
export type Ocr18Finding = {
|
|
6
5
|
readonly filePath: string;
|
|
7
6
|
readonly line: number;
|
|
@@ -21,14 +20,53 @@ export type Ocr18RunResult = {
|
|
|
21
20
|
readonly durationMs: number;
|
|
22
21
|
readonly rawOutput: string;
|
|
23
22
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
readonly language: string;
|
|
23
|
+
/** The git range a review covers; empty means "the workspace" (what `ocr review` defaults to). */
|
|
24
|
+
export type Ocr18Range = {
|
|
27
25
|
readonly from?: string;
|
|
28
26
|
readonly to?: string;
|
|
29
27
|
readonly commit?: string;
|
|
28
|
+
};
|
|
29
|
+
export type Ocr18RunOptions = Ocr18Range & {
|
|
30
|
+
readonly cwd: string;
|
|
31
|
+
/** Required for a review; ignored by delegation mode, which is not language-scoped. */
|
|
32
|
+
readonly language?: string;
|
|
30
33
|
readonly delegate?: boolean;
|
|
31
34
|
readonly timeoutMs?: number;
|
|
32
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* The one severity map: OCR comments (`parseComments`) and the delegated
|
|
38
|
+
* envelope (`ocr-18-delegate-record`) both map through it, so the two cannot
|
|
39
|
+
* disagree about what `high` means.
|
|
40
|
+
*/
|
|
41
|
+
export declare function severityFor(value: unknown): 'error' | 'warn' | 'info';
|
|
42
|
+
export declare function emptyByLanguage(): Readonly<Record<Ocr18Language, number>>;
|
|
43
|
+
export declare function rangeArgs(range: Ocr18Range): string[];
|
|
44
|
+
/** The review argv — no language flag exists, and none is emitted. */
|
|
45
|
+
export declare function buildReviewArgs(range: Ocr18Range): string[];
|
|
33
46
|
export declare function buildOcr18Args(options: Ocr18RunOptions): string[];
|
|
47
|
+
export type Ocr18Invocation = {
|
|
48
|
+
readonly ok: true;
|
|
49
|
+
readonly stdout: string;
|
|
50
|
+
readonly stderr: string;
|
|
51
|
+
} | {
|
|
52
|
+
readonly ok: false;
|
|
53
|
+
readonly state: Ocr18State;
|
|
54
|
+
readonly rawOutput: string;
|
|
55
|
+
};
|
|
56
|
+
export declare function invokeOcr(args: readonly string[], cwd: string, timeoutMs?: number): Ocr18Invocation;
|
|
57
|
+
export type ParsedComments = {
|
|
58
|
+
readonly ok: true;
|
|
59
|
+
readonly findings: readonly Ocr18Finding[];
|
|
60
|
+
} | {
|
|
61
|
+
readonly ok: false;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* `comments[]` from the real 1.13.1 envelope, mapped onto `Ocr18Finding`.
|
|
65
|
+
*
|
|
66
|
+
* A discriminated result rather than `null`: `{ ok: false }` is the execution
|
|
67
|
+
* failure the caller must report, and it cannot be mistaken for an empty review
|
|
68
|
+
* (which is `{ ok: true, findings: [] }`).
|
|
69
|
+
*/
|
|
70
|
+
export declare function parseComments(stdout: string): ParsedComments;
|
|
71
|
+
export declare function summarize(findings: readonly Ocr18Finding[], counts: Readonly<Record<Ocr18Language, number>>): Ocr18Summary;
|
|
34
72
|
export declare function runOcr18(options: Ocr18RunOptions): Ocr18RunResult;
|
|
@@ -1,152 +1,191 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OCR 1.
|
|
3
|
-
*
|
|
2
|
+
* OCR 1.x reviewer adapter: builds the argv, spawns the pinned runtime, and maps
|
|
3
|
+
* its real `comments[]` envelope onto `Ocr18Finding`.
|
|
4
|
+
*
|
|
5
|
+
* The pinned CLI has NO language flag — `--filter-language` is not a flag of the
|
|
6
|
+
* real binary (`Error: unknown flag`) — so this module never emits one. Language
|
|
7
|
+
* attribution lives in `ocr-18-language-routing.ts` and the one-review-many-
|
|
8
|
+
* languages path in `ocr-18-multi.ts`.
|
|
4
9
|
*/
|
|
5
10
|
import { spawnSync } from 'node:child_process';
|
|
6
11
|
import { resolveNpxInvocation } from './npx-resolver.js';
|
|
7
|
-
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
'
|
|
16
|
-
'php'
|
|
17
|
-
];
|
|
18
|
-
function isSupportedLanguage(value) {
|
|
19
|
-
return OCR_18_LANGUAGES.includes(value);
|
|
20
|
-
}
|
|
21
|
-
function severityFor(value) {
|
|
22
|
-
if (value === 'error' || value === 'critical' || value === 2)
|
|
12
|
+
import { isSupportedLanguage, languageForPath, OCR_18_LANGUAGES } from './ocr-18-language-routing.js';
|
|
13
|
+
export const OCR_18_PACKAGE = '@alibaba-group/open-code-review@1.13.1';
|
|
14
|
+
/**
|
|
15
|
+
* The one severity map: OCR comments (`parseComments`) and the delegated
|
|
16
|
+
* envelope (`ocr-18-delegate-record`) both map through it, so the two cannot
|
|
17
|
+
* disagree about what `high` means.
|
|
18
|
+
*/
|
|
19
|
+
export function severityFor(value) {
|
|
20
|
+
if (value === 'error' || value === 'critical' || value === 'high' || value === 2)
|
|
23
21
|
return 'error';
|
|
24
|
-
if (value === 'warn' || value === 'warning' || value === 1)
|
|
22
|
+
if (value === 'warn' || value === 'warning' || value === 'medium' || value === 1)
|
|
25
23
|
return 'warn';
|
|
26
24
|
return 'info';
|
|
27
25
|
}
|
|
28
|
-
function emptyByLanguage() {
|
|
26
|
+
export function emptyByLanguage() {
|
|
29
27
|
const out = {};
|
|
30
|
-
for (const
|
|
31
|
-
out[
|
|
28
|
+
for (const language of OCR_18_LANGUAGES) {
|
|
29
|
+
out[language] = 0;
|
|
32
30
|
}
|
|
33
31
|
return out;
|
|
34
32
|
}
|
|
33
|
+
export function rangeArgs(range) {
|
|
34
|
+
const args = [];
|
|
35
|
+
if (range.from !== undefined)
|
|
36
|
+
args.push('--from', range.from);
|
|
37
|
+
if (range.to !== undefined)
|
|
38
|
+
args.push('--to', range.to);
|
|
39
|
+
if (range.commit !== undefined)
|
|
40
|
+
args.push('--commit', range.commit);
|
|
41
|
+
return args;
|
|
42
|
+
}
|
|
43
|
+
/** The review argv — no language flag exists, and none is emitted. */
|
|
44
|
+
export function buildReviewArgs(range) {
|
|
45
|
+
return [
|
|
46
|
+
'--package',
|
|
47
|
+
OCR_18_PACKAGE,
|
|
48
|
+
'--',
|
|
49
|
+
'ocr',
|
|
50
|
+
'review',
|
|
51
|
+
...rangeArgs(range),
|
|
52
|
+
'--format',
|
|
53
|
+
'json'
|
|
54
|
+
];
|
|
55
|
+
}
|
|
35
56
|
export function buildOcr18Args(options) {
|
|
36
|
-
if (!isSupportedLanguage(options.language)) {
|
|
37
|
-
throw Object.assign(new Error(`unsupported language: ${options.language}`), {
|
|
38
|
-
code: 'LANGUAGE_UNSUPPORTED'
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
const args = ['--package', OCR_18_PACKAGE, '--', 'ocr'];
|
|
42
57
|
if (options.delegate === true) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
args.push('--to', options.to);
|
|
48
|
-
if (options.commit !== undefined)
|
|
49
|
-
args.push('--commit', options.commit);
|
|
58
|
+
// Delegation mode hands the host agent a spec and takes no language: the
|
|
59
|
+
// language is ignored by `ocr delegate preview`, so requiring one would be
|
|
60
|
+
// a value the code carries but does not mean.
|
|
61
|
+
return ['--package', OCR_18_PACKAGE, '--', 'ocr', 'delegate', 'preview', ...rangeArgs(options)];
|
|
50
62
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (options.to !== undefined)
|
|
56
|
-
args.push('--to', options.to);
|
|
57
|
-
if (options.commit !== undefined)
|
|
58
|
-
args.push('--commit', options.commit);
|
|
59
|
-
args.push('--format', 'json');
|
|
63
|
+
if (options.language === undefined || !isSupportedLanguage(options.language)) {
|
|
64
|
+
throw Object.assign(new Error(`unsupported language: ${options.language ?? '<missing>'}`), {
|
|
65
|
+
code: 'LANGUAGE_UNSUPPORTED'
|
|
66
|
+
});
|
|
60
67
|
}
|
|
61
|
-
return
|
|
68
|
+
return buildReviewArgs(options);
|
|
62
69
|
}
|
|
63
|
-
export function
|
|
64
|
-
const start = Date.now();
|
|
65
|
-
if (!isSupportedLanguage(options.language)) {
|
|
66
|
-
return {
|
|
67
|
-
state: 'language-unsupported',
|
|
68
|
-
findings: [],
|
|
69
|
-
summary: null,
|
|
70
|
-
durationMs: Date.now() - start,
|
|
71
|
-
rawOutput: `unsupported language: ${options.language}`
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
const args = buildOcr18Args(options);
|
|
70
|
+
export function invokeOcr(args, cwd, timeoutMs) {
|
|
75
71
|
const spawnOptions = {
|
|
76
|
-
cwd
|
|
72
|
+
cwd,
|
|
77
73
|
encoding: 'utf8',
|
|
78
74
|
// Repo convention: without this the child pops a console window on the
|
|
79
75
|
// user's desktop — and this child can run for the length of a full review.
|
|
80
76
|
windowsHide: true,
|
|
81
|
-
timeout:
|
|
77
|
+
timeout: timeoutMs ?? 60_000,
|
|
82
78
|
maxBuffer: 32 * 1024 * 1024
|
|
83
79
|
};
|
|
84
80
|
// 2026-09-10: bare `spawnSync('npx', …)` cannot launch the Windows `npx.cmd`
|
|
85
81
|
// shim (ENOENT, no shell) — same fix and same helper as `detect-ocr-18.ts` /
|
|
86
|
-
// `detect-eslint.ts`. `shell: true` is NOT an option: it would concatenate
|
|
87
|
-
// argv unescaped and split the `--package` flag.
|
|
88
|
-
const { command, args: npxArgs, baseEnv } = resolveNpxInvocation(args);
|
|
82
|
+
// `detect-eslint.ts`. `shell: true` is NOT an option: it would concatenate
|
|
83
|
+
// the argv unescaped and split the `--package` flag.
|
|
84
|
+
const { command, args: npxArgs, baseEnv } = resolveNpxInvocation([...args]);
|
|
89
85
|
const result = spawnSync(command, npxArgs, { ...spawnOptions, env: baseEnv });
|
|
90
86
|
const stdout = typeof result.stdout === 'string' ? result.stdout : '';
|
|
91
87
|
const stderr = typeof result.stderr === 'string' ? result.stderr : '';
|
|
92
88
|
if (result.error !== undefined && result.error !== null) {
|
|
93
89
|
return {
|
|
90
|
+
ok: false,
|
|
94
91
|
state: 'ocr18-missing',
|
|
95
|
-
findings: [],
|
|
96
|
-
summary: null,
|
|
97
|
-
durationMs: Date.now() - start,
|
|
98
92
|
// Never discard WHY the launch failed — stdout/stderr are both empty here.
|
|
99
93
|
rawOutput: stderr || stdout || result.error.message
|
|
100
94
|
};
|
|
101
95
|
}
|
|
102
96
|
if (result.status !== 0) {
|
|
97
|
+
return { ok: false, state: 'execution-failed', rawOutput: stderr || stdout };
|
|
98
|
+
}
|
|
99
|
+
return { ok: true, stdout, stderr };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* `comments[]` from the real 1.13.1 envelope, mapped onto `Ocr18Finding`.
|
|
103
|
+
*
|
|
104
|
+
* A discriminated result rather than `null`: `{ ok: false }` is the execution
|
|
105
|
+
* failure the caller must report, and it cannot be mistaken for an empty review
|
|
106
|
+
* (which is `{ ok: true, findings: [] }`).
|
|
107
|
+
*/
|
|
108
|
+
export function parseComments(stdout) {
|
|
109
|
+
let parsed;
|
|
110
|
+
try {
|
|
111
|
+
parsed = JSON.parse(stdout);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return { ok: false };
|
|
115
|
+
}
|
|
116
|
+
// A missing or non-array `comments` is a clean review, not a parse failure.
|
|
117
|
+
if (!Array.isArray(parsed.comments))
|
|
118
|
+
return { ok: true, findings: [] };
|
|
119
|
+
const findings = [];
|
|
120
|
+
for (const entry of parsed.comments) {
|
|
121
|
+
if (entry === null || typeof entry !== 'object')
|
|
122
|
+
continue;
|
|
123
|
+
const comment = entry;
|
|
124
|
+
findings.push({
|
|
125
|
+
filePath: typeof comment.path === 'string' ? comment.path : '',
|
|
126
|
+
line: typeof comment.start_line === 'number' ? comment.start_line : 0,
|
|
127
|
+
ruleId: typeof comment.category === 'string' ? comment.category : null,
|
|
128
|
+
severity: severityFor(comment.severity),
|
|
129
|
+
message: typeof comment.content === 'string' ? comment.content : ''
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return { ok: true, findings };
|
|
133
|
+
}
|
|
134
|
+
export function summarize(findings, counts) {
|
|
135
|
+
const bySeverity = { error: 0, warn: 0, info: 0 };
|
|
136
|
+
for (const finding of findings)
|
|
137
|
+
bySeverity[finding.severity]++;
|
|
138
|
+
return { total: findings.length, bySeverity, byLanguage: counts };
|
|
139
|
+
}
|
|
140
|
+
export function runOcr18(options) {
|
|
141
|
+
const start = Date.now();
|
|
142
|
+
const language = options.language;
|
|
143
|
+
if (options.delegate !== true && (language === undefined || !isSupportedLanguage(language))) {
|
|
103
144
|
return {
|
|
104
|
-
state: '
|
|
145
|
+
state: 'language-unsupported',
|
|
105
146
|
findings: [],
|
|
106
147
|
summary: null,
|
|
107
148
|
durationMs: Date.now() - start,
|
|
108
|
-
rawOutput:
|
|
149
|
+
rawOutput: `unsupported language: ${language ?? '<missing>'}`
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const invoked = invokeOcr(buildOcr18Args(options), options.cwd, options.timeoutMs);
|
|
153
|
+
if (!invoked.ok) {
|
|
154
|
+
return {
|
|
155
|
+
state: invoked.state,
|
|
156
|
+
findings: [],
|
|
157
|
+
summary: null,
|
|
158
|
+
durationMs: Date.now() - start,
|
|
159
|
+
rawOutput: invoked.rawOutput
|
|
109
160
|
};
|
|
110
161
|
}
|
|
111
162
|
let findings = [];
|
|
112
|
-
if (stdout.trim().length > 0) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (Array.isArray(parsed.findings)) {
|
|
116
|
-
for (const entry of parsed.findings) {
|
|
117
|
-
if (entry === null || typeof entry !== 'object')
|
|
118
|
-
continue;
|
|
119
|
-
const f = entry;
|
|
120
|
-
findings.push({
|
|
121
|
-
filePath: typeof f.file === 'string' ? f.file : '',
|
|
122
|
-
line: typeof f.line === 'number' ? f.line : 0,
|
|
123
|
-
ruleId: typeof f.rule === 'string' ? f.rule : null,
|
|
124
|
-
severity: severityFor(f.severity),
|
|
125
|
-
message: typeof f.message === 'string' ? f.message : ''
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
163
|
+
if (invoked.stdout.trim().length > 0) {
|
|
164
|
+
const parsed = parseComments(invoked.stdout);
|
|
165
|
+
if (!parsed.ok) {
|
|
131
166
|
return {
|
|
132
167
|
state: 'execution-failed',
|
|
133
168
|
findings: [],
|
|
134
169
|
summary: null,
|
|
135
170
|
durationMs: Date.now() - start,
|
|
136
|
-
rawOutput: stderr || stdout
|
|
171
|
+
rawOutput: invoked.stderr || invoked.stdout
|
|
137
172
|
};
|
|
138
173
|
}
|
|
174
|
+
// A single-language run reports only that language. Delegation mode has no
|
|
175
|
+
// language, and its preview carries no comments, so nothing is filtered.
|
|
176
|
+
findings =
|
|
177
|
+
language === undefined
|
|
178
|
+
? parsed.findings
|
|
179
|
+
: parsed.findings.filter((finding) => languageForPath(finding.filePath) === language);
|
|
139
180
|
}
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const byLanguageMut = { ...emptyByLanguage() };
|
|
144
|
-
byLanguageMut[options.language] = findings.length;
|
|
181
|
+
const byLanguage = { ...emptyByLanguage() };
|
|
182
|
+
if (language !== undefined && isSupportedLanguage(language))
|
|
183
|
+
byLanguage[language] = findings.length;
|
|
145
184
|
return {
|
|
146
185
|
state: 'ok',
|
|
147
186
|
findings,
|
|
148
|
-
summary:
|
|
187
|
+
summary: summarize(findings, byLanguage),
|
|
149
188
|
durationMs: Date.now() - start,
|
|
150
|
-
rawOutput: stdout
|
|
189
|
+
rawOutput: invoked.stdout
|
|
151
190
|
};
|
|
152
191
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peaks-loop",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.11",
|
|
4
4
|
"description": "Loop Engineering CLI — workflow primitive / loop guards / evaluators / slice orchestration",
|
|
5
5
|
"author": "SquabbyZ",
|
|
6
6
|
"keywords": [
|
|
@@ -121,18 +121,18 @@
|
|
|
121
121
|
"node": ">=24.0.0"
|
|
122
122
|
},
|
|
123
123
|
"dependencies": {
|
|
124
|
-
"@alibaba-group/open-code-review": "^1.
|
|
124
|
+
"@alibaba-group/open-code-review": "^1.13.1",
|
|
125
125
|
"@colbymchenry/codegraph": "1.6.2",
|
|
126
|
-
"@upstash/context7-mcp": "^4.
|
|
126
|
+
"@upstash/context7-mcp": "^4.4.4",
|
|
127
127
|
"commander": "^12.1.0",
|
|
128
128
|
"fzf": "^0.5.2",
|
|
129
|
-
"picomatch": "4.0.
|
|
130
|
-
"yaml": "^2.9.
|
|
131
|
-
"zod": "^4.
|
|
132
|
-
"peaks-loop-internal-runtime": "0.0.
|
|
133
|
-
"peaks-loop-shared
|
|
134
|
-
"peaks-loop-
|
|
135
|
-
"peaks-loop-
|
|
129
|
+
"picomatch": "4.0.7",
|
|
130
|
+
"yaml": "^2.9.1",
|
|
131
|
+
"zod": "^4.6.7",
|
|
132
|
+
"peaks-loop-internal-runtime": "0.0.51",
|
|
133
|
+
"peaks-loop-shared": "0.0.100",
|
|
134
|
+
"peaks-loop-mut": "0.1.65",
|
|
135
|
+
"peaks-loop-shared-channel": "0.0.68"
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
138
|
"@changesets/cli": "2.31.1",
|
|
@@ -187,6 +187,38 @@ Both audit skills consume the immutable peaks-prd handoff (`prd/handoff.md`) and
|
|
|
187
187
|
|
|
188
188
|
Full dispatch contract (when-to-fan-out rules, dispatch template, prereq gates) lives in **`references/parallel-review-fanout.md`**. Read that file before issuing any 3-way fan-out.
|
|
189
189
|
|
|
190
|
+
### Gate B3 — OCR 1.x supplementary pass (wired 2026-10-20)
|
|
191
|
+
|
|
192
|
+
When the diff touches any language the OCR bridge routes, run it as part of code review and record the outcome in the RD code-review artifact. There are **two paths**, and delegation is the default one when no provider is configured.
|
|
193
|
+
|
|
194
|
+
**Delegated path — no API key, no provider config.** The packet → host review → record cycle:
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
peaks code-review run-ocr-18 --delegate --rid <rid> --from <base> --to HEAD --json
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
writes `.peaks/_runtime/<sid>/rd/ocr-delegate/<rid>-packet.json` and returns it. The packet carries OCR's deterministic selection (each file with the pattern that selected it), the excluded files, the resolved rule text per group, the git range and the cost surface — nothing is LLM-generated. **You** then review the selected files against those rules with the model you are already running on, write a findings envelope to a file, and record it:
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
peaks code-review ocr-delegate-record --packet <packet-path> --envelope <path> --json
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
- Recorded findings keep the `Ocr18Finding` shape and carry `attribution: ocr-delegate`, so a host-model finding is never read as an OCR finding.
|
|
207
|
+
- A packet with no recorded envelope is **not executed** — never clean. The packet's `findings` is `null`; a recorded clean review has `findings: []`.
|
|
208
|
+
- The record verb refuses a malformed envelope (missing `path`/`content`, non-numeric line, unknown severity) and an envelope naming a different packet. Do not hand-edit its output.
|
|
209
|
+
- This path consumes your own context, not an API budget. Use the packet's cost surface to decide one pass or several.
|
|
210
|
+
|
|
211
|
+
**API path — a provider is configured.** Reviews once over the range with OCR's own agent:
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
peaks code-review run-ocr-18 --languages auto --from <base> --to HEAD --json
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
- `--languages auto` detects from the range and reviews **once**. A range with no routed language skips the invocation and says so — do not spawn OCR to discover there is nothing to review.
|
|
218
|
+
- Record four outcomes separately in `rd/code-review-<rid>.md`: languages with findings; languages detected with **zero** findings; files whose format is not reviewed as a routed language; and `OCR unavailable` with the `detect-ocr-18` state when it could not run. A missing run must never read as a clean review.
|
|
219
|
+
- TypeScript/JavaScript are **dual-track**: ESLint (`peaks lint check`, Gate B5) stays the primary gate, the OCR pass is supplementary. Attribute every finding to the tool that produced it, so a defect flagged twice is not counted twice.
|
|
220
|
+
- Real CLI surface, post-review scoping model, auto-detection, the four outcomes, both paths and the envelope: `references/ocr-multilang-1.8.md` §10 (rewritten for OCR 1.x; the old 1.8 content was wrong about `--filter-language`).
|
|
221
|
+
|
|
190
222
|
## Reviewer fan-out detached mode (Phase C, slice 2026-08-10)
|
|
191
223
|
|
|
192
224
|
Reviewer fan-out may run in detached mode for any of the 3-way fan-out roles (`code-reviewer`, `qa-test-cases-writer`, `karpathy-reviewer`). Detached mode spawns a real OS process via `peaks sub-agent dispatch --mode detached --vendor <vendor>`, isolated from the orchestrator session. Use detached mode when the reviewer's expected runtime exceeds 60s OR processes ≥ 20 source files. Pass `--mode detached` explicitly per reviewer role; the default remains `in-process` (backward compat). The karpathy-reviewer's `<peaks-auto-compact>` marker is honored automatically when `--mode detached` is used. Note what that marker does and does not do (corrected 2026-09-13, rid `2026-09-13-defects-e`): it asks the child to persist durable state to `.peaks/_runtime/<sid>/detached/<rid>/compact/<n>.json` before its own harness compacts the session — the child cannot compact itself, and nothing is spliced back into its prompt. See `../../peaks-code/references/sub-agent-dispatch.md` §"Detached Mode" for the full contract.
|