Commit graph

124 commits

Author SHA1 Message Date
scutifer
907fa937e6
Improve light theme color contrast for WCAG compliance (#682)
Adjust base colors (teal, blue, green, red, yellow, dimGray) to meet
4.5:1 contrast ratio against white backgrounds. Update thinking level
colors to reference theme vars for consistency.

Refactor test-theme-colors.ts into a CLI with contrast, test, and theme
commands for easier color validation.

Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
2026-01-13 13:03:04 +01:00
Mario Zechner
8f95a13e07 feat(coding-agent): add session naming via /name command and extension API
- Add SessionInfoEntry type for session metadata
- Add /name <name> command to set session display name
- Add pi.setSessionName() and pi.getSessionName() extension API
- Session selector shows name (in warning color) instead of first message when set
- Session name included in fuzzy search
- /session command displays name when set

closes #650
2026-01-12 16:56:39 +01:00
Armin Ronacher
62caf219a1 Hook up custom summarization on branch switch 2026-01-12 00:09:33 +01:00
Mario Zechner
df3f5f41c0 Rename /branch command to /fork
- RPC: branch -> fork, get_branch_messages -> get_fork_messages
- SDK: branch() -> fork(), getBranchMessages() -> getForkMessages()
- AgentSession: branch() -> fork(), getUserMessagesForBranching() -> getUserMessagesForForking()
- Extension events: session_before_branch -> session_before_fork, session_branch -> session_fork
- Settings: doubleEscapeAction 'branch' -> 'fork'

fixes #641
2026-01-11 23:12:31 +01:00
Mario Zechner
9655907624 feat: Add skill slash commands and fuzzy matching for all commands
- Skills registered as /skill:name commands for quick access
- Toggle via /settings or skills.enableSkillCommands in settings.json
- Fuzzy matching for all slash command autocomplete (type /skbra for /skill:brave-search)
- Moved fuzzy module from coding-agent to tui package for reuse

Closes #630 by @Dwsy (reimplemented with fixes)
2026-01-11 17:56:11 +01:00
mom
9ddbafb03a fix(coding-agent): update test expectations after registerFlag -- prefix removal 2026-01-11 11:44:19 +00:00
Kao Félix
6d60302646 fix(coding-agent): remove -- from registerFlag calls
This was causing the agent sometimes to pick up on the incorrect syntax when
asked to write extensions with flags
2026-01-11 02:21:15 +01:00
Mario Zechner
af2d8509e6 Fix --no-skills flag not preventing skills from loading
The --no-skills flag set options.skills = [] in main.ts, but the
interactive mode UI would rediscover skills anyway because it called
loadSkills() directly instead of using the already-loaded skills.

Changes:
- Add AgentSession.skills and AgentSession.skillWarnings properties
- discoverSkills() now returns { skills, warnings } instead of Skill[]
- Interactive mode uses session.skills instead of calling loadSkills()
- Update SDK docs and examples for new return type

Fixes #577
2026-01-08 23:41:54 +01:00
Carlos Villela
c865ec1d19
fix(coding-agent): --no-skills flag not preventing skills from loading (#577)
The --no-skills flag set options.skills = [] in main.ts, but the interactive mode UI would rediscover skills anyway because it called loadSkills() directly.

Changes:
- Add AgentSession.skills and AgentSession.skillWarnings properties  
- discoverSkills() now returns { skills, warnings } instead of Skill[]
- Interactive mode uses session.skills instead of calling loadSkills()

Co-authored-by: Carlos Villela <cv@lixo.org>
2026-01-08 23:40:05 +01:00
Mario Zechner
e3dd4f21d1 feat(coding-agent): add tool override support via extensions
- Add setActiveTools() to ExtensionAPI for dynamic tool management
- Extensions can now override, wrap, or disable built-in tools
- Add tool-override.ts example demonstrating the pattern
- Update documentation for tool override capabilities
2026-01-08 18:52:33 +01:00
Carlos Villela
8f5523ed56
feat(coding-agent): add --no-tools flag to disable built-in tools
Add --no-tools flag that allows starting pi without any built-in tools,
enabling extension-only tool setups (e.g., pi-ssh-remote).

- Add --no-tools flag to CLI args parsing
- Handle --tools '' (empty string) as equivalent to no tools
- Fix system prompt to not show READ-ONLY mode when no tools (extensions may provide write capabilities)
- Add tests for new flag and system prompt behavior

fixes #555
2026-01-07 23:10:58 -08:00
Mario Zechner
bf9a415541 Switch to @mariozechner/clipboard fork with musl support
fixes #533
2026-01-08 04:50:37 +01:00
Kao Félix
6845c4b85e
feat(coding-agent): make ctx.shutdown() available for extensions (#542) 2026-01-08 03:30:48 +01:00
Mario Zechner
7f3fa417c4 feat(coding-agent): add --no-extensions flag to disable extension discovery
Adds --no-extensions CLI flag that skips automatic extension discovery
while still allowing explicit -e paths. Three modes now available:

1. Default: auto-discover + any -e additions
2. --no-extensions: no extensions at all
3. --no-extensions -e foo.js: only load explicit extensions

Useful for debugging or running subagent instances without auto-discovered
extensions.

closes #524
2026-01-08 03:22:38 +01:00
Mario Zechner
b1f32b9c8d fix(coding-agent): update test expectation for extension loader error message 2026-01-08 03:11:10 +01:00
Mario Zechner
cb3ac0ba9e refactor(coding-agent): simplify extension runtime architecture
- Replace per-extension closures with shared ExtensionRuntime
- Split context actions: ExtensionContextActions (required) + ExtensionCommandContextActions (optional)
- Rename LoadedExtension to Extension, remove setter methods
- Change runner.initialize() from options object to positional params
- Derive hasUI from uiContext presence (no separate param)
- Add warning when extensions override built-in tools
- RPC and print modes now provide full command context actions

BREAKING CHANGE: Extension system types and initialization API changed.
See CHANGELOG.md for migration details.
2026-01-07 23:50:18 +01:00
Fero
cbd3a8cb87
fix: use defaultThinkingLevel from settings when enabledModels lacks explicit suffix (#540)
When enabledModels is configured without thinking level suffixes (e.g.,
'claude-opus-4-5' instead of 'claude-opus-4-5:high'), the scoped model's
default 'off' thinking level was overriding defaultThinkingLevel from
settings.

Now thinkingLevel in ScopedModel is optional (undefined means 'not
explicitly specified'). When passing to SDK, undefined values are filled
with defaultThinkingLevel from settings.
2026-01-07 18:11:03 +01:00
Mario Zechner
09471ebc7d feat(coding-agent): add ctx.ui.setEditorComponent() extension API
- Add setEditorComponent() to ctx.ui for custom editor components
- Add CustomEditor base class for extensions (handles app keybindings)
- Add keybindings parameter to ctx.ui.custom() factory (breaking change)
- Add modal-editor.ts example (vim-like modes)
- Add rainbow-editor.ts example (animated text highlighting)
- Update docs: extensions.md, tui.md Pattern 7
- Clean up terminal on TUI render errors
2026-01-07 16:11:49 +01:00
Carlos Villela
893e00579d
Merge remote-tracking branch 'origin/main' into feat/no-extensions-flag 2026-01-07 03:20:09 -08:00
ferologics
e0dbdc56d6 fix: preserve externally-added settings when saving
When a user edits settings.json while pi is running (e.g., adding
enabledModels), those settings would be lost when pi saved other
changes (e.g., changing thinking level via Shift+Tab).

The fix re-reads the file before saving and merges the current file
contents with in-memory changes, so external edits are preserved.

Adds test coverage for SettingsManager.
2026-01-07 11:31:14 +01:00
Carlos Villela
499341cdc1
feat(coding-agent): allow explicit -e flags with --no-extensions
--no-extensions now skips discovery but still loads extensions
specified via -e flags. This gives users three modes:

1. Default: auto-discover + any -e additions
2. --no-extensions: no extensions at all
3. --no-extensions -e foo.js: only load foo.js, skip discovery

fixes #524
2026-01-07 02:27:00 -08:00
Carlos Villela
48f524c554
Add --no-extensions flag to disable extension discovery
Similar to --no-skills, this flag disables extension discovery and loading.
Useful for debugging or when extensions are causing issues.
2026-01-06 23:53:01 -08:00
Mario Zechner
59d8b7948c Add ExtensionAPI methods, preset example, and TUI documentation improvements
- ExtensionAPI: setModel(), getThinkingLevel(), setThinkingLevel() methods
- New preset.ts example with plan/implement presets for model/thinking/tools switching
- Export all UI components from pi-coding-agent for extension use
- docs/tui.md: Common Patterns section with copy-paste code for SelectList, BorderedLoader, SettingsList, setStatus, setWidget, setFooter
- docs/tui.md: Key Rules section for extension UI development
- docs/extensions.md: Exhaustive example links for all ExtensionAPI methods and events
- System prompt now references docs/tui.md for TUI development

Fixes #509, relates to #347
2026-01-06 23:24:23 +01:00
Tudor Oancea
f755f69e0a added custom header support and example extension 2026-01-06 21:20:19 +01:00
Mario Zechner
7210086677 Extensions: add pi.sendUserMessage() for sending user messages
Adds sendUserMessage() to the extension API, allowing extensions to send
actual user messages (role: user) rather than custom messages. Unlike
sendMessage(), this always triggers a turn and behaves as if the user
typed the message.

- Add SendUserMessageHandler type and sendUserMessage() to ExtensionAPI
- Wire handler through loader, runner, and all modes
- Implement via prompt() with expandPromptTemplates: false
- Add send-user-message.ts example with /ask, /steer, /followup commands
- Document in extensions.md

fixes #483
2026-01-06 13:40:24 +01:00
Mario Zechner
f023af0dab Add ctx.ui.setFooter() for extensions to replace footer component
Extensions can now replace the built-in footer with a custom component:
- setFooter(factory) replaces with custom component
- setFooter(undefined) restores built-in footer

Includes example extension demonstrating context usage display.

Closes #481
2026-01-06 12:39:45 +01:00
Mario Zechner
90e0b95c81 Merge branch 'fix/image-paste-in-wayland'
# Conflicts:
#	packages/coding-agent/CHANGELOG.md
2026-01-06 12:12:17 +01:00
Zhou Rui
538ae6a083 fix(coding-agent): paste clipboard images on Wayland via wl-paste/xclip 2026-01-06 12:11:43 +01:00
Mario Zechner
1fc2a912d4 Add blockImages setting to prevent images from being sent to LLM providers
- Setting controls filtering at convertToLlm layer (defense-in-depth)
- Images are always stored in session, filtered dynamically based on current setting
- Toggle mid-session works: LLM sees/doesn't see images already in session
- Fixed SettingsManager.save() to handle inMemory mode for all setters

Closes #492
2026-01-06 11:59:09 +01:00
Josh
b582a6b70d
feat(coding-agent): add blockImages setting to prevent image uploads 2026-01-06 00:34:23 -06:00
Robin
1432fd91d2
fix(coding-agent): improve bash tool error handling (#479)
- Validate working directory exists before spawning to provide clear error message
- Add spawn error handler to prevent uncaught exceptions when shell not found or cwd invalid
- Add tests for both error scenarios

Without these fixes, spawn errors (e.g., ENOENT from missing cwd or shell) would
cause uncaught exceptions that crash the entire agent session instead of being
returned as clean tool errors.

Co-authored-by: robinwander <robinwander@users.noreply.github.com>
2026-01-06 00:48:10 +01:00
Mario Zechner
c6fc084534 Merge hooks and custom-tools into unified extensions system (#454)
Breaking changes:
- Settings: 'hooks' and 'customTools' arrays replaced with 'extensions'
- CLI: '--hook' and '--tool' flags replaced with '--extension' / '-e'
- API: HookMessage renamed to CustomMessage, role 'hookMessage' to 'custom'
- API: FileSlashCommand renamed to PromptTemplate
- API: discoverSlashCommands() renamed to discoverPromptTemplates()
- Directories: commands/ renamed to prompts/ for prompt templates

Migration:
- Session version bumped to 3 (auto-migrates v2 sessions)
- Old 'hookMessage' role entries converted to 'custom'

Structural changes:
- src/core/hooks/ and src/core/custom-tools/ merged into src/core/extensions/
- src/core/slash-commands.ts renamed to src/core/prompt-templates.ts
- examples/hooks/ and examples/custom-tools/ merged into examples/extensions/
- docs/hooks.md and docs/custom-tools.md merged into docs/extensions.md

New test coverage:
- test/extensions-runner.test.ts (10 tests)
- test/extensions-discovery.test.ts (26 tests)
- test/prompt-templates.test.ts
2026-01-05 01:43:35 +01:00
Mario Zechner
9794868b38 Implement extension discovery with package.json manifest support
Discovery rules:
1. extensions/*.ts or *.js - direct files
2. extensions/*/index.ts or index.js - subdirectory with index
3. extensions/*/package.json with pi field - load declared paths

No recursion beyond one level. Complex packages use package.json manifest.

Added PiManifest type for future theme/skill bundling support.

17 tests covering all discovery scenarios.

refs #454
2026-01-04 23:24:24 +01:00
Aliou Diallo
5cb7af1ddc
feat(hooks): expose setTitle to HookUIContext (#446) 2026-01-04 20:55:52 +01:00
Helmut Januschka
8ecb1d6c0b refactor: address PR feedback - merge setWidget, use KeyId for shortcuts
1. Merge setWidget and setWidgetComponent into single overloaded method
   - Accepts either string[] or component factory function
   - Uses single Map<string, Component> internally
   - String arrays wrapped in Container with Text components

2. Use KeyId type for registerShortcut instead of plain string
   - Import Key from @mariozechner/pi-tui
   - Update plan-mode example to use Key.shift('p')
   - Type-safe shortcut registration

3. Fix tool API docs
   - Both built-in and custom tools can be enabled/disabled
   - Removed incorrect 'custom tools always active' statement

4. Use matchesKey instead of matchShortcut (already done in rebase)
2026-01-04 18:13:30 +01:00
Helmut Januschka
ce88ebcd68 feat(hooks): add setWidgetComponent for custom TUI components
- New ctx.ui.setWidgetComponent(key, factory) method
- Allows custom Component to render as widget without taking focus
- Unlike custom(), widget components render inline above editor
- Components are disposed when cleared or replaced
- Falls back to no-op in RPC/print modes
2026-01-04 18:13:29 +01:00
Helmut Januschka
4ecf3f9422 refactor(hooks): address PR feedback
- Rename getTools/setTools to getActiveTools/setActiveTools
- Add getAllTools to enumerate all configured tools
- Remove text_delta event (use turn_end/agent_end instead)
- Add shortcut conflict detection:
  - Skip shortcuts that conflict with built-in shortcuts (with warning)
  - Log warnings when hooks register same shortcut (last wins)
- Add note about prompt cache invalidation in setActiveTools
- Update plan-mode hook to use agent_end for [DONE:id] parsing
2026-01-04 18:13:29 +01:00
Helmut Januschka
dc44816051 feat(hooks): add setWidget API for multi-line status displays
- ctx.ui.setWidget(key, lines) for multi-line displays above editor
- Widgets appear below 'Working...' indicator, above editor
- Supports ANSI styling including strikethrough
- Added theme.strikethrough() method
- Plan-mode hook now shows todo list with checkboxes
- Completed items show checked box and strikethrough text
2026-01-04 18:13:28 +01:00
Helmut Januschka
c956a726ed feat(coding-agent): add hook API for CLI flags, shortcuts, and tool control
Hook API additions:
- pi.getTools() / pi.setTools(toolNames) - dynamically enable/disable tools
- pi.registerFlag(name, options) / pi.getFlag(name) - register custom CLI flags
- pi.registerShortcut(shortcut, options) - register keyboard shortcuts

Plan mode hook (examples/hooks/plan-mode.ts):
- /plan command or Shift+P shortcut to toggle
- --plan CLI flag to start in plan mode
- Read-only tools: read, bash, grep, find, ls
- Bash restricted to non-destructive commands (blocks rm, mv, git commit, etc.)
- Interactive prompt after each response: execute, stay, or refine
- Shows plan indicator in footer when active
- State persists across sessions
2026-01-04 18:13:28 +01:00
Helmut Januschka
059292ead1 WIP: Add hook API for dynamic tool control with plan-mode hook example
- Add pi.getTools() and pi.setTools(toolNames) to HookAPI
- Hooks can now enable/disable tools dynamically
- Changes take effect on next agent turn

New example hook: plan-mode.ts
- Claude Code-style read-only exploration mode
- /plan command toggles plan mode on/off
- Plan mode tools: read, bash, grep, find, ls
- Edit/write tools disabled in plan mode
- Injects context telling agent about restrictions
- After each response, prompts to execute/stay/refine
- State persists across sessions
2026-01-04 18:13:28 +01:00
Mario Zechner
9ea483e813 Fix test: update expected error message for concurrent prompt 2026-01-03 16:41:01 +01:00
Evgeniy Skuridin
8917a1f853
feat(coding-agent): add $ARGUMENTS syntax for slash commands (#418)
* feat(coding-agent): add $ARGUMENTS syntax for slash commands

* test(coding-agent): add tests for slash command argument substitution
2026-01-03 14:08:39 +01:00
Mario Zechner
8df22faedf fix(ai): ensure maxTokens > thinkingBudget for Claude thinking models
Claude requires max_tokens > thinking.budget_tokens. When caller specifies
a small maxTokens (e.g. compaction with ~13k tokens) and reasoning is enabled
with high budget (16k tokens), the constraint was violated.

Fix: In mapOptionsForApi, add thinkingBudget on top of caller's maxTokens
(capped at model.maxTokens). If still not enough room, reduce thinkingBudget
to leave space for output.

Applied to both anthropic-messages and google-gemini-cli APIs.

Also adds test utilities for OAuth credential resolution and tests for
compaction with thinking models.

fixes #413
2026-01-03 02:45:30 +01:00
Mario Zechner
d747ec6e23 Enhance provider override to support baseUrl-only mode
Builds on #406 to support simpler proxy use case:
- Override just baseUrl to route built-in provider through proxy
- All built-in models preserved, no need to redefine them
- Full replacement still works when models array is provided
2026-01-03 01:06:08 +01:00
Yevhen Bobrov
243104fa18
Allow models.json to override built-in providers (#406)
* Allow models.json to override built-in providers

When a provider is defined in models.json with the same name as a
built-in provider (e.g., 'anthropic', 'google'), the built-in models
for that provider are completely replaced by the custom definition.

This enables users to:
- Use custom base URLs (proxies, self-hosted endpoints)
- Define a subset of models they want available
- Customize model configurations for built-in providers

Example usage in ~/.pi/agent/models.json:
{
  "providers": {
    "anthropic": {
      "baseUrl": "https://my-proxy.example.com/v1",
      "apiKey": "ANTHROPIC_API_KEY",
      "api": "anthropic-messages",
      "models": [...]
    }
  }
}

* Refactor model-registry for readability

- Extract CustomModelsResult type and emptyCustomModelsResult helper
- Extract loadBuiltInModels method with clear skip logic
- Simplify loadModels with destructuring and ternary
- Reduce repetition in error handling paths

* Refactor model-registry tests for readability

- Extract providerConfig() helper to hide irrelevant model fields
- Extract writeModelsJson() helper for file writing
- Extract getModelsForProvider() helper for filtering
- Move modelsJsonPath to beforeEach

Reduces test file from 262 to 130 lines while maintaining same coverage.
2026-01-03 00:59:59 +01:00
Mario Zechner
3ae02a6849 feat(coding-agent): complete steer()/followUp() migration
- Update settings-manager with steeringMode/followUpMode (migrates old queueMode)
- Update sdk.ts to use new mode options
- Update settings-selector UI to show both modes
- Add Alt+Enter keybind for follow-up messages
- Update RPC API: steer/follow_up commands, set_steering_mode/set_follow_up_mode
- Update rpc-client with new methods
- Delete dead code: queue-mode-selector.ts
- Update tests for new API
- Update mom/context.ts stubs
- Update web-ui example
2026-01-03 00:13:25 +01:00
Mario Zechner
58c423ba36 feat(coding-agent): update AgentSession for steer()/followUp() API
- Rename queueMessage to steer(), add followUp()
- Split _pendingMessages into _steeringMessages and _followUpMessages
- Update sendHookMessage to accept deliverAs option
- Rename hasQueuedMessages to hasPendingMessages
- Rename queuedMessageCount to pendingMessageCount
- Update clearQueue() return type to { steering, followUp }
- Update UI to show steering vs follow-up messages differently

WIP: settings-manager, sdk, interactive-mode, rpc-mode still need updates
2026-01-03 00:13:25 +01:00
Mario Zechner
5ef3cc90d1 Add guard against concurrent prompt() calls
Agent.prompt() and Agent.continue() now throw if called while already
streaming, preventing race conditions and corrupted state. Use
queueMessage() to queue messages during streaming, or await the
previous call.

AgentSession.prompt() has the same guard with a message directing
users to queueMessage().

Ref #403
2026-01-02 22:02:24 +01:00
Mario Zechner
d9adf659ca Fix edit tool failing on files with UTF-8 BOM
Strip BOM before matching (LLM won't include invisible BOM in oldText),
restore on write.

Based on #394 by @prathamdby
2026-01-02 01:57:24 +01:00
Mario Zechner
d51770a63d fix(coding-agent): prevent full re-renders during write tool streaming
Move line count from header to footer to avoid changing the first line
during streaming, which was triggering full screen re-renders in the
TUI's differential rendering logic.
2026-01-02 01:11:06 +01:00