This document describes the local Copilot CLI session ingestion feature added to gh-agent-viz.
gh-agent-viz now supports ingesting local Copilot CLI sessions from ~/.copilot/session-state/*/workspace.yaml in addition to remote agent sessions fetched via the Copilot API (with gh agent-task CLI fallback).
A new Session type unifies both agent-task and local Copilot sessions:
type Session struct {
ID string
Status string
Title string
Repository string
Branch string
PRURL string
PRNumber int
CreatedAt time.Time
UpdatedAt time.Time
Source SessionSource // "agent-task" or "local-copilot"
}
Two session sources are supported via the SessionSource enum:
SourceAgentTask: GitHub agent sessions fetched via Copilot API (or gh agent-task CLI fallback)SourceLocalCopilot: Local Copilot CLI sessions from ~/.copilot/session-state/The local session parser implements tolerant parsing with fallback behavior:
This ensures the TUI never crashes due to malformed session files.
Local session status is derived using DeriveLocalSessionStatus():
| Input Statuses | Normalized Output |
|---|---|
| completed, finished, done, merged, closed | completed |
| running, in progress, active, open | running |
| failed, error, cancelled, canceled | failed |
| queued, pending, waiting | queued |
When no explicit status is provided or status is unknown:
completedrunningunknownfunc FetchLocalSessions() ([]Session, error)
Fetches all local Copilot CLI sessions from ~/.copilot/session-state/. Returns an empty list (not an error) if the directory doesn’t exist.
func FetchAllSessions(repo string) ([]Session, error)
Fetches both agent-task (via CAPI or CLI fallback) and local sessions. Filters by repository if specified. This is the recommended API for fetching all available sessions.
func FromAgentTask(task AgentTask) Session
func (s Session) ToAgentTask() AgentTask
Conversion functions maintain backward compatibility with existing code that expects AgentTask objects.
All functionality is covered by tests:
Run tests with:
go test ./internal/data/...
Expected workspace.yaml structure (all fields optional except session_id):
session_id: "abc123-session"
start_time: "2026-02-15T03:10:00Z"
last_activity: "2026-02-15T03:30:00Z"
message_count: 15
status: "completed"
repository: "owner/repo"
branch: "main"
title: "Session title"
conversation_history:
- role: user
content: "First message"
All existing agent-task functionality remains unchanged:
FetchAgentTasks() still works as beforeFetchAgentTaskDetail() still works as beforeFetchAgentTaskLog() still works as beforeAgentTask type still exists for backward compatibilitygh agent-task view --log)Possible future improvements: