@duke-dsh-plugins/dsh-remote-control 1.1.6 → 1.1.7

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.
@@ -859,6 +859,8 @@ export class HostBridge {
859
859
  // 原始 chunk 顺序发 assistant.delta / assistant.reasoningDelta(跨类型也保序)。
860
860
  #streamBuf = new Map();
861
861
  #modelSelections = new Map(); // sessionId -> {provider, model, reasoningEffort?}(v1.0.8 内存态)
862
+ // v1.1.7:有效权限的直播兜底;权威查询仍优先走 permissions 持久投影。
863
+ #permissionSelections = new Map(); // sessionId -> string(含派生态 custom)
862
864
  #pending = new Map(); // askId -> { resolve, kind, sessionId, timer, abortHandler, signal }
863
865
  #titles = new Map(); // sessionId -> title(turn.end 推送文案用)
864
866
  #pushToken = ""; // 手机 push.register 上报的 token(内存态)
@@ -929,6 +931,7 @@ export class HostBridge {
929
931
  this.#on("api-session/removed", (sessionId) => {
930
932
  const key = String(sessionId);
931
933
  this.#titles.delete(key);
934
+ this.#permissionSelections.delete(key);
932
935
  // 会话没了,它的待执行列表与交付物历史条目也没有意义了(避免内存泄漏)
933
936
  this.#queues.delete(key);
934
937
  this.#deliveredEntries.delete(key);
@@ -1046,6 +1049,13 @@ export class HostBridge {
1046
1049
  this.#sendEvent("session.modelChanged", { sessionId, model: selection });
1047
1050
  return;
1048
1051
  }
1052
+ if (type === "permission/preset" || type === "sandbox/mode" || type === "approval/policy") {
1053
+ // v1.1.7:桌面端当前权限由这三类 knob 事件共同折叠,不是单看 preset。
1054
+ // current(session) 与桌面端 permissions.currentValue 投影共用同一 derive;
1055
+ // 因而直接改 sandbox/approval 导致的 custom 也能同步到手机。
1056
+ this.#emitPermissionChanged(session, event);
1057
+ return;
1058
+ }
1049
1059
  if (type === "assistant/message") {
1050
1060
  // v1.0.9(§5.10):助手消息里的图片 → 广播 assistant.image(带内联缩略图)。
1051
1061
  // 即便本条没有图片,也先把之前的流式文本/思考冲出去,保持时间线顺序。
@@ -1088,6 +1098,35 @@ export class HostBridge {
1088
1098
  return () => this.dispose();
1089
1099
  }
1090
1100
 
1101
+ /**
1102
+ * 权限 knob 变化 → session.permissionChanged(v1.1.7)。
1103
+ * 新宿主用 permissionPresets.current(session) 取有效值;旧宿主没有 current 时,
1104
+ * 只在明确的 permission/preset 事件上回退其 preset,不对 sandbox/approval 臆造值。
1105
+ */
1106
+ #emitPermissionChanged(session, event) {
1107
+ const sessionId = String(session?.id ?? "");
1108
+ if (sessionId === "") return;
1109
+ const svc = this.#service("permissionPresets");
1110
+ let permission = null;
1111
+ if (svc && typeof svc.current === "function") {
1112
+ try {
1113
+ const current = svc.current(session);
1114
+ if (typeof current === "string" && current !== "") permission = current;
1115
+ } catch (e) {
1116
+ this.#log("warn", "permission current failed; change event skipped", {
1117
+ sessionId,
1118
+ error: errText(e),
1119
+ });
1120
+ }
1121
+ } else if (event?.type === "permission/preset") {
1122
+ const preset = event?.data?.preset;
1123
+ if (typeof preset === "string" && preset !== "") permission = preset;
1124
+ }
1125
+ if (permission === null) return;
1126
+ this.#permissionSelections.set(sessionId, permission);
1127
+ this.#sendEvent("session.permissionChanged", { sessionId, permission });
1128
+ }
1129
+
1091
1130
  /** 广播归档全集(契约 §5.2 session.archives)。没有注册表 → 不发。 */
1092
1131
  #broadcastArchives() {
1093
1132
  const ids = this.#archivedSessionIds();
