Skip to content

feat(patchy): the CLI names its version, command and coding agent on every request - #540

Merged
allisonmahmood merged 4 commits into
mainfrom
analytics/537-cli-agent
Oct 5, 2026
Merged

allisonmahmood merged 4 commits into
mainfrom
analytics/537-cli-agent

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

We can't tell which coding agent builds patches or which CLI versions are in use. The CLI version is stored on each version row but never reaches PostHog, and the agent isn't recorded anywhere.

The CLI now names itself on every request it sends to an instance: Patchy-Cli: <release> <command> <agent>, such as Patchy-Cli: 0.0.1 publish codex.

  • Shared contract (packages/api/src/cli.ts): the release pattern (three numbers, no leading zeros), the closed CliCommand list (every command that reaches the instance) and the closed CodingAgent list ending in unknown, with formatPatchyCli and parsePatchyCli. docs/API.md documents the header in the API's description. No endpoint declares it, so no route requires or refuses it.
  • CLI. Api.client adds the header, so it goes only to the instance and never to another host. The command is a required Api.CurrentCommand service, provided per command in the tree. A command that reaches the instance without a name fails to typecheck. CodingAgent.detect returns the first harness whose variable is present and sends only its id, never the value. Each variable is cited from the harness's docs or source.
  • Server. RequestEvents parses the header where non-runtime request events open. Each field is kept only when it matches the pattern or its list, so a newer CLI's new agent still records its release. A header that isn't exactly three fields records nothing. The request event gains cliVersion, cliCommand and agent, and Analytics.CurrentCli carries the release and agent to token.minted, patch.created and patch.updated. With no header (an older CLI or a browser), nothing extra is recorded. An older server ignores the header.

Agents, in detection order, each from a primary source (repo file, vendor docs or a local run): codex (CODEX_THREAD_ID, set in every sandbox mode), cursor, gemini-cli, kilo-code (before opencode, which Kilo also sets), opencode, copilot-cli, grok (GROK_AGENT=1 only, because people also set it to pick a profile), crush, qwen-code, pi, augment, roo-code, cline, and claude-code (CLAUDE_CODE_CHILD_SESSION). For Claude Code, its docs say CLAUDECODE is also set in IDE terminals people type in. It comes last because nested harnesses inherit their launcher's variables. Not included, because no harness-specific variable could be confirmed: Amp, Goose, Zed, Aider, Factory Droid, Windsurf, Warp and oh-my-pi.

Hit every surface:

Dev loop, migrations, company resources, served pages, reverse states and repo layout don't apply.

Touching #538's area: the catalogue adds Cli to token.minted, patch.created and patch.updated, without changing Publication.

Tests:

  • The parser, field by field and for shapes it rejects.
  • Detection for each agent, nesting, and a person's IDE terminal or Grok profile.
  • The bundled CLI sends <release> whoami unknown with a clean environment and codex with CODEX_THREAD_ID set, and never the value.
  • The request event records the parsed fields, hands its handler the release and agent, and records nothing for a missing or malformed header.
  • token.minted and patch.created carry the fields when the request named them, and updates without the header carry none.

Privacy page: allisonmahmood/patchy-web#23 (ships in the same release; not merged with this).

Closes #537

Made by Claude Opus 5.5 via Claude Code in T3 Code.

@github-actions github-actions Bot added area:server Touches the server area area:cli Touches the cli area area:docs Touches the docs area size:l 501-1,000 changed lines labels Oct 5, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review (GPT 6.1 Sol, high): round 1

Verdict: not safe to merge, with one finding.

  • Medium, packages/patchy/src/CodingAgent.ts: presence of GROK_AGENT falsely identified Grok, because people also set it to choose a Grok profile, and Grok's own commands get exactly 1. Fixed in 5e440f8: an entry can require a value (GROK_AGENT=1). The test now pins a profile value as unknown, and the README table shows the value.

Sol found nothing else to act on: strict parsing, compatibility, keeping the header to the instance, event propagation and docs all looked consistent. Round 2 is next.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review (GPT 6.1 Sol, high): round 2

Verdict: safe to merge, with no new findings. Sol confirmed that 5e440f8 fixes the Grok issue against the upstream source. The full diff passes for strict parsing, compatibility both ways, detection accuracy and order, privacy, event attribution, docs and test quality. Sol also ran its own read-only checks: header round-trips, malformed fields, all 14 markers, Grok rejection cases, and the header going only to the instance.

@allisonmahmood
allisonmahmood force-pushed the analytics/537-cli-agent branch from 5e440f8 to ffc006f Compare October 5, 2026 18:59
@allisonmahmood
allisonmahmood changed the base branch from analytics/534-business-events-company to analytics/535-onboarding-events October 5, 2026 18:59
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Restacked onto #539 (stack: #538 → #541 → #539 → #540). New head: ffc006f.

