mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
feat(prompt): 重新注册 bash,把"不要用 bash 搜索"写进工具描述
真实会话里模型仍习惯性先调 bash grep,被拒后才改用 grep 工具;系统提示词里已有 4 处 提醒,但模型下调用决定时看的是工具 schema 描述,而 Pi 内置 bash 描述对此只字未提。 - 新增 extensions/bash-override.ts:用 Pi 的 createBashToolDefinition 重新注册 bash, 执行、输出结构与 codemode 说明完全沿用上游;shellPath/commandPrefix 按 ctx.cwd 经 SettingsManager 惰性解析,与内置一致 - tools.jsonc 新增 descriptionAppend 字段,由 prompt-guard 注册时拼接到上游描述后 - bash 增加命令→工具对照规则(grep -n / grep -rl / find -name),并提示 文件清单用 $(git ls-files) 传参、不要接 xargs(会触发权限审核) 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
2b21163a18
commit
87940da51a
@@ -1,11 +1,28 @@
|
||||
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
||||
|
||||
import { loadToolCatalog, type ToolCatalog } from "./system-prompt-config.ts";
|
||||
import {
|
||||
loadToolCatalog,
|
||||
type ToolCatalog,
|
||||
type ToolCatalogEntry,
|
||||
} from "./system-prompt-config.ts";
|
||||
|
||||
type AnyMessage = { role?: string; content?: unknown } & Record<string, unknown>;
|
||||
|
||||
type AnyHandler = (event: never, ctx: never) => unknown;
|
||||
|
||||
/**
|
||||
* The description a tool registers with under its catalog entry: a `description`
|
||||
* override replaces the upstream text, a `descriptionAppend` is joined onto
|
||||
* whichever base wins (override first, upstream otherwise) with a blank line.
|
||||
*/
|
||||
export function catalogDescription(description: string, entry: ToolCatalogEntry): string {
|
||||
if ("inherit" in entry) return description;
|
||||
const base = typeof entry.description === "string" ? entry.description : description;
|
||||
return typeof entry.descriptionAppend === "string"
|
||||
? `${base.trimEnd()}\n\n${entry.descriptionAppend}`
|
||||
: base;
|
||||
}
|
||||
|
||||
export interface PromptGuardOptions {
|
||||
/**
|
||||
* Post-process the messages a wrapped `context` handler leaves behind.
|
||||
@@ -19,9 +36,11 @@ export interface PromptGuardOptions {
|
||||
* Proxy an `ExtensionAPI` for third-party extensions so they cannot bypass the
|
||||
* bundle's single system-prompt owner (`extensions/system-prompt.ts`):
|
||||
*
|
||||
* - `registerTool` applies the tool's `description` override from
|
||||
* `config/prompt/tools.jsonc` when the catalog carries one (lazily loaded;
|
||||
* a catalog error keeps the upstream description).
|
||||
* - `registerTool` applies the tool's `description` override and
|
||||
* `descriptionAppend` suffix from `config/prompt/tools.jsonc` when the
|
||||
* catalog carries them (lazily loaded; a catalog error keeps the upstream
|
||||
* description). An append composes onto the override when both are set, or
|
||||
* onto the upstream description when only the append is set.
|
||||
* - `before_agent_start` handlers keep every returned field except
|
||||
* `systemPrompt`, which is dropped.
|
||||
* - `context` handlers are post-processed through `opts.contextFilter`.
|
||||
@@ -42,10 +61,12 @@ export function guardExtensionApi(pi: ExtensionAPI, opts: PromptGuardOptions = {
|
||||
|
||||
const registerTool: ExtensionAPI["registerTool"] = (tool) => {
|
||||
const entry = catalog()?.tools[tool.name];
|
||||
if (entry !== undefined && !("inherit" in entry) && typeof entry.description === "string") {
|
||||
pi.registerTool({ ...tool, description: entry.description });
|
||||
} else {
|
||||
const description =
|
||||
entry === undefined ? tool.description : catalogDescription(tool.description, entry);
|
||||
if (description === tool.description) {
|
||||
pi.registerTool(tool);
|
||||
} else {
|
||||
pi.registerTool({ ...tool, description });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user