diff --git a/packages/kilo-vscode/docs/chat-ui-features/context-menus-tooltips.md b/packages/kilo-vscode/docs/chat-ui-features/context-menus-tooltips.md index 2893fc5b6b..a13d794c49 100644 --- a/packages/kilo-vscode/docs/chat-ui-features/context-menus-tooltips.md +++ b/packages/kilo-vscode/docs/chat-ui-features/context-menus-tooltips.md @@ -1,20 +1,29 @@ -# Context Menus & Tooltips +# Context Menus & Tooltips (Webview) -Right-click/context actions and tooltip affordances throughout the chat UI. +Right-click/context actions and tooltip affordances within the chat webview UI. -## Location +> **Note:** For VS Code-native context menus (editor right-click, terminal right-click, code action lightbulb), see [Editor Context Menus & Code Actions](../non-agent-features/editor-context-menus-and-code-actions.md). -- [`webview-ui/src/components/common/ContextMenu.tsx`](../../webview-ui/src/components/common/ContextMenu.tsx:1) -- Various `StandardTooltip` usage +## Scope + +This document covers **webview-internal** context menus and tooltips — i.e., right-click menus and hover tooltips rendered inside the Kilo Code chat panel. + +## Current State -## Interactions +- kilo-ui provides `Tooltip` and `Popover` components, already in use throughout the webview (TaskHeader, ModelSelector, etc.) +- No webview-internal right-click context menu exists yet -- Hover tooltips with explanatory text for all interactive buttons -- Context actions via right-click or dedicated menu buttons +## Remaining Work -## Suggested migration +- Add hover tooltips with explanatory text for all interactive buttons in the chat UI +- Implement right-click context menus on chat messages (copy, retry, edit, delete) +- Consider context menus on code blocks (copy code, insert at cursor, apply diff) + +## Location + +- [`webview-ui/src/components/common/ContextMenu.tsx`](../../webview-ui/src/components/common/ContextMenu.tsx:1) +- kilo-ui `Tooltip` component usage throughout webview -**Reimplement?** No (UI-only). +## Implementation Notes -- These are presentation-layer affordances; backend migration does not affect them. -- Kilo CLI has similar tooltip infrastructure in its UI package ([`packages/ui/src/components/tooltip.tsx`](https://github.com/Kilo-Org/kilo/blob/main/packages/ui/src/components/tooltip.tsx:1)), but Kilo can keep its current tooltip + context menu components. +These are presentation-layer affordances; the CLI backend is not involved. kilo-ui already provides the tooltip infrastructure needed. diff --git a/packages/kilo-vscode/docs/non-agent-features/code-actions.md b/packages/kilo-vscode/docs/non-agent-features/code-actions.md deleted file mode 100644 index 939745d64c..0000000000 --- a/packages/kilo-vscode/docs/non-agent-features/code-actions.md +++ /dev/null @@ -1,24 +0,0 @@ -# Code Actions - -- **What it is**: Integrates into VS Code Code Actions UI (lightbulb/context menu) to trigger AI actions like explain/fix/improve, or add selection to context. - -## Notable characteristics - -- Can run inside current task or spawn a new task. -- Prompt templates configurable. - -## Docs references - -- [`apps/kilocode-docs/pages/code-with-ai/features/code-actions.md`](../../apps/kilocode-docs/pages/code-with-ai/features/code-actions.md) - -## Suggested migration - -- **Kilo CLI availability**: Not present. -- **Migration recommendation**: - - Keep code actions in the VS Code extension host (VS Code APIs, diagnostics, and editor-specific UX). - - Reimplement any backing logic that currently depends on the core agent loop, but keep action registration and application IDE-side. -- **Reimplementation required?**: Yes. - -## Primary implementation anchors (partial) - -- [`src/services/ghost/GhostCodeActionProvider.ts`](../../src/services/ghost/GhostCodeActionProvider.ts) diff --git a/packages/kilo-vscode/docs/non-agent-features/editor-context-menus-and-code-actions.md b/packages/kilo-vscode/docs/non-agent-features/editor-context-menus-and-code-actions.md new file mode 100644 index 0000000000..5ded1f54c8 --- /dev/null +++ b/packages/kilo-vscode/docs/non-agent-features/editor-context-menus-and-code-actions.md @@ -0,0 +1,458 @@ +# Editor Context Menus & Code Actions + +Full spec of the VS Code-native menu, command, code action, keyboard shortcut, and prompt template system from the old Kilo Code extension. All of these need to be rebuilt in the new extension. + +> **Note:** For webview-internal context menus (right-click inside the chat panel), see [Context Menus & Tooltips (Webview)](../chat-ui-features/context-menus-tooltips.md). +> For SCM commit message generation, see [Git Commit Message Generation](git-commit-message-generation.md). +> This document supersedes the old stub at [`code-actions.md`](code-actions.md). + +--- + +## Overview + +The old extension registered a comprehensive set of VS Code contributions: + +- A **"Kilo Code" submenu** in the editor right-click context menu +- A **"Kilo Code" submenu** in the terminal right-click context menu +- A **CodeActionProvider** for lightbulb quick fixes +- **Keyboard shortcuts** for common actions +- **Prompt templates** (user-customizable) that turn captured context into agent task instructions + +None of these exist yet in the rebuild. + +--- + +## Editor Context Menus + +Right-clicking in the editor shows a "Kilo Code" submenu with these commands: + +| Command ID | Label | Captured Context | Behavior | +| ---------------- | ------------------ | --------------------------------------------------- | ------------------------------------------------- | +| `explainCode` | Explain Code | File path, selected text, line range | Starts an agent task with the EXPLAIN prompt | +| `fixCode` | Fix Code | File path, selected text, line range, diagnostics | Starts an agent task with the FIX prompt | +| `improveCode` | Improve Code | File path, selected text, line range | Starts an agent task with the IMPROVE prompt | +| `addToContext` | Add to Context | File path, selected text, line range | Injects formatted code block into chat input (does **not** start a task) | + +All commands use the VS Code editor API to capture the active editor's file path (`document.uri`), current selection (`editor.selection`), and the selected text. `fixCode` additionally captures diagnostics from `vscode.languages.getDiagnostics()` for the selection range. + +--- + +## Terminal Context Menus + +Right-clicking in the terminal shows a "Kilo Code" submenu: + +| Command ID | Label | Captured Context | Behavior | +| ------------------------- | ---------------------- | -------------------------------------- | -------------------------------------------------- | +| `terminalAddToContext` | Add to Context | Terminal selection or recent buffer | Injects terminal output into chat input | +| `terminalFixCommand` | Fix Command | Last executed command + output | Starts an agent task with the TERMINAL_FIX prompt | +| `terminalExplainCommand` | Explain Command | Last executed command + output | Starts an agent task with the TERMINAL_EXPLAIN prompt | + +Terminal context capture uses `vscode.window.activeTerminal` and the terminal selection API. + +> See also [Terminal / Shell Integration](terminal-shell-integration.md) for the underlying terminal command execution and PTY management that these context menu actions depend on. + +--- + +## Code Action Provider (Lightbulb Quick Fixes) + +A `CodeActionProvider` is registered for all languages. When the user clicks the lightbulb or presses the quick fix shortcut: + +| Condition | Actions shown | +| ------------------------------ | --------------------------------------------------------------------- | +| Always | **Add to Kilo Code** → triggers `addToContext` | +| Diagnostics in selection range | **Fix with Kilo Code** → triggers `fixCode` | +| No diagnostics | **Explain with Kilo Code** → triggers `explainCode` | +| No diagnostics | **Improve with Kilo Code** → triggers `improveCode` | + +Controlled by the `enableCodeActions` extension setting (default: `true`). + +--- + +## Keyboard Shortcuts + +| Shortcut (Mac / Win+Linux) | Command | Description | +| ---------------------------------- | --------------------------- | ------------------------------ | +| `Cmd+Shift+A` / `Ctrl+Shift+A` | Focus chat input | Opens/focuses the chat panel | +| `Cmd+K Cmd+A` / `Ctrl+K Ctrl+A` | Add selection to context | Runs `addToContext` | +| `Cmd+Shift+G` / `Ctrl+Shift+G` | Generate terminal command | Starts TERMINAL_GENERATE task | +| `Cmd+Alt+A` / `Ctrl+Alt+A` | Toggle auto-approve | Toggles auto-approval setting | + +--- + +## Prompt Templates + +The old extension defined prompt templates in `support-prompt.ts` that format captured context into agent task instructions. Each template is user-customizable via extension settings. + +| Template | Used by | Purpose | +| ---------------------- | ----------------------------- | -------------------------------------------------------- | +| `EXPLAIN` | `explainCode` | Ask the agent to explain the selected code | +| `FIX` | `fixCode` | Ask the agent to fix code, including diagnostic details | +| `IMPROVE` | `improveCode` | Ask the agent to improve/refactor selected code | +| `ADD_TO_CONTEXT` | `addToContext` | Format a code block for injection into chat input | +| `TERMINAL_ADD_TO_CONTEXT` | `terminalAddToContext` | Format terminal output for injection into chat input | +| `TERMINAL_FIX` | `terminalFixCommand` | Ask the agent to fix a failed terminal command | +| `TERMINAL_EXPLAIN` | `terminalExplainCommand` | Ask the agent to explain a terminal command/output | +| `TERMINAL_GENERATE` | Generate terminal command | Ask the agent to generate a terminal command | +| `COMMIT_MESSAGE` | SCM integration | Generate a commit message (tracked separately) | + +--- + +## Data Flow + +There are two distinct patterns: + +### 1. Action → Agent Task + +Commands like `explainCode`, `fixCode`, `improveCode`, `terminalFixCommand`, and `terminalExplainCommand` follow this flow: + +1. User triggers command (context menu, code action, or keybinding) +2. Extension captures context from VS Code APIs (editor selection, diagnostics, terminal buffer) +3. Extension fills in the prompt template with captured context +4. Extension sends the formatted prompt as a new message to the CLI session (creating a new task) + +### 2. Action → Context Injection + +Commands like `addToContext` and `terminalAddToContext` follow a different flow: + +1. User triggers command +2. Extension captures context from VS Code APIs +3. Extension formats the context as a code block using the template +4. Extension posts a message to the webview to **set the chat input text** (not submit it) +5. User can review and edit before sending + +--- + +## Implementation Notes for Rebuild + +### `package.json` Contributions + +Register in `contributes`: +- `submenus`: Define "Kilo Code" submenus for editor and terminal contexts +- `menus`: Register commands under `editor/context` and `terminal/context` menu groups +- `commands`: Register all command IDs with titles and icons +- `keybindings`: Register keyboard shortcuts with `key`, `mac`, and `when` clauses + +> **Note:** [`package.json`](../../package.json) already has `contributes.commands` (8 commands) and `contributes.menus` (`view/title` + `editor/title` menus) registered. New commands, submenus, and keybindings should be **added alongside** the existing entries, not replace them. + +### CodeActionProvider + +- Register a `CodeActionProvider` for `*` (all languages) +- Check `vscode.languages.getDiagnostics()` to decide which actions to show +- Gate behind the `enableCodeActions` setting +- Return `CodeAction` instances with `command` set to the appropriate command ID + +### Editor Context Capture + +- `vscode.window.activeTextEditor` for file path, selection, document +- `editor.document.getText(selection)` for selected text +- `selection.start.line` / `selection.end.line` for line range +- `vscode.languages.getDiagnostics(document.uri)` filtered to selection range for `fixCode` + +### Terminal Context Capture + +- `vscode.window.activeTerminal` for the active terminal +- Terminal selection API for selected text in terminal +- Shell integration API for last command and its output (where available) + +### Prompt Templates + +Need an equivalent template system in the extension. Options: +- Hardcode templates with settings overrides (like the old extension) +- Delegate prompt construction to the CLI (if it supports parameterized task creation) + +### "Add to Context" Pattern + +The webview needs to handle an incoming message that **sets the chat input text** without submitting it. This requires: +- A new message type (e.g., `SetChatInput`) in the extension→webview protocol +- The `PromptInput` component to accept externally-set text + +--- + +## Prompt Templates (Full Text) + +Below are the exact prompt templates from the old extension's `src/shared/support-prompt.ts`. Each template uses `${variable}` interpolation. These are the defaults; users can customize any template via the `customSupportPrompts` extension setting. + +> **Note:** The `diagnosticText` variable used in the FIX template is auto-generated from VS Code diagnostics using the format `- [source] message (code)`. + +### EXPLAIN + +**Variables:** `filePath`, `startLine`, `endLine`, `userInput`, `selectedText` + +``` +Explain the following code from file path ${filePath}:${startLine}-${endLine} +${userInput} + +\`\`\` +${selectedText} +\`\`\` + +Please provide a clear and concise explanation of what this code does, including: +1. The purpose and functionality +2. Key components and their interactions +3. Important patterns or techniques used +``` + +### FIX + +**Variables:** `filePath`, `startLine`, `endLine`, `diagnosticText`, `userInput`, `selectedText` + +``` +Fix any issues in the following code from file path ${filePath}:${startLine}-${endLine} +${diagnosticText} +${userInput} + +\`\`\` +${selectedText} +\`\`\` + +Please: +1. Address all detected problems listed above (if any) +2. Identify any other potential bugs or issues +3. Provide corrected code +4. Explain what was fixed and why +``` + +### IMPROVE + +**Variables:** `filePath`, `startLine`, `endLine`, `userInput`, `selectedText` + +``` +Improve the following code from file path ${filePath}:${startLine}-${endLine} +${userInput} + +\`\`\` +${selectedText} +\`\`\` + +Please suggest improvements for: +1. Code readability and maintainability +2. Performance optimization +3. Best practices and patterns +4. Error handling and edge cases + +Provide the improved code along with explanations for each enhancement. +``` + +### ADD_TO_CONTEXT + +**Variables:** `filePath`, `startLine`, `endLine`, `selectedText` + +``` +${filePath}:${startLine}-${endLine} +\`\`\` +${selectedText} +\`\`\` +``` + +### TERMINAL_ADD_TO_CONTEXT + +**Variables:** `userInput`, `terminalContent` + +``` +${userInput} +Terminal output: +\`\`\` +${terminalContent} +\`\`\` +``` + +### TERMINAL_FIX + +**Variables:** `userInput`, `terminalContent` + +``` +${userInput} +Fix this terminal command: +\`\`\` +${terminalContent} +\`\`\` + +Please: +1. Identify any issues in the command +2. Provide the corrected command +3. Explain what was fixed and why +``` + +### TERMINAL_EXPLAIN + +**Variables:** `userInput`, `terminalContent` + +``` +${userInput} +Explain this terminal command: +\`\`\` +${terminalContent} +\`\`\` + +Please provide: +1. What the command does +2. Explanation of each part/flag +3. Expected output and behavior +``` + +### TERMINAL_GENERATE *(Kilo-specific addition)* + +**Variables:** `userInput`, `operatingSystem`, `currentDirectory`, `shell` + +``` +Generate a terminal command based on this description: "${userInput}" + +Context: +- Operating System: ${operatingSystem} +- Current Directory: ${currentDirectory} +- Shell: ${shell} + +Requirements: +1. Generate ONLY the command, no explanations or formatting +2. Ensure the command is safe and appropriate +3. Use common command-line tools and best practices +4. Consider the current working directory context +5. Return only the raw command that can be executed directly +``` + +### ENHANCE + +**Variables:** `userInput` + +``` +Generate an enhanced version of this prompt (reply with only the enhanced prompt - no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes): + +${userInput} +``` + +### CONDENSE + +**Variables:** none (system prompt for conversation summary) + +``` +Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions. +This summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing with the conversation and supporting any continuing tasks. + +Your summary should be structured as follows: +Context: The context to continue the conversation with. If applicable based on the current task, this should include: + 1. Previous Conversation: High level details about what was discussed throughout the entire conversation with the user. This should be written to allow someone to be able to follow the general overarching conversation flow. + 2. Current Work: Describe in detail what was being worked on prior to this request to summarize the conversation. Pay special attention to the more recent messages in the conversation. + 3. Key Technical Concepts: List all important technical concepts, technologies, coding conventions, and frameworks discussed, which might be relevant for continuing with this work. + 4. Relevant Files and Code: If applicable, enumerate specific files and code sections examined, modified, or created for the task continuation. Pay special attention to the most recent messages and changes. + 5. Problem Solving: Document problems solved thus far and any ongoing troubleshooting efforts. + 6. Pending Tasks and Next Steps: Outline all pending tasks that you have explicitly been asked to work on, as well as list the next steps you will take for all outstanding work, if applicable. Include code snippets where they add clarity. For any next steps, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure there's no information loss in context between tasks. + +Example summary structure: +1. Previous Conversation: + [Detailed description] +2. Current Work: + [Detailed description] +3. Key Technical Concepts: + - [Concept 1] + - [Concept 2] + - [...] +4. Relevant Files and Code: + - [File Name 1] + - [Summary of why this file is important] + - [Summary of the changes made to this file, if any] + - [Important Code Snippet] + - [File Name 2] + - [Important Code Snippet] + - [...] +5. Problem Solving: + [Detailed description] +6. Pending Tasks and Next Steps: + - [Task 1 details & next steps] + - [Task 2 details & next steps] + - [...] + +Output only the summary of the conversation so far, without any additional commentary or explanation. +``` + +### COMMIT_MESSAGE *(Kilo-specific addition, tracked separately in [git-commit-message-generation.md](git-commit-message-generation.md))* + +**Variables:** `customInstructions`, `gitContext` + +```` +# Conventional Commit Message Generator +## System Instructions +You are an expert Git commit message generator that creates conventional commit messages based on staged changes. Analyze the provided git diff output and generate appropriate conventional commit messages following the specification. + +${customInstructions} + +## CRITICAL: Commit Message Output Rules +- DO NOT include any internal status indicators or bracketed metadata (e.g. "[Status: Active]", "[Context: Missing]") +- DO NOT include any task-specific formatting or artifacts from other rules +- ONLY Generate a clean conventional commit message as specified below + +${gitContext} + +## Conventional Commits Format +Generate commit messages following this exact structure: +``` +[optional scope]: +[optional body] +[optional footer(s)] +``` + +### Core Types (Required) +- **feat**: New feature or functionality (MINOR version bump) +- **fix**: Bug fix or error correction (PATCH version bump) + +### Additional Types (Extended) +- **docs**: Documentation changes only +- **style**: Code style changes (whitespace, formatting, semicolons, etc.) +- **refactor**: Code refactoring without feature changes or bug fixes +- **perf**: Performance improvements +- **test**: Adding or fixing tests +- **build**: Build system or external dependency changes +- **ci**: CI/CD configuration changes +- **chore**: Maintenance tasks, tooling changes +- **revert**: Reverting previous commits + +### Scope Guidelines +- Use parentheses: `feat(api):`, `fix(ui):` +- Common scopes: `api`, `ui`, `auth`, `db`, `config`, `deps`, `docs` +- For monorepos: package or module names +- Keep scope concise and lowercase + +### Description Rules +- Use imperative mood ("add" not "added" or "adds") +- Start with lowercase letter +- No period at the end +- Maximum 50 characters +- Be concise but descriptive + +### Body Guidelines (Optional) +- Start one blank line after description +- Explain the "what" and "why", not the "how" +- Wrap at 72 characters per line +- Use for complex changes requiring explanation + +### Footer Guidelines (Optional) +- Start one blank line after body +- **Breaking Changes**: `BREAKING CHANGE: description` + +## Analysis Instructions +When analyzing staged changes: +1. Determine Primary Type based on the nature of changes +2. Identify Scope from modified directories or modules +3. Craft Description focusing on the most significant change +4. Determine if there are Breaking Changes +5. For complex changes, include a detailed body explaining what and why +6. Add appropriate footers for issue references or breaking changes + +For significant changes, include a detailed body explaining the changes. + +Return ONLY the commit message in the conventional format, nothing else. +```` + +### NEW_TASK + +**Variables:** `userInput` + +``` +${userInput} +``` + +--- + +### Already Done / Tracked Elsewhere + +- **View title bar buttons**: ✅ Done ([#181](https://github.com/Kilo-Org/kilo/issues/181)) +- **SCM commit message generation**: Tracked in [git-commit-message-generation.md](git-commit-message-generation.md) diff --git a/packages/kilo-vscode/docs/opencode-migration-plan.md b/packages/kilo-vscode/docs/opencode-migration-plan.md index bd018b2175..6ed20972d2 100644 --- a/packages/kilo-vscode/docs/opencode-migration-plan.md +++ b/packages/kilo-vscode/docs/opencode-migration-plan.md @@ -72,41 +72,41 @@ The rebuild has a working foundation: ## Non-Agent Feature Parity -| Feature | Status | Details | Backend | Priority | -| ------------------------------------------------------------------------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | -------- | -| Agent Manager | ✅ Done | `AgentManagerProvider` opens editor panel, creates git worktrees for parallel sessions, full `createWorktreeSession` lifecycle (worktree → session → first message). `WorktreeManager` handles `git worktree add`, metadata, and discovery. `WorktreeSelector` in PromptInput toggles local/worktree mode. [#178](https://github.com/Kilo-Org/kilo/issues/178) | Extension orchestrates multiple CLI sessions | P1 | -| [Authentication & Enterprise](non-agent-features/authentication-organization-enterprise-enforcement.md) | 🔨 Partial | Device auth flow works, organization switching implemented. Missing: org feature flags, MDM policy enforcement. [#160](https://github.com/Kilo-Org/kilo/issues/160) | CLI handles its auth; extension handles org/MDM | P1 | -| [Auto-Purge](non-agent-features/auto-purge.md) | ❌ Not started | No scheduled cleanup of old session/task storage. | Extension-side (storage ownership TBD) | P3 | -| Autocomplete / Ghost | ✅ Done | `AutocompleteInlineCompletionProvider` implements `vscode.InlineCompletionItemProvider` with FIM completions via Kilo Gateway. Includes debouncing, LRU cache, tree-sitter context, bracket matching, and stream-based completion. `AutocompleteServiceManager` registers/unregisters the provider. [#164](https://github.com/Kilo-Org/kilo/issues/164) | Extension-side (VS Code InlineCompletionProvider) | P1 | -| [Browser Automation & URL Ingestion](non-agent-features/browser-automation-url-ingestion.md) | 🔨 Partial | Playwright MCP integration implemented: settings toggle, BrowserAutomationService, CLI MCP hub registration, BrowserTab settings UI. Missing: URL-to-markdown ingestion, screenshot viewing in chat. | CLI MCP hub (POST /mcp); extension manages lifecycle | P3 | -| [Checkpoints](non-agent-features/checkpoints.md) | ❌ Not started | No shadow git repo, per-task snapshots, restore UI, or diff viewing. Settings tab is a stub. | CLI (partial: session undo/redo); extension for git snapshots | P1 | -| [Cloud Task Support](non-agent-features/cloud-task-support.md) | ❌ Not started | No cloud sync for tasks across devices. [#168](https://github.com/Kilo-Org/kilo/issues/168) | Kilo cloud API + CLI; extension provides UI | P2 | -| [Code Actions](non-agent-features/code-actions.md) | ❌ Not started | No VS Code lightbulb/context menu integrations (explain, fix, improve). | Extension-side (VS Code CodeActionProvider) | P2 | -| [Code Reviews](non-agent-features/code-reviews.md) | ❌ Not started | No local review mode or automated AI review of uncommitted/branch changes. | CLI (partial); extension for VS Code review UX | P2 | -| [Codebase Indexing & Semantic Search](non-agent-features/codebase-indexing-semantic-search.md) | ❌ Not started | No vector indexing, semantic search, or embeddings infrastructure. | CLI has grep/glob endpoints; semantic indexing is extension or cloud | P2 | -| [Contribution Tracking](non-agent-features/contribution-tracking.md) | ❌ Not started | No AI attribution tracking, line fingerprinting, or reporting. | Extension-side | P3 | -| [Custom Commands](non-agent-features/custom-command-system.md) | ❌ Not started | No slash commands, project-level command discovery, or YAML frontmatter support. | CLI has custom commands; extension provides UI entry points | P2 | -| [Deploy & Secure Surfaces](non-agent-features/deploy-and-secure-surfaces.md) | ❌ Not started | No deploy workflows, managed indexing UI, or security review surfaces. | Extension-side | P3 | -| [Fast Edits](non-agent-features/fast-edits.md) | ❌ Not started | No fast edit mode for quick inline code changes. | CLI fast-edit runtime; extension provides UI | P2 | -| [Git Commit Message Generation](non-agent-features/git-commit-message-generation.md) | ❌ Not started | No AI commit message generation or VS Code Source Control integration. [#165](https://github.com/Kilo-Org/kilo/issues/165) | Extension-side (VS Code Git API) | P2 | -| [Integrations](non-agent-features/integrations.md) | ❌ Not started | No external system integrations (GitHub, etc.) beyond basic auth. | CLI plugin system (partial); extension for IDE hooks | P3 | -| Kilo Gateway | ✅ Done | Kilo Gateway (`KILO_GATEWAY_ID = "kilo"`) is the default provider, listed first in ModelSelector via `PROVIDER_ORDER`. Login/logout/org switching fully implemented in `KiloProvider.ts` and `ProfileView.tsx`. Default model selection in ProvidersTab. [#176](https://github.com/Kilo-Org/kilo/issues/176) | CLI handles gateway connection; extension provides config UI | P0 | -| Localization | ✅ Done | Full i18n system with 16 locales in [`i18n/`](../webview-ui/src/i18n/), three-layer dict merging, locale auto-detection, LanguageTab settings UI with locale selector. | Extension + webview; CLI locale mapping needed | P3 | -| [Marketplace](non-agent-features/marketplace.md) | 🔨 Partial | Placeholder view exists but is non-functional. No catalog, install, or update capabilities. [#169](https://github.com/Kilo-Org/kilo/issues/169) | Extension-side | P2 | -| [MCP & MCP Hub](non-agent-features/mcp-and-mcp-hub.md) | 🔨 Partial | MCP types and HTTP client methods added (getMcpStatus, addMcpServer, connectMcpServer, disconnectMcpServer). Used by BrowserAutomationService. Missing: general MCP configuration UI, server management, tool allowlisting, connection status display. | CLI owns MCP lifecycle; extension provides config UI | P1 | -| Mode Switcher | ✅ Done | ModeSwitcher.tsx implements popover-based agent/mode selector with descriptions, persisted via session.selectAgent(). Integrated into PromptInput. [#162](https://github.com/Kilo-Org/kilo/issues/162) | CLI manages modes; extension provides switcher UI | P2 | -| Model Switcher | ✅ Done | ModelSelector.tsx implements popover-based selector with search/filter, keyboard navigation, provider grouping, free model tags. Integrated into PromptInput. [#163](https://github.com/Kilo-Org/kilo/issues/163) | CLI provides model list; extension provides switcher UI | P1 | -| Provider Configuration | ✅ Done | `ProvidersTab` implements default/small model selection (backed by `ConfigProvider` + `PATCH /global/config`), disabled-providers list, and enabled-providers allowlist. Provider context wired into ModelSelector. [#175](https://github.com/Kilo-Org/kilo/issues/175) | CLI manages providers; extension provides config UI | P1 | -| [Repository Initialization](non-agent-features/repository-initialization.md) | ❌ Not started | No /init command support for setting up agentic engineering. [#174](https://github.com/Kilo-Org/kilo/issues/174) | CLI /init endpoint; extension provides UI trigger | P3 | -| [Rules & Workflows](non-agent-features/rules-and-workflows.md) | ❌ Not started | No rules or workflow management UI. [#173](https://github.com/Kilo-Org/kilo/issues/173) | CLI owns rules runtime; extension provides management UI | P3 | -| [Search & Repo Scanning](non-agent-features/search-and-repo-scanning-infrastructure.md) | ❌ Not started | No search infrastructure beyond CLI grep/glob. | CLI has grep/glob; extension may add UI | P2 | -| [Settings Sync](non-agent-features/settings-sync-integration.md) | ❌ Not started | No VS Code Settings Sync allowlist registration. Settings tabs are all stubs. | Extension-side (VS Code API) | P3 | -| [Settings UI](non-agent-features/settings-ui.md) | 🔨 Partial | 14-tab settings implemented: Providers (model selection + allowlists), AgentBehaviour (MCP read-only, rules, skills), AutoApprove (per-tool dropdowns), Browser, Autocomplete, Display, Notifications, Context, Terminal, Prompts, Experimental, Language, AboutKiloCode. Missing: Workflows subtab (placeholder). [#170](https://github.com/Kilo-Org/kilo/issues/170) | CLI exposes config; extension provides settings forms | P1 | -| [Skills System](non-agent-features/skills-system.md) | ❌ Not started | No skill discovery, management, or hot-reload in extension. | CLI has skills runtime; extension provides packaging/UI | P2 | -| [Speech-to-Text](non-agent-features/speech-to-text.md) | ❌ Not started | No voice input or streaming STT. | Webview (mic capture); CLI-compatible STT optional | P3 | -| Task History | ✅ Done | `SessionList` uses kilo-ui `List` with search (filterKeys=["title"]), date grouping (Today/Yesterday/This Week/This Month/Older), relative timestamps, inline rename, and delete with confirmation. [#167](https://github.com/Kilo-Org/kilo/issues/167) | CLI session storage; extension provides history UI | P1 | -| Telemetry | ✅ Done | `TelemetryProxy` singleton POSTs events to `/telemetry/capture` respecting `vscode.env.isTelemetryEnabled`. Webview `captureTelemetryEvent()` posts to extension which forwards to `TelemetryProxy`. Both sides wired end-to-end. | Extension-side (PostHog + kilo-telemetry) | P1 | -| [Terminal / Shell Integration](non-agent-features/terminal-shell-integration.md) | ❌ Not started | No VS Code terminal integration for command execution display, exit code tracking, or working directory changes. | CLI executes commands; extension provides terminal UX | P1 | +| Feature | Status | Details | Backend | Priority | +| ------------------------------------------------------------------------------------------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | -------- | +| Agent Manager | ✅ Done | `AgentManagerProvider` opens editor panel, creates git worktrees for parallel sessions, full `createWorktreeSession` lifecycle (worktree → session → first message). `WorktreeManager` handles `git worktree add`, metadata, and discovery. `WorktreeSelector` in PromptInput toggles local/worktree mode. [#178](https://github.com/Kilo-Org/kilo/issues/178) | Extension orchestrates multiple CLI sessions | P1 | +| [Authentication & Enterprise](non-agent-features/authentication-organization-enterprise-enforcement.md) | 🔨 Partial | Device auth flow works, organization switching implemented. Missing: org feature flags, MDM policy enforcement. [#160](https://github.com/Kilo-Org/kilo/issues/160) | CLI handles its auth; extension handles org/MDM | P1 | +| [Auto-Purge](non-agent-features/auto-purge.md) | ❌ Not started | No scheduled cleanup of old session/task storage. | Extension-side (storage ownership TBD) | P3 | +| Autocomplete / Ghost | ✅ Done | `AutocompleteInlineCompletionProvider` implements `vscode.InlineCompletionItemProvider` with FIM completions via Kilo Gateway. Includes debouncing, LRU cache, tree-sitter context, bracket matching, and stream-based completion. `AutocompleteServiceManager` registers/unregisters the provider. [#164](https://github.com/Kilo-Org/kilo/issues/164) | Extension-side (VS Code InlineCompletionProvider) | P1 | +| [Browser Automation & URL Ingestion](non-agent-features/browser-automation-url-ingestion.md) | 🔨 Partial | Playwright MCP integration implemented: settings toggle, BrowserAutomationService, CLI MCP hub registration, BrowserTab settings UI. Missing: URL-to-markdown ingestion, screenshot viewing in chat. | CLI MCP hub (POST /mcp); extension manages lifecycle | P3 | +| [Checkpoints](non-agent-features/checkpoints.md) | ❌ Not started | No shadow git repo, per-task snapshots, restore UI, or diff viewing. Settings tab is a stub. | CLI (partial: session undo/redo); extension for git snapshots | P1 | +| [Cloud Task Support](non-agent-features/cloud-task-support.md) | ❌ Not started | No cloud sync for tasks across devices. [#168](https://github.com/Kilo-Org/kilo/issues/168) | Kilo cloud API + CLI; extension provides UI | P2 | +| [Code Actions & Editor Menus](non-agent-features/editor-context-menus-and-code-actions.md) | 🔨 Partial | Editor/terminal right-click submenus, CodeActionProvider lightbulb, keyboard shortcuts, and prompt templates implemented. Terminal content capture is a stub (needs shell integration API). Missing: custom prompt overrides via settings. | Extension-side (VS Code CodeActionProvider + menus + keybindings) | P1 | +| [Code Reviews](non-agent-features/code-reviews.md) | ❌ Not started | No local review mode or automated AI review of uncommitted/branch changes. | CLI (partial); extension for VS Code review UX | P2 | +| [Codebase Indexing & Semantic Search](non-agent-features/codebase-indexing-semantic-search.md) | ❌ Not started | No vector indexing, semantic search, or embeddings infrastructure. | CLI has grep/glob endpoints; semantic indexing is extension or cloud | P2 | +| [Contribution Tracking](non-agent-features/contribution-tracking.md) | ❌ Not started | No AI attribution tracking, line fingerprinting, or reporting. | Extension-side | P3 | +| [Custom Commands](non-agent-features/custom-command-system.md) | ❌ Not started | No slash commands, project-level command discovery, or YAML frontmatter support. | CLI has custom commands; extension provides UI entry points | P2 | +| [Deploy & Secure Surfaces](non-agent-features/deploy-and-secure-surfaces.md) | ❌ Not started | No deploy workflows, managed indexing UI, or security review surfaces. | Extension-side | P3 | +| [Fast Edits](non-agent-features/fast-edits.md) | ❌ Not started | No fast edit mode for quick inline code changes. | CLI fast-edit runtime; extension provides UI | P2 | +| [Git Commit Message Generation](non-agent-features/git-commit-message-generation.md) | ❌ Not started | No AI commit message generation or VS Code Source Control integration. [#165](https://github.com/Kilo-Org/kilo/issues/165) | Extension-side (VS Code Git API) | P2 | +| [Integrations](non-agent-features/integrations.md) | ❌ Not started | No external system integrations (GitHub, etc.) beyond basic auth. | CLI plugin system (partial); extension for IDE hooks | P3 | +| Kilo Gateway | ✅ Done | Kilo Gateway (`KILO_GATEWAY_ID = "kilo"`) is the default provider, listed first in ModelSelector via `PROVIDER_ORDER`. Login/logout/org switching fully implemented in `KiloProvider.ts` and `ProfileView.tsx`. Default model selection in ProvidersTab. [#176](https://github.com/Kilo-Org/kilo/issues/176) | CLI handles gateway connection; extension provides config UI | P0 | +| Localization | ✅ Done | Full i18n system with 16 locales in [`i18n/`](../webview-ui/src/i18n/), three-layer dict merging, locale auto-detection, LanguageTab settings UI with locale selector. | Extension + webview; CLI locale mapping needed | P3 | +| [Marketplace](non-agent-features/marketplace.md) | 🔨 Partial | Placeholder view exists but is non-functional. No catalog, install, or update capabilities. [#169](https://github.com/Kilo-Org/kilo/issues/169) | Extension-side | P2 | +| [MCP & MCP Hub](non-agent-features/mcp-and-mcp-hub.md) | 🔨 Partial | MCP types and HTTP client methods added (getMcpStatus, addMcpServer, connectMcpServer, disconnectMcpServer). Used by BrowserAutomationService. Missing: general MCP configuration UI, server management, tool allowlisting, connection status display. | CLI owns MCP lifecycle; extension provides config UI | P1 | +| [Mode Switcher](non-agent-features/mode-switcher.md) | ✅ Done | ModeSwitcher.tsx implements popover-based agent/mode selector with descriptions, persisted via session.selectAgent(). Integrated into PromptInput. [#162](https://github.com/Kilo-Org/kilo/issues/162) | CLI manages modes; extension provides switcher UI | P2 | +| [Model Switcher](non-agent-features/model-switcher.md) | ✅ Done | ModelSelector.tsx implements popover-based selector with search/filter, keyboard navigation, provider grouping, free model tags. Integrated into PromptInput. [#163](https://github.com/Kilo-Org/kilo/issues/163) | CLI provides model list; extension provides switcher UI | P1 | +| [Provider Configuration](non-agent-features/provider-configuration.md) | 🔨 Partial | Provider context fetches and exposes provider data, connected providers, defaults, model lists — wired into ModelSelector. ProvidersTab UI still a stub. [#175](https://github.com/Kilo-Org/kilo/issues/175) | CLI manages providers; extension provides config UI | P1 | +| [Repository Initialization](non-agent-features/repository-initialization.md) | ❌ Not started | No /init command support for setting up agentic engineering. [#174](https://github.com/Kilo-Org/kilo/issues/174) | CLI /init endpoint; extension provides UI trigger | P3 | +| [Rules & Workflows](non-agent-features/rules-and-workflows.md) | ❌ Not started | No rules or workflow management UI. [#173](https://github.com/Kilo-Org/kilo/issues/173) | CLI owns rules runtime; extension provides management UI | P3 | +| [Search & Repo Scanning](non-agent-features/search-and-repo-scanning-infrastructure.md) | ❌ Not started | No search infrastructure beyond CLI grep/glob. | CLI has grep/glob; extension may add UI | P2 | +| [Settings Sync](non-agent-features/settings-sync-integration.md) | ❌ Not started | No VS Code Settings Sync allowlist registration. Settings tabs are all stubs. | Extension-side (VS Code API) | P3 | +| [Settings UI](non-agent-features/settings-ui.md) | 🔨 Partial | 15-tab settings shell exists. BrowserTab has real settings controls (enable/disable, system Chrome, headless toggles). LanguageTab has working locale selector. Remaining 13 tabs are stubs. [#170](https://github.com/Kilo-Org/kilo/issues/170) | CLI exposes config; extension provides settings forms | P1 | +| [Skills System](non-agent-features/skills-system.md) | ❌ Not started | No skill discovery, management, or hot-reload in extension. | CLI has skills runtime; extension provides packaging/UI | P2 | +| [Speech-to-Text](non-agent-features/speech-to-text.md) | ❌ Not started | No voice input or streaming STT. | Webview (mic capture); CLI-compatible STT optional | P3 | +| [Task History](non-agent-features/task-history.md) | 🔨 Partial | Session list exists but lacks search, metadata, and full persistence. [#167](https://github.com/Kilo-Org/kilo/issues/167) | CLI session storage; extension provides history UI | P1 | +| [Telemetry](non-agent-features/telemetry.md) | ❌ Not started | Dual-layer telemetry (PostHog Node server-side + PostHog JS client-side) for extension usage, errors, LLM completions, and AI interactions. Includes privacy controls, typed events, and structured error tracking. See detailed plan. | Extension-side (PostHog + kilo-telemetry) | P1 | +| [Terminal / Shell Integration](non-agent-features/terminal-shell-integration.md) | ❌ Not started | No VS Code terminal integration for command execution display, exit code tracking, or working directory changes. | CLI executes commands; extension provides terminal UX | P1 | --- diff --git a/packages/kilo-vscode/package.json b/packages/kilo-vscode/package.json index 34762065db..a99b5ff572 100644 --- a/packages/kilo-vscode/package.json +++ b/packages/kilo-vscode/package.json @@ -109,32 +109,56 @@ "light": "assets/icons/kilo-light.svg", "dark": "assets/icons/kilo-dark.svg" } - } - ], - "keybindings": [ + }, { - "command": "kilo-code.new.agentManager.previousSession", - "key": "ctrl+up", - "mac": "cmd+up", - "when": "activeWebviewPanelId == 'kilo-code.new.AgentManagerPanel'" + "command": "kilo-code.new.explainCode", + "title": "Explain Code", + "category": "Kilo Code" }, { - "command": "kilo-code.new.agentManager.nextSession", - "key": "ctrl+down", - "mac": "cmd+down", - "when": "activeWebviewPanelId == 'kilo-code.new.AgentManagerPanel'" + "command": "kilo-code.new.fixCode", + "title": "Fix Code", + "category": "Kilo Code" }, { - "command": "kilo-code.new.agentManager.previousTab", - "key": "ctrl+left", - "mac": "cmd+left", - "when": "activeWebviewPanelId == 'kilo-code.new.AgentManagerPanel'" + "command": "kilo-code.new.improveCode", + "title": "Improve Code", + "category": "Kilo Code" }, { - "command": "kilo-code.new.agentManager.nextTab", - "key": "ctrl+right", - "mac": "cmd+right", - "when": "activeWebviewPanelId == 'kilo-code.new.AgentManagerPanel'" + "command": "kilo-code.new.addToContext", + "title": "Add to Context", + "category": "Kilo Code" + }, + { + "command": "kilo-code.new.terminalAddToContext", + "title": "Add Terminal Content to Context", + "category": "Kilo Code" + }, + { + "command": "kilo-code.new.terminalFixCommand", + "title": "Fix This Command", + "category": "Kilo Code" + }, + { + "command": "kilo-code.new.terminalExplainCommand", + "title": "Explain This Command", + "category": "Kilo Code" + }, + { + "command": "kilo-code.new.focusChatInput", + "title": "Focus Chat Input", + "category": "Kilo Code" + } + ], + "submenus": [ + { + "id": "kilo-code.new.editorContextMenu", + "label": "Kilo Code" + }, + { + "id": "kilo-code.new.terminalContextMenu", + "label": "Kilo Code" } ], "menus": { @@ -183,8 +207,89 @@ "group": "navigation", "when": "true" } + ], + "editor/context": [ + { + "submenu": "kilo-code.new.editorContextMenu", + "group": "1_kilocode" + } + ], + "kilo-code.new.editorContextMenu": [ + { + "command": "kilo-code.new.explainCode", + "group": "1_actions@1" + }, + { + "command": "kilo-code.new.fixCode", + "group": "1_actions@2" + }, + { + "command": "kilo-code.new.improveCode", + "group": "1_actions@3" + }, + { + "command": "kilo-code.new.addToContext", + "group": "1_actions@4" + } + ], + "terminal/context": [ + { + "submenu": "kilo-code.new.terminalContextMenu", + "group": "2_kilocode" + } + ], + "kilo-code.new.terminalContextMenu": [ + { + "command": "kilo-code.new.terminalAddToContext", + "group": "1_actions@1" + }, + { + "command": "kilo-code.new.terminalFixCommand", + "group": "1_actions@2" + }, + { + "command": "kilo-code.new.terminalExplainCommand", + "group": "1_actions@3" + } ] }, + "keybindings": [ + { + "command": "kilo-code.new.focusChatInput", + "key": "ctrl+shift+a", + "mac": "cmd+shift+a" + }, + { + "command": "kilo-code.new.addToContext", + "key": "ctrl+k ctrl+a", + "mac": "cmd+k cmd+a", + "when": "editorTextFocus && editorHasSelection" + }, + { + "command": "kilo-code.new.agentManager.previousSession", + "key": "ctrl+up", + "mac": "cmd+up", + "when": "activeWebviewPanelId == 'kilo-code.new.AgentManagerPanel'" + }, + { + "command": "kilo-code.new.agentManager.nextSession", + "key": "ctrl+down", + "mac": "cmd+down", + "when": "activeWebviewPanelId == 'kilo-code.new.AgentManagerPanel'" + }, + { + "command": "kilo-code.new.agentManager.previousTab", + "key": "ctrl+left", + "mac": "cmd+left", + "when": "activeWebviewPanelId == 'kilo-code.new.AgentManagerPanel'" + }, + { + "command": "kilo-code.new.agentManager.nextTab", + "key": "ctrl+right", + "mac": "cmd+right", + "when": "activeWebviewPanelId == 'kilo-code.new.AgentManagerPanel'" + } + ], "configuration": { "title": "Kilo Code", "properties": { diff --git a/packages/kilo-vscode/src/extension.ts b/packages/kilo-vscode/src/extension.ts index b899c15eee..be001db535 100644 --- a/packages/kilo-vscode/src/extension.ts +++ b/packages/kilo-vscode/src/extension.ts @@ -7,6 +7,7 @@ import { registerAutocompleteProvider } from "./services/autocomplete" import { BrowserAutomationService } from "./services/browser-automation" import { TelemetryProxy } from "./services/telemetry" import { registerCommitMessageService } from "./services/commit-message" +import { registerCodeActions, registerTerminalActions, KiloCodeActionProvider } from "./services/code-actions" export function activate(context: vscode.ExtensionContext) { console.log("Kilo Code extension is now active") @@ -89,6 +90,19 @@ export function activate(context: vscode.ExtensionContext) { // Register commit message generation registerCommitMessageService(context, connectionService) + // Register code actions (editor context menus, terminal context menus, keyboard shortcuts) + registerCodeActions(context, provider) + registerTerminalActions(context, provider) + + // Register CodeActionProvider (lightbulb quick fixes) + context.subscriptions.push( + vscode.languages.registerCodeActionsProvider( + { scheme: "file" }, + new KiloCodeActionProvider(), + KiloCodeActionProvider.metadata, + ), + ) + // Dispose services when extension deactivates (kills the server) context.subscriptions.push({ dispose: () => { diff --git a/packages/kilo-vscode/src/services/code-actions/code-action-provider.ts b/packages/kilo-vscode/src/services/code-actions/code-action-provider.ts new file mode 100644 index 0000000000..ddbaf025e8 --- /dev/null +++ b/packages/kilo-vscode/src/services/code-actions/code-action-provider.ts @@ -0,0 +1,42 @@ +import * as vscode from "vscode" + +export class KiloCodeActionProvider implements vscode.CodeActionProvider { + static readonly metadata: vscode.CodeActionProviderMetadata = { + providedCodeActionKinds: [vscode.CodeActionKind.QuickFix, vscode.CodeActionKind.RefactorRewrite], + } + + provideCodeActions( + document: vscode.TextDocument, + range: vscode.Range | vscode.Selection, + context: vscode.CodeActionContext, + ): vscode.CodeAction[] { + if (range.isEmpty) return [] + + const actions: vscode.CodeAction[] = [] + + const add = new vscode.CodeAction("Add to Kilo Code", vscode.CodeActionKind.RefactorRewrite) + add.command = { command: "kilo-code.new.addToContext", title: "Add to Kilo Code" } + actions.push(add) + + const hasDiagnostics = context.diagnostics.length > 0 + + if (hasDiagnostics) { + const fix = new vscode.CodeAction("Fix with Kilo Code", vscode.CodeActionKind.QuickFix) + fix.command = { command: "kilo-code.new.fixCode", title: "Fix with Kilo Code" } + fix.isPreferred = true + actions.push(fix) + } + + if (!hasDiagnostics) { + const explain = new vscode.CodeAction("Explain with Kilo Code", vscode.CodeActionKind.RefactorRewrite) + explain.command = { command: "kilo-code.new.explainCode", title: "Explain with Kilo Code" } + actions.push(explain) + + const improve = new vscode.CodeAction("Improve with Kilo Code", vscode.CodeActionKind.RefactorRewrite) + improve.command = { command: "kilo-code.new.improveCode", title: "Improve with Kilo Code" } + actions.push(improve) + } + + return actions + } +} diff --git a/packages/kilo-vscode/src/services/code-actions/editor-utils.ts b/packages/kilo-vscode/src/services/code-actions/editor-utils.ts new file mode 100644 index 0000000000..12c6a4dfff --- /dev/null +++ b/packages/kilo-vscode/src/services/code-actions/editor-utils.ts @@ -0,0 +1,28 @@ +import * as vscode from "vscode" + +export interface EditorContext { + filePath: string + selectedText: string + startLine: number + endLine: number + diagnostics: vscode.Diagnostic[] +} + +export function getEditorContext(): EditorContext | undefined { + const editor = vscode.window.activeTextEditor + if (!editor) return undefined + const selection = editor.selection + if (selection.isEmpty) return undefined + const doc = editor.document + return { + filePath: vscode.workspace.asRelativePath(doc.uri), + selectedText: doc.getText(selection), + startLine: selection.start.line + 1, + endLine: selection.end.line + 1, + diagnostics: vscode.languages.getDiagnostics(doc.uri).filter( + (d) => d.range.intersection(selection) !== undefined + ), + } +} + + diff --git a/packages/kilo-vscode/src/services/code-actions/index.ts b/packages/kilo-vscode/src/services/code-actions/index.ts new file mode 100644 index 0000000000..442a332e93 --- /dev/null +++ b/packages/kilo-vscode/src/services/code-actions/index.ts @@ -0,0 +1,3 @@ +export { registerCodeActions } from "./register-code-actions" +export { registerTerminalActions } from "./register-terminal-actions" +export { KiloCodeActionProvider } from "./code-action-provider" diff --git a/packages/kilo-vscode/src/services/code-actions/register-code-actions.ts b/packages/kilo-vscode/src/services/code-actions/register-code-actions.ts new file mode 100644 index 0000000000..3cd63973a3 --- /dev/null +++ b/packages/kilo-vscode/src/services/code-actions/register-code-actions.ts @@ -0,0 +1,65 @@ +import * as vscode from "vscode" +import type { KiloProvider } from "../../KiloProvider" +import { getEditorContext } from "./editor-utils" +import { createPrompt } from "./support-prompt" + +export function registerCodeActions(context: vscode.ExtensionContext, provider: KiloProvider): void { + context.subscriptions.push( + vscode.commands.registerCommand("kilo-code.new.explainCode", () => { + const ctx = getEditorContext() + if (!ctx) return + const prompt = createPrompt("EXPLAIN", { + filePath: ctx.filePath, + startLine: String(ctx.startLine), + endLine: String(ctx.endLine), + selectedText: ctx.selectedText, + userInput: "", + }) + provider.postMessage({ type: "triggerTask", text: prompt }) + }), + + vscode.commands.registerCommand("kilo-code.new.fixCode", () => { + const ctx = getEditorContext() + if (!ctx) return + const prompt = createPrompt("FIX", { + filePath: ctx.filePath, + startLine: String(ctx.startLine), + endLine: String(ctx.endLine), + selectedText: ctx.selectedText, + diagnostics: ctx.diagnostics, + userInput: "", + }) + provider.postMessage({ type: "triggerTask", text: prompt }) + }), + + vscode.commands.registerCommand("kilo-code.new.improveCode", () => { + const ctx = getEditorContext() + if (!ctx) return + const prompt = createPrompt("IMPROVE", { + filePath: ctx.filePath, + startLine: String(ctx.startLine), + endLine: String(ctx.endLine), + selectedText: ctx.selectedText, + userInput: "", + }) + provider.postMessage({ type: "triggerTask", text: prompt }) + }), + + vscode.commands.registerCommand("kilo-code.new.addToContext", () => { + const ctx = getEditorContext() + if (!ctx) return + const prompt = createPrompt("ADD_TO_CONTEXT", { + filePath: ctx.filePath, + startLine: String(ctx.startLine), + endLine: String(ctx.endLine), + selectedText: ctx.selectedText, + }) + provider.postMessage({ type: "setChatBoxMessage", text: prompt }) + provider.postMessage({ type: "action", action: "focusInput" }) + }), + + vscode.commands.registerCommand("kilo-code.new.focusChatInput", () => { + provider.postMessage({ type: "action", action: "focusInput" }) + }), + ) +} diff --git a/packages/kilo-vscode/src/services/code-actions/register-terminal-actions.ts b/packages/kilo-vscode/src/services/code-actions/register-terminal-actions.ts new file mode 100644 index 0000000000..1633db946b --- /dev/null +++ b/packages/kilo-vscode/src/services/code-actions/register-terminal-actions.ts @@ -0,0 +1,57 @@ +import * as vscode from "vscode" +import type { KiloProvider } from "../../KiloProvider" +import { createPrompt } from "./support-prompt" + +function getTerminalSelection(): string { + const terminal = vscode.window.activeTerminal + if (!terminal) return "" + // VS Code terminal API doesn't expose buffer contents directly. + // Terminal selection is available via clipboard in some cases. + // For now, this is a placeholder — full implementation requires + // VS Code shell integration API (terminal.shellIntegration). + return "" +} + +export function registerTerminalActions(context: vscode.ExtensionContext, provider: KiloProvider): void { + context.subscriptions.push( + vscode.commands.registerCommand("kilo-code.new.terminalAddToContext", () => { + const content = getTerminalSelection() + if (!content) { + vscode.window.showInformationMessage("No terminal content available. Select text in the terminal first.") + return + } + const prompt = createPrompt("TERMINAL_ADD_TO_CONTEXT", { + terminalContent: content, + userInput: "", + }) + provider.postMessage({ type: "setChatBoxMessage", text: prompt }) + provider.postMessage({ type: "action", action: "focusInput" }) + }), + + vscode.commands.registerCommand("kilo-code.new.terminalFixCommand", () => { + const content = getTerminalSelection() + if (!content) { + vscode.window.showInformationMessage("No terminal content available. Select text in the terminal first.") + return + } + const prompt = createPrompt("TERMINAL_FIX", { + terminalContent: content, + userInput: "", + }) + provider.postMessage({ type: "triggerTask", text: prompt }) + }), + + vscode.commands.registerCommand("kilo-code.new.terminalExplainCommand", () => { + const content = getTerminalSelection() + if (!content) { + vscode.window.showInformationMessage("No terminal content available. Select text in the terminal first.") + return + } + const prompt = createPrompt("TERMINAL_EXPLAIN", { + terminalContent: content, + userInput: "", + }) + provider.postMessage({ type: "triggerTask", text: prompt }) + }), + ) +} diff --git a/packages/kilo-vscode/src/services/code-actions/support-prompt.ts b/packages/kilo-vscode/src/services/code-actions/support-prompt.ts new file mode 100644 index 0000000000..3a23b392e1 --- /dev/null +++ b/packages/kilo-vscode/src/services/code-actions/support-prompt.ts @@ -0,0 +1,107 @@ +type Params = Record + +function diagnosticText(diagnostics?: any[]) { + if (!diagnostics?.length) return "" + return `\nCurrent problems detected:\n${diagnostics + .map((d) => `- [${d.source || "Error"}] ${d.message}${d.code ? ` (${d.code})` : ""}`) + .join("\n")}` +} + +function fill(template: string, params: Params): string { + return template.replace(/\${(.*?)}/g, (_, key) => { + if (key === "diagnosticText") return diagnosticText(params["diagnostics"] as any[]) + if (key in params) return String(params[key] ?? "") + return "" + }) +} + +type PromptType = + | "EXPLAIN" + | "FIX" + | "IMPROVE" + | "ADD_TO_CONTEXT" + | "TERMINAL_ADD_TO_CONTEXT" + | "TERMINAL_FIX" + | "TERMINAL_EXPLAIN" + +const templates: Record = { + EXPLAIN: `Explain the following code from file path \${filePath}:\${startLine}-\${endLine} +\${userInput} + +\`\`\` +\${selectedText} +\`\`\` + +Please provide a clear and concise explanation of what this code does, including: +1. The purpose and functionality +2. Key components and their interactions +3. Important patterns or techniques used`, + + FIX: `Fix any issues in the following code from file path \${filePath}:\${startLine}-\${endLine} +\${diagnosticText} +\${userInput} + +\`\`\` +\${selectedText} +\`\`\` + +Please: +1. Address all detected problems listed above (if any) +2. Identify any other potential bugs or issues +3. Provide corrected code +4. Explain what was fixed and why`, + + IMPROVE: `Improve the following code from file path \${filePath}:\${startLine}-\${endLine} +\${userInput} + +\`\`\` +\${selectedText} +\`\`\` + +Please suggest improvements for: +1. Code readability and maintainability +2. Performance optimization +3. Best practices and patterns +4. Error handling and edge cases + +Provide the improved code along with explanations for each enhancement.`, + + ADD_TO_CONTEXT: `\${filePath}:\${startLine}-\${endLine} +\`\`\` +\${selectedText} +\`\`\``, + + TERMINAL_ADD_TO_CONTEXT: `\${userInput} +Terminal output: +\`\`\` +\${terminalContent} +\`\`\``, + + TERMINAL_FIX: `\${userInput} +Fix this terminal command: +\`\`\` +\${terminalContent} +\`\`\` + +Please: +1. Identify any issues in the command +2. Provide the corrected command +3. Explain what was fixed and why`, + + TERMINAL_EXPLAIN: `\${userInput} +Explain this terminal command: +\`\`\` +\${terminalContent} +\`\`\` + +Please provide: +1. What the command does +2. Explanation of each part/flag +3. Expected output and behavior`, +} + +export function createPrompt(type: PromptType, params: Params): string { + return fill(templates[type], params) +} + +export type { PromptType } diff --git a/packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx b/packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx index 3a38648842..b1ca8c75a8 100644 --- a/packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx +++ b/packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx @@ -70,10 +70,30 @@ export const PromptInput: Component = () => { const canSend = () => (text().trim().length > 0 || imageAttach.images().length > 0) && !isBusy() && !isDisabled() const unsubscribe = vscode.onMessage((message) => { - if (message.type !== "chatCompletionResult") return - const result = message as { type: "chatCompletionResult"; text: string; requestId: string } - if (result.requestId === `chat-ac-${requestCounter}` && result.text) { - setGhostText(result.text) + if (message.type === "chatCompletionResult") { + const result = message as { type: "chatCompletionResult"; text: string; requestId: string } + if (result.requestId === `chat-ac-${requestCounter}` && result.text) { + setGhostText(result.text) + } + } + + if (message.type === "setChatBoxMessage") { + setText(message.text) + setGhostText("") + if (textareaRef) { + textareaRef.value = message.text + adjustHeight() + } + } + + if (message.type === "triggerTask") { + if (isBusy() || isDisabled()) return + const sel = session.selected() + session.sendMessage(message.text, sel?.providerID, sel?.modelID) + } + + if (message.type === "action" && message.action === "focusInput") { + textareaRef?.focus() } }) diff --git a/packages/kilo-vscode/webview-ui/src/types/messages.ts b/packages/kilo-vscode/webview-ui/src/types/messages.ts index 9d9cef885e..70169e5f98 100644 --- a/packages/kilo-vscode/webview-ui/src/types/messages.ts +++ b/packages/kilo-vscode/webview-ui/src/types/messages.ts @@ -387,6 +387,16 @@ export interface ActionMessage { action: string } +export interface SetChatBoxMessage { + type: "setChatBoxMessage" + text: string +} + +export interface TriggerTaskMessage { + type: "triggerTask" + text: string +} + export interface ProfileDataMessage { type: "profileData" data: ProfileData | null @@ -585,6 +595,8 @@ export type ExtensionMessage = | AgentManagerRepoInfoMessage | AgentManagerWorktreeSetupMessage | AgentManagerStateMessage + | SetChatBoxMessage + | TriggerTaskMessage // ============================================ // Messages FROM webview TO extension