豆包复刻:原生安卓(Compose + 内嵌 Termux)+ Web / Windows

一个界面照着豆包抠的 AI 助手。主力是安卓端,完全离线自主:不依赖电脑、
不需要另外装 Termux。

安卓端
- 原生 Jetpack Compose,7 个页面,配色/圆角/间距对着真机截图量出来的
- 完整动效:抽屉滑入、页面切换、气泡淡入上移、面板底部升起、typing 三点、按钮回弹
- 内置 Termux:bash/apt/pkg 388 个命令、真 pty 终端;
  pty 不可用的 ROM 上自动降级成命令控制台
- APK 内嵌 CPython 3.13(Chaquopy),AI 内核跑在手机上
- 设备能力:定位 / 陀螺仪 / 加速度计 / 光线 / 电量 / 剪贴板
- 语音:朗读 + 语音输入,火山豆包音色 / OpenAI 兼容 / 设备自带三级引擎

AI 能力
- 10 家 OpenAI 兼容提供商:方舟 / OpenAI / DeepSeek / Kimi / 智谱 /
  通义 / 硅基流动 / OpenRouter / 本地 Ollama / 自定义
- 思考强度按各家支持情况发不同字段(thinking / reasoning_effort / 不发),
  认不出来的一律不发,避免给不支持的厂商发字段直接 400
- MCP 三种传输(http / stdio / inproc)、工具热加载、文件上传、权限模式

跨端
- 安卓走原生 Compose,Web / Windows 走 Lynx
- Node 与 Python 两份内核接口逐字段一致,关键路径都有对拍脚本

自检脚本(都不需要真 Key)
- verify-phone.mjs          设备端 24 项验收
- verify-speech.mjs         语音链路 31 项,两份内核各跑一遍
- parity-thinking.mjs       思考强度映射对拍
- probe-settings-wipe.mjs   设置防清空攻击测试
- mock-llm.mjs              假的 OpenAI + 火山语音服务

许可 MIT;第三方组件(Termux Apache-2.0、Chaquopy、Compose、LynxJS、Electron)
的授权见 LICENSE。
This commit is contained in:
l
2026-10-09 14:09:36 +08:00
commit f056bcf45a
308 changed files with 46874 additions and 0 deletions

179
scripts/build-exe.mjs Normal file
View File

