What Pipal adds to Pi

The distance between a library and a product, feature by feature.

intermediate8 min read

Rename a chat and reopen it. The new title is there, alongside the same messages and the same choice of model. All three can live in the same SQLite file. Each answers a different question, and the code that owns the title is different from the code that keeps the transcript.

In this chapter

  • Trace a workspace feature to the library mechanism and the application code that uses it.
  • Explain why installing an extension and granting its tools to a chat are separate decisions.
  • Find Pipal’s saved state in Pi records and see how it becomes the browser’s view.

The library runs the conversation. The application makes it a workspace.

From Pi mechanism to Pipal feature
FeaturePi Pipal
Conversation
Running a chatTranscript entries, submissions and their request IDs, tasks, checkpoints, recovery, and compaction.Serialized admission, retry checks, run deadlines and turn-budget policy, and the pipal.chat document. Core runtime
Model accessUnified model requests and streaming events, provider catalogs, and OAuth support.Markdown profiles, the workspace’s model choices, and the ChatGPT sign-in relay. Profiles and models
Tools and workspaces
A tool callTool definitions and calls, extensions, hooks, execution environments, and read, edit, and write.Per-execution checks for configured tool grants, host diagnostics, and routing for project tools. Tools and extensions
Public web accessA hook can change a provider request, and extensions can supply model-callable tools.An opt-in hook adds hosted search to eligible provider requests. Separate host tools can search with Exa and read a public page through Jina Reader.
Code Mode sandboxPi Codemode runs scripts inside the sandbox. Pi Durable supplies the Code Mode extension.The host installs it when extensions.enabled includes codemode. A profile must select it for its chats.
Work that waitsParking, wakeups, signals, and task-owned conversations.Workspace approvals and YOLO, delegation, scheduled routines, and development workers.
Project locationsAn execution environment gives the file tools an interface for file operations.Pipal saves which locations the owner enables, pins the location on each new chat, and routes project calls to it. Three ways to touch a project
Workspace
Files in and outPi Durable’s Photon-based processor for preparing images.The upload pipeline, published HTML previews, and durable downloads of project files. Files in, artifacts out
Finding and measuringPi Durable’s recorded usage totals and Pi AI’s token estimation helpers.Chat search, the context meter, and session statistics. Search, context and cost
Workspace accessA conversation watch gives its caller the current view and subsequent changes.The HTTP API, event stream, workspace sign-in, and Svelte workspace. Live streams
Running the applicationSchema builders and validation.UI extensions and themes, TOML configuration, and the Linux deployment recipe.

Choose up to two columns

FeaturePi Pipal
ConversationConversation
Running a chatTranscript entries, submissions and their request IDs, tasks, checkpoints, recovery, and compaction.Serialized admission, retry checks, run deadlines and turn-budget policy, and the pipal.chat document. Core runtime
Model accessUnified model requests and streaming events, provider catalogs, and OAuth support.Markdown profiles, the workspace’s model choices, and the ChatGPT sign-in relay. Profiles and models
Tools and workspacesTools and workspaces
A tool callTool definitions and calls, extensions, hooks, execution environments, and read, edit, and write.Per-execution checks for configured tool grants, host diagnostics, and routing for project tools. Tools and extensions
Public web accessA hook can change a provider request, and extensions can supply model-callable tools.An opt-in hook adds hosted search to eligible provider requests. Separate host tools can search with Exa and read a public page through Jina Reader.
Code Mode sandboxPi Codemode runs scripts inside the sandbox. Pi Durable supplies the Code Mode extension.The host installs it when extensions.enabled includes codemode. A profile must select it for its chats.
Work that waitsParking, wakeups, signals, and task-owned conversations.Workspace approvals and YOLO, delegation, scheduled routines, and development workers.
Project locationsAn execution environment gives the file tools an interface for file operations.Pipal saves which locations the owner enables, pins the location on each new chat, and routes project calls to it. Three ways to touch a project
WorkspaceWorkspace
Files in and outPi Durable’s Photon-based processor for preparing images.The upload pipeline, published HTML previews, and durable downloads of project files. Files in, artifacts out
Finding and measuringPi Durable’s recorded usage totals and Pi AI’s token estimation helpers.Chat search, the context meter, and session statistics. Search, context and cost
Workspace accessA conversation watch gives its caller the current view and subsequent changes.The HTTP API, event stream, workspace sign-in, and Svelte workspace. Live streams
Running the applicationSchema builders and validation.UI extensions and themes, TOML configuration, and the Linux deployment recipe.
Read across a row to see where a library mechanism meets a product decision. Use the chips to focus on library mechanisms or application features.

