@skill-harness/adapters 0.12.0 → 0.14.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/dist/archive-access.d.ts +58 -0
- package/dist/archive-access.js +61 -0
- package/dist/archive-checkpoint.d.ts +47 -0
- package/dist/archive-checkpoint.js +116 -0
- package/dist/archive-facts.d.ts +19 -0
- package/dist/archive-facts.js +20 -0
- package/dist/archive-observer.d.ts +21 -0
- package/dist/archive-observer.js +79 -0
- package/dist/archive-policy.d.ts +107 -0
- package/dist/archive-policy.js +135 -0
- package/dist/archive-read-capability.d.ts +49 -0
- package/dist/archive-read-capability.js +45 -0
- package/dist/archive-retention-policy.d.ts +52 -0
- package/dist/archive-retention-policy.js +49 -0
- package/dist/archived-work.d.ts +44 -0
- package/dist/archived-work.js +64 -0
- package/dist/blind-intervention.d.ts +29 -0
- package/dist/blind-intervention.js +211 -0
- package/dist/codex-diagnostic-model.d.ts +14 -0
- package/dist/codex-diagnostic-model.js +39 -0
- package/dist/codex-host-observer.d.ts +111 -0
- package/dist/codex-host-observer.js +309 -0
- package/dist/codex-https.d.ts +7 -0
- package/dist/codex-https.js +221 -0
- package/dist/codex-model-profile.d.ts +38 -0
- package/dist/codex-model-profile.js +54 -0
- package/dist/codex-producer-ipc.d.ts +55 -0
- package/dist/codex-producer-ipc.js +67 -0
- package/dist/codex-sdk-transport.d.ts +50 -0
- package/dist/codex-sdk-transport.js +294 -0
- package/dist/codex-subscription.d.ts +114 -0
- package/dist/codex-subscription.js +268 -0
- package/dist/evidence-archive.d.ts +57 -0
- package/dist/evidence-archive.js +221 -0
- package/dist/execution-projection-schema.d.ts +10 -0
- package/dist/execution-projection-schema.js +30 -0
- package/dist/execution-retention-archive.d.ts +69 -0
- package/dist/execution-retention-archive.js +154 -0
- package/dist/generated/retention-v2-contract.d.ts +72 -0
- package/dist/generated/retention-v2-contract.js +105 -0
- package/dist/generated/retention-v2-json.d.ts +24 -0
- package/dist/generated/retention-v2-json.js +268 -0
- package/dist/generated/retention-v2-native-json.d.ts +2 -0
- package/dist/generated/retention-v2-native-json.js +33 -0
- package/dist/generated/retention-v2-native.d.ts +58 -0
- package/dist/generated/retention-v2-native.js +155 -0
- package/dist/generated/retention-v2-pin.d.ts +2 -0
- package/dist/generated/retention-v2-pin.js +4 -0
- package/dist/generated/retention-v2-types.d.ts +49 -0
- package/dist/generated/retention-v2-types.js +2 -0
- package/dist/generated/retention-v2-work-types.d.ts +260 -0
- package/dist/generated/retention-v2-work-types.js +13 -0
- package/dist/generated/work-v4/execution-id.d.ts +5 -0
- package/dist/generated/work-v4/execution-id.js +14 -0
- package/dist/generated/work-v4/json.d.ts +24 -0
- package/dist/generated/work-v4/json.js +268 -0
- package/dist/generated/work-v4/occurrences.d.ts +226 -0
- package/dist/generated/work-v4/occurrences.js +116 -0
- package/dist/generated/work-v4/pin.d.ts +1 -0
- package/dist/generated/work-v4/pin.js +3 -0
- package/dist/generated/work-v4/projection.d.ts +294 -0
- package/dist/generated/work-v4/projection.js +238 -0
- package/dist/generated/work-v4/reader.d.ts +24 -0
- package/dist/generated/work-v4/reader.js +109 -0
- package/dist/generated/work-v4/snapshot.d.ts +28 -0
- package/dist/generated/work-v4/snapshot.js +268 -0
- package/dist/generated/work-v4/types.d.ts +260 -0
- package/dist/generated/work-v4/types.js +13 -0
- package/dist/generated/work-v4/validation.d.ts +13 -0
- package/dist/generated/work-v4/validation.js +227 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/installed-review-session.d.ts +28 -0
- package/dist/installed-review-session.js +166 -0
- package/dist/intervention-run.d.ts +403 -0
- package/dist/intervention-run.js +169 -0
- package/dist/learning-case.d.ts +12 -0
- package/dist/learning-case.js +15 -0
- package/dist/learning-journal.d.ts +18 -0
- package/dist/learning-journal.js +256 -0
- package/dist/principal-payload-port.d.ts +25 -0
- package/dist/principal-payload-port.js +40 -0
- package/dist/producer-product.d.ts +70 -0
- package/dist/producer-product.js +186 -0
- package/dist/producer-review.d.ts +53 -0
- package/dist/producer-review.js +207 -0
- package/dist/reviewed-archive-export.d.ts +42 -0
- package/dist/reviewed-archive-export.js +78 -0
- package/dist/trust-lifecycle.d.ts +128 -0
- package/dist/trust-lifecycle.js +200 -0
- package/dist/weekly-investigation.d.ts +237 -0
- package/dist/weekly-investigation.js +330 -0
- package/dist/work-candidates.d.ts +29 -0
- package/dist/work-candidates.js +78 -0
- package/dist/work-case-archive.d.ts +25 -0
- package/dist/work-case-archive.js +63 -0
- package/dist/work-case-review.d.ts +45 -0
- package/dist/work-case-review.js +220 -0
- package/dist/work-signal-cases.d.ts +15 -0
- package/dist/work-signal-cases.js +54 -0
- package/dist/work-signal-observation.d.ts +23 -0
- package/dist/work-signal-observation.js +89 -0
- package/package.json +3 -2
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/** Opt-in work-v4 wire identities; none of these declarations grants authority. */
|
|
2
|
+
export type WorkFrozen<T> = T extends ReadonlyArray<infer E> ? ReadonlyArray<WorkFrozen<E>> : T extends object ? {
|
|
3
|
+
readonly [K in keyof T]: WorkFrozen<T[K]>;
|
|
4
|
+
} : T;
|
|
5
|
+
export type WorkInputCode = "WORK_JSON_INVALID" | "WORK_DUPLICATE_MEMBER" | "WORK_LIMIT_EXCEEDED" | "WORK_VERSION_UNSUPPORTED" | "WORK_SCHEMA_INVALID" | "WORK_DIGEST_MISMATCH" | "WORK_CONTEXT_INVALID";
|
|
6
|
+
export declare class WorkInputError extends TypeError {
|
|
7
|
+
readonly code: WorkInputCode;
|
|
8
|
+
constructor(code: WorkInputCode);
|
|
9
|
+
}
|
|
10
|
+
export type WorkWriteCode = "WORK_DESTINATION_INVALID" | "WORK_DESTINATION_ALIAS" | "WORK_LEDGER_WRITE_FAILED";
|
|
11
|
+
export declare class WorkLedgerWriteError extends Error {
|
|
12
|
+
readonly code: WorkWriteCode;
|
|
13
|
+
constructor(code: WorkWriteCode);
|
|
14
|
+
}
|
|
15
|
+
export type WorkInspectionCode = "WORK_INSPECTION_PATH_INVALID" | "WORK_INSPECTION_NOT_REGULAR" | "WORK_INSPECTION_READ_FAILED";
|
|
16
|
+
export interface WorkInspectionDiagnostic {
|
|
17
|
+
readonly line: null;
|
|
18
|
+
readonly code: WorkInputCode | WorkInspectionCode;
|
|
19
|
+
}
|
|
20
|
+
export interface WorkLedgerInspection {
|
|
21
|
+
readonly version: 4;
|
|
22
|
+
readonly status: "read" | "missing" | "error";
|
|
23
|
+
readonly exists: boolean | null;
|
|
24
|
+
readonly ingestion: WorkIngestion | null;
|
|
25
|
+
readonly projection: WorkProjection | null;
|
|
26
|
+
readonly errors: ReadonlyArray<WorkInspectionDiagnostic>;
|
|
27
|
+
}
|
|
28
|
+
export type RevisionKind = "scope" | "goal" | "node" | "obligation" | "artifact" | "policy";
|
|
29
|
+
export type WorkEventKind = "work_revision" | "work_snapshot" | "work_occurrence" | "work_acceptance";
|
|
30
|
+
export interface RevisionRef {
|
|
31
|
+
kind: RevisionKind;
|
|
32
|
+
id: string;
|
|
33
|
+
revision: number;
|
|
34
|
+
digest: string;
|
|
35
|
+
}
|
|
36
|
+
export interface EventRef {
|
|
37
|
+
eventId: string;
|
|
38
|
+
digest: string;
|
|
39
|
+
}
|
|
40
|
+
export interface Identity {
|
|
41
|
+
id: string;
|
|
42
|
+
digest: string;
|
|
43
|
+
}
|
|
44
|
+
export interface WorkRevision {
|
|
45
|
+
kind: RevisionKind;
|
|
46
|
+
id: string;
|
|
47
|
+
revision: number;
|
|
48
|
+
scopeId: string;
|
|
49
|
+
predecessor: RevisionRef | null;
|
|
50
|
+
contentDigest: string;
|
|
51
|
+
parent: RevisionRef | null;
|
|
52
|
+
dependencies: RevisionRef[];
|
|
53
|
+
ownerId: string;
|
|
54
|
+
permittedEffects: string[];
|
|
55
|
+
policy: RevisionRef | null;
|
|
56
|
+
digest: string;
|
|
57
|
+
}
|
|
58
|
+
export interface ObligationBinding {
|
|
59
|
+
intent: RevisionRef;
|
|
60
|
+
obligation: RevisionRef;
|
|
61
|
+
artifact: RevisionRef | null;
|
|
62
|
+
policy: RevisionRef;
|
|
63
|
+
}
|
|
64
|
+
export interface WorkSnapshot {
|
|
65
|
+
snapshotId: string;
|
|
66
|
+
scope: RevisionRef;
|
|
67
|
+
revisions: RevisionRef[];
|
|
68
|
+
bindings: ObligationBinding[];
|
|
69
|
+
digest: string;
|
|
70
|
+
}
|
|
71
|
+
export interface WorkOccurrencePayload {
|
|
72
|
+
scope: RevisionRef;
|
|
73
|
+
obligation: RevisionRef;
|
|
74
|
+
executionId: string;
|
|
75
|
+
parentExecutionId: string | null;
|
|
76
|
+
childId: string | null;
|
|
77
|
+
variantId: string | null;
|
|
78
|
+
artifact: RevisionRef | null;
|
|
79
|
+
provenance: "declared" | "observed";
|
|
80
|
+
state: "unknown" | "starting" | "running" | "completed" | "failed";
|
|
81
|
+
labels: {
|
|
82
|
+
sessionId: string | null;
|
|
83
|
+
branchLeafId: string | null;
|
|
84
|
+
toolCallId: string | null;
|
|
85
|
+
taskId: string | null;
|
|
86
|
+
workspaceId: string | null;
|
|
87
|
+
definitionDigest: string | null;
|
|
88
|
+
configurationDigest: string | null;
|
|
89
|
+
modelId: string | null;
|
|
90
|
+
effortId: string | null;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export interface EvidenceRef {
|
|
94
|
+
id: string;
|
|
95
|
+
digest: string;
|
|
96
|
+
event: EventRef | null;
|
|
97
|
+
}
|
|
98
|
+
export interface AcceptanceBinding {
|
|
99
|
+
snapshot: Identity;
|
|
100
|
+
scope: RevisionRef;
|
|
101
|
+
intent: RevisionRef;
|
|
102
|
+
obligation: RevisionRef;
|
|
103
|
+
artifact: RevisionRef;
|
|
104
|
+
artifactDigest: string;
|
|
105
|
+
policy: RevisionRef;
|
|
106
|
+
evidence: EvidenceRef[];
|
|
107
|
+
}
|
|
108
|
+
export interface WorkAcceptancePayload {
|
|
109
|
+
authorityId: string;
|
|
110
|
+
binding: AcceptanceBinding;
|
|
111
|
+
}
|
|
112
|
+
interface WorkEvent<K extends WorkEventKind, P> {
|
|
113
|
+
ledgerVersion: 4;
|
|
114
|
+
event: K;
|
|
115
|
+
eventId: string;
|
|
116
|
+
ts: string;
|
|
117
|
+
payload: P;
|
|
118
|
+
digest: string;
|
|
119
|
+
}
|
|
120
|
+
export type WorkRevisionEvent = WorkEvent<"work_revision", {
|
|
121
|
+
revision: WorkRevision;
|
|
122
|
+
}>;
|
|
123
|
+
export type WorkSnapshotEvent = WorkEvent<"work_snapshot", {
|
|
124
|
+
snapshot: WorkSnapshot;
|
|
125
|
+
}>;
|
|
126
|
+
export type WorkOccurrenceEvent = WorkEvent<"work_occurrence", WorkOccurrencePayload>;
|
|
127
|
+
export type WorkAcceptanceEvent = WorkEvent<"work_acceptance", WorkAcceptancePayload>;
|
|
128
|
+
export type WorkLedgerEvent = WorkRevisionEvent | WorkSnapshotEvent | WorkOccurrenceEvent | WorkAcceptanceEvent;
|
|
129
|
+
export interface WorkDiagnostic {
|
|
130
|
+
readonly line: number | null;
|
|
131
|
+
readonly code: WorkInputCode;
|
|
132
|
+
}
|
|
133
|
+
export interface WorkIngestion {
|
|
134
|
+
readonly events: ReadonlyArray<WorkLedgerEvent>;
|
|
135
|
+
readonly errors: ReadonlyArray<WorkDiagnostic>;
|
|
136
|
+
readonly complete: boolean;
|
|
137
|
+
}
|
|
138
|
+
export type WorkResolutionCode = "INPUT_INCOMPLETE" | "NO_SELECTION" | "REFERENCE_MISSING" | "SCOPE_INVALID" | "REVISION_INVALID" | "CYCLE" | "DEPENDENCY_INVALID" | "EVENT_CONFLICT" | "ARTIFACT_UNSELECTED" | "ARTIFACT_DIGEST_MISMATCH" | "NO_CLAIM" | "SUPERSEDED_BINDING" | "AUTHORITY_MISSING" | "RECEIPT_MISSING" | "RECEIPT_MISMATCH" | "RECEIPT_CONFLICT" | "DECISION_CONFLICT" | "TRUSTED_REJECTION" | "AVAILABILITY_MISSING" | "BYTES_UNAVAILABLE" | "AVAILABILITY_CONFLICT" | "OCCURRENCE_CONFLICT" | "PARENT_MISSING" | "PARENT_CYCLE" | "OBSERVATION_CONFLICT" | "BRANCH_UNKNOWN";
|
|
139
|
+
export type WorkReference = {
|
|
140
|
+
readonly type: "revision";
|
|
141
|
+
readonly ref: RevisionRef;
|
|
142
|
+
} | {
|
|
143
|
+
readonly type: "event";
|
|
144
|
+
readonly ref: EventRef;
|
|
145
|
+
} | {
|
|
146
|
+
readonly type: "snapshot" | "authority" | "artifact-bytes" | "evidence-bytes";
|
|
147
|
+
readonly ref: Identity;
|
|
148
|
+
} | {
|
|
149
|
+
readonly type: "execution";
|
|
150
|
+
readonly id: string;
|
|
151
|
+
};
|
|
152
|
+
export interface WorkProblem {
|
|
153
|
+
readonly code: WorkResolutionCode;
|
|
154
|
+
readonly reference: WorkReference | null;
|
|
155
|
+
readonly affectedObligations: ReadonlyArray<RevisionRef>;
|
|
156
|
+
}
|
|
157
|
+
export interface WorkConflict {
|
|
158
|
+
readonly kind: "event" | "receipt";
|
|
159
|
+
readonly id: string;
|
|
160
|
+
readonly digests: ReadonlyArray<string>;
|
|
161
|
+
readonly affectedObligations: ReadonlyArray<RevisionRef>;
|
|
162
|
+
}
|
|
163
|
+
/** Explicit trusted-host declarations, never constructed from wire evidence by production code. */
|
|
164
|
+
export interface WorkProjectionContext {
|
|
165
|
+
selectedSnapshot: {
|
|
166
|
+
snapshot: Identity;
|
|
167
|
+
event: EventRef;
|
|
168
|
+
} | null;
|
|
169
|
+
authority: {
|
|
170
|
+
snapshot: Identity;
|
|
171
|
+
decisions: Array<{
|
|
172
|
+
receiptId: string;
|
|
173
|
+
authorityId: string;
|
|
174
|
+
claim: EventRef;
|
|
175
|
+
binding: AcceptanceBinding;
|
|
176
|
+
decision: "accept" | "reject";
|
|
177
|
+
}>;
|
|
178
|
+
availability: Array<{
|
|
179
|
+
kind: "artifact" | "evidence";
|
|
180
|
+
id: string;
|
|
181
|
+
digest: string;
|
|
182
|
+
available: boolean;
|
|
183
|
+
}>;
|
|
184
|
+
} | null;
|
|
185
|
+
}
|
|
186
|
+
export type WorkAvailability = "available" | "unavailable" | "unknown" | "conflicted";
|
|
187
|
+
export interface WorkCoverageItem {
|
|
188
|
+
readonly kind: "artifact" | "evidence";
|
|
189
|
+
readonly identity: Identity;
|
|
190
|
+
readonly state: WorkAvailability;
|
|
191
|
+
}
|
|
192
|
+
export interface WorkCoverage {
|
|
193
|
+
readonly state: WorkAvailability | "unselected";
|
|
194
|
+
readonly items: ReadonlyArray<WorkCoverageItem>;
|
|
195
|
+
}
|
|
196
|
+
export type WorkAcceptanceState = "accepted-under-supplied-authority" | "unaccepted" | "unresolved";
|
|
197
|
+
export interface WorkClaimResult {
|
|
198
|
+
readonly claim: EventRef;
|
|
199
|
+
readonly obligation: RevisionRef;
|
|
200
|
+
readonly applicability: WorkAcceptanceState | "superseded";
|
|
201
|
+
readonly matchedReceiptIds: ReadonlyArray<string>;
|
|
202
|
+
readonly problems: ReadonlyArray<WorkProblem>;
|
|
203
|
+
}
|
|
204
|
+
export interface WorkObligationResult {
|
|
205
|
+
readonly binding: ObligationBinding;
|
|
206
|
+
readonly acceptance: WorkAcceptanceState;
|
|
207
|
+
readonly artifactCoverage: WorkCoverage;
|
|
208
|
+
readonly evidenceCoverage: WorkCoverage;
|
|
209
|
+
readonly claims: ReadonlyArray<EventRef>;
|
|
210
|
+
readonly problems: ReadonlyArray<WorkProblem>;
|
|
211
|
+
}
|
|
212
|
+
export interface WorkOccurrenceView {
|
|
213
|
+
readonly event: EventRef;
|
|
214
|
+
readonly payload: WorkOccurrencePayload;
|
|
215
|
+
}
|
|
216
|
+
export interface WorkAttemptBinding {
|
|
217
|
+
readonly scope: RevisionRef;
|
|
218
|
+
readonly obligation: RevisionRef;
|
|
219
|
+
readonly variantIds: ReadonlyArray<string>;
|
|
220
|
+
readonly artifacts: ReadonlyArray<RevisionRef>;
|
|
221
|
+
}
|
|
222
|
+
export interface WorkAttempt {
|
|
223
|
+
readonly executionId: string;
|
|
224
|
+
readonly bindings: ReadonlyArray<WorkAttemptBinding>;
|
|
225
|
+
readonly parentExecutionId: string | null;
|
|
226
|
+
readonly childId: string | null;
|
|
227
|
+
readonly declaredLabels: ReadonlyArray<WorkOccurrencePayload["labels"]>;
|
|
228
|
+
readonly observedLabels: ReadonlyArray<WorkOccurrencePayload["labels"]>;
|
|
229
|
+
readonly effectiveLabels: WorkOccurrencePayload["labels"];
|
|
230
|
+
readonly state: WorkOccurrencePayload["state"] | "conflicted";
|
|
231
|
+
readonly resolution: "resolved" | "unresolved";
|
|
232
|
+
readonly problems: ReadonlyArray<WorkProblem>;
|
|
233
|
+
}
|
|
234
|
+
export interface WorkRuntimeCounts {
|
|
235
|
+
readonly attempts: number;
|
|
236
|
+
readonly variants: number;
|
|
237
|
+
readonly observedCompletedAttempts: number;
|
|
238
|
+
}
|
|
239
|
+
export interface WorkRuntime {
|
|
240
|
+
readonly counts: WorkRuntimeCounts;
|
|
241
|
+
readonly occurrences: ReadonlyArray<WorkOccurrenceView>;
|
|
242
|
+
readonly attempts: ReadonlyArray<WorkAttempt>;
|
|
243
|
+
}
|
|
244
|
+
export interface WorkProjection {
|
|
245
|
+
readonly selectedSnapshot: Identity | null;
|
|
246
|
+
readonly authoritySnapshot: Identity | null;
|
|
247
|
+
readonly scopeState: "unselected" | "valid" | "unresolved" | "invalid";
|
|
248
|
+
readonly progress: Readonly<{
|
|
249
|
+
accepted: number;
|
|
250
|
+
total: number;
|
|
251
|
+
}> | null;
|
|
252
|
+
readonly obligations: ReadonlyArray<WorkObligationResult>;
|
|
253
|
+
readonly claims: ReadonlyArray<WorkClaimResult>;
|
|
254
|
+
readonly supersededClaims: number;
|
|
255
|
+
readonly conflicts: ReadonlyArray<WorkConflict>;
|
|
256
|
+
readonly problems: ReadonlyArray<WorkProblem>;
|
|
257
|
+
readonly errors: ReadonlyArray<WorkDiagnostic>;
|
|
258
|
+
readonly runtime: WorkRuntime | null;
|
|
259
|
+
}
|
|
260
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class WorkInputError extends TypeError {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code) {
|
|
4
|
+
super(code);
|
|
5
|
+
this.name = "WorkInputError";
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class WorkLedgerWriteError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(code) { super(code); this.name = "WorkLedgerWriteError"; this.code = code; }
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=retention-v2-work-types.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Unique identity for one governed execution occurrence. Logical child ids remain readable positions. */
|
|
2
|
+
export type ExecutionId = `exec:${string}`;
|
|
3
|
+
export declare function isExecutionId(value: unknown): value is ExecutionId;
|
|
4
|
+
export declare function newExecutionId(): ExecutionId;
|
|
5
|
+
export declare function assertExecutionId(value: unknown, field?: string): asserts value is ExecutionId;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// GENERATED from pi-daddy 7c78769c47177b1972b09e1f5c5474ad44cd2cac by scripts/vendor-work-v4-reader.mjs. Do not hand-edit.
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
const EXECUTION_ID_RE = /^exec:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
4
|
+
export function isExecutionId(value) {
|
|
5
|
+
return typeof value === "string" && EXECUTION_ID_RE.test(value);
|
|
6
|
+
}
|
|
7
|
+
export function newExecutionId() {
|
|
8
|
+
return `exec:${randomUUID()}`;
|
|
9
|
+
}
|
|
10
|
+
export function assertExecutionId(value, field = "executionId") {
|
|
11
|
+
if (!isExecutionId(value))
|
|
12
|
+
throw new TypeError(`${field} must be a pi-daddy execution id`);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=execution-id.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type WorkFrozen, type WorkProblem, type WorkConflict } from "./types.js";
|
|
2
|
+
export declare const WORK_EVENT_BYTES: number;
|
|
3
|
+
export declare const WORK_TEXT_BYTES: number;
|
|
4
|
+
export declare const WORK_RECORDS = 10000;
|
|
5
|
+
export type WorkJson = null | boolean | number | string | WorkJson[] | {
|
|
6
|
+
[key: string]: WorkJson;
|
|
7
|
+
};
|
|
8
|
+
/** Inspect descriptors rather than serializing: no getters/toJSON or lossy JSON coercion. */
|
|
9
|
+
export declare function ownWorkFields(value: unknown): Record<string, PropertyDescriptor>;
|
|
10
|
+
/** Detach only the approved JSON value profile, before any serialization or validation use. */
|
|
11
|
+
export declare function copyWorkJson(value: unknown): WorkJson;
|
|
12
|
+
/** Bounded syntax tree: syntax, decoded duplicates, then exact numeric/string profile. */
|
|
13
|
+
export declare function parseWorkJson(text: string): WorkJson;
|
|
14
|
+
/** RFC 8785 emission restricted to our validated JSON profile; not an archival-byte identity. */
|
|
15
|
+
export declare function canonicalWorkJson(value: unknown): string;
|
|
16
|
+
export declare function workDigest(value: unknown): string;
|
|
17
|
+
/** @internal ONLY validated constituents / internally constructed plain results. Output collections
|
|
18
|
+
* are not wire records: they may contain >256 claims, problems, labels, or conflict alternatives.
|
|
19
|
+
* Never use this emitter in place of copyWorkJson/strict ingestion at an input boundary. */
|
|
20
|
+
export declare function workResultKey<T>(value: T): string;
|
|
21
|
+
export declare function sortWorkResults<T>(values: Iterable<T>): T[];
|
|
22
|
+
export declare function mergeWorkProblems(values: readonly WorkFrozen<WorkProblem>[]): WorkFrozen<WorkProblem>[];
|
|
23
|
+
export declare function mergeWorkConflicts(values: readonly WorkFrozen<WorkConflict>[]): WorkFrozen<WorkConflict>[];
|
|
24
|
+
export declare function freezeWork<T>(value: T): WorkFrozen<T>;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// GENERATED from pi-daddy 7c78769c47177b1972b09e1f5c5474ad44cd2cac by scripts/vendor-work-v4-reader.mjs. Do not hand-edit.
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { WorkInputError } from "./types.js";
|
|
4
|
+
export const WORK_EVENT_BYTES = 64 * 1024;
|
|
5
|
+
export const WORK_TEXT_BYTES = 16 * 1024 * 1024;
|
|
6
|
+
export const WORK_RECORDS = 10_000;
|
|
7
|
+
const MAX_DEPTH = 16;
|
|
8
|
+
const MAX_ARRAY = 256;
|
|
9
|
+
const invalid = () => { throw new WorkInputError("WORK_SCHEMA_INVALID"); };
|
|
10
|
+
const limit = () => { throw new WorkInputError("WORK_LIMIT_EXCEEDED"); };
|
|
11
|
+
function unicode(value) {
|
|
12
|
+
// RFC 8785 refuses lone UTF-16 surrogates, including ones decoded from escapes.
|
|
13
|
+
for (let i = 0; i < value.length; i++) {
|
|
14
|
+
const code = value.charCodeAt(i);
|
|
15
|
+
if (code >= 0xd800 && code <= 0xdbff) {
|
|
16
|
+
const next = value.charCodeAt(++i);
|
|
17
|
+
if (!(next >= 0xdc00 && next <= 0xdfff))
|
|
18
|
+
invalid();
|
|
19
|
+
}
|
|
20
|
+
else if (code >= 0xdc00 && code <= 0xdfff)
|
|
21
|
+
invalid();
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
/** Inspect descriptors rather than serializing: no getters/toJSON or lossy JSON coercion. */
|
|
26
|
+
export function ownWorkFields(value) {
|
|
27
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
28
|
+
invalid();
|
|
29
|
+
const prototype = Object.getPrototypeOf(value);
|
|
30
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
31
|
+
invalid();
|
|
32
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
33
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
34
|
+
if (typeof key !== "string")
|
|
35
|
+
return invalid();
|
|
36
|
+
const descriptor = descriptors[key];
|
|
37
|
+
if (!Object.hasOwn(descriptor, "value") || !descriptor.enumerable)
|
|
38
|
+
invalid();
|
|
39
|
+
unicode(key);
|
|
40
|
+
}
|
|
41
|
+
return descriptors;
|
|
42
|
+
}
|
|
43
|
+
/** Detach only the approved JSON value profile, before any serialization or validation use. */
|
|
44
|
+
export function copyWorkJson(value) {
|
|
45
|
+
const ancestors = new Set();
|
|
46
|
+
function copy(v, depth) {
|
|
47
|
+
if (v === null || typeof v === "boolean")
|
|
48
|
+
return v;
|
|
49
|
+
if (typeof v === "string")
|
|
50
|
+
return unicode(v);
|
|
51
|
+
if (typeof v === "number")
|
|
52
|
+
return Number.isSafeInteger(v) ? v : invalid();
|
|
53
|
+
if (typeof v !== "object")
|
|
54
|
+
return invalid();
|
|
55
|
+
if (depth > MAX_DEPTH)
|
|
56
|
+
limit();
|
|
57
|
+
if (ancestors.has(v))
|
|
58
|
+
invalid();
|
|
59
|
+
ancestors.add(v);
|
|
60
|
+
let result;
|
|
61
|
+
if (Array.isArray(v)) {
|
|
62
|
+
if (Object.getPrototypeOf(v) !== Array.prototype)
|
|
63
|
+
invalid();
|
|
64
|
+
if (v.length > MAX_ARRAY)
|
|
65
|
+
limit();
|
|
66
|
+
const fields = Object.getOwnPropertyDescriptors(v);
|
|
67
|
+
if (Reflect.ownKeys(fields).length !== v.length + 1)
|
|
68
|
+
invalid();
|
|
69
|
+
result = [];
|
|
70
|
+
for (let i = 0; i < v.length; i++) {
|
|
71
|
+
const d = fields[String(i)];
|
|
72
|
+
if (!d || !Object.hasOwn(d, "value") || !d.enumerable)
|
|
73
|
+
invalid();
|
|
74
|
+
result.push(copy(d.value, depth + 1));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const fields = ownWorkFields(v);
|
|
79
|
+
result = {};
|
|
80
|
+
for (const key of Object.keys(fields)) {
|
|
81
|
+
Object.defineProperty(result, key, { value: copy(fields[key].value, depth + 1), enumerable: true, writable: true, configurable: true });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
ancestors.delete(v);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
return copy(value, 1);
|
|
88
|
+
}
|
|
89
|
+
/** Exact decimal arithmetic BEFORE Number conversion, without unbounded exponent allocation. */
|
|
90
|
+
function integerToken(token) {
|
|
91
|
+
const match = /^(-?)(\d+)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/.exec(token);
|
|
92
|
+
let digits = (match[2] + (match[3] ?? "")).replace(/^0+/, "");
|
|
93
|
+
if (!digits)
|
|
94
|
+
return 0;
|
|
95
|
+
let shift = BigInt(match[4] ?? "0") - BigInt((match[3] ?? "").length);
|
|
96
|
+
const trailing = /0*$/.exec(digits)[0].length;
|
|
97
|
+
digits = digits.slice(0, digits.length - trailing);
|
|
98
|
+
shift += BigInt(trailing);
|
|
99
|
+
if (shift < 0n || BigInt(digits.length) + shift > 16n)
|
|
100
|
+
invalid();
|
|
101
|
+
const exact = BigInt(digits) * (10n ** shift);
|
|
102
|
+
if (exact > BigInt(Number.MAX_SAFE_INTEGER))
|
|
103
|
+
invalid();
|
|
104
|
+
return Number(match[1] === "-" ? -exact : exact);
|
|
105
|
+
}
|
|
106
|
+
function checkMembers(node) {
|
|
107
|
+
if (node.type === "object") {
|
|
108
|
+
const names = new Set();
|
|
109
|
+
for (const [key, child] of node.entries) {
|
|
110
|
+
if (names.has(key))
|
|
111
|
+
throw new WorkInputError("WORK_DUPLICATE_MEMBER");
|
|
112
|
+
names.add(key);
|
|
113
|
+
checkMembers(child);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (node.type === "array")
|
|
117
|
+
node.items.forEach(checkMembers);
|
|
118
|
+
}
|
|
119
|
+
function materialize(node) {
|
|
120
|
+
if (node.type === "number")
|
|
121
|
+
return integerToken(node.token);
|
|
122
|
+
if (node.type === "literal")
|
|
123
|
+
return typeof node.value === "string" ? unicode(node.value) : node.value;
|
|
124
|
+
if (node.type === "array")
|
|
125
|
+
return node.items.map(materialize);
|
|
126
|
+
return Object.fromEntries(node.entries.map(([key, child]) => [unicode(key), materialize(child)]));
|
|
127
|
+
}
|
|
128
|
+
/** Bounded syntax tree: syntax, decoded duplicates, then exact numeric/string profile. */
|
|
129
|
+
export function parseWorkJson(text) {
|
|
130
|
+
if (typeof text !== "string")
|
|
131
|
+
invalid();
|
|
132
|
+
if (Buffer.byteLength(text, "utf8") > WORK_EVENT_BYTES)
|
|
133
|
+
limit();
|
|
134
|
+
let at = 0;
|
|
135
|
+
const syntax = () => { throw new WorkInputError("WORK_JSON_INVALID"); };
|
|
136
|
+
const whitespace = () => { while (at < text.length && /[ \t\r\n]/.test(text[at]))
|
|
137
|
+
at++; };
|
|
138
|
+
function string() {
|
|
139
|
+
const start = at++;
|
|
140
|
+
while (at < text.length) {
|
|
141
|
+
const char = text[at++];
|
|
142
|
+
if (char === '"') {
|
|
143
|
+
// JSON.parse is used ONLY for one lexically delimited string token, never an object.
|
|
144
|
+
return JSON.parse(text.slice(start, at));
|
|
145
|
+
}
|
|
146
|
+
if (char.charCodeAt(0) < 0x20)
|
|
147
|
+
syntax();
|
|
148
|
+
if (char === "\\") {
|
|
149
|
+
const escape = text[at++];
|
|
150
|
+
if (escape === "u") {
|
|
151
|
+
if (!/^[0-9a-fA-F]{4}$/.test(text.slice(at, at + 4)))
|
|
152
|
+
syntax();
|
|
153
|
+
at += 4;
|
|
154
|
+
}
|
|
155
|
+
else if (!escape || !'"\\/bfnrt'.includes(escape))
|
|
156
|
+
syntax();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return syntax();
|
|
160
|
+
}
|
|
161
|
+
function value(depth) {
|
|
162
|
+
whitespace();
|
|
163
|
+
const char = text[at];
|
|
164
|
+
if (char === '"')
|
|
165
|
+
return { type: "literal", value: string() };
|
|
166
|
+
if (char === "{" || char === "[") {
|
|
167
|
+
if (depth > MAX_DEPTH)
|
|
168
|
+
limit();
|
|
169
|
+
at++;
|
|
170
|
+
whitespace();
|
|
171
|
+
const object = char === "{";
|
|
172
|
+
const end = object ? "}" : "]";
|
|
173
|
+
const entries = [];
|
|
174
|
+
const items = [];
|
|
175
|
+
if (text[at] !== end)
|
|
176
|
+
for (;;) {
|
|
177
|
+
whitespace();
|
|
178
|
+
let key = "";
|
|
179
|
+
if (object) {
|
|
180
|
+
if (text[at] !== '"')
|
|
181
|
+
syntax();
|
|
182
|
+
key = string();
|
|
183
|
+
whitespace();
|
|
184
|
+
if (text[at++] !== ":")
|
|
185
|
+
syntax();
|
|
186
|
+
}
|
|
187
|
+
else if (items.length >= MAX_ARRAY)
|
|
188
|
+
limit();
|
|
189
|
+
const child = value(depth + 1);
|
|
190
|
+
if (object)
|
|
191
|
+
entries.push([key, child]);
|
|
192
|
+
else
|
|
193
|
+
items.push(child);
|
|
194
|
+
whitespace();
|
|
195
|
+
if (text[at] === end)
|
|
196
|
+
break;
|
|
197
|
+
if (text[at++] !== ",")
|
|
198
|
+
syntax();
|
|
199
|
+
}
|
|
200
|
+
at++;
|
|
201
|
+
return object ? { type: "object", entries } : { type: "array", items };
|
|
202
|
+
}
|
|
203
|
+
for (const [token, literal] of [["null", null], ["true", true], ["false", false]]) {
|
|
204
|
+
if (text.startsWith(token, at)) {
|
|
205
|
+
at += token.length;
|
|
206
|
+
return { type: "literal", value: literal };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const token = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(text.slice(at));
|
|
210
|
+
if (!token)
|
|
211
|
+
return syntax();
|
|
212
|
+
at += token[0].length;
|
|
213
|
+
return { type: "number", token: token[0] };
|
|
214
|
+
}
|
|
215
|
+
const result = value(1);
|
|
216
|
+
whitespace();
|
|
217
|
+
if (at !== text.length)
|
|
218
|
+
syntax();
|
|
219
|
+
checkMembers(result);
|
|
220
|
+
return materialize(result);
|
|
221
|
+
}
|
|
222
|
+
function emit(value) {
|
|
223
|
+
if (value === null || typeof value !== "object")
|
|
224
|
+
return JSON.stringify(value);
|
|
225
|
+
if (Array.isArray(value))
|
|
226
|
+
return `[${value.map(emit).join(",")}]`;
|
|
227
|
+
// Emit keys directly: reconstructing a JS object would reorder numeric-looking keys.
|
|
228
|
+
return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${emit(value[key])}`).join(",")}}`;
|
|
229
|
+
}
|
|
230
|
+
/** RFC 8785 emission restricted to our validated JSON profile; not an archival-byte identity. */
|
|
231
|
+
export function canonicalWorkJson(value) { return emit(copyWorkJson(value)); }
|
|
232
|
+
export function workDigest(value) {
|
|
233
|
+
return createHash("sha256").update(canonicalWorkJson(value), "utf8").digest("hex");
|
|
234
|
+
}
|
|
235
|
+
/** @internal ONLY validated constituents / internally constructed plain results. Output collections
|
|
236
|
+
* are not wire records: they may contain >256 claims, problems, labels, or conflict alternatives.
|
|
237
|
+
* Never use this emitter in place of copyWorkJson/strict ingestion at an input boundary. */
|
|
238
|
+
export function workResultKey(value) { return emit(value); }
|
|
239
|
+
export function sortWorkResults(values) {
|
|
240
|
+
const rows = new Map([...values].map(value => [workResultKey(value), value]));
|
|
241
|
+
return [...rows].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, value]) => value);
|
|
242
|
+
}
|
|
243
|
+
export function mergeWorkProblems(values) {
|
|
244
|
+
const rows = new Map();
|
|
245
|
+
for (const row of values) {
|
|
246
|
+
const id = workResultKey([row.code, row.reference]), prior = rows.get(id);
|
|
247
|
+
rows.set(id, { ...row, affectedObligations: sortWorkResults([...(prior?.affectedObligations ?? []), ...row.affectedObligations]) });
|
|
248
|
+
}
|
|
249
|
+
return sortWorkResults(rows.values());
|
|
250
|
+
}
|
|
251
|
+
export function mergeWorkConflicts(values) {
|
|
252
|
+
const rows = new Map();
|
|
253
|
+
for (const row of values) {
|
|
254
|
+
const id = workResultKey([row.kind, row.id]), prior = rows.get(id);
|
|
255
|
+
rows.set(id, { ...row, digests: sortWorkResults([...(prior?.digests ?? []), ...row.digests]),
|
|
256
|
+
affectedObligations: sortWorkResults([...(prior?.affectedObligations ?? []), ...row.affectedObligations]) });
|
|
257
|
+
}
|
|
258
|
+
return sortWorkResults(rows.values());
|
|
259
|
+
}
|
|
260
|
+
export function freezeWork(value) {
|
|
261
|
+
if (value !== null && typeof value === "object") {
|
|
262
|
+
for (const child of Object.values(value))
|
|
263
|
+
freezeWork(child);
|
|
264
|
+
Object.freeze(value);
|
|
265
|
+
}
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=json.js.map
|