dsh-cerebrum 0.1.0 → 0.1.2
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 +3 -0
- package/docs/publish.md +6 -0
- package/lib/api.js +4 -1
- package/lib/client.js +163 -1
- package/lib/config.js +8 -0
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,6 +55,9 @@ dsh plugin --profile desktop add D:\workspace\dsh-cerebrum
|
|
|
55
55
|
|
|
56
56
|
装好插件后,输入框上方会出现 🧠 芯片:显示当前情绪、记忆量、好感度级别;点击展开**大脑仪表盘**(效价/唤醒/支配条、DA/5-HT/NE/ACh、五因素、记忆/技能/意图/好感)。
|
|
57
57
|
|
|
58
|
+
- **不喜欢可以关掉**:面板里的 🙈 隐藏芯片(点小 🧠 恢复);彻底关闭用配置 `ui.enabled: false`(重启宿主生效,芯片完全不出现);
|
|
59
|
+
- 面板可**拖动**(按住标题栏)、可 **📌 固定**到输入栏上方成横条;
|
|
60
|
+
- **宠物联动(免配置)**:检测到同源的 `dsh-pet`(`/dsh-pet-7340`)时,情绪变化会自动推给桌宠——加锁 → 让宠物说一句大脑台词 → 释放锁;不需要用户配置。不想要联动可设 `ui.drivePet: false`;
|
|
58
61
|
- 数据来自宿主内置的 127.0.0.1 只读 API(`http://127.0.0.1:18734`,端口可配 `config.api.port`);
|
|
59
62
|
- UI 只读:修改记忆/情绪仍通过 `cerebrum_*` 工具;
|
|
60
63
|
- 免构建 client bundle(`lib/client.js`),与宿主同一个安装包——**装一个插件,大脑 + 面板都有**。
|
package/docs/publish.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# 发布 dsh-cerebrum 到 DSH 插件市场
|
|
2
2
|
|
|
3
|
+
> **发布状态(2026-10-28)**
|
|
4
|
+
> - GitHub 公开仓库:https://github.com/liu-wen-wu/dsh-cerebrum(main + tag v0.1.1,SSH 推送)
|
|
5
|
+
> - npm:`dsh-cerebrum@0.1.1` 已上线(latest;0.1.0 为上一版)
|
|
6
|
+
> - 市场收录申请:https://github.com/polang233/dsh-plugin-index/issues/121
|
|
7
|
+
> - 本地安装:`dsh-cerebrum@link:D:/workspace/dsh-cerebrum`(desktop profile,已热加载验证)
|
|
8
|
+
|
|
3
9
|
> 目标市场:dshopen.org(DSH 应用内「插件市场/Discover」读取的社区索引,`https://dshopen.org/index.json`)。
|
|
4
10
|
> 收录流程由 [dsh-plugin-index](https://github.com/polang233/dsh-plugin-index) 人工审核:**公开仓库 + 可安装的 npm 版本 + 明确许可证**,三样齐全后提 issue 收录。
|
|
5
11
|
|
package/lib/api.js
CHANGED
|
@@ -31,7 +31,7 @@ const send = (res, status, payload) => {
|
|
|
31
31
|
res.end(JSON.stringify(payload))
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export const startBrainApi = (service, { port = 18734, logger = console } = {}) => {
|
|
34
|
+
export const startBrainApi = (service, { port = 18734, ui = { enabled: true }, logger = console } = {}) => {
|
|
35
35
|
const server = http.createServer((req, res) => {
|
|
36
36
|
if (req.method === 'OPTIONS') return send(res, 204, {})
|
|
37
37
|
if (req.method !== 'GET') return send(res, 405, { error: 'method not allowed' })
|
|
@@ -40,6 +40,9 @@ export const startBrainApi = (service, { port = 18734, logger = console } = {})
|
|
|
40
40
|
switch (url.pathname) {
|
|
41
41
|
case '/ping':
|
|
42
42
|
return send(res, 200, { ok: true, name: 'dsh-cerebrum', uptimeMs: Date.now() - service.startedAt })
|
|
43
|
+
case '/ui':
|
|
44
|
+
// The client respects this: ui.enabled=false removes the chip entirely.
|
|
45
|
+
return send(res, 200, { enabled: ui.enabled !== false, drivePet: ui.drivePet !== false })
|
|
43
46
|
case '/state': {
|
|
44
47
|
const sessionId = url.searchParams.get('session') || undefined
|
|
45
48
|
return send(res, 200, service.state(sessionId))
|
package/lib/client.js
CHANGED
|
@@ -68,15 +68,100 @@ window.__ModuleLoader__.load({
|
|
|
68
68
|
var [open, setOpen] = useState(false)
|
|
69
69
|
var [pinned, setPinned] = useState(false)
|
|
70
70
|
var [pos, setPos] = useState(null)
|
|
71
|
+
var [uiEnabled, setUiEnabled] = useState(true)
|
|
72
|
+
var [hidden, setHidden] = useState(function () {
|
|
73
|
+
try {
|
|
74
|
+
return localStorage.getItem('cerebrum.hidden') === '1'
|
|
75
|
+
} catch (err) {
|
|
76
|
+
return false
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
var [miniPos, setMiniPos] = useState(function () {
|
|
80
|
+
try {
|
|
81
|
+
var raw = localStorage.getItem('cerebrum.miniPos')
|
|
82
|
+
return raw ? JSON.parse(raw) : null
|
|
83
|
+
} catch (err) {
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
86
|
+
})
|
|
71
87
|
var panelRef = useRef(null)
|
|
72
88
|
var dragRef = useRef(null)
|
|
89
|
+
var petRef = useRef({ key: '', at: 0 })
|
|
90
|
+
var uiRef = useRef({ enabled: true, drivePet: true })
|
|
73
91
|
|
|
74
92
|
useEffect(function () {
|
|
75
93
|
var alive = true
|
|
94
|
+
// The host decides whether users opted out of the whole chip.
|
|
95
|
+
get('/ui').then(function (data) {
|
|
96
|
+
if (data) {
|
|
97
|
+
uiRef.current = { enabled: data.enabled !== false, drivePet: data.drivePet !== false }
|
|
98
|
+
if (!alive) return
|
|
99
|
+
if (data.enabled === false) setUiEnabled(false)
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Built-in pet bridge: no setup required. When a dsh-pet instance is
|
|
105
|
+
* detected on this origin, emotion changes are pushed to it as a
|
|
106
|
+
* locked "performance" (bubble line), then the lock is released.
|
|
107
|
+
*/
|
|
108
|
+
var drivePet = function (hints) {
|
|
109
|
+
if (uiRef.current.drivePet === false) return
|
|
110
|
+
var key = (hints.emotionKey || '') + '|' + (hints.line || '')
|
|
111
|
+
var now = Date.now()
|
|
112
|
+
if (petRef.current.key === key) return
|
|
113
|
+
if (now - petRef.current.at < 20000) return
|
|
114
|
+
if ((hints.intensity || 0) < 0.25) return
|
|
115
|
+
petRef.current.key = key
|
|
116
|
+
petRef.current.at = now
|
|
117
|
+
fetch('/dsh-pet-7340/state')
|
|
118
|
+
.then(function (r) { return r.ok ? r.json() : null })
|
|
119
|
+
.then(function (st) {
|
|
120
|
+
if (!st || !st.pets) return
|
|
121
|
+
var id = Object.keys(st.pets)[0]
|
|
122
|
+
if (!id) return
|
|
123
|
+
var attempt = function (surface) {
|
|
124
|
+
var q = '?pet=' + encodeURIComponent(id) + '&surface=' + surface
|
|
125
|
+
return fetch('/dsh-pet-7340/lock' + q, {
|
|
126
|
+
method: 'POST',
|
|
127
|
+
headers: { 'Content-Type': 'application/json' },
|
|
128
|
+
body: JSON.stringify({ ttl: 8000, surface: surface }),
|
|
129
|
+
})
|
|
130
|
+
.then(function (r) { return r.json() })
|
|
131
|
+
.then(function (lock) {
|
|
132
|
+
if (!lock || lock.ok === false || !lock.lockId) {
|
|
133
|
+
if (surface === 'web') return attempt('desktop')
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
var lq = q + '&lock=' + encodeURIComponent(lock.lockId)
|
|
137
|
+
return fetch('/dsh-pet-7340/broadcast' + lq, {
|
|
138
|
+
method: 'POST',
|
|
139
|
+
headers: { 'Content-Type': 'application/json' },
|
|
140
|
+
body: JSON.stringify({ text: hints.line, duration: 6000 }),
|
|
141
|
+
})
|
|
142
|
+
.catch(function () {})
|
|
143
|
+
.then(function () {
|
|
144
|
+
return fetch('/dsh-pet-7340/lock/release' + q, {
|
|
145
|
+
method: 'POST',
|
|
146
|
+
headers: { 'Content-Type': 'application/json' },
|
|
147
|
+
body: JSON.stringify({ lockId: lock.lockId }),
|
|
148
|
+
}).catch(function () {})
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
return attempt('web')
|
|
153
|
+
})
|
|
154
|
+
.catch(function () {})
|
|
155
|
+
}
|
|
156
|
+
|
|
76
157
|
var tick = function () {
|
|
77
|
-
|
|
158
|
+
var qs = sessionId ? '?session=' + encodeURIComponent(sessionId) : ''
|
|
159
|
+
get('/state' + qs).then(function (data) {
|
|
78
160
|
if (alive && data) setState(data)
|
|
79
161
|
})
|
|
162
|
+
get('/render-hints' + qs).then(function (hints) {
|
|
163
|
+
if (alive && hints) drivePet(hints)
|
|
164
|
+
})
|
|
80
165
|
}
|
|
81
166
|
tick()
|
|
82
167
|
var timer = setInterval(tick, POLL_MS)
|
|
@@ -86,6 +171,82 @@ window.__ModuleLoader__.load({
|
|
|
86
171
|
}
|
|
87
172
|
}, [sessionId])
|
|
88
173
|
|
|
174
|
+
var hideChip = function () {
|
|
175
|
+
setHidden(true)
|
|
176
|
+
try {
|
|
177
|
+
localStorage.setItem('cerebrum.hidden', '1')
|
|
178
|
+
} catch (err) {}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
var restoreChip = function () {
|
|
182
|
+
setHidden(false)
|
|
183
|
+
try {
|
|
184
|
+
localStorage.removeItem('cerebrum.hidden')
|
|
185
|
+
} catch (err) {}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
var startMiniDrag = function (event) {
|
|
189
|
+
var rect = event.currentTarget.getBoundingClientRect()
|
|
190
|
+
var start = { mx: event.clientX, my: event.clientY, x: rect.left, y: rect.top, moved: 0 }
|
|
191
|
+
var latest = null
|
|
192
|
+
var move = function (ev) {
|
|
193
|
+
var dx = ev.clientX - start.mx
|
|
194
|
+
var dy = ev.clientY - start.my
|
|
195
|
+
start.moved = Math.max(start.moved, Math.abs(dx) + Math.abs(dy))
|
|
196
|
+
latest = {
|
|
197
|
+
x: Math.max(4, Math.min(window.innerWidth - 30, start.x + dx)),
|
|
198
|
+
y: Math.max(4, Math.min(window.innerHeight - 30, start.y + dy)),
|
|
199
|
+
}
|
|
200
|
+
setMiniPos(latest)
|
|
201
|
+
}
|
|
202
|
+
var up = function () {
|
|
203
|
+
window.removeEventListener('mousemove', move)
|
|
204
|
+
window.removeEventListener('mouseup', up)
|
|
205
|
+
if (latest) {
|
|
206
|
+
try {
|
|
207
|
+
localStorage.setItem('cerebrum.miniPos', JSON.stringify(latest))
|
|
208
|
+
} catch (err) {}
|
|
209
|
+
}
|
|
210
|
+
if (start.moved < 4) restoreChip()
|
|
211
|
+
}
|
|
212
|
+
window.addEventListener('mousemove', move)
|
|
213
|
+
window.addEventListener('mouseup', up)
|
|
214
|
+
event.preventDefault()
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!uiEnabled) return null
|
|
218
|
+
if (hidden) {
|
|
219
|
+
var miniStyle = {
|
|
220
|
+
position: 'fixed',
|
|
221
|
+
zIndex: 1001,
|
|
222
|
+
display: 'flex',
|
|
223
|
+
alignItems: 'center',
|
|
224
|
+
justifyContent: 'center',
|
|
225
|
+
width: '24px',
|
|
226
|
+
height: '24px',
|
|
227
|
+
borderRadius: '999px',
|
|
228
|
+
background: 'rgba(16,26,40,.85)',
|
|
229
|
+
border: '1px solid #1f2c3f',
|
|
230
|
+
cursor: 'grab',
|
|
231
|
+
fontSize: '13px',
|
|
232
|
+
userSelect: 'none',
|
|
233
|
+
opacity: 0.75,
|
|
234
|
+
boxShadow: '0 2px 10px rgba(0,0,0,.35)',
|
|
235
|
+
}
|
|
236
|
+
if (miniPos) {
|
|
237
|
+
miniStyle.left = miniPos.x + 'px'
|
|
238
|
+
miniStyle.top = miniPos.y + 'px'
|
|
239
|
+
} else {
|
|
240
|
+
miniStyle.right = '16px'
|
|
241
|
+
miniStyle.bottom = '96px'
|
|
242
|
+
}
|
|
243
|
+
return createElement('span', {
|
|
244
|
+
style: miniStyle,
|
|
245
|
+
title: '拖动可移动;单击恢复大脑芯片(config.ui.enabled=false 可彻底关闭)',
|
|
246
|
+
onMouseDown: startMiniDrag,
|
|
247
|
+
}, '🧠')
|
|
248
|
+
}
|
|
249
|
+
|
|
89
250
|
var chipStyle = {
|
|
90
251
|
display: 'flex',
|
|
91
252
|
alignItems: 'center',
|
|
@@ -216,6 +377,7 @@ window.__ModuleLoader__.load({
|
|
|
216
377
|
createElement('span', { style: { fontWeight: 700 } }, '🧠 大脑仪表盘'),
|
|
217
378
|
createElement('span', null,
|
|
218
379
|
createElement('button', { type: 'button', style: btnStyle, title: pinned ? '取消固定(恢复浮动)' : '固定到输入栏上方', 'data-no-drag': '1', onClick: function () { setPinned(!pinned) } }, pinned ? '📌 已固定' : '📌 固定'),
|
|
380
|
+
createElement('button', { type: 'button', style: btnStyle, title: '隐藏大脑芯片(点小 🧠 恢复)', 'data-no-drag': '1', onClick: hideChip }, '🙈'),
|
|
219
381
|
createElement('button', { type: 'button', style: btnStyle, title: '收起', 'data-no-drag': '1', onClick: function () { setOpen(false) } }, '✕'),
|
|
220
382
|
))
|
|
221
383
|
|
package/lib/config.js
CHANGED
|
@@ -46,6 +46,12 @@ export const DEFAULT_CONFIG = {
|
|
|
46
46
|
enabled: true,
|
|
47
47
|
port: 18734,
|
|
48
48
|
},
|
|
49
|
+
/** Client UI (the brain chip/dashboard). Users who dislike it can switch it off. */
|
|
50
|
+
ui: {
|
|
51
|
+
enabled: true,
|
|
52
|
+
/** Built-in bridge: drive a detected dsh-pet with brain emotions. */
|
|
53
|
+
drivePet: true,
|
|
54
|
+
},
|
|
49
55
|
autoCapture: {
|
|
50
56
|
enabled: true,
|
|
51
57
|
maxTextChars: 2000,
|
|
@@ -115,6 +121,8 @@ export const resolveConfig = (raw, { home = resolveHome(), cwd = process.cwd() }
|
|
|
115
121
|
merged.workingMemory.slots = Math.round(clampNumber(merged.workingMemory.slots, 4, 1, 9))
|
|
116
122
|
merged.api.enabled = merged.api.enabled !== false
|
|
117
123
|
merged.api.port = Math.round(clampNumber(merged.api.port, 18734, 1024, 65535))
|
|
124
|
+
merged.ui.enabled = merged.ui.enabled !== false
|
|
125
|
+
merged.ui.drivePet = merged.ui.drivePet !== false
|
|
118
126
|
merged.autoCapture.maxTextChars = Math.round(clampNumber(merged.autoCapture.maxTextChars, 2000, 200, 20000))
|
|
119
127
|
merged.autoCapture.toolResultChars = Math.round(clampNumber(merged.autoCapture.toolResultChars, 300, 40, 4000))
|
|
120
128
|
merged.autoCapture.minChars = Math.round(clampNumber(merged.autoCapture.minChars, 6, 0, 500))
|
package/lib/index.js
CHANGED
|
@@ -57,7 +57,7 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
57
57
|
|
|
58
58
|
// Read-only loopback API powering the optional client UI (dock + dashboard).
|
|
59
59
|
if (config.api.enabled) {
|
|
60
|
-
const api = startBrainApi(service, { port: config.api.port })
|
|
60
|
+
const api = startBrainApi(service, { port: config.api.port, ui: config.ui })
|
|
61
61
|
ctx.effect(() => () => api.close(), 'cerebrum:brain-api')
|
|
62
62
|
}
|
|
63
63
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cerebrum",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Brain-inspired cognitive architecture for DeepSeek Harness: hippocampal episodic memory, cortical semantic memory, spreading-activation recall, appraisal-based emotion, neuromodulator state, Big Five personality and dual-process judgment.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|