github / github/copilot-cli

Extension onPostToolUse modifiedResult is not applied to the model's conversation context

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

描述

## Summary

When a Copilot CLI extension returns `modifiedResult` from `onPostToolUse`, the modified text appears in the TUI tool-result preview line but is **not** applied to the model's conversation context. The model sees and responds with the original unmodified tool result.

## Reproduction

Minimal single-file extension (`.github/extensions/repro/extension.mjs`):

```js
import { joinSession } from "@github/copilot-sdk/extension";

joinSession({
tools: [
{
name: "say_hello",
description: "Returns a greeting message",
parameters: { type: "object", properties: {} },
async handler() {
return "ORIGINAL: The tool returned this text.";
},
},
],
hooks: {
async onPostToolUse(input) {
if (input.toolName !== "say_hello") return {};
return {
modifiedResult: {
textResultForLlm: "MODIFIED: The hook replaced the result with this text.",
resultType: "success",
},
};
},
},
});
```

### Steps

1. Place the above in a git repo under `.github/extensions/repro/extension.mjs`
2. Run `copilot --allow-all` from the repo root
3. Ask: "call say_hello and tell me exactly what it returned"

### Expected

The model reports: `MODIFIED: The hook replaced the result with this text.`

### Actual

The TUI tool-result preview correctly shows:
```
● say_hello
└ MODIFIED: The hook replaced the result with this text.
```

But the model responds with: `ORIGINAL: The tool returned this text.`

## Observations

- The hook **does** fire — stderr logging in the hook confirms execution.
- The TUI preview line shows the **modified** text.
- The model responds with the **original** text.
- This suggests the hook's `modifiedResult` is applied to the display layer but not to the model's message history.

## Impact

Any extension relying on `onPostToolUse` + `modifiedResult` for result transformation (sanitization, redaction, enrichment) is silently broken. The hook appears to work from the TUI, but the model operates on original data.

## Environment

- Copilot CLI 1.0.49-1
- Windows 11

贡献指南

打开贡献指南

调研方向

从 .github/extensions/repro/extension.mjs 中的复现开始,跟踪 onPostToolUse 对 modifiedResult 的处理过程,从 hook 经过工具结果预览,再到模型对话上下文。确认原始结果是在何处进入消息历史的。当模型报告修改后的文本,同时 TUI 预览保持正确时,即表示完成。

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

评估

技术栈
javascript
领域
cli
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

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