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,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for the STRAT → TACT producer commands (backlog §16 / §9.2).
|
|
3
|
+
*
|
|
4
|
+
* Split out of `strat-tact-commands.ts` for the repo's 300-line source cap.
|
|
5
|
+
* Pure orchestration helpers: refusal plumbing, the one-axis path guard, and
|
|
6
|
+
* the artifact readers that re-verify a signed JSON document before trusting
|
|
7
|
+
* it. The service layer stays the single implementation of both stages.
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from 'node:fs/promises';
|
|
10
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
11
|
+
import { fail } from 'peaks-loop-shared/result';
|
|
12
|
+
import { isUnsafePathInput } from '../../shared/path-safety.js';
|
|
13
|
+
import { AstGateContextSchema } from '../../services/rd/ast-gate.js';
|
|
14
|
+
import { canonicalSha256 } from '../../services/rd/canonical-hash.js';
|
|
15
|
+
import { ImplOutputSchema, StrategyOutputSchema } from '../../services/rd/types.js';
|
|
16
|
+
const SESSION_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
17
|
+
const JSON_SUFFIX = '.json';
|
|
18
|
+
/** Short sig prefix shown in a mismatch message; the full digest stays in the artifact. */
|
|
19
|
+
const SIG_PREVIEW_LEN = 12;
|
|
20
|
+
export class CommandRefusal extends Error {
|
|
21
|
+
code;
|
|
22
|
+
remedy;
|
|
23
|
+
constructor(code, remedy, message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.remedy = remedy;
|
|
27
|
+
this.name = 'CommandRefusal';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function emitOk(io, json, payload, human) {
|
|
31
|
+
if (json) {
|
|
32
|
+
io.stdout(JSON.stringify({ ok: true, ...payload }));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
io.stdout(human.join('\n'));
|
|
36
|
+
}
|
|
37
|
+
function refuse(io, json, command, r) {
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
if (json) {
|
|
40
|
+
io.stdout(JSON.stringify(fail(command, r.code, r.message, { remedy: r.remedy }, [r.remedy])));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
io.stderr(`${r.code}: ${r.message} — ${r.remedy}\n`);
|
|
44
|
+
}
|
|
45
|
+
/** Run an action body, turning a named refusal into the CLI's error surface. */
|
|
46
|
+
export async function guarded(io, json, command, body) {
|
|
47
|
+
try {
|
|
48
|
+
await body();
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (err instanceof CommandRefusal) {
|
|
52
|
+
refuse(io, json, command, err);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Resolve `--out` and enforce the one-axis layout. */
|
|
59
|
+
export function requireSessionAxis(project, sessionId, out) {
|
|
60
|
+
// The canonical traversal guard PLUS the stricter single-segment regex: the
|
|
61
|
+
// former is what the runtime-id scanner recognises, the latter also rejects
|
|
62
|
+
// backslashes and a leading dot that the traversal guard alone would admit.
|
|
63
|
+
if (isUnsafePathInput(sessionId) || !SESSION_ID_RE.test(sessionId)) {
|
|
64
|
+
throw new CommandRefusal('INVALID_SESSION_ID', 'Use the session id that names .peaks/_runtime/<sid>/ (letters, digits, dot, dash, underscore).', `invalid --session-id: ${sessionId}`);
|
|
65
|
+
}
|
|
66
|
+
const sessionRoot = resolve(project, '.peaks', '_runtime', sessionId);
|
|
67
|
+
const absolute = isAbsolute(out) ? resolve(out) : resolve(project, out);
|
|
68
|
+
const rel = relative(sessionRoot, absolute);
|
|
69
|
+
if (rel === '' || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
70
|
+
throw new CommandRefusal('ONE_AXIS_VIOLATION', `Pass --out .peaks/_runtime/${sessionId}/rd/<file>; artifacts are written only on the session axis.`, `--out must live under .peaks/_runtime/${sessionId}/ (got ${absolute})`);
|
|
71
|
+
}
|
|
72
|
+
return absolute;
|
|
73
|
+
}
|
|
74
|
+
async function readJsonFile(path, notFoundCode, invalidJsonCode, remedy) {
|
|
75
|
+
let raw;
|
|
76
|
+
try {
|
|
77
|
+
raw = await readFile(path, 'utf8');
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
throw new CommandRefusal(notFoundCode, remedy, `${path} could not be read: ${err instanceof Error ? err.message : String(err)}`);
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
return JSON.parse(raw);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
throw new CommandRefusal(invalidJsonCode, remedy, `${path} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Recompute the digest over the RAW parsed JSON, before any schema strip.
|
|
91
|
+
* Order matters: an unknown field added to a signed artifact must change the
|
|
92
|
+
* digest (and therefore refuse), not be silently dropped by the schema.
|
|
93
|
+
*/
|
|
94
|
+
function assertArtifactDigest(raw, path, codes, remedy) {
|
|
95
|
+
if (raw === null || typeof raw !== 'object') {
|
|
96
|
+
throw new CommandRefusal(codes.invalid, remedy, `${path} is not a JSON object`);
|
|
97
|
+
}
|
|
98
|
+
const declared = raw.sha256;
|
|
99
|
+
const recomputed = canonicalSha256(raw);
|
|
100
|
+
if (declared !== recomputed) {
|
|
101
|
+
throw new CommandRefusal(codes.mismatch, remedy, `sha256 mismatch at ${path} (declared=${String(declared).slice(0, SIG_PREVIEW_LEN)}… ` +
|
|
102
|
+
`recomputed=${recomputed.slice(0, SIG_PREVIEW_LEN)}…)`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** The markdown sibling is the human-readable anchor; both must carry the same sig. */
|
|
106
|
+
async function requireStrategyMarkdown(jsonPath, sha256) {
|
|
107
|
+
const markdownPath = jsonPath.endsWith(JSON_SUFFIX)
|
|
108
|
+
? jsonPath.slice(0, -JSON_SUFFIX.length)
|
|
109
|
+
: jsonPath;
|
|
110
|
+
let markdown;
|
|
111
|
+
try {
|
|
112
|
+
markdown = await readFile(markdownPath, 'utf8');
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
throw new CommandRefusal('STRATEGY_MARKDOWN_NOT_FOUND', 'Re-run peaks strat write; it writes strategy.md next to the <out>.json sibling.', `strategy markdown not found at ${markdownPath} (${err instanceof Error ? err.message : String(err)})`);
|
|
116
|
+
}
|
|
117
|
+
const declared = /STRAT\.sig:\s*([a-f0-9]{64})/.exec(markdown)?.[1];
|
|
118
|
+
if (declared !== sha256) {
|
|
119
|
+
throw new CommandRefusal('STRATEGY_SIG_MISMATCH', `Re-run peaks strat write to regenerate both the markdown and its JSON sibling (${jsonPath}).`, `strategy markdown signature at ${markdownPath} is ${declared ?? '<missing>'} but the JSON ` +
|
|
120
|
+
`declares ${sha256.slice(0, SIG_PREVIEW_LEN)}…`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export async function readStrategy(path) {
|
|
124
|
+
const remedy = 'Re-run peaks strat write; --strategy expects the JSON sibling it wrote.';
|
|
125
|
+
const raw = await readJsonFile(path, 'STRATEGY_NOT_FOUND', 'INVALID_STRATEGY_JSON', remedy);
|
|
126
|
+
assertArtifactDigest(raw, path, { invalid: 'INVALID_STRATEGY', mismatch: 'STRAT_SIG_MISMATCH' }, remedy);
|
|
127
|
+
const parsed = StrategyOutputSchema.safeParse(raw);
|
|
128
|
+
if (!parsed.success) {
|
|
129
|
+
throw new CommandRefusal('INVALID_STRATEGY', remedy, `${path} does not match StrategyOutput: ${parsed.error.message}`);
|
|
130
|
+
}
|
|
131
|
+
await requireStrategyMarkdown(path, parsed.data.sha256);
|
|
132
|
+
return parsed.data;
|
|
133
|
+
}
|
|
134
|
+
export async function readImpl(path) {
|
|
135
|
+
const remedy = 'Re-run peaks tact write; --artifact expects the impl.json it wrote.';
|
|
136
|
+
const raw = await readJsonFile(path, 'IMPL_NOT_FOUND', 'INVALID_IMPL_JSON', remedy);
|
|
137
|
+
assertArtifactDigest(raw, path, { invalid: 'INVALID_IMPL', mismatch: 'IMPL_SIG_MISMATCH' }, remedy);
|
|
138
|
+
const parsed = ImplOutputSchema.safeParse(raw);
|
|
139
|
+
if (!parsed.success) {
|
|
140
|
+
throw new CommandRefusal('INVALID_IMPL', remedy, `${path} does not match ImplOutput: ${parsed.error.message}`);
|
|
141
|
+
}
|
|
142
|
+
return parsed.data;
|
|
143
|
+
}
|
|
144
|
+
export function parseAstContext(raw) {
|
|
145
|
+
if (raw === undefined) {
|
|
146
|
+
return { deps: {}, docSummaries: [] };
|
|
147
|
+
}
|
|
148
|
+
const remedy = 'Pass --ast-context as JSON matching { deps, docSummaries }, or omit it for the empty context.';
|
|
149
|
+
const parsed = AstGateContextSchema.safeParse(readJsonOrRefuse(raw, 'INVALID_AST_CONTEXT', remedy, '--ast-context'));
|
|
150
|
+
if (!parsed.success) {
|
|
151
|
+
throw new CommandRefusal('INVALID_AST_CONTEXT', remedy, `--ast-context does not match AstGateContext: ${parsed.error.message}`);
|
|
152
|
+
}
|
|
153
|
+
return parsed.data;
|
|
154
|
+
}
|
|
155
|
+
function readJsonOrRefuse(raw, code, remedy, path) {
|
|
156
|
+
try {
|
|
157
|
+
return JSON.parse(raw);
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
throw new CommandRefusal(code, remedy, `${path} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `peaks strat <sub>` / `peaks tact <sub>` — the STRAT → TACT producer chain.
|
|
3
|
+
*
|
|
4
|
+
* WHY this module exists (backlog §16 / §9.2): the documented chain
|
|
5
|
+
* `strategy.md (STRAT.sig) → impl.json (TACT.sig) → mut-report.json` had no
|
|
6
|
+
* CLI producer, so `mut/mut-report.json` could never receive a real
|
|
7
|
+
* `inputSig`. These commands are thin wrappers over the unchanged rd
|
|
8
|
+
* sub-stages; the service layer stays the single implementation.
|
|
9
|
+
*
|
|
10
|
+
* Hard rules carried over from the services:
|
|
11
|
+
* - H8: a TACT can only anchor to a STRAT whose recomputed sha256 matches
|
|
12
|
+
* the artifact content. `tact write` therefore never accepts a raw
|
|
13
|
+
* `--input-sig`; it re-verifies the strategy JSON first.
|
|
14
|
+
* - H6: AST-gate violations refuse before TACT.sig is written.
|
|
15
|
+
* - One-axis layout: every `--out` lives under
|
|
16
|
+
* `.peaks/_runtime/<sessionId>/`; `--session-id` is required on writes.
|
|
17
|
+
*/
|
|
18
|
+
import { mkdir, stat, writeFile } from 'node:fs/promises';
|
|
19
|
+
import { dirname, isAbsolute, relative, resolve, sep } from 'node:path';
|
|
20
|
+
import { runAstGate } from '../../services/rd/ast-gate.js';
|
|
21
|
+
import { runStrategicStage } from '../../services/rd/strategic-stage.js';
|
|
22
|
+
import { registerStratSig, runTacticalStage } from '../../services/rd/tactical-stage.js';
|
|
23
|
+
import { CommandRefusal, emitOk, guarded, parseAstContext, readImpl, readStrategy, requireSessionAxis } from './strat-tact-command-helpers.js';
|
|
24
|
+
const CHANGED_FILES_REMEDY = 'Pass --changed-files as existing project-relative paths; the AST gate reads only files inside --project.';
|
|
25
|
+
async function isRegularFile(path) {
|
|
26
|
+
try {
|
|
27
|
+
return (await stat(path)).isFile();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Containment check: the AST gate must never read outside --project. */
|
|
34
|
+
async function resolveChangedFiles(project, files) {
|
|
35
|
+
for (const file of files) {
|
|
36
|
+
if (isAbsolute(file)) {
|
|
37
|
+
throw new CommandRefusal('INVALID_CHANGED_FILE', CHANGED_FILES_REMEDY, `--changed-files entry is absolute: ${file}`);
|
|
38
|
+
}
|
|
39
|
+
const absolute = resolve(project, file);
|
|
40
|
+
const rel = relative(project, absolute);
|
|
41
|
+
if (rel === '' || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
42
|
+
throw new CommandRefusal('INVALID_CHANGED_FILE', CHANGED_FILES_REMEDY, `--changed-files entry escapes --project: ${file}`);
|
|
43
|
+
}
|
|
44
|
+
if (!(await isRegularFile(absolute))) {
|
|
45
|
+
throw new CommandRefusal('INVALID_CHANGED_FILE', CHANGED_FILES_REMEDY, `--changed-files entry does not exist as a file under --project: ${file}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [...files];
|
|
49
|
+
}
|
|
50
|
+
/** A TOCTOU failure inside the service still surfaces as a named refusal. */
|
|
51
|
+
async function runTacticalSafely(input) {
|
|
52
|
+
try {
|
|
53
|
+
return await runTacticalStage(input);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
if (err instanceof CommandRefusal) {
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
throw new CommandRefusal('TACT_WRITE_FAILED', 'Re-run peaks tact write; if the AST gate now reports a violation, fix it first.', `tact write failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function runStratWrite(io, a) {
|
|
63
|
+
const project = resolve(a.project);
|
|
64
|
+
const out = requireSessionAxis(project, a.sessionId, a.out);
|
|
65
|
+
await mkdir(dirname(out), { recursive: true });
|
|
66
|
+
const result = await runStrategicStage({
|
|
67
|
+
out,
|
|
68
|
+
goal: a.goal,
|
|
69
|
+
rootCauseAnalysis: a.rootCause,
|
|
70
|
+
impactSurface: a.impact,
|
|
71
|
+
designRationale: a.design
|
|
72
|
+
});
|
|
73
|
+
const jsonPath = `${out}.json`;
|
|
74
|
+
await writeFile(jsonPath, JSON.stringify(result, null, 2), 'utf8');
|
|
75
|
+
emitOk(io, a.json, { path: out, jsonPath, sha256: result.sha256 }, [
|
|
76
|
+
`strategy.md: ${out}`,
|
|
77
|
+
`json: ${jsonPath}`,
|
|
78
|
+
`STRAT.sig: ${result.sha256}`
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
async function runTactWrite(io, a) {
|
|
82
|
+
const project = resolve(a.project);
|
|
83
|
+
const out = requireSessionAxis(project, a.sessionId, a.out);
|
|
84
|
+
const changedFiles = await resolveChangedFiles(project, a.changedFiles);
|
|
85
|
+
const strategyPath = isAbsolute(a.strategy) ? resolve(a.strategy) : resolve(project, a.strategy);
|
|
86
|
+
const strategy = await readStrategy(strategyPath);
|
|
87
|
+
const context = parseAstContext(a.astContext);
|
|
88
|
+
// Name the violations before the service throws its count-only error.
|
|
89
|
+
const gate = await runAstGate({ project, changedFiles, context });
|
|
90
|
+
if (!gate.passed) {
|
|
91
|
+
throw new CommandRefusal('AST_GATE_FAILED', 'Fix the undocumented API call (or update the locked-version doc summary) and re-run peaks tact write.', `AST gate failed — ${gate.violations
|
|
92
|
+
.map((v) => `${v.api} at ${v.file}:${v.line}`)
|
|
93
|
+
.join('; ')}`);
|
|
94
|
+
}
|
|
95
|
+
await mkdir(dirname(out), { recursive: true });
|
|
96
|
+
// H8: rehydrate the in-process registry from the verified artifact —
|
|
97
|
+
// this CLI process never ran `runStrategicStage`.
|
|
98
|
+
registerStratSig(dirname(out), strategy.sha256);
|
|
99
|
+
const impl = await runTacticalSafely({
|
|
100
|
+
project,
|
|
101
|
+
changedFiles,
|
|
102
|
+
inputSig: strategy.sha256,
|
|
103
|
+
context,
|
|
104
|
+
out
|
|
105
|
+
});
|
|
106
|
+
emitOk(io, a.json, {
|
|
107
|
+
path: out,
|
|
108
|
+
sha256: impl.sha256,
|
|
109
|
+
inputSig: impl.inputSig,
|
|
110
|
+
changedFiles: impl.changedFiles,
|
|
111
|
+
astGateResult: impl.astGateResult
|
|
112
|
+
}, [`impl.json: ${out}`, `TACT.sig: ${impl.sha256}`, `inputSig: ${impl.inputSig}`]);
|
|
113
|
+
}
|
|
114
|
+
async function runTactRead(io, a) {
|
|
115
|
+
const project = resolve(a.project);
|
|
116
|
+
const artifact = isAbsolute(a.artifact) ? resolve(a.artifact) : resolve(project, a.artifact);
|
|
117
|
+
const impl = await readImpl(artifact);
|
|
118
|
+
emitOk(io, a.json, {
|
|
119
|
+
sha256: impl.sha256,
|
|
120
|
+
inputSig: impl.inputSig,
|
|
121
|
+
changedFiles: impl.changedFiles,
|
|
122
|
+
astGateResult: impl.astGateResult
|
|
123
|
+
}, [
|
|
124
|
+
`sha256: ${impl.sha256}`,
|
|
125
|
+
`inputSig: ${impl.inputSig}`,
|
|
126
|
+
`changedFiles: ${impl.changedFiles.join(', ')}`,
|
|
127
|
+
`astGateResult: passed=${impl.astGateResult.passed} violations=${impl.astGateResult.violations.length}`
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
export function registerStratTactCommands(program, io) {
|
|
131
|
+
const strat = program
|
|
132
|
+
.command('strat')
|
|
133
|
+
.description('STRAT producer: strategy.md + STRAT.sig (spec §4.2 战略审计)');
|
|
134
|
+
registerStratWrite(strat, io);
|
|
135
|
+
const tact = program
|
|
136
|
+
.command('tact')
|
|
137
|
+
.description('TACT producer/reader: impl.json + TACT.sig chained to STRAT.sig');
|
|
138
|
+
registerTactWrite(tact, io);
|
|
139
|
+
registerTactRead(tact, io);
|
|
140
|
+
}
|
|
141
|
+
function registerStratWrite(strat, io) {
|
|
142
|
+
strat
|
|
143
|
+
.command('write')
|
|
144
|
+
.description('Write strategy.md plus its <out>.json sibling. One-axis: --session-id required.')
|
|
145
|
+
.requiredOption('--project <path>', 'project root')
|
|
146
|
+
.requiredOption('--session-id <sid>', 'session id; --out must live under .peaks/_runtime/<sid>/')
|
|
147
|
+
.requiredOption('--out <path>', 'strategy markdown path (inside .peaks/_runtime/<sid>/)')
|
|
148
|
+
.requiredOption('--goal <text>', 'goal of this slice')
|
|
149
|
+
.requiredOption('--root-cause <text>', 'root-cause analysis')
|
|
150
|
+
.requiredOption('--impact <items...>', 'impact surface entries')
|
|
151
|
+
.requiredOption('--design <text>', 'design rationale')
|
|
152
|
+
.option('--json', 'machine-readable output', false)
|
|
153
|
+
.action((a) => guarded(io, a.json, 'strat write', () => runStratWrite(io, a)));
|
|
154
|
+
}
|
|
155
|
+
function registerTactWrite(tact, io) {
|
|
156
|
+
tact
|
|
157
|
+
.command('write')
|
|
158
|
+
.description('Verify the strategy JSON, run the AST gate, then write impl.json + TACT.sig. One-axis: --session-id required.')
|
|
159
|
+
.requiredOption('--project <path>', 'project root')
|
|
160
|
+
.requiredOption('--session-id <sid>', 'session id; --out must live under .peaks/_runtime/<sid>/')
|
|
161
|
+
.requiredOption('--strategy <path>', 'strategy JSON sibling written by `peaks strat write`')
|
|
162
|
+
.requiredOption('--out <path>', 'impl.json path (inside .peaks/_runtime/<sid>/)')
|
|
163
|
+
.requiredOption('--changed-files <paths...>', 'files the tactical stage changed')
|
|
164
|
+
.option('--ast-context <json>', 'AstGateContext JSON ({ deps, docSummaries })')
|
|
165
|
+
.option('--json', 'machine-readable output', false)
|
|
166
|
+
.action((a) => guarded(io, a.json, 'tact write', () => runTactWrite(io, a)));
|
|
167
|
+
}
|
|
168
|
+
function registerTactRead(tact, io) {
|
|
169
|
+
tact
|
|
170
|
+
.command('read')
|
|
171
|
+
.description('Re-read impl.json, recompute TACT.sig, and print the chain anchor.')
|
|
172
|
+
.requiredOption('--artifact <path>', 'impl.json written by `peaks tact write`')
|
|
173
|
+
.option('--project <path>', 'project root (default: cwd)', '.')
|
|
174
|
+
.option('--json', 'machine-readable output', false)
|
|
175
|
+
.action((a) => guarded(io, a.json, 'tact read', () => runTactRead(io, a)));
|
|
176
|
+
}
|
|
@@ -7,7 +7,7 @@ import { type ShellProbeRunner } from '../env/shell-probe.js';
|
|
|
7
7
|
* guessed number in a warning is worse than no number. What the user needs to
|
|
8
8
|
* know before the block is that this touches the network and is one-time.
|
|
9
9
|
*/
|
|
10
|
-
export declare const ACQUIRE_NETWORK_WARNING = "fetching @alibaba-group/open-code-review@1.
|
|
10
|
+
export declare const ACQUIRE_NETWORK_WARNING = "fetching @alibaba-group/open-code-review@1.13.1 from the npm registry (needs network, one time)";
|
|
11
11
|
/** Which shell the acquisition runs through, in preference order. */
|
|
12
12
|
export type AcquireShellKind = 'bash' | 'powershell' | 'direct';
|
|
13
13
|
export interface AcquireShell {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OCR 1.
|
|
2
|
+
* OCR 1.x acquisition — the ONE step that is allowed to install the reviewer.
|
|
3
3
|
*
|
|
4
4
|
* ## Why this exists as its own module
|
|
5
5
|
*
|
|
@@ -294,7 +294,7 @@ export async function acquireOcr18(options = {}) {
|
|
|
294
294
|
try {
|
|
295
295
|
locked = acquireOcrLock();
|
|
296
296
|
if (!locked) {
|
|
297
|
-
return failure('OCR18_ACQUIRE_BUSY', 'another OCR 1.
|
|
297
|
+
return failure('OCR18_ACQUIRE_BUSY', 'another OCR 1.x acquisition is already running on this machine; ' +
|
|
298
298
|
`the lock (${ocrAcquireLockPath()}) prevents a second download — retry once it finishes`, shell, startedAt);
|
|
299
299
|
}
|
|
300
300
|
// R2's discipline, mirrored: name the network wait BEFORE the block, on the
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored snapshot of the extension allowlist compiled into the PINNED OCR
|
|
3
|
+
* runtime, plus the explicit list of allowlisted formats this project does not
|
|
4
|
+
* route to a language.
|
|
5
|
+
*
|
|
6
|
+
* Source: `alibaba/open-code-review`, `internal/config/allowlist/supported_file_types.json`
|
|
7
|
+
* at tag `v1.13.1` (the version `OCR_18_PACKAGE` pins) — 115 entries. This is a
|
|
8
|
+
* SNAPSHOT, not a live binding: the binary embeds its own copy at build time, so
|
|
9
|
+
* a pin bump must update this file together with `OCR_18_PACKAGE`. The partition
|
|
10
|
+
* test in `tests/unit/services/lint/ocr-multilang-adapter.test.ts` reddens when
|
|
11
|
+
* the routing table and `OCR_18_EXCLUDED_EXTENSIONS` stop covering it exactly,
|
|
12
|
+
* which is how an upstream addition surfaces instead of being silently ignored.
|
|
13
|
+
*
|
|
14
|
+
* Empirical control (2026-10-20, ocr 1.13.1 on win32-x64): a scratch repository
|
|
15
|
+
* holding one file per extension was run through `ocr review --preview`. Every
|
|
16
|
+
* extension below was listed under "Will review"; `.mts`, `.cts` and `.glsl`
|
|
17
|
+
* were listed under "Excluded from review (unsupported_ext)". `.glsl` is in the
|
|
18
|
+
* HEAD allowlist but not in v1.13.1, which is why the tag — not HEAD — is the
|
|
19
|
+
* source here.
|
|
20
|
+
*/
|
|
21
|
+
export declare const OCR_18_ALLOWLIST_V1_13_1: readonly string[];
|
|
22
|
+
/**
|
|
23
|
+
* Allowlisted formats this project deliberately does NOT route to a language.
|
|
24
|
+
*
|
|
25
|
+
* The PRD routes source languages only: markup, stylesheets, data/config and
|
|
26
|
+
* notebook containers carry no source semantics to review per language. They
|
|
27
|
+
* are still reviewed by the CLI — they are simply not attributed to a language,
|
|
28
|
+
* so they never appear as a routed language with a misleading zero.
|
|
29
|
+
*/
|
|
30
|
+
export declare const OCR_18_EXCLUDED_EXTENSIONS: Readonly<Record<string, string>>;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored snapshot of the extension allowlist compiled into the PINNED OCR
|
|
3
|
+
* runtime, plus the explicit list of allowlisted formats this project does not
|
|
4
|
+
* route to a language.
|
|
5
|
+
*
|
|
6
|
+
* Source: `alibaba/open-code-review`, `internal/config/allowlist/supported_file_types.json`
|
|
7
|
+
* at tag `v1.13.1` (the version `OCR_18_PACKAGE` pins) — 115 entries. This is a
|
|
8
|
+
* SNAPSHOT, not a live binding: the binary embeds its own copy at build time, so
|
|
9
|
+
* a pin bump must update this file together with `OCR_18_PACKAGE`. The partition
|
|
10
|
+
* test in `tests/unit/services/lint/ocr-multilang-adapter.test.ts` reddens when
|
|
11
|
+
* the routing table and `OCR_18_EXCLUDED_EXTENSIONS` stop covering it exactly,
|
|
12
|
+
* which is how an upstream addition surfaces instead of being silently ignored.
|
|
13
|
+
*
|
|
14
|
+
* Empirical control (2026-10-20, ocr 1.13.1 on win32-x64): a scratch repository
|
|
15
|
+
* holding one file per extension was run through `ocr review --preview`. Every
|
|
16
|
+
* extension below was listed under "Will review"; `.mts`, `.cts` and `.glsl`
|
|
17
|
+
* were listed under "Excluded from review (unsupported_ext)". `.glsl` is in the
|
|
18
|
+
* HEAD allowlist but not in v1.13.1, which is why the tag — not HEAD — is the
|
|
19
|
+
* source here.
|
|
20
|
+
*/
|
|
21
|
+
export const OCR_18_ALLOWLIST_V1_13_1 = [
|
|
22
|
+
'.java',
|
|
23
|
+
'.kt',
|
|
24
|
+
'.kts',
|
|
25
|
+
'.scala',
|
|
26
|
+
'.groovy',
|
|
27
|
+
'.py',
|
|
28
|
+
'.pyi',
|
|
29
|
+
'.js',
|
|
30
|
+
'.jsx',
|
|
31
|
+
'.ts',
|
|
32
|
+
'.tsx',
|
|
33
|
+
'.mjs',
|
|
34
|
+
'.cjs',
|
|
35
|
+
'.c',
|
|
36
|
+
'.h',
|
|
37
|
+
'.cpp',
|
|
38
|
+
'.cc',
|
|
39
|
+
'.cxx',
|
|
40
|
+
'.hpp',
|
|
41
|
+
'.hxx',
|
|
42
|
+
'.cs',
|
|
43
|
+
'.vb',
|
|
44
|
+
'.fs',
|
|
45
|
+
'.fsi',
|
|
46
|
+
'.fsx',
|
|
47
|
+
'.go',
|
|
48
|
+
'.rs',
|
|
49
|
+
'.rb',
|
|
50
|
+
'.rake',
|
|
51
|
+
'.gemspec',
|
|
52
|
+
'.php',
|
|
53
|
+
'.phtml',
|
|
54
|
+
'.swift',
|
|
55
|
+
'.m',
|
|
56
|
+
'.mm',
|
|
57
|
+
'.sh',
|
|
58
|
+
'.bash',
|
|
59
|
+
'.zsh',
|
|
60
|
+
'.fish',
|
|
61
|
+
'.ps1',
|
|
62
|
+
'.sql',
|
|
63
|
+
'.css',
|
|
64
|
+
'.scss',
|
|
65
|
+
'.sass',
|
|
66
|
+
'.less',
|
|
67
|
+
'.html',
|
|
68
|
+
'.htm',
|
|
69
|
+
'.ftl',
|
|
70
|
+
'.ftlh',
|
|
71
|
+
'.ftlx',
|
|
72
|
+
'.hbs',
|
|
73
|
+
'.mustache',
|
|
74
|
+
'.jinja2',
|
|
75
|
+
'.j2',
|
|
76
|
+
'.pug',
|
|
77
|
+
'.astro',
|
|
78
|
+
'.vue',
|
|
79
|
+
'.ipynb',
|
|
80
|
+
'.svelte',
|
|
81
|
+
'.xml',
|
|
82
|
+
'.yaml',
|
|
83
|
+
'.yml',
|
|
84
|
+
'.json',
|
|
85
|
+
'.toml',
|
|
86
|
+
'.ini',
|
|
87
|
+
'.env',
|
|
88
|
+
'.gradle',
|
|
89
|
+
'.cmake',
|
|
90
|
+
'.r',
|
|
91
|
+
'.lua',
|
|
92
|
+
'.pl',
|
|
93
|
+
'.pm',
|
|
94
|
+
'.ex',
|
|
95
|
+
'.exs',
|
|
96
|
+
'.erl',
|
|
97
|
+
'.hrl',
|
|
98
|
+
'.ets',
|
|
99
|
+
'.json5',
|
|
100
|
+
'.dart',
|
|
101
|
+
'.tf',
|
|
102
|
+
'.graphql',
|
|
103
|
+
'.gql',
|
|
104
|
+
'.prisma',
|
|
105
|
+
'.jl',
|
|
106
|
+
'.hcl',
|
|
107
|
+
'.tfvars',
|
|
108
|
+
'.bicep',
|
|
109
|
+
'.proto',
|
|
110
|
+
'.nix',
|
|
111
|
+
'.hs',
|
|
112
|
+
'.lhs',
|
|
113
|
+
'.nim',
|
|
114
|
+
'.nims',
|
|
115
|
+
'.nimble',
|
|
116
|
+
'.elm',
|
|
117
|
+
'.properties',
|
|
118
|
+
'.po',
|
|
119
|
+
'.pot',
|
|
120
|
+
'.jsonnet',
|
|
121
|
+
'.libsonnet',
|
|
122
|
+
'.zig',
|
|
123
|
+
'.thrift',
|
|
124
|
+
'.capnp',
|
|
125
|
+
'.ml',
|
|
126
|
+
'.mli',
|
|
127
|
+
'.re',
|
|
128
|
+
'.rei',
|
|
129
|
+
'.v',
|
|
130
|
+
'.sv',
|
|
131
|
+
'.vh',
|
|
132
|
+
'.vhd',
|
|
133
|
+
'.vhdl',
|
|
134
|
+
'.sol',
|
|
135
|
+
'.vy',
|
|
136
|
+
'.rego'
|
|
137
|
+
];
|
|
138
|
+
/**
|
|
139
|
+
* Allowlisted formats this project deliberately does NOT route to a language.
|
|
140
|
+
*
|
|
141
|
+
* The PRD routes source languages only: markup, stylesheets, data/config and
|
|
142
|
+
* notebook containers carry no source semantics to review per language. They
|
|
143
|
+
* are still reviewed by the CLI — they are simply not attributed to a language,
|
|
144
|
+
* so they never appear as a routed language with a misleading zero.
|
|
145
|
+
*/
|
|
146
|
+
export const OCR_18_EXCLUDED_EXTENSIONS = {
|
|
147
|
+
'.css': 'stylesheet, not source',
|
|
148
|
+
'.scss': 'stylesheet, not source',
|
|
149
|
+
'.sass': 'stylesheet, not source',
|
|
150
|
+
'.less': 'stylesheet, not source',
|
|
151
|
+
'.html': 'markup, not source',
|
|
152
|
+
'.htm': 'markup, not source',
|
|
153
|
+
'.xml': 'markup/data, not source',
|
|
154
|
+
'.yaml': 'data/config, not source',
|
|
155
|
+
'.yml': 'data/config, not source',
|
|
156
|
+
'.json': 'data/config, not source',
|
|
157
|
+
'.json5': 'data/config, not source',
|
|
158
|
+
'.toml': 'data/config, not source',
|
|
159
|
+
'.ini': 'data/config, not source',
|
|
160
|
+
'.env': 'data/config, not source',
|
|
161
|
+
'.properties': 'data/config, not source',
|
|
162
|
+
'.po': 'translation catalogue, not source',
|
|
163
|
+
'.pot': 'translation catalogue, not source',
|
|
164
|
+
'.ipynb': 'notebook container, not source'
|
|
165
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type Ocr18Language } from './ocr-18-language-routing.js';
|
|
2
|
+
import { type Ocr18Detection } from './ocr-18-multi.js';
|
|
3
|
+
import { type DelegateFile, type DelegatePreview, type DelegateRuleGroup, type RulesResult } from './ocr-18-delegate-payload.js';
|
|
4
|
+
import { type Ocr18Range, type Ocr18State } from './ocr-multilang-adapter.js';
|
|
5
|
+
export type DelegateSelectedFile = {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly status: string;
|
|
8
|
+
readonly insertions: number;
|
|
9
|
+
readonly deletions: number;
|
|
10
|
+
readonly language: Ocr18Language | null;
|
|
11
|
+
/** The glob that selected this file, or `null` when no rule group claimed it. */
|
|
12
|
+
readonly pattern: string | null;
|
|
13
|
+
};
|
|
14
|
+
export type DelegatePacketState = 'no-routed-language' | 'unsupported-files-only' | 'ocr-unavailable' | 'awaiting-envelope';
|
|
15
|
+
export type DelegatePacket = {
|
|
16
|
+
readonly schema_version: '1';
|
|
17
|
+
readonly mode: 'delegate';
|
|
18
|
+
readonly state: DelegatePacketState;
|
|
19
|
+
readonly findings: null;
|
|
20
|
+
readonly rid: string;
|
|
21
|
+
readonly session: string;
|
|
22
|
+
readonly git: {
|
|
23
|
+
readonly from: string | null;
|
|
24
|
+
readonly to: string | null;
|
|
25
|
+
readonly commit: string | null;
|
|
26
|
+
};
|
|
27
|
+
readonly detection: {
|
|
28
|
+
readonly languages: readonly Ocr18Language[];
|
|
29
|
+
readonly changed_file_count: number;
|
|
30
|
+
readonly unsupported_files: readonly string[];
|
|
31
|
+
};
|
|
32
|
+
readonly cost: {
|
|
33
|
+
readonly total_files: number;
|
|
34
|
+
readonly reviewable_count: number;
|
|
35
|
+
readonly excluded_count: number;
|
|
36
|
+
readonly total_insertions: number;
|
|
37
|
+
readonly total_deletions: number;
|
|
38
|
+
} | null;
|
|
39
|
+
readonly selected_files: readonly DelegateSelectedFile[];
|
|
40
|
+
readonly excluded_files: readonly DelegateFile[];
|
|
41
|
+
readonly rules: readonly DelegateRuleGroup[];
|
|
42
|
+
readonly warnings: readonly string[];
|
|
43
|
+
readonly raw_output: string | null;
|
|
44
|
+
};
|
|
45
|
+
export type DelegatePacketInput = {
|
|
46
|
+
readonly rid: string;
|
|
47
|
+
readonly session: string;
|
|
48
|
+
readonly range: Ocr18Range;
|
|
49
|
+
readonly detection: Ocr18Detection;
|
|
50
|
+
readonly preview: DelegatePreview | null;
|
|
51
|
+
readonly rules: readonly DelegateRuleGroup[];
|
|
52
|
+
readonly unavailable: string | null;
|
|
53
|
+
};
|
|
54
|
+
export declare function buildDelegatePacket(input: DelegatePacketInput): DelegatePacket;
|
|
55
|
+
/** Rule resolution in batches, merged by `source|pattern` — the key the rule text is resolved on. */
|
|
56
|
+
export declare function collectDelegateRules(cwd: string, paths: readonly string[], range: Ocr18Range, timeoutMs?: number): RulesResult;
|
|
57
|
+
/**
|
|
58
|
+
* A rid is ONE path segment: it names the packet file under the session's
|
|
59
|
+
* `rd/ocr-delegate/` directory, so a separator or a traversal value would move
|
|
60
|
+
* the write somewhere the caller did not name.
|
|
61
|
+
*/
|
|
62
|
+
export declare function isDelegateRid(value: string): boolean;
|
|
63
|
+
export type CollectDelegateOptions = {
|
|
64
|
+
readonly cwd: string;
|
|
65
|
+
readonly rid: string;
|
|
66
|
+
readonly session: string;
|
|
67
|
+
readonly range: Ocr18Range;
|
|
68
|
+
readonly timeoutMs?: number;
|
|
69
|
+
};
|
|
70
|
+
export type DelegatePacketResult = {
|
|
71
|
+
readonly packet: DelegatePacket;
|
|
72
|
+
readonly failure: {
|
|
73
|
+
readonly state: Ocr18State;
|
|
74
|
+
readonly rawOutput: string;
|
|
75
|
+
} | null;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Phase 1. Writes nothing; the caller owns the path and the durable write.
|
|
79
|
+
*
|
|
80
|
+
* No routed language skips BOTH invocations, exactly like the API path: spawning
|
|
81
|
+
* OCR to discover there is nothing to review is the cost that guard exists for.
|
|
82
|
+
*/
|
|
83
|
+
export declare function collectDelegatePacket(options: CollectDelegateOptions): DelegatePacketResult;
|
|
84
|
+
export declare function writeDelegatePacket(packetPath: string, packet: DelegatePacket): void;
|