@codetelemetry/mcp 0.3.8 → 0.3.12

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 (79) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +90 -9
  3. package/dist/src/client/agent.d.ts +221 -3
  4. package/dist/src/client/agent.js +174 -0
  5. package/dist/src/client/assistants.d.ts +4 -0
  6. package/dist/src/client/assistants.js +5 -0
  7. package/dist/src/client/bin.d.ts +2 -0
  8. package/dist/src/client/bin.js +3 -0
  9. package/dist/src/client/cli.d.ts +1 -0
  10. package/dist/src/client/cli.js +567 -0
  11. package/dist/src/client/clients.d.ts +34 -0
  12. package/dist/src/client/clients.js +74 -0
  13. package/dist/src/client/codexConfig.d.ts +1 -0
  14. package/dist/src/client/codexConfig.js +5 -0
  15. package/dist/src/client/config.d.ts +7 -0
  16. package/dist/src/client/config.js +7 -0
  17. package/dist/src/client/graderSeed.d.ts +50 -0
  18. package/dist/src/client/graderSeed.js +289 -0
  19. package/dist/src/client/hostMetrics.d.ts +54 -0
  20. package/dist/src/client/hostMetrics.js +425 -0
  21. package/dist/src/client/import/browser.d.ts +30 -0
  22. package/dist/src/client/import/browser.js +157 -0
  23. package/dist/src/client/import/convert.d.ts +20 -0
  24. package/dist/src/client/import/convert.js +165 -0
  25. package/dist/src/client/import/core.d.ts +143 -0
  26. package/dist/src/client/import/core.js +441 -0
  27. package/dist/src/client/import/ledger.d.ts +52 -0
  28. package/dist/src/client/import/ledger.js +161 -0
  29. package/dist/src/client/import/model.d.ts +70 -0
  30. package/dist/src/client/import/model.js +42 -0
  31. package/dist/src/client/import/options.d.ts +24 -0
  32. package/dist/src/client/import/options.js +71 -0
  33. package/dist/src/client/import/otlpImport.d.ts +7 -0
  34. package/dist/src/client/import/otlpImport.js +81 -0
  35. package/dist/src/client/import/protocol.d.ts +35 -0
  36. package/dist/src/client/import/protocol.js +51 -0
  37. package/dist/src/client/import/run.d.ts +30 -0
  38. package/dist/src/client/import/run.js +127 -0
  39. package/dist/src/client/import/sources/claudeCodeText.d.ts +19 -0
  40. package/dist/src/client/import/sources/claudeCodeText.js +214 -0
  41. package/dist/src/client/import/sources/codexText.d.ts +20 -0
  42. package/dist/src/client/import/sources/codexText.js +319 -0
  43. package/dist/src/client/import/sources/files.d.ts +24 -0
  44. package/dist/src/client/import/sources/files.js +129 -0
  45. package/dist/src/client/import/transport.d.ts +76 -0
  46. package/dist/src/client/import/transport.js +141 -0
  47. package/dist/src/client/index.d.ts +19 -0
  48. package/dist/src/client/index.js +19 -0
  49. package/dist/src/client/kiro/collector.d.ts +88 -0
  50. package/dist/src/client/kiro/collector.js +577 -0
  51. package/dist/src/client/kiro/command.d.ts +3 -0
  52. package/dist/src/client/kiro/command.js +109 -0
  53. package/dist/src/client/kiro/config.d.ts +39 -0
  54. package/dist/src/client/kiro/config.js +107 -0
  55. package/dist/src/client/kiro/records.d.ts +52 -0
  56. package/dist/src/client/kiro/records.js +206 -0
  57. package/dist/src/client/kiro/service.d.ts +21 -0
  58. package/dist/src/client/kiro/service.js +183 -0
  59. package/dist/src/client/kiro/state.d.ts +45 -0
  60. package/dist/src/client/kiro/state.js +205 -0
  61. package/dist/src/client/kiro/transport.d.ts +9 -0
  62. package/dist/src/client/kiro/transport.js +90 -0
  63. package/dist/src/client/onboard.d.ts +5 -1
  64. package/dist/src/client/onboard.js +28 -23
  65. package/dist/src/client/piConfig.d.ts +29 -0
  66. package/dist/src/client/piConfig.js +112 -0
  67. package/dist/src/client/plan.d.ts +1 -1
  68. package/dist/src/client/plan.js +2 -1
  69. package/dist/src/client/settings.d.ts +4 -0
  70. package/dist/src/client/settings.js +17 -0
  71. package/dist/src/client/yaml.d.ts +5 -0
  72. package/dist/src/client/yaml.js +72 -0
  73. package/dist/src/mcpServer.js +1 -1
  74. package/dist/src/tools.d.ts +9 -6
  75. package/dist/src/tools.js +478 -60
  76. package/dist/src/version.d.ts +1 -1
  77. package/dist/src/version.js +1 -1
  78. package/package.json +178 -9
  79. package/tool-manifest.json +497 -21
