---
name: help-how-to-create-template
description: Build a new Po layout (a web and optional phone template) in the person's own package, without Po's source code. Covers the template contract, the public building blocks, a complete starter, install, selection and checks.
---

# Create a template

A template is the whole Po app layout: where the session list, conversation, composer, activity and settings go. Build one only when the person wants a different arrangement. To restyle the layout they already use (backdrop, theme, CSS, composer or empty-state wrapper), use [Customise the template in use](../help-how-to-customise-template/SKILL.md); it is far less work and survives Po updates better.

Everything here works from an installed Po. You do not need Po's source. A complete starter that builds is in [references/minimal-web-template.md](references/minimal-web-template.md).

## How a template works

- Po (the host) owns the runtime, sessions, routes, persistence, sign-in, approvals and permissions. The template owns every normal piece of UI and nothing else.
- A web template is one React component, `app`, with no props. It reads state from Po's stores and the URL, and composes Po's ready-made views.
- Import only from `@agimon-ai/po-core/web`, `@agimon-ai/po-web-components`, `@agimon-ai/po-web-dashboard`, `@agimon-ai/po-web-dashboard/views`, `@tanstack/react-router`, `@tanstack/react-store`, `react`, and your own dependencies. A package can never import another package's code, so you cannot reuse Elegant's or Desktop's components; copy the pattern instead.
- Use the host actions the views and `useSessionRail` give you. Never call Po's HTTP API yourself or rebuild a privileged action.
- The phone has its own template contract (below). A web template has no effect on the phone.

## Files and ids

Set up the package exactly as in [Customise, step 1](../help-how-to-customise-template/SKILL.md), adding these dependencies at the version `po --version` prints: `@agimon-ai/po-web-components`, `@agimon-ai/po-web-dashboard`, plus `@tanstack/react-router` and `@tanstack/react-store` (the starter pins working versions).

```ts
// src/extensions/(frontend)/template/my-template.web.ts
import { defineWebTemplate } from '@agimon-ai/po-core/web';

import { myTemplate } from './_lib/definition';

export default defineWebTemplate(myTemplate);
```

```ts
// src/extensions/(frontend)/template/_lib/definition.ts
import type { WebTemplateFile } from '@agimon-ai/po-core/web';

import { MyDashboard } from '../_components/MyDashboard';

export const myTemplate = {
  label: 'My template',
  description: 'One line shown under Settings > Appearance > Layout.',
  contractVersion: 3,
  app: MyDashboard,
} satisfies WebTemplateFile;
```

- The template id is the route file's name in kebab case: `my-template.web.ts` is `my-template`. That id is what `web.template` holds. Appearance also shows the plugin id (package name without scope and leading `po-`) under the label; that is not the template id.
- `contractVersion` must be `3`. Version 3 moved remote access off the rail: it is the `rail-status` slot and its own overlays now, so a version 2 template is refused.
- `preview` is optional: a small component, with no props, that draws a sketch of the layout for the Layout card in Settings > Appearance. Draw it with theme token classes (`bg-po-panel`, `bg-po-dim`, `border-po-border`) so it follows the person's theme, and keep it static. Leave it out and the card shows text only. A preview that isn't a component is dropped and the template still loads.
- Po's own templates repeat the route file under `src/extensions/workspaces/(frontend)/template/` and `src/extensions/workspaces/sessions/(frontend)/template/`, each re-exporting the same definition. Do the same if the template should be offered in every scope.

## The app, piece by piece

Copy the starter, then change the layout. The parts every template needs:

**Root (`MyDashboard`)**: switch on `useDashboardRoute().kind`: `settings` shows your settings screen, everything else your main screen. Wrap both in `DashboardRendererProvider` with `thread`, `activity` and `transcript` renderers (`ThreadView`, `SessionActivity`, `SessionTranscriptView` with `watchDashboardTranscript`). Always mount the host dialogs next to it: `DialogOverlay`, `RefusedCard`, `CommandPalette`, `PluginSurface slot={HOST_SLOTS.overlay}`. Leaving one out hides approvals or plugin overlays, including remote access and pairing, which po-remote draws there.

