harness-everything 0.57.4 → 1.0.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 (67) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.releaserc.json +2 -0
  4. package/AGENTS.md +8 -2
  5. package/CHANGELOG.md +23 -0
  6. package/README.md +4 -4
  7. package/benchmarks/results/live-host/agy-2026-11-22/README.md +49 -0
  8. package/benchmarks/results/live-host/agy-2026-11-23/README.md +48 -0
  9. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/README.md +40 -0
  10. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/edit-state-final.json +11 -0
  11. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/events-2026-11-24.jsonl +103 -0
  12. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/host-version.txt +3 -0
  13. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/live-event-trace-probe.js +11 -0
  14. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/plugin-load-lines.txt +2 -0
  15. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/reminder-excerpt.txt +1 -0
  16. package/ci/doc-capability-consistency.test.js +15 -3
  17. package/ci/lib/opencode-v2-driver.js +169 -0
  18. package/ci/mechanism-2ao-plugin-sync.test.js +235 -2
  19. package/ci/mechanism-2n-opencode-plugin.test.js +387 -223
  20. package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +24 -15
  21. package/ci/mechanism-2u-issue-42-regressions.test.js +41 -2
  22. package/ci/mechanism-2w-platform-compatibility.test.js +29 -5
  23. package/ci/mechanism-2x-release-automation.test.js +3 -1
  24. package/ci/mechanism-30-opencode-plugin-loadability.test.js +78 -45
  25. package/ci/mechanism-338-opencode-async.test.js +367 -194
  26. package/ci/mechanism-341-opencode-lane.test.js +143 -183
  27. package/ci/mechanism-39-opencode-verify-outcomes.test.js +118 -86
  28. package/ci/mechanism-394-opencode-ledger-lesson.test.js +46 -97
  29. package/ci/mechanism-397-opencode-observations.test.js +58 -47
  30. package/ci/mechanism-453-opencode-v2-driver.test.js +51 -0
  31. package/ci/mechanism-453-opencode-v2-only-events.test.js +241 -0
  32. package/ci/mechanism-agy-hooks.test.js +1096 -0
  33. package/ci/mechanism-agy-plugin-package.test.js +76 -0
  34. package/ci/telemetry.test.js +31 -24
  35. package/docs/architecture.md +4 -2
  36. package/docs/platform-capabilities.md +62 -26
  37. package/docs/platform-compatibility.json +41 -6
  38. package/docs/system-one-observations.md +1 -1
  39. package/docs/telemetry.md +1 -1
  40. package/docs/troubleshooting.md +2 -2
  41. package/hooks/scripts/agy-post-tool.js +124 -0
  42. package/hooks/scripts/agy-pre-invocation.js +185 -0
  43. package/hooks/scripts/agy-pre-tool.js +158 -0
  44. package/hooks/scripts/agy-session-start.js +54 -0
  45. package/hooks/scripts/agy-stop.js +152 -0
  46. package/hooks/scripts/lib/agy-adapter-core.js +168 -0
  47. package/hooks/scripts/state-persist.js +50 -10
  48. package/opencode-plugin/README.md +60 -66
  49. package/opencode-plugin/index.mjs +11 -13
  50. package/opencode-plugin/plugin.json +1 -1
  51. package/package.json +1 -1
  52. package/plugins/harness-everything/.antigravity-plugin/plugin.json +18 -0
  53. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  54. package/plugins/harness-everything/hooks/scripts/agy-post-tool.js +124 -0
  55. package/plugins/harness-everything/hooks/scripts/agy-pre-invocation.js +185 -0
  56. package/plugins/harness-everything/hooks/scripts/agy-pre-tool.js +158 -0
  57. package/plugins/harness-everything/hooks/scripts/agy-session-start.js +54 -0
  58. package/plugins/harness-everything/hooks/scripts/agy-stop.js +152 -0
  59. package/plugins/harness-everything/hooks/scripts/lib/agy-adapter-core.js +168 -0
  60. package/plugins/harness-everything/hooks/scripts/state-persist.js +50 -10
  61. package/plugins/harness-everything/hooks.json +44 -0
  62. package/plugins/harness-everything/plugin.json +1 -1
  63. package/plugins/harness-everything/rules/AGENTS.md +117 -0
  64. package/sbom.cdx.json +12 -12
  65. package/scripts/plugin-sync.js +105 -14
  66. package/scripts/sync-openai-plugin.js +16 -1
  67. package/scripts/sync-release-version.js +1 -0
