Skip to content

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

Add Copilot CLI session polling

Justin D'Souzadb97c7655c5a
diff --git a/CLAUDE.md b/CLAUDE.md
index 1845728d..f115ecd7 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -52,7 +52,8 @@ Supported runtime surfaces today:
- fx (vercel-labs/fx) telemetry read from the session store fx commits under `~/.fx/sessions/`, covering session start, prompts, tool calls, commands with exit codes and output, file reads/creates/edits with diffs, MCP tool calls, agent messages, history compaction, and per-turn token usage plus reported cost. fx exposes no third-party hook, plugin, or OTLP surface -- its lifecycle hooks are compiled into the binary -- so collection is a read of fx's own records, run by `beacon endpoint fx sync`. Every event carries `harness.collection_method=poll`; approvals are not synthesized (fx persists permission feedback text, not a per-call decision, matching the Cline and Pi posture) and no session-end event is invented, since fx sessions are resumable. Implementation lives in `cli/beacon/internal/fxsession` and `cli/beacon/cmd/endpoint_fx.go`.
- Claude Cowork admin-configured OpenTelemetry setup guidance and local validation.
- OpenClaw Gateway uses a Beacon-managed plugin directory plus OpenClaw's own diagnostics OTLP guidance (`beacon endpoint integrations openclaw`). The plugin's `before_tool_call` hook is fail-closed, so the handler dispatches synchronously and returns without awaiting. Conversation hooks, including `llm_output`, require `plugins.entries.beacon-endpoint.hooks.allowConversationAccess`; without it, token and agent-message coverage is partial. Beacon reads OpenClaw JSON/JSON5 config for advice but does not rewrite it.
-- Runtimes that ride shared hook/OTLP paths without a special contract worth expanding here include Antigravity CLI, Devin CLI, Devin Desktop, Factory Droid, Gemini CLI, GitHub Copilot CLI, Grok Build, Hermes Agent, Qwen Code, and VS Code. Installed hook/endpoint support is governed by `cli/beacon/cmd/endpoint_targets.go` plus the install/status switches in `cli/beacon/cmd/endpoint_hooks.go`; discovery rows live in `cli/beacon/internal/endpoint/harness`.
+- GitHub Copilot CLI uses MDM/customer-managed OTLP HTTP for live spans and approval-like activity, plus `beacon endpoint copilot sync` to backfill local session records from `~/.copilot/session-state`. Poll events carry assistant text, complete tool results, command/file details, and token usage with `harness.collection_method=poll`; approvals still come only from the live OTLP path and are not synthesized from persisted records.
+- Runtimes that ride shared hook/OTLP paths without a special contract worth expanding here include Antigravity CLI, Devin CLI, Devin Desktop, Factory Droid, Gemini CLI, Grok Build, Hermes Agent, Qwen Code, and VS Code. Installed hook/endpoint support is governed by `cli/beacon/cmd/endpoint_targets.go` plus the install/status switches in `cli/beacon/cmd/endpoint_hooks.go`; discovery rows live in `cli/beacon/internal/endpoint/harness`.
- Browser chat telemetry through an optional Chrome MV3 extension (`browser-extension/`) covering claude.ai and chatgpt.com. A main-world interceptor tees the streamed response, a per-site adapter parses it into a normalized turn, and the service worker POSTs OTLP GenAI logs to the local collector on `127.0.0.1:4318`; the extension never writes files and never contacts a remote endpoint. `harness.name` resolves to `claude_web` or `chatgpt_web` (already handled by `NormalizeHarnessName` in `pkg/asymptoteobserve/harness.go`, where the browser cases must stay above the generic `claude` rule) and `harness.collection_method` is `otlp`. Scope is deliberately narrow: only those origins' chat streams, never other tabs or general browsing. Retention defaults to `full`, so prompt and response text is retained by default; this is documented rather than defaulted down, because browser chat telemetry without content has no investigative value. Treat the adapters as experimental, since both sites' stream formats are private and undocumented.
- `beaconjson` OpenTelemetry Collector exporter that converts OTLP logs, traces, metrics, and resource attributes into Beacon endpoint JSONL.
- Endpoint inventory (`inventory.heartbeat` / `inventory.snapshot` in `inventory_state.jsonl`) is written by a scheduled job, `com.beacon.endpoint.inventory` (`service.InventoryManager`, user LaunchAgent or system LaunchDaemon, `beacon-inventory.timer` on systemd), every six hours and once at load, on by default and reconciled by `lifecycle.ReconcileInventoryJob` on every install, repair and package upgrade (`beacon endpoint inventory install-daemon`). Agent hooks do not trigger inventory any more; the hook binary's `--cli` flag and `inventory-heartbeat` subcommand survive only as no-ops for hook commands written by older versions, and `beacon endpoint inventory heartbeat --trigger hook` is likewise retired. A system-mode run inventories the active console user's home and still writes the liveness heartbeat when nobody is logged in; the scheduled scan has no working directory, so project-scoped config is only in `beacon endpoint inventory`.
diff --git a/README.md b/README.md
index 2ea32d94..40535746 100644
--- a/README.md
+++ b/README.md
@@ -245,7 +245,7 @@ Beacon supports local agents, browser agents, cloud agents, CI workflows, and ag
| Factory Droid | OTLP + hooks + poll | ✅ | ✅ | ✅ | – | ✅ | ✅ | – | – |
| fx (Vercel Labs) | Poll | ✅ | ✅ | ✅ | ✅ | ✅ | – | ✅ | ✅ |
| Gemini CLI | OTLP | – | ✅ | ✅ | – | ✅ | ✅ | ✅ | – |
-| GitHub Copilot CLI | OTLP | ✅ | ✅ | ✅ | – | – | ✅ | – | – |
+| GitHub Copilot CLI | OTLP + poll | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | – | ✅ |
| goose | Adapter only; manual hooks/OTLP | ✅ | ✅ | ✅ | ✅ | ✅ | – | ✅ | ✅ |
| Grok Build | Hooks + poll | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | – | – |
| Hermes Agent | Hooks + poll | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | – |
diff --git a/cli/beacon/cmd/endpoint_copilot.go b/cli/beacon/cmd/endpoint_copilot.go
new file mode 100644
index 00000000..d0ff1dfc
--- /dev/null
+++ b/cli/beacon/cmd/endpoint_copilot.go
@@ -0,0 +1,250 @@
+package cmd
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "path/filepath"
+ "strings"
+ "time"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/copilotsession"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/lifecycle"
+ "github.com/spf13/cobra"
+)
+
+var endpointCopilotCmd = &cobra.Command{
+ Use: "copilot",
+ Short: "Collect telemetry from GitHub Copilot CLI sessions",
+ Long: `Collect endpoint telemetry from GitHub Copilot CLI's native session store.
+
+Copilot CLI persists local session records under ~/.copilot/session-state. Beacon
+reads those records after the fact and maps them to endpoint events with
+harness.collection_method=poll. This complements the live OTLP integration:
+OTLP still provides live approvals and spans, while session sync backfills
+assistant text, complete tool results, commands, file activity, and token usage
+that the live path may not expose.`,
+}
+
+var endpointCopilotSyncCmd = &cobra.Command{
+ Use: "sync",
+ Short: "Read new GitHub Copilot CLI session records into the runtime log",
+ SilenceUsage: true,
+ RunE: runEndpointCopilotSync,
+}
+
+var endpointCopilotStatusCmd = &cobra.Command{
+ Use: "status",
+ Short: "Show GitHub Copilot CLI sessions and collection progress",
+ SilenceUsage: true,
+ RunE: runEndpointCopilotStatus,
+}
+
+var endpointCopilotOpts struct {
+ copilotDir string
+ statePath string
+ logPath string
+ print bool
+ watch bool
+ interval time.Duration
+ workspace string
+ sessionID string
+}
+
+func init() {
+ endpointCmd.AddCommand(endpointCopilotCmd)
+ endpointCopilotCmd.AddCommand(endpointCopilotSyncCmd)
+ endpointCopilotCmd.AddCommand(endpointCopilotStatusCmd)
+
+ for _, c := range []*cobra.Command{endpointCopilotSyncCmd, endpointCopilotStatusCmd} {
+ f := c.Flags()
+ f.StringVar(&endpointCopilotOpts.copilotDir, "copilot-dir", "", "GitHub Copilot CLI directory (default ~/.copilot)")
+ f.StringVar(&endpointCopilotOpts.statePath, "state", "", "Collector cursor file (default ~/.beacon/endpoint/state/copilot.json)")
+ f.StringVar(&endpointCopilotOpts.workspace, "workspace", "", "Only include sessions whose cwd matches this workspace")
+ f.StringVar(&endpointCopilotOpts.sessionID, "session-id", "", "Only include one GitHub Copilot CLI session id")
+ f.BoolVar(&endpointOpts.jsonOutput, "json", false, "Print the result as JSON")
+ f.BoolVar(&endpointOpts.userMode, "user", true, "Use per-user endpoint paths")
+ f.BoolVar(&endpointOpts.systemMode, "system", false, "Use system endpoint paths")
+ }
+
+ sync := endpointCopilotSyncCmd.Flags()
+ sync.StringVar(&endpointCopilotOpts.logPath, "log-path", "", "Runtime JSONL log path (default resolved endpoint log)")
+ sync.BoolVar(&endpointCopilotOpts.print, "print", false, "Print mapped events as JSON without writing them or advancing the cursor")
+ sync.BoolVar(&endpointCopilotOpts.watch, "watch", false, "Sweep continuously on --interval")
+ sync.DurationVar(&endpointCopilotOpts.interval, "interval", time.Minute, "Sweep interval for --watch")
+}
+
+func runEndpointCopilotSync(cmd *cobra.Command, args []string) error {
+ userMode := endpointUserMode()
+ opts := copilotsession.CollectOptions{
+ CopilotDir: endpointCopilotOpts.copilotDir,
+ Print: endpointCopilotOpts.print,
+ Out: cmd.OutOrStdout(),
+ Write: !endpointCopilotOpts.print,
+ UserMode: userMode,
+ Workspace: endpointCopilotOpts.workspace,
+ SessionID: endpointCopilotOpts.sessionID,
+ }
+ if !endpointCopilotOpts.print {
+ opts.StatePath = resolveCopilotStatePath(endpointCopilotOpts.statePath, userMode)
+ opts.LogPath = lifecycle.ResolveRuntimeLog(userMode, endpointCopilotOpts.logPath).EffectiveLogPath
+ }
+ ctx := cmd.Context()
+ if ctx == nil {
+ ctx = context.Background()
+ }
+ if endpointCopilotOpts.watch && !endpointCopilotOpts.print {
+ return watchCopilot(ctx, cmd, opts)
+ }
+ summary, err := copilotsession.CollectOnce(opts)
+ reportCopilotSweep(cmd, summary)
+ return err
+}
+
+func watchCopilot(ctx context.Context, cmd *cobra.Command, opts copilotsession.CollectOptions) error {
+ interval := endpointCopilotOpts.interval
+ if interval < 5*time.Second {
+ interval = 5 * time.Second
+ }
+ for {
+ summary, err := copilotsession.CollectOnce(opts)
+ if err != nil {
+ fmt.Fprintf(cmd.ErrOrStderr(), "copilot sync error: %v\n", err)
+ }
+ reportCopilotSweep(cmd, summary)
+ select {
+ case <-ctx.Done():
+ return nil
+ case <-time.After(interval):
+ }
+ }
+}
+
+func reportCopilotSweep(cmd *cobra.Command, summary copilotsession.Summary) {
+ if endpointCopilotOpts.print {
+ return
+ }
+ if endpointOpts.jsonOutput {
+ _ = json.NewEncoder(cmd.OutOrStdout()).Encode(summary)
+ return
+ }
+ fmt.Fprintf(cmd.OutOrStdout(), "copilot sync: %d sessions, %d changed, %d events, %d errors\n",
+ summary.Sessions, summary.SessionsChanged, summary.EventsEmitted, summary.Errors)
+ if summary.MalformedLines > 0 {
+ fmt.Fprintf(cmd.OutOrStdout(), " %d unreadable line(s) in GitHub Copilot CLI session logs\n", summary.MalformedLines)
+ }
+ if summary.PartialSessions > 0 {
+ fmt.Fprintf(cmd.OutOrStdout(), " %d session(s) had a partly written record; it will be read on the next sweep\n", summary.PartialSessions)
+ }
+}
+
+type copilotSessionStatus struct {
+ SessionID string `json:"session_id"`
+ Workspace string `json:"workspace,omitempty"`
+ Repository string `json:"repository,omitempty"`
+ Branch string `json:"branch,omitempty"`
+ Title string `json:"title,omitempty"`
+ Path string `json:"path"`
+ CollectedLine int `json:"collected_line"`
+ LastLine int `json:"last_line"`
+ Collected bool `json:"collected"`
+ SizeBytes int64 `json:"size_bytes"`
+}
+
+type copilotStatusReport struct {
+ CopilotDir string `json:"copilot_dir"`
+ SessionStateDir string `json:"session_state_dir"`
+ Present bool `json:"present"`
+ StatePath string `json:"state_path,omitempty"`
+ Sessions []copilotSessionStatus `json:"sessions"`
+}
+
+func runEndpointCopilotStatus(cmd *cobra.Command, args []string) error {
+ store, err := copilotsession.NewStore(endpointCopilotOpts.copilotDir)
+ if err != nil {
+ return err
+ }
+ statePath := resolveCopilotStatePath(endpointCopilotOpts.statePath, endpointUserMode())
+ state, err := copilotsession.LoadState(statePath)
+ if err != nil {
+ return err
+ }
+ refs, err := store.List()
+ if err != nil {
+ return err
+ }
+ refs = copilotsession.FilterRefs(refs, copilotsession.CollectOptions{Workspace: endpointCopilotOpts.workspace, SessionID: endpointCopilotOpts.sessionID})
+ report := copilotStatusReport{
+ CopilotDir: store.CopilotDir,
+ SessionStateDir: store.SessionStateDir,
+ Present: store.Exists(),
+ StatePath: statePath,
+ Sessions: make([]copilotSessionStatus, 0, len(refs)),
+ }
+ for _, ref := range refs {
+ records, _, _ := store.Read(ref)
+ status := copilotSessionStatus{
+ SessionID: ref.ID,
+ Path: ref.Path,
+ LastLine: lastCopilotLine(records),
+ SizeBytes: ref.SizeBytes,
+ }
+ if ref.Meta != nil {
+ status.Workspace = copilotFirstNonEmpty(ref.Meta.CWD, ref.Meta.GitRoot)
+ status.Repository = ref.Meta.Repository
+ status.Branch = ref.Meta.Branch
+ status.Title = ref.Meta.Name
+ }
+ if cursor := state.Files[ref.Path]; cursor != nil {
+ status.CollectedLine = cursor.LastLine
+ status.Collected = cursor.LastLine >= status.LastLine && cursor.SizeBytes == ref.SizeBytes && !cursor.PartialTail
+ }
+ report.Sessions = append(report.Sessions, status)
+ }
+ if endpointOpts.jsonOutput {
+ return json.NewEncoder(cmd.OutOrStdout()).Encode(report)
+ }
+ out := cmd.OutOrStdout()
+ if !report.Present {
+ fmt.Fprintf(out, "GitHub Copilot CLI sessions: none (%s does not exist)\n", report.SessionStateDir)
+ return nil
+ }
+ fmt.Fprintf(out, "GitHub Copilot CLI sessions: %d in %s\n", len(report.Sessions), report.SessionStateDir)
+ for _, session := range report.Sessions {
+ state := "pending"
+ if session.Collected {
+ state = "collected"
+ }
+ fmt.Fprintf(out, " %s %s line %d/%d %s\n",
+ session.SessionID, state, session.CollectedLine, session.LastLine, strings.TrimSpace(session.Workspace))
+ }
+ return nil
+}
+
+func lastCopilotLine(records []copilotsession.Record) int {
+ if len(records) == 0 {
+ return 0
+ }
+ return records[len(records)-1].Line
+}
+
+func resolveCopilotStatePath(override string, userMode bool) string {
+ if strings.TrimSpace(override) != "" {
+ return override
+ }
+ if !userMode {
+ if dir := filepath.Dir(lifecycle.ResolveRuntimeLog(false, "").EffectiveLogPath); dir != "" && dir != "." {
+ return filepath.Join(dir, "copilot-state.json")
+ }
+ }
+ return copilotsession.DefaultStatePath()
+}
+
+func copilotFirstNonEmpty(values ...string) string {
+ for _, value := range values {
+ if strings.TrimSpace(value) != "" {
+ return value
+ }
+ }
+ return ""
+}
diff --git a/cli/beacon/cmd/endpoint_copilot_test.go b/cli/beacon/cmd/endpoint_copilot_test.go
new file mode 100644
index 00000000..ce32a92d
--- /dev/null
+++ b/cli/beacon/cmd/endpoint_copilot_test.go
@@ -0,0 +1,201 @@
+package cmd
+
+import (
+ "bytes"
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/spf13/cobra"
+)
+
+type copilotCommandFixture struct {
+ copilotDir string
+ statePath string
+ logPath string
+}
+
+func newCopilotCommandFixture(t *testing.T) copilotCommandFixture {
+ t.Helper()
+ root := t.TempDir()
+ f := copilotCommandFixture{
+ copilotDir: filepath.Join(root, "copilot"),
+ statePath: filepath.Join(root, "state", "copilot.json"),
+ logPath: filepath.Join(root, "logs", "runtime.jsonl"),
+ }
+ f.writeSession(t)
+ endpointCopilotOpts.copilotDir = f.copilotDir
+ endpointCopilotOpts.statePath = f.statePath
+ endpointCopilotOpts.logPath = f.logPath
+ endpointCopilotOpts.print = false
+ endpointCopilotOpts.watch = false
+ endpointCopilotOpts.workspace = ""
+ endpointCopilotOpts.sessionID = ""
+ endpointOpts.jsonOutput = false
+ endpointOpts.userMode = true
+ endpointOpts.systemMode = false
+ t.Cleanup(func() {
+ endpointCopilotOpts.copilotDir = ""
+ endpointCopilotOpts.statePath = ""
+ endpointCopilotOpts.logPath = ""
+ endpointCopilotOpts.print = false
+ endpointCopilotOpts.watch = false
+ endpointCopilotOpts.workspace = ""
+ endpointCopilotOpts.sessionID = ""
+ endpointOpts.jsonOutput = false
+ })
+ return f
+}
+
+func (f copilotCommandFixture) writeSession(t *testing.T) {
+ t.Helper()
+ const sessionID = "caab1e17-509c-43b4-9ff2-13d1427c36a1"
+ dir := filepath.Join(f.copilotDir, "session-state", sessionID)
+ if err := os.MkdirAll(dir, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ workspace := strings.Join([]string{
+ "id: " + sessionID,
+ "cwd: /repo",
+ "git_root: /repo",
+ "repository: Asymptote-Labs/agent-beacon",
+ "branch: main",
+ "name: Fixture Session",
+ "",
+ }, "\n")
+ if err := os.WriteFile(filepath.Join(dir, "workspace.yaml"), []byte(workspace), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ lines := []string{
+ `{"id":"s1","timestamp":1770000000000,"type":"session.start","data":{"sessionId":"caab1e17-509c-43b4-9ff2-13d1427c36a1","copilotVersion":"1.2.3","selectedModel":"gpt-5.3-codex","context":{"cwd":"/repo"}}}`,
+ `{"id":"u1","timestamp":1770000000100,"type":"user.message","data":{"content":"run tests"}}`,
+ `{"id":"t1","timestamp":1770000000200,"type":"tool.execution_start","data":{"toolCallId":"call_bash","toolName":"bash","arguments":{"command":"go test ./..."}}}`,
+ `{"id":"t2","timestamp":1770000000500,"type":"tool.execution_complete","data":{"toolCallId":"call_bash","success":true,"result":{"content":"ok"}}}`,
+ `{"id":"a1","timestamp":1770000000800,"type":"assistant.message","data":{"content":"Done.","model":"gpt-5.3-codex","outputTokens":20}}`,
+ }
+ if err := os.WriteFile(filepath.Join(dir, "events.jsonl"), []byte(strings.Join(lines, "\n")+"\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func runCopilotCommand(t *testing.T, cmd *cobra.Command, run func(*cobra.Command, []string) error) string {
+ t.Helper()
+ var out bytes.Buffer
+ cmd.SetOut(&out)
+ cmd.SetErr(&out)
+ t.Cleanup(func() {
+ cmd.SetOut(nil)
+ cmd.SetErr(nil)
+ })
+ if err := run(cmd, nil); err != nil {
+ t.Fatalf("command failed: %v", err)
+ }
+ return out.String()
+}
+
+func TestEndpointCopilotSyncWritesRuntimeLogAndIsIdempotent(t *testing.T) {
+ f := newCopilotCommandFixture(t)
+
+ output := runCopilotCommand(t, endpointCopilotSyncCmd, runEndpointCopilotSync)
+ if !strings.Contains(output, "copilot sync:") {
+ t.Fatalf("sweep reported nothing readable: %q", output)
+ }
+ data, err := os.ReadFile(f.logPath)
+ if err != nil {
+ t.Fatalf("read runtime log: %v", err)
+ }
+ if !strings.Contains(string(data), `"copilot_cli"`) || !strings.Contains(string(data), `"command.executed"`) {
+ t.Fatalf("runtime log has no Copilot command event:\n%s", data)
+ }
+
+ runCopilotCommand(t, endpointCopilotSyncCmd, runEndpointCopilotSync)
+ again, err := os.ReadFile(f.logPath)
+ if err != nil {
+ t.Fatalf("read runtime log again: %v", err)
+ }
+ if !bytes.Equal(data, again) {
+ t.Fatalf("second sweep changed the runtime log:\nfirst:\n%s\nsecond:\n%s", data, again)
+ }
+}
+
+func TestEndpointCopilotSyncPrintLeavesNoTrace(t *testing.T) {
+ f := newCopilotCommandFixture(t)
+ endpointCopilotOpts.print = true
+
+ output := runCopilotCommand(t, endpointCopilotSyncCmd, runEndpointCopilotSync)
+ if !strings.Contains(output, `"copilot_cli"`) {
+ t.Fatalf("--print showed no events:\n%s", output)
+ }
+ for _, line := range strings.Split(strings.TrimSpace(output), "\n") {
+ var event map[string]interface{}
+ if err := json.Unmarshal([]byte(line), &event); err != nil {
+ t.Fatalf("--print emitted a non-JSON line %q: %v", line, err)
+ }
+ }
+ if _, err := os.Stat(f.logPath); !os.IsNotExist(err) {
+ t.Fatal("--print wrote the runtime log")
+ }
+ if _, err := os.Stat(f.statePath); !os.IsNotExist(err) {
+ t.Fatal("--print wrote a cursor file")
+ }
+}
+
+func TestEndpointCopilotStatusReportsProgress(t *testing.T) {
+ newCopilotCommandFixture(t)
+ before := runCopilotCommand(t, endpointCopilotStatusCmd, runEndpointCopilotStatus)
+ if !strings.Contains(before, "pending") {
+ t.Fatalf("status before sync:\n%s", before)
+ }
+ runCopilotCommand(t, endpointCopilotSyncCmd, runEndpointCopilotSync)
+ after := runCopilotCommand(t, endpointCopilotStatusCmd, runEndpointCopilotStatus)
+ if !strings.Contains(after, "collected") {
+ t.Fatalf("status after sync:\n%s", after)
+ }
+}
+
+func TestEndpointCopilotStatusJSONDescribesSessions(t *testing.T) {
+ newCopilotCommandFixture(t)
+ runCopilotCommand(t, endpointCopilotSyncCmd, runEndpointCopilotSync)
+ endpointOpts.jsonOutput = true
+ output := runCopilotCommand(t, endpointCopilotStatusCmd, runEndpointCopilotStatus)
+ var report copilotStatusReport
+ if err := json.Unmarshal([]byte(output), &report); err != nil {
+ t.Fatalf("status --json is not JSON: %v\n%s", err, output)
+ }
+ if !report.Present || len(report.Sessions) != 1 {
+ t.Fatalf("report = %+v", report)
+ }
+ if !report.Sessions[0].Collected || report.Sessions[0].Workspace != "/repo" {
+ t.Fatalf("session = %+v", report.Sessions[0])
+ }
+}
+
+func TestEndpointCopilotStatusOnMachineWithoutCopilotSaysSo(t *testing.T) {
+ newCopilotCommandFixture(t)
+ endpointCopilotOpts.copilotDir = filepath.Join(t.TempDir(), "missing")
+ output := runCopilotCommand(t, endpointCopilotStatusCmd, runEndpointCopilotStatus)
+ if !strings.Contains(output, "none") {
+ t.Fatalf("status on missing Copilot dir: %q", output)
+ }
+}
+
+func TestCopilotStatePathAlwaysResolvesSomewhereDurable(t *testing.T) {
+ if got := resolveCopilotStatePath("/explicit/path.json", true); got != "/explicit/path.json" {
+ t.Errorf("explicit --state overridden: %q", got)
+ }
+ home := t.TempDir()
+ t.Setenv("HOME", home)
+ t.Setenv("USERPROFILE", home)
+ got := resolveCopilotStatePath("", true)
+ if want := filepath.Join(home, ".beacon", "endpoint", "state", "copilot.json"); got != want {
+ t.Errorf("resolveCopilotStatePath = %q, want %q", got, want)
+ }
+ t.Setenv("HOME", "")
+ t.Setenv("USERPROFILE", "")
+ fallback := resolveCopilotStatePath("", true)
+ if fallback == "" || !filepath.IsAbs(fallback) {
+ t.Errorf("with no home the cursor path is %q", fallback)
+ }
+}
diff --git a/cli/beacon/internal/copilotsession/collect.go b/cli/beacon/internal/copilotsession/collect.go
new file mode 100644
index 00000000..8d92e28c
--- /dev/null
+++ b/cli/beacon/internal/copilotsession/collect.go
@@ -0,0 +1,280 @@
+package copilotsession
+
+import (
+ "encoding/json"
+ "errors"
+ "fmt"
+ "io"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/writer"
+)
+
+type Cursor struct {
+ LastLine int `json:"last_line"`
+ SizeBytes int64 `json:"size_bytes,omitempty"`
+ ModTimeUnixMS int64 `json:"mtime_unix_ms,omitempty"`
+ Started bool `json:"started,omitempty"`
+ PartialTail bool `json:"partial_tail,omitempty"`
+}
+
+type State struct {
+ Version int `json:"version"`
+ Files map[string]*Cursor `json:"files"`
+}
+
+type CollectOptions struct {
+ CopilotDir string
+ StatePath string
+ Write bool
+ LogPath string
+ UserMode bool
+ Print bool
+ Out io.Writer
+ Workspace string
+ SessionID string
+}
+
+type Summary struct {
+ Sessions int `json:"sessions"`
+ SessionsChanged int `json:"sessions_changed"`
+ EventsEmitted int `json:"events_emitted"`
+ Errors int `json:"errors"`
+ MalformedLines int `json:"malformed_lines"`
+ PartialSessions int `json:"partial_sessions"`
+}
+
+func DefaultStatePath() string {
+ base := filepath.Join(os.TempDir(), "beacon")
+ if home, err := os.UserHomeDir(); err == nil && strings.TrimSpace(home) != "" {
+ base = filepath.Join(home, ".beacon")
+ }
+ return filepath.Join(base, "endpoint", "state", "copilot.json")
+}
+
+func LoadState(path string) (*State, error) {
+ state := &State{Version: StateVersion, Files: map[string]*Cursor{}}
+ if path == "" {
+ return state, nil
+ }
+ data, err := os.ReadFile(path)
+ if err != nil {
+ if errors.Is(err, os.ErrNotExist) {
+ return state, nil
+ }
+ return nil, err
+ }
+ var stored State
+ if err := json.Unmarshal(data, &stored); err != nil {
+ return nil, fmt.Errorf("read GitHub Copilot CLI collector state %s: %w", path, err)
+ }
+ if stored.Version != StateVersion || stored.Files == nil {
+ return state, nil
+ }
+ state.Files = stored.Files
+ return state, nil
+}
+
+func (s *State) Save(path string) error {
+ if path == "" {
+ return nil
+ }
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ return err
+ }
+ s.Version = StateVersion
+ data, err := json.MarshalIndent(s, "", " ")
+ if err != nil {
+ return err
+ }
+ tmp := path + ".tmp"
+ if err := os.WriteFile(tmp, data, 0o600); err != nil {
+ return err
+ }
+ return os.Rename(tmp, path)
+}
+
+func (s *State) cursor(path string) *Cursor {
+ if s.Files == nil {
+ s.Files = map[string]*Cursor{}
+ }
+ c := s.Files[path]
+ if c == nil {
+ c = &Cursor{}
+ s.Files[path] = c
+ }
+ return c
+}
+
+func CollectOnce(opts CollectOptions) (summary Summary, err error) {
+ if opts.Print {
+ opts.StatePath = ""
+ opts.Write = false
+ }
+ store, err := NewStore(opts.CopilotDir)
+ if err != nil {
+ return summary, err
+ }
+ refs, err := store.List()
+ if err != nil {
+ return summary, err
+ }
+ refs = FilterRefs(refs, opts)
+ summary.Sessions = len(refs)
+ if len(refs) == 0 {
+ return summary, nil
+ }
+ state, err := LoadState(opts.StatePath)
+ if err != nil {
+ return summary, err
+ }
+ defer func() {
+ if saveErr := state.Save(opts.StatePath); saveErr != nil && err == nil {
+ err = fmt.Errorf("save GitHub Copilot CLI collector state: %w", saveErr)
+ }
+ }()
+
+ var errs []error
+ for _, ref := range refs {
+ changed, collectErr := collectSession(store, ref, state, opts, &summary)
+ if collectErr != nil {
+ summary.Errors++
+ errs = append(errs, fmt.Errorf("GitHub Copilot CLI session %s: %w", ref.ID, collectErr))
+ continue
+ }
+ if changed {
+ summary.SessionsChanged++
+ }
+ }
+ if len(errs) > 0 {
+ return summary, errors.Join(errs...)
+ }
+ return summary, nil
+}
+
+func collectSession(store *Store, ref SessionRef, state *State, opts CollectOptions, summary *Summary) (bool, error) {
+ cursor := state.cursor(ref.Path)
+ if ref.SizeBytes < cursor.SizeBytes {
+ cursor.LastLine = 0
+ cursor.Started = false
+ }
+ if ref.SizeBytes == cursor.SizeBytes && ref.ModTimeUnixMS == cursor.ModTimeUnixMS && !cursor.PartialTail {
+ return false, nil
+ }
+ records, stats, err := store.Read(ref)
+ summary.MalformedLines += stats.Malformed
+ if stats.PartialTail {
+ summary.PartialSessions++
+ }
+ if err != nil {
+ return false, err
+ }
+ mapped := MapSession(ref, records, MapOptions{MinLine: cursor.LastLine, SkipSessionStarted: cursor.Started})
+ if len(mapped) == 0 {
+ advanceCursor(cursor, ref, records, stats)
+ return false, nil
+ }
+ for i, item := range mapped {
+ if err := emit(item.Event, opts); err != nil {
+ advanceCursorPartial(cursor, mapped, i)
+ return true, err
+ }
+ summary.EventsEmitted++
+ if item.Event.Event.Action == "session.started" {
+ cursor.Started = true
+ }
+ }
+ advanceCursor(cursor, ref, records, stats)
+ return true, nil
+}
+
+func advanceCursor(cursor *Cursor, ref SessionRef, records []Record, stats Stats) {
+ if len(records) > 0 {
+ cursor.LastLine = records[len(records)-1].Line
+ }
+ cursor.SizeBytes = ref.SizeBytes
+ cursor.ModTimeUnixMS = ref.ModTimeUnixMS
+ cursor.PartialTail = stats.PartialTail
+ for _, record := range records {
+ if record.Type == "session.start" && record.Line <= cursor.LastLine {
+ cursor.Started = true
+ break
+ }
+ }
+}
+
+func advanceCursorPartial(cursor *Cursor, mapped []MappedEvent, failedIdx int) {
+ var lastLine int
+ for i := 0; i < failedIdx; i++ {
+ if mapped[i].SourceLine > lastLine {
+ lastLine = mapped[i].SourceLine
+ }
+ if mapped[i].Event.Event.Action == "session.started" {
+ cursor.Started = true
+ }
+ }
+ if lastLine > cursor.LastLine {
+ cursor.LastLine = lastLine
+ }
+}
+
+func emit(event schema.Event, opts CollectOptions) error {
+ if opts.Print && opts.Out != nil {
+ data, err := json.Marshal(event)
+ if err != nil {
+ return err
+ }
+ if _, err := opts.Out.Write(append(data, '\n')); err != nil {
+ return err
+ }
+ }
+ if opts.Write {
+ if _, err := writer.AppendEvent(event, writer.Options{Path: opts.LogPath, UserMode: opts.UserMode}); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func FilterRefs(refs []SessionRef, opts CollectOptions) []SessionRef {
+ sessionID := strings.TrimSpace(opts.SessionID)
+ workspace := cleanPath(opts.Workspace)
+ if sessionID == "" && workspace == "" {
+ return refs
+ }
+ out := refs[:0]
+ for _, ref := range refs {
+ if sessionID != "" && ref.ID != sessionID {
+ continue
+ }
+ if workspace != "" && cleanPath(workspaceOf(ref)) != workspace {
+ continue
+ }
+ out = append(out, ref)
+ }
+ return out
+}
+
+func workspaceOf(ref SessionRef) string {
+ if ref.Meta == nil {
+ return ""
+ }
+ if strings.TrimSpace(ref.Meta.CWD) != "" {
+ return ref.Meta.CWD
+ }
+ return ref.Meta.GitRoot
+}
+
+func cleanPath(path string) string {
+ path = strings.TrimSpace(path)
+ if path == "" {
+ return ""
+ }
+ if abs, err := filepath.Abs(path); err == nil {
+ return filepath.Clean(abs)
+ }
+ return filepath.Clean(path)
+}
diff --git a/cli/beacon/internal/copilotsession/copilotsession_test.go b/cli/beacon/internal/copilotsession/copilotsession_test.go
new file mode 100644
index 00000000..a9e0f220
--- /dev/null
+++ b/cli/beacon/internal/copilotsession/copilotsession_test.go
@@ -0,0 +1,259 @@
+package copilotsession
+
+import (
+ "bytes"
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
+)
+
+func writeCopilotFixture(t *testing.T, root string) (string, string) {
+ t.Helper()
+ const sessionID = "caab1e17-509c-43b4-9ff2-13d1427c36a1"
+ dir := filepath.Join(root, "session-state", sessionID)
+ if err := os.MkdirAll(dir, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ workspace := strings.Join([]string{
+ "id: " + sessionID,
+ "cwd: /repo",
+ "git_root: /repo",
+ "repository: Asymptote-Labs/agent-beacon",
+ "branch: main",
+ "name: Fixture Session",
+ "created_at: 2026-05-24T23:00:09.657Z",
+ "updated_at: 2026-05-24T23:00:39.908Z",
+ "",
+ }, "\n")
+ if err := os.WriteFile(filepath.Join(dir, WorkspaceFile), []byte(workspace), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ lines := []string{
+ `{"id":"s1","timestamp":1770000000000,"type":"session.start","data":{"sessionId":"caab1e17-509c-43b4-9ff2-13d1427c36a1","copilotVersion":"1.2.3","selectedModel":"gpt-5.3-codex","context":{"cwd":"/repo","repository":"Asymptote-Labs/agent-beacon","branch":"main"}}}`,
+ `{"id":"u1","timestamp":1770000000100,"type":"user.message","data":{"content":"run tests"}}`,
+ `{"id":"t1","timestamp":1770000000200,"type":"tool.execution_start","data":{"toolCallId":"call_bash","toolName":"bash","turnId":"turn1","arguments":{"command":"go test ./...","description":"Run tests"}}}`,
+ `{"id":"t2","timestamp":1770000000500,"type":"tool.execution_complete","data":{"toolCallId":"call_bash","turnId":"turn1","success":true,"result":{"content":"ok","detailedContent":"ok"},"toolTelemetry":{"properties":{"command":"go test ./..."}}}}`,
+ `{"id":"t3","timestamp":1770000000600,"type":"tool.execution_start","data":{"toolCallId":"call_view","toolName":"view","turnId":"turn1","arguments":{"path":"README.md"}}}`,
+ `{"id":"t4","timestamp":1770000000700,"type":"tool.execution_complete","data":{"toolCallId":"call_view","turnId":"turn1","success":true,"result":{"content":"# Beacon"}}}`,
+ `{"id":"a1","timestamp":1770000000800,"type":"assistant.message","data":{"content":"Done.","messageId":"msg1","model":"gpt-5.3-codex","outputTokens":20,"turnId":"turn1"}}`,
+ `{"id":"x1","timestamp":1770000000900,"type":"session.shutdown","data":{"currentModel":"gpt-5.3-codex","modelMetrics":{"gpt-5.3-codex":{"requests":{"count":1,"cost":0.01},"totalNanoAiu":1000,"usage":{"inputTokens":100,"outputTokens":20,"cacheReadTokens":2,"cacheWriteTokens":3,"reasoningTokens":5}}},"totalPremiumRequests":1,"totalNanoAiu":1000}}`,
+ }
+ path := filepath.Join(dir, EventsFile)
+ if err := os.WriteFile(path, []byte(strings.Join(lines, "\n")+"\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ return sessionID, path
+}
+
+func TestMapSessionReconstructsCommandsFilesAndUsage(t *testing.T) {
+ root := t.TempDir()
+ _, _ = writeCopilotFixture(t, root)
+ store, err := NewStore(root)
+ if err != nil {
+ t.Fatal(err)
+ }
+ refs, err := store.List()
+ if err != nil {
+ t.Fatal(err)
+ }
+ records, _, err := store.Read(refs[0])
+ if err != nil {
+ t.Fatal(err)
+ }
+ events := MapSession(refs[0], records, MapOptions{})
+ actions := map[string]int{}
+ for _, item := range events {
+ ev := item.Event
+ actions[ev.Event.Action]++
+ if ev.Harness.Name != Harness || ev.Harness.CollectionMethod != schema.CollectionMethodPoll {
+ t.Fatalf("bad provenance: %+v", ev.Harness)
+ }
+ if ev.Origin != schema.OriginLocal {
+ t.Fatalf("bad origin: %q", ev.Origin)
+ }
+ }
+ for _, action := range []string{"session.started", "prompt.submitted", "tool.invoked", "command.executed", "file.read", "agent.message", "token.usage"} {
+ if actions[action] == 0 {
+ t.Fatalf("missing action %q in %#v", action, actions)
+ }
+ }
+ if actions["token.usage"] != 2 {
+ t.Fatalf("token usage should be split into assistant output and shutdown input/cache/reasoning, got %d", actions["token.usage"])
+ }
+
+ var command schema.Event
+ var fileRead schema.Event
+ var shutdownUsage schema.Event
+ for _, item := range events {
+ switch item.Event.Event.Action {
+ case "command.executed":
+ command = item.Event
+ case "file.read":
+ fileRead = item.Event
+ case "token.usage":
+ if item.Event.GenAI != nil && item.Event.GenAI.Usage != nil && item.Event.GenAI.Usage.InputTokens != nil {
+ shutdownUsage = item.Event
+ }
+ }
+ }
+ if command.Command == nil || command.Command.Command != "go test ./..." || command.Command.Output != "ok" {
+ t.Fatalf("command event = %+v", command.Command)
+ }
+ if fileRead.File == nil || fileRead.File.Path != "README.md" || fileRead.File.Operation != "read" {
+ t.Fatalf("file event = %+v", fileRead.File)
+ }
+ if shutdownUsage.GenAI == nil || shutdownUsage.GenAI.Usage == nil || shutdownUsage.GenAI.Usage.OutputTokens != nil {
+ t.Fatalf("shutdown usage double-counted output tokens: %+v", shutdownUsage.GenAI)
+ }
+ if got := *shutdownUsage.GenAI.Usage.InputTokens; got != 100 {
+ t.Fatalf("shutdown input tokens = %d, want 100", got)
+ }
+ if got := *shutdownUsage.GenAI.Usage.CacheRead.InputTokens; got != 2 {
+ t.Fatalf("cache read tokens = %d, want 2", got)
+ }
+ if got := *shutdownUsage.GenAI.Usage.CacheCreation.InputTokens; got != 3 {
+ t.Fatalf("cache write tokens = %d, want 3", got)
+ }
+ if got := *shutdownUsage.GenAI.Usage.Reasoning.OutputTokens; got != 5 {
+ t.Fatalf("reasoning tokens = %d, want 5", got)
+ }
+}
+
+func TestCollectOnceIsIdempotentAndPrintDoesNotAdvanceState(t *testing.T) {
+ root := t.TempDir()
+ _, _ = writeCopilotFixture(t, root)
+ statePath := filepath.Join(root, "state.json")
+ logPath := filepath.Join(root, "runtime.jsonl")
+ var printed bytes.Buffer
+ printSummary, err := CollectOnce(CollectOptions{CopilotDir: root, StatePath: statePath, Print: true, Out: &printed})
+ if err != nil {
+ t.Fatalf("print CollectOnce: %v", err)
+ }
+ if printSummary.EventsEmitted == 0 || !strings.Contains(printed.String(), `"copilot_cli"`) {
+ t.Fatalf("--print emitted nothing useful: %+v\n%s", printSummary, printed.String())
+ }
+ if _, err := os.Stat(statePath); !os.IsNotExist(err) {
+ t.Fatal("--print wrote collector state")
+ }
+
+ opts := CollectOptions{CopilotDir: root, StatePath: statePath, LogPath: logPath, Write: true, UserMode: true}
+ first, err := CollectOnce(opts)
+ if err != nil {
+ t.Fatalf("first CollectOnce: %v", err)
+ }
+ if first.EventsEmitted == 0 {
+ t.Fatal("first sweep emitted no events")
+ }
+ before, err := os.ReadFile(logPath)
+ if err != nil {
+ t.Fatalf("read runtime log: %v", err)
+ }
+ second, err := CollectOnce(opts)
+ if err != nil {
+ t.Fatalf("second CollectOnce: %v", err)
+ }
+ after, err := os.ReadFile(logPath)
+ if err != nil {
+ t.Fatalf("read runtime log again: %v", err)
+ }
+ if second.EventsEmitted != 0 || !bytes.Equal(before, after) {
+ t.Fatalf("second sweep was not idempotent: %+v", second)
+ }
+}
+
+func TestDecoderReportsPartialTailAndCollectsItLater(t *testing.T) {
+ root := t.TempDir()
+ _, path := writeCopilotFixture(t, root)
+ f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := f.WriteString(`{"id":"partial","type":"user.message","data":{"content":"later"}`); err != nil {
+ t.Fatal(err)
+ }
+ _ = f.Close()
+ store, err := NewStore(root)
+ if err != nil {
+ t.Fatal(err)
+ }
+ refs, _ := store.List()
+ _, stats, err := store.Read(refs[0])
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !stats.PartialTail {
+ t.Fatal("partial tail was not reported")
+ }
+
+ if err := os.WriteFile(path, []byte(strings.TrimRight(readFile(t, path), "\n")+`}`+"\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ records, stats, err := store.Read(refs[0])
+ if err != nil {
+ t.Fatal(err)
+ }
+ if stats.PartialTail {
+ t.Fatal("completed tail still reported partial")
+ }
+ if records[len(records)-1].ID != "partial" {
+ t.Fatalf("last record = %+v", records[len(records)-1])
+ }
+}
+
+func TestEventIDsAreDeterministic(t *testing.T) {
+ root := t.TempDir()
+ _, _ = writeCopilotFixture(t, root)
+ store, _ := NewStore(root)
+ refs, _ := store.List()
+ records, _, _ := store.Read(refs[0])
+ first := MapSession(refs[0], records, MapOptions{})
+ second := MapSession(refs[0], records, MapOptions{})
+ if len(first) != len(second) {
+ t.Fatalf("event counts differ: %d != %d", len(first), len(second))
+ }
+ for i := range first {
+ if first[i].Event.Event.ID != second[i].Event.Event.ID {
+ t.Fatalf("event id %d changed: %s != %s", i, first[i].Event.Event.ID, second[i].Event.Event.ID)
+ }
+ }
+}
+
+func TestStatusStateRoundTrip(t *testing.T) {
+ root := t.TempDir()
+ _, path := writeCopilotFixture(t, root)
+ statePath := filepath.Join(root, "state.json")
+ if _, err := CollectOnce(CollectOptions{CopilotDir: root, StatePath: statePath, Print: true, Out: bytes.NewBuffer(nil)}); err != nil {
+ t.Fatal(err)
+ }
+ state, err := LoadState(statePath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(state.Files) != 0 {
+ t.Fatal("--print persisted state")
+ }
+ if _, err := CollectOnce(CollectOptions{CopilotDir: root, StatePath: statePath, Write: false}); err != nil {
+ t.Fatal(err)
+ }
+ state, err = LoadState(statePath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if state.Files[path] == nil || state.Files[path].LastLine == 0 {
+ data, _ := json.MarshalIndent(state, "", " ")
+ t.Fatalf("state did not record progress:\n%s", data)
+ }
+}
+
+func readFile(t *testing.T, path string) string {
+ t.Helper()
+ data, err := os.ReadFile(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return string(data)
+}
diff --git a/cli/beacon/internal/copilotsession/mapper.go b/cli/beacon/internal/copilotsession/mapper.go
new file mode 100644
index 00000000..4032040d
--- /dev/null
+++ b/cli/beacon/internal/copilotsession/mapper.go
@@ -0,0 +1,834 @@
+package copilotsession
+
+import (
+ "crypto/sha1"
+ "crypto/sha256"
+ "encoding/hex"
+ "encoding/json"
+ "fmt"
+ "io"
+ "path/filepath"
+ "strconv"
+ "strings"
+ "time"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"
+)
+
+type mapper struct {
+ ref SessionRef
+ opts MapOptions
+ out []MappedEvent
+ calls map[string]toolCall
+ session sessionContext
+ model string
+
+ lastUsage map[string]usageTotals
+ outputSinceLastTotals map[string]int64
+}
+
+type sessionContext struct {
+ ID string
+ Workspace string
+ Repository string
+ Branch string
+ Title string
+ Version string
+}
+
+type toolCall struct {
+ ID string
+ Name string
+ Arguments map[string]interface{}
+}
+
+type toolResult struct {
+ CallID string
+ Name string
+ Text string
+ Success bool
+ ErrorText string
+ Raw map[string]interface{}
+}
+
+type usageTotals struct {
+ Input int64
+ Output int64
+ CacheRead int64
+ CacheWrite int64
+ Reasoning int64
+}
+
+func MapSession(ref SessionRef, records []Record, opts MapOptions) []MappedEvent {
+ m := &mapper{
+ ref: ref,
+ opts: opts,
+ calls: map[string]toolCall{},
+ session: sessionFromRef(ref),
+ lastUsage: map[string]usageTotals{},
+ outputSinceLastTotals: map[string]int64{},
+ }
+ for _, record := range records {
+ if record.Line <= opts.MinLine {
+ m.consumeContext(record)
+ continue
+ }
+ m.consume(record)
+ }
+ return m.out
+}
+
+func sessionFromRef(ref SessionRef) sessionContext {
+ ctx := sessionContext{ID: ref.ID}
+ if ref.Meta != nil {
+ ctx.ID = firstNonEmpty(ref.Meta.ID, ctx.ID)
+ ctx.Workspace = firstNonEmpty(ref.Meta.CWD, ref.Meta.GitRoot)
+ ctx.Repository = ref.Meta.Repository
+ ctx.Branch = ref.Meta.Branch
+ ctx.Title = ref.Meta.Name
+ }
+ return ctx
+}
+
+func (m *mapper) consumeContext(record Record) {
+ switch record.Type {
+ case "session.start", "session.resume":
+ m.applySessionData(record.Data)
+ case "session.model_change":
+ if model := firstString(record.Data, "newModel", "selectedModel"); model != "" {
+ m.model = asymptoteobserve.NormalizeModelName(model)
+ }
+ case "assistant.message":
+ if model := firstString(record.Data, "model"); model != "" {
+ m.model = asymptoteobserve.NormalizeModelName(model)
+ }
+ m.rememberAssistantOutput(record)
+ for _, call := range toolRequests(record.Data) {
+ if call.ID != "" {
+ m.calls[call.ID] = call
+ }
+ }
+ case "tool.execution_start":
+ call := parseToolCall(record)
+ if call.ID != "" {
+ m.calls[call.ID] = call
+ }
+ case "session.shutdown":
+ m.rememberShutdownTotals(record)
+ }
+}
+
+func (m *mapper) consume(record Record) {
+ switch record.Type {
+ case "session.start":
+ if !m.opts.SkipSessionStarted {
+ m.emitSessionStarted(record)
+ }
+ case "session.resume":
+ m.emitSessionContext(record, "resume", "GitHub Copilot CLI session resumed")
+ case "session.model_change":
+ m.emitSessionContext(record, "model_change", "GitHub Copilot CLI model changed")
+ case "user.message":
+ m.emitPrompt(record)
+ case "assistant.message":
+ m.emitAssistant(record)
+ case "tool.execution_start":
+ m.emitToolCall(record)
+ case "tool.execution_complete":
+ m.emitToolResult(record)
+ case "session.shutdown":
+ m.emitShutdownUsage(record)
+ case "abort":
+ m.emitAbort(record)
+ }
+}
+
+func (m *mapper) applySessionData(data map[string]interface{}) {
+ if id := firstString(data, "sessionId", "session_id", "id"); id != "" {
+ m.session.ID = id
+ }
+ if version := firstString(data, "copilotVersion", "version"); version != "" {
+ m.session.Version = version
+ }
+ if model := firstString(data, "selectedModel", "currentModel"); model != "" {
+ m.model = asymptoteobserve.NormalizeModelName(model)
+ }
+ ctx := firstMap(data, "context")
+ if cwd := firstString(ctx, "cwd", "workingDirectory", "git_root"); cwd != "" {
+ m.session.Workspace = cwd
+ }
+ if repo := firstString(ctx, "repository"); repo != "" {
+ m.session.Repository = repo
+ }
+ if branch := firstString(ctx, "branch"); branch != "" {
+ m.session.Branch = branch
+ }
+}
+
+func (m *mapper) base(record Record, action, category string, severity schema.Severity, message string) schema.Event {
+ ev := schema.NewEvent(schema.NewEventOptions{
+ Action: action,
+ Category: category,
+ Severity: severity,
+ Harness: schema.HarnessInfo{
+ Name: Harness,
+ Version: m.session.Version,
+ CollectionMethod: schema.CollectionMethodPoll,
+ },
+ Origin: schema.OriginLocal,
+ Fidelity: schema.FidelityObserved,
+ Message: message,
+ })
+ if ts := timestampMS(record.Time, m.ref.ModTimeUnixMS); ts > 0 {
+ ev.Timestamp = schema.FormatTimestamp(time.UnixMilli(ts))
+ }
+ ev.Session = &schema.SessionInfo{ID: firstNonEmpty(m.session.ID, m.ref.ID), WorkingDirectory: m.session.Workspace}
+ if model := firstNonEmpty(m.model); model != "" {
+ ev.Model = model
+ }
+ return ev
+}
+
+func (m *mapper) emitSessionStarted(record Record) {
+ m.applySessionData(record.Data)
+ ev := m.base(record, "session.started", "session", schema.SeverityInfo, "GitHub Copilot CLI session started")
+ raw := map[string]interface{}{
+ "source_path": recordSourcePath(m.ref),
+ "line": record.Line,
+ }
+ if m.session.Repository != "" {
+ raw["repository"] = m.session.Repository
+ }
+ if m.session.Branch != "" {
+ raw["branch"] = m.session.Branch
+ }
+ ev.Raw = map[string]interface{}{"copilot": raw}
+ m.append(record, "session.started", ev)
+}
+
+func (m *mapper) emitSessionContext(record Record, change, message string) {
+ ev := m.base(record, "session.context", "session", schema.SeverityInfo, message)
+ raw := map[string]interface{}{"change": change, "source_path": recordSourcePath(m.ref), "line": record.Line}
+ if model := firstString(record.Data, "newModel", "selectedModel", "currentModel"); model != "" {
+ raw["model"] = model
+ }
+ if effort := firstString(record.Data, "reasoningEffort"); effort != "" {
+ raw["reasoning_effort"] = effort
+ }
+ ev.Raw = map[string]interface{}{"copilot": raw}
+ m.append(record, change, ev)
+}
+
+func (m *mapper) emitPrompt(record Record) {
+ text := firstStringRaw(record.Data, "content", "transformedContent")
+ if strings.TrimSpace(text) == "" {
+ return
+ }
+ ev := m.base(record, "prompt.submitted", "prompt", schema.SeverityInfo, "GitHub Copilot CLI prompt submitted")
+ ev.Prompt = &schema.PromptInfo{Text: text}
+ ev.Content = asymptoteobserve.RetainedContent(text, asymptoteobserve.DefaultStringLimit)
+ ev.GenAI = withGenAI(ev.GenAI, func(genAI *schema.GenAIInfo) {
+ genAI.Input = &schema.GenAIInputInfo{Messages: asymptoteobserve.TextInputMessages(text)}
+ })
+ ev.Raw = m.raw(record, nil)
+ m.append(record, "prompt.submitted", ev)
+}
+
+func (m *mapper) emitAssistant(record Record) {
+ if model := firstString(record.Data, "model"); model != "" {
+ m.model = asymptoteobserve.NormalizeModelName(model)
+ }
+ m.rememberAssistantOutput(record)
+ for _, call := range toolRequests(record.Data) {
+ if call.ID != "" {
+ m.calls[call.ID] = call
+ }
+ }
+ if reasoning := firstStringRaw(record.Data, "reasoningText"); strings.TrimSpace(reasoning) != "" {
+ ev := m.base(record, "agent.reasoning", "agent", schema.SeverityInfo, "GitHub Copilot CLI assistant reasoning")
+ ev.GenAI = withGenAI(ev.GenAI, func(genAI *schema.GenAIInfo) {
+ genAI.Output = &schema.GenAIOutputInfo{Messages: []map[string]interface{}{{
+ "role": "assistant",
+ "content": []map[string]string{{"type": "reasoning", "text": reasoning}},
+ }}}
+ })
+ ev.Content = asymptoteobserve.RetainedContent(reasoning, asymptoteobserve.DefaultRawStringLimit)
+ ev.Raw = m.raw(record, nil)
+ m.append(record, "assistant.reasoning", ev)
+ }
+ if text := firstStringRaw(record.Data, "content"); strings.TrimSpace(text) != "" {
+ ev := m.base(record, "agent.message", "agent", schema.SeverityInfo, "GitHub Copilot CLI assistant message")
+ ev.GenAI = withGenAI(ev.GenAI, func(genAI *schema.GenAIInfo) {
+ genAI.Output = &schema.GenAIOutputInfo{Messages: asymptoteobserve.TextOutputMessages(text)}
+ if id := firstString(record.Data, "messageId", "requestId", "serviceRequestId"); id != "" {
+ genAI.Response = &schema.GenAIResponseInfo{ID: id, Model: firstNonEmpty(m.model, firstString(record.Data, "model"))}
+ }
+ })
+ ev.Content = asymptoteobserve.RetainedContent(text, asymptoteobserve.DefaultRawStringLimit)
+ ev.Raw = m.raw(record, nil)
+ m.append(record, "assistant.message", ev)
+ }
+ m.emitAssistantUsage(record)
+}
+
+func (m *mapper) emitToolCall(record Record) {
+ call := parseToolCall(record)
+ if call.ID != "" {
+ m.calls[call.ID] = call
+ }
+ if call.Name == "" {
+ return
+ }
+ ev := m.base(record, "tool.invoked", "tool", schema.SeverityInfo, "GitHub Copilot CLI tool invoked")
+ ev.Tool = &schema.ToolInfo{Name: call.Name}
+ applyCall(&ev, call)
+ ev.Raw = m.raw(record, nil)
+ m.append(record, "tool.call", ev)
+}
+
+func (m *mapper) emitToolResult(record Record) {
+ result := parseToolResult(record)
+ call := m.calls[result.CallID]
+ if result.Name != "" {
+ call.Name = result.Name
+ }
+ if call.ID == "" {
+ call.ID = result.CallID
+ }
+ if call.Name == "" {
+ return
+ }
+ action, category, severity, message := classifyTool(call, result)
+ ev := m.base(record, action, category, severity, message)
+ ev.Tool = &schema.ToolInfo{Name: call.Name}
+ applyCall(&ev, call)
+ switch action {
+ case "command.executed":
+ applyCommand(&ev, call, result)
+ case "file.read", "file.created", "file.modified":
+ applyFile(&ev, call, result, action)
+ case "mcp.tool_invoked":
+ ev.MCP = mcpInfo(call.Name)
+ }
+ if !result.Success {
+ ev.Error = &schema.ErrorInfo{Type: "tool_execution_failed"}
+ }
+ ev.Raw = m.raw(record, map[string]interface{}{"tool_result": result.Raw})
+ m.append(record, "tool.result", ev)
+}
+
+func (m *mapper) emitAbort(record Record) {
+ ev := m.base(record, "agent.error", "session", schema.SeverityHigh, "GitHub Copilot CLI request interrupted")
+ ev.Error = &schema.ErrorInfo{Type: firstNonEmpty(firstString(record.Data, "reason"), "aborted")}
+ ev.Raw = m.raw(record, nil)
+ m.append(record, "abort", ev)
+}
+
+func (m *mapper) emitAssistantUsage(record Record) {
+ output, ok := int64Value(record.Data["outputTokens"])
+ if !ok || output <= 0 {
+ return
+ }
+ ev := m.base(record, "token.usage", "metric", schema.SeverityInfo, "GitHub Copilot CLI assistant output token usage")
+ ev.GenAI = withGenAI(ev.GenAI, func(genAI *schema.GenAIInfo) {
+ genAI.Usage = &schema.GenAIUsageInfo{OutputTokens: &output}
+ })
+ ev.Raw = m.raw(record, map[string]interface{}{"token_source": "assistant_message_output_tokens"})
+ m.append(record, "assistant.usage", ev)
+}
+
+func (m *mapper) rememberAssistantOutput(record Record) {
+ output, ok := int64Value(record.Data["outputTokens"])
+ if !ok || output <= 0 {
+ return
+ }
+ model := firstNonEmpty(asymptoteobserve.NormalizeModelName(firstString(record.Data, "model")), m.model, "_unknown")
+ m.outputSinceLastTotals[model] += output
+}
+
+func (m *mapper) rememberShutdownTotals(record Record) {
+ for model, total := range shutdownUsage(record.Data) {
+ m.lastUsage[model] = total
+ m.outputSinceLastTotals[model] = 0
+ }
+}
+
+func (m *mapper) emitShutdownUsage(record Record) {
+ models := shutdownUsage(record.Data)
+ for model, current := range models {
+ previous := m.lastUsage[model]
+ outputAlreadyReported := m.outputSinceLastTotals[model]
+ usage := &schema.GenAIUsageInfo{}
+ if n := delta(current.Input, previous.Input); n > 0 {
+ usage.InputTokens = &n
+ }
+ if n := delta(current.Output, previous.Output) - outputAlreadyReported; n > 0 {
+ usage.OutputTokens = &n
+ }
+ if n := delta(current.CacheRead, previous.CacheRead); n > 0 {
+ usage.CacheRead = &schema.GenAIUsageCacheReadInfo{InputTokens: &n}
+ }
+ if n := delta(current.CacheWrite, previous.CacheWrite); n > 0 {
+ usage.CacheCreation = &schema.GenAIUsageCacheCreationInfo{InputTokens: &n}
+ }
+ if n := delta(current.Reasoning, previous.Reasoning); n > 0 {
+ usage.Reasoning = &schema.GenAIUsageReasoningInfo{OutputTokens: &n}
+ }
+ m.lastUsage[model] = current
+ m.outputSinceLastTotals[model] = 0
+ if emptyUsage(usage) {
+ continue
+ }
+ ev := m.base(record, "token.usage", "metric", schema.SeverityInfo, "GitHub Copilot CLI shutdown token usage")
+ ev.Model = model
+ ev.GenAI = withGenAI(ev.GenAI, func(genAI *schema.GenAIInfo) { genAI.Usage = usage })
+ ev.Raw = m.raw(record, map[string]interface{}{
+ "token_source": "session_shutdown_model_metrics_delta",
+ "output_tokens_already_reported": outputAlreadyReported,
+ "cumulative_total_premium_requests": numberValue(record.Data["totalPremiumRequests"]),
+ "cumulative_total_nano_aiu": numberValue(record.Data["totalNanoAiu"]),
+ })
+ m.append(record, "shutdown.usage."+model, ev)
+ }
+}
+
+func (m *mapper) append(record Record, suffix string, ev schema.Event) {
+ dedupID := fmt.Sprintf("%s:%s:%d:%s", recordSourcePath(m.ref), firstNonEmpty(m.session.ID, m.ref.ID), record.Line, suffix)
+ ev.Event.ID = copilotEventID(dedupID)
+ m.out = append(m.out, MappedEvent{SourceLine: record.Line, DedupID: dedupID, Event: ev})
+}
+
+func parseToolCall(record Record) toolCall {
+ return toolCall{
+ ID: firstString(record.Data, "toolCallId", "tool_call_id", "id"),
+ Name: firstString(record.Data, "toolName", "tool_name", "name"),
+ Arguments: argumentsFrom(record.Data["arguments"]),
+ }
+}
+
+func toolRequests(data map[string]interface{}) []toolCall {
+ items, _ := data["toolRequests"].([]interface{})
+ out := make([]toolCall, 0, len(items))
+ for _, item := range items {
+ m, _ := item.(map[string]interface{})
+ if len(m) == 0 {
+ continue
+ }
+ out = append(out, toolCall{
+ ID: firstString(m, "toolCallId", "tool_call_id", "id"),
+ Name: firstString(m, "name", "toolName", "tool_name"),
+ Arguments: argumentsFrom(m["arguments"]),
+ })
+ }
+ return out
+}
+
+func parseToolResult(record Record) toolResult {
+ success := true
+ if value, ok := record.Data["success"].(bool); ok {
+ success = value
+ }
+ result := firstMap(record.Data, "result")
+ errObj := firstMap(record.Data, "error")
+ text := firstNonEmpty(firstStringRaw(result, "content", "detailedContent"), stringifyOutput(result))
+ errText := firstNonEmpty(firstStringRaw(errObj, "message"), firstStringRaw(record.Data, "message"))
+ if !success && errText != "" {
+ text = errText
+ }
+ return toolResult{
+ CallID: firstString(record.Data, "toolCallId", "tool_call_id", "id"),
+ Name: firstString(record.Data, "toolName", "tool_name", "name"),
+ Text: text,
+ Success: success,
+ ErrorText: errText,
+ Raw: record.Data,
+ }
+}
+
+func classifyTool(call toolCall, result toolResult) (action, category string, severity schema.Severity, message string) {
+ name := strings.ToLower(strings.TrimSpace(call.Name))
+ switch {
+ case strings.HasPrefix(name, "mcp__"):
+ return "mcp.tool_invoked", "mcp", schema.SeverityInfo, "GitHub Copilot CLI MCP tool invoked"
+ case name == "bash":
+ return "command.executed", "command", schema.SeverityInfo, "GitHub Copilot CLI command executed"
+ case isFileReadTool(name):
+ return "file.read", "file", schema.SeverityInfo, "GitHub Copilot CLI file read"
+ case isFileCreateTool(name):
+ return "file.created", "file", schema.SeverityInfo, "GitHub Copilot CLI file created"
+ case isFileModifyTool(name):
+ return "file.modified", "file", schema.SeverityInfo, "GitHub Copilot CLI file modified"
+ case !result.Success:
+ return "tool.failed", "tool", schema.SeverityHigh, "GitHub Copilot CLI tool failed"
+ default:
+ return "tool.completed", "tool", schema.SeverityInfo, "GitHub Copilot CLI tool completed"
+ }
+}
+
+func isFileReadTool(name string) bool {
+ switch name {
+ case "view", "read", "read_file", "glob", "rg", "grep", "search":
+ return true
+ default:
+ return false
+ }
+}
+
+func isFileCreateTool(name string) bool {
+ switch name {
+ case "create", "write":
+ return true
+ default:
+ return false
+ }
+}
+
+func isFileModifyTool(name string) bool {
+ switch name {
+ case "edit", "str_replace_editor", "replace", "patch":
+ return true
+ default:
+ return false
+ }
+}
+
+func applyCall(ev *schema.Event, call toolCall) {
+ ev.GenAI = withGenAI(ev.GenAI, func(genAI *schema.GenAIInfo) {
+ genAI.Operation = &schema.GenAIOperationInfo{Name: "execute_tool"}
+ genAI.Tool = &schema.GenAIToolInfo{
+ Name: call.Name,
+ Call: &schema.GenAIToolCallInfo{
+ ID: call.ID,
+ Arguments: call.Arguments,
+ },
+ }
+ })
+ if path := pathFromCall(call); path != "" {
+ ev.Tool.Path = path
+ }
+ if command := firstString(call.Arguments, "command", "cmd"); command != "" {
+ ev.Tool.Command = command
+ }
+}
+
+func applyCommand(ev *schema.Event, call toolCall, result toolResult) {
+ info := &schema.CommandInfo{Command: firstString(call.Arguments, "command", "cmd")}
+ if result.Text != "" {
+ info.Output = result.Text
+ ev.Content = asymptoteobserve.RetainedContent(result.Text, asymptoteobserve.DefaultStringLimit)
+ }
+ ev.Command = info
+}
+
+func applyFile(ev *schema.Event, call toolCall, result toolResult, action string) {
+ path := pathFromCall(call)
+ info := &schema.FileInfo{Path: path}
+ switch action {
+ case "file.created":
+ info.Operation = "create"
+ case "file.modified":
+ info.Operation = "modify"
+ default:
+ info.Operation = "read"
+ }
+ if path != "" {
+ info.Language = strings.TrimPrefix(filepath.Ext(path), ".")
+ }
+ if diff := diffFromCall(call, path); diff != "" && action != "file.read" {
+ info.Diff = diff
+ info.DiffBytes = len(diff)
+ sum := sha256.Sum256([]byte(diff))
+ info.DiffHash = hex.EncodeToString(sum[:])
+ ev.Content = asymptoteobserve.RetainedContent(diff, asymptoteobserve.DefaultStringLimit)
+ } else if result.Text != "" {
+ ev.Content = asymptoteobserve.RetainedContent(result.Text, asymptoteobserve.DefaultStringLimit)
+ }
+ ev.File = info
+}
+
+func pathFromCall(call toolCall) string {
+ if path := firstString(call.Arguments, "path", "file_path", "target_path", "absolute_path"); path != "" {
+ return path
+ }
+ if paths, ok := call.Arguments["paths"].([]interface{}); ok && len(paths) > 0 {
+ if path, ok := paths[0].(string); ok {
+ return path
+ }
+ }
+ if paths := firstString(call.Arguments, "paths"); paths != "" {
+ return paths
+ }
+ return ""
+}
+
+func diffFromCall(call toolCall, path string) string {
+ content := firstStringRaw(call.Arguments, "content", "file_text")
+ if isFileCreateTool(strings.ToLower(call.Name)) && path != "" && content != "" {
+ return "--- /dev/null\n+++ " + path + "\n+" + strings.ReplaceAll(content, "\n", "\n+") + "\n"
+ }
+ oldText := firstStringRaw(call.Arguments, "old_string", "old_str")
+ newText := firstStringRaw(call.Arguments, "new_string", "new_str", "insert")
+ if oldText != "" || newText != "" {
+ return "-" + strings.ReplaceAll(oldText, "\n", "\n-") + "\n+" + strings.ReplaceAll(newText, "\n", "\n+") + "\n"
+ }
+ return ""
+}
+
+func mcpInfo(name string) *schema.MCPInfo {
+ trimmed := strings.TrimPrefix(name, "mcp__")
+ parts := strings.SplitN(trimmed, "__", 2)
+ if len(parts) == 2 {
+ return &schema.MCPInfo{Server: parts[0], Tool: parts[1]}
+ }
+ return &schema.MCPInfo{Tool: name}
+}
+
+func shutdownUsage(data map[string]interface{}) map[string]usageTotals {
+ metrics := firstMap(data, "modelMetrics")
+ out := map[string]usageTotals{}
+ for model, value := range metrics {
+ modelData, _ := value.(map[string]interface{})
+ usageData := firstMap(modelData, "usage")
+ if len(usageData) == 0 {
+ continue
+ }
+ out[asymptoteobserve.NormalizeModelName(model)] = usageTotals{
+ Input: int64OrZero(firstPresent(usageData, "inputTokens", "input_tokens")),
+ Output: int64OrZero(firstPresent(usageData, "outputTokens", "output_tokens")),
+ CacheRead: int64OrZero(firstPresent(usageData, "cacheReadTokens", "cache_read_tokens")),
+ CacheWrite: int64OrZero(firstPresent(usageData, "cacheWriteTokens", "cache_write_tokens")),
+ Reasoning: int64OrZero(firstPresent(usageData, "reasoningTokens", "reasoning_tokens")),
+ }
+ }
+ return out
+}
+
+func emptyUsage(usage *schema.GenAIUsageInfo) bool {
+ return usage.InputTokens == nil && usage.OutputTokens == nil && usage.CacheRead == nil && usage.CacheCreation == nil && usage.Reasoning == nil && usage.CostUSD == nil
+}
+
+func delta(current, previous int64) int64 {
+ if current <= previous {
+ return 0
+ }
+ return current - previous
+}
+
+func (m *mapper) raw(record Record, extra map[string]interface{}) map[string]interface{} {
+ raw := map[string]interface{}{
+ "source_path": recordSourcePath(m.ref),
+ "line": record.Line,
+ "type": record.Type,
+ }
+ if record.ID != "" {
+ raw["record_id"] = record.ID
+ }
+ for k, v := range extra {
+ raw[k] = v
+ }
+ return map[string]interface{}{"copilot": raw}
+}
+
+func withGenAI(genAI *schema.GenAIInfo, edit func(*schema.GenAIInfo)) *schema.GenAIInfo {
+ if genAI == nil {
+ genAI = &schema.GenAIInfo{}
+ }
+ edit(genAI)
+ return genAI
+}
+
+func argumentsFrom(value interface{}) map[string]interface{} {
+ if m, ok := value.(map[string]interface{}); ok {
+ return m
+ }
+ if text, ok := value.(string); ok {
+ var args map[string]interface{}
+ if json.Unmarshal([]byte(text), &args) == nil {
+ return args
+ }
+ return map[string]interface{}{"raw": text}
+ }
+ return map[string]interface{}{}
+}
+
+func firstMap(data map[string]interface{}, keys ...string) map[string]interface{} {
+ for _, key := range keys {
+ if child, ok := data[key].(map[string]interface{}); ok {
+ return child
+ }
+ }
+ return nil
+}
+
+func firstPresent(data map[string]interface{}, keys ...string) interface{} {
+ for _, key := range keys {
+ if value, ok := data[key]; ok {
+ return value
+ }
+ }
+ return nil
+}
+
+func firstString(data map[string]interface{}, keys ...string) string {
+ for _, key := range keys {
+ if value, ok := data[key]; ok {
+ if text := strings.TrimSpace(textValue(value)); text != "" {
+ return text
+ }
+ }
+ }
+ return ""
+}
+
+func firstStringRaw(data map[string]interface{}, keys ...string) string {
+ for _, key := range keys {
+ if value, ok := data[key]; ok {
+ if text := textValue(value); text != "" {
+ return text
+ }
+ }
+ }
+ return ""
+}
+
+func textValue(value interface{}) string {
+ switch v := value.(type) {
+ case nil:
+ return ""
+ case string:
+ return v
+ case []interface{}:
+ parts := make([]string, 0, len(v))
+ for _, item := range v {
+ if text := textValue(item); text != "" {
+ parts = append(parts, text)
+ }
+ }
+ return strings.Join(parts, "\n")
+ case map[string]interface{}:
+ return firstNonEmpty(firstString(v, "text"), firstString(v, "content"), firstString(v, "value"))
+ default:
+ return fmt.Sprint(v)
+ }
+}
+
+func stringifyOutput(value interface{}) string {
+ if value == nil {
+ return ""
+ }
+ switch v := value.(type) {
+ case string:
+ return v
+ case map[string]interface{}:
+ if len(v) == 0 {
+ return ""
+ }
+ }
+ data, err := json.MarshalIndent(value, "", " ")
+ if err != nil {
+ return fmt.Sprint(value)
+ }
+ return string(data)
+}
+
+func firstNonEmpty(values ...string) string {
+ for _, value := range values {
+ if strings.TrimSpace(value) != "" {
+ return value
+ }
+ }
+ return ""
+}
+
+func int64Value(value interface{}) (int64, bool) {
+ switch v := value.(type) {
+ case float64:
+ return int64(v), v >= 0
+ case int64:
+ return v, v >= 0
+ case int:
+ return int64(v), v >= 0
+ case json.Number:
+ n, err := v.Int64()
+ return n, err == nil && n >= 0
+ case string:
+ n, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64)
+ return n, err == nil && n >= 0
+ default:
+ return 0, false
+ }
+}
+
+func int64OrZero(value interface{}) int64 {
+ n, _ := int64Value(value)
+ return n
+}
+
+func numberValue(value interface{}) interface{} {
+ switch v := value.(type) {
+ case nil:
+ return nil
+ case float64, int64, int, json.Number:
+ return v
+ case string:
+ if n, err := strconv.ParseFloat(strings.TrimSpace(v), 64); err == nil {
+ return n
+ }
+ }
+ return nil
+}
+
+func timestampMS(value interface{}, fallback int64) int64 {
+ switch v := value.(type) {
+ case float64:
+ if v < 1000000000000 {
+ return int64(v * 1000)
+ }
+ return int64(v)
+ case int64:
+ if v < 1000000000000 {
+ return v * 1000
+ }
+ return v
+ case string:
+ if n, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64); err == nil {
+ if n < 1000000000000 {
+ return n * 1000
+ }
+ return n
+ }
+ if ts, err := time.Parse(time.RFC3339Nano, v); err == nil {
+ return ts.UnixMilli()
+ }
+ if ts, err := time.Parse(time.RFC3339, v); err == nil {
+ return ts.UnixMilli()
+ }
+ }
+ return fallback
+}
+
+func recordSourcePath(ref SessionRef) string {
+ if ref.Path != "" {
+ return ref.Path
+ }
+ return filepath.Join(ref.Dir, EventsFile)
+}
+
+var copilotIDNamespace = [16]byte{
+ 0x91, 0x35, 0x6c, 0x20, 0x2f, 0x43, 0x4f, 0xb8,
+ 0xa7, 0x8e, 0xb2, 0x59, 0x15, 0x2c, 0x71, 0x09,
+}
+
+func copilotEventID(dedupID string) string {
+ digest := sha1.New()
+ digest.Write(copilotIDNamespace[:])
+ io.WriteString(digest, dedupID)
+ var id [16]byte
+ copy(id[:], digest.Sum(nil))
+ id[6] = (id[6] & 0x0f) | 0x50
+ id[8] = (id[8] & 0x3f) | 0x80
+ out := make([]byte, 32)
+ hex.Encode(out, id[:])
+ return fmt.Sprintf("%s-%s-%s-%s-%s", out[0:8], out[8:12], out[12:16], out[16:20], out[20:32])
+}
diff --git a/cli/beacon/internal/copilotsession/store.go b/cli/beacon/internal/copilotsession/store.go
new file mode 100644
index 00000000..7b93126f
--- /dev/null
+++ b/cli/beacon/internal/copilotsession/store.go
@@ -0,0 +1,209 @@
+package copilotsession
+
+import (
+ "bufio"
+ "bytes"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "io"
+ "io/fs"
+ "os"
+ "path/filepath"
+ "sort"
+ "strings"
+
+ "gopkg.in/yaml.v3"
+)
+
+type Store struct {
+ CopilotDir string
+ SessionStateDir string
+}
+
+func DefaultCopilotDir() (string, error) {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return "", fmt.Errorf("resolve home directory: %w", err)
+ }
+ if strings.TrimSpace(home) == "" {
+ return "", errors.New("home directory is empty")
+ }
+ return filepath.Join(home, ".copilot"), nil
+}
+
+func NewStore(copilotDir string) (*Store, error) {
+ root := strings.TrimSpace(copilotDir)
+ if root == "" {
+ def, err := DefaultCopilotDir()
+ if err != nil {
+ return nil, err
+ }
+ root = def
+ }
+ return &Store{CopilotDir: root, SessionStateDir: filepath.Join(root, "session-state")}, nil
+}
+
+func (s *Store) Exists() bool {
+ info, err := os.Stat(s.SessionStateDir)
+ return err == nil && info.IsDir()
+}
+
+func (s *Store) List() ([]SessionRef, error) {
+ var refs []SessionRef
+ entries, err := os.ReadDir(s.SessionStateDir)
+ if err != nil {
+ if errors.Is(err, fs.ErrNotExist) {
+ return nil, nil
+ }
+ return nil, fmt.Errorf("read GitHub Copilot CLI session directory: %w", err)
+ }
+ for _, entry := range entries {
+ if !entry.IsDir() {
+ continue
+ }
+ dir := filepath.Join(s.SessionStateDir, entry.Name())
+ path := filepath.Join(dir, EventsFile)
+ info, err := os.Stat(path)
+ if err != nil || info.IsDir() {
+ continue
+ }
+ ref := SessionRef{
+ ID: entry.Name(),
+ Path: path,
+ Dir: dir,
+ CopilotDir: s.CopilotDir,
+ ModTimeUnixMS: info.ModTime().UnixMilli(),
+ SizeBytes: info.Size(),
+ }
+ if meta := readWorkspaceMeta(filepath.Join(dir, WorkspaceFile)); meta != nil {
+ ref.Meta = meta
+ if strings.TrimSpace(meta.ID) != "" {
+ ref.ID = meta.ID
+ }
+ }
+ refs = append(refs, ref)
+ }
+ sort.SliceStable(refs, func(i, j int) bool {
+ if refs[i].ModTimeUnixMS != refs[j].ModTimeUnixMS {
+ return refs[i].ModTimeUnixMS < refs[j].ModTimeUnixMS
+ }
+ return refs[i].Path < refs[j].Path
+ })
+ return refs, nil
+}
+
+func (s *Store) Read(ref SessionRef) ([]Record, Stats, error) {
+ f, err := os.Open(ref.Path)
+ if err != nil {
+ return nil, Stats{}, err
+ }
+ defer f.Close()
+ return decodeRecords(f)
+}
+
+func decodeRecords(r io.Reader) ([]Record, Stats, error) {
+ br := bufio.NewReaderSize(r, 64*1024)
+ var records []Record
+ var stats Stats
+ lineNo := 0
+ for {
+ line, partial, oversized, err := readLine(br)
+ if err != nil {
+ if errors.Is(err, io.EOF) {
+ if partial {
+ stats.PartialTail = true
+ }
+ break
+ }
+ return records, stats, err
+ }
+ lineNo++
+ stats.Lines = lineNo
+ if oversized {
+ stats.Malformed++
+ if stats.FirstError == nil {
+ stats.FirstError = fmt.Errorf("GitHub Copilot CLI session line exceeds %d bytes", MaxLineBytes)
+ }
+ continue
+ }
+ if len(bytes.TrimSpace(line)) == 0 {
+ continue
+ }
+ record, err := decodeRecord(line, lineNo)
+ if err != nil {
+ stats.Malformed++
+ if stats.FirstError == nil {
+ stats.FirstError = err
+ }
+ continue
+ }
+ stats.Decoded++
+ records = append(records, *record)
+ }
+ return records, stats, nil
+}
+
+func readLine(br *bufio.Reader) (line []byte, partial, oversized bool, err error) {
+ var buf []byte
+ for {
+ chunk, readErr := br.ReadSlice('\n')
+ if oversized || len(buf)+len(chunk) > MaxLineBytes {
+ oversized = true
+ buf = nil
+ } else {
+ buf = append(buf, chunk...)
+ }
+ if errors.Is(readErr, bufio.ErrBufferFull) {
+ continue
+ }
+ if errors.Is(readErr, io.EOF) {
+ if oversized {
+ return nil, false, true, nil
+ }
+ if len(buf) > 0 {
+ return buf, true, false, io.EOF
+ }
+ return nil, false, false, io.EOF
+ }
+ if readErr != nil {
+ return nil, false, false, readErr
+ }
+ break
+ }
+ if oversized {
+ return nil, false, true, nil
+ }
+ return bytes.TrimSuffix(bytes.TrimSuffix(buf, []byte("\n")), []byte("\r")), false, false, nil
+}
+
+func decodeRecord(line []byte, lineNo int) (*Record, error) {
+ var record Record
+ if err := json.Unmarshal(line, &record); err != nil {
+ return nil, fmt.Errorf("GitHub Copilot CLI event line %d: %w", lineNo, err)
+ }
+ if strings.TrimSpace(record.Type) == "" {
+ return nil, fmt.Errorf("GitHub Copilot CLI event line %d: missing type", lineNo)
+ }
+ record.Line = lineNo
+ record.Raw = append(record.Raw[:0], line...)
+ if record.Data == nil {
+ record.Data = map[string]interface{}{}
+ }
+ return &record, nil
+}
+
+func readWorkspaceMeta(path string) *WorkspaceMeta {
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return nil
+ }
+ var meta WorkspaceMeta
+ if err := yaml.Unmarshal(data, &meta); err != nil {
+ return nil
+ }
+ if meta.ID == "" && meta.CWD == "" && meta.GitRoot == "" && meta.Repository == "" && meta.Branch == "" && meta.Name == "" {
+ return nil
+ }
+ return &meta
+}
diff --git a/cli/beacon/internal/copilotsession/types.go b/cli/beacon/internal/copilotsession/types.go
new file mode 100644
index 00000000..ba72ffb6
--- /dev/null
+++ b/cli/beacon/internal/copilotsession/types.go
@@ -0,0 +1,66 @@
+package copilotsession
+
+import (
+ "encoding/json"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
+)
+
+const (
+ Harness = "copilot_cli"
+ StateVersion = 1
+ MaxLineBytes = 8 * 1024 * 1024
+ EventsFile = "events.jsonl"
+ WorkspaceFile = "workspace.yaml"
+)
+
+type SessionRef struct {
+ ID string
+ Path string
+ Dir string
+ CopilotDir string
+ ModTimeUnixMS int64
+ SizeBytes int64
+ Meta *WorkspaceMeta
+}
+
+type WorkspaceMeta struct {
+ ID string `yaml:"id"`
+ CWD string `yaml:"cwd"`
+ GitRoot string `yaml:"git_root"`
+ Repository string `yaml:"repository"`
+ Branch string `yaml:"branch"`
+ Name string `yaml:"name"`
+ CreatedAt string `yaml:"created_at"`
+ UpdatedAt string `yaml:"updated_at"`
+ SummaryCount int `yaml:"summary_count"`
+}
+
+type Record struct {
+ Line int
+ ID string `json:"id"`
+ ParentID string `json:"parentId,omitempty"`
+ Time interface{} `json:"timestamp,omitempty"`
+ Type string `json:"type"`
+ Data map[string]interface{} `json:"data,omitempty"`
+ Raw json.RawMessage `json:"-"`
+}
+
+type Stats struct {
+ Lines int
+ Decoded int
+ Malformed int
+ PartialTail bool
+ FirstError error
+}
+
+type MappedEvent struct {
+ DedupID string
+ SourceLine int
+ Event schema.Event
+}
+
+type MapOptions struct {
+ MinLine int
+ SkipSessionStarted bool
+}
diff --git a/cli/beacon/internal/tokens/coverage.go b/cli/beacon/internal/tokens/coverage.go
index 4122b447..a2d1ad08 100644
--- a/cli/beacon/internal/tokens/coverage.go
+++ b/cli/beacon/internal/tokens/coverage.go
@@ -84,10 +84,10 @@ var usageExpectation = map[string]struct {
"openclaw_gateway": {ExpectReported, "plugin reports usage per model response when conversation access is granted"},
"vercel_fx": {ExpectReported, "session store carries cumulative usage and cost"},
"deepseek_harness": {ExpectReported, "native session backfill reports usage when DeepSeek persists it"},
+ "copilot_cli": {ExpectReported, "session store carries output tokens and cumulative model usage"},
"asymptote_observe": {ExpectReported, "SDK spans carry semconv usage"},
"gemini_cli": {ExpectGenericOTLP, "only if it emits OTel GenAI semconv usage"},
- "copilot_cli": {ExpectGenericOTLP, "only if it emits OTel GenAI semconv usage"},
"vscode_copilot": {ExpectGenericOTLP, "only if it emits OTel GenAI semconv usage"},
"factory": {ExpectGenericOTLP, "only if it emits OTel GenAI semconv usage"},
"factory_droid": {ExpectGenericOTLP, "only if it emits OTel GenAI semconv usage"},
diff --git a/docs/cli/endpoint-copilot.mdx b/docs/cli/endpoint-copilot.mdx
new file mode 100644
index 00000000..77745900
--- /dev/null
+++ b/docs/cli/endpoint-copilot.mdx
@@ -0,0 +1,102 @@
+---
+title: "beacon endpoint copilot"
+description: "Collect endpoint telemetry from GitHub Copilot CLI session records"
+---
+
+## Command overview
+
+`beacon endpoint copilot` collects telemetry from [GitHub Copilot CLI](/runtimes/github-copilot-cli) by reading the session records Copilot commits under `~/.copilot/session-state` and converting them into Beacon [endpoint events](/concepts/core-concepts#endpoint-event).
+
+```bash title="Command syntax"
+beacon endpoint copilot [command]
+```
+
+This complements Copilot's live OTLP export. OTLP carries live spans and approval-like permission activity; polling backfills assistant text, complete tool results, commands, file activity, and token usage from records already committed to disk.
+
+Every event from this command is marked `harness.collection_method=poll`. Beacon sees what Copilot wrote after the fact, so this path cannot hold, approve, deny, or delay a tool call, and it does not synthesize approval events.
+
+Reading is local and offline. Nothing this command does reaches the network.
+
+## Commands
+
+| Command | Description |
+|---------|-------------|
+| `beacon endpoint copilot sync` | Read new GitHub Copilot CLI session records into the runtime log |
+| `beacon endpoint copilot status` | Show Copilot CLI sessions on this machine and how much of each has been collected |
+
+## Flags
+
+Both subcommands accept:
+
+| Flag | Description |
+|------|-------------|
+| `--copilot-dir <path>` | GitHub Copilot CLI directory. Defaults to `~/.copilot` |
+| `--state <path>` | Collector cursor file. Defaults to `~/.beacon/endpoint/state/copilot.json` |
+| `--workspace <path>` | Only include sessions whose recorded cwd matches this workspace |
+| `--session-id <id>` | Only include one Copilot CLI session id |
+| `--json` | Print the result as JSON |
+| `--user` | Use per-user endpoint paths. Enabled by default |
+| `--system` | Use system endpoint paths. The cursor moves beside the system runtime log |
+
+`sync` also accepts:
+
+| Flag | Description |
+|------|-------------|
+| `--log-path <path>` | Runtime JSONL log path. Defaults to the resolved endpoint log |
+| `--print` | Print mapped events as JSON without writing them or advancing the cursor |
+| `--watch` | Sweep continuously on `--interval` instead of sweeping once and exiting |
+| `--interval <duration>` | Sweep interval for `--watch`. Defaults to `1m`, with a 5-second floor |
+
+## Sweeping
+
+```bash title="Sweep once"
+beacon endpoint copilot sync
+```
+
+```bash title="Preview without writing anything"
+beacon endpoint copilot sync --print
+```
+
+`--print` is a dry run in both directions: it neither writes the runtime log nor advances the cursor, so running it twice shows the same events and running it does not quietly consume the work a later real sweep would do.
+
+```bash title="Sweep continuously"
+beacon endpoint copilot sync --watch --interval 5m
+```
+
+Nothing sweeps on its own. Run `sync` under whatever scheduler the platform already uses, or leave `--watch` running in the account that owns `~/.copilot`.
+
+## Status
+
+```bash title="Show Copilot CLI sessions and collection progress"
+beacon endpoint copilot status
+```
+
+```text
+GitHub Copilot CLI sessions: 2 in /Users/you/.copilot/session-state
+ caab1e17-... collected line 42/42 /Users/you/src/app
+ edbb2d48-... pending line 0/18 /Users/you/src/api
+```
+
+`collected` means the cursor is level with the complete records Beacon decoded from that session's `events.jsonl`. A partly written trailing record is left for the next sweep and reported as pending rather than treated as corruption.
+
+## Cursor behavior
+
+The cursor is what keeps a scheduled sweep from re-appending every session's whole history. It stores the last decoded line per `events.jsonl` file, plus file size and modification time for cheap no-op sweeps.
+
+| Mode | Default cursor path |
+|------|--------------------|
+| User | `~/.beacon/endpoint/state/copilot.json` |
+| System | `copilot-state.json` beside the system runtime log |
+
+Re-reading is safe: each event's id comes from the source file, session id, line number, and mapped event suffix, so the same Copilot record maps to the same event every time.
+
+## Related
+
+<Columns cols={2}>
+ <Card title="GitHub Copilot CLI" icon="code" href="/runtimes/github-copilot-cli">
+ Telemetry coverage, discovery, and known gaps for the runtime.
+ </Card>
+ <Card title="beacon endpoint discover" icon="magnifying-glass" href="/cli/endpoint-discover">
+ Check whether Copilot CLI is detected and whether live OTLP is configured.
+ </Card>
+</Columns>
diff --git a/docs/cli/token-usage.mdx b/docs/cli/token-usage.mdx
index 30e22a1e..fb02e619 100644
--- a/docs/cli/token-usage.mdx
+++ b/docs/cli/token-usage.mdx
@@ -46,18 +46,18 @@ Token coverage is not uniform, and the reason is almost always the runtime rathe
| Oh My Pi | input, output, cache read, cache creation, reasoning | Reported (`cost_usd`) | Yes | Yes |
| Prime Agent | input, output, cache read, cache creation, reasoning | Reported (`cost_usd`) | Yes | Yes |
| fx (Vercel Labs) | input, output, cache read, cache creation | Reported (`cost_usd`) | Yes | Yes |
+| GitHub Copilot CLI | input, output, cache read, cache creation, reasoning | Not reported | Yes | Yes |
| OpenClaw Gateway | input, output, cache read, cache creation | Not reported on the hook | Yes, per model response | Yes |
OpenClaw reports usage on its `llm_output` hook, which is a *conversation* hook -- OpenClaw withholds those from every non-bundled plugin until `plugins.entries.beacon-endpoint.hooks.allowConversationAccess` is set in its config. An OpenClaw endpoint collecting prompts, tools, commands and files while reporting no tokens at all is almost always that key, and `beacon endpoint hooks status --harness openclaw` says so. OpenClaw does compute a per-turn price, from an operator-configured cost table rather than from a provider report, so Beacon does not record it as a reported cost. See [OpenClaw Gateway](/runtimes/openclaw-gateway).
-Cline reports usage once per task rather than per model call, because Beacon's rollups sum `gen_ai.usage` across events and reporting at both granularities would count every token twice. fx reports cumulative totals, which Beacon differences into per-turn deltas for the same reason.
+Cline reports usage once per task rather than per model call, because Beacon's rollups sum `gen_ai.usage` across events and reporting at both granularities would count every token twice. fx reports cumulative totals, which Beacon differences into per-turn deltas for the same reason. GitHub Copilot CLI reports assistant message output tokens and cumulative shutdown model totals; Beacon records the message output directly, then differences shutdown totals for input, cache, reasoning, and any output not already counted.
**Collected through the generic OpenTelemetry path, not yet verified against captured payloads:**
| Runtime | Status |
|---------|--------|
| Gemini CLI | Usage is captured when the runtime emits the OTel GenAI semconv names (`gen_ai.usage.*` attributes, or a `gen_ai.client.token.usage` metric split by `token_type`). The generic path is tested; these runtimes' own payloads have not been captured and pinned. |
-| GitHub Copilot CLI | As above |
| VS Code Copilot | As above |
| Factory Droid | As above |
| Grok Bot | Reaches Beacon only through Cursor's server-side OpenTelemetry export, so usage arrives only if that export carries the semconv names |
diff --git a/docs/docs.json b/docs/docs.json
index e1abdebb..9175ad29 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -296,6 +296,7 @@
"cli/endpoint-onboarding",
"cli/endpoint-opencode",
"cli/endpoint-pi",
+ "cli/endpoint-copilot",
"cli/endpoint-fx",
"cli/endpoint-traces",
"cli/dashboard",
diff --git a/docs/runtimes/github-copilot-cli.mdx b/docs/runtimes/github-copilot-cli.mdx
index 2a9e0459..c7406429 100644
--- a/docs/runtimes/github-copilot-cli.mdx
+++ b/docs/runtimes/github-copilot-cli.mdx
@@ -5,7 +5,7 @@ description: "Beacon support details for GitHub Copilot CLI endpoint telemetry"
## Runtime overview
-Beacon supports GitHub Copilot CLI through MDM-managed OpenTelemetry export to the local OTLP HTTP receiver.
+Beacon supports GitHub Copilot CLI through MDM-managed OpenTelemetry export to the local OTLP HTTP receiver, plus offline polling of Copilot's local session records.
## Prerequisites
@@ -16,17 +16,22 @@ Before enabling GitHub Copilot CLI telemetry, make sure:
- The Copilot CLI launch environment sets `COPILOT_OTEL_ENABLED=true`.
- The Copilot CLI launch environment sets `OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318` or `COPILOT_OTEL_ENDPOINT=http://127.0.0.1:4318`.
- Copilot CLI is restarted after launch-environment changes so new sessions use the updated settings.
+- For local session backfill, Copilot CLI has written sessions under `~/.copilot/session-state`.
## Collection path
GitHub Copilot CLI exports OTLP HTTP telemetry to Beacon's local collector. Beacon normalizes Copilot spans into endpoint events for prompt submission, session activity, tool invocation, and approval-like permission activity.
+Beacon can also read committed session records from `~/.copilot/session-state` through [`beacon endpoint copilot sync`](/cli/endpoint-copilot). Polling backfills assistant text, complete tool results, command and file activity, and Copilot's persisted token usage. Every event from that path is marked `harness.collection_method=poll`, so readers can tell it was observed after Copilot committed the record rather than during the live tool call.
+
Copilot CLI metrics are filtered from the local runtime JSONL log by default so endpoint timelines stay focused on user and agent activity. Use `--include-runtime-metrics` during install or repair only when you need low-level Copilot metrics for troubleshooting.
## Discovery and status
Beacon detects GitHub Copilot CLI through the `copilot` executable or `~/.copilot/config.json`. Use `beacon endpoint discover` or `beacon endpoint status` to confirm that Copilot CLI is present and exporting to Beacon's local OTLP HTTP receiver.
+Use `beacon endpoint copilot status` to inspect local session files and see how far the poll cursor has collected them.
+
Beacon reports Copilot CLI telemetry as configured only when `COPILOT_OTEL_ENABLED` is truthy and the effective OTLP endpoint points to `localhost` or `127.0.0.1`. If `COPILOT_OTEL_FILE_EXPORTER_PATH` is configured, Beacon reports Copilot as misconfigured because the file exporter bypasses the local OTLP collector.
## Install or configuration support
@@ -54,9 +59,12 @@ For a one-command local validation flow, see [Test GitHub Copilot CLI telemetry]
| Area | Support |
|------|---------|
-| Prompt telemetry | Supported from Copilot chat spans when exported over OTLP HTTP |
-| Command, tool, and file telemetry | Supported for session activity, tool invocation, and permission or approval-like spans emitted by Copilot CLI |
-| Local JSONL and dashboard | Supported after events reach the local collector |
+| Prompt telemetry | Supported from Copilot chat spans over OTLP HTTP and from local session polling |
+| Assistant text | Supported from local session polling |
+| Command, tool, and file telemetry | OTLP covers live tool and approval-like activity. Polling reconstructs complete tool calls/results, commands, and file reads or writes from session records |
+| Approvals | Supported from live OTLP permission activity. Polling does not synthesize approval decisions |
+| Token usage | Supported from local session polling. Assistant message output tokens are recorded directly; shutdown model totals are differenced for input, cache, and reasoning usage |
+| Local JSONL and dashboard | Supported after events reach the local runtime log |
| MDM deployment | Supported for the endpoint agent. Copilot launch-environment configuration stays under MDM or customer policy control |
## Deployment notes
@@ -65,6 +73,8 @@ Copilot CLI currently exports OTLP over HTTP, not gRPC. Point it at Beacon's HTT
Beacon validates the effective Copilot environment but does not write Copilot shell profiles or `~/.copilot/config.json`. Keep Copilot CLI outside the default Beacon harness list, and deploy its environment settings with the same MDM or shell-management mechanism you use to launch Copilot.
+To backfill local session records, schedule `beacon endpoint copilot sync` in the logged-in user's context or leave it running with `--watch`. Nothing sweeps on its own.
+
## Related
<Columns cols={2}>
@@ -74,4 +84,7 @@ Beacon validates the effective Copilot environment but does not write Copilot sh
<Card title="Endpoint install" icon="download" href="/cli/endpoint-install">
Configure the local collector before enabling Copilot CLI export.
</Card>
+ <Card title="beacon endpoint copilot" icon="clock-rotate-left" href="/cli/endpoint-copilot">
+ Backfill local Copilot CLI session records.
+ </Card>
</Columns>
diff --git a/docs/runtimes/index.mdx b/docs/runtimes/index.mdx
index fe7baa68..ee60e90c 100644
--- a/docs/runtimes/index.mdx
+++ b/docs/runtimes/index.mdx
@@ -31,7 +31,7 @@ These integrations are grouped by where the agent runs and how telemetry is coll
| [Factory Droid](/runtimes/factory-droid) | OTLP HTTP, optional hooks, and poll of `~/.factory/sessions` through `beacon endpoint factory sync` | OTLP/hooks: session, prompt, write/edit/create tool use, stop, session-end, and available OTLP telemetry. Poll: historical session records committed by Factory |
| [fx (Vercel Labs)](/runtimes/vercel-fx) | Poll of fx's own session records under `~/.fx/sessions` through `beacon endpoint fx sync` | Session start, prompts, tool calls, commands with exit codes and output, file reads and edits with diffs, MCP tool calls, agent messages, history compaction, and token usage and cost. No approval or session-end telemetry, because fx persists neither |
| [Gemini CLI](/runtimes/gemini-cli) | Opt-in local OTLP | Prompts, tool calls, MCP activity, file operations, and approval-related events emitted through OTLP |
-| [GitHub Copilot CLI](/runtimes/github-copilot-cli) | MDM-managed OTLP HTTP | Prompt, session, tool, and approval-like activity emitted through Copilot CLI spans |
+| [GitHub Copilot CLI](/runtimes/github-copilot-cli) | MDM-managed OTLP HTTP plus poll of `~/.copilot/session-state` through `beacon endpoint copilot sync` | OTLP: prompt, session, tool, and approval-like activity emitted through Copilot CLI spans. Poll: assistant text, complete tool results, commands, files, and token usage from committed session records |
| [goose](/runtimes/goose) | Adapter only today: manually written plugin hooks in `.agents/plugins/`, plus manually configured local OTLP export over HTTP | Hooks: session start and end, prompts, pre-tool and post-tool activity, failed tools, command lines, file creates and edits with diffs, and MCP tool calls. OTLP adds token usage, model and provider, response ids, and agent reasoning. No automatic installer/discovery yet, no tool output of any kind on the hook path, and no approval decisions because goose exposes none of those on a hook |
| [Grok Build](/runtimes/grok-build) | Native hooks plus optional poll of `~/.grok/sessions` through `beacon endpoint grok sync` | Hooks: session, prompt, pre-tool, post-tool, failed tool, stop, session-end, command, and file telemetry. Poll: historical committed sessions, tool activity, commands, file activity, and compaction where persisted |
| [Kiro](/runtimes/kiro) | Native hooks through a Beacon-owned file in `.kiro/hooks/` | Session start, prompts, pre-tool and post-tool activity, commands with output, file reads and edits, MCP tool calls, failed tools, and the agent's final response. No approval decisions or token usage, because Kiro exposes neither on a hook |
@@ -121,7 +121,7 @@ MDM assets, meaning Jamf Pro Extension Attributes, Fleet osquery queries, and Ri
| fx (Vercel Labs) | Nothing to configure in fx. Schedule [`beacon endpoint fx sync`](/cli/endpoint-fx) in the logged-in user's context, or leave `--watch` running, so committed sessions keep reaching the runtime log. Nothing sweeps on its own. |
| OpenCode | Install the managed plugin for live telemetry with `beacon endpoint hooks install --harness opencode`. To backfill committed local sessions, schedule [`beacon endpoint opencode sync`](/cli/endpoint-opencode) in the logged-in user's context or leave `--watch` running. |
| Pi | Install the managed extension for live telemetry with `beacon endpoint hooks install --harness pi`. To backfill committed local sessions, schedule [`beacon endpoint pi sync`](/cli/endpoint-pi) in the logged-in user's context or leave `--watch` running. |
-| GitHub Copilot CLI | Configure launch environment through MDM or customer policy: `COPILOT_OTEL_ENABLED=true` and `OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318`. Beacon validates the endpoint but does not edit shell profiles or launch environments. |
+| GitHub Copilot CLI | Configure launch environment through MDM or customer policy: `COPILOT_OTEL_ENABLED=true` and `OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318`. Beacon validates the endpoint but does not edit shell profiles or launch environments. To backfill committed sessions, schedule [`beacon endpoint copilot sync`](/cli/endpoint-copilot) in the logged-in user's context or leave `--watch` running. |
| Factory Droid | Configure launch environment with `OTEL_TELEMETRY_ENDPOINT=http://127.0.0.1:4318`. Beacon discovers the runtime and validates the endpoint but does not edit shell profiles or launch environments. To backfill committed sessions, schedule `beacon endpoint factory sync` in the logged-in user's context or leave `--watch` running. |
| Grok Build | Install hooks with `beacon endpoint hooks install --harness grok`. To backfill committed local sessions, schedule `beacon endpoint grok sync` in the logged-in user's context or leave `--watch` running. |
| Hermes Agent | Install hooks with `beacon endpoint hooks install --harness hermes`. To backfill committed sessions from `~/.hermes/state.db`, schedule `beacon endpoint hermes sync` in the logged-in user's context or leave `--watch` running. |
diff --git a/docs/runtimes/integration-model.mdx b/docs/runtimes/integration-model.mdx
index e5654ea0..259b18d5 100644
--- a/docs/runtimes/integration-model.mdx
+++ b/docs/runtimes/integration-model.mdx
@@ -46,7 +46,7 @@ During install, Beacon configures the runtime surfaces it can safely manage:
| [Codex CLI](/runtimes/codex-cli) | Beacon points Codex CLI at the local OTLP collector, writes log and trace exporter tables to `~/.codex/config.toml`, enables prompt logging, retains one usage-bearing turn span, and installs a metadata-only SessionStart identity hook. Historical sessions can be backfilled with `beacon endpoint codex sync`. |
| [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. |
+| [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. Committed sessions can be backfilled with `beacon endpoint copilot sync`. |
| [Factory Droid](/runtimes/factory-droid) | Droid's OTLP endpoint remains under its launch environment, commonly managed through MDM or another customer-owned policy. Committed sessions can be backfilled with `beacon endpoint factory sync`. |
| [OpenClaw Gateway](/runtimes/openclaw-gateway) | Configure OpenClaw with the `diagnostics-otel` plugin. Beacon prints local OTLP/HTTP setup guidance and validates observed events. Committed session files can be backfilled with `beacon endpoint integrations openclaw sessions sync`. |
| [fx (Vercel Labs)](/runtimes/vercel-fx) | Nothing is installed or configured. fx has no hook file, plugin directory, or OTLP endpoint, so collection is an action: run or schedule [`beacon endpoint fx sync`](/cli/endpoint-fx). |
@@ -59,7 +59,7 @@ During install, Beacon configures the runtime surfaces it can safely manage:
| [Claude Code](/runtimes/claude-code) | Local OTLP export, optional hooks, and poll of `~/.claude/projects` | OTLP and hooks are the live paths. `beacon endpoint claude sync` reads committed transcripts for backfill and marks those events `harness.collection_method=poll`. |
| [Codex CLI](/runtimes/codex-cli) | Local OTLP logs, selective turn traces, SessionStart hook, and poll of `~/.codex/sessions` | Beacon writes structured Codex OTLP config, filters noisy internal spans, and joins OS-user context to per-turn usage. `beacon endpoint codex sync` backfills committed sessions as poll events. |
| [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. |
+| [GitHub Copilot CLI](/runtimes/github-copilot-cli) | MDM-managed OTLP HTTP export plus poll of `~/.copilot/session-state` | Beacon validates Copilot's effective launch environment and maps Copilot spans into prompt, session, tool, and approval-like endpoint events. `beacon endpoint copilot sync` backfills committed session records as poll events with assistant text, complete tool results, commands, file activity, and token usage. |
| [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. |
| [Antigravity CLI](/runtimes/antigravity-cli) | Native hook payloads through `beacon-hooks` | Beacon writes a managed Antigravity hook block and maps prompt, pre-tool, post-tool, invocation, command, file edit, and diff telemetry into endpoint events. |
| [Grok Build](/runtimes/grok-build) | Native hook payloads through `beacon-hooks`, plus poll of `~/.grok/sessions` | Beacon writes an owned Grok hook file and maps session, prompt, tool, command, file, and failed-tool events into endpoint events. `beacon endpoint grok sync` backfills committed sessions as poll events. |