@ssamurias/dsh-fish 1.0.7 → 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.
Files changed (77) hide show
  1. package/AGENTS.md +32 -3
  2. package/CHANGELOG.md +4366 -4265
  3. package/README.md +243 -627
  4. package/RELEASE-NOTES-1.0.8.md +81 -0
  5. package/RELEASE-NOTES-1.0.9.md +79 -0
  6. package/THIRD-PARTY-NOTICES.md +1 -1
  7. package/docs/troubleshooting.md +79 -1
  8. package/docs//350/256/244/344/272/272/345/210/244/346/215/256.md +112 -0
  9. package/lib/appoint.js +106 -22
  10. package/lib/ask.js +8 -3
  11. package/lib/at.js +16 -1
  12. package/lib/capture.js +51 -1
  13. package/lib/claim.js +103 -0
  14. package/lib/client/00-shell.js +500 -0
  15. package/lib/client/01-state-load.js +860 -0
  16. package/lib/client/02-actions.js +670 -0
  17. package/lib/client/03-widgets-header.js +721 -0
  18. package/lib/client/04-pressure-lab.js +891 -0
  19. package/lib/client/05-pressure-charts.js +431 -0
  20. package/lib/client/06-tab-status-grow.js +468 -0
  21. package/lib/client/07-tab-home-bili.js +542 -0
  22. package/lib/client/08-tab-memory-plugins.js +733 -0
  23. package/lib/client/09-tab-outing.js +710 -0
  24. package/lib/client/10-data-handlers.js +519 -0
  25. package/lib/client/11-tab-data-frame.js +661 -0
  26. package/lib/client/12-pressure-chip-mount.js +565 -0
  27. package/lib/client.js +109 -24
  28. package/lib/comment.js +18 -3
  29. package/lib/cue.js +102 -5
  30. package/lib/deliver.js +3 -1
  31. package/lib/derive.js +308 -41
  32. package/lib/doing.js +31 -15
  33. package/lib/drive.js +3 -5
  34. package/lib/env.d.ts +224 -0
  35. package/lib/health.js +56 -0
  36. package/lib/hear.js +70 -0
  37. package/lib/home.js +48 -20
  38. package/lib/identity.js +25 -2
  39. package/lib/index.js +32 -18
  40. package/lib/look.js +2 -1
  41. package/lib/loops.js +39 -0
  42. package/lib/make.js +60 -12
  43. package/lib/markup.js +77 -1
  44. package/lib/match.js +262 -0
  45. package/lib/observe-bili.js +331 -0
  46. package/lib/observe-config.js +223 -0
  47. package/lib/observe-data.js +522 -0
  48. package/lib/observe-home.js +383 -0
  49. package/lib/observe-http.js +250 -0
  50. package/lib/observe-outing.js +650 -0
  51. package/lib/observe-state.js +419 -0
  52. package/lib/observe-trip.js +286 -0
  53. package/lib/observe.js +99 -3574
  54. package/lib/persona.js +187 -40
  55. package/lib/proactive.js +48 -47
  56. package/lib/pronounask.js +15 -1
  57. package/lib/restrict.js +146 -9
  58. package/lib/say.js +68 -4
  59. package/lib/scheduler.js +63 -25
  60. package/lib/schema.js +57 -4
  61. package/lib/scrub.js +16 -1
  62. package/lib/settings.js +128 -12
  63. package/lib/stance.js +131 -19
  64. package/lib/status.js +14 -5
  65. package/lib/store.js +24 -2
  66. package/lib/sub.js +7 -1
  67. package/lib/talkmem.js +12 -8
  68. package/lib/transcript.js +205 -0
  69. package/lib/turns.js +147 -19
  70. package/lib/types.d.ts +513 -0
  71. package/lib/voices.js +26 -1
  72. package/lib/wiki.js +47 -13
  73. package/lib/works.js +200 -49
  74. package/media/banner.jpg +0 -0
  75. package/package.json +1 -1
  76. package/scripts/build-client.mjs +83 -0
  77. package/scripts/sync-pressure-formulas.mjs +12 -15
