pi-distill 0.4.3 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/README.zh-CN.md +7 -7
- package/locales/fallback-renderer.json +5 -5
- package/locales/index.json +14 -14
- package/package.json +6 -2
- package/src/fallback-renderer.ts +2 -2
- package/src/index.ts +26 -30
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ The distillation prompt strictly follows the current locale selected by `/pi-lan
|
|
|
29
29
|
## How it works
|
|
30
30
|
|
|
31
31
|
- Observes `bash`, `read`, `grep`, and `find` through Pi's native `tool_call` / `tool_result` events.
|
|
32
|
-
- Uses the tool's `
|
|
32
|
+
- Uses the tool's `outputRequest` as the source of truth for whether and how to distill a result.
|
|
33
33
|
- Treats a prompt containing only `RAW` as an explicit request for the original output.
|
|
34
34
|
- Uses the current session model by default, or a configured `provider/model` override.
|
|
35
35
|
- Keeps diagnostic metadata such as status, character counts, compression ratio, duration, and anomalies in the tool result details.
|
|
@@ -65,7 +65,7 @@ We are not trying to make the agent see less information. We are trying to avoid
|
|
|
65
65
|
The execution layer should preserve facts. The consumption layer should control context cost. `pi-distill` connects the two:
|
|
66
66
|
|
|
67
67
|
- the tool executes and returns facts;
|
|
68
|
-
- the agent states what it cares about through `
|
|
68
|
+
- the agent states what it cares about through `outputRequest`;
|
|
69
69
|
- the extension reads the actual result before deciding whether to call a distillation model;
|
|
70
70
|
- the model compresses the consumption path without changing the tool's semantics;
|
|
71
71
|
- diagnostics show whether the transformation actually saved context.
|
|
@@ -98,7 +98,7 @@ Savings are not the only metric. The extension records duration, original and re
|
|
|
98
98
|
|
|
99
99
|
```text
|
|
100
100
|
Agent states a handling goal
|
|
101
|
-
↓ through
|
|
101
|
+
↓ through outputRequest
|
|
102
102
|
Tool runs the real operation and returns stdout / stderr / files / media
|
|
103
103
|
↓
|
|
104
104
|
pi-distill uses the actual result and configuration to keep it, distill it, or write it to a file
|
|
@@ -106,15 +106,15 @@ pi-distill uses the actual result and configuration to keep it, distill it, or w
|
|
|
106
106
|
Agent consumes a result suited to the current decision, with auditable diagnostics
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
1. At session start, the extension adds required `
|
|
109
|
+
1. At session start, the extension adds required `outputRequest` to every active tool whose parameter schema is an object. It does not hard-code `bash`, `read`, `grep`, or `find`.
|
|
110
110
|
2. The `tool_call` handler captures the parameter and removes it before forwarding the call, so the underlying tool never receives the extension-only field.
|
|
111
111
|
3. The `tool_result` handler sees the actual output and decides what to do; it does not rely on the agent predicting the output size.
|
|
112
|
-
4. Every tool call must include a non-empty `
|
|
112
|
+
4. Every tool call must include a non-empty `outputRequest`. A prompt containing only `RAW` explicitly requests the original. Any other non-empty prompt permits distillation once the configured threshold is reached.
|
|
113
113
|
5. If distillation fails, no model is available, or compression is ineffective, the original facts are retained and the status is exposed through details and the audit card.
|
|
114
114
|
|
|
115
115
|
## Output contract
|
|
116
116
|
|
|
117
|
-
| `
|
|
117
|
+
| `outputRequest` | Behavior | Use it when |
|
|
118
118
|
| --- | --- | --- |
|
|
119
119
|
| Omitted | Invalid tool call; Pi rejects the call before the underlying tool runs | Never omit it; use `RAW` when no compression is explicitly requested |
|
|
120
120
|
| Exactly `RAW` (case-insensitive) | Skip the distillation model and keep the complete original text; oversized text is returned through a file path | You need to inspect, copy, or verify exact output |
|
|
@@ -134,7 +134,7 @@ The distillation prompt strictly follows the locale selected by `/pi-language`:
|
|
|
134
134
|
|
|
135
135
|
## Scope and boundaries
|
|
136
136
|
|
|
137
|
-
- Handles every active tool with an object parameter schema; whether `
|
|
137
|
+
- Handles every active tool with an object parameter schema; whether `outputRequest` can be injected is determined by the tool schema, not a fixed allowlist.
|
|
138
138
|
- Registers no replacement tools, does not change tool execution semantics, and does not require a separately installed `pi-tool-display` host package.
|
|
139
139
|
- Text distillation is lossy; use `RAW` when completeness matters.
|
|
140
140
|
- Non-text results are a completeness boundary: images, audio, binary data, and mixed content bypass text distillation.
|
package/README.zh-CN.md
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
## 工作方式
|
|
30
30
|
|
|
31
31
|
- 通过 Pi 原生的 `tool_call` / `tool_result` 事件监听 `bash`、`read`、`grep` 和 `find`。
|
|
32
|
-
- 以工具的 `
|
|
32
|
+
- 以工具的 `outputRequest` 作为是否提炼、如何提炼的依据。
|
|
33
33
|
- 当提示词严格只有 `RAW` 时,视为明确要求返回原始输出。
|
|
34
34
|
- 默认使用当前会话模型,也可以配置独立的 `provider/model`。
|
|
35
35
|
- 在工具结果 details 中保留状态、字符数、压缩比、耗时和异常等诊断信息。
|
|
@@ -65,7 +65,7 @@ pi install npm:pi-distill
|
|
|
65
65
|
工具执行层需要保留完整事实;Agent 消费层需要控制上下文成本。`pi-distill` 在两者之间增加一个可选的结果处理层:
|
|
66
66
|
|
|
67
67
|
- 工具负责执行并返回事实;
|
|
68
|
-
- Agent 通过 `
|
|
68
|
+
- Agent 通过 `outputRequest` 表达自己关心什么;
|
|
69
69
|
- 扩展读取真实输出后,再决定是否调用提炼模型;
|
|
70
70
|
- 模型只压缩消费路径,不改变原工具的业务语义;
|
|
71
71
|
- 诊断信息记录这次处理是否真的节省了上下文。
|
|
@@ -100,7 +100,7 @@ pi install npm:pi-distill
|
|
|
100
100
|
|
|
101
101
|
```text
|
|
102
102
|
Agent 提出处理目标
|
|
103
|
-
↓ 通过
|
|
103
|
+
↓ 通过 outputRequest 传给工具
|
|
104
104
|
工具执行真实操作,返回 stdout / stderr / 文件内容 / 多媒体结果
|
|
105
105
|
↓
|
|
106
106
|
pi-distill 根据真实结果和配置决定:原样返回、调用模型提炼,或写入文件
|
|
@@ -108,15 +108,15 @@ pi-distill 根据真实结果和配置决定:原样返回、调用模型提炼
|
|
|
108
108
|
Agent 消费更适合当前决策的结果,并获得可审计的处理诊断
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
1. 扩展在会话启动时为所有已启用、参数 schema 为 object 的工具增加必填的 `
|
|
111
|
+
1. 扩展在会话启动时为所有已启用、参数 schema 为 object 的工具增加必填的 `outputRequest` 参数,不写死 `bash`、`read`、`grep` 或 `find`。
|
|
112
112
|
2. `tool_call` 事件捕获这个参数,并在交给底层工具前移除它,因此原工具不会收到扩展专用字段。
|
|
113
113
|
3. `tool_result` 事件拿到真实输出后再做判断,不依赖 Agent 对输出长度的预测。
|
|
114
|
-
4. 每次工具调用都必须包含非空的 `
|
|
114
|
+
4. 每次工具调用都必须包含非空的 `outputRequest`;严格的 `RAW` 表示明确要求原文;其他非空 prompt 才允许进入提炼流程。
|
|
115
115
|
5. 提炼失败、没有可用模型或结果收益过低时,扩展保留原始事实,并通过 details 和审计卡片暴露状态。
|
|
116
116
|
|
|
117
117
|
## 输出处理契约
|
|
118
118
|
|
|
119
|
-
| `
|
|
119
|
+
| `outputRequest` | 行为 | 适用场景 |
|
|
120
120
|
| --- | --- | --- |
|
|
121
121
|
| 未提供 | 工具调用无效;Pi 会在底层工具执行前拒绝该调用 | 不要省略;未明确要求压缩时使用 `RAW` |
|
|
122
122
|
| 严格为 `RAW`(大小写不敏感) | 不调用提炼模型,保留完整原始文本;如超出返回上限则返回原文文件路径 | 逐字核对、复制内容、需要完整日志时 |
|
|
@@ -136,7 +136,7 @@ Agent 消费更适合当前决策的结果,并获得可审计的处理诊断
|
|
|
136
136
|
|
|
137
137
|
## 覆盖范围与边界
|
|
138
138
|
|
|
139
|
-
- 自动处理所有当前已启用且参数 schema 为 object 的工具;能否注入 `
|
|
139
|
+
- 自动处理所有当前已启用且参数 schema 为 object 的工具;能否注入 `outputRequest` 由工具 schema 决定,不维护固定工具名单。
|
|
140
140
|
- 不注册替代工具,不改变原工具的执行语义,也不要求额外安装独立的 `pi-tool-display` 宿主包。
|
|
141
141
|
- 文本提炼是有损操作;完整性要求应使用 `RAW`。
|
|
142
142
|
- 非文本结果是完整性边界:图片、音频、二进制和混合 content 不进入文本提炼链路。
|
|
@@ -55,10 +55,6 @@
|
|
|
55
55
|
"zh-CN": "◆ Distill {status}",
|
|
56
56
|
"en-US": "◆ Distill {status}"
|
|
57
57
|
},
|
|
58
|
-
"prompt": {
|
|
59
|
-
"zh-CN": "Prompt",
|
|
60
|
-
"en-US": "Prompt"
|
|
61
|
-
},
|
|
62
58
|
"summary": {
|
|
63
59
|
"zh-CN": "摘要",
|
|
64
60
|
"en-US": "Summary"
|
|
@@ -74,5 +70,9 @@
|
|
|
74
70
|
"error": {
|
|
75
71
|
"zh-CN": "错误",
|
|
76
72
|
"en-US": "Error"
|
|
73
|
+
},
|
|
74
|
+
"outputRequest": {
|
|
75
|
+
"zh-CN": "outputRequest",
|
|
76
|
+
"en-US": "outputRequest"
|
|
77
77
|
}
|
|
78
|
-
}
|
|
78
|
+
}
|
package/locales/index.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"zh-CN": "
|
|
4
|
-
"en-US": "Required
|
|
2
|
+
"outputRequestDescription": {
|
|
3
|
+
"zh-CN": "必填:由 Agent 在每次工具调用时传入,说明你希望本次工具调用返回什么内容。绝不能省略、传 null 或空字符串。两种模式必须让 Agent 自主决策:需要完整原始结果时严格传 RAW(不区分大小写的三个 ASCII 字母);需要节省 token 或只关心部分信息时,传一个描述性 prompt,让提炼模型提取你需要的那部分。对于 bash 等执行命令的工具,若只需要编译或测试的通过/失败和错误摘要,请使用描述性 prompt;需要完整日志、完整提取语法/参数/SQL,或逐行调试时才使用 RAW。不要使用“完整输出”或“完整提取”等自然语言作为值;该字段不会传给底层工具。",
|
|
4
|
+
"en-US": "Required: the Agent must pass this on every tool call to describe what it wants the tool to return. Never omit it, use null, or use an empty string. The Agent must actively choose one of two modes: use exactly RAW (the three ASCII letters, case-insensitive) when the full original result is needed; otherwise pass a descriptive prompt so the distiller extracts only the information you need, saving tokens. For command-execution tools such as bash, use a descriptive prompt when you only need pass/fail and an error summary; use RAW for full logs, complete syntax/parameter/SQL extraction, or line-by-line debugging. Do not use natural-language values such as \"full output\" or \"complete extraction\"; this field is removed before the underlying tool runs."
|
|
5
5
|
},
|
|
6
|
-
"
|
|
7
|
-
"zh-CN": "
|
|
8
|
-
"en-US": "MANDATORY:
|
|
9
|
-
},
|
|
10
|
-
"outputPromptSystemGuideline": {
|
|
11
|
-
"zh-CN": "强制工具调用规则:每次调用任何带有 outputPrompt 的工具时,都必须在 arguments 中包含 outputPrompt。绝不能省略、传 null 或空字符串。普通 grep/read/find/ls 调用默认使用 outputPrompt=RAW;只有用户明确要求摘要或压缩时,才传描述性 outputPrompt。RAW 必须是严格的三个 ASCII 字母。",
|
|
12
|
-
"en-US": "MANDATORY tool-call rule: Whenever a tool exposes outputPrompt, include outputPrompt in the arguments of every call. Never omit it, use null, or use an empty string. For ordinary grep/read/find/ls calls, default to outputPrompt=RAW; use a descriptive outputPrompt only when the user explicitly asks for summarization or compression. RAW must be exactly the three ASCII letters."
|
|
6
|
+
"outputRequestSystemGuideline": {
|
|
7
|
+
"zh-CN": "强制工具调用规则:每次调用任何带有 outputRequest 的工具时,Agent 都必须在 arguments 中通过 outputRequest 自主决策需要返回什么内容。绝不能省略、传 null 或空字符串。两种模式:需要完整原始输出时传 RAW;需要节省 token 或只提取部分信息时传描述性 outputRequest。RAW 必须是严格的三个 ASCII 字母。",
|
|
8
|
+
"en-US": "MANDATORY tool-call rule: whenever a tool exposes outputRequest, the Agent must include outputRequest in the arguments of every call and use it to actively decide what to return. Never omit it, use null, or use an empty string. Two modes: use RAW when the full original output is needed; use a descriptive outputRequest when you want to save tokens or extract only part of the result. RAW must be exactly the three ASCII letters."
|
|
13
9
|
},
|
|
14
10
|
"positiveInteger": {
|
|
15
11
|
"zh-CN": "请输入大于 0 的整数。",
|
|
@@ -87,9 +83,9 @@
|
|
|
87
83
|
"zh-CN": "审计渲染器:{value}",
|
|
88
84
|
"en-US": "Audit renderer: {value}"
|
|
89
85
|
},
|
|
90
|
-
"
|
|
91
|
-
"zh-CN": "显示
|
|
92
|
-
"en-US": "Show
|
|
86
|
+
"showOutputRequest": {
|
|
87
|
+
"zh-CN": "显示 outputRequest:{value}",
|
|
88
|
+
"en-US": "Show outputRequest: {value}"
|
|
93
89
|
},
|
|
94
90
|
"showSummary": {
|
|
95
91
|
"zh-CN": "显示摘要:{value}",
|
|
@@ -118,5 +114,9 @@
|
|
|
118
114
|
"commandDescription": {
|
|
119
115
|
"zh-CN": "交互式配置工具输出提炼",
|
|
120
116
|
"en-US": "Configure tool-output distillation interactively"
|
|
117
|
+
},
|
|
118
|
+
"outputRequest": {
|
|
119
|
+
"zh-CN": "outputRequest",
|
|
120
|
+
"en-US": "outputRequest"
|
|
121
121
|
}
|
|
122
|
-
}
|
|
122
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-distill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Pi tool-output distillation with file-first configuration",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"main": "./index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.ts"
|
|
9
|
+
},
|
|
6
10
|
"files": [
|
|
7
11
|
"index.ts",
|
|
8
12
|
"src",
|
|
@@ -53,7 +57,7 @@
|
|
|
53
57
|
"pi-extensions-i18n": "^0.3.0"
|
|
54
58
|
},
|
|
55
59
|
"dependencies": {
|
|
56
|
-
"pi-extensions-tool-display": "^0.
|
|
60
|
+
"pi-extensions-tool-display": "^1.0.0"
|
|
57
61
|
},
|
|
58
62
|
"devDependencies": {
|
|
59
63
|
"@earendil-works/pi-ai": "0.80.10",
|
package/src/fallback-renderer.ts
CHANGED
|
@@ -195,7 +195,7 @@ export function buildDistillAuditLines(
|
|
|
195
195
|
const toolExecutionMs = getFiniteNumber(details.toolExecutionMs);
|
|
196
196
|
const summaryDurationMs = getFiniteNumber(details.summaryDurationMs);
|
|
197
197
|
const fullOutputPath = getString(details.fullOutputPath);
|
|
198
|
-
const
|
|
198
|
+
const outputRequest = getString(details.outputSummaryPrompt);
|
|
199
199
|
const summaryText = getString(details.summaryText);
|
|
200
200
|
const statusView = statusViews[status] ?? { label: status, tone: "muted" as const };
|
|
201
201
|
const metrics: string[] = [];
|
|
@@ -220,7 +220,7 @@ export function buildDistillAuditLines(
|
|
|
220
220
|
];
|
|
221
221
|
if (expanded) {
|
|
222
222
|
const sections: Array<{ label: string; text: string }> = [];
|
|
223
|
-
if (render.showPrompt &&
|
|
223
|
+
if (render.showPrompt && outputRequest) sections.push({ label: i18n.t("outputRequest"), text: outputRequest });
|
|
224
224
|
if (render.showResult && summaryText) sections.push({ label: i18n.t("summary"), text: summaryText });
|
|
225
225
|
if (fullOutputPath) sections.push({ label: i18n.t("file"), text: fullOutputPath });
|
|
226
226
|
if (anomalies.length > 0) sections.push({ label: i18n.t("warning"), text: anomalies.join(", ") });
|
package/src/index.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* 通过 Pi 的工具事件处理所有可扩展工具的结果,并在会话启动时原地扩展
|
|
5
5
|
* 最终生效工具的参数 schema。不注册同名工具,也不争夺工具所有权。
|
|
6
6
|
*
|
|
7
|
-
* 所有工具统一使用
|
|
8
|
-
*
|
|
7
|
+
* 所有工具统一使用 outputRequest:严格传入 RAW 时返回原始输出;其他非空
|
|
8
|
+
* outputRequest 表示调用提炼模型,具体保留内容由 outputRequest 决定。
|
|
9
9
|
* 提炼结果超过 maxChars 时写入临时文件,只返回文件路径。
|
|
10
10
|
*
|
|
11
11
|
* 配置文件优先;旧环境变量继续兼容:
|
|
@@ -74,7 +74,7 @@ type DistillExecutionContext = {
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
type PendingDistillCall = {
|
|
77
|
-
|
|
77
|
+
outputRequest: string;
|
|
78
78
|
originalUserPrompt?: string;
|
|
79
79
|
startedAt: number;
|
|
80
80
|
};
|
|
@@ -85,9 +85,8 @@ type ToolResultEventPatch = {
|
|
|
85
85
|
isError?: boolean;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
export const
|
|
89
|
-
|
|
90
|
-
const OUTPUT_PROMPT_SYSTEM_GUIDELINE = i18n.t("outputPromptSystemGuideline");
|
|
88
|
+
export const OUTPUT_REQUEST_DESCRIPTION = i18n.t("outputRequestDescription");
|
|
89
|
+
const OUTPUT_REQUEST_SYSTEM_GUIDELINE = i18n.t("outputRequestSystemGuideline");
|
|
91
90
|
|
|
92
91
|
type SummaryResult = {
|
|
93
92
|
text: string;
|
|
@@ -311,9 +310,9 @@ async function summarizeOutput(
|
|
|
311
310
|
};
|
|
312
311
|
}
|
|
313
312
|
|
|
314
|
-
function
|
|
315
|
-
return typeof params.
|
|
316
|
-
? params.
|
|
313
|
+
function getOutputRequest(params: Record<string, unknown>): string {
|
|
314
|
+
return typeof params.outputRequest === "string"
|
|
315
|
+
? params.outputRequest.trim()
|
|
317
316
|
: "";
|
|
318
317
|
}
|
|
319
318
|
|
|
@@ -322,7 +321,7 @@ async function processToolResult(
|
|
|
322
321
|
result: ToolResult,
|
|
323
322
|
toolExecutionMs: number,
|
|
324
323
|
): Promise<ToolResult> {
|
|
325
|
-
const prompt =
|
|
324
|
+
const prompt = getOutputRequest(context.params);
|
|
326
325
|
const loaded = loadDistillConfig();
|
|
327
326
|
const config = loaded.config;
|
|
328
327
|
const outputSummaryRender = { ...loaded.render };
|
|
@@ -528,15 +527,15 @@ async function processToolResult(
|
|
|
528
527
|
}
|
|
529
528
|
}
|
|
530
529
|
|
|
531
|
-
function
|
|
530
|
+
function extendOutputRequestParameter(tool: ToolInfo): boolean {
|
|
532
531
|
const parameters = tool.parameters as unknown as Record<string, unknown> | undefined;
|
|
533
532
|
if (!parameters || typeof parameters !== "object" || Array.isArray(parameters)) {
|
|
534
|
-
console.warn(`[pi-distill] Could not extend the ${tool.name} parameter schema;
|
|
533
|
+
console.warn(`[pi-distill] Could not extend the ${tool.name} parameter schema; outputRequest is unavailable.`);
|
|
535
534
|
return false;
|
|
536
535
|
}
|
|
537
536
|
|
|
538
537
|
if (parameters.type !== "object") {
|
|
539
|
-
console.warn(`[pi-distill] Could not extend the ${tool.name} parameter schema;
|
|
538
|
+
console.warn(`[pi-distill] Could not extend the ${tool.name} parameter schema; outputRequest is unavailable.`);
|
|
540
539
|
return false;
|
|
541
540
|
}
|
|
542
541
|
|
|
@@ -544,29 +543,26 @@ function extendOutputPromptParameter(tool: ToolInfo): boolean {
|
|
|
544
543
|
if (properties === undefined) {
|
|
545
544
|
parameters.properties = {};
|
|
546
545
|
} else if (typeof properties !== "object" || properties === null || Array.isArray(properties)) {
|
|
547
|
-
console.warn(`[pi-distill] Could not extend the ${tool.name} parameter schema;
|
|
546
|
+
console.warn(`[pi-distill] Could not extend the ${tool.name} parameter schema; outputRequest is unavailable.`);
|
|
548
547
|
return false;
|
|
549
548
|
}
|
|
550
549
|
|
|
551
|
-
(parameters.properties as Record<string, unknown>).
|
|
550
|
+
(parameters.properties as Record<string, unknown>).outputRequest = {
|
|
552
551
|
type: "string",
|
|
553
|
-
|
|
554
|
-
description: tool.name === "bash"
|
|
555
|
-
? BASH_OUTPUT_PROMPT_DESCRIPTION
|
|
556
|
-
: OUTPUT_PROMPT_DESCRIPTION,
|
|
552
|
+
description: OUTPUT_REQUEST_DESCRIPTION,
|
|
557
553
|
};
|
|
558
554
|
const required = Array.isArray(parameters.required)
|
|
559
555
|
? parameters.required.filter((value): value is string =>
|
|
560
|
-
typeof value === "string" && value !== "
|
|
556
|
+
typeof value === "string" && value !== "outputRequest")
|
|
561
557
|
: [];
|
|
562
|
-
parameters.required = [...required, "
|
|
558
|
+
parameters.required = [...required, "outputRequest"];
|
|
563
559
|
return true;
|
|
564
560
|
}
|
|
565
561
|
|
|
566
562
|
export function extendDistillToolParameters(pi: Pick<ExtensionAPI, "getAllTools">): number {
|
|
567
563
|
let extended = 0;
|
|
568
564
|
for (const tool of pi.getAllTools()) {
|
|
569
|
-
if (
|
|
565
|
+
if (extendOutputRequestParameter(tool)) extended += 1;
|
|
570
566
|
}
|
|
571
567
|
return extended;
|
|
572
568
|
}
|
|
@@ -663,7 +659,7 @@ async function runDistillConfigUi(ctx: ExtensionCommandContext, configPath: stri
|
|
|
663
659
|
i18n.t("threshold", { value: config.missedCompressionRatio }),
|
|
664
660
|
i18n.t("summarizeErrors", { value: config.summarizeErrors ? i18n.t("on") : i18n.t("off") }),
|
|
665
661
|
i18n.t("auditRenderer", { value: config.render.enabled ? i18n.t("on") : i18n.t("off") }),
|
|
666
|
-
i18n.t("
|
|
662
|
+
i18n.t("showOutputRequest", { value: config.render.showPrompt ? i18n.t("on") : i18n.t("off") }),
|
|
667
663
|
i18n.t("showSummary", { value: config.render.showResult ? i18n.t("on") : i18n.t("off") }),
|
|
668
664
|
];
|
|
669
665
|
const choice = await ctx.ui.select(i18n.t("settingsTitle"), choices);
|
|
@@ -746,7 +742,7 @@ export default function piDistillExtension(pi: ExtensionAPI) {
|
|
|
746
742
|
try {
|
|
747
743
|
extendDistillToolParameters(pi);
|
|
748
744
|
} catch (error) {
|
|
749
|
-
console.warn(`[pi-distill] Failed to extend the
|
|
745
|
+
console.warn(`[pi-distill] Failed to extend the outputRequest parameter: ${error instanceof Error ? error.message : String(error)}`);
|
|
750
746
|
}
|
|
751
747
|
};
|
|
752
748
|
|
|
@@ -757,28 +753,28 @@ export default function piDistillExtension(pi: ExtensionAPI) {
|
|
|
757
753
|
return {
|
|
758
754
|
systemPrompt: [
|
|
759
755
|
typeof event.systemPrompt === "string" ? event.systemPrompt : "",
|
|
760
|
-
`<output-prompt-contract>\n${
|
|
756
|
+
`<output-prompt-contract>\n${OUTPUT_REQUEST_SYSTEM_GUIDELINE}\n</output-prompt-contract>`,
|
|
761
757
|
].filter((value) => value.length > 0).join("\n\n"),
|
|
762
758
|
};
|
|
763
759
|
});
|
|
764
760
|
pi.on("tool_call", (event) => {
|
|
765
761
|
pendingCalls.set(event.toolCallId, {
|
|
766
|
-
|
|
762
|
+
outputRequest: getOutputRequest(event.input),
|
|
767
763
|
originalUserPrompt,
|
|
768
764
|
startedAt: performance.now(),
|
|
769
765
|
});
|
|
770
|
-
//
|
|
771
|
-
delete (event.input as Record<string, unknown>).
|
|
766
|
+
// outputRequest 只控制结果处理,不能泄漏给底层内置工具。
|
|
767
|
+
delete (event.input as Record<string, unknown>).outputRequest;
|
|
772
768
|
});
|
|
773
769
|
pi.on("tool_result", async (event: ToolResultEvent, ctx) => {
|
|
774
770
|
const pending = pendingCalls.get(event.toolCallId);
|
|
775
771
|
pendingCalls.delete(event.toolCallId);
|
|
776
|
-
const
|
|
772
|
+
const outputRequest = pending?.outputRequest ?? getOutputRequest(event.input);
|
|
777
773
|
const result = await processToolResult(
|
|
778
774
|
{
|
|
779
775
|
toolName: event.toolName,
|
|
780
776
|
toolCallId: event.toolCallId,
|
|
781
|
-
params: { ...event.input,
|
|
777
|
+
params: { ...event.input, outputRequest },
|
|
782
778
|
originalUserPrompt: pending?.originalUserPrompt ?? originalUserPrompt,
|
|
783
779
|
ctx,
|
|
784
780
|
},
|