@xagent/x-cli 1.1.43 → 1.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -14
- package/dist/index.js +214 -67
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
## 1.1.
|
|
1
|
+
## 1.1.45 – Logo Assets & NPM Publication Complete
|
|
2
2
|
|
|
3
3
|
✅ **Live on NPM**: [@xagent/x-cli](https://www.npmjs.com/package/@xagent/x-cli) - Fully published and ready for global installation
|
|
4
4
|
|
|
@@ -218,14 +218,14 @@ which xcli # Should show installation path
|
|
|
218
218
|
**Try without installing:**
|
|
219
219
|
|
|
220
220
|
```bash
|
|
221
|
-
|
|
221
|
+
X_API_KEY=your_api_key_here npx -y @xagent/x-cli@latest --help
|
|
222
222
|
```
|
|
223
223
|
|
|
224
224
|
**Or install globally:**
|
|
225
225
|
|
|
226
226
|
```bash
|
|
227
227
|
npm install -g @xagent/x-cli@latest && \
|
|
228
|
-
echo 'export
|
|
228
|
+
echo 'export X_API_KEY=your_api_key_here' >> ~/.zshrc && \
|
|
229
229
|
source ~/.zshrc && \
|
|
230
230
|
xcli --help
|
|
231
231
|
```
|
|
@@ -249,7 +249,7 @@ npm link
|
|
|
249
249
|
**Method 1: Environment Variable**
|
|
250
250
|
|
|
251
251
|
```bash
|
|
252
|
-
export
|
|
252
|
+
export X_API_KEY=your_api_key_here
|
|
253
253
|
```
|
|
254
254
|
|
|
255
255
|
**Method 2: .env File**
|
|
@@ -381,7 +381,7 @@ This means you can have different models for different projects while maintainin
|
|
|
381
381
|
|
|
382
382
|
### Using Other API Providers
|
|
383
383
|
|
|
384
|
-
**Important**:
|
|
384
|
+
**Important**: X-CLI uses **OpenAI-compatible APIs**. You can use any provider that implements the OpenAI chat completions standard.
|
|
385
385
|
|
|
386
386
|
**Popular Providers**:
|
|
387
387
|
|
|
@@ -449,7 +449,7 @@ This mode is particularly useful for:
|
|
|
449
449
|
|
|
450
450
|
### Tool Execution Control
|
|
451
451
|
|
|
452
|
-
By default,
|
|
452
|
+
By default, X-CLI allows up to 400 tool execution rounds to handle complex multi-step tasks. You can control this behavior:
|
|
453
453
|
|
|
454
454
|
```bash
|
|
455
455
|
# Limit tool rounds for faster execution on simple tasks
|
|
@@ -514,7 +514,7 @@ xcli [options]
|
|
|
514
514
|
Options:
|
|
515
515
|
-V, --version output the version number
|
|
516
516
|
-d, --directory <dir> set working directory
|
|
517
|
-
-k, --api-key <key> Grok API key (or set
|
|
517
|
+
-k, --api-key <key> Grok API key (or set X_API_KEY env var)
|
|
518
518
|
-u, --base-url <url> Grok API base URL (or set GROK_BASE_URL env var)
|
|
519
519
|
-m, --model <model> AI model to use (e.g., grok-code-fast-1, grok-4-latest) (or set GROK_MODEL env var)
|
|
520
520
|
-p, --prompt <prompt> process a single prompt and exit (headless mode)
|
|
@@ -546,7 +546,7 @@ Grok will automatically load and follow these instructions when working in your
|
|
|
546
546
|
|
|
547
547
|
## Morph Fast Apply (Optional)
|
|
548
548
|
|
|
549
|
-
|
|
549
|
+
X-CLI supports Morph's Fast Apply model for high-speed code editing at **4,500+ tokens/sec with 98% accuracy**. This is an optional feature that provides lightning-fast file editing capabilities.
|
|
550
550
|
|
|
551
551
|
**Setup**: Configure your Morph API key following the [setup instructions](#setup) above.
|
|
552
552
|
|
|
@@ -577,7 +577,7 @@ The AI will automatically choose between `edit_file` (Morph) for complex changes
|
|
|
577
577
|
|
|
578
578
|
## MCP Tools
|
|
579
579
|
|
|
580
|
-
|
|
580
|
+
X-CLI supports MCP (Model Context Protocol) servers, allowing you to extend the AI assistant with additional tools and capabilities.
|
|
581
581
|
|
|
582
582
|
### Adding MCP Tools
|
|
583
583
|
|
|
@@ -856,14 +856,14 @@ This issue is being tracked and the fallbacks ensure the CLI remains functional.
|
|
|
856
856
|
|
|
857
857
|
```bash
|
|
858
858
|
# Set your API key (replace with your actual key)
|
|
859
|
-
export
|
|
859
|
+
export X_API_KEY=your_actual_api_key_here
|
|
860
860
|
|
|
861
861
|
# Or add to your shell profile permanently
|
|
862
|
-
echo 'export
|
|
862
|
+
echo 'export X_API_KEY=your_actual_api_key_here' >> ~/.zshrc
|
|
863
863
|
source ~/.zshrc
|
|
864
864
|
|
|
865
865
|
# Verify it's set
|
|
866
|
-
echo $
|
|
866
|
+
echo $X_API_KEY
|
|
867
867
|
```
|
|
868
868
|
|
|
869
869
|
**🚨 Network/connectivity issues**
|
|
@@ -885,7 +885,7 @@ curl -I https://api.x.ai/v1/models
|
|
|
885
885
|
|
|
886
886
|
## 🙏 Credits
|
|
887
887
|
|
|
888
|
-
This project is built upon the excellent foundation of the original [
|
|
888
|
+
This project is built upon the excellent foundation of the original [X-CLI](https://github.com/superagent-ai/xcli-cli) created by [Ismail Pelaseyed](https://github.com/homanp) at [Superagent.ai](https://github.com/superagent-ai).
|
|
889
889
|
|
|
890
890
|
**Original Project**: [superagent-ai/xcli-cli](https://github.com/superagent-ai/xcli-cli)
|
|
891
891
|
**Founder**: [Ismail Pelaseyed](https://github.com/homanp)
|
|
@@ -909,7 +909,7 @@ To add yourself as a contributor:
|
|
|
909
909
|
### Core Contributors
|
|
910
910
|
|
|
911
911
|
- **[@hinetapora](https://github.com/hinetapora)** — Fork maintainer, advanced tool systems, UX enhancements, auto-upgrade system
|
|
912
|
-
- **[@homanp](https://github.com/homanp)** — Original
|
|
912
|
+
- **[@homanp](https://github.com/homanp)** — Original X-CLI creator and foundation
|
|
913
913
|
|
|
914
914
|
### Community Contributors
|
|
915
915
|
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as path7 from 'path';
|
|
|
5
5
|
import path7__default from 'path';
|
|
6
6
|
import * as os from 'os';
|
|
7
7
|
import os__default from 'os';
|
|
8
|
-
import
|
|
8
|
+
import React2, { useState, useRef, useEffect, useMemo, useCallback } from 'react';
|
|
9
9
|
import { Box, Text, render, useApp, useInput } from 'ink';
|
|
10
10
|
import { program, Command } from 'commander';
|
|
11
11
|
import * as dotenv from 'dotenv';
|
|
@@ -65,16 +65,20 @@ var init_settings_manager = __esm({
|
|
|
65
65
|
};
|
|
66
66
|
SettingsManager = class _SettingsManager {
|
|
67
67
|
constructor() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"user-settings.json"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
)
|
|
68
|
+
const newUserDir = path7.join(os.homedir(), ".x");
|
|
69
|
+
const oldUserDir = path7.join(os.homedir(), ".grok");
|
|
70
|
+
if (fs.existsSync(newUserDir) || !fs.existsSync(oldUserDir)) {
|
|
71
|
+
this.userSettingsPath = path7.join(newUserDir, "user-settings.json");
|
|
72
|
+
} else {
|
|
73
|
+
this.userSettingsPath = path7.join(oldUserDir, "user-settings.json");
|
|
74
|
+
}
|
|
75
|
+
const newProjectDir = path7.join(process.cwd(), ".x");
|
|
76
|
+
const oldProjectDir = path7.join(process.cwd(), ".grok");
|
|
77
|
+
if (fs.existsSync(newProjectDir) || !fs.existsSync(oldProjectDir)) {
|
|
78
|
+
this.projectSettingsPath = path7.join(newProjectDir, "settings.json");
|
|
79
|
+
} else {
|
|
80
|
+
this.projectSettingsPath = path7.join(oldProjectDir, "settings.json");
|
|
81
|
+
}
|
|
78
82
|
}
|
|
79
83
|
/**
|
|
80
84
|
* Get singleton instance
|
|
@@ -95,7 +99,7 @@ var init_settings_manager = __esm({
|
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
/**
|
|
98
|
-
* Load user settings from ~/.
|
|
102
|
+
* Load user settings from ~/.x/user-settings.json
|
|
99
103
|
*/
|
|
100
104
|
loadUserSettings() {
|
|
101
105
|
try {
|
|
@@ -115,7 +119,7 @@ var init_settings_manager = __esm({
|
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
/**
|
|
118
|
-
* Save user settings to ~/.
|
|
122
|
+
* Save user settings to ~/.x/user-settings.json
|
|
119
123
|
*/
|
|
120
124
|
saveUserSettings(settings) {
|
|
121
125
|
try {
|
|
@@ -160,7 +164,7 @@ var init_settings_manager = __esm({
|
|
|
160
164
|
return settings[key];
|
|
161
165
|
}
|
|
162
166
|
/**
|
|
163
|
-
* Load project settings from .
|
|
167
|
+
* Load project settings from .x/settings.json
|
|
164
168
|
*/
|
|
165
169
|
loadProjectSettings() {
|
|
166
170
|
try {
|
|
@@ -180,7 +184,7 @@ var init_settings_manager = __esm({
|
|
|
180
184
|
}
|
|
181
185
|
}
|
|
182
186
|
/**
|
|
183
|
-
* Save project settings to .
|
|
187
|
+
* Save project settings to .x/settings.json
|
|
184
188
|
*/
|
|
185
189
|
saveProjectSettings(settings) {
|
|
186
190
|
try {
|
|
@@ -256,7 +260,7 @@ var init_settings_manager = __esm({
|
|
|
256
260
|
* Get API key from user settings or environment
|
|
257
261
|
*/
|
|
258
262
|
getApiKey() {
|
|
259
|
-
const envApiKey = process.env.GROK_API_KEY;
|
|
263
|
+
const envApiKey = process.env.X_API_KEY || process.env.GROK_API_KEY;
|
|
260
264
|
if (envApiKey) {
|
|
261
265
|
return envApiKey;
|
|
262
266
|
}
|
|
@@ -7033,10 +7037,10 @@ var DependencyAnalyzerTool = class {
|
|
|
7033
7037
|
const circularDeps = [];
|
|
7034
7038
|
const visited = /* @__PURE__ */ new Set();
|
|
7035
7039
|
const visiting = /* @__PURE__ */ new Set();
|
|
7036
|
-
const dfs = (filePath,
|
|
7040
|
+
const dfs = (filePath, path29) => {
|
|
7037
7041
|
if (visiting.has(filePath)) {
|
|
7038
|
-
const cycleStart =
|
|
7039
|
-
const cycle =
|
|
7042
|
+
const cycleStart = path29.indexOf(filePath);
|
|
7043
|
+
const cycle = path29.slice(cycleStart).concat([filePath]);
|
|
7040
7044
|
circularDeps.push({
|
|
7041
7045
|
cycle: cycle.map((fp) => graph.nodes.get(fp)?.filePath || fp),
|
|
7042
7046
|
severity: cycle.length <= 2 ? "error" : "warning",
|
|
@@ -7052,7 +7056,7 @@ var DependencyAnalyzerTool = class {
|
|
|
7052
7056
|
if (node) {
|
|
7053
7057
|
for (const dependency of node.dependencies) {
|
|
7054
7058
|
if (graph.nodes.has(dependency)) {
|
|
7055
|
-
dfs(dependency, [...
|
|
7059
|
+
dfs(dependency, [...path29, filePath]);
|
|
7056
7060
|
}
|
|
7057
7061
|
}
|
|
7058
7062
|
}
|
|
@@ -8557,7 +8561,7 @@ ${customInstructions}
|
|
|
8557
8561
|
The above custom instructions should be followed alongside the standard instructions below.` : "";
|
|
8558
8562
|
this.messages.push({
|
|
8559
8563
|
role: "system",
|
|
8560
|
-
content: `You are
|
|
8564
|
+
content: `You are X-CLI, an AI assistant that helps with file editing, coding tasks, and system operations.${customInstructionsSection}
|
|
8561
8565
|
|
|
8562
8566
|
You have access to these tools:
|
|
8563
8567
|
|
|
@@ -9024,10 +9028,10 @@ Current working directory: ${process.cwd()}`
|
|
|
9024
9028
|
return await this.textEditor.view(args.path, range);
|
|
9025
9029
|
} catch (error) {
|
|
9026
9030
|
console.warn(`view_file tool failed, falling back to bash: ${error.message}`);
|
|
9027
|
-
const
|
|
9028
|
-
let command = `cat "${
|
|
9031
|
+
const path29 = args.path;
|
|
9032
|
+
let command = `cat "${path29}"`;
|
|
9029
9033
|
if (args.start_line && args.end_line) {
|
|
9030
|
-
command = `sed -n '${args.start_line},${args.end_line}p' "${
|
|
9034
|
+
command = `sed -n '${args.start_line},${args.end_line}p' "${path29}"`;
|
|
9031
9035
|
}
|
|
9032
9036
|
return await this.bash.execute(command);
|
|
9033
9037
|
}
|
|
@@ -9287,7 +9291,7 @@ EOF`;
|
|
|
9287
9291
|
var package_default = {
|
|
9288
9292
|
type: "module",
|
|
9289
9293
|
name: "@xagent/x-cli",
|
|
9290
|
-
version: "1.1.
|
|
9294
|
+
version: "1.1.45",
|
|
9291
9295
|
description: "An open-source AI agent that brings the power of Grok directly into your terminal.",
|
|
9292
9296
|
main: "dist/index.js",
|
|
9293
9297
|
module: "dist/index.js",
|
|
@@ -11744,7 +11748,7 @@ ${documentationSection}`;
|
|
|
11744
11748
|
- Reference existing documentation rather than recreating context
|
|
11745
11749
|
|
|
11746
11750
|
---
|
|
11747
|
-
*This section was added by the
|
|
11751
|
+
*This section was added by the X-CLI documentation system*`;
|
|
11748
11752
|
}
|
|
11749
11753
|
};
|
|
11750
11754
|
var claudeMdParser = new ClaudeMdParserImpl();
|
|
@@ -11875,7 +11879,7 @@ Documentation for documentation system commands:
|
|
|
11875
11879
|
- Build instructions: ../package.json
|
|
11876
11880
|
|
|
11877
11881
|
---
|
|
11878
|
-
*Generated by
|
|
11882
|
+
*Generated by X-CLI Documentation System*
|
|
11879
11883
|
*Last updated: ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}*
|
|
11880
11884
|
`;
|
|
11881
11885
|
}
|
|
@@ -11894,7 +11898,7 @@ Documentation for documentation system commands:
|
|
|
11894
11898
|
return files;
|
|
11895
11899
|
}
|
|
11896
11900
|
generateGrokArchitecture() {
|
|
11897
|
-
return `# \u{1F3D7}\uFE0F
|
|
11901
|
+
return `# \u{1F3D7}\uFE0F X-CLI Architecture
|
|
11898
11902
|
|
|
11899
11903
|
## Project Type
|
|
11900
11904
|
**CLI Application** - Conversational AI tool with terminal interface
|
|
@@ -11968,7 +11972,7 @@ Documentation for documentation system commands:
|
|
|
11968
11972
|
return `# \u{1F3D7}\uFE0F Project Architecture
|
|
11969
11973
|
|
|
11970
11974
|
## Project Overview
|
|
11971
|
-
External project documented using
|
|
11975
|
+
External project documented using X-CLI's .agent system.
|
|
11972
11976
|
|
|
11973
11977
|
## Technology Stack
|
|
11974
11978
|
*To be analyzed and documented*
|
|
@@ -12021,7 +12025,7 @@ External project documented using Grok CLI's .agent system.
|
|
|
12021
12025
|
- **Extension Pattern**: Add to handleDirectCommand function
|
|
12022
12026
|
|
|
12023
12027
|
## Authentication & Storage
|
|
12024
|
-
- **Auth**: Environment variable
|
|
12028
|
+
- **Auth**: Environment variable X_API_KEY or user settings
|
|
12025
12029
|
- **Storage**: Local file system only
|
|
12026
12030
|
- **Database**: None (settings via JSON files)
|
|
12027
12031
|
- **MCP**: Optional server integration
|
|
@@ -12093,7 +12097,7 @@ Updated By: Agent System Generator during /init-agent
|
|
|
12093
12097
|
{
|
|
12094
12098
|
baseURL: "https://api.x.ai/v1",
|
|
12095
12099
|
defaultModel: "grok-code-fast-1",
|
|
12096
|
-
apiKey: process.env.
|
|
12100
|
+
apiKey: process.env.X_API_KEY
|
|
12097
12101
|
}
|
|
12098
12102
|
\`\`\`
|
|
12099
12103
|
|
|
@@ -12338,10 +12342,10 @@ Create tool in \`src/tools/\`, then reference in command handler.
|
|
|
12338
12342
|
return `# \u{1F4CB} Example PRD: Documentation System Enhancement
|
|
12339
12343
|
|
|
12340
12344
|
## Objective
|
|
12341
|
-
Add comprehensive documentation generation capabilities to
|
|
12345
|
+
Add comprehensive documentation generation capabilities to X-CLI.
|
|
12342
12346
|
|
|
12343
12347
|
## Background
|
|
12344
|
-
|
|
12348
|
+
X-CLI needs better documentation tools to help users document both the CLI itself and their projects efficiently.
|
|
12345
12349
|
|
|
12346
12350
|
## Requirements
|
|
12347
12351
|
|
|
@@ -12490,8 +12494,8 @@ Creates \`.agent/\` folder structure:
|
|
|
12490
12494
|
|
|
12491
12495
|
## Project Types
|
|
12492
12496
|
|
|
12493
|
-
###
|
|
12494
|
-
- Documents
|
|
12497
|
+
### X-CLI (Internal)
|
|
12498
|
+
- Documents X-CLI's own architecture
|
|
12495
12499
|
- Includes command system patterns
|
|
12496
12500
|
- References existing tool structure
|
|
12497
12501
|
|
|
@@ -12883,7 +12887,7 @@ TypeScript is configured via \`tsconfig.json\`.
|
|
|
12883
12887
|
`;
|
|
12884
12888
|
}
|
|
12885
12889
|
content += `---
|
|
12886
|
-
*Generated by
|
|
12890
|
+
*Generated by X-CLI Documentation System*
|
|
12887
12891
|
`;
|
|
12888
12892
|
content += `*Last updated: ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}*`;
|
|
12889
12893
|
return content;
|
|
@@ -13485,7 +13489,7 @@ type ${type.name} = ${type.definition}
|
|
|
13485
13489
|
});
|
|
13486
13490
|
}
|
|
13487
13491
|
content += `---
|
|
13488
|
-
*Generated by
|
|
13492
|
+
*Generated by X-CLI Documentation System*`;
|
|
13489
13493
|
return content;
|
|
13490
13494
|
}
|
|
13491
13495
|
generateHtml(documentation) {
|
|
@@ -14564,7 +14568,7 @@ ${incident.guardrailCreated ? `Guardrail created: ${incident.guardrailCreated}`
|
|
|
14564
14568
|
- [System Critical State](../system/critical-state.md)
|
|
14565
14569
|
|
|
14566
14570
|
---
|
|
14567
|
-
*Generated by
|
|
14571
|
+
*Generated by X-CLI Self-Healing System*
|
|
14568
14572
|
*Incident ID: ${incident.id}*
|
|
14569
14573
|
`;
|
|
14570
14574
|
}
|
|
@@ -14646,7 +14650,7 @@ ${guardrail.createdFrom ? `- Created from incident: ${guardrail.createdFrom}` :
|
|
|
14646
14650
|
- Category: ${guardrail.category}
|
|
14647
14651
|
|
|
14648
14652
|
---
|
|
14649
|
-
*Generated by
|
|
14653
|
+
*Generated by X-CLI Self-Healing System*
|
|
14650
14654
|
`;
|
|
14651
14655
|
}
|
|
14652
14656
|
async checkGuardrails(operation, context) {
|
|
@@ -14824,7 +14828,7 @@ function isNewerVersion(version1, version2) {
|
|
|
14824
14828
|
}
|
|
14825
14829
|
async function autoUpgrade() {
|
|
14826
14830
|
try {
|
|
14827
|
-
console.log("\u{1F504} Upgrading
|
|
14831
|
+
console.log("\u{1F504} Upgrading X-CLI...");
|
|
14828
14832
|
await execAsync3(`npm update -g ${package_default.name}@latest`, {
|
|
14829
14833
|
timeout: 3e4
|
|
14830
14834
|
});
|
|
@@ -14853,6 +14857,7 @@ async function getCachedVersionInfo() {
|
|
|
14853
14857
|
}
|
|
14854
14858
|
|
|
14855
14859
|
// src/hooks/use-input-handler.ts
|
|
14860
|
+
init_settings_manager();
|
|
14856
14861
|
function useInputHandler({
|
|
14857
14862
|
agent,
|
|
14858
14863
|
chatHistory,
|
|
@@ -15118,7 +15123,7 @@ function useInputHandler({
|
|
|
15118
15123
|
if (trimmedInput === "/help") {
|
|
15119
15124
|
const helpEntry = {
|
|
15120
15125
|
type: "assistant",
|
|
15121
|
-
content: `
|
|
15126
|
+
content: `X-CLI Help:
|
|
15122
15127
|
|
|
15123
15128
|
Built-in Commands:
|
|
15124
15129
|
/clear - Clear chat history
|
|
@@ -15219,7 +15224,7 @@ Available models: ${modelNames.join(", ")}`,
|
|
|
15219
15224
|
const versionInfo = await checkForUpdates();
|
|
15220
15225
|
const versionEntry = {
|
|
15221
15226
|
type: "assistant",
|
|
15222
|
-
content: `\u{1F4E6} **
|
|
15227
|
+
content: `\u{1F4E6} **X-CLI Version Information**
|
|
15223
15228
|
|
|
15224
15229
|
Current Version: **${versionInfo.current}**
|
|
15225
15230
|
Latest Version: **${versionInfo.latest}**
|
|
@@ -15279,7 +15284,7 @@ Upgrading now... This may take a moment.`,
|
|
|
15279
15284
|
|
|
15280
15285
|
Successfully upgraded to version **${versionInfo.latest}**.
|
|
15281
15286
|
|
|
15282
|
-
**Please restart
|
|
15287
|
+
**Please restart X-CLI** to use the new version:
|
|
15283
15288
|
- Exit with \`/exit\` or Ctrl+C
|
|
15284
15289
|
- Run \`grok\` again` : `\u274C **Upgrade Failed**
|
|
15285
15290
|
|
|
@@ -15340,7 +15345,7 @@ This may take a moment.`,
|
|
|
15340
15345
|
|
|
15341
15346
|
Successfully installed version **${versionArg}**.
|
|
15342
15347
|
|
|
15343
|
-
**Please restart
|
|
15348
|
+
**Please restart X-CLI** to use the new version:
|
|
15344
15349
|
- Exit with \`/exit\` or Ctrl+C
|
|
15345
15350
|
- Run \`grok\` again`,
|
|
15346
15351
|
timestamp: /* @__PURE__ */ new Date()
|
|
@@ -16090,6 +16095,140 @@ ${incidents.slice(0, 3).map((i) => `- ${i.title} (${i.impact} impact)`).join("\n
|
|
|
16090
16095
|
clearInput();
|
|
16091
16096
|
return true;
|
|
16092
16097
|
}
|
|
16098
|
+
if (trimmedInput === "/switch" || trimmedInput.startsWith("/switch ")) {
|
|
16099
|
+
const userEntry = {
|
|
16100
|
+
type: "user",
|
|
16101
|
+
content: trimmedInput,
|
|
16102
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16103
|
+
};
|
|
16104
|
+
setChatHistory((prev) => [...prev, userEntry]);
|
|
16105
|
+
setIsProcessing(true);
|
|
16106
|
+
try {
|
|
16107
|
+
const args = trimmedInput.split(" ").slice(1);
|
|
16108
|
+
const settingsManager = getSettingsManager();
|
|
16109
|
+
if (args.length === 0) {
|
|
16110
|
+
const settings = settingsManager.loadUserSettings();
|
|
16111
|
+
const autoCompact = settings.autoCompact ?? false;
|
|
16112
|
+
const thresholds = settings.compactThreshold || { lines: 800, bytes: 2e5 };
|
|
16113
|
+
const statusEntry = {
|
|
16114
|
+
type: "assistant",
|
|
16115
|
+
content: `\u{1F504} **Auto-Compact Status**
|
|
16116
|
+
|
|
16117
|
+
**Current Settings:**
|
|
16118
|
+
- Auto-compact: ${autoCompact ? "\u2705 ENABLED" : "\u274C DISABLED"}
|
|
16119
|
+
- Line threshold: ${thresholds.lines || 800} lines
|
|
16120
|
+
- Size threshold: ${Math.round((thresholds.bytes || 2e5) / 1024)}KB
|
|
16121
|
+
|
|
16122
|
+
**Commands:**
|
|
16123
|
+
- \`/switch compact on\` - Enable auto-compact
|
|
16124
|
+
- \`/switch compact off\` - Disable auto-compact
|
|
16125
|
+
- \`/switch compact lines 500\` - Set line threshold
|
|
16126
|
+
- \`/switch compact bytes 100000\` - Set size threshold (in bytes)
|
|
16127
|
+
|
|
16128
|
+
**How it works:**
|
|
16129
|
+
Auto-compact automatically enables compact mode when conversations exceed thresholds, similar to Claude Code's context management.`,
|
|
16130
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16131
|
+
};
|
|
16132
|
+
setChatHistory((prev) => [...prev, statusEntry]);
|
|
16133
|
+
} else if (args[0] === "compact") {
|
|
16134
|
+
if (args[1] === "on") {
|
|
16135
|
+
settingsManager.updateUserSetting("autoCompact", true);
|
|
16136
|
+
const successEntry = {
|
|
16137
|
+
type: "assistant",
|
|
16138
|
+
content: "\u2705 **Auto-compact enabled!**\n\nCompact mode will automatically activate for long conversations to maintain performance.",
|
|
16139
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16140
|
+
};
|
|
16141
|
+
setChatHistory((prev) => [...prev, successEntry]);
|
|
16142
|
+
} else if (args[1] === "off") {
|
|
16143
|
+
settingsManager.updateUserSetting("autoCompact", false);
|
|
16144
|
+
const successEntry = {
|
|
16145
|
+
type: "assistant",
|
|
16146
|
+
content: "\u274C **Auto-compact disabled**\n\nNormal conversation mode will be used.",
|
|
16147
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16148
|
+
};
|
|
16149
|
+
setChatHistory((prev) => [...prev, successEntry]);
|
|
16150
|
+
} else if (args[1] === "lines" && args[2]) {
|
|
16151
|
+
const lines = parseInt(args[2]);
|
|
16152
|
+
if (isNaN(lines) || lines < 100) {
|
|
16153
|
+
const errorEntry = {
|
|
16154
|
+
type: "assistant",
|
|
16155
|
+
content: "\u274C Invalid line threshold. Must be a number >= 100.",
|
|
16156
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16157
|
+
};
|
|
16158
|
+
setChatHistory((prev) => [...prev, errorEntry]);
|
|
16159
|
+
} else {
|
|
16160
|
+
const currentThresholds = settingsManager.getUserSetting("compactThreshold") || {};
|
|
16161
|
+
settingsManager.updateUserSetting("compactThreshold", {
|
|
16162
|
+
...currentThresholds,
|
|
16163
|
+
lines
|
|
16164
|
+
});
|
|
16165
|
+
const successEntry = {
|
|
16166
|
+
type: "assistant",
|
|
16167
|
+
content: `\u2705 **Line threshold updated to ${lines} lines**`,
|
|
16168
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16169
|
+
};
|
|
16170
|
+
setChatHistory((prev) => [...prev, successEntry]);
|
|
16171
|
+
}
|
|
16172
|
+
} else if (args[1] === "bytes" && args[2]) {
|
|
16173
|
+
const bytes = parseInt(args[2]);
|
|
16174
|
+
if (isNaN(bytes) || bytes < 1e4) {
|
|
16175
|
+
const errorEntry = {
|
|
16176
|
+
type: "assistant",
|
|
16177
|
+
content: "\u274C Invalid size threshold. Must be a number >= 10000 bytes.",
|
|
16178
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16179
|
+
};
|
|
16180
|
+
setChatHistory((prev) => [...prev, errorEntry]);
|
|
16181
|
+
} else {
|
|
16182
|
+
const currentThresholds = settingsManager.getUserSetting("compactThreshold") || {};
|
|
16183
|
+
settingsManager.updateUserSetting("compactThreshold", {
|
|
16184
|
+
...currentThresholds,
|
|
16185
|
+
bytes
|
|
16186
|
+
});
|
|
16187
|
+
const successEntry = {
|
|
16188
|
+
type: "assistant",
|
|
16189
|
+
content: `\u2705 **Size threshold updated to ${Math.round(bytes / 1024)}KB**`,
|
|
16190
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16191
|
+
};
|
|
16192
|
+
setChatHistory((prev) => [...prev, successEntry]);
|
|
16193
|
+
}
|
|
16194
|
+
} else {
|
|
16195
|
+
const helpEntry = {
|
|
16196
|
+
type: "assistant",
|
|
16197
|
+
content: `\u2753 **Invalid compact command**
|
|
16198
|
+
|
|
16199
|
+
**Usage:**
|
|
16200
|
+
- \`/switch compact on\` - Enable auto-compact
|
|
16201
|
+
- \`/switch compact off\` - Disable auto-compact
|
|
16202
|
+
- \`/switch compact lines <number>\` - Set line threshold
|
|
16203
|
+
- \`/switch compact bytes <number>\` - Set size threshold`,
|
|
16204
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16205
|
+
};
|
|
16206
|
+
setChatHistory((prev) => [...prev, helpEntry]);
|
|
16207
|
+
}
|
|
16208
|
+
} else {
|
|
16209
|
+
const helpEntry = {
|
|
16210
|
+
type: "assistant",
|
|
16211
|
+
content: `\u2753 **Unknown switch command**
|
|
16212
|
+
|
|
16213
|
+
**Available switches:**
|
|
16214
|
+
- \`/switch compact\` - Manage auto-compact settings
|
|
16215
|
+
- \`/switch\` - Show current status`,
|
|
16216
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16217
|
+
};
|
|
16218
|
+
setChatHistory((prev) => [...prev, helpEntry]);
|
|
16219
|
+
}
|
|
16220
|
+
} catch (error) {
|
|
16221
|
+
const errorEntry = {
|
|
16222
|
+
type: "assistant",
|
|
16223
|
+
content: `Failed to manage switches: ${error.message}`,
|
|
16224
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16225
|
+
};
|
|
16226
|
+
setChatHistory((prev) => [...prev, errorEntry]);
|
|
16227
|
+
}
|
|
16228
|
+
setIsProcessing(false);
|
|
16229
|
+
clearInput();
|
|
16230
|
+
return true;
|
|
16231
|
+
}
|
|
16093
16232
|
const directBashCommands = [
|
|
16094
16233
|
"ls",
|
|
16095
16234
|
"pwd",
|
|
@@ -16381,23 +16520,10 @@ function LoadingSpinner({
|
|
|
16381
16520
|
message,
|
|
16382
16521
|
progress
|
|
16383
16522
|
}) {
|
|
16384
|
-
const [spinnerIndex, setSpinnerIndex] = useState(0);
|
|
16385
|
-
const [messageIndex, setMessageIndex] = useState(0);
|
|
16386
|
-
useEffect(() => {
|
|
16387
|
-
if (!isActive) return;
|
|
16388
|
-
const interval = setInterval(() => {
|
|
16389
|
-
setSpinnerIndex((prev) => (prev + 1) % 10);
|
|
16390
|
-
if (Date.now() % 3e3 < 200) {
|
|
16391
|
-
const config3 = operationConfig[operation];
|
|
16392
|
-
setMessageIndex((prev) => (prev + 1) % config3.messages.length);
|
|
16393
|
-
}
|
|
16394
|
-
}, 120);
|
|
16395
|
-
return () => clearInterval(interval);
|
|
16396
|
-
}, [isActive, operation]);
|
|
16397
16523
|
if (!isActive) return null;
|
|
16398
16524
|
const config2 = operationConfig[operation];
|
|
16399
|
-
const spinnerChar = config2.spinner[
|
|
16400
|
-
const operationMessage = message || config2.messages[
|
|
16525
|
+
const spinnerChar = config2.spinner[0];
|
|
16526
|
+
const operationMessage = message || config2.messages[0];
|
|
16401
16527
|
const color = getSpinnerColor(operation);
|
|
16402
16528
|
const renderProgressBar = () => {
|
|
16403
16529
|
if (progress === void 0) return null;
|
|
@@ -16678,7 +16804,7 @@ var handleLongContent = (content, maxLength = 5e3) => {
|
|
|
16678
16804
|
isTruncated: true
|
|
16679
16805
|
};
|
|
16680
16806
|
};
|
|
16681
|
-
var MemoizedChatEntry =
|
|
16807
|
+
var MemoizedChatEntry = React2.memo(
|
|
16682
16808
|
({ entry, index }) => {
|
|
16683
16809
|
const renderDiff = (diffContent, filename) => {
|
|
16684
16810
|
return /* @__PURE__ */ jsx(
|
|
@@ -17997,7 +18123,7 @@ function ChatInterfaceWithAgent({
|
|
|
17997
18123
|
}
|
|
17998
18124
|
console.log(" ");
|
|
17999
18125
|
console.log(" ");
|
|
18000
|
-
const logoOutput = "
|
|
18126
|
+
const logoOutput = "X-CLI\n" + package_default.version;
|
|
18001
18127
|
const logoLines = logoOutput.split("\n");
|
|
18002
18128
|
logoLines.forEach((line) => {
|
|
18003
18129
|
if (line.trim()) {
|
|
@@ -18045,7 +18171,7 @@ function ChatInterfaceWithAgent({
|
|
|
18045
18171
|
let lastUpdateTime = Date.now();
|
|
18046
18172
|
const flushUpdates = () => {
|
|
18047
18173
|
const now = Date.now();
|
|
18048
|
-
if (now - lastUpdateTime <
|
|
18174
|
+
if (now - lastUpdateTime < 150) return;
|
|
18049
18175
|
setChatHistory((prev) => {
|
|
18050
18176
|
let newHistory = [...prev];
|
|
18051
18177
|
if (lastTokenCount !== 0) {
|
|
@@ -18631,6 +18757,26 @@ function ensureUserSettingsDirectory() {
|
|
|
18631
18757
|
} catch {
|
|
18632
18758
|
}
|
|
18633
18759
|
}
|
|
18760
|
+
function checkAutoCompact() {
|
|
18761
|
+
try {
|
|
18762
|
+
const manager = getSettingsManager();
|
|
18763
|
+
const settings = manager.loadUserSettings();
|
|
18764
|
+
if (!settings.autoCompact) {
|
|
18765
|
+
return;
|
|
18766
|
+
}
|
|
18767
|
+
const sessionLogPath = path7__default.join(__require("os").homedir(), ".grok", "session.log");
|
|
18768
|
+
const thresholds = settings.compactThreshold || { lines: 800, bytes: 2e5 };
|
|
18769
|
+
if (__require("fs").existsSync(sessionLogPath)) {
|
|
18770
|
+
const stats = __require("fs").statSync(sessionLogPath);
|
|
18771
|
+
const lines = parseInt(__require("child_process").execSync(`wc -l < "${sessionLogPath}"`, { encoding: "utf8" }).trim()) || 0;
|
|
18772
|
+
if (lines >= (thresholds.lines || 800) || stats.size >= (thresholds.bytes || 2e5)) {
|
|
18773
|
+
process.env.COMPACT = "1";
|
|
18774
|
+
console.log(`\u{1F504} Auto-compact enabled (${lines} lines, ${Math.round(stats.size / 1024)}KB)`);
|
|
18775
|
+
}
|
|
18776
|
+
}
|
|
18777
|
+
} catch {
|
|
18778
|
+
}
|
|
18779
|
+
}
|
|
18634
18780
|
async function checkStartupUpdates() {
|
|
18635
18781
|
try {
|
|
18636
18782
|
const versionInfo = await checkForUpdates();
|
|
@@ -18815,7 +18961,7 @@ async function processPromptHeadless(prompt, apiKey, baseURL, model, maxToolRoun
|
|
|
18815
18961
|
}
|
|
18816
18962
|
program.name("grok").description(
|
|
18817
18963
|
"A conversational AI CLI tool powered by Grok with text editor capabilities"
|
|
18818
|
-
).version(package_default.version).argument("[message...]", "Initial message to send to Grok").option("-d, --directory <dir>", "set working directory", process.cwd()).option("-k, --api-key <key>", "
|
|
18964
|
+
).version(package_default.version).argument("[message...]", "Initial message to send to Grok").option("-d, --directory <dir>", "set working directory", process.cwd()).option("-k, --api-key <key>", "X API key (or set X_API_KEY env var)").option(
|
|
18819
18965
|
"-u, --base-url <url>",
|
|
18820
18966
|
"Grok API base URL (or set GROK_BASE_URL env var)"
|
|
18821
18967
|
).option(
|
|
@@ -18847,7 +18993,7 @@ program.name("grok").description(
|
|
|
18847
18993
|
const maxToolRounds = parseInt(options.maxToolRounds) || 400;
|
|
18848
18994
|
if (!apiKey) {
|
|
18849
18995
|
console.error(
|
|
18850
|
-
"\u274C Error: API key required. Set
|
|
18996
|
+
"\u274C Error: API key required. Set X_API_KEY environment variable, use --api-key flag, or save to ~/.x/user-settings.json"
|
|
18851
18997
|
);
|
|
18852
18998
|
process.exit(1);
|
|
18853
18999
|
}
|
|
@@ -18871,9 +19017,10 @@ program.name("grok").description(
|
|
|
18871
19017
|
const agent = new GrokAgent(apiKey, baseURL, model, maxToolRounds);
|
|
18872
19018
|
console.log("\u{1F916} Starting X CLI Conversational Assistant...\n");
|
|
18873
19019
|
ensureUserSettingsDirectory();
|
|
19020
|
+
checkAutoCompact();
|
|
18874
19021
|
checkStartupUpdates();
|
|
18875
19022
|
const initialMessage = Array.isArray(message) ? message.join(" ") : message;
|
|
18876
|
-
const app = render(
|
|
19023
|
+
const app = render(React2.createElement(ChatInterface, { agent, initialMessage }));
|
|
18877
19024
|
const cleanup = () => {
|
|
18878
19025
|
app.unmount();
|
|
18879
19026
|
agent.abortCurrentOperation();
|
|
@@ -18894,7 +19041,7 @@ program.name("grok").description(
|
|
|
18894
19041
|
}
|
|
18895
19042
|
});
|
|
18896
19043
|
var gitCommand = program.command("git").description("Git operations with AI assistance");
|
|
18897
|
-
gitCommand.command("commit-and-push").description("Generate AI commit message and push to remote").option("-d, --directory <dir>", "set working directory", process.cwd()).option("-k, --api-key <key>", "
|
|
19044
|
+
gitCommand.command("commit-and-push").description("Generate AI commit message and push to remote").option("-d, --directory <dir>", "set working directory", process.cwd()).option("-k, --api-key <key>", "X API key (or set X_API_KEY env var)").option(
|
|
18898
19045
|
"-u, --base-url <url>",
|
|
18899
19046
|
"Grok API base URL (or set GROK_BASE_URL env var)"
|
|
18900
19047
|
).option(
|
|
@@ -18923,7 +19070,7 @@ gitCommand.command("commit-and-push").description("Generate AI commit message an
|
|
|
18923
19070
|
const maxToolRounds = parseInt(options.maxToolRounds) || 400;
|
|
18924
19071
|
if (!apiKey) {
|
|
18925
19072
|
console.error(
|
|
18926
|
-
"\u274C Error: API key required. Set
|
|
19073
|
+
"\u274C Error: API key required. Set X_API_KEY environment variable, use --api-key flag, or save to ~/.x/user-settings.json"
|
|
18927
19074
|
);
|
|
18928
19075
|
process.exit(1);
|
|
18929
19076
|
}
|