@codetelemetry/connect 0.1.0 → 0.1.3

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 (91) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -24
  3. package/dist/agent.d.ts +699 -0
  4. package/dist/agent.js +435 -0
  5. package/dist/assistants.d.ts +4 -0
  6. package/dist/assistants.js +5 -0
  7. package/dist/bin.js +3 -0
  8. package/dist/cli.d.ts +1 -0
  9. package/dist/cli.js +567 -0
  10. package/dist/clients.d.ts +34 -0
  11. package/dist/clients.js +74 -0
  12. package/dist/{src/codexConfig.d.ts → codexConfig.d.ts} +1 -0
  13. package/dist/{src/codexConfig.js → codexConfig.js} +5 -0
  14. package/dist/{src/config.d.ts → config.d.ts} +16 -0
  15. package/dist/{src/config.js → config.js} +16 -0
  16. package/dist/connectivity.d.ts +51 -0
  17. package/dist/connectivity.js +118 -0
  18. package/dist/{src/deviceClient.d.ts → deviceClient.d.ts} +9 -2
  19. package/dist/{src/deviceClient.js → deviceClient.js} +45 -13
  20. package/dist/graderSeed.d.ts +50 -0
  21. package/dist/graderSeed.js +289 -0
  22. package/dist/hostMetrics.d.ts +54 -0
  23. package/dist/hostMetrics.js +425 -0
  24. package/dist/import/browser.d.ts +30 -0
  25. package/dist/import/browser.js +157 -0
  26. package/dist/import/convert.d.ts +20 -0
  27. package/dist/import/convert.js +165 -0
  28. package/dist/import/core.d.ts +143 -0
  29. package/dist/import/core.js +441 -0
  30. package/dist/import/ledger.d.ts +52 -0
  31. package/dist/import/ledger.js +161 -0
  32. package/dist/import/model.d.ts +70 -0
  33. package/dist/import/model.js +42 -0
  34. package/dist/import/options.d.ts +24 -0
  35. package/dist/import/options.js +71 -0
  36. package/dist/import/otlpImport.d.ts +7 -0
  37. package/dist/import/otlpImport.js +81 -0
  38. package/dist/import/protocol.d.ts +35 -0
  39. package/dist/import/protocol.js +51 -0
  40. package/dist/import/run.d.ts +30 -0
  41. package/dist/import/run.js +127 -0
  42. package/dist/import/sources/claudeCodeText.d.ts +19 -0
  43. package/dist/import/sources/claudeCodeText.js +214 -0
  44. package/dist/import/sources/codexText.d.ts +20 -0
  45. package/dist/import/sources/codexText.js +319 -0
  46. package/dist/import/sources/files.d.ts +24 -0
  47. package/dist/import/sources/files.js +129 -0
  48. package/dist/import/transport.d.ts +76 -0
  49. package/dist/import/transport.js +141 -0
  50. package/dist/index.d.ts +19 -0
  51. package/dist/index.js +19 -0
  52. package/dist/kiro/collector.d.ts +88 -0
  53. package/dist/kiro/collector.js +577 -0
  54. package/dist/kiro/command.d.ts +3 -0
  55. package/dist/kiro/command.js +109 -0
  56. package/dist/kiro/config.d.ts +39 -0
  57. package/dist/kiro/config.js +107 -0
  58. package/dist/kiro/records.d.ts +52 -0
  59. package/dist/kiro/records.js +206 -0
  60. package/dist/kiro/service.d.ts +21 -0
  61. package/dist/kiro/service.js +183 -0
  62. package/dist/kiro/state.d.ts +45 -0
  63. package/dist/kiro/state.js +205 -0
  64. package/dist/kiro/transport.d.ts +9 -0
  65. package/dist/kiro/transport.js +90 -0
  66. package/dist/{src/onboard.d.ts → onboard.d.ts} +8 -2
  67. package/dist/onboard.js +116 -0
  68. package/dist/piConfig.d.ts +29 -0
  69. package/dist/piConfig.js +112 -0
  70. package/dist/plan.d.ts +53 -0
  71. package/dist/plan.js +113 -0
  72. package/dist/{src/settings.d.ts → settings.d.ts} +4 -0
  73. package/dist/{src/settings.js → settings.js} +17 -0
  74. package/dist/yaml.d.ts +5 -0
  75. package/dist/yaml.js +72 -0
  76. package/package.json +27 -18
  77. package/dist/bin/connect.js +0 -6
  78. package/dist/src/cli.d.ts +0 -10
  79. package/dist/src/cli.js +0 -172
  80. package/dist/src/connectivity.d.ts +0 -27
  81. package/dist/src/connectivity.js +0 -54
  82. package/dist/src/index.d.ts +0 -8
  83. package/dist/src/index.js +0 -8
  84. package/dist/src/onboard.js +0 -84
  85. /package/dist/{bin/connect.d.ts → bin.d.ts} +0 -0
  86. /package/dist/{src/keys.d.ts → keys.d.ts} +0 -0
  87. /package/dist/{src/keys.js → keys.js} +0 -0
  88. /package/dist/{src/otlp.d.ts → otlp.d.ts} +0 -0
  89. /package/dist/{src/otlp.js → otlp.js} +0 -0
  90. /package/dist/{src/repositoryHook.d.ts → repositoryHook.d.ts} +0 -0
  91. /package/dist/{src/repositoryHook.js → repositoryHook.js} +0 -0
