@akilium/telemetry-collector 0.1.9 → 0.1.11

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 (35) hide show
  1. package/README.md +28 -1
  2. package/bin/akilium-telemetry.mjs +0 -0
  3. package/bin/status-reporter.mjs +1 -1
  4. package/dist/instrumentation/src/client.d.ts +77 -0
  5. package/dist/instrumentation/src/client.js +237 -0
  6. package/dist/instrumentation/src/codex-cli.d.ts +20 -0
  7. package/dist/instrumentation/src/codex-cli.js +92 -0
  8. package/dist/instrumentation/src/codex-execution.d.ts +27 -0
  9. package/dist/instrumentation/src/codex-execution.js +123 -0
  10. package/dist/instrumentation/src/index.d.ts +11 -0
  11. package/dist/instrumentation/src/index.js +11 -0
  12. package/dist/instrumentation/src/persisted-file.d.ts +18 -0
  13. package/dist/instrumentation/src/persisted-file.js +65 -0
  14. package/dist/instrumentation/src/posting-wrappers.d.ts +49 -0
  15. package/dist/instrumentation/src/posting-wrappers.js +76 -0
  16. package/dist/instrumentation/src/wrappers.d.ts +68 -0
  17. package/dist/instrumentation/src/wrappers.js +76 -0
  18. package/dist/integration-contracts/src/action-lineage.d.ts +120 -0
  19. package/dist/integration-contracts/src/action-lineage.js +208 -0
  20. package/dist/integration-contracts/src/activity-classification.d.ts +251 -0
  21. package/dist/integration-contracts/src/activity-classification.js +406 -0
  22. package/dist/integration-contracts/src/ai-execution.d.ts +62 -0
  23. package/dist/integration-contracts/src/ai-execution.js +244 -0
  24. package/dist/integration-contracts/src/ai-session.d.ts +282 -0
  25. package/dist/integration-contracts/src/ai-session.js +192 -0
  26. package/dist/integration-contracts/src/artifact-lineage.d.ts +140 -0
  27. package/dist/integration-contracts/src/artifact-lineage.js +236 -0
  28. package/dist/integration-contracts/src/lineage-validation.d.ts +14 -0
  29. package/dist/integration-contracts/src/lineage-validation.js +64 -0
  30. package/dist/integration-contracts/src/posting-lineage.d.ts +105 -0
  31. package/dist/integration-contracts/src/posting-lineage.js +147 -0
  32. package/lib/execution-capture.mjs +1 -1
  33. package/lib/session-activity.mjs +130 -0
  34. package/lib/session-titles.mjs +13 -1
  35. package/package.json +16 -25
