opencode-code-simplifier 1.2.0 → 1.4.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 CHANGED
@@ -12334,40 +12334,129 @@ function tool(input) {
12334
12334
  }
12335
12335
  tool.schema = exports_external;
12336
12336
  // plugin.ts
12337
- var CodeSimplifier = async ({ client }) => {
12338
- await client.app.log({
12339
- body: {
12340
- service: "code-simplifier",
12341
- level: "info",
12342
- message: "Code Simplifier loaded. Use /simplify or the simplify-code tool."
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
+ function ensureFilesExist() {
12443
+ const configDir = join(homedir(), ".config", "opencode");
12444
+ const files = [
12445
+ { path: "skills/code-simplifier/SKILL.md", content: SKILL_CONTENT },
12446
+ { path: "rules/code-simplifier.md", content: RULES_CONTENT }
12447
+ ];
12448
+ for (const file2 of files) {
12449
+ const fullPath = join(configDir, file2.path);
12450
+ const dir = fullPath.substring(0, fullPath.lastIndexOf("/"));
12451
+ if (!existsSync(fullPath)) {
12452
+ mkdirSync(dir, { recursive: true });
12453
+ writeFileSync(fullPath, file2.content, "utf-8");
12343
12454
  }
12344
- });
12455
+ }
12456
+ }
12457
+ var CodeSimplifier = async ({ client }) => {
12458
+ ensureFilesExist();
12345
12459
  return {
12346
- event: async ({ event }) => {
12347
- if (event.type === "session.created") {
12348
- await client.app.log({
12349
- body: {
12350
- service: "code-simplifier",
12351
- level: "info",
12352
- message: "Code Simplifier active for this session."
12353
- }
12354
- });
12355
- }
12356
- },
12357
- "tool.execute.after": async (input, output) => {
12358
- if (input.tool === "write" || input.tool === "edit") {
12359
- const filePath = input?.args?.filePath || input?.args?.file_path;
12360
- if (filePath) {
12361
- await client.app.log({
12362
- body: {
12363
- service: "code-simplifier",
12364
- level: "debug",
12365
- message: `Code modified: ${filePath}`
12366
- }
12367
- });
12368
- }
12369
- }
12370
- },
12371
12460
  tool: {
12372
12461
  "simplify-code": tool({
12373
12462
  description: "Simplify code for clarity while preserving functionality",
package/package.json CHANGED
@@ -1,20 +1,15 @@
1
1
  {
2
2
  "name": "opencode-code-simplifier",
3
- "version": "1.2.0",
3
+ "version": "1.4.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": [
@@ -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,78 +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 globalDir = path.join(os.homedir(), '.config', 'opencode');
17
- const projectDir = path.join(process.cwd(), '.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(` ✓ ${destPath}`);
36
- } else {
37
- console.log(` ⊘ ${destPath} (exists, skipped)`);
38
- }
39
- }
40
- }
41
- }
42
-
43
- function install(targetDir, label) {
44
- const dirs = ['skills', 'rules', 'commands'];
45
-
46
- console.log(`\n📦 Installing opencode-code-simplifier to ${label}: ${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
- // Check if this is a global install
62
- const isGlobal = process.env.npm_config_global === 'true' ||
63
- process.env.npm_config_global === true ||
64
- __dirname.includes('global') ||
65
- __dirname.includes('.cache/opencode');
66
-
67
- if (isGlobal) {
68
- // Global install - copy to ~/.config/opencode/
69
- install(globalDir, 'global');
70
- } else if (fs.existsSync(projectDir)) {
71
- // Project install - copy to .opencode/
72
- install(projectDir, 'project');
73
- } else {
74
- console.log('\n⚠️ No .opencode directory found.');
75
- console.log(' Creating project .opencode directory...\n');
76
- fs.mkdirSync(projectDir, { recursive: true });
77
- install(projectDir, 'project');
78
- }
@@ -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