Skip to content

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

fix: confirm session deletion and respect sync rules

[email protected]124213a0d658
diff --git a/scripts/daemon.js b/scripts/daemon.js
index 6b6ccc7..142aa69 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.148';
-const DAEMON_BUILD_ID = 'release-1.2.148-20260923-windows-compat-target';
+const DAEMON_VERSION = '1.2.151';
+const DAEMON_BUILD_ID = 'release-1.2.151-20260924-session-switch-delete-loading';
const usageReporter = createUsageReporter({ profile: PROFILE.id, version: DAEMON_VERSION });
configureAutomationRuntime({version: DAEMON_VERSION, profileId: PROFILE.id, platform: process.platform});
const automationDiscovery = createAutomationDiscovery({
@@ -5219,6 +5219,12 @@ function hasPendingAutoCopyTo(uid) {
return false;
}
+function shouldStartAutoCopyJob(sourceRules, pendingToSource) {
+ const rules = sourceRules || {};
+ return !!(rules.allSessions || (Array.isArray(rules.sessionIds) && rules.sessionIds.length) ||
+ (Array.isArray(rules.workspaces) && rules.workspaces.length) || pendingToSource);
+}
+
function pruneAutoCopyJobs() {
const completed = Array.from(autoCopyJobs.values())
.filter((job) => job.status === 'done' || job.status === 'partial' || job.status === 'conflict' || job.status === 'error')
@@ -10383,8 +10389,7 @@ function handleApi(req, res) {
// 空间规则可能因切换前后的会话索引时序暂时无法生成初始计划,但规则本身仍需触发复制任务;
// 任务规则通常能直接命中,所以旧逻辑只表现为“任务能复制、空间不复制”。
const sourceRules = sourceUid ? getAutoCopyRules(DATA_DIR, sourceUid) : { allSessions: false, sessionIds: [], workspaces: [] };
- const hasSourceAutoCopyRules = !!(sourceRules.allSessions || sourceRules.sessionIds.length || sourceRules.workspaces.length);
- const autoCopyJob = (hasSourceAutoCopyRules || hasPendingAutoCopyTo(sourceUid) || currentConversationId)
+ const autoCopyJob = shouldStartAutoCopyJob(sourceRules, hasPendingAutoCopyTo(sourceUid))
? startAutoCopyJob(sourceUid, uid, [], {
sourceName: sourceAccount.nickname || '',
targetName: acct.nickname || '',
diff --git a/scripts/inject.js b/scripts/inject.js
index 84aab35..4613bbe 100644
--- a/scripts/inject.js
+++ b/scripts/inject.js
@@ -1146,7 +1146,7 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
"已关闭首页活动弹窗": "Home activity popup closed.",
"Token 用量仅统计本机记录,在不同电脑上查看的数据可能不一致。": "Token usage only includes records on this computer. Figures may differ between computers.",
"会话输入框非空,未覆盖草稿、未发送": "The composer contains a draft. Nothing was overwritten or sent.",
- '页面就绪': 'Page ready', '删除选中的': 'Delete selected', '删除该自动化任务?': 'Delete this automation task?', '删除选中的自动化任务?': 'Delete selected automation tasks?', '删除后无法恢复。': 'This cannot be undone.', '清除': 'Clear', '清除日志': 'Clear logs', '清除运行日志?': 'Clear run logs?', '仅清除已结束的运行记录。': 'Only completed run records will be cleared.', '清除日志失败': 'Failed to clear logs', '任务已启用': 'Task enabled', '任务已停用': 'Task disabled', '发送中': 'Sending',
+ '页面就绪': 'Page ready', '删除选中的': 'Delete selected', '删除中…': 'Deleting…', '删除该自动化任务?': 'Delete this automation task?', '删除选中的自动化任务?': 'Delete selected automation tasks?', '删除后无法恢复。': 'This cannot be undone.', '清除': 'Clear', '清除日志': 'Clear logs', '清除运行日志?': 'Clear run logs?', '仅清除已结束的运行记录。': 'Only completed run records will be cleared.', '清除日志失败': 'Failed to clear logs', '任务已启用': 'Task enabled', '任务已停用': 'Task disabled', '发送中': 'Sending',
'成长计划读取中': 'Growth plan is loading', '成长计划暂不可用': 'Growth plan is unavailable',
'Buddy 今日旅行已完成': 'Buddy finished traveling today', 'Buddy 旅行中': 'Buddy is traveling', 'Buddy 待领取礼物': 'Buddy gift pending', 'Buddy 已归来,待领奖': 'Buddy returned; reward pending', 'Buddy 在家': 'Buddy is home', 'Buddy 尚未解锁': 'Buddy is not unlocked',
'成长任务': 'Growth tasks', '状态暂不可用': 'Status unavailable', '暂不可用': 'Unavailable', '今日旅行已完成': "Today's travel is complete", '旅行中,预计': 'Traveling, expected ', ' 归来': ' return', '旅行中': 'Traveling', '即将归来': 'Returning soon',
@@ -8400,6 +8400,10 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
}
pending = true;
okBtn.disabled = true;
+ var pendingLabel = okBtn.textContent;
+ okBtn.textContent = '删除中…';
+ okBtn.classList.add('is-loading');
+ okBtn.setAttribute('aria-busy', 'true');
api('/api/sessions/delete', {
method: 'POST',
headers: { 'content-type': 'application/json' },
@@ -8413,7 +8417,12 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
toast('删除失败: ' + (e.message || e), true, root);
}).finally(function () {
pending = false;
- if (okBtn.onclick === submit) okBtn.disabled = false;
+ if (okBtn.onclick === submit) {
+ okBtn.disabled = false;
+ okBtn.textContent = pendingLabel;
+ okBtn.classList.remove('is-loading');
+ okBtn.removeAttribute('aria-busy');
+ }
});
};
okBtn.onclick = submit;
@@ -15935,6 +15944,9 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
'.wbs-modal-btn:hover{background:var(--wb-bg-hover,#f5f5f5);color:var(--wb-color-text-primary,#1f1f1f);border-color:var(--wb-border-strong,#bbb)}',
'.wbs-modal-btn.wbs-modal-ok{color:#fff;background:#141416;border-color:#141416}',
'.wbs-modal-btn.wbs-modal-ok:hover{background:#2a2a2e;color:#fff}',
+ '.wbs-modal-btn.is-loading{display:inline-flex;align-items:center;justify-content:center;gap:6px;cursor:wait}',
+ '.wbs-modal-btn.is-loading::before{content:"";width:11px;height:11px;box-sizing:border-box;border:1.5px solid currentColor;border-top-color:transparent;border-radius:50%;animation:wbs-modal-btn-spin .72s linear infinite}',
+ '@keyframes wbs-modal-btn-spin{to{transform:rotate(360deg)}}',
/* 免打扰确认弹窗:红字确认按钮(高危操作,用红色警示) */
'.wbs-modal-btn.wbs-modal-danger{color:#fff;background:#c62828;border-color:#c62828}',
'.wbs-modal-btn.wbs-modal-danger:hover{background:#b71c1c}',
diff --git a/test/session-delete-ui.test.js b/test/session-delete-ui.test.js
index 77fa479..4e9f1e3 100644
--- a/test/session-delete-ui.test.js
+++ b/test/session-delete-ui.test.js
@@ -6,7 +6,16 @@ const vm = require('node:vm');
const source = fs.readFileSync(require('node:path').join(__dirname, '../scripts/inject.js'), 'utf8');
function harness() {
const requests = [], nodes = {};
- for (const id of ['title', 'body', 'ok', 'cancel']) nodes['#wbs-sess-modal-' + id] = { textContent: '', focus() {}, disabled: false };
+ for (const id of ['title', 'body', 'ok', 'cancel']) {
+ const classes = new Set(), attrs = {};
+ nodes['#wbs-sess-modal-' + id] = {
+ textContent: '', focus() {}, disabled: false,
+ classList: { add: name => classes.add(name), remove: name => classes.delete(name), contains: name => classes.has(name) },
+ setAttribute: (name, value) => { attrs[name] = String(value); },
+ getAttribute: name => attrs[name] || null,
+ removeAttribute: name => { delete attrs[name]; },
+ };
+ }
const ctx = vm.createContext({
sessionsPane: { querySelector: id => nodes[id] },
sessionsState: {}, root: {}, toast() {}, loadSessions() {},
@@ -28,6 +37,10 @@ test('all-account deletion requires two confirmations and freezes the selected I
assert.match(h.nodes['#wbs-sess-modal-title'].textContent, /再次确认/);
h.ok.onclick(); h.ok.onclick();
assert.equal(h.requests.length, 1, 'ignore duplicate submission');
+ assert.equal(h.ok.disabled, true, 'delete button is disabled while the request is pending');
+ assert.equal(h.ok.classList.contains('is-loading'), true, 'delete button shows loading while the request is pending');
+ assert.equal(h.ok.getAttribute('aria-busy'), 'true');
+ assert.equal(h.ok.textContent, '删除中…');
assert.equal(h.requests[0].route, '/api/sessions/delete');
assert.deepEqual(JSON.parse(h.requests[0].options.body).ids, ['selected-session']);
h.requests[0].resolve({ deleted: 3, cascaded: 2 });
@@ -48,6 +61,9 @@ test('existing deletion retains its single confirmation and errors permit retry'
h.requests[0].reject(Error('locked'));
await new Promise(resolve => setImmediate(resolve));
assert.equal(h.ok.disabled, false);
+ assert.equal(h.ok.classList.contains('is-loading'), false);
+ assert.equal(h.ok.getAttribute('aria-busy'), null);
+ assert.equal(h.ok.textContent, '确定');
assert.equal(h.ctx.open, true);
h.ok.onclick(); assert.equal(h.requests.length, 2);
});
diff --git a/test/update-layout.test.js b/test/update-layout.test.js
index 1ec7f44..bdca482 100644
--- a/test/update-layout.test.js
+++ b/test/update-layout.test.js
@@ -205,6 +205,24 @@ test('account switching carries the active conversation and opens its copied tar
assert.match(inject, /setBuildTimeout\(function \(\) \{ openCopiedSession\(id, started, attempt \+ 1\); \}, 500\)/);
});
+test('account switching does not auto-copy an opened session without an enabled rule', () => {
+ const daemon = read('daemon.js');
+ const helperStart = daemon.indexOf('function shouldStartAutoCopyJob(');
+ assert.notEqual(helperStart, -1, 'auto-copy decision must have a testable helper');
+ const helperEnd = daemon.indexOf('\n}\n', helperStart) + 3;
+ const context = {};
+ vm.runInNewContext(daemon.slice(helperStart, helperEnd), context);
+ assert.equal(context.shouldStartAutoCopyJob({ allSessions: false, sessionIds: [], workspaces: [] }, false), false);
+ assert.equal(context.shouldStartAutoCopyJob({ allSessions: false, sessionIds: [], workspaces: [] }, true), true);
+ assert.equal(context.shouldStartAutoCopyJob({ allSessions: true, sessionIds: [], workspaces: [] }, false), true);
+ assert.equal(context.shouldStartAutoCopyJob({ allSessions: false, sessionIds: ['session'], workspaces: [] }, false), true);
+ assert.equal(context.shouldStartAutoCopyJob({ allSessions: false, sessionIds: [], workspaces: ['/workspace'] }, false), true);
+ const routeStart = daemon.indexOf("if (req.method === 'POST' && p === '/api/switch')");
+ const route = daemon.slice(routeStart, routeStart + 9000);
+ assert.match(route, /shouldStartAutoCopyJob\(sourceRules, hasPendingAutoCopyTo\(sourceUid\)\)/);
+ assert.doesNotMatch(route, /hasPendingAutoCopyTo\(sourceUid\) \|\| currentConversationId/);
+});
+
test('copied-session activation trusts the official handler even when projection ids are empty', async () => {
const inject = read('inject.js');
const start = inject.indexOf(' function openCopiedSession(sessionId, startedAt) {');
@@ -1307,7 +1325,7 @@ test('automatic session copy includes workspace-only rules when the initial plan
assert.match(daemon, /getAutoCopySessionMembers\(DATA_DIR, lineageId, targetUid\)/);
assert.match(daemon, /const existing = candidates\.find\(/);
assert.match(daemon, /const sourceRules = sourceUid \? getAutoCopyRules\(DATA_DIR, sourceUid\)/);
- assert.match(daemon, /hasSourceAutoCopyRules/);
+ assert.match(daemon, /shouldStartAutoCopyJob\(sourceRules, hasPendingAutoCopyTo\(sourceUid\)\)/);
assert.match(daemon, /hasPendingAutoCopyTo\(uid\)/);
assert.match(daemon, /startAutoCopyJob\(sourceUid, uid, \[\]/);
assert.match(daemon, /copySessionRecord\(src, targetUid/);
@@ -1335,7 +1353,7 @@ test('session copy-all is a separate override with a distinct toggle and hidden
const daemon = read('daemon.js');
const inject = read('inject.js');
assert.match(daemon, /POST' && p === '\/api\/sessions\/auto-copy-all'/);
- assert.match(daemon, /sourceRules\.allSessions/);
+ assert.match(daemon, /rules\.allSessions/);
assert.match(inject, /id="wbs-sess-auto-all"/);
const filters = inject.slice(inject.indexOf('<div class="wbs-sess-filters">'), inject.indexOf('<div class="wbs-sess-toolbar">'));
assert.match(filters, /id="wbs-sess-account-select"[\s\S]*id="wbs-sess-size-seg"[\s\S]*id="wbs-sess-range-seg"/);