agentleFS
PydanticKnown publisherpydantic/pydantic-ai/src/pydantic_ai_pax/AGENTS.md

pydantic-ai / pydantic_ai_pax

AGENTS.md21k starsChanged 5 days agoMITView on GitHub

Read this before touching src/pydantic_ai_pax/. The repository-level AGENTS.md still applies (no em-dashes, no Any, pyright strict, keyword-only arguments, 100% branch coverage). This file adds what is specific to the terminal shell. A thin terminal around any Pydantic AI agent. It reads a prompt, runs the agent, streams the answer, and repeats. Everything beyond that is a plugin, including the default coding tools. The three layers, and who owns what: If a change needs the agent loop to behave differently, propose…

  • Reads credentials

Trending

More talk lately.about the whole repository

Jan 2026: 0 mentionsFeb 2026: 2 mentionsMar 2026: 2 mentionsApr 2026: 31 mentionsMay 2026: 7 mentionsJun 2026: 0 mentionsJul 2026: 2 mentionsAug 2026: 3 mentionsSep 2026: 2 mentionsOct 2026: 5 mentionsNov 2026: 3 mentionsDec 2026: 0 mentions
Jan 2026Jul 2026Dec 2026
Mentions a month of the pydantic/pydantic-ai repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about pydantic/pydantic-ai

The biggest 5 of 85 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 85

Talked about on GitHub, YouTube, Bluesky and Hacker News (85 times).

On GitHub · 50

45 more on GitHub

On YouTube · 23

18 more on YouTube

On Bluesky · 7

2 more on Bluesky

On Hacker News · 5

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

28 rules. About 0 are common, 9 are distinctive, and 19 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 19

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read this before touching src/pydantic_ai_pax/.

    line 3
  2. Distinctive:

    If a change needs the agent loop to behave differently, propose it in core.

    line 21
  3. Very specific:

    Integrations are deferred: Only the coding loop and run plumbing are eager.

    line 200
  4. Very specific:

    Default-on CLI .env loading is a deliberate exception to this repository-content trust rule: it assumes trusted launch and parent …

    line 254
  5. Very specific:

    A load failure leaves the session as it was: Import, construction, or get_* errors are reported and the plugin stays unloaded.

    line 258
  6. Very specific:

    Add the event dataclass and an on_* method (or a get_* method with a no-op default) to Plugin, and route it in _HANDLERS or collect.

    line 305
  7. Very specific:

    Document it in PLUGINS.md in the table it belongs to, and in docs/declarative-plugins.md if it changes the design.

    line 308
  8. Very specific:

    Every key mutates immediately and replace_items redraws.

    line 323
  9. Very specific:

    Keep searchable field lists without eligible rows on type-to-filter with uppercase R reset.

    line 349
  10. Very specific:

    Keep nonsearchable field lists without search and with lowercase r reset.

    line 350
  11. Very specific:

    Do not define new palettes.

    line 396
  12. Very specific:

    Do not add broad backwards-compatibility shim modules for internal file moves.

    line 440
  13. Very specific:

    Keep documented plugin-author paths (pydantic_ai_pax.plugins and pydantic_ai_pax.commands) intact.

    line 441
  14. Distinctive:

    Keep files concise - we don't need any 10,000 line files.

    line 459
  15. Distinctive:

    Check whether an existing interactive command already completes the operation on Windows.

    line 463
  16. Distinctive:

    If a new non-interactive path cannot observe completion because Pax must exit first, fail early with a non-zero status and name the working …

    line 464
  17. Very specific:

    Add Windows-specific orchestration only when a concrete requirement cannot use the existing path.

    line 467
  18. Very specific:

    When adding or modifying a Pax CLI UX feature, test every affected UX feature with your changes in a fresh tmux window before opening a PR.

    line 472
  19. Very specific:

    Test a moment by loading the plugin with load_plugin and firing the event from the shell path that owns it (or LoadedPlugin.dispatch).

    line 478
  20. Distinctive:

    Before adding, removing, or renaming a setting, changing its type, meaning, or default, or changing the SQL schema, consider upgrades, …

    line 486
  21. Very specific:

    Add regression cases to tests/test_settings_compatibility.py and affected CLI tests using the previous stored format.

    line 493
  22. Distinctive:

    Verify older databases load with documented defaults for missing settings and preserve existing preferences, plugin declarations, and model …

    line 496
  23. Distinctive:

    Keep validation strict for known values, new writes, and plugin declarations.

    line 501
  24. Distinctive:

    Verify rejected values and unsupported schema versions leave stored data intact.

    line 505
  25. Distinctive:

    If a change introduces a migration, test failure rollback as well as success.

    line 506
  26. Very specific:

    When a plugin setting's valid values or meaning depend on code other builds may lack, add a feature name to SUPPORTED_FEATURES in …

    line 507
  27. Very specific:

    Run from the repository root.

    line 520
  28. Very specific:

    Keep composer question state on its SessionRuntime, not on the shared terminal.

    line 627

≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Pax guide for AI code assistants