**Route** (`useDashboardRoute()` from `@agimon-ai/po-web-dashboard`): `kind` is `home` (`/`), `session`, `settings`, `page` (`/page/<pageId>`) or `workspace`; with `sessionId`, `tabId`, `section`, `pageId`, `workspaceId`.

**Main area**, in this order of precedence:

| Route state                                            | Show                                                 |
| ------------------------------------------------------ | ---------------------------------------------------- |
| `pageId` set                                           | `<PluginPage pageId sessionId={null} workspaceId />` |
| `kind === 'workspace'`                                 | `<WorkspacePage workspaceId />`                      |
| `kind === 'home'` and sessions exist                   | `<HomePage />`                                       |
| a plugin tab (`webTabs(sessionId)` or a transient tab) | `<tab.panel {...usePluginSlotProps(sessionId)} />`   |
| no sessions (`useNoSessions()`)                        | `<WelcomePanel />`                                   |
| otherwise                                              | `<Timeline />`                                       |

Pages, Home and the workspace page draw their own header; otherwise show `<TopBar />`. Below the content put `<Composer />` (hide it for pages, no sessions, and tabs without `retainComposer`) and `<SelectionBar />` (the mode and model pickers). `HomePage`, `WorkspacePage` and `PluginPage` accept `onShowSessions` when your rail is a drawer.

**Activity**: `<ActivityDock onClose onOpenContent />`. Its open state is `uiStore`'s `dockOpen`, changed with `setDockOpen`. Session MCP's tools face is contributed by po-session-mcp like any plugin face.

**Session list**: `useSessionRail({ onDismiss })` returns everything to draw (from `@agimon-ai/po-core/web` type `WebTemplateRail`):

- `workspaces[]`, each with `id`, `name`, `kind` (`'session'` means draw its sessions without workspace chrome), `legacy`, `available`, and `sessions[]`.
- Each session has `id`, `name`, `active`, `nested` (indent once), `status`, `awaitingInput`, `waitingCount` (things waiting on the person; show as a count, in rose rather than red), `restarting`, `git`, `groups` and `profile`.
- `homeActive`, `pluginContent` (render it: plugins fill the rail), and `scrollRef` (attach it to the scrolling element so position survives remounts).
- `actions`: `openSession`, `createSession(workspaceId)`, `createGeneralSession?`, `openHome`, `openSettings`, `renameSession`, `restartSession`, `removeSession`, `resumeSession`, `openWorkspace?`, `openWorkspaceSettings`, `deleteWorkspace`, `openAddWorkspace`, `closeAddWorkspace`, `addWorkspace({ name, path? })`, `listDirectory`, `searchDirectories`, `renderSessionMenuItems(sessionId)`, and more. Result-returning actions resolve `undefined` on success or `{ error }`.
- **Rail status**: place `<PluginSurface slot={HOST_SLOTS.railStatus} sessionId={null} />` where status controls belong, inside an element with `data-rail-status` naming the spot, for example `<div data-rail-status="elegant-action" className="contents">`. po-remote draws its button or banner to match the spot it finds: `elegant-action`, `elegant-banner`, `advanced-action`, `advanced-banner` or `desktop-action`. Your own template can reuse those names.
- While `addWorkspace` is set, render your add-workspace dialog at the layout root (not inside a drawer that can unmount). Always mount `<SessionRailDialogs />` for new-session, resume and move.

**Settings**: copy the starter's `MySettings`. It routes `section` through `settingsSection`, shows `SettingsMenu` plus the shared sections (`ProviderSettings`, `ClientDevices`, `AppearanceSettings`, `NotificationSettings`, `ImageSettings`, `PresetSettings`, `AccountSettings`), plugin sections (`ContributedSettings`, `SettingsPanelHost`, which is how Remote control and Session MCP appear) and the Workspaces tab (`RepositoryWorkspace`). Keep `AppearanceSettings`: it is how the person leaves your template.

**Conversation layout per turn** (optional): `<Timeline renderTurn={MyTurn} showThinking={false} />`. `MyTurn` receives `{ turn, sessionId, slotProps, statuses, renderEntry }`; call `renderEntry(entry)` for each entry, and `renderEntry(entry, { suppressOutputs: true })` when you show that call's images and Apps elsewhere. `toolOutputDescriptors(entry, slotProps, statuses)` from the views returns those outputs (`{ id, title, content }`) for a gallery, including Apps from calls made inside `exec`. Never show the same output in two places at once: an App mounted twice opens two connections.

