Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(agent-runtime): keep on-demand tools active for the whole session
yexisu5597418f07bd
diff --git a/packages/agent-runtime/src/runtime.test.ts b/packages/agent-runtime/src/runtime.test.tsindex c62804ac0..3a082d600 100644--- a/packages/agent-runtime/src/runtime.test.ts+++ b/packages/agent-runtime/src/runtime.test.ts@@ -2190,7 +2190,7 @@ describe("DesktopAgentRuntime deferred tool catalog", () => {await runtime.dispose();});- it("resets deferred capabilities at the beginning of a new prompt", async () => {+ it("keeps deferred capabilities sticky at the beginning of a new prompt (#1225)", async () => {const runtime = createRuntime();const agent = (runtime as any).agent;const search = agent.state.tools.find(@@ -2207,11 +2207,17 @@ describe("DesktopAgentRuntime deferred tool catalog", () => {true,);+ // Sticky activation: the next prompt does not drop what the model still+ // sees and calls, even when the announcing rows leave the context window.(runtime as any).resetDeferredToolsForPrompt();expect(agent.state.tools.some((tool: any) => tool.name === "BrowserPreview")).toBe(- false,+ true,+ );+ // Tool deltas append new declarations; catalog order is not semantic.+ const byName = (a: { name: string }, b: { name: string }) => a.name.localeCompare(b.name);+ expect([...getCurrentTools(agent.state.messages)].sort(byName)).toEqual(+ agent.state.tools.map(toToolDeclaration).sort(byName),);- expect(getCurrentTools(agent.state.messages)).toEqual(agent.state.tools.map(toToolDeclaration));});});@@ -8741,6 +8747,36 @@ describe("DesktopAgentRuntime deferred tool restore (#225)", () => {await runtime.dispose();});+ it("keeps an activated tool sticky across prompts after its activation rows leave the context (#1225)", async () => {+ // The tool was activated and used earlier in the session, but those rows+ // have since fallen out of the visible context (compaction, long turns).+ // The prompt-time restore finds nothing to reactivate, so sticky+ // activation is what keeps the tool in the schema and prevents the+ // intermittent "Tool BrowserPreview not found" 0 ms rejection.+ const runtime = createRuntime({ history: [] });+ (runtime as any).activeDeferredToolNames.add("BrowserPreview");++ (runtime as any).resetDeferredToolsForPrompt();++ expect(hasTool(runtime, "BrowserPreview")).toBe(true);+ await runtime.dispose();+ });++ it("does not resurrect a sticky activation after the catalog prunes the tool", async () => {+ // rebuildToolCatalog prunes both sets when a tool leaves the catalog+ // (mode switch, extension reload); the prompt-time restore must not+ // re-add a name the catalog no longer holds.+ const runtime = createRuntime({ history: [] });+ (runtime as any).activeDeferredToolNames.add("BrowserPreview");+ (runtime as any).deferredToolNames.delete("BrowserPreview");+ (runtime as any).activeDeferredToolNames.delete("BrowserPreview");++ (runtime as any).resetDeferredToolsForPrompt();++ expect(hasTool(runtime, "BrowserPreview")).toBe(false);+ await runtime.dispose();+ });+it("restores legacy activation markers for an unused tool", async () => {const fixtures: Array<{ details: Record<string, unknown>; addedToolNames?: string[] }> = [{ details: { activated: ["BrowserPreview"] } },diff --git a/packages/agent-runtime/src/runtime.ts b/packages/agent-runtime/src/runtime.tsindex 98aa572dd..069ecd46a 100644--- a/packages/agent-runtime/src/runtime.ts+++ b/packages/agent-runtime/src/runtime.ts@@ -5232,7 +5232,14 @@ Do not invent objections or turn speculative risks into blockers. Stop when the}private resetDeferredToolsForPrompt(): void {- this.activeDeferredToolNames.clear();+ // Sticky activation (#1225): on-demand tools stay active for the whole+ // session instead of being reset at every prompt. A context-only restore+ // drops the activation whenever the announcing rows fall out of the window+ // (compaction, long turns), and the next direct call then fails with+ // "Tool <name> not found" at name resolution — the intermittent 0 ms+ // rejection on Windows. `rebuildToolCatalog` still prunes names that left+ // the catalog (mode switches, extension reloads), so the set cannot+ // outlive the tools it names.this.restoreDeferredToolsFromContext();this.setAgentTools(this.activeTools());}