feat: implement hooks, plugins, session forks, and vim motions

Add 4 major features to codetyper-cli:

- Hooks System: Lifecycle hooks (PreToolUse, PostToolUse, SessionStart,
  SessionEnd, UserPromptSubmit, Stop) with exit code control flow
- Plugin System: Custom tools, commands, and hooks via plugin manifest
- Session Forking: Snapshots, rewind, fork, and switch between branches
- Vim Motions: Normal/Insert/Command/Visual modes with keyboard navigation

New files:
- src/types/{hooks,plugin,session-fork,vim}.ts
- src/constants/{hooks,plugin,session-fork,vim}.ts
- src/services/{hooks-service,plugin-loader,plugin-service,session-fork-service}.ts
- src/stores/vim-store.ts (vanilla)
- src/tui/hooks/{useVimMode,useVimStore,useTodoStore,useThemeStore}.ts
- src/tui/components/VimStatusLine.tsx

Modified:
- src/services/agent.ts (hook integration)
- src/tools/index.ts (plugin tool registration)
- src/stores/{todo-store,theme-store}.ts (converted to vanilla)
- TUI components (updated hook imports)
This commit is contained in:
2026-01-31 22:22:04 -05:00
parent 37d4a43154
commit a3c407d89a
56 changed files with 7507 additions and 90 deletions

View File

@@ -9,6 +9,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- **Hooks System**: Lifecycle hooks for extensibility
- 6 hook events: PreToolUse, PostToolUse, SessionStart, SessionEnd, UserPromptSubmit, Stop
- Exit code control flow (0=allow, 1=warn, 2=block)
- JSON input/output via stdin/stdout
- Modified arguments via `updatedInput`
- Global + local configuration support
- Configurable timeout per hook
- **Plugin System**: Custom tools, commands, and hooks
- Plugin manifest with version and capabilities
- Custom tool definitions via TypeScript
- Custom slash commands via Markdown with frontmatter
- Plugin-specific hooks
- Global (~/.config/codetyper/plugins/) + local (.codetyper/plugins/)
- Dynamic tool/command registration
- **Session Forking/Rewind**: Branch and time-travel session history
- Named snapshots at any point in conversation
- Rewind to any snapshot by name or index
- Fork branches from any snapshot
- Switch between forks
- Suggested commit messages based on session content
- Commands: /snapshot, /rewind, /fork, /forks, /switch
- **Vim Motions**: Vim-style keyboard navigation
- 4 modes: Normal, Insert, Command, Visual
- Scroll navigation (j/k, gg/G, Ctrl+d/u)
- Search with highlighting (/, n/N)
- Command mode (:q, :w, :wq, :nohl)
- Mode indicator in status line
- Configurable via settings.json
- **Home Screen**: New welcome screen with centered gradient logo
- Displays version, provider, and model info
- Transitions to session view on first message

View File

@@ -135,11 +135,21 @@ docs: update README with new CLI options
src/
├── index.ts # Entry point only
├── commands/ # CLI command implementations
├── constants/ # Centralized constants
├── interfaces/ # Interface definitions
├── providers/ # LLM provider integrations
├── services/ # Business logic services
│ ├── hooks-service.ts # Lifecycle hooks
│ ├── plugin-service.ts # Plugin management
│ ├── plugin-loader.ts # Plugin discovery
│ └── session-fork-service.ts # Session forking
├── stores/ # Zustand state stores
│ └── vim-store.ts # Vim mode state
├── tools/ # Agent tools (bash, read, write, edit)
├── tui/ # Terminal UI components
── components/ # Reusable UI components
└── types.ts # Shared type definitions
── components/ # Reusable UI components
│ └── hooks/ # React hooks (useVimMode, etc.)
└── types/ # Type definitions
```
### Testing
@@ -170,11 +180,16 @@ describe('PermissionManager', () => {
| File | Purpose |
|------|---------|
| `src/index.ts` | CLI entry point, command registration |
| `src/agent.ts` | Agent loop, tool orchestration |
| `src/permissions.ts` | Permission system |
| `src/services/agent.ts` | Agent loop, tool orchestration |
| `src/services/permissions.ts` | Permission system |
| `src/services/hooks-service.ts` | Lifecycle hooks |
| `src/services/plugin-service.ts` | Plugin management |
| `src/services/session-fork-service.ts` | Session forking |
| `src/commands/chat-tui.tsx` | Main TUI command |
| `src/tui/App.tsx` | Root TUI component |
| `src/tui/store.ts` | Zustand state management |
| `src/stores/vim-store.ts` | Vim mode state |
| `src/tui/hooks/useVimMode.ts` | Vim keyboard handling |
### Adding a New Provider
@@ -192,6 +207,28 @@ describe('PermissionManager', () => {
4. Register in `src/tools/index.ts`
5. Add permission handling if needed
### Adding a Hook Event
1. Add event type to `src/types/hooks.ts`
2. Add constants to `src/constants/hooks.ts`
3. Add input type for the event
4. Implement execution in `src/services/hooks-service.ts`
5. Call hook from appropriate location
### Creating a Plugin
1. Create directory in `.codetyper/plugins/{name}/`
2. Add `plugin.json` manifest
3. Add tools in `tools/*.ts`
4. Add commands in `commands/*.md`
5. Add hooks in `hooks/*.sh`
### Adding Vim Bindings
1. Add binding to `VIM_DEFAULT_BINDINGS` in `src/constants/vim.ts`
2. Add action handler in `src/tui/hooks/useVimMode.ts`
3. Update documentation
## Questions?
- Open a GitHub issue for questions