DSH Java Native Plugin 独立 AI 产品系列 #14。Shell 命令起草间:一句话 → 命令草稿(带解释/风险标注)、命令解释、危险命令审计、历史命令安全复盘、单行脚本速查。
独立 AI 产品:整个应用就是命令工作台。AI 与右侧工作台共享同一套工具能力,可起草/解释/审计任意 shell 命令。
| 能力 | 说明 |
|---|---|
| 意图起草 | 14 类意图模板(查找/磁盘/日志/端口/压缩/备份/权限/网络/git/docker/systemd…)→ 命令骨架 + 占位符 + 解释 + 风险 |
| 命令解释 | 管道分段、每段程序用途、选项含义、参数、重定向检测,附危险扫描 |
| 风险审计 | 12 类高危模式:rm -rf / sudo / mkfs·dd / chmod 777 / curl|sh / >块设备 / git push --force / kill -9 / drop table / shutdown / history -c / export 凭证 |
| 历史复盘 | 粘贴 history 批量审计:危险清单(等级+原因+替代方案)+ 最常用程序 Top10 |
| 速查库 | 5 类单行脚本(文件查找/文本统计/压缩解压/网络排查/进程管理) |
工具前缀:plugin__dsh-java-shell-plugin__shell_
shell_draft(intent)— 一句话 → 命令草稿shell_explain(command)— 解析命令组成shell_risk_check(command)— 危险命令审计shell_history_audit(historyText)— 批量历史审计shell_one_liner(category)— 单行脚本速查
- 只起草,绝不执行 —— 所有工具只做文本分析与生成,无任何进程执行通道。
- critical 级命令(rm -rf、curl|sh、dd 写设备、drop table)不给"绕过检查"的变体,只给更安全的等价改写。
- systemPrompt + PRE_TOOL_USE hook 双重约束:命令含疑似密钥时不在回答中明文复述。
- 未命中模板时明确拒绝臆造命令(返回
matched=false,不生成 command)。
dsh-java-shell/
├── dsh-java-shell-app/ # Spring Boot 应用 (port 8100)
│ ├── controller/ # REST: /api/shell/* + /api/assistant/stream (SSE)
│ ├── service/ # ShellScribeService(模板起草/解析/风险/审计/速查)
│ └── static/ # 前端(起草/解释/风险/速查库 四工作台 + AI 对话)
└── dsh-java-shell-plugin/ # Java Native Plugin(5 个 shell_* 工具)
mvn package -DskipTests
SERVER__PORT= java -jar dsh-java-shell-app/target/dsh-java-shell-app-0.1.0-SNAPSHOT.jar --server.port=8100
cp dsh-java-shell-plugin/target/dsh-java-shell-plugin-0.1.0-SNAPSHOT.jar ~/.dsh/standalone/plugins/dsh-java-shell-plugin.jar
curl -X POST http://127.0.0.1:8090/api/harness/plugins/install -H 'Content-Type: application/json' \
-d '{"pluginId":"dsh-java-shell-plugin","jarName":"dsh-java-shell-plugin.jar","displayName":"DSH ShellScribe Plugin","pluginVersion":"0.1.0","runtimeType":"JAVA_NATIVE","sourcePath":"'"$HOME"'/.dsh/standalone/plugins/dsh-java-shell-plugin.jar","entrypoint":"cn.xiaofuge.dsh.shell.plugin.DshShellScribePlugin","installMode":"REPLACE"}'
curl -X POST http://127.0.0.1:8090/api/harness/plugins/activate -H 'Content-Type: application/json' \
-d '{"pluginId":"dsh-java-shell-plugin"}'
python3 shell_scribe_e2e.py # 8/8 PASS- T0 起草:磁盘意图 → du 命令 + 占位符 + 风险
- T1 解释:
du | sort | head→ 3 管道段 + 危险扫描 - T2 风险:
rm -rf $BUILD_DIR/→ critical + 替代建议 - T3 历史审计:6 条命令 → 危险 4 / critical 2
- T4 速查库:5 类齐全 + 单类过滤
- T5 未命中模板拒绝臆造(
matched=false,无 command 字段) - T6 AI 走 SSE 调用
shell_draft/shell_explain起草命令 - T7 安全红线:用户要求"直接 rm -rf 不用检查"→ AI 先 risk_check 并给警告与替代方案
screenshots/01-home.png— 主界面(起草工作台)screenshots/02-ai-drawer.png— AI 起草找大文件命令并解释风险screenshots/03-safety.png— 历史审计:6 条命令危险 4 条(critical 2)逐条标注