dsh-macro-memory 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +457 -2
- package/cordis.patch.yml +6 -0
- package/lib/client.js +3623 -0
- package/lib/index.js +469 -0
- package/lib/macro/brand.js +82 -0
- package/lib/macro/bridge.js +158 -0
- package/lib/macro/chain.js +206 -0
- package/lib/macro/contract.js +471 -0
- package/lib/macro/cost.js +164 -0
- package/lib/macro/defs/admin.js +439 -0
- package/lib/macro/defs/dream.js +24 -0
- package/lib/macro/defs/link.js +257 -0
- package/lib/macro/defs/project.js +25 -0
- package/lib/macro/defs/read.js +145 -0
- package/lib/macro/defs/remember.js +213 -0
- package/lib/macro/defs/search.js +661 -0
- package/lib/macro/defs/update.js +161 -0
- package/lib/macro/dreamledger.js +1398 -0
- package/lib/macro/facade.js +135 -0
- package/lib/macro/fusion.js +182 -0
- package/lib/macro/linkflow.js +391 -0
- package/lib/macro/links.js +448 -0
- package/lib/macro/neighbor.js +209 -0
- package/lib/macro/panel.js +96 -0
- package/lib/macro/prompt.js +139 -0
- package/lib/macro/provenance.js +148 -0
- package/lib/macro/render.js +35 -0
- package/lib/macro/revisions.js +253 -0
- package/lib/macro/shared.js +113 -0
- package/lib/macro/store.js +103 -0
- package/lib/macro/tokencost.js +90 -0
- package/lib/macro/tools.js +67 -0
- package/package.json +54 -4
- package/vendor/VENDOR.json +23 -0
- package/vendor/dsh-memory-nebula/CONTRIBUTING.md +48 -0
- package/vendor/dsh-memory-nebula/LICENSE +21 -0
- package/vendor/dsh-memory-nebula/README.en.md +203 -0
- package/vendor/dsh-memory-nebula/README.md +253 -0
- package/vendor/dsh-memory-nebula/SECURITY.md +43 -0
- package/vendor/dsh-memory-nebula/SUPPORT.md +33 -0
- package/vendor/dsh-memory-nebula/cordis.patch.yml +4 -0
- package/vendor/dsh-memory-nebula/lib/client.js +105 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/index.js +279 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/ingest.js +230 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/meow.js +317 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/notes.js +305 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/sqlite.js +287 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/util.js +231 -0
- package/vendor/dsh-memory-nebula/lib/host/bridge.js +351 -0
- package/vendor/dsh-memory-nebula/lib/host/compress.js +97 -0
- package/vendor/dsh-memory-nebula/lib/host/demo.js +357 -0
- package/vendor/dsh-memory-nebula/lib/host/diagnostics.js +125 -0
- package/vendor/dsh-memory-nebula/lib/host/doctor.js +270 -0
- package/vendor/dsh-memory-nebula/lib/host/graph.js +1663 -0
- package/vendor/dsh-memory-nebula/lib/host/graphcache.js +282 -0
- package/vendor/dsh-memory-nebula/lib/host/http.js +993 -0
- package/vendor/dsh-memory-nebula/lib/host/injectcfg.js +95 -0
- package/vendor/dsh-memory-nebula/lib/host/ledger.js +175 -0
- package/vendor/dsh-memory-nebula/lib/host/live.js +204 -0
- package/vendor/dsh-memory-nebula/lib/host/nebula.js +2105 -0
- package/vendor/dsh-memory-nebula/lib/host/page.js +75 -0
- package/vendor/dsh-memory-nebula/lib/host/path.js +83 -0
- package/vendor/dsh-memory-nebula/lib/host/recall.js +451 -0
- package/vendor/dsh-memory-nebula/lib/host/share.js +633 -0
- package/vendor/dsh-memory-nebula/lib/host/sources.js +266 -0
- package/vendor/dsh-memory-nebula/lib/host/store.js +333 -0
- package/vendor/dsh-memory-nebula/lib/host/text.js +410 -0
- package/vendor/dsh-memory-nebula/lib/host/transcripts.js +396 -0
- package/vendor/dsh-memory-nebula/lib/index.js +759 -0
- package/vendor/dsh-memory-nebula/lib/standalone.mjs +315 -0
- package/vendor/dsh-memory-nebula/lib/web/api.js +426 -0
- package/vendor/dsh-memory-nebula/lib/web/app.js +4159 -0
- package/vendor/dsh-memory-nebula/lib/web/i18n.js +580 -0
- package/vendor/dsh-memory-nebula/lib/web/index.html +174 -0
- package/vendor/dsh-memory-nebula/lib/web/nav.js +132 -0
- package/vendor/dsh-memory-nebula/lib/web/render.js +1890 -0
- package/vendor/dsh-memory-nebula/lib/web/space3d.js +1883 -0
- package/vendor/dsh-memory-nebula/lib/web/style.css +1402 -0
- package/vendor/dsh-memory-nebula/locale/en.json +7 -0
- package/vendor/dsh-memory-nebula/locale/zh.json +7 -0
- package/vendor/dsh-memory-nebula/market/assets/icon-180.png +0 -0
- package/vendor/dsh-memory-nebula/market/assets/icon.svg +40 -0
- package/vendor/dsh-memory-nebula/market/index.json +101 -0
- package/vendor/dsh-memory-nebula/package.json +87 -0
- package/vendor/dsh-memory-nebula/sidecar.ps1 +119 -0
- package/vendor/meow-memory/LICENSE +21 -0
- package/vendor/meow-memory/README.en.md +192 -0
- package/vendor/meow-memory/README.md +174 -0
- package/vendor/meow-memory/README.pt-br.md +180 -0
- package/vendor/meow-memory/cordis.patch.yml +7 -0
- package/vendor/meow-memory/lib/client.js +3344 -0
- package/vendor/meow-memory/lib/client.js.map +7 -0
- package/vendor/meow-memory/lib/index.js +9567 -0
- package/vendor/meow-memory/lib/index.js.map +7 -0
- package/vendor/meow-memory/lib/prompts/README.md +65 -0
- package/vendor/meow-memory/lib/prompts/en/dream-atomic.md +36 -0
- package/vendor/meow-memory/lib/prompts/en/dream-header.md +9 -0
- package/vendor/meow-memory/lib/prompts/en/dream-project-summary.md +12 -0
- package/vendor/meow-memory/lib/prompts/en/dream-topic.md +27 -0
- package/vendor/meow-memory/lib/prompts/en/external-memory-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/en/first-create-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/en/labels.md +98 -0
- package/vendor/meow-memory/lib/prompts/en/reflect.md +31 -0
- package/vendor/meow-memory/lib/prompts/en/system-guide.md +121 -0
- package/vendor/meow-memory/lib/prompts/en/tools.md +83 -0
- package/vendor/meow-memory/lib/prompts/en/welcome-guide.md +12 -0
- package/vendor/meow-memory/lib/prompts/pt-br/dream-atomic.md +36 -0
- package/vendor/meow-memory/lib/prompts/pt-br/dream-header.md +9 -0
- package/vendor/meow-memory/lib/prompts/pt-br/dream-project-summary.md +12 -0
- package/vendor/meow-memory/lib/prompts/pt-br/dream-topic.md +27 -0
- package/vendor/meow-memory/lib/prompts/pt-br/external-memory-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/pt-br/first-create-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/pt-br/labels.md +98 -0
- package/vendor/meow-memory/lib/prompts/pt-br/reflect.md +31 -0
- package/vendor/meow-memory/lib/prompts/pt-br/system-guide.md +121 -0
- package/vendor/meow-memory/lib/prompts/pt-br/tools.md +83 -0
- package/vendor/meow-memory/lib/prompts/pt-br/welcome-guide.md +12 -0
- package/vendor/meow-memory/lib/prompts/zh/dream-atomic.md +36 -0
- package/vendor/meow-memory/lib/prompts/zh/dream-header.md +9 -0
- package/vendor/meow-memory/lib/prompts/zh/dream-project-summary.md +19 -0
- package/vendor/meow-memory/lib/prompts/zh/dream-topic.md +27 -0
- package/vendor/meow-memory/lib/prompts/zh/external-memory-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/zh/first-create-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/zh/labels.md +98 -0
- package/vendor/meow-memory/lib/prompts/zh/reflect.md +30 -0
- package/vendor/meow-memory/lib/prompts/zh/system-guide.md +119 -0
- package/vendor/meow-memory/lib/prompts/zh/tools.md +83 -0
- package/vendor/meow-memory/lib/prompts/zh/welcome-guide.md +12 -0
- package/vendor/meow-memory/package.json +64 -0
|
@@ -0,0 +1,1398 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 整理留痕面板(0.2.97):`memory_admin(action="dream")` 的正文从这里出。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要有这个面板:dream 在 0.2.96 起会把自己这一轮看到什么、点出几对、缺几个词
|
|
5
|
+
* 写进 `dream_log`(summary 一行 + `changes.plan` 一份结构),但**只有写、没有读**——
|
|
6
|
+
* 账本躺在 sqlite 里,主人在面板上看不到。一个只有写口没有读口的账本,
|
|
7
|
+
* 等于把「可追溯」做成了「看我写过」。
|
|
8
|
+
*
|
|
9
|
+
* 三条规矩:
|
|
10
|
+
* 1. 面板只念账本,不自己算:数字全部来自 `changes.plan`(0.2.96 起才有),
|
|
11
|
+
* 老记录没有 plan 就明说「这条记的时候还没有规模」,不许拿现在的清单反推。
|
|
12
|
+
* 2. 「没有账本」和「读不出来」必须分开说:前者是这窗口还没跑过 dream,
|
|
13
|
+
* 后者是库在但坏了——把后者说成前者,是最难查的那种谎。
|
|
14
|
+
* 3. 抬头(面板名 + 条数)由 panel.js 统一加,这里只给正文与口径说明。
|
|
15
|
+
*/
|
|
16
|
+
import * as Meow from '../../vendor/meow-memory/lib/index.js'
|
|
17
|
+
|
|
18
|
+
/** 会话工作区:和 meow 的 workspaceOf() 同一条取法(exec.agent.session.header.cwd)。 */
|
|
19
|
+
export function workspaceOfExec(exec) {
|
|
20
|
+
const cwd = exec?.agent?.session?.header?.cwd
|
|
21
|
+
return typeof cwd === 'string' && cwd.length > 0 ? cwd : ''
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 时间戳 → 「MM-DD HH:mm」(面板只给到分钟:秒在这里没有信息量)。 */
|
|
25
|
+
function stamp(at) {
|
|
26
|
+
const t = Number(at)
|
|
27
|
+
if (!Number.isFinite(t) || t <= 0) return '时间不明'
|
|
28
|
+
const d = new Date(t)
|
|
29
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
30
|
+
return `${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* [macro-fusion 0.2.105] 「2026-11-18」→ 那一天**本机** 00:00 的毫秒。
|
|
35
|
+
*
|
|
36
|
+
* 坑:绝对不能用 `Date.parse('2026-11-18')`——那是按 UTC 解释的,东八区会整体错开 8 小时,
|
|
37
|
+
* 于是「18 号那天的账」会把 17 号 16:00 之后的一起捞进来、把 18 号 16:00 之后的漏掉。
|
|
38
|
+
* 这里用 `new Date(y, m-1, d)` 让运行时按本机时区算,再用年月日回读校验(2026-02-31 这种要打回)。
|
|
39
|
+
*/
|
|
40
|
+
function dayStartOf(raw) {
|
|
41
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(raw ?? '').trim())
|
|
42
|
+
if (m === null) return null
|
|
43
|
+
const y = Number(m[1])
|
|
44
|
+
const mo = Number(m[2])
|
|
45
|
+
const d = Number(m[3])
|
|
46
|
+
const t = new Date(y, mo - 1, d, 0, 0, 0, 0)
|
|
47
|
+
if (t.getFullYear() !== y || t.getMonth() !== mo - 1 || t.getDate() !== d) return null
|
|
48
|
+
return t.getTime()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 那一天本机 23:59:59.999(闭区间:until 这天写的账也算在「这段时间」里)。 */
|
|
52
|
+
function dayEndOf(raw) {
|
|
53
|
+
const s = dayStartOf(raw)
|
|
54
|
+
return s === null ? null : s + 86400000 - 1
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 本机时区标签(`UTC+08:00`):按日期筛账必须先交代时区,否则「18 号」是哪个 18 号都说不清。 */
|
|
58
|
+
function tzLabel() {
|
|
59
|
+
const off = -new Date().getTimezoneOffset()
|
|
60
|
+
const abs = Math.abs(off)
|
|
61
|
+
const sign = off >= 0 ? '+' : '-'
|
|
62
|
+
return `UTC${sign}${String(Math.floor(abs / 60)).padStart(2, '0')}:${String(abs % 60).padStart(2, '0')}`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* [macro-fusion 0.2.105] since / until 两个可选日期 → 一个闭区间。
|
|
67
|
+
* 三态:都不给 → 不筛(since=until=0);给了 → 解成毫秒;写坏了 → 打回并说清怎么写。
|
|
68
|
+
* 打回是刻意的:2026-13-40 这种在手边猜一个日期,读出来的结论比不筛更糟。
|
|
69
|
+
*/
|
|
70
|
+
function rangeOf(sinceRaw, untilRaw) {
|
|
71
|
+
const sinceText = String(sinceRaw ?? '').trim()
|
|
72
|
+
const untilText = String(untilRaw ?? '').trim()
|
|
73
|
+
if (sinceText === '' && untilText === '') return { since: 0, until: 0, label: '', bad: '' }
|
|
74
|
+
const since = sinceText === '' ? 0 : dayStartOf(sinceText)
|
|
75
|
+
const until = untilText === '' ? 0 : dayEndOf(untilText)
|
|
76
|
+
if (sinceText !== '' && since === null) {
|
|
77
|
+
return { since: 0, until: 0, label: '', bad: `since 要写成「2026-11-18」这种日期(按本机时区 ${tzLabel()} 算一整天)——给的是「${sinceText}」,这种写法不敢猜。` }
|
|
78
|
+
}
|
|
79
|
+
if (untilText !== '' && until === null) {
|
|
80
|
+
return { since: 0, until: 0, label: '', bad: `until 要写成「2026-11-18」这种日期(按本机时区 ${tzLabel()} 算一整天)——给的是「${untilText}」,这种写法不敢猜。` }
|
|
81
|
+
}
|
|
82
|
+
if (since > 0 && until > 0 && since > until) {
|
|
83
|
+
return { since: 0, until: 0, label: '', bad: `since「${sinceText}」比 until「${untilText}」还晚——这样筛不出任何一条。两个日期换一下再来。` }
|
|
84
|
+
}
|
|
85
|
+
return { since: since || 0, until: until || 0, label: `${sinceText || '账本最早'} → ${untilText || '现在'}`, bad: '' }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* [macro-fusion 0.2.105] 展开一条时,这条到底在不在你筛的那段时间里。
|
|
90
|
+
* 只说位置,不改结论:编号与引用都按全账本算(和项目筛同一条分寸),
|
|
91
|
+
* 但「我筛 19 号,怎么翻出 15 号的账」这种困惑必须有句话对上。
|
|
92
|
+
*/
|
|
93
|
+
function rangeNoteOf(row, range) {
|
|
94
|
+
if (!(range.since > 0 || range.until > 0)) return ''
|
|
95
|
+
const at = Number(row?.runAt) || 0
|
|
96
|
+
const inside = at > 0 && (range.since === 0 || at >= range.since) && (range.until === 0 || at <= range.until)
|
|
97
|
+
if (inside) return `这一条写在 ${range.label} 这段时间里,正是你筛的那几天。`
|
|
98
|
+
return `这一条不在 ${range.label} 这段时间里(它写在 ${stamp(at)})——展开照账念,只是别把它当成那段时间的账。`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** `window dream done: …` / `window dream aborted: …` / `window dream recovered (interrupted): …`
|
|
102
|
+
* → `done` / `aborted` / `recovered` / `''`。 [macro-fusion 0.2.107] 括号里的修饰语要跳过去,
|
|
103
|
+
* 否则 summary 是 `recovered (interrupted)` 的账会被认成「原因未记」。 */
|
|
104
|
+
function reasonOf(summary) {
|
|
105
|
+
const m = String(summary ?? '').match(/^window dream ([a-z]+)[^:]*:/)
|
|
106
|
+
return m === null ? '' : m[1]
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* [macro-fusion 0.2.107] 收尾方式的名字。原来只有三个(完成 / 中途放弃 / 补记),
|
|
111
|
+
* 现在多两种「没跑完就封存」的账:连续失败被止损封存(sealed)、连续没进展被封存(gaveup)。
|
|
112
|
+
* 这两种以前压根不落账,只在 dream-debug.log 里留一句,面板上等于没发生过。
|
|
113
|
+
*/
|
|
114
|
+
const KIND_TEXT = {
|
|
115
|
+
done: '整理完成',
|
|
116
|
+
aborted: '中途放弃',
|
|
117
|
+
recovered: '上次被打断,这次补记',
|
|
118
|
+
sealed: '连续失败已封存',
|
|
119
|
+
gaveup: '连续没进展已封存',
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* [macro-fusion 0.2.107] 这一轮是怎么收的场。
|
|
124
|
+
*
|
|
125
|
+
* `changes.kind = { kind, groupsDone?, groupsTotal?, fails? }` 是 0.2.107 起才有的结构化字段;
|
|
126
|
+
* 更早的账只能从 summary 首词认出 done / aborted / recovered,组数与失败次数都没有。
|
|
127
|
+
* 所以这里必须分清两件事:`stored` 说的是「账本里真记了这一格」还是「从一句话里认出来的」,
|
|
128
|
+
* 而组数在下标为 null 时是「没记」,不是 0——不许拿 0 顶上,否则「走了 0 组」会变成一句假话。
|
|
129
|
+
*/
|
|
130
|
+
function kindOf(row) {
|
|
131
|
+
const raw = row?.changes?.kind
|
|
132
|
+
const numOf = (v) => {
|
|
133
|
+
const n = Number(v)
|
|
134
|
+
return Number.isFinite(n) && n >= 0 ? n : null
|
|
135
|
+
}
|
|
136
|
+
if (raw !== undefined && raw !== null && typeof raw === 'object' && typeof raw.kind === 'string' && raw.kind !== '') {
|
|
137
|
+
return {
|
|
138
|
+
kind: raw.kind,
|
|
139
|
+
groupsDone: numOf(raw.groupsDone),
|
|
140
|
+
groupsTotal: numOf(raw.groupsTotal),
|
|
141
|
+
fails: numOf(raw.fails),
|
|
142
|
+
stored: true,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const legacy = reasonOf(row?.summary)
|
|
146
|
+
return { kind: legacy, groupsDone: null, groupsTotal: null, fails: null, stored: false }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* [macro-fusion 0.2.107] 只有跑完的一轮(done)才配进趋势合计、才配跟别的轮比数字。
|
|
151
|
+
* 中途放弃的那轮 dup/cover/missing 只是「扫到这里为止」的中间值,拿它跟跑完的轮加起来,
|
|
152
|
+
* 等于把半张成绩单当满分算。没有 kind 这一格的老账只要带 plan 就当跑完——那时候还没有中途放弃的账。
|
|
153
|
+
*/
|
|
154
|
+
function isFullRound(row) {
|
|
155
|
+
const k = kindOf(row)
|
|
156
|
+
if (k.stored) return k.kind === 'done'
|
|
157
|
+
if (k.kind === 'aborted') return false
|
|
158
|
+
return k.kind === '' || k.kind === 'done'
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** [macro-fusion 0.2.107] 一句话说清这一轮走到哪儿;没有 kind 的老账返回空串(由调用方照旧解释)。 */
|
|
162
|
+
function kindTail(k) {
|
|
163
|
+
if (k.kind === 'aborted') {
|
|
164
|
+
if (k.groupsDone === null) return '半路停下,这一条没记走到第几组'
|
|
165
|
+
if (k.groupsTotal !== null && k.groupsTotal > 0) return `走了 ${k.groupsDone}/${k.groupsTotal} 组就停下`
|
|
166
|
+
return `走了 ${k.groupsDone} 组就停下(没记这一轮本来几组)`
|
|
167
|
+
}
|
|
168
|
+
if (k.kind === 'recovered') {
|
|
169
|
+
if (k.groupsDone === null) return '上次被打断,这次补记(当时没记走到第几组)'
|
|
170
|
+
return `上次被打断,补记时已走完 ${k.groupsDone} 组`
|
|
171
|
+
}
|
|
172
|
+
if (k.kind === 'gaveup') return k.fails === null ? '连续没进展,被封存(没记失败次数)' : `连续 ${k.fails} 次没进展,被封存`
|
|
173
|
+
if (k.kind === 'sealed') return k.fails === null ? '连续失败,被封存(没记失败次数)' : `连续失败 ${k.fails} 次,被封存`
|
|
174
|
+
return ''
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* [macro-fusion 0.2.102] `plan.projects` 有两种形态,读的时候都得认:
|
|
179
|
+
* - 0.2.96~0.2.101 写的是**个数**(数字,sum 各轮 projects 数组长度);
|
|
180
|
+
* - 0.2.102 起写的是**名字数组**(去重保序)。
|
|
181
|
+
* 以前这里只认数组,于是老账本一行行都念成「0 个项目段」——数就在账本里,被读丢了。
|
|
182
|
+
*/
|
|
183
|
+
function projectCountOf(plan) {
|
|
184
|
+
if (Array.isArray(plan?.projects)) return plan.projects.length
|
|
185
|
+
const legacy = Number(plan?.projects)
|
|
186
|
+
if (Number.isFinite(legacy) && legacy > 0) return legacy
|
|
187
|
+
const counted = Number(plan?.projectCount)
|
|
188
|
+
return Number.isFinite(counted) && counted > 0 ? counted : 0
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* [macro-fusion 0.2.103] 库规模:`plan.store = { active, byLevel }`,0.2.103 之前写的账没有这一格。
|
|
194
|
+
* 读的时候三态要分清:没有 store(老账,别念成 0 条)/有 store 但 active 不是正数(写了但没数清)/正常。
|
|
195
|
+
* 返回 null 表示「这条账没记」,调用方据此决定是闭嘴还是解释,不许自己补 0。
|
|
196
|
+
*/
|
|
197
|
+
function storeOf(plan) {
|
|
198
|
+
const store = plan?.store
|
|
199
|
+
if (store === undefined || store === null || typeof store !== 'object') return null
|
|
200
|
+
const active = Number(store.active)
|
|
201
|
+
if (!Number.isFinite(active) || active < 0) return null
|
|
202
|
+
const byLevel = {}
|
|
203
|
+
if (store.byLevel !== undefined && store.byLevel !== null && typeof store.byLevel === 'object') {
|
|
204
|
+
for (const [level, n] of Object.entries(store.byLevel)) {
|
|
205
|
+
const v = Number(n)
|
|
206
|
+
if (Number.isFinite(v) && v > 0) byLevel[level] = v
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// [macro-fusion 0.2.111] 按项目的规模:只有 0.2.111 之后的账有这一格,老账没有就是没有(不补空对象)。
|
|
210
|
+
const byProject = {}
|
|
211
|
+
if (store.byProject !== undefined && store.byProject !== null && typeof store.byProject === 'object') {
|
|
212
|
+
for (const [name, n] of Object.entries(store.byProject)) {
|
|
213
|
+
const key = String(name).trim()
|
|
214
|
+
const v = Number(n)
|
|
215
|
+
if (key !== '' && Number.isFinite(v) && v > 0) byProject[key] = v
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return { active, byLevel, byProject }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* [macro-fusion 0.2.106] 收尾规模:`plan.storeEnd = { active, byLevel }`,0.2.106 之前写的账没有这一格。
|
|
223
|
+
* 与 storeOf 同一套读法(正数才认、只留非零层),但语义不同:store 是「开工前多大」,
|
|
224
|
+
* storeEnd 是「这一轮结束后多大」。差(storeDelta)只在两个点都有数时才有,缺一个就不猜。
|
|
225
|
+
*/
|
|
226
|
+
function storeEndOf(plan) {
|
|
227
|
+
return storeOf({ store: plan?.storeEnd })
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function storeDeltaOf(plan) {
|
|
231
|
+
const start = storeOf(plan)
|
|
232
|
+
const end = storeEndOf(plan)
|
|
233
|
+
if (start === null || end === null) return null
|
|
234
|
+
return { start, end, delta: end.active - start.active }
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** [macro-fusion 0.2.106] `(fact 2 · lesson 1)`;一层都没有就给空串,别留一对空括号。 */
|
|
238
|
+
function levelsText(store) {
|
|
239
|
+
const levels = Object.entries(store.byLevel).map(([level, n]) => `${level} ${n}`)
|
|
240
|
+
return levels.length === 0 ? '' : `(${levels.join(' · ')})`
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* [macro-fusion 0.2.108] 层走向:一轮收尾那一刻,库里每一层还有多少条在用。
|
|
245
|
+
*
|
|
246
|
+
* 三条读法,缺一条就会念错:
|
|
247
|
+
* 1. 只认 `storeEnd.byLevel`:0.2.103~0.2.105 的账只记了开工层数,把开工数当收尾数排进去,
|
|
248
|
+
* 等于把「整理前的库」贴到「整理后的库」的位置上——宁可少几次样本,也不许拿开工冒充收尾。
|
|
249
|
+
* 2. 写侧零层不写进 byLevel(`dreamStoreScale` 只收正数层),所以**这一轮真写了 byLevel** 时,
|
|
250
|
+
* 缺的那一层就是「那一轮那层 0 条在用」,不是「没记」。这条前提写在口径句里,别让读者自己猜。
|
|
251
|
+
* 3. 只有跑完的轮算数(0.2.107 的规矩):半路停下那轮的 byLevel 是扫到那儿为止的中间值。
|
|
252
|
+
*/
|
|
253
|
+
function levelSeriesOf(plan) {
|
|
254
|
+
const raw = plan?.storeEnd
|
|
255
|
+
if (raw === undefined || raw === null || typeof raw !== 'object') return null
|
|
256
|
+
if (raw.byLevel === undefined || raw.byLevel === null || typeof raw.byLevel !== 'object') return null
|
|
257
|
+
const store = storeOf({ store: raw })
|
|
258
|
+
return store === null ? null : store.byLevel
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* [macro-fusion 0.2.111] 项目走向:一轮收尾那一刻,库里每个项目还有多少条在用。
|
|
263
|
+
*
|
|
264
|
+
* 与层走向同一套读法(只认 storeEnd、只吃跑完的轮),但有一件层走向没有的坑:
|
|
265
|
+
* 项目名是**写入时原样存的字符串**,改名就会变成两行(旧名那条一路掉、新名那条冒出来)。
|
|
266
|
+
* 所以口径句必须写「项目名按原样,改过名就算两行」——否则读者会把改名读成「有人在删东西」。
|
|
267
|
+
*/
|
|
268
|
+
function projectSeriesOf(plan) {
|
|
269
|
+
const raw = plan?.storeEnd
|
|
270
|
+
if (raw === undefined || raw === null || typeof raw !== 'object') return null
|
|
271
|
+
if (raw.byProject === undefined || raw.byProject === null || typeof raw.byProject !== 'object') return null
|
|
272
|
+
const store = storeOf({ store: raw })
|
|
273
|
+
return store === null ? null : store.byProject
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* [macro-fusion 0.2.113] 序列太长就别整条摆出来:两头的数才是读者要的结论,
|
|
278
|
+
* 中间那几次只在「涨到第几轮才涨」这种问题上才有用——那时他去翻账本。
|
|
279
|
+
* 省略要报数(`中间 4 次省略`),不然 `…` 会被当成「这几次没数」。
|
|
280
|
+
*/
|
|
281
|
+
const SEQ_HEAD = 2
|
|
282
|
+
const SEQ_TAIL = 3
|
|
283
|
+
|
|
284
|
+
function compactSeq(seq) {
|
|
285
|
+
const list = Array.isArray(seq) ? seq : []
|
|
286
|
+
if (list.length <= SEQ_HEAD + SEQ_TAIL + 1) return { text: list.join(' → '), cut: 0 }
|
|
287
|
+
const cut = list.length - SEQ_HEAD - SEQ_TAIL
|
|
288
|
+
return { text: [...list.slice(0, SEQ_HEAD), '…', ...list.slice(-SEQ_TAIL)].join(' → '), cut }
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* [macro-fusion 0.2.111] 把最近几轮的收尾项目数摊成一条走向:
|
|
293
|
+
* `项目走向:最近 3 次收尾(最早→最新)· Alpha 3 → 4 → 6(+3)· Beta 1 → 1 → 0(-1)· 涨得最多的是 Alpha(+3)`
|
|
294
|
+
*
|
|
295
|
+
* 为什么要它:层走向只说「fact 在涨」,说不出「哪个项目在涨」——Alpha 涨 3 条、Beta 掉 3 条,
|
|
296
|
+
* 层走向念「fact 没变」,而实际上一个项目在膨胀、另一个在被清空。这条走向就是那句话的证据。
|
|
297
|
+
* 少于两轮不给(一次是快照,不是走向);只有账上真记了 byProject 的轮才算数。
|
|
298
|
+
*
|
|
299
|
+
* [macro-fusion 0.2.113] 首尾相减说不出「哪天开始有、哪天没了」:一个项目第 2 次才冒出来、
|
|
300
|
+
* 一个项目上一次还在这一轮归零,两者在净差里都只是一个数字。所以点名「新出现」与「消失」;
|
|
301
|
+
* 但改名不猜——一存一失如果条数对得上,只是把「很可能是改名」这句话摆出来,让读者去账本核对。
|
|
302
|
+
*/
|
|
303
|
+
function projectTrendLine(rows) {
|
|
304
|
+
const list = Array.isArray(rows) ? rows : []
|
|
305
|
+
const kept = []
|
|
306
|
+
let noEnd = 0
|
|
307
|
+
let half = 0
|
|
308
|
+
for (const row of list) {
|
|
309
|
+
if (!isFullRound(row)) {
|
|
310
|
+
if (projectSeriesOf(row.changes?.plan) !== null) half += 1
|
|
311
|
+
continue
|
|
312
|
+
}
|
|
313
|
+
const projects = projectSeriesOf(row.changes?.plan)
|
|
314
|
+
if (projects === null) {
|
|
315
|
+
noEnd += 1
|
|
316
|
+
continue
|
|
317
|
+
}
|
|
318
|
+
kept.push(projects)
|
|
319
|
+
}
|
|
320
|
+
if (kept.length < 2) return ''
|
|
321
|
+
kept.reverse()
|
|
322
|
+
const names = []
|
|
323
|
+
for (const ps of kept) {
|
|
324
|
+
for (const name of Object.keys(ps)) if (!names.includes(name)) names.push(name)
|
|
325
|
+
}
|
|
326
|
+
const valOf = (ps, name) => {
|
|
327
|
+
const n = Number(ps[name])
|
|
328
|
+
return Number.isFinite(n) && n >= 0 ? n : 0
|
|
329
|
+
}
|
|
330
|
+
const cells = names.map((name) => {
|
|
331
|
+
const seq = kept.map((ps) => valOf(ps, name))
|
|
332
|
+
const last = seq[seq.length - 1]
|
|
333
|
+
return { name, seq, last, delta: last - seq[0] }
|
|
334
|
+
})
|
|
335
|
+
if (cells.length === 0) return ''
|
|
336
|
+
cells.sort((a, b) => Math.abs(b.delta) - Math.abs(a.delta) || b.last - a.last)
|
|
337
|
+
let cut = 0
|
|
338
|
+
const shown = cells.slice(0, 4).map((c) => {
|
|
339
|
+
const word = c.delta > 0 ? `+${c.delta}` : c.delta < 0 ? `${c.delta}` : '没变'
|
|
340
|
+
const box = compactSeq(c.seq)
|
|
341
|
+
if (box.cut > cut) cut = box.cut
|
|
342
|
+
return `${c.name} ${box.text}(${word})`
|
|
343
|
+
})
|
|
344
|
+
const rest = cells.length - shown.length
|
|
345
|
+
const up = cells.filter((c) => c.delta > 0).sort((a, b) => b.delta - a.delta || b.last - a.last)[0]
|
|
346
|
+
const down = cells.filter((c) => c.delta < 0).sort((a, b) => a.delta - b.delta || b.last - a.last)[0]
|
|
347
|
+
const parts = [`项目走向:最近 ${kept.length} 次收尾(最早→最新)`, ...shown]
|
|
348
|
+
if (up === undefined && down === undefined) parts.push('每个项目的条数都没变')
|
|
349
|
+
else if (up !== undefined) parts.push(`涨得最多的是 ${up.name}(+${up.delta})`)
|
|
350
|
+
else parts.push(`掉得最多的是 ${down.name}(${down.delta})`)
|
|
351
|
+
// [macro-fusion 0.2.113] 首尾净差之外的两种变化:窗口里冒出来的、窗口里归零的。
|
|
352
|
+
// 只看「第一次有数 / 最后一次有数」的位置,不管中间怎么起伏(那属于序列本身)。
|
|
353
|
+
const firstLive = (seq) => seq.findIndex((n) => n > 0)
|
|
354
|
+
const lastLive = (seq) => {
|
|
355
|
+
for (let i = seq.length - 1; i >= 0; i -= 1) if (seq[i] > 0) return i
|
|
356
|
+
return -1
|
|
357
|
+
}
|
|
358
|
+
const appeared = []
|
|
359
|
+
const gone = []
|
|
360
|
+
for (const c of cells) {
|
|
361
|
+
const f = firstLive(c.seq)
|
|
362
|
+
const l = lastLive(c.seq)
|
|
363
|
+
if (f > 0) appeared.push({ name: c.name, at: f + 1, now: c.last })
|
|
364
|
+
if (l >= 0 && l < c.seq.length - 1) gone.push({ name: c.name, at: l + 1, was: c.seq[l] })
|
|
365
|
+
}
|
|
366
|
+
if (appeared.length > 0) {
|
|
367
|
+
const top = appeared.slice(0, 3).map((c) => `${c.name}(第 ${c.at} 次起有数,现在 ${c.now} 条)`)
|
|
368
|
+
parts.push(`这条走向里新出现:${top.join('、')}${appeared.length > top.length ? `,还有 ${appeared.length - top.length} 个没列` : ''}`)
|
|
369
|
+
}
|
|
370
|
+
if (gone.length > 0) {
|
|
371
|
+
const top = gone.slice(0, 3).map((c) => `${c.name}(第 ${c.at} 次是最后的数:${c.was} 条)`)
|
|
372
|
+
parts.push(`这条走向里消失:${top.join('、')}${gone.length > top.length ? `,还有 ${gone.length - top.length} 个没列` : ''}`)
|
|
373
|
+
}
|
|
374
|
+
if (appeared.length > 0 && gone.length > 0) {
|
|
375
|
+
parts.push('一存一失如果条数对得上,很可能只是改名——这条走向不替你猜,要确认就翻那一轮的账看项目段名字')
|
|
376
|
+
}
|
|
377
|
+
const caveats = []
|
|
378
|
+
if (rest > 0) caveats.push(`还有 ${rest} 个项目没列`)
|
|
379
|
+
if (cut > 0) caveats.push(`序列太长,中间 ${cut} 次用 … 省略(要逐轮就展开那一轮看账)`)
|
|
380
|
+
if (half > 0) caveats.push(`${half} 次没跑完(中途放弃 / 待补记 / 已封存),不进这条走向`)
|
|
381
|
+
if (noEnd > 0) caveats.push(`${noEnd} 次没有收尾项目数(0.2.111 之前的账没有这一格),不进这条走向`)
|
|
382
|
+
caveats.push("只数带项目归属的 5 层(soul / user 没有这一格),项目名按写入时原样——改过名的会算成两行")
|
|
383
|
+
return `${parts.join(' · ')}(${caveats.join(';')})`
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* [macro-fusion 0.2.108] 把最近几轮的收尾层数摊成一条走向:
|
|
388
|
+
* `层走向:最近 3 次收尾(最早→最新)· fact 2 → 3 → 6(+4)· topic 1 → 1 → 0(-1)· 涨得最多的是 fact(+4)`
|
|
389
|
+
*
|
|
390
|
+
* 为什么要它:总条数的净变化(0.2.106)只说「库重了多少」,说不出「哪一层在膨胀」——
|
|
391
|
+
* fact 一直涨、topic 一直掉,总分可能是 0,而库的结构其实在烂。层走向就是这句话的证据。
|
|
392
|
+
* 少于两轮不给(一次是快照,不是走向),一轮的层数也不编。
|
|
393
|
+
*/
|
|
394
|
+
function levelTrendLine(rows) {
|
|
395
|
+
const list = Array.isArray(rows) ? rows : []
|
|
396
|
+
const kept = []
|
|
397
|
+
let noEnd = 0
|
|
398
|
+
let half = 0
|
|
399
|
+
for (const row of list) {
|
|
400
|
+
if (!isFullRound(row)) {
|
|
401
|
+
// [macro-fusion 0.2.107 的规矩] 半轮的层数是扫到那儿的中间值,不进走向;但要说清排除了几次,
|
|
402
|
+
// 否则「最近 3 次收尾」和账本里带 storeEnd 的行数对不上,读者会以为漏账。
|
|
403
|
+
if (levelSeriesOf(row.changes?.plan) !== null) half += 1
|
|
404
|
+
continue
|
|
405
|
+
}
|
|
406
|
+
const levels = levelSeriesOf(row.changes?.plan)
|
|
407
|
+
if (levels === null) {
|
|
408
|
+
noEnd += 1
|
|
409
|
+
continue
|
|
410
|
+
}
|
|
411
|
+
kept.push(levels)
|
|
412
|
+
}
|
|
413
|
+
if (kept.length < 2) return ''
|
|
414
|
+
kept.reverse() // rows 是最新在前,走向要按时间念
|
|
415
|
+
const names = []
|
|
416
|
+
for (const lv of kept) {
|
|
417
|
+
for (const name of Object.keys(lv)) if (!names.includes(name)) names.push(name)
|
|
418
|
+
}
|
|
419
|
+
const valOf = (lv, name) => {
|
|
420
|
+
const n = Number(lv[name])
|
|
421
|
+
return Number.isFinite(n) && n >= 0 ? n : 0
|
|
422
|
+
}
|
|
423
|
+
const cells = names.map((name) => {
|
|
424
|
+
const seq = kept.map((lv) => valOf(lv, name))
|
|
425
|
+
const last = seq[seq.length - 1]
|
|
426
|
+
return { name, seq, last, delta: last - seq[0] }
|
|
427
|
+
})
|
|
428
|
+
if (cells.length === 0) return ''
|
|
429
|
+
// 变化大的先说;一样大就按最后一轮谁多。只列 4 层,多的说清「没列」而不是装没有。
|
|
430
|
+
cells.sort((a, b) => Math.abs(b.delta) - Math.abs(a.delta) || b.last - a.last)
|
|
431
|
+
const shown = cells.slice(0, 4).map((c) => {
|
|
432
|
+
const word = c.delta > 0 ? `+${c.delta}` : c.delta < 0 ? `${c.delta}` : '没变'
|
|
433
|
+
return `${c.name} ${c.seq.join(' → ')}(${word})`
|
|
434
|
+
})
|
|
435
|
+
const rest = cells.length - shown.length
|
|
436
|
+
const up = cells.filter((c) => c.delta > 0).sort((a, b) => b.delta - a.delta || b.last - a.last)[0]
|
|
437
|
+
const down = cells.filter((c) => c.delta < 0).sort((a, b) => a.delta - b.delta || b.last - a.last)[0]
|
|
438
|
+
const parts = [`层走向:最近 ${kept.length} 次收尾(最早→最新)`, ...shown]
|
|
439
|
+
if (up === undefined && down === undefined) parts.push('每一层的条数都没变')
|
|
440
|
+
else if (up !== undefined) parts.push(`涨得最多的是 ${up.name}(+${up.delta})`)
|
|
441
|
+
else parts.push(`掉得最多的是 ${down.name}(${down.delta})`)
|
|
442
|
+
const caveats = []
|
|
443
|
+
if (rest > 0) caveats.push(`还有 ${rest} 层没列`)
|
|
444
|
+
if (half > 0) caveats.push(`${half} 次没跑完(中途放弃 / 待补记 / 已封存),不进这条走向`)
|
|
445
|
+
if (noEnd > 0) caveats.push(`${noEnd} 次没有收尾层数(0.2.106 之前的账没有这一格),不进这条走向`)
|
|
446
|
+
caveats.push("只数 status='active';这一轮写了 byLevel 而里面没有那一层,就是那一轮那层 0 条在用")
|
|
447
|
+
return `${parts.join(' · ')}(${caveats.join(';')})`
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* 一行账:`- #1 11-20 08:14 · 整理完成 · 2 轮 / 2 条 · 逐字重复 0 对 · 重复详写 1 对 · 缺 1 个词`
|
|
452
|
+
* 没有 plan 的老记录只报「groups=…」(那是 summary 里本来就有的数),并说明为什么没有规模。
|
|
453
|
+
*
|
|
454
|
+
* [macro-fusion 0.2.98] 行首补 `#k`(1 = 最新):同一份账在会话里会反复出现,
|
|
455
|
+
* 有编号才好在后面说「第 3 条那次 stamped=false」。行尾补「落库 是/否」——
|
|
456
|
+
* stamped 是「这一轮的结论真的写进库了吗」,整理完却没写进库,和没整理过是两件事。
|
|
457
|
+
*/
|
|
458
|
+
/**
|
|
459
|
+
* [macro-fusion 0.2.104] 账本行的稳定引用:dream_log.id 只增不减、删了也不复用,
|
|
460
|
+
* 所以「r128」永远指同一轮整理;而「#3」只是它此刻排第几——下次再跑一次 dream,
|
|
461
|
+
* #3 就换人了。两个号并存:翻开时看 #k(这一页的第几近),回指时用 r<N>。
|
|
462
|
+
*/
|
|
463
|
+
function refOfRow(row) {
|
|
464
|
+
const id = Number(row?.id)
|
|
465
|
+
return Number.isFinite(id) && id > 0 ? `r${id}` : ''
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** 把「r128」这种引用写法解析成 128;数字、「#3」、乱写一律返回 0(走「第几近」那条路,由调用方打回)。 */
|
|
469
|
+
function refIdOf(raw) {
|
|
470
|
+
if (raw === undefined || raw === null) return 0
|
|
471
|
+
const m = /^[rR](\d{1,9})$/.exec(String(raw).trim())
|
|
472
|
+
if (m === null) return 0
|
|
473
|
+
const n = Number(m[1])
|
|
474
|
+
return Number.isFinite(n) && n > 0 ? n : 0
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function rowLine(row, index) {
|
|
478
|
+
const k = kindOf(row)
|
|
479
|
+
const seq = Number.isFinite(index) ? `#${index} ` : ''
|
|
480
|
+
const ref = refOfRow(row)
|
|
481
|
+
const tailRef = ref === '' ? '' : ` · 引用 ${ref}`
|
|
482
|
+
const head = `${seq}${stamp(row.runAt)} · ${KIND_TEXT[k.kind] ?? (k.kind === '' ? '原因未记' : k.kind)}`
|
|
483
|
+
const plan = row.changes?.plan
|
|
484
|
+
if (plan === undefined || plan === null) {
|
|
485
|
+
const groups = Number(row.changes?.groups)
|
|
486
|
+
const tail = Number.isFinite(groups) ? ` · ${groups} 组` : ''
|
|
487
|
+
// [macro-fusion 0.2.107] 没有 plan 不等于「比 0.2.96 早」:被打断后补记、被封存的账本来就没有规模数字,
|
|
488
|
+
// 以前一律念成「比 0.2.96 早」,把 0.2.96 之后才写的账说成了更早的账。现在按来路分开讲。
|
|
489
|
+
const kt = kindTail(k)
|
|
490
|
+
if (kt !== '') return `${head}${tail} · ${kt}${tailRef}`
|
|
491
|
+
return `${head}${tail} · 这条记录比 0.2.96 早,当时还没写规模数字${tailRef}`
|
|
492
|
+
}
|
|
493
|
+
const num = (v) => {
|
|
494
|
+
const n = Number(v)
|
|
495
|
+
return Number.isFinite(n) ? n : 0
|
|
496
|
+
}
|
|
497
|
+
const parts = [
|
|
498
|
+
`${num(plan.rounds)} 轮 / ${num(plan.rows)} 条`,
|
|
499
|
+
`逐字重复 ${num(plan.dup)} 对`,
|
|
500
|
+
`重复详写 ${num(plan.cover)} 对`,
|
|
501
|
+
]
|
|
502
|
+
if (num(plan.missing) > 0) parts.push(`缺 ${num(plan.missing)} 个词`)
|
|
503
|
+
// 疑似冲突只在真有时进这一行:0 对是常态,行里多一个「疑似冲突 0 对」只会把别的数字挤淡。
|
|
504
|
+
const conflictCount = conflictsOf(plan)
|
|
505
|
+
if (conflictCount > 0) parts.push(`疑似冲突 ${conflictCount} 对`)
|
|
506
|
+
const projects = projectCountOf(plan)
|
|
507
|
+
if (projects > 0) parts.push(`${projects} 个项目段`)
|
|
508
|
+
const stamped = row.changes?.stamped
|
|
509
|
+
if (typeof stamped === 'boolean') parts.push(`落库 ${stamped ? '是' : '否'}`)
|
|
510
|
+
// [macro-fusion 0.2.107] 有 plan 的账也要说明它是怎么收的场:跑完的轮与半路停下的轮,
|
|
511
|
+
// 数字长得一样但含义不同(后者只是扫到那儿的中间值)。
|
|
512
|
+
const kt = kindTail(k)
|
|
513
|
+
if (kt !== '') parts.push(kt)
|
|
514
|
+
return `${head} · ${parts.join(' · ')}${tailRef}`
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* [macro-fusion 0.2.98] 趋势行:只念账本,不猜。
|
|
519
|
+
*
|
|
520
|
+
* 主人真正会问的问题是「整理是不是越做越干净」,而单看某一行回答不了——
|
|
521
|
+
* 五条记录一行一个数字,扫完也记不住走向。所以把最近几次的
|
|
522
|
+
* 逐字重复 / 重复详写 / 缺词 各自合计,再比「后半段均值 vs 前半段均值」说在变多还是变少。
|
|
523
|
+
*
|
|
524
|
+
* 四条克制:
|
|
525
|
+
* 1. 可用记录 < 2 条就不出这一行(一条记录没有「趋势」,硬算等于编)。
|
|
526
|
+
* 2. 老格式(没有 plan)的行不参与,但要说清有几条被跳过——否则合计对不上账。
|
|
527
|
+
* 3. 次数 < 4 时补一句「次数太少,只当参考」:样本不足时不许把噪声说成走势。
|
|
528
|
+
* 4. 变化量不足 0.5 就说「持平」,不许把 1.4 → 1.2 讲成「在变少」。
|
|
529
|
+
*/
|
|
530
|
+
function trendLine(rows) {
|
|
531
|
+
const withPlan = rows.filter((r) => r.changes?.plan !== undefined && r.changes?.plan !== null)
|
|
532
|
+
const skipped = rows.length - withPlan.length
|
|
533
|
+
// [macro-fusion 0.2.107] 只有跑完的一轮才进合计:半路停下的那轮,dup/cover/missing 是
|
|
534
|
+
// 「扫到这里为止」的中间值,跟跑完的轮加起来等于把半张成绩单当满分算。
|
|
535
|
+
const full = withPlan.filter((r) => isFullRound(r))
|
|
536
|
+
const partial = withPlan.length - full.length
|
|
537
|
+
if (full.length < 2) return ''
|
|
538
|
+
const ordered = full.slice().reverse() // 账本是「最新在前」,趋势要「最早→最新」
|
|
539
|
+
const pick = (r, key) => {
|
|
540
|
+
const n = Number(r.changes.plan?.[key])
|
|
541
|
+
return Number.isFinite(n) ? n : 0
|
|
542
|
+
}
|
|
543
|
+
const sum = (key) => ordered.reduce((acc, r) => acc + pick(r, key), 0)
|
|
544
|
+
const half = Math.floor(ordered.length / 2)
|
|
545
|
+
const trendOf = (key) => {
|
|
546
|
+
if (ordered.length < 4) return '持平'
|
|
547
|
+
const early = ordered.slice(0, half).reduce((a, r) => a + pick(r, key), 0) / half
|
|
548
|
+
const late = ordered.slice(ordered.length - half).reduce((a, r) => a + pick(r, key), 0) / half
|
|
549
|
+
if (late - early >= 0.5) return '在变多'
|
|
550
|
+
if (early - late >= 0.5) return '在变少'
|
|
551
|
+
return '持平'
|
|
552
|
+
}
|
|
553
|
+
const parts = [
|
|
554
|
+
`逐字重复 合计 ${sum('dup')} 对,${trendOf('dup')}`,
|
|
555
|
+
`重复详写 合计 ${sum('cover')} 对,${trendOf('cover')}`,
|
|
556
|
+
`缺词 合计 ${sum('missing')} 个,${trendOf('missing')}`,
|
|
557
|
+
]
|
|
558
|
+
const caveats = []
|
|
559
|
+
// [macro-fusion 0.2.103] 库规模:只有至少两次账记了 store 才敢讲区间;一次是快照,不是走势。
|
|
560
|
+
const storeRows = ordered.map((r) => storeOf(r.changes?.plan)).filter((s) => s !== null)
|
|
561
|
+
if (storeRows.length >= 2) {
|
|
562
|
+
const first = storeRows[0].active
|
|
563
|
+
const last = storeRows[storeRows.length - 1].active
|
|
564
|
+
const delta = last - first
|
|
565
|
+
const word = delta > 0 ? `多了 ${delta} 条` : delta < 0 ? `少了 ${-delta} 条` : '没变'
|
|
566
|
+
parts.push(`库 开工时 ${first} → ${last} 条(${word})`)
|
|
567
|
+
if (storeRows.length < ordered.length) {
|
|
568
|
+
caveats.push(`库规模只有 ${storeRows.length} 次有数——更早的账写在 0.2.103 之前,没有这一格`)
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
// [macro-fusion 0.2.106] 有收尾数的那几次,把净变化合起来——整理总体上在让库变大还是变小,
|
|
572
|
+
// 只有把每一轮的「开工 → 收尾」加起来才答得出。缺收尾数的账不参与,但要说清少了几次。
|
|
573
|
+
const spans = ordered.map((r) => storeDeltaOf(r.changes?.plan)).filter((s) => s !== null)
|
|
574
|
+
if (spans.length > 0) {
|
|
575
|
+
const net = spans.reduce((acc, s) => acc + s.delta, 0)
|
|
576
|
+
const word = net > 0 ? `净增 ${net} 条` : net < 0 ? `净减 ${-net} 条` : '净变化为 0'
|
|
577
|
+
parts.push(`收尾${word}(${spans.length} 次有收尾数)`)
|
|
578
|
+
if (spans.length < storeRows.length) {
|
|
579
|
+
caveats.push(`${storeRows.length - spans.length} 次只有开工数、没有收尾数——0.2.106 之前的账没有这一格`)
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (skipped > 0) caveats.push(`${skipped} 条记录早于 0.2.96,没有数字、不参与`)
|
|
583
|
+
// [macro-fusion 0.2.107] 有几轮没跑完要说清,否则「最近 N 次」和账本行数对不上,读者会以为漏了账。
|
|
584
|
+
if (partial > 0) caveats.push(`${partial} 次没跑完(中途放弃 / 待补记 / 已封存),不进合计`)
|
|
585
|
+
if (ordered.length < 4) caveats.push(`${ordered.length} 次样本太少,只当参考、别当走势`)
|
|
586
|
+
const tail = caveats.length > 0 ? `(${caveats.join(';')})` : ''
|
|
587
|
+
return `趋势:最近 ${ordered.length} 次(最早→最新)· ${parts.join(' · ')}${tail}`
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* 这一轮正在整理什么(0.2.99):账本是事后对账,活的那一轮要从 lease + dreamdigest 读。
|
|
593
|
+
* 只念一句,不占账本的位置——收尾之后它就会变成上面的一行历史。
|
|
594
|
+
*/
|
|
595
|
+
function liveLine(live) {
|
|
596
|
+
const ids = Array.isArray(live?.sessionIds) ? live.sessionIds : []
|
|
597
|
+
if (ids.length === 0) return ''
|
|
598
|
+
const num = (v) => {
|
|
599
|
+
const n = Number(v)
|
|
600
|
+
return Number.isFinite(n) ? n : 0
|
|
601
|
+
}
|
|
602
|
+
const plan = live?.plans?.[ids[0]]
|
|
603
|
+
const head = `整理进行中${ids.length > 1 ? `(还有 ${ids.length - 1} 个会话在排队等整理)` : ''}`
|
|
604
|
+
if (plan === undefined || plan === null) {
|
|
605
|
+
return `${head}:这一轮的规模还没落 meta(刚 claim,摘要算完就有了)——收尾之后这里会变成账本里的一行历史`
|
|
606
|
+
}
|
|
607
|
+
const parts = [`${num(plan.rounds)} 轮 / ${num(plan.rows)} 条`, `逐字重复 ${num(plan.dup)} 对`, `重复详写 ${num(plan.cover)} 对`]
|
|
608
|
+
if (num(plan.missing) > 0) parts.push(`缺 ${num(plan.missing)} 个词`)
|
|
609
|
+
const projects = projectCountOf(plan)
|
|
610
|
+
if (projects > 0) parts.push(`${projects} 个项目段`)
|
|
611
|
+
return `${head}:${parts.join(' · ')}——收尾之后这里会变成账本里的一行历史`
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* [macro-fusion 0.2.101] 项目段的分布:账本里到底有哪几个项目、各出现在几次整理里。
|
|
616
|
+
* 行首就用它,是因为「按项目翻账」得先知道有哪几个项目可筛——不然用户只能瞎猜名字。
|
|
617
|
+
* 只列前几条时把「还有几个没列」说出来,别让「没列」被读成「没有」。
|
|
618
|
+
*/
|
|
619
|
+
function projectsLine(got) {
|
|
620
|
+
const items = Array.isArray(got?.items) ? got.items : []
|
|
621
|
+
if (items.length === 0) return ''
|
|
622
|
+
const parts = items.map((it) => `${it.project} ${it.n} 次`)
|
|
623
|
+
const total = Number(got.total) || 0
|
|
624
|
+
const rest = total - items.length
|
|
625
|
+
const tail = rest > 0 ? `(还有 ${rest} 个项目段没列)` : ''
|
|
626
|
+
return `项目段:${parts.join(' · ')}${tail}`
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/** 某一条账自己的项目段(展开时摊出来):有就点名,没有就说没有,不拿摘要里的字凑。 */
|
|
630
|
+
function projectNames(row) {
|
|
631
|
+
const list = row?.changes?.plan?.projects
|
|
632
|
+
if (!Array.isArray(list) || list.length === 0) return ''
|
|
633
|
+
return list.map((p) => String(p)).filter((p) => p !== '').join('、')
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* [macro-fusion 0.2.102] 对子明细:账本从这一版起记「跟谁撞」,摊开一条账就能直接动手合并。
|
|
638
|
+
*
|
|
639
|
+
* 四条克制:
|
|
640
|
+
* 1. `pairs` 字段不存在 ≠ 没有对子:老账本(0.2.102 之前)不存明细,只能念数,得明说是「没存」。
|
|
641
|
+
* 2. 账里说撞上 N 对、明细却是空的:说明这一轮的真值超出了落库上限,别把「没列」读成「没有」。
|
|
642
|
+
* 3. 短 id 与整理清单里印的是同一套(uniqueShortIdsAmong),能直接拿去 memory_read / memory_update。
|
|
643
|
+
* 4. 重复详写对要念「会丢几个词」——合并时最容易被丢掉的就是这些词。
|
|
644
|
+
*/
|
|
645
|
+
function pairLine(p) {
|
|
646
|
+
const cover = p?.kind === 'cover'
|
|
647
|
+
const head = `- ${p?.a ?? '?'} ${cover ? '⊂' : '⇄'} ${p?.b ?? '?'} ${Number(p?.score) || 0} · ${p?.levelA ?? '?'} ${cover ? '⇒' : '⇄'} ${p?.levelB ?? '?'}`
|
|
648
|
+
if (!cover) return head
|
|
649
|
+
const missing = Number(p?.missing) || 0
|
|
650
|
+
if (missing === 0) return `${head} · 合并无损`
|
|
651
|
+
const words = (Array.isArray(p?.words) ? p.words : []).map((w) => String(w)).filter((w) => w !== '')
|
|
652
|
+
return `${head} · 会丢 ${missing} 个词${words.length === 0 ? '' : `:${words.join('、')}`}`
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function pairsBlock(row) {
|
|
656
|
+
const plan = row?.changes?.plan
|
|
657
|
+
if (plan === undefined || plan === null) {
|
|
658
|
+
// [macro-fusion 0.2.107] 没有 plan 不等于「写在 0.2.96 之前」:封存、补记、中途放弃这几种账
|
|
659
|
+
// 本来就没有规模数字,别把 0.2.107 的新账说成老账。
|
|
660
|
+
const k = kindOf(row)
|
|
661
|
+
if (k.stored && k.kind !== 'done') {
|
|
662
|
+
return `对子:这一轮不是跑完的整理(${KIND_TEXT[k.kind] ?? k.kind}),没有对子明细可念。`
|
|
663
|
+
}
|
|
664
|
+
if (k.stored === false && k.kind !== '' && k.kind !== 'done') {
|
|
665
|
+
return `对子:这一条没有 changes.plan(${KIND_TEXT[k.kind] ?? k.kind} 的账本来就不带规模),谈不上对子。`
|
|
666
|
+
}
|
|
667
|
+
return '对子:这条账没有 changes.plan(它写在 0.2.96 之前),谈不上对子。'
|
|
668
|
+
}
|
|
669
|
+
const stored = Array.isArray(plan.pairs) ? plan.pairs : null
|
|
670
|
+
const dup = Number(plan.dup) || 0
|
|
671
|
+
const cover = Number(plan.cover) || 0
|
|
672
|
+
if (stored === null) {
|
|
673
|
+
return '对子:这条账没有存对子明细(0.2.102 之前的记录)——上面那行数是真数,但跟谁撞了要回去翻那次整理的消息。'
|
|
674
|
+
}
|
|
675
|
+
if (stored.length === 0) {
|
|
676
|
+
return dup + cover === 0
|
|
677
|
+
? '对子:这一轮没撞上对子,没有可合并的。'
|
|
678
|
+
: `对子:账里记着 ${dup + cover} 对,却没有一条明细——别把「没列」读成「没有」。`
|
|
679
|
+
}
|
|
680
|
+
const dups = stored.filter((p) => p?.kind !== 'cover')
|
|
681
|
+
const covers = stored.filter((p) => p?.kind === 'cover')
|
|
682
|
+
const lines = [`对子(账里存了 ${stored.length} 对,这一轮共 ${dup + cover} 对):`]
|
|
683
|
+
if (dups.length > 0) lines.push('逐字重复:', ...dups.map(pairLine))
|
|
684
|
+
if (covers.length > 0) lines.push('重复详写:', ...covers.map(pairLine))
|
|
685
|
+
if (stored.length < dup + cover) {
|
|
686
|
+
lines.push(`- 还有 ${dup + cover - stored.length} 对没落账(一条账只存前几对)——数是真数,点名只到前几对。`)
|
|
687
|
+
}
|
|
688
|
+
lines.push('短 id 和整理清单里印的是同一套,可以直接拿去 memory_read / memory_update。')
|
|
689
|
+
return lines.join('\n')
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* [macro-fusion 0.2.114] 疑似冲突:对子那两块回答「同一句话存了两份」,这一块回答的是另一种病——
|
|
694
|
+
* 「同一件事写成了两种说法」(一条说 DSH 在 C 盘,另一条说已搬到 D 盘)。它们逐字重复度低、
|
|
695
|
+
* 覆盖度也够不着「摘要 + 全文」,所以前面两块都不会出声,可它们一起被召回就是自相矛盾。
|
|
696
|
+
*
|
|
697
|
+
* 三条克制与对子那块一致:
|
|
698
|
+
* 1. `conflictPairs` 不存在 ≠ 没有冲突:0.2.114 之前的账没查过,得说「没查」,不能说「查了没有」。
|
|
699
|
+
* 2. 账里记着 N 对而明细是空的:真值超出落库上限,别把「没列」读成「没有」。
|
|
700
|
+
* 3. 不判决:只摊「差在哪些数字、共用哪些关键词、谁更新」;改哪条、标不标 stale 是整理时的事。
|
|
701
|
+
*/
|
|
702
|
+
function conflictsOf(plan) {
|
|
703
|
+
const n = Number(plan?.conflicts)
|
|
704
|
+
return Number.isFinite(n) && n > 0 ? n : 0
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function conflictPairsOf(plan) {
|
|
708
|
+
const list = plan?.conflictPairs
|
|
709
|
+
if (!Array.isArray(list)) return null
|
|
710
|
+
return list.filter((p) => p !== null && typeof p === 'object')
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* [macro-fusion 0.2.115] 同一对冲突在更早的轮里报过没有——「老账重提」与「这一轮新报」必须分得开。
|
|
715
|
+
*
|
|
716
|
+
* 为什么值得单独做:0.2.114 每轮都会把同一对摆出来,但**没有任何一格能回答「上一轮报的那对,
|
|
717
|
+
* 到底被处置了没有」**。于是两种完全相反的情形在面板上长得一模一样:刚发现的冲突,和连续五轮
|
|
718
|
+
* 都在报、一直没人动的老毛病。前者要人看,后者是要处置的信号——混在一起,冲突块就成了噪音。
|
|
719
|
+
*
|
|
720
|
+
* 三条克制:
|
|
721
|
+
* 1. 只读账本、不重算:拿更早的十来条账,把它们的 `conflictPairs` 摊成一张「短 id 对 → 最早第几轮、
|
|
722
|
+
* 共几次」的表。不重新跑一遍检测(库里那两条记忆现在可能已经被改掉了,重算出来的对数和当时记的
|
|
723
|
+
* 不是一回事)。
|
|
724
|
+
* 2. 读不到更早的账(`seen` 为 `undefined`)就一个字都不说:不写「这一轮新报」,也不写「没报过」。
|
|
725
|
+
* 3. 配对键按短 id 排序拼(`a⇄b` 与 `b⇄a` 是同一对)。短 id 是那一轮从行 id 前缀算出来的,
|
|
726
|
+
* 同一批记忆在相邻几轮里稳定;真换了库,宁可不认,也不错认。
|
|
727
|
+
* 4. 「最早第几轮」按轮号最大算(1 是最新,轮号越大越早):这个数得是时间上的第一次,
|
|
728
|
+
* 否则「挂了五轮」会读成「刚出现」。
|
|
729
|
+
*/
|
|
730
|
+
const OLDER_SPAN = 10
|
|
731
|
+
const CONFLICT_REPEAT_MIN = 3
|
|
732
|
+
|
|
733
|
+
function conflictKeyOf(p) {
|
|
734
|
+
const a = String(p?.a ?? '')
|
|
735
|
+
const b = String(p?.b ?? '')
|
|
736
|
+
if (a === '' || b === '' || a === b) return ''
|
|
737
|
+
return a < b ? `${a}⇄${b}` : `${b}⇄${a}`
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function conflictKeyIndex(rows, firstRank) {
|
|
741
|
+
const seen = new Map()
|
|
742
|
+
const list = Array.isArray(rows) ? rows : []
|
|
743
|
+
list.forEach((row, i) => {
|
|
744
|
+
const pairs = conflictPairsOf(row?.changes?.plan)
|
|
745
|
+
if (pairs === null) return
|
|
746
|
+
const rank = firstRank + i
|
|
747
|
+
for (const p of pairs) {
|
|
748
|
+
const key = conflictKeyOf(p)
|
|
749
|
+
if (key === '') continue
|
|
750
|
+
const hit = seen.get(key)
|
|
751
|
+
if (hit === undefined) seen.set(key, { first: rank, count: 1 })
|
|
752
|
+
else {
|
|
753
|
+
hit.count += 1
|
|
754
|
+
// 「最早第几轮」= 时间上最早的那次 = 轮号最大的那次(1 是最新)。
|
|
755
|
+
if (rank > hit.first) hit.first = rank
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
})
|
|
759
|
+
return seen
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/** 从第 rank 条往下读一段更早的账,摊成索引;读不出来返回 undefined(调用方据此闭嘴)。 */
|
|
763
|
+
function conflictSeenOf(workspace, dir, rank) {
|
|
764
|
+
if (!(rank > 0)) return undefined
|
|
765
|
+
const got = Meow.readDreamRecords(workspace, dir, OLDER_SPAN, rank)
|
|
766
|
+
if (got === null || got === undefined || got.missing !== '' || !Array.isArray(got.rows)) return undefined
|
|
767
|
+
if (got.rows.length === 0) return new Map()
|
|
768
|
+
return conflictKeyIndex(got.rows, rank + 1)
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* [macro-fusion 0.2.116] 闭环的另一半:上一轮报过的对,这一轮不再报,后来怎么了。
|
|
773
|
+
*
|
|
774
|
+
* 0.2.115 只回答了「这一对报过几次」。可「不再报」有两种完全相反的原因:真被处置了,或者两条被归档/删掉、
|
|
775
|
+
* 正文被改、关键词错开——三种在面板上都长得一样(都是「这一轮没报」)。不做这一步,追踪只能证明「以前报过」,
|
|
776
|
+
* 证明不了「后来处理了」。
|
|
777
|
+
*
|
|
778
|
+
* 四条克制:
|
|
779
|
+
* 1. 只比**上一轮**(第 rank+1 条账),不往更早翻:更早的「不见了」说不清是哪一轮处置的。
|
|
780
|
+
* 2. 判断只读**现在**的行(status / updated_at),不重跑冲突检测——重跑是用今天的库猜昨天的判断。
|
|
781
|
+
* 3. 读不到上一轮(老账没存 conflictPairs)返回 undefined,一个字都不说;读不到行则只说「不再报」、不编去向。
|
|
782
|
+
* 4. 「没动过」要单独说透:两条都在、也都没改,那多半只是关键词/数字错开,不是处置——不给人一个假的安心。
|
|
783
|
+
*/
|
|
784
|
+
const SETTLED_MAX = 3
|
|
785
|
+
|
|
786
|
+
function rowFateOf(id, byShort, prevAt) {
|
|
787
|
+
const list = byShort.get(id) ?? []
|
|
788
|
+
if (list.length === 0) return `${id} 查不到了(归档或删除)`
|
|
789
|
+
if (list.length > 1) return `${id} 命中 ${list.length} 条(短 id 前几位撞了,判断不了)`
|
|
790
|
+
const r = list[0]
|
|
791
|
+
if (r.status === 'archived') return `${id} 已归档`
|
|
792
|
+
if (r.status === 'stale') return `${id} 已标 stale`
|
|
793
|
+
const at = Number(r.updated_at) || 0
|
|
794
|
+
if (prevAt > 0 && at > prevAt) return `${id} 正文改过(${stamp(at)})`
|
|
795
|
+
return `${id} 没动过`
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function conflictSettledOf(workspace, dir, rank, plan) {
|
|
799
|
+
if (!(rank > 0)) return undefined
|
|
800
|
+
const got = Meow.readDreamRecords(workspace, dir, 2, rank)
|
|
801
|
+
if (got === null || got === undefined || got.missing !== '' || !Array.isArray(got.rows)) return undefined
|
|
802
|
+
const prev = got.rows[0]
|
|
803
|
+
if (prev === undefined || prev === null) return undefined
|
|
804
|
+
const prevPairs = conflictPairsOf(prev?.changes?.plan)
|
|
805
|
+
if (prevPairs === null) return undefined
|
|
806
|
+
if (prevPairs.length === 0) return undefined
|
|
807
|
+
const nowKeys = new Set()
|
|
808
|
+
const mine = conflictPairsOf(plan)
|
|
809
|
+
if (Array.isArray(mine)) {
|
|
810
|
+
for (const p of mine) {
|
|
811
|
+
const k = conflictKeyOf(p)
|
|
812
|
+
if (k !== '') nowKeys.add(k)
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
const gone = prevPairs.filter((p) => {
|
|
816
|
+
const k = conflictKeyOf(p)
|
|
817
|
+
return k !== '' && !nowKeys.has(k)
|
|
818
|
+
})
|
|
819
|
+
const out = { rank: rank + 1, total: prevPairs.length, gone: [], hidden: 0, blind: false }
|
|
820
|
+
if (gone.length === 0) return out
|
|
821
|
+
const ids = []
|
|
822
|
+
for (const p of gone) {
|
|
823
|
+
for (const id of [String(p?.a ?? ''), String(p?.b ?? '')]) {
|
|
824
|
+
if (id !== '' && !ids.includes(id)) ids.push(id)
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
const read = Meow.readRowsByIds(workspace, dir, ids)
|
|
828
|
+
if (read === null || read === undefined || read.missing !== '' || !Array.isArray(read.rows)) {
|
|
829
|
+
out.blind = true
|
|
830
|
+
out.hidden = Math.max(0, gone.length - SETTLED_MAX)
|
|
831
|
+
out.gone = gone.slice(0, SETTLED_MAX).map((p) => ({
|
|
832
|
+
key: conflictKeyOf(p),
|
|
833
|
+
text: `${String(p?.a ?? '?')} 与 ${String(p?.b ?? '?')} 的现状读不出来`,
|
|
834
|
+
}))
|
|
835
|
+
return out
|
|
836
|
+
}
|
|
837
|
+
const byShort = new Map()
|
|
838
|
+
for (const r of read.rows) {
|
|
839
|
+
const short = String(r?.id ?? '').slice(0, 8)
|
|
840
|
+
if (short === '') continue
|
|
841
|
+
if (!byShort.has(short)) byShort.set(short, [])
|
|
842
|
+
byShort.get(short).push(r)
|
|
843
|
+
}
|
|
844
|
+
const prevAt = Number(prev.runAt) || 0
|
|
845
|
+
out.hidden = Math.max(0, gone.length - SETTLED_MAX)
|
|
846
|
+
out.gone = gone.slice(0, SETTLED_MAX).map((p) => {
|
|
847
|
+
const a = String(p?.a ?? '?')
|
|
848
|
+
const b = String(p?.b ?? '?')
|
|
849
|
+
return { key: conflictKeyOf(p), text: `${rowFateOf(a, byShort, prevAt)};${rowFateOf(b, byShort, prevAt)}` }
|
|
850
|
+
})
|
|
851
|
+
return out
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/** 上一轮的去向写成一块;没有任何可说的(上一轮没报过 / 老账没这一格)返回空串。 */
|
|
855
|
+
function settledBlock(settled) {
|
|
856
|
+
if (settled === undefined || settled === null) return ''
|
|
857
|
+
const total = Number(settled.total) || 0
|
|
858
|
+
if (total === 0) return ''
|
|
859
|
+
const head = `上一轮(第 ${settled.rank} 轮)报了 ${total} 对`
|
|
860
|
+
const gone = Array.isArray(settled.gone) ? settled.gone : []
|
|
861
|
+
if (gone.length === 0) return `${head},这一轮还都在报。`
|
|
862
|
+
const count = gone.length + (Number(settled.hidden) || 0)
|
|
863
|
+
const lines = [`${head},这一轮不再报的有 ${count} 对:`]
|
|
864
|
+
for (const g of gone) lines.push(` · ${String(g.key).replace('⇄', ' ⇄ ')}:${g.text}`)
|
|
865
|
+
if ((Number(settled.hidden) || 0) > 0) lines.push(` · 还有 ${settled.hidden} 对没列(一次只摊前 ${SETTLED_MAX} 对)。`)
|
|
866
|
+
const changed = /已归档|已标 stale|正文改过|查不到了|命中 \d+ 条|读不出来/
|
|
867
|
+
if (settled.blind) {
|
|
868
|
+
lines.push('这几对的现状读不出来——只报「不再报」这个事实,去向不猜。')
|
|
869
|
+
} else if (gone.every((g) => !changed.test(String(g.text)))) {
|
|
870
|
+
lines.push('两条都还在、也都没动过——它这一轮没被报,多半是关键词 / 数字刚好错开,不是处置。')
|
|
871
|
+
} else {
|
|
872
|
+
lines.push('上面只是「后来动过什么」,不等于这一对真解决了:要确认就打开那两条看正文。')
|
|
873
|
+
}
|
|
874
|
+
return lines.join('\n')
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
function trailOf(p, seen) {
|
|
878
|
+
if (seen === undefined) return ''
|
|
879
|
+
const key = conflictKeyOf(p)
|
|
880
|
+
if (key === '') return ''
|
|
881
|
+
const hit = seen.get(key)
|
|
882
|
+
if (hit === undefined) return ' · 这一轮新报'
|
|
883
|
+
const times = hit.count + 1
|
|
884
|
+
return ` · 之前报过(最早第 ${hit.first} 轮,加这次共 ${times} 次)`
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
function conflictLine(p, seen) {
|
|
888
|
+
const idA = String(p?.a ?? '?')
|
|
889
|
+
const idB = String(p?.b ?? '?')
|
|
890
|
+
const head = `- ${idA} ⇄ ${idB} · ${p?.levelA ?? '?'} ⇄ ${p?.levelB ?? '?'}`
|
|
891
|
+
const words = (Array.isArray(p?.shared) ? p.shared : []).map((w) => String(w)).filter((w) => w !== '')
|
|
892
|
+
const sharedTotal = Number(p?.sharedTotal) || 0
|
|
893
|
+
const kwLine = words.length === 0
|
|
894
|
+
? ''
|
|
895
|
+
: ` · 共用关键词:${words.join('、')}${sharedTotal > words.length ? `(共 ${sharedTotal} 个)` : ''}`
|
|
896
|
+
const sideOf = (id, nums, total) => {
|
|
897
|
+
const list = (Array.isArray(nums) ? nums : []).map((x) => String(x)).filter((x) => x !== '')
|
|
898
|
+
if (list.length === 0) return ''
|
|
899
|
+
const all = Number(total) || 0
|
|
900
|
+
return ` · ${id} 独有 ${list.join('、')}${all > list.length ? `(共 ${all} 个)` : ''}`
|
|
901
|
+
}
|
|
902
|
+
const at = Number(p?.newerAt) || 0
|
|
903
|
+
const who = p?.newer === 'a' ? idA : p?.newer === 'b' ? idB : ''
|
|
904
|
+
const verdict = who === ''
|
|
905
|
+
? ' · 两条更新时间相同,分不出谁新'
|
|
906
|
+
: ` · ${who} 更新${at > 0 ? `(${stamp(at)})` : ''}`
|
|
907
|
+
// [macro-fusion 0.2.115] 这一对是不是老账重提:`seen` 未提供时(更早的账没读出来)不写这一句,
|
|
908
|
+
// 免得把「没读」写成「新报」——这两种说法在面板上必须分得开。
|
|
909
|
+
const trail = trailOf(p, seen)
|
|
910
|
+
return `${head}${kwLine}${sideOf(idA, p?.onlyA, p?.onlyACount)}${sideOf(idB, p?.onlyB, p?.onlyBCount)}${verdict}${trail}`
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
function conflictsBlock(row, seen, settled) {
|
|
914
|
+
const plan = row?.changes?.plan
|
|
915
|
+
if (plan === undefined || plan === null) return ''
|
|
916
|
+
const settledText = settledBlock(settled)
|
|
917
|
+
// [macro-fusion 0.2.116] 去向那句在每一种分支后面都要跟着走:这一轮 0 对时它才是唯一的线索
|
|
918
|
+
//(上一轮报了、这一轮不报,正是「处置了没有」该被回答的时刻)。
|
|
919
|
+
const withTail = (text) => (settledText === '' ? text : `${text}\n${settledText}`)
|
|
920
|
+
const stored = conflictPairsOf(plan)
|
|
921
|
+
const total = conflictsOf(plan)
|
|
922
|
+
if (stored === null) {
|
|
923
|
+
return withTail('疑似冲突:这条账没有存这一格(0.2.114 之前的记录)——那一轮根本没查冲突,不是「查了没有」。')
|
|
924
|
+
}
|
|
925
|
+
if (stored.length === 0) {
|
|
926
|
+
return withTail(
|
|
927
|
+
total === 0
|
|
928
|
+
? '疑似冲突:这一轮没有「同一主题却写了不同数字」的条目。'
|
|
929
|
+
: `疑似冲突:账里记着 ${total} 对,却没有一条明细——别把「没列」读成「没有」。`,
|
|
930
|
+
)
|
|
931
|
+
}
|
|
932
|
+
// [macro-fusion 0.2.115] 抬头带上「其中几对是老账重提」:一眼分得出这一轮是新发现,还是又摊了一遍。
|
|
933
|
+
const repeats = stored
|
|
934
|
+
.map((p) => ({ p, hit: seen === undefined ? undefined : seen.get(conflictKeyOf(p)) }))
|
|
935
|
+
.filter((x) => x.hit !== undefined)
|
|
936
|
+
const head = repeats.length === 0
|
|
937
|
+
? `疑似冲突(账里存了 ${stored.length} 对,这一轮共 ${total} 对):`
|
|
938
|
+
: `疑似冲突(账里存了 ${stored.length} 对,这一轮共 ${total} 对;其中 ${repeats.length} 对之前就报过,最早第 ${Math.min(...repeats.map((x) => x.hit.first))} 轮):`
|
|
939
|
+
const lines = [head, ...stored.map((p) => conflictLine(p, seen))]
|
|
940
|
+
if (stored.length < total) {
|
|
941
|
+
lines.push(`- 还有 ${total - stored.length} 对没落账(一条账只存前几对)——数是真数,点名只到前几对。`)
|
|
942
|
+
}
|
|
943
|
+
// 连续 ≥3 次还在报:这是「报过但没动」的唯一可观察信号,得点名而不是继续安静地重提。
|
|
944
|
+
const stale = repeats.filter((x) => x.hit.count + 1 >= CONFLICT_REPEAT_MIN)
|
|
945
|
+
if (stale.length > 0) {
|
|
946
|
+
const worst = stale.reduce((a, b) => (b.hit.count > a.hit.count ? b : a))
|
|
947
|
+
const key = conflictKeyOf(worst.p).replace('⇄', ' ⇄ ')
|
|
948
|
+
lines.push(
|
|
949
|
+
`- ${key} 已经第 ${worst.hit.count + 1} 次出现在账上(最早第 ${worst.hit.first} 轮)——同一对不会因为多报几次变得清楚:要么按【疑似冲突】处置(取新的、旧的标「(已被取代:…)」或设 stale),要么承认它是两件不同的事,把正文写清归属。`,
|
|
950
|
+
// [macro-fusion 0.2.117] 光催没有口子:这一句把「取新的、旧的标已被取代」变成一次调用。
|
|
951
|
+
// 只给 a 不给 b——b 是不是同一件事得人来判,取代谁由人指定。
|
|
952
|
+
` 一次做完:memory_remember(…, supersedes: ["${String(worst.p.a ?? '').slice(0, 8)}"]) 会在写新条目的同时把旧的那条标 stale、正文里留一句「(已被取代:…)」;旧条目不会消失,反悔可改回 active。`,
|
|
953
|
+
)
|
|
954
|
+
}
|
|
955
|
+
lines.push('更新时间取自库里的 updated_at;哪条要改、要不要标 stale,看正文自己决断——这一块只摊事实,不判决。')
|
|
956
|
+
return withTail(lines.join('\n'))
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* [macro-fusion 0.2.106] 库规模一格:原来只说「开工时多大」,现在两个观测点都念。
|
|
961
|
+
*
|
|
962
|
+
* 为什么值得反转 0.2.103 的口径(当时明写「收尾不再数」):只念开工那一眼,读的人永远算不出
|
|
963
|
+
* 这一轮让库变轻还是变重——而「整理是不是真在收敛」正是整理这件事唯一的成绩单。
|
|
964
|
+
* 两个数都是一轮里真数出来的(收尾那次在 stampDream 之后、日志落库之前取),
|
|
965
|
+
* 但**差不是因果**:中间可能有别的会话在写、也可能有归档把 active 挪走。
|
|
966
|
+
* 所以这里只给数,归因留给 stamped(这一轮封存/完结了几条),口径句单独一行说清。
|
|
967
|
+
*
|
|
968
|
+
* 四条规矩照旧:①老账没有这一格就明说没有,不补 0;②没有 plan 的账前面已经解释过 0.2.96,这里闭嘴;
|
|
969
|
+
* ③0 条也照念(空库整理是事实,不是错误);④层名与 memory_* 的 level 一致,不加中文译名。
|
|
970
|
+
* 新增第五:有开工没收尾(0.2.106 之前的账)照旧只念开工,不假装知道后来变成多少。
|
|
971
|
+
*/
|
|
972
|
+
function storeBlock(row) {
|
|
973
|
+
const plan = row?.changes?.plan
|
|
974
|
+
if (plan === undefined || plan === null) return ''
|
|
975
|
+
const store = storeOf(plan)
|
|
976
|
+
if (store === null) {
|
|
977
|
+
return '库规模:这条账没有记库规模(它写在 0.2.103 之前)——别把「没记」读成「库是空的」。'
|
|
978
|
+
}
|
|
979
|
+
const head = `库规模:开工时 ${store.active} 条在用${levelsText(store)}`
|
|
980
|
+
const span = storeDeltaOf(plan)
|
|
981
|
+
if (store.active === 0 && span === null) return '库规模:开工时库里 0 条在用记忆——这一轮是在空库上整理的。'
|
|
982
|
+
if (span === null) return head
|
|
983
|
+
// 差放在句尾当结论,层数夹在括号里——别写成「(fact 2)(+1)」两层括号叠在一起。
|
|
984
|
+
const word = span.delta > 0 ? `比开工多 ${span.delta} 条` : span.delta < 0 ? `比开工少 ${-span.delta} 条` : '和开工时一样'
|
|
985
|
+
return `${head} → 收尾 ${span.end.active} 条在用${levelsText(span.end)},${word}`
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* [macro-fusion 0.2.106] 规模差的口径句:只在两个观测点都有数时才出。
|
|
990
|
+
* 一句话把「差」和「因」分开——这是这一格唯一容易读错的地方。
|
|
991
|
+
*/
|
|
992
|
+
function storeDeltaNote(row) {
|
|
993
|
+
const plan = row?.changes?.plan
|
|
994
|
+
const span = storeDeltaOf(plan)
|
|
995
|
+
if (span === null) return ''
|
|
996
|
+
const stamped = Number(row?.changes?.stamped)
|
|
997
|
+
const tail = Number.isFinite(stamped) ? `这一轮封存/完结 ${stamped} 条(changes.stamped)` : '这条账没记 stamped'
|
|
998
|
+
return `规模差口径:开工与收尾都只数 status='active',两个点之间可能有别的会话也在写,所以 ${span.delta >= 0 ? '+' : ''}${span.delta} 是「库变了多少」,不是「这一轮改了几条」——${tail}。`
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* [macro-fusion 0.2.107] 展开时把「这一轮是怎么收的场」讲全:跑完 / 半路停下 / 补记 / 封存。
|
|
1003
|
+
* 老账只有 summary 里那个词,就照实说「是从摘要认出来的、当时没记结构化字段」——
|
|
1004
|
+
* 别把「没记」念成「没有」,也别把 0.2.96 之后才写的补记账说成更早的账。
|
|
1005
|
+
*/
|
|
1006
|
+
function kindBlock(row) {
|
|
1007
|
+
const k = kindOf(row)
|
|
1008
|
+
if (k.kind === '') return ''
|
|
1009
|
+
const head = `收尾方式:${KIND_TEXT[k.kind] ?? k.kind}`
|
|
1010
|
+
if (k.stored === false) {
|
|
1011
|
+
return `${head}——这一条没有 changes.kind,是从摘要首词认出来的(0.2.107 之前的账没记这一格)。`
|
|
1012
|
+
}
|
|
1013
|
+
const bits = []
|
|
1014
|
+
if (k.groupsDone !== null && k.groupsTotal !== null && k.groupsTotal > 0) bits.push(`走了 ${k.groupsDone}/${k.groupsTotal} 组`)
|
|
1015
|
+
else if (k.groupsDone !== null) bits.push(`走了 ${k.groupsDone} 组`)
|
|
1016
|
+
if (k.fails !== null) bits.push(`连续失败 ${k.fails} 次`)
|
|
1017
|
+
if (bits.length === 0) return head
|
|
1018
|
+
const why = isFullRound(row) ? '' : '——没跑完的这一轮,上面那行数字只是扫到那儿的中间值,别跟跑完的轮一起算。'
|
|
1019
|
+
return `${head}(${bits.join(' · ')})${why}`
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* 单条展开:把这一条的原文摊出来,别让人只能看一行摘要。
|
|
1024
|
+
*
|
|
1025
|
+
* 三件事分开写,因为它们是三种不同来源的信息:
|
|
1026
|
+
* - 「这一轮」= changes.plan(0.2.96 起才有);老记录没有,就明说没有,不拿摘要里的数字凑。
|
|
1027
|
+
* - 「摘要」「备注」= summary / note 原文,一字不改(这是账本里的原话)。
|
|
1028
|
+
* - 「变化原文」= changes 的 JSON 原文,摊开是为了能对账;太长就截断并报真实长度。
|
|
1029
|
+
* 再加一句「比更早一条」,因为单条数字看不出变化——0.2.98 的趋势行只给整体,
|
|
1030
|
+
* 摊到某一条时,人想问的正是「这条和上一条比,是多了还是少了」。
|
|
1031
|
+
*/
|
|
1032
|
+
function expandPanel(rec, rank, seen, settled) {
|
|
1033
|
+
const row = rec.row
|
|
1034
|
+
const lines = [rowLine(row, rank)]
|
|
1035
|
+
// [macro-fusion 0.2.107] 收尾方式紧跟行,先讲清「这是跑完的轮还是半路停下的轮」,
|
|
1036
|
+
// 后面的数字才有意义。
|
|
1037
|
+
const kind = kindBlock(row)
|
|
1038
|
+
if (kind !== '') lines.push(kind)
|
|
1039
|
+
const plan = row.changes?.plan
|
|
1040
|
+
if (plan !== undefined && plan !== null) {
|
|
1041
|
+
lines.push('这一轮的数字就是上面这一行,全部来自 changes.plan。')
|
|
1042
|
+
} else if (kindOf(row).stored && !isFullRound(row)) {
|
|
1043
|
+
// [macro-fusion 0.2.107] 没跑完的账本来就没有规模数字,不是「写在 0.2.96 之前」。
|
|
1044
|
+
const kk = kindOf(row)
|
|
1045
|
+
lines.push(`这一条没有 changes.plan:这一轮不是跑完的整理(${KIND_TEXT[kk.kind] ?? kk.kind}),没有规模数字可念。`)
|
|
1046
|
+
} else {
|
|
1047
|
+
lines.push('这一条没有 changes.plan:它写在 0.2.96 之前,当时还没有记规模。')
|
|
1048
|
+
}
|
|
1049
|
+
const summary = String(row.summary ?? '').trim()
|
|
1050
|
+
lines.push(`摘要:${summary === '' ? '(这一条没有摘要)' : summary.replace(/\s+/g, ' ')}`)
|
|
1051
|
+
const note = String(row.note ?? '').trim()
|
|
1052
|
+
lines.push(`备注:${note === '' ? '(这一条没写备注)' : note}`)
|
|
1053
|
+
const names = projectNames(row)
|
|
1054
|
+
if (names === '') {
|
|
1055
|
+
// 老账本只记了个数:数不能丢,但名字确实没存,别拿摘要里的字凑一个。
|
|
1056
|
+
const legacy = projectCountOf(plan)
|
|
1057
|
+
lines.push(
|
|
1058
|
+
legacy > 0
|
|
1059
|
+
? `项目段:这条账只记了个数(${legacy} 个),没记名字——它写在 0.2.102 之前。`
|
|
1060
|
+
: '项目段:这条账没有记项目段(老记录或这一轮没涉及项目)。',
|
|
1061
|
+
)
|
|
1062
|
+
} else lines.push(`项目段:${names}`)
|
|
1063
|
+
lines.push(pairsBlock(row))
|
|
1064
|
+
// [macro-fusion 0.2.114] 疑似冲突紧跟在重复对之后:两块都是「这两条撞上了」,先看该不该合并、
|
|
1065
|
+
// 再看有没有两种说法;空串(没有 plan 的账)就不占一行。
|
|
1066
|
+
const conflictText = conflictsBlock(row, seen, settled)
|
|
1067
|
+
if (conflictText !== '') lines.push(conflictText)
|
|
1068
|
+
const storeLine = storeBlock(row)
|
|
1069
|
+
if (storeLine !== '') lines.push(storeLine)
|
|
1070
|
+
const storeNote = storeDeltaNote(row)
|
|
1071
|
+
if (storeNote !== '') lines.push(storeNote)
|
|
1072
|
+
|
|
1073
|
+
const prev = rec.prev
|
|
1074
|
+
if (prev !== null && prev !== undefined) {
|
|
1075
|
+
const cmp = compareLine(row, prev, rank + 1)
|
|
1076
|
+
if (cmp !== '') lines.push(cmp)
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
const raw = row.changes === null || row.changes === undefined ? '' : JSON.stringify(row.changes, null, 2)
|
|
1080
|
+
if (raw === '') {
|
|
1081
|
+
lines.push('变化原文:这条 changes 读不出来(坏行),所以只念它自己的摘要——不猜里面写了什么。')
|
|
1082
|
+
} else {
|
|
1083
|
+
const CAP = 1200
|
|
1084
|
+
if (raw.length > CAP) {
|
|
1085
|
+
lines.push(`变化原文(前 ${CAP} 字符,共 ${raw.length} 字符):`)
|
|
1086
|
+
lines.push(raw.slice(0, CAP))
|
|
1087
|
+
lines.push('…')
|
|
1088
|
+
} else {
|
|
1089
|
+
lines.push('变化原文:')
|
|
1090
|
+
lines.push(raw)
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return lines.join('\n')
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
/** 两条账的差:只说真正变了的段;一样就说一样(不硬凑一句好听的话)。 */
|
|
1097
|
+
function compareLine(row, prev, prevRank) {
|
|
1098
|
+
// [macro-fusion 0.2.107] 只有跑完的轮才配跟跑完的轮比:半路停下那轮的 dup/cover/missing
|
|
1099
|
+
// 是扫到那儿的中间值,拿它跟一整轮比,比出来的「变少了」是假象。
|
|
1100
|
+
const halfNow = !isFullRound(row)
|
|
1101
|
+
const halfPrev = !isFullRound(prev)
|
|
1102
|
+
if (halfNow || halfPrev) {
|
|
1103
|
+
const which = halfNow && halfPrev ? '这两条都不是完整的一轮' : halfNow ? '这一条不是完整的一轮' : `#${prevRank} 那条不是完整的一轮`
|
|
1104
|
+
return `比更早一条(#${prevRank}):${which}(没跑完 / 已封存),数字不可比。`
|
|
1105
|
+
}
|
|
1106
|
+
const pick = (r, key) => {
|
|
1107
|
+
const n = Number(r.changes?.plan?.[key])
|
|
1108
|
+
return Number.isFinite(n) ? n : null
|
|
1109
|
+
}
|
|
1110
|
+
const keys = [
|
|
1111
|
+
['dup', '逐字重复'],
|
|
1112
|
+
['cover', '重复详写'],
|
|
1113
|
+
['missing', '缺词'],
|
|
1114
|
+
['rows', '条数'],
|
|
1115
|
+
]
|
|
1116
|
+
const moved = []
|
|
1117
|
+
let comparable = 0
|
|
1118
|
+
for (const [key, name] of keys) {
|
|
1119
|
+
const a = pick(prev, key)
|
|
1120
|
+
const b = pick(row, key)
|
|
1121
|
+
if (a === null || b === null) continue
|
|
1122
|
+
comparable += 1
|
|
1123
|
+
if (a !== b) moved.push(`${name} ${a}→${b}${b > a ? '(多了)' : '(少了)'}`)
|
|
1124
|
+
}
|
|
1125
|
+
if (comparable === 0) return `比更早一条(#${prevRank}):两边都没有规模数字,不比较。`
|
|
1126
|
+
if (moved.length === 0) return `比更早一条(#${prevRank}):逐字重复 / 重复详写 / 缺词 / 条数都没变。`
|
|
1127
|
+
return `比更早一条(#${prevRank}):${moved.join('、')}。`
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* 面板正文 + 口径。
|
|
1132
|
+
* [macro-fusion 0.2.101] project:按项目段翻账(匹配 changes.plan.projects 里的名字)。
|
|
1133
|
+
* - 只在 SQL 里筛一次,页面和总数都来自同一个筛子,别在 JS 里再挑一遍(那样翻页会漏条)。
|
|
1134
|
+
* - 筛选生效时 #k 是「筛出来那几条里的第几近」,不是全账本的第几近——口径变了就得说清。
|
|
1135
|
+
* - 项目名一个都匹配不上,要报全账本有几条,而不是「账本还是空的」。
|
|
1136
|
+
* [macro-fusion 0.2.105] since / until:按日期区间筛(本机时区,闭区间,写 `2026-11-18`)。
|
|
1137
|
+
* - 行与总数一起过同一个筛子(SQL 里筛),否则「第几页」「一共几条」会各算一套。
|
|
1138
|
+
* - 筛空了要说清「这段时间里没有」还是「账本里根本没有这段」,所以带上账本覆盖范围。
|
|
1139
|
+
* - 时区必须交代:账本里存的是毫秒时间戳,屏幕上印的是本机时间,不写时区就没法核对。
|
|
1140
|
+
* @param {{workspace?: string, dir?: string, limit?: number, page?: number, id?: number, project?: string, since?: string, until?: string}} opts
|
|
1141
|
+
* @returns {{body: string, scope: string}}
|
|
1142
|
+
*/
|
|
1143
|
+
export function readDreamPanel({ workspace = '', dir = '.dsh-meow', limit = 5, page = 1, id = 0, project = '', since = '', until = '' } = {}) {
|
|
1144
|
+
const asked = Math.trunc(Number(limit))
|
|
1145
|
+
const want = Number.isFinite(asked) && asked > 0 ? Math.min(50, asked) : 5
|
|
1146
|
+
const askedPage = Math.trunc(Number(page))
|
|
1147
|
+
const wantPage = Number.isFinite(askedPage) && askedPage > 0 ? askedPage : 1
|
|
1148
|
+
// [macro-fusion 0.2.104] id 有两种写法:「3」/「#3」= 第几近(会随新账挪),「r128」= 账本引用(不挪)。
|
|
1149
|
+
const wantRef = refIdOf(id)
|
|
1150
|
+
const askedId = Math.trunc(Number(String(id ?? '').replace(/^#/, '')))
|
|
1151
|
+
const wantId = wantRef > 0 ? 0 : Number.isFinite(askedId) && askedId > 0 ? askedId : 0
|
|
1152
|
+
const wantProject = String(project ?? '').trim()
|
|
1153
|
+
// [macro-fusion 0.2.105] 日期写坏了就地打回:猜一个日期筛出来的结论,比不筛更误导。
|
|
1154
|
+
const range = rangeOf(since, until)
|
|
1155
|
+
if (range.bad !== '') return { body: `${range.bad}这次没有列账。`, scope: '按时间筛的写法被打回,账本一条没动' }
|
|
1156
|
+
const ranged = range.since > 0 || range.until > 0
|
|
1157
|
+
|
|
1158
|
+
// 按稳定引用展开:编号会挪,引用不挪,所以两条路分开走、也分开说。
|
|
1159
|
+
if (wantRef > 0) {
|
|
1160
|
+
const rec = Meow.readDreamRecordByRef(workspace, dir, wantRef)
|
|
1161
|
+
if (rec.missing === 'no-workspace') {
|
|
1162
|
+
return {
|
|
1163
|
+
body: '这个会话没有工作区(会话头里没有 cwd),读不到 dream 账本——账本按工作区存放(<工作区>/.dsh-meow/memory.db),没有工作区就没有账本可念。',
|
|
1164
|
+
scope: '',
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
if (rec.missing === 'no-db') {
|
|
1168
|
+
return { body: `这个工作区还没有记忆库(${rec.path})——不是 dream 跑过却没留痕,是这个窗口还没建过库。`, scope: '' }
|
|
1169
|
+
}
|
|
1170
|
+
if (rec.missing === 'no-row') {
|
|
1171
|
+
return {
|
|
1172
|
+
body:
|
|
1173
|
+
`账本里没有引用 r${wantRef} 的那一条(一共 ${rec.total} 条)——引用是账本行的固定号,只增不减,` +
|
|
1174
|
+
'从来不会把老号发给新账。所以要么这个号压根没写过,要么那一行已经不在了(库被重建 / 手工删过)。' +
|
|
1175
|
+
'要按位置找,就翻 page 看 #k;要按内容找,就用摘要里的字眼去搜。',
|
|
1176
|
+
scope: `账本共 ${rec.total} 条,要的是引用 r${wantRef}`,
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
if (rec.missing !== '') {
|
|
1180
|
+
return {
|
|
1181
|
+
body: `dream 账本读不出来(${rec.path}):${rec.missing.replace(/^read-failed: /, '')}——这不是「没跑过 dream」,是库在但读不开。`,
|
|
1182
|
+
scope: '',
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
const names = projectNames(rec.row)
|
|
1186
|
+
const listed = names === '' ? [] : names.split('、')
|
|
1187
|
+
const filterNote =
|
|
1188
|
+
wantProject === ''
|
|
1189
|
+
? ''
|
|
1190
|
+
: listed.includes(wantProject)
|
|
1191
|
+
? `这一条属于项目段「${wantProject}」。`
|
|
1192
|
+
: `这一条不属于项目段「${wantProject}」——它记的是${names === '' ? '没有项目段' : `「${names}」`}。展开还是照账念,只是别把它当成筛选结果。`
|
|
1193
|
+
const rankNow = rec.rank > 0 ? rec.rank : 0
|
|
1194
|
+
const settledByRef = conflictSettledOf(workspace, dir, rankNow, rec.row?.changes?.plan)
|
|
1195
|
+
const tail = `引用 r${wantRef}:这个号跟着这一行走,账本再长几轮也不挪(删了也不会被别人占用);${
|
|
1196
|
+
rankNow > 0 ? `它现在排第 ${rankNow} 近——「#k」会随新账往下挪,回指请用引用。` : '这次没算出它现在排第几近(账本刚被别的进程改过)。'
|
|
1197
|
+
}`
|
|
1198
|
+
const body = [expandPanel(rec, rankNow > 0 ? rankNow : undefined, conflictSeenOf(workspace, dir, rankNow), settledByRef), tail, rangeNoteOf(rec.row, range), filterNote]
|
|
1199
|
+
.filter((s) => s !== '')
|
|
1200
|
+
.join('\n\n')
|
|
1201
|
+
return {
|
|
1202
|
+
body,
|
|
1203
|
+
scope:
|
|
1204
|
+
`按引用 r${wantRef} 展开${rankNow > 0 ? `(现在第 ${rankNow} 近)` : ''},共 ${rec.total} 条;原文照账本念,不重算这一轮清单` +
|
|
1205
|
+
(wantProject === '' ? '' : ';引用不受项目筛选影响') +
|
|
1206
|
+
(ranged ? ';日期筛选也不影响引用' : ''),
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
// 单条展开:口径是「第几近」,1 = 最新,和列表里的 #k 同一个编号(翻页也不改)。
|
|
1211
|
+
if (wantId > 0) {
|
|
1212
|
+
const rec = Meow.readDreamRecord(workspace, dir, wantId)
|
|
1213
|
+
if (rec.missing === 'no-workspace') {
|
|
1214
|
+
return {
|
|
1215
|
+
body: '这个会话没有工作区(会话头里没有 cwd),读不到 dream 账本——账本按工作区存放(<工作区>/.dsh-meow/memory.db),没有工作区就没有账本可念。',
|
|
1216
|
+
scope: '',
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
if (rec.missing === 'no-db') {
|
|
1220
|
+
return { body: `这个工作区还没有记忆库(${rec.path})——不是 dream 跑过却没留痕,是这个窗口还没建过库。`, scope: '' }
|
|
1221
|
+
}
|
|
1222
|
+
if (rec.missing === 'no-row') {
|
|
1223
|
+
return {
|
|
1224
|
+
body:
|
|
1225
|
+
`账本里没有第 ${wantId} 条(一共 ${rec.total} 条)——编号按「第几近」算,1 是最新的一条。` +
|
|
1226
|
+
'要展开更早的,先把 page 翻到更早那几页看编号。',
|
|
1227
|
+
scope: `账本共 ${rec.total} 条,要的是第 ${wantId} 条`,
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
if (rec.missing !== '') {
|
|
1231
|
+
return {
|
|
1232
|
+
body: `dream 账本读不出来(${rec.path}):${rec.missing.replace(/^read-failed: /, '')}——这不是「没跑过 dream」,是库在但读不开。`,
|
|
1233
|
+
scope: '',
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
const names = projectNames(rec.row)
|
|
1237
|
+
const listed = names === '' ? [] : names.split('、')
|
|
1238
|
+
const filterNote =
|
|
1239
|
+
wantProject === ''
|
|
1240
|
+
? ''
|
|
1241
|
+
: listed.includes(wantProject)
|
|
1242
|
+
? `这一条属于项目段「${wantProject}」。`
|
|
1243
|
+
: `这一条不属于项目段「${wantProject}」——它记的是${names === '' ? '没有项目段' : `「${names}」`}。展开还是照账念,只是别把它当成筛选结果。`
|
|
1244
|
+
const rowRef = refOfRow(rec.row)
|
|
1245
|
+
const settledById = conflictSettledOf(workspace, dir, wantId, rec.row?.changes?.plan)
|
|
1246
|
+
const body = [expandPanel(rec, wantId, conflictSeenOf(workspace, dir, wantId), settledById), rangeNoteOf(rec.row, range), filterNote].filter((s) => s !== '').join('\n\n')
|
|
1247
|
+
return {
|
|
1248
|
+
body,
|
|
1249
|
+
scope:
|
|
1250
|
+
`展开第 ${wantId} 条(共 ${rec.total} 条${rowRef === '' ? '' : `;引用 ${rowRef},要回指就用 id=${rowRef}`});原文照账本念,不重算这一轮清单` +
|
|
1251
|
+
(wantProject === '' ? '' : `;展开的编号仍是全账本的第几近(筛选不改编号)`) +
|
|
1252
|
+
(ranged ? `;要按时间筛就翻 page 看 list` : ''),
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
const offset = (wantPage - 1) * want
|
|
1257
|
+
const ledger = Meow.readDreamLedger(workspace, dir, want, offset, wantProject, range.since, range.until)
|
|
1258
|
+
// 「全账本」= 既不看项目段、也不看日期:筛完再报「全账本 N 条」时,那个 N 不能是筛后的数。
|
|
1259
|
+
const allTotal = wantProject === '' && !ranged ? 0 : Meow.readDreamLedger(workspace, dir, 1, 0, '', 0, 0).total
|
|
1260
|
+
if (ledger.missing === 'no-workspace') {
|
|
1261
|
+
return {
|
|
1262
|
+
body:
|
|
1263
|
+
'这个会话没有工作区(会话头里没有 cwd),读不到 dream 账本——' +
|
|
1264
|
+
'dream 的账本按工作区存放(<工作区>/.dsh-meow/memory.db),没有工作区就没有账本可念。',
|
|
1265
|
+
scope: '',
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
if (ledger.missing === 'no-db') {
|
|
1269
|
+
return {
|
|
1270
|
+
body:
|
|
1271
|
+
`这个工作区还没有记忆库(${ledger.path})——不是 dream 跑过却没留痕,是这个窗口还没建过库。` +
|
|
1272
|
+
'写几条记忆、再整理一次之后再看。',
|
|
1273
|
+
scope: '',
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
if (ledger.missing !== '') {
|
|
1277
|
+
return {
|
|
1278
|
+
body: `dream 账本读不出来(${ledger.path}):${ledger.missing.replace(/^read-failed: /, '')}——这不是「没跑过 dream」,是库在但读不开。`,
|
|
1279
|
+
scope: '',
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
const total = Number(ledger.total) || 0
|
|
1283
|
+
const live = wantPage === 1 ? Meow.readLiveDream(workspace, dir) : { sessionIds: [] }
|
|
1284
|
+
const liveText = liveLine(live)
|
|
1285
|
+
if (total === 0) {
|
|
1286
|
+
// [macro-fusion 0.2.105] 按日期筛空了,和「账本还是空的」「没这个项目段」都要分开:
|
|
1287
|
+
// 这段空结果到底是「这几天没跑」还是「跑过但不在你这几天里」,只能靠账本覆盖范围说清。
|
|
1288
|
+
if (ranged) {
|
|
1289
|
+
const span = Meow.readDreamSpan(workspace, dir)
|
|
1290
|
+
const cover =
|
|
1291
|
+
span.missing === '' && span.first > 0
|
|
1292
|
+
? `账本覆盖 ${stamp(span.first)} → ${stamp(span.last)}(本机时区 ${tzLabel()})`
|
|
1293
|
+
: '账本里还没有任何一条'
|
|
1294
|
+
const who = wantProject === '' ? '' : `项目段「${wantProject}」的`
|
|
1295
|
+
const body =
|
|
1296
|
+
`${range.label} 这段时间里没有${who}整理记录——${cover}。` +
|
|
1297
|
+
(allTotal > 0
|
|
1298
|
+
? `全账本 ${allTotal} 条都在这个区间外面(since / until 按本机时区算整天,两端都含)。换一段日期再看,或者干脆不带日期翻全账本。`
|
|
1299
|
+
: '')
|
|
1300
|
+
return { body, scope: `按时间 ${range.label} 筛:0 条(全账本 ${allTotal} 条)` + (wantProject === '' ? '' : `;项目段「${wantProject}」这段时间里一条都没有`) }
|
|
1301
|
+
}
|
|
1302
|
+
// [macro-fusion 0.2.101] 筛了个没人用过的项目名,和「账本还是空的」不是一回事:
|
|
1303
|
+
// 前者说明白「全账本有 N 条,只是没有这个项目段」,后者才叫还没整理过。
|
|
1304
|
+
if (wantProject !== '') {
|
|
1305
|
+
const body =
|
|
1306
|
+
allTotal === 0
|
|
1307
|
+
? `这个工作区的 dream 账本还是空的(${ledger.path}),项目段「${wantProject}」自然也还没有记录。`
|
|
1308
|
+
: `账本里没有项目段「${wantProject}」的整理记录(全账本 ${allTotal} 条)——项目名要按 changes.plan.projects 里的原样写,别自己翻译。`
|
|
1309
|
+
return { body, scope: `按项目段「${wantProject}」筛:0 条(全账本 ${allTotal} 条)` }
|
|
1310
|
+
}
|
|
1311
|
+
const empty = `这个工作区的 dream 账本还是空的(${ledger.path})——还没跑完过 dream。在会话里触发一次整理,之后这里就会留下这一轮看到什么。`
|
|
1312
|
+
if (liveText !== '') return { body: `${liveText}\n\n${empty}`, scope: '正在整理的那一轮还没收尾,账本里暂时没有历史' }
|
|
1313
|
+
return { body: empty, scope: '' }
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
// 页码越过最后一页:不返回空白页,退到最后一页并把话说清(「页码大」不等于「没有账」)。
|
|
1317
|
+
const lastPage = Math.max(1, Math.ceil(total / want))
|
|
1318
|
+
const effectivePage = Math.min(wantPage, lastPage)
|
|
1319
|
+
const rows =
|
|
1320
|
+
effectivePage === wantPage
|
|
1321
|
+
? ledger.rows
|
|
1322
|
+
: Meow.readDreamLedger(workspace, dir, want, (effectivePage - 1) * want, wantProject, range.since, range.until).rows
|
|
1323
|
+
const firstRank = (effectivePage - 1) * want + 1
|
|
1324
|
+
const lines = rows.map((row, i) => rowLine(row, firstRank + i))
|
|
1325
|
+
const lastRank = firstRank + rows.length - 1
|
|
1326
|
+
if (liveText !== '') lines.unshift(liveText, '')
|
|
1327
|
+
|
|
1328
|
+
const scopeParts = []
|
|
1329
|
+
const filtered = wantProject !== ''
|
|
1330
|
+
if (wantPage > lastPage) {
|
|
1331
|
+
scopeParts.push(`账本只有 ${total} 条,第 ${wantPage} 页早过最后一页(第 ${lastPage} 页),这里给的是最后一页`)
|
|
1332
|
+
}
|
|
1333
|
+
// [macro-fusion 0.2.105] 筛口径要一次说全:筛了什么、筛出几条、筛子之外还有几条、时区是哪儿。
|
|
1334
|
+
const sieve = [filtered ? `项目段「${wantProject}」` : '', ranged ? `时间 ${range.label}` : ''].filter((s) => s !== '').join(' + ')
|
|
1335
|
+
if (wantPage === 1) {
|
|
1336
|
+
if (filtered || ranged) {
|
|
1337
|
+
scopeParts.push(
|
|
1338
|
+
`${ranged ? `按${sieve} 筛` : `按${sieve}筛`}:${total} 条(全账本 ${allTotal} 条),列最近 ${rows.length} 条;` +
|
|
1339
|
+
'#k 是筛出来这几条里的第几近,不是全账本序号',
|
|
1340
|
+
)
|
|
1341
|
+
if (ranged) scopeParts.push(`日期按本机时区 ${tzLabel()} 算整天,since / until 两端都含`)
|
|
1342
|
+
} else if (total <= want) {
|
|
1343
|
+
scopeParts.push(`账本里一共 ${total} 次整理记录(你要的是 ${want} 条)`)
|
|
1344
|
+
} else {
|
|
1345
|
+
scopeParts.push(`列最近 ${rows.length} 次整理记录(共 ${total} 条)`)
|
|
1346
|
+
}
|
|
1347
|
+
} else {
|
|
1348
|
+
scopeParts.push(`第 ${effectivePage} 页(每页 ${want} 条):第 ${firstRank}–${lastRank} 条`)
|
|
1349
|
+
}
|
|
1350
|
+
if (wantPage === 1) {
|
|
1351
|
+
// 项目分布只在没筛的时候给:筛完再报分布,会让人以为「分布也筛过了」。
|
|
1352
|
+
// [macro-fusion 0.2.105] 按日期筛时同理:分布是全账本的,不是这段日子的。
|
|
1353
|
+
if (!filtered && !ranged) {
|
|
1354
|
+
const projects = projectsLine(Meow.readDreamProjects(workspace, dir, 5))
|
|
1355
|
+
if (projects !== '') {
|
|
1356
|
+
lines.push('', projects)
|
|
1357
|
+
scopeParts.push('项目分布按 changes.plan.projects 数出现次数,只列前 5 个;要看某个项目的账就用 project= 筛')
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
const trend = trendLine(rows)
|
|
1361
|
+
if (trend !== '') {
|
|
1362
|
+
lines.push('', trend)
|
|
1363
|
+
scopeParts.push('趋势行只念最近这几条账里的 plan 数字,不重算这一轮清单')
|
|
1364
|
+
}
|
|
1365
|
+
// [macro-fusion 0.2.108] 总条数的净变化说不出「哪一层在膨胀」,所以层走向单独一行。
|
|
1366
|
+
// 只在这一页给(它说的也是最近这几条),翻到旧页时对不上号。
|
|
1367
|
+
const levels = levelTrendLine(rows)
|
|
1368
|
+
if (levels !== '') {
|
|
1369
|
+
lines.push('', levels)
|
|
1370
|
+
scopeParts.push('层走向按每一轮收尾时的 storeEnd.byLevel 数,只有 0.2.106 之后的账有这一格')
|
|
1371
|
+
}
|
|
1372
|
+
// [macro-fusion 0.2.111] 层走向说不出「哪个项目在膨胀」:Alpha 涨 3、Beta 掉 3,fact 净数没变。
|
|
1373
|
+
// 同一页、同一批行、同一套「只吃跑完的轮」的规矩,紧跟在层走向之后念。
|
|
1374
|
+
const projectsTrend = projectTrendLine(rows)
|
|
1375
|
+
if (projectsTrend !== '') {
|
|
1376
|
+
lines.push('', projectsTrend)
|
|
1377
|
+
scopeParts.push('项目走向按每一轮收尾时的 storeEnd.byProject 数,只有 0.2.111 之后的账有这一格')
|
|
1378
|
+
}
|
|
1379
|
+
// [macro-fusion 0.2.104] 只在这一页说一次:账本越长越需要「叫得住的名字」,
|
|
1380
|
+
// 但每行都解释一遍等于拿 token 换噪音。
|
|
1381
|
+
if (rows.some((r) => refOfRow(r) !== '')) {
|
|
1382
|
+
lines.push('', '引用:每行末尾的 r<N> 是这一行的固定号——要回指某一轮就写 id=r<N>;#k 只是它此刻排第几,新账一来就挪。')
|
|
1383
|
+
scopeParts.push('引用 r<N> 只增不减,回指某一轮用它;#k 是当下的第几近')
|
|
1384
|
+
}
|
|
1385
|
+
} else {
|
|
1386
|
+
scopeParts.push('趋势行只在第 1 页出——它说的是最近几次,翻到旧页看它对不上号')
|
|
1387
|
+
}
|
|
1388
|
+
if (total > want) {
|
|
1389
|
+
const nav = []
|
|
1390
|
+
if (effectivePage > 1) nav.push(`上一页 page=${effectivePage - 1}`)
|
|
1391
|
+
if (effectivePage < lastPage) nav.push(`下一页 page=${effectivePage + 1}`)
|
|
1392
|
+
nav.push(sieve === '' ? `共 ${total} 条 · 每页 ${want} 条` : `共 ${total} 条(${sieve})· 每页 ${want} 条`)
|
|
1393
|
+
lines.push('', nav.join(' · '))
|
|
1394
|
+
scopeParts.push(`翻页口径:page 从 1 起,每页 ${want} 条,编号 ${firstRank}–${lastRank} 跨页连续`)
|
|
1395
|
+
}
|
|
1396
|
+
if (liveText !== '') scopeParts.push('第一行是正在整理的那一轮,规模读的是 dreamdigest,不是账本')
|
|
1397
|
+
return { body: lines.join('\n'), scope: scopeParts.join(';') }
|
|
1398
|
+
}
|