harness-everything 1.0.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harness-everything",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harness-everything",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",
@@ -25,6 +25,66 @@ const FILE_MUTATION_TOOLS = new Set([
25
25
  'multi_replace_file_content'
26
26
  ]);
27
27
 
28
+ const FAILED_STATUSES = new Set([
29
+ 'failed',
30
+ 'fail',
31
+ 'error',
32
+ 'errored',
33
+ 'timed_out',
34
+ 'timeout',
35
+ 'cancelled',
36
+ 'canceled',
37
+ 'aborted'
38
+ ]);
39
+
40
+ function normalizeErrorText(rawError) {
41
+ if (typeof rawError === 'string') return rawError.trim();
42
+ if (rawError === null || rawError === undefined || rawError === false) return '';
43
+ if (typeof rawError === 'object') {
44
+ if (Array.isArray(rawError) && rawError.length === 0) return '';
45
+ if (!Array.isArray(rawError) && Object.keys(rawError).length === 0) return '';
46
+ }
47
+ const serialized = JSON.stringify(rawError);
48
+ return typeof serialized === 'string' ? serialized.trim() : '';
49
+ }
50
+
51
+ function hasExplicitFailureFlag(obj) {
52
+ return obj.isError === true
53
+ || obj.is_error === true
54
+ || obj.success === false
55
+ || obj.ok === false
56
+ || obj.interrupted === true;
57
+ }
58
+
59
+ function classifyStructuredOutcome(safePayload, responseObj, error) {
60
+ const rawExitCodes = [
61
+ safePayload.exitCode,
62
+ safePayload.exit_code,
63
+ responseObj.exitCode,
64
+ responseObj.exit_code
65
+ ].filter(Number.isInteger);
66
+ const nonzeroCode = rawExitCodes.find(code => code !== 0);
67
+ const exitCode = nonzeroCode ?? rawExitCodes[0];
68
+
69
+ const statuses = [safePayload.status, responseObj.status]
70
+ .filter(value => typeof value === 'string' && value.trim())
71
+ .map(value => value.trim().toLowerCase());
72
+
73
+ // Structured host errors, failure flags, and nonzero exit codes win over any
74
+ // zero or generic metadata fields. Text-only stdout/output markers are never parsed here
75
+ // because retained AGY captures do not distinguish host metadata from stdout.
76
+ const isFailed = Boolean(error && error.trim())
77
+ || (exitCode !== undefined && exitCode !== 0)
78
+ || hasExplicitFailureFlag(safePayload)
79
+ || hasExplicitFailureFlag(responseObj)
80
+ || statuses.some(status => FAILED_STATUSES.has(status));
81
+
82
+ return {
83
+ isFailed,
84
+ exitCode: isFailed ? (exitCode !== undefined && exitCode !== 0 ? exitCode : undefined) : exitCode
85
+ };
86
+ }
87
+
28
88
  function mapAgyPayloadToStatePersist(payload) {
29
89
  const safePayload = payload && typeof payload === 'object' ? payload : {};
30
90
  const sessionId = getAgySessionId(safePayload);
@@ -56,21 +116,22 @@ function mapAgyPayloadToStatePersist(payload) {
56
116
  toolInput = { ...args, file_path: filePath };
57
117
  }
58
118
 
59
- const toolResponse = safePayload.toolResponse || safePayload.tool_response || safePayload.result || {};
60
- const rawError = safePayload.error || toolResponse.error || '';
61
- const error = typeof rawError === 'string' ? rawError : (rawError ? JSON.stringify(rawError) : '');
62
- const stdout = toolResponse.stdout || (typeof safePayload.output === 'string' ? safePayload.output : '') || '';
63
- const stderr = toolResponse.stderr || (typeof error === 'string' ? error : '') || '';
64
-
65
- const rawExitCodes = [
66
- safePayload.exitCode,
67
- safePayload.exit_code,
68
- toolResponse.exitCode,
69
- toolResponse.exit_code
70
- ].filter(Number.isInteger);
71
- const exitCode = rawExitCodes.find(code => code !== 0) ?? rawExitCodes[0];
119
+ const rawResponse = safePayload.toolResponse || safePayload.tool_response || safePayload.result;
120
+ const responseObj = (rawResponse && typeof rawResponse === 'object' && !Array.isArray(rawResponse))
121
+ ? rawResponse
122
+ : {};
123
+ const error = normalizeErrorText(safePayload.error) || normalizeErrorText(responseObj.error);
124
+ const stdout = (typeof responseObj.stdout === 'string' && responseObj.stdout)
125
+ || (typeof safePayload.stdout === 'string' && safePayload.stdout)
126
+ || (typeof safePayload.output === 'string' && safePayload.output)
127
+ || (typeof rawResponse === 'string' && rawResponse)
128
+ || '';
129
+ const stderr = (typeof responseObj.stderr === 'string' && responseObj.stderr)
130
+ || (typeof safePayload.stderr === 'string' && safePayload.stderr)
131
+ || error
132
+ || '';
72
133
 
73
- const isFailed = Boolean(error && error.trim()) || (exitCode !== undefined && exitCode !== 0);
134
+ const { isFailed, exitCode } = classifyStructuredOutcome(safePayload, responseObj, error);
74
135
 
75
136
  return {
76
137
  hook_event_name: isFailed ? 'PostToolUseFailure' : 'PostToolUse',
@@ -89,7 +150,9 @@ function mapAgyPayloadToStatePersist(payload) {
89
150
  stderr,
90
151
  ...(exitCode !== undefined ? { exitCode } : {})
91
152
  },
92
- error: isFailed ? (error || stderr || `Command exited with code ${exitCode}`) : '',
153
+ error: isFailed
154
+ ? (error || stderr || (exitCode !== undefined ? `Command exited with code ${exitCode}` : 'Tool execution failed'))
155
+ : '',
93
156
  ...(exitCode !== undefined ? { exitCode } : {})
94
157
  };
95
158
  }
