feiyu-brain 1.1.1 → 1.4.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/README.md +44 -0
- package/cordis.patch.yml +19 -0
- package/core/apps.js +279 -0
- package/core/driver.js +184 -0
- package/core/emotion.js +259 -0
- package/core/extract.js +39 -12
- package/core/memory.js +82 -2
- package/core/persona.js +6 -3
- package/docs/FEATURES.md +481 -0
- package/index.js +459 -7
- package/lib/dsh-plugin.mjs +350 -0
- package/lib/hostdeps.mjs +68 -0
- package/market/fangqiuci__feiyu-brain.yml +18 -0
- package/package.json +12 -4
- package/store.js +15 -2
- package/market/fangqiuci_feiyu-brain.yml +0 -94
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* feiyu-brain —— DSH 插件入口
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* 同一个包有两种用法:
|
|
5
|
+
* ① 库:`import { createBrain } from 'feiyu-brain'`(下面 re-export 了全部)
|
|
6
|
+
* ② 插件:`dsh plugin add feiyu-brain` → 注册 6 个工具,模型可以直接读写这条鱼
|
|
7
|
+
*
|
|
8
|
+
* 工具是**读写大脑**,不是"生成对话"——对话仍然由宿主自己的模型完成。
|
|
9
|
+
*
|
|
10
|
+
* feiyu_status 她现在什么状态(人设/自知/意识流/身体/记忆/不变量)
|
|
11
|
+
* feiyu_wake 取"此刻的她",宿主把它拼进 system prompt
|
|
12
|
+
* feiyu_observe 记一次经历(权重会动、记忆会进)
|
|
13
|
+
* feiyu_tick 每日结算(衰减 / 遗忘 / 蜕皮)
|
|
14
|
+
* feiyu_feel 对一件事产生感受(PAD → 找词)
|
|
15
|
+
* feiyu_app 真的开 App / 截屏 / 卸载(adb 或 PowerShell,留证据)
|
|
16
|
+
*
|
|
17
|
+
* 设计约束:
|
|
18
|
+
* - `@deepseek-ai/dsh-tools` 是 optional peer,桌面版可能没有 ⇒ 取不到就降级,
|
|
19
|
+
* 用 identity 透传,**不能让整条插件不激活**。
|
|
20
|
+
* - 工具返回值必须是无损 JSON(宿主会对函数/循环引用报错)。
|
|
21
|
+
* - 找不到角色卡时不是抛异常,而是返回一句话说明怎么配。
|
|
22
|
+
* ============================================================================
|
|
23
|
+
*/
|
|
24
|
+
import { loadHostPackage } from './hostdeps.mjs';
|
|
25
|
+
import * as brain from '../index.js';
|
|
26
|
+
import { BODY_KINDS } from '../core/body.js';
|
|
27
|
+
|
|
28
|
+
export * from '../index.js';
|
|
29
|
+
|
|
30
|
+
export const name = 'feiyu-brain';
|
|
31
|
+
// 只声明 tools:没有 webServer 也要能装
|
|
32
|
+
export const inject = ['tools'];
|
|
33
|
+
|
|
34
|
+
let defineTool = null;
|
|
35
|
+
try {
|
|
36
|
+
const dshTools = await loadHostPackage('dsh-tools');
|
|
37
|
+
if (typeof dshTools?.defineTool === 'function') defineTool = dshTools.defineTool;
|
|
38
|
+
} catch { /* 降级 */ }
|
|
39
|
+
if (typeof defineTool !== 'function') defineTool = (options) => options;
|
|
40
|
+
|
|
41
|
+
/** 宿主只吃无损 JSON */
|
|
42
|
+
const safe = (v) => {
|
|
43
|
+
if (v === undefined || v === null || typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') return v;
|
|
44
|
+
try { return JSON.parse(JSON.stringify(v)); } catch { return String(v); }
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const textOutput = {
|
|
48
|
+
schema: { type: 'object', properties: {}, additionalProperties: true },
|
|
49
|
+
render: (_args, value) => {
|
|
50
|
+
const text = value && typeof value === 'object' && typeof value.text === 'string'
|
|
51
|
+
? value.text
|
|
52
|
+
: JSON.stringify(value, null, 2);
|
|
53
|
+
return [{ type: 'text', text }];
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const pickStr = (v, fallback = '') => (typeof v === 'string' && v.trim() ? v.trim() : fallback);
|
|
58
|
+
|
|
59
|
+
function fail(text, code = 'E_BRAIN') {
|
|
60
|
+
return { ok: false, code, text: `❌ ${text}` };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 大脑抛错时,翻成人能照着做的话 */
|
|
64
|
+
function explain(error) {
|
|
65
|
+
const msg = String(error?.message ?? error);
|
|
66
|
+
if (/找不到角色卡/.test(msg)) {
|
|
67
|
+
return `${msg}
|
|
68
|
+
|
|
69
|
+
怎么配(二选一):
|
|
70
|
+
· 把角色卡放到 <dataDir>/../roles/<名字>.md,并在插件设置里填 roleDir
|
|
71
|
+
· 或者把 current-role.json 放进 dataDir:{"role":"辞辞"}
|
|
72
|
+
|
|
73
|
+
这块的规则见 docs/MIGRATION.md。`;
|
|
74
|
+
}
|
|
75
|
+
return msg;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const fmtPct = (n) => `${(Number(n) * 100).toFixed(1)}%`;
|
|
79
|
+
|
|
80
|
+
export function apply(ctx, entryConfig = {}) {
|
|
81
|
+
const conf = {
|
|
82
|
+
brainId: pickStr(entryConfig?.brainId, 'default'),
|
|
83
|
+
dataDir: pickStr(entryConfig?.dataDir, process.env.FEIYU_DATA_DIR || ''),
|
|
84
|
+
roleDir: pickStr(entryConfig?.roleDir, process.env.FEIYU_ROLE_DIR || ''),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
if (conf.dataDir || conf.roleDir) {
|
|
88
|
+
brain.configure({
|
|
89
|
+
dataDir: conf.dataDir || undefined,
|
|
90
|
+
roleDir: conf.roleDir || undefined,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!ctx?.tools?.register) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const tool = (spec) => ctx.tools.register(defineTool({
|
|
99
|
+
...spec,
|
|
100
|
+
output: spec.output || textOutput,
|
|
101
|
+
async execute(args = {}) {
|
|
102
|
+
try {
|
|
103
|
+
return safe(await spec.execute(args));
|
|
104
|
+
} catch (e) {
|
|
105
|
+
return safe(fail(`工具执行出错:${explain(e)}`, 'E_THROWN'));
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
const idOf = (args) => pickStr(args?.id, conf.brainId);
|
|
111
|
+
|
|
112
|
+
/* ── 1. 状态 ─────────────────────────────────────────── */
|
|
113
|
+
tool({
|
|
114
|
+
name: 'feiyu_status',
|
|
115
|
+
description:
|
|
116
|
+
'看这条鱼现在的状态:人设卡、自知风格(四种方向的份量)、意识流档位、身体(手机/平板/电脑)、'
|
|
117
|
+
+ '命题数量、记忆计数、以及十二条不变量的自检结果。不修改任何东西。',
|
|
118
|
+
parameters: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
properties: {
|
|
121
|
+
id: { type: 'string', description: '鱼的 id,默认 default' },
|
|
122
|
+
},
|
|
123
|
+
additionalProperties: false,
|
|
124
|
+
},
|
|
125
|
+
async execute(args) {
|
|
126
|
+
const id = idOf(args);
|
|
127
|
+
const s = brain.snapshot(id);
|
|
128
|
+
const style = Object.entries(s.style)
|
|
129
|
+
.map(([k, v]) => `${k} ${fmtPct(v)}`)
|
|
130
|
+
.join(' / ');
|
|
131
|
+
|
|
132
|
+
const lines = [
|
|
133
|
+
`🐟 ${s.id} · 人设卡 ${s.roleCard}`,
|
|
134
|
+
`自知 ${s.styleName}(${style})`,
|
|
135
|
+
`意识流 ${s.flow.name}(${s.flow.level})`,
|
|
136
|
+
`身体 ${s.body ? `${s.body.label}(${s.body.screen},${s.body.posture},${s.body.ownership})` : '无'}`,
|
|
137
|
+
`命题 ${s.weights.count} 条(身份 ${s.weights.identity} 条,总权重 ${s.weights.totalWeight})`,
|
|
138
|
+
`记忆 经历 ${s.memory.episodes} / 印象 ${s.memory.impressions} / 卡片 ${s.memory.cards} / 蜕皮 ${s.memory.formerSelves} / 遗忘 ${s.memory.forgotten}`,
|
|
139
|
+
`平台 ${Object.keys(s.apps ?? {}).length ? Object.entries(s.apps).map(([k, v]) => `${k} ${v.seen}条`).join(' · ') : '还没在任何平台上有记录'}`,
|
|
140
|
+
`情绪 ${s.emotion.stage === 1 ? '只会说"说不清"' : `会 ${s.emotion.words.length} 个词`}`,
|
|
141
|
+
`观察 ${s.observations} 次`,
|
|
142
|
+
'',
|
|
143
|
+
'权重最高的五条:',
|
|
144
|
+
...s.weights.top.map((u) => ` ${u.id} ${u.weight} ${u.text}`),
|
|
145
|
+
'',
|
|
146
|
+
s.invariants.length ? `不变量违规 ${s.invariants.length} 条:\n${s.invariants.map((v) => ` ✘ ${v.id}: ${v.msg}`).join('\n')}` : '不变量:全部通过 ✔',
|
|
147
|
+
];
|
|
148
|
+
return { ok: true, text: lines.join('\n'), snapshot: s };
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
/* ── 2. 唤醒段 ───────────────────────────────────────── */
|
|
153
|
+
tool({
|
|
154
|
+
name: 'feiyu_wake',
|
|
155
|
+
description:
|
|
156
|
+
'取"此刻的她"——一段可直接拼进 system prompt 的定长文本(人设 brief + 手上的东西 + 想到的事)。'
|
|
157
|
+
+ '不记录经历。触发者为谁、说了什么,传 sender / text 能让检索更准。',
|
|
158
|
+
parameters: {
|
|
159
|
+
type: 'object',
|
|
160
|
+
properties: {
|
|
161
|
+
id: { type: 'string', description: '鱼的 id,默认 default' },
|
|
162
|
+
sender: { type: 'string', description: '当前说话的人,用于检索对他的记忆' },
|
|
163
|
+
text: { type: 'string', description: '他说的话,用于关键词检索' },
|
|
164
|
+
},
|
|
165
|
+
additionalProperties: false,
|
|
166
|
+
},
|
|
167
|
+
async execute(args) {
|
|
168
|
+
const id = idOf(args);
|
|
169
|
+
const text = brain.wakeLine(id, {
|
|
170
|
+
sender: pickStr(args?.sender),
|
|
171
|
+
text: pickStr(args?.text),
|
|
172
|
+
});
|
|
173
|
+
if (!text.trim()) return fail('大脑没有产出内容,先跑 feiyu_status 看看');
|
|
174
|
+
return { ok: true, text, chars: text.length };
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/* ── 3. 记一次经历 ───────────────────────────────────── */
|
|
179
|
+
tool({
|
|
180
|
+
name: 'feiyu_observe',
|
|
181
|
+
description:
|
|
182
|
+
'让她"经历"一件事:相关的命题权重 ±0.01,记忆里进一条 episode,印象里的互动次数 +1。'
|
|
183
|
+
+ '这是她长大的唯一途径——不调用,人设就永远不变。',
|
|
184
|
+
parameters: {
|
|
185
|
+
type: 'object',
|
|
186
|
+
properties: {
|
|
187
|
+
id: { type: 'string', description: '鱼的 id,默认 default' },
|
|
188
|
+
who: { type: 'string', description: '和谁发生了这件事' },
|
|
189
|
+
text: { type: 'string', description: '发生了什么(她听到/看到的那句话)' },
|
|
190
|
+
feel: { type: 'string', description: '她当时的感受,可留空' },
|
|
191
|
+
app: { type: 'string', description: '如果是某个平台上的事:douyin / bilibili / wechat / qq' },
|
|
192
|
+
kind: { type: 'string', description: '内容类型,例如 解压 / 搞笑 / 做饭,用来累计口味' },
|
|
193
|
+
reaction: { type: 'number', description: '她的反应,-1 到 1,正数表示喜欢' },
|
|
194
|
+
},
|
|
195
|
+
required: ['text'],
|
|
196
|
+
additionalProperties: false,
|
|
197
|
+
},
|
|
198
|
+
async execute(args) {
|
|
199
|
+
const id = idOf(args);
|
|
200
|
+
const who = pickStr(args?.who);
|
|
201
|
+
const text = pickStr(args?.text);
|
|
202
|
+
if (!text) return fail('text 不能为空');
|
|
203
|
+
|
|
204
|
+
const app = pickStr(args?.app);
|
|
205
|
+
const r = brain.observe(id, {
|
|
206
|
+
who,
|
|
207
|
+
text,
|
|
208
|
+
what: text.slice(0, 80),
|
|
209
|
+
feel: pickStr(args?.feel),
|
|
210
|
+
via: app ? `app:${app}` : 'dsh',
|
|
211
|
+
...(app ? { app, kind: pickStr(args?.kind), reaction: Number(args?.reaction ?? 0) } : {}),
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const changed = r.consistent.length + r.conflicting.length;
|
|
215
|
+
return {
|
|
216
|
+
ok: true,
|
|
217
|
+
text: [
|
|
218
|
+
`记下了:${who ? `${who}「${text}」` : `「${text}」`}`,
|
|
219
|
+
app ? `平台 ${app}${pickStr(args?.kind) ? ` / ${pickStr(args?.kind)}` : ''}` : '',
|
|
220
|
+
`权重 一致 ${r.consistent.length} 条 / 冲突 ${r.conflicting.length} 条${changed ? '' : '(没匹配到命题,人设不动)'}`,
|
|
221
|
+
r.label ? `归因 ${r.label}` : '',
|
|
222
|
+
].filter(Boolean).join('\n'),
|
|
223
|
+
matched: changed,
|
|
224
|
+
};
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
/* ── 4. 每日结算 ─────────────────────────────────────── */
|
|
229
|
+
tool({
|
|
230
|
+
name: 'feiyu_tick',
|
|
231
|
+
description:
|
|
232
|
+
'跑一次每日结算:命题衰减、记忆 TTL 到期遗忘、权重到底的蜕皮成"我以前……"。幂等,一天跑多次也只结算一次。',
|
|
233
|
+
parameters: {
|
|
234
|
+
type: 'object',
|
|
235
|
+
properties: {
|
|
236
|
+
id: { type: 'string', description: '鱼的 id,默认 default' },
|
|
237
|
+
},
|
|
238
|
+
additionalProperties: false,
|
|
239
|
+
},
|
|
240
|
+
async execute(args) {
|
|
241
|
+
const id = idOf(args);
|
|
242
|
+
const before = brain.snapshot(id);
|
|
243
|
+
const b = brain.settleBrain(id);
|
|
244
|
+
const after = brain.snapshot(id);
|
|
245
|
+
const shed = after.memory.formerSelves - before.memory.formerSelves;
|
|
246
|
+
const forgot = after.memory.forgotten - before.memory.forgotten;
|
|
247
|
+
return {
|
|
248
|
+
ok: true,
|
|
249
|
+
text: [
|
|
250
|
+
'结算完成。',
|
|
251
|
+
`蜕皮 ${shed > 0 ? `+${shed} 条沉进"我以前……"` : '0'}`,
|
|
252
|
+
`遗忘 ${forgot > 0 ? `+${forgot} 条(真的没有了)` : '0'}`,
|
|
253
|
+
`命题 ${after.weights.count} 条,总权重 ${after.weights.totalWeight}`,
|
|
254
|
+
].join('\n'),
|
|
255
|
+
shed,
|
|
256
|
+
forgot,
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
/* ── 5. 情绪 ─────────────────────────────────────────── */
|
|
262
|
+
tool({
|
|
263
|
+
name: 'feiyu_feel',
|
|
264
|
+
description:
|
|
265
|
+
'让她对一件事产生感受:先算 PAD 三维(愉悦/唤醒/掌控),再找词。'
|
|
266
|
+
+ '同一件事,有劲的鱼偏向生气,累了的鱼偏向委屈——由人设和当前状态算出来,不查表。'
|
|
267
|
+
+ '词表空的时候只会说「我不知道,就是很不舒服」,这是正常的。',
|
|
268
|
+
parameters: {
|
|
269
|
+
type: 'object',
|
|
270
|
+
properties: {
|
|
271
|
+
id: { type: 'string', description: '鱼的 id,默认 default' },
|
|
272
|
+
valence: { type: 'number', description: '这件事对她好不好,-1 到 1' },
|
|
273
|
+
intensity: { type: 'number', description: '强度,0 到 1' },
|
|
274
|
+
what: { type: 'string', description: '发生了什么' },
|
|
275
|
+
},
|
|
276
|
+
required: ['valence'],
|
|
277
|
+
additionalProperties: false,
|
|
278
|
+
},
|
|
279
|
+
async execute(args) {
|
|
280
|
+
const id = idOf(args);
|
|
281
|
+
const v = Math.max(-1, Math.min(1, Number(args?.valence ?? 0)));
|
|
282
|
+
const i = Math.max(0, Math.min(1, Number(args?.intensity ?? 0.5)));
|
|
283
|
+
const r = brain.feel(id, { valence: v, intensity: i, what: pickStr(args?.what) });
|
|
284
|
+
return {
|
|
285
|
+
ok: true,
|
|
286
|
+
text: `${r.text}\n(PAD ${r.pad.map((x) => x.toFixed(2)).join(' / ')},阶段 ${r.stage},会 ${r.knownWords} 个词)`,
|
|
287
|
+
pad: r.pad,
|
|
288
|
+
stage: r.stage,
|
|
289
|
+
label: r.label,
|
|
290
|
+
};
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
/* ── 6. 身体动作 ─────────────────────────────────────── */
|
|
295
|
+
tool({
|
|
296
|
+
name: 'feiyu_app',
|
|
297
|
+
description:
|
|
298
|
+
'让她真的动起来:开 App、截屏、卸载(卸载要过临界点 + 三问)。'
|
|
299
|
+
+ '走真实设备——手机/平板用 adb,电脑用 PowerShell。没有设备返回 E_NO_DEVICE。'
|
|
300
|
+
+ '每个动作都留证据;没有证据的动作不算发生。',
|
|
301
|
+
parameters: {
|
|
302
|
+
type: 'object',
|
|
303
|
+
properties: {
|
|
304
|
+
id: { type: 'string', description: '鱼的 id,默认 default' },
|
|
305
|
+
action: { type: 'string', description: 'open / screenshot / uninstall' },
|
|
306
|
+
package: { type: 'string', description: 'Android 包名,例如 com.ss.android.ugc.aweme' },
|
|
307
|
+
target: { type: 'string', description: '电脑上要启动的程序' },
|
|
308
|
+
why: { type: 'string', description: '卸载 Q1:为什么想删' },
|
|
309
|
+
consequence: { type: 'string', description: '卸载 Q3:删了会怎样' },
|
|
310
|
+
},
|
|
311
|
+
required: ['action'],
|
|
312
|
+
additionalProperties: false,
|
|
313
|
+
},
|
|
314
|
+
async execute(args) {
|
|
315
|
+
const id = idOf(args);
|
|
316
|
+
const action = pickStr(args?.action).toLowerCase();
|
|
317
|
+
|
|
318
|
+
if (action === 'uninstall') {
|
|
319
|
+
const r = await brain.requestUninstall(id, pickStr(args?.package), {
|
|
320
|
+
why: pickStr(args?.why),
|
|
321
|
+
fits: true,
|
|
322
|
+
consequence: pickStr(args?.consequence),
|
|
323
|
+
});
|
|
324
|
+
if (r.ok === false) return { ok: false, code: r.code, text: `❌ ${r.reason ?? r.code}` };
|
|
325
|
+
return { ok: true, text: `已卸载 ${args.package}\n证据:${r.evidence}` };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const map = {
|
|
329
|
+
open: { type: 'open_app', package: pickStr(args?.package), target: pickStr(args?.target), capability: 2 },
|
|
330
|
+
screenshot: { type: 'screenshot', capability: 1 },
|
|
331
|
+
};
|
|
332
|
+
const act = map[action];
|
|
333
|
+
if (!act) return { ok: false, code: 'E_ARGS', text: '❌ action 只能是 open / screenshot / uninstall' };
|
|
334
|
+
|
|
335
|
+
const r = await brain.execAction(id, act);
|
|
336
|
+
if (r.ok === false) return { ok: false, code: r.code, text: `❌ ${r.reason ?? r.code}` };
|
|
337
|
+
return { ok: true, text: `✔ 做完了(${action})\n证据:${r.evidence ?? '(无)'}` };
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
/* ── 配置检查(不注册工具,只打一行日志)───────────── */
|
|
342
|
+
try {
|
|
343
|
+
const s = brain.snapshot(conf.brainId);
|
|
344
|
+
ctx.logger?.info?.(`[feiyu-brain] ${s.id} · ${s.roleCard} · ${s.weights.count} 条命题 · ${s.styleName}`);
|
|
345
|
+
} catch {
|
|
346
|
+
ctx.logger?.warn?.('[feiyu-brain] 还没有角色卡,工具会提示你配置(见 docs/MIGRATION.md)');
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export { BODY_KINDS };
|
package/lib/hostdeps.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/hostdeps.mjs —— 从**宿主那棵树**里取 `@deepseek-ai/*`(取不到就降级)
|
|
3
|
+
*
|
|
4
|
+
* 为什么不能直接 `import '@deepseek-ai/dsh-tools'`:
|
|
5
|
+
* 插件是以 `link:` 装进 profile 的,Node 默认按真实路径解析 ⇒ 从
|
|
6
|
+
* `~/.dsh/plugins/<插件>/lib/` 往上找 node_modules,进不到 profile 的树。
|
|
7
|
+
* 裸 import 会静默失败,工具就一个都注册不上。
|
|
8
|
+
*
|
|
9
|
+
* 顺序:① 直接 import(自己带了依赖)→ ② 宿主 profile 树 → ③ null(降级)
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
12
|
+
import { homedir } from 'node:os';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { pathToFileURL } from 'node:url';
|
|
15
|
+
|
|
16
|
+
function dshHome() {
|
|
17
|
+
return process.env.DSH_HOME || join(homedir(), '.dsh');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** 可能藏着 @deepseek-ai 的目录,按可能性排序 */
|
|
21
|
+
export function candidateRoots() {
|
|
22
|
+
const roots = [];
|
|
23
|
+
const push = (p) => { if (p && !roots.includes(p)) roots.push(p); };
|
|
24
|
+
|
|
25
|
+
if (process.env.DSH_HOST_MODULES) push(process.env.DSH_HOST_MODULES);
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
for (const profile of readdirSync(join(dshHome(), 'profiles'))) {
|
|
29
|
+
push(join(dshHome(), 'profiles', profile, 'node_modules', '@deepseek-ai'));
|
|
30
|
+
}
|
|
31
|
+
} catch { /* 没有 profiles 就算了 */ }
|
|
32
|
+
|
|
33
|
+
push(join(dshHome(), 'node_modules', '@deepseek-ai'));
|
|
34
|
+
return roots;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function entryUrlFor(root, name) {
|
|
38
|
+
try {
|
|
39
|
+
const dir = join(root, name);
|
|
40
|
+
const pkgFile = join(dir, 'package.json');
|
|
41
|
+
if (!existsSync(pkgFile)) return null;
|
|
42
|
+
const pkg = JSON.parse(readFileSync(pkgFile, 'utf8'));
|
|
43
|
+
const dot = pkg.exports?.['.'];
|
|
44
|
+
const rel = typeof dot === 'string' ? dot : (dot?.import || dot?.default || pkg.module || pkg.main);
|
|
45
|
+
if (!rel) return null;
|
|
46
|
+
const file = join(dir, String(rel).replace(/^\.\//, ''));
|
|
47
|
+
return existsSync(file) ? pathToFileURL(file).href : null;
|
|
48
|
+
} catch { return null; }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 取一个 @deepseek-ai 包。
|
|
53
|
+
* @param {string} name 例如 'dsh-tools'
|
|
54
|
+
* @returns {Promise<any|null>}
|
|
55
|
+
*/
|
|
56
|
+
export async function loadHostPackage(name) {
|
|
57
|
+
try {
|
|
58
|
+
return await import(`@deepseek-ai/${name}`);
|
|
59
|
+
} catch { /* 继续往下找 */ }
|
|
60
|
+
|
|
61
|
+
for (const root of candidateRoots()) {
|
|
62
|
+
const url = entryUrlFor(root, name);
|
|
63
|
+
if (!url) continue;
|
|
64
|
+
try { return await import(url); } catch { /* 换下一个 */ }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# DSH 插件市场条目
|
|
2
|
+
#
|
|
3
|
+
# 提交位置:awesome-dsh-plugin/awesome-dsh-plugin
|
|
4
|
+
# data/plugins/fangqiuci__feiyu-brain.yml
|
|
5
|
+
# 文件名是 **双下划线**(<owner>__<repo>.yml),不是单个。
|
|
6
|
+
#
|
|
7
|
+
# 提交前确认三件事(CI 会自动查):
|
|
8
|
+
# ① 仓库 package.json 里有 "dsh": { "bundle": { "patch": "./cordis.patch.yml" } }
|
|
9
|
+
# ② 仓库创建满 1 天(未满也能提,CI 会几小时后自动重跑)
|
|
10
|
+
# ③ 仓库打了 `dsh-plugin` topic
|
|
11
|
+
|
|
12
|
+
url: https://github.com/fangqiuci/feiyu-brain
|
|
13
|
+
name: fangqiuci/feiyu-brain
|
|
14
|
+
category: memory
|
|
15
|
+
|
|
16
|
+
description:
|
|
17
|
+
en: 'Persona-grounded brain kernel with six tools (feiyu_status, feiyu_wake, feiyu_observe, feiyu_tick, feiyu_feel, feiyu_app): weighted traits that erode into memories, a 30-day recall window, PAD emotions, and phone/tablet/desktop bodies.'
|
|
18
|
+
zh: '以人设为根的大脑内核,提供 6 个工具(feiyu_status / feiyu_wake / feiyu_observe / feiyu_tick / feiyu_feel / feiyu_app):带权重的命题随经历涨落、蜕皮成记忆,30 天回忆窗口,PAD 三维情绪,手机/平板/电脑三具身体。'
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feiyu-brain",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "大肥鱼的大脑内核:人设是根,情绪/记忆/意识流/归因都是从人设长出来的。DSH 插件 + 平台无关库。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=20"
|
|
17
17
|
},
|
|
18
|
-
"main": "./
|
|
18
|
+
"main": "./lib/dsh-plugin.mjs",
|
|
19
19
|
"exports": {
|
|
20
|
-
".": "./
|
|
20
|
+
".": "./lib/dsh-plugin.mjs",
|
|
21
|
+
"./lib": "./lib/dsh-plugin.mjs",
|
|
21
22
|
"./adapters": "./adapters/index.js",
|
|
22
23
|
"./adapters/qq-bridge": "./adapters/qq-bridge.js",
|
|
23
24
|
"./adapters/tencent-official": "./adapters/tencent-official.js",
|
|
@@ -33,14 +34,21 @@
|
|
|
33
34
|
"cli.mjs",
|
|
34
35
|
"demo.mjs",
|
|
35
36
|
"selftest.mjs",
|
|
37
|
+
"cordis.patch.yml",
|
|
36
38
|
"core/",
|
|
37
39
|
"adapters/",
|
|
40
|
+
"lib/",
|
|
38
41
|
"docs/",
|
|
39
42
|
"examples/",
|
|
40
43
|
"market/",
|
|
41
44
|
"README.md",
|
|
42
45
|
"LICENSE"
|
|
43
46
|
],
|
|
47
|
+
"dsh": {
|
|
48
|
+
"bundle": {
|
|
49
|
+
"patch": "./cordis.patch.yml"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
44
52
|
"keywords": [
|
|
45
53
|
"llm",
|
|
46
54
|
"agent",
|
package/store.js
CHANGED
|
@@ -102,10 +102,23 @@ export function listBrains() {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
export function loadBrain(id) {
|
|
105
|
-
|
|
105
|
+
const file = brainFile(id);
|
|
106
|
+
const main = readJson(file, null);
|
|
107
|
+
if (main) return main;
|
|
108
|
+
// 主文件坏了就退到备份——评审说得对,单文件损坏不该等于丢档
|
|
109
|
+
const bak = readJson(`${file}.bak`, null);
|
|
110
|
+
if (bak) {
|
|
111
|
+
try { writeJsonAtomic(file, bak); } catch { /* 修不回来也不影响这次读 */ }
|
|
112
|
+
return bak;
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
106
115
|
}
|
|
107
116
|
|
|
108
117
|
export function saveBrain(brain) {
|
|
109
|
-
|
|
118
|
+
const file = brainFile(brain.id);
|
|
119
|
+
try {
|
|
120
|
+
if (fs.existsSync(file)) fs.copyFileSync(file, `${file}.bak`);
|
|
121
|
+
} catch { /* 备份失败不影响写入 */ }
|
|
122
|
+
writeJsonAtomic(file, brain);
|
|
110
123
|
return brain;
|
|
111
124
|
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# DSH 插件市场条目
|
|
2
|
-
#
|
|
3
|
-
# 用法:复制到市场仓库 data/plugins/ 下,文件名
|
|
4
|
-
# fangqiuci_feiyu-brain.yml
|
|
5
|
-
# 然后按 PR 模板提一个 PR。
|
|
6
|
-
#
|
|
7
|
-
# 字段名以市场仓库当前 schema 为准。隔壁 dsh-doubao-video 的条目在
|
|
8
|
-
# data/plugins/fangqiuci_dsh-doubao-video.yml ,category 必须是 workflow。
|
|
9
|
-
|
|
10
|
-
name: feiyu-brain
|
|
11
|
-
displayName: 大肥鱼大脑
|
|
12
|
-
version: 1.1.1
|
|
13
|
-
category: workflow
|
|
14
|
-
author: fangqiuci
|
|
15
|
-
license: MIT
|
|
16
|
-
|
|
17
|
-
description: >-
|
|
18
|
-
平台无关的认知内核:从一张人设卡长出记忆、情绪、意识流和归因。
|
|
19
|
-
不绑定任何平台,老用户接自己的桥接,新用户走腾讯官方开放平台。
|
|
20
|
-
|
|
21
|
-
tarball: "https://registry.npmjs.org/feiyu-brain/-/feiyu-brain-1.1.1.tgz"
|
|
22
|
-
# 也可以用 GitHub Release 直链:
|
|
23
|
-
# tarball: "https://github.com/fangqiuci/feiyu-brain/releases/download/v1.1.1/feiyu-brain-1.1.1.tgz"
|
|
24
|
-
|
|
25
|
-
repository: "https://github.com/fangqiuci/feiyu-brain"
|
|
26
|
-
homepage: "https://github.com/fangqiuci/feiyu-brain#readme"
|
|
27
|
-
bugs: "https://github.com/fangqiuci/feiyu-brain/issues"
|
|
28
|
-
|
|
29
|
-
dsh: ">=0.2.0"
|
|
30
|
-
node: ">=20"
|
|
31
|
-
|
|
32
|
-
keywords:
|
|
33
|
-
- 人格
|
|
34
|
-
- 记忆
|
|
35
|
-
- 情绪
|
|
36
|
-
- 插件
|
|
37
|
-
- qq-bot
|
|
38
|
-
|
|
39
|
-
# 市场审核会看这一栏:它会不会自己联网 / 读文件 / 执行命令
|
|
40
|
-
permissions:
|
|
41
|
-
network: false
|
|
42
|
-
filesystem: data-dir
|
|
43
|
-
exec: false
|
|
44
|
-
|
|
45
|
-
longDescription: |
|
|
46
|
-
## 它是什么
|
|
47
|
-
|
|
48
|
-
一颗大脑,不是一套规则。
|
|
49
|
-
|
|
50
|
-
给它一张人设卡(`roles/<名字>.md`),它抽出带权重的命题;
|
|
51
|
-
每一次经历让权重动 ±0.01,掉到 0.15 就蜕皮成"我以前……";
|
|
52
|
-
记忆 30 天窗口,被反复提起才升级长期;忘了就是真的没有。
|
|
53
|
-
|
|
54
|
-
唤醒时它只产出定长的一段:
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
【此刻的她】你是 DeepSeek 的鲸鱼形象……
|
|
58
|
-
【手上的东西】自己的手机(竖屏,躺着 / 走着)
|
|
59
|
-
【想到的】
|
|
60
|
-
扶摇说过「你嘴真硬」,我当时有点得意
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
剩下的事(怎么回、回几条、要不要回)由宿主交给自己的模型。
|
|
64
|
-
|
|
65
|
-
## 三具身体
|
|
66
|
-
|
|
67
|
-
手机 / 平板 / 电脑。摸哪具是**人设算出来的**:
|
|
68
|
-
好动摸手机,累了拿平板,爱折腾的开电脑。
|
|
69
|
-
|
|
70
|
-
权限四级:L1 观察 / L2 操作 / L3 破坏 / L4 金钱。
|
|
71
|
-
花钱是两道门:身体要有 L4,这一次还要批准。
|
|
72
|
-
|
|
73
|
-
## 为什么平台无关
|
|
74
|
-
|
|
75
|
-
内核只认一种事件:`{ sender, text, chatId }`。
|
|
76
|
-
换平台 = 换一个适配器,大脑一行不动。
|
|
77
|
-
|
|
78
|
-
| 适配器 | 给谁 |
|
|
79
|
-
|---|---|
|
|
80
|
-
| `qq-bridge` | 老用户,接自己现有的桥接 |
|
|
81
|
-
| `tencent-official` | 新用户,腾讯官方机器人开放平台 |
|
|
82
|
-
| `universal` | 任意平台,自带传输 |
|
|
83
|
-
|
|
84
|
-
## 不含什么
|
|
85
|
-
|
|
86
|
-
- 不含任何 QQ 协议实现
|
|
87
|
-
- 不逆向、不伪造签名、不绕过限流
|
|
88
|
-
- 不内置桥接,不代替你决定接哪个身体
|
|
89
|
-
|
|
90
|
-
## 安装
|
|
91
|
-
|
|
92
|
-
```bash
|
|
93
|
-
npm i feiyu-brain
|
|
94
|
-
```
|