Start at the sign-in screen. Pipal’s HTTP server checks sign-in on the chat API. When the client opens a chat, Pipal uses Pi watchesA subscription that starts with the current view of a conversation or document and receives changes after that. on the conversation and its metadata to build the browser’s stream. Pipal computes smaller updates from the public view it builds when the client opts into deltas. The Hono server follows that request. app.ts index.ts

Pick Developer and you see another place where the two meet. A profileA named set of instructions, defaults, and tool grants that Pipal applies to a conversation. is a named set of instructions and tool grants. Pipal reads its instructions and extension names from a Markdown file and uses them to configure the conversation. profiles.ts index.ts

Pi stores the conversation’s choices in pi.agent and includes the instructions when it builds the prompt. That lets a profile tell the assistant how to work while the harness runs the conversation. README.md

Take a file edit. Pi supplies the edit tool and an interface for reading and writing files, called the execution environment. Pipal supplies the project operations behind that interface. The same edit tool can work in a development workspace on This machine or SSH machine, or in a Docker container. Pipal picks the operations for the chat’s locationThe place a chat uses for project tools, either the Pipal host, an account reached over SSH, or a Docker project.. Three ways to touch a project locates each environment. project-coding.ts workspace-locations.ts

The owner chooses which locations to enable in Settings → Workspace. Pipal saves that choice separately from its conversation store, in workspace-settings.json. When you first send from a draft, Pipal pins the location and any project binding to the new chat. To work somewhere else, start a new chat. workspace-locations.ts index.ts

The same division shows up when you attach a photo. Pipal accepts and stores the upload and chooses the preparation limits. It calls Pi Durable’s Photon-based processor to fit an image before including it with the message. uploads.ts

Pipal also supplies the publishing tools. pipal.web-artifacts gives the model a tool that takes self-contained HTML. The workspace’s pipal.coding grant can offer publish_file, which takes a project path and saves a file artifactA saved copy of a project file you can download from the chat.. Pi supplies the transaction that commits either artifact entry with the task’s publication record. Files in, artifacts out follows the two paths to the browser. web-artifacts.ts workspace-locations.ts

Installing a definition gives the host something to run

An extensionA named bundle of additions to the harness, such as tools, prompt sections, hooks, or tasks. can be installed in the host’s registryThe collection of extension definitions installed in the running process. while each chat still gets an explicit selection. A grantThe permission a profile gives a chat to use an extension’s tools. lets that profile use an extension’s tools. Pi Durable’s default is to select all installed extensions. Pipal passes extensions: [] to the harness and selects extensions per chat from its profile and runtime policy. This makes installing a tool definition a separate decision from offering its tools to every chat. README.md index.ts

When pipal.bash is in extensions.enabled, the host registers one bash tool even if all locations are off. The host routes calls by location, and core’s grants() leaves out project tools the chat’s location cannot run. workspace-locations.ts index.ts

A tool can also have to wait. Pi gives a tool a way to parkTo end a tool invocation with a saved wait for a time, a signal, or work the call owns. and save where it left off. Pipal uses that mechanism for actions that need your approval, and can save a scoped YOLOA saved permission to skip the approval prompt for actions in a matching workspace scope. grant when you want to approve actions in that workspace automatically. Pipal uses the same scheduler for other waits. A delegation tool can wait for its specialist’s answer. A routine alarm can sleep until a prompt is due, and the task that supervises a development worker can wait for an assignment to finish. index.ts delegate.ts

The Developer profile requests hosted search and pipal.public-web as optional grants. Its instructions favor hosted search when available, search_public_web as a fallback, and read_url for a specific public page. Both extensions are off by default. The operator opts in through extensions.enabled. Either can work in a Docker chat while shell commands and ordinary file operations stay offline. developer.md config.ts

Deep diveWhich tools get wrapped when the registry is built

When pipal.public-web is enabled, main.ts adds publicWebExtension to the host’s list. Its two tools go through the same grant checks as other host tools. A profile with this grant can use Exa search even when its model also offers hosted search. main.ts public-web.ts

