@fish-under-sea/dsh-visual-companion 0.1.3 → 0.1.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 +3 -2
- package/lib/index.js +20 -8
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -124,16 +124,17 @@ node "$env:DSH_HOME\profiles\<profile>\node_modules\@fish-under-sea\dsh-visual-c
|
|
|
124
124
|
- 服务**闲置 4 小时自动退出**(`--idle-minutes` 可调),原型文件是临时产物,别当交付物;
|
|
125
125
|
- 降级链:无 Node → 自包含 HTML + `present`;无侧边栏浏览器 → 把完整 URL 交给用户手动打开;连插件都没装 → 下一轮手工读 `events.jsonl`;
|
|
126
126
|
- 需要 Node `^22.19.0 || >=24`、DSH `>=0.2.0-rc.2`;不需要任何 API key;
|
|
127
|
+
- **绑定是容错的**(0.1.5 起):`watchDir` 指向的 `<watchDir>/state` 还不存在时会**递归自建**;万一观察不了(路径不是目录、权限不足),只记一条告警并把状态如实留成「未绑定」——**插件照常加载**,工具与 `/companion` 不会一起消失,修好后 `visual_companion({action:"arm"})` 可重试;
|
|
127
128
|
- **已知限制**:宿主插件代码不热重载 —— 改 `lib/index.js` 后要重启宿主;只改 `cordis.patch.yml` 的内容可热重载。
|
|
128
129
|
|
|
129
130
|
## 开发与测试
|
|
130
131
|
|
|
131
132
|
```sh
|
|
132
|
-
node packages/dsh-visual-companion/test/visual-companion.test.mjs # 语料渲染 +
|
|
133
|
+
node packages/dsh-visual-companion/test/visual-companion.test.mjs # 语料渲染 + 清单契约 + 绑定容错(10 用例)
|
|
133
134
|
pnpm pack # 产物检查:files 覆盖 bin / lib / patch / README
|
|
134
135
|
```
|
|
135
136
|
|
|
136
|
-
`lib/message.js` 是**零依赖纯函数**(语料渲染),所以测试与调用方不装 `@deepseek-ai/*` 也能验证文案;`lib/index.js` 才依赖宿主提供的 `@deepseek-ai/dsh-llm`、`dsh-tools`、`schemastery
|
|
137
|
+
`lib/message.js` 是**零依赖纯函数**(语料渲染),所以测试与调用方不装 `@deepseek-ai/*` 也能验证文案;`lib/index.js` 才依赖宿主提供的 `@deepseek-ai/dsh-llm`、`dsh-tools`、`schemastery`(**运行时**是可选 peer,由 DSH 提供;**测试时**同一组包另以 `devDependencies` 声明,所以全新 clone 直接 `pnpm install` 就能跑测试,不必手工往 `node_modules` 里塞)。
|
|
137
138
|
|
|
138
139
|
## 与聚合包的关系
|
|
139
140
|
|
package/lib/index.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* @module @fish-under-sea/dsh-visual-companion
|
|
22
22
|
*/
|
|
23
23
|
import { spawn } from 'node:child_process'
|
|
24
|
-
import { watch } from 'node:fs'
|
|
24
|
+
import { mkdirSync, watch } from 'node:fs'
|
|
25
25
|
import { mkdir, readFile } from 'node:fs/promises'
|
|
26
26
|
import { basename, join } from 'node:path'
|
|
27
27
|
import { fileURLToPath } from 'node:url'
|
|
@@ -145,12 +145,23 @@ function arm(ctx, dir, sessionId) {
|
|
|
145
145
|
state.sessionId = sessionId
|
|
146
146
|
state.lastFingerprint = null
|
|
147
147
|
const watchDir = join(dir, 'state')
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
try {
|
|
149
|
+
// 目录还不存在(这个工作区还没起过伴侣服务)时要自建:fs.watch 对不存在的路径
|
|
150
|
+
// 会同步抛 ENOENT,而那会把整条插件记录成「未激活」——工具和斜杠命令一起消失。
|
|
151
|
+
mkdirSync(watchDir, { recursive: true })
|
|
152
|
+
state.watcher = watch(watchDir, { persistent: false }, (_event, filename) => {
|
|
153
|
+
if (filename !== null && basename(String(filename)) !== 'pending.json') return
|
|
154
|
+
void readPending(dir).then((pending) => (pending === undefined ? undefined : handleSubmit(ctx, pending)))
|
|
155
|
+
})
|
|
156
|
+
state.watcher.on?.('error', (error) => ctx.logger?.warn?.(`visual-companion: 观察 ${watchDir} 出错:${String(error)}`))
|
|
157
|
+
ctx.logger?.info?.(`visual-companion: 已绑定 ${watchDir}/pending.json → 会话 ${sessionId ?? '(由 pending.json 自带)'}`)
|
|
158
|
+
return true
|
|
159
|
+
} catch (error) {
|
|
160
|
+
// 观察不了不该让插件掉线:退化成「未绑定」,需要时还能用 visual_companion arm 重试。
|
|
161
|
+
state.watcher = null
|
|
162
|
+
ctx.logger?.warn?.(`visual-companion: 无法观察 ${watchDir}(${String(error?.message ?? error)});已跳过自动绑定,可稍后用 visual_companion({action:"arm"}) 重试`)
|
|
163
|
+
return false
|
|
164
|
+
}
|
|
154
165
|
}
|
|
155
166
|
|
|
156
167
|
function disarm() {
|
|
@@ -183,7 +194,8 @@ function registerTool(ctx) {
|
|
|
183
194
|
if (args.action === 'arm') {
|
|
184
195
|
const dir = clean(args.dir)
|
|
185
196
|
if (dir === '') return { status: 'arm 失败', detail: '需要 dir' }
|
|
186
|
-
arm(ctx, dir, args.session_id === undefined || clean(args.session_id) === '' ? null : clean(args.session_id))
|
|
197
|
+
const bound = arm(ctx, dir, args.session_id === undefined || clean(args.session_id) === '' ? null : clean(args.session_id))
|
|
198
|
+
if (!bound) return { status: 'arm 失败', detail: `无法观察 ${join(dir, 'state')}(详见日志);先修好目录或权限再重试` }
|
|
187
199
|
return { status: '已绑定', detail: `${dir}/state/pending.json → ${state.sessionId ?? '(由 pending.json 自带 sessionId)'}` }
|
|
188
200
|
}
|
|
189
201
|
if (args.action === 'disarm') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fish-under-sea/dsh-visual-companion",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "把「视觉伴侣页面上的提交」变成一条用户消息:用户在网页上点选、写备注、按提交,DSH 会话自动起一轮继续工作,不必回终端复述。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
"optional": true
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@deepseek-ai/dsh-llm": "0.2.0-rc.2",
|
|
44
|
+
"@deepseek-ai/dsh-tools": "0.2.0-rc.2",
|
|
45
|
+
"@deepseek-ai/schemastery": "^3.18.2"
|
|
46
|
+
},
|
|
42
47
|
"keywords": [
|
|
43
48
|
"dsh",
|
|
44
49
|
"dsh-plugin",
|