@@ -0,0 +1,165 @@
1
+ import { toNano } from "./model.js";
2
+ export const CLAUDE_SERVICE = "claude-code";
3
+ export const CODEX_SERVICE = "codex-cli";
4
+ export const TOKEN_USAGE_METRIC = "claude_code.token.usage";
5
+ export const REDACTED = "<REDACTED>";
6
+ export const IMPORT_COMPLETE_EVENT = "import.session_complete";
7
+ export const IMPORT_FORBIDDEN_EVENTS = Object.freeze([
8
+ "api_request", "api_error", "api_request_body", "api_response_body", "tool_decision",
9
+ "codex.tool_decision", "codex.api_request",
10
+ ]);
11
+ export const IMPORT_FORBIDDEN_ATTRIBUTES = Object.freeze(["duration_ms", "cost_usd"]);
12
+ export const IMPORT_FORBIDDEN_METRICS = Object.freeze([
13
+ "claude_code.active_time.total", "claude_code.session.count", "claude_code.cost.usage",
14
+ "claude_code.lines_of_code.count", "claude_code.commit.count", "claude_code.pull_request.count",
15
+ "claude_code.code_edit_tool.decision",
16
+ ]);
17
+ const clean = (attrs) => {
18
+ const out = {};
19
+ for (const [k, v] of Object.entries(attrs))
20
+ if (v !== undefined)
21
+ out[k] = v;
22
+ return out;
23
+ };
24
+ const iso = (ms) => new Date(ms).toISOString();
25
+ const bool = (v) => (v === undefined ? undefined : v ? "true" : "false");
26
+ const HOUR_MS = 3_600_000;
27
+ function finishLogs(staged) {
28
+ staged.sort((a, b) => a.tsMs - b.tsMs || a.order - b.order);
29
+ return staged.map((s) => ({ timeUnixNano: toNano(s.tsMs), attributes: s.attributes }));
30
+ }
31
+ function convertClaude(session, content) {
32
+ const staged = [];
33
+ let order = 0;
34
+ for (const p of session.prompts) {
35
+ staged.push({
36
+ tsMs: p.tsMs,
37
+ order: order++,
38
+ attributes: clean({
39
+ "event.name": "user_prompt",
40
+ "event.timestamp": iso(p.tsMs),
41
+ "session.id": session.sessionId,
42
+ "prompt.id": p.promptId,
43
+ prompt: content.prompts && p.text !== null ? p.text : REDACTED,
44
+ prompt_length: p.length,
45
+ }),
46
+ });
47
+ }
48
+ for (const t of session.toolCalls) {
49
+ staged.push({
50
+ tsMs: t.tsMs,
51
+ order: order++,
52
+ attributes: clean({
53
+ "event.name": "tool_result",
54
+ "event.timestamp": iso(t.tsMs),
55
+ "session.id": session.sessionId,
56
+ "prompt.id": t.promptId,
57
+ tool_name: t.toolName,
58
+ tool_use_id: t.toolUseId,
59
+ success: bool(t.success),
60
+ ...(content.toolDetails && t.input !== null ? { tool_input: t.input } : {}),
61
+ tool_input_size_bytes: t.inputBytes || undefined,
62
+ tool_result_size_bytes: t.resultBytes,
63
+ }),
64
+ });
65
+ }
66
+ const buckets = new Map();
67
+ for (const c of session.modelCalls) {
68
+ const hour = Math.floor(c.tsMs / HOUR_MS);
69
+ for (const [type, n] of [
70
+ ["input", c.inputTokens],
71
+ ["output", c.outputTokens],
72
+ ["cacheRead", c.cacheReadTokens],
73
+ ["cacheCreation", c.cacheCreationTokens],
74
+ ]) {
75
+ if (n <= 0)
76
+ continue;
77
+ const key = `${c.model}\u0000${type}\u0000${hour}`;
78
+ const b = buckets.get(key);
79
+ if (b) {
80
+ b.total += n;
81
+ b.firstMs = Math.min(b.firstMs, c.tsMs);
82
+ b.lastMs = Math.max(b.lastMs, c.tsMs);
83
+ }
84
+ else {
85
+ buckets.set(key, { firstMs: c.tsMs, lastMs: c.tsMs, total: n, model: c.model, type });
86
+ }
87
+ }
88
+ }
89
+ const metrics = [...buckets.values()]
90
+ .sort((a, b) => a.lastMs - b.lastMs || a.model.localeCompare(b.model) || a.type.localeCompare(b.type))
91
+ .map((b) => ({
92
+ name: TOKEN_USAGE_METRIC,
93
+ timeUnixNano: toNano(b.lastMs),
94
+ startTimeUnixNano: toNano(b.firstMs),
95
+ asInt: b.total,
96
+ attributes: clean({ "session.id": session.sessionId, model: b.model || undefined, type: b.type }),
97
+ }));
98
+ return { logs: finishLogs(staged), metrics };
99
+ }
100
+ function convertCodex(session, content) {
101
+ const staged = [];
102
+ let order = 0;
103
+ for (const p of session.prompts) {
104
+ staged.push({
105
+ tsMs: p.tsMs,
106
+ order: order++,
107
+ attributes: clean({
108
+ "event.name": "codex.user_prompt",
109
+ "event.timestamp": iso(p.tsMs),
110
+ "conversation.id": session.sessionId,
111
+ "prompt.id": p.promptId,
112
+ prompt: content.prompts && p.text !== null ? p.text : REDACTED,
113
+ prompt_length: p.length,
114
+ }),
115
+ });
116
+ }
117
+ for (const c of session.modelCalls) {
118
+ staged.push({
119
+ tsMs: c.tsMs,
120
+ order: order++,
121
+ attributes: clean({
122
+ "event.name": "codex.sse_event",
123
+ "event.kind": "response.completed",
124
+ "event.timestamp": iso(c.tsMs),
125
+ "conversation.id": session.sessionId,
126
+ model: c.model || undefined,
127
+ input_token_count: c.inputTokens + c.cacheReadTokens,
128
+ output_token_count: c.outputTokens,
129
+ cached_token_count: c.cacheReadTokens,
130
+ }),
131
+ });
132
+ }
133
+ for (const t of session.toolCalls) {
134
+ staged.push({
135
+ tsMs: t.tsMs,
136
+ order: order++,
137
+ attributes: clean({
138
+ "event.name": "codex.tool_result",
139
+ "event.timestamp": iso(t.tsMs),
140
+ "conversation.id": session.sessionId,
141
+ tool_name: t.toolName,
142
+ call_id: t.toolUseId,
143
+ success: bool(t.success),
144
+ ...(content.toolDetails && t.input !== null ? { arguments: t.input } : {}),
145
+ }),
146
+ });
147
+ }
148
+ return { logs: finishLogs(staged), metrics: [] };
149
+ }
150
+ export function convertSession(session, content) {
151
+ return session.source === "claude-code" ? convertClaude(session, content) : convertCodex(session, content);
152
+ }
153
+ export function completionMarker(session, plan) {
154
+ return {
155
+ timeUnixNano: toNano(session.endMs),
156
+ attributes: {
157
+ "event.name": IMPORT_COMPLETE_EVENT,
158
+ "session.id": session.sessionId,
159
+ "import.plan": plan.id,
160
+ "import.log_parts": plan.logParts,
161
+ "import.metric_parts": plan.metricParts,
162
+ "import.events": plan.events,
163
+ },
164
+ };
165
+ }
@@ -0,0 +1,143 @@
1
+ import type { ContentPolicy, ImportAttributes, ImportLog, ImportMetric, ImportSource, ImportedSession } from "./model.ts";
2
+ import type { JournalEvent, LedgerEntry } from "./ledger.ts";
3
+ import { type SkipReason } from "./protocol.ts";
4
+ import type { FetchLike } from "../otlp.ts";
5
+ export declare const RETENTION_DAYS = 365;
6
+ export declare const RETENTION_MARGIN_DAYS = 1;
7
+ export declare const DEFAULT_SINCE_DAYS = 30;
8
+ export declare const ACTIVE_GRACE_MS: number;
9
+ export declare const IMPORT_VERSION = "1";
10
+ export declare const DEFAULT_RATE_PER_MINUTE = 120;
11
+ export declare const MAX_RATE_PER_MINUTE = 300;
12
+ export declare const DEFAULT_TIME_LIMIT_MS: number;
13
+ export declare const DAY_MS = 86400000;
14
+ export type ContentBySource = Record<ImportSource, ContentPolicy>;
15
+ export type ImportTool = "connect-cli" | "mcp" | "web-upload";
16
+ export type SkipCounts = Partial<Record<SkipReason | "older" | "newer" | "active" | "filtered" | "ledger" | "empty" | "too_large" | "too_many_events" | "unreadable" | "changed_during_run" | "deferred", number>>;
17
+ export type ImportSourceSummary = {
18
+ source: ImportSource;
19
+ filesFound: number;
20
+ sessionsParsed: number;
21
+ candidates: number;
22
+ imported: number;
23
+ resumed: number;
24
+ skipped: SkipCounts;
25
+ events: number;
26
+ metricPoints: number;
27
+ tokens: {
28
+ input: number;
29
+ output: number;
30
+ cacheRead: number;
31
+ cacheCreation: number;
32
+ };
33
+ };
34
+ export type StopReason = "budget" | "auth" | "busy" | "time_limit" | "status_unavailable";
35
+ export type ImportRunResult = {
36
+ ok: boolean;
37
+ run: string;
38
+ dryRun: boolean;
39
+ key: {
40
+ masked: string;
41
+ keyHash: string;
42
+ };
43
+ window: {
44
+ sinceIso: string;
45
+ untilIso: string;
46
+ clamped: boolean;
47
+ };
48
+ content: ContentBySource;
49
+ sources: ImportSourceSummary[];
50
+ totals: {
51
+ sessions: number;
52
+ events: number;
53
+ metricPoints: number;
54
+ };
55
+ remaining: number;
56
+ stoppedBy: StopReason | null;
57
+ topup?: string | null;
58
+ cleanup: Array<{
59
+ source: ImportSource;
60
+ sessionId: string;
61
+ plans: string[];
62
+ }>;
63
+ warnings: string[];
64
+ errors: string[];
65
+ };
66
+ export type Sha256Hex = (text: string) => string | Promise<string>;
67
+ export type LedgerLike = {
68
+ get(keyHash: string, sessionKey: string): LedgerEntry | undefined;
69
+ record(e: JournalEvent): void;
70
+ };
71
+ export declare function memoryLedger(): LedgerLike;
72
+ export type Plan = {
73
+ id: string;
74
+ logParts: ImportLog[][];
75
+ metricParts: ImportMetric[][];
76
+ events: number;
77
+ metricPoints: number;
78
+ };
79
+ export type Prepared = {
80
+ source: ImportSource;
81
+ sessionId: string;
82
+ fileSig: string;
83
+ startMs: number;
84
+ endMs: number;
85
+ plan: {
86
+ id: string;
87
+ logParts: number;
88
+ metricParts: number;
89
+ events: number;
90
+ metricPoints: number;
91
+ };
92
+ tokens: ImportSourceSummary["tokens"];
93
+ warnings: string[];
94
+ reload: () => Promise<ImportedSession | null>;
95
+ };
96
+ export declare const emptySummary: (source: ImportSource) => ImportSourceSummary;
97
+ export declare const bump: (s: ImportSourceSummary, reason: keyof SkipCounts, n?: number) => void;
98
+ export declare const underProject: (cwd: string | null, project: string, caseInsensitive: boolean) => boolean;
99
+ export declare const startOfUtcDay: (ms: number) => number;
100
+ export declare function resolveWindow(now: number, sinceMs?: number, untilMs?: number): {
101
+ sinceMs: number;
102
+ untilMs: number;
103
+ clamped: boolean;
104
+ warning?: string;
105
+ };
106
+ export declare function buildPlan(session: ImportedSession, content: ContentPolicy, email: string | undefined, sha256Hex: Sha256Hex): Promise<{
107
+ plan: Plan;
108
+ stable: ImportAttributes;
109
+ }>;
110
+ export type PrepareOptions = {
111
+ sinceMs: number;
112
+ untilMs: number;
113
+ project?: string;
114
+ caseInsensitivePaths: boolean;
115
+ content: ContentBySource;
116
+ email?: string;
117
+ sha256Hex: Sha256Hex;
118
+ };
119
+ export declare function prepareSession(session: ImportedSession, fileSig: string, reload: () => Promise<ImportedSession | null>, opts: PrepareOptions): Promise<Prepared | keyof SkipCounts>;
120
+ export type ImportPreparedOptions = PrepareOptions & {
121
+ key: string;
122
+ keyHash: string;
123
+ keyMasked: string;
124
+ statusUrl: string;
125
+ ingestEndpoint: string;
126
+ dryRun: boolean;
127
+ run: string;
128
+ importTool: ImportTool;
129
+ maxSessions?: number;
130
+ ratePerMinute?: number;
131
+ timeLimitMs?: number;
132
+ clamped: boolean;
133
+ now: number;
134
+ clock: () => number;
135
+ fetchImpl: FetchLike;
136
+ sleep?: (ms: number) => Promise<void>;
137
+ ledger: LedgerLike;
138
+ summaries: Map<ImportSource, ImportSourceSummary>;
139
+ warnings: string[];
140
+ logger?: (msg: string) => void;
141
+ };
142
+ export declare function importPrepared(prepared: Prepared[], o: ImportPreparedOptions): Promise<ImportRunResult>;
143
+ export declare const contentOrDefault: (c: Partial<ContentBySource> | undefined) => ContentBySource;