peaks-loop 4.1.9 → 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 +72 -0
- package/dist/cli/commands/_register.js +2 -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/cli/commands/strat-tact-command-helpers.d.ts +16 -0
- package/dist/cli/commands/strat-tact-command-helpers.js +162 -0
- package/dist/cli/commands/strat-tact-commands.d.ts +3 -0
- package/dist/cli/commands/strat-tact-commands.js +176 -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/dist/services/rd/ast-gate.d.ts +19 -12
- package/dist/services/rd/ast-gate.js +10 -0
- package/dist/services/rd/canonical-hash.d.ts +1 -0
- package/dist/services/rd/canonical-hash.js +38 -0
- package/dist/services/rd/impl.js +2 -8
- package/dist/services/rd/strategy.js +2 -8
- package/dist/services/rd/types.d.ts +10 -10
- package/dist/services/rd/types.js +21 -10
- package/package.json +10 -10
- package/skills/bee/peaks-rd/SKILL.md +57 -3
- package/skills/bee/peaks-rd/references/ocr-multilang-1.8.md +314 -111
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OCR 1.x delegation — phase 2: validate the host agent's findings and record them.
|
|
3
|
+
*
|
|
4
|
+
* The envelope is authored by the agent, so it is untrusted input: a malformed
|
|
5
|
+
* entry is refused with the offending index named, never coerced. A finding is
|
|
6
|
+
* mapped onto `Ocr18Finding` through the same `severityFor` map the API path uses,
|
|
7
|
+
* and carries `ocr-delegate` attribution so it is never mistaken for an OCR
|
|
8
|
+
* finding.
|
|
9
|
+
*
|
|
10
|
+
* The packet is the other half of the binding: findings are recorded only against
|
|
11
|
+
* an existing packet in state `awaiting-envelope`, so a packet cannot be invented
|
|
12
|
+
* by submitting an envelope. Recording does not advance the packet — the findings
|
|
13
|
+
* document is the record of phase 2 — so recording again replaces the earlier
|
|
14
|
+
* findings file and reports `replaced: true`.
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
17
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
18
|
+
import { isInsidePath, pathsEqual, stableRealPath } from '../../shared/path-utils.js';
|
|
19
|
+
import { languageForPath } from './ocr-18-language-routing.js';
|
|
20
|
+
import { emptyByLanguage, severityFor, summarize } from './ocr-multilang-adapter.js';
|
|
21
|
+
/** The vocabulary the envelope may use; anything else is refused, not mapped to `info`. */
|
|
22
|
+
const ENVELOPE_SEVERITIES = new Set([
|
|
23
|
+
'error',
|
|
24
|
+
'critical',
|
|
25
|
+
'high',
|
|
26
|
+
'warn',
|
|
27
|
+
'warning',
|
|
28
|
+
'medium',
|
|
29
|
+
'info',
|
|
30
|
+
'low'
|
|
31
|
+
]);
|
|
32
|
+
const PACKET_STATES = new Set([
|
|
33
|
+
'no-routed-language',
|
|
34
|
+
'unsupported-files-only',
|
|
35
|
+
'ocr-unavailable',
|
|
36
|
+
'awaiting-envelope'
|
|
37
|
+
]);
|
|
38
|
+
function asRecord(value) {
|
|
39
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
40
|
+
? value
|
|
41
|
+
: null;
|
|
42
|
+
}
|
|
43
|
+
function textProblem(record, key, at) {
|
|
44
|
+
const value = record[key];
|
|
45
|
+
return typeof value === 'string' && value.trim().length > 0
|
|
46
|
+
? null
|
|
47
|
+
: `${at}.${key} must be a non-empty string`;
|
|
48
|
+
}
|
|
49
|
+
function lineProblem(record, at) {
|
|
50
|
+
const start = record['start_line'];
|
|
51
|
+
if (typeof start !== 'number' || !Number.isInteger(start) || start < 1) {
|
|
52
|
+
return `${at}.start_line must be a positive integer`;
|
|
53
|
+
}
|
|
54
|
+
const end = record['end_line'];
|
|
55
|
+
if (end === undefined)
|
|
56
|
+
return null;
|
|
57
|
+
return typeof end === 'number' && Number.isInteger(end) && end >= start
|
|
58
|
+
? null
|
|
59
|
+
: `${at}.end_line must be an integer at or after start_line`;
|
|
60
|
+
}
|
|
61
|
+
function severityProblem(record, at) {
|
|
62
|
+
const severity = record['severity'];
|
|
63
|
+
return typeof severity === 'string' && ENVELOPE_SEVERITIES.has(severity)
|
|
64
|
+
? null
|
|
65
|
+
: `${at}.severity must be one of ${[...ENVELOPE_SEVERITIES].join('|')} — got ${JSON.stringify(severity)}`;
|
|
66
|
+
}
|
|
67
|
+
function categoryProblem(record, at) {
|
|
68
|
+
const category = record['category'];
|
|
69
|
+
if (category === undefined || category === null)
|
|
70
|
+
return null;
|
|
71
|
+
return typeof category === 'string' && category.trim().length > 0
|
|
72
|
+
? null
|
|
73
|
+
: `${at}.category must be a non-empty string when present`;
|
|
74
|
+
}
|
|
75
|
+
function parseEntry(value, index) {
|
|
76
|
+
const at = `findings[${String(index)}]`;
|
|
77
|
+
const record = asRecord(value);
|
|
78
|
+
if (record === null)
|
|
79
|
+
return `${at} is not an object`;
|
|
80
|
+
const problem = textProblem(record, 'path', at) ??
|
|
81
|
+
textProblem(record, 'content', at) ??
|
|
82
|
+
lineProblem(record, at) ??
|
|
83
|
+
severityProblem(record, at) ??
|
|
84
|
+
categoryProblem(record, at);
|
|
85
|
+
if (problem !== null)
|
|
86
|
+
return problem;
|
|
87
|
+
const category = record['category'];
|
|
88
|
+
return {
|
|
89
|
+
filePath: record['path'].trim(),
|
|
90
|
+
line: record['start_line'],
|
|
91
|
+
ruleId: typeof category === 'string' ? category : null,
|
|
92
|
+
severity: severityFor(record['severity']),
|
|
93
|
+
message: record['content'].trim(),
|
|
94
|
+
attribution: 'ocr-delegate'
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Validate the envelope. Pure: no filesystem, so every refusal is unit-testable. */
|
|
98
|
+
export function parseEnvelope(text) {
|
|
99
|
+
let raw;
|
|
100
|
+
try {
|
|
101
|
+
raw = JSON.parse(text);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return { ok: false, message: 'envelope is not JSON' };
|
|
105
|
+
}
|
|
106
|
+
const record = asRecord(raw);
|
|
107
|
+
if (record === null)
|
|
108
|
+
return { ok: false, message: 'envelope is not a JSON object' };
|
|
109
|
+
const version = record['schema_version'];
|
|
110
|
+
if (version !== '1') {
|
|
111
|
+
return { ok: false, message: 'envelope.schema_version must be the string "1"' };
|
|
112
|
+
}
|
|
113
|
+
const packet = record['packet'];
|
|
114
|
+
if (typeof packet !== 'string' || packet.trim().length === 0) {
|
|
115
|
+
return { ok: false, message: 'envelope.packet must name the packet the findings belong to' };
|
|
116
|
+
}
|
|
117
|
+
const entries = record['findings'];
|
|
118
|
+
if (!Array.isArray(entries)) {
|
|
119
|
+
return { ok: false, message: 'envelope.findings must be an array (use [] for a clean review)' };
|
|
120
|
+
}
|
|
121
|
+
const findings = [];
|
|
122
|
+
for (const [index, entry] of entries.entries()) {
|
|
123
|
+
const finding = parseEntry(entry, index);
|
|
124
|
+
if (typeof finding === 'string')
|
|
125
|
+
return { ok: false, message: finding };
|
|
126
|
+
findings.push(finding);
|
|
127
|
+
}
|
|
128
|
+
return { ok: true, packet, findings };
|
|
129
|
+
}
|
|
130
|
+
function readPacket(packetPath) {
|
|
131
|
+
let raw;
|
|
132
|
+
try {
|
|
133
|
+
raw = JSON.parse(readFileSync(packetPath, 'utf8'));
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return `packet is not readable JSON: ${packetPath}`;
|
|
137
|
+
}
|
|
138
|
+
const record = asRecord(raw);
|
|
139
|
+
if (record === null)
|
|
140
|
+
return `packet is not a JSON object: ${packetPath}`;
|
|
141
|
+
if (record['schema_version'] !== '1' || record['mode'] !== 'delegate') {
|
|
142
|
+
return `not a delegation packet (schema_version 1, mode delegate): ${packetPath}`;
|
|
143
|
+
}
|
|
144
|
+
const state = record['state'];
|
|
145
|
+
if (typeof state !== 'string' || !PACKET_STATES.has(state)) {
|
|
146
|
+
return `packet has no recognised state: ${packetPath}`;
|
|
147
|
+
}
|
|
148
|
+
const rid = record['rid'];
|
|
149
|
+
const session = record['session'];
|
|
150
|
+
if (typeof rid !== 'string' || typeof session !== 'string') {
|
|
151
|
+
return `packet is missing rid/session: ${packetPath}`;
|
|
152
|
+
}
|
|
153
|
+
// A packet is a phase-1 document. A findings ARRAY here means the file is a
|
|
154
|
+
// findings document, not a packet; an omitted key is not a claim about findings.
|
|
155
|
+
if (Array.isArray(record['findings'])) {
|
|
156
|
+
return `packet carries findings; it is not a phase-1 packet: ${packetPath}`;
|
|
157
|
+
}
|
|
158
|
+
return { rid, session, state };
|
|
159
|
+
}
|
|
160
|
+
function absoluteFrom(projectRoot, value) {
|
|
161
|
+
return isAbsolute(value) ? resolve(value) : resolve(projectRoot, value);
|
|
162
|
+
}
|
|
163
|
+
function summaryOf(findings) {
|
|
164
|
+
const counts = { ...emptyByLanguage() };
|
|
165
|
+
for (const finding of findings) {
|
|
166
|
+
const language = languageForPath(finding.filePath);
|
|
167
|
+
if (language !== null)
|
|
168
|
+
counts[language] += 1;
|
|
169
|
+
}
|
|
170
|
+
return summarize(findings, counts);
|
|
171
|
+
}
|
|
172
|
+
/** The packet is the other half of the binding: it must exist, be this file, and await a review. */
|
|
173
|
+
function bindPacket(projectRoot, packetPath, declared) {
|
|
174
|
+
if (!existsSync(projectRoot)) {
|
|
175
|
+
return { code: 'PACKET_INVALID', message: `project root does not exist: ${projectRoot}` };
|
|
176
|
+
}
|
|
177
|
+
if (!pathsEqual(packetPath, declared)) {
|
|
178
|
+
return {
|
|
179
|
+
code: 'PACKET_MISMATCH',
|
|
180
|
+
message: `envelope names ${declared}, which is not the packet given (${packetPath})`
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (!existsSync(packetPath)) {
|
|
184
|
+
return { code: 'PACKET_INVALID', message: `packet does not exist: ${packetPath}` };
|
|
185
|
+
}
|
|
186
|
+
if (!isInsidePath(stableRealPath(packetPath), stableRealPath(projectRoot))) {
|
|
187
|
+
return { code: 'PACKET_INVALID', message: `packet is outside the project root: ${packetPath}` };
|
|
188
|
+
}
|
|
189
|
+
const packet = readPacket(packetPath);
|
|
190
|
+
if (typeof packet === 'string')
|
|
191
|
+
return { code: 'PACKET_INVALID', message: packet };
|
|
192
|
+
if (packet.state !== 'awaiting-envelope') {
|
|
193
|
+
return {
|
|
194
|
+
code: 'PACKET_INVALID',
|
|
195
|
+
message: `packet state is ${packet.state}: there was no delegated review to record`
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return { packetPath, packet };
|
|
199
|
+
}
|
|
200
|
+
export function recordDelegateFindings(options) {
|
|
201
|
+
const envelope = parseEnvelope(options.envelopeText);
|
|
202
|
+
if (!envelope.ok)
|
|
203
|
+
return { ok: false, code: 'ENVELOPE_INVALID', message: envelope.message };
|
|
204
|
+
const bound = bindPacket(options.projectRoot, absoluteFrom(options.projectRoot, options.packetPath), absoluteFrom(options.projectRoot, envelope.packet));
|
|
205
|
+
if ('code' in bound)
|
|
206
|
+
return { ok: false, ...bound };
|
|
207
|
+
const findingsPath = join(dirname(bound.packetPath), `${basename(bound.packetPath).replace(/\.json$/i, '')}.findings.json`);
|
|
208
|
+
const document = {
|
|
209
|
+
schema_version: '1',
|
|
210
|
+
mode: 'delegate',
|
|
211
|
+
state: 'recorded',
|
|
212
|
+
attribution: 'ocr-delegate',
|
|
213
|
+
rid: bound.packet.rid,
|
|
214
|
+
session: bound.packet.session,
|
|
215
|
+
packet: bound.packetPath,
|
|
216
|
+
findings: envelope.findings,
|
|
217
|
+
summary: summaryOf(envelope.findings)
|
|
218
|
+
};
|
|
219
|
+
const replaced = existsSync(findingsPath);
|
|
220
|
+
mkdirSync(dirname(findingsPath), { recursive: true });
|
|
221
|
+
writeFileSync(findingsPath, `${JSON.stringify(document, null, 2)}\n`, 'utf8');
|
|
222
|
+
return { ok: true, document, findingsPath, replaced };
|
|
223
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export declare const LANGUAGE_EXTENSIONS: {
|
|
2
|
+
readonly typescript: readonly [".ts", ".tsx"];
|
|
3
|
+
readonly javascript: readonly [".js", ".jsx", ".mjs", ".cjs"];
|
|
4
|
+
readonly python: readonly [".py", ".pyi"];
|
|
5
|
+
readonly go: readonly [".go"];
|
|
6
|
+
readonly java: readonly [".java"];
|
|
7
|
+
readonly kotlin: readonly [".kt", ".kts"];
|
|
8
|
+
readonly rust: readonly [".rs"];
|
|
9
|
+
readonly c: readonly [".c"];
|
|
10
|
+
readonly cpp: readonly [".cpp", ".cc", ".cxx", ".h", ".hpp", ".hxx"];
|
|
11
|
+
readonly csharp: readonly [".cs"];
|
|
12
|
+
readonly fsharp: readonly [".fs", ".fsi", ".fsx"];
|
|
13
|
+
readonly vbnet: readonly [".vb"];
|
|
14
|
+
readonly ruby: readonly [".rb", ".rake", ".gemspec"];
|
|
15
|
+
readonly php: readonly [".php", ".phtml"];
|
|
16
|
+
readonly swift: readonly [".swift"];
|
|
17
|
+
readonly objc: readonly [".m", ".mm"];
|
|
18
|
+
readonly scala: readonly [".scala"];
|
|
19
|
+
readonly groovy: readonly [".groovy", ".gradle"];
|
|
20
|
+
readonly shell: readonly [".sh", ".bash", ".zsh", ".fish"];
|
|
21
|
+
readonly powershell: readonly [".ps1"];
|
|
22
|
+
readonly sql: readonly [".sql"];
|
|
23
|
+
readonly r: readonly [".r"];
|
|
24
|
+
readonly lua: readonly [".lua"];
|
|
25
|
+
readonly perl: readonly [".pl", ".pm"];
|
|
26
|
+
readonly elixir: readonly [".ex", ".exs"];
|
|
27
|
+
readonly erlang: readonly [".erl", ".hrl"];
|
|
28
|
+
readonly dart: readonly [".dart"];
|
|
29
|
+
readonly julia: readonly [".jl"];
|
|
30
|
+
readonly haskell: readonly [".hs", ".lhs"];
|
|
31
|
+
readonly nim: readonly [".nim", ".nims", ".nimble"];
|
|
32
|
+
readonly ocaml: readonly [".ml", ".mli"];
|
|
33
|
+
readonly reasonml: readonly [".re", ".rei"];
|
|
34
|
+
readonly elm: readonly [".elm"];
|
|
35
|
+
readonly zig: readonly [".zig"];
|
|
36
|
+
readonly solidity: readonly [".sol"];
|
|
37
|
+
readonly vyper: readonly [".vy"];
|
|
38
|
+
readonly rego: readonly [".rego"];
|
|
39
|
+
readonly verilog: readonly [".v", ".sv", ".vh"];
|
|
40
|
+
readonly vhdl: readonly [".vhd", ".vhdl"];
|
|
41
|
+
readonly terraform: readonly [".tf", ".tfvars", ".hcl"];
|
|
42
|
+
readonly protobuf: readonly [".proto"];
|
|
43
|
+
readonly graphql: readonly [".graphql", ".gql"];
|
|
44
|
+
readonly prisma: readonly [".prisma"];
|
|
45
|
+
readonly thrift: readonly [".thrift"];
|
|
46
|
+
readonly capnp: readonly [".capnp"];
|
|
47
|
+
readonly jsonnet: readonly [".jsonnet", ".libsonnet"];
|
|
48
|
+
readonly nix: readonly [".nix"];
|
|
49
|
+
readonly bicep: readonly [".bicep"];
|
|
50
|
+
readonly cmake: readonly [".cmake"];
|
|
51
|
+
readonly arkts: readonly [".ets"];
|
|
52
|
+
readonly astro: readonly [".astro"];
|
|
53
|
+
readonly vue: readonly [".vue"];
|
|
54
|
+
readonly svelte: readonly [".svelte"];
|
|
55
|
+
readonly pug: readonly [".pug"];
|
|
56
|
+
readonly freemarker: readonly [".ftl", ".ftlh", ".ftlx"];
|
|
57
|
+
readonly handlebars: readonly [".hbs", ".mustache"];
|
|
58
|
+
readonly jinja: readonly [".jinja2", ".j2"];
|
|
59
|
+
};
|
|
60
|
+
export type Ocr18Language = keyof typeof LANGUAGE_EXTENSIONS;
|
|
61
|
+
export declare const OCR_18_LANGUAGES: readonly Ocr18Language[];
|
|
62
|
+
/**
|
|
63
|
+
* The routed language `filePath` belongs to, or `null` when it is not a routed
|
|
64
|
+
* format. Three deliberate decisions, all documented rather than assumed:
|
|
65
|
+
*
|
|
66
|
+
* - `.mts` / `.cts` are TypeScript to the PRD, but the pinned 1.13.1 allowlist
|
|
67
|
+
* omits them and `ocr review --preview` reports them `unsupported_ext`.
|
|
68
|
+
* Routing them would report "typescript: 0 findings" for files the CLI never
|
|
69
|
+
* read, so they surface as unsupported files instead.
|
|
70
|
+
* - `.h` is genuinely ambiguous between C and C++. It stays under `cpp` because
|
|
71
|
+
* that is the surface this slice inherited: at `194eccf5`, `--language cpp`
|
|
72
|
+
* matched `.h`, and moving it would silently change a single-language result
|
|
73
|
+
* (the PRD's preserved-behaviour clause). Reassigning it is a deliberate
|
|
74
|
+
* breaking change and needs its own decision, not a "fix" in passing. One file
|
|
75
|
+
* maps to one language on purpose: a double assignment would count the same
|
|
76
|
+
* comment in two `byLanguage` buckets and make the outcome shapes dishonest.
|
|
77
|
+
* - `.m` is claimed by both Objective-C and MATLAB upstream and cannot be told
|
|
78
|
+
* apart by extension; it routes to Objective-C, the far more common reading.
|
|
79
|
+
*/
|
|
80
|
+
export declare function languageForPath(filePath: string): Ocr18Language | null;
|
|
81
|
+
export declare function isSupportedLanguage(value: string): value is Ocr18Language;
|
|
82
|
+
/**
|
|
83
|
+
* Parse a `--languages` value: `auto`, or a comma-separated list of language
|
|
84
|
+
* names / extensions (`ts,js,go` or `.ts,.js,go`). Extensions are resolved
|
|
85
|
+
* through the same routing table, so a token cannot name a language the table
|
|
86
|
+
* does not route.
|
|
87
|
+
*
|
|
88
|
+
* @throws Error with `code: 'LANGUAGE_UNSUPPORTED'` on an unknown or empty token.
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseLanguageSelection(spec: string): {
|
|
91
|
+
readonly auto: true;
|
|
92
|
+
readonly languages: null;
|
|
93
|
+
} | {
|
|
94
|
+
readonly auto: false;
|
|
95
|
+
readonly languages: readonly Ocr18Language[];
|
|
96
|
+
};
|
|
@@ -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;
|