harness-everything 0.53.0 → 0.54.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +3 -1
- package/CHANGELOG.md +18 -0
- package/bin/cli.js +1 -0
- package/ci/invariant-routing.test.js +22 -3
- package/ci/mechanism-2al-codex-hooks-compat.test.js +56 -2
- package/ci/mechanism-349-ci-change-scope.test.js +78 -57
- package/ci/mechanism-397-cycle-import.test.js +18 -3
- package/ci/mechanism-check-packet-write-set.test.js +232 -0
- package/ci/mechanism-codex-prompt-pass-through.test.js +8 -4
- package/ci/mechanism-error-handling-map.test.js +219 -0
- package/ci/mechanism-report-writer.test.js +335 -0
- package/ci/router-workflow-plan.test.js +50 -7
- package/docs/architecture.md +4 -3
- package/docs/error-handling/README.md +250 -0
- package/docs/error-handling/actions/c1-action-map.md +89 -0
- package/docs/error-handling/actions/c2-action-map.md +22 -0
- package/docs/error-handling/actions/c3-action-map.md +26 -0
- package/docs/error-handling/actions/c5-action-map.md +31 -0
- package/docs/error-handling/actions/c6-action-map.md +37 -0
- package/docs/error-handling/actions/c7-action-map.md +18 -0
- package/docs/error-handling/actions/e0002-action-map.md +101 -0
- package/docs/error-handling/activity.puml +84 -0
- package/docs/error-handling/details/c1-authority-conformance.md +93 -0
- package/docs/error-handling/details/c2-test-root-containment.md +35 -0
- package/docs/error-handling/details/c3-mode-ownership.md +50 -0
- package/docs/error-handling/details/c5-host-replay-contract.md +40 -0
- package/docs/error-handling/details/c6-packet-briefing.md +65 -0
- package/docs/error-handling/details/c7-write-set-check.md +54 -0
- package/docs/error-handling/details/e0002-capture-evidence.md +93 -0
- package/docs/error-handling/details/e0002-report-writer.md +116 -0
- package/docs/error-handling/nodes.yaml +44 -0
- package/docs/error-handling/registry.md +59 -0
- package/docs/error-handling/templates/packet-briefing.md +45 -0
- package/docs/platform-capabilities.md +3 -1
- package/hooks/scripts/codex-user-prompt.js +2 -3
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +2 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/codex-user-prompt.js +2 -3
- package/plugins/harness-everything/plugin.json +1 -1
- package/sbom.cdx.json +7 -7
- package/scripts/check-packet-write-set.js +155 -0
- package/scripts/codex-hooks-compat.js +46 -5
- package/scripts/error-handling-map.js +288 -0
- package/scripts/report-writer.js +261 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const crypto = require('node:crypto');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
|
|
8
|
+
const USAGE = 'usage: report-writer write --output <path> --status <DONE|BLOCKED|0|nonzero-int> (--body-file <path>|--context <text>|--from-codex-output <path>) [--reason <text>|--error <text>...] | report-writer check --file <path>';
|
|
9
|
+
const WRITE_OPTIONS = new Set(['--output', '--status', '--reason', '--error', '--body-file', '--context', '--from-codex-output']);
|
|
10
|
+
const LABEL_MARKER = '<!-- harness-label';
|
|
11
|
+
|
|
12
|
+
function error(message) {
|
|
13
|
+
throw new Error(message);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function parseOptions(args, allowed, repeatable = new Set()) {
|
|
17
|
+
const options = new Map();
|
|
18
|
+
for (let i = 0; i < args.length; i += 2) {
|
|
19
|
+
const key = args[i];
|
|
20
|
+
if (!allowed.has(key)) error(`unknown option: ${key}`);
|
|
21
|
+
if (i + 1 >= args.length) error(`missing value for ${key}`);
|
|
22
|
+
if (options.has(key) && !repeatable.has(key)) error(`duplicate option: ${key}`);
|
|
23
|
+
if (repeatable.has(key)) options.set(key, [...(options.get(key) || []), args[i + 1]]);
|
|
24
|
+
else options.set(key, args[i + 1]);
|
|
25
|
+
}
|
|
26
|
+
return options;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function required(options, key) {
|
|
30
|
+
const value = options.get(key);
|
|
31
|
+
if (value === undefined || value === '') error(`missing value for ${key}`);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function singleLine(value, name) {
|
|
36
|
+
if (/\r|\n/.test(value)) error(`${name} must be a single line`);
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function statusFrom(options) {
|
|
41
|
+
const value = singleLine(required(options, '--status'), 'status');
|
|
42
|
+
const reason = options.get('--reason');
|
|
43
|
+
const errors = options.get('--error') || [];
|
|
44
|
+
|
|
45
|
+
let done;
|
|
46
|
+
if (value === 'DONE' || value === '0') done = true;
|
|
47
|
+
else if (value === 'BLOCKED') done = false;
|
|
48
|
+
else if (/^[+-]?\d+$/.test(value) && Number.isSafeInteger(Number(value))) done = Number(value) === 0;
|
|
49
|
+
else error('status must be DONE, BLOCKED, 0, or a nonzero integer');
|
|
50
|
+
|
|
51
|
+
if (done) {
|
|
52
|
+
if (reason !== undefined || errors.length) error('DONE status cannot include a reason or error');
|
|
53
|
+
return 'STATUS: DONE';
|
|
54
|
+
}
|
|
55
|
+
if (reason !== undefined && errors.length) error('provide either --reason or --error, not both');
|
|
56
|
+
const message = reason !== undefined ? reason : errors.join('; ');
|
|
57
|
+
if (message === undefined || message.trim() === '') error('BLOCKED status requires a nonempty --reason or --error');
|
|
58
|
+
singleLine(message, 'reason');
|
|
59
|
+
return `STATUS: BLOCKED: ${message.trim()}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function splitLines(text) {
|
|
63
|
+
if (/\r(?!\n)/.test(text)) error('bare carriage return is not a valid line ending');
|
|
64
|
+
const lines = [];
|
|
65
|
+
const separators = /\r\n|\n/g;
|
|
66
|
+
let start = 0;
|
|
67
|
+
let match;
|
|
68
|
+
while ((match = separators.exec(text))) {
|
|
69
|
+
lines.push({ value: text.slice(start, match.index), start, eol: match[0] });
|
|
70
|
+
start = separators.lastIndex;
|
|
71
|
+
}
|
|
72
|
+
if (start < text.length || text.length === 0 || !text.endsWith('\n')) {
|
|
73
|
+
lines.push({ value: text.slice(start), start, eol: '' });
|
|
74
|
+
}
|
|
75
|
+
return lines;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function statusLineStatus(line) {
|
|
79
|
+
if (line === 'STATUS: DONE') return 'STATUS: DONE';
|
|
80
|
+
const blocked = /^STATUS: BLOCKED: (.+)$/.exec(line);
|
|
81
|
+
if (blocked && blocked[1].trim() !== '') return line;
|
|
82
|
+
error('expected STATUS: DONE or STATUS: BLOCKED: <reason>');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function validateReport(text) {
|
|
86
|
+
if (text.includes(LABEL_MARKER)) error('report contains a host label marker');
|
|
87
|
+
const lines = splitLines(text);
|
|
88
|
+
const controls = lines.filter(line => line.value.startsWith('STATUS:'));
|
|
89
|
+
if (controls.length !== 1) error(`expected exactly one STATUS line; found ${controls.length}`);
|
|
90
|
+
const last = lines[lines.length - 1];
|
|
91
|
+
if (!last || !last.value.startsWith('STATUS:')) error('STATUS line must be terminal with nothing after it');
|
|
92
|
+
return statusLineStatus(last.value);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function validateBody(body) {
|
|
96
|
+
if (body.includes(LABEL_MARKER)) error('body contains a host label marker');
|
|
97
|
+
if (splitLines(body).some(line => line.value.startsWith('STATUS:'))) {
|
|
98
|
+
error('body contains a column-zero STATUS line');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function parseHostLabel(line) {
|
|
103
|
+
const prefix = '<!-- harness-label ';
|
|
104
|
+
const suffix = ' -->';
|
|
105
|
+
if (!line.startsWith(prefix) || !line.endsWith(suffix)) error('malformed terminal host label');
|
|
106
|
+
let value;
|
|
107
|
+
try {
|
|
108
|
+
value = JSON.parse(line.slice(prefix.length, -suffix.length));
|
|
109
|
+
} catch {
|
|
110
|
+
error('terminal host label must contain valid JSON');
|
|
111
|
+
}
|
|
112
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) error('terminal host label JSON must be an object');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function extractCodexBody(raw, expectedStatus) {
|
|
116
|
+
const lines = splitLines(raw);
|
|
117
|
+
let strippedLabel = false;
|
|
118
|
+
let bodyEnd = raw.length;
|
|
119
|
+
const markers = lines.filter(line => line.value.includes(LABEL_MARKER));
|
|
120
|
+
|
|
121
|
+
if (markers.length) {
|
|
122
|
+
if (markers.length !== 1 || markers[0] !== lines[lines.length - 1]) error('host label is allowed only once at EOF');
|
|
123
|
+
parseHostLabel(lines[lines.length - 1].value);
|
|
124
|
+
strippedLabel = true;
|
|
125
|
+
bodyEnd = lines[lines.length - 1].start;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const controls = lines.filter(line => line.value.startsWith('STATUS:'));
|
|
129
|
+
if (controls.length > 1) error(`raw output must contain exactly one STATUS line; found ${controls.length}`);
|
|
130
|
+
if (controls.length === 1) {
|
|
131
|
+
const statusIndex = lines.indexOf(controls[0]);
|
|
132
|
+
const terminalIndex = lines.length - (strippedLabel ? 2 : 1);
|
|
133
|
+
if (statusIndex !== terminalIndex) error('raw STATUS must be terminal or immediately before the host label');
|
|
134
|
+
if (controls[0].value !== expectedStatus) error('raw terminal STATUS does not match the requested status');
|
|
135
|
+
if (strippedLabel && !controls[0].eol) error('host label must be on the line immediately after STATUS');
|
|
136
|
+
bodyEnd = controls[0].start;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const body = raw.slice(0, bodyEnd);
|
|
140
|
+
validateBody(body);
|
|
141
|
+
return { body, strippedLabel };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function assertDistinctFiles(input, output) {
|
|
145
|
+
const inputPath = path.resolve(input);
|
|
146
|
+
const outputPath = path.resolve(output);
|
|
147
|
+
if (inputPath === outputPath) error('output aliases an input file');
|
|
148
|
+
|
|
149
|
+
const inputStat = fs.statSync(inputPath);
|
|
150
|
+
try {
|
|
151
|
+
const outputStat = fs.statSync(outputPath);
|
|
152
|
+
if (inputStat.dev === outputStat.dev && inputStat.ino === outputStat.ino) error('output aliases an input file');
|
|
153
|
+
} catch (cause) {
|
|
154
|
+
if (cause.code !== 'ENOENT') throw cause;
|
|
155
|
+
try {
|
|
156
|
+
const candidate = path.join(fs.realpathSync(path.dirname(outputPath)), path.basename(outputPath));
|
|
157
|
+
if (candidate === fs.realpathSync(inputPath)) error('output aliases an input file');
|
|
158
|
+
} catch (parentError) {
|
|
159
|
+
if (parentError.code !== 'ENOENT') throw parentError;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function readText(file, description) {
|
|
165
|
+
try {
|
|
166
|
+
return fs.readFileSync(file, 'utf8');
|
|
167
|
+
} catch (cause) {
|
|
168
|
+
error(`cannot read ${description} ${file}: ${cause.message}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function reportBytes(body, statusLine) {
|
|
173
|
+
validateBody(body);
|
|
174
|
+
const newline = body.endsWith('\r\n') ? '\r\n' : '\n';
|
|
175
|
+
const separator = body === '' || body.endsWith('\n') ? '' : newline;
|
|
176
|
+
return Buffer.from(`${body}${separator}${statusLine}${newline}`, 'utf8');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function atomicWrite(output, bytes, expectedStatus) {
|
|
180
|
+
const directory = path.dirname(output);
|
|
181
|
+
const temp = path.join(directory, `.${path.basename(output)}.${process.pid}.${crypto.randomBytes(8).toString('hex')}.tmp`);
|
|
182
|
+
let descriptor;
|
|
183
|
+
let published = false;
|
|
184
|
+
try {
|
|
185
|
+
descriptor = fs.openSync(temp, 'wx', 0o666);
|
|
186
|
+
fs.writeFileSync(descriptor, bytes);
|
|
187
|
+
fs.closeSync(descriptor);
|
|
188
|
+
descriptor = undefined;
|
|
189
|
+
|
|
190
|
+
const staged = fs.readFileSync(temp);
|
|
191
|
+
if (!staged.equals(bytes)) error('staged report bytes differ from the intended report');
|
|
192
|
+
if (validateReport(staged.toString('utf8')) !== expectedStatus) error('staged report status differs from the requested status');
|
|
193
|
+
|
|
194
|
+
fs.renameSync(temp, output);
|
|
195
|
+
published = true;
|
|
196
|
+
|
|
197
|
+
const actual = fs.readFileSync(output);
|
|
198
|
+
if (!actual.equals(bytes)) error('published report bytes differ from the staged report');
|
|
199
|
+
if (validateReport(actual.toString('utf8')) !== expectedStatus) error('published report status differs from the requested status');
|
|
200
|
+
} catch (cause) {
|
|
201
|
+
if (descriptor !== undefined) {
|
|
202
|
+
try { fs.closeSync(descriptor); } catch {}
|
|
203
|
+
}
|
|
204
|
+
try { fs.unlinkSync(temp); } catch {}
|
|
205
|
+
if (published) error(`report was published but could not be verified; coordinator disposition required: ${cause.message}`);
|
|
206
|
+
error(`could not publish report before replacement: ${cause.message}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function write(args) {
|
|
211
|
+
const options = parseOptions(args, WRITE_OPTIONS, new Set(['--error']));
|
|
212
|
+
const output = path.resolve(required(options, '--output'));
|
|
213
|
+
const expectedStatus = statusFrom(options);
|
|
214
|
+
const modes = ['--body-file', '--context', '--from-codex-output'].filter(key => options.has(key));
|
|
215
|
+
if (modes.length !== 1) error('provide exactly one of --body-file, --context, or --from-codex-output');
|
|
216
|
+
|
|
217
|
+
let body;
|
|
218
|
+
let strippedLabel = false;
|
|
219
|
+
if (modes[0] === '--context') {
|
|
220
|
+
body = options.get('--context');
|
|
221
|
+
} else {
|
|
222
|
+
const input = required(options, modes[0]);
|
|
223
|
+
assertDistinctFiles(input, output);
|
|
224
|
+
const contents = readText(path.resolve(input), modes[0] === '--body-file' ? 'body file' : 'raw Codex output');
|
|
225
|
+
if (modes[0] === '--from-codex-output') {
|
|
226
|
+
const extracted = extractCodexBody(contents, expectedStatus);
|
|
227
|
+
body = extracted.body;
|
|
228
|
+
strippedLabel = extracted.strippedLabel;
|
|
229
|
+
} else {
|
|
230
|
+
body = contents;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
validateBody(body);
|
|
235
|
+
const bytes = reportBytes(body, expectedStatus);
|
|
236
|
+
atomicWrite(output, bytes, expectedStatus);
|
|
237
|
+
if (strippedLabel) console.error('report-writer: stripped the terminal host label from raw Codex output');
|
|
238
|
+
console.log(`Wrote ${output}`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function check(args) {
|
|
242
|
+
const options = parseOptions(args, new Set(['--file']));
|
|
243
|
+
if (options.size !== 1) error('check requires only --file <path>');
|
|
244
|
+
const file = path.resolve(required(options, '--file'));
|
|
245
|
+
const status = validateReport(readText(file, 'report'));
|
|
246
|
+
console.log(`${file}: valid (${status})`);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function main() {
|
|
250
|
+
try {
|
|
251
|
+
const [command, ...args] = process.argv.slice(2);
|
|
252
|
+
if (command === 'write') write(args);
|
|
253
|
+
else if (command === 'check') check(args);
|
|
254
|
+
else error(USAGE);
|
|
255
|
+
} catch (cause) {
|
|
256
|
+
console.error(`report-writer: ${cause.message}`);
|
|
257
|
+
process.exitCode = 1;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (require.main === module) main();
|