@@ -1809,6 +1848,10 @@ export class HostBridge {
1809
1848
  return await this.#rSessionSelectModel(m);
1810
1849
  case "session.model":
1811
1850
  return await this.#rSessionModel(m);
1851
+ case "session.selectPermission":
1852
+ return await this.#rSessionSelectPermission(m);
1853
+ case "session.permission":
1854
+ return await this.#rSessionPermission(m);
1812
1855
  case "session.queue":
1813
1856
  return this.#rSessionQueue(m);
1814
1857
  case "session.archive":
@@ -2467,6 +2510,146 @@ export class HostBridge {
2467
2510
  this.#reply(m, resultOf(m, { model: this.#modelSelections.get(sessionId) ?? null }));
2468
2511
  }
2469
2512
 
2513
+ /** 契约 §5.1/§5.8(v1.1.7)session.selectPermission:切换已存在会话的权限。
2514
+ * Host 不做根会话/subagent 的额外限制(App 自行限制入口);未知 preset、Auto 准入
2515
+ * 与 resolveAgent 的宿主拒绝均按原错误码/原文回传,绝不在本机假成功。 */
2516
+ async #rSessionSelectPermission(m) {
2517
+ const p = m.payload ?? {};
2518
+ const sessionId = typeof p.sessionId === "string" ? p.sessionId : "";
2519
+ const permission = typeof p.permission === "string" ? p.permission.trim() : "";
2520
+ if (sessionId === "" || permission === "") {
2521
+ this.#reply(m, errorOf(m, "bad-params", "sessionId and permission required"));
2522
+ return;
2523
+ }
2524
+ const svc = this.#service("permissionPresets");
2525
+ if (!svc || typeof svc.set !== "function") {
2526
+ this.#reply(m, errorOf(m, "service-unavailable", "permissionPresets.set unavailable"));
2527
+ return;
2528
+ }
2529
+ let sc = null;
2530
+ try {
2531
+ sc = this.#sc();
2532
+ } catch (e) {
2533
+ this.#reply(m, errorOf(m, "service-unavailable", errText(e)));
2534
+ return;
2535
+ }
2536
+ if (typeof sc.resolveAgent !== "function") {
2537
+ this.#reply(m, errorOf(m, "service-unavailable", "sessionController.resolveAgent unavailable"));
2538
+ return;
2539
+ }
2540
+ let session = null;
2541
+ try {
2542
+ const agentRes = await sc.resolveAgent(sessionId);
2543
+ // 与创建时一致:兼容直接 Agent、{agent} 与旧版 {error};拒绝不得改写。
2544
+ if (agentRes?.error) throw agentRes.error;
2545
+ session = agentRes?.agent?.session ?? agentRes?.session ?? null;
2546
+ if (!session) {
2547
+ this.#reply(m, errorOf(m, "session-not-found", `session "${sessionId}" has no live agent`));
2548
+ return;
2549
+ }
2550
+ } catch (e) {
2551
+ const err = hostErrorOf(e, "session-select-permission-failed");
2552
+ this.#log("warn", "resolveAgent for selectPermission failed", { sessionId, code: err.code });
2553
+ this.#reply(m, errorOf(m, err.code, err.message));
2554
+ return;
2555
+ }
2556
+ try {
2557
+ await svc.set(session, permission);
2558
+ } catch (e) {
2559
+ const err = hostErrorOf(e, "session-select-permission-failed");
2560
+ this.#log("warn", "selectPermission failed", { sessionId, code: err.code });
2561
+ this.#reply(m, errorOf(m, err.code, err.message));
2562
+ return;
2563
+ }
2564
+ // set() 已成功即不能把它伪装成失败。新宿主回读有效值(与桌面端同 derive),
2565
+ // 旧宿主没有 current() 时回显刚被 set 接受的 preset。
2566
+ let selected = permission;
2567
+ if (typeof svc.current === "function") {
2568
+ try {
2569
+ const current = svc.current(session);
2570
+ if (typeof current === "string" && current !== "") selected = current;
2571
+ } catch (e) {
2572
+ this.#log("warn", "permission current readback failed; returning accepted preset", {
2573
+ sessionId,
2574
+ error: errText(e),
2575
+ });
2576
+ }
2577
+ }
2578
+ this.#permissionSelections.set(sessionId, selected);
2579
+ this.#reply(m, resultOf(m, { permission: selected }));
2580
+ }
2581
+
2582
+ /** 契约 §5.1/§5.8(v1.1.7)session.permission:查询有效权限。
2583
+ * 权威来源是 permissions 持久投影 values.permissions.currentValue(桌面端同源),
2584
+ * 因而根会话与 subagent 都可冷读,且不要求激活 live Agent。投影不可用时依次退回
2585
+ * permissionPresets.current(liveSession) 与直播内存态;全部不可用回 null,不臆造。 */
2586
+ async #rSessionPermission(m) {
2587
+ const p = m.payload ?? {};
2588
+ const sessionId = typeof p.sessionId === "string" ? p.sessionId : "";
2589
+ if (sessionId === "") {
2590
+ this.#reply(m, errorOf(m, "bad-params", "sessionId required"));
2591
+ return;
2592
+ }
2593
+ try {
2594
+ const sc = this.#sc();
2595
+ if (typeof sc.projections === "function") {
2596
+ const projections = await sc.projections({ sessionId }, this.#signal(10_000));
2597
+ const view = projections?.values?.permissions;
2598
+ if (view !== undefined && view !== null) {
2599
+ const permission =
2600
+ typeof view.currentValue === "string" && view.currentValue !== "" ? view.currentValue : null;
2601
+ if (permission !== null) this.#permissionSelections.set(sessionId, permission);
2602
+ this.#reply(m, resultOf(m, { permission }));
2603
+ return;
2604
+ }
2605
+ }
2606
+ } catch (e) {
2607
+ this.#log("warn", "permissions projection unavailable; falling back to live tracking", {
2608
+ sessionId,
2609
+ error: errText(e),
2610
+ });
2611
+ }
2612
+
2613
+ // 旧宿主没有 permissions 投影时,live Session 的 current() 仍是有效值权威来源。
2614
+ // 但 subagent 查询绝不能为了兜底而激活 Agent:先用 inspect 冷读身份,命中即只回内存态。
2615
+ try {
2616
+ const svc = this.#service("permissionPresets");
2617
+ const sc = this.#sc();
2618
+ let coldSubagent = false;
2619
+ if (typeof sc.inspect === "function") {
2620
+ try {
2621
+ const inspected = await sc.inspect(sessionId, this.#signal(10_000));
2622
+ const meta = inspected?.meta;
2623
+ coldSubagent = meta?.origin === "subagent" ||
2624
+ (typeof meta?.parentSessionId === "string" && meta.parentSessionId !== "");
2625
+ } catch (e) {
2626
+ this.#log("warn", "permission subagent identity inspect unavailable", {
2627
+ sessionId,
2628
+ error: errText(e),
2629
+ });
2630
+ }
2631
+ }
2632
+ if (!coldSubagent && svc && typeof svc.current === "function" && typeof sc.resolveAgent === "function") {
2633
+ const agentRes = await sc.resolveAgent(sessionId);
2634
+ const session = agentRes?.agent?.session ?? agentRes?.session ?? null;
2635
+ if (session) {
2636
+ const current = svc.current(session);
2637
+ if (typeof current === "string" && current !== "") {
2638
+ this.#permissionSelections.set(sessionId, current);
2639
+ this.#reply(m, resultOf(m, { permission: current }));
2640
+ return;
2641
+ }
2642
+ }
2643
+ }
2644
+ } catch (e) {
2645
+ this.#log("warn", "live permission read unavailable; falling back to tracked value", {
2646
+ sessionId,
2647
+ error: errText(e),
2648
+ });
2649
+ }
2650
+ this.#reply(m, resultOf(m, { permission: this.#permissionSelections.get(sessionId) ?? null }));
2651
+ }
2652
+
2470
2653
  /** 模式目录(宿主 Agent preset 目录)。服务缺失/抛错 → 空目录。 */
