Skip to content

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

fix: gate active conversation copy on its own sync rule

[email protected]c9009c197aed
diff --git a/scripts/daemon.js b/scripts/daemon.js
index 2c2a785..84b0fbe 100644
--- a/scripts/daemon.js
+++ b/scripts/daemon.js
@@ -420,8 +420,8 @@ const primaryAccountStore = createPrimaryAccountStore(DATA_DIR, (uid) => fs.exis
// 1.2.145:识别仅 updated_at 的激活漂移,清除无变更脏标记;无结果任务不再弹同步进度窗口。
// 1.2.126:5.6 加密账号改为密文原样备份、内存解密;导入兼容明文 token,
// 刷新结果不把解密后的 token 写回加密备份。
-const DAEMON_VERSION = '1.2.152';
-const DAEMON_BUILD_ID = 'release-1.2.152-20260924-linux-sleep-open-url';
+const DAEMON_VERSION = '1.2.153';
+const DAEMON_BUILD_ID = 'release-1.2.153-20260924-respect-active-session-sync-rule';
const usageReporter = createUsageReporter({ profile: PROFILE.id, version: DAEMON_VERSION });
configureAutomationRuntime({version: DAEMON_VERSION, profileId: PROFILE.id, platform: process.platform});
const automationDiscovery = createAutomationDiscovery({
@@ -10358,6 +10358,7 @@ function handleApi(req, res) {
releaseAccountSwitch = await assertAccountSwitchIdle();
const sourceAccount = currentAccount() || {};
const sourceUid = String(sourceAccount.uid || '').trim();
+ let currentConversationRow = null;
let currentConversationId = isValidSessionId(String(body.currentConversationId || '').trim())
? String(body.currentConversationId).trim() : '';
// Renderer projection state can briefly retain the destination id from
@@ -10365,12 +10366,14 @@ function handleApi(req, res) {
// the session index proves it belongs to the account being replaced.
if (currentConversationId && sourceUid) {
const ownerRows = await sqliteQuery(
- 'SELECT user_id FROM sessions WHERE id = ? AND deleted_at IS NULL LIMIT 1;',
+ 'SELECT user_id, cwd FROM sessions WHERE id = ? AND deleted_at IS NULL LIMIT 1;',
[currentConversationId]
);
if (!ownerRows.length || String(ownerRows[0].user_id || '') !== sourceUid) {
log(`[switch] 丢弃不属于源账号的当前会话 source=${sourceUid} session=${currentConversationId}`);
currentConversationId = '';
+ } else {
+ currentConversationRow = { ...ownerRows[0], id: currentConversationId };
}
}
const acct = switchTo(DATA_DIR, uid, log);
@@ -10403,11 +10406,15 @@ function handleApi(req, res) {
// 空间规则可能因切换前后的会话索引时序暂时无法生成初始计划,但规则本身仍需触发复制任务;
// 任务规则通常能直接命中,所以旧逻辑只表现为“任务能复制、空间不复制”。
const sourceRules = sourceUid ? getAutoCopyRules(DATA_DIR, sourceUid) : { allSessions: false, sessionIds: [], workspaces: [] };
+ // An unrelated workspace rule may start a job, but must never opt the
+ // open conversation into copying. Use the planner's exact selection rule.
+ const autoCopyOpenSessionId = currentConversationRow && isAutoCopySessionSelected(sourceRules, currentConversationRow)
+ ? currentConversationId : '';
const autoCopyJob = shouldStartAutoCopyJob(sourceRules, hasPendingAutoCopyTo(sourceUid))
? startAutoCopyJob(sourceUid, uid, [], {
sourceName: sourceAccount.nickname || '',
targetName: acct.nickname || '',
- openSessionId: currentConversationId,
+ openSessionId: autoCopyOpenSessionId,
})
: null;
return json(res, 200, {
diff --git a/test/account-switch-session-rules.test.js b/test/account-switch-session-rules.test.js
new file mode 100644
index 0000000..c6b0779
--- /dev/null
+++ b/test/account-switch-session-rules.test.js
@@ -0,0 +1,82 @@
+'use strict';
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const fs = require('node:fs');
+const path = require('node:path');
+const vm = require('node:vm');
+const lib = require('../scripts/lib');
+const source = fs.readFileSync(path.join(__dirname, '../scripts/daemon.js'), 'utf8');
+
+function harness(rules, owner = 'source') {
+ const jobs = [], events = [];
+ const ctx = vm.createContext({
+ DATA_DIR: 'fixture', log() {}, isAutoCopySessionSelected: lib.isAutoCopySessionSelected,
+ isValidSessionId: id => !!id,
+ readBody: async req => req.body,
+ json: (_, status, body) => ({ status, body }),
+ beginRendererReloadPriority: () => () => events.push('release-reload'),
+ assertAccountSwitchIdle: async () => () => events.push('release-switch'),
+ currentAccount: () => ({ uid: 'source' }),
+ sqliteQuery: async () => owner ? [{ user_id: owner, cwd: '/current-workspace' }] : [],
+ switchTo: (_, uid) => { events.push('switch'); return { uid }; },
+ reloadWorkBuddyPage: async () => { events.push('reload'); },
+ mainFrameNavigationSerial: 1, setTimeout() {},
+ getAutoCopyRules: () => rules,
+ hasPendingAutoCopyTo: () => false,
+ startAutoCopyJob: (from, to, plan, labels) => {
+ events.push('job');
+ jobs.push({ from, to, ...labels });
+ return { id: 'job', total: 0, openSessionId: labels.openSessionId };
+ },
+ });
+ const helperStart = source.indexOf('function shouldStartAutoCopyJob(');
+ vm.runInContext(source.slice(helperStart, source.indexOf('\nfunction pruneAutoCopyJobs', helperStart)), ctx);
+ const routeStart = source.indexOf(" if (req.method === 'POST' && p === '/api/switch')");
+ const routeEnd = source.indexOf('\n return json(res, 404', routeStart);
+ vm.runInContext('async function switchRoute(req, res) { const p = "/api/switch";\n' + source.slice(routeStart, routeEnd) + '\n}', ctx);
+ return { jobs, events, run: () => ctx.switchRoute({ method: 'POST', body: { uid: 'target', reload: true, currentConversationId: 'open' } }, {}) };
+}
+
+test('switch route reloads without syncing when no rule is enabled', async () => {
+ const h = harness({ allSessions: false, sessionIds: [], workspaces: [] });
+ const result = await h.run();
+ assert.equal(result.status, 200);
+ assert.equal(result.body.reloaded, true);
+ assert.equal(h.jobs.length, 0);
+ assert.deepEqual(h.events, ['switch', 'reload', 'release-reload', 'release-switch']);
+});
+
+for (const rules of [
+ { allSessions: false, sessionIds: [], workspaces: ['/unrelated-workspace'] },
+ { allSessions: false, sessionIds: ['another-session'], workspaces: [] },
+]) {
+ test('switch route never adds an unselected open conversation to another rule’s job: ' + JSON.stringify(rules), async () => {
+ const h = harness(rules);
+ const result = await h.run();
+ assert.equal(result.status, 200);
+ assert.equal(h.jobs.length, 1, 'the other rule still has its normal sync job');
+ assert.equal(h.jobs[0].openSessionId, '', 'an unselected open conversation must not become a forced planner request');
+ assert.equal(result.body.autoCopy.openSessionId, '');
+ assert.ok(h.events.indexOf('reload') < h.events.indexOf('job'));
+ });
+}
+
+for (const rules of [
+ { allSessions: true, sessionIds: [], workspaces: [] },
+ { allSessions: false, sessionIds: ['open'], workspaces: [] },
+ { allSessions: false, sessionIds: [], workspaces: ['/current-workspace/'] },
+]) {
+ test('switch route preserves restoration for a selected open conversation: ' + JSON.stringify(rules), async () => {
+ const h = harness(rules);
+ assert.equal((await h.run()).status, 200);
+ assert.equal(h.jobs[0].openSessionId, 'open');
+ });
+}
+
+for (const owner of ['', 'other-account']) {
+ test('switch route never carries a missing or foreign conversation: ' + owner, async () => {
+ const h = harness({ allSessions: true, sessionIds: [], workspaces: [] }, owner);
+ assert.equal((await h.run()).status, 200);
+ assert.equal(h.jobs[0].openSessionId, '');
+ });
+}
diff --git a/test/update-layout.test.js b/test/update-layout.test.js
index bdca482..6c297f9 100644
--- a/test/update-layout.test.js
+++ b/test/update-layout.test.js
@@ -176,7 +176,7 @@ test('account switching carries the active conversation and opens its copied tar
const routeStart = script.indexOf("if (req.method === 'POST' && p === '/api/switch')");
const route = script.slice(routeStart, routeStart + 9000);
assert.match(route, /currentConversationId/);
- assert.match(route, /SELECT user_id FROM sessions WHERE id = \? AND deleted_at IS NULL LIMIT 1;/);
+ assert.match(route, /SELECT user_id, cwd FROM sessions WHERE id = \? AND deleted_at IS NULL LIMIT 1;/);
assert.match(route, /不属于源账号的当前会话/);
const dirtyStart = script.indexOf("if (req.method === 'POST' && p === '/api/sessions/dirty')");
const dirtyRoute = script.slice(dirtyStart);