import type { GatewayChatMessage } from '@electron/providers/BaseProvider'; import { getEnabledSkillCapabilities } from './skill-capability-registry'; const AGENT_RUNTIME_CONTEXT = [ 'You are zn-ai, a desktop AI assistant running through a local OpenClaw-style gateway.', 'Treat host tools as explicit capabilities with real side effects.', 'Do not promise that an action was performed unless the runtime actually executed a listed tool.', ].join(' '); function formatRuntimeCapabilityLine(skill: ReturnType[number]): string { const details: string[] = [`category=${skill.category}`]; if (skill.operationHints.length > 0) { details.push(`operations=${skill.operationHints.join(',')}`); } if (skill.inputExtensions.length > 0) { details.push(`inputs=${skill.inputExtensions.join(',')}`); } if (skill.allowedTools.length > 0) { details.push(`allowedTools=${skill.allowedTools.join(',')}`); } if (skill.requiredEnvVars.length > 0) { details.push(`env=${skill.requiredEnvVars.join(',')}`); } if (skill.requiresAuth) { details.push('auth=required'); } details.push(`summary=${skill.plannerSummary}`); return `- ${skill.slug}: ${details.join('; ')}`; } function buildToolRuntimeContext(): string { const enabledSkillCapabilities = getEnabledSkillCapabilities(); const skillCapabilityLines = enabledSkillCapabilities.length > 0 ? enabledSkillCapabilities.map((skill) => formatRuntimeCapabilityLine(skill)) : ['- none']; return [ 'Available host tools in this build:', '- browser.open_url: opens an explicit http/https URL in the local managed browser when the user directly asks to open a page.', '- skills.install: installs a skill when the user explicitly asks to install a marketplace skill by slug or provides a GitHub skill URL.', 'Enabled skill capabilities registered for routing/planning:', ...skillCapabilityLines, 'Treat registered skills as planning capabilities for the downstream planner/executor chain, not as a claim that execution already happened.', 'Structured tool lifecycle updates may be emitted with running, completed, or error states.', 'Only claim a tool or skill action completed after the runtime reports success.', ].join('\n'); } export function buildRuntimeContextMessages(sessionKey: string): GatewayChatMessage[] { return [ { role: 'system', content: [ AGENT_RUNTIME_CONTEXT, buildToolRuntimeContext(), `Current session key: ${sessionKey}`, ].join('\n\n'), }, ]; }