respire-memory 0.3.15: every --parent must be shown first, --clear-parent is refused (#633)

Sync of risense-ai/respire-magpie v0.3.15 (2c5a237c). memory-tools.mjs is byte-identical to upstream at that commit.

- `--clear-parent` joins the forbidden memory options.
- Every `--parent` (both `--parent ID` and `--parent=ID`) must be a full id that was shown first, on remember and update alike; a non-trivial remember still needs one.

Run at 79b99037 on mote (Bun 1.4.2, Node 22): `node scripts/check.mjs` in the package (isolated temp HOME, detached worker, archive checks) passed; `bun test packages/respire-memory` 1 pass; `bun scripts/check.mjs respire-memory` passed.
Broken by hand: with 0.3.14's memory-tools.mjs the new placement checks fail ("Missing expected rejection").
Not tried: a real Respire install against a live model.

PR #633 by @luodaoyi.
This commit is contained in:
luodaoyi
2026-11-02 19:42:50 +08:00
committed by GitHub
parent b820704803
commit 32d58dd511
3 changed files with 19 additions and 6 deletions
+3 -5
View File
@@ -78,7 +78,7 @@ export function memoryTools(call, { readOnly = false, source } = {}) {
if (!record(input) || ![...READ, ...WRITE].includes(input.command) || !Array.isArray(input.args) || input.args.some(arg => typeof arg !== 'string') || JSON.stringify(input).length > 16000) throw new Error('invalid-memory-call')
const { command } = input
let args = input.args.filter(arg => arg !== '--json' && arg !== '--client-only')
if (args.some(arg => /^(?:--(?:direct|force|merge-ids|go|ensure|set|addr|data-dir))(?:=|$)/.test(arg))) throw new Error('forbidden-memory-option')
if (args.some(arg => /^(?:--(?:direct|force|merge-ids|clear-parent|go|ensure|set|addr|data-dir))(?:=|$)/.test(arg))) throw new Error('forbidden-memory-option')
if (command === 'taxonomy' && (args.length !== 1 || args[0] !== '--list')) throw new Error('read-only-taxonomy')
if (command === 'agent-config' && args.length) throw new Error('read-only-config')
if (command === 'show' && !validId(args[0])) throw new Error('full-id-required')
@@ -98,10 +98,8 @@ export function memoryTools(call, { readOnly = false, source } = {}) {
}
const title = args.indexOf('--title')
if (!trivial && (title < 0 || !args[title + 1]?.trim())) throw new Error('title-required')
if (command === 'remember' && !trivial) {
const parent = args[args.indexOf('--parent') + 1]
if (!args.includes('--parent') || !validId(parent) || !shown.has(parent)) throw new Error('shown-parent-required')
}
const parents = args.flatMap((arg, index) => arg === '--parent' ? [args[index + 1]] : arg.startsWith('--parent=') ? [arg.slice('--parent='.length)] : [])
if ((command === 'remember' && !trivial && !parents.length) || parents.some(parent => !validId(parent) || !shown.has(parent))) throw new Error('shown-parent-required')
if (command === 'update' && (!validId(args[0]) || !shown.has(args[0]))) throw new Error('show-before-update')
const key = JSON.stringify([command, args])
if (attempts.has(key)) throw new Error('duplicate-write')
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/gateway-respire-memory",
"version": "0.3.14",
"version": "0.3.15",
"description": "帮助 AI Agent 通过记忆召回、经验积累与后台归档持续自进化",
"type": "module",
"license": "MIT",
+15
View File
@@ -277,6 +277,21 @@ try {
await assert.rejects(() => guarded.run({ command: 'remember', args: ['text', '--importance', 'important', '--title', 'title', '--parent', id] }));
await assert.rejects(() => guarded.run({ command: 'agent-config', args: ['--set', 'readonly=false'] }));
await assert.rejects(() => guarded.run({ command: 'show', args: [diaryId.slice(0,8)] }), /full-id-required/);
const placementCalls = [];
const placement = memoryTools(async args => {
placementCalls.push(args);
return { status: 'ok', summary: args[0] === 'prompt' ? { instructions: 'policy' } : { id } };
});
for (const command of ['recall', 'prompt', 'show']) await placement.run({ command, args: command === 'show' ? [id] : [] });
const placementBaseline = placementCalls.length;
const unshownParent = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
for (const suffix of [['--clear-parent'], ['--clear-parent=true'], ['--parent', unshownParent], ['--parent=' + unshownParent], ['--parent', ''], ['--parent='], ['--force=true'], ['--merge-ids=' + id]]) {
await assert.rejects(() => placement.run({ command: 'update', args: [id, '--title', 'kept title', ...suffix] }), /forbidden-memory-option|shown-parent-required/);
}
assert.equal(placementCalls.length, placementBaseline);
await placement.run({ command: 'update', args: [id, '--title', 'kept title', '--parent=' + id] });
await placement.run({ command: 'show', args: [id] });
await placement.run({ command: 'update', args: [id, '--title', 'ordinary update'] });
const diaryGuard = memoryTools(call, { source: digest('strict-diary-readback') });
await diaryGuard.run({ command: 'recall', args: ['project'] }); await diaryGuard.run({ command: 'prompt', args: [] });
const diaryWrite = await diaryGuard.run({ command: 'remember', args: ['Current turn complete diary.', '--importance', 'trivial'] });