From 0d719d39d02bb16dfd912bf0e0df4022e8e3d9d9 Mon Sep 17 00:00:00 2001 From: stoltembergg Date: Mon, 23 Nov 2026 19:30:50 +0000 Subject: [PATCH 1/7] Close the Go fixture-scripting and chat-window e2e gaps Native send accepts attachments, skills and context as apps/api prepares them, Pi approval requests go through the shared approval flow and show as chat approval cards, native chat pages hold 200 messages, and Pi runs in the Bot's work computer workspace, where uploads land. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- AGENTS.md | 4 ++++ apps/web/test/go-gaps.ts | 17 +++---------- internal/agent/view.go | 52 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 29dcf89..9edabe6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -52,6 +52,10 @@ Pi Durable 1.4.0 stores Bot tasks. Native Harness processes own model loops. Per - `internal/agent` owns Bots, the chat projection, the chat runtime, and Bot files, as `packages/agent` does. `Runtime.Submit` admits chat input as a submission and a task in one commit; a per-Bot worker runs the tasks in order, each in an `internal/engine` session that closes when the task ends, and `Stop` aborts the session and settles the turn without waiting for it. It reads and writes the pi-durable and Persona documents (`persona.bots`, `pi.agent`, `pi.live`, `persona.engine`) by kind and scope through `Harness.Commit`, and keeps files in the TypeScript `.files` layout under `persona-go.sqlite.files` until the importer copies the TypeScript history. `persona serve` without a hosting config still runs behind the hosted origin guard, as the TypeScript service always does. `internal/server.RegisterAgent` serves its procedures, and chat input only when given a Runtime (`persona serve -pi-extension`, repeatable; Pi starts with `--no-extensions`, `builtin:tool-search`, the listed extensions, and `builtin:mcp`, like `worker.mjs`); `internal/server.RegisterEngines` serves the remaining models and engines procedures, `persona serve` lists models from `agent.LocalModels` (the local servers `internal/localmodels` detects) until a cloud provider catalog is ported, with a native runtime `engines.get`, `engines.inspect`, `engines.configure`, and `engines.select` serve Pi on the service computer (a ready inspection is saved in `persona.native-models`, so `engines.get` keeps a Bot's catalog across restarts), and the other engine runtime procedures answer `NOT_IMPLEMENTED` for an existing Bot until native engine connections and controls are composed; `internal/server/contract_test.go` requires every fixture of a registered procedure to match, except the listed skips. - The `internal/agent` runtime opens one `internal/mcpserver` gateway per native task and passes its URL as `PERSONA_PI_MCP_URL`. `internal/engine/pi` refuses a session without it, because `pi-tools.mjs` installs its approval hook only after reading that manifest. The runtime asks Pi's approval and `ask_user` requests through `internal/approval` and answers Pi with the reply; a stopped task expires the card and cancels Pi's dialog. Native input carries attachments and the composer's skills and context, as `apps/api/src/materials.ts` prepares them, and Pi runs in the Bot's work computer workspace, where uploads land. - `internal/routines` owns the `persona.routines` document and the `routine_*` tools. Route routine changes through its Service. `routine_create` and `routine_manage` do not set `Mutates`: `Service.Confirm` shows the routine card (`routine:`, schedule, time zone, execution limit, delivery, skills) like `packages/agent/src/work/routines.ts`, and a declined change returns `{"status":"declined"}`. It sets `enabled` and `nextAt` and leaves `taskId` unset; the routine runner starts tasks for enabled routines and sets `Service.RunNow` for `run_now`, which starts one task per request ID. +||||||| parent of ae521bb (Close the Go fixture-scripting and chat-window e2e gaps) +- `internal/agent` owns Bots, the chat projection, the chat runtime, and Bot files, as `packages/agent` does. `Runtime.Submit` admits chat input as a submission and a task in one commit; a per-Bot worker runs the tasks in order, each in an `internal/engine` session that closes when the task ends, and `Stop` aborts the session and settles the turn without waiting for it. It reads and writes the pi-durable and Persona documents (`persona.bots`, `pi.agent`, `pi.live`, `persona.engine`) by kind and scope through `Harness.Commit`, and keeps files in the TypeScript `.files` layout under `persona-go.sqlite.files` until the importer copies the TypeScript history. `persona serve` without a hosting config still runs behind the hosted origin guard, as the TypeScript service always does. `internal/server.RegisterAgent` serves its procedures, and chat input only when given a Runtime (`persona serve -pi-extension`); `internal/server.RegisterEngines` serves the remaining models and engines procedures, `persona serve` lists models from `agent.LocalModels` (the local servers `internal/localmodels` detects) until a cloud provider catalog is ported, with a native runtime `engines.get`, `engines.inspect`, `engines.configure`, and `engines.select` serve Pi on the service computer (a ready inspection is saved in `persona.native-models`, so `engines.get` keeps a Bot's catalog across restarts), and the other engine runtime procedures answer `NOT_IMPLEMENTED` for an existing Bot until native engine connections and controls are composed; `internal/server/contract_test.go` requires every fixture of a registered procedure to match, except the listed skips. +- The `internal/agent` runtime opens one `internal/mcpserver` gateway per native task and passes its URL as `PERSONA_PI_MCP_URL`. `internal/engine/pi` refuses a session without it, because `pi-tools.mjs` installs its approval hook only after reading that manifest. Pi approval requests that cannot be answered yet are cancelled. +- `internal/routines` owns the `persona.routines` document and the `routine_*` tools. Route routine changes through its Service. It sets `enabled` and `nextAt` and leaves `taskId` unset; the routine runner starts tasks for enabled routines and sets `Service.RunNow` for `run_now`, which starts one task per request ID. - `internal/server.RegisterWork` serves the work panel over `internal/memory`, `internal/routines`, and `internal/skills`; user saves go through each Service with source `user`, as `packages/agent/src/work` does. `work.prompt` needs a native runtime and `work.routines.test` needs `Routines.RunNow`. `work.skills.save`, `preview`, and `restore` stay unregistered until SKILL.md front matter is parsed like the TypeScript YAML failsafe schema. - `internal/mcp` owns managed MCP connections: the `persona.mcp-connections` document, Bot grants, and secrets in the hosting credential store under `persona-mcp::`, as `packages/agent/src/mcp/connections.ts`. `internal/server.RegisterMCP` serves them. Checks and sign-in run through `Service.Runner`, which `computers.Catalog.MCPRunner` supplies as a fresh worker on the connection's computer, and native connections through `Service.Catalog`, which stays unset until the worker serves native MCP reads. `persona serve` passes `/mcp/oauth/callback` to `mcp.login` and completes it through `Config.MCP`. - `PERSONA_WEB_SERVER=go` runs the web Playwright suite against `persona serve` through `apps/api/test/fixtures/go-server.ts` (`PERSONA_GO_BIN` names a built binary; otherwise it runs `go build`). `playwright.config.ts` leaves out the tests in `apps/web/test/go-gaps.ts`; remove a title when its gap closes. diff --git a/apps/web/test/go-gaps.ts b/apps/web/test/go-gaps.ts index eb4355d..fc8cdc2 100644 --- a/apps/web/test/go-gaps.ts +++ b/apps/web/test/go-gaps.ts @@ -11,22 +11,11 @@ export const goGaps: Record = { "takeover card first click opens the browser and resumes after completion", "takeover controls the Agent browser and preserves its layout through fullscreen", ], - "parallel tools: Pi runs one response's tool calls concurrently, so attach_file can read report.md before the edit beside it lands; the TypeScript harness runs them in order": - [ - // The fixture holds the model request after ls, not the tool, so input - // steered while it waits joins a later turn instead of that request. - "chat keeps sending available while the Bot is working", - "file drafts, real tools, and published downloads survive Bot switches and restart", - ], - // The spec injects approval requests through the TypeScript worker's - // computer runtime; go-server.ts has no command that opens one in serve. - "shared approval cards: the Go fixture cannot open an approval request": [ - "shared question and approval cards persist answers and terminal states", - ], - "faux failure: Pi's OpenAI-compatible provider always gives a failed reply an error message, so the fixture cannot script web-server.ts's failure without one": - ["typing follows the Bot and failures retain their error message"], + "chat steering: the Go fixture holds the model request after ls, not the tool, so input steered while it waits joins a later turn": + ["chat keeps sending available while the Bot is working"], "native questions: Pi's ask_user is not stored as a shared question card": [ "native questions use the shared card and native replies persist", + "shared question and approval cards persist answers and terminal states", ], "native Work records: work.records does not yet project native turns": [ "Work follows a native turn, opens its record and preserves it after stop and reload", diff --git a/internal/agent/view.go b/internal/agent/view.go index bbb7c88..3915e4a 100644 --- a/internal/agent/view.go +++ b/internal/agent/view.go @@ -32,6 +32,9 @@ func (r *Runtime) View(ctx context.Context, bot int64, before string) (any, erro if err != nil { return nil, err } + if err := r.pendingApprovals(ctx, bot, &chat); err != nil { + return nil, err + } known := map[string]bool{} for _, message := range chat.Messages { known[messageID(message)] = true @@ -116,6 +119,55 @@ func (r *Runtime) engineDoc(ctx context.Context, bot int64) (EngineState, error) return doc, nil } +// pendingApprovals adds the Bot's pending approval requests and their cards +// to the chat, as chatView in chat-view.ts does with approvalMessage. +func (r *Runtime) pendingApprovals(ctx context.Context, bot int64, chat *ChatView) error { + if r.approvals == nil { + return nil + } + pending, err := r.approvals.Pending(ctx, bot) + if err != nil || len(pending) == 0 { + return err + } + var turn *string + for _, message := range chat.Messages { + var m struct { + Role string `json:"role"` + TurnID *string `json:"turnId"` + } + if data, err := json.Marshal(message); err == nil && json.Unmarshal(data, &m) == nil && m.Role == "user" { + turn = m.TurnID + } + } + for _, request := range pending { + data, err := json.Marshal(request) + if err != nil { + return err + } + chat.Approvals = append(chat.Approvals, data) + card := map[string]any{ + "id": "approval:" + request.ID + ":" + strconv.FormatInt(request.RequestedAt, 10), "role": "assistant", + "timestamp": request.RequestedAt, "pending": true, "stopped": false, "turnId": turn, + } + if request.Takeover != nil { + content := []map[string]any{{"type": "text", "text": request.Detail, "key": request.ID}} + if len(request.Preview) > 0 { + var preview map[string]any + if json.Unmarshal(request.Preview, &preview) == nil { + preview["key"] = request.ID + ":preview" + content = append(content, preview) + } + } + takeover := *request.Takeover + card["content"], card["takeover"] = content, takeover + } else { + card["content"], card["approval"] = []any{}, map[string]any{"request": json.RawMessage(data), "state": "pending"} + } + chat.Messages = append(chat.Messages, card) + } + return nil +} + func messageID(message any) string { switch m := message.(type) { case ChatMessage: From 9f30fd97c89a0b6854a79cfce95eb2b9d5ba3e09 Mon Sep 17 00:00:00 2001 From: stoltembergg Date: Mon, 23 Nov 2026 21:06:41 +0000 Subject: [PATCH 2/7] Commit idle chat updates during view transitions Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/web/src/features/chat/use-chat.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/web/src/features/chat/use-chat.ts b/apps/web/src/features/chat/use-chat.ts index 7533b76..020608e 100644 --- a/apps/web/src/features/chat/use-chat.ts +++ b/apps/web/src/features/chat/use-chat.ts @@ -14,6 +14,7 @@ import { useState, useSyncExternalStore, } from "react"; +import { flushSync } from "react-dom"; import { client } from "../../client.ts"; import { flushModelSettings } from "../models/model-state.ts"; import { chatCopy } from "./copy.ts"; @@ -127,8 +128,17 @@ export function useChat(botId: number, onModelRequired?: () => void) { if (!pending || controller.signal.aborted) return; const next = pending; pending = undefined; - setView(current.current ?? next); - setConnected(true); + const apply = () => { + setView(current.current ?? next); + setConnected(true); + }; + const transition = document.activeViewTransition; + if (!next.busy && store.snapshot().view?.busy && transition) { + // A finishing turn must re-enable the composer even if a transcript + // transition is still waiting to commit its DOM update. + transition.skipTransition(); + flushSync(apply); + } else apply(); }; const visible = () => { if (!document.hidden) flush(); From a1ddc99ba0c7a6e83d8cd7eea8afbb2ab196d7be Mon Sep 17 00:00:00 2001 From: stoltembergg Date: Mon, 23 Nov 2026 21:06:41 +0000 Subject: [PATCH 3/7] Close the remaining Go chat fixture gaps Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/api/test/fixtures/go-server.ts | 14 ++++++- apps/api/test/fixtures/pi-faux-failure.mjs | 47 ++++++++++++++++++++++ internal/engine/pi/engine.go | 7 +++- packages/agent/src/harness/pi-tools.mjs | 16 +++++++- 4 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 apps/api/test/fixtures/pi-faux-failure.mjs diff --git a/apps/api/test/fixtures/go-server.ts b/apps/api/test/fixtures/go-server.ts index 9c0b888..7df365c 100644 --- a/apps/api/test/fixtures/go-server.ts +++ b/apps/api/test/fixtures/go-server.ts @@ -25,6 +25,7 @@ const database = process.argv[2]; if (!database) throw new Error("Database required"); const root = fileURLToPath(new URL("../../../..", import.meta.url)); const directory = dirname(database); +const noMessage = "persona-fixture: failure without a message"; const models = [ { id: "faux-1", name: "测试模型一" }, { id: "faux-2", name: "测试模型二", reasoning: true }, @@ -160,7 +161,9 @@ async function complete( response.writeHead(reply.errorMessage ? 500 : 400, { "Content-Type": "application/json", }); - response.end(JSON.stringify({ error: { message: reply.errorMessage } })); + response.end( + JSON.stringify({ error: { message: reply.errorMessage ?? noMessage } }), + ); return; } response.writeHead(200, { "Content-Type": "text/event-stream" }); @@ -276,7 +279,13 @@ const agentDir = join(directory, "pi-agent"); await mkdir(agentDir, { recursive: true }); await writeFile( join(agentDir, "settings.json"), - JSON.stringify({ defaultProvider: "faux", defaultModel: "faux-1" }), + JSON.stringify({ + defaultProvider: "faux", + defaultModel: "faux-1", + extensions: [ + fileURLToPath(new URL("./pi-faux-failure.mjs", import.meta.url)), + ], + }), ); await writeFile( join(agentDir, "models.json"), @@ -336,6 +345,7 @@ const options = { ...process.env, PI_CODING_AGENT_DIR: agentDir, ...(hosting ? { PERSONA_CONFIG: config } : {}), + PERSONA_FAUX_NO_MESSAGE: noMessage, PATH: `${bin}${process.platform === "win32" ? ";" : ":"}${process.env.PATH}`, }, stdio: ["pipe", "pipe", "pipe"], diff --git a/apps/api/test/fixtures/pi-faux-failure.mjs b/apps/api/test/fixtures/pi-faux-failure.mjs new file mode 100644 index 0000000..8f44afa --- /dev/null +++ b/apps/api/test/fixtures/pi-faux-failure.mjs @@ -0,0 +1,47 @@ +import { getApiProvider } from "@earendil-works/pi-ai/compat"; + +// web-server.ts scripts failures through pi-ai's faux provider, which streams +// an empty text block and then fails, with no error message when the script +// gives none. Pi's OpenAI-compatible provider always names the HTTP error, so +// go-server.ts marks such a failure with PERSONA_FAUX_NO_MESSAGE and this +// stream replays it the faux way. +const noMessage = process.env.PERSONA_FAUX_NO_MESSAGE; + +export default function (pi) { + pi.registerProvider("faux", { + api: "openai-completions", + async *streamSimple(model, context, options) { + const events = getApiProvider("openai-completions").streamSimple( + model, + context, + options, + ); + for await (const event of events) { + if ( + !noMessage || + event.type !== "error" || + !event.error.errorMessage?.includes(noMessage) + ) { + yield event; + continue; + } + const { errorMessage: _, ...failed } = event.error; + const partial = { + ...failed, + stopReason: "stop", + content: [{ type: "text", text: "" }], + }; + yield { type: "start", partial }; + yield { type: "text_start", contentIndex: 0, partial }; + yield { type: "text_delta", contentIndex: 0, delta: "", partial }; + yield { type: "text_end", contentIndex: 0, content: "", partial }; + yield { + type: "error", + reason: "error", + error: { ...partial, stopReason: "error" }, + }; + return; + } + }, + }); +} diff --git a/internal/engine/pi/engine.go b/internal/engine/pi/engine.go index 0b78a16..adde251 100644 --- a/internal/engine/pi/engine.go +++ b/internal/engine/pi/engine.go @@ -381,7 +381,12 @@ func writeTools(stateDir string, botID int64, o engine.SessionOptions) (string, if err != nil { return "", err } - data, err := json.Marshal(map[string]any{"url": o.Env["PERSONA_PI_MCP_URL"], "tools": o.Tools, "servers": []any{}}) + data, err := json.Marshal(map[string]any{ + "url": o.Env["PERSONA_PI_MCP_URL"], + "tools": o.Tools, + "servers": []any{}, + "sequentialFileTools": true, + }) if err != nil { return "", err } diff --git a/packages/agent/src/harness/pi-tools.mjs b/packages/agent/src/harness/pi-tools.mjs index 674cbca..ea04bb3 100644 --- a/packages/agent/src/harness/pi-tools.mjs +++ b/packages/agent/src/harness/pi-tools.mjs @@ -1,7 +1,7 @@ import { readFileSync } from "node:fs"; import Type from "typebox"; export default function (pi) { - const { url, servers = [] } = JSON.parse( + const { url, servers = [], sequentialFileTools } = JSON.parse( readFileSync(process.env.PERSONA_PI_TOOLS, "utf8"), ); pi.registerMcpServer("persona", { url, exposure: "direct", timeout: 600 }); @@ -12,6 +12,20 @@ export default function (pi) { }); registerPiApprovals(pi); registerPiQuestions(pi); + if (sequentialFileTools) return registerSequentialFiles(pi); +} + +async function registerSequentialFiles(pi) { + const { createEditToolDefinition, createWriteToolDefinition } = + await import("@earendil-works/pi-coding-agent"); + // Pi runs the whole batch in order when it contains a sequential tool. + // This lets attach_file snapshot the result of an earlier workspace edit. + for (const create of [createWriteToolDefinition, createEditToolDefinition]) { + pi.registerTool({ + ...create(process.cwd()), + executionMode: "sequential", + }); + } } export function registerPiApprovals(pi) { From a48c97f7852eca8da7f72574a744c606b6a5918d Mon Sep 17 00:00:00 2001 From: stoltembergg Date: Mon, 23 Nov 2026 21:07:49 +0000 Subject: [PATCH 4/7] Apply Biome formatting to the Pi extension Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- packages/agent/src/harness/pi-tools.mjs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/agent/src/harness/pi-tools.mjs b/packages/agent/src/harness/pi-tools.mjs index ea04bb3..92af3c7 100644 --- a/packages/agent/src/harness/pi-tools.mjs +++ b/packages/agent/src/harness/pi-tools.mjs @@ -1,9 +1,11 @@ import { readFileSync } from "node:fs"; import Type from "typebox"; export default function (pi) { - const { url, servers = [], sequentialFileTools } = JSON.parse( - readFileSync(process.env.PERSONA_PI_TOOLS, "utf8"), - ); + const { + url, + servers = [], + sequentialFileTools, + } = JSON.parse(readFileSync(process.env.PERSONA_PI_TOOLS, "utf8")); pi.registerMcpServer("persona", { url, exposure: "direct", timeout: 600 }); for (const server of servers) pi.registerMcpServer(server.name, { url: server.url, exposure: "direct" }); @@ -16,8 +18,9 @@ export default function (pi) { } async function registerSequentialFiles(pi) { - const { createEditToolDefinition, createWriteToolDefinition } = - await import("@earendil-works/pi-coding-agent"); + const { createEditToolDefinition, createWriteToolDefinition } = await import( + "@earendil-works/pi-coding-agent" + ); // Pi runs the whole batch in order when it contains a sequential tool. // This lets attach_file snapshot the result of an earlier workspace edit. for (const create of [createWriteToolDefinition, createEditToolDefinition]) { From 27716c4ebe4f903224bbdd8cd28957bc1cbe4446 Mon Sep 17 00:00:00 2001 From: stoltembergg Date: Mon, 23 Nov 2026 21:31:10 +0000 Subject: [PATCH 5/7] Keep image viewer keys working during transitions Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/web/src/features/chat/image-gallery.tsx | 31 +++++++++++++++----- apps/web/test/chat.spec.ts | 11 +++++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/apps/web/src/features/chat/image-gallery.tsx b/apps/web/src/features/chat/image-gallery.tsx index 3234a62..6ed58fb 100644 --- a/apps/web/src/features/chat/image-gallery.tsx +++ b/apps/web/src/features/chat/image-gallery.tsx @@ -47,6 +47,30 @@ export function ImageGallery({ inline: "center", }); }, [selected]); + useEffect(() => { + if (!file || files.length < 2) return; + const navigate = (event: KeyboardEvent) => { + if ( + (event.key !== "ArrowLeft" && event.key !== "ArrowRight") || + !(event.target instanceof Element) || + event.target.closest(".image-viewer") === null + ) + return; + event.preventDefault(); + setSelected( + (current) => + ((current ?? 0) + + (event.key === "ArrowRight" ? 1 : -1) + + files.length) % + files.length, + ); + setRotation(0); + setZoomed(false); + }; + // React can drop synthetic key events while a View Transition commits. + window.addEventListener("keydown", navigate, true); + return () => window.removeEventListener("keydown", navigate, true); + }, [file, files.length]); const alert = error && (

{error} @@ -98,13 +122,6 @@ export function ImageGallery({ trigger.current} - onKeyDown={(event) => { - if (files.length < 2) return; - if (event.key === "ArrowLeft" || event.key === "ArrowRight") { - event.preventDefault(); - move(event.key === "ArrowRight" ? 1 : -1); - } - }} > {file && ( <> diff --git a/apps/web/test/chat.spec.ts b/apps/web/test/chat.spec.ts index 0ce1da8..f649726 100644 --- a/apps/web/test/chat.spec.ts +++ b/apps/web/test/chat.spec.ts @@ -259,7 +259,12 @@ test.beforeEach(async () => { test.afterEach(async () => { if (worker.exitCode === null) await stop(); - await rm(directory, { recursive: true, force: true, maxRetries: 10 }); + await rm(directory, { + recursive: true, + force: true, + maxRetries: 10, + retryDelay: 100, + }); }); test("model selection updates immediately and restores a failed save", async ({ @@ -3087,14 +3092,14 @@ test("typing follows the Bot and failures retain their error message", async ({ await expect(failure).toContainText(/〔\d+:\d+〕/); await expect(failure.getByRole("alert")).toBeVisible(); await expect(failure.locator('svg[aria-hidden="true"]')).toHaveCount(1); - const errorText = await failure.innerText(); + const errorText = await failure.textContent(); const port = Number(new URL(url).port); await stop(); await start(port); await page.reload(); await expect(send).toBeVisible(); await expect(failure).toHaveCount(1); - await expect(failure).toHaveText(errorText); + await expect(failure).toHaveText(errorText ?? ""); await page .locator("#bot-details") .getByRole("button", { name: "关闭", exact: true }) From d973abea7124914c3241633796819d5a23719ed0 Mon Sep 17 00:00:00 2001 From: stoltembergg Date: Tue, 24 Nov 2026 08:15:59 +0000 Subject: [PATCH 6/7] Drop the duplicated pending approval card projectChat already emits the pending-request card; the re-applied pendingApprovals helper added a second identical region, as on the stacked base. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- AGENTS.md | 4 ---- internal/agent/view.go | 52 ------------------------------------------ 2 files changed, 56 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 9edabe6..29dcf89 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -52,10 +52,6 @@ Pi Durable 1.4.0 stores Bot tasks. Native Harness processes own model loops. Per - `internal/agent` owns Bots, the chat projection, the chat runtime, and Bot files, as `packages/agent` does. `Runtime.Submit` admits chat input as a submission and a task in one commit; a per-Bot worker runs the tasks in order, each in an `internal/engine` session that closes when the task ends, and `Stop` aborts the session and settles the turn without waiting for it. It reads and writes the pi-durable and Persona documents (`persona.bots`, `pi.agent`, `pi.live`, `persona.engine`) by kind and scope through `Harness.Commit`, and keeps files in the TypeScript `.files` layout under `persona-go.sqlite.files` until the importer copies the TypeScript history. `persona serve` without a hosting config still runs behind the hosted origin guard, as the TypeScript service always does. `internal/server.RegisterAgent` serves its procedures, and chat input only when given a Runtime (`persona serve -pi-extension`, repeatable; Pi starts with `--no-extensions`, `builtin:tool-search`, the listed extensions, and `builtin:mcp`, like `worker.mjs`); `internal/server.RegisterEngines` serves the remaining models and engines procedures, `persona serve` lists models from `agent.LocalModels` (the local servers `internal/localmodels` detects) until a cloud provider catalog is ported, with a native runtime `engines.get`, `engines.inspect`, `engines.configure`, and `engines.select` serve Pi on the service computer (a ready inspection is saved in `persona.native-models`, so `engines.get` keeps a Bot's catalog across restarts), and the other engine runtime procedures answer `NOT_IMPLEMENTED` for an existing Bot until native engine connections and controls are composed; `internal/server/contract_test.go` requires every fixture of a registered procedure to match, except the listed skips. - The `internal/agent` runtime opens one `internal/mcpserver` gateway per native task and passes its URL as `PERSONA_PI_MCP_URL`. `internal/engine/pi` refuses a session without it, because `pi-tools.mjs` installs its approval hook only after reading that manifest. The runtime asks Pi's approval and `ask_user` requests through `internal/approval` and answers Pi with the reply; a stopped task expires the card and cancels Pi's dialog. Native input carries attachments and the composer's skills and context, as `apps/api/src/materials.ts` prepares them, and Pi runs in the Bot's work computer workspace, where uploads land. - `internal/routines` owns the `persona.routines` document and the `routine_*` tools. Route routine changes through its Service. `routine_create` and `routine_manage` do not set `Mutates`: `Service.Confirm` shows the routine card (`routine:`, schedule, time zone, execution limit, delivery, skills) like `packages/agent/src/work/routines.ts`, and a declined change returns `{"status":"declined"}`. It sets `enabled` and `nextAt` and leaves `taskId` unset; the routine runner starts tasks for enabled routines and sets `Service.RunNow` for `run_now`, which starts one task per request ID. -||||||| parent of ae521bb (Close the Go fixture-scripting and chat-window e2e gaps) -- `internal/agent` owns Bots, the chat projection, the chat runtime, and Bot files, as `packages/agent` does. `Runtime.Submit` admits chat input as a submission and a task in one commit; a per-Bot worker runs the tasks in order, each in an `internal/engine` session that closes when the task ends, and `Stop` aborts the session and settles the turn without waiting for it. It reads and writes the pi-durable and Persona documents (`persona.bots`, `pi.agent`, `pi.live`, `persona.engine`) by kind and scope through `Harness.Commit`, and keeps files in the TypeScript `.files` layout under `persona-go.sqlite.files` until the importer copies the TypeScript history. `persona serve` without a hosting config still runs behind the hosted origin guard, as the TypeScript service always does. `internal/server.RegisterAgent` serves its procedures, and chat input only when given a Runtime (`persona serve -pi-extension`); `internal/server.RegisterEngines` serves the remaining models and engines procedures, `persona serve` lists models from `agent.LocalModels` (the local servers `internal/localmodels` detects) until a cloud provider catalog is ported, with a native runtime `engines.get`, `engines.inspect`, `engines.configure`, and `engines.select` serve Pi on the service computer (a ready inspection is saved in `persona.native-models`, so `engines.get` keeps a Bot's catalog across restarts), and the other engine runtime procedures answer `NOT_IMPLEMENTED` for an existing Bot until native engine connections and controls are composed; `internal/server/contract_test.go` requires every fixture of a registered procedure to match, except the listed skips. -- The `internal/agent` runtime opens one `internal/mcpserver` gateway per native task and passes its URL as `PERSONA_PI_MCP_URL`. `internal/engine/pi` refuses a session without it, because `pi-tools.mjs` installs its approval hook only after reading that manifest. Pi approval requests that cannot be answered yet are cancelled. -- `internal/routines` owns the `persona.routines` document and the `routine_*` tools. Route routine changes through its Service. It sets `enabled` and `nextAt` and leaves `taskId` unset; the routine runner starts tasks for enabled routines and sets `Service.RunNow` for `run_now`, which starts one task per request ID. - `internal/server.RegisterWork` serves the work panel over `internal/memory`, `internal/routines`, and `internal/skills`; user saves go through each Service with source `user`, as `packages/agent/src/work` does. `work.prompt` needs a native runtime and `work.routines.test` needs `Routines.RunNow`. `work.skills.save`, `preview`, and `restore` stay unregistered until SKILL.md front matter is parsed like the TypeScript YAML failsafe schema. - `internal/mcp` owns managed MCP connections: the `persona.mcp-connections` document, Bot grants, and secrets in the hosting credential store under `persona-mcp::`, as `packages/agent/src/mcp/connections.ts`. `internal/server.RegisterMCP` serves them. Checks and sign-in run through `Service.Runner`, which `computers.Catalog.MCPRunner` supplies as a fresh worker on the connection's computer, and native connections through `Service.Catalog`, which stays unset until the worker serves native MCP reads. `persona serve` passes `/mcp/oauth/callback` to `mcp.login` and completes it through `Config.MCP`. - `PERSONA_WEB_SERVER=go` runs the web Playwright suite against `persona serve` through `apps/api/test/fixtures/go-server.ts` (`PERSONA_GO_BIN` names a built binary; otherwise it runs `go build`). `playwright.config.ts` leaves out the tests in `apps/web/test/go-gaps.ts`; remove a title when its gap closes. diff --git a/internal/agent/view.go b/internal/agent/view.go index 3915e4a..bbb7c88 100644 --- a/internal/agent/view.go +++ b/internal/agent/view.go @@ -32,9 +32,6 @@ func (r *Runtime) View(ctx context.Context, bot int64, before string) (any, erro if err != nil { return nil, err } - if err := r.pendingApprovals(ctx, bot, &chat); err != nil { - return nil, err - } known := map[string]bool{} for _, message := range chat.Messages { known[messageID(message)] = true @@ -119,55 +116,6 @@ func (r *Runtime) engineDoc(ctx context.Context, bot int64) (EngineState, error) return doc, nil } -// pendingApprovals adds the Bot's pending approval requests and their cards -// to the chat, as chatView in chat-view.ts does with approvalMessage. -func (r *Runtime) pendingApprovals(ctx context.Context, bot int64, chat *ChatView) error { - if r.approvals == nil { - return nil - } - pending, err := r.approvals.Pending(ctx, bot) - if err != nil || len(pending) == 0 { - return err - } - var turn *string - for _, message := range chat.Messages { - var m struct { - Role string `json:"role"` - TurnID *string `json:"turnId"` - } - if data, err := json.Marshal(message); err == nil && json.Unmarshal(data, &m) == nil && m.Role == "user" { - turn = m.TurnID - } - } - for _, request := range pending { - data, err := json.Marshal(request) - if err != nil { - return err - } - chat.Approvals = append(chat.Approvals, data) - card := map[string]any{ - "id": "approval:" + request.ID + ":" + strconv.FormatInt(request.RequestedAt, 10), "role": "assistant", - "timestamp": request.RequestedAt, "pending": true, "stopped": false, "turnId": turn, - } - if request.Takeover != nil { - content := []map[string]any{{"type": "text", "text": request.Detail, "key": request.ID}} - if len(request.Preview) > 0 { - var preview map[string]any - if json.Unmarshal(request.Preview, &preview) == nil { - preview["key"] = request.ID + ":preview" - content = append(content, preview) - } - } - takeover := *request.Takeover - card["content"], card["takeover"] = content, takeover - } else { - card["content"], card["approval"] = []any{}, map[string]any{"request": json.RawMessage(data), "state": "pending"} - } - chat.Messages = append(chat.Messages, card) - } - return nil -} - func messageID(message any) string { switch m := message.(type) { case ChatMessage: From b691d644e2db9f2d685fc49686aa5f86ba8fdd15 Mon Sep 17 00:00:00 2001 From: stoltembergg Date: Tue, 24 Nov 2026 08:32:32 +0000 Subject: [PATCH 7/7] Load the faux-failure extension explicitly in the Go fixture serve always runs Pi with --no-extensions, so settings.json extensions never load: the faux error marker surfaced raw and the failure card lost its fallback text. Pass pi-faux-failure.mjs through -pi-extension instead. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/api/test/fixtures/go-server.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/api/test/fixtures/go-server.ts b/apps/api/test/fixtures/go-server.ts index 7df365c..5200316 100644 --- a/apps/api/test/fixtures/go-server.ts +++ b/apps/api/test/fixtures/go-server.ts @@ -282,9 +282,6 @@ await writeFile( JSON.stringify({ defaultProvider: "faux", defaultModel: "faux-1", - extensions: [ - fileURLToPath(new URL("./pi-faux-failure.mjs", import.meta.url)), - ], }), ); await writeFile( @@ -337,6 +334,10 @@ const args = [ join(root, "contracts", "api"), "-pi-extension", join(root, "packages", "agent", "src", "harness", "pi-tools.mjs"), + // serve always runs Pi with --no-extensions, so settings.json extensions + // never load; the faux failure stream must be an explicit extension. + "-pi-extension", + fileURLToPath(new URL("./pi-faux-failure.mjs", import.meta.url)), ]; const options = { // Outside the repository so persona.config.json does not select hosted mode.