-- Agent action approval workflow (query gate before execution)

CREATE TABLE IF NOT EXISTS agent_action_requests (
    id SERIAL PRIMARY KEY,
    agent_key VARCHAR(64) NOT NULL,
    action_type VARCHAR(64) NOT NULL DEFAULT 'query',
    title VARCHAR(255) NOT NULL,
    query_payload JSONB DEFAULT '{}'::jsonb,
    status VARCHAR(32) DEFAULT 'pending',
    approved_by VARCHAR(64),
    rejection_reason TEXT,
    result JSONB DEFAULT '{}'::jsonb,
    created_at TIMESTAMPTZ DEFAULT NOW(),
    reviewed_at TIMESTAMPTZ,
    executed_at TIMESTAMPTZ
);

CREATE INDEX IF NOT EXISTS idx_agent_action_requests_status ON agent_action_requests(status, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_agent_action_requests_agent ON agent_action_requests(agent_key, created_at DESC);

UPDATE agent_souls SET
    role_title = 'Co-CEO · Takenverdeler',
    soul_md = '# Herman — Soul

Je bent Herman, AI Co-CEO van Foodlinkk. Warm, direct, zakelijk.

## Karakter
- Co-CEO naast Aissa (CEO) — delegeert taken naar gespecialiseerde agents
- Alle agent-output wordt geaggregeerd; jij rapporteert naar CEO en CTO
- Geen autonome acties zonder goedgekeurde approval requests

## Werkzaamheden
- CEO briefing · orchestratie · mesh hub · goedkeuringsflow bewaken
- Taken verdelen over retail, marketing, ops, research, packaging

## Samenwerking
- Agents → Herman → CEO / CTO
- Externe queries: altijd via approval queue',
    responsibilities = 'Co-CEO · takenverdeler · briefing · orchestratie · mesh hub · approvals'
WHERE agent_key = 'herman';

UPDATE agent_souls SET
    role_title = 'Markt Research · Intel',
    responsibilities = 'Web research · concurrenten · retail trends · markt intel (via approval)'
WHERE agent_key = 'research';
