UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

18 lines • 20.9 kB
import{Tt as parseSqliteTableDefinition}from"./sqlite-database-admission-B3KDkUt-.mjs";import{n as OPENCLAW_STATE_SCHEMA_VERSION,t as OPENCLAW_AGENT_SCHEMA_VERSION}from"./openclaw-schema-versions-rhFQpVhP.mjs";import{_ as sql,a as executeSqliteQueryTakeFirstSync,c as iterateSqliteQuerySync,i as executeSqliteQuerySync,s as getNodeSqliteKysely}from"./kysely-sync-R08Pt8qn.mjs";import{o as readSqliteUserVersion}from"./sqlite-user-version-DaJ6mdUV.mjs";import"./openclaw-state-db-contract-G6fQNIi2.mjs";import{Et as _enum,Fn as object,Jn as string,Nt as array,Pn as number,xn as literal}from"./schemas-DuCQi-Qb.mjs";import{i as resolveImmutableSqliteFileUri,n as openNodeSqliteDatabase}from"./node-sqlite-DXyF1fBG.mjs";import{a as resolveOpenClawRegisteredAgentDatabasePath}from"./openclaw-state-db.paths-CbgXfEg1.mjs";import{o as runSqliteReadSnapshotSync}from"./sqlite-transaction-CON-dGDv.mjs";import{i as assertSqliteIntegrity}from"./sqlite-integrity-BzUEDiX5.mjs";import{o as readStateSchemaContentVersion}from"./openclaw-state-db-schema-version-DreEd78i.mjs";import{a as assertCurrentStateRuntimeSchema}from"./openclaw-state-db-transaction-B9Gj3UJV.mjs";import{t as MEDIA_ROWS_MIGRATION_META_KEY}from"./openclaw-agent-db-contract-CiyWpx1X.mjs";import{T as withoutAgentColdNavigation,f as LEGACY_MEMORY_REVISION_TRIGGER_NAMES}from"./openclaw-agent-trajectory-storage-migration-Bf7FVcfX.mjs";import{_ as getOpenClawAgentMigrationSchema,l as LEGACY_CANONICAL_VALIDATION_TRIGGER_NAMES,n as AGENT_JSON_PREDICATE_COLUMNS,y as withoutOutboxEnqueueSequence}from"./openclaw-agent-progress-card-schema-DdfZ6p8c.mjs";import{r as assertOpenClawAgentSchemaContains}from"./openclaw-agent-db-schema-helpers-BwxRsv20.mjs";import"./openclaw-agent-json-predicate-schema-BTh9qHqy.mjs";import"./openclaw-agent-outbox-sequence-migration-DbigA3_b.mjs";import{n as resolveCapturedRegistryPath}from"./update-recovery-path-CONVfw4z.mjs";import{a as withVerifiedUpdateRecoveryBackup}from"./update-recovery-backup-reader-DrnItuQx.mjs";import path from"node:path";import{createHash}from"node:crypto";import{isDeepStrictEqual}from"node:util"; //!src/state/openclaw-migration-witness-registry.ts function assertMigrationWitnessRegistryPreserved(e,t){if(!t.registryMigrationBinding)return;const n=new Map((e.tables.find(e=>e.name===`agent_databases`)?.registryRows??[]).map(e=>[e.locator,e]));const r=t.tables.find(e=>e.name===`agent_databases`)?.registryRows;if(!r||n.size!==r.length)throw new Error(`Missing registry row witnesses`);for(const e of r){const t=n.get(e.locator);if(!t||t.store!==e.store||e.schemaVersion!==42&&e.sha256!==t.sha256)throw new Error(`Unrefreshed registry alias changed during migration`)}} //!src/state/openclaw-migration-witness.schema.ts const witnessIdentifierSchema=string().max(256);const count=number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);const headerInteger=number().int().min(-2147483648).max(2147483647);const digest=string().regex(/^[a-f0-9]{64}$/u);const registryRowSchema=object({store:digest,locator:digest,schemaVersion:headerInteger,sha256:digest}).strict();const tableSchema=object({name:witnessIdentifierSchema,columns:array(witnessIdentifierSchema).min(1).max(256),rowCount:count,sha256:digest,migrationSha256:digest,registryRows:array(registryRowSchema).max(4096).optional()}).strict();const witnessSchema=object({version:literal(1),role:_enum([`agent`,`global`,`sqlite`]),schemaVersion:headerInteger,applicationId:headerInteger,agentId:witnessIdentifierSchema.min(1).nullable(),schemaSha256:digest,migrationSchemaSha256:digest,registryMigrationBinding:digest.nullable(),tables:array(tableSchema).max(512),gaps:object({missingWindows:count,emptyWindows:count}).strict()}).strict(); //!src/state/openclaw-migration-witness.ts const agentSchemaVersions=/* @__PURE__ */ new Set([24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42]);const ADDITIVE_AGENT_TABLES=/* @__PURE__ */ new Map([[`session_transcript_cold_archive_chunks`,37],[`session_creation_operations`,40],[`session_transcript_active_event_facts`,41],[`agent_tool_usage`,42]]);const derivedMigrationColumns=new Map(Object.entries({...AGENT_JSON_PREDICATE_COLUMNS,session_windows:[`row_transcript_json`,`row_transcript_updated_at`],trajectory_runtime_events:[`event_utf8_bytes`,`event_payload`,`event_codec`]}).map(([e,t])=>[e,new Set(t)]));function assertUnique(e){if(new Set(e).size!==e.length)throw new Error(`Migration witness contains duplicate identities`)}function parseOpenClawMigrationWitness(e){const t=witnessSchema.parse(e);assertUnique(t.tables.map(e=>e.name));for(const e of t.tables){const n=t.role===`global`&&t.registryMigrationBinding&&e.name===`agent_databases`;assertUnique(e.columns);if(e.registryRows)assertUnique(e.registryRows.map(e=>e.locator));if(e.registryRows&&!n)throw new Error(`Migration witness has unexpected registry observations`);if(!(t.role===`agent`&&([`schema_meta`,`session_key_contract`,`memory_entry_origins`].includes(e.name)||derivedMigrationColumns.has(e.name)))&&!n&&e.sha256!==e.migrationSha256)throw new Error(`Migration witness has an unsupported content transformation`)}if(t.role===`agent`&&(t.agentId===null||!agentSchemaVersions.has(t.schemaVersion))||t.role!==`agent`&&t.agentId!==null||t.role!==`agent`&&t.schemaSha256!==t.migrationSchemaSha256||t.role!==`global`&&t.registryMigrationBinding!==null||t.role!==`agent`&&(t.gaps.missingWindows!==0||t.gaps.emptyWindows!==0)||t.role===`global`&&t.schemaVersion!==40)throw new Error(`Unsupported migration witness owner or schema version`);if((t.role===`agent`?[`schema_meta`,`session_nodes`,`session_windows`,`transcript_events`,`session_key_contract`,`session_canonical_validation_pending`,...[...ADDITIVE_AGENT_TABLES].filter(([,e])=>t.schemaVersion>=e).map(([e])=>e)]:t.role===`global`?[`schema_meta`,`config_machine_state`]:[]).some(e=>!t.tables.some(t=>t.name===e)))throw new Error(`Migration witness is missing its owner's required tables`);return t}function migrationColumn(e,t,n){return!(e===`agent`&&(t===`schema_meta`&&[`schema_version`,`app_version`,`updated_at`].includes(n)||t===`session_key_contract`&&n===`canonical_ready`||derivedMigrationColumns.get(t)?.has(n)))}function hashCell(e,t,n){if(typeof t!==`string`||n!==null&&typeof n!==`string`&&!(n instanceof Uint8Array))throw new Error(`Unreadable migration witness cell`);const r=n===null?Buffer.alloc(0):typeof n===`string`?Buffer.from(n):n;e.update(`${t}:${r.byteLength}:`).update(r).update(`;`)}function witnessIdentifier(e,t){return sql.id(...t?[t,e]:[e])}function captureTable(e,t,n,r,i){const a=getNodeSqliteKysely(e);const o=executeSqliteQuerySync(e,a.selectFrom(sql`pragma_table_xinfo(${n})`.as(`columns`)).select([`name`,`pk`,`hidden`]).where(`hidden`,`!=`,1).orderBy(`cid`)).rows;if(o.length===0||o.length>256)throw new Error(`Unsupported migration witness columns: ${n}`);const s=t===`agent`&&n===`context_engine_turn_outbox`;const c=o.map(({name:e})=>e).filter(e=>!s||e!==`enqueue_sequence`);if(!r){const e=[`rowid`,`_rowid_`,`oid`].find(e=>!c.some(t=>t.toLowerCase()===e));if(!e)throw new Error(`Migration witness cannot inspect implicit row identity: ${n}`);c.unshift(e)}const l=c.map((e,i)=>!(t===`agent`&&n===`memory_entry_origins`&&!r&&i===0)&&migrationColumn(t,n,e));const u=createHash(`sha256`).update(JSON.stringify(c));const d=l.every(Boolean)&&!i?void 0:createHash(`sha256`).update(JSON.stringify(c.filter((e,t)=>l[t])));let f=a.selectFrom(sql`${witnessIdentifier(n)}`.as(`witness`)).select(c.flatMap((e,t)=>{const n=witnessIdentifier(e,`witness`);return[sql`typeof(${n})`.as(`type_${t}`),sql`CASE typeof(${n}) WHEN 'integer' THEN CAST(${n} AS TEXT) WHEN 'real' THEN printf('%!.17g', ${n}) WHEN 'text' THEN CAST(${n} AS BLOB) ELSE ${n} END`.as(`value_${t}`)]}));if(t===`agent`&&n===`schema_meta`)f=f.where(witnessIdentifier(`meta_key`,`witness`),`!=`,MEDIA_ROWS_MIGRATION_META_KEY);const p=o.filter(({pk:e})=>e>0).toSorted((e,t)=>e.pk-t.pk);const m=s?[`advancement_key`]:p.map(({name:e})=>e);for(const e of[...m,...c.filter(e=>!m.includes(e))])f=f.orderBy(witnessIdentifier(e,`witness`));let h=0;const g=new Set(i?.agents.map(e=>`${e.agentId}\0${e.path}`));const _=new Set(i?.agents.filter(e=>e.requireRegistration).map(e=>`${e.agentId}\0${e.path}`));const v=/* @__PURE__ */ new Set;const y=/* @__PURE__ */ new Set;const b=[];const registryText=(e,t)=>{const n=e[`value_${c.indexOf(t)}`];if(n===null||typeof n===`string`)return n;if(n instanceof Uint8Array)return Buffer.from(n).toString(`utf8`);throw new Error(`Unreadable registry migration field: ${t}`)};for(const t of iterateSqliteQuerySync(e,f)){h++;let e=false;let n=``;let r=``;let a=0;if(i){const o=registryText(t,`agent_id`);const s=registryText(t,`path`);const c=`${o}\0${s===null?``:i.resolvePath(resolveOpenClawRegisteredAgentDatabasePath(i.sourcePath,s))}`;e=g.has(c);if(e){n=c;r=`${o}\0${s}`;a=Number(registryText(t,`schema_version`));if(a===42)y.add(c);const e=registryText(t,`last_seen_at`);const i=registryText(t,`size_bytes`);if(e===null||BigInt(e)<0n||i!==null&&BigInt(i)<0n)throw new Error(`Registry migration contains invalid observation metadata`);v.add(c)}}const o=e?createHash(`sha256`).update(JSON.stringify(c)):void 0;for(let n=0;n<c.length;n++){hashCell(u,t[`type_${n}`],t[`value_${n}`]);if(o)hashCell(o,t[`type_${n}`],t[`value_${n}`]);if(l[n]&&d){if(e&&[`schema_version`,`last_seen_at`,`size_bytes`].includes(c[n]))hashCell(d,`null`,null);else hashCell(d,t[`type_${n}`],t[`value_${n}`])}}u.update(` `);d?.update(` `);if(o){if(b.length===4096)throw new Error(`Migration witness exceeds its 4096-registry-locator bound`);b.push({store:createHash(`sha256`).update(n).digest(`hex`),locator:createHash(`sha256`).update(r).digest(`hex`),schemaVersion:a,sha256:o.digest(`hex`)})}}if(i&&v.size!==g.size)throw new Error(`Cannot bind registry observations to every captured agent store; the original alias evidence may be unavailable`);if(i?.phase===`candidate`&&[..._].some(e=>!y.has(e)))throw new Error(`Registry schema version contradicts the verified agent migration`);const x=u.digest(`hex`);return{name:n,columns:c,rowCount:h,sha256:x,migrationSha256:d?.digest(`hex`)??x,...i?{registryRows:b}:{}}}function captureOpenClawMigrationWitness(e,t,n){return runSqliteReadSnapshotSync(e,()=>{const r=getNodeSqliteKysely(e);const i=t?.role??`sqlite`;if(n&&(i!==`global`||n.agents.length===0||n.agents.length>4096))throw new Error(`Invalid registry migration witness context`);const a=readSqliteUserVersion(e);const o=executeSqliteQueryTakeFirstSync(e,r.selectFrom(sql`pragma_application_id()`.as(`header`)).select(`application_id`))?.application_id;const s=i===`global`?readStateSchemaContentVersion(e):a;if(t){const n=executeSqliteQueryTakeFirstSync(e,r.selectFrom(`schema_meta`).select([`role`,`agent_id`]).select(e=>e.cast(`schema_version`,`text`).as(`schema_version`)).where(`meta_key`,`=`,`primary`));if(n?.role!==t.role||t.role===`agent`&&n.agent_id!==t.agentId||n.schema_version!==String(a))throw new Error(`Migration witness database owner does not match the backup inventory`);if(t.role===`agent`){if(!agentSchemaVersions.has(s))throw new Error(`Unsupported agent migration witness schema: ${s}`);assertOpenClawAgentSchemaContains(e,`migration witness`,getOpenClawAgentMigrationSchema(s))}else{if(s!==40)throw new Error(`Unsupported shared-state migration witness schema: ${s}`);assertCurrentStateRuntimeSchema(e,`migration witness`)}}const c=executeSqliteQuerySync(e,r.selectFrom(`sqlite_schema`).select(`name`).where(`type`,`=`,`table`).orderBy(`name`).limit(513)).rows;if(c.length>512)throw new Error(`Migration witness exceeds its 512-table bound`);const l=new Map(executeSqliteQuerySync(e,r.selectFrom(sql`pragma_table_list()`.as(`tables`)).select([`name`,`wr`,`strict`]).where(`schema`,`=`,`main`)).rows.map(e=>[e.name,{withoutRowid:e.wr!==0,strict:e.strict!==0}]));const u=c.map(({name:e})=>witnessIdentifierSchema.parse(e)).filter(e=>!e.startsWith(`sqlite_stat`)).map(t=>{const r=l.get(t);if(r===void 0)throw new Error(`Migration witness table disappeared: ${t}`);return captureTable(e,i,t,r.withoutRowid,t===`agent_databases`?n:void 0)});const d=createHash(`sha256`);const f=createHash(`sha256`);for(const t of iterateSqliteQuerySync(e,r.selectFrom(`sqlite_schema`).select([`type`,`name`,`tbl_name`,`sql`]).orderBy(`type`).orderBy(`name`))){if(t.name.startsWith(`sqlite_stat`))continue;d.update(JSON.stringify(t)).update(` `);const e=ADDITIVE_AGENT_TABLES.get(t.tbl_name);if(i===`agent`&&e!==void 0&&s>=e)continue;const n=`${t.tbl_name}.${t.name}`;if(i===`agent`&&(s===24&&t.type===`trigger`&&LEGACY_CANONICAL_VALIDATION_TRIGGER_NAMES.includes(t.name)||s<31&&t.type===`trigger`&&LEGACY_MEMORY_REVISION_TRIGGER_NAMES.includes(t.name)||t.type===`index`&&(n===`session_windows.idx_agent_session_windows_conversation`||n===`trajectory_runtime_events.idx_agent_trajectory_runtime_run`||s>=39&&(n===`session_input_completions.idx_agent_session_input_completions_session_key`||n===`conversation_deliveries.idx_agent_conversation_deliveries_source_session`)||s<29&&(n===`session_nodes.idx_agent_session_nodes_last_interaction_at`||n===`session_reactions.idx_agent_session_reactions_message`)||s<28&&(n===`transcript_event_identities.idx_agent_transcript_event_parent`||n===`memory_entry_origins.sqlite_autoindex_memory_entry_origins_1`&&t.sql===null))))continue;if(i===`agent`&&t.type===`table`&&(t.name===`session_key_contract`||t.name===`memory_entry_origins`||derivedMigrationColumns.has(t.name))){const e=parseSqliteTableDefinition(t.name===`context_engine_turn_outbox`&&t.sql?withoutOutboxEnqueueSequence(t.sql):t.name===`transcript_events`&&t.sql?withoutAgentColdNavigation(t.sql):t.sql,t.name);for(const n of e.columns.keys())if(!migrationColumn(i,t.name,n))e.columns.delete(n);f.update(JSON.stringify({...t,sql:{columns:[...e.columns],constraints:e.constraints,...l.get(t.name),...t.name===`memory_entry_origins`?{withoutRowid:false}:{}}})).update(` `)}else f.update(JSON.stringify(t)).update(` `)}const p={missingWindows:0,emptyWindows:0};if(i===`agent`){p.missingWindows=Number(executeSqliteQueryTakeFirstSync(e,r.selectFrom(`session_nodes as node`).select(e=>e.fn.countAll().as(`count`)).where(e=>e.not(e.exists(e.selectFrom(`session_windows as window`).select(`window.session_id`).whereRef(`window.session_id`,`=`,`node.current_session_id`)))))?.count);p.emptyWindows=Number(executeSqliteQueryTakeFirstSync(e,r.selectFrom(`session_windows as window`).select(e=>e.fn.countAll().as(`count`)).where(e=>e.not(e.exists(e.selectFrom(`transcript_events as event`).select(`event.session_id`).whereRef(`event.session_id`,`=`,`window.session_id`)))).where(e=>e.not(e.exists(e.selectFrom(`session_transcript_cold_archives as cold`).select(`cold.session_id`).whereRef(`cold.session_id`,`=`,`window.session_id`)))))?.count)}return parseOpenClawMigrationWitness({version:1,role:i,schemaVersion:s,applicationId:o,agentId:t?.role===`agent`?t.agentId:null,schemaSha256:d.digest(`hex`),migrationSchemaSha256:f.digest(`hex`),registryMigrationBinding:n?createHash(`sha256`).update(JSON.stringify([n.sourcePath,n.agents.toSorted((e,t)=>e.agentId.localeCompare(t.agentId)||e.path.localeCompare(t.path)).map(e=>[e.agentId,e.path,e.requireRegistration])])).digest(`hex`):null,tables:u,gaps:p})})}function assertOpenClawMigrationWitnessPreserved(e,t){const n=parseOpenClawMigrationWitness(e);const r=parseOpenClawMigrationWitness(t);const i=n.role===`agent`&&n.schemaVersion<r.schemaVersion&&r.schemaVersion<=42;if(n.role!==r.role||n.agentId!==r.agentId||n.applicationId!==r.applicationId||n.registryMigrationBinding!==r.registryMigrationBinding||!i&&n.schemaVersion!==r.schemaVersion)throw new Error(`Unsupported migration witness owner or version transition`);if((i?n.migrationSchemaSha256:n.schemaSha256)!==(i?r.migrationSchemaSha256:r.schemaSha256))throw new Error(`Migration changed or lost retained database schema`);assertMigrationWitnessRegistryPreserved(n,r);const projected=e=>e.tables.filter(e=>!i||e.name!==`session_canonical_validation_pending`).filter(e=>{const t=ADDITIVE_AGENT_TABLES.get(e.name);return!(i&&t!==void 0&&n.schemaVersion<t&&e.rowCount===0)}).map(t=>({name:t.name,columns:i?t.columns.filter((n,r)=>!(e.role===`agent`&&e.schemaVersion<28&&t.name===`memory_entry_origins`&&r===0)).filter(n=>migrationColumn(e.role,t.name,n)):t.columns,rowCount:t.rowCount,sha256:i||e.registryMigrationBinding?t.migrationSha256:t.sha256})).toSorted((e,t)=>e.name.localeCompare(t.name));const a=projected(n);const o=new Map(projected(r).map(e=>[e.name,e]));for(const e of a){if(JSON.stringify(e)!==JSON.stringify(o.get(e.name)))throw new Error(`Migration changed or lost retained database content: ${e.name}`);o.delete(e.name)}if(o.size>0)throw new Error(`Migration added unclassified database content`);return{warnings:Object.entries(n.gaps).filter(([,e])=>e>0).map(([e,t])=>`Preexisting session history gap: ${e} (${t})`)}} //!src/commands/doctor-migration-preservation.ts function readWitness(e,t,n,r){if(t.kind!==`file`||!t.sqlite)throw new Error(`Preservation requires a captured SQLite payload: ${t.sourcePath}`);const i=path.join(e.directory,t.archivePath);const a=openNodeSqliteDatabase(resolveImmutableSqliteFileUri(i),{readOnly:true});try{a.exec(`PRAGMA trusted_schema = OFF;`);assertSqliteIntegrity(a,t.sourcePath);return captureOpenClawMigrationWitness(a,n,r)}finally{a.close()}}async function inspectDoctorMigrationPreservation(e){return withVerifiedUpdateRecoveryBackup(e.original,async t=>withVerifiedUpdateRecoveryBackup(e.candidate,async n=>{if(t.generation?.kind!==`baseline`||t.stateDir!==n.stateDir||t.configPath!==n.configPath||t.installRoot!==n.installRoot||!isDeepStrictEqual(t.excludedRoots,n.excludedRoots)||n.generation?.kind!==`baseline`&&n.generation?.baselineSha256!==e.original.manifestSha256)throw new Error(`Preservation captures do not share the admitted original scope.`);const r=new Map(n.entries.map(e=>[e.sourcePath,e]));const i=new Map(t.entries.filter(e=>e.kind===`symlink`).map(e=>[e.sourcePath,e.target]));const a=new Map(n.entries.filter(e=>e.kind===`symlink`).map(e=>[e.sourcePath,e.target]));const o=new Set(t.entries.filter(e=>e.kind===`directory`).map(e=>e.sourcePath));const s=new Set(n.entries.filter(e=>e.kind===`directory`).map(e=>e.sourcePath));const c=new Set(t.entries.map(e=>e.sourcePath));for(const e of n.entries)if(!c.has(e.sourcePath))throw new Error(`Preservation added an unclassified resource: ${e.sourcePath}`);const l=new Map(t.databases.map(e=>[e.path,e]));const u=new Map(n.databases.map(e=>[e.path,e]));if(l.size!==u.size||[...l].some(([e,t])=>!isDeepStrictEqual(t,u.get(e))))throw new Error(`Preservation database ownership inventory changed`);const d=new Set([...t.warnings??[],...n.warnings??[]].map(e=>e.message));const f=/* @__PURE__ */ new Map;const p=[];for(const n of t.entries){const t=l.get(n.sourcePath);if(n.kind!==`file`||!n.sqlite||t?.role!==`agent`)continue;const i=r.get(n.sourcePath);if(!i)throw new Error(`Preservation lost an inventoried resource: ${n.sourcePath}`);const a=readWitness(e.original,n,t);const o=readWitness(e.candidate,i,t);assertOpenClawMigrationWitnessPreserved(a,o);f.set(n.sourcePath,{before:a,after:o});if(o.schemaVersion===42)p.push({agentId:t.agentId,path:t.path,requireRegistration:a.schemaVersion<42})}let m=0;let h=0;for(const n of t.entries){const t=r.get(n.sourcePath);if(!t)throw new Error(`Preservation lost an inventoried resource: ${n.sourcePath}`);if(n.kind===`missing`){if(!isDeepStrictEqual(n,t))throw new Error(`Preservation changed a previously missing resource: ${n.sourcePath}`);d.add(`Preexisting missing resource: ${n.sourcePath}`);continue}if(n.kind===`file`&&n.sqlite){if(t.kind!==`file`||!t.sqlite||t.mode!==n.mode)throw new Error(`Preservation changed SQLite file kind or mode: ${n.sourcePath}`);const r=l.get(n.sourcePath);const c=r?.role===`global`&&p.length>0?{sourcePath:n.sourcePath,agents:p}:void 0;const u=f.get(n.sourcePath);const h=u?.before??readWitness(e.original,n,r,c?{...c,phase:`original`,resolvePath:e=>resolveCapturedRegistryPath(e,i,o)}:void 0);const g=u?.after??readWitness(e.candidate,t,r,c?{...c,phase:`candidate`,resolvePath:e=>resolveCapturedRegistryPath(e,a,s)}:void 0);const _=assertOpenClawMigrationWitnessPreserved(h,g);for(const e of _.warnings)d.add(`${n.sourcePath}: ${e}`);m++}else if(n.kind===`file`){if(t.kind!==`file`||t.sqlite||n.sha256!==t.sha256||n.size!==t.size||n.mode!==t.mode)throw new Error(`Preservation changed protected file bytes or mode: ${n.sourcePath}`);h++}else if(!isDeepStrictEqual(n,t))throw new Error(`Preservation changed protected resource: ${n.sourcePath}`)}return{schema:`openclaw.migration-preservation.v1`,status:d.size?`preserved-with-warnings`:`preserved`,original:e.original,candidate:e.candidate,resources:t.entries.length,databases:m,files:h,warnings:[...d],activationAuthorized:false}}))}export{inspectDoctorMigrationPreservation};