/** * register — the advisor tool registration: zero-param schema, curated * description / promptSnippet / promptGuidelines, and an execute that delegates * to executeAdvisor. The guidance overrides are read from persisted config. */ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { validateGuidanceFields } from "@juicesharp/rpiv-config"; import { Type } from "typebox"; import { loadAdvisorConfig } from "./config.js"; import { executeAdvisor } from "./execute.js"; import { ADVISOR_TOOL_NAME, TOOL_LABEL } from "./messages.js"; const AdvisorParams = Type.Object({}); const ADVISOR_DESCRIPTION = "Escalate to a stronger reviewer model for guidance. When you need " + "stronger judgment — a complex decision, an ambiguous failure, a problem " + "you're circling without progress — escalate to the advisor model for " + "guidance, then resume. Takes NO parameters — when you call advisor(), " + "your entire conversation history is automatically forwarded. The advisor " + "sees the task, every tool call you've made, every result you've seen."; export const DEFAULT_PROMPT_SNIPPET = "Escalate to a stronger reviewer model for guidance when stuck, before substantive work, or before declaring done"; export const DEFAULT_PROMPT_GUIDELINES: string[] = [ "Call `advisor` BEFORE substantive work — before writing, before committing to an interpretation, before building on an assumption. Orientation (finding files, fetching a source, seeing what's there) is not substantive work; writing, editing, and declaring an answer are.", "Also call `advisor` when you believe the task is complete. BEFORE this call, make your deliverable durable: write the file, save the result, commit the change. The advisor call takes time; if the session ends during it, a durable result persists and an unwritten one doesn't.", "Also call `advisor` when stuck — errors recurring, approach not converging, results that don't fit — or when considering a change of approach.", "On tasks longer than a few steps, call `advisor` at least once before committing to an approach and once before declaring done. On short reactive tasks where the next action is dictated by tool output you just read, you don't need to keep calling — the advisor adds most of its value on the first call, before the approach crystallizes.", "Give the advisor's advice serious weight. If you follow a step and it fails empirically, or you have primary-source evidence that contradicts a specific claim, adapt — a passing self-test is not evidence the advice is wrong, it's evidence your test doesn't check what the advice is checking.", "If you've already retrieved data pointing one way and the advisor points another, don't silently switch — surface the conflict in one more `advisor` call (\"I found X, you suggest Y, which constraint breaks the tie?\"). A reconcile call is cheaper than committing to the wrong branch.", ]; export function registerAdvisorTool(pi: ExtensionAPI): void { const guidance = validateGuidanceFields(loadAdvisorConfig().guidance); pi.registerTool({ name: ADVISOR_TOOL_NAME, label: TOOL_LABEL, description: ADVISOR_DESCRIPTION, promptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET, promptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES, parameters: AdvisorParams, async execute(_toolCallId, _params, signal, onUpdate, ctx) { return executeAdvisor(ctx, pi, signal, onUpdate); }, }); }