Skip to content

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

refactor(cmd): unify harness target normalization into one table

Claude6748cead2065
diff --git a/cli/beacon/cmd/endpoint_targets.go b/cli/beacon/cmd/endpoint_targets.go
index d3084b5c..d57071e3 100644
--- a/cli/beacon/cmd/endpoint_targets.go
+++ b/cli/beacon/cmd/endpoint_targets.go
@@ -17,41 +17,89 @@ type endpointTarget struct {
Kind endpointTargetKind
}
-func normalizeEndpointTarget(name string) (endpointTarget, bool) {
+// harnessTarget is one row of the supported-harness registry. It is the single
+// source of truth for both normalizers:
+//
+// - endpointAliases map a spelling to the harness in the combined endpoint
+// namespace, classified by endpointKind (OTLP vs hook).
+// - hookAliases map a spelling to the harness in the hook-only namespace.
+//
+// The two alias sets differ on purpose: in the hook-only namespace some OTLP
+// spellings are reinterpreted as their hook variant (for example "claude" and
+// "vscode"), and OTLP-only harnesses are not hook-addressable at all.
+type harnessTarget struct {
+ name string
+ endpointKind endpointTargetKind
+ endpointAliases []string
+ hookAliases []string
+}
+
+// harnessTargets lists every supported runtime. Adding a harness is one row;
+// the lookup tables below are derived from it.
+var harnessTargets = []harnessTarget{
+ {name: "claude", endpointKind: endpointTargetOTLP, endpointAliases: []string{"claude", "claude-code"}, hookAliases: []string{"claude", "claude-code"}},
+ {name: "claude", endpointKind: endpointTargetHook, endpointAliases: []string{"claude-hooks"}, hookAliases: []string{"claude-hooks"}},
+ {name: "codex", endpointKind: endpointTargetOTLP, endpointAliases: []string{"codex", "codex-cli"}},
+ {name: "gemini", endpointKind: endpointTargetOTLP, endpointAliases: []string{"gemini", "gemini-cli"}},
+ {name: "vscode", endpointKind: endpointTargetOTLP, endpointAliases: []string{"vscode", "vs-code", "vscode-copilot"}, hookAliases: []string{"vscode", "vs-code"}},
+ {name: "cursor", endpointKind: endpointTargetHook, endpointAliases: []string{"cursor"}, hookAliases: []string{"cursor"}},
+ {name: "factory", endpointKind: endpointTargetHook, endpointAliases: []string{"factory", "droid"}, hookAliases: []string{"factory", "droid"}},
+ {name: "opencode", endpointKind: endpointTargetHook, endpointAliases: []string{"opencode"}, hookAliases: []string{"opencode"}},
+ {name: "grok", endpointKind: endpointTargetHook, endpointAliases: []string{"grok"}, hookAliases: []string{"grok"}},
+ {name: "hermes", endpointKind: endpointTargetHook, endpointAliases: []string{"hermes", "hermes-agent"}, hookAliases: []string{"hermes", "hermes-agent"}},
+ {name: "antigravity", endpointKind: endpointTargetHook, endpointAliases: []string{"antigravity", "antigravity-cli"}, hookAliases: []string{"antigravity", "antigravity-cli"}},
+ {name: "devin-cli", endpointKind: endpointTargetHook, endpointAliases: []string{"devin", "devin-cli"}, hookAliases: []string{"devin", "devin-cli"}},
+ {name: "devin-desktop", endpointKind: endpointTargetHook, endpointAliases: []string{"devin-desktop"}, hookAliases: []string{"devin-desktop"}},
+}
+
+var (
+ endpointTargetLookup = buildEndpointTargetLookup()
+ hookTargetLookup = buildHookTargetLookup()
+)
+
+func buildEndpointTargetLookup() map[string]endpointTarget {
+ m := make(map[string]endpointTarget)
+ for _, t := range harnessTargets {
+ for _, alias := range t.endpointAliases {
+ m[alias] = endpointTarget{Name: t.name, Kind: t.endpointKind}
+ }
+ }
+ return m
+}
+
+func buildHookTargetLookup() map[string]string {
+ m := make(map[string]string)
+ for _, t := range harnessTargets {
+ for _, alias := range t.hookAliases {
+ m[alias] = t.name
+ }
+ }
+ return m
+}
+
+// normalizeHarnessKey canonicalizes a user-supplied harness spelling: trimmed,
+// lowercased, with underscores treated as hyphens.
+func normalizeHarnessKey(name string) string {
key := strings.ToLower(strings.TrimSpace(name))
- key = strings.ReplaceAll(key, "_", "-")
- switch key {
- case "":
- return endpointTarget{}, false
- case "claude", "claude-code":
- return endpointTarget{Name: "claude", Kind: endpointTargetOTLP}, true
- case "codex", "codex-cli":
- return endpointTarget{Name: "codex", Kind: endpointTargetOTLP}, true
- case "gemini", "gemini-cli":
- return endpointTarget{Name: "gemini", Kind: endpointTargetOTLP}, true
- case "vscode", "vs-code", "vscode-copilot":
- return endpointTarget{Name: "vscode", Kind: endpointTargetOTLP}, true
- case "cursor":
- return endpointTarget{Name: "cursor", Kind: endpointTargetHook}, true
- case "claude-hooks":
- return endpointTarget{Name: "claude", Kind: endpointTargetHook}, true
- case "factory", "droid":
- return endpointTarget{Name: "factory", Kind: endpointTargetHook}, true
- case "opencode":
- return endpointTarget{Name: "opencode", Kind: endpointTargetHook}, true
- case "grok":
- return endpointTarget{Name: "grok", Kind: endpointTargetHook}, true
- case "hermes", "hermes-agent":
- return endpointTarget{Name: "hermes", Kind: endpointTargetHook}, true
- case "antigravity", "antigravity-cli":
- return endpointTarget{Name: "antigravity", Kind: endpointTargetHook}, true
- case "devin", "devin-cli":
- return endpointTarget{Name: "devin-cli", Kind: endpointTargetHook}, true
- case "devin-desktop":
- return endpointTarget{Name: "devin-desktop", Kind: endpointTargetHook}, true
- default:
+ return strings.ReplaceAll(key, "_", "-")
+}
+
+func normalizeEndpointTarget(name string) (endpointTarget, bool) {
+ key := normalizeHarnessKey(name)
+ if key == "" {
return endpointTarget{}, false
}
+ target, ok := endpointTargetLookup[key]
+ return target, ok
+}
+
+func normalizeHookTarget(name string) (string, bool) {
+ key := normalizeHarnessKey(name)
+ if key == "" {
+ return "", false
+ }
+ target, ok := hookTargetLookup[key]
+ return target, ok
}
func splitEndpointTargets(values []string) (otlp []string, hooks []string, err error) {
@@ -99,37 +147,3 @@ func canonicalHookTargets(values []string) ([]string, error) {
}
return targets, nil
}
-
-func normalizeHookTarget(name string) (string, bool) {
- key := strings.ToLower(strings.TrimSpace(name))
- key = strings.ReplaceAll(key, "_", "-")
- switch key {
- case "":
- return "", false
- case "antigravity", "antigravity-cli":
- return "antigravity", true
- case "cursor":
- return "cursor", true
- case "claude", "claude-code":
- return "claude", true
- case "vscode", "vs-code":
- return "vscode", true
- case "factory", "droid":
- return "factory", true
- case "opencode":
- return "opencode", true
- case "grok":
- return "grok", true
- case "hermes", "hermes-agent":
- return "hermes", true
- case "devin", "devin-cli":
- return "devin-cli", true
- case "devin-desktop":
- return "devin-desktop", true
- default:
- if target, ok := normalizeEndpointTarget(key); ok && target.Kind == endpointTargetHook {
- return target.Name, true
- }
- return "", false
- }
-}
diff --git a/cli/beacon/cmd/endpoint_targets_characterization_test.go b/cli/beacon/cmd/endpoint_targets_characterization_test.go
new file mode 100644
index 00000000..44ccfe13
--- /dev/null
+++ b/cli/beacon/cmd/endpoint_targets_characterization_test.go
@@ -0,0 +1,104 @@
+package cmd
+
+import "testing"
+
+// These characterization tests pin the exact input→output mapping of the two
+// harness-target normalizers across every recognized alias (including the
+// underscore spellings) and the OTLP/Hook asymmetries, before the two switch
+// statements are collapsed into a single harness table. They guard against any
+// behavior drift during that refactor.
+
+func TestNormalizeEndpointTargetCharacterization(t *testing.T) {
+ type want struct {
+ name string
+ kind endpointTargetKind
+ ok bool
+ }
+ cases := map[string]want{
+ // OTLP harnesses
+ "claude": {"claude", endpointTargetOTLP, true},
+ "claude-code": {"claude", endpointTargetOTLP, true},
+ "claude_code": {"claude", endpointTargetOTLP, true},
+ "codex": {"codex", endpointTargetOTLP, true},
+ "codex-cli": {"codex", endpointTargetOTLP, true},
+ "gemini": {"gemini", endpointTargetOTLP, true},
+ "gemini-cli": {"gemini", endpointTargetOTLP, true},
+ "vscode": {"vscode", endpointTargetOTLP, true},
+ "vs-code": {"vscode", endpointTargetOTLP, true},
+ "vscode-copilot": {"vscode", endpointTargetOTLP, true},
+ // Hook harnesses
+ "cursor": {"cursor", endpointTargetHook, true},
+ "claude-hooks": {"claude", endpointTargetHook, true},
+ "factory": {"factory", endpointTargetHook, true},
+ "droid": {"factory", endpointTargetHook, true},
+ "opencode": {"opencode", endpointTargetHook, true},
+ "grok": {"grok", endpointTargetHook, true},
+ "hermes": {"hermes", endpointTargetHook, true},
+ "hermes-agent": {"hermes", endpointTargetHook, true},
+ "antigravity": {"antigravity", endpointTargetHook, true},
+ "antigravity-cli": {"antigravity", endpointTargetHook, true},
+ "devin": {"devin-cli", endpointTargetHook, true},
+ "devin-cli": {"devin-cli", endpointTargetHook, true},
+ "devin-desktop": {"devin-desktop", endpointTargetHook, true},
+ // Case/whitespace normalization
+ " Claude_Code ": {"claude", endpointTargetOTLP, true},
+ "DEVIN_DESKTOP": {"devin-desktop", endpointTargetHook, true},
+ // Unsupported
+ "": {"", "", false},
+ "unknown": {"", "", false},
+ "vscode-hooks": {"", "", false},
+ "claude-cowork": {"", "", false},
+ }
+ for in, w := range cases {
+ got, ok := normalizeEndpointTarget(in)
+ if ok != w.ok || got.Name != w.name || (ok && got.Kind != w.kind) {
+ t.Errorf("normalizeEndpointTarget(%q) = (%+v, %v), want ({Name:%q Kind:%q}, %v)",
+ in, got, ok, w.name, w.kind, w.ok)
+ }
+ }
+}
+
+func TestNormalizeHookTargetCharacterization(t *testing.T) {
+ type want struct {
+ name string
+ ok bool
+ }
+ cases := map[string]want{
+ "antigravity": {"antigravity", true},
+ "antigravity-cli": {"antigravity", true},
+ "antigravity_cli": {"antigravity", true},
+ "cursor": {"cursor", true},
+ // claude is OTLP in the endpoint namespace but a hook in the hook namespace
+ "claude": {"claude", true},
+ "claude-code": {"claude", true},
+ "claude_code": {"claude", true},
+ "claude-hooks": {"claude", true},
+ "vscode": {"vscode", true},
+ "vs-code": {"vscode", true},
+ "vs_code": {"vscode", true},
+ "factory": {"factory", true},
+ "droid": {"factory", true},
+ "opencode": {"opencode", true},
+ "grok": {"grok", true},
+ "hermes": {"hermes", true},
+ "hermes-agent": {"hermes", true},
+ "devin": {"devin-cli", true},
+ "devin-cli": {"devin-cli", true},
+ "devin-desktop": {"devin-desktop", true},
+ "DEVIN_DESKTOP": {"devin-desktop", true},
+ // OTLP-only harnesses are not hook-addressable
+ "codex": {"", false},
+ "codex-cli": {"", false},
+ "gemini": {"", false},
+ "vscode-copilot": {"", false},
+ // Unsupported
+ "": {"", false},
+ "unknown": {"", false},
+ }
+ for in, w := range cases {
+ got, ok := normalizeHookTarget(in)
+ if ok != w.ok || got != w.name {
+ t.Errorf("normalizeHookTarget(%q) = (%q, %v), want (%q, %v)", in, got, ok, w.name, w.ok)
+ }
+ }
+}