Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

30.8 KB
Raw Blame
package asymptoteobserve

import "strings"

// NormalizeHarnessName maps whatever a runtime calls itself onto Beacon's canonical harness name.
//
// This lives in the shared module because two independent paths write the same field and must
// agree. The OTLP path derives a name from resource attributes and event names in the collector
// exporter; the hook path takes it from the `--platform` value it was installed with. They
// disagreed: one session produced both `claude` and `claude_code`, which splits that session in
// two for any query, dashboard, or SIEM detection that groups by harness.name -- exactly what a
// customer forwarding to Sentinel does.
//
// Normalizing at the point of writing rather than at every point of reading is deliberate. The
// alternative pushes the inconsistency onto every consumer, including consumers we do not own,
// and `harness.name` is a release contract that downstream queries are written against.
//
// The `--platform` flag is intentionally left alone: it identifies the runtime being hooked and
// is part of the hook command written into settings.json, so changing it would only take effect
// after every existing install were rewritten. Mapping at write time fixes existing installs too.
//
// Ordering matters. The browser-chat cases must precede the generic "claude" rule, which would
// otherwise coerce claude_web into claude_code.
//
// Beacon Cloud groups forwarded sessions by these canonical names, so a new harness or spelling
// here needs a matching Beacon Cloud change in the same release; see "Downstream consumers" in
// docs/telemetry-schema/normalization.mdx.
func NormalizeHarnessName(name string) string {
	lower := strings.ToLower(strings.TrimSpace(name))
	switch {
	case lower == "":
		return ""
	case strings.Contains(lower, "cowork") || strings.Contains(lower, "co-work"):
		return "claude_cowork"
	case strings.Contains(lower, "claude_agent_sdk") || strings.Contains(lower, "claude-agent-sdk") || strings.Contains(lower, "claude agent sdk"):
		return "claude_agent_sdk"
	case strings.Contains(lower, "claude_web") || strings.Contains(lower, "claude-web") || lower == "claude.ai":
		return "claude_web"
	case strings.Contains(lower, "chatgpt") || lower == "chatgpt.com" || strings.Contains(lower, "openai_web"):
		return "chatgpt_web"
	case strings.Contains(lower, "claude_code") || strings.Contains(lower, "claude-code") || strings.Contains(lower, "claude code") || strings.HasPrefix(lower, "claude_code."):
		return "claude_code"
	case lower == "claude" || strings.Contains(lower, "claude"):
		return "claude_code"
	case strings.Contains(lower, "openclaw") || strings.Contains(lower, "open-claw"):
		return "openclaw_gateway"
	case strings.Contains(lower, "antigravity") || strings.Contains(lower, "anti-gravity"):
		return "antigravity_cli"
	// codex-app-server is not a Desktop name. The desktop app and, since about CLI 0.158, the terminal
	// CLI both run Codex's app-server and export OTLP under that one service name, so it falls
	// through to codex_cli here. What tells them apart is the `originator` Codex reports for each
	// conversation; CodexSurface maps it.
	case lower == "codex_desktop" || lower == "codex-desktop" || lower == "codex desktop":
		return "codex_desktop"
	case strings.Contains(lower, "codex"):
		return "codex_cli"
	case strings.Contains(lower, "gemini"):
		return "gemini_cli"
	// Every VS Code spelling resolves before the generic copilot rule below, which contains
	// "copilot" and would otherwise swallow them. Two consequences of getting this wrong, both
	// real: the hook path installs with --platform vscode while the OTLP path reports
	// vscode_copilot, so one session was recorded under two names; and vscode_copilot itself
	// normalized to copilot_cli, which is a different product -- meaning the canonical name was
	// not stable under re-normalization and VS Code activity was attributed to the Copilot CLI.
	case strings.Contains(lower, "copilot-chat") || strings.Contains(lower, "vscode_copilot") ||
		strings.Contains(lower, "vscode-copilot") || strings.Contains(lower, "vscode") ||
		strings.Contains(lower, "vs code"):
		return "vscode_copilot"
	case strings.Contains(lower, "github-copilot") || strings.Contains(lower, "copilot_cli") || strings.Contains(lower, "copilot"):
		return "copilot_cli"
	// Oh My Pi (omp) is a separate product from Pi, not another Pi host, so it gets its own
	// canonical name rather than folding into pi_cli. It is a fork of pi-mono with its own binary
	// (`omp`), its own config root (`~/.omp`), its own npm package, and an event API Pi does not
	// have -- approval decisions among them. Recording both under one name would merge two
	// separately installed runtimes' activity in every query that groups by harness.name, which is
	// the one thing a security log must not do to two different products on the same machine.
	//
	// The canonical spelling is `omp` because that is what the user sees: the binary they run and
	// the directory Beacon installs into. `oh-my-pi` is the repository name, not the command.
	//
	// Equality against a closed set, like Pi below and for a sharper version of the same reason:
	// "omp" is three characters and sits inside ordinary words this field carries in practice --
	// "prompt" contains it, and so does any harness name containing "comp". A Contains rule would
	// report those as Oh My Pi sessions.
	//
	// Placed above the Pi case deliberately. Equality makes the order irrelevant today, but every
	// Oh My Pi spelling here ends in "pi", so if the Pi case were ever loosened to a substring
	// match, resolving Oh My Pi first is what keeps "oh-my-pi" from being recorded as Pi.
	case lower == "omp" || lower == "omp_cli" || lower == "omp-cli" || lower == "omp cli" ||
		lower == "oh-my-pi" || lower == "oh_my_pi" || lower == "ohmypi" || lower == "oh my pi" ||
		lower == "omp.sh":
		return "omp"
	// Pi is matched by equality against a fixed set of spellings, not by substring, because "pi" is
	// two characters and appears inside names that belong to other runtimes: "copilot" contains it,
	// so a Contains rule here would report every GitHub Copilot and VS Code Copilot session as Pi.
	// The set is closed for the same reason -- a prefix rule would claim any future runtime whose
	// name happens to start with those two letters.
	//
	// Its position after the Copilot rules is also deliberate. Equality makes this case
	// order-independent today, but if it is ever loosened to a substring match, sitting below the
	// broader rules means Copilot still resolves correctly and only genuine Pi names reach here.
	// The reverse ordering would turn that same edit into silent misattribution.
	case lower == "pi" || lower == "pi.dev" || lower == "pi_cli" || lower == "pi-cli" ||
		lower == "pi_agent" || lower == "pi-agent" || lower == "pi agent":
		return "pi_cli"
	// Cline reaches Beacon from more than one host -- a VS Code extension, a JetBrains plugin and a
	// CLI, all over the same agent core -- so the spelling that arrives depends on which host
	// reported it. Pinning the canonical name here is what keeps one Cline session from being
	// recorded under two names when the hook path (`--platform cline`) and an OTLP resource
	// attribute disagree about capitalization or suffix.
	//
	// Equality against a closed set, like Pi above and unlike the Contains rules further up.
	// "cline" is a substring of Cline's own configuration names -- `.clinerules` is a directory
	// every Cline user has -- so a Contains rule here would claim any harness whose name merely
	// mentioned one of those paths. The set is closed rather than a prefix rule for the same
	// reason.
	case lower == "cline" || lower == "cline_cli" || lower == "cline-cli" || lower == "cline cli" ||
		lower == "cline.bot":
		return "cline"
	// Qwen Code is matched by equality against a closed set, not by a substring rule, and the
	// reason is specific to this runtime rather than general caution: every Qwen model id begins
	// with the same four letters the harness does -- qwen3-coder-plus, qwen-max, qwen-turbo. A
	// Contains rule would therefore report any event whose harness attribute happened to carry a
	// model string as a Qwen Code session, which is how a model name ends up masquerading as a
	// runtime in a dashboard grouped by harness.name.
	//
	// The canonical spelling is qwen_code rather than qwen_cli because Qwen Code is the product's
	// name; it follows claude_code, not codex_cli. Both spellings arrive in practice -- the hook
	// path installs with --platform qwen, while an OTLP resource attribute carries whatever the
	// runtime calls itself -- and pinning them here is what keeps one session from being recorded
	// under two names.
	case lower == "qwen" || lower == "qwen_code" || lower == "qwen-code" || lower == "qwen code" ||
		lower == "qwencode" || lower == "qwen_cli" || lower == "qwen-cli" || lower == "qwen cli" ||
		lower == "qwen_coder" || lower == "qwen-coder" || lower == "qwen coder":
		return "qwen_code"
	// Muse Code is Meta's terminal coding agent; Muse Spark is the model it runs. Beacon hooks the
	// agent, so the harness is muse_code -- the canonical spelling follows claude_code and
	// qwen_code, because Muse Code is the product's name rather than a CLI suffix.
	//
	// Muse Spark spellings are deliberately absent from this set, and that is the whole reason the
	// case is written as equality against a closed set rather than Contains(lower, "muse"). Every
	// Muse Spark model id begins with the same four letters the harness does -- muse-spark-1.2,
	// muse-spark-1.3, muse-spark-1.2-contributor -- so a substring rule would report any event
	// whose harness attribute happened to carry a model string as a Muse Code session. That is the
	// Qwen failure exactly (see TestQwenModelNamesAreNotTreatedAsTheHarness), and here it would be
	// worse: the model and the agent ship under one brand, so a reader seeing "muse_spark" in
	// harness.name has no way to tell a misattributed model id from a real runtime. Leaving those
	// spellings unmapped means they fall to the passthrough case below and show up as themselves,
	// which is visible as an anomaly rather than silently filed under the agent.
	//
	// "muse" alone is also an ordinary English word, so the closed set is what keeps a harness
	// attribute that merely contains it from being claimed. There is no prefix rule for the same
	// reason: a future runtime named "musey" is not this one.
	case lower == "muse" || lower == "muse_code" || lower == "muse-code" || lower == "muse code" ||
		lower == "musecode" || lower == "muse_cli" || lower == "muse-cli" || lower == "muse cli":
		return "muse_code"
	// Prime Agent (Prime Intellect) ships the same extension API as Pi, which is why Beacon
	// observes it the same way -- but it is a separate product, and recording its sessions as
	// pi_cli would merge two runtimes' activity under one name in every query that groups by
	// harness.name. The canonical spelling is prime_agent because that is the product's name and
	// the command it installs; it follows claude_code and qwen_code, not codex_cli.
	//
	// Equality against a closed set, like Pi, Cline and Qwen Code above rather than the Contains
	// rules further up. "prime" is an ordinary English word that appears in model ids, file paths
	// and vendor names, so a substring rule would report any event whose harness attribute merely
	// contained it as a Prime Agent session. The set is closed rather than a prefix rule for the
	// same reason.
	//
	// Both the hook spelling and the runtime's own are pinned here: the hook path installs with
	// --platform prime, while the runtime calls itself prime-agent, and without this one session
	// would be recorded under two names.
	case lower == "prime" || lower == "prime_agent" || lower == "prime-agent" || lower == "prime agent" ||
		lower == "primeagent" || lower == "prime_cli" || lower == "prime-cli" || lower == "prime cli" ||
		lower == "prime_intellect" || lower == "prime-intellect" || lower == "prime intellect":
		return "prime_agent"
	// Senpi is the standalone edition of oh-my-openagent (OMO): an in-flight fork of pi-mono that
	// OMO brands and bundles its own extension into, distributed as the `omo` command. It is a
	// separate product from Pi, Oh My Pi and Prime Agent, so it gets its own canonical name rather
	// than folding into pi_cli -- recording its sessions as pi_cli would merge two runtimes'
	// activity under one name in every query that groups by harness.name.
	//
	// The canonical spelling is omo_senpi rather than bare omo because oh-my-openagent ships two
	// other editions today (a plugin riding OpenCode, and one riding Codex CLI); "omo" alone would
	// not say which one produced a row if Beacon ever observes those too, so it is normalized to
	// this edition's full name rather than left standing for the whole project.
	//
	// Deliberately narrow, and that is the whole reason for the set rather than a wider one. "senpi"
	// and "oh-my-openagent" both name things bigger than this one edition -- upstream Senpi is a
	// real, separately installable engine a user can run without OMO at all, and
	// "oh-my-openagent"/"oh-my-opencode" (the pre-rename package name) name the project as a whole,
	// under which the OpenCode and Codex CLI editions also ship. Accepting either here would claim a
	// spelling that a future integration for one of those needs for itself. Only spellings that say
	// "omo" specifically -- the branded binary and config directory this edition actually uses --
	// are accepted, and equality against that closed set rather than Contains for the same reason
	// Pi, Cline, Qwen Code and Prime Agent above use equality: "omo" is an ordinary three-letter
	// string that could appear inside an unrelated harness attribute.
	case lower == "omo" || lower == "omo_senpi" || lower == "omo-senpi" || lower == "omo senpi":
		return "omo_senpi"
	// fx (vercel-labs/fx) is matched by equality against a closed set for the same reason Pi is,
	// only more so: "fx" is two characters and appears inside ordinary words a harness attribute
	// can plausibly carry -- "sfx", "fx-runner", "effects" does not contain it but "fxagent" does
	// -- so a Contains rule would claim sessions that are not fx's. There is no prefix rule here
	// either: a future runtime named "fxr" is not this one.
	//
	// The canonical name is vercel_fx rather than fx because harness.name is what a SIEM query
	// groups by, and a two-letter value there says nothing about which product produced the row.
	// The vendor prefix follows what the product is called in practice ("Vercel fx") and keeps the
	// name self-describing for a reader who has never seen it before.
	case lower == "fx" || lower == "fx_cli" || lower == "fx-cli" || lower == "fx cli" ||
		lower == "fx.sh" || lower == "vercel_fx" || lower == "vercel-fx" || lower == "vercel fx" ||
		lower == "vercel fx cli" || lower == "fx_agent" || lower == "fx-agent":
		return "vercel_fx"
	// OpenHands (formerly All Hands AI) is matched by equality against a closed set for the same
	// reason Qwen Code and Muse Code are, and it is the Muse case exactly: the same organization
	// ships the agent and a model family under one name, so every OpenHands LM model id begins
	// with the letters the harness does -- openhands-lm-32b-v0.1, openhands-lm-7b-v0.1. A
	// Contains(lower, "openhands") rule would report any event whose harness attribute happened to
	// carry one of those model strings as an OpenHands session, and a reader could not tell the
	// misattribution from the real thing because both start with the same word.
	//
	// Model spellings are therefore deliberately left out of the set: they fall to the passthrough
	// case and show up as themselves, which is visible as an anomaly rather than silently filed
	// under the agent.
	//
	// The canonical spelling is plain `openhands` rather than `openhands_cli`, because OpenHands
	// is one product that runs the same agent in Cloud, the CLI and the local GUI -- Beacon hooks
	// all three through the same `.openhands/hooks.json`, so a CLI suffix would name only one of
	// the places the events come from. It follows `cline` and `omp`, not `codex_cli`.
	case lower == "openhands" || lower == "open_hands" || lower == "open-hands" || lower == "open hands" ||
		lower == "openhands_cli" || lower == "openhands-cli" || lower == "openhands cli" ||
		lower == "openhands_agent" || lower == "openhands-agent" || lower == "openhands agent" ||
		lower == "openhands.dev":
		return "openhands"
	// Grok Bot is xAI's always-on agent product: each Bot runs on a Cursor-hosted cloud computer
	// and the desktop app is a client to it. It is a different product from Grok Build, the xAI
	// terminal coding agent Beacon hooks under the `grok` harness, and the two must never share a
	// name: one runs on the endpoint under the operator's own account, the other runs in a vendor
	// cloud and reaches Beacon only through Cursor's server-side OpenTelemetry export (resource
	// attribute cursor.surface=grok_bot). A query grouping by harness.name that merged them would
	// file cloud-computer shell commands under a local CLI.
	//
	// Equality against a closed set, and deliberately narrower than every other xAI spelling.
	// "grok" alone is Grok Build and stays on the passthrough path as itself; "grok-4", "grok-4.6"
	// and the other model ids also begin with the same four letters, so a Contains(lower, "grok")
	// rule would claim both the sibling product and any event whose harness attribute carried a
	// model string. Those fall through and show up as themselves, which is the visible anomaly a
	// reader can act on rather than a silent misattribution.
	//
	// The canonical spelling is grok_bot because that is what the product is called and what
	// Cursor's own export writes for the surface; it follows claude_code and muse_code, not a CLI
	// suffix, because there is no CLI.
	case lower == "grok_bot" || lower == "grok-bot" || lower == "grok bot" || lower == "grokbot" ||
		lower == "grok_bot_desktop" || lower == "grok-bot-desktop" || lower == "cursor.grok_bot" ||
		lower == "cursor/grok_bot" || lower == "xai_grok_bot" || lower == "xai-grok-bot":
		return "grok_bot"
	// Kiro is AWS's coding agent. One agent harness runs it in the Kiro IDE, the Kiro CLI
	// (`kiro-cli`), Kiro Web, Mobile and Crew, and every local surface loads the same
	// `.kiro/hooks/*.json` files -- so Beacon hooks all of them at once and there is one runtime
	// to name, not two. The canonical spelling is plain `kiro` for that reason: it follows `cline`
	// and `openhands`, not `codex_cli`, because a CLI suffix would name one of the surfaces the
	// events come from and not the others.
	//
	// `kiro_code` is accepted as an input spelling but is deliberately not the canonical one.
	// Kiro's own documentation never uses it -- the product is "Kiro", the IDE is "Kiro IDE" and
	// the terminal client is "Kiro CLI" -- and choosing a name the vendor does not use would make
	// harness.name harder to match against anything else a reader has seen.
	//
	// Equality against a closed set rather than Contains(lower, "kiro"), for the reason Pi and Oh
	// My Pi already carry in a sharper form: "kiro" is four characters and Kiro stamps them on
	// paths and configuration names that legitimately appear in other fields -- `.kiro/hooks`,
	// `.kiroignore`, `KIRO_HOME`, `kiro_powers`. A substring rule would claim a harness attribute
	// that merely mentioned one of those. There is no prefix rule for the same reason: a future
	// runtime named "kirosaki" is not this one.
	//
	// Unlike Qwen Code, Muse Code and OpenHands, there is no model family to keep out of the set:
	// Kiro runs third-party models under their own names and ships none called kiro. The closed
	// set still holds, because that is a fact about today's model catalog rather than a property
	// of the name, and a `kiro-*` model id appearing later would otherwise be filed as the agent.
	case lower == "kiro" || lower == "kiro_ide" || lower == "kiro-ide" || lower == "kiro ide" ||
		lower == "kiro_cli" || lower == "kiro-cli" || lower == "kiro cli" || lower == "kirocli" ||
		lower == "kiro_code" || lower == "kiro-code" || lower == "kiro code" || lower == "kirocode" ||
		lower == "kiro_agent" || lower == "kiro-agent" || lower == "kiro agent" ||
		lower == "kiro.dev":
		return "kiro"
	// goose (Block) reaches Beacon over two paths at once, and pinning the name here is what keeps
	// them from splitting one session in two. The hook path installs with --platform goose; the
	// OTLP path reads goose's own resource attributes, which set service.name and
	// service.namespace to the literal string "goose". Both land on the same value only because
	// this case exists to say so.
	//
	// The canonical spelling is plain `goose` for the reason `cline`, `openhands` and `kiro` are
	// unsuffixed: one agent core serves the CLI, the desktop app and the embedded server, all
	// three discover the same `.agents/plugins` hooks and all three export under the same
	// service.name -- so a CLI suffix would name one of the surfaces the events come from and not
	// the others.
	//
	// Equality against a closed set rather than Contains(lower, "goose"), and here the substring
	// rule would be worse than usual on three counts:
	//
	//   - GooseAI is a different company's LLM inference service. Its spellings -- gooseai,
	//     goose-ai, goose.ai -- are a model provider, not this runtime, and they are deliberately
	//     absent from the set. That is the Muse Spark and OpenHands LM failure in a sharper form:
	//     those are at least the same vendor's model, while this would file a third party's
	//     inference endpoint as Block's agent.
	//   - "goose" is an ordinary English word, so it turns up in repository names, hostnames and
	//     user names that a harness attribute can legitimately carry.
	//   - goose stamps its own name across paths and configuration a reader may pass through this
	//     function -- .goosehints, GOOSE_MODE, goose-docs -- exactly the Kiro hazard above.
	//
	// Everything left out falls to the passthrough case and shows up as itself, which reads as an
	// anomaly a person can act on rather than a silent misattribution.
	//
	// "codename goose" is in the set because it is the project's own branding and appears in
	// release artifacts and documentation, so it is a spelling that arrives in practice rather
	// than one invented here.
	case lower == "goose" || lower == "goose_cli" || lower == "goose-cli" || lower == "goose cli" ||
		lower == "goosecli" || lower == "goose_agent" || lower == "goose-agent" || lower == "goose agent" ||
		lower == "codename_goose" || lower == "codename-goose" || lower == "codename goose" ||
		lower == "block_goose" || lower == "block-goose" || lower == "block goose":
		return "goose"
	// DeepSeek Harness (`dsh`) is DeepSeek's open agent harness: a TypeScript, plugin-composed
	// runtime whose CLI, Web, ACP and SDK surfaces all boot from one `$DSH_HOME` and one patch
	// layer -- so Beacon hooks all of them at once through a single mount and there is one runtime
	// to name, not four.
	//
	// The canonical spelling is `deepseek_harness` rather than `dsh`, for the reason vercel_fx is
	// not `fx`: harness.name is what a SIEM query groups by, and a three-letter value there says
	// nothing about which product produced the row. `dsh` is accepted as an input spelling because
	// it is what the binary is called and what an operator types.
	//
	// Equality against a closed set, and this is the sharpest case in this function for it.
	// DeepSeek ships the agent and a model family under one name, so every DeepSeek model id
	// begins with the letters the harness does -- deepseek-chat, deepseek-reasoner, deepseek-v3,
	// deepseek-r1, deepseek-coder. A Contains(lower, "deepseek") rule would report any event whose
	// harness attribute happened to carry one of those model strings as a DeepSeek Harness
	// session, and the misattribution would be unreadable as one because both start with the same
	// word. The same hazard applies to `dsh`: the runtime stamps those three letters on
	// environment variables and paths that legitimately appear in other fields -- DSH_HOME,
	// ~/.dsh, DSH_GITHUB_WEBHOOK_SECRET, the managed $DSH_* variables a bash tool call can print.
	//
	// Bare `deepseek` is deliberately NOT in the set, and that is the one entry a reader is most
	// likely to want to add. It is the vendor and the model family, not the harness: an OTLP
	// resource attribute reading "deepseek" is far more likely to have come from a provider route
	// than from this runtime, and filing it under the agent would attribute somebody's API traffic
	// to an endpoint install that may not exist. It falls to the passthrough case and shows up as
	// itself, which reads as an anomaly a person can act on.
	case lower == "dsh" || lower == "dsh_cli" || lower == "dsh-cli" || lower == "dsh cli" ||
		lower == "dshcli" || lower == "deepseek_harness" || lower == "deepseek-harness" ||
		lower == "deepseek harness" || lower == "deepseekharness" ||
		lower == "deepseek_ai/dsh" || lower == "deepseek-ai/dsh" ||
		lower == "@deepseek-ai/dsh" || lower == "deepseek_dsh" || lower == "deepseek-dsh":
		return "deepseek_harness"
	// Kimi Code (Moonshot AI) is one agent core behind several front ends -- the terminal CLI, the
	// desktop app, the VS Code extension and the ACP server -- and all of them report the same
	// client identity to a hook (`client_type: "kimi_code_cli"`), because the identity names the
	// core rather than the window it is drawn in. So there is one runtime to name, not four, and
	// the canonical spelling is `kimi_code`: it is the product's name and follows claude_code,
	// qwen_code and muse_code rather than a CLI suffix that would describe only one surface.
	//
	// Equality against a closed set rather than Contains(lower, "kimi"), and this runtime needs it
	// for three separate reasons at once -- more than any other case in this function:
	//
	//   - The model family. Every Kimi model id begins with the letters the harness does:
	//     kimi-k2, kimi-k3, kimi-k2.7-code, kimi-latest, kimi-thinking, kimi-for-coding. That is
	//     the Qwen, Muse Spark and OpenHands LM hazard, and here the catalog is large and still
	//     growing.
	//   - The provider. `kimi` is a provider *type* in the runtime's own config.toml
	//     (`[providers.kimi]`, `type = "kimi"`, `KIMI_API_KEY`), so the string names an API route
	//     that other runtimes use too -- a Claude Code session pointed at Moonshot is not a Kimi
	//     Code session.
	//   - The vendor's other surfaces. `kimi.com` is the consumer chat product, which Beacon does
	//     not observe at all; reporting it as the coding agent would invent an endpoint install.
	//
	// Bare `kimi` is nonetheless IN the set, unlike bare `deepseek` above, and the difference is
	// worth stating because the two cases look identical from a distance. It is the `--platform`
	// value Beacon's own installer writes -- the binary is `kimi`, and the flag follows the binary
	// the way `muse`, `qwen` and `kiro` do -- so leaving it out would mean every hook Beacon
	// installs reports a name this function refuses to canonicalize. The three hazards above are
	// all handled by equality rather than by exclusion: no model id is exactly "kimi", and the
	// provider type and the chat product reach harness.name by no path that exists today, because
	// Kimi Code exports no OpenTelemetry and the only writer is the flag Beacon wrote itself.
	// `deepseek` is out of its set for the opposite reason -- `dsh`, not `deepseek`, is that
	// runtime's flag, so excluding the vendor word costs nothing there and costs the whole
	// integration here.
	//
	// Model spellings are deliberately absent, so they fall to the passthrough case and show up as
	// themselves -- a visible anomaly a person can act on rather than a silent misattribution.
	case lower == "kimi" || lower == "kimi_code" || lower == "kimi-code" || lower == "kimi code" ||
		lower == "kimicode" || lower == "kimi_cli" || lower == "kimi-cli" || lower == "kimi cli" ||
		lower == "kimi_code_cli" || lower == "kimi-code-cli" || lower == "kimi code cli" ||
		lower == "kimi_code_acp" || lower == "kimi-code-acp" ||
		lower == "moonshot_kimi_code" || lower == "moonshot-kimi-code":
		return "kimi_code"
	// Harness² (google-research/harness2) is a framework that drives other agents rather than
	// being one: it refines an OpenCode or Codex executor's harness by running that executor over
	// benchmark tasks, many times per task. Beacon reads the trajectories it records under its runs
	// directory and files them under this one name, with the executor that produced each one kept
	// beside it, because the question a reader of these sessions asks first is "which of these
	// came from an experiment" rather than "which agent binary ran".
	//
	// Equality against a closed set rather than Contains(lower, "harness"), and the reason is a
	// different product. Harness (harness.io) is a CI/CD platform with its own `harness` CLI and
	// delegate, and "harness" is also what half the field calls the code around a model -- this
	// function's own name uses the word that way. A substring rule would file any of those under
	// this framework. Bare "harness" is therefore deliberately NOT in the set and falls to the
	// passthrough case, as a visible anomaly rather than a silent misattribution. The superscript
	// spelling is the project's own name for itself; "harness^2" is how it is typed without one.
	case lower == "harness2" || lower == "harness²" || lower == "harness^2" || lower == "harness_2" ||
		lower == "harness-2" || lower == "harness 2" || lower == "harness2_cli" || lower == "harness2-cli" ||
		lower == "google-research/harness2" || lower == "google_research/harness2" ||
		lower == "google_harness2" || lower == "google-harness2":
		return "harness2"
	case name != "":
		// An unrecognized runtime keeps its own name rather than being coerced or dropped. A new
		// harness should show up in the log as itself, not as "unknown".
		return name
	default:
		return ""
	}
}

// CodexSurface is the harness a Codex originator names. Every Codex client (the terminal CLI,
// `codex exec`, the IDE extension, the desktop app) runs on Codex's app-server and reports its
// client name as `originator`: on OTLP records sanitized to a metric tag ("codex-tui",
// "codex_exec", "Codex_Desktop"), and verbatim in a rollout's session_meta ("Codex Desktop"). The
// live collector and `codex sync` both name a conversation from it, so one conversation gets one
// name on both paths. Only the desktop app is codex_desktop.
func CodexSurface(originator string) string {
	lower := strings.ToLower(strings.TrimSpace(originator))
	switch {
	case strings.Contains(lower, "desktop"):
		return "codex_desktop"
	// The IDE extension is the CLI's agent in an editor panel, with no harness of its own.
	case lower == "codex_vscode":
		return "codex_cli"
	default:
		return "codex_cli"
	}
}

// IsCodexAppServer reports whether a service name is Codex's app-server, the one the CLI and the
// desktop app share and that therefore needs an originator to place.
func IsCodexAppServer(serviceName string) bool {
	normalized := strings.NewReplacer("-", "", "_", "", " ", "").Replace(strings.ToLower(strings.TrimSpace(serviceName)))
	return normalized == "codexappserver"
}