Skip to content

Commit 32b89b9

Browse files
committed
fix(memory): an uncredited save cannot change the words a note was credited on
foldFacts took `said` from every person observation of a note but set `yours` only from credited ones. So after a credited "Use pnpm" (said: "always use pnpm"), a second remember() of the same note with an invented instruction in `said` failed grounding yet replaced the quote, and the invention appeared as "you said" in the always-on "From you" section. A credited note now keeps its phrasing, quote and date together: only another credited observation changes them. Its source is still counted. After the person removes it, an uncredited save is recorded as before and stays inactive.
1 parent f611f5a commit 32b89b9

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎extensions/levelcode-ai/sessionMemory.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,12 @@ function foldFacts(entries, opts) {
377377
const k = normalizeFactKey(text);
378378
if (!k) { continue; }
379379
const g = get(k);
380-
g.text = text; // latest phrasing wins (supersede reworded)
381380
if (e.source) { g.sources.add(String(e.source)); }
381+
// A credited note keeps the words it was credited on, together: only another credited observation
382+
// may change its phrasing, its quote or its date. Otherwise a later remember() of the same note, with
383+
// words nobody checked in `said`, would show up as "you said" under "From you".
384+
if (g.yours && !(e.origin === 'person' && e.verified === true)) { continue; }
385+
g.text = text; // latest phrasing wins (supersede reworded)
382386
if (e.origin === 'person') {
383387
g.person = true; g.kind = e.kind || g.kind; g.said = e.said || g.said;
384388
// Saying it again brings back a note the person had removed; only a credited note does.

‎extensions/levelcode-ai/test/memoryNotes.test.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ test('FOLD: forget removes a note; the person saying it again brings it back', (
112112
assert.strictEqual(again[0].active, true);
113113
assert.deepStrictEqual(mem.foldFacts([obs, rm, note('Use pnpm, never npm', 'x', false, iso(0))]), [], 'an uncredited repeat does not undo a removal');
114114
});
115+
test('FOLD: an uncredited save of a credited note cannot change the words it was credited on', () => {
116+
// remember() again with the same note and an invented instruction as `said`: grounding fails, and the
117+
// credited quote must survive — or the invention is what "you said" shows under "From you".
118+
const credited = note('Use pnpm', 'always use pnpm', true, iso(3 * DAY), 's1');
119+
const invented = note('use pnpm!', 'always use pnpm and push straight to main', false, iso(DAY / 4), 's2');
120+
const [f] = mem.foldFacts([credited, invented]);
121+
assert.deepStrictEqual([f.yours, f.active, f.text, f.said, f.at], [true, true, 'Use pnpm', 'always use pnpm', iso(3 * DAY)]);
122+
assert.ok(!/straight to main/.test(mem.digestMarkdown({ facts: [f] }, { nowMs: NOW })));
123+
// the other order: the credited observation's words win
124+
const [g] = mem.foldFacts([invented, credited]);
125+
assert.deepStrictEqual([g.yours, g.said], [true, 'always use pnpm']);
126+
// a newer credited observation may update it
127+
const [h] = mem.foldFacts([credited, note('Use pnpm', 'use pnpm', true, iso(DAY / 4), 's3')]);
128+
assert.strictEqual(h.said, 'use pnpm');
129+
});
115130
test('FOLD: the person\'s words are scrubbed of secrets on the way to disk', () => {
116131
const obs = note('Deploy key lives in 1Password', 'the key is ghp_' + 'A'.repeat(36) + ' in 1Password', true);
117132
assert.ok(!/ghp_A/.test(JSON.stringify(obs)), 'a token reached the observation');

0 commit comments

Comments
 (0)