tools system - web-fetch
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { readdirSync, existsSync, mkdirSync, cpSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { SEED_PATH, DATA_PATH } from './data-path';
|
||||
|
||||
const SEED_TOOLS_DIR = join(SEED_PATH, 'tools');
|
||||
const GLOBAL_TOOLS_DIR = join(DATA_PATH, 'tools');
|
||||
|
||||
export function syncSeedTools(): void {
|
||||
if (!existsSync(SEED_TOOLS_DIR)) return;
|
||||
|
||||
mkdirSync(GLOBAL_TOOLS_DIR, { recursive: true });
|
||||
|
||||
const seedEntries = readdirSync(SEED_TOOLS_DIR, { withFileTypes: true });
|
||||
|
||||
for (const entry of seedEntries) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
|
||||
const seedToolDir = join(SEED_TOOLS_DIR, entry.name);
|
||||
const toolFile = join(seedToolDir, 'TOOL.md');
|
||||
if (!existsSync(toolFile)) continue;
|
||||
|
||||
const targetDir = join(GLOBAL_TOOLS_DIR, entry.name);
|
||||
|
||||
if (existsSync(targetDir)) {
|
||||
// Tool already exists in DATA_PATH — skip to preserve user edits
|
||||
continue;
|
||||
}
|
||||
|
||||
cpSync(seedToolDir, targetDir, { recursive: true });
|
||||
console.log(`[tools] Synced seed tool: ${entry.name}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user