@open-cr-agent/core 0.6.0 → 0.9.0
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/README.md +1 -1
- package/dist/agent/json.d.ts +0 -1
- package/dist/agent/json.js +0 -1
- package/dist/agent/model-call.d.ts +13 -0
- package/dist/agent/model-call.js +22 -0
- package/dist/agent/pool.d.ts +0 -1
- package/dist/agent/pool.js +0 -1
- package/dist/agent/settings.d.ts +9 -5
- package/dist/agent/settings.js +20 -8
- package/dist/agent/spend-limit.d.ts +18 -0
- package/dist/agent/spend-limit.js +53 -0
- package/dist/agent/usage.d.ts +0 -1
- package/dist/agent/usage.js +0 -1
- package/dist/anchor/anchor.d.ts +0 -1
- package/dist/anchor/anchor.js +0 -1
- package/dist/anchor/match.d.ts +0 -1
- package/dist/anchor/match.js +0 -1
- package/dist/anchor/relocate.d.ts +1 -2
- package/dist/anchor/relocate.js +8 -15
- package/dist/at.d.ts +0 -1
- package/dist/at.js +0 -1
- package/dist/bounded-file.d.ts +12 -0
- package/dist/bounded-file.js +47 -0
- package/dist/bundle/bundle.d.ts +0 -1
- package/dist/bundle/bundle.js +0 -1
- package/dist/bundle/grouping.d.ts +0 -1
- package/dist/bundle/grouping.js +0 -1
- package/dist/bundle/runtime-grouper.d.ts +1 -2
- package/dist/bundle/runtime-grouper.js +8 -15
- package/dist/contracts.d.ts +37 -1
- package/dist/contracts.js +14 -1
- package/dist/diff/hunks.d.ts +0 -1
- package/dist/diff/hunks.js +0 -1
- package/dist/diff/parse.d.ts +0 -1
- package/dist/diff/parse.js +0 -1
- package/dist/diff/quoted-path.d.ts +0 -1
- package/dist/diff/quoted-path.js +0 -1
- package/dist/domain.d.ts +11 -1
- package/dist/domain.js +2 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +0 -1
- package/dist/hash.d.ts +0 -1
- package/dist/hash.js +0 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.js +4 -5
- package/dist/internal.d.ts +10 -6
- package/dist/internal.js +9 -5
- package/dist/judge/judge.d.ts +1 -2
- package/dist/judge/judge.js +10 -14
- package/dist/judge/prompt.d.ts +1 -2
- package/dist/judge/prompt.js +10 -2
- package/dist/judge/verdict.d.ts +2 -2
- package/dist/judge/verdict.js +4 -3
- package/dist/knowledge/learning.d.ts +21 -0
- package/dist/knowledge/learning.js +1 -0
- package/dist/knowledge/select.d.ts +15 -0
- package/dist/knowledge/select.js +175 -0
- package/dist/learn/draft.d.ts +21 -0
- package/dist/learn/draft.js +123 -0
- package/dist/{pipeline → matrix}/matrix.d.ts +1 -3
- package/dist/{pipeline → matrix}/matrix.js +1 -2
- package/dist/memory/memory.d.ts +0 -1
- package/dist/memory/memory.js +0 -1
- package/dist/net/proxied-fetch.d.ts +0 -1
- package/dist/net/proxied-fetch.js +0 -1
- package/dist/pipeline/assemble-report.d.ts +0 -7
- package/dist/pipeline/assemble-report.js +33 -21
- package/dist/pipeline/check-stage.d.ts +0 -1
- package/dist/pipeline/check-stage.js +31 -12
- package/dist/pipeline/context.d.ts +2 -2
- package/dist/pipeline/context.js +26 -7
- package/dist/pipeline/coverage.d.ts +1 -2
- package/dist/pipeline/coverage.js +37 -17
- package/dist/pipeline/execute-stage.d.ts +5 -6
- package/dist/pipeline/execute-stage.js +50 -29
- package/dist/pipeline/execute.d.ts +13 -7
- package/dist/pipeline/execute.js +108 -43
- package/dist/pipeline/filter-stage.d.ts +0 -1
- package/dist/pipeline/filter-stage.js +2 -1
- package/dist/pipeline/findings.d.ts +0 -1
- package/dist/pipeline/findings.js +0 -1
- package/dist/pipeline/imports.d.ts +0 -1
- package/dist/pipeline/imports.js +2 -17
- package/dist/pipeline/options.d.ts +22 -2
- package/dist/pipeline/options.js +31 -1
- package/dist/pipeline/plan-output.d.ts +7 -1
- package/dist/pipeline/plan-output.js +9 -2
- package/dist/pipeline/plan.d.ts +14 -9
- package/dist/pipeline/plan.js +64 -10
- package/dist/pipeline/preview.d.ts +5 -5
- package/dist/pipeline/preview.js +18 -28
- package/dist/pipeline/provenance.d.ts +0 -1
- package/dist/pipeline/provenance.js +0 -1
- package/dist/pipeline/resume.d.ts +22 -0
- package/dist/pipeline/resume.js +24 -0
- package/dist/pipeline/run-id.d.ts +0 -1
- package/dist/pipeline/run-id.js +0 -1
- package/dist/pipeline/run.d.ts +0 -1
- package/dist/pipeline/run.js +18 -45
- package/dist/pipeline/task-prompt.d.ts +13 -0
- package/dist/pipeline/task-prompt.js +43 -0
- package/dist/pipeline/task.d.ts +8 -8
- package/dist/pipeline/task.js +11 -7
- package/dist/plugin/builtin.d.ts +1 -1
- package/dist/plugin/builtin.js +12 -3
- package/dist/plugin/host.d.ts +0 -1
- package/dist/plugin/host.js +0 -1
- package/dist/plugin/registry.d.ts +0 -1
- package/dist/plugin/registry.js +0 -1
- package/dist/plugin/types.d.ts +0 -1
- package/dist/plugin/types.js +0 -1
- package/dist/report/output-schema.d.ts +69 -1
- package/dist/report/output-schema.js +34 -5
- package/dist/report/output.d.ts +0 -1
- package/dist/report/output.js +31 -4
- package/dist/report/provenance.d.ts +0 -1
- package/dist/report/provenance.js +0 -1
- package/dist/report/read.d.ts +0 -1
- package/dist/report/read.js +5 -3
- package/dist/report/report.d.ts +57 -4
- package/dist/report/report.js +40 -3
- package/dist/report/serialize.d.ts +0 -1
- package/dist/report/serialize.js +0 -1
- package/dist/rereview/presence.d.ts +0 -1
- package/dist/rereview/presence.js +0 -1
- package/dist/rereview/quote.d.ts +0 -1
- package/dist/rereview/quote.js +0 -1
- package/dist/rereview/reconcile.d.ts +0 -1
- package/dist/rereview/reconcile.js +0 -1
- package/dist/review/impact.d.ts +20 -5
- package/dist/review/impact.js +153 -29
- package/dist/review/plan-phase.d.ts +1 -2
- package/dist/review/plan-phase.js +13 -13
- package/dist/review/prompt-text.d.ts +1 -2
- package/dist/review/prompt-text.js +82 -21
- package/dist/review/prompt.d.ts +6 -1
- package/dist/review/prompt.js +57 -3
- package/dist/review/reviewer.d.ts +0 -1
- package/dist/review/reviewer.js +0 -1
- package/dist/review/reviewers/agents-md.d.ts +0 -1
- package/dist/review/reviewers/agents-md.js +0 -1
- package/dist/review/reviewers/correctness.d.ts +0 -1
- package/dist/review/reviewers/correctness.js +0 -1
- package/dist/review/reviewers/docs.d.ts +0 -1
- package/dist/review/reviewers/docs.js +0 -1
- package/dist/review/reviewers/performance.d.ts +0 -1
- package/dist/review/reviewers/performance.js +0 -1
- package/dist/review/reviewers/scopes.d.ts +0 -1
- package/dist/review/reviewers/scopes.js +0 -1
- package/dist/review/reviewers/security.d.ts +0 -1
- package/dist/review/reviewers/security.js +0 -1
- package/dist/review/tools.d.ts +1 -1
- package/dist/review/tools.js +1 -1
- package/dist/rules/builtin/general.d.ts +0 -1
- package/dist/rules/builtin/general.js +0 -1
- package/dist/rules/builtin/go.d.ts +0 -1
- package/dist/rules/builtin/go.js +0 -1
- package/dist/rules/builtin/index.d.ts +0 -1
- package/dist/rules/builtin/index.js +0 -1
- package/dist/rules/builtin/java.d.ts +0 -1
- package/dist/rules/builtin/java.js +0 -1
- package/dist/rules/builtin/performance.d.ts +0 -1
- package/dist/rules/builtin/performance.js +0 -1
- package/dist/rules/builtin/python.d.ts +0 -1
- package/dist/rules/builtin/python.js +0 -1
- package/dist/rules/builtin/security.d.ts +0 -1
- package/dist/rules/builtin/security.js +0 -1
- package/dist/rules/builtin/typescript.d.ts +0 -1
- package/dist/rules/builtin/typescript.js +0 -1
- package/dist/rules/languages.d.ts +0 -1
- package/dist/rules/languages.js +0 -1
- package/dist/rules/repo-rules.d.ts +0 -1
- package/dist/rules/repo-rules.js +0 -1
- package/dist/rules/resolve.d.ts +0 -1
- package/dist/rules/resolve.js +0 -1
- package/dist/rules/rule-set.d.ts +0 -1
- package/dist/rules/rule-set.js +0 -1
- package/dist/runtime/attempt.d.ts +27 -2
- package/dist/runtime/attempt.js +68 -2
- package/dist/runtime/chain-runner.d.ts +2 -3
- package/dist/runtime/chain-runner.js +0 -1
- package/dist/runtime/effort-capability.d.ts +0 -1
- package/dist/runtime/effort-capability.js +0 -1
- package/dist/runtime/failback.d.ts +2 -3
- package/dist/runtime/failback.js +61 -15
- package/dist/runtime/models.d.ts +0 -1
- package/dist/runtime/models.js +14 -13
- package/dist/runtime/quota.d.ts +1 -1
- package/dist/runtime/quota.js +3 -2
- package/dist/runtime/tools.d.ts +0 -1
- package/dist/runtime/tools.js +11 -1
- package/dist/runtime/wrap-up.d.ts +6 -0
- package/dist/runtime/wrap-up.js +27 -0
- package/dist/sarif/candidates.d.ts +3 -3
- package/dist/sarif/candidates.js +2 -1
- package/dist/sarif/evidence.d.ts +35 -0
- package/dist/sarif/evidence.js +128 -0
- package/dist/sarif/schema.d.ts +18 -1
- package/dist/sarif/schema.js +8 -1
- package/dist/select/patterns.d.ts +1 -1
- package/dist/select/patterns.js +46 -1
- package/dist/select/select.d.ts +2 -1
- package/dist/select/select.js +34 -4
- package/dist/session/jsonl.d.ts +2 -2
- package/dist/session/jsonl.js +9 -4
- package/dist/session/resume-read.d.ts +2 -0
- package/dist/session/resume-read.js +131 -0
- package/dist/session/seal.d.ts +5 -0
- package/dist/session/seal.js +29 -0
- package/dist/triage.d.ts +0 -1
- package/dist/triage.js +0 -1
- package/dist/vcs.d.ts +0 -1
- package/dist/vcs.js +0 -1
- package/dist/verify/prompt.d.ts +6 -3
- package/dist/verify/prompt.js +13 -5
- package/dist/verify/related.d.ts +3 -0
- package/dist/verify/related.js +88 -0
- package/dist/verify/verify.d.ts +3 -4
- package/dist/verify/verify.js +27 -20
- package/package.json +3 -3
- package/dist/agent/budget.d.ts +0 -13
- package/dist/agent/budget.js +0 -28
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { errorMessage } from "../errors.js";
|
|
2
|
+
// The wrap-up turn of an attempt that ended without an error and without the
|
|
3
|
+
// done tool (at the step cap, or stopped early after the resume), unless the
|
|
4
|
+
// run no longer wants it: cancelled, timed out or past its spend limit, which
|
|
5
|
+
// all abort the signal.
|
|
6
|
+
export function pendingWrapUp(attempt, ended, signal) {
|
|
7
|
+
if (!attempt.wrapUp || signal.aborted)
|
|
8
|
+
return undefined;
|
|
9
|
+
return ended === "step_cap" || ended === "stopped_early" ? attempt.wrapUp : undefined;
|
|
10
|
+
}
|
|
11
|
+
// The attempt's outcome after the turn. The attempt had finished, so a turn
|
|
12
|
+
// that fails keeps what it reported and spent but neither fails the task nor
|
|
13
|
+
// moves it to the next model; the error is recorded in the outcome.
|
|
14
|
+
export async function wrapUp(before, turn) {
|
|
15
|
+
try {
|
|
16
|
+
const { error, ...after } = outcomeOf(await turn());
|
|
17
|
+
const findings = Math.max(0, after.findings.length - before.findings.length);
|
|
18
|
+
return { ...after, wrappedUp: { findings, ...(error ? { error: error.message } : {}) } };
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return { ...before, wrappedUp: { findings: 0, error: errorMessage(error) } };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function outcomeOf(attempt) {
|
|
25
|
+
const { wrapUp: _turn, ...outcome } = attempt;
|
|
26
|
+
return outcome;
|
|
27
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LineRange, Severity } from "../domain.js";
|
|
2
2
|
import type { SarifRun } from "./schema.js";
|
|
3
|
-
interface SarifTool {
|
|
3
|
+
export interface SarifTool {
|
|
4
4
|
name: string;
|
|
5
5
|
slug: string;
|
|
6
6
|
version?: string;
|
|
@@ -13,6 +13,8 @@ export interface SarifCandidate {
|
|
|
13
13
|
ruleId: string;
|
|
14
14
|
title: string;
|
|
15
15
|
body: string;
|
|
16
|
+
message: string;
|
|
17
|
+
security: boolean;
|
|
16
18
|
}
|
|
17
19
|
export interface SarifCandidates {
|
|
18
20
|
tool: SarifTool;
|
|
@@ -24,5 +26,3 @@ export interface SarifCandidates {
|
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
28
|
export declare function sarifCandidates(run: SarifRun): SarifCandidates;
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=candidates.d.ts.map
|
package/dist/sarif/candidates.js
CHANGED
|
@@ -40,6 +40,8 @@ export function sarifCandidates(run) {
|
|
|
40
40
|
ruleId,
|
|
41
41
|
title: rule?.shortDescription?.text?.trim() || rule?.name || ruleId,
|
|
42
42
|
body: bodyOf(text, ruleId, rule, tool),
|
|
43
|
+
message: text,
|
|
44
|
+
security: [...(result.properties?.tags ?? []), ...(rule?.properties?.tags ?? [])].some((tag) => tag.toLowerCase() === "security"),
|
|
43
45
|
};
|
|
44
46
|
const snippet = region.snippet?.text?.trim();
|
|
45
47
|
if (snippet)
|
|
@@ -99,4 +101,3 @@ function repositoryPath(uri, base) {
|
|
|
99
101
|
return undefined;
|
|
100
102
|
return path;
|
|
101
103
|
}
|
|
102
|
-
//# sourceMappingURL=candidates.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { FileDiff, LineRange, Severity } from "../domain.js";
|
|
2
|
+
import { type SarifTool } from "./candidates.js";
|
|
3
|
+
import type { SarifLog } from "./schema.js";
|
|
4
|
+
export declare const EVIDENCE_MARGIN_LINES = 10;
|
|
5
|
+
export declare const MAX_EVIDENCE_PER_BUNDLE = 20;
|
|
6
|
+
export declare const MAX_EVIDENCE_MESSAGE_CHARS = 300;
|
|
7
|
+
export interface AnalyzerResult {
|
|
8
|
+
tool: SarifTool;
|
|
9
|
+
file: string;
|
|
10
|
+
lines: LineRange;
|
|
11
|
+
severity: Severity;
|
|
12
|
+
ruleId: string;
|
|
13
|
+
message: string;
|
|
14
|
+
security: boolean;
|
|
15
|
+
onChange: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface AnalyzerEvidenceUse {
|
|
18
|
+
tool: string;
|
|
19
|
+
version?: string;
|
|
20
|
+
results: number;
|
|
21
|
+
bundles: string[];
|
|
22
|
+
}
|
|
23
|
+
interface FileGroup {
|
|
24
|
+
label: string;
|
|
25
|
+
files: readonly FileDiff[];
|
|
26
|
+
}
|
|
27
|
+
export interface AnalyzerEvidence {
|
|
28
|
+
forBundle(bundle: FileGroup): readonly AnalyzerResult[];
|
|
29
|
+
warnings: string[];
|
|
30
|
+
}
|
|
31
|
+
export declare function analyzerEvidence(logs: readonly SarifLog[], bundles: readonly FileGroup[]): AnalyzerEvidence;
|
|
32
|
+
export declare function evidenceUses(evidence: AnalyzerEvidence, bundles: readonly FileGroup[]): AnalyzerEvidenceUse[];
|
|
33
|
+
export declare function changedLines(diffs: readonly FileDiff[]): Map<string, LineRange[]>;
|
|
34
|
+
export declare function overlaps(lines: LineRange, range: LineRange, margin: number): boolean;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { sarifCandidates } from "./candidates.js";
|
|
2
|
+
// Analyzer results shown to reviewers as evidence (ADR-0042): a lead the
|
|
3
|
+
// reviewer confirms in the code, never a finding of its own.
|
|
4
|
+
// A result just outside a hunk is often what the change makes reachable.
|
|
5
|
+
export const EVIDENCE_MARGIN_LINES = 10;
|
|
6
|
+
export const MAX_EVIDENCE_PER_BUNDLE = 20;
|
|
7
|
+
export const MAX_EVIDENCE_MESSAGE_CHARS = 300;
|
|
8
|
+
const noEvidence = { forBundle: () => [], warnings: [] };
|
|
9
|
+
export function analyzerEvidence(logs, bundles) {
|
|
10
|
+
if (logs.length === 0)
|
|
11
|
+
return noEvidence;
|
|
12
|
+
const windows = changedLines(bundles.flatMap((b) => b.files));
|
|
13
|
+
const near = [];
|
|
14
|
+
const counts = new Map();
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
for (const log of logs) {
|
|
17
|
+
for (const run of log.runs) {
|
|
18
|
+
const { tool, candidates, skipped } = sarifCandidates(run);
|
|
19
|
+
const count = counts.get(tool.name) ?? { near: 0, given: 0, away: 0, skipped: 0 };
|
|
20
|
+
counts.set(tool.name, count);
|
|
21
|
+
count.skipped += skipped.noLocation + skipped.unsupportedUri + skipped.noMessage;
|
|
22
|
+
for (const candidate of candidates) {
|
|
23
|
+
const key = [tool.name, candidate.ruleId, candidate.file, candidate.lines.start].join("\0");
|
|
24
|
+
if (seen.has(key))
|
|
25
|
+
continue;
|
|
26
|
+
seen.add(key);
|
|
27
|
+
const result = placed(tool, candidate, windows.get(candidate.file) ?? []);
|
|
28
|
+
if (!result) {
|
|
29
|
+
count.away += 1;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
count.near += 1;
|
|
33
|
+
near.push(result);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
near.sort(byRelevance);
|
|
38
|
+
const kept = new Set();
|
|
39
|
+
for (const bundle of bundles) {
|
|
40
|
+
const files = new Set(bundle.files.map((f) => f.newPath));
|
|
41
|
+
for (const r of near.filter((r) => files.has(r.file)).slice(0, MAX_EVIDENCE_PER_BUNDLE)) {
|
|
42
|
+
kept.add(r);
|
|
43
|
+
const count = counts.get(r.tool.name);
|
|
44
|
+
if (count)
|
|
45
|
+
count.given += 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const given = near.filter((r) => kept.has(r));
|
|
49
|
+
return {
|
|
50
|
+
// A file is in one bundle, so a task never sees more than its bundle's cap.
|
|
51
|
+
forBundle: (bundle) => {
|
|
52
|
+
const files = new Set(bundle.files.map((f) => f.newPath));
|
|
53
|
+
return given.filter((r) => files.has(r.file));
|
|
54
|
+
},
|
|
55
|
+
warnings: [...counts].flatMap(([tool, c]) => evidenceWarning(tool, c)),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function placed(tool, candidate, ranges) {
|
|
59
|
+
const { lines } = candidate;
|
|
60
|
+
const onChange = ranges.some((r) => overlaps(lines, r, 0));
|
|
61
|
+
if (!onChange && !ranges.some((r) => overlaps(lines, r, EVIDENCE_MARGIN_LINES)))
|
|
62
|
+
return undefined;
|
|
63
|
+
return {
|
|
64
|
+
tool,
|
|
65
|
+
file: candidate.file,
|
|
66
|
+
lines,
|
|
67
|
+
severity: candidate.severity,
|
|
68
|
+
ruleId: candidate.ruleId,
|
|
69
|
+
message: candidate.message.slice(0, MAX_EVIDENCE_MESSAGE_CHARS),
|
|
70
|
+
security: candidate.security,
|
|
71
|
+
onChange,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const SEVERITY_ORDER = { critical: 0, warning: 1, suggestion: 2 };
|
|
75
|
+
function byRelevance(a, b) {
|
|
76
|
+
return (Number(b.onChange) - Number(a.onChange) ||
|
|
77
|
+
SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity] ||
|
|
78
|
+
Number(b.security) - Number(a.security) ||
|
|
79
|
+
(a.file < b.file ? -1 : a.file > b.file ? 1 : 0) ||
|
|
80
|
+
a.lines.start - b.lines.start ||
|
|
81
|
+
(a.ruleId < b.ruleId ? -1 : a.ruleId > b.ruleId ? 1 : 0));
|
|
82
|
+
}
|
|
83
|
+
// The new-side lines each hunk covers, context included.
|
|
84
|
+
export function evidenceUses(evidence, bundles) {
|
|
85
|
+
const uses = new Map();
|
|
86
|
+
for (const bundle of bundles) {
|
|
87
|
+
for (const r of evidence.forBundle(bundle)) {
|
|
88
|
+
const use = uses.get(r.tool.name) ?? {
|
|
89
|
+
tool: r.tool.name,
|
|
90
|
+
...(r.tool.version ? { version: r.tool.version } : {}),
|
|
91
|
+
results: 0,
|
|
92
|
+
bundles: [],
|
|
93
|
+
};
|
|
94
|
+
use.results += 1;
|
|
95
|
+
if (!use.bundles.includes(bundle.label))
|
|
96
|
+
use.bundles.push(bundle.label);
|
|
97
|
+
uses.set(r.tool.name, use);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return [...uses.values()];
|
|
101
|
+
}
|
|
102
|
+
export function changedLines(diffs) {
|
|
103
|
+
const windows = new Map();
|
|
104
|
+
for (const diff of diffs) {
|
|
105
|
+
const ranges = diff.hunks
|
|
106
|
+
.filter((h) => h.newLines > 0)
|
|
107
|
+
.map((h) => ({ start: h.newStart, end: h.newStart + h.newLines - 1 }));
|
|
108
|
+
if (ranges.length > 0)
|
|
109
|
+
windows.set(diff.newPath, ranges);
|
|
110
|
+
}
|
|
111
|
+
return windows;
|
|
112
|
+
}
|
|
113
|
+
export function overlaps(lines, range, margin) {
|
|
114
|
+
return lines.start <= range.end + margin && lines.end >= range.start - margin;
|
|
115
|
+
}
|
|
116
|
+
function evidenceWarning(tool, c) {
|
|
117
|
+
const left = [];
|
|
118
|
+
if (c.near > c.given) {
|
|
119
|
+
left.push(`${c.near - c.given} over the limit of ${MAX_EVIDENCE_PER_BUNDLE} per bundle`);
|
|
120
|
+
}
|
|
121
|
+
if (c.away > 0)
|
|
122
|
+
left.push(`${c.away} away from the change`);
|
|
123
|
+
if (c.skipped > 0)
|
|
124
|
+
left.push(`${c.skipped} without a file, lines or message`);
|
|
125
|
+
if (left.length === 0)
|
|
126
|
+
return [];
|
|
127
|
+
return [`${tool}: gave reviewers ${c.given} result(s) as evidence; left out ${left.join(", ")}`];
|
|
128
|
+
}
|
package/dist/sarif/schema.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ declare const rule: z.ZodObject<{
|
|
|
13
13
|
defaultConfiguration: z.ZodOptional<z.ZodObject<{
|
|
14
14
|
level: z.ZodOptional<z.ZodString>;
|
|
15
15
|
}, z.core.$loose>>;
|
|
16
|
+
properties: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
17
|
+
tags: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
18
|
+
}, z.core.$loose>>>;
|
|
16
19
|
}, z.core.$loose>;
|
|
17
20
|
declare const result: z.ZodObject<{
|
|
18
21
|
ruleId: z.ZodOptional<z.ZodString>;
|
|
@@ -36,6 +39,9 @@ declare const result: z.ZodObject<{
|
|
|
36
39
|
}, z.core.$loose>>;
|
|
37
40
|
}, z.core.$loose>>;
|
|
38
41
|
}, z.core.$loose>>>;
|
|
42
|
+
properties: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
43
|
+
tags: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
44
|
+
}, z.core.$loose>>>;
|
|
39
45
|
}, z.core.$loose>;
|
|
40
46
|
declare const sarifRunSchema: z.ZodObject<{
|
|
41
47
|
tool: z.ZodObject<{
|
|
@@ -56,6 +62,9 @@ declare const sarifRunSchema: z.ZodObject<{
|
|
|
56
62
|
defaultConfiguration: z.ZodOptional<z.ZodObject<{
|
|
57
63
|
level: z.ZodOptional<z.ZodString>;
|
|
58
64
|
}, z.core.$loose>>;
|
|
65
|
+
properties: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
66
|
+
tags: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
67
|
+
}, z.core.$loose>>>;
|
|
59
68
|
}, z.core.$loose>>>;
|
|
60
69
|
}, z.core.$loose>;
|
|
61
70
|
}, z.core.$loose>;
|
|
@@ -81,6 +90,9 @@ declare const sarifRunSchema: z.ZodObject<{
|
|
|
81
90
|
}, z.core.$loose>>;
|
|
82
91
|
}, z.core.$loose>>;
|
|
83
92
|
}, z.core.$loose>>>;
|
|
93
|
+
properties: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
94
|
+
tags: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
95
|
+
}, z.core.$loose>>>;
|
|
84
96
|
}, z.core.$loose>>>;
|
|
85
97
|
}, z.core.$loose>;
|
|
86
98
|
declare const sarifLogSchema: z.ZodObject<{
|
|
@@ -104,6 +116,9 @@ declare const sarifLogSchema: z.ZodObject<{
|
|
|
104
116
|
defaultConfiguration: z.ZodOptional<z.ZodObject<{
|
|
105
117
|
level: z.ZodOptional<z.ZodString>;
|
|
106
118
|
}, z.core.$loose>>;
|
|
119
|
+
properties: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
120
|
+
tags: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
121
|
+
}, z.core.$loose>>>;
|
|
107
122
|
}, z.core.$loose>>>;
|
|
108
123
|
}, z.core.$loose>;
|
|
109
124
|
}, z.core.$loose>;
|
|
@@ -129,6 +144,9 @@ declare const sarifLogSchema: z.ZodObject<{
|
|
|
129
144
|
}, z.core.$loose>>;
|
|
130
145
|
}, z.core.$loose>>;
|
|
131
146
|
}, z.core.$loose>>>;
|
|
147
|
+
properties: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
148
|
+
tags: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
149
|
+
}, z.core.$loose>>>;
|
|
132
150
|
}, z.core.$loose>>>;
|
|
133
151
|
}, z.core.$loose>>;
|
|
134
152
|
}, z.core.$loose>;
|
|
@@ -141,4 +159,3 @@ export declare class SarifError extends OcraError {
|
|
|
141
159
|
}
|
|
142
160
|
export declare function parseSarifLog(text: string): SarifLog;
|
|
143
161
|
export {};
|
|
144
|
-
//# sourceMappingURL=schema.d.ts.map
|
package/dist/sarif/schema.js
CHANGED
|
@@ -4,6 +4,12 @@ import { errorMessage, OcraError } from "../errors.js";
|
|
|
4
4
|
// far more than this, and none of it is trusted beyond what is checked here.
|
|
5
5
|
// https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html
|
|
6
6
|
const message = z.looseObject({ text: z.string().optional() });
|
|
7
|
+
// Tags such as "security" and CWE ids; a log that writes them in another
|
|
8
|
+
// shape loses them, never the result.
|
|
9
|
+
const properties = z
|
|
10
|
+
.looseObject({ tags: z.array(z.string()).optional().catch(undefined) })
|
|
11
|
+
.optional()
|
|
12
|
+
.catch(undefined);
|
|
7
13
|
const region = z.looseObject({
|
|
8
14
|
startLine: z.int().positive(),
|
|
9
15
|
endLine: z.int().positive().optional(),
|
|
@@ -26,6 +32,7 @@ const rule = z.looseObject({
|
|
|
26
32
|
fullDescription: message.optional(),
|
|
27
33
|
helpUri: z.string().optional(),
|
|
28
34
|
defaultConfiguration: z.looseObject({ level: z.string().optional() }).optional(),
|
|
35
|
+
properties,
|
|
29
36
|
});
|
|
30
37
|
const result = z.looseObject({
|
|
31
38
|
ruleId: z.string().optional(),
|
|
@@ -33,6 +40,7 @@ const result = z.looseObject({
|
|
|
33
40
|
level: z.string().optional(),
|
|
34
41
|
message,
|
|
35
42
|
locations: z.array(location).optional(),
|
|
43
|
+
properties,
|
|
36
44
|
});
|
|
37
45
|
const sarifRunSchema = z.looseObject({
|
|
38
46
|
tool: z.looseObject({
|
|
@@ -68,4 +76,3 @@ export function parseSarifLog(text) {
|
|
|
68
76
|
throw new SarifError(`not a SARIF 2.1.0 log: ${z.prettifyError(parsed.error)}`);
|
|
69
77
|
return parsed.data;
|
|
70
78
|
}
|
|
71
|
-
//# sourceMappingURL=schema.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const SECRET_PATTERNS: string[];
|
|
2
2
|
export declare const ENV_TEMPLATE_PATTERNS: string[];
|
|
3
3
|
export declare const NON_REVIEWABLE_EXTENSIONS: string[];
|
|
4
|
+
export declare const TEXT_EXTENSIONS: string[];
|
|
4
5
|
export declare const GENERATED_PATTERNS: string[];
|
|
5
6
|
export declare const MIGRATION_PATTERNS: string[];
|
|
6
|
-
//# sourceMappingURL=patterns.d.ts.map
|
package/dist/select/patterns.js
CHANGED
|
@@ -99,6 +99,52 @@ export const NON_REVIEWABLE_EXTENSIONS = [
|
|
|
99
99
|
"db",
|
|
100
100
|
"sqlite",
|
|
101
101
|
];
|
|
102
|
+
// Names that say source or text: such a file diffing as binary is worth a
|
|
103
|
+
// warning (select.ts). Not exhaustive; a miss only loses the warning.
|
|
104
|
+
export const TEXT_EXTENSIONS = [
|
|
105
|
+
"c",
|
|
106
|
+
"cc",
|
|
107
|
+
"cpp",
|
|
108
|
+
"cs",
|
|
109
|
+
"css",
|
|
110
|
+
"cxx",
|
|
111
|
+
"dart",
|
|
112
|
+
"ex",
|
|
113
|
+
"exs",
|
|
114
|
+
"go",
|
|
115
|
+
"gradle",
|
|
116
|
+
"h",
|
|
117
|
+
"hpp",
|
|
118
|
+
"html",
|
|
119
|
+
"java",
|
|
120
|
+
"js",
|
|
121
|
+
"json",
|
|
122
|
+
"jsx",
|
|
123
|
+
"kt",
|
|
124
|
+
"kts",
|
|
125
|
+
"lua",
|
|
126
|
+
"m",
|
|
127
|
+
"md",
|
|
128
|
+
"mjs",
|
|
129
|
+
"cjs",
|
|
130
|
+
"php",
|
|
131
|
+
"pl",
|
|
132
|
+
"py",
|
|
133
|
+
"rb",
|
|
134
|
+
"rs",
|
|
135
|
+
"scala",
|
|
136
|
+
"scss",
|
|
137
|
+
"sh",
|
|
138
|
+
"sql",
|
|
139
|
+
"swift",
|
|
140
|
+
"toml",
|
|
141
|
+
"ts",
|
|
142
|
+
"tsx",
|
|
143
|
+
"vue",
|
|
144
|
+
"xml",
|
|
145
|
+
"yaml",
|
|
146
|
+
"yml",
|
|
147
|
+
];
|
|
102
148
|
export const GENERATED_PATTERNS = [
|
|
103
149
|
"**/package-lock.json",
|
|
104
150
|
"**/npm-shrinkwrap.json",
|
|
@@ -129,4 +175,3 @@ export const GENERATED_PATTERNS = [
|
|
|
129
175
|
"**/__snapshots__/**",
|
|
130
176
|
];
|
|
131
177
|
export const MIGRATION_PATTERNS = ["**/migrations/**", "**/migrate/**", "**/*.migration.*"];
|
|
132
|
-
//# sourceMappingURL=patterns.js.map
|
package/dist/select/select.d.ts
CHANGED
|
@@ -25,5 +25,6 @@ export interface SelectionPolicy {
|
|
|
25
25
|
}
|
|
26
26
|
export declare const defaultSelectionPolicy: SelectionPolicy;
|
|
27
27
|
export declare function isSecretPath(path: string): boolean;
|
|
28
|
+
export declare function foldPath(path: string): string;
|
|
28
29
|
export declare function selectFiles(diffs: readonly FileDiff[], policy?: SelectionPolicy): FileDecision[];
|
|
29
|
-
|
|
30
|
+
export declare function binaryTextWarning(decisions: readonly FileDecision[]): string | undefined;
|
package/dist/select/select.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import picomatch from "picomatch";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { ENV_TEMPLATE_PATTERNS, GENERATED_PATTERNS, MIGRATION_PATTERNS, NON_REVIEWABLE_EXTENSIONS, SECRET_PATTERNS, } from "./patterns.js";
|
|
3
|
+
import { ENV_TEMPLATE_PATTERNS, GENERATED_PATTERNS, MIGRATION_PATTERNS, NON_REVIEWABLE_EXTENSIONS, SECRET_PATTERNS, TEXT_EXTENSIONS, } from "./patterns.js";
|
|
4
4
|
export const exclusionReasonSchema = z.enum([
|
|
5
5
|
"binary",
|
|
6
6
|
"secret",
|
|
@@ -20,8 +20,24 @@ const isSecret = picomatch(SECRET_PATTERNS, { ...globOptions, ignore: ENV_TEMPLA
|
|
|
20
20
|
const isGenerated = picomatch(GENERATED_PATTERNS, globOptions);
|
|
21
21
|
const isMigration = picomatch(MIGRATION_PATTERNS, globOptions);
|
|
22
22
|
const nonReviewableExtensions = new Set(NON_REVIEWABLE_EXTENSIONS);
|
|
23
|
+
const textExtensions = new Set(TEXT_EXTENSIONS);
|
|
24
|
+
const NAMED_FILES = 3;
|
|
25
|
+
// The raw path is matched too: NFKC can fold a character into "/", which a
|
|
26
|
+
// pattern's "*" matches only in the raw path.
|
|
23
27
|
export function isSecretPath(path) {
|
|
24
|
-
return isSecret(path);
|
|
28
|
+
return isSecret(path) || isSecret(foldPath(path));
|
|
29
|
+
}
|
|
30
|
+
const IGNORABLE = /\p{Default_Ignorable_Code_Point}/gu;
|
|
31
|
+
// A case-insensitive file system opens a file under any name that folds to
|
|
32
|
+
// the same as its own. APFS normalizes and applies full Unicode case folding,
|
|
33
|
+
// so a Kelvin sign opens "k", a long s "s", "ß" "ss" and a ligature its
|
|
34
|
+
// letters; HFS+ also skips some invisible characters. The access policy
|
|
35
|
+
// compares this form, which folds the ASCII names it refuses at least as far,
|
|
36
|
+
// so that no spelling of such a name passes. NFKC takes the Kelvin sign, the
|
|
37
|
+
// long s and ligatures to ASCII; upper-casing expands "ß" (and "ẞ", once
|
|
38
|
+
// lower-cased), which lower-casing keeps.
|
|
39
|
+
export function foldPath(path) {
|
|
40
|
+
return path.normalize("NFKC").replace(IGNORABLE, "").toLowerCase().toUpperCase().toLowerCase();
|
|
25
41
|
}
|
|
26
42
|
export function selectFiles(diffs, policy = defaultSelectionPolicy) {
|
|
27
43
|
const isUserExcluded = matcher(policy.exclude);
|
|
@@ -35,7 +51,7 @@ function exclusionReason(diff, policy, isUserExcluded, isUserIncluded) {
|
|
|
35
51
|
const path = diff.newPath;
|
|
36
52
|
if (diff.isBinary)
|
|
37
53
|
return "binary";
|
|
38
|
-
if (
|
|
54
|
+
if (isSecretPath(diff.oldPath) || isSecretPath(path))
|
|
39
55
|
return "secret";
|
|
40
56
|
if (diff.kind === "deleted")
|
|
41
57
|
return "deleted";
|
|
@@ -51,6 +67,21 @@ function exclusionReason(diff, policy, isUserExcluded, isUserIncluded) {
|
|
|
51
67
|
return "too_large";
|
|
52
68
|
return undefined;
|
|
53
69
|
}
|
|
70
|
+
// A file whose name says text diffs as binary because of its size or a
|
|
71
|
+
// .gitattributes entry, and an adapter that reads attributes from the
|
|
72
|
+
// reviewed tree (an old git) lets the change set them: worth saying, since
|
|
73
|
+
// binary files are not reviewed.
|
|
74
|
+
export function binaryTextWarning(decisions) {
|
|
75
|
+
const paths = decisions
|
|
76
|
+
.filter((d) => !d.selected && d.reason === "binary" && d.diff.kind !== "deleted")
|
|
77
|
+
.map((d) => d.diff.newPath)
|
|
78
|
+
.filter((path) => textExtensions.has(extension(path)));
|
|
79
|
+
if (paths.length === 0)
|
|
80
|
+
return undefined;
|
|
81
|
+
const more = paths.length > NAMED_FILES ? ` and ${paths.length - NAMED_FILES} more` : "";
|
|
82
|
+
return (`${paths.length} file(s) not reviewed as binary although their names say text ` +
|
|
83
|
+
`(a .gitattributes entry or their size): ${paths.slice(0, NAMED_FILES).join(", ")}${more}`);
|
|
84
|
+
}
|
|
54
85
|
function matcher(patterns) {
|
|
55
86
|
return patterns.length === 0 ? () => false : picomatch([...patterns], globOptions);
|
|
56
87
|
}
|
|
@@ -59,4 +90,3 @@ function extension(path) {
|
|
|
59
90
|
const dot = name.lastIndexOf(".");
|
|
60
91
|
return dot > 0 ? name.slice(dot + 1).toLowerCase() : "";
|
|
61
92
|
}
|
|
62
|
-
//# sourceMappingURL=select.js.map
|
package/dist/session/jsonl.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const REPORT_FILE = "report.json";
|
|
|
4
4
|
export declare class JsonlSessionWriter {
|
|
5
5
|
readonly dir: string;
|
|
6
6
|
readonly id: string;
|
|
7
|
-
|
|
7
|
+
private readonly sealKey;
|
|
8
|
+
constructor(sessionsDir: string, id?: string, sealKey?: string);
|
|
8
9
|
write(event: ReviewEvent): void;
|
|
9
10
|
}
|
|
10
|
-
//# sourceMappingURL=jsonl.d.ts.map
|
package/dist/session/jsonl.js
CHANGED
|
@@ -4,15 +4,20 @@ import { isNotFound, OcraError } from "../errors.js";
|
|
|
4
4
|
import { newRunId } from "../pipeline/run-id.js";
|
|
5
5
|
import { toReportOutput } from "../report/output.js";
|
|
6
6
|
import { serializeOutput } from "../report/serialize.js";
|
|
7
|
+
import { sealLine } from "./seal.js";
|
|
7
8
|
export const EVENTS_FILE = "events.jsonl";
|
|
8
9
|
export const REPORT_FILE = "report.json";
|
|
9
10
|
// Events are appended synchronously, one JSON object per line, so the log
|
|
10
|
-
// stays valid and ordered even if the process dies mid-run.
|
|
11
|
+
// stays valid and ordered even if the process dies mid-run. With a seal key
|
|
12
|
+
// (this machine's, seal.ts), each line is sealed so that --resume can tell
|
|
13
|
+
// it from a line a change brought into the tree.
|
|
11
14
|
export class JsonlSessionWriter {
|
|
12
15
|
dir;
|
|
13
16
|
id;
|
|
14
|
-
|
|
17
|
+
sealKey;
|
|
18
|
+
constructor(sessionsDir, id = newRunId(), sealKey) {
|
|
15
19
|
this.id = id;
|
|
20
|
+
this.sealKey = sealKey;
|
|
16
21
|
// The sessions directory lives in the reviewed tree, which may carry
|
|
17
22
|
// links planted to send the logs, or the .gitignore write, elsewhere.
|
|
18
23
|
for (const dir of [dirname(sessionsDir), sessionsDir])
|
|
@@ -30,7 +35,8 @@ export class JsonlSessionWriter {
|
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
write(event) {
|
|
33
|
-
const
|
|
38
|
+
const serialized = serializeOutput({ time: new Date().toISOString(), ...event }, 0);
|
|
39
|
+
const line = this.sealKey ? sealLine(this.sealKey, this.id, serialized) : serialized;
|
|
34
40
|
appendFileSync(join(this.dir, EVENTS_FILE), `${line}\n`);
|
|
35
41
|
if (event.type === "run_finished") {
|
|
36
42
|
const report = toReportOutput(event.report);
|
|
@@ -49,4 +55,3 @@ function refuseSymlink(path) {
|
|
|
49
55
|
throw error;
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
|
-
//# sourceMappingURL=jsonl.js.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { lstat } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { readBoundedFile } from "../bounded-file.js";
|
|
5
|
+
import { reportedFindingSchema } from "../domain.js";
|
|
6
|
+
import { errorMessage, OcraError } from "../errors.js";
|
|
7
|
+
import { boundFinding, MAX_FINDINGS_PER_TASK } from "../pipeline/task.js";
|
|
8
|
+
import { taskOutcomeSchema } from "../report/output-schema.js";
|
|
9
|
+
import { EVENTS_FILE } from "./jsonl.js";
|
|
10
|
+
import { unsealLine } from "./seal.js";
|
|
11
|
+
// A session log is bounded by the run's task and finding limits; anything
|
|
12
|
+
// far larger was not written by ocra.
|
|
13
|
+
const MAX_EVENTS_BYTES = 64 * 1024 * 1024;
|
|
14
|
+
const RUN_ID = /^[\w@-][\w.@-]*$/;
|
|
15
|
+
const reportedEventSchema = z.object({
|
|
16
|
+
type: z.literal("task_reported"),
|
|
17
|
+
taskId: z.string(),
|
|
18
|
+
key: z.string(),
|
|
19
|
+
findings: z.array(z.object({ reported: reportedFindingSchema, model: z.string().exactOptional() })),
|
|
20
|
+
});
|
|
21
|
+
const finishedEventSchema = z.object({
|
|
22
|
+
type: z.literal("task_finished"),
|
|
23
|
+
outcome: taskOutcomeSchema,
|
|
24
|
+
});
|
|
25
|
+
const bundledEventSchema = z.object({
|
|
26
|
+
type: z.literal("files_bundled"),
|
|
27
|
+
groups: z.array(z.object({ label: z.string(), files: z.array(z.string()) })),
|
|
28
|
+
});
|
|
29
|
+
// The completed tasks of an earlier run, from its session log, which a run
|
|
30
|
+
// killed before it finished still has. The session lives in the reviewed
|
|
31
|
+
// tree, where a change can bring one of its own: only lines sealed with this
|
|
32
|
+
// machine's key (seal.ts) are read, the rest is skipped and counted, and a
|
|
33
|
+
// log with no such line is refused. Sealed lines are still validated and
|
|
34
|
+
// bounded like a model's answer. The bundles come from the log too; report.json
|
|
35
|
+
// carries no seal.
|
|
36
|
+
export async function readResumedRun(sessionsDir, runId, sealKey, warn = () => { }) {
|
|
37
|
+
if (!RUN_ID.test(runId)) {
|
|
38
|
+
throw new OcraError("INPUT_INVALID", `--resume: ${JSON.stringify(runId)} is not a run id`);
|
|
39
|
+
}
|
|
40
|
+
const dir = join(sessionsDir, runId);
|
|
41
|
+
for (const path of [dirname(sessionsDir), sessionsDir, dir])
|
|
42
|
+
await refuseLink(path, runId);
|
|
43
|
+
const text = await readEvents(join(dir, EVENTS_FILE), runId);
|
|
44
|
+
const reported = new Map();
|
|
45
|
+
let groups = [];
|
|
46
|
+
const finished = new Map();
|
|
47
|
+
let sealed = 0;
|
|
48
|
+
let unsealed = 0;
|
|
49
|
+
for (const raw of text.split("\n")) {
|
|
50
|
+
if (!raw.trim())
|
|
51
|
+
continue;
|
|
52
|
+
const line = unsealLine(sealKey, runId, raw);
|
|
53
|
+
if (line === undefined) {
|
|
54
|
+
unsealed += 1;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
sealed += 1;
|
|
58
|
+
let data;
|
|
59
|
+
try {
|
|
60
|
+
data = JSON.parse(line);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const r = reportedEventSchema.safeParse(data);
|
|
66
|
+
if (r.success)
|
|
67
|
+
reported.set(r.data.taskId, r.data);
|
|
68
|
+
const f = finishedEventSchema.safeParse(data);
|
|
69
|
+
if (f.success)
|
|
70
|
+
finished.set(f.data.outcome.taskId, f.data.outcome);
|
|
71
|
+
const b = bundledEventSchema.safeParse(data);
|
|
72
|
+
if (b.success)
|
|
73
|
+
groups = b.data.groups;
|
|
74
|
+
}
|
|
75
|
+
if (sealed === 0 && unsealed === 0) {
|
|
76
|
+
throw new OcraError("INPUT_INVALID", `--resume: the session log of ${runId} is empty, so there is nothing to reuse`);
|
|
77
|
+
}
|
|
78
|
+
if (sealed === 0) {
|
|
79
|
+
throw new OcraError("INPUT_INVALID", `--resume: the session of ${runId} was not written by ocra on this machine, so none of it is reused`);
|
|
80
|
+
}
|
|
81
|
+
if (unsealed > 0) {
|
|
82
|
+
warn(`--resume: ignored ${unsealed} line(s) of the session of ${runId} that ocra on this machine did not write`);
|
|
83
|
+
}
|
|
84
|
+
const tasks = [];
|
|
85
|
+
for (const [taskId, outcome] of finished) {
|
|
86
|
+
const event = reported.get(taskId);
|
|
87
|
+
if (!event || !reusable(outcome))
|
|
88
|
+
continue;
|
|
89
|
+
tasks.push({ key: event.key, outcome, findings: bounded(event.findings) });
|
|
90
|
+
}
|
|
91
|
+
return { runId, bundles: groups, tasks };
|
|
92
|
+
}
|
|
93
|
+
// Only a task that finished its review, with a plausible outcome: one cut
|
|
94
|
+
// off before it finished is reviewed again (ADR-0030).
|
|
95
|
+
function reusable(outcome) {
|
|
96
|
+
const { usage } = outcome;
|
|
97
|
+
return (outcome.status === "completed" &&
|
|
98
|
+
outcome.ended === undefined &&
|
|
99
|
+
(outcome.reusedFrom === undefined || RUN_ID.test(outcome.reusedFrom)) &&
|
|
100
|
+
outcome.durationMs >= 0 &&
|
|
101
|
+
Object.values(usage).every((n) => Number.isFinite(n) && n >= 0));
|
|
102
|
+
}
|
|
103
|
+
// The same bounds a live task's findings get, so a session written by hand
|
|
104
|
+
// cannot bring in more or longer findings than a model could.
|
|
105
|
+
function bounded(findings) {
|
|
106
|
+
return findings.slice(0, MAX_FINDINGS_PER_TASK).map(({ reported, model }) => ({
|
|
107
|
+
reported: boundFinding(reported),
|
|
108
|
+
...(model === undefined ? {} : { model }),
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
async function readEvents(path, runId) {
|
|
112
|
+
try {
|
|
113
|
+
return await readBoundedFile(path, { maxBytes: MAX_EVENTS_BYTES, followLinks: false });
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (error instanceof OcraError) {
|
|
117
|
+
throw new OcraError(error.code, `--resume: the session log of ${runId}: ${error.message}`, {
|
|
118
|
+
cause: error,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
throw new OcraError("INPUT_INVALID", `--resume: no session log for run ${runId}: ${errorMessage(error)}`, { cause: error });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Like the writer, follow no link planted in the reviewed tree to make
|
|
125
|
+
// another directory read as this run's.
|
|
126
|
+
async function refuseLink(path, runId) {
|
|
127
|
+
const info = await lstat(path).catch(() => undefined);
|
|
128
|
+
if (info?.isSymbolicLink()) {
|
|
129
|
+
throw new OcraError("ACCESS_DENIED", `--resume: the session of ${runId} is reached through the symbolic link ${path}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const SEAL_KEY: RegExp;
|
|
2
|
+
/** The serialized JSON object with its seal as a last field. */
|
|
3
|
+
export declare function sealLine(key: string, runId: string, line: string): string;
|
|
4
|
+
/** The line as it was before sealing; undefined unless key sealed it for this run. */
|
|
5
|
+
export declare function unsealLine(key: string, runId: string, sealed: string): string | undefined;
|