opencode-see-image 0.5.3 → 0.5.5

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 (2) hide show
  1. package/index.ts +57 -7
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -119,6 +119,11 @@ function resolveFromFilesystem(
119
119
  ): ResolvedImage | null {
120
120
  let absPath: string | null = null
121
121
 
122
+ // Expand tilde to home directory
123
+ if (name.startsWith("~")) {
124
+ name = path.join(os.homedir(), name.slice(1))
125
+ }
126
+
122
127
  if (path.isAbsolute(name) && fs.existsSync(name)) {
123
128
  absPath = name
124
129
  } else {
@@ -346,14 +351,46 @@ const PKG_NAME = "opencode-see-image"
346
351
  const REGISTRY_LATEST = `https://registry.npmjs.org/${PKG_NAME}/latest`
347
352
 
348
353
  function currentVersion(): string | null {
354
+ // Try import.meta.url first (works when not bundled)
349
355
  try {
350
356
  const here = new URL(".", import.meta.url)
351
357
  const pkgPath = new URL("package.json", here)
352
358
  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
353
- return pkg.version ?? null
354
- } catch {
355
- return null
356
- }
359
+ if (pkg.version) return pkg.version
360
+ } catch {}
361
+
362
+ // Fallback: walk up from import.meta.url looking for package.json with our name
363
+ try {
364
+ let dir = new URL(".", import.meta.url)
365
+ for (let i = 0; i < 10; i++) {
366
+ const pkgPath = new URL("package.json", dir)
367
+ try {
368
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
369
+ if (pkg.name === PKG_NAME && pkg.version) return pkg.version
370
+ } catch {}
371
+ const parent = new URL("../", dir)
372
+ if (parent.href === dir.href) break
373
+ dir = parent
374
+ }
375
+ } catch {}
376
+
377
+ // Last resort: check the known opencode cache paths
378
+ try {
379
+ const cacheDir = path.join(os.homedir(), ".cache/opencode/packages")
380
+ if (fs.existsSync(cacheDir)) {
381
+ for (const sub of fs.readdirSync(cacheDir)) {
382
+ if (sub.startsWith(PKG_NAME)) {
383
+ const pkgPath = path.join(cacheDir, sub, "node_modules", PKG_NAME, "package.json")
384
+ try {
385
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
386
+ if (pkg.version) return pkg.version
387
+ } catch {}
388
+ }
389
+ }
390
+ }
391
+ } catch {}
392
+
393
+ return null
357
394
  }
358
395
 
359
396
  function semverGt(a: string, b: string): boolean {
@@ -373,8 +410,13 @@ async function maybeAutoUpdate(
373
410
  $: any,
374
411
  log: (msg: string, level?: string) => void,
375
412
  ) {
413
+ log(`starting update check`, "debug")
376
414
  const current = currentVersion()
377
- if (!current) return
415
+ if (!current) {
416
+ log(`could not determine current version`, "warn")
417
+ return
418
+ }
419
+ log(`current version: ${current}`, "debug")
378
420
 
379
421
  let latest: string
380
422
  try {
@@ -425,10 +467,18 @@ const SeeImagePlugin: Plugin = async (ctx) => {
425
467
  const log = (message: string, level: string = "info") => {
426
468
  try {
427
469
  client?.app?.log?.({ body: { service: PKG_NAME, level, message } })
428
- } catch {}
470
+ } catch {
471
+ // fallback for environments where client.app.log is unavailable
472
+ if (process.env.NODE_ENV !== "production") {
473
+ console.log(`[${PKG_NAME}] ${level}: ${message}`)
474
+ }
475
+ }
429
476
  }
430
477
 
431
- maybeAutoUpdate(client, $, log).catch(() => {})
478
+ log(`plugin initialized`, "info")
479
+ maybeAutoUpdate(client, $, log).catch((e) => {
480
+ log(`auto-update error: ${e?.message ?? e}`, "warn")
481
+ })
432
482
 
433
483
  const seeImageTool = tool({
434
484
  description:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-see-image",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Give non-vision opencode models the ability to see images/screenshots by routing them to a vision-capable model (MiniMax M3 via opencode-go by default).",
5
5
  "type": "module",
6
6
  "main": "index.ts",