2471
2654
  async #loadAgentPresets() {
2472
2655
  const svc = this.#service("agentPresets");
package/market/index.json CHANGED
@@ -69,6 +69,16 @@
69
69
  "sortKeys": {}
70
70
  },
71
71
  "versions": [
72
+ {
73
+ "version": "1.1.7",
74
+ "publishTimestamp": 1793320998,
75
+ "source": {
76
+ "type": "npm"
77
+ },
78
+ "engines": {
79
+ "dsh": "^0.1.5-rc.3 || ^0.2.0-rc.1 || ^0.2.1-rc.0"
80
+ }
81
+ },
72
82
  {
73
83
  "version": "1.1.6",
74
84
  "publishTimestamp": 1793202911,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duke-dsh-plugins/dsh-remote-control",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "Remote-control bridge for DeepSeek Harness: pairs a HarmonyOS phone app with the desktop Host over an end-to-end-encrypted public relay (WebSocket). Lets the phone list/create/switch sessions, send prompts, watch streamed replies, cancel turns, and answer approval and ask-user-question requests from anywhere; pushes Huawei Push Kit notifications (gracefully disabled when AGC is unconfigured) for approvals, questions, and turn completion. The pairing QR lives in the DSH settings panel (\"DSH Pocket\"). Fail-open by design: any relay timeout or fault hands the request back to the desktop answerer.",
5
5
  "type": "module",
6
6
  "main": "index.js",