@codetelemetry/connect 0.1.1 → 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.
- package/LICENSE +1 -1
- package/README.md +8 -24
- package/dist/agent.d.ts +699 -0
- package/dist/agent.js +435 -0
- package/dist/assistants.d.ts +4 -0
- package/dist/assistants.js +5 -0
- package/dist/bin.js +3 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +567 -0
- package/dist/clients.d.ts +34 -0
- package/dist/clients.js +74 -0
- package/dist/{src/codexConfig.d.ts → codexConfig.d.ts} +1 -0
- package/dist/{src/codexConfig.js → codexConfig.js} +5 -0
- package/dist/{src/config.d.ts → config.d.ts} +16 -0
- package/dist/{src/config.js → config.js} +16 -0
- package/dist/connectivity.d.ts +51 -0
- package/dist/connectivity.js +118 -0
- package/dist/{src/deviceClient.d.ts → deviceClient.d.ts} +9 -2
- package/dist/{src/deviceClient.js → deviceClient.js} +45 -13
- package/dist/graderSeed.d.ts +50 -0
- package/dist/graderSeed.js +289 -0
- package/dist/hostMetrics.d.ts +54 -0
- package/dist/hostMetrics.js +425 -0
- package/dist/import/browser.d.ts +30 -0
- package/dist/import/browser.js +157 -0
- package/dist/import/convert.d.ts +20 -0
- package/dist/import/convert.js +165 -0
- package/dist/import/core.d.ts +143 -0
- package/dist/import/core.js +441 -0
- package/dist/import/ledger.d.ts +52 -0
- package/dist/import/ledger.js +161 -0
- package/dist/import/model.d.ts +70 -0
- package/dist/import/model.js +42 -0
- package/dist/import/options.d.ts +24 -0
- package/dist/import/options.js +71 -0
- package/dist/import/otlpImport.d.ts +7 -0
- package/dist/import/otlpImport.js +81 -0
- package/dist/import/protocol.d.ts +35 -0
- package/dist/import/protocol.js +51 -0
- package/dist/import/run.d.ts +30 -0
- package/dist/import/run.js +127 -0
- package/dist/import/sources/claudeCodeText.d.ts +19 -0
- package/dist/import/sources/claudeCodeText.js +214 -0
- package/dist/import/sources/codexText.d.ts +20 -0
- package/dist/import/sources/codexText.js +319 -0
- package/dist/import/sources/files.d.ts +24 -0
- package/dist/import/sources/files.js +129 -0
- package/dist/import/transport.d.ts +76 -0
- package/dist/import/transport.js +141 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +19 -0
- package/dist/kiro/collector.d.ts +88 -0
- package/dist/kiro/collector.js +577 -0
- package/dist/kiro/command.d.ts +3 -0
- package/dist/kiro/command.js +109 -0
- package/dist/kiro/config.d.ts +39 -0
- package/dist/kiro/config.js +107 -0
- package/dist/kiro/records.d.ts +52 -0
- package/dist/kiro/records.js +206 -0
- package/dist/kiro/service.d.ts +21 -0
- package/dist/kiro/service.js +183 -0
- package/dist/kiro/state.d.ts +45 -0
- package/dist/kiro/state.js +205 -0
- package/dist/kiro/transport.d.ts +9 -0
- package/dist/kiro/transport.js +90 -0
- package/dist/{src/onboard.d.ts → onboard.d.ts} +8 -2
- package/dist/onboard.js +116 -0
- package/dist/piConfig.d.ts +29 -0
- package/dist/piConfig.js +112 -0
- package/dist/plan.d.ts +53 -0
- package/dist/plan.js +113 -0
- package/dist/{src/repositoryHook.d.ts → repositoryHook.d.ts} +0 -1
- package/dist/{src/repositoryHook.js → repositoryHook.js} +5 -38
- package/dist/{src/settings.d.ts → settings.d.ts} +4 -0
- package/dist/{src/settings.js → settings.js} +17 -0
- package/dist/yaml.d.ts +5 -0
- package/dist/yaml.js +72 -0
- package/package.json +27 -18
- package/dist/bin/connect.js +0 -6
- package/dist/src/cli.d.ts +0 -10
- package/dist/src/cli.js +0 -172
- package/dist/src/connectivity.d.ts +0 -27
- package/dist/src/connectivity.js +0 -54
- package/dist/src/index.d.ts +0 -8
- package/dist/src/index.js +0 -8
- package/dist/src/onboard.js +0 -84
- /package/dist/{bin/connect.d.ts → bin.d.ts} +0 -0
- /package/dist/{src/keys.d.ts → keys.d.ts} +0 -0
- /package/dist/{src/keys.js → keys.js} +0 -0
- /package/dist/{src/otlp.d.ts → otlp.d.ts} +0 -0
- /package/dist/{src/otlp.js → otlp.js} +0 -0
package/dist/onboard.js
ADDED
|
@@ -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 {};
|
package/dist/piConfig.js
ADDED
|
@@ -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
|
+
}
|
|
@@ -7,7 +7,6 @@ export declare function normalizeRepositoryRemote(value: string): string;
|
|
|
7
7
|
export declare function selectCodexOtelExporterLine(raw: string): string;
|
|
8
8
|
export declare function repositoryHookSource(options?: {
|
|
9
9
|
codexConfigPath?: string;
|
|
10
|
-
claudeSettingsPath?: string;
|
|
11
10
|
}): string;
|
|
12
11
|
export declare function quotedCommand(filePath: string, platform?: string): string;
|
|
13
12
|
export declare function validateCodexRepositoryObservationHook(configPath: string): void;
|
|
@@ -111,9 +111,6 @@ export function repositoryHookSource(options = {}) {
|
|
|
111
111
|
const codexConfigPath = options.codexConfigPath
|
|
112
112
|
? path.resolve(options.codexConfigPath)
|
|
113
113
|
: "";
|
|
114
|
-
const claudeSettingsPath = options.claudeSettingsPath
|
|
115
|
-
? path.resolve(options.claudeSettingsPath)
|
|
116
|
-
: "";
|
|
117
114
|
return String.raw `"use strict";
|
|
118
115
|
const crypto = require("node:crypto");
|
|
119
116
|
const fs = require("node:fs");
|
|
@@ -122,7 +119,6 @@ const https = require("node:https");
|
|
|
122
119
|
const path = require("node:path");
|
|
123
120
|
const { execFileSync } = require("node:child_process");
|
|
124
121
|
const codexConfigPath = ${JSON.stringify(codexConfigPath)};
|
|
125
|
-
const claudeSettingsPath = ${JSON.stringify(claudeSettingsPath)};
|
|
126
122
|
const observationStatePath = path.join(__dirname, ${JSON.stringify(REPOSITORY_HOOK_STATE_FILE)});
|
|
127
123
|
const observationLockPath = observationStatePath + ".lock";
|
|
128
124
|
const maxObservationStateEntries = ${REPOSITORY_HOOK_STATE_MAX_ENTRIES};
|
|
@@ -306,24 +302,8 @@ function codexTelemetryConfig() {
|
|
|
306
302
|
};
|
|
307
303
|
} catch { return {}; }
|
|
308
304
|
}
|
|
309
|
-
function claudeTelemetryConfig() {
|
|
310
|
-
if (!claudeSettingsPath) return {};
|
|
311
|
-
try {
|
|
312
|
-
// Claude Code does not pass the OTEL_* exporter variables from settings.json
|
|
313
|
-
// into hook processes, so read the live env block at hook time. As with
|
|
314
|
-
// config.toml, the bearer key is never copied into this script and key
|
|
315
|
-
// rotation does not change the trusted hook definition.
|
|
316
|
-
const env = JSON.parse(fs.readFileSync(claudeSettingsPath, "utf8")).env || {};
|
|
317
|
-
return {
|
|
318
|
-
endpoint: String(env.OTEL_EXPORTER_OTLP_ENDPOINT || ""),
|
|
319
|
-
headers: otlpAuthHeaders(String(env.OTEL_EXPORTER_OTLP_HEADERS || "")),
|
|
320
|
-
};
|
|
321
|
-
} catch { return {}; }
|
|
322
|
-
}
|
|
323
305
|
function environmentAuthHeaders() {
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
function otlpAuthHeaders(raw) {
|
|
306
|
+
const raw = String(process.env.OTEL_EXPORTER_OTLP_HEADERS || "");
|
|
327
307
|
for (const part of raw.split(",")) {
|
|
328
308
|
const separator = part.indexOf("=");
|
|
329
309
|
if (separator < 0 || part.slice(0, separator).trim().toLowerCase() !== "authorization") continue;
|
|
@@ -336,28 +316,15 @@ function otlpAuthHeaders(raw) {
|
|
|
336
316
|
}
|
|
337
317
|
return {};
|
|
338
318
|
}
|
|
339
|
-
function logsEndpoint(base) {
|
|
340
|
-
const trimmed = String(base || "").replace(/\/$/, "");
|
|
341
|
-
if (!trimmed) return "";
|
|
342
|
-
return trimmed.endsWith("/v1/logs") ? trimmed : trimmed + "/v1/logs";
|
|
343
|
-
}
|
|
344
319
|
function deliveryDestination() {
|
|
345
|
-
const base =
|
|
320
|
+
const base = String(process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "").replace(/\/$/, "");
|
|
346
321
|
// Endpoint and credentials are one provenance-bearing choice. In particular,
|
|
347
|
-
// never attach the key from config.toml
|
|
348
|
-
// environment-provided endpoint.
|
|
322
|
+
// never attach the key from config.toml to an environment-provided endpoint.
|
|
349
323
|
if (base) return {
|
|
350
|
-
endpoint: base,
|
|
324
|
+
endpoint: base.endsWith("/v1/logs") ? base : base + "/v1/logs",
|
|
351
325
|
headers: environmentAuthHeaders(),
|
|
352
326
|
source: "environment",
|
|
353
327
|
};
|
|
354
|
-
const settings = claudeTelemetryConfig();
|
|
355
|
-
const settingsEndpoint = logsEndpoint(settings.endpoint);
|
|
356
|
-
if (settingsEndpoint) return {
|
|
357
|
-
endpoint: settingsEndpoint,
|
|
358
|
-
headers: settings.headers || {},
|
|
359
|
-
source: "settings",
|
|
360
|
-
};
|
|
361
328
|
const config = codexTelemetryConfig();
|
|
362
329
|
const authorization = String(config.authorization || "");
|
|
363
330
|
return {
|
|
@@ -623,7 +590,7 @@ export function installRepositoryObservationHook(settings, settingsPath) {
|
|
|
623
590
|
const directory = path.dirname(path.resolve(settingsPath));
|
|
624
591
|
const hookPath = path.join(directory, REPOSITORY_HOOK_FILE);
|
|
625
592
|
fs.mkdirSync(directory, { recursive: true });
|
|
626
|
-
fs.writeFileSync(hookPath, repositoryHookSource(
|
|
593
|
+
fs.writeFileSync(hookPath, repositoryHookSource(), { mode: 0o700 });
|
|
627
594
|
try {
|
|
628
595
|
fs.chmodSync(hookPath, 0o700);
|
|
629
596
|
}
|
|
@@ -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
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
|
+
}
|