diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index f8c3e9a..6291c09 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.4" + "version": "0.3.5" }, "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.4", + "version": "0.3.5", "author": { "name": "Cofoundy SAC" }, diff --git a/README.md b/README.md index 9ab66b2..813629b 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,15 @@ workspace directly. A Claude Code session where the agent published three docs. Above the prompt, the Basalt band shows the mark, 3 docs and the latest one, architecture-v2, with the buttons Open, Copy and All; a side pane lists every doc of the session with its space, folder and link.

-`o` opens the latest doc in your browser, `c` copies its URL, `l` (or `/basalt-links`) +**New first, then edits.** Each doc says what the session did to it: `new v1` when the +session created it, `edited v7` when it published a new version of a doc that already +existed (the version comes from the server; basalt-cli ≥ 0.16.1 prints it, and a pushed +doc is `new` when the push added the file). The band shows the newest doc the session +*created*, with the tally beside it (`1 new · 2 edited`); the pane lists the created docs +first, under their own heading, then the edits, newest first in each. Publishing the same +doc again updates its row: the version moves, and a doc the session created stays `new`. + +`o` opens the doc in the band 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. diff --git a/plugins/basalt/.claude-plugin/plugin.json b/plugins/basalt/.claude-plugin/plugin.json index 3f105a4..690d0f9 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.4", + "version": "0.3.5", "author": { "name": "Cofoundy SAC", "url": "https://cofoundy.dev" diff --git a/plugins/basalt/hooks/register.tsx b/plugins/basalt/hooks/register.tsx index c468eff..d797db7 100644 --- a/plugins/basalt/hooks/register.tsx +++ b/plugins/basalt/hooks/register.tsx @@ -50,6 +50,56 @@ export const isPublish = (tool: string, command: unknown): boolean => export const isGitPush = (command: unknown): boolean => typeof command === 'string' && GIT_PUSH.test(commandText(command)) +// What a publish said about each URL it printed: created or a new version, and which one. +// The CLI prints one row per doc — `new space/slug v1` — and `--json` / MCP return +// objects with `status` and `version`. Version 1 IS a creation, whichever surface said it. +type Fact = { kind?: 'new' | 'edited'; version?: number } +const EDITED = new Set(['modified', 'republished', 'overwritten', 'metadata-only', 'conflict']) +const kindOf = (status?: unknown, version?: number): Fact['kind'] => { + const word = typeof status === 'string' ? status.replace(/^✗\s*/, '') : undefined + if (word === 'new' || version === 1) return 'new' + if ((word && EDITED.has(word)) || (version !== undefined && version > 1)) return 'edited' + return undefined +} + +const clean = (url: string) => url.replace(/[.,;:!?]+$/, '') + +export const publishFacts = (text: string): Map => { + const facts = new Map() + const put = (url: string, fact: Fact) => { + const before = facts.get(url) ?? {} + facts.set(url, { kind: before.kind ?? fact.kind, version: before.version ?? fact.version }) + } + // JSON (`--json`, MCP Trust Object): every object that carries a Basalt URL. + const walk = (value: unknown) => { + if (Array.isArray(value)) return value.forEach(walk) + if (!value || typeof value !== 'object') return + const o = value as Record + const url = [o.canonicalUrl, o.canonical_url, o.url].find( + (u): u is string => typeof u === 'string' && u.startsWith('https://app.basalt.cofoundy.ai/'), + ) + if (url) { + const version = typeof o.version === 'number' ? o.version : undefined + put(clean(url), { kind: kindOf(o.status, version), version }) + } + Object.values(o).forEach(walk) + } + for (const chunk of text.split(/\n(?=[[{])/)) { + try { walk(JSON.parse(chunk)) } catch { /* not JSON: the row reader below */ } + } + // Human rows: the status is the line's first word, the version a `v` on the same line. + for (const line of text.split('\n')) { + const urls = line.match(URL_RE) + if (!urls) continue + const status = line.trim().replace(/^✗\s*/, '').split(/\s+/)[0] + const v = line.match(/\sv(\d+)\b/) + const version = v ? Number(v[1]) : undefined + for (const url of urls) put(clean(url), { kind: kindOf(status, version), version }) + } + + return facts +} + // The ranges a `git push` moved onto a default branch (" 1a2b3c4..5d6e7f8 main -> main"). // A new branch, a delete or a push to any other branch publishes nothing: the vault's // Action publishes on a push to main. @@ -97,18 +147,22 @@ export type PushIo = { // changed under a vault.yaml, in a repo whose workflows run `basalt publish`. The URL is // the flat /{space}/{slug} one: the app sends whoever may read it to the canonical URL, // and the workspace is not knowable from the repo. -export async function pushedDocs(io: PushIo, dir: string, output: string): Promise<{ url: string; trail: string[]; title: string }[]> { +export async function pushedDocs(io: PushIo, dir: string, output: string): Promise<{ url: string; trail: string[]; title: string; kind: 'new' | 'edited' }[]> { const ranges = pushedRanges(output) if (ranges.length === 0) return [] const top = await io.git(dir, ['rev-parse', '--show-toplevel']) if (top.exitCode !== 0) return [] const root = top.stdout.trim() - const docs: { url: string; trail: string[]; title: string }[] = [] + const docs: { url: string; trail: string[]; title: string; kind: 'new' | 'edited' }[] = [] for (const { from, to } of ranges) { const action = await io.git(root, ['grep', '-l', '-e', 'basalt publish', to, '--', '.github/workflows']) if (action.exitCode !== 0) continue - const changed = await io.git(root, ['diff', '--name-only', '--diff-filter=AMR', `${from}..${to}`, '--', '*.md', '*.mdx']) - for (const file of changed.stdout.split('\n').filter(Boolean)) { + // `A` is a doc the push created; `M`/`R` a new version of one that existed. + const changed = await io.git(root, ['diff', '--name-status', '--diff-filter=AMR', `${from}..${to}`, '--', '*.md', '*.mdx']) + for (const row of changed.stdout.split('\n').filter(Boolean)) { + const cols = row.split('\t') + const kind = cols[0]?.startsWith('A') ? 'new' : 'edited' + const file = cols[cols.length - 1] ?? '' const parts = file.split('/') for (let depth = parts.length - 1; depth >= 0; depth--) { const yaml = await io.read([root, ...parts.slice(0, depth), 'vault.yaml'].join('/')) @@ -117,7 +171,7 @@ export async function pushedDocs(io: PushIo, dir: string, output: string): Promi const slug = normalizeSlug(parts.slice(depth).join('/')) if (space && slug) { const path = slug.split('/') - docs.push({ url: `${BASE}/${space}/${slug}`, trail: [space, ...path.slice(0, -1)], title: path[path.length - 1] ?? slug }) + docs.push({ url: `${BASE}/${space}/${slug}`, trail: [space, ...path.slice(0, -1)], title: path[path.length - 1] ?? slug, kind }) } break } @@ -158,6 +212,21 @@ export const withWorkspace = (link: BasaltLink, list: BasaltLink[]): BasaltLink // Rows stored by an earlier version carry no trail. const fresh = (link: BasaltLink) => (Array.isArray(link.trail) ? link : toLink(link.url, link.by, link.at)) +// Created docs first, then new versions, each newest first: what the person most likely +// wants to open is what this session MADE. Rows from an earlier band (no kind) go last. +const RANK = { new: 0, edited: 1, unknown: 2 } as const +export const ordered = (list: BasaltLink[]): BasaltLink[] => + [...list].sort((a, b) => RANK[a.kind ?? 'unknown'] - RANK[b.kind ?? 'unknown'] || b.at - a.at) + +// Publishing a doc again updates its row instead of adding nothing: the time moves, the +// version is the latest, and a doc this session created stays «new». +export const merge = (row: BasaltLink, again: BasaltLink): BasaltLink => ({ + ...row, + at: Math.max(row.at, again.at), + kind: row.kind === 'new' || again.kind === 'new' ? 'new' : (again.kind ?? row.kind), + version: Math.max(row.version ?? 0, again.version ?? 0) || undefined, +}) + const cut = (text: string, room: number) => { if (text.length <= room) return text const keep = Math.max(1, room - 1) @@ -208,16 +277,31 @@ const STRINGS = { pane: 'Basalt · session docs', empty: 'No Basalt docs in this session yet.', command: 'List the Basalt docs of this session', opened: 'Basalt docs of this session opened in the pane.', session: 'session', subagent: 'subagent', + new: 'new', edited: 'edited', newGroup: 'New', editedGroup: 'Edited', }, es: { open: 'Abrir', copy: 'Copiar', all: 'Todos', copied: 'Link copiado', pane: 'Basalt · docs de la sesión', empty: 'Ningún doc de Basalt en esta sesión todavía.', command: 'Lista los docs de Basalt de esta sesión', opened: 'Docs de Basalt de esta sesión abiertos en el panel.', session: 'sesión', subagent: 'subagente', + new: 'nuevo', edited: 'editado', newGroup: 'Nuevos', editedGroup: 'Editados', }, } as const type Strings = (typeof STRINGS)[keyof typeof STRINGS] +// «nuevo» / «editado v3» — the one word that says what this session did to the doc. +export const tag = (link: BasaltLink, t: Pick): string => + link.kind === undefined ? '' : `${link.kind === 'new' ? t.new : t.edited}${link.version ? ` v${link.version}` : ''}` + +// «1 nuevo · 2 editados»; falls back to the plain count when no row knows its kind. +export const tally = (list: BasaltLink[], t: Pick, es: boolean): string => { + const n = list.filter(l => l.kind === 'new').length + const m = list.filter(l => l.kind === 'edited').length + if (n + m === 0) return `${list.length} doc${list.length === 1 ? '' : 's'}` + const plural = (word: string, k: number) => (k === 1 || !es ? word : `${word}s`) + return [n ? `${n} ${plural(t.new, n)}` : '', m ? `${m} ${plural(t.edited, m)}` : ''].filter(Boolean).join(' · ') +} + export const pickLanguage = (lcAll?: string, lcMessages?: string, lang?: string): keyof typeof STRINGS => { const locale = lcAll || lcMessages || lang || '' @@ -304,8 +388,7 @@ export const register: Register = on => { const by = e.agentId ? 'subagent' : 'session' const now = await $.clock.now() if (publish) { - for (const url of new Set((text.match(URL_RE) ?? []).map(url => url.replace(/[.,;:!?]+$/, '')))) - found.push(toLink(url, by, now)) + for (const [url, fact] of publishFacts(text)) found.push({ ...toLink(url, by, now), ...fact }) } else { const dir = pushDir(command as string, await $.session.cwd(), (await $.env.get('HOME')) ?? '') for (const doc of await pushedDocs(pushIo($), dir, text).catch(() => [])) found.push({ ...doc, by, at: now }) @@ -314,10 +397,14 @@ export const register: Register = on => { // One doc, one row: a flat /{space}/{slug} and its canonical /{ws}/{space}/{slug} are the same doc. const key = (link: BasaltLink) => [...link.trail, link.title].join('/') await update($, links, list => { - const known = new Set(list.map(fresh).map(key)) - const added = found.filter(link => !known.has(key(link)) && known.add(key(link))).map(link => withWorkspace(link, list)) + const rows = list.map(fresh) + for (const link of found) { + const i = rows.findIndex(row => key(row) === key(link)) + if (i >= 0) rows[i] = merge(rows[i] as BasaltLink, link) + else rows.push(withWorkspace(link, rows)) + } - return [...list, ...added] + return rows }) } @@ -325,13 +412,15 @@ export const register: Register = on => { }) on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => { - const list = (await read($, links)).map(fresh) - const last = list[list.length - 1] + const list = ordered((await read($, links)).map(fresh)) + const last = list[0] if (e.props.hasSurvey || !last) return next(e) const { Box, Button, Text } = $.ui.resolve(e) const t = await labels($) - const { path, title } = crumb(last, e.props.bodyColumns - BAND_CHROME) + const count = tally(list, t, t === STRINGS.es) + const label = tag(last, t) + const { path, title } = crumb(last, e.props.bodyColumns - BAND_CHROME - count.length - (label ? label.length + 3 : 0)) const below = await next(e) return ( @@ -341,10 +430,11 @@ export const register: Register = on => { basalt - {list.length} - doc{list.length === 1 ? '' : 's'} + {count} + {path} {title} + {label ? · {label} : null}