@zhangfeiyue/dsh-long-term-memory 0.0.0-stage → 1.1.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/README.md CHANGED
@@ -1,3 +1,97 @@
1
- # Temporary Holding Version
1
+ # Long-term memory
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A persistent memory for DeepSeek Harness, shared by every session and every
4
+ workspace in this profile.
5
+
6
+ ## What it does
7
+
8
+ - **Builds profiles.** Beyond a record store it synthesises a *personal profile*
9
+ (identity, communication, values, constraints, goals, working style) and a
10
+ *work profile per domain* (stack, conventions, quality bar, workflow, pitfalls,
11
+ decisions) from the evidence, with an admission gate so a passing remark does
12
+ not become "who the user is".
13
+ - **Recalls automatically.** Before each request, the plugin injects the personal
14
+ profile, the work profile for the active domain, project knowledge and
15
+ unfinished tasks, each with its own character budget. The block names the store
16
+ location and gives every line an id.
17
+ - **Records explicit instructions.** A user sentence that asks the agent to
18
+ remember something ("remember that…", "from now on…", "记住…") becomes a
19
+ preference memory immediately, without an extra model round trip.
20
+ - **Captures unfinished work.** Every `todo/write` snapshot becomes task
21
+ memories, so work abandoned by a closed session is visible and resumable in a
22
+ later one — including after a restart.
23
+ - **Stays scoped.** Persona is global; work knowledge is partitioned by domain;
24
+ project knowledge and tasks by workspace. One project's notes never surface in
25
+ another.
26
+ - **Consolidates itself.** A background pass merges near-duplicate records,
27
+ supersedes revised preferences and decisions instead of deleting them, archives
28
+ stale trivia and closed tasks, and enforces a size cap.
29
+
30
+ ## Tools
31
+
32
+ | Tool | Purpose |
33
+ |---|---|
34
+ | `memory_save` | Record a preference, project fact, decision, solution, task, capability or note. Near-identical entries merge instead of duplicating. |
35
+ | `memory_search` | Retrieve relevant memories; scoped to the current workspace unless cross-workspace results are requested. |
36
+ | `memory_update` | Correct text, retitle, retag, re-rank, or advance a task's status. |
37
+ | `memory_forget` | Delete entries by id. Irreversible. |
38
+ | `memory_profile` | Read a profile, or pin/unpin one entry in it. |
39
+ | `memory_admin` | `stats`, `consolidate`, `backup`, `export`, `profiles`. |
40
+
41
+ ## Memory board
42
+
43
+ The bundle also ships a browser half. **Settings → Plugins → Long-term memory**
44
+ shows a live board of the whole store: the personal profile, each work profile
45
+ with its entry count, unfinished tasks, and a feed of recent changes.
46
+
47
+ It is live rather than polled: the Host pushes a snapshot over server-sent events
48
+ whenever the store changes, and falls back to polling if the stream cannot
49
+ connect. You can pin, edit and delete entries and change a task's status inline;
50
+ each write carries the version the board last saw, so a stale tab gets `409`
51
+ instead of overwriting a newer memory, and every board write is stamped
52
+ `source: { kind: 'board', at }`.
53
+
54
+ | Route | Purpose |
55
+ |---|---|
56
+ | `GET /long-term-memory/snapshot` | Initial paint and polling fallback |
57
+ | `GET /long-term-memory/events` | Server-sent event stream |
58
+ | `GET /long-term-memory/record?id=…` | Exact stored text for the editor |
59
+ | `POST /long-term-memory/mutate` | Pin, edit, re-status, delete |
60
+
61
+ ## Storage
62
+
63
+ Records live outside every workspace, by default in
64
+ `~/.dsh/long-term-memory/records.jsonl` — an append-only log folded at load time,
65
+ so a crash costs at most the record being written. Compaction keeps dated backups
66
+ in `backup/`, and plugin diagnostics go to `logs/plugin.log`.
67
+
68
+ ## Configuration
69
+
70
+ The composition row needs no configuration. To retune the plugin, write
71
+ `~/.dsh/long-term-memory/config.json`:
72
+
73
+ ```json
74
+ {
75
+ "maxRecords": 5000,
76
+ "maxInjectChars": 2400,
77
+ "injectRefreshMs": 300000,
78
+ "consolidateIntervalMs": 21600000,
79
+ "staleDays": 180,
80
+ "autoExtract": true,
81
+ "taskCapture": true,
82
+ "personaMinImportance": 4,
83
+ "workMinImportance": 3,
84
+ "profileBudgets": { "persona": 400, "work": 500, "project": 520, "tasks": 400 },
85
+ "domains": [{ "pattern": "my-org", "domain": "development" }]
86
+ }
87
+ ```
88
+
89
+ `storeDir` moves the store; a value in the composition row overrides the file.
90
+
91
+ ## Failure behaviour
92
+
93
+ Every listener, context provider and tool catches its own errors and degrades to
94
+ "no memory". A damaged or unwritable store never stops a session, and the log
95
+ skips a torn trailing line instead of failing to load. The plugin uses only
96
+ documented extension points — no session event types of its own, no core file
97
+ changes.
package/client.js ADDED
@@ -0,0 +1,580 @@
1
+ /**
2
+ * Browser half: the memory board.
3
+ *
4
+ * Registers one tab into the Plugins settings section. Data arrives two ways:
5
+ * an initial `GET /long-term-memory/snapshot` for a fast first paint, then a
6
+ * server-sent event stream that pushes a fresh snapshot whenever the store
7
+ * changes. Polling remains as a fallback for a composition where the stream
8
+ * cannot connect.
9
+ *
10
+ * Writes go through `POST /long-term-memory/mutate` with the record version the
11
+ * board last saw, so a stale tab is answered 409 instead of overwriting a newer
12
+ * memory.
13
+ *
14
+ * No build step and no Harness client package import: React comes from the
15
+ * browser module table, and every control is plain markup. Styling uses neutral
16
+ * alpha surfaces over the inherited text colour, so it reads correctly in both
17
+ * light and dark themes without depending on token names that could move.
18
+ */
19
+ window.__ModuleLoader__.load({
20
+ id: '@zhangfeiyue/dsh-long-term-memory',
21
+ factory(require) {
22
+ const React = require('react')
23
+ const h = React.createElement
24
+ const { useState, useEffect, useMemo, useRef, useCallback } = React
25
+
26
+ const SNAPSHOT_ENDPOINT = '/long-term-memory/snapshot'
27
+ const EVENTS_ENDPOINT = '/long-term-memory/events'
28
+ const MUTATE_ENDPOINT = '/long-term-memory/mutate'
29
+ const RECORD_ENDPOINT = '/long-term-memory/record'
30
+ const POLL_MS = 3000
31
+ const FALLBACK_MS = 4000
32
+
33
+ /** Whether the browser prefers Chinese. */
34
+ function prefersChinese() {
35
+ try {
36
+ return String(navigator.language || navigator.userLanguage || '').toLowerCase().startsWith('zh')
37
+ } catch {
38
+ return false
39
+ }
40
+ }
41
+
42
+ const COPY = {
43
+ en: {
44
+ tab: 'Long-term memory',
45
+ title: 'Memory board',
46
+ subtitle: 'Live view of the long-term memory store',
47
+ store: 'Store',
48
+ records: 'records',
49
+ active: 'active',
50
+ openTasks: 'unfinished tasks',
51
+ logLines: 'log entries',
52
+ persona: 'Personal profile',
53
+ work: 'Work profiles',
54
+ tasks: 'Unfinished tasks',
55
+ recent: 'Recent changes',
56
+ emptyPersona: 'Nothing has cleared the admission rule yet. An entry enters a profile when it is pinned, confirmed twice, or important enough.',
57
+ emptyWork: 'No work profile yet.',
58
+ emptyTasks: 'No unfinished work.',
59
+ emptyRecent: 'No records yet.',
60
+ refreshed: 'updated',
61
+ loading: 'Loading memory board…',
62
+ failed: 'Cannot reach the memory store.',
63
+ retry: 'Retry',
64
+ now: 'just now',
65
+ seconds: 's ago',
66
+ minutes: 'm ago',
67
+ hours: 'h ago',
68
+ days: 'd ago',
69
+ live: 'live',
70
+ polling: 'polling',
71
+ pin: 'Pin',
72
+ unpin: 'Unpin',
73
+ edit: 'Edit',
74
+ save: 'Save',
75
+ cancel: 'Cancel',
76
+ remove: 'Delete',
77
+ confirmRemove: 'Delete this memory permanently?',
78
+ pinned: 'pinned',
79
+ importance: 'importance',
80
+ domains: 'domains',
81
+ conflict: 'That memory changed while you were editing; the board reloaded it.',
82
+ failedWrite: 'The change was rejected.',
83
+ readOnlyHint: 'Edits are audited as board changes. Verification uses the memory tools.',
84
+ },
85
+ zh: {
86
+ tab: '长期记忆',
87
+ title: '记忆看板',
88
+ subtitle: '长期记忆存储的实时视图',
89
+ store: '存储',
90
+ records: '条记录',
91
+ active: '活跃',
92
+ openTasks: '未完成任务',
93
+ logLines: '条日志',
94
+ persona: '个人画像',
95
+ work: '工作画像',
96
+ tasks: '未完成任务',
97
+ recent: '近期变化',
98
+ emptyPersona: '暂无条目满足入选条件。条目需要被固定、被确认两次,或重要度足够高,才会进入画像。',
99
+ emptyWork: '暂无工作画像。',
100
+ emptyTasks: '没有未完成的工作。',
101
+ emptyRecent: '还没有记录。',
102
+ refreshed: '更新于',
103
+ loading: '正在加载记忆看板…',
104
+ failed: '无法连接记忆存储。',
105
+ retry: '重试',
106
+ now: '刚刚',
107
+ seconds: ' 秒前',
108
+ minutes: ' 分钟前',
109
+ hours: ' 小时前',
110
+ days: ' 天前',
111
+ live: '实时',
112
+ polling: '轮询',
113
+ pin: '固定',
114
+ unpin: '取消固定',
115
+ edit: '编辑',
116
+ save: '保存',
117
+ cancel: '取消',
118
+ remove: '删除',
119
+ confirmRemove: '确定永久删除这条记忆?',
120
+ pinned: '已固定',
121
+ importance: '重要度',
122
+ domains: '个领域',
123
+ conflict: '编辑期间这条记忆已被修改,看板已刷新。',
124
+ failedWrite: '修改被拒绝。',
125
+ readOnlyHint: '修改会以「看板」身份记入审计。校验请使用记忆工具。',
126
+ },
127
+ }
128
+
129
+ /** Relative time in the active language. */
130
+ function relativeTime(timestamp, t) {
131
+ const seconds = Math.max(0, Math.round((Date.now() - timestamp) / 1000))
132
+ if (seconds < 5) return t.now
133
+ if (seconds < 60) return `${seconds}${t.seconds}`
134
+ const minutes = Math.round(seconds / 60)
135
+ if (minutes < 60) return `${minutes}${t.minutes}`
136
+ const hours = Math.round(minutes / 60)
137
+ if (hours < 24) return `${hours}${t.hours}`
138
+ return `${Math.round(hours / 24)}${t.days}`
139
+ }
140
+
141
+ const S = {
142
+ wrap: { display: 'flex', flexDirection: 'column', gap: 16, padding: '4px 2px 24px' },
143
+ head: { display: 'flex', flexWrap: 'wrap', alignItems: 'baseline', gap: 10 },
144
+ title: { fontSize: 16, fontWeight: 600, margin: 0 },
145
+ muted: { fontSize: 12, opacity: 0.62 },
146
+ chips: { display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 2 },
147
+ chip: {
148
+ fontSize: 12,
149
+ padding: '2px 8px',
150
+ borderRadius: 999,
151
+ background: 'rgba(127,127,127,0.12)',
152
+ whiteSpace: 'nowrap',
153
+ },
154
+ store: {
155
+ fontSize: 11,
156
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
157
+ opacity: 0.55,
158
+ wordBreak: 'break-all',
159
+ },
160
+ grid: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))', gap: 12 },
161
+ card: {
162
+ border: '1px solid rgba(127,127,127,0.26)',
163
+ borderRadius: 10,
164
+ padding: '10px 12px',
165
+ background: 'rgba(127,127,127,0.05)',
166
+ minWidth: 0,
167
+ },
168
+ cardTitle: { fontSize: 13, fontWeight: 600, margin: '0 0 8px', display: 'flex', justifyContent: 'space-between', gap: 8 },
169
+ row: { display: 'flex', gap: 8, alignItems: 'flex-start', padding: '4px 0', borderTop: '1px solid rgba(127,127,127,0.14)' },
170
+ facet: { fontSize: 11, opacity: 0.6, minWidth: 84, flexShrink: 0, paddingTop: 2 },
171
+ text: { fontSize: 12.5, lineHeight: 1.5, margin: 0, wordBreak: 'break-word' },
172
+ meta: { fontSize: 11, opacity: 0.5, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace' },
173
+ pill: {
174
+ fontSize: 10.5,
175
+ padding: '1px 6px',
176
+ borderRadius: 999,
177
+ background: 'rgba(127,127,127,0.16)',
178
+ flexShrink: 0,
179
+ },
180
+ changed: { background: 'rgba(45,120,220,0.16)', borderRadius: 6 },
181
+ empty: { fontSize: 12, opacity: 0.6, margin: 0, lineHeight: 1.6 },
182
+ error: { fontSize: 12.5, color: '#d14343' },
183
+ notice: { fontSize: 12, color: '#c9761a' },
184
+ button: {
185
+ fontSize: 11.5,
186
+ padding: '2px 8px',
187
+ borderRadius: 6,
188
+ border: '1px solid rgba(127,127,127,0.35)',
189
+ background: 'transparent',
190
+ color: 'inherit',
191
+ cursor: 'pointer',
192
+ whiteSpace: 'nowrap',
193
+ },
194
+ buttonDanger: {
195
+ fontSize: 11.5,
196
+ padding: '2px 8px',
197
+ borderRadius: 6,
198
+ border: '1px solid rgba(209,67,67,0.45)',
199
+ background: 'transparent',
200
+ color: '#d14343',
201
+ cursor: 'pointer',
202
+ whiteSpace: 'nowrap',
203
+ },
204
+ actions: { display: 'flex', gap: 4, alignItems: 'center', flexShrink: 0 },
205
+ textarea: {
206
+ width: '100%',
207
+ minHeight: 64,
208
+ fontSize: 12.5,
209
+ lineHeight: 1.5,
210
+ padding: 6,
211
+ borderRadius: 6,
212
+ border: '1px solid rgba(127,127,127,0.35)',
213
+ background: 'transparent',
214
+ color: 'inherit',
215
+ resize: 'vertical',
216
+ fontFamily: 'inherit',
217
+ },
218
+ select: {
219
+ fontSize: 11.5,
220
+ padding: '2px 6px',
221
+ borderRadius: 6,
222
+ border: '1px solid rgba(127,127,127,0.35)',
223
+ background: 'transparent',
224
+ color: 'inherit',
225
+ },
226
+ }
227
+
228
+ /** Send one mutation; resolves the response payload or throws. */
229
+ async function sendMutation(payload) {
230
+ const response = await fetch(MUTATE_ENDPOINT, {
231
+ method: 'POST',
232
+ headers: { 'content-type': 'application/json', 'x-ltm-request': '1' },
233
+ body: JSON.stringify(payload),
234
+ })
235
+ let body = {}
236
+ try {
237
+ body = await response.json()
238
+ } catch {
239
+ body = {}
240
+ }
241
+ if (!response.ok) {
242
+ const error = new Error(body.error || `HTTP ${response.status}`)
243
+ error.status = response.status
244
+ error.payload = body
245
+ throw error
246
+ }
247
+ return body
248
+ }
249
+
250
+ /** Snapshot via SSE with polling fallback. */
251
+ function useSnapshot() {
252
+ const [state, setState] = useState({ status: 'loading', snapshot: null, error: null, live: false })
253
+ const [nonce, setNonce] = useState(0)
254
+
255
+ useEffect(() => {
256
+ let alive = true
257
+ let source = null
258
+ let pollTimer = null
259
+ let graceTimer = null
260
+ let sawEvent = false
261
+
262
+ const apply = snapshot => {
263
+ if (alive) setState({ status: 'ready', snapshot, error: null, live: sawEvent })
264
+ }
265
+ const fail = message => {
266
+ if (!alive) return
267
+ setState(previous => ({
268
+ status: previous.snapshot ? 'ready' : 'error',
269
+ snapshot: previous.snapshot,
270
+ error: message,
271
+ live: sawEvent,
272
+ }))
273
+ }
274
+ const pollOnce = async () => {
275
+ try {
276
+ const response = await fetch(SNAPSHOT_ENDPOINT, { headers: { accept: 'application/json' }, cache: 'no-store' })
277
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
278
+ apply(await response.json())
279
+ } catch (error) {
280
+ fail(String(error?.message ?? error))
281
+ }
282
+ }
283
+ const ensurePolling = () => {
284
+ if (pollTimer !== null) return
285
+ pollOnce()
286
+ pollTimer = setInterval(pollOnce, POLL_MS)
287
+ }
288
+ const stopPolling = () => {
289
+ if (pollTimer === null) return
290
+ clearInterval(pollTimer)
291
+ pollTimer = null
292
+ }
293
+
294
+ pollOnce()
295
+ if (typeof EventSource === 'function') {
296
+ try {
297
+ source = new EventSource(EVENTS_ENDPOINT)
298
+ source.addEventListener('snapshot', event => {
299
+ sawEvent = true
300
+ stopPolling()
301
+ try {
302
+ apply(JSON.parse(event.data))
303
+ } catch {
304
+ // A malformed frame is skipped; the next one will arrive.
305
+ }
306
+ })
307
+ source.addEventListener('error', () => {
308
+ // EventSource reconnects on its own; polling covers the gap.
309
+ if (!sawEvent) ensurePolling()
310
+ })
311
+ } catch {
312
+ ensurePolling()
313
+ }
314
+ } else {
315
+ ensurePolling()
316
+ }
317
+ graceTimer = setTimeout(() => {
318
+ if (alive && !sawEvent) ensurePolling()
319
+ }, FALLBACK_MS)
320
+
321
+ return () => {
322
+ alive = false
323
+ clearTimeout(graceTimer)
324
+ stopPolling()
325
+ if (source !== null) source.close()
326
+ }
327
+ }, [nonce])
328
+
329
+ return {
330
+ status: state.status,
331
+ snapshot: state.snapshot,
332
+ error: state.error,
333
+ live: state.live,
334
+ retry: () => setNonce(value => value + 1),
335
+ }
336
+ }
337
+
338
+ /** Rows whose `updatedAt` moved since the previous snapshot. */
339
+ function useChangedIds(snapshot) {
340
+ const [changed, setChanged] = useState(() => new Set())
341
+ const previous = useRef(new Map())
342
+ useEffect(() => {
343
+ if (snapshot === null) return
344
+ const next = new Map()
345
+ const moved = new Set()
346
+ const consider = row => {
347
+ if (row === null || typeof row.id !== 'string') return
348
+ const before = previous.current.get(row.id)
349
+ if (before !== undefined && before !== row.updatedAt) moved.add(row.id)
350
+ next.set(row.id, row.updatedAt)
351
+ }
352
+ for (const row of snapshot.recent) consider(row)
353
+ for (const task of snapshot.tasks) consider(task)
354
+ previous.current = next
355
+ setChanged(moved)
356
+ }, [snapshot])
357
+ return changed
358
+ }
359
+
360
+ /** The board. */
361
+ function MemoryBoard() {
362
+ const t = useMemo(() => (prefersChinese() ? COPY.zh : COPY.en), [])
363
+ const { status, snapshot, error, live, retry } = useSnapshot()
364
+ const changed = useChangedIds(snapshot)
365
+ const [busyId, setBusyId] = useState(null)
366
+ const [notice, setNotice] = useState(null)
367
+ const [editing, setEditing] = useState(null)
368
+ const [draft, setDraft] = useState('')
369
+
370
+ const mutate = useCallback(async (payload) => {
371
+ setBusyId(payload.id)
372
+ setNotice(null)
373
+ try {
374
+ await sendMutation(payload)
375
+ setEditing(null)
376
+ } catch (problem) {
377
+ setNotice(problem.status === 409 ? t.conflict : `${t.failedWrite} ${problem.message}`)
378
+ } finally {
379
+ setBusyId(null)
380
+ }
381
+ }, [t])
382
+
383
+ // The snapshot carries truncated text; an edit loads the exact stored value
384
+ // so saving cannot silently drop the tail of a memory.
385
+ const beginEdit = useCallback(async (id) => {
386
+ setNotice(null)
387
+ if (editing === id) {
388
+ setEditing(null)
389
+ return
390
+ }
391
+ setBusyId(id)
392
+ try {
393
+ const response = await fetch(`${RECORD_ENDPOINT}?id=${encodeURIComponent(id)}`, {
394
+ headers: { accept: 'application/json' },
395
+ cache: 'no-store',
396
+ })
397
+ const body = await response.json().catch(() => ({}))
398
+ if (!response.ok || body.record === undefined) throw new Error(body.error || `HTTP ${response.status}`)
399
+ setDraft(body.record.text)
400
+ setEditing(id)
401
+ } catch (problem) {
402
+ setNotice(`${t.failedWrite} ${problem.message}`)
403
+ } finally {
404
+ setBusyId(null)
405
+ }
406
+ }, [editing, t])
407
+
408
+ if (snapshot === null) {
409
+ if (status === 'error') {
410
+ return h('div', { style: S.wrap },
411
+ h('p', { style: S.error }, `${t.failed} ${error ?? ''}`),
412
+ h('button', { type: 'button', style: S.button, onClick: retry }, t.retry))
413
+ }
414
+ return h('div', { style: S.wrap }, h('p', { style: S.empty }, t.loading))
415
+ }
416
+
417
+ const chips = [
418
+ `${snapshot.records} ${t.records}`,
419
+ `${snapshot.byStatus?.active ?? 0} ${t.active}`,
420
+ `${snapshot.tasks.length} ${t.openTasks}`,
421
+ `${snapshot.logLines} ${t.logLines}`,
422
+ live ? `● ${t.live}` : `○ ${t.polling}`,
423
+ ].map(chip => h('span', { key: chip, style: S.chip }, chip))
424
+
425
+ const actionButtons = (row, options = {}) => {
426
+ const busy = busyId === row.id
427
+ const buttons = []
428
+ if (options.pin !== false) {
429
+ buttons.push(h('button', {
430
+ key: 'pin',
431
+ type: 'button',
432
+ disabled: busy,
433
+ style: S.button,
434
+ onClick: () => mutate({ action: row.pinned ? 'unpin' : 'pin', id: row.id, expectedUpdatedAt: row.updatedAt }),
435
+ }, row.pinned ? t.unpin : t.pin))
436
+ }
437
+ if (options.edit !== false) {
438
+ buttons.push(h('button', {
439
+ key: 'edit',
440
+ type: 'button',
441
+ disabled: busy,
442
+ style: S.button,
443
+ onClick: () => { void beginEdit(row.id) },
444
+ }, editing === row.id ? t.cancel : t.edit))
445
+ }
446
+ buttons.push(h('button', {
447
+ key: 'remove',
448
+ type: 'button',
449
+ disabled: busy,
450
+ style: S.buttonDanger,
451
+ onClick: () => {
452
+ let confirmed = true
453
+ try {
454
+ confirmed = window.confirm(t.confirmRemove)
455
+ } catch {
456
+ confirmed = true
457
+ }
458
+ if (confirmed) mutate({ action: 'delete', id: row.id, expectedUpdatedAt: row.updatedAt })
459
+ },
460
+ }, t.remove))
461
+ return h('div', { style: S.actions }, buttons)
462
+ }
463
+
464
+ const editorFor = (row) => (editing === row.id
465
+ ? h('div', { style: { marginTop: 6 } },
466
+ h('textarea', {
467
+ style: S.textarea,
468
+ value: draft,
469
+ onChange: event => setDraft(event.target.value),
470
+ }),
471
+ h('div', { style: { ...S.actions, marginTop: 6 } },
472
+ h('button', {
473
+ type: 'button',
474
+ style: S.button,
475
+ onClick: () => {
476
+ if (draft.trim().length === 0) return
477
+ mutate({ action: 'update', id: row.id, expectedUpdatedAt: row.updatedAt, patch: { text: draft } })
478
+ },
479
+ }, t.save)))
480
+ : null)
481
+
482
+ const profileRow = entry => {
483
+ const row = { id: entry.id, text: entry.text, pinned: entry.pinned, updatedAt: entry.updatedAt }
484
+ const isEditing = editing === entry.id
485
+ return h('div', { key: entry.id, style: changed.has(entry.id) ? { ...S.row, ...S.changed } : S.row },
486
+ h('span', { style: S.facet }, entry.label),
487
+ h('div', { style: { minWidth: 0, flex: 1 } },
488
+ isEditing
489
+ ? editorFor({ ...row })
490
+ : h('p', { style: S.text }, entry.text),
491
+ h('span', { style: S.meta },
492
+ entry.id,
493
+ entry.pinned ? ` · ${t.pinned}` : '',
494
+ ` · ${t.importance} ${entry.importance}`)),
495
+ actionButtons(row, { edit: true }))
496
+ }
497
+
498
+ const personaBody = snapshot.persona.count === 0
499
+ ? h('p', { style: S.empty }, t.emptyPersona)
500
+ : snapshot.persona.entries.map(profileRow)
501
+
502
+ const workBody = snapshot.work.length === 0
503
+ ? h('p', { style: S.empty }, t.emptyWork)
504
+ : snapshot.work.map(profile => h('div', { key: profile.domain, style: { marginBottom: 10 } },
505
+ h('div', { style: { ...S.facet, minWidth: 0, marginBottom: 4, opacity: 0.75 } }, profile.domain),
506
+ profile.entries.map(profileRow)))
507
+
508
+ const taskBody = snapshot.tasks.length === 0
509
+ ? h('p', { style: S.empty }, t.emptyTasks)
510
+ : snapshot.tasks.slice(0, 12).map(task => h('div', {
511
+ key: task.id,
512
+ style: changed.has(task.id) ? { ...S.row, ...S.changed } : S.row,
513
+ },
514
+ h('div', { style: { minWidth: 0, flex: 1 } },
515
+ h('p', { style: S.text }, task.text),
516
+ h('span', { style: S.meta }, `${task.id} · ${relativeTime(task.updatedAt, t)}`)),
517
+ h('div', { style: S.actions },
518
+ h('select', {
519
+ style: S.select,
520
+ value: task.status,
521
+ disabled: busyId === task.id,
522
+ onChange: event => mutate({ action: 'update', id: task.id, expectedUpdatedAt: task.updatedAt, patch: { status: event.target.value } }),
523
+ }, ['open', 'blocked', 'done', 'dropped'].map(value => h('option', { key: value, value }, value))),
524
+ h('button', {
525
+ type: 'button',
526
+ disabled: busyId === task.id,
527
+ style: S.buttonDanger,
528
+ onClick: () => mutate({ action: 'delete', id: task.id, expectedUpdatedAt: task.updatedAt }),
529
+ }, t.remove))))
530
+
531
+ const recentBody = snapshot.recent.length === 0
532
+ ? h('p', { style: S.empty }, t.emptyRecent)
533
+ : snapshot.recent.slice(0, 12).map(row => h('div', {
534
+ key: row.id,
535
+ style: changed.has(row.id) ? { ...S.row, ...S.changed } : S.row,
536
+ },
537
+ h('span', { style: S.pill }, row.layer === 'work' && row.domain ? `${row.layer}/${row.domain}` : row.layer),
538
+ h('div', { style: { minWidth: 0, flex: 1 } },
539
+ editing === row.id ? editorFor(row) : h('p', { style: S.text }, row.text),
540
+ h('span', { style: S.meta }, `${row.kind} · ${row.status} · ${relativeTime(row.updatedAt, t)}`)),
541
+ actionButtons(row)))
542
+
543
+ const card = (key, title, aside, children) => h('div', { key, style: S.card },
544
+ h('h3', { style: S.cardTitle }, h('span', null, title), h('span', { style: S.muted }, aside)),
545
+ children)
546
+
547
+ const cards = [
548
+ card('persona', t.persona, String(snapshot.persona.count), personaBody),
549
+ card('work', t.work, `${snapshot.work.length} ${t.domains}`, workBody),
550
+ card('tasks', t.tasks, String(snapshot.tasks.length), taskBody),
551
+ card('recent', t.recent, `${t.refreshed} ${relativeTime(snapshot.generatedAt, t)}`, recentBody),
552
+ ]
553
+
554
+ const header = h('div', null,
555
+ h('div', { style: S.head },
556
+ h('h2', { style: S.title }, t.title),
557
+ h('span', { style: S.muted }, t.subtitle)),
558
+ h('div', { style: S.chips }, chips),
559
+ h('div', { style: S.store }, `${t.store}: ${snapshot.storeDir}`))
560
+
561
+ return h('div', { style: S.wrap },
562
+ header,
563
+ notice === null ? null : h('p', { style: S.notice }, notice),
564
+ h('div', { style: S.grid }, cards),
565
+ h('p', { style: S.muted }, t.readOnlyHint))
566
+ }
567
+
568
+ return {
569
+ inject: ['slots'],
570
+ apply(ctx) {
571
+ ctx.slots.inject('settings.plugins.tab', () => ctx.slots.register({
572
+ name: 'settings.plugins.tab',
573
+ id: 'long-term-memory',
574
+ order: 30,
575
+ label: () => (prefersChinese() ? COPY.zh.tab : COPY.en.tab),
576
+ }, MemoryBoard))
577
+ },
578
+ }
579
+ },
580
+ })
@@ -0,0 +1,9 @@
1
+ # Bundle patch layer for the global long-term memory plugin.
2
+ #
3
+ # The row mounts the package's `index.js` as a Host plugin for every session in
4
+ # this profile. Configuration is left empty on purpose: the plugin resolves its
5
+ # defaults from ~/.dsh/long-term-memory/config.json, so this row keeps working
6
+ # across DSH upgrades without editing the profile.
7
+ - insert:
8
+ - id: long-term-memory
9
+ name: '@zhangfeiyue/dsh-long-term-memory'