harness-everything 0.58.0 → 1.0.1

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 (53) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/AGENTS.md +8 -2
  4. package/CHANGELOG.md +24 -0
  5. package/README.md +4 -4
  6. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/README.md +40 -0
  7. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/edit-state-final.json +11 -0
  8. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/events-2026-11-24.jsonl +103 -0
  9. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/host-version.txt +3 -0
  10. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/live-event-trace-probe.js +11 -0
  11. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/plugin-load-lines.txt +2 -0
  12. package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/reminder-excerpt.txt +1 -0
  13. package/ci/doc-capability-consistency.test.js +4 -2
  14. package/ci/lib/opencode-v2-driver.js +169 -0
  15. package/ci/mechanism-2n-opencode-plugin.test.js +387 -223
  16. package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +24 -15
  17. package/ci/mechanism-2u-issue-42-regressions.test.js +41 -2
  18. package/ci/mechanism-2w-platform-compatibility.test.js +16 -3
  19. package/ci/mechanism-30-opencode-plugin-loadability.test.js +78 -45
  20. package/ci/mechanism-338-opencode-async.test.js +367 -194
  21. package/ci/mechanism-341-opencode-lane.test.js +143 -183
  22. package/ci/mechanism-39-opencode-verify-outcomes.test.js +118 -86
  23. package/ci/mechanism-394-ledger-match.test.js +105 -3
  24. package/ci/mechanism-394-opencode-ledger-lesson.test.js +46 -97
  25. package/ci/mechanism-397-opencode-observations.test.js +58 -47
  26. package/ci/mechanism-453-opencode-v2-driver.test.js +51 -0
  27. package/ci/mechanism-453-opencode-v2-only-events.test.js +241 -0
  28. package/ci/mechanism-516-agy-post-tool-exit.test.js +472 -0
  29. package/ci/mechanism-516-agy-stop-revision.test.js +215 -0
  30. package/ci/telemetry.test.js +31 -24
  31. package/docs/architecture.md +4 -2
  32. package/docs/platform-capabilities.md +60 -26
  33. package/docs/platform-compatibility.json +8 -6
  34. package/docs/system-one-observations.md +1 -1
  35. package/docs/telemetry.md +1 -1
  36. package/docs/troubleshooting.md +2 -2
  37. package/hooks/scripts/agy-post-tool.js +79 -16
  38. package/hooks/scripts/agy-stop.js +63 -10
  39. package/hooks/scripts/lib/ledger-match.js +132 -20
  40. package/hooks/scripts/state-persist.js +7 -1
  41. package/opencode-plugin/README.md +60 -66
  42. package/opencode-plugin/index.mjs +11 -13
  43. package/opencode-plugin/plugin.json +1 -1
  44. package/package.json +1 -1
  45. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  46. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  47. package/plugins/harness-everything/hooks/scripts/agy-post-tool.js +79 -16
  48. package/plugins/harness-everything/hooks/scripts/agy-stop.js +63 -10
  49. package/plugins/harness-everything/hooks/scripts/lib/ledger-match.js +132 -20
  50. package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -1
  51. package/plugins/harness-everything/plugin.json +1 -1
  52. package/plugins/harness-everything/rules/AGENTS.md +8 -2
  53. package/sbom.cdx.json +12 -12
@@ -7,9 +7,8 @@ const helper = require('./test-helper');
7
7
  console.log('\n[2p] opencode 2.x default-export entrypoint: registration and firing behavior...');
8
8
 
9
9
  // OpenCode 2.x requires a default export { id, setup } that registers hooks
10
- // through ctx.tool.hook / ctx.event.subscribe. The named V1 factory still
11
- // exists for OpenCode 1 hosts and the mechanism tests; this test covers the
12
- // V2 adapter that the real host actually loads.
10
+ // through ctx.tool.hook / ctx.session.hook / ctx.event.subscribe. This test
11
+ // covers the V2 plugin surface and event shapes.
13
12
 
