feat: /model command to switch AI model from Telegram#66
Conversation
Usage: /model — show current model + available options /model sonnet — switch to Claude Sonnet 4.6 /model opus — switch to Claude Opus 4.6 /model haiku — switch to Claude Haiku 4.5 Writes to ~/.pi/agent/settings.json (defaultProvider + defaultModel). Takes effect on next agent turn (new sessions use new model). Registered in Telegram bot command menu.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3af1ca9174
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| function writeSettings(settings: Record<string, any>): void { | ||
| writeFileSync(SETTINGS_PATH, JSON.stringify(settings, null, 2) + "\n"); |
There was a problem hiding this comment.
Ensure settings path exists before persisting /model changes
writeSettings writes ~/.pi/agent/settings.json directly, but /model is now registered globally in Telegram and can run on installs where ~/.pi/agent does not exist yet (for example non-Pi setups or first-run environments). In that case writeFileSync throws ENOENT, and this handler has no local error handling, so the command fails and can bubble an unhandled rejection through the message callback. Create the parent directory (or catch and report write errors) before writing.
Useful? React with 👍 / 👎.
| settings.defaultModel = target; | ||
| settings.defaultProvider = provider; |
There was a problem hiding this comment.
Split provider/model when accepting slash-form model input
The slash-path branch treats any input containing / as a model id, but then keeps the existing provider and stores the entire string into defaultModel. For inputs like /model amazon-bedrock/us.anthropic..., this persists defaultProvider=amazon-bedrock and defaultModel=amazon-bedrock/us..., which later gets recombined as provider/model (e.g. amazon-bedrock/amazon-bedrock/us...) in status/reporting paths and produces a malformed configured identifier. Parse provider/model explicitly when / is present instead of storing the unsplit string.
Useful? React with 👍 / 👎.
Switch AI model live from Telegram without SSH.
Usage:
/model— show current model + available options/model sonnet— switch to Claude Sonnet 4.6/model opus— switch to Claude Opus 4.6/model haiku— switch to Claude Haiku 4.5/model opus-4.7— switch to Claude Opus 4.7Writes to
~/.pi/agent/settings.json. Takes effect on next agent turn.Registered in Telegram bot command menu.