ocs-stats 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,235 @@
1
+ # OpenCode Skills & Agents
2
+
3
+ A collection of reusable skills and agents for [OpenCode](https://opencode.ai) - an AI-powered development assistant that runs in your terminal.
4
+
5
+ ## What This Does
6
+
7
+ When you add these files to your project, OpenCode will:
8
+ - Follow your coding conventions (formatting, patterns, etc.)
9
+ - Write commit messages in your preferred format
10
+ - Audit your code for security vulnerabilities
11
+ - Use proper patterns for your tech stack
12
+
13
+ ## Installation
14
+
15
+ ### Method 1: NPX (Recommended)
16
+
17
+ ```bash
18
+ cd /path/to/your/project
19
+ npx ocs-stats
20
+ ```
21
+
22
+ That's it! The `.opencode` folder will be created in your project.
23
+
24
+ **Global install** (shared across all projects):
25
+ ```bash
26
+ npx ocs-stats --global
27
+ ```
28
+
29
+ ### Method 2: Download ZIP
30
+
31
+ 1. Click the green **"Code"** button at the top of this page
32
+ 2. Select **"Download ZIP"**
33
+ 3. Extract the ZIP file
34
+ 4. Copy the `templates/.opencode` folder to your project root
35
+
36
+ ```
37
+ your-project/
38
+ ├── .opencode/ ← Paste this folder here
39
+ ├── src/
40
+ ├── package.json
41
+ └── ...
42
+ ```
43
+
44
+ ### Method 3: Clone & Copy
45
+
46
+ ```bash
47
+ git clone https://github.com/Zen0space/opencode-skills.git
48
+ cp -r opencode-skills/templates/.opencode /path/to/your/project/
49
+ ```
50
+
51
+ ## Verify Installation
52
+
53
+ ```bash
54
+ cd /path/to/your/project
55
+ opencode
56
+ ```
57
+
58
+ OpenCode automatically loads any `.opencode` folder in your project root.
59
+
60
+ ## Check Your Progress
61
+
62
+ Use the `stats` command to view your security agent's progress:
63
+
64
+ ```bash
65
+ npx ocs-stats stats
66
+ ```
67
+
68
+ Example output:
69
+ ```
70
+ ╔══════════════════════════════════════╗
71
+ ║ SECURITY AGENT ║
72
+ ╠══════════════════════════════════════╣
73
+ ║ Level 1 - Novice ║
74
+ ║ XP: [█████████░░░░░░░░] 85/150 ║
75
+ ║ Progress: 57% ║
76
+ ║ ║
77
+ ║ Stats: ║
78
+ ║ * Issues Fixed: 4 ║
79
+ ║ * Audits Done: 2 ║
80
+ ║ * Patterns Added: 1 ║
81
+ ║ * XP Penalties: 0 ║
82
+ ╚══════════════════════════════════════╝
83
+ ```
84
+
85
+ ## Update Skills
86
+
87
+ ```bash
88
+ npx ocs-stats update
89
+ ```
90
+
91
+ ## What's Included
92
+
93
+ ### Agents
94
+
95
+ | Agent | Description |
96
+ |-------|-------------|
97
+ | `security` | Security expert with XP-based leveling system for auditing and fixing vulnerabilities |
98
+
99
+ ### Skills
100
+
101
+ | Skill | Description |
102
+ |-------|-------------|
103
+ | `commit` | Commit message conventions (type(scope): description format) |
104
+ | `memories` | Session memory for tracking work context and pending tasks |
105
+ | `mobile` | Mobile development (React Native, Flutter, Swift) |
106
+ | `security` | Security patterns, auth approach, and anti-patterns |
107
+ | `webapp` | Web development (React, Vue, Svelte, Angular) |
108
+
109
+ ## Customization
110
+
111
+ ### Understand Session Memory
112
+
113
+ The `memories` skill tracks your current work session:
114
+ - **Current Focus:** What you're actively working on
115
+ - **Recent Work:** Last changes made
116
+ - **Pending Tasks:** TODOs to complete
117
+ - **Context Notes:** Important decisions and gotchas
118
+
119
+ The agent reads and updates this file automatically. You can also edit it manually.
120
+
121
+ ### Update Commit Conventions (Optional)
122
+
123
+ Edit `.opencode/skills/commit/SKILL.md` if you use different commit formats.
124
+
125
+ ### Remove What You Don't Need
126
+
127
+ ```bash
128
+ # Remove mobile skill if you're not building a mobile app
129
+ rm -rf .opencode/skills/mobile
130
+
131
+ # Remove security agent if you don't need security audits
132
+ rm -rf .opencode/agents/security
133
+ rm -rf .opencode/security
134
+ ```
135
+
136
+ ## Security Agent Features
137
+
138
+ The security agent includes an XP-based leveling system that tracks your progress:
139
+
140
+ | Level | Title | XP Required |
141
+ |-------|-------|-------------|
142
+ | 1 | Novice | 0 |
143
+ | 2 | Apprentice | 150 |
144
+ | 3 | Practitioner | 450 |
145
+ | 4 | Expert | 900 |
146
+ | 5 | Master | 1500 |
147
+ | 6 | Grandmaster | 3,000 |
148
+
149
+ ### XP Awards (Fix-Only System)
150
+
151
+ | Action | XP |
152
+ |--------|-----|
153
+ | Fix critical issue | +60 XP |
154
+ | Fix high issue | +35 XP |
155
+ | Fix medium issue | +15 XP |
156
+ | Fix low issue | +10 XP |
157
+ | Add security pattern | +30 XP |
158
+ | Complete package audit | +75 XP |
159
+
160
+ ### Preflight Checklist
161
+
162
+ Before risky operations (auth changes, DB schema, middleware), the agent:
163
+ 1. Shows a dry-run preview
164
+ 2. Confirms user permission
165
+ 3. Documents rollback plan
166
+
167
+ ## File Structure
168
+
169
+ ```
170
+ .opencode/
171
+ ├── agents/
172
+ │ └── security.md # Security audit agent
173
+ ├── skills/
174
+ │ ├── commit/SKILL.md # Commit conventions
175
+ │ ├── memories/SKILL.md # Session memory (auto-updated)
176
+ │ ├── mobile/SKILL.md # Mobile patterns (RN, Flutter, Swift)
177
+ │ ├── security/SKILL.md # Security patterns
178
+ │ └── webapp/SKILL.md # Web patterns (React, Vue, Svelte, Angular)
179
+ └── security/
180
+ ├── xp.json # XP tracking (auto-updated)
181
+ └── knowledge.md # Accumulated findings (auto-updated)
182
+ ```
183
+
184
+ ## For Contributors
185
+
186
+ ```
187
+ opencode-skills/
188
+ ├── package.json # npm package config
189
+ ├── bin/cli.js # CLI entry point
190
+ ├── src/ # Source files
191
+ │ ├── init.js
192
+ │ ├── display.js
193
+ │ └── stats.js
194
+ ├── templates/ # Files copied to user projects
195
+ │ ├── agents/
196
+ │ ├── skills/
197
+ │ └── security/
198
+ ├── README.md
199
+ └── LICENSE
200
+ ```
201
+
202
+ **Publishing to npm:**
203
+ ```bash
204
+ npm login
205
+ npm publish
206
+ ```
207
+
208
+ ## Troubleshooting
209
+
210
+ ### OpenCode not finding my skills
211
+
212
+ - Make sure `.opencode` folder is in your **project root** (same level as `package.json`)
213
+ - Check that skill files are named `SKILL.md` (uppercase)
214
+
215
+ ### Skills not working as expected
216
+
217
+ - Open the `SKILL.md` file and verify the content
218
+ - Make sure the frontmatter (between `---`) is valid YAML
219
+
220
+ ### Want to reset security XP?
221
+
222
+ Delete the tracking files and OpenCode will recreate them:
223
+
224
+ ```bash
225
+ rm .opencode/security/xp.json
226
+ rm .opencode/security/knowledge.md
227
+ ```
228
+
229
+ ## Contributing
230
+
231
+ Feel free to submit issues and pull requests to improve these skills and agents.
232
+
233
+ ## License
234
+
235
+ MIT License - see [LICENSE](LICENSE) for details.
package/bin/cli.js ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { init, update } from '../src/init.js';
4
+ import { stats, displayXp } from '../src/stats.js';
5
+
6
+ const args = process.argv.slice(2);
7
+ const command = args[0];
8
+ const isGlobal = args.includes('--global') || args.includes('-g');
9
+ const isHelp = args.includes('--help') || args.includes('-h');
10
+
11
+ if (isHelp) {
12
+ console.log(`
13
+ ocs-stats - Install OpenCode skills and agents
14
+
15
+ Usage:
16
+ npx ocs-stats Install to current project
17
+ npx ocs-stats --global Install globally (~/.opencode)
18
+ npx ocs-stats update Update skills (removes existing)
19
+ npx ocs-stats stats Show security agent progress
20
+ npx ocs-stats display-xp <amount> "<reason>"
21
+ Display XP gain (used by agent)
22
+
23
+ Options:
24
+ -g, --global Install to user home directory
25
+ -h, --help Show this help message
26
+
27
+ Examples:
28
+ npx ocs-stats
29
+ npx ocs-stats update
30
+ npx ocs-stats stats
31
+ npx ocs-stats display-xp 35 "Fixed high issue"
32
+ `);
33
+ process.exit(0);
34
+ }
35
+
36
+ if (command === 'update') {
37
+ update({ isGlobal }).catch((err) => {
38
+ console.error('Error:', err.message);
39
+ process.exit(1);
40
+ });
41
+ process.exit(0);
42
+ }
43
+
44
+ if (command === 'stats') {
45
+ stats();
46
+ process.exit(0);
47
+ }
48
+
49
+ if (command === 'display-xp') {
50
+ const amount = args[1];
51
+ const reason = args[2];
52
+ displayXp(amount, reason);
53
+ process.exit(0);
54
+ }
55
+
56
+ init({ isGlobal }).catch((err) => {
57
+ console.error('Error:', err.message);
58
+ process.exit(1);
59
+ });
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "ocs-stats",
3
+ "version": "1.0.0",
4
+ "description": "OpenCode Skills - One-click installer with gamified XP stats",
5
+ "type": "module",
6
+ "bin": {
7
+ "ocs-stats": "./bin/cli.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "templates"
13
+ ],
14
+ "keywords": [
15
+ "opencode",
16
+ "ai",
17
+ "skills",
18
+ "agents",
19
+ "cli",
20
+ "stats"
21
+ ],
22
+ "author": "Zen0space",
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/Zen0space/opencode-skills.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/Zen0space/opencode-skills/issues"
30
+ },
31
+ "homepage": "https://github.com/Zen0space/opencode-skills#readme",
32
+ "engines": {
33
+ "node": ">=18"
34
+ }
35
+ }
package/src/display.js ADDED
@@ -0,0 +1,119 @@
1
+ const LEVEL_THRESHOLDS = [
2
+ { level: 1, title: 'Novice', xpRequired: 0 },
3
+ { level: 2, title: 'Apprentice', xpRequired: 150 },
4
+ { level: 3, title: 'Practitioner', xpRequired: 450 },
5
+ { level: 4, title: 'Expert', xpRequired: 900 },
6
+ { level: 5, title: 'Master', xpRequired: 1500 },
7
+ { level: 6, title: 'Grandmaster', xpRequired: 3000 }
8
+ ];
9
+
10
+ const BOX_WIDTH = 40;
11
+ const CONTENT_WIDTH = BOX_WIDTH - 2;
12
+
13
+ export function progressBar(current, max, width = 16) {
14
+ const safeCurrent = Math.max(0, current);
15
+ const safeMax = Math.max(1, max);
16
+ const filled = Math.min(width, Math.round((safeCurrent / safeMax) * width));
17
+ const empty = width - filled;
18
+ return '█'.repeat(filled) + '░'.repeat(empty);
19
+ }
20
+
21
+ export function getNextLevelXp(currentLevel) {
22
+ const nextLevel = LEVEL_THRESHOLDS.find(t => t.level === currentLevel + 1);
23
+ return nextLevel ? nextLevel.xpRequired : null;
24
+ }
25
+
26
+ function line(content) {
27
+ const padding = CONTENT_WIDTH - content.length;
28
+ return '║' + content + ' '.repeat(Math.max(0, padding)) + '║';
29
+ }
30
+
31
+ function topBorder() {
32
+ return '╔' + '═'.repeat(CONTENT_WIDTH) + '╗';
33
+ }
34
+
35
+ function bottomBorder() {
36
+ return '╚' + '═'.repeat(CONTENT_WIDTH) + '╝';
37
+ }
38
+
39
+ function divider() {
40
+ return '╠' + '═'.repeat(CONTENT_WIDTH) + '╣';
41
+ }
42
+
43
+ function emptyLine() {
44
+ return '║' + ' '.repeat(CONTENT_WIDTH) + '║';
45
+ }
46
+
47
+ export function showXpGain(amount, reason, data) {
48
+ const { xp, level, title } = data;
49
+ const nextLevelXp = getNextLevelXp(level);
50
+
51
+ const xpText = `+${amount} XP ${reason.substring(0, 24)}`;
52
+ const levelText = `Level ${level} - ${title}`;
53
+
54
+ console.log('');
55
+ console.log(topBorder());
56
+ console.log(line(' ' + xpText));
57
+ console.log(divider());
58
+ console.log(line(' ' + levelText));
59
+
60
+ if (!nextLevelXp) {
61
+ console.log(line(' [████████████████] MAX LEVEL!'));
62
+ } else {
63
+ const bar = progressBar(xp, nextLevelXp);
64
+ const xpStr = `${xp}/${nextLevelXp}`;
65
+ console.log(line(` [${bar}] ${xpStr}`));
66
+ }
67
+
68
+ console.log(bottomBorder());
69
+ console.log('');
70
+ }
71
+
72
+ export function showStats(data) {
73
+ const { xp, level, title, issuesFixed, totalAudits, patternsAdded, mistakes } = data;
74
+ const nextLevelXp = getNextLevelXp(level);
75
+
76
+ const totalFixed = (issuesFixed?.critical || 0) +
77
+ (issuesFixed?.high || 0) +
78
+ (issuesFixed?.medium || 0) +
79
+ (issuesFixed?.low || 0);
80
+
81
+ const totalPenalty = mistakes?.totalPenaltyXP || 0;
82
+
83
+ console.log('');
84
+ console.log(topBorder());
85
+ console.log(line(' SECURITY AGENT'));
86
+ console.log(divider());
87
+ console.log(line(` Level ${level} - ${title}`));
88
+
89
+ if (!nextLevelXp) {
90
+ console.log(line(' XP: [████████████████] MAX LEVEL!'));
91
+ } else {
92
+ const bar = progressBar(xp, nextLevelXp);
93
+ const xpStr = `${xp}/${nextLevelXp}`;
94
+ const percent = Math.round((xp / nextLevelXp) * 100);
95
+ console.log(line(` XP: [${bar}] ${xpStr}`));
96
+ console.log(line(` Progress: ${percent}%`));
97
+ }
98
+
99
+ console.log(emptyLine());
100
+ console.log(line(' Stats:'));
101
+ console.log(line(` * Issues Fixed: ${totalFixed}`));
102
+ console.log(line(` * Audits Done: ${totalAudits || 0}`));
103
+ console.log(line(` * Patterns Added: ${patternsAdded || 0}`));
104
+ console.log(line(` * XP Penalties: ${totalPenalty}`));
105
+ console.log(bottomBorder());
106
+ console.log('');
107
+ }
108
+
109
+ export function showLevelUp(newLevel, newTitle) {
110
+ console.log('');
111
+ console.log(topBorder());
112
+ console.log(emptyLine());
113
+ console.log(line(' LEVEL UP!'));
114
+ console.log(emptyLine());
115
+ console.log(line(` Level ${newLevel} - ${newTitle}`));
116
+ console.log(emptyLine());
117
+ console.log(bottomBorder());
118
+ console.log('');
119
+ }
package/src/init.js ADDED
@@ -0,0 +1,87 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+
8
+ const TEMPLATES_DIR = path.join(__dirname, '..', 'templates');
9
+
10
+ export async function init({ isGlobal = false } = {}) {
11
+ const targetDir = isGlobal
12
+ ? path.join(process.env.HOME || process.env.USERPROFILE, '.opencode')
13
+ : path.join(process.cwd(), '.opencode');
14
+
15
+ const targetParent = path.dirname(targetDir);
16
+
17
+ console.log(`\nInstalling OpenCode skills to: ${targetDir}\n`);
18
+
19
+ if (fs.existsSync(targetDir)) {
20
+ console.log('.opencode folder already exists.');
21
+ console.log(' To update: npx ocs-stats update\n');
22
+ process.exit(0);
23
+ }
24
+
25
+ if (!fs.existsSync(targetParent)) {
26
+ fs.mkdirSync(targetParent, { recursive: true });
27
+ }
28
+
29
+ copyDir(TEMPLATES_DIR, targetDir);
30
+
31
+ console.log('Installed successfully!\n');
32
+ console.log('What was installed:');
33
+ console.log(' * Agents: security');
34
+ console.log(' * Skills: commit, memories, mobile, security, webapp');
35
+ console.log(' * Security: XP tracking, knowledge base\n');
36
+
37
+ if (!isGlobal) {
38
+ console.log('Next steps:');
39
+ console.log(' 1. Edit .opencode/skills/memories/SKILL.md to match your project');
40
+ console.log(' 2. Run `opencode` in this directory to start using the skills\n');
41
+ console.log('Check progress: npx ocs-stats stats\n');
42
+ }
43
+ }
44
+
45
+ export async function update({ isGlobal = false } = {}) {
46
+ const targetDir = isGlobal
47
+ ? path.join(process.env.HOME || process.env.USERPROFILE, '.opencode')
48
+ : path.join(process.cwd(), '.opencode');
49
+
50
+ console.log(`\nUpdating OpenCode skills at: ${targetDir}\n`);
51
+
52
+ if (!fs.existsSync(targetDir)) {
53
+ console.log('.opencode folder not found. Run `npx ocs-stats` first.\n');
54
+ process.exit(1);
55
+ }
56
+
57
+ // Remove existing
58
+ fs.rmSync(targetDir, { recursive: true, force: true });
59
+ console.log(' Removed existing .opencode folder');
60
+
61
+ // Reinstall
62
+ copyDir(TEMPLATES_DIR, targetDir);
63
+ console.log(' Installed fresh copy\n');
64
+
65
+ console.log('Updated successfully!\n');
66
+ console.log('What was installed:');
67
+ console.log(' * Agents: security');
68
+ console.log(' * Skills: commit, memories, mobile, security, webapp');
69
+ console.log(' * Security: XP tracking, knowledge base\n');
70
+ }
71
+
72
+ function copyDir(src, dest) {
73
+ fs.mkdirSync(dest, { recursive: true });
74
+
75
+ const entries = fs.readdirSync(src, { withFileTypes: true });
76
+
77
+ for (const entry of entries) {
78
+ const srcPath = path.join(src, entry.name);
79
+ const destPath = path.join(dest, entry.name);
80
+
81
+ if (entry.isDirectory()) {
82
+ copyDir(srcPath, destPath);
83
+ } else {
84
+ fs.copyFileSync(srcPath, destPath);
85
+ }
86
+ }
87
+ }
package/src/stats.js ADDED
@@ -0,0 +1,48 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { showStats, showXpGain } from './display.js';
4
+
5
+ function findXpJson() {
6
+ const cwdPath = path.join(process.cwd(), '.opencode', 'security', 'xp.json');
7
+
8
+ if (fs.existsSync(cwdPath)) {
9
+ return cwdPath;
10
+ }
11
+
12
+ return null;
13
+ }
14
+
15
+ export function stats() {
16
+ const xpPath = findXpJson();
17
+
18
+ if (!xpPath) {
19
+ console.log('');
20
+ console.log(' No .opencode/security/xp.json found in this project.');
21
+ console.log('');
22
+ console.log(' Make sure you\'re in a project with opencode-skills installed.');
23
+ console.log(' Run: npx create-opencode-skills');
24
+ console.log('');
25
+ process.exit(1);
26
+ }
27
+
28
+ const data = JSON.parse(fs.readFileSync(xpPath, 'utf-8'));
29
+ showStats(data);
30
+ }
31
+
32
+ export function displayXp(amount, reason) {
33
+ const xpPath = findXpJson();
34
+
35
+ if (!xpPath) {
36
+ console.log('No xp.json found');
37
+ process.exit(1);
38
+ }
39
+
40
+ if (!amount || isNaN(amount)) {
41
+ console.log('Invalid XP amount. Usage: display-xp <amount> "<reason>"');
42
+ process.exit(1);
43
+ }
44
+
45
+ const data = JSON.parse(fs.readFileSync(xpPath, 'utf-8'));
46
+ const reasonText = reason || 'XP earned';
47
+ showXpGain(parseInt(amount, 10), reasonText, data);
48
+ }