github / github/copilot-cli

Feature: Emit a dedicated event when user switches to a custom agent via /agent

未關閉
#2,838 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
area:agents area:sessions
主要語言
Shell
星號
11.2k
分支
1.9k
平均合併
14 小時 16 分鐘
30 天內合併 PR
6

描述

## Summary

When a user invokes `/agent ` to switch to a custom agent at the session root, no dedicated event is emitted. The only signal that an agent switch occurred is the `` block silently prepended to `user.message.data.transformedContent`. This makes it difficult for downstream tooling to reliably track which custom agent is active.

## Current behavior

- `/agent review-pr-comments` rewrites the next user message by prepending `...` into `transformedContent`
- There is no `session.agent_changed` or `session.agent_invoked` event in `events.jsonl`
- `subagent.selected` exists but fires rarely (21 events across 920+ sessions in one user's history) and doesn't appear to be the canonical marker for root-level `/agent` switches
- `session.mode_changed` and `session.model_change` exist for other session-level state changes, but agents have no equivalent

## Impact

- **Session analytics**: Tools like [copilot-session-tools](https://github.com/Arithmomaniac/copilot-session-tools) that enrich `events.jsonl` into queryable databases cannot reliably count or filter by which custom agent was used. The only workaround is parsing `` blocks out of `transformedContent`, which is fragile and undocumented.
- **Skill auditing**: When auditing skill/agent effectiveness, the lack of a clean event means agent usage counts are dramatically undercounted (in one audit, `review-pr-comments` showed 0 dispatches via `task` tool but actually had 390 root-level invocations hidden in `transformedContent`).
- **Observability**: Users and platform teams can't answer "which custom agents are actually being used?" without deep parsing of message content.

## Proposed solution

Emit a new event when `/agent ` is invoked at the session root:

```jsonl
{"type": "session.agent_invoked", "agentName": "review-pr-comments", "agentSource": "user", "timestamp": "..."}
```

Fields:
- `agentName`: The agent identifier as it appears in the `.agent.md` filename
- `agentSource`: `"user"` for custom agents in `~/.copilot/agents/`, `"project"` for repo-level agents, `"builtin"` for platform agents

This would parallel the existing `session.mode_changed` and `session.model_change` events.

## Workaround (current)

Parse `transformedContent` for `` blocks and extract the agent name — but this is fragile, undocumented, and requires access to the full message payload rather than just the event stream.

貢獻指南

開啟貢獻指南

研究方向

先定位根層級的 /agent 指令處理邏輯,以及現有的 session.mode_changed 和 session.model_change 事件發射器。加入提議的 session.agent_invoked 事件,其中包含 agentName、agentSource 和 timestamp,然後驗證在 session 根層級呼叫 /agent 會在 events.jsonl 中產生該事件,而不依賴對 transformedContent 的解析。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
shell
領域
cli, observability
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。