@semalt-ai/code 1.0.0 → 1.1.0

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.
Files changed (3) hide show
  1. package/README.md +227 -0
  2. package/index.js +8 -0
  3. package/package.json +8 -2
package/README.md ADDED
@@ -0,0 +1,227 @@
1
+ # Semalt.AI Code CLI
2
+
3
+ `@semalt-ai/code` is a self-hosted AI coding assistant for the terminal.
4
+
5
+ It provides an interactive chat interface, one-shot code generation, AI-assisted file editing, shell command execution, and an agent loop that can read files, write files, and run commands after user approval.
6
+
7
+ ## Features
8
+
9
+ - Interactive terminal chat mode
10
+ - OpenAI-compatible API integration
11
+ - Streaming responses with terminal-friendly formatting
12
+ - Optional reasoning stream display when the backend provides it
13
+ - User-approved shell, file read, and file write actions
14
+ - File and directory context loading
15
+ - One-shot code task mode
16
+ - AI-assisted file editing mode
17
+ - Model discovery from the configured API
18
+
19
+ ## Requirements
20
+
21
+ - Node.js `>=16`
22
+ - An OpenAI-compatible API endpoint
23
+
24
+ The default configuration expects a local API server at `http://127.0.0.1:8800`.
25
+
26
+ ## Installation
27
+
28
+ Install the package globally so the `semalt-code` command is available system-wide.
29
+
30
+ ```bash
31
+ npm install -g @semalt-ai/code
32
+ ```
33
+
34
+ After global installation, run:
35
+
36
+ ```bash
37
+ semalt-code
38
+ ```
39
+
40
+ ## Initial Setup
41
+
42
+ Create the CLI config:
43
+
44
+ ```bash
45
+ semalt-code init --api-base http://127.0.0.1:8800 --api-key any --default-model default
46
+ ```
47
+
48
+ This writes configuration to:
49
+
50
+ ```text
51
+ ~/.semalt-ai/config.json
52
+ ```
53
+
54
+ Example config:
55
+
56
+ ```json
57
+ {
58
+ "api_base": "http://127.0.0.1:8800",
59
+ "api_key": "any",
60
+ "default_model": "default",
61
+ "temperature": 0.7,
62
+ "max_tokens": 4096,
63
+ "stream": true
64
+ }
65
+ ```
66
+
67
+ ## Usage
68
+
69
+ ```bash
70
+ semalt-code [command] [options]
71
+ ```
72
+
73
+ ### Commands
74
+
75
+ - `semalt-code`
76
+ - `semalt-code chat`
77
+ Starts interactive chat mode.
78
+
79
+ - `semalt-code code <prompt>`
80
+ Runs a one-shot coding task.
81
+
82
+ - `semalt-code edit <file> <instruction>`
83
+ Sends a file to the model and overwrites it with the returned result.
84
+
85
+ - `semalt-code shell <command>`
86
+ Runs a shell command with approval prompts.
87
+
88
+ - `semalt-code models`
89
+ Lists models exposed by the configured API.
90
+
91
+ - `semalt-code init`
92
+ Creates or updates the local config file.
93
+
94
+ ### Options
95
+
96
+ - `-m, --model <name>`
97
+ Override the model name.
98
+
99
+ - `-v, --version`
100
+ Print the current CLI version.
101
+
102
+ - `-f, --file <path>`
103
+ Load one or more files or directories into the prompt context for `code`.
104
+
105
+ - `-a, --analyze`
106
+ After `shell`, ask the model to summarize the command output.
107
+
108
+ - `--dry-run`
109
+ For `edit`, show the generated result without saving it.
110
+
111
+ - `--api-base <url>`
112
+ Set the API base URL during `init`.
113
+
114
+ - `--api-key <key>`
115
+ Set the API key during `init`.
116
+
117
+ - `--default-model <name>`
118
+ Set the default model during `init`.
119
+
120
+ ## Interactive Chat Mode
121
+
122
+ Running `semalt-code` without arguments starts the terminal chat UI.
123
+
124
+ Available interactive commands:
125
+
126
+ - `/help`
127
+ - `/file <path>`
128
+ - `/model <name>`
129
+ - `/clear`
130
+ - `/compact`
131
+ - `/cost`
132
+ - `/shell <cmd>`
133
+ - `!<cmd>`
134
+ - `/approve`
135
+ - `/config`
136
+ - `exit`
137
+
138
+ ### What `/file` does
139
+
140
+ - If you pass a file, its full content is added to the conversation context.
141
+ - If you pass a directory, the CLI recursively loads up to 50 non-hidden files.
142
+
143
+ ## Agent Behavior
144
+
145
+ The assistant is instructed to use special tool-like tags:
146
+
147
+ - `<exec>...</exec>` for shell commands
148
+ - `<read_file>...</read_file>` for file reads
149
+ - `<write_file path="...">...</write_file>` for file writes
150
+
151
+ When the model emits these actions, the CLI:
152
+
153
+ 1. Detects them in the response
154
+ 2. Prompts the user for approval
155
+ 3. Executes the action
156
+ 4. Sends the result back to the model
157
+ 5. Continues for up to 10 iterations
158
+
159
+ This makes the tool behave like a lightweight terminal agent while keeping the user in control.
160
+
161
+ ## Examples
162
+
163
+ ### Start chat
164
+
165
+ ```bash
166
+ semalt-code
167
+ ```
168
+
169
+ ### Ask for a coding task with file context
170
+
171
+ ```bash
172
+ semalt-code code -f package.json -f index.js "Explain this project and suggest improvements"
173
+ ```
174
+
175
+ ### Edit a file with AI
176
+
177
+ ```bash
178
+ semalt-code edit index.js "Refactor duplicated logic into helper functions"
179
+ ```
180
+
181
+ ### Preview an edit without saving
182
+
183
+ ```bash
184
+ semalt-code edit index.js "Add better error handling" --dry-run
185
+ ```
186
+
187
+ ### Run and analyze a shell command
188
+
189
+ ```bash
190
+ semalt-code shell -a "npm test"
191
+ ```
192
+
193
+ ### List models
194
+
195
+ ```bash
196
+ semalt-code models
197
+ ```
198
+
199
+ ### Show the current version
200
+
201
+ ```bash
202
+ semalt-code --version
203
+ ```
204
+
205
+ ## How Responses Are Rendered
206
+
207
+ The CLI formats streamed output for terminal readability:
208
+
209
+ - headings
210
+ - bullet lists
211
+ - numbered lists
212
+ - fenced code blocks
213
+ - diff-like output
214
+ - inline code and file paths
215
+
216
+ If the backend returns `reasoning_content`, the CLI also shows a lightweight `thinking` section during streaming.
217
+
218
+ ## Notes and Limitations
219
+
220
+ - This project is currently a single-file CLI implementation centered in `index.js`.
221
+ - It uses Node's built-in `http` and `https` modules and does not require extra runtime dependencies.
222
+ - The `edit` command writes the model output directly back to the target file, so review prompts and backend behavior carefully.
223
+ - Shell and file operations are approval-based, but they still execute on the local system after approval.
224
+
225
+ ## License
226
+
227
+ MIT
package/index.js CHANGED
@@ -10,6 +10,8 @@ const http = require('http');
10
10
  const https = require('https');
