@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.
- package/README.md +28 -1
- package/bin/akilium-telemetry.mjs +0 -0
- package/bin/status-reporter.mjs +1 -1
- package/dist/instrumentation/src/client.d.ts +77 -0
- package/dist/instrumentation/src/client.js +237 -0
- package/dist/instrumentation/src/codex-cli.d.ts +20 -0
- package/dist/instrumentation/src/codex-cli.js +92 -0
- package/dist/instrumentation/src/codex-execution.d.ts +27 -0
- package/dist/instrumentation/src/codex-execution.js +123 -0
- package/dist/instrumentation/src/index.d.ts +11 -0
- package/dist/instrumentation/src/index.js +11 -0
- package/dist/instrumentation/src/persisted-file.d.ts +18 -0
- package/dist/instrumentation/src/persisted-file.js +65 -0
- package/dist/instrumentation/src/posting-wrappers.d.ts +49 -0
- package/dist/instrumentation/src/posting-wrappers.js +76 -0
- package/dist/instrumentation/src/wrappers.d.ts +68 -0
- package/dist/instrumentation/src/wrappers.js +76 -0
- package/dist/integration-contracts/src/action-lineage.d.ts +120 -0
- package/dist/integration-contracts/src/action-lineage.js +208 -0
- package/dist/integration-contracts/src/activity-classification.d.ts +251 -0
- package/dist/integration-contracts/src/activity-classification.js +406 -0
- package/dist/integration-contracts/src/ai-execution.d.ts +62 -0
- package/dist/integration-contracts/src/ai-execution.js +244 -0
- package/dist/integration-contracts/src/ai-session.d.ts +282 -0
- package/dist/integration-contracts/src/ai-session.js +192 -0
- package/dist/integration-contracts/src/artifact-lineage.d.ts +140 -0
- package/dist/integration-contracts/src/artifact-lineage.js +236 -0
- package/dist/integration-contracts/src/lineage-validation.d.ts +14 -0
- package/dist/integration-contracts/src/lineage-validation.js +64 -0
- package/dist/integration-contracts/src/posting-lineage.d.ts +105 -0
- package/dist/integration-contracts/src/posting-lineage.js +147 -0
- package/lib/execution-capture.mjs +1 -1
- package/lib/session-activity.mjs +130 -0
- package/lib/session-titles.mjs +13 -1
- package/package.json +16 -25
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type LineageAuthorityV1 } from "./artifact-lineage.ts";
|
|
2
|
+
/** Posting contracts are a new negotiated major slice; v1.0/v1.1 artifact parsers stay strict. */
|
|
3
|
+
export declare const POSTING_LINEAGE_CONTRACT_VERSION: "1.2.0";
|
|
4
|
+
export declare const POSTING_LINEAGE_CAPABILITY: "posting_lineage_v1";
|
|
5
|
+
export type PostingKindV1_2 = "linear_comment" | "github_comment" | "slack_message";
|
|
6
|
+
export type PostingIdentityV1_2 = {
|
|
7
|
+
kind: "linear_comment";
|
|
8
|
+
workspaceId: string;
|
|
9
|
+
commentId: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "github_comment";
|
|
12
|
+
repositoryId: string;
|
|
13
|
+
family: "conversation" | "inline_review";
|
|
14
|
+
commentId: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: "slack_message";
|
|
17
|
+
workspaceId: string;
|
|
18
|
+
channelId: string;
|
|
19
|
+
messageId: string;
|
|
20
|
+
};
|
|
21
|
+
/** Parent/thread references are context, deliberately excluded from canonical posting identity. */
|
|
22
|
+
export type PostingParentContextV1_2 = {
|
|
23
|
+
kind: "linear_issue";
|
|
24
|
+
issueId: string;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "github_issue" | "github_pull_request";
|
|
27
|
+
repositoryId: string;
|
|
28
|
+
number: string;
|
|
29
|
+
} | {
|
|
30
|
+
kind: "github_review_thread";
|
|
31
|
+
repositoryId: string;
|
|
32
|
+
pullRequestNumber: string;
|
|
33
|
+
threadId: string | null;
|
|
34
|
+
} | {
|
|
35
|
+
kind: "slack_thread";
|
|
36
|
+
channelId: string;
|
|
37
|
+
parentMessageId: string;
|
|
38
|
+
};
|
|
39
|
+
export interface PostingPresentationV1_2 {
|
|
40
|
+
sourceContext: string | null;
|
|
41
|
+
parentReference: string | null;
|
|
42
|
+
permalink: string | null;
|
|
43
|
+
}
|
|
44
|
+
export interface PostingObservationV1_2 {
|
|
45
|
+
contractVersion: typeof POSTING_LINEAGE_CONTRACT_VERSION;
|
|
46
|
+
observationId: string;
|
|
47
|
+
identity: PostingIdentityV1_2;
|
|
48
|
+
parent: PostingParentContextV1_2 | null;
|
|
49
|
+
operation: "created" | "modified" | "deleted";
|
|
50
|
+
occurredAt: string | null;
|
|
51
|
+
recordedAt: string;
|
|
52
|
+
}
|
|
53
|
+
export interface PostingActionResultV1_2 {
|
|
54
|
+
contractVersion: typeof POSTING_LINEAGE_CONTRACT_VERSION;
|
|
55
|
+
actionId: string;
|
|
56
|
+
attemptId: string;
|
|
57
|
+
resultReferenceId: string;
|
|
58
|
+
identity: PostingIdentityV1_2;
|
|
59
|
+
parent: PostingParentContextV1_2 | null;
|
|
60
|
+
relationship: "created" | "modified" | "referenced";
|
|
61
|
+
confirmation: "provider_response" | "provider_lookup";
|
|
62
|
+
confirmedAt: string;
|
|
63
|
+
}
|
|
64
|
+
export interface PostingActionEnvelopeV1_2 {
|
|
65
|
+
contractVersion: typeof POSTING_LINEAGE_CONTRACT_VERSION;
|
|
66
|
+
reportId: string;
|
|
67
|
+
actionId: string;
|
|
68
|
+
attemptId: string;
|
|
69
|
+
phase: "artifact_result";
|
|
70
|
+
executionStatus: "succeeded" | "failed" | "cancelled" | "unknown";
|
|
71
|
+
startedAt: string | null;
|
|
72
|
+
completedAt: string | null;
|
|
73
|
+
occurredAt: string | null;
|
|
74
|
+
results: Omit<PostingActionResultV1_2, "contractVersion" | "actionId" | "attemptId">[];
|
|
75
|
+
}
|
|
76
|
+
export interface BoundPostingActionEnvelopeV1_2 {
|
|
77
|
+
authority: LineageAuthorityV1;
|
|
78
|
+
envelope: PostingActionEnvelopeV1_2;
|
|
79
|
+
reportKey: string;
|
|
80
|
+
attemptKey: string;
|
|
81
|
+
}
|
|
82
|
+
export interface PostingReadItemV1_2 {
|
|
83
|
+
contractVersion: typeof POSTING_LINEAGE_CONTRACT_VERSION;
|
|
84
|
+
artifactId: string;
|
|
85
|
+
kind: PostingKindV1_2;
|
|
86
|
+
reference: string;
|
|
87
|
+
relationship: "created" | "modified" | "referenced";
|
|
88
|
+
qualification: "instrumented" | "source_confirmed" | "reviewed";
|
|
89
|
+
parent: PostingParentContextV1_2 | null;
|
|
90
|
+
presentation: PostingPresentationV1_2;
|
|
91
|
+
lifecycle: "active" | "deleted" | "unknown";
|
|
92
|
+
}
|
|
93
|
+
export declare function parsePostingIdentityV1_2(value: unknown): PostingIdentityV1_2;
|
|
94
|
+
export declare function parsePostingParentContextV1_2(value: unknown): PostingParentContextV1_2 | null;
|
|
95
|
+
/** Collision-free key; parent labels/IDs and mutable presentation never affect identity. */
|
|
96
|
+
export declare function postingIdentityKeyV1_2(identity: PostingIdentityV1_2): string;
|
|
97
|
+
export declare function parsePostingObservationV1_2(value: unknown): PostingObservationV1_2;
|
|
98
|
+
export declare function parsePostingPresentationV1_2(value: unknown, approvedOrigins?: readonly string[]): PostingPresentationV1_2;
|
|
99
|
+
export declare function parsePostingActionResultV1_2(value: unknown): PostingActionResultV1_2;
|
|
100
|
+
export declare function parsePostingActionEnvelopeV1_2(value: unknown): PostingActionEnvelopeV1_2;
|
|
101
|
+
export declare function bindPostingActionEnvelopeV1_2(value: unknown, context: {
|
|
102
|
+
authority: unknown;
|
|
103
|
+
capabilities: readonly string[];
|
|
104
|
+
}): BoundPostingActionEnvelopeV1_2;
|
|
105
|
+
export declare function parsePostingReadItemV1_2(value: unknown, approvedOrigins?: readonly string[]): PostingReadItemV1_2;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { parseLineageAuthority } from "./artifact-lineage.js";
|
|
2
|
+
import { choice, fail, fields, nullable, timestamp, uuid } from "./lineage-validation.js";
|
|
3
|
+
/** Posting contracts are a new negotiated major slice; v1.0/v1.1 artifact parsers stay strict. */
|
|
4
|
+
export const POSTING_LINEAGE_CONTRACT_VERSION = "1.2.0";
|
|
5
|
+
export const POSTING_LINEAGE_CAPABILITY = "posting_lineage_v1";
|
|
6
|
+
const bounded = (value, max, path) => {
|
|
7
|
+
if (value === null)
|
|
8
|
+
return null;
|
|
9
|
+
if (typeof value !== "string" || value.length === 0 || value.length > max || value.trim() !== value)
|
|
10
|
+
fail(path);
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
const providerId = (value, path) => {
|
|
14
|
+
// Provider identifiers remain opaque strings: no numeric coercion or leading-zero loss.
|
|
15
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(value))
|
|
16
|
+
fail(path);
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
export function parsePostingIdentityV1_2(value) {
|
|
20
|
+
const root = fields(value, ["kind", "workspaceId", "commentId", "repositoryId", "family", "channelId", "messageId"], "posting.identity");
|
|
21
|
+
const kind = choice(root.kind, ["linear_comment", "github_comment", "slack_message"], "posting.identity.kind");
|
|
22
|
+
if (kind === "linear_comment") {
|
|
23
|
+
const item = fields(value, ["kind", "workspaceId", "commentId"], "posting.identity");
|
|
24
|
+
return { kind, workspaceId: uuid(item.workspaceId, "posting.identity.workspaceId"), commentId: providerId(item.commentId, "posting.identity.commentId") };
|
|
25
|
+
}
|
|
26
|
+
if (kind === "github_comment") {
|
|
27
|
+
const item = fields(value, ["kind", "repositoryId", "family", "commentId"], "posting.identity");
|
|
28
|
+
if (typeof item.repositoryId !== "string" || !/^[1-9][0-9]{0,29}$/.test(item.repositoryId))
|
|
29
|
+
fail("posting.identity.repositoryId");
|
|
30
|
+
return { kind, repositoryId: item.repositoryId, family: choice(item.family, ["conversation", "inline_review"], "posting.identity.family"), commentId: providerId(item.commentId, "posting.identity.commentId") };
|
|
31
|
+
}
|
|
32
|
+
const item = fields(value, ["kind", "workspaceId", "channelId", "messageId"], "posting.identity");
|
|
33
|
+
return { kind, workspaceId: providerId(item.workspaceId, "posting.identity.workspaceId"), channelId: providerId(item.channelId, "posting.identity.channelId"), messageId: providerId(item.messageId, "posting.identity.messageId") };
|
|
34
|
+
}
|
|
35
|
+
export function parsePostingParentContextV1_2(value) {
|
|
36
|
+
if (value === null)
|
|
37
|
+
return null;
|
|
38
|
+
const root = fields(value, ["kind", "issueId", "repositoryId", "number", "pullRequestNumber", "threadId", "channelId", "parentMessageId"], "posting.parent");
|
|
39
|
+
const kind = choice(root.kind, ["linear_issue", "github_issue", "github_pull_request", "github_review_thread", "slack_thread"], "posting.parent.kind");
|
|
40
|
+
if (kind === "linear_issue") {
|
|
41
|
+
const item = fields(value, ["kind", "issueId"], "posting.parent");
|
|
42
|
+
return { kind, issueId: providerId(item.issueId, "posting.parent.issueId") };
|
|
43
|
+
}
|
|
44
|
+
if (kind === "github_issue" || kind === "github_pull_request") {
|
|
45
|
+
const item = fields(value, ["kind", "repositoryId", "number"], "posting.parent");
|
|
46
|
+
if (typeof item.repositoryId !== "string" || !/^[1-9][0-9]{0,29}$/.test(item.repositoryId))
|
|
47
|
+
fail("posting.parent.repositoryId");
|
|
48
|
+
return { kind, repositoryId: item.repositoryId, number: providerId(item.number, "posting.parent.number") };
|
|
49
|
+
}
|
|
50
|
+
if (kind === "github_review_thread") {
|
|
51
|
+
const item = fields(value, ["kind", "repositoryId", "pullRequestNumber", "threadId"], "posting.parent");
|
|
52
|
+
if (typeof item.repositoryId !== "string" || !/^[1-9][0-9]{0,29}$/.test(item.repositoryId))
|
|
53
|
+
fail("posting.parent.repositoryId");
|
|
54
|
+
return { kind, repositoryId: item.repositoryId, pullRequestNumber: providerId(item.pullRequestNumber, "posting.parent.pullRequestNumber"), threadId: nullable(item.threadId, (v) => providerId(v, "posting.parent.threadId")) };
|
|
55
|
+
}
|
|
56
|
+
const item = fields(value, ["kind", "channelId", "parentMessageId"], "posting.parent");
|
|
57
|
+
return { kind, channelId: providerId(item.channelId, "posting.parent.channelId"), parentMessageId: providerId(item.parentMessageId, "posting.parent.parentMessageId") };
|
|
58
|
+
}
|
|
59
|
+
/** Collision-free key; parent labels/IDs and mutable presentation never affect identity. */
|
|
60
|
+
export function postingIdentityKeyV1_2(identity) {
|
|
61
|
+
switch (identity.kind) {
|
|
62
|
+
case "linear_comment": return JSON.stringify([POSTING_LINEAGE_CONTRACT_VERSION, identity.kind, identity.workspaceId, identity.commentId]);
|
|
63
|
+
case "github_comment": return JSON.stringify([POSTING_LINEAGE_CONTRACT_VERSION, identity.kind, identity.repositoryId, identity.family, identity.commentId]);
|
|
64
|
+
case "slack_message": return JSON.stringify([POSTING_LINEAGE_CONTRACT_VERSION, identity.kind, identity.workspaceId, identity.channelId, identity.messageId]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function parsePostingObservationV1_2(value) {
|
|
68
|
+
const root = fields(value, ["contractVersion", "observationId", "identity", "parent", "operation", "occurredAt", "recordedAt"], "posting.observation");
|
|
69
|
+
if (root.contractVersion !== POSTING_LINEAGE_CONTRACT_VERSION)
|
|
70
|
+
fail("posting.observation.contractVersion");
|
|
71
|
+
return { contractVersion: POSTING_LINEAGE_CONTRACT_VERSION, observationId: uuid(root.observationId, "posting.observation.observationId"),
|
|
72
|
+
identity: parsePostingIdentityV1_2(root.identity), parent: parsePostingParentContextV1_2(root.parent),
|
|
73
|
+
operation: choice(root.operation, ["created", "modified", "deleted"], "posting.observation.operation"),
|
|
74
|
+
occurredAt: nullable(root.occurredAt, (v) => timestamp(v, "posting.observation.occurredAt")), recordedAt: timestamp(root.recordedAt, "posting.observation.recordedAt") };
|
|
75
|
+
}
|
|
76
|
+
export function parsePostingPresentationV1_2(value, approvedOrigins = []) {
|
|
77
|
+
const root = fields(value, ["sourceContext", "parentReference", "permalink"], "posting.presentation");
|
|
78
|
+
const permalink = bounded(root.permalink, 1024, "posting.presentation.permalink");
|
|
79
|
+
if (permalink !== null) {
|
|
80
|
+
let url;
|
|
81
|
+
try {
|
|
82
|
+
url = new URL(permalink);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
fail("posting.presentation.permalink");
|
|
86
|
+
}
|
|
87
|
+
if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash || !approvedOrigins.includes(url.origin))
|
|
88
|
+
fail("posting.presentation.permalink");
|
|
89
|
+
}
|
|
90
|
+
return { sourceContext: bounded(root.sourceContext, 256, "posting.presentation.sourceContext"), parentReference: bounded(root.parentReference, 512, "posting.presentation.parentReference"), permalink };
|
|
91
|
+
}
|
|
92
|
+
export function parsePostingActionResultV1_2(value) {
|
|
93
|
+
const root = fields(value, ["contractVersion", "actionId", "attemptId", "resultReferenceId", "identity", "parent", "relationship", "confirmation", "confirmedAt"], "posting.actionResult");
|
|
94
|
+
if (root.contractVersion !== POSTING_LINEAGE_CONTRACT_VERSION)
|
|
95
|
+
fail("posting.actionResult.contractVersion");
|
|
96
|
+
return { contractVersion: POSTING_LINEAGE_CONTRACT_VERSION, actionId: providerId(root.actionId, "posting.actionResult.actionId"),
|
|
97
|
+
attemptId: providerId(root.attemptId, "posting.actionResult.attemptId"), resultReferenceId: providerId(root.resultReferenceId, "posting.actionResult.resultReferenceId"),
|
|
98
|
+
identity: parsePostingIdentityV1_2(root.identity), parent: parsePostingParentContextV1_2(root.parent),
|
|
99
|
+
relationship: choice(root.relationship, ["created", "modified", "referenced"], "posting.actionResult.relationship"),
|
|
100
|
+
confirmation: choice(root.confirmation, ["provider_response", "provider_lookup"], "posting.actionResult.confirmation"), confirmedAt: timestamp(root.confirmedAt, "posting.actionResult.confirmedAt") };
|
|
101
|
+
}
|
|
102
|
+
export function parsePostingActionEnvelopeV1_2(value) {
|
|
103
|
+
const root = fields(value, ["contractVersion", "reportId", "actionId", "attemptId", "phase", "executionStatus", "startedAt", "completedAt", "occurredAt", "results"], "posting.action");
|
|
104
|
+
if (root.contractVersion !== POSTING_LINEAGE_CONTRACT_VERSION || root.phase !== "artifact_result" || !Array.isArray(root.results) || root.results.length < 1 || root.results.length > 32)
|
|
105
|
+
fail("posting.action.contractVersion");
|
|
106
|
+
const actionId = providerId(root.actionId, "posting.action.actionId");
|
|
107
|
+
const attemptId = providerId(root.attemptId, "posting.action.attemptId");
|
|
108
|
+
const startedAt = nullable(root.startedAt, (v) => timestamp(v, "posting.action.startedAt"));
|
|
109
|
+
const completedAt = nullable(root.completedAt, (v) => timestamp(v, "posting.action.completedAt"));
|
|
110
|
+
const occurredAt = nullable(root.occurredAt, (v) => timestamp(v, "posting.action.occurredAt"));
|
|
111
|
+
if (startedAt !== null && completedAt !== null && startedAt > completedAt)
|
|
112
|
+
fail("posting.action.completedAt");
|
|
113
|
+
const refs = new Set();
|
|
114
|
+
const results = root.results.map((raw) => {
|
|
115
|
+
const item = fields(raw, ["resultReferenceId", "identity", "parent", "relationship", "confirmation", "confirmedAt"], "posting.action.result");
|
|
116
|
+
const resultReferenceId = providerId(item.resultReferenceId, "posting.action.result.resultReferenceId");
|
|
117
|
+
if (refs.has(resultReferenceId))
|
|
118
|
+
fail("posting.action.result.resultReferenceId");
|
|
119
|
+
refs.add(resultReferenceId);
|
|
120
|
+
return { resultReferenceId, identity: parsePostingIdentityV1_2(item.identity), parent: parsePostingParentContextV1_2(item.parent),
|
|
121
|
+
relationship: choice(item.relationship, ["created", "modified", "referenced"], "posting.action.result.relationship"),
|
|
122
|
+
confirmation: choice(item.confirmation, ["provider_response", "provider_lookup"], "posting.action.result.confirmation"),
|
|
123
|
+
confirmedAt: timestamp(item.confirmedAt, "posting.action.result.confirmedAt") };
|
|
124
|
+
});
|
|
125
|
+
return { contractVersion: POSTING_LINEAGE_CONTRACT_VERSION, reportId: uuid(root.reportId, "posting.action.reportId"), actionId, attemptId,
|
|
126
|
+
phase: "artifact_result", executionStatus: choice(root.executionStatus, ["succeeded", "failed", "cancelled", "unknown"], "posting.action.executionStatus"),
|
|
127
|
+
startedAt, completedAt, occurredAt, results };
|
|
128
|
+
}
|
|
129
|
+
export function bindPostingActionEnvelopeV1_2(value, context) {
|
|
130
|
+
if (!context.capabilities.includes("artifact_lineage_v1") || !context.capabilities.includes(POSTING_LINEAGE_CAPABILITY))
|
|
131
|
+
fail("posting.authority.capabilities");
|
|
132
|
+
const authority = parseLineageAuthority(context.authority);
|
|
133
|
+
const envelope = parsePostingActionEnvelopeV1_2(value);
|
|
134
|
+
return { authority, envelope, reportKey: JSON.stringify([POSTING_LINEAGE_CONTRACT_VERSION, authority.tenantId, authority.sourceId, envelope.reportId]),
|
|
135
|
+
attemptKey: JSON.stringify([POSTING_LINEAGE_CONTRACT_VERSION, authority.tenantId, authority.sourceId, envelope.actionId, envelope.attemptId]) };
|
|
136
|
+
}
|
|
137
|
+
export function parsePostingReadItemV1_2(value, approvedOrigins = []) {
|
|
138
|
+
const root = fields(value, ["contractVersion", "artifactId", "kind", "reference", "relationship", "qualification", "parent", "presentation", "lifecycle"], "posting.readItem");
|
|
139
|
+
if (root.contractVersion !== POSTING_LINEAGE_CONTRACT_VERSION)
|
|
140
|
+
fail("posting.readItem.contractVersion");
|
|
141
|
+
return { contractVersion: POSTING_LINEAGE_CONTRACT_VERSION, artifactId: uuid(root.artifactId, "posting.readItem.artifactId"),
|
|
142
|
+
kind: choice(root.kind, ["linear_comment", "github_comment", "slack_message"], "posting.readItem.kind"), reference: providerId(root.reference, "posting.readItem.reference"),
|
|
143
|
+
relationship: choice(root.relationship, ["created", "modified", "referenced"], "posting.readItem.relationship"),
|
|
144
|
+
qualification: choice(root.qualification, ["instrumented", "source_confirmed", "reviewed"], "posting.readItem.qualification"),
|
|
145
|
+
parent: parsePostingParentContextV1_2(root.parent), presentation: parsePostingPresentationV1_2(root.presentation, approvedOrigins),
|
|
146
|
+
lifecycle: choice(root.lifecycle, ["active", "deleted", "unknown"], "posting.readItem.lifecycle") };
|
|
147
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StringDecoder } from "node:string_decoder";
|
|
2
2
|
import { once } from "node:events";
|
|
3
|
-
import { createAiExecutionReporter, captureCodexExecutionJsonl } from "
|
|
3
|
+
import { createAiExecutionReporter, captureCodexExecutionJsonl } from "../dist/instrumentation/src/index.js";
|
|
4
4
|
|
|
5
5
|
/** Stream Codex JSONL through unchanged while forwarding only its allowlisted execution metadata. */
|
|
6
6
|
export async function captureExecutionJsonl({ input, output, sourceVersion, endpoint, token, fetch }) {
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createReadStream, existsSync, lstatSync, readdirSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { join, resolve, relative, sep } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const hash = value => createHash('sha256').update(value).digest('hex');
|
|
6
|
+
const sessionKey = (source, id) => hash(`sha256:${hash(`${source}:${id}`)}`);
|
|
7
|
+
const idPattern = /^[A-Za-z0-9_-]{1,128}$/;
|
|
8
|
+
const savedName = value => typeof value === 'string' && value.trim().length > 0 && value.trim().length <= 100 && !/[\u0000-\u001f\u007f]/.test(value) ? value.trim() : null;
|
|
9
|
+
const kindOf = source => ({ user: 'work', guardian_review: 'guardian_review', subagent: 'subagent' })[source] ?? 'unknown';
|
|
10
|
+
|
|
11
|
+
async function* boundedLines(file, budget, maximumLine = 1_048_576) {
|
|
12
|
+
const stat = lstatSync(file);
|
|
13
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > budget.remaining) return;
|
|
14
|
+
budget.remaining -= stat.size;
|
|
15
|
+
// Read chunks rather than readline: malformed giant lines must not allocate an unbounded buffer.
|
|
16
|
+
const stream = createReadStream(file, { encoding: 'utf8', highWaterMark: 16_384 });
|
|
17
|
+
let pending = '', oversized = false;
|
|
18
|
+
try {
|
|
19
|
+
for await (const chunk of stream) {
|
|
20
|
+
for (const [index, part] of chunk.split('\n').entries()) {
|
|
21
|
+
if (index) { if (!oversized) yield pending; pending = ''; oversized = false; }
|
|
22
|
+
if (!oversized) {
|
|
23
|
+
pending += part;
|
|
24
|
+
if (Buffer.byteLength(pending) > maximumLine) { pending = ''; oversized = true; }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (pending && !oversized) yield pending;
|
|
29
|
+
} finally { stream.destroy(); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Only the first metadata record; never iterate a rollout's conversation records. */
|
|
33
|
+
async function runtimeHeader(file, codexHome, expectedThreadId) {
|
|
34
|
+
if (typeof file !== 'string' || !existsSync(file)) return null;
|
|
35
|
+
const root = realpathSync(codexHome), candidate = resolve(root, relative(resolve(codexHome), resolve(file)));
|
|
36
|
+
if (![join(root, 'sessions') + sep, join(root, 'archived_sessions') + sep].some(prefix => candidate.startsWith(prefix)) ||
|
|
37
|
+
realpathSync(file) !== candidate || lstatSync(file).isSymbolicLink()) return null;
|
|
38
|
+
// The file can be large; only the first bounded line is consumed.
|
|
39
|
+
const stream = createReadStream(file, { encoding: 'utf8', highWaterMark: 4096 });
|
|
40
|
+
let line = '';
|
|
41
|
+
try {
|
|
42
|
+
for await (const chunk of stream) {
|
|
43
|
+
const newline = chunk.indexOf('\n');
|
|
44
|
+
line += newline < 0 ? chunk : chunk.slice(0, newline);
|
|
45
|
+
if (Buffer.byteLength(line) > 131_072) return null;
|
|
46
|
+
if (newline >= 0) break;
|
|
47
|
+
}
|
|
48
|
+
const entry = JSON.parse(line);
|
|
49
|
+
return entry.type === 'session_meta' && entry.payload && typeof entry.payload === 'object' && entry.payload.id === expectedThreadId ? entry.payload : null;
|
|
50
|
+
} catch { return null; } finally { stream.destroy(); }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function readSessionActivity(codexHome, archive, sourceId, targets) {
|
|
54
|
+
const wanted = new Set(targets), found = new Map();
|
|
55
|
+
if (wanted.size > 200) throw new Error('Too many activity targets');
|
|
56
|
+
// Known local schema only; unsupported versions remain unknown and do not disrupt usage collection.
|
|
57
|
+
const file = join(codexHome, 'state_5.sqlite');
|
|
58
|
+
if (existsSync(file) && lstatSync(file).isFile() && !lstatSync(file).isSymbolicLink() && lstatSync(file).size <= 512 * 1024 * 1024) {
|
|
59
|
+
let db;
|
|
60
|
+
try {
|
|
61
|
+
const { DatabaseSync } = await import('node:sqlite');
|
|
62
|
+
db = new DatabaseSync(file, { readOnly: true });
|
|
63
|
+
db.exec('PRAGMA query_only=ON; PRAGMA busy_timeout=250;');
|
|
64
|
+
const rows = db.prepare('SELECT id, thread_source, source, agent_nickname, updated_at_ms, updated_at, rollout_path FROM threads ORDER BY updated_at DESC LIMIT 50000').all();
|
|
65
|
+
for (const row of rows) {
|
|
66
|
+
if (typeof row.id !== 'string' || !idPattern.test(row.id)) continue;
|
|
67
|
+
const key = sessionKey(sourceId, row.id);
|
|
68
|
+
if (!wanted.has(key)) continue;
|
|
69
|
+
let source; try { source = JSON.parse(row.source); } catch { source = null; }
|
|
70
|
+
const spawn = source?.subagent?.thread_spawn;
|
|
71
|
+
const kind = kindOf(row.thread_source);
|
|
72
|
+
let parent = spawn?.parent_thread_id;
|
|
73
|
+
// Guardian parentage is in session_meta, not the normal spawn-edge catalog.
|
|
74
|
+
if (!parent && kind === 'guardian_review') parent = (await runtimeHeader(row.rollout_path, codexHome, row.id))?.parent_thread_id;
|
|
75
|
+
const millis = row.updated_at_ms ?? row.updated_at * 1000;
|
|
76
|
+
if (!Number.isFinite(millis) || millis <= 0) continue;
|
|
77
|
+
found.set(key, { sessionKeyHash: key, activityKind: kind,
|
|
78
|
+
parentSessionKeyHash: typeof parent === 'string' && idPattern.test(parent) && parent !== row.id ? sessionKey(sourceId, parent) : null,
|
|
79
|
+
agentName: kind === 'subagent' ? savedName(row.agent_nickname ?? spawn?.agent_nickname) : null,
|
|
80
|
+
sourceUpdatedAt: new Date(millis).toISOString(), warmupEventIdentities: [] });
|
|
81
|
+
}
|
|
82
|
+
} catch { /* Unsupported/locked state is unknown, never a heuristic actor assignment. */ }
|
|
83
|
+
finally { db?.close(); }
|
|
84
|
+
}
|
|
85
|
+
if (!existsSync(archive) || lstatSync(archive).isSymbolicLink() || !lstatSync(archive).isDirectory()) return [...found.values()];
|
|
86
|
+
const events = new Map(), phases = new Map();
|
|
87
|
+
const budget = { remaining: 256 * 1024 * 1024 };
|
|
88
|
+
const files = readdirSync(archive).filter(name => /^logs(?:-[A-Za-z0-9.-]+)?\.json$/.test(name))
|
|
89
|
+
.map(name => join(archive, name)).sort((a, b) => lstatSync(b).mtimeMs - lstatSync(a).mtimeMs).slice(0, 32);
|
|
90
|
+
let count = 0;
|
|
91
|
+
for (const path of files) {
|
|
92
|
+
for await (const line of boundedLines(path, budget)) {
|
|
93
|
+
let packet; try { packet = JSON.parse(line); } catch { continue; }
|
|
94
|
+
for (const resource of Array.isArray(packet?.resourceLogs) ? packet.resourceLogs : []) for (const scope of Array.isArray(resource?.scopeLogs) ? resource.scopeLogs : []) for (const record of Array.isArray(scope?.logRecords) ? scope.logRecords : []) {
|
|
95
|
+
if (++count > 250_000) break;
|
|
96
|
+
const attributes = new Map((Array.isArray(record?.attributes) ? record.attributes : []).filter(a => a && typeof a.key === 'string').map(a => [a.key, a.value?.stringValue ?? a.value?.intValue]));
|
|
97
|
+
const id = attributes.get('conversation.id');
|
|
98
|
+
if (typeof id !== 'string' || !idPattern.test(id)) continue;
|
|
99
|
+
const key = sessionKey(sourceId, id);
|
|
100
|
+
if (!wanted.has(key)) continue;
|
|
101
|
+
const nano = record.timeUnixNano ?? record.observedTimeUnixNano;
|
|
102
|
+
if (typeof nano !== 'string' || !/^\d{1,20}$/.test(nano)) continue;
|
|
103
|
+
const time = BigInt(nano);
|
|
104
|
+
if (attributes.get('event.name') === 'codex.startup_phase' && attributes.get('startup.phase') === 'startup_prewarm_websocket_warmup') {
|
|
105
|
+
const duration = Number(attributes.get('duration_ms'));
|
|
106
|
+
if (Number.isFinite(duration) && duration >= 0 && duration <= 60_000) {
|
|
107
|
+
const list = phases.get(key) ?? [];
|
|
108
|
+
if (list.length < 1000) list.push({ end: time, start: time - BigInt(Math.ceil(duration * 1e6)) });
|
|
109
|
+
phases.set(key, list);
|
|
110
|
+
}
|
|
111
|
+
} else if (attributes.get('event.name') === 'codex.sse_event' && attributes.get('event.kind') === 'response.completed') {
|
|
112
|
+
const list = events.get(key) ?? [];
|
|
113
|
+
if (list.length < 2000) list.push({ time, identity: hash(`${sourceId}:${nano}:${hash(`${sourceId}:${id}`)}:codex.sse_event:response.completed`) });
|
|
114
|
+
events.set(key, list);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (count > 250_000) break;
|
|
118
|
+
}
|
|
119
|
+
if (count > 250_000) break;
|
|
120
|
+
}
|
|
121
|
+
for (const [key, intervals] of phases) {
|
|
122
|
+
const matches = (events.get(key) ?? []).filter(event => intervals.some(phase => event.time >= phase.start && event.time <= phase.end));
|
|
123
|
+
if (!matches.length) continue;
|
|
124
|
+
const entry = found.get(key) ?? { sessionKeyHash: key, activityKind: 'unknown', parentSessionKeyHash: null,
|
|
125
|
+
agentName: null, sourceUpdatedAt: new Date(Number(matches.reduce((latest, e) => e.time > latest ? e.time : latest, 0n) / 1_000_000n)).toISOString(), warmupEventIdentities: [] };
|
|
126
|
+
entry.warmupEventIdentities = [...new Set(matches.map(event => event.identity))].slice(0, 50);
|
|
127
|
+
found.set(key, entry);
|
|
128
|
+
}
|
|
129
|
+
return [...found.values()];
|
|
130
|
+
}
|
package/lib/session-titles.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { createReadStream, existsSync, lstatSync } from 'node:fs';
|
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { homedir } from 'node:os';
|
|
6
|
+
import { readSessionActivity } from './session-activity.mjs';
|
|
6
7
|
import { atomicWrite, readJson } from './agent-telemetry.mjs';
|
|
7
8
|
|
|
8
9
|
const hash = value => createHash('sha256').update(value).digest('hex');
|
|
@@ -39,7 +40,7 @@ export async function readSessionTitles(file, sourceId, targets) {
|
|
|
39
40
|
return [...found.values()];
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export async function syncSessionTitlesOnce(root, { request = fetch, codexHome = process.env.CODEX_HOME || join(homedir(), '.codex') } = {}) {
|
|
43
|
+
export async function syncSessionTitlesOnce(root, { request = fetch, syncActivity = false, codexHome = process.env.CODEX_HOME || join(homedir(), '.codex') } = {}) {
|
|
43
44
|
const file = join(root, 'session-title-enrollment.json');
|
|
44
45
|
if (!existsSync(file)) return 'not_enrolled';
|
|
45
46
|
if (!privateFile(file)) throw new Error('Session title credential must be private');
|
|
@@ -78,6 +79,17 @@ export async function syncSessionTitlesOnce(root, { request = fetch, codexHome =
|
|
|
78
79
|
!(page.continuation === null || typeof page.continuation === 'string' && /^[0-9a-f-]{36}$/i.test(page.continuation))) throw new Error('Invalid title targets');
|
|
79
80
|
const titles = page.targets.length ? await readSessionTitles(join(codexHome, 'session_index.jsonl'), binding.sourceId, page.targets) : [];
|
|
80
81
|
for (let i = 0; i < titles.length; i += 50) await send('/titles', { contractVersion: '1.0.0', titles: titles.slice(i, i + 50) });
|
|
82
|
+
if (syncActivity && page.targets.length) {
|
|
83
|
+
const metadata = await readSessionActivity(codexHome, join(root, 'data', 'archive'), binding.sourceId, page.targets);
|
|
84
|
+
let batch = [];
|
|
85
|
+
for (const item of metadata) {
|
|
86
|
+
if (batch.length && (batch.length >= 20 || Buffer.byteLength(JSON.stringify([...batch, item])) > 50_000)) {
|
|
87
|
+
await send('/activity', { contractVersion: '1.0.0', sessions: batch }); batch = [];
|
|
88
|
+
}
|
|
89
|
+
batch.push(item);
|
|
90
|
+
}
|
|
91
|
+
if (batch.length) await send('/activity', { contractVersion: '1.0.0', sessions: batch });
|
|
92
|
+
}
|
|
81
93
|
atomicWrite(cursorFile, JSON.stringify({ fingerprint, afterSessionId: page.continuation }) + '\n');
|
|
82
94
|
return 'synchronized';
|
|
83
95
|
}
|
package/package.json
CHANGED
|
@@ -1,33 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akilium/telemetry-collector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Akilium local OpenTelemetry Collector installer and diagnostic CLI",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"engines": {
|
|
7
|
-
"node": ">=22"
|
|
8
|
-
},
|
|
6
|
+
"engines": { "node": ">=22.13" },
|
|
9
7
|
"license": "MIT",
|
|
10
|
-
"repository": {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"files": [
|
|
19
|
-
"bin",
|
|
20
|
-
"lib",
|
|
21
|
-
"README.md"
|
|
22
|
-
],
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@akilium/instrumentation": "0.1.9"
|
|
25
|
-
},
|
|
26
|
-
"publishConfig": {
|
|
27
|
-
"access": "public"
|
|
8
|
+
"repository": { "type": "git", "url": "git+https://github.com/Akilium/akila-platform.git", "directory": "packages/telemetry-collector" },
|
|
9
|
+
"bin": { "akilium-telemetry": "./bin/akilium-telemetry.mjs" },
|
|
10
|
+
"files": ["bin", "lib", "README.md", "dist/instrumentation/src", "dist/integration-contracts/src"],
|
|
11
|
+
"exports": {
|
|
12
|
+
"./instrumentation": {
|
|
13
|
+
"types": "./dist/instrumentation/src/index.d.ts",
|
|
14
|
+
"default": "./dist/instrumentation/src/index.js"
|
|
15
|
+
}
|
|
28
16
|
},
|
|
29
17
|
"scripts": {
|
|
30
|
-
"
|
|
18
|
+
"build:package": "pnpm --filter @akilium/instrumentation build && rm -rf dist && mkdir -p dist && cp -R ../instrumentation/dist/instrumentation dist/instrumentation && cp -R ../instrumentation/dist/integration-contracts dist/integration-contracts",
|
|
19
|
+
"prepack": "pnpm run build:package",
|
|
20
|
+
"pretest": "pnpm run build:package",
|
|
31
21
|
"test": "node --test test/*.test.mjs"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": { "access": "public" }
|
|
24
|
+
}
|