dsh-open-in-dsh 0.3.4 → 0.3.5
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 +11 -6
- package/client/globals.d.ts +1 -0
- package/client/index.ts +50 -6
- package/cordis.patch.yml +5 -3
- package/lib/client.js +25 -6
- package/lib/index.js +82 -22
- package/lib/types/index.d.ts +48 -28
- package/lib/types/types.d.ts +41 -0
- package/lib/types.js +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -100,6 +100,10 @@ bundle 自带的 `cordis.patch.yml` 只是默认值;覆盖写在 profile 的 `
|
|
|
100
100
|
|
|
101
101
|
`Config` schema 的作用是让这一行的 `config` 在加载时被校验并补上默认值,并让 `Config.listConfigs` 读得到键名;它不会长出一个可编辑表单。「设置 → 插件」是只读清单,开关插件请用侧边栏「插件」页。
|
|
102
102
|
|
|
103
|
+
`alwaysNewSession` 是**实时**字段:Config 里标了 `.volatile()`,内核把它作为 synced config 交给浏览器半边,页面在每次打开文件夹时现读当前值。所以改这个值**不用重启宿主、也不用刷新页面**——保存后下一次右键就按新值走;页面已经开着也一样,因为引用是原地更新的。
|
|
104
|
+
|
|
105
|
+
其余字段是挂载时读一次的部署参数(总开关、回环策略、补收窗口、套接字路径)。改它们要重挂这一行:路由与套接字跟着重建,不会靠一次原地更新假装生效。
|
|
106
|
+
|
|
103
107
|
## 工作方式
|
|
104
108
|
|
|
105
109
|
### Windows
|
|
@@ -110,7 +114,7 @@ bundle 自带的 `cordis.patch.yml` 只是默认值;覆盖写在 profile 的 `
|
|
|
110
114
|
|---|---|---|
|
|
111
115
|
| 1 | 菜单动词 | `open-in-dsh.vbs` 用环境变量把 `%V` 交给 `open-in-dsh.ps1`,后者解析端口/应用并 POST 到 `127.0.0.1:<port>/dsh-open-in-dsh/api/v1/open`;没人应答就先把桌面版启动起来再重投 |
|
|
112
116
|
| 2 | 宿主半边 | 校验路径(必须存在且是目录、只接受回环来源),入队并广播 |
|
|
113
|
-
| 3 | 页面 | 通过 SSE
|
|
117
|
+
| 3 | 页面 | 通过 SSE 收到请求,按 synced config 里 `alwaysNewSession` 的当前值分流:`false` 时走 `workspaces.create({ path })` + `uiWorkspace.openWorkspace(id)`;`true` 时走 `workspaces.create({ path })` + `sessions.create({ workspaceId })` + `uiWorkspace.openSession(id)` |
|
|
114
118
|
| 4 | 启动器 | 桌面版:再启动一次应用把窗口提到最前(单实例锁 → `second-instance` → 聚焦);`dsh web`:没人跟随时打开浏览器 URL |
|
|
115
119
|
|
|
116
120
|
动词指向 `wscript.exe` 而不是 PowerShell,路径通过进程环境变量传:GUI 子系统的 wscript 不会创建控制台窗口,因此右键不会闪窗;`%V` 里的空格、单引号、盘符根目录的结尾反斜杠也不经过引号转义。
|
|
@@ -168,7 +172,8 @@ Chrome 会把后台页面的定时器节流到每分钟一次,而刚点完右
|
|
|
168
172
|
- 只注册了「文件夹」和「文件夹空白处」。右键盘符(如 `D:\`)需要再注册 `Drive\shell\DSHOpen`,路径规范化已支持盘符根目录。
|
|
169
173
|
- 桌面版提窗口靠「再启动一次应用」(每次多一个立即退出的短进程)。能不能真的抢到前台取决于 Windows 的前台权限策略;应用没开时走冷启动,窗口必然起来。
|
|
170
174
|
- 桌面版登录页出现时页面还没跑起来:请求会待在回放窗口里,登录进去、页面加载后才落地,超过 `backlogTtlMs` 就过期,需要重按一次。
|
|
171
|
-
-
|
|
175
|
+
- 宿主半边改代码要重启宿主才生效;桌面版必须整个退出再打开。配置里的 `alwaysNewSession` 是例外(实时字段,保存即生效);其余配置字段改完由内核重载这一行。
|
|
176
|
+
- 内核 0.2.2-rc.3 之前没有 synced config:浏览器半边 `apply` 收不到这行配置,`alwaysNewSession: true` 会退回默认(复用空白会话)。要这个开关就升级内核。
|
|
172
177
|
- macOS:快速操作在子菜单里,不是顶层条目(顶层需要 Finder Sync 扩展 + Xcode 工程 + 签名);右键文件夹空白处没有入口(服务总要有选中项);移动 checkout 后启动器绝对路径会失效,重跑一次 `install-macos.sh install`——`status` 会打印 `STALE` 并以非 0 退出。
|
|
173
178
|
- 宿主重启后插件重新绑定套接字/路由;套接字不在时启动器明确报错并写日志,不会假装成功。
|
|
174
179
|
- Windows 桌面版的端口**每次启动都变**(桌面壳用 --port 0)。动词里存的是 0,启动器每次现场发现:从 DSH 进程的 loopback 连接反推端口,再用 /dsh-open-in-dsh/api/v1/status 确认(这版 Windows 上监听套接字不在
|
|
@@ -177,17 +182,17 @@ etstat 表里,所以只能靠连接反推)。发现失败会回落到 19387
|
|
|
177
182
|
## 验证(开发)
|
|
178
183
|
|
|
179
184
|
```sh
|
|
180
|
-
npm test #
|
|
185
|
+
npm test # 89 个测试(含客户端构建与语法检查)
|
|
181
186
|
node --test test/macos.test.ts # macOS 启动器/安装器 17 个测试
|
|
182
187
|
```
|
|
183
188
|
|
|
184
|
-
`npm test` 覆盖宿主路由与回放、`%V` 的各种形态、脚本镜像(路由路径/端口/`-Probe`
|
|
189
|
+
`npm test` 覆盖宿主路由与回放、`%V` 的各种形态、脚本镜像(路由路径/端口/`-Probe` 一致)、白名单与「打开方式」策略、会话定位、synced config 的实时读取,以及真实 `node:http` 上的集成路由(含跨域拒绝)。
|
|
185
190
|
|
|
186
191
|
## 兼容性
|
|
187
192
|
|
|
188
|
-
- **DSH**:`engines.dsh: ^0.2.1-rc.2 || ^0.2.2-alpha.2`;Node.js `>=24`。
|
|
193
|
+
- **DSH**:`engines.dsh: ^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1`;Node.js `>=24`。
|
|
189
194
|
- **会话存储**:宿主半边通过 `dsh-session-ops/store` 读会话头(peer 依赖,`dsh-session-ops >= 0.1.0`),与 `dsh-session-ops` 共用同一份存储格式。
|
|
190
|
-
-
|
|
195
|
+
- 本插件运行时不 import 任何内核包,只使用内核提供的服务(`webServer`、`workspaces`、`sessions`、`uiWorkspace`、客户端模块系统);类型层面只 `import type` 了 `@deepseek-ai/cordis` 的 `Volatile`(编译器会擦掉)。接口变化时最坏结果是某个入口失效,不会影响 DSH 本身。
|
|
191
196
|
- DSH 侧「打开方式」菜单依赖内核的 `@deepseek-ai/dsh-client-ui-context-menu` 客户端包。
|
|
192
197
|
|
|
193
198
|
## License
|
package/client/globals.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ interface DshOpenInDebug {
|
|
|
27
27
|
/** A snapshot of the stream state, for `console.log(__dshOpenIn.status())`. */
|
|
28
28
|
status: () => {
|
|
29
29
|
lastSeq: number
|
|
30
|
+
/** The live synced setting: read from the Host reference on each call. */
|
|
30
31
|
settings: { alwaysNewSession: boolean }
|
|
31
32
|
uiWorkspace: boolean
|
|
32
33
|
readyState: number | null
|
package/client/index.ts
CHANGED
|
@@ -37,6 +37,30 @@ function parseFrame(text) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* One field of this plugin's Host config, as the kernel syncs it.
|
|
42
|
+
*
|
|
43
|
+
* Mirrors `SyncedConfigRef<T>` from `@deepseek-ai/dsh-client-config/types`
|
|
44
|
+
* without importing it: the browser half is spliced into a classic script by
|
|
45
|
+
* `scripts/build-client.mts` and carries no package dependency of its own. A
|
|
46
|
+
* field can read `undefined` — the Host may keep a value it cannot project, or
|
|
47
|
+
* run a build from before this code — so every read handles absence.
|
|
48
|
+
*/
|
|
49
|
+
interface SyncedConfigRef<T> {
|
|
50
|
+
get(): T | undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* This plugin's top-level volatile Config fields, as `apply` receives them.
|
|
55
|
+
*
|
|
56
|
+
* Mirrors `SyncedConfig<OpenInDshConfig>`. Only `alwaysNewSession` is volatile:
|
|
57
|
+
* the Host reads it out of the graph row into a reference, and a later config
|
|
58
|
+
* write updates that reference in place while the page stays loaded.
|
|
59
|
+
*/
|
|
60
|
+
interface SyncedConfig {
|
|
61
|
+
alwaysNewSession?: SyncedConfigRef<boolean>
|
|
62
|
+
}
|
|
63
|
+
|
|
40
64
|
/** Dictionary namespace owned by this plugin. */
|
|
41
65
|
const NS = 'dsh-open-in-dsh'
|
|
42
66
|
|
|
@@ -401,12 +425,29 @@ function createPlugin(require) {
|
|
|
401
425
|
}
|
|
402
426
|
}
|
|
403
427
|
|
|
428
|
+
/**
|
|
429
|
+
* Whether a request should land in a brand-new Session.
|
|
430
|
+
*
|
|
431
|
+
* Read at the moment of use, never captured: the Host commits a config write
|
|
432
|
+
* into the synced reference in place, and the plugin is not remounted for it,
|
|
433
|
+
* so a value read once at mount would stay stale for the life of the page.
|
|
434
|
+
* Absent means the shipped default (`false`: reuse the Workspace's blank
|
|
435
|
+
* Session).
|
|
436
|
+
*
|
|
437
|
+
* @param config - the synced Config `apply` received.
|
|
438
|
+
* @returns true when every announced folder opens in a new blank Session.
|
|
439
|
+
*/
|
|
440
|
+
function readAlwaysNewSession(config: SyncedConfig): boolean {
|
|
441
|
+
return config.alwaysNewSession?.get() === true
|
|
442
|
+
}
|
|
443
|
+
|
|
404
444
|
/**
|
|
405
445
|
* Mount the plugin.
|
|
406
446
|
* @param ctx - browser plugin context, with `workspaces` and `sessions`.
|
|
447
|
+
* @param config - the Host's synced volatile Config, handed over by the
|
|
448
|
+
* kernel (empty object when the row has none).
|
|
407
449
|
*/
|
|
408
|
-
function apply(ctx) {
|
|
409
|
-
const settings = { alwaysNewSession: true }
|
|
450
|
+
function apply(ctx, config: SyncedConfig = {}) {
|
|
410
451
|
let lastSeq = readSeq()
|
|
411
452
|
let source = null
|
|
412
453
|
let uiWorkspace = null
|
|
@@ -608,7 +649,9 @@ function createPlugin(require) {
|
|
|
608
649
|
const openFolder = async (path) => {
|
|
609
650
|
const workspace = await ctx.workspaces.create({ path })
|
|
610
651
|
|
|
611
|
-
|
|
652
|
+
// Read after the Workspace await: a config write may arrive while this
|
|
653
|
+
// request is in flight, and the newest value is the one the user expects.
|
|
654
|
+
if (!readAlwaysNewSession(config)) {
|
|
612
655
|
if (uiWorkspace !== null) await uiWorkspace.openWorkspace(workspace.workspaceId)
|
|
613
656
|
return
|
|
614
657
|
}
|
|
@@ -655,8 +698,8 @@ function createPlugin(require) {
|
|
|
655
698
|
source.addEventListener('hello', (event) => {
|
|
656
699
|
const payload = parseFrame(event.data)
|
|
657
700
|
if (payload === null) return
|
|
658
|
-
|
|
659
|
-
|
|
701
|
+
// Config is not carried by the frame: the synced reference is already
|
|
702
|
+
// live. `hello` only reports the sequence.
|
|
660
703
|
if (Number.isInteger(payload.seq) && payload.seq < lastSeq) {
|
|
661
704
|
lastSeq = 0
|
|
662
705
|
writeSeq(0)
|
|
@@ -681,7 +724,8 @@ function createPlugin(require) {
|
|
|
681
724
|
openWith: launch,
|
|
682
725
|
status: () => ({
|
|
683
726
|
lastSeq,
|
|
684
|
-
|
|
727
|
+
// Read live, like every other consumer of the synced field.
|
|
728
|
+
settings: { alwaysNewSession: readAlwaysNewSession(config) },
|
|
685
729
|
uiWorkspace: uiWorkspace !== null,
|
|
686
730
|
readyState: source === null ? null : source.readyState,
|
|
687
731
|
}),
|
package/cordis.patch.yml
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
# package.json declares `dsh.client.platform: web` is mounted in the Client
|
|
5
5
|
# tree by the same entry, so the Client half never needs its own row.
|
|
6
6
|
#
|
|
7
|
-
# `alwaysNewSession` is
|
|
8
|
-
#
|
|
9
|
-
#
|
|
7
|
+
# `alwaysNewSession` is declared `.volatile()` in the Host schema, so the kernel
|
|
8
|
+
# projects it into this row's graph data and hands the browser half the live
|
|
9
|
+
# reference in `apply(ctx, config)` (a `SyncedConfig`). A write reaches the
|
|
10
|
+
# loaded page in place — no host restart, no page reload, and no second copy of
|
|
11
|
+
# the value travelling over the plugin's own SSE stream.
|
|
10
12
|
- insert:
|
|
11
13
|
- id: open-in-dsh
|
|
12
14
|
name: dsh-open-in-dsh
|
package/lib/client.js
CHANGED
|
@@ -407,12 +407,28 @@ window.__ModuleLoader__.load({
|
|
|
407
407
|
// Nothing to do; the folder is open either way.
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Whether a request should land in a brand-new Session.
|
|
412
|
+
*
|
|
413
|
+
* Read at the moment of use, never captured: the Host commits a config write
|
|
414
|
+
* into the synced reference in place, and the plugin is not remounted for it,
|
|
415
|
+
* so a value read once at mount would stay stale for the life of the page.
|
|
416
|
+
* Absent means the shipped default (`false`: reuse the Workspace's blank
|
|
417
|
+
* Session).
|
|
418
|
+
*
|
|
419
|
+
* @param config - the synced Config `apply` received.
|
|
420
|
+
* @returns true when every announced folder opens in a new blank Session.
|
|
421
|
+
*/
|
|
422
|
+
function readAlwaysNewSession(config) {
|
|
423
|
+
return config.alwaysNewSession?.get() === true;
|
|
424
|
+
}
|
|
410
425
|
/**
|
|
411
426
|
* Mount the plugin.
|
|
412
427
|
* @param ctx - browser plugin context, with `workspaces` and `sessions`.
|
|
428
|
+
* @param config - the Host's synced volatile Config, handed over by the
|
|
429
|
+
* kernel (empty object when the row has none).
|
|
413
430
|
*/
|
|
414
|
-
function apply(ctx) {
|
|
415
|
-
const settings = { alwaysNewSession: true };
|
|
431
|
+
function apply(ctx, config = {}) {
|
|
416
432
|
let lastSeq = readSeq();
|
|
417
433
|
let source = null;
|
|
418
434
|
let uiWorkspace = null;
|
|
@@ -593,7 +609,9 @@ window.__ModuleLoader__.load({
|
|
|
593
609
|
*/
|
|
594
610
|
const openFolder = async (path) => {
|
|
595
611
|
const workspace = await ctx.workspaces.create({ path });
|
|
596
|
-
|
|
612
|
+
// Read after the Workspace await: a config write may arrive while this
|
|
613
|
+
// request is in flight, and the newest value is the one the user expects.
|
|
614
|
+
if (!readAlwaysNewSession(config)) {
|
|
597
615
|
if (uiWorkspace !== null)
|
|
598
616
|
await uiWorkspace.openWorkspace(workspace.workspaceId);
|
|
599
617
|
return;
|
|
@@ -642,8 +660,8 @@ window.__ModuleLoader__.load({
|
|
|
642
660
|
const payload = parseFrame(event.data);
|
|
643
661
|
if (payload === null)
|
|
644
662
|
return;
|
|
645
|
-
|
|
646
|
-
|
|
663
|
+
// Config is not carried by the frame: the synced reference is already
|
|
664
|
+
// live. `hello` only reports the sequence.
|
|
647
665
|
if (Number.isInteger(payload.seq) && payload.seq < lastSeq) {
|
|
648
666
|
lastSeq = 0;
|
|
649
667
|
writeSeq(0);
|
|
@@ -665,7 +683,8 @@ window.__ModuleLoader__.load({
|
|
|
665
683
|
openWith: launch,
|
|
666
684
|
status: () => ({
|
|
667
685
|
lastSeq,
|
|
668
|
-
|
|
686
|
+
// Read live, like every other consumer of the synced field.
|
|
687
|
+
settings: { alwaysNewSession: readAlwaysNewSession(config) },
|
|
669
688
|
uiWorkspace: uiWorkspace !== null,
|
|
670
689
|
readyState: source === null ? null : source.readyState,
|
|
671
690
|
}),
|
package/lib/index.js
CHANGED
|
@@ -62,21 +62,31 @@ export const DEFAULT_SOCKET_PATH = join(homedir(), '.dsh', 'run', 'dsh-open-in-d
|
|
|
62
62
|
* 默认值、profile 补丁层的覆盖、`$DSH_HOME/settings.yaml` 里同名的段,都在这条路径上
|
|
63
63
|
* 合并成一份,`Config.listConfigs` 也就读得到 schema——写配置的人(或 agent)不用再猜键名。
|
|
64
64
|
*
|
|
65
|
+
* 标了 `.volatile()` 的字段还会被内核投影成 graph row 的 synced config,浏览器半边
|
|
66
|
+
* 在 `apply(ctx, config)` 里直接拿到它的实时引用(`@deepseek-ai/dsh-client-config/types`
|
|
67
|
+
* 的 `SyncedConfig`)。所以「页面该怎么处理这次右键」这类每次都要重新判断的字段标
|
|
68
|
+
* volatile;挂载时消费一次的值(总开关、回环策略、补收窗口、套接字路径)不标——
|
|
69
|
+
* 改它们本来就该重挂这一行,标成 volatile 反而会让改动原地生效、路由却不重建。
|
|
70
|
+
*
|
|
65
71
|
* 它**不会**凭空长出一个可编辑的配置表单:「设置 → 插件」按设计就是只读清单
|
|
66
72
|
* (inspect plugins *without changing their configuration*),而侧边栏「插件」页里那块
|
|
67
73
|
* 可编辑区域要由插件**自己注册一个配置页**(官方插件是配套 UI 包做的)。
|
|
68
|
-
*
|
|
74
|
+
* 本插件只有这几个字段,不值得为它单开一页——改它们直接写 YAML 或 settings.yaml。
|
|
69
75
|
*/
|
|
70
76
|
export const Config = z.object({
|
|
71
|
-
/**
|
|
77
|
+
/** 总开关。关掉后连路由都不注册;挂载时读一次,改它需要重挂。 */
|
|
72
78
|
enabled: z.boolean().default(true),
|
|
73
79
|
/**
|
|
74
80
|
* 每次右键都新建一个空白会话。
|
|
75
81
|
*
|
|
76
82
|
* **默认 false**:复用该工作区已有的空白会话。同一个文件夹点几次就堆几个空会话
|
|
77
83
|
* 是很容易发生的,而复用正是 DSH 侧边栏「新会话」自己的语义。
|
|
84
|
+
*
|
|
85
|
+
* **volatile**:页面在每次打开文件夹时现读(`config.alwaysNewSession.get()`),
|
|
86
|
+
* 所以改这个值不用重启宿主、也不用刷新页面,下一次右键就按新值走;宿主半边自己
|
|
87
|
+
* 不读它,只靠 schema 把它投影给浏览器半边。
|
|
78
88
|
*/
|
|
79
|
-
alwaysNewSession: z.boolean().default(false),
|
|
89
|
+
alwaysNewSession: z.boolean().default(false).volatile(),
|
|
80
90
|
/**
|
|
81
91
|
* 是否接受非回环来源。**默认 false,不要轻易打开。**
|
|
82
92
|
*
|
|
@@ -99,6 +109,57 @@ export const Config = z.object({
|
|
|
99
109
|
*/
|
|
100
110
|
socketPath: z.string().default(DEFAULT_SOCKET_PATH),
|
|
101
111
|
});
|
|
112
|
+
/**
|
|
113
|
+
* Config 字段里由内核作为实时引用交给 `apply` 的那些。
|
|
114
|
+
*
|
|
115
|
+
* 与 {@link Config} 的 `.volatile()` 标记、{@link OpenInDshConfig} 的 `Volatile`
|
|
116
|
+
* 类型必须一一对应;加字段时三处一起改。
|
|
117
|
+
*/
|
|
118
|
+
const VOLATILE_FIELDS = ['alwaysNewSession'];
|
|
119
|
+
/**
|
|
120
|
+
* Whether a field arrived as a live reference rather than a value.
|
|
121
|
+
*
|
|
122
|
+
* The Loader resolves the row against {@link Config} before it calls `apply`, so
|
|
123
|
+
* a `.volatile()` field is a reference; a test or a hand-written composition
|
|
124
|
+
* passes the raw value instead. Re-parsing a reference throws (the field
|
|
125
|
+
* validator sees an object where it expects a boolean), so the two shapes are
|
|
126
|
+
* told apart here before {@link resolveConfig} normalizes the row.
|
|
127
|
+
*
|
|
128
|
+
* @param value - one config field.
|
|
129
|
+
* @returns true when the field is a reference.
|
|
130
|
+
*/
|
|
131
|
+
function isVolatileValue(value) {
|
|
132
|
+
return (value !== null &&
|
|
133
|
+
typeof value === 'object' &&
|
|
134
|
+
typeof value.get === 'function');
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Resolve one entry config into the shape this half reads.
|
|
138
|
+
*
|
|
139
|
+
* Two callers, two shapes, one result: the Loader hands `apply` a row where every
|
|
140
|
+
* `.volatile()` field is already a reference, while a test passes the raw block
|
|
141
|
+
* the schema still has to validate and default. References are lifted out first
|
|
142
|
+
* and put back after the plain remainder is parsed, so the function is
|
|
143
|
+
* idempotent — resolving an already-resolved row keeps the same references,
|
|
144
|
+
* which is what makes the volatile update path work: the kernel commits later
|
|
145
|
+
* writes into those objects in place.
|
|
146
|
+
*
|
|
147
|
+
* @param rawConfig - the row as `apply` received it.
|
|
148
|
+
* @returns the row with defaults applied and live references preserved.
|
|
149
|
+
*/
|
|
150
|
+
export function resolveConfig(rawConfig) {
|
|
151
|
+
const row = isRecord(rawConfig) ? { ...rawConfig } : {};
|
|
152
|
+
const live = {};
|
|
153
|
+
for (const key of VOLATILE_FIELDS) {
|
|
154
|
+
const value = row[key];
|
|
155
|
+
if (!isVolatileValue(value))
|
|
156
|
+
continue;
|
|
157
|
+
live[key] = value;
|
|
158
|
+
delete row[key];
|
|
159
|
+
}
|
|
160
|
+
const plain = Config(row);
|
|
161
|
+
return { ...plain, ...live };
|
|
162
|
+
}
|
|
102
163
|
/** The endpoint the Explorer verb's launcher calls. Mirrored in `scripts/`. */
|
|
103
164
|
export const ROUTE_OPEN = '/dsh-open-in-dsh/api/v1/open';
|
|
104
165
|
/** The endpoint the browser half follows. Hand-mirrored in `client/index.ts`. */
|
|
@@ -251,29 +312,27 @@ export function openWithCommand(platform, appId, target) {
|
|
|
251
312
|
return null;
|
|
252
313
|
}
|
|
253
314
|
/**
|
|
254
|
-
* Install the
|
|
315
|
+
* Install the six routes.
|
|
255
316
|
*
|
|
256
317
|
* `webServer` is acquired through `ctx.inject` rather than read directly: the
|
|
257
318
|
* service appears asynchronously, and a plain read inside `apply` would
|
|
258
319
|
* silently see nothing and never register the routes.
|
|
259
320
|
*
|
|
260
|
-
* The
|
|
261
|
-
*
|
|
262
|
-
* `apply`
|
|
263
|
-
* default at the point of use.
|
|
321
|
+
* The row config arrives already resolved when the Loader mounts the plugin; a
|
|
322
|
+
* test passes the raw block. {@link resolveConfig} accepts both and yields one
|
|
323
|
+
* object with the shipped defaults applied, so `apply` reads one shape instead
|
|
324
|
+
* of re-deciding each default at the point of use.
|
|
264
325
|
*
|
|
265
326
|
* @param ctx - host plugin context.
|
|
266
|
-
* @param rawConfig - the
|
|
327
|
+
* @param rawConfig - the row as the Loader hands it over (resolved), or the raw
|
|
328
|
+
* `config` block from a test or hand-written composition.
|
|
267
329
|
* @returns nothing; the routes are registered once `webServer` appears.
|
|
268
330
|
*/
|
|
269
331
|
export function apply(ctx, rawConfig = {}) {
|
|
270
|
-
const config =
|
|
332
|
+
const config = resolveConfig(rawConfig);
|
|
271
333
|
if (config.enabled === false)
|
|
272
334
|
return;
|
|
273
|
-
const hub = createHub({
|
|
274
|
-
alwaysNewSession: config.alwaysNewSession,
|
|
275
|
-
backlogTtlMs: config.backlogTtlMs,
|
|
276
|
-
});
|
|
335
|
+
const hub = createHub({ backlogTtlMs: config.backlogTtlMs });
|
|
277
336
|
const allowNonLoopback = config.allowNonLoopback === true;
|
|
278
337
|
ctx.inject(['webServer'], (host) => {
|
|
279
338
|
host.effect(() => host.webServer.register({
|
|
@@ -328,8 +387,11 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
328
387
|
* replayable backlog row for the same request, an expiring replay window, and
|
|
329
388
|
* a sequence that rewinds on host restart — can be tested without HTTP.
|
|
330
389
|
*
|
|
390
|
+
* It carries no session policy: `alwaysNewSession` is a volatile config field,
|
|
391
|
+
* so the browser half reads its own synced reference. Sending the value through
|
|
392
|
+
* an SSE frame as well would be a second, staler source of truth.
|
|
393
|
+
*
|
|
331
394
|
* @param options - hub options.
|
|
332
|
-
* @param options.alwaysNewSession - session policy sent to the browser half.
|
|
333
395
|
* @param options.backlogTtlMs - replay window in milliseconds.
|
|
334
396
|
* @param options.now - clock, for tests.
|
|
335
397
|
* @returns the hub.
|
|
@@ -339,9 +401,6 @@ export function createHub(options = {}) {
|
|
|
339
401
|
? Number(options.backlogTtlMs)
|
|
340
402
|
: DEFAULT_BACKLOG_TTL_MS;
|
|
341
403
|
const now = typeof options.now === 'function' ? options.now : () => Date.now();
|
|
342
|
-
// Defaults to the schema's shipped default (reuse a blank session), so a hub
|
|
343
|
-
// built directly — as the tests do — behaves like the mounted plugin.
|
|
344
|
-
const settings = { alwaysNewSession: options.alwaysNewSession === true };
|
|
345
404
|
/** Live `text/event-stream` responses, each one an open DSH page. */
|
|
346
405
|
const streams = new Set();
|
|
347
406
|
/** Newest-last request rows, bounded and time-filtered on read. */
|
|
@@ -415,7 +474,6 @@ export function createHub(options = {}) {
|
|
|
415
474
|
subscribe,
|
|
416
475
|
clients,
|
|
417
476
|
close,
|
|
418
|
-
settings,
|
|
419
477
|
get seq() { return seq; },
|
|
420
478
|
get lastSeenAt() { return lastSeenAt; },
|
|
421
479
|
};
|
|
@@ -628,9 +686,11 @@ function createEventsHandler(ctx, hub, allowNonLoopback) {
|
|
|
628
686
|
'x-accel-buffering': 'no',
|
|
629
687
|
});
|
|
630
688
|
response.write('retry: 2000\n\n');
|
|
631
|
-
// `hello` carries the sequence
|
|
632
|
-
//
|
|
633
|
-
|
|
689
|
+
// `hello` carries the sequence the Client half cannot see in its own
|
|
690
|
+
// `apply` — including the rewind a host restart implies. Config does not
|
|
691
|
+
// travel here any more: the kernel projects the volatile fields into the
|
|
692
|
+
// graph row, so the page already holds a live reference at mount time.
|
|
693
|
+
response.write(sseFrame('hello', { seq: hub.seq }));
|
|
634
694
|
for (const entry of hub.pending(since))
|
|
635
695
|
response.write(sseFrame('request', entry));
|
|
636
696
|
const stop = hub.subscribe(response);
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
2
|
import z from '@deepseek-ai/schemastery';
|
|
3
|
+
import type { OpenInDshConfig } from './types.js';
|
|
4
|
+
export type { OpenInDshConfig };
|
|
3
5
|
/** A thrown value from a failed spawn: an `Error` that may carry an errno code. */
|
|
4
6
|
interface ExecFailure extends Error {
|
|
5
7
|
code?: string | number;
|
|
@@ -82,13 +84,8 @@ export interface RequestEntry {
|
|
|
82
84
|
readonly path: string;
|
|
83
85
|
readonly at: number;
|
|
84
86
|
}
|
|
85
|
-
/** The settings the page receives in the `hello` frame. */
|
|
86
|
-
export interface HubSettings {
|
|
87
|
-
readonly alwaysNewSession: boolean;
|
|
88
|
-
}
|
|
89
87
|
/** Options for {@link createHub}. */
|
|
90
88
|
export interface HubOptions {
|
|
91
|
-
alwaysNewSession?: boolean;
|
|
92
89
|
backlogTtlMs?: number;
|
|
93
90
|
now?: () => number;
|
|
94
91
|
}
|
|
@@ -99,7 +96,6 @@ export interface Hub {
|
|
|
99
96
|
subscribe(response: EventStream): () => void;
|
|
100
97
|
clients(): number;
|
|
101
98
|
close(): void;
|
|
102
|
-
readonly settings: HubSettings;
|
|
103
99
|
readonly seq: number;
|
|
104
100
|
readonly lastSeenAt: number;
|
|
105
101
|
}
|
|
@@ -174,21 +170,31 @@ export declare const DEFAULT_SOCKET_PATH: string;
|
|
|
174
170
|
* 默认值、profile 补丁层的覆盖、`$DSH_HOME/settings.yaml` 里同名的段,都在这条路径上
|
|
175
171
|
* 合并成一份,`Config.listConfigs` 也就读得到 schema——写配置的人(或 agent)不用再猜键名。
|
|
176
172
|
*
|
|
173
|
+
* 标了 `.volatile()` 的字段还会被内核投影成 graph row 的 synced config,浏览器半边
|
|
174
|
+
* 在 `apply(ctx, config)` 里直接拿到它的实时引用(`@deepseek-ai/dsh-client-config/types`
|
|
175
|
+
* 的 `SyncedConfig`)。所以「页面该怎么处理这次右键」这类每次都要重新判断的字段标
|
|
176
|
+
* volatile;挂载时消费一次的值(总开关、回环策略、补收窗口、套接字路径)不标——
|
|
177
|
+
* 改它们本来就该重挂这一行,标成 volatile 反而会让改动原地生效、路由却不重建。
|
|
178
|
+
*
|
|
177
179
|
* 它**不会**凭空长出一个可编辑的配置表单:「设置 → 插件」按设计就是只读清单
|
|
178
180
|
* (inspect plugins *without changing their configuration*),而侧边栏「插件」页里那块
|
|
179
181
|
* 可编辑区域要由插件**自己注册一个配置页**(官方插件是配套 UI 包做的)。
|
|
180
|
-
*
|
|
182
|
+
* 本插件只有这几个字段,不值得为它单开一页——改它们直接写 YAML 或 settings.yaml。
|
|
181
183
|
*/
|
|
182
184
|
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
183
|
-
/**
|
|
185
|
+
/** 总开关。关掉后连路由都不注册;挂载时读一次,改它需要重挂。 */
|
|
184
186
|
enabled: z<boolean, boolean, "defined">;
|
|
185
187
|
/**
|
|
186
188
|
* 每次右键都新建一个空白会话。
|
|
187
189
|
*
|
|
188
190
|
* **默认 false**:复用该工作区已有的空白会话。同一个文件夹点几次就堆几个空会话
|
|
189
191
|
* 是很容易发生的,而复用正是 DSH 侧边栏「新会话」自己的语义。
|
|
192
|
+
*
|
|
193
|
+
* **volatile**:页面在每次打开文件夹时现读(`config.alwaysNewSession.get()`),
|
|
194
|
+
* 所以改这个值不用重启宿主、也不用刷新页面,下一次右键就按新值走;宿主半边自己
|
|
195
|
+
* 不读它,只靠 schema 把它投影给浏览器半边。
|
|
190
196
|
*/
|
|
191
|
-
alwaysNewSession: z<boolean, boolean, "defined">;
|
|
197
|
+
alwaysNewSession: z<boolean, boolean, "volatile-defined">;
|
|
192
198
|
/**
|
|
193
199
|
* 是否接受非回环来源。**默认 false,不要轻易打开。**
|
|
194
200
|
*
|
|
@@ -211,15 +217,19 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
211
217
|
*/
|
|
212
218
|
socketPath: z<string, string, "defined">;
|
|
213
219
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
214
|
-
/**
|
|
220
|
+
/** 总开关。关掉后连路由都不注册;挂载时读一次,改它需要重挂。 */
|
|
215
221
|
enabled: z<boolean, boolean, "defined">;
|
|
216
222
|
/**
|
|
217
223
|
* 每次右键都新建一个空白会话。
|
|
218
224
|
*
|
|
219
225
|
* **默认 false**:复用该工作区已有的空白会话。同一个文件夹点几次就堆几个空会话
|
|
220
226
|
* 是很容易发生的,而复用正是 DSH 侧边栏「新会话」自己的语义。
|
|
227
|
+
*
|
|
228
|
+
* **volatile**:页面在每次打开文件夹时现读(`config.alwaysNewSession.get()`),
|
|
229
|
+
* 所以改这个值不用重启宿主、也不用刷新页面,下一次右键就按新值走;宿主半边自己
|
|
230
|
+
* 不读它,只靠 schema 把它投影给浏览器半边。
|
|
221
231
|
*/
|
|
222
|
-
alwaysNewSession: z<boolean, boolean, "defined">;
|
|
232
|
+
alwaysNewSession: z<boolean, boolean, "volatile-defined">;
|
|
223
233
|
/**
|
|
224
234
|
* 是否接受非回环来源。**默认 false,不要轻易打开。**
|
|
225
235
|
*
|
|
@@ -242,14 +252,21 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
242
252
|
*/
|
|
243
253
|
socketPath: z<string, string, "defined">;
|
|
244
254
|
}>>, "plain">;
|
|
245
|
-
/**
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Resolve one entry config into the shape this half reads.
|
|
257
|
+
*
|
|
258
|
+
* Two callers, two shapes, one result: the Loader hands `apply` a row where every
|
|
259
|
+
* `.volatile()` field is already a reference, while a test passes the raw block
|
|
260
|
+
* the schema still has to validate and default. References are lifted out first
|
|
261
|
+
* and put back after the plain remainder is parsed, so the function is
|
|
262
|
+
* idempotent — resolving an already-resolved row keeps the same references,
|
|
263
|
+
* which is what makes the volatile update path work: the kernel commits later
|
|
264
|
+
* writes into those objects in place.
|
|
265
|
+
*
|
|
266
|
+
* @param rawConfig - the row as `apply` received it.
|
|
267
|
+
* @returns the row with defaults applied and live references preserved.
|
|
268
|
+
*/
|
|
269
|
+
export declare function resolveConfig(rawConfig: unknown): OpenInDshConfig;
|
|
253
270
|
/** The endpoint the Explorer verb's launcher calls. Mirrored in `scripts/`. */
|
|
254
271
|
export declare const ROUTE_OPEN = "/dsh-open-in-dsh/api/v1/open";
|
|
255
272
|
/** The endpoint the browser half follows. Hand-mirrored in `client/index.ts`. */
|
|
@@ -330,22 +347,23 @@ export declare function availableApps(platform?: string, exists?: ExistsFn, appD
|
|
|
330
347
|
*/
|
|
331
348
|
export declare function openWithCommand(platform: string, appId: string, target: LaunchTarget): LaunchCommand | null;
|
|
332
349
|
/**
|
|
333
|
-
* Install the
|
|
350
|
+
* Install the six routes.
|
|
334
351
|
*
|
|
335
352
|
* `webServer` is acquired through `ctx.inject` rather than read directly: the
|
|
336
353
|
* service appears asynchronously, and a plain read inside `apply` would
|
|
337
354
|
* silently see nothing and never register the routes.
|
|
338
355
|
*
|
|
339
|
-
* The
|
|
340
|
-
*
|
|
341
|
-
* `apply`
|
|
342
|
-
* default at the point of use.
|
|
356
|
+
* The row config arrives already resolved when the Loader mounts the plugin; a
|
|
357
|
+
* test passes the raw block. {@link resolveConfig} accepts both and yields one
|
|
358
|
+
* object with the shipped defaults applied, so `apply` reads one shape instead
|
|
359
|
+
* of re-deciding each default at the point of use.
|
|
343
360
|
*
|
|
344
361
|
* @param ctx - host plugin context.
|
|
345
|
-
* @param rawConfig - the
|
|
362
|
+
* @param rawConfig - the row as the Loader hands it over (resolved), or the raw
|
|
363
|
+
* `config` block from a test or hand-written composition.
|
|
346
364
|
* @returns nothing; the routes are registered once `webServer` appears.
|
|
347
365
|
*/
|
|
348
|
-
export declare function apply(ctx: HostContext, rawConfig?:
|
|
366
|
+
export declare function apply(ctx: HostContext, rawConfig?: unknown): void;
|
|
349
367
|
/**
|
|
350
368
|
* The one piece of shared state: the request sequence and its followers.
|
|
351
369
|
*
|
|
@@ -353,8 +371,11 @@ export declare function apply(ctx: HostContext, rawConfig?: Partial<OpenInDshCon
|
|
|
353
371
|
* replayable backlog row for the same request, an expiring replay window, and
|
|
354
372
|
* a sequence that rewinds on host restart — can be tested without HTTP.
|
|
355
373
|
*
|
|
374
|
+
* It carries no session policy: `alwaysNewSession` is a volatile config field,
|
|
375
|
+
* so the browser half reads its own synced reference. Sending the value through
|
|
376
|
+
* an SSE frame as well would be a second, staler source of truth.
|
|
377
|
+
*
|
|
356
378
|
* @param options - hub options.
|
|
357
|
-
* @param options.alwaysNewSession - session policy sent to the browser half.
|
|
358
379
|
* @param options.backlogTtlMs - replay window in milliseconds.
|
|
359
380
|
* @param options.now - clock, for tests.
|
|
360
381
|
* @returns the hub.
|
|
@@ -469,4 +490,3 @@ export declare function directoryPath(value: unknown): string | null;
|
|
|
469
490
|
* @returns canonical path plus the directory flag, or null when it is not one.
|
|
470
491
|
*/
|
|
471
492
|
export declare function existingPath(value: unknown, stat?: StatFn): LaunchTarget | null;
|
|
472
|
-
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared entry Config type of `dsh-open-in-dsh`.
|
|
3
|
+
*
|
|
4
|
+
* One type, two faces: the Host schema in `index.ts` resolves the profile row
|
|
5
|
+
* into this shape, and the browser half receives its `Volatile` fields through
|
|
6
|
+
* `apply(ctx, config)` as the kernel's `SyncedConfig<OpenInDshConfig>`
|
|
7
|
+
* (`@deepseek-ai/dsh-client-config/types`). Keeping the shape here means the
|
|
8
|
+
* half that declares the fields and the half that reads them cannot drift, and
|
|
9
|
+
* that neither half has to import the other.
|
|
10
|
+
*
|
|
11
|
+
* Only a field some reader reads again while the plugin stays mounted is
|
|
12
|
+
* declared `Volatile`. The Loader hands those to `apply` as references and
|
|
13
|
+
* commits a later config write into them in place, so the plugin must read
|
|
14
|
+
* `.get()` at the point of use instead of capturing a value. A field consumed
|
|
15
|
+
* once at mount — the enable switch, the loopback policy, the replay window,
|
|
16
|
+
* the bound socket path — stays an ordinary value on purpose: changing it has
|
|
17
|
+
* to remount the row, and a volatile field would silently stop doing that.
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-open-in-dsh/types
|
|
20
|
+
*/
|
|
21
|
+
import type { Volatile } from '@deepseek-ai/cordis';
|
|
22
|
+
/** One resolved entry config, as both plugin faces name it. */
|
|
23
|
+
export interface OpenInDshConfig {
|
|
24
|
+
/** Master switch, read once when the row mounts; off means no route and no socket. */
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether every announced folder lands in a brand-new blank Session.
|
|
28
|
+
*
|
|
29
|
+
* Volatile because the browser half decides per request: a write made while
|
|
30
|
+
* the host runs must reach the page that is already loaded, without a reload.
|
|
31
|
+
* The Host half itself never reads this field — it exists in the schema so
|
|
32
|
+
* the kernel projects it into the graph row the Client face receives.
|
|
33
|
+
*/
|
|
34
|
+
alwaysNewSession: Volatile<boolean>;
|
|
35
|
+
/** Whether a non-loopback peer may announce a path; captured by the route handlers at mount. */
|
|
36
|
+
allowNonLoopback: boolean;
|
|
37
|
+
/** How long an unanswered request stays replayable; read once when the hub is built. */
|
|
38
|
+
backlogTtlMs: number;
|
|
39
|
+
/** macOS handoff socket path; bound once when the row mounts. Empty disables the transport. */
|
|
40
|
+
socketPath: string;
|
|
41
|
+
}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-open-in-dsh",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig.client.json && node scripts/build-client.mts",
|
|
37
37
|
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.client.json --noEmit",
|
|
38
38
|
"prepare": "npm run build",
|
|
39
|
-
"test": "npm run build && node --check lib/index.js && node --check lib/client.js && node --check .client-build/index.js && node --test test/host.test.ts test/routes.test.ts test/scripts.test.ts test/macos.test.ts test/open-with.test.ts test/session.test.ts test/menu.test.ts test/session-menu.test.ts"
|
|
39
|
+
"test": "npm run build && node --check lib/index.js && node --check lib/client.js && node --check .client-build/index.js && node --test test/host.test.ts test/routes.test.ts test/scripts.test.ts test/macos.test.ts test/open-with.test.ts test/session.test.ts test/menu.test.ts test/session-menu.test.ts test/client-config.test.ts"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=24",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
+
"@deepseek-ai/dsh-client-config": "0.2.3-alpha.2",
|
|
87
88
|
"@types/node": "^26.6.5",
|
|
88
89
|
"typescript": "^7.0.2"
|
|
89
90
|
}
|