dsh-oh-my-claude 1.6.2 → 1.6.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/CHANGELOG.md +13 -0
- package/README.md +3 -2
- package/README.zh.md +3 -2
- package/lib/server/adapter/box-route.d.ts +54 -0
- package/lib/server/adapter/box-route.js +157 -0
- package/lib/server/adapter/box-route.js.map +1 -0
- package/lib/server/adapter/class.d.ts +9 -1
- package/lib/server/adapter/class.js +60 -17
- package/lib/server/adapter/class.js.map +1 -1
- package/lib/server/adapter/routing.d.ts +5 -5
- package/lib/server/adapter/routing.js +3 -2
- package/lib/server/adapter/routing.js.map +1 -1
- package/lib/server/adapter.js +2 -1
- package/lib/server/adapter.js.map +1 -1
- package/lib/server/first-party.d.ts +2 -0
- package/lib/server/first-party.js +1 -1
- package/lib/server/first-party.js.map +1 -1
- package/lib/server/hold.d.ts +2 -2
- package/lib/server/hold.js +3 -5
- package/lib/server/hold.js.map +1 -1
- package/lib/server/plan-gate.d.ts +6 -0
- package/lib/server/plan-gate.js +8 -0
- package/lib/server/plan-gate.js.map +1 -1
- package/lib/server/process.d.ts +22 -3
- package/lib/server/process.js +20 -10
- package/lib/server/process.js.map +1 -1
- package/lib/server/sessions.d.ts +14 -2
- package/lib/server/sessions.js +12 -5
- package/lib/server/sessions.js.map +1 -1
- package/lib/server/translator.js +7 -2
- package/lib/server/translator.js.map +1 -1
- package/package.json +1 -1
- package/src/adapter/box-route.ts +202 -0
- package/src/adapter/class.ts +60 -21
- package/src/adapter/routing.ts +7 -6
- package/src/adapter.ts +2 -1
- package/src/first-party.ts +2 -1
- package/src/hold.ts +4 -3
- package/src/plan-gate.ts +8 -0
- package/src/process.ts +35 -10
- package/src/sessions.ts +22 -13
- package/src/translator.ts +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,19 @@ Versions from 1.0.0 up are on npm. Everything below 1.0.0 was released from the
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.6.3] - 2026-11-12
|
|
10
|
+
|
|
11
|
+
dsh: runs on 0.2.2-alpha.2 through 0.2.2-rc.2; built and tested on 0.2.2-rc.2.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- A router on an ssh box is that box's own. Each box is now asked where its Claude Code sends its requests, so CC Switch on this PC has no say over a box's model menu, and a router on a box gets what a local one gets: its names in the menu with Claude's rows set aside, its turns kept out of the Claude cost totals, the panel login kept from it, and the window set in Settings sent along. A box needs `curl` for the plugin to tell a router from a proxy that forwards to Anthropic.
|
|
16
|
+
- In plan mode Claude can list and read the terminals you run in dsh's side panel, which dsh 0.2.2-rc.2 adds as `user_terminal_list` and `user_terminal_read`. Both only read, so they join the tools plan mode allows. dsh ships the terminal panel in `@deepseek-ai/dsh-experimental-terminal-bundle`, so the two tools exist only on a profile that mounts it.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- `/compact` typed in a Claude session no longer ends with "This turn failed: content.filter is not a function". The compaction itself went through; the line Claude Code writes when it finishes was read as a tool result. Thanks to @huananhuxu-debug (#273)
|
|
21
|
+
|
|
9
22
|
## [1.6.2] - 2026-11-11
|
|
10
23
|
|
|
11
24
|
dsh: runs on 0.2.2-alpha.2 through 0.2.2-rc.1; built and tested on 0.2.2-rc.1.
|
package/README.md
CHANGED
|
@@ -105,7 +105,8 @@ dsh ships prereleases only and moves client APIs between them, so every release
|
|
|
105
105
|
|
|
106
106
|
| Plugin | Runs on dsh | Tested on dsh | npm tag |
|
|
107
107
|
| --- | --- | --- | --- |
|
|
108
|
-
| 1.6.
|
|
108
|
+
| 1.6.3 | 0.2.2-alpha.2 through 0.2.2-rc.2 | 0.2.2-rc.2 | `latest` |
|
|
109
|
+
| 1.6.2 | 0.2.2-alpha.2 through 0.2.2-rc.1 | 0.2.2-rc.1 | none, superseded by 1.6.3 |
|
|
109
110
|
| 1.6.1 | 0.2.2-alpha.2 through 0.2.2-rc.1 | 0.2.2-rc.1 | none, superseded by 1.6.2 |
|
|
110
111
|
| 1.6.0 | 0.2.2-alpha.2 through 0.2.2-rc.1 | 0.2.2-rc.1 | none, superseded by 1.6.1 |
|
|
111
112
|
| 1.5.14 | 0.2.0-rc.1 through 0.2.2-rc.1 | 0.2.2-rc.1 | `dsh-0.2.1`, `dsh-0.2` |
|
|
@@ -129,7 +130,7 @@ dsh ships prereleases only and moves client APIs between them, so every release
|
|
|
129
130
|
|
|
130
131
|
## What you get
|
|
131
132
|
|
|
132
|
-
1. Any Claude model your login can use, in dsh's own picker. Hide the ones you don't use with a switch in Settings, or with `hiddenModels` in the plugin config. Add one the lineup doesn't list, such as a name your local router sends to another model, in the same Settings block or with `customModels`. The menu follows the router: switch one such as CC Switch on and it lists the router's models, switch it off and Claude's are back, with no reload. [Models](https://github.com/lcestou/dsh-oh-my-claude/blob/main/docs/how-it-works.md#models)
|
|
133
|
+
1. Any Claude model your login can use, in dsh's own picker. Hide the ones you don't use with a switch in Settings, or with `hiddenModels` in the plugin config. Add one the lineup doesn't list, such as a name your local router sends to another model, in the same Settings block or with `customModels`. The menu follows the router: switch one such as CC Switch on and it lists the router's models, switch it off and Claude's are back, with no reload. An ssh box follows its own router, not this PC's. [Models](https://github.com/lcestou/dsh-oh-my-claude/blob/main/docs/how-it-works.md#models)
|
|
133
134
|
2. Every dsh session resumes its Claude Code session, tool history included, and a terminal `claude /resume` sees the same one. [Sessions](https://github.com/lcestou/dsh-oh-my-claude/blob/main/docs/how-it-works.md#sessions)
|
|
134
135
|
3. Restart dsh without killing a running Claude turn. [Restarts](https://github.com/lcestou/dsh-oh-my-claude/blob/main/docs/how-it-works.md#restarts)
|
|
135
136
|
4. dsh's access shield sets Claude's six permission modes per session. [Permission mode](https://github.com/lcestou/dsh-oh-my-claude/blob/main/docs/how-it-works.md#permission-mode-per-session)
|
package/README.zh.md
CHANGED
|
@@ -105,7 +105,8 @@ dsh 只发布预发行版,客户端 API 也会在版本之间变动,所以
|
|
|
105
105
|
|
|
106
106
|
| 插件 | 可运行于 dsh | 测试于 dsh | npm 标签 |
|
|
107
107
|
| --- | --- | --- | --- |
|
|
108
|
-
| 1.6.
|
|
108
|
+
| 1.6.3 | 0.2.2-alpha.2 至 0.2.2-rc.2 | 0.2.2-rc.2 | `latest` |
|
|
109
|
+
| 1.6.2 | 0.2.2-alpha.2 至 0.2.2-rc.1 | 0.2.2-rc.1 | 无,已由 1.6.3 取代 |
|
|
109
110
|
| 1.6.1 | 0.2.2-alpha.2 至 0.2.2-rc.1 | 0.2.2-rc.1 | 无,已由 1.6.2 取代 |
|
|
110
111
|
| 1.6.0 | 0.2.2-alpha.2 至 0.2.2-rc.1 | 0.2.2-rc.1 | 无,已由 1.6.1 取代 |
|
|
111
112
|
| 1.5.14 | 0.2.0-rc.1 至 0.2.2-rc.1 | 0.2.2-rc.1 | `dsh-0.2.1`、`dsh-0.2` |
|
|
@@ -129,7 +130,7 @@ dsh 只发布预发行版,客户端 API 也会在版本之间变动,所以
|
|
|
129
130
|
|
|
130
131
|
## 你能得到什么
|
|
131
132
|
|
|
132
|
-
1. 在 dsh 自己的选择器里使用你的登录可用的任何 Claude 模型。用设置里的开关或插件配置的 `hiddenModels` 隐藏不用的模型。在同一处设置里或用 `customModels` 添加列表里没有的模型,例如本地路由转发到其他模型的名称。菜单会跟随路由:打开 CC Switch 这类路由后列出路由提供的模型,关闭后恢复为 Claude 的模型,无需刷新。[Models](https://github.com/lcestou/dsh-oh-my-claude/blob/main/docs/how-it-works.md#models)
|
|
133
|
+
1. 在 dsh 自己的选择器里使用你的登录可用的任何 Claude 模型。用设置里的开关或插件配置的 `hiddenModels` 隐藏不用的模型。在同一处设置里或用 `customModels` 添加列表里没有的模型,例如本地路由转发到其他模型的名称。菜单会跟随路由:打开 CC Switch 这类路由后列出路由提供的模型,关闭后恢复为 Claude 的模型,无需刷新。SSH 机器跟随它自己的路由,而不是这台电脑的。[Models](https://github.com/lcestou/dsh-oh-my-claude/blob/main/docs/how-it-works.md#models)
|
|
133
134
|
2. 每个 dsh 会话都会续接它的 Claude Code 会话(包括工具历史),终端里的 `claude /resume` 看到的是同一个会话。[Sessions](https://github.com/lcestou/dsh-oh-my-claude/blob/main/docs/how-it-works.md#sessions)
|
|
134
135
|
3. 重启 dsh 不会中断正在运行的 Claude 回合。[Restarts](https://github.com/lcestou/dsh-oh-my-claude/blob/main/docs/how-it-works.md#restarts)
|
|
135
136
|
4. dsh 的访问权限盾牌按会话设置 Claude 的六种权限模式。[Permission mode](https://github.com/lcestou/dsh-oh-my-claude/blob/main/docs/how-it-works.md#permission-mode-per-session)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type FirstPartyProbe } from "../first-party.js";
|
|
2
|
+
import { type Route, type RouteEnv } from "./routing.js";
|
|
3
|
+
/** What one box answered. */
|
|
4
|
+
export interface BoxRoute {
|
|
5
|
+
/** The routing variables in force for a `claude` started there over ssh. */
|
|
6
|
+
env: RouteEnv;
|
|
7
|
+
/** The box states a context window of its own (a settings key or either CLI variable), which
|
|
8
|
+
* the plugin must not overrule with one of its own. */
|
|
9
|
+
ownWindow: boolean;
|
|
10
|
+
/** Whether the base URL reaches Anthropic, asked from the box. `undefined` when there is no
|
|
11
|
+
* proxy address to ask, the box has no `curl`, or the endpoint did not answer. */
|
|
12
|
+
answer: FirstPartyProbe;
|
|
13
|
+
}
|
|
14
|
+
/** Runs `script` on `host` and answers its stdout, or `undefined` when the ssh or the script failed. */
|
|
15
|
+
export type BoxRunner = (host: string, script: string) => Promise<string | undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* The script that prints the three layers the far CLI merges, lowest first: the shell's own
|
|
18
|
+
* variables, the user's settings.json, the managed file. Each part ends with a mark, so a
|
|
19
|
+
* missing file is an empty part and a cut-off answer has too few marks to be read.
|
|
20
|
+
*/
|
|
21
|
+
export declare const boxEnvScript: (host: string) => string;
|
|
22
|
+
/** The script that asks `baseUrl` the first-party question from the box: no key, headers kept. */
|
|
23
|
+
export declare const boxProbeScript: (baseUrl: string) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Read `boxEnvScript`'s output. `undefined` when it is not whole (the ssh died halfway), so a
|
|
26
|
+
* half answer is never taken for "no router". A settings file that does not parse counts as
|
|
27
|
+
* silent, as it does for the CLI.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseBoxEnv(out: string): Pick<BoxRoute, "env" | "ownWindow"> | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Read `boxProbeScript`'s output: header blocks, then the body. `undefined` for an empty answer
|
|
32
|
+
* (no `curl`, a refused connection, a timeout), which is "not asked" rather than "not Anthropic".
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseBoxProbe(out: string | undefined): FirstPartyProbe;
|
|
35
|
+
/** Ask `host` both questions now. `undefined` when the box could not be read at all. */
|
|
36
|
+
export declare function askBoxRoute(host: string, run?: BoxRunner): Promise<BoxRoute | undefined>;
|
|
37
|
+
/** The state of a box that answered, by the same rules as this box's own (`routeOf`). The
|
|
38
|
+
* "proxy reaches Anthropic" switch is not applied: it vouches for this box's proxy. */
|
|
39
|
+
export declare const boxRouteState: (box: BoxRoute) => Route;
|
|
40
|
+
/**
|
|
41
|
+
* A box's answer for a caller that can wait: a turn about to start there. A kept answer is
|
|
42
|
+
* returned at once, however old, and refreshed behind the caller once it is past
|
|
43
|
+
* `PROBE_TTL_MS`, so only the first turn after a boot waits on the ssh. A router switched on
|
|
44
|
+
* there is therefore seen by the turn after the next one at the latest.
|
|
45
|
+
*/
|
|
46
|
+
export declare function boxRouteOf(host: string, run?: BoxRunner, now?: number): Promise<BoxRoute | undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* The same for a caller that must not wait: a model listing. Answers what is kept, `undefined`
|
|
49
|
+
* when nothing is, and asks behind the caller when that is missing or old; `changed` is called
|
|
50
|
+
* when the box then says something else, so the caller can list again.
|
|
51
|
+
*/
|
|
52
|
+
export declare function boxRouteKnown(host: string, changed: () => void, run?: BoxRunner, now?: number): BoxRoute | undefined;
|
|
53
|
+
/** Forget every kept answer; tests start from an empty store. */
|
|
54
|
+
export declare const forgetBoxRoutes: () => void;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Where an ssh box's own Claude Code sends its traffic. The box's settings files, its shell and its
|
|
2
|
+
// loopback are not this one's, so both halves of the question are asked there over ssh: which
|
|
3
|
+
// routing variables are in force, and whether the address they name reaches Anthropic.
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { messagesUrl, PROBE_TTL_MS, ProbeBody, readsAsAnthropic, } from "../first-party.js";
|
|
6
|
+
import { managedDir } from "../instructions.js";
|
|
7
|
+
import { shq, sshArgs } from "../process.js";
|
|
8
|
+
import { settingsEnvIn } from "../sessions.js";
|
|
9
|
+
import { proxyBaseUrl } from "./catalog.js";
|
|
10
|
+
import { routeEnvIn, routeOf, routeSignature } from "./routing.js";
|
|
11
|
+
/** The plugin's ssh, with its options and host check (`sshArgs`). Never throws. */
|
|
12
|
+
const sshRun = (host, script) => new Promise((resolve) => {
|
|
13
|
+
try {
|
|
14
|
+
execFile("ssh", sshArgs(host, script), { timeout: 12_000, windowsHide: true }, (e, out) => resolve(e ? undefined : String(out)));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// `sshArgs` refuses a host ssh would read as an option
|
|
18
|
+
resolve(undefined);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const MARK = "<<omc-box-route>>";
|
|
22
|
+
/** The variables read out of the far shell's environment: the ones that route the CLI or size its
|
|
23
|
+
* window. By name, so a key exported there never crosses the wire. */
|
|
24
|
+
const SHELL_VARS = "^(ANTHROPIC_BASE_URL|ANTHROPIC_DEFAULT_[A-Z0-9_]+|CLAUDE_CODE_USE_[A-Z]+|CLAUDE_CODE_AUTO_COMPACT_WINDOW|CLAUDE_CODE_MAX_CONTEXT_TOKENS)=";
|
|
25
|
+
/**
|
|
26
|
+
* The script that prints the three layers the far CLI merges, lowest first: the shell's own
|
|
27
|
+
* variables, the user's settings.json, the managed file. Each part ends with a mark, so a
|
|
28
|
+
* missing file is an empty part and a cut-off answer has too few marks to be read.
|
|
29
|
+
*/
|
|
30
|
+
export const boxEnvScript = (host) => `env | grep -E ${shq(SHELL_VARS)}; printf '\\n%s\\n' ${shq(MARK)}; ` +
|
|
31
|
+
`cat "\${CLAUDE_CONFIG_DIR:-$HOME/.claude}/settings.json" 2>/dev/null; printf '\\n%s\\n' ${shq(MARK)}; ` +
|
|
32
|
+
`cat ${shq(`${managedDir({ sshHost: host })}/managed-settings.json`)} 2>/dev/null; printf '\\n%s\\n' ${shq(MARK)}`;
|
|
33
|
+
/** The script that asks `baseUrl` the first-party question from the box: no key, headers kept. */
|
|
34
|
+
export const boxProbeScript = (baseUrl) => `curl -s -m 4 -D - -X POST -H 'content-type: application/json' -d '{}' ${shq(messagesUrl(baseUrl))}`;
|
|
35
|
+
/**
|
|
36
|
+
* Read `boxEnvScript`'s output. `undefined` when it is not whole (the ssh died halfway), so a
|
|
37
|
+
* half answer is never taken for "no router". A settings file that does not parse counts as
|
|
38
|
+
* silent, as it does for the CLI.
|
|
39
|
+
*/
|
|
40
|
+
export function parseBoxEnv(out) {
|
|
41
|
+
const parts = out.split(`\n${MARK}\n`);
|
|
42
|
+
if (parts.length < 4)
|
|
43
|
+
return undefined;
|
|
44
|
+
const env = {};
|
|
45
|
+
for (const line of (parts[0] ?? "").split("\n")) {
|
|
46
|
+
const at = line.indexOf("=");
|
|
47
|
+
if (at > 0)
|
|
48
|
+
env[line.slice(0, at)] = line.slice(at + 1);
|
|
49
|
+
}
|
|
50
|
+
// The managed file outranks the user's, and both outrank the shell.
|
|
51
|
+
const files = settingsEnvIn([
|
|
52
|
+
{ scope: "managed", text: parts[2] ?? "" },
|
|
53
|
+
{ scope: "user", text: parts[1] ?? "" },
|
|
54
|
+
]);
|
|
55
|
+
Object.assign(env, files.env);
|
|
56
|
+
const ownWindow = files.autoCompactWindow !== undefined ||
|
|
57
|
+
env.CLAUDE_CODE_AUTO_COMPACT_WINDOW !== undefined ||
|
|
58
|
+
env.CLAUDE_CODE_MAX_CONTEXT_TOKENS !== undefined;
|
|
59
|
+
// Only the routing variables are kept: the settings file also holds the router's key.
|
|
60
|
+
return { env: routeEnvIn(env), ownWindow };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Read `boxProbeScript`'s output: header blocks, then the body. `undefined` for an empty answer
|
|
64
|
+
* (no `curl`, a refused connection, a timeout), which is "not asked" rather than "not Anthropic".
|
|
65
|
+
*/
|
|
66
|
+
export function parseBoxProbe(out) {
|
|
67
|
+
if (!out?.startsWith("HTTP/"))
|
|
68
|
+
return undefined;
|
|
69
|
+
let rest = out.replaceAll("\r\n", "\n");
|
|
70
|
+
let requestId = "";
|
|
71
|
+
// More than one block when the endpoint sent an interim status first.
|
|
72
|
+
while (rest.startsWith("HTTP/")) {
|
|
73
|
+
const end = rest.indexOf("\n\n");
|
|
74
|
+
const head = end === -1 ? rest : rest.slice(0, end);
|
|
75
|
+
requestId = /^request-id:\s*(.*)$/im.exec(head)?.[1]?.trim() ?? requestId;
|
|
76
|
+
rest = end === -1 ? "" : rest.slice(end + 2);
|
|
77
|
+
}
|
|
78
|
+
return readsAsAnthropic(probeBody(rest), requestId);
|
|
79
|
+
}
|
|
80
|
+
/** The probe's body, blank when it is not JSON in a shape `ProbeBody` reads: the request id in
|
|
81
|
+
* the header still counts then. */
|
|
82
|
+
function probeBody(text) {
|
|
83
|
+
try {
|
|
84
|
+
return ProbeBody(JSON.parse(text));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return ProbeBody({});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** Ask `host` both questions now. `undefined` when the box could not be read at all. */
|
|
91
|
+
export async function askBoxRoute(host, run = sshRun) {
|
|
92
|
+
const read = parseBoxEnv((await run(host, boxEnvScript(host))) ?? "");
|
|
93
|
+
if (!read)
|
|
94
|
+
return undefined;
|
|
95
|
+
const baseUrl = read.env.cloud ? undefined : proxyBaseUrl(read.env.baseUrl);
|
|
96
|
+
const answer = baseUrl ? parseBoxProbe(await run(host, boxProbeScript(baseUrl))) : undefined;
|
|
97
|
+
return { ...read, answer };
|
|
98
|
+
}
|
|
99
|
+
/** The state of a box that answered, by the same rules as this box's own (`routeOf`). The
|
|
100
|
+
* "proxy reaches Anthropic" switch is not applied: it vouches for this box's proxy. */
|
|
101
|
+
export const boxRouteState = (box) => routeOf(box.env, { forwards: false }, () => box.answer);
|
|
102
|
+
/** One text for "what this box last said", compared to tell a change from a repeat. */
|
|
103
|
+
const signatureOf = (box) => box ? JSON.stringify([routeSignature(box.env), box.ownWindow, box.answer ?? null]) : "";
|
|
104
|
+
/** Kept answers by host, with the request in flight for each. A box that could not be read is
|
|
105
|
+
* kept too, as `undefined`, so an unreachable box is asked once per `PROBE_TTL_MS` and not on
|
|
106
|
+
* every listing. */
|
|
107
|
+
const kept = new Map();
|
|
108
|
+
const asking = new Map();
|
|
109
|
+
/** Ask `host` and keep the answer; callers arriving while it is asked share the one request. */
|
|
110
|
+
function refreshBoxRoute(host, run) {
|
|
111
|
+
const live = asking.get(host);
|
|
112
|
+
if (live)
|
|
113
|
+
return live;
|
|
114
|
+
const asked = askBoxRoute(host, run)
|
|
115
|
+
.catch(() => undefined)
|
|
116
|
+
.then((box) => {
|
|
117
|
+
kept.set(host, { at: Date.now(), box });
|
|
118
|
+
return box;
|
|
119
|
+
})
|
|
120
|
+
.finally(() => asking.delete(host));
|
|
121
|
+
asking.set(host, asked);
|
|
122
|
+
return asked;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A box's answer for a caller that can wait: a turn about to start there. A kept answer is
|
|
126
|
+
* returned at once, however old, and refreshed behind the caller once it is past
|
|
127
|
+
* `PROBE_TTL_MS`, so only the first turn after a boot waits on the ssh. A router switched on
|
|
128
|
+
* there is therefore seen by the turn after the next one at the latest.
|
|
129
|
+
*/
|
|
130
|
+
export async function boxRouteOf(host, run = sshRun, now = Date.now()) {
|
|
131
|
+
const hit = kept.get(host);
|
|
132
|
+
if (!hit)
|
|
133
|
+
return refreshBoxRoute(host, run);
|
|
134
|
+
if (now - hit.at >= PROBE_TTL_MS)
|
|
135
|
+
void refreshBoxRoute(host, run);
|
|
136
|
+
return hit.box;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The same for a caller that must not wait: a model listing. Answers what is kept, `undefined`
|
|
140
|
+
* when nothing is, and asks behind the caller when that is missing or old; `changed` is called
|
|
141
|
+
* when the box then says something else, so the caller can list again.
|
|
142
|
+
*/
|
|
143
|
+
export function boxRouteKnown(host, changed, run = sshRun, now = Date.now()) {
|
|
144
|
+
const hit = kept.get(host);
|
|
145
|
+
if (hit && now - hit.at < PROBE_TTL_MS)
|
|
146
|
+
return hit.box;
|
|
147
|
+
void refreshBoxRoute(host, run).then((box) => {
|
|
148
|
+
if (signatureOf(box) !== signatureOf(hit?.box))
|
|
149
|
+
changed();
|
|
150
|
+
});
|
|
151
|
+
return hit?.box;
|
|
152
|
+
}
|
|
153
|
+
/** Forget every kept answer; tests start from an empty store. */
|
|
154
|
+
export const forgetBoxRoutes = () => {
|
|
155
|
+
kept.clear();
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=box-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box-route.js","sourceRoot":"","sources":["../../../src/adapter/box-route.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,8FAA8F;AAC9F,uFAAuF;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAEL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,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AAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QAC3C,IAAI,WAAW,CAAC,GAAG,CAAC,KAAK,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC;YAAE,OAAO,EAAE,CAAC;IAC5D,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,EAAE,GAAG,CAAC;AAClB,CAAC;AAED,iEAAiE;AACjE,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE;IAClC,IAAI,CAAC,KAAK,EAAE,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -163,7 +163,8 @@ export declare class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
163
163
|
* The environment the CLI of this mount runs with, as far as this process can know it: dsh's
|
|
164
164
|
* own, then the `env` of the mount's settings.json, then the managed file's, each outranking
|
|
165
165
|
* the one before as it does for the CLI (measured on 2.1.322: a base URL in settings.json wins
|
|
166
|
-
* over an exported one). Empty for an ssh box, whose files and shell are not this one's
|
|
166
|
+
* over an exported one). Empty for an ssh box, whose files and shell are not this one's: its
|
|
167
|
+
* routing is asked on the box instead (`box-route.ts`).
|
|
167
168
|
* Without `cwd` it is the mount's own answer, which is what the listing follows, since a
|
|
168
169
|
* model menu is per mount. With `cwd` the workspace's project and local settings files are
|
|
169
170
|
* merged in as well, which is what a turn there really runs with: a workspace file outranks
|
|
@@ -226,6 +227,10 @@ export declare class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
226
227
|
* it here would overrule that choice.
|
|
227
228
|
*/
|
|
228
229
|
private sizedWindow;
|
|
230
|
+
/** The window this mount's row for `model` states, when it is one the plugin sized (a
|
|
231
|
+
* router's alias, an added model with a size), else undefined. The allowlist and the "replace
|
|
232
|
+
* the built-in rows" switch are left out: a session on a model they hide still has its row. */
|
|
233
|
+
private rowWindow;
|
|
229
234
|
/** What a listing is filtered by: the state, and this mount's "also list Claude's own models"
|
|
230
235
|
* switch (`routedClaude:<provider>` in the hints store). */
|
|
231
236
|
private routeFilter;
|
|
@@ -1004,6 +1009,9 @@ export declare class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
1004
1009
|
* keeps its own login, which is what a second instance is for.
|
|
1005
1010
|
*/
|
|
1006
1011
|
localEnvOverride(firstParty?: boolean, window?: number, routed?: boolean): Record<string, string> | undefined;
|
|
1012
|
+
/** What a `claude` started on `host` is handed: the box's panel login, withheld from a turn
|
|
1013
|
+
* proven to go to a router there (as `localEnvOverride` does here), and the spec's window. */
|
|
1014
|
+
private farEnv;
|
|
1007
1015
|
/** The child env a keeper hands Claude: dsh's environment plus the plugin's additions. */
|
|
1008
1016
|
keeperEnv(firstParty?: boolean, window?: number, routed?: boolean): Record<string, string>;
|
|
1009
1017
|
/** Spawner for one session: keeper mode needs the session to place and name the keeper. A spec
|
|
@@ -7,6 +7,7 @@ import { watch } from "node:fs";
|
|
|
7
7
|
import { dirname } from "node:path";
|
|
8
8
|
import { hostname, tmpdir } from "node:os";
|
|
9
9
|
import { basename, join } from "node:path";
|
|
10
|
+
import { boxRouteKnown, boxRouteOf, boxRouteState } from "./box-route.js";
|
|
10
11
|
import { numberOf } from "../plugins.js";
|
|
11
12
|
import { LlmAdapter, LlmError, createToolResultMessage, createUserMessage, } from "@deepseek-ai/dsh-llm";
|
|
12
13
|
import { repairStoredTurns } from "../turn-repair.js";
|
|
@@ -470,7 +471,8 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
470
471
|
* The environment the CLI of this mount runs with, as far as this process can know it: dsh's
|
|
471
472
|
* own, then the `env` of the mount's settings.json, then the managed file's, each outranking
|
|
472
473
|
* the one before as it does for the CLI (measured on 2.1.322: a base URL in settings.json wins
|
|
473
|
-
* over an exported one). Empty for an ssh box, whose files and shell are not this one's
|
|
474
|
+
* over an exported one). Empty for an ssh box, whose files and shell are not this one's: its
|
|
475
|
+
* routing is asked on the box instead (`box-route.ts`).
|
|
474
476
|
* Without `cwd` it is the mount's own answer, which is what the listing follows, since a
|
|
475
477
|
* model menu is per mount. With `cwd` the workspace's project and local settings files are
|
|
476
478
|
* merged in as well, which is what a turn there really runs with: a workspace file outranks
|
|
@@ -571,17 +573,21 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
571
573
|
* in the constructor because dsh builds adapters it never lists from.
|
|
572
574
|
*/
|
|
573
575
|
async route() {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
// changing is not an event in the directory that holds the link.
|
|
580
|
-
for (const dir of [this.realClaudeHome, managedDir()])
|
|
581
|
-
watchSettingsIn(dir, this.providerId, () => void this.settingsMoved());
|
|
576
|
+
// An ssh box answers for itself (`box-route.ts`), and is `unknown` until it has: its files
|
|
577
|
+
// cannot be watched from here, so its answer is asked again as it ages instead.
|
|
578
|
+
if (this.config.sshHost) {
|
|
579
|
+
const box = boxRouteKnown(this.config.sshHost, () => void this.routeChanged());
|
|
580
|
+
return box ? boxRouteState(box) : { state: "unknown" };
|
|
582
581
|
}
|
|
582
|
+
const env = routeEnvIn(await this.claudeEnv());
|
|
583
|
+
if (this.routeSeen === undefined)
|
|
584
|
+
void this.routeFirstSeen(routeSignature(env)).catch(() => { });
|
|
585
|
+
// The real home: with the mirror on, `claudeHome` holds links, and a link's target
|
|
586
|
+
// changing is not an event in the directory that holds the link.
|
|
587
|
+
for (const dir of [this.realClaudeHome, managedDir()])
|
|
588
|
+
watchSettingsIn(dir, this.providerId, () => void this.settingsMoved());
|
|
583
589
|
const hints = await readHints(join(STATE_DIR, "hints.json"));
|
|
584
|
-
return routeOf(env, {
|
|
590
|
+
return routeOf(env, { forwards: firstPartyMode(hints) === "on" }, (baseUrl) => firstPartyKnown(baseUrl, () => void this.routeChanged()));
|
|
585
591
|
}
|
|
586
592
|
/**
|
|
587
593
|
* The name of `model` when only a router can answer for it and this mount is talking to
|
|
@@ -618,6 +624,14 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
618
624
|
env.CLAUDE_CODE_AUTO_COMPACT_WINDOW !== undefined ||
|
|
619
625
|
env.CLAUDE_CODE_MAX_CONTEXT_TOKENS !== undefined)
|
|
620
626
|
return undefined;
|
|
627
|
+
return this.rowWindow(model);
|
|
628
|
+
}
|
|
629
|
+
/** The window this mount's row for `model` states, when it is one the plugin sized (a
|
|
630
|
+
* router's alias, an added model with a size), else undefined. The allowlist and the "replace
|
|
631
|
+
* the built-in rows" switch are left out: a session on a model they hide still has its row. */
|
|
632
|
+
async rowWindow(model) {
|
|
633
|
+
if (!model)
|
|
634
|
+
return undefined;
|
|
621
635
|
const picker = await this.pickerSettings();
|
|
622
636
|
const rows = picker && { ...picker, availableModels: undefined, replaceBuiltInOptions: false };
|
|
623
637
|
const row = (await catalogNow(this.cliModels, rows)).find((m) => m.id === model);
|
|
@@ -660,8 +674,16 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
660
674
|
async pickerSettings() {
|
|
661
675
|
const fromFile = await readPickerSettings(join(this.claudeHome, "settings.json"));
|
|
662
676
|
// The alias names from every layer of the mount's env: they work exported in the shell dsh
|
|
663
|
-
// started from and in the managed file as well as in settings.json.
|
|
664
|
-
|
|
677
|
+
// started from and in the managed file as well as in settings.json. An ssh box's are its
|
|
678
|
+
// own, as it last answered, and the ones in this box's file name this box's router.
|
|
679
|
+
const far = this.config.sshHost
|
|
680
|
+
? boxRouteKnown(this.config.sshHost, () => void this.routeChanged())
|
|
681
|
+
: undefined;
|
|
682
|
+
if (this.config.sshHost && fromFile)
|
|
683
|
+
delete fromFile.aliasNames;
|
|
684
|
+
const { aliasNames, aliasModels } = this.config.sshHost
|
|
685
|
+
? (far?.env ?? { aliasNames: {}, aliasModels: {} })
|
|
686
|
+
: routeEnvIn(await this.claudeEnv());
|
|
665
687
|
const named = Object.keys(aliasNames).length + Object.keys(aliasModels).length === 0
|
|
666
688
|
? fromFile
|
|
667
689
|
: {
|
|
@@ -1167,6 +1189,12 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
1167
1189
|
via = routedTo;
|
|
1168
1190
|
}
|
|
1169
1191
|
}
|
|
1192
|
+
// A turn on a box is tagged by that box's own answer: its settings and its loopback, asked
|
|
1193
|
+
// there. A box that could not be read, or whose endpoint did not answer, tags nothing.
|
|
1194
|
+
const far = targetHost === undefined ? undefined : await boxRouteOf(targetHost);
|
|
1195
|
+
const farRoute = far && boxRouteState(far);
|
|
1196
|
+
if (farRoute?.state === "routed")
|
|
1197
|
+
via = farRoute.host;
|
|
1170
1198
|
const turns = selectTurns(options.messages, session?.resuming ?? false, this.providerId);
|
|
1171
1199
|
let prompt = buildPrompt(turns, drops);
|
|
1172
1200
|
// A turn on a box reads that box's disk, so what was attached here follows it there.
|
|
@@ -1244,11 +1272,18 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
1244
1272
|
!this.config.sshHost &&
|
|
1245
1273
|
!remoteWorkspaceFor(cwd))
|
|
1246
1274
|
spec.route = inForce;
|
|
1247
|
-
//
|
|
1275
|
+
// On a box it is what keeps the panel login out of a router's hands there (`farEnv`).
|
|
1248
1276
|
if (via !== undefined)
|
|
1249
1277
|
spec.routed = true;
|
|
1250
1278
|
// And for a window the plugin or the user has to state: see `ClaudeProcessSpec.window`.
|
|
1251
|
-
|
|
1279
|
+
// On an ssh box's own mount the rows are that box's, so its window rides there too, unless
|
|
1280
|
+
// the box states one itself. Not for a remote workspace under this box's mount, whose rows
|
|
1281
|
+
// are this box's and say nothing about the far model.
|
|
1282
|
+
let sized;
|
|
1283
|
+
if (here !== undefined)
|
|
1284
|
+
sized = await this.sizedWindow(model, here);
|
|
1285
|
+
else if (this.config.sshHost && far && !far.ownWindow)
|
|
1286
|
+
sized = await this.rowWindow(model);
|
|
1252
1287
|
if (sized !== undefined)
|
|
1253
1288
|
spec.window = sized;
|
|
1254
1289
|
// Keeper or child joins the spec the same way: a flip of the Settings switch replaces each
|
|
@@ -3340,6 +3375,11 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
3340
3375
|
}
|
|
3341
3376
|
return Object.keys(over).length === 0 ? undefined : over;
|
|
3342
3377
|
}
|
|
3378
|
+
/** What a `claude` started on `host` is handed: the box's panel login, withheld from a turn
|
|
3379
|
+
* proven to go to a router there (as `localEnvOverride` does here), and the spec's window. */
|
|
3380
|
+
farEnv(host, routed, window) {
|
|
3381
|
+
return { token: routed ? undefined : readSshToken(STATE_DIR, host), window };
|
|
3382
|
+
}
|
|
3343
3383
|
/** The child env a keeper hands Claude: dsh's environment plus the plugin's additions. */
|
|
3344
3384
|
keeperEnv(firstParty, window, routed) {
|
|
3345
3385
|
return childEnv(process.env, this.localEnvOverride(firstParty, window, routed));
|
|
@@ -3401,7 +3441,7 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
3401
3441
|
if (this.keeperOwner)
|
|
3402
3442
|
record.owner = this.keeperOwner;
|
|
3403
3443
|
const started = new Promise((resolve, reject) => {
|
|
3404
|
-
const s = run(holdStartScript(holdId, cwd, command, args,
|
|
3444
|
+
const s = run(holdStartScript(holdId, cwd, command, args, this.farEnv(host, spec.routed, spec.window)));
|
|
3405
3445
|
let out = "";
|
|
3406
3446
|
let err = "";
|
|
3407
3447
|
s.stdin.end();
|
|
@@ -3672,7 +3712,7 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
3672
3712
|
// A remote-workspace cwd is a local placeholder here; redirect it to the box's real path.
|
|
3673
3713
|
if (this.config.sshHost) {
|
|
3674
3714
|
const host = this.config.sshHost;
|
|
3675
|
-
return sshSpawner(host, (cwd) => remoteCwdFor(host, cwd),
|
|
3715
|
+
return sshSpawner(host, (cwd) => remoteCwdFor(host, cwd), this.farEnv(host, routed, window));
|
|
3676
3716
|
}
|
|
3677
3717
|
const base = child === "dsh" && this.subprocess ? seamSpawner(this.subprocess) : nodeSpawner;
|
|
3678
3718
|
if (child === "dsh" && !this.subprocess && !this.warnedNoSeam) {
|
|
@@ -3686,7 +3726,7 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
3686
3726
|
return (command, args, cwd) => {
|
|
3687
3727
|
const ws = remoteWorkspaceFor(cwd);
|
|
3688
3728
|
if (ws)
|
|
3689
|
-
return sshSpawner(ws.host, () => ws.remoteCwd,
|
|
3729
|
+
return sshSpawner(ws.host, () => ws.remoteCwd, this.farEnv(ws.host, routed, window))(
|
|
3690
3730
|
// The far box's own binary, by the configured name: see `commandFor`.
|
|
3691
3731
|
this.configuredCommand, args, cwd);
|
|
3692
3732
|
return local(command, args, cwd);
|
|
@@ -5248,8 +5288,11 @@ export class ClaudeCodeAdapter extends LlmAdapter {
|
|
|
5248
5288
|
// only once the whole batch has answered. A park on the first of two results closed the
|
|
5249
5289
|
// slower call with a placeholder row, left a dsh call of the same message to run without
|
|
5250
5290
|
// its card, and a nested agent's inner result parked the step under the agent itself.
|
|
5291
|
+
// Nor at a user frame of the CLI's own text (a slash command's output, a compaction
|
|
5292
|
+
// summary): it is no tool result, so nothing has been handed the steer.
|
|
5251
5293
|
if (proc.steerPending &&
|
|
5252
5294
|
event.type === "user" &&
|
|
5295
|
+
Array.isArray(event.message?.content) &&
|
|
5253
5296
|
pending.size === 0 &&
|
|
5254
5297
|
!relaying &&
|
|
5255
5298
|
!tr.callsOutstanding()) {
|