@@ -0,0 +1,179 @@
/**
* 打包 Windows 桌面版(Electron)。
*
* ⚠️ 一个必须知道的坑:Electron 的 exe 放在**非 ASCII 目录**下会在启动时崩溃(0xC0000005),
* 所以输出目录固定用纯英文路径,工作区里的中文目录不能直接放 exe。
* exe 的**文件名**可以是中文,这个没问题。
*
* 用法: node scripts/build-exe.mjs [--skip-build] [--out D:\some\ascii\dir]
*/
import { spawnSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const here = path.dirname(fileURLToPath(import.meta.url));
const repo = path.resolve(here, '..');
const desktopDir = path.join(repo, 'desktop');
const staging = path.join(desktopDir, 'dist-staging');
const args = process.argv.slice(2);
const skipBuild = args.includes('--skip-build');
const outIndex = args.indexOf('--out');
const OUT_DIR = outIndex >= 0 && args[outIndex + 1]
? path.resolve(args[outIndex + 1])
: 'C:\\Users\\Administrator\\Documents\\DoubaoClone';
const APP_NAME = 'Doubao'; // 必须 ASCII:决定输出文件夹名
const EXE_NAME = '\u8c46\u5305.exe'; // 豆包.exe:文件名可以是中文
const version = JSON.parse(fs.readFileSync(path.join(desktopDir, 'package.json'), 'utf8')).version;
function log(msg) {
console.log(`[build-exe] ${msg}`);
}
function run(cmd, argv, opts = {}) {
const res = spawnSync(cmd, argv, { stdio: 'inherit', shell: true, ...opts });
if (res.status !== 0) throw new Error(`${cmd} ${argv.join(' ')} 退出码 ${res.status}`);
}
function rm(target) {
fs.rmSync(target, { recursive: true, force: true });
}
function copy(from, to, filter) {
if (!fs.existsSync(from)) throw new Error(`缺少 ${from}`);
fs.cpSync(from, to, { recursive: true, filter });
}
/* ------------------------------ 1. 构建界面 ------------------------------ */
if (!skipBuild) {
log('构建 Lynx 界面产物…');
run('npm', ['--prefix', 'app', 'run', 'build'], { cwd: repo });
}
/* ------------------------------ 2. 准备暂存目录 ------------------------------ */
log('准备暂存目录…');
rm(staging);
fs.mkdirSync(staging, { recursive: true });
// 2.1 Electron 主进程 + package.json
fs.copyFileSync(path.join(desktopDir, 'main.cjs'), path.join(staging, 'main.cjs'));
fs.mkdirSync(path.join(staging, 'build'), { recursive: true });
for (const f of ['icon.ico', 'icon.png']) {
const src = path.join(desktopDir, 'build', f);
if (fs.existsSync(src)) fs.copyFileSync(src, path.join(staging, 'build', f));
}
fs.writeFileSync(
path.join(staging, 'package.json'),
JSON.stringify(
{
name: 'doubao-desktop',
productName: APP_NAME, // 用 ASCII:%APPDATA% 下的数据目录也跟着是英文,稳妥
version,
description: '\u8c46\u5305 \u00b7 LynxJS \u590d\u523b\uff08\u684c\u9762\u7248\uff09',
main: 'main.cjs',
},
null,
2,
),
'utf8',
);
// 2.2 AI 内核(源码 + 依赖)
log('复制 AI 内核…');
fs.mkdirSync(path.join(staging, 'server'), { recursive: true });
copy(path.join(repo, 'server', 'src'), path.join(staging, 'server', 'src'));
if (fs.existsSync(path.join(repo, 'server', 'config'))) {
copy(path.join(repo, 'server', 'config'), path.join(staging, 'server', 'config'));
}
fs.copyFileSync(path.join(repo, 'server', 'package.json'), path.join(staging, 'server', 'package.json'));
copy(path.join(repo, 'server', 'node_modules'), path.join(staging, 'server', 'node_modules'));
// 2.3 运行时资源:Lynx 产物 / 宿主页 / web-core / python 工具
log('复制运行时资源…');
const runtime = path.join(staging, 'runtime');
fs.mkdirSync(runtime, { recursive: true });
copy(path.join(repo, 'app', 'dist'), path.join(runtime, 'app', 'dist'));
copy(path.join(repo, 'web'), path.join(runtime, 'web'));
copy(
path.join(repo, 'app', 'node_modules', '@lynx-js', 'web-core', 'dist', 'client_prod', 'static'),
path.join(runtime, 'web-core'),
);
copy(path.join(repo, 'tools'), path.join(runtime, 'tools'), (src) => !src.includes('__pycache__'));
// 2.4 打包版 MCP 配置:文件系统服务的目录指向数据目录,用占位符避免写死路径
const mcpPath = path.join(runtime, 'tools', 'mcp.servers.json');
if (fs.existsSync(mcpPath)) {
const conf = JSON.parse(fs.readFileSync(mcpPath, 'utf8'));
conf.servers = (conf.servers || []).map((s) =>
s.name === 'filesystem'
? { ...s, enabled: true, args: ['-y', '@modelcontextprotocol/server-filesystem', '${DOUBAO_DATA}'] }
: s);
fs.writeFileSync(mcpPath, JSON.stringify(conf, null, 2), 'utf8');
}
/* ------------------------------ 3. 调 electron-packager ------------------------------ */
log(`打包到 ${OUT_DIR} …`);
const packager = path.join(desktopDir, 'node_modules', '.bin', 'electron-packager.cmd');
if (!fs.existsSync(packager)) throw new Error('没找到 electron-packager,先在 desktop/ 里 npm install');
fs.mkdirSync(OUT_DIR, { recursive: true });
run(packager, [
`"${staging}"`,
APP_NAME,
'--platform=win32',
'--arch=x64',
'--out', `"${OUT_DIR}"`,
'--overwrite',
// packager 默认会打成 app.asar,这里关掉:明文目录路径透明,出问题好排查
'--asar=false',
'--prune=true',
'--icon', `"${path.join(desktopDir, 'build', 'icon.ico')}"`,
`--app-version=${version}`,
'--build-version', version,
'--win32metadata.CompanyName=DoubaoClone',
`--win32metadata.ProductName=${APP_NAME}`,
'--win32metadata.FileDescription=Doubao for Windows',
], {
cwd: desktopDir,
env: {
...process.env,
ELECTRON_MIRROR: process.env.ELECTRON_MIRROR || 'https://npmmirror.com/mirrors/electron/',
ELECTRON_CUSTOM_DIR: process.env.ELECTRON_CUSTOM_DIR || '{{ version }}',
},
});
/* ------------------------------ 4. 收尾 ------------------------------ */
const appDir = path.join(OUT_DIR, `${APP_NAME}-win32-x64`);
const exePath = path.join(appDir, `${APP_NAME}.exe`);
if (!fs.existsSync(exePath)) throw new Error(`打包产物里没找到 ${exePath}`);
const cnExe = path.join(appDir, EXE_NAME);
if (cnExe !== exePath) {
if (fs.existsSync(cnExe)) rm(cnExe);
fs.renameSync(exePath, cnExe);
}
rm(staging);
log('完成 ✅');
const totalBytes = (() => {
let sum = 0;
const walk = (dir) => {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) walk(full);
else sum += fs.statSync(full).size;
}
};
walk(appDir);
return sum;
})();
console.log('');
console.log(` 目录:${appDir}`);
console.log(` 程序:${EXE_NAME}`);
console.log(` 体积:exe ${(fs.statSync(cnExe).size / 1024 / 1024).toFixed(0)} MB,整包 ${(totalBytes / 1024 / 1024).toFixed(0)} MB`);
console.log('');
console.log(' ⚠️ 整个路径必须是纯英文/数字:Electron 放在中文目录下会在启动时崩溃。');
console.log(` 双击「${EXE_NAME}」即可,数据存在 %APPDATA%\\Doubao\\data。`);