WorkBuddy、CodeBuddy 桌面端增强助手:签到猫猫旅行成长计划查询、多账号独立备份、点切即用;免打扰模式让 AI 无人值守跑长任务;跨账号会话迁移、异常中断自动续接;暂存/快捷提示词;毛玻璃主题与更多实用功能。
fix: bind fork transcript runtime identity before publication
[email protected]a5f77f116725
diff --git a/scripts/daemon.js b/scripts/daemon.jsindex d261e51..31004e0 100644--- a/scripts/daemon.js+++ b/scripts/daemon.js@@ -535,8 +535,8 @@ const primaryAccountStore = createPrimaryAccountStore(DATA_DIR, (uid) => fs.exis// 1.2.65:兼容空会话同步、自定义模型和重定向备份目录,工作目录恢复退避重试。// 1.2.66:刷新凭据按原信封加密保存,同账号刷新去重,过期账号保留手动切换。// 1.2.67:Windows 重启 GUI 客户端时不再请求隐藏主窗口,与冷启动保持一致。-const DAEMON_VERSION = '1.2.75';-const DAEMON_BUILD_ID = 'release-1.2.75-opt-in-session-cwd-repair';+const DAEMON_VERSION = '1.2.76';+const DAEMON_BUILD_ID = 'release-1.2.76-fork-runtime-identity';const usageReporter = createUsageReporter({ profile: PROFILE.id, version: DAEMON_VERSION });configureAutomationRuntime({version: DAEMON_VERSION, profileId: PROFILE.id, platform: process.platform});const automationDiscovery = createAutomationDiscovery({@@ -5387,8 +5387,15 @@ async function createForkSession(src, selection) {const id = crypto.randomUUID();const target = path.join(path.dirname(source), id + '.jsonl');+ // Resume restores runtime identity from the records, not the new filename.+ // Rebind only the source envelope; message IDs, payloads and child sessions+ // must keep their original identities.+ const text = plan.records.slice(0, plan.keptRecords).map(({ line, value }) => {+ if (!value || value.sessionId !== src.id) return line;+ return JSON.stringify(Object.assign({}, value, { sessionId: id }));+ }).join('\n') + '\n';ensureArchiveParentNoFollow(root, target);- await fs.promises.writeFile(target, plan.text, { flag: 'wx', mode: 0o600 });+ await fs.promises.writeFile(target, text, { flag: 'wx', mode: 0o600 });try {const now = Date.now();const title = forkedTitle(src.custom_title || src.title);diff --git a/test/session-fork-integration.test.js b/test/session-fork-integration.test.jsindex ba45859..39ceb34 100644--- a/test/session-fork-integration.test.js+++ b/test/session-fork-integration.test.js@@ -11,16 +11,17 @@ const compat = require('../scripts/workbuddy-compat.js');const daemonSource = fs.readFileSync(path.join(__dirname, '../scripts/daemon.js'), 'utf8');const injectSource = fs.readFileSync(path.join(__dirname, '../scripts/inject.js'), 'utf8');-function fixture(t, insertCopiedSession) {+function fixture(t, insertCopiedSession, makeRecords) {const root = fs.mkdtempSync(path.join(os.tmpdir(), 'wd-fork-integration-'));t.after(() => fs.rmSync(root, { recursive: true, force: true }));const directory = path.join(root, 'projects', 'workspace-a');fs.mkdirSync(directory, { recursive: true });const row = { id: crypto.randomUUID(), user_id: 'account-a', cwd: '/workspace/a', title: '原会话', created_at: 1 };const source = path.join(directory, row.id + '.jsonl');- const messages = ['user', 'assistant', 'user', 'assistant'].map((role, index) =>- JSON.stringify({ type: 'message', role, timestamp: 10000 + index * 1000,- content: [{ type: 'text', text: 'message ' + index }] })).join('\n') + '\n';+ const records = makeRecords ? makeRecords(row) : ['user', 'assistant', 'user', 'assistant'].map((role, index) =>+ ({ type: 'message', role, sessionId: row.id, timestamp: 10000 + index * 1000,+ content: [{ type: 'text', text: 'message ' + index }] }));+ const messages = records.map(record => JSON.stringify(record)).join('\n') + '\n';fs.writeFileSync(source, messages);const context = {fs, path, crypto, Buffer, PROFILE: { dataRoot: root }, forkedTitle: fork.forkedTitle,@@ -47,7 +48,37 @@ test('fork creates a new local session in the same workspace without changing thassert.match(copied[0].title, /分支/);assert.equal(fs.readFileSync(source, 'utf8'), messages);const branch = path.join(root, 'projects', 'workspace-a', result.id + '.jsonl');- assert.deepEqual(fs.readFileSync(branch, 'utf8').split('\n').filter(Boolean).length, 2);+ const records = fs.readFileSync(branch, 'utf8').trim().split('\n').map(JSON.parse);+ assert.equal(records.length, 2);+ assert.ok(records.every(record => record.sessionId === result.id), 'resume must use the fork runtime identity');+});++test('fork rebinds only the source envelope before publishing the row', async t => {+ let published = false;+ const f = fixture(t, async (_row, _uid, id) => {+ const file = path.join(f.root, 'projects', 'workspace-a', id + '.jsonl');+ const records = fs.readFileSync(file, 'utf8').trim().split('\n').map(JSON.parse);+ assert.deepEqual(records, original.slice(0, -2).map(record => record.sessionId === f.row.id+ ? { ...record, sessionId: id } : record));+ published = true;+ }, row => [+ { type: 'session-meta', sessionId: row.id, id: 'activation' },+ { type: 'message', role: 'user', sessionId: row.id, id: row.id, timestamp: 10000,+ content: [{ type: 'text', text: 'literal ' + row.id }] },+ { type: 'message', role: 'assistant', sessionId: row.id, id: 'reply', timestamp: 11000,+ content: [{ type: 'text', text: 'answer' }] },+ { type: 'function_call', sessionId: row.id, id: 'tool', name: 'AskUserQuestion',+ arguments: { sessionId: row.id, question: row.id } },+ { type: 'function_call_result', sessionId: row.id, call_id: 'tool', output: { sessionId: row.id } },+ { type: 'reasoning', sessionId: 'unrelated-child', payload: { sessionId: row.id } },+ { type: 'file-history-snapshot', snapshot: { sessionId: row.id } },+ { type: 'message', role: 'user', sessionId: row.id, timestamp: 12000, content: [{ type: 'text', text: 'next' }] },+ { type: 'message', role: 'assistant', sessionId: row.id, timestamp: 13000, content: [{ type: 'text', text: 'later' }] },+ ]);+ const original = f.messages.trim().split('\n').map(JSON.parse);+ await f.createForkSession(f.row, { messageIndex: 1, roles: 'uaua', finishedAt: 11000 });+ assert.equal(published, true);+ assert.equal(fs.readFileSync(f.source, 'utf8'), f.messages);});test('failed session insert removes only the newly written fork file', async (t) => {diff --git a/test/session-sync-daemon.test.js b/test/session-sync-daemon.test.jsindex c3b9064..3ccc2ed 100644--- a/test/session-sync-daemon.test.js+++ b/test/session-sync-daemon.test.js@@ -120,6 +120,65 @@ test('account two continuation updates account one and never account three', asyassert.equal((await h.copy()).copiedBytes, 0);});+test('fork and original keep separate runtime identities and continuations across workspace account switches', async t => {+ const h = harness(t, true);+ for (const [id, uid] of [['b', 'two'], ['c', 'three']]) {+ lib.removeAutoCopySessionMember(h.root, h.lineage, uid, id);+ h.rows.delete(id);+ fs.unlinkSync(h.file(id));+ }+ const fork = require('../scripts/session-fork');+ Object.assign(h.ctx, {+ Buffer, forkedTitle: fork.forkedTitle, planForkAtMessage: fork.planForkAtMessage,+ collectSessionArchiveFiles: (_root, id) => [{ path: 'projects/p/' + id + '.jsonl', source: h.file(id) }],+ ensureArchiveParentNoFollow() {},+ });+ const start = source.indexOf('async function createForkSession(');+ vm.runInNewContext(source.slice(start, source.indexOf('\nasync function prepareSessionExport(', start)), h.ctx);+ const original = h.rows.get('a');+ Object.assign(original, { cwd: '/fixture/workspace', status: 'completed', last_activity_at: 1 });+ lib.setAutoCopyRule(h.root, { uid: 'one', kind: 'workspace', key: original.cwd, enabled: true });+ const records = ['user', 'assistant', 'user', 'assistant'].map((role, index) => ({+ type: 'message', role, sessionId: 'a', timestamp: 10000 + index * 1000,+ content: [{ text: 'shared history ' + index }],+ }));+ h.write('a', records);+ const branch = await h.ctx.createForkSession(original, { messageIndex: 1, roles: 'uaua', finishedAt: 11000 });+ const read = id => fs.readFileSync(h.file(id), 'utf8').trim().split('\n').map(JSON.parse);+ assert.ok(read(branch.id).every(record => record.sessionId === branch.id), 'fork must resume as itself before switching');+ const continueSession = (id, label) => {+ h.write(id, [...read(id), { type: 'message', role: 'user', sessionId: id, content: [{ text: label }] }]);+ Object.assign(h.rows.get(id), { updated_at: Date.now(), last_activity_at: Date.now() });+ };+ continueSession(branch.id, 'branch continuation');+ continueSession('a', 'original continuation');+ const originalBefore = fs.readFileSync(h.file('a'));+ const branchBefore = fs.readFileSync(h.file(branch.id));+ const switchTo = async (from, to) => {+ for (const row of await h.ctx.buildAutoCopyPlan(from, to)) {+ await h.ctx.copySessionRecord(row, to, { auto: true, lineageId: row.lineageId });+ }+ };+ await switchTo('one', 'two');+ const branchLineage = lib.getAutoCopySession(h.root, 'one', branch.id).lineageId;+ assert.notEqual(branchLineage, h.lineage);+ const copies = [h.lineage, branchLineage].map(lineage => lib.getAutoCopyMapping(h.root, lineage, 'two').targetId);+ assert.equal(new Set(copies).size, 2);+ assert.equal([...h.rows.values()].filter(row => row.user_id === 'two' && row.deleted_at == null).length, 2);+ for (const [index, id] of copies.entries()) {+ assert.ok(read(id).every(record => record.sessionId === id));+ assert.deepEqual(read(id), read(index === 0 ? 'a' : branch.id).map(record => ({ ...record, sessionId: id })));+ }+ continueSession(copies[1], 'branch on account two');+ await switchTo('two', 'one');+ assert.deepEqual(fs.readFileSync(h.file('a')), originalBefore, 'branch edits must never overwrite the original');+ assert.notDeepEqual(fs.readFileSync(h.file(branch.id)), branchBefore);+ assert.equal(read(branch.id).at(-1).content[0].text, 'branch on account two');+ assert.ok(read(branch.id).every(record => record.sessionId === branch.id));+ const rows = [...h.rows.values()].filter(row => row.user_id === 'one');+ assert.equal(lib.dedupeAutoCopySessionRows(rows, { one: lib.getAutoCopyRules(h.root, 'one').allLineages }).length, 2);+});+test('legacy equal mappings repair runtime IDs once instead of taking the revision fast path', async t => {const h = harness(t);const records = base.map(row => ({ ...row, sessionId: 'a' }));