@ssamurias/dsh-fish 1.0.8 → 1.0.9
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 +32 -3
- package/CHANGELOG.md +4366 -4304
- package/README.md +22 -9
- package/RELEASE-NOTES-1.0.9.md +79 -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/capture.js +16 -0
- package/lib/claim.js +103 -0
- package/lib/client/00-shell.js +500 -0
- package/lib/client/01-state-load.js +860 -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 +542 -0
- package/lib/client/08-tab-memory-plugins.js +733 -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 +661 -0
- package/lib/client/12-pressure-chip-mount.js +565 -0
- package/lib/client.js +83 -3
- package/lib/comment.js +18 -3
- package/lib/derive.js +197 -19
- package/lib/doing.js +31 -15
- package/lib/env.d.ts +224 -0
- package/lib/health.js +56 -0
- package/lib/hear.js +67 -0
- package/lib/home.js +12 -1
- package/lib/identity.js +23 -0
- package/lib/index.js +27 -17
- package/lib/look.js +2 -1
- package/lib/make.js +60 -12
- package/lib/markup.js +61 -23
- package/lib/observe-bili.js +331 -0
- package/lib/observe-config.js +223 -0
- package/lib/observe-data.js +522 -0
- package/lib/observe-home.js +383 -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/persona.js +149 -23
- package/lib/restrict.js +21 -1
- package/lib/say.js +48 -0
- package/lib/scheduler.js +23 -3
- package/lib/schema.js +11 -4
- package/lib/scrub.js +3 -3
- package/lib/settings.js +104 -7
- package/lib/stance.js +41 -3
- package/lib/status.js +14 -5
- package/lib/turns.js +51 -4
- package/lib/types.d.ts +513 -0
- package/lib/voices.js +3 -0
- package/lib/wiki.js +47 -13
- 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/health.js
CHANGED
|
@@ -167,6 +167,58 @@ function dedupeByText(rows) {
|
|
|
167
167
|
return out
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/**
|
|
171
|
+
* 认识人这几个数(1.0.9)。只数事件流里已经有的东西,不推断、不评价。
|
|
172
|
+
*
|
|
173
|
+
* 这个版本第一次往事件里写「这句话是谁说的」(`who`),也第一次写群聊里的
|
|
174
|
+
* `voice`。这几个数只回答一个问题:那条链路今天有没有真在跑。
|
|
175
|
+
*
|
|
176
|
+
* - ownerJudged:写在你名下的判断有几条(S0 起,屋子里她说的话都带 `who.id = 'owner'`)
|
|
177
|
+
* - met:除你之外,事件里出现过、带稳定 id 的人有几个(昵称会改,所以认 id)
|
|
178
|
+
* - judged:其中她真写过判断的有几个(`utterance` / `revise` 带 `who`)
|
|
179
|
+
* - herWords:群房与外客那两路,她的话留了几条(S2-a)
|
|
180
|
+
* - othersWords:群聊里别人的话留了几条(S2-b)
|
|
181
|
+
* - drifts / unsettled:说法变过几处、一直没定几处
|
|
182
|
+
*
|
|
183
|
+
* 一个数都没有时,`people` 不进返回值——界面上不排一排零当装饰。
|
|
184
|
+
*/
|
|
185
|
+
function peopleStats(list, model) {
|
|
186
|
+
const met = new Set()
|
|
187
|
+
const judged = new Set()
|
|
188
|
+
let ownerJudged = 0
|
|
189
|
+
let herWords = 0
|
|
190
|
+
let othersWords = 0
|
|
191
|
+
for (const ev of list) {
|
|
192
|
+
const type = String(ev?.type ?? '')
|
|
193
|
+
const id = String(ev?.who?.id ?? '')
|
|
194
|
+
if (type === 'utterance' && ev?.scene === 'group') herWords += 1
|
|
195
|
+
if (type === 'voice' && ev?.scene === 'group') othersWords += 1
|
|
196
|
+
if (!id) continue
|
|
197
|
+
const isJudge = type === 'utterance' || type === 'revise'
|
|
198
|
+
if (id === 'owner') {
|
|
199
|
+
if (isJudge) ownerJudged += 1
|
|
200
|
+
continue
|
|
201
|
+
}
|
|
202
|
+
met.add(id)
|
|
203
|
+
if (isJudge) judged.add(id)
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
met: met.size,
|
|
207
|
+
judged: judged.size,
|
|
208
|
+
ownerJudged,
|
|
209
|
+
herWords,
|
|
210
|
+
othersWords,
|
|
211
|
+
drifts: Array.isArray(model?.drifts) ? model.drifts.length : 0,
|
|
212
|
+
unsettled: Array.isArray(model?.unsettled) ? model.unsettled.length : 0,
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** 一个数都没有时整段不摆。 */
|
|
217
|
+
function peopleEmpty(p) {
|
|
218
|
+
if (!p) return true
|
|
219
|
+
return !(p.met + p.judged + p.ownerJudged + p.herWords + p.othersWords + p.drifts + p.unsettled)
|
|
220
|
+
}
|
|
221
|
+
|
|
170
222
|
/**
|
|
171
223
|
* @param {Array} events 事件流(只读)
|
|
172
224
|
* @param {{now?:number, growthDays?:number, staleDays?:number}} opts
|
|
@@ -258,6 +310,8 @@ export function examine(events = [], { now = Date.now(), growthDays = 30, staleD
|
|
|
258
310
|
.sort((a, b) => b.days - a.days))
|
|
259
311
|
.slice(0, HEALTH_LIST)
|
|
260
312
|
|
|
313
|
+
const people = peopleStats(list, model)
|
|
314
|
+
|
|
261
315
|
return {
|
|
262
316
|
ok: true,
|
|
263
317
|
// 连一条判断都还没形成时,别说「一切正常」——说还太早。
|
|
@@ -283,5 +337,7 @@ export function examine(events = [], { now = Date.now(), growthDays = 30, staleD
|
|
|
283
337
|
stock: stockStats(list, weekFrom),
|
|
284
338
|
// 0.9.9 收尾(用户 m03900):说话有没有落到具体东西上。同样只报数。
|
|
285
339
|
speech: speechStats(list, weekFrom),
|
|
340
|
+
// 1.0.9:认识人那几个数。一个都没有时整段不出现在返回值里。
|
|
341
|
+
...(peopleEmpty(people) ? {} : { people }),
|
|
286
342
|
}
|
|
287
343
|
}
|
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/home.js
CHANGED
|
@@ -455,7 +455,18 @@ async function ensureTalkSessionOnce(ctx, { root = rootDir(), wsId, title = TITL
|
|
|
455
455
|
// 命名失败不影响功能:侧栏会显示默认标题,但会话本身是好的
|
|
456
456
|
await sc.rename({ sessionId, title }).catch(() => {})
|
|
457
457
|
}
|
|
458
|
-
|
|
458
|
+
// 2026-11-23(用户报的「崩溃回退不带 carry」):旧的那条接不上
|
|
459
|
+
// (宿主崩过、把它弄丢了),这里兜底补建一间——那也是一次搬家,新房间的
|
|
460
|
+
// 第一句该看到同一页交接。原来只有轮换与「认领活会话」(adoptLiveSession)
|
|
461
|
+
// 两条路拼 carry,这条兜底路一直是空的。
|
|
462
|
+
// 第一次开档(没有旧会话)与用户明说要重开(force:重置 / 重新搭一间)
|
|
463
|
+
// 不摆:那不是搬家,是把话头重新起一页。
|
|
464
|
+
const oldSid = String(saved?.sessionId ?? '')
|
|
465
|
+
const carry = !force && oldSid
|
|
466
|
+
? await buildHandoff(root, { turns: await carryTurnsFor(root) }).catch(() => '')
|
|
467
|
+
: ''
|
|
468
|
+
await writeAtomic(homeFile(root), JSON.stringify({ wsId, sessionId, title, preset: presetUsed, pressureRoomLinks: saved?.pressureRoomLinks, pressureRoomIds: [...new Set([...(saved?.pressureRoomIds ?? []), sessionId])], createdAt: new Date().toISOString(), ...(carry ? { carry } : {}) }, null, 2))
|
|
469
|
+
if (carry) log?.('旧会话接不上了,新房间先留一页交接,等第一句话时摆出来')
|
|
459
470
|
return { ok: true, sessionId, reused: false, preset: presetUsed }
|
|
460
471
|
} catch (err) {
|
|
461
472
|
return { ok: false, why: `建会话失败:${String(err?.message ?? err).slice(0, 160)}` }
|
package/lib/identity.js
CHANGED
|
@@ -29,6 +29,7 @@ import { selfDocPath, catalogOf } from './selfdoc.js'
|
|
|
29
29
|
import { fillOwner, pronounFor } from './pronoun.js'
|
|
30
30
|
import { cwdOf, foldedRecallNote, isHerHome, toolSurfaceFor, visibleToolsOf } from './restrict.js'
|
|
31
31
|
import { paths } from './store.js'
|
|
32
|
+
import { whenHers } from './claim.js'
|
|
32
33
|
import { normalizeNote, notesPath } from './note.js'
|
|
33
34
|
import { appointPath } from './appoint.js'
|
|
34
35
|
import { activeOutingSync, bindOutingSession } from './outing.js'
|
|
@@ -1356,6 +1357,7 @@ export function attachAwayGuard(agent, { root, herDir, log } = {}) {
|
|
|
1356
1357
|
*/
|
|
1357
1358
|
export function registerIdentity(ctx, { root, herDir, log } = {}) {
|
|
1358
1359
|
const state = { ok: false, applied: 0, why: '' }
|
|
1360
|
+
const claimedIdentity = new WeakSet()
|
|
1359
1361
|
const onCreated = ({ agent } = {}) => {
|
|
1360
1362
|
try {
|
|
1361
1363
|
if (!herDir) return
|
|
@@ -1384,6 +1386,27 @@ export function registerIdentity(ctx, { root, herDir, log } = {}) {
|
|
|
1384
1386
|
const starting = Boolean(outing && !outing.sessionId && !cwd)
|
|
1385
1387
|
const isOuting = sidMatch || cwdMatch || starting
|
|
1386
1388
|
if (!home && !isOuting) {
|
|
1389
|
+
// 桥自建的会话(2026-11-23):cwd 是她的屋子,id 不在册。先不挂——等第一封
|
|
1390
|
+
// 外面来的信把它认下来(lib/claim.js),再把身份段补上。他自己开在这个
|
|
1391
|
+
// 工作区的会话收的是本地客户端打的字,永远等不到那封信,不会误挂。
|
|
1392
|
+
if (agent && sid && flatPath(cwd) === flatPath(herDir)) {
|
|
1393
|
+
const ref = new WeakRef(agent)
|
|
1394
|
+
whenHers(sid, herDir, () => {
|
|
1395
|
+
const got = ref.deref()
|
|
1396
|
+
if (!got || claimedIdentity.has(got)) return
|
|
1397
|
+
claimedIdentity.add(got)
|
|
1398
|
+
const r = attachIdentity(got, root, { herDir, log })
|
|
1399
|
+
if (r.ok) {
|
|
1400
|
+
state.ok = true
|
|
1401
|
+
state.applied += 1
|
|
1402
|
+
log?.(`[dsh-fish] 身份段已挂进 system prompt(第 ${state.applied} 次·桥的会话)`, 'debug')
|
|
1403
|
+
} else {
|
|
1404
|
+
state.ok = false
|
|
1405
|
+
state.why = r.why ?? 'unknown'
|
|
1406
|
+
log?.(`[dsh-fish] 桥的会话身份段没挂上:${state.why}`)
|
|
1407
|
+
}
|
|
1408
|
+
})
|
|
1409
|
+
}
|
|
1387
1410
|
if (outing) log?.(`[dsh-fish] 有条出门记录,但这条会话没对上:cwd=${cwd || '(空)'} sid=${sid || '(空)'}`)
|
|
1388
1411
|
return
|
|
1389
1412
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* index.js —— 插件入口
|
|
3
4
|
*
|
|
@@ -62,7 +63,7 @@ export const name = 'dsh-fish'
|
|
|
62
63
|
* 版本号,必须和 package.json 的 version 一样(test/boot.test.mjs 盯着)。
|
|
63
64
|
* 不只是日志:升级自检和设置页的「检查更新」拿它当「正在跑的版本」。
|
|
64
65
|
*/
|
|
65
|
-
export const VERSION = '1.0.
|
|
66
|
+
export const VERSION = '1.0.9'
|
|
66
67
|
|
|
67
68
|
// ⚠️ 一个数组写全,不要拆成对象
|
|
68
69
|
// 2026-10-30(m02961):`userQuestions` **不再写进 inject**。写进 inject 的东西缺一个,
|
|
@@ -90,12 +91,15 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
90
91
|
const plog = levelLog(logger)
|
|
91
92
|
// 工具面收窄的结果(给自检读)。applied 是"真的挂上过几次",
|
|
92
93
|
// 不是"注册了没有"——注册了但没匹配到 agent 等于没生效,这两件事必须分开。
|
|
94
|
+
/** @type {any} */
|
|
93
95
|
let restrictState = { ok: false, applied: 0, why: 'not attempted', allow: [] }
|
|
94
96
|
// 多租户(2026-10-28 m01319):这个对象是「这个实例认哪个家、它还是不是房主」的唯一真相,
|
|
95
97
|
// 工具注册时按引用传下去 —— boot 之后填进来,工具执行时现读,不做拷贝。
|
|
98
|
+
/** @type {import('./types.js').TenancyBag & { root: string, herDir: string, tenant: { ok: boolean, instanceId?: string, why?: string, owner?: any } }} */
|
|
96
99
|
const tenancy = { root, herDir: '', tenant: { ok: true, instanceId: '', why: '' } }
|
|
97
100
|
// 升级自检(2026-10-29):`file:` 装的人常常只换了源目录,跑的还是 node_modules 里的旧副本。
|
|
98
101
|
// 这里只读不写;查不到就写 skipped,不影响启动。
|
|
102
|
+
/** @type {{ upgrade: Record<string, any>, host: Record<string, any> }} */
|
|
99
103
|
const install = {
|
|
100
104
|
upgrade: { ok: false, skipped: true, why: '还没查', running: VERSION, source: '', sourcePath: '', profile: '', stale: false },
|
|
101
105
|
// 宿主版本(2026-10-30 m03193):package.json 的 engines.dsh 声明范围,这里运行时对一次账。
|
|
@@ -104,7 +108,11 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
104
108
|
// 宿主兼容(2026-10-30 m02961):只在运行时探测,不写进 inject。
|
|
105
109
|
// 写进 inject 的代价是「缺了就整个插件不装」——而缺的那个服务只关掉一条功能。
|
|
106
110
|
const compat = { checked: false, userQuestions: false }
|
|
111
|
+
// jsconfig 的 lib 带 DOM,`setInterval` 被当成返回 number;Node 里返回的是带 unref 的
|
|
112
|
+
// Timeout 对象。这里只用到 unref,收回 any 免得类型层替 Node 做错判断。
|
|
113
|
+
/** @type {any} */
|
|
107
114
|
let heartbeat = null
|
|
115
|
+
/** @type {boolean} */
|
|
108
116
|
let stopped = false
|
|
109
117
|
// 正在认领的那次:shutdown 要等它放开,新实例才不会把旧认领读成「被占着」
|
|
110
118
|
let claiming = null
|
|
@@ -184,25 +192,26 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
184
192
|
// 那个文件、读到写了一半的)什么都不改,下一拍再看——以前这里一次 false 就永久只读,
|
|
185
193
|
// 要重启 DSH 才回得来。声明文件没了或是空的(重开一局、从备份恢复都会把它带走)
|
|
186
194
|
// 就用同一个 instanceId 重新占;真有别人活着占着,claimRoot 会照实拒绝。
|
|
195
|
+
const tenantStopped = () => stopped || tenancy.tenant.ok === false
|
|
187
196
|
const beatOnce = async () => {
|
|
188
|
-
if (
|
|
197
|
+
if (tenantStopped()) return
|
|
189
198
|
const beat = await beatRootState(root, id)
|
|
190
|
-
if (
|
|
199
|
+
if (tenantStopped()) return
|
|
191
200
|
if (beat.state === 'lost') return lose(`声明里是 ${beat.owner}`)
|
|
192
201
|
if (beat.state !== 'vacant') return
|
|
193
202
|
// 声明不在了,也可能是数据目录刚被迁走(老目录改名封存,声明跟着走了)。那就不能重新占:
|
|
194
203
|
// 占上以后她的写工具照样回成功,写下的东西留在老位置,重启后走指针去新位置就看不到了。
|
|
195
204
|
// 和以前一样从这一拍起停写,等重启。指针这一次没读成就下一拍再看,不猜。
|
|
196
205
|
const gone = await rootMovedAway(root, { since: bootAt })
|
|
197
|
-
if (
|
|
206
|
+
if (tenantStopped()) return
|
|
198
207
|
if (gone.state === 'unknown') return
|
|
199
208
|
if (gone.state === 'moved') {
|
|
200
209
|
tenancy.tenant = { ok: false, instanceId: id, why: '数据文件夹已经搬到了新位置,重启 DSH 之前这边不再写入。' }
|
|
201
210
|
logger.warn('[dsh-fish] 数据目录已经迁走,停止写入,等重启')
|
|
202
211
|
return
|
|
203
212
|
}
|
|
204
|
-
const again = await claimRoot(root, { version: VERSION, instanceId: id, bootAt })
|
|
205
|
-
if (
|
|
213
|
+
const again = await claimRoot(root, /** @type {any} */ ({ version: VERSION, instanceId: id, bootAt }))
|
|
214
|
+
if (tenantStopped()) return
|
|
206
215
|
if (!again.ok) return lose(`声明没了,重新占时发现 ${again.owner?.instanceId ?? '别的实例'} 占着`)
|
|
207
216
|
logger.info('[dsh-fish] 占用声明不在了,已经重新写上')
|
|
208
217
|
}
|
|
@@ -306,7 +315,7 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
306
315
|
// 反过来,读回来以后 cwd 落在她屋里**但不是这些 id** 的会话(他本人的)不再被认成她。
|
|
307
316
|
try { seedHerSessions(root) } catch { /* 台账读坏了等于没读,退化成旧判据 */ }
|
|
308
317
|
try {
|
|
309
|
-
const off = registerToolRestrict(ctx, {
|
|
318
|
+
const off = registerToolRestrict(ctx, /** @type {any} */ ({
|
|
310
319
|
herDir,
|
|
311
320
|
extra: config?.tools?.allow ?? [],
|
|
312
321
|
enabled: config?.tools?.restrict !== false,
|
|
@@ -315,8 +324,8 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
315
324
|
// her_say 不看开关,在 FISH_TOOLS 基线里(以前这里传的 proactive 早就没人读了)。
|
|
316
325
|
dream: config?.dream?.enabled !== false,
|
|
317
326
|
log: plog,
|
|
318
|
-
onResult: (r) => { restrictState = r },
|
|
319
|
-
})
|
|
327
|
+
onResult: (/** @type {any} */ r) => { restrictState = r },
|
|
328
|
+
}))
|
|
320
329
|
if (typeof off === 'function') disposers.push(off)
|
|
321
330
|
} catch (err) {
|
|
322
331
|
logger.warn('[dsh-fish] 工具面收窄没挂上', err?.message ?? err)
|
|
@@ -351,30 +360,31 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
351
360
|
logger.warn('[dsh-fish] 请神补挂没挂上', err?.message ?? err)
|
|
352
361
|
}
|
|
353
362
|
|
|
363
|
+
/** @type {Record<string, any>} */
|
|
354
364
|
let home = { ok: false, why: 'not attempted', wsId: '', sessionId: '' }
|
|
355
365
|
try {
|
|
356
|
-
home = await bootstrapHome(ctx, {
|
|
366
|
+
home = await bootstrapHome(ctx, /** @type {any} */ ({
|
|
357
367
|
root,
|
|
358
368
|
preset: config?.tools?.preset ?? '',
|
|
359
369
|
tenant: tenancy.tenant,
|
|
360
370
|
log: plog,
|
|
361
|
-
})
|
|
371
|
+
}))
|
|
362
372
|
} catch (err) {
|
|
363
|
-
home = { ok: false, why: String(err?.message ?? err).slice(0, 160), wsId: '', sessionId: '' }
|
|
373
|
+
home = { ok: false, why: String(/** @type {any} */ (err)?.message ?? err).slice(0, 160), wsId: '', sessionId: '' }
|
|
364
374
|
}
|
|
365
375
|
if (stopped) return
|
|
366
376
|
// 观测台要能把「这个家在别处也开着」和普通失败分开报(2026-10-29 m02162)。
|
|
367
|
-
tenancy.home = { ok: home.ok, blocked: home.blocked === true, sessionId: home.sessionId ?? '', why: home.why ?? '' }
|
|
377
|
+
tenancy.home = /** @type {any} */ ({ ok: home.ok, blocked: home.blocked === true, sessionId: home.sessionId ?? '', why: home.why ?? '' })
|
|
368
378
|
if (home.blocked === true) logger.warn(`[dsh-fish] ${home.why}`)
|
|
369
379
|
else if (!home.ok) logger.warn(`[dsh-fish] 屋子没建起来:${home.why}`)
|
|
370
380
|
else {
|
|
371
381
|
// 屋子是空的(上一次开了但从没说过话)时,侧栏不会显示它——见 sessionVisible。
|
|
372
382
|
// 启动时就叫一声,免得用户重启后以为"人不见了"。
|
|
373
383
|
try {
|
|
374
|
-
const woke = await wakeIfBlank(ctx, { sessionId: home.sessionId, root, log: plog, freshOnly: !home.reused })
|
|
384
|
+
const woke = await wakeIfBlank(ctx, /** @type {any} */ ({ sessionId: home.sessionId, root, log: plog, freshOnly: !home.reused }))
|
|
375
385
|
if (woke.woke) logger.info('[dsh-fish] 屋子是空的,已经叫了她一声')
|
|
376
386
|
} catch (err) {
|
|
377
|
-
logger.warn(`[dsh-fish] 启动唤醒失败:${String(err?.message ?? err).slice(0, 120)}`)
|
|
387
|
+
logger.warn(`[dsh-fish] 启动唤醒失败:${String(/** @type {any} */ (err)?.message ?? err).slice(0, 120)}`)
|
|
378
388
|
}
|
|
379
389
|
}
|
|
380
390
|
|
|
@@ -394,7 +404,7 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
394
404
|
const found = findPocketWorkspace(ctx, config)
|
|
395
405
|
const homeWs = String(home?.wsId ?? '') || String((await homeStatus(root)).wsId ?? '')
|
|
396
406
|
if (found.registered && homeWs) {
|
|
397
|
-
const order = await ensurePocketOrder(ctx, { pocketWsId: found.wsId, homeWsId: homeWs })
|
|
407
|
+
const order = /** @type {any} */ (await ensurePocketOrder(ctx, { pocketWsId: found.wsId, homeWsId: homeWs }))
|
|
398
408
|
if (order.retitled) logger.info('[dsh-fish] 工作园区的工作区名已统一')
|
|
399
409
|
if (order.ok && order.moved) logger.info('[dsh-fish] 工作园区已排到大肥鱼的家下面')
|
|
400
410
|
else if (!order.ok) logger.info(`[dsh-fish] 口袋排序跳过:${order.why}`)
|
|
@@ -498,7 +508,7 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
498
508
|
|
|
499
509
|
// 动手回合的闸与记账(2026-11-14,用户 m01237):只在主动回合里生效,
|
|
500
510
|
// 他自己找她、定时叫醒都不经过;拿不到会话时一律放行。
|
|
501
|
-
const doingOff = registerDoingHooks(ctx, { root, log: (...a) => logger.info(...a) })
|
|
511
|
+
const doingOff = registerDoingHooks(ctx, /** @type {any} */ ({ root, log: (/** @type {any[]} */ ...a) => logger.info(...a) }))
|
|
502
512
|
if (doingOff) disposers.push(doingOff)
|
|
503
513
|
|
|
504
514
|
// 生物钟:把屋子信息一起传下去。她每晚醒来说话要落进**同一个**会话,
|
package/lib/look.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* 这个工具让她能在醒着的时候自己说"我想看看别的"。
|
|
8
8
|
*
|
|
9
9
|
* 三条约束(与 growth_commit 同构):
|
|
10
|
-
* 1.
|
|
10
|
+
* 1. **只读**。不点赞、不评论;登录过就带主人的登录态请求(1.0.6 起,1.0.9 起定时刷站
|
|
11
|
+
* 与安静刷也一样)。站方只知道这个账号看了这条;她不会在账号上留下评论、点赞这类痕迹。
|
|
11
12
|
* 2. **不回显状态**。返回值只有素材本身,没有"你今天还剩几次""你处于第几阶段"。
|
|
12
13
|
* 3. **不给她配置**。她不知道有黑名单、不知道有配额;被过滤掉的东西她也不会知道。
|
|
13
14
|
* 知道就变成了"哦原来他们不让我看这个",那不是她要处理的事。
|