@@ -0,0 +1,168 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+
6
+ function readJsonStdin(timeoutMs = 1500) {
7
+ return new Promise(resolve => {
8
+ let raw = '';
9
+ let settled = false;
10
+
11
+ const timer = setTimeout(() => {
12
+ if (settled) return;
13
+ settled = true;
14
+ try {
15
+ resolve(raw.trim() ? JSON.parse(raw) : {});
16
+ } catch (_) {
17
+ resolve({});
18
+ }
19
+ }, timeoutMs);
20
+
21
+ process.stdin.setEncoding('utf8');
22
+ process.stdin.on('data', chunk => { raw += chunk; });
23
+ process.stdin.on('end', () => {
24
+ if (settled) return;
25
+ settled = true;
26
+ clearTimeout(timer);
27
+ try {
28
+ resolve(raw.trim() ? JSON.parse(raw) : {});
29
+ } catch (_) {
30
+ resolve({});
31
+ }
32
+ });
33
+ process.stdin.on('error', () => {
34
+ if (settled) return;
35
+ settled = true;
36
+ clearTimeout(timer);
37
+ resolve({});
38
+ });
39
+ });
40
+ }
41
+
42
+ function resolveKernelRouter() {
43
+ const candidates = [
44
+ path.join(__dirname, '..', '..', '..', 'skills', 'harness-everything', 'scripts', 'kernel-router.js'),
45
+ path.join(__dirname, '..', '..', '..', 'harness-everything', 'scripts', 'kernel-router.js'),
46
+ path.join(__dirname, '..', '..', 'harness-everything', 'scripts', 'kernel-router.js')
47
+ ];
48
+ return candidates.find(candidate => fs.existsSync(candidate)) || null;
49
+ }
50
+
51
+ function getAgySessionId(payload) {
52
+ if (!payload || typeof payload !== 'object') return '';
53
+ const candidate = payload.conversationId || payload.session_id || payload.sessionId || '';
54
+ return typeof candidate === 'string' ? candidate.trim() : String(candidate || '').trim();
55
+ }
56
+
57
+ function getAgyWorkspacePaths(payload) {
58
+ if (!payload || typeof payload !== 'object') return [];
59
+ const roots = [];
60
+ if (Array.isArray(payload.workspacePaths)) {
61
+ for (const entry of payload.workspacePaths) {
62
+ if (typeof entry === 'string' && entry.trim()) roots.push(entry.trim());
63
+ }
64
+ }
65
+ if (typeof payload.cwd === 'string' && payload.cwd.trim()) {
66
+ roots.push(payload.cwd.trim());
67
+ }
68
+ return [...new Set(roots)];
69
+ }
70
+
71
+ function getAgyEffectiveCwd(payload) {
72
+ if (payload && typeof payload === 'object') {
73
+ if (typeof payload.cwd === 'string' && payload.cwd.trim()) {
74
+ return payload.cwd.trim();
75
+ }
76
+ if (Array.isArray(payload.workspacePaths)) {
77
+ const first = payload.workspacePaths.find(entry => typeof entry === 'string' && entry.trim());
78
+ if (first) return first.trim();
79
+ }
80
+ }
81
+ return process.cwd();
82
+ }
83
+
84
+ function normalizeAgyStatePayload(payload, overrideCwd) {
85
+ const base = payload && typeof payload === 'object' ? payload : {};
86
+ const sessionId = getAgySessionId(base);
87
+ const effectiveCwd = (typeof overrideCwd === 'string' && overrideCwd.trim())
88
+ ? overrideCwd.trim()
89
+ : getAgyEffectiveCwd(base);
90
+
91
+ return {
92
+ ...base,
93
+ ...(sessionId ? { session_id: sessionId, sessionId, conversationId: sessionId } : {}),
94
+ cwd: effectiveCwd
95
+ };
96
+ }
97
+
98
+ const MAX_SYMLINK_HOPS = 40;
99
+ const realpath = fs.realpathSync.native || fs.realpathSync;
100
+
101
+ function canonicalizePath(targetPath, baseDir, depth = 0) {
102
+ if (depth > MAX_SYMLINK_HOPS) return null;
103
+ if (typeof targetPath !== 'string' || !targetPath.trim()) return null;
104
+ const resolved = (typeof baseDir === 'string' && baseDir.trim())
105
+ ? path.resolve(baseDir, targetPath)
106
+ : path.resolve(targetPath);
107
+
108
+ try {
109
+ return realpath(resolved);
110
+ } catch (_) {
111
+ const suffix = [];
112
+ let current = resolved;
113
+ while (true) {
114
+ try {
115
+ const stat = fs.lstatSync(current);
116
+ if (stat.isSymbolicLink()) {
117
+ const linkTarget = fs.readlinkSync(current);
118
+ const resolvedLink = path.resolve(path.dirname(current), linkTarget);
119
+ const nextPath = suffix.length > 0 ? path.join(resolvedLink, ...suffix) : resolvedLink;
120
+ return canonicalizePath(nextPath, null, depth + 1);
121
+ }
122
+ } catch (_) {
123
+ // Entry does not exist yet; continue ascending to nearest existing ancestor.
124
+ }
125
+
126
+ const parent = path.dirname(current);
127
+ if (parent === current) return resolved;
128
+ suffix.unshift(path.basename(current));
129
+ current = parent;
130
+ try {
131
+ const realAncestor = realpath(current);
132
+ return path.join(realAncestor, ...suffix);
133
+ } catch (_) {}
134
+ }
135
+ }
136
+ }
137
+
138
+ function isOutOfBoundsPath(filePath, allowedRoots, baseDir) {
139
+ if (typeof filePath !== 'string' || !filePath.trim()) return true;
140
+ const roots = (Array.isArray(allowedRoots) ? allowedRoots : [allowedRoots])
141
+ .filter(root => typeof root === 'string' && root.trim());
142
+ if (roots.length === 0) return false;
143
+
144
+ const resolveBase = (typeof baseDir === 'string' && baseDir.trim()) ? baseDir : roots[0];
145
+ const canonicalTarget = canonicalizePath(filePath, resolveBase);
146
+ if (!canonicalTarget) return true;
147
+
148
+ const normTarget = process.platform === 'win32' ? canonicalTarget.toLowerCase() : canonicalTarget;
149
+ return !roots.some(root => {
150
+ const canonicalRoot = canonicalizePath(root);
151
+ if (!canonicalRoot) return false;
152
+ const normRoot = process.platform === 'win32' ? canonicalRoot.toLowerCase() : canonicalRoot;
153
+ if (normTarget === normRoot) return true;
154
+ const prefix = normRoot.endsWith(path.sep) ? normRoot : normRoot + path.sep;
155
+ return normTarget.startsWith(prefix);
156
+ });
157
+ }
158
+
159
+ module.exports = {
160
+ readJsonStdin,
161
+ resolveKernelRouter,
162
+ getAgySessionId,
163
+ getAgyWorkspacePaths,
164
+ getAgyEffectiveCwd,
165
+ normalizeAgyStatePayload,
166
+ canonicalizePath,
167
+ isOutOfBoundsPath
168
+ };
@@ -2,10 +2,40 @@
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
4
  const { getWorkspaceRoot, getSessionDir } = require('./lib/harness-state');
