mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
docs(coding-agent): restore the full extensions guide, corrected against current source (#11498)
## Summary The docs refresh (#9898) cut `docs/extensions.md` from about 3,100 lines to 130, dropping API reference and tool guidance. #11039 restored part of it. This PR restores the full guide and corrects it against current source. - **Structure:** the original sections, with the ASCII lifecycle diagram replaced by three Mermaid diagrams (run, turn, session) and ordered hook lists, plus a handler composition table. - **Merged:** content added after the cut: tool exposure, calling other tools, structured output, MCP servers, `registerToolRenderer`, virtual models, `provider_stream_event`, `before_agent_start` `messageType`. - **Corrected:** removed or renamed APIs (`modelRegistry.stream()`, prompt sections are `<tools>`/`<rules>`, `builtin:read` paths, `highlightCode`), wrong behavior claims (errors only by throwing, `model_select` on restore, `sendUserMessage` always triggering a turn, override warning, `truncateLine` bytes), examples that did not type-check, links to removed `tui.md` patterns and `rpc.md` anchors, and wrong API lists in the examples table. - **Kept:** anchors that other docs and changelogs link to, as `<a id>` tags. - **Fixed example:** `reload-runtime.ts` tool queued `/reload-runtime` with `deliverAs: "followUp"`. Queued text reaches the model as a plain user message, so the command never ran and Pi never reloaded. The tool now sets a flag and returns `terminate: true`; an `agent_settled` handler sends `/reload-runtime` with `expandPromptTemplates: true`, which runs after the settled handlers finish, while the agent is idle. In the long run it may be better to revisit how API reference is, provided to the agent, especially since more capable models do explore the source without it. ## Validation - `npm run check` - Edited TypeScript examples type-check against current types - All relative links and anchors in `extensions.md` resolve, including inbound anchors from other docs - `reload-runtime.ts`: faux-provider harness test (temporary, not committed) shows one reload after the run settles and no extra model request; the old version never reloads. Also verified in interactive mode with a real model. - Reviewed by GPT-6 Astra and GPT-5.6 Sol against source; all findings applied
This commit is contained in:
parent
bb65e3e497
commit
85c2ee3e76
2 changed files with 3156 additions and 213 deletions
|
|
@ -2,7 +2,7 @@
|
|||
* Reload Runtime Extension
|
||||
*
|
||||
* Demonstrates ctx.reload() from ExtensionCommandContext and an LLM-callable
|
||||
* tool that queues a follow-up command to trigger reload.
|
||||
* tool that requests a reload once the agent has settled.
|
||||
*/
|
||||
|
||||
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
||||
|
|
@ -19,19 +19,31 @@ export default function (pi: ExtensionAPI) {
|
|||
},
|
||||
});
|
||||
|
||||
// LLM-callable tool. Tools get ExtensionContext, so they cannot call ctx.reload() directly.
|
||||
// Instead, queue a follow-up user command that executes the command above.
|
||||
// LLM-callable tool. Tools do not receive ExtensionCommandContext, so they cannot call
|
||||
// ctx.reload(), and Pi cannot reload while the agent is running. The tool records the
|
||||
// request and ends the run; the agent_settled handler then runs the command above.
|
||||
let reloadRequested = false;
|
||||
|
||||
pi.registerTool({
|
||||
name: "reload_runtime",
|
||||
label: "Reload Runtime",
|
||||
description: "Reload extensions, skills, prompts, themes, and context files",
|
||||
parameters: Type.Object({}),
|
||||
async execute() {
|
||||
pi.sendUserMessage("/reload-runtime", { deliverAs: "followUp" });
|
||||
reloadRequested = true;
|
||||
return {
|
||||
content: [{ type: "text", text: "Queued /reload-runtime as a follow-up command." }],
|
||||
content: [{ type: "text", text: "Reload requested. Pi reloads after this response." }],
|
||||
details: {},
|
||||
terminate: true,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
pi.on("agent_settled", () => {
|
||||
if (!reloadRequested) return;
|
||||
reloadRequested = false;
|
||||
// Sent from agent_settled, the command runs after every settled handler finishes, while
|
||||
// the agent is idle. expandPromptTemplates dispatches it as a command, not as model input.
|
||||
pi.sendUserMessage("/reload-runtime", { expandPromptTemplates: true });
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue