Skip to content

WorkBuddy、CodeBuddy 桌面端增强助手:签到猫猫旅行成长计划查询、多账号独立备份、点切即用;免打扰模式让 AI 无人值守跑长任务;跨账号会话迁移、异常中断自动续接;暂存/快捷提示词;毛玻璃主题与更多实用功能。

fix: handle Windows client startup paths

[email protected]9c9357d89660
diff --git a/scripts/cdp-targets.js b/scripts/cdp-targets.js
index c2806ec..df3e99e 100644
--- a/scripts/cdp-targets.js
+++ b/scripts/cdp-targets.js
@@ -27,6 +27,11 @@ const APP_CBINTL = /\/CodeBuddy\.app(?:\/|$)/i;
// 路径形如 ~/.local/share/workbuddy-ai/app/workbuddy/...,必须先于 CN 规则判定。
const APP_AI_LINUX = /\/workbuddy-ai\//i;
const APP_CN_LINUX = /\/opt\/WorkBuddy\//i;
+// Windows 没有 .app 包,renderer URL 直接落在安装目录的 resources/app.asar 下。
+// 目录可能位于任意盘符,但官方 CN/AI 目录名仍可作为 profile 强信号。
+const APP_AI_WIN = /\/WorkBuddy(?:%20| )?AI\/resources\/app\.asar(?:\/|$)/i;
+const APP_AI_WIN_COMPACT = /\/WorkBuddyAI\/resources\/app\.asar(?:\/|$)/i;
+const APP_CN_WIN = /\/WorkBuddy\/resources\/app\.asar(?:\/|$)/i;
const DOMAIN_WB_AI = /https?:\/\/(?:[^/]+\.)?workbuddy\.ai(?:\/|$)/i;
const DOMAIN_WB_CN = /https?:\/\/(?:[^/]+\.)?workbuddy\.cn(?:\/|$)/i;
const DOMAIN_CB_CN = /https?:\/\/(?:[^/]+\.)?codebuddy\.cn(?:\/|$)/i;
@@ -42,8 +47,10 @@ function classifyTarget(url, title, description) {
const u = normalizeTargetUrl(url);
if (APP_AI.test(u)) return 'workbuddy-ai';
if (APP_AI_LINUX.test(u)) return 'workbuddy-ai';
+ if (APP_AI_WIN.test(u) || APP_AI_WIN_COMPACT.test(u)) return 'workbuddy-ai';
if (APP_CN.test(u)) return 'workbuddy-cn';
if (APP_CN_LINUX.test(u)) return 'workbuddy-cn';
+ if (APP_CN_WIN.test(u)) return 'workbuddy-cn';
if (APP_CBCN.test(u)) return 'codebuddy-cn';
if (APP_CBINTL.test(u)) return 'codebuddy-intl';
if (DOMAIN_WB_AI.test(u)) return 'workbuddy-ai';
@@ -88,6 +95,17 @@ function isTargetForProfile(target, profile) {
const desc = String(target.description || '');
const haystack = `${url} ${title} ${desc}`;
+ // Windows 官方安装目录的 app.asar 路径是比标题更可靠的归属证据,必须先于
+ // customTarget/标题兜底判断;企业目标仍保留自己的精确信号策略。
+ const cls = classifyTarget(url, title, desc);
+ const normalizedUrl = normalizeTargetUrl(url);
+ const windowsOfficialPath = /^file:\/\/\/[A-Za-z]:\//i.test(normalizedUrl) && (
+ APP_AI_WIN.test(normalizedUrl)
+ || APP_AI_WIN_COMPACT.test(normalizeTargetUrl(url))
+ || APP_CN_WIN.test(normalizedUrl)
+ );
+ if (windowsOfficialPath) return cls === profile.id;
+
// 企业专享版沿用 CN/AI 的 UI 能力,但应用路径和登录域均由用户选择后生成。
// 企业模式只接受它自己的精确信号,不再回落到官方域名或通用标题。
if (profile.customTarget) {
@@ -101,8 +119,6 @@ function isTargetForProfile(target, profile) {
return signals.some((signal) => lower.includes(signal));
}
- // 强信号:页面明确属于某客户端 → 必须与当前 profile 一致,否则一律拒绝
- const cls = classifyTarget(url, title, desc);
if (cls) return cls === profile.id;
// CodeBuddy:Editor 模式的 target URL 通常是 vscode-file://,不包含产品名;
diff --git a/scripts/daemon.js b/scripts/daemon.js
index 1bdc695..6c60b90 100644
--- a/scripts/daemon.js
+++ b/scripts/daemon.js
@@ -481,13 +481,14 @@ const primaryAccountStore = createPrimaryAccountStore(DATA_DIR, (uid) => fs.exis
// 1.2.18:自动化 session.create 可选 cwd(绝对路径)/ workspace(侧栏工作区名)指定新会话
// 工作目录;工作区不存在或绑定校验不通过时拒绝发送,不退回默认目录。
// 1.2.20:CodeBuddy 原生安全存储不可用时保护已有加密会话,并给出钥匙串/密钥环修复提示。
-// 1.2.29:/api/status 的客户端运行状态改为后台定时刷新 + 请求直读缓存。Windows 上
+// 1.2.30:/api/status 的客户端运行状态改为后台定时刷新 + 请求直读缓存。Windows 上
// safeClientRunning() 会冷启 PowerShell 做 CIM 进程枚举(实测 2.4-6.7s),
// 在请求线程里执行会把状态接口拖到远超 launcher HTTP 发现预算的程度,温启动
// 时 launcher 发现不到已在监听的 daemon,误选备用 UI 端口后失败退出。
-// launcher 的 httpGet 预算同步对齐到 HTTP_GET_TIMEOUT_MS。
-const DAEMON_VERSION = '1.2.29';
-const DAEMON_BUILD_ID = 'release-1.2.29-20261012-status-nonblocking';
+// launcher 的 httpGet 预算同步对齐到 HTTP_GET_TIMEOUT_MS;Windows app.asar
+// 页面归属与 CDP 目标等待窗口也同步修复。
+const DAEMON_VERSION = '1.2.30';
+const DAEMON_BUILD_ID = 'release-1.2.30-20261012-windows-startup-followup';
const usageReporter = createUsageReporter({ profile: PROFILE.id, version: DAEMON_VERSION });
configureAutomationRuntime({version: DAEMON_VERSION, profileId: PROFILE.id, platform: process.platform});
const automationDiscovery = createAutomationDiscovery({
diff --git a/scripts/win-launcher.js b/scripts/win-launcher.js
index 8948066..08d86b8 100644
--- a/scripts/win-launcher.js
+++ b/scripts/win-launcher.js
@@ -1545,7 +1545,9 @@ function nativeDaemonStatusMatches(status) {
);
}
-async function waitForNativeDaemon(attempts = 40) {
+// 原生 helper/PowerShell/CIM 冷启动可能超过 10 秒;给 watchdog/daemon 60 秒完成初始化,
+// 避免第一次等待失败后重复清理并制造第二个启动竞态。
+async function waitForNativeDaemon(attempts = 240) {
for (let attempt = 0; attempt < attempts; attempt += 1) {
if (attempt > 0) await sleep(250);
const status = await readStatus();
diff --git a/test/cdp-targets.test.js b/test/cdp-targets.test.js
index b5283c3..21cfd19 100644
--- a/test/cdp-targets.test.js
+++ b/test/cdp-targets.test.js
@@ -10,6 +10,8 @@ const CN_URL = 'file:///Applications/WorkBuddy.app/Contents/Resources/app.asar/r
const CB_CN_URL = 'file:///Applications/CodeBuddy%20CN.app/Contents/Resources/app/renderer/index.html';
const CB_INTL_URL = 'file:///Applications/CodeBuddy.app/Contents/Resources/app/renderer/index.html';
const VSCODE_URL = 'vscode-file://vscode-app/Applications/CodeBuddy.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html';
+const WIN_CN_URL = 'file:///E:/WorkBuddy/resources/app.asar/renderer/index.html';
+const WIN_AI_URL = 'file:///E:/WorkBuddyAI/resources/app.asar/renderer/index.html';
test('normalizeTargetUrl 把 %20 还原为空格', () => {
assert.equal(normalizeTargetUrl(AI_URL), AI_URL.replace(/%20/g, ' '));
@@ -31,6 +33,12 @@ test('classifyTarget 依据 app 包路径识别四客户端(含 %20 编码)'
assert.equal(classifyTarget(AI_URL, 'WorkBuddy'), 'workbuddy-ai');
});
+test('classifyTarget 识别 Windows 安装目录中的 app.asar 页面', () => {
+ assert.equal(classifyTarget(WIN_CN_URL, 'WorkBuddy'), 'workbuddy-cn');
+ assert.equal(classifyTarget(WIN_AI_URL, 'WorkBuddy AI'), 'workbuddy-ai');
+ assert.equal(classifyTarget('file:///E:/WorkBuddy%20AI/resources/app.asar/renderer/index.html', 'WorkBuddy'), 'workbuddy-ai');
+});
+
test('classifyTarget 依据登录域名识别国际版/国内版', () => {
assert.equal(classifyTarget('https://www.workbuddy.ai/profile/plans-usage', ''), 'workbuddy-ai');
assert.equal(classifyTarget('https://www.workbuddy.cn/profile/plans-usage', ''), 'workbuddy-cn');
diff --git a/test/daemon-status-nonblocking.test.js b/test/daemon-status-nonblocking.test.js
index ebe93f9..4ab6375 100644
--- a/test/daemon-status-nonblocking.test.js
+++ b/test/daemon-status-nonblocking.test.js
@@ -114,7 +114,7 @@ test('daemon behavior change ships a version and build bump so stale daemons are
const buildId = daemonSource.match(/const DAEMON_BUILD_ID = '([^']+)'/);
assert.ok(version && buildId, 'DAEMON_VERSION/DAEMON_BUILD_ID not found');
assert.notEqual(version[1], '1.2.28', 'DAEMON_VERSION must be incremented for a daemon behavior change');
- assert.match(buildId[1], /^release-1\.2\.29-/, 'DAEMON_BUILD_ID must be rewritten for the new build');
+ assert.match(buildId[1], /^release-1\.2\.30-/, 'DAEMON_BUILD_ID must be rewritten for the new build');
});
test('launcher httpGet uses a budget aligned with the daemon probe cost', () => {
diff --git a/test/windows-elevated-consent.test.js b/test/windows-elevated-consent.test.js
index 8cebc6d..d3007d3 100644
--- a/test/windows-elevated-consent.test.js
+++ b/test/windows-elevated-consent.test.js
@@ -78,6 +78,14 @@ test('native daemon reuse requires matching privilege, profile, build, data and
assert.match(src, /function hasElevatedSessionConsent[\s\S]*--check-elevated-session/);
});
+test('native daemon wait allows the watchdog up to 60 seconds to become ready', () => {
+ const src = read('scripts/win-launcher.js');
+ const start = src.indexOf('async function waitForNativeDaemon(');
+ const end = src.indexOf('\n}', start);
+ assert.ok(start >= 0 && end > start);
+ assert.match(src.slice(start, end), /attempts\s*=\s*240/);
+});
+
test('native consent policy rejects missing, corrupt, foreign and no-longer-eligible consent', (t) => {
const { spawnSync } = require('node:child_process');
const os = require('node:os');