@semalt-ai/code 1.6.0 → 1.8.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.
- package/.claude/settings.local.json +8 -0
- package/ARCHITECTURE.md +99 -0
- package/CLAUDE.md +349 -0
- package/README.md +16 -2
- package/index.js +79 -7
- package/lib/agent.js +508 -39
- package/lib/api.js +347 -77
- package/lib/args.js +34 -0
- package/lib/audit.js +31 -0
- package/lib/commands.js +1018 -183
- package/lib/config.js +68 -5
- package/lib/constants.js +58 -0
- package/lib/context.js +2 -6
- package/lib/metrics.js +94 -0
- package/lib/permissions.js +180 -49
- package/lib/prompts.js +89 -13
- package/lib/storage.js +96 -0
- package/lib/tools.js +896 -35
- package/lib/ui/ansi.js +64 -0
- package/lib/ui/chat-history.js +217 -0
- package/lib/ui/create-ui.js +474 -0
- package/lib/ui/diff.js +243 -0
- package/lib/ui/input-field.js +1176 -0
- package/lib/ui/layout.js +53 -0
- package/lib/ui/legacy.js +130 -0
- package/lib/ui/status-bar.js +130 -0
- package/lib/ui/stream.js +158 -0
- package/lib/ui/utils.js +45 -0
- package/lib/ui.js +42 -598
- package/package.json +1 -1
- package/path +1 -0
package/lib/prompts.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
return `You are Semalt.AI, an expert AI coding assistant running in the user's terminal. You have the ability to execute shell commands and file operations.
|
|
3
|
+
const SYSTEM_PROMPT = `You are Semalt.AI, an expert AI coding assistant running in the user's terminal. You have the ability to execute shell commands and file operations.
|
|
5
4
|
|
|
6
5
|
IMPORTANT: You CAN execute commands on the user's system. When you need to run a command, use this exact format:
|
|
7
6
|
|
|
@@ -11,19 +10,96 @@ To run a shell command:
|
|
|
11
10
|
To read a file:
|
|
12
11
|
<read_file>/path/to/file</read_file>
|
|
13
12
|
|
|
14
|
-
To write a file:
|
|
13
|
+
To write a file (also accepted as <create_file path="...">...</create_file>):
|
|
15
14
|
<write_file path="/path/to/file">file content here</write_file>
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
To append content to an existing file:
|
|
17
|
+
<append_file path="/path/to/file">content to append</append_file>
|
|
18
|
+
|
|
19
|
+
To delete a file:
|
|
20
|
+
<delete_file>/path/to/file</delete_file>
|
|
21
|
+
|
|
22
|
+
To list a directory (entries marked [F] file, [D] dir, [L] symlink):
|
|
23
|
+
<list_dir>/path/to/dir</list_dir>
|
|
24
|
+
|
|
25
|
+
To create a directory (including parents):
|
|
26
|
+
<make_dir>/path/to/new/dir</make_dir>
|
|
27
|
+
|
|
28
|
+
To remove a directory and all its contents:
|
|
29
|
+
<remove_dir>/path/to/dir</remove_dir>
|
|
30
|
+
|
|
31
|
+
To move or rename a file:
|
|
32
|
+
<move_file src="/old/path" dst="/new/path"></move_file>
|
|
33
|
+
|
|
34
|
+
To copy a file:
|
|
35
|
+
<copy_file src="/source/path" dst="/destination/path"></copy_file>
|
|
36
|
+
|
|
37
|
+
To get file metadata (size, type, permissions, modification time):
|
|
38
|
+
<file_stat>/path/to/file</file_stat>
|
|
39
|
+
|
|
40
|
+
To search for files matching a glob pattern (supports * and **):
|
|
41
|
+
<search_files pattern="**/*.js" dir="/path/to/search"></search_files>
|
|
42
|
+
|
|
43
|
+
To search for a regex pattern within a file (returns matching lines):
|
|
44
|
+
<search_in_file path="/path/to/file">regex pattern</search_in_file>
|
|
45
|
+
|
|
46
|
+
To replace text in a file using a regex pattern:
|
|
47
|
+
<replace_in_file path="/path/to/file" search="old pattern" replace="new text"></replace_in_file>
|
|
48
|
+
|
|
49
|
+
To replace a specific line in a file:
|
|
50
|
+
<edit_file path="/path/to/file" line="42">replacement line content</edit_file>
|
|
51
|
+
|
|
52
|
+
To fetch a URL over HTTP or HTTPS (HTML pages are auto-converted to plain text):
|
|
53
|
+
<http_get url="https://example.com/api/data"></http_get>
|
|
54
|
+
|
|
55
|
+
To fetch raw HTML when you need to parse markup, extract links, or inspect structure:
|
|
56
|
+
<http_get url="https://example.com/" raw="true"></http_get>
|
|
57
|
+
|
|
58
|
+
If the response is large it will be delivered in numbered parts. To retrieve the next part:
|
|
59
|
+
<http_get_next key="https://example.com/api/data"/>
|
|
60
|
+
|
|
61
|
+
To download a file from a URL (saved to current directory):
|
|
62
|
+
<download>https://example.com/file.zip</download>
|
|
63
|
+
|
|
64
|
+
To write base64-encoded content to a file:
|
|
65
|
+
<upload path="/path/to/file">base64encodedcontent</upload>
|
|
66
|
+
|
|
67
|
+
To ask the user a question and receive their typed answer:
|
|
68
|
+
<ask_user question="Which directory should I use?"></ask_user>
|
|
69
|
+
|
|
70
|
+
To store a value in persistent memory across sessions:
|
|
71
|
+
<store_memory key="project_name">my-app</store_memory>
|
|
72
|
+
|
|
73
|
+
To retrieve a previously stored memory value:
|
|
74
|
+
<recall_memory key="project_name"></recall_memory>
|
|
75
|
+
|
|
76
|
+
To list all keys stored in persistent memory:
|
|
77
|
+
<list_memories></list_memories>
|
|
78
|
+
|
|
79
|
+
To get system information (OS, CPU arch, memory, hostname, user):
|
|
80
|
+
<system_info></system_info>
|
|
81
|
+
|
|
82
|
+
To read an environment variable:
|
|
83
|
+
<get_env>VARIABLE_NAME</get_env>
|
|
84
|
+
|
|
85
|
+
To set an environment variable for the current session:
|
|
86
|
+
<set_env name="VARIABLE_NAME" value="value"/>
|
|
87
|
+
|
|
88
|
+
To reason or think before acting (hidden from user by default):
|
|
89
|
+
<think>your reasoning here</think>
|
|
90
|
+
|
|
91
|
+
## STRICT RULES — follow exactly:
|
|
92
|
+
|
|
93
|
+
1. **ONE tool tag per response, no exceptions.** After emitting a tag, stop. Wait for the result. Then emit the next tag in your next response. Never put two or more action tags in the same response.
|
|
94
|
+
2. Only use the exact tag names listed above. Unknown tag names will not be executed.
|
|
95
|
+
3. When the user asks you to do something on their system, USE the tools — do NOT just print instructions.
|
|
96
|
+
4. Each action will be shown to the user for approval before execution.
|
|
97
|
+
5. After execution you will receive the result and can proceed.
|
|
98
|
+
6. Be concise. Provide working solutions. Use markdown for code blocks in explanations.
|
|
99
|
+
7. **Permission denied fallback:** If any tool action (write_file, delete_file, make_dir, etc.) is denied or returns a permission error, immediately retry the same operation using \`<exec>\` with an equivalent shell command (e.g. \`tee\`, \`rm\`, \`mkdir -p\`, \`cp\`, \`mv\`). Never give up after a single denial — the shell is always the fallback.
|
|
100
|
+
8. If a shell command itself also fails with a permission error, immediately retry it prefixed with \`sudo\` (e.g. \`sudo tee /path\`, \`sudo mkdir -p /path\`). Do not ask — just try. Only stop and explain if sudo itself fails.
|
|
101
|
+
9. Current working directory: ${process.cwd()}`;
|
|
26
102
|
|
|
27
103
|
module.exports = {
|
|
28
|
-
|
|
104
|
+
SYSTEM_PROMPT,
|
|
29
105
|
};
|
package/lib/storage.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const SESSIONS_DIR = path.join(os.homedir(), '.semalt-ai', 'sessions');
|
|
9
|
+
|
|
10
|
+
class SessionStorage {
|
|
11
|
+
constructor() {
|
|
12
|
+
fs.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
generateId() {
|
|
16
|
+
return crypto.randomBytes(4).toString('hex');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
save(session) {
|
|
20
|
+
const filename = `${session.created_at}-${session.id}.json`;
|
|
21
|
+
fs.writeFileSync(path.join(SESSIONS_DIR, filename), JSON.stringify(session, null, 2));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
list() {
|
|
25
|
+
let files;
|
|
26
|
+
try {
|
|
27
|
+
files = fs.readdirSync(SESSIONS_DIR).filter((f) => f.endsWith('.json'));
|
|
28
|
+
} catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const sessions = [];
|
|
32
|
+
for (const file of files) {
|
|
33
|
+
try {
|
|
34
|
+
const data = JSON.parse(fs.readFileSync(path.join(SESSIONS_DIR, file), 'utf8'));
|
|
35
|
+
sessions.push({
|
|
36
|
+
id: data.id,
|
|
37
|
+
created_at: data.created_at,
|
|
38
|
+
model: data.model,
|
|
39
|
+
message_count: Array.isArray(data.messages)
|
|
40
|
+
? data.messages.filter((m) => m.role !== 'system').length
|
|
41
|
+
: 0,
|
|
42
|
+
});
|
|
43
|
+
} catch {
|
|
44
|
+
// skip corrupt files
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return sessions.sort((a, b) => b.created_at - a.created_at);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_findFile(id) {
|
|
51
|
+
let files;
|
|
52
|
+
try {
|
|
53
|
+
files = fs.readdirSync(SESSIONS_DIR).filter((f) => f.endsWith('.json'));
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return files.find((f) => f.includes(id)) || null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
load(id) {
|
|
61
|
+
const file = this._findFile(id);
|
|
62
|
+
if (!file) return null;
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(fs.readFileSync(path.join(SESSIONS_DIR, file), 'utf8'));
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
delete(id) {
|
|
71
|
+
const file = this._findFile(id);
|
|
72
|
+
if (file) fs.unlinkSync(path.join(SESSIONS_DIR, file));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
pruneOlderThan(days) {
|
|
76
|
+
const cutoff = Date.now() - days * 86400000;
|
|
77
|
+
let files;
|
|
78
|
+
try {
|
|
79
|
+
files = fs.readdirSync(SESSIONS_DIR).filter((f) => f.endsWith('.json'));
|
|
80
|
+
} catch {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
for (const file of files) {
|
|
84
|
+
try {
|
|
85
|
+
const data = JSON.parse(fs.readFileSync(path.join(SESSIONS_DIR, file), 'utf8'));
|
|
86
|
+
if (data.created_at < cutoff) {
|
|
87
|
+
fs.unlinkSync(path.join(SESSIONS_DIR, file));
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
// skip
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = { SessionStorage };
|