whale-memory-core 0.11.2 → 0.15.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/index.d.ts +15 -8
- package/index.js +17 -10
- package/lib/archive.d.ts +22 -0
- package/lib/archive.js +135 -0
- package/lib/as-of.d.ts +5 -0
- package/lib/as-of.js +32 -0
- package/lib/book.d.ts +4 -0
- package/lib/book.js +75 -0
- package/lib/chapter-events.d.ts +39 -0
- package/lib/chapter-events.js +89 -0
- package/lib/event-log.d.ts +10 -0
- package/lib/event-log.js +61 -0
- package/lib/evidence-from-experience.d.ts +8 -6
- package/lib/evidence-from-experience.js +62 -40
- package/lib/later-events.d.ts +21 -18
- package/lib/later-events.js +80 -75
- package/lib/link-events.d.ts +15 -0
- package/lib/link-events.js +33 -0
- package/lib/recall-events.d.ts +24 -23
- package/lib/recall-events.js +97 -94
- package/lib/recap.d.ts +23 -0
- package/lib/recap.js +79 -0
- package/lib/seal-events.d.ts +25 -0
- package/lib/seal-events.js +82 -0
- package/lib/self-experience.d.ts +175 -118
- package/lib/self-experience.js +560 -390
- package/lib/self-memory.js +68 -67
- package/lib/unfinished-events.d.ts +26 -25
- package/lib/unfinished-events.js +105 -102
- package/lib/unsaid.d.ts +28 -0
- package/lib/unsaid.js +105 -0
- package/lib/waking.js +92 -91
- package/package.json +113 -85
package/lib/recap.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// 回顾材料:把这几天发生过的整理出来,给她写回想用
|
|
2
|
+
// 只列事实——写下了什么、改过什么想法、感觉怎么变的、哪些事想通或放下了、哪些还没弄完
|
|
3
|
+
// 不调模型、不下结论、不替她归纳;她封存了的不列。要不要写回想、从哪几件事想到的,由她定
|
|
4
|
+
import { loadAll } from './self-experience.js'
|
|
5
|
+
import { parseAsOf, dayOf } from './as-of.js'
|
|
6
|
+
|
|
7
|
+
const snippet = (s, n = 40) => { const c = [...String(s || '')]; return c.length > n ? c.slice(0, n).join('') + '…' : c.join('') }
|
|
8
|
+
|
|
9
|
+
// days:往回看几天(1–366);asOf:以那一刻为"今天"往回看(只看那时的她)
|
|
10
|
+
export function recap(dir, { days = 7, asOf = null, now = new Date() } = {}) {
|
|
11
|
+
if (!Number.isInteger(days) || days < 1 || days > 366) throw new Error('days 要是 1 到 366 之间的整数。')
|
|
12
|
+
const cut = parseAsOf(asOf)
|
|
13
|
+
const end = cut === null ? now.getTime() : cut
|
|
14
|
+
// 按自然日:含"今天"在内往回 days 天,从那天本地零点算起
|
|
15
|
+
const e = new Date(end)
|
|
16
|
+
const start = new Date(e.getFullYear(), e.getMonth(), e.getDate() - (days - 1)).getTime() - 1
|
|
17
|
+
const within = (at) => { const t = Date.parse(String(at || '')); return Number.isFinite(t) && t > start && t <= end }
|
|
18
|
+
const rows = loadAll(dir, { asOf: cut === null ? null : asOf }).filter((r) => !r.sealed)
|
|
19
|
+
const head = (r) => ({ id: r.id, day: r.day, text: snippet(r.then.text) })
|
|
20
|
+
|
|
21
|
+
const written = rows.filter((r) => within(r.at)).map((r) => ({ ...head(r), kind: r.kind, feeling: r.then.feeling || [], refs: r.then.refs || [] }))
|
|
22
|
+
const revised = []
|
|
23
|
+
const feelingShifts = []
|
|
24
|
+
for (const r of rows) {
|
|
25
|
+
const inRange = (r.later || []).filter((l) => within(l.at))
|
|
26
|
+
for (const l of inRange) revised.push({ ...head(r), thought: String(l.thought || ''), feeling: l.feeling || [], at: l.at, laterDay: l.day || String(l.at || '').slice(0, 10) })
|
|
27
|
+
const felt = [...inRange].reverse().find((l) => Array.isArray(l.feeling) && l.feeling.length)
|
|
28
|
+
if (felt) feelingShifts.push({ ...head(r), then: r.then.feeling || [], now: felt.feeling, laterDay: felt.day || String(felt.at || '').slice(0, 10) })
|
|
29
|
+
}
|
|
30
|
+
const settled = []
|
|
31
|
+
const reopened = []
|
|
32
|
+
for (const r of rows) {
|
|
33
|
+
const st = r.unfinishedState
|
|
34
|
+
if (!st || !within(st.at)) continue
|
|
35
|
+
const item = { ...head(r), unfinished: r.then.unfinished, choice: st.choice, stateDay: st.day }
|
|
36
|
+
if (st.choice === 'reopen') reopened.push(item)
|
|
37
|
+
else settled.push(item)
|
|
38
|
+
}
|
|
39
|
+
const stillOpen = rows
|
|
40
|
+
.filter((r) => r.then.unfinished && !(r.unfinishedState && (r.unfinishedState.choice === 'done' || r.unfinishedState.choice === 'shelved')))
|
|
41
|
+
.slice(-5)
|
|
42
|
+
.map((r) => ({ ...head(r), unfinished: r.then.unfinished }))
|
|
43
|
+
|
|
44
|
+
return { from: dayOf(start + 1), to: dayOf(end), days, written, revised, feelingShifts, settled, reopened, stillOpen }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const at = (x) => (x.day || '') + '「' + x.text + '」(' + x.id + ')'
|
|
48
|
+
|
|
49
|
+
export function renderRecap(rc) {
|
|
50
|
+
const lines = ['【这几天(' + rc.from + ' ~ ' + rc.to + ')】']
|
|
51
|
+
const empty = !rc.written.length && !rc.revised.length && !rc.settled.length && !rc.reopened.length
|
|
52
|
+
if (empty) lines.push('这几天没有新写下的,也没有改过想法。')
|
|
53
|
+
if (rc.written.length) {
|
|
54
|
+
lines.push('写下了 ' + rc.written.length + ' 件:')
|
|
55
|
+
for (const x of rc.written) lines.push('- ' + at(x) + (x.feeling.length ? ' 当时的感觉:' + x.feeling.join('、') : '') + (x.kind === '回想' ? '(这是一条回想)' : ''))
|
|
56
|
+
}
|
|
57
|
+
if (rc.revised.length) {
|
|
58
|
+
lines.push('回头想过的:')
|
|
59
|
+
for (const x of rc.revised) lines.push('- ' + at(x) + ' → ' + x.laterDay + ' 写了「' + snippet(x.thought, 60) + '」')
|
|
60
|
+
}
|
|
61
|
+
if (rc.feelingShifts.length) {
|
|
62
|
+
lines.push('感觉变了的:')
|
|
63
|
+
for (const x of rc.feelingShifts) lines.push('- ' + at(x) + ':当时 ' + (x.then.length ? x.then.join('、') : '没写') + ' → ' + x.laterDay + ' ' + x.now.join('、'))
|
|
64
|
+
}
|
|
65
|
+
if (rc.settled.length) {
|
|
66
|
+
lines.push('有了决定的:')
|
|
67
|
+
for (const x of rc.settled) lines.push('- 「' + x.unfinished + '」' + (x.choice === 'done' ? '想通了' : '先放下了') + '(' + x.stateDay + ',' + x.id + ')')
|
|
68
|
+
}
|
|
69
|
+
if (rc.reopened.length) {
|
|
70
|
+
lines.push('又拾起来的:')
|
|
71
|
+
for (const x of rc.reopened) lines.push('- 「' + x.unfinished + '」(' + x.stateDay + ',' + x.id + ')')
|
|
72
|
+
}
|
|
73
|
+
if (rc.stillOpen.length) {
|
|
74
|
+
lines.push('还没弄完的:')
|
|
75
|
+
for (const x of rc.stillOpen) lines.push('- 「' + x.unfinished + '」(' + x.id + ')')
|
|
76
|
+
}
|
|
77
|
+
lines.push('(这些是记录,不是结论。想写一条回想,就用 write --kind 回想 --refs 带上你想到的那几条 id;不想写也可以。)')
|
|
78
|
+
return lines.join('\n')
|
|
79
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type SealAction = 'seal' | 'unseal'
|
|
2
|
+
|
|
3
|
+
export const ACTIONS: Set<SealAction>
|
|
4
|
+
|
|
5
|
+
export interface SealEvent {
|
|
6
|
+
id: string
|
|
7
|
+
at: string
|
|
8
|
+
day: string
|
|
9
|
+
action: SealAction
|
|
10
|
+
note: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface SealedInfo {
|
|
14
|
+
at: string
|
|
15
|
+
day: string
|
|
16
|
+
note: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function eventsFile(memDir: string): string
|
|
20
|
+
/** 同一把锁里重读 → 判断 → 追加;已是这个状态就 noop,不写第二条 */
|
|
21
|
+
export function decide(memDir: string, opts: { id: string; action: SealAction; note?: string }, lockOpts?: Record<string, unknown>): { row: SealEvent | null; noop: boolean }
|
|
22
|
+
export function readAll(memDir: string): { rows: SealEvent[]; bad: number }
|
|
23
|
+
/** 现在(或截至 until)仍封存着的经历 */
|
|
24
|
+
export function sealedByExp(memDir: string, opts?: { until?: number | null }): Map<string, SealedInfo>
|
|
25
|
+
export const internals: { FILE: string }
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// 她选择的遗忘:封存 / 解封。一行一个 { id, at, day, action, note? },只追加
|
|
2
|
+
// 封存不是删除:原文、后记、选择都还在;只是不再被主动想起(召回、醒来、别的回想里的摘要都避开它)
|
|
3
|
+
// 要真的抹掉,仍然只有 purge 整库删除
|
|
4
|
+
import fs from 'node:fs'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import { withFileLock } from './file-lock.js'
|
|
7
|
+
import { before } from './as-of.js'
|
|
8
|
+
|
|
9
|
+
const FILE = 'seal-events.jsonl'
|
|
10
|
+
export const ACTIONS = new Set(['seal', 'unseal'])
|
|
11
|
+
|
|
12
|
+
export function eventsFile(memDir) {
|
|
13
|
+
return path.join(memDir, FILE)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function makeRow({ id, action, note }) {
|
|
17
|
+
const now = new Date()
|
|
18
|
+
return { id: String(id), at: now.toISOString(), day: now.toLocaleDateString('sv-SE'), action, note: String(note || '').slice(0, 200) }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 调用前必须已经持有锁
|
|
22
|
+
function appendUnlocked(memDir, row) {
|
|
23
|
+
const file = eventsFile(memDir)
|
|
24
|
+
let prefix = ''
|
|
25
|
+
try {
|
|
26
|
+
const st = fs.statSync(file)
|
|
27
|
+
if (st.size) {
|
|
28
|
+
const fd = fs.openSync(file, 'r')
|
|
29
|
+
const buf = Buffer.alloc(1)
|
|
30
|
+
fs.readSync(fd, buf, 0, 1, st.size - 1)
|
|
31
|
+
fs.closeSync(fd)
|
|
32
|
+
if (buf[0] !== 10) prefix = '\n'
|
|
33
|
+
}
|
|
34
|
+
} catch { }
|
|
35
|
+
fs.appendFileSync(file, prefix + JSON.stringify(row) + '\n', 'utf8')
|
|
36
|
+
return row
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 同一把锁里「重读当前状态 → 判断 → 追加」:已经封存的再封存、没封存的解封,都是空操作,不写第二条
|
|
40
|
+
export function decide(memDir, { id, action, note = '' } = {}, opts = {}) {
|
|
41
|
+
if (!String(id || '').trim()) throw new Error('id 不能为空')
|
|
42
|
+
if (!ACTIONS.has(action)) throw new Error('action 只能是 seal / unseal')
|
|
43
|
+
fs.mkdirSync(memDir, { recursive: true })
|
|
44
|
+
return withFileLock(eventsFile(memDir) + '.lock', () => {
|
|
45
|
+
const rows = readAll(memDir).rows.filter((r) => r.id === String(id))
|
|
46
|
+
const last = rows[rows.length - 1] || null
|
|
47
|
+
const sealedNow = Boolean(last && last.action === 'seal')
|
|
48
|
+
if ((action === 'seal' && sealedNow) || (action === 'unseal' && !sealedNow)) return { row: last, noop: true }
|
|
49
|
+
return { row: appendUnlocked(memDir, makeRow({ id, action, note })), noop: false }
|
|
50
|
+
}, opts)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function readAll(memDir) {
|
|
54
|
+
let raw = ''
|
|
55
|
+
try { raw = fs.readFileSync(eventsFile(memDir), 'utf8') } catch { return { rows: [], bad: 0 } }
|
|
56
|
+
const rows = []
|
|
57
|
+
let bad = 0
|
|
58
|
+
for (const line of raw.split('\n')) {
|
|
59
|
+
if (!line.trim()) continue
|
|
60
|
+
try {
|
|
61
|
+
const r = JSON.parse(line)
|
|
62
|
+
if (r && r.id && ACTIONS.has(r.action)) rows.push(r)
|
|
63
|
+
else bad += 1
|
|
64
|
+
} catch { bad += 1 }
|
|
65
|
+
}
|
|
66
|
+
return { rows, bad }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 每个经历 id 现在是否封存着:只收最后一次是 seal 的;until 用于翻回那天(那时还没封存就不算)
|
|
70
|
+
export function sealedByExp(memDir, { until = null } = {}) {
|
|
71
|
+
const { rows } = readAll(memDir)
|
|
72
|
+
const last = new Map()
|
|
73
|
+
for (const r of rows) {
|
|
74
|
+
if (!before(r, until)) continue
|
|
75
|
+
last.set(r.id, r)
|
|
76
|
+
}
|
|
77
|
+
const map = new Map()
|
|
78
|
+
for (const [id, r] of last) if (r.action === 'seal') map.set(id, { at: r.at, day: r.day, note: r.note || '' })
|
|
79
|
+
return map
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const internals = { FILE }
|
package/lib/self-experience.d.ts
CHANGED
|
@@ -1,119 +1,176 @@
|
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
export function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
|
|
119
176
|
export const internals: { WEIGHTS: Set<Weight>; FILE: string }
|