opencode-code-simplifier 1.1.0 → 1.3.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/dist/plugin.js +141 -0
- package/package.json +1 -6
- package/commands/simplify.md +0 -19
- package/install.js +0 -67
- package/rules/code-simplifier.md +0 -46
- package/skills/code-simplifier/SKILL.md +0 -56
package/dist/plugin.js
CHANGED
|
@@ -12334,7 +12334,148 @@ function tool(input) {
|
|
|
12334
12334
|
}
|
|
12335
12335
|
tool.schema = exports_external;
|
|
12336
12336
|
// plugin.ts
|
|
12337
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
12338
|
+
import { join } from "path";
|
|
12339
|
+
import { homedir } from "os";
|
|
12340
|
+
var SKILL_CONTENT = `---
|
|
12341
|
+
name: code-simplifier
|
|
12342
|
+
description: Simplifies and refines code for clarity, consistency, and maintainability while preserving all functionality.
|
|
12343
|
+
---
|
|
12344
|
+
|
|
12345
|
+
You are a code simplification specialist. Refine recently modified code for clarity while preserving exact functionality. Prioritize readable, explicit code over overly compact solutions.
|
|
12346
|
+
|
|
12347
|
+
## Core Rules
|
|
12348
|
+
|
|
12349
|
+
1. **Preserve Functionality** - Never change what code does, only how it does it.
|
|
12350
|
+
|
|
12351
|
+
2. **Apply Project Standards** (from AGENTS.md):
|
|
12352
|
+
- ES modules with proper imports
|
|
12353
|
+
- \`function\` keyword over arrow functions
|
|
12354
|
+
- Explicit return types for top-level functions
|
|
12355
|
+
- Proper React patterns with explicit Props types
|
|
12356
|
+
- Avoid try/catch when possible
|
|
12357
|
+
- Consistent naming conventions
|
|
12358
|
+
|
|
12359
|
+
3. **Enhance Clarity**:
|
|
12360
|
+
- Reduce nesting and complexity
|
|
12361
|
+
- Eliminate redundant code
|
|
12362
|
+
- Improve variable/function names
|
|
12363
|
+
- Consolidate related logic
|
|
12364
|
+
- Remove obvious comments
|
|
12365
|
+
- Use if/else or switch over nested ternaries
|
|
12366
|
+
- Clarity over brevity
|
|
12367
|
+
|
|
12368
|
+
4. **Remove Debug Artifacts**:
|
|
12369
|
+
|
|
12370
|
+
DELETE:
|
|
12371
|
+
- Unconditional console.log/console.debug
|
|
12372
|
+
- debugger statements
|
|
12373
|
+
- Commented-out code
|
|
12374
|
+
- Obsolete TODO/FIXME
|
|
12375
|
+
- Bare print() in Python
|
|
12376
|
+
- Unused debug variables
|
|
12377
|
+
|
|
12378
|
+
KEEP:
|
|
12379
|
+
- Logs behind guards: \`if (debug)\`, \`if (isDev)\`, \`if (process.env.DEBUG)\`
|
|
12380
|
+
- Logger calls with levels: \`logger.debug()\`
|
|
12381
|
+
- Python logging module with level checks
|
|
12382
|
+
- console.error for error handling
|
|
12383
|
+
- console.warn for legitimate warnings
|
|
12384
|
+
|
|
12385
|
+
5. **Maintain Balance** - Don't over-simplify. Avoid clever one-liners that reduce readability.
|
|
12386
|
+
|
|
12387
|
+
6. **Focus Scope** - Only refine recently modified code unless instructed otherwise.
|
|
12388
|
+
|
|
12389
|
+
## Process
|
|
12390
|
+
|
|
12391
|
+
1. Identify recently modified sections
|
|
12392
|
+
2. Apply standards and simplify structure
|
|
12393
|
+
3. Remove debug artifacts and obvious comments
|
|
12394
|
+
4. Verify functionality unchanged
|
|
12395
|
+
5. Confirm readability improved`;
|
|
12396
|
+
var RULES_CONTENT = `# Code Simplifier Rules
|
|
12397
|
+
|
|
12398
|
+
Simplify code for clarity while preserving exact functionality.
|
|
12399
|
+
|
|
12400
|
+
## Core Rules
|
|
12401
|
+
|
|
12402
|
+
1. **Preserve Functionality** - Never change what code does, only how.
|
|
12403
|
+
|
|
12404
|
+
2. **Enhance Clarity**:
|
|
12405
|
+
- Reduce nesting and complexity
|
|
12406
|
+
- Eliminate redundant code
|
|
12407
|
+
- Improve variable/function names
|
|
12408
|
+
- Consolidate related logic
|
|
12409
|
+
- Remove obvious comments
|
|
12410
|
+
- Use if/else or switch over nested ternaries
|
|
12411
|
+
- Clarity over brevity
|
|
12412
|
+
|
|
12413
|
+
3. **Remove Debug Artifacts**:
|
|
12414
|
+
- DELETE: Unconditional console.log/debug, debugger, commented-out code, bare print() in Python
|
|
12415
|
+
- KEEP: Logs behind guards (\`if (debug)\`, \`if (process.env.DEBUG)\`), logger calls with levels, console.error/warn
|
|
12416
|
+
|
|
12417
|
+
4. **Maintain Balance** - Don't over-simplify into clever one-liners.
|
|
12418
|
+
|
|
12419
|
+
## Language Guidelines
|
|
12420
|
+
|
|
12421
|
+
**JavaScript/TypeScript:**
|
|
12422
|
+
- ES modules with proper imports
|
|
12423
|
+
- \`function\` keyword over arrow functions
|
|
12424
|
+
- Explicit return types for top-level functions
|
|
12425
|
+
- Avoid try/catch when possible
|
|
12426
|
+
|
|
12427
|
+
**Python:**
|
|
12428
|
+
- Follow PEP 8
|
|
12429
|
+
- Use type hints
|
|
12430
|
+
- List comprehensions when clearer
|
|
12431
|
+
- Context managers for resources
|
|
12432
|
+
|
|
12433
|
+
## When to Apply
|
|
12434
|
+
|
|
12435
|
+
- After writing/modifying code
|
|
12436
|
+
- During code review
|
|
12437
|
+
- When explicitly asked
|
|
12438
|
+
|
|
12439
|
+
Skip when:
|
|
12440
|
+
- User wants exact structure preserved
|
|
12441
|
+
- Code is already clean`;
|
|
12442
|
+
var COMMAND_CONTENT = `---
|
|
12443
|
+
description: Simplify code for clarity while preserving functionality
|
|
12444
|
+
agent: code
|
|
12445
|
+
---
|
|
12446
|
+
|
|
12447
|
+
Use code-simplifier skill to simplify recently modified code.
|
|
12448
|
+
|
|
12449
|
+
Focus on:
|
|
12450
|
+
1. Reducing complexity and nesting
|
|
12451
|
+
2. Eliminating nested ternaries
|
|
12452
|
+
3. Improving readability with clear names
|
|
12453
|
+
4. Extracting reusable functions
|
|
12454
|
+
5. Removing debug artifacts (unconditional console.log, debugger, commented code)
|
|
12455
|
+
6. Removing obvious comments
|
|
12456
|
+
7. Preserving all functionality
|
|
12457
|
+
|
|
12458
|
+
If no file specified, focus on recently modified code.
|
|
12459
|
+
|
|
12460
|
+
User request: $ARGUMENTS`;
|
|
12461
|
+
function ensureFilesExist() {
|
|
12462
|
+
const configDir = join(homedir(), ".config", "opencode");
|
|
12463
|
+
const files = [
|
|
12464
|
+
{ path: "skills/code-simplifier/SKILL.md", content: SKILL_CONTENT },
|
|
12465
|
+
{ path: "rules/code-simplifier.md", content: RULES_CONTENT },
|
|
12466
|
+
{ path: "commands/simplify.md", content: COMMAND_CONTENT }
|
|
12467
|
+
];
|
|
12468
|
+
for (const file2 of files) {
|
|
12469
|
+
const fullPath = join(configDir, file2.path);
|
|
12470
|
+
const dir = fullPath.substring(0, fullPath.lastIndexOf("/"));
|
|
12471
|
+
if (!existsSync(fullPath)) {
|
|
12472
|
+
mkdirSync(dir, { recursive: true });
|
|
12473
|
+
writeFileSync(fullPath, file2.content, "utf-8");
|
|
12474
|
+
}
|
|
12475
|
+
}
|
|
12476
|
+
}
|
|
12337
12477
|
var CodeSimplifier = async ({ client }) => {
|
|
12478
|
+
ensureFilesExist();
|
|
12338
12479
|
await client.app.log({
|
|
12339
12480
|
body: {
|
|
12340
12481
|
service: "code-simplifier",
|
package/package.json
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-code-simplifier",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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",
|
|
13
9
|
"README.md"
|
|
14
10
|
],
|
|
15
11
|
"scripts": {
|
|
16
12
|
"build": "bun build plugin.ts --outfile=dist/plugin.js --target=node",
|
|
17
|
-
"postinstall": "node install.js",
|
|
18
13
|
"prepublishOnly": "bun run build"
|
|
19
14
|
},
|
|
20
15
|
"keywords": [
|
package/commands/simplify.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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/rules/code-simplifier.md
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|