Skip to content

Commit 3686744

Browse files
committed
fix: use agent prompts instead of event hooks for context injection
OpenCode doesn't support injecting context through event hooks. Instead, the plugin now generates a prompt file that agents can reference via {file:./prompts/superpowers.txt} in their configuration.
1 parent c940d84 commit 3686744

2 files changed

Lines changed: 52 additions & 27 deletions

File tree

‎.opencode/INSTALL.md‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,40 @@ mkdir -p .opencode/plugin
3333
ln -sf ~/.config/opencode/superpowers/.opencode/plugin/superpowers.js .opencode/plugin/superpowers.js
3434
```
3535

36-
### 3. Restart OpenCode
36+
### 3. Configure Agent Prompt
3737

38-
Restart OpenCode to load the plugin. On the next session, you should see:
38+
The plugin generates a prompt file at `~/.config/opencode/prompts/superpowers.txt`. Add this to your agent configuration.
3939

40+
**Option A: Extend the Build agent** (recommended)
41+
42+
Edit `~/.config/opencode/opencode.json`:
43+
44+
```json
45+
{
46+
"agent": {
47+
"build": {
48+
"prompt": "{file:./prompts/superpowers.txt}"
49+
}
50+
}
51+
}
4052
```
41-
You have superpowers.
53+
54+
**Option B: Create a custom agent**
55+
56+
Create `~/.config/opencode/agent/superbuild.md`:
57+
58+
```markdown
59+
---
60+
description: Build agent with superpowers support
61+
---
62+
63+
{file:./prompts/superpowers.txt}
4264
```
4365

66+
### 4. Restart OpenCode
67+
68+
Restart OpenCode to load the plugin. The prompt file will be generated automatically.
69+
4470
## Usage
4571

4672
### Finding Skills

‎.opencode/plugin/superpowers.js‎

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Superpowers plugin for OpenCode.ai
33
*
44
* Provides custom tools for loading and discovering skills,
5-
* with automatic bootstrap on session start.
5+
* with prompt generation for agent configuration.
66
*/
77

88
import path from 'path';
@@ -19,6 +19,8 @@ export const SuperpowersPlugin = async ({ project, client, $, directory, worktre
1919
const homeDir = os.homedir();
2020
const superpowersSkillsDir = path.join(homeDir, '.config/opencode/superpowers/skills');
2121
const personalSkillsDir = path.join(homeDir, '.config/opencode/skills');
22+
const promptsDir = path.join(homeDir, '.config/opencode/prompts');
23+
const promptFile = path.join(promptsDir, 'superpowers.txt');
2224

2325
return {
2426
tools: [
@@ -79,18 +81,21 @@ ${content}`;
7981
}
8082
],
8183

82-
event: async ({ event }) => {
83-
if (event.type === 'session.created') {
84-
const usingSuperpowersPath = skillsCore.resolveSkillPath('using-superpowers', superpowersSkillsDir, personalSkillsDir);
84+
config: async () => {
85+
// Create prompts directory if it doesn't exist
86+
if (!fs.existsSync(promptsDir)) {
87+
fs.mkdirSync(promptsDir, { recursive: true });
88+
}
8589

86-
let usingSuperpowersContent = '';
87-
if (usingSuperpowersPath) {
88-
const fullContent = fs.readFileSync(usingSuperpowersPath.skillFile, 'utf8');
89-
usingSuperpowersContent = skillsCore.stripFrontmatter(fullContent);
90-
}
90+
// Generate prompt content
91+
const usingSuperpowersPath = skillsCore.resolveSkillPath('using-superpowers', superpowersSkillsDir, personalSkillsDir);
92+
let promptContent = '';
93+
94+
if (usingSuperpowersPath) {
95+
const fullContent = fs.readFileSync(usingSuperpowersPath.skillFile, 'utf8');
96+
const usingSuperpowersContent = skillsCore.stripFrontmatter(fullContent);
9197

92-
const toolMapping = `
93-
**Tool Mapping for OpenCode:**
98+
const toolMapping = `**Tool Mapping for OpenCode:**
9499
When skills reference tools you don't have, substitute OpenCode equivalents:
95100
- \`TodoWrite\` → \`update_plan\` (your planning/task tracking tool)
96101
- \`Task\` tool with subagents → Use OpenCode's subagent system (@mention syntax or automatic dispatch)
@@ -105,27 +110,21 @@ When skills reference tools you don't have, substitute OpenCode equivalents:
105110
**Skills naming:**
106111
- Superpowers skills: \`superpowers:skill-name\` (from ~/.config/opencode/superpowers/skills/)
107112
- Personal skills: \`skill-name\` (from ~/.config/opencode/skills/)
108-
- Personal skills override superpowers skills when names match
109-
`;
113+
- Personal skills override superpowers skills when names match`;
110114

111-
const hasUpdates = skillsCore.checkForUpdates(path.join(homeDir, '.config/opencode/superpowers'));
112-
113-
const updateNotice = hasUpdates ?
114-
'\n\n**Updates available!** Run `cd ~/.config/opencode/superpowers && git pull` to update superpowers.' :
115-
'';
116-
117-
return {
118-
context: `<EXTREMELY_IMPORTANT>
115+
promptContent = `<EXTREMELY_IMPORTANT>
119116
You have superpowers.
120117
121118
**Below is the full content of your 'superpowers:using-superpowers' skill - your introduction to using skills. For all other skills, use the 'use_skill' tool:**
122119
123120
${usingSuperpowersContent}
124121
125-
${toolMapping}${updateNotice}
126-
</EXTREMELY_IMPORTANT>`
127-
};
122+
${toolMapping}
123+
</EXTREMELY_IMPORTANT>`;
128124
}
125+
126+
// Write prompt file
127+
fs.writeFileSync(promptFile, promptContent, 'utf8');
129128
}
130129
};
131130
};

0 commit comments

Comments
 (0)