5
- const { cwdOf, classifyShell, isVerificationShell, directMutationInWorkspace } = require('./lib/workflow-isolation');
5
+ const { cwdOf, classifyShell, isVerificationShell, directMutationInWorkspace, mutationPaths } = require('./lib/workflow-isolation');
6
+ const { getAgyWorkspacePaths, isOutOfBoundsPath } = require('./lib/agy-adapter-core');
6
7
  const { observeTool } = require('./lib/telemetry');
7
8
  const { readCodexToolOutcome } = require('./lib/codex-tool-outcome');
8
9
  const codex = process.argv.includes('--codex');
10
+ const agy = process.argv.includes('--agy');
11
+
12
+ function agyMutationTargets(payload, toolName) {
13
+ if (toolName === 'apply_patch') {
14
+ return mutationPaths(payload).map(v => String(v || '').trim()).filter(Boolean);
15
+ }
16
+ const input = (payload && (payload.tool_input ?? payload.toolInput ?? payload.input)) || {};
17
+ const candidates = [
18
+ input.file_path,
19
+ input.filePath,
20
+ input.path,
21
+ input.TargetFile,
22
+ input.Path,
23
+ input.targetFile
24
+ ];
25
+ const target = candidates.find(value => typeof value === 'string' && value.trim());
26
+ return target ? [target.trim()] : [];
27
+ }
28
+
29
+ function agyDirectMutationInWorkspace(payload, mutationCwd, root, toolName) {
30
+ const targets = agyMutationTargets(payload, toolName);
31
+ if (targets.length === 0) return false;
32
+ const agyRoots = getAgyWorkspacePaths(payload);
33
+ if (typeof root === 'string' && root.trim() && !agyRoots.includes(root.trim())) {
34
+ agyRoots.push(root.trim());
35
+ }
36
+ if (agyRoots.length === 0) return false;
37
+ return targets.some(target => !isOutOfBoundsPath(target, agyRoots, mutationCwd));
38
+ }
9
39
 
