@ottili_one/ai-chat 1.0.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 +275 -0
- package/dist/cli/commands.d.ts +13 -0
- package/dist/cli/commands.js +221 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +4 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/prompts.d.ts +2 -0
- package/dist/cli/prompts.js +32 -0
- package/dist/cli/prompts.js.map +1 -0
- package/dist/cli/repl.d.ts +9 -0
- package/dist/cli/repl.js +166 -0
- package/dist/cli/repl.js.map +1 -0
- package/dist/config/env.d.ts +2 -0
- package/dist/config/env.js +8 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/userConfig.d.ts +10 -0
- package/dist/config/userConfig.js +91 -0
- package/dist/config/userConfig.js.map +1 -0
- package/dist/core/explainCommand.d.ts +2 -0
- package/dist/core/explainCommand.js +4 -0
- package/dist/core/explainCommand.js.map +1 -0
- package/dist/core/generateCommand.d.ts +2 -0
- package/dist/core/generateCommand.js +29 -0
- package/dist/core/generateCommand.js.map +1 -0
- package/dist/core/output.d.ts +4 -0
- package/dist/core/output.js +67 -0
- package/dist/core/output.js.map +1 -0
- package/dist/core/prompts.d.ts +7 -0
- package/dist/core/prompts.js +71 -0
- package/dist/core/prompts.js.map +1 -0
- package/dist/core/response.d.ts +19 -0
- package/dist/core/response.js +44 -0
- package/dist/core/response.js.map +1 -0
- package/dist/core/session.d.ts +9 -0
- package/dist/core/session.js +23 -0
- package/dist/core/session.js.map +1 -0
- package/dist/exec/runCommand.d.ts +11 -0
- package/dist/exec/runCommand.js +57 -0
- package/dist/exec/runCommand.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/platform/detectPlatform.d.ts +9 -0
- package/dist/platform/detectPlatform.js +49 -0
- package/dist/platform/detectPlatform.js.map +1 -0
- package/dist/platform/detectServiceManager.d.ts +3 -0
- package/dist/platform/detectServiceManager.js +38 -0
- package/dist/platform/detectServiceManager.js.map +1 -0
- package/dist/platform/detectShell.d.ts +3 -0
- package/dist/platform/detectShell.js +21 -0
- package/dist/platform/detectShell.js.map +1 -0
- package/dist/providers/factory.d.ts +2 -0
- package/dist/providers/factory.js +9 -0
- package/dist/providers/factory.js.map +1 -0
- package/dist/providers/openai.d.ts +8 -0
- package/dist/providers/openai.js +73 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/types.d.ts +1 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/safety/classifyRisk.d.ts +7 -0
- package/dist/safety/classifyRisk.js +115 -0
- package/dist/safety/classifyRisk.js.map +1 -0
- package/dist/safety/dangerousPatterns.d.ts +8 -0
- package/dist/safety/dangerousPatterns.js +70 -0
- package/dist/safety/dangerousPatterns.js.map +1 -0
- package/dist/safety/executionPolicy.d.ts +9 -0
- package/dist/safety/executionPolicy.js +21 -0
- package/dist/safety/executionPolicy.js.map +1 -0
- package/dist/types/index.d.ts +79 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/branding.d.ts +6 -0
- package/dist/utils/branding.js +11 -0
- package/dist/utils/branding.js.map +1 -0
- package/dist/utils/errors.d.ts +26 -0
- package/dist/utils/errors.js +59 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/logger.d.ts +5 -0
- package/dist/utils/logger.js +14 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/strings.d.ts +5 -0
- package/dist/utils/strings.js +30 -0
- package/dist/utils/strings.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ottili ONE
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# `ai-cmd`
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
`ai-cmd` is a focused CLI for turning natural-language terminal questions into a single shell command you can inspect, copy, explain, and optionally run with confirmation.
|
|
9
|
+
|
|
10
|
+
It is designed for the fast path:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
ai "how do I restart nginx"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Instead of a chatty assistant or a full autonomous agent, `ai-cmd` aims to be the small utility you keep installed because it is quick, predictable, and useful.
|
|
17
|
+
|
|
18
|
+
## Why it exists
|
|
19
|
+
|
|
20
|
+
Developers regularly know what they want to do in the terminal, but not the exact command for the current machine, shell, or init system.
|
|
21
|
+
|
|
22
|
+
`ai-cmd` narrows that gap by:
|
|
23
|
+
|
|
24
|
+
- generating one best command instead of a long essay
|
|
25
|
+
- adapting to Linux, macOS, WSL, and generic Unix-like environments
|
|
26
|
+
- explaining what the command does
|
|
27
|
+
- classifying command risk before execution
|
|
28
|
+
- keeping interactive follow-ups lightweight
|
|
29
|
+
|
|
30
|
+
## Powered by Ottili ONE
|
|
31
|
+
|
|
32
|
+
This project is part of the **Ottili ONE ecosystem** — a modular AI system for automating development, business workflows, and operations.
|
|
33
|
+
|
|
34
|
+
### Website: https://ottili.one
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- One-shot command generation: `ai "<question>"`
|
|
41
|
+
- Interactive REPL mode: `ai`
|
|
42
|
+
- Session-aware follow-up questions in REPL mode
|
|
43
|
+
- Command explanations and platform notes
|
|
44
|
+
- Clipboard copy support
|
|
45
|
+
- Optional execution with confirmation
|
|
46
|
+
- Heuristic risk classification for destructive commands
|
|
47
|
+
- OpenAI-compatible provider abstraction
|
|
48
|
+
- JSON mode for scripting
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
### Global install from npm
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install -g ai-cmd
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Local development install
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm install
|
|
62
|
+
npm run build
|
|
63
|
+
npm link
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
`ai-cmd` reads configuration from environment variables and optionally from `~/.ai-cmd/config.json`.
|
|
69
|
+
|
|
70
|
+
Environment variables take precedence over the config file.
|
|
71
|
+
|
|
72
|
+
If no API key is configured yet, `ai-cmd` creates a starter config file for you on first run.
|
|
73
|
+
|
|
74
|
+
### Required
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
export AI_API_KEY="your-api-key"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Optional
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
export AI_PROVIDER="openai"
|
|
84
|
+
export AI_MODEL="gpt-5.4-mini"
|
|
85
|
+
export AI_BASE_URL="https://api.openai.com/v1"
|
|
86
|
+
export AI_TIMEOUT_MS="30000"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Example config file
|
|
90
|
+
|
|
91
|
+
`~/.ai-cmd/config.json`
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"provider": "openai",
|
|
96
|
+
"model": "gpt-5.4-mini",
|
|
97
|
+
"apiKey": "your-api-key",
|
|
98
|
+
"baseUrl": "https://api.openai.com/v1",
|
|
99
|
+
"timeoutMs": 30000
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
If configuration is missing, `ai-cmd` fails clearly:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
Missing AI_API_KEY. Set it in your environment or edit ~/.ai-cmd/config.json. A starter config has been created if it did not already exist.
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Usage
|
|
110
|
+
|
|
111
|
+
### One-shot mode
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
ai "how do I restart nginx"
|
|
115
|
+
ai "find all files bigger than 100MB"
|
|
116
|
+
ai "show disk usage" --json
|
|
117
|
+
ai "remove node_modules and reinstall packages" --exec
|
|
118
|
+
ai "find all jpg files" --copy
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Interactive mode
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
ai
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Commands available inside the REPL:
|
|
128
|
+
|
|
129
|
+
- `help`
|
|
130
|
+
- `last`
|
|
131
|
+
- `explain`
|
|
132
|
+
- `run`
|
|
133
|
+
- `copy`
|
|
134
|
+
- `clear`
|
|
135
|
+
- `exit`
|
|
136
|
+
|
|
137
|
+
Example session:
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
ai-cmd > how do I restart nginx
|
|
141
|
+
ai-cmd > explain
|
|
142
|
+
ai-cmd > run
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## CLI flags
|
|
146
|
+
|
|
147
|
+
- `--version` Show the branded version banner
|
|
148
|
+
- `--exec` Execute the generated command after confirmation
|
|
149
|
+
- `--yes` Skip the normal confirmation step for low and medium risk commands
|
|
150
|
+
- `--explain` Explicitly request explanation details from the provider
|
|
151
|
+
- `--json` Output machine-readable JSON
|
|
152
|
+
- `--shell <bash|zsh|sh>` Hint the active shell
|
|
153
|
+
- `--copy` Copy the generated command to the clipboard
|
|
154
|
+
- `--no-color` Disable colored output
|
|
155
|
+
- `--debug` Print diagnostic context
|
|
156
|
+
|
|
157
|
+
## Safety model
|
|
158
|
+
|
|
159
|
+
`ai-cmd` is allowed to execute commands, so the MVP includes a practical safety layer:
|
|
160
|
+
|
|
161
|
+
- `low` risk: read-only or status-style commands such as `ls -la`
|
|
162
|
+
- `medium` risk: service restarts, dependency installs, project-scoped cleanup
|
|
163
|
+
- `high` risk: destructive recursive deletes, disk tools, remote shell pipes, system package removal
|
|
164
|
+
|
|
165
|
+
Execution rules:
|
|
166
|
+
|
|
167
|
+
- low and medium risk commands require confirmation unless `--yes` is used
|
|
168
|
+
- high risk commands always require an explicit confirmation phrase
|
|
169
|
+
- `--yes` never bypasses the high-risk confirmation path
|
|
170
|
+
- unsupported host OSes can still generate best-effort Unix-style commands, but execution is disabled
|
|
171
|
+
|
|
172
|
+
Example high-risk confirmation:
|
|
173
|
+
|
|
174
|
+
```text
|
|
175
|
+
Risk: HIGH
|
|
176
|
+
This command can delete files recursively outside the current project.
|
|
177
|
+
Type EXECUTE HIGH RISK COMMAND to continue:
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Supported platforms
|
|
181
|
+
|
|
182
|
+
- Linux
|
|
183
|
+
- macOS
|
|
184
|
+
- WSL
|
|
185
|
+
- Generic Unix-like systems
|
|
186
|
+
|
|
187
|
+
Notes:
|
|
188
|
+
|
|
189
|
+
- Linux service-manager detection prefers `systemctl`, then `service`, then `rc-service`
|
|
190
|
+
- macOS service handling prefers launchd-oriented commands
|
|
191
|
+
- Native Windows command generation is intentionally limited in this MVP
|
|
192
|
+
|
|
193
|
+
## Architecture
|
|
194
|
+
|
|
195
|
+
```text
|
|
196
|
+
src/
|
|
197
|
+
cli/
|
|
198
|
+
config/
|
|
199
|
+
core/
|
|
200
|
+
exec/
|
|
201
|
+
platform/
|
|
202
|
+
providers/
|
|
203
|
+
safety/
|
|
204
|
+
types/
|
|
205
|
+
utils/
|
|
206
|
+
tests/
|
|
207
|
+
integration/
|
|
208
|
+
unit/
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Key design choices:
|
|
212
|
+
|
|
213
|
+
- thin Commander-based CLI layer
|
|
214
|
+
- business logic isolated under `core/`
|
|
215
|
+
- provider abstraction isolated under `providers/`
|
|
216
|
+
- platform and service-manager detection isolated under `platform/`
|
|
217
|
+
- execution safety and confirmation logic isolated under `safety/`
|
|
218
|
+
- strict JSON normalization and validation before rendering or execution
|
|
219
|
+
|
|
220
|
+
## Development
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
npm install
|
|
224
|
+
npm run typecheck
|
|
225
|
+
npm run lint
|
|
226
|
+
npm test
|
|
227
|
+
npm run build
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Run in development mode:
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
npm run dev -- "how do I list listening ports"
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## JSON output
|
|
237
|
+
|
|
238
|
+
`--json` prints a structured payload suitable for scripts:
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
ai "show disk usage" --json
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Example shape:
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"question": "show disk usage",
|
|
249
|
+
"command": "du -sh .",
|
|
250
|
+
"explanation": "Shows total disk usage for the current directory.",
|
|
251
|
+
"risk": "low",
|
|
252
|
+
"platformNotes": [],
|
|
253
|
+
"assumptions": [],
|
|
254
|
+
"platform": {
|
|
255
|
+
"os": "linux",
|
|
256
|
+
"shell": "bash",
|
|
257
|
+
"serviceManager": "systemctl",
|
|
258
|
+
"cwd": "/work/project",
|
|
259
|
+
"cwdName": "project"
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Roadmap
|
|
265
|
+
|
|
266
|
+
- additional provider adapters
|
|
267
|
+
- richer shell support
|
|
268
|
+
- more precise filesystem-aware risk detection
|
|
269
|
+
- Homebrew distribution
|
|
270
|
+
- optional standalone binaries
|
|
271
|
+
- improved follow-up context handling
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { runCommand } from "../exec/runCommand.js";
|
|
2
|
+
import type { AIProvider, AppConfig, PlatformContext, PromptAdapter } from "../types/index.js";
|
|
3
|
+
export interface CliDependencies {
|
|
4
|
+
loadConfig: () => Promise<AppConfig>;
|
|
5
|
+
detectPlatformContext: () => Promise<PlatformContext>;
|
|
6
|
+
createProvider: (config: AppConfig) => AIProvider;
|
|
7
|
+
createPromptAdapter: () => PromptAdapter;
|
|
8
|
+
copyToClipboard: (command: string) => Promise<void>;
|
|
9
|
+
commandRunner: typeof runCommand;
|
|
10
|
+
}
|
|
11
|
+
export declare function createDefaultDependencies(): CliDependencies;
|
|
12
|
+
export declare function runCli(argv?: string[], dependencies?: CliDependencies): Promise<void>;
|
|
13
|
+
export declare function runCliAndHandleErrors(argv?: string[], dependencies?: CliDependencies): Promise<void>;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import clipboardy from "clipboardy";
|
|
2
|
+
import { Command, Option } from "commander";
|
|
3
|
+
import { startRepl } from "./repl.js";
|
|
4
|
+
import { createPromptAdapter } from "./prompts.js";
|
|
5
|
+
import { loadConfig } from "../config/userConfig.js";
|
|
6
|
+
import { generateCommand } from "../core/generateCommand.js";
|
|
7
|
+
import { formatSuggestion } from "../core/output.js";
|
|
8
|
+
import { runCommand } from "../exec/runCommand.js";
|
|
9
|
+
import { detectPlatformContext } from "../platform/detectPlatform.js";
|
|
10
|
+
import { createProvider } from "../providers/factory.js";
|
|
11
|
+
import { assessCommandRisk } from "../safety/classifyRisk.js";
|
|
12
|
+
import { enforceExecutionPolicy } from "../safety/executionPolicy.js";
|
|
13
|
+
import { ClipboardError, ConfigurationError, getErrorMessage } from "../utils/errors.js";
|
|
14
|
+
import { formatVersionBanner } from "../utils/branding.js";
|
|
15
|
+
import { Logger } from "../utils/logger.js";
|
|
16
|
+
export function createDefaultDependencies() {
|
|
17
|
+
return {
|
|
18
|
+
loadConfig: () => loadConfig(),
|
|
19
|
+
detectPlatformContext,
|
|
20
|
+
createProvider,
|
|
21
|
+
createPromptAdapter,
|
|
22
|
+
copyToClipboard: async (command) => {
|
|
23
|
+
try {
|
|
24
|
+
await clipboardy.write(command);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
throw new ClipboardError("Clipboard unavailable. Command printed below instead.", error);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
commandRunner: runCommand
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function normalizeCliOptions(rawOptions) {
|
|
34
|
+
const options = {
|
|
35
|
+
exec: Boolean(rawOptions.exec),
|
|
36
|
+
yes: Boolean(rawOptions.yes),
|
|
37
|
+
explain: Boolean(rawOptions.explain),
|
|
38
|
+
json: Boolean(rawOptions.json),
|
|
39
|
+
version: Boolean(rawOptions.version),
|
|
40
|
+
noColor: rawOptions.color === false,
|
|
41
|
+
debug: Boolean(rawOptions.debug),
|
|
42
|
+
copy: Boolean(rawOptions.copy)
|
|
43
|
+
};
|
|
44
|
+
if (rawOptions.shell === "bash" ||
|
|
45
|
+
rawOptions.shell === "zsh" ||
|
|
46
|
+
rawOptions.shell === "sh") {
|
|
47
|
+
options.shell = rawOptions.shell;
|
|
48
|
+
}
|
|
49
|
+
return options;
|
|
50
|
+
}
|
|
51
|
+
function ensureInteractiveFlagsAreValid(options) {
|
|
52
|
+
if (options.json || options.exec || options.yes || options.copy) {
|
|
53
|
+
throw new ConfigurationError("--json, --exec, --yes, and --copy require a question in one-shot mode.");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function writeJsonWithExecution(suggestion, execution) {
|
|
57
|
+
process.stdout.write(`${JSON.stringify({
|
|
58
|
+
question: suggestion.question,
|
|
59
|
+
command: suggestion.command,
|
|
60
|
+
explanation: suggestion.explanation,
|
|
61
|
+
risk: suggestion.risk,
|
|
62
|
+
platformNotes: suggestion.platformNotes,
|
|
63
|
+
assumptions: suggestion.assumptions,
|
|
64
|
+
platform: suggestion.platform,
|
|
65
|
+
execution
|
|
66
|
+
}, null, 2)}\n`);
|
|
67
|
+
}
|
|
68
|
+
async function handleOneShot(question, options, deps) {
|
|
69
|
+
const logger = new Logger(options.debug);
|
|
70
|
+
const config = await deps.loadConfig();
|
|
71
|
+
const platform = await deps.detectPlatformContext();
|
|
72
|
+
const provider = deps.createProvider(config);
|
|
73
|
+
const effectivePlatform = options.shell
|
|
74
|
+
? { ...platform, shell: options.shell }
|
|
75
|
+
: platform;
|
|
76
|
+
if (options.exec && effectivePlatform.os === "unsupported") {
|
|
77
|
+
throw new ConfigurationError("Execution is disabled on unsupported host OSes. Use a Unix-like shell or WSL.");
|
|
78
|
+
}
|
|
79
|
+
logger.debug("Using platform context", effectivePlatform);
|
|
80
|
+
logger.debug("Using provider", {
|
|
81
|
+
provider: config.provider,
|
|
82
|
+
model: config.model,
|
|
83
|
+
baseUrl: config.baseUrl
|
|
84
|
+
});
|
|
85
|
+
const suggestion = await generateCommand({
|
|
86
|
+
question,
|
|
87
|
+
platform: effectivePlatform,
|
|
88
|
+
provider,
|
|
89
|
+
explainRequested: true
|
|
90
|
+
});
|
|
91
|
+
let execution;
|
|
92
|
+
if (options.json) {
|
|
93
|
+
if (options.copy) {
|
|
94
|
+
try {
|
|
95
|
+
await deps.copyToClipboard(suggestion.command);
|
|
96
|
+
process.stderr.write("Command copied to clipboard.\n");
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (error instanceof ClipboardError) {
|
|
100
|
+
process.stderr.write(`${error.message}\n${suggestion.command}\n`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (options.exec) {
|
|
108
|
+
const assessment = assessCommandRisk(suggestion.command);
|
|
109
|
+
await enforceExecutionPolicy({
|
|
110
|
+
command: suggestion.command,
|
|
111
|
+
risk: assessment.level,
|
|
112
|
+
yes: options.yes,
|
|
113
|
+
prompt: deps.createPromptAdapter(),
|
|
114
|
+
...(assessment.reasons[0] ? { reason: assessment.reasons[0] } : {})
|
|
115
|
+
});
|
|
116
|
+
execution = await deps.commandRunner(suggestion.command, {
|
|
117
|
+
cwd: effectivePlatform.cwd,
|
|
118
|
+
stdio: "pipe"
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
writeJsonWithExecution(suggestion, execution);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
process.stdout.write(`${formatSuggestion(suggestion, {
|
|
125
|
+
color: !options.noColor,
|
|
126
|
+
explain: true,
|
|
127
|
+
json: false
|
|
128
|
+
})}\n`);
|
|
129
|
+
if (options.copy) {
|
|
130
|
+
try {
|
|
131
|
+
await deps.copyToClipboard(suggestion.command);
|
|
132
|
+
process.stderr.write("Command copied to clipboard.\n");
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error instanceof ClipboardError) {
|
|
136
|
+
process.stderr.write(`${error.message}\n${suggestion.command}\n`);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!options.exec) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const assessment = assessCommandRisk(suggestion.command);
|
|
147
|
+
await enforceExecutionPolicy({
|
|
148
|
+
command: suggestion.command,
|
|
149
|
+
risk: assessment.level,
|
|
150
|
+
yes: options.yes,
|
|
151
|
+
prompt: deps.createPromptAdapter(),
|
|
152
|
+
...(assessment.reasons[0] ? { reason: assessment.reasons[0] } : {})
|
|
153
|
+
});
|
|
154
|
+
await deps.commandRunner(suggestion.command, {
|
|
155
|
+
cwd: effectivePlatform.cwd,
|
|
156
|
+
stdio: "inherit"
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
export async function runCli(argv = process.argv, dependencies = createDefaultDependencies()) {
|
|
160
|
+
const program = new Command();
|
|
161
|
+
program
|
|
162
|
+
.name("ai")
|
|
163
|
+
.description("Natural-language shell command generation with safe execution.")
|
|
164
|
+
.argument("[question...]", "Question to turn into a shell command")
|
|
165
|
+
.option("--exec", "Execute the generated command after confirmation")
|
|
166
|
+
.option("--yes", "Skip the standard confirmation prompt for low/medium-risk commands")
|
|
167
|
+
.option("--explain", "Show the explanation alongside the generated command")
|
|
168
|
+
.option("--json", "Emit machine-readable JSON")
|
|
169
|
+
.addOption(new Option("--shell <shell>", "Shell hint for command generation").choices([
|
|
170
|
+
"bash",
|
|
171
|
+
"zsh",
|
|
172
|
+
"sh"
|
|
173
|
+
]))
|
|
174
|
+
.option("-v, --version", "Show branded version information")
|
|
175
|
+
.option("--copy", "Copy the generated command to the clipboard")
|
|
176
|
+
.option("--no-color", "Disable colored output")
|
|
177
|
+
.option("--debug", "Print internal diagnostics")
|
|
178
|
+
.action(async (questionParts, rawOptions) => {
|
|
179
|
+
const options = normalizeCliOptions(rawOptions);
|
|
180
|
+
const question = questionParts.join(" ").trim();
|
|
181
|
+
if (options.version) {
|
|
182
|
+
process.stdout.write(`${formatVersionBanner()}\n`);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (options.yes && !options.exec) {
|
|
186
|
+
throw new ConfigurationError("--yes can only be used together with --exec.");
|
|
187
|
+
}
|
|
188
|
+
if (!question) {
|
|
189
|
+
ensureInteractiveFlagsAreValid(options);
|
|
190
|
+
const logger = new Logger(options.debug);
|
|
191
|
+
const config = await dependencies.loadConfig();
|
|
192
|
+
const platform = await dependencies.detectPlatformContext();
|
|
193
|
+
const provider = dependencies.createProvider(config);
|
|
194
|
+
const effectivePlatform = options.shell
|
|
195
|
+
? { ...platform, shell: options.shell }
|
|
196
|
+
: platform;
|
|
197
|
+
await startRepl({
|
|
198
|
+
platform: effectivePlatform,
|
|
199
|
+
provider,
|
|
200
|
+
prompt: dependencies.createPromptAdapter(),
|
|
201
|
+
color: !options.noColor,
|
|
202
|
+
logger
|
|
203
|
+
});
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
await handleOneShot(question, options, dependencies);
|
|
207
|
+
});
|
|
208
|
+
await program.parseAsync(argv);
|
|
209
|
+
}
|
|
210
|
+
export async function runCliAndHandleErrors(argv = process.argv, dependencies = createDefaultDependencies()) {
|
|
211
|
+
try {
|
|
212
|
+
await runCli(argv, dependencies);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
const debug = argv.includes("--debug") ||
|
|
216
|
+
argv.includes("-d");
|
|
217
|
+
process.stderr.write(`${getErrorMessage(error, debug)}\n`);
|
|
218
|
+
process.exitCode = 1;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAA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AK,CAAC,GAAG,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,qBAAqB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import prompts from "prompts";
|
|
2
|
+
import { UserCancelledError } from "../utils/errors.js";
|
|
3
|
+
export function createPromptAdapter() {
|
|
4
|
+
return {
|
|
5
|
+
async confirm(message, initial = false) {
|
|
6
|
+
const response = await prompts({
|
|
7
|
+
type: "confirm",
|
|
8
|
+
name: "value",
|
|
9
|
+
message,
|
|
10
|
+
initial
|
|
11
|
+
}, {
|
|
12
|
+
onCancel: () => {
|
|
13
|
+
throw new UserCancelledError("Command execution cancelled.");
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return Boolean(response.value);
|
|
17
|
+
},
|
|
18
|
+
async text(message) {
|
|
19
|
+
const response = await prompts({
|
|
20
|
+
type: "text",
|
|
21
|
+
name: "value",
|
|
22
|
+
message
|
|
23
|
+
}, {
|
|
24
|
+
onCancel: () => {
|
|
25
|
+
throw new UserCancelledError("Command execution cancelled.");
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return String(response.value ?? "");
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/cli/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,KAAK,CAAC,OAAO,CAAC,OAAe,EAAE,OAAO,GAAG,KAAK;YAC5C,MAAM,QAAQ,GAAG,MAAM,OAAO,CAC5B;gBACE,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,OAAO;gBACb,OAAO;gBACP,OAAO;aACR,EACD;gBACE,QAAQ,EAAE,GAAG,EAAE;oBACb,MAAM,IAAI,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;gBAC/D,CAAC;aACF,CACF,CAAC;YAEF,OAAO,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,OAAe;YACxB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAC5B;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,OAAO;gBACb,OAAO;aACR,EACD;gBACE,QAAQ,EAAE,GAAG,EAAE;oBACb,MAAM,IAAI,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;gBAC/D,CAAC;aACF,CACF,CAAC;YAEF,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AIProvider, PlatformContext, PromptAdapter } from "../types/index.js";
|
|
2
|
+
import type { Logger } from "../utils/logger.js";
|
|
3
|
+
export declare function startRepl(options: {
|
|
4
|
+
platform: PlatformContext;
|
|
5
|
+
provider: AIProvider;
|
|
6
|
+
prompt: PromptAdapter;
|
|
7
|
+
color: boolean;
|
|
8
|
+
logger: Logger;
|
|
9
|
+
}): Promise<void>;
|