feat(providers): add Zed agent provider#594
Merged
Merged
Conversation
Reads Zed's agent threads from the single threads.db SQLite store: each row's zstd-compressed JSON carries the thread model and per-request Anthropic-shaped token usage, so calls are emitted per request with exact input/output/cache fields and priced through the existing engine. In-progress threads with an empty per-request map fall back to the cumulative counter. zstd comes from node:zlib, which ships it from 22.15; on older Nodes the provider skips with a notice instead of failing. On-disk format documented by @chatzinikolakisk in #480 and the schema verified against a real Zed install.
Zed's DataType enum carries both zstd (the current save path) and json;
verified against crates/agent/src/db.rs, along with the exact TokenUsage
field names, the SerializedLanguageModel {provider, model} shape, and
RFC3339 updated_at serialization.
Validated against a real thread: request_token_usage is keyed by user message and covered only part of the requests (cumulative was ~3x the map sum), so per-request calls are now supplemented by one remainder entry that brings each thread exactly to cumulative_token_usage. Live run matches the store token-for-token on all four fields.
Member
Author
|
Validated end-to-end against a real Zed thread now (fresh install, real agent chat): the provider's output matches the store token-for-token on all four fields (input 37,786 / output 3,594 / cacheRead 176,640 / cacheWrite 0). Two findings from the live data are folded in: the per-request map undercounts (cumulative was ~3x the map sum), so threads now top up to the exact cumulative counter with a remainder entry, and legacy uncompressed json rows are read alongside zstd. Format details additionally verified against Zed's source (crates/agent/src/db.rs: DataType, DbThread, TokenUsage, SerializedLanguageModel). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #480.
Adds a provider for Zed's built-in agent. Full credit to @chatzinikolakisk for documenting the on-disk format in the issue; the schema was additionally verified byte-for-byte against a real Zed install.
How it works
threads.db(macOS~/Library/Application Support/Zed/threads/threads.db, with Linux and Windows paths mapped). One row per thread; thedatablob is zstd-compressed JSON.request_token_usagemap is emitted as one call per request with exactinput/output/cache_creation/cache_readtoken fields (Anthropic semantics), priced through the existing LiteLLM engine, deduped aszed:<threadId>:<requestId>.cumulative_token_usageso they still count.zlib.zstdDecompressSync(no new dependency). It ships from Node 22.15; since the package floor is 22.13, the provider feature-detects and skips with a notice on older Nodes, mirroring thenode:sqliteguard.--provider zedvalidates and non-Zed users load nothing extra.Testing
threads.db(exact schema) with zstd-compressed thread JSON: per-request emission with exact token fields, cumulative fallback, non-zstd and malformed-blob skipping, cross-parse dedup, zero-usage threads, and missing-DB discovery.Known limits
updated_at; day-level attribution for long-running threads is approximate.threadstable, so numbers were validated via fixtures, not real history. @chatzinikolakisk, if you are up for it, runningcodeburn overview --provider zedon this branch against your real usage and posting the result would be a great validation.folder_pathsis not yet mapped to per-project attribution; all Zed usage lands under a singlezedproject for now.