fix(companion): emit draft from user-turn tool_result + stamp space_id on created entities

- driver: tool_results arrive as type:'user' content blocks (not bare); parse them
- route: tool_result content is a JSON string; parse it for pending_change_id → draft event
- propose_change: inject ctx.space_id into create payloads (model can't know the uuid; tables require it)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-01 22:21:15 +10:00
parent 1e8bbca2a5
commit 1b8dc91800
3 changed files with 37 additions and 21 deletions

View File

@@ -23,13 +23,22 @@ export const proposeChangeTool = {
if (tier === 'deny') {
return { error: `not permitted to ${action} ${entity_type}` };
}
// Stamp the current Space onto newly-created space-scoped entities — the
// model doesn't know the Space uuid, and these tables require space_id NOT NULL.
const SPACE_SCOPED = ['task', 'page', 'project', 'resource'];
const finalPayload = { ...(payload ?? {}) };
if (action === 'create' && ctx.space_id && SPACE_SCOPED.includes(entity_type)
&& finalPayload.space_id == null) {
finalPayload.space_id = ctx.space_id;
}
// v1: drafting always routes through approval, even for allow-tier agents.
const change = await pendingChanges.create({
agent_id: ctx.agent.id,
entity_type,
entity_id: entity_id ?? null,
action,
payload: payload ?? {},
payload: finalPayload,
reason: reason ?? null
});
return {