## Keep what customisations rely on

People's own packages customise every template through these, so a new template must keep them working:

- Mark your layout roots with `data-po-region`: `rail`, `content`, `activity`, `settings` (`TopBar`, `Composer` and `SelectionBar` already mark `header`, `composer` and `controls`). Their CSS and the backdrop's translucency target these.
- Use `<Composer />` and `<Timeline />`: they render the `composer-region` and `empty-state-region` fills. A hand-drawn composer silently drops them.
- Style with Po's tokens (`bg-po-panel`, `text-po-dim`, `var(--po-cyan)`), never fixed colours, so every theme works. Red is for real failures; rose (`po-magenta`) for the person's attention.
- Po draws the backdrop and ambient fills itself, outside your app.

## A phone template

Optional, and separate from the web one. Without it the phone keeps its bundled layouts.

```ts
// src/extensions/(frontend)/template/my-template.native.ts
import { defineNativeTemplate } from '@agimon-ai/po-core/native';

import { myNativeTemplate } from './_lib/nativeDefinition.native';

export default defineNativeTemplate(myNativeTemplate);
```

```tsx
// src/extensions/(frontend)/template/_lib/nativeDefinition.native.tsx
import type { NativeTemplateFile, NativeTemplateSessionsProps } from '@agimon-ai/po-core/native';
import { SessionScreen, SessionsScreen, type SessionScreenProps } from '@agimon-ai/po-native-dashboard';

function MySessions(props: NativeTemplateSessionsProps) {
  return <SessionsScreen {...props} quiet />;
}

function MySession(props: SessionScreenProps) {
  return <SessionScreen {...props} composer={{ ...props.composer, quiet: true }} />;
}

export const myNativeTemplate = {
  label: 'My template',
  description: 'One line shown in the phone settings.',
  contractVersion: 2,
  screens: { sessions: MySessions, session: MySession },
} satisfies NativeTemplateFile;
```

- Both screens are required. Start from `SessionsScreen` and `SessionScreen` and change them through their props before drawing your own.
- The app keeps pairing, navigation, tabs, the Activity stack and Home. The session screen may set only its header title and right control (`setHeader`).
- Phone files may import only: `react`, `react-native`, `react-native-unistyles`, `@tanstack/store`, `@agimon-ai/po-core/native`, `@agimon-ai/po-native-components`, `@agimon-ai/po-native-dashboard`, `@gorhom/bottom-sheet`, `expo-symbols`, `expo-haptics`, `expo-clipboard`, `@expo/vector-icons/MaterialIcons`, `@shopify/flash-list`, `@react-native-segmented-control/segmented-control`, `react-native-safe-area-context`.
- A screen that throws falls back to the bundled layout. A `contractVersion: 1` layout is refused.
- Selected with `native.template` (separate from `web.template`).

## Install and select

1. Install, build and add the package to `presets.yaml`, then `po sync`, exactly as in [Customise, step 3](../help-how-to-customise-template/SKILL.md).
2. Open Settings → Appearance → Layout. Your template is listed by its `label`. Choose where it applies ("Applies to": global default or one workspace), select it, and click **Set as default**. Or set it in config:

   ```yaml
   web:
     template: my-template
   ```

   The global default lives in the host config, `~/.po/config.yaml`; a workspace value in `<repo>/.po/config.yaml` overrides it. If the template does not appear after selecting it globally, check for a workspace value first.

3. Refresh the browser.

## Check it

Build success only proves it compiles. Look at each of these rendered, at desktop and phone widths:

- Home (`/`), a session conversation while the agent runs, a plugin tab, `/page/<id>`, a workspace page, and settings (including switching back to another template in Appearance).
- New session, add workspace, resume, an approval prompt, the command palette.
- The activity dock opening and closing; a tool call with an image or MCP App.
- A theme switch and a customisation package (backdrop, composer fill) on top of your template.

Report what you saw rendered separately from what only built.
