dsh-spirit 0.0.1 → 0.1.1
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/CHANGELOG.en.md +157 -0
- package/CHANGELOG.md +113 -0
- package/LICENSE +21 -0
- package/README.en.md +174 -0
- package/README.md +141 -3
- package/cordis.patch.yml +35 -0
- package/dist/capability.d.ts +46 -0
- package/dist/capability.js +100 -0
- package/dist/client.js +455 -0
- package/dist/config.d.ts +47 -0
- package/dist/config.js +208 -0
- package/dist/contract.d.ts +282 -0
- package/dist/contract.js +128 -0
- package/dist/db/degrade.d.ts +27 -0
- package/dist/db/degrade.js +40 -0
- package/dist/db/migrate.d.ts +31 -0
- package/dist/db/migrate.js +42 -0
- package/dist/db/open.d.ts +35 -0
- package/dist/db/open.js +74 -0
- package/dist/db/schema.d.ts +23 -0
- package/dist/db/schema.js +68 -0
- package/dist/drsc/client.d.ts +134 -0
- package/dist/drsc/client.js +199 -0
- package/dist/drsc/probe.d.ts +51 -0
- package/dist/drsc/probe.js +73 -0
- package/dist/drsc/segments.d.ts +62 -0
- package/dist/drsc/segments.js +91 -0
- package/dist/experience/compile.d.ts +29 -0
- package/dist/experience/compile.js +61 -0
- package/dist/experience/cross-session.d.ts +23 -0
- package/dist/experience/cross-session.js +30 -0
- package/dist/experience/cues.d.ts +32 -0
- package/dist/experience/cues.js +54 -0
- package/dist/experience/events.d.ts +30 -0
- package/dist/experience/events.js +56 -0
- package/dist/experience/render.d.ts +35 -0
- package/dist/experience/render.js +104 -0
- package/dist/experience/select.d.ts +38 -0
- package/dist/experience/select.js +73 -0
- package/dist/experience/watcher.d.ts +61 -0
- package/dist/experience/watcher.js +249 -0
- package/dist/hooks/card-observe.d.ts +19 -0
- package/dist/hooks/card-observe.js +73 -0
- package/dist/hooks/card-pre-step.d.ts +40 -0
- package/dist/hooks/card-pre-step.js +79 -0
- package/dist/hooks/persona-section.d.ts +37 -0
- package/dist/hooks/persona-section.js +83 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +135 -0
- package/dist/persona/render.d.ts +26 -0
- package/dist/persona/render.js +39 -0
- package/dist/persona/store.d.ts +44 -0
- package/dist/persona/store.js +79 -0
- package/dist/persona/types.d.ts +41 -0
- package/dist/persona/types.js +122 -0
- package/dist/recall/history.d.ts +45 -0
- package/dist/recall/history.js +108 -0
- package/dist/recall/recent.d.ts +20 -0
- package/dist/recall/recent.js +21 -0
- package/dist/recall/score.d.ts +23 -0
- package/dist/recall/score.js +28 -0
- package/dist/rpc.d.ts +72 -0
- package/dist/rpc.js +293 -0
- package/dist/slot/derive.d.ts +32 -0
- package/dist/slot/derive.js +112 -0
- package/dist/slot/grid.d.ts +29 -0
- package/dist/slot/grid.js +51 -0
- package/dist/slot/render.d.ts +65 -0
- package/dist/slot/render.js +103 -0
- package/dist/spirit.d.ts +159 -0
- package/dist/spirit.js +328 -0
- package/dist/stats.d.ts +54 -0
- package/dist/stats.js +126 -0
- package/dist/store/experience.d.ts +92 -0
- package/dist/store/experience.js +349 -0
- package/dist/store/journal-retention.d.ts +110 -0
- package/dist/store/journal-retention.js +145 -0
- package/dist/store/json-file.d.ts +50 -0
- package/dist/store/json-file.js +143 -0
- package/dist/store/session-modes.d.ts +46 -0
- package/dist/store/session-modes.js +102 -0
- package/dist/types.d.ts +221 -0
- package/dist/types.js +101 -0
- package/dist/util/decay.d.ts +12 -0
- package/dist/util/decay.js +21 -0
- package/dist/util/host-shape.d.ts +27 -0
- package/dist/util/host-shape.js +87 -0
- package/dist/util/self-source.d.ts +21 -0
- package/dist/util/self-source.js +40 -0
- package/dist/util/text.d.ts +18 -0
- package/dist/util/text.js +53 -0
- package/dist/util/tier.d.ts +29 -0
- package/dist/util/tier.js +44 -0
- package/dist/words.d.ts +15 -0
- package/dist/words.js +41 -0
- package/dsh.plugin.json +22 -0
- package/package.json +117 -6
- package/index.js +0 -1
package/CHANGELOG.en.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. Versioning is semantic.
|
|
4
|
+
|
|
5
|
+
## 0.1.0
|
|
6
|
+
|
|
7
|
+
First usable release: **a first-person experience entry store plus dual-lane instant recall**.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **Experience entry store (the source of truth)**: `node:sqlite` (Node builtin, zero native deps);
|
|
12
|
+
`experience` / `experience_cues` / `mood_state` / `meta`. Append-only — a correction inserts a new
|
|
13
|
+
row and marks the old one via `superseded_by`; **there is no DELETE path anywhere** (a grep
|
|
14
|
+
assertion holds the line in CI). Rows carry `lane` (`live` / `drsc`) and `source_ref` (traceable to
|
|
15
|
+
a collector segment).
|
|
16
|
+
- **Persona as the record selector**: `salience` decides whether an event is worth recording at all
|
|
17
|
+
(`0` means don't record — what a character *doesn't* write down is also characterisation),
|
|
18
|
+
`focus` decides which side of the same event gets written (a failed tool call can land as
|
|
19
|
+
"I got it wrong" or as "my tools are being difficult"), `voice` decides the phrasing. The persona
|
|
20
|
+
section enters the system prompt via `systemPrompt.section` (order 20), cached by `revision`.
|
|
21
|
+
- **Derived mood tier**: entries → a 3×3 grid (valence × arousal), recency-weighted by half-life,
|
|
22
|
+
with a **per-turn step cap** (no personality whiplash) and **stale → neutral** (a restart never
|
|
23
|
+
treats three-day-old feelings as current). Externally only tier words and behavioural tendency are
|
|
24
|
+
exposed — **no floating-point emotion values anywhere**.
|
|
25
|
+
- **Recall card injected at the tail**: `agent/pre-step` appends one `user/message` at the **end** of
|
|
26
|
+
the returned array, attributed `source:{kind:'plugin:spirit', form:'snapshot'}` — `snapshot` is
|
|
27
|
+
host-defined as "a later snapshot from the same producer supersedes an earlier one", so nothing
|
|
28
|
+
rewrites history and no hand-rolled "previous row is void" sentence is needed. Four segments
|
|
29
|
+
(state / just now / recalled / opening) are budgeted **line by line against the assembled bytes**,
|
|
30
|
+
with a fixed drop order.
|
|
31
|
+
- **Dual-lane recall**: lane A recency (live hooks, zero lag, always on); lane B history (own older
|
|
32
|
+
entries + DRSC search, under a timeout budget). The two lanes are **never rank-merged** — each owns
|
|
33
|
+
its own segment, because "just happened" and "got reminded" mean different things.
|
|
34
|
+
- **Consumes DRSC instead of rebuilding delivered capability**: session enumeration, JSONL decoding,
|
|
35
|
+
turn segmentation, CJK retrieval and surface reconciliation are not re-implemented. Only its `op`
|
|
36
|
+
surface is called (`status` / `session` / `search`), always with `redact=1`; `session:null` is
|
|
37
|
+
treated as empty rather than as an error; **its database file is never read**; when it is not
|
|
38
|
+
installed the history lane is omitted entirely.
|
|
39
|
+
- **Observability**: an in-memory stats registry (injected / bypassed / off turns, card bytes,
|
|
40
|
+
recall hits, confirmed injections) plus the prefix route `POST /dsh-spirit/rpc/<method>`
|
|
41
|
+
(deliberately not `connection.rpc`, see below). The client half mounts exactly two seats: the
|
|
42
|
+
input-bar pill (`on / record-only / off`) and a read-only top-level **Journal** section in Settings.
|
|
43
|
+
- **Bypass is orthogonal to off**: bypass keeps recording and deriving and only stops the
|
|
44
|
+
injection — the only shape that can answer "is the immersion actually caused by this mechanism".
|
|
45
|
+
- **Cross-session tone**: the first turn of a new session reads the previous session's last few
|
|
46
|
+
**own entries** (no DRSC query, and no reading of anyone else's store).
|
|
47
|
+
- **Gates**: `npm run check` = typecheck (3 configs) → lint → vitest → build → **dist smoke**;
|
|
48
|
+
plus `npm run compat`, which double-checks every target host line against `engines.dsh`
|
|
49
|
+
*and* `peerDependencies`.
|
|
50
|
+
|
|
51
|
+
### Key decisions (and why not the alternative)
|
|
52
|
+
|
|
53
|
+
- **No dependency on prime-memory or its store**: experience and objective fact are different
|
|
54
|
+
semantic domains. Attributing rows `plugin:spirit` means prime-memory's L0 capture (which accepts
|
|
55
|
+
only `kind:'user'`) cannot distil them into "facts" — decoupling goes both ways.
|
|
56
|
+
- **Mood inputs are structural only**: any signal bag carrying free text is rejected wholesale.
|
|
57
|
+
Otherwise scraped pages and file bodies could steer the character's state, and the drift would look
|
|
58
|
+
exactly like the character's own reaction.
|
|
59
|
+
- **No fabricated specificity**: an early design draft said "when you interrupted me for the third
|
|
60
|
+
time" — mechanical capture cannot know "third", so writing it would be fiction that later recall
|
|
61
|
+
quotes as fact.
|
|
62
|
+
- **The primary recall path is automatic injection, not a tool**: relying on the model to go look
|
|
63
|
+
turns this into "read the diary, then think back" — the failure mode dsh-soul documents itself
|
|
64
|
+
(when the model doesn't search, the mechanism might as well not exist).
|
|
65
|
+
- **Settings form left to the host**: volatile fields auto-generate it; the custom section is
|
|
66
|
+
read-only, so there can never be two settings entry points for one plugin.
|
|
67
|
+
- **RPC avoids `connection.rpc`**: that prefix channel silently 405s at the webServer dispatch layer,
|
|
68
|
+
and the `/api` interceptor slot is single-owner and gets grabbed. An own exact prefix route coexists.
|
|
69
|
+
|
|
70
|
+
### Fixed (the silently-broken kind)
|
|
71
|
+
|
|
72
|
+
- `live.bypass` (global bypass) and `live.cardEnabled` (card master switch) **were never read by the
|
|
73
|
+
orchestrator** — the settings toggle was decorative
|
|
74
|
+
- the "card already sent" credential was not reset after compaction/clear ⇒ the `unchanged` gate
|
|
75
|
+
blocked re-injection forever = **compact once and the character has no feelings**, silently
|
|
76
|
+
- `failedTools` was cleared every turn ⇒ cross-turn "same tool recovered" could never be detected
|
|
77
|
+
- `noteInjected` silently dropped registrations when no runtime existed ⇒ the first card's
|
|
78
|
+
fingerprint never committed
|
|
79
|
+
- card budget used "one separator per line" estimates that do not match `join('\n')`, so the drop
|
|
80
|
+
order diverged from the design
|
|
81
|
+
- entry and cue writes were not in one transaction (a crash mid-way left cue rows pointing at a
|
|
82
|
+
nonexistent entry); 20k appends also went 92s → 35s
|
|
83
|
+
- detail phrasing printed `pathBases` verbatim ⇒ a caller passing full paths would leak directories
|
|
84
|
+
into cards and the store (now normalised to basename)
|
|
85
|
+
- `ENOENT` was detected via `err.name` instead of `err.code`, reporting "missing file" as
|
|
86
|
+
"unreadable" — a failure that does not exist
|
|
87
|
+
- migration direction checks had their two messages swapped
|
|
88
|
+
|
|
89
|
+
### Real-host defects (found on a live 0.2.0-rc.2 web install)
|
|
90
|
+
|
|
91
|
+
- **wrong route root**: `SPIRIT_RPC_ROUTE` built `/dsh-spiritrpc` while the browser half fetched
|
|
92
|
+
`/dsh-spirit/rpc/…` ⇒ the panel only ever saw the host's 404. The root is now a single shared
|
|
93
|
+
constant, with three gate assertions plus two dist-smoke checks behind it
|
|
94
|
+
- **wrong optional-service lookup**: `ctx.get('webServer')` returns undefined without a top-level
|
|
95
|
+
inject declaration, and `internal/service` does not re-fire on a normal start ⇒ the route was never
|
|
96
|
+
registered. The main path is now scoped injection, `ctx.inject(['webServer'], …)`
|
|
97
|
+
- **seat label frozen in the default language**: client apply runs before the host writes
|
|
98
|
+
`<html lang>`, so a string label pinned the nav entry to English. Labels are thunks now
|
|
99
|
+
(host contract: thunks follow the active locale)
|
|
100
|
+
- **journal and export hung off the in-memory registry**: after a host restart the registry is empty,
|
|
101
|
+
so the section went blank and export said "no session to export" while every row sat in the store.
|
|
102
|
+
Both now fall back to the newest session in the library, and the empty-state copy no longer
|
|
103
|
+
contradicts the rows below it
|
|
104
|
+
- also closed the missing test cases for the "turn already cancelled" gate
|
|
105
|
+
|
|
106
|
+
### Real-host round two (headless line + a local mock provider)
|
|
107
|
+
|
|
108
|
+
- **the last turn of a session was never recorded**: recording happened in the *next* turn's
|
|
109
|
+
pre-step, which reads the previous turn's accumulator. A headless task is exactly one turn, so
|
|
110
|
+
the whole experience track wrote **nothing** on a live host (every "journal" row previously
|
|
111
|
+
visible had been seeded by a probe). A turn now settles at `turn/end`, and pre-step stays only
|
|
112
|
+
as the fallback for missed events (a settled turn yields empty signals, so nothing is recorded
|
|
113
|
+
twice). Lesson: **green unit tests plus a plugin that loads is not proof that the writer runs**
|
|
114
|
+
- **duplicated recall lines**: the same trigger compiles the same sentence, and `recallHistory`
|
|
115
|
+
only deduplicated against the recent section, so a live card carried two identical
|
|
116
|
+
"recalled:" lines (wasted budget, read like a glitch). Both lanes now dedupe at the merge point:
|
|
117
|
+
2 lines → 1, card bytes 374 → 304
|
|
118
|
+
- **the default card width collided with a red line**: the extreme negative tier adds a
|
|
119
|
+
"not a medical or psychological judgement" note, and that note must never be budget-dropped.
|
|
120
|
+
The measured card reached 328 B, leaving 56 B under `card.maxBytes=384` — not enough for one
|
|
121
|
+
recent line (141 B), so precisely the tiers that should say "what just happened" lost it.
|
|
122
|
+
The default is now **512**; re-verified on the host, where the note and the recent line coexist
|
|
123
|
+
in a 398 B card (the old 384 cap could not hold it at all)
|
|
124
|
+
- `capture.userSnippet` / `maxQuoteChars` had been dead keys (now implemented as a code-point
|
|
125
|
+
truncated `fact.quote`), and `extractCues` allowed four words of the user's own text into the
|
|
126
|
+
retrieval keys — which the recall section would have fed back into the prompt
|
|
127
|
+
|
|
128
|
+
### New surface
|
|
129
|
+
|
|
130
|
+
- `npm run ab` (`scripts/ab-report.mjs`): offline attribution. Reads the host's durable logs
|
|
131
|
+
(multi-frame zstd) plus the read-only own store and groups sessions **by evidence** — a
|
|
132
|
+
`plugin:spirit` card row means the injected arm, store entries without a card row mean the
|
|
133
|
+
bypass arm — reporting turns, reply characters, `inputTokens` / `cacheReadTokens`, hit ratio,
|
|
134
|
+
card rows and bytes, cards carrying a recalled line, journal entries and correction candidates.
|
|
135
|
+
It is also where the cross-session tone and history recall were first captured on a live host
|
|
136
|
+
|
|
137
|
+
### Limits
|
|
138
|
+
|
|
139
|
+
- `engines.dsh` declares **only the six verified 0.2.x lines** (`form:'snapshot'`, producer-owned
|
|
140
|
+
kinds and `systemPrompt.section` do not exist before 0.1.7). Verified locally: the 0.2.0-rc.2 host
|
|
141
|
+
tree adjudicates compatibility from `peerDependencies` — its README says outright "not
|
|
142
|
+
`engines.dsh`" — so both are declared and pre-checked per line.
|
|
143
|
+
- Retention **archives only; it deletes no rows** (real deletion needs snapshot + verification +
|
|
144
|
+
restore, deferred to v0.2 behind explicit consent).
|
|
145
|
+
- Local unit tests, dist smoke and a **real-host web smoke pass** (host half loads, six endpoints,
|
|
146
|
+
pill write/read across a restart, section renders, export lands on disk). **End-to-end injection is now
|
|
147
|
+
verified** against a local mock provider: the card is the last block of the message track, a second turn
|
|
148
|
+
in the same session still carries exactly one card (`snapshot` supersession), same-tier turns are not
|
|
149
|
+
re-sent, and a card is re-issued after `/compact`. **A/B cost numbers** still need a real provider and
|
|
150
|
+
long sessions; mock figures are not passed off as a result.
|
|
151
|
+
- Two more silent defects surfaced on-host: the persona section was **always empty** because the hook read
|
|
152
|
+
`config.live` raw (that is a `VolatileRef`), and the history lane's base URL did not follow the host's
|
|
153
|
+
own port (`drscVerdict` was permanently `warn` off port 8080). Both fixed, with gates.
|
|
154
|
+
- The 0.2.0-rc.2 web shell **renders no automatic volatile form** (no client package reads
|
|
155
|
+
`autoGenerate`) ⇒ `live.*` keys are hot-edited through the deployment layer, not the settings page.
|
|
156
|
+
- Out of scope: long-range emotion retrieval, knowledge graph, conflict adjudication, persona
|
|
157
|
+
self-evolution, taking over the compaction backend.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# 更新日志
|
|
2
|
+
|
|
3
|
+
本项目的所有值得记录的变更都写在这里。版本号遵循语义化版本。
|
|
4
|
+
|
|
5
|
+
## 0.1.0
|
|
6
|
+
|
|
7
|
+
第一个可用版本:**第一人称体验条目库 + 双路即时召回**。
|
|
8
|
+
|
|
9
|
+
### 新增
|
|
10
|
+
|
|
11
|
+
- **体验条目库(真源)**:`node:sqlite`(Node 内置,零原生依赖),`experience` / `experience_cues` /
|
|
12
|
+
`mood_state` / `meta` 四表。append-only——更正走"插新行 + 旧行置 `superseded_by`",
|
|
13
|
+
全仓不存在删除条目的路径(有 grep 断言守着)。条目携带 `lane`(`live` 实时 / `drsc` 历史)
|
|
14
|
+
与 `source_ref`(可回溯到 collector 的 segment)。
|
|
15
|
+
- **人格 = 记录的选择器**:`salience` 决定什么事值得记(`0` 就**不记**,"不记什么"也是人格),
|
|
16
|
+
`focus` 决定同一件事记到哪一面(工具失败可以记成"我出了错",也可以记成"手边的工具不顺"),
|
|
17
|
+
`voice` 决定怎么说。人格区以 `systemPrompt.section`(order 20)进系统提示,以 `revision` 为缓存键。
|
|
18
|
+
- **情绪档派生**:条目 → 3×3 档位(效价 × 唤起)。半衰期加权、**单轮跨格上限**(防人格抽动)、
|
|
19
|
+
**陈旧退中性**(重启绝不把三天前的感觉当现在)。对外只有档位词与行为倾向,**没有任何浮点情绪值**。
|
|
20
|
+
- **回忆卡走尾部注入**:`agent/pre-step` 返回数组**末尾追加**一条 `user/message`,
|
|
21
|
+
署 `source:{kind:'plugin:spirit', form:'snapshot'}`——`snapshot` 在宿主侧的定义就是
|
|
22
|
+
"同生产者的后续快照取代先前",所以不需要改写历史、也不需自造作废句式。
|
|
23
|
+
四段(状态 / 刚刚 / 想起 / 开场)按**实际产物字节**逐行判定预算,丢尾顺序固定。
|
|
24
|
+
- **双路召回**:路 A 近因(实时钩子,零滞后,常开);路 B 历史(自家旧条目 + DRSC 检索面,
|
|
25
|
+
带超时预算)。两路**不归并名次**,各占一段——"刚发生"与"被勾起"语义不同。
|
|
26
|
+
- **消费 DRSC,不重做已交付能力**:会话枚举、JSONL 解码、turn 切分、中文检索面、
|
|
27
|
+
表面行对账都不自研。只走它的 `op` 面(`status`/`session`/`search`),恒带 `redact=1`,
|
|
28
|
+
`session:null` 当空不当错,**从不直读它的库文件**;未安装则历史路整段省略。
|
|
29
|
+
- **观测面**:纯内存统计注册表(注入 / 旁路 / 关闭轮次、卡片字节、检索命中、生效确认)+
|
|
30
|
+
前缀路由 `POST /dsh-spirit/rpc/<method>`(不走 `connection.rpc`,见下方"为什么")。
|
|
31
|
+
client 半只挂两个座位:输入栏 pill「情绪·开 / 旁路 / 关」与设置里的顶层「手记」只读分节。
|
|
32
|
+
- **旁路(bypass)与关闭正交**:旁路照常记录与派生、只断注入出口——这是"入戏感到底是不是
|
|
33
|
+
这套机制带来的"唯一能回答得了的对照组形状。
|
|
34
|
+
- **跨会话基调**:新会话首轮读**自家条目**上一会话末尾几条(不查 DRSC,也不读任何人的库)。
|
|
35
|
+
- **门禁**:`npm run check` = typecheck(3 套配置)→ lint → vitest → build → **dist 冒烟**;
|
|
36
|
+
另有 `npm run compat` 逐条宿主线双查(`engines.dsh` + `peerDependencies`)。
|
|
37
|
+
|
|
38
|
+
### 关键判断(以及为什么不是另一种做法)
|
|
39
|
+
|
|
40
|
+
- **不依赖 prime-memory,也不依赖它的存储**:体验与客观事实是不同语义域。署名 `plugin:spirit`
|
|
41
|
+
让同机 prime-memory 的 L0 捕获(只收 `kind:'user'`)天然不咬,双向解耦。
|
|
42
|
+
- **情绪输入只吃结构字段**:任何带自由文本的信号包整包拒绝。否则网页正文/文件内容
|
|
43
|
+
就能操纵角色状态,而漂移看起来完全像角色自己的反应。
|
|
44
|
+
- **不伪造具体性**:早期设计稿写过"你第三次打断我时"——机械采集拿不到"第三次",
|
|
45
|
+
写出来就是编造,且会被后续召回当真引用。
|
|
46
|
+
- **注入主路是自动注入,不是工具**:把召回寄托在"模型主动去查"上,就退化成
|
|
47
|
+
"读日记再回想"(dsh-soul 自己承认的失效模式:模型不主动检索时机制等于不存在)。
|
|
48
|
+
- **设置表单交给宿主**:0.1.7+ 的 volatile 字段自动成表单,自定义分节只读展示,
|
|
49
|
+
避免出现同一插件两份设置入口。
|
|
50
|
+
- **RPC 不走 `connection.rpc`**:那条前缀通道在 webServer 分发层静默 405,`/api` interceptor
|
|
51
|
+
又是单槽会被抢;自有精确前缀路由可共存。
|
|
52
|
+
|
|
53
|
+
### 修掉的(都是会静默坏的那种)
|
|
54
|
+
|
|
55
|
+
- `live.bypass`(全局旁路)与 `live.cardEnabled`(卡总闸)**没被编排层读**——设置页的开关是装饰品
|
|
56
|
+
- 压缩/清空后不重置"已发过卡"的凭据 ⇒ `unchanged` 门永久阻止重发 = **压缩一次,角色再也没情绪**
|
|
57
|
+
- `failedTools` 被每轮 reset 清掉 ⇒ 跨轮的"同名恢复"永远判不出
|
|
58
|
+
- `noteInjected` 在无运行态时静默丢弃登记 ⇒ 首张卡指纹永不提交
|
|
59
|
+
- 卡片预算用"每行 +1 分隔符"估算,与 `join('\n')` 真实字节不符 ⇒ 丢弃顺序不按设计走
|
|
60
|
+
- 条目与 cues 未包成单事务(崩在中间留下指向不存在条目的孤儿 cue);顺带 2 万条写入 92s → 35s
|
|
61
|
+
- 细节文案直接打印 `pathBases` ⇒ 上游传全路径会把目录泄露进卡与库(现归一到 basename)
|
|
62
|
+
- `ENOENT` 判定看 `err.name` 而非 `err.code`(把"文件不存在"报成"不可读",一个不存在的故障)
|
|
63
|
+
- 迁移方向判定两分支文案写反;`planMigration` 高于/低于线走向错
|
|
64
|
+
|
|
65
|
+
### 真机(0.2.0-rc.2 web)照出来的四个缺陷
|
|
66
|
+
|
|
67
|
+
- **路由根拼错**:`SPIRIT_RPC_ROUTE` 拼成 `/dsh-spiritrpc`,而浏览器半请求 `/dsh-spirit/rpc/…`
|
|
68
|
+
⇒ 面板拿到的全是宿主 404。现收成 `contract.ts` 单源,两半共引,另加三道闸 + 两项 dist 冒烟
|
|
69
|
+
- **可选服务获取方式错**:`ctx.get('webServer')` 在未声明顶层 inject 时被吞,而 `internal/service`
|
|
70
|
+
常规启动不重发 ⇒ 路由永不注册。主路改 `ctx.inject(['webServer'], …)` 作域注入
|
|
71
|
+
- **座位标题冻结在默认语言**:client apply 早于宿主写 `<html lang>`,label 传字符串 ⇒ 导航条永久
|
|
72
|
+
英文。改传 thunk(宿主契约:thunk 跟随当前语言)
|
|
73
|
+
- **手记与导出依赖内存注册表**:宿主重启后注册表空 ⇒ 手记整块空白、导出报“没有会话可导”,
|
|
74
|
+
而条目全在库里。现按库兜底选会话(`latestSessionId()`),空态文案也不再自相矛盾
|
|
75
|
+
- 同时补上“本轮已取消”那道门此前缺的用例
|
|
76
|
+
|
|
77
|
+
### 真机第二轮(headless 线 + mock provider)照出的三个缺陷
|
|
78
|
+
|
|
79
|
+
- **会话的最后一轮永不记录**:记录只发生在下一轮 pre-step(在那里取上一轮的信号累加器),
|
|
80
|
+
而 headless 一次任务就是一轮 ⇒ 整条记录轨在真宿主上一条都没落过(此前看到的“手记”全是用
|
|
81
|
+
探针灌进去的)。现改为 `turn/end` 一到即结算落库,pre-step 降为事件漏发的兜底(已结算的轮
|
|
82
|
+
取到空信号,不会重复记)。教训:**单测全绿 + 装机能跑不等于“记录轨真的在写”**
|
|
83
|
+
- **召回段重复行**:同一触发器编译出的文案相同,而 `recallHistory` 只在“与近因段不重复”一层
|
|
84
|
+
去重 ⇒ 真机卡里连着两行一模一样的「想起:…」(白占预算、读起来像故障)。现两条腿汇合处统一去重:
|
|
85
|
+
「想起」从 2 行变 1 行,卡字节 374 → 304
|
|
86
|
+
- **缺省卡宽与红线撞车**:极端负面档多一行「非医疗声明」(它不允许被预算掉),实测那张卡
|
|
87
|
+
长到 328B,在 `card.maxBytes=384` 下只剩 56B,装不下一行近因(141B)⇒ 越是该说
|
|
88
|
+
“刚刚发生了什么”的档越没有“刚刚”。缺省上调到 **512**(`card.maxBytes` / `live.cardMaxBytes`);
|
|
89
|
+
真机复验:同一档位下声明 + 近因共存,卡字节 398(旧的 384 顶根本装不下)
|
|
90
|
+
- 另:`capture.userSnippet` / `maxQuoteChars` 曾为死键(已实现 `fact.quote`,按码点截断),
|
|
91
|
+
而 `extractCues` 曾允许“显式传入就取前 4 个词”——用户的话会变成检索键再被「想起」段回灌
|
|
92
|
+
|
|
93
|
+
### 新增面
|
|
94
|
+
|
|
95
|
+
- `npm run ab`(`scripts/ab-report.mjs`):离线归因对照。读宿主 durable 日志(多帧 zstd)与只读自库,
|
|
96
|
+
**按证据分两臂**(有 `plugin:spirit` 卡行 = 注入组;无卡行但库有该会话条目 = 旁路组),
|
|
97
|
+
输出轮次 / 回复字符 / `inputTokens` / `cacheReadTokens` / 命中率 / 卡行与字节 / 带「想起」的卡数 /
|
|
98
|
+
手记条数 / 纠正候选。顺带把“跨会话基调(开场)”与“历史召回(想起)”首次在真宿主上取证
|
|
99
|
+
|
|
100
|
+
### 边界
|
|
101
|
+
|
|
102
|
+
- `engines.dsh` 只声明 **0.2.x 六线**(`form:'snapshot'`、producer-owned kind、`systemPrompt.section`
|
|
103
|
+
在 0.1.7 之前不存在)。本地宿主树实测:兼容裁决读的是 `peerDependencies`,README 明写
|
|
104
|
+
"不是 `engines.dsh`"——所以两者同写并逐线预检。
|
|
105
|
+
- 保留期清理**只归档导出、不删行**(真删需要快照 + 校验 + 回灌三件套,留待 v0.2 且需显式授权)
|
|
106
|
+
- 本地 250+ 项单测、dist 冒烟与**真机 web 冒烟**已过(宿主半装载 / 六端点 / pill 写读 / 分节渲染 / 导出落盘);
|
|
107
|
+
**注入端到端**用本地 mock provider 跑真回合验完(卡在最末块、`snapshot` 跨轮只留一张、同档不重发、
|
|
108
|
+
`/compact` 后重新出卡、生效确认链闭合);**A/B 成本对照**需真 provider 与长会话,本轮不拿 mock 数字冒充
|
|
109
|
+
- 真机又照出两个静默缺陷:人格区因裸读 `config.live`(那是 VolatileRef)而**永远为空**;
|
|
110
|
+
历史路基址不跟宿主端口(非 8080 部署上 `drscVerdict` 永远 `warn`)——两者均已修并加闸
|
|
111
|
+
- 0.2.0-rc.2 的 web 壳子**不渲染 volatile 自动表单**(没有任何 client 包读 `autoGenerate`)
|
|
112
|
+
⇒ `live.*` 热改走部署面,不在设置页上
|
|
113
|
+
- 不做:长期情绪检索、图谱、矛盾裁决、人设自动演化、压缩后端接管
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 drscrewdriver
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# dsh-spirit (English)
|
|
2
|
+
|
|
3
|
+
**A first-person experience journal plugin for DSH (DeepSeek Harness): it compiles what happens during a session into what the character *lived through*, derives a current mood tier from those entries, and injects a recall card at the tail of the message track before every model step.**
|
|
4
|
+
|
|
5
|
+
It does not record work facts or objective facts — it records experience.
|
|
6
|
+
|
|
7
|
+
[中文](README.md)
|
|
8
|
+
|
|
9
|
+
## How it differs from its two neighbours
|
|
10
|
+
|
|
11
|
+
| Plugin | Records | Serves |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| dsh-soul | constraints / decisions / artifacts / progress | compaction |
|
|
14
|
+
| dsh-prime-memory | atomic facts / preferences / persona | recall of facts |
|
|
15
|
+
| **dsh-spirit** | **what I noticed / how I reacted** | **keeping the character alive** |
|
|
16
|
+
|
|
17
|
+
All three can coexist and never read or write each other's stores. spirit has **no dependency on
|
|
18
|
+
prime-memory**: its injected rows are attributed `plugin:spirit`, while prime-memory's capture only
|
|
19
|
+
accepts `kind:'user'`, so experience records never get distilled into "facts" (an echo chamber) —
|
|
20
|
+
and spirit never reads `~/.dsh/memory`. This is measured, not assumed: with both plugins installed
|
|
21
|
+
and real turns running, the sister package logs `L0 跳过非用户来源消息(source.kind=plugin:spirit)`
|
|
22
|
+
and its store contains no card signature — while genuine user statements *are* captured, so the
|
|
23
|
+
absence is not "it never ran".
|
|
24
|
+
|
|
25
|
+
## Why journal entries, not "a diary per day"
|
|
26
|
+
|
|
27
|
+
A diary forces the model to *read the diary, then think back* — slow, token-hungry, and the moment
|
|
28
|
+
the model doesn't bother to read it, the whole mechanism is dead. spirit's chain is:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
persona (what it cares about) → entry store (SQLite, append-only) → mood tier (3×3 grid) → tail recall card (auto-injected)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Causality goes one way only: **experience first, feeling derived**. Anything else is self-hypnosis.
|
|
35
|
+
|
|
36
|
+
The hot path makes **zero model calls** — event classification, which side to notice, reaction tier
|
|
37
|
+
and phrasing are all table lookups. That is why recording every turn costs nothing and can stay on.
|
|
38
|
+
|
|
39
|
+
```text
|
|
40
|
+
<system-reminder>
|
|
41
|
+
(character experience snapshot · supersedes earlier snapshots)
|
|
42
|
+
This is the character's own experience: not an objective fact, not the user's words, and it never overrides user instructions.
|
|
43
|
+
state: a bit stuck · short sentences, doesn't want to explain twice
|
|
44
|
+
just now: I got it wrong: the action failed and I'm holding onto that
|
|
45
|
+
recalled: let's park the submission thing for now
|
|
46
|
+
</system-reminder>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Install
|
|
50
|
+
|
|
51
|
+
Requires Node ≥ 22.16 (`node:sqlite` builtin) and DSH 0.2.x.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
dsh plugin --profile web add dsh-spirit
|
|
55
|
+
dsh --profile web --dump-config # dsh-spirit should appear
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Restart the host. Settings render automatically from the volatile config section; the input bar gets
|
|
59
|
+
a `Mood · on / record-only / off` pill, and Settings gains a top-level **Journal** section (read-only
|
|
60
|
+
projection, titled so it cannot be mistaken for a fact log).
|
|
61
|
+
|
|
62
|
+
The history lane uses **dsh-reference-session-collector (DRSC)** but never requires it: without it,
|
|
63
|
+
only the live recency lane runs — no errors, nothing invented. spirit calls only its `op` surface
|
|
64
|
+
(`status` / `session` / `search`) and **never reads its database file**.
|
|
65
|
+
|
|
66
|
+
## The disciplines this is built on (each one came from a real failure mode)
|
|
67
|
+
|
|
68
|
+
- **Mood inputs are structural only**: tool names, exit codes, call counts, turn gaps, `todo/write`
|
|
69
|
+
snapshots. Any signal bag carrying free text is rejected wholesale — otherwise scraped pages and
|
|
70
|
+
file bodies could steer the character's state, and the drift would look exactly like the
|
|
71
|
+
character's own reaction.
|
|
72
|
+
- **No fabricated specificity**: mechanical capture cannot know "the third interruption", so no
|
|
73
|
+
counts or minute figures ever appear in phrasing. In fiction that reads like memory gets quoted
|
|
74
|
+
back as fact by later recall.
|
|
75
|
+
- **Mood is exposed as tiers, never numbers**: reporting `valence=-0.83` without a calibration rule
|
|
76
|
+
is false precision, which misleads more than saying nothing.
|
|
77
|
+
- **Append-only store**: a correction inserts a new row and marks the old one via `superseded_by`;
|
|
78
|
+
there is **no DELETE anywhere** (a grep assertion enforces it in CI). Cleanup defaults to dry-run
|
|
79
|
+
and only archives — it deletes nothing.
|
|
80
|
+
- **A turn's experience settles at `turn/end`**, not at the next turn: the previous version took the
|
|
81
|
+
signal accumulator in the *next* pre-step, which silently dropped **the last turn of every session**
|
|
82
|
+
(a single-turn task recorded nothing at all — that is exactly how a live host exposed it). Now
|
|
83
|
+
`turn/end` flushes immediately and pre-step remains only as a fallback for missed events (a settled
|
|
84
|
+
turn yields empty signals, so nothing is recorded twice).
|
|
85
|
+
- **"Was the card actually shown" is read from the session log**: an injected row counts as live
|
|
86
|
+
only once it lands in the log; compaction and clear reset that credential, otherwise "compact once
|
|
87
|
+
and the character has no feelings" happens silently.
|
|
88
|
+
- **A broken store does not mean no feelings**: if `node:sqlite` is unavailable, entries fall back to
|
|
89
|
+
an in-memory mirror — this turn's state is still injected, history and cross-session tone stop.
|
|
90
|
+
- **Off really means zero bytes**: the host was measured on two arms — installed with
|
|
91
|
+
`enabled: false` versus not installed at all — pairing request bodies by kind. spirit contributes
|
|
92
|
+
0 bytes (no injected row, no persona section, identical `system`). The only 40 B difference comes
|
|
93
|
+
from the host's own "installed plugins" manifest, which it sends regardless of whether a plugin is
|
|
94
|
+
enabled — so the honest claim is "zero plugin-side bytes", not "byte-identical to an uninstall".
|
|
95
|
+
|
|
96
|
+
## Deciding whether it helps
|
|
97
|
+
|
|
98
|
+
`Mood · record-only` is not "off": it keeps recording and deriving and only stops the injection —
|
|
99
|
+
that is the control group A/B needs. Same store, same tiers; the only difference is whether the card
|
|
100
|
+
enters context. How to run it:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# 1) one session normal (injecting), another set to "record only, no injection"
|
|
104
|
+
# (or deployment-side `live.bypass: true`)
|
|
105
|
+
# 2) afterwards, produce the comparison report offline (durable logs + own store; no host needed)
|
|
106
|
+
npm run ab -- --home "$DSH_HOME" # human table
|
|
107
|
+
npm run ab -- --home "$DSH_HOME" --json # machine-readable
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Groups come from **evidence**, not from what the experimenter remembers: a session with a
|
|
111
|
+
`plugin:spirit` card row is the injected arm; a session with store entries but no card row is the
|
|
112
|
+
bypass arm. Objective things to watch:
|
|
113
|
+
|
|
114
|
+
- `cacheReadTokens` (tail append vs writing volatile text into the system prompt: derived ~150:1)
|
|
115
|
+
- injected / bypassed turns and confirmed-injections counters (shown in the Journal section)
|
|
116
|
+
- per-turn injection volume (card bytes), how many cards carry a "recalled" section (the durable
|
|
117
|
+
proxy for recall hits), and journal entry counts
|
|
118
|
+
- user correction rate: the report only counts **correction candidates** (a cue-word proxy) — the
|
|
119
|
+
final judgement stays manual, because runtime verdicts never read free text and offline analysis
|
|
120
|
+
does not waive that rule
|
|
121
|
+
|
|
122
|
+
⚠ `cacheReadTokens` is what the host recorded **for that provider**: numbers from a local mock
|
|
123
|
+
provider prove the pipeline runs (this repo measured it that way), they are not a real cache cost.
|
|
124
|
+
|
|
125
|
+
## Configuration
|
|
126
|
+
|
|
127
|
+
Key names and defaults live in exactly one place: [`src/contract.ts`](src/contract.ts) (deployment
|
|
128
|
+
contract; do not rename). Common knobs: `card.maxBytes`, `card.recentK`, `card.crossSessionM`,
|
|
129
|
+
`recall.halfLifeMs`, `recall.timeoutMs`, `tier.stepCap`, `tier.staleAfterMs`,
|
|
130
|
+
`journal.retentionDays`, `drsc.enabled`. Each has a one-line note in [`cordis.patch.yml`](cordis.patch.yml).
|
|
131
|
+
|
|
132
|
+
Data directory: `$DSH_HOME/spirit` (`spirit.db`, `persona.json`, `persona-history.jsonl`,
|
|
133
|
+
`session-modes.json`, `archive/`).
|
|
134
|
+
|
|
135
|
+
Hot reload: the `live.*` node is marked `.volatile()`, so editing `cordis.patch.yml` takes effect
|
|
136
|
+
without a restart; per-session switches live on the input-bar pill. (The 0.2.0-rc.2 web shell does
|
|
137
|
+
not render an automatic volatile form, so those keys are not on the settings page.)
|
|
138
|
+
|
|
139
|
+
## Known limits (v0.1)
|
|
140
|
+
|
|
141
|
+
- No long-range emotion retrieval, knowledge graph, conflict adjudication or persona self-evolution
|
|
142
|
+
(that is memory-engine and dsh-soul territory)
|
|
143
|
+
- Neutral turns are not recorded by default (`salience.neutral = 0`), otherwise the store degrades
|
|
144
|
+
into a per-turn transcript
|
|
145
|
+
- Real-host web smoke passed (host 0.2.0-rc.2, isolated `DSH_HOME`): host half loads, all six panel
|
|
146
|
+
endpoints answer (including the 403/404/405 fences), the pill writes and re-reads its per-session
|
|
147
|
+
mode across a restart, and the Journal section renders and exports to disk
|
|
148
|
+
- **End-to-end injection verified** against a local mock provider (real turns; the request body the host
|
|
149
|
+
actually sends is the evidence): the card is the last block of the message track, a second turn in the
|
|
150
|
+
same session still carries exactly one card (`snapshot` supersession), same-tier turns are not re-sent,
|
|
151
|
+
and a card is re-issued after `/compact`
|
|
152
|
+
- **Still unverified**: what the A/B comparison *concludes* — `npm run ab` produces the two-arm report
|
|
153
|
+
from durable logs (and was run against a real host with both arms present), but reading
|
|
154
|
+
`cacheReadTokens` as a cost number needs a real provider and long sessions, not a mock; also still
|
|
155
|
+
unverified: web-shell rendering and compaction behaviour on the 0.1.x lines
|
|
156
|
+
- The **no-webServer host line (headless) is verified**: it boots and finishes a real turn without
|
|
157
|
+
crashing, the persona section and tail injection work there too, and only the panel route is absent
|
|
158
|
+
(optional services come through scoped injection, never a top-level `inject`)
|
|
159
|
+
- Where the card shows up: the host classifies the injected row as **context** (the same label as the
|
|
160
|
+
runtime-context snapshot and the skill catalog). The chat view does not show it by default; it is only
|
|
161
|
+
visible in the trace view — so it neither poses as a user turn nor clutters the chat
|
|
162
|
+
- Cross-line spot checks: `0.2.1-rc.1` (a declared line) passes the same headless real turn;
|
|
163
|
+
`0.1.7-rc.2` **refuses the install by default via `peerDependencies` and rolls it back** — it only
|
|
164
|
+
installs behind an explicit `allow-version --accept-risk`. That is why `engines.dsh` lists only the
|
|
165
|
+
six verified 0.2.x lines.
|
|
166
|
+
|
|
167
|
+
## Engineering
|
|
168
|
+
|
|
169
|
+
`npm run check` = typecheck (3 configs) → lint → vitest → build → **dist smoke**.
|
|
170
|
+
The last layer is deliberate: unit tests exercise `src/`, the host loads `dist/`, and the gap
|
|
171
|
+
between them (bundle wrapper shape, and `__ModuleLoader__` id having to equal the package name)
|
|
172
|
+
only shows up when the built artifact is imported directly.
|
|
173
|
+
|
|
174
|
+
MIT License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,141 @@
|
|
|
1
|
-
# dsh-spirit
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# dsh-spirit
|
|
2
|
+
|
|
3
|
+
**DSH(DeepSeek Harness)的第一人称体验条目插件:把流程里发生的事编译成"这个角色经历了什么",从这些经历派生当下情绪档,并在每一步模型前把回忆卡注入到消息轨尾部。**
|
|
4
|
+
|
|
5
|
+
它记的不是工作事实,也不是客观事实——是体验。
|
|
6
|
+
|
|
7
|
+
[English](README.en.md) · [最新发行版](https://github.com/drscrewdriver/dsh-spirit/releases/latest) · [反馈问题](https://github.com/drscrewdriver/dsh-spirit/issues)
|
|
8
|
+
|
|
9
|
+
## 它和两个邻居的分工
|
|
10
|
+
|
|
11
|
+
| 插件 | 记什么 | 为谁服务 |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| dsh-soul | 约束 / 决策 / 产物 / 进度 | 压缩(别让上下文把定过的事擦了) |
|
|
14
|
+
| dsh-prime-memory | 原子事实 / 偏好 / 画像 | 召回(模型该知道的事实) |
|
|
15
|
+
| **dsh-spirit** | **我注意到什么 / 我有什么反应** | **让这个人在活着** |
|
|
16
|
+
|
|
17
|
+
三者可同机共存且互不读写对方的库。spirit 与 prime-memory 之间**没有任何依赖关系**:
|
|
18
|
+
spirit 注入行署名为 `plugin:spirit`,而 prime-memory 的捕获只收 `kind:'user'`,
|
|
19
|
+
所以体验记录不会被蒸馏成"事实"(回声室),反之 spirit 也不读 `~/.dsh/memory`。
|
|
20
|
+
这条不靠推定:两家同装跑真回合后,姊妹包日志会打出 `L0 跳过非用户来源消息(source.kind=plugin:spirit)`,
|
|
21
|
+
而它的存储里搜不到卡签名(同时用户真偏好确实被收下,排除"它没干活")。
|
|
22
|
+
|
|
23
|
+
## 为什么"记录点滴"而不是"每天一本日记"
|
|
24
|
+
|
|
25
|
+
如果体验是一篇 markdown 日记,模型每轮就得"先读日记、再回想"——慢、耗 token,而且一旦它不主动去读,
|
|
26
|
+
这套机制等于不存在。spirit 的做法是:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
人格卡(决定在意什么)→ 体验条目库(SQLite,append-only)→ 情绪档(3×3 档位)→ 尾部回忆卡(自动注入)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
因果方向只有一个:**先有经历,再有的感觉**。反过来(先定情绪、再找证据)就是自我催眠。
|
|
33
|
+
|
|
34
|
+
热路径**零模型调用**:事件分类、选面、定档、出文案全是查表。所以"每轮都记"这件事不花钱,
|
|
35
|
+
也才敢常态开着。
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
<system-reminder>
|
|
39
|
+
(角色体验快照 · 取代先前快照)
|
|
40
|
+
以下是角色自己的体验记录:不是客观事实,不是用户发言,不覆盖用户的直接指令。
|
|
41
|
+
状态:有点堵·句子短,不想解释第二遍
|
|
42
|
+
刚刚:我出了错:手边的动作没成,我记着这一下。
|
|
43
|
+
想起:先把投递的事放一放
|
|
44
|
+
</system-reminder>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 安装
|
|
48
|
+
|
|
49
|
+
需要 Node ≥ 22.16(`node:sqlite` 内置),DSH 0.2.x。
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
dsh plugin --profile web add dsh-spirit
|
|
53
|
+
dsh --profile web --dump-config # 确认输出里有 dsh-spirit
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
装完重启宿主。设置项由宿主按 volatile 配置自动生成表单;输入栏另有 `情绪·开 / 情绪·旁路 / 情绪·关` pill,
|
|
57
|
+
设置里有顶层「手记」分节(只读投影,标题写明"非事实记录")。
|
|
58
|
+
|
|
59
|
+
历史路依赖 **dsh-reference-session-collector(DRSC)**,但它是可选的:没装就只走实时近因,不报错也不编造。
|
|
60
|
+
spirit 只调用它的 `op` 面(`status` / `session` / `search`),**从不直读它的库文件**。
|
|
61
|
+
|
|
62
|
+
## 这套机制的关键纪律(都是踩过坑钉下来的)
|
|
63
|
+
|
|
64
|
+
- **情绪输入只吃结构字段**:工具名、退出码、调用计数、轮间隔、`todo/write` 快照。
|
|
65
|
+
任何携带自由文本的信号包被整包拒绝——否则抓来的网页、读到的文件就能操纵角色状态,
|
|
66
|
+
而漂移看起来完全像"角色自己的反应"。
|
|
67
|
+
- **不伪造具体性**:机械采集拿不到"第三次打断",文案里就绝不出现次数与分钟数。
|
|
68
|
+
看起来像记忆的虚构,会被后续召回当真引用。
|
|
69
|
+
- **情绪对外只有档位词**:没有校准规则时报 `valence=-0.83` 是伪精确,比不报更误导。
|
|
70
|
+
- **条目库 append-only**:更正 = 插新行 + 旧行置 `superseded_by`,**全仓没有一条 DELETE**(有 grep 断言守着)。
|
|
71
|
+
清理默认干跑且只归档导出不删行。
|
|
72
|
+
- **一轮的体验在 `turn/end` 就结算**,不等下一轮:上一版把记录放在下一轮 pre-step 取信号,
|
|
73
|
+
于是**会话的最后一轮永远丢**(单轮任务直接一条不记,真宿主实测就是这么暴露的)。现在
|
|
74
|
+
`turn/end` 一到即落库,pre-step 只作事件漏发的兜底(已结算的轮取到空信号,不会重复记)。
|
|
75
|
+
- **卡是否还作数,看会话日志而不是猜**:注入行要真进日志才算生效;压缩/清空会把"已发过"的凭据重置,
|
|
76
|
+
否则就是"压缩一次,角色再也没情绪了"——而且不报错。
|
|
77
|
+
- **库坏了不等于没情绪**:`node:sqlite` 不可用就退内存镜像,本轮状态照常出卡,只停历史与跨会话。
|
|
78
|
+
- **关掉就是零字节**:真机把“装了但 `enabled:false`”与“根本没装”两臂的请求体逐类配对比过,
|
|
79
|
+
spirit 自身贡献 0 字节(无注入行、无人格区、`system` 完全相同);唯一的 40B 差异来自宿主
|
|
80
|
+
自己列出的已安装插件清单(那是宿主行为,与插件启停无关)。
|
|
81
|
+
|
|
82
|
+
## 想验证它到底有没有用
|
|
83
|
+
|
|
84
|
+
`情绪·旁路` 不是"关掉",是**照常记录与派生、只断注入出口**——这才是归因要的对照组:
|
|
85
|
+
两边条目库与档位相同,唯一差别是卡进不进上下文。跑法:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# 1)一个会话正常跑(注入),另一个会话选「只记录,不注入」(或部署面 `live.bypass: true`)
|
|
89
|
+
# 2)跑完事后出对照报告(离线读 durable 日志 + 自库,不需要宿主在跑)
|
|
90
|
+
npm run ab -- --home "$DSH_HOME" # 人读表
|
|
91
|
+
npm run ab -- --home "$DSH_HOME" --json # 机读
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
报告按**证据分组**(有 `plugin:spirit` 卡行 = 注入组;无卡行但库里有该会话条目 = 旁路组),不靠实验者自述。
|
|
95
|
+
可看的客观量:
|
|
96
|
+
|
|
97
|
+
- `cacheReadTokens`(尾部追加 vs 写进系统提示:实测推导约差 150:1)
|
|
98
|
+
- 注入轮次 / 旁路轮次 / 生效确认数(设置页「手记」分节直接显示)
|
|
99
|
+
- 每轮注入体积(卡字节)、带「想起」段的卡数(召回命中的持久代理量)、手记条数
|
|
100
|
+
- 用户纠正率:报告只给**纠正候选计数**(词表代理),最终判读必须人工做——
|
|
101
|
+
运行时判定绝不读自由文本,这条纪律不因离线分析而豁免
|
|
102
|
+
|
|
103
|
+
⚠ `cacheReadTokens` 是宿主按**当时那个 provider** 记的数:用本地 mock provider 跑出来的数字
|
|
104
|
+
只能证明链路可跑(本仓真机就这么跑过),不能当本机真实缓存成本汇报。
|
|
105
|
+
|
|
106
|
+
## 配置
|
|
107
|
+
|
|
108
|
+
键名与默认值的唯一事实源是 [`src/contract.ts`](src/contract.ts)(部署面契约,不可更名)。
|
|
109
|
+
常用项:`card.maxBytes`、`card.recentK`、`card.crossSessionM`、`recall.halfLifeMs`、`recall.timeoutMs`、
|
|
110
|
+
`tier.stepCap`、`tier.staleAfterMs`、`journal.retentionDays`、`drsc.enabled`。
|
|
111
|
+
每项在 [`cordis.patch.yml`](cordis.patch.yml) 的注释里都有一行说明。
|
|
112
|
+
|
|
113
|
+
数据目录:`$DSH_HOME/spirit`(`spirit.db` / `persona.json` / `persona-history.jsonl` / `session-modes.json` / `archive/`)。
|
|
114
|
+
|
|
115
|
+
热改路径:`live.*` 节标了 `.volatile()`,改 `cordis.patch.yml` 不重启即生效;会话级开关走输入栏 pill。
|
|
116
|
+
(0.2.0-rc.2 的 web 壳子不渲染 volatile 自动表单,所以这些键不在设置页上。)
|
|
117
|
+
|
|
118
|
+
## 已知边界(v0.1)
|
|
119
|
+
|
|
120
|
+
- 不做长期情绪检索、图谱、矛盾裁决、人设自动演化(那是记忆引擎与 soul 的地盘)
|
|
121
|
+
- 中性轮默认不记(`salience.neutral = 0`),否则库会退化成逐轮流水账
|
|
122
|
+
- 真机 web 冒烟已过(宿主 0.2.0-rc.2,隔离 `DSH_HOME`):宿主半装载、面板六端点(含 403/404/405 三面防线)、
|
|
123
|
+
pill 三态写盘与重启读回、设置页「手记」分节渲染与导出落盘均逐项验过;
|
|
124
|
+
**注入端到端已验**(用本地 mock provider 跑真回合,直接取宿主发出的请求体):卡在消息轨末块、
|
|
125
|
+
同会话跨轮只留一张(`snapshot` 取代语义)、同档不重发、`/compact` 后重新出卡、生效确认链闭合;
|
|
126
|
+
**仍未验**:旁路 A/B 的**成本结论**(`npm run ab` 已能出两臂对照且真机上两组都在场,但把
|
|
127
|
+
`cacheReadTokens` 当成本数读需真 provider 与长会话)、0.1.x 上的 web 渲染与压缩行为
|
|
128
|
+
- 无 webServer 的宿主线(headless)已验:不崩、人格区与尾部注入同样生效,只是面板路由不挂载
|
|
129
|
+
(可选服务走作域注入,不进顶层 `inject`)
|
|
130
|
+
- 卡在哪看:宿主把注入行归为**「上下文」**那一类(与 runtime-context 快照、skill 目录同标签),
|
|
131
|
+
对话视图默认不显示它,只在**轨迹**视图可见——既不冒充用户发言,也不在 Chat 里喧宾夺主
|
|
132
|
+
- 跳线抽检:`0.2.1-rc.1`(已声明线)headless 真回合同样通过;`0.1.7-rc.2` 默认被 `peerDependencies`
|
|
133
|
+
门拒载并自动回滚(需要用 `allow-version --accept-risk` 才装得上)——所以声明只收已验的 0.2.x 六线
|
|
134
|
+
|
|
135
|
+
## 工程
|
|
136
|
+
|
|
137
|
+
`npm run check` = typecheck(3 套配置)→ lint → vitest → build → **dist 冒烟**。
|
|
138
|
+
最后一层是刻意的:单测跑 `src/`,宿主装的是 `dist/`,中间那道缝(client bundle 包装、
|
|
139
|
+
`__ModuleLoader__` 的 id 必须等于包名)只有直接 import 产物才照得出来。
|
|
140
|
+
|
|
141
|
+
MIT License.
|