Files
platform/src/servers/bootstrap.ts
T
pastilhasandClaude Opus 4.6 49cd559c8a tool registry, claude tool awareness, and model selector fix
- Add agent-agnostic tool registry (tool-registry.ts) that discovers tools from disk
- Embed tool-loader extension as platform infrastructure (ensure-tool-loader.ts)
- Inject tool context into Claude prompts on first message
- Add marketplace tool sync (sync-marketplace.ts)
- Fix model selector defaulting to claude-code when no model explicitly selected
- Exclude tool-loader-source.ts from tsconfig (Pi-specific deps)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 11:55:38 +00:00

86 lines
2.7 KiB
TypeScript

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 { ensureToolLoader } from './ensure-tool-loader';
// Queue is now owned by the sidecar process
import { startDiscordBotIfConfigured } from './channels/discord/bot';
import { startTelegramBotIfConfigured } from './channels/telegram/bot';
import { startWhatsAppBotIfConfigured } from './channels/whatsapp/bot';
mkdirSync(DATA_PATH, { recursive: true });
/** Check common locations for the Pi package directory. */
async function findPiPackageDir(): Promise<string | null> {
const candidates = [
join(homedir(), '.npm-global', 'lib', 'node_modules', '@mariozechner', 'pi-coding-agent'),
'/usr/local/lib/node_modules/@mariozechner/pi-coding-agent',
];
for (const dir of candidates) {
if (await Bun.file(join(dir, 'package.json')).exists()) return dir;
}
return null;
}
async function ensurePiInstalled(): Promise<boolean> {
const dir = await findPiPackageDir();
if (!dir) return false;
try {
const pkg = await Bun.file(join(dir, 'package.json')).json();
if (pkg.version) {
console.log(`[bootstrap] Pi found: ${pkg.version}`);
return true;
}
} catch {}
return false;
}
async function installPi(): Promise<boolean> {
console.log('[bootstrap] Pi not found, installing...');
try {
const proc = Bun.spawn(['npm', 'install', '-g', '@mariozechner/pi-coding-agent'], {
stdout: 'pipe',
stderr: 'pipe',
});
const stderr = await new Response(proc.stderr).text();
await proc.exited;
if (proc.exitCode !== 0) {
console.error('[bootstrap] Pi installation failed:', stderr.trim());
return false;
}
console.log('[bootstrap] Pi installed successfully');
return true;
} catch (err) {
console.error('[bootstrap] Pi installation error:', err);
return false;
}
}
(async () => {
const installed = await ensurePiInstalled();
if (!installed) {
const ok = await installPi();
if (!ok) {
console.error('[bootstrap] Could not install Pi — model discovery will not work');
return;
}
}
await syncMarketplaceTools();
ensureToolLoader();
// Queue is initialized by the sidecar process
await startDiscordBotIfConfigured().catch((err) => {
console.error('[channels] Failed to start Discord bot:', err);
});
await startTelegramBotIfConfigured().catch((err) => {
console.error('[channels] Failed to start Telegram bot:', err);
});
await startWhatsAppBotIfConfigured().catch((err) => {
console.error('[channels] Failed to start WhatsApp bot:', err);
});
})();