diff --git a/packages/devin/README.md b/packages/devin/README.md index 93bef21..4951547 100644 --- a/packages/devin/README.md +++ b/packages/devin/README.md @@ -25,7 +25,11 @@ plugin's own, `~/.cache/opencode-devin-auth//`, so the CLI's own sign-in is never touched. A CLI that reads another `credentials.toml` than that folder's (on Windows it reads `%APPDATA%\devin\` whatever it is run with) isn't asked: it would name -its own account. Otherwise the account is named "Devin". +its own account. Otherwise the account is named +`Devin · `, using a one-way fingerprint of the API server +and session token. Repeating the same sign-in keeps its slot, while two +accounts whose identities are both unreadable no longer replace each +other. The token is kept where OpenCode keeps sign-ins (`auth.json`; in magpie, `plugin-auth.json`) as `{ "type": "api", "key", "metadata": { "email", "plan", "orgId", "teamId" } }`. diff --git a/packages/devin/identity.test.mjs b/packages/devin/identity.test.mjs index 6d188aa..a77b8ad 100644 --- a/packages/devin/identity.test.mjs +++ b/packages/devin/identity.test.mjs @@ -134,10 +134,17 @@ test.if(unix)("a key Devin refuses fails the sign-in, whatever the CLI says", as await expect(_internal.success("key-refused", "https://server.codeium.com")).rejects.toThrow("Devin didn't take the sign-in") }, SLOW) -test.if(unix)("when Devin can't tell, the CLI names the account only if it read the key's own folder", async () => { +test.if(unix)("unreadable identities keep separate stable slots until the CLI names the account", async () => { devin(() => new Response("", { status: 503 })) // the CLI read its own credentials.toml: not the key's account - expect((await _internal.success("key-c", "https://server.codeium.com")).metadata).toEqual({ email: "Devin" }) + const c = await _internal.success("key-c", "https://server.codeium.com") + const cAgain = await _internal.success("key-c", "https://server.codeium.com") + const d = await _internal.success("key-d", "https://server.codeium.com") + expect(c.metadata.email).toMatch(/^Devin · [0-9a-f]{12}$/) + expect(cAgain.metadata.email).toBe(c.metadata.email) + expect(d.metadata.email).not.toBe(c.metadata.email) + expect(c.metadata.email).not.toContain("key-c") + expect(d.metadata.email).not.toContain("key-d") // a CLI that honours the folder answers for the key process.env.FAKE_HONOURS = "1" process.env.FAKE_EMAIL = "c@x.dev" diff --git a/packages/devin/index.mjs b/packages/devin/index.mjs index ef2eab3..1a10d2a 100644 --- a/packages/devin/index.mjs +++ b/packages/devin/index.mjs @@ -928,17 +928,23 @@ async function exchange(code, verifier, redirect) { return { key, webapp: r.devinWebappHost, api: r.devinApiUrl } } +// unknownAccount names a credential without revealing it. The same key on +// the same server keeps its slot, while two unreadable accounts don't both +// become "Devin" and replace each other in magpie (#931). +const unknownAccount = (key, server) => + `Devin · ${createHash("sha256").update(server || SERVER).update("\0").update(key).digest("hex").slice(0, 12)}` + // success names a key's account as Devin does when asked with the key // (GetUserStatus), or, when Devin can't tell, as the CLI does in a data // folder of the plugin's own: never by the CLI alone, which on Windows // names its own account whatever key it is given (#17). A key Devin or the // CLI says nobody is signed in with fails it; with neither able to tell, -// the account is just "Devin". +// a stable fingerprint keeps that credential apart from another (#931). async function success(key, server) { let who = await whoByKey(key, server) if (who === undefined) who = await identity(await homeFor(key, server)) if (who === null) throw new Error("Devin didn't take the sign-in: nobody is signed in with the token it gave") - const metadata = { email: who?.user || "Devin" } + const metadata = { email: who?.user || unknownAccount(key, server) } if (who?.plan) metadata.plan = who.plan const orgId = who?.orgId || who?.teamId if (orgId) metadata.orgId = orgId diff --git a/packages/devin/package.json b/packages/devin/package.json index 3afeeac..fb90798 100644 --- a/packages/devin/package.json +++ b/packages/devin/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-devin-auth", - "version": "0.1.38", + "version": "0.1.39", "description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie", "type": "module", "main": "./index.mjs",