opencode-add-dir 1.0.0 → 1.0.2

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
@@ -1,43 +1,68 @@
1
1
  # OpenCode Add-Dir Plugin
2
2
 
3
- A plugin for OpenCode that adds the `/add-dir` command to include external directories in your session context.
3
+ Add external directories to your OpenCode session context with automatic permission approval.
4
4
 
5
- ## Installation
5
+ ## Quick Start
6
+
7
+ 1. Install the plugin:
6
8
 
7
9
  ```bash
8
- cd ~/.config/opencode/plugins/add-dir
9
- bun install
10
+ cd ~/.config/opencode
11
+ npm install opencode-add-dir
10
12
  ```
11
13
 
12
- ## Features
13
-
14
- - Add external directories to session context with `/add-dir <path>`
15
- - Smart filtering of binary files and common build directories
16
- - Recursive directory scanning
17
- - Configurable limits (100KB per file, 500 files max)
18
- - Read and write access to added directories
14
+ 2. Add `"opencode-add-dir"` to your `~/.config/opencode/opencode.jsonc` plugins array:
19
15
 
20
- ## Configuration
16
+ ```jsonc
17
+ {
18
+ "plugin": [
19
+ "your-other-plugins",
20
+ "opencode-add-dir"
21
+ ]
22
+ }
23
+ ```
21
24
 
22
- The plugin automatically installs its command file to `~/.config/opencode/command/add-dir.md` during installation.
25
+ 3. Restart OpenCode
23
26
 
24
- Ensure your `~/.config/opencode/opencode.jsonc` includes:
27
+ 4. Use the command:
25
28
 
26
- ```jsonc
27
- "plugin": [
28
- "./plugins/add-dir"
29
- ]
29
+ ```bash
30
+ /add-dir /path/to/your/project
30
31
  ```
31
32
 
32
- ## Usage
33
+ ## Features
34
+
35
+ - **Zero Configuration**: Works immediately after installation
36
+ - **Auto Permission**: No permission prompts for directories you add
37
+ - **Smart Filtering**: Automatically skips node_modules, .git, binary files, etc.
38
+ - **Recursive Scanning**: Reads entire directory structures
39
+ - **File Limits**: 100KB per file, 500 files max (to prevent overwhelm)
40
+ - **Full Access**: Read and write to added directories
41
+
42
+ ## How It Works
43
+
44
+ 1. `/add-dir <path>` scans the directory and adds all files to context
45
+ 2. Directory path is automatically registered for future access
46
+ 3. Any operations on that directory skip permission prompts
47
+ 4. Works recursively - all subdirectories are auto-approved
48
+
49
+ ## Usage Examples
33
50
 
34
51
  ```bash
35
- /add-dir /path/to/your/project
52
+ # Add a project directory
53
+ /add-dir ~/projects/my-app
54
+
55
+ # Add any external directory
56
+ /add-dir /path/to/external/code
57
+
58
+ # Now you can read/write without permission prompts
59
+ read ~/projects/my-app/src/index.js
60
+ edit ~/projects/my-app/package.json
36
61
  ```
37
62
 
38
- ## Filtering Rules
63
+ ## What Gets Filtered
39
64
 
40
- ### Ignored Directories
65
+ ### Automatically Skipped Directories
41
66
  - `node_modules`
42
67
  - `.git`
43
68
  - `dist`, `build`
@@ -49,29 +74,68 @@ Ensure your `~/.config/opencode/opencode.jsonc` includes:
49
74
  - `.nuxt`, `.output`
50
75
  - `tmp`, `temp`, `.turbo`
51
76
 
52
- ### Binary Files
77
+ ### Binary Files (Not Read)
53
78
  Images, PDFs, Office docs, archives, media files, executables, compiled files, etc.
54
79
 
80
+ ## Installation Details
81
+
82
+ The plugin's postinstall script automatically:
83
+ 1. Finds your OpenCode config directory (`~/.config/opencode/`)
84
+ 2. Creates the `/add-dir` command file
85
+ 3. Installs it to `~/.config/opencode/command/add-dir.md`
86
+
87
+ ### Troubleshooting
88
+
89
+ If the `/add-dir` command doesn't work after installation:
90
+
91
+ 1. Verify the command file exists:
92
+ ```bash
93
+ ls -la ~/.config/opencode/command/add-dir.md
94
+ ```
95
+
96
+ 2. If missing, create it manually:
97
+ ```bash
98
+ mkdir -p ~/.config/opencode/command
99
+ cat > ~/.config/opencode/command/add-dir.md << 'EOF'
100
+ ---
101
+ description: Add an external directory to the session context
102
+ ---
103
+ Add the directory at path $ARGUMENTS to this session's context.
104
+ Use the add_dir tool to read all files from the specified directory.
105
+ EOF
106
+ ```
107
+
55
108
  ## Development
56
109
 
110
+ For contributors and maintainers:
111
+
57
112
  ```bash
