move tasks to marketplace, sync native tasks on bootstrap

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 13:57:40 +00:00
co-authored by Claude Opus 4.6
parent ef6402a827
commit ee1b816d66
13 changed files with 92 additions and 819 deletions
+2 -1
View File
@@ -2,7 +2,7 @@ import { mkdirSync } from 'node:fs';
import { join } from 'node:path';
import { homedir } from 'node:os';
import { DATA_PATH } from './data-path';
import { syncMarketplaceTools } from './sync-marketplace';
import { syncMarketplaceTools, syncMarketplaceTasks } from './sync-marketplace';
import { ensureToolLoader } from './ensure-tool-loader';
// Queue is now owned by the sidecar process
import { startDiscordBotIfConfigured } from './channels/discord/bot';
@@ -68,6 +68,7 @@ async function installPi(): Promise<boolean> {
}
await syncMarketplaceTools();
await syncMarketplaceTasks();
ensureToolLoader();
// Queue is initialized by the sidecar process
+72 -2
View File
@@ -2,10 +2,13 @@ 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';
const MARKETPLACE_URL = process.env.MARKETPLACE_URL ?? 'https://marketplace.officer.dev';
const GLOBAL_TOOLS_DIR = join(DATA_PATH, 'tools');
// ── Tool sync types ──
type ToolInput = {
type: string;
description: string;
@@ -26,11 +29,35 @@ type MarketplaceTool = {
implementation: string;
};
type MarketplaceResponse = {
type ToolSyncResponse = {
categories: Array<{ name: string; tools: MarketplaceTool[] }>;
uncategorized: MarketplaceTool[];
};
// ── Task sync types ──
type MarketplaceTask = {
dirName: string;
name: string;
description: string;
body: string;
version: number;
mode: string;
language: string | null;
implementation: string | null;
args: string[] | null;
inputs: Record<string, unknown> | null;
trigger: unknown[] | null;
config: Record<string, unknown> | null;
};
type TaskSyncResponse = {
categories: Array<{ name: string; tasks: MarketplaceTask[] }>;
uncategorized: MarketplaceTask[];
};
// ── Tool sync (writes files to disk) ──
function buildToolMd(tool: MarketplaceTool): string {
const lines = ['---'];
lines.push(`name: ${tool.name}`);
@@ -72,7 +99,7 @@ export async function syncMarketplaceTools(): Promise<void> {
return;
}
const data = (await res.json()) as MarketplaceResponse;
const data = (await res.json()) as ToolSyncResponse;
mkdirSync(GLOBAL_TOOLS_DIR, { recursive: true });
@@ -103,3 +130,46 @@ export async function syncMarketplaceTools(): Promise<void> {
console.error('[marketplace] Failed to sync tools:', err instanceof Error ? err.message : err);
}
}
// ── Task sync (upserts into officer_db) ──
export async function syncMarketplaceTasks(): Promise<void> {
try {
const res = await fetch(`${MARKETPLACE_URL}/api/tasks/native`);
if (!res.ok) {
console.error(`[marketplace] Failed to fetch tasks: ${res.status} ${res.statusText}`);
return;
}
const data = (await res.json()) as TaskSyncResponse;
const allTasks: MarketplaceTask[] = [];
for (const category of data.categories) {
allTasks.push(...category.tasks);
}
if (data.uncategorized) {
allTasks.push(...data.uncategorized);
}
for (const task of allTasks) {
await upsertNativeTask({
dirName: task.dirName,
name: task.name,
description: task.description,
body: task.body,
version: task.version,
mode: task.mode,
language: task.language,
implementation: task.implementation,
args: task.args,
inputs: task.inputs,
trigger: task.trigger,
config: task.config,
});
console.log(`[marketplace] Synced task: ${task.dirName} (v${task.version})`);
}
} catch (err) {
console.error('[marketplace] Failed to sync tasks:', err instanceof Error ? err.message : err);
}
}