whale-memory-core 0.15.0 → 0.18.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.
Files changed (48) hide show
  1. package/README.md +14 -0
  2. package/bin/whale-memory-mcp.mjs +276 -0
  3. package/demo.mjs +44 -33
  4. package/index.d.ts +16 -15
  5. package/index.js +18 -17
  6. package/lib/archive.d.ts +22 -22
  7. package/lib/archive.js +171 -135
  8. package/lib/as-of.d.ts +5 -5
  9. package/lib/as-of.js +32 -32
  10. package/lib/book.d.ts +4 -4
  11. package/lib/book.js +75 -75
  12. package/lib/chapter-events.d.ts +39 -39
  13. package/lib/chapter-events.js +89 -89
  14. package/lib/detail-recall.d.ts +15 -0
  15. package/lib/detail-recall.js +174 -0
  16. package/lib/event-log.d.ts +10 -10
  17. package/lib/event-log.js +61 -61
  18. package/lib/evidence-from-experience.d.ts +8 -8
  19. package/lib/evidence-from-experience.js +62 -62
  20. package/lib/evidence-policy.js +2 -2
  21. package/lib/fact-timeline-contract.d.ts +73 -0
  22. package/lib/fact-timeline-contract.js +226 -0
  23. package/lib/fact-timeline-query.d.ts +29 -0
  24. package/lib/fact-timeline-query.js +97 -0
  25. package/lib/file-lock.js +1 -1
  26. package/lib/later-events.d.ts +21 -21
  27. package/lib/later-events.js +80 -80
  28. package/lib/link-events.d.ts +15 -15
  29. package/lib/link-events.js +33 -33
  30. package/lib/query-match.js +55 -0
  31. package/lib/recall-events.d.ts +24 -24
  32. package/lib/recall-events.js +97 -97
  33. package/lib/recap.d.ts +23 -23
  34. package/lib/recap.js +79 -79
  35. package/lib/seal-events.d.ts +25 -25
  36. package/lib/seal-events.js +82 -82
  37. package/lib/self-experience.d.ts +180 -175
  38. package/lib/self-experience.js +624 -560
  39. package/lib/self-memory.js +70 -68
  40. package/lib/self-prompt.js +8 -4
  41. package/lib/self-settings.js +2 -2
  42. package/lib/unfinished-events.d.ts +26 -26
  43. package/lib/unfinished-events.js +105 -105
  44. package/lib/unsaid.d.ts +28 -28
  45. package/lib/unsaid.js +105 -105
  46. package/lib/waking.d.ts +1 -1
  47. package/lib/waking.js +99 -92
  48. package/package.json +127 -113
