dsh-mobile-plugin 0.5.33 → 0.5.35

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.
Files changed (142) hide show
  1. package/README.md +17 -2
  2. package/dsh-mobile-credentials/lib/credentials.js +49 -2
  3. package/extensions/README.md +25 -21
  4. package/host.js +16 -1
  5. package/lib/git/pr.js +375 -0
  6. package/lib/git/read.js +1 -0
  7. package/lib/host-capabilities.cjs +67 -0
  8. package/lib/http/routing.js +25 -0
  9. package/lib/impl.js +34 -26
  10. package/lib/mirror/history-blob.cjs +184 -0
  11. package/lib/mirror/pusher.cjs +276 -1
  12. package/lib/mobile/approval-facts.js +439 -0
  13. package/lib/mobile/approval-memory.js +199 -0
  14. package/lib/mobile/approvals.js +596 -30
  15. package/lib/mobile/auto-review-log.js +160 -0
  16. package/lib/mobile/auto-review.js +172 -0
  17. package/lib/mobile/credential-upgrade.js +14 -0
  18. package/lib/mobile/device-permissions.js +86 -0
  19. package/lib/mobile/directory-browse.js +23 -8
  20. package/lib/mobile/events.js +9 -1
  21. package/lib/mobile/extension-catalog.js +106 -44
  22. package/lib/mobile/extension-data.js +6 -0
  23. package/lib/mobile/file-ops.js +89 -76
  24. package/lib/mobile/git.js +108 -2
  25. package/lib/mobile/live-steps.js +107 -4
  26. package/lib/mobile/mail.js +621 -0
  27. package/lib/mobile/monitor.js +6 -0
  28. package/lib/mobile/notification-prefs.js +205 -0
  29. package/lib/mobile/pairing.js +15 -2
  30. package/lib/mobile/permissions.js +433 -0
  31. package/lib/mobile/project-write-queue.js +115 -0
  32. package/lib/mobile/project-writes.js +61 -0
  33. package/lib/mobile/push-notify.js +293 -13
  34. package/lib/mobile/questions.js +20 -3
  35. package/lib/mobile/recent-failures.js +48 -0
  36. package/lib/mobile/relay-control.js +5 -0
  37. package/lib/mobile/session-cache.js +50 -0
  38. package/lib/mobile/session-last-turn.js +24 -22
  39. package/lib/mobile/session-new.js +205 -0
  40. package/lib/mobile/session-send.js +0 -1
  41. package/lib/mobile/sessions.js +12 -84
  42. package/lib/mobile/skill-write.js +549 -0
  43. package/lib/mobile/stats-collect.cjs +33 -3
  44. package/lib/mobile/stats-ledger.cjs +39 -2
  45. package/lib/mobile/stream.js +24 -3
  46. package/lib/mobile/supervisor-broadcast.js +58 -11
  47. package/lib/mobile/supervisor-tools.js +1 -1
  48. package/lib/mobile/third-party-extensions.js +158 -0
  49. package/lib/mobile/uploads.js +30 -14
  50. package/lib/mobile/worktree-isolation.js +479 -0
  51. package/lib/mobile/worktree-lifecycle.js +79 -0
  52. package/lib/p2p/wiring.cjs +41 -16
  53. package/lib/panel/index.html +15 -15
  54. package/lib/read-receipt.cjs +89 -5
  55. package/lib/relay/core.js +25 -1
  56. package/lib/relay/lan-proxy.js +6 -1
  57. package/lib/relay/preview.js +21 -1
  58. package/lib/relay/protocol.js +1 -0
  59. package/lib/relay/status.js +6 -0
  60. package/lib/relay/tunnel-forwarder.cjs +178 -0
  61. package/lib/routes/control-plane.js +35 -1
  62. package/lib/routes/mobile-api.js +105 -52
  63. package/lib/shared/via-header.js +15 -2
  64. package/lib/sidecar-facade-worker.cjs +15 -2
  65. package/lib/sidecar-facade.cjs +5 -0
  66. package/lib/tailcat/host-process.cjs +1 -1
  67. package/lib/tailcat/ingress.cjs +2 -2
  68. package/lib/tailcat/wiring.cjs +34 -13
  69. package/package.json +11 -3
  70. package/assets/pets/README.md +0 -9
  71. package/assets/pets/deepy-whale/attention.gif +0 -0
  72. package/assets/pets/deepy-whale/done.gif +0 -0
  73. package/assets/pets/deepy-whale/error.gif +0 -0
  74. package/assets/pets/deepy-whale/idle.gif +0 -0
  75. package/assets/pets/deepy-whale/pack.json +0 -54
  76. package/assets/pets/deepy-whale/sleeping.gif +0 -0
  77. package/assets/pets/deepy-whale/working-3.gif +0 -0
  78. package/assets/pets/deepy-whale/working.gif +0 -0
  79. package/knowledge/apps/alipay.md +0 -30
  80. package/knowledge/apps/android-settings.md +0 -30
  81. package/knowledge/apps/baijiahao.md +0 -30
  82. package/knowledge/apps/bilibili.md +0 -31
  83. package/knowledge/apps/boss-zhipin.md +0 -32
  84. package/knowledge/apps/dedao.md +0 -33
  85. package/knowledge/apps/douyin.md +0 -32
  86. package/knowledge/apps/feishu.md +0 -35
  87. package/knowledge/apps/gmail.md +0 -33
  88. package/knowledge/apps/jike.md +0 -31
  89. package/knowledge/apps/kuaishou.md +0 -34
  90. package/knowledge/apps/linkedin.md +0 -33
  91. package/knowledge/apps/qqmail.md +0 -30
  92. package/knowledge/apps/taobao.md +0 -33
  93. package/knowledge/apps/telegram.md +0 -27
  94. package/knowledge/apps/toutiao.md +0 -32
  95. package/knowledge/apps/uber-eats.md +0 -26
  96. package/knowledge/apps/uber.md +0 -27
  97. package/knowledge/apps/wechat.md +0 -33
  98. package/knowledge/apps/weibo.md +0 -31
  99. package/knowledge/apps/whatsapp.md +0 -27
  100. package/knowledge/apps/x.md +0 -32
  101. package/knowledge/apps/xiaohongshu.md +0 -30
  102. package/knowledge/apps/zhihu.md +0 -31
  103. package/knowledge/sites/bilibili.com/SITE.md +0 -50
  104. package/knowledge/sites/bilibili.com/references/view-fields.md +0 -17
  105. package/knowledge/sites/github.com/SITE.md +0 -51
  106. package/knowledge/sites/github.com/references/repo-fields.md +0 -13
  107. package/knowledge/sites/x.com/SITE.md +0 -47
  108. package/knowledge/sites/xiaohongshu.com/SITE.md +0 -48
  109. package/knowledge/sites/xiaohongshu.com/references/note-fields.md +0 -18
  110. package/knowledge/sites/youtube.com/SITE.md +0 -49
  111. package/knowledge/sites/youtube.com/references/innertube-fields.md +0 -14
  112. package/knowledge/sites/zhihu.com/SITE.md +0 -47
  113. package/knowledge/sites/zhihu.com/references/api-fields.md +0 -21
  114. package/lib/mobile/pet-tools.js +0 -261
  115. package/lib/mobile/pets.js +0 -755
  116. package/lib/mobile/phone/access.js +0 -85
  117. package/lib/mobile/phone/binding.js +0 -247
  118. package/lib/mobile/phone/confirm.js +0 -189
  119. package/lib/mobile/phone/evidence.js +0 -228
  120. package/lib/mobile/phone/gate.js +0 -290
  121. package/lib/mobile/phone/grounding.js +0 -314
  122. package/lib/mobile/phone/guard.js +0 -465
  123. package/lib/mobile/phone/index.js +0 -83
  124. package/lib/mobile/phone/irreversible.js +0 -226
  125. package/lib/mobile/phone/knowledge-tools.js +0 -665
  126. package/lib/mobile/phone/learn.js +0 -329
  127. package/lib/mobile/phone/pacing.js +0 -173
  128. package/lib/mobile/phone/redact.js +0 -237
  129. package/lib/mobile/phone/risk.js +0 -95
  130. package/lib/mobile/phone/route-hint.js +0 -164
  131. package/lib/mobile/phone/routes-memory.js +0 -133
  132. package/lib/mobile/phone/routes.js +0 -279
  133. package/lib/mobile/phone/service.js +0 -500
  134. package/lib/mobile/phone/site-commands.js +0 -271
  135. package/lib/mobile/phone/step-summary.js +0 -201
  136. package/lib/mobile/phone/stop-summary.js +0 -235
  137. package/lib/mobile/phone/tool-groups.js +0 -125
  138. package/lib/mobile/phone/tools.js +0 -2282
  139. package/lib/mobile/phone/untrusted.js +0 -65
  140. package/lib/mobile/phone-knowledge.js +0 -317
  141. package/lib/mobile/wechat-tools.js +0 -257
  142. package/lib/mobile/wechat.js +0 -514
