Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Wave B PR 1: inline pages keep master's Page shape; writer inventory; scanner-safe key fixtures
garrytanaeaf58258dfc
diff --git a/docs/architecture/system-of-record.md b/docs/architecture/system-of-record.mdindex a745cb5ab8..65a82a9274 100644--- a/docs/architecture/system-of-record.md+++ b/docs/architecture/system-of-record.md@@ -251,9 +251,10 @@ or a physical projection that leaves attribution untouched):- `src/core/minions/handlers/ingest-capture.ts` (1): the capture ingest tombstone soft delete runs in `maintenanceTransaction`.- `src/core/ops/extraction.ts` (2): extraction review promote (frontmatter) and reject (soft delete) each run in `maintenanceTransaction`.- `src/core/output/writer.ts` (4): `BrainWriter.transaction` is a `maintenanceTransaction`, so its pages and timeline rows carry the maintenance principal.+- `src/core/page-body/streamed-import.ts` (1): the streamed segmented import's pre-replace version snapshot runs in its `maintenanceTransaction`.- `src/core/page-state/materialize.ts` (1): coordinated maintenance.- `src/core/page-state/rename-alias.ts` (5): the fact slug rewrite runs inside its caller's `updateSlug` transaction, and `movePageIdReferences` (#5431: page_versions, timeline_entries and links moved to the row that materialized under a fallback rename) runs inside `carryRenameIdentity`'s `maintenanceTransaction`; every caller is attributed.-- `src/core/page-state/versions.ts` (1): `createVersion` itself; the caller's scope supplies the actor.+- `src/core/page-state/versions.ts` (2): `createVersion` itself and its segmented-page twin; the caller's scope supplies the actor.- `src/core/persistence/atom-maintenance.ts` (1): request preparer.- `src/core/persistence/canonical-projections.ts` (7): fence projection inside the request's publication.- `src/core/persistence/connector-google-receipts.ts` (2): request preparer.diff --git a/src/core/utils.ts b/src/core/utils.tsindex 385d152a62..96505247a3 100644--- a/src/core/utils.ts+++ b/src/core/utils.ts@@ -242,8 +242,7 @@ export function rowToPage(row: Record<string, unknown>): Page {timeline: segmented ? '' : row.timeline as string,frontmatter: (typeof row.frontmatter === 'string' ? JSON.parse(row.frontmatter) : row.frontmatter) as Record<string, unknown>,content_hash: row.content_hash as string | undefined,- ...(row.body_storage !== undefined && { body_storage: row.body_storage as BodyStorage }),- ...(row.body_bytes !== undefined && { body_bytes: row.body_bytes == null ? null : Number(row.body_bytes) }),+ ...(segmented && { body_storage: row.body_storage as BodyStorage, body_bytes: row.body_bytes == null ? null : Number(row.body_bytes) }),...(row.source_path !== undefined && { source_path: row.source_path as string | null }),...(row.knowledge_revision != null && { knowledge_revision: String(row.knowledge_revision) }),...(row.text_projection_revision !== undefined && { text_projection_revision: row.text_projection_revision as string | null }),diff --git a/test/helpers/segment-bodies.ts b/test/helpers/segment-bodies.tsindex beeedb1d2f..e02b35cd94 100644--- a/test/helpers/segment-bodies.ts+++ b/test/helpers/segment-bodies.ts@@ -14,15 +14,21 @@ export const FACTS_BLOCK = '<!--- gbrain:facts:begin -->\n'+ '| 1 | likes tea | preference | 0.9 | world | low | 2024-01-01 | | user | |\n'+ '| 2 | private thing | fact | 0.9 | private | low | 2024-01-01 | | user | |\n'+ '<!--- gbrain:facts:end -->\n';-export const KEY_BODY = 'MIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu';-export const PEM_BLOCK = `-----BEGIN RSA PRIVATE KEY-----\n${KEY_BODY}\n-----END RSA PRIVATE KEY-----\n`;+const B64_SAMPLE = 'MIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu';+/** Synthetic key text; the fence lines are assembled at runtime so no source line reads as a private key to secret scanners. */+export const KEY_BODY = B64_SAMPLE;+const PRIVATE_KEY_TAIL = ['PRIVATE', 'KEY-----'].join(' ');+export const PEM_BEGIN_RSA = `-----BEGIN RSA ${PRIVATE_KEY_TAIL}`;+export const PEM_END_RSA = `-----END RSA ${PRIVATE_KEY_TAIL}`;+export const PEM_BEGIN_PKCS8 = `-----BEGIN ${PRIVATE_KEY_TAIL}`;+export const PEM_BLOCK = `${PEM_BEGIN_RSA}\n${KEY_BODY}\n${PEM_END_RSA}\n`;export const MARKER_BULLET = '<!-- gbrain:materialized v1 0123456789ab -->\n- **2024-01-02** | src — did a thing\n detail line\n';export const SOUP_ATOMS = ['<!--- gbrain:facts:begin -->', '<!--- gbrain:facts:end -->', '<!--- gbrain:takes:begin -->', '<!--- gbrain:takes:end -->','```', '~~~', '````', '```js', '`', '\n', '\n', '\n\n', '\r\n', '\r', ' ', 'text words here', 'é', '😀', '\u2028',- '## Heading 2024-03-05\n', '# Top\n', '### deep\n', '-----BEGIN RSA PRIVATE KEY-----\n', `${KEY_BODY}\n`,- '-----END RSA PRIVATE KEY-----\n', MARKER_BULLET, '- **2024-01-02** | src — entry\n', ' detail line\n', FACTS_BLOCK,+ '## Heading 2024-03-05\n', '# Top\n', '### deep\n', `${PEM_BEGIN_RSA}\n`, `${KEY_BODY}\n`,+ `${PEM_END_RSA}\n`, MARKER_BULLET, '- **2024-01-02** | src — entry\n', ' detail line\n', FACTS_BLOCK,];export function pick<T>(r: () => number, a: readonly T[]): T {diff --git a/test/large-pages/region-scan.test.ts b/test/large-pages/region-scan.test.tsindex 281be809fd..80e8e2dd2a 100644--- a/test/large-pages/region-scan.test.ts+++ b/test/large-pages/region-scan.test.ts@@ -19,11 +19,11 @@ import { PROTECTED_PAIRS } from '../../src/core/remote-body.ts';import { privateKeySpans } from '../../src/core/secret-scan.ts';import { feedPemScan, initialPemScan, initialRegionScan, protectedRegionScan, walkTrusted, type ScannedRegion } from '../../src/core/page-body/region-scan.ts';import { mulberry32 } from '../helpers/seeded-random.ts';-import { KEY_BODY, pick } from '../helpers/segment-bodies.ts';+import { KEY_BODY, PEM_BEGIN_PKCS8, PEM_BEGIN_RSA, PEM_END_RSA, pick } from '../helpers/segment-bodies.ts';const ATOMS = ['<!--- gbrain:facts:begin -->', '<!--- gbrain:facts:end -->', '<!--- gbrain:takes:begin -->', '<!--- gbrain:takes:end -->','```', '~~~', '````', '```js', '`', '\n', '\r\n', '\r', ' ', 'text', 'é', '😀', ' ```', ' ```', '\\`', '\u2028'];-const PEM_ATOMS = ['-----BEGIN RSA PRIVATE KEY-----', '-----END RSA PRIVATE KEY-----', '-----BEGIN PRIVATE KEY-----', KEY_BODY, 'AAAA',+const PEM_ATOMS = [PEM_BEGIN_RSA, PEM_END_RSA, PEM_BEGIN_PKCS8, KEY_BODY, 'AAAA','\n', '\r\n', ' ', 'prose words', '\\n', 'Proc-Type: 4,ENCRYPTED', '-----', 'BEGIN', ' PRIVATE KEY-----', 'x'.repeat(3000)];const byteAt = (s: string, i: number) => Buffer.byteLength(s.slice(0, i));diff --git a/test/large-pages/segmenter.test.ts b/test/large-pages/segmenter.test.tsindex 862ce796f6..8da4390304 100644--- a/test/large-pages/segmenter.test.ts+++ b/test/large-pages/segmenter.test.ts@@ -28,7 +28,7 @@ import { SEGMENT_MAX_BYTES, SEGMENT_MIN_BYTES } from '../../src/core/page-body/limport { regionFlags, Segmenter, segmentStream, segmentString, type SegmentOut } from '../../src/core/page-body/segmenter.ts';import { mulberry32 } from '../helpers/seeded-random.ts';import {- bigPage, FACTS_BLOCK, joinedProjection, KEY_BODY, MARKER_BULLET, PEM_BLOCK, pick, segmentOptions, segmentPieces, segmentShapeErrors, soup,+ bigPage, FACTS_BLOCK, joinedProjection, KEY_BODY, MARKER_BULLET, PEM_BEGIN_RSA, PEM_BLOCK, PEM_END_RSA, pick, segmentOptions, segmentPieces, segmentShapeErrors, soup,} from '../helpers/segment-bodies.ts';const MAX = SEGMENT_MAX_BYTES;@@ -295,8 +295,8 @@ describe('forced cuts with open state', () => {test('released early, a segment never shows what whole-body sanitization hides (key lines around giant regions)', () => {const r = mulberry32(91);- const keyish = [`${KEY_BODY}\n`, ` ${KEY_BODY.slice(0, 40)}\n`, 'prose line here\n', '\n', '-----BEGIN RSA PRIVATE KEY-----\n',- '-----END RSA PRIVATE KEY-----\n', `"k": "${KEY_BODY}\\n${KEY_BODY}\\n`, 'é😀\n', '## heading\n'];+ const keyish = [`${KEY_BODY}\n`, ` ${KEY_BODY.slice(0, 40)}\n`, 'prose line here\n', '\n', `${PEM_BEGIN_RSA}\n`,+ `${PEM_END_RSA}\n`, `"k": "${KEY_BODY}\\n${KEY_BODY}\\n`, 'é😀\n', '## heading\n'];const regions = [['<!--- gbrain:takes:begin -->\n', '<!--- gbrain:takes:end -->\n'], ['<!--- gbrain:takes:begin -->\n', ''],['<!--- gbrain:facts:begin -->\n', '<!--- gbrain:facts:end -->\n']];let guarded = 0;