opencode-sa-assistant 0.2.3 → 0.2.4

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.3",
3
+ "version": "0.2.4",
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",
@@ -8,9 +8,10 @@
8
8
  import { SA_ORCHESTRATOR_PROMPT } from "../prompts/orchestrator";
9
9
  import { GURU_PROMPTS } from "../prompts/gurus";
10
10
  import { SPECIALIST_PROMPTS } from "../prompts/specialists";
11
- import { existsSync, mkdirSync, writeFileSync } from "fs";
12
- import { join } from "path";
11
+ import { existsSync, mkdirSync, writeFileSync, readFileSync } from "fs";
12
+ import { join, dirname } from "path";
13
13
  import { homedir } from "os";
14
+ import { fileURLToPath } from "url";
14
15
 
15
16
  /**
16
17
  * Agent definition with frontmatter metadata
@@ -164,3 +165,110 @@ export function uninstallSAAgents(): string[] {
164
165
 
165
166
  return removed;
166
167
  }
168
+
169
+ /**
170
+ * SA Skill names that will be installed
171
+ */
172
+ export const SA_SKILL_NAMES = ["docx", "pptx", "mcp", "guru"] as const;
173
+
174
+ /**
175
+ * Get the skills directory path for project-level installation
176
+ * Uses process.cwd() to find the project root
177
+ */
178
+ function getSkillsDir(): string {
179
+ return join(process.cwd(), ".opencode", "skills");
180
+ }
181
+
182
+ /**
183
+ * Get the source skills directory (where SKILL.md files are bundled)
184
+ */
185
+ function getSourceSkillsDir(): string {
186
+ // In ESM, use import.meta.url to find the module location
187
+ // Fallback to __dirname for CommonJS compatibility
188
+ try {
189
+ const currentFile = fileURLToPath(import.meta.url);
190
+ return join(dirname(currentFile), "..", "skills");
191
+ } catch {
192
+ // Fallback for environments where import.meta.url is not available
193
+ return join(__dirname, "..", "skills");
194
+ }
195
+ }
196
+
197
+ /**
198
+ * Install SA skills to .opencode/skills/
199
+ * Creates the directory structure if it doesn't exist.
200
+ * Only writes files if they don't exist (preserves user modifications).
201
+ */
202
+ export function installSASkills(): { installed: string[]; skipped: string[]; errors: string[] } {
203
+ const skillsDir = getSkillsDir();
204
+ const sourceDir = getSourceSkillsDir();
205
+ const installed: string[] = [];
206
+ const skipped: string[] = [];
207
+ const errors: string[] = [];
208
+
209
+ for (const skillName of SA_SKILL_NAMES) {
210
+ const targetDir = join(skillsDir, skillName);
211
+ const targetPath = join(targetDir, "SKILL.md");
212
+ const sourcePath = join(sourceDir, skillName, "SKILL.md");
213
+
214
+ try {
215
+ // Check if target already exists
216
+ if (existsSync(targetPath)) {
217
+ skipped.push(skillName);
218
+ continue;
219
+ }
220
+
221
+ // Read source file
222
+ if (!existsSync(sourcePath)) {
223
+ errors.push(`${skillName}: source file not found at ${sourcePath}`);
224
+ continue;
225
+ }
226
+
227
+ const content = readFileSync(sourcePath, "utf-8");
228
+
229
+ // Create target directory
230
+ if (!existsSync(targetDir)) {
231
+ mkdirSync(targetDir, { recursive: true });
232
+ }
233
+
234
+ // Write skill file
235
+ writeFileSync(targetPath, content, "utf-8");
236
+ installed.push(skillName);
237
+ } catch (err) {
238
+ errors.push(`${skillName}: ${err instanceof Error ? err.message : String(err)}`);
239
+ }
240
+ }
241
+
242
+ return { installed, skipped, errors };
243
+ }
244
+
245
+ /**
246
+ * Uninstall SA skills (remove SKILL.md files and directories)
247
+ */
248
+ export function uninstallSASkills(): string[] {
249
+ const skillsDir = getSkillsDir();
250
+ const removed: string[] = [];
251
+
252
+ for (const skillName of SA_SKILL_NAMES) {
253
+ const skillDir = join(skillsDir, skillName);
254
+ const skillPath = join(skillDir, "SKILL.md");
255
+
256
+ if (existsSync(skillPath)) {
257
+ try {
258
+ const { unlinkSync, rmdirSync } = require("fs");
259
+ unlinkSync(skillPath);
260
+ // Try to remove the directory if empty
261
+ try {
262
+ rmdirSync(skillDir);
263
+ } catch {
264
+ // Directory not empty, leave it
265
+ }
266
+ removed.push(skillName);
267
+ } catch {
268
+ // Ignore errors during uninstall
269
+ }
270
+ }
271
+ }
272
+
273
+ return removed;
274
+ }
package/src/index.ts CHANGED
@@ -1,12 +1,21 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
2
  import { chatMessageHook, systemTransformHook } from "./hooks/wadd-mode";
3
- import { installSAAgents } from "./agents";
3
+ import { installSAAgents, installSASkills } from "./agents";
4
4
 
5
5
  export const SaAssistantPlugin: Plugin = async (ctx) => {
6
- const { installed, skipped } = installSAAgents();
6
+ const agentResult = installSAAgents();
7
+ const skillResult = installSASkills();
7
8
 
8
- if (installed.length > 0) {
9
- console.log(`[SA Assistant] Installed agents: ${installed.join(", ")}`);
9
+ if (agentResult.installed.length > 0) {
10
+ console.log(`[SA Assistant] Installed agents: ${agentResult.installed.join(", ")}`);
11
+ }
12
+
13
+ if (skillResult.installed.length > 0) {
14
+ console.log(`[SA Assistant] Installed skills: ${skillResult.installed.join(", ")}`);
15
+ }
16
+
17
+ if (skillResult.errors.length > 0) {
18
+ console.warn(`[SA Assistant] Skill installation errors: ${skillResult.errors.join(", ")}`);
10
19
  }
11
20
 
12
21
  return {