deskbuddy 0.2.0-beta.2 → 0.2.0-beta.3

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/hook/hook.cjs CHANGED
@@ -764,8 +764,35 @@ async function reportIfAuthorized(tool, nowMs) {
764
764
  // clientId 为空说明还没 setup 过(服务端靠 clientId ↔ userId 绑定关系认人):
765
765
  // 绝不能在这里现编一个,那等于凭空造出一台没人认领的机器
766
766
  if (!cfg.clientId || cfg.enabledTools.indexOf(tool) === -1) return
767
+ // Codex:以 daemon 连着的 app-server 清单判 remoteWindow(切片 B);Claude Code:状态文件 + 窗口唤醒标记
767
768
  const remote = tool === 'codex' ? readCodexRemote() || new Set() : null
768
- await postReport(cfg, buildSnapshot(readAliveStates(tool), tool, cfg, nowMs, remote))
769
+ await postReport(cfg, buildSnapshot(withWake(readAliveStates(tool)), tool, cfg, nowMs, remote))
770
+ }
771
+
772
+ // ---------- 窗口唤醒(asyncRewake,与 src/core/wake.ts 同构) ----------
773
+
774
+ /**
775
+ * daemon 写的 `wake/marks/<sessionId>.json`:这个会话开着的窗口里有等待者,设备指令能直接唤醒窗口执行。
776
+ * 标记里的智能体进程还在才算(kill 0,不查进程名:每次上报都要调)
777
+ */
778
+ function wakeMarked(sessionId) {
779
+ const safe = String(sessionId).replace(/[^A-Za-z0-9_-]/g, '')
780
+ if (!safe) return false
781
+ try {
782
+ const m = JSON.parse(fs.readFileSync(path.join(deskbuddyHome(), 'wake', 'marks', safe + '.json'), 'utf8'))
783
+ // 写标记的 daemon 死了就不算(daemon 退出来不及清标记时,不能一直误报 remoteWindow)
784
+ const daemonPid = Number(m && m.daemonPid) || 0
785
+ if (!daemonPid || !pidExists(daemonPid)) return false
786
+ const pid = Number(m && m.agentPid) || 0
787
+ return pid > 0 ? pidExists(pid) : true
788
+ } catch (e) {
789
+ return false
790
+ }
791
+ }
792
+
793
+ /** 上报前叠加唤醒标记:能被唤醒的会话带 remoteWindow=true(服务端据此放行 8348) */
794
+ function withWake(states) {
795
+ return states.map((s) => (s.remoteWindow === true || !wakeMarked(s.sessionId) ? s : Object.assign({}, s, { remoteWindow: true })))
769
796
  }
770
797
 
771
798
  /**
@@ -1165,6 +1192,7 @@ module.exports = {
1165
1192
  main,
1166
1193
  mapEvent,
1167
1194
  processName,
1195
+ parentPid,
1168
1196
  readAiTitle,
1169
1197
  readAliveStates,
1170
1198
  readCodexThreadName,
@@ -1192,4 +1220,8 @@ module.exports = {
1192
1220
  noteWindow,
1193
1221
  readWindow,
1194
1222
  windowOwns,
1223
+ wakeMarked,
1224
+ withWake,
1225
+ detectInteractive,
1226
+ pidExists,
1195
1227
  }