dsh-memu-memory 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -0
- package/CHANGELOG.md +36 -0
- package/README.md +4 -1
- package/README.zh.md +4 -1
- package/docs/client-conventions.md +3 -0
- package/docs/mcp-porting.md +146 -0
- package/docs/memory-semantics.md +4 -2
- package/docs/troubleshooting.md +40 -0
- package/lib/binding-diagnostics.js +1 -1
- package/lib/client.js +223 -120
- package/lib/consolidation-worker.js +11 -3
- package/lib/curator.js +16 -4
- package/lib/cycle.js +75 -4
- package/lib/engine.js +68 -0
- package/lib/index.js +4 -2
- package/lib/inject.js +142 -8
- package/lib/memory.js +123 -21
- package/lib/port-surface.js +82 -0
- package/lib/private.js +49 -13
- package/lib/prompts/private-consolidation.coding.md +3 -1
- package/lib/prompts/private-consolidation.md +2 -0
- package/lib/prompts/private-consolidation.mixed.md +2 -0
- package/lib/prompts/private-consolidation.rp.md +2 -0
- package/lib/prompts/system-guide.coding.md +8 -2
- package/lib/prompts/system-guide.md +6 -0
- package/lib/prompts/system-guide.mixed.md +11 -0
- package/lib/prompts/system-guide.rp.md +6 -0
- package/lib/rpc.js +19 -5
- package/lib/tools.js +25 -0
- package/lib/turn-log.js +34 -11
- package/lib/worker-pool.js +11 -7
- package/package.json +2 -1
- package/tests/browser.test.mjs +21 -0
- package/tests/client-export.test.mjs +1 -0
- package/tests/client-render.test.mjs +1 -0
- package/tests/consolidation-fork.test.mjs +20 -1
- package/tests/curator-probe.test.mjs +19 -1
- package/tests/engine.test.mjs +60 -0
- package/tests/help-page.test.mjs +1 -0
- package/tests/inject-guide.test.mjs +108 -1
- package/tests/new-session-gate.test.mjs +1 -0
- package/tests/port-surface.test.mjs +138 -0
- package/tests/prompts.test.mjs +30 -0
- package/tests/react-snapshot.test.mjs +1 -0
- package/tests/salience-domain.test.mjs +34 -0
- package/tests/settings-beat.test.mjs +1 -0
- package/tests/sidebar-beat.test.mjs +1 -0
- package/tests/stale-maintenance.test.mjs +131 -0
- package/tests/turn-log.test.mjs +13 -0
- package/tests/webui.test.mjs +8 -1
package/lib/client.js
CHANGED
|
@@ -279,7 +279,7 @@ window.__ModuleLoader__.load({
|
|
|
279
279
|
poolReview: '待复核',
|
|
280
280
|
poolInactive: '已失效',
|
|
281
281
|
wallReadError: '部分记忆库读取失败',
|
|
282
|
-
wallLimit: '
|
|
282
|
+
wallLimit: '超出单次读取上限,其余未显示',
|
|
283
283
|
wallScopePrivate: '私有',
|
|
284
284
|
wallScopeGlobal: '全局',
|
|
285
285
|
wallFilterScope: '范围',
|
|
@@ -727,6 +727,8 @@ window.__ModuleLoader__.load({
|
|
|
727
727
|
browseSearch: '搜索本库',
|
|
728
728
|
browseSearchPlaceholder: '按标题、正文、ID 或标签过滤当前记忆库…',
|
|
729
729
|
browseSearchClear: '清空',
|
|
730
|
+
browseLoadMore: '显示更多',
|
|
731
|
+
browseLoadingFull: '正在加载完整正文…',
|
|
730
732
|
// Enum display labels. Stored values stay English; only these flip with locale.
|
|
731
733
|
layerLongTerm: '长期记忆',
|
|
732
734
|
layerAnchor: '锚点记忆',
|
|
@@ -1268,7 +1270,7 @@ window.__ModuleLoader__.load({
|
|
|
1268
1270
|
poolReview: 'Review',
|
|
1269
1271
|
poolInactive: 'Inactive',
|
|
1270
1272
|
wallReadError: 'Some libraries could not be read',
|
|
1271
|
-
wallLimit: '
|
|
1273
|
+
wallLimit: 'Beyond the single-read cap; the rest is not shown',
|
|
1272
1274
|
wallScopePrivate: 'Private',
|
|
1273
1275
|
wallScopeGlobal: 'Global',
|
|
1274
1276
|
wallFilterScope: 'Scope',
|
|
@@ -1716,6 +1718,8 @@ window.__ModuleLoader__.load({
|
|
|
1716
1718
|
browseSearch: 'Search this library',
|
|
1717
1719
|
browseSearchPlaceholder: 'Filter the current library by title, body, id or tags…',
|
|
1718
1720
|
browseSearchClear: 'Clear',
|
|
1721
|
+
browseLoadMore: 'Show more',
|
|
1722
|
+
browseLoadingFull: 'Loading full text…',
|
|
1719
1723
|
layerLongTerm: 'Long-term',
|
|
1720
1724
|
layerAnchor: 'Anchor',
|
|
1721
1725
|
layerMustRemember: 'Permanent',
|
|
@@ -3193,6 +3197,127 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
3193
3197
|
item.hidden ? null : h('figcaption', null, item.caption || '[图片]')))) : null)
|
|
3194
3198
|
}
|
|
3195
3199
|
|
|
3200
|
+
// 一张可编辑的记忆卡。draft 下沉到卡片内部:浏览页可能有几百张卡,输入时
|
|
3201
|
+
// 若把草稿放在父级 state,每敲一个字都要重渲染整个列表(2026-11-28 的卡顿
|
|
3202
|
+
// 现场)。memo 之后只有被编辑的那一张会重画。
|
|
3203
|
+
const BrowserMemoryCard = React.memo(function BrowserMemoryCard({ file: f, t, busy, browseBusy, onSave, onArchive, onResolve, onLoadFull }) {
|
|
3204
|
+
const [draft, setDraft] = React.useState({})
|
|
3205
|
+
// 列表只带截断后的正文。第一次聚焦正文输入框时补拉全文,否则用户改一个字
|
|
3206
|
+
// 保存就会把尾部写丢。拉取期间输入框只读,避免在截断版上先打字。
|
|
3207
|
+
const [fullContent, setFullContent] = React.useState(null)
|
|
3208
|
+
const [loadingFull, setLoadingFull] = React.useState(false)
|
|
3209
|
+
const set = (key, value) => setDraft((prev) => ({ ...prev, [key]: value }))
|
|
3210
|
+
const ensureFull = async () => {
|
|
3211
|
+
if (!f.truncated || fullContent !== null || loadingFull) return
|
|
3212
|
+
setLoadingFull(true)
|
|
3213
|
+
try {
|
|
3214
|
+
const text = await onLoadFull(f)
|
|
3215
|
+
if (typeof text === 'string') setFullContent(text)
|
|
3216
|
+
} catch (error) {
|
|
3217
|
+
// 拉不到就退回截断显示;至少留一条可查的信号,不静默。
|
|
3218
|
+
try { console.warn('dsh-memu-memory: full body load failed', f.id, error?.message || error) } catch {}
|
|
3219
|
+
} finally { setLoadingFull(false) }
|
|
3220
|
+
}
|
|
3221
|
+
// 有构成就讲构成;没有就回到旧的单值标签,老条目照旧可读。
|
|
3222
|
+
const moodText = emotionTagText(f.emotion)
|
|
3223
|
+
|| (typeof f.moodValence === 'number' && f.moodValence !== 0 ? f.moodValence.toFixed(2) : '')
|
|
3224
|
+
return h('div', { style: S.item },
|
|
3225
|
+
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8, alignItems: 'center' } },
|
|
3226
|
+
h('div', { style: S.row },
|
|
3227
|
+
h(Tag, null, enumText(t, LAYER_LABELS, f.layer || 'long_term')),
|
|
3228
|
+
f.marginalized ? h(Tag, null, t('marginalizedTag')) : null,
|
|
3229
|
+
f.openLoop ? h(Tag, null, t('openLoopTag')) : null,
|
|
3230
|
+
// What the memory is allowed to do with itself. Hiding these in the data
|
|
3231
|
+
// meant the only way to notice a misfiled "never say out loud" was to
|
|
3232
|
+
// open the JSON.
|
|
3233
|
+
f.disclosure && f.disclosure !== 'can_tell'
|
|
3234
|
+
? h(Tag, { tone: f.disclosure === 'never_say' ? 'warn' : 'info' }, enumText(t, DISCLOSURE_LABELS, f.disclosure))
|
|
3235
|
+
: null,
|
|
3236
|
+
f.visibility === 'secret' ? h(Tag, { tone: 'warn' }, enumText(t, VISIBILITY_LABELS, 'secret')) : null,
|
|
3237
|
+
// Provenance, always shown here: the browser is where you audit a memory,
|
|
3238
|
+
// so "where did this come from" is not an optional detail. A quote and an
|
|
3239
|
+
// inference read identically once injected — this tag is the difference.
|
|
3240
|
+
h(Tag, { tone: f.source === 'imagined' ? 'warn' : (f.source === 'user_said' ? 'info' : undefined) },
|
|
3241
|
+
enumText(t, SOURCE_LABELS, f.source || 'inferred')),
|
|
3242
|
+
f.owner === 'about_user' ? h(Tag, { tone: 'info' }, enumText(t, OWNER_LABELS, 'about_user')) : null,
|
|
3243
|
+
// Keep the year: a deadline sliced from offset 5 reads "10-29 14:30", which
|
|
3244
|
+
// is indistinguishable from a stale entry once the year turns over.
|
|
3245
|
+
f.expiresAt ? h(Tag, null, `${t('shortTermExpires')} ${String(f.expiresAt).slice(0, 16).replace('T', ' ')}`) : null,
|
|
3246
|
+
f.peak ? h(Tag, null, t('peakTag')) : null,
|
|
3247
|
+
// A dated memory is an appointment, not an anniversary; the tag has to
|
|
3248
|
+
// say which, because only one of them means "this happens every year".
|
|
3249
|
+
f.salientDate
|
|
3250
|
+
? h(Tag, null, `${/^\d{4}-\d{2}-\d{2}$/.test(f.salientDate) ? t('dueDateTag') : t('anniversaryTag')} ${f.salientDate}`)
|
|
3251
|
+
: null,
|
|
3252
|
+
// 四轴构成放在 Tag 里;激活/掌控/来源直接可见,不再只藏在悬停提示里。
|
|
3253
|
+
moodText ? h(Tag, null, `${t('moodTag')} ${moodText}`) : null,
|
|
3254
|
+
emotionMetaText(f, t) ? h('span', { style: S.muted }, emotionMetaText(f, t)) : null,
|
|
3255
|
+
typeof f.accuracy === 'number' && typeof f.confidence === 'number' && f.accuracy <= 0.6 && f.accuracy < f.confidence - 0.1
|
|
3256
|
+
? h(Tag, { tone: 'warn' }, `${t('accuracyTag')} ${f.accuracy}`) : null,
|
|
3257
|
+
h(Tag, null, enumText(t, STATUS_LABELS, f.status || 'active'))),
|
|
3258
|
+
h('div', { style: { display: 'flex', gap: 6, flexShrink: 0 } },
|
|
3259
|
+
// 待复核条目在这里就能拍板,不必绕去全局页的复核队列;
|
|
3260
|
+
// resolution 沿用复核草稿(缺省 replace),与全局队列同一 RPC。
|
|
3261
|
+
f.status === 'pending_review'
|
|
3262
|
+
? h(Button, { onClick: () => onResolve(f.id, 'accept'), disabled: busy || browseBusy, primary: true }, t('accept'))
|
|
3263
|
+
: null,
|
|
3264
|
+
f.status === 'pending_review'
|
|
3265
|
+
? h(Button, { onClick: () => onResolve(f.id, 'reject'), disabled: busy || browseBusy, style: S.ghost }, t('reject'))
|
|
3266
|
+
: null,
|
|
3267
|
+
h(Button, { onClick: () => onSave(f.id, draft), disabled: busy || browseBusy }, t('save')),
|
|
3268
|
+
h(Button, { onClick: () => onArchive(f.id), disabled: busy || browseBusy, style: S.ghost }, t('archive')))),
|
|
3269
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, margin: '8px 0 4px' } },
|
|
3270
|
+
h('span', { style: { ...S.muted, minWidth: 72 } }, t('decay')),
|
|
3271
|
+
h(Bar, { value: f.decay, title: `${Math.round((Number(f.decay) || 0) * 100)}%` }),
|
|
3272
|
+
h('span', { style: S.muted }, f.lastAccessAt
|
|
3273
|
+
? `${t('accessed')}: ${String(f.lastAccessAt).slice(0, 10)}`
|
|
3274
|
+
: t('neverAccessed'))),
|
|
3275
|
+
h(MemoryAttachments, { items: f.attachments, t }),
|
|
3276
|
+
h('input', {
|
|
3277
|
+
style: { ...S.input, width: '100%', marginTop: 8 },
|
|
3278
|
+
value: draft.title ?? f.title ?? '', placeholder: t('name'),
|
|
3279
|
+
onChange: (e) => set('title', e.target.value),
|
|
3280
|
+
}),
|
|
3281
|
+
h('textarea', {
|
|
3282
|
+
style: { ...S.textarea, marginTop: 6, minHeight: 90 },
|
|
3283
|
+
value: draft.content ?? fullContent ?? f.content ?? '',
|
|
3284
|
+
readOnly: loadingFull,
|
|
3285
|
+
title: loadingFull ? t('browseLoadingFull') : undefined,
|
|
3286
|
+
onFocus: () => { void ensureFull() },
|
|
3287
|
+
onChange: (e) => set('content', e.target.value),
|
|
3288
|
+
}),
|
|
3289
|
+
h('input', {
|
|
3290
|
+
style: { ...S.input, width: '100%', marginTop: 6 },
|
|
3291
|
+
value: (draft.tags ?? f.tags ?? []).join(', '), placeholder: 'tag1, tag2',
|
|
3292
|
+
onChange: (e) => set('tags', e.target.value.split(',').map((x) => x.trim()).filter(Boolean)),
|
|
3293
|
+
}),
|
|
3294
|
+
h('div', { style: { display: 'flex', gap: 6, marginTop: 6, flexWrap: 'wrap' } },
|
|
3295
|
+
h('select', {
|
|
3296
|
+
style: { ...S.input, flex: '1 1 120px', minWidth: 0 },
|
|
3297
|
+
title: t('disclosureLabel'),
|
|
3298
|
+
value: draft.disclosure ?? f.disclosure ?? 'can_tell',
|
|
3299
|
+
onChange: (e) => set('disclosure', e.target.value),
|
|
3300
|
+
}, ['can_tell', 'only_if_asked', 'never_say'].map((v) => h('option', { key: v, value: v }, enumText(t, DISCLOSURE_LABELS, v)))),
|
|
3301
|
+
h('select', {
|
|
3302
|
+
style: { ...S.input, flex: '1 1 110px', minWidth: 0 },
|
|
3303
|
+
title: t('ownerLabel'),
|
|
3304
|
+
value: draft.owner ?? f.owner ?? 'me',
|
|
3305
|
+
onChange: (e) => set('owner', e.target.value),
|
|
3306
|
+
}, ['me', 'us', 'about_user', 'about_project'].map((v) => h('option', { key: v, value: v }, enumText(t, OWNER_LABELS, v)))),
|
|
3307
|
+
h('select', {
|
|
3308
|
+
style: { ...S.input, flex: '1 1 110px', minWidth: 0 },
|
|
3309
|
+
title: t('visibilityLabel'),
|
|
3310
|
+
value: draft.visibility ?? f.visibility ?? 'shared',
|
|
3311
|
+
onChange: (e) => set('visibility', e.target.value),
|
|
3312
|
+
}, ['shared', 'secret'].map((v) => h('option', { key: v, value: v }, enumText(t, VISIBILITY_LABELS, v)))),
|
|
3313
|
+
h('select', {
|
|
3314
|
+
style: { ...S.input, flex: '1 1 110px', minWidth: 0 },
|
|
3315
|
+
title: t('sourceLabel'),
|
|
3316
|
+
value: draft.source ?? f.source ?? 'inferred',
|
|
3317
|
+
onChange: (e) => set('source', e.target.value),
|
|
3318
|
+
}, ['user_said', 'inferred', 'imagined', 'told'].map((v) => h('option', { key: v, value: v }, enumText(t, SOURCE_LABELS, v))))))
|
|
3319
|
+
})
|
|
3320
|
+
|
|
3196
3321
|
function VisionConfigPanel({ call, config, t }) {
|
|
3197
3322
|
const [message, setMessage] = React.useState('')
|
|
3198
3323
|
const [busy, setBusy] = React.useState(false)
|
|
@@ -4602,12 +4727,38 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4602
4727
|
let alive = true
|
|
4603
4728
|
const requestId = ++browseRequest.current
|
|
4604
4729
|
const current = () => alive && requestId === browseRequest.current
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4730
|
+
// 整库流式读取:首批立即上屏,之后逐批追加。记忆墙原先在 300 条处截断,
|
|
4731
|
+
// 读者看到的是“最近 300 条”而不是自己的库(2026-11-28)。每批之间让出
|
|
4732
|
+
// 一帧,卡片一批批出现,而不是最后一起跳出来。
|
|
4733
|
+
const stream = async (targetLibraryId) => {
|
|
4734
|
+
let items = []
|
|
4735
|
+
let total = 0
|
|
4736
|
+
let batches = 0
|
|
4737
|
+
for (;;) {
|
|
4738
|
+
// 活锁保护:库在读取过程中被持续写入时 total 会一直变大,没有这条上限
|
|
4739
|
+
// 这个循环可以永远转下去。40 批 × 300 = 12000 条,远超正常库规模,
|
|
4740
|
+
// 真的到顶就停在这里(界面会显示「超出单次读取上限」)。
|
|
4741
|
+
if (++batches > 40) return
|
|
4742
|
+
const value = await call('browseWall', {
|
|
4743
|
+
libraryId: targetLibraryId || null,
|
|
4744
|
+
limit: 300,
|
|
4745
|
+
offset: items.length,
|
|
4746
|
+
domain: wallDomain || undefined,
|
|
4747
|
+
})
|
|
4608
4748
|
if (!current()) return
|
|
4609
|
-
|
|
4749
|
+
const batch = Array.isArray(value?.items) ? value.items : []
|
|
4750
|
+
items = items.concat(batch)
|
|
4751
|
+
total = Number(value?.total) || items.length
|
|
4752
|
+
setData({ ...value, items, total })
|
|
4610
4753
|
setError('')
|
|
4754
|
+
if (!batch.length || items.length >= total) return
|
|
4755
|
+
await new Promise(resolve => setTimeout(resolve, 0))
|
|
4756
|
+
if (!current()) return
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
const load = async () => {
|
|
4760
|
+
try {
|
|
4761
|
+
await stream(libraryId)
|
|
4611
4762
|
} catch (failure) {
|
|
4612
4763
|
if (!current()) return
|
|
4613
4764
|
const message = String(failure?.message || failure)
|
|
@@ -4616,12 +4767,10 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4616
4767
|
// 不再整页空。用户可手动切换库;多库选项保留为禁用。
|
|
4617
4768
|
if (!libraryId && firstLibraryId && /forbidden|403/i.test(message)) {
|
|
4618
4769
|
try {
|
|
4619
|
-
|
|
4770
|
+
await stream(firstLibraryId)
|
|
4620
4771
|
// A newer selection owns the wall now; do not force the reader
|
|
4621
4772
|
// back to the first library from a fallback they did not ask for.
|
|
4622
4773
|
if (!current()) return
|
|
4623
|
-
setData(value)
|
|
4624
|
-
setError('')
|
|
4625
4774
|
setMultiBlocked(true)
|
|
4626
4775
|
setLibraryId(firstLibraryId)
|
|
4627
4776
|
return
|
|
@@ -5813,7 +5962,13 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
5813
5962
|
const browseLibraryRequest = React.useRef(0)
|
|
5814
5963
|
const reviewsRequest = React.useRef(0)
|
|
5815
5964
|
const statsRequest = React.useRef(0)
|
|
5816
|
-
|
|
5965
|
+
// 浏览页一次挂载多少张卡:先 60 张,滚到底自动追加。几百张卡一次性建完
|
|
5966
|
+
// 会明显卡(每张卡有 6 个可编辑控件),而它们之间没有共享状态。
|
|
5967
|
+
const [browseShown, setBrowseShown] = React.useState(60)
|
|
5968
|
+
const browseMoreRef = React.useRef(null)
|
|
5969
|
+
// 渲染期写入、effect 只读:archShown 在 loading 分支之后才定义,而 hook
|
|
5970
|
+
// 顺序契约要求 effect 必须放在那之前(见下方 Hook order 注释)。
|
|
5971
|
+
const browseTotalRef = React.useRef(0)
|
|
5817
5972
|
const [browseBusy, setBrowseBusy] = React.useState(false)
|
|
5818
5973
|
// 'active' | 'archived'. Archiving used to be a one-way door in the UI: the entry
|
|
5819
5974
|
// stayed in the same list with a different tag, so the mess you were trying to
|
|
@@ -5821,6 +5976,19 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
5821
5976
|
const [browseView, setBrowseView] = React.useState('active')
|
|
5822
5977
|
// 当前库内的即时过滤:列表本来就已取回(browseLibrary),不再加一次 RPC。
|
|
5823
5978
|
const [browseQuery, setBrowseQuery] = React.useState('')
|
|
5979
|
+
// 滚到底部自动追加下一批卡片(依赖排在 browseView/browseQuery 之后,否则
|
|
5980
|
+
// 依赖数组会踩到 TDZ)。IntersectionObserver 不可用时退回「显示更多」按钮。
|
|
5981
|
+
React.useEffect(() => {
|
|
5982
|
+
const node = browseMoreRef.current
|
|
5983
|
+
if (!node || typeof IntersectionObserver !== 'function') return undefined
|
|
5984
|
+
const observer = new IntersectionObserver((entries) => {
|
|
5985
|
+
if (entries.some((entry) => entry.isIntersecting)) {
|
|
5986
|
+
setBrowseShown((count) => Math.min(count + 120, browseTotalRef.current || count + 120))
|
|
5987
|
+
}
|
|
5988
|
+
}, { rootMargin: '600px 0px' })
|
|
5989
|
+
observer.observe(node)
|
|
5990
|
+
return () => observer.disconnect()
|
|
5991
|
+
}, [browseShown, browseView, browseQuery, browseLibId])
|
|
5824
5992
|
// Permanent deletion is two clicks, and only for the row that was armed.
|
|
5825
5993
|
const [deleteArmed, setDeleteArmed] = React.useState('')
|
|
5826
5994
|
React.useEffect(() => {
|
|
@@ -6429,7 +6597,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6429
6597
|
if (requestId !== browseLibraryRequest.current) return
|
|
6430
6598
|
setBrowseFiles(res?.files || [])
|
|
6431
6599
|
setBrowseSource(res?.source || 'engine')
|
|
6432
|
-
|
|
6600
|
+
setBrowseShown(60)
|
|
6433
6601
|
setDeleteArmed('')
|
|
6434
6602
|
} catch (e) { if (requestId === browseLibraryRequest.current) setError(String(e?.message || e)) } finally { if (requestId === browseLibraryRequest.current) setBrowseBusy(false) }
|
|
6435
6603
|
}
|
|
@@ -6493,9 +6661,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6493
6661
|
await openBrowser(browseLibId)
|
|
6494
6662
|
} catch (e) { setError(String(e?.message || e)) } finally { setBrowseBusy(false) }
|
|
6495
6663
|
}
|
|
6496
|
-
const saveMemory = async (id) => {
|
|
6497
|
-
|
|
6498
|
-
if (Object.keys(patch).length === 0) return
|
|
6664
|
+
const saveMemory = async (id, patch) => {
|
|
6665
|
+
if (!patch || Object.keys(patch).length === 0) return
|
|
6499
6666
|
setBrowseBusy(true)
|
|
6500
6667
|
try {
|
|
6501
6668
|
await call('updateMemory', { libraryId: browseLibId, id, patch })
|
|
@@ -6551,6 +6718,23 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6551
6718
|
if (item.libraryId && browseLibId === item.libraryId) await openBrowser(item.libraryId)
|
|
6552
6719
|
} catch (e) { setError(String(e?.message || e)) } finally { setBusy(false) }
|
|
6553
6720
|
}
|
|
6721
|
+
// 卡片回调必须引用稳定,否则 React.memo 在每次父渲染时都会失效。动作实现
|
|
6722
|
+
// 放在 ref 里(它们依赖本轮闭包中的 call / browseLibId),组件只拿恒定的转发器。
|
|
6723
|
+
const cardActionsRef = React.useRef({})
|
|
6724
|
+
cardActionsRef.current = {
|
|
6725
|
+
save: saveMemory,
|
|
6726
|
+
archive: archiveMemory,
|
|
6727
|
+
resolve: (id, kind) => resolveReview({ id, libraryId: browseLibId }, kind),
|
|
6728
|
+
// 列表只带截断正文,编辑前按需补全文(getMemory 读 sidecar 索引,不起引擎)。
|
|
6729
|
+
loadFull: async (file) => {
|
|
6730
|
+
const res = await call('getMemory', { libraryId: file.libraryId || browseLibId, id: file.id })
|
|
6731
|
+
return res?.entry?.content ?? ''
|
|
6732
|
+
},
|
|
6733
|
+
}
|
|
6734
|
+
const cardSave = React.useCallback((id, patch) => cardActionsRef.current.save(id, patch), [])
|
|
6735
|
+
const cardArchive = React.useCallback((id) => cardActionsRef.current.archive(id), [])
|
|
6736
|
+
const cardResolve = React.useCallback((id, kind) => cardActionsRef.current.resolve(id, kind), [])
|
|
6737
|
+
const cardLoadFull = React.useCallback((file) => cardActionsRef.current.loadFull(file), [])
|
|
6554
6738
|
// 撤销集合合并(spec §4.11 undo-absorb / §6.7 UI):全局元数据动作,不带
|
|
6555
6739
|
// libraryId;两段确认由 actionLabel/confirmAction 承担。成功后刷新全局列表。
|
|
6556
6740
|
const undoAbsorb = async (id) => {
|
|
@@ -7816,108 +8000,6 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
7816
8000
|
: null),
|
|
7817
8001
|
promptPageBody))
|
|
7818
8002
|
|
|
7819
|
-
const renderBrowserItem = (f) => {
|
|
7820
|
-
const draft = browseDraft[f.id] || {}
|
|
7821
|
-
const set = (key, value) => setBrowseDraft((prev) => ({
|
|
7822
|
-
...prev, [f.id]: { ...(prev[f.id] || {}), [key]: value },
|
|
7823
|
-
}))
|
|
7824
|
-
// 有构成就讲构成;没有就回到旧的单值标签,老条目照旧可读。
|
|
7825
|
-
const moodText = emotionTagText(f.emotion)
|
|
7826
|
-
|| (typeof f.moodValence === 'number' && f.moodValence !== 0 ? f.moodValence.toFixed(2) : '')
|
|
7827
|
-
return h('div', { key: f.id, style: S.item },
|
|
7828
|
-
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8, alignItems: 'center' } },
|
|
7829
|
-
h('div', { style: S.row },
|
|
7830
|
-
h(Tag, null, enumText(t, LAYER_LABELS, f.layer || 'long_term')),
|
|
7831
|
-
f.marginalized ? h(Tag, null, t('marginalizedTag')) : null,
|
|
7832
|
-
f.openLoop ? h(Tag, null, t('openLoopTag')) : null,
|
|
7833
|
-
// What the memory is allowed to do with itself. Hiding these in the data
|
|
7834
|
-
// meant the only way to notice a misfiled "never say out loud" was to
|
|
7835
|
-
// open the JSON.
|
|
7836
|
-
f.disclosure && f.disclosure !== 'can_tell'
|
|
7837
|
-
? h(Tag, { tone: f.disclosure === 'never_say' ? 'warn' : 'info' }, enumText(t, DISCLOSURE_LABELS, f.disclosure))
|
|
7838
|
-
: null,
|
|
7839
|
-
f.visibility === 'secret' ? h(Tag, { tone: 'warn' }, enumText(t, VISIBILITY_LABELS, 'secret')) : null,
|
|
7840
|
-
// Provenance, always shown here: the browser is where you audit a memory,
|
|
7841
|
-
// so "where did this come from" is not an optional detail. A quote and an
|
|
7842
|
-
// inference read identically once injected — this tag is the difference.
|
|
7843
|
-
h(Tag, { tone: f.source === 'imagined' ? 'warn' : (f.source === 'user_said' ? 'info' : undefined) },
|
|
7844
|
-
enumText(t, SOURCE_LABELS, f.source || 'inferred')),
|
|
7845
|
-
f.owner === 'about_user' ? h(Tag, { tone: 'info' }, enumText(t, OWNER_LABELS, 'about_user')) : null,
|
|
7846
|
-
// Keep the year: a deadline sliced from offset 5 reads "10-29 14:30", which
|
|
7847
|
-
// is indistinguishable from a stale entry once the year turns over.
|
|
7848
|
-
f.expiresAt ? h(Tag, null, `${t('shortTermExpires')} ${String(f.expiresAt).slice(0, 16).replace('T', ' ')}`) : null,
|
|
7849
|
-
f.peak ? h(Tag, null, t('peakTag')) : null,
|
|
7850
|
-
// A dated memory is an appointment, not an anniversary; the tag has to
|
|
7851
|
-
// say which, because only one of them means "this happens every year".
|
|
7852
|
-
f.salientDate
|
|
7853
|
-
? h(Tag, null, `${/^\d{4}-\d{2}-\d{2}$/.test(f.salientDate) ? t('dueDateTag') : t('anniversaryTag')} ${f.salientDate}`)
|
|
7854
|
-
: null,
|
|
7855
|
-
// 四轴构成放在 Tag 里;激活/掌控/来源直接可见,不再只藏在悬停提示里。
|
|
7856
|
-
moodText ? h(Tag, null, `${t('moodTag')} ${moodText}`) : null,
|
|
7857
|
-
emotionMetaText(f, t) ? h('span', { style: S.muted }, emotionMetaText(f, t)) : null,
|
|
7858
|
-
typeof f.accuracy === 'number' && typeof f.confidence === 'number' && f.accuracy <= 0.6 && f.accuracy < f.confidence - 0.1
|
|
7859
|
-
? h(Tag, { tone: 'warn' }, `${t('accuracyTag')} ${f.accuracy}`) : null,
|
|
7860
|
-
h(Tag, null, enumText(t, STATUS_LABELS, f.status || 'active'))),
|
|
7861
|
-
h('div', { style: { display: 'flex', gap: 6, flexShrink: 0 } },
|
|
7862
|
-
// 待复核条目在这里就能拍板,不必绕去全局页的复核队列;
|
|
7863
|
-
// resolution 沿用复核草稿(缺省 replace),与全局队列同一 RPC。
|
|
7864
|
-
f.status === 'pending_review'
|
|
7865
|
-
? h(Button, { onClick: () => resolveReview({ id: f.id, libraryId: browseLibId }, 'accept'), disabled: busy || browseBusy, primary: true }, t('accept'))
|
|
7866
|
-
: null,
|
|
7867
|
-
f.status === 'pending_review'
|
|
7868
|
-
? h(Button, { onClick: () => resolveReview({ id: f.id, libraryId: browseLibId }, 'reject'), disabled: busy || browseBusy, style: S.ghost }, t('reject'))
|
|
7869
|
-
: null,
|
|
7870
|
-
h(Button, { onClick: () => saveMemory(f.id), disabled: busy || browseBusy }, t('save')),
|
|
7871
|
-
h(Button, { onClick: () => archiveMemory(f.id), disabled: busy || browseBusy, style: S.ghost }, t('archive')))),
|
|
7872
|
-
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, margin: '8px 0 4px' } },
|
|
7873
|
-
h('span', { style: { ...S.muted, minWidth: 72 } }, t('decay')),
|
|
7874
|
-
h(Bar, { value: f.decay, title: `${Math.round((Number(f.decay) || 0) * 100)}%` }),
|
|
7875
|
-
h('span', { style: S.muted }, f.lastAccessAt
|
|
7876
|
-
? `${t('accessed')}: ${String(f.lastAccessAt).slice(0, 10)}`
|
|
7877
|
-
: t('neverAccessed'))),
|
|
7878
|
-
h(MemoryAttachments, { items: f.attachments, t }),
|
|
7879
|
-
h('input', {
|
|
7880
|
-
style: { ...S.input, width: '100%', marginTop: 8 },
|
|
7881
|
-
value: draft.title ?? f.title ?? '', placeholder: t('name'),
|
|
7882
|
-
onChange: (e) => set('title', e.target.value),
|
|
7883
|
-
}),
|
|
7884
|
-
h('textarea', {
|
|
7885
|
-
style: { ...S.textarea, marginTop: 6, minHeight: 90 },
|
|
7886
|
-
value: draft.content ?? f.content ?? '',
|
|
7887
|
-
onChange: (e) => set('content', e.target.value),
|
|
7888
|
-
}),
|
|
7889
|
-
h('input', {
|
|
7890
|
-
style: { ...S.input, width: '100%', marginTop: 6 },
|
|
7891
|
-
value: (draft.tags ?? f.tags ?? []).join(', '), placeholder: 'tag1, tag2',
|
|
7892
|
-
onChange: (e) => set('tags', e.target.value.split(',').map((x) => x.trim()).filter(Boolean)),
|
|
7893
|
-
}),
|
|
7894
|
-
h('div', { style: { display: 'flex', gap: 6, marginTop: 6, flexWrap: 'wrap' } },
|
|
7895
|
-
h('select', {
|
|
7896
|
-
style: { ...S.input, flex: '1 1 120px', minWidth: 0 },
|
|
7897
|
-
title: t('disclosureLabel'),
|
|
7898
|
-
value: draft.disclosure ?? f.disclosure ?? 'can_tell',
|
|
7899
|
-
onChange: (e) => set('disclosure', e.target.value),
|
|
7900
|
-
}, ['can_tell', 'only_if_asked', 'never_say'].map((v) => h('option', { key: v, value: v }, enumText(t, DISCLOSURE_LABELS, v)))),
|
|
7901
|
-
h('select', {
|
|
7902
|
-
style: { ...S.input, flex: '1 1 110px', minWidth: 0 },
|
|
7903
|
-
title: t('ownerLabel'),
|
|
7904
|
-
value: draft.owner ?? f.owner ?? 'me',
|
|
7905
|
-
onChange: (e) => set('owner', e.target.value),
|
|
7906
|
-
}, ['me', 'us', 'about_user', 'about_project'].map((v) => h('option', { key: v, value: v }, enumText(t, OWNER_LABELS, v)))),
|
|
7907
|
-
h('select', {
|
|
7908
|
-
style: { ...S.input, flex: '1 1 110px', minWidth: 0 },
|
|
7909
|
-
title: t('visibilityLabel'),
|
|
7910
|
-
value: draft.visibility ?? f.visibility ?? 'shared',
|
|
7911
|
-
onChange: (e) => set('visibility', e.target.value),
|
|
7912
|
-
}, ['shared', 'secret'].map((v) => h('option', { key: v, value: v }, enumText(t, VISIBILITY_LABELS, v)))),
|
|
7913
|
-
h('select', {
|
|
7914
|
-
style: { ...S.input, flex: '1 1 110px', minWidth: 0 },
|
|
7915
|
-
title: t('sourceLabel'),
|
|
7916
|
-
value: draft.source ?? f.source ?? 'inferred',
|
|
7917
|
-
onChange: (e) => set('source', e.target.value),
|
|
7918
|
-
}, ['user_said', 'inferred', 'imagined', 'told'].map((v) => h('option', { key: v, value: v }, enumText(t, SOURCE_LABELS, v))))))
|
|
7919
|
-
}
|
|
7920
|
-
|
|
7921
8003
|
const browsePool = file => file.status === 'pending_review' ? 'review' : file.status === 'archived' ? 'archived'
|
|
7922
8004
|
: ['suppressed', 'expired', 'superseded'].includes(file.status) || file.expiresAt && Date.parse(file.expiresAt) <= Date.now() ? 'inactive' : 'active'
|
|
7923
8005
|
const browseQueryText = browseQuery.trim().toLowerCase()
|
|
@@ -7925,6 +8007,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
7925
8007
|
|| [file.title, file.content, file.id, ...(Array.isArray(file.tags) ? file.tags : [])]
|
|
7926
8008
|
.some(value => String(value || '').toLowerCase().includes(browseQueryText))
|
|
7927
8009
|
const archShown = browseFiles.filter(file => browsePool(file) === browseView && browseMatched(file))
|
|
8010
|
+
// 供滚到底部自动追加用(effect 在 loading 分支之前,拿不到这里的局部值)。
|
|
8011
|
+
browseTotalRef.current = archShown.length
|
|
8012
|
+
const browseVisible = browseView === 'archived' ? archShown : archShown.slice(0, browseShown)
|
|
7928
8013
|
// An archived row is a body you are deciding about, not a draft you are editing:
|
|
7929
8014
|
// no title/content/tag fields, just enough to recognise it plus the two exits.
|
|
7930
8015
|
const renderArchivedMemory = (f) => h('div', { key: f.id, style: S.item },
|
|
@@ -7990,14 +8075,14 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
7990
8075
|
h('select', {
|
|
7991
8076
|
style: { ...S.input, flex: 1 }, value: browseLibId,
|
|
7992
8077
|
title: (state.libraries || []).find((lib) => lib.id === browseLibId)?.scopeKey || t('currentLibrary'),
|
|
7993
|
-
onChange: (e) => { setBrowseLibId(e.target.value); setBrowseQuery('') },
|
|
8078
|
+
onChange: (e) => { setBrowseLibId(e.target.value); setBrowseQuery(''); setBrowseShown(60) },
|
|
7994
8079
|
}, (state.libraries || []).map((l) => h('option', { key: l.id, value: l.id }, libraryOptionLabel(l, state.libraries || []))))),
|
|
7995
8080
|
browseView === 'relations' ? null : h('div', { style: S.row },
|
|
7996
8081
|
h('span', { style: S.label }, t('browseSearch')),
|
|
7997
8082
|
h('input', {
|
|
7998
8083
|
style: { ...S.input, flex: 1 }, type: 'search', value: browseQuery,
|
|
7999
8084
|
placeholder: t('browseSearchPlaceholder'), 'aria-label': t('browseSearch'),
|
|
8000
|
-
onChange: (e) => setBrowseQuery(e.target.value),
|
|
8085
|
+
onChange: (e) => { setBrowseQuery(e.target.value); setBrowseShown(60) },
|
|
8001
8086
|
}),
|
|
8002
8087
|
browseQuery
|
|
8003
8088
|
? h('span', { style: S.muted, role: 'status' },
|
|
@@ -8019,7 +8104,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
8019
8104
|
role: 'tab',
|
|
8020
8105
|
'aria-selected': browseView === value,
|
|
8021
8106
|
className: `dshm-nav-item${browseView === value ? ' on' : ''}`,
|
|
8022
|
-
onClick: () => { setBrowseView(value); setDeleteArmed('') },
|
|
8107
|
+
onClick: () => { setBrowseView(value); setBrowseShown(60); setDeleteArmed('') },
|
|
8023
8108
|
}, value === 'relations' ? pair[1] : pair[1] + ' (' + count + ')')
|
|
8024
8109
|
})),
|
|
8025
8110
|
browseView === 'archived' && archShown.length > 0
|
|
@@ -8030,7 +8115,25 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
8030
8115
|
: archShown.length === 0
|
|
8031
8116
|
? h(Empty, null, browseView === 'archived' ? t('browseArchivedEmpty') : t('noMemoriesView'))
|
|
8032
8117
|
: h('div', { style: { ...S.list, marginTop: 10 } },
|
|
8033
|
-
|
|
8118
|
+
browseVisible.map(browseView === 'archived' ? renderArchivedMemory : (file) => h(BrowserMemoryCard, {
|
|
8119
|
+
key: file.id,
|
|
8120
|
+
file,
|
|
8121
|
+
t,
|
|
8122
|
+
busy,
|
|
8123
|
+
browseBusy,
|
|
8124
|
+
onSave: cardSave,
|
|
8125
|
+
onArchive: cardArchive,
|
|
8126
|
+
onResolve: cardResolve,
|
|
8127
|
+
onLoadFull: cardLoadFull,
|
|
8128
|
+
})),
|
|
8129
|
+
browseView !== 'archived' && archShown.length > browseShown
|
|
8130
|
+
? h('div', { ref: browseMoreRef, style: { ...S.muted, marginTop: 10 }, role: 'status' },
|
|
8131
|
+
h(Button, {
|
|
8132
|
+
onClick: () => setBrowseShown((count) => count + 120),
|
|
8133
|
+
style: S.ghost,
|
|
8134
|
+
title: t('browseLoadMore'),
|
|
8135
|
+
}, t('browseLoadMore') + ` (${browseVisible.length}/${archShown.length})`))
|
|
8136
|
+
: null)))
|
|
8034
8137
|
|
|
8035
8138
|
const renderFolderItem = (folder) => {
|
|
8036
8139
|
const disabled = folderBusy === folder.scopeKey
|
|
@@ -170,7 +170,8 @@ function rangeLine(snapshot) {
|
|
|
170
170
|
* worker 的任务书:身份、范围、可用工具、回执契约。
|
|
171
171
|
* 这不是「人格」,是职责——所以它不描述风格,只描述能做什么、不能做什么、怎么交差。
|
|
172
172
|
*/
|
|
173
|
-
export function buildWorkerBrief({ snapshot, probe = null, contract = '', reason = 'auto', jobId = null, mustCover = [], autoReceipt = false, singleOnly = false } = {}) {
|
|
173
|
+
export function buildWorkerBrief({ snapshot, probe = null, contract = '', reason = 'auto', jobId = null, mustCover = [], autoReceipt = false, singleOnly = false, domain = 'general' } = {}) {
|
|
174
|
+
const coding = String(domain) === 'coding'
|
|
174
175
|
const ptc = probe?.ptcObserved === true
|
|
175
176
|
const sdkShape = singleOnly
|
|
176
177
|
? 'await tools.memu_private_remember({...}) / await tools.memu_private_update({...})'
|
|
@@ -193,11 +194,18 @@ export function buildWorkerBrief({ snapshot, probe = null, contract = '', reason
|
|
|
193
194
|
: '直接写,不要再检索:目录和召回命中已经给出。真正新增的条目合并成一次 memu_private_remember_batch({items:[...]}) 提交:每个窗口只发一次 batch,不要逐条 remember;只有本窗只写 1 条时才用 memu_private_remember。目录里已有的同一事实用 memu_private_update(用目录里的 id)合并,能合并的更新也放在同一轮里,不要一条一轮来回。',
|
|
194
195
|
'时间锚点:每条用户消息前的 [事件时间 YYYY-MM-DD HH:mm] 是那一轮的发生时间;observed_at 填这个时间,今天/明天/下周X/月底按它算绝对日期;不要用整理时的入库时间,也不要用真实时钟。',
|
|
195
196
|
'写库字段:speaker_id、source_kind、observed_at、absolute_date 必填;冲突用 conflicts_with,明确取代用 supersedes;助手说过的话用 source_kind=assistant_said;承诺写 commitment。',
|
|
196
|
-
|
|
197
|
+
coding
|
|
198
|
+
// 工程记忆的价值排序与写入形状和 RP 完全不同:中文工程结论落在 RP 排序的
|
|
199
|
+
// "其他明确事实"里会被"普通事实最多 3 条"挤掉,所以任务书按域分叉。
|
|
200
|
+
? '按价值排序:根因与修复理由 = 接口/不变量变化 = 环境与版本约束 = 被否决方案及其失败条件 > 验证结论与测试范围 > 需求/验收变化 > 工作偏好 > 其余明确事实。前两类必须写,每窗最多新增 8 条;工程结论不受「普通事实最多 3 条」限制,必写候选不受限,总数仍不超过 8 条。'
|
|
201
|
+
: '按价值排序:约定/承诺 = 新人物首次出现/换人接手/称呼变化 > 日期/改口/冲突 > 身份/边界/第三方人物 > 偏好/计划 > 其他明确事实。前两类必须写;每窗最多新增 8 条,普通事实最多 3 条,必写候选不受限,总数仍不超过 8 条。',
|
|
197
202
|
'同一件事有两种说法时各写一条,用 conflicts_with 互指;只有明确取代才用 supersedes,旧正文保留。承诺/约定写 commitment。',
|
|
203
|
+
'先清欠账再查过时:目录「欠账」里 open 且已过 due_at 的承诺,按本窗证据结案(done/cancelled/expired),没有证据就保留 open 并写明仍欠着谁;valid_to 已过或已被明确取代的旧条目用 memu_private_update 归档或补正窗口,旧正文保留。',
|
|
198
204
|
// 2026-11-15:link 裁决步骤写进任务书——触发时机明示,模型不再靠读工具参数说明猜。
|
|
199
205
|
'写完条目后用本轮创建/更新的 id 调一次 memu_private_link_suggest,返回的候选【逐条】裁决:有具体证据的用 memu_private_link 连(note 引用转录原句作依据),没有证据的明确放弃,不许全部留着不裁决。触发时机:同一事实的新版本→连到旧条(取代关系);同一个人的多条记忆→挂到命名实体 entity {name, kind};承诺/约定→commitment;两条互斥→conflict。相似≠相连,宁缺毋滥。',
|
|
200
|
-
|
|
206
|
+
coding
|
|
207
|
+
? 'content 写 150–350 字,按「结论 / 作用范围与定位(路径 + 符号,行号只作辅助)/ 条件与原因 / 验证状态」排;标题写结论本身(模块、符号、错误签名或命令),不要「修复了异步问题」这类空话;不写人物地点与原文模板,不复述整段对话。emotion 与 dominance 只属于人物侧条目,工程事实省略。'
|
|
208
|
+
: 'content 写 50–150 字,只保留人物、地点、时间、事情、原话/说话人;emotion 只在叙事确实有情绪瞬间时填写,普通事实省略;不要复述整段对话,不要写成行为日志。',
|
|
201
209
|
...(Array.isArray(mustCover) && mustCover.length > 0
|
|
202
210
|
? [
|
|
203
211
|
'本窗必写候选(先写这些,再写其他;每条都必须落库,或在失败说明里写明为什么不写,不得静默跳过):',
|
package/lib/curator.js
CHANGED
|
@@ -121,8 +121,20 @@ function eventCallId(event) {
|
|
|
121
121
|
* 次调用的双写,以 tool/call 事件为准——块只在没有对应事件时保留(先按 callId
|
|
122
122
|
* 配对;两侧都没有 id 时按 name+arguments 计数配对,支持重复调用)。字符预算
|
|
123
123
|
* 保留原行为,另加可选 token 预算(累计 estTokens 超预算即停)。
|
|
124
|
+
* 工具行额度可按域覆盖:编码域的修改重点在命令/错误签名/参数里,300/400 只够开头。
|
|
124
125
|
*/
|
|
125
|
-
export
|
|
126
|
+
export const CONDENSE_TOOL_RESULT_CHARS = 400
|
|
127
|
+
export const CONDENSE_TOOL_CALL_CHARS = 300
|
|
128
|
+
const CONDENSE_TOOL_RESULT_CHARS_CODING = 1_400
|
|
129
|
+
const CONDENSE_TOOL_CALL_CHARS_CODING = 700
|
|
130
|
+
|
|
131
|
+
export function condenseLimitsFor(domain) {
|
|
132
|
+
return String(domain) === 'coding'
|
|
133
|
+
? { toolResultChars: CONDENSE_TOOL_RESULT_CHARS_CODING, toolCallChars: CONDENSE_TOOL_CALL_CHARS_CODING }
|
|
134
|
+
: { toolResultChars: CONDENSE_TOOL_RESULT_CHARS, toolCallChars: CONDENSE_TOOL_CALL_CHARS }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function condenseEvents(events, maxChars = MAX_SESSION_CHARS, { maxTokens = Infinity, toolResultChars = CONDENSE_TOOL_RESULT_CHARS, toolCallChars = CONDENSE_TOOL_CALL_CHARS } = {}) {
|
|
126
138
|
// 事件侧先收一遍:callId 集合 + (name, arguments) 计数,供块侧配对。
|
|
127
139
|
const eventCallIds = new Set()
|
|
128
140
|
const eventSignatures = new Map()
|
|
@@ -159,17 +171,17 @@ export function condenseEvents(events, maxChars = MAX_SESSION_CHARS, { maxTokens
|
|
|
159
171
|
claimedSignatures.set(key, (claimedSignatures.get(key) || 0) + 1)
|
|
160
172
|
continue
|
|
161
173
|
}
|
|
162
|
-
lines.push(`Tool call: ${b.name}${b.arguments ? ` ${truncate(argsText(b.arguments),
|
|
174
|
+
lines.push(`Tool call: ${b.name}${b.arguments ? ` ${truncate(argsText(b.arguments), toolCallChars)}` : ''}`)
|
|
163
175
|
}
|
|
164
176
|
continue
|
|
165
177
|
}
|
|
166
178
|
if (type === 'tool/result') {
|
|
167
179
|
const text = textOf(event.data?.message?.content)
|
|
168
|
-
if (text) lines.push(`Tool result${event.data?.message?.isError ? ' (error)' : ''}: ${truncate(text,
|
|
180
|
+
if (text) lines.push(`Tool result${event.data?.message?.isError ? ' (error)' : ''}: ${truncate(text, toolResultChars)}`)
|
|
169
181
|
continue
|
|
170
182
|
}
|
|
171
183
|
if (type === 'tool/call') {
|
|
172
|
-
lines.push(`Tool call: ${event.data?.name || '?'} ${truncate(argsText(event.data?.arguments),
|
|
184
|
+
lines.push(`Tool call: ${event.data?.name || '?'} ${truncate(argsText(event.data?.arguments), toolCallChars)}`)
|
|
173
185
|
}
|
|
174
186
|
} catch {}
|
|
175
187
|
}
|