Память и сейф: первый публичный выпуск 1.0.0

This commit is contained in:
Denis Markov 2026-12-03 16:59:52 +03:00
commit 85ecb086fb
16 changed files with 2811 additions and 0 deletions

7
tests/check-local.mjs Normal file
View file

@ -0,0 +1,7 @@
import { DatabaseSync } from 'node:sqlite'
const db = new DatabaseSync('C:/Users/denis/.dsh/memory/memory.sqlite')
const row = db.prepare("select id, substr(body, 1, 40) as body from memory_entries where id = 'mem-658a012c'").get()
console.log('test note present:', JSON.stringify(row ?? null))
console.log('collections:', db.prepare('select collection, count(*) as n from memory_entries group by collection').all().map(r => `${r.collection}=${r.n}`).join(', '))
console.log('fts exists:', db.prepare("select count(*) as n from sqlite_master where name = 'memory_entries_fts'").get().n === 1)

75
tests/memory-smoke.mjs Normal file
View file

@ -0,0 +1,75 @@
/** Смоук-тест хостовой части: node memory-smoke.mjs local|server|fallback */
import { apply } from '../index.js'
const mode = process.argv[2] ?? 'local'
const CWD = 'C:\\Users\\denis\\Documents\\deepseek-harness\\default-workspace'
const tools = new Map()
const contexts = []
const sections = []
const ctx = {
logger: { warn: (...a) => console.error('[warn]', ...a), info: (...a) => console.error('[info]', ...a) },
get(name) {
if (name === 'workingDirectory') return { get: () => CWD }
if (name === 'commands') return { register: () => () => {} }
return undefined
},
tools: { register(definition) { tools.set(definition.name, definition); return () => {} } },
systemPrompt: {
context(definition) { contexts.push(definition); return () => {} },
section(definition) { sections.push(definition); return () => {} },
},
on() { return () => {} },
effect(callback) { callback() },
}
const config = mode === 'local'
? { mode: 'local', host: '127.0.0.1', port: 1, database: 'x', user: 'x', password: 'x' }
: mode === 'mirror'
? { mode: 'local', host: '192.168.31.4', port: 5434, database: 'dsh_memory', user: 'dsh_memory' }
: mode === 'fallback'
? { mode: 'server', host: '127.0.0.1', port: 1, database: 'x', user: 'x', password: 'x', autoFallback: true }
: { mode: 'server', host: '192.168.31.4', port: 5434, database: 'dsh_memory', user: 'dsh_memory' }
await apply(ctx, config)
const exec = { agent: { session: {} }, signal: new AbortController().signal }
const call = async (name, args) => tools.get(name).execute(args, exec)
const out = (...a) => console.log(...a)
if (mode === 'local') {
out('TOOLS:', [...tools.keys()].join(','))
out('CONTEXTS:', contexts.map(c => c.name).join(','))
const rulesText = sections[0]?.text?.({}) ?? ''
out('RULES:', rulesText.length, JSON.stringify(rulesText.slice(0, 120)))
const saved = await call('memory_save', { text: 'Локальная заметка перед миграцией: проверка фолбэка и переноса.', tags: ['migrate'], scope: 'global', collection: 'home-server', pinned: true })
out('SAVE:', saved)
const id = /mem-[0-9a-f]+/.exec(saved)?.[0]
out('UPDATE:', await call('memory_update', { id, text: 'Локальная заметка обновлена: проверка memory_update.', tags: ['updated'] }))
out('SEARCH_NEW:', await call('memory_search', { query: 'обновлена', collection: 'home-server' }))
out('SEARCH_OTHER_COLLECTION:', await call('memory_search', { query: 'обновлена', collection: 'personal' }))
out('SEARCH_OLD:', await call('memory_search', { query: 'фолбэка' }))
out('LIST_COLLECTION:', await call('memory_list', { collection: 'home-server', limit: 5 }))
out('SAVE_PERSONAL:', await call('memory_save', { text: 'Личная заметка пользователя: предпочитает короткие ответы.', scope: 'global', collection: 'personal' }))
await new Promise(r => setTimeout(r, 300))
out('RECALL:', JSON.stringify(contexts[0].text({ agent: { session: {} } }).slice(0, 200)))
out('SECRET_SAVE:', await call('secret_save', { name: 'Тест: db admin', value: 'SuperSecret123', username: 'admin', url: 'db.local', notes: 'тест', tags: ['test'] }))
out('SECRET_LIST:', await call('secret_list', { limit: 5 }))
out('SECRET_GET:', await call('secret_get', { match: 'Тест: db admin' }))
out('SECRET_FORGET:', await call('secret_forget', { match: 'Тест: db admin' }))
out('SECRET_LIST_AFTER:', await call('secret_list', { limit: 5 }))
} else if (mode === 'server') {
out('SAVE_SERVER:', await call('memory_save', { text: 'Серверная заметка: проверка записи в обе базы.', tags: ['server'], scope: 'global' }))
out('SECRET_SAVE_SERVER:', await call('secret_save', { name: 'Тест: server token', value: 'tok_abc123', url: 'https://example.test', tags: ['test'] }))
out('LIST_SERVER:', await call('memory_list', { limit: 10 }))
} else if (mode === 'mirror') {
out('MIRROR_NOTE:', await call('memory_save', { text: 'Заметка в локальном режиме должна уйти и на сервер.', tags: ['mirror'], scope: 'global' }))
out('MIRROR_SECRET:', await call('secret_save', { name: 'Тест: mirror secret', value: 'mirror_value', tags: ['mirror'] }))
out('MIRROR_LIST:', await call('secret_list', { limit: 10 }))
} else {
out('FALLBACK_SAVE:', await call('memory_save', { text: 'Заметка при недоступном сервере: должна уйти в локальную SQLite.', scope: 'global' }))
out('FALLBACK_LIST:', await call('memory_list', { limit: 5 }))
}
process.exit(0)