ALTER TABLE runtime_engines ADD COLUMN local_command TEXT;
ALTER TABLE runtime_engines ADD COLUMN local_args_json TEXT;
ALTER TABLE runtime_engines ADD COLUMN local_healthcheck_args_json TEXT;
ALTER TABLE runtime_engines ADD COLUMN local_working_dir TEXT;
ALTER TABLE runtime_engines ADD COLUMN local_env_json TEXT;
ALTER TABLE runtime_engines ADD COLUMN purpose_scopes_json TEXT;
ALTER TABLE runtime_engines ADD COLUMN timeout_ms INTEGER DEFAULT 300000;
ALTER TABLE runtime_engines ADD COLUMN notes TEXT;

CREATE TABLE IF NOT EXISTS runtime_agents (
  id                 TEXT PRIMARY KEY,
  name               TEXT NOT NULL,
  description        TEXT,
  prompt             TEXT,
  system_skill_kind  TEXT,
  runtime_code       TEXT,
  applies_to_json    TEXT,
  enabled            INTEGER DEFAULT 1,
  updated_at         INTEGER
);

INSERT OR IGNORE INTO runtime_engines (
  code, name, icon, protocol, local_command, local_args_json, local_healthcheck_args_json,
  purpose_scopes_json, timeout_ms, enabled, is_active, notes, updated_at
) VALUES
  (
    'local-codex',
    '本地 Codex CLI',
    '⌘',
    'local-cli',
    'codex',
    '["exec","--skip-git-repo-check","--dangerously-bypass-approvals-and-sandbox","-C","{workdir}","-"]',
    '["--version"]',
    '["create","evaluate","run"]',
    300000,
    0,
    0,
    '调用本机 codex exec；工作目录使用每次 Skill 运行的会话目录。',
    unixepoch()
  ),
  (
    'local-qoder',
    '本地 Qoder',
    'Q',
    'local-cli',
    'qoder',
    '["-"]',
    '["--version"]',
    '["create","evaluate","run"]',
    300000,
    0,
    0,
    '可按本机 Qoder CLI 的真实参数调整运行参数。',
    unixepoch()
  ),
  (
    'local-workbuddy',
    '本地 WorkBuddy',
    'W',
    'local-cli',
    'workbuddy',
    '["-p","--permission-mode","bypassPermissions"]',
    '["--version"]',
    '["create","evaluate","run"]',
    300000,
    0,
    0,
    '可按本机 WorkBuddy CLI 的真实参数调整运行参数。',
    unixepoch()
  ),
  (
    'local-trae',
    '本地 Trae Work',
    'T',
    'local-cli',
    'trae',
    '["-"]',
    '["--version"]',
    '["create","evaluate","run"]',
    300000,
    0,
    0,
    '可按本机 Trae Work CLI 的真实参数调整运行参数。',
    unixepoch()
  );

INSERT OR IGNORE INTO runtime_agents (
  id, name, description, prompt, system_skill_kind, runtime_code, applies_to_json, enabled, updated_at
) VALUES
  (
    'agent-skill-creator',
    'Skill 创建智能体',
    '负责把 AI 创建请求直接交给配置运行时执行并返回结果。',
    '直接执行用户任务；可按需使用运行时工具或生成文件，不要求固定输出格式。',
    'creator',
    'agentrun',
    '["create"]',
    1,
    unixepoch()
  ),
  (
    'agent-skill-evaluator',
    'Skill 评测智能体',
    '负责评测阶段，读取 Skill 包文件并输出有证据的评分。',
    '请先检查当前工作目录中的 Skill 包文件，再基于证据评分和给出改进建议。',
    'evaluator',
    'agentrun',
    '["evaluate"]',
    1,
    unixepoch()
  ),
  (
    'agent-skill-runner',
    'Skill 运行智能体',
    '负责已发布或沙箱 Skill 的真实运行。',
    '请严格按照当前 Skill 执行用户输入；如果 Skill 要求生成文件，请真实创建文件。',
    NULL,
    'agentrun',
    '["run"]',
    1,
    unixepoch()
  );
