@headsdown/opencodeHeadsDown availability and focus-mode gating plugin for OpenCode.
0
17
近 7 天 2
27.7
生态多维模型
4 天前
2026-08-15
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@headsdown/opencode@0.1.3"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@headsdown/opencode@0.1.3"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @headsdown/opencodeopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
HeadsDown availability-awareness and task-gating plugin for OpenCode.
What it does
- Adds
headsdown_policy,headsdown_approve,headsdown_digest,headsdown_outcome, andheadsdown_authtools to OpenCode - Injects HeadsDown execution guidance into system prompts on every turn
- Enforces policy through both permission mediation and pre-tool hard gates
- Applies mode-aware model shaping via
chat.params,chat.headers, andshell.env - Shapes tool definitions with mode-aware HeadsDown constraints
- Persists policy context during session compaction and can disable auto-continue in strict Wrap-Up windows
- Tracks approved proposals and reports outcomes for calibration
Install
npm install @headsdown/opencode
Then configure OpenCode in opencode.json (published npm mode):
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@headsdown/opencode", "@headsdown/opencode/tui"]
}
@headsdown/opencode loads server-side policy hooks and tools.
@headsdown/opencode/tui adds TUI-only status toasts and command palette actions.
Why two plugins?
- OpenCode uses separate plugin surfaces for runtime/server behavior and TUI behavior.
- This package exports both surfaces (
@headsdown/opencodeand@headsdown/opencode/tui) so each can be loaded in the correct place.
First-time auth
Inside OpenCode, run the headsdown_auth tool and complete the Device Flow.
After auth, use headsdown_policy to confirm your current mode, schedule state, and execution guidance.
Proposal and outcome workflow
When the user is in busy or limited mode and the agent needs to modify files:
- Call
headsdown_approve - If approved, continue the task
- If deferred, summarize and ask the user whether to postpone or reduce scope
- After completion/failure, call
headsdown_outcomewith the outcome
Use headsdown_digest at session start or when asked "what did I miss?" to review updates that arrived during focus mode.
TUI features
The TUI plugin adds:
HeadsDown: Refresh policycommand (/headsdown-policy-refresh)HeadsDown: Show policycommand (/headsdown-policy)- Transition toasts when mode changes or Wrap-Up/lock state becomes active
- Note: this plugin currently does not add a persistent sidebar panel.
Development
cd headsdown-opencode
npm install
npm run build
npm test
Build output bundling
The published dist/index.js and dist/tui.js files are bundled with esbuild. This keeps @headsdown/sdk inlined in the distributed artifacts so consumers do not pull it as a transitive runtime dependency.
Build commands:
esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.js --external:@opencode-ai/plugin
esbuild src/tui.ts --bundle --platform=node --format=esm --outfile=dist/tui.js --external:@opencode-ai/plugin
@opencode-ai/plugin stays external because it is provided by the OpenCode host at runtime.
Local plugin toggle helper
Use scripts/toggle-headsdown-plugin.sh from a target OpenCode project to switch between:
local: loads this repo's built files through local shims (.opencode/plugins)published: loads@headsdown/opencodeand@headsdown/opencode/tuifrom npm inopencode.json
In local mode, opencode.json may keep an empty plugin array while local shims are used.
Example:
./scripts/toggle-headsdown-plugin.sh local
Dependency update automation
This repo uses Renovate to keep @headsdown/sdk and other routine dependencies current. New SDK releases open bot PRs automatically, and eligible updates can automerge after required CI checks pass. In normal maintenance flow, do not manually edit @headsdown/sdk versions unless you are intentionally overriding Renovate behavior.
License
MIT