@grympler/opencode-tmux-handover 1.0.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.
@@ -0,0 +1,529 @@
1
+ # Implementation Guide: Adding Configuration to tt-plugin
2
+
3
+ This guide walks through the step-by-step process of implementing user-configurable command availability in the tt-plugin.
4
+
5
+ ---
6
+
7
+ ## Quick Start: Add Plugin Configuration
8
+
9
+ ### Step 1: Create Configuration Module
10
+
11
+ Create `src/config.ts`:
12
+
13
+ ```typescript
14
+ import { readFileSync } from "fs"
15
+ import { homedir } from "os"
16
+ import { join } from "path"
17
+
18
+ export interface PluginConfig {
19
+ enabledCommands: string[]
20
+ defaultTerminal?: string
21
+ sessionPrefix?: string
22
+ }
23
+
24
+ const DEFAULT_CONFIG: PluginConfig = {
25
+ enabledCommands: ["tmux", "tmux-oc", "tmux-claude", "tmux-copilot"],
26
+ defaultTerminal: "auto",
27
+ sessionPrefix: "oc"
28
+ }
29
+
30
+ export function loadConfig(): PluginConfig {
31
+ const configPath = join(homedir(), ".config", "opencode", "tt-plugin-config.json")
32
+
33
+ try {
34
+ const fileContent = readFileSync(configPath, "utf-8")
35
+ const userConfig = JSON.parse(fileContent)
36
+
37
+ return {
38
+ ...DEFAULT_CONFIG,
39
+ ...userConfig
40
+ }
41
+ } catch {
42
+ // Config file doesn't exist or is invalid - use defaults
43
+ return DEFAULT_CONFIG
44
+ }
45
+ }
46
+
47
+ export function getConfigPath(): string {
48
+ return join(homedir(), ".config", "opencode", "tt-plugin-config.json")
49
+ }
50
+ ```
51
+
52
+ ### Step 2: Update Plugin to Use Configuration
53
+
54
+ Update `src/index.ts`:
55
+
56
+ ```typescript
57
+ import type { Plugin } from "@opencode-ai/plugin"
58
+ import { join } from "path"
59
+ import { loadConfig } from "./config"
60
+
61
+ export const TmuxLauncher: Plugin = async ({ $, directory }) => {
62
+ const config = loadConfig()
63
+
64
+ return {
65
+ "command.execute.before": async (input, output) => {
66
+ const commandName = input.command || ""
67
+
68
+ // Check if command is in enabled list
69
+ if (!config.enabledCommands.includes(commandName)) {
70
+ return
71
+ }
72
+
73
+ if (!commandName.startsWith("tmux")) return
74
+
75
+ const scriptMap: Record<string, string> = {
76
+ "tmux": "opencode-tmux.sh",
77
+ "tmux-oc": "opencode-tmux-oc.sh",
78
+ "tmux-claude": "opencode-tmux-claude.sh",
79
+ "tmux-copilot": "opencode-tmux-copilot.sh"
80
+ }
81
+
82
+ const scriptName = scriptMap[commandName]
83
+ if (!scriptName) return
84
+
85
+ const scriptPath = join(import.meta.dirname, "..", "scripts", scriptName)
86
+
87
+ try {
88
+ await $`bash ${scriptPath}`.cwd(directory)
89
+ output.parts = []
90
+ } catch (err) {
91
+ console.error("tt-plugin:", err)
92
+ }
93
+ }
94
+ }
95
+ }
96
+ ```
97
+
98
+ ### Step 3: Create Configuration Script
99
+
100
+ Create `src/scripts/opencode-tt-config.sh`:
101
+
102
+ ```bash
103
+ #!/usr/bin/env bash
104
+ set -euo pipefail
105
+
106
+ CONFIG_DIR="$HOME/.config/opencode"
107
+ CONFIG_FILE="$CONFIG_DIR/tt-plugin-config.json"
108
+
109
+ # Ensure config directory exists
110
+ mkdir -p "$CONFIG_DIR"
111
+
112
+ # Show current configuration
113
+ if [ -f "$CONFIG_FILE" ]; then
114
+ echo "Current tt-plugin configuration:"
115
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
116
+ cat "$CONFIG_FILE" | head -20
117
+ echo ""
118
+ echo "Location: $CONFIG_FILE"
119
+ echo ""
120
+ else
121
+ echo "No tt-plugin configuration found."
122
+ echo "Creating default configuration at: $CONFIG_FILE"
123
+ echo ""
124
+ fi
125
+
126
+ # Create or show default configuration
127
+ cat > "$CONFIG_FILE" << 'EOF'
128
+ {
129
+ "enabledCommands": ["tmux", "tmux-oc", "tmux-claude", "tmux-copilot"],
130
+ "defaultTerminal": "auto",
131
+ "sessionPrefix": "oc"
132
+ }
133
+ EOF
134
+
135
+ echo "Configuration saved!"
136
+ echo ""
137
+ echo "Available options:"
138
+ echo " enabledCommands: Array of command names to enable"
139
+ echo " Options: tmux, tmux-oc, tmux-claude, tmux-copilot"
140
+ echo ""
141
+ echo " defaultTerminal: Preferred terminal emulator"
142
+ echo " Options: auto, gnome-terminal, terminator, konsole, alacritty, kitty, xterm"
143
+ echo ""
144
+ echo " sessionPrefix: Prefix for tmux session names"
145
+ echo " Default: oc"
146
+ echo ""
147
+ echo "Edit with: ${EDITOR:-nano} $CONFIG_FILE"
148
+ ```
149
+
150
+ ### Step 4: Add Configuration Command
151
+
152
+ Create `src/commands/tt-configure.md`:
153
+
154
+ ```markdown
155
+ ---
156
+ description: Configure tt-plugin settings
157
+ ---
158
+
159
+ Open and configure the tt-plugin settings, including which tmux commands to enable and terminal preferences.
160
+ ```
161
+
162
+ ### Step 5: Update Installation Script
163
+
164
+ Update `install.sh` to include the config script:
165
+
166
+ ```bash
167
+ #!/usr/bin/env bash
168
+ set -euo pipefail
169
+
170
+ # ... existing code ...
171
+
172
+ # Add to symlink creation loop
173
+ CONFIG_SCRIPT_SRC="${PLUGIN_DIR}/src/scripts/opencode-tt-config.sh"
174
+ CONFIG_SCRIPT_DST="$COMMANDS_DIR/tt-configure"
175
+
176
+ # Create symlink for configuration script
177
+ mkdir -p "$COMMANDS_DIR"
178
+ ln -sf "$CONFIG_SCRIPT_SRC" "$CONFIG_SCRIPT_DST" || true
179
+
180
+ # Make executable
181
+ chmod +x "$CONFIG_SCRIPT_SRC"
182
+
183
+ echo "✓ Configuration command installed: tt-configure"
184
+ ```
185
+
186
+ ---
187
+
188
+ ## Usage Guide for Users
189
+
190
+ ### First Time Setup
191
+
192
+ 1. Install the plugin
193
+ 2. Run the configuration command:
194
+ ```
195
+ /tt-configure
196
+ ```
197
+ 3. Edit the generated config file:
198
+ ```bash
199
+ # ~/.config/opencode/tt-plugin-config.json
200
+ {
201
+ "enabledCommands": ["tmux", "tmux-oc"],
202
+ "defaultTerminal": "alacritty",
203
+ "sessionPrefix": "myproject"
204
+ }
205
+ ```
206
+
207
+ ### Common Configurations
208
+
209
+ #### Only Use OpenCode Integration
210
+ ```json
211
+ {
212
+ "enabledCommands": ["tmux-oc"]
213
+ }
214
+ ```
215
+
216
+ #### Use Claude Split
217
+ ```json
218
+ {
219
+ "enabledCommands": ["tmux", "tmux-claude"]
220
+ }
221
+ ```
222
+
223
+ #### All Commands, Specific Terminal
224
+ ```json
225
+ {
226
+ "enabledCommands": ["tmux", "tmux-oc", "tmux-claude", "tmux-copilot"],
227
+ "defaultTerminal": "kitty"
228
+ }
229
+ ```
230
+
231
+ #### Minimal Setup (Just Tmux)
232
+ ```json
233
+ {
234
+ "enabledCommands": ["tmux"]
235
+ }
236
+ ```
237
+
238
+ ---
239
+
240
+ ## Publishing as npm Package
241
+
242
+ ### Step 1: Update package.json for Publishing
243
+
244
+ ```json
245
+ {
246
+ "name": "tt-plugin",
247
+ "version": "1.0.0",
248
+ "description": "OpenCode plugin for launching tmux with AI assistants in split panes",
249
+ "main": "src/index.ts",
250
+ "type": "module",
251
+ "exports": {
252
+ ".": "./src/index.ts"
253
+ },
254
+ "scripts": {
255
+ "install": "bash install.sh",
256
+ "uninstall": "bash uninstall.sh",
257
+ "test": "bash -n src/scripts/*.sh && npx tsc --noEmit src/index.ts"
258
+ },
259
+ "keywords": [
260
+ "opencode",
261
+ "plugin",
262
+ "tmux",
263
+ "terminal",
264
+ "ai",
265
+ "assistant"
266
+ ],
267
+ "author": "Your Name <your.email@example.com>",
268
+ "license": "MIT",
269
+ "homepage": "https://github.com/yourname/tt-plugin",
270
+ "repository": {
271
+ "type": "git",
272
+ "url": "https://github.com/yourname/tt-plugin.git"
273
+ },
274
+ "bugs": {
275
+ "url": "https://github.com/yourname/tt-plugin/issues"
276
+ },
277
+ "engines": {
278
+ "opencode": ">=dev",
279
+ "tmux": ">=3.0",
280
+ "bash": ">=4.0",
281
+ "node": ">=18.0.0"
282
+ },
283
+ "files": [
284
+ "src/",
285
+ "scripts/",
286
+ "install.sh",
287
+ "uninstall.sh",
288
+ "README.md",
289
+ "DISTRIBUTION_AND_CONFIG.md",
290
+ "IMPLEMENTATION_GUIDE.md",
291
+ "package.json"
292
+ ]
293
+ }
294
+ ```
295
+
296
+ ### Step 2: Setup npm Publishing
297
+
298
+ ```bash
299
+ # Create npm account
300
+ npm adduser
301
+
302
+ # Verify you're logged in
303
+ npm whoami
304
+
305
+ # Tag version (if not already done)
306
+ npm version patch # or minor, major
307
+
308
+ # Publish to npm
309
+ npm publish
310
+
311
+ # Verify it's published
312
+ npm view tt-plugin
313
+ ```
314
+
315
+ ### Step 3: Users Can Install From npm
316
+
317
+ Users add to their `~/.config/opencode/opencode.json`:
318
+
319
+ ```json
320
+ {
321
+ "plugin": ["tt-plugin"]
322
+ }
323
+ ```
324
+
325
+ OpenCode will automatically install it!
326
+
327
+ ---
328
+
329
+ ## Advanced Configuration
330
+
331
+ ### Adding Configuration Validation
332
+
333
+ Update `src/config.ts`:
334
+
335
+ ```typescript
336
+ export function validateConfig(config: any): PluginConfig {
337
+ const validCommands = ["tmux", "tmux-oc", "tmux-claude", "tmux-copilot"]
338
+ const validTerminals = [
339
+ "auto",
340
+ "gnome-terminal",
341
+ "terminator",
342
+ "konsole",
343
+ "alacritty",
344
+ "kitty",
345
+ "xterm"
346
+ ]
347
+
348
+ // Validate enabledCommands
349
+ if (Array.isArray(config.enabledCommands)) {
350
+ const invalid = config.enabledCommands.filter(
351
+ cmd => !validCommands.includes(cmd)
352
+ )
353
+ if (invalid.length > 0) {
354
+ console.warn(
355
+ `tt-plugin: Invalid commands ignored: ${invalid.join(", ")}`
356
+ )
357
+ config.enabledCommands = config.enabledCommands.filter(
358
+ cmd => validCommands.includes(cmd)
359
+ )
360
+ }
361
+ }
362
+
363
+ // Validate defaultTerminal
364
+ if (config.defaultTerminal && !validTerminals.includes(config.defaultTerminal)) {
365
+ console.warn(
366
+ `tt-plugin: Invalid terminal "${config.defaultTerminal}", using "auto"`
367
+ )
368
+ config.defaultTerminal = "auto"
369
+ }
370
+
371
+ return config as PluginConfig
372
+ }
373
+ ```
374
+
375
+ ### Configuration with Environment Variables
376
+
377
+ Users can override config with environment variables:
378
+
379
+ ```bash
380
+ # Override enabled commands via environment
381
+ export TT_PLUGIN_COMMANDS="tmux,tmux-oc"
382
+
383
+ # Use in plugin
384
+ const enabledCommands =
385
+ process.env.TT_PLUGIN_COMMANDS?.split(",") ||
386
+ config.enabledCommands
387
+ ```
388
+
389
+ ---
390
+
391
+ ## File Structure After Implementation
392
+
393
+ ```
394
+ tt-plugin/
395
+ ├── src/
396
+ │ ├── index.ts # Main plugin (reads config)
397
+ │ ├── config.ts # Configuration management
398
+ │ ├── commands/
399
+ │ │ ├── tmux.md
400
+ │ │ ├── tmux-oc.md
401
+ │ │ ├── tmux-claude.md
402
+ │ │ ├── tmux-copilot.md
403
+ │ │ └── tt-configure.md # NEW: Configuration command
404
+ │ └── scripts/
405
+ │ ├── opencode-tmux.sh
406
+ │ ├── opencode-tmux-oc.sh
407
+ │ ├── opencode-tmux-claude.sh
408
+ │ ├── opencode-tmux-copilot.sh
409
+ │ └── opencode-tt-config.sh # NEW: Configuration helper
410
+ ├── scripts/
411
+ │ ├── register-plugin.js
412
+ │ └── unregister-plugin.js
413
+ ├── install.sh # Updated to symlink config script
414
+ ├── uninstall.sh
415
+ ├── package.json # Updated with new files
416
+ ├── README.md
417
+ ├── DISTRIBUTION_AND_CONFIG.md # NEW: This file
418
+ ├── IMPLEMENTATION_GUIDE.md # NEW: Implementation steps
419
+ └── .git/
420
+ ```
421
+
422
+ ---
423
+
424
+ ## Testing Configuration
425
+
426
+ ### Manual Test
427
+
428
+ ```bash
429
+ # 1. Create test config
430
+ mkdir -p ~/.config/opencode
431
+ cat > ~/.config/opencode/tt-plugin-config.json << 'EOF'
432
+ {
433
+ "enabledCommands": ["tmux", "tmux-oc"],
434
+ "defaultTerminal": "alacritty"
435
+ }
436
+ EOF
437
+
438
+ # 2. Verify config loads
439
+ npm test
440
+
441
+ # 3. Test with OpenCode
442
+ opencode
443
+ # Run: /tmux # Should work
444
+ # Run: /tmux-claude # Should be silently ignored
445
+ # Run: /tt-configure # Should show configuration
446
+ ```
447
+
448
+ ### Validation Test
449
+
450
+ ```bash
451
+ # Test invalid configuration
452
+ cat > ~/.config/opencode/tt-plugin-config.json << 'EOF'
453
+ {
454
+ "enabledCommands": ["tmux", "invalid-command"],
455
+ "defaultTerminal": "invalid-terminal"
456
+ }
457
+ EOF
458
+
459
+ # Should warn but still work with filtered commands
460
+ opencode
461
+ ```
462
+
463
+ ---
464
+
465
+ ## Troubleshooting
466
+
467
+ ### Configuration Not Loading
468
+
469
+ ```bash
470
+ # Check if config file exists
471
+ ls -la ~/.config/opencode/tt-plugin-config.json
472
+
473
+ # Check for JSON syntax errors
474
+ cat ~/.config/opencode/tt-plugin-config.json | jq .
475
+
476
+ # Check OpenCode logs
477
+ # The plugin logs to OpenCode's debug logs
478
+ ```
479
+
480
+ ### Commands Still Not Working
481
+
482
+ ```bash
483
+ # Verify plugin is loaded
484
+ grep "tt-plugin" ~/.config/opencode/opencode.json
485
+
486
+ # Verify command registration
487
+ ls -la ~/.config/opencode/commands/ | grep tmux
488
+
489
+ # Run plugin directly to check for errors
490
+ node -e "import('./src/index.ts').then(m => console.log(m))"
491
+ ```
492
+
493
+ ### Publishing Issues
494
+
495
+ ```bash
496
+ # Verify npm account
497
+ npm whoami
498
+
499
+ # Check package.json syntax
500
+ npm run test
501
+
502
+ # Dry run publish
503
+ npm publish --dry-run
504
+
505
+ # Check what will be published
506
+ npm pack --dry-run
507
+ ```
508
+
509
+ ---
510
+
511
+ ## Next Steps
512
+
513
+ After implementing configuration:
514
+
515
+ 1. **Add telemetry** - Track which commands users enable
516
+ 2. **Add more settings** - Terminal colors, session names, etc.
517
+ 3. **Create web UI** - Build a configuration interface
518
+ 4. **Add CLI config** - Let users configure via command line
519
+ 5. **Documentation** - Update README with configuration examples
520
+
521
+ ---
522
+
523
+ ## Related Files
524
+
525
+ - `DISTRIBUTION_AND_CONFIG.md` - Conceptual guide
526
+ - `AGENTS.md` - Developer guidelines
527
+ - `README.md` - User documentation
528
+ - `src/index.ts` - Main plugin entry point
529
+ - `package.json` - Package manifest