@agenttrail/cli 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,293 @@
1
- # Temporary Holding Version
1
+ # @agenttrail/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The `agenttrail` command connects an AI coding agent to agenttrail. Every command
4
+ names the agent with `--agent claude`, `--agent cursor` or `--agent codex`; a command without one
5
+ prints `choose --agent claude, --agent cursor or --agent codex`, exits 1 and changes nothing.
6
+
7
+ **Codex is not yet available.** `--agent codex` is recognised so that no Codex run is ever
8
+ mistaken for Claude Code's, but every command refuses it: it prints
9
+ ``error: `<command> --agent codex` is not yet available.``, exits 1, and reads and writes
10
+ nothing.
11
+
12
+ Claude Code and Cursor are connected by different means, because they expose different
13
+ things:
14
+
15
+ - **Claude Code** points **Claude Code's native OpenTelemetry exporter** at the
16
+ agenttrail ingest endpoint. This is a **per-project, opt-in config-writer +
17
+ project-identity resolver** — not an MCP server, not an in-process SDK, and not a
18
+ long-running process. It writes the correct OTel environment block into your
19
+ project's `.claude/settings.json`; Claude Code's own bundled exporter ships the spans.
20
+ - **Cursor** exports no traces you can redirect, so this package supplies the
21
+ runtime instead: `setup --agent cursor` registers **Cursor hook entries** in the
22
+ project's `.cursor/hooks.json` that run a small capture hook, which answers `{}`,
23
+ queues one file per step and exits, while a detached sender posts finished steps
24
+ to ingest. See [`docs/integrations/cursor.md`](../../docs/integrations/cursor.md).
25
+
26
+ Most of this README is the Claude Code path; the Cursor section below says exactly
27
+ where it differs.
28
+
29
+ ## Install / run (Claude Code)
30
+
31
+ ### One command (recommended) — browser device login, no API key
32
+
33
+ ```bash
34
+ npx -y @agenttrail/cli@latest setup --agent claude # opens the browser; approve, done
35
+ npx -y @agenttrail/cli@latest status --agent claude # → ACTIVE
36
+ ```
37
+
38
+ Run `setup` with **no API key**: it runs the OAuth-2.0 device-authorization flow
39
+ (RFC 8628, the `gh auth login` pattern) when you don't already have a valid
40
+ credential — printing a short code, opening the browser to the agenttrail web app
41
+ where your existing session approves it — then writes the project config. It
42
+ receives a **short-lived, refreshable, ingest-scoped** credential bound to your
43
+ user + active org; no API key to generate, copy, or paste. The credential lives
44
+ in `~/.agenttrail/credentials.json` (mode 0600) and its ingest token is mirrored
45
+ into `.claude/settings.local.json`; a registered `SessionStart` hook
46
+ transparently refreshes it between sessions. Re-running `setup` with a valid
47
+ credential reuses it (no browser) and just (re)writes this project's config.
48
+
49
+ (`login` / `logout` remain available as explicit session verbs — `login` does
50
+ the device-auth + config write; `setup` is the credential-aware install that
51
+ device-auths for you when needed.)
52
+
53
+ ### API key (CI / headless / `--team`)
54
+
55
+ Device login needs a browser, so non-interactive environments use an API key:
56
+
57
+ ```bash
58
+ export AGENTTRAIL_API_KEY="dlv_live_..."
59
+ npx -y @agenttrail/cli@latest setup --agent claude --org <your-org-uuid>
60
+ npx -y @agenttrail/cli@latest status --agent claude
61
+ ```
62
+
63
+ ### What `setup --agent claude` writes in your repo
64
+
65
+ The default setup keeps everything about **this machine** out of git, so a trial run does
66
+ not leave a change for you to commit or a flag for your teammates to inherit:
67
+
68
+ - **Real-time enforcement** (the policy endpoints, the token and the
69
+ `AGENTTRAIL_PEP_ENFORCE` switch) and the ingest token go into
70
+ `.claude/settings.local.json`.
71
+ - `.claude/settings.local.json` and `.agenttrail.json` (and the temporary copies a write
72
+ leaves for a moment) are kept out of git with lines in the repo's own `.git/info/exclude`,
73
+ which git reads like `.gitignore` but never tracks. Setup checks with git that they are
74
+ ignored, and never edits `.gitignore`.
75
+ - The **telemetry settings** (`CLAUDE_CODE_*`, `OTEL_*` and the `SessionStart` refresh hook)
76
+ still go into `.claude/settings.json`, which is usually committed. Apart from moving an
77
+ older install's enforcement keys out of that file (below), that is the only tracked change
78
+ setup makes today. A `.agenttrail.json` the repo already tracks is left as it is.
79
+
80
+ If the repo **already tracks** `.claude/settings.local.json` (or a `.gitignore` rule
81
+ re-includes it), that file would carry your credential into git, so setup **writes nothing**
82
+ and stops with the reason and the fix: `git rm --cached .claude/settings.local.json` and
83
+ commit (or remove the re-including rule), then run setup again. AgentTrail is not connected in
84
+ that repo until then. The same applies to `.agenttrail.json` when it would hold an API key.
85
+
86
+ `--team` is the explicit "write committable config" path: key-free settings meant to be
87
+ committed, and never the `AGENTTRAIL_PEP_ENFORCE` switch or a token.
88
+
89
+ An older version wrote the enforcement settings into `.claude/settings.json` and appended
90
+ lines to `.gitignore`. Running `setup` again moves the settings to
91
+ `.claude/settings.local.json` once enforcement is verified again (if `settings.json` is
92
+ committed, commit that change), and removes the `.gitignore` lines it added if they were never
93
+ committed. `logout` removes the enforcement settings from both files; the
94
+ `.git/info/exclude` lines stay, because the files they hide can still hold your own settings.
95
+
96
+ ## Cursor (`--agent cursor`)
97
+
98
+ ```bash
99
+ npx -y @agenttrail/cli@latest setup --agent cursor # in the folder you open in Cursor
100
+ npx -y @agenttrail/cli@latest status --agent cursor # → Capture: ON for <folder>
101
+ ```
102
+
103
+ Run it in the folder you open in Cursor, and trust the workspace when Cursor asks:
104
+ Cursor loads hooks from the folder it opens, and runs a project's hooks only in a
105
+ trusted workspace.
106
+
107
+ What differs from `--agent claude`:
108
+
109
+ | | Claude Code | Cursor |
110
+ |---|---|---|
111
+ | How spans are produced | Claude Code's own exporter, configured by us | our capture hook + a detached sender, both under `~/.agenttrail/cursor/runtime/` |
112
+ | What is written in the repo | telemetry settings in `.claude/settings.json`; everything per-machine in `.claude/settings.local.json`, kept out of git via `.git/info/exclude` | `.cursor/hooks.json`, kept out of git via `.git/info/exclude` |
113
+ | State | `~/.agenttrail/credentials.json` | `~/.agenttrail/cursor/` (its own credential, registry, queue and checkpoint) |
114
+ | Auth | device login, or `--key` / `--team` for CI | device login only — `--key`, `--team` and `--global` are refused |
115
+ | Content capture | **on by default** (`--no-capture-content` opts out); scrubbed at ingest | off by default (`--capture-content` turns it on); scrubbed **on this machine** before it is queued, then server-side as well |
116
+ | Cost | tokens × the provider's list price | not computed: Cursor sessions read "Not reported by Cursor" |
117
+ | Real-time blocking | the enforcement plugin | from Cursor 3.21.16, installed by `setup`; an older Cursor is captured only |
118
+
119
+ Two behaviours have no Claude Code counterpart:
120
+
121
+ - **A repo that already tracks `.cursor/hooks.json`** gets its entries in
122
+ `~/.cursor/hooks.json` instead, each behind a `/bin/sh` gate that compares
123
+ `$CURSOR_PROJECT_DIR` against your connected folders and answers `{}` without
124
+ reading stdin anywhere else. A laptop-wide file still behaves per project.
125
+ - **A workspace opened on a subfolder** loads only that subfolder's hooks, so setup
126
+ run there writes its entries too, under the same project.
127
+
128
+ `setup --agent cursor --unregister` disconnects one project; `logout --agent cursor`
129
+ removes this machine's Cursor state and revokes the device.
130
+
131
+ ## Commands
132
+
133
+ Each runs as `npx -y @agenttrail/cli@latest <command> --agent <claude|cursor|codex>`. With
134
+ `--agent codex`, every command below refuses: Codex is not yet available.
135
+
136
+ | Command | What it does |
137
+ |---|---|
138
+ | `login` | Browser device-auth (RFC 8628); writes `~/.agenttrail/credentials.json` (0600) + the OTLP header + a `SessionStart` refresh hook. No API key. With `--agent cursor`: the Cursor device session only, written to `~/.agenttrail/cursor/credentials.json` — no project files and no hook. |
139
+ | `login --refresh` | Refresh the ingest token **only when it's near expiry** (the `SessionStart` hook path; a no-op on a normal day). Inside Cursor, the Claude Code hook that calls this recognises Cursor's payload and exits 0 having done nothing. |
140
+ | `logout` | Revoke the device session and clear the local credential + header. Also tears down enforcement: removes the agenttrail enforcement plugin **and** its `agenttrail` marketplace declaration from your user settings (best-effort — never fails the logout). With `--agent cursor`: flushes what is queued, removes our hook entries from every connected folder and from `~/.cursor/hooks.json`, deletes everything under `~/.agenttrail/cursor/` bar the folder and the credential the revoke clears — the import checkpoint included, since it names every conversation this machine imported — and revokes the Cursor device. |
141
+ | `setup` | One-command install. No key → browser device-auth (reuses a valid credential, else runs the flow), then writes config. `--key`/`--team` → the API-key/CI path. With `--agent cursor`: device-auth only, and it connects **this one project** — `--unregister` disconnects it again. |
142
+ | `status` | Report whether the exporter is active in the current directory (incl. the on-disk OTLP endpoint). With `--agent cursor`: whether capture is ON, BROKEN or NOT INSTALLED here, the entries in each connected folder, the backlog, the newest Cursor version seen, and what the sender last uploaded or dropped. |
143
+
144
+ ## Flags
145
+
146
+ | Flag | Effect |
147
+ |---|---|
148
+ | `--agent <claude\|cursor\|codex>` | Required on every command: the agent to connect. `codex` is refused by every command until its support ships (not yet available); anything else is refused before any change is made. |
149
+ | `--org <uuid>` | Org UUID the API key belongs to (required). |
150
+ | `--project <slug>` | Override the derived project slug. |
151
+ | `--developer <uuid>` | Per-machine developer id (optional). |
152
+ | `--key <dlv_...>` | API key for the CI/headless path (default: `$AGENTTRAIL_API_KEY`). When omitted (and not `--team`), `setup` uses browser device-auth. Refused by `setup --agent cursor`. |
153
+ | `--endpoint <url>` | OTLP ingest base URL. Precedence: flag → `$AGENTTRAIL_INGEST_ENDPOINT` → prod default (`https://ingest.agenttrail.sh`). Point at a self-hosted ingest, e.g. `--endpoint http://localhost:4318`. |
154
+ | `--api-endpoint <url>` | API base URL for the device-auth flow (`setup`/`login`/`--refresh`/`logout`). Accepts a **bare origin** (e.g. `https://api.agenttrail.sh` or `http://localhost:3000`); the CLI derives the `/api/v1` base internally (idempotent if you pass `…/api/v1`). Precedence: flag → `$AGENTTRAIL_API_ENDPOINT` → prod default (`https://api.agenttrail.sh`). Distinct from `--endpoint` (ingest). |
155
+ | `--team` | Write committable, **key-free** config (key supplied per-dev via env). Refused by `setup --agent cursor`. |
156
+ | `--global` | Configure `~/.claude` + `~/.agenttrail/config.json` (per-user; prints a privacy warning). Refused by `setup --agent cursor` — Cursor is per project only. |
157
+ | `--no-capture-content` | `--agent claude`: turn OFF prompt/tool-content capture, which is **on by default** (prompts, commands, file paths and tool output). Setup writes the three content flags as `"0"`, and a later rerun without a flag keeps that opt-out. |
158
+ | `--capture-content` | `--agent claude`: turn capture back on after `--no-capture-content` (on is already the default). `--agent cursor`: turn ON prompt/tool-content capture. Ingest scrubs it server-side under your org's config; with `--agent cursor` it is also scrubbed **on this machine** before it is queued — the scrubber reads the whole value, and the 8192-character cap applies to what is kept afterwards. Scrubbing is shape-based, so it reduces exposure rather than guaranteeing none; the cap is a size limit on what is stored, not a safety measure. |
159
+ | `--unregister` | `setup --agent cursor` only: disconnect this project — remove its entries and its registry record, leaving every other project connected and this device signed in. |
160
+
161
+ ## Key facts
162
+
163
+ - **Device login is the no-key path**. The ingest token (7-day TTL,
164
+ `traces:write` only) is refreshed transparently by `login --refresh`, wired to
165
+ a `SessionStart` hook that refreshes **only when the token is near expiry** —
166
+ so a normal session start is a no-op (no rotation, no race). Concurrent
167
+ refreshes on one machine are serialized by a `credentials.json` file lock, so
168
+ two Claude windows never self-revoke. `logout` revokes the session server-side
169
+ (ingestion stops within ~60s). Manage devices under Settings → Connected
170
+ Devices in the web app.
171
+ - **Per-project, inactive when unconfigured** — no silent global fall-through;
172
+ nested repos do not inherit a parent's config (resolution stops at the git root).
173
+ - **`CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1` is required** — span emission is a
174
+ Claude Code beta feature, OFF by default; the writer always sets it.
175
+ - **Claude Code content capture is ON by default**: `setup` writes the three
176
+ `OTEL_LOG_*` content flags, so prompts, commands, file paths and tool output reach
177
+ AgentTrail. `--no-capture-content` opts out (metadata + tokens only), and `setup`
178
+ and `status` both print which mode is on. Cursor stays off unless you pass
179
+ `--capture-content`. A committed `.claude/settings.json` (under `--team`, or in a
180
+ repo that tracks it) carries the flags to every teammate; a teammate opts out for
181
+ themselves by setting the three flags to `"0"` in their own
182
+ `.claude/settings.local.json`. Claude Code's own exporter sends the content, so nothing
183
+ scrubs it on your machine; ingest scrubs captured content under your org's configured mode, falling
184
+ back to the deployment-wide `SCRUB_MODE` — never to no scrubbing. The one
185
+ passthrough is an org explicitly setting `mode: "off"`, which opts out by choice.
186
+ Scrubbing is shape-based, so a structureless secret can still get through; the
187
+ residual-risk section of the Claude Code guide spells out what that means.
188
+ - **Endpoint is configurable** but defaults to the hosted ingest. Precedence is
189
+ `--endpoint` → `$AGENTTRAIL_INGEST_ENDPOINT` → `https://ingest.agenttrail.sh`. An
190
+ explicitly-provided value (flag or env) is validated as an absolute `http(s)`
191
+ URL and its trailing slash stripped (Claude Code appends `/v1/traces`). The
192
+ endpoint is non-secret, so it is written to the committable
193
+ `.claude/settings.json`; `status` reports the value on disk.
194
+ - **Project id** is a deterministic, cross-tenant collision-safe UUIDv5:
195
+ `uuidv5(AGENTTRAIL_PROJECT_NS, "<orgId>:<projectSlug>")` with a frozen namespace
196
+ (`18a5d968-0fa2-5c8a-88da-0b29d80105d4`). With **no git remote** the slug falls
197
+ back to the directory name and the CLI warns that the identity may be unstable
198
+ across machines — add an `origin` remote for a stable identity.
199
+ - **Agent id** (`agenttrail.agent.id`) identifies the **agent tool** — a separate
200
+ dimension from the repo. `uuidv5(AGENTTRAIL_AGENT_NS, "<orgId>:<vendor>")` in its
201
+ own frozen namespace (`7f050af4-796e-5b05-94c2-dba78bcdc7c2`), so an agent id can
202
+ never equal a project id. Stamped on both live capture and backfill; one agent per
203
+ vendor per org, so a repo used from both Claude Code and Cursor is **one project
204
+ with two agents**, not two projects.
205
+
206
+ ## Backfill — import past sessions
207
+
208
+ ### Claude Code history
209
+
210
+ Claude Code capture is forward-only, but Claude Code persists full session
211
+ transcripts locally at `~/.claude/projects/<project>/<session>.jsonl`. `backfill`
212
+ reads those transcripts, maps each session to an OTLP trace, and replays them
213
+ through the same `POST /v1/traces` pipeline live capture uses — so a new user's
214
+ dashboard + pattern detector have real history on day one.
215
+
216
+ ```bash
217
+ npx -y @agenttrail/cli@latest backfill --scan --agent claude # JSON inventory; uploads nothing
218
+ npx -y @agenttrail/cli@latest backfill --import --agent claude [--dry-run] # parse + upload
219
+ npx -y @agenttrail/cli@latest backfill --import --agent claude --since 7d
220
+ npx -y @agenttrail/cli@latest backfill --status --agent claude # show the checkpoint
221
+ npx -y @agenttrail/cli@latest backfill --resume --agent claude # continue (skip done, retry failed)
222
+ ```
223
+
224
+ Key properties:
225
+
226
+ - **Scoped to the current project.** `--scan` / `--import` / `--resume`
227
+ cover ONLY the project you run them in — matched on each session's recorded
228
+ working directory, mirroring per-project `setup`. Sessions from other projects
229
+ on the machine are not imported (their count is reported, never their names), and
230
+ there is no flag to widen it: `cd` into another project and re-run. `--status` is
231
+ the exception — it reports the machine-wide import checkpoint.
232
+
233
+ - **Metadata + tokens by default.** `--content` is an explicit opt-in that also
234
+ uploads prompt/tool content; that content is **scrubbed server-side** by
235
+ agenttrail's ingest scrubber under your org's content-capture setting (secrets
236
+ redacted; stripped entirely when the org does not capture content). No content
237
+ ever leaves the machine un-gated.
238
+ - **Idempotent re-import.** IDs are deterministic —
239
+ `trace_id = uuidv5(sessionId, AGENTTRAIL_BACKFILL_NS)`,
240
+ `span_id = sha256(sessionId+messageUuid+toolUseId)[:8B]` — and timestamps are
241
+ taken verbatim from the transcript, so a second run de-dups against ClickHouse's
242
+ `(org_id, trace_id)` ReplacingMergeTree instead of double-counting.
243
+ - **Streaming + resilient.** Transcripts are parsed line-by-line (never whole-file);
244
+ parsing discriminates on line **structure** (the transcript `version` is
245
+ recorded for reporting, never used to reject); a corrupt session is quarantined
246
+ and reported without aborting the run.
247
+ - **Resumable.** Progress is checkpointed at `~/.agenttrail/backfill-state.json`;
248
+ `--resume` skips already-imported sessions (by content hash) and retries the rest.
249
+ - **Bounded + polite.** Uploads run in a bounded worker pool with exponential
250
+ backoff on 429/5xx (honoring `Retry-After`), reusing your device-login token or
251
+ API key.
252
+
253
+ ### Cursor history
254
+
255
+ ```bash
256
+ npx -y @agenttrail/cli@latest backfill --agent cursor --scan # list, upload nothing
257
+ npx -y @agenttrail/cli@latest backfill --agent cursor --import # first import of this project
258
+ npx -y @agenttrail/cli@latest backfill --agent cursor --status # the import checkpoint
259
+ npx -y @agenttrail/cli@latest backfill --agent cursor --resume # top up — skips unchanged files
260
+ ```
261
+
262
+ Same per-project rule, reading Cursor's own session files under
263
+ `~/.cursor/projects/<encoded path>/agent-transcripts/` — this project's encoded folder,
264
+ and the encoded folder of every subfolder setup has run in. Five differences from the
265
+ Claude Code import, each of them a property of what Cursor records:
266
+
267
+ - **it never includes what you or the agent said** — not with `--content` either. The
268
+ transcript reader drops message text by design, so what content mode adds to a Cursor
269
+ import is tool input: commands and paths, edge-scrubbed before they leave the machine;
270
+ - **no model, no tokens, no cost and no tool-call id** — the session files hold none, so
271
+ every imported span carries `agenttrail.usage.reported=false`;
272
+ - **times come from the file, not the session**: each conversation's turns are spread
273
+ between its file's birth and modification times (one second per turn where the file
274
+ system keeps no birth time), and every span is marked
275
+ `agenttrail.time.approximate=true`. **A transcript that has GROWN moves its times and
276
+ re-imports as new rows** — an unchanged one reproduces them exactly and replaces its
277
+ rows. `--resume` compares the source hash and skips it; a plain `--import` re-sends;
278
+ - **one recorded path outside the project root drops the whole conversation**, counted
279
+ `outside-root`. The encoded folder name is lossy, so that path is the only evidence we
280
+ get that the wrong project was opened; a partial import would file another repo's
281
+ commands here. A conversation recording no absolute path is kept;
282
+ - **`--since` is Claude Code only**, and a Cursor import refuses it rather than ignoring
283
+ it. A session file carries no time of its own, so a window could only come from the
284
+ file's timestamps — "last touched", not "happened" — which is a different question from
285
+ the one the flag asks. A Cursor import is bounded by the project, not by a date.
286
+
287
+ Conversations already captured live, already imported, or still waiting in the local queue
288
+ are skipped. The checkpoint is its own file,
289
+ `~/.agenttrail/cursor/backfill-state.json`, and `logout --agent cursor` deletes it with the
290
+ rest of this machine's Cursor state.
291
+
292
+ Full guides: [`docs/integrations/claude-code.md`](../../docs/integrations/claude-code.md)
293
+ and [`docs/integrations/cursor.md`](../../docs/integrations/cursor.md).