Skip to content

Commit 4913ab1

Browse files
committed
add support for initial message and grok-code-fast-1
1 parent f9fa972 commit 4913ab1

File tree

7 files changed

+179
-90
lines changed

7 files changed

+179
-90
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,17 @@ This file stores **global settings** that apply across all projects. These setti
114114

115115
- **API Key**: Your Grok API key
116116
- **Base URL**: Custom API endpoint (if needed)
117-
- **Default Model**: Your preferred model (e.g., `grok-4-latest`)
117+
- **Default Model**: Your preferred model (e.g., `grok-code-fast-1`)
118118
- **Available Models**: List of models you can use
119119

120120
**Example:**
121121
```json
122122
{
123123
"apiKey": "your_api_key_here",
124124
"baseURL": "https://api.x.ai/v1",
125-
"defaultModel": "grok-4-latest",
125+
"defaultModel": "grok-code-fast-1",
126126
"models": [
127+
"grok-code-fast-1",
127128
"grok-4-latest",
128129
"grok-3-latest",
129130
"grok-3-fast",
@@ -159,7 +160,7 @@ This file stores **project-specific settings** in your current working directory
159160
1. **Global Defaults**: User-level settings provide your default preferences
160161
2. **Project Override**: Project-level settings override defaults for specific projects
161162
3. **Directory-Specific**: When you change directories, project settings are loaded automatically
162-
4. **Fallback Logic**: Project model → User default model → System default (`grok-4-latest`)
163+
4. **Fallback Logic**: Project model → User default model → System default (`grok-code-fast-1`)
163164

164165
This means you can have different models for different projects while maintaining consistent global settings like your API key.
165166

@@ -245,6 +246,7 @@ You can specify which AI model to use with the `--model` parameter or `GROK_MODE
245246
**Method 1: Command Line Flag**
246247
```bash
247248
# Use Grok models
249+
grok --model grok-code-fast-1
248250
grok --model grok-4-latest
249251
grok --model grok-3-latest
250252
grok --model grok-3-fast
@@ -256,7 +258,7 @@ grok --model claude-sonnet-4-20250514 --base-url https://api-endpoint.com/v1
256258

257259
**Method 2: Environment Variable**
258260
```bash
259-
export GROK_MODEL=grok-4-latest
261+
export GROK_MODEL=grok-code-fast-1
260262
grok
261263
```
262264

@@ -265,11 +267,11 @@ Add to `~/.grok/user-settings.json`:
265267
```json
266268
{
267269
"apiKey": "your_api_key_here",
268-
"defaultModel": "grok-4-latest"
270+
"defaultModel": "grok-code-fast-1"
269271
}
270272
```
271273

272-
**Model Priority**: `--model` flag > `GROK_MODEL` environment variable > user default model > system default (grok-4-latest)
274+
**Model Priority**: `--model` flag > `GROK_MODEL` environment variable > user default model > system default (grok-code-fast-1)
273275

274276
### Command Line Options
275277

@@ -281,7 +283,7 @@ Options:
281283
-d, --directory <dir> set working directory
282284
-k, --api-key <key> Grok API key (or set GROK_API_KEY env var)
283285
-u, --base-url <url> Grok API base URL (or set GROK_BASE_URL env var)
284-
-m, --model <model> AI model to use (e.g., grok-4-latest, grok-3-latest) (or set GROK_MODEL env var)
286+
-m, --model <model> AI model to use (e.g., grok-code-fast-1, grok-4-latest) (or set GROK_MODEL env var)
285287
-p, --prompt <prompt> process a single prompt and exit (headless mode)
286288
--max-tool-rounds <rounds> maximum number of tool execution rounds (default: 400)
287289
-h, --help display help for command

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vibe-kit/grok-cli",
3-
"version": "0.0.23",
3+
"version": "0.0.24",
44
"description": "An open-source AI agent that brings the power of Grok directly into your terminal.",
55
"main": "dist/index.js",
66
"bin": {

src/agent/grok-agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class GrokAgent extends EventEmitter {
6464
super();
6565
const manager = getSettingsManager();
6666
const savedModel = manager.getCurrentModel();
67-
const modelToUse = model || savedModel || "grok-4-latest";
67+
const modelToUse = model || savedModel || "grok-code-fast-1";
6868
this.maxToolRounds = maxToolRounds || 400;
6969
this.grokClient = new GrokClient(apiKey, modelToUse, baseURL);
7070
this.textEditor = new TextEditorTool();
@@ -160,7 +160,7 @@ Current working directory: ${process.cwd()}`,
160160
await initializeMCPServers();
161161
}
162162
} catch (error) {
163-
console.warn('MCP initialization failed:', error);
163+
console.warn("MCP initialization failed:", error);
164164
} finally {
165165
this.mcpInitialized = true;
166166
}

