mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
feat(pi-overflow): 新增统一的新工具结果展示截断扩展
此前截断分散在多层且互相冲突:Pi bash 保留尾部 50KB,RTK 兜底截断又只留 开头 12000 字符(砍掉报错与完整输出路径),pi-chrome 截开头 30K,web_fetch 各 provider 不一致。新扩展统一负责"新结果给模型看多少": - capture.ts 最先加载暂存原文,index.ts 最后加载(system-prompt 之前) - 超过 24K 字符时原文落盘 <agentDir>/my-pi/pi-overflow/(700/600、原子写), 优先取 bash fullOutputPath 完整文件;模型看到 头 + 中段信号行 + 尾 的有界 视图,行号基于落盘原文、结尾永远可见 - overflow_query:按 id 正则搜索、行区间、jsonPath 只读查询,id 校验防穿越 - 收编:RTK truncate 默认关闭、删除 pi-chrome truncateText、web_fetch 默认 每页 20000(上限 100000)、web_search max_results 限定 1–20 - pi-compaction 遮蔽带 details.overflow.id 的结果时在占位符提示 overflow_query - 登记 tools.jsonc / routing / 权限 allow / tool-search 常驻与分组 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent
a6d8416c76
commit
2a6bf8c929
@@ -21,5 +21,6 @@
|
||||
- click/type/fill/key 上的 `includeSnapshot=true` 会保存动作后的快照并返回其捕获路径,而不是把快照嵌入工具结果。
|
||||
- 授权后的 `before_agent_start` 不再返回 `systemPrompt`:Chrome 使用提示写入 `event.systemPromptOptions.sections.chrome_profile_bridge` 结构化分区,由组合包单一提示词出口 `extensions/system-prompt.ts` 统一组装,顺序由 `config/prompt/sections.jsonc` 控制;未授权时不贡献任何提示词内容。
|
||||
- 移除 `PI_CHROME_BRIDGE_HOST`/`PI_CHROME_BRIDGE_PORT` 环境变量,host/port 固定为 `127.0.0.1:17318`(Companion 扩展 `service_worker.js` 同样硬编码该地址,单侧可配只会断连且非回环 host 有安全风险)。
|
||||
- 移除 `MAX_TEXT_CHARS`/`truncateText` 的 30K 字符文本截断:chrome_* 工具返回完整文本,超长结果的展示截断由 pi-overflow 统一负责;`MAX_ELEMENTS` 等条数上限保留不变。
|
||||
|
||||
同步上游时,请以导入 commit 为基准比较并选择性移植改动。不得整体覆盖这些本地生命周期、隐私和 Context Mode 集成。
|
||||
|
||||
@@ -67,14 +67,8 @@ const PI_CHROME_AUTH_KEY = "__piChromeProfileBridgeAuth__";
|
||||
const DEFAULT_HOST = "127.0.0.1";
|
||||
const DEFAULT_PORT = 17318;
|
||||
const DEFAULT_TIMEOUT_MS = 30_000;
|
||||
const MAX_TEXT_CHARS = 30_000;
|
||||
const MAX_ELEMENTS = 80;
|
||||
|
||||
function truncateText(text: string, maxChars = MAX_TEXT_CHARS): string {
|
||||
if (text.length <= maxChars) return text;
|
||||
return `${text.slice(0, maxChars)}\n\n[truncated ${text.length - maxChars} characters]`;
|
||||
}
|
||||
|
||||
function safeJson(value: unknown): string {
|
||||
return JSON.stringify(value, null, 2);
|
||||
}
|
||||
@@ -142,7 +136,7 @@ function formatChromeInspect(inspect: any): string {
|
||||
lines.push("\n## Ancestors");
|
||||
for (const a of inspect.ancestors.slice(0, 6)) lines.push(`- ${a.uid} ${a.role || a.tag} ${compactLine(a.label || a.selector, 120)}`);
|
||||
}
|
||||
return truncateText(lines.join("\n"));
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function extensionRoot(): string {
|
||||
@@ -1512,7 +1506,7 @@ Usage rules:
|
||||
: typeof value === "string"
|
||||
? value
|
||||
: safeJson(value) ?? "undefined";
|
||||
return { content: [{ type: "text", text: truncateText(text) }], details: { value: value as Json } };
|
||||
return { content: [{ type: "text", text }], details: { value: value as Json } };
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1691,7 +1685,7 @@ Usage rules:
|
||||
}),
|
||||
async execute(_id, params, signal): Promise<ToolTextResult> {
|
||||
const result = await authorizedBridgeSend("page.console.list", withBackground(params), DEFAULT_TIMEOUT_MS, signal);
|
||||
return { content: [{ type: "text", text: truncateText(safeJson(result)) }], details: { result: result as Json } };
|
||||
return { content: [{ type: "text", text: safeJson(result) }], details: { result: result as Json } };
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1713,7 +1707,7 @@ Usage rules:
|
||||
}),
|
||||
async execute(_id, params, signal): Promise<ToolTextResult> {
|
||||
const result = await authorizedBridgeSend("page.network.list", withBackground(params), DEFAULT_TIMEOUT_MS, signal);
|
||||
return { content: [{ type: "text", text: truncateText(safeJson(result)) }], details: { result: result as Json } };
|
||||
return { content: [{ type: "text", text: safeJson(result) }], details: { result: result as Json } };
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1733,7 +1727,7 @@ Usage rules:
|
||||
}),
|
||||
async execute(_id, params, signal): Promise<ToolTextResult> {
|
||||
const result = await authorizedBridgeSend("page.network.get", withBackground(params), DEFAULT_TIMEOUT_MS, signal);
|
||||
return { content: [{ type: "text", text: truncateText(safeJson(result)) }], details: { result: result as Json } };
|
||||
return { content: [{ type: "text", text: safeJson(result) }], details: { result: result as Json } };
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user