peaks-loop 4.1.10 → 4.1.12
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 +78 -0
- package/README-en.md +1 -1
- package/README.md +1 -1
- 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/code/orchestrator-can-do-probes.d.ts +10 -0
- package/dist/services/code/orchestrator-can-do-probes.js +12 -2
- 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/dist/services/scan/archetype-service.js +24 -8
- package/dist/services/scan/frontend-evidence.d.ts +19 -0
- package/dist/services/scan/frontend-evidence.js +142 -0
- package/dist/services/scan/scan-types.d.ts +8 -1
- 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,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OCR 1.x language routing table — the single source of truth for which
|
|
3
|
+
* language a file belongs to.
|
|
4
|
+
*
|
|
5
|
+
* The pinned CLI has NO language flag (`--filter-language` is not a flag of the
|
|
6
|
+
* real binary), so routing happens AFTER `ocr review` returns: ONE review runs
|
|
7
|
+
* over the whole range and each returned comment is attributed to a language by
|
|
8
|
+
* the extension of its path. `OCR_18_LANGUAGES`, the extension lookup and
|
|
9
|
+
* `--languages` token resolution are all derived from `LANGUAGE_EXTENSIONS`, so a
|
|
10
|
+
* language cannot be routed without an extension entry.
|
|
11
|
+
*
|
|
12
|
+
* `ocr-18-allowlist.ts` holds the vendored copy of the pinned runtime's own
|
|
13
|
+
* allowlist; the routing test reddens if the two drift apart.
|
|
14
|
+
*/
|
|
15
|
+
import { normalizePath } from '../../shared/path-utils.js';
|
|
16
|
+
export const LANGUAGE_EXTENSIONS = {
|
|
17
|
+
typescript: ['.ts', '.tsx'],
|
|
18
|
+
javascript: ['.js', '.jsx', '.mjs', '.cjs'],
|
|
19
|
+
python: ['.py', '.pyi'],
|
|
20
|
+
go: ['.go'],
|
|
21
|
+
java: ['.java'],
|
|
22
|
+
kotlin: ['.kt', '.kts'],
|
|
23
|
+
rust: ['.rs'],
|
|
24
|
+
c: ['.c'],
|
|
25
|
+
cpp: ['.cpp', '.cc', '.cxx', '.h', '.hpp', '.hxx'],
|
|
26
|
+
csharp: ['.cs'],
|
|
27
|
+
fsharp: ['.fs', '.fsi', '.fsx'],
|
|
28
|
+
vbnet: ['.vb'],
|
|
29
|
+
ruby: ['.rb', '.rake', '.gemspec'],
|
|
30
|
+
php: ['.php', '.phtml'],
|
|
31
|
+
swift: ['.swift'],
|
|
32
|
+
objc: ['.m', '.mm'],
|
|
33
|
+
scala: ['.scala'],
|
|
34
|
+
groovy: ['.groovy', '.gradle'],
|
|
35
|
+
shell: ['.sh', '.bash', '.zsh', '.fish'],
|
|
36
|
+
powershell: ['.ps1'],
|
|
37
|
+
sql: ['.sql'],
|
|
38
|
+
r: ['.r'],
|
|
39
|
+
lua: ['.lua'],
|
|
40
|
+
perl: ['.pl', '.pm'],
|
|
41
|
+
elixir: ['.ex', '.exs'],
|
|
42
|
+
erlang: ['.erl', '.hrl'],
|
|
43
|
+
dart: ['.dart'],
|
|
44
|
+
julia: ['.jl'],
|
|
45
|
+
haskell: ['.hs', '.lhs'],
|
|
46
|
+
nim: ['.nim', '.nims', '.nimble'],
|
|
47
|
+
ocaml: ['.ml', '.mli'],
|
|
48
|
+
reasonml: ['.re', '.rei'],
|
|
49
|
+
elm: ['.elm'],
|
|
50
|
+
zig: ['.zig'],
|
|
51
|
+
solidity: ['.sol'],
|
|
52
|
+
vyper: ['.vy'],
|
|
53
|
+
rego: ['.rego'],
|
|
54
|
+
verilog: ['.v', '.sv', '.vh'],
|
|
55
|
+
vhdl: ['.vhd', '.vhdl'],
|
|
56
|
+
terraform: ['.tf', '.tfvars', '.hcl'],
|
|
57
|
+
protobuf: ['.proto'],
|
|
58
|
+
graphql: ['.graphql', '.gql'],
|
|
59
|
+
prisma: ['.prisma'],
|
|
60
|
+
thrift: ['.thrift'],
|
|
61
|
+
capnp: ['.capnp'],
|
|
62
|
+
jsonnet: ['.jsonnet', '.libsonnet'],
|
|
63
|
+
nix: ['.nix'],
|
|
64
|
+
bicep: ['.bicep'],
|
|
65
|
+
cmake: ['.cmake'],
|
|
66
|
+
arkts: ['.ets'],
|
|
67
|
+
astro: ['.astro'],
|
|
68
|
+
vue: ['.vue'],
|
|
69
|
+
svelte: ['.svelte'],
|
|
70
|
+
pug: ['.pug'],
|
|
71
|
+
freemarker: ['.ftl', '.ftlh', '.ftlx'],
|
|
72
|
+
handlebars: ['.hbs', '.mustache'],
|
|
73
|
+
jinja: ['.jinja2', '.j2']
|
|
74
|
+
};
|
|
75
|
+
export const OCR_18_LANGUAGES = Object.keys(LANGUAGE_EXTENSIONS);
|
|
76
|
+
/** Extension (lower-case, leading dot) to the language it routes to. */
|
|
77
|
+
const LANGUAGE_BY_EXTENSION = new Map(Object.entries(LANGUAGE_EXTENSIONS).flatMap(([language, extensions]) => extensions.map((extension) => [extension, language])));
|
|
78
|
+
/** The lower-cased extension of `filePath` (leading dot), or `''` when it has none. */
|
|
79
|
+
function extensionOf(filePath) {
|
|
80
|
+
const normalized = normalizePath(filePath);
|
|
81
|
+
const base = normalized.slice(normalized.lastIndexOf('/') + 1).toLowerCase();
|
|
82
|
+
const dot = base.lastIndexOf('.');
|
|
83
|
+
return dot === -1 ? '' : base.slice(dot);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The routed language `filePath` belongs to, or `null` when it is not a routed
|
|
87
|
+
* format. Three deliberate decisions, all documented rather than assumed:
|
|
88
|
+
*
|
|
89
|
+
* - `.mts` / `.cts` are TypeScript to the PRD, but the pinned 1.13.1 allowlist
|
|
90
|
+
* omits them and `ocr review --preview` reports them `unsupported_ext`.
|
|
91
|
+
* Routing them would report "typescript: 0 findings" for files the CLI never
|
|
92
|
+
* read, so they surface as unsupported files instead.
|
|
93
|
+
* - `.h` is genuinely ambiguous between C and C++. It stays under `cpp` because
|
|
94
|
+
* that is the surface this slice inherited: at `194eccf5`, `--language cpp`
|
|
95
|
+
* matched `.h`, and moving it would silently change a single-language result
|
|
96
|
+
* (the PRD's preserved-behaviour clause). Reassigning it is a deliberate
|
|
97
|
+
* breaking change and needs its own decision, not a "fix" in passing. One file
|
|
98
|
+
* maps to one language on purpose: a double assignment would count the same
|
|
99
|
+
* comment in two `byLanguage` buckets and make the outcome shapes dishonest.
|
|
100
|
+
* - `.m` is claimed by both Objective-C and MATLAB upstream and cannot be told
|
|
101
|
+
* apart by extension; it routes to Objective-C, the far more common reading.
|
|
102
|
+
*/
|
|
103
|
+
export function languageForPath(filePath) {
|
|
104
|
+
return LANGUAGE_BY_EXTENSION.get(extensionOf(filePath)) ?? null;
|
|
105
|
+
}
|
|
106
|
+
export function isSupportedLanguage(value) {
|
|
107
|
+
return OCR_18_LANGUAGES.includes(value);
|
|
108
|
+
}
|
|
109
|
+
/** A language name, or an extension token (`.ts` / `ts`), resolved through the table. */
|
|
110
|
+
function resolveLanguageToken(token) {
|
|
111
|
+
const lower = token.toLowerCase();
|
|
112
|
+
if (isSupportedLanguage(lower))
|
|
113
|
+
return lower;
|
|
114
|
+
return LANGUAGE_BY_EXTENSION.get(lower.startsWith('.') ? lower : `.${lower}`) ?? null;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Parse a `--languages` value: `auto`, or a comma-separated list of language
|
|
118
|
+
* names / extensions (`ts,js,go` or `.ts,.js,go`). Extensions are resolved
|
|
119
|
+
* through the same routing table, so a token cannot name a language the table
|
|
120
|
+
* does not route.
|
|
121
|
+
*
|
|
122
|
+
* @throws Error with `code: 'LANGUAGE_UNSUPPORTED'` on an unknown or empty token.
|
|
123
|
+
*/
|
|
124
|
+
export function parseLanguageSelection(spec) {
|
|
125
|
+
const tokens = spec
|
|
126
|
+
.split(',')
|
|
127
|
+
.map((token) => token.trim())
|
|
128
|
+
.filter((token) => token.length > 0);
|
|
129
|
+
const only = tokens[0];
|
|
130
|
+
if (tokens.length === 1 && only !== undefined && only.toLowerCase() === 'auto') {
|
|
131
|
+
return { auto: true, languages: null };
|
|
132
|
+
}
|
|
133
|
+
const languages = [];
|
|
134
|
+
for (const token of tokens) {
|
|
135
|
+
const language = resolveLanguageToken(token);
|
|
136
|
+
if (language === null) {
|
|
137
|
+
throw Object.assign(new Error(`unsupported language: ${token}`), {
|
|
138
|
+
code: 'LANGUAGE_UNSUPPORTED'
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (!languages.includes(language))
|
|
142
|
+
languages.push(language);
|
|
143
|
+
}
|
|
144
|
+
if (languages.length === 0) {
|
|
145
|
+
throw Object.assign(new Error('no language given'), { code: 'LANGUAGE_UNSUPPORTED' });
|
|
146
|
+
}
|
|
147
|
+
return { auto: false, languages };
|
|
148
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type Ocr18Finding, type Ocr18Range, type Ocr18State, type Ocr18Summary } from './ocr-multilang-adapter.js';
|
|
2
|
+
import { type Ocr18Language } from './ocr-18-language-routing.js';
|
|
3
|
+
export type Ocr18Detection = {
|
|
4
|
+
readonly languages: readonly Ocr18Language[];
|
|
5
|
+
readonly changedFileCount: number;
|
|
6
|
+
/** Changed files whose format the CLI does not review as a routed language. */
|
|
7
|
+
readonly unsupportedFiles: readonly string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Which routed languages (and which unrouted files) the requested range touches.
|
|
11
|
+
*
|
|
12
|
+
* @throws when git cannot answer — "could not detect" must not read as "nothing
|
|
13
|
+
* to review", so the caller is given the choice of what to say.
|
|
14
|
+
*/
|
|
15
|
+
export declare function detectLanguages(cwd: string, range?: Ocr18Range): Ocr18Detection;
|
|
16
|
+
export type Ocr18LanguageReport = {
|
|
17
|
+
readonly language: Ocr18Language;
|
|
18
|
+
readonly findings: readonly Ocr18Finding[];
|
|
19
|
+
readonly count: number;
|
|
20
|
+
};
|
|
21
|
+
export type Ocr18MultiResult = {
|
|
22
|
+
readonly state: Ocr18State;
|
|
23
|
+
readonly detected: readonly Ocr18Language[];
|
|
24
|
+
readonly languages: readonly Ocr18LanguageReport[];
|
|
25
|
+
readonly changedFileCount: number;
|
|
26
|
+
readonly unsupportedFiles: readonly string[];
|
|
27
|
+
/**
|
|
28
|
+
* Findings on formats the caller did not route (a `.yaml` finding, say).
|
|
29
|
+
* Reported rather than dropped: the review DID look at them.
|
|
30
|
+
*/
|
|
31
|
+
readonly unroutedFindings: readonly Ocr18Finding[];
|
|
32
|
+
readonly summary: Ocr18Summary | null;
|
|
33
|
+
readonly durationMs: number;
|
|
34
|
+
readonly rawOutput: string;
|
|
35
|
+
};
|
|
36
|
+
export type Ocr18MultiOptions = Ocr18Range & {
|
|
37
|
+
readonly cwd: string;
|
|
38
|
+
/** Requested report set; omitted means every language detected in the range. */
|
|
39
|
+
readonly languages?: readonly Ocr18Language[];
|
|
40
|
+
readonly timeoutMs?: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* One review for the whole change set, findings grouped by language.
|
|
44
|
+
*
|
|
45
|
+
* The four outcomes a caller must be able to tell apart:
|
|
46
|
+
* 1. a language reported with findings (`count` > 0);
|
|
47
|
+
* 2. a language reported with count 0 while the state is `ok` — it ran and was clean;
|
|
48
|
+
* 3. `unsupportedFiles` — the file is in the diff but the CLI does not review it
|
|
49
|
+
* as a routed language (with state `no-routed-language` when that is ALL
|
|
50
|
+
* the range holds);
|
|
51
|
+
* 4. a state of `ocr18-missing` / `execution-failed` with `languages: []` — it
|
|
52
|
+
* never ran, so there is no zero to mistake for a clean result.
|
|
53
|
+
*/
|
|
54
|
+
export declare function runOcr18Multi(options: Ocr18MultiOptions): Ocr18MultiResult;
|
|
@@ -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;
|