src/grok/client.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface GrokResponse {
4747

4848
export class GrokClient {
4949
private client: OpenAI;
50-
private currentModel: string = "grok-3-latest";
50+
private currentModel: string = "grok-code-fast-1";
5151

5252
constructor(apiKey: string, model?: string, baseURL?: string) {
5353
this.client = new OpenAI({
@@ -89,9 +89,8 @@ export class GrokClient {
8989
requestPayload.search_parameters = searchOptions.search_parameters;
9090
}
9191

92-
const response = await this.client.chat.completions.create(
93-
requestPayload
94-
);
92+
const response =
93+
await this.client.chat.completions.create(requestPayload);
9594

9695
return response as GrokResponse;
9796
} catch (error: any) {

src/index.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,27 @@ function loadBaseURL(): string {
6565
}
6666

6767
// Save command line settings to user settings file
68-
async function saveCommandLineSettings(apiKey?: string, baseURL?: string): Promise<void> {
68+
async function saveCommandLineSettings(
69+
apiKey?: string,
70+
baseURL?: string
71+
): Promise<void> {
6972
try {
7073
const manager = getSettingsManager();
7174

7275
// Update with command line values
7376
if (apiKey) {
74-
manager.updateUserSetting('apiKey', apiKey);
77+
manager.updateUserSetting("apiKey", apiKey);
7578
console.log("✅ API key saved to ~/.grok/user-settings.json");
7679
}
7780
if (baseURL) {
78-
manager.updateUserSetting('baseURL', baseURL);
81+
manager.updateUserSetting("baseURL", baseURL);
7982
console.log("✅ Base URL saved to ~/.grok/user-settings.json");
8083
}
8184
} catch (error) {
82-
console.warn("⚠️ Could not save settings to file:", error instanceof Error ? error.message : "Unknown error");
85+
console.warn(
86+
"⚠️ Could not save settings to file:",
87+
error instanceof Error ? error.message : "Unknown error"
88+
);
8389
}
8490
}
8591

@@ -307,6 +313,7 @@ program
307313
"A conversational AI CLI tool powered by Grok with text editor capabilities"
308314
)
309315
.version("1.0.1")
316+
.argument("[message]", "Initial message to send to Grok")
310317
.option("-d, --directory <dir>", "set working directory", process.cwd())
311318
.option("-k, --api-key <key>", "Grok API key (or set GROK_API_KEY env var)")
312319
.option(
@@ -315,7 +322,7 @@ program
315322
)
316323
.option(
317324
"-m, --model <model>",
318-
"AI model to use (e.g., gemini-2.5-pro, grok-4-latest) (or set GROK_MODEL env var)"
325+
"AI model to use (e.g., grok-code-fast-1, grok-4-latest) (or set GROK_MODEL env var)"
319326
)
320327
.option(
321328
"-p, --prompt <prompt>",
@@ -326,7 +333,7 @@ program
326333
"maximum number of tool execution rounds (default: 400)",
327334
"400"
328335
)
329-
.action(async (options) => {
336+
.action(async (message, options) => {
330337
if (options.directory) {
331338
try {
332339
process.chdir(options.directory);
@@ -360,7 +367,13 @@ program
360367

361368
// Headless mode: process prompt and exit
362369
if (options.prompt) {
363-
await processPromptHeadless(options.prompt, apiKey, baseURL, model, maxToolRounds);
370+
await processPromptHeadless(
371+
options.prompt,
372+
apiKey,
373+
baseURL,
374+
model,
375+
maxToolRounds
376+
);
364377
return;
365378
}
366379

@@ -370,7 +383,9 @@ program
370383

371384
ensureUserSettingsDirectory();
372385

373-
render(React.createElement(ChatInterface, { agent }));
386+
render(
387+
React.createElement(ChatInterface, { agent, initialMessage: message })
388+
);
374389
} catch (error: any) {
375390
console.error("❌ Error initializing Grok CLI:", error.message);
376391
process.exit(1);
@@ -393,7 +408,7 @@ gitCommand
393408
)
394409
.option(
395410
"-m, --model <model>",
396-
"AI model to use (e.g., gemini-2.5-pro, grok-4-latest) (or set GROK_MODEL env var)"
411+
"AI model to use (e.g., grok-code-fast-1, grok-4-latest) (or set GROK_MODEL env var)"
397412
)
398413
.option(
399414
"--max-tool-rounds <rounds>",

src/ui/components/chat-interface.tsx

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@ import cfonts from "cfonts";
1818

1919
interface ChatInterfaceProps {
2020
agent?: GrokAgent;
21+
initialMessage?: string;
2122
}
2223

2324
// Main chat component that handles input when agent is available
24-
function ChatInterfaceWithAgent({ agent }: { agent: GrokAgent }) {
25+
function ChatInterfaceWithAgent({
26+
agent,
27+
initialMessage,
28+
}: {
29+
agent: GrokAgent;
30+
initialMessage?: string;
31+
}) {
2532
const [chatHistory, setChatHistory] = useState<ChatEntry[]>([]);
2633
const [isProcessing, setIsProcessing] = useState(false);
2734
const [processingTime, setProcessingTime] = useState(0);
@@ -101,6 +108,29 @@ function ChatInterfaceWithAgent({ agent }: { agent: GrokAgent }) {
101108
setChatHistory([]);
102109
}, []);
103110

111+
// Process initial message if provided
112+
useEffect(() => {
113+
if (initialMessage && agent) {
114+
// First, immediately add the user message to chat history
115+
const userEntry: ChatEntry = {
116+
type: "user",
117+
content: initialMessage,
118+
timestamp: new Date(),
119+
};
120+
setChatHistory([userEntry]);
121+
122+
// Then process the message asynchronously
123+
const processInitialMessage = async () => {
124+
setIsProcessing(true);
125+
const entries = await agent.processUserMessage(initialMessage);
126+
setChatHistory(entries);
127+
setIsProcessing(false);
128+
};
129+
130+
processInitialMessage();
131+
}
132+
}, [initialMessage, agent]);
133+
104134
useEffect(() => {
105135
const handleConfirmationRequest = (options: ConfirmationOptions) => {
106136
setConfirmationOptions(options);
@@ -178,7 +208,8 @@ function ChatInterfaceWithAgent({ agent }: { agent: GrokAgent }) {
178208

179209
<Box flexDirection="column" marginBottom={1}>
180210
<Text color="gray">
181-
Type your request in natural language. Ctrl+C to clear, 'exit' to quit.
211+
Type your request in natural language. Ctrl+C to clear, 'exit' to
212+
quit.
182213
</Text>
183214
</Box>
184215

@@ -222,7 +253,10 @@ function ChatInterfaceWithAgent({ agent }: { agent: GrokAgent }) {
222253
{autoEditEnabled ? "▶" : "⏸"} auto-edit:{" "}
223254
{autoEditEnabled ? "on" : "off"}
224255
</Text>
225-
<Text color="gray" dimColor> (shift + tab)</Text>
256+
<Text color="gray" dimColor>
257+
{" "}
258+
(shift + tab)
259+
</Text>
226260
</Box>
227261
<Box marginRight={2}>
228262
<Text color="yellow">{agent.getCurrentModel()}</Text>
@@ -250,7 +284,10 @@ function ChatInterfaceWithAgent({ agent }: { agent: GrokAgent }) {
250284
}
251285

252286
// Main component that handles API key input or chat interface
253-
export default function ChatInterface({ agent }: ChatInterfaceProps) {
287+
export default function ChatInterface({
288+
agent,
289+
initialMessage,
290+
}: ChatInterfaceProps) {
254291
const [currentAgent, setCurrentAgent] = useState<GrokAgent | null>(
255292
agent || null
256293
);
@@ -263,5 +300,10 @@ export default function ChatInterface({ agent }: ChatInterfaceProps) {
263300
return <ApiKeyInput onApiKeySet={handleApiKeySet} />;
264301
}
265302

266-
return <ChatInterfaceWithAgent agent={currentAgent} />;
303+
return (
304+
<ChatInterfaceWithAgent
305+
agent={currentAgent}
306+
initialMessage={initialMessage}
307+
/>
308+
);
267309
}

0 commit comments

Comments
 (0)