@codetelemetry/mcp 0.3.12 → 0.4.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/README.md CHANGED
@@ -31,19 +31,105 @@ 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.12", "codetelemetry-mcp"] }
34
+ "codetelemetry": { "command": "npx", "args": ["-y", "--package=@codetelemetry/mcp@0.4.0", "codetelemetry-mcp"] }
35
35
  }
36
36
  }
37
37
  ```
38
38
 
39
39
  Then just ask the agent: **"Connect me to CodeTelemetry."**
40
40
 
41
+ ## Persistent organization workspaces
42
+
43
+ Ask the agent: **Create a Acme workspace for this repository and configure its Grader.**
44
+ It calls `bootstrap_workspace` with a stable local context name, the repository path,
45
+ and either `organizationName` (new) or `organizationId` (existing). Select checks
46
+ with `seed_grader_config` and pass the reviewed `checks` and `features`; `publish`
47
+ explicitly publishes them, and `terraform` leaves an IaC artifact.
48
+
49
+ The first call returns one browser approval URL. The page identifies the signed-in
50
+ account and destination, supports changing account, and creates a requested new
51
+ organization. Resume with just the same `name`. The private checkpoint survives
52
+ MCP restarts, expired device codes and interrupted responses. Creation uses the
53
+ same operation ID on retries; existing organizations are selected by ID, never name.
54
+
55
+ ```sh
56
+ npx -y @codetelemetry/connect bootstrap acme \
57
+ --organization-name "Acme" --client codex --project /path/to/repository
58
+ # After approval (or funding), resume the exact saved plan:
59
+ npx -y @codetelemetry/connect bootstrap acme
60
+ npx -y @codetelemetry/connect workspace list
61
+ ```
62
+
63
+ `--plan file.json` supplies the same bootstrap fields as the MCP tool, including
64
+ selected Grader checks. CLI exit 2 means setup is waiting for the returned action;
65
+ exit 0 means the requested checks completed. Funding is checked before client
66
+ configuration. No credits or seats are purchased. Content and repository observation
67
+ remain separate explicit opt-ins.
68
+
69
+ Credentials are private version-1 JSON files under
70
+ `$CODETELEMETRY_CONTEXT_HOME/<name>.json`, defaulting to
71
+ `$XDG_CONFIG_HOME/codetelemetry/workspaces` or
72
+ `~/.config/codetelemetry/workspaces`. Files are owned, mode 0600 on POSIX, atomically
73
+ replaced, and bounded to 64 KiB. There are at most 64 contexts and 192 directory
74
+ entries including checkpoints/locks. Unsafe versions, symlinks, mismatched account,
75
+ organization, billing account or origin fail closed. Failed authorization never
76
+ falls back to personal scope. Expired credentials can be replaced with
77
+ `bootstrap_workspace` using `reauthorize: true`; the replacement must attest the
78
+ same identity. Remove an unused named context/checkpoint explicitly to free capacity.
79
+
80
+ The repository's `.codetelemetry/workspace.json` contains only the context name,
81
+ service origin and scope. It can be committed; never commit the private context,
82
+ client config, Terraform state or plan. Bindings are found from subdirectories up
83
+ to the repository root. `CODETELEMETRY_WORKSPACE` selects a context explicitly but
84
+ must agree with an existing repository binding. MCP verifies scope at restore and
85
+ before use; governance requests also carry the expected scope so a key rescope
86
+ cannot race a check and change personal configuration.
87
+
88
+ For existing auth, call `workspace_context` with `action: "save"`, a name and
89
+ `repositoryPath`. `action: "use"` selects an already-saved context. Rebinding a
90
+ repository requires explicitly removing its previous binding. Unbound clients
91
+ retain the legacy login behavior.
92
+
93
+ Bootstrap writes Claude settings inside the repository. Codex ignores project-local
94
+ `otel`, so bootstrap writes a dedicated user-level profile
95
+ `$CODEX_HOME/codetelemetry-<name>.config.toml` (or the default `~/.codex` directory).
96
+ Launch with `codetelemetry-connect run <name> -- <arguments>` or
97
+ `codex --profile codetelemetry-<name>` in the bound repository. The profile retains
98
+ your base sign-in/settings while overriding telemetry and its explicit content
99
+ opt-in. It does not rewrite the base config or copy auth tokens. The profile also registers the version-pinned workspace MCP server and disables
100
+ the standard global CodeTelemetry MCP entry for that profile. Claude receives a
101
+ project `.mcp.json` entry bound to the same context. Optional Codex observation
102
+ hooks live in the profile and run only when it is selected.
103
+ Codex combines global and profile hooks. Bootstrap upgrades recognized older
104
+ CodeTelemetry observation helpers so they abstain in named workspaces; global
105
+ hook definitions and personal reporting are preserved. Modified helpers require
106
+ review before configuration continues. When opting into new observation hooks,
107
+ review and trust them in Codex's `/hooks` interface before expecting observations.
108
+ See [OpenAI configuration reference](https://learn.chatgpt.com/docs/config-file/config-reference)
109
+ and [hooks](https://learn.chatgpt.com/docs/hooks).
110
+ Secret-bearing project paths are added to `.gitignore` before configuration.
111
+
112
+ A requested GitHub gate produces its generated workflow locally. Bootstrap then
113
+ reads GitHub through the existing `gh` authentication and checks the default-branch
114
+ workflow, required check, and a real organization-scoped PR decision for the local
115
+ HEAD and published policy after setup started. It reports pending repository
116
+ work explicitly. It does not claim a PR passed merely because a probe landed.
117
+ A verified gate decision retains its actual success/failure verdict and score.
118
+ Terraform artifact generation is reported separately from applying Terraform.
119
+
120
+ The public service must deploy `/api/device/code/bootstrap-v1` and the matching
121
+ approval route before clients use new-organization creation. Older deployments
122
+ refuse the versioned request rather than creating a personal key. Existing-org
123
+ contexts use the established scope-v1 device flow.
124
+
41
125
  ## Tools
42
126
 
43
127
  | Tool | What it does |
44
128
  | --- | --- |
45
129
  | `count_reply_phrases` | Count how often your own phrases appear in your Claude model replies, per day or week and per model (turns, turns with a match, per-phrase counts). Plain-text phrases with `{a|b}` / `[a|b]` groups, whole-word and case-insensitive; main-thread replies only; counts and session references, never reply text. |
46
130
  | `import_history` | Import this machine's past Claude Code / Codex sessions (`~/.claude/projects`, `~/.codex/sessions`) through the normal ingest, tagged as imported. Dry run by default; skips sessions captured live or already imported; resumes interrupted imports; pages with `remaining`. Content defaults to `live` (what your live exporters send); `none` opts out. |
131
+ | `workspace_context` | Save, list or select persistent verified workspace contexts. Repository bindings contain no credentials; cold MCP processes restore the bound context. |
132
+ | `bootstrap_workspace` | Create or select an organization, authorize once, and resume funding, repository-local telemetry, Grader publication, Terraform artifacts and GitHub gate verification. |
47
133
  | `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). |