@@ -0,0 +1,116 @@
1
+ import { resolveEndpoints } from "./config.js";
2
+ import {} from "./settings.js";
3
+ import { PI_EXTENSION_HINT, resolveClient } from "./clients.js";
4
+ import { sendTestEvent } from "./otlp.js";
5
+ import { confirmLanded, verifyScope, } from "./connectivity.js";
6
+ import { keyHash, mask, assertKey } from "./keys.js";
7
+ import { enableKiroService } from "./kiro/service.js";
8
+ export async function onboard(opts) {
9
+ const log = opts.logger ?? (() => { });
10
+ const steps = [];
11
+ const client = resolveClient(opts.client);
12
+ if (client.id === "kiro" && opts.settings?.scope === "project")
13
+ throw new Error("Kiro V3 capture is per-user; project scope is unsupported. Use a separate CodeTelemetry collector config.");
14
+ let apiKey;
15
+ let deviceIngest;
16
+ let approvedScope;
17
+ if (opts.key) {
18
+ apiKey = assertKey(opts.key);
19
+ steps.push({ name: "authenticate", ok: true, detail: "used provided ingest key" });
20
+ }
21
+ else if (opts.getKey) {
22
+ const got = await opts.getKey();
23
+ apiKey = assertKey(got.apiKey);
24
+ deviceIngest = got.ingestEndpoint;
25
+ approvedScope = got.scope;
26
+ steps.push({ name: "authenticate", ok: true, detail: "obtained ingest key via device flow" });
27
+ }
28
+ else {
29
+ throw new Error("onboard requires either `key` or `getKey`");
30
+ }
31
+ const endpoints = resolveEndpoints({
32
+ apiBase: opts.endpoints?.apiBase,
33
+ ingestEndpoint: deviceIngest ?? opts.endpoints?.ingestEndpoint,
34
+ });
35
+ log(`Using ingest key ${mask(apiKey)} → ${endpoints.ingestEndpoint}`);
36
+ if (opts.expectedScope && Object.keys(opts.expectedScope).length > 0) {
37
+ const scopeAttested = approvedScope
38
+ && (opts.expectedScope.tenantId === undefined || opts.expectedScope.tenantId === approvedScope.tenantId)
39
+ && (opts.expectedScope.teamId === undefined || opts.expectedScope.teamId === approvedScope.teamId)
40
+ && (opts.expectedScope.billingAccountId === undefined || opts.expectedScope.billingAccountId === approvedScope.billingAccountId);
41
+ if (scopeAttested) {
42
+ steps.push({ name: "verify_scope", ok: true, detail: "device authorization attested key destination and billing scope" });
43
+ }
44
+ else {
45
+ const preflight = await verifyScope({
46
+ key: apiKey,
47
+ connectivityUrl: endpoints.connectivityUrl,
48
+ fetchImpl: opts.fetchImpl,
49
+ expected: opts.expectedScope,
50
+ });
51
+ if (preflight.state !== "scope_verified") {
52
+ const mismatches = preflight.mismatches?.join(", ");
53
+ throw new Error(`refusing to configure key: ${preflight.state}${mismatches ? ` (${mismatches})` : ""}`);
54
+ }
55
+ steps.push({ name: "verify_scope", ok: true, detail: "key destination and billing scope verified" });
56
+ }
57
+ }
58
+ const settings = client.write({
59
+ key: apiKey,
60
+ ingestEndpoint: endpoints.ingestEndpoint,
61
+ configPath: client.resolveConfigPath({ scope: opts.settings?.scope, path: opts.settings?.path }),
62
+ enrich: opts.settings?.enrich,
63
+ repositoryObservation: opts.settings?.repositoryObservation,
64
+ backup: opts.settings?.backup,
65
+ });
66
+ steps.push({
67
+ name: "write_config",
68
+ ok: true,
69
+ detail: `${settings.created ? "created" : "updated"} ${settings.path} (${settings.wrote.length} ${client.noun})`,
70
+ });
71
+ log(`Wrote ${settings.wrote.length} ${client.noun} to ${settings.path}${settings.backupPath ? ` (backup: ${settings.backupPath})` : ""}`);
72
+ if (client.id === "pi") {
73
+ const installed = client.readSummary(settings.path).extensionInstalled === true;
74
+ const detail = installed ? "pi-otel extension detected" : `pi-otel extension not detected: ${PI_EXTENSION_HINT}`;
75
+ steps.push({ name: "check_extension", ok: true, detail });
76
+ log(detail);
77
+ }
78
+ if (client.id === "kiro" && opts.activateCollector !== false) {
79
+ const service = await enableKiroService(settings.path, opts.kiroService);
80
+ steps.push({ name: "activate_collector", ok: service.ok, detail: service.detail });
81
+ log(service.detail);
82
+ }
83
+ let test = null;
84
+ if (opts.sendTest !== false) {
85
+ test = await sendTestEvent({ key: apiKey, ingestEndpoint: endpoints.ingestEndpoint, fetchImpl: opts.fetchImpl });
86
+ steps.push({
87
+ name: "send_test_event",
88
+ ok: test.ok,
89
+ detail: test.ok ? `probe accepted (HTTP ${test.httpStatus})` : `ingest returned HTTP ${test.httpStatus}`,
90
+ });
91
+ log(test.ok ? `Test event accepted (probe ${test.probeId})` : `Test event rejected (HTTP ${test.httpStatus})`);
92
+ }
93
+ let verify = null;
94
+ if (opts.verify !== false && test?.ok) {
95
+ log("Waiting for the probe to land…");
96
+ verify = await confirmLanded({
97
+ key: apiKey,
98
+ connectivityUrl: endpoints.connectivityUrl,
99
+ probeId: test.probeId,
100
+ fetchImpl: opts.fetchImpl,
101
+ timeoutMs: opts.verifyTimeoutMs,
102
+ intervalMs: opts.verifyIntervalMs,
103
+ expected: opts.expectedScope,
104
+ });
105
+ steps.push({
106
+ name: "verify_telemetry",
107
+ ok: verify.landed,
108
+ detail: verify.landed
109
+ ? `landed in ${verify.elapsedMs}ms for ${verify.scope?.teamId ? `organization ${verify.scope.teamId}` : "personal scope"}`
110
+ : `${verify.state} (${verify.elapsedMs}ms)`,
111
+ });
112
+ log(verify.landed ? `✓ Telemetry landed in ${verify.elapsedMs}ms` : "Telemetry not confirmed yet — it can take a moment to appear");
113
+ }
114
+ const ok = steps.every((s) => s.ok);
115
+ return { ok, key: { masked: mask(apiKey), keyHash: keyHash(apiKey) }, settings, test, verify, steps };
116
+ }
@@ -0,0 +1,29 @@
1
+ export declare function resolvePiConfigPath(opts?: {
2
+ path?: string;
3
+ }): string;
4
+ export declare function piTracesEndpoint(ingestEndpoint: string): string;
5
+ export declare function buildPiOtelBlock(key: string, ingestEndpoint: string, enrich: boolean): Record<string, unknown>;
6
+ type SettingsObject = Record<string, unknown>;
7
+ export declare function mergePiSettings(existing: SettingsObject, otel: Record<string, unknown>): SettingsObject;
8
+ export type PiWriteResult = {
9
+ path: string;
10
+ wrote: string[];
11
+ backupPath: string | null;
12
+ created: boolean;
13
+ };
14
+ export type PiWriteOptions = {
15
+ key: string;
16
+ ingestEndpoint: string;
17
+ configPath: string;
18
+ enrich?: boolean;
19
+ backup?: boolean;
20
+ };
21
+ export declare function writePiConfig(opts: PiWriteOptions): PiWriteResult;
22
+ export declare function readPiKey(filePath: string): string | null;
23
+ export declare function readPiSummary(filePath: string): {
24
+ exists: boolean;
25
+ otelKeys: string[];
26
+ hasKey: boolean;
27
+ extensionInstalled: boolean;
28
+ };
29
+ export {};
@@ -0,0 +1,112 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { assertKey } from "./keys.js";
5
+ export function resolvePiConfigPath(opts = {}) {
6
+ if (opts.path)
7
+ return path.resolve(opts.path);
8
+ return path.join(os.homedir(), ".pi", "agent", "settings.json");
9
+ }
10
+ export function piTracesEndpoint(ingestEndpoint) {
11
+ const url = new URL(ingestEndpoint);
12
+ const port = url.port || (url.protocol === "http:" ? "80" : "443");
13
+ const base = url.pathname.replace(/\/+$/, "");
14
+ return `${url.protocol}//${url.hostname}:${port}${base}/v1/traces`;
15
+ }
16
+ export function buildPiOtelBlock(key, ingestEndpoint, enrich) {
17
+ return {
18
+ enabled: true,
19
+ endpoint: piTracesEndpoint(ingestEndpoint),
20
+ protocol: "http",
21
+ headers: { Authorization: `Bearer ${key}` },
22
+ serviceName: "pi",
23
+ signals: { traces: true, metrics: false, logs: false },
24
+ ...(enrich ? { captureContent: "full" } : {}),
25
+ };
26
+ }
27
+ function readJson(filePath) {
28
+ if (!fs.existsSync(filePath))
29
+ return {};
30
+ const raw = fs.readFileSync(filePath, "utf8").trim();
31
+ if (!raw)
32
+ return {};
33
+ try {
34
+ const parsed = JSON.parse(raw);
35
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
36
+ return parsed;
37
+ throw new Error("settings.json is not a JSON object");
38
+ }
39
+ catch (err) {
40
+ throw new Error(`refusing to overwrite ${filePath}: it isn't valid JSON (${err.message}). Fix or move it, then retry.`);
41
+ }
42
+ }
43
+ export function mergePiSettings(existing, otel) {
44
+ const previous = existing.otel && typeof existing.otel === "object" && !Array.isArray(existing.otel)
45
+ ? { ...existing.otel }
46
+ : {};
47
+ return { ...existing, otel: { ...previous, ...otel } };
48
+ }
49
+ export function writePiConfig(opts) {
50
+ const key = assertKey(opts.key);
51
+ const otel = buildPiOtelBlock(key, opts.ingestEndpoint, !!opts.enrich);
52
+ const filePath = path.resolve(opts.configPath);
53
+ const existed = fs.existsSync(filePath);
54
+ const merged = mergePiSettings(readJson(filePath), otel);
55
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
56
+ let backupPath = null;
57
+ if (existed && opts.backup !== false) {
58
+ backupPath = `${filePath}.bak`;
59
+ fs.copyFileSync(filePath, backupPath);
60
+ try {
61
+ fs.chmodSync(backupPath, 0o600);
62
+ }
63
+ catch {
64
+ }
65
+ }
66
+ fs.writeFileSync(filePath, `${JSON.stringify(merged, null, 2)}\n`, { mode: 0o600 });
67
+ try {
68
+ fs.chmodSync(filePath, 0o600);
69
+ }
70
+ catch {
71
+ }
72
+ return { path: filePath, wrote: Object.keys(otel), backupPath, created: !existed };
73
+ }
74
+ export function readPiKey(filePath) {
75
+ if (!fs.existsSync(filePath))
76
+ return null;
77
+ try {
78
+ const headers = JSON.parse(fs.readFileSync(filePath, "utf8"))?.otel?.headers;
79
+ if (!headers || typeof headers !== "object" || Array.isArray(headers))
80
+ return null;
81
+ for (const value of Object.values(headers)) {
82
+ const match = typeof value === "string" ? /Bearer\s+(cot_[A-Za-z0-9_-]+)/.exec(value) : null;
83
+ if (match)
84
+ return match[1];
85
+ }
86
+ return null;
87
+ }
88
+ catch {
89
+ return null;
90
+ }
91
+ }
92
+ export function readPiSummary(filePath) {
93
+ if (!fs.existsSync(filePath))
94
+ return { exists: false, otelKeys: [], hasKey: false, extensionInstalled: false };
95
+ let parsed;
96
+ try {
97
+ parsed = readJson(filePath);
98
+ }
99
+ catch {
100
+ return { exists: true, otelKeys: [], hasKey: false, extensionInstalled: false };
101
+ }
102
+ const otel = parsed.otel && typeof parsed.otel === "object" && !Array.isArray(parsed.otel)
103
+ ? parsed.otel
104
+ : {};
105
+ const packages = Array.isArray(parsed.packages) ? parsed.packages : [];
106
+ return {
107
+ exists: true,
108
+ otelKeys: Object.keys(otel),
109
+ hasKey: readPiKey(filePath) !== null,
110
+ extensionInstalled: packages.some((entry) => typeof entry === "string" && /(^|[:/])pi-otel(@|$)/.test(entry)),
111
+ };
112
+ }
package/dist/plan.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ export declare const MAX_PLAN_TEXT = 4000;
2
+ export declare const MAX_PLAN_TITLE = 300;
3
+ export declare const MAX_PLAN_STEP_TITLE = 300;
4
+ export declare const MAX_PLAN_STEP_DETAIL = 4000;
5
+ export declare const MAX_PLAN_STEPS = 50;
6
+ export declare const MAX_PLAN_REPO = 200;
7
+ export declare const MAX_PLAN_PROJECT = 200;
8
+ export declare const MAX_PLAN_MODEL = 120;
9
+ export declare const PLAN_PROVIDERS: readonly ["claude", "codex", "pi", "kiro"];
10
+ export type PlanProvider = (typeof PLAN_PROVIDERS)[number];
11
+ export type PlanStepInput = string | {
12
+ title?: string;
13
+ detail?: string;
14
+ };
15
+ export type PlanInput = {
16
+ planText?: string;
17
+ steps?: PlanStepInput[];
18
+ title?: string;
19
+ repo?: string;
20
+ project?: string;
21
+ provider?: PlanProvider;
22
+ model?: string;
23
+ };
24
+ export type PlanSourceStep = {
25
+ index: number;
26
+ title: string | null;
27
+ chars: number;
28
+ };
29
+ export type PlanSource = {
30
+ kind: "plan";
31
+ title: string | null;
32
+ format: "text" | "steps" | "text+steps";
33
+ stepCount: number;
34
+ steps: PlanSourceStep[];
35
+ repo: string | null;
36
+ project: string | null;
37
+ provider: PlanProvider | null;
38
+ model: string | null;
39
+ contentChars: number;
40
+ };
41
+ export type NormalizedPlan = {
42
+ taskText: string;
43
+ repo?: string;
44
+ source: PlanSource;
45
+ };
46
+ export type NormalizePlanResult = {
47
+ ok: true;
48
+ plan: NormalizedPlan;
49
+ } | {
50
+ ok: false;
51
+ message: string;
52
+ };
53
+ export declare function normalizePlan(raw: Record<string, unknown>): NormalizePlanResult;
package/dist/plan.js ADDED
@@ -0,0 +1,113 @@
1
+ import { ONBOARD_CLIENTS } from "./assistants.js";
2
+ export const MAX_PLAN_TEXT = 4_000;
3
+ export const MAX_PLAN_TITLE = 300;
4
+ export const MAX_PLAN_STEP_TITLE = 300;
5
+ export const MAX_PLAN_STEP_DETAIL = 4_000;
6
+ export const MAX_PLAN_STEPS = 50;
7
+ export const MAX_PLAN_REPO = 200;
8
+ export const MAX_PLAN_PROJECT = 200;
9
+ export const MAX_PLAN_MODEL = 120;
10
+ export const PLAN_PROVIDERS = ONBOARD_CLIENTS;
11
+ const bad = (message) => ({ ok: false, message });
12
+ function boundedString(value, max) {
13
+ if (value === undefined)
14
+ return undefined;
15
+ if (typeof value !== "string" || value.length > max)
16
+ return null;
17
+ return value.trim();
18
+ }
19
+ export function normalizePlan(raw) {
20
+ const planText = boundedString(raw.planText, MAX_PLAN_TEXT);
21
+ if (planText === null) {
22
+ return bad(`planText must be a string of at most ${MAX_PLAN_TEXT} characters`);
23
+ }
24
+ const title = boundedString(raw.title, MAX_PLAN_TITLE);
25
+ if (title === null)
26
+ return bad(`title must be a string of at most ${MAX_PLAN_TITLE} characters`);
27
+ const repo = boundedString(raw.repo, MAX_PLAN_REPO);
28
+ if (repo === null)
29
+ return bad(`repo must be a string of at most ${MAX_PLAN_REPO} characters`);
30
+ const project = boundedString(raw.project, MAX_PLAN_PROJECT);
31
+ if (project === null)
32
+ return bad(`project must be a string of at most ${MAX_PLAN_PROJECT} characters`);
33
+ const model = boundedString(raw.model, MAX_PLAN_MODEL);
34
+ if (model === null)
35
+ return bad(`model must be a string of at most ${MAX_PLAN_MODEL} characters`);
36
+ let provider;
37
+ if (raw.provider !== undefined) {
38
+ if (typeof raw.provider !== "string" || !PLAN_PROVIDERS.includes(raw.provider)) {
39
+ return bad(`provider must be one of ${PLAN_PROVIDERS.join(", ")}`);
40
+ }
41
+ provider = raw.provider;
42
+ }
43
+ const stepLines = [];
44
+ const sourceSteps = [];
45
+ if (raw.steps !== undefined) {
46
+ if (!Array.isArray(raw.steps))
47
+ return bad("steps must be an array");
48
+ if (raw.steps.length > MAX_PLAN_STEPS)
49
+ return bad(`steps must contain at most ${MAX_PLAN_STEPS} items`);
50
+ for (let i = 0; i < raw.steps.length; i++) {
51
+ const step = raw.steps[i];
52
+ let stepTitle;
53
+ let stepDetail;
54
+ if (typeof step === "string") {
55
+ stepDetail = step.trim();
56
+ }
57
+ else if (step !== null && typeof step === "object" && !Array.isArray(step)) {
58
+ const obj = step;
59
+ const t = boundedString(obj.title, MAX_PLAN_STEP_TITLE);
60
+ const d = boundedString(obj.detail, MAX_PLAN_STEP_DETAIL);
61
+ if (t === null)
62
+ return bad(`steps[${i}].title must be a string of at most ${MAX_PLAN_STEP_TITLE} characters`);
63
+ if (d === null)
64
+ return bad(`steps[${i}].detail must be a string of at most ${MAX_PLAN_STEP_DETAIL} characters`);
65
+ stepTitle = t || undefined;
66
+ stepDetail = d || undefined;
67
+ }
68
+ else {
69
+ return bad(`steps[${i}] must be a string or an object with title/detail`);
70
+ }
71
+ if (!stepTitle && !stepDetail) {
72
+ return bad(`steps[${i}] must have a non-empty title or detail`);
73
+ }
74
+ const label = stepTitle && stepDetail ? `${stepTitle}: ${stepDetail}` : stepTitle ?? stepDetail;
75
+ stepLines.push(`${i + 1}. ${label}`);
76
+ sourceSteps.push({
77
+ index: i + 1,
78
+ title: stepTitle ?? null,
79
+ chars: (stepTitle?.length ?? 0) + (stepDetail?.length ?? 0),
80
+ });
81
+ }
82
+ }
83
+ const hasText = !!planText;
84
+ const hasSteps = sourceSteps.length > 0;
85
+ if (!hasText && !hasSteps) {
86
+ return bad("Provide planText or at least one step to estimate.");
87
+ }
88
+ const parts = [];
89
+ if (title)
90
+ parts.push(title);
91
+ if (planText)
92
+ parts.push(planText);
93
+ if (hasSteps)
94
+ parts.push(`Plan steps:\n${stepLines.join("\n")}`);
95
+ const taskText = parts.join("\n\n");
96
+ if (taskText.length > MAX_PLAN_TEXT) {
97
+ return bad(`Assembled plan is ${taskText.length} characters; keep title, plan text, and steps under ${MAX_PLAN_TEXT} together.`);
98
+ }
99
+ const format = hasText && hasSteps ? "text+steps" : hasSteps ? "steps" : "text";
100
+ const source = {
101
+ kind: "plan",
102
+ title: title || null,
103
+ format,
104
+ stepCount: sourceSteps.length,
105
+ steps: sourceSteps,
106
+ repo: repo || null,
107
+ project: project || null,
108
+ provider: provider ?? null,
109
+ model: model || null,
110
+ contentChars: taskText.length,
111
+ };
112
+ return { ok: true, plan: { taskText, ...(repo ? { repo } : {}), source } };
113
+ }
@@ -25,4 +25,8 @@ export declare function readSettingsSummary(filePath: string): {
25
25
  otelKeys: string[];
26
26
  hasKey: boolean;
27
27
  };