14
13
  helper.check(
15
14
  '2p. the plugin entrypoint resolves the canonical router and observations runtime from the source checkout',
@@ -86,14 +85,20 @@ helper.check(
86
85
  },
87
86
  };
88
87
 
88
+ const v2Event = (type, sessionID, data = {}) => ({
89
+ id: `evt-${type}-${sessionID}-${Date.now()}`,
90
+ created: Date.now(),
91
+ type,
92
+ durable: true,
93
+ data: { sessionID, ...data },
94
+ });
89
95
  const push = (event) => eventQueue.push(event);
90
- const settle = () => new Promise((resolve) => setTimeout(resolve, 50));
91
- const waitFor = async (predicate) => {
96
+ const waitFor = async (predicate, label = 'V2 async verification') => {
92
97
  const deadline = Date.now() + 5000;
93
98
  while (!predicate()) {
94
99
  if (Date.now() > deadline) {
95
100
  const editState = path.join(stateRoot, 's1', 'edit-state.json');
96
- throw new Error(`V2 async verification did not settle: prompts=${prompts.length}; consumedEvents=${consumedEvents}; queued=${eventQueue.length}; editState=${fs.existsSync(editState) ? fs.readFileSync(editState, 'utf8') : 'missing'}`);
101
+ throw new Error(`${label} did not settle: prompts=${prompts.length}; consumedEvents=${consumedEvents}; queued=${eventQueue.length}; editState=${fs.existsSync(editState) ? fs.readFileSync(editState, 'utf8') : 'missing'}`);
97
102
  }
98
103
  await new Promise(resolve => setTimeout(resolve, 20));
99
104
  }
@@ -108,13 +113,16 @@ helper.check(
108
113
  `default export keys: ${JSON.stringify(definition && Object.keys(definition))}`
109
114
  );
110
115
 
116
+ const exportKeys = Object.keys(mod).sort();
111
117
  helper.check(
112
- '2p. the module still exports the V1 HarnessEnforcement factory for OpenCode 1 hosts and tests',
113
- typeof mod.HarnessEnforcement === 'function',
114
- `exports: ${Object.keys(mod).join(', ')}`
118
+ '2p. the module exports only the V2 default definition with setup and no server',
119
+ exportKeys.length === 1 && exportKeys[0] === 'default'
120
+ && Boolean(definition) && typeof definition.setup === 'function'
121
+ && !Object.hasOwn(definition, 'server'),
122
+ `exports: ${exportKeys.join(', ')}; default keys: ${JSON.stringify(definition && Object.keys(definition))}`
115
123
  );
116
124
 
117
- await definition.setup(fakeCtx);
125
+ const dispose = await definition.setup(fakeCtx);
118
126
 
119
127
  helper.check(
120
128
  '2p. setup registers the V2 tool hooks under their OpenCode 2 names',
@@ -135,12 +143,12 @@ helper.check(
135
143
 
136
144
  // Flow 1: repeated failures use real V2 event shapes and leave edits available:
137
145
  // execute.before/after carry {tool, sessionID, id, input}; the event stream
138
- // carries flat {type, sessionID}.
146
+ // carries V2 envelopes {id, created, type, durable, data: {sessionID}}.
139
147
  const sessionDir = path.join(stateRoot, 's1');
140
148
  for (let i = 1; i <= 3; i++) {
141
149
  await before({ tool: 'edit', sessionID: 's1', id: `before-${i}`, input: {} });
142
150
  await after({ tool: 'edit', sessionID: 's1', id: `c${i}`, input: {} });
143
- push({ type: 'session.idle', sessionID: 's1' });
151
+ push(v2Event('session.execution.succeeded', 's1'));
144
152
  await waitFor(() => prompts.length === i);
145
153
  }
146
154
 
@@ -202,17 +210,18 @@ helper.check(
202
210
  legacyDir
203
211
  );
204
212
 
205
- // Flow 3: session reset through the flat V2 event shape.
213
+ // Flow 3: session reset through the V2 event envelope.
206
214
  await after({ tool: 'edit', sessionID: 'reset', id: 'reset-edit', input: {} });
207
215
  helper.check('2p. an edit created state for its session before the reset probe', fs.existsSync(path.join(stateRoot, 'reset', 'edit-state.json')), 'state/reset');
208
- push({ type: 'session.created', sessionID: 'reset' });
209
- await settle();
216
+ push(v2Event('session.created', 'reset'));
217
+ await waitFor(() => !fs.existsSync(path.join(stateRoot, 'reset', 'edit-state.json')), 'session.created reset');
210
218
  helper.check(
211
219
  '2p. a flat v2 session.created event resets that session state',
212
220
  !fs.existsSync(path.join(stateRoot, 'reset', 'edit-state.json')),
213
221
  'edit-state.json survived the reset'
214
222
  );
215
223
 
224
+ if (typeof dispose === 'function') await dispose();
216
225
  helper.finish();
217
226
  })().catch((err) => {
218
227
  console.error('2p. opencode v2 entrypoint test crashed:', err);
@@ -213,8 +213,47 @@ fs.mkdirSync(opencodeLegacy, { recursive: true });
213
213
  fs.writeFileSync(path.join(opencodeLegacy, 'edit-state.json'), '{"legacy":true}', 'utf8');
214
214
  const opencodeScript = `
215
215
  import { existsSync } from 'node:fs';
216
- const { HarnessEnforcement } = await import(${JSON.stringify(pathToFileURL(path.join(root, 'opencode-plugin', 'index.mjs')).href)});
217
- await HarnessEnforcement({ client: {}, directory: ${JSON.stringify(opencodeWorkspace)} });
216
+ const mod = await import(${JSON.stringify(pathToFileURL(path.join(root, 'opencode-plugin', 'index.mjs')).href)});
217
+ const toolHooks = new Map();
218
+ const teardown = await mod.default.setup({
219
+ location: { directory: ${JSON.stringify(opencodeWorkspace)} },
220
+ tool: {
221
+ hook: async (name, cb) => {
222
+ toolHooks.set(name, cb);
223
+ return { dispose: async () => {} };
224
+ },
225
+ },
226
+ session: {
227
+ get: async ({ sessionID }) => ({ id: sessionID, location: { directory: ${JSON.stringify(opencodeWorkspace)} } }),
228
+ hook: async () => ({ dispose: async () => {} }),
229
+ prompt: async () => ({}),
230
+ context: async () => [],
231
+ },
232
+ event: {
233
+ subscribe: ({ signal }) => ({
234
+ [Symbol.asyncIterator]: () => ({
235
+ next: () => signal.aborted
236
+ ? Promise.resolve({ done: true, value: undefined })
237
+ : new Promise(resolve => {
238
+ signal.addEventListener('abort', () => resolve({ done: true, value: undefined }), { once: true });
239
+ }),
240
+ return: async () => ({ done: true, value: undefined }),
241
+ }),
242
+ }),
243
+ },
244
+ });
245
+ try {
246
+ await toolHooks.get('execute.before')({
247
+ tool: 'read',
248
+ sessionID: 's-2u-issue-42',
249
+ agent: 'default',
250
+ messageID: 'm-2u-issue-42',
251
+ id: 'c-2u-issue-42',
252
+ input: {},
253
+ });
254
+ } finally {
255
+ if (typeof teardown === 'function') await teardown();
256
+ }
218
257
  console.log(JSON.stringify({ legacy: existsSync(${JSON.stringify(opencodeLegacy)}), target: existsSync(${JSON.stringify(path.join(opencodeStateDir, 'edit-state.json'))}) }));
219
258
  `;
220
259
  const opencodeRun = run(noGitA, ['--input-type=module', '-e', opencodeScript], {
@@ -74,12 +74,25 @@ for (const platform of matrix.platforms) {
74
74
  if (platform.id === 'opencode') {
75
75
  const capability = platform.capabilities.liveHostVerification;
76
76
  assert.strictEqual(capability.status, 'Partial');
77
- assert.strictEqual(capability.evidence, 'benchmarks/results/live-host/opencode-2026-09-16/README.md');
77
+ assert.strictEqual(capability.evidence, 'benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/README.md');
78
78
  const artifactRoot = path.dirname(path.join(ROOT, capability.evidence));
79
+ for (const file of [
80
+ 'README.md',
81
+ 'events-2026-11-24.jsonl',
82
+ 'edit-state-final.json',
83
+ 'reminder-excerpt.txt',
84
+ 'plugin-load-lines.txt',
85
+ 'live-event-trace-probe.js',
86
+ 'host-version.txt',
87
+ ]) {
88
+ assert.ok(fs.statSync(path.join(artifactRoot, file)).size > 0, `Missing OpenCode V2 evidence: ${file}`);
89
+ }
90
+ const OPENCODE_HISTORICAL_EVIDENCE = 'benchmarks/results/live-host/opencode-2026-09-16/README.md';
91
+ const historicalArtifactRoot = path.dirname(path.join(ROOT, OPENCODE_HISTORICAL_EVIDENCE));
79
92
  for (const file of ['README.md', 'probe-control.md', 'run-commands.md']) {
80
- assert.ok(fs.statSync(path.join(artifactRoot, file)).size > 0, `Missing OpenCode evidence: ${file}`);
93
+ assert.ok(fs.statSync(path.join(historicalArtifactRoot, file)).size > 0, `Missing historical OpenCode evidence: ${file}`);
81
94
  }
82
- const session = path.join(artifactRoot, 'state', 'sessions', 'ses_f5520f1d9ffeB8KLTIUKgA5ng8');
95
+ const session = path.join(historicalArtifactRoot, 'state', 'sessions', 'ses_f5520f1d9ffeB8KLTIUKgA5ng8');
83
96
  // This is an archived post-reset snapshot, not a current behavior witness.
84
97
  const breaker = JSON.parse(fs.readFileSync(path.join(session, 'circuit-breaker.json'), 'utf8'));
85
98
  const compliance = JSON.parse(fs.readFileSync(path.join(session, 'compliance.json'), 'utf8'));
@@ -2,6 +2,7 @@ const assert = require('assert');
2
2
  const fs = require('fs');
3
3
  const os = require('os');
4
4
  const path = require('path');
5
+ const { pathToFileURL } = require('url');
5
6
  const vm = require('vm');
6
7
  const helper = require('./test-helper');
7
8
 
@@ -25,7 +26,7 @@ function installStatement(text) {
25
26
  return statements[0];
26
27
  }
27
28
 
28
- function verifyInstall(text) {
29
+ function installIntoTempDir(text) {
29
30
  const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-loadability-'));
30
31
  try {
31
32
  vm.runInNewContext(installStatement(text), {
@@ -34,7 +35,30 @@ function verifyInstall(text) {
34
35
  opencodePluginsDir: directory,
35
36
  }, { timeout: 1000 });
36
37
  assert.deepStrictEqual(fs.readdirSync(directory), ['harness-enforcement.js']);
37
- assert.ok(fs.readFileSync(sourceFile).equals(fs.readFileSync(path.join(directory, 'harness-enforcement.js'))));
38
+ const copiedFile = path.join(directory, 'harness-enforcement.js');
39
+ assert.ok(fs.readFileSync(sourceFile).equals(fs.readFileSync(copiedFile)));
40
+ return { directory, copiedFile };
41
+ } catch (error) {
42
+ fs.rmSync(directory, { recursive: true, force: true });
43
+ throw error;
44
+ }
45
+ }
46
+
47
+ function verifyInstall(text) {
48
+ const { directory } = installIntoTempDir(text);
49
+ fs.rmSync(directory, { recursive: true, force: true });
50
+ }
51
+
52
+ async function verifyCopiedEntrypoint(text) {
53
+ const { directory, copiedFile } = installIntoTempDir(text);
54
+ try {
55
+ // Scratch copy uses .js outside a module-typed package; add package.json after
56
+ // verifying the installed directory contains only harness-enforcement.js.
57
+ fs.writeFileSync(path.join(directory, 'package.json'), JSON.stringify({ type: 'module' }) + '\n');
58
+ const mod = await import(pathToFileURL(copiedFile).href);
59
+ assert.deepStrictEqual(Object.keys(mod).sort(), ['default']);
60
+ assert.ok(mod.default && typeof mod.default.setup === 'function', 'Expected default.setup to be a function');
61
+ assert.strictEqual(Object.hasOwn(mod.default, 'server'), false, 'Expected no default.server on V2 entrypoint');
38
62
  } finally {
39
63
  fs.rmSync(directory, { recursive: true, force: true });
40
64
  }
@@ -66,53 +90,62 @@ function walk(directory) {
66
90
  });
67
91
  }
68
92
 
69
- try {
70
- const runner = fs.readFileSync(runnerFile, 'utf8');
71
- verifyInstall(runner);
72
- assert.throws(() => verifyInstall(runner.replace('harness-enforcement.js', 'harness-enforcement.mjs')));
73
- assert.throws(() => verifyInstall(runner.replace("'index.mjs'", "'plugin.json'")));
93
+ (async () => {
94
+ try {
95
+ const runner = fs.readFileSync(runnerFile, 'utf8');
96
+ verifyInstall(runner);
97
+ assert.throws(() => verifyInstall(runner.replace('harness-enforcement.js', 'harness-enforcement.mjs')));
98
+ assert.throws(() => verifyInstall(runner.replace("'index.mjs'", "'plugin.json'")));
74
99
 
75
- for (const extension of ['mjs', 'cjs', 'mts', 'cts', 'jsx', 'tsx', 'json']) {
100
+ for (const extension of ['mjs', 'cjs', 'mts', 'cts', 'jsx', 'tsx', 'json']) {
101
+ for (const base of ['.opencode/plugins/', '~/.config/opencode/plugins/']) {
102
+ assert.strictEqual(invalidTargets(`${base}example.${extension}`).length, 1);
103
+ }
104
+ }
76
105
  for (const base of ['.opencode/plugins/', '~/.config/opencode/plugins/']) {
77
- assert.strictEqual(invalidTargets(`${base}example.${extension}`).length, 1);
106
+ assert.strictEqual(invalidTargets(`${base}example`).length, 1);
107
+ assert.deepStrictEqual(invalidTargets(`${base}example.js`), []);
108
+ assert.deepStrictEqual(invalidTargets(`${base}example.ts`), []);
78
109
  }
79
- }
80
- for (const base of ['.opencode/plugins/', '~/.config/opencode/plugins/']) {
81
- assert.strictEqual(invalidTargets(`${base}example`).length, 1);
82
- assert.deepStrictEqual(invalidTargets(`${base}example.js`), []);
83
- assert.deepStrictEqual(invalidTargets(`${base}example.ts`), []);
84
- }
85
- assert.deepStrictEqual(invalidTargets('opencode-plugin/index.mjs .opencode/plugins/example.js'), []);
110
+ assert.deepStrictEqual(invalidTargets('opencode-plugin/index.mjs .opencode/plugins/example.js'), []);
86
111
 
87
- const scanViolations = (readText = file => fs.readFileSync(file, 'utf8')) => {
88
- const violations = [];
89
- for (const file of walk(root).filter(file => /\.(?:md|js|mjs|json|jsonc|yml|yaml|txt)$/.test(file))) {
90
- const text = readText(file);
91
- for (const target of invalidTargets(text)) violations.push(`${path.relative(root, file)}: ${target}`);
92
- }
93
- return violations;
94
- };
95
- assert.deepStrictEqual(scanViolations(), [], 'Unsupported OpenCode install destinations; only .js/.ts are auto-discovered');
112
+ const scanViolations = (readText = file => fs.readFileSync(file, 'utf8')) => {
113
+ const violations = [];
114
+ for (const file of walk(root).filter(file => /\.(?:md|js|mjs|json|jsonc|yml|yaml|txt)$/.test(file))) {
115
+ const text = readText(file);
116
+ for (const target of invalidTargets(text)) violations.push(`${path.relative(root, file)}: ${target}`);
117
+ }
118
+ return violations;
119
+ };
120
+ assert.deepStrictEqual(scanViolations(), [], 'Unsupported OpenCode install destinations; only .js/.ts are auto-discovered');
96
121
 
97
- const scannedFiles = walk(root);
98
- assert.ok(scannedFiles.includes(readmeFile), 'Tracked OpenCode README must remain in the repository scan');
99
- const plantedTarget = '.opencode/plugins/' + 'negative-control.mjs';
100
- const planted = scanViolations(file => {
101
- const text = fs.readFileSync(file, 'utf8');
102
- return file === readmeFile ? text + '\n' + plantedTarget + '\n' : text;
103
- });
104
- assert.ok(
105
- planted.some(item => item === `${path.relative(root, readmeFile)}: ${plantedTarget}`),
106
- 'Scanner negative control must fail when a tracked file contains an unsupported .mjs install target'
107
- );
122
+ const scannedFiles = walk(root);
123
+ assert.ok(scannedFiles.includes(readmeFile), 'Tracked OpenCode README must remain in the repository scan');
124
+ const plantedTarget = '.opencode/plugins/' + 'negative-control.mjs';
125
+ const planted = scanViolations(file => {
126
+ const text = fs.readFileSync(file, 'utf8');
127
+ return file === readmeFile ? text + '\n' + plantedTarget + '\n' : text;
128
+ });
129
+ assert.ok(
130
+ planted.some(item => item === `${path.relative(root, readmeFile)}: ${plantedTarget}`),
131
+ 'Scanner negative control must fail when a tracked file contains an unsupported .mjs install target'
132
+ );
108
133
 
109
- const readme = fs.readFileSync(readmeFile, 'utf8');
110
- for (const destination of ['.opencode/plugins/harness-enforcement.js', '~/.config/opencode/plugins/harness-enforcement.js']) {
111
- assert.ok(readme.includes(`cp opencode-plugin/index.mjs ${destination}`));
134
+ const readme = fs.readFileSync(readmeFile, 'utf8');
135
+ for (const destination of ['.opencode/plugins/harness-enforcement.js', '~/.config/opencode/plugins/harness-enforcement.js']) {
136
+ assert.ok(readme.includes(`cp opencode-plugin/index.mjs ${destination}`));
137
+ }
138
+ helper.check('30. real install statement produces a byte-identical .js/.ts-discoverable file; non-allowlisted filenames and content mutations fail', true);
139
+
140
+ try {
141
+ await verifyCopiedEntrypoint(runner);
142
+ helper.check('30. copied .js entrypoint exports only the V2 default definition with setup and no server', true);
143
+ } catch (error) {
144
+ helper.check('30. copied .js entrypoint exports only the V2 default definition with setup and no server', false, error.stack);
145
+ }
146
+ helper.finish();
147
+ } catch (error) {
148
+ helper.check('30. OpenCode installation contract', false, error.stack);
149
+ helper.finish();
112
150
  }
113
- helper.check('30. real install statement produces a byte-identical .js/.ts-discoverable file; non-allowlisted filenames and content mutations fail', true);
114
- helper.finish();
115
- } catch (error) {
116
- helper.check('30. OpenCode installation contract', false, error.stack);
117
- helper.finish();
118
- }
151
+ })();