@codetelemetry/mcp 0.3.0
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 +21 -0
- package/README.md +242 -0
- package/dist/src/client/agent.d.ts +379 -0
- package/dist/src/client/agent.js +204 -0
- package/dist/src/client/codexConfig.d.ts +23 -0
- package/dist/src/client/codexConfig.js +265 -0
- package/dist/src/client/config.d.ts +26 -0
- package/dist/src/client/config.js +32 -0
- package/dist/src/client/connectivity.d.ts +27 -0
- package/dist/src/client/connectivity.js +54 -0
- package/dist/src/client/deviceClient.d.ts +32 -0
- package/dist/src/client/deviceClient.js +112 -0
- package/dist/src/client/keys.d.ts +5 -0
- package/dist/src/client/keys.js +24 -0
- package/dist/src/client/onboard.d.ts +47 -0
- package/dist/src/client/onboard.js +84 -0
- package/dist/src/client/otlp.d.ts +18 -0
- package/dist/src/client/otlp.js +60 -0
- package/dist/src/client/repositoryHook.d.ts +17 -0
- package/dist/src/client/repositoryHook.js +631 -0
- package/dist/src/client/settings.d.ts +28 -0
- package/dist/src/client/settings.js +97 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/manifest.d.ts +29 -0
- package/dist/src/manifest.js +93 -0
- package/dist/src/mcpServer.d.ts +3 -0
- package/dist/src/mcpServer.js +18 -0
- package/dist/src/server.d.ts +2 -0
- package/dist/src/server.js +16 -0
- package/dist/src/session.d.ts +21 -0
- package/dist/src/session.js +44 -0
- package/dist/src/tools.d.ts +28 -0
- package/dist/src/tools.js +697 -0
- package/dist/src/version.d.ts +2 -0
- package/dist/src/version.js +2 -0
- package/package.json +55 -0
- package/tool-manifest.json +474 -0
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
import { resolveEndpoints, resolveSettingsPath, } from "./client/config.js";
|
|
2
|
+
import { writeSettings, readSettingsSummary, } from "./client/settings.js";
|
|
3
|
+
import { resolveCodexConfigPath, writeCodexConfig, readCodexSummary, } from "./client/codexConfig.js";
|
|
4
|
+
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, } from "./client/agent.js";
|
|
7
|
+
import { requestDeviceCode, pollOnce, } from "./client/deviceClient.js";
|
|
8
|
+
import { onboard as onboardCore, } from "./client/onboard.js";
|
|
9
|
+
import { looksLikeKey, scrub, } from "./client/keys.js";
|
|
10
|
+
import { OnboardingSession } from "./session.js";
|
|
11
|
+
import { registryIdentity } from "./manifest.js";
|
|
12
|
+
function endpointsFor(ctx) {
|
|
13
|
+
return resolveEndpoints({
|
|
14
|
+
apiBase: ctx.session.apiBase ?? ctx.endpointsOverride?.apiBase,
|
|
15
|
+
ingestEndpoint: ctx.session.ingestEndpoint ?? ctx.endpointsOverride?.ingestEndpoint,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const NO_KEY = {
|
|
19
|
+
ok: false,
|
|
20
|
+
error: "no_key",
|
|
21
|
+
message: "No ingest key yet. Either pass `key` to get_ingest_key/onboard, or run authenticate then auth_status.",
|
|
22
|
+
};
|
|
23
|
+
const obj = (properties = {}, required = []) => ({
|
|
24
|
+
type: "object",
|
|
25
|
+
properties,
|
|
26
|
+
...(required.length ? { required } : {}),
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
});
|
|
29
|
+
const CLIENT_PROP = {
|
|
30
|
+
type: "string",
|
|
31
|
+
enum: ["claude", "codex"],
|
|
32
|
+
description: "Which coding client to configure: claude → settings.json env block (default); codex → the [otel] section of ~/.codex/config.toml (Codex needs the literal key in the file — it does not expand ${VAR} placeholders).",
|
|
33
|
+
};
|
|
34
|
+
const pickClient = (args) => (args.client === "codex" ? "codex" : "claude");
|
|
35
|
+
const invalidBooleanOptIn = (args) => {
|
|
36
|
+
for (const name of ["enrich", "repositoryObservation"]) {
|
|
37
|
+
if (args[name] !== undefined && typeof args[name] !== "boolean")
|
|
38
|
+
return name;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
const ENRICH_PROP = {
|
|
43
|
+
type: "boolean",
|
|
44
|
+
description: "Opt in to content telemetry (default false). Claude Code uploads prompt text, tool details/content, and raw API request/response bodies; Codex uploads prompt text. These can contain source code, commands, file contents, secrets, or other sensitive data.",
|
|
45
|
+
};
|
|
46
|
+
const REPOSITORY_OBSERVATION_PROP = {
|
|
47
|
+
type: "boolean",
|
|
48
|
+
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
|
+
};
|
|
50
|
+
function configPathFor(client, args, ctx) {
|
|
51
|
+
if (client === "codex") {
|
|
52
|
+
return resolveCodexConfigPath({ path: ctx.configPathsOverride?.codex });
|
|
53
|
+
}
|
|
54
|
+
return resolveSettingsPath({
|
|
55
|
+
scope: args.scope === "project" ? "project" : "user",
|
|
56
|
+
path: ctx.configPathsOverride?.claude,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const MAX_ISSUE_REFERENCE = 512;
|
|
60
|
+
export const ISSUE_SIZING_ERRORS = new Set([
|
|
61
|
+
"no_connected_workspace",
|
|
62
|
+
"ambiguous_connection",
|
|
63
|
+
"connection_not_found",
|
|
64
|
+
"workspace_not_connected",
|
|
65
|
+
"conflicting_selection",
|
|
66
|
+
"connection_needs_reconnect",
|
|
67
|
+
"issue_inaccessible",
|
|
68
|
+
"issue_not_found",
|
|
69
|
+
"empty_issue",
|
|
70
|
+
"invalid_reference",
|
|
71
|
+
"invalid_workspace",
|
|
72
|
+
"read_limit_exceeded",
|
|
73
|
+
"linear_unavailable",
|
|
74
|
+
"linear_not_configured",
|
|
75
|
+
]);
|
|
76
|
+
export const TOOLS = [
|
|
77
|
+
{
|
|
78
|
+
name: "authenticate",
|
|
79
|
+
title: "Authenticate (device code)",
|
|
80
|
+
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.",
|
|
81
|
+
inputSchema: obj(),
|
|
82
|
+
async handler(_args, ctx) {
|
|
83
|
+
const code = await requestDeviceCode(endpointsFor(ctx), ctx.fetchImpl);
|
|
84
|
+
ctx.session.deviceCode = code.deviceCode;
|
|
85
|
+
ctx.session.userCode = code.userCode;
|
|
86
|
+
return {
|
|
87
|
+
ok: true,
|
|
88
|
+
action: "authorize",
|
|
89
|
+
verificationUri: code.verificationUri,
|
|
90
|
+
userCode: code.userCode,
|
|
91
|
+
expiresInSec: code.expiresIn,
|
|
92
|
+
message: `Ask the user to open ${code.verificationUri} and approve code ${code.userCode}, then call auth_status.`,
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "auth_status",
|
|
98
|
+
title: "Check authentication status",
|
|
99
|
+
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).",
|
|
100
|
+
inputSchema: obj(),
|
|
101
|
+
async handler(_args, ctx) {
|
|
102
|
+
if (!ctx.session.deviceCode)
|
|
103
|
+
return { ok: false, status: "no_pending_auth", message: "Call authenticate first." };
|
|
104
|
+
const r = await pollOnce(endpointsFor(ctx), ctx.session.deviceCode, ctx.fetchImpl);
|
|
105
|
+
if (r.status === "authorized") {
|
|
106
|
+
ctx.session.setKey(r.apiKey, "device-flow", r.ingestEndpoint);
|
|
107
|
+
ctx.session.deviceCode = null;
|
|
108
|
+
return { ok: true, status: "authorized", key: { masked: ctx.session.view().masked, keyHash: ctx.session.keyHash } };
|
|
109
|
+
}
|
|
110
|
+
if (r.status === "pending")
|
|
111
|
+
return { ok: true, status: "pending", message: "Not approved yet — ask the user to finish, then call auth_status again." };
|
|
112
|
+
return { ok: false, status: "error", error: r.error };
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "get_ingest_key",
|
|
117
|
+
title: "Get / set the ingest key",
|
|
118
|
+
description: "Record an ingest key for this session. Pass `key` to use a key the user already has (one-time reveal from the dashboard), or omit it to use the key obtained via authenticate/auth_status. Returns only a masked preview + hash — never the plaintext.",
|
|
119
|
+
inputSchema: obj({ key: { type: "string", description: "A cot_… ingest key (optional if already authenticated)." } }),
|
|
120
|
+
async handler(args, ctx) {
|
|
121
|
+
if (typeof args.key === "string" && args.key) {
|
|
122
|
+
if (!looksLikeKey(args.key))
|
|
123
|
+
return { ok: false, error: "bad_key", message: "That doesn't look like a cot_… ingest key." };
|
|
124
|
+
ctx.session.setKey(args.key, "pasted");
|
|
125
|
+
}
|
|
126
|
+
if (!ctx.session.hasKey())
|
|
127
|
+
return NO_KEY;
|
|
128
|
+
const v = ctx.session.view();
|
|
129
|
+
return { ok: true, keyHash: v.keyHash, masked: v.masked, source: v.source };
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "write_local_config",
|
|
134
|
+
title: "Write local OTEL config (Claude Code or Codex)",
|
|
135
|
+
description: "Write the OpenTelemetry exporter config (and the ingest key) into a recognized local client config — Claude Code's user or current-project settings.json, or Codex's active ~/.codex/config.toml (`client: \"codex\"`). 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).",
|
|
136
|
+
inputSchema: obj({
|
|
137
|
+
client: CLIENT_PROP,
|
|
138
|
+
scope: { type: "string", enum: ["user", "project"], description: "Claude only: user → ~/.claude/settings.json (default); project → ./.claude/settings.json." },
|
|
139
|
+
enrich: ENRICH_PROP,
|
|
140
|
+
repositoryObservation: REPOSITORY_OBSERVATION_PROP,
|
|
141
|
+
}),
|
|
142
|
+
async handler(args, ctx) {
|
|
143
|
+
if (!ctx.session.hasKey())
|
|
144
|
+
return NO_KEY;
|
|
145
|
+
const invalidOptIn = invalidBooleanOptIn(args);
|
|
146
|
+
if (invalidOptIn) {
|
|
147
|
+
return { ok: false, error: "bad_input", message: `${invalidOptIn} must be a boolean.` };
|
|
148
|
+
}
|
|
149
|
+
const client = pickClient(args);
|
|
150
|
+
const r = client === "codex"
|
|
151
|
+
? writeCodexConfig({
|
|
152
|
+
key: ctx.session.useKey(),
|
|
153
|
+
ingestEndpoint: endpointsFor(ctx).ingestEndpoint,
|
|
154
|
+
configPath: configPathFor(client, args, ctx),
|
|
155
|
+
enrich: args.enrich === true,
|
|
156
|
+
repositoryObservation: args.repositoryObservation === true,
|
|
157
|
+
})
|
|
158
|
+
: writeSettings({
|
|
159
|
+
key: ctx.session.useKey(),
|
|
160
|
+
ingestEndpoint: endpointsFor(ctx).ingestEndpoint,
|
|
161
|
+
settingsPath: configPathFor(client, args, ctx),
|
|
162
|
+
enrich: args.enrich === true,
|
|
163
|
+
repositoryObservation: args.repositoryObservation === true,
|
|
164
|
+
});
|
|
165
|
+
return { ok: true, path: r.path, wrote: r.wrote, backupPath: r.backupPath, created: r.created };
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: "send_test_event",
|
|
170
|
+
title: "Send a test telemetry event",
|
|
171
|
+
description: "Fire one synthetic OTLP log carrying a unique probe id, so we can prove the pipe works before the user starts a real session. Returns the probe id and the ingest HTTP status.",
|
|
172
|
+
inputSchema: obj(),
|
|
173
|
+
async handler(_args, ctx) {
|
|
174
|
+
if (!ctx.session.hasKey())
|
|
175
|
+
return NO_KEY;
|
|
176
|
+
const r = await sendTestEvent({ key: ctx.session.useKey(), ingestEndpoint: endpointsFor(ctx).ingestEndpoint, fetchImpl: ctx.fetchImpl });
|
|
177
|
+
ctx.session.lastProbeId = r.probeId;
|
|
178
|
+
return { ok: r.ok, probeId: r.probeId, httpStatus: r.httpStatus };
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: "verify_telemetry",
|
|
183
|
+
title: "Confirm telemetry landed",
|
|
184
|
+
description: "Poll the connectivity check until the last test event's probe id is seen in the tenant's data (or a timeout). Confirms the user's telemetry is flowing end to end.",
|
|
185
|
+
inputSchema: obj({ timeoutMs: { type: "number", description: "Max time to wait (default 30000)." } }),
|
|
186
|
+
async handler(args, ctx) {
|
|
187
|
+
if (!ctx.session.hasKey())
|
|
188
|
+
return NO_KEY;
|
|
189
|
+
if (!ctx.session.lastProbeId)
|
|
190
|
+
return { ok: false, error: "no_probe", message: "Call send_test_event first." };
|
|
191
|
+
const r = await confirmLanded({
|
|
192
|
+
key: ctx.session.useKey(),
|
|
193
|
+
connectivityUrl: endpointsFor(ctx).connectivityUrl,
|
|
194
|
+
probeId: ctx.session.lastProbeId,
|
|
195
|
+
timeoutMs: typeof args.timeoutMs === "number" ? args.timeoutMs : undefined,
|
|
196
|
+
fetchImpl: ctx.fetchImpl,
|
|
197
|
+
});
|
|
198
|
+
return { ok: r.landed, landed: r.landed, elapsedMs: r.elapsedMs, polls: r.polls };
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: "onboard",
|
|
203
|
+
title: "Onboard (one shot)",
|
|
204
|
+
description: "Do the whole onboarding in one call: use the session key (or a `key` you pass), write a recognized local client config, 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.",
|
|
205
|
+
inputSchema: obj({
|
|
206
|
+
key: { type: "string", description: "A cot_… ingest key (optional if already authenticated)." },
|
|
207
|
+
client: CLIENT_PROP,
|
|
208
|
+
scope: { type: "string", enum: ["user", "project"], description: "Claude only: which settings.json to write (default user)." },
|
|
209
|
+
enrich: ENRICH_PROP,
|
|
210
|
+
repositoryObservation: REPOSITORY_OBSERVATION_PROP,
|
|
211
|
+
timeoutMs: { type: "number", description: "Verify timeout (default 30000)." },
|
|
212
|
+
}),
|
|
213
|
+
async handler(args, ctx) {
|
|
214
|
+
const invalidOptIn = invalidBooleanOptIn(args);
|
|
215
|
+
if (invalidOptIn) {
|
|
216
|
+
return { ok: false, error: "bad_input", message: `${invalidOptIn} must be a boolean.` };
|
|
217
|
+
}
|
|
218
|
+
if (typeof args.key === "string" && args.key) {
|
|
219
|
+
if (!looksLikeKey(args.key))
|
|
220
|
+
return { ok: false, error: "bad_key", message: "That doesn't look like a cot_… ingest key." };
|
|
221
|
+
ctx.session.setKey(args.key, "pasted");
|
|
222
|
+
}
|
|
223
|
+
if (!ctx.session.hasKey())
|
|
224
|
+
return NO_KEY;
|
|
225
|
+
const result = await onboardCore({
|
|
226
|
+
key: ctx.session.useKey(),
|
|
227
|
+
client: pickClient(args),
|
|
228
|
+
endpoints: {
|
|
229
|
+
apiBase: ctx.session.apiBase ?? ctx.endpointsOverride?.apiBase,
|
|
230
|
+
ingestEndpoint: ctx.session.ingestEndpoint ?? ctx.endpointsOverride?.ingestEndpoint,
|
|
231
|
+
},
|
|
232
|
+
settings: {
|
|
233
|
+
scope: args.scope === "project" ? "project" : "user",
|
|
234
|
+
path: pickClient(args) === "codex"
|
|
235
|
+
? ctx.configPathsOverride?.codex
|
|
236
|
+
: ctx.configPathsOverride?.claude,
|
|
237
|
+
enrich: args.enrich === true,
|
|
238
|
+
repositoryObservation: args.repositoryObservation === true,
|
|
239
|
+
},
|
|
240
|
+
verifyTimeoutMs: typeof args.timeoutMs === "number" ? args.timeoutMs : undefined,
|
|
241
|
+
fetchImpl: ctx.fetchImpl,
|
|
242
|
+
});
|
|
243
|
+
if (result.test?.probeId)
|
|
244
|
+
ctx.session.lastProbeId = result.test.probeId;
|
|
245
|
+
return {
|
|
246
|
+
ok: result.ok,
|
|
247
|
+
steps: result.steps,
|
|
248
|
+
key: result.key,
|
|
249
|
+
settings: { path: result.settings.path, wrote: result.settings.wrote, created: result.settings.created, backupPath: result.settings.backupPath },
|
|
250
|
+
test: result.test ? { probeId: result.test.probeId, httpStatus: result.test.httpStatus, ok: result.test.ok } : null,
|
|
251
|
+
verify: result.verify,
|
|
252
|
+
};
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: "status",
|
|
257
|
+
title: "Onboarding status",
|
|
258
|
+
description: "Read-only diagnostics for a recognized client config: whether a key is held (masked), whether Claude Code's user/current-project settings.json or Codex's active ~/.codex/config.toml has the OTEL config, the resolved endpoints, any pending authorization, and `server` — the MCP build and tool-inventory hash. No secrets.",
|
|
259
|
+
inputSchema: obj({
|
|
260
|
+
client: CLIENT_PROP,
|
|
261
|
+
scope: { type: "string", enum: ["user", "project"], description: "Claude only: which settings.json to inspect (default user)." },
|
|
262
|
+
}),
|
|
263
|
+
async handler(args, ctx) {
|
|
264
|
+
const client = pickClient(args);
|
|
265
|
+
const settingsPath = configPathFor(client, args, ctx);
|
|
266
|
+
const summary = client === "codex" ? readCodexSummary(settingsPath) : readSettingsSummary(settingsPath);
|
|
267
|
+
const ep = endpointsFor(ctx);
|
|
268
|
+
return {
|
|
269
|
+
ok: true,
|
|
270
|
+
server: registryIdentity(TOOLS),
|
|
271
|
+
auth: ctx.session.view(),
|
|
272
|
+
pendingAuth: !!ctx.session.deviceCode,
|
|
273
|
+
lastProbeId: ctx.session.lastProbeId,
|
|
274
|
+
settings: { path: settingsPath, ...summary },
|
|
275
|
+
endpoints: { apiBase: ep.apiBase, ingestEndpoint: ep.ingestEndpoint },
|
|
276
|
+
};
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
name: "get_cost_signal",
|
|
281
|
+
title: "Get cost signal",
|
|
282
|
+
description: "Read this workspace's recent observed model cost — totals, by model, and top repo. `observedCostUsd` is what your model provider charges; CodeTelemetry's fee is 10% of it (`feeUsd`), which is what draws down the credit balance — they're labeled separately. Personal-scope (your own usage). Requires an ingest key (run authenticate/auth_status or pass one to get_ingest_key first).",
|
|
283
|
+
inputSchema: obj(),
|
|
284
|
+
async handler(_args, ctx) {
|
|
285
|
+
if (!ctx.session.hasKey())
|
|
286
|
+
return NO_KEY;
|
|
287
|
+
const r = await getCostSignal({
|
|
288
|
+
key: ctx.session.useKey(),
|
|
289
|
+
url: endpointsFor(ctx).agentCostUrl,
|
|
290
|
+
fetchImpl: ctx.fetchImpl,
|
|
291
|
+
});
|
|
292
|
+
if (!r.ok) {
|
|
293
|
+
return {
|
|
294
|
+
ok: false,
|
|
295
|
+
error: "read_failed",
|
|
296
|
+
message: r.httpStatus === 401 ? "ingest key invalid or revoked" : `cost read returned HTTP ${r.httpStatus}`,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
if (!r.cost)
|
|
300
|
+
return { ok: true, cost: null, message: "No token telemetry yet for this workspace." };
|
|
301
|
+
return { ok: true, cost: r.cost };
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: "search_sessions",
|
|
306
|
+
title: "Search coding sessions",
|
|
307
|
+
description: "Find coding sessions using the same bounded query and filters as the Sessions UI: free text across titles, accepted prompt samples, ids, repos, models, members, and assistants, plus explicit assistant/model/duration filters. Returns metadata and match-field provenance only; raw prompt text is never returned through the ingest-key-authenticated MCP surface.",
|
|
308
|
+
inputSchema: obj({
|
|
309
|
+
q: { type: "string", maxLength: 200, description: "Whitespace-separated terms; every term must match somewhere in the indexed session fields." },
|
|
310
|
+
repo: { type: "string", maxLength: 200, description: "Exact repository filter." },
|
|
311
|
+
model: { type: "string", maxLength: 200, description: "Model-name fragment, such as sol or opus." },
|
|
312
|
+
assistant: { type: "string", enum: ["all", "claude", "codex"], description: "Assistant filter (default all)." },
|
|
313
|
+
minDurationMs: { type: "integer", minimum: 0, maximum: 31_536_000_000, description: "Inclusive minimum elapsed session span in milliseconds." },
|
|
314
|
+
maxDurationMs: { type: "integer", minimum: 0, maximum: 31_536_000_000, description: "Inclusive maximum elapsed session span in milliseconds." },
|
|
315
|
+
sort: { type: "string", enum: ["session", "assistant", "member", "repo", "models", "prompts", "invocations", "tools", "tokens", "cost", "output", "costPerCommit", "duration", "lastSeen"], description: "Sort column (default lastSeen)." },
|
|
316
|
+
direction: { type: "string", enum: ["asc", "desc"], description: "Sort direction (default desc)." },
|
|
317
|
+
limit: { type: "integer", minimum: 1, maximum: 100, description: "Page size (default 25, max 100)." },
|
|
318
|
+
offset: { type: "integer", minimum: 0, maximum: 100000, description: "Page offset." },
|
|
319
|
+
}),
|
|
320
|
+
async handler(args, ctx) {
|
|
321
|
+
if (!ctx.session.hasKey())
|
|
322
|
+
return NO_KEY;
|
|
323
|
+
const r = await searchCodingSessions({
|
|
324
|
+
key: ctx.session.useKey(),
|
|
325
|
+
url: endpointsFor(ctx).agentSessionSearchUrl,
|
|
326
|
+
query: args,
|
|
327
|
+
fetchImpl: ctx.fetchImpl,
|
|
328
|
+
timeoutMs: SESSION_SEARCH_REQUEST_TIMEOUT_MS,
|
|
329
|
+
});
|
|
330
|
+
if (!r.ok) {
|
|
331
|
+
return {
|
|
332
|
+
ok: false,
|
|
333
|
+
error: r.error === "read_timeout" ? "read_timeout" : "read_failed",
|
|
334
|
+
message: r.httpStatus === 401
|
|
335
|
+
? "ingest key invalid or revoked"
|
|
336
|
+
: r.httpStatus === 429
|
|
337
|
+
? "session search rate limit exceeded"
|
|
338
|
+
: r.message ?? r.error ?? `session search returned HTTP ${r.httpStatus}`,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
return { ok: true, report: r.report };
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
name: "get_session_performance",
|
|
346
|
+
title: "Measure session read performance",
|
|
347
|
+
description: "Run the same bounded session-timeline read used by the UI and report cache status, query phases, rows, bytes, and latency. Returns counts only, never prompts, commands, outputs, or other raw content. Personal-scope and ingest-key authenticated.",
|
|
348
|
+
inputSchema: obj({
|
|
349
|
+
sessionId: { type: "string", minLength: 1, maxLength: 200, description: "Session id to measure." },
|
|
350
|
+
includeFresh: { type: "boolean", description: "Also bypass the dashboard cache once to measure a fresh read (default false)." },
|
|
351
|
+
cacheSamples: { type: "integer", minimum: 1, maximum: 3, description: "Number of real dashboard-cache reads to sample (default 2)." },
|
|
352
|
+
}, ["sessionId"]),
|
|
353
|
+
async handler(args, ctx) {
|
|
354
|
+
if (!ctx.session.hasKey())
|
|
355
|
+
return NO_KEY;
|
|
356
|
+
const sessionId = typeof args.sessionId === "string" ? args.sessionId.trim() : "";
|
|
357
|
+
if (!sessionId || sessionId.length > 200) {
|
|
358
|
+
return { ok: false, error: "bad_input", message: "sessionId must contain 1-200 characters" };
|
|
359
|
+
}
|
|
360
|
+
if (args.includeFresh !== undefined && typeof args.includeFresh !== "boolean") {
|
|
361
|
+
return { ok: false, error: "bad_input", message: "includeFresh must be a boolean" };
|
|
362
|
+
}
|
|
363
|
+
if (args.cacheSamples !== undefined &&
|
|
364
|
+
(typeof args.cacheSamples !== "number" || !Number.isInteger(args.cacheSamples) ||
|
|
365
|
+
args.cacheSamples < 1 || args.cacheSamples > 3)) {
|
|
366
|
+
return { ok: false, error: "bad_input", message: "cacheSamples must be an integer from 1 to 3" };
|
|
367
|
+
}
|
|
368
|
+
const r = await getSessionPerformance({
|
|
369
|
+
key: ctx.session.useKey(),
|
|
370
|
+
url: endpointsFor(ctx).agentSessionPerformanceUrl,
|
|
371
|
+
sessionId,
|
|
372
|
+
includeFresh: typeof args.includeFresh === "boolean" ? args.includeFresh : undefined,
|
|
373
|
+
cacheSamples: typeof args.cacheSamples === "number" ? args.cacheSamples : undefined,
|
|
374
|
+
fetchImpl: ctx.fetchImpl,
|
|
375
|
+
timeoutMs: 120_000,
|
|
376
|
+
});
|
|
377
|
+
if (!r.ok) {
|
|
378
|
+
if (r.error === "read_timeout") {
|
|
379
|
+
return {
|
|
380
|
+
ok: false,
|
|
381
|
+
error: "read_timeout",
|
|
382
|
+
message: "Session performance read timed out; retry with includeFresh=false and cacheSamples=1.",
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
ok: false,
|
|
387
|
+
error: "read_failed",
|
|
388
|
+
message: r.httpStatus === 401
|
|
389
|
+
? "ingest key invalid or revoked"
|
|
390
|
+
: r.httpStatus === 429
|
|
391
|
+
? "session performance read rate limit exceeded"
|
|
392
|
+
: r.message ?? `session performance read returned HTTP ${r.httpStatus}`,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
return { ok: true, report: r.report };
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
name: "find_similar_session_errors",
|
|
400
|
+
title: "Find sessions with similar errors",
|
|
401
|
+
description: "Answer 'any other sessions with similar errors?' by matching normalized exact and family signatures within your telemetry. Raw failure text remains inside ClickHouse; results contain safe categories, hash prefixes, counts, session ids, similarity, and query performance only.",
|
|
402
|
+
inputSchema: obj({
|
|
403
|
+
sessionId: { type: "string", minLength: 1, maxLength: 200, description: "Session whose failures should be matched." },
|
|
404
|
+
lookbackDays: { type: "integer", minimum: 1, maximum: 30, description: "Bounded history window (default 30 days)." },
|
|
405
|
+
limit: { type: "integer", minimum: 1, maximum: 20, description: "Maximum matching sessions (default 10)." },
|
|
406
|
+
}, ["sessionId"]),
|
|
407
|
+
async handler(args, ctx) {
|
|
408
|
+
if (!ctx.session.hasKey())
|
|
409
|
+
return NO_KEY;
|
|
410
|
+
const sessionId = typeof args.sessionId === "string" ? args.sessionId.trim() : "";
|
|
411
|
+
if (!sessionId || sessionId.length > 200) {
|
|
412
|
+
return { ok: false, error: "bad_input", message: "sessionId must contain 1-200 characters" };
|
|
413
|
+
}
|
|
414
|
+
if (args.lookbackDays !== undefined &&
|
|
415
|
+
(typeof args.lookbackDays !== "number" || !Number.isInteger(args.lookbackDays) ||
|
|
416
|
+
args.lookbackDays < 1 || args.lookbackDays > 30)) {
|
|
417
|
+
return { ok: false, error: "bad_input", message: "lookbackDays must be an integer from 1 to 30" };
|
|
418
|
+
}
|
|
419
|
+
if (args.limit !== undefined &&
|
|
420
|
+
(typeof args.limit !== "number" || !Number.isInteger(args.limit) || args.limit < 1 || args.limit > 20)) {
|
|
421
|
+
return { ok: false, error: "bad_input", message: "limit must be an integer from 1 to 20" };
|
|
422
|
+
}
|
|
423
|
+
const r = await findSimilarSessionErrors({
|
|
424
|
+
key: ctx.session.useKey(),
|
|
425
|
+
url: endpointsFor(ctx).agentSimilarErrorsUrl,
|
|
426
|
+
sessionId,
|
|
427
|
+
lookbackDays: typeof args.lookbackDays === "number" ? args.lookbackDays : undefined,
|
|
428
|
+
limit: typeof args.limit === "number" ? args.limit : undefined,
|
|
429
|
+
fetchImpl: ctx.fetchImpl,
|
|
430
|
+
timeoutMs: 25_000,
|
|
431
|
+
});
|
|
432
|
+
if (!r.ok) {
|
|
433
|
+
if (r.error === "read_timeout") {
|
|
434
|
+
return {
|
|
435
|
+
ok: false,
|
|
436
|
+
error: "read_timeout",
|
|
437
|
+
message: "Similar-error read timed out; retry with fewer lookbackDays.",
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
ok: false,
|
|
442
|
+
error: "read_failed",
|
|
443
|
+
message: r.httpStatus === 401
|
|
444
|
+
? "ingest key invalid or revoked"
|
|
445
|
+
: r.httpStatus === 429
|
|
446
|
+
? "similar error read rate limit exceeded"
|
|
447
|
+
: r.message ?? `similar error read returned HTTP ${r.httpStatus}`,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
return { ok: true, report: r.report, performance: r.performance };
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
name: "estimate_task_size",
|
|
455
|
+
title: "T-shirt size a task from your history",
|
|
456
|
+
description: "Estimate the effort of a proposed task — t-shirt size, predicted token range, and confidence — from YOUR similar past coding sessions rather than a generic complexity guess. Pass free-form text and/or a Linear issue's fields (identifier/title/description/labels) resolved by your Linear connector. The prediction comes from matched past sessions and is sized against a ladder calibrated from that same history; when confidence is low the result carries a small confidence-building task instead of a falsely precise number.",
|
|
457
|
+
inputSchema: obj({
|
|
458
|
+
taskText: { type: "string", minLength: 1, maxLength: 4000, description: "Free-form description of the task to size." },
|
|
459
|
+
issue: {
|
|
460
|
+
type: "object",
|
|
461
|
+
description: "A Linear (or Linear-shaped) issue. Combined with taskText when both are given.",
|
|
462
|
+
properties: {
|
|
463
|
+
identifier: { type: "string", maxLength: 64, description: "Issue key, e.g. ELL-8." },
|
|
464
|
+
title: { type: "string", maxLength: 512 },
|
|
465
|
+
description: { type: "string", maxLength: 4000 },
|
|
466
|
+
labels: { type: "array", maxItems: 20, items: { type: "string", maxLength: 64 } },
|
|
467
|
+
},
|
|
468
|
+
additionalProperties: false,
|
|
469
|
+
},
|
|
470
|
+
issueKey: { type: "string", maxLength: 64, description: "Linear issue key (e.g. ELL-8) to look up in the connected workspace and size. Resolved through the tenant's DEFAULT connection — an issue key is only unique within a workspace, so prefer `estimate_linear_issue` (which accepts a URL and disambiguates connected workspaces explicitly) when more than one workspace may be connected." },
|
|
471
|
+
repo: { type: "string", maxLength: 200, description: "Repo the work will land in, when known. Selects that repo's calibrated ladder if one exists." },
|
|
472
|
+
linearScale: { type: "string", enum: ["exponential", "fibonacci", "linear", "tShirt"], description: "Also project the size onto this Linear estimate scale. Sizing by issueKey uses the issue's own team scale by default." },
|
|
473
|
+
linearScaleExtended: { type: "boolean", description: "True when that scale is Linear's extended variant (different point values)." },
|
|
474
|
+
lookbackDays: { type: "integer", minimum: 1, maximum: 365, description: "History window to size against (default 90 days)." },
|
|
475
|
+
limit: { type: "integer", minimum: 1, maximum: 5000, description: "Maximum historical sessions to load (default 1000)." },
|
|
476
|
+
}),
|
|
477
|
+
async handler(args, ctx) {
|
|
478
|
+
if (!ctx.session.hasKey())
|
|
479
|
+
return NO_KEY;
|
|
480
|
+
const taskText = typeof args.taskText === "string" ? args.taskText.trim() : "";
|
|
481
|
+
if (args.taskText !== undefined && (typeof args.taskText !== "string" || args.taskText.length > 4_000)) {
|
|
482
|
+
return { ok: false, error: "bad_input", message: "taskText must be a string of at most 4000 characters" };
|
|
483
|
+
}
|
|
484
|
+
let issue;
|
|
485
|
+
if (args.issue !== undefined) {
|
|
486
|
+
if (args.issue === null || typeof args.issue !== "object" || Array.isArray(args.issue)) {
|
|
487
|
+
return { ok: false, error: "bad_input", message: "issue must be an object" };
|
|
488
|
+
}
|
|
489
|
+
const raw = args.issue;
|
|
490
|
+
const str = (v, max) => v === undefined ? undefined : (typeof v === "string" && v.length <= max ? v : null);
|
|
491
|
+
const identifier = str(raw.identifier, 64);
|
|
492
|
+
const title = str(raw.title, 512);
|
|
493
|
+
const description = str(raw.description, 4_000);
|
|
494
|
+
if (identifier === null || title === null || description === null) {
|
|
495
|
+
return { ok: false, error: "bad_input", message: "issue fields must be strings within their length limits" };
|
|
496
|
+
}
|
|
497
|
+
let labels;
|
|
498
|
+
if (raw.labels !== undefined) {
|
|
499
|
+
if (!Array.isArray(raw.labels) || raw.labels.length > 20 ||
|
|
500
|
+
raw.labels.some((l) => typeof l !== "string" || l.length > 64)) {
|
|
501
|
+
return { ok: false, error: "bad_input", message: "issue.labels must be up to 20 strings of at most 64 characters" };
|
|
502
|
+
}
|
|
503
|
+
labels = raw.labels;
|
|
504
|
+
}
|
|
505
|
+
issue = { identifier, title, description, labels };
|
|
506
|
+
}
|
|
507
|
+
const issueKey = args.issueKey;
|
|
508
|
+
if (issueKey !== undefined && (typeof issueKey !== "string" || !issueKey.trim() || issueKey.length > 64)) {
|
|
509
|
+
return { ok: false, error: "bad_input", message: "issueKey must contain 1-64 characters" };
|
|
510
|
+
}
|
|
511
|
+
const issueText = [issue?.title, issue?.description, ...(issue?.labels ?? [])]
|
|
512
|
+
.filter(Boolean).join("").trim();
|
|
513
|
+
if (!taskText && !issueText && !issueKey) {
|
|
514
|
+
return { ok: false, error: "bad_input", message: "Provide taskText or an issue with a title/description to size." };
|
|
515
|
+
}
|
|
516
|
+
for (const [name, max] of [["lookbackDays", 365], ["limit", 5_000]]) {
|
|
517
|
+
const value = args[name];
|
|
518
|
+
if (value !== undefined &&
|
|
519
|
+
(typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > max)) {
|
|
520
|
+
return { ok: false, error: "bad_input", message: `${name} must be an integer from 1 to ${max}` };
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
const repo = args.repo;
|
|
524
|
+
if (repo !== undefined && (typeof repo !== "string" || repo.length > 200)) {
|
|
525
|
+
return { ok: false, error: "bad_input", message: "repo must be a string of at most 200 characters" };
|
|
526
|
+
}
|
|
527
|
+
const linearScale = args.linearScale;
|
|
528
|
+
if (linearScale !== undefined &&
|
|
529
|
+
!["exponential", "fibonacci", "linear", "tShirt"].includes(linearScale)) {
|
|
530
|
+
return { ok: false, error: "bad_input", message: "linearScale must be one of exponential, fibonacci, linear, tShirt" };
|
|
531
|
+
}
|
|
532
|
+
if (args.linearScaleExtended !== undefined && typeof args.linearScaleExtended !== "boolean") {
|
|
533
|
+
return { ok: false, error: "bad_input", message: "linearScaleExtended must be a boolean" };
|
|
534
|
+
}
|
|
535
|
+
const r = await estimateTaskSize({
|
|
536
|
+
key: ctx.session.useKey(),
|
|
537
|
+
url: endpointsFor(ctx).agentTaskSizeUrl,
|
|
538
|
+
taskText: taskText || undefined,
|
|
539
|
+
issue,
|
|
540
|
+
issueKey: typeof issueKey === "string" ? issueKey : undefined,
|
|
541
|
+
repo: typeof repo === "string" ? repo : undefined,
|
|
542
|
+
linearScale: linearScale,
|
|
543
|
+
linearScaleExtended: args.linearScaleExtended,
|
|
544
|
+
lookbackDays: typeof args.lookbackDays === "number" ? args.lookbackDays : undefined,
|
|
545
|
+
limit: typeof args.limit === "number" ? args.limit : undefined,
|
|
546
|
+
fetchImpl: ctx.fetchImpl,
|
|
547
|
+
timeoutMs: 60_000,
|
|
548
|
+
});
|
|
549
|
+
if (!r.ok) {
|
|
550
|
+
if (r.error === "read_timeout") {
|
|
551
|
+
return {
|
|
552
|
+
ok: false,
|
|
553
|
+
error: "read_timeout",
|
|
554
|
+
message: r.message ?? "Task sizing read timed out; retry with fewer lookbackDays.",
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
ok: false,
|
|
559
|
+
error: "read_failed",
|
|
560
|
+
message: r.httpStatus === 401
|
|
561
|
+
? "ingest key invalid or revoked"
|
|
562
|
+
: r.httpStatus === 429
|
|
563
|
+
? "task sizing read rate limit exceeded"
|
|
564
|
+
: r.message ?? r.error ?? `task sizing read returned HTTP ${r.httpStatus}`,
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
return { ok: true, estimate: r.estimate, performance: r.performance };
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
name: "estimate_linear_issue",
|
|
572
|
+
title: "T-shirt size an existing Linear issue",
|
|
573
|
+
description: "Estimate the effort of an EXISTING Linear issue — t-shirt size, predicted token range, and confidence — from YOUR similar past coding sessions. Pass the issue's URL or identifier (e.g. ELL-44); CodeTelemetry resolves it through the Linear workspace the user already connected, so you never paste the issue's contents in and never supply a Linear token. " +
|
|
574
|
+
"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. " +
|
|
575
|
+
"READ-ONLY: it never changes the issue's estimate, description, labels, state, or comments. If more than one connected workspace could hold that identifier the call fails with `ambiguous_connection` and lists them — retry naming one via `workspace` or `connectionId`.",
|
|
576
|
+
inputSchema: obj({
|
|
577
|
+
reference: {
|
|
578
|
+
type: "string",
|
|
579
|
+
minLength: 1,
|
|
580
|
+
maxLength: MAX_ISSUE_REFERENCE,
|
|
581
|
+
description: "The Linear issue to size: an identifier like \"ELL-44\", or a linear.app issue URL. Free-text search is not accepted — resolve the issue first.",
|
|
582
|
+
},
|
|
583
|
+
workspace: {
|
|
584
|
+
type: "string",
|
|
585
|
+
maxLength: 200,
|
|
586
|
+
description: "Which connected Linear workspace to resolve the issue through: its url key, name, or id. Needed only when several connections could match (the failure lists them).",
|
|
587
|
+
},
|
|
588
|
+
connectionId: {
|
|
589
|
+
type: "string",
|
|
590
|
+
maxLength: 128,
|
|
591
|
+
description: "A specific CodeTelemetry Linear connection id (as returned in a `connections` list), when you already know which one to use. It does NOT override `workspace` or the workspace named by an issue URL — every hint you give must agree, or the call fails with `conflicting_selection`. Normally pass either this or `workspace`, not both.",
|
|
592
|
+
},
|
|
593
|
+
repo: { type: "string", maxLength: 200, description: "Repo the work will land in, when known. Selects that repo's calibrated ladder if one exists." },
|
|
594
|
+
linearScale: { type: "string", enum: ["exponential", "fibonacci", "linear", "tShirt"], description: "Project the size onto this Linear estimate scale. Defaults to the issue's own team scale." },
|
|
595
|
+
linearScaleExtended: { type: "boolean", description: "True when that scale is Linear's extended variant (different point values)." },
|
|
596
|
+
lookbackDays: { type: "integer", minimum: 1, maximum: 365, description: "History window to size against (default 90 days)." },
|
|
597
|
+
limit: { type: "integer", minimum: 1, maximum: 5000, description: "Maximum historical sessions to load (default 1000)." },
|
|
598
|
+
}, ["reference"]),
|
|
599
|
+
async handler(args, ctx) {
|
|
600
|
+
if (!ctx.session.hasKey())
|
|
601
|
+
return NO_KEY;
|
|
602
|
+
const reference = typeof args.reference === "string" ? args.reference.trim() : "";
|
|
603
|
+
if (typeof args.reference !== "string" || !reference || args.reference.length > MAX_ISSUE_REFERENCE) {
|
|
604
|
+
return {
|
|
605
|
+
ok: false,
|
|
606
|
+
error: "bad_input",
|
|
607
|
+
message: `reference must be a Linear issue URL or identifier of 1-${MAX_ISSUE_REFERENCE} characters`,
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
for (const [name, max] of [["workspace", 200], ["connectionId", 128], ["repo", 200]]) {
|
|
611
|
+
const value = args[name];
|
|
612
|
+
if (value === undefined)
|
|
613
|
+
continue;
|
|
614
|
+
if (typeof value !== "string" || (name !== "repo" && !value.trim()) || value.length > max) {
|
|
615
|
+
return { ok: false, error: "bad_input", message: `${name} must be a string of at most ${max} characters` };
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
for (const [name, max] of [["lookbackDays", 365], ["limit", 5_000]]) {
|
|
619
|
+
const value = args[name];
|
|
620
|
+
if (value !== undefined &&
|
|
621
|
+
(typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > max)) {
|
|
622
|
+
return { ok: false, error: "bad_input", message: `${name} must be an integer from 1 to ${max}` };
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
const linearScale = args.linearScale;
|
|
626
|
+
if (linearScale !== undefined &&
|
|
627
|
+
!["exponential", "fibonacci", "linear", "tShirt"].includes(linearScale)) {
|
|
628
|
+
return { ok: false, error: "bad_input", message: "linearScale must be one of exponential, fibonacci, linear, tShirt" };
|
|
629
|
+
}
|
|
630
|
+
if (args.linearScaleExtended !== undefined && typeof args.linearScaleExtended !== "boolean") {
|
|
631
|
+
return { ok: false, error: "bad_input", message: "linearScaleExtended must be a boolean" };
|
|
632
|
+
}
|
|
633
|
+
const r = await estimateLinearIssue({
|
|
634
|
+
key: ctx.session.useKey(),
|
|
635
|
+
url: endpointsFor(ctx).agentLinearIssueSizeUrl,
|
|
636
|
+
reference,
|
|
637
|
+
workspace: typeof args.workspace === "string" ? args.workspace : undefined,
|
|
638
|
+
connectionId: typeof args.connectionId === "string" ? args.connectionId : undefined,
|
|
639
|
+
repo: typeof args.repo === "string" ? args.repo : undefined,
|
|
640
|
+
linearScale: linearScale,
|
|
641
|
+
linearScaleExtended: args.linearScaleExtended,
|
|
642
|
+
lookbackDays: typeof args.lookbackDays === "number" ? args.lookbackDays : undefined,
|
|
643
|
+
limit: typeof args.limit === "number" ? args.limit : undefined,
|
|
644
|
+
fetchImpl: ctx.fetchImpl,
|
|
645
|
+
timeoutMs: 60_000,
|
|
646
|
+
});
|
|
647
|
+
if (!r.ok) {
|
|
648
|
+
if (r.error === "read_timeout") {
|
|
649
|
+
return {
|
|
650
|
+
ok: false,
|
|
651
|
+
error: "read_timeout",
|
|
652
|
+
message: r.message ?? "Linear issue sizing timed out; retry with fewer lookbackDays.",
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
if (r.httpStatus === 401) {
|
|
656
|
+
return { ok: false, error: "unauthenticated", message: "ingest key invalid or revoked" };
|
|
657
|
+
}
|
|
658
|
+
if (r.httpStatus === 429) {
|
|
659
|
+
return { ok: false, error: "rate_limited", message: "issue sizing rate limit exceeded — retry shortly" };
|
|
660
|
+
}
|
|
661
|
+
if (r.error && ISSUE_SIZING_ERRORS.has(r.error)) {
|
|
662
|
+
return {
|
|
663
|
+
ok: false,
|
|
664
|
+
error: r.error,
|
|
665
|
+
message: r.message ?? r.error,
|
|
666
|
+
...(r.connections ? { connections: r.connections } : {}),
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
return {
|
|
670
|
+
ok: false,
|
|
671
|
+
error: "sizing_failed",
|
|
672
|
+
message: r.message ?? r.error ?? `Linear issue sizing returned HTTP ${r.httpStatus}`,
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
return {
|
|
676
|
+
ok: true,
|
|
677
|
+
estimate: r.estimate,
|
|
678
|
+
source: r.source,
|
|
679
|
+
note: "Predicts coding-assistant token effort from your own history — not elapsed time or human engineering hours. Read-only: nothing was written back to Linear. `source` says which issue, in which workspace, was sized and shows the normalized text that was matched; the issue's body is carried once, on `estimate.issueSource.description`, capped at 4,000 characters — check `descriptionTruncated` before quoting it as the whole issue.",
|
|
680
|
+
performance: r.performance,
|
|
681
|
+
};
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
];
|
|
685
|
+
export const TOOLS_BY_NAME = Object.fromEntries(TOOLS.map((t) => [t.name, t]));
|
|
686
|
+
export async function callTool(name, args, ctx) {
|
|
687
|
+
const tool = TOOLS_BY_NAME[name];
|
|
688
|
+
if (!tool)
|
|
689
|
+
return { ok: false, error: "unknown_tool", message: `No tool named ${name}.` };
|
|
690
|
+
try {
|
|
691
|
+
const result = await tool.handler(args ?? {}, ctx);
|
|
692
|
+
return JSON.parse(scrub(JSON.stringify(result)));
|
|
693
|
+
}
|
|
694
|
+
catch (err) {
|
|
695
|
+
return { ok: false, error: "tool_error", message: scrub(String(err.message ?? err)) };
|
|
696
|
+
}
|
|
697
|
+
}
|