@agenttrail/cli 0.0.0-stage → 0.1.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,253 @@
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
+ ## Cursor (`--agent cursor`)
64
+
65
+ ```bash
66
+ npx -y @agenttrail/cli@latest setup --agent cursor # in the folder you open in Cursor
67
+ npx -y @agenttrail/cli@latest status --agent cursor # → Capture: ON for <folder>
68
+ ```
69
+
70
+ Run it in the folder you open in Cursor, and trust the workspace when Cursor asks:
71
+ Cursor loads hooks from the folder it opens, and runs a project's hooks only in a
72
+ trusted workspace.
73
+
74
+ What differs from `--agent claude`:
75
+
76
+ | | Claude Code | Cursor |
77
+ |---|---|---|
78
+ | How spans are produced | Claude Code's own exporter, configured by us | our capture hook + a detached sender, both under `~/.agenttrail/cursor/runtime/` |
79
+ | What is written in the repo | `.claude/settings.json` (+ `.claude/settings.local.json`) | `.cursor/hooks.json`, kept out of git via `.git/info/exclude` |
80
+ | State | `~/.agenttrail/credentials.json` | `~/.agenttrail/cursor/` (its own credential, registry, queue and checkpoint) |
81
+ | Auth | device login, or `--key` / `--team` for CI | device login only — `--key`, `--team` and `--global` are refused |
82
+ | Content capture | scrubbed server-side | scrubbed **on this machine** before it is queued, then server-side as well |
83
+ | Cost | tokens × the provider's list price | not computed: Cursor sessions read "Not reported by Cursor" |
84
+ | Real-time blocking | the enforcement plugin | from Cursor 3.21.16, installed by `setup`; an older Cursor is captured only |
85
+
86
+ Two behaviours have no Claude Code counterpart:
87
+
88
+ - **A repo that already tracks `.cursor/hooks.json`** gets its entries in
89
+ `~/.cursor/hooks.json` instead, each behind a `/bin/sh` gate that compares
90
+ `$CURSOR_PROJECT_DIR` against your connected folders and answers `{}` without
91
+ reading stdin anywhere else. A laptop-wide file still behaves per project.
92
+ - **A workspace opened on a subfolder** loads only that subfolder's hooks, so setup
93
+ run there writes its entries too, under the same project.
94
+
95
+ `setup --agent cursor --unregister` disconnects one project; `logout --agent cursor`
96
+ removes this machine's Cursor state and revokes the device.
97
+
98
+ ## Commands
99
+
100
+ Each runs as `npx -y @agenttrail/cli@latest <command> --agent <claude|cursor|codex>`. With
101
+ `--agent codex`, every command below refuses: Codex is not yet available.
102
+
103
+ | Command | What it does |
104
+ |---|---|
105
+ | `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. |
106
+ | `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. |
107
+ | `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. |
108
+ | `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. |
109
+ | `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. |
110
+
111
+ ## Flags
112
+
113
+ | Flag | Effect |
114
+ |---|---|
115
+ | `--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. |
116
+ | `--org <uuid>` | Org UUID the API key belongs to (required). |
117
+ | `--project <slug>` | Override the derived project slug. |
118
+ | `--developer <uuid>` | Per-machine developer id (optional). |
119
+ | `--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`. |
120
+ | `--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`. |
121
+ | `--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). |
122
+ | `--team` | Write committable, **key-free** config (key supplied per-dev via env). Refused by `setup --agent cursor`. |
123
+ | `--global` | Configure `~/.claude` + `~/.agenttrail/config.json` (per-user; prints a privacy warning). Refused by `setup --agent cursor` — Cursor is per project only. |
124
+ | `--capture-content` | 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. |
125
+ | `--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. |
126
+
127
+ ## Key facts
128
+
129
+ - **Device login is the no-key path**. The ingest token (7-day TTL,
130
+ `traces:write` only) is refreshed transparently by `login --refresh`, wired to
131
+ a `SessionStart` hook that refreshes **only when the token is near expiry** —
132
+ so a normal session start is a no-op (no rotation, no race). Concurrent
133
+ refreshes on one machine are serialized by a `credentials.json` file lock, so
134
+ two Claude windows never self-revoke. `logout` revokes the session server-side
135
+ (ingestion stops within ~60s). Manage devices under Settings → Connected
136
+ Devices in the web app.
137
+ - **Per-project, inactive when unconfigured** — no silent global fall-through;
138
+ nested repos do not inherit a parent's config (resolution stops at the git root).
139
+ - **`CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1` is required** — span emission is a
140
+ Claude Code beta feature, OFF by default; the writer always sets it.
141
+ - **Content is OFF by default** (metadata + tokens only). `--capture-content` is an
142
+ explicit opt-in, and the server-side scrubbing it waited on has
143
+ landed: ingest scrubs captured content under your org's configured mode, falling
144
+ back to the deployment-wide `SCRUB_MODE` — never to no scrubbing. The one
145
+ passthrough is an org explicitly setting `mode: "off"`, which opts out by choice.
146
+ Scrubbing is shape-based, so a structureless secret can still get through; the
147
+ residual-risk section of the Claude Code guide spells out what that means.
148
+ - **Endpoint is configurable** but defaults to the hosted ingest. Precedence is
149
+ `--endpoint` → `$AGENTTRAIL_INGEST_ENDPOINT` → `https://ingest.agenttrail.sh`. An
150
+ explicitly-provided value (flag or env) is validated as an absolute `http(s)`
151
+ URL and its trailing slash stripped (Claude Code appends `/v1/traces`). The
152
+ endpoint is non-secret, so it is written to the committable
153
+ `.claude/settings.json`; `status` reports the value on disk.
154
+ - **Project id** is a deterministic, cross-tenant collision-safe UUIDv5:
155
+ `uuidv5(AGENTTRAIL_PROJECT_NS, "<orgId>:<projectSlug>")` with a frozen namespace
156
+ (`18a5d968-0fa2-5c8a-88da-0b29d80105d4`). With **no git remote** the slug falls
157
+ back to the directory name and the CLI warns that the identity may be unstable
158
+ across machines — add an `origin` remote for a stable identity.
159
+ - **Agent id** (`agenttrail.agent.id`) identifies the **agent tool** — a separate
160
+ dimension from the repo. `uuidv5(AGENTTRAIL_AGENT_NS, "<orgId>:<vendor>")` in its
161
+ own frozen namespace (`7f050af4-796e-5b05-94c2-dba78bcdc7c2`), so an agent id can
162
+ never equal a project id. Stamped on both live capture and backfill; one agent per
163
+ vendor per org, so a repo used from both Claude Code and Cursor is **one project
164
+ with two agents**, not two projects.
165
+
166
+ ## Backfill — import past sessions
167
+
168
+ ### Claude Code history
169
+
170
+ Claude Code capture is forward-only, but Claude Code persists full session
171
+ transcripts locally at `~/.claude/projects/<project>/<session>.jsonl`. `backfill`
172
+ reads those transcripts, maps each session to an OTLP trace, and replays them
173
+ through the same `POST /v1/traces` pipeline live capture uses — so a new user's
174
+ dashboard + pattern detector have real history on day one.
175
+
176
+ ```bash
177
+ npx -y @agenttrail/cli@latest backfill --scan --agent claude # JSON inventory; uploads nothing
178
+ npx -y @agenttrail/cli@latest backfill --import --agent claude [--dry-run] # parse + upload
179
+ npx -y @agenttrail/cli@latest backfill --import --agent claude --since 7d
180
+ npx -y @agenttrail/cli@latest backfill --status --agent claude # show the checkpoint
181
+ npx -y @agenttrail/cli@latest backfill --resume --agent claude # continue (skip done, retry failed)
182
+ ```
183
+
184
+ Key properties:
185
+
186
+ - **Scoped to the current project.** `--scan` / `--import` / `--resume`
187
+ cover ONLY the project you run them in — matched on each session's recorded
188
+ working directory, mirroring per-project `setup`. Sessions from other projects
189
+ on the machine are not imported (their count is reported, never their names), and
190
+ there is no flag to widen it: `cd` into another project and re-run. `--status` is
191
+ the exception — it reports the machine-wide import checkpoint.
192
+
193
+ - **Metadata + tokens by default.** `--content` is an explicit opt-in that also
194
+ uploads prompt/tool content; that content is **scrubbed server-side** by
195
+ agenttrail's ingest scrubber under your org's content-capture setting (secrets
196
+ redacted; stripped entirely when the org does not capture content). No content
197
+ ever leaves the machine un-gated.
198
+ - **Idempotent re-import.** IDs are deterministic —
199
+ `trace_id = uuidv5(sessionId, AGENTTRAIL_BACKFILL_NS)`,
200
+ `span_id = sha256(sessionId+messageUuid+toolUseId)[:8B]` — and timestamps are
201
+ taken verbatim from the transcript, so a second run de-dups against ClickHouse's
202
+ `(org_id, trace_id)` ReplacingMergeTree instead of double-counting.
203
+ - **Streaming + resilient.** Transcripts are parsed line-by-line (never whole-file);
204
+ parsing discriminates on line **structure** (the transcript `version` is
205
+ recorded for reporting, never used to reject); a corrupt session is quarantined
206
+ and reported without aborting the run.
207
+ - **Resumable.** Progress is checkpointed at `~/.agenttrail/backfill-state.json`;
208
+ `--resume` skips already-imported sessions (by content hash) and retries the rest.
209
+ - **Bounded + polite.** Uploads run in a bounded worker pool with exponential
210
+ backoff on 429/5xx (honoring `Retry-After`), reusing your device-login token or
211
+ API key.
212
+
213
+ ### Cursor history
214
+
215
+ ```bash
216
+ npx -y @agenttrail/cli@latest backfill --agent cursor --scan # list, upload nothing
217
+ npx -y @agenttrail/cli@latest backfill --agent cursor --import # first import of this project
218
+ npx -y @agenttrail/cli@latest backfill --agent cursor --status # the import checkpoint
219
+ npx -y @agenttrail/cli@latest backfill --agent cursor --resume # top up — skips unchanged files
220
+ ```
221
+
222
+ Same per-project rule, reading Cursor's own session files under
223
+ `~/.cursor/projects/<encoded path>/agent-transcripts/` — this project's encoded folder,
224
+ and the encoded folder of every subfolder setup has run in. Five differences from the
225
+ Claude Code import, each of them a property of what Cursor records:
226
+
227
+ - **it never includes what you or the agent said** — not with `--content` either. The
228
+ transcript reader drops message text by design, so what content mode adds to a Cursor
229
+ import is tool input: commands and paths, edge-scrubbed before they leave the machine;
230
+ - **no model, no tokens, no cost and no tool-call id** — the session files hold none, so
231
+ every imported span carries `agenttrail.usage.reported=false`;
232
+ - **times come from the file, not the session**: each conversation's turns are spread
233
+ between its file's birth and modification times (one second per turn where the file
234
+ system keeps no birth time), and every span is marked
235
+ `agenttrail.time.approximate=true`. **A transcript that has GROWN moves its times and
236
+ re-imports as new rows** — an unchanged one reproduces them exactly and replaces its
237
+ rows. `--resume` compares the source hash and skips it; a plain `--import` re-sends;
238
+ - **one recorded path outside the project root drops the whole conversation**, counted
239
+ `outside-root`. The encoded folder name is lossy, so that path is the only evidence we
240
+ get that the wrong project was opened; a partial import would file another repo's
241
+ commands here. A conversation recording no absolute path is kept;
242
+ - **`--since` is Claude Code only**, and a Cursor import refuses it rather than ignoring
243
+ it. A session file carries no time of its own, so a window could only come from the
244
+ file's timestamps — "last touched", not "happened" — which is a different question from
245
+ the one the flag asks. A Cursor import is bounded by the project, not by a date.
246
+
247
+ Conversations already captured live, already imported, or still waiting in the local queue
248
+ are skipped. The checkpoint is its own file,
249
+ `~/.agenttrail/cursor/backfill-state.json`, and `logout --agent cursor` deletes it with the
250
+ rest of this machine's Cursor state.
251
+
252
+ Full guides: [`docs/integrations/claude-code.md`](../../docs/integrations/claude-code.md)
253
+ and [`docs/integrations/cursor.md`](../../docs/integrations/cursor.md).