What conflicted:

Codex review (GPT 6.1 Sol, high): restack confirmation, round 3

Verdict: safe to merge, with no findings. Sol checked that both lower PRs' catalogue entries are intact and that Cli is limited to the three events. Delete reporting stays in the Patches service, with no duplicate API emission. #541's lifecycle events can fire during CLI requests but carry no CLI fields, which keeps the three-event boundary. #539's onboarding events come from browser flows. The docs are coherent with the combined behavior.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Stack deploy review (GPT 6.1 Sol, high)

Scope: the whole stack on ffc006f (git diff origin/main...HEAD, 66 files), with the question "what could hurt production after deploy". Production runs 48153dc, the current main, so a deploy would ship exactly this diff.

No deploy blockers. Sol found no regressions in:

  • transaction, lock or cancellation behaviour; reports run after commit;
  • HTTP responses;
  • startup wiring (the moved Analytics.layer adds no configuration);
  • compatibility either way between old and new CLIs and servers, or retained release archives;
  • schema: there are no migrations, so rolling back to 48153dc is safe.

PostHog capture only queues and never fails a request.

Sol raised two privacy findings against a stricter brief than the product's rules. Both exist on main today; this stack doesn't introduce them.

  1. Table, store and integration names reach PostHog (PatchesApi.ts, publish event). Dismissed: this is intended and already disclosed. Usage records "carry the names its builder gave its tables, file stores, connections and handlers" (patchyhq.com/cloud/privacy).
  2. The sdkImports filter (/^patchy\/[a-z][a-z0-9/-]*$/) accepts any patchy/… path. Valid but minor. main sends raw sdkImports, so feat(analytics): every business event names its company #538 already narrows it. An exact list of SDK entry points shared with the CLI would close it, but only a hand-crafted publish could exploit it. Not blocking; follow-up.

Orchestrator's own checks, made against the code:

  • Companies.create and consumeInvite are database-only (no Clerk calls), so the outer reported-commit transaction doesn't move external I/O inside a transaction.
  • The connection store still inspects the customer database before its transaction.
  • Claude Code's detection variable (CLAUDE_CODE_CHILD_SESSION) matches Claude Code's environment-variable docs.

Made by Claude Opus 5.5 via Claude Code in T3 Code.

@allisonmahmood
allisonmahmood force-pushed the analytics/535-onboarding-events branch from 844d5a4 to 08027db Compare October 5, 2026 20:39
Base automatically changed from analytics/535-onboarding-events to main October 5, 2026 21:28
allisonmahmood and others added 4 commits October 5, 2026 23:29
…every request

Every request the patchy CLI sends to an instance carries
`Patchy-Cli: <release> <command> <agent>`. The command is the contract's
closed `CliCommand` list, provided per command so an unnamed command that
reaches the instance fails to typecheck. The agent comes from the first
harness variable present, from a closed `CodingAgent` list, or `unknown`.

The server parses the header where request events open: each field is kept
only when it matches the release pattern or its list. The request event
records `cliVersion`, `cliCommand` and `agent`, and `token.minted`,
`patch.created` and `patch.updated` carry `cliVersion` and `agent` through
`Analytics.CurrentCli`. A request without the header records nothing extra.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…haustively

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the analytics/537-cli-agent branch from ffc006f to 501106f Compare October 5, 2026 21:29
@allisonmahmood
allisonmahmood merged commit aed1454 into main Oct 5, 2026
13 checks passed
@allisonmahmood
allisonmahmood deleted the analytics/537-cli-agent branch October 5, 2026 21:40
allisonmahmood added a commit that referenced this pull request Oct 6, 2026
…ease (#556)

What's new for this deploy, plus the history since the first production
deploy. The thin entries #555 seeded by hand are rewritten from what
each deploy actually shipped. This is the first run of `AGENTS.md` ›
Deploying: a fresh subagent gathered and wrote these releases, and I
checked them against the PRs.

**Release 4 (this deploy, `4a928f7..8697463`)**
- New: **See what's new in Patchy** (#555)

**Release 3 (2026-10-06, `aed1454..4a928f7`)**
- Fixed: **Creating a company explains a handle it can't use** (#553)

**Release 2 (2026-10-05, `48153dc..aed1454`)**
- Behind the scenes: key moments are recorded, identifying people by id,
never by name or email address (#538, #539, #541)
- Behind the scenes: the patchy command reports its version, command and
coding agent (#540)

**Release 1 (2026-10-05, first production deploy, `48153dc`)**
- Behind the scenes: Patchy Cloud's first release went live

Made by Claude Opus 5.5 via Claude Code in T3 Code.

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Touches the cli area area:docs Touches the docs area area:server Touches the server area size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(patchy): the CLI names its version, command and coding agent on every request

1 participant