@@ -1,176 +1,181 @@
1
- export type Weight = 'important' | 'normal' | 'minor'
2
-
3
- export interface Quote {
4
- text: string
5
- source?: string
6
- }
7
-
8
- export interface LaterEntry {
9
- at: string
10
- day?: string
11
- thought: string
12
- reason?: string
13
- /** 她后来再想起时的感觉(0.12 起);当时的感觉在 then.feeling 里,永远不动 */
14
- feeling?: string[]
15
- }
16
-
17
- /** 出处 / 反向引用里的一条:指路用的一句话摘要 */
18
- export interface ExperienceBrief {
19
- id: string
20
- day?: string
21
- text?: string
22
- /** 出处指向的经历找不到了(例如只恢复了部分文件) */
23
- missing?: boolean
24
- /** 那条经历她封存了:不给摘要 */
25
- sealed?: boolean
26
- }
27
-
28
- /** 「翻回那天的自己」:2026-11-15(截到那天本地时间的最后一刻)、完整 ISO 时间或 Date */
29
- export type AsOf = string | Date | null
30
-
31
- export interface Experience {
32
- id: string
33
- at: string
34
- day: string
35
- author?: string
36
- source?: string
37
- kind: string
38
- weight: Weight
39
- then: {
40
- text: string
41
- scene?: string
42
- feeling?: string[]
43
- thought?: string
44
- unfinished?: string
45
- quote?: Quote | null
46
- state?: Record<string, unknown> | null
47
- /** 这条是从哪几件事想到的(经历 id,写入时校验过存在) */
48
- refs?: string[]
49
- }
50
- later: LaterEntry[]
51
- /** 由 then.refs 派生:出处的摘要 */
52
- refsInfo?: ExperienceBrief[]
53
- /** 反向引用:后来有哪些回想把这条写进了出处 */
54
- citedBy?: ExperienceBrief[]
55
- /** 用 asOf 读出来时,截到的那一刻(ISO) */
56
- viewAsOf?: string
57
- /** 她封存了这件事(0.13 起):不会被召回、不进醒来块,但还在 */
58
- sealed?: { at: string; day: string; note: string }
59
- /** 事后联想(0.14 起):她亲手连起来的另一件事,两头都能看到 */
60
- links?: Array<ExperienceBrief & { reason: string; linkDay: string }>
61
- /** 这一天落在她起过名字的哪段日子里(0.14 起) */
62
- chapters?: Array<{ id: string; name: string }>
63
- recalls?: number
64
- lastRecalledAt?: string
65
- matchedIn?: Array<'then' | 'quote' | 'later'>
66
- /** 没弄完的事后来怎么样了:done=想通,shelved=先放下,reopen=又接着想 */
67
- unfinishedState?: {
68
- id: string
69
- at: string
70
- day: string
71
- choice: 'done' | 'shelved' | 'reopen'
72
- note: string
73
- /** 完整的选择历史,按追加顺序 */
74
- history: Array<'done' | 'shelved' | 'reopen'>
75
- }
76
- /** recall 返回:是哪几条后记让这条被想起 */
77
- matchedLater?: LaterEntry[]
78
- /** 0.10.0 之前的旧 id(只在唯一对应时出现);用它也能 revise / currentView */
79
- formerId?: string
80
- status?: string
81
- legacy?: boolean
82
- }
83
-
84
- export const LIMITS: Record<string, number>
85
-
86
- export function loadAll(dir: string, opts?: { asOf?: AsOf }): Experience[]
87
-
88
- export function addExperience(dir: string, opts: {
89
- text: string
90
- scene?: string
91
- feeling?: string[]
92
- thought?: string
93
- unfinished?: string
94
- quote?: Quote | null
95
- weight?: Weight
96
- kind?: string
97
- state?: Record<string, unknown> | null
98
- source?: string
99
- /** 出处:数组,或逗号分隔的字符串;引用不存在的经历会抛错,整条不写 */
100
- refs?: string[] | string
101
- }): Experience
102
-
103
- export function reviseExperience(dir: string, opts: { id: string; thought: string; reason?: string; feeling?: string[] | string }): {
104
- ok: boolean
105
- id?: string
106
- at?: string
107
- feeling?: string[]
108
- error?: string
109
- }
110
-
111
- export function markRecalled(dir: string, id: string): boolean
112
-
113
- export function currentView(dir: string, id: string, opts?: { asOf?: AsOf }): Experience | null
114
-
115
- export function recall(dir: string, query: string, opts?: {
116
- limit?: number
117
- minOverlap?: number
118
- mark?: boolean
119
- minRatio?: number
120
- mode?: 'strict' | 'loose'
121
- /** 在那天的自己里找;不能和 mark 一起用 */
122
- asOf?: AsOf
123
- /** 默认不召回她封存了的经历;只在"她自己要翻"时打开 */
124
- includeSealed?: boolean
125
- }): Experience[]
126
-
127
- /** 事后联想:两条都必须存在、必须写理由;同一对(不分方向)只连一次 */
128
- export function linkExperiences(dir: string, opts: { from: string; to: string; reason: string }): {
129
- ok: boolean
130
- from?: string
131
- to?: string
132
- noop?: boolean
133
- at?: string
134
- error?: string
135
- }
136
-
137
- /** 封存 / 解封:不删除任何东西;重复同一个动作是 noop */
138
- export function setSealed(dir: string, opts: { id: string; sealed?: boolean; note?: string }): {
139
- ok: boolean
140
- id?: string
141
- sealed?: boolean
142
- at?: string
143
- noop?: boolean
144
- error?: string
145
- }
146
-
147
- export function renderTwoPart(entry: Experience, opts?: { now?: Date }): string
148
-
149
- export interface PendingLegacyEvents {
150
- /** 几条旧经历共用的旧 id */
151
- id: string
152
- /** 可能的归属(当前 id) */
153
- candidates: string[]
154
- later: number
155
- recalls: number
156
- }
157
-
158
- export function pendingLegacyEvents(dir: string): PendingLegacyEvents[]
159
-
160
- export function setUnfinishedState(
161
- dir: string,
162
- opts: { id: string; choice: 'done' | 'shelved' | 'reopen'; note?: string }
163
- ): { ok: boolean; id?: string; at?: string; choice?: string; noop?: boolean; error?: string }
164
-
165
- export interface RecallContextItem {
166
- id: string
167
- day: string
168
- text: string
169
- thought: string
170
- weight: Weight
171
- raw: Experience
172
- }
173
-
174
- export function recallForContext(dir: string, query: string, opts?: { max?: number }): RecallContextItem[]
175
-
1
+ export type Weight = 'important' | 'normal' | 'minor'
2
+
3
+ export interface Quote {
4
+ text: string
5
+ source?: string
6
+ }
7
+
8
+ export interface LaterEntry {
9
+ at: string
10
+ day?: string
11
+ thought: string
12
+ reason?: string
13
+ /** 她后来再想起时的感觉(0.12 起);当时的感觉在 then.feeling 里,永远不动 */
14
+ feeling?: string[]
15
+ }
16
+
17
+ /** 出处 / 反向引用里的一条:指路用的一句话摘要 */
18
+ export interface ExperienceBrief {
19
+ id: string
20
+ day?: string
21
+ text?: string
22
+ /** 出处指向的经历找不到了(例如只恢复了部分文件) */
23
+ missing?: boolean
24
+ /** 那条经历她封存了:不给摘要 */
25
+ sealed?: boolean
26
+ }
27
+
28
+ /** 「翻回那天的自己」:2026-11-15(截到那天本地时间的最后一刻)、完整 ISO 时间或 Date */
29
+ export type AsOf = string | Date | null
30
+
31
+ export interface Experience {
32
+ id: string
33
+ at: string
34
+ day: string
35
+ author?: string
36
+ source?: string
37
+ kind: string
38
+ weight: Weight
39
+ then: {
40
+ text: string
41
+ scene?: string
42
+ feeling?: string[]
43
+ thought?: string
44
+ unfinished?: string
45
+ quote?: Quote | null
46
+ state?: Record<string, unknown> | null
47
+ /** 这条是从哪几件事想到的(经历 id,写入时校验过存在) */
48
+ refs?: string[]
49
+ }
50
+ later: LaterEntry[]
51
+ /** 由 then.refs 派生:出处的摘要 */
52
+ refsInfo?: ExperienceBrief[]
53
+ /** 反向引用:后来有哪些回想把这条写进了出处 */
54
+ citedBy?: ExperienceBrief[]
55
+ /** 用 asOf 读出来时,截到的那一刻(ISO) */
56
+ viewAsOf?: string
57
+ /** 她封存了这件事(0.13 起):不会被召回、不进醒来块,但还在 */
58
+ sealed?: { at: string; day: string; note: string }
59
+ /** 事后联想(0.14 起):她亲手连起来的另一件事,两头都能看到 */
60
+ links?: Array<ExperienceBrief & { reason: string; linkDay: string }>
61
+ /** 这一天落在她起过名字的哪段日子里(0.14 起) */
62
+ chapters?: Array<{ id: string; name: string }>
63
+ recalls?: number
64
+ lastRecalledAt?: string
65
+ matchedIn?: Array<'then' | 'quote' | 'later'>
66
+ /** 没弄完的事后来怎么样了:done=想通,shelved=先放下,reopen=又接着想 */
67
+ unfinishedState?: {
68
+ id: string
69
+ at: string
70
+ day: string
71
+ choice: 'done' | 'shelved' | 'reopen'
72
+ note: string
73
+ /** 完整的选择历史,按追加顺序 */
74
+ history: Array<'done' | 'shelved' | 'reopen'>
75
+ }
76
+ /** recall 返回:是哪几条后记让这条被想起 */
77
+ matchedLater?: LaterEntry[]
78
+ /** 0.10.0 之前的旧 id(只在唯一对应时出现);用它也能 revise / currentView */
79
+ formerId?: string
80
+ status?: string
81
+ legacy?: boolean
82
+ }
83
+
84
+ export const LIMITS: Record<string, number>
85
+
86
+ export function loadAll(dir: string, opts?: { asOf?: AsOf }): Experience[]
87
+
88
+ export function addExperience(dir: string, opts: {
89
+ text: string
90
+ scene?: string
91
+ /** 数组,或逗号分隔的字符串(, , 、);去空白、去重 */
92
+ feeling?: string[] | string
93
+ thought?: string
94
+ unfinished?: string
95
+ quote?: Quote | null
96
+ weight?: Weight
97
+ kind?: string
98
+ state?: Record<string, unknown> | null
99
+ source?: string
100
+ /** 出处:数组,或逗号分隔的字符串;引用不存在的经历会抛错,整条不写 */
101
+ refs?: string[] | string
102
+ }): Experience
103
+
104
+ export function reviseExperience(dir: string, opts: { id: string; thought: string; reason?: string; feeling?: string[] | string }): {
105
+ ok: boolean
106
+ id?: string
107
+ at?: string
108
+ feeling?: string[]
109
+ error?: string
110
+ }
111
+
112
+ export function markRecalled(dir: string, id: string): boolean
113
+
114
+ export function currentView(dir: string, id: string, opts?: { asOf?: AsOf }): Experience | null
115
+
116
+ export function recall(dir: string, query: string, opts?: {
117
+ limit?: number
118
+ minOverlap?: number
119
+ mark?: boolean
120
+ minRatio?: number
121
+ mode?: 'strict' | 'loose'
122
+ /** 在那天的自己里找;不能和 mark 一起用 */
123
+ asOf?: AsOf
124
+ /** 默认不召回她封存了的经历;只在"她自己要翻"时打开 */
125
+ includeSealed?: boolean
126
+ /** strict 用哪套门槛:cover(默认,0.17 起)或 legacy(0.16 及以前,结果逐条一致) */
127
+ gate?: 'cover' | 'legacy'
128
+ }): Experience[]
129
+
130
+ /** 事后联想:两条都必须存在、必须写理由;同一对(不分方向)只连一次 */
131
+ export function linkExperiences(dir: string, opts: { from: string; to: string; reason: string }): {
132
+ ok: boolean
133
+ from?: string
134
+ to?: string
135
+ noop?: boolean
136
+ at?: string
137
+ error?: string
138
+ }
139
+
140
+ /** 封存 / 解封:不删除任何东西;重复同一个动作是 noop */
141
+ export function setSealed(dir: string, opts: { id: string; sealed?: boolean; note?: string }): {
142
+ ok: boolean
143
+ id?: string
144
+ sealed?: boolean
145
+ at?: string
146
+ noop?: boolean
147
+ error?: string
148
+ }
149
+
150
+ /** lang:'zh'(默认)或 'en',只换标签,她写下的内容原样 */
151
+ export function renderTwoPart(entry: Experience, opts?: { now?: Date; lang?: 'zh' | 'en' }): string
152
+
153
+ export interface PendingLegacyEvents {
154
+ /** 几条旧经历共用的旧 id */
155
+ id: string
156
+ /** 可能的归属(当前 id) */
157
+ candidates: string[]
158
+ later: number
159
+ recalls: number
160
+ }
161
+
162
+ export function pendingLegacyEvents(dir: string): PendingLegacyEvents[]
163
+
164
+ export function setUnfinishedState(
165
+ dir: string,
166
+ opts: { id: string; choice: 'done' | 'shelved' | 'reopen'; note?: string }
167
+ ): { ok: boolean; id?: string; at?: string; choice?: string; noop?: boolean; error?: string }
168
+
169
+ export interface RecallContextItem {
170
+ id: string
171
+ day: string
172
+ text: string
173
+ thought: string
174
+ weight: Weight
175
+ raw: Experience
176
+ }
177
+
178
+ /** 宿主拿用户原话自动召回用;默认 gate 为 legacy,升级不改变自动递回的行为 */
179
+ export function recallForContext(dir: string, query: string, opts?: { max?: number; gate?: 'cover' | 'legacy' }): RecallContextItem[]
180
+
176
181
  export const internals: { WEIGHTS: Set<Weight>; FILE: string }