@@ -121,4 +184,4 @@ if (require.main === module) {
121
184
  });
122
185
  }
123
186
 
124
- module.exports = { main, mapAgyPayloadToStatePersist };
187
+ module.exports = { main, mapAgyPayloadToStatePersist, classifyStructuredOutcome };
@@ -26,6 +26,7 @@ const {
26
26
  normalizeAgyStatePayload
27
27
  } = require('./lib/agy-adapter-core');
28
28
  const { getWorkspaceRoot, getSessionDir } = require('./lib/harness-state');
29
+ const { workspaceFingerprint } = require('./lib/workflow-isolation');
29
30
 
30
31
  const STOP_STATE_FILE = 'agy-stop-state.json';
31
32
 
@@ -40,16 +41,58 @@ function readStopState(filePath) {
40
41
  }
41
42
 
42
43
  function writeStopState(filePath, state) {
44
+ let temp;
43
45
  try {
44
46
  fs.mkdirSync(path.dirname(filePath), { recursive: true });
45
- const temp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
47
+ temp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
46
48
  fs.writeFileSync(temp, JSON.stringify(state, null, 2) + '\n', 'utf8');
47
49
  fs.renameSync(temp, filePath);
50
+ return true;
48
51
  } catch (_) {
49
- // Best-effort marker write; never fail stop evaluation on state IO.
52
+ if (temp) { try { fs.unlinkSync(temp); } catch (_) {} }
53
+ return false;
50
54
  }
51
55
  }
52
56
 
