@ssamurias/dsh-fish 1.0.9 → 1.1.1
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 +9 -5
- package/CHANGELOG.md +4453 -4366
- package/README.md +29 -4
- package/RELEASE-NOTES-1.1.0.md +55 -0
- package/RELEASE-NOTES-1.1.1.md +61 -0
- package/docs/troubleshooting.md +4 -4
- package/docs//350/256/244/344/272/272/345/210/244/346/215/256.md +19 -5
- package/lib/autobackup.js +4 -0
- package/lib/bridgeclaim.js +138 -0
- package/lib/claim.js +118 -11
- package/lib/client/00-shell.js +130 -0
- package/lib/client/01-state-load.js +48 -7
- package/lib/client/05-pressure-charts.js +1 -1
- package/lib/client/06-tab-status-grow.js +12 -1
- package/lib/client/07-tab-home-bili.js +82 -14
- package/lib/client/08-tab-memory-plugins.js +24 -1
- package/lib/client/09-tab-outing.js +1 -1
- package/lib/client/11-tab-data-frame.js +111 -21
- package/lib/client.js +409 -46
- package/lib/derive.js +92 -30
- package/lib/events.js +5 -2
- package/lib/guess.js +29 -0
- package/lib/health.js +20 -1
- package/lib/herpeople.js +159 -0
- package/lib/history.js +27 -5
- package/lib/identity.js +38 -20
- package/lib/index.js +16 -5
- package/lib/look.js +1 -1
- package/lib/observe-bili.js +5 -2
- package/lib/observe-home.js +59 -3
- package/lib/observe-state.js +1 -1
- package/lib/observe.js +8 -2
- package/lib/people.js +514 -0
- package/lib/peopledoc.js +112 -0
- package/lib/persona.js +211 -55
- package/lib/proactive.js +11 -0
- package/lib/restrict.js +109 -18
- package/lib/say.js +24 -2
- package/lib/schedules.js +97 -0
- package/lib/selfdoc.js +19 -2
- package/lib/settings.js +28 -4
- package/lib/stance.js +7 -1
- package/lib/sub.js +1 -1
- package/lib/tenant.js +54 -9
- package/lib/types.d.ts +4 -0
- package/lib/use.js +3 -3
- package/lib/watch.js +1 -1
- package/lib/wiki.js +96 -17
- package/package.json +1 -1
- package/scripts/build-client.mjs +15 -1
- package/tools/check-install.mjs +64 -23
package/lib/index.js
CHANGED
|
@@ -21,6 +21,8 @@ import { registerLook } from './look.js'
|
|
|
21
21
|
import { registerSpeak, speakOn } from './speak.js'
|
|
22
22
|
import { registerRecall } from './recall.js'
|
|
23
23
|
import { registerHerDiary } from './herdiary.js'
|
|
24
|
+
// 1.1.0(S3-c):翻她认识的人。形状照 herdiary——只读、参数不是路径、一次一份。
|
|
25
|
+
import { registerHerPeople } from './herpeople.js'
|
|
24
26
|
// 2026-11-18(用户 m01161):立场是自动长出来的,她得能核对来源、也能整条撤掉。
|
|
25
27
|
import { registerHerStance } from './stance.js'
|
|
26
28
|
import { registerWatch } from './watch.js'
|
|
@@ -46,7 +48,7 @@ import { writeSelfDoc } from './selfdoc.js'
|
|
|
46
48
|
import { claimRoot, beatRootState, releaseRoot, HEARTBEAT_MS } from './tenant.js'
|
|
47
49
|
import { rootMovedAway } from './move.js'
|
|
48
50
|
import { setRiskLog } from './bili.js'
|
|
49
|
-
import { registerToolRestrict, seedHerSessions } from './restrict.js'
|
|
51
|
+
import { registerToolRestrict, seedHerSessions, isHerSessionId } from './restrict.js'
|
|
50
52
|
// `clearWakeSection` 在 dispose 里用:它挂在 system prompt 段上,是个模块级变量,
|
|
51
53
|
// 停用时不清的话下次启用会带着上一次的残留(2026-10-25)。
|
|
52
54
|
import { clearWakeSection, registerIdentity } from './identity.js'
|
|
@@ -63,7 +65,7 @@ export const name = 'dsh-fish'
|
|
|
63
65
|
* 版本号,必须和 package.json 的 version 一样(test/boot.test.mjs 盯着)。
|
|
64
66
|
* 不只是日志:升级自检和设置页的「检查更新」拿它当「正在跑的版本」。
|
|
65
67
|
*/
|
|
66
|
-
export const VERSION = '1.
|
|
68
|
+
export const VERSION = '1.1.1'
|
|
67
69
|
|
|
68
70
|
// ⚠️ 一个数组写全,不要拆成对象
|
|
69
71
|
// 2026-10-30(m02961):`userQuestions` **不再写进 inject**。写进 inject 的东西缺一个,
|
|
@@ -96,7 +98,10 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
96
98
|
// 多租户(2026-10-28 m01319):这个对象是「这个实例认哪个家、它还是不是房主」的唯一真相,
|
|
97
99
|
// 工具注册时按引用传下去 —— boot 之后填进来,工具执行时现读,不做拷贝。
|
|
98
100
|
/** @type {import('./types.js').TenancyBag & { root: string, herDir: string, tenant: { ok: boolean, instanceId?: string, why?: string, owner?: any } }} */
|
|
99
|
-
const tenancy = { root, herDir: '', tenant: { ok: true, instanceId: '', why: '' } }
|
|
101
|
+
const tenancy = { root, herDir: '', tenant: { ok: true, instanceId: '', why: '' }, ctx }
|
|
102
|
+
// 她是谁按会话 id 认,不按目录(2026-11-24 issue #179):她换过工作目录之后,
|
|
103
|
+
// 写入口仍要把字写回她自己的家,而不是因为「此刻站在别处」把笔收走。
|
|
104
|
+
tenancy.isHerSession = (sessionId) => isHerSessionId(sessionId, tenancy.herDir)
|
|
100
105
|
// 升级自检(2026-10-29):`file:` 装的人常常只换了源目录,跑的还是 node_modules 里的旧副本。
|
|
101
106
|
// 这里只读不写;查不到就写 skipped,不影响启动。
|
|
102
107
|
/** @type {{ upgrade: Record<string, any>, host: Record<string, any> }} */
|
|
@@ -157,7 +162,7 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
157
162
|
install.upgrade = await checkUpgrade({ version: VERSION })
|
|
158
163
|
if (install.upgrade.stale === true) {
|
|
159
164
|
const u = install.upgrade
|
|
160
|
-
logger.warn(`[dsh-fish] ${u.why}。改的是源目录,装进去的是另一份——要么 pnpm install --force,要么删掉 node_modules\\dsh-fish
|
|
165
|
+
logger.warn(`[dsh-fish] ${u.why}。改的是源目录,装进去的是另一份——要么 pnpm install --force,要么删掉 node_modules\\@ssamurias\\dsh-fish 再启动(0.8.9 之前装的在 node_modules\\dsh-fish)。`)
|
|
161
166
|
}
|
|
162
167
|
} catch (err) {
|
|
163
168
|
install.upgrade = { ...install.upgrade, skipped: true, why: String(err?.message ?? err).slice(0, 120) }
|
|
@@ -316,8 +321,10 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
316
321
|
try { seedHerSessions(root) } catch { /* 台账读坏了等于没读,退化成旧判据 */ }
|
|
317
322
|
try {
|
|
318
323
|
const off = registerToolRestrict(ctx, /** @type {any} */ ({
|
|
324
|
+
root,
|
|
319
325
|
herDir,
|
|
320
326
|
extra: config?.tools?.allow ?? [],
|
|
327
|
+
bridgeDirs: config?.bridge?.dirs ?? [],
|
|
321
328
|
enabled: config?.tools?.restrict !== false,
|
|
322
329
|
// 0.9.0 起公开:梦默认开。issue #64:关掉「允许她记梦」时
|
|
323
330
|
// 工具面也要跟着收——否则身份文档说她有、伸手却是空的。
|
|
@@ -344,7 +351,7 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
344
351
|
}
|
|
345
352
|
if (stopped) return
|
|
346
353
|
try {
|
|
347
|
-
const off = registerIdentity(ctx, { root, herDir, log: plog })
|
|
354
|
+
const off = registerIdentity(ctx, { root, herDir, log: plog, bridgeDirs: config?.bridge?.dirs ?? [] })
|
|
348
355
|
if (typeof off === 'function') disposers.push(off)
|
|
349
356
|
} catch (err) {
|
|
350
357
|
logger.warn('[dsh-fish] 身份段没挂上', err?.message ?? err)
|
|
@@ -455,6 +462,9 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
455
462
|
() => registerRecall(ctx, { root }),
|
|
456
463
|
// issue #7:日记不进事件流,所以她需要一个只读的窗口回头翻(her_diary)。
|
|
457
464
|
() => registerHerDiary(ctx, { root }),
|
|
465
|
+
// 1.1.0(S3-c):她认识的人也不进身份文档的全部(那一段只摆三个人一行),
|
|
466
|
+
// 想细看谁自己翻。只读,不收路径。
|
|
467
|
+
() => registerHerPeople(ctx, { root }),
|
|
458
468
|
// 2026-11-18(用户 m01161):清单上每条立场由哪几次长出来、编号是什么,
|
|
459
469
|
// 只读给她看;撤销仍走她已有的 growth_commit(revise + refs 多条)。
|
|
460
470
|
() => registerHerStance(ctx, { root }),
|
|
@@ -588,3 +598,4 @@ export function apply(ctx, baseConfig = {}) {
|
|
|
588
598
|
},
|
|
589
599
|
}
|
|
590
600
|
}
|
|
601
|
+
|
package/lib/look.js
CHANGED
|
@@ -348,7 +348,7 @@ async function resolveWanted(client, o) {
|
|
|
348
348
|
*/
|
|
349
349
|
function tenancyOf(root, tenancy) {
|
|
350
350
|
if (tenancy && typeof tenancy === 'object') {
|
|
351
|
-
return { root, herDir: String(tenancy.herDir ?? ''), tenant: tenancy.tenant ?? { ok: true } }
|
|
351
|
+
return { root, herDir: String(tenancy.herDir ?? ''), tenant: tenancy.tenant ?? { ok: true }, ctx: tenancy.ctx }
|
|
352
352
|
}
|
|
353
353
|
return { root, herDir: '', tenant: { ok: true } }
|
|
354
354
|
}
|
package/lib/observe-bili.js
CHANGED
|
@@ -237,10 +237,13 @@ export function buildBiliRoutes(env) {
|
|
|
237
237
|
['/history', async (req, res) => {
|
|
238
238
|
const url = new URL(req.url ?? '/', 'http://x')
|
|
239
239
|
const days = Math.max(1, Math.min(366, Number(url.searchParams.get('days')) || 14))
|
|
240
|
+
// 搜索词在这边筛(2026-11-24,用户 m02329):365 天全量最多约七万条,
|
|
241
|
+
// 先整段发到浏览器再让前端过滤是白烧带宽;截 80 字防止有人拿它当注入口。
|
|
242
|
+
const q = String(url.searchParams.get('q') ?? '').trim().slice(0, 80)
|
|
240
243
|
const { events } = await readEvents(root)
|
|
241
|
-
const groups = historyFromEvents(events, { days })
|
|
244
|
+
const groups = historyFromEvents(events, { days, q })
|
|
242
245
|
const total = groups.reduce((a, g) => a + g.items.length, 0)
|
|
243
|
-
send(res, 200, { days, total, groups })
|
|
246
|
+
send(res, 200, { days, q, total, groups })
|
|
244
247
|
}],
|
|
245
248
|
|
|
246
249
|
['/away', async (_req, res) => {
|
package/lib/observe-home.js
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
|
|
10
10
|
import fs from 'node:fs'
|
|
11
11
|
import { join } from 'node:path'
|
|
12
|
+
import { timingSafeEqual } from 'node:crypto'
|
|
12
13
|
import { fileURLToPath } from 'node:url'
|
|
13
14
|
import { readEvents, paths } from './store.js'
|
|
15
|
+
import { claimBridgeSession, releaseBridgeSession } from './bridgeclaim.js'
|
|
14
16
|
import { loadConfig, updateConfig, dateKey } from './settings.js'
|
|
15
17
|
import { selfPronounOf, fillSelf } from './selfpronoun.js'
|
|
16
18
|
import { deriveSelf } from './derive.js'
|
|
@@ -65,6 +67,7 @@ export function createBridgeHandlers(env) {
|
|
|
65
67
|
scene: body.scene,
|
|
66
68
|
channel: body.channel,
|
|
67
69
|
speaker: body.speaker,
|
|
70
|
+
speakerId: body.speakerId,
|
|
68
71
|
room: body.room,
|
|
69
72
|
title: body.title,
|
|
70
73
|
guest: body.guest,
|
|
@@ -94,17 +97,66 @@ export function createBridgeHandlers(env) {
|
|
|
94
97
|
})
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
|
|
100
|
+
const tokenOk = (req, want) => {
|
|
101
|
+
if (!want) return false
|
|
102
|
+
const got = String(req?.headers?.['x-fish-token'] ?? '')
|
|
103
|
+
if (!got || got.length !== want.length) return false
|
|
104
|
+
try { return timingSafeEqual(Buffer.from(got), Buffer.from(want)) } catch { return false }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** 认领口与 /say 共用 token;配置没开、没配 token 都当不存在。 */
|
|
108
|
+
const claimGate = async () => {
|
|
109
|
+
const { config } = await loadConfig(root)
|
|
110
|
+
const b = config?.bridge ?? {}
|
|
111
|
+
if (!b.claim) return { code: 'disabled', status: 404, error: '认领口没开' }
|
|
112
|
+
if (!b.token) return { code: 'no_token', status: 503, error: '没有配置 bridge.token,认领口不接客' }
|
|
113
|
+
return { token: String(b.token) }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const claimHandler = async (req, res) => {
|
|
117
|
+
if (req.method !== 'POST') return send(res, 405, { error: 'method not allowed' })
|
|
118
|
+
const gate = await claimGate()
|
|
119
|
+
if (gate.code) return send(res, gate.status, { ok: false, code: gate.code, error: gate.error })
|
|
120
|
+
if (!tokenOk(req, gate.token)) return send(res, 401, { ok: false, code: 'bad_token', error: 'token 不对' })
|
|
121
|
+
const raw = await readBody(req, 20_000)
|
|
122
|
+
/** @type {Record<string, any>} */
|
|
123
|
+
let body = {}
|
|
124
|
+
try { body = JSON.parse(raw || '{}') } catch { return send(res, 400, { ok: false, code: 'bad_body', error: 'body 不是 JSON' }) }
|
|
125
|
+
const r = claimBridgeSession({
|
|
126
|
+
root,
|
|
127
|
+
sessionId: body?.sessionId,
|
|
128
|
+
herDir: paths(root).herDir,
|
|
129
|
+
log: flog('warn'),
|
|
130
|
+
})
|
|
131
|
+
const status = r.ok ? 200 : r.code === 'unknown_session' ? 400 : 409
|
|
132
|
+
return send(res, status, { ...r, error: r.ok ? undefined : (r.why ?? r.code) })
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const releaseHandler = async (req, res) => {
|
|
136
|
+
if (req.method !== 'POST') return send(res, 405, { error: 'method not allowed' })
|
|
137
|
+
const gate = await claimGate()
|
|
138
|
+
if (gate.code) return send(res, gate.status, { ok: false, code: gate.code, error: gate.error })
|
|
139
|
+
if (!tokenOk(req, gate.token)) return send(res, 401, { ok: false, code: 'bad_token', error: 'token 不对' })
|
|
140
|
+
const raw = await readBody(req, 20_000)
|
|
141
|
+
/** @type {Record<string, any>} */
|
|
142
|
+
let body = {}
|
|
143
|
+
try { body = JSON.parse(raw || '{}') } catch { return send(res, 400, { ok: false, code: 'bad_body', error: 'body 不是 JSON' }) }
|
|
144
|
+
const r = await releaseBridgeSession({ root, sessionId: body?.sessionId, herDir: paths(root).herDir })
|
|
145
|
+
const status = r.ok ? 200 : r.code === 'unknown_session' ? 404 : 409
|
|
146
|
+
return send(res, status, { ...r, error: r.ok ? undefined : (r.why ?? r.code) })
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return { sayHandler, whoamiHandler, claimHandler, releaseHandler }
|
|
98
150
|
}
|
|
99
151
|
|
|
100
152
|
/**
|
|
101
153
|
* @param {import('./types.js').ObserveEnv} env
|
|
102
|
-
* @param {{ sayHandler: import('./types.js').ObserveHandler, whoamiHandler: import('./types.js').ObserveHandler }} bridgeHandlers
|
|
154
|
+
* @param {{ sayHandler: import('./types.js').ObserveHandler, whoamiHandler: import('./types.js').ObserveHandler, claimHandler: import('./types.js').ObserveHandler, releaseHandler: import('./types.js').ObserveHandler }} bridgeHandlers
|
|
103
155
|
* @returns {import('./types.js').ObserveRouteEntry[]}
|
|
104
156
|
*/
|
|
105
157
|
export function buildHomeRoutes(env, bridgeHandlers) {
|
|
106
158
|
const { ctx, root, flog, inflight, awayFromBeat, reclaimTenant } = env
|
|
107
|
-
const { sayHandler, whoamiHandler } = bridgeHandlers
|
|
159
|
+
const { sayHandler, whoamiHandler, claimHandler, releaseHandler } = bridgeHandlers
|
|
108
160
|
|
|
109
161
|
return [
|
|
110
162
|
['/wake', async (req, res) => {
|
|
@@ -117,6 +169,8 @@ export function buildHomeRoutes(env, bridgeHandlers) {
|
|
|
117
169
|
|
|
118
170
|
['/say', sayHandler],
|
|
119
171
|
['/whoami', whoamiHandler],
|
|
172
|
+
['/claim', claimHandler],
|
|
173
|
+
['/release', releaseHandler],
|
|
120
174
|
|
|
121
175
|
['/inbox', async (req, res) => {
|
|
122
176
|
if (req.method === 'POST') {
|
|
@@ -381,3 +435,5 @@ export function buildHomeRoutes(env, bridgeHandlers) {
|
|
|
381
435
|
}],
|
|
382
436
|
]
|
|
383
437
|
}
|
|
438
|
+
|
|
439
|
+
|
package/lib/observe-state.js
CHANGED
|
@@ -302,7 +302,7 @@ export function buildStateRoutes(env) {
|
|
|
302
302
|
const model = deriveSelf(events, { growthDays: config.growthDays })
|
|
303
303
|
const doc = await selfDocStatus(root)
|
|
304
304
|
const h = await homeStatus(root)
|
|
305
|
-
const budget = Number(config?.memory?.docBudget ??
|
|
305
|
+
const budget = Number(config?.memory?.docBudget ?? 3600)
|
|
306
306
|
const shownCap = shownCount(config?.memory?.beliefsShown ?? BELIEF_SHOWN)
|
|
307
307
|
const pb = personaBudget(model, { budget, withBans: model?.persona?.imported !== true, shown: shownCap, sleepKeep: config?.memory?.sleepKeep })
|
|
308
308
|
const diary = await listDiary(root).catch(() => [])
|
package/lib/observe.js
CHANGED
|
@@ -114,7 +114,7 @@ export function registerObserve(ctx, deps = {}) {
|
|
|
114
114
|
disposers.push(pressure.dispose)
|
|
115
115
|
|
|
116
116
|
let bridgePortLive = 0
|
|
117
|
-
/** @type {{ sayHandler: import('./types.js').ObserveHandler, whoamiHandler: import('./types.js').ObserveHandler } | null} */
|
|
117
|
+
/** @type {{ sayHandler: import('./types.js').ObserveHandler, whoamiHandler: import('./types.js').ObserveHandler, claimHandler: import('./types.js').ObserveHandler, releaseHandler: import('./types.js').ObserveHandler } | null} */
|
|
118
118
|
let bridgeHandlers = null
|
|
119
119
|
|
|
120
120
|
/**
|
|
@@ -135,7 +135,12 @@ export function registerObserve(ctx, deps = {}) {
|
|
|
135
135
|
try { closeBridgeServer() } catch { /* 没起过 */ }
|
|
136
136
|
const st = startBridgeServer({
|
|
137
137
|
port,
|
|
138
|
-
handlers: {
|
|
138
|
+
handlers: {
|
|
139
|
+
'/say': bridgeHandlers.sayHandler,
|
|
140
|
+
'/whoami': bridgeHandlers.whoamiHandler,
|
|
141
|
+
'/claim': bridgeHandlers.claimHandler,
|
|
142
|
+
'/release': bridgeHandlers.releaseHandler,
|
|
143
|
+
},
|
|
139
144
|
log: (/** @type {unknown[]} */ ...a) => logLine('warn', ['桥接投递口:', ...a.map((x) => String(x))], root),
|
|
140
145
|
})
|
|
141
146
|
bridgePortLive = port
|
|
@@ -215,3 +220,4 @@ export function registerObserve(ctx, deps = {}) {
|
|
|
215
220
|
},
|
|
216
221
|
}
|
|
217
222
|
}
|
|
223
|
+
|