opencode-devin 0.2.0 → 0.2.1
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 +19 -2
- package/dist/auth/browser.d.ts +7 -0
- package/dist/auth/browser.js +18 -0
- package/dist/auth/login.d.ts +15 -0
- package/dist/auth/login.js +51 -0
- package/dist/index.js +10 -38
- package/dist/protocol/catalog.js +25 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ flowchart TD
|
|
|
89
89
|
|
|
90
90
|
- **No `devin/` models**: run `/connect` again. Failures are logged as `[opencode-devin] ...`; the log is at `~/.local/share/opencode/log/opencode.log`.
|
|
91
91
|
- **A model is rejected even though `/models` lists it**: the account can see a uid it is not entitled to. The error names the tier.
|
|
92
|
-
- **Costs look wrong or absent**: OpenCode reads cost from the pricing published to `/models`, not from the stream. Check the model has a non-zero price there.
|
|
92
|
+
- **Costs look wrong or absent**: OpenCode reads cost from the pricing published to `/models`, not from the stream. Check the model has a non-zero price there — `bun scripts/devin.ts verify` dumps what the catalog actually reports.
|
|
93
93
|
- **A 401 during chat**: the short-lived token is refreshed automatically. Reconnect only if the session token itself was revoked.
|
|
94
94
|
- **`Plugin failed to load`**: rebuild and `opencode reload`. See the FAQ on atomic builds.
|
|
95
95
|
- **A path in `plugins` is ignored**: only `name@file:<absolute-path>` links a local build.
|
|
@@ -106,6 +106,9 @@ npm run build
|
|
|
106
106
|
`build` is atomic, so the plugin can be reloaded while it runs. Publishing uses
|
|
107
107
|
`build:clean`, which wipes `dist/` first.
|
|
108
108
|
|
|
109
|
+
Shared fixtures for the synthetic-catalog tests live in `test/helpers.ts`
|
|
110
|
+
(fake JWTs, protobuf `modelConfig`/`catalogReply` encoders, `stubFetch`).
|
|
111
|
+
|
|
109
112
|
### Developing against a local build
|
|
110
113
|
|
|
111
114
|
Edit `plugins` in `~/.config/opencode/opencode.json` to one of these, then run
|
|
@@ -131,7 +134,21 @@ opencode api provider.list # the devin provider's "package" field
|
|
|
131
134
|
### Testing against the real API
|
|
132
135
|
|
|
133
136
|
`bun test` runs everything except the live suite, which skips itself without a
|
|
134
|
-
credential:
|
|
137
|
+
credential. The dev CLI gets you one and runs the whole check end to end:
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
bun scripts/devin.ts all # login (if needed) → catalog dump → live tests
|
|
141
|
+
bun scripts/devin.ts login # just the PKCE login → .devin-token.env
|
|
142
|
+
bun scripts/devin.ts verify # dump live catalog pricing
|
|
143
|
+
bun scripts/devin.ts test # run test/live.test.ts
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The login is the same browser PKCE flow as `/connect` (loopback callback, or
|
|
147
|
+
`--manual` for paste-code on headless machines). The token lands in
|
|
148
|
+
`.devin-token.env`, which `verify`/`test`/`all` pick up automatically, so a
|
|
149
|
+
second `all` run skips the browser entirely.
|
|
150
|
+
|
|
151
|
+
Or with a token you already have:
|
|
135
152
|
|
|
136
153
|
```sh
|
|
137
154
|
DEVIN_LLM_API_KEY='devin-session-token$...' bun test test/live.test.ts
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open a URL in the system browser.
|
|
3
|
+
*
|
|
4
|
+
* Windows: `cmd /c start` truncates URLs at "&" (cmd metacharacter) when
|
|
5
|
+
* spawned from Bun — rundll32 hands the URL to the default browser verbatim.
|
|
6
|
+
*/
|
|
7
|
+
export function openBrowser(url) {
|
|
8
|
+
if (process.platform === "win32") {
|
|
9
|
+
Bun.spawn(["rundll32", "url.dll,FileProtocolHandler", url], {
|
|
10
|
+
stdin: "ignore",
|
|
11
|
+
stdout: "ignore",
|
|
12
|
+
stderr: "ignore",
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const cmd = process.platform === "darwin" ? ["open", url] : ["xdg-open", url];
|
|
17
|
+
Bun.spawn(cmd, { stdin: "ignore", stdout: "ignore", stderr: "ignore" });
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type CallbackServer } from "./loopback.ts";
|
|
2
|
+
export interface LoginFlow {
|
|
3
|
+
/** URL to open in the browser. */
|
|
4
|
+
url: string;
|
|
5
|
+
/** Resolve with the authorization code (auto: wait for redirect; code: pass the pasted code). */
|
|
6
|
+
finish: (code?: string) => Promise<string>;
|
|
7
|
+
/** Abort the flow and release resources. */
|
|
8
|
+
close: () => void;
|
|
9
|
+
}
|
|
10
|
+
/** Start an automatic login: binds the loopback server and returns the URL to open. */
|
|
11
|
+
export declare function loginAuto(): Promise<LoginFlow & {
|
|
12
|
+
server: CallbackServer;
|
|
13
|
+
}>;
|
|
14
|
+
/** Start a manual login: no loopback; the webapp displays the code for pasting. */
|
|
15
|
+
export declare function loginManual(): Promise<LoginFlow>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Devin CLI login flow (PKCE), shared by the plugin's `/connect` methods and
|
|
3
|
+
* the standalone `scripts/devin.ts login` command.
|
|
4
|
+
*
|
|
5
|
+
* Two modes, matching what the webapp supports:
|
|
6
|
+
* - "auto": loopback callback — browser redirects to 127.0.0.1, we capture
|
|
7
|
+
* the code. Hands-free once the user finishes the web login.
|
|
8
|
+
* - "code": no redirect_uri — the webapp shows a code the user pastes back.
|
|
9
|
+
* Fallback for headless machines and environments where loopback
|
|
10
|
+
* redirects can't reach the browser.
|
|
11
|
+
*/
|
|
12
|
+
import { authorizeUrl } from "./url.js";
|
|
13
|
+
import { exchangeCode } from "./exchange.js";
|
|
14
|
+
import { startCallbackServer } from "./loopback.js";
|
|
15
|
+
import { challengeFor, generateState, generateVerifier } from "./pkce.js";
|
|
16
|
+
/** Start an automatic login: binds the loopback server and returns the URL to open. */
|
|
17
|
+
export async function loginAuto() {
|
|
18
|
+
const verifier = generateVerifier();
|
|
19
|
+
const state = generateState();
|
|
20
|
+
const server = await startCallbackServer(state);
|
|
21
|
+
const url = authorizeUrl({ state, challenge: await challengeFor(verifier), redirectUri: server.redirectUri });
|
|
22
|
+
return {
|
|
23
|
+
url,
|
|
24
|
+
server,
|
|
25
|
+
finish: async () => {
|
|
26
|
+
try {
|
|
27
|
+
const code = await server.code;
|
|
28
|
+
return await exchangeCode({ code, verifier });
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
server.close();
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
close: () => server.close(),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Start a manual login: no loopback; the webapp displays the code for pasting. */
|
|
38
|
+
export async function loginManual() {
|
|
39
|
+
const verifier = generateVerifier();
|
|
40
|
+
const state = generateState();
|
|
41
|
+
const url = authorizeUrl({ state, challenge: await challengeFor(verifier) });
|
|
42
|
+
return {
|
|
43
|
+
url,
|
|
44
|
+
finish: async (code) => {
|
|
45
|
+
if (!code?.trim())
|
|
46
|
+
throw new Error("Manual login requires the pasted authorization code");
|
|
47
|
+
return exchangeCode({ code: code.trim(), verifier });
|
|
48
|
+
},
|
|
49
|
+
close: () => { },
|
|
50
|
+
};
|
|
51
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -14,26 +14,10 @@
|
|
|
14
14
|
import { Plugin, Provider } from "@opencode/plugin";
|
|
15
15
|
import { DEFAULT_API_SERVER, LLM_ENV_VAR, PROVIDER_ID } from "./constants.js";
|
|
16
16
|
import { resolveCredentials, toStoredCredential } from "./credentials.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { challengeFor, generateState, generateVerifier } from "./auth/pkce.js";
|
|
20
|
-
import { exchangeCode } from "./auth/exchange.js";
|
|
17
|
+
import { openBrowser } from "./auth/browser.js";
|
|
18
|
+
import { loginAuto, loginManual } from "./auth/login.js";
|
|
21
19
|
import { fetchModels } from "./catalog.js";
|
|
22
20
|
export { createDevinProvider } from "./provider.js";
|
|
23
|
-
function openBrowser(url) {
|
|
24
|
-
if (process.platform === "win32") {
|
|
25
|
-
// `cmd /c start` truncates URLs at "&" (cmd metacharacter) when spawned
|
|
26
|
-
// from Bun — rundll32 hands the URL to the default browser verbatim.
|
|
27
|
-
Bun.spawn(["rundll32", "url.dll,FileProtocolHandler", url], {
|
|
28
|
-
stdin: "ignore",
|
|
29
|
-
stdout: "ignore",
|
|
30
|
-
stderr: "ignore",
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const cmd = process.platform === "darwin" ? ["open", url] : ["xdg-open", url];
|
|
35
|
-
Bun.spawn(cmd, { stdin: "ignore", stdout: "ignore", stderr: "ignore" });
|
|
36
|
-
}
|
|
37
21
|
export default Plugin.define({
|
|
38
22
|
id: PROVIDER_ID,
|
|
39
23
|
async setup(ctx) {
|
|
@@ -71,24 +55,13 @@ export default Plugin.define({
|
|
|
71
55
|
integrationID: PROVIDER_ID,
|
|
72
56
|
method: { id: "devin", type: "oauth", label: "Log in with Devin (browser)" },
|
|
73
57
|
authorize: async () => {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
const server = await startCallbackServer(state);
|
|
77
|
-
const url = authorizeUrl({ state, challenge: await challengeFor(verifier), redirectUri: server.redirectUri });
|
|
78
|
-
openBrowser(url);
|
|
58
|
+
const flow = await loginAuto();
|
|
59
|
+
openBrowser(flow.url);
|
|
79
60
|
return {
|
|
80
|
-
url,
|
|
81
|
-
instructions: `Log in to Devin in the opened browser tab. If it did not open, go to: ${url}`,
|
|
61
|
+
url: flow.url,
|
|
62
|
+
instructions: `Log in to Devin in the opened browser tab. If it did not open, go to: ${flow.url}`,
|
|
82
63
|
mode: "auto",
|
|
83
|
-
callback: (
|
|
84
|
-
try {
|
|
85
|
-
const code = await server.code;
|
|
86
|
-
return toStoredCredential(await exchangeCode({ code, verifier }));
|
|
87
|
-
}
|
|
88
|
-
finally {
|
|
89
|
-
server.close();
|
|
90
|
-
}
|
|
91
|
-
})(),
|
|
64
|
+
callback: flow.finish().then(toStoredCredential),
|
|
92
65
|
};
|
|
93
66
|
},
|
|
94
67
|
});
|
|
@@ -96,13 +69,12 @@ export default Plugin.define({
|
|
|
96
69
|
integrationID: PROVIDER_ID,
|
|
97
70
|
method: { id: "code", type: "oauth", label: "Paste code (headless)" },
|
|
98
71
|
authorize: async () => {
|
|
99
|
-
const
|
|
100
|
-
const state = generateState();
|
|
72
|
+
const flow = await loginManual();
|
|
101
73
|
return {
|
|
102
|
-
url:
|
|
74
|
+
url: flow.url,
|
|
103
75
|
instructions: "Open the URL, sign in to Devin, and copy the code shown on the page, then paste it here.",
|
|
104
76
|
mode: "code",
|
|
105
|
-
callback: async (code) => toStoredCredential(await
|
|
77
|
+
callback: async (code) => toStoredCredential(await flow.finish(code)),
|
|
106
78
|
};
|
|
107
79
|
},
|
|
108
80
|
});
|
package/dist/protocol/catalog.js
CHANGED
|
@@ -113,7 +113,18 @@ function decodeModelConfig(buf) {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
else if (field.num === 32 && field.wire === 2 && Buffer.isBuffer(field.value)) {
|
|
116
|
-
// Pricing message (repeated)
|
|
116
|
+
// Pricing message (repeated), verified against a live
|
|
117
|
+
// GetCascadeModelConfigs dump and the prices shown in the Devin app
|
|
118
|
+
// (e.g. claude-opus-5-5 = $4/$20, claude-sonnet-5-5 = $2/$10):
|
|
119
|
+
// #1 type string "Input" | "Cached input" | "Output"
|
|
120
|
+
// #2 price float32 USD per unit (#3 = "1M tokens") ← real price
|
|
121
|
+
// #3 unit string "1M tokens"
|
|
122
|
+
// #4 factor float32 per-type constant (0.1/0.007/0.28) —
|
|
123
|
+
// internal credit coefficient, NOT the price.
|
|
124
|
+
// This is what the old code read by mistake.
|
|
125
|
+
// #5 credits float32 same price expressed in Cognition credits
|
|
126
|
+
// #6 flag varint 1
|
|
127
|
+
// #7 note string e.g. "Higher effort consumes more tokens"
|
|
117
128
|
pricing ??= { input: 0, cachedInput: 0, output: 0 };
|
|
118
129
|
let type = "";
|
|
119
130
|
let price = 0;
|
|
@@ -121,15 +132,24 @@ function decodeModelConfig(buf) {
|
|
|
121
132
|
if (part.num === 1 && part.wire === 2 && Buffer.isBuffer(part.value)) {
|
|
122
133
|
type = part.value.toString("utf8").toLowerCase();
|
|
123
134
|
}
|
|
124
|
-
else if (part.num ===
|
|
135
|
+
else if (part.num === 2 &&
|
|
136
|
+
part.wire === 5 &&
|
|
137
|
+
Buffer.isBuffer(part.value) &&
|
|
138
|
+
part.value.length === 4) {
|
|
125
139
|
price = part.value.readFloatLE(0);
|
|
126
140
|
}
|
|
127
141
|
}
|
|
128
|
-
|
|
142
|
+
// Match the pricing dimension by exact label, not substring: the REST
|
|
143
|
+
// API documents extra labels like "sidekick_input" (Fusion models) and
|
|
144
|
+
// "cache_read"/"cache_write" that would corrupt a substring match.
|
|
145
|
+
// Normalise case/spacing defensively — the wire strings are the same
|
|
146
|
+
// labels the REST API exposes in snake_case.
|
|
147
|
+
const normalized = type.trim().toLowerCase().replace(/[\s-]+/g, "_");
|
|
148
|
+
if (normalized === "input")
|
|
129
149
|
pricing.input = price;
|
|
130
|
-
else if (
|
|
150
|
+
else if (normalized === "cached_input" || normalized === "cache_read")
|
|
131
151
|
pricing.cachedInput = price;
|
|
132
|
-
else if (
|
|
152
|
+
else if (normalized === "output")
|
|
133
153
|
pricing.output = price;
|
|
134
154
|
}
|
|
135
155
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "opencode-devin",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"description": "OpenCode v2 plugin: connect your Devin subscription to opencode with native /connect login and devin/* models",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"@opencode/plugin": "2.0.16"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/bun": "1.4.
|
|
53
|
-
"protobufjs": "^8.8.
|
|
52
|
+
"@types/bun": "1.4.4",
|
|
53
|
+
"protobufjs": "^8.8.1",
|
|
54
54
|
"typescript": "7.0.2"
|
|
55
55
|
}
|
|
56
56
|
}
|