48
134
  | `auth_status` | Poll the approval; on success captures the key into the session (masked-only to the model). |
49
135
  | `get_ingest_key` | Record a pasted key (fast path) or report the authenticated one — masked + hash only. |
@@ -64,8 +150,10 @@ Then just ask the agent: **"Connect me to CodeTelemetry."**
64
150
  | `estimate_plan` | T-shirt size a Claude Code / Codex **plan** (plain text or ordered steps) from the caller's own history. |
65
151
  | `estimate_linear_issue` | T-shirt size an **existing Linear issue** by URL or identifier, resolved through the workspace the user already connected. |
66
152
  | `seed_grader_config` | Inspect local agent instructions, selected skills, and project task files; return source text and command-check candidates for the user's requested grading focus. Reads files without running commands or uploading them. |
153
+ | `publish_grader_config` | Publish the reviewed draft as a new policy version using its exact revision. Completes setup through MCP; historical scores remain unchanged. |
154
+ | `write_grader_config_artifact` | Write selected checks as Terraform JSON or a standalone Pulumi YAML program, choosing the format from repository context. Refuses overwrites; runs no commands. |
67
155
  | `get_grader_config` | Read a page of the workspace's Grader draft, its revision, and published version. |
68
- | `update_grader_config` | Add, update, or remove selected draft checks while preserving others. Records the user's requested instruction features and rejects stale revisions. Publish the draft on the Grader page to change scoring. |
156
+ | `update_grader_config` | Add, update, or remove selected draft checks while preserving others. Records the user's requested instruction features and rejects stale revisions. Use publish_grader_config with the returned revision to apply it to future scoring. |
69
157
  | `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. |
70
158
  | `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. |
71
159
 
@@ -114,12 +202,64 @@ edit returns `conflict`; read again before retrying. An uncertain save must also
114
202
  be read back before retrying. Only selected check definitions and your feature
115
203
  description go to the server; source file text stays local to the MCP response.
116
204
 