Read this before touching src/pydantic_ai_pax/. The repository-level AGENTS.md still applies (no em-dashes, no Any, pyright strict, keyword-only arguments, 100% branch coverage). This file adds what is specific to the terminal shell.

What Pax is

A thin terminal around any Pydantic AI agent. It reads a prompt, runs the agent, streams the answer, and repeats. Everything beyond that is a plugin, including the default coding tools.

The three layers, and who owns what:

LayerOwnsNever does
Pydantic AI corethe agent loop, hooks, events, toolsetsknow Pax exists
pydantic_ai_harnessreusable capabilities (Coder, Shell, ...)print to a terminal
pydantic_ai_paxthe prompt loop, rendering, /commands, plugin loadingreimplement a core hook

If a change needs the agent loop to behave differently, propose it in core. If it is a reusable behavior with no terminal in it, it belongs in harness. Only the shell itself lives here.

The plugin model

A plugin is a Plugin subclass, or a bare capability class. It is declarative in the same way core's AbstractCapability is: every contribution is a method with a default that contributes nothing, and a plugin overrides only what it needs. get_capabilities for tools, instructions, and agent-run hooks (a Hooks capability, or @on_event on your own capability); get_commands for /commands; render for custom output; get_status_segments, get_spinners, get_model_providers, and get_side_panels (pages the web UI shows beside the chat); configure for a settings menu; on_session_start, on_session_end, on_turn_start, on_turn_end, on_conversation_changed, on_command_end, on_plugin_load_failed, on_task_progress, on_fork_end, and on_install_progress for Pax's own moments; prepare for async reads the get_* methods depend on. The settings model is the class's type parameter (Plugin[Settings]), validated into self.settings. self.host is a PluginHost, the plugin's runtime context (console, conversation, session_id, status, full screen, saved settings, the prompt through send_input/interrupt/complete, the saved sessions, the delegated tasks, and read-only setting(KEY)); it registers nothing. docs/declarative-plugins.md records the design. PLUGINS.md is the user contract. If code and PLUGINS.md disagree, fix one so they agree in the same PR.

Rules for the plugin API

  • Declare, do not register. A plugin returns what it offers from get_* methods, which the loader calls once per load (collect), after awaiting prepare(). No registration calls, no module-level dicts, no import-time side effects. Tests call load_plugin(PluginClass, host); it raises TypeError for a plugin that overrides prepare, whose tests call from_host, then await plugin.prepare(), then collect.
  • One method per moment, one typed event per method. A handler never receives *args, **kwargs, dict, or context: object = None.
  • No string sub-dispatch. A handler does not receive event_type: str and switch on it. Use the event class as the key.
  • One async spelling. No _sync or _async pairs.
  • Observers return None. Deciders mutate the event (event.text = ..., event.cancel()). Nothing collects a list of return values.
  • Fail closed, one way. A raising handler on a decidable moment cancels the action and reports the error. No per-registration "fail open" flag.
  • Sign in only when the user asks. Loading waits for every plugin and a run waits for its tools, so neither may open a browser or wait on a sign-in. Use plugins/sign_in.py: a SignInMethod (mcp.OAuthSignIn for MCP OAuth), sign_in_now from a menu or /NAME login, and no tools while signed out.
  • A built-in's per-run capability is a WorkspacelessCapability. A bare capability function might return a sandbox, so local_workspace() attaches the launch directory only after every for_run, and harness Skills (which reads its libraries in for_run) fails the turn. Wrap a function that never returns a workspace in runtime/session.py's WorkspacelessCapability. The one exception is a built-in that moves some conversations elsewhere, as sandbox does: subclass ConversationWorkspace and answer supplies from the run's own history, the same history get_workspace resolves from. Answer shell_line_workspace from that history too, so ! lines run where the runs do.
  • Pax moments are on_<subject>_<moment> (on_turn_start). Core hooks stay core's, reached through a Hooks capability. Do not wrap a core hook in a plugin method.
  • Payloads are kw-only dataclasses. Not BaseModel. Pydantic is for the settings JSON boundary only.
  • No getattr/hasattr on a plugin to discover what it supports. It returned the thing from a get_* method or it did not; has_configure and has_render compare against the base-class default.
  • Only shell-owned moments. on_session_start, on_session_end, on_turn_start, on_turn_end, on_conversation_changed, on_command_end, on_plugin_load_failed, on_task_progress, on_fork_end, on_install_progress. Startup load failures happen before an agent run, so core's before_run cannot observe them. The loader reports them after trying every enabled plugin so observability can receive failures that preceded its own load. Which conversation the shell holds, and its title, change between runs (/new, /resume, background naming); core only sees a conversation_id per run. Session._publish is the one place ConversationChanged is fired from. /commands never reach the agent, so no core hook sees them; the shell fires CommandEnd around _execute_command, outside the scope Esc cancels: a refused /plugins fires its refusal instead, and a cancelled command fires nothing. A delegated task's own events never enter the parent run's stream, and a background task outlives that run, so no hook of the parent sees them; Tasks.observe, the harness owner's one observer, fires TaskProgress. A /fork runs a separate session in the background, so its run's hooks belong to that session and nothing of the parent sees it end; Forks._run fires ForkEnd. /update now is a command, so no core hook sees its install either, and CommandEnd comes only once uv has finished; Updates.command fires InstallProgress as it goes. Additional moments need the same justification: say which core hook you checked and why it does not fit.

