Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge l1a-taint (I2 taint in derivers, derivation edges, deriver gate wiring, attributed extract/enrichment/meeting writers); derived pages page-gated at their declaration; drop the pair-store registry (init cycle); marker-only changes still import

garrytan1ba1adaa9017
diff --git a/src/core/facts/proposal-supersede.ts b/src/core/facts/proposal-supersede.ts
index bbda356b20..6e787b1584 100644
--- a/src/core/facts/proposal-supersede.ts
+++ b/src/core/facts/proposal-supersede.ts
@@ -65,7 +65,7 @@ export interface ProposalActionResult {
/**
* The proposal record a checked supersede reads and transitions: decide_proposals
* (S9) by default, or another typed store with the same pair shape (#5575
- * trust_proposals, registered by trust/supersede-handlers.ts). `onAccept` /
+ * trust_proposals, trust/supersede-handlers.ts TRUST_PAIR_STORE). `onAccept` /
* `onUndo` run inside the same transaction after the facts change.
*/
export type PairProposal = Pick<ProposalRow, 'id' | 'source_id' | 'old_fact_id' | 'new_fact_id' | 'status' | 'before_state' | 'after_state'>;
@@ -80,12 +80,11 @@ export const DECIDE_PROPOSAL_STORE: PairProposalStore = {
name: 'decide', get: getProposal,
transition: (engine, id, from, to, state) => transitionProposal(engine, id, from as ProposalRow['status'], to as ProposalRow['status'], state),
};
-const pairStores = new Map<string, PairProposalStore>([[DECIDE_PROPOSAL_STORE.name, DECIDE_PROPOSAL_STORE]]);
-export function registerPairProposalStore(store: PairProposalStore): void { pairStores.set(store.name, store); }
+/** The store a managed decide_proposal intent names; loaded lazily so the trust module and this one never cycle at init. */
async function pairStore(name: unknown): Promise<PairProposalStore | null> {
if (name === undefined || name === null) return DECIDE_PROPOSAL_STORE;
- if (name === 'trust' && !pairStores.has('trust')) await import('../trust/supersede-handlers.ts');
- return typeof name === 'string' ? pairStores.get(name) ?? null : null;
+ if (name === 'trust') return (await import('../trust/supersede-handlers.ts')).TRUST_PAIR_STORE;
+ return null;
}
export class ProposalConflictError extends Error {
diff --git a/src/core/import-file.ts b/src/core/import-file.ts
index 73e69c0a91..bdd0fd7656 100644
--- a/src/core/import-file.ts
+++ b/src/core/import-file.ts
@@ -1,6 +1,6 @@
import { assertUnmanagedCanonicalWriter } from './persistence/maintenance.ts';
import { suffixedFrontmatterSlugHold } from './persistence/suffixed-slug.ts';
-import { maintenanceTransaction, ownerSourceGateInput, writeTrustOfGate } from './persistence/attribution.ts';
+import { maintenanceTransaction, ownerSourceGateInput, trustMarkerChanged, writeTrustOfGate } from './persistence/attribution.ts';
import { assertImportBase, sameCanonicalImport, sameContentAnyKeyOrder } from './page-state/import-guard.ts';
import { stabilizeSafetyAssessments } from './persistence/reconcile-safety.ts';
import { decideImportIdentity, collidingSlugOwner, fileOriginUri } from './import-identity.ts';
@@ -521,7 +521,7 @@ export async function importFromContent(
timeline: parsed.timeline,
frontmatter: parsed.frontmatter,
});
- const unchanged = !!existing && !existing.deleted_at && !opts.forceRechunk && !needsProjectionRebuild && !embedSkipChanged && (existing.content_hash === hash
+ const unchanged = !!existing && !existing.deleted_at && !opts.forceRechunk && !needsProjectionRebuild && !embedSkipChanged && !trustMarkerChanged(existing.frontmatter, parsed.frontmatter) && (existing.content_hash === hash
? !opts.prepare || sameCanonicalImport(existingSnapshot, parsedPage)
: !legacyHashMatch && await sameContentAnyKeyOrder(engine, existing, existingSnapshot?.tags ?? null, parsedPage, sourceId ?? 'default'));
if (existing && unchanged) {
diff --git a/src/core/persistence/attribution.ts b/src/core/persistence/attribution.ts
index f336f4b449..f8aaf5c579 100644
--- a/src/core/persistence/attribution.ts
+++ b/src/core/persistence/attribution.ts
@@ -4,7 +4,7 @@ import type { BrainEngine } from '../engine.ts';
import { withWriteAttribution } from './context.ts';
import type { WriteTrust } from '../trust/tier.ts';
import { requestChannelTrust } from '../trust/channel.ts';
-export { ownerSourceGateInput, writeTrustOfGate } from '../trust/channel.ts';
+export { ownerSourceGateInput, trustMarkerChanged, writeTrustOfGate } from '../trust/channel.ts';
/**
* The actor the database stamps on rows written inside withCoordinatedWrite
diff --git a/src/core/trust/channel.ts b/src/core/trust/channel.ts
index 2de5504d64..c60909edbb 100644
--- a/src/core/trust/channel.ts
+++ b/src/core/trust/channel.ts
@@ -200,3 +200,12 @@ export async function ownerSourceGateInput(engine: Pick<BrainEngine, 'executeRaw
const trust = ownerPageTrust({ frontmatter, sourceConfig: config, channel: 'import' });
return { tier: trust.tier, origin: { channel: 'import' }, requestId: null };
}
+
+/**
+ * The `trust_tier` marker is hash-ephemeral (utils.ts), so an import whose only
+ * change is adding or removing it would read as unchanged; removing it by hand
+ * is the owner act that restamps a page on the next sync (CEO-21), so it counts.
+ */
+export function trustMarkerChanged(prior: Record<string, unknown> | null | undefined, next: Record<string, unknown> | null | undefined): boolean {
+ return (prior?.trust_tier ?? null) !== (next?.trust_tier ?? null);
+}
diff --git a/src/core/trust/page-handlers.ts b/src/core/trust/page-handlers.ts
index a9bd1e5630..69c5279e8b 100644
--- a/src/core/trust/page-handlers.ts
+++ b/src/core/trust/page-handlers.ts
@@ -244,7 +244,8 @@ async function publishOwnerPage(engine: BrainEngine, input: PageActionInput, int
if ((await tx.readPageSnapshot(input.slug, { sourceId: input.sourceId }))?.revision !== input.expectedRevision) {
throw changedSincePreview(pageRef(input.sourceId, input.slug), intent.mode === 'confirm' ? 'its confirmation' : 'the revert');
}
- await importFromContent(tx, input.slug, markdown, { sourceId: input.sourceId, noEmbed: true, preserveGateMarkers: intent.mode === 'confirm', forceRechunk: intent.mode === 'revert', allowEmptyOverwrite: intent.mode === 'revert' });
+ // forceRechunk: the trust_tier marker is hash-ephemeral, so removing it alone would read as unchanged content.
+ await importFromContent(tx, input.slug, markdown, { sourceId: input.sourceId, noEmbed: true, preserveGateMarkers: intent.mode === 'confirm', forceRechunk: true, allowEmptyOverwrite: intent.mode === 'revert' });
await closeProposal(tx, intent.proposal, input.by);
}))));
}
diff --git a/src/core/trust/page-write.ts b/src/core/trust/page-write.ts
index b4e2675a95..169706ccca 100644
--- a/src/core/trust/page-write.ts
+++ b/src/core/trust/page-write.ts
@@ -21,6 +21,7 @@ import type { BrainEngine } from '../engine.ts';
import { queuePageProjection } from '../page-state/projections.ts';
import type { WriteRequest } from '../persistence/model.ts';
import { frontmatterTrustCaps, requestChannelTrust, stampTrustMarker } from './channel.ts';
+import { declaredWriteTrust, readDerivationDeclaration } from './taint.ts';
import { insertTrustProposal, updatePendingTrustProposalAfter } from './proposals.ts';
import { OWNER_TIER_FLOOR, compareTrust, effectiveWriteTrust, minTrust, storedTrustTier, type TrustTier, type WriteTrust } from './tier.ts';
@@ -36,7 +37,9 @@ export function isFenceEditWrite(row: Pick<WriteRequest, 'operation' | 'intent'>
/** The tier of one journaled page write, or undefined when the request's channel declares none. */
export function pageWriteTrust(row: Pick<WriteRequest, 'id' | 'operation' | 'authority' | 'intent'>, frontmatter: Record<string, unknown> | null | undefined): WriteTrust | undefined {
- const channel = requestChannelTrust(row);
+ // A managed derived page (atoms, synthesis, concepts, chronicle) carries its derivation declaration (trust/taint.ts).
+ const derivation = readDerivationDeclaration(row.intent?.derivation);
+ const channel = derivation ? declaredWriteTrust(derivation) : requestChannelTrust(row);
if (!channel || isFenceEditWrite(row)) return channel;
const caps = frontmatterTrustCaps(frontmatter);
return caps.length ? effectiveWriteTrust({ channel: channel.tier, lowerTo: caps, origin: channel.origin ?? { channel: row.operation } }) : channel;
diff --git a/src/core/trust/supersede-handlers.ts b/src/core/trust/supersede-handlers.ts
index e301c4a3b1..77f62e7fd9 100644
--- a/src/core/trust/supersede-handlers.ts
+++ b/src/core/trust/supersede-handlers.ts
@@ -13,7 +13,7 @@
*/
import type { BrainEngine } from '../engine.ts';
import {
- applyProposalAction, registerPairProposalStore, type PairProposal, type PairProposalStore, type ProposalActionResult,
+ applyProposalAction, type PairProposal, type PairProposalStore, type ProposalActionResult,
} from '../facts/proposal-supersede.ts';
import { currentWriteTrust, withTrustPromotion, withWriteAttribution } from '../persistence/context.ts';
import { normalizeDimension } from '../chronicle/ontology.ts';
@@ -157,7 +157,6 @@ export const TRUST_PAIR_STORE: PairProposalStore = {
for (const id of [proposal.old_fact_id, proposal.new_fact_id]) await queueTierProjection(tx, 'facts', id);
},
};
-registerPairProposalStore(TRUST_PAIR_STORE);
function fromPairResult(proposal: TrustProposalRow, decision: TrustDecision, result: ProposalActionResult) {
const status = result.status === 'stale' ? 'superseded' : result.status;