A tour of the repository

Three packages, two seams between them, and how to find the file that does a thing.

beginner6 min read

Say you want to change what happens when you press Send. You could start by searching the whole checkout. It’s quicker to decide which part of the send you mean. The button lives in one package, the request in another, and the rules for accepting the message in a third.

In this chapter

  • Find your way from the root to the three packages
  • Follow the two interfaces a browser action crosses
  • Pick a source file and a test for the behavior you’re tracing

Start with the three packages

Inside the checkout
  • packages/
    • core/
      Conversation rules
      • src/
        • index.ts
          Runtime and message rules
          Start at createRuntime() for startup and submit() for a send.
        • contracts.ts
          Shared shapes and helpers
          Look here for ConversationSnapshot or messageLimit.
        • view.ts
          Turns saved state into views
      • test/
        Runtime and policy tests
    • server/
      HTTP and host adapters
      • src/
        • main.ts
          Starts the server
        • app.ts
          Defines the routes
          Look here for HTTP validation and the call into the runtime.
        • config.ts
          Reads operator settings
        • workspace-locations.ts
          Opens locations and routes tool calls
        • project-tool-definitions.ts
          Shared tool definitions for Bash and Git clone
        • project-shell.ts
          Runs isolated Docker tools
        • public-web.ts
          Optional host tools for Exa search and Jina Reader
      • test/
        Routes, startup and tools
    • web/
      Svelte browser client
      • src/
        • main.ts
          Mounts the app
        • App.svelte
          The chat workspace
          This is where a send starts and where the selected chat’s view arrives from its event stream.
        • lib/
          Components and client helpers
          • DeveloperWorkspace.svelte
            The Settings → Workspace panel
          • workspace-choice.ts
            Location options, remembered projects and Docker shell hint
      • test/
        Client behavior tests
  • agents/
    Bundled profiles
  • patches/
    Pi Durable’s generation retry patch
  • docs/
    Operator guides and decisions
  • deploy/
    Deployment examples
    • linux/
      Caddy and systemd files
  • examples/
    Code to read or adapt
    • tools/
      • clock.mjs
        A host tool example
  • scripts/
    Project utilities
    • ui-extension.mjs
      Enables or disables UI extensions
  • tests/
    Across package boundaries
    • browser/
      Browser flows
    • recovery.test.ts
      Process-death recovery
    • sse-delta.test.ts
      Stream updates and reconnects
  • config.example.toml
    Example operator settings
  • package.json
    Commands for the whole checkout
  • pnpm-workspace.yaml
    Packages and dependency pins
  • tsconfig.base.json
    Shared TypeScript settings
    • Conversation rules
    • HTTP and host adapters
    • Svelte browser client
  • agents/
    Bundled profiles
  • patches/
    Pi Durable’s generation retry patch
  • docs/
    Operator guides and decisions
  • Deployment examples
  • Code to read or adapt
  • Project utilities
  • Across package boundaries
  • config.example.toml
    Example operator settings
  • package.json
    Commands for the whole checkout
  • pnpm-workspace.yaml
    Packages and dependency pins
  • tsconfig.base.json
    Shared TypeScript settings
This is a selected tree of the pinned checkout. Open a folder or select a file with a note to see where to start.

Open packages/web/src/App.svelte if the thing you’re looking for is on the page. The browser starts from main.ts, which mounts that component. Inside App.svelte, you can follow a send from the draft through the request. Look for select() in the same file to see how the client watches a chat and applies its updates. Smaller pieces, such as the model picker, live in src/lib/. Open DeveloperWorkspace.svelte there for the Workspace tab in Settings. App.svelte DeveloperWorkspace.svelte

Open packages/server/src/main.ts if the question is what Pipal starts with. It reads the settings and profiles, sets up the available tools, and gives the runtime to Hono. Move to app.ts to see what the browser can ask the server to do. For project tools, follow loadWorkspaceLocations() to see how the host opens a locationThe place a chat uses for project tools, either the Pipal host, an account reached over SSH, or a Docker project. and routes a call. For Docker, follow command execution into project-shell.ts. main.ts workspace-locations.ts

Open packages/core/src/index.ts if the question is whether a message should be accepted. Core applies the rules for the conversation and uses Pi Durable to keep its state. Core also has tools of its own. For instance, the read-only workspace tools are in workspace.ts. Start with the name the assistant sees and trace it to the code that runs it. index.ts workspace.ts

Two files at the root are worth keeping open as you read. pnpm-workspace.yaml tells pnpm where the packages are. package.json tells you what commands run across them. Start with the root manifest when you want to find out what pnpm build builds or what pnpm test runs. package.json

A send crosses two interfaces

How the packages meet
  • Pipal packages
    • packages/web

      The browser sends HTTP requests and reads an event stream. It imports shared definitions and helpers from core.

    • packages/server

      Hono translates HTTP requests into calls on the object returned by createRuntime().

    • packages/core

      Core owns the conversation rules. The server calls it directly as TypeScript in the same process.

  • packages/web → packages/server · HTTP and event stream
  • packages/server → packages/core · Direct function calls

packages/server

Hono translates HTTP requests into calls on the object returned by createRuntime().

Talks to

Select a package to see how it talks to its neighbor. The browser speaks HTTP. Hono calls the runtime in the same process.

Press Send and the browser posts the message as JSON, a text format for the fields it sends. Hono reads that request and calls runtime.submit(). The response is a receipt with HTTP 202. The browser gets the conversation and reply on a separate event streamAn open HTTP response that carries updates from the server to the browser., which it watches as long as the chat is selected. app.ts App.svelte

