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.
- package/README.md +17 -2
- package/dsh-mobile-credentials/lib/credentials.js +49 -2
- package/extensions/README.md +25 -21
- package/host.js +16 -1
- package/lib/git/pr.js +375 -0
- package/lib/git/read.js +1 -0
- package/lib/host-capabilities.cjs +67 -0
- package/lib/http/routing.js +25 -0
- package/lib/impl.js +34 -26
- package/lib/mirror/history-blob.cjs +184 -0
- package/lib/mirror/pusher.cjs +276 -1
- package/lib/mobile/approval-facts.js +439 -0
- package/lib/mobile/approval-memory.js +199 -0
- package/lib/mobile/approvals.js +596 -30
- package/lib/mobile/auto-review-log.js +160 -0
- package/lib/mobile/auto-review.js +172 -0
- package/lib/mobile/credential-upgrade.js +14 -0
- package/lib/mobile/device-permissions.js +86 -0
- package/lib/mobile/directory-browse.js +23 -8
- package/lib/mobile/events.js +9 -1
- package/lib/mobile/extension-catalog.js +106 -44
- package/lib/mobile/extension-data.js +6 -0
- package/lib/mobile/file-ops.js +89 -76
- package/lib/mobile/git.js +108 -2
- package/lib/mobile/live-steps.js +107 -4
- package/lib/mobile/mail.js +621 -0
- package/lib/mobile/monitor.js +6 -0
- package/lib/mobile/notification-prefs.js +205 -0
- package/lib/mobile/pairing.js +15 -2
- package/lib/mobile/permissions.js +433 -0
- package/lib/mobile/project-write-queue.js +115 -0
- package/lib/mobile/project-writes.js +61 -0
- package/lib/mobile/push-notify.js +293 -13
- package/lib/mobile/questions.js +20 -3
- package/lib/mobile/recent-failures.js +48 -0
- package/lib/mobile/relay-control.js +5 -0
- package/lib/mobile/session-cache.js +50 -0
- package/lib/mobile/session-last-turn.js +24 -22
- package/lib/mobile/session-new.js +205 -0
- package/lib/mobile/session-send.js +0 -1
- package/lib/mobile/sessions.js +12 -84
- package/lib/mobile/skill-write.js +549 -0
- package/lib/mobile/stats-collect.cjs +33 -3
- package/lib/mobile/stats-ledger.cjs +39 -2
- package/lib/mobile/stream.js +24 -3
- package/lib/mobile/supervisor-broadcast.js +58 -11
- package/lib/mobile/supervisor-tools.js +1 -1
- package/lib/mobile/third-party-extensions.js +158 -0
- package/lib/mobile/uploads.js +30 -14
- package/lib/mobile/worktree-isolation.js +479 -0
- package/lib/mobile/worktree-lifecycle.js +79 -0
- package/lib/p2p/wiring.cjs +41 -16
- package/lib/panel/index.html +15 -15
- package/lib/read-receipt.cjs +89 -5
- package/lib/relay/core.js +25 -1
- package/lib/relay/lan-proxy.js +6 -1
- package/lib/relay/preview.js +21 -1
- package/lib/relay/protocol.js +1 -0
- package/lib/relay/status.js +6 -0
- package/lib/relay/tunnel-forwarder.cjs +178 -0
- package/lib/routes/control-plane.js +35 -1
- package/lib/routes/mobile-api.js +105 -52
- package/lib/shared/via-header.js +15 -2
- package/lib/sidecar-facade-worker.cjs +15 -2
- package/lib/sidecar-facade.cjs +5 -0
- package/lib/tailcat/host-process.cjs +1 -1
- package/lib/tailcat/ingress.cjs +2 -2
- package/lib/tailcat/wiring.cjs +34 -13
- package/package.json +11 -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/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/pet-tools.js +0 -261
- package/lib/mobile/pets.js +0 -755
- package/lib/mobile/phone/access.js +0 -85
- package/lib/mobile/phone/binding.js +0 -247
- package/lib/mobile/phone/confirm.js +0 -189
- 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/index.js +0 -83
- 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-hint.js +0 -164
- package/lib/mobile/phone/routes-memory.js +0 -133
- package/lib/mobile/phone/routes.js +0 -279
- package/lib/mobile/phone/service.js +0 -500
- package/lib/mobile/phone/site-commands.js +0 -271
- 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 -2282
- package/lib/mobile/phone/untrusted.js +0 -65
- package/lib/mobile/phone-knowledge.js +0 -317
- package/lib/mobile/wechat-tools.js +0 -257
- package/lib/mobile/wechat.js +0 -514
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 审批卡「事实行」折算:把一次审批(工具名 + 原始参数)折成一句人话,外加高亮与动作类别。
|
|
5
|
+
*
|
|
6
|
+
* 纯展示、纯函数:输出只进审批卡的展示位,不进任何执行路径,不新增 shell / 文件写 / 系统设置
|
|
7
|
+
* 能力。所有输入都是本来就存在的东西(会话日志里的 tool-call arguments),这里只读不写。
|
|
8
|
+
*
|
|
9
|
+
* 一句话分工:headline 是 agent 自己说的(reason / displayReason),事实行是电脑从原始参数
|
|
10
|
+
* 算出来的;删除 / 推送 / 装软件高亮。算不出来就**不出这一行**,绝不糊一句会让用户误判的话。
|
|
11
|
+
*
|
|
12
|
+
* 动作类别键 `classKey`(`<tool>:<class>`)既做「这一类以后都同意」的记账键,也做「同一轮
|
|
13
|
+
* 重复请求」的比较键,两处必须用同一份,所以只在这里算一遍。
|
|
14
|
+
*
|
|
15
|
+
* 详见 docs/dev-map / decisions 里这条改动的原因。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** 整行事实的字符上限(中文按 1 计)。先保数量与动词,再保目标名。 */
|
|
19
|
+
const FACT_MAX = 40;
|
|
20
|
+
/** 目标清单最多列几个,超出写「等 N 个」。 */
|
|
21
|
+
const MAX_TARGETS = 3;
|
|
22
|
+
/** 一条事实最多几个分句。 */
|
|
23
|
+
const MAX_CLAUSES = 3;
|
|
24
|
+
|
|
25
|
+
/** 删除类程序:高亮。 */
|
|
26
|
+
const DELETE_PROGS = new Set(['rm', 'rmdir', 'unlink', 'shred']);
|
|
27
|
+
/** 包管理器 → 装包动词集合。 */
|
|
28
|
+
const PM_INSTALL = {
|
|
29
|
+
npm: new Set(['install', 'i', 'add']),
|
|
30
|
+
pnpm: new Set(['install', 'i', 'add']),
|
|
31
|
+
yarn: new Set(['install', 'add']),
|
|
32
|
+
bun: new Set(['install', 'add']),
|
|
33
|
+
pip: new Set(['install']),
|
|
34
|
+
pip3: new Set(['install']),
|
|
35
|
+
gem: new Set(['install']),
|
|
36
|
+
cargo: new Set(['install']),
|
|
37
|
+
apt: new Set(['install']),
|
|
38
|
+
'apt-get': new Set(['install']),
|
|
39
|
+
go: new Set(['install']),
|
|
40
|
+
};
|
|
41
|
+
const INSTALL_MANAGERS = new Set(Object.keys(PM_INSTALL));
|
|
42
|
+
|
|
43
|
+
function isRecord(value) {
|
|
44
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 取路径末段(一行放不下整条路径)。 */
|
|
48
|
+
function baseOf(p) {
|
|
49
|
+
if (typeof p !== 'string' || !p) return '';
|
|
50
|
+
const norm = p.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
51
|
+
const idx = norm.lastIndexOf('/');
|
|
52
|
+
return idx >= 0 ? norm.slice(idx + 1) : norm;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 相对 cwd 的第一段目录;超出 cwd / 取不到就 `abs`。 */
|
|
56
|
+
function dirKeyOf(p, cwd) {
|
|
57
|
+
if (typeof p !== 'string' || !p) return 'abs';
|
|
58
|
+
if (typeof cwd !== 'string' || !cwd) return 'abs';
|
|
59
|
+
const norm = p.replace(/\\/g, '/');
|
|
60
|
+
const root = cwd.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
61
|
+
if (!norm.startsWith(`${root}/`)) return 'abs';
|
|
62
|
+
const rel = norm.slice(root.length + 1);
|
|
63
|
+
const seg = rel.split('/')[0];
|
|
64
|
+
return seg && seg !== '..' ? seg : 'abs';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 取文件路径(宿主两种写法都认)。 */
|
|
68
|
+
function pathOf(args) {
|
|
69
|
+
if (!isRecord(args)) return '';
|
|
70
|
+
if (typeof args.file_path === 'string' && args.file_path) return args.file_path;
|
|
71
|
+
if (typeof args.path === 'string' && args.path) return args.path;
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** 把一个目标清单收成「a、b 等 N 个」,最多 `MAX_TARGETS` 个。 */
|
|
76
|
+
function listTargets(names) {
|
|
77
|
+
const clean = names.map((n) => String(n || '').trim()).filter(Boolean);
|
|
78
|
+
if (clean.length === 0) return '';
|
|
79
|
+
if (clean.length <= MAX_TARGETS) return clean.join('、');
|
|
80
|
+
return `${clean.slice(0, MAX_TARGETS).join('、')} 等 ${clean.length} 个`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 按 `&&` `||` `;` `|` 换行切段,剥 sudo 与 VAR=val 前缀,返回每段的 token 数组。 */
|
|
84
|
+
function splitSegments(command) {
|
|
85
|
+
if (typeof command !== 'string') return [];
|
|
86
|
+
// 先把 sh -c "…" / bash -c "…" 剥一层(常见且便宜)。
|
|
87
|
+
let cmd = command;
|
|
88
|
+
const shellWrap = cmd.match(/\b(?:sh|bash)\s+-c\s+(['"])([\s\S]*)\1/);
|
|
89
|
+
if (shellWrap) cmd = shellWrap[2];
|
|
90
|
+
const rawSegs = cmd.split(/\n|&&|\|\||;|\|/);
|
|
91
|
+
const out = [];
|
|
92
|
+
for (let seg of rawSegs) {
|
|
93
|
+
seg = seg.trim();
|
|
94
|
+
if (!seg) continue;
|
|
95
|
+
// 剥段首赋值 VAR=value
|
|
96
|
+
seg = seg.replace(/^(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)+/, '');
|
|
97
|
+
let tokens = seg.split(/\s+/).filter(Boolean);
|
|
98
|
+
// 剥 sudo(可能带选项)
|
|
99
|
+
while (tokens[0] === 'sudo') {
|
|
100
|
+
tokens = tokens.slice(1);
|
|
101
|
+
while (tokens.length && tokens[0].startsWith('-')) tokens = tokens.slice(1);
|
|
102
|
+
}
|
|
103
|
+
if (tokens.length === 0) continue;
|
|
104
|
+
out.push(tokens);
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 去掉首尾引号。 */
|
|
110
|
+
function unquote(s) {
|
|
111
|
+
if (typeof s !== 'string') return '';
|
|
112
|
+
const m = s.match(/^(['"])([\s\S]*)\1$/);
|
|
113
|
+
return m ? m[2] : s;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 从 URL 取 host,失败返回 ''。 */
|
|
117
|
+
function hostOf(url) {
|
|
118
|
+
if (typeof url !== 'string' || !url) return '';
|
|
119
|
+
try {
|
|
120
|
+
return new URL(url).host || '';
|
|
121
|
+
} catch {
|
|
122
|
+
// 相对串(web_fetch 一般给绝对 URL)——退回按域名猜一下,不行就空。
|
|
123
|
+
const m = url.match(/^[a-z]+:\/\/([^/]+)/i);
|
|
124
|
+
return m ? m[1] : '';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 解析一段 bash,返回 `{ clause, highlight, prog }`;cliches 里只给「一段」。 */
|
|
129
|
+
function clauseOfSegment(tokens) {
|
|
130
|
+
const prog = baseOf(tokens[0] || '');
|
|
131
|
+
if (!prog) return null;
|
|
132
|
+
const rest = tokens.slice(1);
|
|
133
|
+
const nonOpt = rest.filter((t) => !t.startsWith('-'));
|
|
134
|
+
|
|
135
|
+
// git 子命令
|
|
136
|
+
if (prog === 'git') {
|
|
137
|
+
const sub = (rest.find((t) => !t.startsWith('-')) || '').toLowerCase();
|
|
138
|
+
if (sub === 'commit') {
|
|
139
|
+
const m = tokens.join(' ').match(/-m\s+(['"])([\s\S]*?)\1/);
|
|
140
|
+
const msg = m ? m[2].slice(0, 20) : '';
|
|
141
|
+
return { clause: msg ? `提交:${msg}` : '提交(git commit)', highlight: false, prog: 'git' };
|
|
142
|
+
}
|
|
143
|
+
if (sub === 'push') {
|
|
144
|
+
const parts = nonOpt.slice(1); // 去掉 'push' 本身
|
|
145
|
+
const target = parts.slice(0, 2).join('/');
|
|
146
|
+
return { clause: target ? `推送 → ${target}` : '推送', highlight: true, prog: 'git' };
|
|
147
|
+
}
|
|
148
|
+
if (sub === 'reset' && rest.includes('--hard')) {
|
|
149
|
+
return { clause: '丢弃未提交改动', highlight: true, prog: 'git' };
|
|
150
|
+
}
|
|
151
|
+
if (sub === 'clean' && rest.some((t) => /^-[a-z]*f/.test(t))) {
|
|
152
|
+
return { clause: '删未跟踪文件', highlight: true, prog: 'git' };
|
|
153
|
+
}
|
|
154
|
+
return { clause: `跑 git ${sub}`.trim(), highlight: false, prog: 'git' };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 删除类
|
|
158
|
+
if (DELETE_PROGS.has(prog)) {
|
|
159
|
+
const names = nonOpt.map(unquote);
|
|
160
|
+
const list = listTargets(names);
|
|
161
|
+
return { clause: list ? `删 ${list}` : '删文件', highlight: true, prog };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 包管理器装包
|
|
165
|
+
if (INSTALL_MANAGERS.has(prog)) {
|
|
166
|
+
const verb = (nonOpt[0] || '').toLowerCase();
|
|
167
|
+
if (PM_INSTALL[prog].has(verb)) {
|
|
168
|
+
const pkg = nonOpt.slice(1).map(unquote).filter((p) => p && !p.startsWith('-')).join('、');
|
|
169
|
+
return { clause: pkg ? `装 ${pkg}(${prog})` : `装包(${prog})`, highlight: true, prog };
|
|
170
|
+
}
|
|
171
|
+
return { clause: `跑 ${prog} ${verb}`.trim(), highlight: false, prog };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 网络
|
|
175
|
+
if (prog === 'curl' || prog === 'wget') {
|
|
176
|
+
const urlTok = rest.find((t) => /^https?:\/\//i.test(t));
|
|
177
|
+
const host = hostOf(urlTok || '');
|
|
178
|
+
return { clause: host ? `连 ${host}` : `跑 ${prog}`, highlight: false, prog };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 重定向写文件(段内出现 > 或 >>)
|
|
182
|
+
const redirect = tokens.findIndex((t) => t === '>' || t === '>>');
|
|
183
|
+
if (redirect >= 0 && tokens[redirect + 1]) {
|
|
184
|
+
return { clause: `写 ${baseOf(tokens[redirect + 1])}`, highlight: false, prog };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 其它程序
|
|
188
|
+
const first = nonOpt[0] !== undefined ? unquote(nonOpt[0]).replace(/^["']+|["']+$/g, '') : '';
|
|
189
|
+
return { clause: first ? `跑 ${prog} ${first}`.trim() : `跑 ${prog}`, highlight: false, prog };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** 单次 bash 调用的类别键(按程序 / git 子命令 / 包管理器子命令 / 程序组合)。 */
|
|
193
|
+
function bashClassKey(command) {
|
|
194
|
+
const segs = splitSegments(command);
|
|
195
|
+
if (segs.length === 0) return 'tool:bash';
|
|
196
|
+
const progs = [];
|
|
197
|
+
let gitSub = null;
|
|
198
|
+
let pmVerb = null;
|
|
199
|
+
for (const tokens of segs) {
|
|
200
|
+
const prog = baseOf(tokens[0] || '');
|
|
201
|
+
if (!prog) continue;
|
|
202
|
+
if (prog === 'git') {
|
|
203
|
+
const sub = (tokens.slice(1).find((t) => !t.startsWith('-')) || '').toLowerCase();
|
|
204
|
+
if (sub) gitSub = sub;
|
|
205
|
+
}
|
|
206
|
+
if (INSTALL_MANAGERS.has(prog)) {
|
|
207
|
+
const verb = (tokens.slice(1).find((t) => !t.startsWith('-')) || '').toLowerCase();
|
|
208
|
+
if (verb) pmVerb = `${prog}:${verb}`;
|
|
209
|
+
}
|
|
210
|
+
if (!progs.includes(prog)) progs.push(prog);
|
|
211
|
+
}
|
|
212
|
+
if (progs.length === 0) return 'tool:bash';
|
|
213
|
+
if (progs.length === 1 && progs[0] === 'git') return `bash:git:${gitSub || 'git'}`;
|
|
214
|
+
if (progs.length === 1 && INSTALL_MANAGERS.has(progs[0]) && pmVerb) return `bash:${pmVerb}`;
|
|
215
|
+
// 多段或普通程序:去重升序拼接
|
|
216
|
+
return `bash:${progs.slice().sort().join('+')}`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** 判断一次调用是不是「解析不出」的壳(run_code / node -e "$(…)" 之类)。 */
|
|
220
|
+
function isOpaque(toolName, args) {
|
|
221
|
+
if (toolName === 'run_code') return true;
|
|
222
|
+
if (toolName === 'bash' && isRecord(args) && typeof args.command === 'string') {
|
|
223
|
+
if (!/\$\(|`/.test(args.command)) return false;
|
|
224
|
+
const tokens = args.command.split(/\s+/);
|
|
225
|
+
const interp = tokens.some((t) => t === '-e' || t === '-c' || /^-[a-z]*[ec]$/.test(t));
|
|
226
|
+
return interp;
|
|
227
|
+
}
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** 单次调用 → `{ clause, highlight, classKey }`。 */
|
|
232
|
+
function callToPiece(toolName, args) {
|
|
233
|
+
const name = typeof toolName === 'string' ? toolName : '';
|
|
234
|
+
if (name === 'bash') {
|
|
235
|
+
if (!isRecord(args) || typeof args.command !== 'string' || !args.command.trim()) {
|
|
236
|
+
return { clause: '', highlight: false, classKey: 'tool:bash' };
|
|
237
|
+
}
|
|
238
|
+
if (isOpaque(name, args)) {
|
|
239
|
+
const segs = splitSegments(args.command);
|
|
240
|
+
const prog = segs.length ? baseOf(segs[0][0] || '') : 'bash';
|
|
241
|
+
return { clause: `跑 ${prog}(内容无法静态解析)`, highlight: false, classKey: `bash:${prog}` };
|
|
242
|
+
}
|
|
243
|
+
const segs = splitSegments(args.command);
|
|
244
|
+
const clauses = [];
|
|
245
|
+
let highlight = false;
|
|
246
|
+
for (const tokens of segs) {
|
|
247
|
+
const piece = clauseOfSegment(tokens);
|
|
248
|
+
if (!piece) continue;
|
|
249
|
+
if (piece.clause) clauses.push(piece.clause);
|
|
250
|
+
if (piece.highlight) highlight = true;
|
|
251
|
+
}
|
|
252
|
+
return { clause: clauses.join(';'), highlight, classKey: bashClassKey(args.command) };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (name === 'write' || name === 'edit') {
|
|
256
|
+
const p = pathOf(args);
|
|
257
|
+
if (!p) return { clause: '', highlight: false, classKey: `tool:${name}` };
|
|
258
|
+
const d = dirKeyOf(p, opts.cwd);
|
|
259
|
+
return { clause: `改 ${baseOf(p)}`, highlight: false, classKey: `${name}:${d}` };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (name === 'read' || name === 'read_image') {
|
|
263
|
+
const p = pathOf(args);
|
|
264
|
+
if (!p) return { clause: '', highlight: false, classKey: `tool:${name}` };
|
|
265
|
+
const d = dirKeyOf(p, opts.cwd);
|
|
266
|
+
return { clause: `读 ${baseOf(p)}`, highlight: false, classKey: `read:${d}` };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (name === 'web_fetch') {
|
|
270
|
+
const url = isRecord(args) && typeof args.url === 'string' ? args.url : '';
|
|
271
|
+
const host = hostOf(url);
|
|
272
|
+
return { clause: host ? `连 ${host}` : '打开网页', highlight: false, classKey: host ? `web_fetch:${host}` : 'tool:web_fetch' };
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (name === 'web_search') {
|
|
276
|
+
let q = '';
|
|
277
|
+
if (isRecord(args)) {
|
|
278
|
+
if (typeof args.query === 'string') q = args.query;
|
|
279
|
+
else if (Array.isArray(args.queries) && typeof args.queries[0] === 'string') q = args.queries[0];
|
|
280
|
+
}
|
|
281
|
+
const short = q.slice(0, 20);
|
|
282
|
+
return { clause: short ? `在网上搜 "${short}"` : '在网上搜', highlight: false, classKey: 'tool:web_search' };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// 未知工具
|
|
286
|
+
return { clause: name ? `执行 ${name}` : '', highlight: false, classKey: name ? `tool:${name}` : 'tool:unknown' };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** 危险度排序,用于多调用聚合时取「最危险那条」做 classKey。 */
|
|
290
|
+
function dangerRank(classKey) {
|
|
291
|
+
if (/^(bash:rm|bash:rmdir|bash:unlink|bash:shred)$/.test(classKey)) return 5;
|
|
292
|
+
if (classKey === 'bash:git:push' || classKey === 'bash:git:reset' || classKey === 'bash:git:clean') return 5;
|
|
293
|
+
if (INSTALL_MANAGERS.has((classKey.split(':')[1] || '').split(':')[0]) && /install|add|:i$/.test(classKey)) return 4;
|
|
294
|
+
if (/^(write|edit):/.test(classKey)) return 3;
|
|
295
|
+
if (/^read:/.test(classKey)) return 2;
|
|
296
|
+
return 1;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** 把 classKey 翻成给人看的一句(撤销页 / 按钮用)。 */
|
|
300
|
+
function labelOf(classKey) {
|
|
301
|
+
const parts = String(classKey || '').split(':');
|
|
302
|
+
const tool = parts[0];
|
|
303
|
+
if (tool === 'bash') {
|
|
304
|
+
if (parts[1] === 'git' && parts[2]) {
|
|
305
|
+
const map = { push: 'git push', commit: 'git commit', reset: 'git reset', clean: 'git clean' };
|
|
306
|
+
return `Bash · ${map[parts[2]] || `git ${parts[2]}`}`;
|
|
307
|
+
}
|
|
308
|
+
if (parts.length === 3) {
|
|
309
|
+
return `Bash · ${parts[1]} ${parts[2] === 'add' || parts[2] === 'install' || parts[2] === 'i' ? '装包' : parts[2]}`;
|
|
310
|
+
}
|
|
311
|
+
const prog = parts[1] || '';
|
|
312
|
+
if (DELETE_PROGS.has(prog)) return 'Bash · 删除文件';
|
|
313
|
+
if (prog === 'curl' || prog === 'wget') return 'Bash · 联网请求';
|
|
314
|
+
return `Bash · 运行 ${prog || '命令'}`;
|
|
315
|
+
}
|
|
316
|
+
if (tool === 'write' || tool === 'edit') return `改文件 · ${parts[1] || '未知目录'}`;
|
|
317
|
+
if (tool === 'read') return `读文件 · ${parts[1] || '未知目录'}`;
|
|
318
|
+
if (tool === 'web_fetch') return `联网 · ${parts[1] || '网页'}`;
|
|
319
|
+
if (tool === 'tool') return `工具 · ${parts[1] || '未知'}`;
|
|
320
|
+
return tool ? String(classKey) : '';
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let opts = {};
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* 主入口:`calls` = `{toolName, args}` 或它的数组;`options.cwd` 用于写/读文件的目录归类。
|
|
327
|
+
* 返回 `{ fact, highlight, classKey, classLabel, rememberable }`。
|
|
328
|
+
*/
|
|
329
|
+
function deriveApprovalFacts(calls, options) {
|
|
330
|
+
opts = isRecord(options) ? options : {};
|
|
331
|
+
const list = Array.isArray(calls) ? calls : [calls];
|
|
332
|
+
const pieces = [];
|
|
333
|
+
for (const call of list) {
|
|
334
|
+
if (!isRecord(call)) continue;
|
|
335
|
+
const piece = callToPiece(call.toolName, call.args);
|
|
336
|
+
if (piece) pieces.push(piece);
|
|
337
|
+
}
|
|
338
|
+
const nonEmpty = pieces.filter((p) => p.clause);
|
|
339
|
+
const joined = nonEmpty.map((p) => p.clause).slice(0, MAX_CLAUSES).join(';');
|
|
340
|
+
const highlight = pieces.some((p) => p.highlight);
|
|
341
|
+
let fact = joined;
|
|
342
|
+
if (fact.length > FACT_MAX) {
|
|
343
|
+
// 先保数量与动词、再保目标名:若带「等 N 个」,保住这段后缀,只截前面的目标清单。
|
|
344
|
+
const m = fact.match(/^(.*?)(\s等\s\d+\s个)$/);
|
|
345
|
+
if (m) {
|
|
346
|
+
const suffix = m[2];
|
|
347
|
+
const room = FACT_MAX - suffix.length - 1;
|
|
348
|
+
fact = room > 0 ? `${m[1].slice(0, room)}…${suffix}` : suffix.trim();
|
|
349
|
+
} else {
|
|
350
|
+
fact = `${fact.slice(0, FACT_MAX - 1)}…`;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// classKey:多调用取最危险那条;单调用就是它自己。
|
|
355
|
+
let classKey = pieces.length ? pieces[0].classKey : 'tool:unknown';
|
|
356
|
+
for (const p of pieces) {
|
|
357
|
+
if (dangerRank(p.classKey) > dangerRank(classKey)) classKey = p.classKey;
|
|
358
|
+
}
|
|
359
|
+
// 高亮是同一份解析给出的第二个信号:删除 / 推送 / reset / clean / 装包只在这几处点亮
|
|
360
|
+
// (见 `clauseOfSegment`)。组合命令的类别键容易把危险那一段藏进 `a+b`,两条一起看才不漏。
|
|
361
|
+
const rememberable = isRememberable(classKey) && !highlight;
|
|
362
|
+
return {
|
|
363
|
+
fact,
|
|
364
|
+
highlight,
|
|
365
|
+
classKey,
|
|
366
|
+
classLabel: labelOf(classKey),
|
|
367
|
+
rememberable,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 哪些动作类别**永远不许**被「这一类以后都同意」记住。
|
|
373
|
+
*
|
|
374
|
+
* 判据分两层,两层都只看原始请求折出来的东西(`deriveApprovalFacts` 的输入就是原始参数):
|
|
375
|
+
* - **动作类别**(classKey):删除类程序、`git push` / `git reset` / `git clean`、装包动词;
|
|
376
|
+
* - **高亮**(highlight):上面这几类一旦被解析出来就会置高亮,多段命令(`cd x && rm -rf y`)
|
|
377
|
+
* 的类别键是 `bash:cd+rm` 这种组合,单看类别字符串容易漏,高亮是同一份解析给出的第二个信号。
|
|
378
|
+
*
|
|
379
|
+
* 理由:`rm` 这个类别一旦被记住,任意 `rm`(包括 `rm -rf ~`)都变成静默放行 —— 这不是「同类」,
|
|
380
|
+
* 只是「同名」。推送、装软件同理(推送会动远端,装包会执行第三方脚本)。这三类一律每次问,
|
|
381
|
+
* 宁可多推一张卡。
|
|
382
|
+
*/
|
|
383
|
+
function isIrreversibleClass(classKey) {
|
|
384
|
+
const key = String(classKey || '');
|
|
385
|
+
if (!key) return false;
|
|
386
|
+
// `git rm` 也是删文件(只是经过了 git),`git push/reset/clean` 会动远端或不可恢复。
|
|
387
|
+
if (key === 'bash:git:push' || key === 'bash:git:reset' || key === 'bash:git:clean' || key === 'bash:git:rm') return true;
|
|
388
|
+
if (!key.startsWith('bash:')) return false;
|
|
389
|
+
// 组合键(`bash:cd+rm`)与单程序键(`bash:rm`)都拆成「程序[:动词]」逐段看。
|
|
390
|
+
for (const part of key.slice('bash:'.length).split('+')) {
|
|
391
|
+
const [prog, verb] = part.split(':');
|
|
392
|
+
if (!prog) continue;
|
|
393
|
+
if (DELETE_PROGS.has(prog)) return true;
|
|
394
|
+
if (INSTALL_MANAGERS.has(prog) && PM_INSTALL[prog].has(String(verb || '').toLowerCase())) return true;
|
|
395
|
+
}
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* 键退化到 `tool:<name>`(无区分度)时不给「以后都同意」;删除 / 推送 / 装软件这三类也不给
|
|
401
|
+
* (见 `isIrreversibleClass`);其余给。
|
|
402
|
+
*/
|
|
403
|
+
function isRememberable(classKey) {
|
|
404
|
+
if (!classKey || classKey === 'tool:unknown') return false;
|
|
405
|
+
if (classKey.startsWith('tool:')) return false;
|
|
406
|
+
if (isIrreversibleClass(classKey)) return false;
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** 归一化的关键参数摘要(同轮重复比较用;字符串直接比,不用哈希)。 */
|
|
411
|
+
function keyArgsOf(toolName, args) {
|
|
412
|
+
if (!isRecord(args)) return '';
|
|
413
|
+
try {
|
|
414
|
+
if (toolName === 'bash' && typeof args.command === 'string') {
|
|
415
|
+
return args.command.replace(/\s+/g, ' ').trim();
|
|
416
|
+
}
|
|
417
|
+
if ((toolName === 'write' || toolName === 'edit') && pathOf(args)) {
|
|
418
|
+
const content = typeof args.content === 'string' ? args.content : '';
|
|
419
|
+
const oldStr = typeof args.old_string === 'string' ? args.old_string : '';
|
|
420
|
+
const newStr = typeof args.new_string === 'string' ? args.new_string : '';
|
|
421
|
+
const body = content.length > 65536
|
|
422
|
+
? `${content.length}\u0000${content.slice(0, 64)}\u0000${content.slice(-64)}`
|
|
423
|
+
: content;
|
|
424
|
+
return `${pathOf(args)}\u0000${body}\u0000${oldStr}\u0000${newStr}`;
|
|
425
|
+
}
|
|
426
|
+
return JSON.stringify(args);
|
|
427
|
+
} catch {
|
|
428
|
+
return '';
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
module.exports = {
|
|
433
|
+
deriveApprovalFacts,
|
|
434
|
+
keyArgsOf,
|
|
435
|
+
labelOf,
|
|
436
|
+
isRememberable,
|
|
437
|
+
isIrreversibleClass,
|
|
438
|
+
FACT_MAX,
|
|
439
|
+
};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 审批记忆账:用户按「这一类以后都同意」放行过的动作类别,回在这里记一条。
|
|
5
|
+
*
|
|
6
|
+
* 为什么单独一本账:审批桥本身的挂起项全在内存里(宿主重启就没了),而「以后都同意」是一种
|
|
7
|
+
* 跨会话、跨重启都要生效的持久偏好;它必须落盘,并且**能在 UI 里逐条撤销** —— 撤销权是这条
|
|
8
|
+
* 功能成立的前提(用户点错了随时能收回),所以这里提供按 classKey 的删除。
|
|
9
|
+
*
|
|
10
|
+
* 同一本账还带**最近的拒绝记录**:用户在审批卡上拒掉一条时把理由写下来,设置页的「最近拒绝」
|
|
11
|
+
* 一节才有得对账(理由当时只在卡上闪一下,卡一结算就没了)。这份记录只给人看,不参与任何
|
|
12
|
+
* 判定,所以只留最近若干条、超了挤掉最老的。
|
|
13
|
+
*
|
|
14
|
+
* 落盘位置 `<DSH_HOME>/storages/mobile-plugin/approval-rules.json`,照任务账(task-ledger.js)
|
|
15
|
+
* 同一套「原子写 + 读坏当空」的边界:账本读不动不能把审批拦在门外,写失败也只影响「重启后
|
|
16
|
+
* 还在不在」。`DSH_MOBILE_APPROVAL_RULES` 只给测试注入路径用。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const fs = require('node:fs');
|
|
20
|
+
const path = require('node:path');
|
|
21
|
+
|
|
22
|
+
const { dshHome } = require('../shared/paths.js');
|
|
23
|
+
// 只借一个纯函数判据(删除 / 推送 / 装软件这三类不给「以后都同意」),不反向依赖。
|
|
24
|
+
const { isIrreversibleClass } = require('./approval-facts.js');
|
|
25
|
+
|
|
26
|
+
const VERSION = 1;
|
|
27
|
+
/** 规则条数上限:纯兜底,超了挤掉最老的(规则很小,正常远到不了)。 */
|
|
28
|
+
const MAX_RULES = 500;
|
|
29
|
+
/** 拒绝记录上限:只是给人对账用的流水,留最近这些就够了。 */
|
|
30
|
+
const MAX_DECISIONS = 50;
|
|
31
|
+
|
|
32
|
+
function rulesFile() {
|
|
33
|
+
return process.env.DSH_MOBILE_APPROVAL_RULES
|
|
34
|
+
|| path.join(dshHome(), 'storages', 'mobile-plugin', 'approval-rules.json');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isRecord(value) {
|
|
38
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function textOf(value, max) {
|
|
42
|
+
if (typeof value !== 'string') return '';
|
|
43
|
+
return value.replace(/\s+/g, ' ').trim().slice(0, max);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function normalizeRule(entry) {
|
|
47
|
+
if (!isRecord(entry)) return null;
|
|
48
|
+
const classKey = textOf(entry.classKey, 200);
|
|
49
|
+
if (!classKey) return null;
|
|
50
|
+
// 删除 / 推送 / 装软件这三类**永远不认**,读到也当没写过(见 approval-facts 的
|
|
51
|
+
// `isIrreversibleClass`):旧版本记下过 `bash:rm`,不清掉的话一次「以后都同意」会继续
|
|
52
|
+
// 把任意 `rm` 静默放行。这里在加载口清洗,下一次写盘就把它们从文件里抹掉。
|
|
53
|
+
if (isIrreversibleClass(classKey)) return null;
|
|
54
|
+
return {
|
|
55
|
+
classKey,
|
|
56
|
+
label: textOf(entry.label, 120) || classKey,
|
|
57
|
+
createdAt: Number.isFinite(entry.createdAt) ? entry.createdAt : Date.now(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function emptyStore() {
|
|
62
|
+
return { version: VERSION, updatedAt: 0, rules: [], decisions: [] };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 一条拒绝记录:形状不对的丢掉,读坏的文件不能把页面撑炸。 */
|
|
66
|
+
function normalizeDecision(entry) {
|
|
67
|
+
if (!isRecord(entry)) return null;
|
|
68
|
+
const classKey = textOf(entry.classKey, 200);
|
|
69
|
+
if (!classKey) return null;
|
|
70
|
+
const reason = textOf(entry.reason, 200);
|
|
71
|
+
return {
|
|
72
|
+
classKey,
|
|
73
|
+
reason: reason || undefined,
|
|
74
|
+
at: Number.isFinite(entry.at) ? entry.at : Date.now(),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 读账:文件不存在 / 读坏 / 形状不对一律当空,绝不抛。 */
|
|
79
|
+
function readStore() {
|
|
80
|
+
let raw;
|
|
81
|
+
try {
|
|
82
|
+
raw = JSON.parse(fs.readFileSync(rulesFile(), 'utf8'));
|
|
83
|
+
} catch {
|
|
84
|
+
return emptyStore();
|
|
85
|
+
}
|
|
86
|
+
if (!isRecord(raw) || !Array.isArray(raw.rules)) return emptyStore();
|
|
87
|
+
const rules = [];
|
|
88
|
+
for (const entry of raw.rules) {
|
|
89
|
+
const rule = normalizeRule(entry);
|
|
90
|
+
if (rule) rules.push(rule);
|
|
91
|
+
}
|
|
92
|
+
const decisions = [];
|
|
93
|
+
for (const entry of Array.isArray(raw.decisions) ? raw.decisions : []) {
|
|
94
|
+
const decision = normalizeDecision(entry);
|
|
95
|
+
if (decision) decisions.push(decision);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
version: VERSION,
|
|
99
|
+
updatedAt: Number.isFinite(raw.updatedAt) ? raw.updatedAt : 0,
|
|
100
|
+
rules,
|
|
101
|
+
decisions,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 原子写:先写临时文件再 rename;写失败安静返回 false,不抛。 */
|
|
106
|
+
function saveStore(store) {
|
|
107
|
+
const file = rulesFile();
|
|
108
|
+
let rules = store.rules.slice();
|
|
109
|
+
if (rules.length > MAX_RULES) {
|
|
110
|
+
rules = rules.sort((a, b) => a.createdAt - b.createdAt).slice(rules.length - MAX_RULES);
|
|
111
|
+
}
|
|
112
|
+
let decisions = (store.decisions || []).slice();
|
|
113
|
+
if (decisions.length > MAX_DECISIONS) decisions = decisions.slice(decisions.length - MAX_DECISIONS);
|
|
114
|
+
const next = { ...store, version: VERSION, updatedAt: Date.now(), rules, decisions };
|
|
115
|
+
try {
|
|
116
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
117
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
118
|
+
fs.writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
|
|
119
|
+
fs.renameSync(tmp, file);
|
|
120
|
+
return true;
|
|
121
|
+
} catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 列出全部规则(给撤销页)。 */
|
|
127
|
+
function listRules() {
|
|
128
|
+
return readStore().rules.map((rule) => ({ classKey: rule.classKey, label: rule.label }));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** 这一类是否已被允许。 */
|
|
132
|
+
function hasRule(classKey) {
|
|
133
|
+
if (!classKey) return false;
|
|
134
|
+
return readStore().rules.some((rule) => rule.classKey === classKey);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 记一条(已存在则更新 label,不重复)。不可记的类别直接拒(见 `normalizeRule`)。 */
|
|
138
|
+
function addRule({ classKey, label }) {
|
|
139
|
+
const key = textOf(classKey, 200);
|
|
140
|
+
if (!key) return false;
|
|
141
|
+
if (isIrreversibleClass(key)) return false;
|
|
142
|
+
const store = readStore();
|
|
143
|
+
const at = store.rules.findIndex((rule) => rule.classKey === key);
|
|
144
|
+
if (at >= 0) {
|
|
145
|
+
store.rules[at] = { ...store.rules[at], label: textOf(label, 120) || store.rules[at].label };
|
|
146
|
+
} else {
|
|
147
|
+
store.rules.push({ classKey: key, label: textOf(label, 120) || key, createdAt: Date.now() });
|
|
148
|
+
}
|
|
149
|
+
return saveStore(store);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** 撤一条。返回是否真的删掉了。 */
|
|
153
|
+
function removeRule(classKey) {
|
|
154
|
+
const key = textOf(classKey, 200);
|
|
155
|
+
if (!key) return false;
|
|
156
|
+
const store = readStore();
|
|
157
|
+
const next = store.rules.filter((rule) => rule.classKey !== key);
|
|
158
|
+
if (next.length === store.rules.length) return false;
|
|
159
|
+
store.rules = next;
|
|
160
|
+
saveStore(store);
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** 最近的拒绝记录(新的在前),给设置页「最近拒绝」那一节。 */
|
|
165
|
+
function listDecisions() {
|
|
166
|
+
return readStore().decisions
|
|
167
|
+
.slice()
|
|
168
|
+
.sort((a, b) => b.at - a.at)
|
|
169
|
+
.map((decision) => ({
|
|
170
|
+
classKey: decision.classKey,
|
|
171
|
+
reason: decision.reason,
|
|
172
|
+
at: decision.at,
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 记一条拒绝。只给人对账用,不参与任何判定;缺 classKey 就不记(没有类别的行在页面上说不出
|
|
178
|
+
* 是哪一类被拒),落盘失败也只影响这一条留不留得下来。
|
|
179
|
+
*/
|
|
180
|
+
function recordDecision({ classKey, reason } = {}) {
|
|
181
|
+
const key = textOf(classKey, 200);
|
|
182
|
+
if (!key) return false;
|
|
183
|
+
const store = readStore();
|
|
184
|
+
store.decisions.push({
|
|
185
|
+
classKey: key,
|
|
186
|
+
reason: textOf(reason, 200) || undefined,
|
|
187
|
+
at: Date.now(),
|
|
188
|
+
});
|
|
189
|
+
return saveStore(store);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
module.exports = {
|
|
193
|
+
listRules,
|
|
194
|
+
hasRule,
|
|
195
|
+
addRule,
|
|
196
|
+
removeRule,
|
|
197
|
+
listDecisions,
|
|
198
|
+
recordDecision,
|
|
199
|
+
};
|