@codetelemetry/mcp 0.3.7 → 0.3.9
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 +100 -11
- package/dist/src/client/agent.d.ts +20 -0
- package/dist/src/client/agent.js +20 -0
- package/dist/src/client/config.d.ts +2 -0
- package/dist/src/client/config.js +2 -0
- package/dist/src/client/deviceClient.js +11 -5
- package/dist/src/client/plan.d.ts +53 -0
- package/dist/src/client/plan.js +112 -0
- package/dist/src/session.d.ts +7 -0
- package/dist/src/session.js +27 -0
- package/dist/src/tools.d.ts +11 -0
- package/dist/src/tools.js +454 -28
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +5 -5
- package/tool-manifest.json +191 -8
package/dist/src/tools.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
1
4
|
import { resolveEndpoints, resolveSettingsPath, } from "./client/config.js";
|
|
2
5
|
import { writeSettings, readSettingsSummary, } from "./client/settings.js";
|
|
3
6
|
import { resolveCodexConfigPath, writeCodexConfig, readCodexSummary, } from "./client/codexConfig.js";
|
|
4
7
|
import { sendTestEvent, } from "./client/otlp.js";
|
|
5
|
-
import { confirmLanded, } from "./client/connectivity.js";
|
|
6
|
-
import { getCostSignal, getSessionPerformance, findSimilarSessionErrors, searchCodingSessions, SESSION_SEARCH_REQUEST_TIMEOUT_MS, estimateTaskSize, estimateLinearIssue, interpretSession, readSessionEvents, compareSessions, planNextSession, } from "./client/agent.js";
|
|
8
|
+
import { confirmLanded, verifyScope, } from "./client/connectivity.js";
|
|
9
|
+
import { getCostSignal, getSessionPerformance, findSimilarSessionErrors, searchCodingSessions, SESSION_SEARCH_REQUEST_TIMEOUT_MS, estimateTaskSize, estimateLinearIssue, interpretSession, readSessionEvents, compareSessions, planNextSession, readGitHubGate, configureGitHubGate, } from "./client/agent.js";
|
|
10
|
+
import { normalizePlan, PLAN_PROVIDERS, MAX_PLAN_TEXT, MAX_PLAN_STEPS, } from "./client/plan.js";
|
|
7
11
|
import { requestDeviceCode, pollOnce, } from "./client/deviceClient.js";
|
|
8
12
|
import { onboard as onboardCore, } from "./client/onboard.js";
|
|
9
13
|
import { looksLikeKey, scrub, } from "./client/keys.js";
|
|
@@ -47,15 +51,126 @@ const REPOSITORY_OBSERVATION_PROP = {
|
|
|
47
51
|
type: "boolean",
|
|
48
52
|
description: "Install repository-observation hooks (default false). The hooks send the absolute repository root and working-directory paths, repository name, a hashed repository id, session id, and hook event to CodeTelemetry when a session starts/resumes or its workspace changes.",
|
|
49
53
|
};
|
|
50
|
-
|
|
54
|
+
const CLAUDE_CONFIG_FILES = new Set(["settings.json", "settings.local.json"]);
|
|
55
|
+
const CODEX_CONFIG_FILES = new Set(["config.toml"]);
|
|
56
|
+
const MAX_CONFIG_PATH = 1024;
|
|
57
|
+
const MAX_CONFIG_BYTES = 1024 * 1024;
|
|
58
|
+
const PATH_PROP = {
|
|
59
|
+
type: "string",
|
|
60
|
+
minLength: 1,
|
|
61
|
+
maxLength: MAX_CONFIG_PATH,
|
|
62
|
+
description: "Explicit config file, overriding scope and the Codex default: a settings.json or settings.local.json inside a .claude directory (or $CLAUDE_CONFIG_DIR), or with client \"codex\" a config.toml inside a .codex directory (or $CODEX_HOME). A leading ~ is the home directory. Links, network paths and anything but a regular file are refused.",
|
|
63
|
+
};
|
|
64
|
+
export function requestedConfigPath(client, args, pathImpl = path) {
|
|
65
|
+
if (args.path === undefined)
|
|
66
|
+
return { ok: true, path: undefined };
|
|
67
|
+
if (typeof args.path !== "string" || !args.path.trim() || args.path.length > MAX_CONFIG_PATH) {
|
|
68
|
+
return { ok: false, message: `path must be a non-empty string of at most ${MAX_CONFIG_PATH} characters.` };
|
|
69
|
+
}
|
|
70
|
+
const raw = args.path.trim();
|
|
71
|
+
const resolved = pathImpl.resolve(raw === "~" || raw.startsWith("~/") ? pathImpl.join(os.homedir(), raw.slice(1)) : raw);
|
|
72
|
+
if (resolved.startsWith("\\\\")) {
|
|
73
|
+
return { ok: false, message: "path must be a local file, not a network or device path." };
|
|
74
|
+
}
|
|
75
|
+
const dir = pathImpl.dirname(resolved);
|
|
76
|
+
const codex = client === "codex";
|
|
77
|
+
const configDir = codex ? process.env.CODEX_HOME : process.env.CLAUDE_CONFIG_DIR;
|
|
78
|
+
const inClientDir = pathImpl.basename(dir) === (codex ? ".codex" : ".claude")
|
|
79
|
+
|| (!!configDir && pathImpl.resolve(configDir) === dir);
|
|
80
|
+
if (!(codex ? CODEX_CONFIG_FILES : CLAUDE_CONFIG_FILES).has(pathImpl.basename(resolved)) || !inClientDir) {
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
message: codex
|
|
84
|
+
? "path must name a config.toml inside a .codex directory (or $CODEX_HOME)."
|
|
85
|
+
: "path must name a settings.json or settings.local.json inside a .claude directory (or $CLAUDE_CONFIG_DIR).",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
let stat;
|
|
89
|
+
try {
|
|
90
|
+
stat = fs.lstatSync(resolved);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
stat = undefined;
|
|
94
|
+
}
|
|
95
|
+
if (stat && !stat.isFile()) {
|
|
96
|
+
return { ok: false, message: "path must be a regular file, not a link, directory or device." };
|
|
97
|
+
}
|
|
98
|
+
if (stat && stat.size > MAX_CONFIG_BYTES) {
|
|
99
|
+
return { ok: false, message: `path must be a config file of at most ${MAX_CONFIG_BYTES} bytes.` };
|
|
100
|
+
}
|
|
101
|
+
return { ok: true, path: resolved };
|
|
102
|
+
}
|
|
103
|
+
function configPathFor(client, args, ctx, requested) {
|
|
51
104
|
if (client === "codex") {
|
|
52
|
-
return resolveCodexConfigPath({ path: ctx.configPathsOverride?.codex });
|
|
105
|
+
return resolveCodexConfigPath({ path: ctx.configPathsOverride?.codex ?? requested });
|
|
53
106
|
}
|
|
54
107
|
return resolveSettingsPath({
|
|
55
108
|
scope: args.scope === "project" ? "project" : "user",
|
|
56
|
-
path: ctx.configPathsOverride?.claude,
|
|
109
|
+
path: ctx.configPathsOverride?.claude ?? requested,
|
|
57
110
|
});
|
|
58
111
|
}
|
|
112
|
+
const MAX_WORKSPACE_URL = 2048;
|
|
113
|
+
const MAX_ORGANIZATION_ID = 256;
|
|
114
|
+
function recognizedWorkspaceOrigin(value) {
|
|
115
|
+
let url;
|
|
116
|
+
try {
|
|
117
|
+
url = new URL(value.trim());
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
if (url.protocol !== "https:" || url.username || url.password)
|
|
123
|
+
return null;
|
|
124
|
+
const host = url.hostname.toLowerCase();
|
|
125
|
+
if (host !== "codetelemetry.com" && !host.endsWith(".codetelemetry.com"))
|
|
126
|
+
return null;
|
|
127
|
+
return url.origin;
|
|
128
|
+
}
|
|
129
|
+
function originOf(value) {
|
|
130
|
+
try {
|
|
131
|
+
return new URL(value).origin;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function scopeMatches(expected, attested) {
|
|
138
|
+
return (expected.tenantId === undefined || expected.tenantId === attested.tenantId)
|
|
139
|
+
&& (expected.teamId === undefined || expected.teamId === attested.teamId)
|
|
140
|
+
&& (expected.billingAccountId === undefined || expected.billingAccountId === attested.billingAccountId);
|
|
141
|
+
}
|
|
142
|
+
async function scopeCheck(ctx, key, expected, attested) {
|
|
143
|
+
if (attested)
|
|
144
|
+
return scopeMatches(expected, attested) ? "match" : "mismatch";
|
|
145
|
+
try {
|
|
146
|
+
const checked = await verifyScope({
|
|
147
|
+
key,
|
|
148
|
+
connectivityUrl: endpointsFor(ctx).connectivityUrl,
|
|
149
|
+
fetchImpl: ctx.fetchImpl,
|
|
150
|
+
expected,
|
|
151
|
+
});
|
|
152
|
+
if (checked.state === "scope_verified" || checked.state === "budget_exhausted")
|
|
153
|
+
return "match";
|
|
154
|
+
return checked.state === "wrong_scope" ? "mismatch" : "unverified";
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return "unverified";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function endAuthorization(ctx) {
|
|
161
|
+
ctx.session.deviceCode = null;
|
|
162
|
+
ctx.session.userCode = null;
|
|
163
|
+
ctx.session.deviceScopeFenced = false;
|
|
164
|
+
ctx.session.pendingScope = null;
|
|
165
|
+
}
|
|
166
|
+
function wrongScope(expected) {
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
status: "wrong_scope",
|
|
170
|
+
error: "wrong_scope",
|
|
171
|
+
message: `The approved key is not for organization ${expected.teamId}, so it was not kept. Call authenticate again and approve it for that organization.`,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
59
174
|
const MAX_ISSUE_REFERENCE = 512;
|
|
60
175
|
export const ISSUE_SIZING_ERRORS = new Set([
|
|
61
176
|
"no_connected_workspace",
|
|
@@ -223,23 +338,92 @@ function boundedCompareSessionsResult(value) {
|
|
|
223
338
|
message: "The comparison response exceeded the complete MCP response budget; retry with fewer sessions.",
|
|
224
339
|
};
|
|
225
340
|
}
|
|
341
|
+
const GITHUB_GATE_SETTINGS_PATH = "/app/integrations/github";
|
|
342
|
+
const GITHUB_GATE_HOW_TO = {
|
|
343
|
+
workflow: "Commit gate.actions.workflow.content, unchanged, at gate.actions.workflow.path on the default branch of each trusted repository (for example in a pull request the user merges). It runs on pull_request_target, so it takes effect once it is on the default branch.",
|
|
344
|
+
requireCheck: "After the workflow has run once, require the check gate.actions.requiredCheck.name from GitHub Actions on the default branch. With the user's permission and their own gh CLI: gh api -X POST repos/OWNER/REPO/rulesets --input - with gate.actions.rulesetJson as the body. Or Settings > Rules > Rulesets (or Branches) > Require status checks to pass.",
|
|
345
|
+
noSecrets: "Never ask the user for a GitHub token: the workflow authenticates with GitHub's OIDC token and needs only permissions: id-token: write.",
|
|
346
|
+
};
|
|
347
|
+
const GITHUB_GATE_ERRORS = new Set(["invalid", "not_ready", "requires_dashboard", "not_configured", "conflict"]);
|
|
348
|
+
function githubGateFailure(r) {
|
|
349
|
+
if (r.httpStatus === 401)
|
|
350
|
+
return { ok: false, error: "unauthenticated", message: "ingest key invalid or revoked" };
|
|
351
|
+
if (r.httpStatus === 429)
|
|
352
|
+
return { ok: false, error: "rate_limited", message: "GitHub PR gate rate limit exceeded; retry shortly" };
|
|
353
|
+
if (r.error && GITHUB_GATE_ERRORS.has(r.error))
|
|
354
|
+
return { ok: false, error: r.error, message: r.message ?? r.error };
|
|
355
|
+
return { ok: false, error: "github_gate_unavailable", message: r.message ?? r.error ?? `GitHub PR gate returned HTTP ${r.httpStatus}` };
|
|
356
|
+
}
|
|
226
357
|
export const TOOLS = [
|
|
227
358
|
{
|
|
228
359
|
name: "authenticate",
|
|
229
360
|
title: "Authenticate (device code)",
|
|
230
|
-
description: "Begin device-code authentication. Returns a verification URL and a short user code; show them to the human and ask them to approve in a browser, then call auth_status. No password or browser automation is needed.",
|
|
231
|
-
inputSchema: obj(
|
|
232
|
-
|
|
233
|
-
|
|
361
|
+
description: "Begin device-code authentication. Returns a verification URL and a short user code; show them to the human and ask them to approve in a browser, then call auth_status. No password or browser automation is needed. Pass organizationId to connect one of the user's organizations instead of their personal workspace.",
|
|
362
|
+
inputSchema: obj({
|
|
363
|
+
organizationId: {
|
|
364
|
+
type: "string",
|
|
365
|
+
minLength: 1,
|
|
366
|
+
maxLength: MAX_ORGANIZATION_ID,
|
|
367
|
+
description: "Optional organization id. The approval page pre-selects that organization, and auth_status keeps only a key issued to it. Omit it for the personal workspace, or to let the user choose while approving.",
|
|
368
|
+
},
|
|
369
|
+
workspaceUrl: {
|
|
370
|
+
type: "string",
|
|
371
|
+
minLength: 1,
|
|
372
|
+
maxLength: MAX_WORKSPACE_URL,
|
|
373
|
+
description: "Optional CodeTelemetry server to sign in to (default https://codetelemetry.com). Only https URLs on codetelemetry.com or its subdomains are accepted. It picks the server, not an organization.",
|
|
374
|
+
},
|
|
375
|
+
}),
|
|
376
|
+
async handler(args, ctx) {
|
|
377
|
+
let organizationId;
|
|
378
|
+
if (args.organizationId !== undefined) {
|
|
379
|
+
const value = typeof args.organizationId === "string" ? args.organizationId.trim() : "";
|
|
380
|
+
if (!value || value.length > MAX_ORGANIZATION_ID) {
|
|
381
|
+
return { ok: false, error: "bad_input", message: `organizationId must be a non-empty string of at most ${MAX_ORGANIZATION_ID} characters.` };
|
|
382
|
+
}
|
|
383
|
+
organizationId = value;
|
|
384
|
+
}
|
|
385
|
+
let origin = null;
|
|
386
|
+
if (args.workspaceUrl !== undefined) {
|
|
387
|
+
origin = typeof args.workspaceUrl === "string" && args.workspaceUrl.length <= MAX_WORKSPACE_URL
|
|
388
|
+
? recognizedWorkspaceOrigin(args.workspaceUrl)
|
|
389
|
+
: null;
|
|
390
|
+
if (!origin) {
|
|
391
|
+
return { ok: false, error: "bad_input", message: "workspaceUrl must be an https URL on codetelemetry.com or one of its subdomains." };
|
|
392
|
+
}
|
|
393
|
+
const pinned = ctx.endpointsOverride?.apiBase || process.env.CODETELEMETRY_API_BASE;
|
|
394
|
+
if (pinned && originOf(pinned) !== origin) {
|
|
395
|
+
return { ok: false, error: "bad_input", message: "This MCP server's configuration pins the CodeTelemetry server, so workspaceUrl cannot change it." };
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const current = endpointsFor(ctx);
|
|
399
|
+
const switching = origin !== null && origin !== originOf(current.apiBase);
|
|
400
|
+
const endpoints = switching
|
|
401
|
+
? resolveEndpoints({ apiBase: origin, ingestEndpoint: ctx.endpointsOverride?.ingestEndpoint })
|
|
402
|
+
: current;
|
|
403
|
+
const expected = organizationId ? { teamId: organizationId } : undefined;
|
|
404
|
+
const code = await requestDeviceCode(endpoints, ctx.fetchImpl, undefined, expected);
|
|
405
|
+
if (origin !== null) {
|
|
406
|
+
if (switching)
|
|
407
|
+
ctx.session.forgetKey();
|
|
408
|
+
ctx.session.apiBase = origin;
|
|
409
|
+
ctx.session.serverChosenByModel = true;
|
|
410
|
+
}
|
|
234
411
|
ctx.session.deviceCode = code.deviceCode;
|
|
235
412
|
ctx.session.userCode = code.userCode;
|
|
413
|
+
ctx.session.deviceScopeFenced = code.scopeFenced;
|
|
414
|
+
ctx.session.pendingScope = expected ?? null;
|
|
415
|
+
const verificationUriComplete = `${code.verificationUri}?code=${encodeURIComponent(code.userCode)}` +
|
|
416
|
+
(organizationId ? `&teamId=${encodeURIComponent(organizationId)}` : "") +
|
|
417
|
+
(code.scopeFenced ? "&scope=v1" : "");
|
|
236
418
|
return {
|
|
237
419
|
ok: true,
|
|
238
420
|
action: "authorize",
|
|
239
421
|
verificationUri: code.verificationUri,
|
|
422
|
+
verificationUriComplete,
|
|
240
423
|
userCode: code.userCode,
|
|
241
424
|
expiresInSec: code.expiresIn,
|
|
242
|
-
|
|
425
|
+
...(organizationId ? { organizationId } : {}),
|
|
426
|
+
message: `Ask the user to open ${verificationUriComplete} and approve code ${code.userCode}${organizationId ? ` for organization ${organizationId}` : ""}, then call auth_status.`,
|
|
243
427
|
};
|
|
244
428
|
},
|
|
245
429
|
},
|
|
@@ -249,17 +433,63 @@ export const TOOLS = [
|
|
|
249
433
|
description: "Poll the pending device authorization once. Returns 'pending' until the user approves, then 'authorized' (the ingest key is captured into the session — its plaintext is never returned).",
|
|
250
434
|
inputSchema: obj(),
|
|
251
435
|
async handler(_args, ctx) {
|
|
252
|
-
|
|
436
|
+
const pending = {
|
|
437
|
+
deviceCode: ctx.session.deviceCode,
|
|
438
|
+
scopeFenced: ctx.session.deviceScopeFenced,
|
|
439
|
+
expected: ctx.session.pendingScope,
|
|
440
|
+
};
|
|
441
|
+
if (!pending.deviceCode)
|
|
253
442
|
return { ok: false, status: "no_pending_auth", message: "Call authenticate first." };
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
443
|
+
const superseded = () => ctx.session.deviceCode !== pending.deviceCode;
|
|
444
|
+
const SUPERSEDED = { ok: false, status: "superseded", message: "A newer authorization or key replaced this one; nothing was kept." };
|
|
445
|
+
const r = await pollOnce(endpointsFor(ctx), pending.deviceCode, ctx.fetchImpl, undefined, {
|
|
446
|
+
scopeFenced: pending.scopeFenced,
|
|
447
|
+
});
|
|
448
|
+
if (superseded())
|
|
449
|
+
return SUPERSEDED;
|
|
260
450
|
if (r.status === "pending")
|
|
261
451
|
return { ok: true, status: "pending", message: "Not approved yet — ask the user to finish, then call auth_status again." };
|
|
262
|
-
|
|
452
|
+
if (r.status === "error") {
|
|
453
|
+
endAuthorization(ctx);
|
|
454
|
+
return r.error === "wrong_scope" && pending.expected
|
|
455
|
+
? wrongScope(pending.expected)
|
|
456
|
+
: { ok: false, status: "error", error: r.error };
|
|
457
|
+
}
|
|
458
|
+
if (ctx.session.serverChosenByModel && recognizedWorkspaceOrigin(r.ingestEndpoint) === null) {
|
|
459
|
+
endAuthorization(ctx);
|
|
460
|
+
return {
|
|
461
|
+
ok: false,
|
|
462
|
+
status: "error",
|
|
463
|
+
error: "untrusted_ingest_endpoint",
|
|
464
|
+
message: "The server issued an ingest endpoint outside codetelemetry.com, so the key was not kept.",
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
if (pending.expected) {
|
|
468
|
+
const check = await scopeCheck(ctx, r.apiKey, pending.expected, r.scope);
|
|
469
|
+
if (superseded())
|
|
470
|
+
return SUPERSEDED;
|
|
471
|
+
if (check !== "match") {
|
|
472
|
+
endAuthorization(ctx);
|
|
473
|
+
return check === "mismatch"
|
|
474
|
+
? wrongScope(pending.expected)
|
|
475
|
+
: {
|
|
476
|
+
ok: false,
|
|
477
|
+
status: "scope_unverified",
|
|
478
|
+
error: "scope_unverified",
|
|
479
|
+
message: "CodeTelemetry could not confirm the key's organization, so it was not kept. Call authenticate again.",
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
ctx.session.setKey(r.apiKey, "device-flow", r.ingestEndpoint);
|
|
484
|
+
ctx.session.keyScope = r.scope ?? null;
|
|
485
|
+
ctx.session.keyExpectedScope = pending.expected;
|
|
486
|
+
endAuthorization(ctx);
|
|
487
|
+
return {
|
|
488
|
+
ok: true,
|
|
489
|
+
status: "authorized",
|
|
490
|
+
key: { masked: ctx.session.view().masked, keyHash: ctx.session.keyHash },
|
|
491
|
+
...(r.scope ? { organizationId: r.scope.teamId } : {}),
|
|
492
|
+
};
|
|
263
493
|
},
|
|
264
494
|
},
|
|
265
495
|
{
|
|
@@ -282,10 +512,11 @@ export const TOOLS = [
|
|
|
282
512
|
{
|
|
283
513
|
name: "write_local_config",
|
|
284
514
|
title: "Write local OTEL config (Claude Code or Codex)",
|
|
285
|
-
description: "Write the OpenTelemetry exporter config (and the ingest key) into a
|
|
515
|
+
description: "Write the OpenTelemetry exporter config (and the ingest key) into a local client config — Claude Code's user or current-project settings.json, Codex's active ~/.codex/config.toml (`client: \"codex\"`), or an explicit `path` to another settings.json, settings.local.json or config.toml. Preserves existing settings and backs up the file first. Content telemetry and repository-path observation are separate, explicit opt-ins. Returns the path and the KEYS written (never values).",
|
|
286
516
|
inputSchema: obj({
|
|
287
517
|
client: CLIENT_PROP,
|
|
288
518
|
scope: { type: "string", enum: ["user", "project"], description: "Claude only: user → ~/.claude/settings.json (default); project → ./.claude/settings.json." },
|
|
519
|
+
path: PATH_PROP,
|
|
289
520
|
enrich: ENRICH_PROP,
|
|
290
521
|
repositoryObservation: REPOSITORY_OBSERVATION_PROP,
|
|
291
522
|
}),
|
|
@@ -297,18 +528,21 @@ export const TOOLS = [
|
|
|
297
528
|
return { ok: false, error: "bad_input", message: `${invalidOptIn} must be a boolean.` };
|
|
298
529
|
}
|
|
299
530
|
const client = pickClient(args);
|
|
531
|
+
const requested = requestedConfigPath(client, args);
|
|
532
|
+
if (!requested.ok)
|
|
533
|
+
return { ok: false, error: "bad_input", message: requested.message };
|
|
300
534
|
const r = client === "codex"
|
|
301
535
|
? writeCodexConfig({
|
|
302
536
|
key: ctx.session.useKey(),
|
|
303
537
|
ingestEndpoint: endpointsFor(ctx).ingestEndpoint,
|
|
304
|
-
configPath: configPathFor(client, args, ctx),
|
|
538
|
+
configPath: configPathFor(client, args, ctx, requested.path),
|
|
305
539
|
enrich: args.enrich === true,
|
|
306
540
|
repositoryObservation: args.repositoryObservation === true,
|
|
307
541
|
})
|
|
308
542
|
: writeSettings({
|
|
309
543
|
key: ctx.session.useKey(),
|
|
310
544
|
ingestEndpoint: endpointsFor(ctx).ingestEndpoint,
|
|
311
|
-
settingsPath: configPathFor(client, args, ctx),
|
|
545
|
+
settingsPath: configPathFor(client, args, ctx, requested.path),
|
|
312
546
|
enrich: args.enrich === true,
|
|
313
547
|
repositoryObservation: args.repositoryObservation === true,
|
|
314
548
|
});
|
|
@@ -344,18 +578,20 @@ export const TOOLS = [
|
|
|
344
578
|
probeId: ctx.session.lastProbeId,
|
|
345
579
|
timeoutMs: typeof args.timeoutMs === "number" ? args.timeoutMs : undefined,
|
|
346
580
|
fetchImpl: ctx.fetchImpl,
|
|
581
|
+
...(ctx.session.keyExpectedScope ? { expected: ctx.session.keyExpectedScope } : {}),
|
|
347
582
|
});
|
|
348
|
-
return { ok: r.landed, landed: r.landed, elapsedMs: r.elapsedMs, polls: r.polls };
|
|
583
|
+
return { ok: r.landed, landed: r.landed, state: r.state, elapsedMs: r.elapsedMs, polls: r.polls };
|
|
349
584
|
},
|
|
350
585
|
},
|
|
351
586
|
{
|
|
352
587
|
name: "onboard",
|
|
353
588
|
title: "Onboard (one shot)",
|
|
354
|
-
description: "Do the whole onboarding in one call: use the session key (or a `key` you pass), write a recognized local
|
|
589
|
+
description: "Do the whole onboarding in one call: use the session key (or a `key` you pass), write a local client config (the recognized default, or an explicit settings.json, settings.local.json or config.toml `path`), send a test event, and confirm it landed. Content telemetry and repository-path observation are separate, explicit opt-ins. Returns a step-by-step checklist. Run authenticate + auth_status first if you don't already have a key.",
|
|
355
590
|
inputSchema: obj({
|
|
356
591
|
key: { type: "string", description: "A cot_… ingest key (optional if already authenticated)." },
|
|
357
592
|
client: CLIENT_PROP,
|
|
358
593
|
scope: { type: "string", enum: ["user", "project"], description: "Claude only: which settings.json to write (default user)." },
|
|
594
|
+
path: PATH_PROP,
|
|
359
595
|
enrich: ENRICH_PROP,
|
|
360
596
|
repositoryObservation: REPOSITORY_OBSERVATION_PROP,
|
|
361
597
|
timeoutMs: { type: "number", description: "Verify timeout (default 30000)." },
|
|
@@ -365,6 +601,10 @@ export const TOOLS = [
|
|
|
365
601
|
if (invalidOptIn) {
|
|
366
602
|
return { ok: false, error: "bad_input", message: `${invalidOptIn} must be a boolean.` };
|
|
367
603
|
}
|
|
604
|
+
const client = pickClient(args);
|
|
605
|
+
const requested = requestedConfigPath(client, args);
|
|
606
|
+
if (!requested.ok)
|
|
607
|
+
return { ok: false, error: "bad_input", message: requested.message };
|
|
368
608
|
if (typeof args.key === "string" && args.key) {
|
|
369
609
|
if (!looksLikeKey(args.key))
|
|
370
610
|
return { ok: false, error: "bad_key", message: "That doesn't look like a cot_… ingest key." };
|
|
@@ -374,20 +614,21 @@ export const TOOLS = [
|
|
|
374
614
|
return NO_KEY;
|
|
375
615
|
const result = await onboardCore({
|
|
376
616
|
key: ctx.session.useKey(),
|
|
377
|
-
client
|
|
617
|
+
client,
|
|
378
618
|
endpoints: {
|
|
379
619
|
apiBase: ctx.session.apiBase ?? ctx.endpointsOverride?.apiBase,
|
|
380
620
|
ingestEndpoint: ctx.session.ingestEndpoint ?? ctx.endpointsOverride?.ingestEndpoint,
|
|
381
621
|
},
|
|
382
622
|
settings: {
|
|
383
623
|
scope: args.scope === "project" ? "project" : "user",
|
|
384
|
-
path:
|
|
624
|
+
path: (client === "codex"
|
|
385
625
|
? ctx.configPathsOverride?.codex
|
|
386
|
-
: ctx.configPathsOverride?.claude,
|
|
626
|
+
: ctx.configPathsOverride?.claude) ?? requested.path,
|
|
387
627
|
enrich: args.enrich === true,
|
|
388
628
|
repositoryObservation: args.repositoryObservation === true,
|
|
389
629
|
},
|
|
390
630
|
verifyTimeoutMs: typeof args.timeoutMs === "number" ? args.timeoutMs : undefined,
|
|
631
|
+
...(ctx.session.keyExpectedScope ? { expectedScope: ctx.session.keyExpectedScope } : {}),
|
|
391
632
|
fetchImpl: ctx.fetchImpl,
|
|
392
633
|
});
|
|
393
634
|
if (result.test?.probeId)
|
|
@@ -405,14 +646,18 @@ export const TOOLS = [
|
|
|
405
646
|
{
|
|
406
647
|
name: "status",
|
|
407
648
|
title: "Onboarding status",
|
|
408
|
-
description: "Read-only diagnostics for a recognized
|
|
649
|
+
description: "Read-only diagnostics for a client config (the recognized default, or an explicit settings.json, settings.local.json or config.toml `path`): whether a key is held (masked), whether that config has the OTEL settings, the organization requested and attested, the resolved endpoints, any pending authorization, and `server` — the MCP build and tool-inventory hash. No secrets.",
|
|
409
650
|
inputSchema: obj({
|
|
410
651
|
client: CLIENT_PROP,
|
|
411
652
|
scope: { type: "string", enum: ["user", "project"], description: "Claude only: which settings.json to inspect (default user)." },
|
|
653
|
+
path: PATH_PROP,
|
|
412
654
|
}),
|
|
413
655
|
async handler(args, ctx) {
|
|
414
656
|
const client = pickClient(args);
|
|
415
|
-
const
|
|
657
|
+
const requested = requestedConfigPath(client, args);
|
|
658
|
+
if (!requested.ok)
|
|
659
|
+
return { ok: false, error: "bad_input", message: requested.message };
|
|
660
|
+
const settingsPath = configPathFor(client, args, ctx, requested.path);
|
|
416
661
|
const summary = client === "codex" ? readCodexSummary(settingsPath) : readSettingsSummary(settingsPath);
|
|
417
662
|
const ep = endpointsFor(ctx);
|
|
418
663
|
return {
|
|
@@ -420,6 +665,10 @@ export const TOOLS = [
|
|
|
420
665
|
server: registryIdentity(TOOLS),
|
|
421
666
|
auth: ctx.session.view(),
|
|
422
667
|
pendingAuth: !!ctx.session.deviceCode,
|
|
668
|
+
organization: {
|
|
669
|
+
requested: (ctx.session.pendingScope ?? ctx.session.keyExpectedScope)?.teamId ?? null,
|
|
670
|
+
key: ctx.session.keyScope ? (ctx.session.keyScope.teamId ?? "personal") : null,
|
|
671
|
+
},
|
|
423
672
|
lastProbeId: ctx.session.lastProbeId,
|
|
424
673
|
settings: { path: settingsPath, ...summary },
|
|
425
674
|
endpoints: { apiBase: ep.apiBase, ingestEndpoint: ep.ingestEndpoint },
|
|
@@ -873,6 +1122,91 @@ export const TOOLS = [
|
|
|
873
1122
|
return { ok: true, estimate: r.estimate, performance: r.performance };
|
|
874
1123
|
},
|
|
875
1124
|
},
|
|
1125
|
+
{
|
|
1126
|
+
name: "estimate_plan",
|
|
1127
|
+
title: "T-shirt size a Claude Code / Codex plan",
|
|
1128
|
+
description: "Estimate the effort of a plan a coding assistant proposed — t-shirt size, predicted token range, and confidence — from YOUR similar past coding sessions. Submit the plan content explicitly as `planText` and/or ordered `steps`; the server cannot read the agent's hidden state, so whatever you don't pass isn't sized. The plan is sized as ONE unit: submitted step boundaries are preserved in `source` for provenance, but the estimate is never the sum of independently sized steps. " +
|
|
1129
|
+
"The number predicts CODING-ASSISTANT TOKEN EFFORT, not elapsed time or human engineering hours. When the matched history is weak or contradictory the result is low confidence and carries a small calibration task instead of a falsely precise number. Read-only: it never edits the plan, creates issues, or starts work.",
|
|
1130
|
+
inputSchema: obj({
|
|
1131
|
+
planText: { type: "string", minLength: 1, maxLength: MAX_PLAN_TEXT, description: "The plan as plain text. Combined with `steps` when both are given." },
|
|
1132
|
+
steps: {
|
|
1133
|
+
type: "array",
|
|
1134
|
+
maxItems: MAX_PLAN_STEPS,
|
|
1135
|
+
description: "Ordered plan steps. Each item is a string (the step's detail) or an object { title?, detail? }. Order is preserved in the result's source metadata.",
|
|
1136
|
+
items: {
|
|
1137
|
+
oneOf: [
|
|
1138
|
+
{ type: "string", minLength: 1, maxLength: 4000 },
|
|
1139
|
+
{
|
|
1140
|
+
type: "object",
|
|
1141
|
+
properties: {
|
|
1142
|
+
title: { type: "string", maxLength: 300 },
|
|
1143
|
+
detail: { type: "string", maxLength: 4000 },
|
|
1144
|
+
},
|
|
1145
|
+
additionalProperties: false,
|
|
1146
|
+
},
|
|
1147
|
+
],
|
|
1148
|
+
},
|
|
1149
|
+
},
|
|
1150
|
+
title: { type: "string", maxLength: 300, description: "Optional plan title, used as the leading line of the sized text." },
|
|
1151
|
+
repo: { type: "string", maxLength: 200, description: "Repo the work will land in, when known. Selects that repo's calibrated ladder if one exists." },
|
|
1152
|
+
project: { type: "string", maxLength: 200, description: "Optional project/product grouping. Recorded as context; does not change the estimate." },
|
|
1153
|
+
provider: { type: "string", enum: [...PLAN_PROVIDERS], description: "Which coding assistant produced the plan (claude or codex). Recorded as context; does not change the estimate." },
|
|
1154
|
+
model: { type: "string", maxLength: 120, description: "Model id the caller knows produced the plan. Recorded as context; does not change the estimate." },
|
|
1155
|
+
lookbackDays: { type: "integer", minimum: 1, maximum: 365, description: "History window to size against (default 90 days)." },
|
|
1156
|
+
limit: { type: "integer", minimum: 1, maximum: 5000, description: "Maximum historical sessions to load (default 1000)." },
|
|
1157
|
+
}),
|
|
1158
|
+
async handler(args, ctx) {
|
|
1159
|
+
if (!ctx.session.hasKey())
|
|
1160
|
+
return NO_KEY;
|
|
1161
|
+
for (const [name, max] of [["lookbackDays", 365], ["limit", 5_000]]) {
|
|
1162
|
+
const value = args[name];
|
|
1163
|
+
if (value !== undefined &&
|
|
1164
|
+
(typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > max)) {
|
|
1165
|
+
return { ok: false, error: "bad_input", message: `${name} must be an integer from 1 to ${max}` };
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
const normalized = normalizePlan(args);
|
|
1169
|
+
if (!normalized.ok) {
|
|
1170
|
+
return { ok: false, error: "bad_input", message: normalized.message };
|
|
1171
|
+
}
|
|
1172
|
+
const { taskText, repo, source } = normalized.plan;
|
|
1173
|
+
const r = await estimateTaskSize({
|
|
1174
|
+
key: ctx.session.useKey(),
|
|
1175
|
+
url: endpointsFor(ctx).agentTaskSizeUrl,
|
|
1176
|
+
taskText,
|
|
1177
|
+
repo,
|
|
1178
|
+
lookbackDays: typeof args.lookbackDays === "number" ? args.lookbackDays : undefined,
|
|
1179
|
+
limit: typeof args.limit === "number" ? args.limit : undefined,
|
|
1180
|
+
fetchImpl: ctx.fetchImpl,
|
|
1181
|
+
timeoutMs: 60_000,
|
|
1182
|
+
});
|
|
1183
|
+
if (!r.ok) {
|
|
1184
|
+
if (r.error === "read_timeout") {
|
|
1185
|
+
return {
|
|
1186
|
+
ok: false,
|
|
1187
|
+
error: "read_timeout",
|
|
1188
|
+
message: r.message ?? "Plan sizing read timed out; retry with fewer lookbackDays.",
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
return {
|
|
1192
|
+
ok: false,
|
|
1193
|
+
error: "read_failed",
|
|
1194
|
+
message: r.httpStatus === 401
|
|
1195
|
+
? "ingest key invalid or revoked"
|
|
1196
|
+
: r.httpStatus === 429
|
|
1197
|
+
? "task sizing read rate limit exceeded"
|
|
1198
|
+
: r.message ?? r.error ?? `plan sizing read returned HTTP ${r.httpStatus}`,
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
return {
|
|
1202
|
+
ok: true,
|
|
1203
|
+
estimate: r.estimate,
|
|
1204
|
+
source,
|
|
1205
|
+
note: "Predicts coding-assistant token effort from your own history — not elapsed time or human engineering hours. The whole plan is sized as one unit; step boundaries in `source` are provenance, not independently summed estimates.",
|
|
1206
|
+
performance: r.performance,
|
|
1207
|
+
};
|
|
1208
|
+
},
|
|
1209
|
+
},
|
|
876
1210
|
{
|
|
877
1211
|
name: "estimate_linear_issue",
|
|
878
1212
|
title: "T-shirt size an existing Linear issue",
|
|
@@ -987,6 +1321,98 @@ export const TOOLS = [
|
|
|
987
1321
|
};
|
|
988
1322
|
},
|
|
989
1323
|
},
|
|
1324
|
+
{
|
|
1325
|
+
name: "get_github_pr_gate",
|
|
1326
|
+
title: "Read the GitHub PR gate",
|
|
1327
|
+
description: "Use this when the user wants to set up, check, or understand their CodeTelemetry GitHub PR gate: a required GitHub check that blocks a pull request whose coding session did not meet the workspace's validation policy. " +
|
|
1328
|
+
"Returns the gate exactly as its settings page shows it: the policy (enabled, minScore, missingScore, complexityAware, requireTestBeforePush), the trusted repositories, the GitHub Actions workflow file to commit (actions.workflow.path and its exact content), the check to require (actions.requiredCheck), nextSteps still outstanding, and recent decisions. " +
|
|
1329
|
+
"Setup needs no GitHub token or secret: the workflow authenticates to CodeTelemetry with the OIDC token GitHub mints for each run. Read-only.",
|
|
1330
|
+
inputSchema: obj(),
|
|
1331
|
+
async handler(_args, ctx) {
|
|
1332
|
+
if (!ctx.session.hasKey())
|
|
1333
|
+
return NO_KEY;
|
|
1334
|
+
const ep = endpointsFor(ctx);
|
|
1335
|
+
const r = await readGitHubGate({ key: ctx.session.useKey(), url: ep.agentGitHubGateUrl, fetchImpl: ctx.fetchImpl });
|
|
1336
|
+
if (!r.ok || !r.gate)
|
|
1337
|
+
return githubGateFailure(r);
|
|
1338
|
+
return { ok: true, gate: r.gate, settingsUrl: `${ep.apiBase}${GITHUB_GATE_SETTINGS_PATH}`, howTo: GITHUB_GATE_HOW_TO };
|
|
1339
|
+
},
|
|
1340
|
+
},
|
|
1341
|
+
{
|
|
1342
|
+
name: "configure_github_pr_gate",
|
|
1343
|
+
title: "Configure the GitHub PR gate",
|
|
1344
|
+
description: "Use this when the user asks to set up or change their CodeTelemetry GitHub PR gate. Change only what they asked for. " +
|
|
1345
|
+
"addRepositories / removeRepositories take owner/repo, owner/* (every repository of that owner), or a github.com URL; the repository you are working in is usually the one to add. " +
|
|
1346
|
+
"Policy: minScore (0-100), missingScore (pass lets a PR with no session or no score through; fail blocks it), complexityAware (simple work needs a lower score), requireTestBeforePush, and enabled. Enabling needs at least one trusted repository. " +
|
|
1347
|
+
"Once the gate is enabled, a change that loosens it (turning it off, lowering minScore, missingScore fail to pass, turning complexityAware on, dropping requireTestBeforePush) is refused with requires_dashboard: the gate judges your own work, so the user makes that change on the settings page. " +
|
|
1348
|
+
"Returns the updated gate. GitHub enforces nothing until the workflow in gate.actions.workflow is committed to each trusted repository's default branch and the check in gate.actions.requiredCheck is required there; howTo says how.",
|
|
1349
|
+
inputSchema: obj({
|
|
1350
|
+
addRepositories: {
|
|
1351
|
+
type: "array",
|
|
1352
|
+
maxItems: 20,
|
|
1353
|
+
items: { type: "string", minLength: 3, maxLength: 300 },
|
|
1354
|
+
description: "Repositories to trust: owner/repo, owner/*, or a github.com repository URL.",
|
|
1355
|
+
},
|
|
1356
|
+
removeRepositories: {
|
|
1357
|
+
type: "array",
|
|
1358
|
+
maxItems: 20,
|
|
1359
|
+
items: { type: "string", minLength: 3, maxLength: 300 },
|
|
1360
|
+
description: "Repositories to stop trusting. Their checks are then refused, which blocks rather than passes.",
|
|
1361
|
+
},
|
|
1362
|
+
enabled: { type: "boolean", description: "Turn the gate on. Turning it off is a loosening: the user does that on the settings page." },
|
|
1363
|
+
minScore: { type: "integer", minimum: 0, maximum: 100, description: "The validation score a PR's session must reach (default 70)." },
|
|
1364
|
+
missingScore: { type: "string", enum: ["pass", "fail"], description: "What happens when no session or no score can be found for a PR (default pass)." },
|
|
1365
|
+
complexityAware: { type: "boolean", description: "Trivial work always passes and low-complexity work needs half the score." },
|
|
1366
|
+
requireTestBeforePush: { type: "boolean", description: "Every linked session must pass its required checks after its final edit and before pushing." },
|
|
1367
|
+
}),
|
|
1368
|
+
async handler(args, ctx) {
|
|
1369
|
+
if (!ctx.session.hasKey())
|
|
1370
|
+
return NO_KEY;
|
|
1371
|
+
const change = {};
|
|
1372
|
+
for (const name of ["addRepositories", "removeRepositories"]) {
|
|
1373
|
+
const value = args[name];
|
|
1374
|
+
if (value === undefined)
|
|
1375
|
+
continue;
|
|
1376
|
+
if (!Array.isArray(value) || value.length > 20 ||
|
|
1377
|
+
!value.every((item) => typeof item === "string" && item.trim().length >= 3 && item.length <= 300)) {
|
|
1378
|
+
return { ok: false, error: "bad_input", message: `${name} must be a list of at most 20 repositories (owner/repo or owner/*)` };
|
|
1379
|
+
}
|
|
1380
|
+
change[name] = value.map((item) => item.trim());
|
|
1381
|
+
}
|
|
1382
|
+
for (const name of ["enabled", "complexityAware", "requireTestBeforePush"]) {
|
|
1383
|
+
if (args[name] === undefined)
|
|
1384
|
+
continue;
|
|
1385
|
+
if (typeof args[name] !== "boolean")
|
|
1386
|
+
return { ok: false, error: "bad_input", message: `${name} must be a boolean` };
|
|
1387
|
+
change[name] = args[name];
|
|
1388
|
+
}
|
|
1389
|
+
if (args.minScore !== undefined) {
|
|
1390
|
+
const score = args.minScore;
|
|
1391
|
+
if (typeof score !== "number" || !Number.isInteger(score) || score < 0 || score > 100) {
|
|
1392
|
+
return { ok: false, error: "bad_input", message: "minScore must be an integer from 0 to 100" };
|
|
1393
|
+
}
|
|
1394
|
+
change.minScore = score;
|
|
1395
|
+
}
|
|
1396
|
+
if (args.missingScore !== undefined) {
|
|
1397
|
+
if (args.missingScore !== "pass" && args.missingScore !== "fail") {
|
|
1398
|
+
return { ok: false, error: "bad_input", message: "missingScore must be pass or fail" };
|
|
1399
|
+
}
|
|
1400
|
+
change.missingScore = args.missingScore;
|
|
1401
|
+
}
|
|
1402
|
+
if (Object.keys(change).length === 0) {
|
|
1403
|
+
return { ok: false, error: "bad_input", message: "Nothing to change: pass a repository list or a policy field." };
|
|
1404
|
+
}
|
|
1405
|
+
const ep = endpointsFor(ctx);
|
|
1406
|
+
const r = await configureGitHubGate({ key: ctx.session.useKey(), url: ep.agentGitHubGateConfigureUrl, change, fetchImpl: ctx.fetchImpl });
|
|
1407
|
+
if (!r.ok || !r.gate) {
|
|
1408
|
+
const failure = githubGateFailure(r);
|
|
1409
|
+
return r.error === "requires_dashboard"
|
|
1410
|
+
? { ...failure, settingsUrl: `${ep.apiBase}${GITHUB_GATE_SETTINGS_PATH}` }
|
|
1411
|
+
: failure;
|
|
1412
|
+
}
|
|
1413
|
+
return { ok: true, gate: r.gate, settingsUrl: `${ep.apiBase}${GITHUB_GATE_SETTINGS_PATH}`, howTo: GITHUB_GATE_HOW_TO };
|
|
1414
|
+
},
|
|
1415
|
+
},
|
|
990
1416
|
];
|
|
991
1417
|
export const TOOLS_BY_NAME = Object.fromEntries(TOOLS.map((t) => [t.name, t]));
|
|
992
1418
|
export async function callTool(name, args, ctx) {
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const MCP_SERVER_NAME = "codetelemetry";
|
|
2
|
-
export declare const MCP_SERVER_VERSION = "0.3.
|
|
2
|
+
export declare const MCP_SERVER_VERSION = "0.3.9";
|
package/dist/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const MCP_SERVER_NAME = "codetelemetry";
|
|
2
|
-
export const MCP_SERVER_VERSION = "0.3.
|
|
2
|
+
export const MCP_SERVER_VERSION = "0.3.9";
|