Skip to content

Commit 9323509

Browse files
author
yee.wang
committed
feat: redesign as opencode plugin with auto-injected provider and auth hook
- rename package to opencode-qoder-plugin - move @opencode-ai/plugin to dependencies (required by Bun installer) - config hook injects all 10 Qoder models automatically, no provider block needed - auth hook checks ~/.qoder/.auth/user and prompts 'qoder login' if absent - add GitHub Actions CI (test on push) and Publish (release on tag push) - add AGENTS.md with project structure and release process - update README: single-line plugin install, remove manual provider config
1 parent 3584bb3 commit 9323509

7 files changed

Lines changed: 1536 additions & 193 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 22
17+
cache: npm
18+
- run: npm ci
19+
- run: npm test

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 22
19+
registry-url: https://registry.npmjs.org
20+
cache: npm
21+
- run: npm ci
22+
- run: npm publish --provenance
23+
env:
24+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

AGENTS.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# AGENTS.md
2+
3+
This is **opencode-qoder-plugin** — an [opencode](https://opencode.ai) plugin that injects Qoder AI models via a `config` hook. No manual provider configuration needed by users.
4+
5+
## Project Structure
6+
7+
```
8+
opencode-qoder-plugin/
9+
├── index.ts # Plugin entry — config hook + auth hook
10+
├── provider.ts # Exports createQoderProvider() (opencode npm loader entry)
11+
├── src/
12+
│ ├── models.ts # 10 built-in model definitions (injected by config hook)
13+
│ ├── qoder-language-model.ts # LanguageModelV2 implementation (doGenerate + doStream)
14+
│ ├── prompt-builder.ts # AI SDK CallOptions → Qoder prompt / multimodal builder
15+
│ └── vendor/
16+
│ ├── qoder-agent-sdk.mjs # Vendored Qoder Agent SDK — DO NOT modify
17+
│ └── qoder-agent-sdk.d.ts # SDK type declarations — DO NOT modify
18+
└── tests/
19+
├── models.test.ts
20+
├── plugin.test.ts
21+
├── qoder-language-model.test.ts
22+
└── integration/
23+
├── real-api.test.ts # Requires `qoder login`
24+
└── opencode-cli.test.ts
25+
```
26+
27+
## Key Design Decisions
28+
29+
- **Plugin, not provider config**`index.ts` uses the `config` hook to inject `provider.qoder` automatically. Users only need `"plugin": ["opencode-qoder-plugin"]` in their `opencode.json`.
30+
- **Auth hook** — checks `~/.qoder/.auth/user` for login state. If absent, surfaces a prompt telling users to run `qoder login`.
31+
- **Vendored SDK**`src/vendor/qoder-agent-sdk.mjs` is a bundled copy of `@ali/qoder-agent-sdk` (internal registry). Do not replace it without testing the full streaming pipeline.
32+
- **Model merging** — builtin models from `src/models.ts` are injected first; any `provider.qoder.models` overrides in the user's `opencode.json` take precedence.
33+
34+
## How the Streaming Pipeline Works
35+
36+
```
37+
opencode → QoderLanguageModel.doStream()
38+
→ buildPromptFromOptions() # text or multimodal (base64 image)
39+
→ resolveQoderCLI() # finds latest ~/.qoder/bin/qodercli/qodercli-<version>
40+
→ SDK query() # streams SDKMessage events
41+
├─ stream_event path # incremental text / tool-input deltas (preferred)
42+
└─ assistant path # full-block fallback
43+
→ ReadableStream<V2StreamPart>
44+
```
45+
46+
## Development
47+
48+
```bash
49+
npm install
50+
npm test # unit tests, no network required
51+
```
52+
53+
## Release Process
54+
55+
Releases are automated via GitHub Actions:
56+
57+
1. Update `version` in `package.json`
58+
2. Commit and push: `git commit -m "chore: release vX.Y.Z"`
59+
3. Tag and push: `git tag vX.Y.Z && git push origin vX.Y.Z`
60+
4. The **Publish** workflow triggers automatically and publishes to npmjs.com using `NPM_TOKEN` secret
61+
62+
> **NPM_TOKEN** must be set in GitHub repo Settings → Secrets → `NPM_TOKEN`.
63+
> Use an **Automation** type token from https://www.npmjs.com/settings/~/tokens to bypass OTP.
64+
65+
## What NOT to Do
66+
67+
- Do not modify `src/vendor/` files without thorough integration testing
68+
- Do not add a `provider.qoder` block to `opencode.json` — the plugin injects it automatically
69+
- Do not move `@opencode-ai/plugin` back to `devDependencies` — it must be in `dependencies` so opencode's Bun installer pulls it

0 commit comments

Comments
 (0)