remove stale native tasks on marketplace sync

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-22 17:55:14 +00:00
co-authored by Claude Opus 4.6
parent b3f1d10bc1
commit 039ea7ae71
3 changed files with 19 additions and 2 deletions
+1
View File
@@ -80,6 +80,7 @@ export {
updateTask,
deleteTask,
upsertNativeTask,
deleteNativeTasksNotIn,
} from './queries/tasks';
export {
+10 -1
View File
@@ -1,4 +1,4 @@
import { eq, or, and, isNull, sql } from 'drizzle-orm';
import { eq, or, and, isNull, notInArray, sql } from 'drizzle-orm';
import { db } from '../db';
import { tasks } from '../schema/agent-items';
@@ -73,6 +73,15 @@ export async function deleteTask(id: number) {
await db.delete(tasks).where(eq(tasks.id, id));
}
export async function deleteNativeTasksNotIn(dirNames: string[]) {
if (dirNames.length === 0) return [];
const deleted = await db
.delete(tasks)
.where(and(eq(tasks.scope, 'native'), notInArray(tasks.dirName, dirNames)))
.returning({ dirName: tasks.dirName });
return deleted;
}
export async function upsertNativeTask(data: Omit<TaskInsert, 'scope' | 'userId'>) {
const existing = await db
.select({ id: tasks.id })
+8 -1
View File
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { DATA_PATH } from './data-path';
import { parseSeedVersion } from './sync-version';
import { upsertNativeTask } from 'officerdb';
import { upsertNativeTask, deleteNativeTasksNotIn } from 'officerdb';
const MARKETPLACE_URL = process.env.MARKETPLACE_URL ?? 'https://marketplace.officer.dev';
const GLOBAL_TOOLS_DIR = join(DATA_PATH, 'tools');
@@ -169,6 +169,13 @@ export async function syncMarketplaceTasks(): Promise<void> {
console.log(`[marketplace] Synced task: ${task.dirName} (v${task.version})`);
}
// Delete native tasks that no longer exist in the marketplace
const activeDirNames = allTasks.map((t) => t.dirName);
const deleted = await deleteNativeTasksNotIn(activeDirNames);
for (const row of deleted) {
console.log(`[marketplace] Removed task: ${row.dirName}`);
}
} catch (err) {
console.error('[marketplace] Failed to sync tasks:', err instanceof Error ? err.message : err);
}