@skill-harness/adapters 0.17.0 → 0.18.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.
Files changed (118) hide show
  1. package/dist/index.d.ts +0 -30
  2. package/dist/index.js +0 -30
  3. package/dist/pi.js +21 -133
  4. package/package.json +2 -3
  5. package/dist/archive-access.d.ts +0 -58
  6. package/dist/archive-access.js +0 -61
  7. package/dist/archive-checkpoint.d.ts +0 -47
  8. package/dist/archive-checkpoint.js +0 -116
  9. package/dist/archive-facts.d.ts +0 -19
  10. package/dist/archive-facts.js +0 -20
  11. package/dist/archive-observer.d.ts +0 -21
  12. package/dist/archive-observer.js +0 -79
  13. package/dist/archive-policy.d.ts +0 -107
  14. package/dist/archive-policy.js +0 -135
  15. package/dist/archive-read-capability.d.ts +0 -49
  16. package/dist/archive-read-capability.js +0 -45
  17. package/dist/archive-retention-policy.d.ts +0 -52
  18. package/dist/archive-retention-policy.js +0 -49
  19. package/dist/archived-work.d.ts +0 -45
  20. package/dist/archived-work.js +0 -78
  21. package/dist/blind-intervention.d.ts +0 -35
  22. package/dist/blind-intervention.js +0 -218
  23. package/dist/codex-diagnostic-model.d.ts +0 -14
  24. package/dist/codex-diagnostic-model.js +0 -39
  25. package/dist/codex-host-observer.d.ts +0 -111
  26. package/dist/codex-host-observer.js +0 -309
  27. package/dist/codex-https.d.ts +0 -7
  28. package/dist/codex-https.js +0 -221
  29. package/dist/codex-model-profile.d.ts +0 -38
  30. package/dist/codex-model-profile.js +0 -54
  31. package/dist/codex-producer-ipc.d.ts +0 -55
  32. package/dist/codex-producer-ipc.js +0 -67
  33. package/dist/codex-sdk-transport.d.ts +0 -50
  34. package/dist/codex-sdk-transport.js +0 -294
  35. package/dist/codex-subscription.d.ts +0 -114
  36. package/dist/codex-subscription.js +0 -268
  37. package/dist/evidence-archive.d.ts +0 -65
  38. package/dist/evidence-archive.js +0 -225
  39. package/dist/execution-projection-schema.d.ts +0 -10
  40. package/dist/execution-projection-schema.js +0 -30
  41. package/dist/execution-retention-archive.d.ts +0 -69
  42. package/dist/execution-retention-archive.js +0 -154
  43. package/dist/generated/retention-v2-contract.d.ts +0 -72
  44. package/dist/generated/retention-v2-contract.js +0 -105
  45. package/dist/generated/retention-v2-json.d.ts +0 -24
  46. package/dist/generated/retention-v2-json.js +0 -268
  47. package/dist/generated/retention-v2-native-json.d.ts +0 -2
  48. package/dist/generated/retention-v2-native-json.js +0 -33
  49. package/dist/generated/retention-v2-native.d.ts +0 -58
  50. package/dist/generated/retention-v2-native.js +0 -155
  51. package/dist/generated/retention-v2-pin.d.ts +0 -2
  52. package/dist/generated/retention-v2-pin.js +0 -4
  53. package/dist/generated/retention-v2-types.d.ts +0 -49
  54. package/dist/generated/retention-v2-types.js +0 -2
  55. package/dist/generated/retention-v2-work-types.d.ts +0 -260
  56. package/dist/generated/retention-v2-work-types.js +0 -13
  57. package/dist/generated/work-v4/execution-id.d.ts +0 -5
  58. package/dist/generated/work-v4/execution-id.js +0 -14
  59. package/dist/generated/work-v4/json.d.ts +0 -24
  60. package/dist/generated/work-v4/json.js +0 -268
  61. package/dist/generated/work-v4/occurrences.d.ts +0 -226
  62. package/dist/generated/work-v4/occurrences.js +0 -116
  63. package/dist/generated/work-v4/pin.d.ts +0 -1
  64. package/dist/generated/work-v4/pin.js +0 -3
  65. package/dist/generated/work-v4/projection.d.ts +0 -294
  66. package/dist/generated/work-v4/projection.js +0 -238
  67. package/dist/generated/work-v4/reader.d.ts +0 -24
  68. package/dist/generated/work-v4/reader.js +0 -109
  69. package/dist/generated/work-v4/snapshot.d.ts +0 -28
  70. package/dist/generated/work-v4/snapshot.js +0 -268
  71. package/dist/generated/work-v4/types.d.ts +0 -260
  72. package/dist/generated/work-v4/types.js +0 -13
  73. package/dist/generated/work-v4/validation.d.ts +0 -13
  74. package/dist/generated/work-v4/validation.js +0 -227
  75. package/dist/installed-review-session.d.ts +0 -28
  76. package/dist/installed-review-session.js +0 -166
  77. package/dist/intervention-run.d.ts +0 -403
  78. package/dist/intervention-run.js +0 -169
  79. package/dist/learning-case.d.ts +0 -12
  80. package/dist/learning-case.js +0 -15
  81. package/dist/learning-journal.d.ts +0 -18
  82. package/dist/learning-journal.js +0 -256
  83. package/dist/learning-lifecycle.d.ts +0 -28
  84. package/dist/learning-lifecycle.js +0 -66
  85. package/dist/learning-trust-setup.d.ts +0 -64
  86. package/dist/learning-trust-setup.js +0 -55
  87. package/dist/learning-workspace.d.ts +0 -1084
  88. package/dist/learning-workspace.js +0 -705
  89. package/dist/principal-payload-port.d.ts +0 -25
  90. package/dist/principal-payload-port.js +0 -40
  91. package/dist/producer-product.d.ts +0 -70
  92. package/dist/producer-product.js +0 -186
  93. package/dist/producer-review.d.ts +0 -53
  94. package/dist/producer-review.js +0 -207
  95. package/dist/prompt-capture-extension.d.ts +0 -10
  96. package/dist/prompt-capture-extension.js +0 -26
  97. package/dist/prompt-provenance.d.ts +0 -22
  98. package/dist/prompt-provenance.js +0 -146
  99. package/dist/reviewed-archive-export.d.ts +0 -42
  100. package/dist/reviewed-archive-export.js +0 -78
  101. package/dist/session-observation.d.ts +0 -50
  102. package/dist/session-observation.js +0 -186
  103. package/dist/session-retention.d.ts +0 -48
  104. package/dist/session-retention.js +0 -121
  105. package/dist/trust-lifecycle.d.ts +0 -152
  106. package/dist/trust-lifecycle.js +0 -209
  107. package/dist/weekly-investigation.d.ts +0 -237
  108. package/dist/weekly-investigation.js +0 -330
  109. package/dist/work-candidates.d.ts +0 -29
  110. package/dist/work-candidates.js +0 -78
  111. package/dist/work-case-archive.d.ts +0 -25
  112. package/dist/work-case-archive.js +0 -63
  113. package/dist/work-case-review.d.ts +0 -45
  114. package/dist/work-case-review.js +0 -220
  115. package/dist/work-signal-cases.d.ts +0 -15
  116. package/dist/work-signal-cases.js +0 -54
  117. package/dist/work-signal-observation.d.ts +0 -23
  118. package/dist/work-signal-observation.js +0 -89
