opencode-code-simplifier 1.0.0 → 1.1.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/README.md CHANGED
@@ -2,18 +2,18 @@
2
2
 
3
3
  Code simplifier plugin for [OpenCode](https://opencode.ai). Simplifies and refines code for clarity while preserving functionality.
4
4
 
5
- ## Features
5
+ ## Install
6
6
 
7
- - Reduces nesting and complexity
8
- - Removes debug artifacts (unconditional console.log, debugger, commented code)
9
- - Removes obvious comments that describe what code does
10
- - Preserves conditional logging (logs behind `if (debug)`, `if (isDev)`, etc.)
11
- - Converts nested ternaries to if/else chains
12
- - Applies language-specific best practices
7
+ ```bash
8
+ npm install opencode-code-simplifier --save-dev
9
+ ```
13
10
 
14
- ## Install
11
+ This will automatically:
12
+ 1. Copy `skills/code-simplifier/SKILL.md` to `.opencode/skills/`
13
+ 2. Copy `rules/code-simplifier.md` to `.opencode/rules/`
14
+ 3. Copy `commands/simplify.md` to `.opencode/commands/`
15
15
 
16
- Add to your `opencode.json`:
16
+ Then add to your `opencode.json`:
17
17
 
18
18
  ```json
19
19
  {
@@ -21,27 +21,30 @@ Add to your `opencode.json`:
21
21
  }
22
22
  ```
23
23
 
24
- Or place the plugin file in:
25
- - `.opencode/plugins/` (project-level)
26
- - `~/.config/opencode/plugins/` (global)
27
-
28
- ## Usage
24
+ Restart OpenCode to activate.
29
25
 
30
- ### Automatic
26
+ ## Features
31
27
 
32
- The plugin logs when code is modified. Run simplification manually or ask OpenCode to simplify.
28
+ - Reduces nesting and complexity
29
+ - Removes debug artifacts (unconditional console.log, debugger, commented code)
30
+ - Removes obvious comments
31
+ - Preserves conditional logging (if debug, if isDev, etc.)
32
+ - Converts nested ternaries to if/else chains
33
+ - Applies language-specific best practices
33
34
 
34
- ### Manual
35
+ ## Usage
35
36
 
36
- Use the `simplify-code` tool:
37
+ ### Command
37
38
 
38
39
  ```
39
- /simplify-code file=path/to/file.js
40
+ /simplify
40
41
  ```
41
42
 
42
- ### Via Command
43
+ ### Manual Tool
43
44
 
44
- The plugin works with the `/simplify` command if you have a corresponding command file.
45
+ ```
46
+ simplify-code file=path/to/file.js
47
+ ```
45
48
 
46
49
  ## What Gets Removed
47
50
 
@@ -0,0 +1,19 @@
1
+ ---
2
+ description: Simplify code for clarity while preserving functionality
3
+ agent: code
4
+ ---
5
+
6
+ Use code-simplifier skill to simplify recently modified code.
7
+
8
+ Focus on:
9
+ 1. Reducing complexity and nesting
10
+ 2. Eliminating nested ternaries
11
+ 3. Improving readability with clear names
12
+ 4. Extracting reusable functions
13
+ 5. Removing debug artifacts (unconditional console.log, debugger, commented code)
14
+ 6. Removing obvious comments
15
+ 7. Preserving all functionality
16
+
17
+ If no file specified, focus on recently modified code.
18
+
19
+ User request: $ARGUMENTS
package/install.js ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Postinstall script for opencode-code-simplifier
5
+ * Copies skills, rules, and commands to .opencode directory
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const os = require('os');
11
+
12
+ // Source directory (inside node_modules)
13
+ const sourceDir = __dirname;
14
+
15
+ // Target directories
16
+ const projectDir = path.join(process.cwd(), '.opencode');
17
+ const globalDir = path.join(os.homedir(), '.config', 'opencode');
18
+
19
+ function copyDir(src, dest) {
20
+ if (!fs.existsSync(dest)) {
21
+ fs.mkdirSync(dest, { recursive: true });
22
+ }
23
+
24
+ const entries = fs.readdirSync(src, { withFileTypes: true });
25
+
26
+ for (const entry of entries) {
27
+ const srcPath = path.join(src, entry.name);
28
+ const destPath = path.join(dest, entry.name);
29
+
30
+ if (entry.isDirectory()) {
31
+ copyDir(srcPath, destPath);
32
+ } else {
33
+ if (!fs.existsSync(destPath)) {
34
+ fs.copyFileSync(srcPath, destPath);
35
+ console.log(` ✓ ${path.relative(process.cwd(), destPath)}`);
36
+ } else {
37
+ console.log(` ⊘ ${path.relative(process.cwd(), destPath)} (exists, skipped)`);
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ function install(targetDir) {
44
+ const dirs = ['skills', 'rules', 'commands'];
45
+
46
+ console.log(`\n📦 Installing opencode-code-simplifier to ${targetDir}\n`);
47
+
48
+ for (const dir of dirs) {
49
+ const src = path.join(sourceDir, dir);
50
+ const dest = path.join(targetDir, dir);
51
+
52
+ if (fs.existsSync(src)) {
53
+ console.log(`${dir}/`);
54
+ copyDir(src, dest);
55
+ }
56
+ }
57
+
58
+ console.log('\n✅ Done! Restart OpenCode to use the plugin.\n');
59
+ }
60
+
61
+ // Install to project .opencode directory
62
+ if (fs.existsSync(projectDir)) {
63
+ install(projectDir);
64
+ } else {
65
+ console.log('\n⚠️ No .opencode directory found in current project.');
66
+ console.log(' Run this in your project root, or install globally.\n');
67
+ }
package/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "opencode-code-simplifier",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Code simplifier plugin for OpenCode - simplifies and refines code for clarity while preserving functionality",
5
5
  "main": "dist/plugin.js",
6
6
  "types": "dist/plugin.d.ts",
7
7
  "files": [
8
8
  "dist",
9
+ "skills",
10
+ "rules",
11
+ "commands",
12
+ "install.js",
9
13
  "README.md"
10
14
  ],
11
15
  "scripts": {
12
16
  "build": "bun build plugin.ts --outfile=dist/plugin.js --target=node",
17
+ "postinstall": "node install.js",
13
18
  "prepublishOnly": "bun run build"
14
19
  },
15
20
  "keywords": [
@@ -0,0 +1,46 @@
1
+ # Code Simplifier Rules
2
+
3
+ Simplify code for clarity while preserving exact functionality.
4
+
5
+ ## Core Rules
6
+
7
+ 1. **Preserve Functionality** - Never change what code does, only how.
8
+
9
+ 2. **Enhance Clarity**:
10
+ - Reduce nesting and complexity
11
+ - Eliminate redundant code
12
+ - Improve variable/function names
13
+ - Consolidate related logic
14
+ - Remove obvious comments
15
+ - Use if/else or switch over nested ternaries
16
+ - Clarity over brevity
17
+
18
+ 3. **Remove Debug Artifacts**:
19
+ - DELETE: Unconditional console.log/debug, debugger, commented-out code, bare print() in Python
20
+ - KEEP: Logs behind guards (`if (debug)`, `if (process.env.DEBUG)`), logger calls with levels, console.error/warn
21
+
22
+ 4. **Maintain Balance** - Don't over-simplify into clever one-liners.
23
+
24
+ ## Language Guidelines
25
+
26
+ **JavaScript/TypeScript:**
27
+ - ES modules with proper imports
28
+ - `function` keyword over arrow functions
29
+ - Explicit return types for top-level functions
30
+ - Avoid try/catch when possible
31
+
32
+ **Python:**
33
+ - Follow PEP 8
34
+ - Use type hints
35
+ - List comprehensions when clearer
36
+ - Context managers for resources
37
+
38
+ ## When to Apply
39
+
40
+ - After writing/modifying code
41
+ - During code review
42
+ - When explicitly asked
43
+
44
+ Skip when:
45
+ - User wants exact structure preserved
46
+ - Code is already clean
@@ -0,0 +1,56 @@
1
+ ---
2
+ name: code-simplifier
3
+ description: Simplifies and refines code for clarity, consistency, and maintainability while preserving all functionality.
4
+ ---
5
+
6
+ You are a code simplification specialist. Refine recently modified code for clarity while preserving exact functionality. Prioritize readable, explicit code over overly compact solutions.
7
+
8
+ ## Core Rules
9
+
10
+ 1. **Preserve Functionality** - Never change what code does, only how it does it.
11
+
12
+ 2. **Apply Project Standards** (from AGENTS.md):
13
+ - ES modules with proper imports
14
+ - `function` keyword over arrow functions
15
+ - Explicit return types for top-level functions
16
+ - Proper React patterns with explicit Props types
17
+ - Avoid try/catch when possible
18
+ - Consistent naming conventions
19
+
20
+ 3. **Enhance Clarity**:
21
+ - Reduce nesting and complexity
22
+ - Eliminate redundant code
23
+ - Improve variable/function names
24
+ - Consolidate related logic
25
+ - Remove obvious comments
26
+ - Use if/else or switch over nested ternaries
27
+ - Clarity over brevity
28
+
29
+ 4. **Remove Debug Artifacts**:
30
+
31
+ DELETE:
32
+ - Unconditional console.log/console.debug
33
+ - debugger statements
34
+ - Commented-out code
35
+ - Obsolete TODO/FIXME
36
+ - Bare print() in Python
37
+ - Unused debug variables
38
+
39
+ KEEP:
40
+ - Logs behind guards: `if (debug)`, `if (isDev)`, `if (process.env.DEBUG)`
41
+ - Logger calls with levels: `logger.debug()`
42
+ - Python logging module with level checks
43
+ - console.error for error handling
44
+ - console.warn for legitimate warnings
45
+
46
+ 5. **Maintain Balance** - Don't over-simplify. Avoid clever one-liners that reduce readability.
47
+
48
+ 6. **Focus Scope** - Only refine recently modified code unless instructed otherwise.
49
+
50
+ ## Process
51
+
52
+ 1. Identify recently modified sections
53
+ 2. Apply standards and simplify structure
54
+ 3. Remove debug artifacts and obvious comments
55
+ 4. Verify functionality unchanged
56
+ 5. Confirm readability improved