From bcc43c7165e94df1488da966ad1dd367f7f6e9a5 Mon Sep 17 00:00:00 2001 From: A-PachecoT Date: Mon, 5 Oct 2026 17:02:23 -0500 Subject: [PATCH] fix(hooks): links band counts only docs the session published The band scanned every conversation row, so a link the session merely read (a subagent grepping old transcripts) showed up as one of its docs: 6 docs in a session that published none. It now takes links from the result of a publish (basalt publish|move, publish_doc|update_doc over MCP), never from reads. Claude-Session: https://claude.ai/code/session_01G9jK1XDP9gkSR5JA6xhBWh --- .claude-plugin/marketplace.json | 4 +- plugins/basalt/.claude-plugin/plugin.json | 2 +- plugins/basalt/hooks/register.tsx | 18 ++++++--- plugins/basalt/tests/links.test.tsx | 49 +++++++++++++++++++++++ 4 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 plugins/basalt/tests/links.test.tsx diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 354a94e..c397635 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -6,14 +6,14 @@ }, "metadata": { "description": "Basalt — the trust layer for AI-generated work. Connect your AI to publish, update and share governed docs by URL.", - "version": "0.3.1" + "version": "0.3.2" }, "plugins": [ { "name": "basalt", "source": "./plugins/basalt", "description": "Connect your AI to Basalt — publish, update and share governed docs by URL. Bundles the Basalt MCP server (OAuth) + a skill that converges on it when you ask to publish or share written work.", - "version": "0.3.1", + "version": "0.3.2", "author": { "name": "Cofoundy SAC" }, diff --git a/plugins/basalt/.claude-plugin/plugin.json b/plugins/basalt/.claude-plugin/plugin.json index e50ac1c..4a3218a 100644 --- a/plugins/basalt/.claude-plugin/plugin.json +++ b/plugins/basalt/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "basalt", "description": "Connect your AI to Basalt — publish, update and share governed docs by URL. Bundles the Basalt MCP server (OAuth), a skill that converges on it when you ask to publish or share written work, and quiet session hooks (auth probe · edit tracking · publish nudge).", - "version": "0.3.1", + "version": "0.3.2", "author": { "name": "Cofoundy SAC", "url": "https://cofoundy.dev" diff --git a/plugins/basalt/hooks/register.tsx b/plugins/basalt/hooks/register.tsx index 6d849ea..800f866 100644 --- a/plugins/basalt/hooks/register.tsx +++ b/plugins/basalt/hooks/register.tsx @@ -29,6 +29,12 @@ const strings = (value: unknown, out: string[] = []): string[] => { return out } +// The calls that publish: `basalt publish|move` from a shell, `publish_doc|update_doc` over MCP. +export const isPublish = (tool: string, command: unknown): boolean => + tool === 'Bash' + ? typeof command === 'string' && /(^|[\s;&|(])basalt\s+(publish|move)\b/.test(command) + : /basalt/i.test(tool) && /__(publish_doc|update_doc)$/.test(tool) + // Canonical URLs are /{workspace}/{space}/{doc…}; the workspace is always the // same for one person, so the trail starts at the space. export const toLink = (url: string, by: string, at: number): BasaltLink => { @@ -173,10 +179,12 @@ export const register: Register = on => { return { text: (await labels($)).opened } }) - // Every row the conversation keeps (the person's, the model's, a tool's, a subagent's) is scanned. - on('session.append', async ($, e, next) => { - const stored = await next(e) - const found = strings(e.message.content).flatMap(text => text.match(URL_RE) ?? []) + // Only what this session published: the result of a publish, never a link it merely read + // (a subagent grepping old transcripts filled the band with docs nobody made). + on('tool.call', async ($, e, next) => { + const out = await next(e) + if (!isPublish(e.tool, (e as { command?: unknown }).command) || out.deny !== undefined || out.isError) return out + const found = strings([out.text, out.result]).flatMap(text => text.match(URL_RE) ?? []) if (found.length > 0) { const now = await $.clock.now() const by = e.agentId ? 'subagent' : 'session' @@ -190,7 +198,7 @@ export const register: Register = on => { }) } - return stored + return out }) on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => { diff --git a/plugins/basalt/tests/links.test.tsx b/plugins/basalt/tests/links.test.tsx new file mode 100644 index 0000000..8b8e348 --- /dev/null +++ b/plugins/basalt/tests/links.test.tsx @@ -0,0 +1,49 @@ +import { describe, expect, mock, test } from 'claude-code/testing' + +import { isPublish } from '../hooks/register' + +const Box = 'Box' as any +const URL = 'https://app.basalt.cofoundy.ai/cofoundy/factory/intent/panel' +const BAND = { component: 'AbovePrompt', props: { hasSurvey: false, isWorking: false, maxRows: 20 } } as const + +function engine(on: any) { + mock.clock(on) + mock.store(on) + mock.env(on, {}) + on('session.start', ($: any, e: any) => ({ cwd: e.cwd })) + on('command.register', ($: any, e: any) => ({ value: { command: e.name } })) + on('ui.render', () => ) + on('tool.call', () => ({ result: { stdout: `ok ${URL}` }, text: `ok ${URL}` })) +} + +const band = async ($: any) => { + await $.session.start({ cwd: '/w', surface: 'terminal', isInteractive: true }) + const ui = await $.ui.mount({ plugin: 'basalt', surface: 'terminal', ...BAND } as any) + const shown = (await ui.find({ key: 'abrir' })) !== undefined + await ui.unmount() + return shown +} + +describe('links band', () => { + test('a link the session only read is not a doc it made', async ($, on) => { + engine(on) + await $.tool.call({ tool: 'Bash', command: `grep -r basalt ~/.claude/projects` } as any) + expect(await band($)).toBe(false) + }) + + test('a publish puts its link in the band', async ($, on) => { + engine(on) + await $.tool.call({ tool: 'Bash', command: 'basalt publish docs/panel.md' } as any) + expect(await band($)).toBe(true) + }) + + test('which calls publish', () => { + expect(isPublish('Bash', 'cd vault && basalt publish a.md')).toBe(true) + expect(isPublish('Bash', 'basalt move p/a p/b')).toBe(true) + expect(isPublish('Bash', 'basalt list')).toBe(false) + expect(isPublish('Bash', 'cat basalt-publish.log')).toBe(false) + expect(isPublish('mcp__plugin_basalt_basalt__publish_doc', undefined)).toBe(true) + expect(isPublish('mcp__basalt__update_doc', undefined)).toBe(true) + expect(isPublish('mcp__basalt__get_doc', undefined)).toBe(false) + }) +})