Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/cli.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ if (args.includes("--help") || args.includes("-h")) {
"deepcode - Deep Code CLI",
"",
"Usage:",
" deepcode Launch the interactive TUI in the current directory",
" deepcode --version Print the version",
" deepcode --help Show this help",
" deepcode Launch the interactive TUI in the current directory",
" deepcode -p <prompt> Launch with a pre-filled prompt",
" deepcode --prompt <prompt> Same as -p",
" deepcode --version Print the version",
" deepcode --help Show this help",
"",
"Configuration:",
" ~/.deepcode/settings.json User-level API key, model, base URL",
Expand Down Expand Up @@ -50,6 +52,15 @@ if (args.includes("--help") || args.includes("-h")) {
process.exit(0);
}

function extractInitialPrompt(args: string[]): string | undefined {
const promptIndex = args.findIndex((arg) => arg === "-p" || arg === "--prompt");
if (promptIndex !== -1 && promptIndex + 1 < args.length) {
return args[promptIndex + 1];
}
return undefined;
}

const initialPrompt = extractInitialPrompt(args);
const projectRoot = process.cwd();
configureWindowsShell();

Expand All @@ -68,7 +79,12 @@ async function main(): Promise<void> {
function startApp(): void {
let restarting = false;
const inkInstance = render(
<App projectRoot={projectRoot} version={packageInfo.version} onRestart={() => restartRef.current?.()} />,
<App
projectRoot={projectRoot}
version={packageInfo.version}
initialPrompt={initialPrompt}
onRestart={() => restartRef.current?.()}
/>,
{ exitOnCtrlC: false }
);

Expand Down
4 changes: 3 additions & 1 deletion src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ type View = "chat" | "session-list" | "mcp-status";
type AppProps = {
projectRoot: string;
version?: string;
initialPrompt?: string;
onRestart?: () => void;
};

export function App({ projectRoot, version = "", onRestart }: AppProps): React.ReactElement {
export function App({ projectRoot, version = "", initialPrompt, onRestart }: AppProps): React.ReactElement {
const { exit } = useApp();
const { stdout, write } = useStdout();
const { columns } = useWindowSize();
Expand Down Expand Up @@ -470,6 +471,7 @@ export function App({ projectRoot, version = "", onRestart }: AppProps): React.R
promptHistory={promptHistory}
busy={busy}
loadingText={loadingText}
initialPrompt={initialPrompt}
onSubmit={handleSubmit}
onModelConfigChange={handleModelConfigChange}
onInterrupt={handleInterrupt}
Expand Down
19 changes: 18 additions & 1 deletion src/ui/PromptInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
loadingText?: string | null;
disabled?: boolean;
placeholder?: string;
initialPrompt?: string;
onSubmit: (submission: PromptSubmission) => void;
onModelConfigChange: (selection: ModelConfigSelection) => string | Promise<string>;
onInterrupt: () => void;
Expand Down Expand Up @@ -109,13 +110,16 @@
loadingText,
disabled,
placeholder,
initialPrompt,
onSubmit,
onModelConfigChange,
onInterrupt,
}: Props): React.ReactElement {
const { exit } = useApp();
const { stdout } = useStdout();
const [buffer, setBuffer] = useState<PromptBufferState>(EMPTY_BUFFER);
const [buffer, setBuffer] = useState<PromptBufferState>(() =>
initialPrompt ? { text: initialPrompt, cursor: initialPrompt.length } : EMPTY_BUFFER
);
const [imageUrls, setImageUrls] = useState<string[]>([]);
const [selectedSkills, setSelectedSkills] = useState<SkillInfo[]>([]);
const [statusMessage, setStatusMessage] = useState<string | null>(null);
Expand Down Expand Up @@ -192,6 +196,19 @@
setDraftBeforeHistory(null);
}, [promptHistoryKey]);

// Auto-submit initial prompt provided via -p/--prompt CLI flag
useEffect(() => {
if (!initialPrompt || !initialPrompt.trim()) return;

onSubmit({
text: initialPrompt,
imageUrls: [],
selectedSkills: undefined,
});
setBuffer(EMPTY_BUFFER);
clearPromptUndoRedoState(undoRedoRef.current);
}, []); // Only on mount

Check warning on line 210 in src/ui/PromptInput.tsx

View workflow job for this annotation

GitHub Actions / Node 22 / windows-latest

React Hook useEffect has missing dependencies: 'initialPrompt' and 'onSubmit'. Either include them or remove the dependency array. If 'onSubmit' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 210 in src/ui/PromptInput.tsx

View workflow job for this annotation

GitHub Actions / Node 20 / macos-latest

React Hook useEffect has missing dependencies: 'initialPrompt' and 'onSubmit'. Either include them or remove the dependency array. If 'onSubmit' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 210 in src/ui/PromptInput.tsx

View workflow job for this annotation

GitHub Actions / Node 20 / windows-latest

React Hook useEffect has missing dependencies: 'initialPrompt' and 'onSubmit'. Either include them or remove the dependency array. If 'onSubmit' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 210 in src/ui/PromptInput.tsx

View workflow job for this annotation

GitHub Actions / Node 24 / ubuntu-latest

React Hook useEffect has missing dependencies: 'initialPrompt' and 'onSubmit'. Either include them or remove the dependency array. If 'onSubmit' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 210 in src/ui/PromptInput.tsx

View workflow job for this annotation

GitHub Actions / Node 20 / ubuntu-latest

React Hook useEffect has missing dependencies: 'initialPrompt' and 'onSubmit'. Either include them or remove the dependency array. If 'onSubmit' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 210 in src/ui/PromptInput.tsx

View workflow job for this annotation

GitHub Actions / Node 24 / windows-latest

React Hook useEffect has missing dependencies: 'initialPrompt' and 'onSubmit'. Either include them or remove the dependency array. If 'onSubmit' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 210 in src/ui/PromptInput.tsx

View workflow job for this annotation

GitHub Actions / Node 24 / macos-latest

React Hook useEffect has missing dependencies: 'initialPrompt' and 'onSubmit'. Either include them or remove the dependency array. If 'onSubmit' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 210 in src/ui/PromptInput.tsx

View workflow job for this annotation

GitHub Actions / Node 22 / ubuntu-latest

React Hook useEffect has missing dependencies: 'initialPrompt' and 'onSubmit'. Either include them or remove the dependency array. If 'onSubmit' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 210 in src/ui/PromptInput.tsx

View workflow job for this annotation

GitHub Actions / Node 22 / macos-latest

React Hook useEffect has missing dependencies: 'initialPrompt' and 'onSubmit'. Either include them or remove the dependency array. If 'onSubmit' changes too often, find the parent component that defines it and wrap that definition in useCallback

useTerminalInput(
(input, key) => {
if (key.focusIn) {
Expand Down
Loading