@ssamurias/dsh-fish 0.9.5 → 0.9.6
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/AGENTS.md +30 -7
- package/CHANGELOG.md +125 -2
- package/README.md +5 -2
- package/RELEASE-NOTES-0.9.5.md +2 -1
- package/RELEASE-NOTES-0.9.6.md +84 -0
- package/RELEASE.md +2 -2
- package/lib/ask.js +1 -1
- package/lib/backup.js +344 -37
- package/lib/bili.js +8 -2
- package/lib/browse.js +62 -7
- package/lib/capture.js +3 -1
- package/lib/client.js +711 -199
- package/lib/comment.js +96 -31
- package/lib/deliver.js +6 -4
- package/lib/derive.js +55 -11
- package/lib/events.js +18 -6
- package/lib/generator.js +9 -3
- package/lib/hear.js +44 -2
- package/lib/herdiary.js +45 -11
- package/lib/history.js +23 -4
- package/lib/home.js +17 -1
- package/lib/hook.js +189 -0
- package/lib/import.js +37 -12
- package/lib/index.js +8 -6
- package/lib/look.js +11 -2
- package/lib/move.js +6 -4
- package/lib/note.js +11 -11
- package/lib/observe.js +481 -200
- package/lib/outing.js +140 -29
- package/lib/persona.js +64 -11
- package/lib/possess.js +4 -3
- package/lib/quality.js +4 -1
- package/lib/restrict.js +252 -36
- package/lib/say.js +4 -1
- package/lib/scheduler.js +97 -62
- package/lib/schema.js +15 -1
- package/lib/selfcheck.js +63 -10
- package/lib/selfdoc.js +85 -14
- package/lib/selfupdate.js +38 -1
- package/lib/settings.js +14 -2
- package/lib/speak.js +21 -4
- package/lib/store.js +16 -0
- package/lib/tenant.js +33 -0
- package/lib/turns.js +79 -0
- package/lib/use.js +28 -15
- package/lib/video.js +69 -38
- package/lib/watch.js +5 -2
- package/lib/wish.js +45 -7
- package/package.json +1 -1
package/lib/selfupdate.js
CHANGED
|
@@ -543,6 +543,18 @@ export function vbsFor(cmdPath) {
|
|
|
543
543
|
].join('\r\n')
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
+
/**
|
|
547
|
+
* `.vbs` 必须写成 UTF-16LE + BOM(issue #97)。
|
|
548
|
+
*
|
|
549
|
+
* `wscript.exe` 读脚本默认按**系统 ANSI 代码页**(简体中文 = GBK),不认 UTF-8。
|
|
550
|
+
* 数据目录带中文(`G:\大肥鱼\…`)时,落盘的 UTF-8 字节被当 GBK 念成乱码路径,
|
|
551
|
+
* `cmd` 找不到脚本、`//B` 又把错误吞了 —— 界面表现就是「点了没反应」。
|
|
552
|
+
* `.cmd` 相反,必须 UTF-8 无 BOM(cmd 会把 BOM 念成 `@echo`)。
|
|
553
|
+
*/
|
|
554
|
+
export function vbsBytes(text) {
|
|
555
|
+
return Buffer.concat([Buffer.from([0xff, 0xfe]), Buffer.from(String(text ?? ''), 'utf16le')])
|
|
556
|
+
}
|
|
557
|
+
|
|
546
558
|
/**
|
|
547
559
|
* 写脚本 + 起进程(detached,宿主被杀也不会带走它)。
|
|
548
560
|
* 返回脚本路径,调用方负责把状态切到 installing。
|
|
@@ -574,7 +586,8 @@ export async function armInstall({
|
|
|
574
586
|
let child
|
|
575
587
|
if (platform === 'win32') {
|
|
576
588
|
const vbsPath = path.join(dir, `install-v${v}${backupSuffix}.vbs`)
|
|
577
|
-
|
|
589
|
+
// UTF-16LE + BOM:wscript 按 ANSI 读脚本,UTF-8 的中文路径会被念成乱码(issue #97)。
|
|
590
|
+
await fsp.writeFile(vbsPath, vbsBytes(vbsFor(scriptPath)))
|
|
578
591
|
child = spawnImpl('wscript.exe', ['//B', '//Nologo', vbsPath], {
|
|
579
592
|
cwd: root,
|
|
580
593
|
detached: true,
|
|
@@ -625,10 +638,14 @@ export function createSelfUpdater({
|
|
|
625
638
|
downloadImpl = downloadTarball,
|
|
626
639
|
now = () => Date.now(),
|
|
627
640
|
platform = process.platform,
|
|
641
|
+
/** 起了安装脚本之后等 last.log 多久(测试用短值;issue #97) */
|
|
642
|
+
installCheckMs = 12_000,
|
|
628
643
|
} = {}) {
|
|
629
644
|
const dir = path.join(root, 'updates')
|
|
630
645
|
let st = { phase: 'idle', version: '', error: '', bytes: 0, total: 0, source: '', note: '', file: '', startedAt: 0 }
|
|
631
646
|
let running = false
|
|
647
|
+
/** 起了安装脚本之后盯 last.log 的那个定时器(issue #97),下一次安装前清掉 */
|
|
648
|
+
let armedWatch = null
|
|
632
649
|
|
|
633
650
|
const snapshot = () => {
|
|
634
651
|
const profileDir = profileDirOf(moduleUrl)
|
|
@@ -719,6 +736,26 @@ export function createSelfUpdater({
|
|
|
719
736
|
tarball: st.file,
|
|
720
737
|
})
|
|
721
738
|
st = { ...st, phase: 'installing', note: '正在关闭应用并在后台安装,装完会自动重开。' }
|
|
739
|
+
// 起了进程 ≠ 跑起来了(issue #97):.vbs 崩掉时 wscript 立刻退出、一个字都不写,
|
|
740
|
+
// //B 又把错误吞了,界面会永远停在「正在安装」。给 12 秒看 last.log:
|
|
741
|
+
// 它还是没出现,就说明启动器没跑起来,别让人干等。
|
|
742
|
+
try {
|
|
743
|
+
if (armedWatch) clearTimeout(armedWatch)
|
|
744
|
+
armedWatch = setTimeout(() => {
|
|
745
|
+
armedWatch = null
|
|
746
|
+
try {
|
|
747
|
+
if (st.phase !== 'installing') return
|
|
748
|
+
if (fs.existsSync(armed.logFile)) return
|
|
749
|
+
st = {
|
|
750
|
+
...st,
|
|
751
|
+
phase: 'failed',
|
|
752
|
+
error: `安装脚本没跑起来(多半是路径里有中文或空格)。手动装:在资源管理器里双击 ${armed.scriptPath}`,
|
|
753
|
+
note: '',
|
|
754
|
+
}
|
|
755
|
+
} catch { /* ignore */ }
|
|
756
|
+
}, installCheckMs)
|
|
757
|
+
if (typeof armedWatch.unref === 'function') armedWatch.unref()
|
|
758
|
+
} catch { /* 没有定时器的环境(测试夹具)就跳过 */ }
|
|
722
759
|
return { ok: true, phase: 'installing', script: armed.scriptPath }
|
|
723
760
|
} catch (e) {
|
|
724
761
|
return { ok: false, error: `起安装脚本失败:${e?.message ?? e}` }
|
package/lib/settings.js
CHANGED
|
@@ -100,7 +100,10 @@ export const DEFAULTS = {
|
|
|
100
100
|
keywords: [], // 额外的搜索词(可追加;空 = 只看首页/排行)
|
|
101
101
|
// 她什么时候能上网(2026-10-23 加,用户要求单独可调)
|
|
102
102
|
// 和"什么时候醒来"是两件事:醒着不一定要上网,上网只在醒着时发生。
|
|
103
|
-
|
|
103
|
+
// null = 跟着醒来时段走(issue #86 第 2 条,2026-11-09 用户拍板)。
|
|
104
|
+
// 不另给一段默认值:她睡着的时候不该被安排出门、也不该攒着素材等她醒;
|
|
105
|
+
// 醒来那一刻再现场去翻,翻到的直接进这一轮的上下文。
|
|
106
|
+
window: null,
|
|
104
107
|
// 评论区里别人的话(2026-10-24,用户 m02454)
|
|
105
108
|
// 打开后每次浏览最多留 1 条评论给她读(跨视频重复 > 高赞短句 > 25% 随机)。
|
|
106
109
|
// 关掉也能正常上网——只是她再也读不到别人的说法。
|
|
@@ -339,7 +342,16 @@ export function normalizeConfig(raw = {}) {
|
|
|
339
342
|
cfg.browse.enabled = Boolean(cfg.browse.enabled)
|
|
340
343
|
cfg.browse.voices = cfg.browse.voices !== false
|
|
341
344
|
cfg.browse.keywords = dedupe(cfg.browse.keywords)
|
|
342
|
-
|
|
345
|
+
// 上网时段(issue #86 第 2 条):null = 跟着醒来时段走(默认就是跟随)。
|
|
346
|
+
// 存了一个坏值时也退成跟随——退到「自己的默认」会让她在睡着时被安排出门。
|
|
347
|
+
cfg.browse.window = cfg.browse.window == null
|
|
348
|
+
? null
|
|
349
|
+
: validWindow(cfg.browse.window, cfg.window)
|
|
350
|
+
// 和醒来时段一模一样等于跟随:只存一份,改了醒来时段它也会跟着动。
|
|
351
|
+
if (Array.isArray(cfg.browse.window)
|
|
352
|
+
&& cfg.browse.window[0] === cfg.window[0] && cfg.browse.window[1] === cfg.window[1]) {
|
|
353
|
+
cfg.browse.window = null
|
|
354
|
+
}
|
|
343
355
|
|
|
344
356
|
// 请求节奏:夹值已由 LIMITS 做过,这里只保证是对象(老配置里没有这一组)
|
|
345
357
|
cfg.bili = { ...DEFAULTS.bili, ...cfg.bili }
|
package/lib/speak.js
CHANGED
|
@@ -105,8 +105,10 @@ function softReason(why) {
|
|
|
105
105
|
*
|
|
106
106
|
* 为什么要用 getter:`ctx.tools.register` 只在启动时跑一次,而配置随时能改。
|
|
107
107
|
* 存一份「最近一次看到的状态」,宿主每轮序列化工具表时会再取一次 description,
|
|
108
|
-
*
|
|
109
|
-
*
|
|
108
|
+
* 于是开关一翻,下一轮就跟着变。同步这份状态的有三处:启动注册时(index.js)、
|
|
109
|
+
* 设置页保存配置时(observe.js 的 POST /config,和身份文档同一刻重写)、她每次调用时
|
|
110
|
+
* (`execute` 里本来就要读配置)。不经设置页、直接改 config.json 的,要等她下一次调用
|
|
111
|
+
* 或重启才跟上。
|
|
110
112
|
*/
|
|
111
113
|
let speakEnabled = false
|
|
112
114
|
|
|
@@ -115,6 +117,15 @@ export function noteSpeakEnabled(on) {
|
|
|
115
117
|
speakEnabled = on === true
|
|
116
118
|
}
|
|
117
119
|
|
|
120
|
+
/**
|
|
121
|
+
* 说明该写哪一版:能上 B 站、又允许说话,两个都开才算开(issue #62)。
|
|
122
|
+
* 和身份文档「在网上说话」那一节(selfdoc.js 的 speak)同一个判据;
|
|
123
|
+
* 只看 comment.enabled 的话,断网时说明写「可以留评论」,身份文档却写「这会儿还说不出去」。
|
|
124
|
+
*/
|
|
125
|
+
export function speakOn(config) {
|
|
126
|
+
return biliOn(config) && config?.comment?.enabled === true
|
|
127
|
+
}
|
|
128
|
+
|
|
118
129
|
/** 关着时的那一段必须**不含**任何"能发出去"的暗示,也不解释原因。 */
|
|
119
130
|
function speakDescription(on) {
|
|
120
131
|
if (!on) {
|
|
@@ -122,6 +133,9 @@ function speakDescription(on) {
|
|
|
122
133
|
}
|
|
123
134
|
return (
|
|
124
135
|
'在 B 站说一句话。可以给你今天看过的某个视频留一条评论,或者回一句别人留在你评论下面的话。' +
|
|
136
|
+
// 2026-11-09(0.9.6 S7,设计 §8.7 g1):评论区是鱼八股的高发地。
|
|
137
|
+
// 不写「你可以说:……」(那只是换一套模板),只要求**句子挂在这条视频的具体地方上**。
|
|
138
|
+
'评论要挂在这条视频的具体地方上——哪一句话、哪个画面、哪个数字。换一条视频也说得通的话,就别发。' +
|
|
125
139
|
'这是会留下来的东西——别人看得见,你也删不掉别人已经看到的。' +
|
|
126
140
|
'不想说就不说,没有人等着你回答。'
|
|
127
141
|
)
|
|
@@ -174,10 +188,13 @@ export function registerSpeak(ctx, deps = {}) {
|
|
|
174
188
|
if (!who.ok) return { ok: false, said: '', note: who.note }
|
|
175
189
|
const { config } = await loadConfig(root)
|
|
176
190
|
// 顺手同步一次:启动之后才被改的开关,靠这里让下一轮的 description 跟上。
|
|
177
|
-
noteSpeakEnabled(config
|
|
191
|
+
noteSpeakEnabled(speakOn(config))
|
|
178
192
|
// issue #62:断网要断干净。以前只认 comment.enabled,bili.enabled=false 时
|
|
179
193
|
// 照样能发评论、照样联网。两个开关是「与」:先看能不能上 B 站,再看让不让说话。
|
|
180
|
-
|
|
194
|
+
// 2026-11-09(用户 m00861):断网也按「这会儿不行」的说法,不出现「现在」这类
|
|
195
|
+
// 像在宣布环境状态的措辞,和 softReason 的口径一致——她听到的是这一刻不方便,
|
|
196
|
+
// 不是「网断了」这件事本身。
|
|
197
|
+
if (!biliOn(config)) return { ok: false, said: '', note: '这会儿不方便说。' }
|
|
181
198
|
if (config?.comment?.enabled !== true) return { ok: false, said: '', note: softReason('没开这个权限') }
|
|
182
199
|
return speakOnce({
|
|
183
200
|
kind: args?.kind,
|
package/lib/store.js
CHANGED
|
@@ -372,6 +372,22 @@ export async function pruneDiary(keepDays, todayKey, root = rootDir()) {
|
|
|
372
372
|
return removed
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
/**
|
|
376
|
+
* 写过日记的日期(新→旧):diary/ 里现存的文件,并上事件流里每篇写下时留的 `diary:<日期>` 记录。
|
|
377
|
+
*
|
|
378
|
+
* 「日记留多久」只删文件、不动事件流(issue #67),所以被清掉的那些也还算写过;同一天写两次只算一篇。
|
|
379
|
+
* 身份文档的「写过几篇」、her_diary 的「一共写过几篇」、记忆页的篇数都用这一个口径,别各数各的。
|
|
380
|
+
* 纯函数。files 传 listDiary 的结果;它不是数组(读不到目录)时原样返回,调用方自己当「不知道」。
|
|
381
|
+
*/
|
|
382
|
+
export function diaryDatesWritten(files, events = []) {
|
|
383
|
+
if (!Array.isArray(files)) return files
|
|
384
|
+
const meta = (Array.isArray(events) ? events : [])
|
|
385
|
+
.filter((e) => e?.type === 'meta')
|
|
386
|
+
.map((e) => /^diary:(\d{4}-\d{2}-\d{2})/.exec(String(e.text ?? ''))?.[1])
|
|
387
|
+
.filter(Boolean)
|
|
388
|
+
return [...new Set([...files, ...meta])].sort().reverse()
|
|
389
|
+
}
|
|
390
|
+
|
|
375
391
|
/** 列出已有的日记日期(新→旧) */
|
|
376
392
|
export async function listDiary(root = rootDir()) {
|
|
377
393
|
try {
|
package/lib/tenant.js
CHANGED
|
@@ -258,6 +258,39 @@ export function checkCaller(root, exec, { herDir = '', tool = 'growth_commit', o
|
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
/**
|
|
262
|
+
* 「这一次调用是不是发生在这个家里」——只回答是/否。
|
|
263
|
+
*
|
|
264
|
+
* 与 `checkCaller` 同一套判据(放行系统侧、没有 cwd 的会话、root 内、当前出门/请神那条会话),
|
|
265
|
+
* 但不写日志、不给拒绝话术:它给的是**记账这类旁路**用的。
|
|
266
|
+
*
|
|
267
|
+
* 2026-11-09 外部用户报告:别的会话(default-workspace)顺手点了一下 `her_note`,
|
|
268
|
+
* 写入被 `checkCaller` 正确拒了,可 `lib/use.js` 的 `withUse` 不问来路照样记了一行
|
|
269
|
+
* `use:her_note fail …`——别人的误操作就这样进了她的成长账。
|
|
270
|
+
* 记不记与写不写是两件事:写由 `guardWrite` 拦,记由这里先问一句。
|
|
271
|
+
*/
|
|
272
|
+
export function callerInRoot(root, exec) {
|
|
273
|
+
const { sessionId, cwd } = callerOf(exec)
|
|
274
|
+
if (!sessionId && !cwd) return true
|
|
275
|
+
if (!cwd) return true
|
|
276
|
+
if (isInside(cwd, root)) return true
|
|
277
|
+
if (sessionId) {
|
|
278
|
+
try {
|
|
279
|
+
const active = activeOutingSync(root)
|
|
280
|
+
if (active && String(active.sessionId ?? '') === sessionId) return true
|
|
281
|
+
} catch {
|
|
282
|
+
/* 读不出门记录时按「不是她」算,宁可漏记一条,也不往她账上写别人的事 */
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
const possessed = activePossessionSync(root)
|
|
286
|
+
if (possessed && String(possessed.sessionId ?? '') === sessionId) return true
|
|
287
|
+
} catch {
|
|
288
|
+
/* 同上 */
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return false
|
|
292
|
+
}
|
|
293
|
+
|
|
261
294
|
/**
|
|
262
295
|
* 占一个家。一个 root 同时只允许一个活着的实例。
|
|
263
296
|
* @returns {Promise<{ok:boolean, instanceId:string, owner?:object, why?:string}>}
|
package/lib/turns.js
CHANGED
|
@@ -76,6 +76,62 @@ import { clearWakeSectionFor } from './identity.js'
|
|
|
76
76
|
*/
|
|
77
77
|
const PLUGIN_RPC = /^(wake|say|boot|report|letter|sleep|nudge|probe|turn|sys|carry|outing)[-_]/i
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* 桥登记来源(2026-11-09,issue #96)。
|
|
81
|
+
*
|
|
82
|
+
* 走宿主 `prompt()` 的桥没法把 `scene` 写进 `source`——`prompt()` 的 source 由
|
|
83
|
+
* 宿主填,桥只能定 requestId。于是群聊、群友私聊、桥自己发起的定时提醒全都
|
|
84
|
+
* 长成 `{ kind:'user', rpcId }`,被当成「他本人在说话」。
|
|
85
|
+
*
|
|
86
|
+
* 约定:桥在调 `prompt()` **之前**先发一条 `dsh-fish/source`:
|
|
87
|
+
* { rpcId, scene:'group'|'private'|'desk', owner:true, guest:true, machine:true }
|
|
88
|
+
*
|
|
89
|
+
* 这里按 rpcId 存一份短命表(5 分钟、最多 200 条),`classifyMessage` 先查它。
|
|
90
|
+
* 不发的桥保持老行为(带 rpcId 的当人),不倒退。
|
|
91
|
+
*/
|
|
92
|
+
const SOURCE_TTL_MS = 5 * 60_000
|
|
93
|
+
const SOURCE_MAX = 200
|
|
94
|
+
const declaredSources = new Map()
|
|
95
|
+
|
|
96
|
+
/** 记下一条 rpcId 的来历。同步、永不抛;返回是否记住了。 */
|
|
97
|
+
export function declareSource(o = {}) {
|
|
98
|
+
try {
|
|
99
|
+
const rpcId = String(o?.rpcId ?? '').trim()
|
|
100
|
+
if (!rpcId || rpcId.length > 200) return false
|
|
101
|
+
const now = Date.now()
|
|
102
|
+
for (const [k, v] of declaredSources) if (now - v.at > SOURCE_TTL_MS) declaredSources.delete(k)
|
|
103
|
+
const scene = normalizeScene(o?.scene)
|
|
104
|
+
declaredSources.set(rpcId, {
|
|
105
|
+
scene: scene === 'group' || scene === 'private' ? scene : '',
|
|
106
|
+
owner: o?.owner === true,
|
|
107
|
+
guest: o?.guest === true,
|
|
108
|
+
machine: o?.machine === true,
|
|
109
|
+
at: now,
|
|
110
|
+
})
|
|
111
|
+
if (declaredSources.size > SOURCE_MAX) {
|
|
112
|
+
declaredSources.delete(declaredSources.keys().next().value)
|
|
113
|
+
}
|
|
114
|
+
return true
|
|
115
|
+
} catch {
|
|
116
|
+
return false
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function declaredFor(rpcId) {
|
|
121
|
+
const hit = declaredSources.get(rpcId)
|
|
122
|
+
if (!hit) return null
|
|
123
|
+
if (Date.now() - hit.at > SOURCE_TTL_MS) {
|
|
124
|
+
declaredSources.delete(rpcId)
|
|
125
|
+
return null
|
|
126
|
+
}
|
|
127
|
+
return hit
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** 只给测试用:清空登记表。 */
|
|
131
|
+
export function clearDeclaredSources() {
|
|
132
|
+
declaredSources.clear()
|
|
133
|
+
}
|
|
134
|
+
|
|
79
135
|
/**
|
|
80
136
|
* 宿主/我们这边自己拼的、**确定不是人打的** source.kind。
|
|
81
137
|
*
|
|
@@ -199,11 +255,24 @@ export function classifyMessage(data) {
|
|
|
199
255
|
if (normalizeScene(src.scene) === 'group') {
|
|
200
256
|
return src.owner === true && src.guest !== true ? 'group-owner' : 'group'
|
|
201
257
|
}
|
|
258
|
+
// 外客不必非得写在群聊里:桥能写 source 时,{ scene:'private', guest:true }
|
|
259
|
+
// 也是群友私聊(2026-11-09,issue #96)。/say 一直认这个字段,这里对齐。
|
|
260
|
+
if (src.guest === true) return 'group'
|
|
202
261
|
// 宿主拼的上下文 / 定时消息 / 工具回灌 / 她自己说的话:都不是他
|
|
203
262
|
if (MACHINE_KINDS.has(kind) || kind.startsWith('plugin:')) return 'context'
|
|
204
263
|
if (MACHINE_FORMS.has(src.form)) return 'context'
|
|
205
264
|
const rid = String(src.rpcId ?? '')
|
|
206
265
|
if (rid && PLUGIN_RPC.test(rid)) return 'plugin'
|
|
266
|
+
// 桥登记过这条 requestId 的来历,就按它说的算(2026-11-09,issue #96)。
|
|
267
|
+
// 这一条必须排在「带 rpcId 就当人」前面:prompt() 送来的群聊和定时提醒
|
|
268
|
+
// 也只有 rpcId 能认,不查登记就全被算成他本人。
|
|
269
|
+
const decl = rid ? declaredFor(rid) : null
|
|
270
|
+
if (decl) {
|
|
271
|
+
if (decl.machine) return 'plugin'
|
|
272
|
+
if (decl.guest) return 'group'
|
|
273
|
+
if (decl.scene === 'group') return decl.owner ? 'group-owner' : 'group'
|
|
274
|
+
return 'human'
|
|
275
|
+
}
|
|
207
276
|
if (kind === 'user') {
|
|
208
277
|
// 客户端(桌面/网页侧栏)打的字一定带时区——宿主从浏览器那边取的。
|
|
209
278
|
// 桥走宿主 prompt 时不带时区,但每条都有 rpcId(宿主把 kind 写死成
|
|
@@ -553,6 +622,9 @@ export function registerTurns(ctx, deps = {}) {
|
|
|
553
622
|
await hearTurn(root, {
|
|
554
623
|
text: p.msgs.join('\n'),
|
|
555
624
|
turns,
|
|
625
|
+
// 记下的那句要带这条会话的 id(2026-11-08,用户 m01199):出门/请神算「这一趟多了什么」
|
|
626
|
+
// 时按会话过滤,没有 id 的条目会被当成这趟的东西。
|
|
627
|
+
sessionId: p.sessionId,
|
|
556
628
|
day,
|
|
557
629
|
stage: stageOf(day, Number(config?.growthDays ?? 30)),
|
|
558
630
|
config,
|
|
@@ -691,12 +763,19 @@ export function registerTurns(ctx, deps = {}) {
|
|
|
691
763
|
}
|
|
692
764
|
})
|
|
693
765
|
|
|
766
|
+
// 桥在调 prompt() 之前先报一句「这条是谁说的」(2026-11-09,issue #96)。
|
|
767
|
+
// 同步收下、不等不挡;不报的桥保持老行为。
|
|
768
|
+
const offSource = ctx.on?.('dsh-fish/source', (o) => {
|
|
769
|
+
declareSource(o)
|
|
770
|
+
})
|
|
771
|
+
|
|
694
772
|
return () => {
|
|
695
773
|
stopped = true
|
|
696
774
|
pending = null
|
|
697
775
|
TURNS_BOUND.delete(ctx)
|
|
698
776
|
try {
|
|
699
777
|
if (typeof off === 'function') off()
|
|
778
|
+
if (typeof offSource === 'function') offSource()
|
|
700
779
|
} catch {
|
|
701
780
|
/* ignore */
|
|
702
781
|
}
|
package/lib/use.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { appendEvent, readEvents } from './store.js'
|
|
19
19
|
import { similarity } from './derive.js'
|
|
20
20
|
import { noteRegisteredTool } from './toolreg.js'
|
|
21
|
+
import { callerInRoot } from './tenant.js'
|
|
21
22
|
|
|
22
23
|
/** 一句话的上限:她在回忆里看到的是一条,不是一段。 */
|
|
23
24
|
export const USE_LINE_MAX = 80
|
|
@@ -70,7 +71,9 @@ function oneLine(text, n = USE_LINE_MAX) {
|
|
|
70
71
|
*/
|
|
71
72
|
const SAYING = {
|
|
72
73
|
her_recall: (out) => (out?.found ? '翻到了。' : '没翻到。'),
|
|
73
|
-
|
|
74
|
+
// gone:那天写过、文件被「日记留多久」清掉了(herdiary.js)。记成「那天没有日记」,
|
|
75
|
+
// 她以后翻回忆会以为自己那天没写。
|
|
76
|
+
her_diary: (out) => (out?.found ? '翻到日记了。' : out?.gone ? '写过的日记已经清掉了,没翻到。' : '那天没有日记。'),
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
/**
|
|
@@ -146,21 +149,31 @@ export async function recordUse(root, { tool, out, sessionId, now = Date.now() }
|
|
|
146
149
|
export function withUse(def, { root, tool }) {
|
|
147
150
|
const run = def?.execute
|
|
148
151
|
if (typeof run !== 'function') return def
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
// 按属性描述符复制,不用 `{ ...def }`:展开会把 getter 当场求值成死值。
|
|
153
|
+
// bili_speak 的说明是 getter(随「能不能说话」现取),展开之后就定格在启动那一刻,
|
|
154
|
+
// 之后开关怎么翻,她读到的说明都不变(issue #62 后续)。
|
|
155
|
+
const props = Object.getOwnPropertyDescriptors(def)
|
|
156
|
+
delete props.execute
|
|
157
|
+
const wrapped = Object.create(Object.getPrototypeOf(def), props)
|
|
158
|
+
async function execute(args, exec) {
|
|
159
|
+
// 记录之前先问一句「这次调用是不是发生在这个家里」(2026-11-09 外部用户报告):
|
|
160
|
+
// 别的会话顺手点了一下,写入会被 guardWrite 拒掉,但记账这一层以前照记,
|
|
161
|
+
// 于是一次误操作也给她的成长账添了一行 use:… fail。记不记与写不写分开管:
|
|
162
|
+
// 出门 / 请神那条会话仍然算她(判据在 callerInRoot 里与 checkCaller 一致)。
|
|
163
|
+
const own = callerInRoot(root, exec)
|
|
164
|
+
try {
|
|
165
|
+
const out = await run(args, exec)
|
|
166
|
+
if (own) await recordUse(root, { tool, out, sessionId: exec?.sessionId })
|
|
167
|
+
return out
|
|
168
|
+
} catch (err) {
|
|
169
|
+
// 做到一半炸了也要留一笔:这是「尝试没完成」里最该被记住的一类。
|
|
170
|
+
// 不记异常原文——英文、内部词、堆栈都不该进她的账。
|
|
171
|
+
if (own) await recordUse(root, { tool, out: { ok: false, note: '这次没成。' }, sessionId: exec?.sessionId })
|
|
172
|
+
throw err
|
|
173
|
+
}
|
|
163
174
|
}
|
|
175
|
+
Object.defineProperty(wrapped, 'execute', { value: execute, configurable: true, enumerable: true, writable: true })
|
|
176
|
+
return wrapped
|
|
164
177
|
}
|
|
165
178
|
|
|
166
179
|
/**
|
package/lib/video.js
CHANGED
|
@@ -246,41 +246,70 @@ export function normalizeAt(at, duration = 0) {
|
|
|
246
246
|
return out.sort((x, y) => x - y)
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
/**
|
|
250
|
-
* 抽帧 + 拼图。
|
|
251
|
-
*
|
|
252
|
-
* @param {object} o
|
|
253
|
-
* @param {string} o.bvid
|
|
254
|
-
* @param {object} [o.client] 注入的 bili 客户端(单测用假的)
|
|
255
|
-
* @param {string} [o.root]
|
|
256
|
-
* @param {number} [o.frames] 取几帧(默认 9 = 3×3);只在没给 o.at 时用
|
|
257
|
-
* @param {number|number[]} [o.at] 她点名的时刻(秒);给了就只取这几个时刻
|
|
258
|
-
* @param {{ok:boolean,bin:string}} [o.ffmpeg] 注入的 ffmpeg 探测结果(单测用假的)
|
|
259
|
-
* @param {string} [o.caFile] 显式 CA 包路径;给了就同时开证书校验(-tls_verify 1),只在 http(s) 时生效
|
|
260
|
-
* @returns {Promise<{ok:boolean, path:string, why:string, title:string, up:string, view:number, duration:number, shots:number}>}
|
|
261
|
-
*/
|
|
262
249
|
/**
|
|
263
250
|
* 点名看一条视频之前该不该拦(issue #62)。
|
|
264
251
|
*
|
|
265
252
|
* 以前黑名单只在 `rankVideos` 里生效:列表被筛过,她点名打开的那条却谁都不查,
|
|
266
|
-
* 标题带屏蔽词、UP
|
|
267
|
-
* 这里用 view 已经取到的元信息判断,不额外发请求。
|
|
253
|
+
* 标题带屏蔽词、UP 在屏蔽名单的视频照样抽帧。
|
|
268
254
|
*
|
|
269
|
-
*
|
|
255
|
+
* `v` 按 `client.view()` 回来的形状读:toVideo 已经把 owner 摊平成顶层的 `up` / `mid`,
|
|
256
|
+
* 详情里也没有标签——标签由调用方另外取,放进 `v.tags`(字符串数组)。
|
|
257
|
+
* 0.9.5 曾按 B 站原始回包读 `owner.name` / `owner.mid` / `tags`,结果只有标题关键词拦得住。
|
|
258
|
+
*
|
|
259
|
+
* @param {{title?: string, up?: string, mid?: number|string, duration?: number, tags?: string[]}} v
|
|
270
260
|
* @param {object} cfg 整份配置(读 cfg.avoid)
|
|
271
261
|
* @param {number} [minDuration] 秒;0 / 不传 = 不查时长
|
|
272
|
-
* @returns {string} 空串 =
|
|
262
|
+
* @returns {{note: string, hit: string}} note 空串 = 放行,否则是一句话理由
|
|
263
|
+
* (给她看的,不带"屏蔽/黑名单"这种系统词);hit 写命中了哪一项(给日志看的)
|
|
273
264
|
*/
|
|
274
|
-
export function
|
|
275
|
-
const
|
|
276
|
-
|
|
265
|
+
export function watchBlockHit(v, cfg, minDuration = 0) {
|
|
266
|
+
const tags = Array.isArray(v?.tags) ? v.tags.map((t) => String(t ?? '')).filter(Boolean) : []
|
|
267
|
+
const hit = avoidHit(v, { avoid: cfg?.avoid }, tags)
|
|
268
|
+
if (hit) return { note: '这条我不想看。', hit: hitLabel(v, tags, hit) }
|
|
277
269
|
const min = Number(minDuration ?? 0)
|
|
278
270
|
const dur = Number(v?.duration ?? 0)
|
|
279
|
-
if (min > 0 && dur > 0 && dur < min) return '这条太短了,不想看。'
|
|
280
|
-
return ''
|
|
271
|
+
if (min > 0 && dur > 0 && dur < min) return { note: '这条太短了,不想看。', hit: `时长 ${dur} 秒,短于 ${min} 秒` }
|
|
272
|
+
return { note: '', hit: '' }
|
|
281
273
|
}
|
|
282
274
|
|
|
283
|
-
|
|
275
|
+
/** 同上,只要给她看的那句理由(空串 = 放行)。 */
|
|
276
|
+
export function watchBlocked(v, cfg, minDuration = 0) {
|
|
277
|
+
return watchBlockHit(v, cfg, minDuration).note
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** avoidHit 只回命中的那个词(或 `up:<mid>`);日志里要看得出是 UP、标题、UP 名还是标签。 */
|
|
281
|
+
function hitLabel(v, tags, hit) {
|
|
282
|
+
const mid = String(v?.mid ?? '')
|
|
283
|
+
if (mid && hit === `up:${mid}`) return `屏蔽的 UP ${mid}`
|
|
284
|
+
const where = String(v?.title ?? '').includes(hit) ? '标题'
|
|
285
|
+
: String(v?.up ?? '').includes(hit) ? 'UP 名'
|
|
286
|
+
: tags.some((t) => t.includes(hit)) ? '标签'
|
|
287
|
+
: ''
|
|
288
|
+
return `${where ? `${where}含` : '含'}屏蔽词「${hit}」`
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** 设了屏蔽关键词才值得为标签多发一次请求。 */
|
|
292
|
+
function hasKeywords(avoid) {
|
|
293
|
+
return (avoid?.keywords ?? []).some((k) => String(k ?? '') !== '')
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* 抽帧 + 拼图。
|
|
298
|
+
*
|
|
299
|
+
* @param {object} o
|
|
300
|
+
* @param {string} o.bvid
|
|
301
|
+
* @param {object} [o.client] 注入的 bili 客户端(单测用假的)
|
|
302
|
+
* @param {string} [o.root]
|
|
303
|
+
* @param {number} [o.frames] 取几帧(默认 9 = 3×3);只在没给 o.at 时用
|
|
304
|
+
* @param {number|number[]} [o.at] 她点名的时刻(秒);给了就只取这几个时刻
|
|
305
|
+
* @param {{ok:boolean,bin:string}} [o.ffmpeg] 注入的 ffmpeg 探测结果(单测用假的)
|
|
306
|
+
* @param {string} [o.caFile] 显式 CA 包路径;给了就同时开证书校验(-tls_verify 1),只在 http(s) 时生效
|
|
307
|
+
* @param {object} [o.avoid] 配置里的 avoid(屏蔽的 UP 与关键词)
|
|
308
|
+
* @returns {Promise<{ok:boolean, path:string, why:string, title:string, up:string, view:number, duration:number, shots:number, blocked?:string}>}
|
|
309
|
+
* blocked 只在命中屏蔽时有:写命中了哪一项(给日志看,不给她看)
|
|
310
|
+
*/
|
|
311
|
+
export async function grabFrames(o = {}) {
|
|
312
|
+
const root = o.root ?? rootDir()
|
|
284
313
|
const bvid = String(o.bvid ?? '').trim()
|
|
285
314
|
const fail = (why, extra = {}) => ({ ok: false, path: '', why, title: '', up: '', view: 0, duration: 0, shots: 0, times: [], ...extra })
|
|
286
315
|
|
|
@@ -303,22 +332,24 @@ export async function grabFrames(o = {}) { const root = o.root ?? rootDir()
|
|
|
303
332
|
}
|
|
304
333
|
if (!info?.ok) return fail(info?.message ?? '取不到这条视频的信息')
|
|
305
334
|
|
|
306
|
-
// issue #62
|
|
335
|
+
// issue #62:点名看的那条也要过屏蔽名单——屏蔽的 UP,标题 / UP 名 / 标签里的关键词。
|
|
307
336
|
// 放在取 cid / playurl 之前:被拦下时不该先把播放地址要来。
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
337
|
+
// 点名打开的那一条不查最短时长(`avoid.minDuration` 只管列表)。
|
|
338
|
+
const d = info.data ?? {}
|
|
339
|
+
const meta = { title: d.title, up: d.up, mid: d.mid, duration: Number(d.duration) || 0, tags: [] }
|
|
340
|
+
let block = watchBlockHit(meta, { avoid: o.avoid }, 0)
|
|
341
|
+
// 标签不在详情里,要另取一次:只在设了关键词、标题和 UP 又都没中时才取。
|
|
342
|
+
// 默认配置自带屏蔽词,所以点名看画面通常要多发这一次请求(排进同一个请求队列)。
|
|
343
|
+
// 取不到就只按标题与 UP 判,和列表那边(browse.js 的 absorb)一样;
|
|
344
|
+
// 但标签接口被风控(-412 这类)时,客户端整个读通道一起冷却,下面的 playurl 也会被拒。
|
|
345
|
+
if (!block.note && hasKeywords(o.avoid)) {
|
|
346
|
+
try {
|
|
347
|
+
const t = await client.tags(bvid)
|
|
348
|
+
if (t?.ok && Array.isArray(t.data)) meta.tags = t.data
|
|
349
|
+
} catch { /* 取不到标签只按标题与 UP 判 */ }
|
|
350
|
+
if (meta.tags.length) block = watchBlockHit(meta, { avoid: o.avoid }, 0)
|
|
351
|
+
}
|
|
352
|
+
if (block.note) return fail(block.note, { blocked: block.hit })
|
|
322
353
|
|
|
323
354
|
const cid = info.data?.cid
|
|
324
355
|
if (!cid) return fail('取不到分P信息(cid)')
|
package/lib/watch.js
CHANGED
|
@@ -113,11 +113,14 @@ export function registerWatch(ctx, deps = {}) {
|
|
|
113
113
|
root,
|
|
114
114
|
frames: config?.video?.frames,
|
|
115
115
|
at: args?.at,
|
|
116
|
-
// issue #62
|
|
116
|
+
// issue #62:点名看的那条也要过屏蔽名单(屏蔽的 UP,标题 / UP 名 / 标签里的关键词);
|
|
117
|
+
// 最短时长只管列表,这里不查。
|
|
117
118
|
avoid: config?.avoid,
|
|
118
119
|
})
|
|
119
120
|
if (!r.ok) {
|
|
120
|
-
|
|
121
|
+
// 命中屏蔽不是抽帧失败:单记一行,写清命中了哪一项。她听到的仍只是那句理由。
|
|
122
|
+
if (r.blocked) logLine('info', ['看画面:命中屏蔽,没取画面', bvid, r.blocked], root)
|
|
123
|
+
else logLine('warn', ['看画面:抽帧失败', bvid, r.why ?? ''], root)
|
|
121
124
|
return { ok: false, path: '', text: '', note: r.why }
|
|
122
125
|
}
|
|
123
126
|
|
package/lib/wish.js
CHANGED
|
@@ -68,6 +68,12 @@ export const WISH_LATER_DAYS = 30
|
|
|
68
68
|
/** 他答应了但还没到的摆几天。 */
|
|
69
69
|
export const WISH_APPROVE_DAYS = 14
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* subject 里认工具名的最短长度(issue #83)。
|
|
73
|
+
* 短名字(`her`、`bili`)在中文句子里太容易撞上,只认 4 个字以上的。
|
|
74
|
+
*/
|
|
75
|
+
const TOOL_NAME_MIN = 4
|
|
76
|
+
|
|
71
77
|
const DAY = 86_400_000
|
|
72
78
|
|
|
73
79
|
/** `askId` → 那条 `answer` 事件。 */
|
|
@@ -121,16 +127,48 @@ function toolInHand(has, name) {
|
|
|
121
127
|
}
|
|
122
128
|
|
|
123
129
|
/**
|
|
124
|
-
*
|
|
130
|
+
* subject 里点到的那个工具名;没有就返回空串(issue #83)。
|
|
131
|
+
*
|
|
132
|
+
* 0.9.5 只认「subject 正好等于工具名」。可真实数据里她常写成
|
|
133
|
+
* 「her_note 的读取:列出还没划掉的那些」——一句描述里带着工具名,
|
|
134
|
+
* 精确比对就永远对不上,卡照样摆满 14 天(issue #83 实测)。
|
|
135
|
+
*
|
|
136
|
+
* 这里再认一种:subject 里出现一个**完整的**工具名。三条边界:
|
|
137
|
+
* - 只认 TOOL_NAME_MIN 个字符以上的名字,短名在中文句子里太容易误撞;
|
|
138
|
+
* - 名字前后不能紧挨字母/数字/下划线(`her_note` 不该被 `her_notes` 命中);
|
|
139
|
+
* - 命中多个时取最长的那个(`bili_look` 与 `bili_look_at` 同时出现时以后者为准)。
|
|
140
|
+
* `has` 是函数时列不出名单,只能按整句比——猜不了就不猜,宁可多摆几天。
|
|
141
|
+
*/
|
|
142
|
+
function toolNamedIn(has, subject) {
|
|
143
|
+
if (!subject) return ''
|
|
144
|
+
if (toolInHand(has, subject)) return subject
|
|
145
|
+
if (!(has instanceof Set) && !Array.isArray(has)) return ''
|
|
146
|
+
const hay = subject.toLowerCase()
|
|
147
|
+
let hit = ''
|
|
148
|
+
for (const raw of has instanceof Set ? [...has] : has) {
|
|
149
|
+
const name = String(raw ?? '').trim().toLowerCase()
|
|
150
|
+
if (name.length < TOOL_NAME_MIN) continue
|
|
151
|
+
const at = hay.indexOf(name)
|
|
152
|
+
if (at < 0) continue
|
|
153
|
+
if (at > 0 && /[a-z0-9_]/.test(hay[at - 1])) continue
|
|
154
|
+
if (/[a-z0-9_]/.test(hay[at + name.length] ?? '')) continue
|
|
155
|
+
if (name.length > hit.length) hit = name
|
|
156
|
+
}
|
|
157
|
+
return hit
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 这张卡要的东西是不是已经在她手上了(issue #58 / #83)。
|
|
125
162
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
163
|
+
* 认两种写法:`subject` 正好是工具名,或 `subject` 里带着一个工具名
|
|
164
|
+
* (「某工具:做什么」)。剩下的(纯描述、没点名的)猜不准是不是同一样东西,
|
|
165
|
+
* 宁可多摆几天。查不了(`has` 没传/抛错)也照旧摆。
|
|
128
166
|
*/
|
|
129
167
|
export function toolArrived(e, has) {
|
|
130
168
|
if (String(e?.type ?? '') !== 'ask') return false
|
|
131
169
|
if (String(e?.ask?.kind ?? '') !== 'need-tool') return false
|
|
132
170
|
const subject = String(e?.ask?.subject ?? '').trim()
|
|
133
|
-
return
|
|
171
|
+
return Boolean(toolNamedIn(has, subject))
|
|
134
172
|
}
|
|
135
173
|
|
|
136
174
|
/** 她那句话怎么收尾——只陈述结局,不给建议。 */
|
|
@@ -171,9 +209,9 @@ export function wishesOf(events = [], { now = Date.now(), days = 0, has = null }
|
|
|
171
209
|
if (!raw) continue
|
|
172
210
|
const text = raw.length > WISH_TEXT_MAX ? `${raw.slice(0, WISH_TEXT_MAX - 1)}…` : raw
|
|
173
211
|
const subject = String(e?.ask?.subject ?? '').trim()
|
|
174
|
-
// 已经到手的不再摆(issue #58):卡上答「可以」不发权限,他只能在卡外给,
|
|
175
|
-
//
|
|
176
|
-
if (
|
|
212
|
+
// 已经到手的不再摆(issue #58 / #83):卡上答「可以」不发权限,他只能在卡外给,
|
|
213
|
+
// 事件流里没有这条记录,所以按她此刻的白名单对一遍——整句是工具名、或句子里带着工具名都算。
|
|
214
|
+
if (toolNamedIn(has, subject)) continue
|
|
177
215
|
// 同一件事反复问过(她开两张卡):只留最近的那一张,不摆两遍。
|
|
178
216
|
if (picked.some((p) => similarity(p.subject || p.text, subject || text) >= WISH_SIMILARITY)) continue
|
|
179
217
|
picked.push({ id: String(e.id ?? ''), text, subject, verdict, at, tail: wishTail(verdict) })
|