@ssamurias/dsh-fish 1.0.8 → 1.1.0
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 +368 -338
- package/CHANGELOG.md +113 -0
- package/README.md +377 -352
- package/RELEASE-NOTES-1.0.9.md +79 -0
- package/RELEASE-NOTES-1.1.0.md +55 -0
- package/docs//350/256/244/344/272/272/345/210/244/346/215/256.md +112 -0
- package/lib/appoint.js +106 -22
- package/lib/ask.js +2 -1
- package/lib/autobackup.js +4 -0
- package/lib/capture.js +16 -0
- package/lib/claim.js +103 -0
- package/lib/client/00-shell.js +630 -0
- package/lib/client/01-state-load.js +901 -0
- package/lib/client/02-actions.js +670 -0
- package/lib/client/03-widgets-header.js +721 -0
- package/lib/client/04-pressure-lab.js +891 -0
- package/lib/client/05-pressure-charts.js +431 -0
- package/lib/client/06-tab-status-grow.js +468 -0
- package/lib/client/07-tab-home-bili.js +610 -0
- package/lib/client/08-tab-memory-plugins.js +756 -0
- package/lib/client/09-tab-outing.js +710 -0
- package/lib/client/10-data-handlers.js +519 -0
- package/lib/client/11-tab-data-frame.js +749 -0
- package/lib/client/12-pressure-chip-mount.js +565 -0
- package/lib/client.js +477 -47
- package/lib/comment.js +18 -3
- package/lib/derive.js +262 -22
- package/lib/doing.js +31 -15
- package/lib/env.d.ts +224 -0
- package/lib/events.js +5 -2
- package/lib/guess.js +29 -0
- package/lib/health.js +75 -0
- package/lib/hear.js +67 -0
- package/lib/herpeople.js +159 -0
- package/lib/history.js +27 -5
- package/lib/home.js +12 -1
- package/lib/identity.js +23 -0
- package/lib/index.js +34 -18
- package/lib/look.js +3 -2
- package/lib/make.js +60 -12
- package/lib/markup.js +61 -23
- package/lib/observe-bili.js +334 -0
- package/lib/observe-config.js +223 -0
- package/lib/observe-data.js +522 -0
- package/lib/observe-home.js +384 -0
- package/lib/observe-http.js +250 -0
- package/lib/observe-outing.js +650 -0
- package/lib/observe-state.js +419 -0
- package/lib/observe-trip.js +286 -0
- package/lib/observe.js +99 -3574
- package/lib/people.js +514 -0
- package/lib/peopledoc.js +112 -0
- package/lib/persona.js +324 -42
- package/lib/restrict.js +74 -3
- package/lib/say.js +71 -1
- package/lib/scheduler.js +23 -3
- package/lib/schedules.js +97 -0
- package/lib/schema.js +11 -4
- package/lib/scrub.js +3 -3
- package/lib/selfdoc.js +19 -2
- package/lib/settings.js +112 -11
- package/lib/stance.js +47 -3
- package/lib/status.js +14 -5
- package/lib/sub.js +1 -1
- package/lib/tenant.js +35 -7
- package/lib/turns.js +51 -4
- package/lib/types.d.ts +515 -0
- package/lib/voices.js +3 -0
- package/lib/watch.js +1 -1
- package/lib/wiki.js +131 -25
- package/lib/works.js +120 -45
- package/package.json +1 -1
- package/scripts/build-client.mjs +83 -0
- package/scripts/sync-pressure-formulas.mjs +12 -15
package/lib/env.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* env.d.ts —— 零依赖环境下的 Node.js 内置模块与全局对象最小类型声明
|
|
3
|
+
*
|
|
4
|
+
* 铁律要求 `devDependencies` 保持 `{}`,不装 `@types/node`;
|
|
5
|
+
* 本文件提供插件实际用到的 `node:*` 内置模块与 `Buffer`/`process` 声明,
|
|
6
|
+
* 让本地 IDE 语言服务与 CI `npx tsc -p jsconfig.json --noEmit` 在零安装状态下直接通过。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
interface Buffer extends Uint8Array {
|
|
10
|
+
toString(encoding?: string, start?: number, end?: number): string
|
|
11
|
+
equals(other: Uint8Array): boolean
|
|
12
|
+
subarray(start?: number, end?: number): Buffer
|
|
13
|
+
slice(start?: number, end?: number): Buffer
|
|
14
|
+
write(str: string, offset?: number, length?: number, encoding?: string): number
|
|
15
|
+
copy(target: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare var Buffer: {
|
|
19
|
+
from(data: string, encoding?: string): Buffer
|
|
20
|
+
from(data: ArrayBuffer | ArrayLike<number> | Uint8Array): Buffer
|
|
21
|
+
alloc(size: number, fill?: number | string, encoding?: string): Buffer
|
|
22
|
+
allocUnsafe(size: number): Buffer
|
|
23
|
+
concat(list: ReadonlyArray<Uint8Array>, totalLength?: number): Buffer
|
|
24
|
+
isBuffer(obj: unknown): obj is Buffer
|
|
25
|
+
byteLength(str: string | Uint8Array, encoding?: string): number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare var process: {
|
|
29
|
+
env: Record<string, string | undefined>
|
|
30
|
+
argv: string[]
|
|
31
|
+
pid: number
|
|
32
|
+
ppid: number
|
|
33
|
+
platform: string
|
|
34
|
+
arch: string
|
|
35
|
+
version: string
|
|
36
|
+
execPath: string
|
|
37
|
+
cwd(): string
|
|
38
|
+
exit(code?: number): never
|
|
39
|
+
kill(pid: number, signal?: string | number): boolean
|
|
40
|
+
on(event: string, listener: (...args: any[]) => void): any
|
|
41
|
+
off(event: string, listener: (...args: any[]) => void): any
|
|
42
|
+
stdout: { write(chunk: string | Uint8Array): boolean }
|
|
43
|
+
stderr: { write(chunk: string | Uint8Array): boolean }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare module 'node:fs' {
|
|
47
|
+
const fs: {
|
|
48
|
+
existsSync(p: string): boolean
|
|
49
|
+
readFileSync(p: string): Buffer
|
|
50
|
+
readFileSync(p: string, encoding: string): string
|
|
51
|
+
writeFileSync(p: string, data: string | Uint8Array, options?: any): void
|
|
52
|
+
appendFileSync(p: string, data: string | Uint8Array, options?: any): void
|
|
53
|
+
mkdirSync(p: string, options?: any): string | undefined
|
|
54
|
+
readdirSync(p: string, options?: any): any[]
|
|
55
|
+
statSync(p: string, options?: any): any
|
|
56
|
+
lstatSync(p: string, options?: any): any
|
|
57
|
+
realpathSync(p: string, options?: any): string
|
|
58
|
+
renameSync(oldPath: string, newPath: string): void
|
|
59
|
+
unlinkSync(p: string): void
|
|
60
|
+
rmSync(p: string, options?: any): void
|
|
61
|
+
chmodSync(p: string, mode: number | string): void
|
|
62
|
+
copyFileSync(src: string, dest: string, mode?: number): void
|
|
63
|
+
openSync(p: string, flags: string | number, mode?: number): number
|
|
64
|
+
closeSync(fd: number): void
|
|
65
|
+
fsyncSync(fd: number): void
|
|
66
|
+
readSync(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null): number
|
|
67
|
+
writeSync(fd: number, buffer: Uint8Array | string, offset?: number, length?: number, position?: number | null): number
|
|
68
|
+
createReadStream(p: string, options?: any): any
|
|
69
|
+
createWriteStream(p: string, options?: any): any
|
|
70
|
+
promises: typeof import('node:fs/promises')
|
|
71
|
+
}
|
|
72
|
+
export const existsSync: typeof fs.existsSync
|
|
73
|
+
export const readFileSync: typeof fs.readFileSync
|
|
74
|
+
export const writeFileSync: typeof fs.writeFileSync
|
|
75
|
+
export const appendFileSync: typeof fs.appendFileSync
|
|
76
|
+
export const mkdirSync: typeof fs.mkdirSync
|
|
77
|
+
export const readdirSync: typeof fs.readdirSync
|
|
78
|
+
export const statSync: typeof fs.statSync
|
|
79
|
+
export const lstatSync: typeof fs.lstatSync
|
|
80
|
+
export const realpathSync: typeof fs.realpathSync
|
|
81
|
+
export const renameSync: typeof fs.renameSync
|
|
82
|
+
export const unlinkSync: typeof fs.unlinkSync
|
|
83
|
+
export const rmSync: typeof fs.rmSync
|
|
84
|
+
export const chmodSync: typeof fs.chmodSync
|
|
85
|
+
export const copyFileSync: typeof fs.copyFileSync
|
|
86
|
+
export const openSync: typeof fs.openSync
|
|
87
|
+
export const closeSync: typeof fs.closeSync
|
|
88
|
+
export const fsyncSync: typeof fs.fsyncSync
|
|
89
|
+
export const readSync: typeof fs.readSync
|
|
90
|
+
export const writeSync: typeof fs.writeSync
|
|
91
|
+
export const createReadStream: typeof fs.createReadStream
|
|
92
|
+
export const createWriteStream: typeof fs.createWriteStream
|
|
93
|
+
export const promises: typeof fs.promises
|
|
94
|
+
export default fs
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
declare module 'node:fs/promises' {
|
|
98
|
+
export function readFile(p: string): Promise<Buffer>
|
|
99
|
+
export function readFile(p: string, encoding: string): Promise<string>
|
|
100
|
+
export function writeFile(p: string, data: string | Uint8Array, options?: any): Promise<void>
|
|
101
|
+
export function appendFile(p: string, data: string | Uint8Array, options?: any): Promise<void>
|
|
102
|
+
export function mkdir(p: string, options?: any): Promise<string | undefined>
|
|
103
|
+
export function readdir(p: string, options?: any): Promise<any[]>
|
|
104
|
+
export function stat(p: string, options?: any): Promise<any>
|
|
105
|
+
export function lstat(p: string, options?: any): Promise<any>
|
|
106
|
+
export function realpath(p: string, options?: any): Promise<string>
|
|
107
|
+
export function rename(oldPath: string, newPath: string): Promise<void>
|
|
108
|
+
export function unlink(p: string): Promise<void>
|
|
109
|
+
export function rm(p: string, options?: any): Promise<void>
|
|
110
|
+
export function chmod(p: string, mode: number | string): Promise<void>
|
|
111
|
+
export function copyFile(src: string, dest: string, mode?: number): Promise<void>
|
|
112
|
+
export function mkdtemp(prefix: string, options?: any): Promise<string>
|
|
113
|
+
export function open(p: string, flags?: string | number, mode?: number): Promise<any>
|
|
114
|
+
const fsp: Record<string, any>
|
|
115
|
+
export default fsp
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
declare module 'node:path' {
|
|
119
|
+
const path: {
|
|
120
|
+
join(...paths: string[]): string
|
|
121
|
+
resolve(...paths: string[]): string
|
|
122
|
+
dirname(p: string): string
|
|
123
|
+
basename(p: string, ext?: string): string
|
|
124
|
+
extname(p: string): string
|
|
125
|
+
relative(from: string, to: string): string
|
|
126
|
+
normalize(p: string): string
|
|
127
|
+
isAbsolute(p: string): boolean
|
|
128
|
+
parse(p: string): { root: string; dir: string; base: string; ext: string; name: string }
|
|
129
|
+
sep: string
|
|
130
|
+
delimiter: string
|
|
131
|
+
posix: any
|
|
132
|
+
win32: any
|
|
133
|
+
}
|
|
134
|
+
export const join: typeof path.join
|
|
135
|
+
export const resolve: typeof path.resolve
|
|
136
|
+
export const dirname: typeof path.dirname
|
|
137
|
+
export const basename: typeof path.basename
|
|
138
|
+
export const extname: typeof path.extname
|
|
139
|
+
export const relative: typeof path.relative
|
|
140
|
+
export const normalize: typeof path.normalize
|
|
141
|
+
export const isAbsolute: typeof path.isAbsolute
|
|
142
|
+
export const parse: typeof path.parse
|
|
143
|
+
export const sep: string
|
|
144
|
+
export const delimiter: string
|
|
145
|
+
export const posix: any
|
|
146
|
+
export const win32: any
|
|
147
|
+
export default path
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
declare module 'node:os' {
|
|
151
|
+
export function homedir(): string
|
|
152
|
+
export function tmpdir(): string
|
|
153
|
+
export function platform(): string
|
|
154
|
+
export function hostname(): string
|
|
155
|
+
export function cpus(): any[]
|
|
156
|
+
export const EOL: string
|
|
157
|
+
const os: Record<string, any>
|
|
158
|
+
export default os
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
declare module 'node:url' {
|
|
162
|
+
export function fileURLToPath(url: string | URL): string
|
|
163
|
+
export function pathToFileURL(p: string): URL
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
declare module 'node:child_process' {
|
|
167
|
+
export function spawn(command: string, args?: readonly string[], options?: any): any
|
|
168
|
+
export function spawnSync(command: string, args?: readonly string[], options?: any): any
|
|
169
|
+
export function execFile(file: string, args?: readonly string[] | any, options?: any, callback?: any): any
|
|
170
|
+
export function execFileSync(file: string, args?: readonly string[], options?: any): any
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare module 'node:crypto' {
|
|
174
|
+
export function createHash(algorithm: string): any
|
|
175
|
+
export function createHmac(algorithm: string, key: string | Uint8Array): any
|
|
176
|
+
export function randomBytes(size: number): Buffer
|
|
177
|
+
export function randomUUID(): string
|
|
178
|
+
export function scryptSync(password: string | Uint8Array, salt: string | Uint8Array, keylen: number, options?: any): Buffer
|
|
179
|
+
export function createCipheriv(algorithm: string, key: Uint8Array, iv: Uint8Array, options?: any): any
|
|
180
|
+
export function createDecipheriv(algorithm: string, key: Uint8Array, iv: Uint8Array, options?: any): any
|
|
181
|
+
export function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean
|
|
182
|
+
const crypto: Record<string, any>
|
|
183
|
+
export default crypto
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
declare module 'node:zlib' {
|
|
187
|
+
export function gzipSync(buf: string | Uint8Array, options?: any): Buffer
|
|
188
|
+
export function gunzipSync(buf: Uint8Array, options?: any): Buffer
|
|
189
|
+
export function inflateRawSync(buf: Uint8Array, options?: any): Buffer
|
|
190
|
+
export function deflateRawSync(buf: string | Uint8Array, options?: any): Buffer
|
|
191
|
+
const zlib: Record<string, any>
|
|
192
|
+
export default zlib
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
declare module 'node:http' {
|
|
196
|
+
export function createServer(requestListener?: (req: any, res: any) => void): any
|
|
197
|
+
export function request(url: string | URL | any, options?: any, callback?: any): any
|
|
198
|
+
const http: Record<string, any>
|
|
199
|
+
export default http
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
declare module 'node:https' {
|
|
203
|
+
export function request(url: string | URL | any, options?: any, callback?: any): any
|
|
204
|
+
const https: Record<string, any>
|
|
205
|
+
export default https
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
declare module 'node:net' {
|
|
209
|
+
export function createConnection(options: any, connectListener?: () => void): any
|
|
210
|
+
export function createServer(connectionListener?: (socket: any) => void): any
|
|
211
|
+
export function isIP(input: string): number
|
|
212
|
+
const net: Record<string, any>
|
|
213
|
+
export default net
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
declare module 'node:tls' {
|
|
217
|
+
export function connect(options: any, secureConnectListener?: () => void): any
|
|
218
|
+
const tls: Record<string, any>
|
|
219
|
+
export default tls
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
declare module 'node:timers/promises' {
|
|
223
|
+
export function setTimeout<T = void>(delay?: number, value?: T, options?: any): Promise<T>
|
|
224
|
+
}
|
package/lib/events.js
CHANGED
|
@@ -437,9 +437,12 @@ export const CATALOG = [
|
|
|
437
437
|
{
|
|
438
438
|
id: 'tension_resolve', stage: 3, asks: false, once: true, gate: 'competence',
|
|
439
439
|
topic: ['对不上', '更信'],
|
|
440
|
-
|
|
440
|
+
// 2026-11-24:只拿 solid 的一对去问她「哪一点上不能同时成立」。
|
|
441
|
+
// suspect(字面撞词、没共同对象)不适合当这张卡的题目——那等于逼她给一件
|
|
442
|
+
// 可能不存在的事编一个理由。
|
|
443
|
+
cond: (m) => (m.tensions ?? []).some((t) => t?.severity !== 'suspect'),
|
|
441
444
|
prompt: (m) => {
|
|
442
|
-
const t = m.tensions[0]
|
|
445
|
+
const t = (m.tensions ?? []).find((x) => x?.severity !== 'suspect') ?? m.tensions[0]
|
|
443
446
|
const a = String(t?.a?.text ?? '').slice(0, 60)
|
|
444
447
|
const b = String(t?.b?.text ?? '').slice(0, 60)
|
|
445
448
|
return `你信的两句话对不上:「${a}」和「${b}」。先说清它们在哪一点上不能同时成立,再说你更信哪一句;另一句怎么改,给个新说法。`
|
package/lib/guess.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* guess.js —— 「这句是猜的,还是不是」(S0.6,用户 m01020 / m01298)
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一个文件:`lib/people.js` 也要用它(判断摆到某个人名下时要知道
|
|
5
|
+
* 该写「你猜过」还是「你有一句准话」),而 `lib/derive.js` 要 import people.js。
|
|
6
|
+
* 放在 derive 里就成了循环依赖,所以把这两条正则挪出来,derive 照旧 re-export。
|
|
7
|
+
*
|
|
8
|
+
* 为什么只分两类:`lib/stance.js` 的 `classifyStance` 敢用两条正则判「喜欢 / 拒绝」,
|
|
9
|
+
* 是因为那两个类别边界硬。「观察」和「看法」的边界软得多——「他总在半夜回话」
|
|
10
|
+
* 既是看到的,也是她的看法;硬分必错,而分类一错,摆出来的标题就是错的,比不分更糟。
|
|
11
|
+
* 「猜的」边界硬:推测词就那么几个。
|
|
12
|
+
*
|
|
13
|
+
* 分类在宿主侧(`lib/schema.js` 堵死了她自己打标:`anchored` 只认宿主写,
|
|
14
|
+
* 「让她自己打标,等于让她决定『我哪句话算数』」)。所以不新增任何参数,
|
|
15
|
+
* 只从她写下的正文里读,**只改摆法,不改她的任何数据**。
|
|
16
|
+
*
|
|
17
|
+
* 已知边界:漏判(她写「兴许」「说不准」以外的说法)只会少一个「猜」字,不会写坏数据;
|
|
18
|
+
* 误判(「不可能」里带「可能」)用 NOT_GUESS 挡一道。宁可漏,不可错标签。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const GUESS_WORDS = /(可能|大概|也许|好像|像是|估计|应该是|说不定|我猜|我怀疑|感觉上|兴许|说不准)/
|
|
22
|
+
const NOT_GUESS = /(不可能|没可能|不太可能)/
|
|
23
|
+
|
|
24
|
+
export function isGuess(text = '') {
|
|
25
|
+
const s = String(text ?? '')
|
|
26
|
+
if (!s) return false
|
|
27
|
+
if (NOT_GUESS.test(s)) return false
|
|
28
|
+
return GUESS_WORDS.test(s)
|
|
29
|
+
}
|
package/lib/health.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import { deriveSelf } from './derive.js'
|
|
16
16
|
import { parseGuardLine } from './guardlog.js'
|
|
17
|
+
import { BELIEF_SHOWN } from './persona.js'
|
|
17
18
|
|
|
18
19
|
const DAY_MS = 86_400_000
|
|
19
20
|
|
|
@@ -167,6 +168,67 @@ function dedupeByText(rows) {
|
|
|
167
168
|
return out
|
|
168
169
|
}
|
|
169
170
|
|
|
171
|
+
/**
|
|
172
|
+
* 认识人这几个数(1.0.9)。只数事件流里已经有的东西,不推断、不评价。
|
|
173
|
+
*
|
|
174
|
+
* 这个版本第一次往事件里写「这句话是谁说的」(`who`),也第一次写群聊里的
|
|
175
|
+
* `voice`。这几个数只回答一个问题:那条链路今天有没有真在跑。
|
|
176
|
+
*
|
|
177
|
+
* - ownerJudged:写在你名下的判断有几条(S0 起,屋子里她说的话都带 `who.id = 'owner'`)
|
|
178
|
+
* - met:除你之外,事件里出现过、带稳定 id 的人有几个(昵称会改,所以认 id)
|
|
179
|
+
* - judged:其中她真写过判断的有几个(`utterance` / `revise` 带 `who`)
|
|
180
|
+
* - herWords:群房与外客那两路,她的话留了几条(S2-a)
|
|
181
|
+
* - othersWords:群聊里别人的话留了几条(S2-b)
|
|
182
|
+
* - drifts / unsettled:说法变过几处、一直没定几处
|
|
183
|
+
*
|
|
184
|
+
* 一个数都没有时,`people` 不进返回值——界面上不排一排零当装饰。
|
|
185
|
+
*/
|
|
186
|
+
function peopleStats(list, model) {
|
|
187
|
+
const met = new Set()
|
|
188
|
+
const judged = new Set()
|
|
189
|
+
let ownerJudged = 0
|
|
190
|
+
let herWords = 0
|
|
191
|
+
let othersWords = 0
|
|
192
|
+
for (const ev of list) {
|
|
193
|
+
const type = String(ev?.type ?? '')
|
|
194
|
+
// 1.1.0 审计(2026-11-24):桥只给名字时 who.id 是空的,人靠名字建(people.js 的 name: 键)。
|
|
195
|
+
// 从前这里只看 id,于是 her_people 里认得的人,体检里一个都不算——两个数对不上。
|
|
196
|
+
const id = String(ev?.who?.id ?? '') || (String(ev?.who?.name ?? '').trim() ? `name:${String(ev.who.name).trim()}` : '')
|
|
197
|
+
if (type === 'utterance' && ev?.scene === 'group') herWords += 1
|
|
198
|
+
if (type === 'voice' && ev?.scene === 'group') othersWords += 1
|
|
199
|
+
if (!id) continue
|
|
200
|
+
const isJudge = type === 'utterance' || type === 'revise'
|
|
201
|
+
if (id === 'owner') {
|
|
202
|
+
if (isJudge) ownerJudged += 1
|
|
203
|
+
continue
|
|
204
|
+
}
|
|
205
|
+
met.add(id)
|
|
206
|
+
if (isJudge) judged.add(id)
|
|
207
|
+
}
|
|
208
|
+
// 2026-11-24 审计:她关于{T}的判断多数**不带 `who`**——按 S0.5 的教法靠 `topic`
|
|
209
|
+
// 写称呼挂到人身上,上面那句 `if (!id) continue` 就把它跳过了,于是身份段里明明
|
|
210
|
+
// 摆着「你对{T}有过一句准话」,体检却说 0 条。这里以 `peopleOf` 挂好的结果为准
|
|
211
|
+
// (它和身份段同一个派生),事件数只作兜底。
|
|
212
|
+
const ownerRow = Array.isArray(model?.people) ? model.people.find((p) => p.id === 'owner') : null
|
|
213
|
+
const ownerTotal = Number(ownerRow?.judged)
|
|
214
|
+
if (Number.isFinite(ownerTotal)) ownerJudged = Math.max(ownerJudged, ownerTotal)
|
|
215
|
+
return {
|
|
216
|
+
met: met.size,
|
|
217
|
+
judged: judged.size,
|
|
218
|
+
ownerJudged,
|
|
219
|
+
herWords,
|
|
220
|
+
othersWords,
|
|
221
|
+
drifts: Array.isArray(model?.drifts) ? model.drifts.length : 0,
|
|
222
|
+
unsettled: Array.isArray(model?.unsettled) ? model.unsettled.length : 0,
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** 一个数都没有时整段不摆。 */
|
|
227
|
+
function peopleEmpty(p) {
|
|
228
|
+
if (!p) return true
|
|
229
|
+
return !(p.met + p.judged + p.ownerJudged + p.herWords + p.othersWords + p.drifts + p.unsettled)
|
|
230
|
+
}
|
|
231
|
+
|
|
170
232
|
/**
|
|
171
233
|
* @param {Array} events 事件流(只读)
|
|
172
234
|
* @param {{now?:number, growthDays?:number, staleDays?:number}} opts
|
|
@@ -207,6 +269,13 @@ export function examine(events = [], { now = Date.now(), growthDays = 30, staleD
|
|
|
207
269
|
const model = deriveSelf(list, { growthDays })
|
|
208
270
|
const ranked = Array.isArray(model?.ranked) ? model.ranked : []
|
|
209
271
|
|
|
272
|
+
// 1.1.0 收尾(用户 m04951):判断被分给「人」之后,「你自己说过的话」那一段只剩关于世界的。
|
|
273
|
+
// 那一段最多摆几条由 persona 定(BELIEF_SHOWN),这里只把两边的实际条数摆出来,
|
|
274
|
+
// 让人一眼看出「人判断有没有把世界判断挤没」——这是唯一一处改完没实测过的副作用。
|
|
275
|
+
const personBeliefs = ranked.filter((b) => String(b?.who?.id ?? '') !== '').length
|
|
276
|
+
const worldBeliefs = Math.max(0, ranked.length - personBeliefs)
|
|
277
|
+
const beliefView = { person: personBeliefs, world: worldBeliefs, shown: Math.min(worldBeliefs, BELIEF_SHOWN), max: BELIEF_SHOWN }
|
|
278
|
+
|
|
210
279
|
// 同一对判断可能被正反各报一次(detectTensions 两个方向都会看)——按无序对去重,别让一对占两行。
|
|
211
280
|
const seenPairs = new Set()
|
|
212
281
|
const tensions = (Array.isArray(model?.tensions) ? model.tensions : [])
|
|
@@ -258,6 +327,8 @@ export function examine(events = [], { now = Date.now(), growthDays = 30, staleD
|
|
|
258
327
|
.sort((a, b) => b.days - a.days))
|
|
259
328
|
.slice(0, HEALTH_LIST)
|
|
260
329
|
|
|
330
|
+
const people = peopleStats(list, model)
|
|
331
|
+
|
|
261
332
|
return {
|
|
262
333
|
ok: true,
|
|
263
334
|
// 连一条判断都还没形成时,别说「一切正常」——说还太早。
|
|
@@ -283,5 +354,9 @@ export function examine(events = [], { now = Date.now(), growthDays = 30, staleD
|
|
|
283
354
|
stock: stockStats(list, weekFrom),
|
|
284
355
|
// 0.9.9 收尾(用户 m03900):说话有没有落到具体东西上。同样只报数。
|
|
285
356
|
speech: speechStats(list, weekFrom),
|
|
357
|
+
// 1.0.9:认识人那几个数。一个都没有时整段不出现在返回值里。
|
|
358
|
+
// 1.1.0 收尾:一条判断都没有时不给这几个数,界面不摆零。
|
|
359
|
+
...(ranked.length ? { beliefView } : {}),
|
|
360
|
+
...(peopleEmpty(people) ? {} : { people }),
|
|
286
361
|
}
|
|
287
362
|
}
|
package/lib/hear.js
CHANGED
|
@@ -208,6 +208,73 @@ export async function rememberGroupWord(root, o = {}) {
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/**
|
|
212
|
+
* 群里别人说的那一句(认识人 S2-b,2026-11-23,用户 m03903)。
|
|
213
|
+
*
|
|
214
|
+
* 为什么不并进 rememberGroupWord:那边写的是 `heard`——**他**说的。
|
|
215
|
+
* `heard` 会进「他说过的话」、进冲突检测;别人的话混进 heard,她就再也分不清
|
|
216
|
+
* 哪句是他说的。所以这条写 `voice`(别人的说法),跟她读到的评论同一个类型,
|
|
217
|
+
* 永远进不了判断(`lib/derive.js` 只把 `utterance` 收成信念)。
|
|
218
|
+
*
|
|
219
|
+
* 三条硬边界:
|
|
220
|
+
* 1. **默认关。** `people.others.rememberOthers` 关着时一条不落,和以前一模一样。
|
|
221
|
+
* 2. **不知道是谁就不记。** 桥没报 speakerId / speakerName 时,记下来只是
|
|
222
|
+
* 「不知道谁说了句话」:挂不到人身上,还占掉别人那一条的位置。
|
|
223
|
+
* events.jsonl 只能追加,写错了删不掉——宁可这条不记。
|
|
224
|
+
* 3. **量闸是硬的**:一天 5 条、一条 160 字、同一个人一天 1 条。超了就丢,不补不排队。
|
|
225
|
+
*
|
|
226
|
+
* 永不抛:记账失败只 log,不能连累对话。
|
|
227
|
+
*/
|
|
228
|
+
export async function rememberGroupMemberWord(root, o = {}) {
|
|
229
|
+
const log = o.log ?? (() => {})
|
|
230
|
+
try {
|
|
231
|
+
let config = o.config
|
|
232
|
+
if (config === undefined) config = await loadConfig(root).then((r) => r?.config).catch(() => null)
|
|
233
|
+
const gate = config?.people?.others
|
|
234
|
+
if (gate?.rememberOthers !== true) return { written: false, why: 'off' }
|
|
235
|
+
|
|
236
|
+
const who = o.who && (o.who.id || o.who.name)
|
|
237
|
+
? { id: String(o.who.id ?? '').trim(), name: String(o.who.name ?? '').trim() }
|
|
238
|
+
: null
|
|
239
|
+
if (!who) return { written: false, why: 'unknown-speaker' }
|
|
240
|
+
|
|
241
|
+
const flat = String(o.text ?? '').replace(/\s+/g, ' ').trim()
|
|
242
|
+
// 太短的话不值得记(「嗯」「好」),和他那边同一个门槛。
|
|
243
|
+
if (flat.length < HEAR_MIN_CHARS) return { written: false, why: 'too-short' }
|
|
244
|
+
const chars = Math.max(1, Number(gate.othersCharMax ?? HEAR_SNIPPET) || HEAR_SNIPPET)
|
|
245
|
+
const sentence = flat.length > chars ? flat.slice(0, chars - 1) + '…' : flat
|
|
246
|
+
|
|
247
|
+
const day = Number(o.day ?? 0)
|
|
248
|
+
const { events } = await readEvents(root).catch(() => ({ events: [] }))
|
|
249
|
+
// 只数「今天、群聊、别人说的」那几条;她自己的话(utterance)不算在额度里。
|
|
250
|
+
const mine = (e) => e?.type === 'voice' && e?.scene === 'group' && Number(e?.day) === day
|
|
251
|
+
const today = events.filter(mine)
|
|
252
|
+
if (today.length >= Number(gate.othersPerDayMax ?? 5)) return { written: false, why: 'per-day' }
|
|
253
|
+
const same = today.filter((e) => {
|
|
254
|
+
const w = e?.who && typeof e.who === 'object' ? e.who : {}
|
|
255
|
+
if (who.id) return String(w.id ?? '') === who.id
|
|
256
|
+
return String(w.name ?? '') === who.name
|
|
257
|
+
})
|
|
258
|
+
if (same.length >= Number(gate.othersPerPersonPerDay ?? 1)) return { written: false, why: 'per-person' }
|
|
259
|
+
|
|
260
|
+
const ev = await appendEvent(
|
|
261
|
+
{
|
|
262
|
+
type: 'voice',
|
|
263
|
+
text: sentence,
|
|
264
|
+
who,
|
|
265
|
+
scene: 'group',
|
|
266
|
+
...(o.sessionId ? { sessionId: String(o.sessionId) } : {}),
|
|
267
|
+
},
|
|
268
|
+
{ day, stage: Number(o.stage ?? 1), source: 'system' },
|
|
269
|
+
root,
|
|
270
|
+
)
|
|
271
|
+
return { written: true, id: ev.id, text: sentence }
|
|
272
|
+
} catch (err) {
|
|
273
|
+
log('hear · 群里别人那句没记下', err?.message ?? err)
|
|
274
|
+
return { written: false, why: 'failed' }
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
211
278
|
export async function hearTurn(root, o = {}) {
|
|
212
279
|
const log = o.log ?? (() => {})
|
|
213
280
|
const every = Number(o.config?.memory?.hearEvery ?? HEAR_EVERY)
|
package/lib/herpeople.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* herpeople.js —— 让她能回头翻「她认识的人」:her_people 工具(1.1.0 S3-c)
|
|
3
|
+
*
|
|
4
|
+
* 和 `lib/herdiary.js` 同一个形状:只开一扇很窄的窗,**不是**给她一个读文件工具。
|
|
5
|
+
* - 参数只有一个名字(或名字里的几个字),或 `list`;
|
|
6
|
+
* - **不收路径**——`../`、绝对路径在这里没有入口;
|
|
7
|
+
* - 一次一份,正文截断到 `PEOPLE_READ_MAX`;
|
|
8
|
+
* - 读到的**不参与**身份文档拼装,也**不进** `her_recall`:
|
|
9
|
+
* 身份文档里那一段只有三个人一行,完整的内容在事件流里,只有她主动翻才看得到。
|
|
10
|
+
*
|
|
11
|
+
* 为什么不能返回空字符串:返回空串,她会以为「翻成功了,但是空的」;
|
|
12
|
+
* 名单为空时得直接说清「你现在还没往谁名下写过什么」——那是事实,不是失败。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { toJsonSchema } from './toolschema.js'
|
|
16
|
+
import { rootDir, readEvents } from './store.js'
|
|
17
|
+
import { loadConfig } from './settings.js'
|
|
18
|
+
import { defineTool } from './tool.js'
|
|
19
|
+
import { deriveSelf } from './derive.js'
|
|
20
|
+
import { findPerson, renderPerson, PEOPLE_READ_MAX } from './people.js'
|
|
21
|
+
import { pronounOf } from './pronoun.js'
|
|
22
|
+
|
|
23
|
+
/** 一次名单回几条:名单本身很短,全给也行,但这里与 `PEOPLE_MAX` 对齐。 */
|
|
24
|
+
const LIST_MAX = 24
|
|
25
|
+
|
|
26
|
+
/** 名字匹配词最长多少个字(防止她拿一整段话当名字)。 */
|
|
27
|
+
const WANT_MAX = 40
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 这一行在名单里怎么写。
|
|
31
|
+
*
|
|
32
|
+
* 2026-11-24 审计:从前这里写死「主人(你说的那个人)」,而她照名单里的字去查
|
|
33
|
+
* 却查不到(那一行的 `name` 是空串,`findPerson` 比对的是名字)——名单在教她
|
|
34
|
+
* 用一个查不到的说法。现在用她自己的称呼:她叫他「猫」,名单里就是「猫」。
|
|
35
|
+
*/
|
|
36
|
+
function labelOf(p, call) {
|
|
37
|
+
if (p.id !== 'owner') return p.name || '(没留下名字)'
|
|
38
|
+
return p.name || call || '你说的那个人'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function nameLine(p, call) {
|
|
42
|
+
const n = labelOf(p, call)
|
|
43
|
+
const j = p.judgments[0]
|
|
44
|
+
return j ? `- ${n}:${j.guess ? '你猜过' : '你写过'}「${j.text.slice(0, 30)}」` : `- ${n}`
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 注册 her_people 工具。
|
|
49
|
+
*
|
|
50
|
+
* @param {object} ctx dsh ctx
|
|
51
|
+
* @param {object} deps `{ root }`
|
|
52
|
+
*/
|
|
53
|
+
export function registerHerPeople(ctx, deps = {}) {
|
|
54
|
+
const root = deps.root ?? rootDir()
|
|
55
|
+
return ctx.tools.register(
|
|
56
|
+
defineTool({
|
|
57
|
+
name: 'her_people',
|
|
58
|
+
description:
|
|
59
|
+
'翻你认识的人:你怎么看这个人、这个人说过什么、你拒绝过什么。' +
|
|
60
|
+
'不给名字就回一份名单;给一个名字(或者名字里的几个字)就回那一个人。' +
|
|
61
|
+
'一次一份,太长的会截断。',
|
|
62
|
+
parameters: toJsonSchema({
|
|
63
|
+
name: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
required: false,
|
|
66
|
+
description: '想看谁。全名或者名字里的几个字都行。不写就回一份名单。',
|
|
67
|
+
},
|
|
68
|
+
list: {
|
|
69
|
+
type: 'boolean',
|
|
70
|
+
required: false,
|
|
71
|
+
description: '只想要一份名单:给 true 就只回名字,不出正文。',
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
output: {
|
|
75
|
+
schema: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
properties: {
|
|
78
|
+
found: { type: 'boolean' },
|
|
79
|
+
text: { type: 'string' },
|
|
80
|
+
},
|
|
81
|
+
required: ['found', 'text'],
|
|
82
|
+
},
|
|
83
|
+
render: (_args, out) => [{ type: 'text', text: out.text }],
|
|
84
|
+
},
|
|
85
|
+
async execute(args) {
|
|
86
|
+
try {
|
|
87
|
+
const { events } = await readEvents(root).catch(() => ({ events: [] }))
|
|
88
|
+
const { config } = await loadConfig(root).catch(() => ({ config: {} }))
|
|
89
|
+
// 2026-11-24 审计:这里从前自己调 `peopleOf(events)`,**不传她的称呼**,
|
|
90
|
+
// 于是主人那一行永远没有名字、靠 `topic` 写称呼的判断一条也挂不上——
|
|
91
|
+
// 身份段里摆着「你对猫有过一句准话」,翻出来却没有这句;她按名单里的字
|
|
92
|
+
// 去查也查不到。现在跟身份段走同一个派生(`deriveSelf`),一个真相源。
|
|
93
|
+
const model = deriveSelf(Array.isArray(events) ? events : [], {
|
|
94
|
+
growthDays: config?.growthDays,
|
|
95
|
+
})
|
|
96
|
+
const call = String(model?.name ?? '').trim().slice(0, WANT_MAX)
|
|
97
|
+
// 开关关着时,她的世界里只有{T}一个人——工具也不该把别人翻出来。
|
|
98
|
+
const others = config?.people?.others?.enabled === true
|
|
99
|
+
const all = Array.isArray(model?.people) ? model.people : []
|
|
100
|
+
// 只有称呼、没有任何往来记录的人不摆:一个空壳子页面对她没信息量,
|
|
101
|
+
// 还会让「你现在认识 N 个人」这个数虚高。
|
|
102
|
+
const hasContent = (p) =>
|
|
103
|
+
p.times > 0 || p.judgments.length > 0 || p.changed.length > 0 || p.said.length > 0 || p.didTo.length > 0
|
|
104
|
+
const people = (others ? all : all.filter((p) => p.id === 'owner')).filter(hasContent)
|
|
105
|
+
|
|
106
|
+
if (!people.length) {
|
|
107
|
+
return {
|
|
108
|
+
found: false,
|
|
109
|
+
text:
|
|
110
|
+
'你现在还没往谁名下写过什么。哪天对某个人心里有了一句准话,' +
|
|
111
|
+
'用 growth_commit 写下来、topic 填那个人的名字,这里就会有了。',
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const want = String(args?.name ?? '')
|
|
116
|
+
.replace(/\s+/g, ' ')
|
|
117
|
+
.trim()
|
|
118
|
+
.slice(0, WANT_MAX)
|
|
119
|
+
|
|
120
|
+
if (args?.list === true || !want) {
|
|
121
|
+
const rows = people.slice(0, LIST_MAX)
|
|
122
|
+
return {
|
|
123
|
+
found: true,
|
|
124
|
+
text: [`你现在认识 ${people.length} 个人:`, ...rows.map((p) => nameLine(p, call))].join('\n'),
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 名单里写的是哪个字,就得能用那个字查到(见 `labelOf`):名字匹配不上时,
|
|
129
|
+
// 再按名单上显示的那个说法找一遍——她照着名单问,不该得到「没找到」。
|
|
130
|
+
let hit = findPerson(people, want)
|
|
131
|
+
if (!hit.length) {
|
|
132
|
+
const byLabel = people.filter((p) => {
|
|
133
|
+
const n = labelOf(p, call)
|
|
134
|
+
return n === want || n.includes(want) || want.includes(n)
|
|
135
|
+
})
|
|
136
|
+
if (byLabel.length) hit = byLabel
|
|
137
|
+
}
|
|
138
|
+
if (!hit.length) {
|
|
139
|
+
return {
|
|
140
|
+
found: false,
|
|
141
|
+
text:
|
|
142
|
+
`没找到「${want}」。你现在认识的是:` +
|
|
143
|
+
people.map((p) => labelOf(p, call)).join('、') +
|
|
144
|
+
'。',
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const text = hit.map((p) => renderPerson(p, { pronoun: pronounOf(config) })).join('\n\n')
|
|
148
|
+
return {
|
|
149
|
+
found: true,
|
|
150
|
+
text: text.length > PEOPLE_READ_MAX ? `${text.slice(0, PEOPLE_READ_MAX)}…` : text,
|
|
151
|
+
}
|
|
152
|
+
} catch {
|
|
153
|
+
// 读不出来就是读不出来,不说教、不假装成功。
|
|
154
|
+
return { found: false, text: '这会儿翻不开,稍后再试。' }
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
}),
|
|
158
|
+
)
|
|
159
|
+
}
|
package/lib/history.js
CHANGED
|
@@ -26,8 +26,13 @@ export { videoUrl }
|
|
|
26
26
|
* 按日期倒序分组的历史。
|
|
27
27
|
*
|
|
28
28
|
* @param {Array} events 事件流
|
|
29
|
-
* @param {{days?:number, limit?:number}} opts days=取最近几天(默认 14),limit=每天最多几条(默认 200
|
|
30
|
-
*
|
|
29
|
+
* @param {{days?:number, limit?:number, q?:string}} opts days=取最近几天(默认 14),limit=每天最多几条(默认 200),
|
|
30
|
+
* q=搜索词(空格分开的每个词都要命中;空则不过滤,2026-11-24 用户 m02329)
|
|
31
|
+
* how 三档(2026-11-24,用户 m01923):watch=抽帧看过画面、look=她自己点开读过、
|
|
32
|
+
* browse=自动逛翻到过。以前后两档合写成 'glance',界面上只能标出「看过画面」一种,
|
|
33
|
+
* 剩下两种靠猜;拆开之后每一行都能说清她跟这条视频是什么关系。
|
|
34
|
+
*
|
|
35
|
+
* @returns {Array<{date:string, items:Array<{bvid,title,up,duration,view,url,how:'watch'|'look'|'browse'}>}>}
|
|
31
36
|
*/
|
|
32
37
|
export function historyFromEvents(events, opts = {}) {
|
|
33
38
|
const days = Math.max(1, Math.min(366, Number(opts.days) || 14))
|
|
@@ -92,7 +97,7 @@ export function historyFromEvents(events, opts = {}) {
|
|
|
92
97
|
duration: firstCount(b.duration, i.duration),
|
|
93
98
|
view: firstCount(b.view, i.view),
|
|
94
99
|
url: videoUrl(got.bvid),
|
|
95
|
-
how: '
|
|
100
|
+
how: 'look',
|
|
96
101
|
})
|
|
97
102
|
}
|
|
98
103
|
|
|
@@ -114,15 +119,32 @@ export function historyFromEvents(events, opts = {}) {
|
|
|
114
119
|
duration: Number(it?.duration) || 0,
|
|
115
120
|
view: Number(it?.view) || 0,
|
|
116
121
|
url: videoUrl(bvid),
|
|
117
|
-
how: '
|
|
122
|
+
how: 'browse',
|
|
118
123
|
})
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
126
|
|
|
127
|
+
const hitWord = wordHit(opts.q)
|
|
122
128
|
return [...groups.entries()]
|
|
123
129
|
.sort((a, b) => (a[0] < b[0] ? 1 : -1))
|
|
124
130
|
.slice(0, days)
|
|
125
|
-
.map(([date, items]) => ({ date, items: items.slice(0, limit) }))
|
|
131
|
+
.map(([date, items]) => ({ date, items: items.filter(hitWord).slice(0, limit) }))
|
|
132
|
+
.filter((g) => g.items.length > 0)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 搜索词(2026-11-24,用户 m02329):空格分开的每个词都要命中,标题 / UP 名 / BV 号都算。
|
|
137
|
+
*
|
|
138
|
+
* 放在服务端而不是浏览器:365 天全量一次能给到约七万条,先发下去再筛是白烧带宽。
|
|
139
|
+
* 没有词时返回一个恒真的函数,调用方不必分支。
|
|
140
|
+
*/
|
|
141
|
+
function wordHit(q) {
|
|
142
|
+
const words = String(q ?? '').toLowerCase().split(/\s+/).filter(Boolean)
|
|
143
|
+
if (!words.length) return () => true
|
|
144
|
+
return (it) => {
|
|
145
|
+
const hay = `${it?.title ?? ''} ${it?.up ?? ''} ${it?.bvid ?? ''}`.toLowerCase()
|
|
146
|
+
return words.every((w) => hay.includes(w))
|
|
147
|
+
}
|
|
126
148
|
}
|
|
127
149
|
|
|
128
150
|
/**
|