# Goldfish Implementation Plan > **For agentic workers:** REQUIRED SUB-SKILL: Use /skill:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. **Goal:** Replace useless `forget` with `goldfish`, an automatic task-gated tool-use experiment that maps work to task segments. **Architecture:** `goldfish` is a Pi extension with one LLM-facing `task` tool, visible normal tools, hard `tool_call` enforcement while idle, and a persistent `aboveEditor` widget. State is persisted as custom session entries and replayed on `session_start` like `notes`. **Tech Stack:** TypeScript Pi extension API, Pi custom widgets, Vitest, existing `test/harness`, `mise` tasks. **Research basis:** Tool-use papers point toward explicit state and constrained/gated tool availability: ToolDec shows finite-state constraints beat prompt-only tool syntax; ToolSandbox emphasizes stateful tool execution and intermediate milestones. Goldfish applies that locally: finite task state, dynamic tool menu, hard gate, and milestone check command. **Roadmap:** None **Phase:** Single-plan implementation **Status:** Reconciled on 2026-08-10 against current code and history; `extensions/goldfish` exists and the task-gate experiment shipped. --- ## File Map - Delete: `extensions/forget/` - Create: `extensions/goldfish/index.ts` - Create: `extensions/goldfish/package.json` - Create: `extensions/goldfish/README.md` - Create: `extensions/goldfish/__tests__/goldfish.test.ts` - Create: `extensions/goldfish/__tests__/harness.test.ts` - Modify: `package-lock.json` via `npm install --package-lock-only --ignore-scripts` ## Tool/state contract Task state: ```ts type TaskStatus = "idle" | "active" | "done" | "abandoned"; type GoldfishTask = { id: number; title: string; doneCommand: string; doneTimeoutSeconds: number; status: TaskStatus; createdAt: number; updatedAt: number; toolCalls: number; checks: number; lastResult?: string; }; ``` LLM-facing tool: - `task({ action: "create", title, doneCommand, doneTimeoutSeconds? })` - `task({ action: "check" })` - `task({ action: "abandon", reason })` Done command contract: - exit `0` => task closes as done. - exit `1` => task remains active. - exit `2+`, signal, timeout, spawn error => task closes as abandoned. - timeout default: `60s`, hard cap: `300s`. Guidance contract: - When idle, normal tools stay visible for same-turn SDK compatibility. - Hard gate blocks non-task tool calls while idle even if the model emits stale tool calls. - When active, all normal tools and `task` are allowed. - Tool descriptions are stateful and imperative: "Before any other tool, create a task with a done command.". - Widget mirrors state so the human always sees why tools are hidden/allowed. ## Task 1: Delete `forget` and add empty `goldfish` shell **Files:** - Delete: `extensions/forget/` - Create: `extensions/goldfish/package.json` - Create: `extensions/goldfish/README.md` - Create: `extensions/goldfish/index.ts` - Test: `extensions/goldfish/__tests__/harness.test.ts` - [x] **Step 1: Delete old extension** Run: ```bash rm -rf extensions/forget ``` - [x] **Step 2: Create package metadata** Write `extensions/goldfish/package.json`: ```json { "name": "@bugabinga/pi-ext-goldfish", "type": "module", "main": "index.ts", "scripts": {}, "devDependencies": { "@marcfargas/pi-test-harness": "^0.6.1", "vitest": "^4.1.8" }, "peerDependencies": { "@earendil-works/pi-coding-agent": "*" }, "license": "MIT", "description": "Task-gated Pi tool use experiment.", "keywords": ["pi", "pi-extension"], "private": true } ``` - [x] **Step 3: Create README** Write `extensions/goldfish/README.md`: ```markdown # goldfish Task-gated Pi tool-use experiment. When no task is active, normal tools stay visible but are hard-blocked. The agent must create a task with a done command before using them. The widget shows current state above the editor. ``` - [x] **Step 4: Write failing harness test** Write `extensions/goldfish/__tests__/harness.test.ts`: ```ts import { afterEach, describe, expect, it } from "vitest"; import { createTestSession, type TestSession } from "../../../test/harness"; import goldfishExtension from "../index"; describe("goldfish pi-test-harness", () => { let t: TestSession | undefined; afterEach(() => { t?.dispose(); t = undefined; }); it("loads in real Pi extension runtime", async () => { t = await createTestSession({ extensionFactories: [goldfishExtension] }); expect(t.session.extensionRunner.extensions).toHaveLength(1); }); }); ``` Run: ```bash mise run test -- extensions/goldfish/__tests__/harness.test.ts ``` Expected: fail because `extensions/goldfish/index.ts` does not exist. - [x] **Step 5: Create minimal extension** Write `extensions/goldfish/index.ts`: ```ts import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; export default function goldfishExtension(_pi: ExtensionAPI): void {} ``` Run: ```bash mise run test -- extensions/goldfish/__tests__/harness.test.ts ``` Expected: pass. ## Task 2: State machine and replay **Files:** - Modify: `extensions/goldfish/index.ts` - Test: `extensions/goldfish/__tests__/goldfish.test.ts` - [x] **Step 1: Write failing state tests** Write tests for: - empty state is idle. - create event opens active task. - done event closes current task. - abandon event closes current task. - replay returns latest active task. Run: ```bash mise run test -- extensions/goldfish/__tests__/goldfish.test.ts ``` Expected: fail because helpers are missing. - [x] **Step 2: Implement pure state helpers** Add event types, `createState()`, `applyEvent()`, `replayGoldfish()`, `currentTask()`, and export them under `__test`. Run: ```bash mise run test -- extensions/goldfish/__tests__/goldfish.test.ts ``` Expected: pass. ## Task 3: Task tool schema, execution, and render UI **Files:** - Modify: `extensions/goldfish/index.ts` - Test: `extensions/goldfish/__tests__/goldfish.test.ts` - [x] **Step 1: Write failing tool tests** Test: - collapsed result for `create` shows status, title, command, timeout only. - expanded result includes full details. - check exit `0` marks done. - check exit `1` keeps active. - check exit `2` abandons. - check timeout abandons. - [x] **Step 2: Implement `goldfish` tool** Use a single `task` tool with `action` enum. Return structured `details`. Render result like built-ins: - collapsed: one bounded status line. - expanded: full task context and check output. - expansion hint uses `keyHint("app.tools.expand", "to expand")` if available in current imports/patterns. - [x] **Step 3: Verify tests** Run: ```bash mise run test -- extensions/goldfish ``` Expected: pass. ## Task 4: Dynamic hide + hard gate **Files:** - Modify: `extensions/goldfish/index.ts` - Test: `extensions/goldfish/__tests__/goldfish.test.ts` - [x] **Step 1: Write failing visibility tests** Test a fake `ExtensionAPI` with active tools: - idle => normal tools visible but blocked by hard gate. - active => normal tools plus `task` allowed. - active tool baseline excludes tools not active at session start. - [x] **Step 2: Write failing hard-gate tests** Test `beforeToolCall`/`tool_call` handler logic: - idle non-task returns blocked result. - idle task is allowed. - active non-task is allowed. - [x] **Step 3: Implement visibility and gate** Use `pi.getActiveTools()` / `pi.setActiveTools()`. Capture baseline after registering `task` on `session_start`. Use `pi.on("tool_call", ...)` for hard blocking. Run: ```bash mise run test -- extensions/goldfish ``` Expected: pass. ## Task 5: Persistent widget **Files:** - Modify: `extensions/goldfish/index.ts` - Test: `extensions/goldfish/__tests__/goldfish.test.ts` - [x] **Step 1: Write failing widget tests** Test: - idle compact line says tools blocked and task required. - active compact line shows active task and check command. - expanded lines show id, title, done command, timeout, checks, tool calls, last result. - widget output truncates to width. - [x] **Step 2: Implement widget** Follow `notes` and `goal`: - `ctx.ui.setWidget("goldfish", () => ({ invalidate() {}, render(width) { ... } }), { placement: "aboveEditor" })`. - compact by default. - expanded toggle shortcut: `alt+f`. - auto-expanded when tools are blocked. Run: ```bash mise run test -- extensions/goldfish ``` Expected: pass. ## Task 6: Prompt/guidance steering **Files:** - Modify: `extensions/goldfish/index.ts` - Test: `extensions/goldfish/__tests__/goldfish.test.ts` - [x] **Step 1: Write failing guidance tests** Test generated guidance text: - idle: imperative, short, says `task.create` is required first. - active: says current task and done command. - blocked tool response tells model exact next allowed action. - [x] **Step 2: Inject guidance at correct time** Use `before_agent_start` or `context` event to prepend/append a short state block. Keep it under 12 lines. Do not duplicate stale guidance. Run: ```bash mise run test -- extensions/goldfish ``` Expected: pass. ## Task 7: Real-life `pi --print --no-session` smoke loop **Files:** - Modify as failures indicate. - [x] **Step 1: Run smoke without active task** Run: ```bash pi --print --no-session -e ./extensions/goldfish "list files in this repo" ``` Expected: model must call `task.create` before file tools are usable. - [x] **Step 2: Run smoke with achievable task** Run: ```bash pi --print --no-session -e ./extensions/goldfish "check whether package.json exists" ``` Expected: task is created, normal tool is used, check closes. - [x] **Step 3: Iterate until smoke behavior is sane** If the model fails to create tasks, strengthen guidance and hidden-tool behavior. If rendering is noisy, tighten collapsed render output. If it loops, lower check retry caps. ## Task 8: Final verification Run: ```bash mise run test -- extensions/goldfish mise run check ``` If `mise run check` fails due unrelated dirty `q` work, report exact blocker and keep targeted verification evidence. Run: ```bash git status --short ``` Expected: only goldfish deletion/addition, package lock, and pre-existing unrelated dirty work.