@semalt-ai/code 1.0.0 → 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.
Files changed (2) hide show
  1. package/README.md +218 -0
  2. package/package.json +8 -2
package/README.md ADDED
@@ -0,0 +1,218 @@
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
+ - `-f, --file <path>`
100
+ Load one or more files or directories into the prompt context for `code`.
101
+
102
+ - `-a, --analyze`
103
+ After `shell`, ask the model to summarize the command output.
104
+
105
+ - `--dry-run`
106
+ For `edit`, show the generated result without saving it.
107
+
108
+ - `--api-base <url>`
109
+ Set the API base URL during `init`.
110
+
111
+ - `--api-key <key>`
112
+ Set the API key during `init`.
113
+
114
+ - `--default-model <name>`
115
+ Set the default model during `init`.
116
+
117
+ ## Interactive Chat Mode
118
+
119
+ Running `semalt-code` without arguments starts the terminal chat UI.
120
+
121
+ Available interactive commands:
122
+
123
+ - `/help`
124
+ - `/file <path>`
125
+ - `/model <name>`
126
+ - `/clear`
127
+ - `/compact`
128
+ - `/cost`
129
+ - `/shell <cmd>`
130
+ - `!<cmd>`
131
+ - `/approve`
132
+ - `/config`
133
+ - `exit`
134
+
135
+ ### What `/file` does
136
+
137
+ - If you pass a file, its full content is added to the conversation context.
138
+ - If you pass a directory, the CLI recursively loads up to 50 non-hidden files.
139
+
140
+ ## Agent Behavior
141
+
142
+ The assistant is instructed to use special tool-like tags:
143
+
144
+ - `<exec>...</exec>` for shell commands
145
+ - `<read_file>...</read_file>` for file reads
146
+ - `<write_file path="...">...</write_file>` for file writes
147
+
148
+ When the model emits these actions, the CLI:
149
+
150
+ 1. Detects them in the response
151
+ 2. Prompts the user for approval
152
+ 3. Executes the action
153
+ 4. Sends the result back to the model
154
+ 5. Continues for up to 10 iterations
155
+
156
+ This makes the tool behave like a lightweight terminal agent while keeping the user in control.
157
+
158
+ ## Examples
159
+
160
+ ### Start chat
161
+
162
+ ```bash
163
+ semalt-code
164
+ ```
165
+
166
+ ### Ask for a coding task with file context
167
+
168
+ ```bash
169
+ semalt-code code -f package.json -f index.js "Explain this project and suggest improvements"
170
+ ```
171
+
172
+ ### Edit a file with AI
173
+
174
+ ```bash
175
+ semalt-code edit index.js "Refactor duplicated logic into helper functions"
176
+ ```
177
+
178
+ ### Preview an edit without saving
179
+
180
+ ```bash
181
+ semalt-code edit index.js "Add better error handling" --dry-run
182
+ ```
183
+
184
+ ### Run and analyze a shell command
185
+
186
+ ```bash
187
+ semalt-code shell -a "npm test"
188
+ ```
189
+
190
+ ### List models
191
+
192
+ ```bash
193
+ semalt-code models
194
+ ```
195
+
196
+ ## How Responses Are Rendered
197
+
198
+ The CLI formats streamed output for terminal readability:
199
+
200
+ - headings
201
+ - bullet lists
202
+ - numbered lists
203
+ - fenced code blocks
204
+ - diff-like output
205
+ - inline code and file paths
206
+
207
+ If the backend returns `reasoning_content`, the CLI also shows a lightweight `thinking` section during streaming.
208
+
209
+ ## Notes and Limitations
210
+
211
+ - This project is currently a single-file CLI implementation centered in `index.js`.
212
+ - It uses Node's built-in `http` and `https` modules and does not require extra runtime dependencies.
213
+ - The `edit` command writes the model output directly back to the target file, so review prompts and backend behavior carefully.
214
+ - Shell and file operations are approval-based, but they still execute on the local system after approval.
215
+
216
+ ## License
217
+
218
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semalt-ai/code",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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": {