Loading and unloading

Plugins load and unload while Pax runs. The rules that make that safe:

  • One LoadedPlugin per plugin. It holds the instance and what its get_* methods returned, so unloading is "discard this LoadedPlugin". No callback -> owner map, no scanning registries for a plugin's name.
  • A running agent run never changes its plugins. Core binds capabilities once per run, so /plugins (an args_during_turn command) may load and unload mid-turn, but the run keeps the snapshot run_turn bound. SessionPlugins.turn() defers on_session_end of plugins unloaded meanwhile until the run is over, shielded from cancellation. Do not swap capabilities inside a run; that needs core support.
  • Plugins are per live session; declarations are per process. Each live session's SessionPlugins (plugins/loader.py) holds its loaded instances, guards, and deferred ends, and is its host.plugins. They all join the process's ProcessPlugins (plugins/process_plugins.py, held by ClaiProcess): declarations, staged /plugins add settings, open settings menus, the change lock, and imports. enable, disable, remove, and reload run in the session they came from under that lock (ProcessPlugins.change), then every other live session follows them, also when the origin failed; /plugins add and settings edits are followed once saved. Each session follows under the turn() rule above. PluginLoader is the former name of SessionPlugins, kept for tests; built with store= and no process=, it gets a process of its own, as one-session hosts do.
  • Plugin.scope = 'process' builds a plugin once per process. observability, workspaces, and web are. The first session to load one builds it and fires on_session_start; it then joins every live session (capabilities, commands, and each moment, dispatched per session with host.live.current() naming it). It ends once, when unloaded (after every running turn that bound it) or when the last session closes; sessions load a name one at a time, so it is built once. Its host's session_id, workspace, tasks, plugins, setting, send_input, submit_prompt, interrupt, and ask_in_composer follow the session being handled (moments, commands, and runs set it); its other attributes are the loading session's. restart keeps it. A process plugin that includes a session plugin (web and ask_user) keeps it off in every session. Plugin.scope, host.live, and the LiveSession/LiveSessions protocols are public: PLUGINS.md's "Several live sessions" is their contract, with the six rules every plugin follows. Change them as public API, and update that section in the same PR.
  • A process holds many live sessions; a conversation is live in one. ClaiProcess.live (runtime/live_runtimes.py) is host.live. create_shell adds each SessionRuntime and SessionRuntime.close removes it; close a runtime with close, never with loader.close alone. open returns the session already holding a conversation, and Session.resume refuses one another session holds or is resuming (LiveRuntimes.claim). Sessions open and new start run as tasks of serving, in their own directory, with Interrupts(signals=False), refuse /reload and /update now unless the terminal shows them (only that session, or the one Pax started with, restarts it, never from another folder or while another session runs a turn, and a failed /reload continues the shown session's conversation), and close after IDLE_AFTER (an hour) with no turn, command, queued input, fork, task, watcher, or terminal focus. /set of anything but model and run.* reaches every live session (CommandContext.adopt) unless its project file sets it. There is no turn cap.
  • Per session on SessionRuntime, per process on ClaiProcess; never the other way. ClaiProcess (runtime/process.py) holds what exists once: the stores, ProcessPlugins, the task owner and router, the namer, the Codex providers, and live. SessionRuntime (runtime/session_runtime.py) holds what each live session has: its Session, commands, SessionPlugins, status, interrupts, input queue, forks, and folder (Session.workspace, which plugins read as host.workspace). Terminal holds what only the terminal has, whichever session it shows. A per-session value on ClaiProcess leaks between sessions; a process value on a runtime is built twice or closes with one session. Module-level mutable state is process state too, so keep it off modules. Never call os.chdir or read Path.cwd() for a session's folder after startup: pass Session.workspace (or host.workspace). Path.cwd stays only as the default of hosts built outside the shell, and for --worktree setup and cleanup around the session.
  • The terminal shows one live session at a time. Terminal (ui/prompt/terminal.py) owns the terminal console, the LivePrompt, the line prompt, the transcript, input history, and pasted images. Only the session shown (SessionRuntime.terminal, LiveRuntimes.focused) reads the editor, prints to the console, and takes Ctrl+C (Interrupts.focus); the others print nowhere (Terminal.session_console) and read their inbox. chat sets live.build, so the web UI opens sessions beside the terminal's. /resume of a conversation another live session holds shows that one (Sessions.show_live), mid-turn too, and never forks it; the one shown before stays live, and the session Pax started with is closed for idleness like any other while hidden. Prompts queued for a session stay its own when the terminal shows another. pax --web keeps its terminal on the session it started with. With one live session nothing changes, and the toolbar adds N live only for more.
  • Load runs on_session_start for that plugin; unload runs on_session_end. A plugin cannot tell whether it was loaded at startup or later, and must not need to.
  • reload is unload, re-import, load. Drop-in entry modules use fresh source. Installed modules use importlib.reload, which retains globals absent from the new source. Plugins keep their state on the instance, set up in __init__.
  • Instruction order is capability order. Placement is a core CapabilityOrdering (position, wraps, wrapped_by), not a Pax list.
  • Registration is idempotent per name. "Active for the next prompt" is the natural unit. Stock agents are rebuilt when the capability snapshot or Pax's unchosen default model changes. Plugins are bound at construction so self-delegation carries their tools, instructions, and guardrails, and the default model is bound as the agent's own so a capability can replace it. Supplied agents still receive plugins per run (agent.run(capabilities=...)) and are never rebuilt.
  • Shipped plugins register first, in declared order. The menu's alphabetical order is for scanning only. Registration order is the order instructions, renderers, and status segments are consulted in, so coder's guidance leads the prompt.
  • Integrations are deferred. Only the coding loop and run plumbing are eager. The agent docs capability (pax_customization) and every hosted integration plugin pass defer_loading=True on the capability they build (on the one a for_run function returns, never on the DynamicCapability), so each costs one catalog line until the model calls load_capability. A new integration does the same.
  • Built-ins are declarations, not code paths. DEFAULT_PLUGINS in config/builtins.py lists the library's built-ins (re-exported by app.py, kept apart so pax plugins can toggle one without importing the shell); STOCK_PLUGINS opts the CLI-owned agent into delegation without changing supplied-agent defaults. Pax ships enabled (coder, ask_user, repo_context, compaction, persistence, observability, hooks). The loader treats them like drop-ins with the lowest precedence: a store declaration with the same id replaces one, disable persists an override, remove resets it. Do not special-case Coder anywhere else; the agent from create_agent() has no coding tools of its own. coder is declared with repo_context: false because repo_context binds harness RepoContext itself; keep it that way or AGENTS.md reaches the model twice. When a built-in takes the id of a row the former harness catalog offered, add that old row to RETIRED_BUILTINS in plugins/process_plugins.py, so a user's saved toggle of it maps to the built-in instead of outranking it.
  • open_stock_agent loads coder, repo_context, and compaction only. Add a built-in to that list only when it needs no terminal and reads nothing from the user's Pax configuration directory. Hosts rely on a configuration that the user's saved settings cannot change.
  • Project declarations rank just above built-ins and start off. .clai/settings.json (project_settings.py) may declare plugins; the loader takes them as project=, every one enabled=False, because a repository must not run code as the user on launch. /plugins enable is the approval and persists the approved declaration in the store. Precedence is store, drop-in folder, project, built-in. Pax never writes the project file. The exception is a factory in APPROVED_AS_WRITTEN (plugins/process_plugins.py), such as the hooks table's project_hooks: its declaration is what runs, so a stored approval with the same id and factory that differs from the project's is stale and the project's, off, replaces it. A drop-in or a user's own plugin under that id is never replaced. /plugins enable also records the SHA-256 of each repository file the declaration runs (ProcessPlugins.project_files: a file plugin's own file, and the programs inside the project a hooks table runs) in the store's approved_files table, beside plugins so older builds never read it. An APPROVED_AS_WRITTEN approval whose files differ is stale too, and import_module refuses a project file whose bytes differ, executing the bytes it checked. HooksPlugin compares each program at spawn with the approved contents (read through host.settings_database), stopping a before_tool call on a mismatch. approve refuses a file it cannot read, so an empty digest never matches.
  • Project settings beyond display wait for approval. .clai/settings.json keys in SAFE_PROJECT_KEYS (display.*) apply at once; every other key is pending until /project approve stores that exact value for the project root in the store's approved_project_settings table, so a changed value waits again. A new Settings field waits too unless added there on purpose. A run.permissions no wider than the user's own applies at once, since it cannot widen anything. update_channel is user-only, rejected in a project file. Approval is a /command only, never a pax subcommand, because the agent can run pax from its shell. For the same reason pax config refuses a change widens (refuse_widening), and pax plugins only lists. Unapproved instructions go to the model as ProjectInstructions user-channel data, never as Session.instructions. Default-on CLI .env loading is a deliberate exception to this repository-content trust rule: it assumes trusted launch and parent directories, without plugin approval. Environment variables documents the scope and opt-out.
  • A load failure leaves the session as it was. Import, construction, or get_* errors are reported and the plugin stays unloaded; nothing it declared is kept. When construction succeeded, on_session_end runs with reason='error' under a shield with a five-second cooperative timeout before a failed/cancelled load drops the plugin. Cleanup must tolerate an incomplete on_session_start.

Overlapping plugins go in the compatibility matrix. plugins/compatibility.py maps a plugin's factory to the factories it already includes, each with the capability classes it must bind for that to hold (coder includes harness SubAgents while it binds one, which it does with sub_agents on, and compaction only while it binds a history compaction, which it does not, so both run by default). While the including plugin is loaded, the loader keeps the included ones unloaded and refuses to enable or configure them, and /plugins greys their rows out. Their saved enabled flag is untouched, so turning the including plugin off loads them again. Add a row there; do not special-case ids.

Compaction registers harness FallbackCompaction directly with max_fraction and context_window for both strategies. Harness owns the trigger; do not add threshold math or an orchestrator in Pax. Register the usage gauge after the chain so yellow means the compacted request still exceeds the threshold. /compact drives the same chain regardless of threshold, keeps the result only when harness estimate_message_tokens (provider-reported usage) says it shrank, reports the saving out of the status row's estimate_context_tokens figure (capped at the per-message sum), and passes runtime/agent_instrumentation.tracer() so it is traced. Only ModelAPIError, FallbackExceptionGroup, and UsageLimitExceeded select truncation after a summary failure; other exceptions propagate. Its configure is a FieldMenu over CompactionSettings; the loader's reload builds the new chain. Background compaction is harness FallbackCompaction(background_start=...), not Pax code: the plugin only passes the setting, closes the chain in on_session_end, discards the summaries of conversations other than the shown one and its running tasks at each turn end and conversation change (not per task event, which would build one for every streamed event), and has /compact try the chain's take_background_compaction (without a focus) or discard_background_compaction (with one) before the capped chain. The status row's window does not depend on it: Session.on_context_window reports each streamed request model's window, and the shell fills it in when no gauge has. Until a turn on the selected model runs in the conversation, show_model sets Status.model_window from the window /model settings saved for it, else its profile (infer_model_profile; a plugin model's from its settings_from provider's), which the row and web UI show while context_window is None; after one, an unresolved window stays ?. A window /model settings saved for a model reaches compaction and the row through SavedContextWindows, an outermost capability that wraps each step's model in ContextWindowModel; never apply it in ModelResolver, where building the model would skip the run's other resolvers. A conversation without a figure yet, such as a resumed one, reads its last response's context_tokens.

Adding or changing a Pax moment or contribution

  1. Add the event dataclass and an on_* method (or a get_* method with a no-op default) to Plugin, and route it in _HANDLERS or collect.
  2. Fire it, or read the collected value, from exactly one place in the shell.
  3. Document it in PLUGINS.md in the table it belongs to, and in docs/declarative-plugins.md if it changes the design.

The /plugins, /set, /theme, /model, and /model add menus

Built on termflow's MenuBuilder (and TextInputBuilder for typed values), exactly like Code Puppy's /agent, /mcp, /set, and /model menus: alternate screen, a .preview panel on the right, markdown_style() for colours. Single-key actions and the key legend go through slash_search's hotkeys and footer in a searchable menu, .on_key and .footer_hint in one that is not.

  • Split it in two: a pure build_plugins_menu(...) that returns the menu (so tests drive it headless, no terminal), and a thin async runner that owns the screen and calls menu.run in a thread.
  • Every key mutates immediately and replace_items redraws. No pending-changes state, no save/cancel pair. Settings menus still end with a Save & close row (save_and_close_item(), recognized by picked(result)) that only leaves; FieldMenu, /keys, and /plugins add it for you.
  • Turning a plugin on opens its configure menu. A widget cannot open from inside another menu's key handler, so PluginMenu closes with a Configure result and open_plugins_menu runs the settings menu, then reopens the list.
  • Enter performs the highlighted row's primary action (/plugins toggles, like Space) and never silently closes a list menu. Termflow's default Enter selects the row and closes, so where that is not the row's action, bind enter as a hotkey that does the action, or nothing; Esc closes.
  • Footer hints separate actions with - and capitalize named keys (Enter, Esc, Space); letter hotkeys stay as typed (c configure, R reset). Modifier keys join with + (Ctrl+C, Ctrl+X Ctrl+S, Cmd+Shift+Z) in footers, dialogs, help text, and docs alike; ctrl-c is only a key name in code.
  • Nothing prints to the console while the menu is open; the alternate screen would hide it. Show empty states and errors inside the menu as disabled rows.
  • Esc and Ctrl+C close cleanly. They are not errors.
  • Make a new or changed menu searchable with slash_search (ui/menus/slash_search.py), not a bare .searchable(): plain letters stay hotkeys, / starts a search, Esc leaves it. Pass single-key actions as its hotkeys so they type into the search instead of firing while the user searches. For searchable FieldMenu lists, use slash_search only when a row offers Space cycling. Eligible rows have multiple declared choices and no action/submenu mapping. Cycle choices in declaration order and wrap. Start at the first choice when the current value is absent or unlisted. Keep searchable field lists without eligible rows on type-to-filter with uppercase R reset. Keep nonsearchable field lists without search and with lowercase r reset.
  • A widget opened mid-run (including the standalone inline ask_user picker) goes inside async with host.full_screen(), which flushes streamed text and suspends the editor's input reader first, preserving its draft. Slash-command handlers already run with the editor suspended. Composer questions and approvals use its existing reader through PromptQuestions. Do not start a second input reader alongside the live editor.
  • Adding a plugin is not in the menu. It needs free text, so it stays /plugins add ID MODULE[:ATTR] [JSON] or /plugins add GIT_URL. Git installs use the existing file loader, with HTTPS/SSH for network sources; see PLUGINS.md for the repository layout, trust boundary, and checkout management.
  • Anything that is "edit named, validated fields" uses field_menu.py: a FieldSource supplies rows, current values, validation, apply, and reset; FieldMenu builds the widgets; run_flow is the loop. /set and per-model settings are two sources, not two editors. Do not write a third editor.
  • /set edits go through CommandContext.set_setting / reset_setting, the same path as the typed command, so validation lives in one place.
  • Multi-line text goes through text_editor.edit_text: $VISUAL or $EDITOR on a temporary file, else (on Windows, unset, or failing to start) a built-in prompt_toolkit editor, since termflow has no multi-line input. Call it from a menu worker between widgets, or ask with Dialogs.text(multiline=True) from a settings menu action, which the web UI shows as a text area. Do not write another editor.
  • Widget runners are a Runners value passed into the loops; tests pass scripted ones (tests/menu_script.py). Only the real widget.run() one-liners are no cover. Code that asks through Dialogs (settings menu actions, plugins/keys.py, plugins/sign_in.py) is tested with tests/pax/dialog_script.py's ScriptedDialogs instead.
  • Model sources live in model_catalog.py. To add one (models.dev, a provider API), write a function returning CatalogModels and merge it in catalog(). The menu never talks to a source directly.
  • Per-model settings are the editable subset of core's ModelSettings, declared once as ModelSettingsForm with descriptions and bounds. Extend the form, not the menu, to expose another setting.

Rendering

StreamRenderer owns text and thinking. It knows nothing about any specific tool. Tool-specific output (shell previews, diffs, grep) comes from render on the plugin that owns the event. Match on event classes, never on tool_name strings. Always flush the stream before printing anything else; the shell does this for renderers, so do not call console.print from an event hook when a renderer would do.

Colours

/theme offers the unchanged default appearance and termflow.themes.PALETTES. Do not define new palettes. Resolve brand roles with theme.color(...) for Rich; theme.sgr(...) resolves raw ANSI itself. A theme change repaints retained transcript lines by translating these roles, so colour output through them, and print logo branding inside theme.branded() so it keeps its colours. theme.current() returns a Termflow palette or None for the original appearance. Termflow owns palette application and reset; theme.use(...) leaves the terminal untouched in the default session. Markdown keeps its original style by default and uses to_render_style() for a selected palette. The preview renders a sample without OSC changes or persistence. Heavy imports in theme.py stay lazy for the splash. Code uses the terminal foreground and ANSI syntax colours through theme.syntax_theme(), shared by streamed fences, shell command headers, and theme previews. Shell command headers add dim and drop underlines over the lexed code (command_syntax._SECONDARY), so a tool call reads as secondary; keep fences unchanged. The default theme's diff lines use a dark green and red; bundled palettes get diff lines from theme.diff_renderer(), tinted from the palette until their lightness differs, so colour-blind readers can tell them apart. On a light terminal (app.chat asks for the background once, ui/terminal_background.py, and passes it to theme.use(background=...)), default paints brand roles in the fixed theme._ON_LIGHT shades and diffs on pale lines with Pygments' xcode style; code fences keep the terminal's ANSI colours. On a dark or unknown background it is unchanged. theme.color() and theme.syntax_theme() raise a palette colour to WCAG AA contrast (or the palette's own text contrast); test_theme_preview.py checks both for every palette.

Echo the user's own text through rendering.prompt_line, which paints it on theme.prompt_background(): under a palette, its background moved towards its text, on a truecolor terminal only (theme.truecolor(), as theme.sgr decides). The default theme has no tint, on a light terminal background as on a dark one.

Source layout

The package root composes the shell (app.py, __main__.py) and keeps the plugin-author imports pydantic_ai_pax.plugins and pydantic_ai_pax.commands stable. Other code is grouped by responsibility:

  • cli/ owns argument handling, command context, headless output, and shell passthrough.
  • config/ owns settings, credential storage, and project declarations. config/__init__.py provides the existing pydantic_ai_pax.config settings API.
  • runtime/ owns sessions, forks, worktrees, reload, and speculative turns.
  • models/ owns model discovery, settings validation, and optional provider adapters. Pure model parameter expansion belongs here, not in a menu.
  • ui/prompt/ owns editing, terminal input, surface painting, and resize.
  • ui/menus/ owns widgets and command-specific pickers; ui/rendering/ owns themes, streaming, status, and output formatting.
  • plugins/ owns the host API, loading, and credential picker helpers. builtin_plugins/ and mcp/ retain their plugin and server boundaries.

Move a capability to core or harness if it does not need a terminal. Keep UI imports out of reusable validation code. The CLI and app may compose these packages; new package initializers should not eagerly import the app or heavy UI. Do not add broad backwards-compatibility shim modules for internal file moves. Keep documented plugin-author paths (pydantic_ai_pax.plugins and pydantic_ai_pax.commands) intact; update example imports when moving UI helpers. The package was pydantic-clai2 until it became pydantic-ai-pax. The pydantic-clai2 shim in src/pydantic_clai2/ depends on it and alone owns pydantic_clai2/, which aliases pydantic_clai2.X to pydantic_ai_pax.X and holds the deprecated clai2 command. PluginSettings renames a pydantic_clai2 factory as it validates, and SettingsStore.save_plugin stores factories under pydantic_clai2, which older builds sharing the database still import. The clai2-bleeding release keeps the old name so existing installs keep updating. The keyring service is pydantic-ai-pax: credential_store copies an encryption key saved under pydantic-clai2 and keeps the old entry for older builds, and older per-entry logins are still read from pydantic-clai2. The config and state folders moved to pydantic-ai-pax: paths.py moves a pydantic-clai2 folder on first use and leaves a symlink, so older builds still share it.

File map

FILE_MAP.md lists what each module holds. Read it to find where a change belongs, and update its row when you add, move, or change the responsibility of a module. It is kept out of this file because this file is sent with every request.

Keep files concise - we don't need any 10,000 line files. Single responsibility.

Windows-only CLI operations

Check whether an existing interactive command already completes the operation on Windows. If a new non-interactive path cannot observe completion because Pax must exit first, fail early with a non-zero status and name the working command. Do not report success for a detached operation or add a process trampoline just to make the new path work. Add Windows-specific orchestration only when a concrete requirement cannot use the existing path. For updates, /update now is the working interactive path.

Testing

  • When adding or modifying a Pax CLI UX feature, test every affected UX feature with your changes in a fresh tmux window before opening a PR. Run Pax with uv run pax. Verify the actual terminal behavior against the intention of the user's request, not just the implementation or automated tests.
  • pytest-anyio; real model calls are blocked globally.
  • Drive the shell with TestModel and a Console(file=StringIO()).
  • Test a moment by loading the plugin with load_plugin and firing the event from the shell path that owns it (or LoadedPlugin.dispatch). Assert the handler's effect (the cancelled turn, the rewritten text), not a mock call count.
  • Renderers get synthetic events. They must not need Coder installed.
  • Cancellation: use a real anyio cancel scope, order with Events, no sleeps.

Settings and database compatibility

Before adding, removing, or renaming a setting, changing its type, meaning, or default, or changing the SQL schema, consider upgrades, downgrades, and branch switches. Different versions can share the same settings database.

  • Adding a setting needs no API compatibility waiver: SETTING_FIELDS and STRING_SETTINGS are growing_collections in .github/api-compatibility-allowlist.json. Removing or renaming one still needs a deprecation and a waiver.
  • Add regression cases to tests/test_settings_compatibility.py and affected CLI tests using the previous stored format. Keep historical fixtures unchanged; do not regenerate them with current models or rewrite them to make a change pass.
  • Verify older databases load with documented defaults for missing settings and preserve existing preferences, plugin declarations, and model settings. Test migrations and repeated initialization for data preservation and idempotence.
  • Preserve unknown saved setting names and their values when reading, editing other settings, resetting, and reopening. Unknown does not mean obsolete. Keep validation strict for known values, new writes, and plugin declarations.
  • For renamed fields or changed types, meanings, or defaults, define the migration or intentional behavior change and test it explicitly. Comparing only against the current Settings() defaults will not catch an unintended default change.
  • Verify rejected values and unsupported schema versions leave stored data intact. If a change introduces a migration, test failure rollback as well as success.
  • When a plugin setting's valid values or meaning depend on code other builds may lack, add a feature name to SUPPORTED_FEATURES in config/features.py and tag the setting (host.settings(Model, requires=...), or CAPABILITY_REQUIREMENTS for a module:Class capability). Tags live in the plugin_requirements table; never add a field to PluginSettings, a key to its settings, or bump user_version, since older builds reject all three. A build lacking a feature drops only that setting and uses the default. Run setup UserErrors are caught only by PluginGuard, and only around a capability Pax built from a module:Class declaration's settings with no Hooks inside, so policy hooks and plugin-contributed capabilities always fail closed. See "Settings that need a feature" in customization.md.

Local verification

Run from the repository root. Pax shares the root uv.lock, .venv, and Pyright configuration with Harness.

uv sync --locked --all-packages --group lint
uv run --no-sync ruff format --check .
uv run --no-sync ruff check .
PYRIGHT_PYTHON_IGNORE_WARNINGS=1 uv run --no-sync pyright src/pydantic_ai_pax tests/pax
uv run --no-sync pytest -p no:cacheprovider tests/pax

Docs parity

README.md is the product tour, docs/reference.md is the user reference, PLUGINS.md is the plugin contract, and this file is for agents. A user-facing change updates the reference (and the README when it changes what the tour shows) and PLUGINS.md in the same PR. The README is the PyPI page, so its links and images are absolute URLs on main; scripts/screenshots/capture.sh regenerates the images in docs/images/. docs/harness/pax.md is the same story as the README on the docs site, not a copy of it: edit both, keep code blocks identical, and see the "Pax front pages" section of docs/AGENTS.md for which link and model styles each one takes. Plain language, short sentences, no jargon a first-time plugin author would not know.

Agent-readable docs are indexed by pax_docs._PAX_DOCS. Docs outside pydantic_ai_pax/ ship through pyproject.toml's wheel force-include and sdist include. The catalog and packaging guards in tests/pax/test_pax_docs.py reject new docs missing from either surface. If a new feature falls outside the existing discovery triggers, update pax_docs._DESCRIPTION and _hint.

The resume browser is a focused exception to the single MenuBuilder convention: it needs independently focused projects/sessions and two-line cards. Keep its frame pure, inject keys/size/IO, use Termflow terminal ownership and layout, and run through menu_worker. Metadata refreshes must preserve selection by ID. /tasks is the other exception: a termflow.live app, because a transcript that streams beside an input needs a frame loop. Its actions are Ctrl chords, since letters type the message. Keep TaskView free of the terminal and the event loop: snapshot, act and size are injected, and tests pass open_tasks a scripted run. History-changing plugins use await conversation.commit_messages, not the legacy in-memory replace_messages, so exiting immediately after /compact is durable.

The interactive editor owns its layout explicitly. Do not reintroduce a PromptSession renderer. PromptSurface starts inline on the main screen, repainting only the rows the terminal's scrollback lacks plus the editor, and switches to the alternate screen for good once they would fill the terminal, the terminal narrows, widens, or shrinks, or release(turn_running=True) hands the terminal over mid-turn. Released between turns, it erases its rows and prints the transcript into scrollback as it arrives (_print_released), keeping no rows, since a command may write to the terminal directly; it cannot do that mid-turn, when a streamed part may still grow. display.full_screen (LivePrompt(full_screen=True), PromptSurface.full_screen) starts on the alternate screen; tests that need fixed frame rows use it. The inline phase pushes only KEYS_ON, never mouse reporting, so the terminal keeps its own wheel scrollback and selection; it shows every unprinted row, so it has nothing to scroll and follows. It erases its rows by moving up the count it painted, which a terminal that reflows text, or pushes rows into scrollback as it shrinks, or anything else writing to the terminal would invalidate, hence the switches. Do not let anything but PromptSurface write to the main screen while inline rows are up. The rules below about scrolling, the mouse, and resizes are the alternate screen's. On the alternate screen it composes a termflow.live ScreenBuffer, TranscriptView draws its transcript region, and render_diff paints changed cells. Do not invent a parallel canvas. The hardware cursor stays hidden; the input cursor is a painted reverse-video cell. Keep terminal mutations in PromptSurface, and detach the key reader before a menu owns the screen. The prompt-toolkit decoder preserves paste, modified keys, and SGR mouse reports. PageUp/PageDown and wheel input scroll the transcript, not the draft. Wheel and drag reports arrive in bursts, so they paint once after the input callback (PromptSurface._paint_soon), never once per report. An idle session must cost next to no CPU, since users keep dozens open. The editor's timed repaint (LivePrompt.tick) runs ten times a second only while a turn runs or the panel animates, and once a second (IDLE_REPAINT) otherwise, sleeping in between; a read wakes it, since the work it starts animates. PromptSurface.paint skips a frame identical to the last one. Input, output, and resizes paint at once; output inside a frame interval paints when it ends (PromptSurface.changed), without waiting for a tick. Do not add a timer that repaints unconditionally, or one that wakes an idle editor more than once a second. Mouse reporting stops most terminals from selecting text, so a left-button drag, double-click (a word) or triple-click (a line) selects painted cells in PromptSurface, and its release copies them through text_clipboard.copy_text. Do not drop the drag modes (?1002h) or copy-out breaks. Words, lines, and copies join rows only where TranscriptView.joins says a row wraps on; rows Rich wrapped are separate lines.

Resize rebuilds from TranscriptBuffer, not guessed row coordinates or cursor reports. Never send erase-scrollback (CSI 3 J). Preserve the draft and scroll anchor. SIGWINCH invalidates the next frame; it must not perform terminal IO. A MarkdownBlock shows its streamed rows until its writer calls end, and renders its source again only after that: rendering a streaming part again per frame costs the whole part every frame. Full-screen menus leave the live panel temporarily. Composer questions keep its reader and focus until the user explicitly focuses the question. Standalone questions borrow the released panel with run_worker(inline=True) and pin the question text in their rows, not the transcript, so output streamed meanwhile cannot push it away. Streamed text and thinking keep Markdown source, a tool-call group its call names, and a shell call's header its command, for width/theme repaint (syntax colours share hex values with brand roles under a palette, so translating them would guess; a part still streaming is translated like tool output until it ends, then renders again); tool output keeps styled lines, each tagged with the theme that painted it, and recolor.py translates them role by role (theme.roles) when the theme changes. On exit, restore prints retained output into native scrollback once, skipping startup output already printed there. Transcript memory is bounded, including Markdown parts. Reload rebinds the retained transcript and its nested classes in place after a successful shell rebuild, including migration from the pre-live Text-line buffer. The suspended chat coroutine still holds that transcript; do not only replace it on the new shell or mutate it before a rebuild that can fail.

The standalone ask_user picker, the default, borrows the released PromptSurface while the editor is suspended. Keep its numbered choices and Enter toggles; do not switch screens inside the picker or reintroduce Space-to-toggle. With input.questions=composer, the effective send binding toggles choices; Ctrl+J inserts a newline in custom answers (it steers on Windows) and never confirms a choice. Keep composer question state on its SessionRuntime, not on the shared terminal. Generic send, steering, and remembered question routing never authorize tools.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.