10
40
  function isSuccessfulMetadataStep(command, cwd) {
11
41
  // A line break starts a second shell command, so it can never be metadata-only.
@@ -83,14 +113,19 @@ function processState(payload) {
83
113
  const stdout = codexResult?.stdout ?? toolResponse.stdout ?? payload.stdout ?? '';
84
114
  const stderr = codexResult?.stderr ?? toolResponse.stderr ?? payload.stderr ?? payload.error ?? '';
85
115
  const rawExitCode = toolResponse.exitCode ?? toolResponse.exit_code ?? payload.exitCode;
86
- const exitCode = codex ? codexResult.exitCode : typeof rawExitCode === 'number' ? rawExitCode : undefined;
116
+ const exitCode = codex ? codexResult.exitCode
117
+ : agy ? (Number.isInteger(rawExitCode) ? rawExitCode : undefined)
118
+ : typeof rawExitCode === 'number' ? rawExitCode : undefined;
87
119
  const stderrSignal = typeof stderr === 'string' && stderr.trim().length > 0;
88
120
  const hookEvent = captureEventName;
89
121
  const isSuccessEvent = hookEvent === 'PostToolUse';
122
+ const agyErrorSignal = agy && typeof payload.error === 'string' && payload.error.trim().length > 0;
90
123
  const isFailed = codex ? codexResult.outcome === 'failure' :
91
- hookEvent === 'PostToolUseFailure' || (exitCode !== undefined && exitCode !== 0) ||
124
+ hookEvent === 'PostToolUseFailure' || agyErrorSignal || (exitCode !== undefined && exitCode !== 0) ||
92
125
  (!isSuccessEvent && exitCode === undefined && stderrSignal);
93
- const verifiedSuccess = codex ? codexResult.outcome === 'success' : !isFailed && (isSuccessEvent || exitCode === 0);
126
+ const verifiedSuccess = codex ? codexResult.outcome === 'success'
127
+ : agy ? (!isFailed && exitCode === 0)
128
+ : !isFailed && (isSuccessEvent || exitCode === 0);
94
129
  const toolName = payload.tool_name || payload.tool || 'command';
95
130
  let editAfterCapture = false;
96
131
  let stateOnlyCandidate = false;
@@ -98,11 +133,13 @@ function processState(payload) {
98
133
  let output = (stderrSignal ? stderr : stdout) || (typeof payload.output === 'string' ? payload.output : '');
99
134
  if (output.length > 500) output = '...' + output.slice(-500);
100
135
  state.status = 'failed'; state.timestamp = new Date().toISOString(); state.tool = toolName; state.exitCode = exitCode; state.errorSummary = output.trim();
101
- } else if ((!codex || verifiedSuccess) && state.status === 'failed') {
136
+ } else if (((!codex && !agy) || verifiedSuccess) && state.status === 'failed') {
102
137
  state.lastResolved = { tool: state.tool, timestamp: state.timestamp }; state.status = 'idle'; state.timestamp = new Date().toISOString(); delete state.exitCode; delete state.errorSummary;
103
138
  }
104
139
  const isDirectTool = toolName === 'Edit' || toolName === 'Write' || toolName === 'apply_patch';
105
- if (isDirectTool && directMutationInWorkspace(payload, cwdOf(payload, root), root)) state.lastEditAt = Date.now();
140
+ if (isDirectTool && (agy
141
+ ? agyDirectMutationInWorkspace(payload, cwdOf(payload, root), root, toolName)
142
+ : directMutationInWorkspace(payload, cwdOf(payload, root), root))) state.lastEditAt = Date.now();
106
143
  const isShell = toolName === 'Bash' || toolName === 'PowerShell' || toolName === 'exec_command';
107
144
  const command = (payload.tool_input && payload.tool_input.command) || '';
108
145
  if (isShell) {
@@ -114,10 +151,6 @@ function processState(payload) {
114
151
  { toolName, sessionId, agentId: payload.agent_id }));
115
152
  const metadataStep = !stateOnlyCandidate && verifiedSuccess
116
153
  && isSuccessfulMetadataStep(command, cwdOf(payload, root));
117
- if (!metadataStep && commandClass !== 'read-only' && commandClass !== 'worktree-setup') {
118
- if (stateOnlyCandidate) editAfterCapture = true;
119
- else state.lastEditAt = Date.now();
120
- }
121
154
  // The host-specific outcome must confirm success before verification advances.
122
155
  // Pilot ON only: a registered, argv-validated doc-check that resolves to this install's own runtime is the document
123
156
  // verification evidence, and only at the shipped pin (R3-02). Any other path earns no verification evidence. OFF stays legacy.
@@ -129,6 +162,13 @@ function processState(payload) {
129
162
  const verifies = stateOnlyCandidate ? false : docCheckCandidate
130
163
  ? Boolean(pinCheckable) && docCheck.fileDigest(installedCheck.installed) === docCheck.SHIPPED_DOC_CHECK_DIGEST
131
164
  : !(pilotEnabled && docCheck.trustRisk(command)) && isVerificationShell(command, { cwd: cwdOf(payload, root), root });
165
+ // On AGY hosts that omit shell error/exitCode, an unconfirmed verification-only command must not advance lastEditAt
166
+ // and defeat agy-stop.js's bounded continuation fingerprint.
167
+ const agyUnknownOutcomeVerify = agy && !verifiedSuccess && !isFailed && verifies;
168
+ if (!metadataStep && !agyUnknownOutcomeVerify && commandClass !== 'read-only' && commandClass !== 'worktree-setup') {
169
+ if (stateOnlyCandidate) editAfterCapture = true;
170
+ else state.lastEditAt = Date.now();
171
+ }
132
172
  if (verifiedSuccess && verifies) {
133
173
  const verifiedAt = Date.now();
134
174
  const verifiedExitCode = exitCode ?? null;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Adds edit tracking, verification reminders, prompt routing, and observation hooks for OpenCode.
4
4
 
5
- > **Evidence boundary:** the plugin is covered by deterministic mechanism tests. Live plugin loading remains unverified beyond one scoped surface: retained evidence supports project-scope `.js` loading and edit/verification state on OpenCode 1.18.31 (macOS) — [live-host evidence](../benchmarks/results/live-host/opencode-2026-09-16/README.md). That retained snapshot is historical: its final state was post-reset; the hard-lock was only an interactive observation with no retained blocked-tool trace. Reflection was operator-seeded, then agent-rewritten, so no behavioral-effectiveness claim is made. The current plugin does not force reflection or block edits based on verification history. Global scope, npm-package installation, and other host versions remain unverified. See [`../docs/platform-capabilities.md`](../docs/platform-capabilities.md).
5
+ > **Support and evidence boundary:** Harness supports the **OpenCode V2 plugin API only**; OpenCode 1.x / V1 is unsupported (#453). The plugin is covered by deterministic V2 mechanism tests. Tested V2 live observations cover one isolated OpenCode `2.1.4` (macOS 26.6.2) long-lived server run ([V2 lifecycle trace](../benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/README.md): V2 default-export load, V2 tool hooks, V2 event envelope + `session.execution.succeeded` completion, and completion → verification → reminder delivery; standalone `opencode run` exits before verification finishes), alongside OpenCode `2.1.3` (macOS, server-log load-only) and OpenCode `2.1.4` (macOS, [workspace trace](../benchmarks/results/live-host/opencode-2026-11-15-workspace/README.md)); router/context injection, observation recording, ledger lessons, session create/delete reset, cancellation, and a validated minimum patch version remain unverified. Retained historical/unsupported V1 evidence documents project-scope `.js` loading and edit/verification state on OpenCode 1.18.31 (macOS) — [live-host evidence](../benchmarks/results/live-host/opencode-2026-09-16/README.md). That retained snapshot is historical and does not establish current V2 capability: its final state was post-reset; the hard-lock was only an interactive observation with no retained blocked-tool trace. Reflection was operator-seeded, then agent-rewritten, so no behavioral-effectiveness claim is made. The current plugin does not force reflection or block edits based on verification history. Global scope, npm-package installation, and other host versions remain unverified. See [`../docs/platform-capabilities.md`](../docs/platform-capabilities.md).
6
6
 
7
7
  ## Problem
8
8
 
@@ -13,27 +13,25 @@ only SUGGEST rules (soft guidance). This means:
13
13
 
14
14
  ## The plugin
15
15
 
16
- **File:** `index.mjs` - the ESM plugin entrypoint. The OpenCode 2 adapter uses
17
- the documented prompt and context hooks; the V1 factory remains available for
18
- existing OpenCode 1 installations. There is no manifest-to-script
16
+ **File:** `index.mjs` - the OpenCode V2 ESM plugin entrypoint. Harness targets
17
+ the OpenCode V2 plugin API only; OpenCode 1.x / V1 is unsupported, and the
18
+ module's only public surface is its V2 default export
19
+ `{ id: "harness.enforcement", setup(ctx) }`. There is no manifest-to-script
19
20
  mechanism; an earlier version of this plugin assumed one (a `plugin.json`
20
21
  mapping event names to standalone scripts) and opencode never invoked it -
21
22
  see issue #37 for how that was found and fixed. **Naming caveat (issue
22
23
  #127):** opencode's discovery glob only matches `*.js`/`*.ts`, so the file
23
24
  must be copied to a `.js` name when installed - see Installation below.
24
25
 
25
- It implements edit tracking and verification reminders across OpenCode's hooks:
26
-
27
- The V1 factory follows opencode's plugin contract directly: the named
28
- `HarnessEnforcement` export is an async factory receiving the opencode context
29
- (`client`, `directory`, `project`, `worktree`, and `$`) and returning the hook
30
- map. Copying this one file into `.opencode/plugins/` under a `.js` name is
31
- enough for opencode to discover and invoke it; `plugin.json` is only a
32
- repository
33
- inventory and is not an opencode runtime manifest. The hook callbacks use the
34
- V1 `(input, output)` shape, including
35
- `output.args` when the host supplies tool arguments only in the result object.
36
- OpenCode 2's prompt injection and observation path resolves the canonical
26
+ It implements edit tracking, verification reminders, prompt/context routing,
27
+ and observation hooks through the OpenCode V2 plugin context:
28
+
29
+ `setup(ctx)` registers `ctx.session.hook("prompt|context")`,
30
+ `ctx.tool.hook("execute.before|after")`, and `ctx.event.subscribe()` and wires
31
+ them into a private internal enforcement core. Copying this one file into
32
+ `.opencode/plugins/` under a `.js` name is enough for opencode to discover and
33
+ invoke it; `plugin.json` is only a repository inventory and is not an opencode
34
+ runtime manifest. Prompt injection and observation capture resolve the canonical
37
35
  `harness-everything/scripts/kernel-router.js` and
38
36
  `hooks/scripts/lib/observations.js` from an ancestor Harness checkout/runtime.
39
37
 
@@ -42,16 +40,16 @@ OpenCode 2's prompt injection and observation path resolves the canonical
42
40
  Fires after every `edit`, `write` or `apply_patch` tool call and marks
43
41
  verification as pending.
44
42
 
45
- ### 2. Verification reminder (`event`, on `session.idle`)
43
+ ### 2. Verification reminder (`ctx.event.subscribe()`, on `session.execution.succeeded`)
46
44
 
47
- opencode has no "before complete" hook to block the way Claude Code's Stop
48
- hook does. `session.idle` - fired when the agent's turn ends - is the closest
49
- analog, and it cannot be blocked (the hook has no return value that denies
50
- it). So when it fires with verification still pending, the plugin runs the
51
- available `npm test` / `npm run lint` / `npm run build` scripts right there,
52
- and on failure calls `client.session.prompt()` to push a synthetic follow-up
53
- message into the session - forcing the agent to keep working instead of
54
- actually stopping.
45
+ OpenCode has no "before complete" hook to block the way Claude Code's Stop
46
+ hook does. `session.execution.succeeded` (carrying `data.sessionID`) - fired
47
+ when the agent's turn completes in OpenCode V2 - is the closest analog, and it
48
+ cannot be blocked. So when it fires with verification still pending, the plugin
49
+ runs the available `npm test` / `npm run lint` / `npm run build` scripts right
50
+ there, and on failure calls `ctx.session.prompt()` to push a synthetic follow-up
51
+ message into the session - prompting the agent to keep working instead of
52
+ stopping with unverified edits.
55
53
 
56
54
  The async runner streams stdout/stderr and gives the **whole ordered sequence**
57
55
  (`test`, `lint`, `build`) one wall-clock budget: 10 minutes by default, overridden
@@ -65,7 +63,7 @@ signal, or cancellation). The follow-up describes the verification outcome.
65
63
  |---|---|
66
64
  | Retained output | First and last 2,000 characters per stream; the final diagnostic shares a 2,000-character budget across streams, plus labels/elision markers |
67
65
  | Timeout/cancel | Terminate the shell/npm/script process group, then force-kill after 150 ms on POSIX; Windows uses `taskkill /T /F` |
68
- | Concurrent lifecycle | Duplicate idle events share the active run; a code edit or session reset aborts it; an idle arriving during cancellation waits for cleanup before verifying the newer edits; the V2 event stream continues consuming cancellation events; disposal awaits active child cleanup; stale results cannot clear newer edits or recreate deleted state |
66
+ | Concurrent lifecycle | Duplicate turn-completion events share the active run; a code edit or session reset aborts it; a completion arriving during cancellation waits for cleanup before verifying the newer edits; the V2 event stream continues consuming cancellation events; disposal awaits active child cleanup; stale results cannot clear newer edits or recreate deleted state |
69
67
 
70
68
  The event loop remains available while scripts run. The output-retention limit
71
69
  never becomes a check verdict. Mechanism tests cover large output, shared
@@ -73,28 +71,22 @@ budget, child cleanup and concurrent hooks; these are deterministic mechanism
73
71
  evidence, not a new live-host verification claim. Processes deliberately
74
72
  escaping the process group are outside this cleanup boundary.
75
73
 
76
- Idle handling is bounded: after a failed verification, the plugin records that
77
- the follow-up is pending and ignores repeated `session.idle` events until a new
78
- code edit arrives. If prompt delivery fails, the exact follow-up text is saved
79
- and retried on the next idle event without re-running verification.
74
+ Completion handling is bounded: after a failed verification, the plugin records
75
+ that the follow-up is pending and ignores repeated `session.execution.succeeded`
76
+ events until a new code edit arrives. If prompt delivery fails, the exact
77
+ follow-up text is saved and retried on the next completion event without
78
+ re-running verification.
80
79
 
81
80
  ## Installation
82
81
 
83
- **OpenCode 2.x:** the module default-exports
82
+ **OpenCode V2 plugin API only:** the module default-exports
84
83
  `{ id: "harness.enforcement", setup(ctx) }` and registers
85
84
  `ctx.session.hook("prompt|context")`, `ctx.tool.hook("execute.before|after")`,
86
- plus `ctx.event.subscribe()` through the OpenCode 2 plugin context. OpenCode 2
87
- never loads a named-export-only plugin: it fails with `Plugin must export a
88
- default definition with an id and an effect or setup function`
89
- (SchemaError at `["default"]`). The named `HarnessEnforcement` export stays
90
- available for OpenCode 1.x hosts: it receives the V1 context
91
- (`{client, directory}`) and returns a V1 hooks object
92
- (`tool.execute.before`, `tool.execute.after`, `event`); the V2 `setup`
93
- adapter wraps that factory and maps the V2 hook events onto it, so the
94
- enforcement logic is shared, not duplicated.
95
-
96
- The prompt/context routing and System One observation hooks are V2-only. The
97
- V1 factory keeps its existing enforcement hooks; it does not capture turns.
85
+ plus `ctx.event.subscribe()` through the OpenCode V2 plugin context. No named
86
+ V1 factory, host `session.idle`, or legacy session-id event fallback is
87
+ exported or supported; OpenCode 1.x / V1 is unsupported. OpenCode V2 rejects
88
+ named-export-only plugins with `Plugin must export a default definition with an
89
+ id and an effect or setup function` (SchemaError at `["default"]`).
98
90
 
99
91
  When OpenCode runs on Bun, its Harness router needs `node` on the OpenCode
100
92
  process's `PATH`. Run `node --version` from the same environment that launches
@@ -102,9 +94,6 @@ OpenCode and check it against the [Harness Node.js baseline](../docs/repository-
102
94
  If the router cannot start or load, OpenCode still admits prompts and logs a
103
95
  `router-unavailable` warning with a reason and per-plugin count.
104
96
 
105
- Direction:
106
- named factory (V1 hosts/tests) → default-export setup adapter → V2 domains.
107
-
108
97
  Copy `index.mjs` into opencode's plugin directory **under a `.js` filename**.
109
98
  The router and observation hooks resolve from a Harness checkout above the
110
99
  plugin, or from sibling `harness-everything/`, `hooks/scripts/`, and
@@ -126,16 +115,16 @@ cp -R scripts/lib ~/.config/opencode/scripts/
126
115
  Restart OpenCode after copying so the plugin is discovered at startup.
127
116
 
128
117
  The destination extension matters: opencode's plugin auto-discovery scans
129
- only `*.js` / `*.ts` files in those directories (`{plugin,plugins}/*.{ts,js}`
130
- in its v1 loader), so a `.mjs` copy is **silently never loaded** - no error,
131
- no hooks, no state. Verified live on opencode 1.18.31 with an extension A/B
132
- probe (see
118
+ only `*.js` / `*.ts` files in those directories, so a `.mjs` copy is **silently
119
+ never loaded** - no error, no hooks, no state. Keep the `.js` install filename
120
+ for current V2 installs (the original extension A/B probe is preserved as
121
+ historical evidence in
133
122
  [`benchmarks/results/live-host/opencode-2026-09-16/probe-control.md`](../benchmarks/results/live-host/opencode-2026-09-16/probe-control.md)).
134
123
 
135
124
  opencode auto-loads `.js`/`.ts` files dropped in those directories at startup -
136
- no `opencode.json` entry needed. This procedure tests directory discovery;
137
- explicit local-file configuration and npm-package installation are separate
138
- installation surfaces and were not verified in this run.
125
+ no `opencode.json` entry needed. Explicit local-file configuration and
126
+ npm-package installation are separate installation surfaces and remain
127
+ unverified.
139
128
 
140
129
  ## Manual verification CLI
141
130
 
@@ -169,20 +158,25 @@ session root.
169
158
 
170
159
  ## Testing
171
160
 
172
- `ci/mechanism-2n-opencode-plugin.test.js` imports `index.mjs` and drives its
173
- exported hooks directly with a mock `client`/`event` context - the same shape
174
- OpenCode's plugin loader passes in - covering edit → idle → reminder, repeated
175
- failures, legacy pending state remaining inert, prompt-delivery retry,
176
- repeated-idle idempotency, session isolation, reset behavior, and legacy-state
177
- migration. `ci/mechanism-2p-opencode-v2-entrypoint.test.js` exercises the same
178
- edit and legacy-state paths through the default V2 export.
179
-
180
- It does not launch a real opencode process; the test remains a deterministic
181
- hook-sequence check against the documented and source-verified hook signatures.
182
- A passing test is therefore mechanism evidence, not live-host loading evidence.
183
- Live-host evidence and the install-filename loadability guard live elsewhere:
184
- the host session artifact is
161
+ `ci/mechanism-2n-opencode-plugin.test.js` and
162
+ `ci/mechanism-2p-opencode-v2-entrypoint.test.js` import `index.mjs`, enforce the
163
+ V2-only default-export contract (`{ id, setup(ctx) }`), and drive the registered
164
+ V2 hooks with a mock V2 `ctx` - covering edit → `session.execution.succeeded` →
165
+ reminder, repeated failures, legacy pending state remaining inert,
166
+ prompt-delivery retry, repeated-completion idempotency, session isolation, reset
167
+ behavior, and legacy-state migration.
168
+
169
+ They do not launch a real opencode process; the tests remain deterministic
170
+ hook-sequence checks against the documented and source-verified V2 hook
171
+ signatures. A passing test is therefore mechanism evidence, not live-host
172
+ loading evidence. The isolated OpenCode 2.1.4 (macOS 26.6.2) V2 lifecycle trace
173
+ lives at
174
+ [`benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/`](../benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/),
175
+ the limited OpenCode 2.1.4 workspace trace lives at
176
+ [`benchmarks/results/live-host/opencode-2026-11-15-workspace/`](../benchmarks/results/live-host/opencode-2026-11-15-workspace/),
177
+ the historical/unsupported 1.18.31 archive lives at
185
178
  [`benchmarks/results/live-host/opencode-2026-09-16/`](../benchmarks/results/live-host/opencode-2026-09-16/),
186
179
  and `ci/mechanism-30-opencode-plugin-loadability.test.js` (npm script
187
180
  `test:opencode:loadability`) fails any change that reintroduces a
188
181
  silently-ignored install filename such as `harness-enforcement.mjs`.
182
+ Verification reminders need a long-lived server (`opencode serve` + `opencode run --server`); `opencode run --standalone` exits before verification completes.
@@ -661,7 +661,7 @@ function appendTelemetry(workspace, input) {
661
661
  }
662
662
  }
663
663
 
664
- export const HarnessEnforcement = async ({ client, directory, signal }) => {
664
+ const createEnforcement = async ({ client, directory, signal }) => {
665
665
  // State is resolved per real workspace and per opencode session. The CJS
666
666
  // hooks use the same workspaces/<key>/state/sessions/<id> contract, while
667
667
  // the old flat plugin state is intentionally left untouched because it is
@@ -1033,9 +1033,9 @@ export const HarnessEnforcement = async ({ client, directory, signal }) => {
1033
1033
  // function" (SchemaError at ["default"]) - this is what tripped the global
1034
1034
  // install on this machine's OpenCode 2.1.3.
1035
1035
  //
1036
- // The named `HarnessEnforcement` factory above keeps the hooks-object shape
1037
- // used by the repository mechanism tests (and by OpenCode 1.x hosts); this
1038
- // default export adapts it to the V2 hooks. Tool hook events are verified
1036
+ // The private `createEnforcement` factory above keeps an internal hooks-object
1037
+ // shape; this default export adapts it to the V2 hooks. OpenCode 1.x is not
1038
+ // supported. Tool hook events are verified
1039
1039
  // OpenCode 2.1.3 shapes: execute.before is {tool, sessionID, agent, messageID,
1040
1040
  // id, input} with `input` carrying the tool args; execute.after adds
1041
1041
  // {status, result | error}.
@@ -1129,11 +1129,11 @@ export default {
1129
1129
  const enforcementFor = workspace => {
1130
1130
  if (events.signal.aborted) return Promise.resolve(null)
1131
1131
  if (!enforcementByWorkspace.has(workspace)) {
1132
- enforcementByWorkspace.set(workspace, HarnessEnforcement({
1132
+ enforcementByWorkspace.set(workspace, createEnforcement({
1133
1133
  signal: events.signal,
1134
1134
  client: {
1135
1135
  session: {
1136
- // V1 shutdown path calls client.session.prompt({path, body}) twice;
1136
+ // The private core calls client.session.prompt({path, body}) twice;
1137
1137
  // map it onto the V2 session API instead of duplicating the code.
1138
1138
  prompt: ({ path, body }) =>
1139
1139
  ctx.session.prompt({
@@ -1309,13 +1309,11 @@ export default {
1309
1309
  try {
1310
1310
  for await (const raw of ctx.event.subscribe({ signal: events.signal })) {
1311
1311
  if (events.signal.aborted) break
1312
- // OpenCode 2.x events are flat with the session id at data.sessionID;
1313
- // V1 hosts keep it top-level. V2 hosts send no session.idle, so a
1314
- // completed turn ends with session.execution.succeeded.
1315
- const sessionID = raw.sessionID || (raw.data && raw.data.sessionID)
1316
- || (raw.properties && (raw.properties.sessionID || raw.properties.info?.id))
1317
- const turnEnded = raw.type === "session.idle" || raw.type === "session.execution.succeeded"
1318
- const lifecycleEvent = ["session.idle", "session.created", "session.deleted"].includes(raw.type)
1312
+ // OpenCode V2 events carry the session id at data.sessionID. A turn
1313
+ // completes with session.execution.succeeded; V2 sends no session.idle.
1314
+ const sessionID = raw.data && raw.data.sessionID
1315
+ const turnEnded = raw.type === "session.execution.succeeded"
1316
+ const lifecycleEvent = ["session.created", "session.deleted"].includes(raw.type)
1319
1317
  if ((!turnEnded && !lifecycleEvent) || typeof sessionID !== "string" || !sessionID) continue
1320
1318
  retryLedgerReleases()
1321
1319
  if (raw.type === "session.deleted") invalidatedSessions.add(sessionID)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "harness-enforcement",
3
3
  "description": "Repository inventory for the opencode enforcement plugin and its standalone helper",
4
- "version": "0.57.4",
4
+ "version": "1.0.0",
5
5
  "runtime": "index.mjs",
6
6
  "hooks": {
7
7
  "verify": "hooks/verify.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harness-everything",
3
- "version": "0.57.4",
3
+ "version": "1.0.0",
4
4
  "description": "Harness OS: An Orchestrated Agent Operating System for AI-driven Development",
5
5
  "main": "harness-everything/scripts/bootstrap.js",
6
6
  "bin": {
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "harness-everything",
3
+ "version": "1.0.0",
4
+ "description": "Invariant-first engineering harness for routing, verification, and failure recovery while preserving agent autonomy.",
5
+ "author": {
6
+ "name": "Miya Daniel",
7
+ "url": "https://github.com/dyphn1"
8
+ },
9
+ "homepage": "https://github.com/dyphn1/Harness-everything",
10
+ "repository": "https://github.com/dyphn1/Harness-everything",
11
+ "license": "Apache-2.0",
12
+ "keywords": [
13
+ "agent-harness",
14
+ "orchestration",
15
+ "tdd",
16
+ "verification"
17
+ ]
18
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harness-everything",
3
- "version": "0.57.4",
3
+ "version": "1.0.0",
4
4
  "description": "Invariant-first engineering harness for routing, verification, and failure recovery while preserving agent autonomy.",
5
5
  "author": {
6
6
  "name": "Miya Daniel",