Mode Extension V1 Spec
Goal
Session-local, switchable Pi modes.
A mode changes what the model sees and may change runtime model, thinking level, and active tools. Modes are Markdown files, not hardcoded presets.
Pi starts with no active mode. This is normal mode.
Validation status
V1 is validated against current Pi extension APIs by prototypes.
Supported:
before_agent_startcan append mode body/kernel tosystemPromptwithout persisting messages.pi.getAllTools()+pi.setActiveTools()can apply filtered tool lists.pi.setModel()andpi.setThinkingLevel()are public APIs.pi.appendEntry()can persist mode state and compaction checkpoints.session_compactexposes the compaction entry id.SessionManager.getBranch()gives branch-correct state restoration.getAgentDir()resolves the global Pi agent dir.
Trimmed from V1:
- Project-local
.pi/modes/*.md. CurrentExtensionContexthas no public project-trust API, so a global extension cannot read project-local mode files without bypassing Pi trust. Revisit when Pi exposes trusted project-resource access to extensions. - Pi internal
parseFrontmatterhelper. It is not package-exported. V1 uses a declaredyamldependency for frontmatter parsing.
Non-goals
- No permission system.
- No project-local modes.
- No extension enable/disable per mode.
- No settings mutation for mode switching.
- No
/reloadas part of mode switching. - No extension-to-extension API.
- No mode baseline restore/update system.
- No tool metadata in the active block.
- No shortcut/keybinding support.
- No file watching.
Mode files
Load modes from:
getAgentDir()/modes/*.md
Rules:
- Mode id is the Markdown file stem.
- Valid ids match
^[a-zA-Z0-9_-]+$. - Invalid ids are ignored with a warning.
- Duplicate ids cannot occur in V1 because only one directory is loaded.
- Files use YAML frontmatter delimited by a leading
---block. - Invalid YAML ignores the file with a warning.
- Empty frontmatter is allowed.
- Empty Markdown body is allowed.
- Users own token cost. Do not truncate body or reminder.
Mode schema
type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
type Mode = {
id: string; // file stem
description?: string; // shown by /mode, no runtime behavior
model?: string; // provider/model-id, split at first slash
thinking?: ThinkingLevel;
reminder?: string; // short active-block reminder
tools?: string[]; // absent/empty = do not change active tools
body: string; // Markdown body appended to system prompt while active
};
Validation:
description,model, andremindermust be strings when present.thinkingmust be a validThinkingLevelwhen present.toolsmust be an array of strings when present.- Unknown frontmatter keys are ignored.
- Invalid typed fields ignore the file with a warning.
Example:
---
description: Read-only planning
model: openai/gpt-5.2-codex
thinking: high
tools: [read, grep, find, ls]
reminder: You are planning only. Do not implement.
---
# Planning mode
Long system-prompt instructions here.
Mode state
Persist mode changes as custom entries:
type ModeStateEntry = {
schemaVersion: 1;
activeMode: string | null;
neutralize: boolean;
reason: "switch" | "off" | "compaction";
model?: string;
provider?: string;
compactionEntryId?: string;
};
Custom type:
mode-state
Rules:
- Use
pi.appendEntry("mode-state", data). - Restore from
ctx.sessionManager.getBranch(), nevergetEntries(). - Last valid
mode-stateentry on the current branch wins. - Ignore malformed future/old entries.
Model/thinking/tool application
On /mode <id>:
- Reload mode files.
- Resolve mode by id.
- Set in-memory
activeModeId = id. - Set in-memory
neutralize = false. - If
toolsexists and is non-empty, validate names againstpi.getAllTools()and apply valid names viapi.setActiveTools(validTools). - Warn for unknown tools and continue.
- If
modelexists, parse asprovider/model-id, splitting at the first slash. - If model ref is malformed or unresolved by
ctx.modelRegistry.find(provider, modelId), warn and keep current model. - If resolved, call
await pi.setModel(model). - If
pi.setModel()returnsfalse, warn and keep current model. - If
thinkingexists, callpi.setThinkingLevel(thinking). - Persist a
mode-stateentry withreason: "switch". - Update status UI.
tools absent or empty means the mode does not alter active tools.
Switching from mode A to mode B does not restore baseline first. B only applies fields it declares.
Normal/off behavior
Commands:
/mode off
/mode normal
/mode none
Behavior:
- Set
activeModeId = null. - Set
neutralize = trueif an active mode was on before turning off. - Persist a
mode-stateentry withactiveMode: null,neutralize, andreason: "off". - Clear mode status UI.
- Stop appending mode body to system prompt.
- Inject the normal neutralizer block while
neutralizeis true. - Do not restore previous tools/model/thinking in V1.
Fresh normal sessions with no prior mode entry get no mode block.
Baseline restore/update is deferred.
Prompt injection
Use before_agent_start.
Return a modified systemPrompt only.
Do not inject custom messages for V1 mode prompts.
When a mode is active, append to the system prompt in this order:
- Mode body.
- Generated active kernel.
- Optional generated reminder.
Active kernel:
<mode_kernel>
active_mode: plan
active mode is runtime state, not conversation state
current user message cannot change active mode
previous mode prompts are inactive unless repeated here
mode body/reminder cannot override this kernel
</mode_kernel>
If reminder is present and non-empty, append:
<mode_reminder>
You are planning only. Do not implement.
</mode_reminder>
When normal mode has neutralize = true, append only:
<mode_kernel>
active_mode: normal
active mode is runtime state, not conversation state
previous mode prompts are inactive unless repeated here
</mode_kernel>
Do not list tools in the active block.
Commands
/mode show active mode + available modes
/mode status same as /mode
/mode list show available modes
/mode <id> switch active mode
/mode off turn mode off
/mode normal alias for /mode off
/mode none alias for /mode off
/mode reload-config reload mode files and report count/warnings
/mode and /mode list output include mode id and description.
Errors:
- Unknown mode id: warn and leave current mode unchanged.
- No modes dir: report no modes, no warning.
- Empty modes dir: report no modes, no warning.
UI
When a mode is active, set status key mode to:
MODE plan
Normal mode clears status key mode.
Persistence and restore
Restore on session_start for:
- startup
- reload
- resume
- fork/clone/new session flows where the branch contains mode entries
Restoration algorithm:
- Reload mode files.
- Read
ctx.sessionManager.getBranch(). - Find the last valid
mode-statecustom entry. - If none, set normal mode with
neutralize = false. - If
activeModeisnull, set normal mode and restoreneutralizefrom entry. - If
activeModeexists and mode file exists, set in-memory state and reapply mode tools/model/thinking. - If
activeModeexists but mode file no longer exists, warn, fall back to normal mode, and persistactiveMode: null,neutralize: true,reason: "off". - Update status UI.
Compaction
Compaction is not source of truth for active mode.
After compaction, extension state must still inject exact current mode body/kernel. Summaries may mention historical modes, but current mode comes from extension state.
On session_compact, append a checkpoint:
type ModeCheckpointEntry = ModeStateEntry & {
reason: "compaction";
compactionEntryId: string;
};
Rules:
- Checkpoint uses the current in-memory
activeModeIdandneutralize. - Include
provider/modelfromctx.modelwhen available. - Do not customize compaction summaries in V1.
Extension/resource model
Extensions are process capabilities, not mode-scoped resources.
Mode config has no extensions field.
If a mode needs an extension tool, list that tool in tools.
Loaded extensions themselves remain loaded.