dsh-paseo-host 0.0.0-stage → 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 jixy <467677527@qq.com>
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 CHANGED
@@ -1,3 +1,176 @@
1
- # Temporary Holding Version
1
+ # dsh-paseo-host
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `paseo-dsh` 的 DSH 侧配套插件。**一个包做两件事**,替代原先分开安装的
4
+ `dsh-paseo-remote-host` 与 `dsh-paseo-workspace-sync`。
5
+
6
+ | 能力 | 作用 | 装在哪 |
7
+ |---|---|---|
8
+ | `host` | 本机 unix socket(0600),把 session controller 的 create / resolve / prompt / cancel / follow / list / archive 暴露给 `paseo-dsh` 的 remote transport | desktop / headless |
9
+ | `sync.ownership` | 把 Paseo 的 `paseo-dsh` 会话按 cwd 归到 DSH 工作区(缺失则按需新建) | desktop |
10
+ | `sync.syncArchive` | Paseo 已归档 → DSH 也归档 | desktop |
11
+ | `sync.syncTitle` | 把 Paseo 标题写回 DSH(只能改 live 会话) | paseo |
12
+ | `liveStatusWrite` / `liveStatusRelay` | stdio 模式下跨进程转发 running 状态(remote 模式下不需要,留作兜底) | paseo / desktop |
13
+
14
+ ## 为什么合并
15
+
16
+ 两块共享同一个 `workspaceRegistry` / `sessionPersistence`,分开装只是多一份
17
+ `package.json`、多一份 `cordis.patch.yml`、升级时多同步一次。合并后:
18
+
19
+ - 一个包、一次安装、一份版本号;
20
+ - `host` 与 `sync` 各自 `inject` 自己需要的服务,缺服务只少一块能力;
21
+ - remote transport 落地后,状态转发退化为 stdio 兜底,不用再维护两个包的开关矩阵。
22
+
23
+ ## 安装
24
+
25
+ 两个 profile 都要装,配置不同。
26
+
27
+ > **desktop profile 注意**:它的 `dsh.profile.bundles` 由 DSH 的插件管理器维护,手改
28
+ > `package.json` 会被同步回去。所以 `dsh-paseo-host` 在 desktop 上用
29
+ > `cordis.patch.yml` 的 `insert` 装载,不要加进 `bundles`。paseo profile 没有这个限制,
30
+ > 但用同一种方式更一致。
31
+
32
+ ### desktop profile
33
+
34
+ ```json
35
+ // ~/.dsh/profiles/desktop/package.json —— 只加依赖,bundles 不动
36
+ {
37
+ "dependencies": {
38
+ "dsh-paseo-host": "link:/path/to/paseo-dsh/dsh-paseo-host"
39
+ }
40
+ }
41
+ ```
42
+
43
+ ```yaml
44
+ # ~/.dsh/profiles/desktop/cordis.patch.yml
45
+ - insert:
46
+ - id: paseo-host
47
+ name: dsh-paseo-host
48
+ config:
49
+ enabled: true
50
+ host:
51
+ enabled: true
52
+ socketPath: ''
53
+ sync:
54
+ ownership: true
55
+ syncTitle: false
56
+ syncArchive: true
57
+ intervalMs: 30000
58
+ liveStatusWrite: false
59
+ liveStatusRelay: true
60
+ ```
61
+
62
+ ### paseo profile
63
+
64
+ ```json
65
+ // ~/.dsh/profiles/paseo/package.json
66
+ {
67
+ "dependencies": {
68
+ "dsh-paseo-host": "link:/path/to/paseo-dsh/dsh-paseo-host"
69
+ }
70
+ }
71
+ ```
72
+
73
+ ```yaml
74
+ # ~/.dsh/profiles/paseo/cordis.patch.yml
75
+ - insert:
76
+ - id: paseo-host
77
+ name: dsh-paseo-host
78
+ config:
79
+ enabled: true
80
+ host:
81
+ enabled: false
82
+ sync:
83
+ ownership: false
84
+ syncArchive: false
85
+ syncTitle: true
86
+ intervalMs: 10000
87
+ liveStatusWrite: true
88
+ liveStatusRelay: false
89
+ ```
90
+
91
+ 装完在 profile 目录执行一次 `pnpm install`,然后重启 DSH。
92
+
93
+ > `ownership` 必须只在 desktop 打开:`workspace.json` 是 single-layout,多进程
94
+ > 写会互相覆盖。
95
+
96
+ ## 配置
97
+
98
+ 分组写法(推荐)
99
+
100
+ ```yaml
101
+ config:
102
+ enabled: true
103
+ host:
104
+ enabled: true
105
+ socketPath: '' # 空 = <DSH_HOME>/paseo-remote.sock
106
+ maxMessages: 20
107
+ historyMessages: 200
108
+ debug: false
109
+ sync:
110
+ paseoRoot: '' # 空 = ~/.paseo
111
+ intervalMs: 30000
112
+ initialDelayMs: 4000
113
+ ownership: true
114
+ syncTitle: false
115
+ syncArchive: true
116
+ unarchiveFromPaseo: false
117
+ autoCreateWorkspace: true
118
+ workspaceTitle: dirname # dirname | display-name
119
+ uuidOnlyFallback: true
120
+ dryRun: false
121
+ logFile: '' # 空 = <DSH_HOME>/paseo-host.log
122
+ liveStatusWrite: false
123
+ liveStatusRelay: true
124
+ statusIntervalMs: 5000
125
+ statusTtlMs: 30000
126
+ statusResendMs: 30000
127
+ ```
128
+
129
+ 扁平写法也接受(旧配置可直接迁移):顶层 `socketPath` / `maxMessages` / `debug`
130
+ 会进入 `host`,`ownership` / `syncTitle` / `syncArchive` / `intervalMs` 等会进入
131
+ `sync`。分组里显式写过的键优先,不会被顶层旧值覆盖。
132
+
133
+ ## 诊断
134
+
135
+ 两个日志文件,职责分开(合并后没有改名,避免丢掉升级前的排查历史):
136
+
137
+ | 文件 | 内容 | 格式 |
138
+ |---|---|---|
139
+ | `~/.dsh/paseo-host.log` | 同步循环、归属、归档、标题、状态转发 | JSONL,单行 `{at, level, message, detail}` |
140
+ | `~/.dsh/paseo-remote-host.log` | socket 启动与请求诊断:`listening on ...`、`history replay:`、`slash menu:`、`created workspace for ...` | 纯文本,超过 256KB 自动重建 |
141
+
142
+ 同步相关的关键行:
143
+
144
+ ```
145
+ 同步循环已启动 { pid, intervalMs, ownership, syncTitle }
146
+ 桌面宿主在线,归属交由它负责 ← paseo 会话进程检测到 desktop 在写 workspace.json
147
+ 已加入工作区:<title>
148
+ 已归档:<sessionId>
149
+ 已同步标题:<title>
150
+ ```
151
+
152
+ 预览不写入:
153
+
154
+ ```bash
155
+ node lib/cli.js
156
+ ```
157
+
158
+ ## 与 `paseo-dsh` 的关系
159
+
160
+ `paseo-dsh`(Paseo 侧插件)通过 `~/.paseo/paseo-dsh-transport.json` 选择传输:
161
+
162
+ ```json
163
+ { "transport": "remote", "socketPath": "~/.dsh/paseo-remote.sock" }
164
+ ```
165
+
166
+ 不写这个文件就是 `stdio`,行为与只装 `paseo-dsh` 时一致;本插件的 `host` 部分
167
+ 不会生效,`sync` 与 `liveStatus` 仍可用。
168
+
169
+ ## 测试
170
+
171
+ ```bash
172
+ node --test test/*.test.js
173
+ ```
174
+
175
+ 覆盖:同步计划(归属/归档/标题/内部会话/纯 uuid 兜底)、同步执行(attach /
176
+ archive / relabel)、状态读写与转发、配置归一化。
@@ -0,0 +1,28 @@
1
+ # dsh-paseo-host 的装载层。
2
+ #
3
+ # 一个包,两件事:
4
+ # host —— 在 Desktop/Host 进程里开一个仅本机可访问的 unix socket(0600),
5
+ # 给 paseo-dsh 的 remote transport 提供 create/prompt/cancel/follow。
6
+ # sync —— 把 Paseo 的 paseo-dsh 会话按 cwd 归到 DSH 工作区,并同步归档/标题;
7
+ # stdio 模式下还用 liveStatus 跨进程转发运行状态。
8
+ #
9
+ # 装到不同 profile 时用同一份配置结构,按需关掉不需要的一半:
10
+ # desktop profile:host.enabled=true + sync.ownership=true + liveStatusRelay=true
11
+ # paseo profile:host.enabled=false + sync.syncTitle=true + liveStatusWrite=true
12
+ - insert:
13
+ - id: paseo-host
14
+ name: dsh-paseo-host
15
+ config:
16
+ enabled: true
17
+ host:
18
+ enabled: true
19
+ # 空串 = <DSH_HOME>/paseo-remote.sock
20
+ socketPath: ''
21
+ sync:
22
+ # 只有 desktop 侧写 workspace.json,避免多进程互相覆盖。
23
+ ownership: true
24
+ syncTitle: false
25
+ syncArchive: true
26
+ intervalMs: 30000
27
+ liveStatusWrite: false
28
+ liveStatusRelay: true
package/lib/cli.js ADDED
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 只读预览:算出 dsh-paseo-host 会做什么,不写任何文件。
4
+ *
5
+ * node lib/cli.js
6
+ * node lib/cli.js --json
7
+ * node lib/cli.js --include-archived
8
+ * node lib/cli.js --no-uuid-fallback
9
+ * node lib/cli.js --workspace-title display-name
10
+ *
11
+ * 需要 DSH 正在运行才会真正生效——这里只是计划。
12
+ *
13
+ * @module dsh-paseo-host/cli
14
+ */
15
+ import { readSessionHeaders } from './headers.js';
16
+ import { buildPlan } from './plan.js';
17
+ import { isUsefulTitle, scan } from './scan.js';
18
+
19
+ function parseArgs(argv) {
20
+ const options = {
21
+ json: false,
22
+ includeArchived: false,
23
+ autoCreateWorkspace: true,
24
+ syncArchive: true,
25
+ uuidOnlyFallback: true,
26
+ workspaceTitle: 'dirname',
27
+ paseoRoot: '',
28
+ };
29
+ for (let index = 0; index < argv.length; index += 1) {
30
+ const arg = argv[index];
31
+ switch (arg) {
32
+ case '--json':
33
+ options.json = true;
34
+ break;
35
+ case '--include-archived':
36
+ options.includeArchived = true;
37
+ break;
38
+ case '--no-auto-create':
39
+ options.autoCreateWorkspace = false;
40
+ break;
41
+ case '--no-archive':
42
+ options.syncArchive = false;
43
+ break;
44
+ case '--no-uuid-fallback':
45
+ options.uuidOnlyFallback = false;
46
+ break;
47
+ case '--workspace-title':
48
+ options.workspaceTitle = argv[index + 1] === 'display-name' ? 'display-name' : 'dirname';
49
+ index += 1;
50
+ break;
51
+ case '--paseo-root':
52
+ options.paseoRoot = argv[index + 1] ?? '';
53
+ index += 1;
54
+ break;
55
+ case '--help':
56
+ case '-h':
57
+ options.help = true;
58
+ break;
59
+ default:
60
+ break;
61
+ }
62
+ }
63
+ return options;
64
+ }
65
+
66
+ function printPlan(plan, context) {
67
+ const lines = [];
68
+ lines.push(`Paseo paseo-dsh 会话:${context.agents} 条`);
69
+ lines.push(`DSH 会话 header:${context.headers} 条`);
70
+ lines.push(`DSH 工作区:${context.workspaces} 个(已归档会话 ${context.archived} 条)`);
71
+ lines.push('');
72
+
73
+ const section = (title, items, format) => {
74
+ lines.push(`${title}(${items.length})`);
75
+ if (items.length === 0) lines.push(' -');
76
+ for (const item of items) lines.push(` - ${format(item)}`);
77
+ lines.push('');
78
+ };
79
+
80
+ section('加入现有工作区', plan.attach, item => `${item.sessionId} → ${item.workspaceTitle} (${item.cwd})${item.orphan === true ? ' [Paseo 已无记录]' : ''}`);
81
+ section('新建工作区并加入', plan.create, item => `${item.sessionId} → 新建「${item.title}」 (${item.cwd})`);
82
+ section('归档', plan.archive, item => `${item.sessionId} ${item.title ?? ''}`.trim());
83
+ section('恢复归档', plan.unarchive, item => `${item.sessionId} ${item.title ?? ''}`.trim());
84
+ section('同步标题(仅 live 会话生效)', plan.relabel.filter(item => isUsefulTitle(item.title)), item => `${item.sessionId} ← ${item.title}`);
85
+
86
+ const skipped = plan.skip.reduce((group, item) => {
87
+ group[item.reason] = (group[item.reason] ?? 0) + 1;
88
+ return group;
89
+ }, {});
90
+ lines.push(`跳过(${plan.skip.length})`);
91
+ for (const [reason, count] of Object.entries(skipped)) lines.push(` - ${reason}: ${count}`);
92
+ if (plan.skip.length === 0) lines.push(' -');
93
+
94
+ console.log(lines.join('\n'));
95
+ }
96
+
97
+ const options = parseArgs(process.argv.slice(2));
98
+ if (options.help) {
99
+ console.log('用法: node lib/cli.js [--json] [--include-archived] [--no-auto-create] [--no-archive] [--no-uuid-fallback] [--workspace-title dirname|display-name] [--paseo-root DIR]');
100
+ process.exit(0);
101
+ }
102
+
103
+ const data = scan({ paseoRoot: options.paseoRoot });
104
+ const headers = await readSessionHeaders(data.home);
105
+ const plan = buildPlan({
106
+ agents: data.agents,
107
+ paseoWorkspaces: data.paseoWorkspaces,
108
+ headers,
109
+ dsh: data.dsh,
110
+ }, {
111
+ autoCreateWorkspace: options.autoCreateWorkspace,
112
+ syncArchive: options.syncArchive,
113
+ includeArchivedPaseo: options.includeArchived,
114
+ workspaceTitle: options.workspaceTitle,
115
+ uuidOnlyFallback: options.uuidOnlyFallback,
116
+ wantTitle: true,
117
+ });
118
+
119
+ if (options.json) {
120
+ console.log(JSON.stringify({
121
+ paseoRoot: data.paseoRoot,
122
+ dshHome: data.home,
123
+ agents: data.agents.size,
124
+ headers: headers.length,
125
+ workspaces: data.dsh.workspaces.length,
126
+ archived: data.dsh.archived.length,
127
+ plan,
128
+ }, null, 2));
129
+ } else {
130
+ printPlan(plan, {
131
+ agents: data.agents.size,
132
+ headers: headers.length,
133
+ workspaces: data.dsh.workspaces.length,
134
+ archived: data.dsh.archived.length,
135
+ });
136
+ }
package/lib/headers.js ADDED
@@ -0,0 +1,119 @@
1
+ /**
2
+ * 只读会话 header 扫描(CLI 用)。
3
+ *
4
+ * 插件运行时直接用 DSH 的 `sessionPersistence.list()`;CLI 不在 DSH 进程里,
5
+ * 所以自己读 `<DSH_HOME>/sessions/<escaped-cwd>/<session>/session.v*.jsonl.zstd`
6
+ * 的第一个 Zstandard 帧。只解压 header,不读事件正文。
7
+ *
8
+ * @module dsh-paseo-host/headers
9
+ */
10
+ import { createReadStream, readdirSync, statSync } from 'node:fs';
11
+ import { createZstdDecompress } from 'node:zlib';
12
+ import { join } from 'node:path';
13
+
14
+ const MAX_HEADER_BYTES = 256 * 1024;
15
+ const CONCURRENCY = 8;
16
+
17
+ function readHeaderFile(file) {
18
+ return new Promise((resolve) => {
19
+ let settled = false;
20
+ let out = Buffer.alloc(0);
21
+ let stream;
22
+ let zstd;
23
+ const finish = (value) => {
24
+ if (settled) return;
25
+ settled = true;
26
+ try { stream?.destroy(); } catch { /* 已关闭 */ }
27
+ try { zstd?.destroy(); } catch { /* 已关闭 */ }
28
+ resolve(value);
29
+ };
30
+ try {
31
+ stream = createReadStream(file, { start: 0, end: MAX_HEADER_BYTES - 1 });
32
+ zstd = createZstdDecompress();
33
+ } catch {
34
+ resolve(undefined);
35
+ return;
36
+ }
37
+ stream.on('error', () => finish(undefined));
38
+ zstd.on('error', () => finish(undefined));
39
+ zstd.on('end', () => finish(undefined));
40
+ zstd.on('data', (chunk) => {
41
+ out = Buffer.concat([out, chunk]);
42
+ const newline = out.indexOf(0x0a);
43
+ if (newline >= 0) {
44
+ try {
45
+ finish(JSON.parse(out.subarray(0, newline).toString('utf8')));
46
+ } catch {
47
+ finish(undefined);
48
+ }
49
+ } else if (out.length > MAX_HEADER_BYTES) {
50
+ finish(undefined);
51
+ }
52
+ });
53
+ stream.pipe(zstd);
54
+ });
55
+ }
56
+
57
+ function sessionLogFile(sessionDir) {
58
+ let names;
59
+ try {
60
+ names = readdirSync(sessionDir);
61
+ } catch {
62
+ return undefined;
63
+ }
64
+ const candidates = names
65
+ .filter(name => /^session\.v\d+\.jsonl(?:\.zstd)?$/.test(name))
66
+ .map(name => ({ name, mtime: statSync(join(sessionDir, name)).mtimeMs }))
67
+ .sort((left, right) => right.mtime - left.mtime);
68
+ return candidates.length === 0 ? undefined : join(sessionDir, candidates[0].name);
69
+ }
70
+
71
+ async function mapLimit(items, limit, worker) {
72
+ const results = new Array(items.length);
73
+ let cursor = 0;
74
+ const runners = Array.from({ length: Math.min(limit, items.length) }, async () => {
75
+ while (true) {
76
+ const index = cursor;
77
+ cursor += 1;
78
+ if (index >= items.length) return;
79
+ results[index] = await worker(items[index]);
80
+ }
81
+ });
82
+ await Promise.all(runners);
83
+ return results;
84
+ }
85
+
86
+ /**
87
+ * 读取所有会话 header。
88
+ * @param {string} home - DSH_HOME。
89
+ * @returns {Promise<Array<{id:string, cwd?:string, origin?:string, createdAt?:number}>>}
90
+ */
91
+ export async function readSessionHeaders(home) {
92
+ const root = join(home, 'sessions');
93
+ let projectDirs;
94
+ try {
95
+ projectDirs = readdirSync(root, { withFileTypes: true })
96
+ .filter(entry => entry.isDirectory())
97
+ .map(entry => join(root, entry.name));
98
+ } catch {
99
+ return [];
100
+ }
101
+
102
+ const files = [];
103
+ for (const projectDir of projectDirs) {
104
+ let entries;
105
+ try {
106
+ entries = readdirSync(projectDir, { withFileTypes: true });
107
+ } catch {
108
+ continue;
109
+ }
110
+ for (const entry of entries) {
111
+ if (!entry.isDirectory()) continue;
112
+ const file = sessionLogFile(join(projectDir, entry.name));
113
+ if (file !== undefined) files.push(file);
114
+ }
115
+ }
116
+
117
+ const headers = await mapLimit(files, CONCURRENCY, readHeaderFile);
118
+ return headers.filter(header => header !== null && typeof header === 'object' && typeof header.id === 'string');
119
+ }