dsh-agent-soul 0.2.0 → 0.4.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 +236 -125
- package/docs/preview.html +8 -8
- package/lib/api.js +304 -30
- package/lib/client/api.js +39 -0
- package/lib/client/app.js +3 -1
- package/lib/client/diary-tab.js +347 -0
- package/lib/client/memory-tab.js +26 -4
- package/lib/client/mood-tab.js +12 -10
- package/lib/client/overview-tab.js +33 -0
- package/lib/client/persona-tab.js +1 -0
- package/lib/client/settings-tab.js +1 -1
- package/lib/client.js +464 -16
- package/lib/diary.js +1265 -0
- package/lib/env.js +57 -9
- package/lib/extract.js +323 -9
- package/lib/index.js +498 -67
- package/lib/memory.js +1377 -807
- package/lib/mood.js +270 -23
- package/lib/paths.js +196 -168
- package/lib/purpose.js +195 -1
- package/lib/refine.js +221 -0
- package/lib/registry.js +236 -236
- package/lib/store.js +697 -383
- package/lib/tool.js +27 -8
- package/package.json +84 -71
- package/tools/build-client.mjs +1 -0
- package/tools/sync.mjs +131 -0
package/lib/tool.js
CHANGED
|
@@ -31,7 +31,8 @@ import {
|
|
|
31
31
|
savePurposeState,
|
|
32
32
|
writeMemory
|
|
33
33
|
} from './store.js'
|
|
34
|
-
import { recall, setPinned } from './memory.js'
|
|
34
|
+
import { forgetRecord, makeArchiver, recall, setPinned, touchRecords } from './memory.js'
|
|
35
|
+
import { archivePath } from './paths.js'
|
|
35
36
|
|
|
36
37
|
/** 工具执行时的 cwd:优先取宿主传的上下文,退化到「最近一次注入的 cwd」。 */
|
|
37
38
|
let fallbackCwd = ''
|
|
@@ -138,17 +139,25 @@ export function registerMemoryTool(ctx) {
|
|
|
138
139
|
if (action === 'recall') {
|
|
139
140
|
const query = String(args?.query ?? '').trim()
|
|
140
141
|
if (query === '') return { ok: false, message: 'query 不能为空' }
|
|
141
|
-
const cards = [{ card: globalCard(), label: '全局' }]
|
|
142
|
-
if (cwd !== '')
|
|
142
|
+
const cards = [{ card: globalCard(), label: '全局', save: () => saveGlobalCard(globalCard()) }]
|
|
143
|
+
if (cwd !== '') {
|
|
144
|
+
cards.push({ card: projectCard(cwd), label: '本项目', save: () => saveProjectCard(cwd, projectCard(cwd)) })
|
|
145
|
+
}
|
|
143
146
|
const items = []
|
|
144
147
|
for (const entry of cards) {
|
|
148
|
+
const hitIds = []
|
|
145
149
|
for (const hit of recall(entry.card, query, { limit: 6 })) {
|
|
150
|
+
hitIds.push(hit.record.id)
|
|
146
151
|
items.push({
|
|
147
152
|
id: hit.record.id,
|
|
148
153
|
text: `${hit.record.text.slice(0, 120)}(${hit.record.clarity}·${entry.label})`,
|
|
149
154
|
record: hit.record
|
|
150
155
|
})
|
|
151
156
|
}
|
|
157
|
+
// 被想起来的记忆要「刷新」:lastSeenAt 更新、recallCount +1、清晰度回升一档。
|
|
158
|
+
// 不调用的话 README 写的「被再次提及就刷新时间、召回 +1」就是一句空话,
|
|
159
|
+
// 而且越常想起的事反而会正常衰减到消失。
|
|
160
|
+
if (hitIds.length > 0 && touchRecords(entry.card, hitIds) > 0) entry.save()
|
|
152
161
|
}
|
|
153
162
|
items.sort((a, b) => (b.record.importance ?? 0) - (a.record.importance ?? 0))
|
|
154
163
|
return {
|
|
@@ -163,10 +172,12 @@ export function registerMemoryTool(ctx) {
|
|
|
163
172
|
if (id === '') return { ok: false, message: 'id 不能为空(先 recall 或 list 拿到 id)' }
|
|
164
173
|
const cards = [{ card: globalCard(), save: () => saveGlobalCard(globalCard()), label: '全局' }]
|
|
165
174
|
if (cwd !== '') cards.push({ card: projectCard(cwd), save: () => saveProjectCard(cwd, projectCard(cwd)), label: '本项目' })
|
|
175
|
+
// 走 forgetRecord 而不是自己 splice:它会把删掉的这条写进 archive.jsonl,
|
|
176
|
+
// 以后「她为什么把这件事忘了」还能查回来(README 承诺的)
|
|
177
|
+
const archive = makeArchiver(archivePath())
|
|
166
178
|
for (const entry of cards) {
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
const [removed] = entry.card.records.splice(index, 1)
|
|
179
|
+
const removed = forgetRecord(entry.card, id, archive)
|
|
180
|
+
if (removed === null) continue
|
|
170
181
|
entry.save()
|
|
171
182
|
note('tool', `忘掉一条(${entry.label}):${removed.text.slice(0, 40)}`)
|
|
172
183
|
return { ok: true, message: `忘掉了:${removed.text.slice(0, 40)}` }
|
|
@@ -189,13 +200,21 @@ export function registerMemoryTool(ctx) {
|
|
|
189
200
|
}
|
|
190
201
|
|
|
191
202
|
if (action === 'list') {
|
|
203
|
+
// 项目卡也要列:不然模型往 project 作用域写进去的东西,自己拿不到 id,
|
|
204
|
+
// forget / pin 对项目记忆基本用不了
|
|
205
|
+
const cards = [{ card: globalCard(), label: '全局' }]
|
|
206
|
+
if (cwd !== '') cards.push({ card: projectCard(cwd), label: '本项目' })
|
|
192
207
|
const items = []
|
|
193
|
-
for (const entry of
|
|
208
|
+
for (const entry of cards) {
|
|
194
209
|
for (const record of entry.card.records.slice(-10).reverse()) {
|
|
195
210
|
items.push({ id: record.id, text: `${record.text.slice(0, 80)}(${record.clarity}·${entry.label})` })
|
|
196
211
|
}
|
|
197
212
|
}
|
|
198
|
-
return {
|
|
213
|
+
return {
|
|
214
|
+
ok: true,
|
|
215
|
+
message: items.length === 0 ? '还没记下什么。' : '最近记下的:',
|
|
216
|
+
items: items.slice(0, 20)
|
|
217
|
+
}
|
|
199
218
|
}
|
|
200
219
|
|
|
201
220
|
return { ok: false, message: `不认识的 action:${action}` }
|
package/package.json
CHANGED
|
@@ -1,71 +1,84 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-agent-soul",
|
|
3
|
-
"version": "0.2
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "给 DSH 的 agent 一套会忘事的记忆、一份会变的人格和一份会起伏的心情:人格按小节合并(项目覆盖全局但不吃掉全局),记忆按人的规律衰减(清晰→模糊→只剩印象→遗忘),「心里惦记的事」让她的主动有连续性,心情跟着每轮对话自己判断、自己平复(不注入、无挂饰)。",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"deepseek",
|
|
8
|
-
"deepseek-harness",
|
|
9
|
-
"dsh",
|
|
10
|
-
"dsh-plugin",
|
|
11
|
-
"agent",
|
|
12
|
-
"memory",
|
|
13
|
-
"mood",
|
|
14
|
-
"persona",
|
|
15
|
-
"personality",
|
|
16
|
-
"soul"
|
|
17
|
-
],
|
|
18
|
-
"main": "lib/index.js",
|
|
19
|
-
"exports": {
|
|
20
|
-
".": "./lib/index.js",
|
|
21
|
-
"./client": "./lib/client.js",
|
|
22
|
-
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
23
|
-
"./package.json": "./package.json"
|
|
24
|
-
},
|
|
25
|
-
"files": [
|
|
26
|
-
"lib",
|
|
27
|
-
"assets",
|
|
28
|
-
"docs",
|
|
29
|
-
"tools",
|
|
30
|
-
"cordis.patch.yml",
|
|
31
|
-
"README.md",
|
|
32
|
-
"LICENSE"
|
|
33
|
-
],
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build:client": "node tools/build-client.mjs",
|
|
36
|
-
"test": "node tools/build-client.mjs && node tests/memory.test.js && node tests/mood.test.js && node tests/persona.test.js && node tests/purpose.test.js && node tests/registry.test.js && node tests/smoke.test.js && node tests/client.test.js",
|
|
37
|
-
"test:
|
|
38
|
-
"test:
|
|
39
|
-
"test:
|
|
40
|
-
"test:
|
|
41
|
-
"test:
|
|
42
|
-
"test:
|
|
43
|
-
"test:
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-agent-soul",
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "给 DSH 的 agent 一套会忘事的记忆、一份会变的人格和一份会起伏的心情:人格按小节合并(项目覆盖全局但不吃掉全局),记忆按人的规律衰减(清晰→模糊→只剩印象→遗忘),「心里惦记的事」让她的主动有连续性,心情跟着每轮对话自己判断、自己平复(不注入、无挂饰)。",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"deepseek",
|
|
8
|
+
"deepseek-harness",
|
|
9
|
+
"dsh",
|
|
10
|
+
"dsh-plugin",
|
|
11
|
+
"agent",
|
|
12
|
+
"memory",
|
|
13
|
+
"mood",
|
|
14
|
+
"persona",
|
|
15
|
+
"personality",
|
|
16
|
+
"soul"
|
|
17
|
+
],
|
|
18
|
+
"main": "lib/index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./lib/index.js",
|
|
21
|
+
"./client": "./lib/client.js",
|
|
22
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"lib",
|
|
27
|
+
"assets",
|
|
28
|
+
"docs",
|
|
29
|
+
"tools",
|
|
30
|
+
"cordis.patch.yml",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build:client": "node tools/build-client.mjs",
|
|
36
|
+
"test": "node tools/build-client.mjs && node tests/extract.test.js && node tests/refine.test.js && node tests/goal-revive.test.js && node tests/archive.test.js && node tests/diary.test.js && node tests/diary-new-path.test.js && node tests/memory.test.js && node tests/memory-near-dupe.test.js && node tests/recall-dedupe.test.js && node tests/recent-context.test.js && node tests/first-turn.test.js && node tests/log-rotate.test.js && node tests/inject.test.js && node tests/sticky.test.js && node tests/mood.test.js && node tests/mood-digest.test.js && node tests/persona.test.js && node tests/purpose.test.js && node tests/emotion-purpose.test.js && node tests/registry.test.js && node tests/smoke.test.js && node tests/client.test.js",
|
|
37
|
+
"test:extract": "node tests/extract.test.js",
|
|
38
|
+
"test:refine": "node tests/refine.test.js",
|
|
39
|
+
"test:goal": "node tests/goal-revive.test.js",
|
|
40
|
+
"test:archive": "node tests/archive.test.js",
|
|
41
|
+
"test:diary": "node tests/diary.test.js",
|
|
42
|
+
"test:diary-new": "node tests/diary-new-path.test.js",
|
|
43
|
+
"test:memory": "node tests/memory.test.js",
|
|
44
|
+
"test:memory-dupe": "node tests/memory-near-dupe.test.js",
|
|
45
|
+
"test:recall": "node tests/recall-dedupe.test.js",
|
|
46
|
+
"test:recent": "node tests/recent-context.test.js",
|
|
47
|
+
"test:log": "node tests/log-rotate.test.js",
|
|
48
|
+
"test:inject": "node tests/inject.test.js",
|
|
49
|
+
"test:mood": "node tests/mood.test.js",
|
|
50
|
+
"test:mood-digest": "node tests/mood-digest.test.js",
|
|
51
|
+
"test:emotion": "node tests/emotion-purpose.test.js",
|
|
52
|
+
"test:persona": "node tests/persona.test.js",
|
|
53
|
+
"test:purpose": "node tests/purpose.test.js",
|
|
54
|
+
"test:registry": "node tests/registry.test.js",
|
|
55
|
+
"test:smoke": "node tests/smoke.test.js",
|
|
56
|
+
"test:client": "node tools/build-client.mjs && node tests/client.test.js",
|
|
57
|
+
"sync": "node tools/build-client.mjs"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@deepseek-ai/cordis": "^4.0.1"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=22.19"
|
|
64
|
+
},
|
|
65
|
+
"dsh": {
|
|
66
|
+
"manifestVersion": 1,
|
|
67
|
+
"bundle": {
|
|
68
|
+
"patch": "./cordis.patch.yml"
|
|
69
|
+
},
|
|
70
|
+
"client": {
|
|
71
|
+
"platform": "web",
|
|
72
|
+
"inject": []
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"repository": {
|
|
76
|
+
"type": "git",
|
|
77
|
+
"url": "git+https://github.com/danshuyue/dsh-agent-soul.git"
|
|
78
|
+
},
|
|
79
|
+
"bugs": {
|
|
80
|
+
"url": "https://github.com/danshuyue/dsh-agent-soul/issues"
|
|
81
|
+
},
|
|
82
|
+
"homepage": "https://github.com/danshuyue/dsh-agent-soul#readme",
|
|
83
|
+
"license": "MIT"
|
|
84
|
+
}
|
package/tools/build-client.mjs
CHANGED
package/tools/sync.mjs
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sync.mjs —— 把源码同步到 DSH 插件目录(原子写,不会读到半截文件)。
|
|
3
|
+
*
|
|
4
|
+
* ── 为什么需要它 ──
|
|
5
|
+
* 2026-10-28 真事故:用 `cp` 覆盖 client.js 时,DSH 正好在启动读取它,
|
|
6
|
+
* 读到了写了一半的文件,日志里只有一句
|
|
7
|
+
*
|
|
8
|
+
* web boot: 1 entry did not activate
|
|
9
|
+
* dsh-agent-soul: bundle script ... failed to load
|
|
10
|
+
*
|
|
11
|
+
* 整个桌面应用起不来。代码本身没问题,纯粹是复制和读取撞在了一起。
|
|
12
|
+
*
|
|
13
|
+
* 所以这里改成了「先写 .tmp,再 rename」:同一分区上 rename 是原子的,
|
|
14
|
+
* 读的人要么看到旧版、要么看到新版,不会看到半截。
|
|
15
|
+
*
|
|
16
|
+
* ── 用法 ──
|
|
17
|
+
* node tools/sync.mjs 同步到 <DSH_HOME>/plugins/dsh-agent-soul
|
|
18
|
+
* node tools/sync.mjs --to <目录> 指定目标
|
|
19
|
+
* node tools/sync.mjs --dry 只看会改什么,不真写
|
|
20
|
+
*/
|
|
21
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, renameSync, rmSync, statSync } from 'node:fs'
|
|
22
|
+
import { homedir } from 'node:os'
|
|
23
|
+
import { dirname, join, resolve } from 'node:path'
|
|
24
|
+
import { fileURLToPath } from 'node:url'
|
|
25
|
+
|
|
26
|
+
const SRC = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
27
|
+
const argv = process.argv.slice(2)
|
|
28
|
+
const dry = argv.includes('--dry')
|
|
29
|
+
const toIndex = argv.indexOf('--to')
|
|
30
|
+
const dshHome = process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
31
|
+
const DEST = toIndex >= 0 && argv[toIndex + 1] ? resolve(argv[toIndex + 1]) : join(dshHome, 'plugins', 'dsh-agent-soul')
|
|
32
|
+
|
|
33
|
+
/** 同步的项:目录整份同步,文件单个同步。 */
|
|
34
|
+
// assets 是心情那五张表情图(PNG),lib/api.js 直接从这里读出去给设置页
|
|
35
|
+
const DIRS = ['lib', 'tests', 'docs', 'assets']
|
|
36
|
+
const FILES = ['package.json', 'cordis.patch.yml', 'README.md', 'LICENSE']
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 原子复制:先落到同目录的 .tmp-<pid>,再 rename 覆盖。
|
|
40
|
+
* rename 在同一分区是原子操作,读的人不会看到半截内容。
|
|
41
|
+
*/
|
|
42
|
+
function atomicCopy(from, to) {
|
|
43
|
+
const tmp = `${to}.tmp-${process.pid}`
|
|
44
|
+
copyFileSync(from, tmp)
|
|
45
|
+
renameSync(tmp, to)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function syncDir(name) {
|
|
49
|
+
const from = join(SRC, name)
|
|
50
|
+
if (!existsSync(from)) return { added: 0, updated: 0 }
|
|
51
|
+
const to = join(DEST, name)
|
|
52
|
+
if (!dry) mkdirSync(to, { recursive: true })
|
|
53
|
+
|
|
54
|
+
let added = 0
|
|
55
|
+
let updated = 0
|
|
56
|
+
for (const entry of readdirSync(from)) {
|
|
57
|
+
const srcFile = join(from, entry)
|
|
58
|
+
if (!statSync(srcFile).isFile()) continue
|
|
59
|
+
const dstFile = join(to, entry)
|
|
60
|
+
const existed = existsSync(dstFile)
|
|
61
|
+
if (!dry) atomicCopy(srcFile, dstFile)
|
|
62
|
+
if (existed) updated += 1
|
|
63
|
+
else added += 1
|
|
64
|
+
}
|
|
65
|
+
return { added, updated }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function syncFile(name) {
|
|
69
|
+
const from = join(SRC, name)
|
|
70
|
+
if (!existsSync(from)) return null
|
|
71
|
+
const dstFile = join(DEST, name)
|
|
72
|
+
const existed = existsSync(dstFile)
|
|
73
|
+
if (!dry) atomicCopy(from, dstFile)
|
|
74
|
+
return { added: existed ? 0 : 1, updated: existed ? 1 : 0 }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ---- 主流程 ----
|
|
78
|
+
|
|
79
|
+
if (!existsSync(DEST) && !dry) {
|
|
80
|
+
console.error(`目标目录不存在:${DEST}`)
|
|
81
|
+
console.error('第一次安装请先手动建目录并在 profile 里登记,参考 README「安装」。')
|
|
82
|
+
process.exit(1)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log(`源:${SRC}`)
|
|
86
|
+
console.log(`目标:${DEST}${dry ? '(--dry,只看不改)' : ''}`)
|
|
87
|
+
console.log('')
|
|
88
|
+
|
|
89
|
+
let added = 0
|
|
90
|
+
let updated = 0
|
|
91
|
+
for (const dir of DIRS) {
|
|
92
|
+
const result = syncDir(dir)
|
|
93
|
+
added += result.added
|
|
94
|
+
updated += result.updated
|
|
95
|
+
if (result.added + result.updated > 0) {
|
|
96
|
+
console.log(` ${dir}/ 新增 ${result.added},更新 ${result.updated}`)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const file of FILES) {
|
|
100
|
+
const result = syncFile(file)
|
|
101
|
+
if (result === null) {
|
|
102
|
+
console.log(` ${file} 源码里没有,跳过`)
|
|
103
|
+
continue
|
|
104
|
+
}
|
|
105
|
+
added += result.added
|
|
106
|
+
updated += result.updated
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 清理上次中断留下的 .tmp(只清自己这套命名)
|
|
110
|
+
try {
|
|
111
|
+
for (const dir of DIRS) {
|
|
112
|
+
const target = join(DEST, dir)
|
|
113
|
+
if (!existsSync(target)) continue
|
|
114
|
+
for (const entry of readdirSync(target)) {
|
|
115
|
+
if (/\.tmp-\d+$/.test(entry)) {
|
|
116
|
+
rmSync(join(target, entry), { force: true })
|
|
117
|
+
console.log(` 清掉残留临时文件 ${dir}/${entry}`)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} catch {
|
|
122
|
+
/* 清理失败不影响同步结果 */
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
console.log('')
|
|
126
|
+
console.log(dry ? '(dry run 结束,什么都没改)' : `同步完成:新增 ${added},更新 ${updated} 个文件`)
|
|
127
|
+
if (!dry) {
|
|
128
|
+
console.log('')
|
|
129
|
+
console.log('⚠️ 改动要重启 DSH(或刷新页面加载 client.js)才生效。')
|
|
130
|
+
console.log(' 重启前确认没有正在进行的同步 —— 这个脚本已经是原子写,不会再读到半截文件。')
|
|
131
|
+
}
|