The first Send from a new draft takes an extra step. The browser posts the draft settings to /api/v1/conversations. Core creates the chat and pins its location and any project binding. The browser starts watching the chat if it’s still selected, and posts the message to /api/v1/conversations/:id/messages. Follow one message traces both requests and the saved reply. App.svelte index.ts

Both ends need to agree on what a conversation update looks like. That agreement is the contractThe agreed shape of the data that two parts of Pipal send to each other.. Look in packages/core/src/contracts.ts for the shared TypeScript types, limits, and helpers. For example, sharing the message length limit lets the browser check what you typed against the same number core enforces. contracts.ts

Say you change the message limit. Sharing the number lets the browser give you immediate feedback. Core still checks the request when it arrives. A direct API caller can skip the browser check, and attached text files count toward the same limit in both places. App.svelte index.ts

Deep diveWhere the in-process interface starts

main.ts imports createRuntime from @pipal/core, whose root export points at src/index.ts. The runtime returns operations such as submit, history, and watch. PipalRuntime derives its type from that return value. Hono receives it through the app options and calls it directly. A change to how submit decides whether to take an input belongs in core. A change to how that outcome is represented over HTTP belongs at the route and its error handling. package.json main.ts index.ts

packages/server/src/app.ts
api.post('/conversations/:id/messages', async c => {
const { text, requestId, attachmentIds, textFiles } = await body(c, message);
const files = attachmentIds?.length
? { ids: attachmentIds, prepare: (vision: boolean) => uploads.prepare(attachmentIds, vision) }
: undefined;
return c.json(await runtime.submit(c.req.param('id'), text, requestId, files, textFiles), 202);
});

The browser’s apiPath() prefixes routes with the build’s base URL and api/v1/. App.svelte imports types and executable helpers from @pipal/core/contracts. ChatGPTLogin.svelte imports a separate helper to parse the sign-in redirect. The runtime stays in the server process. api.ts App.svelte ChatGPTLogin.svelte

Find the file by the question you have

I want to find… Open…
A route accepting a request packages/server/src/app.ts
A rule for accepting a message packages/core/src/index.ts, at admission()
The shape of a conversation update packages/core/src/contracts.ts, at ConversationSnapshot
The chat screen packages/web/src/App.svelte
The Bash tool for a Docker project packages/server/src/project-shell.ts
Developer’s optional Exa search and Jina Reader tools packages/server/src/public-web.ts
A server default packages/server/src/config.ts

If you want to change what Chat or a specialist is asked to do, open agents/. Each profile file begins with settings and continues with the instructions. The runtime loads these files on startup, which is why a change there needs a restart. Guides on how to operate the project live in docs/, and the files for the Linux deployment live in deploy/linux/. main.ts

Find a test that crosses the same boundary

Look in a package’s test/ directory if you’re changing one piece. For example, packages/server/test/app.test.ts sends requests to the app and checks what the browser would get back. The root tests/ directory covers work that crosses boundaries, including recovery after a process dies. Look in tests/browser/ for cases that drive the page itself. Changing Pipal covers running the checks. app.test.ts recovery.test.ts

Deep diveHow the tests choose what to exercise

The app test subscribes to a conversation, sends a message, waits for the run to start, closes the stream, and opens a fresh one. It asserts that the accepted user message and assistant reply are both in the result. The recovery suite starts a separate process and stops it during work. Its replacement opens the saved store and verifies the recovered result. These test different boundaries even though both start with a send. app.test.ts recovery.test.ts

The root script runs Vitest for pnpm test and Playwright for pnpm test:e2e. Package checks type-check the source without producing a server build; the root check also covers the shared tests. That gives you distinct places to look for a type mismatch, a route regression, or a browser flow. package.json tsconfig.base.json

The workspace tree also holds tests for behaviors that do not need a browser. Core’s package tests can exercise runtime decisions directly, and the separate stream suite checks the versioned updates that cross the HTTP boundary. Before adding a browser case, check whether the behavior lives at one of those smaller boundaries. runtime.test.ts sse-delta.test.ts

The TypeScript configuration supports the same split. The shared compiler settings allow explicit TypeScript extensions and set noEmit, so a type check does not create a second copy of the server sources. The web package builds the files that the browser actually loads. tsconfig.base.json package.json

The checkout tells you where to read. Where do the conversation, the model, and a file the assistant edits actually live? Where everything lives and runs moves from the source tree to the machines.

Recap

  • Web owns the screen, server owns HTTP, and core owns conversation rules.
  • The browser uses HTTP and an event stream. Hono calls the runtime directly.
  • Use the question you have to pick the file, then find a test at the same boundary.
Check yourself
  1. You want to change how the message route reads a request. Where do you start?
    • app.ts in server
    • App.svelte in web
    • agents/chat.md
    Answer and explanation

    app.ts in server

    The Hono route reads the request and hands the input to core.

  2. You want to check whether a busy chat can accept another message. Which code decides?
    • The sidebar
    • Core’s admission rules
    • The Caddy configuration
    Answer and explanation

    Core’s admission rules

    Core applies the conversation rules. Hono carries the result back to the browser.

  3. Where would you look for a test that kills Pipal during a reply?
    • The profile folder
    • The server manifest
    • tests/recovery.test.ts
    Answer and explanation

    tests/recovery.test.ts

    The recovery suite kills a child process and opens the same store in a fresh process.

  1. You want to change how the message route reads a request. Where do you start?

  2. You want to check whether a busy chat can accept another message. Which code decides?

  3. Where would you look for a test that kills Pipal during a reply?

In the source

Book contents

Search the book