harness-everything 1.3.1 → 1.3.2
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 +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +8 -0
- package/behavioral-evals/ledger-pairs/README.md +53 -0
- package/behavioral-evals/ledger-pairs/arm.js +359 -0
- package/behavioral-evals/ledger-pairs/fixture.js +138 -0
- package/behavioral-evals/ledger-pairs/preflight.js +96 -0
- package/behavioral-evals/ledger-pairs/score.js +155 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/README.md +108 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-baseline/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-baseline/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-baseline/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-baseline/arm-result.json +28 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-baseline/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-treatment/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-baseline/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-treatment/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-baseline/arm-result.json +49 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-treatment/arm-result.json +49 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-baseline/arm-result.json +49 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-treatment/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/receipt.jsonl +17 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/arm-result.json +41 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/receipt.jsonl +58 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/arm-result.json +50 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/receipt.jsonl +101 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/receipt.jsonl +29 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/receipt.jsonl +23 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/arm-result.json +34 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/receipt.jsonl +24 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/arm-result.json +47 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/receipt.jsonl +69 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/receipt.jsonl +65 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/run-order.sh +18 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/score.json +1032 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/README.md +50 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/collect-rerun.txt +3 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/export-report.json +22 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/host-version.txt +1 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/import-report-1.json +18 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/import-report-2.json +18 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/labels-observed-excerpt.jsonl +2 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/observations-index-excerpt.json +26 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/plugin-load-lines.txt +1 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/README.md +46 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/observations-index-excerpt.json +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/plugin-load-lines.txt +2 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/run-marks.txt +6 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/steering-probe.js +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/steering-trace.jsonl +167 -0
- package/ci/mechanism-332-fable-directive.test.js +180 -0
- package/ci/mechanism-552-ledger-pairs.test.js +159 -0
- package/ci/router-workflow-plan.test.js +61 -21
- package/docs/platform-capabilities.md +28 -11
- package/docs/platform-compatibility.json +5 -5
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/routing-keywords.json +0 -2
- package/harness-everything/scripts/tier-router.js +105 -11
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/rules/AGENTS.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +0 -2
- package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +105 -11
- package/sbom.cdx.json +7 -7
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"name": "harness-everything",
|
|
11
11
|
"source": "./",
|
|
12
12
|
"description": "Harness OS: an orchestrated agent operating system — tier routing, circuit breaker guardrails, verification gates, WAL session memory, and self-evolving workspace rules.",
|
|
13
|
-
"version": "1.3.
|
|
13
|
+
"version": "1.3.2",
|
|
14
14
|
"author": {
|
|
15
15
|
"name": "Miya Daniel"
|
|
16
16
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "harness-everything",
|
|
3
3
|
"description": "Harness OS: an orchestrated agent operating system — tier routing, circuit breaker guardrails, verification gates, WAL session memory, and self-evolving workspace rules.",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Miya Daniel"
|
|
7
7
|
},
|
package/AGENTS.md
CHANGED
|
@@ -55,7 +55,7 @@ flowchart LR
|
|
|
55
55
|
- New features, fixes, tests, and host compatibility work target V2 only. No V1 public entrypoint, V1-only event fallback, V1 hook registration, or compatibility mode may be added.
|
|
56
56
|
- Retain historical V1 artifacts, but never promote them to current V2 capability evidence.
|
|
57
57
|
- Reintroducing V1 support requires an explicit owner-approved support-contract change; it is not a routine compatibility fix.
|
|
58
|
-
- State the V2 API family as the supported boundary. Tested V2 versions are recorded separately (`2.1.3` server-log load-only; `2.1.4` limited session workspace trace;
|
|
58
|
+
- State the V2 API family as the supported boundary. Tested V2 versions are recorded separately (`2.1.3` server-log load-only; `2.1.4` limited session workspace trace; one isolated `2.1.4` macOS 26.6.2 [V2 lifecycle trace](benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/README.md) establishing V2 default-export load, V2 tool hooks, V2 event envelope + `session.execution.succeeded`, and completion → verification → reminder delivery on a long-lived server — standalone `opencode run` exits before verification finishes; and two isolated `2.4.1` macOS 26.7.3 long-lived server runs: [turn → export trace](benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/README.md) establishing observation recording + idempotent training export, with router/context injection indirectly observed (model emitted the injected label contract) rather than a full injection trace, and [steering trace](benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/README.md) establishing mid-turn live steering delivery shape as witness-only for #450; ledger lessons, session create/delete reset, cancellation, global scope, npm install, and other versions/OSes remain unverified); none establishes a validated minimum patch version or coverage of every V2 release.
|
|
59
59
|
|
|
60
60
|
**Historical / unsupported V1 evidence:** the retained [OpenCode evidence](benchmarks/results/live-host/opencode-2026-09-16/README.md) documents project-scope `.js` loading and edit/verification state on OpenCode 1.18.31 (macOS). It is preserved as historical/unsupported evidence only and does not establish current V2 capability:
|
|
61
61
|
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.3.2](https://github.com/dyphn1/Harness-everything/compare/v1.3.1...v1.3.2) (2026-11-28)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* **router:** decide fable directives by clause position and scope prohibitions ([#332](https://github.com/dyphn1/Harness-everything/issues/332)) ([000dbb1](https://github.com/dyphn1/Harness-everything/commit/000dbb16c9d4bd74612ce00791bc76a7d3f1a7e3))
|
|
10
|
+
* **router:** separate politeness prefixes from fable directive verbs ([#332](https://github.com/dyphn1/Harness-everything/issues/332)) ([0e488da](https://github.com/dyphn1/Harness-everything/commit/0e488da18c705964ee6a969256c9d48cecb2ca9c))
|
|
11
|
+
* **router:** treat a fable mention or negation as no fable request ([#332](https://github.com/dyphn1/Harness-everything/issues/332)) ([3b8b371](https://github.com/dyphn1/Harness-everything/commit/3b8b3710c56040347dc36f3576e1e04e4a3760ca))
|
|
12
|
+
|
|
5
13
|
## [1.3.1](https://github.com/dyphn1/Harness-everything/compare/v1.3.0...v1.3.1) (2026-11-28)
|
|
6
14
|
|
|
7
15
|
## [1.3.0](https://github.com/dyphn1/Harness-everything/compare/v1.2.2...v1.3.0) (2026-11-26)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# E-0003 paired carrier experiment
|
|
2
|
+
|
|
3
|
+
## Design
|
|
4
|
+
|
|
5
|
+
```mermaid
|
|
6
|
+
flowchart LR
|
|
7
|
+
F[Identical fixture files and hooks] --> P[Same E-0003 trigger]
|
|
8
|
+
P --> B[Baseline: strip exact carrier fragment]
|
|
9
|
+
P --> T[Treatment: pass carrier fragment]
|
|
10
|
+
B --> R[Receipt and next-decision evidence]
|
|
11
|
+
T --> R
|
|
12
|
+
R --> S[Score by runner; retain every assigned arm]
|
|
13
|
+
A[AGY prompt injection] --> S
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- Four baseline/treatment pairs per runner (12 pairs, 24 arms). Score Codex/Luna, OpenCode and AGY separately; never pool runners. Verdicts are **descriptive, inconclusive**.
|
|
17
|
+
- Baseline and treatment have byte-identical fixture files, initial commit, Git hook and permissions. Both can discover E-0003 in the workspace. OpenCode and Codex baseline probes strip only the exact `Cue`/`Lesson` carrier fragment after the Harness carrier appends it; treatment passes it through. This estimates the exploratory incremental effect of the carrier when the lesson is self-discoverable. Receipt files contain keyed statuses only, never command text.
|
|
18
|
+
- AGY remains a separate `agy-injection` intervention: same fixture files, with packet context added only to treatment.
|
|
19
|
+
- Luna's scored action is `prepared-commit`: Codex makes the source change, runs the test, stages `src/sample.js`, and writes `.commit-msg.txt`. The driver then performs `git add -A`, unstages the message file, verifies only `src/sample.js` is staged, and invokes `git commit -F` through the fixture hook. Do not pool this with direct commits from other runners.
|
|
20
|
+
- Token usage is post-hoc measurement including input, output and reasoning tokens when reported (cached usage is retained). Arms over 200,000 tokens are invalid and remain in the assigned-arm denominator. Every arm has a 45-minute timeout.
|
|
21
|
+
- Scoring requires an explicit correlated receipt before the matching scored decision. `unknown` remains unknown. Same-attempt diagnostics are merged; retries represent distinct attempts. File reads of the error ledger and `git log`/`git show` touching it are retained as a per-arm covariate.
|
|
22
|
+
|
|
23
|
+
## Preflight and dry-run
|
|
24
|
+
|
|
25
|
+
Run the same no-model trigger against both fixture arms, then dry-run each runner. Keep the output directory outside the repository.
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
node behavioral-evals/ledger-pairs/preflight.js --no-model --out "$OUT/pf"
|
|
29
|
+
node behavioral-evals/ledger-pairs/arm.js --runner codex --arm baseline --pair 1 --dry-run --out "$OUT/dry"
|
|
30
|
+
node behavioral-evals/ledger-pairs/arm.js --runner opencode --arm baseline --pair 1 --dry-run --out "$OUT/dry"
|
|
31
|
+
node behavioral-evals/ledger-pairs/arm.js --runner agy --arm baseline --pair 1 --dry-run --out "$OUT/dry"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The preflight checks equal fixture bytes, matching E-0003 selection and commitlint accept/reject controls. It sends no model request and cannot establish live receipt. Review isolated live receipts before launching arms; OpenCode requires the isolated long-lived V2 server and actual next-request capture. Keep raw host captures private.
|
|
35
|
+
|
|
36
|
+
## Balanced live order
|
|
37
|
+
|
|
38
|
+
Record a seed and shuffle pair IDs `1..4` separately for each runner. Assign exactly two pairs baseline-first and two treatment-first, run each pair consecutively, and retain the resulting order. For each arm, use an isolated HOME/XDG/TMPDIR/CODEX_HOME. Supply the coordinator's auth directory to Codex/OpenCode; OpenCode also needs `OPENCODE_PASSWORD`.
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
node behavioral-evals/ledger-pairs/arm.js --runner codex --arm baseline --pair 1 --out "$OUT/live" --auth-dir "$AUTH_DIR"
|
|
42
|
+
node behavioral-evals/ledger-pairs/arm.js --runner codex --arm treatment --pair 1 --out "$OUT/live" --auth-dir "$AUTH_DIR"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Run the same two commands for every assigned pair and runner in the recorded balanced order. Stop/mark an arm invalid if post-hoc usage exceeds 200,000 or elapsed time exceeds 45 minutes. Keep every assigned arm and its missing/contamination reasons.
|
|
46
|
+
|
|
47
|
+
## Scoring
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
node behavioral-evals/ledger-pairs/score.js "$OUT"/*/pair-*/arm-result.json
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Report assigned arms, valid pairs, missing/contamination reasons, commit action, first attempt, retries, correct diff/test, hook bypass, file reads, token usage, elapsed time and receipt state per runner. A no-model preflight or mechanism test is not live-host evidence.
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const { spawn, spawnSync } = require('node:child_process');
|
|
7
|
+
const net = require('node:net');
|
|
8
|
+
const { buildFixture, TASK_TEXT } = require('./fixture');
|
|
9
|
+
|
|
10
|
+
const REPO = path.resolve(__dirname, '../..');
|
|
11
|
+
const LEDGER_RECORD = '.agents/harness-everything/errors/E-0003-commitlint-subject.md';
|
|
12
|
+
const RUNNERS = ['codex', 'opencode', 'agy'];
|
|
13
|
+
const ARMS = ['baseline', 'treatment'];
|
|
14
|
+
const COMMIT_TASK_TEXT = `${TASK_TEXT.split('\n')[0]}\nRun the test and stage only src/sample.js. Write the commit subject you intend to use to .commit-msg.txt; do not run git commit. The driver will make the commit through the fixture hook.`;
|
|
15
|
+
|
|
16
|
+
function filterCarrierContext(text, fragment, strip) {
|
|
17
|
+
const matched = typeof text === 'string' && typeof fragment === 'string' && text.includes(fragment);
|
|
18
|
+
return { matched, stripped: Boolean(matched && strip), text: matched && strip ? text.replace(fragment, '') : text };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function parseArgs(argv) {
|
|
22
|
+
const args = { dryRun: false, timeoutMs: 45 * 60 * 1000 };
|
|
23
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
24
|
+
const key = argv[i];
|
|
25
|
+
if (key === '--dry-run') args.dryRun = true;
|
|
26
|
+
else if (['--runner', '--arm', '--pair', '--out', '--auth-dir', '--timeout-ms'].includes(key)) args[key.slice(2).replace(/-([a-z])/g, (_, c) => c.toUpperCase())] = argv[++i];
|
|
27
|
+
else throw new Error(`unknown argument: ${key}`);
|
|
28
|
+
}
|
|
29
|
+
if (!RUNNERS.includes(args.runner)) throw new Error('--runner must be codex|opencode|agy');
|
|
30
|
+
if (!ARMS.includes(args.arm)) throw new Error('--arm must be baseline|treatment');
|
|
31
|
+
if (!Number.isInteger(Number(args.pair)) || Number(args.pair) < 1 || Number(args.pair) > 4) throw new Error('--pair must be 1..4');
|
|
32
|
+
if (!args.out) throw new Error('--out is required');
|
|
33
|
+
args.pair = Number(args.pair);
|
|
34
|
+
args.timeoutMs = Number(args.timeoutMs);
|
|
35
|
+
if (!Number.isFinite(args.timeoutMs) || args.timeoutMs < 1 || args.timeoutMs > 45 * 60 * 1000) throw new Error('--timeout-ms must be between 1 and 2700000 (the 45-minute arm cap)');
|
|
36
|
+
return args;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isolatedEnvironment(root, authDir, runner) {
|
|
40
|
+
const home = path.join(root, 'home');
|
|
41
|
+
const xdg = path.join(root, 'xdg');
|
|
42
|
+
const tmp = path.join(root, 'tmp');
|
|
43
|
+
const codexHome = path.join(root, 'codex-home');
|
|
44
|
+
for (const dir of [home, xdg, tmp, codexHome]) fs.mkdirSync(dir, { recursive: true });
|
|
45
|
+
// Minimal env: never inherit the coordinator's CLAUDE*/CODEX*/HARNESS_* session variables.
|
|
46
|
+
const base = {};
|
|
47
|
+
for (const k of ['PATH', 'LANG', 'TERM', 'SHELL', 'OPENCODE_PASSWORD']) if (process.env[k]) base[k] = process.env[k];
|
|
48
|
+
base.PONYTAIL_DEFAULT_MODE = 'off';
|
|
49
|
+
// agy keeps its login under ~/.gemini; isolating HOME logs it out, so agy keeps the real HOME (recorded in arm-plan).
|
|
50
|
+
if (runner === 'agy') return { ...base, HOME: process.env.HOME, TMPDIR: tmp };
|
|
51
|
+
const env = { ...base, HOME: home, USERPROFILE: home, XDG_CONFIG_HOME: path.join(xdg, 'config'), XDG_DATA_HOME: path.join(xdg, 'data'), XDG_STATE_HOME: path.join(xdg, 'state'), XDG_CACHE_HOME: path.join(xdg, 'cache'), TMPDIR: tmp, CODEX_HOME: codexHome };
|
|
52
|
+
for (const dir of [env.XDG_CONFIG_HOME, env.XDG_DATA_HOME, env.XDG_STATE_HOME, env.XDG_CACHE_HOME]) fs.mkdirSync(dir, { recursive: true });
|
|
53
|
+
if (authDir) copyAuth(path.resolve(authDir), { home, xdg, codexHome }, runner);
|
|
54
|
+
return env;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function copyAuth(source, destinations, runner) {
|
|
58
|
+
if (!fs.existsSync(source)) throw new Error(`auth directory not found: ${source}`);
|
|
59
|
+
const files = ['auth.json', 'credentials.json'];
|
|
60
|
+
for (const name of files) {
|
|
61
|
+
const from = path.join(source, name);
|
|
62
|
+
if (!fs.existsSync(from) || !fs.statSync(from).isFile()) continue;
|
|
63
|
+
// opencode reads auth from XDG_DATA_HOME/opencode; codex from CODEX_HOME.
|
|
64
|
+
const targets = runner === 'opencode' ? [path.join(destinations.xdg, 'data', 'opencode', name)] : [path.join(destinations.codexHome, name)];
|
|
65
|
+
for (const to of targets) {
|
|
66
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
67
|
+
fs.copyFileSync(from, to); fs.chmodSync(to, 0o600);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function quoteShell(value) {
|
|
73
|
+
return `'${String(value).replace(/'/g, "'\\''")}'`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function commandPlan(args, fixture, env) {
|
|
77
|
+
if (args.runner === 'codex') {
|
|
78
|
+
return {
|
|
79
|
+
command: 'codex',
|
|
80
|
+
args: ['exec', '-m', 'gpt-6-luna', '-c', 'model_reasoning_effort="high"', '-s', 'workspace-write', '-C', fixture.repo, '--json', COMMIT_TASK_TEXT],
|
|
81
|
+
cwd: fixture.repo,
|
|
82
|
+
taskText: COMMIT_TASK_TEXT,
|
|
83
|
+
action: 'prepared-commit',
|
|
84
|
+
tokenCapEnforcement: 'post-hoc measurement',
|
|
85
|
+
carrier: 'Codex user-hook compatibility runtime installed under isolated CODEX_HOME; hooks/scripts/codex-ledger-lesson.js',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (args.runner === 'opencode') {
|
|
89
|
+
const pluginPath = path.join(fixture.repo, '.opencode', 'plugins', 'harness-enforcement.js');
|
|
90
|
+
fs.mkdirSync(path.dirname(pluginPath), { recursive: true });
|
|
91
|
+
fs.writeFileSync(pluginPath, `export { default } from ${JSON.stringify(path.join(REPO, 'opencode-plugin/index.mjs'))};\n`);
|
|
92
|
+
fs.appendFileSync(path.join(fixture.repo, '.git', 'info', 'exclude'), '\n.opencode/\n');
|
|
93
|
+
return {
|
|
94
|
+
command: 'opencode',
|
|
95
|
+
args: ['run', '--server', '<isolated-long-lived-server>', '--auto', '--model', 'opencode/hy4-flash-free', '--format', 'json', TASK_TEXT],
|
|
96
|
+
cwd: fixture.repo,
|
|
97
|
+
taskText: TASK_TEXT,
|
|
98
|
+
action: 'commit',
|
|
99
|
+
tokenCapEnforcement: 'post-hoc measurement',
|
|
100
|
+
carrier: 'OpenCode V2 checkout plugin, one-line re-export, tool before/after to next context hook',
|
|
101
|
+
server: { command: 'opencode', args: ['serve', '--hostname', '127.0.0.1', '--port', '<ephemeral>'], requiredVersion: '2.4.1', env: 'OPENCODE_PASSWORD' },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const prompt = args.arm === 'treatment'
|
|
105
|
+
? `${TASK_TEXT}\n\nPacket-context intervention (agy-injection; not a repository-ledger carrier):\n${fs.readFileSync(path.join(fixture.repo, LEDGER_RECORD), 'utf8').split('## Lesson')[1]?.split(/^## /m)[0] || ''}`
|
|
106
|
+
: TASK_TEXT;
|
|
107
|
+
return {
|
|
108
|
+
command: 'agy',
|
|
109
|
+
args: ['-p', prompt, '--model', 'gemini-4-hydrogen-high', '--mode', 'accept-edits', '--sandbox', '--settings', '{"permissions":{"allow":["command(*)","read_file(*)"]}}'],
|
|
110
|
+
cwd: fixture.repo,
|
|
111
|
+
taskText: prompt,
|
|
112
|
+
action: 'commit',
|
|
113
|
+
tokenCapEnforcement: 'post-hoc measurement',
|
|
114
|
+
carrier: 'none; packet-context injection, reported as agy-injection only',
|
|
115
|
+
isolation: 'real HOME (agy login lives in ~/.gemini); TMPDIR isolated; global agy plugins load equally in both arms',
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function ephemeralPort() {
|
|
120
|
+
const server = net.createServer();
|
|
121
|
+
await new Promise((resolve, reject) => server.once('error', reject).listen(0, '127.0.0.1', resolve));
|
|
122
|
+
const port = server.address().port;
|
|
123
|
+
await new Promise(resolve => server.close(resolve));
|
|
124
|
+
return port;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 200k cap (owner: post-hoc measurement) counts uncached input + output + reasoning; cache reads are retained separately.
|
|
128
|
+
function usageTotal(u) { return u ? Math.max(0, u.inputTokens - (u.inputIncludesCache ? u.cachedTokens : 0)) + u.outputTokens + u.reasoningTokens : 0; }
|
|
129
|
+
|
|
130
|
+
function parseUsage(stdout) {
|
|
131
|
+
const totals = { inputTokens: 0, outputTokens: 0, reasoningTokens: 0, cachedTokens: 0, totalTokens: 0 };
|
|
132
|
+
let found = false;
|
|
133
|
+
function visit(value) {
|
|
134
|
+
if (!value || typeof value !== 'object') return;
|
|
135
|
+
for (const [key, child] of Object.entries(value)) {
|
|
136
|
+
const target = ({ total_tokens: 'totalTokens', tokens: 'totalTokens', input_tokens: 'inputTokens', prompt_tokens: 'inputTokens', output_tokens: 'outputTokens', completion_tokens: 'outputTokens', reasoning_tokens: 'reasoningTokens', cached_input_tokens: 'cachedTokens', cached_tokens: 'cachedTokens' })[key];
|
|
137
|
+
// opencode --format json nests usage as tokens:{input,output,reasoning,cache:{read}}.
|
|
138
|
+
if (key === 'tokens' && child && typeof child === 'object') {
|
|
139
|
+
for (const [k, t] of [['input', 'inputTokens'], ['output', 'outputTokens'], ['reasoning', 'reasoningTokens']]) if (Number.isFinite(child[k])) { totals[t] += child[k]; found = true; }
|
|
140
|
+
if (Number.isFinite(child.cache?.read)) { totals.cachedTokens += child.cache.read; found = true; }
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (target && Number.isFinite(child)) { totals[target] += child; found = true; }
|
|
144
|
+
else if (child && typeof child === 'object') visit(child);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
for (const line of String(stdout || '').split(/\r?\n/)) { try { visit(JSON.parse(line)); } catch {} }
|
|
148
|
+
if (!found) return null;
|
|
149
|
+
if (!totals.totalTokens) totals.totalTokens = totals.inputTokens + totals.outputTokens + totals.reasoningTokens + totals.cachedTokens;
|
|
150
|
+
return totals;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function git(repo, args) {
|
|
154
|
+
return spawnSync('git', ['-C', repo, ...args], { encoding: 'utf8' });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function sanitize(text, env) {
|
|
158
|
+
let result = String(text || '');
|
|
159
|
+
for (const key of ['GEMINI_API_KEY', 'OPENCODE_PASSWORD']) {
|
|
160
|
+
if (env[key]) result = result.split(env[key]).join('[REDACTED]');
|
|
161
|
+
}
|
|
162
|
+
return result.replace(/(sk-[A-Za-z0-9_-]{16,}|AIza[A-Za-z0-9_-]{20,})/g, '[REDACTED]');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function runPreparedCommit(repo, env) {
|
|
166
|
+
const messagePath = path.join(repo, '.commit-msg.txt');
|
|
167
|
+
const staged = git(repo, ['add', '-A']);
|
|
168
|
+
if (fs.existsSync(messagePath)) git(repo, ['reset', '--', '.commit-msg.txt']);
|
|
169
|
+
const stagedFiles = git(repo, ['diff', '--cached', '--name-only']).stdout.trim().split(/\r?\n/).filter(Boolean);
|
|
170
|
+
if (staged.status !== 0 || !fs.existsSync(messagePath) || stagedFiles.length !== 1 || stagedFiles[0] !== 'src/sample.js') return { accepted: false, stagedFiles, failure: 'prepared-commit-missing-message-or-unexpected-stage', output: staged.stderr, diagnostics: [] };
|
|
171
|
+
const commit = spawnSync('git', ['-C', repo, 'commit', '-F', messagePath], { encoding: 'utf8', env });
|
|
172
|
+
const output = `${commit.stdout || ''}${commit.stderr || ''}`;
|
|
173
|
+
const diagnostics = ['subject-case', 'header-max-length', 'type-empty', 'subject-empty'].filter(diagnostic => output.includes(`[${diagnostic}]`));
|
|
174
|
+
return { accepted: commit.status === 0, stagedFiles, output, diagnostics };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function runProcess(plan, env, timeoutMs, logFile) {
|
|
178
|
+
return new Promise(resolve => {
|
|
179
|
+
const child = spawn(plan.command, plan.args, { cwd: plan.cwd, env, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
|
|
180
|
+
let stdout = '';
|
|
181
|
+
let stderr = '';
|
|
182
|
+
let timedOut = false;
|
|
183
|
+
const timeout = setTimeout(() => { timedOut = true; child.kill('SIGTERM'); }, timeoutMs);
|
|
184
|
+
child.stdout.on('data', chunk => { stdout += chunk; });
|
|
185
|
+
child.stderr.on('data', chunk => { stderr += chunk; });
|
|
186
|
+
child.on('error', error => { stderr += `${error.message}\n`; });
|
|
187
|
+
child.on('close', code => {
|
|
188
|
+
clearTimeout(timeout);
|
|
189
|
+
const body = `EXIT_CODE=${code}\nTIMED_OUT=${timedOut}\n--- stdout ---\n${sanitize(stdout, env)}\n--- stderr ---\n${sanitize(stderr, env)}\n`;
|
|
190
|
+
fs.writeFileSync(logFile, body, { mode: 0o600 });
|
|
191
|
+
resolve({ code, timedOut, stdout: sanitize(stdout, env), stderr: sanitize(stderr, env) });
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function installCodexCarrierProbe(env, out, arm) {
|
|
197
|
+
const hooksFile = path.join(env.CODEX_HOME, 'hooks.json');
|
|
198
|
+
const wrapper = path.join(env.CODEX_HOME, 'ledger-probe.js');
|
|
199
|
+
const receiptFile = path.join(out, 'receipt.jsonl');
|
|
200
|
+
const sourceHook = path.join(REPO, 'hooks/scripts/codex-ledger-lesson.js');
|
|
201
|
+
const source = `'use strict';\nconst fs=require('node:fs');\nconst path=require('node:path');\nconst {spawnSync}=require('node:child_process');\nconst filter=${filterCarrierContext.toString()};\nconst input=fs.readFileSync(0,'utf8');\nconst payload=JSON.parse(input||'{}');\nconst result=spawnSync(process.execPath,[${JSON.stringify(sourceHook)}],{input,encoding:'utf8',cwd:payload.cwd,env:process.env});\nconst record=fs.readFileSync(path.join(payload.cwd,'.agents/harness-everything/errors/E-0003-commitlint-subject.md'),'utf8');const section=n=>{const m=record.match(new RegExp('^## '+n+'\\\\s*\\\\n([\\\\s\\\\S]*?)(?=^## |$)','m'));return m?m[1].trim():''};const fragment='Cue:\\n'+section('Cue')+'\\nLesson:\\n'+section('Lesson');\nlet output=result.stdout||'';let matched=false;let stripped=false;\ntry{const data=JSON.parse(output||'{}');const key=data.hookSpecificOutput?.additionalContext;const filtered=filter(key,fragment,${JSON.stringify(arm === 'baseline')});matched=filtered.matched;stripped=filtered.stripped;if(stripped){data.hookSpecificOutput.additionalContext=filtered.text;output=JSON.stringify(data)}}catch{}\nconst command=payload.tool_input?.command||'';const compound=/&&|\\|\\||\\n/.test(command);fs.appendFileSync(${JSON.stringify(receiptFile)},JSON.stringify({phase:payload.hook_event_name||'unknown',requestId:payload.turn_id||payload.turnId||null,matched,stripped,kind:compound?'compound':/^\\s*git\\s+commit\\b/.test(command)?'direct':'other',containsGitCommit:/\\bgit\\s+commit\\b/i.test(command)})+'\\n',{mode:0o600});\nprocess.stdout.write(output);process.stderr.write(result.stderr||'');process.exitCode=result.status||0;\n`;
|
|
202
|
+
fs.writeFileSync(wrapper, source, { mode: 0o700 });
|
|
203
|
+
const config = JSON.parse(fs.readFileSync(hooksFile, 'utf8'));
|
|
204
|
+
let changed = false;
|
|
205
|
+
function rewrite(value) {
|
|
206
|
+
if (Array.isArray(value)) return value.map(rewrite);
|
|
207
|
+
if (!value || typeof value !== 'object') return typeof value === 'string' && value.includes('codex-ledger-lesson.js') ? (changed = true, value.replace(/[^\s"']*codex-ledger-lesson\.js/, wrapper)) : value;
|
|
208
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, rewrite(child)]));
|
|
209
|
+
}
|
|
210
|
+
const rewritten = rewrite(config);
|
|
211
|
+
if (!changed) throw new Error('Codex compatibility hooks did not expose codex-ledger-lesson.js for probe wrapping');
|
|
212
|
+
fs.writeFileSync(hooksFile, `${JSON.stringify(rewritten, null, 2)}\n`, { mode: 0o600 });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function installOpenCodeCarrierProbe(fixture, out, arm) {
|
|
216
|
+
const pluginPath = path.join(fixture.repo, '.opencode', 'plugins', 'zz-ledger-probe.js');
|
|
217
|
+
const receiptFile = path.join(out, 'receipt.jsonl');
|
|
218
|
+
fs.mkdirSync(path.dirname(pluginPath), { recursive: true });
|
|
219
|
+
fs.writeFileSync(pluginPath, `import fs from 'node:fs';\nimport path from 'node:path';\nconst filter=${filterCarrierContext.toString()};\nconst receipt=${JSON.stringify(receiptFile)};\nconst root=${JSON.stringify(fixture.repo)};\nconst baseline=${JSON.stringify(arm === 'baseline')};\nconst write=x=>fs.appendFileSync(receipt,JSON.stringify(x)+'\\n',{mode:0o600});\nconst fragment=()=>{const record=fs.readFileSync(path.join(root,'.agents/harness-everything/errors/E-0003-commitlint-subject.md'),'utf8');const section=n=>{const m=record.match(new RegExp('^## '+n+'\\\\s*\\\\n([\\\\s\\\\S]*?)(?=^## |$)','m'));return m?m[1].trim():''};return 'Cue:\\n'+section('Cue')+'\\nLesson:\\n'+section('Lesson')};\nconst toolReceipt=(phase,event)=>{const command=typeof event.input?.command==='string'?event.input.command:'';const kind=/&&|\\|\\||\\n/.test(command)?'compound':/^\\s*git\\s+commit\\b/.test(command)?'direct':'other';write({phase,requestId:event.messageID||event.messageId||null,kind,containsGitCommit:/\\bgit\\s+commit\\b/i.test(command)})};\nexport default {id:'fixture.ledger-probe',async setup(ctx){await ctx.session.hook('context',event=>{const exact=fragment();const system=Array.isArray(event.system)?event.system:[];for(const part of system){if(typeof part?.text!=='string')continue;const filtered=filter(part.text,exact,baseline);if(!filtered.matched)continue;write({phase:'context',requestId:event.messageID||event.messageId||null,matched:true,stripped:filtered.stripped});if(filtered.stripped)part.text=filtered.text}});await ctx.tool.hook('execute.before',event=>toolReceipt('tool.execute.before',event));await ctx.tool.hook('execute.after',event=>toolReceipt('tool.execute.after',event))}};\n`);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async function runArm(args) {
|
|
223
|
+
const out = path.resolve(args.out, args.runner, `pair-${args.pair}-${args.arm}`);
|
|
224
|
+
fs.mkdirSync(out, { recursive: true });
|
|
225
|
+
const fixture = await buildFixture({ out: path.join(out, 'fixture'), arm: args.arm, sourceRoot: REPO });
|
|
226
|
+
const env = isolatedEnvironment(out, args.authDir, args.runner);
|
|
227
|
+
const plan = commandPlan(args, fixture, env);
|
|
228
|
+
const manifest = {
|
|
229
|
+
schemaVersion: 1,
|
|
230
|
+
runner: args.runner,
|
|
231
|
+
arm: args.arm,
|
|
232
|
+
pair: args.pair,
|
|
233
|
+
intervention: args.runner === 'agy' ? 'agy-injection' : 'repo-ledger-context-visibility',
|
|
234
|
+
visibility: fixture.visibility,
|
|
235
|
+
initialSha: fixture.initialSha,
|
|
236
|
+
taskText: plan.taskText,
|
|
237
|
+
carrier: plan.carrier,
|
|
238
|
+
tokenLimit: { max: 200000, enforcement: plan.tokenCapEnforcement },
|
|
239
|
+
timeoutMs: args.timeoutMs,
|
|
240
|
+
commitlintResolution: fixture.commitlintResolution,
|
|
241
|
+
command: plan,
|
|
242
|
+
liveHostEvidence: 'UNCHECKED until retained matcher receipt and next-request capture are reviewed',
|
|
243
|
+
};
|
|
244
|
+
fs.writeFileSync(path.join(out, 'arm-plan.json'), `${JSON.stringify(manifest, null, 2)}\n`, { mode: 0o600 });
|
|
245
|
+
if (args.dryRun) return { out, manifest };
|
|
246
|
+
|
|
247
|
+
if (args.runner === 'codex') {
|
|
248
|
+
const install = await runProcess({ command: process.execPath, args: [path.join(REPO, 'scripts/codex-hooks-compat.js'), 'install', '--codex-home', env.CODEX_HOME, '--allow-unreleased-source'], cwd: REPO }, env, 60000, path.join(out, 'hook-install.log'));
|
|
249
|
+
if (install.code !== 0) throw new Error(`isolated Codex hook install failed; see ${path.join(out, 'hook-install.log')}`);
|
|
250
|
+
installCodexCarrierProbe(env, out, args.arm);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
let server;
|
|
254
|
+
if (args.runner === 'opencode') {
|
|
255
|
+
if (!env.OPENCODE_PASSWORD) throw new Error('OPENCODE_PASSWORD is required for isolated opencode serve');
|
|
256
|
+
const version = spawnSync('opencode', ['--version'], { encoding: 'utf8', env });
|
|
257
|
+
const actualVersion = (version.stdout || '').trim();
|
|
258
|
+
if (version.status !== 0 || !/(^|[^0-9.])2\.4\.1($|[^0-9])/.test(actualVersion)) throw new Error(`OpenCode must be 2.4.1 for this packet; found ${actualVersion || 'unknown'}`);
|
|
259
|
+
manifest.runnerVersion = actualVersion;
|
|
260
|
+
installOpenCodeCarrierProbe(fixture, out, args.arm);
|
|
261
|
+
const port = await ephemeralPort();
|
|
262
|
+
server = spawn('opencode', ['serve', '--hostname', '127.0.0.1', '--port', String(port)], { cwd: fixture.repo, env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
263
|
+
fs.writeFileSync(path.join(out, 'server.pid'), `${server.pid}\n`, { mode: 0o600 });
|
|
264
|
+
const serverLog = fs.createWriteStream(path.join(out, 'server.log'), { mode: 0o600 });
|
|
265
|
+
server.stdout.pipe(serverLog);
|
|
266
|
+
server.stderr.pipe(serverLog);
|
|
267
|
+
await new Promise(resolve => setTimeout(resolve, 1500));
|
|
268
|
+
plan.args[2] = `http://127.0.0.1:${port}`;
|
|
269
|
+
fs.writeFileSync(path.join(out, 'arm-plan.json'), `${JSON.stringify(manifest, null, 2)}\n`, { mode: 0o600 });
|
|
270
|
+
}
|
|
271
|
+
const startedAt = new Date().toISOString();
|
|
272
|
+
const result = await runProcess(plan, env, args.timeoutMs, path.join(out, 'transcript.log'));
|
|
273
|
+
if (server) server.kill('SIGTERM');
|
|
274
|
+
let preparedCommit = null;
|
|
275
|
+
if (args.runner === 'codex') {
|
|
276
|
+
preparedCommit = runPreparedCommit(fixture.repo, { ...env, ...require('./fixture').FIXED_ENV });
|
|
277
|
+
fs.appendFileSync(path.join(out, 'transcript.log'), `\n--- prepared-commit driver ---\n${preparedCommit.output || preparedCommit.failure || ''}\n`);
|
|
278
|
+
}
|
|
279
|
+
const endedAt = new Date().toISOString();
|
|
280
|
+
const log = fs.readFileSync(path.join(out, 'transcript.log'), 'utf8');
|
|
281
|
+
const recordPath = path.join(fixture.repo, LEDGER_RECORD);
|
|
282
|
+
const recordBeforeRestore = fs.readFileSync(recordPath, 'utf8');
|
|
283
|
+
const visibilityUntouched = recordBeforeRestore === fixture.record;
|
|
284
|
+
const head = git(fixture.repo, ['rev-parse', 'HEAD']).stdout.trim();
|
|
285
|
+
const commits = head && head !== fixture.initialSha ? git(fixture.repo, ['rev-list', '--reverse', `${fixture.initialSha}..HEAD`]).stdout.trim().split(/\r?\n/).filter(Boolean) : [];
|
|
286
|
+
const changedFiles = head && head !== fixture.initialSha ? git(fixture.repo, ['diff', '--name-only', `${fixture.initialSha}..HEAD`]).stdout.trim().split(/\r?\n/).filter(Boolean) : [];
|
|
287
|
+
const finalSource = fs.readFileSync(path.join(fixture.repo, 'src/sample.js'), 'utf8');
|
|
288
|
+
const test = spawnSync(process.execPath, ['test.js'], { cwd: fixture.repo, encoding: 'utf8' });
|
|
289
|
+
const diagnostics = [];
|
|
290
|
+
for (const diagnostic of ['subject-case', 'header-max-length', 'type-empty', 'subject-empty']) {
|
|
291
|
+
const count = (log.match(new RegExp(`\\[${diagnostic}\\]`, 'g')) || []).length;
|
|
292
|
+
for (let i = 0; i < count; i += 1) diagnostics.push(diagnostic);
|
|
293
|
+
}
|
|
294
|
+
const events = diagnostics.length ? [{ kind: 'commit', accepted: false, attemptId: args.runner === 'codex' ? 'driver-commit-1' : 'unresolved-attempt-1', diagnostics: [...new Set(diagnostics)] }] : [];
|
|
295
|
+
const receiptFile = path.join(out, 'receipt.jsonl');
|
|
296
|
+
const probeRecords = fs.existsSync(receiptFile) ? fs.readFileSync(receiptFile, 'utf8').split(/\r?\n/).filter(Boolean).map(line => JSON.parse(line)) : [];
|
|
297
|
+
const receiptEvents = [];
|
|
298
|
+
if (args.runner === 'opencode') {
|
|
299
|
+
for (const receipt of probeRecords.filter(row => row.phase === 'context')) {
|
|
300
|
+
const linkedAction = receipt.requestId && probeRecords.find(row => row.phase === 'tool.execute.before' && row.requestId === receipt.requestId && row.containsGitCommit);
|
|
301
|
+
const requestId = receipt.requestId;
|
|
302
|
+
receiptEvents.push({ kind: 'receipt', requestId, correlated: Boolean(linkedAction), status: receipt.matched && !receipt.stripped ? 'delivered-before-decision' : receipt.stripped ? 'filtered' : 'unknown' });
|
|
303
|
+
if (linkedAction) receiptEvents.push({ kind: 'decision', requestId, actionKind: linkedAction.kind });
|
|
304
|
+
}
|
|
305
|
+
} else if (args.runner === 'codex') {
|
|
306
|
+
for (const receipt of probeRecords.filter(row => row.containsGitCommit)) {
|
|
307
|
+
const requestId = receipt.requestId;
|
|
308
|
+
if (requestId) receiptEvents.push({ kind: 'decision', requestId, actionKind: receipt.kind });
|
|
309
|
+
receiptEvents.push({ kind: 'receipt', requestId, correlated: Boolean(requestId), status: 'delivered-after-decision' });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
events.push(...receiptEvents);
|
|
313
|
+
if (preparedCommit) {
|
|
314
|
+
events.push({ kind: 'prepared-commit', accepted: preparedCommit.accepted, stagedFiles: preparedCommit.stagedFiles });
|
|
315
|
+
}
|
|
316
|
+
for (const sha of commits) events.push({ kind: 'commit', accepted: true, sha, subject: git(fixture.repo, ['show', '-s', '--format=%s', sha]).stdout.trim() });
|
|
317
|
+
events.push({ kind: 'test', passed: test.status === 0 });
|
|
318
|
+
for (const line of log.split(/\r?\n/)) if (/--no-verify|HUSKY\s*=\s*0/i.test(line)) events.push({ kind: 'bypass', value: line });
|
|
319
|
+
const workingTree = git(fixture.repo, ['status', '--short']).stdout.trim();
|
|
320
|
+
// codex input_tokens already include cached_input_tokens; opencode input excludes cache reads.
|
|
321
|
+
const usage = parseUsage(result.stdout);
|
|
322
|
+
if (usage && args.runner === 'codex') usage.inputIncludesCache = true;
|
|
323
|
+
const record = {
|
|
324
|
+
runner: args.runner, arm: args.arm, pair: args.pair, action: plan.action, startedAt, endedAt,
|
|
325
|
+
elapsedMs: Date.parse(endedAt) - Date.parse(startedAt), tokenCapEnforcement: plan.tokenCapEnforcement,
|
|
326
|
+
usage, overCap: usageTotal(usage) > 200000, events,
|
|
327
|
+
initialFiles: { 'src/sample.js': "'use strict';\n\nmodule.exports = () => '';\n" },
|
|
328
|
+
finalFiles: { 'src/sample.js': finalSource },
|
|
329
|
+
manualIntervention: 0,
|
|
330
|
+
failures: [...(result.code === 0 ? [] : [`runner-exit-${result.code}`]), ...(!visibilityUntouched ? ['agent-modified-visibility-intervention'] : [])],
|
|
331
|
+
unknowns: ['matcher receipt and model-request delivery require coordinator review', 'manual intervention is zero only while the arm remains unattended'],
|
|
332
|
+
transcriptPath: 'transcript.log', transcriptSha256: require('node:crypto').createHash('sha256').update(log).digest('hex'),
|
|
333
|
+
gitLog: git(fixture.repo, ['log', '--format=%H%x09%s']).stdout.trim().split(/\r?\n/),
|
|
334
|
+
changedFiles,
|
|
335
|
+
correctDiff: visibilityUntouched && changedFiles.length === 1 && changedFiles[0] === 'src/sample.js' && finalSource.includes("module.exports = () => 'hello';"),
|
|
336
|
+
testPassed: test.status === 0,
|
|
337
|
+
hookRejections: diagnostics,
|
|
338
|
+
preparedCommit,
|
|
339
|
+
probeRecords,
|
|
340
|
+
fileReads: (log.match(/(?:read_file|read_file_tool|git\s+(?:log|show))[^\n]*(?:\.agents\/harness-everything\/errors|E-\d{4})/gi) || []).length,
|
|
341
|
+
probeReceiptPath: fs.existsSync(path.join(out, 'receipt.jsonl')) ? 'receipt.jsonl' : 'missing',
|
|
342
|
+
matcherReceipt: 'unknown; review sanitized host trace',
|
|
343
|
+
contextDelivery: 'unknown; review actual next-request capture',
|
|
344
|
+
workingTree,
|
|
345
|
+
treeClean: workingTree === '',
|
|
346
|
+
};
|
|
347
|
+
fs.writeFileSync(path.join(out, 'arm-result.json'), `${JSON.stringify(record, null, 2)}\n`, { mode: 0o600 });
|
|
348
|
+
return { out, manifest, result: { code: result.code, timedOut: result.timedOut } };
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async function main(argv) {
|
|
352
|
+
const args = parseArgs(argv);
|
|
353
|
+
const result = await runArm(args);
|
|
354
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (require.main === module) main(process.argv.slice(2)).catch(error => { console.error(error.message); process.exitCode = 2; });
|
|
358
|
+
|
|
359
|
+
module.exports = { commandPlan, filterCarrierContext, isolatedEnvironment, installCodexCarrierProbe, installOpenCodeCarrierProbe, main, parseArgs, runArm, runPreparedCommit, sanitize };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { spawnSync } = require('node:child_process');
|
|
6
|
+
|
|
7
|
+
const LEDGER = '.agents/harness-everything/errors';
|
|
8
|
+
const RECORD_NAME = 'E-0003-commitlint-subject.md';
|
|
9
|
+
const TASK_TEXT = [
|
|
10
|
+
'Make a small real change in src/sample.js that adds a short greeting for the existing test.',
|
|
11
|
+
'Run the test, then commit the change. Choose any commit subject that follows the repository rules.',
|
|
12
|
+
'Only change src/sample.js. Do not bypass hooks or edit the fixture, test, ledger, or configuration.',
|
|
13
|
+
].join('\n');
|
|
14
|
+
const FIXED_ENV = Object.freeze({
|
|
15
|
+
GIT_AUTHOR_NAME: 'Ledger Pair Fixture',
|
|
16
|
+
GIT_AUTHOR_EMAIL: 'ledger-pair@example.invalid',
|
|
17
|
+
GIT_COMMITTER_NAME: 'Ledger Pair Fixture',
|
|
18
|
+
GIT_COMMITTER_EMAIL: 'ledger-pair@example.invalid',
|
|
19
|
+
GIT_AUTHOR_DATE: '2026-01-01T00:00:00Z',
|
|
20
|
+
GIT_COMMITTER_DATE: '2026-01-01T00:00:00Z',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function run(command, args, options = {}) {
|
|
24
|
+
const result = spawnSync(command, args, { encoding: 'utf8', ...options });
|
|
25
|
+
if (result.error || result.status !== 0) {
|
|
26
|
+
throw new Error(`${command} ${args.join(' ')} failed: ${result.error?.message || result.stderr || result.status}`);
|
|
27
|
+
}
|
|
28
|
+
return result.stdout.trim();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function applyVisibility(record, arm) {
|
|
32
|
+
if (!['baseline', 'treatment'].includes(arm)) throw new Error(`invalid arm: ${arm}`);
|
|
33
|
+
return { ...record };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function visibilityFromRecord(record) {
|
|
37
|
+
return record.includes('## Lesson') ? 'visible' : 'unknown';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function indexRow(indexText) {
|
|
41
|
+
const rows = indexText.split(/\r?\n/).filter(Boolean).map(line => JSON.parse(line));
|
|
42
|
+
if (rows.length !== 1 || rows[0].id !== 'E-0003') throw new Error('fixture index must contain only E-0003');
|
|
43
|
+
return rows[0];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function copyDependencyClosure(packageName, sourceModules, targetModules, copied = new Set()) {
|
|
47
|
+
if (copied.has(packageName)) return;
|
|
48
|
+
copied.add(packageName);
|
|
49
|
+
const source = path.join(sourceModules, ...packageName.split('/'));
|
|
50
|
+
if (!fs.existsSync(source)) throw new Error(`required offline dependency is missing: ${packageName}`);
|
|
51
|
+
const target = path.join(targetModules, ...packageName.split('/'));
|
|
52
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
53
|
+
fs.cpSync(source, target, { recursive: true, dereference: true });
|
|
54
|
+
const metadata = JSON.parse(fs.readFileSync(path.join(source, 'package.json'), 'utf8'));
|
|
55
|
+
for (const dependency of Object.keys(metadata.dependencies || {})) {
|
|
56
|
+
copyDependencyClosure(dependency, sourceModules, targetModules, copied);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function applyVisibilityToWorkspace(repo, arm) {
|
|
61
|
+
const recordPath = path.join(repo, LEDGER, RECORD_NAME);
|
|
62
|
+
const original = fs.readFileSync(recordPath, 'utf8');
|
|
63
|
+
return { recordPath, visibility: 'identical-visible', original };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function buildFixture({ out, arm = 'treatment', sourceRoot = path.resolve(__dirname, '../..') } = {}) {
|
|
67
|
+
if (!out) throw new Error('out is required');
|
|
68
|
+
if (!['baseline', 'treatment'].includes(arm)) throw new Error(`invalid arm: ${arm}`);
|
|
69
|
+
const destination = path.resolve(out);
|
|
70
|
+
const repo = path.join(destination, 'repo');
|
|
71
|
+
fs.rmSync(destination, { recursive: true, force: true });
|
|
72
|
+
fs.mkdirSync(path.join(repo, LEDGER), { recursive: true });
|
|
73
|
+
fs.mkdirSync(path.join(repo, '.husky'), { recursive: true });
|
|
74
|
+
fs.mkdirSync(path.join(repo, '.githooks'), { recursive: true });
|
|
75
|
+
fs.mkdirSync(path.join(repo, 'src'), { recursive: true });
|
|
76
|
+
fs.mkdirSync(path.join(repo, 'node_modules', '.bin'), { recursive: true });
|
|
77
|
+
|
|
78
|
+
const sourceRecordPath = path.join(sourceRoot, LEDGER, RECORD_NAME);
|
|
79
|
+
const sourceIndex = path.join(sourceRoot, LEDGER, 'index.jsonl');
|
|
80
|
+
const sourceRow = indexRow(fs.readFileSync(sourceIndex, 'utf8').split(/\r?\n/).find(line => JSON.parse(line).id === 'E-0003'));
|
|
81
|
+
fs.copyFileSync(path.join(sourceRoot, 'commitlint.config.js'), path.join(repo, 'commitlint.config.js'));
|
|
82
|
+
fs.copyFileSync(path.join(sourceRoot, '.husky', 'commit-msg'), path.join(repo, '.husky', 'commit-msg'));
|
|
83
|
+
fs.copyFileSync(sourceRecordPath, path.join(repo, LEDGER, RECORD_NAME));
|
|
84
|
+
fs.writeFileSync(path.join(repo, LEDGER, 'index.jsonl'), `${JSON.stringify(sourceRow)}\n`);
|
|
85
|
+
fs.writeFileSync(path.join(repo, 'src', 'sample.js'), "'use strict';\n\nmodule.exports = () => '';\n");
|
|
86
|
+
fs.writeFileSync(path.join(repo, 'test.js'), "'use strict';\nconst assert = require('node:assert/strict');\nassert.equal(require('./src/sample')(), 'hello');\n");
|
|
87
|
+
|
|
88
|
+
// Reuse the installed CLI by absolute path and copy the conventional config's
|
|
89
|
+
// transitive dependency closure; no network or full node_modules copy is used.
|
|
90
|
+
const cli = path.join(path.dirname(require.resolve('@commitlint/cli')), 'cli.js');
|
|
91
|
+
const sourceModules = path.join(sourceRoot, 'node_modules');
|
|
92
|
+
const shimPath = path.join(repo, 'node_modules', '.bin', 'commitlint');
|
|
93
|
+
|
|
94
|
+
const hookPath = path.join(repo, '.githooks', 'commit-msg');
|
|
95
|
+
fs.writeFileSync(hookPath, '#!/bin/sh\nexec .husky/commit-msg "$@"\n', { mode: 0o755 });
|
|
96
|
+
fs.writeFileSync(path.join(repo, '.husky', 'commit-msg'), fs.readFileSync(path.join(repo, '.husky', 'commit-msg')));
|
|
97
|
+
fs.chmodSync(path.join(repo, '.husky', 'commit-msg'), 0o755);
|
|
98
|
+
|
|
99
|
+
run('git', ['init', '--quiet', '--object-format=sha1', repo]);
|
|
100
|
+
copyDependencyClosure('@commitlint/config-conventional', sourceModules, path.join(repo, 'node_modules'));
|
|
101
|
+
const shellQuote = value => `'${String(value).replace(/'/g, "'\\''")}'`;
|
|
102
|
+
if (process.platform === 'win32') {
|
|
103
|
+
fs.writeFileSync(`${shimPath}.cmd`, `@"${process.execPath}" "${cli}" %*\r\n`, { mode: 0o755 });
|
|
104
|
+
} else {
|
|
105
|
+
fs.writeFileSync(shimPath, `#!/bin/sh\nexec ${shellQuote(process.execPath)} ${shellQuote(cli)} "$@"\n`, { mode: 0o755 });
|
|
106
|
+
}
|
|
107
|
+
fs.appendFileSync(path.join(repo, '.git', 'info', 'exclude'), '\nnode_modules/\n');
|
|
108
|
+
run('git', ['-C', repo, 'config', 'user.name', FIXED_ENV.GIT_AUTHOR_NAME]);
|
|
109
|
+
run('git', ['-C', repo, 'config', 'user.email', FIXED_ENV.GIT_AUTHOR_EMAIL]);
|
|
110
|
+
run('git', ['-C', repo, 'config', 'core.hooksPath', '.githooks']);
|
|
111
|
+
run('git', ['-C', repo, 'add', 'commitlint.config.js', '.husky/commit-msg', '.githooks/commit-msg', 'src/sample.js', 'test.js', `${LEDGER}/${RECORD_NAME}`, `${LEDGER}/index.jsonl`]);
|
|
112
|
+
run('git', ['-C', repo, 'update-index', '--chmod=+x', '.husky/commit-msg', '.githooks/commit-msg']);
|
|
113
|
+
run('git', ['-C', repo, '-c', 'core.hooksPath=/dev/null', 'commit', '--quiet', '--no-verify', '-m', 'chore: create paired experiment fixture'], { env: { ...process.env, ...FIXED_ENV } });
|
|
114
|
+
const initialSha = run('git', ['-C', repo, 'rev-parse', 'HEAD']);
|
|
115
|
+
const visibility = applyVisibilityToWorkspace(repo, arm);
|
|
116
|
+
return {
|
|
117
|
+
repo,
|
|
118
|
+
initialSha,
|
|
119
|
+
arm,
|
|
120
|
+
visibility: visibility.visibility,
|
|
121
|
+
taskText: TASK_TEXT,
|
|
122
|
+
record: fs.readFileSync(visibility.recordPath, 'utf8'),
|
|
123
|
+
index: fs.readFileSync(path.join(repo, LEDGER, 'index.jsonl'), 'utf8'),
|
|
124
|
+
commitlintPath: cli,
|
|
125
|
+
commitlintResolution: `absolute checkout path ${cli}; no network install`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = {
|
|
130
|
+
FIXED_ENV,
|
|
131
|
+
TASK_TEXT,
|
|
132
|
+
applyVisibility,
|
|
133
|
+
applyVisibilityToWorkspace,
|
|
134
|
+
buildFixture,
|
|
135
|
+
copyDependencyClosure,
|
|
136
|
+
indexRow,
|
|
137
|
+
visibilityFromRecord,
|
|
138
|
+
};
|