diffpact 0.0.0-stage → 0.4.2
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/CHANGELOG.md +126 -0
- package/LICENSE +21 -0
- package/README.md +214 -2
- package/bin/diffpact.mjs +10 -0
- package/dist/adapters/claude-code.js +191 -0
- package/dist/adapters/codex.js +348 -0
- package/dist/adapters/gemini-agy.js +429 -0
- package/dist/adapters/vercel-board.js +138 -0
- package/dist/amend.js +470 -0
- package/dist/boundaries.js +309 -0
- package/dist/canonical-json.js +63 -0
- package/dist/cli.js +1433 -0
- package/dist/delegate.js +140 -0
- package/dist/doctor.js +293 -0
- package/dist/git.js +219 -0
- package/dist/index.js +19 -0
- package/dist/merge-verify.js +721 -0
- package/dist/report.js +220 -0
- package/dist/review.js +527 -0
- package/dist/runner.js +213 -0
- package/dist/schema.js +424 -0
- package/dist/types.js +220 -0
- package/dist/verify.js +952 -0
- package/dist/worktree.js +717 -0
- package/examples/harnesses/README.md +63 -0
- package/examples/quickstart/README.md +17 -0
- package/examples/quickstart/run.mjs +247 -0
- package/package.json +62 -4
- package/schemas/contract.schema.json +148 -0
- package/schemas/receipt.schema.json +49 -0
- package/schemas/review.schema.json +48 -0
package/dist/amend.js
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { canonicalSha256 } from './canonical-json.js';
|
|
4
|
+
import { commitExists, resolveRepoRoot } from './git.js';
|
|
5
|
+
import { validateContract } from './schema.js';
|
|
6
|
+
import {
|
|
7
|
+
EXIT_INCOMPLETE,
|
|
8
|
+
EXIT_PASS,
|
|
9
|
+
EXIT_STALE,
|
|
10
|
+
EXIT_VIOLATION,
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
} from './types.js';
|
|
14
|
+
|
|
15
|
+
const HEX40 = /^[0-9a-f]{40}$/;
|
|
16
|
+
const HEX64 = /^[0-9a-f]{64}$/;
|
|
17
|
+
const AMENDMENT_SCHEMA_VERSION = 'diffpact-amendment-v0.2' ;
|
|
18
|
+
const AMENDMENT_HASH_DOMAIN = 'diffpact/amendment/v0.2';
|
|
19
|
+
const CONTRACT_HASH_DOMAIN = 'diffpact/contract/v0.1';
|
|
20
|
+
|
|
21
|
+
const ALLOWED_AMENDMENT_KEYS = new Set ([
|
|
22
|
+
'schema_version',
|
|
23
|
+
'sequence',
|
|
24
|
+
'amended_at',
|
|
25
|
+
'authorized_by',
|
|
26
|
+
'reason',
|
|
27
|
+
'previous_contract_sha256',
|
|
28
|
+
'new_contract_sha256',
|
|
29
|
+
'added_allowed_paths',
|
|
30
|
+
'added_read_only_paths',
|
|
31
|
+
'added_forbidden_paths',
|
|
32
|
+
'previous_starting_sha',
|
|
33
|
+
'new_starting_sha',
|
|
34
|
+
'entry_sha256'
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
function isPlainObject(value ) {
|
|
65
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isNonEmptySafeString(value ) {
|
|
69
|
+
return typeof value === 'string' && value.trim().length > 0 && !value.includes('\0');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isNonEmptyStringArray(value ) {
|
|
73
|
+
return Array.isArray(value) && value.every((item) => isNonEmptySafeString(item));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function mergeUniquePaths(
|
|
77
|
+
existing ,
|
|
78
|
+
additions
|
|
79
|
+
) {
|
|
80
|
+
const seen = new Set (existing);
|
|
81
|
+
const merged = [...existing];
|
|
82
|
+
const added = [];
|
|
83
|
+
|
|
84
|
+
for (const raw of additions) {
|
|
85
|
+
if (typeof raw === 'string') {
|
|
86
|
+
const normalized = raw.normalize('NFC').replace(/\\/g, '/');
|
|
87
|
+
if (seen.has(normalized)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
seen.add(normalized);
|
|
91
|
+
merged.push(raw);
|
|
92
|
+
added.push(normalized);
|
|
93
|
+
} else {
|
|
94
|
+
merged.push(raw );
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return { merged, added };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function parseAndValidateEntry(
|
|
102
|
+
raw ,
|
|
103
|
+
expectedSequence ,
|
|
104
|
+
lineNumber
|
|
105
|
+
) {
|
|
106
|
+
if (!isPlainObject(raw)) {
|
|
107
|
+
return { ok: false, error: `Amendment line ${lineNumber} must be a JSON object` };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for (const key of Object.keys(raw)) {
|
|
111
|
+
if (!ALLOWED_AMENDMENT_KEYS.has(key)) {
|
|
112
|
+
return { ok: false, error: `Amendment line ${lineNumber} has unexpected property "${key}"` };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (raw.schema_version !== AMENDMENT_SCHEMA_VERSION) {
|
|
117
|
+
return {
|
|
118
|
+
ok: false,
|
|
119
|
+
error: `Amendment line ${lineNumber} has unsupported schema_version "${String(raw.schema_version)}"`
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (
|
|
124
|
+
typeof raw.sequence !== 'number' ||
|
|
125
|
+
!Number.isInteger(raw.sequence) ||
|
|
126
|
+
raw.sequence !== expectedSequence
|
|
127
|
+
) {
|
|
128
|
+
return {
|
|
129
|
+
ok: false,
|
|
130
|
+
error: `Amendment line ${lineNumber} has invalid sequence ${String(raw.sequence)} (expected ${expectedSequence})`
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!isNonEmptySafeString(raw.amended_at)) {
|
|
135
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid amended_at` };
|
|
136
|
+
}
|
|
137
|
+
if (!isNonEmptySafeString(raw.authorized_by)) {
|
|
138
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid authorized_by` };
|
|
139
|
+
}
|
|
140
|
+
if (!isNonEmptySafeString(raw.reason)) {
|
|
141
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid reason` };
|
|
142
|
+
}
|
|
143
|
+
if (typeof raw.previous_contract_sha256 !== 'string' || !HEX64.test(raw.previous_contract_sha256)) {
|
|
144
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid previous_contract_sha256` };
|
|
145
|
+
}
|
|
146
|
+
if (typeof raw.new_contract_sha256 !== 'string' || !HEX64.test(raw.new_contract_sha256)) {
|
|
147
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid new_contract_sha256` };
|
|
148
|
+
}
|
|
149
|
+
if (typeof raw.entry_sha256 !== 'string' || !HEX64.test(raw.entry_sha256)) {
|
|
150
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid entry_sha256` };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (raw.added_allowed_paths !== undefined && !isNonEmptyStringArray(raw.added_allowed_paths)) {
|
|
154
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid added_allowed_paths` };
|
|
155
|
+
}
|
|
156
|
+
if (raw.added_read_only_paths !== undefined && !isNonEmptyStringArray(raw.added_read_only_paths)) {
|
|
157
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid added_read_only_paths` };
|
|
158
|
+
}
|
|
159
|
+
if (raw.added_forbidden_paths !== undefined && !isNonEmptyStringArray(raw.added_forbidden_paths)) {
|
|
160
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid added_forbidden_paths` };
|
|
161
|
+
}
|
|
162
|
+
if (
|
|
163
|
+
raw.previous_starting_sha !== undefined &&
|
|
164
|
+
(typeof raw.previous_starting_sha !== 'string' || !HEX40.test(raw.previous_starting_sha))
|
|
165
|
+
) {
|
|
166
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid previous_starting_sha` };
|
|
167
|
+
}
|
|
168
|
+
if (
|
|
169
|
+
raw.new_starting_sha !== undefined &&
|
|
170
|
+
(typeof raw.new_starting_sha !== 'string' || !HEX40.test(raw.new_starting_sha))
|
|
171
|
+
) {
|
|
172
|
+
return { ok: false, error: `Amendment line ${lineNumber} has invalid new_starting_sha` };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const { entry_sha256: recordedEntrySha, ...bodyWithoutEntrySha } = raw;
|
|
176
|
+
let expectedEntrySha ;
|
|
177
|
+
try {
|
|
178
|
+
expectedEntrySha = canonicalSha256(AMENDMENT_HASH_DOMAIN, bodyWithoutEntrySha);
|
|
179
|
+
} catch (err) {
|
|
180
|
+
return {
|
|
181
|
+
ok: false,
|
|
182
|
+
error: `Amendment line ${lineNumber} cannot be canonicalized: ${(err ).message}`
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (recordedEntrySha !== expectedEntrySha) {
|
|
187
|
+
return {
|
|
188
|
+
ok: false,
|
|
189
|
+
error: `Amendment line ${lineNumber} entry_sha256 mismatch: expected ${expectedEntrySha}, got ${recordedEntrySha}`
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const entry = {
|
|
194
|
+
schema_version: AMENDMENT_SCHEMA_VERSION,
|
|
195
|
+
sequence: raw.sequence,
|
|
196
|
+
amended_at: raw.amended_at,
|
|
197
|
+
authorized_by: raw.authorized_by,
|
|
198
|
+
reason: raw.reason,
|
|
199
|
+
previous_contract_sha256: raw.previous_contract_sha256,
|
|
200
|
+
new_contract_sha256: raw.new_contract_sha256,
|
|
201
|
+
...(raw.added_allowed_paths !== undefined ? { added_allowed_paths: raw.added_allowed_paths } : {}),
|
|
202
|
+
...(raw.added_read_only_paths !== undefined ? { added_read_only_paths: raw.added_read_only_paths } : {}),
|
|
203
|
+
...(raw.added_forbidden_paths !== undefined ? { added_forbidden_paths: raw.added_forbidden_paths } : {}),
|
|
204
|
+
...(raw.previous_starting_sha !== undefined ? { previous_starting_sha: raw.previous_starting_sha } : {}),
|
|
205
|
+
...(raw.new_starting_sha !== undefined ? { new_starting_sha: raw.new_starting_sha } : {}),
|
|
206
|
+
entry_sha256: recordedEntrySha
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
return { ok: true, entry };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Reads `<pactDir>/amendments.jsonl` and verifies each entry's schema, `entry_sha256`,
|
|
214
|
+
* contiguous 1-based sequence numbers, and `previous_contract_sha256` hash chain.
|
|
215
|
+
*/
|
|
216
|
+
export function readAmendmentHistory(
|
|
217
|
+
contractPath ,
|
|
218
|
+
cwd
|
|
219
|
+
) {
|
|
220
|
+
const contractAbs = path.resolve(cwd ?? process.cwd(), contractPath);
|
|
221
|
+
const pactDir = path.dirname(contractAbs);
|
|
222
|
+
const amendmentsPath = path.join(pactDir, 'amendments.jsonl');
|
|
223
|
+
|
|
224
|
+
if (!fs.existsSync(amendmentsPath)) {
|
|
225
|
+
return { valid: true, entries: [] };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let content ;
|
|
229
|
+
try {
|
|
230
|
+
content = fs.readFileSync(amendmentsPath, 'utf8');
|
|
231
|
+
} catch (err) {
|
|
232
|
+
return {
|
|
233
|
+
valid: false,
|
|
234
|
+
entries: [],
|
|
235
|
+
error: `Failed to read amendments.jsonl: ${(err ).message}`
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const rawLines = content.split(/\r?\n/).filter((line) => line.trim().length > 0);
|
|
240
|
+
const entries = [];
|
|
241
|
+
|
|
242
|
+
for (let i = 0; i < rawLines.length; i++) {
|
|
243
|
+
const line = rawLines[i] ;
|
|
244
|
+
const lineNumber = i + 1;
|
|
245
|
+
let parsed ;
|
|
246
|
+
try {
|
|
247
|
+
parsed = JSON.parse(line);
|
|
248
|
+
} catch (err) {
|
|
249
|
+
return {
|
|
250
|
+
valid: false,
|
|
251
|
+
entries,
|
|
252
|
+
error: `Invalid JSON on line ${lineNumber} of amendments.jsonl: ${(err ).message}`
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const validated = parseAndValidateEntry(parsed, lineNumber, lineNumber);
|
|
257
|
+
if (!validated.ok) {
|
|
258
|
+
return { valid: false, entries, error: validated.error };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const prev = entries[i - 1];
|
|
262
|
+
if (prev && validated.entry.previous_contract_sha256 !== prev.new_contract_sha256) {
|
|
263
|
+
return {
|
|
264
|
+
valid: false,
|
|
265
|
+
entries,
|
|
266
|
+
error: `Amendment hash chain broken at sequence ${validated.entry.sequence}: previous_contract_sha256 (${validated.entry.previous_contract_sha256}) does not match prior new_contract_sha256 (${prev.new_contract_sha256})`
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
entries.push(validated.entry);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return { valid: true, entries };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Applies a validated, audited amendment to an existing task contract, invalidates
|
|
278
|
+
* any stale `receipt.json`, and appends a hash-chained record to `amendments.jsonl`.
|
|
279
|
+
*/
|
|
280
|
+
export function amendContract(options )
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
{
|
|
287
|
+
if (!isNonEmptySafeString(options.authorizedBy)) {
|
|
288
|
+
return {
|
|
289
|
+
exitCode: EXIT_VIOLATION,
|
|
290
|
+
error: 'authorizedBy must be a non-empty string'
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
if (!isNonEmptySafeString(options.reason)) {
|
|
294
|
+
return {
|
|
295
|
+
exitCode: EXIT_VIOLATION,
|
|
296
|
+
error: 'reason must be a non-empty string'
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const authorizedBy = options.authorizedBy.trim();
|
|
301
|
+
const reason = options.reason.trim();
|
|
302
|
+
|
|
303
|
+
const rawAddAllowed = options.addAllowedPaths ?? [];
|
|
304
|
+
const rawAddReadOnly = options.addReadOnlyPaths ?? [];
|
|
305
|
+
const rawAddForbidden = options.addForbiddenPaths ?? [];
|
|
306
|
+
const requestedStartingSha =
|
|
307
|
+
options.updateStartingSha !== undefined ? options.updateStartingSha.trim() : undefined;
|
|
308
|
+
const hasStartingShaRequest =
|
|
309
|
+
requestedStartingSha !== undefined && requestedStartingSha.length > 0;
|
|
310
|
+
|
|
311
|
+
if (
|
|
312
|
+
rawAddAllowed.length === 0 &&
|
|
313
|
+
rawAddReadOnly.length === 0 &&
|
|
314
|
+
rawAddForbidden.length === 0 &&
|
|
315
|
+
!hasStartingShaRequest
|
|
316
|
+
) {
|
|
317
|
+
return {
|
|
318
|
+
exitCode: EXIT_INCOMPLETE,
|
|
319
|
+
error:
|
|
320
|
+
'At least one amendment mutation (addAllowedPaths, addReadOnlyPaths, addForbiddenPaths, or updateStartingSha) is required'
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const contractAbs = path.resolve(options.cwd ?? process.cwd(), options.contractPath);
|
|
325
|
+
if (!fs.existsSync(contractAbs)) {
|
|
326
|
+
return {
|
|
327
|
+
exitCode: EXIT_INCOMPLETE,
|
|
328
|
+
error: `Contract file not found: "${contractAbs}"`
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
let contract ;
|
|
333
|
+
try {
|
|
334
|
+
contract = validateContract(JSON.parse(fs.readFileSync(contractAbs, 'utf8')));
|
|
335
|
+
} catch (err) {
|
|
336
|
+
return {
|
|
337
|
+
exitCode: EXIT_INCOMPLETE,
|
|
338
|
+
error: `Invalid existing contract: ${(err ).message}`
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const previousContractSha256 = canonicalSha256(CONTRACT_HASH_DOMAIN, contract);
|
|
343
|
+
|
|
344
|
+
if (contract.task_type === 'research' && rawAddAllowed.length > 0) {
|
|
345
|
+
return {
|
|
346
|
+
exitCode: EXIT_VIOLATION,
|
|
347
|
+
error: 'Research contracts cannot be granted write paths via addAllowedPaths'
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const history = readAmendmentHistory(contractAbs, options.cwd);
|
|
352
|
+
if (!history.valid) {
|
|
353
|
+
return {
|
|
354
|
+
exitCode: EXIT_VIOLATION,
|
|
355
|
+
error: history.error ?? 'Existing amendment history failed integrity verification'
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const lastEntry = history.entries[history.entries.length - 1];
|
|
360
|
+
if (lastEntry && lastEntry.new_contract_sha256 !== previousContractSha256) {
|
|
361
|
+
return {
|
|
362
|
+
exitCode: EXIT_VIOLATION,
|
|
363
|
+
error: `Contract hash mismatch with amendment log: latest amendment recorded ${lastEntry.new_contract_sha256}, but current contract hashes to ${previousContractSha256}`
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (hasStartingShaRequest) {
|
|
368
|
+
const workDir = options.cwd ?? path.dirname(contractAbs);
|
|
369
|
+
let repoRoot ;
|
|
370
|
+
try {
|
|
371
|
+
repoRoot = resolveRepoRoot(workDir);
|
|
372
|
+
} catch (err) {
|
|
373
|
+
return {
|
|
374
|
+
exitCode: EXIT_INCOMPLETE,
|
|
375
|
+
error: `Git repository unavailable at "${workDir}": ${(err ).message}`
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (!commitExists(repoRoot, requestedStartingSha)) {
|
|
380
|
+
return {
|
|
381
|
+
exitCode: EXIT_STALE,
|
|
382
|
+
error: `Commit "${requestedStartingSha}" does not exist in Git repository`
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const allowedMerge = mergeUniquePaths(contract.allowed_paths, rawAddAllowed);
|
|
388
|
+
const readOnlyMerge = mergeUniquePaths(contract.read_only_paths ?? [], rawAddReadOnly);
|
|
389
|
+
const forbiddenMerge = mergeUniquePaths(contract.forbidden_paths, rawAddForbidden);
|
|
390
|
+
|
|
391
|
+
const nextStartingSha = hasStartingShaRequest ? requestedStartingSha : contract.starting_sha;
|
|
392
|
+
const startingShaChanged = nextStartingSha !== contract.starting_sha;
|
|
393
|
+
|
|
394
|
+
const candidate = {
|
|
395
|
+
...contract,
|
|
396
|
+
starting_sha: nextStartingSha,
|
|
397
|
+
allowed_paths: allowedMerge.merged,
|
|
398
|
+
forbidden_paths: forbiddenMerge.merged,
|
|
399
|
+
...(contract.read_only_paths !== undefined || rawAddReadOnly.length > 0
|
|
400
|
+
? { read_only_paths: readOnlyMerge.merged }
|
|
401
|
+
: {})
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
let updatedContract ;
|
|
405
|
+
try {
|
|
406
|
+
updatedContract = validateContract(candidate);
|
|
407
|
+
} catch (err) {
|
|
408
|
+
return {
|
|
409
|
+
exitCode: EXIT_VIOLATION,
|
|
410
|
+
error: `Amended contract failed schema validation: ${(err ).message}`
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const newContractSha256 = canonicalSha256(CONTRACT_HASH_DOMAIN, updatedContract);
|
|
415
|
+
|
|
416
|
+
if (
|
|
417
|
+
allowedMerge.added.length === 0 &&
|
|
418
|
+
readOnlyMerge.added.length === 0 &&
|
|
419
|
+
forbiddenMerge.added.length === 0 &&
|
|
420
|
+
!startingShaChanged
|
|
421
|
+
) {
|
|
422
|
+
return {
|
|
423
|
+
exitCode: EXIT_INCOMPLETE,
|
|
424
|
+
error: 'Amendment produced no actual changes to the contract'
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const entryBody = {
|
|
429
|
+
schema_version: AMENDMENT_SCHEMA_VERSION,
|
|
430
|
+
sequence: history.entries.length + 1,
|
|
431
|
+
amended_at: new Date().toISOString(),
|
|
432
|
+
authorized_by: authorizedBy,
|
|
433
|
+
reason,
|
|
434
|
+
previous_contract_sha256: previousContractSha256,
|
|
435
|
+
new_contract_sha256: newContractSha256,
|
|
436
|
+
...(allowedMerge.added.length > 0 ? { added_allowed_paths: allowedMerge.added } : {}),
|
|
437
|
+
...(readOnlyMerge.added.length > 0 ? { added_read_only_paths: readOnlyMerge.added } : {}),
|
|
438
|
+
...(forbiddenMerge.added.length > 0 ? { added_forbidden_paths: forbiddenMerge.added } : {}),
|
|
439
|
+
...(startingShaChanged
|
|
440
|
+
? {
|
|
441
|
+
previous_starting_sha: contract.starting_sha,
|
|
442
|
+
new_starting_sha: updatedContract.starting_sha
|
|
443
|
+
}
|
|
444
|
+
: {})
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
const entrySha256 = canonicalSha256(AMENDMENT_HASH_DOMAIN, entryBody);
|
|
448
|
+
const entry = {
|
|
449
|
+
...entryBody,
|
|
450
|
+
entry_sha256: entrySha256
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
const pactDir = path.dirname(contractAbs);
|
|
454
|
+
fs.writeFileSync(contractAbs, JSON.stringify(updatedContract, null, 2) + '\n', 'utf8');
|
|
455
|
+
|
|
456
|
+
const receiptPath = path.join(pactDir, 'receipt.json');
|
|
457
|
+
if (fs.existsSync(receiptPath)) {
|
|
458
|
+
fs.rmSync(receiptPath, { force: true });
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const amendmentsPath = path.join(pactDir, 'amendments.jsonl');
|
|
462
|
+
fs.appendFileSync(amendmentsPath, JSON.stringify(entry) + '\n', 'utf8');
|
|
463
|
+
|
|
464
|
+
return {
|
|
465
|
+
exitCode: EXIT_PASS,
|
|
466
|
+
contractSha256: newContractSha256,
|
|
467
|
+
entry,
|
|
468
|
+
amendmentCount: history.entries.length + 1
|
|
469
|
+
};
|
|
470
|
+
}
|