Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/deepseek-harness.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

beautiCode 通过 DeepSeek Harness 的 Cordis 插件接口接入(`beauticode-dsh`),不修改 DSH 源码,也不依赖 Chromium 调试端口。插件通过 DSH 的结构化页面注入同时支持 Web 和官方 Desktop;后者的页面地址是 `dsh-app://app/`,Host 默认端口是 `19387`。DSH 由你自己启动;beautiCode 只挂插件、不替代、不重启你的 DSH。Codex Desktop 仍由托盘按原路径拉起,与本节无关。

Web 安装器按 profile 的 dsh.profile.bundles 判断插件是否已经注册为包层。已注册时保留包层并备份、移除重复的补丁条目;未注册时由当前 profile 的补丁挂载。已有 DSH 主目录改用目录联接点时,安装器解析该目录的真实位置,继续检查插件子目录及链接归属。

## 已实现能力

- 图片背景、MP4 视频背景与清除。首页(`data-phase="hero"`)壁纸保持原亮度;进入会话(`active` / `settling`)后才压暗。
Expand Down
2 changes: 2 additions & 0 deletions docs/host-adapter-cursor-doubao.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ runtime\node.exe scripts\desktop-cdp-setup.mjs --host doubao install
| Cursor | 3.18.9 | 9341 | `vscode-file://vscode-app/d:/cursor/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html` | `[data-action-id="marketplace"][data-sidebar-primary-action]`,标签 `Customize` |
| 豆包 | 2.29.12 | 9342 | `doubao://doubao-chat/chat` | `[data-testid="skill-page-item-more"]`,标签 `更多` |

豆包 2.31.4 的当前 Windows 安装程序默认写入 %LOCALAPPDATA%\Doubao\Application\Doubao.exe,主窗口启动阶段也会报告 doubao://doubao-chat/chat/。两种精确主路由都可匹配,其他窗口或路径会被忽略。

锚点或标签不一致时注入会失败关闭,不会用模糊文本匹配插入其他页面。客户端升级后应先重新测量这些契约。

Cursor 的入口是 `background`,直接位于 `Customize` 后;所有面板文案为英文。豆包的入口是 `自定义背景`,直接位于 `更多` 后;面板文案为中文。
Expand Down
207 changes: 26 additions & 181 deletions integrations/deepseek-harness/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import crypto from "node:crypto";
import os from "node:os";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { backupPatch, fileUriInsert, hasBridge, packageInsert, removePatch, writePatch } from "./profile-patch.mjs";