57
+ function clearStopState(filePath) {
58
+ try { fs.unlinkSync(filePath); } catch (_) {}
59
+ }
60
+
61
+ function pendingRevision(handoff, root, sessionId) {
62
+ const directRevision = Number.isSafeInteger(handoff && handoff.agyDirectMutationRevision)
63
+ ? handoff.agyDirectMutationRevision
64
+ : null;
65
+ let contentFingerprint = null;
66
+ try { contentFingerprint = workspaceFingerprint(root, { maxPaths: 5000 }); } catch (_) {}
67
+ return {
68
+ revision: directRevision === null ? `session:${sessionId || 'default'}` : `direct:${directRevision}`,
69
+ directRevision,
70
+ contentFingerprint
71
+ };
72
+ }
73
+
74
+ function samePendingRevision(saved, current) {
75
+ if (!saved) return false;
76
+ if (!saved.lastContinuedRevision) {
77
+ // Older markers have no stable revision. Keep their session allowance
78
+ // when handoff state is legacy too; the prior content baseline is unknown.
79
+ return current.directRevision === null && Boolean(saved.lastContinuedFingerprint);
80
+ }
81
+ if (saved.lastContinuedRevision !== current.revision) return false;
82
+ return !current.contentFingerprint || !saved.lastContinuedContentFingerprint
83
+ || saved.lastContinuedContentFingerprint === current.contentFingerprint;
84
+ }
85
+
86
+ function stopMarker(revision, reason) {
87
+ return {
88
+ lastContinuedRevision: revision.revision,
89
+ lastContinuedContentFingerprint: revision.contentFingerprint,
90
+ lastContinuedFingerprint: `${revision.revision}${revision.contentFingerprint ? `|workspace:${revision.contentFingerprint}` : ''}`,
91
+ lastContinuedReason: reason,
92
+ updatedAt: new Date().toISOString()
93
+ };
94
+ }
95
+
53
96
  const ABNORMAL_TERMINATION_REASONS = new Set([
54
97
  'USER_CANCELED',
55
98
  'CANCELED',
@@ -103,17 +146,14 @@ function evaluateStop(payload) {
103
146
  let pending = null;
104
147
  if (isFailed) {
105
148
  pending = {
106
- fingerprint: `failed:${handoff.timestamp || ''}:${handoff.tool || ''}:${handoff.exitCode ?? ''}`,
107
149
  reason: 'Harness Verify-Before-Claim: pending tool failure must be resolved before claiming completion.'
108
150
  };
109
151
  } else if (lastEditAt > 0 && lastVerifyAt < lastEditAt) {
110
152
  pending = {
111
- fingerprint: `edit:${lastEditAt}`,
112
153
  reason: 'Harness Verify-Before-Claim: unverified edits exist in session. Run relevant test/build/lint verification before claiming completion.'
113
154
  };
114
155
  } else if (process.env.HARNESS_REQUIRE_VERIFICATION === '1' && (!lastVerifyAt || lastVerifyAt < lastEditAt)) {
115
156
  pending = {
116
- fingerprint: `strict:${lastVerifyAt}`,
117
157
  reason: 'Harness Verify-Before-Claim: objective test verification is required before claiming completion.'
118
158
  };
119
159
  }
@@ -121,19 +161,32 @@ function evaluateStop(payload) {
121
161
  if (pending) {
122
162
  const stopStateFile = path.join(sessionDir, STOP_STATE_FILE);
123
163
  const saved = readStopState(stopStateFile);
124
- if (saved && saved.lastContinuedFingerprint === pending.fingerprint) {
164
+ const revision = pendingRevision(handoff, root, sessionId);
165
+ if (samePendingRevision(saved, revision)) {
166
+ if (saved.lastContinuedReason !== pending.reason
167
+ || saved.lastContinuedRevision !== revision.revision
168
+ || (!saved.lastContinuedContentFingerprint && revision.contentFingerprint)) {
169
+ const marker = stopMarker(revision, pending.reason);
170
+ // A missed probe can refresh diagnostics, but cannot erase the last content baseline.
171
+ if (!revision.contentFingerprint && saved.lastContinuedContentFingerprint) {
172
+ marker.lastContinuedContentFingerprint = saved.lastContinuedContentFingerprint;
173
+ marker.lastContinuedFingerprint = saved.lastContinuedFingerprint;
174
+ }
175
+ writeStopState(stopStateFile, {
176
+ ...saved,
177
+ ...marker
178
+ });
179
+ }
125
180
  return { decision: 'allow' };
126
181
  }
127
- writeStopState(stopStateFile, {
128
- lastContinuedFingerprint: pending.fingerprint,
129
- updatedAt: new Date().toISOString()
130
- });
182
+ if (!writeStopState(stopStateFile, stopMarker(revision, pending.reason))) return { decision: 'allow' };
131
183
  return {
132
184
  decision: 'continue',
133
185
  reason: pending.reason
134
186
  };
135
187
  }
136
188
 
189
+ clearStopState(path.join(sessionDir, STOP_STATE_FILE));
137
190
  return { decision: 'allow' };
138
191
  }
139
192
 
@@ -190,40 +190,152 @@ function words(command) {
190
190
  return tokens;
191
191
  }
192
192
 
193
- // Recognize only a bounded top-level sequence. Wrappers, pipelines, redirects,
194
- // subshells, and heredocs stay unsupported; quoted separators remain arguments.
193
+ function literalRedirectTarget(command, start) {
194
+ let index = start;
195
+ while (index < command.length && /\s/.test(command[index])) index += 1;
196
+ const targetStart = index;
197
+ let quote = null;
198
+ let length = 0;
199
+ for (; index < command.length; index += 1) {
200
+ const char = command[index];
201
+ if (quote === "'") {
202
+ if (char === "'") quote = null;
203
+ else length += 1;
204
+ continue;
205
+ }
206
+ if (quote === '"') {
207
+ if (char === '"') quote = null;
208
+ else if (char === '\\' && index + 1 < command.length) { index += 1; length += 1; }
209
+ else if (char === '$' || char === '`') return null;
210
+ else length += 1;
211
+ continue;
212
+ }
213
+ if (char === '"' || char === "'") { quote = char; continue; }
214
+ if (char === '\\' && index + 1 < command.length) { index += 1; length += 1; continue; }
215
+ if (/\s/.test(char) || ';|&<>'.includes(char)) break;
216
+ if (char === '#' && index === targetStart) return null;
217
+ if ('()$`'.includes(char) || /[*?\[\]{}]/.test(char) || (char === '~' && length === 0)) return null;
218
+ length += 1;
219
+ }
220
+ return quote || length === 0 ? null : index;
221
+ }
222
+
223
+ function readRedirect(command, index, fileDescriptor) {
224
+ const char = command[index];
225
+ let operatorEnd = index + 1;
226
+ if (char === '<') {
227
+ if (command[index + 1] === '<' || command[index + 1] === '>') return null;
228
+ } else if (char === '>') {
229
+ if (command[index + 1] === '|') return null;
230
+ if (command[index + 1] === '>') operatorEnd += 1;
231
+ else if (command[index + 1] === '&') {
232
+ if (!fileDescriptor) return null;
233
+ let targetEnd = index + 2;
234
+ const digitsStart = targetEnd;
235
+ while (/[0-9]/.test(command[targetEnd] || '')) targetEnd += 1;
236
+ if (targetEnd === digitsStart ||
237
+ (targetEnd < command.length && !/\s/.test(command[targetEnd]) && !';|&<>'.includes(command[targetEnd]))) return null;
238
+ return targetEnd;
239
+ }
240
+ } else if (char === '&') {
241
+ if (command[index + 1] !== '>' || command[index + 2] === '>') return null;
242
+ operatorEnd += 1;
243
+ } else return null;
244
+ return literalRedirectTarget(command, operatorEnd);
245
+ }
246
+
247
+ // Recognize a bounded top-level command list; redirects are removed before
248
+ // candidate matching so their filenames never become command words.
195
249
  function splitSimpleCommandSegments(command) {
196
250
  if (typeof command !== 'string' || command.length > LIMITS.command || /[\r\n\0]/.test(command)) return null;
197
251
  const segments = [];
252
+ let segment = '';
198
253
  let quote = null;
199
- let start = 0;
254
+ let tokenStart = true;
255
+ let afterSeparator = false;
200
256
  for (let index = 0; index < command.length; index += 1) {
201
257
  const char = command[index];
202
- if (quote) {
203
- if (char === quote) quote = null;
204
- else if (char === '\\' && quote === '"' && index + 1 < command.length) index += 1;
258
+ if (quote === "'") {
259
+ segment += char;
260
+ if (char === "'") quote = null;
261
+ tokenStart = false;
262
+ afterSeparator = false;
205
263
  continue;
206
264
  }
207
- if (char === '"' || char === "'") { quote = char; continue; }
208
- if (char === '\\' && index + 1 < command.length) { index += 1; continue; }
209
- if ('<>()`'.includes(char)) return null;
265
+ if (quote === '"') {
266
+ if (char === '"') { segment += char; quote = null; tokenStart = false; afterSeparator = false; continue; }
267
+ if (char === '\\' && index + 1 < command.length) { segment += char + command[++index]; afterSeparator = false; continue; }
268
+ if (char === '`' || (char === '$' && command[index + 1] === '(')) return null;
269
+ segment += char;
270
+ afterSeparator = false;
271
+ continue;
272
+ }
273
+ if (char === '"' || char === "'") { segment += char; quote = char; tokenStart = false; afterSeparator = false; continue; }
274
+ if (char === '\\' && index + 1 < command.length) { segment += char + command[++index]; tokenStart = false; afterSeparator = false; continue; }
275
+ if (char === '`' || (char === '$' && command[index + 1] === '(') || '()'.includes(char)) return null;
276
+ if (char === '#' && tokenStart) {
277
+ if (afterSeparator) return null;
278
+ break;
279
+ }
280
+ if (/\s/.test(char)) { segment += char; tokenStart = true; continue; }
281
+
282
+ let descriptorEnd = index;
283
+ if (tokenStart && /[0-9]/.test(char)) {
284
+ while (/[0-9]/.test(command[descriptorEnd] || '')) descriptorEnd += 1;
285
+ if (command[descriptorEnd] === '>' || command[descriptorEnd] === '<') {
286
+ const end = readRedirect(command, descriptorEnd, true);
287
+ if (end === null) return null;
288
+ index = end - 1;
289
+ tokenStart = true;
290
+ continue;
291
+ }
292
+ }
293
+ if (char === '<' || char === '>') {
294
+ const end = readRedirect(command, index, false);
295
+ if (end === null) return null;
296
+ index = end - 1;
297
+ tokenStart = true;
298
+ continue;
299
+ }
300
+ if (char === '&' && command[index + 1] === '>') {
301
+ const end = readRedirect(command, index, false);
302
+ if (end === null) return null;
303
+ index = end - 1;
304
+ tokenStart = true;
305
+ continue;
306
+ }
307
+
210
308
  let separatorLength = 0;
211
309
  if (char === ';') separatorLength = 1;
212
- else if (char === '&' || char === '|') {
213
- if (command[index + 1] !== char || command[index + 2] === char) return null;
310
+ else if (char === '&') {
311
+ if (command[index + 1] !== '&' || command[index + 2] === '&') return null;
214
312
  separatorLength = 2;
313
+ } else if (char === '|') {
314
+ if (command[index + 1] === '&' || command[index + 2] === '|') return null;
315
+ separatorLength = command[index + 1] === '|' ? 2 : 1;
215
316
  }
216
- if (!separatorLength) continue;
217
- const segment = command.slice(start, index).trim();
218
- if (!segment || segments.length >= LIMITS.commandSegments - 1) return null;
219
- segments.push(segment);
220
- index += separatorLength - 1;
221
- start = index + 1;
317
+ if (separatorLength) {
318
+ const current = segment.trim();
319
+ if (!current || segments.length >= LIMITS.commandSegments - 1) return null;
320
+ segments.push(current);
321
+ segment = '';
322
+ index += separatorLength - 1;
323
+ tokenStart = true;
324
+ afterSeparator = true;
325
+ continue;
326
+ }
327
+ if (char === '&' || char === '|') return null;
328
+ segment += char;
329
+ tokenStart = false;
330
+ afterSeparator = false;
222
331
  }
223
332
  if (quote) return null;
224
- const finalSegment = command.slice(start).trim();
225
- if (!finalSegment || segments.length >= LIMITS.commandSegments) return null;
226
- segments.push(finalSegment);
333
+ const finalSegment = segment.trim();
334
+ if (afterSeparator) return null;
335
+ if (finalSegment) {
336
+ if (segments.length >= LIMITS.commandSegments) return null;
337
+ segments.push(finalSegment);
338
+ }
227
339
  return segments;
228
340
  }
229
341
 
@@ -139,7 +139,13 @@ function processState(payload) {
139
139
  const isDirectTool = toolName === 'Edit' || toolName === 'Write' || toolName === 'apply_patch';
140
140
  if (isDirectTool && (agy
141
141
  ? agyDirectMutationInWorkspace(payload, cwdOf(payload, root), root, toolName)
142
- : directMutationInWorkspace(payload, cwdOf(payload, root), root))) state.lastEditAt = Date.now();
142
+ : directMutationInWorkspace(payload, cwdOf(payload, root), root))) {
143
+ state.lastEditAt = Date.now();
144
+ if (agy) {
145
+ const revision = Number.isSafeInteger(state.agyDirectMutationRevision) ? state.agyDirectMutationRevision : 0;
146
+ if (revision < Number.MAX_SAFE_INTEGER) state.agyDirectMutationRevision = revision + 1;
147
+ }
148
+ }
143
149
  const isShell = toolName === 'Bash' || toolName === 'PowerShell' || toolName === 'exec_command';
144
150
  const command = (payload.tool_input && payload.tool_input.command) || '';
145
151
  if (isShell) {
@@ -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": "1.0.0",
4
+ "version": "1.0.1",
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",
package/sbom.cdx.json CHANGED
@@ -2,23 +2,23 @@
2
2
  "$schema": "https://cyclonedx.org/schema/bom-1.7.schema.json",
3
3
  "bomFormat": "CycloneDX",
4
4
  "specVersion": "1.7",
5
- "serialNumber": "urn:uuid:ff5d04d0-54bd-5ddb-9f0d-9cfa7c77a6ce",
5
+ "serialNumber": "urn:uuid:5e19a56c-c29d-5512-8fe8-c5b8456ca9ff",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-11-24T15:33:36.933Z",
8
+ "timestamp": "2026-11-24T21:06:36.371Z",
9
9
  "tools": [
10
10
  {
11
11
  "vendor": "Harness Everything",
12
12
  "name": "generate-sbom.js",
13
- "version": "1.0.0"
13
+ "version": "1.0.1"
14
14
  }
15
15
  ],
16
16
  "component": {
17
17
  "type": "application",
18
- "bom-ref": "pkg:npm/harness-everything@1.0.0",
18
+ "bom-ref": "pkg:npm/harness-everything@1.0.1",
19
19
  "name": "harness-everything",
20
- "version": "1.0.0",
21
- "purl": "pkg:npm/harness-everything@1.0.0"
20
+ "version": "1.0.1",
21
+ "purl": "pkg:npm/harness-everything@1.0.1"
22
22
  }
23
23
  },
24
24
  "components": [
@@ -2033,7 +2033,7 @@
2033
2033
  ]
2034
2034
  },
2035
2035
  {
2036
- "ref": "pkg:npm/harness-everything@1.0.0",
2036
+ "ref": "pkg:npm/harness-everything@1.0.1",
2037
2037
  "dependsOn": [
2038
2038
  "pkg:npm/%40commitlint/cli@19.8.1",
2039
2039
  "pkg:npm/%40commitlint/config-conventional@19.8.1",