@fefeding/aicmd 0.1.2 → 0.1.3
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/README.md +22 -0
- package/README.zh.md +22 -0
- package/bin/aicmd.js +67 -4
- package/dist/node_modules/.pnpm-workspace-state-v1.json +1 -1
- package/dist/package.json +11 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -195,9 +195,31 @@ All data is stored locally on the server:
|
|
|
195
195
|
| AI Config | `~/.aicmd/ai-config.json` |
|
|
196
196
|
| Chat History | `~/.aicmd/ai-history/` |
|
|
197
197
|
| User Skills | `~/.aicmd/skills/*.md` |
|
|
198
|
+
| Trash Bin | `~/.aicmd/.trash/` |
|
|
198
199
|
|
|
199
200
|
Use `AICMD_DATA_DIR` environment variable to override the data directory.
|
|
200
201
|
|
|
202
|
+
## Safety Mechanisms
|
|
203
|
+
|
|
204
|
+
The AI agent includes built-in command-level safety protections to reduce the risk of destructive operations:
|
|
205
|
+
|
|
206
|
+
### Delete Protection (Trash Bin)
|
|
207
|
+
- All `rm` commands (Linux/macOS) are automatically rewritten to `mv` into `~/.aicmd/.trash/` instead of permanent deletion.
|
|
208
|
+
- Windows `Remove-Item`/`del`/`rd` commands are similarly rewritten to `Move-Item` into `%USERPROFILE%\.aicmd\.trash\`.
|
|
209
|
+
- Trashed files are timestamped (e.g. `_del_1716000000_filename`) to avoid naming conflicts.
|
|
210
|
+
- To recover a file, simply browse the trash directory and move it back.
|
|
211
|
+
|
|
212
|
+
### Dangerous Operation Blocking
|
|
213
|
+
The following irreversible, destructive operations are blocked entirely:
|
|
214
|
+
|
|
215
|
+
| Platform | Blocked Operations |
|
|
216
|
+
|----------|-------------------|
|
|
217
|
+
| Linux/macOS | `rm -rf /`, `mkfs.*` (disk formatting), `dd of=/dev/sd*` (disk overwrite), fork bombs |
|
|
218
|
+
| Windows | `format C:`, `Clear-Disk`, `Remove-Item C:\`, `rd /s C:\` |
|
|
219
|
+
|
|
220
|
+
### Platform Awareness
|
|
221
|
+
The safety layer automatically detects the target session's OS (via systemContext) and applies the appropriate Unix or Windows rules — no manual configuration required.
|
|
222
|
+
|
|
201
223
|
## Cross-Platform Support
|
|
202
224
|
|
|
203
225
|
The terminal and AI agent work on:
|
package/README.zh.md
CHANGED
|
@@ -195,9 +195,31 @@ tags: [deploy, ops]
|
|
|
195
195
|
| AI 配置 | `~/.aicmd/ai-config.json` |
|
|
196
196
|
| 对话历史 | `~/.aicmd/ai-history/` |
|
|
197
197
|
| 用户 Skills | `~/.aicmd/skills/*.md` |
|
|
198
|
+
| 回收站 | `~/.aicmd/.trash/` |
|
|
198
199
|
|
|
199
200
|
可通过 `AICMD_DATA_DIR` 环境变量自定义数据目录。
|
|
200
201
|
|
|
202
|
+
## 安全机制
|
|
203
|
+
|
|
204
|
+
AI Agent 内置了命令级安全防护,降低误操作风险:
|
|
205
|
+
|
|
206
|
+
### 删除保护(回收站)
|
|
207
|
+
- 所有 `rm` 命令(Linux/macOS)自动改写为 `mv` 到 `~/.aicmd/.trash/`,而非永久删除
|
|
208
|
+
- Windows 的 `Remove-Item`/`del`/`rd` 同样改写为 `Move-Item` 到 `%USERPROFILE%\.aicmd\.trash\`
|
|
209
|
+
- 回收站文件带时间戳命名(如 `_del_1716000000_filename`),不会冲突
|
|
210
|
+
- 需要恢复时,直接到回收站目录找回即可
|
|
211
|
+
|
|
212
|
+
### 危险操作阻止
|
|
213
|
+
以下不可恢复的破坏性操作会被直接阻止执行:
|
|
214
|
+
|
|
215
|
+
| 平台 | 被阻止的操作 |
|
|
216
|
+
|------|-------------|
|
|
217
|
+
| Linux/macOS | `rm -rf /`、`mkfs.*` 格式化磁盘、`dd of=/dev/sd*` 覆写磁盘、Fork bomb |
|
|
218
|
+
| Windows | `format C:`、`Clear-Disk`、`Remove-Item C:\`、`rd /s C:\` |
|
|
219
|
+
|
|
220
|
+
### 平台感知
|
|
221
|
+
安全防护自动检测目标会话的操作系统(通过 systemContext),分别应用 Unix 或 Windows 规则,无需手动配置。
|
|
222
|
+
|
|
201
223
|
## 跨平台支持
|
|
202
224
|
|
|
203
225
|
终端和 AI Agent 支持以下平台:
|
package/bin/aicmd.js
CHANGED
|
@@ -8,11 +8,53 @@ const os = require('os');
|
|
|
8
8
|
|
|
9
9
|
const projectRoot = path.resolve(__dirname, '..');
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* 递归修复目录及所有文件权限:目录 755,文件 644
|
|
13
|
+
*/
|
|
14
|
+
function fixPermissions(dir) {
|
|
15
|
+
try {
|
|
16
|
+
fs.chmodSync(dir, 0o755);
|
|
17
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
const fullPath = path.join(dir, entry.name);
|
|
20
|
+
try {
|
|
21
|
+
if (entry.isDirectory()) {
|
|
22
|
+
fixPermissions(fullPath);
|
|
23
|
+
} else {
|
|
24
|
+
fs.chmodSync(fullPath, 0o644);
|
|
25
|
+
}
|
|
26
|
+
} catch { /* 单个文件失败不影响其他 */ }
|
|
27
|
+
}
|
|
28
|
+
} catch { /* ignore */ }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function ensureDataDir() {
|
|
12
32
|
const dataDir = process.env.AICMD_DATA_DIR || path.join(os.homedir(), '.aicmd');
|
|
13
|
-
|
|
14
|
-
fs.
|
|
33
|
+
try {
|
|
34
|
+
if (!fs.existsSync(dataDir)) {
|
|
35
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
36
|
+
} else {
|
|
37
|
+
// 确保整个数据目录可写,递归修复权限
|
|
38
|
+
try {
|
|
39
|
+
fs.accessSync(dataDir, fs.constants.W_OK);
|
|
40
|
+
} catch {
|
|
41
|
+
fixPermissions(dataDir);
|
|
42
|
+
// 再次检查
|
|
43
|
+
try { fs.accessSync(dataDir, fs.constants.W_OK); } catch {
|
|
44
|
+
throw new Error(`Permission denied even after chmod: ${dataDir}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.error(`Cannot access data directory ${dataDir}: ${e.message}`);
|
|
50
|
+
console.error('Try: sudo chown -R $(whoami) ' + dataDir);
|
|
51
|
+
process.exit(1);
|
|
15
52
|
}
|
|
53
|
+
return dataDir;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getPidFilePath() {
|
|
57
|
+
const dataDir = ensureDataDir();
|
|
16
58
|
return path.join(dataDir, 'aicmd.server.pid');
|
|
17
59
|
}
|
|
18
60
|
|
|
@@ -26,7 +68,19 @@ function readPid() {
|
|
|
26
68
|
|
|
27
69
|
function writePid(pid) {
|
|
28
70
|
const pidFilePath = getPidFilePath();
|
|
29
|
-
|
|
71
|
+
try {
|
|
72
|
+
fs.writeFileSync(pidFilePath, pid.toString());
|
|
73
|
+
} catch (e) {
|
|
74
|
+
// 尝试修复权限后重试
|
|
75
|
+
try { fs.chmodSync(pidFilePath, 0o644); } catch { /* ignore */ }
|
|
76
|
+
try {
|
|
77
|
+
fs.writeFileSync(pidFilePath, pid.toString());
|
|
78
|
+
} catch (e2) {
|
|
79
|
+
console.error(`Cannot write PID file ${pidFilePath}: ${e2.message}`);
|
|
80
|
+
console.error('Try: sudo chown -R $(whoami) ' + path.dirname(pidFilePath));
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
30
84
|
}
|
|
31
85
|
|
|
32
86
|
function deletePid() {
|
|
@@ -114,6 +168,7 @@ async function startProject() {
|
|
|
114
168
|
|
|
115
169
|
console.log('Server started with PID:', child.pid);
|
|
116
170
|
console.log(`aicmd is running at http://localhost:${port}`);
|
|
171
|
+
openBrowser(`http://localhost:${port}`);
|
|
117
172
|
}
|
|
118
173
|
|
|
119
174
|
function stopProject() {
|
|
@@ -145,6 +200,14 @@ function restartProject() {
|
|
|
145
200
|
startProject();
|
|
146
201
|
}
|
|
147
202
|
|
|
203
|
+
function openBrowser(url) {
|
|
204
|
+
const platform = process.platform;
|
|
205
|
+
const cmd = platform === 'darwin' ? 'open' : platform === 'win32' ? 'start' : 'xdg-open';
|
|
206
|
+
const args = platform === 'win32' ? ['', url] : [url];
|
|
207
|
+
const proc = spawn(cmd, args, { detached: true, stdio: 'ignore', shell: platform === 'win32' });
|
|
208
|
+
proc.unref();
|
|
209
|
+
}
|
|
210
|
+
|
|
148
211
|
function showVersion() {
|
|
149
212
|
const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
150
213
|
console.log(pkg.version);
|
package/dist/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@fefeding/
|
|
3
|
-
"version": "0.1.
|
|
2
|
+
"name": "@fefeding/aicmd",
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "AI-powered web SSH terminal with autonomous agent, skills, and file transfer",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://
|
|
9
|
+
"url": "https://github.com/fefeding/ai-cmd"
|
|
10
10
|
},
|
|
11
11
|
"main": "view/index.html",
|
|
12
12
|
"files": [
|
|
@@ -14,14 +14,15 @@
|
|
|
14
14
|
"public/",
|
|
15
15
|
"view/",
|
|
16
16
|
"dist/",
|
|
17
|
-
"
|
|
17
|
+
"data/skills",
|
|
18
|
+
"patches",
|
|
18
19
|
"server.js",
|
|
19
20
|
"package.json",
|
|
20
21
|
"README.md"
|
|
21
22
|
],
|
|
22
23
|
"icon": "public/favicon.ico",
|
|
23
24
|
"window": {
|
|
24
|
-
"title": "
|
|
25
|
+
"title": "AICmd - AI Terminal",
|
|
25
26
|
"width": 1200,
|
|
26
27
|
"height": 800,
|
|
27
28
|
"min_width": 800,
|
|
@@ -32,9 +33,9 @@
|
|
|
32
33
|
"icon": "public/favicon.ico"
|
|
33
34
|
},
|
|
34
35
|
"scripts": {
|
|
35
|
-
"start": "pm2 start server.js --name
|
|
36
|
-
"restart": "pm2 restart
|
|
37
|
-
"stop": "pm2 stop
|
|
36
|
+
"start": "pm2 start server.js --name aicmd-server --disable-logs --",
|
|
37
|
+
"restart": "pm2 restart aicmd-server --disable-logs --",
|
|
38
|
+
"stop": "pm2 stop aicmd-server --",
|
|
38
39
|
"dev": "vite",
|
|
39
40
|
"build": "npm run build-only",
|
|
40
41
|
"preview": "vite preview",
|
|
@@ -104,7 +105,7 @@
|
|
|
104
105
|
"zmodem.js": "^0.1.10"
|
|
105
106
|
},
|
|
106
107
|
"bin": {
|
|
107
|
-
"
|
|
108
|
+
"aicmd": "bin/aicmd.js"
|
|
108
109
|
},
|
|
109
110
|
"pnpm": {
|
|
110
111
|
"onlyBuiltDependencies": [
|