Skip to content

feat(v2): agent tracking — 数据契约 + Session 元数据扩展 #16

Description

@monster-echo

背景

用户在 Corterm PTY 里最常跑 Claude Code / Codex / OpenCode,但目前 session 名字是 `sess_{Guid}` 完全无业务含义,且 agent 内部活动(prompt / tool call / cost)对用户不可见。

本 issue 是 Agent Tracking 主线工作的 Phase 1:奠定数据模型基础。完整设计见 plan 文件。

范围

新契约(`src/Shared/CortexTerminal.Contracts/`):

  • `Sessions/AgentDtos.cs`:`AgentKind` enum (None/ClaudeCode/Codex/OpenCode)、`AgentRuntimeInfo` record
  • `Streaming/AgentActivityFrames.cs`:`AgentStartedFrame`、`AgentPromptSubmittedFrame`、`AgentToolCallFrame`、`AgentStoppedFrame`

Session 表扩展(`SessionRecordEntity.cs`):

  • 加 `AgentKind` (string, nullable)
  • 加 `AgentSessionId` (string, nullable) — agent 自己的内部 session id(如 Claude Code 的 UUID)
  • 加 `InferredTitle` (string, nullable) — 自动从首条 prompt 派生

新表(`SessionAgentEventEntity.cs`):

  • 字段:`Id / SessionId / EventType / Payload(jsonb) / CreatedAtUtc`
  • 索引:`(SessionId, CreatedAtUtc)`

Migration:`AddAgentTracking`

验收

  • migration up/down 都干净
  • 契约类型被 Gateway / Worker / Console 同时能引用
  • 现有 session 表的旧数据迁移后 `AgentKind=null`,不影响 v1 行为
  • 单元测试覆盖 AgentKind 枚举序列化

依赖

无前置依赖。是 #17 #18 #19 #20 的基础。

不做的事

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions