feat(discord): writes on write-marked roots, web fetch and search, held prompts (#1509)
Row 23. write_file and edit_file for roots marked write: true under the same fence as reads; web_fetch (https only, public addresses, pinned connection, capped body) and web_search through SearXNG; extension renamed to tools.mjs. Engine holds a prompt while pi is busy and sends it as its own run, so a second message mid-turn no longer folds into the first (live defect). fake-pi models the real follow-up folding. Suite 52/52, node tests 129. rev-code-02 APPROVED round 3, comment 26362, tree dbd2ce9a. Records: QUEUE rows 23-24, CURRENT, BUILD-LOG phase, SESSIONS, row 24 brief (git verbs, D5-D7 ruled). Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
+28
-8
@@ -1,6 +1,9 @@
|
||||
// pi extension: the Discord Sage's read-only tools. Loaded by the connector
|
||||
// with `--no-builtin-tools --extension <this file> --tools list_dir,read_file,search`
|
||||
// so pi exposes exactly these three tools and none of its own.
|
||||
// pi extension: the Discord Sage's tools. Loaded by the connector with
|
||||
// `--no-builtin-tools --extension <this file> --tools <enabled names>` so pi
|
||||
// exposes exactly the tools the binding enables and none of its own: the
|
||||
// three reads always, write_file and edit_file only when a root is marked
|
||||
// write: true, web_fetch and web_search only with a web key
|
||||
// (enabledToolNames in ../src/tools.mjs decides, in one place).
|
||||
//
|
||||
// Every decision lives in ../src/tools.mjs; this file only registers the
|
||||
// tools with pi and reads its configuration from the one environment
|
||||
@@ -12,7 +15,7 @@
|
||||
// prompt run, so a follow-up message gets a fresh budget.
|
||||
|
||||
import { Type } from "typebox";
|
||||
import { TOOLS_ENV, TOOL_NAMES, TOOL_DESCRIPTIONS, READ_MAX_LINES, loadToolsConfig, createToolSet } from "../src/tools.mjs";
|
||||
import { TOOLS_ENV, TOOL_DESCRIPTIONS, READ_MAX_LINES, loadToolsConfig, createToolSet, enabledToolNames } from "../src/tools.mjs";
|
||||
|
||||
const PARAMS = {
|
||||
list_dir: () => Type.Object({
|
||||
@@ -30,6 +33,23 @@ const PARAMS = {
|
||||
text: Type.String({ description: "Fixed string to find, case-insensitive" }),
|
||||
path: Type.Optional(Type.String({ description: "Subfolder or file relative to the root; empty for the whole root" })),
|
||||
}),
|
||||
write_file: () => Type.Object({
|
||||
root: Type.String({ description: "Name of a root that allows writes" }),
|
||||
path: Type.String({ description: "File path relative to the root; the parent folder must exist" }),
|
||||
text: Type.String({ description: "The whole new content of the file" }),
|
||||
}),
|
||||
edit_file: () => Type.Object({
|
||||
root: Type.String({ description: "Name of a root that allows writes" }),
|
||||
path: Type.String({ description: "File path relative to the root" }),
|
||||
old: Type.String({ description: "Exact text to replace; must occur exactly once" }),
|
||||
new: Type.String({ description: "Replacement text" }),
|
||||
}),
|
||||
web_fetch: () => Type.Object({
|
||||
url: Type.String({ description: "Absolute https url of a public page" }),
|
||||
}),
|
||||
web_search: () => Type.Object({
|
||||
query: Type.String({ description: "Search words, as you would type them" }),
|
||||
}),
|
||||
};
|
||||
|
||||
export default function (pi) {
|
||||
@@ -43,22 +63,22 @@ export default function (pi) {
|
||||
}
|
||||
const config = loadToolsConfig(parsed);
|
||||
const tools = createToolSet(config);
|
||||
const rootNames = config.roots.map((r) => r.name).join(", ");
|
||||
const rootNames = config.roots.map((r) => (r.write ? `${r.name} (writable)` : r.name)).join(", ");
|
||||
|
||||
pi.on("agent_start", async () => {
|
||||
tools.resetBudget();
|
||||
});
|
||||
|
||||
for (const name of TOOL_NAMES) {
|
||||
for (const name of enabledToolNames(config)) {
|
||||
const d = TOOL_DESCRIPTIONS[name];
|
||||
pi.registerTool({
|
||||
name,
|
||||
label: d.label,
|
||||
description: `${d.description} Declared roots: ${rootNames}.`,
|
||||
description: name.startsWith("web_") ? d.description : `${d.description} Declared roots: ${rootNames}.`,
|
||||
promptSnippet: d.snippet,
|
||||
parameters: PARAMS[name](),
|
||||
async execute(_toolCallId, params) {
|
||||
const r = tools.call(name, params);
|
||||
const r = await tools.call(name, params);
|
||||
return { content: [{ type: "text", text: r.text }], details: r.details };
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user