harness-everything 1.1.0 → 1.2.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.
Files changed (32) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +19 -0
  4. package/benchmarks/results/live-host/agy-2026-11-25/README.md +32 -0
  5. package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/README.md +32 -0
  6. package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/claude-records.json +1 -0
  7. package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/codex-hook-trace.txt +24 -0
  8. package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/opencode-records.json +1 -0
  9. package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/probe.sh +16 -0
  10. package/ci/mechanism-498-local-store-promote.test.js +402 -0
  11. package/ci/mechanism-498-local-store-scan.test.js +570 -0
  12. package/ci/mechanism-516-windows-verify-and-shell.test.js +328 -0
  13. package/docs/platform-capabilities.md +2 -2
  14. package/docs/platform-compatibility.json +2 -2
  15. package/error-ledger-bootstrap/SKILL.md +1 -1
  16. package/error-ledger-bootstrap/references/workflow.md +15 -1
  17. package/error-ledger-bootstrap/scripts/promote.js +145 -9
  18. package/error-ledger-bootstrap/scripts/scan.js +394 -3
  19. package/hooks/scripts/lib/workflow-isolation.js +1 -1
  20. package/opencode-plugin/plugin.json +1 -1
  21. package/package.json +1 -1
  22. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  23. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  24. package/plugins/harness-everything/hooks/scripts/lib/workflow-isolation.js +1 -1
  25. package/plugins/harness-everything/plugin.json +1 -1
  26. package/plugins/harness-everything/scripts/lib/verification-contract.js +68 -12
  27. package/plugins/harness-everything/skills/error-ledger-bootstrap/SKILL.md +1 -1
  28. package/plugins/harness-everything/skills/error-ledger-bootstrap/references/workflow.md +15 -1
  29. package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +145 -9
  30. package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +394 -3
  31. package/sbom.cdx.json +7 -7
  32. package/scripts/lib/verification-contract.js +68 -12
@@ -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.1.0",
13
+ "version": "1.2.0",
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.1.0",
4
+ "version": "1.2.0",
5
5
  "author": {
6
6
  "name": "Miya Daniel"
7
7
  },
