Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

remember items[]: replaces travels per item, a batch-level replaces is invalid_params; items[] case in the zero-model write test; gbrain core add/remove classified async_derived

garrytan286e1abc472c
diff --git a/docs/protocol/MEMORY_VERBS_v1.md b/docs/protocol/MEMORY_VERBS_v1.md
index 265dea5604..23518cf8ca 100644
--- a/docs/protocol/MEMORY_VERBS_v1.md
+++ b/docs/protocol/MEMORY_VERBS_v1.md
@@ -310,11 +310,12 @@ Optional response fields; clients must ignore any they do not know.
`items` (1 to 20) replaces `fact` for a batch, typically right before
context compaction. Each item is a fact string or an object with `fact` plus
-optional `entity`, `kind`, `ttl`, `visibility`, `provenance` and
-`infer_entity`; top-level `provenance`,
+optional `entity`, `kind`, `ttl`, `visibility`, `provenance`,
+`infer_entity` and `replaces`; top-level `provenance`,
`kind`, `ttl`, `visibility` and `infer_entity` are the defaults, so top-level
-`provenance` is optional when every item carries its own. Passing both
-`fact` and `items` is `invalid_params`.
+`provenance` is optional when every item carries its own. `replaces` names one
+fact, so it goes on its item; passing both `fact` and `items`, or a top-level
+`replaces` with `items`, is `invalid_params`.
Every item is validated before any is written: one invalid item refuses the
whole call with `items[<i>]` in the message. Each item is then saved as its own
diff --git a/llms-full.txt b/llms-full.txt
index f82d9a63ff..729bbe6b68 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -9122,11 +9122,12 @@ Optional response fields; clients must ignore any they do not know.
`items` (1 to 20) replaces `fact` for a batch, typically right before
context compaction. Each item is a fact string or an object with `fact` plus
-optional `entity`, `kind`, `ttl`, `visibility`, `provenance` and
-`infer_entity`; top-level `provenance`,
+optional `entity`, `kind`, `ttl`, `visibility`, `provenance`,
+`infer_entity` and `replaces`; top-level `provenance`,
`kind`, `ttl`, `visibility` and `infer_entity` are the defaults, so top-level
-`provenance` is optional when every item carries its own. Passing both
-`fact` and `items` is `invalid_params`.
+`provenance` is optional when every item carries its own. `replaces` names one
+fact, so it goes on its item; passing both `fact` and `items`, or a top-level
+`replaces` with `items`, is `invalid_params`.
Every item is validated before any is written: one invalid item refuses the
whole call with `items[<i>]` in the message. Each item is then saved as its own
diff --git a/src/core/ops/write-inference.ts b/src/core/ops/write-inference.ts
index a19ac069cc..7f27c87345 100644
--- a/src/core/ops/write-inference.ts
+++ b/src/core/ops/write-inference.ts
@@ -80,6 +80,9 @@ export const CLI_WRITE_INFERENCE: Readonly<Record<string, WriteInference>> = {
'hook ipc banking': 'none',
// P1: accept/undo/date append or remove a timeline line and re-derive links; reject records a verdict.
'edge-proposals': 'none',
+ // Core memory: mark or unmark a page as always loaded through put_page as the local owner.
+ 'core add': 'async_derived',
+ 'core remove': 'async_derived',
};
export function writeInferenceOf(op: Pick<Operation, 'name' | 'writeInference'>): WriteInference {
diff --git a/src/core/remember-batch.ts b/src/core/remember-batch.ts
index 9b6a3c1cbc..a43403d0e5 100644
--- a/src/core/remember-batch.ts
+++ b/src/core/remember-batch.ts
@@ -23,7 +23,7 @@ import type { OperationContext } from './operations.ts';
import { OperationError } from './ops/contract.ts';
export const REMEMBER_BATCH_MAX = 20;
-const ITEM_KEYS = new Set(['fact', 'provenance', 'entity', 'infer_entity', 'kind', 'ttl', 'visibility']);
+const ITEM_KEYS = new Set(['fact', 'provenance', 'entity', 'infer_entity', 'kind', 'ttl', 'visibility', 'replaces']);
/** Deterministic UUID for child `index` of a batch request (stable across replays). */
export function childRequestId(requestId: string, index: number): string {
@@ -52,6 +52,10 @@ export async function runRememberBatch(ctx: OperationContext, p: Record<string,
if (typeof p.fact === 'string' && p.fact.trim()) {
throw verbError('invalid_params', 'Pass either fact or items, not both.', 'Move the single fact into items, or drop items.');
}
+ if (p.replaces !== undefined) {
+ throw verbError('invalid_params', 'replaces names one fact, so it cannot apply to a whole batch.',
+ 'Put replaces on the item it belongs to: items: [{ "fact": "...", "replaces": "<fact_id>" }].');
+ }
const shared: Record<string, unknown> = {};
for (const key of ['provenance', 'source_id', 'kind', 'ttl', 'visibility', 'infer_entity']) if (p[key] !== undefined) shared[key] = p[key];
const normalized = items.map((raw, index) => {
diff --git a/test/remember-batch.test.ts b/test/remember-batch.test.ts
index da574d6526..68f04d4d76 100644
--- a/test/remember-batch.test.ts
+++ b/test/remember-batch.test.ts
@@ -64,6 +64,24 @@ describe('remember items[] batch', () => {
});
});
+describe('remember items[] and replaces', () => {
+ test('replaces travels with the item it names', async () => {
+ const { handler, writes } = fakeSingle();
+ await runRememberBatch(ctx, { provenance: 'p', items: [{ fact: 'Moved to Lisbon', replaces: '42' }, { fact: 'Ships Fridays' }] }, handler, ve);
+ expect(writes.map(w => w.replaces)).toEqual(['42', undefined]);
+ });
+
+ test('a batch-level replaces is refused before any write: it names one fact', async () => {
+ const { handler, writes } = fakeSingle();
+ let err: unknown;
+ try { await runRememberBatch(ctx, { provenance: 'p', replaces: '42', items: [{ fact: 'a' }, { fact: 'b' }] }, handler, ve); } catch (e) { err = e; }
+ expect(err).toBeInstanceOf(OperationError);
+ expect((err as OperationError).code).toBe('invalid_params');
+ expect((err as Error).message).toContain('replaces');
+ expect(writes).toHaveLength(0);
+ });
+});
+
describe('remember items[] shorthand and receipts', () => {
test('a bare string item is one fact with the shared provenance', async () => {
const { handler, writes } = fakeSingle();
diff --git a/test/write-path-zero-llm.serial.test.ts b/test/write-path-zero-llm.serial.test.ts
index 45393dd5f0..4ad7660b7f 100644
--- a/test/write-path-zero-llm.serial.test.ts
+++ b/test/write-path-zero-llm.serial.test.ts
@@ -163,6 +163,15 @@ describe('writes commit with zero generative model calls', () => {
expectNoGenerative('remember/forget');
});
+ test('remember items[] (a pre-compaction batch) embeds at most, never generates', async () => {
+ const batch = await call('remember', { provenance: 'test', items: [
+ { fact: 'Alice Example ships on Fridays.', entity: 'companies/acme-example' },
+ 'Bob Example prefers written updates.',
+ ] }, true);
+ expect(batch.saved).toBe(2);
+ expectNoGenerative('remember items[]');
+ });
+
test('delete_page and restore_page', async () => {
COVERED.add('delete_page'); COVERED.add('restore_page');
await call('put_page', { slug: 'notes/temp', content: `---\ntype: note\ntitle: Temp\n---\nTemporary.` });