harness-everything 1.0.0 → 1.1.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 (39) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +21 -0
  4. package/ci/mechanism-394-ledger-match.test.js +324 -3
  5. package/ci/mechanism-496-claude-capture.test.js +342 -0
  6. package/ci/mechanism-496-codex-capture.test.js +508 -0
  7. package/ci/mechanism-496-local-error-cli-edges.test.js +234 -0
  8. package/ci/mechanism-496-local-error-cli.test.js +517 -0
  9. package/ci/mechanism-496-local-error-store.test.js +731 -0
  10. package/ci/mechanism-496-opencode-capture.test.js +483 -0
  11. package/ci/mechanism-496-review-fixes.test.js +278 -0
  12. package/ci/mechanism-516-agy-post-tool-exit.test.js +472 -0
  13. package/ci/mechanism-516-agy-stop-revision.test.js +215 -0
  14. package/hooks/scripts/agy-post-tool.js +79 -16
  15. package/hooks/scripts/agy-stop.js +63 -10
  16. package/hooks/scripts/codex-ledger-lesson.js +103 -27
  17. package/hooks/scripts/ledger-lesson.js +94 -23
  18. package/hooks/scripts/lib/ledger-match.js +169 -21
  19. package/hooks/scripts/lib/local-error-source.js +127 -0
  20. package/hooks/scripts/lib/local-errors.js +597 -0
  21. package/hooks/scripts/lib/observations.js +1 -1
  22. package/hooks/scripts/state-persist.js +7 -1
  23. package/opencode-plugin/index.mjs +86 -1
  24. package/opencode-plugin/plugin.json +1 -1
  25. package/package.json +2 -1
  26. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  27. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  28. package/plugins/harness-everything/hooks/scripts/agy-post-tool.js +79 -16
  29. package/plugins/harness-everything/hooks/scripts/agy-stop.js +63 -10
  30. package/plugins/harness-everything/hooks/scripts/codex-ledger-lesson.js +103 -27
  31. package/plugins/harness-everything/hooks/scripts/ledger-lesson.js +94 -23
  32. package/plugins/harness-everything/hooks/scripts/lib/ledger-match.js +169 -21
  33. package/plugins/harness-everything/hooks/scripts/lib/local-error-source.js +127 -0
  34. package/plugins/harness-everything/hooks/scripts/lib/local-errors.js +597 -0
  35. package/plugins/harness-everything/hooks/scripts/lib/observations.js +1 -1
  36. package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -1
  37. package/plugins/harness-everything/plugin.json +1 -1
  38. package/sbom.cdx.json +7 -7
  39. package/scripts/errors-local.js +357 -0
