dsh-mobile-plugin 0.5.34 → 0.5.36
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 +0 -11
- package/lib/mobile/answer-sources.js +223 -0
- package/lib/mobile/approval-facts.js +0 -13
- package/lib/mobile/approval-memory.js +1 -1
- package/lib/mobile/events.js +0 -20
- package/lib/mobile/extension-data.js +105 -5
- package/lib/mobile/history-derive.js +54 -1
- package/lib/mobile/notification-prefs.js +2 -2
- package/lib/mobile/permissions.js +13 -24
- package/lib/mobile/plugin-market.js +103 -4
- package/lib/mobile/run-timeline.js +317 -0
- package/lib/mobile/session-send.js +0 -1
- package/lib/mobile/session-stop-summary.js +122 -0
- package/lib/mobile/stats-ledger.cjs +45 -0
- package/lib/mobile/stop-summary.js +146 -0
- package/lib/mobile/third-party-extensions.js +86 -0
- package/lib/mobile/tool-result-cache.js +30 -2
- package/lib/panel/index.html +15 -15
- package/lib/relay/lan-proxy.js +20 -11
- package/lib/relay/tunnel.js +28 -12
- package/lib/routes/mobile-api.js +26 -58
- package/lib/shared/derived-cache.js +121 -0
- package/lib/shared/http-util.js +55 -18
- package/package.json +1 -3
- package/assets/pets/README.md +0 -9
- package/assets/pets/deepy-whale/attention.gif +0 -0
- package/assets/pets/deepy-whale/done.gif +0 -0
- package/assets/pets/deepy-whale/error.gif +0 -0
- package/assets/pets/deepy-whale/idle.gif +0 -0
- package/assets/pets/deepy-whale/pack.json +0 -54
- package/assets/pets/deepy-whale/sleeping.gif +0 -0
- package/assets/pets/deepy-whale/working-3.gif +0 -0
- package/assets/pets/deepy-whale/working.gif +0 -0
- package/config/agent-presets/supervisor/agent.cordis.yml +0 -237
- package/config/agent-presets/supervisor/preset.yml +0 -3
- package/knowledge/apps/alipay.md +0 -30
- package/knowledge/apps/android-settings.md +0 -30
- package/knowledge/apps/baijiahao.md +0 -30
- package/knowledge/apps/bilibili.md +0 -31
- package/knowledge/apps/boss-zhipin.md +0 -32
- package/knowledge/apps/dedao.md +0 -33
- package/knowledge/apps/douyin.md +0 -32
- package/knowledge/apps/feishu.md +0 -35
- package/knowledge/apps/gmail.md +0 -33
- package/knowledge/apps/jike.md +0 -31
- package/knowledge/apps/kuaishou.md +0 -34
- package/knowledge/apps/linkedin.md +0 -33
- package/knowledge/apps/qqmail.md +0 -30
- package/knowledge/apps/taobao.md +0 -33
- package/knowledge/apps/telegram.md +0 -27
- package/knowledge/apps/toutiao.md +0 -32
- package/knowledge/apps/uber-eats.md +0 -26
- package/knowledge/apps/uber.md +0 -27
- package/knowledge/apps/wechat.md +0 -33
- package/knowledge/apps/weibo.md +0 -31
- package/knowledge/apps/whatsapp.md +0 -27
- package/knowledge/apps/x.md +0 -32
- package/knowledge/apps/xiaohongshu.md +0 -30
- package/knowledge/apps/zhihu.md +0 -31
- package/knowledge/sites/bilibili.com/SITE.md +0 -50
- package/knowledge/sites/bilibili.com/references/view-fields.md +0 -17
- package/knowledge/sites/github.com/SITE.md +0 -51
- package/knowledge/sites/github.com/references/repo-fields.md +0 -13
- package/knowledge/sites/x.com/SITE.md +0 -47
- package/knowledge/sites/xiaohongshu.com/SITE.md +0 -48
- package/knowledge/sites/xiaohongshu.com/references/note-fields.md +0 -18
- package/knowledge/sites/youtube.com/SITE.md +0 -49
- package/knowledge/sites/youtube.com/references/innertube-fields.md +0 -14
- package/knowledge/sites/zhihu.com/SITE.md +0 -47
- package/knowledge/sites/zhihu.com/references/api-fields.md +0 -21
- package/lib/mobile/auto-review-log.js +0 -160
- package/lib/mobile/knowledge-base.js +0 -481
- package/lib/mobile/mail.js +0 -621
- package/lib/mobile/pet-tools.js +0 -261
- package/lib/mobile/pets.js +0 -755
- package/lib/mobile/phone/access.js +0 -140
- package/lib/mobile/phone/binding.js +0 -247
- package/lib/mobile/phone/confirm.js +0 -190
- package/lib/mobile/phone/evidence.js +0 -228
- package/lib/mobile/phone/gate.js +0 -290
- package/lib/mobile/phone/grounding.js +0 -314
- package/lib/mobile/phone/guard.js +0 -465
- package/lib/mobile/phone/guarded.js +0 -86
- package/lib/mobile/phone/index.js +0 -114
- package/lib/mobile/phone/irreversible.js +0 -226
- package/lib/mobile/phone/knowledge-tools.js +0 -665
- package/lib/mobile/phone/learn.js +0 -329
- package/lib/mobile/phone/pacing.js +0 -173
- package/lib/mobile/phone/redact.js +0 -237
- package/lib/mobile/phone/risk.js +0 -95
- package/lib/mobile/phone/route-extract.js +0 -460
- package/lib/mobile/phone/route-hint.js +0 -164
- package/lib/mobile/phone/routes-memory.js +0 -133
- package/lib/mobile/phone/routes.js +0 -287
- package/lib/mobile/phone/service.js +0 -520
- package/lib/mobile/phone/site-commands.js +0 -271
- package/lib/mobile/phone/skill-recall.js +0 -246
- package/lib/mobile/phone/skill-routes.js +0 -106
- package/lib/mobile/phone/step-summary.js +0 -201
- package/lib/mobile/phone/stop-summary.js +0 -235
- package/lib/mobile/phone/tool-groups.js +0 -125
- package/lib/mobile/phone/tools.js +0 -2590
- package/lib/mobile/phone/untrusted.js +0 -65
- package/lib/mobile/phone-knowledge.js +0 -317
- package/lib/mobile/route-store.js +0 -266
- package/lib/mobile/supervisor-broadcast.js +0 -503
- package/lib/mobile/supervisor-memory/index.js +0 -305
- package/lib/mobile/supervisor-runtime/index.js +0 -54
- package/lib/mobile/supervisor-runtime/inject.js +0 -218
- package/lib/mobile/supervisor-runtime/judgment.js +0 -113
- package/lib/mobile/supervisor-tools.js +0 -419
- package/lib/mobile/task-ledger.js +0 -381
|
@@ -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
|
-
};
|
package/lib/mobile/phone/risk.js
DELETED
|
@@ -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
|
-
};
|