beadboard/src/tui/tools/bb-deviation.ts
zenchantlive d335e5bf71 fix: orchestrator button + Pi SDK session error
- Move leftSidebarMode from URL state to local useState in unified-shell,
    avoiding force-dynamic router round-trip that made the button appear broken                                           - Replace fileURLToPath(new URL(..., import.meta.url)) with process.cwd()
    in bb-pi-bootstrap.ts — import.meta.url is a webpack:// URL in Next.js,
    causing cross-realm TypeError when passed to Node.js fileURLToPath()
2026-03-24 19:02:04 -05:00

39 lines
1.6 KiB
TypeScript

import { Type } from '@sinclair/typebox';
import type { ToolDefinition } from '@mariozechner/pi-coding-agent';
import { embeddedPiDaemon } from '../../lib/embedded-daemon';
export function createDeviationTool(projectRoot: string): ToolDefinition {
return {
name: 'bb_record_deviation',
label: 'Record Template Deviation',
description: 'Log when and why you are deviating from a standard mission template (e.g., adding an extra worker, skipping an archetype, changing the flow).',
parameters: Type.Object({
reason: Type.String({ description: 'Why the deviation was necessary' }),
deviation_type: Type.String({ description: 'What kind of deviation (e.g., "extra_worker", "missing_archetype", "custom_flow")' }),
details: Type.Optional(Type.String({ description: 'Additional context about the deviation' })),
}),
async execute(_toolCallId, params: any) {
try {
// We use the existing daemon event system to record this
embeddedPiDaemon.appendEvent(projectRoot, {
kind: 'deviation.proposed',
title: `Deviation [${params.deviation_type}]`,
detail: params.reason,
status: 'idle',
});
return {
content: [{ type: 'text', text: 'Deviation recorded successfully.' }],
details: {},
};
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
return {
content: [{ type: 'text', text: `Failed to record deviation: ${message}` }],
isError: true,
details: {},
};
}
},
};
}