Выпуск 1.0.2: память сначала, поиск по всей установке

This commit is contained in:
Denis Markov 2026-12-04 09:14:28 +03:00
parent 3ac8b21c36
commit 4dfc935b05
3 changed files with 22 additions and 9 deletions

View file

@ -42,6 +42,7 @@ You have durable memory shared by every session in this installation (plugin \`m
The recall block in context is a cached digest and may lag behind the store.
- **One signal is enough.** Save immediately, without asking and without waiting for confirmation, when any of these appear: a user preference, correction, or feedback; a project convention; an architectural decision together with its reason; an environment fact; a non-obvious gotcha that will outlive this session. Never ask the user whether to save.
- **Start from memory.** Before exploring a repository, server, or CI system, call \`memory_search\` with the task's keywords (deploy, release, pipeline, forgejo, service or host name). Earlier sessions likely recorded the procedure, the exact commands, and its gotchas: read that note and follow it instead of re-deriving the setup from scratch. Re-research only when memory has nothing or the note proves stale.
- **Check before writing.** Call \`memory_search\` first. If a note already covers the topic but the fact changed, rewrite it in place with \`memory_update\` (same id, same history); use \`memory_forget\` + \`memory_save\` only when the old note is about something else. Do not keep two contradicting notes.
- **One topic per note, one collection per note.** Write for a future session that knows nothing about this conversation: name the paths, commands, services, and reasons. Give the note a collection: \`personal\` for user facts and preferences, \`home-server\` for infrastructure, the project or site name (e.g. \`autoan\`, \`itmarkov.ru\`) for project knowledge, \`dsh\` for the harness itself. Scope \`global\` for user-wide facts, \`workspace\` for this project's conventions and decisions. Pin only rules that must always apply. When searching, pass \`collection\` to narrow the store.
- **Do not save:** transient task state, secrets or credentials, anything already in the repository or AGENTS.md, unverified claims, point-in-time values (line numbers, counts, commit hashes), or facts that are cheaper to re-derive from the code than to recall.
@ -447,6 +448,8 @@ function createLocalStore(logger) {
const cwdParam = cwd ?? null
if (scope === 'global') return { sql: `scope = 'global'`, params: [] }
if (scope === 'workspace') return { sql: `scope = 'workspace' AND workspace IS ?`, params: [cwdParam] }
// all без каталога = вся память установки, включая заметки других проектов.
if (scope === 'all' && cwdParam === null) return { sql: '1 = 1', params: [] }
return { sql: `(scope = 'global' OR (scope = 'workspace' AND workspace IS ?))`, params: [cwdParam] }
}
@ -639,8 +642,10 @@ function createPgStore(pool, logger) {
? `scope = 'global'`
: scope === 'workspace'
? `scope = 'workspace' AND workspace = $1`
: `(scope = 'global' OR (scope = 'workspace' AND workspace = $1))`
const params = scope === 'global' ? [] : [cwd ?? null]
: scope === 'all' && cwd === undefined
? `true`
: `(scope = 'global' OR (scope = 'workspace' AND workspace = $1))`
const params = (scope === 'global' || (scope === 'all' && cwd === undefined)) ? [] : [cwd ?? null]
const filters = [where]
if (collection) { filters.push(`collection = $${params.length + 1}`); params.push(collection) }
params.push(limit)
@ -657,8 +662,10 @@ function createPgStore(pool, logger) {
? `scope = 'global'`
: scope === 'workspace'
? `scope = 'workspace' AND workspace = $2`
: `(scope = 'global' OR (scope = 'workspace' AND workspace = $2))`
const params = scope === 'global' ? [needle] : [needle, cwd ?? null]
: scope === 'all' && cwd === undefined
? `true`
: `(scope = 'global' OR (scope = 'workspace' AND workspace = $2))`
const params = (scope === 'global' || (scope === 'all' && cwd === undefined)) ? [needle] : [needle, cwd ?? null]
let filters = [where]
if (collection) { filters.push(`collection = $${params.length + 1}`); params.push(collection) }
const likeIndex = params.length + 1
@ -1082,13 +1089,13 @@ function createTools(ctx, engine, settings, recall) {
{
name: 'memory_search',
description:
'Search saved memory notes by keyword (substring of the note or an exact tag). '
+ 'Call it when the user refers to something from an earlier session, an earlier decision, or a preference you do not see in the current conversation.',
'Search saved memory notes by keyword (substring of the note or an exact tag). Searches every collection and every project by default, so a deployment or CI note saved in another workspace is found here. '
+ 'Call it before exploring a repository, server, or CI system: earlier sessions likely recorded the procedure and its gotchas.',
parameters: {
type: 'object',
properties: {
query: { type: 'string', description: 'Keyword or phrase to look for.' },
scope: { type: 'string', enum: ['global', 'workspace', 'all'], description: 'Limit to global notes, workspace notes, or both (default).' },
scope: { type: 'string', enum: ['all', 'global', 'workspace'], description: 'all (default) searches everything; global only user-wide notes; workspace only notes of the current working directory.' },
collection: { type: 'string', description: 'Only notes from this collection (personal, home-server, project/site name). Optional.' },
limit: { type: 'number', description: 'Maximum results, 1-20 (default 8).' },
},
@ -1101,7 +1108,8 @@ function createTools(ctx, engine, settings, recall) {
if (text.length === 0) throw new Error('memory: `query` must be a non-empty string')
const limit = clampInt(args.limit, 1, 20, 8)
const scope = args.scope === 'global' || args.scope === 'workspace' ? args.scope : 'all'
const rows = await engine.search(text.toLowerCase(), scope, sessionCwd(ctx, exec), limit, normalizeCollection(args.collection))
const cwd = scope === 'workspace' ? sessionCwd(ctx, exec) : undefined
const rows = await engine.search(text.toLowerCase(), scope, cwd, limit, normalizeCollection(args.collection))
if (rows.length === 0) return `No memories match ${JSON.stringify(text)}.`
return `Found ${rows.length} memor${rows.length === 1 ? 'y' : 'ies'}:\n${rows.map(row => formatRow(row, { showDate: true })).join('\n')}`
},