-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathbeans-prime.ts
More file actions
56 lines (50 loc) · 1.69 KB
/
beans-prime.ts
File metadata and controls
56 lines (50 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { Plugin } from '@opencode-ai/plugin';
/**
* Beans Prime Plugin for OpenCode
*
* This plugin injects the output of `beans prime` into OpenCode's system prompt,
* giving the AI context about your project's beans (issues/tasks). It runs on:
*
* - Chat session start: Adds bean context to the system prompt
* - Session compaction: Re-injects context when the session is compacted
*
* Plugin Location Options:
*
* 1. Project-local (current): .opencode/plugin/beans-prime.ts
* - Only available in this project
* - Committed to version control, shared with collaborators
*
* 2. User-global: ~/.opencode/plugin/beans-prime.ts
* - Available in all your projects that use beans
* - Personal configuration, not shared
*/
export const BeansPrimePlugin: Plugin = async ({ $, directory }) => {
// Check if beans CLI exists and project has beans config
let prime = undefined;
try {
// Both conditions must be true:
// 1. beans CLI is installed
// 2. Project has .beans.yml config
const hasBeans = await $`which beans`.quiet();
const hasConfig = await $`test -f ${directory}/.beans.yml`.quiet();
if (hasBeans.exitCode === 0 && hasConfig.exitCode === 0) {
const result = await $`beans prime`.cwd(directory).quiet();
prime = result.stdout.toString();
}
} catch (e) {
// beans not available or not configured - silently skip
}
return {
'experimental.chat.system.transform': async (_, output) => {
if (prime) {
output.system.push(prime);
}
},
'experimental.session.compacting': async (_, output) => {
if (prime) {
output.context.push(prime);
}
},
};
};
export default BeansPrimePlugin;