dsh-miloco-bridge 0.1.2 → 0.1.4

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 CHANGED
@@ -48,7 +48,7 @@ dsh plugin --profile web add github:exa160/dsh-miloco-bridge
48
48
 
49
49
  ```bash
50
50
  # 发布包
51
- dsh plugin --profile web add file:dist/dsh-miloco-bridge-0.1.2.tgz
51
+ dsh plugin --profile web add file:dist/dsh-miloco-bridge-0.1.4.tgz
52
52
 
53
53
  # 本地开发(link)
54
54
  ./install.sh --profile web
@@ -102,7 +102,7 @@ systemctl --user restart dsh-web.service
102
102
  ## 开发
103
103
 
104
104
  ```bash
105
- npm test # 76 项测试
105
+ npm test # 78 项测试
106
106
  npm run selftest # 离线自检
107
107
  npm run verify:readonly # 真实 Miloco 只读接口
108
108
  npm run pack:bundle # 生成 dist/*.tgz
package/cordis.patch.yml CHANGED
@@ -141,14 +141,13 @@
141
141
  config:
142
142
  - id: tool-subagent-control
143
143
  name: '@deepseek-ai/dsh-tool-subagent-control'
144
- - id: tool-subagent-list-agents
145
- name: '@deepseek-ai/dsh-tool-subagent-control/list-agents'
146
144
  - id: tool-subagent
147
145
  name: '@deepseek-ai/dsh-tool-subagent'
148
146
  config:
149
147
  provider: spawn
150
148
  toolName: subagent
151
- modelSelectionSettings: true
149
+ modelSelection: true
150
+ modelDiscovery: true
152
151
  - id: tool-subagent-fork
153
152
  name: '@deepseek-ai/dsh-tool-subagent'
154
153
  config:
package/docs/INSTALL.md CHANGED
@@ -33,14 +33,14 @@ npm 新包可能处于审核期;若 `dsh plugin add dsh-miloco-bridge` 暂时
33
33
 
34
34
  ```bash
35
35
  npm run pack:bundle
36
- # dist/dsh-miloco-bridge-0.1.2.tgz
37
- dsh plugin --profile web add "file:/path/to/dist/dsh-miloco-bridge-0.1.2.tgz"
36
+ # dist/dsh-miloco-bridge-0.1.4.tgz
37
+ dsh plugin --profile web add "file:/path/to/dist/dsh-miloco-bridge-0.1.4.tgz"
38
38
  ```
39
39
 
40
40
  或:
41
41
 
42
42
  ```bash
43
- ./install.sh --profile web --bundle dist/dsh-miloco-bridge-0.1.2.tgz
43
+ ./install.sh --profile web --bundle dist/dsh-miloco-bridge-0.1.4.tgz
44
44
  ```
45
45
 
46
46
  ### 1.3 手动配置
@@ -273,7 +273,7 @@ systemctl --user restart dsh-web.service
273
273
 
274
274
  ```bash
275
275
  npm run pack:bundle
276
- dsh plugin --profile web add "file:dist/dsh-miloco-bridge-0.1.2.tgz"
276
+ dsh plugin --profile web add "file:dist/dsh-miloco-bridge-0.1.4.tgz"
277
277
  systemctl --user restart dsh-web.service
278
278
  ```
279
279
 
@@ -220,7 +220,7 @@ dsh-miloco-bridge: push delivery failed ... # 仅在失败时
220
220
 
221
221
  ```bash
222
222
  npm run pack:bundle
223
- tar -tzf dist/dsh-miloco-bridge-0.1.2.tgz | head -30
223
+ tar -tzf dist/dsh-miloco-bridge-0.1.4.tgz | head -30
224
224
  ```
225
225
 
226
226
  预期包含:`package/lib/*`、`package/skills/*/SKILL.md`、`package/adapter/dsh_adapter.py`、
@@ -230,7 +230,7 @@ tar -tzf dist/dsh-miloco-bridge-0.1.2.tgz | head -30
230
230
 