package/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## [1.2.0](https://github.com/dyphn1/Harness-everything/compare/v1.1.1...v1.2.0) (2026-11-25)
6
+
7
+ ### Features
8
+
9
+ * **error-ledger-bootstrap:** bind local-store leads at promotion ([#498](https://github.com/dyphn1/Harness-everything/issues/498)) ([19f3b57](https://github.com/dyphn1/Harness-everything/commit/19f3b574613725819698558dc363ade2b890a036))
10
+ * **error-ledger-bootstrap:** opt-in local-store scan source ([#498](https://github.com/dyphn1/Harness-everything/issues/498)) ([6ef61ae](https://github.com/dyphn1/Harness-everything/commit/6ef61ae3f4209f380d41529ef7d078931bbe05fd)), closes [#496](https://github.com/dyphn1/Harness-everything/issues/496)
11
+
12
+ ### Bug Fixes
13
+
14
+ * **error-ledger-bootstrap:** exclude provisional id collisions, check reader contract ([#498](https://github.com/dyphn1/Harness-everything/issues/498)) ([17a28db](https://github.com/dyphn1/Harness-everything/commit/17a28dba01bf91424a243ac9cea60bf0b751d9e3))
15
+
16
+ ## [1.1.1](https://github.com/dyphn1/Harness-everything/compare/v1.1.0...v1.1.1) (2026-11-25)
17
+
18
+ ### Bug Fixes
19
+
20
+ * **agy:** exclude sphinx make-mode help from verification ([9cb27dc](https://github.com/dyphn1/Harness-everything/commit/9cb27dcb83225c1dfdac0f4f0deb53a27ae6df44))
21
+ * **agy:** require grounded windows verification evidence ([#525](https://github.com/dyphn1/Harness-everything/issues/525)) ([1427391](https://github.com/dyphn1/Harness-everything/commit/1427391ead664e716caa6a3f16f9705033fda024))
22
+ * **agy:** support windows verifiers and readonly powershell ([#516](https://github.com/dyphn1/Harness-everything/issues/516)) ([7b3b4d9](https://github.com/dyphn1/Harness-everything/commit/7b3b4d9d8c206ef347dddd7505a9120d0f665472))
23
+
5
24
  ## [1.1.0](https://github.com/dyphn1/Harness-everything/compare/v1.0.1...v1.1.0) (2026-11-25)
6
25
 
7
26
  ### Features
@@ -0,0 +1,32 @@
1
+ # Live-Host Evidence: Google Antigravity (AGY) Windows Desktop & CLI 1.5.16 (Partial)
2
+
3
+ Sanitized live-host verification of the native Google Antigravity (AGY) plugin (`harness-everything` `1.0.1`, matching commit `d5789004` / PR #521) on **Windows**. This records partial live-host coverage on Windows Desktop App and `agy` CLI `1.5.16`, confirms that PR #521's bounded `Stop` continuation fix operates on live Windows sessions, and documents the remaining #516 / #514 gaps observed during the run.
4
+
5
+ ## Environment & Scope
6
+
7
+ | Field | Value |
8
+ |---|---|
9
+ | Date | 2026-11-25 |
10
+ | Host | Antigravity Desktop App (Windows) + `agy` CLI `1.5.16` |
11
+ | OS / Runtime | Windows, Node `v24.18.0` |
12
+ | Install Scope | Global: `<USERPROFILE>/.gemini/config/plugins/harness-everything` (`version: 1.0.1`, updated `2026-11-25 08:52`, SHA-256 parity verified against `plugins/harness-everything` at `d5789004`) |
13
+ | Related Issues | #516 (Windows Stop loop / verification detection), #514 (AGY live-host evidence), #510 |
14
+
15
+ ## Live Observations (Windows Desktop App & `agy` CLI `1.5.16`)
16
+
17
+ | Surface | Result | Sanitized Evidence |
18
+ |---|---|---|
19
+ | `agy --version` / `agy plugin list --json` | **Observed live** | `agy` CLI `1.5.16` listed `<USERPROFILE>/.gemini/config/plugins/harness-everything` (`enabled: true`, `version: "1.0.1"`, 28 skills, `rules: ["AGENTS.md"]`, `hooks: ["harness-everything"]`). |
20
+ | `agy plugin validate --json ./plugins/harness-everything` | **Observed live** | Exited `0` (`manifest: ".antigravity-plugin/plugin.json"`, `components: { agents: 0, hooks: 1, mcpServers: 0, rules: 1, sidecars: 0, skills: 28 }`, 2 expected multi-host warnings + 1 note). |
21
+ | `SessionStart` | **Observed live** | Injected `Harness Skills OS active. Operating under AGENTS.md invariant-first routing.` at step 1 of live Windows Desktop session `<conv-2>`. |
22
+ | `PreInvocation` | **Observed live** | Injected `[Tier Routing Pre-check]` and persisted `workflow-run.json` and `agy-pre-invocation-state.json` under `<USERPROFILE>/.agents/harness-everything/workspaces/<ws-key>/state/sessions/<conv-id>/`. |
23
+ | `Stop` bounded continuation (with direct edits) | **Observed live** | In live Windows Desktop session `<conv-1>` (`developerdocs`, `2026-11-25 10:13–10:16`), `handoff-state.json` tracked `agyDirectMutationRevision: 5`, and `agy-stop-state.json` recorded `lastContinuedRevision: "direct:5"` with `lastContinuedContentFingerprint`, bounding continuation to 1 and allowing subsequent build + commit completion without the prior 7+ turn loop. |
24
+ | `Stop` bounded continuation (read-only PowerShell session) | **Observed live** | In live Windows Desktop session `<conv-2>` (`Harness-everything`, `2026-11-25 17:28–17:32`) with zero workspace file edits, running PowerShell pipelines (`Get-ChildItem ... \| ForEach-Object { ... }`) and `npm.cmd run test:consistency` updated `handoff-state.json` `lastEditAt`. At turn end (`2026-11-25T09:32:21.322Z`), host `Stop` returned `continue` once and wrote `agy-stop-state.json` (`lastContinuedRevision: "session:<conv-2>"` + `lastContinuedContentFingerprint`), then allowed termination on the following turn end with unchanged workspace content. |
25
+ | `PostToolUse` shell verification credit | **Host-limited / Gap confirmed** | On both `<conv-1>` (`.venv\Scripts\mkdocs build --strict`) and `<conv-2>` (`npm.cmd run test:consistency`, `node --test ...`), `lastVerifyAt` remained unset: (1) live Desktop `PostToolUse` omitted numeric `exitCode`, and (2) `verification-contract.js` did not recognize `mkdocs`, `.venv\Scripts\mkdocs`, `npm.cmd`, or `node --test`. |
26
+ | Installed hook scripts (isolated `HARNESS_STATE_HOME`) | **Mechanism verified** | Direct invocation of all 5 installed scripts under `<USERPROFILE>/.gemini/config/plugins/harness-everything/hooks/scripts/agy-*.js` passed (`SessionStart`, `PreInvocation` dedup, `PreToolUse` in/out-of-bounds + `git push --force` deny, `PostToolUse`, and `Stop` 1-continuation cap under PowerShell command churn). |
27
+
28
+ ## Observed Remaining Gaps (Analysis Input for #516 Follow-up)
29
+
30
+ 1. **PowerShell read-only pipelines / `npm.cmd` bump `lastEditAt`:** `workflow-isolation.js` (`splitShellSegments` / `READ_ONLY_PREFIX_RE`) marks PowerShell script blocks (`{...}`) and `$` expressions (`$_.Name`) as `untrusted`, and `npm.cmd` as `mutation-or-unknown`, causing `state-persist.js` to advance `lastEditAt` on read-only turns.
31
+ 2. **Windows verification command recognition:** `scripts/lib/verification-contract.js` did not match Windows `.cmd` runner wrappers (`npm.cmd`, `pnpm.cmd`, `yarn.cmd`, `bun.cmd`), `node --test`, `mkdocs build`, `poetry run mkdocs build`, or `Set-Location ...; <cmd>` PowerShell preludes.
32
+ 3. **Unresolved host / #514 items:** Live `PostToolUse` `exitCode: 0` emission on AGY Desktop, IDE-specific write tools (`write_to_file`, `replace_file_content`, `multi_replace_file_content`), live `model_stop`, project-scope `.agents/plugins/harness-everything/` isolation without global install, and `/hooks` TUI view remain `UNCHECKED`.
@@ -0,0 +1,32 @@
1
+ # #496 L0 capture on live hosts (macOS, 2026-11-25)
2
+
3
+ **Observed:** macOS (Darwin 25.6.0), release `v1.1.0` (includes #522 `819175cb`). Claude Code 2.1.332 (installed plugin 1.1.0, model haiku), Codex CLI 0.172.0 (compat-hooks runtime `1.1.0-8d1bc23f452c`, `gpt-6-luna` low), OpenCode 2.1.4 (`--standalone`, global plugin shim loading `opencode-plugin/index.mjs` from main `d2c63df5`, model `opencode/hy4-flash-free`).
4
+
5
+ Each host ran [`probe.sh`](probe.sh): a fresh empty Git repo, its own `HARNESS_OBSERVATIONS_DIR` and `TMPDIR`, one prompt asking the model to run `ls ./missing-496-probe-dir .` (exit 1) and report the exit code. Afterwards `scripts/errors-local.js list --json` ran in the same workspace with the same store. Home and scratch paths are replaced in the retained files.
6
+
7
+ ```mermaid
8
+ flowchart LR
9
+ P["probe prompt<br/>ls missing dir (exit 1)"] --> C["Claude Code<br/>PostToolUseFailure"]
10
+ P --> X["Codex<br/>PostToolUse"]
11
+ P --> O["OpenCode V2<br/>tool hook"]
12
+ C --> S1["occurrence recorded"]
13
+ O --> S2["occurrence recorded"]
14
+ X --> U["outcome unknown<br/>(text-only tool_response) → no record"]
15
+ ```
16
+
17
+ | Host | Hook delivered | Record | Notes |
18
+ |---|---|---|---|
19
+ | Claude Code | `PostToolUseFailure` | [`claude-records.json`](claude-records.json): 1 `occurrence`, `host: claude`, `commandClass: shell`, `exitCode: null`, `destination: unknown` | The host payload carries no structured exit code; the excerpt starts with the host's `Exit code 1` line. |
20
+ | OpenCode V2 | tool hook in `--standalone` run | [`opencode-records.json`](opencode-records.json): 1 `occurrence`, `host: opencode`, `exitCode: 1`, `destination: unknown` | |
21
+ | Codex | `PostToolUse` fired 5× ([`codex-hook-trace.txt`](codex-hook-trace.txt)) | none (`list` → `[]`) | By design: `readCodexToolOutcome` returns `unknown` without a structured exit status, and capture runs only on `failure`. This is the #488 host gap, not a capture defect. |
22
+
23
+ ## What this establishes
24
+
25
+ - Live capture works end to end on Claude Code and OpenCode V2 for a shell failure: host hook → redacted store record → `errors-local list` in the same workspace.
26
+ - Records are workspace-scoped (`workspaceKey`), carry a `p-` provisional id outside the `E-` namespace, and default to `destination: unknown`.
27
+
28
+ ## What this does not establish
29
+
30
+ - **Codex capture:** not observed; blocked on a structured exit status from the host (#488). No text parsing was added.
31
+ - **Cross-host signatures:** the same failure produced different signatures (`v1-shell-generic-6732037fac2f` on Claude vs `v1-shell-generic-b6246d9928fe` on OpenCode) because the Claude excerpt includes the host's `Exit code 1` prefix. L1 clustering across hosts would split this class (finding, follow-up).
32
+ - Matcher delivery of provisional lessons, review/CI sources, other OSes (Windows is #516), other host versions, and any behaviour change.
@@ -0,0 +1 @@
1
+ [{"schemaVersion":1,"kind":"occurrence","provisionalId":"p-81ef79757bc2bcc0fc75","workspaceKey":"ws-e123bcbdaa0c","destination":"unknown","createdAt":"2026-11-25T12:20:57.120Z","signature":"v1-shell-generic-6732037fac2f","source":"tool-failure","host":"claude","sessionKey":"125cd801deeff1df69ee138b","toolUseId":"4b451c21415e5431259c483d","commandClass":"shell","exitCode":null,"outputExcerpt":"Exit code 1\nls: ./missing-496-probe-dir: No such file or directory","matchedLedgerIds":[]}]
@@ -0,0 +1,24 @@
1
+ hook: PreToolUse
2
+ hook: PreToolUse
3
+ hook: PreToolUse
4
+ hook: PreToolUse
5
+ hook: PreToolUse Completed
6
+ hook: PreToolUse Completed
7
+ hook: PreToolUse Completed
8
+ hook: PreToolUse Completed
9
+ exec
10
+ /bin/zsh -lc 'ls ./missing-496-probe-dir .' in <scratch>/496live/codex/ws
11
+ exited 1 in 0ms:
12
+ ls: ./missing-496-probe-dir: No such file or directory
13
+ .:
14
+
15
+ hook: PostToolUse
16
+ hook: PostToolUse
17
+ hook: PostToolUse
18
+ hook: PostToolUse
19
+ hook: PostToolUse
20
+ hook: PostToolUse Completed
21
+ hook: PostToolUse Completed
22
+ hook: PostToolUse Completed
23
+ hook: PostToolUse Completed
24
+ hook: PostToolUse Completed
@@ -0,0 +1 @@
1
+ [{"schemaVersion":1,"kind":"occurrence","provisionalId":"p-fadb4641d6c4245be1f0","workspaceKey":"ws-936a53060334","destination":"unknown","createdAt":"2026-11-25T12:21:02.660Z","signature":"v1-shell-generic-b6246d9928fe","source":"tool-failure","host":"opencode","sessionKey":"81724dce7b8e2c8055515547","toolUseId":"1aebf58c5b965ab9d88aeaa8","commandClass":"shell","exitCode":1,"outputExcerpt":"ls: ./missing-496-probe-dir: No such file or directory\n","matchedLedgerIds":[]}]
@@ -0,0 +1,16 @@
1
+ #!/bin/bash
2
+ # usage: probe.sh <host> — one fresh git dir + isolated store per host
3
+ set -u
4
+ H=$1; S=$(cd "$(dirname "$0")" && pwd); D=$S/$H; rm -rf "$D"; mkdir -p "$D/ws" "$D/store" "$D/tmp"
5
+ cd "$D/ws" && git init -q && git commit -q --allow-empty -m init
6
+ export HARNESS_OBSERVATIONS_DIR="$D/store" TMPDIR="$D/tmp"
7
+ P='Run exactly this one shell command: ls ./missing-496-probe-dir . Then reply with only its exit code. Do nothing else.'
8
+ date -u +%FT%TZ > "$D/start.txt"
9
+ case $H in
10
+ claude) claude -p "$P" --model haiku --allowedTools "Bash(ls:*)" ;;
11
+ codex) codex exec -m gpt-6-luna -c model_reasoning_effort='"low"' -s workspace-write "$P" ;;
12
+ opencode) opencode run --standalone -m opencode/hy4-flash-free "$P" ;;
13
+ esac < /dev/null > "$D/host.log" 2>&1
14
+ echo "host exit $?" >> "$D/host.log"
15
+ node <home>/Desktop/Skills/Harness-everything/scripts/errors-local.js list --json > "$D/list.json" 2> "$D/list.err"
16
+ echo "list exit $?" >> "$D/host.log"
@@ -0,0 +1,402 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const assert = require('node:assert/strict');
5
+ const childProcess = require('node:child_process');
6
+ const crypto = require('node:crypto');
7
+ const fs = require('node:fs');
8
+ const os = require('node:os');
9
+ const path = require('node:path');
10
+ const localErrors = require('../hooks/scripts/lib/local-errors');
11
+ const { render } = require('../scripts/errors-sync');
12
+
13
+ const ROOT = path.resolve(__dirname, '..');
14
+ const SCANNER = path.join(ROOT, 'error-ledger-bootstrap', 'scripts', 'scan.js');
15
+ const PROMOTER = path.join(ROOT, 'error-ledger-bootstrap', 'scripts', 'promote.js');
16
+ const SYNC = path.join(ROOT, 'scripts', 'errors-sync.js');
17
+ const ERRORS = path.join('.agents', 'harness-everything', 'errors');
18
+ const TMP = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'harness-498-promote-')));
19
+ const STORE = path.join(TMP, 'store');
20
+ const HOME = path.join(TMP, 'home');
21
+ const PRIVATE = {
22
+ provisionalId: 'provisional-parser-one',
23
+ lesson: 'PRIVATE_LESSON_SENTINEL',
24
+ cue: 'PRIVATE_CUE_SENTINEL',
25
+ issueUrl: 'https://private.example/PRIVATE_URL_SENTINEL'
26
+ };
27
+ const WRITER_ENV = isolatedEnv({ HARNESS_OBSERVATIONS_DIR: STORE, HOME, USERPROFILE: HOME });
28
+
29
+ function isolatedEnv(overrides = {}) {
30
+ const env = { ...process.env, ...overrides, GIT_CONFIG_NOSYSTEM: '1' };
31
+ for (const name of ['HARNESS_WORKSPACE_ROOT', 'CLAUDE_PROJECT_DIR', 'CODEX_PROJECT_DIR', 'HARNESS_SYSTEM_ONE_MODE']) {
32
+ delete env[name];
33
+ }
34
+ return env;
35
+ }
36
+
37
+ function write(file, bytes) {
38
+ fs.mkdirSync(path.dirname(file), { recursive: true });
39
+ fs.writeFileSync(file, bytes);
40
+ }
41
+
42
+ function git(root, args, extraEnv = {}) {
43
+ const result = childProcess.spawnSync('git', ['-C', root, ...args], {
44
+ encoding: 'utf8',
45
+ env: isolatedEnv({
46
+ GIT_AUTHOR_NAME: 'Promotion Fixture', GIT_AUTHOR_EMAIL: 'fixture@example.invalid',
47
+ GIT_COMMITTER_NAME: 'Promotion Fixture', GIT_COMMITTER_EMAIL: 'fixture@example.invalid',
48
+ ...extraEnv
49
+ }),
50
+ stdio: ['ignore', 'pipe', 'pipe']
51
+ });
52
+ assert.ifError(result.error);
53
+ assert.equal(result.status, 0, `git ${args.join(' ')} failed: ${result.stderr}`);
54
+ return result.stdout.trim();
55
+ }
56
+
57
+ function hash(bytes) {
58
+ return crypto.createHash('sha256').update(bytes).digest('hex');
59
+ }
60
+
61
+ function treeDigest(directory, excludeLock = false) {
62
+ const entries = fs.readdirSync(directory).sort()
63
+ .filter(name => !(excludeLock && name === '.promote.lock'))
64
+ .map(name => [name, hash(fs.readFileSync(path.join(directory, name)))]);
65
+ return hash(JSON.stringify(entries));
66
+ }
67
+
68
+ function createTarget(name) {
69
+ const root = fs.realpathSync.native(fs.mkdtempSync(path.join(TMP, `${name}-`)));
70
+ const errorsDir = path.join(root, ERRORS);
71
+ write(path.join(errorsDir, 'E-0001-fixture.md'), [
72
+ '---', 'id: E-0001', 'signature: fixture', 'class: test-coupling',
73
+ 'title: Promotion fixture', 'scope: in', 'status: lesson', 'sites: []',
74
+ 'violates: Fixture contract', 'mechanism_ref: null', 'episodes: []', '---',
75
+ '', '## Cue', '', 'A synthetic target ledger.', '', '## Lesson', '', 'Keep this fixture isolated.', ''
76
+ ].join('\n'));
77
+ write(path.join(errorsDir, 'index.jsonl'), render(root));
78
+ write(path.join(root, 'README.md'), '# Promotion fixture\n');
79
+ write(path.join(root, 'src', 'parser.js'), 'module.exports = value => value;\n');
80
+ write(path.join(root, 'ci', 'parser.test.js'), "require('../src/parser');\n");
81
+ git(root, ['init', '-q']);
82
+ git(root, ['config', 'user.name', 'Promotion Fixture']);
83
+ git(root, ['config', 'user.email', 'fixture@example.invalid']);
84
+ git(root, ['config', 'commit.gpgsign', 'false']);
85
+ const epoch = Date.parse('2026-11-25T00:00:00.000Z');
86
+ function commit(subject, seconds, content) {
87
+ write(path.join(root, 'src', 'parser.js'), content);
88
+ git(root, ['add', '-A']);
89
+ const date = new Date(epoch + seconds * 1000).toISOString();
90
+ git(root, ['commit', '-q', '-m', subject], { GIT_AUTHOR_DATE: date, GIT_COMMITTER_DATE: date });
91
+ }
92
+ git(root, ['add', '-A']);
93
+ const seedDate = new Date(epoch).toISOString();
94
+ git(root, ['commit', '-q', '-m', 'chore: seed promotion fixture'], {
95
+ GIT_AUTHOR_DATE: seedDate, GIT_COMMITTER_DATE: seedDate
96
+ });
97
+ commit('fix: preserve parser boundary', 1, 'module.exports = value => value == null ? "" : value;\n');
98
+ commit('fix: handle parser edge case', 2, 'module.exports = value => String(value ?? "");\n');
99
+ return { root, errorsDir };
100
+ }
101
+
102
+ function scan(target, destination = 'harness') {
103
+ const out = path.join(TMP, `report-${crypto.randomBytes(5).toString('hex')}`);
104
+ fs.mkdirSync(out);
105
+ const result = childProcess.spawnSync(process.execPath, [
106
+ SCANNER, '--root', target.root, '--no-memory', '--hide-ledger',
107
+ '--source', 'local-store', '--destination', destination, '--out', out, '--json'
108
+ ], {
109
+ cwd: ROOT,
110
+ encoding: 'utf8',
111
+ env: isolatedEnv({ HARNESS_OBSERVATIONS_DIR: STORE, HOME, USERPROFILE: HOME })
112
+ });
113
+ assert.ifError(result.error);
114
+ assert.equal(result.status, 0, `scanner exit ${result.status}; stderr: ${result.stderr}`);
115
+ const envelope = JSON.parse(result.stdout);
116
+ const reportFile = envelope.reportJson;
117
+ const report = JSON.parse(fs.readFileSync(reportFile, 'utf8'));
118
+ const localSource = report.sources.find(source => source.type === 'local-store');
119
+ const candidate = report.candidates.find(item => item.sources.some(source => source.type === 'local-store'));
120
+ const gitCandidate = report.candidates.find(item => item.sources.some(source => source.type === 'git' || source.type === 'doc'));
121
+ assert.equal(localSource.status, 'used', 'positive control: scanner reads a valid, workspace-bound store row');
122
+ assert.ok(candidate, 'real scanner emits the local lead');
123
+ assert.equal(candidate.signature, 'parser-edge-case');
124
+ assert.ok(gitCandidate, 'real target history supplies a separate repeated-fix candidate');
125
+ return { target, reportFile, report, localSource, candidate, gitCandidate };
126
+ }
127
+
128
+ function addLocalLead(target, destination) {
129
+ const result = localErrors.addProvisionalLesson({
130
+ workspaceRoot: target.root,
131
+ destination,
132
+ provisionalId: PRIVATE.provisionalId,
133
+ signature: 'parser-edge-case',
134
+ match: { actions: [{ tool: 'shell', executable: 'git', subcommand: 'commit' }] },
135
+ lesson: PRIVATE.lesson,
136
+ cue: PRIVATE.cue,
137
+ issueUrl: PRIVATE.issueUrl
138
+ }, { env: WRITER_ENV });
139
+ assert.ok(['appended', 'duplicate'].includes(result.status), `local-store fixture write failed: ${result.status}`);
140
+ return result.record;
141
+ }
142
+
143
+ function saveReport(fixture) {
144
+ fixture.reportBytes = Buffer.from(`${JSON.stringify(fixture.report, null, 2)}\n`);
145
+ fs.writeFileSync(fixture.reportFile, fixture.reportBytes);
146
+ return fixture.reportBytes;
147
+ }
148
+
149
+ function bindCorroboratingCommit(fixture) {
150
+ const source = fixture.gitCandidate.sources.find(item => ['git', 'doc'].includes(item.type) && /^[a-f0-9]{40}$/i.test(item.sha));
151
+ assert.ok(source, 'positive control: a scanner Git/doc source has a real commit SHA');
152
+ git(fixture.target.root, ['cat-file', '-e', `${source.sha}^{commit}`]);
153
+ fixture.candidate.sites = [...new Set([...fixture.candidate.sites, ...fixture.gitCandidate.sites])].sort();
154
+ fixture.candidate.sources.push(source);
155
+ fixture.candidate.sources.sort((left, right) => `${left.type}:${left.sha || left.ref}`.localeCompare(`${right.type}:${right.sha || right.ref}`));
156
+ fixture.candidate.domain = fixture.candidate.sites[0].split('/')[0];
157
+ fixture.candidate.id = hash(JSON.stringify([
158
+ 'error-candidate', fixture.candidate.sites,
159
+ fixture.candidate.sources.map(item => `${item.type}:${item.sha || item.ref}`)
160
+ ])).slice(0, 20);
161
+ saveReport(fixture);
162
+ }
163
+
164
+ function prepared(name, corroborate = true, destination = 'harness') {
165
+ const target = createTarget(name);
166
+ addLocalLead(target, destination);
167
+ const fixture = scan(target, destination);
168
+ fixture.destination = destination;
169
+ if (corroborate) bindCorroboratingCommit(fixture);
170
+ else saveReport(fixture);
171
+ fixture.localRef = fixture.candidate.sources.find(item => item.type === 'local-store').ref;
172
+ return fixture;
173
+ }
174
+
175
+ function approvalFor(fixture, changes = {}) {
176
+ return {
177
+ schemaVersion: 1,
178
+ candidateId: fixture.candidate.id,
179
+ reportSha256: hash(fs.readFileSync(fixture.reportFile)),
180
+ targetRoot: fixture.target.root,
181
+ destination: fixture.destination,
182
+ approvedBy: 'fixture-owner',
183
+ approvedAt: '2026-11-25T12:00:00.000Z',
184
+ record: {
185
+ signature: fixture.candidate.signature,
186
+ class: 'test-coupling',
187
+ title: 'Parser boundary regression',
188
+ violates: 'The parser preserves the approved token boundary.',
189
+ scope: 'in',
190
+ status: 'lesson',
191
+ sites: ['src/parser.js'],
192
+ sourcesNote: 'The repeated target commits corroborate this local lead.'
193
+ },
194
+ ...changes
195
+ };
196
+ }
197
+
198
+ function saveApproval(fixture, approval, name = 'approval.json') {
199
+ const file = path.join(TMP, `${path.basename(fixture.target.root)}-${name}`);
200
+ write(file, `${JSON.stringify(approval, null, 2)}\n`);
201
+ return file;
202
+ }
203
+
204
+ function invoke(fixture, approvalFile, extraEnv = {}) {
205
+ return childProcess.spawnSync(process.execPath, [
206
+ PROMOTER, '--target', fixture.target.root, '--report', fixture.reportFile,
207
+ '--approval', approvalFile, '--harness', ROOT, '--json'
208
+ ], {
209
+ cwd: ROOT,
210
+ encoding: 'utf8',
211
+ env: isolatedEnv({ HARNESS_OBSERVATIONS_DIR: STORE, HOME, USERPROFILE: HOME, ...extraEnv })
212
+ });
213
+ }
214
+
215
+ function resultFor(run, status, label) {
216
+ assert.ifError(run.error);
217
+ assert.equal(run.status, status, `${label}: promote exited ${run.status}; stderr: ${run.stderr}; stdout: ${run.stdout}`);
218
+ assert.equal(run.stderr.trim(), '', `${label}: JSON result is on stdout`);
219
+ return JSON.parse(run.stdout);
220
+ }
221
+
222
+ function refuse(fixture, approvalFile, label, diagnostic, extraEnv = {}) {
223
+ const before = treeDigest(fixture.target.errorsDir);
224
+ const result = resultFor(invoke(fixture, approvalFile, extraEnv), 2, label);
225
+ assert.equal(result.ok, false, `${label}: refusal result is explicit`);
226
+ assert.match(result.error, diagnostic, `${label}: refusal explains the contract violation`);
227
+ assert.equal(treeDigest(fixture.target.errorsDir), before, `${label}: SHA-256 ledger-tree digest is unchanged`);
228
+ return result;
229
+ }
230
+
231
+ function promoteControl(fixture, approvalFile, label) {
232
+ const reportBefore = fs.readFileSync(fixture.reportFile);
233
+ const before = fs.readdirSync(fixture.target.errorsDir).filter(name => /^E-\d{4}-.*\.md$/.test(name)).sort();
234
+ const result = resultFor(invoke(fixture, approvalFile), 0, `${label} positive control`);
235
+ assert.deepEqual(result, {
236
+ ok: true, id: 'E-0002',
237
+ file: path.posix.join(...ERRORS.split(path.sep), 'E-0002-parser-edge-case.md'),
238
+ indexUpdated: true
239
+ }, `${label}: only one new E-ID is allocated`);
240
+ const after = fs.readdirSync(fixture.target.errorsDir).filter(name => /^E-\d{4}-.*\.md$/.test(name)).sort();
241
+ assert.deepEqual(after, [...before, 'E-0002-parser-edge-case.md'].sort(), `${label}: intended destination ledger gets one record`);
242
+ const record = fs.readFileSync(path.join(fixture.target.errorsDir, 'E-0002-parser-edge-case.md'), 'utf8');
243
+ assert.ok(record.includes(fixture.gitCandidate.sources.find(item => ['git', 'doc'].includes(item.type)).sha),
244
+ `${label}: the corroborating target commit reaches the promoted record`);
245
+ assert.doesNotMatch(record, /p-local-|w-local-|PRIVATE_LESSON_SENTINEL|PRIVATE_CUE_SENTINEL|PRIVATE_URL_SENTINEL|issueUrl|workspaceKey|provisionalId/,
246
+ `${label}: opaque refs and private store fields stay out of committed text`);
247
+ assert.equal(fs.readFileSync(path.join(fixture.target.errorsDir, 'index.jsonl'), 'utf8'), render(fixture.target.root),
248
+ `${label}: destination index matches the canonical renderer`);
249
+ assert.deepEqual(fs.readFileSync(fixture.reportFile), reportBefore, `${label}: promotion leaves approved report bytes unchanged`);
250
+ }
251
+
252
+ function duplicateInjection(fixture, wholeRule = false) {
253
+ const marker = path.join(TMP, `${path.basename(fixture.target.root)}-lock-ledger.sha`);
254
+ const hook = path.join(TMP, `${path.basename(fixture.target.root)}-lock-injection.js`);
255
+ const config = {
256
+ promoteScript: PROMOTER,
257
+ targetRoot: fixture.target.root,
258
+ errorsDir: fixture.target.errorsDir,
259
+ lockPath: path.join(fixture.target.errorsDir, '.promote.lock'),
260
+ recordPath: path.join(fixture.target.errorsDir, `E-0002-${wholeRule ? 'same-rule-other-signature' : 'parser-edge-case'}.md`),
261
+ indexPath: path.join(fixture.target.errorsDir, 'index.jsonl'),
262
+ syncScript: SYNC,
263
+ marker
264
+ };
265
+ const record = [
266
+ '---', 'id: E-0002', `signature: ${wholeRule ? 'same-rule-other-signature' : 'parser-edge-case'}`, 'class: test-coupling',
267
+ 'title: Added after local-store scan', 'scope: in', 'status: lesson',
268
+ ...(wholeRule ? ['match:', ' actions:', ' - tool: shell', ' executable: git', ' subcommand: commit'] : []),
269
+ 'sites:', ' - src/parser.js', 'violates: Duplicate class control',
270
+ 'mechanism_ref: null', 'episodes: []', '---', '', '## Cue', '', 'A duplicate control.',
271
+ '', '## Lesson', '', 'This record was inserted after scan and after lock acquisition.', ''
272
+ ].join('\n');
273
+ const hookText = [
274
+ "const fs = require('node:fs');",
275
+ "const path = require('node:path');",
276
+ "const crypto = require('node:crypto');",
277
+ `const config = ${JSON.stringify(config)};`,
278
+ `const record = ${JSON.stringify(record)};`,
279
+ 'const originalOpenSync = fs.openSync.bind(fs);',
280
+ 'const originalWriteFileSync = fs.writeFileSync.bind(fs);',
281
+ 'let injected = false;',
282
+ 'fs.openSync = function (file, ...args) {',
283
+ ' const fd = originalOpenSync(file, ...args);',
284
+ ' if (!injected && process.argv[1] === config.promoteScript && path.resolve(String(file)) === config.lockPath) {',
285
+ ' injected = true;',
286
+ " originalWriteFileSync(config.recordPath, record, { flag: 'wx' });",
287
+ ' const index = require(config.syncScript).render(config.targetRoot);',
288
+ ' originalWriteFileSync(config.indexPath, index);',
289
+ " const rows = fs.readdirSync(config.errorsDir).filter(name => name !== '.promote.lock').sort().map(name => [name, crypto.createHash('sha256').update(fs.readFileSync(path.join(config.errorsDir, name))).digest('hex')]);",
290
+ " originalWriteFileSync(config.marker, crypto.createHash('sha256').update(JSON.stringify(rows)).digest('hex'));",
291
+ ' }',
292
+ ' return fd;',
293
+ '};', ''
294
+ ].join('\n');
295
+ write(hook, hookText);
296
+ return { marker, recordPath: config.recordPath, nodeOptions: `--require="${hook.replace(/\\/g, '/')}"` };
297
+ }
298
+
299
+ try {
300
+ const positive = prepared('positive-control');
301
+ assert.ok(positive.candidate.sources.some(source => source.type === 'local-store'));
302
+ assert.ok(positive.candidate.sources.some(source => ['git', 'doc'].includes(source.type)),
303
+ 'positive control: local ref and real commit are bound to the same approved candidate');
304
+ assert.equal(positive.localSource.destination, 'harness');
305
+ assert.match(positive.localSource.workspaceRef, /^w-local-[a-f0-9]{64}$/);
306
+ const validApproval = saveApproval(positive, approvalFor(positive));
307
+ promoteControl(positive, validApproval, 'same-candidate corroboration');
308
+
309
+ const projectDestination = prepared('project-destination', true, 'project');
310
+ assert.equal(projectDestination.localSource.destination, 'project');
311
+ promoteControl(projectDestination, saveApproval(projectDestination, approvalFor(projectDestination)),
312
+ 'project destination binding');
313
+
314
+ const missingApproval = prepared('missing-approval');
315
+ refuse(missingApproval, path.join(TMP, 'not-created-approval.json'), 'missing approval', /approval cannot be read/);
316
+ promoteControl(missingApproval, saveApproval(missingApproval, approvalFor(missingApproval)), 'missing approval');
317
+
318
+ const wrongApproval = prepared('wrong-approval');
319
+ const wrong = approvalFor(wrongApproval);
320
+ wrong.reportSha256 = '0'.repeat(64);
321
+ refuse(wrongApproval, saveApproval(wrongApproval, wrong), 'wrong approval digest', /report SHA-256/);
322
+ promoteControl(wrongApproval, saveApproval(wrongApproval, approvalFor(wrongApproval)), 'wrong approval digest');
323
+
324
+ const editedReport = prepared('edited-report');
325
+ const approved = saveApproval(editedReport, approvalFor(editedReport));
326
+ const reportBytes = fs.readFileSync(editedReport.reportFile);
327
+ fs.appendFileSync(editedReport.reportFile, ' ');
328
+ refuse(editedReport, approved, 'edited report', /report SHA-256/);
329
+ fs.writeFileSync(editedReport.reportFile, reportBytes);
330
+ promoteControl(editedReport, approved, 'edited report');
331
+
332
+ const wrongWorkspace = prepared('wrong-workspace');
333
+ const boundReport = fs.readFileSync(wrongWorkspace.reportFile);
334
+ wrongWorkspace.localSource.workspaceRef = `w-local-${'0'.repeat(64)}`;
335
+ saveReport(wrongWorkspace);
336
+ const wrongWorkspaceApproval = saveApproval(wrongWorkspace, approvalFor(wrongWorkspace));
337
+ refuse(wrongWorkspace, wrongWorkspaceApproval, 'wrong workspace binding', /workspace.*(?:match|target)|workspace binding/i);
338
+ fs.writeFileSync(wrongWorkspace.reportFile, boundReport);
339
+ wrongWorkspace.report = JSON.parse(boundReport.toString('utf8'));
340
+ wrongWorkspace.localSource = wrongWorkspace.report.sources.find(source => source.type === 'local-store');
341
+ wrongWorkspace.candidate = wrongWorkspace.report.candidates.find(item => item.id === JSON.parse(boundReport.toString('utf8')).candidates.find(candidate => candidate.sources.some(source => source.type === 'local-store')).id);
342
+ promoteControl(wrongWorkspace, saveApproval(wrongWorkspace, approvalFor(wrongWorkspace)), 'wrong workspace binding');
343
+
344
+ const wrongDestination = prepared('wrong-destination');
345
+ const projectApproval = saveApproval(wrongDestination, approvalFor(wrongDestination, { destination: 'project' }));
346
+ refuse(wrongDestination, projectApproval, 'wrong destination approval', /destination/);
347
+ promoteControl(wrongDestination, saveApproval(wrongDestination, approvalFor(wrongDestination)), 'wrong destination approval');
348
+
349
+ const unknownDestination = prepared('unknown-destination');
350
+ const goodReport = fs.readFileSync(unknownDestination.reportFile);
351
+ unknownDestination.localSource.destination = 'unknown';
352
+ for (const source of unknownDestination.candidate.sources.filter(item => item.type === 'local-store')) source.destination = 'unknown';
353
+ saveReport(unknownDestination);
354
+ const unknownApproval = saveApproval(unknownDestination, approvalFor(unknownDestination, { destination: 'unknown' }));
355
+ refuse(unknownDestination, unknownApproval, 'unknown destination', /destination/);
356
+ fs.writeFileSync(unknownDestination.reportFile, goodReport);
357
+ unknownDestination.report = JSON.parse(goodReport.toString('utf8'));
358
+ unknownDestination.localSource = unknownDestination.report.sources.find(source => source.type === 'local-store');
359
+ unknownDestination.candidate = unknownDestination.report.candidates.find(item => item.sources.some(source => source.type === 'local-store'));
360
+ promoteControl(unknownDestination, saveApproval(unknownDestination, approvalFor(unknownDestination)), 'unknown destination');
361
+
362
+ const localOnly = prepared('local-only', false);
363
+ assert.ok(localOnly.gitCandidate, 'negative control: a similar durable Git candidate exists elsewhere in the report');
364
+ assert.ok(!localOnly.candidate.sources.some(source => ['git', 'doc'].includes(source.type)),
365
+ 'negative control: the selected local candidate itself has no durable source');
366
+ assert.ok(!fs.readFileSync(localOnly.reportFile, 'utf8').includes(PRIVATE.issueUrl), 'stored issue URL stays private to the store');
367
+ refuse(localOnly, saveApproval(localOnly, approvalFor(localOnly)), 'local-only evidence including issue URL', /durable source evidence/);
368
+ bindCorroboratingCommit(localOnly);
369
+ promoteControl(localOnly, saveApproval(localOnly, approvalFor(localOnly)), 'local-only evidence including issue URL');
370
+
371
+ const duplicateAfterScan = prepared('duplicate-after-scan');
372
+ const duplicateApproval = saveApproval(duplicateAfterScan, approvalFor(duplicateAfterScan));
373
+ const injection = duplicateInjection(duplicateAfterScan);
374
+ const raced = resultFor(invoke(duplicateAfterScan, duplicateApproval, { NODE_OPTIONS: injection.nodeOptions }), 2,
375
+ 'duplicate added after scan while promotion lock is acquired');
376
+ assert.equal(raced.ok, false);
377
+ assert.match(raced.error, /duplicate class|exact dedupe/i,
378
+ 'lock-time recheck identifies the newly added exact class');
379
+ assert.equal(treeDigest(duplicateAfterScan.target.errorsDir, true), fs.readFileSync(injection.marker, 'utf8'),
380
+ 'after the concurrent duplicate insertion, the refusal makes zero further ledger writes');
381
+ fs.rmSync(injection.recordPath);
382
+ write(path.join(duplicateAfterScan.target.errorsDir, 'index.jsonl'), render(duplicateAfterScan.target.root));
383
+ promoteControl(duplicateAfterScan, duplicateApproval, 'locked dedupe recheck');
384
+
385
+ const wholeRuleDuplicate = prepared('whole-rule-after-scan');
386
+ const wholeRuleApproval = saveApproval(wholeRuleDuplicate, approvalFor(wholeRuleDuplicate));
387
+ const wholeRuleInjection = duplicateInjection(wholeRuleDuplicate, true);
388
+ const wholeRuleResult = resultFor(invoke(wholeRuleDuplicate, wholeRuleApproval,
389
+ { NODE_OPTIONS: wholeRuleInjection.nodeOptions }), 2, 'whole-rule duplicate added after scan under the lock');
390
+ assert.equal(wholeRuleResult.ok, false);
391
+ assert.match(wholeRuleResult.error, /duplicate class|exact dedupe/i,
392
+ 'lock-time recheck catches the same exact rule under a different signature');
393
+ assert.equal(treeDigest(wholeRuleDuplicate.target.errorsDir, true), fs.readFileSync(wholeRuleInjection.marker, 'utf8'),
394
+ 'whole-rule refusal makes zero further ledger writes after the concurrent insertion');
395
+ fs.rmSync(wholeRuleInjection.recordPath);
396
+ write(path.join(wholeRuleDuplicate.target.errorsDir, 'index.jsonl'), render(wholeRuleDuplicate.target.root));
397
+ promoteControl(wholeRuleDuplicate, wholeRuleApproval, 'locked whole-rule dedupe recheck');
398
+
399
+ console.log('PASS local-store promotion binds workspace, destination, corroboration, approval, and locked dedupe');
400
+ } finally {
401
+ fs.rmSync(TMP, { recursive: true, force: true });
402
+ }