(
send: (event: string, data: unknown) => void,
enableTasks: boolean,
enableSkills: boolean,
concurrency: number = 1,
)
| 4802 | } |
| 4803 | |
| 4804 | private async runPostprocess( |
| 4805 | send: (event: string, data: unknown) => void, |
| 4806 | enableTasks: boolean, |
| 4807 | enableSkills: boolean, |
| 4808 | concurrency: number = 1, |
| 4809 | ): Promise<void> { |
| 4810 | const ctx = this.ctx!; |
| 4811 | |
| 4812 | const importSessions = this.store.getDistinctSessionKeys() |
| 4813 | .filter((sk: string) => sk.startsWith("openclaw-import-") || sk.startsWith("openclaw-session-") || /^agent:[^:]+:(import|session:)/.test(sk)); |
| 4814 | |
| 4815 | type PendingItem = { sessionKey: string; action: "full" | "skill-only"; owner: string }; |
| 4816 | const pendingItems: PendingItem[] = []; |
| 4817 | let skippedCount = 0; |
| 4818 | |
| 4819 | const ownerMap = this.store.getSessionOwnerMap(importSessions); |
| 4820 | |
| 4821 | for (const sk of importSessions) { |
| 4822 | const hasTask = this.store.hasTaskForSession(sk); |
| 4823 | const hasSkill = this.store.hasSkillForSessionTask(sk); |
| 4824 | const owner = ownerMap.get(sk) ?? "agent:main"; |
| 4825 | |
| 4826 | if (enableTasks && !hasTask) { |
| 4827 | pendingItems.push({ sessionKey: sk, action: "full", owner }); |
| 4828 | } else if (enableSkills && hasTask && !hasSkill) { |
| 4829 | pendingItems.push({ sessionKey: sk, action: "skill-only", owner }); |
| 4830 | } else { |
| 4831 | skippedCount++; |
| 4832 | } |
| 4833 | } |
| 4834 | |
| 4835 | // Group pending items by agent (owner) |
| 4836 | const agentGroups = new Map<string, PendingItem[]>(); |
| 4837 | for (const item of pendingItems) { |
| 4838 | const group = agentGroups.get(item.owner) ?? []; |
| 4839 | group.push(item); |
| 4840 | agentGroups.set(item.owner, group); |
| 4841 | } |
| 4842 | |
| 4843 | this.ppState.total = pendingItems.length; |
| 4844 | this.ppState.skippedSessions = skippedCount; |
| 4845 | this.ppState.totalSessions = importSessions.length; |
| 4846 | const existingTaskCount = (this.store as any).db.prepare("SELECT COUNT(*) as c FROM tasks WHERE session_key IN (" + importSessions.map(() => "?").join(",") + ")").get(...importSessions)?.c ?? 0; |
| 4847 | const existingSkillCount = this.store.countSkills("active"); |
| 4848 | send("info", { |
| 4849 | totalSessions: importSessions.length, |
| 4850 | alreadyProcessed: skippedCount, |
| 4851 | pending: pendingItems.length, |
| 4852 | agents: Array.from(agentGroups.keys()), |
| 4853 | concurrency, |
| 4854 | existingTasks: existingTaskCount, |
| 4855 | existingSkills: existingSkillCount, |
| 4856 | }); |
| 4857 | send("progress", { processed: 0, total: pendingItems.length }); |
| 4858 | |
| 4859 | let globalIdx = 0; |
| 4860 | const incIdx = () => ++globalIdx; |
| 4861 |
no test coverage detected