Skip to content

feat: send the shared Doist CLI usage headers on every request - #114

Merged
scottlovegrove merged 2 commits into
mainfrom
scottl/check-user-tracking
Nov 10, 2026
Merged

scottlovegrove merged 2 commits into
mainfrom
scottl/check-user-tracking

Conversation

@scottlovegrove

Copy link
Copy Markdown
Collaborator

Summary

comms-cli only told the backend Doist-Platform: cli and Doist-Version. It now sends the shared Doist CLI header set from @doist/cli-core 1.9.0 (createUsageTracking, todoist/cli-core#176), the same set todoist-cli sends and automations-cli is moving to, so Comms API logs can tell which command, OS and CLI run a request came from.

Header Value
User-Agent comms-cli/<version>
doist-platform cli
doist-version the CLI version
doist-os macos / linux / windows / unknown
request-id a new UUID per request
session-id one UUID per CLI run
cli-command the command that made the request, e.g. thread:view, search

No identifying data is added: both IDs are random and nothing is persisted.

What changed

  • src/lib/usage-tracking.ts replaces src/lib/attribution.ts: one tracker per process, trackCommandUsage(program) (the preAction hook that records the command) and withUsageHeaders(fetch) for requests that bypass the SDK.
  • The Comms SDK client gets headers: () => usageTracking.headers(), so each request gets its own request-id.
  • The raw search fetch, and the OAuth token and refresh requests, carry the headers too. The token requests now send comms-cli/<version> as their User-Agent instead of the OAuth library's.
  • tdc view <url> puts the hook on its routing program as well, so its requests are labelled with the routed command (thread:view) rather than view.

The Comms backend already reads the doist-* headers into client_info, so doist-os should show up in Datadog straight away. request-id, session-id and cli-command aren't read by the backend yet; recording them is a backend follow-up.

Test plan

  • npm run verify
  • New tests run real commands through program.parseAsync and assert the headers reaching the SDK: the full set for tdc user, thread:view for tdc thread <id>, tdc thread view <id> and tdc view <thread URL>, one session ID and different request IDs across a run. The search, OAuth exchange and refresh tests assert the headers on the raw fetch.
  • Against a local server that logs request headers, tdc user sent cli-command: user and tdc thread id:… sent cli-command: thread:view on both threads/getone and comments/get, sharing one session-id with a different request-id each
  • Not run against the real Comms API or a real OAuth login

comms-cli only sent Doist-Platform and Doist-Version. It now uses
@doist/cli-core's createUsageTracking (1.9.0), the same set todoist-cli
and automations-cli send: User-Agent comms-cli/<version>, doist-platform,
doist-version, doist-os, a request-id per request, a session-id per run
and cli-command naming the command that made the request.

The headers go on every Comms SDK request (worked out per request), the
raw search fetch, and the OAuth token and refresh requests. A preAction
hook records the command, and `tdc view <url>` relabels its requests to
the routed command (thread:view, msg:view, ...).

src/lib/attribution.ts is replaced by src/lib/usage-tracking.ts.
@scottlovegrove scottlovegrove self-assigned this Nov 10, 2026

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR swaps the old static attribution headers for the shared Doist CLI usage-tracking set from cli-core 1.9.0, wiring it consistently across the SDK client, the raw search fetch, the OAuth token/refresh requests, and both command programs (including the tdc view routing proxy). The implementation reuses cli-core's createUsageTracking/mergeHeaders rather than reimplementing header construction, tests cover the header flow through real program.parseAsync runs, and no security, privacy, or reuse issues were found.

Few things worth tightening:

  • The test named "a new request ID across the requests of a run" actually compares headers from two separate runs, so it would pass even if request-id were generated once per command invocation. Capture two headers from the same headersSentBy('thread', ...) call and assert they differ to pin per-request uniqueness.

Share Feedback • Review Logs

Comment thread src/lib/usage-tracking.test.ts Resolved
The test compared a tdc user run with a tdc thread run, so a request ID
made once per run would still have passed. It now takes the two requests
of one tdc thread run and checks they share a session ID but not a
request ID.
@scottlovegrove scottlovegrove added the 🚢 Ship PR requires passing checks before merge, but no independent human review. label Nov 10, 2026
@scottlovegrove
scottlovegrove merged commit c09e909 into main Nov 10, 2026
6 checks passed
@scottlovegrove
scottlovegrove deleted the scottl/check-user-tracking branch November 10, 2026 17:24
doist-release-bot Bot added a commit that referenced this pull request Nov 10, 2026
## [4.1.0](v4.0.0...v4.1.0) (2026-11-10)

### Features

* send the shared Doist CLI usage headers on every request ([#114](#114)) ([c09e909](c09e909))
@doist-release-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 4.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released 🚢 Ship PR requires passing checks before merge, but no independent human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants