Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
refactor(trust): one holdBinding for the hold preview and the door release check; submitTrustRelease documents its approved guard (/ship review pass 3, #7511)
garrytan4a979abac791
diff --git a/src/core/trust/owner-actions.ts b/src/core/trust/owner-actions.tsindex 45c008de04..59e033bf7b 100644--- a/src/core/trust/owner-actions.ts+++ b/src/core/trust/owner-actions.ts@@ -103,6 +103,7 @@ export interface OwnerApplyOptions {const hash8 = (value: string): string => createHash('sha256').update(value).digest('hex').slice(0, 8);const bindingOf = (value: unknown): string => createHash('sha256').update(JSON.stringify(value, (_key, v: unknown) => typeof v === 'bigint' ? v.toString() : v)).digest('hex');+const holdBinding = (hold: Pick<HoldRow, 'id' | 'status' | 'last_seen_at'>): string => bindingOf({ id: hold.id, status: hold.status, last_seen_at: hold.last_seen_at });const snippet = (text: unknown, max = 80): string => {const flat = String(text ?? '').replace(/\s+/g, ' ').trim();return flat.length > max ? `${flat.slice(0, max - 3)}...` : flat;@@ -189,7 +190,7 @@ const defaultHoldStore: HoldStoreAdapter = {return (await import('./release-publish.ts')).submitTrustRelease(engine, id, by, config,approved === undefined ? undefined : async hold => {const row = await defaultHoldStore.get(engine, hold.id);- return !!row && bindingOf({ id: row.id, status: row.status, last_seen_at: row.last_seen_at }) === approved;+ return !!row && holdBinding(row) === approved;});},};@@ -326,7 +327,7 @@ async function previewHold(engine: BrainEngine, id: number, action: 'release' |if (!hold) throw notFound(label, 'held write');const text = hold.payload.fact ?? hold.payload.claim ?? '';return { action, ref: label, token: label, command: trustCommand(action, label), raises: action === 'release',- binding: bindingOf({ id: hold.id, status: hold.status, last_seen_at: hold.last_seen_at }), tier: hold.tier,+ binding: holdBinding(hold), tier: hold.tier,...(action === 'release' ? { target_tier: 'user_confirmed' as TrustTier } : {}),summary: action === 'release'? `Release held ${hold.kind} ${label} ("${snippet(text)}", ${hold.reason_families.join(', ') || 'detector error'}) into memory as "confirmed by you"`diff --git a/src/core/trust/release-publish.ts b/src/core/trust/release-publish.tsindex d7878ef9c4..cbc5adadba 100644--- a/src/core/trust/release-publish.ts+++ b/src/core/trust/release-publish.ts@@ -58,7 +58,8 @@ function releaseTarget(hold: WriteGateHold): { slug: string; mode: ReleaseIntent/*** Publishes a managed release through the door and waits for it; true once committed. Null when the hold takes the* transactional release instead (see the module comment); false when it is no longer held and no request of this- * approval exists.+ * approval exists. `approved` (the owner's preview binding, re-read by owner-actions.ts) is checked after the replay of+ * an existing request and before admission: a hold re-gated since the owner confirmed it refuses `preview_changed`.*/export async function submitTrustRelease(engine: BrainEngine, holdId: number, by: string, config?: GBrainConfig,approved?: (hold: WriteGateHold) => Promise<boolean>): Promise<boolean | null> {