@codetelemetry/mcp 0.3.9 → 0.3.14

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 (81) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +135 -9
  3. package/dist/src/client/agent.d.ts +201 -3
  4. package/dist/src/client/agent.js +154 -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 +6 -0
  16. package/dist/src/client/config.js +6 -0
  17. package/dist/src/client/graderArtifact.d.ts +14 -0
  18. package/dist/src/client/graderArtifact.js +94 -0
  19. package/dist/src/client/graderSeed.d.ts +50 -0
  20. package/dist/src/client/graderSeed.js +289 -0
  21. package/dist/src/client/hostMetrics.d.ts +54 -0
  22. package/dist/src/client/hostMetrics.js +425 -0
  23. package/dist/src/client/import/browser.d.ts +30 -0
  24. package/dist/src/client/import/browser.js +157 -0
  25. package/dist/src/client/import/convert.d.ts +20 -0
  26. package/dist/src/client/import/convert.js +165 -0
  27. package/dist/src/client/import/core.d.ts +143 -0
  28. package/dist/src/client/import/core.js +441 -0
  29. package/dist/src/client/import/ledger.d.ts +52 -0
  30. package/dist/src/client/import/ledger.js +161 -0
  31. package/dist/src/client/import/model.d.ts +70 -0
  32. package/dist/src/client/import/model.js +42 -0
  33. package/dist/src/client/import/options.d.ts +24 -0
  34. package/dist/src/client/import/options.js +71 -0
  35. package/dist/src/client/import/otlpImport.d.ts +7 -0
  36. package/dist/src/client/import/otlpImport.js +81 -0
  37. package/dist/src/client/import/protocol.d.ts +35 -0
  38. package/dist/src/client/import/protocol.js +51 -0
  39. package/dist/src/client/import/run.d.ts +30 -0
  40. package/dist/src/client/import/run.js +127 -0
  41. package/dist/src/client/import/sources/claudeCodeText.d.ts +19 -0
  42. package/dist/src/client/import/sources/claudeCodeText.js +214 -0
  43. package/dist/src/client/import/sources/codexText.d.ts +20 -0
  44. package/dist/src/client/import/sources/codexText.js +319 -0
  45. package/dist/src/client/import/sources/files.d.ts +24 -0
  46. package/dist/src/client/import/sources/files.js +129 -0
  47. package/dist/src/client/import/transport.d.ts +76 -0
  48. package/dist/src/client/import/transport.js +141 -0
  49. package/dist/src/client/index.d.ts +19 -0
  50. package/dist/src/client/index.js +19 -0
  51. package/dist/src/client/kiro/collector.d.ts +88 -0
  52. package/dist/src/client/kiro/collector.js +577 -0
  53. package/dist/src/client/kiro/command.d.ts +3 -0
  54. package/dist/src/client/kiro/command.js +109 -0
  55. package/dist/src/client/kiro/config.d.ts +39 -0
  56. package/dist/src/client/kiro/config.js +107 -0
  57. package/dist/src/client/kiro/records.d.ts +52 -0
  58. package/dist/src/client/kiro/records.js +206 -0
  59. package/dist/src/client/kiro/service.d.ts +21 -0
  60. package/dist/src/client/kiro/service.js +183 -0
  61. package/dist/src/client/kiro/state.d.ts +45 -0
  62. package/dist/src/client/kiro/state.js +205 -0
  63. package/dist/src/client/kiro/transport.d.ts +9 -0
  64. package/dist/src/client/kiro/transport.js +90 -0
  65. package/dist/src/client/onboard.d.ts +5 -1
  66. package/dist/src/client/onboard.js +28 -23
  67. package/dist/src/client/piConfig.d.ts +29 -0
  68. package/dist/src/client/piConfig.js +112 -0
  69. package/dist/src/client/plan.d.ts +1 -1
  70. package/dist/src/client/plan.js +2 -1
  71. package/dist/src/client/settings.d.ts +4 -0
  72. package/dist/src/client/settings.js +17 -0
  73. package/dist/src/client/yaml.d.ts +5 -0
  74. package/dist/src/client/yaml.js +72 -0
  75. package/dist/src/mcpServer.js +1 -1
  76. package/dist/src/tools.d.ts +9 -6
  77. package/dist/src/tools.js +428 -60
  78. package/dist/src/version.d.ts +1 -1
  79. package/dist/src/version.js +1 -1
  80. package/package.json +178 -9
  81. package/tool-manifest.json +708 -21
