Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/capy/belief-ledger-w1' into capy/belief-w1-trust
garrytan734e36d3e6ba
diff --cc src/core/belief/ledger.tsindex bd12c02f1b,dcb5c2fbb2..ed2a3a20f6--- a/src/core/belief/ledger.ts+++ b/src/core/belief/ledger.ts@@@ -387,26 -363,16 +401,27 @@@ export async function finalizeBeliefEveconst silenced = pageDrafts(d, stream, lifetimes.get(page.id)!, after, draft => drafts.push(draft));if (!silenced) drafts.push(...subjectDrafts(d, page.slug, before, after));}- const dbSlugs = new Set([...preSubjects, ...postSubjects].filter(s => s.dbOnly).map(s => s.stream));- for (const slug of dbSlugs) drafts.push(...subjectDrafts(d, slug, preSubjects.filter(s => s.dbOnly && s.stream === slug), postSubjects.filter(s => s.dbOnly && s.stream === slug)));+ // A renamed page's database-only facts follow it: their pre side is diffed under the slug the page moved to, so a rename moves no key.+ const renamedTo = new Map(streams.flatMap(s => s.pre && s.post && s.pre.slug !== s.post.slug ? [[s.pre.slug, s.post.slug] as const] : []));+ const dbPre = preSubjects.filter(s => s.dbOnly), dbPost = postSubjects.filter(s => s.dbOnly);+ const dbStream = (s: Subject) => renamedTo.get(s.stream) ?? s.stream;+ for (const slug of new Set([...dbPre.map(dbStream), ...dbPost.map(s => s.stream)])) {+ drafts.push(...subjectDrafts(d, slug, dbPre.filter(s => dbStream(s) === slug), dbPost.filter(s => s.stream === slug)));+ }+ // A contested fact outside the batch's streams is keyed and hashed as its own stream holds it now (its page's lifetime when the page exists).+ const extraStreams = new Map<string, Awaited<ReturnType<typeof currentStateHash>>>();+ for (const f of extraFacts) {+ const stream = f.sms ?? f.entity_slug;+ if (stream && !extraStreams.has(stream)) extraStreams.set(stream, await currentStateHash(tx, opts.sourceId, batch.incarnation, stream));+ }for (const note of batch.notes) {- if (note.kind === 'contested') drafts.push(...contestedDraft(d, note, { pre, post, preSubjects, postSubjects, extraFacts, lifetimes }));+ if (note.kind === 'contested') drafts.push(...contestedDraft(d, note, { pre, post, preSubjects, postSubjects, extraFacts, extraStreams, lifetimes }));else if (note.kind === 'held') {const page = postPageAt(note.slug);- drafts.push({ sourceId: opts.sourceId, incarnation: batch.incarnation, lifetime: lifetimeAt(note.slug), slug: note.slug, stream: note.slug,- subjectKind: note.holdKind === 'take' ? 'take' : 'fact', subjectKey: heldKey(note.holdKind, note.fingerprint), eventType: 'trust.held',+ const lifetime = lifetimeAt(note.slug);+ drafts.push({ sourceId: opts.sourceId, incarnation: batch.incarnation, lifetime, slug: note.slug, stream: note.slug,+ subjectKind: note.holdKind === 'take' ? 'take' : 'fact', subjectKey: heldKey(lifetime ? lifetimeRef(lifetime) : slugRef(batch.incarnation, note.slug), note.holdKind, note.fingerprint), eventType: 'trust.held',trustTier: note.tier, tierBasis: 'writer', visibility: page && !page.visible ? 'private' : 'world', value: { value_hash: note.valueHash },stateHash: streamHash(note.slug), cause: d.cause({ hold: `wh${note.holdId}` }) });}