function findPackageRoot(startDir) {
let dir = startDir;
Expand All @@ -30,7 +31,6 @@ function findPackageRoot(startDir) {

const here = findPackageRoot(path.dirname(fileURLToPath(import.meta.url)));
const pluginName = "beauticode-dsh";
const bridgeId = "beauticode-bridge";

function argValue(argv, name) {
const idx = argv.indexOf(name);
Expand Down Expand Up @@ -134,51 +134,6 @@ function legacyDefaultPluginHome() {
return path.join(defaultDataRoot(), "plugin");
}

function toFileUri(filePath) {
const full = path.resolve(filePath).replaceAll("\\", "/");
if (/^[A-Za-z]:/.test(full)) return `file:///${full}`;
return pathToFileURL(full).href;
}

function fileUriInsert(uri) {
return [
"# beauticode-bridge (installer)",
"- insert:",
" - id: beauticode-bridge",
` name: '${uri}'`,
" inject: [webServer]",
"",
].join("\n");
}

function packageInsert() {
return [
"# beauticode-bridge (installer)",
"- insert:",
" - id: beauticode-bridge",
` name: '${pluginName}'`,
" inject: [webServer]",
"",
].join("\n");
}

function hasBridge(text) {
return new RegExp(`^[ \\t]*-[ \\t]*id:[ \\t]*${bridgeId}[ \\t]*(?:#.*)?\\r?$`, "m").test(text);
}

function bridgeCount(text) {
return (String(text).match(new RegExp(`^[ \\t]*-[ \\t]*id:[ \\t]*${bridgeId}[ \\t]*(?:#.*)?\\r?$`, "gm")) || []).length;
}

async function backupPatch(filePath) {
const base = `${filePath}.beauticode-backup-${Date.now()}`;
let backup = base;
let suffix = 0;
while (fs.existsSync(backup)) backup = `${base}-${++suffix}`;
await fsp.copyFile(filePath, backup, fs.constants.COPYFILE_EXCL);
return backup;
}

async function backupDirectory(target) {
const base = `${target}.beauticode-backup-${Date.now()}`;
let backup = base;
Expand All @@ -188,129 +143,6 @@ async function backupDirectory(target) {
return backup;
}

async function backupDuplicatePatch(filePath) {
return backupPatch(filePath);
}

function stripBridge(text) {
const lines = text.split(/\r?\n/);
const removed = new Array(lines.length).fill(false);
const indentOf = (line) => line.match(/^[ \t]*/)?.[0].length ?? 0;

for (let i = 0; i < lines.length; i += 1) {
const insert = lines[i].match(/^([ \t]*)-\s*insert:\s*(?:#.*)?$/);
if (!insert) continue;
const insertIndent = insert[1].length;
let blockEnd = i + 1;
while (blockEnd < lines.length) {
const line = lines[blockEnd];
if (line.trim() && indentOf(line) <= insertIndent) break;
blockEnd += 1;
}

let foundBridge = false;
for (let j = i + 1; j < blockEnd; ) {
const bridge = lines[j].match(
/^([ \t]*)-\s*id:\s*beauticode-bridge\s*(?:#.*)?$/,
);
if (!bridge || bridge[1].length <= insertIndent) {
j += 1;
continue;
}
foundBridge = true;
const itemIndent = bridge[1].length;
let itemEnd = j + 1;
while (itemEnd < blockEnd) {
const line = lines[itemEnd];
if (line.trim() && indentOf(line) <= itemIndent) break;
itemEnd += 1;
}
for (let k = j; k < itemEnd; k += 1) removed[k] = true;
j = itemEnd;
}

if (!foundBridge) continue;
const marker = `${insert[1]}# beauticode-bridge (installer)`;
if (i > 0 && lines[i - 1].trimEnd() === marker) removed[i - 1] = true;
const hasSibling = lines
.slice(i + 1, blockEnd)
.some(
(line, offset) =>
!removed[i + 1 + offset] &&
line.trim() !== "" &&
!line.trimStart().startsWith("#"),
);
if (!hasSibling) {
for (let k = i; k < blockEnd; k += 1) removed[k] = true;
}
i = blockEnd - 1;
}

return lines.filter((_, index) => !removed[index]).join("\n");
}

function overlayPayload(text) {
return text
.split(/\r?\n/)
.map((line) => line.trim())
.filter((line) => line && !line.startsWith("#"))
.join("\n");
}

function isEmptyOverlay(text) {
const payload = overlayPayload(text);
return payload === "" || payload === "[]";
}

// DSH seeds overlays as `# comment\n[]`. `[]` is already a complete YAML
// document, so appending `- insert:` makes js-yaml throw.
function keptOverlay(text) {
const withoutFlowEmpty = text
.split(/\r?\n/)
.filter((line) => line.trim() !== "[]")
.join("\n");
if (isEmptyOverlay(withoutFlowEmpty)) return "";
return withoutFlowEmpty.trim();
}

function withTrailingNewline(text) {
return text.endsWith("\n") ? text : `${text}\n`;
}

async function writePatch(filePath, body) {
await fsp.mkdir(path.dirname(filePath), { recursive: true });
const insert = withTrailingNewline(body);
if (!fs.existsSync(filePath)) {
await fsp.writeFile(filePath, insert, "utf8");
return;
}
const raw = await fsp.readFile(filePath, "utf8");
if (hasBridge(raw) && bridgeCount(raw) > 1) {
await backupDuplicatePatch(filePath);
}
const remainder = hasBridge(raw) ? stripBridge(raw) : raw;
const kept = keptOverlay(remainder);
const next = kept ? `${kept}\n\n${insert}` : insert;
await fsp.writeFile(filePath, withTrailingNewline(next), "utf8");
}

async function removePatch(filePath) {
if (!fs.existsSync(filePath)) return false;
const raw = await fsp.readFile(filePath, "utf8");
if (!hasBridge(raw)) return false;
const kept = keptOverlay(stripBridge(raw));
if (!kept) {
await fsp.writeFile(
filePath,
"# Your patch layer for this dsh profile.\n[]\n",
"utf8",
);
return true;
}
await fsp.writeFile(filePath, withTrailingNewline(kept), "utf8");
return true;
}

function shouldCopy(source) {
const relative = path.relative(here, source);
if (relative.startsWith("test") || relative.includes(`${path.sep}test${path.sep}`)) {
Expand Down Expand Up @@ -404,8 +236,7 @@ async function sameLinkTarget(link, dest) {
try {
const stat = await fsp.lstat(link);
if (stat.isSymbolicLink()) {
const target = await fsp.readlink(link);
return path.resolve(path.dirname(link), target) === path.resolve(dest);
return path.relative(await fsp.realpath(link), await fsp.realpath(dest)) === "";
}
if (stat.isDirectory()) {
return path.resolve(link) === path.resolve(dest);
Expand Down Expand Up @@ -488,9 +319,12 @@ async function ensureWebPackageDep(webPackage, pluginHome) {
);
delete json.dependencies["@beauticode/dsh-plugin"];
const current = json.dependencies[pluginName];
if (current === spec && !hadLegacy) return;
const bundles = json.dsh?.profile?.bundles;
const loadsPluginBundle = Array.isArray(bundles) && bundles.includes(pluginName);
if (current === spec && !hadLegacy) return loadsPluginBundle;
json.dependencies[pluginName] = spec;
await fsp.writeFile(webPackage, `${JSON.stringify(json, null, 2)}\n`, "utf8");
return loadsPluginBundle;
}

async function removeWebPackageDep(webPackage) {
Expand All @@ -504,6 +338,14 @@ async function removeWebPackageDep(webPackage) {
changed = true;
}
}
const bundles = json.dsh?.profile?.bundles;
if (Array.isArray(bundles)) {
const remaining = bundles.filter((name) => name !== pluginName && name !== "@beauticode/dsh-plugin");
if (remaining.length !== bundles.length) {
json.dsh.profile.bundles = remaining;
changed = true;
}
}
if (!changed) return false;
await fsp.writeFile(webPackage, `${JSON.stringify(json, null, 2)}\n`, "utf8");
return true;
Expand All @@ -526,15 +368,13 @@ async function install(opts) {

if (fs.existsSync(webPackage)) {
await linkPluginIntoProfile(webProfile, dest);
await ensureWebPackageDep(webPackage, dest);
const loadsPluginBundle = await ensureWebPackageDep(webPackage, dest);
const pluginPatch = path.join(dest, "cordis.patch.yml");
const pluginShipsBridge =
fs.existsSync(pluginPatch) && hasBridge(await fsp.readFile(pluginPatch, "utf8"));
if (pluginShipsBridge) {
// DSH loads the package patch as well as the profile patch. Keep the
// package's canonical loader and remove only beautiCode's managed
// profile block, preserving unrelated profile configuration. Back up
// the user's profile before this repair, even when it had one entry.
if (loadsPluginBundle && pluginShipsBridge) {
// DSH composes only the bundles listed by this profile. Keep its
// existing bundle mount and back up any redundant overlay entry.
if (fs.existsSync(webPatch)) {
const profilePatch = await fsp.readFile(webPatch, "utf8");
if (hasBridge(profilePatch)) {
Expand All @@ -543,7 +383,7 @@ async function install(opts) {
}
}
} else {
await writePatch(webPatch, packageInsert());
await writePatch(webPatch, packageInsert(pluginName));
}
if (fs.existsSync(homePatch)) {
const homeRaw = await fsp.readFile(homePatch, "utf8");
Expand All @@ -558,7 +398,7 @@ async function install(opts) {
}

await fsp.mkdir(dshHome, { recursive: true });
await writePatch(homePatch, fileUriInsert(toFileUri(indexFile)));
await writePatch(homePatch, fileUriInsert(pathToFileURL(indexFile).href));
const migrated = await removeLegacyManagedPlugin(opts.legacyPluginHome, dest);
console.log(`DSH web profile 还不存在,已写入 ${homePatch}`);
console.log(copied ? `插件已安装到 ${dest}` : `已复用已安装的插件 ${dest}`);
Expand Down Expand Up @@ -625,7 +465,12 @@ export async function runCli(argv = process.argv.slice(2)) {
console.log(version);
return { version };
}
const dshHome = argValue(argv, "--dsh-home") || defaultDshHome();
const selectedHome = argValue(argv, "--dsh-home") || defaultDshHome();
// A relocated DSH home defines the installation boundary. Guard its child paths separately.
const dshHome = await fsp.realpath(selectedHome).catch(error => {
if (error.code === "ENOENT") return selectedHome;
throw error;
});
const requestedPluginHome = argValue(argv, "--plugin-home");
const pluginHome = requestedPluginHome || defaultPluginHome(dshHome);
const opts = {
Expand Down
1 change: 1 addition & 0 deletions integrations/deepseek-harness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"host-apply.mjs",
"ui-host.mjs",
"cli.js",
"profile-patch.mjs",
"bin/beauticode-dsh",
"cordis.patch.yml",
"vendor",
Expand Down
Loading
Loading