opencode-andev-rules 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/plugin.js DELETED
@@ -1,96 +0,0 @@
1
- // @thaiannguyen-05/opencode-rules
2
- //
3
- // On-demand rule injection plugin for opencode.
4
- // When user says "follow the rule of andev" (or similar), fetches RULES.md
5
- // from GitHub and injects it into the system prompt.
6
- //
7
- // Hooks:
8
- // - chat.message: detect trigger phrase in user input
9
- // - experimental.chat.system.transform: inject rules into system prompt
10
-
11
- const RULES_URL = 'https://raw.githubusercontent.com/thaiannguyen-05/rules-for-global-agents/main/RULES.md';
12
-
13
- // Trigger patterns — case-insensitive
14
- const TRIGGER_PATTERNS = [
15
- /follow\s+(the\s+)?rules?\s+of\s+andev/i,
16
- /follow\s+andev\s+rules?/i,
17
- /use\s+andev\s+rules?/i,
18
- /apply\s+andev\s+rules?/i,
19
- /andev\s+rules/i,
20
- ];
21
-
22
- // In-memory cache: rules text per session
23
- let cachedRules = null;
24
- let fetchFailed = false;
25
-
26
- function detectTrigger(text) {
27
- if (!text) return false;
28
- return TRIGGER_PATTERNS.some((pattern) => pattern.test(text));
29
- }
30
-
31
- async function fetchRules() {
32
- // Return cache if available
33
- if (cachedRules !== null) return cachedRules;
34
-
35
- // Don't retry if fetch already failed
36
- if (fetchFailed) return null;
37
-
38
- try {
39
- const response = await fetch(RULES_URL, {
40
- headers: { Accept: 'text/plain' },
41
- });
42
-
43
- if (!response.ok) {
44
- fetchFailed = true;
45
- return null;
46
- }
47
-
48
- const text = await response.text();
49
-
50
- if (!text || text.trim().length === 0) {
51
- fetchFailed = true;
52
- return null;
53
- }
54
-
55
- cachedRules = text;
56
- return cachedRules;
57
- } catch {
58
- fetchFailed = true;
59
- return null;
60
- }
61
- }
62
-
63
- export const AndevRulesPlugin = async (_ctx) => {
64
- let triggerDetected = false;
65
-
66
- return {
67
- // Detect trigger phrase in user messages
68
- 'chat.message': async (_input, output) => {
69
- if (!output || !output.parts) return;
70
-
71
- for (const part of output.parts) {
72
- if (part && part.type === 'text' && part.text) {
73
- if (detectTrigger(part.text)) {
74
- triggerDetected = true;
75
- }
76
- }
77
- }
78
- },
79
-
80
- // Inject rules into system prompt when trigger was detected
81
- 'experimental.chat.system.transform': async (_input, output) => {
82
- if (!output || !Array.isArray(output.system)) return;
83
- if (!triggerDetected) return;
84
-
85
- const rules = await fetchRules();
86
- if (rules) {
87
- output.system.push(`## Rules from andev (follow these rules)\n\n${rules}`);
88
- }
89
-
90
- // Reset trigger for next message
91
- triggerDetected = false;
92
- },
93
- };
94
- };
95
-
96
- export default AndevRulesPlugin;