opencode-sa-assistant 0.2.1 → 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 +1 -1
- package/src/hooks/wadd-mode.ts +80 -32
package/package.json
CHANGED
package/src/hooks/wadd-mode.ts
CHANGED
|
@@ -2,71 +2,119 @@
|
|
|
2
2
|
* WADD Mode Activation System
|
|
3
3
|
*
|
|
4
4
|
* Detects "wadd" keyword and activates AWS Solutions Architect mode.
|
|
5
|
-
*
|
|
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 "
|
|
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
|
-
*
|
|
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
|
-
|
|
48
|
+
const textWithoutCode = removeCodeBlocks(content);
|
|
49
|
+
return WADD_PATTERN.test(textWithoutCode);
|
|
24
50
|
}
|
|
25
51
|
|
|
26
52
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @param message - Message object to modify
|
|
53
|
+
* Extracts text from message parts array
|
|
29
54
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
message.content = `[SA MODE ACTIVATED]\n\n${message.content}`;
|
|
55
|
+
function extractPromptText(parts: any[]): string {
|
|
56
|
+
if (!parts || !Array.isArray(parts)) return "";
|
|
57
|
+
return parts
|
|
58
|
+
.filter((p: any) => p.type === "text")
|
|
59
|
+
.map((p: any) => p.text || "")
|
|
60
|
+
.join(" ");
|
|
37
61
|
}
|
|
38
62
|
|
|
39
63
|
/**
|
|
40
64
|
* Hook: chat.message
|
|
41
|
-
* 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.
|
|
42
67
|
*/
|
|
43
68
|
export const chatMessageHook = async (input: any, output: any) => {
|
|
44
|
-
const
|
|
45
|
-
if (!
|
|
69
|
+
const promptText = extractPromptText(output?.parts);
|
|
70
|
+
if (!promptText) return;
|
|
46
71
|
|
|
47
|
-
if (detectWaddKeyword(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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 {
|
|
78
|
+
output.variant = "max";
|
|
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
|
+
});
|
|
58
98
|
}
|
|
59
99
|
};
|
|
60
100
|
|
|
61
101
|
/**
|
|
62
102
|
* Hook: experimental.chat.system.transform
|
|
63
|
-
* Injects SA orchestrator system prompt when SA mode is active
|
|
103
|
+
* Injects SA orchestrator system prompt when SA mode is active.
|
|
64
104
|
*/
|
|
65
105
|
export const systemTransformHook = async (input: any, output: any) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
m.
|
|
69
|
-
|
|
106
|
+
const hasWadd = input.messages?.some((m: any) => {
|
|
107
|
+
if (m.role !== "user") return false;
|
|
108
|
+
const parts = m.parts || m.content;
|
|
109
|
+
if (Array.isArray(parts)) {
|
|
110
|
+
const text = parts
|
|
111
|
+
.filter((p: any) => p.type === "text")
|
|
112
|
+
.map((p: any) => p.text || "")
|
|
113
|
+
.join(" ");
|
|
114
|
+
return detectWaddKeyword(text);
|
|
115
|
+
}
|
|
116
|
+
return typeof parts === "string" && detectWaddKeyword(parts);
|
|
117
|
+
});
|
|
70
118
|
|
|
71
119
|
if (hasWadd) {
|
|
72
120
|
output.system = `${output.system || ""}\n\n${SA_ORCHESTRATOR_PROMPT}`;
|