harness-everything 0.12.2 → 0.12.3

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.
@@ -10,7 +10,7 @@
10
10
  "name": "harness-everything",
11
11
  "source": "./",
12
12
  "description": "Harness OS: an orchestrated agent operating system — tier routing, circuit breaker guardrails, verification gates, WAL session memory, and self-evolving workspace rules.",
13
- "version": "0.12.2",
13
+ "version": "0.12.3",
14
14
  "author": {
15
15
  "name": "Miya Daniel"
16
16
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "harness-everything",
3
3
  "description": "Harness OS: an orchestrated agent operating system — tier routing, circuit breaker guardrails, verification gates, WAL session memory, and self-evolving workspace rules.",
4
- "version": "0.12.2",
4
+ "version": "0.12.3",
5
5
  "author": {
6
6
  "name": "Miya Daniel"
7
7
  },
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## [0.12.3](https://github.com/dyphn1/Harness-everything/compare/v0.12.2...v0.12.3) (2026-09-19)
6
+
7
+ ### Bug Fixes
8
+
9
+ * **workflow:** degrade oversized fingerprints conservatively ([ea90f30](https://github.com/dyphn1/Harness-everything/commit/ea90f30a4495e6144017373463c5279fae563252))
10
+ * **workflow:** degrade oversized fingerprints conservatively ([a618d22](https://github.com/dyphn1/Harness-everything/commit/a618d2216955ab3594ecb31b45635dea94e9b109))
11
+ * **workflow:** settle oversized fingerprint probes conservatively ([aafce50](https://github.com/dyphn1/Harness-everything/commit/aafce508551d6564afc884da17555ed71f989836))
12
+ * **workflow:** settle oversized fingerprint probes conservatively ([3092dd6](https://github.com/dyphn1/Harness-everything/commit/3092dd60ed19de97c096f57278c26813f77c3ff7))
13
+
14
+ ### Performance Improvements
15
+
16
+ * **workflow:** batch workspace content hashing ([ad0fc18](https://github.com/dyphn1/Harness-everything/commit/ad0fc18260c5a716d7711cb4b83cf9f5059dd21d))
17
+ * **workflow:** batch workspace content hashing ([2cdd6e3](https://github.com/dyphn1/Harness-everything/commit/2cdd6e3dc568c9d6007ca10de76b06b47ff39880))
18
+
5
19
  ## [0.12.2](https://github.com/dyphn1/Harness-everything/compare/v0.12.1...v0.12.2) (2026-09-19)
6
20
 
7
21
  ### Bug Fixes
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const assert = require('assert');
5
+ const crypto = require('crypto');
6
+ const fs = require('fs');
7
+ const os = require('os');
8
+ const path = require('path');
9
+ const { spawnSync } = require('child_process');
10
+
11
+ const ROOT = path.resolve(__dirname, '..');
12
+ const isolation = require(path.join(ROOT, 'hooks/scripts/lib/workflow-isolation'));
13
+ const pluginIsolation = require(path.join(ROOT, 'plugins/harness-everything/hooks/scripts/lib/workflow-isolation'));
14
+ const state = require(path.join(ROOT, 'hooks/scripts/lib/harness-state'));
15
+
16
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-workspace-fingerprint-'));
17
+ const repo = path.join(temp, 'repo');
18
+ fs.mkdirSync(repo);
19
+ const env = {
20
+ ...process.env,
21
+ HARNESS_STATE_HOME: path.join(temp, 'state'),
22
+ HARNESS_WORKSPACE_ROOT: repo,
23
+ };
24
+ process.env.HARNESS_STATE_HOME = env.HARNESS_STATE_HOME;
25
+ process.env.HARNESS_WORKSPACE_ROOT = env.HARNESS_WORKSPACE_ROOT;
26
+
27
+ let passed = 0;
28
+ function check(value, message) {
29
+ assert.ok(value, message);
30
+ passed++;
31
+ console.log('PASS ' + message);
32
+ }
33
+
34
+ function run(command, args, options = {}) {
35
+ const result = spawnSync(command, args, {
36
+ cwd: options.cwd || repo,
37
+ env,
38
+ input: options.input,
39
+ encoding: 'utf8',
40
+ windowsHide: true,
41
+ maxBuffer: 64 * 1024 * 1024,
42
+ });
43
+ assert.strictEqual(result.status, 0, result.stderr || result.stdout);
44
+ return result.stdout;
45
+ }
46
+
47
+ function git(args) {
48
+ return run('git', args);
49
+ }
50
+
51
+ function node(script, payload, args = []) {
52
+ return spawnSync(process.execPath, [path.join(ROOT, script), ...args], {
53
+ cwd: repo,
54
+ env,
55
+ input: payload === undefined ? undefined : JSON.stringify(payload),
56
+ encoding: 'utf8',
57
+ windowsHide: true,
58
+ maxBuffer: 64 * 1024 * 1024,
59
+ });
60
+ }
61
+
62
+ function gitRaw(args) {
63
+ return run('git', args);
64
+ }
65
+
66
+ function legacyHashWorktreePath(root, relative) {
67
+ const target = path.join(root, relative);
68
+ let stat;
69
+ try {
70
+ stat = fs.lstatSync(target);
71
+ } catch (error) {
72
+ if (error.code === 'ENOENT') return null;
73
+ throw error;
74
+ }
75
+ if (stat.isDirectory()) {
76
+ const result = spawnSync('git', ['-C', target, 'rev-parse', 'HEAD'], {
77
+ encoding: 'utf8',
78
+ windowsHide: true,
79
+ });
80
+ return { mode: '160000', oid: result.status === 0 ? result.stdout.trim() : 'directory' };
81
+ }
82
+ const mode = stat.isSymbolicLink() ? '120000' : ((stat.mode & 0o111) ? '100755' : '100644');
83
+ const result = spawnSync('git', ['hash-object', '--path=' + relative, '--', relative], {
84
+ cwd: root,
85
+ encoding: 'utf8',
86
+ windowsHide: true,
87
+ });
88
+ if (result.status !== 0) throw new Error('legacy fingerprint failed for ' + relative);
89
+ return { mode, oid: result.stdout.trim() };
90
+ }
91
+
92
+ function legacyFingerprint(cwd) {
93
+ const root = isolation.canonical(gitRaw(['rev-parse', '--show-toplevel']).trim());
94
+ const entries = new Map();
95
+ for (const record of gitRaw(['ls-files', '-s', '-z']).split('\0')) {
96
+ if (!record) continue;
97
+ const tab = record.indexOf('\t');
98
+ assert.ok(tab >= 0, 'legacy index record has a tab');
99
+ const meta = record.slice(0, tab).trim().split(/\s+/);
100
+ const relative = record.slice(tab + 1);
101
+ entries.set(relative, { relative, mode: meta[0], oid: meta[1] });
102
+ }
103
+ for (const relative of gitRaw(['diff-files', '--name-only', '-z']).split('\0').filter(Boolean)) {
104
+ const value = legacyHashWorktreePath(root, relative);
105
+ if (value) entries.set(relative, { relative, mode: value.mode, oid: value.oid });
106
+ else entries.delete(relative);
107
+ }
108
+ for (const relative of gitRaw(['ls-files', '--others', '--exclude-standard', '-z']).split('\0').filter(Boolean)) {
109
+ const value = legacyHashWorktreePath(root, relative);
110
+ if (value) entries.set(relative, { relative, mode: value.mode, oid: value.oid });
111
+ }
112
+ const digest = crypto.createHash('sha256');
113
+ digest.update('harness-workspace-fingerprint-v1\0');
114
+ for (const entry of [...entries.values()].sort((a, b) => a.relative.localeCompare(b.relative))) {
115
+ digest.update(entry.relative); digest.update('\0');
116
+ digest.update(entry.mode); digest.update('\0');
117
+ digest.update(entry.oid); digest.update('\0');
118
+ }
119
+ return digest.digest('hex');
120
+ }
121
+
122
+ try {
123
+ git(['init']);
124
+ fs.writeFileSync(path.join(repo, 'tracked.txt'), 'tracked\n');
125
+ fs.writeFileSync(path.join(repo, 'delete-me.txt'), 'delete me\n');
126
+ git(['add', '.']);
127
+ git(['-c', 'user.name=Harness Test', '-c', 'user.email=harness@example.invalid', 'commit', '-m', 'fixture']);
128
+
129
+ const cleanLegacy = legacyFingerprint(repo);
130
+ check(isolation.workspaceFingerprint(repo) === cleanLegacy,
131
+ '#169 batched fingerprint matches the legacy clean-worktree fingerprint');
132
+ check(pluginIsolation.workspaceFingerprint(repo) === cleanLegacy,
133
+ '#169 packaged plugin fingerprint matches canonical/legacy on a clean worktree');
134
+
135
+ fs.writeFileSync(path.join(repo, 'tracked.txt'), 'tracked changed\n');
136
+ fs.writeFileSync(path.join(repo, 'untracked.txt'), 'untracked\n');
137
+ const dirtyLegacy = legacyFingerprint(repo);
138
+ const dirtyBatched = isolation.workspaceFingerprint(repo);
139
+ check(dirtyBatched === dirtyLegacy,
140
+ '#169 batched fingerprint matches legacy for dirty tracked + untracked content');
141
+ check(pluginIsolation.workspaceFingerprint(repo) === dirtyLegacy,
142
+ '#169 packaged plugin batched fingerprint matches legacy dirty semantics');
143
+
144
+ git(['add', 'tracked.txt', 'untracked.txt']);
145
+ check(isolation.workspaceFingerprint(repo) === dirtyBatched,
146
+ '#169 staging visible content does not change the workspace fingerprint');
147
+
148
+ fs.unlinkSync(path.join(repo, 'delete-me.txt'));
149
+ check(isolation.workspaceFingerprint(repo) === legacyFingerprint(repo),
150
+ '#169 tracked deletion keeps legacy fingerprint semantics');
151
+
152
+ git(['reset', '--hard', 'HEAD']);
153
+ git(['clean', '-fdx']);
154
+ const bulk = path.join(repo, 'bulk');
155
+ fs.mkdirSync(bulk);
156
+ for (let i = 0; i < 1000; i++) {
157
+ fs.writeFileSync(path.join(bulk, 'file-' + String(i).padStart(4, '0') + '.txt'), 'x\n');
158
+ }
159
+
160
+ const startedAt = process.hrtime.bigint();
161
+ const bulkFingerprint = isolation.workspaceFingerprint(repo);
162
+ const elapsedMs = Number(process.hrtime.bigint() - startedAt) / 1e6;
163
+ check(/^[a-f0-9]{64}$/.test(bulkFingerprint),
164
+ '#169 1000-untracked-file fingerprint returns a valid digest');
165
+ check(elapsedMs < 5000,
166
+ '#169 1000-untracked-file fingerprint stays below 5s regression ceiling (actual ' + elapsedMs.toFixed(1) + 'ms)');
167
+ check(pluginIsolation.workspaceFingerprint(repo) === bulkFingerprint,
168
+ '#169 packaged plugin fingerprint remains byte-identical for 1000 untracked files');
169
+
170
+ let limitError = null;
171
+ try {
172
+ isolation.workspaceFingerprint(repo, { maxPaths: 10 });
173
+ } catch (error) {
174
+ limitError = error;
175
+ }
176
+ check(limitError?.code === 'HARNESS_FINGERPRINT_LIMIT' &&
177
+ limitError.count === 1000 &&
178
+ limitError.maxPaths === 10,
179
+ '#169 explicit fingerprint cap reports a structured conservative-fallback signal');
180
+
181
+ for (let i = 1000; i < 5101; i++) {
182
+ fs.writeFileSync(path.join(bulk, 'file-' + String(i).padStart(4, '0') + '.txt'), 'x\n');
183
+ }
184
+ const sessionId = 'workspace-fingerprint-limit';
185
+ const payload = { session_id: sessionId, cwd: repo };
186
+ const routed = node('harness-everything/scripts/kernel-router.js', {
187
+ ...payload,
188
+ prompt: 'Fix this checkout bug with a regression test',
189
+ });
190
+ check(routed.status === 0, '#169 large-workspace Tier-2 fixture routes normally');
191
+ const started = node('hooks/scripts/workflow-disposition.js', undefined, ['start', '--session-id', sessionId]);
192
+ check(started.status === 0, '#169 large-workspace Tier-2 fixture starts normally');
193
+
194
+ const admitted = node('hooks/scripts/workflow-gate.js', {
195
+ ...payload,
196
+ tool_name: 'Bash',
197
+ tool_use_id: 'toolu_fingerprint_limit',
198
+ tool_input: { command: 'node large-fingerprint.js' },
199
+ });
200
+ check(admitted.status === 0,
201
+ '#169 >5000 observed paths degrade conservatively instead of blocking the shell call');
202
+ const workflowFile = path.join(state.getSessionDir(repo, sessionId), 'workflow-run.json');
203
+ const workflow = JSON.parse(fs.readFileSync(workflowFile, 'utf8'));
204
+ check(workflow.state === 'running' &&
205
+ workflow.budget?.counters?.iterations === 1 &&
206
+ workflow.lastMutationAt > 0 &&
207
+ workflow.budget?.events?.at(-1)?.evidence === 'shell:fingerprint-limit',
208
+ '#169 fingerprint-limit fallback records one auditable conservative mutation');
209
+
210
+ console.log('PASS: batched workspace fingerprint (' + passed + ' assertions, 1000-file ' + elapsedMs.toFixed(1) + 'ms)');
211
+ } finally {
212
+ if (!temp.startsWith(path.join(os.tmpdir(), 'harness-workspace-fingerprint-'))) {
213
+ throw new Error('unsafe fixture cleanup');
214
+ }
215
+ fs.rmSync(temp, { recursive: true, force: true });
216
+ }
@@ -5,8 +5,15 @@ const crypto = require('crypto');
5
5
  const path = require('path');
6
6
  const { spawnSync } = require('child_process');
7
7
 
8
- function gitRaw(cwd, args) {
9
- const result = spawnSync('git', args, { cwd, encoding: 'utf8', windowsHide: true, timeout: 5000, maxBuffer: 16 * 1024 * 1024 });
8
+ function gitRaw(cwd, args, options = {}) {
9
+ const result = spawnSync('git', args, {
10
+ cwd,
11
+ encoding: 'utf8',
12
+ windowsHide: true,
13
+ timeout: options.timeout ?? 5000,
14
+ maxBuffer: options.maxBuffer ?? (16 * 1024 * 1024),
15
+ ...(options.input === undefined ? {} : { input: options.input }),
16
+ });
10
17
  if (result.status !== 0) throw new Error('cannot verify Git worktree isolation');
11
18
  return result.stdout;
12
19
  }
@@ -15,30 +22,73 @@ function git(cwd, args) {
15
22
  return gitRaw(cwd, args).trim();
16
23
  }
17
24
 
18
- function hashWorktreePath(root, relative) {
19
- const target = path.join(root, relative);
20
- let stat;
21
- try { stat = fs.lstatSync(target); }
22
- catch (error) {
23
- if (error.code === 'ENOENT') return null;
24
- throw error;
25
+ function fingerprintLimitError(count, maxPaths) {
26
+ const error = new Error('workspace fingerprint path limit exceeded');
27
+ error.code = 'HARNESS_FINGERPRINT_LIMIT';
28
+ error.count = count;
29
+ error.maxPaths = maxPaths;
30
+ return error;
31
+ }
32
+
33
+ function hashWorktreePaths(root, relatives) {
34
+ const values = new Map();
35
+ const batch = [];
36
+ for (const relative of relatives) {
37
+ const target = path.join(root, relative);
38
+ let stat;
39
+ try { stat = fs.lstatSync(target); }
40
+ catch (error) {
41
+ if (error.code === 'ENOENT') {
42
+ values.set(relative, null);
43
+ continue;
44
+ }
45
+ throw error;
46
+ }
47
+ if (stat.isDirectory()) {
48
+ const result = spawnSync('git', ['-C', target, 'rev-parse', 'HEAD'], {
49
+ encoding: 'utf8', windowsHide: true, timeout: 5000,
50
+ });
51
+ values.set(relative, { mode: '160000', oid: result.status === 0 ? result.stdout.trim() : 'directory' });
52
+ continue;
53
+ }
54
+ const mode = stat.isSymbolicLink() ? '120000' : ((stat.mode & 0o111) ? '100755' : '100644');
55
+ // --stdin-paths is line-delimited. Rare pathnames containing a newline use
56
+ // the legacy one-file call so the fingerprint remains exact.
57
+ if (/[\r\n]/.test(relative)) {
58
+ const one = spawnSync('git', ['hash-object', '--path=' + relative, '--', relative], {
59
+ cwd: root, encoding: 'utf8', windowsHide: true, timeout: 5000,
60
+ });
61
+ if (one.status !== 0) throw new Error('cannot fingerprint workspace content');
62
+ values.set(relative, { mode, oid: one.stdout.trim() });
63
+ continue;
64
+ }
65
+ batch.push({ relative, mode });
25
66
  }
26
- if (stat.isDirectory()) {
27
- const result = spawnSync('git', ['-C', target, 'rev-parse', 'HEAD'], { encoding: 'utf8', windowsHide: true, timeout: 5000 });
28
- return { mode: '160000', oid: result.status === 0 ? result.stdout.trim() : 'directory' };
67
+
68
+ if (batch.length > 0) {
69
+ const hashed = spawnSync('git', ['hash-object', '--stdin-paths'], {
70
+ cwd: root,
71
+ input: batch.map(item => item.relative).join('\n') + '\n',
72
+ encoding: 'utf8',
73
+ windowsHide: true,
74
+ timeout: 15000,
75
+ maxBuffer: 16 * 1024 * 1024,
76
+ });
77
+ if (hashed.status !== 0) throw new Error('cannot fingerprint workspace content');
78
+ const oids = hashed.stdout.split(/\r?\n/).filter(Boolean);
79
+ if (oids.length !== batch.length) throw new Error('cannot fingerprint workspace content');
80
+ for (let i = 0; i < batch.length; i++) {
81
+ values.set(batch[i].relative, { mode: batch[i].mode, oid: oids[i] });
82
+ }
29
83
  }
30
- const mode = stat.isSymbolicLink() ? '120000' : ((stat.mode & 0o111) ? '100755' : '100644');
31
- const result = spawnSync('git', ['hash-object', '--path=' + relative, '--', relative], {
32
- cwd: root, encoding: 'utf8', windowsHide: true, timeout: 5000,
33
- });
34
- if (result.status !== 0) throw new Error('cannot fingerprint workspace content');
35
- return { mode, oid: result.stdout.trim() };
84
+ return values;
36
85
  }
37
86
 
38
- function workspaceFingerprint(cwd) {
87
+ function workspaceFingerprint(cwd, options = {}) {
39
88
  const root = canonical(git(cwd, ['rev-parse', '--show-toplevel']));
40
89
  const entries = new Map();
41
- for (const record of gitRaw(root, ['ls-files', '-s', '-z']).split('\0')) {
90
+ const largeGitRead = { timeout: 15000, maxBuffer: 64 * 1024 * 1024 };
91
+ for (const record of gitRaw(root, ['ls-files', '-s', '-z'], largeGitRead).split('\0')) {
42
92
  if (!record) continue;
43
93
  const tab = record.indexOf('\t');
44
94
  if (tab < 0) throw new Error('cannot fingerprint workspace index');
@@ -49,18 +99,25 @@ function workspaceFingerprint(cwd) {
49
99
  entries.set(relative, { relative, mode, oid });
50
100
  }
51
101
 
102
+ const changed = gitRaw(root, ['diff-files', '--name-only', '-z'], largeGitRead).split('\0').filter(Boolean);
103
+ const untracked = gitRaw(root, ['ls-files', '--others', '--exclude-standard', '-z'], largeGitRead).split('\0').filter(Boolean);
104
+ const observedPaths = [...new Set([...changed, ...untracked])];
105
+ const maxPaths = Number.isInteger(options.maxPaths) && options.maxPaths > 0 ? options.maxPaths : 5000;
106
+ if (observedPaths.length > maxPaths) throw fingerprintLimitError(observedPaths.length, maxPaths);
107
+ const worktreeValues = hashWorktreePaths(root, observedPaths);
108
+
52
109
  // Substitute current worktree content for tracked paths that differ from the
53
110
  // index. This keeps the fingerprint stable across git add / git commit when
54
111
  // visible workspace content did not change.
55
- for (const relative of gitRaw(root, ['diff-files', '--name-only', '-z']).split('\0').filter(Boolean)) {
56
- const value = hashWorktreePath(root, relative);
112
+ for (const relative of changed) {
113
+ const value = worktreeValues.get(relative);
57
114
  if (value) entries.set(relative, { relative, mode: value.mode, oid: value.oid });
58
115
  else entries.delete(relative);
59
116
  }
60
117
 
61
- for (const relative of gitRaw(root, ['ls-files', '--others', '--exclude-standard', '-z']).split('\0').filter(Boolean)) {
62
- const value = hashWorktreePath(root, relative);
63
- entries.set(relative, { relative, mode: value.mode, oid: value.oid });
118
+ for (const relative of untracked) {
119
+ const value = worktreeValues.get(relative);
120
+ if (value) entries.set(relative, { relative, mode: value.mode, oid: value.oid });
64
121
  }
65
122
 
66
123
  const digest = crypto.createHash('sha256');
@@ -39,8 +39,10 @@ function observeWorkspaceMutation(payload, root) {
39
39
  try {
40
40
  after = workspaceFingerprint(observationCwd);
41
41
  } catch (error) {
42
- if (!isMajorWorkflow(context.workflow)) {
43
- const conservative = settleMutationProbeConservative(context, probeKey, toolName, 'unobservable-workspace');
42
+ const fingerprintLimited = error && error.code === 'HARNESS_FINGERPRINT_LIMIT';
43
+ if (!isMajorWorkflow(context.workflow) || fingerprintLimited) {
44
+ const evidence = fingerprintLimited ? 'fingerprint-limit' : 'unobservable-workspace';
45
+ const conservative = settleMutationProbeConservative(context, probeKey, toolName, evidence);
44
46
  return Boolean(conservative && conservative.changed);
45
47
  }
46
48
  context.workflow.state = 'blocked';
@@ -79,9 +79,11 @@ function decide(payload) {
79
79
  try {
80
80
  fingerprint = workspaceFingerprint(cwd);
81
81
  } catch (error) {
82
- if (isMajorWorkflow(workflow)) throw error;
82
+ const fingerprintLimited = error && error.code === 'HARNESS_FINGERPRINT_LIMIT';
83
+ if (isMajorWorkflow(workflow) && !fingerprintLimited) throw error;
84
+ const evidence = fingerprintLimited ? 'shell:fingerprint-limit' : 'shell:unobservable-workspace';
83
85
  if (workflow.strategy === 'iterative-single') {
84
- recordBudgetEvent(context, 'iteration', { evidence: 'shell:unobservable-workspace' });
86
+ recordBudgetEvent(context, 'iteration', { evidence });
85
87
  }
86
88
  workflow.lastMutationAt = Date.now();
87
89
  saveWorkflow(context);
@@ -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.12.2",
4
+ "version": "0.12.3",
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.12.2",
3
+ "version": "0.12.3",
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": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harness-everything",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
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",
@@ -5,8 +5,15 @@ const crypto = require('crypto');
5
5
  const path = require('path');
6
6
  const { spawnSync } = require('child_process');
7
7
 
8
- function gitRaw(cwd, args) {
9
- const result = spawnSync('git', args, { cwd, encoding: 'utf8', windowsHide: true, timeout: 5000, maxBuffer: 16 * 1024 * 1024 });
8
+ function gitRaw(cwd, args, options = {}) {
9
+ const result = spawnSync('git', args, {
10
+ cwd,
11
+ encoding: 'utf8',
12
+ windowsHide: true,
13
+ timeout: options.timeout ?? 5000,
14
+ maxBuffer: options.maxBuffer ?? (16 * 1024 * 1024),
15
+ ...(options.input === undefined ? {} : { input: options.input }),
16
+ });
10
17
  if (result.status !== 0) throw new Error('cannot verify Git worktree isolation');
11
18
  return result.stdout;
12
19
  }
@@ -15,30 +22,73 @@ function git(cwd, args) {
15
22
  return gitRaw(cwd, args).trim();
16
23
  }
17
24
 
18
- function hashWorktreePath(root, relative) {
19
- const target = path.join(root, relative);
20
- let stat;
21
- try { stat = fs.lstatSync(target); }
22
- catch (error) {
23
- if (error.code === 'ENOENT') return null;
24
- throw error;
25
+ function fingerprintLimitError(count, maxPaths) {
26
+ const error = new Error('workspace fingerprint path limit exceeded');
27
+ error.code = 'HARNESS_FINGERPRINT_LIMIT';
28
+ error.count = count;
29
+ error.maxPaths = maxPaths;
30
+ return error;
31
+ }
32
+
33
+ function hashWorktreePaths(root, relatives) {
34
+ const values = new Map();
35
+ const batch = [];
36
+ for (const relative of relatives) {
37
+ const target = path.join(root, relative);
38
+ let stat;
39
+ try { stat = fs.lstatSync(target); }
40
+ catch (error) {
41
+ if (error.code === 'ENOENT') {
42
+ values.set(relative, null);
43
+ continue;
44
+ }
45
+ throw error;
46
+ }
47
+ if (stat.isDirectory()) {
48
+ const result = spawnSync('git', ['-C', target, 'rev-parse', 'HEAD'], {
49
+ encoding: 'utf8', windowsHide: true, timeout: 5000,
50
+ });
51
+ values.set(relative, { mode: '160000', oid: result.status === 0 ? result.stdout.trim() : 'directory' });
52
+ continue;
53
+ }
54
+ const mode = stat.isSymbolicLink() ? '120000' : ((stat.mode & 0o111) ? '100755' : '100644');
55
+ // --stdin-paths is line-delimited. Rare pathnames containing a newline use
56
+ // the legacy one-file call so the fingerprint remains exact.
57
+ if (/[\r\n]/.test(relative)) {
58
+ const one = spawnSync('git', ['hash-object', '--path=' + relative, '--', relative], {
59
+ cwd: root, encoding: 'utf8', windowsHide: true, timeout: 5000,
60
+ });
61
+ if (one.status !== 0) throw new Error('cannot fingerprint workspace content');
62
+ values.set(relative, { mode, oid: one.stdout.trim() });
63
+ continue;
64
+ }
65
+ batch.push({ relative, mode });
25
66
  }
26
- if (stat.isDirectory()) {
27
- const result = spawnSync('git', ['-C', target, 'rev-parse', 'HEAD'], { encoding: 'utf8', windowsHide: true, timeout: 5000 });
28
- return { mode: '160000', oid: result.status === 0 ? result.stdout.trim() : 'directory' };
67
+
68
+ if (batch.length > 0) {
69
+ const hashed = spawnSync('git', ['hash-object', '--stdin-paths'], {
70
+ cwd: root,
71
+ input: batch.map(item => item.relative).join('\n') + '\n',
72
+ encoding: 'utf8',
73
+ windowsHide: true,
74
+ timeout: 15000,
75
+ maxBuffer: 16 * 1024 * 1024,
76
+ });
77
+ if (hashed.status !== 0) throw new Error('cannot fingerprint workspace content');
78
+ const oids = hashed.stdout.split(/\r?\n/).filter(Boolean);
79
+ if (oids.length !== batch.length) throw new Error('cannot fingerprint workspace content');
80
+ for (let i = 0; i < batch.length; i++) {
81
+ values.set(batch[i].relative, { mode: batch[i].mode, oid: oids[i] });
82
+ }
29
83
  }
30
- const mode = stat.isSymbolicLink() ? '120000' : ((stat.mode & 0o111) ? '100755' : '100644');
31
- const result = spawnSync('git', ['hash-object', '--path=' + relative, '--', relative], {
32
- cwd: root, encoding: 'utf8', windowsHide: true, timeout: 5000,
33
- });
34
- if (result.status !== 0) throw new Error('cannot fingerprint workspace content');
35
- return { mode, oid: result.stdout.trim() };
84
+ return values;
36
85
  }
37
86
 
38
- function workspaceFingerprint(cwd) {
87
+ function workspaceFingerprint(cwd, options = {}) {
39
88
  const root = canonical(git(cwd, ['rev-parse', '--show-toplevel']));
40
89
  const entries = new Map();
41
- for (const record of gitRaw(root, ['ls-files', '-s', '-z']).split('\0')) {
90
+ const largeGitRead = { timeout: 15000, maxBuffer: 64 * 1024 * 1024 };
91
+ for (const record of gitRaw(root, ['ls-files', '-s', '-z'], largeGitRead).split('\0')) {
42
92
  if (!record) continue;
43
93
  const tab = record.indexOf('\t');
44
94
  if (tab < 0) throw new Error('cannot fingerprint workspace index');
@@ -49,18 +99,25 @@ function workspaceFingerprint(cwd) {
49
99
  entries.set(relative, { relative, mode, oid });
50
100
  }
51
101
 
102
+ const changed = gitRaw(root, ['diff-files', '--name-only', '-z'], largeGitRead).split('\0').filter(Boolean);
103
+ const untracked = gitRaw(root, ['ls-files', '--others', '--exclude-standard', '-z'], largeGitRead).split('\0').filter(Boolean);
104
+ const observedPaths = [...new Set([...changed, ...untracked])];
105
+ const maxPaths = Number.isInteger(options.maxPaths) && options.maxPaths > 0 ? options.maxPaths : 5000;
106
+ if (observedPaths.length > maxPaths) throw fingerprintLimitError(observedPaths.length, maxPaths);
107
+ const worktreeValues = hashWorktreePaths(root, observedPaths);
108
+
52
109
  // Substitute current worktree content for tracked paths that differ from the
53
110
  // index. This keeps the fingerprint stable across git add / git commit when
54
111
  // visible workspace content did not change.
55
- for (const relative of gitRaw(root, ['diff-files', '--name-only', '-z']).split('\0').filter(Boolean)) {
56
- const value = hashWorktreePath(root, relative);
112
+ for (const relative of changed) {
113
+ const value = worktreeValues.get(relative);
57
114
  if (value) entries.set(relative, { relative, mode: value.mode, oid: value.oid });
58
115
  else entries.delete(relative);
59
116
  }
60
117
 
61
- for (const relative of gitRaw(root, ['ls-files', '--others', '--exclude-standard', '-z']).split('\0').filter(Boolean)) {
62
- const value = hashWorktreePath(root, relative);
63
- entries.set(relative, { relative, mode: value.mode, oid: value.oid });
118
+ for (const relative of untracked) {
119
+ const value = worktreeValues.get(relative);
120
+ if (value) entries.set(relative, { relative, mode: value.mode, oid: value.oid });
64
121
  }
65
122
 
66
123
  const digest = crypto.createHash('sha256');
@@ -39,8 +39,10 @@ function observeWorkspaceMutation(payload, root) {
39
39
  try {
40
40
  after = workspaceFingerprint(observationCwd);
41
41
  } catch (error) {
42
- if (!isMajorWorkflow(context.workflow)) {
43
- const conservative = settleMutationProbeConservative(context, probeKey, toolName, 'unobservable-workspace');
42
+ const fingerprintLimited = error && error.code === 'HARNESS_FINGERPRINT_LIMIT';
43
+ if (!isMajorWorkflow(context.workflow) || fingerprintLimited) {
44
+ const evidence = fingerprintLimited ? 'fingerprint-limit' : 'unobservable-workspace';
45
+ const conservative = settleMutationProbeConservative(context, probeKey, toolName, evidence);
44
46
  return Boolean(conservative && conservative.changed);
45
47
  }
46
48
  context.workflow.state = 'blocked';
@@ -79,9 +79,11 @@ function decide(payload) {
79
79
  try {
80
80
  fingerprint = workspaceFingerprint(cwd);
81
81
  } catch (error) {
82
- if (isMajorWorkflow(workflow)) throw error;
82
+ const fingerprintLimited = error && error.code === 'HARNESS_FINGERPRINT_LIMIT';
83
+ if (isMajorWorkflow(workflow) && !fingerprintLimited) throw error;
84
+ const evidence = fingerprintLimited ? 'shell:fingerprint-limit' : 'shell:unobservable-workspace';
83
85
  if (workflow.strategy === 'iterative-single') {
84
- recordBudgetEvent(context, 'iteration', { evidence: 'shell:unobservable-workspace' });
86
+ recordBudgetEvent(context, 'iteration', { evidence });
85
87
  }
86
88
  workflow.lastMutationAt = Date.now();
87
89
  saveWorkflow(context);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "harness-everything",
4
- "version": "0.12.2",
4
+ "version": "0.12.3",
5
5
  "description": "Invariant-first engineering harness for routing, verification, and failure recovery while preserving agent autonomy.",
6
6
  "author": {
7
7
  "name": "Miya Daniel",