The loop over the configured extensions installs each definition with its tool registrations copied and execute wrapped. The wrapper reads the conversation’s pipal.chat, resolves the profile ID against the current profile map, and checks the extension name. For workspace tools, core resolves the pinned location and checks the project binding and whether that location supports the tool. Workspace tools other than read require approval or a matching YOLO grant. The host’s route() wrapper checks the binding again when it dispatches the call. index.ts workspace-locations.ts

Pi calls execute again when a tool that parked inside execute wakes or a replay-safe invocation is retried. Pi also offers a gate in beforeTool, which runs again if the call parked there before reaching execute. README.md

Core installs the built-in worker, delegate, and routine definitions separately. Delegation uses its own authorization callback on each execution. Specialists and workers inherit their parent’s location and project binding. Starting or continuing a worker checks that the parent still has access to a location with named projects and that the target profile has workspace grants. The routine extension registers the alarm task and supplies no model tools. An extension task needs its definition to be installed before it can resume. index.ts delegate.ts workers.ts routines.ts README.md

Core also installs pipal.turn-budget and includes it when applying a profile’s grants. Its generation hooks warn when the tool budget runs low and reserve a text reply. An eligible top-level chat can offer Resume response after that closeout, a turn-limit failure, or an abort. Pi runs the new submission and Pipal decides when to offer it. index.ts turn-budget.ts view.ts

The runtime test parks a tool and then opens the same store with the extension still installed but removed from the profile. The test checks that the old call’s execution body never runs after wake. The saved selection in pi.agent and the check on execution serve different moments in a call’s life. runtime.test.ts

A Pipal chat fits inside Pi’s store

The records behind one chat
  • durable.sqlite

    Pi Durable owns the store. Pipal saves its chat state using Pi’s record types.

    • One conversation

      Pi gives the conversation its identity and transcript. Pipal adds product state at that identity.

      • Entries

        The transcript includes Pi entries and application-defined records.

        • Pi messages

          A plain user input, an assistant response, and a tool result can produce pi.user, pi.assistant, and pi.tool-result entries.

        • Pipal entries

          pipal.attachment-message, pipal.routine-message, and pipal.resume record special kinds of user inputs. pipal.web-artifact keeps published HTML. pipal.file-artifact captures a project file’s name and bytes.

      • Documents

        Documents hold the current values alongside the transcript.

        • Pi documents

          pi.agent holds agent settings, pi.live holds live work, and pi.usage holds recorded tokens and spend.

        • pipal.chat

          Pipal keeps the chat title, archive flag, profile ID, deadline, and any saved workspace location, project name, and project scope here.

        • pipal.routines

          For a chat with routines, this document holds the schedule records and the alarm reference.

      • pipal.published-artifact

        Both publishing tools use this task-scoped document to remember the entry they wrote.

      • Tasks

        Pi schedules durable work, including tasks Pipal defines.

        • Pi tasks

          pi.generation runs the model request and owns the pi.tool tasks for its tool calls.

        • Pipal tasks

          Pipal creates a pipal.routine-alarm when a chat needs an alarm and a pipal.development-worker when it starts a worker. Pi schedules both. Signals reach tasks under a key.

    • Session documents

      pipal.chat-creation receipts are keyed by the lowercased creation request ID. pipal.worker-slots tracks worker capacity across conversations.

  • pipal.chat → Pi documents · The profile ID and pi.agent settings are saved together
  • Session documents → One conversation · A creation receipt points to the conversation
  • pipal.routines → Pipal tasks · The schedule document identifies the current alarm
  • pipal.published-artifact → Pipal entries · Remembers the published entry ID

pipal.chat

Pipal keeps the chat title, archive flag, profile ID, deadline, and any saved workspace location, project name, and project scope here.

Talks to

Open a box to see what it holds. The chat’s title and current model share a conversation identity, but live in different documents.

Go back to the title you changed. It lives in pipal.chat, a conversation-scoped documentNamed, typed JSON state that can change in a commit., meaning that each conversation can have its own value under that name. The current model lives in Pi’s pi.agent. At creation Pipal writes both in the same commitAn all-or-nothing write that can save transcript entries, document changes, and work together.. Pipal defines its durable chat records using Pi’s documents, entriesOne permanent record in a conversation’s transcript, such as a user message or a tool result., signalsA typed value delivered under a key to a live task, such as a person’s answer to an approval request., and tasksA unit of work whose state is saved so the harness can pick it up again.. view.ts index.ts

