feat: 升级至 v0.2.2 — 工作空间路径注入、Provider 切换修复、编码与样式优化

功能增强:
- System Prompt 注入当前工作空间路径到动态区(LLM 可使用绝对路径调用工具)
- ContextBuilder.buildSystemPrompt 新增 workspacePath 参数

Provider 切换修复:
- reloadAdapter 返回 boolean,失败时 sendMessage 中止发送
- 切换 Provider 时自动清空 apiKey(不同 Provider key 不通用)
- apiKey 为空时显示警告提示
- Provider 切换事件加 sessionId 字段

编码修复:
- run_command 使用 encoding: 'buffer' 获取原始字节
- 新增 decodeBuffer 智能解码:UTF-8 严格 → GBK → UTF-8 宽松
- 修复不响应 chcp 的 Windows 命令中文乱码问题

样式优化:
- 代码块底色改用主题变量(灰底主题色文字,双主题适配)
- 表格标题 th/td 底色和文字色改用主题变量
- CodeBlock 组件 pre 背景从 secondary.main 改为 background.default
- 设置面板已自动执行工具行 opacity 0.8→0.15(淡绿底,文字清晰)

版本号 0.2.1 → 0.2.2
This commit is contained in:
thzxx
2026-07-12 13:46:09 +08:00
parent 6e49c44742
commit aa13a98f63
9 changed files with 96 additions and 32 deletions
+28 -5
View File
@@ -24,6 +24,26 @@ import type { SandboxManager } from '../../sandbox/sandbox';
const execAsync = promisify(exec);
// ===== Windows 编码智能解码 =====
// 某些 Windows 程序(dir、systeminfo、ipconfig 等)不响应 chcp 65001
// 仍按系统代码页(GBK/CP936)输出字节流。
// 策略:先尝试严格 UTF-8 解码,失败则用 GBK 解码,最后降级为 UTF-8 宽松模式。
function decodeBuffer(buf: Buffer): string {
if (buf.length === 0) return '';
try {
// 严格模式:包含非法 UTF-8 字节序列时抛错
return new TextDecoder('utf-8', { fatal: true }).decode(buf);
} catch {
// UTF-8 解码失败 → 用 GBK/CP936 解码(Windows 中文系统默认代码页)
try {
return new TextDecoder('gbk').decode(buf);
} catch {
// 最终降级:UTF-8 宽松模式(用 替换字符 代替非法字节)
return buf.toString('utf-8');
}
}
}
// ===== 9. run_command =====
export class RunCommandTool implements IMetonaTool {
@@ -100,10 +120,13 @@ export class RunCommandTool implements IMetonaTool {
? `chcp 65001 >nul 2>&1 && ${command}`
: command;
// 使用 encoding: 'buffer' 获取原始字节,手动智能解码
// 部分程序(如 dir、systeminfo)不响应 chcp 65001,仍输出 GBK 字节流
const { stdout, stderr } = await execAsync(finalCommand, {
cwd: resolvedWorkdir,
timeout,
maxBuffer: 1024 * 1024, // 1MB
encoding: 'buffer', // 返回 Buffer 而非字符串,便于智能解码
env: {
...process.env,
NODE_ENV: 'production',
@@ -118,18 +141,18 @@ export class RunCommandTool implements IMetonaTool {
return {
success: true,
stdout: stdout.slice(0, 50_000),
stderr: stderr.slice(0, 10_000),
stdout: decodeBuffer(stdout).slice(0, 50_000),
stderr: decodeBuffer(stderr).slice(0, 10_000),
command,
};
} catch (error) {
const err = error as { message: string; code?: number; stdout?: string; stderr?: string };
const err = error as { message: string; code?: number; stdout?: Buffer; stderr?: Buffer };
return {
success: false,
error: err.message,
exit_code: err.code,
stdout: (err.stdout ?? '').slice(0, 10_000),
stderr: (err.stderr ?? '').slice(0, 10_000),
stdout: decodeBuffer(err.stdout ?? Buffer.alloc(0)).slice(0, 10_000),
stderr: decodeBuffer(err.stderr ?? Buffer.alloc(0)).slice(0, 10_000),
command,
};
}