dsh-memory-metabolism 0.2.2 → 0.2.3

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
@@ -6,7 +6,7 @@ Local-first Markdown memory for DeepSeek Harness, with a full-page memory workbe
6
6
 
7
7
  *Screenshots use demo data.*
8
8
 
9
- Status: 0.2.2. The Markdown store, workbench, chat and organizer are usable; retention/write thresholds remain tunable.
9
+ Status: 0.2.3. The Markdown store, workbench, chat and organizer are usable; retention/write thresholds remain tunable.
10
10
 
11
11
  ## Why
12
12
 
package/README.zh.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  *截图为演示数据。*
8
8
 
9
- 状态:0.2.2。记忆存储、工作台、聊天和整理已可用;写入阈值和留存参数仍可调整。
9
+ 状态:0.2.3。记忆存储、工作台、聊天和整理已可用;写入阈值和留存参数仍可调整。
10
10
 
11
11
  ## 为什么
12
12
 
package/lib/api.js CHANGED
@@ -146,7 +146,7 @@ export function registerRoutes({ ctx, hostCtx, service, store, config, chatStore
146
146
  if (request.method !== 'GET' && request.method !== 'HEAD') return sendJson(response, 405, { ok: false, error: 'GET only' })
147
147
  const status = service.status()
148
148
  const project = queryValue(request.url, 'project') || status.lastProject || ''
149
- const preview = previewProjections({ store, config, projectKey: project })
149
+ const preview = previewProjections({ store, config, projectKey: project, service })
150
150
  const trace = service.trace().filter((row) => row.kind === 'inject').slice(-8).reverse().map((row) => ({
151
151
  ...row,
152
152
  chars: Number.isFinite(row.chars) ? row.chars : (row.ids || []).reduce((sum, id) => sum + String(service.locate(id)?.text || '').length, 0),
package/lib/context.js CHANGED
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from 'node:fs'
2
2
  import { join } from 'node:path'
3
3
  import { createUserMessage } from '@deepseek-ai/dsh-llm'
4
4
  import { budgetClip, stripDeletedLines, toHomeShort } from './shared/text.js'
5
+ import { serializeMemory } from './shared/markdown.js'
5
6
 
6
7
  const PROJECTION_SOURCE = Object.freeze({
7
8
  kind: 'plugin:dsh-memory-metabolism',
@@ -76,6 +77,20 @@ function projection(text, heading) {
76
77
  })
77
78
  }
78
79
 
80
+ function renderActive(service, store, scope, key) {
81
+ const entries = service.read({ scope, project: scope === 'project' ? key : undefined, status: 'active', limit: 500 })
82
+ const sections = []
83
+ for (const entry of entries) {
84
+ let section = sections.find((item) => item.title === (entry.section || '记忆'))
85
+ if (!section) {
86
+ section = { title: entry.section || '记忆', entries: [] }
87
+ sections.push(section)
88
+ }
89
+ section.entries.push({ id: entry.id, text: entry.text })
90
+ }
91
+ return { text: stripDeletedLines(serializeMemory(sections)), ids: entries.map((entry) => entry.id), file: store.fileFor(scope, scope === 'project' ? key : null) }
92
+ }
93
+
79
94
  export function buildProjections({ service, store, config, session }) {
80
95
  const cwd = session?.header?.cwd
81
96
  const projectKey = service.projectKey(cwd)
@@ -94,21 +109,21 @@ export function buildProjections({ service, store, config, session }) {
94
109
  if (message) out.push(message)
95
110
  }
96
111
 
97
- const global = store.read('global', null)
112
+ const global = renderActive(service, store, 'global', null)
98
113
  if (global.text.trim() !== '') {
99
- const message = projection(budgetClip(stripDeletedLines(global.text), config.maxInjectionChars), '# 用户级记忆 (' + toHomeShort(global.file) + ')')
114
+ const message = projection(budgetClip(global.text, config.maxInjectionChars), '# 用户级记忆 (' + toHomeShort(global.file) + ')')
100
115
  if (message) {
101
116
  out.push(message)
102
- ids.push(...global.entries.map((entry) => entry.id))
117
+ ids.push(...global.ids)
103
118
  }
104
119
  }
105
120
 
106
- const project = store.read('project', projectKey)
121
+ const project = renderActive(service, store, 'project', projectKey)
107
122
  if (project.text.trim() !== '') {
108
- const message = projection(budgetClip(stripDeletedLines(project.text), config.maxInjectionChars), '# 项目记忆 (' + projectKey + ' @ ' + toHomeShort(project.file) + ')')
123
+ const message = projection(budgetClip(project.text, config.maxInjectionChars), '# 项目记忆 (' + projectKey + ' @ ' + toHomeShort(project.file) + ')')
109
124
  if (message) {
110
125
  out.push(message)
111
- ids.push(...project.entries.map((entry) => entry.id))
126
+ ids.push(...project.ids)
112
127
  }
113
128
  }
114
129
 
package/lib/preview.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { existsSync, readFileSync } from 'node:fs'
2
2
  import { join } from 'node:path'
3
3
  import { budgetClip, stripDeletedLines, toHomeShort } from './shared/text.js'
4
+ import { serializeMemory } from './shared/markdown.js'
4
5
 
5
6
  function readText(file) {
6
7
  try { return readFileSync(file, 'utf8') } catch { return '' }
@@ -18,7 +19,18 @@ function section(title, raw, limit, source) {
18
19
  }
19
20
  }
20
21
 
21
- export function previewProjections({ store, config, projectKey }) {
22
+ function activeText(service, scope, key) {
23
+ const entries = service.read({ scope, project: scope === 'project' ? key : undefined, status: 'active', limit: 500 })
24
+ const sections = []
25
+ for (const entry of entries) {
26
+ let section = sections.find((item) => item.title === (entry.section || '记忆'))
27
+ if (!section) { section = { title: entry.section || '记忆', entries: [] }; sections.push(section) }
28
+ section.entries.push({ id: entry.id, text: entry.text })
29
+ }
30
+ return { text: stripDeletedLines(serializeMemory(sections)), ids: entries.map((entry) => entry.id) }
31
+ }
32
+
33
+ export function previewProjections({ store, config, projectKey, service }) {
22
34
  const key = String(projectKey || '')
23
35
  const limit = Math.max(1, Number(config.maxInjectionChars) || 6000)
24
36
  const sections = []
@@ -27,14 +39,10 @@ export function previewProjections({ store, config, projectKey }) {
27
39
  const conventions = readText(join(store.dirs.root, 'conventions.md'))
28
40
  if (conventions.trim()) sections.push(section('协作约定', conventions, Math.min(limit, 3000), join(store.dirs.root, 'conventions.md')))
29
41
 
30
- const global = store.read('global', null)
31
- if (global.text.trim()) {
32
- sections.push({ ...section('全局记忆', stripDeletedLines(global.text), limit, toHomeShort(global.file)), ids: global.entries.map((entry) => entry.id) })
33
- }
34
- const project = key ? store.read('project', key) : { text: '', file: '', entries: [] }
35
- if (project.text.trim()) {
36
- sections.push({ ...section('项目记忆', stripDeletedLines(project.text), limit, toHomeShort(project.file)), ids: project.entries.map((entry) => entry.id), project: key })
37
- }
42
+ const globalRaw = service ? activeText(service, 'global', null) : { text: store.read('global', null).text, ids: [] }
43
+ if (globalRaw.text.trim()) sections.push({ ...section('全局记忆', globalRaw.text, limit, toHomeShort(store.fileFor('global', null))), ids: globalRaw.ids })
44
+ const projectRaw = service && key ? activeText(service, 'project', key) : (key ? { text: store.read('project', key).text, ids: [] } : { text: '', ids: [] })
45
+ if (projectRaw.text.trim()) sections.push({ ...section('项目记忆', projectRaw.text, limit, toHomeShort(key ? store.fileFor('project', key) : '')), ids: projectRaw.ids, project: key })
38
46
  if (store.listProjectKeys().length > 0 || store.listReferenceNames().length > 0) {
39
47
  const index = ['# 记忆索引', '项目:' + store.listProjectKeys().join(', '), '参考:' + store.listReferenceNames().join(', '), '当前项目:' + key].join('\n')
40
48
  sections.push(section('记忆索引', index, Math.min(limit, 2000), 'index'))
package/lib/service.js CHANGED
@@ -336,8 +336,9 @@ export function createService({ store, config }) {
336
336
  const totalChars = entries.reduce((sum, entry) => sum + countChars(entry.text), 0)
337
337
  const trace = store.readTrace()
338
338
  const lastProject = [...trace].reverse().find((row) => row.project)?.project ?? (store.listProjectKeys()[0] ?? null)
339
- const globalChars = store.read('global', null).entries.reduce((sum, entry) => sum + countChars(entry.text), 0)
340
- const projectChars = lastProject ? store.read('project', lastProject).entries.reduce((sum, entry) => sum + countChars(entry.text), 0) : 0
339
+ const activeEntries = entries.filter((entry) => statusOf(meta, entry, config) === 'active')
340
+ const globalChars = activeEntries.filter((entry) => entry.scope === 'global').reduce((sum, entry) => sum + countChars(entry.text), 0)
341
+ const projectChars = lastProject ? activeEntries.filter((entry) => entry.scope === 'project' && entry.key === lastProject).reduce((sum, entry) => sum + countChars(entry.text), 0) : 0
341
342
  const chars = Math.min(globalChars, config.maxInjectionChars) + Math.min(projectChars, config.maxInjectionChars)
342
343
  return {
343
344
  ok: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-memory-metabolism",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Local-first Markdown memory for DeepSeek Harness with a full-page memory workbench, independent chat threads, project scoping and a restricted memory assistant.",
5
5
  "type": "module",
6
6
  "exports": {