package/lib/drive.js CHANGED
@@ -26,7 +26,6 @@ export const DRIVE = Object.freeze({
26
26
  growthPerHour: 0.08,
27
27
  threshold: 0.8,
28
28
  cost: 0.8,
29
- minGapMs: 2 * 60 * 60_000,
30
29
  /** 桌上每一样没合上的事 / 每一行旧句子各加多少(各最多算两份 / 三份)。 */
31
30
  // 2026-11-17(用户 m03985):外部反馈说「想说话不该是进度条」——先把「话头未接」
32
31
  // 这一类冲动抬上去,让有真东西时更早开、没东西时更晚开;同一天用户 m04229 又批准
@@ -199,10 +198,9 @@ export function driveOf({ events = [], now = Date.now(), desk = null, stage = 1,
199
198
  if (!last) return { ...base, why: '还没有任何记录,不急着动' }
200
199
 
201
200
  const hoursSince = Math.max(0, (now - last) / HOUR)
202
- // 刚动过:哪怕攒得快,也得隔开一点——两次冲动贴在一起就不像冲动了。
203
- if (now - last < DRIVE.minGapMs) {
204
- return { ...base, hoursSince, why: '刚动过,还没到两小时' }
205
- }
201
+ // 2026-11-22(用户 m00851):原来这里有一道写死的「两小时」硬闸。
202
+ // 它只拦得住「刚动过」这一种情况,却和设置里的「安静多久」打架;
203
+ // 现在时间闸统一交给 proactiveState 的 quietMinutes,这里只算劲儿,不再拦。
206
204
 
207
205
  // 上次开口没人接:底噪打折(不是惩罚,只是「说了也没人接」这件事本身的重量)。
208
206
  const spoke = lastSpokeAt(events)
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
@@ -193,6 +193,9 @@ export async function rememberGroupWord(root, o = {}) {
193
193
  type: 'heard',
194
194
  text: sentence,
195
195
  scene: 'group',
196
+ // 这句话是谁说的(1.0.8,认识人 S1,2026-11-22)。
197
+ // 群聊里原来只有「有人在说」,没有「谁在说」——一句原话因此谁也挂不上。
198
+ ...(o.who && (o.who.id || o.who.name) ? { who: { id: String(o.who.id ?? ''), name: String(o.who.name ?? '') } } : {}),
196
199
  ...(o.sessionId ? { sessionId: String(o.sessionId) } : {}),
197
200
  },
198
201
  { day: Number(o.day ?? 0), stage: Number(o.stage ?? 1), source: 'system' },
@@ -205,6 +208,73 @@ export async function rememberGroupWord(root, o = {}) {
205
208
  }
206
209
  }
207
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
+
208
278
  export async function hearTurn(root, o = {}) {
209
279
  const log = o.log ?? (() => {})
210
280
  const every = Number(o.config?.memory?.hearEvery ?? HEAR_EVERY)
package/lib/home.js CHANGED
@@ -30,6 +30,7 @@ import { TALK_KEEP } from './talkmem.js'
30
30
  import { armHandoff, buildHandoff } from './handoff.js'
31
31
  import { freshWakeText } from './wakeconst.js'
32
32
  import { dateKey, loadConfig } from './settings.js'
33
+ import { asHerSession, rememberHerSession } from './restrict.js'
33
34
 
34
35
  const TITLE_WORKSPACE = '大肥鱼的家'
35
36
  const TITLE_SESSION = '跟大肥鱼说话'
@@ -294,20 +295,28 @@ async function adoptLiveSession(root, saved, { wsId, sessionId, title }) {
294
295
  * 聊满轮数换一间(rotateTalkSessionOnce)。2026-11-19 外部用户反馈:换房那条路
295
296
  * 根本没传 preset,新房间就照宿主的默认走;那位用户的默认是「PTC 极简」,
296
297
  * 换完房她只剩几件工具。两条路必须同一个口径。
298
+ *
299
+ * 2026-11-22:这里也是**认领「她是她」的窗口**。宿主的 create 在返回前就同步发出
300
+ * `agent/created`,那一刻新 id 还拿不到;`asHerSession` 把这几毫秒圈起来,
301
+ * 让身份守卫在窗口里按 cwd 认领,拿到返回值后再按 id 补一笔(`rememberHerSession`)。
297
302
  */
298
- async function createTalkSession(sc, { workspaceId, preset = '', log } = {}) {
303
+ async function createTalkSession(sc, { workspaceId, preset = '', log, herDir = '' } = {}) {
299
304
  const want = String(preset ?? '').trim()
300
305
  if (want) {
301
306
  try {
302
- const created = await sc.create({ workspaceId, agentPreset: want })
303
- return { sessionId: String(created?.sessionId ?? created?.id ?? ''), preset: want }
307
+ const created = await asHerSession(herDir, () => sc.create({ workspaceId, agentPreset: want }))
308
+ const sessionId = String(created?.sessionId ?? created?.id ?? '')
309
+ rememberHerSession(sessionId, herDir)
310
+ return { sessionId, preset: want }
304
311
  } catch (err) {
305
312
  const why = String(err?.message ?? err).slice(0, 160)
306
313
  log?.(`受限 preset「${want}」没被接受(${why}),这次用默认组合建会话`)
307
314
  }
308
315
  }
309
- const created = await sc.create({ workspaceId })
310
- return { sessionId: String(created?.sessionId ?? created?.id ?? ''), preset: '' }
316
+ const created = await asHerSession(herDir, () => sc.create({ workspaceId }))
317
+ const sessionId = String(created?.sessionId ?? created?.id ?? '')
318
+ rememberHerSession(sessionId, herDir)
319
+ return { sessionId, preset: '' }
311
320
  }
312
321
 
313
322
  async function ensureTalkSessionOnce(ctx, { root = rootDir(), wsId, title = TITLE_SESSION, preset = '', log, force = false } = {}) {
@@ -438,7 +447,7 @@ async function ensureTalkSessionOnce(ctx, { root = rootDir(), wsId, title = TITL
438
447
  // preset 不被接受(老宿主 / 没装)时回落默认组合,但**必须让调用方知道**,
439
448
  // 否则她会在「全套工具」下悄悄长大 —— 这是自检里「她的工具面」要报的。
440
449
  try {
441
- const room = await createTalkSession(sc, { workspaceId: wsId, preset, log })
450
+ const room = await createTalkSession(sc, { workspaceId: wsId, preset, log, herDir: paths(root).herDir })
442
451
  const sessionId = room.sessionId
443
452
  const presetUsed = room.preset
444
453
  if (!sessionId) return { ok: false, why: '宿主建了会话但没给 id' }
@@ -446,7 +455,18 @@ async function ensureTalkSessionOnce(ctx, { root = rootDir(), wsId, title = TITL
446
455
  // 命名失败不影响功能:侧栏会显示默认标题,但会话本身是好的
447
456
  await sc.rename({ sessionId, title }).catch(() => {})
448
457
  }
449
- await writeAtomic(homeFile(root), JSON.stringify({ wsId, sessionId, title, preset: presetUsed, pressureRoomLinks: saved?.pressureRoomLinks, pressureRoomIds: [...new Set([...(saved?.pressureRoomIds ?? []), sessionId])], createdAt: new Date().toISOString() }, null, 2))
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?.('旧会话接不上了,新房间先留一页交接,等第一句话时摆出来')
450
470
  return { ok: true, sessionId, reused: false, preset: presetUsed }
451
471
  } catch (err) {
452
472
  return { ok: false, why: `建会话失败:${String(err?.message ?? err).slice(0, 160)}` }
@@ -1002,7 +1022,7 @@ async function rotateTalkSessionOnce(ctx, { root = rootDir(), wsId, title = TITL
1002
1022
  let sessionId = ''
1003
1023
  let presetUsed = ''
1004
1024
  try {
1005
- const room = await createTalkSession(sc, { workspaceId: wid, preset, log })
1025
+ const room = await createTalkSession(sc, { workspaceId: wid, preset, log, herDir: paths(root).herDir })
1006
1026
  sessionId = room.sessionId
1007
1027
  presetUsed = room.preset
1008
1028
  } catch (err) {
@@ -1180,31 +1200,35 @@ export async function verifyWoke(ctx, { root = '', sessionId = '', log, delayMs
1180
1200
  * 认回来是这里唯一说得通的做法:她住在哪条会话,应当以**人实际在哪条里说话**为准。
1181
1201
  * 反过来硬把新会话塞给他是做不到的(宿主不允许插件改 current)。
1182
1202
  *
1183
- * 三件事要一起做:
1203
+ * 两件事要一起做:
1184
1204
  * - 清掉 `rotatedFrom`:已经认回来了,它不再是「换下来那条」;
1185
- * - 清掉 `carry`:那段「上次说到这」本来就从这条会话里取的,再贴一遍等于重复;
1186
1205
  * - 不碰 `turns`:轮数接着数,不因为他落回旧窗口就白送一段。
1206
+ * `carry` 留着(2026-11-22,issue #171):轮换时那段「上次说到这」是给
1207
+ * **`rotatedTo` 那间新房**准备的;他先回旧窗口不代表不搬了,等真搬过去
1208
+ * 还得摆一次。页的开关在 armHandoffFor 里按 rotatedTo 认房,所以留在旧窗口
1209
+ * 不会冒出来(identity 段只在 armed 时才读它)。
1187
1210
  * 失败只返回 false,下次说话再认一次。
1188
1211
  *
1189
1212
  * 2026-11-13(外部反馈:轮换后「家」停在旧会话,自动醒落回旧对话):
1190
- * 搬进的是**轮换建出来的那间**(`rotatedTo`)时上面三件事一条都不做——
1191
- * 那段 carry 本来就是给它准备的;`rotatedFrom` / `rotatedTo` 也留着,
1192
- * 他要是再回旧窗口,这一对还在,屋子能跟着人再搬一次。
1213
+ * 搬进的是**轮换建出来的那间**(`rotatedTo`)时上面两件事一条都不做——
1214
+ * `rotatedFrom` / `rotatedTo` 也留着,他要是再回旧窗口,这一对还在,
1215
+ * 屋子能跟着人再搬一次。
1193
1216
  */
1194
1217
  export async function adoptTalkSession(root = rootDir(), sessionId = '') {
1195
1218
  const sid = String(sessionId ?? '')
1196
1219
  if (!sid) return false
1220
+ // 认回来的这条从此就是她的家:先记进身份台账,宿主晚一步发 agent/created
1221
+ // 也能按 id 认出来(2026-11-22,与 createTalkSession 的认领同一套判据)。
1222
+ rememberHerSession(sid, paths(root).herDir)
1197
1223
  try {
1198
1224
  return await mutateHome(async () => {
1199
1225
  const saved = (await readJson(homeFile(root), null)) ?? {}
1200
1226
  if (String(saved.sessionId ?? '') === sid) return true
1201
1227
  const next = { ...saved, sessionId: sid, adoptedAt: new Date().toISOString() }
1202
1228
  // 搬进的是轮换新开的那间:carry 是给它准备的,留着。
1203
- // 其余情况(认回旧窗口):它已经不是「换下来那条」,carry 也不该再粘一遍。
1204
- if (String(saved.rotatedTo ?? '') !== sid) {
1205
- delete next.rotatedFrom
1206
- delete next.carry
1207
- }
1229
+ // 认回旧窗口:carry 也留着,但把 rotatedFrom 清掉——他可能随后才搬进
1230
+ // rotatedTo 那间,到那时 armHandoffFor 才摆页(issue #171)。
1231
+ if (String(saved.rotatedTo ?? '') !== sid) delete next.rotatedFrom
1208
1232
  delete next.status
1209
1233
  delete next.archivedAt
1210
1234
  await writeAtomic(homeFile(root), JSON.stringify(next, null, 2))
@@ -1258,8 +1282,10 @@ export async function activeCarry(root = rootDir(), now = Date.now()) {
1258
1282
  * 身份文档里的一段常驻文字(那是旧 carry 的做法),而是一页只在特定一步
1259
1283
  * 生效的东西:
1260
1284
  * 1. home.json 指的**就是**他正在说话的这条会话(不是别的房间);
1261
- * 2. 屏幕上还留着他换窗口前那一段(carry 非空;换完、他说完第一轮就清掉);
1262
- * 3. 这一轮是他开口的(叫醒那一轮不算——新房间还没见到人,先别自念)。
1285
+ * 2. 这条会话就是轮换建出来的那间(`rotatedTo`);认回旧窗口时 carry 还留着,
1286
+ * 但页不该在旧窗口摆(2026-11-22,issue #171);
1287
+ * 3. 屏幕上还留着他换窗口前那一段(carry 非空;换完、他说完第一轮就清掉);
1288
+ * 4. 这一轮是他开口的(叫醒那一轮不算——新房间还没见到人,先别自念)。
1263
1289
  *
1264
1290
  * 只要当前这一条会话对不上,就不打开:认回旧窗口、群里、别的 workspace
1265
1291
  * 都不该突然冒出一页「上次停在这」。
@@ -1270,6 +1296,8 @@ export async function armHandoffFor(root = rootDir(), sessionId = '') {
1270
1296
  try {
1271
1297
  const saved = (await readJson(homeFile(root), null)) ?? {}
1272
1298
  if (String(saved.sessionId ?? '') !== sid) return false
1299
+ const rotatedTo = String(saved.rotatedTo ?? '')
1300
+ if (rotatedTo && rotatedTo !== sid) return false
1273
1301
  if (!String(saved.carry ?? '').trim()) return false
1274
1302
  armHandoff(sid)
1275
1303
  return true
package/lib/identity.js CHANGED
@@ -29,13 +29,14 @@ 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'
35
36
  import { attachStreamScrub } from './scrub.js'
36
37
  import { deliverQueued } from './sessionnote.js'
37
38
  import { handoffArmed, handoffTextSync, markHandoffShown } from './handoff.js'
38
- import { cueFor } from './cue.js'
39
+ import { flashFor } from './cue.js'
39
40
 
40
41
  /** 段名与顺序:放在宿主自己的段之后、`complete` 段之前(order 越大越靠后)。 */
41
42
  export const IDENTITY_SECTION = 'fish:identity'
@@ -1221,7 +1222,7 @@ export function attachIdentity(agent, root, { frozen = '', herDir = '', log } =
1221
1222
  remember(agent, 'section', sp.section({
1222
1223
  name: CUE_SECTION,
1223
1224
  order: CUE_ORDER,
1224
- text: () => fillOwner(cueFor(wakeSid, { root }), pronounFor(root)),
1225
+ text: () => fillOwner(flashFor(wakeSid, { root }), pronounFor(root)),
1225
1226
  }))
1226
1227
  // 「本子上记着什么」目录段:排在 cue 之前(cue 才是最后一段)。
1227
1228
  // 平时没什么可报(便条/约定都空)就是空串,等于这一段不存在。
@@ -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
  }