22
33This file provides guidance for AI coding agents working in this repository.
44
5- ## Repository Overview
5+ ## Quick Reference
66
7- This repository contains the CLI tools for OpenCode plugin management.
7+ | Item | Value |
8+ | ------| -------|
9+ | ** Language** | JavaScript (ES Modules) |
10+ | ** Node Version** | >=18 |
11+ | ** Dependencies** | Zero (Node.js built-ins only) |
12+ | ** Entry Point** | ` bin/opencode-link.js ` |
13+ | ** Type System** | JSDoc annotations |
814
9- - ** Type** : CLI tool (ES Module, Node.js)
10- - ** Entry Point** : ` bin/opencode-link.js `
11- - ** No external dependencies** - uses Node.js built-ins only
15+ ## Build/Lint/Test Commands
16+
17+ This project has ** no build step** - it uses pure ES Modules JavaScript.
18+
19+ ``` bash
20+ # No build required - run directly
21+ node bin/opencode-link.js list
22+
23+ # Link globally for development testing
24+ npm link
25+
26+ # Test CLI in a fresh directory
27+ mkdir -p /tmp/test-cli && cd /tmp/test-cli
28+ npx opencode-link list
29+
30+ # Test with local plugins
31+ mkdir -p /tmp/test-cli/.opencode && cd /tmp/test-cli/.opencode
32+ npm install github:techdivision/opencode-plugins
33+ npx opencode-link list
34+
35+ # Verify ES module syntax
36+ node --check bin/opencode-link.js
37+ node --check lib/discovery.js
38+ node --check lib/linker.js
39+ node --check lib/schema.js
40+ ```
41+
42+ ** Note** : This project has no automated tests, linting, or formatting tools configured. Testing is done manually via the CLI commands above.
1243
1344## Project Structure
1445
1546```
1647opencode-cli/
17- ├── package.json # NPM package configuration
18- ├── README.md # Documentation
19- ├── AGENTS.md # This file
20- ├── .gitignore
48+ ├── package.json # NPM package config (type: module)
49+ ├── README.md # User documentation
50+ ├── AGENTS.md # AI agent guidance (this file)
2151├── bin/
22- │ └── opencode-link.js # CLI entry point
52+ │ └── opencode-link.js # CLI entry point (~714 lines)
2353└── lib/
2454 ├── index.js # Re-exports all modules
25- ├── discovery.js # Plugin discovery (global + local )
26- ├── linker.js # Symlink creation utilities
27- └── schema.js # JSON schema generation
55+ ├── discovery.js # Plugin discovery logic (~424 lines )
56+ ├── linker.js # Symlink utilities (~359 lines)
57+ └── schema.js # JSON schema generation (~88 lines)
2858```
2959
30- ## Files
31-
32- | File | Purpose |
33- | ------| ---------|
34- | ` bin/opencode-link.js ` | CLI entry point, argument parsing, command dispatch |
35- | ` lib/discovery.js ` | Discovers plugins from global npm prefix and local node_modules |
36- | ` lib/linker.js ` | Creates symlinks with "last wins" strategy |
37- | ` lib/schema.js ` | Generates combined JSON schema from plugin schemas |
38- | ` lib/index.js ` | Re-exports all modules for convenience |
60+ ## Code Style Guidelines
3961
40- ## Code Style
41-
42- - ** Module System** : ES Modules (` "type": "module" ` in package.json)
43- - ** Node.js APIs** : Use ` fs ` , ` path ` , ` os ` , ` child_process ` from Node.js built-ins
44- - ** No Dependencies** : Zero external dependencies
45- - ** Formatting** : 2-space indentation, single quotes, semicolons
46- - ** Functions** : Use JSDoc comments for public functions
62+ ### Module System (ES Modules)
4763
4864``` javascript
49- // Good - ES Module imports
65+ // CORRECT - ES Module imports (Node.js built-ins only)
5066import fs from ' fs' ;
5167import path from ' path' ;
68+ import os from ' os' ;
69+ import { execSync } from ' child_process' ;
5270import { fileURLToPath } from ' url' ;
5371
54- // Good - __dirname equivalent for ES Modules
72+ // CORRECT - __dirname equivalent for ES Modules
5573const __filename = fileURLToPath (import .meta.url);
5674const __dirname = path .dirname (__filename );
5775
58- // Good - JSDoc for functions
76+ // CORRECT - Named exports
77+ export function discoverPlugins (targetDir ) { ... }
78+ export const AGENTS_MD_MARKER = ' <!-- AUTO-GENERATED -->' ;
79+ ` ` `
80+
81+ ### Formatting Rules
82+
83+ - **Indentation**: 2 spaces (not tabs)
84+ - **Quotes**: Single quotes for strings
85+ - **Semicolons**: Always use semicolons
86+ - **Trailing commas**: Use in multi-line arrays/objects
87+ - **Line length**: No strict limit, but keep readable
88+
89+ ### Naming Conventions
90+
91+ ` ` ` javascript
92+ // Functions and variables: camelCase
93+ function discoverPlugins (targetDir ) { ... }
94+ const allPlugins = new Map ();
95+
96+ // Constants: UPPER_SNAKE_CASE
97+ const AGENTS_MD_MARKER = ' <!-- AUTO-GENERATED -->' ;
98+ const CONTENT_TYPE_MAPPING = { ... };
99+
100+ // Private functions: camelCase (no underscore prefix)
101+ function getGlobalDir () { ... } // Not exported = private
102+ ` ` `
103+
104+ ### JSDoc Documentation
105+
106+ All exported functions MUST have JSDoc comments:
107+
108+ ` ` ` javascript
59109/**
60110 * Discovers all available plugins from all locations.
111+ *
112+ * Priority (last wins):
113+ * 1. Global: npm global prefix (npm install -g)
114+ * 2. Local: {targetDir}/node_modules/
115+ *
61116 * @param {string} targetDir - The .opencode directory
62117 * @returns {Map<string, PluginDescriptor>} Map of plugin name to descriptor
63118 */
64119export function discoverPlugins (targetDir ) { ... }
65120` ` `
66121
122+ Use ` @typedef` for complex types at the end of files.
123+
124+ ### Error Handling
125+
126+ ` ` ` javascript
127+ // Silent catch for non-critical operations
128+ try {
129+ const prefix = execSync (' npm config get prefix' , { encoding: ' utf-8' }).trim ();
130+ return path .join (prefix, ' lib' , ' node_modules' );
131+ } catch {
132+ return null ; // Empty catch - failure is acceptable
133+ }
134+
135+ // Check existence before operations
136+ if (! fs .existsSync (nodeModulesDir)) {
137+ return plugins; // Early return, no error thrown
138+ }
139+ ` ` `
140+
141+ ### Console Output
142+
143+ Use ANSI color codes for terminal output:
144+
145+ ` ` ` javascript
146+ const colors = {
147+ reset: ' \x1b [0m' ,
148+ green: ' \x1b [32m' ,
149+ yellow: ' \x1b [33m' ,
150+ red: ' \x1b [31m' ,
151+ cyan: ' \x1b [36m' ,
152+ gray: ' \x1b [90m' ,
153+ };
154+
155+ console .log (` ${ colors .green } + ${ message}${ colors .reset } ` );
156+ ` ` `
157+
67158## Key Concepts
68159
69160### Plugin Discovery (lib/discovery.js)
@@ -85,32 +176,14 @@ Priority: **last wins** (local overrides global)
85176- **Real files preserved**: Real files/directories are NOT overwritten
86177- **Same-source skipped**: Symlinks pointing to same source are skipped
87178
88- ## Testing
89-
90- ` ` ` bash
91- # Link globally for testing
92- npm link
93-
94- # Test in a new project
95- mkdir - p / tmp/ test- cli && cd / tmp/ test- cli
96- npx opencode- link list
97-
98- # Test with opencode- plugins
99- mkdir - p / tmp/ test- cli/ .opencode && cd / tmp/ test- cli/ .opencode
100- npm install github: techdivision/ opencode- plugins
101- npx opencode- link list
102- ` ` `
103-
104179## Git Workflow
105180
106- This repository follows a simple workflow:
107-
108- 1. Work on ` main` branch for now (small repo)
181+ 1. Work on ` main` branch (small repo)
1091822. Use conventional commits: ` feat: ` , ` fix: ` , ` docs: ` , ` refactor: `
1101833. Tag releases: ` v0.1 .0 ` , ` v0.2 .0 ` , etc.
111184
112185## Related Repositories
113186
114- - **opencode-plugins**: Main plugin repository (depends on this CLI)
187+ - **opencode-plugins**: Main plugin repository
115188- **opencode-plugin-time-tracking**: Example singlerepo plugin
116189- **opencode-plugin-shell-env**: Example singlerepo plugin
0 commit comments