The client gets a conversation snapshotThe JSON view Pipal assembles for the browser from saved chat state, recent messages, and live work., a JSON view Pipal builds from those records. The title comes from pipal.chat, the chosen model comes from pi.agent, and the partial text comes from pi.live. The snapshot also says which location the chat uses and flags it if the pinned workspace is unavailable. A saved artifact appears as card metadata. Separate requests fetch the contents for download or, for HTML, preview. The shared shapes live in contracts.ts. view.ts index.ts

Deep diveHow broader state fits into the same record types

Search and cost tell you how the product reads the store. Pipal builds its own search index from transcript entries. For session statistics, it reads Pi’s usage ledger and assembles the numbers it exposes to the client. The context meter comes from a separate calculation in the snapshot, using the model’s context limit and a measurement that combines reported usage and Pi AI’s token estimates as available. index.ts session-info.ts context-window.ts

packages/core/src/view.ts
export type Metadata = {
project?: string; projectScope?: string; location?: WorkspaceChoice;
// …
};
export const Chat = defineDoc<Metadata>({
kind: 'pipal.chat', version: 1, scope: 'conversation', history: 'latest', fork: 'initial',
initial: () => ({ title: 'New conversation', archived: false, createdAt: 0, profile: '', deadline: 0 }),
checkpointWhen: () => true
});

A document can belong to a task or to the session that holds the conversations. A publish call records the entry ID in its task-scoped pipal.published-artifact document, so a replay can return the original ID. The session-scoped pipal.chat-creation document family keeps a receipt per keyed creation. The input signature and the resulting chat ID are recorded in the creation commit. If Pipal first has to open a project, it can reserve the signature and location in an earlier commit. pipal.worker-slots holds the owner task IDs occupying worker capacity across the session. web-artifacts.ts index.ts workers.ts

A pipal.workspace-decision signal carries the answer to an approval. pipal.routines-changed wakes an alarm a routine edit superseded. The pipal.routine-alarm task can commit a scheduled input, and pipal.development-worker owns the separate worker conversation. Pipal sends pipal.worker-change to wake the supervisor for a new assignment or notify a waiting tool when one finishes. The data model follows the identifiers that connect these records. workspace-approval.ts routines.ts workers.ts

You can now place a title, a tool decision, and a model request on either side of the boundary. What happens when one click has to cross it? Follow one message starts at Send and follows the request all the way back to the browser.

Recap

  • Pi supplies primitives for the transcript, model calls, tools, and recovery. Pipal composes them into a signed-in workspace with its own rules.
  • Installing an extension makes its definitions available. Pipal selects extensions per chat, checks configured tool grants at execution, and routes project calls using the chat’s pinned location and project binding.
  • Pipal’s durable chat state uses Pi’s record types, and Pipal projects those records into the browser’s JSON view.
Check yourself
  1. A tool from a still-installed configured extension wakes after its profile loses the grant. What happens at execution?
    • The tool runs under its original grant
    • Pipal checks the current profile and denies the call
    • The browser decides from its cached profile
    Answer and explanation

    Pipal checks the current profile and denies the call

    The runtime wrapper looks up the current profile each time execute runs, including a wake.

  2. Where can Pipal save a chat title and configure its model together?
    • In one Pi commit touching two documents
    • In a browser session cookie
    • In a schema migration that makes a table for the chat
    Answer and explanation

    In one Pi commit touching two documents

    Pipal puts the title in pipal.chat and configures the model in pi.agent through the same transaction.

  3. The same edit tool is offered for Docker and This machine. Which piece changes with the location?
    • Pi’s transcript entry format
    • The model provider’s tool protocol
    • Pipal’s implementation of the project operations
    Answer and explanation

    Pipal’s implementation of the project operations

    Pi supplies the edit tool and its environment interface. Pipal supplies the operations that reach a particular workspace.

  1. A tool from a still-installed configured extension wakes after its profile loses the grant. What happens at execution?

  2. Where can Pipal save a chat title and configure its model together?

  3. The same edit tool is offered for Docker and This machine. Which piece changes with the location?

In the source

Book contents

Search the book