dsh-mobile-plugin 0.5.125 → 0.5.126

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/lib/impl.js CHANGED
@@ -431,6 +431,7 @@ function apply(ctx) {
431
431
  controlTarget: () => (state.controlToken && state.instanceId
432
432
  ? { baseUrl: CONTROL_BASE_URL, token: state.controlToken, instanceId: state.instanceId }
433
433
  : null),
434
+ workspaceIdOf: ({ sessionId }) => require('./mobile/workspace-id.js').workspaceIdOf(ctx, { sessionId }),
434
435
  })
435
436
  // 镜像推送调度器:会话事件立即推,后台循环每个 tick 补推一个冷会话;凭据摘要由装配层给取值器(凭据库归本进程),中转靠它认离线缓存的读者。
436
437
  mirror = createMirrorPusher({ ctx, tunnelConnected, getSidecar: sidecarLifecycle.getSidecar, lastMobileAt: activity.snapshot, credentialDigests: () => credentials.activeDigests(state.instanceId), getHistoryKey, notifyTurnEnded: pushNotify.notifyTurnEnded })
@@ -1236,7 +1236,7 @@ function createMirrorPusher(deps) {
1236
1236
  // 标题从镜像快照现查:中转与苹果都只认纯文本,没查到就用会话 id 前缀。
1237
1237
  if (p?.event?.type === 'turn/end' && notifyTurnEnded) {
1238
1238
  const fact = lastTurnOf(ctx, sessionId);
1239
- if (fact) notifyTurnEnded(sessionId, fact, sessionTitleOf(sessionId));
1239
+ if (fact) void notifyTurnEnded(sessionId, fact, sessionTitleOf(sessionId));
1240
1240
  }
1241
1241
  void pushSessionImmediately(sessionId);
1242
1242
  }
@@ -1,3 +1,4 @@
1
+ // 2026-11-27:上游明确说不支持 tools 时回专用短码,手机据此降级去掉工具重试。
1
2
  // 2026-11-26:手机够不着的渠道,由电脑代发模型请求(只转发模型调用,会话仍在手机上)。
2
3
  // 2026-11-26:自建渠道查不到时退回 DSH 自己的模型服务,当前 DSH 渠道也能经电脑代发。
3
4
  'use strict';
