@ssamurias/dsh-fish 0.9.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +58 -24
- package/CHANGELOG.md +178 -15
- package/README.md +56 -159
- package/RELEASE-NOTES-0.9.9.md +135 -0
- package/RELEASE-NOTES-1.0.0.md +137 -0
- package/lib/appoint.js +26 -11
- package/lib/ask.js +4 -3
- package/lib/askinchat.js +6 -1
- package/lib/at.js +241 -0
- package/lib/backup.js +15 -2
- package/lib/bili.js +37 -1
- package/lib/browse.js +29 -7
- package/lib/capture.js +36 -6
- package/lib/cardanswer.js +12 -2
- package/lib/client.js +135 -12
- package/lib/comment.js +27 -9
- package/lib/compact.js +36 -8
- package/lib/contract.js +266 -0
- package/lib/curiosity.js +6 -5
- package/lib/deliver.js +6 -3
- package/lib/derive.js +293 -18
- package/lib/desk.js +4 -3
- package/lib/dream.js +3 -1
- package/lib/echo.js +75 -0
- package/lib/events.js +124 -36
- package/lib/gapwall.js +3 -1
- package/lib/generator.js +10 -0
- package/lib/grant.js +3 -2
- package/lib/guard.js +184 -184
- package/lib/guardlog.js +58 -0
- package/lib/health.js +138 -0
- package/lib/herdiary.js +27 -8
- package/lib/home.js +49 -2
- package/lib/hook.js +1 -1
- package/lib/identity.js +71 -5
- package/lib/import.js +302 -302
- package/lib/index.js +67 -16
- package/lib/intent.js +5 -3
- package/lib/keep.js +3 -2
- package/lib/keepsake.js +3 -2
- package/lib/letter.js +3 -3
- package/lib/locate.js +40 -1
- package/lib/log.js +58 -4
- package/lib/look.js +15 -1
- package/lib/material.js +57 -1
- package/lib/move.js +147 -14
- package/lib/note.js +113 -31
- package/lib/observe.js +76 -27
- package/lib/pair.js +95 -0
- package/lib/persona.js +217 -70
- package/lib/pocket.js +2 -2
- package/lib/proactive.js +7 -6
- package/lib/pronoun.js +160 -0
- package/lib/pronounask.js +210 -0
- package/lib/quality.js +1 -1
- package/lib/readme.js +1 -1
- package/lib/recall.js +187 -29
- package/lib/restrict.js +28 -1
- package/lib/say.js +19 -13
- package/lib/scheduler.js +187 -13
- package/lib/schema.js +57 -0
- package/lib/selfdoc.js +36 -10
- package/lib/sessionnote.js +111 -37
- package/lib/settings.js +75 -6
- package/lib/sources.js +99 -0
- package/lib/speak.js +7 -2
- package/lib/speechanchor.js +132 -0
- package/lib/stance.js +36 -6
- package/lib/store.js +89 -10
- package/lib/sub.js +387 -0
- package/lib/talkmem.js +40 -8
- package/lib/tenant.js +236 -36
- package/lib/turns.js +165 -40
- package/lib/unlock.js +30 -9
- package/lib/use.js +21 -1
- package/lib/watch.js +4 -0
- package/lib/wish.js +13 -3
- package/package.json +3 -3
- package/tools/check-install.mjs +237 -0
- package/RELEASE.md +0 -154
- package/media/principle-loop-2x.png +0 -0
- package/media/principle-memory-2x.png +0 -0
package/lib/contract.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 素材契约(1.0,2026-11-12 用户 m03699)
|
|
3
|
+
*
|
|
4
|
+
* ## 这是什么
|
|
5
|
+
*
|
|
6
|
+
* 一个**可选**的返回形状:外面的插件(知乎、贴吧、新闻、小说……)如果愿意按它返回,
|
|
7
|
+
* 她拿到的就不是「一段文本」,而是一条**素材**——有出处、有原话、有分级,
|
|
8
|
+
* 于是「她说的话能不能挂到具体一句上」这件事,才轮得到这些来源。
|
|
9
|
+
*
|
|
10
|
+
* ## 为什么是「认领制」
|
|
11
|
+
*
|
|
12
|
+
* 不改现有通路:不按形状返回的工具,一切照旧(她照样调得动、照样是普通文本)。
|
|
13
|
+
* 只有按形状返回、并且被本插件接住的那一条,才升级成素材。
|
|
14
|
+
* 所以已接入的插件不需要重接,也不会因为这份契约改变行为。
|
|
15
|
+
*
|
|
16
|
+
* ## 三条由插件这边定的规则
|
|
17
|
+
*
|
|
18
|
+
* 1. **分级由我们定**:第三方只能声明 `kind`(事实 / 观点 / 虚构),
|
|
19
|
+
* 不能自己声明「我这是几级证据」。它声明 fact,也只能让 quote 拿到 1 级;
|
|
20
|
+
* 没有可核对的锚(`url` 或同条素材里的事实项)就降回 2 级。
|
|
21
|
+
* 2. **可核对由我们核**:`canVerify` 不看第三方怎么说,只看有没有事实项。
|
|
22
|
+
* 3. **渲染与防护由我们走**:文本一字不改,但要过 `debrief()` 那层牌子,
|
|
23
|
+
* 并且只标「谁写的」,不给她看等级数字。
|
|
24
|
+
*
|
|
25
|
+
* ## 形状
|
|
26
|
+
*
|
|
27
|
+
* ```json
|
|
28
|
+
* {
|
|
29
|
+
* "dshFishMaterial": 1,
|
|
30
|
+
* "source": "zhihu",
|
|
31
|
+
* "key": "https://example.com/a/1",
|
|
32
|
+
* "at": "2026-11-12",
|
|
33
|
+
* "title": "为什么……",
|
|
34
|
+
* "kind": "opinion",
|
|
35
|
+
* "facts": [{ "label": "作者", "value": "某人", "url": "…" }],
|
|
36
|
+
* "quotes": [{ "text": "原话,一个字都不用改", "kind": "answer", "by": "答主:某人" }]
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* 约束(超出即拒或截断,不静默丢一半):
|
|
41
|
+
* - `source` 1–40 字,`key` 1–200 字;
|
|
42
|
+
* - `facts` ≤ 20 条、`quotes` ≤ 40 条,每条正文 ≤ 500 字;
|
|
43
|
+
* - 总正文 ≤ 20000 字;
|
|
44
|
+
* - 重复原话去重;空素材(既无事实也无原话)直接拒。
|
|
45
|
+
*
|
|
46
|
+
* 全文见 `docs/素材契约.md`。
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/** 契约版本。第三方按这个数字声明自己按哪一版返回。 */
|
|
50
|
+
export const CONTRACT_VERSION = 1
|
|
51
|
+
|
|
52
|
+
/** 形状标记:有它就能被认出来,没有也可以按字段判断。 */
|
|
53
|
+
export const CONTRACT_MARK = 'dshFishMaterial'
|
|
54
|
+
|
|
55
|
+
/** 第三方只能声明这三类。 */
|
|
56
|
+
export const SOURCE_KINDS = Object.freeze(['fact', 'opinion', 'fiction'])
|
|
57
|
+
|
|
58
|
+
/** 类别 → 它最多能拿到的级别(数字越小越硬)。 */
|
|
59
|
+
export const KIND_GRADE = Object.freeze({ fact: 1, opinion: 2, fiction: 3 })
|
|
60
|
+
|
|
61
|
+
/** 硬上限。 */
|
|
62
|
+
export const LIMITS = Object.freeze({
|
|
63
|
+
body: 20000,
|
|
64
|
+
facts: 20,
|
|
65
|
+
quotes: 40,
|
|
66
|
+
text: 500,
|
|
67
|
+
title: 200,
|
|
68
|
+
source: 40,
|
|
69
|
+
key: 200,
|
|
70
|
+
by: 40,
|
|
71
|
+
kind: 20,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const GRADES = new Set([1, 2, 3])
|
|
75
|
+
|
|
76
|
+
/** 只去首尾空白、不乱动中间的字——原文一个字都不改。 */
|
|
77
|
+
function clean(v, max) {
|
|
78
|
+
return String(v ?? '').trim().slice(0, max)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 标题这类展示用字段可以压空白。 */
|
|
82
|
+
function flat(v, max) {
|
|
83
|
+
return String(v ?? '').replace(/\s+/g, ' ').trim().slice(0, max)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function kindOf(raw, fallback) {
|
|
87
|
+
if (SOURCE_KINDS.includes(raw?.kind)) return raw.kind
|
|
88
|
+
if (SOURCE_KINDS.includes(fallback)) return fallback
|
|
89
|
+
return 'opinion'
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 把第三方返回的对象校验、规范化成一条素材。
|
|
94
|
+
*
|
|
95
|
+
* 不抛错:校验不过就返回 `{ ok: false, problems }`,调用方照旧按普通文本处理。
|
|
96
|
+
* 能修的就修(截断、去重、降级),修不了才拒——拒的时候也把原因带上。
|
|
97
|
+
*
|
|
98
|
+
* @param {object} raw 第三方返回的对象
|
|
99
|
+
* @param {{ source?: string, kind?: string, now?: number }} [o]
|
|
100
|
+
* @returns {{ ok: boolean, material: object|null, problems: string[] }}
|
|
101
|
+
*/
|
|
102
|
+
export function coerceMaterial(raw, o = {}) {
|
|
103
|
+
const problems = []
|
|
104
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
105
|
+
return { ok: false, material: null, problems: ['not-an-object'] }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const source = clean(o.source ?? raw.source, LIMITS.source)
|
|
109
|
+
if (!source) problems.push('missing-source')
|
|
110
|
+
const key = clean(raw.key, LIMITS.key)
|
|
111
|
+
if (!key) problems.push('missing-key')
|
|
112
|
+
// 来路和身份缺一样就不收。没有来路的素材,她引用时就分不清是谁说的;
|
|
113
|
+
// 没有 key 的素材,去重、回看和「同一件事」都挂不上——宁可退回普通文本。
|
|
114
|
+
if (!source || !key) return { ok: false, material: null, problems }
|
|
115
|
+
|
|
116
|
+
const declared = clean(raw.kind, LIMITS.kind)
|
|
117
|
+
if (declared && !SOURCE_KINDS.includes(declared)) problems.push('bad-kind')
|
|
118
|
+
const kind = kindOf(raw, o.kind)
|
|
119
|
+
const ceiling = KIND_GRADE[kind]
|
|
120
|
+
|
|
121
|
+
const facts = []
|
|
122
|
+
const factList = Array.isArray(raw.facts) ? raw.facts : []
|
|
123
|
+
if (factList.length > LIMITS.facts) problems.push('too-many-facts')
|
|
124
|
+
for (const f of factList) {
|
|
125
|
+
if (facts.length >= LIMITS.facts) break
|
|
126
|
+
if (!f || typeof f !== 'object') continue
|
|
127
|
+
const value = clean(f.value, LIMITS.text)
|
|
128
|
+
if (!value) continue
|
|
129
|
+
const label = flat(f.label, LIMITS.by)
|
|
130
|
+
const url = clean(f.url, 500)
|
|
131
|
+
facts.push({ label, value, grade: 1, ...(url ? { url } : {}) })
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const quotes = []
|
|
135
|
+
const seen = new Set()
|
|
136
|
+
const quoteList = Array.isArray(raw.quotes) ? raw.quotes : []
|
|
137
|
+
if (quoteList.length > LIMITS.quotes) problems.push('too-many-quotes')
|
|
138
|
+
for (const q of quoteList) {
|
|
139
|
+
if (quotes.length >= LIMITS.quotes) break
|
|
140
|
+
if (!q || typeof q !== 'object') continue
|
|
141
|
+
const text = clean(q.text, LIMITS.text)
|
|
142
|
+
if (!text || seen.has(text)) continue
|
|
143
|
+
seen.add(text)
|
|
144
|
+
// 声明的级别不能比「它说自己是哪一类」更硬:观点不能自称证据。
|
|
145
|
+
let grade = Number.isInteger(q.grade) ? q.grade : ceiling
|
|
146
|
+
if (!GRADES.has(grade)) grade = ceiling
|
|
147
|
+
if (grade < ceiling) {
|
|
148
|
+
grade = ceiling
|
|
149
|
+
problems.push('grade-clamped')
|
|
150
|
+
}
|
|
151
|
+
const url = clean(q.url, 500)
|
|
152
|
+
// 1 级必须有锚:自己的 url,或同条素材里的事实项;否则降回观点。
|
|
153
|
+
if (grade === 1 && !url && facts.length === 0) {
|
|
154
|
+
grade = 2
|
|
155
|
+
problems.push('fact-without-anchor')
|
|
156
|
+
}
|
|
157
|
+
const by = flat(q.by, LIMITS.by) || source
|
|
158
|
+
const qkind = flat(q.kind, LIMITS.kind) || 'body'
|
|
159
|
+
const like = Number(q.like)
|
|
160
|
+
quotes.push({
|
|
161
|
+
by,
|
|
162
|
+
kind: qkind,
|
|
163
|
+
grade,
|
|
164
|
+
text,
|
|
165
|
+
...(url ? { url } : {}),
|
|
166
|
+
...(Number.isFinite(like) && like > 0 ? { like } : {}),
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!facts.length && !quotes.length) {
|
|
171
|
+
problems.push('empty')
|
|
172
|
+
return { ok: false, material: null, problems }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const total = quotes.reduce((n, q) => n + q.text.length, 0) + facts.reduce((n, f) => n + f.value.length, 0)
|
|
176
|
+
if (total > LIMITS.body) {
|
|
177
|
+
problems.push('too-long')
|
|
178
|
+
return { ok: false, material: null, problems }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
ok: true,
|
|
183
|
+
problems,
|
|
184
|
+
material: {
|
|
185
|
+
source,
|
|
186
|
+
key,
|
|
187
|
+
at: raw.at ?? o.at ?? null,
|
|
188
|
+
title: flat(raw.title, LIMITS.title),
|
|
189
|
+
kind,
|
|
190
|
+
tags: Array.isArray(raw.tags) ? raw.tags.map((t) => flat(t, 40)).filter(Boolean).slice(0, 12) : [],
|
|
191
|
+
facts,
|
|
192
|
+
quotes,
|
|
193
|
+
// 不看它怎么说,只看有没有事实项。
|
|
194
|
+
canVerify: raw.canVerify === false ? false : facts.length > 0,
|
|
195
|
+
blocked: raw.blocked ?? undefined,
|
|
196
|
+
},
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 工具的返回值(字符串)→ 素材。认不出来就返回 null(调用方按普通文本走)。
|
|
202
|
+
*
|
|
203
|
+
* 只认「整段就是一个 JSON 对象」这一种:不猜、不从散文里抠 JSON,
|
|
204
|
+
* 免得把一段真的在聊天的文本误判成素材。
|
|
205
|
+
*/
|
|
206
|
+
export function materialFromToolText(text, o = {}) {
|
|
207
|
+
const s = String(text ?? '').trim()
|
|
208
|
+
if (!s || (s[0] !== '{' && s[0] !== '[')) return null
|
|
209
|
+
let raw = null
|
|
210
|
+
try {
|
|
211
|
+
raw = JSON.parse(s)
|
|
212
|
+
} catch {
|
|
213
|
+
return null
|
|
214
|
+
}
|
|
215
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null
|
|
216
|
+
if (!(Array.isArray(raw.quotes) || Array.isArray(raw.facts) || raw[CONTRACT_MARK])) return null
|
|
217
|
+
const r = coerceMaterial(raw, o)
|
|
218
|
+
return r.ok ? r.material : null
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 任意一段文本 → 素材(观点级)。
|
|
223
|
+
*
|
|
224
|
+
* 给「没按契约返回、但内容值得留下」的来源用:它不算证据,但至少能被引用、
|
|
225
|
+
* 能进统计、能在以后被翻出来。正文放 `body`,不硬塞成原话(截断会丢字)。
|
|
226
|
+
*/
|
|
227
|
+
export function fromPlainText({ source = '', kind = 'opinion', text = '', at = null, key = '' } = {}) {
|
|
228
|
+
const body = String(text ?? '').trim()
|
|
229
|
+
if (!body || !source) return null
|
|
230
|
+
const grade = KIND_GRADE[kind] ?? KIND_GRADE.opinion
|
|
231
|
+
return {
|
|
232
|
+
source: clean(source, LIMITS.source),
|
|
233
|
+
key: clean(key, LIMITS.key) || `${clean(source, LIMITS.source)}:${body.slice(0, 40)}`,
|
|
234
|
+
at,
|
|
235
|
+
title: '',
|
|
236
|
+
kind,
|
|
237
|
+
tags: [],
|
|
238
|
+
facts: [],
|
|
239
|
+
quotes: [],
|
|
240
|
+
body: body.slice(0, LIMITS.body),
|
|
241
|
+
canVerify: false,
|
|
242
|
+
blocked: undefined,
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* 一条素材渲染成她能看的几行(给将来的非 B 站来源用;B 站那条仍走 `renderMaterial`)。
|
|
248
|
+
*
|
|
249
|
+
* 只标「谁写的」,不出现「几级」「可信度」这类字——等级是给渲染流程看的,
|
|
250
|
+
* 不是给她看的标签。
|
|
251
|
+
*/
|
|
252
|
+
export function renderMaterialText(material) {
|
|
253
|
+
if (!material) return ''
|
|
254
|
+
const lines = []
|
|
255
|
+
const title = material.title ? `《${material.title}》` : ''
|
|
256
|
+
const when = material.at ? ` · ${String(material.at).slice(0, 10)}` : ''
|
|
257
|
+
lines.push(`${title}${title ? ' · ' : ''}来源:${material.source}${when}`)
|
|
258
|
+
for (const f of material.facts ?? []) {
|
|
259
|
+
lines.push(` ${f.label ? `${f.label}:` : ''}${f.value}`)
|
|
260
|
+
}
|
|
261
|
+
if (material.body) lines.push(material.body)
|
|
262
|
+
for (const q of material.quotes ?? []) {
|
|
263
|
+
lines.push(` ${q.by}:「${q.text}」`)
|
|
264
|
+
}
|
|
265
|
+
return lines.join('\n')
|
|
266
|
+
}
|
package/lib/curiosity.js
CHANGED
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { isProofOnly, similarity } from './derive.js'
|
|
28
|
-
import { HER_TYPES, tsMs } from './schema.js'
|
|
28
|
+
import { HER_TYPES, tsMs, localDaysAgo } from './schema.js'
|
|
29
|
+
import { fillOwner } from './pronoun.js'
|
|
29
30
|
|
|
30
31
|
/** 一次醒来最多摆几个口子。多了就成了清单,不是惦记。 */
|
|
31
32
|
export const CURIOSITY_SHOW_MAX = 3
|
|
@@ -128,9 +129,9 @@ export function curiosityOf(events = [], now = Date.now()) {
|
|
|
128
129
|
return out
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
/** 几天前 / 今天 /
|
|
132
|
+
/** 几天前 / 今天 / 昨天——不给小时数,那不是她会算的东西。按本地日历日数。 */
|
|
132
133
|
function agoText(at, at0) {
|
|
133
|
-
const days =
|
|
134
|
+
const days = localDaysAgo(at, at0)
|
|
134
135
|
if (days <= 0) return '今天'
|
|
135
136
|
if (days === 1) return '昨天'
|
|
136
137
|
return `${days} 天前`
|
|
@@ -198,6 +199,6 @@ export function renderEcho(events = [], now = Date.now()) {
|
|
|
198
199
|
const age = at0 - leave
|
|
199
200
|
if (age < 0 || age > ECHO_HOURS * 3600000) return ''
|
|
200
201
|
const seen = lastSeenAt(events)
|
|
201
|
-
if (seen >= leave) return '
|
|
202
|
-
return '
|
|
202
|
+
if (seen >= leave) return fillOwner('你上次留的那句话,{T}后来来过了。')
|
|
203
|
+
return fillOwner('你上次留的那句话,{T}还没来过。')
|
|
203
204
|
}
|
package/lib/deliver.js
CHANGED
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
import { randomUUID } from 'node:crypto'
|
|
53
53
|
import { sessionRow } from './home.js'
|
|
54
54
|
import { recheckToolRestrict } from './restrict.js'
|
|
55
|
+
import { fillOwner } from './pronoun.js'
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
58
|
* 我们自己起的来源名。
|
|
@@ -112,7 +113,9 @@ export function fishMessage(text = WAKE_PING, { rpcId = '', kind = FISH_SOURCE_K
|
|
|
112
113
|
return {
|
|
113
114
|
id: `${kind}-${randomUUID()}`,
|
|
114
115
|
role: 'user',
|
|
115
|
-
|
|
116
|
+
// 正文里指主人的位置写成 `{T}`(见 lib/pronoun.js 文件头);投递前填一次。
|
|
117
|
+
// 这条消息也可能带她的原话(回执、便条),那些文本里没有 `{T}`,不会被碰。
|
|
118
|
+
content: [{ type: 'text', text: fillOwner(String(text ?? WAKE_PING)) }],
|
|
116
119
|
source,
|
|
117
120
|
}
|
|
118
121
|
}
|
|
@@ -146,8 +149,8 @@ export async function resolveLiveAgent(sc, sessionId) {
|
|
|
146
149
|
* 也不报错。结果就是每递一次话、每叫醒一次,宿主侧多一条空壳。
|
|
147
150
|
*
|
|
148
151
|
* 本机实测(`~/.dsh-fish/home` 这个 cwd,2026-11-05):52 条会话里 39 条只有一行
|
|
149
|
-
* session 头(≤400 字节);同一台机器上 `--D
|
|
150
|
-
* `--C-Users
|
|
152
|
+
* session 头(≤400 字节);同一台机器上 `--D-<工作区>--` 59 条只 4 条、
|
|
153
|
+
* `--C-Users-<用户名>-.dsh-<工作区>--` 102 条只 1 条 —— 空壳只长在这条路径上。
|
|
151
154
|
*
|
|
152
155
|
* `create({ workspaceId })`(换房走的那个、`lib/home.js` 的 `rotateTalkSession`)
|
|
153
156
|
* 才是「真的再开一间」,那个不动。
|