openpets 1.0.4

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 ADDED
@@ -0,0 +1,373 @@
1
+ # Pets CLI
2
+
3
+ A command-line interface for managing OpenCode pets plugins. This tool allows you to validate plugins and display information about available pets listed in the local `opencode.json` file.
4
+
5
+ ## Installation
6
+
7
+ The CLI is included in the `pets` package. To build and use it:
8
+
9
+ ```bash
10
+ # Build the CLI
11
+ npm run build-cli
12
+
13
+ # Use directly
14
+ ./pets.sh <command> [options]
15
+
16
+ # Or use with node
17
+ node src/core/cli.js <command> [options]
18
+ ```
19
+
20
+ ## Commands
21
+
22
+ ### `validate`
23
+ Validate plugins in current directory or pets directory.
24
+
25
+ **Options:**
26
+ - `-a, --all` - Validate all plugins in pets directory
27
+ - `-p, --plugin <name>` - Validate a specific plugin by name
28
+ - `-d, --directory <path>` - Specify pets directory (default: ./pets)
29
+
30
+ **Examples:**
31
+ ```bash
32
+ # Validate current directory
33
+ pets validate
34
+
35
+ # Validate all plugins in ./pets
36
+ pets validate --all
37
+
38
+ # Validate specific plugin
39
+ pets validate --plugin jira
40
+
41
+ # Validate with custom directory
42
+ pets validate --all --directory ./my-plugins
43
+ ```
44
+
45
+ ### `list`
46
+ List available pets from local `opencode.json` file.
47
+
48
+ **Options:**
49
+ - `-d, --directory <path>` - Specify directory to search for `opencode.json` (default: .)
50
+
51
+ **Examples:**
52
+ ```bash
53
+ # List pets from current directory
54
+ pets list
55
+
56
+ # List from custom directory
57
+ pets list --directory ./config
58
+ ```
59
+
60
+ ### `info`
61
+ Run validation and list available pets in one command.
62
+
63
+ **Options:**
64
+ - `-d, --directory <path>` - Specify directory to search (default: .)
65
+ - `-p, --pets-dir <path>` - Specify pets directory (default: ./pets)
66
+
67
+ **Examples:**
68
+ ```bash
69
+ # Run validation and list pets
70
+ pets info
71
+
72
+ # Use custom directories
73
+ pets info --directory ./config --pets-dir ./my-plugins
74
+ ```
75
+
76
+ ### `init`
77
+ Create a new `pets.json` configuration file.
78
+
79
+ **Options:**
80
+ - `-d, --directory <path>` - Specify directory to create `pets.json` (default: .)
81
+ - `-f, --force` - Overwrite existing `pets.json`
82
+ - `-t, --template <type>` - Template to use: `basic`, `full`, `development` (default: basic)
83
+
84
+ **Templates:**
85
+ - `basic`: Minimal configuration with version and plugins array
86
+ - `full`: Complete configuration with settings and metadata
87
+ - `development`: Development-focused configuration with sample plugins
88
+
89
+ **Examples:**
90
+ ```bash
91
+ # Create basic configuration
92
+ pets init
93
+
94
+ # Create full configuration with settings
95
+ pets init --template full
96
+
97
+ # Overwrite existing configuration
98
+ pets init --force --template development
99
+ ```
100
+
101
+ ### `config`
102
+ Manage `pets.json` configuration settings.
103
+
104
+ **Options:**
105
+ - `-d, --directory <path>` - Specify directory with `pets.json` (default: .)
106
+ - `-s, --set <key=value>` - Set configuration value
107
+ - `-g, --get <key>` - Get configuration value
108
+ - `-l, --list` - List all configuration
109
+
110
+ **Examples:**
111
+ ```bash
112
+ # Show all configuration
113
+ pets config --list
114
+
115
+ # Get specific setting
116
+ pets config --get settings.autoValidate
117
+
118
+ # Set configuration value
119
+ pets config --set settings.autoValidate=true
120
+
121
+ # Set nested value
122
+ pets config --set settings.defaultPetsDirectory="./my-pets"
123
+ ```
124
+
125
+ ### `add`
126
+ Add a plugin to `pets.json` configuration.
127
+
128
+ **Options:**
129
+ - `-d, --directory <path>` - Specify directory with `pets.json` (default: .)
130
+ - `-p, --plugin <path>` - Plugin path to add (required)
131
+ - `-n, --name <name>` - Plugin name (optional, auto-detected)
132
+ - `-e, --enabled` - Enable plugin (default: true)
133
+
134
+ **Examples:**
135
+ ```bash
136
+ # Add plugin with auto-detected name
137
+ pets add --plugin ./pets/jira
138
+
139
+ # Add plugin with custom name
140
+ pets add --plugin ./custom/path --name my-plugin
141
+
142
+ # Add disabled plugin
143
+ pets add --plugin ./pets/gitlab --enabled false
144
+ ```
145
+
146
+ ### `remove`
147
+ Remove a plugin from `pets.json` configuration.
148
+
149
+ **Options:**
150
+ - `-d, --directory <path>` - Specify directory with `pets.json` (default: .)
151
+ - `-p, --plugin <path>` - Plugin path to remove
152
+ - `-n, --name <name>` - Plugin name to remove
153
+
154
+ **Examples:**
155
+ ```bash
156
+ # Remove by path
157
+ pets remove --plugin ./pets/jira
158
+
159
+ # Remove by name
160
+ pets remove --name jira
161
+ ```
162
+
163
+ ### `show`
164
+ Display current `pets.json` configuration in a readable format.
165
+
166
+ **Options:**
167
+ - `-d, --directory <path>` - Specify directory with `pets.json` (default: .)
168
+
169
+ **Examples:**
170
+ ```bash
171
+ # Show current configuration
172
+ pets show
173
+
174
+ # Show configuration from custom directory
175
+ pets show --directory ./config
176
+ ```
177
+
178
+ ### `help`
179
+ Show help information.
180
+
181
+ ## Usage Examples
182
+
183
+ ### Basic Workflow
184
+ ```bash
185
+ # 1. Build CLI
186
+ npm run build-cli
187
+
188
+ # 2. Create local configuration
189
+ ./pets.sh init --template full
190
+
191
+ # 3. Add plugins to local config
192
+ ./pets.sh add --plugin ./pets/jira --name jira
193
+ ./pets.sh add --plugin ./pets/gitlab --name gitlab
194
+
195
+ # 4. Check all plugins are valid
196
+ ./pets.sh validate --all
197
+
198
+ # 5. See what pets are configured locally
199
+ ./pets.sh show
200
+
201
+ # 6. Get combined validation and listing
202
+ ./pets.sh info
203
+ ```
204
+
205
+ ### Development Workflow
206
+ ```bash
207
+ # Create development configuration with sample plugins
208
+ ./pets.sh init --template development
209
+
210
+ # Validate a single plugin during development
211
+ ./pets.sh validate --plugin my-new-plugin
212
+
213
+ # Check current directory plugin
214
+ ./pets.sh validate
215
+
216
+ # Add new plugin to local config
217
+ ./pets.sh add --plugin ./my-plugin --name my-plugin
218
+
219
+ # Configure settings
220
+ ./pets.sh config --set settings.autoValidate=false
221
+
222
+ # Test with different configurations
223
+ ./pets.sh list --directory ./test-config
224
+ ```
225
+
226
+ ### Configuration Management
227
+ ```bash
228
+ # Initialize new configuration
229
+ ./pets.sh init --template full
230
+
231
+ # Add plugins
232
+ ./pets.sh add --plugin ./pets/jira --name "Jira Plugin"
233
+ ./pets.sh add --plugin ./pets/gitlab --name "GitLab Plugin"
234
+
235
+ # Manage configuration
236
+ ./pets.sh config --list
237
+ ./pets.sh config --get settings.autoValidate
238
+ ./pets.sh config --set settings.defaultPetsDirectory="./my-plugins"
239
+
240
+ # Remove plugins
241
+ ./pets.sh remove --name "Jira Plugin"
242
+
243
+ # Show current state
244
+ ./pets.sh show
245
+ ```
246
+
247
+ ### Development Workflow
248
+ ```bash
249
+ # Validate a single plugin during development
250
+ ./pets.sh validate --plugin my-new-plugin
251
+
252
+ # Check current directory plugin
253
+ ./pets.sh validate
254
+
255
+ # Test with different configurations
256
+ ./pets.sh list --directory ./test-config
257
+ ```
258
+
259
+ ## Output
260
+
261
+ The CLI provides clear, emoji-enhanced output:
262
+
263
+ - ✅ Success indicators
264
+ - ❌ Error indicators
265
+ - ⚠️ Warning indicators
266
+ - 🔍 Search/validation indicators
267
+ - 🐾 Pet-related information
268
+ - 📋 Report headers
269
+
270
+ ## Integration with OpenCode
271
+
272
+ The CLI integrates seamlessly with OpenCode workflows:
273
+
274
+ 1. **Validation First**: Always run validation before using plugins
275
+ 2. **Configuration Discovery**: Automatically reads `opencode.json` for available pets
276
+ 3. **Development Support**: Helps ensure plugin quality during development
277
+
278
+ ## pets.json Configuration Format
279
+
280
+ The `pets.json` file allows local configuration of plugins:
281
+
282
+ ### Basic Structure
283
+ ```json
284
+ {
285
+ "version": "1.0.0",
286
+ "created": "2025-11-19T15:39:56.996Z",
287
+ "plugins": [
288
+ {
289
+ "name": "jira",
290
+ "path": "./pets/jira",
291
+ "enabled": true,
292
+ "description": "Jira integration plugin",
293
+ "added": "2025-11-19T15:40:00.000Z"
294
+ }
295
+ ]
296
+ }
297
+ ```
298
+
299
+ ### Full Structure
300
+ ```json
301
+ {
302
+ "version": "1.0.0",
303
+ "created": "2025-11-19T15:39:56.996Z",
304
+ "description": "Local pets configuration",
305
+ "settings": {
306
+ "autoValidate": true,
307
+ "showWarnings": true,
308
+ "defaultPetsDirectory": "./pets"
309
+ },
310
+ "plugins": [
311
+ {
312
+ "name": "jira",
313
+ "path": "./pets/jira",
314
+ "enabled": true,
315
+ "description": "Jira & Confluence integration",
316
+ "added": "2025-11-19T15:40:00.000Z"
317
+ }
318
+ ]
319
+ }
320
+ ```
321
+
322
+ ### Plugin Object Properties
323
+ - `name`: Plugin identifier (string, required)
324
+ - `path`: Relative or absolute path to plugin (string, required)
325
+ - `enabled`: Whether plugin is active (boolean, default: true)
326
+ - `description`: Plugin description (string, optional)
327
+ - `added`: When plugin was added (ISO date string, auto-generated)
328
+
329
+ ### Settings Properties
330
+ - `autoValidate`: Automatically validate plugins on operations (boolean, default: true)
331
+ - `showWarnings`: Show validation warnings (boolean, default: true)
332
+ - `defaultPetsDirectory`: Default directory to search for plugins (string, default: "./pets")
333
+
334
+ ## File Structure
335
+
336
+ The CLI expects this structure:
337
+
338
+ ```
339
+ project/
340
+ ├── pets.json # Local plugin configuration
341
+ ├── opencode.json # OpenCode configuration (optional)
342
+ ├── pets/ # Plugin directory
343
+ │ ├── plugin1/
344
+ │ │ ├── package.json
345
+ │ │ ├── index.ts
346
+ │ │ └── opencode.json
347
+ │ └── plugin2/
348
+ │ ├── package.json
349
+ │ ├── index.ts
350
+ │ └── opencode.json
351
+ └── src/core/
352
+ ├── cli.js # Compiled CLI
353
+ └── cli.ts # CLI source
354
+ ```
355
+
356
+ ## Error Handling
357
+
358
+ The CLI provides helpful error messages for common issues:
359
+
360
+ - Missing `opencode.json` files
361
+ - Invalid plugin structure
362
+ - Missing required files
363
+ - JSON syntax errors
364
+ - Missing dependencies
365
+
366
+ ## Contributing
367
+
368
+ To extend the CLI:
369
+
370
+ 1. Edit `src/core/cli.ts` for new commands
371
+ 2. Update `src/core/validate-plugin.ts` for validation logic
372
+ 3. Rebuild with `npm run build-cli`
373
+ 4. Test with `./pets.sh help`
@@ -0,0 +1,117 @@
1
+ import { createLogger } from "../logger"
2
+ import * as fs from "fs"
3
+ import * as path from "path"
4
+ import { exec } from "child_process"
5
+ import { promisify } from "util"
6
+
7
+ const execAsync = promisify(exec)
8
+ const logger = createLogger("base-ai-client")
9
+
10
+ export interface AIImageResult {
11
+ success: boolean
12
+ images?: Array<{ url: string; width?: number; height?: number }>
13
+ error?: string
14
+ metadata?: Record<string, any>
15
+ requestId?: string
16
+ credits?: Record<string, any>
17
+ }
18
+
19
+ export interface AIVideoResult {
20
+ success: boolean
21
+ videos?: Array<{ url: string; duration?: number; width?: number; height?: number }>
22
+ error?: string
23
+ metadata?: Record<string, any>
24
+ requestId?: string
25
+ credits?: Record<string, any>
26
+ }
27
+
28
+ export interface BaseAIClientConfig {
29
+ apiKey: string
30
+ baseUrl?: string
31
+ debug?: boolean
32
+ }
33
+
34
+ export abstract class BaseAIClient {
35
+ protected apiKey: string
36
+ protected baseUrl?: string
37
+ protected debug: boolean
38
+
39
+ constructor(config: BaseAIClientConfig) {
40
+ this.apiKey = config.apiKey
41
+ this.baseUrl = config.baseUrl
42
+ this.debug = config.debug || false
43
+ }
44
+
45
+ abstract get providerName(): string
46
+
47
+ protected ensureApiKey(envVarName: string): void {
48
+ if (!this.apiKey || this.apiKey.trim() === "") {
49
+ throw new Error(`${envVarName} environment variable is required but not set`)
50
+ }
51
+ }
52
+
53
+ protected async downloadMedia(url: string, outputDir: string, prefix: string): Promise<string> {
54
+ try {
55
+ if (!fs.existsSync(outputDir)) {
56
+ fs.mkdirSync(outputDir, { recursive: true })
57
+ }
58
+
59
+ const timestamp = Date.now()
60
+ const extension = url.includes('.mp4') || url.includes('video') ? 'mp4' : 'png'
61
+ const filename = `${prefix}-${timestamp}.${extension}`
62
+ const filepath = path.join(outputDir, filename)
63
+
64
+ logger.info(`Downloading media from ${url}`)
65
+
66
+ const response = await fetch(url)
67
+ if (!response.ok) {
68
+ throw new Error(`Failed to download: ${response.statusText}`)
69
+ }
70
+
71
+ const buffer = await response.arrayBuffer()
72
+ fs.writeFileSync(filepath, Buffer.from(buffer))
73
+
74
+ logger.info(`Media saved to ${filepath}`)
75
+ return filepath
76
+ } catch (error: any) {
77
+ logger.error(`Failed to download media: ${error.message}`)
78
+ throw error
79
+ }
80
+ }
81
+
82
+ protected async openInDefaultViewer(filepath: string): Promise<void> {
83
+ try {
84
+ const platform = process.platform
85
+ let command: string
86
+
87
+ if (platform === "darwin") {
88
+ command = `open "${filepath}"`
89
+ } else if (platform === "win32") {
90
+ command = `start "" "${filepath}"`
91
+ } else {
92
+ command = `xdg-open "${filepath}"`
93
+ }
94
+
95
+ await execAsync(command)
96
+ logger.info(`Opened ${filepath} in default viewer`)
97
+ } catch (error: any) {
98
+ logger.warn(`Failed to open in viewer: ${error.message}`)
99
+ }
100
+ }
101
+
102
+ protected getMimeType(filename: string): string {
103
+ const ext = path.extname(filename).toLowerCase()
104
+ const mimeTypes: Record<string, string> = {
105
+ '.jpg': 'image/jpeg',
106
+ '.jpeg': 'image/jpeg',
107
+ '.png': 'image/png',
108
+ '.gif': 'image/gif',
109
+ '.webp': 'image/webp',
110
+ '.mp4': 'video/mp4',
111
+ '.mov': 'video/quicktime',
112
+ '.avi': 'video/x-msvideo',
113
+ '.webm': 'video/webm'
114
+ }
115
+ return mimeTypes[ext] || 'application/octet-stream'
116
+ }
117
+ }
package/browser.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Browser-safe exports from openpets
3
+ *
4
+ * This module only exports code that doesn't use Node.js APIs like fs, path, etc.
5
+ * Use this entry point when importing from browser/frontend code.
6
+ */
7
+
8
+ export * from './types'
9
+ export * from './search-pets'
10
+ export * from './schema-helpers'