github / github/copilot-cli

Feature Request: Formalize events.jsonl as an official hook/integration API

未关闭
#3,551 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area:plugins area:sessions
主要语言
Shell
星标
11.2k
派生
1.9k
平均合并
14 小时 16 分钟
30 天内合并 PR
6

描述

## Summary

Copilot CLI already writes a rich, machine-readable event stream to `~/.copilot/session-state/{id}/events.jsonl` for every session. This file contains 20+ event types covering the full session lifecycle (task completion, user prompts, tool invocations, sub-agent activity, context compaction, model changes, etc.).

**This is effectively a zero-configuration hook system** — external tools can watch this file and react to events without any plugin API, registration, or modification to Copilot CLI itself.

## Proposal

Formalize `events.jsonl` as a **supported, documented external integration surface** with:

1. **Official documentation** of the event schema (types, data fields, guarantees)
2. **Stability contract** — which event types/fields are stable vs. internal/experimental
3. **Versioning** — a schema version field so consumers can handle format changes gracefully
4. **Best practices guide** for external consumers (file sharing mode, incremental reading, offset tracking)

## Why This Matters

Several community tools already consume this file for:
- **Toast notifications** when a task completes (the `session.task_complete` event even includes a natural-language summary)
- **Real-time activity indicators** (Working/Idle/NeedsInput/Problem states)
- **Session dashboards** and monitoring UIs
- **Webhook integration** (forward completion events to Slack, etc.)
- **Cost tracking** via `session.compaction_complete` token counts

Without documentation or stability guarantees, these integrations are fragile — any internal change to event formats could silently break them.

## Current Event Types (observed in v1.0.54)

| Event Type | Description |
|---|---|
| `session.start` | Session began (includes version, cwd, model) |
| `session.task_complete` | Agent finished work (**includes summary text**) |
| `session.shutdown` | Session ended permanently |
| `session.model_change` | Model switched |
| `session.mode_changed` | Mode changed (autopilot, etc.) |
| `session.plan_changed` | Implementation plan updated |
| `session.compaction_start/complete` | Context compaction (token counts) |
| `assistant.turn_start/end` | Agent reasoning turns |
| `assistant.message` | Agent output |
| `user.message` | User submitted prompt |
| `tool.execution_start/complete` | Tool invocations (includes tool name, args, success) |
| `subagent.started/completed` | Fleet agents |
| `skill.invoked` | Skill triggered |
| `hook.start/end` | Internal hooks |
| `abort` | User cancelled |

## Comparison to Claude Code Hooks

Claude Code requires explicit hook registration in `~/.claude/settings.json` and only fires 2 events (Stop, UserPromptSubmit). Copilot CLI's events.jsonl is **richer (20+ events), requires zero setup, and includes contextual data** like task summaries and token counts. The only tradeoff is ~1-2s detection latency vs. instant script invocation.

## Reference Implementation

I've documented the full pattern with code examples (PowerShell, C#, Node.js) and 10 use-case ideas:
https://gist.github.com/RockNoggin/8cc87f640ce5e3d284298a6db21f7523

## Ask

- Document the event schema officially
- Declare which events/fields are stable for external consumption
- Add a schema version to the JSON line format
- Consider adding a simple `session.idle` event (agent finished turn, no pending tool calls) to make done detection even easier for simple consumers

贡献指南

打开贡献指南

调研方向

Start by reviewing the event stream at ~/.copilot/session-state/{id}/events.jsonl and the referenced integration examples in the linked gist. Define the documented schema, stability and versioning expectations, and consumer guidance; done means external consumers have an official, durable integration contract.

由索引模型根据 Issue 内容生成。

评估

技术栈
json
领域
api, cli, documentation
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。