ushman-ledger 0.3.0 → 1.2.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/AGENTS.md +11 -7
- package/CHANGELOG.md +8 -12
- package/README.md +28 -57
- package/dist/archive-journal.d.ts +29 -18
- package/dist/archive-journal.d.ts.map +1 -1
- package/dist/archive-journal.js +17 -17
- package/dist/blobs.js +3 -3
- package/dist/builders.d.ts +79 -358
- package/dist/builders.d.ts.map +1 -1
- package/dist/builders.js +15 -60
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +227 -52
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +104 -4
- package/dist/handle.d.ts +4 -2
- package/dist/handle.d.ts.map +1 -1
- package/dist/handle.js +20 -15
- package/dist/helpers.d.ts +7 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +38 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/lab-min.d.ts +7 -7
- package/dist/lab-min.d.ts.map +1 -1
- package/dist/lab-min.js +7 -9
- package/dist/list.d.ts +104 -303
- package/dist/list.d.ts.map +1 -1
- package/dist/note.d.ts +20 -0
- package/dist/note.d.ts.map +1 -1
- package/dist/note.js +5 -0
- package/dist/patch-resolver.d.ts +27 -0
- package/dist/patch-resolver.d.ts.map +1 -0
- package/dist/patch-resolver.js +184 -0
- package/dist/read-index.d.ts +45 -57
- package/dist/read-index.d.ts.map +1 -1
- package/dist/read-index.js +16 -34
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +19 -130
- package/dist/recovery.d.ts +19 -8
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +13 -13
- package/dist/render/migration-log.d.ts +3 -0
- package/dist/render/migration-log.d.ts.map +1 -0
- package/dist/render/migration-log.js +72 -0
- package/dist/render/retro.d.ts.map +1 -1
- package/dist/render/retro.js +41 -25
- package/dist/render/workspace-narrative.d.ts +6 -0
- package/dist/render/workspace-narrative.d.ts.map +1 -0
- package/dist/render/workspace-narrative.js +69 -0
- package/dist/schema/entry-core.d.ts +110 -0
- package/dist/schema/entry-core.d.ts.map +1 -0
- package/dist/schema/entry-core.js +143 -0
- package/dist/schema/entry-migrations.d.ts +3 -0
- package/dist/schema/entry-migrations.d.ts.map +1 -0
- package/dist/schema/entry-migrations.js +48 -0
- package/dist/schema/entry-read.d.ts +694 -0
- package/dist/schema/entry-read.d.ts.map +1 -0
- package/dist/schema/entry-read.js +92 -0
- package/dist/schema/entry-write.d.ts +865 -0
- package/dist/schema/entry-write.d.ts.map +1 -0
- package/dist/schema/entry-write.js +105 -0
- package/dist/schema/entry.d.ts +6 -3295
- package/dist/schema/entry.d.ts.map +1 -1
- package/dist/schema/entry.js +10 -619
- package/dist/schema/manifest.d.ts +28 -41
- package/dist/schema/manifest.d.ts.map +1 -1
- package/dist/schema/manifest.js +20 -24
- package/dist/schema/note.d.ts +3 -9
- package/dist/schema/note.d.ts.map +1 -1
- package/dist/schema/note.js +13 -2
- package/dist/storage/filesystem.d.ts +2 -1
- package/dist/storage/filesystem.d.ts.map +1 -1
- package/dist/storage/filesystem.js +6 -4
- package/dist/storage/lock-reclaimer.d.ts +2 -0
- package/dist/storage/lock-reclaimer.d.ts.map +1 -0
- package/dist/storage/lock-reclaimer.js +45 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/schema/entry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/schema/entry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,kBAAkB,CAAC;AAEzE,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AAEjC,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,WAAyE,CAAC;AAE5H,eAAO,MAAM,iBAAiB,GAAI,OAAO,OAAO,KAAG,YACa,CAAC"}
|
package/dist/schema/entry.js
CHANGED
|
@@ -1,619 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'cleanup',
|
|
12
|
-
'parity',
|
|
13
|
-
'characterize',
|
|
14
|
-
'equiv',
|
|
15
|
-
'analyze',
|
|
16
|
-
'recover',
|
|
17
|
-
'ship',
|
|
18
|
-
'migration',
|
|
19
|
-
];
|
|
20
|
-
export const LEDGER_KINDS = [
|
|
21
|
-
'tool-invocation',
|
|
22
|
-
'agent-patch',
|
|
23
|
-
'operator-patch',
|
|
24
|
-
'stage-transition',
|
|
25
|
-
'operator-decision',
|
|
26
|
-
'validator-result',
|
|
27
|
-
'runtime-event',
|
|
28
|
-
'note',
|
|
29
|
-
'correction',
|
|
30
|
-
'strip-decision-reverted',
|
|
31
|
-
'descope-brief',
|
|
32
|
-
'merge-return',
|
|
33
|
-
'merge-return-rejected',
|
|
34
|
-
'revert',
|
|
35
|
-
'rollback',
|
|
36
|
-
'rework.test_retired',
|
|
37
|
-
];
|
|
38
|
-
export const STAGE_TRANSITION_STAGES = [
|
|
39
|
-
'intake',
|
|
40
|
-
'seed',
|
|
41
|
-
'vendor-extract',
|
|
42
|
-
'cleanup',
|
|
43
|
-
'parity',
|
|
44
|
-
'characterize',
|
|
45
|
-
];
|
|
46
|
-
export const OPERATOR_DECISION_ACTIONS = [
|
|
47
|
-
'bypass-doctor',
|
|
48
|
-
'skip-check',
|
|
49
|
-
'override-strip-decision',
|
|
50
|
-
'override-ship-state',
|
|
51
|
-
'manual-parity-assertion',
|
|
52
|
-
'ledger-hand-edit',
|
|
53
|
-
'escalation',
|
|
54
|
-
];
|
|
55
|
-
const SHA256_HEX_PATTERN = /^[a-f0-9]{64}$/u;
|
|
56
|
-
const WINDOWS_ABSOLUTE_PATH_PATTERN = /^[a-z]:[\\/]/iu;
|
|
57
|
-
const normalizeWorkspaceRelativePath = (value) => value.replaceAll('\\', '/');
|
|
58
|
-
const mergeAffectedFiles = (left, right) => [
|
|
59
|
-
...new Set([...(left ?? []), ...right]),
|
|
60
|
-
];
|
|
61
|
-
const WorkspaceRelativePathSchema = z
|
|
62
|
-
.string()
|
|
63
|
-
.min(1)
|
|
64
|
-
.refine((value) => {
|
|
65
|
-
const normalized = normalizeWorkspaceRelativePath(value);
|
|
66
|
-
if (normalized.startsWith('/') || WINDOWS_ABSOLUTE_PATH_PATTERN.test(value)) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
if (normalized.startsWith('./') ||
|
|
70
|
-
normalized.endsWith('/') ||
|
|
71
|
-
normalized.includes('//') ||
|
|
72
|
-
normalized === '.' ||
|
|
73
|
-
normalized === '..') {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
if (path.posix.normalize(normalized) !== normalized) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
return !normalized.split('/').includes('..');
|
|
80
|
-
}, 'Expected a normalized workspace-relative path.');
|
|
81
|
-
const SHA256HexSchema = z.string().regex(SHA256_HEX_PATTERN, 'Expected a lowercase SHA-256 hex digest.');
|
|
82
|
-
const UuidV7Schema = z.string().refine(isUuidV7, 'Expected a UUIDv7 value.');
|
|
83
|
-
const LegacyOperatorDecisionTypeSchema = z.enum([
|
|
84
|
-
'strip-decision',
|
|
85
|
-
'strip-decision-revised',
|
|
86
|
-
'vendor-boundary',
|
|
87
|
-
'intent-exclusion',
|
|
88
|
-
'other',
|
|
89
|
-
]);
|
|
90
|
-
export const mapLegacyDecisionTypeToAction = (decisionType) => {
|
|
91
|
-
switch (decisionType) {
|
|
92
|
-
case 'strip-decision':
|
|
93
|
-
case 'strip-decision-revised':
|
|
94
|
-
return 'override-strip-decision';
|
|
95
|
-
default:
|
|
96
|
-
return 'escalation';
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const makeDigestRecordSchema = () => z.record(z.string().min(1), SHA256HexSchema);
|
|
100
|
-
const validatePatchPayload = ({ ctx, payload, }) => {
|
|
101
|
-
const touchedPaths = payload.touchedPaths ?? [];
|
|
102
|
-
const beforeMap = payload.fileSha256Before ?? {};
|
|
103
|
-
const afterMap = payload.fileSha256After ?? {};
|
|
104
|
-
if (touchedPaths.length === 0) {
|
|
105
|
-
ctx.addIssue({
|
|
106
|
-
code: 'custom',
|
|
107
|
-
message: 'payload.touchedPaths must contain at least one path',
|
|
108
|
-
path: ['payload', 'touchedPaths'],
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
for (const touchedPath of touchedPaths) {
|
|
112
|
-
if (!(touchedPath in beforeMap)) {
|
|
113
|
-
ctx.addIssue({
|
|
114
|
-
code: 'custom',
|
|
115
|
-
message: `payload.fileSha256Before is missing ${touchedPath}`,
|
|
116
|
-
path: ['payload', 'fileSha256Before', touchedPath],
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
if (!(touchedPath in afterMap)) {
|
|
120
|
-
ctx.addIssue({
|
|
121
|
-
code: 'custom',
|
|
122
|
-
message: `payload.fileSha256After is missing ${touchedPath}`,
|
|
123
|
-
path: ['payload', 'fileSha256After', touchedPath],
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
for (const hunk of payload.hunks ?? []) {
|
|
128
|
-
if (!touchedPaths.includes(hunk.path)) {
|
|
129
|
-
ctx.addIssue({
|
|
130
|
-
code: 'custom',
|
|
131
|
-
message: `payload.hunks path ${hunk.path} must appear in payload.touchedPaths`,
|
|
132
|
-
path: ['payload', 'hunks'],
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
export const LedgerPhaseSchema = z.enum(LEDGER_PHASES);
|
|
138
|
-
export const StageTransitionStageSchema = z.enum(STAGE_TRANSITION_STAGES);
|
|
139
|
-
export const OperatorDecisionActionSchema = z.enum(OPERATOR_DECISION_ACTIONS);
|
|
140
|
-
export const EmitterSchema = z.object({
|
|
141
|
-
tool: z.string().min(1),
|
|
142
|
-
user: z.string().min(1).optional(),
|
|
143
|
-
version: z.string().min(1),
|
|
144
|
-
});
|
|
145
|
-
export const LedgerLinksSchema = z
|
|
146
|
-
.object({
|
|
147
|
-
affectedFiles: z.array(WorkspaceRelativePathSchema).optional(),
|
|
148
|
-
blobs: z.array(z.string()).optional(),
|
|
149
|
-
briefId: z.string().optional(),
|
|
150
|
-
correctsLedgerId: z.string().optional(),
|
|
151
|
-
gitRef: z.string().optional(),
|
|
152
|
-
idempotencyKey: z.string().optional(),
|
|
153
|
-
stripDecisionId: z.string().optional(),
|
|
154
|
-
supersedesLedgerId: z.string().optional(),
|
|
155
|
-
validatorVerdictId: z.string().optional(),
|
|
156
|
-
})
|
|
157
|
-
.catchall(z.unknown());
|
|
158
|
-
const LedgerEntryBaseSchema = z.object({
|
|
159
|
-
_legacy: z.literal(true).optional(),
|
|
160
|
-
details: z.record(z.string(), z.unknown()).optional(),
|
|
161
|
-
emitter: EmitterSchema,
|
|
162
|
-
id: z.string().min(1),
|
|
163
|
-
kind: z.string().min(1),
|
|
164
|
-
links: LedgerLinksSchema.default({}),
|
|
165
|
-
phase: LedgerPhaseSchema,
|
|
166
|
-
prevEntryId: z.string().min(1).nullable(),
|
|
167
|
-
schemaVersion: z.literal(LedgerSchemaVersion),
|
|
168
|
-
summary: z.string().min(1),
|
|
169
|
-
ts: z.string().datetime({ offset: true }),
|
|
170
|
-
});
|
|
171
|
-
export const PatchHunkSchema = z
|
|
172
|
-
.object({
|
|
173
|
-
endLine: z.number().int().positive(),
|
|
174
|
-
path: WorkspaceRelativePathSchema,
|
|
175
|
-
startLine: z.number().int().positive(),
|
|
176
|
-
})
|
|
177
|
-
.refine((value) => value.endLine >= value.startLine, {
|
|
178
|
-
message: 'payload.hunks endLine must be greater than or equal to startLine',
|
|
179
|
-
path: ['endLine'],
|
|
180
|
-
});
|
|
181
|
-
export const PatchPayloadSchema = z.object({
|
|
182
|
-
diff: z.string().min(1).optional(),
|
|
183
|
-
diffSha256: SHA256HexSchema,
|
|
184
|
-
fileSha256After: makeDigestRecordSchema().default({}),
|
|
185
|
-
fileSha256Before: makeDigestRecordSchema().default({}),
|
|
186
|
-
hunks: z.array(PatchHunkSchema).default([]),
|
|
187
|
-
touchedPaths: z.array(WorkspaceRelativePathSchema).default([]),
|
|
188
|
-
});
|
|
189
|
-
export const PatchPayloadWriteSchema = PatchPayloadSchema.superRefine((value, ctx) => {
|
|
190
|
-
validatePatchPayload({
|
|
191
|
-
ctx,
|
|
192
|
-
payload: value,
|
|
193
|
-
});
|
|
194
|
-
if (!value.diff) {
|
|
195
|
-
ctx.addIssue({
|
|
196
|
-
code: 'custom',
|
|
197
|
-
message: 'payload.diff is required for new patch records',
|
|
198
|
-
path: ['diff'],
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
export const OperatorDecisionPayloadSchema = z.object({
|
|
203
|
-
action: OperatorDecisionActionSchema,
|
|
204
|
-
checkId: z.string().min(1).optional(),
|
|
205
|
-
rationale: z.string().trim().min(1, 'payload.rationale must not be empty'),
|
|
206
|
-
});
|
|
207
|
-
export const ValidatorResultPayloadSchema = z.object({
|
|
208
|
-
id: UuidV7Schema,
|
|
209
|
-
});
|
|
210
|
-
export const CorrectionPayloadSchema = z.object({
|
|
211
|
-
correctsValidatorResultId: UuidV7Schema.optional(),
|
|
212
|
-
});
|
|
213
|
-
export const StageTransitionPayloadSchema = z.object({
|
|
214
|
-
doctorBaselineId: z.string().min(1).optional(),
|
|
215
|
-
endedAt: z.string().datetime({ offset: true }),
|
|
216
|
-
exitCode: z.number().int(),
|
|
217
|
-
stage: StageTransitionStageSchema,
|
|
218
|
-
startedAt: z.string().datetime({ offset: true }),
|
|
219
|
-
});
|
|
220
|
-
export const StripDecisionRevertedPayloadSchema = z.object({
|
|
221
|
-
invalidatedStages: z.array(StageTransitionStageSchema).optional(),
|
|
222
|
-
rationale: z.string().trim().min(1),
|
|
223
|
-
stripDecisionId: z.string().min(1),
|
|
224
|
-
});
|
|
225
|
-
export const DescopeBriefPayloadSchema = z.object({
|
|
226
|
-
briefId: z.string().min(1),
|
|
227
|
-
reason: z.string().trim().min(1).optional(),
|
|
228
|
-
round: z.number().int().positive().optional(),
|
|
229
|
-
stripDecisionIds: z.array(z.string().min(1)).optional(),
|
|
230
|
-
});
|
|
231
|
-
export const MergeReturnPayloadSchema = z.object({
|
|
232
|
-
briefId: z.string().min(1).optional(),
|
|
233
|
-
returnId: z.string().min(1),
|
|
234
|
-
source: z.string().min(1).optional(),
|
|
235
|
-
});
|
|
236
|
-
export const MergeReturnRejectedPayloadSchema = MergeReturnPayloadSchema.extend({
|
|
237
|
-
reason: z.string().trim().min(1),
|
|
238
|
-
});
|
|
239
|
-
export const RevertPayloadSchema = z.object({
|
|
240
|
-
reason: z.string().trim().min(1),
|
|
241
|
-
targetEntryId: z.string().min(1).optional(),
|
|
242
|
-
});
|
|
243
|
-
export const RollbackPayloadSchema = RevertPayloadSchema.extend({
|
|
244
|
-
targetStage: StageTransitionStageSchema.optional(),
|
|
245
|
-
});
|
|
246
|
-
export const ReworkTestRetiredPayloadSchema = z.object({
|
|
247
|
-
briefId: z.string().min(1).optional(),
|
|
248
|
-
removedBy: z.enum(['descope', 'decompose', 'operator']),
|
|
249
|
-
removedTestPath: WorkspaceRelativePathSchema,
|
|
250
|
-
removedTestSymbols: z.array(z.string().min(1)),
|
|
251
|
-
sourceSymbolDeletedFrom: WorkspaceRelativePathSchema,
|
|
252
|
-
});
|
|
253
|
-
export const ToolInvocationEntrySchema = LedgerEntryBaseSchema.extend({
|
|
254
|
-
args: z.array(z.string()).optional(),
|
|
255
|
-
cwd: z.string().optional(),
|
|
256
|
-
exitCode: z.number().int().optional(),
|
|
257
|
-
kind: z.literal('tool-invocation'),
|
|
258
|
-
});
|
|
259
|
-
export const AgentPatchDiffSchema = z.object({
|
|
260
|
-
addedLines: z.number().int().nonnegative(),
|
|
261
|
-
blobSha256: SHA256HexSchema,
|
|
262
|
-
bytes: z.number().int().nonnegative(),
|
|
263
|
-
removedLines: z.number().int().nonnegative(),
|
|
264
|
-
});
|
|
265
|
-
const PatchEntryBaseSchema = LedgerEntryBaseSchema.extend({
|
|
266
|
-
diff: AgentPatchDiffSchema,
|
|
267
|
-
payload: PatchPayloadSchema,
|
|
268
|
-
rationale: z.string().min(1),
|
|
269
|
-
}).superRefine((value, ctx) => {
|
|
270
|
-
if (value.payload.diffSha256 !== value.diff.blobSha256) {
|
|
271
|
-
ctx.addIssue({
|
|
272
|
-
code: 'custom',
|
|
273
|
-
message: 'payload.diffSha256 must match diff.blobSha256',
|
|
274
|
-
path: ['payload', 'diffSha256'],
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
validatePatchPayload({
|
|
278
|
-
ctx,
|
|
279
|
-
payload: value.payload,
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
export const AgentPatchEntrySchema = PatchEntryBaseSchema.safeExtend({
|
|
283
|
-
agent: z.object({
|
|
284
|
-
name: z.string().min(1),
|
|
285
|
-
sessionId: z.string().min(1).optional(),
|
|
286
|
-
}),
|
|
287
|
-
kind: z.literal('agent-patch'),
|
|
288
|
-
});
|
|
289
|
-
export const OperatorPatchEntrySchema = PatchEntryBaseSchema.safeExtend({
|
|
290
|
-
kind: z.literal('operator-patch'),
|
|
291
|
-
operator: z.object({
|
|
292
|
-
name: z.string().min(1),
|
|
293
|
-
}),
|
|
294
|
-
});
|
|
295
|
-
export const StageTransitionEntrySchema = LedgerEntryBaseSchema.extend({
|
|
296
|
-
kind: z.literal('stage-transition'),
|
|
297
|
-
payload: StageTransitionPayloadSchema,
|
|
298
|
-
});
|
|
299
|
-
export const OperatorDecisionEntrySchema = LedgerEntryBaseSchema.extend({
|
|
300
|
-
body: z.record(z.string(), z.unknown()).optional(),
|
|
301
|
-
decisionType: LegacyOperatorDecisionTypeSchema.optional(),
|
|
302
|
-
kind: z.literal('operator-decision'),
|
|
303
|
-
payload: OperatorDecisionPayloadSchema,
|
|
304
|
-
});
|
|
305
|
-
export const ValidatorResultEntrySchema = LedgerEntryBaseSchema.extend({
|
|
306
|
-
kind: z.literal('validator-result'),
|
|
307
|
-
metrics: z.record(z.string(), z.unknown()).optional(),
|
|
308
|
-
payload: ValidatorResultPayloadSchema,
|
|
309
|
-
resultPath: z.string().optional(),
|
|
310
|
-
validator: z.enum(['parity', 'equiv', 'characterize', 'verify', 'doctor']),
|
|
311
|
-
verdict: z.enum(['green', 'yellow', 'red']),
|
|
312
|
-
});
|
|
313
|
-
export const RuntimeEventEntrySchema = LedgerEntryBaseSchema.extend({
|
|
314
|
-
kind: z.literal('runtime-event'),
|
|
315
|
-
level: z.enum(['info', 'warn', 'error']),
|
|
316
|
-
message: z.string().min(1),
|
|
317
|
-
source: z.string().min(1),
|
|
318
|
-
stripDecisionId: z.string().optional(),
|
|
319
|
-
});
|
|
320
|
-
export const NoteEntrySchema = LedgerEntryBaseSchema.extend({
|
|
321
|
-
body: z.string(),
|
|
322
|
-
kind: z.literal('note'),
|
|
323
|
-
subkind: NoteSubkindSchema,
|
|
324
|
-
});
|
|
325
|
-
export const CorrectionEntrySchema = LedgerEntryBaseSchema.extend({
|
|
326
|
-
kind: z.literal('correction'),
|
|
327
|
-
payload: CorrectionPayloadSchema.default({}),
|
|
328
|
-
rationale: z.string().min(1),
|
|
329
|
-
}).superRefine((value, ctx) => {
|
|
330
|
-
if (!value.links?.correctsLedgerId) {
|
|
331
|
-
ctx.addIssue({
|
|
332
|
-
code: 'custom',
|
|
333
|
-
message: 'correction entries require links.correctsLedgerId',
|
|
334
|
-
path: ['links', 'correctsLedgerId'],
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
export const StripDecisionRevertedEntrySchema = LedgerEntryBaseSchema.extend({
|
|
339
|
-
kind: z.literal('strip-decision-reverted'),
|
|
340
|
-
payload: StripDecisionRevertedPayloadSchema,
|
|
341
|
-
});
|
|
342
|
-
export const DescopeBriefEntrySchema = LedgerEntryBaseSchema.extend({
|
|
343
|
-
kind: z.literal('descope-brief'),
|
|
344
|
-
payload: DescopeBriefPayloadSchema,
|
|
345
|
-
});
|
|
346
|
-
export const MergeReturnEntrySchema = LedgerEntryBaseSchema.extend({
|
|
347
|
-
kind: z.literal('merge-return'),
|
|
348
|
-
payload: MergeReturnPayloadSchema,
|
|
349
|
-
});
|
|
350
|
-
export const MergeReturnRejectedEntrySchema = LedgerEntryBaseSchema.extend({
|
|
351
|
-
kind: z.literal('merge-return-rejected'),
|
|
352
|
-
payload: MergeReturnRejectedPayloadSchema,
|
|
353
|
-
});
|
|
354
|
-
export const RevertEntrySchema = LedgerEntryBaseSchema.extend({
|
|
355
|
-
kind: z.literal('revert'),
|
|
356
|
-
payload: RevertPayloadSchema,
|
|
357
|
-
});
|
|
358
|
-
export const RollbackEntrySchema = LedgerEntryBaseSchema.extend({
|
|
359
|
-
kind: z.literal('rollback'),
|
|
360
|
-
payload: RollbackPayloadSchema,
|
|
361
|
-
});
|
|
362
|
-
export const ReworkTestRetiredEntrySchema = LedgerEntryBaseSchema.extend({
|
|
363
|
-
kind: z.literal('rework.test_retired'),
|
|
364
|
-
payload: ReworkTestRetiredPayloadSchema,
|
|
365
|
-
});
|
|
366
|
-
export const LedgerEntrySchema = z.discriminatedUnion('kind', [
|
|
367
|
-
ToolInvocationEntrySchema,
|
|
368
|
-
AgentPatchEntrySchema,
|
|
369
|
-
OperatorPatchEntrySchema,
|
|
370
|
-
StageTransitionEntrySchema,
|
|
371
|
-
OperatorDecisionEntrySchema,
|
|
372
|
-
ValidatorResultEntrySchema,
|
|
373
|
-
RuntimeEventEntrySchema,
|
|
374
|
-
NoteEntrySchema,
|
|
375
|
-
CorrectionEntrySchema,
|
|
376
|
-
StripDecisionRevertedEntrySchema,
|
|
377
|
-
DescopeBriefEntrySchema,
|
|
378
|
-
MergeReturnEntrySchema,
|
|
379
|
-
MergeReturnRejectedEntrySchema,
|
|
380
|
-
RevertEntrySchema,
|
|
381
|
-
RollbackEntrySchema,
|
|
382
|
-
ReworkTestRetiredEntrySchema,
|
|
383
|
-
]);
|
|
384
|
-
const LegacyAgentPatchEntrySchema = LedgerEntryBaseSchema.extend({
|
|
385
|
-
agent: z.object({
|
|
386
|
-
name: z.string().min(1),
|
|
387
|
-
sessionId: z.string().min(1).optional(),
|
|
388
|
-
}),
|
|
389
|
-
diff: AgentPatchDiffSchema,
|
|
390
|
-
kind: z.literal('agent-patch'),
|
|
391
|
-
rationale: z.string().min(1),
|
|
392
|
-
});
|
|
393
|
-
const LegacyOperatorDecisionEntrySchema = LedgerEntryBaseSchema.extend({
|
|
394
|
-
body: z.record(z.string(), z.unknown()),
|
|
395
|
-
decisionType: LegacyOperatorDecisionTypeSchema,
|
|
396
|
-
kind: z.literal('operator-decision'),
|
|
397
|
-
});
|
|
398
|
-
const LegacyValidatorResultEntrySchema = LedgerEntryBaseSchema.extend({
|
|
399
|
-
kind: z.literal('validator-result'),
|
|
400
|
-
metrics: z.record(z.string(), z.unknown()).optional(),
|
|
401
|
-
resultPath: z.string().optional(),
|
|
402
|
-
validator: z.enum(['parity', 'equiv', 'characterize', 'verify', 'doctor']),
|
|
403
|
-
verdict: z.enum(['green', 'yellow', 'red']),
|
|
404
|
-
});
|
|
405
|
-
const RecordEntryBaseSchema = z.object({
|
|
406
|
-
details: z.record(z.string(), z.unknown()).optional(),
|
|
407
|
-
emitter: EmitterSchema,
|
|
408
|
-
idempotencyKey: z.string().min(1).optional(),
|
|
409
|
-
links: LedgerLinksSchema.optional(),
|
|
410
|
-
phase: LedgerPhaseSchema,
|
|
411
|
-
summary: z.string().min(1),
|
|
412
|
-
});
|
|
413
|
-
export const ToolInvocationRecordSchema = RecordEntryBaseSchema.extend({
|
|
414
|
-
args: z.array(z.string()).optional(),
|
|
415
|
-
cwd: z.string().optional(),
|
|
416
|
-
exitCode: z.number().int().optional(),
|
|
417
|
-
kind: z.literal('tool-invocation'),
|
|
418
|
-
});
|
|
419
|
-
const PatchRecordPayloadInputSchema = z.object({
|
|
420
|
-
diff: z.string().min(1).optional(),
|
|
421
|
-
diffSha256: SHA256HexSchema.optional(),
|
|
422
|
-
fileSha256After: makeDigestRecordSchema().optional(),
|
|
423
|
-
fileSha256Before: makeDigestRecordSchema().optional(),
|
|
424
|
-
hunks: z.array(PatchHunkSchema).optional(),
|
|
425
|
-
touchedPaths: z.array(WorkspaceRelativePathSchema).min(1).optional(),
|
|
426
|
-
});
|
|
427
|
-
const PatchRecordBaseSchema = RecordEntryBaseSchema.extend({
|
|
428
|
-
diff: AgentPatchDiffSchema.optional(),
|
|
429
|
-
diffPath: z.string().min(1).optional(),
|
|
430
|
-
payload: PatchRecordPayloadInputSchema.optional(),
|
|
431
|
-
rationale: z.string().min(1),
|
|
432
|
-
}).superRefine((value, ctx) => {
|
|
433
|
-
if (!value.payload && !value.diff && !value.diffPath) {
|
|
434
|
-
ctx.addIssue({
|
|
435
|
-
code: 'custom',
|
|
436
|
-
message: 'patch records require payload, diff, or diffPath',
|
|
437
|
-
path: ['payload'],
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
if (value.diff && value.diffPath) {
|
|
441
|
-
ctx.addIssue({
|
|
442
|
-
code: 'custom',
|
|
443
|
-
message: 'patch records must provide either diff or diffPath, not both',
|
|
444
|
-
path: ['diffPath'],
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
export const AgentPatchRecordSchema = PatchRecordBaseSchema.safeExtend({
|
|
449
|
-
agent: z.object({
|
|
450
|
-
name: z.string().min(1),
|
|
451
|
-
sessionId: z.string().min(1).optional(),
|
|
452
|
-
}),
|
|
453
|
-
kind: z.literal('agent-patch'),
|
|
454
|
-
});
|
|
455
|
-
export const OperatorPatchRecordSchema = PatchRecordBaseSchema.safeExtend({
|
|
456
|
-
kind: z.literal('operator-patch'),
|
|
457
|
-
operator: z.object({
|
|
458
|
-
name: z.string().min(1),
|
|
459
|
-
}),
|
|
460
|
-
});
|
|
461
|
-
export const StageTransitionRecordSchema = RecordEntryBaseSchema.extend({
|
|
462
|
-
kind: z.literal('stage-transition'),
|
|
463
|
-
payload: StageTransitionPayloadSchema,
|
|
464
|
-
});
|
|
465
|
-
export const OperatorDecisionRecordSchema = RecordEntryBaseSchema.extend({
|
|
466
|
-
kind: z.literal('operator-decision'),
|
|
467
|
-
payload: OperatorDecisionPayloadSchema,
|
|
468
|
-
});
|
|
469
|
-
export const ValidatorResultRecordSchema = RecordEntryBaseSchema.extend({
|
|
470
|
-
kind: z.literal('validator-result'),
|
|
471
|
-
metrics: z.record(z.string(), z.unknown()).optional(),
|
|
472
|
-
payload: z
|
|
473
|
-
.object({
|
|
474
|
-
id: UuidV7Schema.optional(),
|
|
475
|
-
})
|
|
476
|
-
.optional(),
|
|
477
|
-
resultPath: z.string().optional(),
|
|
478
|
-
validator: z.enum(['parity', 'equiv', 'characterize', 'verify', 'doctor']),
|
|
479
|
-
verdict: z.enum(['green', 'yellow', 'red']),
|
|
480
|
-
});
|
|
481
|
-
export const RuntimeEventRecordSchema = RecordEntryBaseSchema.extend({
|
|
482
|
-
kind: z.literal('runtime-event'),
|
|
483
|
-
level: z.enum(['info', 'warn', 'error']),
|
|
484
|
-
message: z.string().min(1),
|
|
485
|
-
source: z.string().min(1),
|
|
486
|
-
stripDecisionId: z.string().optional(),
|
|
487
|
-
});
|
|
488
|
-
export const NoteRecordSchema = RecordEntryBaseSchema.extend({
|
|
489
|
-
body: z.string(),
|
|
490
|
-
kind: z.literal('note'),
|
|
491
|
-
subkind: NoteSubkindSchema,
|
|
492
|
-
});
|
|
493
|
-
export const CorrectionRecordSchema = RecordEntryBaseSchema.extend({
|
|
494
|
-
kind: z.literal('correction'),
|
|
495
|
-
payload: CorrectionPayloadSchema.optional(),
|
|
496
|
-
rationale: z.string().min(1),
|
|
497
|
-
}).superRefine((value, ctx) => {
|
|
498
|
-
if (!value.links?.correctsLedgerId) {
|
|
499
|
-
ctx.addIssue({
|
|
500
|
-
code: 'custom',
|
|
501
|
-
message: 'correction records require links.correctsLedgerId',
|
|
502
|
-
path: ['links', 'correctsLedgerId'],
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
export const StripDecisionRevertedRecordSchema = RecordEntryBaseSchema.extend({
|
|
507
|
-
kind: z.literal('strip-decision-reverted'),
|
|
508
|
-
payload: StripDecisionRevertedPayloadSchema,
|
|
509
|
-
});
|
|
510
|
-
export const DescopeBriefRecordSchema = RecordEntryBaseSchema.extend({
|
|
511
|
-
kind: z.literal('descope-brief'),
|
|
512
|
-
payload: DescopeBriefPayloadSchema,
|
|
513
|
-
});
|
|
514
|
-
export const MergeReturnRecordSchema = RecordEntryBaseSchema.extend({
|
|
515
|
-
kind: z.literal('merge-return'),
|
|
516
|
-
payload: MergeReturnPayloadSchema,
|
|
517
|
-
});
|
|
518
|
-
export const MergeReturnRejectedRecordSchema = RecordEntryBaseSchema.extend({
|
|
519
|
-
kind: z.literal('merge-return-rejected'),
|
|
520
|
-
payload: MergeReturnRejectedPayloadSchema,
|
|
521
|
-
});
|
|
522
|
-
export const RevertRecordSchema = RecordEntryBaseSchema.extend({
|
|
523
|
-
kind: z.literal('revert'),
|
|
524
|
-
payload: RevertPayloadSchema,
|
|
525
|
-
});
|
|
526
|
-
export const RollbackRecordSchema = RecordEntryBaseSchema.extend({
|
|
527
|
-
kind: z.literal('rollback'),
|
|
528
|
-
payload: RollbackPayloadSchema,
|
|
529
|
-
});
|
|
530
|
-
export const ReworkTestRetiredRecordSchema = RecordEntryBaseSchema.extend({
|
|
531
|
-
kind: z.literal('rework.test_retired'),
|
|
532
|
-
payload: ReworkTestRetiredPayloadSchema,
|
|
533
|
-
});
|
|
534
|
-
export const LedgerRecordSchema = z.discriminatedUnion('kind', [
|
|
535
|
-
ToolInvocationRecordSchema,
|
|
536
|
-
AgentPatchRecordSchema,
|
|
537
|
-
OperatorPatchRecordSchema,
|
|
538
|
-
StageTransitionRecordSchema,
|
|
539
|
-
OperatorDecisionRecordSchema,
|
|
540
|
-
ValidatorResultRecordSchema,
|
|
541
|
-
RuntimeEventRecordSchema,
|
|
542
|
-
NoteRecordSchema,
|
|
543
|
-
CorrectionRecordSchema,
|
|
544
|
-
StripDecisionRevertedRecordSchema,
|
|
545
|
-
DescopeBriefRecordSchema,
|
|
546
|
-
MergeReturnRecordSchema,
|
|
547
|
-
MergeReturnRejectedRecordSchema,
|
|
548
|
-
RevertRecordSchema,
|
|
549
|
-
RollbackRecordSchema,
|
|
550
|
-
ReworkTestRetiredRecordSchema,
|
|
551
|
-
]);
|
|
552
|
-
const normalizePatchEntry = (entry) => ({
|
|
553
|
-
...entry,
|
|
554
|
-
links: {
|
|
555
|
-
...entry.links,
|
|
556
|
-
affectedFiles: mergeAffectedFiles(entry.links.affectedFiles, entry.payload.touchedPaths),
|
|
557
|
-
},
|
|
558
|
-
});
|
|
559
|
-
const normalizeLegacyAgentPatchEntry = (entry) => normalizePatchEntry({
|
|
560
|
-
...entry,
|
|
561
|
-
_legacy: true,
|
|
562
|
-
payload: {
|
|
563
|
-
diffSha256: entry.diff.blobSha256,
|
|
564
|
-
fileSha256After: {},
|
|
565
|
-
fileSha256Before: {},
|
|
566
|
-
hunks: [],
|
|
567
|
-
touchedPaths: entry.links.affectedFiles ?? [],
|
|
568
|
-
},
|
|
569
|
-
});
|
|
570
|
-
const normalizeLegacyOperatorDecisionEntry = (entry) => ({
|
|
571
|
-
...entry,
|
|
572
|
-
_legacy: true,
|
|
573
|
-
payload: {
|
|
574
|
-
action: mapLegacyDecisionTypeToAction(entry.decisionType),
|
|
575
|
-
checkId: typeof entry.links.stripDecisionId === 'string' ? entry.links.stripDecisionId : undefined,
|
|
576
|
-
rationale: typeof entry.body.rationale === 'string' && entry.body.rationale.trim().length > 0
|
|
577
|
-
? entry.body.rationale
|
|
578
|
-
: entry.summary,
|
|
579
|
-
},
|
|
580
|
-
});
|
|
581
|
-
const normalizeLegacyValidatorResultEntry = (entry) => ({
|
|
582
|
-
...entry,
|
|
583
|
-
_legacy: true,
|
|
584
|
-
payload: {
|
|
585
|
-
id: createDeterministicUuidV7({
|
|
586
|
-
seed: `${entry.id}:${entry.summary}:${entry.validator}:${entry.verdict}`,
|
|
587
|
-
timestamp: entry.ts,
|
|
588
|
-
}),
|
|
589
|
-
},
|
|
590
|
-
});
|
|
591
|
-
const normalizeCurrentEntry = (entry) => {
|
|
592
|
-
switch (entry.kind) {
|
|
593
|
-
case 'agent-patch':
|
|
594
|
-
case 'operator-patch':
|
|
595
|
-
return normalizePatchEntry(entry);
|
|
596
|
-
default:
|
|
597
|
-
return entry;
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
export const parseLedgerEntry = (input) => {
|
|
601
|
-
const current = LedgerEntrySchema.safeParse(input);
|
|
602
|
-
if (current.success) {
|
|
603
|
-
return normalizeCurrentEntry(current.data);
|
|
604
|
-
}
|
|
605
|
-
const legacyAgentPatch = LegacyAgentPatchEntrySchema.safeParse(input);
|
|
606
|
-
if (legacyAgentPatch.success) {
|
|
607
|
-
return normalizeLegacyAgentPatchEntry(legacyAgentPatch.data);
|
|
608
|
-
}
|
|
609
|
-
const legacyOperatorDecision = LegacyOperatorDecisionEntrySchema.safeParse(input);
|
|
610
|
-
if (legacyOperatorDecision.success) {
|
|
611
|
-
return normalizeLegacyOperatorDecisionEntry(legacyOperatorDecision.data);
|
|
612
|
-
}
|
|
613
|
-
const legacyValidatorResult = LegacyValidatorResultEntrySchema.safeParse(input);
|
|
614
|
-
if (legacyValidatorResult.success) {
|
|
615
|
-
return normalizeLegacyValidatorResultEntry(legacyValidatorResult.data);
|
|
616
|
-
}
|
|
617
|
-
return LedgerEntrySchema.parse(input);
|
|
618
|
-
};
|
|
619
|
-
export const parseLedgerRecord = (input) => LedgerRecordSchema.parse(input);
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { migrateLedgerEntryInput, migrateLedgerRecordInput } from "./entry-migrations.js";
|
|
3
|
+
import { LedgerEntrySchema } from "./entry-read.js";
|
|
4
|
+
import { LedgerRecordSchema } from "./entry-write.js";
|
|
5
|
+
export * from "./entry-core.js";
|
|
6
|
+
export * from "./entry-migrations.js";
|
|
7
|
+
export * from "./entry-read.js";
|
|
8
|
+
export * from "./entry-write.js";
|
|
9
|
+
export const parseLedgerEntry = (input) => v.parse(LedgerEntrySchema, migrateLedgerEntryInput(input));
|
|
10
|
+
export const parseLedgerRecord = (input) => v.parse(LedgerRecordSchema, migrateLedgerRecordInput(input));
|