dsh-codex-oauth 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 eons2long
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # dsh-codex-oauth
2
+
3
+ [English](README.md) | [中文](README.zh.md)
4
+
5
+ DSH adapter that uses the same OpenAI Codex OAuth credential as Pi:
6
+ `~/.pi/agent/auth.json` → `openai-codex`.
7
+
8
+ It uses Pi's installed `@earendil-works/pi-ai` Codex provider and DSH's public
9
+ `dsh-llm-pi-ai` adapter, including the official Codex Responses transport, images,
10
+ tool calls, reasoning replay, compaction, and OAuth refresh. It does not copy the
11
+ token into an API-key environment variable.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ dsh plugin --profile web add dsh-codex-oauth
17
+ ```
18
+
19
+ For a manual profile install, add the package to the profile and include this
20
+ entry in its `cordis.patch.yml`:
21
+
22
+ ```yaml
23
+ - insert:
24
+ - id: llm-codex-oauth
25
+ name: dsh-codex-oauth
26
+ ```
27
+
28
+ The profile must also include the normal `llm` service. Restart:
29
+
30
+ ```bash
31
+ npx @deepseek-ai/dsh web
32
+ ```
33
+
34
+ Then select provider `openai-codex` in the model picker.
35
+
36
+ ## Scope
37
+
38
+ The plugin delegates message conversion, streaming, image attachments, tool calls,
39
+ reasoning replay, and compaction to DSH's public `dsh-llm-pi-ai` adapter. It only
40
+ bridges the credential store to Pi's existing OAuth document.
41
+
42
+ The plugin reads/writes `~/.pi/agent/auth.json` and never prints token values.
43
+ Because Pi and DSH do not share a cross-application lock, avoid starting both at the
44
+ same time while an OAuth refresh may occur; a future version may use a separate DSH
45
+ credential file and its own login flow to remove that race.
46
+
47
+ ## License
48
+
49
+ MIT
package/README.zh.md ADDED
@@ -0,0 +1,81 @@
1
+ # dsh-codex-oauth
2
+
3
+ [English](README.md) | 中文
4
+
5
+ 让 [DeepSeek Harness(dsh)](https://github.com/deepseek-ai/deepseek-harness)
6
+ 复用 Pi 已登录的 ChatGPT Plus/Pro Codex OAuth,在不使用 OpenAI Platform API Key 的情况下调用 `openai-codex` 模型。
7
+
8
+ 本插件不是普通的 OpenAI API 适配器,也不会把 ChatGPT 订阅变成通用 API 凭据。它使用 Pi 的 Codex provider、官方 Codex Responses 传输和 DSH 公共的 `dsh-llm-pi-ai` 适配器。
9
+
10
+ ## 功能
11
+
12
+ - 复用 `~/.pi/agent/auth.json` 中的 `openai-codex` OAuth 凭据;
13
+ - access token 过期时自动使用 refresh token 更新;
14
+ - 使用 Pi 同款 Codex 模型目录;
15
+ - 支持流式输出、工具调用、推理、图片输入、replay 和上下文压缩;
16
+ - 不读取或打印 API Key,也不会把 token 放进环境变量。
17
+
18
+ ## 安装
19
+
20
+ 将插件安装到 dsh 的 `web` profile:
21
+
22
+ ```bash
23
+ dsh plugin --profile web add dsh-codex-oauth
24
+ dsh web
25
+ ```
26
+
27
+ 如果使用的是 `npx` 版本:
28
+
29
+ ```bash
30
+ npx @deepseek-ai/dsh plugin --profile web add dsh-codex-oauth
31
+ npx @deepseek-ai/dsh web
32
+ ```
33
+
34
+ 启动后,在模型选择器中选择:
35
+
36
+ ```text
37
+ Provider: openai-codex
38
+ ```
39
+
40
+ 也可以手动把下面的条目加入 profile 的 `cordis.patch.yml`:
41
+
42
+ ```yaml
43
+ - insert:
44
+ - id: llm-codex-oauth
45
+ name: dsh-codex-oauth
46
+ ```
47
+
48
+ ## 前置条件
49
+
50
+ Pi 必须已经完成 OpenAI Codex 登录,并且存在:
51
+
52
+ ```text
53
+ ~/.pi/agent/auth.json
54
+ ```
55
+
56
+ 文件中应有 `openai-codex` OAuth 条目。插件不会替用户登录,也不会要求复制 token。
57
+
58
+ ## 凭据与并发注意事项
59
+
60
+ 插件只使用 Pi 的现有凭据文件,并会在 OAuth 刷新后写回该文件。Pi 与 DSH 并不共享同一个跨应用锁,因此在 token 可能刷新时,不建议同时运行 Pi 和 DSH。
61
+
62
+ 卸载插件不会删除 Pi 的登录凭据。若要退出登录,请通过 Pi 自己的 `/logout` 完成。
63
+
64
+ ## 限制
65
+
66
+ - ChatGPT 订阅权限、模型目录、配额和 Codex 后端行为由 OpenAI 控制,可能变化;
67
+ - 插件依赖 DSH 的公共 `dsh-llm-pi-ai` 适配器,需与当前 DSH 版本兼容;
68
+ - 这是 Codex 后端接入,不是公开的 OpenAI Platform API;
69
+ - DSH 的其他能力(文件系统、Shell、MCP、权限、附件等)仍由当前 profile 提供。
70
+
71
+ ## 开发与测试
72
+
73
+ ```bash
74
+ npm test
75
+ ```
76
+
77
+ 测试需要 DSH 和 Pi 的依赖已经安装或由 DSH profile 提供。
78
+
79
+ ## 许可证
80
+
81
+ MIT
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: llm-codex-oauth
3
+ name: dsh-codex-oauth
package/lib/adapter.js ADDED
@@ -0,0 +1,43 @@
1
+ import { createModels } from "@earendil-works/pi-ai";
2
+ import { openaiCodexProvider } from "@earendil-works/pi-ai/providers/openai-codex";
3
+ import { PiAiAdapter } from "@deepseek-ai/dsh-llm-pi-ai";
4
+ import { resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
5
+ import { OPENAI_CODEX_PROVIDER } from "./store.js";
6
+
7
+ const STREAM_IDLE_TIMEOUT_MS = 300_000;
8
+
9
+ function tokenProvider(provider) {
10
+ return {
11
+ ...provider,
12
+ auth: {
13
+ ...provider.auth,
14
+ apiKey: {
15
+ name: "OpenAI Codex OAuth bearer token",
16
+ async resolve({ credential }) {
17
+ return credential?.access
18
+ ? { auth: { apiKey: credential.access }, source: "Pi OAuth" }
19
+ : undefined;
20
+ },
21
+ },
22
+ },
23
+ };
24
+ }
25
+
26
+ export function createCodexAdapter(credentials, resolveAttachments) {
27
+ const provider = openaiCodexProvider();
28
+ const profiles = new Map([[OPENAI_CODEX_PROVIDER, {
29
+ provider: OPENAI_CODEX_PROVIDER,
30
+ displayName: "OpenAI Codex",
31
+ streamIdleTimeoutMs: STREAM_IDLE_TIMEOUT_MS,
32
+ retryPolicy: resolveRetryPolicy(undefined, "dsh-codex-oauth retryPolicy"),
33
+ configuredMaxTokens: new Map(),
34
+ piProvider: tokenProvider(provider),
35
+ }]]);
36
+ const models = createModels({ credentials });
37
+ models.setProvider(provider);
38
+ return new PiAiAdapter({
39
+ profiles: () => profiles,
40
+ resolveApiKey: async () => (await models.getAuth(OPENAI_CODEX_PROVIDER))?.auth.apiKey,
41
+ resolveAttachments,
42
+ });
43
+ }
package/lib/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import { createCodexAdapter } from "./adapter.js";
2
+ import { PiCodexCredentialStore, OPENAI_CODEX_PROVIDER, PI_AUTH_FILE } from "./store.js";
3
+
4
+ export const name = "llm-codex-oauth";
5
+ export const inject = ["llm"];
6
+
7
+ export { OPENAI_CODEX_PROVIDER, PI_AUTH_FILE, PiCodexCredentialStore, createCodexAdapter };
8
+
9
+ export function apply(ctx) {
10
+ const credentials = new PiCodexCredentialStore();
11
+ ctx.llm.registerAdapter(
12
+ [OPENAI_CODEX_PROVIDER],
13
+ createCodexAdapter(credentials, () => ctx.get?.("attachments")),
14
+ );
15
+ }
package/lib/store.js ADDED
@@ -0,0 +1,65 @@
1
+ import { mkdir, readFile, stat } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+ import { withFileLock, writeFileAtomic } from "@deepseek-ai/dsh-atomic-write";
5
+
6
+ export const OPENAI_CODEX_PROVIDER = "openai-codex";
7
+ export const PI_AUTH_FILE = join(homedir(), ".pi", "agent", "auth.json");
8
+
9
+ function clone(value) {
10
+ return value === undefined ? undefined : structuredClone(value);
11
+ }
12
+
13
+ async function ownerOnly(filename) {
14
+ if (process.platform === "win32") return;
15
+ try {
16
+ if ((await stat(filename)).mode & 0o077) throw new Error(`${filename} must be owner-only (chmod 600)`);
17
+ } catch (error) {
18
+ if (error?.code !== "ENOENT") throw error;
19
+ }
20
+ }
21
+
22
+ export class PiCodexCredentialStore {
23
+ constructor(filename = PI_AUTH_FILE) { this.filename = filename; }
24
+
25
+ async readAll() {
26
+ await ownerOnly(this.filename);
27
+ try { return JSON.parse(await readFile(this.filename, "utf8")); }
28
+ catch (error) { if (error?.code === "ENOENT") return {}; throw error; }
29
+ }
30
+
31
+ async read(providerId) {
32
+ if (providerId !== OPENAI_CODEX_PROVIDER) return undefined;
33
+ const value = (await this.readAll())[providerId];
34
+ return value?.type === "oauth" ? clone(value) : undefined;
35
+ }
36
+
37
+ async list() {
38
+ return (await this.read(OPENAI_CODEX_PROVIDER) === undefined)
39
+ ? [] : [{ providerId: OPENAI_CODEX_PROVIDER, type: "oauth" }];
40
+ }
41
+
42
+ async modify(providerId, fn) {
43
+ if (providerId !== OPENAI_CODEX_PROVIDER) throw new Error(`credential store does not own ${providerId}`);
44
+ await mkdir(dirname(this.filename), { recursive: true, mode: 0o700 });
45
+ return withFileLock(this.filename, async () => {
46
+ const auth = await this.readAll();
47
+ const current = auth[providerId];
48
+ const next = await fn(clone(current));
49
+ if (next === undefined) return clone(current);
50
+ auth[providerId] = next;
51
+ await writeFileAtomic(this.filename, `${JSON.stringify(auth, null, 2)}\n`, { mode: 0o600, dirMode: 0o700 });
52
+ return clone(next);
53
+ });
54
+ }
55
+
56
+ async delete(providerId) {
57
+ if (providerId !== OPENAI_CODEX_PROVIDER) return;
58
+ await mkdir(dirname(this.filename), { recursive: true, mode: 0o700 });
59
+ await withFileLock(this.filename, async () => {
60
+ const auth = await this.readAll();
61
+ delete auth[providerId];
62
+ await writeFileAtomic(this.filename, `${JSON.stringify(auth, null, 2)}\n`, { mode: 0o600, dirMode: 0o700 });
63
+ });
64
+ }
65
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "dsh-codex-oauth",
3
+ "version": "0.1.1",
4
+ "description": "Use Pi's OpenAI Codex OAuth subscription in DeepSeek Harness",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/eons2long/dsh-codex-oauth.git"
8
+ },
9
+ "homepage": "https://github.com/eons2long/dsh-codex-oauth#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/eons2long/dsh-codex-oauth/issues"
12
+ },
13
+ "keywords": ["dsh-plugin", "deepseek-harness", "openai-codex", "oauth"],
14
+ "license": "MIT",
15
+ "scripts": { "test": "node test/smoke.mjs" },
16
+ "type": "module",
17
+ "main": "lib/index.js",
18
+ "exports": { ".": "./lib/index.js" },
19
+ "files": ["lib", "cordis.patch.yml", "README.md", "README.zh.md", "LICENSE"],
20
+ "dsh": { "bundle": { "patch": "./cordis.patch.yml" } },
21
+ "peerDependencies": {
22
+ "@earendil-works/pi-ai": "^0.84.1",
23
+ "@deepseek-ai/cordis": "^4.0.1",
24
+ "@deepseek-ai/dsh-atomic-write": "^0.1.0-rc.6",
25
+ "@deepseek-ai/dsh-llm": "^0.1.0-rc.6",
26
+ "@deepseek-ai/dsh-llm-pi-ai": "^0.1.0-rc.6"
27
+ }
28
+ }