From ad677ff35bcb8936adee5cca6d2a361b60ef5d97 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Fri, 27 Nov 2026 08:14:30 +0000 Subject: [PATCH] fix(web): re-read the goal when its content changes past the snippet The graph gives the web UI each node's updatedAt (withUpdatedAt, asked for only by web-api), and the browser's diff counts it. Before, a saved Max intents edit changed neither tags nor snippet, so the page kept the old goal text and redrew the old limit after the follow-up poll. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 ++ supabase/functions/_shared/pg-store.ts | 3 ++- supabase/functions/_shared/types.ts | 3 +++ supabase/functions/_shared/web-api.ts | 2 ++ tests/integration/pg-store-graph.test.ts | 17 +++++++++++++++++ tests/unit/web-api.test.ts | 2 +- tests/unit/web-public.test.ts | 9 +++++++++ web/public/diff.js | 12 ++++++++++-- 8 files changed, 46 insertions(+), 4 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 47e23b1..59d60e6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -94,6 +94,8 @@ Design: `docs/superpowers/specs/2026-11-22-memory-claims-design.md` and filters (tags or tags_all required) oldest first, capped at `GRAPH_MAX_NODES` (400) or `GRAPH_FULL_MAX_NODES` (100) for full content, with `count(*) over ()` as `total`, then reads `memory_links` between those ids (the links policy hides unreadable or deleted ends), the superseded set, and the batched claims. No decay and no `touch_accessed`. +`withUpdatedAt` adds each node's `updatedAt`; only `web-api` asks for it (the browser's diff needs it to see an edit +past the snippet), so the MCP tool's output stays as it was. **Blackboard skill.** `skills/blackboard/` is a Claude Code skill, made of instructions only, that runs shared-goal boards on these tools: graph, claim_next, claims, links and search browse. It has no server code of its own. The design diff --git a/supabase/functions/_shared/pg-store.ts b/supabase/functions/_shared/pg-store.ts index fbbab16..9098413 100644 --- a/supabase/functions/_shared/pg-store.ts +++ b/supabase/functions/_shared/pg-store.ts @@ -620,7 +620,7 @@ export class PgMemoryStore implements MemoryStore { const scopeIds = await this.resolveScopeIds(tx, f.scopes); if (scopeIds.length === 0) return { nodes: [], edges: [], truncated: false, total: 0 }; const rows = await tx` - select id, scope, category, tags, content, created_at, count(*) over () as total + select id, scope, category, tags, content, created_at, updated_at, count(*) over () as total from agent_memory.memory_view where scope_id = any(${scopeIds}::uuid[]) and (${f.category ?? null}::text is null or category = ${f.category ?? null}::text) @@ -639,6 +639,7 @@ export class PgMemoryStore implements MemoryStore { tags: r.tags, createdAt: iso(r.created_at), }; + if (f.withUpdatedAt) n.updatedAt = iso(r.updated_at); if (full) n.content = r.content; else n.snippet = snippet(r.content, GRAPH_SNIPPET_CHARS); return n; diff --git a/supabase/functions/_shared/types.ts b/supabase/functions/_shared/types.ts index dc4df60..1596b61 100644 --- a/supabase/functions/_shared/types.ts +++ b/supabase/functions/_shared/types.ts @@ -115,6 +115,8 @@ export interface GraphFilters { tagsAll?: string[]; /** 'short' (default): a snippet per node; 'full': the whole content, with a lower node cap. */ detail?: 'short' | 'full'; + /** Give each node its `updatedAt`, so a caller that polls sees a content edit past the snippet (the web UI). */ + withUpdatedAt?: boolean; } export interface GraphNode { @@ -123,6 +125,7 @@ export interface GraphNode { category: MemoryCategory; tags: string[]; createdAt: string; + updatedAt?: string; snippet?: string; content?: string; superseded?: true; diff --git a/supabase/functions/_shared/web-api.ts b/supabase/functions/_shared/web-api.ts index 490f42b..d206967 100644 --- a/supabase/functions/_shared/web-api.ts +++ b/supabase/functions/_shared/web-api.ts @@ -369,6 +369,8 @@ export async function routeWebApi(req: Request, store: WebStore): Promise + withWorld(async (w, _a, mk) => { + const s = mk(w.rw.id); + const tag = freshTag(); + // The limit line sits past the snippet, so only updatedAt shows the edit. + const head = `Goal: ${'x'.repeat(200)}`; + const goal = await s.store(w.alpha.name, req(`${head}\nMax intents: 20`, [tag, 'kind:goal'])); + const before = (await s.graph({ tagsAll: [tag], withUpdatedAt: true })).nodes[0]; + assertEquals(before.updatedAt, goal.updatedAt); + await s.update(goal.id, { content: `${head}\nMax intents: 30` }); + const after = (await s.graph({ tagsAll: [tag], withUpdatedAt: true })).nodes[0]; + assertEquals(after.snippet, before.snippet); + assertEquals(typeof after.updatedAt, 'string'); + assertEquals(after.updatedAt !== before.updatedAt, true); })); Deno.test('graph short gives 160-character snippets; full gives content and caps at 100', () => diff --git a/tests/unit/web-api.test.ts b/tests/unit/web-api.test.ts index 92ba8ea..9d2fb97 100644 --- a/tests/unit/web-api.test.ts +++ b/tests/unit/web-api.test.ts @@ -212,7 +212,7 @@ Deno.test('GET /graph requires tags_all and passes the filters', async () => { assertEquals(await r.json(), EMPTY_GRAPH); assertEquals(s.calls, [{ fn: 'graph', - args: [{ tagsAll: ['board:x', 'kind:goal'], scopes: ['a'], detail: 'full' }], + args: [{ tagsAll: ['board:x', 'kind:goal'], scopes: ['a'], detail: 'full', withUpdatedAt: true }], }]); }); diff --git a/tests/unit/web-public.test.ts b/tests/unit/web-public.test.ts index afb677f..b400b75 100644 --- a/tests/unit/web-public.test.ts +++ b/tests/unit/web-public.test.ts @@ -116,6 +116,7 @@ Deno.test('workerLabel falls back to the claim session, then the claim descripti type Node = { id: string; + updatedAt?: string; scope: string; category: string; tags: string[]; @@ -155,6 +156,14 @@ Deno.test('diffGraph sees tags, snippet and superseded changes', () => { assertEquals(diffGraph(prev, next).changed, ['a', 'b', 'c']); }); +Deno.test('diffGraph sees a content edit below the snippet through updatedAt', () => { + const at = '2026-01-01T00:00:00.000Z'; + const prev = graph(node('a', { updatedAt: at }), node('b')); + const next = graph(node('a', { updatedAt: '2026-01-01T00:00:05.000Z' }), node('b')); + assertEquals(diffGraph(prev, next).changed, ['a']); + assertEquals(diffGraph(prev, graph(node('a', { updatedAt: at }), node('b'))).changed, []); +}); + Deno.test('diffGraph sees a claim appear, disappear or move', () => { const claim = { by: 'me', until: null, description: 'd', session: { id: '1', label: 'w1' } }; assertEquals(diffGraph(graph(node('a')), graph(node('a', { claim }))).changed, ['a']); diff --git a/web/public/diff.js b/web/public/diff.js index c07bdcc..7304f0f 100644 --- a/web/public/diff.js +++ b/web/public/diff.js @@ -8,6 +8,7 @@ * id: string; * tags: string[]; * snippet?: string; + * updatedAt?: string; * superseded?: true; * claim?: Claim; * }} GraphNode @@ -28,11 +29,18 @@ function claimKey(c) { * @returns {string} */ function nodeKey(n) { - return JSON.stringify([[...n.tags].sort(), n.snippet ?? null, n.superseded === true, claimKey(n.claim)]); + return JSON.stringify([ + [...n.tags].sort(), + n.snippet ?? null, + n.updatedAt ?? null, + n.superseded === true, + claimKey(n.claim), + ]); } /** - * Which node ids appeared, vanished or changed (tags, snippet, superseded or the whole claim) between two graphs. + * Which node ids appeared, vanished or changed (tags, snippet, updatedAt, superseded or the whole claim) between two + * graphs. updatedAt is what shows an edit past the snippet, such as the goal's `Max intents:` line. * @param {GraphResult | null} prev * @param {GraphResult} next * @returns {{ added: string[]; removed: string[]; changed: string[] }}