-
Notifications
You must be signed in to change notification settings - Fork 0
Add Pi extensions and same-run add_tool to CUA CLI #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rgarcia
wants to merge
24
commits into
main
Choose a base branch
from
hypeship/harness-extension-host
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
caba46a
Add Tier-A pi extension host for CuaAgentHarness
rgarcia 1377534
Harden extension-host tool reapply, reload, and prompt paths
rgarcia 33c5e6e
Add e2e self-improve loop tests for the extension host
rgarcia 08d0298
Drop removed extension tools on reload
rgarcia 088d355
Wire the pi extension host into the cua CLI runtime
rgarcia 001caed
Load project-local extensions by default; drop trust gating
rgarcia e8f2596
Recommend claude-opus-4-8 in cli --help and README
rgarcia 79caa34
Add opt-in runtime tool authoring (--self-extend)
rgarcia 49c2dd9
Harden extension-host lifecycle (load/reload/dispose)
rgarcia 84dc3a5
Coalesce reentrant reloads; don't drop extension prompt rejections
rgarcia 2a112c5
Settle reloads on dispose and fix first-turn screenshot ownership
rgarcia 451934e
Harden extension reapply/load/reload error paths
rgarcia ead1258
Remove merged tools from the harness on dispose
rgarcia 7ba546b
Adapt extension-host tests to the instance-based scripted-provider fi…
rgarcia 095b958
Add same-run self-authored tools
rgarcia e1487e3
Keep anchored Pi packages installable
rgarcia 351b650
Clarify anchored dependency provenance
rgarcia 9aefa03
Factor AgentHarness extension compatibility
rgarcia 8cf92b4
Preserve extension tools across mode switches
rgarcia 7474a26
Serialize extension active tool updates
rgarcia e5a6c02
Bundle branch dependencies in CLI prereleases
rgarcia 29ac171
Guard extension screenshots and teardown
rgarcia 3877459
Align action screenshots and reload state
rgarcia 52d2540
Merge remote-tracking branch 'origin/main' into hypeship/harness-exte…
rgarcia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import type { AgentTool, Context, Message, Model } from "@earendil-works/pi-ai"; | ||
| import { createServer } from "node:http"; | ||
| import { cuaModels, getCuaModel, resolveCuaRuntimeSpec } from "../src/index"; | ||
| import { ANTHROPIC_NATIVE_BROWSER_MESSAGES_API } from "../src/providers/anthropic/native"; | ||
|
|
||
| const { openaiCreate } = vi.hoisted(() => ({ | ||
| openaiCreate: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("openai", () => ({ | ||
| default: class { | ||
| responses = { | ||
| create: (...args: unknown[]) => { | ||
| openaiCreate(...args); | ||
| return { | ||
| withResponse: async () => { | ||
| throw new Error("stop after payload capture"); | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
| }, | ||
| })); | ||
|
|
||
| const dynamicTool: AgentTool = { | ||
| name: "learned_tool", | ||
| label: "Learned tool", | ||
| description: "learned", | ||
| parameters: { type: "object", properties: {} }, | ||
| execute: async () => ({ content: [], details: {} }), | ||
| }; | ||
| const addTool: AgentTool = { ...dynamicTool, name: "add_tool", label: "Add tool" }; | ||
|
|
||
| function addMessages(api: string, responseId?: string): Message[] { | ||
| return [ | ||
| { | ||
| role: "assistant", | ||
| content: [{ type: "toolCall", id: "add_1", name: "add_tool", arguments: {} }], | ||
| api, | ||
| provider: api.startsWith("openai") ? "openai" : "anthropic", | ||
| model: api.startsWith("openai") ? "gpt-5.5" : "claude-sonnet-4-5", | ||
| responseId, | ||
| usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } }, | ||
| stopReason: "toolUse", | ||
| timestamp: 0, | ||
| }, | ||
| { | ||
| role: "toolResult", | ||
| toolCallId: "add_1", | ||
| toolName: "add_tool", | ||
| content: [{ type: "text", text: "added" }], | ||
| addedToolNames: ["learned_tool"], | ||
| isError: false, | ||
| timestamp: 0, | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| async function capturePayload( | ||
| model: Model<any>, | ||
| context: Context, | ||
| transform?: (payload: unknown, model: Model<any>) => unknown | Promise<unknown>, | ||
| ): Promise<Record<string, any>> { | ||
| let payload: Record<string, any> | undefined; | ||
| await cuaModels() | ||
| .streamSimple(model, context, { | ||
| apiKey: "test", | ||
| onPayload: async (value, payloadModel) => { | ||
| const transformed = transform | ||
| ? ((await transform(value, payloadModel)) ?? value) | ||
| : value; | ||
| payload = transformed as Record<string, any>; | ||
| return transformed; | ||
| }, | ||
| }) | ||
| .result(); | ||
| if (!payload) throw new Error("payload was not captured"); | ||
| return payload; | ||
| } | ||
|
|
||
| describe("message-anchored dynamic tool payloads", () => { | ||
| it("uses OpenAI tool search while preserving response threading", async () => { | ||
| const model = getCuaModel("openai:gpt-5.5"); | ||
| const payload = await capturePayload(model, { | ||
| systemPrompt: "test", | ||
| tools: [addTool, dynamicTool], | ||
| messages: addMessages(model.api, "resp_add"), | ||
| }); | ||
| expect(payload.store).toBe(true); | ||
| expect(payload.previous_response_id).toBe("resp_add"); | ||
| const searchOutput = payload.input.find((item: any) => item.type === "tool_search_output"); | ||
| expect(searchOutput.tools).toEqual( | ||
| expect.arrayContaining([expect.objectContaining({ name: "learned_tool", defer_loading: true })]), | ||
| ); | ||
| expect(payload.input).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ type: "tool_search_call" }), | ||
| expect.objectContaining({ type: "tool_search_output" }), | ||
| ]), | ||
| ); | ||
| }); | ||
|
|
||
| it("eagerly declares the tool after the add marker is pruned by the next response anchor", async () => { | ||
| const model = getCuaModel("openai:gpt-5.5"); | ||
| const messages = addMessages(model.api, "resp_add"); | ||
| messages.push( | ||
| { | ||
| role: "assistant", | ||
| content: [{ type: "toolCall", id: "learn_1", name: "learned_tool", arguments: {} }], | ||
| api: model.api, | ||
| provider: "openai", | ||
| model: model.id, | ||
| responseId: "resp_learned", | ||
| usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } }, | ||
| stopReason: "toolUse", | ||
| timestamp: 0, | ||
| }, | ||
| { role: "toolResult", toolCallId: "learn_1", toolName: "learned_tool", content: [], isError: false, timestamp: 0 }, | ||
| ); | ||
| const payload = await capturePayload(model, { systemPrompt: "test", tools: [addTool, dynamicTool], messages }); | ||
| expect(payload.previous_response_id).toBe("resp_learned"); | ||
| expect(payload.tools).toEqual( | ||
| expect.arrayContaining([expect.objectContaining({ name: "learned_tool" })]), | ||
| ); | ||
| expect(payload.tools.find((tool: any) => tool.name === "learned_tool").defer_loading).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("uses Anthropic references for supported models and eager tools for Haiku", async () => { | ||
| const supported = getCuaModel("anthropic:claude-sonnet-4-5"); | ||
| const supportedPayload = await capturePayload(supported, { | ||
| systemPrompt: "test", | ||
| tools: [addTool, dynamicTool], | ||
| messages: addMessages(supported.api), | ||
| }); | ||
| expect(supportedPayload.tools).toEqual( | ||
| expect.arrayContaining([expect.objectContaining({ name: "learned_tool", defer_loading: true })]), | ||
| ); | ||
| expect(JSON.stringify(supportedPayload.messages)).toContain("tool_reference"); | ||
|
|
||
| const haiku = { | ||
| ...supported, | ||
| id: "claude-haiku-4", | ||
| compat: { ...supported.compat, supportsToolReferences: false }, | ||
| }; | ||
| const haikuPayload = await capturePayload(haiku, { | ||
| systemPrompt: "test", | ||
| tools: [addTool, dynamicTool], | ||
| messages: addMessages(haiku.api), | ||
| }); | ||
| expect(JSON.stringify(haikuPayload.messages)).not.toContain("tool_reference"); | ||
| expect(haikuPayload.tools).toEqual( | ||
| expect.arrayContaining([expect.objectContaining({ name: "learned_tool" })]), | ||
| ); | ||
| }); | ||
|
|
||
| it("preserves dynamic tools and beta headers through Anthropic native routing", async () => { | ||
| let requestHeaders: Record<string, string | string[] | undefined> = {}; | ||
| const server = createServer((request, response) => { | ||
| requestHeaders = request.headers; | ||
| response.writeHead(500, { "content-type": "application/json" }); | ||
| response.end('{"error":{"message":"captured"}}'); | ||
| }); | ||
| await new Promise<void>((resolve) => | ||
| server.listen(0, "127.0.0.1", resolve), | ||
| ); | ||
| try { | ||
| const address = server.address(); | ||
| if (!address || typeof address === "string") | ||
| throw new Error("test server did not bind"); | ||
| const spec = resolveCuaRuntimeSpec( | ||
| "anthropic:claude-sonnet-4-5", | ||
| { nativeTool: { type: "browser_20260701" } }, | ||
| ); | ||
| const model = { | ||
| ...spec.model, | ||
| api: ANTHROPIC_NATIVE_BROWSER_MESSAGES_API, | ||
| baseUrl: `http://127.0.0.1:${address.port}`, | ||
| } as Model<any>; | ||
| const nativePlaceholder = { | ||
| ...dynamicTool, | ||
| ...spec.toolDefinitions[0], | ||
| } as AgentTool; | ||
| const payload = await capturePayload( | ||
| model, | ||
| { | ||
| systemPrompt: "test", | ||
| tools: [nativePlaceholder, addTool, dynamicTool], | ||
| messages: addMessages("anthropic-messages"), | ||
| }, | ||
| spec.onPayload, | ||
| ); | ||
| expect(payload.tools).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| name: "learned_tool", | ||
| defer_loading: true, | ||
| }), | ||
| ]), | ||
| ); | ||
| expect(payload.tools).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ type: "browser_20260701" }), | ||
| ]), | ||
| ); | ||
| expect(requestHeaders["anthropic-beta"]).toContain( | ||
| "browser-use-2026-07-01", | ||
| ); | ||
| } finally { | ||
| await new Promise<void>((resolve, reject) => | ||
| server.close((error) => (error ? reject(error) : resolve())), | ||
| ); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.