11
11
  const { URL } = require('url');
12
12
 
13
+ const PACKAGE_JSON = require('./package.json');
14
+
13
15
  // ── Config ────────────────────────────────────────────────────────────────────
14
16
 
15
17
  const DEFAULT_CONFIG = {
@@ -1081,12 +1083,18 @@ Options:
1081
1083
  --api-base <url> API base URL (init)
1082
1084
  --api-key <key> API key (init)
1083
1085
  --default-model <name> Default model (init)
1086
+ -v, --version Show CLI version
1084
1087
 
1085
1088
  Config: ${CONFIG_PATH}
1086
1089
  `);
1087
1090
  return;
1088
1091
  }
1089
1092
 
1093
+ if (command === '--version' || command === '-v') {
1094
+ console.log(PACKAGE_JSON.version);
1095
+ return;
1096
+ }
1097
+
1090
1098
  if (command === 'chat') {
1091
1099
  const { opts } = parseArgs(rawArgs.slice(1));
1092
1100
  await cmdChat(opts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semalt-ai/code",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Self-hosted AI Coding Assistant CLI",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -9,7 +9,13 @@
9
9
  "scripts": {
10
10
  "start": "node index.js"
11
11
  },
12
- "keywords": ["ai", "coding", "assistant", "cli", "semalt"],
12
+ "keywords": [
13
+ "ai",
14
+ "coding",
15
+ "assistant",
16
+ "cli",
17
+ "semalt"
18
+ ],
13
19
  "author": "Semalt.AI",
14
20
  "license": "MIT",
15
21
  "engines": {