Phase 2 of v2.0. BooCoder is now a functional write-capable chatbot.
Write-path guard: resolveWritePath() uses resolve() (no realpath — files may
not exist for creates) + prefix-check + secret-file deny list (.env, *.pem,
id_rsa*, etc.). 23 unit tests cover traversal attacks.
Pending-changes service: queueEdit/Create/Delete → applyOne/All →
rejectOne/All → rewindOne. Edit diffs stored as JSON {old, new}. All writes
queue before touching disk; apply re-validates the path guard.
5 write tools: edit_file, create_file, delete_file, apply_pending, rewind.
Registered alongside 25 read-only tools from BooChat (30 total, alpha-sorted).
Write tools use a module-level inference context for sql+sessionId injection.
Inference loop via workspace dependency: apps/coder imports
createInferenceRunner, createBroker, ALL_TOOLS from @boocode/server (dist/).
apps/server gains declaration: true + exports map with typed subpath entries.
No code duplication — one inference engine shared by both apps.
API routes: POST /api/sessions/:id/messages (user msg → inference), POST stop,
GET/POST pending-changes CRUD (5 endpoints), WebSocket session streaming.
Dockerfile updated to build apps/server first (coder depends on its .d.ts).
Health endpoint reports tool count: {"ok":true,"db":true,"tools":30}.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { z } from 'zod';
|
|
import type { ToolDef, ToolContext } from './types.js';
|
|
import { queueCreate } from '../pending_changes.js';
|
|
|
|
const CreateFileInput = z.object({
|
|
file_path: z.string().min(1),
|
|
content: z.string(),
|
|
});
|
|
type CreateFileInputT = z.infer<typeof CreateFileInput>;
|
|
|
|
export const createFileTool: ToolDef<CreateFileInputT> = {
|
|
name: 'create_file',
|
|
description:
|
|
'Queue creation of a new file with the given content. ' +
|
|
'The change is staged in pending_changes and must be applied explicitly.',
|
|
inputSchema: CreateFileInput,
|
|
jsonSchema: {
|
|
type: 'function',
|
|
function: {
|
|
name: 'create_file',
|
|
description:
|
|
'Queue creation of a new file with the given content. ' +
|
|
'The change is staged in pending_changes and must be applied explicitly.',
|
|
parameters: {
|
|
type: 'object',
|
|
properties: {
|
|
file_path: { type: 'string', description: 'Path for the new file (relative to project root or absolute)' },
|
|
content: { type: 'string', description: 'Full content of the file to create' },
|
|
},
|
|
required: ['file_path', 'content'],
|
|
},
|
|
},
|
|
},
|
|
async execute(input: CreateFileInputT, projectRoot: string, context: ToolContext): Promise<unknown> {
|
|
const change = await queueCreate(
|
|
context.sql,
|
|
context.sessionId,
|
|
context.taskId,
|
|
input.file_path,
|
|
input.content,
|
|
projectRoot,
|
|
);
|
|
return {
|
|
status: 'queued',
|
|
change_id: change.id,
|
|
file_path: change.file_path,
|
|
operation: 'create',
|
|
message: `File creation queued: ${change.file_path}. Use apply_pending to write changes to disk.`,
|
|
};
|
|
},
|
|
};
|