Skip to content

v2.0.0 — OpenCode V2 Plugin Port

Choose a tag to compare

@6zev 6zev released this 22 Oct 05:51
· 89 commits to main since this release

v2.0.0 — OpenCode V2 Plugin Port

Plugin @hung319/opencode-hive 2.0.0: port toàn bộ API plugin từ OpenCode V1 sang OpenCode 2.x (Plugin.define). Bản V1 không còn được hỗ trợ.

Breaking — yêu cầu OpenCode 2.x

  • Entry point mới: Plugin.define({ id: 'opencode-hive', async setup(ctx) → cleanup }).
  • Đã bỏ mọi API V1: PluginInput, hooks, experimental.chat.system.transform, experimental.session.compacting, hooks.config.
  • Loader: OpenCode V2 resolve entry plugin theo package.json exports → index.js tầng gốc — ship shim export { default } from './dist/index.js'.

Hooks mapping (V1 → V2)

V1 V2
experimental.chat.system.transform session context hook — 2 hook cùng tên: [0] = system injection (HIVE_SYSTEM_PROMPT dạng {type:'text',text}), .at(-1) = per-agent hive-tool gate (mutate event.tools in place)
experimental.session.compacting session compaction hook — event {sessionID, system, messages}, push snapshot/compression hint dạng {type:'text',text}
per-agent tools deny map trong config gating trong context hook qua agentAllowedTools (custom agents kế thừa map của base agent)
hooks.tool[name].execute(input, ctx) ctx.tool.transform(editor.add(tool())) + compat layer: execute legacy (input, ctx) → V2 (args, v2Context), kết quả string → {content}
hooks.config(opencodeConfig) sinh trực tiếp .opencode/agents/<id>.md (V2 xoá hook config)
default_agent / demote built-in ctx.agent.transform(agentEditor.default("zetta")) — built-in không bị demote (demoting build làm mọi session mặc định vỡ AgentNotFoundError)

Agent bootstrap V2

  • v2-bootstrap.ts sinh 1 markdown agent definition cho mỗi hive agent từ runtime config V1-shape:
    • permissions: YAML flow-map: - { action: "read", resource: "*", effect: "allow" } (alias V2: task/delegate → subagent, bash → shell, write/patch → edit)
    • model: provider/model#variant (bare variant không có model bị bỏ ngầm — kế thừa session model, semantics như V1 model-sanitize)
    • temperature: frontmatter (field hợp lệ theo schema/docs V2) — mới: giữ đúng docs-sync của ví dụ custom-agents trong README (forager-ui 0.2, reviewer-security 0.3 mặc định kế thừa)
    • description dạng JSON.stringify (YAML double-quoted scalar)
  • Custom agents (customAgents.<id>.baseAgent) resolve như V1: kế thừa model/variant/temperature của base.

Client adaptations

  • OpenCodeProviderService(client, defaultSessionID?) — gọi LLM qua session.generate({ sessionID, prompt }), trả {text}.
  • captureStructuredMemory(ctx, sessionID?) — forward sessionID (V2 không cung cấp client/event loop như V1).
  • HiddenJudge + compaction restoration gọi session.synthetic.

Tests

  • Harness dùng chung src/__tests__/v2-harness.ts: runV2PluginSetup({ directory?, config? }) (có config → isolate $HOME vào temp dir + seed agent_hive.json; không có → giữ $HOME ambient), sessionHooks: Map<string, Handler[]>, execTool (unwrap {content}), createV2ToolContext, agentPromptProxy (đọc prompt từ body agent md).
  • Port 5 e2e suites: plugin-smoke (18), config-autoload-skills (17), agent-mode (4), opencode-runtime-smoke (4 + 1 skip runtime thật), custom-agent-docs-example (1).
  • Toàn bộ: 624 pass / 0 fail / 1 skip (46 files, 1504 assertions).

Verify

  • bunx tsc --noEmit: 0 errors; bun run build: dist 1.12 MB.
  • Runtime thật (opencode v2.1.2): plugin nạp (loading plugin id=.../hive-root), banner zetta · big-pickle, 8 agent md sinh đúng (có field temperature mới), exit=0.

Upgrade notes

  • Người dùng plugin: không cần thay đổi gì — overrides đổi qua agent_hive.json (agents / customAgents) như docs README; format file này không đổi.
  • Tùy chọn khác zetta: agents.<id> theo README; built-in build/plan không bị plugin chạm tới.
  • Consumer gọi trực tiếp hive-core: không đổi API.