58
- cd ~/.config/opencode/plugins/add-dir
113
+ # Clone the repository
114
+ git clone https://github.com/kuzeofficial/add-dir-opencode.git
115
+ cd opencode-add-dir
59
116
 
60
117
  # Install dependencies
61
118
  bun install
62
119
 
63
- # Build the plugin
120
+ # Build the TypeScript source
64
121
  bun run build
65
122
 
66
- # The build output goes to dist/
123
+ # Test locally
124
+ npm link
125
+ cd ~/.config/opencode
126
+ npm link opencode-add-dir
127
+
128
+ # Publish new version
129
+ npm version patch # or minor/major
130
+ npm publish
67
131
  ```
68
132
 
69
133
  ## Files
70
134
 
71
- - `src/index.ts` - Main plugin implementation
135
+ - `src/index.ts` - Main plugin with permission auto-approval
72
136
  - `command/add-dir.md` - Command definition (auto-installed)
73
137
  - `scripts/install.js` - Post-install script (auto-runs)
74
- - `package.json` - Package configuration
138
+ - `package.json` - NPM package configuration
75
139
 
76
140
  ## License
77
141
 
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "opencode-add-dir",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "OpenCode plugin to add external directories to session context",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "files": [
9
9
  "dist",
10
- "command"
10
+ "command",
11
+ "scripts"
11
12
  ],
12
13
  "scripts": {
13
14
  "build": "tsc",
@@ -0,0 +1,58 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import os from 'os';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ const COMMAND_SOURCE = path.join(__dirname, '..', 'command', 'add-dir.md');
10
+
11
+ function findOpencodeConfigDir(startDir = process.cwd()) {
12
+ const configFiles = ['opencode.jsonc', 'opencode.json'];
13
+ let currentDir = startDir;
14
+
15
+ while (currentDir !== path.parse(currentDir).root) {
16
+ for (const configFile of configFiles) {
17
+ const configPath = path.join(currentDir, configFile);
18
+ if (fs.existsSync(configPath)) {
19
+ return currentDir;
20
+ }
21
+ }
22
+ currentDir = path.dirname(currentDir);
23
+ }
24
+
25
+ const defaultConfigDir = path.join(os.homedir(), '.config', 'opencode');
26
+ if (fs.existsSync(defaultConfigDir)) {
27
+ return defaultConfigDir;
28
+ }
29
+
30
+ return null;
31
+ }
32
+
33
+ try {
34
+ const opencodeDir = findOpencodeConfigDir();
35
+
36
+ if (!opencodeDir) {
37
+ console.log('ℹ opencode-add-dir: Could not find opencode config directory, skipping command file installation');
38
+ process.exit(0);
39
+ }
40
+
41
+ const commandDir = path.join(opencodeDir, 'command');
42
+ const commandDest = path.join(commandDir, 'add-dir.md');
43
+
44
+ if (!fs.existsSync(commandDir)) {
45
+ fs.mkdirSync(commandDir, { recursive: true });
46
+ }
47
+
48
+ if (fs.existsSync(COMMAND_SOURCE)) {
49
+ fs.copyFileSync(COMMAND_SOURCE, commandDest);
50
+ console.log('✓ opencode-add-dir: Command file installed to', commandDest);
51
+ } else {
52
+ console.error('✗ opencode-add-dir: Command source file not found at', COMMAND_SOURCE);
53
+ process.exit(1);
54
+ }
55
+ } catch (error) {
56
+ console.error('✗ opencode-add-dir: Failed to install command file:', error.message);
57
+ process.exit(1);
58
+ }