Skip to content

Commit d9c709d

Browse files
authored
Package OpenCode plugin for npm and add release workflow (#11)
1 parent c011e73 commit d9c709d

File tree

5 files changed

+173
-9
lines changed

5 files changed

+173
-9
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Release opencode package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'opencode-v*'
7+
workflow_dispatch:
8+
inputs:
9+
publish:
10+
description: Publish to npm (unchecked = dry run only)
11+
type: boolean
12+
required: false
13+
default: false
14+
15+
permissions:
16+
contents: read
17+
id-token: write
18+
19+
concurrency:
20+
group: release-opencode
21+
cancel-in-progress: false
22+
23+
jobs:
24+
release:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- uses: actions/setup-node@v4
31+
with:
32+
node-version: 22
33+
registry-url: https://registry.npmjs.org
34+
35+
- name: Read package metadata
36+
id: pkg
37+
run: |
38+
name=$(node -p "require('./opencode/package.json').name")
39+
version=$(node -p "require('./opencode/package.json').version")
40+
echo "name=$name" >> "$GITHUB_OUTPUT"
41+
echo "version=$version" >> "$GITHUB_OUTPUT"
42+
43+
- name: Validate release tag matches package version
44+
if: github.event_name == 'push'
45+
run: |
46+
expected="opencode-v${{ steps.pkg.outputs.version }}"
47+
if [ "${GITHUB_REF_NAME}" != "$expected" ]; then
48+
echo "::error title=Tag/version mismatch::Expected tag $expected for version ${{ steps.pkg.outputs.version }}, got ${GITHUB_REF_NAME}."
49+
exit 1
50+
fi
51+
52+
- name: Ensure npm version is not already published
53+
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.publish)
54+
run: |
55+
if npm view "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }}" version >/dev/null 2>&1; then
56+
echo "::error title=Version already published::${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }} already exists on npm."
57+
exit 1
58+
fi
59+
60+
- name: Validate package contents
61+
working-directory: opencode
62+
run: npm pack --dry-run
63+
64+
- name: Publish to npm
65+
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.publish)
66+
working-directory: opencode
67+
run: npm publish --access public --provenance
68+
env:
69+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
70+
71+
- name: Dry-run summary
72+
if: github.event_name == 'workflow_dispatch' && !inputs.publish
73+
run: |
74+
echo "Dry run complete for ${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }}."
75+
echo "Re-run this workflow with publish=true to publish."

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Paste a screenshot in your browser, your agent gets the URL instantly.
1313
| Agent | Directory | npm package | Install |
1414
|---|---|---|---|
1515
| [pi](https://github.com/mariozechner/pi) | [`pi/`](pi/) | `@modemdev/glance-pi` | `pi install npm:@modemdev/glance-pi` |
16-
| [OpenCode](https://github.com/anomalyco/opencode) | [`opencode/`](opencode/) | | See [`opencode/README.md`](opencode/README.md) |
16+
| [OpenCode](https://github.com/anomalyco/opencode) | [`opencode/`](opencode/) | `@modemdev/glance-opencode` | Add `"@modemdev/glance-opencode"` to `opencode.json` `plugin` list |
1717

1818
## How it works
1919

opencode/README.md

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,67 @@
77
Maintains a **persistent background session** on glance.sh. Paste an image anytime — the agent receives it instantly.
88

99
- **Background listener** — starts when OpenCode launches, reconnects automatically, refreshes sessions before they expire.
10-
- **`glance` tool** — the LLM calls it when it needs to see something visual. Surfaces the session URL and waits for the next paste.
10+
- **`glance` tool** — the LLM calls it when it needs to see something visual. Surfaces the session URL.
11+
- **`glance_wait` tool** — waits for the next paste and returns the image URL.
1112
- **Multiple images** — paste as many images as you want during a session.
1213

1314
## Install
1415

15-
Symlink or copy `glance.ts` into your OpenCode plugins directory:
16+
Recommended (npm package):
17+
18+
Add the plugin to your global `~/.config/opencode/opencode.json` or project `opencode.json`:
19+
20+
```json
21+
{
22+
"$schema": "https://opencode.ai/config.json",
23+
"plugin": ["@modemdev/glance-opencode"]
24+
}
25+
```
26+
27+
Restart OpenCode. The background session starts automatically.
28+
29+
Optional: pin a specific version:
30+
31+
```json
32+
{
33+
"$schema": "https://opencode.ai/config.json",
34+
"plugin": ["@modemdev/glance-opencode@0.1.0"]
35+
}
36+
```
37+
38+
## Verify
39+
40+
Ask the agent to call the `glance` tool. You should get a session URL like `https://glance.sh/s/<id>`.
41+
42+
Then call `glance_wait` and paste an image in the browser tab — it should return a `Screenshot: https://glance.sh/<token>.<ext>` URL.
43+
44+
## Update / remove
45+
46+
- If you use `@modemdev/glance-opencode` without pinning, OpenCode checks for newer versions at startup.
47+
- If you pin a version, bump it in your `plugin` list when you want to upgrade.
48+
- To remove, delete the package from your `plugin` list and restart OpenCode.
49+
50+
## Publishing (maintainers)
51+
52+
Releases are automated via GitHub Actions.
53+
54+
Prerequisite: configure `NPM_TOKEN` in the `glance-agent-plugins` repository with publish access to `@modemdev/glance-opencode`.
55+
56+
1. Bump `version` in `opencode/package.json`.
57+
2. Commit and push to `main`.
58+
3. Create and push a matching tag:
59+
60+
```bash
61+
git tag opencode-v0.1.0
62+
git push origin opencode-v0.1.0
63+
```
64+
65+
The `Release opencode package` workflow validates the tag/version match and publishes with npm provenance.
66+
You can also run the workflow manually in dry-run mode from Actions.
67+
68+
## Manual install (legacy)
69+
70+
If you prefer local file management, symlink or copy `glance.ts` into your OpenCode plugins directory:
1671

1772
```bash
1873
# symlink (recommended — stays up to date with git pulls)
@@ -22,22 +77,22 @@ ln -s "$(pwd)/glance.ts" ~/.config/opencode/plugins/glance.ts
2277
ln -s "$(pwd)/glance.ts" .opencode/plugins/glance.ts
2378
```
2479

25-
Restart OpenCode. The background session starts automatically.
26-
2780
## How it works
2881

29-
```
82+
```text
3083
opencode starts
3184
└─▶ plugin creates session on glance.sh
3285
└─▶ connects SSE (background, auto-reconnect)
3386
3487
LLM calls glance tool
3588
└─▶ surfaces session URL
89+
90+
LLM calls glance_wait tool
3691
└─▶ waits for image paste
3792
3893
user pastes image at /s/<id>
3994
└─▶ SSE emits "image" event
40-
└─▶ tool returns image URL to LLM
95+
└─▶ glance_wait returns image URL to LLM
4196
4297
session expires (~10 min)
4398
└─▶ plugin creates new session, reconnects

opencode/glance.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
* screenshot; it surfaces the existing session URL and waits for a
1010
* paste.
1111
*
12-
* Install: symlink or copy this file into your opencode plugins
13-
* directory, e.g. .opencode/plugins/glance.ts or
12+
* Install: add "@modemdev/glance-opencode" to the `plugin` list in
13+
* opencode.json (recommended), or symlink/copy this file into your
14+
* plugins directory, e.g. .opencode/plugins/glance.ts or
1415
* ~/.config/opencode/plugins/glance.ts
1516
*/
1617

opencode/package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@modemdev/glance-opencode",
3+
"version": "0.1.0",
4+
"description": "glance.sh plugin package for OpenCode",
5+
"license": "MIT",
6+
"type": "module",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/modem-dev/glance-agent-plugins.git",
10+
"directory": "opencode"
11+
},
12+
"homepage": "https://github.com/modem-dev/glance-agent-plugins/tree/main/opencode",
13+
"bugs": {
14+
"url": "https://github.com/modem-dev/glance-agent-plugins/issues"
15+
},
16+
"keywords": [
17+
"opencode",
18+
"opencode-plugin",
19+
"glance",
20+
"screenshot",
21+
"agent"
22+
],
23+
"files": [
24+
"glance.ts",
25+
"README.md"
26+
],
27+
"exports": {
28+
".": "./glance.ts"
29+
},
30+
"dependencies": {
31+
"@opencode-ai/plugin": "^1.0.0"
32+
}
33+
}

0 commit comments

Comments
 (0)