@ssamurias/dsh-fish 1.1.4 → 1.1.5
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 +3 -2
- package/CHANGELOG.md +40 -1
- package/README.md +28 -122
- package/RELEASE-NOTES-1.1.5.md +49 -0
- package/lib/becoming.js +70 -0
- package/lib/client/01-state-load.js +6 -0
- package/lib/client/11-tab-data-frame.js +57 -0
- package/lib/client.js +63 -0
- package/lib/decisions.js +207 -0
- package/lib/derive.js +99 -8
- package/lib/guard.js +75 -9
- package/lib/herpeople.js +1 -1
- package/lib/index.js +1 -1
- package/lib/observe-data.js +16 -0
- package/lib/people.js +20 -11
- package/lib/peopledoc.js +1 -1
- package/lib/persona.js +15 -0
- package/lib/recall.js +34 -1
- package/lib/say.js +41 -3
- package/lib/scheduler.js +37 -3
- package/lib/speak.js +10 -5
- package/lib/turns.js +40 -1
- package/lib/wiki.js +3 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -986,6 +986,10 @@ window.__ModuleLoader__.load({
|
|
|
986
986
|
const [note, setNote] = useState('')
|
|
987
987
|
// 设置界面重做(2026-10-23):当前页 + 新增的几个环境项
|
|
988
988
|
const [tab, setTab] = useState('now')
|
|
989
|
+
// 判决账(2026-11-29,用户 m00311):只读,和运行日志分开一张卡,不混在一起。
|
|
990
|
+
// 放在 tab 之后:client.test.mjs 按下标找 tab,不能再往它前面加 state。
|
|
991
|
+
const [decisions, setDecisions] = useState(null)
|
|
992
|
+
const [decisionsBusy, setDecisionsBusy] = useState(false)
|
|
989
993
|
const [pressure, setPressure] = useState(null)
|
|
990
994
|
const [structureExperiment, setStructureExperiment] = useState({})
|
|
991
995
|
const [requestExperiment, setRequestExperiment] = useState({})
|
|
@@ -1681,6 +1685,8 @@ window.__ModuleLoader__.load({
|
|
|
1681
1685
|
jget('/rules').then(setRules).catch(() => {})
|
|
1682
1686
|
// 运行日志:失败就当没这回事(日志本身坏了不该拖垮设置页)
|
|
1683
1687
|
jget('/log?lines=40').then(setLogTail).catch(() => {})
|
|
1688
|
+
// 判决账:只读聚合,失败就当这栏还没账(不影响其它卡片)。
|
|
1689
|
+
jget('/decisions?days=7').then(setDecisions).catch(() => {})
|
|
1684
1690
|
// 她的东西(1.0.4):只读清单,失败就当这栏还没东西。
|
|
1685
1691
|
jget('/works?limit=30').then(setWorks).catch(() => {})
|
|
1686
1692
|
// 报告:先拿日期列表,再取最新那天的正文(失败不影响其它卡片)
|
|
@@ -8118,6 +8124,14 @@ window.__ModuleLoader__.load({
|
|
|
8118
8124
|
showReport && reports.md ? h('pre', { style: { marginTop: '8px', maxHeight: '320px', overflow: 'auto' } }, reports.md) : null)
|
|
8119
8125
|
}
|
|
8120
8126
|
|
|
8127
|
+
// 判决账里的时间:给人看的短格式(月-日 时:分),坏时间就给空。
|
|
8128
|
+
const decisionWhen = (iso) => {
|
|
8129
|
+
const t = new Date(iso)
|
|
8130
|
+
if (Number.isNaN(t.getTime())) return ''
|
|
8131
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
8132
|
+
return `${p(t.getMonth() + 1)}-${p(t.getDate())} ${p(t.getHours())}:${p(t.getMinutes())}`
|
|
8133
|
+
}
|
|
8134
|
+
|
|
8121
8135
|
const dataPage = h('div', { className: 'page' },
|
|
8122
8136
|
group('数据在哪',
|
|
8123
8137
|
'一个文件夹装全部。想备份、想搬走、想看原始记录,都在这一格里。',
|
|
@@ -8361,6 +8375,55 @@ window.__ModuleLoader__.load({
|
|
|
8361
8375
|
}, '清空日志')),
|
|
8362
8376
|
h('p', { className: 'hint' }, S('导出的是纯文本:版本、自检结果、脱敏后的配置、日志末尾。没有 cookie,没有她说过的话。'))),
|
|
8363
8377
|
|
|
8378
|
+
// ---- 判决账(2026-11-29,用户 m00311)----
|
|
8379
|
+
// 单独一张卡:它回答的是「她为什么醒 / 为什么没醒」,不是「插件运行时报了什么错」。
|
|
8380
|
+
// 只读,不参与任何判定,也不进她的提示词。放在数据列,不和运行日志混。
|
|
8381
|
+
group('判决账',
|
|
8382
|
+
S('她每一次醒来、没醒,为什么,回没回。只记账,不参与她的判断,也不进她的提示词。'),
|
|
8383
|
+
!decisions
|
|
8384
|
+
? h('p', { className: 'empty' }, decisionsBusy ? '读取中…' : '还没读。')
|
|
8385
|
+
: h('div', null,
|
|
8386
|
+
h('p', { className: 'hint' },
|
|
8387
|
+
`近 ${decisions.days} 天一共 ${decisions.total} 条。`),
|
|
8388
|
+
decisions.groups?.length
|
|
8389
|
+
? h('div', { style: { marginTop: '8px' } },
|
|
8390
|
+
h('div', {
|
|
8391
|
+
className: 'row',
|
|
8392
|
+
style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary)', padding: '3px 0' },
|
|
8393
|
+
},
|
|
8394
|
+
h('span', { style: { flex: '1' } }, '原因'),
|
|
8395
|
+
h('span', { style: { width: '48px', textAlign: 'right' } }, '次数'),
|
|
8396
|
+
h('span', { style: { width: '40px', textAlign: 'right' } }, '醒'),
|
|
8397
|
+
h('span', { style: { width: '48px', textAlign: 'right' } }, '开口')),
|
|
8398
|
+
...decisions.groups.map((g) => h('div', {
|
|
8399
|
+
key: g.code,
|
|
8400
|
+
className: 'row',
|
|
8401
|
+
style: { padding: '3px 0', borderTop: '0.5px solid var(--dsw-alias-border-l2)' },
|
|
8402
|
+
},
|
|
8403
|
+
h('span', { style: { flex: '1' } }, g.label || g.code),
|
|
8404
|
+
h('span', { style: { width: '48px', textAlign: 'right' } }, String(g.count)),
|
|
8405
|
+
h('span', { style: { width: '40px', textAlign: 'right' } }, String(g.woke || 0)),
|
|
8406
|
+
h('span', { style: { width: '48px', textAlign: 'right' } }, String(g.replied || 0)))))
|
|
8407
|
+
: h('p', { className: 'empty' }, S('近七天还没有账。')),
|
|
8408
|
+
decisions.recent?.length
|
|
8409
|
+
? h('details', { style: { marginTop: '10px' } },
|
|
8410
|
+
h('summary', { style: { cursor: 'pointer', fontSize: '12px' } },
|
|
8411
|
+
`最近 ${Math.min(20, decisions.recent.length)} 条`),
|
|
8412
|
+
h('div', { style: { maxHeight: '180px', overflow: 'auto', marginTop: '6px' } },
|
|
8413
|
+
...decisions.recent.slice(0, 20).map((d, i) => h('p', {
|
|
8414
|
+
key: `${d.at || ''}-${i}`,
|
|
8415
|
+
className: 'hint',
|
|
8416
|
+
style: { margin: '2px 0' },
|
|
8417
|
+
}, `${decisionWhen(d.at)} ${d.woke ? (d.replied ? '开口' : '醒了没说') : '没醒'} ${d.why || ''}`))))
|
|
8418
|
+
: null),
|
|
8419
|
+
h('div', { className: 'row' },
|
|
8420
|
+
h('button', {
|
|
8421
|
+
onClick: () => {
|
|
8422
|
+
setDecisionsBusy(true)
|
|
8423
|
+
jget('/decisions?days=7').then(setDecisions).catch(() => {}).finally(() => setDecisionsBusy(false))
|
|
8424
|
+
},
|
|
8425
|
+
}, decisionsBusy ? '读取中…' : '刷新判决账'))),
|
|
8426
|
+
|
|
8364
8427
|
importCard,
|
|
8365
8428
|
|
|
8366
8429
|
// 宿主旧了(0.8.1):比升级自检更基础——先告诉它为什么有个功能没反应。
|
package/lib/decisions.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* decisions.js —— 判决账:这一轮为什么醒、回没回、叫没叫模型
|
|
4
|
+
*
|
|
5
|
+
* 为什么单独一份文件(2026-11-29,用户 m00311 批准):
|
|
6
|
+
* 她的记忆里只留下「结果」——说了什么、写了什么。可出问题时最常问的是
|
|
7
|
+
* **「这一轮为什么没醒 / 为什么没回」**。这句话在旧账里查不到:主动回合的
|
|
8
|
+
* skip 只写日志,日志轮转掉就没了;人类回合根本不记「谁把她叫醒」。
|
|
9
|
+
*
|
|
10
|
+
* 三条边界,先写在最前面:
|
|
11
|
+
* 1. **只记不用**。这份账不参与判醒、不参与回不回、不进她的提示词。
|
|
12
|
+
* 它只是给人看的行车记录仪。要拿它调参数,得先另开一轮讨论。
|
|
13
|
+
* 2. **不记原文**。不存他说的话、不存她说的话、不存会话 id。
|
|
14
|
+
* 只存时间、类型、醒/回、稳定原因码和一句人话原因。
|
|
15
|
+
* 3. **只追加**。一行一条,坏了就跳过那一行;不从这份账反推任何状态。
|
|
16
|
+
*
|
|
17
|
+
* 文件位置:`<root>/decisions.jsonl`。和 events.jsonl 分开,避免把
|
|
18
|
+
* 「系统为什么这么做」混进「她经历过什么」。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { promises as fs } from 'node:fs'
|
|
22
|
+
import { dirname, join } from 'node:path'
|
|
23
|
+
import { rootDir } from './store.js'
|
|
24
|
+
|
|
25
|
+
/** 判决类型:人类开口、接着上一轮、自己醒的一轮。 */
|
|
26
|
+
export const DECISION_KINDS = ['human', 'continuation', 'proactive']
|
|
27
|
+
|
|
28
|
+
/** 稳定原因码 → 数据页上的人话。改文案不改码;码是聚合与排查用的。 */
|
|
29
|
+
export const DECISION_LABELS = {
|
|
30
|
+
human: '他说话了',
|
|
31
|
+
continuation: '接着上一轮',
|
|
32
|
+
off: '主动性关着',
|
|
33
|
+
window: '不在醒着的时段',
|
|
34
|
+
away: '她不在家',
|
|
35
|
+
rest: '今天请了假',
|
|
36
|
+
cap: '今天的额度用完了',
|
|
37
|
+
cap_silent: '醒过太多次,都没落地',
|
|
38
|
+
retry: '上次没送出去,还在等',
|
|
39
|
+
silent_wait: '上次醒来没开口,还在等',
|
|
40
|
+
self_said: '她自己刚开过口',
|
|
41
|
+
talked: '刚说过话',
|
|
42
|
+
no_material: '桌上没有可说的东西',
|
|
43
|
+
no_new: '这半天没有新东西',
|
|
44
|
+
busy: '她正忙',
|
|
45
|
+
hot: '你还在说话',
|
|
46
|
+
deliver_fail: '这一拍没送进去',
|
|
47
|
+
silent: '醒着,但选择不说',
|
|
48
|
+
turn: '醒着,开口了',
|
|
49
|
+
tool: '醒着,做了件事但没说话',
|
|
50
|
+
other: '别的原因',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 把一句中文原因压成稳定码。
|
|
55
|
+
*
|
|
56
|
+
* 为什么不直接存中文:中文文案会改,聚合会跟着散。码不动,文案随便改。
|
|
57
|
+
* 匹配用「包含」而不是全等:`proactiveState` 的原因常带括号补充。
|
|
58
|
+
*
|
|
59
|
+
* @param {string} why
|
|
60
|
+
* @returns {string}
|
|
61
|
+
*/
|
|
62
|
+
export function decisionCodeOf(why) {
|
|
63
|
+
const w = String(why ?? '')
|
|
64
|
+
if (!w) return 'other'
|
|
65
|
+
if (w.includes('他说话了')) return 'human'
|
|
66
|
+
if (w.includes('接着上一轮')) return 'continuation'
|
|
67
|
+
if (w.includes('主动性关着') || w.includes('主动说话是关着的')) return 'off'
|
|
68
|
+
if (w.includes('不在她醒着的时段')) return 'window'
|
|
69
|
+
if (w.includes('她不在家')) return 'away'
|
|
70
|
+
if (w.includes('请了假')) return 'rest'
|
|
71
|
+
if (w.includes('醒过太多次')) return 'cap_silent'
|
|
72
|
+
if (w.includes('到上限') || w.includes('额度')) return 'cap'
|
|
73
|
+
if (w.includes('没送出去')) return 'retry'
|
|
74
|
+
if (w.includes('没开口')) return 'silent_wait'
|
|
75
|
+
if (w.includes('刚开过口')) return 'self_said'
|
|
76
|
+
if (w.includes('刚说过话')) return 'talked'
|
|
77
|
+
if (w.includes('桌上没有')) return 'no_material'
|
|
78
|
+
if (w.includes('没有新东西')) return 'no_new'
|
|
79
|
+
if (w.includes('她正忙') || w.includes('别的插件说她在忙')) return 'busy'
|
|
80
|
+
if (w.includes('你还在说话')) return 'hot'
|
|
81
|
+
if (w.includes('deliver failed') || w.includes('投递没有落成')) return 'deliver_fail'
|
|
82
|
+
return 'other'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 判决账文件。 */
|
|
86
|
+
export function decisionsFile(root = rootDir()) {
|
|
87
|
+
return join(root, 'decisions.jsonl')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 往判决账追加一行。
|
|
92
|
+
*
|
|
93
|
+
* 复制 `store.js` 的 appendLine 口径(不导出私有函数):文件末字节不是换行时
|
|
94
|
+
* 先补一个,再写这一行;只追加,不改已有内容。写失败不抛——判决账写不进去
|
|
95
|
+
* 不能连累她说话。
|
|
96
|
+
*
|
|
97
|
+
* @param {string} file
|
|
98
|
+
* @param {string} line
|
|
99
|
+
*/
|
|
100
|
+
async function appendLine(file, line) {
|
|
101
|
+
await fs.mkdir(dirname(file), { recursive: true })
|
|
102
|
+
const fh = await fs.open(file, 'a+')
|
|
103
|
+
try {
|
|
104
|
+
const { size } = await fh.stat()
|
|
105
|
+
let glued = false
|
|
106
|
+
if (size > 0) {
|
|
107
|
+
const last = Buffer.alloc(1)
|
|
108
|
+
const { bytesRead } = await fh.read(last, 0, 1, size - 1)
|
|
109
|
+
glued = bytesRead === 1 && last[0] !== 0x0a
|
|
110
|
+
}
|
|
111
|
+
await fh.appendFile((glued ? '\n' : '') + line + '\n', 'utf8')
|
|
112
|
+
} finally {
|
|
113
|
+
await fh.close()
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 记一笔判决。
|
|
119
|
+
*
|
|
120
|
+
* @param {string} root
|
|
121
|
+
* @param {{kind:string,code?:string,why?:string,woke?:boolean,replied?:boolean,model?:boolean,source?:string}} d
|
|
122
|
+
* @returns {Promise<boolean>} 写没写进去
|
|
123
|
+
*/
|
|
124
|
+
export async function recordDecision(root, d = /** @type {any} */ ({})) {
|
|
125
|
+
try {
|
|
126
|
+
const why = String(d.why ?? '')
|
|
127
|
+
const code = String(d.code ?? decisionCodeOf(why))
|
|
128
|
+
const kind = DECISION_KINDS.includes(d.kind) ? d.kind : 'other'
|
|
129
|
+
const row = {
|
|
130
|
+
v: 1,
|
|
131
|
+
at: new Date().toISOString(),
|
|
132
|
+
kind,
|
|
133
|
+
code,
|
|
134
|
+
why: why.slice(0, 200),
|
|
135
|
+
woke: d.woke === true,
|
|
136
|
+
replied: d.replied === true,
|
|
137
|
+
model: d.model === true,
|
|
138
|
+
source: String(d.source ?? ''),
|
|
139
|
+
}
|
|
140
|
+
await appendLine(decisionsFile(root), JSON.stringify(row))
|
|
141
|
+
return true
|
|
142
|
+
} catch {
|
|
143
|
+
return false
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 读判决账。坏行跳过,不抛。
|
|
149
|
+
*
|
|
150
|
+
* @param {string} root
|
|
151
|
+
* @param {{days?:number,limit?:number}} [o]
|
|
152
|
+
* @returns {Promise<{decisions:object[],total:number,days:number}>}
|
|
153
|
+
*/
|
|
154
|
+
export async function readDecisions(root, o = {}) {
|
|
155
|
+
const days = Math.min(90, Math.max(1, Number(o.days) || 7))
|
|
156
|
+
const limit = Math.min(500, Math.max(1, Number(o.limit) || 500))
|
|
157
|
+
const cutoff = Date.now() - days * 24 * 3600_000
|
|
158
|
+
let raw = ''
|
|
159
|
+
try {
|
|
160
|
+
raw = await fs.readFile(decisionsFile(root), 'utf8')
|
|
161
|
+
} catch {
|
|
162
|
+
return { decisions: [], total: 0, days }
|
|
163
|
+
}
|
|
164
|
+
const all = []
|
|
165
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
166
|
+
const s = line.trim()
|
|
167
|
+
if (!s) continue
|
|
168
|
+
try {
|
|
169
|
+
const d = JSON.parse(s)
|
|
170
|
+
if (!d || typeof d !== 'object') continue
|
|
171
|
+
const t = Date.parse(String(d.at ?? ''))
|
|
172
|
+
if (!Number.isFinite(t) || t < cutoff) continue
|
|
173
|
+
all.push(d)
|
|
174
|
+
} catch {
|
|
175
|
+
// 半行/坏行:跳过。判决账是旁证,不值得为一行坏数据把整页弄挂。
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// 时间倒序,最近的在最前;limit 作用在倒序之后。
|
|
179
|
+
all.sort((a, b) => (Date.parse(String(b.at)) || 0) - (Date.parse(String(a.at)) || 0))
|
|
180
|
+
return { decisions: all.slice(0, limit), total: all.length, days }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 按原因码聚合。只算数量、醒/回次数,不算分数、不排序成「谁更重要」。
|
|
185
|
+
*
|
|
186
|
+
* @param {object[]} decisions
|
|
187
|
+
* @returns {{code:string,label:string,count:number,woke:number,replied:number}[]}
|
|
188
|
+
*/
|
|
189
|
+
export function summarizeDecisions(decisions = []) {
|
|
190
|
+
/** @type {Map<string,{code:string,label:string,count:number,woke:number,replied:number}>} */
|
|
191
|
+
const m = new Map()
|
|
192
|
+
for (const d of decisions) {
|
|
193
|
+
const code = String(d?.code ?? 'other')
|
|
194
|
+
const cur = m.get(code) ?? {
|
|
195
|
+
code,
|
|
196
|
+
label: DECISION_LABELS[code] ?? code,
|
|
197
|
+
count: 0,
|
|
198
|
+
woke: 0,
|
|
199
|
+
replied: 0,
|
|
200
|
+
}
|
|
201
|
+
cur.count += 1
|
|
202
|
+
if (d?.woke === true) cur.woke += 1
|
|
203
|
+
if (d?.replied === true) cur.replied += 1
|
|
204
|
+
m.set(code, cur)
|
|
205
|
+
}
|
|
206
|
+
return [...m.values()].sort((a, b) => b.count - a.count || a.code.localeCompare(b.code))
|
|
207
|
+
}
|
package/lib/derive.js
CHANGED
|
@@ -581,6 +581,19 @@ export function orderEvents(events = []) {
|
|
|
581
581
|
/** 导入他人人设时带上来的称呼,写在 meta 事件里(见 lib/import.js) */
|
|
582
582
|
export const IMPORT_NAME_PREFIX = 'import-name:'
|
|
583
583
|
|
|
584
|
+
/**
|
|
585
|
+
* 他本人在会话里定的称呼,写在 meta 事件里(2026-11-30,用户 m01825 拍的 A+B)。
|
|
586
|
+
*
|
|
587
|
+
* 为什么要有这条路:称呼唯一真相是 `model.name`,而她的话之外没有第二条能改它的路。
|
|
588
|
+
* 导入时带来的名字(`import-name:`)一旦写错——比如把她的名字当成他的称呼——
|
|
589
|
+
* 之后就只能靠她自己哪天说出「改口句」才能翻回来,而他本人说什么都不算数。
|
|
590
|
+
* 外部那台机器就是这样:身份文档通篇写着「你管他叫林汐」,她照着把对方喊成自己。
|
|
591
|
+
*
|
|
592
|
+
* 这条通道只在「她第一次正式给他起过名」之后才生效(见 `namedByHer`):
|
|
593
|
+
* 起名这件事本身留给她,他只能在她叫出一个名字之后**改口**,不能绕过这一步。
|
|
594
|
+
*/
|
|
595
|
+
export const NAME_SET_PREFIX = 'name-set:'
|
|
596
|
+
|
|
584
597
|
/**
|
|
585
598
|
* 「这一局的人设是别人给的」这条标记,同样写在 meta 事件里(2026-10-27,用户 m03769)。
|
|
586
599
|
*
|
|
@@ -885,6 +898,50 @@ export function pickName(text, pronoun) {
|
|
|
885
898
|
return hit ? hit.name : null
|
|
886
899
|
}
|
|
887
900
|
|
|
901
|
+
// 他本人在会话里说「叫我 X」(2026-11-30,用户 m01825 拍板的 B)。
|
|
902
|
+
//
|
|
903
|
+
// 只认第一人称:他说「以后叫我俊儇」「叫我阿辰就行」「我叫俊儇」。
|
|
904
|
+
// 不认转述(「他让我叫你阿辰」——那是别人的要求,不是他定的),
|
|
905
|
+
// 不认否定(「以后别叫我老大」),引号里的原文(他在复述别人的话)也不算。
|
|
906
|
+
// 「叫我起来 / 叫我吃饭」这类祈使句由 looksLikeName 的动词整词否决挡掉。
|
|
907
|
+
const OWNER_CALL_RE = /(?:以后|从今|往后|就|直接)?\s*(?:叫我|喊我|称呼我)\s*[::]?\s*[「“"']?([^,。!?;\s「」“”"']{1,8})/g
|
|
908
|
+
// 「我叫 X」「我的名字是 X」:从行首或句首开始才认——「我说我叫阿辰」是复述,
|
|
909
|
+
// 不能当成他在给自己定名(这类句子里「我」前面还有别的字,锚不到句首)。
|
|
910
|
+
const OWNER_SELF_RE = /(?:^|[。!?;\n])\s*我(?:的名字)?(?:就)?(?:叫|是)\s*[「“"']?([^,。!?;\s「」“”"']{1,8})/g
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* 他本人在会话里定的称呼(用户 m01825 的 B 通道)。
|
|
914
|
+
* 只说明「他刚刚说了这个称呼」,要不要真的写进去由调用方判断
|
|
915
|
+
* (`turns.js` 只在 `model.namedByHer` 为真时落事件)。
|
|
916
|
+
* @param {unknown} text
|
|
917
|
+
* @returns {{name: string} | null}
|
|
918
|
+
*/
|
|
919
|
+
export function pickOwnerRename(text) {
|
|
920
|
+
const s = String(text ?? '')
|
|
921
|
+
for (const re of [OWNER_CALL_RE, OWNER_SELF_RE]) {
|
|
922
|
+
re.lastIndex = 0
|
|
923
|
+
const m = re.exec(s)
|
|
924
|
+
if (!m) continue
|
|
925
|
+
const name = String(m[1] ?? '')
|
|
926
|
+
.trim()
|
|
927
|
+
.replace(/^[::]+/, '')
|
|
928
|
+
.replace(/[::]+$/, '')
|
|
929
|
+
.replace(/^[「『【((]+/, '')
|
|
930
|
+
.replace(/[」』】))]+$/, '')
|
|
931
|
+
// 「叫我阿辰就行」「叫我阿辰就好了」:后半截是语气,不是名字
|
|
932
|
+
.replace(/(?:就行|就好|好了|就可以|即可)$/, '')
|
|
933
|
+
.replace(NAME_TAIL, '')
|
|
934
|
+
.trim()
|
|
935
|
+
if (!looksLikeName(name)) continue
|
|
936
|
+
if (quotedAt(s, m.index)) continue
|
|
937
|
+
const before = s.slice(0, m.index).slice(-10)
|
|
938
|
+
if (NAME_NEG_BEFORE.test(before)) continue
|
|
939
|
+
if (NAME_RELAY_BEFORE.test(before)) continue
|
|
940
|
+
return { name }
|
|
941
|
+
}
|
|
942
|
+
return null
|
|
943
|
+
}
|
|
944
|
+
|
|
888
945
|
// 称呼怎么落定(issue #102 后续,2026-11-13 用户转来外部排查)。
|
|
889
946
|
//
|
|
890
947
|
// 高置信永远能覆盖;低置信只在「还没有名字」或「现在这个名字也是低置信猜的」时采用。
|
|
@@ -1165,6 +1222,12 @@ function deriveSelfUncached(events = [], opts = {}) {
|
|
|
1165
1222
|
let name = null
|
|
1166
1223
|
// 这个名字是「高置信」认出来的,还是低置信猜的?低置信猜的名字可以被后来的低置信改掉。
|
|
1167
1224
|
let nameConfident = false
|
|
1225
|
+
// 2026-11-30(用户 m01825):他本人在会话里定过称呼(`name-set:`)之后,
|
|
1226
|
+
// 她后来那些(包括高置信的)都不再改动它——他明确说过一次,以他为准。
|
|
1227
|
+
let nameLocked = false
|
|
1228
|
+
// 她有没有**正式**给他起过名(她自己高置信认出来的,不是导入带来的)。
|
|
1229
|
+
// 他改口的通道要等她起过名才开;导入带来的名字不算——那不是她起的名。
|
|
1230
|
+
let namedByHer = false
|
|
1168
1231
|
// 2026-10-27(用户 m03769):这一局是不是「接别人养的」那一局。
|
|
1169
1232
|
// **只从事件流里认**,不看配置——配置会跟着备份/恢复一起搬回来,
|
|
1170
1233
|
// 那样一条原生的鱼只要恢复过一次别人的档,就永久拿到了豁免。
|
|
@@ -1262,9 +1325,14 @@ function deriveSelfUncached(events = [], opts = {}) {
|
|
|
1262
1325
|
// 后来接受他给的名字「时梦尘」,状态栏就永远停在那个被他自己否掉的旧称呼上。
|
|
1263
1326
|
{
|
|
1264
1327
|
// 高置信才覆盖;低置信只在还没有名字(或现名也是低置信猜的)时采用(issue #102)
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
|
|
1328
|
+
const hit = pickNameHit(ev.text, pronoun)
|
|
1329
|
+
// 她**正式**给他起过名,才算「起名事件」——他改口的通道要等这一步。
|
|
1330
|
+
if (hit?.confident) namedByHer = true
|
|
1331
|
+
if (!nameLocked) {
|
|
1332
|
+
const next = settleName({ name, confident: nameConfident }, hit)
|
|
1333
|
+
name = next.name
|
|
1334
|
+
nameConfident = next.confident
|
|
1335
|
+
}
|
|
1268
1336
|
}
|
|
1269
1337
|
if (CORRECTION_RE.test(ev.text) || CORRECTION_PHRASE_RE.test(String(ev.text ?? ''))) corrected.push(ev.id)
|
|
1270
1338
|
// P1(2026-10-24):自我叙述不用等 stage 4 的 remember 模板。
|
|
@@ -1343,9 +1411,13 @@ function deriveSelfUncached(events = [], opts = {}) {
|
|
|
1343
1411
|
})
|
|
1344
1412
|
// 同 utterance:高置信盖掉先前的,低置信只补空缺(issue #102)
|
|
1345
1413
|
{
|
|
1346
|
-
const
|
|
1347
|
-
|
|
1348
|
-
|
|
1414
|
+
const hit = pickNameHit(ev.text, pronoun)
|
|
1415
|
+
if (hit?.confident) namedByHer = true
|
|
1416
|
+
if (!nameLocked) {
|
|
1417
|
+
const next = settleName({ name, confident: nameConfident }, hit)
|
|
1418
|
+
name = next.name
|
|
1419
|
+
nameConfident = next.confident
|
|
1420
|
+
}
|
|
1349
1421
|
}
|
|
1350
1422
|
if (!narrative && ev.verdict === 'refined' && /我(一直|原来|其实)/.test(ev.text)) setNarrative({ at: ev.ts, text: ev.text })
|
|
1351
1423
|
break
|
|
@@ -1402,13 +1474,29 @@ function deriveSelfUncached(events = [], opts = {}) {
|
|
|
1402
1474
|
const at = Date.parse(ev.ts) || 0
|
|
1403
1475
|
if (at > lastWakeAt) lastWakeAt = at
|
|
1404
1476
|
heardSinceWake = false
|
|
1477
|
+
} else if (t.startsWith(NAME_SET_PREFIX)) {
|
|
1478
|
+
// 他本人在会话里定过称呼(2026-11-30,用户 m01825)。这条压过导入名,
|
|
1479
|
+
// 也压过她后来认出来的名字;之后她再说什么都不动它(见 nameLocked)。
|
|
1480
|
+
const n = t.slice(NAME_SET_PREFIX.length).trim()
|
|
1481
|
+
if (n && looksLikeName(n)) {
|
|
1482
|
+
name = n
|
|
1483
|
+
nameConfident = true
|
|
1484
|
+
nameLocked = true
|
|
1485
|
+
}
|
|
1405
1486
|
} else if (t.startsWith(IMPORT_NAME_PREFIX)) {
|
|
1406
1487
|
// 导入他人人设时带来的称呼(2026-10-27,用户 m03201「称呼带过来」)。
|
|
1407
1488
|
// 走事件而不是配置:称呼是她认知的一部分,得跟着事件流走;
|
|
1408
1489
|
// 放配置里的话,重置之后会剩一条谁也不记得的孤立设置。
|
|
1409
|
-
//
|
|
1490
|
+
//
|
|
1491
|
+
// 2026-11-30(外部报告:导入的名字把她喊成自己):**只在这局还没有称呼时采用,
|
|
1492
|
+
// 而且只算低置信**。它只是一个猜——导入单子是人手填的,填错的时候(把她的名字
|
|
1493
|
+
// 当成他的称呼)原来会写成高置信,此后她再怎么叫、他再怎么改都翻不回来。
|
|
1494
|
+
// 低置信的规矩照旧(settleName):她自己认出一个名字就能盖掉它。
|
|
1410
1495
|
const n = t.slice(IMPORT_NAME_PREFIX.length).trim()
|
|
1411
|
-
if (n
|
|
1496
|
+
if (n && !name) {
|
|
1497
|
+
name = n
|
|
1498
|
+
nameConfident = false
|
|
1499
|
+
}
|
|
1412
1500
|
} else if (t.startsWith(IMPORT_MARK_PREFIX)) {
|
|
1413
1501
|
// 「这一局是接别人养的那一位」(2026-10-27,用户 m03769)。
|
|
1414
1502
|
//
|
|
@@ -2054,6 +2142,9 @@ function deriveSelfUncached(events = [], opts = {}) {
|
|
|
2054
2142
|
// 「你自己说过的话」要照它剔一遍:改口句(revise)本身不带 topic,光看 topic 剔不掉。
|
|
2055
2143
|
personBeliefIds: [...new Set(peopleAll.flatMap((p) => (Array.isArray(p.judgmentIds) ? p.judgmentIds : [])))],
|
|
2056
2144
|
name,
|
|
2145
|
+
// 她有没有正式给他起过名(她自己认出来的名字,不是导入带来的)。
|
|
2146
|
+
// `turns.js` 用它决定「他本人在会话里定的称呼」这条路开不开(用户 m01825)。
|
|
2147
|
+
namedByHer,
|
|
2057
2148
|
// 2026-10-24 起 beliefs 按**显著性**排(不是时间)。固化/常被提起的在前,
|
|
2058
2149
|
// 靠后的才是"更早以前"——遗忘不再是无差别的时间截断。
|
|
2059
2150
|
beliefs: ranked,
|
package/lib/guard.js
CHANGED
|
@@ -140,8 +140,9 @@ export function looksMojibake(text) {
|
|
|
140
140
|
* @returns {{hit:boolean, why:string}}
|
|
141
141
|
*/
|
|
142
142
|
const LEAK_PATTERNS = [
|
|
143
|
-
// Windows 盘符路径 / UNC /
|
|
144
|
-
|
|
143
|
+
// Windows 盘符路径 / UNC / 用户目录。
|
|
144
|
+
// 前面不能是字母:`https://` 里的 `s:/` 也长成盘符,但它是网址,不是门牌。
|
|
145
|
+
/(?<![A-Za-z])[A-Za-z]:[\\/][^\s]*/,
|
|
145
146
|
/\\\\[^\s]+\\[^\s]*/,
|
|
146
147
|
/(?:^|[\s((])\/(?:Users|home|root|tmp|var)\/[^\s]*/,
|
|
147
148
|
// 状态库与家用目录名:命中即说明她在念家里的东西
|
|
@@ -168,17 +169,82 @@ export function looksLikeLeak(text) {
|
|
|
168
169
|
return { hit: false, why: '' }
|
|
169
170
|
}
|
|
170
171
|
|
|
172
|
+
/**
|
|
173
|
+
* 只抹掉那一段,不动整句。
|
|
174
|
+
*
|
|
175
|
+
* 为什么不是整条丢(2026-11-29,用户 m00311):一句「这个我回头问一下,
|
|
176
|
+
* Cookie 是 SESSDATA=abc」里真正不能出门的只有后半段。整条丢掉,她明明
|
|
177
|
+
* 说了一句正常的话,却只收到「这句先不说了」——她不知道哪一段出了问题,
|
|
178
|
+
* 下一次还会照原样说。所以先按片段换掉,换完再复查。
|
|
179
|
+
*
|
|
180
|
+
* 占位词用〔凭据〕/〔地址〕/〔本机〕这类**事实**,不用「敏感信息」——
|
|
181
|
+
* 后者等于告诉她「这里有审查」,而且会教她下次换个写法绕。
|
|
182
|
+
*/
|
|
183
|
+
const REDACTIONS = [
|
|
184
|
+
// 登录凭据:连键带值一起换,避免留下 `SESSDATA=` 又命中一次。
|
|
185
|
+
[/\b(?:SESSDATA|bili_jct|DedeUserID(?:__ckMd5)?|buvid3)\s*=\s*[^\s;,。;、))]*/gi, '〔凭据〕'],
|
|
186
|
+
[/\bsk-[A-Za-z0-9_-]{16,}\b/g, '〔凭据〕'],
|
|
187
|
+
[/\bBearer\s+[A-Za-z0-9._-]{20,}/gi, '〔凭据〕'],
|
|
188
|
+
[/\b(?:api[_-]?key|access[_-]?token|secret[_-]?key|password|passwd|cookie)\b\s*[:=]\s*[^\s;,。;、))]*/gi, '〔凭据〕'],
|
|
189
|
+
[/\b[A-Za-z0-9_-]{32,}\b/g, '〔凭据〕'],
|
|
190
|
+
// 门牌:盘符 / UNC / Unix 家目录。和 LEAK_PATTERNS 的判据保持同一条边界。
|
|
191
|
+
[/(?<![A-Za-z])[A-Za-z]:[\\/][^\s,。;、))]*/g, '〔地址〕'],
|
|
192
|
+
[/\\\\[^\s]+\\[^\s,。;、))]*/g, '〔地址〕'],
|
|
193
|
+
[/(?<![\w])\/(?:Users|home|root|tmp|var)\/[^\s,。;、))]*/g, '〔地址〕'],
|
|
194
|
+
// 家里的文件名与目录名。
|
|
195
|
+
[/(?:AGENTS|IDENTITY)\.md/gi, '〔本机〕'],
|
|
196
|
+
[/(?:events\.jsonl|config\.json|owner\.json|state\.json|inbox\.md)/gi, '〔本机〕'],
|
|
197
|
+
[/\.dsh-fish/gi, '〔本机〕'],
|
|
198
|
+
[/\.dsh(?![a-z-])/gi, '〔本机〕'],
|
|
199
|
+
// 账号数字 / 私聊字样 / 邮箱 / 手机号。
|
|
200
|
+
[/\b(?:uid|mid)\s*[::=]?\s*\d{3,}/gi, '〔账号〕'],
|
|
201
|
+
[/(?:私聊|聊天记录|我们(?:的)?对话|我跟(?:你|他)说)/g, '〔私事〕'],
|
|
202
|
+
[/[\w.+-]+@[\w-]+\.[\w.]+/g, '〔邮箱〕'],
|
|
203
|
+
[/(?<!\d)1[3-9]\d{9}(?!\d)/g, '〔电话〕'],
|
|
204
|
+
]
|
|
205
|
+
|
|
206
|
+
/** 把一句话里像凭据/门牌的片段换成占位词,其余原样。 */
|
|
207
|
+
function redactSensitive(text) {
|
|
208
|
+
let out = String(text ?? '')
|
|
209
|
+
for (const [re, to] of REDACTIONS) out = out.replace(re, to)
|
|
210
|
+
return out
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 抹完之后还剩不剩一句真话。
|
|
215
|
+
*
|
|
216
|
+
* 只有占位词和标点(`SESSDATA=abc` 这种整句就是凭据的),不该把
|
|
217
|
+
* 「〔凭据〕」当评论发出去——那不是改写,是发了一句谁也看不懂的空话。
|
|
218
|
+
*/
|
|
219
|
+
function hasContentAfterRedaction(text) {
|
|
220
|
+
const rest = String(text ?? '')
|
|
221
|
+
.replace(/〔(?:凭据|地址|本机|账号|私事|邮箱|电话)〕/g, '')
|
|
222
|
+
.replace(/[\s,。;、!?…—,.!?;:()()"'“”‘’\-]/g, '')
|
|
223
|
+
return rest.length > 0
|
|
224
|
+
}
|
|
225
|
+
|
|
171
226
|
/**
|
|
172
227
|
* 她要说出去的话,出门前过一遍。
|
|
173
|
-
*
|
|
228
|
+
*
|
|
229
|
+
* 两段式(2026-11-29,用户 m00311):
|
|
230
|
+
* 1. 先按片段抹掉凭据/门牌,整句保留;
|
|
231
|
+
* 2. 抹完再复查一遍,仍命中才整条拦下。
|
|
232
|
+
* 拦下时 why 仍是 'secret' / 'leak',调用方据此决定怎么跟她说。
|
|
233
|
+
*
|
|
234
|
+
* @returns {{ok:boolean, text:string, why:string, redacted?:boolean}}
|
|
174
235
|
*/
|
|
175
236
|
export function screenOutgoing(text) {
|
|
176
237
|
const s = String(text ?? '')
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
if (
|
|
181
|
-
|
|
238
|
+
if (!s) return { ok: true, text: s, why: '' }
|
|
239
|
+
const secret = looksLikeSecret(s)
|
|
240
|
+
const leak = secret.hit ? { hit: false, why: '' } : looksLikeLeak(s)
|
|
241
|
+
if (!secret.hit && !leak.hit) return { ok: true, text: s, why: '' }
|
|
242
|
+
|
|
243
|
+
const clean = redactSensitive(s).trim()
|
|
244
|
+
// 抹完复查:占位词自己不能触发规则;仍命中说明有规则没覆盖到的写法,
|
|
245
|
+
// 这时宁可整条不发,也不把半截凭据送出去。
|
|
246
|
+
if (!clean || !hasContentAfterRedaction(clean) || looksLikeSecret(clean).hit || looksLikeLeak(clean).hit) {
|
|
247
|
+
return { ok: false, text: '', why: secret.hit ? 'secret' : 'leak' }
|
|
182
248
|
}
|
|
183
|
-
return { ok: true, text:
|
|
249
|
+
return { ok: true, text: clean, why: '', redacted: true }
|
|
184
250
|
}
|
package/lib/herpeople.js
CHANGED
|
@@ -158,7 +158,7 @@ export function registerHerPeople(ctx, deps = {}) {
|
|
|
158
158
|
'。',
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
const text = hit.map((p) => renderPerson(p, { pronoun: pronounOf(config) })).join('\n\n')
|
|
161
|
+
const text = hit.map((p) => renderPerson(p, { pronoun: pronounOf(config), startAt: model?.startAt })).join('\n\n')
|
|
162
162
|
return {
|
|
163
163
|
found: true,
|
|
164
164
|
text: text.length > PEOPLE_READ_MAX ? `${text.slice(0, PEOPLE_READ_MAX)}…` : text,
|
package/lib/index.js
CHANGED
|
@@ -70,7 +70,7 @@ export const name = 'dsh-fish'
|
|
|
70
70
|
* 版本号,必须和 package.json 的 version 一样(test/boot.test.mjs 盯着)。
|
|
71
71
|
* 不只是日志:升级自检和设置页的「检查更新」拿它当「正在跑的版本」。
|
|
72
72
|
*/
|
|
73
|
-
export const VERSION = '1.1.
|
|
73
|
+
export const VERSION = '1.1.5'
|
|
74
74
|
|
|
75
75
|
// ⚠️ 一个数组写全,不要拆成对象
|
|
76
76
|
// 2026-10-30(m02961):`userQuestions` **不再写进 inject**。写进 inject 的东西缺一个,
|
package/lib/observe-data.js
CHANGED
|
@@ -30,6 +30,7 @@ import { LOG_KEEP, LOG_MAX_BYTES, buildBundle, clearLog, logLine, logsDir, redac
|
|
|
30
30
|
import { checkUpdate, REPO_URL, normalizeVersion } from './update.js'
|
|
31
31
|
import { tailUpdateLog } from './selfupdate.js'
|
|
32
32
|
import { send, sentTooLarge, readBody, readBodyBuffer } from './observe-http.js'
|
|
33
|
+
import { readDecisions, summarizeDecisions } from './decisions.js'
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* @param {import('./types.js').ObserveEnv} env
|
|
@@ -146,6 +147,21 @@ export function buildDataRoutes(env) {
|
|
|
146
147
|
})
|
|
147
148
|
}],
|
|
148
149
|
|
|
150
|
+
// 判决账(2026-11-29,用户 m00311):只读。看「这一轮为什么醒 / 为什么没醒、
|
|
151
|
+
// 回没回」,按原因聚合;不参与任何判定,也不进她的提示词。
|
|
152
|
+
['/decisions', async (req, res) => {
|
|
153
|
+
if (req.method !== 'GET') return send(res, 405, { error: '只支持 GET' })
|
|
154
|
+
const url = new URL(req.url ?? '/', 'http://x')
|
|
155
|
+
const days = Math.max(1, Math.min(90, Number(url.searchParams.get('days') ?? 7) || 7))
|
|
156
|
+
const { decisions: all, total, days: d } = await readDecisions(root, { days, limit: 500 })
|
|
157
|
+
return send(res, 200, {
|
|
158
|
+
days: d,
|
|
159
|
+
total,
|
|
160
|
+
groups: summarizeDecisions(all),
|
|
161
|
+
recent: all.slice(0, 100),
|
|
162
|
+
})
|
|
163
|
+
}],
|
|
164
|
+
|
|
149
165
|
['/log/export', async (req, res) => {
|
|
150
166
|
if (req.method !== 'GET') return send(res, 405, { error: '只支持 GET' })
|
|
151
167
|
const url = new URL(req.url ?? '/', 'http://x')
|