mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
fix(panel): allocate isolated UUIDs in session full-move mode to prevent cross-client mirror deletion
This commit is contained in:
+19
-35
@@ -1827,7 +1827,7 @@ const I18N_MESSAGES_ZH_CN = Object.freeze({
|
|||||||
'settings.oth.migModeLabel': '迁移方式',
|
'settings.oth.migModeLabel': '迁移方式',
|
||||||
'settings.oth.migModeMove': '完整迁移(推荐)',
|
'settings.oth.migModeMove': '完整迁移(推荐)',
|
||||||
'settings.oth.migModeClone': '克隆副本',
|
'settings.oth.migModeClone': '克隆副本',
|
||||||
'settings.oth.migModeMoveHint': '保留原 ID 和全部历史步序明细,备份后移出源端(零重复计费)',
|
'settings.oth.migModeMoveHint': '分配目标端独立会话 ID 并完整保留全部历史步序明细,备份后移出源端(零重复计费;迁移前建议先关闭源端该会话)',
|
||||||
'settings.oth.migModeCloneHint': '保留源会话并生成新 ID,新副本仅统计迁入后的新步骤',
|
'settings.oth.migModeCloneHint': '保留源会话并生成新 ID,新副本仅统计迁入后的新步骤',
|
||||||
'settings.oth.migProjectLabel': '绑定目标项目',
|
'settings.oth.migProjectLabel': '绑定目标项目',
|
||||||
'settings.oth.migProjectOutside': '独立会话(无所属项目)',
|
'settings.oth.migProjectOutside': '独立会话(无所属项目)',
|
||||||
@@ -2624,7 +2624,7 @@ const I18N_MESSAGES_EN_US = Object.freeze({
|
|||||||
'settings.oth.migModeLabel': 'Migration Mode',
|
'settings.oth.migModeLabel': 'Migration Mode',
|
||||||
'settings.oth.migModeMove': 'Full Move (Recommended)',
|
'settings.oth.migModeMove': 'Full Move (Recommended)',
|
||||||
'settings.oth.migModeClone': 'Clone Copy',
|
'settings.oth.migModeClone': 'Clone Copy',
|
||||||
'settings.oth.migModeMoveHint': 'Preserves original ID and full historical steps/details; archives source backup before moving',
|
'settings.oth.migModeMoveHint': 'Assigns an isolated target ID while preserving all historical steps/details; archives source backup before moving (close source session first)',
|
||||||
'settings.oth.migModeCloneHint': 'Keeps source intact with a fresh UUID; only counts new steps generated after cloning',
|
'settings.oth.migModeCloneHint': 'Keeps source intact with a fresh UUID; only counts new steps generated after cloning',
|
||||||
'settings.oth.migProjectLabel': 'Target Project',
|
'settings.oth.migProjectLabel': 'Target Project',
|
||||||
'settings.oth.migProjectOutside': 'Standalone (No Project)',
|
'settings.oth.migProjectOutside': 'Standalone (No Project)',
|
||||||
@@ -21856,87 +21856,74 @@ function isSameList(a, b) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildCliPreviewMiniBar(pct, width = 8, emptyChar = '⢕') {
|
|
||||||
const clamped = Math.max(0, Math.min(100, Number(pct)));
|
|
||||||
let filled = Math.round((clamped / 100) * width);
|
|
||||||
if (clamped > 0 && filled === 0) filled = 1;
|
|
||||||
if (clamped < 95 && filled >= width) filled = Math.max(0, width - 1);
|
|
||||||
return {
|
|
||||||
barFilled: '█'.repeat(filled),
|
|
||||||
barEmpty: emptyChar.repeat(Math.max(0, width - filled)),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatCliPreviewSlot(slotKey, isEn) {
|
function formatCliPreviewSlot(slotKey, isEn) {
|
||||||
switch (slotKey) {
|
switch (slotKey) {
|
||||||
case 'tps':
|
case 'tps':
|
||||||
return { prefix: '', barFilled: '', barEmpty: '', text: '68.4 t/s', tone: 'good' };
|
return { prefix: '', text: '68.4 t/s', tone: 'good', pillPct: null };
|
||||||
case 'avg_tps':
|
case 'avg_tps':
|
||||||
return {
|
return {
|
||||||
prefix: '',
|
prefix: '',
|
||||||
barFilled: '',
|
|
||||||
barEmpty: '',
|
|
||||||
text: isEn ? 'avg 54.0' : '均 54.0',
|
text: isEn ? 'avg 54.0' : '均 54.0',
|
||||||
tone: 'info',
|
tone: 'info',
|
||||||
|
pillPct: null,
|
||||||
};
|
};
|
||||||
case 'ttft':
|
case 'ttft':
|
||||||
return { prefix: '', barFilled: '', barEmpty: '', text: '1.1s', tone: 'good' };
|
return { prefix: '', text: '1.1s', tone: 'good', pillPct: null };
|
||||||
case 'cost':
|
case 'cost':
|
||||||
return { prefix: '', barFilled: '', barEmpty: '', text: '$0.040', tone: 'normal' };
|
return { prefix: '', text: '$0.040', tone: 'normal', pillPct: null };
|
||||||
case 'session_cost':
|
case 'session_cost':
|
||||||
return { prefix: '', barFilled: '', barEmpty: '', text: '$0.42', tone: 'normal' };
|
return { prefix: '', text: '$0.42', tone: 'normal', pillPct: null };
|
||||||
case 'cache_hit':
|
case 'cache_hit':
|
||||||
return {
|
return {
|
||||||
prefix: '',
|
prefix: '',
|
||||||
barFilled: '',
|
|
||||||
barEmpty: '',
|
|
||||||
text: isEn ? 'cache 92%' : '缓 92%',
|
text: isEn ? 'cache 92%' : '缓 92%',
|
||||||
tone: 'good',
|
tone: 'good',
|
||||||
|
pillPct: null,
|
||||||
};
|
};
|
||||||
case 'session_tokens':
|
case 'session_tokens':
|
||||||
return { prefix: '', barFilled: '', barEmpty: '', text: '142K tok', tone: 'muted' };
|
return { prefix: '', text: '142K tok', tone: 'muted', pillPct: null };
|
||||||
case 'quota_auto':
|
case 'quota_auto':
|
||||||
return {
|
return {
|
||||||
prefix: isEn ? '5h ' : '余 ',
|
prefix: isEn ? '5h ' : '余 ',
|
||||||
...buildCliPreviewMiniBar(64, 8, '⣿'),
|
|
||||||
text: '64%',
|
text: '64%',
|
||||||
tone: 'good',
|
tone: 'good',
|
||||||
|
pillPct: 64,
|
||||||
};
|
};
|
||||||
case 'gemini_5h':
|
case 'gemini_5h':
|
||||||
return {
|
return {
|
||||||
prefix: 'G5h ',
|
prefix: 'G5h ',
|
||||||
...buildCliPreviewMiniBar(64, 8, '⣿'),
|
|
||||||
text: '64%',
|
text: '64%',
|
||||||
tone: 'good',
|
tone: 'good',
|
||||||
|
pillPct: 64,
|
||||||
};
|
};
|
||||||
case 'gemini_weekly':
|
case 'gemini_weekly':
|
||||||
return {
|
return {
|
||||||
prefix: isEn ? 'Gw ' : 'G周 ',
|
prefix: isEn ? 'Gw ' : 'G周 ',
|
||||||
...buildCliPreviewMiniBar(88, 8, '⣿'),
|
|
||||||
text: '88%',
|
text: '88%',
|
||||||
tone: 'good',
|
tone: 'good',
|
||||||
|
pillPct: 88,
|
||||||
};
|
};
|
||||||
case 'claude_5h':
|
case 'claude_5h':
|
||||||
return {
|
return {
|
||||||
prefix: 'C5h ',
|
prefix: 'C5h ',
|
||||||
...buildCliPreviewMiniBar(96, 8, '⣿'),
|
|
||||||
text: '96%',
|
text: '96%',
|
||||||
tone: 'good',
|
tone: 'good',
|
||||||
|
pillPct: 96,
|
||||||
};
|
};
|
||||||
case 'claude_weekly':
|
case 'claude_weekly':
|
||||||
return {
|
return {
|
||||||
prefix: isEn ? 'Cw ' : 'C周 ',
|
prefix: isEn ? 'Cw ' : 'C周 ',
|
||||||
...buildCliPreviewMiniBar(99, 8, '⣿'),
|
|
||||||
text: '99%',
|
text: '99%',
|
||||||
tone: 'good',
|
tone: 'good',
|
||||||
|
pillPct: 99,
|
||||||
};
|
};
|
||||||
case 'context':
|
case 'context':
|
||||||
default:
|
default:
|
||||||
return {
|
return {
|
||||||
prefix: isEn ? 'Ctx ' : '上下文 ',
|
prefix: isEn ? 'Ctx ' : '上下文 ',
|
||||||
...buildCliPreviewMiniBar(56),
|
|
||||||
text: '56%',
|
text: '56%',
|
||||||
tone: 'accent',
|
tone: 'accent',
|
||||||
|
pillPct: 56,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22256,16 +22243,12 @@ const SettingsStructureTab = defineComponent({
|
|||||||
cliPreviewChildren.push(sepEl);
|
cliPreviewChildren.push(sepEl);
|
||||||
}
|
}
|
||||||
const prefixEl = h('span', { className: 'cli-preview-prefix' });
|
const prefixEl = h('span', { className: 'cli-preview-prefix' });
|
||||||
const barFillEl = h('span', { className: 'cli-preview-bar-fill' });
|
|
||||||
const barEmptyEl = h('span', { className: 'cli-preview-bar-empty' });
|
|
||||||
const valueEl = h('span', { className: 'cli-preview-val' });
|
const valueEl = h('span', { className: 'cli-preview-val' });
|
||||||
const slotEl = h('span', { className: 'cli-preview-slot' }, [
|
const slotEl = h('span', { className: 'cli-preview-slot' }, [
|
||||||
prefixEl,
|
prefixEl,
|
||||||
barFillEl,
|
|
||||||
barEmptyEl,
|
|
||||||
valueEl,
|
valueEl,
|
||||||
]);
|
]);
|
||||||
cliPreviewSlotParts.push({ slotEl, prefixEl, barFillEl, barEmptyEl, valueEl });
|
cliPreviewSlotParts.push({ slotEl, prefixEl, valueEl });
|
||||||
cliPreviewChildren.push(slotEl);
|
cliPreviewChildren.push(slotEl);
|
||||||
}
|
}
|
||||||
const cliPreviewEl = h('div', { className: 'cli-status-preview' }, cliPreviewChildren);
|
const cliPreviewEl = h('div', { className: 'cli-status-preview' }, cliPreviewChildren);
|
||||||
@@ -22398,12 +22381,13 @@ const SettingsStructureTab = defineComponent({
|
|||||||
if (sepEl) patchAttr(sepEl, 'hidden', !visible);
|
if (sepEl) patchAttr(sepEl, 'hidden', !visible);
|
||||||
if (visible) {
|
if (visible) {
|
||||||
const item = formatCliPreviewSlot(key, isEn);
|
const item = formatCliPreviewSlot(key, isEn);
|
||||||
|
const isPill = Number.isFinite(item.pillPct);
|
||||||
patchAttr(parts.slotEl, 'data-metric', key);
|
patchAttr(parts.slotEl, 'data-metric', key);
|
||||||
patchText(parts.prefixEl, item.prefix || '');
|
patchText(parts.prefixEl, item.prefix || '');
|
||||||
patchText(parts.barFillEl, item.barFilled || '');
|
|
||||||
patchText(parts.barEmptyEl, item.barEmpty || '');
|
|
||||||
patchText(parts.valueEl, item.text || '');
|
patchText(parts.valueEl, item.text || '');
|
||||||
|
patchStyleVar(parts.slotEl, '--cli-pill-pct', isPill ? `${item.pillPct}%` : '');
|
||||||
patchClasses(parts.slotEl, {
|
patchClasses(parts.slotEl, {
|
||||||
|
'is-pill': isPill,
|
||||||
'tone-good': item.tone === 'good',
|
'tone-good': item.tone === 'good',
|
||||||
'tone-info': item.tone === 'info',
|
'tone-info': item.tone === 'info',
|
||||||
'tone-accent': item.tone === 'accent',
|
'tone-accent': item.tone === 'accent',
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
* @fileoverview 跨端会话按需迁移器 (`session-migrator.mjs`)。
|
* @fileoverview 跨端会话按需迁移器 (`session-migrator.mjs`)。
|
||||||
*
|
*
|
||||||
* 支持两种显式模式:
|
* 支持两种显式模式:
|
||||||
* 1. `move`(默认「完整迁移」):保留原 `cascade_id` 和 `trajectory_id`,先将源 `.db` 一致性快照备份归档,
|
* 1. `move`(默认「完整迁移」):为目标端分配独立的新 `cascade_id` / `trajectory_id`(避免撞上桌面端/CLI
|
||||||
* 再安全移入目标端并清理源端 `.db` 及摘要行——迁入后完整保留全部历史步序(#1/#3/#5…)、上下文和调用明细,
|
* 跨端摘要镜像同步导致被自动删行或覆盖),先将源 `.db` 一致性快照备份归档,再把目标库中属于源会话的步骤
|
||||||
* 且全局仅存一份天然零重复计费;若源 `.db` 正被原客户端锁住(`EBUSY`/`EPERM`),安全回滚并提示关闭原端;
|
* `sourceTrajectoryStepInfo.cascadeId` 及 `gen_metadata` 归属 ID 结构化改写为新 ID,随后安全移出源端
|
||||||
|
* `.db` 及摘要行——迁入后完整保留全部历史步序(#1/#3/#5…)、上下文和调用明细,且全局仅存一份天然零重复计费;
|
||||||
* 2. `clone`(可选「克隆副本」):生成全新 UUID,源端 100% 保持不动;保留历史步骤原有的 `originCascadeId`,
|
* 2. `clone`(可选「克隆副本」):生成全新 UUID,源端 100% 保持不动;保留历史步骤原有的 `originCascadeId`,
|
||||||
* 由 `cli-sqlite-reader.mjs` 自动跳过克隆历史步,仅统计迁入后新产生的步骤(避免跨端双倍计费)。
|
* 由 `cli-sqlite-reader.mjs` 自动跳过克隆历史步,仅统计迁入后新产生的步骤(避免跨端双倍计费)。
|
||||||
*
|
*
|
||||||
@@ -767,7 +768,10 @@ function migratorBuildWorkspaceSubmessage(rawUri, targetClientId) {
|
|||||||
return Buffer.concat([encodeProtoStringField(1, rawUri), encodeProtoStringField(2, rawUri)]);
|
return Buffer.concat([encodeProtoStringField(1, rawUri), encodeProtoStringField(2, rawUri)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function migratorBuildSummaryMetaBlob(sourceMetaBlob, { newCid, targetClientId, targetProjectId, rawUri, encodedUri }) {
|
function migratorBuildSummaryMetaBlob(
|
||||||
|
sourceMetaBlob,
|
||||||
|
{ srcCid = '', newCid, targetClientId, targetProjectId, rawUri, encodedUri }
|
||||||
|
) {
|
||||||
const wsBytes = migratorBuildWorkspaceSubmessage(rawUri, targetClientId);
|
const wsBytes = migratorBuildWorkspaceSubmessage(rawUri, targetClientId);
|
||||||
const primaryUri = targetClientId === 'cli' ? rawUri : encodedUri;
|
const primaryUri = targetClientId === 'cli' ? rawUri : encodedUri;
|
||||||
const replacements = new Map([
|
const replacements = new Map([
|
||||||
@@ -778,6 +782,12 @@ function migratorBuildSummaryMetaBlob(sourceMetaBlob, { newCid, targetClientId,
|
|||||||
[18, encodeProtoStringField(18, targetProjectId)],
|
[18, encodeProtoStringField(18, targetProjectId)],
|
||||||
]);
|
]);
|
||||||
if (sourceMetaBlob && sourceMetaBlob.byteLength > 0) {
|
if (sourceMetaBlob && sourceMetaBlob.byteLength > 0) {
|
||||||
|
if (srcCid) {
|
||||||
|
const fn8 = splitProtoRawFields(sourceMetaBlob).find((f) => f.fn === 8 && f.wt === 2);
|
||||||
|
if (fn8 && fn8.payload.toString('utf8').trim().toLowerCase() === srcCid) {
|
||||||
|
replacements.set(8, encodeProtoStringField(8, newCid));
|
||||||
|
}
|
||||||
|
}
|
||||||
return patchProtoMessageFields(sourceMetaBlob, replacements);
|
return patchProtoMessageFields(sourceMetaBlob, replacements);
|
||||||
}
|
}
|
||||||
const parts = [];
|
const parts = [];
|
||||||
@@ -788,9 +798,107 @@ function migratorBuildSummaryMetaBlob(sourceMetaBlob, { newCid, targetClientId,
|
|||||||
return Buffer.concat(parts);
|
return Buffer.concat(parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在「完整迁移」模式下,仅定向改写单步 `metadata` 中的 `sourceTrajectoryStepInfo`(`fn 20`)
|
||||||
|
* 的 `cascadeId`(`fn 4`)及 `trajectoryId`(`fn 1`),绝不触碰工具参数路径或外部父会话 ID。
|
||||||
|
*
|
||||||
|
* @param {Uint8Array | Buffer} rawBlob
|
||||||
|
* @param {{ srcCid: string, newCid: string, srcTid?: string, newTid?: string }} ids
|
||||||
|
* @returns {Buffer | null} 若无需改写则返回 `null`
|
||||||
|
*/
|
||||||
|
function migratorPatchStepMetadataOwnership(rawBlob, { srcCid, newCid, srcTid = '', newTid = '' }) {
|
||||||
|
const u8 = toUint8Array(rawBlob);
|
||||||
|
if (!u8 || u8.byteLength === 0) return null;
|
||||||
|
const buf = Buffer.from(u8.buffer, u8.byteOffset, u8.byteLength);
|
||||||
|
const hasCid = srcCid && buf.includes(srcCid);
|
||||||
|
const hasTid = srcTid && newTid && buf.includes(srcTid);
|
||||||
|
if (!hasCid && !hasTid) return null;
|
||||||
|
|
||||||
|
const topFields = splitProtoRawFields(buf);
|
||||||
|
const fn20 = topFields.find((f) => f.fn === 20 && f.wt === 2);
|
||||||
|
if (!fn20) return null;
|
||||||
|
|
||||||
|
const subFields = splitProtoRawFields(fn20.payload);
|
||||||
|
const subReplacements = new Map();
|
||||||
|
for (const sf of subFields) {
|
||||||
|
if (sf.fn === 4 && sf.wt === 2 && srcCid) {
|
||||||
|
if (sf.payload.toString('utf8').trim().toLowerCase() === srcCid) {
|
||||||
|
subReplacements.set(4, encodeProtoStringField(4, newCid));
|
||||||
|
}
|
||||||
|
} else if (sf.fn === 1 && sf.wt === 2 && srcTid && newTid) {
|
||||||
|
if (sf.payload.toString('utf8').trim().toLowerCase() === srcTid) {
|
||||||
|
subReplacements.set(1, encodeProtoStringField(1, newTid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (subReplacements.size === 0) return null;
|
||||||
|
|
||||||
|
const patchedSub = patchProtoMessageFields(fn20.payload, subReplacements);
|
||||||
|
return patchProtoMessageFields(buf, new Map([[20, encodeProtoBytesField(20, patchedSub)]]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在「完整迁移」模式下,仅定向改写 `gen_metadata.data` 中 `chatModel`(`fn 1`)的 `extraMeta`
|
||||||
|
* 重复映射字段(`fn 20`)里 `cascade_id` / `root_cascade_id` 等于 `srcCid` 的值,保留其余全部字段和提示词原文。
|
||||||
|
*
|
||||||
|
* @param {Uint8Array | Buffer} rawBlob
|
||||||
|
* @param {string} srcCid
|
||||||
|
* @param {string} newCid
|
||||||
|
* @returns {Buffer | null} 若无需改写则返回 `null`
|
||||||
|
*/
|
||||||
|
function migratorPatchGenMetadataOwnership(rawBlob, srcCid, newCid) {
|
||||||
|
const u8 = toUint8Array(rawBlob);
|
||||||
|
if (!u8 || u8.byteLength === 0 || !srcCid) return null;
|
||||||
|
const buf = Buffer.from(u8.buffer, u8.byteOffset, u8.byteLength);
|
||||||
|
if (!buf.includes(srcCid)) return null;
|
||||||
|
|
||||||
|
const topFields = splitProtoRawFields(buf);
|
||||||
|
let topChanged = false;
|
||||||
|
const rebuiltTop = [];
|
||||||
|
|
||||||
|
for (const field of topFields) {
|
||||||
|
if (field.fn === 1 && field.wt === 2 && field.payload.includes(srcCid)) {
|
||||||
|
const chatFields = splitProtoRawFields(field.payload);
|
||||||
|
let chatChanged = false;
|
||||||
|
const rebuiltChat = [];
|
||||||
|
for (const cf of chatFields) {
|
||||||
|
if (cf.fn === 20 && cf.wt === 2 && cf.payload.includes(srcCid)) {
|
||||||
|
const kvFields = splitProtoRawFields(cf.payload);
|
||||||
|
const keyField = kvFields.find((item) => item.fn === 1 && item.wt === 2);
|
||||||
|
const valField = kvFields.find((item) => item.fn === 2 && item.wt === 2);
|
||||||
|
const keyStr = keyField ? keyField.payload.toString('utf8').trim() : '';
|
||||||
|
const valStr = valField ? valField.payload.toString('utf8').trim().toLowerCase() : '';
|
||||||
|
if (
|
||||||
|
(keyStr === 'cascade_id' || keyStr === 'root_cascade_id') &&
|
||||||
|
valStr === srcCid
|
||||||
|
) {
|
||||||
|
const patchedEntry = patchProtoMessageFields(
|
||||||
|
cf.payload,
|
||||||
|
new Map([[2, encodeProtoStringField(2, newCid)]])
|
||||||
|
);
|
||||||
|
rebuiltChat.push(encodeProtoBytesField(20, patchedEntry));
|
||||||
|
chatChanged = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rebuiltChat.push(cf.raw);
|
||||||
|
}
|
||||||
|
if (chatChanged) {
|
||||||
|
rebuiltTop.push(encodeProtoBytesField(1, Buffer.concat(rebuiltChat)));
|
||||||
|
topChanged = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rebuiltTop.push(field.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
return topChanged ? Buffer.concat(rebuiltTop) : null;
|
||||||
|
}
|
||||||
|
|
||||||
function migratorBuildPatchedRawSummary({
|
function migratorBuildPatchedRawSummary({
|
||||||
sourceRawSummary,
|
sourceRawSummary,
|
||||||
sourceMetaBlob,
|
sourceMetaBlob,
|
||||||
|
srcCid = '',
|
||||||
newCid,
|
newCid,
|
||||||
newTid,
|
newTid,
|
||||||
title,
|
title,
|
||||||
@@ -816,6 +924,7 @@ function migratorBuildPatchedRawSummary({
|
|||||||
const rawFields = splitProtoRawFields(sourceRawSummary);
|
const rawFields = splitProtoRawFields(sourceRawSummary);
|
||||||
const fn17 = rawFields.find((f) => f.fn === 17 && f.wt === 2);
|
const fn17 = rawFields.find((f) => f.fn === 17 && f.wt === 2);
|
||||||
const patchedFn17 = migratorBuildSummaryMetaBlob(fn17?.payload || sourceMetaBlob, {
|
const patchedFn17 = migratorBuildSummaryMetaBlob(fn17?.payload || sourceMetaBlob, {
|
||||||
|
srcCid,
|
||||||
newCid,
|
newCid,
|
||||||
targetClientId,
|
targetClientId,
|
||||||
targetProjectId,
|
targetProjectId,
|
||||||
@@ -836,6 +945,7 @@ function migratorBuildPatchedRawSummary({
|
|||||||
[20, null], // 清除来源覆盖标记,交由目标端原生识别
|
[20, null], // 清除来源覆盖标记,交由目标端原生识别
|
||||||
[21, null], // 清除未空闲标志
|
[21, null], // 清除未空闲标志
|
||||||
[23, null], // 清除终止标志
|
[23, null], // 清除终止标志
|
||||||
|
[26, null], // 清除运行中附加状态标志
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -844,6 +954,7 @@ function migratorBuildPatchedRawSummary({
|
|||||||
const createdTsBytes = encodeProtoTimestamp(createdMs || nowMs);
|
const createdTsBytes = encodeProtoTimestamp(createdMs || nowMs);
|
||||||
const lastUiTsBytes = encodeProtoTimestamp(lastUserInputMs || nowMs);
|
const lastUiTsBytes = encodeProtoTimestamp(lastUserInputMs || nowMs);
|
||||||
const synthMeta = migratorBuildSummaryMetaBlob(sourceMetaBlob, {
|
const synthMeta = migratorBuildSummaryMetaBlob(sourceMetaBlob, {
|
||||||
|
srcCid,
|
||||||
newCid,
|
newCid,
|
||||||
targetClientId,
|
targetClientId,
|
||||||
targetProjectId,
|
targetProjectId,
|
||||||
@@ -1100,14 +1211,11 @@ export function migrateSessions(params = {}, options = {}) {
|
|||||||
const rawUri = migratorToRawFileUri(effectiveWsInput);
|
const rawUri = migratorToRawFileUri(effectiveWsInput);
|
||||||
const encodedUri = migratorToDesktopEncodedUri(effectiveWsInput);
|
const encodedUri = migratorToDesktopEncodedUri(effectiveWsInput);
|
||||||
|
|
||||||
const newCid = mode === 'move' ? srcCid : randomUUID();
|
// 两种模式统一分配全新 UUID:Antigravity 桌面端和 CLI 会互相镜像对方的 conversation_summaries.db,
|
||||||
|
// 复用原 UUID 会在移除源摘要行时触发目标端 language_server 将同 ID 行反手删掉或覆盖回 CLI 镜像。
|
||||||
|
const newCid = randomUUID();
|
||||||
|
const newTid = randomUUID();
|
||||||
const dstDbPath = join(dstConvDir, `${newCid}.db`);
|
const dstDbPath = join(dstConvDir, `${newCid}.db`);
|
||||||
if (mode === 'move' && existsSync(dstDbPath)) {
|
|
||||||
results.push({ ok: false, sourceCascadeId: srcCid, error: 'target_already_exists' });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let newTid = randomUUID();
|
|
||||||
const itemNowMs = baseNowMs + i;
|
const itemNowMs = baseNowMs + i;
|
||||||
const itemNowSql = migratorFormatSqliteUtcTime(itemNowMs);
|
const itemNowSql = migratorFormatSqliteUtcTime(itemNowMs);
|
||||||
const dstBrainDir = join(dstRoot, 'brain', newCid);
|
const dstBrainDir = join(dstRoot, 'brain', newCid);
|
||||||
@@ -1128,23 +1236,19 @@ export function migrateSessions(params = {}, options = {}) {
|
|||||||
srcDb.exec(`VACUUM INTO '${escapedDst}'`);
|
srcDb.exec(`VACUUM INTO '${escapedDst}'`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. 在目标库中改写 trajectory_meta 和 trajectory_metadata_blob
|
// 2. 在目标库中改写 trajectory_meta 和 trajectory_metadata_blob;
|
||||||
// 移动模式保留原 trajectory_id 和 cascade_id,使所有历史步序(#1/#3/#5…)在目标端完整连贯呈现
|
// 移动模式同步把属于源会话的历史步 metadata 及 gen_metadata 归属 ID 重写为 newCid,
|
||||||
|
// 使迁入后的全部历史步序(#1/#3/#5…)在目标端完整连贯呈现且不撞跨端摘要镜像。
|
||||||
let sourceMetaBlob = null;
|
let sourceMetaBlob = null;
|
||||||
migratorOpenWritableDbWithRetry(dstDbPath, (dstDb) => {
|
migratorOpenWritableDbWithRetry(dstDbPath, (dstDb) => {
|
||||||
if (mode === 'move') {
|
|
||||||
const origMeta = dstDb.prepare('SELECT trajectory_id FROM trajectory_meta LIMIT 1').get();
|
const origMeta = dstDb.prepare('SELECT trajectory_id FROM trajectory_meta LIMIT 1').get();
|
||||||
if (origMeta?.trajectory_id) {
|
const srcTid = String(origMeta?.trajectory_id || '').trim().toLowerCase();
|
||||||
newTid = String(origMeta.trajectory_id).trim();
|
|
||||||
}
|
dstDb.exec('BEGIN IMMEDIATE');
|
||||||
dstDb
|
try {
|
||||||
.prepare('UPDATE trajectory_meta SET source = ?')
|
|
||||||
.run(dstDef.trajectorySourceNum);
|
|
||||||
} else {
|
|
||||||
dstDb
|
dstDb
|
||||||
.prepare('UPDATE trajectory_meta SET trajectory_id = ?, cascade_id = ?, source = ?')
|
.prepare('UPDATE trajectory_meta SET trajectory_id = ?, cascade_id = ?, source = ?')
|
||||||
.run(newTid, newCid, dstDef.trajectorySourceNum);
|
.run(newTid, newCid, dstDef.trajectorySourceNum);
|
||||||
}
|
|
||||||
|
|
||||||
const metaRow = dstDb
|
const metaRow = dstDb
|
||||||
.prepare("SELECT data FROM trajectory_metadata_blob WHERE id = 'main' LIMIT 1")
|
.prepare("SELECT data FROM trajectory_metadata_blob WHERE id = 'main' LIMIT 1")
|
||||||
@@ -1153,19 +1257,68 @@ export function migrateSessions(params = {}, options = {}) {
|
|||||||
sourceMetaBlob = Buffer.from(metaRow.data);
|
sourceMetaBlob = Buffer.from(metaRow.data);
|
||||||
const wsBytes = migratorBuildWorkspaceSubmessage(rawUri, dstDef.id);
|
const wsBytes = migratorBuildWorkspaceSubmessage(rawUri, dstDef.id);
|
||||||
const primaryMetaUri = dstDef.id === 'cli' ? rawUri : encodedUri;
|
const primaryMetaUri = dstDef.id === 'cli' ? rawUri : encodedUri;
|
||||||
const patchedMeta = patchProtoMessageFields(
|
const metaReplacements = new Map([
|
||||||
sourceMetaBlob,
|
|
||||||
new Map([
|
|
||||||
[1, wsBytes.length > 0 ? encodeProtoBytesField(1, wsBytes) : null],
|
[1, wsBytes.length > 0 ? encodeProtoBytesField(1, wsBytes) : null],
|
||||||
[6, encodeProtoStringField(6, newCid)],
|
[6, encodeProtoStringField(6, newCid)],
|
||||||
[7, primaryMetaUri ? encodeProtoStringField(7, primaryMetaUri) : null],
|
[7, primaryMetaUri ? encodeProtoStringField(7, primaryMetaUri) : null],
|
||||||
[18, encodeProtoStringField(18, resolvedProjectId)],
|
[18, encodeProtoStringField(18, resolvedProjectId)],
|
||||||
])
|
]);
|
||||||
);
|
const fn8 = splitProtoRawFields(sourceMetaBlob).find((f) => f.fn === 8 && f.wt === 2);
|
||||||
|
if (fn8 && fn8.payload.toString('utf8').trim().toLowerCase() === srcCid) {
|
||||||
|
metaReplacements.set(8, encodeProtoStringField(8, newCid));
|
||||||
|
}
|
||||||
|
const patchedMeta = patchProtoMessageFields(sourceMetaBlob, metaReplacements);
|
||||||
dstDb
|
dstDb
|
||||||
.prepare("UPDATE trajectory_metadata_blob SET data = ? WHERE id = 'main'")
|
.prepare("UPDATE trajectory_metadata_blob SET data = ? WHERE id = 'main'")
|
||||||
.run(patchedMeta);
|
.run(patchedMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mode === 'move') {
|
||||||
|
try {
|
||||||
|
const stepRows = dstDb
|
||||||
|
.prepare('SELECT idx, metadata FROM steps WHERE metadata IS NOT NULL')
|
||||||
|
.all();
|
||||||
|
const updStep = dstDb.prepare('UPDATE steps SET metadata = ? WHERE idx = ?');
|
||||||
|
for (const row of stepRows || []) {
|
||||||
|
const patched = migratorPatchStepMetadataOwnership(row.metadata, {
|
||||||
|
srcCid,
|
||||||
|
newCid,
|
||||||
|
srcTid,
|
||||||
|
newTid,
|
||||||
|
});
|
||||||
|
if (patched) {
|
||||||
|
updStep.run(patched, row.idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 兼容不含 steps 表的最小结构
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const genRows = dstDb
|
||||||
|
.prepare('SELECT idx, data FROM gen_metadata WHERE data IS NOT NULL')
|
||||||
|
.all();
|
||||||
|
const updGen = dstDb.prepare('UPDATE gen_metadata SET data = ?, size = ? WHERE idx = ?');
|
||||||
|
for (const row of genRows || []) {
|
||||||
|
const patched = migratorPatchGenMetadataOwnership(row.data, srcCid, newCid);
|
||||||
|
if (patched) {
|
||||||
|
updGen.run(patched, patched.length, row.idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 兼容不含 gen_metadata 表的最小结构
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dstDb.exec('COMMIT');
|
||||||
|
} catch (txErr) {
|
||||||
|
try {
|
||||||
|
dstDb.exec('ROLLBACK');
|
||||||
|
} catch {
|
||||||
|
// 忽略回滚异常
|
||||||
|
}
|
||||||
|
throw txErr;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3. 拷贝 brain/<srcCid> -> brain/<newCid>(保留源 brain 中的媒体文件不删,确保历史图片绝对路径持续有效)
|
// 3. 拷贝 brain/<srcCid> -> brain/<newCid>(保留源 brain 中的媒体文件不删,确保历史图片绝对路径持续有效)
|
||||||
@@ -1228,6 +1381,7 @@ export function migrateSessions(params = {}, options = {}) {
|
|||||||
const patchedRawSummary = migratorBuildPatchedRawSummary({
|
const patchedRawSummary = migratorBuildPatchedRawSummary({
|
||||||
sourceRawSummary: srcSummary?.raw_summary || null,
|
sourceRawSummary: srcSummary?.raw_summary || null,
|
||||||
sourceMetaBlob,
|
sourceMetaBlob,
|
||||||
|
srcCid,
|
||||||
newCid,
|
newCid,
|
||||||
newTid,
|
newTid,
|
||||||
title: finalTitle,
|
title: finalTitle,
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>用量监控</title>
|
<title>用量监控</title>
|
||||||
<link rel="stylesheet" href="/styles.css?v=1795278375975">
|
<link rel="stylesheet" href="/styles.css?v=1795284394191">
|
||||||
<script src="/preload.js"></script>
|
<script src="/preload.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app-root"></div>
|
<div id="app-root"></div>
|
||||||
<script src="/app.js?v=1795278375975"></script>
|
<script src="/app.js?v=1795284394191"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -667,7 +667,7 @@ export const I18N_MESSAGES_EN_US = Object.freeze({
|
|||||||
'settings.oth.migModeLabel': 'Migration Mode',
|
'settings.oth.migModeLabel': 'Migration Mode',
|
||||||
'settings.oth.migModeMove': 'Full Move (Recommended)',
|
'settings.oth.migModeMove': 'Full Move (Recommended)',
|
||||||
'settings.oth.migModeClone': 'Clone Copy',
|
'settings.oth.migModeClone': 'Clone Copy',
|
||||||
'settings.oth.migModeMoveHint': 'Preserves original ID and full historical steps/details; archives source backup before moving',
|
'settings.oth.migModeMoveHint': 'Assigns an isolated target ID while preserving all historical steps/details; archives source backup before moving (close source session first)',
|
||||||
'settings.oth.migModeCloneHint': 'Keeps source intact with a fresh UUID; only counts new steps generated after cloning',
|
'settings.oth.migModeCloneHint': 'Keeps source intact with a fresh UUID; only counts new steps generated after cloning',
|
||||||
'settings.oth.migProjectLabel': 'Target Project',
|
'settings.oth.migProjectLabel': 'Target Project',
|
||||||
'settings.oth.migProjectOutside': 'Standalone (No Project)',
|
'settings.oth.migProjectOutside': 'Standalone (No Project)',
|
||||||
|
|||||||
@@ -667,7 +667,7 @@ export const I18N_MESSAGES_ZH_CN = Object.freeze({
|
|||||||
'settings.oth.migModeLabel': '迁移方式',
|
'settings.oth.migModeLabel': '迁移方式',
|
||||||
'settings.oth.migModeMove': '完整迁移(推荐)',
|
'settings.oth.migModeMove': '完整迁移(推荐)',
|
||||||
'settings.oth.migModeClone': '克隆副本',
|
'settings.oth.migModeClone': '克隆副本',
|
||||||
'settings.oth.migModeMoveHint': '保留原 ID 和全部历史步序明细,备份后移出源端(零重复计费)',
|
'settings.oth.migModeMoveHint': '分配目标端独立会话 ID 并完整保留全部历史步序明细,备份后移出源端(零重复计费;迁移前建议先关闭源端该会话)',
|
||||||
'settings.oth.migModeCloneHint': '保留源会话并生成新 ID,新副本仅统计迁入后的新步骤',
|
'settings.oth.migModeCloneHint': '保留源会话并生成新 ID,新副本仅统计迁入后的新步骤',
|
||||||
'settings.oth.migProjectLabel': '绑定目标项目',
|
'settings.oth.migProjectLabel': '绑定目标项目',
|
||||||
'settings.oth.migProjectOutside': '独立会话(无所属项目)',
|
'settings.oth.migProjectOutside': '独立会话(无所属项目)',
|
||||||
|
|||||||
@@ -108,7 +108,16 @@ function createConvDb(dbPath, { cid, tid, source = 17, projectId = 'default-cli-
|
|||||||
encodeProtoVarintField(2, i),
|
encodeProtoVarintField(2, i),
|
||||||
encodeProtoStringField(4, cid),
|
encodeProtoStringField(4, cid),
|
||||||
]);
|
]);
|
||||||
const stepMeta = encodeProtoBytesField(20, srcInfo);
|
// 模拟真实步骤:在 fn 4 (toolCall.argumentsJson) 中携带含源 cid 的文件路径,验证改写归属时绝不误伤路径
|
||||||
|
const toolCallSub = Buffer.concat([
|
||||||
|
encodeProtoStringField(1, `tc-${i}`),
|
||||||
|
encodeProtoStringField(2, 'read_file'),
|
||||||
|
encodeProtoStringField(3, `{"Path":"C:/Users/Test/.gemini/antigravity-cli/brain/${cid}/note.md"}`),
|
||||||
|
]);
|
||||||
|
const stepMeta = Buffer.concat([
|
||||||
|
encodeProtoBytesField(4, toolCallSub),
|
||||||
|
encodeProtoBytesField(20, srcInfo),
|
||||||
|
]);
|
||||||
const stepPayload = isUser
|
const stepPayload = isUser
|
||||||
? encodeProtoBytesField(19, encodeProtoStringField(2, promptText))
|
? encodeProtoBytesField(19, encodeProtoStringField(2, promptText))
|
||||||
: encodeProtoBytesField(20, encodeProtoStringField(1, 'ok reply'));
|
: encodeProtoBytesField(20, encodeProtoStringField(1, 'ok reply'));
|
||||||
@@ -116,6 +125,30 @@ function createConvDb(dbPath, { cid, tid, source = 17, projectId = 'default-cli-
|
|||||||
'INSERT INTO steps (idx, step_type, status, metadata, step_payload) VALUES (?, ?, 3, ?, ?)'
|
'INSERT INTO steps (idx, step_type, status, metadata, step_payload) VALUES (?, ?, 3, ?, ?)'
|
||||||
).run(i, isUser ? 14 : 15, stepMeta, stepPayload);
|
).run(i, isUser ? 14 : 15, stepMeta, stepPayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 写入带重复 fn 20 extraMeta 映射和含源 cid 路径提示词的 gen_metadata,验证定向改写归属 ID 而不破坏其他 map 项
|
||||||
|
if (stepCount > 0) {
|
||||||
|
const mapEntry = (k, v) =>
|
||||||
|
encodeProtoBytesField(
|
||||||
|
20,
|
||||||
|
Buffer.concat([encodeProtoStringField(1, k), encodeProtoStringField(2, v)])
|
||||||
|
);
|
||||||
|
const chatModelSub = Buffer.concat([
|
||||||
|
encodeProtoStringField(1, `prompt referencing brain/${cid}/shot.png`),
|
||||||
|
mapEntry('model_enum', 'MODEL_PLACEHOLDER_M37'),
|
||||||
|
mapEntry('cascade_id', cid),
|
||||||
|
mapEntry('root_cascade_id', cid),
|
||||||
|
mapEntry('used_claude', 'false'),
|
||||||
|
]);
|
||||||
|
const genBlob = Buffer.concat([
|
||||||
|
encodeProtoBytesField(1, chatModelSub),
|
||||||
|
encodeProtoVarintField(2, 1),
|
||||||
|
]);
|
||||||
|
db.prepare('INSERT INTO gen_metadata (idx, data, size) VALUES (0, ?, ?)').run(
|
||||||
|
genBlob,
|
||||||
|
genBlob.length
|
||||||
|
);
|
||||||
|
}
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +389,7 @@ test('Cross-client session migration clones CLI/Legacy-IDE/Desktop SQLite sessio
|
|||||||
assert.ok(cat.desktopProjects.some((p) => p.projectId === projId && p.name === 'antigravity-usage-monitor'));
|
assert.ok(cat.desktopProjects.some((p) => p.projectId === projId && p.name === 'antigravity-usage-monitor'));
|
||||||
assert.ok(cat.desktopProjects.some((p) => p.projectId === 'outside-of-project' && p.isOutsideProject));
|
assert.ok(cat.desktopProjects.some((p) => p.projectId === 'outside-of-project' && p.isOutsideProject));
|
||||||
|
|
||||||
// 3. Default FULL MOVE mode: CLI -> Desktop (1 idle + 1 running -> idle moves with original UUID & ALL historical steps!)
|
// 3. Default FULL MOVE mode: CLI -> Desktop (1 idle + 1 running -> idle moves with isolated fresh UUID & ALL historical steps!)
|
||||||
const migRes = migrateSessions(
|
const migRes = migrateSessions(
|
||||||
{
|
{
|
||||||
sourceClient: 'cli',
|
sourceClient: 'cli',
|
||||||
@@ -376,7 +409,11 @@ test('Cross-client session migration clones CLI/Legacy-IDE/Desktop SQLite sessio
|
|||||||
const okItem = migRes.results.find((r) => r.ok);
|
const okItem = migRes.results.find((r) => r.ok);
|
||||||
const runErr = migRes.results.find((r) => !r.ok);
|
const runErr = migRes.results.find((r) => !r.ok);
|
||||||
assert.equal(runErr.error, 'session_running');
|
assert.equal(runErr.error, 'session_running');
|
||||||
assert.equal(okItem.newCascadeId, cliIdleCid, 'Full move preserves original cascadeId so historical steps stay intact');
|
assert.notEqual(
|
||||||
|
okItem.newCascadeId,
|
||||||
|
cliIdleCid,
|
||||||
|
'Full move assigns a fresh target cascadeId to avoid Desktop/CLI cross-mirror summary deletion'
|
||||||
|
);
|
||||||
assert.ok(
|
assert.ok(
|
||||||
okItem.archivedSourcePath && existsSync(okItem.archivedSourcePath),
|
okItem.archivedSourcePath && existsSync(okItem.archivedSourcePath),
|
||||||
'Archives source DB snapshot before removing from source client'
|
'Archives source DB snapshot before removing from source client'
|
||||||
@@ -402,15 +439,15 @@ test('Cross-client session migration clones CLI/Legacy-IDE/Desktop SQLite sessio
|
|||||||
const annText = readFileSync(join(deskRoot, 'annotations', `${okItem.newCascadeId}.pbtxt`), 'utf8');
|
const annText = readFileSync(join(deskRoot, 'annotations', `${okItem.newCascadeId}.pbtxt`), 'utf8');
|
||||||
assert.ok(annText.includes('Fix Braille progress bar width'));
|
assert.ok(annText.includes('Fix Braille progress bar width'));
|
||||||
|
|
||||||
// Inspect moved DB metadata & unknown field 15 preservation
|
// Inspect moved DB metadata, ownership rewrite, tool-path preservation, & unknown field 15 preservation
|
||||||
const movedDb = new DatabaseSync(movedDbPath, { readOnly: true });
|
const movedDb = new DatabaseSync(movedDbPath, { readOnly: true });
|
||||||
const metaRow = movedDb.prepare('SELECT * FROM trajectory_meta').get();
|
const metaRow = movedDb.prepare('SELECT * FROM trajectory_meta').get();
|
||||||
assert.equal(metaRow.cascade_id, cliIdleCid);
|
assert.equal(metaRow.cascade_id, okItem.newCascadeId);
|
||||||
assert.equal(metaRow.trajectory_id, 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaa1');
|
assert.notEqual(metaRow.trajectory_id, 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaa1');
|
||||||
assert.equal(metaRow.source, 1);
|
assert.equal(metaRow.source, 1);
|
||||||
const blobRow = movedDb.prepare("SELECT data FROM trajectory_metadata_blob WHERE id = 'main'").get();
|
const blobRow = movedDb.prepare("SELECT data FROM trajectory_metadata_blob WHERE id = 'main'").get();
|
||||||
const blobFields = splitProtoRawFields(blobRow.data);
|
const blobFields = splitProtoRawFields(blobRow.data);
|
||||||
assert.equal(blobFields.find((f) => f.fn === 6)?.payload.toString('utf8'), cliIdleCid);
|
assert.equal(blobFields.find((f) => f.fn === 6)?.payload.toString('utf8'), okItem.newCascadeId);
|
||||||
assert.equal(blobFields.find((f) => f.fn === 7)?.payload.toString('utf8'), projWsEnc);
|
assert.equal(blobFields.find((f) => f.fn === 7)?.payload.toString('utf8'), projWsEnc);
|
||||||
assert.equal(blobFields.find((f) => f.fn === 18)?.payload.toString('utf8'), projId);
|
assert.equal(blobFields.find((f) => f.fn === 18)?.payload.toString('utf8'), projId);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
@@ -418,29 +455,63 @@ test('Cross-client session migration clones CLI/Legacy-IDE/Desktop SQLite sessio
|
|||||||
Buffer.from([0xde, 0xad, 0xbe, 0xef]),
|
Buffer.from([0xde, 0xad, 0xbe, 0xef]),
|
||||||
'Preserves unknown protobuf fields byte-for-byte'
|
'Preserves unknown protobuf fields byte-for-byte'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Verify step toolCall file path still references original brain/<cliIdleCid> while fn20.fn4 is rewritten to newCascadeId
|
||||||
|
const step0Meta = movedDb.prepare('SELECT metadata FROM steps WHERE idx = 0').get().metadata;
|
||||||
|
const step0Fields = splitProtoRawFields(step0Meta);
|
||||||
|
const step0ToolStr = step0Fields.find((f) => f.fn === 4)?.payload.toString('utf8') || '';
|
||||||
|
assert.ok(
|
||||||
|
step0ToolStr.includes(`brain/${cliIdleCid}/note.md`),
|
||||||
|
'Does not corrupt historical file paths inside toolCall arguments'
|
||||||
|
);
|
||||||
|
const step0SrcInfo = splitProtoRawFields(step0Fields.find((f) => f.fn === 20).payload);
|
||||||
|
assert.equal(step0SrcInfo.find((f) => f.fn === 4)?.payload.toString('utf8'), okItem.newCascadeId);
|
||||||
|
assert.equal(step0SrcInfo.find((f) => f.fn === 1)?.payload.toString('utf8'), metaRow.trajectory_id);
|
||||||
|
|
||||||
|
// Verify gen_metadata preserves prompt text path + other map entries while rewriting cascade_id/root_cascade_id
|
||||||
|
const gen0Blob = movedDb.prepare('SELECT data FROM gen_metadata WHERE idx = 0').get().data;
|
||||||
|
const gen0Chat = splitProtoRawFields(splitProtoRawFields(gen0Blob).find((f) => f.fn === 1).payload);
|
||||||
|
assert.equal(
|
||||||
|
gen0Chat.find((f) => f.fn === 1)?.payload.toString('utf8'),
|
||||||
|
`prompt referencing brain/${cliIdleCid}/shot.png`
|
||||||
|
);
|
||||||
|
const extraEntries = new Map();
|
||||||
|
for (const cf of gen0Chat.filter((f) => f.fn === 20)) {
|
||||||
|
const kv = splitProtoRawFields(cf.payload);
|
||||||
|
extraEntries.set(
|
||||||
|
kv.find((x) => x.fn === 1)?.payload.toString('utf8'),
|
||||||
|
kv.find((x) => x.fn === 2)?.payload.toString('utf8')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert.equal(extraEntries.get('model_enum'), 'MODEL_PLACEHOLDER_M37');
|
||||||
|
assert.equal(extraEntries.get('used_claude'), 'false');
|
||||||
|
assert.equal(extraEntries.get('cascade_id'), okItem.newCascadeId);
|
||||||
|
assert.equal(extraEntries.get('root_cascade_id'), okItem.newCascadeId);
|
||||||
movedDb.close();
|
movedDb.close();
|
||||||
|
|
||||||
// Verify ALL historical steps (#0..#5, including #1/#3/#5 planner responses) are preserved in telemetry!
|
// Verify ALL historical steps (#0..#5, including #1/#3/#5 planner responses) and gen_metadata stay intact in telemetry!
|
||||||
const decodedMoved = readLocalSqliteTrajectory(movedDbPath, { cascadeId: cliIdleCid });
|
const decodedMoved = readLocalSqliteTrajectory(movedDbPath, { cascadeId: okItem.newCascadeId });
|
||||||
assert.ok(decodedMoved, 'Moved session decodes cleanly via cli-sqlite-reader');
|
assert.ok(decodedMoved, 'Moved session decodes cleanly via cli-sqlite-reader');
|
||||||
assert.equal(decodedMoved.numTotalSteps, 6, 'All 6 historical steps (#0..#5) stay intact after full move');
|
assert.equal(decodedMoved.numTotalSteps, 6, 'All 6 historical steps (#0..#5) stay intact after full move');
|
||||||
|
assert.equal(decodedMoved.generatorMetadata.length, 1, 'Rewritten gen_metadata remains owned by target session');
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
decodedMoved.steps.map((s) => s.idx),
|
decodedMoved.steps.map((s) => s.idx),
|
||||||
[0, 1, 2, 3, 4, 5],
|
[0, 1, 2, 3, 4, 5],
|
||||||
'Historical step numbering remains continuous without jumping'
|
'Historical step numbering remains continuous without jumping'
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verify target summary DB row & stripped fn 20 CLI source tag
|
// Verify target summary DB row under newCascadeId & stripped fn 20 CLI source tag
|
||||||
const checkSumDb = new DatabaseSync(join(deskRoot, 'conversation_summaries.db'), { readOnly: true });
|
const checkSumDb = new DatabaseSync(join(deskRoot, 'conversation_summaries.db'), { readOnly: true });
|
||||||
const sumRow = checkSumDb
|
const sumRow = checkSumDb
|
||||||
.prepare('SELECT * FROM conversation_summaries WHERE conversation_id = ?')
|
.prepare('SELECT * FROM conversation_summaries WHERE conversation_id = ?')
|
||||||
.get(cliIdleCid);
|
.get(okItem.newCascadeId);
|
||||||
assert.equal(sumRow.project_id, projId);
|
assert.equal(sumRow.project_id, projId);
|
||||||
assert.equal(sumRow.source, '');
|
assert.equal(sumRow.source, '');
|
||||||
assert.equal(sumRow.app_data_dir, 'antigravity');
|
assert.equal(sumRow.app_data_dir, 'antigravity');
|
||||||
assert.equal(sumRow.workspace_uris, JSON.stringify([projWsEnc]));
|
assert.equal(sumRow.workspace_uris, JSON.stringify([projWsEnc]));
|
||||||
const rawSumFields = splitProtoRawFields(sumRow.raw_summary);
|
const rawSumFields = splitProtoRawFields(sumRow.raw_summary);
|
||||||
assert.equal(rawSumFields.some((f) => f.fn === 20), false, 'Strips CLI source enum from raw_summary');
|
assert.equal(rawSumFields.some((f) => f.fn === 20), false, 'Strips CLI source enum from raw_summary');
|
||||||
|
assert.equal(rawSumFields.some((f) => f.fn === 26), false, 'Strips running state flag from raw_summary');
|
||||||
checkSumDb.close();
|
checkSumDb.close();
|
||||||
|
|
||||||
// 4. Optional CLONE mode: Desktop -> CLI (fresh UUID, source untouched, zero double-billing)
|
// 4. Optional CLONE mode: Desktop -> CLI (fresh UUID, source untouched, zero double-billing)
|
||||||
|
|||||||
Reference in New Issue
Block a user