-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathcli.tsx
More file actions
136 lines (120 loc) · 4.39 KB
/
cli.tsx
File metadata and controls
136 lines (120 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React from "react";
import { render } from "ink";
import { App } from "./ui";
import { setShellIfWindows } from "./common/shell-utils";
import { checkForNpmUpdate, promptForPendingUpdate, type PackageInfo } from "./updateCheck";
const args = process.argv.slice(2);
const packageInfo = readPackageInfo();
if (args.includes("--version") || args.includes("-v")) {
process.stdout.write(`${packageInfo.version || "unknown"}\n`);
process.exit(0);
}
if (args.includes("--help") || args.includes("-h")) {
process.stdout.write(
[
"deepcode - Deep Code CLI",
"",
"Usage:",
" 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",
" ./.deepcode/settings.json Project-level settings",
" ~/.agents/skills/*/SKILL.md User-level skills",
" ./.agents/skills/*/SKILL.md Project-level skills",
" ./.deepcode/skills/*/SKILL.md Legacy project-level skills",
"",
"Inside the TUI:",
" enter Send the prompt",
" shift+enter Insert a newline",
" home/end Move within the current line",
" alt+left/right Move by word",
" ctrl+w Delete the previous word",
" ctrl+v Paste an image from the clipboard",
" ctrl+x Clear pasted images",
" esc Interrupt the current model turn",
" / Open the skills/commands menu",
" /new Start a fresh conversation",
" /init Initialize an AGENTS.md file with instructions for LLM",
" /resume Pick a previous conversation to continue",
" /continue Continue the active conversation, or resume one if empty",
" /exit Quit",
" ctrl+d twice Quit",
].join("\n") + "\n"
);
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;
}
let initialPrompt = extractInitialPrompt(args);
const projectRoot = process.cwd();
configureWindowsShell();
if (!process.stdin.isTTY) {
process.stderr.write("deepcode requires an interactive terminal (TTY). " + "Re-run from a real terminal session.\n");
process.exit(1);
}
void main();
async function main(): Promise<void> {
const updatePromptResult = await promptForPendingUpdate(packageInfo);
const restartRef: { current: (() => void) | null } = { current: null };
function startApp(): void {
let restarting = false;
const appInitialPrompt = initialPrompt;
initialPrompt = undefined;
const inkInstance = render(
<App
projectRoot={projectRoot}
version={packageInfo.version}
initialPrompt={appInitialPrompt}
onRestart={() => restartRef.current?.()}
/>,
{ exitOnCtrlC: false }
);
restartRef.current = () => {
restarting = true;
process.stdout.write("\u001B[2J\u001B[3J\u001B[H");
inkInstance.unmount();
startApp();
};
inkInstance.waitUntilExit().then(() => {
if (!restarting) {
restartRef.current = null;
process.exit(0);
}
});
}
if (!updatePromptResult.installed) {
void checkForNpmUpdate(packageInfo);
}
startApp();
}
function configureWindowsShell(): void {
process.env.NoDefaultCurrentDirectoryInExePath = "1";
try {
setShellIfWindows();
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
process.stderr.write(`deepcode: ${message}\n`);
process.exit(1);
}
}
function readPackageInfo(): PackageInfo {
try {
const pkg = require("../package.json") as { name?: unknown; version?: unknown };
return {
name: typeof pkg.name === "string" ? pkg.name : "@vegamo/deepcode-cli",
version: typeof pkg.version === "string" ? pkg.version : "",
};
} catch {
return { name: "@vegamo/deepcode-cli", version: "" };
}
}