231
231
  ```bash
232
232
  DSH_HOME=/tmp/dsh-miloco-bundle-verify \
233
- dsh plugin --profile web add "file:$PWD/dist/dsh-miloco-bridge-0.1.2.tgz"
233
+ dsh plugin --profile web add "file:$PWD/dist/dsh-miloco-bridge-0.1.4.tgz"
234
234
  ```
235
235
 
236
236
  ---
package/lib/client.js CHANGED
@@ -473,6 +473,8 @@ window.__ModuleLoader__.load({
473
473
  const [busy, setBusy] = React.useState(false)
474
474
  const [saved, setSaved] = React.useState(null)
475
475
  const [sessionId, setSessionId] = React.useState('')
476
+ const [sessionInput, setSessionInput] = React.useState('')
477
+ const sessionFocusCleared = React.useRef(false)
476
478
  const [modelValue, setModelValue] = React.useState('')
477
479
  const [reasoningEffort, setReasoningEffort] = React.useState('')
478
480
  const [deployLog, setDeployLog] = React.useState('')
@@ -503,7 +505,10 @@ window.__ModuleLoader__.load({
503
505
  call('/status')
504
506
  .then((payload) => {
505
507
  setStatus(payload)
506
- setSessionId(payload.overlay?.push?.target?.sessionId ?? '')
508
+ const targetSession = payload.overlay?.push?.target?.sessionId ?? ''
509
+ setSessionId(targetSession)
510
+ setSessionInput(targetSession)
511
+ sessionFocusCleared.current = false
507
512
  const provider = payload.overlay?.push?.model?.provider ?? ''
508
513
  const model = payload.overlay?.push?.model?.model ?? ''
509
514
  setModelValue(provider && model ? `${provider}/${model}` : '')
@@ -855,6 +860,12 @@ window.__ModuleLoader__.load({
855
860
 
856
861
  // ---------------------------------------------------------------- 推送目标
857
862
  const lastSession = status.lastMilocoSession ?? ''
863
+ const selectedSession = (status.sessions ?? []).find(session => session.id === sessionId)
864
+ const sessionPlaceholder = sessionInput === '' && sessionId
865
+ ? `当前:${selectedSession?.title || sessionId};输入搜索或会话 id`
866
+ : lastSession
867
+ ? `留空 = 上一次触发 miloco 的会话(${lastSession})`
868
+ : '留空 = 上一次触发 miloco 的会话(还没有)'
858
869
  const selectedEfforts = effortOptions(status, modelValue)
859
870
  const effortValue = selectedEfforts.some(item => item.id === reasoningEffort)
860
871
  ? reasoningEffort
@@ -867,11 +878,32 @@ window.__ModuleLoader__.load({
867
878
  h('input', {
868
879
  type: 'text',
869
880
  list: SESSION_LIST_ID,
870
- value: sessionId,
871
- placeholder: lastSession
872
- ? `留空 = 上一次触发 miloco 的会话(${lastSession})`
873
- : '留空 = 上一次触发 miloco 的会话(还没有)',
874
- onChange: (event) => setSessionId(event.target.value),
881
+ value: sessionInput,
882
+ placeholder: sessionPlaceholder,
883
+ onFocus: () => {
884
+ if (sessionId) {
885
+ sessionFocusCleared.current = true
886
+ setSessionInput('')
887
+ }
888
+ },
889
+ onChange: (event) => {
890
+ const value = event.target.value
891
+ sessionFocusCleared.current = false
892
+ setSessionInput(value)
893
+ if (!value || (status.sessions ?? []).some(session => session.id === value)) {
894
+ setSessionId(value)
895
+ }
896
+ },
897
+ onBlur: () => {
898
+ const value = sessionInput.trim()
899
+ if (sessionFocusCleared.current && value === '') {
900
+ setSessionInput(sessionId)
901
+ } else {
902
+ setSessionId(value)
903
+ setSessionInput(value)
904
+ }
905
+ sessionFocusCleared.current = false
906
+ },
875
907
  }),
876
908
  h('datalist', { id: SESSION_LIST_ID }, sessionOptions(status)),
877
909
  h('button', { type: 'button', disabled: busy, onClick: refreshSessions }, '刷新会话'))),
package/lib/index.js CHANGED
@@ -112,6 +112,20 @@ export function normalizeConfig(raw) {
112
112
  }
113
113
  }
114
114
 
115
+ /**
116
+ * Whether the context can still own new effects.
117
+ *
118
+ * Cordis clears `uid` on disposal and moves `state` to 5 on unload. A plugin
119
+ * whose async work outlives its scope must stop before calling `effect`.
120
+ *
121
+ * @param {any} ctx - Cordis context.
122
+ * @returns {boolean} True while the fiber is loadable.
123
+ */
124
+ function fiberActive(ctx) {
125
+ const fiber = ctx?.fiber
126
+ return fiber === undefined || (fiber.uid !== null && fiber.state !== 5)
127
+ }
128
+
115
129
  /**
116
130
  * Activate the infra half.
117
131
  * @param {any} ctx - Cordis context.
@@ -132,8 +146,24 @@ export function apply(ctx, rawConfig) {
132
146
  })
133
147
 
134
148
  ctx.inject(['sessionController', 'webServer', 'sandboxPolicy'], (host) => {
149
+ /** @type {(() => void)[]} */
150
+ const pushDisposers = []
151
+ // Claim the cleanup effect before the dynamic import starts: the scope may
152
+ // be disposed while the import is pending, and an effect registered
153
+ // afterwards throws INACTIVE_EFFECT inside a detached promise.
154
+ host.effect(() => () => {
155
+ for (const dispose of pushDisposers.splice(0).reverse()) {
156
+ try {
157
+ dispose()
158
+ } catch (error) {
159
+ host.logger?.warn?.(`dsh-miloco-bridge: 卸载推送服务失败:${error instanceof Error ? error.message : error}`)
160
+ }
161
+ }
162
+ }, 'dsh-miloco-bridge: push service')
163
+
135
164
  // 推送服务:Miloco → DSH 的入站通路。
136
165
  void import('./push.js').then(({ createPushService }) => {
166
+ if (!fiberActive(host)) return
137
167
  const push = createPushService({
138
168
  ctx: host,
139
169
  config,
@@ -147,8 +177,10 @@ export function apply(ctx, rawConfig) {
147
177
  },
148
178
  })
149
179
  push.register()
150
- host.effect(() => push.dispose, 'dsh-miloco-bridge: push service')
180
+ pushDisposers.push(push.dispose)
151
181
  host.logger?.info?.(`dsh-miloco-bridge: 推送目标覆盖文件 ${config.overlayFile}`)
182
+ }).catch((error) => {
183
+ host.logger?.warn?.(`dsh-miloco-bridge: 加载推送服务失败:${error instanceof Error ? error.message : error}`)
152
184
  })
153
185
 
154
186
  const deploy = createDeployService({ config, logger: host.logger, overlay })
package/lib/skills.js CHANGED
@@ -69,8 +69,9 @@ export async function registerSkills(ctx, logger) {
69
69
 
70
70
  for (const directory of entries.sort()) {
71
71
  let text
72
+ const skillFile = join(SKILLS_DIR, directory, 'SKILL.md')
72
73
  try {
73
- text = await readFile(join(SKILLS_DIR, directory, 'SKILL.md'), 'utf8')
74
+ text = await readFile(skillFile, 'utf8')
74
75
  } catch {
75
76
  logger?.warn?.(`dsh-miloco-bridge: 技能 ${directory} 缺少 SKILL.md,已跳过`)
76
77
  continue
@@ -87,6 +88,13 @@ export async function registerSkills(ctx, logger) {
87
88
  name,
88
89
  description,
89
90
  content: body,
91
+ // DSH requires a string `source` on every loaded skill definition;
92
+ // runtime registrations without one fail with
93
+ // `loaded skill "<name>" source must be a string`.
94
+ // `source` is prompt-visible metadata, so use a stable label instead
95
+ // of the absolute file path (which `path` already carries for the UI).
96
+ source: 'dsh-miloco-bridge',
97
+ path: skillFile,
90
98
  ...(data.whenToUse ? { whenToUse: data.whenToUse } : {}),
91
99
  }))
92
100
  } catch (error) {
@@ -83,6 +83,20 @@ export function normalizeConfig(raw) {
83
83
  }
84
84
  }
85
85
 
86
+ /**
87
+ * Whether the context can still own new effects.
88
+ *
89
+ * Cordis clears `uid` on disposal and moves `state` to 5 on unload. A plugin
90
+ * whose async work outlives its scope must stop before calling `effect`.
91
+ *
92
+ * @param {any} ctx - Cordis context.
93
+ * @returns {boolean} True while the fiber is loadable.
94
+ */
95
+ function fiberActive(ctx) {
96
+ const fiber = ctx?.fiber
97
+ return fiber === undefined || (fiber.uid !== null && fiber.state !== 5)
98
+ }
99
+
86
100
  /**
87
101
  * Read the session id from a tool execution.
88
102
  * @param {any} exec - Tool execution context.
@@ -118,6 +132,9 @@ export async function apply(ctx, rawConfig) {
118
132
  // Runtime mode: state file first (written by the Web tab), static config as
119
133
  // fallback. The two halves live in different scopes, hence the shared file.
120
134
  const persisted = await state.read().catch(() => ({}))
135
+ // The preset can be torn down while that read is pending (for example when a
136
+ // sibling row fails to load). Registering tools on a disposed context throws.
137
+ if (!fiberActive(ctx)) return
121
138
  const persistedMode = typeof persisted.mode === 'string'
122
139
  ? persisted.mode
123
140
  : (config.readOnly === false ? 'full' : 'readonly')
@@ -182,15 +199,32 @@ export async function apply(ctx, rawConfig) {
182
199
  // ------------------------------------------------------------------ 技能
183
200
 
184
201
  ctx.inject(['skills'], (host) => {
185
- void registerSkills(host, host.logger).then((skillDisposers) => {
186
- host.effect(() => () => {
187
- for (const dispose of skillDisposers) {
202
+ /** @type {(() => void)[]} */
203
+ const skillDisposers = []
204
+ // Claim the cleanup effect before the async reads start: the scope may be
205
+ // disposed while a read is pending, and an effect registered afterwards
206
+ // throws INACTIVE_EFFECT inside a detached promise.
207
+ host.effect(() => () => {
208
+ for (const dispose of skillDisposers.splice(0)) {
209
+ try {
210
+ dispose()
211
+ } catch { /* 卸载期忽略 */ }
212
+ }
213
+ }, 'dsh-miloco-bridge: skills')
214
+
215
+ void registerSkills(host, host.logger).then((registered) => {
216
+ if (!fiberActive(host)) {
217
+ for (const dispose of registered) {
188
218
  try {
189
219
  dispose()
190
- } catch { /* 卸载期忽略 */ }
220
+ } catch { /* 作用域已销毁 */ }
191
221
  }
192
- }, 'dsh-miloco-bridge: skills')
193
- host.logger?.info?.(`dsh-miloco-bridge: 已注册 ${skillDisposers.length} 个技能`)
222
+ return
223
+ }
224
+ skillDisposers.push(...registered)
225
+ host.logger?.info?.(`dsh-miloco-bridge: 已注册 ${registered.length} 个技能`)
226
+ }).catch((error) => {
227
+ host.logger?.warn?.(`dsh-miloco-bridge: 注册技能失败:${error instanceof Error ? error.message : error}`)
194
228
  })
195
229
  })
196
230
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-miloco-bridge",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Unofficial DSH bridge for Xiaomi Miloco: an isolated Agent preset for Miloco tools, native tools/skills, Web settings, perception-priority filtering, and Miloco -> DSH push.",
5
5
  "keywords": [
6
6
  "dsh",