harness-everything 0.55.3 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +1 -1
- package/BENCHMARK_SOP.md +2 -2
- package/CHANGELOG.md +26 -0
- package/README.md +15 -16
- package/SECURITY.md +1 -1
- package/VERIFICATION.md +4 -8
- package/behavioral-evals/PAIRED-BENCHMARK.md +12 -27
- package/behavioral-evals/README.md +21 -65
- package/behavioral-evals/cases/breaker-zoom-out-after-3.yaml +26 -33
- package/behavioral-evals/cases/pressure-sunk-cost-retry.yaml +15 -17
- package/behavioral-evals/paired-benchmark.js +3 -40
- package/behavioral-evals/run.js +2 -3
- package/ci/fixtures/468-dispatch/runner.js +144 -0
- package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/legacy-off-golden.json +0 -6
- package/ci/invariant-routing.test.js +26 -5
- package/ci/lib/opencode-verification-loader.js +3 -5
- package/ci/mechanism-2a-rule-of-3.test.js +111 -97
- package/ci/mechanism-2n-opencode-plugin.test.js +68 -206
- package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +47 -28
- package/ci/mechanism-2w-platform-compatibility.test.js +1 -0
- package/ci/mechanism-32-paired-benchmark.test.js +1 -2
- package/ci/mechanism-33-issues-205-207.test.js +1 -1
- package/ci/mechanism-338-opencode-async.test.js +18 -49
- package/ci/mechanism-36-verify-timeout.test.js +3 -189
- package/ci/mechanism-39-opencode-verify-outcomes.test.js +56 -323
- package/ci/mechanism-397-opencode-observations.test.js +6 -7
- package/ci/mechanism-468-dispatch-cli.test.js +546 -0
- package/ci/mechanism-codex-hook-results.test.js +9 -5
- package/ci/mechanism-error-handling-map.test.js +14 -12
- package/ci/mechanism-prb-outline-review.test.js +1 -13
- package/ci/mechanism-system-one-router.test.js +1 -1
- package/ci/openai-plugin-package.test.js +30 -7
- package/ci/openai-plugin-runtime.test.js +64 -32
- package/ci/prompt-contract-regressions.test.js +1 -5
- package/ci/self-evolve-loop.test.js +51 -51
- package/ci/workflow-execution-contract.test.js +3 -6
- package/docker-verify.sh +1 -117
- package/docs/architecture.md +9 -7
- package/docs/document-lifecycle.md +1 -1
- package/docs/enforcement-locks.md +12 -10
- package/docs/error-handling/README.md +3 -3
- package/docs/error-handling/actions/c8-action-map.md +41 -0
- package/docs/error-handling/details/c8-dispatch-cli.md +75 -0
- package/docs/error-handling/nodes.yaml +5 -0
- package/docs/error-handling/registry.md +4 -1
- package/docs/mechanism-first-skill-mesh.md +2 -2
- package/docs/openai-plugin.md +3 -3
- package/docs/philosophy.md +1 -1
- package/docs/platform-capabilities.md +2 -2
- package/docs/platform-compatibility.json +2 -2
- package/docs/reflection.md +1 -1
- package/docs/routing.md +2 -2
- package/docs/system-one-suggestion-gates.md +4 -4
- package/docs/troubleshooting.md +9 -35
- package/docs/workflow-runtime.md +19 -18
- package/docs/workflows/environment-detection.md +11 -9
- package/docs/workflows/fable-discipline.md +6 -5
- package/docs/workflows/fable-mode.md +6 -5
- package/docs/workflows/harness-everything.md +5 -5
- package/docs/workflows/improve-codebase-architecture.md +10 -8
- package/docs/workflows/install-cognitive-os.md +5 -5
- package/docs/workflows/tdd.md +9 -9
- package/docs/workflows/zoom-out.md +20 -30
- package/environment-detection/SKILL.md +2 -2
- package/environment-detection/references/shell-syntax-rules.md +1 -1
- package/eval-harness/SKILL.md +1 -1
- package/eval-harness/references/scoring-rubric.md +3 -3
- package/evals/zoom-out/eval.yaml +2 -2
- package/evals/zoom-out/tasks/negative-productive-iteration.yaml +15 -0
- package/evals/zoom-out/tasks/negative-trivial-edit.yaml +6 -6
- package/evals/zoom-out/tasks/positive-first-failure.yaml +15 -0
- package/evals/zoom-out/tasks/positive-repair-loop.yaml +1 -1
- package/fable-discipline/SKILL.md +3 -3
- package/fable-discipline/references/discipline-rules.md +1 -1
- package/fable-mode/SKILL.md +1 -1
- package/fable-mode/execution-guardrails/SKILL.md +2 -4
- package/fable-mode/execution-guardrails/references/guardrail-rules.md +3 -3
- package/fable-mode/fable-haiku/SKILL.md +1 -1
- package/fable-mode/fable-opus/SKILL.md +2 -2
- package/fable-mode/fable-sonnet/SKILL.md +1 -1
- package/fable-mode/references/execution-phases.md +2 -2
- package/harness-everything/SKILL.md +3 -3
- package/harness-everything/references/router-workflow-plan.md +2 -2
- package/harness-everything/references/skill-registry.md +2 -2
- package/harness-everything/references/triage-and-tiers.md +5 -5
- package/harness-everything/scripts/bootstrap.js +1 -26
- package/harness-everything/scripts/kernel-router-core.js +2 -3
- package/harness-everything/scripts/kernel-router.js +1 -1
- package/harness-everything/scripts/router-contract-core.js +1 -1
- package/harness-everything/scripts/routing-keywords.json +0 -2
- package/hooks/hooks.json +0 -33
- package/hooks/scripts/lib/harness-state.js +5 -6
- package/hooks/scripts/lib/learning-opportunity.js +3 -13
- package/hooks/scripts/openai-session-start.js +2 -4
- package/improve-codebase-architecture/SKILL.md +3 -3
- package/improve-codebase-architecture/guides/refactoring-workflow.md +5 -4
- package/install-cognitive-os/SKILL.md +3 -3
- package/opencode-plugin/README.md +12 -43
- package/opencode-plugin/index.mjs +21 -368
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +2 -4
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/hooks.json +0 -14
- package/plugins/harness-everything/hooks/scripts/lib/harness-state.js +5 -6
- package/plugins/harness-everything/hooks/scripts/lib/learning-opportunity.js +3 -13
- package/plugins/harness-everything/hooks/scripts/lib/workspace.js +2 -2
- package/plugins/harness-everything/hooks/scripts/openai-session-start.js +2 -4
- package/plugins/harness-everything/hooks/session-start.js +2 -4
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/scripts/lib/advisory-text.js +2 -2
- package/plugins/harness-everything/scripts/lib/workspace.js +2 -2
- package/plugins/harness-everything/skills/environment-detection/SKILL.md +2 -2
- package/plugins/harness-everything/skills/environment-detection/references/shell-syntax-rules.md +1 -1
- package/plugins/harness-everything/skills/eval-harness/SKILL.md +1 -1
- package/plugins/harness-everything/skills/eval-harness/references/scoring-rubric.md +3 -3
- package/plugins/harness-everything/skills/fable-discipline/SKILL.md +3 -3
- package/plugins/harness-everything/skills/fable-discipline/references/discipline-rules.md +1 -1
- package/plugins/harness-everything/skills/fable-mode/SKILL.md +1 -1
- package/plugins/harness-everything/skills/fable-mode/execution-guardrails/SKILL.md +2 -4
- package/plugins/harness-everything/skills/fable-mode/execution-guardrails/references/guardrail-rules.md +3 -3
- package/plugins/harness-everything/skills/fable-mode/fable-haiku/SKILL.md +1 -1
- package/plugins/harness-everything/skills/fable-mode/fable-opus/SKILL.md +2 -2
- package/plugins/harness-everything/skills/fable-mode/fable-sonnet/SKILL.md +1 -1
- package/plugins/harness-everything/skills/fable-mode/references/execution-phases.md +2 -2
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +3 -3
- package/plugins/harness-everything/skills/harness-everything/references/router-workflow-plan.md +2 -2
- package/plugins/harness-everything/skills/harness-everything/references/skill-registry.md +2 -2
- package/plugins/harness-everything/skills/harness-everything/references/triage-and-tiers.md +5 -5
- package/plugins/harness-everything/skills/harness-everything/scripts/bootstrap.js +1 -26
- package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router-core.js +2 -3
- package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/router-contract-core.js +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +0 -2
- package/plugins/harness-everything/skills/improve-codebase-architecture/SKILL.md +3 -3
- package/plugins/harness-everything/skills/improve-codebase-architecture/guides/refactoring-workflow.md +5 -4
- package/plugins/harness-everything/skills/install-cognitive-os/SKILL.md +3 -3
- package/plugins/harness-everything/skills/self-evolve/SKILL.md +1 -1
- package/plugins/harness-everything/skills/self-evolve/references/memory-resolution.md +3 -3
- package/plugins/harness-everything/skills/self-evolve/schemas/lesson-candidate.schema.json +4 -1
- package/plugins/harness-everything/skills/self-evolve/scripts/lesson-candidate.js +1 -0
- package/plugins/harness-everything/skills/skill-creator/SKILL.md +1 -1
- package/plugins/harness-everything/skills/skill-creator/references/quality-checklist.md +1 -1
- package/plugins/harness-everything/skills/skill-creator/references/quality-principles.md +4 -4
- package/plugins/harness-everything/skills/tdd/SKILL.md +2 -2
- package/plugins/harness-everything/skills/tdd/references/core-discipline.md +3 -5
- package/plugins/harness-everything/skills/todo-driven-workflow/SKILL.md +2 -2
- package/plugins/harness-everything/skills/zoom-out/SKILL.md +14 -26
- package/plugins/harness-everything/skills/zoom-out/references/circuit-breaker.md +18 -62
- package/references/platform-advisory-template.md +3 -9
- package/sbom.cdx.json +7 -7
- package/scripts/dispatch.js +340 -0
- package/scripts/lib/advisory-text.js +2 -2
- package/scripts/lib/workspace.js +2 -2
- package/self-evolve/SKILL.md +1 -1
- package/self-evolve/references/memory-resolution.md +3 -3
- package/self-evolve/schemas/lesson-candidate.schema.json +4 -1
- package/self-evolve/scripts/lesson-candidate.js +1 -0
- package/skill-creator/SKILL.md +1 -1
- package/skill-creator/references/quality-checklist.md +1 -1
- package/skill-creator/references/quality-principles.md +4 -4
- package/submission/openai/test-cases.json +5 -5
- package/tdd/SKILL.md +2 -2
- package/tdd/references/core-discipline.md +3 -5
- package/todo-driven-workflow/SKILL.md +2 -2
- package/zoom-out/SKILL.md +14 -26
- package/zoom-out/references/circuit-breaker.md +18 -62
- package/behavioral-evals/opencode-hardlock-live.js +0 -17
- package/behavioral-evals/opencode-reflection-gate-live.js +0 -342
- package/ci/mechanism-31-opencode-hardlock-evidence.test.js +0 -82
- package/evals/zoom-out/tasks/negative-first-edge-case-review.yaml +0 -16
- package/evals/zoom-out/tasks/positive-repeated-failure.yaml +0 -15
- package/hooks/scripts/reset-circuit-breaker.js +0 -30
- package/hooks/scripts/rule-of-3-tracker.js +0 -165
- package/hooks/scripts/rule-of-3.js +0 -171
- package/plugins/harness-everything/hooks/scripts/reset-circuit-breaker.js +0 -30
- package/plugins/harness-everything/hooks/scripts/rule-of-3-tracker.js +0 -165
- package/plugins/harness-everything/hooks/scripts/rule-of-3.js +0 -171
|
@@ -1,74 +1,30 @@
|
|
|
1
|
-
# Zoom Out —
|
|
1
|
+
# Zoom Out — Voluntary Diagnosis Guidance
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This reference helps an agent decide whether a fresh diagnosis would improve the next step. It does not impose a trigger or pause.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Reassessment path
|
|
6
6
|
|
|
7
7
|
```mermaid
|
|
8
8
|
flowchart TD
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
CheckPath -- Template / Path Unavailable --> WritePlatform[Write to .github/harness-everything/zoom-out-report.md or Inline]
|
|
15
|
-
|
|
16
|
-
WriteSession --> DecisionGate{4. Phase 4: Decision Gate}
|
|
17
|
-
WritePlatform --> DecisionGate
|
|
18
|
-
|
|
19
|
-
DecisionGate -- Clear Untried Path Identified --> Resume[RESUME: Execute Fresh Diagnosis in TDD / Fable]
|
|
20
|
-
DecisionGate -- Requirement Conflict / Access Gap --> Escalate[ESCALATE: Present 2-3 Options + Recommendation to Human]
|
|
21
|
-
|
|
22
|
-
Resume --> Resolved{5. Problem Cracking Succeeds?}
|
|
23
|
-
Resolved -- Yes --> SelfEvolve[Call self-evolve to Persist Insight]
|
|
24
|
-
Resolved -- No (3 More Matching Failures) --> CeaseFire
|
|
9
|
+
Signal[New evidence or unclear next step] --> Review[Revisit goal, assumptions, and evidence]
|
|
10
|
+
Review --> Useful{Is the next action justified?}
|
|
11
|
+
Useful -- Yes --> Continue[Continue and verify]
|
|
12
|
+
Useful -- No --> Update[Revise the approach or surface a genuine user decision]
|
|
13
|
+
Update --> Continue
|
|
25
14
|
```
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
- **Rule of 3 (Repeated Failures)**: Attempting to fix the same error or test failure 3 times without progress.
|
|
29
|
-
- **Divergence**: Fixing one bug repeatedly introduces new secondary errors.
|
|
30
|
-
- **Repair loop (feature level)**: Two consecutive review or fix rounds on the same feature each surface new defects in the same decision class (for example "is this the trusted checker?"), even though every command succeeded.
|
|
31
|
-
- The Rule of 3 hook cannot see this. It counts same-signature command failures in one session. Successful review findings do not increment it, and unrelated successes can leave an existing count in place. New sessions and different failure signatures do not accumulate a feature's review history.
|
|
32
|
-
- The signal comes from review history: prior findings and their dispositions, the round count per class in an error ledger, or the reviewer noticing the pattern. It is a prompt to reflect, not a lock. The hook gate in the skill contract applies only to the three-failure trigger.
|
|
33
|
-
- "Same decision class" means the same acceptance decision under the same trust assumptions, possibly at different sites. "Same directory" or "validation" is too broad. Count a repeated or renamed finding once, and treat missing history as unknown, not zero.
|
|
34
|
-
- Phase 2 here means: list every finding so far by decision class, state the acceptance clause each violates, and inventory every site (callers, state readers, Stop consumers) that makes the same decision. Findings that map to no acceptance clause stay `unresolved` for the owner instead of becoming new fixes.
|
|
35
|
-
- RESUME by using the inventory to choose the smallest justified correction (which may be one shared fix, or no code change), then re-trace one normal end-to-end acceptance path. Unresolved findings need scope adjudication, not speculative repairs.
|
|
36
|
-
- Whoever applies the fixes counts too. Before fixing review round 2 or later on one feature, classify each new finding against the decision classes of earlier rounds. A class that also appeared in the previous round MUST trigger Phase 2 before any edit; do not wait for the reviewer to name the pattern.
|
|
37
|
-
- A one-shot reviewer cannot see the previous round on its own. The packet carries the current acceptance anchor, a link to the previous comparable report with its revision, the prior finding IDs and dispositions, and the fix made since.
|
|
38
|
-
- **Goal Drift**: Execution strays far from the initial task objective.
|
|
39
|
-
- **User Instruction**: The user requests a step back ("zoom out", "step back", "stop and think").
|
|
40
|
-
|
|
41
|
-
## 2. Phase 1 — Cease Fire
|
|
42
|
-
- Pause code editing attempts immediately.
|
|
43
|
-
- Refrain from guessing quick fixes without checking underlying facts first.
|
|
44
|
-
|
|
45
|
-
## 3. Phase 2 — Rebuild Full Picture (Reflect & Fact-Check)
|
|
46
|
-
Use read-only tools (Read / Grep / Glob) to gather fresh evidence:
|
|
47
|
-
1. **Restate Goal**: Review original objectives from task/todo context.
|
|
48
|
-
2. **Examine Failed Attempts**: Identify the underlying belief behind each failed fix.
|
|
49
|
-
3. **Fact-Check Assumptions**: Verify files, configuration, logs, and docs directly.
|
|
50
|
-
4. **Elevate Perspective**: Check for layer mismatches, API contract misunderstandings, or conflicting requirements.
|
|
51
|
-
5. **Form Fresh Diagnosis**: Synthesize a comprehensive explanation that accounts for all observed evidence.
|
|
52
|
-
|
|
53
|
-
## 4. Phase 3 — Write Reflection Report
|
|
54
|
-
Copy `zoom-out/templates/zoom-out-report.template.md` to the `zoom-out-report.md` path given in the Rule of 3 message and fill it in section by section.
|
|
55
|
-
|
|
56
|
-
A complete report automatically releases the circuit breaker on hook-enabled systems.
|
|
16
|
+
An agent may reassess at the first meaningful signal or later. A run may continue when attempts add evidence, narrow the cause, and justify the next check. Neither a failure count nor review history forces a pause.
|
|
57
17
|
|
|
58
|
-
##
|
|
18
|
+
## Make the diagnosis concrete
|
|
59
19
|
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
|
|
20
|
+
- Restate the goal and the acceptance clause that matters.
|
|
21
|
+
- List observed results and assumptions separately; include which attempted changes were informative.
|
|
22
|
+
- When the issue may span consumers, inventory callers and state readers before choosing a correction.
|
|
23
|
+
- Group findings by the acceptance decision they affect. Keep findings with no matching clause unresolved for the owner instead of inventing extra scope.
|
|
24
|
+
- Select the smallest next check or change that distinguishes the remaining explanations.
|
|
63
25
|
|
|
64
|
-
|
|
65
|
-
> The real blocker is a [requirement conflict / architecture trade-off / destructive step / access gap], which is your call, not mine.
|
|
66
|
-
> Option A: [...] (trade-off: ...). Option B: [...] (trade-off: ...).
|
|
67
|
-
> I recommend A because [...]. Which direction do you choose?"
|
|
26
|
+
If a review or repair reveals the same decision problem at another site, trace all sites that make that decision before editing again. Productive iteration remains valid while it keeps reducing uncertainty.
|
|
68
27
|
|
|
69
|
-
|
|
28
|
+
## Optional record
|
|
70
29
|
|
|
71
|
-
|
|
72
|
-
- **Self-recovery path**: a valid report ending in `RESUME` releases the breaker — reload the appropriate execution mode (`tdd`, `fable-mode`) and execute the new diagnosis. If the SAME failure signature accumulates 3 more failures, start another zoom-out/reflection cycle.
|
|
73
|
-
- **Human path**: after the human answers an `ESCALATE`, continue under their direction. `npm run harness:reset` (or a new session / `/clear`) is an optional manual state clear for recovery or maintenance; it is not required merely because the breaker re-tripped.
|
|
74
|
-
- Either way, once the problem is ultimately cracked, feed the insight to `self-evolve`.
|
|
30
|
+
A written summary can help a handoff or preserve a useful diagnosis, but no report, token, unlock, reset, or escalation ritual is required. When a note helps, record the goal, evidence, changed understanding, next action, and any decision that belongs to the user. The template at `<this-skill-dir>/templates/zoom-out-report.template.md` is optional.
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
// Compatibility shim for callers that used the pre-#190 probe name.
|
|
5
|
-
// The current live contract is the Rule-of-3 reflection gate plus re-trip.
|
|
6
|
-
const probe = require('./opencode-reflection-gate-live');
|
|
7
|
-
|
|
8
|
-
if (require.main === module) {
|
|
9
|
-
console.warn('Deprecated: use behavioral-evals/opencode-reflection-gate-live.js.');
|
|
10
|
-
try { process.exitCode = probe.main(process.argv.slice(2)); }
|
|
11
|
-
catch (error) {
|
|
12
|
-
console.error(error && error.stack ? error.stack : error);
|
|
13
|
-
process.exitCode = 1;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = probe;
|
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const os = require('os');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const crypto = require('crypto');
|
|
8
|
-
const { execFileSync, spawnSync } = require('child_process');
|
|
9
|
-
|
|
10
|
-
const ROOT = path.resolve(__dirname, '..');
|
|
11
|
-
const PLUGIN_SOURCE = path.join(ROOT, 'opencode-plugin', 'index.mjs');
|
|
12
|
-
const INSTALLED_PLUGIN_NAME = 'harness-enforcement.js';
|
|
13
|
-
const PRE_REFLECTION_MARKER = 'PRE_REFLECTION_OK';
|
|
14
|
-
const FIRST_CYCLE_MARKERS = ['CYCLE1_ATTEMPT_2', 'CYCLE1_ATTEMPT_3'];
|
|
15
|
-
const BLOCKED_MARKER = 'BLOCKED_WHILE_REFLECTION_PENDING';
|
|
16
|
-
const RETRIP_MARKERS = ['RETRIP_1', 'RETRIP_2', 'RETRIP_3'];
|
|
17
|
-
const REFLECTION_REQUIRED_MESSAGE = 'Harness reflection is required before another code edit.';
|
|
18
|
-
const PROBE_CONTRACT = 'rule-of-3-reflection-retrip-v2';
|
|
19
|
-
|
|
20
|
-
const PROMPT = [
|
|
21
|
-
'You are running a live Harness Rule-of-3 reflection-gate integration probe. Follow this sequence exactly.',
|
|
22
|
-
'',
|
|
23
|
-
'Mutable targets are limited to probe.txt and the exact Harness reflection artifact path that the plugin gives you.',
|
|
24
|
-
'Do not modify package.json, opencode.json, .opencode/plugins, or any test command. The npm test failure is intentional and must remain unchanged.',
|
|
25
|
-
'',
|
|
26
|
-
`1. First edit probe.txt and append the exact marker ${PRE_REFLECTION_MARKER}, then end the turn.`,
|
|
27
|
-
`2. After the first verification-failure follow-up, append ${FIRST_CYCLE_MARKERS[0]} and end the turn. After the second, append ${FIRST_CYCLE_MARKERS[1]} and end the turn. The third matching failure should request reflection.`,
|
|
28
|
-
`3. When reflection is first required, BEFORE writing the report, attempt one edit to probe.txt appending ${BLOCKED_MARKER}. Do not work around the rejection. Then write the required report to the exact path with sections ## Goal, ## Failed Attempts, ## Verified Facts, ## Diagnosis, and ## Decision. The first non-empty Decision line must begin with RESUME:, and include the exact reflection token.`,
|
|
29
|
-
`4. After that reflection is accepted, make three successive edits to probe.txt, one per verification cycle, appending ${RETRIP_MARKERS[0]}, then ${RETRIP_MARKERS[1]}, then ${RETRIP_MARKERS[2]}. End the turn after each edit so the intentional verification failure is observed each time.`,
|
|
30
|
-
'5. When Harness requests reflection for the second three-failure cycle, stop. Do not write a second reflection report, reset Harness state, or start a different session.',
|
|
31
|
-
].join('\n');
|
|
32
|
-
|
|
33
|
-
function sha256File(file) {
|
|
34
|
-
return crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function safeCommand(command, args, options = {}) {
|
|
38
|
-
try {
|
|
39
|
-
return execFileSync(command, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], ...options }).trim();
|
|
40
|
-
} catch (error) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function recursiveFind(root, basename) {
|
|
46
|
-
if (!fs.existsSync(root)) return [];
|
|
47
|
-
const out = [];
|
|
48
|
-
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
49
|
-
const file = path.join(root, entry.name);
|
|
50
|
-
if (entry.isDirectory()) out.push(...recursiveFind(file, basename));
|
|
51
|
-
else if (entry.isFile() && entry.name === basename) out.push(file);
|
|
52
|
-
}
|
|
53
|
-
return out;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function parseToolInputs(transcriptFile) {
|
|
57
|
-
if (!fs.existsSync(transcriptFile)) return [];
|
|
58
|
-
const events = [];
|
|
59
|
-
for (const line of fs.readFileSync(transcriptFile, 'utf8').split(/\r?\n/)) {
|
|
60
|
-
if (!line.trim()) continue;
|
|
61
|
-
let event;
|
|
62
|
-
try { event = JSON.parse(line); } catch { continue; }
|
|
63
|
-
const part = event && event.part;
|
|
64
|
-
if (!part || !String(event.type || '').includes('tool')) continue;
|
|
65
|
-
const input = part.state && part.state.input !== undefined ? part.state.input : part.input;
|
|
66
|
-
events.push({ tool: part.tool || 'tool', input: input ?? {} });
|
|
67
|
-
}
|
|
68
|
-
return events;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function readJson(file) {
|
|
72
|
-
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function verifyReflection(file) {
|
|
76
|
-
if (!fs.existsSync(file)) return false;
|
|
77
|
-
const text = fs.readFileSync(file, 'utf8');
|
|
78
|
-
const sections = ['## Goal', '## Failed Attempts', '## Verified Facts', '## Diagnosis', '## Decision'];
|
|
79
|
-
if (!sections.every((section) => text.includes(section))) return false;
|
|
80
|
-
const decision = text.split('## Decision')[1] || '';
|
|
81
|
-
const first = decision.split(/\r?\n/).map((line) => line.trim()).find(Boolean);
|
|
82
|
-
return Boolean(first && /^RESUME\s*:/i.test(first) && /Reflection token:\s*[A-Za-z0-9_-]+/i.test(text));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function verifyEvidence(evidenceDir) {
|
|
86
|
-
const transcriptFile = path.join(evidenceDir, 'transcript.jsonl');
|
|
87
|
-
const stderrFile = path.join(evidenceDir, 'stderr.txt');
|
|
88
|
-
const probeFile = path.join(evidenceDir, 'workspace', 'probe.txt');
|
|
89
|
-
const breakerFile = path.join(evidenceDir, 'state', 'circuit-breaker.json');
|
|
90
|
-
const complianceFile = path.join(evidenceDir, 'state', 'compliance.json');
|
|
91
|
-
const reflectionFile = path.join(evidenceDir, 'state', 'zoom-out-report.md');
|
|
92
|
-
const metadataFile = path.join(evidenceDir, 'metadata.json');
|
|
93
|
-
|
|
94
|
-
const checks = [];
|
|
95
|
-
const check = (name, pass, detail = null) => checks.push({ name, pass: Boolean(pass), detail });
|
|
96
|
-
|
|
97
|
-
let metadata = {};
|
|
98
|
-
try { metadata = readJson(metadataFile); } catch { /* reported below */ }
|
|
99
|
-
check('metadata records current reflection-gate probe contract', metadata.probeContract === PROBE_CONTRACT, metadata.probeContract || null);
|
|
100
|
-
check('metadata records isolated Harness state', metadata.stateIsolated === true, metadata.stateIsolation || null);
|
|
101
|
-
check('metadata records .js auto-discovery destination', metadata.installedPluginName === INSTALLED_PLUGIN_NAME, metadata.installedPluginName || null);
|
|
102
|
-
check('installed plugin is byte-identical to the recorded canonical source',
|
|
103
|
-
typeof metadata.pluginSha256 === 'string' && metadata.pluginSha256.length === 64 && metadata.installedPluginSha256 === metadata.pluginSha256,
|
|
104
|
-
{ source: metadata.pluginSha256 || null, installed: metadata.installedPluginSha256 || null });
|
|
105
|
-
|
|
106
|
-
const combined = [transcriptFile, stderrFile]
|
|
107
|
-
.filter((file) => fs.existsSync(file))
|
|
108
|
-
.map((file) => fs.readFileSync(file, 'utf8'))
|
|
109
|
-
.join('\n');
|
|
110
|
-
check('live host surfaced the Harness reflection gate error', combined.includes(REFLECTION_REQUIRED_MESSAGE));
|
|
111
|
-
|
|
112
|
-
const toolInputs = parseToolInputs(transcriptFile);
|
|
113
|
-
const toolText = toolInputs.map((entry) => JSON.stringify(entry.input)).join('\n');
|
|
114
|
-
check('structured tool trace contains the pre-reflection edit attempt', toolText.includes(PRE_REFLECTION_MARKER));
|
|
115
|
-
check('structured tool trace contains both first-cycle retry edits', FIRST_CYCLE_MARKERS.every((marker) => toolText.includes(marker)));
|
|
116
|
-
check('structured tool trace contains the edit attempt blocked by reflectionPending', toolText.includes(BLOCKED_MARKER));
|
|
117
|
-
check('structured tool trace contains all three post-reflection re-trip edits', RETRIP_MARKERS.every((marker) => toolText.includes(marker)));
|
|
118
|
-
|
|
119
|
-
let probe = '';
|
|
120
|
-
try { probe = fs.readFileSync(probeFile, 'utf8'); } catch { /* reported below */ }
|
|
121
|
-
check('pre-reflection edit reached the filesystem', probe.includes(PRE_REFLECTION_MARKER), probe || null);
|
|
122
|
-
check('first-cycle retry edits reached the filesystem', FIRST_CYCLE_MARKERS.every((marker) => probe.includes(marker)), probe || null);
|
|
123
|
-
check('reflection-pending blocked marker did not reach the filesystem', probe.length > 0 && !probe.includes(BLOCKED_MARKER), probe || null);
|
|
124
|
-
check('all post-reflection re-trip edits reached the filesystem before the second reflection', RETRIP_MARKERS.every((marker) => probe.includes(marker)), probe || null);
|
|
125
|
-
|
|
126
|
-
let breaker = null;
|
|
127
|
-
try { breaker = readJson(breakerFile); } catch { /* reported below */ }
|
|
128
|
-
const activeSignature = breaker && breaker.reflectionSignature;
|
|
129
|
-
const activeEntry = activeSignature && breaker.failures && breaker.failures[activeSignature];
|
|
130
|
-
check('snapshot has no retired hardLock field',
|
|
131
|
-
breaker && !Object.prototype.hasOwnProperty.call(breaker, 'hardLock'),
|
|
132
|
-
breaker);
|
|
133
|
-
check('snapshot proves one completed reflection',
|
|
134
|
-
breaker && Number.isFinite(breaker.lastReflection) &&
|
|
135
|
-
typeof breaker.lastReflectionSignature === 'string' && breaker.lastReflectionSignature.length > 0,
|
|
136
|
-
breaker);
|
|
137
|
-
check('three more matching failures request a second reflection instead of a permanent lock',
|
|
138
|
-
breaker && breaker.reflectionPending === true &&
|
|
139
|
-
typeof breaker.reflectionToken === 'string' && breaker.reflectionToken.length > 0 &&
|
|
140
|
-
typeof activeSignature === 'string' && activeSignature.length > 0,
|
|
141
|
-
breaker);
|
|
142
|
-
check('the re-trip is for the same verification signature that was previously reflected',
|
|
143
|
-
breaker && activeSignature === breaker.lastReflectionSignature,
|
|
144
|
-
breaker);
|
|
145
|
-
check('post-reflection signature count restarted and reached the next Rule-of-3 boundary',
|
|
146
|
-
activeEntry && Number.isInteger(activeEntry.count) && activeEntry.count >= 3,
|
|
147
|
-
activeEntry || null);
|
|
148
|
-
check('first reflection artifact is valid and preserved', verifyReflection(reflectionFile));
|
|
149
|
-
|
|
150
|
-
let compliance = null;
|
|
151
|
-
try { compliance = readJson(complianceFile); } catch { /* reported below */ }
|
|
152
|
-
check('compliance records at least two forced reflections',
|
|
153
|
-
compliance && Number.isInteger(compliance.reflectionsForced) && compliance.reflectionsForced >= 2,
|
|
154
|
-
compliance);
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
schemaVersion: 2,
|
|
158
|
-
verifiedAt: new Date().toISOString(),
|
|
159
|
-
passed: checks.every((entry) => entry.pass),
|
|
160
|
-
checks,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function archiveSelectedState(stateHome, evidenceDir) {
|
|
165
|
-
const candidates = [];
|
|
166
|
-
for (const file of recursiveFind(stateHome, 'circuit-breaker.json')) {
|
|
167
|
-
try {
|
|
168
|
-
const state = readJson(file);
|
|
169
|
-
candidates.push({ file, state });
|
|
170
|
-
} catch {
|
|
171
|
-
candidates.push({ file, state: null });
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const selected = candidates.find((candidate) => {
|
|
175
|
-
const state = candidate.state;
|
|
176
|
-
const signature = state && state.reflectionSignature;
|
|
177
|
-
const entry = signature && state.failures && state.failures[signature];
|
|
178
|
-
return Boolean(
|
|
179
|
-
state &&
|
|
180
|
-
state.reflectionPending === true &&
|
|
181
|
-
Number.isFinite(state.lastReflection) &&
|
|
182
|
-
signature &&
|
|
183
|
-
state.lastReflectionSignature === signature &&
|
|
184
|
-
entry &&
|
|
185
|
-
Number.isInteger(entry.count) &&
|
|
186
|
-
entry.count >= 3 &&
|
|
187
|
-
!Object.prototype.hasOwnProperty.call(state, 'hardLock')
|
|
188
|
-
);
|
|
189
|
-
}) || null;
|
|
190
|
-
const rawStateDir = path.join(evidenceDir, 'raw-state');
|
|
191
|
-
if (fs.existsSync(stateHome)) fs.cpSync(stateHome, rawStateDir, { recursive: true });
|
|
192
|
-
if (!selected) return { selected: null, candidates: candidates.map(({ file, state }) => ({ file, state })) };
|
|
193
|
-
|
|
194
|
-
const sourceDir = path.dirname(selected.file);
|
|
195
|
-
const targetDir = path.join(evidenceDir, 'state');
|
|
196
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
197
|
-
for (const name of ['circuit-breaker.json', 'edit-state.json', 'compliance.json', 'zoom-out-report.md']) {
|
|
198
|
-
const source = path.join(sourceDir, name);
|
|
199
|
-
if (fs.existsSync(source)) fs.copyFileSync(source, path.join(targetDir, name));
|
|
200
|
-
}
|
|
201
|
-
return {
|
|
202
|
-
selected: path.relative(stateHome, sourceDir).split(path.sep).join('/'),
|
|
203
|
-
candidates: candidates.map(({ file, state }) => ({ file: path.relative(stateHome, file).split(path.sep).join('/'), state })),
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function defaultEvidenceDir() {
|
|
208
|
-
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
209
|
-
return path.join(ROOT, 'benchmarks', 'results', 'live-host', `opencode-reflection-gate-${stamp}`);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function runLive(options = {}) {
|
|
213
|
-
const evidenceDir = path.resolve(options.out || defaultEvidenceDir());
|
|
214
|
-
if (fs.existsSync(evidenceDir) && fs.readdirSync(evidenceDir).length > 0) {
|
|
215
|
-
throw new Error(`evidence output directory must be empty or absent: ${evidenceDir}`);
|
|
216
|
-
}
|
|
217
|
-
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-opencode-reflection-gate-'));
|
|
218
|
-
const workspace = path.join(tempRoot, 'workspace');
|
|
219
|
-
const stateHome = path.join(tempRoot, 'state-home');
|
|
220
|
-
const transcriptFile = path.join(evidenceDir, 'transcript.jsonl');
|
|
221
|
-
const stderrFile = path.join(evidenceDir, 'stderr.txt');
|
|
222
|
-
const workspaceEvidenceDir = path.join(evidenceDir, 'workspace');
|
|
223
|
-
const model = options.model || process.env.BEHAVIORAL_MODEL || null;
|
|
224
|
-
const opencode = options.opencode || 'opencode';
|
|
225
|
-
|
|
226
|
-
fs.mkdirSync(workspace, { recursive: true });
|
|
227
|
-
fs.mkdirSync(path.join(workspace, '.opencode', 'plugins'), { recursive: true });
|
|
228
|
-
fs.mkdirSync(evidenceDir, { recursive: true });
|
|
229
|
-
fs.writeFileSync(path.join(workspace, 'probe.txt'), 'baseline\n', 'utf8');
|
|
230
|
-
fs.writeFileSync(path.join(workspace, 'package.json'), JSON.stringify({
|
|
231
|
-
name: 'harness-opencode-reflection-gate-live-probe',
|
|
232
|
-
private: true,
|
|
233
|
-
version: '0.0.0',
|
|
234
|
-
scripts: { test: "node -e \"console.log('HARNESS_LIVE_PROBE_RED'); process.exit(1)\"" },
|
|
235
|
-
}, null, 2));
|
|
236
|
-
fs.writeFileSync(path.join(workspace, 'opencode.json'), JSON.stringify({ $schema: 'https://opencode.ai/config.json' }, null, 2));
|
|
237
|
-
const installedPluginFile = path.join(workspace, '.opencode', 'plugins', INSTALLED_PLUGIN_NAME);
|
|
238
|
-
fs.copyFileSync(PLUGIN_SOURCE, installedPluginFile);
|
|
239
|
-
fs.writeFileSync(path.join(evidenceDir, 'prompt.txt'), PROMPT + '\n', 'utf8');
|
|
240
|
-
|
|
241
|
-
const args = ['run', '--format', 'json', '--auto', '--dir', workspace];
|
|
242
|
-
if (model) args.push('-m', model);
|
|
243
|
-
args.push(PROMPT);
|
|
244
|
-
const startedAt = new Date().toISOString();
|
|
245
|
-
const result = spawnSync(opencode, args, {
|
|
246
|
-
cwd: workspace,
|
|
247
|
-
env: { ...process.env, HARNESS_STATE_HOME: stateHome },
|
|
248
|
-
encoding: 'utf8',
|
|
249
|
-
timeout: 20 * 60 * 1000,
|
|
250
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
251
|
-
windowsHide: true,
|
|
252
|
-
});
|
|
253
|
-
fs.writeFileSync(transcriptFile, result.stdout || '', 'utf8');
|
|
254
|
-
fs.writeFileSync(stderrFile, result.stderr || '', 'utf8');
|
|
255
|
-
fs.mkdirSync(workspaceEvidenceDir, { recursive: true });
|
|
256
|
-
for (const name of ['probe.txt', 'package.json', 'opencode.json']) {
|
|
257
|
-
const source = path.join(workspace, name);
|
|
258
|
-
if (fs.existsSync(source)) fs.copyFileSync(source, path.join(workspaceEvidenceDir, name));
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const stateArchive = archiveSelectedState(stateHome, evidenceDir);
|
|
262
|
-
const metadata = {
|
|
263
|
-
schemaVersion: 2,
|
|
264
|
-
probeContract: PROBE_CONTRACT,
|
|
265
|
-
startedAt,
|
|
266
|
-
completedAt: new Date().toISOString(),
|
|
267
|
-
opencodeVersion: safeCommand(opencode, ['--version']),
|
|
268
|
-
nodeVersion: process.version,
|
|
269
|
-
platform: process.platform,
|
|
270
|
-
arch: process.arch,
|
|
271
|
-
repoCommit: safeCommand('git', ['rev-parse', 'HEAD'], { cwd: ROOT }),
|
|
272
|
-
model,
|
|
273
|
-
installedPluginName: INSTALLED_PLUGIN_NAME,
|
|
274
|
-
pluginSource: 'opencode-plugin/index.mjs',
|
|
275
|
-
pluginSha256: sha256File(PLUGIN_SOURCE),
|
|
276
|
-
installedPluginSha256: sha256File(installedPluginFile),
|
|
277
|
-
stateIsolated: true,
|
|
278
|
-
stateIsolation: { env: 'HARNESS_STATE_HOME', location: 'temporary' },
|
|
279
|
-
opencodeExitStatus: result.status,
|
|
280
|
-
opencodeSignal: result.signal || null,
|
|
281
|
-
spawnError: result.error ? String(result.error.message || result.error) : null,
|
|
282
|
-
selectedState: stateArchive.selected,
|
|
283
|
-
stateCandidates: stateArchive.candidates,
|
|
284
|
-
};
|
|
285
|
-
fs.writeFileSync(path.join(evidenceDir, 'metadata.json'), JSON.stringify(metadata, null, 2));
|
|
286
|
-
|
|
287
|
-
const verification = verifyEvidence(evidenceDir);
|
|
288
|
-
fs.writeFileSync(path.join(evidenceDir, 'verification.json'), JSON.stringify(verification, null, 2));
|
|
289
|
-
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
290
|
-
|
|
291
|
-
console.log(`${verification.passed ? 'PASS' : 'FAIL'}: ${evidenceDir}`);
|
|
292
|
-
for (const item of verification.checks) {
|
|
293
|
-
console.log(` ${item.pass ? 'PASS' : 'FAIL'} ${item.name}${item.pass || item.detail == null ? '' : ` — ${typeof item.detail === 'string' ? item.detail : JSON.stringify(item.detail)}`}`);
|
|
294
|
-
}
|
|
295
|
-
return verification.passed ? 0 : 1;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function flag(args, name) {
|
|
299
|
-
const index = args.indexOf(name);
|
|
300
|
-
return index >= 0 ? args[index + 1] : undefined;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function main(argv = process.argv.slice(2)) {
|
|
304
|
-
const command = argv[0];
|
|
305
|
-
if (command === 'run') {
|
|
306
|
-
return runLive({ out: flag(argv, '--out'), model: flag(argv, '--model'), opencode: flag(argv, '--opencode') });
|
|
307
|
-
}
|
|
308
|
-
if (command === 'verify') {
|
|
309
|
-
const evidenceDir = argv[1];
|
|
310
|
-
if (!evidenceDir) throw new Error('verify requires an evidence directory');
|
|
311
|
-
const verification = verifyEvidence(path.resolve(evidenceDir));
|
|
312
|
-
fs.writeFileSync(path.join(path.resolve(evidenceDir), 'verification.json'), JSON.stringify(verification, null, 2));
|
|
313
|
-
console.log(`${verification.passed ? 'PASS' : 'FAIL'}: ${path.resolve(evidenceDir)}`);
|
|
314
|
-
for (const item of verification.checks) console.log(` ${item.pass ? 'PASS' : 'FAIL'} ${item.name}`);
|
|
315
|
-
return verification.passed ? 0 : 1;
|
|
316
|
-
}
|
|
317
|
-
console.log('Usage:\n node behavioral-evals/opencode-reflection-gate-live.js run [--out <dir>] [--model <model>] [--opencode <path>]\n node behavioral-evals/opencode-reflection-gate-live.js verify <evidence-dir>');
|
|
318
|
-
return command ? 1 : 0;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (require.main === module) {
|
|
322
|
-
try { process.exitCode = main(); }
|
|
323
|
-
catch (error) {
|
|
324
|
-
console.error(error && error.stack ? error.stack : error);
|
|
325
|
-
process.exitCode = 1;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
module.exports = {
|
|
330
|
-
BLOCKED_MARKER,
|
|
331
|
-
FIRST_CYCLE_MARKERS,
|
|
332
|
-
INSTALLED_PLUGIN_NAME,
|
|
333
|
-
PRE_REFLECTION_MARKER,
|
|
334
|
-
PROBE_CONTRACT,
|
|
335
|
-
PROMPT,
|
|
336
|
-
REFLECTION_REQUIRED_MESSAGE,
|
|
337
|
-
RETRIP_MARKERS,
|
|
338
|
-
main,
|
|
339
|
-
parseToolInputs,
|
|
340
|
-
verifyEvidence,
|
|
341
|
-
verifyReflection,
|
|
342
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const helper = require('./test-helper');
|
|
4
|
-
const {
|
|
5
|
-
BLOCKED_MARKER,
|
|
6
|
-
FIRST_CYCLE_MARKERS,
|
|
7
|
-
INSTALLED_PLUGIN_NAME,
|
|
8
|
-
PRE_REFLECTION_MARKER,
|
|
9
|
-
PROBE_CONTRACT,
|
|
10
|
-
REFLECTION_REQUIRED_MESSAGE,
|
|
11
|
-
RETRIP_MARKERS,
|
|
12
|
-
verifyEvidence,
|
|
13
|
-
} = require('../behavioral-evals/opencode-reflection-gate-live');
|
|
14
|
-
|
|
15
|
-
console.log('\n[31] opencode live Rule-of-3 reflection evidence contract...');
|
|
16
|
-
|
|
17
|
-
function writeJson(file, value) {
|
|
18
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
19
|
-
fs.writeFileSync(file, JSON.stringify(value, null, 2));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function makeEvidence() {
|
|
23
|
-
const dir = helper.tempDir('.mechanism-test-opencode-live-reflection-evidence');
|
|
24
|
-
fs.mkdirSync(path.join(dir, 'workspace'), { recursive: true });
|
|
25
|
-
fs.mkdirSync(path.join(dir, 'state'), { recursive: true });
|
|
26
|
-
const pluginHash = 'a'.repeat(64);
|
|
27
|
-
writeJson(path.join(dir, 'metadata.json'), {
|
|
28
|
-
schemaVersion: 2, probeContract: PROBE_CONTRACT, stateIsolated: true,
|
|
29
|
-
installedPluginName: INSTALLED_PLUGIN_NAME, pluginSha256: pluginHash, installedPluginSha256: pluginHash,
|
|
30
|
-
});
|
|
31
|
-
const toolEvent = (input) => JSON.stringify({ type: 'tool', part: { tool: 'edit', state: { input } } });
|
|
32
|
-
fs.writeFileSync(path.join(dir, 'transcript.jsonl'), [
|
|
33
|
-
toolEvent({ filePath: 'probe.txt', text: PRE_REFLECTION_MARKER }),
|
|
34
|
-
...FIRST_CYCLE_MARKERS.map((marker) => toolEvent({ filePath: 'probe.txt', text: marker })),
|
|
35
|
-
toolEvent({ filePath: 'probe.txt', text: BLOCKED_MARKER }),
|
|
36
|
-
...RETRIP_MARKERS.map((marker) => toolEvent({ filePath: 'probe.txt', text: marker })),
|
|
37
|
-
JSON.stringify({ type: 'text', part: { text: REFLECTION_REQUIRED_MESSAGE } }), '',
|
|
38
|
-
].join('\n'));
|
|
39
|
-
fs.writeFileSync(path.join(dir, 'stderr.txt'), '', 'utf8');
|
|
40
|
-
fs.writeFileSync(path.join(dir, 'workspace', 'probe.txt'), ['baseline', PRE_REFLECTION_MARKER, ...FIRST_CYCLE_MARKERS, ...RETRIP_MARKERS, ''].join('\n'), 'utf8');
|
|
41
|
-
const signature = 'npm test: HARNESS_LIVE_PROBE_RED';
|
|
42
|
-
writeJson(path.join(dir, 'state', 'circuit-breaker.json'), {
|
|
43
|
-
failures: { [signature]: { count: 3, firstSeen: 5, lastSeen: 8 } },
|
|
44
|
-
lastReflection: 4, lastReflectionSignature: signature, reflectionPending: true,
|
|
45
|
-
reflectionRequestedAt: 8, reflectionToken: 'second456', reflectionSignature: signature,
|
|
46
|
-
});
|
|
47
|
-
writeJson(path.join(dir, 'state', 'compliance.json'), {
|
|
48
|
-
sessionStart: 1, totalEdits: 6, verifiedEdits: 0, circuitBreakerTrips: 2, reflectionsForced: 2,
|
|
49
|
-
});
|
|
50
|
-
fs.writeFileSync(path.join(dir, 'state', 'zoom-out-report.md'), [
|
|
51
|
-
'## Goal','exercise the Rule-of-3 reflection gate','## Failed Attempts','three controlled failures',
|
|
52
|
-
'## Verified Facts','the verification fixture intentionally stays red','## Diagnosis','this is a live enforcement probe',
|
|
53
|
-
'## Decision','RESUME: reproduce the same three-failure cycle after reflection','Reflection token: first123','',
|
|
54
|
-
].join('\n'));
|
|
55
|
-
return dir;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const valid=makeEvidence(); let result=verifyEvidence(valid);
|
|
60
|
-
helper.check('31. complete attributed reflection/re-trip evidence passes',result.passed,JSON.stringify(result.checks.filter((entry)=>!entry.pass)));
|
|
61
|
-
|
|
62
|
-
const wrongPlugin=makeEvidence(); const mf=path.join(wrongPlugin,'metadata.json'); const md=JSON.parse(fs.readFileSync(mf,'utf8'));
|
|
63
|
-
md.installedPluginSha256='b'.repeat(64); writeJson(mf,md); result=verifyEvidence(wrongPlugin);
|
|
64
|
-
helper.check('31. evidence fails when the installed plugin hash differs from the canonical source hash',!result.passed&&result.checks.some((e)=>e.name==='installed plugin is byte-identical to the recorded canonical source'&&!e.pass),JSON.stringify(result.checks));
|
|
65
|
-
|
|
66
|
-
const landed=makeEvidence(); fs.appendFileSync(path.join(landed,'workspace','probe.txt'),`${BLOCKED_MARKER}\n`); result=verifyEvidence(landed);
|
|
67
|
-
helper.check('31. reflection gate fails if the blocked marker reached the filesystem',!result.passed&&result.checks.some((e)=>e.name==='reflection-pending blocked marker did not reach the filesystem'&&!e.pass),JSON.stringify(result.checks));
|
|
68
|
-
|
|
69
|
-
const retired=makeEvidence(); const bf=path.join(retired,'state','circuit-breaker.json'); const bs=JSON.parse(fs.readFileSync(bf,'utf8')); bs.hardLock=true; writeJson(bf,bs); result=verifyEvidence(retired);
|
|
70
|
-
helper.check('31. current evidence rejects the retired hardLock field',!result.passed&&result.checks.some((e)=>e.name==='snapshot has no retired hardLock field'&&!e.pass),JSON.stringify(result.checks));
|
|
71
|
-
|
|
72
|
-
const noRetrip=makeEvidence(); const rf=path.join(noRetrip,'state','circuit-breaker.json'); const rs=JSON.parse(fs.readFileSync(rf,'utf8')); rs.reflectionPending=false; rs.reflectionToken=null; rs.reflectionSignature=null; writeJson(rf,rs); result=verifyEvidence(noRetrip);
|
|
73
|
-
helper.check('31. evidence fails without a second Rule-of-3 reflection request',!result.passed&&result.checks.some((e)=>e.name==='three more matching failures request a second reflection instead of a permanent lock'&&!e.pass),JSON.stringify(result.checks));
|
|
74
|
-
|
|
75
|
-
const noAttempt=makeEvidence(); const tf=path.join(noAttempt,'transcript.jsonl'); fs.writeFileSync(tf,fs.readFileSync(tf,'utf8').split(/\r?\n/).filter((line)=>!line.includes(BLOCKED_MARKER)).join('\n')); result=verifyEvidence(noAttempt);
|
|
76
|
-
helper.check('31. evidence fails when no structured edit was attempted during reflectionPending',!result.passed&&result.checks.some((e)=>e.name==='structured tool trace contains the edit attempt blocked by reflectionPending'&&!e.pass),JSON.stringify(result.checks));
|
|
77
|
-
|
|
78
|
-
const noReflection=makeEvidence(); fs.rmSync(path.join(noReflection,'state','zoom-out-report.md')); result=verifyEvidence(noReflection);
|
|
79
|
-
helper.check('31. evidence fails without the preserved first reflection artifact',!result.passed&&result.checks.some((e)=>e.name==='first reflection artifact is valid and preserved'&&!e.pass),JSON.stringify(result.checks));
|
|
80
|
-
|
|
81
|
-
helper.finish();
|
|
82
|
-
} catch(error) { helper.check('31. OpenCode Rule-of-3 reflection live evidence contract',false,error.stack); helper.finish(); }
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
id: negative-first-edge-case-review-001
|
|
2
|
-
name: A first review finding an edge case is ordinary review
|
|
3
|
-
description: One edge case in the first review does not establish repeated repair rounds.
|
|
4
|
-
tags:
|
|
5
|
-
- negative-trigger
|
|
6
|
-
inputs:
|
|
7
|
-
prompt: "Review this PR for the first time. The reviewer found one edge case in an unchanged state reader. Assess the finding against the acceptance clause and trace the affected consumers. No earlier review or corrective round has taken place."
|
|
8
|
-
expected:
|
|
9
|
-
should_trigger: false
|
|
10
|
-
graders:
|
|
11
|
-
- type: text
|
|
12
|
-
name: not-contains-keywords
|
|
13
|
-
config:
|
|
14
|
-
contains:
|
|
15
|
-
- "circuit breaker tripped"
|
|
16
|
-
- "reflection report"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
id: positive-repeated-failure-001
|
|
2
|
-
name: Repeated failure triggers reflection
|
|
3
|
-
description: "Reflect-first circuit breaker - after 3 failures, stop edits, rebuild the full picture with read-only tools, write a fact-check report, then resume or escalate. USE FOR: \"you are stuck in a loop\", \"the same error keeps failing\", \"rethink your assumptions\". DO NOT USE FOR: \"routine single-failure debugging\", \"greenfield planning without failures\"."
|
|
4
|
-
tags:
|
|
5
|
-
- positive-trigger
|
|
6
|
-
inputs:
|
|
7
|
-
prompt: "You are stuck in a loop: the same error keeps failing with this TypeError even after three fixes. Step back and rethink your assumptions before trying again."
|
|
8
|
-
expected:
|
|
9
|
-
should_trigger: true
|
|
10
|
-
graders:
|
|
11
|
-
- type: text
|
|
12
|
-
name: contains-keywords
|
|
13
|
-
config:
|
|
14
|
-
contains:
|
|
15
|
-
- "zoom-out"
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Manual escape hatch for the Rule of 3 circuit breaker. Run this directly
|
|
3
|
-
// in your own terminal (not through the agent — Bash is blocked while the
|
|
4
|
-
// breaker is tripped) to clear it without waiting for a new session.
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const { getWorkspaceRoot, getSessionDir, readCurrentSession } = require('./lib/harness-state');
|
|
8
|
-
|
|
9
|
-
// This is run directly by the human, not through the agent, so there's no
|
|
10
|
-
// hook payload to read a session_id from - resolve "the session that's
|
|
11
|
-
// currently blocked" via the pointer bootstrap.js wrote at its last
|
|
12
|
-
// SessionStart.
|
|
13
|
-
const root = getWorkspaceRoot();
|
|
14
|
-
const harnessDir = getSessionDir(root, readCurrentSession(root));
|
|
15
|
-
const stateFile = path.join(harnessDir, 'rule-of-3-state.json');
|
|
16
|
-
const reportFile = path.join(harnessDir, 'zoom-out-report.md');
|
|
17
|
-
|
|
18
|
-
if (fs.existsSync(stateFile)) {
|
|
19
|
-
fs.unlinkSync(stateFile);
|
|
20
|
-
console.log('Rule of 3 circuit breaker cleared.');
|
|
21
|
-
} else {
|
|
22
|
-
console.log('Rule of 3 circuit breaker is not currently tripped.');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// A human reset is a full clear: the stale reflection report belongs to the
|
|
26
|
-
// loop that was just abandoned.
|
|
27
|
-
if (fs.existsSync(reportFile)) {
|
|
28
|
-
fs.unlinkSync(reportFile);
|
|
29
|
-
console.log('Stale zoom-out report removed.');
|
|
30
|
-
}
|