From 8eaa20106a036f3129b11a6d2b52d64ee2a0e7ec Mon Sep 17 00:00:00 2001 From: mawkone Date: Wed, 10 Jun 2026 11:55:17 -0700 Subject: [PATCH] feat(orchestration): implement state-based loop governor with forced checkpoints, phase events, and robust tool signatures --- vibn-frontend/app/api/chat/route.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/vibn-frontend/app/api/chat/route.ts b/vibn-frontend/app/api/chat/route.ts index 853ef8cf..f31f3725 100644 --- a/vibn-frontend/app/api/chat/route.ts +++ b/vibn-frontend/app/api/chat/route.ts @@ -964,9 +964,17 @@ export async function POST(request: Request) { extraSystem += `\n\n[WARNING] You only have ${maxToolRounds - round} tool calls left before you are forcefully terminated. Stop exploring, make your final edits, and write your final response to the user NOW.`; } + // Execute tool calls and add results. OpenAI-compatible APIs + const resp = await callVibnChat({ + systemPrompt: systemPrompt + extraSystem, + messages, + tools: toolDefs, + temperature: 0.7, + includeThoughts: true, + }); + // C-08: Force Checkpoint Before Mutation - // If the AI is trying to use mutating tools but hasn't emitted a checkpoint, - // intercept the tool calls, block them, and force it to state its plan. + // (Moved safely *after* callVibnChat so 'resp' is defined) const requestedMutations = resp.toolCalls.filter((tc) => [ "fs_write", @@ -1010,15 +1018,6 @@ export async function POST(request: Request) { }); } - // Execute tool calls and add results. OpenAI-compatible APIs - const resp = await callVibnChat({ - systemPrompt: systemPrompt + extraSystem, - messages, - tools: toolDefs, - temperature: 0.7, - includeThoughts: true, - }); - if (resp.error) { emit({ type: "error", error: resp.error }); safeClose();