@@ -190,6 +191,12 @@ function dshToolsOf(raw) {
190
191
  function dshErrorCodeOf(reason) {
191
192
  const failure = reason && reason.failure && typeof reason.failure === 'object' ? reason.failure : {};
192
193
  const status = Number(failure.status);
194
+ // 只有明确提到 tools / function / tool_calls 的 400 才算「不支持工具」;鉴权、限流、渠道缺失各走各的短码。
195
+ const detail = [failure.message, failure.body, failure.detail]
196
+ .flatMap((value) => typeof value === 'string' ? [value] : value && typeof value === 'object' ? [JSON.stringify(value)] : [])
197
+ .join(' ')
198
+ .toLowerCase();
199
+ if (status === 400 && /\btools?\b|\bfunctions?\b|tool_calls/.test(detail)) return 'tools-unsupported';
193
200
  if (status === 401 || status === 403) return 'http-401';
194
201
  if (status === 429) return 'http-429';
195
202
  if (status === 404) return 'http-404';
@@ -1,3 +1,4 @@
1
+ // 任务通知监控条目携带精确工作区归属,供本地与 APNs 偏好按层级解析。
1
2
  'use strict';
2
3
 
3
4
  /**
@@ -29,6 +30,7 @@ const { pendingFailedTurns } = require('./recent-failures.js');
29
30
  const { sessionPreviewFor } = require('./session-preview.js');
30
31
  const { archivedSessionIdsForMonitor, pendingInteractionOf, pendingCardOf } = require('./session-flags.js');
31
32
  const { withActiveParents } = require('./session-active.js');
33
+ const { workspaceIdOfRows, workspaceRows } = require('./workspace-id.js');
32
34
 
33
35
  /**
34
36
  * 一条会话在监控视图里的那几格。
@@ -42,7 +44,7 @@ const { withActiveParents } = require('./session-active.js');
42
44
  * 一字不差),只在那几条待处理的条目上带 —— 手机回前台时先问原生要它,就不必等流重新
43
45
  * 接上才有卡(见 `session-flags.js` 的 pendingCardOf)。拿不到都不出字段。
44
46
  */
45
- function monitorItem(summary, state, fact) {
47
+ function monitorItem(summary, state, fact, workspaceId = '') {
46
48
  const running = summary.running === true;
47
49
  // 完成/失败优先用**上一轮事实**(`session-last-turn`),不再等 `state.completed`。
48
50
  //
@@ -59,6 +61,7 @@ function monitorItem(summary, state, fact) {
59
61
  : (state ? state.completed === true : false);
60
62
  const item = {
61
63
  sessionId: summary.sessionId,
64
+ workspaceId: workspaceId || '',
62
65
  title: listTitle(summary),
63
66
  running,
64
67
  completed,
@@ -171,10 +174,12 @@ async function buildMonitorState(ctx, deviceKey, extraItems = null, scopeSession
171
174
  }));
172
175
  }
173
176
 
177
+ const workspaceRowsSnapshot = await workspaceRows(ctx);
174
178
  const items = live.map((summary) => monitorItem(
175
179
  summary,
176
180
  states.get(summary.sessionId),
177
181
  lastTurnOf(ctx, summary.sessionId),
182
+ workspaceIdOfRows(workspaceRowsSnapshot, summary),
178
183
  ));
179
184
  // 可能要提醒的那几条补一句「这一轮跑出了什么」:只在完成 / 失败 / 待回话的条目上取,
180
185
  // 走 sessionPreviewFor 的缓存;常态(全在跑 / 全闲且已读)一条 history 都不读。
@@ -1,3 +1,4 @@
1
+ // APNs 事件携带精确工作区归属,总控据每台手机的偏好逐设备过滤。
1
2
  'use strict';
2
3
 
3
4
  /**
@@ -42,6 +43,18 @@ const INTERACTION_TTL_MS = 30_000;
42
43
  */
43
44
  function createPushNotifier(deps) {
44
45
  const controlTarget = typeof deps.controlTarget === 'function' ? deps.controlTarget : () => null;
46
+ const resolveWorkspaceId = typeof deps.workspaceIdOf === 'function'
47
+ ? deps.workspaceIdOf
48
+ : async () => '';
49
+
50
+ async function workspaceIdOf(sessionId) {
51
+ try {
52
+ const value = await resolveWorkspaceId({ sessionId });
53
+ return typeof value === 'string' ? value.trim() : '';
54
+ } catch {
55
+ return '';
56
+ }
57
+ }
45
58
 
46
59
  /** 已经发出去的帧:key → { at, approvalId? }。key 是 `${sessionId}:${rpcId}`(卡)或
47
60
  * `${sessionId}:${turn}:${status}`(轮次)。同一次收尾会被事件流与列表折叠两条路各观察到
@@ -129,7 +142,7 @@ function createPushNotifier(deps) {
129
142
  * 报告一轮收尾。`fact` 是 session-last-turn 的 `lastTurnOf` 形状
130
143
  * ({ turn, endedAt, status, ... }),只有 completed / failed 两种值得推。
131
144
  */
132
- function notifyTurnEnded(sessionId, fact, title) {
145
+ async function notifyTurnEnded(sessionId, fact, title) {
133
146
  if (!sessionId || !fact || typeof fact.turn !== 'number') return;
134
147
  if (fact.status !== 'completed' && fact.status !== 'failed') return;
135
148
  const fingerprint = `${sessionId}:${fact.turn}:${fact.status}`;
@@ -138,12 +151,14 @@ function createPushNotifier(deps) {
138
151
  // (没有通知服务扩展),而这个列表在电脑上、读它的手机可能被设成十门语言里的任一门。
139
152
  // 所以标题是会话名(用户自己起的),正文只给「成没成」一个符号。
140
153
  const body = fact.status === 'failed' ? '✗' : '✓';
141
- // 推给这台实例登记过的全部手机:按设备记账在 App 自己手里(本机已读水位),
142
- // 总控只存「实例 + 设备 → 令牌」一级。
154
+ const workspaceId = await workspaceIdOf(sessionId);
155
+ // 推给这台实例登记过的全部手机:总控按每台手机保存的偏好逐设备过滤。
143
156
  void pushFrame(fingerprint, {
144
157
  title: title || String(sessionId).slice(0, 8),
145
158
  body,
146
159
  sessionId,
160
+ workspaceId,
161
+ kind: fact.status === 'failed' ? 'failed' : 'completed',
147
162
  }, { kind: fact.status === 'failed' ? 'failed' : 'completed', sessionId });
148
163
  }
149
164
 
@@ -182,7 +197,7 @@ function createPushNotifier(deps) {
182
197
  * 前两样是审批卡上的展示信息(事实行 / 那一行高亮),通知栏里得原样带上,否则手机在后台
183
198
  * 看到的还是没长事实行的那张卡。`title` 是会话名。
184
199
  */
185
- function notifyInteraction(sessionId, card, hints = {}) {
200
+ async function notifyInteraction(sessionId, card, hints = {}) {
186
201
  if (!sessionId || !card || typeof card !== 'object') return;
187
202
  // 第三参早先就是「标题」一个字符串;现在扩成带提示的对象,字符串按标题认。
188
203
  const hint = typeof hints === 'string'
@@ -259,10 +274,13 @@ function createPushNotifier(deps) {
259
274
  const category = kind === 'approval'
260
275
  ? 'dsh.approval'
261
276
  : (answerable ? 'dsh.question' : 'dsh.pending');
277
+ const workspaceId = await workspaceIdOf(sessionId);
262
278
  return pushFrame(fingerprint, {
263
279
  title: hint.title || String(sessionId).slice(0, 8),
264
280
  body: summary,
265
281
  sessionId,
282
+ workspaceId,
283
+ kind: 'pending',
266
284
  category,
267
285
  interaction,
268
286
  }, { kind, sessionId, approvalId }, upgrade);
@@ -0,0 +1,40 @@
1
+ // 任务提醒按精确证据解析会话的工作区归属:显式 workspaceId、唯一会话归属、唯一路径。
2
+ 'use strict';
3
+
4
+ function normalizePath(value) {
5
+ return typeof value === 'string' ? value.trim().replace(/[\\/]+$/, '') : '';
6
+ }
7
+
8
+ function workspaceIdOfRows(rows, summary) {
9
+ if (summary && typeof summary.workspaceId === 'string' && summary.workspaceId.trim()) return summary.workspaceId.trim();
10
+ const sessionId = summary && typeof summary.sessionId === 'string' ? summary.sessionId : '';
11
+ const cwd = normalizePath(summary && summary.cwd);
12
+ const items = Array.isArray(rows) ? rows : [];
13
+ const bySession = items.filter((row) => row && Array.isArray(row.sessionIds) && sessionId && row.sessionIds.includes(sessionId));
14
+ if (bySession.length === 1) return typeof bySession[0].workspaceId === 'string' ? bySession[0].workspaceId.trim() : '';
15
+ if (bySession.length > 1) return '';
16
+ if (!cwd) return '';
17
+ const byPath = items.filter((row) => normalizePath(row && (row.path || row.cwd)) === cwd);
18
+ if (byPath.length === 1) return typeof byPath[0].workspaceId === 'string' ? byPath[0].workspaceId.trim() : '';
19
+ return '';
20
+ }
21
+
22
+ async function workspaceRows(ctx, signal) {
23
+ const registry = ctx && ctx.get && ctx.get('workspaceRegistry');
24
+ if (registry && typeof registry.list === 'function') {
25
+ try { return registry.list().map((row) => ({ workspaceId: row.id, path: row.path, sessionIds: [...(row.sessionIds || [])] })); } catch { return []; }
26
+ }
27
+ try {
28
+ const { workspaceListViaFollow } = require('./host-bridge/shims.js');
29
+ const result = await workspaceListViaFollow(ctx, signal);
30
+ const value = result && result.value;
31
+ return value && Array.isArray(value.items) ? value.items : [];
32
+ } catch { return []; }
33
+ }
34
+
35
+ async function workspaceIdOf(ctx, summary, signal) {
36
+ if (summary && typeof summary.workspaceId === 'string' && summary.workspaceId.trim()) return summary.workspaceId.trim();
37
+ return workspaceIdOfRows(await workspaceRows(ctx, signal), summary);
38
+ }
39
+
40
+ module.exports = { normalizePath, workspaceIdOfRows, workspaceRows, workspaceIdOf };