opencode-api-security-testing 3.0.1 → 3.0.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/postinstall.mjs +91 -37
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-api-security-testing",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "API Security Testing Plugin for OpenCode - Automated vulnerability scanning and penetration testing",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/postinstall.mjs CHANGED
@@ -3,8 +3,10 @@
3
3
  /**
4
4
  * postinstall.mjs - API Security Testing Plugin
5
5
  *
6
- * Copies agent markdown files to ~/.config/opencode/agents/
7
- * This allows OpenCode to discover and use the agents.
6
+ * Installs:
7
+ * 1. Agents to ~/.config/opencode/agents/
8
+ * 2. Skill (SKILL.md) to ~/.config/opencode/skills/api-security-testing/
9
+ * 3. References to ~/.config/opencode/skills/api-security-testing/
8
10
  */
9
11
 
10
12
  import { copyFileSync, existsSync, mkdirSync, readdirSync } from "node:fs";
@@ -14,61 +16,113 @@ import { fileURLToPath } from "node:url";
14
16
  const __filename = fileURLToPath(import.meta.url);
15
17
  const __dirname = dirname(__filename);
16
18
 
17
- function getOpencodeAgentsDir() {
19
+ function getOpencodeBaseDir() {
18
20
  const home = process.env.HOME || process.env.USERPROFILE || "/root";
19
- // OpenCode uses ~/.config/opencode/agents on ALL platforms including Windows
20
- return join(home, ".config", "opencode", "agents");
21
+ return join(home, ".config", "opencode");
21
22
  }
22
23
 
23
24
  function main() {
24
25
  const packageRoot = __dirname;
25
26
  const agentsSourceDir = join(packageRoot, "agents");
26
- const agentsTargetDir = getOpencodeAgentsDir();
27
+ const agentsTargetDir = join(getOpencodeBaseDir(), "agents");
28
+ const skillTargetDir = join(getOpencodeBaseDir(), "skills", "api-security-testing");
27
29
 
28
- console.log("[api-security-testing] Installing agents...");
30
+ console.log("[api-security-testing] Installing...");
29
31
  console.log(` Package root: ${packageRoot}`);
30
- console.log(` Target: ${agentsTargetDir}`);
32
+ console.log(` Target base: ${getOpencodeBaseDir()}`);
31
33
 
32
- // Create target directory if needed
33
- if (!existsSync(agentsTargetDir)) {
34
- mkdirSync(agentsTargetDir, { recursive: true });
35
- console.log(` Created: ${agentsTargetDir}`);
36
- }
34
+ let successCount = 0;
35
+ let totalFiles = 0;
37
36
 
38
- // Check source directory
39
- if (!existsSync(agentsSourceDir)) {
40
- console.error("[api-security-testing] Error: agents source directory not found");
41
- process.exit(1);
37
+ // 1. Install agents
38
+ console.log("\n[1/3] Installing agents...");
39
+ if (existsSync(agentsSourceDir)) {
40
+ const agentFiles = readdirSync(agentsSourceDir).filter(f => f.endsWith(".md"));
41
+ totalFiles += agentFiles.length;
42
+
43
+ if (!existsSync(agentsTargetDir)) {
44
+ mkdirSync(agentsTargetDir, { recursive: true });
45
+ }
46
+
47
+ for (const file of agentFiles) {
48
+ const sourcePath = join(agentsSourceDir, file);
49
+ const targetPath = join(agentsTargetDir, file);
50
+ try {
51
+ copyFileSync(sourcePath, targetPath);
52
+ console.log(` ✓ Installed agent: ${file}`);
53
+ successCount++;
54
+ } catch (err) {
55
+ console.error(` ✗ Failed: ${file} - ${err.message}`);
56
+ }
57
+ }
58
+ } else {
59
+ console.error(" ✗ agents/ directory not found");
42
60
  }
43
61
 
44
- // Copy all .md files
45
- const files = readdirSync(agentsSourceDir).filter(f => f.endsWith(".md"));
62
+ // 2. Install SKILL.md
63
+ console.log("\n[2/3] Installing skill...");
64
+ const skillSource = join(packageRoot, "SKILL.md");
65
+ const skillTarget = join(skillTargetDir, "SKILL.md");
66
+ totalFiles++;
46
67
 
47
- if (files.length === 0) {
48
- console.error("[api-security-testing] Error: No agent files found");
49
- process.exit(1);
50
- }
51
-
52
- let successCount = 0;
53
- for (const file of files) {
54
- const sourcePath = join(agentsSourceDir, file);
55
- const targetPath = join(agentsTargetDir, file);
68
+ if (existsSync(skillSource)) {
69
+ if (!existsSync(skillTargetDir)) {
70
+ mkdirSync(skillTargetDir, { recursive: true });
71
+ }
56
72
  try {
57
- copyFileSync(sourcePath, targetPath);
58
- console.log(` Installed: ${file}`);
73
+ copyFileSync(skillSource, skillTarget);
74
+ console.log(` Installed: SKILL.md`);
59
75
  successCount++;
60
76
  } catch (err) {
61
- console.error(` Failed: ${file} - ${err.message}`);
77
+ console.error(` Failed: SKILL.md - ${err.message}`);
62
78
  }
79
+ } else {
80
+ console.error(" ✗ SKILL.md not found");
81
+ }
82
+
83
+ // 3. Install references
84
+ console.log("\n[3/3] Installing references...");
85
+ const refsSourceDir = join(packageRoot, "references");
86
+ const refsTargetDir = join(skillTargetDir, "references");
87
+
88
+ if (existsSync(refsSourceDir)) {
89
+ if (!existsSync(refsTargetDir)) {
90
+ mkdirSync(refsTargetDir, { recursive: true });
91
+ }
92
+
93
+ const refFiles = readdirSync(refsSourceDir, { recursive: true }).filter(f => typeof f === "string");
94
+ totalFiles += refFiles.length;
95
+
96
+ for (const file of refFiles) {
97
+ const sourcePath = join(refsSourceDir, file);
98
+ const targetPath = join(refsTargetDir, file);
99
+ const targetFileDir = join(refsTargetDir, file).replace(/\/[^\/]+$/, "");
100
+ if (!existsSync(targetFileDir)) {
101
+ mkdirSync(targetFileDir, { recursive: true });
102
+ }
103
+ try {
104
+ copyFileSync(sourcePath, targetPath);
105
+ console.log(` ✓ Installed: references/${file}`);
106
+ successCount++;
107
+ } catch (err) {
108
+ console.error(` ✗ Failed: references/${file} - ${err.message}`);
109
+ }
110
+ }
111
+ } else {
112
+ console.log(" (references/ not found, skipping)");
63
113
  }
64
114
 
65
- if (successCount === files.length) {
66
- console.log(`[api-security-testing] Successfully installed ${successCount} agent(s)`);
67
- console.log(` Location: ${agentsTargetDir}`);
68
- console.log("\nTo use the agents, run:");
69
- console.log(" opencode @api-cyber-supervisor");
115
+ // Summary
116
+ console.log("\n========================================");
117
+ if (successCount === totalFiles) {
118
+ console.log(`✓ Successfully installed ${successCount} file(s)`);
119
+ console.log(`\nAgent location: ${agentsTargetDir}`);
120
+ console.log(`Skill location: ${skillTargetDir}`);
121
+ console.log("\nTo use:");
122
+ console.log(" @api-cyber-supervisor - Start security testing");
123
+ console.log(" skill({ name: \"api-security-testing\" }) - Load skill");
70
124
  } else {
71
- console.error(`[api-security-testing] Partially installed: ${successCount}/${files.length}`);
125
+ console.log(`⚠ Partially installed: ${successCount}/${totalFiles}`);
72
126
  process.exit(1);
73
127
  }
74
128
  }