@@ -0,0 +1,278 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const assert = require('node:assert/strict');
5
+ const fs = require('node:fs');
6
+ const os = require('node:os');
7
+ const path = require('node:path');
8
+ const { execFileSync, spawnSync } = require('node:child_process');
9
+
10
+ const ROOT = path.resolve(__dirname, '..');
11
+ const CLI = path.join(ROOT, 'scripts', 'errors-local.js');
12
+ const localErrors = require(path.join(ROOT, 'hooks', 'scripts', 'lib', 'local-errors.js'));
13
+ const { createProvisionalSource } = require(path.join(ROOT, 'hooks', 'scripts', 'lib', 'local-error-source.js'));
14
+ const { matchLedgerLessons } = require(path.join(ROOT, 'hooks', 'scripts', 'lib', 'ledger-match.js'));
15
+
16
+ let failures = 0;
17
+ const sandboxes = [];
18
+
19
+ function test(name, fn) {
20
+ try {
21
+ fn();
22
+ console.log(` PASS ${name}`);
23
+ } catch (error) {
24
+ failures += 1;
25
+ console.error(` FAIL ${name}\n ${error.stack.split('\n').slice(0, 5).join('\n ')}`);
26
+ }
27
+ }
28
+
29
+ function canonicalDir(dir) {
30
+ return fs.realpathSync.native ? fs.realpathSync.native(dir) : fs.realpathSync(dir);
31
+ }
32
+
33
+ function makeSandbox() {
34
+ const dir = canonicalDir(fs.mkdtempSync(path.join(os.tmpdir(), 'local-err-review-')));
35
+ sandboxes.push(dir);
36
+ const home = path.join(dir, 'home');
37
+ const store = path.join(dir, 'observations');
38
+ const stateHome = path.join(dir, 'state-home');
39
+ const repo = path.join(dir, 'repo');
40
+ const matcherState = path.join(dir, 'matcher-state');
41
+ for (const p of [home, store, stateHome, repo, matcherState]) {
42
+ fs.mkdirSync(p, { recursive: true });
43
+ }
44
+ execFileSync('git', ['init', '-q', repo]);
45
+ const env = {
46
+ ...process.env,
47
+ HOME: home,
48
+ USERPROFILE: home,
49
+ HARNESS_OBSERVATIONS_DIR: store,
50
+ HARNESS_STATE_HOME: stateHome,
51
+ };
52
+ delete env.HARNESS_OBSERVATIONS;
53
+ delete env.HARNESS_SYSTEM_ONE_MODE;
54
+ delete env.HARNESS_WORKSPACE_ROOT;
55
+ delete env.CLAUDE_PROJECT_DIR;
56
+ delete env.CODEX_PROJECT_DIR;
57
+ return { dir, store, repo, matcherState, env };
58
+ }
59
+
60
+ function runCli(args, sandbox) {
61
+ return spawnSync(process.execPath, [CLI, ...args], {
62
+ cwd: sandbox.repo,
63
+ env: sandbox.env,
64
+ encoding: 'utf8',
65
+ stdio: ['ignore', 'pipe', 'pipe'],
66
+ });
67
+ }
68
+
69
+ function actionMatch() {
70
+ return { actions: [{ tool: 'shell', executable: 'git', subcommand: 'commit' }] };
71
+ }
72
+
73
+ console.log('mechanism-496-review-fixes:');
74
+
75
+ test('redacts complete Basic/Bearer authorization values before storage and signature derivation', () => {
76
+ const s = makeSandbox();
77
+ const fixtures = [
78
+ { header: 'Authorization', scheme: 'Basic', credential: 'BASIC_FIXTURE_ALPHA_91' },
79
+ { header: 'aUtHoRiZaTiOn', scheme: 'bAsIc', credential: 'BASIC_FIXTURE_BETA_82' },
80
+ { header: 'Proxy-Authorization', scheme: 'Bearer', credential: 'BEARER_FIXTURE_ALPHA_73' },
81
+ { header: 'pRoXy-aUtHoRiZaTiOn', scheme: 'bEaReR', credential: 'BEARER_FIXTURE_BETA_64' },
82
+ ];
83
+ const credentials = fixtures.map(row => row.credential);
84
+
85
+ for (const [index, row] of fixtures.entries()) {
86
+ const res = localErrors.appendOccurrence({
87
+ workspaceRoot: s.repo,
88
+ host: 'claude',
89
+ sessionKey: `auth-session-${index}`,
90
+ toolUseId: `auth-tool-${index}`,
91
+ command: 'node synthetic-check.js',
92
+ exitCode: 1,
93
+ output: `Fatal synthetic diagnostic AUTH_CONTROL\n${row.header}: ${row.scheme} ${row.credential}`,
94
+ }, { env: s.env });
95
+ assert.equal(res.status, 'appended');
96
+ assert.ok(!res.record.outputExcerpt.includes(row.credential), 'stored occurrence excerpt must omit the whole credential');
97
+ assert.ok(res.record.outputExcerpt.includes('Fatal synthetic diagnostic AUTH_CONTROL'), 'diagnostic remains usable');
98
+ }
99
+
100
+ const sameFailure = (credential, toolUseId) => localErrors.appendOccurrence({
101
+ workspaceRoot: s.repo,
102
+ host: 'codex',
103
+ sessionKey: 'signature-session',
104
+ toolUseId,
105
+ command: 'node synthetic-check.js',
106
+ exitCode: 1,
107
+ output: `Fatal synthetic diagnostic SIGNATURE_CONTROL\nAuthorization: Basic ${credential}`,
108
+ }, { env: s.env });
109
+ const first = sameFailure('BASIC_SIGNATURE_FIXTURE_11', 'signature-tool-1');
110
+ const second = sameFailure('BASIC_SIGNATURE_FIXTURE_22', 'signature-tool-2');
111
+ assert.equal(first.record.signature, second.record.signature,
112
+ 'automatic signatures must ignore only the authorization payload');
113
+ const differentDiagnostic = localErrors.appendOccurrence({
114
+ workspaceRoot: s.repo,
115
+ host: 'codex',
116
+ command: 'node synthetic-check.js',
117
+ exitCode: 1,
118
+ output: 'Fatal synthetic diagnostic DIFFERENT_CONTROL\nAuthorization: Basic BASIC_SIGNATURE_FIXTURE_33',
119
+ }, { env: s.env });
120
+ assert.notEqual(first.record.signature, differentDiagnostic.record.signature,
121
+ 'different diagnostics remain distinguishable');
122
+
123
+ const lesson = localErrors.addProvisionalLesson({
124
+ workspaceRoot: s.repo,
125
+ destination: 'project',
126
+ signature: 'v1-git-auth-review-control',
127
+ match: actionMatch(),
128
+ lesson: 'Preserve the safe lesson. Authorization: Basic BASIC_LESSON_FIXTURE_54',
129
+ cue: 'Before committing. Proxy-Authorization: Bearer BEARER_CUE_FIXTURE_45',
130
+ }, { env: s.env });
131
+ assert.equal(lesson.status, 'appended');
132
+ credentials.push('BASIC_SIGNATURE_FIXTURE_11', 'BASIC_SIGNATURE_FIXTURE_22', 'BASIC_SIGNATURE_FIXTURE_33',
133
+ 'BASIC_LESSON_FIXTURE_54', 'BEARER_CUE_FIXTURE_45');
134
+
135
+ const rawIndex = fs.readFileSync(path.join(s.store, 'errors-index.json'), 'utf8');
136
+ for (const credential of credentials) {
137
+ assert.ok(!rawIndex.includes(credential), `raw errors-index.json must omit ${credential}`);
138
+ }
139
+
140
+ const listed = runCli(['list', '--json'], s);
141
+ assert.equal(listed.status, 0, listed.stderr);
142
+ const exported = runCli(['export'], s);
143
+ assert.equal(exported.status, 0, exported.stderr);
144
+ for (const output of [listed.stdout, exported.stdout]) {
145
+ for (const credential of credentials) assert.ok(!output.includes(credential), 'CLI output must omit fixture credentials');
146
+ assert.ok(output.includes('Fatal synthetic diagnostic AUTH_CONTROL'), 'CLI retains a safe diagnostic');
147
+ assert.ok(output.includes('Preserve the safe lesson.'), 'CLI retains the safe lesson');
148
+ }
149
+
150
+ const source = createProvisionalSource({ env: s.env, workspaceRoot: s.repo });
151
+ const matched = matchLedgerLessons({
152
+ workspaceRoot: s.repo,
153
+ workspaceIdentity: lesson.record.workspaceKey,
154
+ sessionIdentity: 'synthetic-session',
155
+ stateDir: s.matcherState,
156
+ event: { phase: 'action', tool: 'shell', command: 'git commit -m "safe"', outcome: { failed: 'unknown' } },
157
+ provisionalSource: source,
158
+ });
159
+ assert.ok(matched && matched.text.includes('Preserve the safe lesson.'), 'positive control lesson remains deliverable');
160
+ for (const credential of credentials) assert.ok(!matched.text.includes(credential), 'matched context must omit fixture credentials');
161
+ });
162
+
163
+ test('read-side retention filters before limits, stays read-only, and withholds expired matcher lessons', () => {
164
+ const s = makeSandbox();
165
+ const now = Date.now();
166
+ const retentionMs = localErrors.LIMITS.retentionMs;
167
+ const cutoff = now - retentionMs;
168
+ const workspaceA = localErrors.resolveWorkspaceKey({ workspaceRoot: s.repo }, { env: s.env });
169
+ const otherRepo = path.join(s.dir, 'other-repo');
170
+ fs.mkdirSync(otherRepo);
171
+ execFileSync('git', ['init', '-q', otherRepo]);
172
+ const workspaceB = localErrors.resolveWorkspaceKey({ workspaceRoot: otherRepo }, { env: s.env });
173
+
174
+ const occurrence = (id, workspaceKey, createdAt, outputExcerpt) => ({
175
+ schemaVersion: 1,
176
+ kind: 'occurrence',
177
+ provisionalId: id,
178
+ workspaceKey,
179
+ destination: 'unknown',
180
+ createdAt: new Date(createdAt).toISOString(),
181
+ signature: `v1-git-${id}`,
182
+ source: 'tool-failure',
183
+ host: 'claude',
184
+ sessionKey: null,
185
+ toolUseId: null,
186
+ commandClass: 'git',
187
+ exitCode: 1,
188
+ outputExcerpt,
189
+ matchedLedgerIds: [],
190
+ });
191
+ const lesson = (id, workspaceKey, createdAt, text) => ({
192
+ schemaVersion: 1,
193
+ kind: 'provisional-lesson',
194
+ provisionalId: id,
195
+ workspaceKey,
196
+ destination: 'project',
197
+ createdAt: new Date(createdAt).toISOString(),
198
+ signature: `v1-git-${id}`,
199
+ match: actionMatch(),
200
+ lesson: text,
201
+ issueUrl: null,
202
+ promotionId: null,
203
+ });
204
+
205
+ const file = path.join(s.store, 'errors-index.json');
206
+ const initialIndex = {
207
+ schemaVersion: 1,
208
+ kind: 'local-error-store',
209
+ records: [
210
+ occurrence('future-occurrence', workspaceA, now + 60_000, 'Fresh future occurrence diagnostic.'),
211
+ occurrence('fresh-occurrence', workspaceA, cutoff + 2, 'Fresh cutoff occurrence diagnostic.'),
212
+ occurrence('expired-occurrence', workspaceA, cutoff - 1, 'Expired occurrence diagnostic.'),
213
+ occurrence('boundary-occurrence', workspaceA, cutoff, 'Boundary occurrence diagnostic.'),
214
+ occurrence('other-workspace-occurrence', workspaceB, now + 60_000, 'Other workspace diagnostic.'),
215
+ lesson('expired-lesson', workspaceA, cutoff - 1, 'Expired matching lesson.'),
216
+ lesson('boundary-lesson', workspaceA, cutoff, 'Boundary matching lesson.'),
217
+ lesson('fresh-cutoff-lesson', workspaceA, cutoff + 2, 'Fresh cutoff matching lesson.'),
218
+ lesson('future-lesson', workspaceA, now + 60_000, 'Fresh matching lesson positive control.'),
219
+ ],
220
+ };
221
+ fs.writeFileSync(file, `${JSON.stringify(initialIndex, null, 2)}\n`, 'utf8');
222
+
223
+ const indexBefore = fs.readFileSync(file);
224
+ const storeEntriesBefore = fs.readdirSync(s.store).sort();
225
+ const limited = localErrors.listRecords({
226
+ env: s.env,
227
+ workspaceRoot: s.repo,
228
+ kind: 'occurrence',
229
+ limit: 1,
230
+ now,
231
+ limits: { retentionMs },
232
+ });
233
+ assert.equal(limited.length, 1);
234
+ assert.equal(limited[0].provisionalId, 'fresh-occurrence', 'retention filtering happens before the limit');
235
+
236
+ const records = localErrors.listRecords({ env: s.env, workspaceRoot: s.repo, now, limits: { retentionMs } });
237
+ assert.deepEqual(records.map(record => record.provisionalId), [
238
+ 'future-occurrence', 'fresh-occurrence', 'fresh-cutoff-lesson', 'future-lesson',
239
+ ]);
240
+ assert.ok(!records.some(record => /expired|boundary|other-workspace/.test(record.provisionalId)));
241
+ assert.deepEqual(fs.readdirSync(s.store).sort(), storeEntriesBefore, 'read must not create a lock or claim in the store');
242
+ assert.equal(fs.existsSync(path.join(s.store, '.index.lock')), false, 'read must not acquire the write lock');
243
+ assert.equal(Buffer.compare(indexBefore, fs.readFileSync(file)), 0, 'read must leave index bytes unchanged');
244
+
245
+ const listed = runCli(['list', '--json'], s);
246
+ assert.equal(listed.status, 0, listed.stderr);
247
+ const exported = runCli(['export'], s);
248
+ assert.equal(exported.status, 0, exported.stderr);
249
+ for (const output of [listed.stdout, exported.stdout]) {
250
+ assert.ok(output.includes('future-occurrence'), 'fresh workspace-matching occurrence is listed/exported');
251
+ assert.ok(output.includes('future-lesson'), 'fresh workspace-matching lesson is listed/exported');
252
+ assert.ok(!output.includes('expired-occurrence'));
253
+ assert.ok(!output.includes('boundary-occurrence'));
254
+ assert.ok(!output.includes('expired-lesson'));
255
+ assert.ok(!output.includes('boundary-lesson'));
256
+ assert.ok(!output.includes('other-workspace-occurrence'));
257
+ }
258
+
259
+ const source = createProvisionalSource({ env: s.env, workspaceRoot: s.repo });
260
+ const candidates = source(workspaceA);
261
+ assert.deepEqual(candidates.map(candidate => candidate.identity), ['future-lesson'],
262
+ 'expired and cutoff-boundary lessons are not offered by the provisional source');
263
+ const matched = matchLedgerLessons({
264
+ workspaceRoot: s.repo,
265
+ workspaceIdentity: workspaceA,
266
+ sessionIdentity: 'retention-session',
267
+ stateDir: s.matcherState,
268
+ event: { phase: 'action', tool: 'shell', command: 'git commit -m "safe"', outcome: { failed: 'unknown' } },
269
+ provisionalSource: source,
270
+ });
271
+ assert.ok(matched && matched.text.includes('Fresh matching lesson positive control.'));
272
+ assert.ok(!matched.text.includes('Expired matching lesson.'));
273
+ assert.ok(!matched.text.includes('Boundary matching lesson.'));
274
+ });
275
+
276
+ for (const dir of sandboxes) fs.rmSync(dir, { recursive: true, force: true });
277
+ console.log(failures ? `\n${failures} failure(s)` : '\nAll review-fix checks passed.');
278
+ process.exit(failures ? 1 : 0);