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:
云服务部-叶林立
2026-10-22 01:20:52 -07:00
co-authored by Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent 2b21163a18
commit 87940da51a
11 changed files with 226 additions and 28 deletions
+15 -7
View File
@@ -10,7 +10,12 @@ import { fileURLToPath } from "node:url";
/** Entry in `config/prompt/tools.jsonc`. */
export type ToolCatalogEntry =
| { inherit: true }
| { snippet?: string | null; guidelines?: string[]; description?: string };
| {
snippet?: string | null;
guidelines?: string[];
description?: string;
descriptionAppend?: string;
};
export interface ToolCatalog {
version: 1;
@@ -152,7 +157,7 @@ function isStringArray(value: unknown): value is string[] {
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
}
const TOOL_ENTRY_KEYS = new Set(["inherit", "snippet", "guidelines", "description"]);
const TOOL_ENTRY_KEYS = new Set(["inherit", "snippet", "guidelines", "description", "descriptionAppend"]);
function validateToolEntry(name: string, raw: unknown): ToolCatalogEntry {
if (!isPlainObject(raw)) {
@@ -170,9 +175,9 @@ function validateToolEntry(name: string, raw: unknown): ToolCatalogEntry {
return { inherit: true };
}
const hasField =
"snippet" in raw || "guidelines" in raw || "description" in raw;
"snippet" in raw || "guidelines" in raw || "description" in raw || "descriptionAppend" in raw;
if (!hasField) {
fail("tools.jsonc", `tool "${name}" needs "inherit": true or at least one of snippet/guidelines/description`);
fail("tools.jsonc", `tool "${name}" needs "inherit": true or at least one of snippet/guidelines/description/descriptionAppend`);
}
if ("snippet" in raw && raw.snippet !== null && typeof raw.snippet !== "string") {
fail("tools.jsonc", `tool "${name}".snippet must be a string or null`);
@@ -183,10 +188,13 @@ function validateToolEntry(name: string, raw: unknown): ToolCatalogEntry {
if ("description" in raw && typeof raw.description !== "string") {
fail("tools.jsonc", `tool "${name}".description must be a string`);
}
if ("descriptionAppend" in raw && typeof raw.descriptionAppend !== "string") {
fail("tools.jsonc", `tool "${name}".descriptionAppend must be a string`);
}
return raw as ToolCatalogEntry;
}
function validateToolCatalog(raw: unknown): ToolCatalog {
export function validateToolCatalog(raw: unknown): ToolCatalog {
if (!isPlainObject(raw) || raw.version !== 1 || !isPlainObject(raw.tools)) {
fail("tools.jsonc", 'expected { "version": 1, "tools": { ... } }');
}
@@ -321,8 +329,8 @@ export function isSubagentCustomPrompt(customPrompt: unknown): boolean {
* Apply the tool catalog to the mutable prompt options: a `snippet` string
* replaces the tool's `<tools>` line (`null` hides it), `guidelines` replaces
* the tool's `<rules>` lines; `{inherit:true}` entries are left untouched.
* `description` is not applied here — it is a registration-time concern handled
* by `extensions/prompt-guard.ts`.
* `description` and `descriptionAppend` are not applied here — they are
* registration-time concerns handled by `extensions/prompt-guard.ts`.
*
* Returns the selected tool names that have no catalog entry at all.
*/