@@ -0,0 +1,406 @@
1
+ import { choice, fail, fields, id, nullable, timestamp, uuid } from "./lineage-validation.js";
2
+ import { parseLineageAuthority } from "./artifact-lineage.js";
3
+ import { ACTION_LINEAGE_CONTRACT_VERSION } from "./action-lineage.js";
4
+ /** Purpose and output evidence are independent, optional capabilities. */
5
+ export const ACTIVITY_CLASSIFICATION_CONTRACT_VERSION = "1.1.0";
6
+ export const ACTIVITY_PURPOSE_CAPABILITY = "activity_purpose_v1";
7
+ export const ACTIVITY_OUTPUT_CAPABILITY = "activity_output_v1";
8
+ export const CODE_CONTRIBUTION_CAPABILITY = "code_contribution_v1";
9
+ export const ACTIVITY_CLASSIFICATION_LIMITS = {
10
+ maxBytes: 65536,
11
+ maxReports: 100,
12
+ maxExamples: 32,
13
+ maxSupportingReferences: 32,
14
+ maxStringLength: 2048,
15
+ };
16
+ const activityPurposeChoices = ["research", "exploration", "learning", "planning", "decision_support", "analysis", "debugging",
17
+ "review", "creation", "transformation", "communication", "operations", "other", "unknown", "mixed", "pending"];
18
+ const outputStatusChoices = ["durable", "ephemeral", "both", "no_output", "unknown"];
19
+ function parseOutputCategory(value) {
20
+ if (value === null)
21
+ return null;
22
+ const c = fields(value, ["categoryId", "categoryVersion", "scope", "tenantId", "teamId", "categoryKey", "name"], "activityOutput.category");
23
+ const scope = choice(c.scope, ["shared", "tenant", "team"], "activityOutput.category.scope");
24
+ const tenantId = nullable(c.tenantId, (v) => uuid(v, "activityOutput.category.tenantId"));
25
+ const teamId = nullable(c.teamId, (v) => uuid(v, "activityOutput.category.teamId"));
26
+ if (!Number.isSafeInteger(c.categoryVersion) || c.categoryVersion < 1 ||
27
+ (scope === "shared" && (tenantId !== null || teamId !== null)) || (scope === "tenant" && (!tenantId || teamId !== null)) ||
28
+ (scope === "team" && (!tenantId || !teamId)) || c.categoryKey !== undefined && (typeof c.categoryKey !== "string" || c.categoryKey.length > 64) ||
29
+ c.name !== undefined && (typeof c.name !== "string" || c.name.length > 200) || (c.categoryKey === undefined) !== (c.name === undefined))
30
+ fail("activityOutput.category");
31
+ return { categoryId: uuid(c.categoryId, "activityOutput.category.categoryId"), categoryVersion: c.categoryVersion,
32
+ scope, tenantId, teamId, ...(c.categoryKey ? { categoryKey: c.categoryKey, name: c.name } : {}) };
33
+ }
34
+ function boundedCount(value, path) {
35
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0 || value > 10_000_000)
36
+ fail(path);
37
+ return value;
38
+ }
39
+ export function parseActivityPurposeOutputAggregate(value) {
40
+ const a = fields(value, ["contractVersion", "asOf", "windowStart", "windowEnd", "unit", "eligibleActionCount",
41
+ "authorizedEligibleActionCount", "artifactSubset", "pendingCount", "coverage", "purposes", "outputs", "outputConflictCount",
42
+ "sources", "flows", "knownCollectionGapIntervals"], "activityOutput.aggregate");
43
+ if (a.contractVersion !== ACTIVITY_CLASSIFICATION_CONTRACT_VERSION || a.unit !== "eligible_action_event_records" ||
44
+ typeof a.artifactSubset !== "boolean" || !Array.isArray(a.purposes) || a.purposes.length > 256 ||
45
+ !Array.isArray(a.outputs) || a.outputs.length > 5 || !Array.isArray(a.sources) || a.sources.length > 20 ||
46
+ !Array.isArray(a.flows) || a.flows.length > 500)
47
+ fail("activityOutput.aggregate.shape");
48
+ const asOf = timestamp(a.asOf, "activityOutput.aggregate.asOf");
49
+ const windowStart = timestamp(a.windowStart, "activityOutput.aggregate.windowStart");
50
+ const windowEnd = timestamp(a.windowEnd, "activityOutput.aggregate.windowEnd");
51
+ if (Date.parse(windowStart) >= Date.parse(windowEnd) || Date.parse(windowEnd) > Date.parse(asOf))
52
+ fail("activityOutput.aggregate.window");
53
+ const purposes = a.purposes.map((value) => {
54
+ const p = fields(value, ["category", "purpose", "count"], "activityOutput.purpose");
55
+ return { category: parseOutputCategory(p.category), purpose: choice(p.purpose, activityPurposeChoices, "activityOutput.purpose.code"),
56
+ count: boundedCount(p.count, "activityOutput.purpose.count") };
57
+ });
58
+ const outputs = a.outputs.map((value) => {
59
+ const o = fields(value, ["status", "count"], "activityOutput.output");
60
+ return { status: choice(o.status, outputStatusChoices, "activityOutput.output.status"),
61
+ count: boundedCount(o.count, "activityOutput.output.count") };
62
+ });
63
+ const sources = a.sources.map((value) => {
64
+ const s = fields(value, ["sourceId", "count"], "activityOutput.source");
65
+ return { sourceId: uuid(s.sourceId, "activityOutput.source.sourceId"), count: boundedCount(s.count, "activityOutput.source.count") };
66
+ });
67
+ const flows = a.flows.map((value) => {
68
+ const f = fields(value, ["sourceId", "purpose", "category", "output", "count"], "activityOutput.flow");
69
+ return { sourceId: uuid(f.sourceId, "activityOutput.flow.sourceId"),
70
+ purpose: choice(f.purpose, activityPurposeChoices, "activityOutput.flow.purpose"), category: parseOutputCategory(f.category),
71
+ output: choice(f.output, outputStatusChoices, "activityOutput.flow.output"), count: boundedCount(f.count, "activityOutput.flow.count") };
72
+ });
73
+ return { contractVersion: ACTIVITY_CLASSIFICATION_CONTRACT_VERSION, asOf, windowStart, windowEnd,
74
+ unit: "eligible_action_event_records", eligibleActionCount: boundedCount(a.eligibleActionCount, "activityOutput.eligible"),
75
+ authorizedEligibleActionCount: boundedCount(a.authorizedEligibleActionCount, "activityOutput.authorizedEligible"),
76
+ artifactSubset: a.artifactSubset, pendingCount: boundedCount(a.pendingCount, "activityOutput.pending"),
77
+ coverage: choice(a.coverage, ["complete", "partial"], "activityOutput.coverage"), purposes, outputs,
78
+ outputConflictCount: boundedCount(a.outputConflictCount, "activityOutput.conflicts"), sources, flows,
79
+ knownCollectionGapIntervals: boundedCount(a.knownCollectionGapIntervals, "activityOutput.gaps") };
80
+ }
81
+ export function parseActivityPurposeOutputBucketPage(value) {
82
+ const p = fields(value, ["context", "items", "continuation"], "activityOutput.bucketPage");
83
+ const c = fields(p.context, ["contractVersion", "scope", "from", "to", "asOf", "evidenceFilter", "artifactSubset"], "activityOutput.bucketContext");
84
+ if (c.contractVersion !== ACTIVITY_CLASSIFICATION_CONTRACT_VERSION || c.scope !== "authorized_slice" || typeof c.artifactSubset !== "boolean" ||
85
+ !Array.isArray(p.items) || p.items.length > 50)
86
+ fail("activityOutput.bucketPage.shape");
87
+ const from = timestamp(c.from, "activityOutput.bucket.from");
88
+ const to = timestamp(c.to, "activityOutput.bucket.to");
89
+ const asOf = timestamp(c.asOf, "activityOutput.bucket.asOf");
90
+ if (Date.parse(from) >= Date.parse(to) || Date.parse(to) > Date.parse(asOf))
91
+ fail("activityOutput.bucket.window");
92
+ const items = p.items.map((value) => {
93
+ const i = fields(value, ["attemptRecordId", "eventRecordId", "sourceId", "occurredAt", "purpose", "category", "output",
94
+ "outputConflict", "assignment"], "activityOutput.bucketItem");
95
+ let assignment = null;
96
+ if (i.assignment !== null) {
97
+ const a = fields(i.assignment, ["assignmentId", "method", "precedence", "qualification", "evidenceReferences", "categoryId",
98
+ "categoryVersion", "contextId", "eventRecordId"], "activityOutput.assignment");
99
+ if (!Array.isArray(a.evidenceReferences) || a.evidenceReferences.length > 32 || typeof a.precedence !== "string" ||
100
+ typeof a.qualification !== "string")
101
+ fail("activityOutput.assignment");
102
+ assignment = { assignmentId: uuid(a.assignmentId, "activityOutput.assignment.id"),
103
+ method: choice(a.method, ["manual", "declared", "inherited", "deterministic", "heuristic", "provider_inferred"], "activityOutput.assignment.method"),
104
+ precedence: a.precedence, qualification: a.qualification,
105
+ evidenceReferences: a.evidenceReferences.map((x) => id(x, "activityOutput.assignment.evidence")),
106
+ categoryId: a.categoryId === null ? null : uuid(a.categoryId, "activityOutput.assignment.categoryId"),
107
+ categoryVersion: a.categoryVersion === null ? null : positiveInteger(a.categoryVersion, "activityOutput.assignment.categoryVersion"),
108
+ contextId: a.contextId === null ? null : id(a.contextId, "activityOutput.assignment.contextId"),
109
+ eventRecordId: uuid(a.eventRecordId, "activityOutput.assignment.eventRecordId") };
110
+ }
111
+ if (typeof i.outputConflict !== "boolean")
112
+ fail("activityOutput.bucketItem.outputConflict");
113
+ return { attemptRecordId: uuid(i.attemptRecordId, "activityOutput.bucketItem.attemptRecordId"),
114
+ eventRecordId: uuid(i.eventRecordId, "activityOutput.bucketItem.eventRecordId"),
115
+ sourceId: uuid(i.sourceId, "activityOutput.bucketItem.sourceId"), occurredAt: timestamp(i.occurredAt, "activityOutput.bucketItem.occurredAt"),
116
+ purpose: choice(i.purpose, activityPurposeChoices, "activityOutput.bucketItem.purpose"),
117
+ category: parseOutputCategory(i.category),
118
+ output: choice(i.output, outputStatusChoices, "activityOutput.bucketItem.output"), outputConflict: i.outputConflict, assignment };
119
+ });
120
+ let continuation = null;
121
+ if (p.continuation !== null) {
122
+ const k = fields(p.continuation, ["occurredAt", "attemptRecordId"], "activityOutput.continuation");
123
+ continuation = { occurredAt: timestamp(k.occurredAt, "activityOutput.continuation.occurredAt"),
124
+ attemptRecordId: uuid(k.attemptRecordId, "activityOutput.continuation.attemptRecordId") };
125
+ }
126
+ return { context: { contractVersion: ACTIVITY_CLASSIFICATION_CONTRACT_VERSION, scope: "authorized_slice", from, to, asOf,
127
+ evidenceFilter: choice(c.evidenceFilter, ["established", "include_inferred", "inferred_only"], "activityOutput.bucket.evidenceFilter"),
128
+ artifactSubset: c.artifactSubset }, items, continuation };
129
+ }
130
+ function boundedText(value, path, max = ACTIVITY_CLASSIFICATION_LIMITS.maxStringLength) {
131
+ if (typeof value !== "string" || value.length === 0 || value.length > max || value.trim() !== value)
132
+ fail(path);
133
+ return value;
134
+ }
135
+ function positiveInteger(value, path) {
136
+ if (!Number.isSafeInteger(value) || value < 1)
137
+ fail(path);
138
+ return value;
139
+ }
140
+ function parseCategoryReference(value, authority) {
141
+ const c = fields(value, ["categoryId", "categoryVersion", "scope", "tenantId", "teamId"], "activity.category");
142
+ const scope = choice(c.scope, ["shared", "tenant", "team"], "activity.category.scope");
143
+ const tenantId = nullable(c.tenantId, (v) => uuid(v, "activity.category.tenantId"));
144
+ const teamId = nullable(c.teamId, (v) => uuid(v, "activity.category.teamId"));
145
+ if (!Number.isSafeInteger(c.categoryVersion) || c.categoryVersion < 1)
146
+ fail("activity.category.categoryVersion");
147
+ if ((scope === "shared" && (tenantId !== null || teamId !== null)) ||
148
+ (scope === "tenant" && (tenantId === null || teamId !== null)) ||
149
+ (scope === "team" && (tenantId === null || teamId === null)))
150
+ fail("activity.category.scope");
151
+ const allowedTeamId = authority?.owningScope.kind === "team" ? authority.owningScope.teamId : null;
152
+ if (authority && (scope === "tenant" && tenantId !== authority.tenantId ||
153
+ scope === "team" && (tenantId !== authority.tenantId || teamId !== allowedTeamId)))
154
+ fail("activity.category.scope");
155
+ return { categoryId: uuid(c.categoryId, "activity.category.categoryId"), categoryVersion: c.categoryVersion,
156
+ scope, tenantId, teamId };
157
+ }
158
+ function parseReferences(value, path) {
159
+ if (!Array.isArray(value) || value.length > ACTIVITY_CLASSIFICATION_LIMITS.maxSupportingReferences)
160
+ fail(path);
161
+ const refs = value.map((entry) => id(entry, path));
162
+ if (new Set(refs).size !== refs.length)
163
+ fail(path);
164
+ return refs;
165
+ }
166
+ function parseTextList(value, path, max) {
167
+ if (!Array.isArray(value) || value.length > max)
168
+ fail(path);
169
+ return value.map((entry) => boundedText(entry, path));
170
+ }
171
+ function parseOwner(value) {
172
+ const o = fields(value, ["kind", "teamId", "projectId"], "activity.owner");
173
+ if (o.kind === "shared") {
174
+ fields(o, ["kind"], "activity.owner");
175
+ return { kind: "shared" };
176
+ }
177
+ if (o.kind === "tenant") {
178
+ fields(o, ["kind"], "activity.owner");
179
+ return { kind: "tenant" };
180
+ }
181
+ if (o.kind === "team") {
182
+ fields(o, ["kind", "teamId"], "activity.owner");
183
+ return { kind: "team", teamId: uuid(o.teamId, "activity.owner.teamId") };
184
+ }
185
+ if (o.kind === "project") {
186
+ fields(o, ["kind", "projectId"], "activity.owner");
187
+ return { kind: "project", projectId: uuid(o.projectId, "activity.owner.projectId") };
188
+ }
189
+ return fail("activity.owner.kind");
190
+ }
191
+ export function parseActivityCategoryVersion(value, authority) {
192
+ const c = fields(value, ["contractVersion", "categoryId", "version", "scope", "tenantId", "teamId", "parent", "name", "definition",
193
+ "inclusionCriteria", "exclusionCriteria", "positiveExamples", "counterExamples", "permittedEvidenceFields", "methods", "semanticRubric", "precedence", "owner"], "activity.categoryVersion");
194
+ if (c.contractVersion !== ACTIVITY_CLASSIFICATION_CONTRACT_VERSION)
195
+ fail("activity.categoryVersion.contractVersion");
196
+ const scope = choice(c.scope, ["shared", "tenant", "team"], "activity.categoryVersion.scope");
197
+ const tenantId = nullable(c.tenantId, (v) => uuid(v, "activity.categoryVersion.tenantId"));
198
+ const teamId = nullable(c.teamId, (v) => uuid(v, "activity.categoryVersion.teamId"));
199
+ if ((scope === "shared" && (tenantId !== null || teamId !== null)) ||
200
+ (scope === "tenant" && (tenantId === null || teamId !== null)) ||
201
+ (scope === "team" && (tenantId === null || teamId === null)))
202
+ fail("activity.categoryVersion.scope");
203
+ if (authority && (tenantId !== null && tenantId !== authority.tenantId || scope === "team" &&
204
+ (authority.owningScope.kind !== "team" || teamId !== authority.owningScope.teamId)))
205
+ fail("activity.categoryVersion.scope");
206
+ if (!Number.isSafeInteger(c.version) || c.version < 1 || !Number.isSafeInteger(c.precedence) ||
207
+ c.precedence < 0 || c.precedence > 1000)
208
+ fail("activity.categoryVersion.version");
209
+ const methods = Array.isArray(c.methods) && c.methods.length > 0 && c.methods.length <= 6
210
+ ? c.methods.map((m) => choice(m, ["declaration", "membership", "deterministic", "heuristic", "semantic", "manual"], "activity.categoryVersion.methods"))
211
+ : fail("activity.categoryVersion.methods");
212
+ const semanticRubric = nullable(c.semanticRubric, (v) => boundedText(v, "activity.categoryVersion.semanticRubric"));
213
+ if (methods.includes("semantic") !== (semanticRubric !== null))
214
+ fail("activity.categoryVersion.semanticRubric");
215
+ const owner = parseOwner(c.owner);
216
+ if ((scope === "shared" && owner.kind !== "shared") || (scope === "tenant" && owner.kind !== "tenant") ||
217
+ (scope === "team" && (owner.kind !== "team" || owner.teamId !== teamId)))
218
+ fail("activity.categoryVersion.owner");
219
+ const categoryId = uuid(c.categoryId, "activity.categoryVersion.categoryId");
220
+ const parent = nullable(c.parent, (v) => parseCategoryReference(v, authority ?? null));
221
+ if (parent && (scope === "shared" || parent.scope === "team" && (parent.tenantId !== tenantId || parent.teamId !== teamId) ||
222
+ parent.scope === "tenant" && parent.tenantId !== tenantId))
223
+ fail("activity.categoryVersion.parent");
224
+ return { contractVersion: ACTIVITY_CLASSIFICATION_CONTRACT_VERSION, categoryId, version: c.version, scope,
225
+ tenantId, teamId, parent,
226
+ name: boundedText(c.name, "activity.categoryVersion.name", 128), definition: boundedText(c.definition, "activity.categoryVersion.definition"),
227
+ inclusionCriteria: parseTextList(c.inclusionCriteria, "activity.categoryVersion.inclusionCriteria", 32),
228
+ exclusionCriteria: parseTextList(c.exclusionCriteria, "activity.categoryVersion.exclusionCriteria", 32),
229
+ positiveExamples: parseTextList(c.positiveExamples, "activity.categoryVersion.positiveExamples", ACTIVITY_CLASSIFICATION_LIMITS.maxExamples),
230
+ counterExamples: parseTextList(c.counterExamples, "activity.categoryVersion.counterExamples", ACTIVITY_CLASSIFICATION_LIMITS.maxExamples),
231
+ permittedEvidenceFields: parseTextList(c.permittedEvidenceFields, "activity.categoryVersion.permittedEvidenceFields", 32),
232
+ methods: methods, semanticRubric, precedence: c.precedence,
233
+ owner: owner.kind === "shared" ? { kind: "shared" } : owner };
234
+ }
235
+ export function parseActivityAssignment(value, authorityValue) {
236
+ const authority = parseLineageAuthority(authorityValue);
237
+ const a = fields(value, ["assignmentId", "tenantId", "owner", "subject", "category", "purpose", "method", "precedence", "qualification", "evidenceReferences", "evidenceRevision", "evaluationGeneration", "recordedAt", "supersedesAssignmentId"], "activity.assignment");
238
+ const owner = parseOwner(a.owner);
239
+ const subject = fields(a.subject, ["sourceId", "actionId", "attemptId", "eventRecordId", "contextId"], "activity.assignment.subject");
240
+ const tenantId = uuid(a.tenantId, "activity.assignment.tenantId");
241
+ if (tenantId !== authority.tenantId || uuid(subject.sourceId, "activity.assignment.subject.sourceId") !== authority.sourceId)
242
+ fail("activity.assignment.scope");
243
+ if (owner.kind === "shared")
244
+ fail("activity.assignment.owner");
245
+ if (a.purpose !== "unknown" && a.purpose !== "mixed" && a.purpose !== "other" && a.category === null)
246
+ fail("activity.assignment.category");
247
+ return { assignmentId: uuid(a.assignmentId, "activity.assignment.assignmentId"), tenantId, owner,
248
+ subject: { sourceId: authority.sourceId, actionId: id(subject.actionId, "activity.assignment.subject.actionId"),
249
+ attemptId: id(subject.attemptId, "activity.assignment.subject.attemptId"),
250
+ eventRecordId: nullable(subject.eventRecordId, (v) => uuid(v, "activity.assignment.subject.eventRecordId")),
251
+ contextId: nullable(subject.contextId, (v) => uuid(v, "activity.assignment.subject.contextId")) },
252
+ category: nullable(a.category, (v) => parseCategoryReference(v, authority)),
253
+ purpose: choice(a.purpose, ["research", "exploration", "learning", "planning", "decision_support", "analysis", "debugging", "review", "creation", "transformation", "communication", "operations", "other", "unknown", "mixed"], "activity.assignment.purpose"),
254
+ method: choice(a.method, ["manual", "declared", "inherited", "deterministic", "heuristic", "provider_inferred"], "activity.assignment.method"),
255
+ precedence: choice(a.precedence, ["manual", "action_declaration", "phase_declaration", "session_declaration", "deterministic", "provider_inferred"], "activity.assignment.precedence"),
256
+ qualification: choice(a.qualification, ["established", "reported", "inferred", "disputed"], "activity.assignment.qualification"),
257
+ evidenceReferences: parseReferences(a.evidenceReferences, "activity.assignment.evidenceReferences"),
258
+ evidenceRevision: positiveInteger(a.evidenceRevision, "activity.assignment.evidenceRevision"),
259
+ evaluationGeneration: positiveInteger(a.evaluationGeneration, "activity.assignment.evaluationGeneration"),
260
+ recordedAt: timestamp(a.recordedAt, "activity.assignment.recordedAt"),
261
+ supersedesAssignmentId: nullable(a.supersedesAssignmentId, (v) => uuid(v, "activity.assignment.supersedesAssignmentId")) };
262
+ }
263
+ function parsePurpose(value, authority) {
264
+ const p = fields(value, ["declarationId", "category", "declaredAt", "evidenceReferences"], "activity.purpose");
265
+ return { declarationId: uuid(p.declarationId, "activity.purpose.declarationId"),
266
+ category: parseCategoryReference(p.category, authority), declaredAt: timestamp(p.declaredAt, "activity.purpose.declaredAt"),
267
+ evidenceReferences: parseReferences(p.evidenceReferences, "activity.purpose.evidenceReferences") };
268
+ }
269
+ function parseMembership(value) {
270
+ const m = fields(value, ["membershipId", "contextId", "contextKind", "actionId", "attemptId", "establishedAt"], "activity.membership");
271
+ return { membershipId: uuid(m.membershipId, "activity.membership.membershipId"), contextId: id(m.contextId, "activity.membership.contextId"),
272
+ contextKind: choice(m.contextKind, ["phase", "session"], "activity.membership.contextKind"),
273
+ actionId: id(m.actionId, "activity.membership.actionId"), attemptId: id(m.attemptId, "activity.membership.attemptId"),
274
+ establishedAt: timestamp(m.establishedAt, "activity.membership.establishedAt") };
275
+ }
276
+ function parseOutput(value) {
277
+ const o = fields(value, ["assertionId", "outputId", "actionId", "attemptId", "kind", "lifetime", "occurredAt", "origin", "qualification", "evidenceReference"], "activity.output");
278
+ return { assertionId: uuid(o.assertionId, "activity.output.assertionId"), outputId: id(o.outputId, "activity.output.outputId"),
279
+ actionId: id(o.actionId, "activity.output.actionId"), attemptId: id(o.attemptId, "activity.output.attemptId"),
280
+ kind: choice(o.kind, ["answer", "draft", "code", "report", "file", "tool_result", "other"], "activity.output.kind"),
281
+ lifetime: choice(o.lifetime, ["session", "transient", "temporary_storage"], "activity.output.lifetime"),
282
+ occurredAt: timestamp(o.occurredAt, "activity.output.occurredAt"),
283
+ origin: choice(o.origin, ["instrumented", "adapter_reported", "reviewed"], "activity.output.origin"),
284
+ qualification: choice(o.qualification, ["established", "reported", "disputed"], "activity.output.qualification"),
285
+ evidenceReference: nullable(o.evidenceReference, (v) => id(v, "activity.output.evidenceReference")) };
286
+ }
287
+ function parseNoOutput(value) {
288
+ const o = fields(value, ["assertionId", "actionId", "attemptId", "occurredAt", "origin", "qualification", "evidenceReference", "supersedesAssertionId"], "activity.noOutput");
289
+ return { assertionId: uuid(o.assertionId, "activity.noOutput.assertionId"), actionId: id(o.actionId, "activity.noOutput.actionId"),
290
+ attemptId: id(o.attemptId, "activity.noOutput.attemptId"), occurredAt: timestamp(o.occurredAt, "activity.noOutput.occurredAt"),
291
+ origin: choice(o.origin, ["instrumented", "adapter_reported", "reviewed"], "activity.noOutput.origin"),
292
+ qualification: choice(o.qualification, ["established", "reported", "disputed"], "activity.noOutput.qualification"),
293
+ evidenceReference: nullable(o.evidenceReference, (v) => id(v, "activity.noOutput.evidenceReference")),
294
+ supersedesAssertionId: nullable(o.supersedesAssertionId, (v) => uuid(v, "activity.noOutput.supersedesAssertionId")) };
295
+ }
296
+ /** Bind payload references to authenticated source and tenant context; never trust payload scope claims. */
297
+ export function parseActivityPurposeReport(value, context) {
298
+ if (!context.capabilities.includes(ACTIVITY_PURPOSE_CAPABILITY) && !context.capabilities.includes(ACTIVITY_OUTPUT_CAPABILITY))
299
+ fail("activity.capabilities");
300
+ const authority = parseLineageAuthority(context.authority);
301
+ const hasNoOutput = !!value && typeof value === "object" && !Array.isArray(value) && "noOutput" in value;
302
+ const r = fields(value, hasNoOutput
303
+ ? ["contractVersion", "reportId", "actionId", "attemptId", "purpose", "membership", "outputs", "noOutput"]
304
+ : ["contractVersion", "reportId", "actionId", "attemptId", "purpose", "membership", "outputs"], "activity.report");
305
+ if (r.contractVersion !== ACTIVITY_CLASSIFICATION_CONTRACT_VERSION)
306
+ fail("activity.contractVersion");
307
+ if (!Array.isArray(r.outputs) || r.outputs.length > ACTIVITY_CLASSIFICATION_LIMITS.maxReports)
308
+ fail("activity.outputs");
309
+ const actionId = id(r.actionId, "activity.actionId");
310
+ const attemptId = id(r.attemptId, "activity.attemptId");
311
+ const purpose = nullable(r.purpose, (v) => parsePurpose(v, authority));
312
+ const membership = nullable(r.membership, parseMembership);
313
+ const outputs = r.outputs.map(parseOutput);
314
+ const noOutput = hasNoOutput ? nullable(r.noOutput, parseNoOutput) : null;
315
+ if ((purpose || membership) && !context.capabilities.includes(ACTIVITY_PURPOSE_CAPABILITY))
316
+ fail("activity.capabilities");
317
+ if ((outputs.length || noOutput) && !context.capabilities.includes(ACTIVITY_OUTPUT_CAPABILITY))
318
+ fail("activity.outputCapability");
319
+ if (membership && (membership.actionId !== actionId || membership.attemptId !== attemptId))
320
+ fail("activity.membership.subject");
321
+ if (outputs.some((o) => o.actionId !== actionId || o.attemptId !== attemptId))
322
+ fail("activity.output.subject");
323
+ if (noOutput && (noOutput.actionId !== actionId || noOutput.attemptId !== attemptId))
324
+ fail("activity.noOutput.subject");
325
+ if (new Set(outputs.map((o) => o.assertionId)).size !== outputs.length)
326
+ fail("activity.output.assertionId");
327
+ return { contractVersion: ACTIVITY_CLASSIFICATION_CONTRACT_VERSION, reportId: uuid(r.reportId, "activity.reportId"),
328
+ actionId, attemptId, purpose, membership, outputs, noOutput };
329
+ }
330
+ export function parseActivityPurposeJson(text, context) {
331
+ if (new TextEncoder().encode(text).byteLength > ACTIVITY_CLASSIFICATION_LIMITS.maxBytes)
332
+ fail("activity.bytes");
333
+ let value;
334
+ try {
335
+ value = JSON.parse(text);
336
+ }
337
+ catch {
338
+ fail("activity.json");
339
+ }
340
+ return parseActivityPurposeReport(value, context);
341
+ }
342
+ export function bindActivityPurposeReport(value, context) {
343
+ const authority = parseLineageAuthority(context.authority);
344
+ const report = parseActivityPurposeReport(value, { authority, capabilities: context.capabilities });
345
+ return {
346
+ authority,
347
+ report,
348
+ reportKey: JSON.stringify([ACTIVITY_CLASSIFICATION_CONTRACT_VERSION, authority.tenantId, authority.sourceId, report.reportId]),
349
+ attemptKey: JSON.stringify([ACTION_LINEAGE_CONTRACT_VERSION, authority.tenantId, authority.sourceId, report.actionId, report.attemptId]),
350
+ };
351
+ }
352
+ /** Parse persisted read contracts without allowing unbounded chart payloads or invented units. */
353
+ export function parseActivityPurposeAggregate(value) {
354
+ const a = fields(value, ["contractVersion", "asOf", "windowStart", "windowEnd", "unit", "eligibleActionCount", "pendingCount", "coverage", "purposes", "outputs"], "activity.aggregate");
355
+ if (a.contractVersion !== ACTIVITY_CLASSIFICATION_CONTRACT_VERSION || a.unit !== "eligible_action_event_records")
356
+ fail("activity.aggregate.contract");
357
+ const asOf = timestamp(a.asOf, "activity.aggregate.asOf");
358
+ const windowStart = timestamp(a.windowStart, "activity.aggregate.windowStart");
359
+ const windowEnd = timestamp(a.windowEnd, "activity.aggregate.windowEnd");
360
+ if (windowStart >= windowEnd || windowEnd > asOf)
361
+ fail("activity.aggregate.window");
362
+ if (!Number.isSafeInteger(a.eligibleActionCount) || a.eligibleActionCount < 0 ||
363
+ !Number.isSafeInteger(a.pendingCount) || a.pendingCount < 0 || a.pendingCount > a.eligibleActionCount)
364
+ fail("activity.aggregate.count");
365
+ if (!Array.isArray(a.purposes) || a.purposes.length > 128 || !Array.isArray(a.outputs) || a.outputs.length > 8)
366
+ fail("activity.aggregate.buckets");
367
+ const purposes = a.purposes.map((entry) => {
368
+ const p = fields(entry, ["category", "purpose", "count"], "activity.aggregate.purpose");
369
+ if (!Number.isSafeInteger(p.count) || p.count < 0)
370
+ fail("activity.aggregate.purpose.count");
371
+ return { category: nullable(p.category, (v) => parseCategoryReference(v, null)),
372
+ purpose: choice(p.purpose, ["research", "exploration", "learning", "planning", "decision_support", "analysis", "debugging", "review", "creation", "transformation", "communication", "operations", "other", "unknown", "mixed", "pending"], "activity.aggregate.purpose.purpose"),
373
+ count: p.count };
374
+ });
375
+ const outputs = a.outputs.map((entry) => {
376
+ const o = fields(entry, ["status", "count"], "activity.aggregate.output");
377
+ if (!Number.isSafeInteger(o.count) || o.count < 0)
378
+ fail("activity.aggregate.output.count");
379
+ return { status: choice(o.status, ["durable", "ephemeral", "both", "no_output", "unknown"], "activity.aggregate.output.status"), count: o.count };
380
+ });
381
+ if (purposes.reduce((n, p) => n + p.count, 0) !== a.eligibleActionCount || outputs.reduce((n, o) => n + o.count, 0) !== a.eligibleActionCount)
382
+ fail("activity.aggregate.conservation");
383
+ return { contractVersion: ACTIVITY_CLASSIFICATION_CONTRACT_VERSION, asOf, windowStart, windowEnd,
384
+ unit: "eligible_action_event_records", eligibleActionCount: a.eligibleActionCount,
385
+ pendingCount: a.pendingCount, coverage: choice(a.coverage, ["complete", "partial", "unavailable"], "activity.aggregate.coverage"), purposes, outputs };
386
+ }
387
+ export function parseActivityClassificationJob(value) {
388
+ const j = fields(value, ["jobId", "tenantId", "owner", "provider", "model", "status", "subjectCount", "requestLimit", "inputTokenLimit", "createdAt"], "activity.job");
389
+ const ownerValue = fields(j.owner, ["kind", "teamId", "projectId"], "activity.job.owner");
390
+ const owner = ownerValue.kind === "tenant"
391
+ ? { kind: "tenant" }
392
+ : ownerValue.kind === "team"
393
+ ? { kind: "team", teamId: uuid(ownerValue.teamId, "activity.job.owner.teamId") }
394
+ : ownerValue.kind === "project"
395
+ ? { kind: "project", projectId: uuid(ownerValue.projectId, "activity.job.owner.projectId") }
396
+ : fail("activity.job.owner.kind");
397
+ if (!Number.isSafeInteger(j.subjectCount) || j.subjectCount < 1 || j.subjectCount > 100 ||
398
+ !Number.isSafeInteger(j.requestLimit) || j.requestLimit < 1 || j.requestLimit > 100 ||
399
+ !Number.isSafeInteger(j.inputTokenLimit) || j.inputTokenLimit < 1 || j.inputTokenLimit > 2000)
400
+ fail("activity.job.bounds");
401
+ return { jobId: uuid(j.jobId, "activity.job.jobId"), tenantId: uuid(j.tenantId, "activity.job.tenantId"), owner,
402
+ provider: choice(j.provider, ["jev", "openai_decisions"], "activity.job.provider"), model: boundedText(j.model, "activity.job.model", 128),
403
+ status: choice(j.status, ["previewed", "queued", "running", "completed", "partial", "failed", "cancelled"], "activity.job.status"),
404
+ subjectCount: j.subjectCount, requestLimit: j.requestLimit, inputTokenLimit: j.inputTokenLimit,
405
+ createdAt: timestamp(j.createdAt, "activity.job.createdAt") };
406
+ }
@@ -0,0 +1,62 @@
1
+ /** Strict, metadata-only execution evidence contract. Numeric usage remains in canonical source facts. */
2
+ export declare const AI_EXECUTION_EVIDENCE_CONTRACT_VERSION: "1.0.0";
3
+ export declare const AI_EXECUTION_EVIDENCE_LIMITS: {
4
+ readonly maxBytes: number;
5
+ readonly maxExecutions: 32;
6
+ readonly maxFactReferencesPerExecution: 32;
7
+ };
8
+ /** Contract fixture mapping only. Runtime mappings require a separately verified adapter version. */
9
+ export declare const AI_EXECUTION_SOURCE_MAPPINGS: {
10
+ readonly "codex-execution-fixture-v1": {
11
+ readonly provider: "codex";
12
+ readonly runtimeVersion: "fixture";
13
+ };
14
+ readonly "codex-execution-cli-0.166.0": {
15
+ readonly provider: "codex";
16
+ readonly runtimeVersion: "0.166.0";
17
+ };
18
+ };
19
+ export type AiExecutionMappingVersion = keyof typeof AI_EXECUTION_SOURCE_MAPPINGS;
20
+ export type AiExecutionKindV1 = "model_call" | "tool_execution" | "agent_execution";
21
+ export type AiExecutionOperationV1 = "model_inference" | "read_file" | "write_file" | "run_tests" | "command_execution" | "tool_other" | "agent_invocation";
22
+ export type AiExecutionStatusV1 = "started" | "succeeded" | "failed" | "cancelled" | "unknown";
23
+ export type AiExecutionFactKindV1 = "event" | "cost_fact" | "provider_metric_fact";
24
+ export interface AiExecutionFactReferenceV1 {
25
+ kind: AiExecutionFactKindV1;
26
+ recordId: string;
27
+ revision: string;
28
+ }
29
+ export interface AiExecutionRecordV1 {
30
+ executionKey: string;
31
+ turnKey?: string;
32
+ parentExecutionKey?: string;
33
+ retryOfExecutionKey?: string;
34
+ traceKey?: string;
35
+ relatedSessionKey?: string;
36
+ relationship?: "delegates_to" | "forks_to";
37
+ kind: AiExecutionKindV1;
38
+ operation: AiExecutionOperationV1;
39
+ status: AiExecutionStatusV1;
40
+ startedAt?: string;
41
+ endedAt?: string;
42
+ occurredAt?: string;
43
+ factReferences: AiExecutionFactReferenceV1[];
44
+ }
45
+ export interface AiExecutionEvidencePacketV1 {
46
+ contractVersion: typeof AI_EXECUTION_EVIDENCE_CONTRACT_VERSION;
47
+ reportId: string;
48
+ mappingVersion: AiExecutionMappingVersion;
49
+ namespace: string;
50
+ protectedSessionKey: string;
51
+ executions: AiExecutionRecordV1[];
52
+ predecessorReportId?: string;
53
+ correctionReason?: "source_correction" | "binding_correction" | "timing_correction";
54
+ }
55
+ export declare class AiExecutionContractError extends Error {
56
+ readonly problems: readonly string[];
57
+ constructor(problems: readonly string[]);
58
+ }
59
+ /** Parse a closed packet and enforce source mapping, membership, correction and timing semantics. */
60
+ export declare function parseAiExecutionEvidencePacket(input: unknown): AiExecutionEvidencePacketV1;
61
+ /** Enforce the UTF-8 wire limit before parsing, then apply closed structural validation. */
62
+ export declare function parseAiExecutionEvidenceBody(body: string): AiExecutionEvidencePacketV1;