The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Revert "Add Codex session token attribution"
Shukan Shah22cec2f01509
diff --git a/README.md b/README.mdindex 46106a76..bc4724f9 100644--- a/README.md+++ b/README.md@@ -80,7 +80,7 @@ CI, and cloud surfaces.| --- | --- | --- || [Antigravity CLI](https://docs.asymptotelabs.ai/cli/supported-runtimes-antigravity-cli) | Native hooks | Prompt, pre-tool, post-tool, stop, invocation, command, and file telemetry where Antigravity exposes hook payloads || [Claude Code](https://docs.asymptotelabs.ai/cli/supported-runtimes-claude-code) | Local OTLP export plus optional hooks | Prompt, command, tool, file, lifecycle, subagent, and permission telemetry where emitted through OTLP or hooks |-| [Codex CLI](https://docs.asymptotelabs.ai/cli/supported-runtimes-codex-cli) | Local OTLP logs plus usage reconciliation hooks | Session, prompt, approval, and tool-result activity from Codex semantic logs; session-level token usage from local Codex session JSONL |+| [Codex CLI](https://docs.asymptotelabs.ai/cli/supported-runtimes-codex-cli) | Local OTLP logs | Session, prompt, approval, and tool-result activity from Codex semantic logs || [Cursor](https://docs.asymptotelabs.ai/cli/supported-runtimes-cursor) | Native hooks | Prompt, tool, shell command, MCP-like, approval, and file edit telemetry || [Devin CLI](https://docs.asymptotelabs.ai/cli/supported-runtimes-devin) | Native hooks | Session, prompt, pre-tool, post-tool, permission request, stop, session-end, approval, and file telemetry || [Devin Desktop](https://docs.asymptotelabs.ai/cli/supported-runtimes-devin-desktop) | Cascade/Windsurf hooks | Prompt, command, MCP tool, file read, and file write telemetry where Desktop exposes Cascade hook payloads |diff --git a/cli/beacon-hooks/cmd/codex_usage_sync.go b/cli/beacon-hooks/cmd/codex_usage_sync.godeleted file mode 100644index 75121d30..00000000--- a/cli/beacon-hooks/cmd/codex_usage_sync.go+++ /dev/null@@ -1,117 +0,0 @@-package cmd--import (- "os"- "strings"- "time"-- "github.com/spf13/cobra"-- "github.com/asymptote-labs/agent-beacon/cli/beacon-hooks/internal/logging"- "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/codexusage"-)--var codexUsageSyncCmd = &cobra.Command{- Use: "codex-usage-sync",- Short: "Reconcile Codex session token usage into endpoint telemetry",- Hidden: true,- Run: runCodexUsageSync,-}--func init() {- rootCmd.AddCommand(codexUsageSyncCmd)-}--func runCodexUsageSync(cmd *cobra.Command, args []string) {- logger := logging.NewLoggerForPlatform("codex-usage-sync", platformFlag)- if platformFlag != "codex" {- outputJSON(emptyResponse)- return- }- if err := reconcileCodexUsage(logger); err != nil {- logger.Warn("Codex usage reconciliation failed", "error", err.Error())- }- outputJSON(emptyResponse)-}--func maybeReconcileCodexUsage(logger *logging.Logger) {- if platformFlag != "codex" {- return- }- if err := reconcileCodexUsage(logger); err != nil {- logger.Warn("Codex usage reconciliation failed", "error", err.Error())- }-}--func reconcileCodexUsage(logger *logging.Logger) error {- if !endpointLoggingConfigured() {- logger.Debug("Skipping Codex usage reconciliation because endpoint logging is not configured")- return nil- }- result, err := codexusage.ReconcileAndWrite(codexusage.ReconcileOptions{}, func(event codexusage.UsageEvent) error {- fields := codexUsageFields(event)- if err := logger.EndpointEvent("token.usage", "metric", "info", "Codex token usage observed", fields); err != nil {- return err- }- return nil- })- if err != nil {- return err- }- logger.Debug("Codex usage reconciliation completed", "events", len(result.Events), "scanned", result.Scanned)- return nil-}--func endpointLoggingConfigured() bool {- for _, key := range []string{"BEACON_ENDPOINT_LOG", "BEACON_CLOUD_LOG_PATH", "BEACON_LOG_PATH", "BEACON_RUNTIME_LOG"} {- if strings.TrimSpace(os.Getenv(key)) != "" {- return true- }- }- return strings.TrimSpace(os.Getenv("BEACON_ENDPOINT_MODE")) != ""-}--func codexUsageFields(event codexusage.UsageEvent) map[string]interface{} {- sessionID := "codex:" + event.SessionID- if event.SessionID == "" {- sessionID = ""- }- ts := event.Timestamp- if ts.IsZero() {- ts = time.Now().UTC()- }- fields := map[string]interface{}{- "timestamp": ts.UTC().Format(time.RFC3339),- "harness": map[string]interface{}{"name": "codex_cli"},- "model": event.Model,- "gen_ai": map[string]interface{}{- "usage": map[string]interface{}{- "input_tokens": event.InputTokens,- "output_tokens": event.OutputTokens,- "cache_read": map[string]interface{}{- "input_tokens": event.CacheReadTokens,- },- },- },- "raw": map[string]interface{}{- "source": codexusage.SourceCodexSessionJSONL,- "source_kind": "derived_session_usage",- "source_path_hash": codexusage.SourcePathHash(event.SourcePath),- "dedup_key": event.DedupKey,- "turn_id": event.TurnID,- "cost_source": "not_computed",- },- }- if event.ReasoningTokens > 0 {- fields["gen_ai"].(map[string]interface{})["usage"].(map[string]interface{})["reasoning"] = map[string]interface{}{- "output_tokens": event.ReasoningTokens,- }- }- if sessionID != "" {- fields["session"] = map[string]interface{}{"id": sessionID, "working_directory": event.WorkingDir}- }- if event.WorkingDir != "" {- fields["repository"] = event.WorkingDir- }- return fields-}diff --git a/cli/beacon-hooks/cmd/codex_usage_sync_test.go b/cli/beacon-hooks/cmd/codex_usage_sync_test.godeleted file mode 100644index 94389acf..00000000--- a/cli/beacon-hooks/cmd/codex_usage_sync_test.go+++ /dev/null@@ -1,108 +0,0 @@-package cmd--import (- "os"- "path/filepath"- "strings"- "testing"-)--func TestRunCodexUsageSyncWritesTokenUsageEvent(t *testing.T) {- tmp := t.TempDir()- logPath := filepath.Join(tmp, "runtime.jsonl")- statePath := filepath.Join(tmp, "state.json")- sessionDir := filepath.Join(tmp, "codex", "sessions")- if err := os.MkdirAll(sessionDir, 0755); err != nil {- t.Fatal(err)- }- sessionPath := filepath.Join(sessionDir, "session.jsonl")- lines := []string{- `{"type":"session_meta","timestamp":"2026-06-29T10:00:00Z","payload":{"id":"codex-session-1","cwd":"/repo"}}`,- `{"type":"turn_context","timestamp":"2026-06-29T10:00:01Z","payload":{"model":"gpt-5","turn_id":"turn-1"}}`,- `{"type":"event_msg","timestamp":"2026-06-29T10:00:03Z","payload":{"type":"token_count","info":{"last_token_usage":{"input_tokens":1000,"output_tokens":50,"cached_input_tokens":600,"reasoning_output_tokens":7}}}}`,- }- if err := os.WriteFile(sessionPath, []byte(strings.Join(lines, "\n")+"\n"), 0644); err != nil {- t.Fatal(err)- }- t.Setenv("BEACON_ENDPOINT_LOG", logPath)- t.Setenv("BEACON_CODEX_USAGE_STATE", statePath)- t.Setenv("BEACON_CODEX_SESSIONS_DIR", sessionDir)- origPlatform := platformFlag- platformFlag = "codex"- t.Cleanup(func() { platformFlag = origPlatform })-- runHookWithInput(t, runCodexUsageSync, map[string]interface{}{"hook_event_name": "Stop"})- events := endpointEvents(t, logPath)- if len(events) != 1 {- t.Fatalf("events = %#v, want one token event", events)- }- event := events[0]- if event["message"] != "Codex token usage observed" {- t.Fatalf("message = %#v", event["message"])- }- session := event["session"].(map[string]interface{})- if session["id"] != "codex:codex-session-1" {- t.Fatalf("session = %#v", session)- }- usage := event["gen_ai"].(map[string]interface{})["usage"].(map[string]interface{})- if usage["input_tokens"].(float64) != 400 || usage["output_tokens"].(float64) != 50 {- t.Fatalf("usage = %#v", usage)- }- cacheRead := usage["cache_read"].(map[string]interface{})- if cacheRead["input_tokens"].(float64) != 600 {- t.Fatalf("cache_read = %#v", cacheRead)- }- reasoning := usage["reasoning"].(map[string]interface{})- if reasoning["output_tokens"].(float64) != 7 {- t.Fatalf("reasoning = %#v", reasoning)- }- if _, ok := usage["cost_usd"]; ok {- t.Fatalf("Codex usage event should not include cost_usd: %#v", usage)- }- raw := event["raw"].(map[string]interface{})- if raw["source"] != "codex_session_jsonl" || raw["dedup_key"] == "" {- t.Fatalf("raw = %#v", raw)- }-- runHookWithInput(t, runCodexUsageSync, map[string]interface{}{"hook_event_name": "Stop"})- if got := len(endpointEvents(t, logPath)); got != 1 {- t.Fatalf("idempotent run wrote %d events, want 1", got)- }-}--func TestRunCodexUsageSyncWithoutEndpointLogDoesNotMarkSeen(t *testing.T) {- tmp := t.TempDir()- statePath := filepath.Join(tmp, "state.json")- sessionDir := filepath.Join(tmp, "codex", "sessions")- if err := os.MkdirAll(sessionDir, 0755); err != nil {- t.Fatal(err)- }- sessionPath := filepath.Join(sessionDir, "session.jsonl")- lines := []string{- `{"type":"session_meta","timestamp":"2026-06-29T10:00:00Z","payload":{"id":"codex-session-1"}}`,- `{"type":"turn_context","timestamp":"2026-06-29T10:00:01Z","payload":{"model":"gpt-5","turn_id":"turn-1"}}`,- `{"type":"event_msg","timestamp":"2026-06-29T10:00:03Z","payload":{"type":"token_count","info":{"last_token_usage":{"input_tokens":10,"output_tokens":2,"cached_input_tokens":4}}}}`,- }- if err := os.WriteFile(sessionPath, []byte(strings.Join(lines, "\n")+"\n"), 0644); err != nil {- t.Fatal(err)- }- t.Setenv("BEACON_ENDPOINT_LOG", "")- t.Setenv("BEACON_ENDPOINT_MODE", "")- t.Setenv("BEACON_CODEX_USAGE_STATE", statePath)- t.Setenv("BEACON_CODEX_SESSIONS_DIR", sessionDir)- origPlatform := platformFlag- platformFlag = "codex"- t.Cleanup(func() { platformFlag = origPlatform })-- runHookWithInput(t, runCodexUsageSync, map[string]interface{}{"hook_event_name": "Stop"})- if _, err := os.Stat(statePath); !os.IsNotExist(err) {- t.Fatalf("state path exists or stat failed after skipped reconciliation: %v", err)- }-- logPath := filepath.Join(tmp, "runtime.jsonl")- t.Setenv("BEACON_ENDPOINT_LOG", logPath)- runHookWithInput(t, runCodexUsageSync, map[string]interface{}{"hook_event_name": "Stop"})- if got := len(endpointEvents(t, logPath)); got != 1 {- t.Fatalf("events after configuring endpoint log = %d, want 1", got)- }-}diff --git a/cli/beacon-hooks/cmd/session_end.go b/cli/beacon-hooks/cmd/session_end.goindex b224308a..62f51a2c 100644--- a/cli/beacon-hooks/cmd/session_end.go+++ b/cli/beacon-hooks/cmd/session_end.go@@ -36,7 +36,6 @@ func runSessionEnd(cmd *cobra.Command, args []string) {logger := logging.NewSessionLogger("session-end", platformFlag, sessionID)logger.Info("Session ended", "session_id", sessionID, "platform", platformFlag)emitHookEvent(logger, "session.ended", "session", "info", "Agent session ended", input, sessionFields(sessionID, input))- maybeReconcileCodexUsage(logger)uploadCloudTelemetry(logger, true)logFile := config.GetSessionLogFile(platformFlag, sessionID)@@ -49,7 +48,6 @@ func runSessionEnd(cmd *cobra.Command, args []string) {uploadCloudTelemetry(platformLogger, true)} else {platformLogger.Info("Session ended", "platform", platformFlag)- maybeReconcileCodexUsage(platformLogger)uploadCloudTelemetry(platformLogger, true)}diff --git a/cli/beacon-hooks/cmd/stop.go b/cli/beacon-hooks/cmd/stop.goindex 1b15c4e9..0e555e08 100644--- a/cli/beacon-hooks/cmd/stop.go+++ b/cli/beacon-hooks/cmd/stop.go@@ -76,7 +76,6 @@ func runStop(cmd *cobra.Command, args []string) {elapsed := time.Since(start)logger.Info("stop completed", "duration_ms", elapsed.Milliseconds())emitHookEvent(logger, "tool.completed", "tool", "info", "Agent response completed", input, sessionFields(sessionID, input))- maybeReconcileCodexUsage(logger)uploadCloudTelemetry(logger, true)outputJSONAndExit(emptyResponse)}diff --git a/cli/beacon/README.md b/cli/beacon/README.mdindex b1223e09..f420af04 100644--- a/cli/beacon/README.md+++ b/cli/beacon/README.md@@ -16,16 +16,12 @@ make build./beacon endpoint discover --json./beacon endpoint repair./beacon endpoint dashboard-./beacon token-usage-./beacon endpoint codex-usage sync./beacon endpoint uninstall --keep-logs```Endpoint commands use per-user paths by default so hook and OTLP telemetry share`~/.beacon/endpoint/logs/runtime.jsonl`. Use `--system` for root-managed-deployment paths. `beacon endpoint codex-usage sync` reconciles local Codex-session JSONL into token-only runtime events when operators need a manual-backfill outside the normal Codex hook-triggered flow.+deployment paths.Add optional Splunk HEC forwarding during install or repair:diff --git a/cli/beacon/cmd/endpoint_codex_usage.go b/cli/beacon/cmd/endpoint_codex_usage.godeleted file mode 100644index 23c93d4f..00000000--- a/cli/beacon/cmd/endpoint_codex_usage.go+++ /dev/null@@ -1,113 +0,0 @@-package cmd--import (- "fmt"- "os"- "runtime"- "time"-- "github.com/spf13/cobra"-- "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/lifecycle"- "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"- "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/writer"- "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"- "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/codexusage"-)--var endpointCodexUsageCmd = &cobra.Command{- Use: "codex-usage",- Short: "Manage Codex session token usage reconciliation",-}--var endpointCodexUsageSyncCmd = &cobra.Command{- Use: "sync",- Short: "Write derived Codex session token usage events to the runtime log",- SilenceUsage: true,- RunE: runEndpointCodexUsageSync,-}--func init() {- endpointCmd.AddCommand(endpointCodexUsageCmd)- endpointCodexUsageCmd.AddCommand(endpointCodexUsageSyncCmd)- endpointCodexUsageSyncCmd.Flags().BoolVar(&endpointOpts.userMode, "user", true, "Use per-user endpoint paths")- endpointCodexUsageSyncCmd.Flags().BoolVar(&endpointOpts.systemMode, "system", false, "Use system endpoint paths")- endpointCodexUsageSyncCmd.Flags().StringVar(&endpointOpts.logPath, "log-path", "", "Runtime JSONL log path")-}--func runEndpointCodexUsageSync(cmd *cobra.Command, args []string) error {- userMode := endpointOpts.userMode- if endpointOpts.systemMode {- userMode = false- }- runtimeLog := lifecycle.ResolveRuntimeLog(userMode, endpointOpts.logPath)- result, err := syncCodexUsageToLog(runtimeLog.EffectiveLogPath, runtimeLog.EffectiveUserMode)- if err != nil {- return err- }- fmt.Fprintf(cmd.OutOrStdout(), "Wrote %d Codex token usage events (scanned %d files)\n", len(result.Events), result.Scanned)- return nil-}--func syncCodexUsageToLog(logPath string, userMode bool) (codexusage.ReconcileResult, error) {- return codexusage.ReconcileAndWrite(codexusage.ReconcileOptions{}, func(usage codexusage.UsageEvent) error {- event := codexUsageSchemaEvent(usage)- if _, err := writer.AppendEvent(event, writer.Options{Path: logPath, UserMode: userMode}); err != nil {- return err- }- return nil- })-}--func codexUsageSchemaEvent(usage codexusage.UsageEvent) schema.Event {- ts := usage.Timestamp- if ts.IsZero() {- ts = time.Now().UTC()- }- sessionID := ""- if usage.SessionID != "" {- sessionID = "codex:" + usage.SessionID- }- input := usage.InputTokens- output := usage.OutputTokens- cacheRead := usage.CacheReadTokens- reasoning := usage.ReasoningTokens- event := schema.NewEvent(schema.NewEventOptions{- Action: "token.usage",- Category: "metric",- Severity: schema.SeverityInfo,- Harness: schema.HarnessInfo{Name: "codex_cli"},- Message: "Codex token usage observed",- Origin: schema.OriginLocal,- })- event.Timestamp = ts.UTC().Format(time.RFC3339)- event.Endpoint.OS = runtime.GOOS- if hostname, err := os.Hostname(); err == nil {- event.Endpoint.Hostname = hostname- }- event.Model = usage.Model- event.Repository = usage.WorkingDir- if sessionID != "" {- event.Session = &schema.SessionInfo{ID: sessionID, WorkingDirectory: usage.WorkingDir}- }- event.GenAI = &schema.GenAIInfo{- Usage: &schema.GenAIUsageInfo{- InputTokens: &input,- OutputTokens: &output,- CacheRead: &schema.GenAIUsageCacheReadInfo{InputTokens: &cacheRead},- },- }- if reasoning > 0 {- event.GenAI.Usage.Reasoning = &schema.GenAIUsageReasoningInfo{OutputTokens: &reasoning}- }- event.Raw = map[string]interface{}{- "source": codexusage.SourceCodexSessionJSONL,- "source_kind": "derived_session_usage",- "source_path_hash": codexusage.SourcePathHash(usage.SourcePath),- "dedup_key": usage.DedupKey,- "turn_id": usage.TurnID,- "cost_source": "not_computed",- }- event.Content = &schema.ContentInfo{Retention: asymptoteobserve.ContentRetentionMetadata, Included: false}- return event-}diff --git a/cli/beacon/cmd/token_usage.go b/cli/beacon/cmd/token_usage.goindex 79aac7c1..7fe38577 100644--- a/cli/beacon/cmd/token_usage.go+++ b/cli/beacon/cmd/token_usage.go@@ -13,21 +13,19 @@ import ()type tokenUsageOptions struct {- userMode bool- systemMode bool- logPath string- jsonOutput bool- since string- until string- session string- model string- harness string- repository string- runID string- bucket string- top int- codexSource string- codexSync bool+ userMode bool+ systemMode bool+ logPath string+ jsonOutput bool+ since string+ until string+ session string+ model string+ harness string+ repository string+ runID string+ bucket string+ top int}var tokenUsageOpts tokenUsageOptions@@ -69,19 +67,9 @@ func runTokenUsage(cmd *cobra.Command, args []string) error {if err != nil {return err}- if tokenUsageOpts.codexSync {- if _, err := syncCodexUsageToLog(runtimeLog.EffectiveLogPath, runtimeLog.EffectiveUserMode); err != nil {- return err- }- events, err = dashboard.ReadEventsAppendOrder(runtimeLog.EffectiveLogPath, query)- if err != nil {- return err- }- }opts := tokens.Options{- SessionID: tokenUsageOpts.session,- TopLimit: tokenUsageOpts.top,- CodexSource: tokenUsageOpts.codexSource,+ SessionID: tokenUsageOpts.session,+ TopLimit: tokenUsageOpts.top,}if bucket := strings.TrimSpace(tokenUsageOpts.bucket); bucket != "" {parsed, err := time.ParseDuration(bucket)@@ -116,6 +104,4 @@ func init() {tokenUsageCmd.Flags().StringVar(&tokenUsageOpts.runID, "run-id", "", "Filter by CI run id")tokenUsageCmd.Flags().StringVar(&tokenUsageOpts.bucket, "bucket", "", "Time-series bucket size (for example 1h or 15m)")tokenUsageCmd.Flags().IntVar(&tokenUsageOpts.top, "top", 0, "Limit each grouping to the top N entries (0 keeps all)")- tokenUsageCmd.Flags().StringVar(&tokenUsageOpts.codexSource, "codex-source", tokens.CodexSourceAuto, "Codex usage source: auto, runtime, otlp, or both-debug")- tokenUsageCmd.Flags().BoolVar(&tokenUsageOpts.codexSync, "codex-sync", false, "Reconcile local Codex session token usage before reading the runtime log")}diff --git a/cli/beacon/cmd/token_usage_test.go b/cli/beacon/cmd/token_usage_test.goindex 2115c3ab..f9297e52 100644--- a/cli/beacon/cmd/token_usage_test.go+++ b/cli/beacon/cmd/token_usage_test.go@@ -19,7 +19,7 @@ func TestTokenUsageCommandRegistered(t *testing.T) {if cmd == nil || cmd.Use != "token-usage" {t.Fatalf("token-usage command not registered: %#v", cmd)}- for _, flag := range []string{"log-path", "json", "since", "until", "session", "model", "harness", "repository", "run-id", "bucket", "top", "codex-source", "codex-sync"} {+ for _, flag := range []string{"log-path", "json", "since", "until", "session", "model", "harness", "repository", "run-id", "bucket", "top"} {if cmd.Flags().Lookup(flag) == nil {t.Fatalf("token-usage command missing --%s flag", flag)}@@ -116,21 +116,3 @@ func TestTokenUsageEmptyLogSucceeds(t *testing.T) {t.Fatalf("empty report = %q", output)}}--func TestTokenUsageCodexSourceSummary(t *testing.T) {- logPath := filepath.Join(t.TempDir(), "runtime.jsonl")- lines := []string{- `{"timestamp":"2026-06-11T10:00:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"token.usage","category":"metric"},"severity":"info","endpoint":{"os":"darwin"},"harness":{"name":"codex_cli"},"session":{"id":"codex:s1"},"model":"gpt-5","gen_ai":{"usage":{"input_tokens":40,"output_tokens":10,"cache_read":{"input_tokens":60}}},"message":"Codex token usage observed","raw":{"source":"codex_session_jsonl","dedup_key":"turn-1"}}`,- `{"timestamp":"2026-06-11T10:00:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"token.usage","category":"metric"},"severity":"info","endpoint":{"os":"darwin"},"harness":{"name":"codex_cli"},"model":"gpt-5","gen_ai":{"usage":{"input_tokens":40,"output_tokens":10,"cache_read":{"input_tokens":60}}},"message":"codex.turn.token_usage","raw":{"metric_name":"codex.turn.token_usage","metric_temporality":"Delta"}}`,- }- if err := os.WriteFile(logPath, []byte(strings.Join(lines, "\n")+"\n"), 0644); err != nil {- t.Fatal(err)- }- output := runTokenUsageCommand(t, "--log-path", logPath)- if !strings.Contains(output, "Codex source: session files (OTLP suppressed)") {- t.Fatalf("text report missing Codex source summary:\n%s", output)- }- if !strings.Contains(output, "codex:s1") {- t.Fatalf("text report missing session attribution:\n%s", output)- }-}diff --git a/cli/beacon/internal/endpoint/dashboard/server.go b/cli/beacon/internal/endpoint/dashboard/server.goindex b0271010..d09578b7 100644--- a/cli/beacon/internal/endpoint/dashboard/server.go+++ b/cli/beacon/internal/endpoint/dashboard/server.go@@ -293,7 +293,7 @@ func parseQuery(r *http.Request, fallbackLimit int) EventQuery {func tokenOptions(r *http.Request) tokens.Options {q := r.URL.Query()- opts := tokens.Options{SessionID: q.Get("session"), CodexSource: q.Get("codex_source")}+ opts := tokens.Options{SessionID: q.Get("session")}if bucket := q.Get("bucket"); bucket != "" {if parsed, err := time.ParseDuration(bucket); err == nil && parsed > 0 {opts.BucketSize = parseddiff --git a/cli/beacon/internal/endpoint/dashboard/static/app.js b/cli/beacon/internal/endpoint/dashboard/static/app.jsindex 0a2894b1..10cf19c0 100644--- a/cli/beacon/internal/endpoint/dashboard/static/app.js+++ b/cli/beacon/internal/endpoint/dashboard/static/app.js@@ -1031,11 +1031,7 @@ async function loadTokens() {function renderTokensPage(report, session) {setText("#log-path", state.status?.log_path || "Runtime log unavailable");- const meta = [`${report.events_with_usage} of ${report.total_events} events carry usage`];- if (report.source?.codex) {- meta.push(`Codex source: ${report.source.codex}`);- }- setText("#token-meta", meta.join(" · "));+ setText("#token-meta", `${report.events_with_usage} of ${report.total_events} events carry usage`);renderTokenCards(report.totals || {});renderUtilizationRows(report.utilization || []);renderUsageGroupRows("#token-models", report.by_model || [], "model");diff --git a/cli/beacon/internal/endpoint/hooks/codex.go b/cli/beacon/internal/endpoint/hooks/codex.goindex 1c666a25..bee25977 100644--- a/cli/beacon/internal/endpoint/hooks/codex.go+++ b/cli/beacon/internal/endpoint/hooks/codex.go@@ -65,8 +65,6 @@ func installCodexHooks(path, binaryPath, logPath, configPath string) error {endpointHooks := map[string]settingsHookGroup{"SessionStart": {Hooks: []settingsHookRef{{Type: "command", Command: prefix + " inventory-heartbeat", Timeout: 10}}},"UserPromptSubmit": {Hooks: []settingsHookRef{{Type: "command", Command: prefix + " inventory-heartbeat", Timeout: 10}}},- "Stop": {Hooks: []settingsHookRef{{Type: "command", Command: prefix + " codex-usage-sync", Timeout: 10}}},- "SessionEnd": {Hooks: []settingsHookRef{{Type: "command", Command: prefix + " codex-usage-sync", Timeout: 10}}},}return installSettingsEndpointHooks(path, "codex", endpointHooks)}diff --git a/cli/beacon/internal/endpoint/hooks/codex_test.go b/cli/beacon/internal/endpoint/hooks/codex_test.goindex 0fa910bc..c3fdae53 100644--- a/cli/beacon/internal/endpoint/hooks/codex_test.go+++ b/cli/beacon/internal/endpoint/hooks/codex_test.go@@ -7,7 +7,7 @@ import ("testing")-func TestInstallCodexHooksUsesInventoryAndUsageSync(t *testing.T) {+func TestInstallCodexHooksUsesInventoryHeartbeatOnly(t *testing.T) {path := filepath.Join(t.TempDir(), "hooks.json")existing := `{"hooks":{"SessionStart":[{"hooks":[{"type":"command","command":"echo keep"}]}]}}`if err := os.WriteFile(path, []byte(existing), 0600); err != nil {@@ -27,11 +27,8 @@ func TestInstallCodexHooksUsesInventoryAndUsageSync(t *testing.T) {"echo keep","SessionStart","UserPromptSubmit",- "Stop",- "SessionEnd","--platform codex","inventory-heartbeat",- "codex-usage-sync","BEACON_ENDPOINT_LOG='/tmp/runtime.jsonl'","BEACON_ENDPOINT_CONFIG='/tmp/config.json'",} {@@ -39,9 +36,9 @@ func TestInstallCodexHooksUsesInventoryAndUsageSync(t *testing.T) {t.Fatalf("Codex hooks missing %q:\n%s", want, text)}}- for _, forbidden := range []string{"session-start", "prompt-submit", " stop", " session-end"} {+ for _, forbidden := range []string{"session-start", "prompt-submit"} {if strings.Contains(text, forbidden) {- t.Fatalf("Codex hooks should not emit runtime lifecycle events %q:\n%s", forbidden, text)+ t.Fatalf("Codex inventory hooks should not emit runtime hook events %q:\n%s", forbidden, text)}}}diff --git a/cli/beacon/internal/tokens/report.go b/cli/beacon/internal/tokens/report.goindex 5857a3d3..ae2fc349 100644--- a/cli/beacon/internal/tokens/report.go+++ b/cli/beacon/internal/tokens/report.go@@ -10,9 +10,6 @@ import (// RenderText writes a human-readable token usage report.func RenderText(w io.Writer, report Report) {fmt.Fprintf(w, "Token usage report (%d of %d events carry usage)\n\n", report.EventsWithUsage, report.TotalEvents)- if report.Source != nil && report.Source.Codex != "" {- fmt.Fprintf(w, "Codex source: %s\n\n", report.Source.Codex)- }tw := tabwriter.NewWriter(w, 2, 4, 2, ' ', 0)fmt.Fprintln(tw, "TOTALS\tINPUT\tOUTPUT\tCACHE READ\tCACHE CREATE\tREASONING\tCOST USD\tEVENTS")writeUsageRow(tw, "", report.Totals)diff --git a/cli/beacon/internal/tokens/tokens.go b/cli/beacon/internal/tokens/tokens.goindex d6d1560c..73ed81f8 100644--- a/cli/beacon/internal/tokens/tokens.go+++ b/cli/beacon/internal/tokens/tokens.go@@ -14,13 +14,6 @@ import (const defaultNearLimitRatio = 0.8-const (- CodexSourceAuto = "auto"- CodexSourceRuntime = "runtime"- CodexSourceOTLP = "otlp"- CodexSourceBothDebug = "both-debug"-)-// Usage sums the canonical gen_ai.usage fields across events. Field names// match the event schema so report consumers see one vocabulary.type Usage struct {@@ -102,17 +95,6 @@ type Options struct {SessionID string// TopLimit caps each group list (0 keeps all groups).TopLimit int- // CodexSource selects which Codex usage source contributes to totals:- // auto (default), runtime, otlp, or both-debug.- CodexSource string-}--type SourceSummary struct {- Codex string `json:"codex,omitempty"`- CodexSessionEvents int `json:"codex_session_events,omitempty"`- CodexOTLPEvents int `json:"codex_otlp_events,omitempty"`- CodexOTLPSuppressed int `json:"codex_otlp_suppressed,omitempty"`- Diagnostic bool `json:"diagnostic,omitempty"`}type Report struct {@@ -127,7 +109,6 @@ type Report struct {SessionDetail *SessionDetail `json:"session_detail,omitempty"`EventsWithUsage int `json:"events_with_usage"`TotalEvents int `json:"total_events"`- Source *SourceSummary `json:"source,omitempty"`}// usageEvent is one usage-bearing event with its usage normalized to a delta@@ -150,8 +131,6 @@ type usageEvent struct {metricName stringseriesField stringseriesValue float64- rawSource string- rawDedupKey string}// Aggregate builds a token usage report from endpoint events. Events from@@ -171,8 +150,6 @@ func Aggregate(events []schema.Event, opts Options) Report {}report := Report{TotalEvents: len(events)}usageEvents := collectUsageEvents(events)- usageEvents = dedupeCodexSessionUsage(usageEvents)- usageEvents, report.Source = selectCodexUsageSource(usageEvents, opts.CodexSource)usageEvents = dedupeOverlappingChannels(usageEvents)resolveCumulativeSeries(usageEvents)@@ -298,116 +275,12 @@ func collectUsageEvents(events []schema.Event) []*usageEvent {ue.cumulative = true}ue.metricName, _ = event.Raw["metric_name"].(string)- ue.rawSource, _ = event.Raw["source"].(string)- ue.rawDedupKey, _ = event.Raw["dedup_key"].(string)}out = append(out, ue)}return out}-func dedupeCodexSessionUsage(events []*usageEvent) []*usageEvent {- seen := map[string]bool{}- out := events[:0]- for _, event := range events {- if isCodexSessionUsage(event) && event.rawDedupKey != "" {- if seen[event.rawDedupKey] {- continue- }- seen[event.rawDedupKey] = true- }- out = append(out, event)- }- return out-}--func selectCodexUsageSource(events []*usageEvent, source string) ([]*usageEvent, *SourceSummary) {- source = strings.ToLower(strings.TrimSpace(source))- if source == "" {- source = CodexSourceAuto- }- switch source {- case CodexSourceAuto, CodexSourceRuntime, CodexSourceOTLP, CodexSourceBothDebug:- default:- source = CodexSourceAuto- }- summary := &SourceSummary{}- var hasSession bool- for _, event := range events {- if isCodexSessionUsage(event) {- hasSession = true- summary.CodexSessionEvents++- } else if isCodexOTLPUsage(event) {- summary.CodexOTLPEvents++- }- }- if summary.CodexSessionEvents == 0 && summary.CodexOTLPEvents == 0 {- return events, nil- }- if source == CodexSourceAuto {- if hasSession {- out := events[:0]- for _, event := range events {- if isCodexOTLPUsage(event) {- summary.CodexOTLPSuppressed++- continue- }- out = append(out, event)- }- if summary.CodexOTLPSuppressed > 0 {- summary.Codex = "session files (OTLP suppressed)"- } else {- summary.Codex = "session files"- }- return out, summary- }- summary.Codex = "otlp metrics"- return events, summary- }- out := events[:0]- for _, event := range events {- switch source {- case CodexSourceRuntime:- if isCodexOTLPUsage(event) {- summary.CodexOTLPSuppressed++- continue- }- case CodexSourceOTLP:- if isCodexSessionUsage(event) {- continue- }- case CodexSourceBothDebug:- summary.Diagnostic = true- }- out = append(out, event)- }- switch source {- case CodexSourceRuntime:- if summary.CodexOTLPSuppressed > 0 {- summary.Codex = "session files (OTLP suppressed)"- } else {- summary.Codex = "session files"- }- case CodexSourceOTLP:- summary.Codex = "otlp metrics"- case CodexSourceBothDebug:- summary.Codex = "session files and OTLP metrics (diagnostic)"- }- return out, summary-}--func isCodexSessionUsage(event *usageEvent) bool {- return isCodexHarness(event.harness) && strings.EqualFold(event.rawSource, "codex_session_jsonl")-}--func isCodexOTLPUsage(event *usageEvent) bool {- return isCodexHarness(event.harness) && strings.EqualFold(event.metricName, "codex.turn.token_usage")-}--func isCodexHarness(harness string) bool {- return strings.EqualFold(harness, "codex_cli") || strings.EqualFold(harness, "codex")-}-// dedupeOverlappingChannels removes double-counted usage when a runtime reports// the same tokens through two OTel channels. Claude Code emits each request's// usage on both a claude_code.api_request log record and thediff --git a/cli/beacon/internal/tokens/tokens_test.go b/cli/beacon/internal/tokens/tokens_test.goindex 4970d339..61ed63af 100644--- a/cli/beacon/internal/tokens/tokens_test.go+++ b/cli/beacon/internal/tokens/tokens_test.go@@ -132,80 +132,6 @@ func TestAggregateDedupesDualChannelUsage(t *testing.T) {}}-func TestAggregatePrefersCodexSessionUsageOverOTLP(t *testing.T) {- sessionEvent := usageEventFixture("2026-06-11T10:00:00Z", "codex_cli", "codex:s1", "gpt-5", func(e *schema.Event) {- e.GenAI.Usage.InputTokens = int64Ptr(40)- e.GenAI.Usage.OutputTokens = int64Ptr(10)- e.GenAI.Usage.CacheRead = &schema.GenAIUsageCacheReadInfo{InputTokens: int64Ptr(60)}- e.Raw = map[string]interface{}{"source": "codex_session_jsonl", "dedup_key": "session-turn-1"}- })- otlpEvent := usageEventFixture("2026-06-11T10:00:00Z", "codex_cli", "", "gpt-5", func(e *schema.Event) {- e.GenAI.Usage.InputTokens = int64Ptr(40)- e.GenAI.Usage.OutputTokens = int64Ptr(10)- e.GenAI.Usage.CacheRead = &schema.GenAIUsageCacheReadInfo{InputTokens: int64Ptr(60)}- e.Raw = map[string]interface{}{"metric_name": "codex.turn.token_usage", "metric_temporality": "Delta"}- })-- report := Aggregate([]schema.Event{sessionEvent, otlpEvent}, Options{})- if report.Totals.InputTokens != 40 || report.Totals.OutputTokens != 10 || report.Totals.CacheReadInputTokens != 60 {- t.Fatalf("auto totals = %#v, want session event only", report.Totals)- }- if report.Source == nil || report.Source.Codex != "session files (OTLP suppressed)" || report.Source.CodexOTLPSuppressed != 1 {- t.Fatalf("source summary = %#v", report.Source)- }- if len(report.BySession) != 1 || report.BySession[0].Key != "codex:s1" {- t.Fatalf("by_session = %#v, want session-derived attribution", report.BySession)- }-- otlpOnly := Aggregate([]schema.Event{sessionEvent, otlpEvent}, Options{CodexSource: CodexSourceOTLP})- if otlpOnly.Totals.InputTokens != 40 || len(otlpOnly.BySession) != 0 {- t.Fatalf("otlp-only report = totals %#v sessions %#v", otlpOnly.Totals, otlpOnly.BySession)- }-- debug := Aggregate([]schema.Event{sessionEvent, otlpEvent}, Options{CodexSource: CodexSourceBothDebug})- if debug.Totals.InputTokens != 80 || debug.Source == nil || !debug.Source.Diagnostic {- t.Fatalf("both-debug report = totals %#v source %#v", debug.Totals, debug.Source)- }-}--func TestAggregateAutoSuppressesCodexOTLPWhenSessionUsageExists(t *testing.T) {- sessionEvent := usageEventFixture("2026-06-11T10:00:00Z", "codex_cli", "codex:s1", "gpt-5", func(e *schema.Event) {- e.GenAI.Usage.InputTokens = int64Ptr(40)- e.GenAI.Usage.OutputTokens = int64Ptr(10)- e.Raw = map[string]interface{}{"source": "codex_session_jsonl", "dedup_key": "session-turn-1"}- })- otlpOnlyEvent := usageEventFixture("2026-06-11T10:01:00Z", "codex_cli", "", "gpt-5", func(e *schema.Event) {- e.GenAI.Usage.InputTokens = int64Ptr(9)- e.GenAI.Usage.OutputTokens = int64Ptr(3)- e.Raw = map[string]interface{}{"metric_name": "codex.turn.token_usage", "metric_temporality": "Delta"}- })-- report := Aggregate([]schema.Event{sessionEvent, otlpOnlyEvent}, Options{})- if report.Totals.InputTokens != 40 || report.Totals.OutputTokens != 10 || report.Totals.Events != 1 {- t.Fatalf("auto totals = %#v, want session event only", report.Totals)- }- if report.Source == nil || report.Source.Codex != "session files (OTLP suppressed)" || report.Source.CodexOTLPSuppressed != 1 {- t.Fatalf("source summary = %#v", report.Source)- }-}--func TestAggregateDedupesCodexSessionUsageByRawDedupKey(t *testing.T) {- event := usageEventFixture("2026-06-11T10:00:00Z", "codex_cli", "codex:s1", "gpt-5", func(e *schema.Event) {- e.GenAI.Usage.InputTokens = int64Ptr(40)- e.GenAI.Usage.OutputTokens = int64Ptr(10)- e.Raw = map[string]interface{}{"source": "codex_session_jsonl", "dedup_key": "same-turn"}- })- duplicate := event-- report := Aggregate([]schema.Event{event, duplicate}, Options{})- if report.Totals.InputTokens != 40 || report.Totals.OutputTokens != 10 || report.Totals.Events != 1 {- t.Fatalf("duplicate session totals = %#v, want one contribution", report.Totals)- }- if report.TotalEvents != 2 || report.EventsWithUsage != 1 {- t.Fatalf("event counts = %d/%d, want 1 usage event from 2 log events", report.EventsWithUsage, report.TotalEvents)- }-}-func TestAggregateDedupesCumulativeSeries(t *testing.T) {cumulative := func(ts string, value int64) schema.Event {return usageEventFixture(ts, "claude_code", "s1", "claude-sonnet-4-5", func(e *schema.Event) {diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdxindex e5a97529..8cbfe465 100644--- a/docs/changelog/cli.mdx+++ b/docs/changelog/cli.mdx@@ -14,7 +14,6 @@ Stay up to date with the latest changes to the Agent Beacon CLI.### v0.0.91 · June 29, 2026- **Nested MCP inventory detection** · Agent inventory now discovers MCP server definitions nested inside Claude Code project records such as `~/.claude.json` `projects.*.mcpServers`, plus nested MCP blocks using the `mcpServers`, `mcp_servers`, or `mcp` naming patterns in supported harness config files.-- **Codex session token attribution** · Codex hooks now reconcile local Codex session JSONL into token-only `gen_ai.usage` events in the runtime log, giving `beacon token-usage`, the dashboard, and S3 forwarding session-level Codex token attribution while keeping Codex cost out of scope.- **Hook refresh after package updates** · macOS package postinstall now refreshes Beacon-managed user hook payloads for the active console user on a best-effort basis, so self-updates replace stale copied `beacon-hooks` binaries without overwriting non-Beacon hook commands.- **Jamf inventory remediation guidance** · Jamf deployment docs now include optional endpoint self-update enablement commands and MDM-owned inventory log/state permission remediation steps for environments where user-level runtime hooks cannot write system-mode inventory files.diff --git a/docs/cli/endpoint-install.mdx b/docs/cli/endpoint-install.mdxindex 130a0659..8a7fb1a7 100644--- a/docs/cli/endpoint-install.mdx+++ b/docs/cli/endpoint-install.mdx@@ -11,7 +11,7 @@ description: "Install or update the local Beacon endpoint collector and runtimebeacon endpoint install```-By default, Beacon configures Claude Code and Codex CLI telemetry for local or customer-controlled runtime JSONL logs. Gemini CLI and VS Code Copilot telemetry are opt-in with the `gemini` and `vscode` harnesses. Claude Code can also use optional hook telemetry for richer lifecycle, subagent, permission, and tool detail; install the endpoint agent first, then add Claude hooks with `beacon endpoint hooks install --harness claude`. Codex runtime telemetry remains OTLP-backed for semantic logs and fallback token metrics, and optional Codex hooks can trigger inventory heartbeats plus session-level token usage reconciliation with `beacon endpoint hooks install --harness codex`. Beacon applies redaction, sanitization, truncation, and event-size limits before writing supported content fields. GitHub Copilot CLI and Factory Droid OTLP are managed through their launch environments, so Beacon validates their telemetry state but does not mutate shell profiles during install.+By default, Beacon configures Claude Code and Codex CLI telemetry for local or customer-controlled runtime JSONL logs. Gemini CLI and VS Code Copilot telemetry are opt-in with the `gemini` and `vscode` harnesses. Claude Code can also use optional hook telemetry for richer lifecycle, subagent, permission, and tool detail; install the endpoint agent first, then add Claude hooks with `beacon endpoint hooks install --harness claude`. Codex runtime telemetry stays OTLP-based, but optional Codex hooks can trigger inventory heartbeats with `beacon endpoint hooks install --harness codex`. Beacon applies redaction, sanitization, truncation, and event-size limits before writing supported content fields. GitHub Copilot CLI and Factory Droid OTLP are managed through their launch environments, so Beacon validates their telemetry state but does not mutate shell profiles during install.## Flagsdiff --git a/docs/cli/token-usage.mdx b/docs/cli/token-usage.mdxindex 13e60a07..128bdf09 100644--- a/docs/cli/token-usage.mdx+++ b/docs/cli/token-usage.mdx@@ -25,7 +25,7 @@ A few rules shape how the numbers read:- **Counts are kept disjoint.** `input_tokens`, `output_tokens`, `cache_read`, and `cache_creation` do not overlap, so a total is `input + output + cache_read + cache_creation` without double-counting. When a runtime reports prompt tokens inclusive of cache (Codex), Beacon subtracts the cached portion so the disjoint model holds.- **Cost is runtime-reported only.** `cost_usd` reflects what the runtime emits. Beacon never derives cost from local pricing tables, so cost appears only for runtimes that report it.-- **Attribution depends on the metadata a runtime attaches.** Model, harness, repository, and run grouping work whenever those fields are present. For Codex, Beacon derives session-level token events from local Codex session JSONL when hook reconciliation is enabled, because Codex's OTLP token metric does not carry a conversation id.+- **Attribution depends on the metadata a runtime attaches.** Model, harness, repository, and run grouping work whenever those fields are present. Per-session grouping (`--session`, the session step tree) requires a session or conversation id on the usage signal.- **Duplicate channels are de-duplicated.** When a runtime emits the same usage on more than one signal (Claude Code reports it on both logs and metrics), Beacon counts it once.### Per-runtime coverage@@ -33,9 +33,9 @@ A few rules shape how the numbers read:| Runtime | Tokens | Cost | Per-session ||---------|--------|------|-------------|| Claude Code | input, output, cache read, cache creation, reasoning | Reported (`cost_usd`) | Yes |-| Codex CLI | input, output, cache read, reasoning | Not emitted by Codex | Yes, when local Codex session JSONL is available |+| Codex CLI | input, output, cache read, reasoning | Not emitted by Codex | No (metric carries no conversation id) |-`cost_usd` remains empty for Codex because Codex does not emit a cost signal and Beacon does not derive cost locally. See the [Codex CLI](/runtimes/codex-cli#token-usage) and [Claude Code](/runtimes/claude-code) runtime pages for details.+`cost_usd` and `--session` detail are empty for Codex because Codex does not emit a cost signal or a conversation id on its usage metric — not a Beacon limitation. See the [Codex CLI](/runtimes/codex-cli#token-usage-and-cost) and [Claude Code](/runtimes/claude-code) runtime pages for details.## Examples@@ -84,8 +84,6 @@ Filters can be combined to narrow the report to a time range, model, agent harne| `--run-id <id>` | Filter by CI run ID. Bare run IDs and composite provider/run keys are accepted || `--bucket <duration>` | Time-series bucket size, such as `1h` or `15m` || `--top <count>` | Limit each grouping to the top N entries. `0` keeps all entries |-| `--codex-source <auto\|runtime\|otlp\|both-debug>` | Select the Codex token source. `auto` prefers session-derived runtime events and suppresses OTLP duplicates. `both-debug` is diagnostic only |-| `--codex-sync` | Reconcile local Codex session files into the runtime log before reporting |## Runtime Log Selectiondiff --git a/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx b/docs/guides/jamf-anthropic-openai-cursor-mdm.mdxindex a21f9d7b..2294f4ee 100644--- a/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx+++ b/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx@@ -40,7 +40,7 @@ After rollout:- The S3 forwarder runs as `com.beacon.endpoint.s3-forwarder`.- Claude Code hooks write local runtime telemetry.- Cursor hooks write local runtime telemetry.-- Codex CLI sends OTLP logs and fallback token metrics to Beacon's local collector; optional hooks reconcile local Codex session JSONL into session-level token usage events.+- Codex CLI sends OTLP logs and token metrics to Beacon's local collector.- Runtime telemetry is written locally to `/var/log/beacon-agent/runtime.jsonl`.- Inventory telemetry is written locally to `/var/log/beacon-agent/inventory_state.jsonl`.- Vector uploads both JSONL streams to your S3 bucket.@@ -60,7 +60,7 @@ Runtime objects contain agent activity. Inventory objects contain agent configur| --- | --- | --- || Claude Code | S3 helper installs Claude Code hooks for the console user | Prompt, lifecycle, tool, permission, command, file, and inventory telemetry where Claude Code exposes it || Cursor | Separate user hook policy installs Cursor hooks | Prompt, tool, shell command, MCP-like, approval, file edit, and inventory telemetry where Cursor exposes it |-| Codex CLI | Separate user config policy writes `~/.codex/config.toml`; optional hook policy writes `~/.codex/hooks.json` | Codex semantic logs through local OTLP plus session-level token usage from local Codex session JSONL |+| Codex CLI | Separate user config policy writes `~/.codex/config.toml` | Codex semantic logs and token usage metrics emitted through local OTLP || Claude Cowork, cloud agents, CI, SDK apps | Out of scope for this Mac MDM runbook | Configure those from their runtime-specific pages |## Prerequisites@@ -322,7 +322,7 @@ endpoint = "http://127.0.0.1:4317"endpoint = "http://127.0.0.1:4317"```-Preserve existing non-OTel Codex settings and ensure the final file is owned by the user. This step is required for Codex runtime telemetry. Optional Codex hooks can be installed separately when you want Codex sessions to trigger inventory heartbeats and session-level token usage reconciliation.+Preserve existing non-OTel Codex settings and ensure the final file is owned by the user. This step is required for Codex runtime telemetry. Optional Codex hooks can be installed separately when you want Codex sessions to trigger inventory heartbeats.## Validate A Deployed Mac@@ -540,7 +540,7 @@ command -v codexgrep -n 'otel\|otlp-grpc\|127.0.0.1:4317' ~/.codex/config.toml```-Codex semantic runtime telemetry is OTLP-based. Re-run the Codex config policy for the logged-in user if the OTel block is missing. If session-level token usage is missing, also confirm the optional Codex hook policy installed Beacon-managed stop/session-end usage reconciliation hooks.+Codex runtime telemetry is OTLP-based. Re-run the Codex config policy for the logged-in user if the OTel block is missing.### Inventory Is Emptydiff --git a/docs/runtimes/codex-cli.mdx b/docs/runtimes/codex-cli.mdxindex b80d3cf5..fb834117 100644--- a/docs/runtimes/codex-cli.mdx+++ b/docs/runtimes/codex-cli.mdx@@ -18,24 +18,18 @@ Before enabling Codex CLI telemetry, make sure:## Collection path-Codex CLI exports local OpenTelemetry logs and metrics to Asymptote's localhost collector. Asymptote uses Codex semantic logs for session, prompt, approval, and tool-result events, and keeps the `codex.turn.token_usage` metric as a fallback and diagnostics signal. Other high-volume Codex metrics, and Codex spans, are suppressed by default. Codex hooks refresh `inventory_state.jsonl` and reconcile local session JSONL into session-attributed token usage events in the runtime log.+Codex CLI exports local OpenTelemetry logs and metrics to Asymptote's localhost collector. Asymptote uses Codex semantic logs for session, prompt, approval, and tool-result events, and keeps the `codex.turn.token_usage` metric for token attribution. Other high-volume Codex metrics, and Codex spans, are suppressed by default. Optional Codex hooks are heartbeat-only and refresh `inventory_state.jsonl`; they do not write duplicate runtime prompt or session events.Use `--include-codex-spans` during install or repair only when you need raw Codex spans for troubleshooting.-### Token usage+### Token usage and cost-`beacon endpoint install` configures both the Codex log exporter and the Codex metrics exporter in `~/.codex/config.toml`, so Codex's per-turn `codex.turn.token_usage` metric reaches the collector. Beacon also installs Codex usage reconciliation hooks. On Codex stop/session-end, Beacon parses local Codex session JSONL, derives session-attributed token events, and writes them to the normal endpoint runtime log.+`beacon endpoint install` configures both the Codex log exporter and the Codex metrics exporter in `~/.codex/config.toml`, so Codex's per-turn `codex.turn.token_usage` metric reaches the collector. Beacon normalizes it into the canonical `gen_ai.usage` fields (`input_tokens`, `output_tokens`, `cache_read.input_tokens`, `reasoning.output_tokens`). Codex reports prompt tokens inclusive of the cached portion, so Beacon subtracts cached input to keep `input_tokens` and `cache_read` disjoint and avoid double-counting in totals.-The derived events use Beacon's canonical `gen_ai.usage` schema and flow through the same local JSONL and S3 forwarding path as other endpoint events. Codex reports prompt tokens inclusive of the cached portion, so Beacon subtracts cached input to keep `input_tokens` and `cache_read.input_tokens` disjoint:+Two attribution limits are specific to Codex and follow from what Codex emits, not from Beacon:-- Codex `input_tokens - cached_input_tokens` becomes `gen_ai.usage.input_tokens`.-- Codex `cached_input_tokens` becomes `gen_ai.usage.cache_read.input_tokens`.-- Codex `output_tokens` becomes `gen_ai.usage.output_tokens`.-- Codex `reasoning_output_tokens` becomes `gen_ai.usage.reasoning.output_tokens` when present.--Codex does not emit a cost signal, so `gen_ai.usage.cost_usd` is empty for Codex turns. Beacon does not derive Codex cost locally in the endpoint agent.--When both local session-derived events and OTLP Codex token metrics are present, `beacon token-usage` defaults to `--codex-source auto`: it prefers session-derived events and suppresses OTLP duplicates. Use `--codex-source otlp` for OTLP-only diagnostics, or `--codex-source both-debug` to compare both non-authoritatively.+- **No cost.** Codex does not emit a cost signal, so `gen_ai.usage.cost_usd` is empty for Codex turns. Beacon never derives cost from local pricing tables.+- **No per-session attribution.** Codex's usage metric carries no conversation id, so Codex turns do not roll up by session. Model, harness, repository, and run attribution work normally.See [How token attribution works](/cli/token-usage#how-token-attribution-works) for the cross-runtime model.@@ -72,13 +66,13 @@ Asymptote detects Codex CLI through the `codex` executable and `~/.codex/config.`beacon endpoint install` writes Codex OTLP exporter tables to `~/.codex/config.toml`.-To let Codex sessions trigger inventory heartbeats and usage reconciliation, install optional Codex hooks after the endpoint is installed:+To let Codex sessions trigger inventory heartbeats, install optional Codex hooks after the endpoint is installed:```bashbeacon endpoint hooks install --harness codex```-The hook installer writes heartbeat and token-usage reconciliation hooks to `~/.codex/hooks.json` or project `.codex/hooks.json`, depending on `--level`.+The hook installer writes heartbeat-only hooks to `~/.codex/hooks.json` or project `.codex/hooks.json`, depending on `--level`.## Telemetry coverage@@ -86,9 +80,9 @@ The hook installer writes heartbeat and token-usage reconciliation hooks to `~/.|------|---------|| Prompt telemetry | Supported when emitted through Codex semantic logs || Command, tool, and file telemetry | Supported when emitted through Codex semantic logs |-| Token usage | Supported through local session-derived runtime events (input, output, cache read, reasoning), with OTLP metrics retained as fallback/diagnostics |+| Token usage | Supported through the `codex.turn.token_usage` metric (input, output, cache read, reasoning) || Cost attribution | Not available; Codex emits no cost signal |-| Per-session attribution | Supported when local Codex session JSONL is available |+| Per-session attribution | Not available; Codex usage metric carries no conversation id || Local JSONL and dashboard | Supported || MDM deployment | Supported through the system-mode package or MDM-managed config |diff --git a/docs/runtimes/index.mdx b/docs/runtimes/index.mdxindex fc9b7db1..974c3fb1 100644--- a/docs/runtimes/index.mdx+++ b/docs/runtimes/index.mdx@@ -21,7 +21,7 @@ These integrations are grouped by where the agent runs and how telemetry is coll|----------------|-----------------|--------------------|| [Antigravity CLI](/runtimes/antigravity-cli) | Native hooks | Prompt, pre-tool, post-tool, stop, invocation, command, and file telemetry where Antigravity exposes hook payloads || [Claude Code](/runtimes/claude-code) | Local OTLP export plus optional hooks | Prompt, command, tool, file, lifecycle, subagent, and permission telemetry where emitted through OTLP or hooks |-| [Codex CLI](/runtimes/codex-cli) | Local OTLP logs plus usage reconciliation hooks | Session, prompt, approval, and tool-result activity from Codex semantic logs; session-level token usage from local Codex session JSONL |+| [Codex CLI](/runtimes/codex-cli) | Local OTLP logs plus optional inventory hooks | Session, prompt, approval, and tool-result activity from Codex semantic logs; inventory heartbeat triggers from hooks || [Cursor](/runtimes/cursor) | Native hooks | Prompt, tool, shell command, MCP-like, approval, and file edit telemetry || [Devin CLI](/runtimes/devin) | Native hooks | Session, prompt, pre-tool, post-tool, permission request, stop, session-end, approval, and file telemetry || [Devin Desktop](/runtimes/devin-desktop) | Cascade/Windsurf hooks | Prompt, command, MCP tool, file read, and file write telemetry where Desktop exposes Cascade hook payloads |diff --git a/docs/runtimes/integration-model.mdx b/docs/runtimes/integration-model.mdxindex c7ed6f6c..7a1071d4 100644--- a/docs/runtimes/integration-model.mdx+++ b/docs/runtimes/integration-model.mdx@@ -34,7 +34,7 @@ During install, Beacon configures the runtime surfaces it can safely manage:| Runtime or surface | Install-time behavior ||--------------------|-----------------------|| [Claude Code](/runtimes/claude-code) | Beacon points Claude Code at the local OTLP collector. Hook installation is separate through [`beacon endpoint hooks`](/cli/hooks). |-| [Codex CLI](/runtimes/codex-cli) | Beacon points Codex CLI at the local OTLP collector, writes structured OTLP exporter tables to `~/.codex/config.toml`, sets `log_user_prompt = false`, and can install hooks that reconcile local Codex session JSONL into session-level token usage events. |+| [Codex CLI](/runtimes/codex-cli) | Beacon points Codex CLI at the local OTLP collector, writes structured OTLP exporter tables to `~/.codex/config.toml`, sets `log_user_prompt = false`, and sends logs, traces, and metrics to the local collector. || [Gemini CLI](/runtimes/gemini-cli) | Optional with `--harness gemini`. Beacon writes local OTLP settings to `~/.gemini/settings.json`, sets `target` to `local`, uses OTLP gRPC, enables the collector, and removes `outfile` so telemetry flows to Beacon. || [VS Code](/runtimes/vscode) | Optional with `--harness vscode`. Beacon writes Copilot Chat OTel settings to VS Code user settings and points OTLP/HTTP to the local collector. || [GitHub Copilot CLI](/runtimes/github-copilot-cli) | Copilot's OTLP HTTP endpoint remains under MDM or customer-owned launch-environment policy. Beacon validates `COPILOT_OTEL_ENABLED=true` and a localhost OTLP endpoint but does not write Copilot configuration. |@@ -47,7 +47,7 @@ During install, Beacon configures the runtime surfaces it can safely manage:| Runtime | Collection path | Notes ||---------|-----------------|-------|| [Claude Code](/runtimes/claude-code) | Local OTLP export plus optional hooks | Uses Claude settings to enable telemetry and point OTLP to localhost; optional hooks add lifecycle, subagent, permission, and tool event detail. |-| [Codex CLI](/runtimes/codex-cli) | Local OTLP logs, traces, metrics, and usage reconciliation hooks | Beacon writes structured Codex OTLP config, filters noisy internal transport spans, and can derive session-level token events from local Codex session JSONL. |+| [Codex CLI](/runtimes/codex-cli) | Local OTLP logs, traces, and metrics | Beacon writes structured Codex OTLP config and filters noisy internal transport spans. || [Gemini CLI](/runtimes/gemini-cli) | Opt-in local OTLP logs, traces, and metrics | Beacon writes Gemini telemetry settings and maps Gemini prompts, tool calls, MCP activity, file operations, and approval events into endpoint events. || [GitHub Copilot CLI](/runtimes/github-copilot-cli) | MDM-managed OTLP HTTP export | Beacon validates Copilot's effective launch environment and maps Copilot spans into prompt, session, tool, and approval-like endpoint events. || [VS Code](/runtimes/vscode) | Copilot Chat OTel plus optional preview hooks | Beacon writes VS Code Copilot OTel settings and maps Copilot prompts, sessions, model metadata, and tool activity into endpoint events. Hooks are optional for extra lifecycle and cross-agent detail. |diff --git a/docs/security/data-inventory.mdx b/docs/security/data-inventory.mdxindex 328e25fa..6bda77b7 100644--- a/docs/security/data-inventory.mdx+++ b/docs/security/data-inventory.mdx@@ -12,7 +12,7 @@ Beacon writes normalized endpoint events only when supported runtimes provide te| Agent harness | Collection path | Commonly available telemetry ||---------------|-----------------|------------------------------|| Claude Code | Local OTLP export | Prompt, command, tool, and file telemetry when emitted through OTLP |-| Codex CLI | Local OTLP logs plus usage reconciliation hooks | Session, prompt, approval, and tool-result activity from Codex semantic logs; session-level token usage from local Codex session JSONL |+| Codex CLI | Local OTLP logs plus optional inventory hooks | Session, prompt, approval, and tool-result activity from Codex semantic logs; inventory heartbeat triggers from hooks || Gemini CLI | Opt-in local OTLP | Prompts, tool calls, MCP activity, file operations, and approval-related events emitted through OTLP || Grok Build | Native hooks | Session, prompt, pre-tool, post-tool, failed tool, stop, session-end, command, and file telemetry || OpenCode | Managed plugin hooks | Chat messages, session events, command execution, permission activity, diffs, and errors |diff --git a/docs/telemetry-schema/normalization.mdx b/docs/telemetry-schema/normalization.mdxindex 2f4094bb..41540eeb 100644--- a/docs/telemetry-schema/normalization.mdx+++ b/docs/telemetry-schema/normalization.mdx@@ -85,7 +85,7 @@ Beacon preserves OpenTelemetry GenAI semantic convention fields under the nested| `gen_ai.usage.reasoning.output_tokens` | `gen_ai.usage.reasoning.output_tokens` || `gen_ai.usage.cost`, runtime `*.cost.usage` metric datapoints | `gen_ai.usage.cost_usd` |-Usage also arrives as metric datapoints, not just span and log attributes. Claude Code's `claude_code.token.usage` and `claude_code.cost.usage` and Codex's `codex.turn.token_usage` are expanded per datapoint and mapped into the same `gen_ai.usage` fields by their `token_type` (for example Codex `cached_input` maps to `cache_read.input_tokens` and `reasoning_output` to `reasoning.output_tokens`; rollup types such as `total` are ignored). Beacon can also derive Codex session-level token usage from local Codex session JSONL; those events use the same `gen_ai.usage` token fields and mark `raw.source` as `codex_session_jsonl` with a stable `raw.dedup_key`. `gen_ai.usage.cost_usd` carries runtime-reported cost only and is never derived from a local pricing table. See [How token attribution works](/cli/token-usage#how-token-attribution-works) for how these normalized fields aggregate into local reports.+Usage also arrives as metric datapoints, not just span and log attributes. Claude Code's `claude_code.token.usage` and `claude_code.cost.usage` and Codex's `codex.turn.token_usage` are expanded per datapoint and mapped into the same `gen_ai.usage` fields by their `token_type` (for example Codex `cached_input` maps to `cache_read.input_tokens` and `reasoning_output` to `reasoning.output_tokens`; rollup types such as `total` are ignored). `gen_ai.usage.cost_usd` carries runtime-reported cost only and is never derived from a local pricing table. See [How token attribution works](/cli/token-usage#how-token-attribution-works) for how these normalized fields aggregate into local reports.## Prompt and content handlingdiff --git a/pkg/asymptoteobserve/codexusage/codexusage.go b/pkg/asymptoteobserve/codexusage/codexusage.godeleted file mode 100644index 56fd2417..00000000--- a/pkg/asymptoteobserve/codexusage/codexusage.go+++ /dev/null@@ -1,549 +0,0 @@-package codexusage--import (- "bufio"- "crypto/sha256"- "encoding/hex"- "encoding/json"- "fmt"- "io/fs"- "os"- "path/filepath"- "sort"- "strings"- "time"-)--const (- SourceCodexSessionJSONL = "codex_session_jsonl"- defaultMaxLineBytes = 64 * 1024 * 1024-)--type UsageEvent struct {- SessionID string- WorkingDir string- Model string- TurnID string- Timestamp time.Time- InputTokens int64- OutputTokens int64- CacheReadTokens int64- ReasoningTokens int64- SourcePath string- DedupKey string-}--type ParseOptions struct {- MaxLineBytes int-}--type ReconcileOptions struct {- Roots []string- StatePath string- ModifiedSince time.Time-}--type ReconcileResult struct {- Events []UsageEvent- Scanned int-}--type WriteFunc func(UsageEvent) error--type rawLine struct {- Type string `json:"type"`- Timestamp string `json:"timestamp"`- Payload json.RawMessage `json:"payload"`-}--type sessionMetaPayload struct {- ID string `json:"id"`- CWD string `json:"cwd"`- ForkedFromID string `json:"forked_from_id"`- Timestamp string `json:"timestamp"`-}--type turnContextPayload struct {- Model string `json:"model"`- TurnID string `json:"turn_id"`-}--type eventMsgPayload struct {- Type string `json:"type"`- Info struct {- LastTokenUsage json.RawMessage `json:"last_token_usage"`- } `json:"info"`-}--type tokenUsagePayload struct {- InputTokens int64 `json:"input_tokens"`- OutputTokens int64 `json:"output_tokens"`- CachedInputTokens int64 `json:"cached_input_tokens"`- ReasoningTokens int64 `json:"reasoning_output_tokens"`-}--type forkGate struct {- active bool- createdMs int64-}--func (g *forkGate) arm(meta sessionMetaPayload, envelope time.Time) {- if meta.ForkedFromID == "" {- return- }- ms := uuidV7Millis(meta.ID)- if ms == 0 {- if ts := parseOptionalTimestamp(meta.Timestamp); !ts.IsZero() {- ms = ts.UnixMilli()- }- }- if ms == 0 && !envelope.IsZero() {- ms = envelope.UnixMilli()- }- if ms == 0 {- return- }- g.active = true- g.createdMs = ms-}--func (g *forkGate) suppresses(lineType string, turnID string) bool {- if !g.active {- return false- }- if lineType != "turn_context" {- return true- }- if turnID == "" {- g.active = false- return true- }- if ms := uuidV7Millis(turnID); ms != 0 && ms < g.createdMs {- return true- }- g.active = false- return false-}--func ParseFile(path string, opts ParseOptions) ([]UsageEvent, error) {- maxLineBytes := opts.MaxLineBytes- if maxLineBytes <= 0 {- maxLineBytes = defaultMaxLineBytes- }- f, err := os.Open(path)- if err != nil {- return nil, err- }- defer f.Close()-- scanner := bufio.NewScanner(f)- scanner.Buffer(make([]byte, 0, 64*1024), maxLineBytes)- var (- events []UsageEvent- sessionID string- cwd string- model string- turnID string- lastUsageRaw string- pending *UsageEvent- gate forkGate- )- flushPending := func() {- if pending == nil {- return- }- events = append(events, *pending)- pending = nil- }- for scanner.Scan() {- line := strings.TrimSpace(scanner.Text())- if line == "" {- continue- }- var raw rawLine- if err := json.Unmarshal([]byte(line), &raw); err != nil {- continue- }- ts := parseTimestamp(raw.Timestamp)- switch raw.Type {- case "session_meta":- flushPending()- if gate.active {- continue- }- var meta sessionMetaPayload- if err := json.Unmarshal(raw.Payload, &meta); err != nil {- continue- }- if meta.ID != "" {- sessionID = meta.ID- }- if meta.CWD != "" {- cwd = meta.CWD- }- gate.arm(meta, ts)- case "turn_context":- flushPending()- var payload turnContextPayload- if err := json.Unmarshal(raw.Payload, &payload); err != nil {- continue- }- if gate.suppresses(raw.Type, payload.TurnID) {- continue- }- model = strings.TrimSpace(payload.Model)- turnID = strings.TrimSpace(payload.TurnID)- lastUsageRaw = ""- case "response_item":- if gate.suppresses(raw.Type, "") {- continue- }- case "event_msg":- if gate.suppresses(raw.Type, "") {- continue- }- var payload eventMsgPayload- if err := json.Unmarshal(raw.Payload, &payload); err != nil {- continue- }- if payload.Type != "token_count" || len(payload.Info.LastTokenUsage) == 0 {- continue- }- usageRaw := compactJSON(payload.Info.LastTokenUsage)- if usageRaw == "" || usageRaw == lastUsageRaw {- continue- }- lastUsageRaw = usageRaw- var usage tokenUsagePayload- if err := json.Unmarshal(payload.Info.LastTokenUsage, &usage); err != nil {- continue- }- input := usage.InputTokens - usage.CachedInputTokens- if input < 0 {- input = 0- }- if input == 0 && usage.OutputTokens == 0 && usage.CachedInputTokens == 0 && usage.ReasoningTokens == 0 {- continue- }- if sessionID == "" {- sessionID = strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))- }- event := UsageEvent{- SessionID: sessionID,- WorkingDir: cwd,- Model: model,- TurnID: turnID,- Timestamp: ts,- InputTokens: input,- OutputTokens: usage.OutputTokens,- CacheReadTokens: usage.CachedInputTokens,- ReasoningTokens: usage.ReasoningTokens,- SourcePath: path,- }- event.DedupKey = DedupKey(event, usageRaw)- pending = &event- }- }- if err := scanner.Err(); err != nil {- return nil, err- }- flushPending()- return events, nil-}--func Reconcile(opts ReconcileOptions) (ReconcileResult, error) {- files, err := DiscoverFiles(opts.Roots)- if err != nil {- return ReconcileResult{}, err- }- seen, err := LoadState(opts.StatePath)- if err != nil {- return ReconcileResult{}, err- }- result := ReconcileResult{Scanned: len(files)}- for _, path := range files {- if !opts.ModifiedSince.IsZero() {- info, err := os.Stat(path)- if err != nil || info.ModTime().Before(opts.ModifiedSince) {- continue- }- }- events, err := ParseFile(path, ParseOptions{})- if err != nil {- continue- }- for _, event := range events {- if event.DedupKey == "" || seen[event.DedupKey] {- continue- }- seen[event.DedupKey] = true- result.Events = append(result.Events, event)- }- }- return result, nil-}--func ReconcileAndWrite(opts ReconcileOptions, write WriteFunc) (ReconcileResult, error) {- if write == nil {- return ReconcileResult{}, fmt.Errorf("nil Codex usage writer")- }- statePath := resolveStatePath(opts.StatePath)- unlock, err := lockState(statePath)- if err != nil {- return ReconcileResult{}, err- }- defer unlock()-- files, err := DiscoverFiles(opts.Roots)- if err != nil {- return ReconcileResult{}, err- }- seen, err := loadStateFile(statePath)- if err != nil {- return ReconcileResult{}, err- }- result := ReconcileResult{Scanned: len(files)}- for _, path := range files {- if !opts.ModifiedSince.IsZero() {- info, err := os.Stat(path)- if err != nil || info.ModTime().Before(opts.ModifiedSince) {- continue- }- }- events, err := ParseFile(path, ParseOptions{})- if err != nil {- continue- }- for _, event := range events {- if event.DedupKey == "" || seen[event.DedupKey] {- continue- }- if err := write(event); err != nil {- return result, err- }- seen[event.DedupKey] = true- if err := saveStateFile(statePath, seen); err != nil {- return result, err- }- result.Events = append(result.Events, event)- }- }- return result, nil-}--func MarkEventsSeen(events []UsageEvent, statePath string) error {- if len(events) == 0 {- return nil- }- seen, err := LoadState(statePath)- if err != nil {- return err- }- for _, event := range events {- if event.DedupKey != "" {- seen[event.DedupKey] = true- }- }- return SaveState(statePath, seen)-}--func MarkEventSeen(event UsageEvent, statePath string) error {- if event.DedupKey == "" {- return nil- }- return MarkEventsSeen([]UsageEvent{event}, statePath)-}--func DiscoverFiles(roots []string) ([]string, error) {- if len(roots) == 0 {- defaults, err := DefaultRoots()- if err != nil {- return nil, err- }- roots = defaults- }- seen := map[string]bool{}- var out []string- for _, root := range roots {- root = strings.TrimSpace(root)- if root == "" {- continue- }- if err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {- if err != nil {- return nil- }- if d.IsDir() {- return nil- }- if strings.EqualFold(filepath.Ext(path), ".jsonl") && !seen[path] {- seen[path] = true- out = append(out, path)- }- return nil- }); err != nil && !os.IsNotExist(err) {- return nil, err- }- }- sort.Strings(out)- return out, nil-}--func DefaultRoots() ([]string, error) {- if override := strings.TrimSpace(os.Getenv("BEACON_CODEX_SESSIONS_DIR")); override != "" {- return splitList(override), nil- }- home, err := os.UserHomeDir()- if err != nil {- return nil, err- }- return []string{- filepath.Join(home, ".codex", "sessions"),- filepath.Join(home, ".codex", "archived_sessions"),- }, nil-}--func DefaultStatePath() string {- if path := strings.TrimSpace(os.Getenv("BEACON_CODEX_USAGE_STATE")); path != "" {- return path- }- home, err := os.UserHomeDir()- if err != nil {- return filepath.Join(".", ".beacon", "endpoint", "state", "codex_usage_seen.json")- }- return filepath.Join(home, ".beacon", "endpoint", "state", "codex_usage_seen.json")-}--func LoadState(path string) (map[string]bool, error) {- return loadStateFile(resolveStatePath(path))-}--func loadStateFile(path string) (map[string]bool, error) {- data, err := os.ReadFile(path)- if err != nil {- if os.IsNotExist(err) {- return map[string]bool{}, nil- }- return nil, err- }- var seen map[string]bool- if err := json.Unmarshal(data, &seen); err != nil {- return nil, err- }- if seen == nil {- seen = map[string]bool{}- }- return seen, nil-}--func SaveState(path string, seen map[string]bool) error {- return saveStateFile(resolveStatePath(path), seen)-}--func saveStateFile(path string, seen map[string]bool) error {- if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {- return err- }- data, err := json.MarshalIndent(seen, "", " ")- if err != nil {- return err- }- return os.WriteFile(path, data, 0600)-}--func resolveStatePath(path string) string {- if strings.TrimSpace(path) != "" {- return path- }- return DefaultStatePath()-}--func SourcePathHash(path string) string {- sum := sha256.Sum256([]byte(filepath.Clean(path)))- return hex.EncodeToString(sum[:])-}--func DedupKey(event UsageEvent, usageRaw string) string {- var b strings.Builder- fmt.Fprintf(&b, "%s|%s|%s|%s|%s|%d|%d|%d|%d|%s",- SourceCodexSessionJSONL,- filepath.Clean(event.SourcePath),- event.SessionID,- event.TurnID,- event.Model,- event.InputTokens,- event.OutputTokens,- event.CacheReadTokens,- event.ReasoningTokens,- usageRaw,- )- sum := sha256.Sum256([]byte(b.String()))- return hex.EncodeToString(sum[:])-}--func parseTimestamp(raw string) time.Time {- if ts := parseOptionalTimestamp(raw); !ts.IsZero() {- return ts- }- return time.Now().UTC()-}--func parseOptionalTimestamp(raw string) time.Time {- raw = strings.TrimSpace(raw)- if raw == "" {- return time.Time{}- }- if ts, err := time.Parse(time.RFC3339Nano, raw); err == nil {- return ts.UTC()- }- if ts, err := time.Parse(time.RFC3339, raw); err == nil {- return ts.UTC()- }- return time.Time{}-}--func compactJSON(raw json.RawMessage) string {- var value interface{}- if err := json.Unmarshal(raw, &value); err != nil {- return ""- }- data, err := json.Marshal(value)- if err != nil {- return ""- }- return string(data)-}--func uuidV7Millis(id string) int64 {- cleaned := strings.ReplaceAll(id, "-", "")- if len(cleaned) != 32 || cleaned[12] != '7' {- return 0- }- var value int64- for _, ch := range cleaned[:12] {- value <<= 4- switch {- case ch >= '0' && ch <= '9':- value += int64(ch - '0')- case ch >= 'a' && ch <= 'f':- value += int64(ch-'a') + 10- case ch >= 'A' && ch <= 'F':- value += int64(ch-'A') + 10- default:- return 0- }- }- return value-}--func splitList(value string) []string {- separator := os.PathListSeparator- fields := strings.FieldsFunc(value, func(r rune) bool { return r == ',' || r == separator })- var out []string- for _, field := range fields {- if trimmed := strings.TrimSpace(field); trimmed != "" {- out = append(out, trimmed)- }- }- return out-}diff --git a/pkg/asymptoteobserve/codexusage/codexusage_test.go b/pkg/asymptoteobserve/codexusage/codexusage_test.godeleted file mode 100644index d1ade730..00000000--- a/pkg/asymptoteobserve/codexusage/codexusage_test.go+++ /dev/null@@ -1,161 +0,0 @@-package codexusage--import (- "os"- "path/filepath"- "strings"- "testing"-)--func TestParseFileNormalizesAndDedupesTokenCount(t *testing.T) {- path := filepath.Join(t.TempDir(), "session.jsonl")- lines := []string{- `{"type":"session_meta","timestamp":"2026-06-29T10:00:00Z","payload":{"id":"codex-session-1","cwd":"/repo"}}`,- `{"type":"turn_context","timestamp":"2026-06-29T10:00:01Z","payload":{"model":"gpt-5","turn_id":"turn-1"}}`,- `{"type":"response_item","timestamp":"2026-06-29T10:00:02Z","payload":{"role":"assistant","content":[{"type":"output_text","text":"hi"}]}}`,- `{"type":"event_msg","timestamp":"2026-06-29T10:00:03Z","payload":{"type":"token_count","info":{"last_token_usage":{"input_tokens":1000,"output_tokens":50,"cached_input_tokens":600,"reasoning_output_tokens":7,"total_tokens":1050}}}}`,- `{"type":"event_msg","timestamp":"2026-06-29T10:00:04Z","payload":{"type":"token_count","info":{"last_token_usage":{"input_tokens":1000,"output_tokens":50,"cached_input_tokens":600,"reasoning_output_tokens":7,"total_tokens":1050}}}}`,- }- if err := os.WriteFile(path, []byte(strings.Join(lines, "\n")+"\n"), 0644); err != nil {- t.Fatal(err)- }-- events, err := ParseFile(path, ParseOptions{})- if err != nil {- t.Fatalf("ParseFile returned error: %v", err)- }- if len(events) != 1 {- t.Fatalf("events = %#v, want 1 unique token event", events)- }- event := events[0]- if event.SessionID != "codex-session-1" || event.WorkingDir != "/repo" || event.Model != "gpt-5" || event.TurnID != "turn-1" {- t.Fatalf("event metadata = %#v", event)- }- if event.InputTokens != 400 || event.CacheReadTokens != 600 || event.OutputTokens != 50 || event.ReasoningTokens != 7 {- t.Fatalf("normalized tokens = input %d cache %d output %d reasoning %d", event.InputTokens, event.CacheReadTokens, event.OutputTokens, event.ReasoningTokens)- }- if event.DedupKey == "" {- t.Fatal("dedup key is empty")- }-}--func TestParseFileKeepsLatestTokenSnapshotPerTurn(t *testing.T) {- path := filepath.Join(t.TempDir(), "session.jsonl")- lines := []string{- `{"type":"session_meta","timestamp":"2026-06-29T10:00:00Z","payload":{"id":"codex-session-1"}}`,- `{"type":"turn_context","timestamp":"2026-06-29T10:00:01Z","payload":{"model":"gpt-5","turn_id":"turn-1"}}`,- `{"type":"event_msg","timestamp":"2026-06-29T10:00:02Z","payload":{"type":"token_count","info":{"last_token_usage":{"input_tokens":100,"output_tokens":5,"cached_input_tokens":40}}}}`,- `{"type":"event_msg","timestamp":"2026-06-29T10:00:03Z","payload":{"type":"token_count","info":{"last_token_usage":{"input_tokens":200,"output_tokens":9,"cached_input_tokens":80}}}}`,- }- if err := os.WriteFile(path, []byte(strings.Join(lines, "\n")+"\n"), 0644); err != nil {- t.Fatal(err)- }-- events, err := ParseFile(path, ParseOptions{})- if err != nil {- t.Fatalf("ParseFile returned error: %v", err)- }- if len(events) != 1 {- t.Fatalf("events = %#v, want latest snapshot only", events)- }- if got := events[0]; got.InputTokens != 120 || got.CacheReadTokens != 80 || got.OutputTokens != 9 {- t.Fatalf("latest snapshot tokens = %#v", got)- }-}--func TestParseFileForkGateDoesNotStickOnEmptyTurnID(t *testing.T) {- path := filepath.Join(t.TempDir(), "fork.jsonl")- lines := []string{- `{"type":"session_meta","timestamp":"2026-06-29T10:00:00Z","payload":{"id":"forked-session","forked_from_id":"parent-session","timestamp":"2026-06-29T10:00:00Z"}}`,- `{"type":"turn_context","timestamp":"2026-06-29T10:00:01Z","payload":{"model":"gpt-5","turn_id":""}}`,- `{"type":"event_msg","timestamp":"2026-06-29T10:00:02Z","payload":{"type":"token_count","info":{"last_token_usage":{"input_tokens":10,"output_tokens":2,"cached_input_tokens":4}}}}`,- }- if err := os.WriteFile(path, []byte(strings.Join(lines, "\n")+"\n"), 0644); err != nil {- t.Fatal(err)- }-- events, err := ParseFile(path, ParseOptions{})- if err != nil {- t.Fatalf("ParseFile returned error: %v", err)- }- if len(events) != 1 {- t.Fatalf("events = %#v, want token usage after empty turn id clears fork gate", events)- }- if events[0].InputTokens != 6 || events[0].CacheReadTokens != 4 || events[0].OutputTokens != 2 {- t.Fatalf("tokens = %#v", events[0])- }-}--func TestReconcileUsesStateForIdempotence(t *testing.T) {- dir := t.TempDir()- path := filepath.Join(dir, "session.jsonl")- statePath := filepath.Join(dir, "state.json")- line := `{"type":"session_meta","timestamp":"2026-06-29T10:00:00Z","payload":{"id":"codex-session-1"}}` + "\n" +- `{"type":"turn_context","timestamp":"2026-06-29T10:00:01Z","payload":{"model":"gpt-5","turn_id":"turn-1"}}` + "\n" +- `{"type":"event_msg","timestamp":"2026-06-29T10:00:03Z","payload":{"type":"token_count","info":{"last_token_usage":{"input_tokens":10,"output_tokens":2,"cached_input_tokens":4}}}}` + "\n"- if err := os.WriteFile(path, []byte(line), 0644); err != nil {- t.Fatal(err)- }-- first, err := Reconcile(ReconcileOptions{Roots: []string{dir}, StatePath: statePath})- if err != nil {- t.Fatalf("first reconcile: %v", err)- }- if len(first.Events) != 1 {- t.Fatalf("first events = %#v, want 1", first.Events)- }- if err := MarkEventsSeen(first.Events, statePath); err != nil {- t.Fatalf("mark seen: %v", err)- }- second, err := Reconcile(ReconcileOptions{Roots: []string{dir}, StatePath: statePath})- if err != nil {- t.Fatalf("second reconcile: %v", err)- }- if len(second.Events) != 0 {- t.Fatalf("second events = %#v, want idempotent empty", second.Events)- }-}--func TestReconcileAndWriteMarksAfterSuccessfulWrite(t *testing.T) {- dir := t.TempDir()- path := filepath.Join(dir, "session.jsonl")- statePath := filepath.Join(dir, "state.json")- line := `{"type":"session_meta","timestamp":"2026-06-29T10:00:00Z","payload":{"id":"codex-session-1"}}` + "\n" +- `{"type":"turn_context","timestamp":"2026-06-29T10:00:01Z","payload":{"model":"gpt-5","turn_id":"turn-1"}}` + "\n" +- `{"type":"event_msg","timestamp":"2026-06-29T10:00:03Z","payload":{"type":"token_count","info":{"last_token_usage":{"input_tokens":10,"output_tokens":2,"cached_input_tokens":4}}}}` + "\n"- if err := os.WriteFile(path, []byte(line), 0644); err != nil {- t.Fatal(err)- }-- var writes int- first, err := ReconcileAndWrite(ReconcileOptions{Roots: []string{dir}, StatePath: statePath}, func(event UsageEvent) error {- writes++- return nil- })- if err != nil {- t.Fatalf("first reconcile write: %v", err)- }- if len(first.Events) != 1 || writes != 1 {- t.Fatalf("first result events=%#v writes=%d, want one write", first.Events, writes)- }- second, err := ReconcileAndWrite(ReconcileOptions{Roots: []string{dir}, StatePath: statePath}, func(event UsageEvent) error {- writes++- return nil- })- if err != nil {- t.Fatalf("second reconcile write: %v", err)- }- if len(second.Events) != 0 || writes != 1 {- t.Fatalf("second result events=%#v writes=%d, want no duplicate write", second.Events, writes)- }-}--func TestLoadStateRejectsCorruptJSON(t *testing.T) {- statePath := filepath.Join(t.TempDir(), "state.json")- if err := os.WriteFile(statePath, []byte("{not json"), 0600); err != nil {- t.Fatal(err)- }- if _, err := LoadState(statePath); err == nil {- t.Fatal("LoadState returned nil error for corrupt JSON")- }-}diff --git a/pkg/asymptoteobserve/codexusage/lock_unix.go b/pkg/asymptoteobserve/codexusage/lock_unix.godeleted file mode 100644index 299ab6d2..00000000--- a/pkg/asymptoteobserve/codexusage/lock_unix.go+++ /dev/null@@ -1,27 +0,0 @@-//go:build !windows--package codexusage--import (- "os"- "path/filepath"- "syscall"-)--func lockState(path string) (func(), error) {- if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {- return nil, err- }- lock, err := os.OpenFile(path+".lock", os.O_CREATE|os.O_RDWR, 0600)- if err != nil {- return nil, err- }- if err := syscall.Flock(int(lock.Fd()), syscall.LOCK_EX); err != nil {- _ = lock.Close()- return nil, err- }- return func() {- _ = syscall.Flock(int(lock.Fd()), syscall.LOCK_UN)- _ = lock.Close()- }, nil-}diff --git a/pkg/asymptoteobserve/codexusage/lock_windows.go b/pkg/asymptoteobserve/codexusage/lock_windows.godeleted file mode 100644index 605fac15..00000000--- a/pkg/asymptoteobserve/codexusage/lock_windows.go+++ /dev/null@@ -1,29 +0,0 @@-//go:build windows--package codexusage--import (- "os"- "path/filepath"- "time"-)--func lockState(path string) (func(), error) {- if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {- return nil, err- }- lockPath := path + ".lock"- var lastErr error- for i := 0; i < 100; i++ {- f, err := os.OpenFile(lockPath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)- if err == nil {- return func() {- _ = f.Close()- _ = os.Remove(lockPath)- }, nil- }- lastErr = err- time.Sleep(50 * time.Millisecond)- }- return nil, lastErr-}