-
Notifications
You must be signed in to change notification settings - Fork 11
🤖 feat: AI-generated workspace creation on first message #500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kylecarbs
wants to merge
10
commits into
main
Choose a base branch
from
titles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+505
−7
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
42c2497
feat: AI-generated workspace creation on first message
kylecarbs 103de6f
chore: format ipcMain.ts
kylecarbs 2b2d607
fix: Store branch name in 'name' field, display title in 'displayName'
kylecarbs 1e0bc94
fmt: Run prettier
kylecarbs 7089184
fmt: Prettier formatting for WorkspaceListItem
kylecarbs cce7058
fix: Don't use context hooks in FirstMessageInput
kylecarbs 0db2f8f
fix: Remove unused import
kylecarbs ee71cd6
refactor: Remove ProjectSelector, use single-project detection
kylecarbs f95c956
fix: Actually replace ProjectSelector usage in App.tsx
kylecarbs 8ba4189
fix: Tailwind class order
kylecarbs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import React, { useState, useRef, useCallback } from "react"; | ||
| import { cn } from "@/lib/utils"; | ||
| import type { FrontendWorkspaceMetadata } from "@/types/workspace"; | ||
| import type { RuntimeConfig } from "@/types/runtime"; | ||
| import { useSendMessageOptions } from "@/hooks/useSendMessageOptions"; | ||
| import { parseRuntimeString } from "@/utils/chatCommands"; | ||
| import { getRuntimeKey } from "@/constants/storage"; | ||
|
|
||
| interface FirstMessageInputProps { | ||
| projectPath: string; | ||
| onWorkspaceCreated: (metadata: FrontendWorkspaceMetadata) => void; | ||
| } | ||
|
|
||
| /** | ||
| * FirstMessageInput - Simplified input for sending first message without a workspace | ||
| * | ||
| * When user sends a message, it: | ||
| * 1. Creates a workspace with AI-generated title/branch | ||
| * 2. Sends the message to the new workspace | ||
| * 3. Switches to the new workspace (via callback) | ||
| */ | ||
| export function FirstMessageInput({ projectPath, onWorkspaceCreated }: FirstMessageInputProps) { | ||
| const [input, setInput] = useState(""); | ||
| const [isSending, setIsSending] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const inputRef = useRef<HTMLTextAreaElement>(null); | ||
|
|
||
| // Get send message options (uses placeholder since no workspace exists yet) | ||
| const sendMessageOptions = useSendMessageOptions("__no_workspace__"); | ||
|
|
||
| const handleSend = useCallback(async () => { | ||
| if (!input.trim() || isSending) return; | ||
|
|
||
| setIsSending(true); | ||
| setError(null); | ||
|
|
||
| try { | ||
| // Read runtime preference from localStorage | ||
| const runtimeKey = getRuntimeKey(projectPath); | ||
| const runtimeString = localStorage.getItem(runtimeKey); | ||
| const runtimeConfig: RuntimeConfig | undefined = runtimeString | ||
| ? parseRuntimeString(runtimeString, "") | ||
| : undefined; | ||
|
|
||
| const result = await window.api.workspace.sendFirstMessage(projectPath, input, { | ||
| ...sendMessageOptions, | ||
| runtimeConfig, | ||
| }); | ||
|
|
||
| if (!result.success) { | ||
| setError(result.error); | ||
| setIsSending(false); | ||
| return; | ||
| } | ||
|
|
||
| // Clear input | ||
| setInput(""); | ||
|
|
||
| // Notify parent to switch workspace | ||
| onWorkspaceCreated(result.metadata); | ||
| } catch (err) { | ||
| const errorMessage = err instanceof Error ? err.message : String(err); | ||
| setError(`Failed to create workspace: ${errorMessage}`); | ||
| setIsSending(false); | ||
| } | ||
| }, [input, isSending, projectPath, sendMessageOptions, onWorkspaceCreated]); | ||
|
|
||
| const handleKeyDown = useCallback( | ||
| (e: React.KeyboardEvent<HTMLTextAreaElement>) => { | ||
| // Send on Cmd+Enter (Mac) or Ctrl+Enter (Windows/Linux) | ||
| if ((e.metaKey || e.ctrlKey) && e.key === "Enter") { | ||
| e.preventDefault(); | ||
| void handleSend(); | ||
| } | ||
| }, | ||
| [handleSend] | ||
| ); | ||
|
|
||
| return ( | ||
| <div className="flex h-full flex-col"> | ||
| {/* Spacer to push input to bottom */} | ||
| <div className="flex-1" /> | ||
|
|
||
| {/* Input area */} | ||
| <div className="border-t border-gray-700 p-4"> | ||
| {error && ( | ||
| <div className="mb-3 rounded border border-red-700 bg-red-900/20 px-3 py-2 text-sm text-red-400"> | ||
| {error} | ||
| </div> | ||
| )} | ||
|
|
||
| <div className="flex flex-col gap-2"> | ||
| <textarea | ||
| ref={inputRef} | ||
| className={cn( | ||
| "w-full resize-none rounded border bg-gray-800 px-3 py-2 text-white", | ||
| "border-gray-600 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500", | ||
| "placeholder-gray-500", | ||
| "min-h-[80px] max-h-[300px]" | ||
| )} | ||
| placeholder="Type your first message to create a workspace..." | ||
| value={input} | ||
| onChange={(e) => setInput(e.target.value)} | ||
| onKeyDown={handleKeyDown} | ||
| disabled={isSending} | ||
| autoFocus | ||
| /> | ||
|
|
||
| <div className="flex items-center justify-between"> | ||
| <span className="text-xs text-gray-500"> | ||
| {window.api.platform === "darwin" ? "⌘" : "Ctrl"}+Enter to send | ||
| </span> | ||
|
|
||
| <button | ||
| type="button" | ||
| onClick={() => void handleSend()} | ||
| disabled={!input.trim() || isSending} | ||
| className={cn( | ||
| "rounded px-4 py-2 text-sm font-medium", | ||
| !input.trim() || isSending | ||
| ? "cursor-not-allowed bg-gray-700 text-gray-500" | ||
| : "bg-blue-600 text-white hover:bg-blue-700" | ||
| )} | ||
| > | ||
| {isSending ? "Creating..." : "Send"} | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { useMemo } from "react"; | ||
| import type { ProjectConfig } from "@/types/project"; | ||
|
|
||
| interface ProjectSelectorProps { | ||
| projects: Map<string, ProjectConfig>; | ||
| selectedProject: string | null; | ||
| onSelect: (projectPath: string) => void; | ||
| } | ||
|
|
||
| /** | ||
| * ProjectSelector - Dropdown for selecting a project when no workspace exists | ||
| * | ||
| * Shows project list in a dropdown. If only one project exists, it's auto-selected | ||
| * and the dropdown is not shown. | ||
| */ | ||
| export function ProjectSelector({ projects, selectedProject, onSelect }: ProjectSelectorProps) { | ||
| const projectList = useMemo(() => Array.from(projects.keys()), [projects]); | ||
|
|
||
| // Extract project name from path for display | ||
| const getProjectName = (projectPath: string): string => { | ||
| return projectPath.split("/").pop() ?? projectPath.split("\\").pop() ?? projectPath; | ||
| }; | ||
|
|
||
| if (projectList.length === 0) { | ||
| return ( | ||
| <div className="flex items-center justify-center p-4 text-gray-400"> | ||
| No projects added. Use Command Palette (⌘⇧P) to add a project. | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| // If only one project, don't show selector (it's auto-selected by parent) | ||
| if (projectList.length === 1) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex items-center gap-2 border-b border-gray-700 p-4"> | ||
| <label htmlFor="project-selector" className="text-sm text-gray-400"> | ||
| Project: | ||
| </label> | ||
| <select | ||
| id="project-selector" | ||
| className="flex-1 rounded-md border border-gray-600 bg-gray-800 px-3 py-2 text-gray-200 focus:ring-2 focus:ring-blue-500 focus:outline-none" | ||
| value={selectedProject ?? ""} | ||
| onChange={(e) => onSelect(e.target.value)} | ||
| > | ||
| <option value="" disabled> | ||
| Select a project... | ||
| </option> | ||
| {projectList.map((projectPath) => ( | ||
| <option key={projectPath} value={projectPath}> | ||
| {getProjectName(projectPath)} | ||
| </option> | ||
| ))} | ||
| </select> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make workspaceId optional here? Then we reduce duplication in the IPC.