@@ -1,238 +0,0 @@
1
- // GENERATED from pi-daddy 7c78769c47177b1972b09e1f5c5474ad44cd2cac by scripts/vendor-work-v4-reader.mjs. Do not hand-edit.
2
- import { parseWorkLedgerText } from "./reader.js";
3
- import { canonicalWorkJson, freezeWork, workDigest, workResultKey as key, sortWorkResults as unique, mergeWorkProblems, mergeWorkConflicts } from "./json.js";
4
- const revisionIdentity = ({ kind, id, revision, digest }) => key(["revision", kind, id, revision, digest]);
5
- /** The ONLY nested identity definition. Claims deliberately have no nested quarantine identity. */
6
- function nestedIdentity(event) {
7
- switch (event.event) {
8
- case "work_revision": return revisionIdentity(event.payload.revision);
9
- case "work_snapshot": return key(["snapshot", event.payload.snapshot.snapshotId, event.payload.snapshot.digest]);
10
- case "work_occurrence": return key(["occurrence", event.payload]);
11
- case "work_acceptance": return null;
12
- }
13
- }
14
- function sourceIds(index, event) {
15
- const nested = "event" in event ? nestedIdentity(event) : null;
16
- return [...(index.conflictSources.events[key(event.eventId)] ? [event.eventId] : []),
17
- ...(nested === null ? [] : index.conflictSources.bodies[nested] ?? [])];
18
- }
19
- /** @internal Only index-derived validated events/references. Raw alternatives remain diagnostic input. */
20
- export function workEventConflictSources(index, event) {
21
- return unique(unique(sourceIds(index, event)).flatMap(id => index.conflictSources.events[key(id)]));
22
- }
23
- /** @internal Exact revision references need not have a clean delivery to be quarantined. */
24
- export function workRevisionConflictSources(index, ref) {
25
- return unique((index.conflictSources.bodies[revisionIdentity(ref)] ?? []).flatMap(id => index.conflictSources.events[key(id)]));
26
- }
27
- function sorted(values) {
28
- // Canonicalize individual rows, not the aggregate. A valid 10,000-record input can have
29
- // more than 256 candidates/conflicts; the per-wire-array bound must not truncate replay.
30
- return [...values].map(value => ({ value, key: canonicalWorkJson(value) }))
31
- .sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0)
32
- .map(entry => entry.value);
33
- }
34
- /**
35
- * @internal Strict text -> complete delivery grouping -> quarantine -> effective evidence.
36
- * Deliberately not re-exported by work-ledger.ts: this is not an unchecked public projector.
37
- * Raw serialized/archival byte hashes play no role in semantic delivery identity.
38
- */
39
- export function indexWorkLedgerText(text) {
40
- const ingestion = parseWorkLedgerText(text);
41
- const groups = new Map();
42
- for (const event of ingestion.events) {
43
- let group = groups.get(event.eventId);
44
- if (!group) {
45
- group = new Map();
46
- groups.set(event.eventId, group);
47
- }
48
- if (!group.has(event.digest)) {
49
- // Equal canonical digests can arrive with different property insertion orders. Normalize
50
- // the validated body so even serialized index output does not choose an arrival's key order.
51
- // Parse ONLY our own canonical emission, never raw input. Strict ingestion already checked
52
- // duplicates, domains and digests. JCS can expand exact exponent tokens beyond the delivered
53
- // text size, so applying the raw-line byte bound again here would reject valid evidence.
54
- const normalized = JSON.parse(canonicalWorkJson(event));
55
- group.set(event.digest, freezeWork(normalized));
56
- }
57
- }
58
- const conflictingEvents = [];
59
- const quarantined = new Map(); // Retained diagnostic view, not a second quarantine policy.
60
- const bodies = new Map(), eventGroups = new Map();
61
- for (const [eventId, group] of groups) {
62
- if (group.size < 2)
63
- continue;
64
- eventGroups.set(key(eventId), sorted([...group.values()].map(event => ({ eventId, digest: event.digest }))));
65
- for (const event of group.values()) {
66
- conflictingEvents.push({ eventId, digest: event.digest });
67
- const identity = nestedIdentity(event);
68
- if (identity !== null) {
69
- const ids = bodies.get(identity) ?? new Set();
70
- ids.add(eventId);
71
- bodies.set(identity, ids);
72
- }
73
- if (event.event === "work_revision") {
74
- const { kind, id, revision, digest } = event.payload.revision;
75
- // Ingestion verified that this digest covers the entire revision, including kind/ID/scope.
76
- // Quarantine exact bodies, not every fork or successor sharing a stable entity ID.
77
- quarantined.set(digest, { kind, id, revision, digest });
78
- }
79
- }
80
- }
81
- const candidates = sorted([...groups.values()].flatMap(group => [...group.values()]));
82
- const byKey = (map) => [...map].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
83
- const conflictSources = { bodies: Object.fromEntries(byKey(bodies).map(([identity, ids]) => [identity, [...ids].sort()])),
84
- events: Object.fromEntries(byKey(eventGroups)) };
85
- // All existing nested identities use the same source index before any effective evidence is exposed.
86
- const effectiveEvents = ingestion.complete ? candidates.filter(event => !sourceIds({ conflictSources }, event).length) : [];
87
- return freezeWork({
88
- ingestion, candidates, conflictingEvents: sorted(conflictingEvents), conflictSources,
89
- quarantinedRevisions: sorted(quarantined.values()), effectiveEvents,
90
- });
91
- }
92
- const eventRef = (event) => ({ eventId: event.eventId, digest: event.digest });
93
- const eventReference = (event) => ({ type: "event", ref: eventRef(event) });
94
- const isConflict = (p) => p.code.endsWith("CONFLICT");
95
- function coverage(items) {
96
- const state = ["conflicted", "unavailable", "unknown"].find(s => items.some(item => item.state === s));
97
- return { state: state ?? (items.length ? "available" : "unknown"), items: unique(items) };
98
- }
99
- /** @internal Global receipt identity diagnostics exist even without a resolved work selector. */
100
- export function indexWorkReceipts(authority) {
101
- const receipts = new Map();
102
- const conflicts = [];
103
- for (const d of authority?.decisions ?? []) {
104
- const group = receipts.get(d.receiptId) ?? new Map();
105
- // Complete decision + enclosing authority snapshot; diagnostic identity, NOT authentication.
106
- group.set(workDigest({ authoritySnapshot: authority.snapshot, ...d }), d);
107
- receipts.set(d.receiptId, group);
108
- }
109
- for (const [id, group] of receipts)
110
- if (group.size > 1) {
111
- conflicts.push({ kind: "receipt", id, digests: unique(group.keys()), affectedObligations: [] });
112
- }
113
- return { receipts, conflicts: unique(conflicts) };
114
- }
115
- /** @internal Conditional binding proof, not authentication. Only the separately supplied, validated
116
- * host authority is a TCB input. No wire label, event, receipt-shaped payload or environment is trust. */
117
- export function projectWorkAcceptance(index, structure, authority, runtime) {
118
- const snapshot = structure.snapshot;
119
- const claims = [], obligations = [];
120
- const problems = [...structure.problems];
121
- const conflicts = [...structure.conflicts, ...runtime.conflicts];
122
- const eventConflicts = new Set(index.conflictingEvents.map(e => e.eventId));
123
- const events = new Map(index.candidates.map(e => [key(eventRef(e)), e]));
124
- const receiptIndex = indexWorkReceipts(authority), { receipts } = receiptIndex;
125
- conflicts.push(...receiptIndex.conflicts);
126
- const decisions = [...receipts.values()].filter(g => g.size === 1).flatMap(g => [...g.values()]);
127
- function available(kind, id, digest) {
128
- const values = unique((authority?.availability ?? []).filter(row => row.kind === kind && row.id === id && row.digest === digest).map(row => row.available));
129
- const state = values.length > 1 ? "conflicted" : values.length === 0 ? "unknown" : values[0] ? "available" : "unavailable";
130
- return { kind, identity: { id, digest }, state };
131
- }
132
- const allClaims = index.candidates.filter((e) => e.event === "work_acceptance");
133
- function sourceProblems(ref, affected) {
134
- const result = [];
135
- const found = events.get(key(ref));
136
- for (const event of workEventConflictSources(index, found ?? ref)) {
137
- result.push({ code: "EVENT_CONFLICT", reference: { type: "event", ref: event }, affectedObligations: affected });
138
- }
139
- if (!found)
140
- result.push({ code: "REFERENCE_MISSING", reference: { type: "event", ref }, affectedObligations: affected });
141
- for (const p of runtime.eventProblems.get(key(ref)) ?? [])
142
- result.push({ ...p, affectedObligations: affected });
143
- return mergeWorkProblems(result);
144
- }
145
- for (const row of structure.obligations) {
146
- const binding = row.binding, affected = [binding.obligation];
147
- const problem = (code, reference) => ({ code, reference, affectedObligations: affected });
148
- const inventoryProblem = problem("ARTIFACT_UNSELECTED", { type: "revision", ref: binding.obligation });
149
- const blockers = [...row.problems, ...(binding.artifact === null ? [inventoryProblem] : [])];
150
- const selectedClaims = allClaims.filter(e => e.payload.binding.scope.id === snapshot.scope.id && e.payload.binding.obligation.id === binding.obligation.id);
151
- const applicable = (claim) => {
152
- const b = claim.payload.binding;
153
- return key(b.snapshot) === key(structure.selectedSnapshot) && key(b.scope) === key(snapshot.scope) &&
154
- key(b.intent) === key(binding.intent) && key(b.obligation) === key(binding.obligation) &&
155
- key(b.artifact) === key(binding.artifact) && key(b.policy) === key(binding.policy);
156
- };
157
- const current = selectedClaims.filter(applicable);
158
- const currentRefs = new Set(current.map(e => key(eventRef(e))));
159
- for (const e of current)
160
- if (eventConflicts.has(e.eventId)) {
161
- blockers.push(...index.conflictingEvents.filter(ref => ref.eventId === e.eventId).map(ref => problem("EVENT_CONFLICT", { type: "event", ref })));
162
- }
163
- for (const [id, group] of receipts)
164
- if (group.size > 1 && [...group.values()].some(d => currentRefs.has(key(d.claim)))) {
165
- conflicts.push({ kind: "receipt", id, digests: unique(group.keys()), affectedObligations: affected });
166
- blockers.push(problem("RECEIPT_CONFLICT", { type: "authority", ref: authority.snapshot }));
167
- }
168
- const artifactItems = row.artifact ? [available("artifact", row.artifact.id, row.artifact.contentDigest)] : [];
169
- const artifactCoverage = binding.artifact === null ? { state: "unselected", items: [] } : coverage(artifactItems);
170
- const evidenceCoverage = coverage(unique(current.flatMap(e => e.payload.binding.evidence.map(ref => available("evidence", ref.id, ref.digest)))));
171
- function coverageProblems(items) {
172
- return items.filter(item => item.state !== "available").map(item => problem(item.state === "conflicted" ? "AVAILABILITY_CONFLICT" : item.state === "unavailable" ? "BYTES_UNAVAILABLE" : "AVAILABILITY_MISSING", { type: item.kind === "artifact" ? "artifact-bytes" : "evidence-bytes", ref: item.identity }));
173
- }
174
- const rowClaims = [];
175
- const trustedDecisions = new Set();
176
- for (const claim of selectedClaims) {
177
- if (eventConflicts.has(claim.eventId))
178
- continue; // No first/last winner row, even for a favorable exact alternative.
179
- if (!applicable(claim)) {
180
- rowClaims.push({ claim: eventRef(claim), obligation: claim.payload.binding.obligation, applicability: "superseded",
181
- matchedReceiptIds: [], problems: [problem("SUPERSEDED_BINDING", eventReference(claim))] });
182
- continue;
183
- }
184
- const b = claim.payload.binding;
185
- const local = [];
186
- const bytesMatch = row.artifact !== null && b.artifactDigest === row.artifact.contentDigest;
187
- if (row.artifact && !bytesMatch)
188
- local.push(problem("ARTIFACT_DIGEST_MISMATCH", { type: "artifact-bytes", ref: { id: row.artifact.id, digest: b.artifactDigest } }));
189
- if (!row.artifact && binding.artifact)
190
- local.push(problem("REFERENCE_MISSING", { type: "revision", ref: binding.artifact }));
191
- const matching = decisions.filter(d => bytesMatch && key(d.claim) === key(eventRef(claim)) &&
192
- d.authorityId === claim.payload.authorityId && key(d.binding) === key(b));
193
- for (const d of matching)
194
- trustedDecisions.add(d.decision);
195
- if (!authority)
196
- local.push(problem("AUTHORITY_MISSING", null));
197
- else if (!matching.length)
198
- local.push(problem(decisions.some(d => d.claim.eventId === claim.eventId) ? "RECEIPT_MISMATCH" : "RECEIPT_MISSING", eventReference(claim)));
199
- const support = b.evidence.flatMap(ref => ref.event ? sourceProblems(ref.event, affected) : []);
200
- const availabilityProblems = coverageProblems([...artifactItems, ...b.evidence.map(ref => available("evidence", ref.id, ref.digest))]);
201
- local.push(...support, ...availabilityProblems);
202
- // Only EXACT matching current trusted decisions root global support conflicts. Missing trust,
203
- // wrong bytes and superseded/mismatched receipts cannot turn an unsupported sibling into a veto.
204
- if (matching.length)
205
- blockers.push(...support.filter(isConflict), ...availabilityProblems.filter(isConflict));
206
- const rejection = matching.some(d => d.decision === "reject");
207
- rowClaims.push({ claim: eventRef(claim), obligation: b.obligation,
208
- applicability: rejection ? "unaccepted" : matching.some(d => d.decision === "accept") && local.length === 0 ? "accepted-under-supplied-authority" : "unresolved",
209
- matchedReceiptIds: unique(matching.map(d => d.receiptId)),
210
- problems: rejection ? [problem("TRUSTED_REJECTION", eventReference(claim))] : mergeWorkProblems(local),
211
- });
212
- }
213
- if (trustedDecisions.size > 1)
214
- blockers.push(problem("DECISION_CONFLICT", { type: "revision", ref: binding.obligation }));
215
- const blocked = mergeWorkProblems(blockers);
216
- for (const p of blocked)
217
- if (p.code === "EVENT_CONFLICT" && p.reference?.type === "event") {
218
- const id = p.reference.ref.eventId;
219
- conflicts.push({ kind: "event", id, digests: index.conflictingEvents.filter(e => e.eventId === id).map(e => e.digest), affectedObligations: affected });
220
- }
221
- const finalClaims = rowClaims.map(c => blocked.length && c.applicability !== "superseded" ? { ...c, applicability: "unresolved", problems: blocked } : c);
222
- const accepted = finalClaims.some(c => c.applicability === "accepted-under-supplied-authority");
223
- const rejected = finalClaims.some(c => c.applicability === "unaccepted");
224
- const unresolved = finalClaims.filter(c => c.applicability === "unresolved");
225
- const acceptance = blocked.length ? "unresolved" : accepted ? "accepted-under-supplied-authority" : rejected ? "unaccepted" : unresolved.length ? "unresolved" : "unaccepted";
226
- const obligationProblems = blocked.length ? blocked : accepted ? [] : rejected ?
227
- finalClaims.filter(c => c.applicability === "unaccepted").flatMap(c => c.problems) : unresolved.length ? unresolved.flatMap(c => c.problems) :
228
- [problem("NO_CLAIM", { type: "revision", ref: binding.obligation })];
229
- obligations.push({ binding, acceptance, artifactCoverage, evidenceCoverage, claims: unique(finalClaims.map(c => c.claim)), problems: mergeWorkProblems(obligationProblems) });
230
- claims.push(...finalClaims);
231
- problems.push(...obligationProblems, ...finalClaims.flatMap(c => c.problems));
232
- }
233
- return { obligations: unique(obligations), claims: unique(claims), supersededClaims: claims.filter(c => c.applicability === "superseded").length,
234
- conflicts: mergeWorkConflicts(conflicts), problems: mergeWorkProblems([...problems, ...runtime.problems]),
235
- progress: { accepted: obligations.filter(o => o.acceptance === "accepted-under-supplied-authority").length, total: obligations.length },
236
- };
237
- }
238
- //# sourceMappingURL=projection.js.map
@@ -1,24 +0,0 @@
1
- import { type WorkAcceptanceEvent, type WorkAcceptancePayload, type WorkFrozen, type WorkIngestion, type WorkOccurrenceEvent, type WorkOccurrencePayload, type WorkRevision, type WorkRevisionEvent, type WorkSnapshot, type WorkSnapshotEvent, type WorkProjectionContext, type WorkProjection } from "./types.js";
2
- export * from "./types.js";
3
- export declare function buildWorkRevisionEvent(args: {
4
- eventId: string;
5
- now: Date;
6
- revision: Omit<WorkRevision, "digest">;
7
- }): WorkFrozen<WorkRevisionEvent>;
8
- export declare function buildWorkSnapshotEvent(args: {
9
- eventId: string;
10
- now: Date;
11
- snapshot: Omit<WorkSnapshot, "digest">;
12
- }): WorkFrozen<WorkSnapshotEvent>;
13
- export declare function buildWorkOccurrenceEvent(args: {
14
- eventId: string;
15
- now: Date;
16
- payload: WorkOccurrencePayload;
17
- }): WorkFrozen<WorkOccurrenceEvent>;
18
- export declare function buildWorkAcceptanceEvent(args: {
19
- eventId: string;
20
- now: Date;
21
- payload: WorkAcceptancePayload;
22
- }): WorkFrozen<WorkAcceptanceEvent>;
23
- export declare function parseWorkLedgerText(text: string): WorkFrozen<WorkIngestion>;
24
- export declare function projectWorkLedger(text: string, context?: WorkFrozen<WorkProjectionContext>): WorkFrozen<WorkProjection>;
@@ -1,109 +0,0 @@
1
- // GENERATED from pi-daddy 7c78769c47177b1972b09e1f5c5474ad44cd2cac by scripts/vendor-work-v4-reader.mjs. Do not hand-edit.
2
- import { isDate } from "node:util/types";
3
- import { canonicalWorkJson, copyWorkJson, freezeWork, ownWorkFields, parseWorkJson, WORK_EVENT_BYTES, WORK_TEXT_BYTES, WORK_RECORDS, mergeWorkConflicts, } from "./json.js";
4
- import { validateWorkEvent, validateWorkContext } from "./validation.js";
5
- import { indexWorkLedgerText, indexWorkReceipts, projectWorkAcceptance } from "./projection.js";
6
- import { resolveWorkSnapshotText } from "./snapshot.js";
7
- import { foldWorkOccurrences } from "./occurrences.js";
8
- import { WorkInputError, } from "./types.js";
9
- export * from "./types.js";
10
- function build(args, kind, field) {
11
- const fields = ownWorkFields(args);
12
- const required = ["eventId", "now", field];
13
- if (Object.keys(fields).length !== required.length || required.some(key => !Object.hasOwn(fields, key))) {
14
- throw new WorkInputError("WORK_SCHEMA_INVALID");
15
- }
16
- const now = fields.now.value;
17
- if (!isDate(now) || Object.getPrototypeOf(now) !== Date.prototype || Reflect.ownKeys(now).length !== 0 ||
18
- !Number.isFinite(Date.prototype.getTime.call(now)))
19
- throw new WorkInputError("WORK_SCHEMA_INVALID");
20
- const content = copyWorkJson(fields[field].value);
21
- const candidate = copyWorkJson({ ledgerVersion: 4, event: kind, eventId: fields.eventId.value,
22
- ts: Date.prototype.toISOString.call(now), payload: field === "payload" ? content : { [field]: content } });
23
- const event = validateWorkEvent(candidate, true);
24
- if (Buffer.byteLength(canonicalWorkJson(event), "utf8") > WORK_EVENT_BYTES)
25
- throw new WorkInputError("WORK_LIMIT_EXCEEDED");
26
- return freezeWork(event);
27
- }
28
- export function buildWorkRevisionEvent(args) {
29
- return build(args, "work_revision", "revision");
30
- }
31
- export function buildWorkSnapshotEvent(args) {
32
- return build(args, "work_snapshot", "snapshot");
33
- }
34
- export function buildWorkOccurrenceEvent(args) {
35
- return build(args, "work_occurrence", "payload");
36
- }
37
- export function buildWorkAcceptanceEvent(args) {
38
- return build(args, "work_acceptance", "payload");
39
- }
40
- function* lines(text) {
41
- let start = 0, line = 1;
42
- while (start < text.length) {
43
- const end = text.indexOf("\n", start);
44
- yield { text: text.slice(start, end === -1 ? text.length : end), line: line++ };
45
- if (end === -1)
46
- return;
47
- start = end + 1;
48
- }
49
- }
50
- const blank = (text) => /^[ \t\r]*$/.test(text);
51
- export function parseWorkLedgerText(text) {
52
- const wholeError = (code) => freezeWork({ events: [], errors: [{ line: null, code }], complete: false });
53
- if (typeof text !== "string")
54
- return wholeError("WORK_SCHEMA_INVALID");
55
- if (Buffer.byteLength(text, "utf8") > WORK_TEXT_BYTES)
56
- return wholeError("WORK_LIMIT_EXCEEDED");
57
- let records = 0;
58
- for (const row of lines(text))
59
- if (!blank(row.text) && ++records > WORK_RECORDS)
60
- return wholeError("WORK_LIMIT_EXCEEDED");
61
- const events = [], errors = [];
62
- for (const row of lines(text)) {
63
- if (blank(row.text))
64
- continue;
65
- try {
66
- events.push(validateWorkEvent(parseWorkJson(row.text)));
67
- }
68
- catch (error) {
69
- if (!(error instanceof WorkInputError))
70
- throw error;
71
- errors.push({ line: row.line, code: error.code });
72
- }
73
- }
74
- return freezeWork({ events, errors, complete: errors.length === 0 });
75
- }
76
- export function projectWorkLedger(text, context = { selectedSnapshot: null, authority: null }) {
77
- const index = indexWorkLedgerText(text);
78
- const errors = [...index.ingestion.errors];
79
- let copied = null;
80
- try {
81
- const value = copyWorkJson(context);
82
- validateWorkContext(value);
83
- copied = JSON.parse(canonicalWorkJson(value));
84
- }
85
- catch (error) {
86
- if (!(error instanceof WorkInputError))
87
- throw error;
88
- errors.push({ line: null, code: "WORK_CONTEXT_INVALID" });
89
- }
90
- errors.sort((a, b) => (a.line ?? Infinity) - (b.line ?? Infinity) || (a.code < b.code ? -1 : a.code > b.code ? 1 : 0));
91
- const conflicts = mergeWorkConflicts([
92
- ...index.conflictingEvents.map(ref => ({ kind: "event", id: ref.eventId, digests: [ref.digest], affectedObligations: [] })),
93
- ...indexWorkReceipts(copied?.authority ?? null).conflicts,
94
- ]);
95
- const identities = { selectedSnapshot: copied?.selectedSnapshot?.snapshot ?? null, authoritySnapshot: copied?.authority?.snapshot ?? null };
96
- function empty(scopeState, problems, retained = conflicts) {
97
- return freezeWork({ ...identities, scopeState, progress: null, obligations: [], claims: [], supersededClaims: 0,
98
- conflicts: mergeWorkConflicts([...retained, ...conflicts]), problems, errors, runtime: null });
99
- }
100
- if (errors.length)
101
- return empty("unresolved", [{ code: "INPUT_INCOMPLETE", reference: null, affectedObligations: [] }]);
102
- const structure = resolveWorkSnapshotText(text, copied.selectedSnapshot);
103
- if (structure.scopeState !== "valid")
104
- return empty(structure.scopeState, structure.problems, structure.conflicts);
105
- const runtime = foldWorkOccurrences(index, structure.snapshot);
106
- const acceptance = projectWorkAcceptance(index, structure, copied.authority, runtime);
107
- return freezeWork({ ...identities, scopeState: "valid", ...acceptance, errors, runtime: runtime.runtime });
108
- }
109
- //# sourceMappingURL=reader.js.map
@@ -1,28 +0,0 @@
1
- import { type EventRef, type Identity, type ObligationBinding, type WorkConflict, type WorkDiagnostic, type WorkFrozen, type WorkProblem, type WorkRevision, type WorkSnapshot } from "./types.js";
2
- type Revision = WorkFrozen<WorkRevision>;
3
- type Problem = WorkFrozen<WorkProblem>;
4
- /** Internal shape of WorkProjectionContext.selectedSnapshot, not an authority context. */
5
- interface Selection {
6
- snapshot: Identity;
7
- event: EventRef;
8
- }
9
- /** Internal structural result only. Never a substitute for WorkProjection/acceptance/runtime. */
10
- interface SnapshotResolution {
11
- readonly scopeState: "unselected" | "valid" | "unresolved" | "invalid";
12
- readonly selectedSnapshot: WorkFrozen<Identity> | null;
13
- readonly snapshot: WorkFrozen<WorkSnapshot> | null;
14
- readonly scope: Revision | null;
15
- readonly revisions: readonly Revision[];
16
- readonly obligations: ReadonlyArray<{
17
- readonly binding: WorkFrozen<ObligationBinding>;
18
- readonly revision: Revision;
19
- readonly artifact: Revision | null;
20
- readonly problems: readonly Problem[];
21
- }>;
22
- readonly problems: readonly Problem[];
23
- readonly conflicts: ReadonlyArray<WorkFrozen<WorkConflict>>;
24
- readonly errors: ReadonlyArray<WorkFrozen<WorkDiagnostic>>;
25
- }
26
- /** @internal Real builder/text/index/selector path. No unchecked parsed-object projection entry. */
27
- export declare function resolveWorkSnapshotText(text: string, requested?: WorkFrozen<Selection> | null): SnapshotResolution;
28
- export {};