28
+ export declare function readClaudeContentFlags(filePath: string): {
29
+ prompts: boolean;
30
+ toolDetails: boolean;
31
+ };
28
32
  export {};
@@ -95,3 +95,20 @@ export function readSettingsSummary(filePath) {
95
95
  const hasKey = typeof env.OTEL_EXPORTER_OTLP_HEADERS === "string" && env.OTEL_EXPORTER_OTLP_HEADERS.includes("cot_");
96
96
  return { exists: true, otelKeys, hasKey };
97
97
  }
98
+ function readEnvBlock(filePath) {
99
+ if (!fs.existsSync(filePath))
100
+ return null;
101
+ try {
102
+ const obj = JSON.parse(fs.readFileSync(filePath, "utf8"));
103
+ const env = obj?.env;
104
+ return env && typeof env === "object" && !Array.isArray(env) ? env : null;
105
+ }
106
+ catch {
107
+ return null;
108
+ }
109
+ }
110
+ export function readClaudeContentFlags(filePath) {
111
+ const env = readEnvBlock(filePath) ?? {};
112
+ const on = (k) => env[k] === "1" || env[k] === "true";
113
+ return { prompts: on("OTEL_LOG_USER_PROMPTS"), toolDetails: on("OTEL_LOG_TOOL_DETAILS") };
114
+ }
package/dist/yaml.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export type YamlValue = string | number | boolean | null | YamlValue[] | {
2
+ [key: string]: YamlValue;
3
+ };
4
+ export declare function renderScalar(value: string | number | boolean | null): string;
5
+ export declare function renderYaml(value: YamlValue): string;
package/dist/yaml.js ADDED
@@ -0,0 +1,72 @@
1
+ const PLAIN_SAFE = /^[A-Za-z_][A-Za-z0-9_.\-/]*$/;
2
+ const RESERVED = new Set([
3
+ "true", "false", "yes", "no", "on", "off", "null", "y", "n",
4
+ ]);
5
+ function quote(s) {
6
+ return `'${s.replace(/'/g, "''")}'`;
7
+ }
8
+ export function renderScalar(value) {
9
+ if (value === null)
10
+ return "null";
11
+ if (typeof value === "boolean")
12
+ return value ? "true" : "false";
13
+ if (typeof value === "number") {
14
+ if (!Number.isFinite(value))
15
+ throw new Error(`cannot emit non-finite number: ${value}`);
16
+ return String(value);
17
+ }
18
+ if (value === "")
19
+ return "''";
20
+ if (RESERVED.has(value.toLowerCase()))
21
+ return quote(value);
22
+ if (/^[-+]?(\d+\.?\d*|\.\d+)$/.test(value))
23
+ return quote(value);
24
+ if (!PLAIN_SAFE.test(value))
25
+ return quote(value);
26
+ return value;
27
+ }
28
+ function isScalar(v) {
29
+ return v === null || typeof v === "string" || typeof v === "number" || typeof v === "boolean";
30
+ }
31
+ function isEmptyContainer(v) {
32
+ if (Array.isArray(v))
33
+ return v.length === 0;
34
+ if (typeof v === "object" && v !== null)
35
+ return Object.keys(v).length === 0;
36
+ return false;
37
+ }
38
+ function renderInlineEmpty(v) {
39
+ return Array.isArray(v) ? "[]" : "{}";
40
+ }
41
+ function renderNode(value, indent) {
42
+ const pad = " ".repeat(indent);
43
+ if (Array.isArray(value)) {
44
+ return value.flatMap((item) => {
45
+ if (isScalar(item))
46
+ return [`${pad}- ${renderScalar(item)}`];
47
+ if (isEmptyContainer(item))
48
+ return [`${pad}- ${renderInlineEmpty(item)}`];
49
+ const lines = renderNode(item, indent + 1);
50
+ return [`${pad}- ${lines[0].trimStart()}`, ...lines.slice(1)];
51
+ });
52
+ }
53
+ if (typeof value === "object" && value !== null) {
54
+ return Object.entries(value).flatMap(([key, child]) => {
55
+ const k = renderScalar(key);
56
+ if (isScalar(child))
57
+ return [`${pad}${k}: ${renderScalar(child)}`];
58
+ if (isEmptyContainer(child))
59
+ return [`${pad}${k}: ${renderInlineEmpty(child)}`];
60
+ const childIndent = Array.isArray(child) ? indent : indent + 1;
61
+ return [`${pad}${k}:`, ...renderNode(child, childIndent)];
62
+ });
63
+ }
64
+ throw new Error(`unsupported YAML node: ${String(value)}`);
65
+ }
66
+ export function renderYaml(value) {
67
+ if (isScalar(value))
68
+ return renderScalar(value) + "\n";
69
+ if (isEmptyContainer(value))
70
+ return renderInlineEmpty(value) + "\n";
71
+ return renderNode(value, 0).join("\n") + "\n";
72
+ }
package/package.json CHANGED
@@ -1,25 +1,34 @@
1
1
  {
2
2
  "name": "@codetelemetry/connect",
3
- "version": "0.1.0",
4
- "description": "Public-safe CLI and library for connecting Claude Code or Codex to CodeTelemetry.",
3
+ "version": "0.1.3",
4
+ "description": "CodeTelemetry local client and onboarding CLI",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "homepage": "https://codetelemetry.com/docs/onboarding/connect-cli",
8
- "repository": { "type": "git", "url": "git+https://github.com/ElliotGardiner/codetelemetry-connect.git" },
9
- "bugs": { "url": "https://github.com/ElliotGardiner/codetelemetry-connect/issues" },
10
- "bin": { "codetelemetry-connect": "./dist/bin/connect.js" },
11
- "exports": { ".": { "types": "./dist/src/index.d.ts", "default": "./dist/src/index.js" } },
12
- "files": ["dist"],
13
- "publishConfig": { "access": "public" },
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/CodeTelemetry/codetelemetry-mcp.git",
10
+ "directory": "packages/connect"
11
+ },
12
+ "bin": {
13
+ "codetelemetry-connect": "./dist/bin.js"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "engines": {
25
+ "node": ">=22.6"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
14
30
  "scripts": {
15
- "clean": "node scripts/cleanDist.ts",
16
- "build": "npm run clean && tsc -p tsconfig.build.json",
17
- "test": "node --test test/*.test.ts",
18
- "typecheck": "tsc --noEmit",
19
- "audit:package": "node scripts/auditPackage.ts",
20
- "test:packaged": "node scripts/packagedSmoke.ts",
31
+ "build": "node ../../scripts/buildConnect.ts",
21
32
  "prepack": "npm run build"
22
- },
23
- "engines": { "node": ">=22.6" },
24
- "devDependencies": { "@types/node": "^22.10.0", "typescript": "^5.9.3" }
33
+ }
25
34
  }
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- import { run } from "../src/cli.js";
3
- run(process.argv.slice(2)).then((code) => { process.exitCode = code; }, (error) => {
4
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
5
- process.exitCode = 1;
6
- });
package/dist/src/cli.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { type Endpoints } from "./config.ts";
2
- import { type FetchLike } from "./otlp.ts";
3
- type RunDeps = {
4
- endpointsOverride?: Partial<Endpoints>;
5
- fetchImpl?: FetchLike;
6
- openBrowser?: (url: string) => boolean;
7
- env?: NodeJS.ProcessEnv;
8
- };
9
- export declare function run(argv: string[], deps?: RunDeps): Promise<number>;
10
- export {};