Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
feat(get_page): content_only returns the round-trip fields without the duplicated compiled_truth/timeline
Howard Park83825d6a95e6
diff --git a/src/core/ops/pages.ts b/src/core/ops/pages.tsindex 8e61d67fd8..9c15c63c96 100644--- a/src/core/ops/pages.ts+++ b/src/core/ops/pages.ts@@ -83,6 +83,7 @@ const get_page: Operation = {slug: { type: 'string', description: 'Page slug.', required: true },fuzzy: { type: 'boolean', description: 'Fuzzy slug match.' },include_content: { type: 'boolean', description: 'Full markdown + revision, for editing.' },+ content_only: { type: 'boolean', description: 'With include_content: only the round-trip fields (slug, type, title, revision, tags, content).' },include_deleted: { type: 'boolean', description: 'Include soft-deleted pages.' },include_timeline_entries: { type: 'boolean', description: 'Also return timeline rows.' },source_id: { type: 'string', description: "One source, or '__all__'." },@@ -93,6 +94,9 @@ const get_page: Operation = {const includeDeleted = (p.include_deleted as boolean) === true;const includeContent = (p.include_content as boolean) === true;const includeTimelineEntries = (p.include_timeline_entries as boolean) === true;+ // Only meaningful with include_content: a round-trip reader needs `content`+ // + `revision`, not the same text again as compiled_truth + timeline.+ const contentOnly = includeContent && (p.content_only as boolean) === true;// #4329: honor a per-call source_id (pre-fix it was silently dropped).// resolveRequestedScope (inside federatedSearchScope) enforces the remote// caller's grant on the explicit value.@@ -198,6 +202,25 @@ const get_page: Operation = {// Opt-in (include_content: true): get_page is the most-called read op, and// `content` roughly duplicates compiled_truth + timeline — always emitting// it would double every reader's payload for the round-trip minority.+ if (contentOnly) {+ // Everything a get→edit→put_page round trip needs, without the duplicate+ // compiled_truth / timeline / frontmatter the full shape carries next to+ // `content` (a 30 KB page otherwise comes back as ~62 KB).+ const deletedAt = (visibleBody as { deleted_at?: unknown }).deleted_at;+ return {+ slug: visibleBody.slug,+ type: visibleBody.type,+ title: visibleBody.title,+ revision: snapshot!.revision,+ tags,+ content: serializePageToMarkdown(visibleBody as Page, tags),+ ...(includeTimelineEntries+ ? { timeline_entries: await ctx.engine.getTimeline(page.slug, await readPolicyOpts(ctx, { sourceId: page.source_id })) } : {}),+ ...(deletedAt ? { deleted_at: deletedAt } : {}),+ ...(resolved_slug ? { resolved_slug } : {}),+ ...(content_flag ? { content_flag } : {}),+ };+ }return {...visibleBody,revision: snapshot!.revision,diff --git a/test/get-page-content-roundtrip-2225.test.ts b/test/get-page-content-roundtrip-2225.test.tsindex fe21f21b66..9df3c294f7 100644--- a/test/get-page-content-roundtrip-2225.test.ts+++ b/test/get-page-content-roundtrip-2225.test.ts@@ -86,6 +86,33 @@ describe('get_page content round-trip (#2225)', () => {expect(page.timeline as string).toContain('Series A closed');}, 30_000);+ test('content_only: the round-trip fields without the duplicated compiled_truth / timeline / frontmatter', async () => {+ await putPage.handler(localCtx(), { slug: 'companies/contentonly-example', content: ORIGINAL });++ const full = (await getPage.handler(localCtx(), { slug: 'companies/contentonly-example', include_content: true })) as Record<string, unknown>;+ const lean = (await getPage.handler(localCtx(), { slug: 'companies/contentonly-example', include_content: true, content_only: true })) as Record<string, unknown>;+ expect(lean.content).toBe(full.content);+ expect(lean.revision).toBe(full.revision);+ expect(lean.slug).toBe('companies/contentonly-example');+ expect(lean.title).toBe('Acme Example');+ for (const dup of ['compiled_truth', 'timeline', 'frontmatter']) expect(dup in lean).toBe(false);+ expect(JSON.stringify(lean).length).toBeLessThan(JSON.stringify(full).length);++ // The lean read is enough for a revision-checked round trip.+ const edited = (lean.content as string).replace('42 employees', '44 employees');+ await putPage.handler(localCtx(), { slug: 'companies/contentonly-example', content: edited, expected_revision: lean.revision });+ const row = await engine.getPage('companies/contentonly-example', { sourceId: 'default' });+ expect(row!.compiled_truth ?? '').toContain('44 employees');+ expect(row!.timeline ?? '').toContain('Series A closed');+ }, 30_000);++ test('content_only without include_content is ignored (the default read shape is unchanged)', async () => {+ await putPage.handler(localCtx(), { slug: 'companies/contentonly-ignored', content: ORIGINAL });+ const page = (await getPage.handler(localCtx(), { slug: 'companies/contentonly-ignored', content_only: true })) as Record<string, unknown>;+ expect('content' in page).toBe(false);+ expect(page.compiled_truth as string).toContain('Acme builds widgets');+ }, 30_000);+test('naive get_page.content → put_page preserves pages.timeline', async () => {await putPage.handler(localCtx(), { slug: 'companies/roundtrip-example', content: ORIGINAL });