dsh-codex-subscription 3.1.2 → 3.1.3

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.en.md CHANGED
@@ -42,7 +42,7 @@ This plugin supports the latest DeepSeek Harness release recorded in its package
42
42
  2. Paste this package name, with its version, into the **Package name or address** field:
43
43
 
44
44
  ```text
45
- dsh-codex-subscription@3.1.2
45
+ dsh-codex-subscription@3.1.3
46
46
  ```
47
47
 
48
48
  3. Click **Install** and wait for completion. Follow the page instructions; save your work before restarting if requested.
@@ -54,7 +54,7 @@ Why the version is included: DSH's plugin page only installs versions that are a
54
54
  <summary>Terminal installation (with an existing dsh command)</summary>
55
55
 
56
56
  ```sh
57
- dsh plugin --profile web add dsh-codex-subscription@3.1.2
57
+ dsh plugin --profile web add dsh-codex-subscription@3.1.3
58
58
  ```
59
59
 
60
60
  Follow the restart instructions, then sign in under **Settings → Codex**. Both the Plugins page and the terminal use DSH's installation management.
@@ -67,7 +67,7 @@ Follow the restart instructions, then sign in under **Settings → Codex**. Both
67
67
  After signing in and selecting a Codex model in Web, install the same plugin in the Headless profile:
68
68
 
69
69
  ```sh
70
- dsh plugin --profile headless add dsh-codex-subscription@3.1.2
70
+ dsh plugin --profile headless add dsh-codex-subscription@3.1.3
71
71
  dsh --profile headless "Reply with only the word: ok"
72
72
  ```
73
73
 
@@ -294,7 +294,7 @@ Find this plugin on the DSH **Plugins** page and use its update or uninstall act
294
294
  <summary>Terminal commands</summary>
295
295
 
296
296
  ```sh
297
- dsh plugin --profile web update dsh-codex-subscription@3.1.2
297
+ dsh plugin --profile web update dsh-codex-subscription@3.1.3
298
298
  ```
299
299
 
300
300
  Run only when you want to uninstall:
package/README.md CHANGED
@@ -42,7 +42,7 @@
42
42
  2. 在 **包名或地址** 输入框中粘贴下面的包名(已带版本号):
43
43
 
44
44
  ```text
45
- dsh-codex-subscription@3.1.2
45
+ dsh-codex-subscription@3.1.3
46
46
  ```
47
47
 
48
48
  3. 点击 **安装**,等待安装完成;按页面提示操作,需要重启时先保存工作。
@@ -54,7 +54,7 @@
54
54
  <summary>终端安装(已能运行 dsh 命令)</summary>
55
55
 
56
56
  ```sh
57
- dsh plugin --profile web add dsh-codex-subscription@3.1.2
57
+ dsh plugin --profile web add dsh-codex-subscription@3.1.3
58
58
  ```
59
59
 
60
60
  安装完成后按提示重启 DSH,再到 **设置 → Codex 订阅** 登录。插件页面和终端均由 DSH 管理安装。
@@ -67,7 +67,7 @@ dsh plugin --profile web add dsh-codex-subscription@3.1.2
67
67
  先在 Web 中完成登录并选择一次 Codex 模型,再把同一个插件安装到 Headless profile:
68
68
 
69
69
  ```sh
70
- dsh plugin --profile headless add dsh-codex-subscription@3.1.2
70
+ dsh plugin --profile headless add dsh-codex-subscription@3.1.3
71
71
  dsh --profile headless "只回复:ok"
72
72
  ```
73
73
 
@@ -308,7 +308,7 @@ DSH 实机设置截图,随浅色 / 深色主题切换。
308
308
  <summary>终端方式</summary>
309
309
 
310
310
  ```sh
311
- dsh plugin --profile web update dsh-codex-subscription@3.1.2
311
+ dsh plugin --profile web update dsh-codex-subscription@3.1.3
312
312
  ```
313
313
 
314
314
  仅在需要卸载时运行:
package/lib/client.js CHANGED
@@ -11478,7 +11478,7 @@ window.__ModuleLoader__.load({
11478
11478
  }
11479
11479
  //#endregion
11480
11480
  //#region src/version.js
11481
- const PACKAGE_VERSION = "3.1.2";
11481
+ const PACKAGE_VERSION = "3.1.3";
11482
11482
  //#endregion
11483
11483
  //#region src/client-recovery.js
11484
11484
  async function recoveryCall(rpc, endpoint, payload = {}, timeoutMs = 1e4) {
package/lib/index.js CHANGED
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
2
2
  import { createHash, randomBytes, randomUUID } from "node:crypto";
3
3
  import { closeOpenAICodexWebSocketSessions, getOpenAICodexWebSocketDebugStats, resetOpenAICodexWebSocketDebugStats } from "@earendil-works/pi-ai/api/openai-codex-responses";
4
4
  import { execFile, spawn } from "node:child_process";
5
- import { appendFileSync, constants, mkdirSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from "node:fs";
5
+ import { appendFileSync, constants, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
6
6
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
7
7
  import { request } from "node:https";
8
8
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -17,7 +17,7 @@ import { defineTool } from "@deepseek-ai/dsh-tools";
17
17
  import * as dshLlm from "@deepseek-ai/dsh-llm";
18
18
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
19
19
  import * as dshCredentials from "@deepseek-ai/dsh-credentials";
20
- import { hostname } from "node:os";
20
+ import { homedir, hostname } from "node:os";
21
21
  import { dshHomePath, resolveDshHome } from "@deepseek-ai/dsh-home-paths";
22
22
  import { PiAiAdapter } from "@deepseek-ai/dsh-llm-pi-ai";
23
23
  import { openaiCodexProvider as createOpenAICodexProvider } from "@earendil-works/pi-ai/providers/openai-codex";
@@ -85,6 +85,78 @@ function observeAdapter(adapter, provider) {
85
85
  } });
86
86
  }
87
87
  //#endregion
88
+ //#region src/hidden-model-directory.js
89
+ /**
90
+ * Shares the subscription settings' hidden-model list with the host model
91
+ * directory (what other pickers read through `llm.listModels`).
92
+ *
93
+ * `listModels` is also the host's send-time availability check, so a hidden
94
+ * model stays listed while something still depends on it. Only the list is
95
+ * filtered: `resolveModel`, `prepareCall` and `stream` keep resolving against
96
+ * the unfiltered catalog, so an old session on a hidden model keeps working.
97
+ */
98
+ const ids = (models) => models.map((model) => model.id);
99
+ const same = (left, right) => left.length === right.length && left.every((id, index) => id === right[index]);
100
+ /**
101
+ * @param disabled - returns the user's hidden model ids (stale ids are harmless).
102
+ * @param pinned - returns model ids that must stay listed: models of open
103
+ * sessions, the default model, and this plugin's own configured models.
104
+ * @param fallback - returns the default model id, kept when everything is hidden.
105
+ */
106
+ function visibleModels(models, { disabled, pinned = () => [], fallback = () => void 0 }) {
107
+ const hidden = new Set(disabled());
108
+ if (hidden.size === 0) return models;
109
+ const keep = new Set(pinned());
110
+ const visible = models.filter((model) => !hidden.has(model.id) || keep.has(model.id));
111
+ if (visible.length > 0 || models.length === 0) return visible;
112
+ const preferred = fallback();
113
+ return [models.find((model) => model.id === preferred) ?? models[0]];
114
+ }
115
+ function createHiddenModelDirectory({ provider, disabled, pinned, fallback, emit }) {
116
+ const options = {
117
+ disabled,
118
+ pinned: () => {
119
+ try {
120
+ return pinned?.() ?? [];
121
+ } catch {
122
+ return [];
123
+ }
124
+ },
125
+ fallback
126
+ };
127
+ let catalog;
128
+ let emitted;
129
+ const filtered = (models) => visibleModels(models, options);
130
+ const wrap = (adapter) => new Proxy(adapter, { get(target, property) {
131
+ if (property === "listModels") return async (requested, ...rest) => {
132
+ const models = await target.listModels(requested, ...rest);
133
+ if (requested !== provider || !Array.isArray(models)) return models;
134
+ catalog = models;
135
+ const visible = filtered(models);
136
+ emitted = ids(visible);
137
+ return visible;
138
+ };
139
+ const value = Reflect.get(target, property, target);
140
+ return typeof value === "function" ? value.bind(target) : value;
141
+ } });
142
+ return {
143
+ wrap,
144
+ /** The hidden list changed: tell the host to reload its directory. */
145
+ settingsChanged: (value, previous) => {
146
+ if (same([...value ?? []].sort(), [...previous ?? []].sort())) return false;
147
+ emit();
148
+ return true;
149
+ },
150
+ /** Something a hidden model depends on may have changed; emit only if the listed set would differ. */
151
+ dependenciesChanged: () => {
152
+ if (catalog === void 0 || emitted === void 0) return false;
153
+ if (same(ids(filtered(catalog)), emitted)) return false;
154
+ emit();
155
+ return true;
156
+ }
157
+ };
158
+ }
159
+ //#endregion
88
160
  //#region src/default-model.js
89
161
  /**
90
162
  * DSH owns the model a freshly created agent starts on. This module is the
@@ -2413,7 +2485,7 @@ function inheritedOriginalImageRef(session, assetId) {
2413
2485
  }
2414
2486
  //#endregion
2415
2487
  //#region src/version.js
2416
- const PACKAGE_VERSION = "3.1.2";
2488
+ const PACKAGE_VERSION = "3.1.3";
2417
2489
  const USER_AGENT = `dsh-codex-subscription/${PACKAGE_VERSION}`;
2418
2490
  //#endregion
2419
2491
  //#region src/http-failure.js
@@ -4155,6 +4227,26 @@ const TEXTUAL = /* @__PURE__ */ new Set([
4155
4227
  "diff-files",
4156
4228
  "diff-index"
4157
4229
  ]);
4230
+ /**
4231
+ * The phone's folder picker first asks the host for its home folder with one fixed PowerShell line. Nothing is run for it:
4232
+ * when the request is exactly that line, the answer is this machine's home folder.
4233
+ */
4234
+ function homeFolderAnswer(command, home = homedir()) {
4235
+ if (!Array.isArray(command) || command.length !== 5 || command.some((part) => typeof part !== "string")) return void 0;
4236
+ const [exe, ...flags] = command;
4237
+ if (!/^(?:powershell|pwsh)(?:\.exe)?$/iu.test(basename(exe))) return void 0;
4238
+ if (JSON.stringify(flags) !== JSON.stringify([
4239
+ "-NoProfile",
4240
+ "-NonInteractive",
4241
+ "-Command",
4242
+ "(Resolve-Path -LiteralPath $HOME).Path"
4243
+ ])) return void 0;
4244
+ return {
4245
+ exitCode: 0,
4246
+ stdout: `${home}\r\n`,
4247
+ stderr: ""
4248
+ };
4249
+ }
4158
4250
  /** The argv to run for a phone request, or a reason it is refused. */
4159
4251
  function gitArguments(command) {
4160
4252
  if (!Array.isArray(command) || command.length < 2 || command.some((part) => typeof part !== "string" || part.length > 4096 || part.includes("\0"))) return { error: "not a git command" };
@@ -4797,6 +4889,19 @@ function localFolder(value) {
4797
4889
  return;
4798
4890
  }
4799
4891
  }
4892
+ /** Whether two local folders are the same one: real paths compared, separators unified, case ignored on Windows. */
4893
+ function samePath(left, right) {
4894
+ if (typeof left !== "string" || typeof right !== "string" || left === "" || right === "") return false;
4895
+ const normal = (value) => {
4896
+ let resolved = value;
4897
+ try {
4898
+ resolved = realpathSync.native(value);
4899
+ } catch {}
4900
+ resolved = resolved.replace(/\\/gu, "/").replace(/(?<=.)\/+$/u, "");
4901
+ return process.platform === "win32" ? resolved.toLowerCase() : resolved;
4902
+ };
4903
+ return normal(left) === normal(right);
4904
+ }
4800
4905
  /** One image the phone attached, sent inline as a data URL (its own file paths mean nothing on this machine). */
4801
4906
  function dataImage(url) {
4802
4907
  const match = typeof url === "string" ? /^data:(image\/[A-Za-z0-9.+-]+);base64,([A-Za-z0-9+/=\s]+)$/u.exec(url) : null;
@@ -5960,6 +6065,8 @@ function createDshRemoteControl({ controller, agents, permissions = () => void 0
5960
6065
  };
5961
6066
  },
5962
6067
  "command/exec": async (params) => {
6068
+ const home = homeFolderAnswer(params?.command);
6069
+ if (home !== void 0) return home;
5963
6070
  const folders = await conversationFolders();
5964
6071
  try {
5965
6072
  return await runGit(params, { folders });
@@ -6228,7 +6335,16 @@ function createDshRemoteControl({ controller, agents, permissions = () => void 0
6228
6335
  if (params?.ephemeral === true) return titleThread(params);
6229
6336
  const cwd = localFolder(params?.cwd);
6230
6337
  const project = typeof params?.projectId === "string" ? workspaceList().find((entry) => String(entry.id) === params.projectId) : void 0;
6231
- const created = await service().create(project ? { workspaceId: project.id } : cwd ? { cwd } : {});
6338
+ const workspace = !project && cwd ? workspaceList().find((entry) => samePath(entry.path, cwd)) : void 0;
6339
+ let created;
6340
+ if (project) created = await service().create({ workspaceId: project.id });
6341
+ else if (workspace) try {
6342
+ created = await service().create({ workspaceId: workspace.id });
6343
+ } catch (error) {
6344
+ const made = error?.details?.sessionId;
6345
+ created = typeof made === "string" && made !== "" ? { sessionId: made } : await service().create({ cwd });
6346
+ }
6347
+ else created = await service().create(cwd ? { cwd } : {});
6232
6348
  if (typeof params?.threadSource === "string" && params.threadSource !== "") threadSources.set(created.sessionId, params.threadSource.slice(0, 64));
6233
6349
  const agent = await agentFor(created.sessionId);
6234
6350
  const saved = phoneConfig.read();
@@ -12188,7 +12304,32 @@ function apply(ctx, config = {}) {
12188
12304
  auth: adapterAuth,
12189
12305
  resolveAttachments: () => ctx.get?.("attachments")
12190
12306
  });
12191
- ctx.llm.registerAdapter([PROVIDER], observeAdapter(compaction.wrapAdapter(adapter), provider));
12307
+ const hiddenDirectory = createHiddenModelDirectory({
12308
+ provider: PROVIDER,
12309
+ disabled: () => normalizeDisabledModels(settings.get()[DISABLED_MODELS_FIELD]),
12310
+ pinned: () => {
12311
+ const keep = [];
12312
+ try {
12313
+ for (const session of ctx.get?.("sessions")?.list?.() ?? []) {
12314
+ const route = session.requestContext?.();
12315
+ if (route?.provider === PROVIDER && typeof route.model === "string") keep.push(route.model);
12316
+ }
12317
+ } catch {}
12318
+ const selection = defaultModel.status();
12319
+ if (selection.managed) keep.push(selection.model);
12320
+ return keep;
12321
+ },
12322
+ fallback: () => {
12323
+ const selection = defaultModel.status();
12324
+ return selection.managed ? selection.model : void 0;
12325
+ },
12326
+ emit: () => ctx.llm.emitAdaptersUpdated?.()
12327
+ });
12328
+ ctx.effect(() => settings.watch((value, previous) => hiddenDirectory.settingsChanged(normalizeDisabledModels(value[DISABLED_MODELS_FIELD]), normalizeDisabledModels(previous[DISABLED_MODELS_FIELD]))), "codex-subscription: hidden model directory");
12329
+ ctx.effect(() => ctx.on?.("session/event", (_session, event) => {
12330
+ if (event?.type === "request/context") hiddenDirectory.dependenciesChanged();
12331
+ }), "codex-subscription: hidden model dependencies");
12332
+ ctx.llm.registerAdapter([PROVIDER], hiddenDirectory.wrap(observeAdapter(compaction.wrapAdapter(adapter), provider)));
12192
12333
  const currentAgent = () => ctx.get?.("agents")?.currentInitiator?.();
12193
12334
  const servesCurrentModel = () => {
12194
12335
  if (settings.get().otherModels !== "off") return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-codex-subscription",
3
- "version": "3.1.2",
3
+ "version": "3.1.3",
4
4
  "description": "Use ChatGPT and Codex subscriptions in DeepSeek Harness with OAuth, quota, safe resets, web search, images and Fast mode, and control DSH from the ChatGPT mobile app (Beta)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",