Skip to content

feat(analytics): every business event names its company - #538

Merged
allisonmahmood merged 4 commits into
mainfrom
analytics/534-business-events-company
Oct 5, 2026
Merged

allisonmahmood merged 4 commits into
mainfrom
analytics/534-business-events-company

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

PostHog's business events named who acted but not the company, so every company-level number on the product dashboard had to join through a wide event, and token.minted had nothing to join on. Patch events also didn't say who owns the patch.

Every business event now carries companyId, and every patch event carries ownerUserId beside patchId. A typed catalogue in packages/analytics/src/Analytics.ts declares each event's properties. AnalyticsEvent is a union keyed by name, so an emitter that sends the wrong properties, or leaves out its company, fails to typecheck.

  • companyId sits on the event envelope, so catalogue entries never repeat it. track sends it as a property, and events stay personless, with no groups.
  • token.minted reads the user's company in the same transaction that mints the token. Publish uses the caller's company and identity; only the owner can publish, so the publisher is the owner. Delete reads both from the deleted row. purgeDeleted now returns the owner it read under its row lock.
  • docs/OPERATIONS.md gains a "Business events" section covering what reaches PostHog, the principal rule (patchy-instance when nobody acted), companyId and ownerUserId, and a list of events by area. packages/analytics/CONTEXT.md points to the catalogue instead of listing events.
  • Tests pin both fields on all five existing events. A type-level test shows the catalogue rejecting a missing company, a missing owner and another event's properties.

Hit every surface: vocabulary (CONTEXT.md) and operations docs applied. The wire contract, CLI, dev loop, migrations, served pages and repo layout were untouched. Company resources: purgeDeleted reads one more column on the row it already locks, with no lock changes.

Closes #534

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

allisonmahmood and others added 3 commits October 5, 2026 17:56
Business events now carry companyId, and patch events carry ownerUserId
beside patchId. A typed catalogue in Analytics.ts declares each event's
properties, so an emitter cannot drift from its documented shape.

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

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added area:server Touches the server area area:docs Touches the docs area size:m 100-500 changed lines labels Oct 5, 2026
…orts

A manifest's sdkImports is client supplied free text; analytics now keeps
only entries shaped like an SDK entry point.

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

Copy link
Copy Markdown
Owner Author

Codex review (GPT 6.1 Sol, high)

Round 1: not safe to merge. Three findings:

  1. Major, fixed in 4d1bc6f. sdkImports on patch.created/patch.updated forwarded the manifest's client-supplied strings unchanged, so a hand-crafted manifest could put free text into PostHog. Analytics now keeps only entries shaped like an SDK entry point (patchy/…), and the tier 2 publish test sends an email-shaped entry and shows it dropped. The other name-shaped properties (tables, stores, integration aliases) are manifest keys, which the schema already restricts to camelCase DefinitionNames.
  2. Major, dismissed. "Undocumented properties bypass catalogue checking through ordinary variables or spreads." That is TypeScript's structural typing, not a gap in the catalogue. TS has no exact object types, so only a runtime schema per event could close it. feat(analytics): every business event names its company #534 asks that "the types reject an event with the wrong properties". Every emitter builds its properties as an inline literal at the track call, where excess-property checks apply and a reviewer sees every key. A runtime catalogue would add machinery the spec doesn't ask for.
  3. Minor, dismissed. "No Hit every surface entry for business events in CLAUDE.md." feat(analytics): every business event names its company #534 doesn't ask for one. Each follow-up ticket (feat(analytics): onboarding moments are business events #535, fix(patches): every patch lifecycle change is a business event, from every path #536, feat(patchy): the CLI names its version, command and coding agent on every request #537) already names its docs follow-through. The catalogue is the single source, and OPERATIONS.md and CONTEXT.md point to it.

Sol confirmed: company attribution and event-time ownership are accurate on all five events, reporting stays personless with no groups, the catalogue is easy to extend, and the tests are focused.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review (GPT 6.1 Sol, high)

Round 2: safe to merge. Sol accepted the sdkImports fix and both written dismissals, and found nothing new.

@allisonmahmood
allisonmahmood merged commit 3dcfcac into main Oct 5, 2026
13 checks passed
@allisonmahmood
allisonmahmood deleted the analytics/534-business-events-company branch October 5, 2026 19:59
allisonmahmood added a commit that referenced this pull request Oct 5, 2026
…every request (#540)

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:

- **Wire contract:** the shared lists and parser, the regenerated
`docs/API.md`, the server and the CLI.
- **CLI:** `packages/patchy/README.md` (a new section with the variable
table) and ADR-0004 (a header subsection). No command, flag or exit code
changed, so the global skill doesn't change.
- **Vocabulary:** the Publishing **Agent** term, and one sentence on the
Analytics **Request event** term (#538 owns that file).
- **Operations:** a paragraph in Wide events, and one sentence in #538's
Business events section.

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.

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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:docs Touches the docs area area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(analytics): every business event names its company

1 participant