117
- Changes appear as a draft at the [Grader page](https://codetelemetry.com/app/validation).
118
- Publish there to apply them to scoring. MCP tools do not publish a policy or
119
- rewrite historical scores. Remote configuration requires a backend implementing
120
- `POST /api/agent/grader` and `POST /api/agent/grader/configure`; older deployments
205
+ Changes are initially saved as a draft. To activate them, call
206
+ `publish_grader_config` with the exact `expectedRevision` returned by
207
+ `update_grader_config` or a fresh `get_grader_config`. The complete workflow —
208
+ seed, select checks, save, review, publish — works through MCP without the UI.
209
+ Publish only when the user wants activation; saving a draft stays separate.
210
+ Publication creates a new policy version for future evaluations and leaves
211
+ historical scores unchanged. Concurrent edits or a repeated publish using the
212
+ same revision return `conflict`. After `publish_uncertain`, read
213
+ `get_grader_config` and compare `publishedVersion` and `revision` before retrying.
214
+ The [Grader page](https://codetelemetry.com/app/validation) remains an alternative. Remote configuration requires a backend implementing
215
+ `POST /api/agent/grader`, `POST /api/agent/grader/configure`, and
216
+ `POST /api/agent/grader/publish`; older deployments
121
217
  return `not_supported` or `not_configured`. Local seeding works without a key.
122
218
 
219
+
220
+ Leave selected checks in the repository with `write_grader_config_artifact`:
221
+
222
+ ```json
223
+ {
224
+ "repositoryPath": "/path/to/project",
225
+ "features": "Require successful unit tests and lint from AGENTS.md",
226
+ "checks": ["<selected complete check objects from the seed or draft>"]
227
+ }
228
+ ```
229
+
230
+ The example's `checks` placeholder must be replaced with actual check objects.
231
+ Auto detection scans at most 4,000 entries, five directories deep, skipping links,
232
+ dependencies and state directories. `.tf` / `.tf.json` selects Terraform;
233
+ `Pulumi.yaml` / `Pulumi.yml` selects Pulumi. Mixed, missing or incomplete context
234
+ requires `format: "terraform"` or `format: "pulumi"`, or a narrower directory.
235
+
236
+ Terraform writes `codetelemetry-grader.tf.json`, for use with the local
237
+ `codetelemetry_grader_config` provider resource. Configure the provider using
238
+ [codetelemetry-providers](https://github.com/ElliotGardiner/codetelemetry-providers)
239
+ before planning; it is not a published registry integration.
240
+ Pulumi writes `codetelemetry-grader.pulumi.yaml` as JSON, a valid YAML subset.
241
+ Move it to a **separate directory** as `Pulumi.yaml`, build the provider binary
242
+ there at `./bin/terraform-provider-codetelemetry`, then run `pulumi install` and
243
+ `pulumi preview`. This standalone YAML program works alongside repositories using
244
+ any Pulumi language; it does not rewrite an existing Pulumi program.
245
+
246
+ Both resources own their listed check IDs, preserve unrelated checks, and use
247
+ revision checks on writes. An identical draft saved by the MCP can be adopted
248
+ without a write. Conflicting existing IDs require explicit import and review.
249
+ Destroy removes only managed draft checks. Use one state owner per workspace;
250
+ review plans and protect production resources as needed.
251
+
252
+ The requested focus is retained in Terraform locals or the Pulumi program
253
+ description. The IaC dashboard API preserves the draft's existing
254
+ `requestedFeatures`; use `update_grader_config` to change that remote intent.
255
+ Artifacts contain selected check definitions, not raw instructions or skills.
256
+ Template-like source strings remain literal. Files are created with restrictive
257
+ permissions and never overwrite an existing file, including symlinks. Edit an
258
+ existing artifact with normal file tools. The artifact tool does not execute IaC or publish a
259
+ policy; use `publish_grader_config` for activation. Apply with `CODETELEMETRY_ENDPOINT` and a **Cognito ID token** in
260
+ `CODETELEMETRY_TOKEN`, supplied through your secret manager; the MCP's ingest key
261
+ is not the IaC credential. Keep secrets out of check definitions and protect state.
262
+
123
263
  ## Organizations
124
264
 
125
265
  Without an `organizationId`, the key goes wherever the user picks while approving:
@@ -1,3 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import { run } from "./cli.js";
3
- process.exitCode = await run(process.argv.slice(2));
3
+ import { scrub } from "./keys.js";
4
+ try {
5
+ process.exitCode = await run(process.argv.slice(2));
6
+ }
7
+ catch (error) {
8
+ process.stderr.write(scrub(`CodeTelemetry: ${String(error.message)}\n`));
9
+ process.exitCode = 1;
10
+ }
@@ -0,0 +1,28 @@
1
+ import { type FetchLike } from "./otlp.ts";
2
+ export type BootstrapOptions = {
3
+ name: string;
4
+ repositoryPath?: string;
5
+ organizationName?: string;
6
+ organizationId?: string;
7
+ client?: "claude" | "codex";
8
+ configPath?: string;
9
+ features?: string;
10
+ checks?: Record<string, unknown>[];
11
+ publish?: boolean;
12
+ githubRepository?: string;
13
+ terraform?: boolean;
14
+ enrich?: boolean;
15
+ repositoryObservation?: boolean;
16
+ reauthorize?: boolean;
17
+ };
18
+ export declare function bootstrapWorkspace(options: BootstrapOptions, environment?: {
19
+ apiBase?: string;
20
+ fetchImpl?: FetchLike;
21
+ timeoutMs?: number;
22
+ }): Promise<{
23
+ nextAction?: string | undefined;
24
+ ok: boolean;
25
+ status: string;
26
+ workspace: string;
27
+ steps: Record<string, string>;
28
+ }>;