@vdntio/clai 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +98 -0
- package/dist/ai/index.d.ts +24 -0
- package/dist/ai/index.js +78 -0
- package/dist/ai/mock.d.ts +17 -0
- package/dist/ai/mock.js +49 -0
- package/dist/ai/parser.d.ts +14 -0
- package/dist/ai/parser.js +109 -0
- package/dist/ai/prompt.d.ts +12 -0
- package/dist/ai/prompt.js +76 -0
- package/dist/ai/providers/index.d.ts +1 -0
- package/dist/ai/providers/index.js +2 -0
- package/dist/ai/providers/openrouter.d.ts +31 -0
- package/dist/ai/providers/openrouter.js +142 -0
- package/dist/ai/types.d.ts +46 -0
- package/dist/ai/types.js +15 -0
- package/dist/cli/index.d.ts +19 -0
- package/dist/cli/index.js +71 -0
- package/dist/config/index.d.ts +12 -0
- package/dist/config/index.js +363 -0
- package/dist/config/types.d.ts +76 -0
- package/dist/config/types.js +40 -0
- package/dist/context/directory.d.ts +18 -0
- package/dist/context/directory.js +71 -0
- package/dist/context/history.d.ts +16 -0
- package/dist/context/history.js +89 -0
- package/dist/context/index.d.ts +24 -0
- package/dist/context/index.js +61 -0
- package/dist/context/redaction.d.ts +14 -0
- package/dist/context/redaction.js +57 -0
- package/dist/context/stdin.d.ts +13 -0
- package/dist/context/stdin.js +86 -0
- package/dist/context/system.d.ts +11 -0
- package/dist/context/system.js +56 -0
- package/dist/context/types.d.ts +31 -0
- package/dist/context/types.js +10 -0
- package/dist/error/index.d.ts +30 -0
- package/dist/error/index.js +50 -0
- package/dist/logging/file-logger.d.ts +12 -0
- package/dist/logging/file-logger.js +66 -0
- package/dist/logging/index.d.ts +15 -0
- package/dist/logging/index.js +33 -0
- package/dist/logging/logger.d.ts +15 -0
- package/dist/logging/logger.js +60 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +192 -0
- package/dist/output/execute.d.ts +30 -0
- package/dist/output/execute.js +144 -0
- package/dist/output/index.d.ts +4 -0
- package/dist/output/index.js +7 -0
- package/dist/output/types.d.ts +48 -0
- package/dist/output/types.js +34 -0
- package/dist/output/validate.d.ts +23 -0
- package/dist/output/validate.js +42 -0
- package/dist/safety/index.d.ts +34 -0
- package/dist/safety/index.js +59 -0
- package/dist/safety/patterns.d.ts +23 -0
- package/dist/safety/patterns.js +96 -0
- package/dist/safety/types.d.ts +20 -0
- package/dist/safety/types.js +18 -0
- package/dist/signals/index.d.ts +4 -0
- package/dist/signals/index.js +35 -0
- package/dist/ui/App.d.ts +4 -0
- package/dist/ui/App.js +57 -0
- package/dist/ui/components/ActionPrompt.d.ts +8 -0
- package/dist/ui/components/ActionPrompt.js +9 -0
- package/dist/ui/components/CommandDisplay.d.ts +9 -0
- package/dist/ui/components/CommandDisplay.js +13 -0
- package/dist/ui/components/DangerousWarning.d.ts +6 -0
- package/dist/ui/components/DangerousWarning.js +6 -0
- package/dist/ui/components/Spinner.d.ts +15 -0
- package/dist/ui/components/Spinner.js +17 -0
- package/dist/ui/hooks/useAnimation.d.ts +27 -0
- package/dist/ui/hooks/useAnimation.js +85 -0
- package/dist/ui/hooks/useTerminalSize.d.ts +12 -0
- package/dist/ui/hooks/useTerminalSize.js +56 -0
- package/dist/ui/hooks/useTimeout.d.ts +9 -0
- package/dist/ui/hooks/useTimeout.js +31 -0
- package/dist/ui/index.d.ts +25 -0
- package/dist/ui/index.js +80 -0
- package/dist/ui/output.d.ts +20 -0
- package/dist/ui/output.js +56 -0
- package/dist/ui/spinner.d.ts +13 -0
- package/dist/ui/spinner.js +58 -0
- package/dist/ui/types.d.ts +105 -0
- package/dist/ui/types.js +60 -0
- package/dist/ui/utils/formatCommand.d.ts +50 -0
- package/dist/ui/utils/formatCommand.js +113 -0
- package/package.json +68 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/ui/utils/formatCommand.ts
|
|
2
|
+
// Utilities for formatting and truncating commands for display
|
|
3
|
+
/**
|
|
4
|
+
* Format a command for display in the terminal
|
|
5
|
+
* Truncates with ellipsis if too long for available width
|
|
6
|
+
*
|
|
7
|
+
* @param command - The command string to format
|
|
8
|
+
* @param maxWidth - Maximum width available (in columns)
|
|
9
|
+
* @returns Formatted command string
|
|
10
|
+
*/
|
|
11
|
+
export function formatCommand(command, maxWidth) {
|
|
12
|
+
// Account for "$ " prefix (2 chars) and some padding
|
|
13
|
+
const availableWidth = maxWidth - 4;
|
|
14
|
+
if (availableWidth <= 3) {
|
|
15
|
+
// Extremely narrow terminal
|
|
16
|
+
return '...';
|
|
17
|
+
}
|
|
18
|
+
if (command.length <= availableWidth) {
|
|
19
|
+
return command;
|
|
20
|
+
}
|
|
21
|
+
// Truncate with ellipsis, preserving as much context as possible
|
|
22
|
+
return command.slice(0, availableWidth - 3) + '...';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Format command counter like [1/3]
|
|
26
|
+
*
|
|
27
|
+
* @param currentIndex - Current index (0-based)
|
|
28
|
+
* @param total - Total number of commands
|
|
29
|
+
* @returns Formatted counter string
|
|
30
|
+
*/
|
|
31
|
+
export function formatCounter(currentIndex, total) {
|
|
32
|
+
if (total <= 1) {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
return `[${currentIndex + 1}/${total}]`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Calculate available width for command display
|
|
39
|
+
* Accounts for prefix, counter, and padding
|
|
40
|
+
*
|
|
41
|
+
* @param terminalWidth - Total terminal width
|
|
42
|
+
* @param hasCounter - Whether counter will be shown
|
|
43
|
+
* @returns Width available for command text
|
|
44
|
+
*/
|
|
45
|
+
export function getCommandDisplayWidth(terminalWidth, hasCounter = true) {
|
|
46
|
+
// Reserve space for:
|
|
47
|
+
// - "$ " prefix (2 chars)
|
|
48
|
+
// - Counter "[N/M]" (5-7 chars) if multiple commands
|
|
49
|
+
// - Some padding (2-4 chars)
|
|
50
|
+
const counterSpace = hasCounter ? 8 : 0;
|
|
51
|
+
const padding = 4;
|
|
52
|
+
return Math.max(20, terminalWidth - counterSpace - padding);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Truncate text with ellipsis in the middle (for paths)
|
|
56
|
+
*
|
|
57
|
+
* @param text - Text to truncate
|
|
58
|
+
* @param maxLength - Maximum length
|
|
59
|
+
* @returns Truncated text
|
|
60
|
+
*/
|
|
61
|
+
export function truncateMiddle(text, maxLength) {
|
|
62
|
+
if (text.length <= maxLength) {
|
|
63
|
+
return text;
|
|
64
|
+
}
|
|
65
|
+
if (maxLength <= 5) {
|
|
66
|
+
return text.slice(0, maxLength - 1) + '…';
|
|
67
|
+
}
|
|
68
|
+
const sideLength = Math.floor((maxLength - 3) / 2);
|
|
69
|
+
const start = text.slice(0, sideLength);
|
|
70
|
+
const end = text.slice(-sideLength);
|
|
71
|
+
return `${start}...${end}`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Wrap text to fit within a maximum width
|
|
75
|
+
*
|
|
76
|
+
* @param text - Text to wrap
|
|
77
|
+
* @param maxWidth - Maximum line width
|
|
78
|
+
* @returns Array of wrapped lines
|
|
79
|
+
*/
|
|
80
|
+
export function wrapText(text, maxWidth) {
|
|
81
|
+
if (text.length <= maxWidth) {
|
|
82
|
+
return [text];
|
|
83
|
+
}
|
|
84
|
+
const words = text.split(/\s+/);
|
|
85
|
+
const lines = [];
|
|
86
|
+
let currentLine = '';
|
|
87
|
+
for (const word of words) {
|
|
88
|
+
if (currentLine.length === 0) {
|
|
89
|
+
currentLine = word;
|
|
90
|
+
}
|
|
91
|
+
else if (currentLine.length + 1 + word.length <= maxWidth) {
|
|
92
|
+
currentLine += ' ' + word;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
lines.push(currentLine);
|
|
96
|
+
currentLine = word;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (currentLine.length > 0) {
|
|
100
|
+
lines.push(currentLine);
|
|
101
|
+
}
|
|
102
|
+
return lines;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create a visual separator line
|
|
106
|
+
*
|
|
107
|
+
* @param width - Width of the separator
|
|
108
|
+
* @param char - Character to use (default: ─)
|
|
109
|
+
* @returns Separator string
|
|
110
|
+
*/
|
|
111
|
+
export function createSeparator(width, char = '─') {
|
|
112
|
+
return char.repeat(Math.max(0, width));
|
|
113
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vdntio/clai",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "AI-powered CLI that converts natural language into executable shell commands",
|
|
5
|
+
"module": "src/main.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"clai": "dist/main.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "tsx watch src/main.ts",
|
|
17
|
+
"build": "tsc && chmod +x dist/main.js",
|
|
18
|
+
"test": "vitest",
|
|
19
|
+
"lint": "eslint . --ext .ts",
|
|
20
|
+
"link": "bun link",
|
|
21
|
+
"prepublishOnly": "bun run build"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/vdntio/clAI"
|
|
26
|
+
},
|
|
27
|
+
"bugs": "https://github.com/vdntio/clAI/issues",
|
|
28
|
+
"homepage": "https://github.com/vdntio/clAI#readme",
|
|
29
|
+
"keywords": [
|
|
30
|
+
"cli",
|
|
31
|
+
"ai",
|
|
32
|
+
"shell",
|
|
33
|
+
"commands",
|
|
34
|
+
"natural-language",
|
|
35
|
+
"openrouter",
|
|
36
|
+
"bun"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@eslint/js": "^9.39.2",
|
|
47
|
+
"@iarna/toml": "^2.2.5",
|
|
48
|
+
"@types/bun": "latest",
|
|
49
|
+
"@types/node": "^25.1.0",
|
|
50
|
+
"@types/react": "^19.2.10",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
52
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
53
|
+
"commander": "^14.0.2",
|
|
54
|
+
"eslint": "^9.39.2",
|
|
55
|
+
"globals": "^17.2.0",
|
|
56
|
+
"prettier": "^3.8.1",
|
|
57
|
+
"tsx": "^4.21.0",
|
|
58
|
+
"typescript": "^5.9.3",
|
|
59
|
+
"vitest": "^4.0.18",
|
|
60
|
+
"zod": "^4.3.6"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"chalk": "^5.6.2",
|
|
64
|
+
"ink": "^6.6.0",
|
|
65
|
+
"react": "^19.2.4",
|
|
66
|
+
"react-devtools-core": "^7.0.1"
|
|
67
|
+
}
|
|
68
|
+
}
|