import { draftStore } from '../store/draft-store.js';
import { renderLevel } from '../core/ascii-renderer.js';
import { solve } from '../core/solver.js';
interface ToolDefinition {
name: string;
description: string;
inputSchema: object;
handler: (args: any) => Promise<{ content: Array<{ type: 'text'; text: string }> }>;
}
function checkActiveDraft(): string | null {
const draft = draftStore.getCurrentDraft();
if (!draft) {
return 'No active draft. Use create_level first.';
}
return null;
}
export function getVisualizationTools(): ToolDefinition[] {
return [
{
name: 'visualize_level',
description: 'Display ASCII art visualization of the current level, optionally with solution overlay',
inputSchema: {
type: 'object',
properties: {
showSolution: {
type: 'boolean',
description: 'Whether to overlay the solution path on the visualization',
default: false
},
showCoords: {
type: 'boolean',
description: 'Whether to show coordinate labels',
default: true
}
}
},
handler: async (args: { showSolution?: boolean; showCoords?: boolean }) => {
const error = checkActiveDraft();
if (error) {
return { content: [{ type: 'text', text: error }] };
}
const draft = draftStore.getCurrentDraft()!;
const showSolution = args.showSolution ?? false;
const showCoords = args.showCoords ?? true;
// If solution requested, solve first
if (showSolution) {
const puzzleData = draftStore.exportPuzzleData();
if (puzzleData) {
const result = solve(puzzleData);
draftStore.updateDraft({ lastSolverResult: result, isDirty: false });
}
}
const viz = renderLevel(draft, { showCoords, showSolution });
let output = viz + '\n\n';
// Add legend
output += 'Legend:\n';
output += ' S = Start\n';
output += ' G = Goal\n';
output += ' # = Wall/Rock\n';
output += ' X = Hot Coals\n';
output += ' ~ = Lava\n';
output += ' . = Dirt\n';
output += ' i = Thin ice\n';
output += ' W = Warp\n';
output += ' P = Pushable rock\n';
output += ' * = Pressure plate\n';
output += ' B = Barrier\n';
if (showSolution && draft.lastSolverResult?.solvable) {
output += '\n';
output += `Solution: ${draft.lastSolverResult.solution?.join(' → ')}\n`;
output += `Moves: ${draft.lastSolverResult.moves}\n`;
}
return { content: [{ type: 'text', text: output }] };
}
}
];
}