opencode-sa-assistant 0.2.2 → 0.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-sa-assistant",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "description": "OpenCode plugin for AWS Solutions Architect assistant with multi-agent Guru system",
@@ -2,59 +2,105 @@
2
2
  * WADD Mode Activation System
3
3
  *
4
4
  * Detects "wadd" keyword and activates AWS Solutions Architect mode.
5
- * Uses word boundary regex to prevent false positives.
5
+ * Follows oh-my-opencode keyword-detector pattern.
6
6
  */
7
7
 
8
8
  import { SA_ORCHESTRATOR_PROMPT } from "../prompts/orchestrator";
9
9
 
10
+ /**
11
+ * Patterns for code block removal (prevent false positives)
12
+ */
13
+ const CODE_BLOCK_PATTERN = /```[\s\S]*?```/g;
14
+ const INLINE_CODE_PATTERN = /`[^`]+`/g;
15
+
10
16
  /**
11
17
  * Regex pattern for WADD keyword detection
12
- * - \b: Word boundary (prevents matching "wa", "wadding", "mywadd")
18
+ * - \b: Word boundary (prevents matching "wadding", "mywadd")
13
19
  * - i flag: Case-insensitive matching
14
20
  */
15
21
  const WADD_PATTERN = /\bwadd\b/i;
16
22
 
17
23
  /**
18
- * Detects if content contains the WADD keyword
24
+ * SA Mode activation message (injected before user message)
25
+ */
26
+ const SA_MODE_MESSAGE = `[sa-mode]
27
+ AWS Solutions Architect Mode activated. You have access to:
28
+ - 4 Guru agents (sa-bezos, sa-vogels, sa-naval, sa-feynman)
29
+ - 3 Specialist agents (sa-explorer, sa-researcher, sa-reviewer)
30
+ - AWS MCP tools (aws-docs_search_documentation, aws-docs_read_documentation)
31
+
32
+ Follow Guru_Mandate: Consult appropriate Gurus before architecture decisions.
33
+ Apply Well-Architected Framework 6 pillars for all reviews.`;
34
+
35
+ /**
36
+ * Removes code blocks from text to prevent false keyword detection
37
+ */
38
+ export function removeCodeBlocks(text: string): string {
39
+ return text.replace(CODE_BLOCK_PATTERN, "").replace(INLINE_CODE_PATTERN, "");
40
+ }
41
+
42
+ /**
43
+ * Detects if content contains the WADD keyword (outside code blocks)
19
44
  * @param content - User message content to check
20
45
  * @returns true if WADD keyword found, false otherwise
21
46
  */
22
47
  export function detectWaddKeyword(content: string): boolean {
23
- return WADD_PATTERN.test(content);
48
+ const textWithoutCode = removeCodeBlocks(content);
49
+ return WADD_PATTERN.test(textWithoutCode);
24
50
  }
25
51
 
52
+ /**
53
+ * Extracts text from message parts array
54
+ */
26
55
  function extractPromptText(parts: any[]): string {
27
56
  if (!parts || !Array.isArray(parts)) return "";
28
57
  return parts
29
58
  .filter((p: any) => p.type === "text")
30
59
  .map((p: any) => p.text || "")
31
- .join("");
60
+ .join(" ");
32
61
  }
33
62
 
34
63
  /**
35
64
  * Hook: chat.message
36
- * Intercepts user messages to detect WADD keyword and activate SA mode
65
+ * Intercepts user messages to detect WADD keyword and activate SA mode.
66
+ * Follows oh-my-opencode pattern: inject message before user content.
37
67
  */
38
68
  export const chatMessageHook = async (input: any, output: any) => {
39
- const content = extractPromptText(output?.parts);
40
- if (!content) return;
69
+ const promptText = extractPromptText(output?.parts);
70
+ if (!promptText) return;
41
71
 
42
- if (detectWaddKeyword(content)) {
72
+ if (!detectWaddKeyword(promptText)) return;
73
+
74
+ // Set variant to "max" for best model (like ultrawork)
75
+ if (output.message) {
76
+ output.message.variant = "max";
77
+ } else {
43
78
  output.variant = "max";
44
-
45
- if (output.toasts) {
46
- output.toasts.push({
47
- type: "info",
48
- title: "SA Assistant Mode",
49
- message: "AWS Solutions Architect mode activated"
50
- });
51
- }
79
+ }
80
+
81
+ // Find text part and inject SA mode message before content
82
+ const textPartIndex = output.parts?.findIndex(
83
+ (p: any) => p.type === "text" && p.text !== undefined
84
+ );
85
+
86
+ if (textPartIndex !== -1 && output.parts[textPartIndex]) {
87
+ const originalText = output.parts[textPartIndex].text ?? "";
88
+ output.parts[textPartIndex].text = `${SA_MODE_MESSAGE}\n\n---\n\n${originalText}`;
89
+ }
90
+
91
+ // Show toast notification
92
+ if (output.toasts) {
93
+ output.toasts.push({
94
+ type: "info",
95
+ title: "SA Assistant Mode",
96
+ message: "AWS Solutions Architect mode activated"
97
+ });
52
98
  }
53
99
  };
54
100
 
55
101
  /**
56
102
  * Hook: experimental.chat.system.transform
57
- * Injects SA orchestrator system prompt when SA mode is active
103
+ * Injects SA orchestrator system prompt when SA mode is active.
58
104
  */
59
105
  export const systemTransformHook = async (input: any, output: any) => {
60
106
  const hasWadd = input.messages?.some((m: any) => {
@@ -64,7 +110,7 @@ export const systemTransformHook = async (input: any, output: any) => {
64
110
  const text = parts
65
111
  .filter((p: any) => p.type === "text")
66
112
  .map((p: any) => p.text || "")
67
- .join("");
113
+ .join(" ");
68
114
  return detectWaddKeyword(text);
69
115
  }
70
116
  return typeof parts === "string" && detectWaddKeyword(parts);