opencode-glm-quota 1.3.1 → 1.3.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.
Files changed (3) hide show
  1. package/README.md +17 -0
  2. package/bin/install.js +109 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -35,6 +35,23 @@ npx opencode-glm-quota install
35
35
  - Merges agent configuration into `~/.config/opencode/opencode.json`
36
36
  - Supports `--force` flag to overwrite existing files
37
37
 
38
+ ### Uninstall
39
+
40
+ ```bash
41
+ # Remove OpenCode integration files and config
42
+ npx opencode-glm-quota uninstall
43
+
44
+ # If installed globally
45
+ npx opencode-glm-quota uninstall --global
46
+ ```
47
+
48
+ **What the uninstaller does:**
49
+ - Removes `/glm_quota` command
50
+ - Deletes `skills/glm-quota/SKILL.md`
51
+ - Removes plugin entry from OpenCode config
52
+ - Removes `glm-quota-exec` agent config
53
+ - Runs `npm remove opencode-glm-quota` (or `--global`)
54
+
38
55
  ### Option 2: From GitHub
39
56
 
40
57
  ```bash
package/bin/install.js CHANGED
@@ -9,11 +9,13 @@
9
9
  * Usage:
10
10
  * node bin/install.js # Interactive install (ask before overwriting)
11
11
  * node bin/install.js --force # Force overwrite existing files
12
+ * node bin/install.js uninstall # Remove integration files and config
12
13
  */
13
14
 
14
15
  import * as fs from 'fs'
15
16
  import * as path from 'path'
16
17
  import * as os from 'os'
18
+ import { spawnSync } from 'child_process'
17
19
  import { parse as parseJsonc } from 'jsonc-parser'
18
20
 
19
21
  // ==========================================
@@ -72,6 +74,30 @@ function copyFile(source, destination) {
72
74
  fs.copyFileSync(source, destination)
73
75
  }
74
76
 
77
+ /**
78
+ * Remove file if it exists
79
+ */
80
+ function removeFile(filePath, label) {
81
+ if (fileExists(filePath)) {
82
+ fs.unlinkSync(filePath)
83
+ console.log(` ✓ Removed ${label}`)
84
+ } else {
85
+ console.log(` ⊙ Not found ${label}`)
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Remove directory if it exists
91
+ */
92
+ function removeDirectory(dirPath, label) {
93
+ if (fileExists(dirPath)) {
94
+ fs.rmSync(dirPath, { recursive: true, force: true })
95
+ console.log(` ✓ Removed ${label}`)
96
+ } else {
97
+ console.log(` ⊙ Not found ${label}`)
98
+ }
99
+ }
100
+
75
101
  /**
76
102
  * Parse JSON or JSONC file
77
103
  */
@@ -208,6 +234,79 @@ function mergeConfig() {
208
234
  console.log(` ✓ Merged configuration into ${path.basename(TARGET_CONFIG)}`)
209
235
  }
210
236
 
237
+ /**
238
+ * Remove plugin configuration and agent configuration
239
+ */
240
+ function removeConfig() {
241
+ if (!fileExists(TARGET_CONFIG)) {
242
+ console.log(` ⊙ Config not found: ${TARGET_CONFIG}`)
243
+ return
244
+ }
245
+
246
+ const PLUGIN_NAME = 'opencode-glm-quota'
247
+ const existingConfig = parseConfig(TARGET_CONFIG)
248
+ let changed = false
249
+
250
+ if (Array.isArray(existingConfig.plugin)) {
251
+ const next = existingConfig.plugin.filter((name) => name !== PLUGIN_NAME)
252
+ if (next.length !== existingConfig.plugin.length) {
253
+ existingConfig.plugin = next
254
+ changed = true
255
+ console.log(' ✓ Removed plugin from plugin array')
256
+ }
257
+ }
258
+
259
+ if (Array.isArray(existingConfig.plugins)) {
260
+ const next = existingConfig.plugins.filter((name) => name !== PLUGIN_NAME)
261
+ if (next.length !== existingConfig.plugins.length) {
262
+ existingConfig.plugins = next
263
+ changed = true
264
+ console.log(' ✓ Removed plugin from plugins array')
265
+ }
266
+ }
267
+
268
+ if (existingConfig.agent && existingConfig.agent['glm-quota-exec']) {
269
+ delete existingConfig.agent['glm-quota-exec']
270
+ if (Object.keys(existingConfig.agent).length === 0) {
271
+ delete existingConfig.agent
272
+ }
273
+ changed = true
274
+ console.log(' ✓ Removed glm-quota-exec agent config')
275
+ }
276
+
277
+ if (changed) {
278
+ writeConfig(TARGET_CONFIG, existingConfig)
279
+ console.log(` ✓ Updated ${path.basename(TARGET_CONFIG)}`)
280
+ } else {
281
+ console.log(' ⊙ No config changes needed')
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Remove npm package
287
+ */
288
+ function removePackage(globalFlag) {
289
+ const args = ['remove', 'opencode-glm-quota']
290
+ if (globalFlag) {
291
+ args.push('--global')
292
+ }
293
+
294
+ const result = spawnSync('npm', args, { stdio: 'inherit' })
295
+ if (result.status !== 0) {
296
+ console.log(' ⊙ npm remove failed, remove manually if needed')
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Uninstall integration files and configuration
302
+ */
303
+ function uninstall(globalFlag) {
304
+ removeFile(TARGET_COMMAND, TARGET_COMMAND)
305
+ removeDirectory(path.dirname(TARGET_SKILL), path.dirname(TARGET_SKILL))
306
+ removeConfig()
307
+ removePackage(globalFlag)
308
+ }
309
+
211
310
  // ==========================================
212
311
  // MAIN INSTALLATION FUNCTION
213
312
  // ==========================================
@@ -219,7 +318,17 @@ function main() {
219
318
  try {
220
319
  // Parse command line arguments
221
320
  const args = process.argv.slice(2)
321
+ const isUninstall = args.includes('uninstall')
222
322
  const forceFlag = args.includes('--force')
323
+ const globalFlag = args.includes('--global') || args.includes('-g')
324
+
325
+ if (isUninstall) {
326
+ console.log('✓ Uninstalling GLM Quota Plugin...\n')
327
+ uninstall(globalFlag)
328
+ console.log()
329
+ console.log('✓ Uninstall complete!')
330
+ return
331
+ }
223
332
 
224
333
  console.log('✓ Installing GLM Quota Plugin...\n')
225
334
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-glm-quota",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin to query Z.ai GLM Coding Plan usage statistics including quota limits, model usage, and MCP tool usage",
6
6
  "main": "dist/index.js",