@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/README.md
CHANGED
|
@@ -31,7 +31,7 @@ deterministic (see [Releases & discovery](#releases--discovery)):
|
|
|
31
31
|
```json
|
|
32
32
|
{
|
|
33
33
|
"mcpServers": {
|
|
34
|
-
"codetelemetry": { "command": "npx", "args": ["-y", "--package=@codetelemetry/mcp@0.3.
|
|
34
|
+
"codetelemetry": { "command": "npx", "args": ["-y", "--package=@codetelemetry/mcp@0.3.9", "codetelemetry-mcp"] }
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
```
|
|
@@ -42,10 +42,10 @@ Then just ask the agent: **"Connect me to CodeTelemetry."**
|
|
|
42
42
|
|
|
43
43
|
| Tool | What it does |
|
|
44
44
|
| --- | --- |
|
|
45
|
-
| `authenticate` | Start device-code auth; returns a URL + short code for the human to approve. |
|
|
45
|
+
| `authenticate` | Start device-code auth; returns a URL + short code for the human to approve. Optional `organizationId` connects one of the user's organizations; optional `workspaceUrl` picks a CodeTelemetry server (codetelemetry.com hosts only). |
|
|
46
46
|
| `auth_status` | Poll the approval; on success captures the key into the session (masked-only to the model). |
|
|
47
47
|
| `get_ingest_key` | Record a pasted key (fast path) or report the authenticated one — masked + hash only. |
|
|
48
|
-
| `write_local_config` | Merge the OTEL config + key into
|
|
48
|
+
| `write_local_config` | Merge the OTEL config + key into Claude Code's or Codex's config (the default, or an explicit `path` to a `settings.json`/`settings.local.json` in a `.claude` directory or a `config.toml` in a `.codex` directory); preserves + backs up. |
|
|
49
49
|
| `send_test_event` | Fire one OTLP probe log with a unique id. |
|
|
50
50
|
| `verify_telemetry` | Poll the connectivity check until the probe lands. |
|
|
51
51
|
| `onboard` | One-shot: key → config → test → verify, returns a checklist. |
|
|
@@ -59,21 +59,58 @@ Then just ask the agent: **"Connect me to CodeTelemetry."**
|
|
|
59
59
|
| `get_session_performance` | Measure a session timeline's fresh/cache latency, rows, bytes, and query phases without returning content. |
|
|
60
60
|
| `find_similar_session_errors` | Find other personal-scope sessions with matching normalized failure signatures and report query performance. |
|
|
61
61
|
| `estimate_task_size` | T-shirt size a proposed task (free-form text or a Linear-shaped issue) from the caller's own history. |
|
|
62
|
+
| `estimate_plan` | T-shirt size a Claude Code / Codex **plan** (plain text or ordered steps) from the caller's own history. |
|
|
62
63
|
| `estimate_linear_issue` | T-shirt size an **existing Linear issue** by URL or identifier, resolved through the workspace the user already connected. |
|
|
64
|
+
| `get_github_pr_gate` | Read the workspace's GitHub PR gate as its settings page shows it: the policy, trusted repositories, the GitHub Actions workflow file to commit, the check to require, outstanding steps, and recent decisions. |
|
|
65
|
+
| `configure_github_pr_gate` | Set up or change the GitHub PR gate: trust repositories (`owner/repo` or `owner/*`), set the policy, enable it. Once the gate is on, a change that loosens it is refused (`requires_dashboard`) and the user makes it on the settings page. No GitHub token is involved: the workflow authenticates with GitHub's own OIDC token. |
|
|
63
66
|
|
|
64
67
|
Typical agent flow: `authenticate` → (human approves) → `auth_status` →
|
|
65
68
|
`onboard`. Or, if the user pastes a key: `onboard { key }`.
|
|
66
69
|
|
|
70
|
+
GitHub PR gate flow, run from inside the repository to gate:
|
|
71
|
+
`configure_github_pr_gate { addRepositories: ["owner/repo"], enabled: true }` →
|
|
72
|
+
commit `gate.actions.workflow.content` at `gate.actions.workflow.path` (a PR
|
|
73
|
+
the user merges) → once it has run, the user requires
|
|
74
|
+
`codetelemetry/validation` from GitHub Actions on the default branch (`howTo`
|
|
75
|
+
gives the `gh api` ruleset command to run with their permission).
|
|
76
|
+
|
|
77
|
+
## Organizations
|
|
78
|
+
|
|
79
|
+
Without an `organizationId`, the key goes wherever the user picks while approving:
|
|
80
|
+
their personal workspace or one of their organizations. To connect an
|
|
81
|
+
organization on purpose, pass its id, shown in parentheses next to each
|
|
82
|
+
organization on the approval page:
|
|
83
|
+
|
|
84
|
+
```jsonc
|
|
85
|
+
// tool: authenticate
|
|
86
|
+
{ "organizationId": "<organization id>" }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The approval link then pre-selects that organization, the sign-in runs on the
|
|
90
|
+
scope-fenced route, and `auth_status` keeps the key only when CodeTelemetry
|
|
91
|
+
attests that it belongs to that organization. Otherwise it answers `wrong_scope`
|
|
92
|
+
(or `scope_unverified` when the organization could not be confirmed) and discards
|
|
93
|
+
the key. `onboard` and `verify_telemetry` repeat the check against
|
|
94
|
+
the connectivity endpoint. `workspaceUrl` is unrelated: it picks the CodeTelemetry
|
|
95
|
+
server, not an organization.
|
|
96
|
+
|
|
67
97
|
## Data and local changes
|
|
68
98
|
|
|
69
99
|
The default setup writes only the OpenTelemetry exporter endpoint and ingest
|
|
70
|
-
credential to the selected client's
|
|
71
|
-
|
|
72
|
-
`
|
|
73
|
-
|
|
74
|
-
`
|
|
75
|
-
|
|
76
|
-
|
|
100
|
+
credential to the selected client's config file: Claude Code's user or
|
|
101
|
+
current-project `settings.json`, or Codex's active `config.toml`. An explicit
|
|
102
|
+
`path` may name another config file of the same client, and nothing else: a
|
|
103
|
+
`settings.json` or `settings.local.json` inside a `.claude` directory (or
|
|
104
|
+
`$CLAUDE_CONFIG_DIR`), or a `config.toml` inside a `.codex` directory (or
|
|
105
|
+
`$CODEX_HOME`). A leading `~` is the home directory; links, network paths and
|
|
106
|
+
anything but a regular file are refused, and a path the host pins outranks the
|
|
107
|
+
model's. Authentication uses `https://codetelemetry.com` unless `authenticate` is
|
|
108
|
+
given a `workspaceUrl`, which must be an https URL on codetelemetry.com or one of
|
|
109
|
+
its subdomains and cannot override a server the MCP configuration pins. Moving to
|
|
110
|
+
another server drops any key from the old one, and telemetry goes to the ingest
|
|
111
|
+
endpoint the new server issues with its key. Existing config is preserved, backed
|
|
112
|
+
up before a change, and the resulting file is made owner-readable only where the
|
|
113
|
+
platform supports it.
|
|
77
114
|
|
|
78
115
|
Two higher-sensitivity features are off by default and require separate boolean
|
|
79
116
|
opt-ins:
|
|
@@ -93,6 +130,54 @@ on prompt/body telemetry, and `enrich` does not install repository hooks. A late
|
|
|
93
130
|
run with `repositoryObservation` omitted or false removes only CodeTelemetry's
|
|
94
131
|
managed hook entries and helper/state files; unrelated user hooks are preserved.
|
|
95
132
|
|
|
133
|
+
## Estimating a plan
|
|
134
|
+
|
|
135
|
+
`estimate_plan` predicts the **coding-assistant token effort** of a plan from the
|
|
136
|
+
user's own similar past sessions — not elapsed time or human engineering hours.
|
|
137
|
+
The client must submit the plan content **explicitly** (the server never reads the
|
|
138
|
+
agent's hidden state), and the whole plan is sized as **one** unit: submitted step
|
|
139
|
+
boundaries are preserved in `source` for provenance but are never summed as
|
|
140
|
+
independent estimates. It is read-only — it never edits the plan, creates issues,
|
|
141
|
+
or starts work. Weak or contradictory history yields a **low-confidence** result
|
|
142
|
+
carrying a small calibration task rather than a falsely precise number.
|
|
143
|
+
|
|
144
|
+
**Claude Code** — after Claude drafts a plan, ask it to size that plan. Claude
|
|
145
|
+
passes its own plan text/steps explicitly:
|
|
146
|
+
|
|
147
|
+
```jsonc
|
|
148
|
+
// tool: estimate_plan
|
|
149
|
+
{
|
|
150
|
+
"title": "Add a rate limiter to the ingest API",
|
|
151
|
+
"steps": [
|
|
152
|
+
{ "title": "Token bucket", "detail": "per-tenant bucket in the ingest middleware" },
|
|
153
|
+
{ "title": "Config", "detail": "expose the limit + window as env vars" },
|
|
154
|
+
"Add unit and integration tests for the limiter"
|
|
155
|
+
],
|
|
156
|
+
"repo": "elo",
|
|
157
|
+
"provider": "claude",
|
|
158
|
+
"model": "claude-opus-4-8"
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Codex** — the same tool from a Codex session. Pass the plan as plain text (or
|
|
163
|
+
steps) and set `provider: "codex"`:
|
|
164
|
+
|
|
165
|
+
```jsonc
|
|
166
|
+
// tool: estimate_plan
|
|
167
|
+
{
|
|
168
|
+
"title": "Backfill Linear estimates",
|
|
169
|
+
"planText": "1. Read settled sessions for the window\n2. Size each by actual token usage\n3. Write the estimate + provenance back to Linear behind a confirm gate",
|
|
170
|
+
"repo": "elo",
|
|
171
|
+
"provider": "codex"
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The result carries the shared sizing schema (`estimate`: size, predicted token
|
|
176
|
+
range, confidence with reasons, comparable-work evidence, optional calibration
|
|
177
|
+
task), plus normalized `source` metadata (title, format, preserved step
|
|
178
|
+
boundaries, repo/project/provider/model) and a `note` restating that the number is
|
|
179
|
+
token effort, not time.
|
|
180
|
+
|
|
96
181
|
## Estimating a Linear issue
|
|
97
182
|
|
|
98
183
|
`estimate_linear_issue` sizes an issue that **already exists** in Linear, so you
|
|
@@ -212,7 +297,7 @@ npm run smoke -- --tarball out.tgz --require-auth # exactly these by
|
|
|
212
297
|
and read `server`:
|
|
213
298
|
|
|
214
299
|
```jsonc
|
|
215
|
-
"server": { "name": "codetelemetry", "version": "0.3.
|
|
300
|
+
"server": { "name": "codetelemetry", "version": "0.3.9", "registryHash": "cb420922…", "toolCount": 21 }
|
|
216
301
|
```
|
|
217
302
|
|
|
218
303
|
**When a long-running client sees a new tool.** `tools/list` is requested once, at
|
|
@@ -252,3 +337,7 @@ npm run test:protocol # drives the tools through a real MCP client/server pair
|
|
|
252
337
|
npm run test:packaged # packs, launches the artifact, runs the release smoke
|
|
253
338
|
npm run typecheck
|
|
254
339
|
```
|
|
340
|
+
|
|
341
|
+
`npm test`, `test:protocol` and `test:e2e` load `test/support/isolateHome.ts`, which
|
|
342
|
+
points `HOME`, `USERPROFILE` and `CODEX_HOME` at a throwaway directory, so a test can
|
|
343
|
+
never rewrite your own `~/.claude/settings.json` or Codex config.
|
|
@@ -445,6 +445,26 @@ export declare function readSessionEvents(opts: {
|
|
|
445
445
|
error: string | null;
|
|
446
446
|
message: string | null;
|
|
447
447
|
}>;
|
|
448
|
+
export type GitHubGateResult = {
|
|
449
|
+
ok: boolean;
|
|
450
|
+
gate: Record<string, unknown> | null;
|
|
451
|
+
httpStatus: number;
|
|
452
|
+
error: string | null;
|
|
453
|
+
message: string | null;
|
|
454
|
+
};
|
|
455
|
+
export declare function readGitHubGate(opts: {
|
|
456
|
+
key: string;
|
|
457
|
+
url: string;
|
|
458
|
+
fetchImpl?: FetchLike;
|
|
459
|
+
timeoutMs?: number;
|
|
460
|
+
}): Promise<GitHubGateResult>;
|
|
461
|
+
export declare function configureGitHubGate(opts: {
|
|
462
|
+
key: string;
|
|
463
|
+
url: string;
|
|
464
|
+
change: Record<string, unknown>;
|
|
465
|
+
fetchImpl?: FetchLike;
|
|
466
|
+
timeoutMs?: number;
|
|
467
|
+
}): Promise<GitHubGateResult>;
|
|
448
468
|
export declare function compareSessions(opts: {
|
|
449
469
|
key: string;
|
|
450
470
|
url: string;
|
package/dist/src/client/agent.js
CHANGED
|
@@ -231,6 +231,26 @@ export async function readSessionEvents(opts) {
|
|
|
231
231
|
message: result.message,
|
|
232
232
|
};
|
|
233
233
|
}
|
|
234
|
+
export async function readGitHubGate(opts) {
|
|
235
|
+
const result = await postAgent({ ...opts, body: {} });
|
|
236
|
+
return {
|
|
237
|
+
ok: result.ok,
|
|
238
|
+
gate: result.ok ? result.value?.gate ?? null : null,
|
|
239
|
+
httpStatus: result.httpStatus,
|
|
240
|
+
error: result.error,
|
|
241
|
+
message: result.message,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
export async function configureGitHubGate(opts) {
|
|
245
|
+
const result = await postAgent({ ...opts, body: opts.change });
|
|
246
|
+
return {
|
|
247
|
+
ok: result.ok,
|
|
248
|
+
gate: result.ok ? result.value?.gate ?? null : null,
|
|
249
|
+
httpStatus: result.httpStatus,
|
|
250
|
+
error: result.error,
|
|
251
|
+
message: result.message,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
234
254
|
export async function compareSessions(opts) {
|
|
235
255
|
const result = await postAgent({
|
|
236
256
|
...opts,
|
|
@@ -21,6 +21,8 @@ export type Endpoints = {
|
|
|
21
21
|
agentReadSessionEventsUrl: string;
|
|
22
22
|
agentCompareSessionsUrl: string;
|
|
23
23
|
agentPlanNextSessionUrl: string;
|
|
24
|
+
agentGitHubGateUrl: string;
|
|
25
|
+
agentGitHubGateConfigureUrl: string;
|
|
24
26
|
};
|
|
25
27
|
export declare function resolveEndpoints(overrides?: Partial<{
|
|
26
28
|
apiBase: string;
|
|
@@ -28,6 +28,8 @@ export function resolveEndpoints(overrides = {}) {
|
|
|
28
28
|
agentReadSessionEventsUrl: `${apiBase}/api/agent/read-session-events`,
|
|
29
29
|
agentCompareSessionsUrl: `${apiBase}/api/agent/compare-sessions`,
|
|
30
30
|
agentPlanNextSessionUrl: `${apiBase}/api/agent/plan-next-session`,
|
|
31
|
+
agentGitHubGateUrl: `${apiBase}/api/agent/github-gate`,
|
|
32
|
+
agentGitHubGateConfigureUrl: `${apiBase}/api/agent/github-gate/configure`,
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
35
|
export function resolveSettingsPath(opts = {}) {
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
const TERMINAL_ERRORS = new Set(["expired_token", "invalid_grant", "access_denied"]);
|
|
1
|
+
const TERMINAL_ERRORS = new Set(["expired_token", "invalid_grant", "access_denied", "wrong_scope"]);
|
|
2
|
+
function tokenError(body, fallback) {
|
|
3
|
+
return body.state === "wrong_scope" ? "wrong_scope" : String(body.error ?? fallback);
|
|
4
|
+
}
|
|
5
|
+
function issuedIngestEndpoint(body, endpoints) {
|
|
6
|
+
return typeof body.ingest_endpoint === "string" && body.ingest_endpoint ? body.ingest_endpoint : endpoints.ingestEndpoint;
|
|
7
|
+
}
|
|
2
8
|
export async function requestDeviceCode(endpoints, fetchImpl = fetch, timeoutMs = 10_000, expected) {
|
|
3
9
|
const scopeFenced = !!expected && Object.keys(expected).length > 0;
|
|
4
10
|
const codeUrl = scopeFenced ? endpoints.deviceScopedCodeUrl : endpoints.deviceCodeUrl;
|
|
@@ -90,11 +96,11 @@ export async function pollOnce(endpoints, deviceCode, fetchImpl = fetch, timeout
|
|
|
90
96
|
return {
|
|
91
97
|
status: "authorized",
|
|
92
98
|
apiKey: String(j.api_key),
|
|
93
|
-
ingestEndpoint:
|
|
99
|
+
ingestEndpoint: issuedIngestEndpoint(j, endpoints),
|
|
94
100
|
...(scope ? { scope } : {}),
|
|
95
101
|
};
|
|
96
102
|
}
|
|
97
|
-
const error =
|
|
103
|
+
const error = tokenError(j, "authorization_pending");
|
|
98
104
|
return TERMINAL_ERRORS.has(error) ? { status: "error", error } : { status: "pending" };
|
|
99
105
|
}
|
|
100
106
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -119,11 +125,11 @@ export async function pollForKey(endpoints, deviceCode, opts = {}) {
|
|
|
119
125
|
const scope = keyScope(j.scope);
|
|
120
126
|
return {
|
|
121
127
|
apiKey: String(j.api_key),
|
|
122
|
-
ingestEndpoint:
|
|
128
|
+
ingestEndpoint: issuedIngestEndpoint(j, endpoints),
|
|
123
129
|
...(scope ? { scope } : {}),
|
|
124
130
|
};
|
|
125
131
|
}
|
|
126
|
-
const error =
|
|
132
|
+
const error = tokenError(j, res.status >= 500 ? "server_error" : "authorization_pending");
|
|
127
133
|
if (TERMINAL_ERRORS.has(error)) {
|
|
128
134
|
throw new Error(`device authorization ${error}`);
|
|
129
135
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare const MAX_PLAN_TEXT = 4000;
|
|
2
|
+
export declare const MAX_PLAN_TITLE = 300;
|
|
3
|
+
export declare const MAX_PLAN_STEP_TITLE = 300;
|
|
4
|
+
export declare const MAX_PLAN_STEP_DETAIL = 4000;
|
|
5
|
+
export declare const MAX_PLAN_STEPS = 50;
|
|
6
|
+
export declare const MAX_PLAN_REPO = 200;
|
|
7
|
+
export declare const MAX_PLAN_PROJECT = 200;
|
|
8
|
+
export declare const MAX_PLAN_MODEL = 120;
|
|
9
|
+
export declare const PLAN_PROVIDERS: readonly ["claude", "codex"];
|
|
10
|
+
export type PlanProvider = (typeof PLAN_PROVIDERS)[number];
|
|
11
|
+
export type PlanStepInput = string | {
|
|
12
|
+
title?: string;
|
|
13
|
+
detail?: string;
|
|
14
|
+
};
|
|
15
|
+
export type PlanInput = {
|
|
16
|
+
planText?: string;
|
|
17
|
+
steps?: PlanStepInput[];
|
|
18
|
+
title?: string;
|
|
19
|
+
repo?: string;
|
|
20
|
+
project?: string;
|
|
21
|
+
provider?: PlanProvider;
|
|
22
|
+
model?: string;
|
|
23
|
+
};
|
|
24
|
+
export type PlanSourceStep = {
|
|
25
|
+
index: number;
|
|
26
|
+
title: string | null;
|
|
27
|
+
chars: number;
|
|
28
|
+
};
|
|
29
|
+
export type PlanSource = {
|
|
30
|
+
kind: "plan";
|
|
31
|
+
title: string | null;
|
|
32
|
+
format: "text" | "steps" | "text+steps";
|
|
33
|
+
stepCount: number;
|
|
34
|
+
steps: PlanSourceStep[];
|
|
35
|
+
repo: string | null;
|
|
36
|
+
project: string | null;
|
|
37
|
+
provider: PlanProvider | null;
|
|
38
|
+
model: string | null;
|
|
39
|
+
contentChars: number;
|
|
40
|
+
};
|
|
41
|
+
export type NormalizedPlan = {
|
|
42
|
+
taskText: string;
|
|
43
|
+
repo?: string;
|
|
44
|
+
source: PlanSource;
|
|
45
|
+
};
|
|
46
|
+
export type NormalizePlanResult = {
|
|
47
|
+
ok: true;
|
|
48
|
+
plan: NormalizedPlan;
|
|
49
|
+
} | {
|
|
50
|
+
ok: false;
|
|
51
|
+
message: string;
|
|
52
|
+
};
|
|
53
|
+
export declare function normalizePlan(raw: Record<string, unknown>): NormalizePlanResult;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export const MAX_PLAN_TEXT = 4_000;
|
|
2
|
+
export const MAX_PLAN_TITLE = 300;
|
|
3
|
+
export const MAX_PLAN_STEP_TITLE = 300;
|
|
4
|
+
export const MAX_PLAN_STEP_DETAIL = 4_000;
|
|
5
|
+
export const MAX_PLAN_STEPS = 50;
|
|
6
|
+
export const MAX_PLAN_REPO = 200;
|
|
7
|
+
export const MAX_PLAN_PROJECT = 200;
|
|
8
|
+
export const MAX_PLAN_MODEL = 120;
|
|
9
|
+
export const PLAN_PROVIDERS = ["claude", "codex"];
|
|
10
|
+
const bad = (message) => ({ ok: false, message });
|
|
11
|
+
function boundedString(value, max) {
|
|
12
|
+
if (value === undefined)
|
|
13
|
+
return undefined;
|
|
14
|
+
if (typeof value !== "string" || value.length > max)
|
|
15
|
+
return null;
|
|
16
|
+
return value.trim();
|
|
17
|
+
}
|
|
18
|
+
export function normalizePlan(raw) {
|
|
19
|
+
const planText = boundedString(raw.planText, MAX_PLAN_TEXT);
|
|
20
|
+
if (planText === null) {
|
|
21
|
+
return bad(`planText must be a string of at most ${MAX_PLAN_TEXT} characters`);
|
|
22
|
+
}
|
|
23
|
+
const title = boundedString(raw.title, MAX_PLAN_TITLE);
|
|
24
|
+
if (title === null)
|
|
25
|
+
return bad(`title must be a string of at most ${MAX_PLAN_TITLE} characters`);
|
|
26
|
+
const repo = boundedString(raw.repo, MAX_PLAN_REPO);
|
|
27
|
+
if (repo === null)
|
|
28
|
+
return bad(`repo must be a string of at most ${MAX_PLAN_REPO} characters`);
|
|
29
|
+
const project = boundedString(raw.project, MAX_PLAN_PROJECT);
|
|
30
|
+
if (project === null)
|
|
31
|
+
return bad(`project must be a string of at most ${MAX_PLAN_PROJECT} characters`);
|
|
32
|
+
const model = boundedString(raw.model, MAX_PLAN_MODEL);
|
|
33
|
+
if (model === null)
|
|
34
|
+
return bad(`model must be a string of at most ${MAX_PLAN_MODEL} characters`);
|
|
35
|
+
let provider;
|
|
36
|
+
if (raw.provider !== undefined) {
|
|
37
|
+
if (typeof raw.provider !== "string" || !PLAN_PROVIDERS.includes(raw.provider)) {
|
|
38
|
+
return bad(`provider must be one of ${PLAN_PROVIDERS.join(", ")}`);
|
|
39
|
+
}
|
|
40
|
+
provider = raw.provider;
|
|
41
|
+
}
|
|
42
|
+
const stepLines = [];
|
|
43
|
+
const sourceSteps = [];
|
|
44
|
+
if (raw.steps !== undefined) {
|
|
45
|
+
if (!Array.isArray(raw.steps))
|
|
46
|
+
return bad("steps must be an array");
|
|
47
|
+
if (raw.steps.length > MAX_PLAN_STEPS)
|
|
48
|
+
return bad(`steps must contain at most ${MAX_PLAN_STEPS} items`);
|
|
49
|
+
for (let i = 0; i < raw.steps.length; i++) {
|
|
50
|
+
const step = raw.steps[i];
|
|
51
|
+
let stepTitle;
|
|
52
|
+
let stepDetail;
|
|
53
|
+
if (typeof step === "string") {
|
|
54
|
+
stepDetail = step.trim();
|
|
55
|
+
}
|
|
56
|
+
else if (step !== null && typeof step === "object" && !Array.isArray(step)) {
|
|
57
|
+
const obj = step;
|
|
58
|
+
const t = boundedString(obj.title, MAX_PLAN_STEP_TITLE);
|
|
59
|
+
const d = boundedString(obj.detail, MAX_PLAN_STEP_DETAIL);
|
|
60
|
+
if (t === null)
|
|
61
|
+
return bad(`steps[${i}].title must be a string of at most ${MAX_PLAN_STEP_TITLE} characters`);
|
|
62
|
+
if (d === null)
|
|
63
|
+
return bad(`steps[${i}].detail must be a string of at most ${MAX_PLAN_STEP_DETAIL} characters`);
|
|
64
|
+
stepTitle = t || undefined;
|
|
65
|
+
stepDetail = d || undefined;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return bad(`steps[${i}] must be a string or an object with title/detail`);
|
|
69
|
+
}
|
|
70
|
+
if (!stepTitle && !stepDetail) {
|
|
71
|
+
return bad(`steps[${i}] must have a non-empty title or detail`);
|
|
72
|
+
}
|
|
73
|
+
const label = stepTitle && stepDetail ? `${stepTitle}: ${stepDetail}` : stepTitle ?? stepDetail;
|
|
74
|
+
stepLines.push(`${i + 1}. ${label}`);
|
|
75
|
+
sourceSteps.push({
|
|
76
|
+
index: i + 1,
|
|
77
|
+
title: stepTitle ?? null,
|
|
78
|
+
chars: (stepTitle?.length ?? 0) + (stepDetail?.length ?? 0),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const hasText = !!planText;
|
|
83
|
+
const hasSteps = sourceSteps.length > 0;
|
|
84
|
+
if (!hasText && !hasSteps) {
|
|
85
|
+
return bad("Provide planText or at least one step to estimate.");
|
|
86
|
+
}
|
|
87
|
+
const parts = [];
|
|
88
|
+
if (title)
|
|
89
|
+
parts.push(title);
|
|
90
|
+
if (planText)
|
|
91
|
+
parts.push(planText);
|
|
92
|
+
if (hasSteps)
|
|
93
|
+
parts.push(`Plan steps:\n${stepLines.join("\n")}`);
|
|
94
|
+
const taskText = parts.join("\n\n");
|
|
95
|
+
if (taskText.length > MAX_PLAN_TEXT) {
|
|
96
|
+
return bad(`Assembled plan is ${taskText.length} characters; keep title, plan text, and steps under ${MAX_PLAN_TEXT} together.`);
|
|
97
|
+
}
|
|
98
|
+
const format = hasText && hasSteps ? "text+steps" : hasSteps ? "steps" : "text";
|
|
99
|
+
const source = {
|
|
100
|
+
kind: "plan",
|
|
101
|
+
title: title || null,
|
|
102
|
+
format,
|
|
103
|
+
stepCount: sourceSteps.length,
|
|
104
|
+
steps: sourceSteps,
|
|
105
|
+
repo: repo || null,
|
|
106
|
+
project: project || null,
|
|
107
|
+
provider: provider ?? null,
|
|
108
|
+
model: model || null,
|
|
109
|
+
contentChars: taskText.length,
|
|
110
|
+
};
|
|
111
|
+
return { ok: true, plan: { taskText, ...(repo ? { repo } : {}), source } };
|
|
112
|
+
}
|
package/dist/src/session.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ExpectedKeyScope, KeyScope } from "./client/connectivity.ts";
|
|
1
2
|
export type KeySource = "device-flow" | "pasted";
|
|
2
3
|
export declare class OnboardingSession {
|
|
3
4
|
#private;
|
|
@@ -8,7 +9,13 @@ export declare class OnboardingSession {
|
|
|
8
9
|
deviceCode: string | null;
|
|
9
10
|
userCode: string | null;
|
|
10
11
|
lastProbeId: string | null;
|
|
12
|
+
pendingScope: ExpectedKeyScope | null;
|
|
13
|
+
deviceScopeFenced: boolean;
|
|
14
|
+
keyScope: KeyScope | null;
|
|
15
|
+
keyExpectedScope: ExpectedKeyScope | null;
|
|
16
|
+
serverChosenByModel: boolean;
|
|
11
17
|
setKey(plaintext: string, source: KeySource, ingestEndpoint?: string): void;
|
|
18
|
+
forgetKey(): void;
|
|
12
19
|
hasKey(): boolean;
|
|
13
20
|
useKey(): string;
|
|
14
21
|
view(): {
|
package/dist/src/session.js
CHANGED
|
@@ -8,6 +8,11 @@ export class OnboardingSession {
|
|
|
8
8
|
deviceCode = null;
|
|
9
9
|
userCode = null;
|
|
10
10
|
lastProbeId = null;
|
|
11
|
+
pendingScope = null;
|
|
12
|
+
deviceScopeFenced = false;
|
|
13
|
+
keyScope = null;
|
|
14
|
+
keyExpectedScope = null;
|
|
15
|
+
serverChosenByModel = false;
|
|
11
16
|
setKey(plaintext, source, ingestEndpoint) {
|
|
12
17
|
if (!looksLikeKey(plaintext))
|
|
13
18
|
throw new Error("not a valid CodeTelemetry ingest key (expected cot_…)");
|
|
@@ -16,6 +21,23 @@ export class OnboardingSession {
|
|
|
16
21
|
this.source = source;
|
|
17
22
|
if (ingestEndpoint)
|
|
18
23
|
this.ingestEndpoint = ingestEndpoint;
|
|
24
|
+
this.keyScope = null;
|
|
25
|
+
this.keyExpectedScope = null;
|
|
26
|
+
if (source === "pasted") {
|
|
27
|
+
this.pendingScope = null;
|
|
28
|
+
this.deviceCode = null;
|
|
29
|
+
this.userCode = null;
|
|
30
|
+
this.deviceScopeFenced = false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
forgetKey() {
|
|
34
|
+
this.#key = null;
|
|
35
|
+
this.keyHash = null;
|
|
36
|
+
this.source = null;
|
|
37
|
+
this.keyScope = null;
|
|
38
|
+
this.keyExpectedScope = null;
|
|
39
|
+
this.ingestEndpoint = null;
|
|
40
|
+
this.lastProbeId = null;
|
|
19
41
|
}
|
|
20
42
|
hasKey() {
|
|
21
43
|
return this.#key !== null;
|
|
@@ -40,5 +62,10 @@ export class OnboardingSession {
|
|
|
40
62
|
this.deviceCode = null;
|
|
41
63
|
this.userCode = null;
|
|
42
64
|
this.lastProbeId = null;
|
|
65
|
+
this.pendingScope = null;
|
|
66
|
+
this.deviceScopeFenced = false;
|
|
67
|
+
this.keyScope = null;
|
|
68
|
+
this.keyExpectedScope = null;
|
|
69
|
+
this.serverChosenByModel = false;
|
|
43
70
|
}
|
|
44
71
|
}
|
package/dist/src/tools.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { type FetchLike } from "./client/otlp.ts";
|
|
3
|
+
import { type OnboardClient } from "./client/onboard.ts";
|
|
2
4
|
import { OnboardingSession } from "./session.ts";
|
|
3
5
|
export type ToolContext = {
|
|
4
6
|
session: OnboardingSession;
|
|
@@ -22,6 +24,14 @@ export type ToolDef = {
|
|
|
22
24
|
inputSchema: Record<string, unknown>;
|
|
23
25
|
handler: (args: Record<string, unknown>, ctx: ToolContext) => Promise<ToolResult>;
|
|
24
26
|
};
|
|
27
|
+
type RequestedPath = {
|
|
28
|
+
ok: true;
|
|
29
|
+
path: string | undefined;
|
|
30
|
+
} | {
|
|
31
|
+
ok: false;
|
|
32
|
+
message: string;
|
|
33
|
+
};
|
|
34
|
+
export declare function requestedConfigPath(client: OnboardClient, args: Record<string, unknown>, pathImpl?: path.PlatformPath): RequestedPath;
|
|
25
35
|
export declare const ISSUE_SIZING_ERRORS: ReadonlySet<string>;
|
|
26
36
|
export declare const INTERPRET_SESSION_STATES: ReadonlySet<string>;
|
|
27
37
|
export declare const COMPARE_SESSION_STATES: ReadonlySet<string>;
|
|
@@ -30,3 +40,4 @@ export declare const READ_SESSION_EVENTS_STATES: ReadonlySet<string>;
|
|
|
30
40
|
export declare const TOOLS: ToolDef[];
|
|
31
41
|
export declare const TOOLS_BY_NAME: Record<string, ToolDef>;
|
|
32
42
|
export declare function callTool(name: string, args: Record<string, unknown>, ctx: ToolContext): Promise<ToolResult>;
|
|
43
|
+
export {};
|