@@ -1,237 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * 统一脱敏:运行记录、证据账本、网络数据三处共用同一套规则,一处改了另两处跟着改。
5
- * 纯逻辑、无 IO、不改入参(redactObject 返回新对象)。
6
- *
7
- * 覆盖 Mika Redactor.kt 的全部口径,并补上卡号:
8
- * - 密码框里打进去的字(字段名像凭据的,整段打码);
9
- * - sk-* / AIza* / AQ.* / ghp_* 等已知格式的 Key、Bearer 令牌;
10
- * - JWT(eyJ… 三段);
11
- * - 又长又杂的串(≥32 位,且同时有大写、小写、数字);
12
- * - 16 位 / 19 位卡号类数字串(含分组空格 / 连字符);
13
- * - 名字像凭据的 query / 表单 / JSON / 头字段的值(token、secret、password、cookie、
14
- * authorization…;author、keyword 这类不算);
15
- * - OAuth 回跳里的 code、state;
16
- * - 前后 24 字内有「验证码 / 短信 / code / otp」一类词的 4–8 位数字。
17
- *
18
- * 三个导出的分工:
19
- * redact(text) 对一段自由文本跑全部文本级规则(Key/JWT/长串/卡号/验证码)。
20
- * redactObject(obj) 递归处理对象/数组:凭据名整段打码,其余字符串跑 redact。
21
- * redactNetwork(body) 网络数据(URL / 表单 / JSON 正文 / 头表):凭据名与 OAuth 一并打码。
22
- */
23
-
24
- const MASK = '***';
25
-
26
- /* ── 已知格式的凭据 ───────────────────────────────────────────────────── */
27
-
28
- const SK_KEY = /\bsk-[A-Za-z0-9_-]{16,}/g;
29
- const GOOGLE_KEY = /\bAIza[0-9A-Za-z_-]{30,}/g;
30
- /** Google 新格式认证 Key:AQ. 开头一长串 base64url。 */
31
- const GOOGLE_AUTH_KEY = /\bAQ\.[0-9A-Za-z_-]{20,}/g;
32
- const GITHUB_TOKEN = /\bgh[pousr]_[A-Za-z0-9]{20,}/g;
33
- const BEARER = /\bBearer\s+[A-Za-z0-9._~+/=-]{8,}/g;
34
-
35
- /* ── JWT 与又长又杂的串 ───────────────────────────────────────────────── */
36
-
37
- const JWT = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g;
38
- const LONG = /[A-Za-z0-9_\-+=]{32,}/g;
39
- const LONG_SLASH = /[A-Za-z0-9_\-+/=]{32,}/g;
40
-
41
- /* ── 16 / 19 位卡号类 ─────────────────────────────────────────────────── */
42
-
43
- /** 13–19 位数字,允许单个空格或连字符分组;是否真按卡号遮由位数(16 或 19)决定。 */
44
- const CARD_LIKE = /(?<![\d.,])(?:\d[ -]?){15,18}\d(?![\d.,])/g;
45
-
46
- /* ── 验证码一类的 4–8 位数字 ──────────────────────────────────────────── */
47
-
48
- const CODE_WORD = /验证|校验码|动态码|动态密码|确认码|安全码|短信|口令|\b(?:code|otp|passcode|pin|2fa)\b/gi;
49
- /** 4–8 位数字,中间可隔单个空格或连字符;后面跟单位 / 年份 / 货币的是量,不是码。 */
50
- const CODE_DIGITS =
51
- /(?<![\d.¥$€£])(?<!\d,)\d(?:[ -]?\d){3,7}(?!\d)(?!\.\d)(?!,\d{3}(?!\d))(?!\s*(?:年|元|块|角|分钟|小时|秒|天|月|日|号|次|个|人|件|条|米|公里|千米|克|公斤|千克|斤|吨|度|℃|°|%|‰|[¥$€£]|km|kg|mb|gb|kb|ms|cm|mm|mah|rmb|usd|cny))/gi;
52
- /** 码和词之间至多隔几个字(哪一边都算)。 */
53
- const CODE_WINDOW = 24;
54
-
55
- /* ── 名字像凭据 ──────────────────────────────────────────────────────── */
56
-
57
- const SECRET_WORDS = new Set([
58
- 'token', 'tokens', 'secret', 'password', 'passwd', 'pwd', 'passcode', 'session', 'sessionid', 'sessid', 'sid',
59
- 'auth', 'authorization', 'csrf', 'xsrf', 'signature', 'sig', 'otp', 'cookie', 'credential', 'credentials',
60
- 'apikey', 'jwt', 'bearer', 'pin', 'privatekey',
61
- ]);
62
- const SECRET_COMPOUNDS = new Set([
63
- 'apikey', 'accesskey', 'secretkey', 'privatekey', 'clientsecret', 'sessionkey', 'authkey',
64
- ]);
65
- const CASE_BOUNDARY = /(?<=[a-z0-9])(?=[A-Z])/g;
66
- const WORD_SPLIT = /[^A-Za-z0-9]+/g;
67
-
68
- /** 字段名按驼峰 / 下划线 / 连字符拆成词,有像凭据的词就是凭据字段。 */
69
- function secretName(name) {
70
- const words = String(name == null ? '' : name)
71
- .split(WORD_SPLIT)
72
- .flatMap((part) => part.split(CASE_BOUNDARY))
73
- .map((w) => w.toLowerCase())
74
- .filter(Boolean);
75
- return words.some((w) => SECRET_WORDS.has(w)) || SECRET_COMPOUNDS.has(words.join(''));
76
- }
77
-
78
- const OAUTH_MARKERS = new Set(['state', 'redirect_uri', 'client_id', 'code_verifier']);
79
- const OAUTH_RESULTS = new Set(['code', 'state']);
80
-
81
- /* ── 文本级规则 ──────────────────────────────────────────────────────── */
82
-
83
- function maskLong(s, slash) {
84
- const re = slash ? LONG_SLASH : LONG;
85
- return s.replace(re, (m) => {
86
- if (/[A-Z]/.test(m) && /[a-z]/.test(m) && /\d/.test(m)) return MASK;
87
- return m;
88
- });
89
- }
90
-
91
- function maskCards(s) {
92
- return s.replace(CARD_LIKE, (m) => {
93
- const digits = m.replace(/\D/g, '').length;
94
- return digits === 16 || digits === 19 ? MASK : m;
95
- });
96
- }
97
-
98
- function maskCodes(s) {
99
- const words = [];
100
- for (const m of s.matchAll(CODE_WORD)) {
101
- words.push({ start: m.index, last: m.index + m[0].length - 1 });
102
- }
103
- if (words.length === 0) return s;
104
- return s.replace(CODE_DIGITS, (match, offset) => {
105
- const first = offset;
106
- const last = offset + match.length - 1;
107
- const near = words.some((w) => {
108
- const afterWord = first - w.last;
109
- const beforeWord = w.start - last;
110
- return (afterWord >= 1 && afterWord <= CODE_WINDOW + 1) || (beforeWord >= 1 && beforeWord <= CODE_WINDOW + 1);
111
- });
112
- return near ? MASK : match;
113
- });
114
- }
115
-
116
- /**
117
- * 自由文本脱敏:Key / Bearer / JWT / 长杂串 / 卡号 / 验证码。
118
- * @param {string} input
119
- * @returns {string}
120
- */
121
- function redact(input) {
122
- if (input === null || input === undefined) return input;
123
- let s = typeof input === 'string' ? input : String(input);
124
- s = s.replace(SK_KEY, MASK);
125
- s = s.replace(GOOGLE_KEY, MASK);
126
- s = s.replace(GOOGLE_AUTH_KEY, MASK);
127
- s = s.replace(GITHUB_TOKEN, MASK);
128
- s = s.replace(BEARER, 'Bearer ' + MASK);
129
- s = s.replace(JWT, MASK);
130
- s = maskLong(s, true);
131
- s = maskCards(s);
132
- s = maskCodes(s);
133
- return s;
134
- }
135
-
136
- /* ── 结构化数据:query / 表单 / JSON / 头 ────────────────────────────── */
137
-
138
- /**
139
- * 查询串或表单里 a=b&c=d:凭据名的值遮住;像 OAuth 回跳的(有 state 等,且带 code 或凭据)把 code、state 也遮住。
140
- * [bareKey] 为真时,孤零零一个叫 key 的参数也算凭据。
141
- */
142
- function maskParams(q, bareKey) {
143
- const parts = q.split('&');
144
- const names = parts.map((p) => p.split('=')[0].toLowerCase());
145
- const oauth = names.some((n) => OAUTH_MARKERS.has(n)) && (names.includes('code') || names.some((n) => secretName(n)));
146
- return parts
147
- .map((p) => {
148
- const eq = p.indexOf('=');
149
- if (eq <= 0) return p;
150
- const name = p.slice(0, eq);
151
- const n = name.toLowerCase();
152
- const hide = secretName(name) || (bareKey && n === 'key') || (oauth && OAUTH_RESULTS.has(n));
153
- return hide ? name + '=' + MASK : p;
154
- })
155
- .join('&');
156
- }
157
-
158
- function maskUrl(u) {
159
- const hash = u.indexOf('#');
160
- const beforeHash = hash >= 0 ? u.slice(0, hash) : u;
161
- const fragment = hash >= 0 ? u.slice(hash + 1) : null;
162
- const q = beforeHash.indexOf('?');
163
- const base = q >= 0 ? beforeHash.slice(0, q + 1) + maskParams(beforeHash.slice(q + 1), true) : beforeHash;
164
- return fragment === null ? base : base + '#' + (fragment.includes('=') ? maskParams(fragment, true) : fragment);
165
- }
166
-
167
- const JSON_PAIR = /"((?:[^"\\]|\\.){1,100})"(\s*:\s*)("(?:[^"\\]|\\.)*"|-?\d[\d.eE+-]*|true|false|null)/g;
168
- const FORM = /^[^\s{}[\]"<>]+=[^\s]*$/;
169
-
170
- function maskBody(b) {
171
- if (FORM.test(b)) return maskParams(b, false);
172
- return b.replace(JSON_PAIR, (m, key, sep) => (secretName(key) ? `"${key}"${sep}"${MASK}"` : m));
173
- }
174
-
175
- /**
176
- * 网络数据里的一个字符串(URL / 表单 / JSON 正文)脱敏。先按结构遮凭据名与 OAuth,
177
- * 再跑一遍文本级规则兜住值里的 Key / JWT / 长串 / 卡号。
178
- */
179
- function maskNetworkString(s) {
180
- let out;
181
- if (/^[a-z][a-z0-9+.-]*:\/\//i.test(s) || (/^[^\s]*\?/.test(s) && s.includes('='))) {
182
- out = maskUrl(s);
183
- } else if (FORM.test(s)) {
184
- out = maskParams(s, false);
185
- } else {
186
- out = maskBody(s);
187
- }
188
- return redact(out);
189
- }
190
-
191
- /**
192
- * 递归脱敏对象 / 数组。名字像凭据的键整段打码;其余字符串跑 redact;数字布尔原样。
193
- * @param {*} value
194
- * @returns {*}
195
- */
196
- function redactObject(value) {
197
- if (value === null || value === undefined) return value;
198
- if (Array.isArray(value)) return value.map((v) => redactObject(v));
199
- if (typeof value === 'string') return redact(value);
200
- if (typeof value === 'object') {
201
- const out = {};
202
- for (const k of Object.keys(value)) {
203
- if (secretName(k)) out[k] = MASK;
204
- else out[k] = redactObject(value[k]);
205
- }
206
- return out;
207
- }
208
- return value;
209
- }
210
-
211
- /**
212
- * 网络数据脱敏:body 可以是字符串(URL / 表单 / JSON 正文),也可以是头表这类对象。
213
- * @param {*} body
214
- * @returns {*}
215
- */
216
- function redactNetwork(body) {
217
- if (body === null || body === undefined) return body;
218
- if (typeof body === 'string') return maskNetworkString(body);
219
- if (Array.isArray(body)) return body.map((b) => redactNetwork(b));
220
- if (typeof body === 'object') return redactObject(body);
221
- return body;
222
- }
223
-
224
- module.exports = {
225
- redact,
226
- redactObject,
227
- redactNetwork,
228
- secretName,
229
- maskParams,
230
- maskUrl,
231
- // 给「证据账本 / 运行记录」这类只要纯文本遮罩的调用方留的别名,语义等价于 redact:
232
- // phone/evidence.js 的 loadSharedRedactor 找的就是 evidence / text 这两个名字之一。
233
- evidence: redact,
234
- text: redact,
235
- MASK,
236
- CODE_WINDOW,
237
- };
@@ -1,95 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * 动作风险五级分级:纯函数,只回答「这一步大概会造成多大影响」,不做任何动作、不读屏。
5
- *
6
- * 从 Mika(`core/action/Approval.kt` 的 `ActionRisk`)借五级口径:
7
- *
8
- * Read 只看,或只在界面间移动(读屏、等、开/关 App、返回)
9
- * Change 在界面上改东西(点、打字、滑、手势、按键),改的是界面不是世界
10
- * External 把东西交给别人(发送、发布、提交),会影响屏外的世界
11
- * Irreversible 做了收不回(付款、下单、删除)
12
- * Unknown 看不清点的是什么,按拿不准处理
13
- *
14
- * `outward`(影响屏幕之外的世界,或拿不准会不会)对 External / Irreversible / Unknown 为真,
15
- * 用来决定「这一步要不要记账、要不要人工确认」。这份分级只给调用方做参考:真正的放行/接管
16
- * 判定在 gate.js 里,risk 不碰任何状态。
17
- *
18
- * 我们对 Mika 的取舍:Mika 分级要读整屏快照,能按资源 ID、组合键、弹框、拖拽等信号判;
19
- * 我们的输入只有「动作名 + 目标文字 + 是否对外」这一份结构化信息,所以分级只用到这三样,
20
- * 判不准的一律落到 Unknown,不猜。
21
- */
22
-
23
- const { matchLabel } = require('./irreversible.js');
24
-
25
- /** 只看、只在界面间移动,不改屏外的世界。 */
26
- const READ_ACTIONS = new Set([
27
- 'screen.read', 'read', 'screenshot', 'list', 'find', 'wait',
28
- 'scroll', 'app.open', 'app.close', 'back', 'home', 'recents', 'tab',
29
- ]);
30
-
31
- /** 在界面上改东西。 */
32
- const CHANGE_ACTIONS = new Set(['tap', 'type', 'swipe', 'key', 'gesture', 'clear', 'clear_text', 'long_press']);
33
-
34
- /** 点按类:读不到目标文字时判不了点的是什么。 */
35
- const TAP_LIKE = new Set(['tap', 'long_press']);
36
-
37
- function result(level, outward, why) {
38
- return { level, outward, why };
39
- }
40
-
41
- /**
42
- * classify({ action, target, outward }) → { level, outward, why }
43
- *
44
- * @param {object} input
45
- * @param {string} input.action 动作名(tap / type / swipe / key / app.open / screen.read …)
46
- * @param {string} [input.target] 这一下作用的文字(按钮名、发送对象、输入框标签…)
47
- * @param {boolean} [input.outward] 调用方已经知道这一步对外(如带回车的打字、提交式点击)时置 true
48
- * @returns {{level:string, outward:boolean, why:string}}
49
- */
50
- function classify(input) {
51
- const src = input && typeof input === 'object' ? input : {};
52
- const action = typeof src.action === 'string' ? src.action.trim().toLowerCase() : '';
53
- const target = typeof src.target === 'string' ? src.target.trim() : '';
54
- const outwardFlag = src.outward === true;
55
-
56
- if (!action) return result('Unknown', true, '没有动作名,判不了这一步做什么');
57
-
58
- if (READ_ACTIONS.has(action)) {
59
- return result('Read', false, `${action} 只看或只在界面间移动,不改屏外的东西`);
60
- }
61
-
62
- if (!CHANGE_ACTIONS.has(action)) {
63
- return result('Unknown', true, `不认识的动作「${action}」,按拿不准处理`);
64
- }
65
-
66
- // 目标文字能命中不可逆词表:按命中的类别定级。
67
- const hit = target ? matchLabel(target) : null;
68
- if (hit) {
69
- if (hit.kind === 'payment') {
70
- return result('Irreversible', true, `「${target}」是付款/下单一类,做了收不回`);
71
- }
72
- if (hit.kind === 'delete') {
73
- return result('Irreversible', true, `「${target}」是删除一类,做了收不回`);
74
- }
75
- return result('External', true, `「${target}」会把东西交给别人(${hit.kind})`);
76
- }
77
-
78
- // 调用方已经声明这一步对外(例如带回车的打字)。
79
- if (outwardFlag) {
80
- return result('External', true, `${action} 被声明为对外动作,会影响屏外的世界`);
81
- }
82
-
83
- // 点按类却读不到目标文字:看不清点的是什么。
84
- if (TAP_LIKE.has(action) && !target) {
85
- return result('Unknown', true, '点按但读不到目标文字,看不清点的是什么');
86
- }
87
-
88
- return result('Change', false, `${action} 只在界面上改动,不涉及屏外的世界`);
89
- }
90
-
91
- module.exports = {
92
- classify,
93
- READ_ACTIONS,
94
- CHANGE_ACTIONS,
95
- };
@@ -1,164 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * `phone_route_hint`:只读地翻出「这个 App 以前成功过的路线」。
5
- *
6
- * 用法是打开一个 App 之后问一句「以前有没有做成过、怎么做的」。**只给参考,不自动执行**:
7
- * 这里既不连手机、也不发任何动作,模型看过之后还得自己按当前屏幕重新判断。之所以只给摘要不给
8
- * 原始步骤,是因为界面会变,照抄旧路线比没有更危险 —— 摘要让模型看懂大意,具体每一步仍要现读屏。
9
- *
10
- * 注册形状照 `phone/tools.js` 里的那套:走 `ctx.inject(['tools'], …)` 再 `defineTool`,
11
- * 不能直接读 `ctx.tools`(宿主里那是个影子对象,`register` 一调就抛,被容错吞掉后一条工具都交不到
12
- * 模型手上)。缺 tools 注入的 profile 静默跳过,别把整块装配掀翻。
13
- */
14
-
15
- const routesMemory = require('./routes-memory.js');
16
-
17
- /** 一次最多回几条路线。 */
18
- const MAX_ROUTES = 5;
19
- /** 摘要里单段文字最长多少字。 */
20
- const MAX_TEXT = 60;
21
-
22
- /** 动作名换成一句人话动词。 */
23
- const ACTION_VERBS = {
24
- tap: '点击',
25
- type: '输入',
26
- key: '按键',
27
- swipe: '滑动',
28
- gesture: '手势',
29
- 'screen.wait': '等待',
30
- 'screen.read': '读屏',
31
- 'screen.screenshot': '截图',
32
- 'app.open': '打开',
33
- 'app.close': '关闭',
34
- };
35
-
36
- function clip(text) {
37
- const value = typeof text === 'string' ? text.trim() : '';
38
- if (!value) return '';
39
- return value.length > MAX_TEXT ? `${value.slice(0, MAX_TEXT)}…` : value;
40
- }
41
-
42
- /**
43
- * 把一步压成一句摘要。只取最有辨识度的一个参数,不要把小箭头变成一段代码。
44
- */
45
- function summarizeStep(step) {
46
- if (!step || typeof step !== 'object') return '';
47
- const action = typeof step.action === 'string' ? step.action.trim() : '';
48
- if (!action) return '';
49
- const args = step.args && typeof step.args === 'object' ? step.args : {};
50
- const verb = ACTION_VERBS[action] || action;
51
-
52
- let object = '';
53
- if (action === 'type') {
54
- const text = clip(args.text);
55
- if (text) object = `「${text}」`;
56
- } else if (action === 'tap') {
57
- const target = clip(args.target);
58
- if (target) object = `「${target}」`;
59
- else if (typeof args.ref === 'string' && args.ref.trim()) object = args.ref.trim();
60
- } else if (action === 'key') {
61
- object = typeof args.key === 'string' ? args.key : '';
62
- } else if (action === 'app.open') {
63
- object = clip(args.packageName);
64
- } else if (action === 'swipe') {
65
- object = typeof args.direction === 'string' ? args.direction : '';
66
- } else {
67
- object = clip(args.target) || clip(args.text) || clip(args.packageName) || (typeof args.ref === 'string' ? args.ref.trim() : '');
68
- }
69
- return object ? `${verb}${object}` : verb;
70
- }
71
-
72
- /**
73
- * 把一条路线压成可读的摘要对象:步骤数、时间、整条路线的一句话。
74
- */
75
- function summarizeRoute(route) {
76
- const steps = route && Array.isArray(route.steps) ? route.steps : [];
77
- const parts = steps.map(summarizeStep).filter(Boolean);
78
- return {
79
- at: route && Number.isFinite(route.at) ? route.at : 0,
80
- stepCount: steps.length,
81
- summary: parts.join(' → '),
82
- };
83
- }
84
-
85
- /** 取这个 App 最近成功的几条,压成摘要。没有记录回空数组。 */
86
- function hintFor(packageName) {
87
- const routes = routesMemory.list(packageName);
88
- // 最近的先给:新近成功的路线更贴近现在这个版本的界面。
89
- return routes
90
- .slice()
91
- .sort((a, b) => b.at - a.at)
92
- .slice(0, MAX_ROUTES)
93
- .map(summarizeRoute);
94
- }
95
-
96
- /**
97
- * 注册 `phone_route_hint`。与 `installPhoneTools` 同一口径:拿不到 tools 注入就静静不装。
98
- */
99
- function installRouteHint(ctx) {
100
- if (!ctx || typeof ctx.inject !== 'function') return;
101
- let defineTool;
102
- try {
103
- ({ defineTool } = require('@deepseek-ai/dsh-tools'));
104
- } catch {
105
- return;
106
- }
107
-
108
- ctx.inject(['tools'], (scoped) => {
109
- if (!scoped || !scoped.tools || typeof scoped.tools.register !== 'function') return;
110
- scoped.tools.register(defineTool({
111
- name: 'phone_route_hint',
112
- description: 'Look up routes this app has succeeded with before, as short step summaries. This is reference only — nothing is executed. After opening an app, use it to recall a past successful path, then re-read the screen and decide each step yourself; the UI may have changed.',
113
- parameters: {
114
- packageName: {
115
- type: 'string',
116
- required: true,
117
- description: 'Android package name of the app, e.g. "com.tencent.mm".',
118
- },
119
- },
120
- output: {
121
- schema: {
122
- type: 'object',
123
- additionalProperties: false,
124
- properties: {
125
- ok: { type: 'boolean' },
126
- packageName: { type: 'string' },
127
- count: { type: 'number' },
128
- // 一条路线是「步骤数 + 摘要」,形状固定,但为了紧凑允许附加字段。
129
- routes: { type: 'array', items: { type: 'object', additionalProperties: true } },
130
- note: { type: 'string' },
131
- },
132
- },
133
- render: (_args, value) => {
134
- const count = Array.isArray(value.routes) ? value.routes.length : 0;
135
- const lines = [`这个 App 以前成功过 ${count} 条路线(仅供参考,不会自动执行):`];
136
- for (const route of value.routes || []) lines.push(`- ${route.summary}`);
137
- if (!count) lines.push('- 还没有记录。');
138
- return [{ type: 'text', text: lines.join('\n') }];
139
- },
140
- },
141
- execute: async (args) => {
142
- const pkg = typeof args.packageName === 'string' ? args.packageName.trim() : '';
143
- if (!pkg) throw new Error('要给一个包名(例如 com.tencent.mm)才能查历史路线。');
144
- const routes = hintFor(pkg);
145
- const value = {
146
- ok: true,
147
- packageName: pkg,
148
- count: routes.length,
149
- routes,
150
- };
151
- if (routes.length === 0) value.note = '这个 App 还没有成功过的路线记录。';
152
- return value;
153
- },
154
- }));
155
- });
156
- }
157
-
158
- module.exports = {
159
- installRouteHint,
160
- summarizeStep,
161
- summarizeRoute,
162
- hintFor,
163
- MAX_ROUTES,
164
- };
@@ -1,133 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * 成功路线记忆:把「这个 App 上一轮是怎么一步步做成的」记下来,下次打开同一个 App 时能翻出
5
- * 以前成功过的路线给模型参考。
6
- *
7
- * 存一份 JSON 在 `<DSH_HOME>/storages/mobile-plugin/phone-routes.json`,按包名分桶:
8
- *
9
- * { "<包名>": [ { steps: [...], at: 1794…, hits: 0 } ] } // 每个包最多 20 条
10
- *
11
- * 三条边界:
12
- * - **只在成功时记**:`record` 由调用方在结局判定为成功后调;失败、超时、取消一律不记。
13
- * - **每个包封顶 20 条**:旧记录满了就挤掉最旧的,避免一个常用 App 把文件越攒越大。
14
- * - **加载失败安静退化**:文件不存在、读坏、形状不对,都当「还没有记录」,绝不抛 —— 记忆是
15
- * 锦上添花,不能因为它把一次操作或者整个插件装载掀翻。
16
- */
17
-
18
- const fs = require('node:fs');
19
- const path = require('node:path');
20
-
21
- const { dshHome } = require('../../shared/paths');
22
-
23
- /** 每个包名最多留这么多条历史路线。 */
24
- const MAX_PER_PACKAGE = 20;
25
-
26
- /** 落盘文件:`<DSH_HOME>/storages/mobile-plugin/phone-routes.json`,调用时解析。 */
27
- function routesFile() {
28
- return path.join(dshHome(), 'storages', 'mobile-plugin', 'phone-routes.json');
29
- }
30
-
31
- /** 只保留能落盘、也有意义的字段,别把整个 args 原样塞进去(可能很大)。 */
32
- function normalizeSteps(steps) {
33
- if (!Array.isArray(steps)) return [];
34
- const out = [];
35
- for (const step of steps) {
36
- if (!step || typeof step !== 'object') continue;
37
- const entry = {};
38
- if (typeof step.action === 'string' && step.action.trim()) entry.action = step.action.trim();
39
- if (step.args && typeof step.args === 'object' && !Array.isArray(step.args)) entry.args = step.args;
40
- if (step.until && typeof step.until === 'object' && !Array.isArray(step.until)) entry.until = step.until;
41
- if (entry.action) out.push(entry);
42
- }
43
- return out;
44
- }
45
-
46
- /** 读整份账本。读不到 / 读坏 / 形状不对都当空。 */
47
- function readStore() {
48
- let raw;
49
- try {
50
- raw = fs.readFileSync(routesFile(), 'utf8');
51
- } catch {
52
- return {};
53
- }
54
- let parsed;
55
- try {
56
- parsed = JSON.parse(raw);
57
- } catch {
58
- return {};
59
- }
60
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
61
- return parsed;
62
- }
63
-
64
- /** 写整份账本。写不进去就安静放弃:这一轮照样算完成,只是这条没记住。 */
65
- function writeStore(store) {
66
- const file = routesFile();
67
- fs.mkdirSync(path.dirname(file), { recursive: true });
68
- fs.writeFileSync(file, `${JSON.stringify(store, null, 2)}\n`);
69
- }
70
-
71
- /** 归一化包名。 */
72
- function normalizePackage(packageName) {
73
- return typeof packageName === 'string' ? packageName.trim() : '';
74
- }
75
-
76
- /**
77
- * 记一条成功路线。只在成功时由调用方调;包名为空或步骤为空时不记。
78
- * 返回这个包当前的全部记录(方便调用方/测试看结果)。
79
- */
80
- function record(packageName, steps) {
81
- const pkg = normalizePackage(packageName);
82
- const cleaned = normalizeSteps(steps);
83
- if (!pkg || cleaned.length === 0) return [];
84
-
85
- const store = readStore();
86
- const bucket = Array.isArray(store[pkg]) ? store[pkg].filter((item) => item && Array.isArray(item.steps)) : [];
87
- bucket.push({ steps: cleaned, at: Date.now(), hits: 0 });
88
- // 只留最近的 MAX_PER_PACKAGE 条:新记录在尾部,超了从头挤掉最旧的。
89
- store[pkg] = bucket.slice(-MAX_PER_PACKAGE);
90
- try {
91
- writeStore(store);
92
- } catch {
93
- // 写失败不抛,记忆丢一条不影响这一轮已经成功的结果。
94
- }
95
- return store[pkg].map(copyRecord);
96
- }
97
-
98
- function copyRecord(item) {
99
- return {
100
- steps: Array.isArray(item.steps) ? item.steps.map((step) => ({ ...step })) : [],
101
- at: Number.isFinite(item.at) ? item.at : 0,
102
- hits: Number.isFinite(item.hits) ? item.hits : 0,
103
- };
104
- }
105
-
106
- /**
107
- * 读回某个 App 以前成功过的路线(按记录先后,旧的在前)。包名为空或没记录都回空数组。
108
- * 返回的是副本,调用方改不到账本上。
109
- */
110
- function list(packageName) {
111
- const pkg = normalizePackage(packageName);
112
- if (!pkg) return [];
113
- const store = readStore();
114
- const bucket = Array.isArray(store[pkg]) ? store[pkg] : [];
115
- return bucket.filter((item) => item && Array.isArray(item.steps)).map(copyRecord);
116
- }
117
-
118
- /** 单测用:删掉落盘文件,回到「还没有任何记录」。 */
119
- function resetForTest() {
120
- try {
121
- fs.rmSync(routesFile(), { force: true });
122
- } catch {
123
- // 本来就没有。
124
- }
125
- }
126
-
127
- module.exports = {
128
- routesFile,
129
- record,
130
- list,
131
- resetForTest,
132
- MAX_PER_PACKAGE,
133
- };