WorkBuddy、CodeBuddy 桌面端增强助手:签到猫猫旅行成长计划查询、多账号独立备份、点切即用;免打扰模式让 AI 无人值守跑长任务;跨账号会话迁移、异常中断自动续接;暂存/快捷提示词;毛玻璃主题与更多实用功能。
fix: handle streamed assistant records when branching sessions
[email protected]51cb3a1cbba4
diff --git a/scripts/daemon.js b/scripts/daemon.jsindex cfd6807..ef9686c 100644--- a/scripts/daemon.js+++ b/scripts/daemon.js@@ -376,8 +376,8 @@ const primaryAccountStore = createPrimaryAccountStore(DATA_DIR, (uid) => fs.exis// 1.2.52:成长任务支持在悬浮层内直接接取,并在完成后同步最新任务状态。// 1.2.55:成长弹窗支持开启盲盒与抽奖并提示奖励,收敛成长/用量统计 primary 色使用。// 1.2.56:成长任务补齐说明与标签、已领取折叠、Buddy 派出,并把用量柱状图改为面积折线图。-const DAEMON_VERSION = '1.2.75';-const DAEMON_BUILD_ID = 'release-1.2.75-20260919-session-fork-stream-alignment';+const DAEMON_VERSION = '1.2.76';+const DAEMON_BUILD_ID = 'release-1.2.76-20260919-session-fork-stream-alignment-fix';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/session-fork.js b/scripts/session-fork.jsindex c84e110..59ec221 100644--- a/scripts/session-fork.js+++ b/scripts/session-fork.js@@ -190,20 +190,20 @@ function planForkAtMessage(text, selection) {const roles = selection && selection.roles;const index = selection && selection.messageIndex;const finishedAt = selection && selection.finishedAt;- if (typeof roles !== 'string' || !/^(?:ua){1,5000}$/.test(roles) ||+ if (typeof roles !== 'string' || !/^[ua]{2,10000}$/.test(roles) ||+ roles[0] !== 'u' || roles[roles.length - 1] !== 'a' ||!Number.isInteger(index) || index < 0 || index >= roles.length ||+ roles[index] !== 'a' ||!Number.isSafeInteger(finishedAt) || finishedAt <= 0) {return invalid('分支消息参数无效');}const parsed = parseRecords(text);if (parsed.skipped) return invalid('会话记录正在写入或包含损坏的行,请稍后重试');- if (index % 2 !== 1) return invalid('无法确认所选消息的分支位置');// The renderer may hide task-notification user records and merge consecutive- // assistant records from one streamed turn. The alternating visible role- // shape guards the selection, while finishedAt identifies the exact JSONL- // assistant record without assuming the two representations have the same- // number of records.+ // assistant records from one streamed turn. The selected role guards the+ // index, while finishedAt identifies the exact JSONL assistant record without+ // assuming the two representations have the same number of records.const messages = parsed.records.map((entry, recordIndex) => ({recordIndex, value: entry.value,})).filter((entry) => entry.value && entry.value.type === 'message' &&@@ -212,10 +212,10 @@ function planForkAtMessage(text, selection) {const rawRoles = messages.map((entry) => entry.value.role === 'user' ? 'u' : 'a').join('');let selected;if (rawRoles === roles) {- // In the compact representation, messageIndex identifies the assistant- // ordinal directly. Preserve the timestamp tolerance, but do not fall- // through to a different assistant if this record is malformed.- selected = assistantMessages[Math.floor(index / 2)];+ // When both sides expose the same record shape, messageIndex is the+ // renderer message position. This also handles consecutive assistant+ // records emitted by streamed replies.+ selected = messages[index];} else {// In streamed files, the same visible assistant can span several JSONL// records. The completion timestamp is the stable cross-representation key.diff --git a/test/automation-model.test.js b/test/automation-model.test.jsindex f7346b8..cf34580 100644--- a/test/automation-model.test.js+++ b/test/automation-model.test.js@@ -159,7 +159,7 @@ test('daemon selects and checks the model before sending, and ships the rendererassert.ok(selectAt > 0 && sendAt > selectAt);assert.match(daemon, /if \(modelId\) await confirmAutomationModel\(modelId/);assert.match(daemon, /restoreAutomationNewTaskPreference\(modelSelection\)/);- assert.match(daemon, /const DAEMON_VERSION = '1\.2\.74'/);+ assert.match(daemon, /const DAEMON_VERSION = '1\.2\.76'/);const staging = fs.readFileSync(path.join(__dirname, '../scripts/build-mac-dmg.sh'), 'utf8');assert.match(staging, /automation-model\.js/);});diff --git a/test/session-fork.test.js b/test/session-fork.test.jsindex 7abfed5..946289c 100644--- a/test/session-fork.test.js+++ b/test/session-fork.test.js@@ -168,13 +168,32 @@ test('renderer message position forks only when roles and completion time matchassert.equal(result.drop, 2);assert.deepEqual(parseRecords(result.text).records.map((item) => item.value.role), ['user', 'assistant']);assert.equal(planForkAtMessage(text, { ...choice, roles: 'auua' }).ok, false);- assert.equal(planForkAtMessage(text, { ...choice, roles: 'uaa' }).ok, false);+ assert.equal(planForkAtMessage(text, { ...choice, roles: 'uaua', messageIndex: 0 }).ok, false);assert.equal(planForkAtMessage(text, { ...choice, messageIndex: 2 }).ok, false);assert.equal(planForkAtMessage(text, { ...choice, finishedAt: T0 + 120000 }).ok, false);assert.equal(planForkAtMessage(toText(records.map((record, i) => i === 1 ? { ...record, timestamp: 'invalid' } : record)), choice).ok, false);assert.equal(planForkAtMessage(text + '{bad\n', choice).ok, false);});+test('renderer message position accepts consecutive assistant stream records', () => {+ const records = [+ { type: 'message', role: 'user', timestamp: T0, content: [{ type: 'text', text: '问题一' }] },+ { type: 'message', role: 'assistant', timestamp: T0 + 1000, content: [{ type: 'text', text: '回答一' }] },+ { type: 'message', role: 'user', timestamp: T0 + 2000, content: [{ type: 'text', text: '问题二' }] },+ { type: 'message', role: 'assistant', timestamp: T0 + 3000, content: [{ type: 'text', text: '回答二的开头' }] },+ { type: 'message', role: 'assistant', timestamp: T0 + 4000, content: [{ type: 'text', text: '回答二的结尾' }] },+ { type: 'message', role: 'user', timestamp: T0 + 5000, content: [{ type: 'text', text: '问题三' }] },+ { type: 'message', role: 'assistant', timestamp: T0 + 6000, content: [{ type: 'text', text: '回答三' }] },+ ];+ const result = planForkAtMessage(toText(records), {+ messageIndex: 6,+ roles: 'uauaaua',+ finishedAt: T0 + 6000,+ });+ assert.equal(result.ok, true);+ assert.equal(result.drop, 0);+});+test('renderer fork matching ignores task notifications and groups streamed assistant records', () => {const records = [{ type: 'message', role: 'user', timestamp: T0, content: [{ type: 'text', text: '<system-reminder><user_query>问题一</user_query></system-reminder>' }] },