From 83294a0faa84cf7d631eb16691af3febff11ac86 Mon Sep 17 00:00:00 2001 From: A-PachecoT Date: Sat, 3 Oct 2026 22:33:31 -0500 Subject: [PATCH] =?UTF-8?q?feat(hooks):=20links=20band=20=E2=80=94=20every?= =?UTF-8?q?=20Basalt=20doc=20of=20the=20session,=20one=20key=20away?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agents publish docs mid-conversation and the URL scrolls away with the chat. A function-hooks module (hooks/register.tsx, beside the shell hooks) scans every row the session appends — CLI output, MCP results, model text, subagents — for app.basalt.cofoundy.ai links and keeps them in a band above the prompt: - o opens the latest doc, c copies it, l (or /basalt-links) opens a side pane with all of them; the pane stays pinned across reloads and sessions until the person closes it. - Long nested names fit the band: the title survives (cut in the middle), then the space, then the nearest folders, collapsed to "…". - Basalt brand tokens: Molten only on the mark, Signal Teal for counts and links, Column Grey chip behind the wordmark. - The mark is the SVG on desktop, a PNG on kitty/Ghostty run directly, and ⬣ in Molten under a multiplexer, where Claude Code draws no pictures. Clients without function hooks keep the three shell hooks unchanged. Bumps the plugin to 0.3.0. Verified: claude plugin validate plugins/basalt (pass), claude plugin test plugins/basalt (4/4), tsc against Claude Code 2.1.288 types, scripts/validate-skills.sh (pass), hooks/tests/run.sh (101/101). --- .claude-plugin/marketplace.json | 4 +- README.md | 28 ++- plugins/basalt/.claude-plugin/plugin.json | 5 +- plugins/basalt/hooks/hooks.json | 5 +- plugins/basalt/hooks/mark.ts | 7 + plugins/basalt/hooks/register.tsx | 231 ++++++++++++++++++++++ plugins/basalt/tests/crumb.test.ts | 22 +++ plugins/basalt/types/index.d.ts | 7 + 8 files changed, 303 insertions(+), 6 deletions(-) create mode 100644 plugins/basalt/hooks/mark.ts create mode 100644 plugins/basalt/hooks/register.tsx create mode 100644 plugins/basalt/tests/crumb.test.ts create mode 100644 plugins/basalt/types/index.d.ts diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 0b702f2..490c5de 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.2.0" + "version": "0.3.0" }, "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.2.0", + "version": "0.3.0", "author": { "name": "Cofoundy SAC" }, diff --git a/README.md b/README.md index 4e50842..1e575c3 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,10 @@ plugins/basalt/ ├── .mcp.json # the Basalt MCP server (HTTP + per-user OAuth) ├── commands/basalt.md # the /basalt command ├── skills/basalt/SKILL.md # the auto-invoking skill (its description is the magic) -└── hooks/ # three session-boundary hooks (silence by default) +├── hooks/ # three session-boundary hooks (silence by default) +│ └── register.tsx # + the links band (a Claude Code function-hooks module) +├── types/index.d.ts # the band's state contract +└── tests/ # `claude plugin test plugins/basalt` ``` The plugin holds **no secrets** — it points at the public MCP endpoint and auth is @@ -117,6 +120,29 @@ so you don't have to silence the whole vault to quiet one file. Every hook ships tests that run against **real captured Claude Code payloads** (`hooks/tests/run.sh`) — a silent hook is worthless if it's silently dead. +## The links band (every doc of the session, one key away) + +Agents publish docs mid-conversation, and the URL scrolls away with the chat. The band +above the prompt keeps them: every `app.basalt.cofoundy.ai` link that enters the +session — from the CLI, the MCP, the model's own text or a subagent — lands there. + +``` +⬣ basalt 5 docs basalt-pm › … › v3.1-collaboration-…-review-loop-final [ Abrir ] [ Copiar ] [ Todos ] +``` + +`o` opens the latest doc in your browser, `c` copies its URL, `l` (or `/basalt-links`) +opens a side pane with every doc of the session. The pane stays pinned across reloads +and sessions until you close it. Long nested names keep the title (cut in the middle, +so its version suffix survives), then the space, then the nearest folders. + +The mark is the real logo where the surface can draw it: the SVG on the desktop app, +a PNG on kitty or Ghostty run directly, and `⬣` in Molten elsewhere (inside tmux, +screen, zellij or herdr Claude Code draws no pictures). + +It is a function-hooks module +(early access in Claude Code); clients without it keep the three shell hooks above, +unchanged. + ## Already have docs in git? Use the [`basalt` CLI](https://www.npmjs.com/package/basalt-cli) instead — it syncs a diff --git a/plugins/basalt/.claude-plugin/plugin.json b/plugins/basalt/.claude-plugin/plugin.json index 5619cf2..26cae5f 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.2.0", + "version": "0.3.0", "author": { "name": "Cofoundy SAC", "url": "https://cofoundy.dev" @@ -19,5 +19,6 @@ "ai-agents", "share-docs", "markdown" - ] + ], + "types": "./types/index.d.ts" } diff --git a/plugins/basalt/hooks/hooks.json b/plugins/basalt/hooks/hooks.json index 868a323..a09d43e 100644 --- a/plugins/basalt/hooks/hooks.json +++ b/plugins/basalt/hooks/hooks.json @@ -45,5 +45,8 @@ ] } ] - } + }, + "modules": [ + "./register.tsx" + ] } diff --git a/plugins/basalt/hooks/mark.ts b/plugins/basalt/hooks/mark.ts new file mode 100644 index 0000000..8a32fd8 --- /dev/null +++ b/plugins/basalt/hooks/mark.ts @@ -0,0 +1,7 @@ +// Basalt mark, from products/basalt/brand/assets: the SVG for surfaces that draw it, +// a 64 px PNG of it (basalt-mark-512.png) for terminals with the kitty graphics protocol. +export const MARK_SVG = + ' ' + +export const MARK_PNG = + 'iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAQKADAAQAAAABAAAAQAAAAABGUUKwAAAMrklEQVR4Ae0beZBT5f2X+9g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YjcWbsjAW+Chb4L4a2YLN94TiHAAAAAElFTkSuQmCC' diff --git a/plugins/basalt/hooks/register.tsx b/plugins/basalt/hooks/register.tsx new file mode 100644 index 0000000..b5cd1de --- /dev/null +++ b/plugins/basalt/hooks/register.tsx @@ -0,0 +1,231 @@ +import { atom, read, update } from 'claude-code' +import type { EngineInterface, Register } from 'claude-code' + +import { MARK_PNG, MARK_SVG } from './mark' + +import type { BasaltLink } from '../types' + +// Basalt brand tokens (products/basalt/tokens/colors.css). Dark-first: +// Molten is the one ember (the mark, nothing else), Signal Teal is links. +const MOLTEN = '#E2603B' +const ASH = '#F4F5F3' +const MUTED = '#7C828B' // stone-400: metadata on dark +const TEAL = '#3FB6A8' +const COLUMN = '#3A3F47' // column grey: the chip behind the wordmark +const STONE = '#B8BDC4' // stone-300: secondary text on dark + +const PANE = 'basalt-links' +const URL_RE = /https:\/\/app\.basalt\.cofoundy\.ai\/[^\s)\]"'<>`\\]+/g +// What the band's fixed parts take: "⬣ basalt · 12 docs · " + the four buttons. +const BAND_CHROME = 24 + 44 +const links = atom({ plugin: 'basalt', key: 'links' } as const, []) + +// Junta todos los strings de un content (texto del modelo, tool results, anidados). +const strings = (value: unknown, out: string[] = []): string[] => { + if (typeof value === 'string') out.push(value) + else if (Array.isArray(value)) value.forEach(v => strings(v, out)) + else if (value && typeof value === 'object') Object.values(value).forEach(v => strings(v, out)) + + return out +} + +// 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 => { + const segments = new URL(url).pathname.split('/').filter(Boolean).map(decodeURIComponent) + const trail = segments.length >= 3 ? segments.slice(1) : segments + const title = trail[trail.length - 1] ?? url + + return { url, title, trail: trail.slice(0, -1), by, at } +} + +// Rows stored by an earlier version of this mod carry no trail. +const fresh = (link: BasaltLink) => (Array.isArray(link.trail) ? link : toLink(link.url, link.by, link.at)) + +const cut = (text: string, room: number) => { + if (text.length <= room) return text + const keep = Math.max(1, room - 1) + const head = Math.ceil(keep / 2) + + return text.slice(0, head) + '…' + text.slice(text.length - (keep - head)) +} + +// Fits "space › folder › title" into `room` cells: the title always survives +// (cut in the middle, so its start and its version suffix stay), then the +// nearest folders, and whatever does not fit collapses to "…". +// Fits "space › folder › title" into `room` cells. Priority: the title (cut in +// the middle, so its start and its version suffix stay), then the space, then +// the nearest folders; the folders that do not fit collapse to "…". +export const crumb = (link: BasaltLink, room: number) => { + const trail = link.trail + const space = trail[0] + // The space keeps its place beside the title unless the room is too small for both. + const reserve = space === undefined ? 0 : trail.length > 1 ? space.length + 7 : space.length + 3 + const title = cut(link.title, Math.max(16, room - reserve)) + let left = room - title.length + const whole = trail.reduce((sum, part) => sum + part.length + 3, 0) + if (whole <= left) return { path: trail.map(part => part + ' › ').join(''), title } + left -= 4 // "… › " + const folders = trail.slice(1) + const head = space !== undefined && space.length + 3 <= left ? [space] : [] + left -= head.reduce((sum, part) => sum + part.length + 3, 0) + const near: string[] = [] + for (const part of [...folders].reverse()) { + if (part.length + 3 > left) break + near.unshift(part) + left -= part.length + 3 + } + + return { path: [...head, '…', ...near].map(part => part + ' › ').join(''), title } +} + +async function openUrl($: EngineInterface, url: string) { + const mac = await $.process.run(['open', url]).catch(() => ({ exitCode: 1 })) + if (mac.exitCode !== 0) await $.process.run(['xdg-open', url]).catch(() => undefined) +} + +// The pane stays open across reloads and sessions until the person closes it. +async function openPane($: EngineInterface, focus?: true) { + await $.store.set('isPinned', true) + await $.ui.open({ id: PANE, title: 'Basalt · docs de la sesión', ...(focus ? { focus } : {}) }) +} + +async function copyUrl($: EngineInterface, url: string, surface: Parameters[0]['surface']) { + await $.ui.copy({ text: url, surface }) + $.ui.toast('Link copiado') +} + +// Whether this terminal shows kitty graphics: kitty or Ghostty, run directly. +// A multiplexer (tmux, screen, herdr) passes none through, and there `Image` +// would draw its alt dim, so the glyph in Molten is the better fallback. +async function hasGraphics($: EngineInterface) { + const multiplexed = [ + await $.env.get('TMUX'), + await $.env.get('STY'), + await $.env.get('HERDR_ENV'), + await $.env.get('ZELLIJ'), + ].some(Boolean) + if (multiplexed) return false + const program = await $.env.get('TERM_PROGRAM') + + return program === 'ghostty' || Boolean(await $.env.get('KITTY_WINDOW_ID')) +} + +// The mark, best the surface can draw: the SVG on desktop, the PNG on a +// terminal with kitty graphics, and the hexagon glyph in Molten elsewhere. +async function mark($: EngineInterface, e: Parameters[0]) { + if (e.surface === 'terminal' && (await hasGraphics($))) { + const { Image } = $.ui.resolve(e) + + return ⬣ + } + if (e.surface === 'desktop') { + const { Svg } = $.ui.resolve(e) + + return + } + const { Text } = $.ui.resolve(e) + + return ⬣ +} + +export const register: Register = on => { + on('session.start', async ($, e, next) => { + await $.command.register({ name: 'basalt-links', description: 'Lista los docs de Basalt de esta sesión' }) + if ((await $.store.get('isPinned')) === true) void openPane($) + + return next(e) + }) + + on('command.run', { command: 'basalt-links' }, async $ => { + await openPane($) + + return { text: 'Docs de Basalt de esta sesión abiertos en el panel.' } + }) + + // Cada fila que entra a la conversación (tuya, del modelo, de un tool, de un subagente) se escanea. + on('session.append', async ($, e, next) => { + const stored = await next(e) + const found = strings(e.message.content).flatMap(text => text.match(URL_RE) ?? []) + if (found.length > 0) { + const now = await $.clock.now() + const by = e.agentId ? 'subagente' : 'sesión' + await update($, links, list => { + const known = new Set(list.map(link => link.url)) + const fresh = [...new Set(found.map(url => url.replace(/[.,;:!?]+$/, '')))] + .filter(url => !known.has(url)) + .map(url => toLink(url, by, now)) + + return [...list, ...fresh] + }) + } + + return stored + }) + + on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => { + const list = (await read($, links)).map(fresh) + const last = list[list.length - 1] + if (e.props.hasSurvey || !last) return next(e) + + const { Box, Button, Text } = $.ui.resolve(e) + const { path, title } = crumb(last, e.props.bodyColumns - BAND_CHROME) + const below = await next(e) + + return ( + + + {await mark($, e)} + + basalt + + {list.length} + doc{list.length === 1 ? '' : 's'} + {path} + {title} +