@olegkoval/agent-skills 1.83.0 → 1.84.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/adapters/claude/olko-github-pr/skills/lekker-review/SKILL.md +13 -3
- package/adapters/claude/olko-github-pr/skills/lekker-review/references/boundary-evidence.md +73 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/references/codex-workflow.md +5 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/references/defect-evaluation.md +82 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/references/evidence-efficiency-ablation.md +59 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-probe-contract.mjs +33 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-probe-runner.mjs +92 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-probe.mjs +22 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-report.mjs +2 -2
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-source.mjs +3 -2
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-validation.mjs +97 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/evidence-bundle.mjs +30 -13
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/evidence-packet.mjs +74 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/stage-ledger.mjs +96 -0
- package/package.json +1 -1
- package/plugins/olko-apple-kit/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-creative/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-garmin-kit/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-git-tools/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-github-pr/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-github-pr/skills/lekker-review/SKILL.md +13 -3
- package/plugins/olko-github-pr/skills/lekker-review/references/boundary-evidence.md +73 -0
- package/plugins/olko-github-pr/skills/lekker-review/references/codex-workflow.md +5 -0
- package/plugins/olko-github-pr/skills/lekker-review/references/defect-evaluation.md +82 -0
- package/plugins/olko-github-pr/skills/lekker-review/references/evidence-efficiency-ablation.md +59 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-probe-contract.mjs +33 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-probe-runner.mjs +92 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-probe.mjs +22 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-report.mjs +2 -2
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-source.mjs +3 -2
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-validation.mjs +97 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/evidence-bundle.mjs +30 -13
- package/plugins/olko-github-pr/skills/lekker-review/scripts/evidence-packet.mjs +74 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/stage-ledger.mjs +96 -0
- package/plugins/olko-obsidian/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-product/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-reflection/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-release/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-skill-meta/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-web-ops/.claude-plugin/plugin.json +1 -1
|
@@ -696,10 +696,20 @@ helper before assembling context. Never run a copy from the reviewed worktree:
|
|
|
696
696
|
```sh
|
|
697
697
|
node "<SKILL_ROOT>/scripts/evidence-bundle.mjs" \
|
|
698
698
|
--worktree "<scratchpad>/worktree.json" > "<scratchpad>/evidence-bundle.json"
|
|
699
|
-
jq 'del(.git.diff.text, .lint.report)' "<scratchpad>/evidence-bundle.json" \
|
|
699
|
+
jq 'del(.git.diff.text, .lint.report, .boundary.report.results)' "<scratchpad>/evidence-bundle.json" \
|
|
700
700
|
> "<scratchpad>/static-evidence.json"
|
|
701
701
|
```
|
|
702
702
|
|
|
703
|
+
Boundary probes are optional and remain off unless the operator explicitly
|
|
704
|
+
opts in with `--trusted-boundary-opt-in`, `--boundary-config`, and
|
|
705
|
+
`--boundary-out`. The fixed trusted CLI adapter reads only exact base/head
|
|
706
|
+
source from observed Git evidence. Follow
|
|
707
|
+
[`references/boundary-evidence.md`](references/boundary-evidence.md) for the
|
|
708
|
+
local configuration. Include the compact boundary status, provenance, candidate
|
|
709
|
+
summary, and verified reduced failure code with its stderr hash/path in semantic review context. Treat candidates as evidence for
|
|
710
|
+
review; they never create findings or a clean verdict automatically. If opted
|
|
711
|
+
in collection is unavailable, preserve its reason in the bundle.
|
|
712
|
+
|
|
703
713
|
Check each exit status and re-read the JSON. Missing tools, nonzero exits or
|
|
704
714
|
malformed output make this collection unavailable: preserve diagnostics and
|
|
705
715
|
set both context paths below to null. Do not silently pass an empty file.
|
|
@@ -707,8 +717,8 @@ When Git evidence is available, its provenance base/head must match the
|
|
|
707
717
|
review's selected commit pair; a mismatch invalidates the collection, never
|
|
708
718
|
changes the review target. Unavailable Git or lint stays explicitly unknown.
|
|
709
719
|
|
|
710
|
-
The compact view removes
|
|
711
|
-
Keep the full bundle for provenance and detail; semantic review still reads
|
|
720
|
+
The compact view removes duplicate raw diff text, lint report data, and raw
|
|
721
|
+
boundary invocation rows, but retains the reduced failure reference after its raw stderr hash is checked. Keep the full bundle for provenance and detail; semantic review still reads
|
|
712
722
|
DIFF_FILE and existing lint/preflight inputs. Do not replace changedPaths,
|
|
713
723
|
project rules or the mandatory risk check with a different Git diff. Reuse
|
|
714
724
|
available pinned inventory instead of recollecting it in every review agent.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Boundary probe evidence
|
|
2
|
+
|
|
3
|
+
Boundary probing is opt-in. It is not enabled for PRs by default and does not
|
|
4
|
+
accept arbitrary command strings from PR content. The registered Node filename
|
|
5
|
+
operation executes a trusted source captured from the exact base and head
|
|
6
|
+
commits named by observed Git evidence, using a fixed CLI protocol. A repaired
|
|
7
|
+
commit is optional and must be named in the local configuration.
|
|
8
|
+
|
|
9
|
+
Create a local JSON configuration outside the reviewed worktree:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"schema": 1,
|
|
14
|
+
"trustedRoot": "/absolute/path/to/trusted/repository",
|
|
15
|
+
"repoSlug": "agent-skills",
|
|
16
|
+
"seed": 20261108,
|
|
17
|
+
"maxInputs": 32,
|
|
18
|
+
"suffix": "",
|
|
19
|
+
"repairedCommit": "<optional exact 40-character commit SHA>"
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use the existing evidence-bundle helper with explicit local consent:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
node "<SKILL_ROOT>/scripts/evidence-bundle.mjs" \
|
|
27
|
+
--worktree "<scratchpad>/worktree.json" \
|
|
28
|
+
--trusted-boundary-opt-in \
|
|
29
|
+
--boundary-config "<local-config.json>" \
|
|
30
|
+
--boundary-out "<scratchpad>/boundary-artifacts"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The adapter independently recollects Git evidence and requires the fixed
|
|
34
|
+
`run-log.mjs` path in the observed changed-path list. It observes the filesystem
|
|
35
|
+
component limit in the output filesystem, uses only nonempty ASCII slug inputs,
|
|
36
|
+
and accepts 8–88 generated inputs (plus bounded reduction) per run, never more
|
|
37
|
+
than 100 invocations per source, with a five-second invocation timeout.
|
|
38
|
+
The generated report records the seed, full inputs and hashes, exact source
|
|
39
|
+
commits and hashes, adapter/generator hashes, Node version, exit codes, and raw
|
|
40
|
+
stdout/stderr artifact paths. An error, timeout, stale identity, invalid input,
|
|
41
|
+
missing file, hash mismatch, or exhausted reduction budget is unavailable. The
|
|
42
|
+
trusted CLI runs with a minimal environment in a temporary working/state
|
|
43
|
+
directory; this is not an operating-system filesystem sandbox, so only opt in
|
|
44
|
+
for code already trusted by the operator.
|
|
45
|
+
|
|
46
|
+
The reduced candidate's raw stderr is rehashed before its fixed `ENAMETOOLONG`
|
|
47
|
+
failure code and stderr hash/path enter the compact reviewer packet. A missing,
|
|
48
|
+
changed, or escaping stderr artifact makes the boundary capture unavailable.
|
|
49
|
+
The evidence is a composed trusted CLI probe. A passing reproduction is an
|
|
50
|
+
evidence candidate for human semantic review, never an automatic finding or a
|
|
51
|
+
clean verdict. The compact reviewer context retains status, provenance, and
|
|
52
|
+
candidate/minimal-input summaries while raw runs remain in the full bundle.
|
|
53
|
+
# Explicit filename adapter
|
|
54
|
+
|
|
55
|
+
Boundary probing stays opt-in. The current adapter can be pointed at a changed
|
|
56
|
+
repository-relative Node module with `sourcePath` and the fixed
|
|
57
|
+
`node-fs.mkdtempSync.filename` operation. It still invokes only the built-in
|
|
58
|
+
`start` CLI protocol; configuration cannot supply commands. Applicability is
|
|
59
|
+
manual: no automatic AST or data-flow detection is claimed. Inputs are
|
|
60
|
+
nonempty ASCII target slugs; UTF-8 target generation is unsupported. The
|
|
61
|
+
independent property is that each valid target produces a component within the
|
|
62
|
+
observed filesystem byte limit. Full stdout/stderr, pinned source bytes,
|
|
63
|
+
invocation outcomes, and the reduced witness remain in the audit report.
|
|
64
|
+
|
|
65
|
+
## Shadow evidence projection
|
|
66
|
+
|
|
67
|
+
`evidence-packet.mjs` projects selected changed-path patches, matching lint
|
|
68
|
+
diagnostics, and the compact boundary witness from a saved full bundle. Pass the
|
|
69
|
+
full bundle's independently recorded SHA-256, dimension, and exact changed paths.
|
|
70
|
+
The packet stays separate from the immutable bundle, rejects hash mismatch,
|
|
71
|
+
and fails closed when its byte budget is exceeded. It is opt-in shadow output;
|
|
72
|
+
omitted paths and diagnostics remain explicit gaps, and every consumer must
|
|
73
|
+
still review the whole diff.
|
|
@@ -84,6 +84,11 @@ bounded task:
|
|
|
84
84
|
stale/unavailable facts to the coordinator rather than silently retargeting
|
|
85
85
|
or recollecting them per agent. It does not replace semantic investigation,
|
|
86
86
|
the authoritative diff, or required schema/completion/verification gates.
|
|
87
|
+
If opted-in static evidence contains boundary data, inspect its capture status,
|
|
88
|
+
source provenance, candidate/reduced-input summary, and verified reduced failure
|
|
89
|
+
code with its stderr hash/path as evidence only. An
|
|
90
|
+
unavailable probe stays unknown; a candidate never creates a finding or clean
|
|
91
|
+
verdict without semantic verification.
|
|
87
92
|
3. Review only the target diff. Do not edit files, run git writes, post to
|
|
88
93
|
GitHub, or communicate externally.
|
|
89
94
|
4. Write the shared result contract to
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Defect-aware evaluation
|
|
2
|
+
|
|
3
|
+
The existing `eval-runner.mjs` mode remains a location-based legacy heuristic.
|
|
4
|
+
Use `--defects` only for a local, human-approved frozen corpus with reproduced
|
|
5
|
+
defect contracts. It reads data files and never executes reviewed PR code.
|
|
6
|
+
|
|
7
|
+
## Inputs
|
|
8
|
+
|
|
9
|
+
The manifest records full commit identities, expected runs, and defect contracts:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"schema": 1,
|
|
14
|
+
"defects": [{
|
|
15
|
+
"id": "DEFECT-1",
|
|
16
|
+
"contract": "Supported long run targets must create an archive without ENAMETOOLONG.",
|
|
17
|
+
"reproductionEvidence": "oracle/reproduction.md"
|
|
18
|
+
}],
|
|
19
|
+
"cases": [{
|
|
20
|
+
"id": "case-buggy",
|
|
21
|
+
"headSha": "<40-character commit SHA>",
|
|
22
|
+
"expectedDefects": ["DEFECT-1"],
|
|
23
|
+
"expectedRuns": 1
|
|
24
|
+
}]
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Each results entry carries the completed run identity and the exact findings JSON
|
|
29
|
+
bytes as a string. The evaluator hashes the UTF-8 bytes; formatting changes
|
|
30
|
+
therefore invalidate the adjudication. Include a row for every expected run.
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{"runs":[{"caseId":"case-buggy","runId":"review-001","status":"completed",
|
|
34
|
+
"headSha":"<same full SHA>","findingsBytes":"[{\"file\":\"src/a.js\",\"line\":3,\"severity\":\"important\"}]"}]}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Adjudication is separate from the findings and binds the exact run, commit, and
|
|
38
|
+
finding bytes. Every finding index needs exactly one verdict, rationale, and
|
|
39
|
+
evidence reference. A confirmed verdict also needs a defect ID; use a new ID for
|
|
40
|
+
a candidate defect not yet in the registry.
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{"evaluations":[{"runId":"review-001","headSha":"<same full SHA>",
|
|
44
|
+
"findingsSha256":"<64-character SHA-256>","decisions":[
|
|
45
|
+
{"findingIndex":0,"verdict":"confirmed","defectId":"DEFECT-1",
|
|
46
|
+
"rationale":"Matches the reproduction contract","evidence":"adjudication/DEFECT-1.md"}]}]}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Run the opt-in scorer:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
node "${SKILL_ROOT}/scripts/eval-runner.mjs" --defects \
|
|
53
|
+
--manifest <manifest.json> --results <defect-runs.json> \
|
|
54
|
+
--adjudication <adjudication.json>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Reading the result
|
|
58
|
+
|
|
59
|
+
`available` and `coverageComplete` must both be true before treating corpus
|
|
60
|
+
metrics as complete. Missing, duplicate, malformed, unresolved, or mismatched
|
|
61
|
+
evidence keeps coverage unavailable. A newly confirmed defect remains visible
|
|
62
|
+
but requires corpus adjudication and is not added to the recall denominator.
|
|
63
|
+
|
|
64
|
+
- Recall is expected defect IDs detected, deduplicated once per case run.
|
|
65
|
+
- Precision is confirmed finding decisions divided by confirmed plus false-alarm
|
|
66
|
+
finding decisions. Repeated claims count here because each finding is a
|
|
67
|
+
separate decision; `uniqueConfirmedDefects` reports deduplicated IDs.
|
|
68
|
+
- False alarms are explicit adjudications, not inferred from severity.
|
|
69
|
+
- False alarms per review and clean alarm rate use fully adjudicated runs.
|
|
70
|
+
- `distinctCases` counts case IDs represented; it does not claim statistical
|
|
71
|
+
independence between related cases.
|
|
72
|
+
- Empty precision or recall denominators are `null`, never zero.
|
|
73
|
+
|
|
74
|
+
## Measurement protocol
|
|
75
|
+
|
|
76
|
+
Evaluate only previously unseen cases with frozen base, buggy, and fixed commits
|
|
77
|
+
and a reproduced contract for each known defect. Hide arm identity and version
|
|
78
|
+
labels from adjudicators; provide the finding text and contract needed to judge
|
|
79
|
+
each claim. Randomize paired case/version order. Record cost for all agents and
|
|
80
|
+
retries in both arms. Report missing
|
|
81
|
+
coverage and unresolved judgments. This harness does not establish a benefit
|
|
82
|
+
claim; that requires a completed, blinded comparison over the frozen protocol.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Evidence projection ablation: preregistration draft
|
|
2
|
+
|
|
3
|
+
This is a future experiment design only. Do not run it as part of implementation.
|
|
4
|
+
The four-case 2026-11-08 screen failed promotion and its cases are now known
|
|
5
|
+
development fixtures. Freeze a new holdout before any model call.
|
|
6
|
+
|
|
7
|
+
## Arms and scope
|
|
8
|
+
|
|
9
|
+
- Baseline: the assigned dimension reviewer receives the full immutable evidence
|
|
10
|
+
bundle and the same review inputs as today.
|
|
11
|
+
- Projection: that reviewer receives the deterministic, hash-verified packet
|
|
12
|
+
for its assigned dimension. A whole-diff safety pass receives the same full
|
|
13
|
+
diff in both arms; its reviewer count, prompt, proof policy, and routing stay
|
|
14
|
+
fixed. Omitted packet context is never marked reviewed.
|
|
15
|
+
- Use the same pinned model, effort, tools, prompts, timeout, and retry policy in
|
|
16
|
+
both arms. Run one case-arm at a time; alternate arm order within each pair.
|
|
17
|
+
|
|
18
|
+
## Corpus and procedure
|
|
19
|
+
|
|
20
|
+
Freeze at least 30 independent PR-level pairs from at least three repositories,
|
|
21
|
+
covering three or more defect families. Prefer real bug-introducing commits and
|
|
22
|
+
their repairs; include safe controls and near-boundary changes with explicit
|
|
23
|
+
contracts. Keep root causes and repositories disjoint from packet-development
|
|
24
|
+
fixtures. Record base/head SHAs, contracts, valid-input assumptions, expected
|
|
25
|
+
findings, and immutable source hashes before unblinding. Adjudicators see claims
|
|
26
|
+
and evidence without the arm label.
|
|
27
|
+
|
|
28
|
+
Run three paired repetitions per PR with counterbalanced order and no retries.
|
|
29
|
+
The PR is the sampling unit; repetitions are nested observations, not new PRs.
|
|
30
|
+
Record every reviewer, coordinator, and verification session once from explicit
|
|
31
|
+
saved manifests, plus measured setup/adjudication minutes. Preserve cached,
|
|
32
|
+
uncached, total input, and output tokens separately. Record elapsed observations
|
|
33
|
+
separately; do not sum overlapping durations or convert token sums to currency.
|
|
34
|
+
The primary all-in cost uses invoice-backed provider charges plus a frozen
|
|
35
|
+
hourly rate for measured setup, coordination, adjudication, and verification.
|
|
36
|
+
Freeze provider rates, currency, and labor rate before collection. If charges or
|
|
37
|
+
labor measurements are unavailable, report the resource vector and leave the
|
|
38
|
+
cost endpoint unavailable; do not promote on token totals alone.
|
|
39
|
+
|
|
40
|
+
## Analysis and stop rules
|
|
41
|
+
|
|
42
|
+
Before collection, freeze the smallest worthwhile all-in cost reduction, the
|
|
43
|
+
defect-recall non-inferiority margin, a hard review-cost ceiling, and the
|
|
44
|
+
maximum sample size. Report paired PR-level differences and 95% cluster
|
|
45
|
+
bootstrap intervals, resampling PRs while keeping their repetitions together.
|
|
46
|
+
Include false alarms, duplicate claims, unavailable evidence, packet bytes, all
|
|
47
|
+
review/coordinator/verification usage, and manual time. Byte reduction is a
|
|
48
|
+
mechanism check, not the efficiency endpoint.
|
|
49
|
+
|
|
50
|
+
Stop immediately on cross-tenant/data exposure, a missed critical defect, stale
|
|
51
|
+
provenance accepted as available, or budget exhaustion. Otherwise evaluate at
|
|
52
|
+
30 pairs; add only the predeclared next batch when intervals are too wide, up to
|
|
53
|
+
the frozen maximum. Promote only if the cost interval clears the worthwhile
|
|
54
|
+
effect and the recall interval stays within its safety margin. Otherwise retain
|
|
55
|
+
shadow mode and report the result as inconclusive or failed.
|
|
56
|
+
|
|
57
|
+
No sample-size or quality claim is supported by the existing four-case screen.
|
|
58
|
+
The coordinator must approve the frozen corpus, thresholds, and spend ceiling
|
|
59
|
+
before this experiment is launched.
|
package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-probe-contract.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
|
|
5
|
+
const HELPER_MODULES = Object.freeze(['boundary-cases.mjs', 'boundary-filesystem.mjs', 'boundary-invocation.mjs', 'boundary-probe-contract.mjs', 'boundary-probe-runner.mjs', 'boundary-report.mjs', 'boundary-source.mjs', 'boundary-validation.mjs', 'git-evidence.mjs'])
|
|
6
|
+
const sha256 = value => createHash('sha256').update(value).digest('hex')
|
|
7
|
+
|
|
8
|
+
export const unavailable = reason => ({ schema: 1, status: 'unavailable', reason, candidates: [] })
|
|
9
|
+
|
|
10
|
+
export function observedChangedPath(bundle, source) {
|
|
11
|
+
return bundle?.git?.status === 'available' && Array.isArray(bundle.git.changedPaths)
|
|
12
|
+
&& bundle.git.changedPaths.includes(source) && /^[a-f0-9]{40,64}$/.test(bundle.git.provenance?.baseSha ?? '')
|
|
13
|
+
&& /^[a-f0-9]{40,64}$/.test(bundle.git.provenance?.headSha ?? '')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function validProbeConfig(config) {
|
|
17
|
+
return config && typeof config === 'object' && !Array.isArray(config) && config.schema === 1
|
|
18
|
+
&& typeof config.trustedRoot === 'string' && typeof config.repoSlug === 'string'
|
|
19
|
+
&& /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(config.repoSlug)
|
|
20
|
+
&& (config.suffix === undefined || typeof config.suffix === 'string') && /^[a-z0-9]*$/.test(config.suffix ?? '')
|
|
21
|
+
&& (config.inputKind === undefined || config.inputKind === 'ascii')
|
|
22
|
+
&& (config.sourcePath === undefined && config.operation === undefined && config.expectedProperty === undefined
|
|
23
|
+
|| typeof config.sourcePath === 'string' && /^(?:[A-Za-z0-9._-]+\/)*[A-Za-z0-9._-]+\.mjs$/.test(config.sourcePath)
|
|
24
|
+
&& config.operation === 'node-fs.mkdtempSync.filename'
|
|
25
|
+
&& config.expectedProperty === 'valid ASCII targets produce a component within the observed byte limit')
|
|
26
|
+
&& Number.isSafeInteger(config.seed)
|
|
27
|
+
&& (config.maxInputs === undefined || Number.isSafeInteger(config.maxInputs) && config.maxInputs >= 8 && config.maxInputs <= 88)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function hashBoundaryHelpers(adapterUrl) {
|
|
31
|
+
return Object.fromEntries(HELPER_MODULES.map(name => [name,
|
|
32
|
+
sha256(readFileSync(fileURLToPath(new URL(`./${name}`, adapterUrl))))]))
|
|
33
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { join, resolve } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { observeComponentLimit } from './boundary-filesystem.mjs'
|
|
6
|
+
import { runTrustedCli } from './boundary-invocation.mjs'
|
|
7
|
+
import { generateBoundaryCases } from './boundary-cases.mjs'
|
|
8
|
+
import { assembleBoundaryReport, isBoundaryCandidate } from './boundary-report.mjs'
|
|
9
|
+
import { readTrustedSource, RUN_LOG_SOURCE } from './boundary-source.mjs'
|
|
10
|
+
import { hashBoundaryHelpers, observedChangedPath, unavailable, validProbeConfig } from './boundary-probe-contract.mjs'
|
|
11
|
+
import { collectGitEvidence } from './git-evidence.mjs'
|
|
12
|
+
|
|
13
|
+
const sha256 = value => createHash('sha256').update(value).digest('hex')
|
|
14
|
+
|
|
15
|
+
export function runBoundaryProbe({ config, worktreePath, mergeBase, headSha, outputDir, optIn = false }) {
|
|
16
|
+
if (!optIn) return unavailable('explicit trusted-probe opt-in is required')
|
|
17
|
+
const sourcePath = config?.sourcePath ?? RUN_LOG_SOURCE
|
|
18
|
+
const git = collectGitEvidence({ worktreePath, mergeBase, headSha })
|
|
19
|
+
const evidenceBundle = { git }
|
|
20
|
+
if (!observedChangedPath(evidenceBundle, sourcePath)) return unavailable('trusted adapter path is absent from observed Git changed paths')
|
|
21
|
+
if (!validProbeConfig(config)) {
|
|
22
|
+
return unavailable('trusted adapter configuration is missing or malformed')
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const root = resolve(config.trustedRoot)
|
|
26
|
+
const out = resolve(outputDir)
|
|
27
|
+
if (existsSync(out)) throw new Error('output directory already exists; refusing to overwrite evidence')
|
|
28
|
+
mkdirSync(out, { recursive: false })
|
|
29
|
+
const componentLimit = observeComponentLimit(out)
|
|
30
|
+
if (config.maxComponentBytes !== undefined && config.maxComponentBytes !== componentLimit) throw new Error('configured component limit differs from observed filesystem limit')
|
|
31
|
+
const provenance = evidenceBundle.git.provenance
|
|
32
|
+
const commits = { original: provenance.baseSha, defective: provenance.headSha,
|
|
33
|
+
...(config.repairedCommit ? { repaired: config.repairedCommit } : {}) }
|
|
34
|
+
const roles = Object.keys(commits)
|
|
35
|
+
const sources = Object.fromEntries(roles.map(role => [role, readTrustedSource(root, commits[role], sourcePath)]))
|
|
36
|
+
const internalPrefix = `${'0'.repeat(15)}-${config.repoSlug}-`
|
|
37
|
+
const cases = generateBoundaryCases({ seed: config.seed, limit: componentLimit,
|
|
38
|
+
prefix: internalPrefix, suffix: config.suffix ?? '', count: config.maxInputs ?? 32, kinds: ['ascii'] })
|
|
39
|
+
.filter(item => /^[a-z0-9-]+$/.test(item.input))
|
|
40
|
+
const suffixBytes = Buffer.byteLength(config.suffix ?? '')
|
|
41
|
+
const room = componentLimit - Buffer.byteLength(internalPrefix) - suffixBytes
|
|
42
|
+
const requiredLengths = [room - 1 + suffixBytes, room + suffixBytes, room + 1 + suffixBytes]
|
|
43
|
+
if (cases.length > 88 || requiredLengths.some(length => !cases.some(item => item.inputBytes === length))) {
|
|
44
|
+
throw new Error('insufficient boundary coverage or input budget leaves no room for bounded reduction')
|
|
45
|
+
}
|
|
46
|
+
for (const [role, source] of Object.entries(sources)) writeFileSync(join(out, `${role}.source.mjs`), source.bytes)
|
|
47
|
+
const results = cases.map(item => {
|
|
48
|
+
const runs = Object.fromEntries(Object.entries(sources).map(([role, source]) => [role,
|
|
49
|
+
runTrustedCli({ source, target: item.input, repoSlug: config.repoSlug, outputDir: out, id: `${item.id}-${role}` })]))
|
|
50
|
+
return { id: item.id, kind: item.kind, input: item.input, inputSha256: item.inputSha256,
|
|
51
|
+
inputBytes: item.inputBytes, prefix: internalPrefix, suffix: config.suffix ?? '',
|
|
52
|
+
status: item.status, artifactRoot: out, runs }
|
|
53
|
+
})
|
|
54
|
+
const shrinkResults = []
|
|
55
|
+
let reduced = null
|
|
56
|
+
const firstCandidate = results.find(isBoundaryCandidate)
|
|
57
|
+
if (firstCandidate) {
|
|
58
|
+
let low = 0, high = firstCandidate.input.length, best = firstCandidate
|
|
59
|
+
for (let step = 0; step < 10 && high - low > 1 && results.length + shrinkResults.length < 100; step += 1) {
|
|
60
|
+
const middle = Math.floor((low + high) / 2), input = firstCandidate.input.slice(0, middle)
|
|
61
|
+
const runs = Object.fromEntries(Object.entries(sources).map(([role, source]) => [role,
|
|
62
|
+
runTrustedCli({ source, target: input, repoSlug: config.repoSlug, outputDir: out, id: `shrink-${step}-${role}` })]))
|
|
63
|
+
const row = { id: `shrink-${step}`, kind: 'ascii', input, inputSha256: sha256(input), inputBytes: Buffer.byteLength(input),
|
|
64
|
+
prefix: internalPrefix, suffix: config.suffix ?? '', status: 'available', artifactRoot: out, runs }
|
|
65
|
+
shrinkResults.push(row)
|
|
66
|
+
if (isBoundaryCandidate(row)) { high = middle; best = row } else low = middle
|
|
67
|
+
}
|
|
68
|
+
if (high - low > 1) throw new Error('bounded counterexample reduction exhausted invocation coverage')
|
|
69
|
+
reduced = best
|
|
70
|
+
}
|
|
71
|
+
const report = assembleBoundaryReport({ source: sourcePath,
|
|
72
|
+
provenance: { trustedRoot: root, repoSlug: config.repoSlug,
|
|
73
|
+
baseSha: provenance.baseSha, headSha: provenance.headSha,
|
|
74
|
+
sources: Object.fromEntries(Object.entries(sources).map(([role, source]) => [role,
|
|
75
|
+
{ commit: source.commit, sha256: source.sha256 }])) },
|
|
76
|
+
seed: config.seed, componentLimit, prefixSha256: sha256(internalPrefix),
|
|
77
|
+
suffixSha256: sha256(config.suffix ?? ''), cases, results, shrinkResults, outputDir: out, reduced })
|
|
78
|
+
report.contract = { ...report.contract, operation: config.operation ?? 'node-fs.mkdtempSync.filename',
|
|
79
|
+
expectedProperty: config.expectedProperty ?? 'valid ASCII targets produce a component within the observed byte limit',
|
|
80
|
+
generator: 'seeded ASCII slug boundary lengths with bounded binary shrink',
|
|
81
|
+
applicability: 'source path must appear in observed changed paths', invocationBudget: { inputs: config.maxInputs ?? 32, shrinkSteps: 10, timeoutMs: 5000 } }
|
|
82
|
+
report.provenance.adapterSha256 = sha256(readFileSync(fileURLToPath(new URL('./boundary-probe.mjs', import.meta.url))))
|
|
83
|
+
report.provenance.generatorSha256 = sha256(readFileSync(fileURLToPath(new URL('./boundary-cases.mjs', import.meta.url))))
|
|
84
|
+
report.provenance.moduleSha256 = hashBoundaryHelpers(import.meta.url)
|
|
85
|
+
report.provenance.runtime = process.version
|
|
86
|
+
const bytes = Buffer.from(JSON.stringify(report, null, 2) + '\n')
|
|
87
|
+
writeFileSync(join(out, 'boundary-report.json'), bytes)
|
|
88
|
+
return { ...report, reportSha256: sha256(bytes), reportFile: join(out, 'boundary-report.json') }
|
|
89
|
+
} catch (error) {
|
|
90
|
+
return unavailable(`trusted boundary probe failed: ${error.message}`)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { runBoundaryProbe } from './boundary-probe-runner.mjs'
|
|
4
|
+
import { unavailable } from './boundary-probe-contract.mjs'
|
|
5
|
+
|
|
6
|
+
function main(argv) {
|
|
7
|
+
const flag = name => { const index = argv.indexOf(`--${name}`); return index < 0 ? null : argv[index + 1] }
|
|
8
|
+
const configPath = flag('config'), worktreePath = flag('worktree'), outputDir = flag('out')
|
|
9
|
+
if (!argv.includes('--trusted-opt-in') || !configPath || !worktreePath || !outputDir) {
|
|
10
|
+
console.error('usage: boundary-probe.mjs --trusted-opt-in --config <trusted.json> --worktree <worktree.json> --out <directory>')
|
|
11
|
+
process.exitCode = 2; return
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const metadata = JSON.parse(readFileSync(worktreePath, 'utf8'))
|
|
15
|
+
const report = runBoundaryProbe({ config: JSON.parse(readFileSync(configPath, 'utf8')),
|
|
16
|
+
worktreePath: metadata.worktreePath, mergeBase: metadata.mergeBase, headSha: metadata.headSha, outputDir, optIn: true })
|
|
17
|
+
console.log(JSON.stringify(report))
|
|
18
|
+
if (report.status !== 'available') process.exitCode = 1
|
|
19
|
+
} catch { console.log(JSON.stringify(unavailable('probe input could not be read'))); process.exitCode = 2 }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) main(process.argv.slice(2))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
export function isBoundaryCandidate(row) {
|
|
2
2
|
const original = row.runs?.original, defective = row.runs?.defective, repaired = row.runs?.repaired
|
|
3
3
|
return original?.status === 'observed' && defective?.status === 'observed'
|
|
4
4
|
&& original.exitClass === 'success' && defective.exitClass === 'component-limit'
|
|
@@ -8,7 +8,7 @@ function isCandidate(row) {
|
|
|
8
8
|
export function assembleBoundaryReport({ source, provenance, seed, componentLimit, prefixSha256, suffixSha256,
|
|
9
9
|
cases, results, shrinkResults, outputDir, reduced }) {
|
|
10
10
|
const allResults = [...results, ...shrinkResults]
|
|
11
|
-
const candidates = allResults.filter(
|
|
11
|
+
const candidates = allResults.filter(isBoundaryCandidate).map(row => ({ id: row.id, input: row.input,
|
|
12
12
|
evidenceClass: 'composed trusted CLI probe', inputSha256: row.inputSha256,
|
|
13
13
|
outcomes: Object.fromEntries(Object.entries(row.runs).map(([role, result]) => [role, result.exitCode])) }))
|
|
14
14
|
const roles = ['original', 'defective', ...(provenance?.sources?.repaired ? ['repaired'] : [])]
|
|
@@ -4,8 +4,9 @@ import { execFileSync } from 'node:child_process'
|
|
|
4
4
|
export const RUN_LOG_SOURCE = 'plugins/olko-github-pr/skills/lekker-review/scripts/run-log.mjs'
|
|
5
5
|
const gitEnv = { PATH: '/usr/bin:/bin', HOME: '/nonexistent', GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null' }
|
|
6
6
|
|
|
7
|
-
export function readTrustedSource(root, commit) {
|
|
7
|
+
export function readTrustedSource(root, commit, sourcePath = RUN_LOG_SOURCE) {
|
|
8
8
|
if (!/^[a-f0-9]{40}$/.test(commit ?? '')) throw new Error('trusted source needs an exact commit SHA')
|
|
9
|
+
if (typeof sourcePath !== 'string' || sourcePath.startsWith('/') || sourcePath.split('/').some(part => !part || part === '.' || part === '..')) throw new Error('trusted source path must be repository-relative')
|
|
9
10
|
let resolved
|
|
10
11
|
try {
|
|
11
12
|
resolved = execFileSync('git', ['--no-replace-objects', '-C', root, 'rev-parse', '--verify', `${commit}^{commit}`], {
|
|
@@ -14,7 +15,7 @@ export function readTrustedSource(root, commit) {
|
|
|
14
15
|
} catch { throw new Error('trusted commit is unavailable') }
|
|
15
16
|
if (resolved !== commit) throw new Error('trusted commit did not resolve exactly')
|
|
16
17
|
let bytes
|
|
17
|
-
try { bytes = execFileSync('git', ['--no-replace-objects', '-C', root, 'show', `${resolved}:${
|
|
18
|
+
try { bytes = execFileSync('git', ['--no-replace-objects', '-C', root, 'show', `${resolved}:${sourcePath}`], { env: gitEnv, stdio: ['ignore', 'pipe', 'ignore'] }) }
|
|
18
19
|
catch { throw new Error('trusted CLI source is unavailable at the pinned commit') }
|
|
19
20
|
return { commit: resolved, bytes, sha256: createHash('sha256').update(bytes).digest('hex') }
|
|
20
21
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, relative, isAbsolute } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const record = value => value && typeof value === 'object' && !Array.isArray(value);
|
|
6
|
+
const fullSha = value => typeof value === 'string' && /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(value);
|
|
7
|
+
const digest = value => typeof value === 'string' && /^[a-f0-9]{64}$/.test(value);
|
|
8
|
+
const sha256 = value => createHash('sha256').update(value).digest('hex');
|
|
9
|
+
const MODULES = ['boundary-cases.mjs', 'boundary-filesystem.mjs', 'boundary-invocation.mjs',
|
|
10
|
+
'boundary-probe-contract.mjs', 'boundary-probe-runner.mjs', 'boundary-report.mjs', 'boundary-source.mjs', 'boundary-validation.mjs', 'git-evidence.mjs'];
|
|
11
|
+
|
|
12
|
+
export function validateBoundaryReport(probe, git) {
|
|
13
|
+
try {
|
|
14
|
+
if (probe?.status !== 'available' || typeof probe.reportFile !== 'string') return { captureStatus: 'unavailable', reason: probe?.reason ?? 'trusted boundary probe unavailable' };
|
|
15
|
+
const bytes = readFileSync(probe.reportFile), digestValue = createHash('sha256').update(bytes).digest('hex');
|
|
16
|
+
const report = JSON.parse(bytes.toString('utf8'));
|
|
17
|
+
const invalid = validateShape(report, git);
|
|
18
|
+
if (digestValue !== probe.reportSha256 || invalid) return { captureStatus: 'unavailable', reason: invalid ?? 'boundary artifact hash mismatch' };
|
|
19
|
+
const reducedFailure = readReducedFailure(report, probe.reportFile);
|
|
20
|
+
return { captureStatus: 'available', reportPath: probe.reportFile, reportSha256: digestValue,
|
|
21
|
+
provenance: report.provenance, summary: { candidateCount: report.candidates.length,
|
|
22
|
+
inputCount: report.results.length, evidenceClass: 'composed trusted CLI probe',
|
|
23
|
+
...(reducedFailure ? { reducedFailure } : {}) }, report };
|
|
24
|
+
} catch { return { captureStatus: 'unavailable', reason: 'trusted boundary artifact is missing or malformed' }; }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function readReducedFailure(report, reportFile) {
|
|
28
|
+
if (!report.reducedCounterexample) return null;
|
|
29
|
+
const row = report.results.find(result => result.id === report.reducedCounterexample.id);
|
|
30
|
+
const run = row.runs.defective;
|
|
31
|
+
const root = realpathSync(dirname(reportFile));
|
|
32
|
+
if (realpathSync(report.artifactRoot) !== root || run.stderrFile !== `${row.id}-defective/stderr.raw`) throw new Error('invalid boundary artifact path');
|
|
33
|
+
const path = realpathSync(join(root, run.stderrFile)), inside = relative(root, path);
|
|
34
|
+
if (!inside || inside.startsWith('..') || isAbsolute(inside)) throw new Error('boundary artifact escaped output directory');
|
|
35
|
+
const stderr = readFileSync(path);
|
|
36
|
+
if (sha256(stderr) !== run.stderrSha256 || !stderr.includes('ENAMETOOLONG')) throw new Error('boundary stderr does not support failure class');
|
|
37
|
+
return { caseId: row.id, exitClass: run.exitClass, failureCode: 'ENAMETOOLONG',
|
|
38
|
+
stderrFile: run.stderrFile, stderrSha256: run.stderrSha256 };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function validRun(run) {
|
|
42
|
+
if (!record(run) || run.status !== 'observed' || !digest(run.stdoutSha256) || !digest(run.stderrSha256)
|
|
43
|
+
|| typeof run.stdoutFile !== 'string' || typeof run.stderrFile !== 'string') return false;
|
|
44
|
+
return run.exitClass === 'success' && run.exitCode === 0 || run.exitClass === 'component-limit' && run.exitCode === 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function defectCandidate(row) {
|
|
48
|
+
return row.runs.original.exitClass === 'success' && row.runs.defective.exitClass === 'component-limit'
|
|
49
|
+
&& (!row.runs.repaired || row.runs.repaired.exitClass === 'success');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function validateShape(report, git) {
|
|
53
|
+
if (!record(report) || report.schema !== 1 || report.status !== 'available' || typeof report.source !== 'string'
|
|
54
|
+
|| report.source.startsWith('/') || report.source.split('/').some(part => !part || part === '.' || part === '..')) return 'boundary report identity is invalid';
|
|
55
|
+
if (git?.status !== 'available' || !Array.isArray(git.changedPaths) || !git.changedPaths.includes(report.source)
|
|
56
|
+
|| report.provenance?.baseSha !== git.provenance?.baseSha || report.provenance?.headSha !== git.provenance?.headSha) return 'boundary report Git identity mismatch';
|
|
57
|
+
if (!Array.isArray(report.results) || report.results.length === 0 || report.results.length > 100
|
|
58
|
+
|| report.contract?.count !== report.results.length || !Number.isSafeInteger(report.contract?.maxComponentBytes)
|
|
59
|
+
|| report.contract.maxComponentBytes < 1 || typeof report.contract.validInput !== 'string'
|
|
60
|
+
|| !Number.isSafeInteger(report.seed) || !Array.isArray(report.candidates)) return 'boundary report coverage is empty, malformed, or over budget';
|
|
61
|
+
if (!fullSha(report.provenance.sources?.original?.commit) || report.provenance.sources.original.commit !== git.provenance.baseSha
|
|
62
|
+
|| !fullSha(report.provenance.sources?.defective?.commit) || report.provenance.sources.defective.commit !== git.provenance.headSha
|
|
63
|
+
|| !digest(report.provenance.sources.original.sha256) || !digest(report.provenance.sources.defective.sha256)
|
|
64
|
+
|| !digest(report.provenance.adapterSha256) || !digest(report.provenance.generatorSha256)
|
|
65
|
+
|| !record(report.provenance.moduleSha256) || Object.keys(report.provenance.moduleSha256).sort().join(',') !== MODULES.slice().sort().join(',')
|
|
66
|
+
|| Object.values(report.provenance.moduleSha256).some(value => !digest(value))
|
|
67
|
+
|| typeof report.provenance.runtime !== 'string' || typeof report.provenance.trustedRoot !== 'string'
|
|
68
|
+
|| !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(report.provenance.repoSlug ?? '')) return 'boundary report source provenance is invalid';
|
|
69
|
+
const roles = report.provenance.sources.repaired ? ['original', 'defective', 'repaired'] : ['original', 'defective'];
|
|
70
|
+
if (roles.includes('repaired') && (!fullSha(report.provenance.sources.repaired.commit) || !digest(report.provenance.sources.repaired.sha256))) return 'boundary repaired source provenance is invalid';
|
|
71
|
+
const ids = report.results.map(row => row?.id);
|
|
72
|
+
if (new Set(ids).size !== ids.length) return 'boundary input identifiers are duplicated';
|
|
73
|
+
for (const row of report.results) {
|
|
74
|
+
if (!record(row) || typeof row.id !== 'string' || !/^[a-z0-9-]+$/.test(row.id)
|
|
75
|
+
|| typeof row.input !== 'string' || !/^[a-z0-9-]+$/.test(row.input)
|
|
76
|
+
|| row.status !== 'available' || row.inputBytes !== Buffer.byteLength(row.input) || row.inputSha256 !== sha256(row.input)) return 'boundary input coverage is invalid';
|
|
77
|
+
if (!record(row.runs) || roles.some(role => !validRun(row.runs[role]))) return 'boundary invocation outcome is incomplete';
|
|
78
|
+
}
|
|
79
|
+
const expected = report.results.filter(defectCandidate).map(row => row.id).sort(), candidates = report.candidates;
|
|
80
|
+
if (expected.length !== candidates.length || new Set(candidates.map(candidate => candidate?.id)).size !== candidates.length) return 'boundary candidate summary does not match observed outcomes';
|
|
81
|
+
if (candidates.some(candidate => {
|
|
82
|
+
const row = report.results.find(result => result.id === candidate?.id);
|
|
83
|
+
return !row || !expected.includes(candidate.id) || candidate.input !== row.input || candidate.inputSha256 !== row.inputSha256
|
|
84
|
+
|| candidate.evidenceClass !== 'composed trusted CLI probe';
|
|
85
|
+
})) return 'boundary candidate identity does not match observed outcomes';
|
|
86
|
+
if (candidates.some(candidate => {
|
|
87
|
+
const row = report.results.find(result => result.id === candidate.id);
|
|
88
|
+
return roles.some(role => candidate.outcomes?.[role] !== row.runs[role].exitCode);
|
|
89
|
+
})) return 'boundary candidate outcomes do not match invocation outcomes';
|
|
90
|
+
const reduced = report.reducedCounterexample;
|
|
91
|
+
if (!candidates.length) return reduced == null ? null : 'boundary reduced input has no candidate';
|
|
92
|
+
const row = report.results.find(result => result.id === reduced?.id);
|
|
93
|
+
if (!record(reduced) || !row || !candidates.some(candidate => candidate.id === row.id)
|
|
94
|
+
|| reduced.input !== row.input || reduced.inputSha256 !== row.inputSha256
|
|
95
|
+
|| roles.some(role => reduced.outcomes?.[role] !== row.runs[role].exitCode)) return 'boundary reduced input does not match observed candidate';
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
@@ -3,36 +3,53 @@ import { readFileSync } from 'node:fs';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { collectGitEvidence } from './git-evidence.mjs';
|
|
5
5
|
import { validateLintReceipt } from './validate-lint-receipt.mjs';
|
|
6
|
+
import { runBoundaryProbe } from './boundary-probe-runner.mjs';
|
|
7
|
+
import { validateBoundaryReport } from './boundary-validation.mjs';
|
|
6
8
|
|
|
7
9
|
const record = value => value && typeof value === 'object' && !Array.isArray(value);
|
|
8
10
|
const unavailableLint = reason => ({ captureStatus: 'unavailable', reason });
|
|
9
11
|
const unavailableBundle = reason => ({ schema: 1,
|
|
10
12
|
git: { schema: 1, status: 'unavailable', reason }, lint: unavailableLint(reason) });
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
if (!
|
|
14
|
+
function collectBoundary(options, git) {
|
|
15
|
+
if (!options?.trustedOptIn) return undefined;
|
|
16
|
+
if (typeof options.configPath !== 'string' || typeof options.outputDir !== 'string') return { captureStatus: 'unavailable', reason: 'trusted opt-in needs a config and output directory' };
|
|
17
|
+
try {
|
|
18
|
+
const config = JSON.parse(readFileSync(options.configPath, 'utf8'));
|
|
19
|
+
const probe = runBoundaryProbe({ config, worktreePath: options.worktreePath, mergeBase: git.provenance.baseSha,
|
|
20
|
+
headSha: git.provenance.headSha, outputDir: options.outputDir, optIn: true });
|
|
21
|
+
return validateBoundaryReport(probe, git);
|
|
22
|
+
} catch { return { captureStatus: 'unavailable', reason: 'trusted boundary artifact is missing or malformed' }; }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function collectEvidence(worktreeMetadata, options = {}) {
|
|
26
|
+
if (!record(worktreeMetadata)) return { ...unavailableBundle('worktree metadata is missing or malformed'),
|
|
27
|
+
...(options.trustedOptIn ? { boundary: { captureStatus: 'unavailable', reason: 'worktree metadata unavailable' } } : {}) };
|
|
14
28
|
const git = collectGitEvidence({ worktreePath: worktreeMetadata.worktreePath,
|
|
15
29
|
mergeBase: worktreeMetadata.mergeBase, headSha: worktreeMetadata.headSha });
|
|
16
|
-
if (git.status !== 'available') return { schema: 1, git, lint: unavailableLint(`Git evidence unavailable: ${git.reason}`) };
|
|
17
|
-
|
|
18
|
-
if (typeof worktreeMetadata.
|
|
30
|
+
if (git.status !== 'available') return { schema: 1, git, lint: unavailableLint(`Git evidence unavailable: ${git.reason}`), ...(options.trustedOptIn ? { boundary: { captureStatus: 'unavailable', reason: 'Git evidence unavailable' } } : {}) };
|
|
31
|
+
const boundary = collectBoundary({ ...options, worktreePath: worktreeMetadata.worktreePath }, git);
|
|
32
|
+
if (typeof worktreeMetadata.eslintJson !== 'string' || !worktreeMetadata.eslintJson) return { schema: 1, git, lint: unavailableLint('lint report path unavailable'), ...(boundary ? { boundary } : {}) };
|
|
33
|
+
if (typeof worktreeMetadata.eslintProvenance !== 'string' || !worktreeMetadata.eslintProvenance) return { schema: 1, git, lint: unavailableLint('lint provenance path unavailable'), ...(boundary ? { boundary } : {}) };
|
|
19
34
|
let reportBytes, receipt;
|
|
20
|
-
try { reportBytes = readFileSync(worktreeMetadata.eslintJson); } catch { return { schema: 1, git, lint: unavailableLint('lint report could not be read') }; }
|
|
21
|
-
try { receipt = JSON.parse(readFileSync(worktreeMetadata.eslintProvenance, 'utf8')); } catch { return { schema: 1, git, lint: unavailableLint('lint provenance is missing or malformed') }; }
|
|
35
|
+
try { reportBytes = readFileSync(worktreeMetadata.eslintJson); } catch { return { schema: 1, git, lint: unavailableLint('lint report could not be read'), ...(boundary ? { boundary } : {}) }; }
|
|
36
|
+
try { receipt = JSON.parse(readFileSync(worktreeMetadata.eslintProvenance, 'utf8')); } catch { return { schema: 1, git, lint: unavailableLint('lint provenance is missing or malformed'), ...(boundary ? { boundary } : {}) }; }
|
|
22
37
|
const provenance = validateLintReceipt(receipt, { baseSha: git.provenance.baseSha,
|
|
23
38
|
headSha: git.provenance.headSha, trackedClean: git.provenance.trackedCleanBefore && git.provenance.trackedCleanAfter }, reportBytes);
|
|
24
|
-
if (provenance.status !== 'available') return { schema: 1, git, lint: unavailableLint(provenance.reason) };
|
|
39
|
+
if (provenance.status !== 'available') return { schema: 1, git, lint: unavailableLint(provenance.reason), ...(boundary ? { boundary } : {}) };
|
|
25
40
|
let report;
|
|
26
|
-
try { report = JSON.parse(reportBytes.toString('utf8')); } catch { return { schema: 1, git, lint: unavailableLint('lint report is malformed JSON') }; }
|
|
27
|
-
if (!Array.isArray(report)) return { schema: 1, git, lint: unavailableLint('lint report is not a JSON array') };
|
|
41
|
+
try { report = JSON.parse(reportBytes.toString('utf8')); } catch { return { schema: 1, git, lint: unavailableLint('lint report is malformed JSON'), ...(boundary ? { boundary } : {}) }; }
|
|
42
|
+
if (!Array.isArray(report)) return { schema: 1, git, lint: unavailableLint('lint report is not a JSON array'), ...(boundary ? { boundary } : {}) };
|
|
28
43
|
return { schema: 1, git, lint: { captureStatus: 'available', exitCode: provenance.exitCode,
|
|
29
|
-
reportSha256: provenance.reportSha256, report } };
|
|
44
|
+
reportSha256: provenance.reportSha256, report }, ...(boundary ? { boundary } : {}) };
|
|
30
45
|
}
|
|
31
46
|
|
|
32
47
|
function main(argv) {
|
|
33
48
|
const i = argv.indexOf('--worktree'), path = i < 0 ? null : argv[i + 1];
|
|
34
|
-
if (!path || path.startsWith('--')) { console.error('usage: evidence-bundle.mjs --worktree <worktree.json>'); process.exitCode = 2; return; }
|
|
35
|
-
|
|
49
|
+
if (!path || path.startsWith('--')) { console.error('usage: evidence-bundle.mjs --worktree <worktree.json> [--trusted-boundary-opt-in --boundary-config <file> --boundary-out <dir>]'); process.exitCode = 2; return; }
|
|
50
|
+
const value = name => { const at = argv.indexOf(`--${name}`); return at < 0 ? null : argv[at + 1]; };
|
|
51
|
+
const boundaryOptions = { trustedOptIn: argv.includes('--trusted-boundary-opt-in'), configPath: value('boundary-config'), outputDir: value('boundary-out') };
|
|
52
|
+
try { console.log(JSON.stringify(collectEvidence(JSON.parse(readFileSync(path, 'utf8')), boundaryOptions))); }
|
|
36
53
|
catch { console.log(JSON.stringify(unavailableBundle('worktree metadata could not be read'))); process.exitCode = 2; }
|
|
37
54
|
}
|
|
38
55
|
|