Files
opencode-power-pack/.opencode/plugins/opencode-power-pack.js
T
Yefta Sutanto 4dfff60ff5 refactor(opencode): simplify the dual-host plugin and stop sharing agent state
- Drop the @opencode/plugin dependency: Plugin.define is an identity
  function, and both hosts load a plain { id, setup, server } object.
  This removes ~3,700 lockfile lines from every OpenCode 1 and 2 install.
- Remove the OpencodePowerPack named export. OpenCode 1.18.7+ uses the
  default export's server() and never scans named exports when it exists.
- Derive the OpenCode 2 rulesets from the OpenCode 1 permission maps so
  the read-only policy has a single source, and parse SKILL.md once.
- Build fresh agent definitions per hook call. OpenCode 2 appends global
  rules to agent permissions in place, and the shared module array leaked
  those rules between code-explorer and code-architect.
- Un-export eval runner helpers that nothing imports.
2026-09-24 10:39:25 +10:00

62 lines
2.5 KiB
JavaScript

/**
* opencode-power-pack
*
* Registers every bundled skill and the feature workflow's specialist roles
* as read-only subagents derived from their SKILL.md bodies, on both hosts:
*
* - OpenCode 2 calls `setup` and receives the skill and agent transforms.
* - OpenCode 1 (1.18.7+) calls `server` on the default export and receives
* the config hook, which registers skills/ in `config.skills.paths` and
* merges the agents into `config.agent`.
*
* User-defined agents with the same names are preserved.
*
* ──── Attribution ────────────────────────────────────────────────────────
*
* The OpenCode 1 loader pattern (importing fs/path via fileURLToPath and
* pushing into config.skills.paths via the `config` hook) is adapted directly
* from Jesse Vincent's superpowers plugin: https://github.com/obra/superpowers
*
* The skills under skills/ are modified upstream works. See UPSTREAMS.json
* for immutable source commits and blobs, and THIRD_PARTY_NOTICES.md for
* their licenses and attribution.
* ─────────────────────────────────────────────────────────────────────────
*/
import path from 'path';
import { fileURLToPath } from 'url';
import { agents, legacyAgents, loadSkills } from '../lib/agent-config.js';
const skillsDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../skills');
const skills = loadSkills(skillsDir);
export default {
id: 'opencode-power-pack',
async setup(ctx) {
await ctx.skill.transform((editor) => {
for (const skill of skills) editor.add({ ...skill });
});
await ctx.agent.transform((editor) => {
for (const [name, agent] of Object.entries(agents(skills))) {
if (!editor.get(name)) editor.update(name, (draft) => Object.assign(draft, agent));
}
});
},
async server() {
return {
config: async (config) => {
config.skills = config.skills || {};
config.skills.paths = config.skills.paths || [];
if (!config.skills.paths.includes(skillsDir)) config.skills.paths.push(skillsDir);
config.agent = config.agent || {};
for (const [name, agent] of Object.entries(legacyAgents(skills))) {
if (!config.agent[name]) config.agent[name] = agent;
}
},
};
},
};