feat(owner): auto-apply owner profile after pull sync and CLI import

PullEngine gains an onSessionImported hook (hook errors never fail the
pull), wired in both the CLI server and Electron main to silently fill
session owner from the stored platform profile. The chatlab import CLI
command does the same after a successful import.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
diguaandClaude Fable 5 committed 2026-06-13 13:16:52 +08:00
1 parent 502762bcf5
commit 82ce9dcc2f
5 files changed
+64 -2

No files matched your search

+18 -1
View File
@@ -242,7 +242,7 @@ program
}
const { streamImport, detectFormat } = await import('./import')
const { dbManager } = initRuntime()
const { dbManager, pathProvider } = initRuntime()
const nativeBinding = resolveNativeBinding()
const format = detectFormat(file)
@@ -269,6 +269,23 @@ program
console.log(` Session ID: ${result.sessionId}`)
console.log(` Messages written: ${result.diagnostics?.messagesWritten ?? 0}`)
console.log(` Messages skipped: ${result.diagnostics?.messagesSkipped ?? 0}`)
if (result.sessionId) {
try {
const { PreferencesManager, createDatabaseManagerAdapter, ownerProfileService } =
await import('@openchatlab/node-runtime')
const applied = ownerProfileService.tryApplyOwnerProfile(
createDatabaseManagerAdapter(dbManager),
new PreferencesManager(pathProvider.getSystemDir()),
result.sessionId
)
if (applied.applied) {
console.log(` Owner auto-detected: ${applied.ownerId}`)
}
} catch (ownerErr) {
console.warn(` Owner profile apply skipped: ${ownerErr instanceof Error ? ownerErr.message : ownerErr}`)
}
}
} else {
console.error(`\n\nImport failed: ${result.error}`)
process.exit(1)
+10
View File
@@ -6,6 +6,7 @@
import type { FastifyInstance } from 'fastify'
import type { DatabaseManager } from '@openchatlab/node-runtime'
import { PreferencesManager, createDatabaseManagerAdapter, ownerProfileService } from '@openchatlab/node-runtime'
import type { PathProvider } from '@openchatlab/core'
import { DataSourceManager, PullEngine, initScheduler, stopAllTimers } from '@openchatlab/sync'
import type { SyncLogger } from '@openchatlab/sync'
@@ -42,12 +43,21 @@ export function initSync(
const importer = new DirectImporter(dbManager, syncLogger)
const notifier = new NoopNotifier()
const sessionAdapter = createDatabaseManagerAdapter(dbManager)
const preferences = new PreferencesManager(pathProvider.getSystemDir())
pullEngine = new PullEngine({
fetcher,
importer,
notifier,
dsManager,
logger: syncLogger,
onSessionImported: (localSessionId) => {
const result = ownerProfileService.tryApplyOwnerProfile(sessionAdapter, preferences, localSessionId)
if (result.applied) {
syncLogger.info(`[Pull] Applied owner profile to session ${localSessionId} (owner: ${result.ownerId})`)
}
},
})
registerAutomationRoutes(server, { dsManager, pullEngine, dbManager, serverInfo })