@@ -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
+ }
@@ -6,7 +6,7 @@ export declare const MAX_PLAN_STEPS = 50;
6
6
  export declare const MAX_PLAN_REPO = 200;
7
7
  export declare const MAX_PLAN_PROJECT = 200;
8
8
  export declare const MAX_PLAN_MODEL = 120;
9
- export declare const PLAN_PROVIDERS: readonly ["claude", "codex"];
9
+ export declare const PLAN_PROVIDERS: readonly ["claude", "codex", "pi", "kiro"];
10
10
  export type PlanProvider = (typeof PLAN_PROVIDERS)[number];
11
11
  export type PlanStepInput = string | {
12
12
  title?: string;
@@ -1,3 +1,4 @@
1
+ import { ONBOARD_CLIENTS } from "./assistants.js";
1
2
  export const MAX_PLAN_TEXT = 4_000;
2
3
  export const MAX_PLAN_TITLE = 300;
3
4
  export const MAX_PLAN_STEP_TITLE = 300;
@@ -6,7 +7,7 @@ export const MAX_PLAN_STEPS = 50;
6
7
  export const MAX_PLAN_REPO = 200;
7
8
  export const MAX_PLAN_PROJECT = 200;
8
9
  export const MAX_PLAN_MODEL = 120;
9
- export const PLAN_PROVIDERS = ["claude", "codex"];
10
+ export const PLAN_PROVIDERS = ONBOARD_CLIENTS;
10
11
  const bad = (message) => ({ ok: false, message });
11
12
  function boundedString(value, max) {
12
13
  if (value === undefined)
@@ -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
+ }
@@ -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;
@@ -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
+ }
@@ -30,7 +30,7 @@ export function buildServer(ctx) {
30
30
  server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: manifestEntries(TOOLS) }));
31
31
  server.setRequestHandler(CallToolRequestSchema, async (req) => {
32
32
  const result = await callTool(req.params.name, (req.params.arguments ?? {}), ctx);
33
- if (["interpret_session", "read_session_events", "compare_sessions", "plan_next_session"].includes(req.params.name))
33
+ if (["interpret_session", "read_session_events", "compare_sessions", "plan_next_session", "seed_grader_config", "get_grader_config", "update_grader_config", "publish_grader_config", "write_grader_config_artifact"].includes(req.params.name))
34
34
  return boundedToolResponse(result);
35
35
  return {
36
36
  content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
@@ -1,6 +1,5 @@
1
1
  import path from "node:path";
2
- import { type FetchLike } from "./client/otlp.ts";
3
- import { type OnboardClient } from "./client/onboard.ts";
2
+ import { type FetchLike, type OnboardClient } from "./client/index.ts";
4
3
  import { OnboardingSession } from "./session.ts";
5
4
  export type ToolContext = {
6
5
  session: OnboardingSession;
@@ -8,11 +7,15 @@ export type ToolContext = {
8
7
  apiBase?: string;
9
8
  ingestEndpoint?: string;
10
9
  };
11
- configPathsOverride?: {
12
- claude?: string;
13
- codex?: string;
14
- };
10
+ configPathsOverride?: Partial<Record<OnboardClient, string>>;
15
11
  fetchImpl?: FetchLike;
12
+ importOverrides?: {
13
+ claudeDir?: string;
14
+ codexDir?: string;
15
+ ledgerPath?: string;
16
+ nowMs?: number;
17
+ sleep?: (ms: number) => Promise<void>;
18
+ };
16
19
  };
17
20
  export type ToolResult = {
18
21
  ok: boolean;