dsh-memory-metabolism 0.2.0 → 0.2.1

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/client.js CHANGED
@@ -67,7 +67,12 @@ window.__ModuleLoader__.load({
67
67
  wbOrganizer: '整理记忆', wbCandidates: '候选', wbDuplicates: '重复组', wbDuplicateEntries: '涉及条目', wbFadingItems: '淡忘', wbScan: '扫描重复', wbAskOrganizer: '让助手整理', wbNoDup: '没有发现重复。', wbOrganizerHint: '先扫描,再让助手给出方案;不会自动改。',
68
68
  wbModel: '模型', wbAuto: '自动', wbHistory: '历史预算', wbRounds: '最大工具轮数', wbDocLimit: '文档上限', wbSaveSettings: '保存设置', wbSettingsSaved: '设置已保存。', wbClose: '关闭',
69
69
  wbProjects: '项目', wbThreadProject: '项目', wbError: '出错:{error}', wbStopped: '已停止。', wbToolSearch: '搜索记忆', wbToolRead: '读取记忆', wbToolStatus: '记忆状态', wbToolConsolidate: '重复检查', wbToolApply: '应用记忆',
70
- wbTools: '工具', wbDeleteHint: '删除后不可恢复。', wbModelHint: '只用于本插件聊天,不影响主会话。',
70
+ wbTools: '工具', wbDeleteHint: '删除后不可恢复。', wbModelHint: '只用于本插件聊天,不影响主会话。',
71
+ wbMemory: '记忆条目', wbAssistantPanel: '记忆助手', wbSearchMemory: '搜索记忆…', wbAll: '全部', wbNoMemory: '没有匹配的条目。',
72
+ wbAutoOrganize: '自动整理', wbAutoOrganizeHint: '每段请求安静后后台提炼日志和候选;不会自动改人格或归档。',
73
+ wbDiagnostics: '诊断', wbInjectionPreview: '注入预览', wbLastInjections: '最近注入', wbOrganizerState: '自动整理器', wbErrors: '最近错误', wbNoDiagnostics: '暂无诊断数据。', wbPreviewTotal: '合计', wbTruncated: '已截断', wbDiagRefresh: '刷新诊断', wbNoErrors: '没有记录错误。', wbNoOrganizer: '还没有运行记录。',
74
+ wbFileEntries: '文件入口', wbOpenData: '数据目录', wbOpenGlobal: '全局记忆', wbOpenProject: '项目记忆', wbOpenPersona: '插件人格', wbOpenConventions: '协作约定', wbOpenHostPersona: 'AGENTS.md', wbOpenReferences: '参考文档', wbOpenChats: '对话记录', wbMoved: '已重新分级。', wbMoveToGlobal: '移到用户级', wbMoveToProject: '移到项目级', wbNoForget: '免遗忘', wbOpenFailed: '打开失败:{error}', wbPathHint: '只打开已知文件/目录,不接受任意路径。',
75
+ wbUseful: '有用', wbApprove: '批准', wbArchiveConfirm: '归档这条记忆?归档后不再注入,但不会物理删除。', wbMemoryHint: '主区域直接浏览和操作;助手只在需要时处理。', wbRetention: '留存', wbShowAssistant: '显示助手', wbHideAssistant: '收起助手', wbDirectAction: '直接操作',
71
76
  },
72
77
  en: {
73
78
  nav: 'Memory metabolism', title: 'Memory metabolism',
@@ -129,7 +134,12 @@ window.__ModuleLoader__.load({
129
134
  wbOrganizer: 'Organize memory', wbCandidates: 'Candidates', wbDuplicates: 'Duplicate groups', wbDuplicateEntries: 'Entries involved', wbFadingItems: 'Fading', wbScan: 'Scan duplicates', wbAskOrganizer: 'Ask the assistant', wbNoDup: 'No duplicates found.', wbOrganizerHint: 'Scan first, then ask the assistant for a plan; nothing is applied automatically.',
130
135
  wbModel: 'Model', wbAuto: 'Auto', wbHistory: 'History budget', wbRounds: 'Max tool rounds', wbDocLimit: 'Document limit', wbSaveSettings: 'Save settings', wbSettingsSaved: 'Settings saved.', wbClose: 'Close',
131
136
  wbProjects: 'Projects', wbThreadProject: 'Project', wbError: 'Error: {error}', wbStopped: 'Stopped.', wbToolSearch: 'Search memory', wbToolRead: 'Read memory', wbToolStatus: 'Memory status', wbToolConsolidate: 'Duplicate scan', wbToolApply: 'Apply memory',
132
- wbTools: 'Tools', wbDeleteHint: 'This cannot be undone.', wbModelHint: 'Only for this plugin chat; does not affect the main session.',
137
+ wbTools: 'Tools', wbDeleteHint: 'This cannot be undone.', wbModelHint: 'Only for this plugin chat; does not affect the main session.',
138
+ wbMemory: 'Memories', wbAssistantPanel: 'Memory assistant', wbSearchMemory: 'Search memories…', wbAll: 'All', wbNoMemory: 'No matching memories.',
139
+ wbAutoOrganize: 'Auto-organize', wbAutoOrganizeHint: 'After a request settles, extract a daily log and memory candidates in the background; never edits persona or archives on its own.',
140
+ wbDiagnostics: 'Diagnostics', wbInjectionPreview: 'Injection preview', wbLastInjections: 'Recent injections', wbOrganizerState: 'Auto organizer', wbErrors: 'Recent errors', wbNoDiagnostics: 'No diagnostics yet.', wbPreviewTotal: 'Total', wbTruncated: 'truncated', wbDiagRefresh: 'Refresh diagnostics', wbNoErrors: 'No recorded errors.', wbNoOrganizer: 'No organizer run yet.',
141
+ wbFileEntries: 'File entries', wbOpenData: 'Data folder', wbOpenGlobal: 'Global memory', wbOpenProject: 'Project memory', wbOpenPersona: 'Plugin persona', wbOpenConventions: 'Conventions', wbOpenHostPersona: 'AGENTS.md', wbOpenReferences: 'References', wbOpenChats: 'Chat logs', wbMoved: 'Reclassified.', wbMoveToGlobal: 'Move to user', wbMoveToProject: 'Move to project', wbNoForget: 'No-forget', wbOpenFailed: 'Open failed: {error}', wbPathHint: 'Only known files/folders can be opened; arbitrary paths are rejected.',
142
+ wbUseful: 'Useful', wbApprove: 'Approve', wbArchiveConfirm: 'Archive this memory? It will stop being injected, but is not deleted.', wbMemoryHint: 'Browse and act directly in the main area; use the assistant only when needed.', wbRetention: 'Retention', wbShowAssistant: 'Show assistant', wbHideAssistant: 'Hide assistant', wbDirectAction: 'Direct actions',
133
143
  },
134
144
  }
135
145
 
@@ -275,7 +285,7 @@ window.__ModuleLoader__.load({
275
285
  '.mmx-btn:hover:not(:disabled){background:var(--mmx-hover)}.mmx-btn:disabled{opacity:.45;cursor:default}',
276
286
  '.mmx-btn-primary{border-color:transparent;background:var(--mmx-c-cyan);color:#fff}.mmx-btn-primary:hover:not(:disabled){filter:brightness(1.06);background:var(--mmx-c-cyan)}',
277
287
  '.mmx-btn-org{border-color:color-mix(in srgb,var(--mmx-c-purple) 42%,var(--mmx-border));color:var(--mmx-c-purple);background:color-mix(in srgb,var(--mmx-c-purple) 8%,var(--mmx-surface))}',
278
- '.mmx-overview{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px;margin-bottom:12px}',
288
+ '.mmx-overview{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px;margin-bottom:12px}',
279
289
  '.mmx-card{border:1px solid var(--mmx-border);border-radius:9px;background:var(--mmx-surface);padding:13px 14px;min-width:0;position:relative;overflow:hidden}',
280
290
  '.mmx-card:after{content:"";position:absolute;inset:0 0 auto 0;height:1px;background:linear-gradient(90deg,transparent,color-mix(in srgb,var(--mmx-c-cyan) 35%,transparent),transparent)}',
281
291
  '.mmx-card-label{color:var(--mmx-caption);font-size:10px;line-height:14px;text-transform:uppercase;letter-spacing:.09em;margin-bottom:5px}',
@@ -353,6 +363,39 @@ window.__ModuleLoader__.load({
353
363
  '.mmx-notice.err{color:var(--mmx-c-red);border-color:color-mix(in srgb,var(--mmx-c-red) 30%,var(--mmx-border))}',
354
364
  '@media (max-width:1000px){.mmx-overview{grid-template-columns:repeat(2,minmax(0,1fr))}.mmx-workbench{grid-template-columns:220px minmax(0,1fr)}}',
355
365
  '@media (max-width:760px){.mmx-root{padding:16px}.mmx-workbench{grid-template-columns:1fr;height:auto;min-height:560px}.mmx-rail{max-height:180px;border-right:0;border-bottom:1px solid var(--mmx-border)}.mmx-thread-list{flex-direction:column}.mmx-overview{grid-template-columns:1fr}.mmx-stages{grid-template-columns:repeat(3,minmax(0,1fr))}.mmx-actions{justify-content:flex-start}.mmx-chat-body{padding:12px}.mmx-msg{max-width:94%}}',
366
+ '.mmx-layout{display:flex;align-items:flex-start;gap:16px;width:100%}',
367
+ '.mmx-main{flex:1;min-width:0;display:flex;flex-direction:column;gap:0}',
368
+ '.mmx-assistant{width:380px;flex:0 0 380px;display:flex;flex-direction:column;min-height:560px;height:min(720px,calc(100vh - 280px));position:sticky;top:0;border:1px solid var(--mmx-border);border-radius:11px;background:var(--mmx-surface);overflow:hidden}',
369
+ '.mmx-side-title-wrap{min-width:0;display:flex;flex-direction:column;gap:2px}',
370
+ '.mmx-side-sub{font-size:10px;line-height:14px;color:var(--mmx-caption);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:240px}',
371
+ '.mmx-thread-picker{display:flex;align-items:center;gap:6px;padding:8px 10px;border-bottom:1px solid var(--mmx-border);background:var(--mmx-surface-2)}',
372
+ '.mmx-thread-picker select{flex:1;min-width:0;height:28px;border:1px solid var(--mmx-border);border-radius:6px;background:var(--mmx-surface);color:var(--mmx-text);padding:0 6px;font:inherit;font-size:11px}',
373
+ '.mmx-thread-picker .mmx-btn{height:28px;padding:0 8px}',
374
+ '.mmx-assistant .mmx-chat-body{padding:12px}',
375
+ '.mmx-assistant .mmx-msg{max-width:96%}',
376
+ '.mmx-assistant .mmx-composer{padding:9px 10px 7px}',
377
+ '.mmx-memory-panel{border:1px solid var(--mmx-border);border-radius:11px;background:var(--mmx-surface);overflow:hidden;margin-top:12px;display:flex;flex-direction:column}',
378
+ '.mmx-panel-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:13px 14px;border-bottom:1px solid var(--mmx-border)}',
379
+ '.mmx-panel-title{font-size:13px;font-weight:650}.mmx-panel-sub{font-size:11px;line-height:16px;color:var(--mmx-muted);margin-top:2px}',
380
+ '.mmx-panel-count{font-size:12px;color:var(--mmx-c-cyan);font-variant-numeric:tabular-nums}',
381
+ '.mmx-memory-toolbar{display:flex;align-items:center;gap:8px;padding:10px 14px;border-bottom:1px solid var(--mmx-border);flex-wrap:wrap}',
382
+ '.mmx-memory-search{flex:1 1 220px;height:30px;border:1px solid var(--mmx-border);border-radius:7px;background:var(--mmx-bg);color:var(--mmx-text);padding:0 9px;font:inherit;font-size:12px;outline:none}',
383
+ '.mmx-memory-search:focus{border-color:color-mix(in srgb,var(--mmx-c-cyan) 45%,var(--mmx-border))}',
384
+ '.mmx-filter-bar{display:flex;align-items:center;gap:4px;flex-wrap:wrap}',
385
+ '.mmx-filter{height:26px;padding:0 8px;border:1px solid var(--mmx-border);border-radius:999px;background:transparent;color:var(--mmx-muted);font-size:11px;cursor:pointer}',
386
+ '.mmx-filter.on{color:var(--mmx-c-cyan);border-color:color-mix(in srgb,var(--mmx-c-cyan) 38%,var(--mmx-border));background:color-mix(in srgb,var(--mmx-c-cyan) 8%,transparent)}',
387
+ '.mmx-memory-list{display:flex;flex-direction:column;max-height:min(430px,calc(100vh - 500px));overflow:auto}',
388
+ '.mmx-memory-row{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:11px 14px;border-bottom:1px solid var(--mmx-border)}',
389
+ '.mmx-memory-row:last-child{border-bottom:0}.mmx-memory-row:hover{background:var(--mmx-hover)}',
390
+ '.mmx-memory-main{min-width:0;flex:1}.mmx-memory-text{font-size:12px;line-height:18px;color:var(--mmx-text);white-space:pre-wrap;overflow-wrap:anywhere}',
391
+ '.mmx-memory-meta{display:flex;align-items:center;gap:5px;flex-wrap:wrap;margin-top:5px}',
392
+ '.mmx-memory-actions{display:flex;align-items:center;gap:5px;flex:none;flex-wrap:wrap;justify-content:flex-end}',
393
+ '.mmx-memory-actions .mmx-btn{height:26px;padding:0 8px;font-size:11px}',
394
+ '.mmx-file-grid{display:flex;align-items:center;gap:6px;flex-wrap:wrap}',
395
+ '.mmx-file-grid .mmx-btn{height:26px;padding:0 8px;font-size:11px}',
396
+ '.mmx-panel-foot{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:8px 14px;border-top:1px solid var(--mmx-border);color:var(--mmx-caption);font-size:10px}',
397
+ '@media (max-width:1100px){.mmx-layout{flex-direction:column}.mmx-assistant{width:100%;flex-basis:auto;height:560px;position:static}}',
398
+ '@media (max-width:760px){.mmx-memory-toolbar{align-items:stretch}.mmx-memory-search{flex-basis:100%}.mmx-memory-row{flex-direction:column}.mmx-memory-actions{justify-content:flex-start}}',
356
399
  ].join('\n')
357
400
 
358
401
  function MemoryConsole(props) {
@@ -567,7 +610,14 @@ window.__ModuleLoader__.load({
567
610
  const [notice, setNotice] = useState(null)
568
611
  const [modal, setModal] = useState(null)
569
612
  const [orgReport, setOrgReport] = useState(null)
570
- const [orgBusy, setOrgBusy] = useState(false)
613
+ const [orgBusy, setOrgBusy] = useState(false)
614
+ const [memEntries, setMemEntries] = useState([])
615
+ const [memQuery, setMemQuery] = useState('')
616
+ const [memFilter, setMemFilter] = useState('all')
617
+ const [memBusy, setMemBusy] = useState(false)
618
+ const [sideOpen, setSideOpen] = useState(true)
619
+ const [diagnostics, setDiagnostics] = useState(null)
620
+ const [diagBusy, setDiagBusy] = useState(false)
571
621
  const abortRef = useRef(null)
572
622
  const bodyRef = useRef(null)
573
623
  const activeRef = useRef('')
@@ -580,10 +630,12 @@ window.__ModuleLoader__.load({
580
630
  try {
581
631
  const state = await call('/api/memory-metabolism/status')
582
632
  const list = await call('/api/memory-metabolism/chat/threads')
583
- const modelDoc = await call('/api/memory-metabolism/chat/models').catch(() => ({ providers: [] }))
633
+ const modelDoc = await call('/api/memory-metabolism/chat/models').catch(() => ({ providers: [] }))
634
+ const entriesDoc = await call('/api/memory-metabolism/entries').catch(() => ({ entries: [] }))
584
635
  setStatus(state)
585
636
  setSettings({ ...(state.config || {}) })
586
- setModels(modelDoc.providers || [])
637
+ setModels(modelDoc.providers || [])
638
+ setMemEntries(entriesDoc.entries || [])
587
639
  const items = list.threads || []
588
640
  setThreads(items)
589
641
  const nextId = activeRef.current || items[0]?.id || ''
@@ -609,7 +661,77 @@ window.__ModuleLoader__.load({
609
661
  }
610
662
  }, [])
611
663
 
612
- useEffect(() => { void loadAll() }, [loadAll])
664
+ useEffect(() => { void loadAll() }, [loadAll])
665
+
666
+ const refreshMemories = async () => {
667
+ const state = await call('/api/memory-metabolism/status')
668
+ const entriesDoc = await call('/api/memory-metabolism/entries').catch(() => ({ entries: [] }))
669
+ setStatus(state)
670
+ setSettings({ ...(state.config || {}) })
671
+ setMemEntries(entriesDoc.entries || [])
672
+ }
673
+
674
+ const openEntry = async (kind) => {
675
+ try {
676
+ await call('/api/memory-metabolism/open', { kind, project: status?.lastProject })
677
+ } catch (error) {
678
+ setNotice({ kind: 'err', text: tx('wbOpenFailed', { error: error.message }) })
679
+ }
680
+ }
681
+
682
+ const openDiagnostics = async () => {
683
+ setDrawer('diagnostics')
684
+ setDiagBusy(true)
685
+ try {
686
+ const project = status?.lastProject || ''
687
+ const doc = await call('/api/memory-metabolism/diagnostics' + (project ? '?project=' + encodeURIComponent(project) : ''))
688
+ setDiagnostics(doc)
689
+ } catch (error) {
690
+ setNotice({ kind: 'err', text: tx('wbError', { error: error.message }) })
691
+ } finally { setDiagBusy(false) }
692
+ }
693
+
694
+ const reclassifyMemory = async (entry) => {
695
+ if (!entry || memBusy) return
696
+ const target = entry.scope === 'global' ? 'project' : 'global'
697
+ const project = target === 'project' ? (entry.scope === 'project' ? entry.key : status?.lastProject) : undefined
698
+ setMemBusy(true)
699
+ try {
700
+ await call('/api/memory-metabolism/reclassify', { id: entry.id, scope: target, project })
701
+ await refreshMemories()
702
+ setNotice({ kind: 'ok', text: t('wbMoved') })
703
+ } catch (error) { setNotice({ kind: 'err', text: tx('wbError', { error: error.message }) }) }
704
+ finally { setMemBusy(false) }
705
+ }
706
+
707
+ const archiveMemory = async (id) => {
708
+ if (!id || !window.confirm(t('wbArchiveConfirm'))) return
709
+ setMemBusy(true)
710
+ try {
711
+ await call('/api/memory-metabolism/archive', { id })
712
+ await refreshMemories()
713
+ setNotice({ kind: 'ok', text: t('wbArchive') })
714
+ } catch (error) { setNotice({ kind: 'err', text: tx('wbError', { error: error.message }) }) }
715
+ finally { setMemBusy(false) }
716
+ }
717
+
718
+ const feedbackMemory = async (id) => {
719
+ setMemBusy(true)
720
+ try {
721
+ await call('/api/memory-metabolism/feedback', { id, signal: 'useful' })
722
+ await refreshMemories()
723
+ } catch (error) { setNotice({ kind: 'err', text: tx('wbError', { error: error.message }) }) }
724
+ finally { setMemBusy(false) }
725
+ }
726
+
727
+ const approveMemory = async (id) => {
728
+ setMemBusy(true)
729
+ try {
730
+ await call('/api/memory-metabolism/approve', { id })
731
+ await refreshMemories()
732
+ } catch (error) { setNotice({ kind: 'err', text: tx('wbError', { error: error.message }) }) }
733
+ finally { setMemBusy(false) }
734
+ }
613
735
 
614
736
  useEffect(() => {
615
737
  if (!bodyRef.current) return
@@ -802,7 +924,9 @@ window.__ModuleLoader__.load({
802
924
  await call('/api/memory-metabolism/config', {
803
925
  assistantModel: settings.assistantModel || '',
804
926
  chatHistoryChars: Number(settings.chatHistoryChars) || 24000,
805
- chatMaxRounds: Number(settings.chatMaxRounds) || 6,
927
+ chatMaxRounds: Number(settings.chatMaxRounds) || 6,
928
+ autoOrganize: settings.autoOrganize !== false,
929
+ autoOrganizeModel: settings.autoOrganizeModel || '',
806
930
  assistantMaxInputChars: Number(settings.assistantMaxInputChars) || 120000,
807
931
  })
808
932
  const state = await call('/api/memory-metabolism/status')
@@ -872,10 +996,6 @@ window.__ModuleLoader__.load({
872
996
  h('div', null,
873
997
  h('div', { className: 'mmx-card-value', style: { fontSize: '18px' } }, chars, h('small', null, '/ ' + budget)),
874
998
  h('div', { className: 'mmx-card-note' }, t('wbTotalChars') + ' ' + totalChars)))),
875
- h('div', { className: 'mmx-card' },
876
- h('div', { className: 'mmx-card-label' }, t('wbProject')),
877
- h('div', { className: 'mmx-card-value', style: { fontSize: '18px' } }, status?.lastProject || '—'),
878
- h('div', { className: 'mmx-card-note' }, (status?.projects?.length || 0) + ' ' + t('wbProjects') + ' · ' + threads.length + ' ' + t('wbThreads'))),
879
999
  h('div', { className: 'mmx-card' },
880
1000
  h('div', { className: 'mmx-card-label' }, t('wbPending')),
881
1001
  h('div', { className: 'mmx-card-value' }, candidate + (orgReport?.duplicateGroups?.length || 0), h('small', null, t('wbCandidate') + ' + ' + t('wbDuplicates'))),
@@ -903,51 +1023,115 @@ window.__ModuleLoader__.load({
903
1023
  h('div', { className: 'mmx-actions' },
904
1024
  h('button', { className: 'mmx-btn', onClick: () => void loadAll() }, t('wbRefresh')),
905
1025
  h('button', { className: 'mmx-btn mmx-btn-org', onClick: () => void openOrganizer() }, t('wbOrganize')),
1026
+ h('button', { className: 'mmx-btn', onClick: () => void openDiagnostics() }, t('wbDiagnostics')),
1027
+ h('button', { className: 'mmx-btn', onClick: () => setSideOpen((value) => !value) }, sideOpen ? t('wbHideAssistant') : t('wbShowAssistant')),
906
1028
  h('button', { className: 'mmx-btn mmx-btn-primary', onClick: () => void createThread() }, '+ ' + t('wbNewChat')),
907
1029
  h('button', { className: 'mmx-btn', onClick: () => { setDrawer('settings'); setSettings({ ...(status?.config || {}) }) } }, t('wbSettings'))))
908
1030
 
909
- const chatHead = h('div', { className: 'mmx-chat-head' },
910
- h('div', { className: 'mmx-chat-title' }, thread?.title || t('wbNewChat')),
911
- h('div', { className: 'mmx-chat-tools' },
912
- h('span', { className: 'mmx-badge' }, thread?.project || status?.lastProject || '—'),
913
- h('span', { className: 'mmx-badge mmx-badge-accent' }, settings.assistantModel || t('wbAuto')),
914
- h('button', { className: 'mmx-btn', onClick: () => { setDrawer('settings'); setSettings({ ...(status?.config || {}) }) } }, t('wbSettings'))))
915
-
916
- const chatBody = h('div', { className: 'mmx-chat-body', ref: bodyRef },
917
- loading ? h('div', { className: 'mmx-empty' }, t('wbThinking'))
918
- : messages.length === 0 ? h('div', { className: 'mmx-empty' },
919
- h('div', null, t('wbNoMessages')),
920
- h('div', { className: 'mmx-badge' }, t('wbLocalOnly')))
921
- : messages.map((message, index) => h(MemoryChatMessage, { key: message.id || index, message, t })),
922
- streaming ? h('div', { className: 'mmx-typing' }, h('i'), h('i'), h('i'), h('span', null, t('wbThinking'))) : null)
923
-
924
- const composer = h('div', { className: 'mmx-composer' },
925
- doc ? h('div', { className: 'mmx-file' }, tx('wbAttached', { name: doc.name }),
926
- h('button', { className: 'mmx-rail-new', style: { height: '18px', padding: '0 5px' }, onClick: () => setDoc(null) }, '×')) : null,
927
- h('textarea', {
928
- value: input,
929
- placeholder: t('wbInput'),
930
- onChange: (event) => setInput(event.target.value),
931
- onKeyDown: (event) => { if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault(); void send() } },
932
- }),
933
- h('div', { className: 'mmx-composer-row' },
934
- h('label', { className: 'mmx-btn', style: { cursor: 'pointer' } }, t('wbAttach'),
935
- h('input', { type: 'file', accept: '.md,.txt,.json,.csv,text/plain,text/markdown,application/json', style: { display: 'none' }, onChange: (event) => void pickDoc(event) })),
936
- streaming
937
- ? h('button', { className: 'mmx-btn mmx-btn-org', onClick: () => void stop() }, t('wbStop'))
938
- : h('button', { className: 'mmx-btn mmx-btn-primary', disabled: !input.trim() && !doc, onClick: () => void send() }, t('wbSend')),
939
- h('span', { className: 'mmx-right mmx-badge' }, t('wbModelHint'))),
940
- h('div', { className: 'mmx-composer-foot' },
941
- h('span', null, t('wbLocalOnly')),
942
- h('span', null, (status?.lastProject || '') + ' · ' + total + ' ' + t('wbTotal'))))
943
-
944
- const workbench = h('div', { className: 'mmx-workbench' },
945
- h('aside', { className: 'mmx-rail' },
946
- h('div', { className: 'mmx-rail-head' }, h('span', null, t('wbChats')), h('button', { className: 'mmx-rail-new', onClick: () => void createThread() }, '+ ' + t('wbNew'))),
947
- h('div', { className: 'mmx-thread-list' }, threads.length ? threads.map(threadRow) : h('div', { className: 'mmx-empty' }, t('wbEmptyThreads'))),
948
- h('div', { className: 'mmx-rail-foot' }, h('span', null, '●'), h('span', null, t('wbLocalOnly')))),
949
- h('section', { className: 'mmx-chat' }, chatHead, chatBody, composer))
950
-
1031
+ const chatHead = h('div', { className: 'mmx-chat-head' },
1032
+ h('div', { className: 'mmx-side-title-wrap' },
1033
+ h('div', { className: 'mmx-chat-title' }, thread?.title || t('wbNewChat')),
1034
+ h('div', { className: 'mmx-side-sub' }, (thread?.project || status?.lastProject || '—') + ' · ' + (settings.assistantModel || t('wbAuto')))),
1035
+ h('div', { className: 'mmx-chat-tools' },
1036
+ h('button', { className: 'mmx-btn', onClick: () => { setDrawer('settings'); setSettings({ ...(status?.config || {}) }) } }, t('wbSettings')),
1037
+ h('button', { className: 'mmx-btn', onClick: () => setSideOpen(false) }, t('wbHideAssistant'))))
1038
+
1039
+ const threadPicker = h('div', { className: 'mmx-thread-picker' },
1040
+ h('select', {
1041
+ value: activeId || '',
1042
+ onChange: (event) => void selectThread(event.target.value),
1043
+ disabled: threads.length === 0,
1044
+ }, threads.length
1045
+ ? threads.map((item) => h('option', { key: item.id, value: item.id }, item.title || t('wbNewChat')))
1046
+ : h('option', { value: '' }, t('wbEmptyThreads'))),
1047
+ h('button', { className: 'mmx-btn', title: t('wbNewChat'), onClick: () => void createThread() }, '+'),
1048
+ h('button', { className: 'mmx-btn', title: t('wbChats'), disabled: !thread, onClick: () => thread && openThreadMenu(thread) }, '⋯'))
1049
+
1050
+ const chatBody = h('div', { className: 'mmx-chat-body', ref: bodyRef },
1051
+ loading ? h('div', { className: 'mmx-empty' }, t('wbThinking'))
1052
+ : messages.length === 0 ? h('div', { className: 'mmx-empty' },
1053
+ h('div', null, t('wbNoMessages')),
1054
+ h('div', { className: 'mmx-badge' }, t('wbLocalOnly')))
1055
+ : messages.map((message, index) => h(MemoryChatMessage, { key: message.id || index, message, t })),
1056
+ streaming ? h('div', { className: 'mmx-typing' }, h('i'), h('i'), h('i'), h('span', null, t('wbThinking'))) : null)
1057
+
1058
+ const composer = h('div', { className: 'mmx-composer' },
1059
+ doc ? h('div', { className: 'mmx-file' }, tx('wbAttached', { name: doc.name }),
1060
+ h('button', { className: 'mmx-rail-new', style: { height: '18px', padding: '0 5px' }, onClick: () => setDoc(null) }, '×')) : null,
1061
+ h('textarea', {
1062
+ value: input,
1063
+ placeholder: t('wbInput'),
1064
+ onChange: (event) => setInput(event.target.value),
1065
+ onKeyDown: (event) => { if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault(); void send() } },
1066
+ }),
1067
+ h('div', { className: 'mmx-composer-row' },
1068
+ h('label', { className: 'mmx-btn', style: { cursor: 'pointer' } }, t('wbAttach'),
1069
+ h('input', { type: 'file', accept: '.md,.txt,.json,.csv,text/plain,text/markdown,application/json', style: { display: 'none' }, onChange: (event) => void pickDoc(event) })),
1070
+ streaming
1071
+ ? h('button', { className: 'mmx-btn mmx-btn-org', onClick: () => void stop() }, t('wbStop'))
1072
+ : h('button', { className: 'mmx-btn mmx-btn-primary', disabled: !input.trim() && !doc, onClick: () => void send() }, t('wbSend')),
1073
+ h('span', { className: 'mmx-right mmx-badge' }, t('wbModelHint'))),
1074
+ h('div', { className: 'mmx-composer-foot' },
1075
+ h('span', null, t('wbLocalOnly')),
1076
+ h('span', null, (status?.lastProject || '') + ' · ' + total + ' ' + t('wbTotal'))))
1077
+
1078
+ const statusKey = (value) => ({ active: 'statusActive', candidate: 'statusCandidate', fading: 'statusFading', archived: 'statusArchived', disputed: 'statusDisputed', excluded: 'statusExcluded' }[value] || 'statusActive')
1079
+ const scopeKey = (value) => ({ global: 'scopeGlobal', project: 'scopeProject', reference: 'scopeReference' }[value] || 'wbAll')
1080
+ const memoryFilters = [
1081
+ { key: 'all', label: 'wbAll' },
1082
+ { key: 'global', label: 'scopeGlobal' },
1083
+ { key: 'project', label: 'scopeProject' },
1084
+ { key: 'candidate', label: 'statusCandidate' },
1085
+ { key: 'fading', label: 'statusFading' },
1086
+ ]
1087
+ const needle = memQuery.trim().toLowerCase()
1088
+ const filteredMemories = memEntries.filter((entry) => {
1089
+ if (memFilter === 'global' && entry.scope !== 'global') return false
1090
+ if (memFilter === 'project' && entry.scope !== 'project') return false
1091
+ if (memFilter === 'candidate' && entry.status !== 'candidate') return false
1092
+ if (memFilter === 'fading' && entry.status !== 'fading') return false
1093
+ if (needle && !String(entry.text || '').toLowerCase().includes(needle)) return false
1094
+ return true
1095
+ })
1096
+ const memoryRow = (entry) => h('div', { key: entry.id, className: 'mmx-memory-row' },
1097
+ h('div', { className: 'mmx-memory-main' },
1098
+ h('div', { className: 'mmx-memory-text' }, entry.text),
1099
+ h('div', { className: 'mmx-memory-meta' },
1100
+ h('span', { className: 'mmx-badge' }, t(scopeKey(entry.scope))),
1101
+ entry.section ? h('span', { className: 'mmx-badge' }, entry.section) : null,
1102
+ h('span', { className: 'mmx-badge' }, t(statusKey(entry.status))),
1103
+ entry.pinned ? h('span', { className: 'mmx-badge mmx-badge-accent' }, t('wbNoForget')) : null,
1104
+ h('span', { className: 'mmx-badge' }, Math.round((Number(entry.retention) || 0) * 100) + '% ' + t('wbRetention')))),
1105
+ h('div', { className: 'mmx-memory-actions' },
1106
+ entry.status === 'candidate'
1107
+ ? h('button', { className: 'mmx-btn mmx-btn-primary', disabled: memBusy, onClick: () => void approveMemory(entry.id) }, t('wbApprove'))
1108
+ : h('button', { className: 'mmx-btn', disabled: memBusy, onClick: () => void feedbackMemory(entry.id) }, t('wbUseful')),
1109
+ h('button', { className: 'mmx-btn', disabled: memBusy, onClick: () => void reclassifyMemory(entry) }, entry.scope === 'global' ? t('wbMoveToProject') : t('wbMoveToGlobal')),
1110
+ h('button', { className: 'mmx-btn mmx-btn-org', disabled: memBusy, onClick: () => void archiveMemory(entry.id) }, t('wbArchive'))))
1111
+
1112
+ const memoryPanel = h('section', { className: 'mmx-memory-panel' },
1113
+ h('div', { className: 'mmx-panel-head' },
1114
+ h('div', null,
1115
+ h('div', { className: 'mmx-panel-title' }, t('wbMemory')),
1116
+ h('div', { className: 'mmx-panel-sub' }, t('wbMemoryHint'))),
1117
+ h('div', { className: 'mmx-panel-count' }, filteredMemories.length + ' / ' + memEntries.length)),
1118
+ h('div', { className: 'mmx-memory-toolbar' },
1119
+ h('input', { className: 'mmx-memory-search', value: memQuery, placeholder: t('wbSearchMemory'), onChange: (event) => setMemQuery(event.target.value) }),
1120
+ h('div', { className: 'mmx-filter-bar' }, memoryFilters.map((filter) => h('button', { key: filter.key, className: 'mmx-filter' + (memFilter === filter.key ? ' on' : ''), onClick: () => setMemFilter(filter.key) }, t(filter.label)))),
1121
+ h('button', { className: 'mmx-btn', onClick: () => void openEntry('data') }, t('wbOpenData')),
1122
+ h('button', { className: 'mmx-btn', disabled: memBusy, onClick: () => void refreshMemories() }, t('wbRefresh'))),
1123
+ h('div', { className: 'mmx-memory-list' }, filteredMemories.length
1124
+ ? filteredMemories.slice(0, 80).map(memoryRow)
1125
+ : h('div', { className: 'mmx-empty' }, t('wbNoMemory'))),
1126
+ h('div', { className: 'mmx-panel-foot' },
1127
+ h('span', null, t('wbDirectAction')),
1128
+ h('span', null, t('wbRetention') + ' · ' + total + ' ' + t('wbTotal'))))
1129
+
1130
+ const assistantSide = h('aside', { className: 'mmx-assistant' }, chatHead, threadPicker, chatBody, composer)
1131
+
1132
+ const layout = h('div', { className: 'mmx-layout' },
1133
+ h('main', { className: 'mmx-main' }, overviewCards, flow, memoryPanel),
1134
+ sideOpen ? assistantSide : null)
951
1135
  const organizerDrawer = drawer === 'organizer' ? h('div', { className: 'mmx-drawer' },
952
1136
  h('div', { className: 'mmx-drawer-head' },
953
1137
  h('div', { className: 'mmx-drawer-title' }, t('wbOrganizer')),
@@ -980,11 +1164,68 @@ window.__ModuleLoader__.load({
980
1164
  h('div', { className: 'mmx-field' }, h('label', null, t('wbHistory')), h('input', { type: 'number', min: '4000', step: '1000', value: settings.chatHistoryChars || 24000, onChange: (event) => setSettings({ ...settings, chatHistoryChars: Number(event.target.value) }) })),
981
1165
  h('div', { className: 'mmx-field' }, h('label', null, t('wbRounds')), h('input', { type: 'number', min: '1', max: '12', value: settings.chatMaxRounds || 6, onChange: (event) => setSettings({ ...settings, chatMaxRounds: Number(event.target.value) }) })),
982
1166
  h('div', { className: 'mmx-field' }, h('label', null, t('wbDocLimit')), h('input', { type: 'number', min: '1000', step: '1000', value: settings.assistantMaxInputChars || 120000, onChange: (event) => setSettings({ ...settings, assistantMaxInputChars: Number(event.target.value) }) })),
983
- h('div', { className: 'mmx-row' },
1167
+ h('label', { className: 'mmx-row', style: { alignItems: 'center', gap: '8px' } },
1168
+ h('input', { type: 'checkbox', checked: settings.autoOrganize !== false, onChange: (event) => setSettings({ ...settings, autoOrganize: event.target.checked }) }),
1169
+ h('span', null, t('wbAutoOrganize')),
1170
+ h('span', { className: 'mmx-hint' }, t('wbAutoOrganizeHint'))),
1171
+ h('div', { className: 'mmx-section' },
1172
+ h('div', { className: 'mmx-section-title' }, t('wbFileEntries')),
1173
+ h('div', { className: 'mmx-hint' }, t('wbPathHint')),
1174
+ h('div', { className: 'mmx-file-grid' },
1175
+ h('button', { className: 'mmx-btn', onClick: () => void openEntry('data') }, t('wbOpenData')),
1176
+ h('button', { className: 'mmx-btn', onClick: () => void openEntry('global') }, t('wbOpenGlobal')),
1177
+ h('button', { className: 'mmx-btn', onClick: () => void openEntry('project') }, t('wbOpenProject')),
1178
+ h('button', { className: 'mmx-btn', onClick: () => void openEntry('hostPersona') }, t('wbOpenHostPersona')),
1179
+ h('button', { className: 'mmx-btn', onClick: () => void openEntry('conventions') }, t('wbOpenConventions')),
1180
+ h('button', { className: 'mmx-btn', onClick: () => void openEntry('persona') }, t('wbOpenPersona')),
1181
+ h('button', { className: 'mmx-btn', onClick: () => void openEntry('references') }, t('wbOpenReferences')),
1182
+ h('button', { className: 'mmx-btn', onClick: () => void openEntry('chats') }, t('wbOpenChats')))),
1183
+ h('div', { className: 'mmx-row' },
984
1184
  h('button', { className: 'mmx-btn mmx-btn-primary', onClick: () => void saveSettings() }, t('wbSaveSettings')),
985
1185
  h('button', { className: 'mmx-btn', onClick: () => setDrawer('') }, t('wbClose'))),
986
1186
  h('div', { className: 'mmx-notice' }, t('wbModelHint')))) : null
987
1187
 
1188
+ const diagnosticsDrawer = drawer === 'diagnostics' ? h('div', { className: 'mmx-drawer' },
1189
+ h('div', { className: 'mmx-drawer-head' },
1190
+ h('div', { className: 'mmx-drawer-title' }, t('wbDiagnostics')),
1191
+ h('button', { className: 'mmx-drawer-close', onClick: () => setDrawer('') }, '×')),
1192
+ h('div', { className: 'mmx-drawer-body' },
1193
+ diagBusy ? h('div', { className: 'mmx-empty' }, t('wbThinking')) : !diagnostics ? h('div', { className: 'mmx-empty' }, t('wbNoDiagnostics')) : h('div', null,
1194
+ h('div', { className: 'mmx-section' },
1195
+ h('div', { className: 'mmx-section-title' }, t('wbInjectionPreview')),
1196
+ h('div', { className: 'mmx-kv' }, h('span', null, t('wbPreviewTotal')), h('b', null, (diagnostics.preview?.totalChars || 0) + ' / ' + (diagnostics.preview?.budget || 0))),
1197
+ h('div', { className: 'mmx-list' }, (diagnostics.preview?.sections || []).length
1198
+ ? diagnostics.preview.sections.map((item, index) => h('div', { key: index, className: 'mmx-list-item' },
1199
+ h('b', null, item.title), ' · ' + item.clippedChars + ' / ' + item.chars,
1200
+ item.truncated ? h('span', { className: 'mmx-badge mmx-c-yellow-text' }, t('wbTruncated')) : null,
1201
+ h('div', { className: 'mmx-hint' }, item.source || '')))
1202
+ : h('div', { className: 'mmx-empty' }, t('wbNoDiagnostics')))),
1203
+ h('div', { className: 'mmx-section' },
1204
+ h('div', { className: 'mmx-section-title' }, t('wbLastInjections')),
1205
+ h('div', { className: 'mmx-list' }, (diagnostics.lastInjections || []).length
1206
+ ? diagnostics.lastInjections.map((row, index) => h('div', { key: index, className: 'mmx-list-item' },
1207
+ shortDate(row.time) + ' · ' + (row.project || '—') + ' · ' + (row.ids?.length || 0) + ' ids · ' + (row.chars || 0) + ' chars'))
1208
+ : h('div', { className: 'mmx-empty' }, t('wbNoDiagnostics')))),
1209
+ h('div', { className: 'mmx-section' },
1210
+ h('div', { className: 'mmx-section-title' }, t('wbOrganizerState')),
1211
+ h('div', { className: 'mmx-list' },
1212
+ diagnostics.organizer?.time
1213
+ ? h('div', { className: 'mmx-list-item' },
1214
+ h('b', null, diagnostics.organizer.status || '—'), ' · ' + shortDate(diagnostics.organizer.time),
1215
+ h('div', { className: 'mmx-hint' }, 'model=' + (diagnostics.organizer.model || '—') + ' · proposals=' + (diagnostics.organizer.proposals || 0) + ' · written=' + (diagnostics.organizer.written || 0) + ' · candidates=' + (diagnostics.organizer.candidates || 0) + ' · skipped=' + (diagnostics.organizer.skipped || 0) + ' · ' + (diagnostics.organizer.durationMs || 0) + 'ms'),
1216
+ diagnostics.organizer.reason ? h('div', { className: 'mmx-hint' }, diagnostics.organizer.reason) : null,
1217
+ diagnostics.organizer.error ? h('div', { className: 'mmx-c-red-text' }, diagnostics.organizer.error) : null)
1218
+ : h('div', { className: 'mmx-empty' }, t('wbNoOrganizer')))),
1219
+ h('div', { className: 'mmx-section' },
1220
+ h('div', { className: 'mmx-section-title' }, t('wbErrors')),
1221
+ h('div', { className: 'mmx-list' }, (diagnostics.errors || []).length
1222
+ ? diagnostics.errors.slice(-8).reverse().map((row, index) => h('div', { key: index, className: 'mmx-list-item' },
1223
+ shortDate(row.time) + ' · ' + (row.stage || '—'), h('div', { className: 'mmx-c-red-text' }, row.message || '')))
1224
+ : h('div', { className: 'mmx-empty' }, t('wbNoErrors')))),
1225
+ h('div', { className: 'mmx-row' },
1226
+ h('button', { className: 'mmx-btn', onClick: () => void openDiagnostics() }, t('wbDiagRefresh')),
1227
+ h('button', { className: 'mmx-btn', onClick: () => setDrawer('') }, t('wbClose')))))) : null
1228
+
988
1229
  const modalEl = modal ? h('div', { className: 'mmx-modal-mask', onClick: () => setModal(null) },
989
1230
  h('div', { className: 'mmx-modal', onClick: (event) => event.stopPropagation() },
990
1231
  modal.kind === 'actions' ? h('div', null,
@@ -1011,11 +1252,10 @@ window.__ModuleLoader__.load({
1011
1252
  h('style', null, WORKBENCH_CSS),
1012
1253
  header,
1013
1254
  notice ? h('div', { className: 'mmx-notice ' + (notice.kind === 'err' ? 'err' : '') }, notice.text) : null,
1014
- overviewCards,
1015
- flow,
1016
- workbench,
1255
+ layout,
1017
1256
  organizerDrawer,
1018
1257
  settingsDrawer,
1258
+ diagnosticsDrawer,
1019
1259
  modalEl)
1020
1260
  }
1021
1261
 
package/docs/DETAIL.md CHANGED
@@ -15,7 +15,7 @@ L0 is the only layer that touches files. L2 never calls `fs.writeFile` directly;
15
15
 
16
16
  ## Storage
17
17
 
18
- - One Markdown file per scope: `global/MEMORY.md`, `projects/<key>/MEMORY.md`, `reference/<name>.md`.
18
+ - Global memory is `<dataDir>/global/MEMORY.md`. Project memory is `<project>/.deepseek-harness/MEMORY.md` plus `project.json`; the data directory keeps `meta/projects.json` as a root registry and legacy `projects/<key>/MEMORY.md` for migration. Reference documents live under `<dataDir>/reference/<name>.md`.
19
19
  - Each entry has a hidden `<!-- id: ... -->` comment. The id survives text edits; deleting the comment assigns a new id.
20
20
  - `meta/index.json` stores per-entry `S`, `D`, trust, use count, last use, status, importance and timestamps. It is a cache, not the source of truth; if it is lost, entries are rebuilt with defaults.
21
21
  - `meta/trace.json` stores the last 50 injection traces.
@@ -67,20 +67,37 @@ The trace records projection snapshots (file headings + ids) and search results
67
67
  - The system prompt section is constant. It explains the scopes, tools and write rules. Constant text keeps the prompt prefix stable.
68
68
  - Dynamic content is projected as user messages at `agent/pre-step`: persona (optional), conventions (optional), global memory, current project memory and an index of projects/references. Each projection has a heading identity; the same file is not injected twice in one surface. Compaction removes it, so the next step re-injects the current version.
69
69
  - The projection is deduplicated by heading, not by full text: editing a memory file does not cause a second copy of the same file identity.
70
- - The current project key is resolved from the session cwd at projection time. The system prompt never contains a project key, so two sessions with different projects do not share a cached key.
70
+ - The current project is resolved from the session cwd at projection time; registration writes/reads the project-local `MEMORY.md` and records a collision-safe key in `meta/projects.json`. The system prompt never contains a project key, so two sessions with different projects do not share a cached key.
71
71
 
72
72
  Limitations: the projection is a user message, not a system message. It is visible in the conversation history. This is intentional; it makes the injection auditable and survives compaction.
73
73
 
74
+ ## Auto organizer
75
+
76
+ The organizer listens to `session/event` and keeps a per-session buffer of real user, assistant and tool-result text. A request may span several agent turns, so `turn/end` only resets a quiet timer; it does not settle immediately. A new user message settles the previous request first.
77
+
78
+ After the quiet period it:
79
+
80
+ 1. Writes the buffered request to `<project>/.deepseek-harness/memory/YYYY-MM-DD.md` as evidence.
81
+ 2. Calls a model without tools and asks for a JSON array of durable proposals.
82
+ 3. Sends each proposal through `service.write` with the same write gate and deduplication. Non-explicit content becomes a candidate; explicit "remember" requests may become active.
83
+ 4. Persists the run summary in `meta/organizer.json` and errors in `meta/errors.jsonl`.
84
+
85
+ It never edits persona, archives, merges or runs commands. Plan mode and the plugin chat do not feed it. The model call can be disabled with `autoOrganize=false`.
86
+
87
+ ## Diagnostics
88
+
89
+ `GET /diagnostics` returns a read-only report: resolved paths, the exact projection sections that would be injected (with character counts and truncation), recent injection traces, the last organizer run and recent errors. The preview reads files but does not call a model or write anything. The workbench opens it from the header "Diagnostics" button.
90
+
74
91
  ## Workbench and memory chat
75
92
 
76
- The plugin registers a sidebar entry and a full `main` view, following the same slot pattern as `dsh-github-flow`. The view contains overview cards, a metabolism flow, chat threads, an organizer drawer and a chat settings drawer. The existing Settings section remains the memory administration panel.
93
+ The plugin registers a sidebar entry and a full `main` view, following the same slot pattern as `dsh-github-flow`. The main pane contains the overview cards, the metabolism flow and a directly operable memory list. The assistant is a collapsible right sidebar with threads, chat and composer; organizer and chat settings open as drawers. The existing Settings section remains the memory administration panel.
77
94
 
78
95
  The chat is a custom restricted agent loop, not a DSH session:
79
96
 
80
97
  1. The user sends text or a text attachment in a thread.
81
98
  2. The server builds a system prompt with the current project, counts and the fixed tool rules, plus recent thread text capped by `chatHistoryChars`.
82
99
  3. It calls `ctx.llm.stream` with five tools: `memory_search`, `memory_read`, `memory_status`, `memory_consolidate`, `memory_apply`.
83
- 4. The loop executes tool calls through the memory service only; it appends tool results and continues until `stop` or `chatMaxRounds`.
100
+ 4. The loop executes tool calls through the memory service only; it appends tool results and continues until `stop` or `chatMaxRounds`. Successful retrieval calls `recordUse`, so injection and search reinforce `lastUsed`, `useCount` and FSRS stability.
84
101
  5. Text deltas and tool events stream to the client over SSE. The assistant message and tool chips are persisted in `chats/<id>.json`.
85
102
  6. No DSH session is created, no `ctx.subagent` is used and nothing is written to the main chat.
86
103
 
package/index.js CHANGED
@@ -6,6 +6,7 @@ import { registerTools } from './lib/tools.js'
6
6
  import { registerContext } from './lib/context.js'
7
7
  import { registerRoutes } from './lib/api.js'
8
8
  import { createChatStore } from './lib/chat/store.js'
9
+ import { createAutoOrganizer } from './lib/organizer.js'
9
10
 
10
11
  export const name = 'memory-metabolism'
11
12
 
@@ -26,6 +27,13 @@ export const Config = Schema.object({
26
27
  staleDays: Schema.number().default(30).description('Soft stale window used by the console and diagnostics.'),
27
28
  archiveRetrievability: Schema.number().default(0.2).description('Archive low-importance entries below this retrievability.'),
28
29
  autoProject: Schema.boolean().default(true).description('Resolve the project key from the session cwd.'),
30
+ projectStorage: Schema.string().default('local').description('local: project memory inside the project; central: legacy central shards.'),
31
+ globalNoForget: Schema.boolean().default(true).description('User-level entries do not fade by default.'),
32
+ autoOrganize: Schema.boolean().default(true).description('After a request settles, extract durable memory candidates in the background.'),
33
+ autoOrganizeModel: Schema.string().default('').description('Provider/model for the background organizer. Empty = assistantModel.'),
34
+ autoOrganizeDelayMs: Schema.number().default(2500).description('Quiet period before an auto-organizer run.'),
35
+ autoOrganizeMaxChars: Schema.number().default(12000).description('Transcript budget for the auto organizer.'),
36
+ autoOrganizeMinChars: Schema.number().default(40).description('Skip shorter requests.'),
29
37
  assistantModel: Schema.string().default('').description('Provider/model for the in-plugin memory chat. Empty = use the last session model, then the first available model.'),
30
38
  assistantMaxInputChars: Schema.number().default(120000).description('Maximum document size accepted by the memory chat.'),
31
39
  chatHistoryChars: Schema.number().default(24000).description('How much prior chat text to send back to the model.'),
@@ -51,6 +59,8 @@ export function apply(ctx, config = {}) {
51
59
  const service = createService({ store, config: resolved })
52
60
  const chatStore = createChatStore(resolved.dataDir)
53
61
  chatStore.ensure()
62
+ const organizer = createAutoOrganizer({ ctx, service, store, config: resolved })
63
+ organizer.register()
54
64
 
55
65
  ctx.on('session/event', (session, event) => {
56
66
  if (event?.type === 'plan/mode' && session?.id) service.setPlanMode(session.id, event?.data?.active === true)
@@ -60,6 +70,6 @@ export function apply(ctx, config = {}) {
60
70
  registerContext({ ctx, service, store, config: resolved })
61
71
 
62
72
  ctx.inject(['webServer'], (webCtx) => {
63
- registerRoutes({ ctx: webCtx, hostCtx: ctx, service, store, config: resolved, chatStore })
73
+ registerRoutes({ ctx: webCtx, hostCtx: ctx, service, store, config: resolved, chatStore, organizer })
64
74
  })
65
75
  }