diff --git a/packages/api-model/src/capabilities.ts b/packages/api-model/src/capabilities.ts new file mode 100644 index 000000000..34dc5fe06 --- /dev/null +++ b/packages/api-model/src/capabilities.ts @@ -0,0 +1,204 @@ +/** + * Capability manifests: what each port's typed `support.capabilities` registry + * says it can do on each tmux release, as the port itself serializes it. + * + * A port never writes this file by hand. Its own build emits it from the + * registry the library refuses with, and its own drift test fails when the + * two disagree. The site reads the manifest from the same checkout and + * revision as that port's API model, resolves every API name in it through + * the model, and computes each table cell from the release fields. Nothing + * here is a list somebody keeps in step. + */ + +export const CAPABILITY_SCHEMA = 'libtmux-capabilities/1' + +/** A tmux command, and the flags of it a capability depends on. */ +export interface CapabilityCommand { + command: string + flags?: string[] +} + +/** How a library behaves where the capability is not available. */ +export type Handling = 'refuse' | 'fallback' | 'repair' + +/** One positive capability, as the port's registry declares it. */ +export interface CapabilityEntry { + /** Stable id shared by every port (`control-mode`, `buffer-delete-named`). */ + id: string + /** Short name for headings. */ + name: string + /** One sentence: what a caller can do with it. */ + summary: string + /** The first tmux release it works on. */ + since: string + /** Exact releases at or above `since` where it does not work. */ + except?: string[] + /** What the library does below `since` or on an excepted release. */ + handling: Handling + /** The API name of the error a refusal raises. Required when `handling` is `refuse`. */ + error?: string + /** Public API names that need this capability, as the port's API model names them. */ + apis: string[] + /** tmux commands the capability concerns. */ + commands: CapabilityCommand[] +} + +/** A release-specific defect the library works around. Not a capability. */ +export interface Workaround { + id: string + name: string + summary: string + /** Exact releases the workaround applies to. */ + releases: string[] + handling: Exclude + apis: string[] + commands: CapabilityCommand[] +} + +/** The floor from the port's `support.versions`. */ +export interface Floor { + minimum: string +} + +export interface CapabilityManifest { + schema: typeof CAPABILITY_SCHEMA + /** The site's port slug. */ + port: string + floor: Floor + capabilities: CapabilityEntry[] + workarounds: Workaround[] +} + +/** + * A version tmux has printed: `X.Y`, `X.Ya`, `X.Y-rc`, `X.Y-rcN` or `next-X.Y`. + * tmux names its first candidate `X.Y-rc` and the next `X.Y-rc2`, so N starts + * at 2 and has no leading zero. + */ +const VERSION = /^(?:next-(0|[1-9]\d*)\.(0|[1-9]\d*)|(0|[1-9]\d*)\.(0|[1-9]\d*)([a-z]?)(-rc(?:[2-9]|[1-9]\d+)?)?)$/ + +/** A sortable key in tmux's own order: next-X.Y < X.Y-rc < X.Y-rcN < X.Y < X.Ya. */ +export function tmuxVersionKey(version: string): number[] { + const m = VERSION.exec(version) + if (!m) throw new TypeError(`not a version tmux prints: ${JSON.stringify(version)}`) + if (m[1] !== undefined) return [Number(m[1]), Number(m[2]), 0, 0, 0] + const letter = m[5] ? m[5].charCodeAt(0) - 96 : 0 + if (m[6] !== undefined) { + if (letter) throw new TypeError(`a candidate carries no patch letter: ${JSON.stringify(version)}`) + return [Number(m[3]), Number(m[4]), 1, Number(m[6].slice(3)), 0] + } + return [Number(m[3]), Number(m[4]), 2, 0, letter] +} + +export function compareTmuxVersions(a: string, b: string): number { + const ka = tmuxVersionKey(a) + const kb = tmuxVersionKey(b) + for (let i = 0; i < ka.length; i++) if (ka[i] !== kb[i]) return ka[i] - kb[i] + return 0 +} + +/** What a library does with a capability on one release. */ +export type CellState = 'supported' | 'workaround' | 'fallback' | 'refused' | 'repaired' + +export function capabilityState(entry: CapabilityEntry, release: string): CellState { + const available = compareTmuxVersions(release, entry.since) >= 0 && !(entry.except ?? []).includes(release) + if (available) return 'supported' + if (entry.handling === 'fallback') return 'fallback' + if (entry.handling === 'repair') return 'repaired' + return 'refused' +} + +export function workaroundState(entry: Workaround, release: string): CellState { + if (!entry.releases.includes(release)) return 'supported' + return entry.handling === 'repair' ? 'workaround' : 'refused' +} + +const ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/ + +function isString(v: unknown): v is string { + return typeof v === 'string' && v.length > 0 +} + +function checkVersion(errors: string[], where: string, v: unknown): void { + if (!isString(v)) { + errors.push(`${where}: expected a tmux version`) + return + } + try { + tmuxVersionKey(v) + } catch (e) { + errors.push(`${where}: ${(e as Error).message}`) + } +} + +function checkCommands(errors: string[], where: string, v: unknown): void { + if (!Array.isArray(v)) { + errors.push(`${where}: expected an array of commands`) + return + } + v.forEach((c, i) => { + if (!c || typeof c !== 'object' || !isString((c as CapabilityCommand).command)) { + errors.push(`${where}[${i}]: expected { command, flags? }`) + return + } + const flags = (c as CapabilityCommand).flags + if (flags !== undefined && (!Array.isArray(flags) || !flags.every((f) => /^-[A-Za-z]$/.test(f)))) { + errors.push(`${where}[${i}].flags: expected single-letter flags such as "-b"`) + } + }) +} + +function checkNames(errors: string[], where: string, v: unknown): void { + if (!Array.isArray(v) || !v.every(isString)) errors.push(`${where}: expected an array of API names`) +} + +/** + * Validate a manifest without a schema library. Every problem is reported, so + * a port fixing its emitter sees the whole list at once. + */ +export function validateManifest(value: unknown): { manifest?: CapabilityManifest; errors: string[] } { + const errors: string[] = [] + const m = value as Partial | null + if (!m || typeof m !== 'object') return { errors: ['manifest: expected an object'] } + if (m.schema !== CAPABILITY_SCHEMA) errors.push(`schema: expected "${CAPABILITY_SCHEMA}"`) + if (!isString(m.port)) errors.push('port: expected the site port slug') + checkVersion(errors, 'floor.minimum', m.floor?.minimum) + const ids = new Set() + const seen = (where: string, id: unknown) => { + if (!isString(id) || !ID.test(id)) errors.push(`${where}.id: expected a kebab-case id`) + else if (ids.has(id)) errors.push(`${where}.id: "${id}" appears twice`) + else ids.add(id) + } + if (!Array.isArray(m.capabilities)) errors.push('capabilities: expected an array') + else { + m.capabilities.forEach((c, i) => { + const at = `capabilities[${i}]` + seen(at, c?.id) + if (!isString(c?.name)) errors.push(`${at}.name: expected a name`) + if (!isString(c?.summary)) errors.push(`${at}.summary: expected a sentence`) + checkVersion(errors, `${at}.since`, c?.since) + if (c?.except !== undefined) { + if (Array.isArray(c.except)) c.except.forEach((r, j) => checkVersion(errors, `${at}.except[${j}]`, r)) + else errors.push(`${at}.except: expected an array of releases`) + } + if (!['refuse', 'fallback', 'repair'].includes(c?.handling as string)) errors.push(`${at}.handling: expected refuse, fallback or repair`) + if (c?.handling === 'refuse' && !isString(c?.error)) errors.push(`${at}.error: a refusal names its error type`) + checkNames(errors, `${at}.apis`, c?.apis) + checkCommands(errors, `${at}.commands`, c?.commands) + }) + } + if (!Array.isArray(m.workarounds)) errors.push('workarounds: expected an array') + else { + m.workarounds.forEach((w, i) => { + const at = `workarounds[${i}]` + seen(at, w?.id) + if (!isString(w?.name)) errors.push(`${at}.name: expected a name`) + if (!isString(w?.summary)) errors.push(`${at}.summary: expected a sentence`) + if (!Array.isArray(w?.releases) || w.releases.length === 0) errors.push(`${at}.releases: expected at least one release`) + else w.releases.forEach((r, j) => checkVersion(errors, `${at}.releases[${j}]`, r)) + if (!['refuse', 'repair'].includes(w?.handling as string)) errors.push(`${at}.handling: expected refuse or repair`) + checkNames(errors, `${at}.apis`, w?.apis) + checkCommands(errors, `${at}.commands`, w?.commands) + }) + } + return errors.length ? { errors } : { manifest: m as CapabilityManifest, errors } +} diff --git a/packages/api-model/src/index.ts b/packages/api-model/src/index.ts index 1fe013729..71b01102f 100644 --- a/packages/api-model/src/index.ts +++ b/packages/api-model/src/index.ts @@ -30,3 +30,17 @@ export { parentInventory } from './parent-inventory.ts' export { navSidecarFor, type NavConfig } from './nav-sidecar.ts' export { parsePythonDoc } from './doc/python.ts' +export { + CAPABILITY_SCHEMA, + capabilityState, + compareTmuxVersions, + tmuxVersionKey, + validateManifest, + workaroundState, + type CapabilityCommand, + type CapabilityEntry, + type CapabilityManifest, + type CellState, + type Handling, + type Workaround, +} from './capabilities.ts' diff --git a/packages/api-model/test/capabilities.test.ts b/packages/api-model/test/capabilities.test.ts new file mode 100644 index 000000000..b346e6406 --- /dev/null +++ b/packages/api-model/test/capabilities.test.ts @@ -0,0 +1,116 @@ +import { describe, expect, it } from 'vitest' +import { + CAPABILITY_SCHEMA, + capabilityState, + compareTmuxVersions, + validateManifest, + workaroundState, + type CapabilityEntry, + type Workaround, +} from '../src/capabilities.ts' + +const control: CapabilityEntry = { + id: 'control-mode', + name: 'Control mode', + summary: 'Attach a library-managed control client.', + since: '3.7', + handling: 'fallback', + apis: ['libtmux.Server.observe'], + commands: [{ command: 'attach-session', flags: ['-C'] }], +} + +const runShell: CapabilityEntry = { + id: 'run-shell-capture', + name: 'Captured run-shell output', + summary: 'Read the standard output of run-shell.', + since: '3.3a', + except: ['3.4'], + handling: 'refuse', + error: 'libtmux.CapabilityUnavailable', + apis: ['libtmux.Server.run_shell'], + commands: [{ command: 'run-shell' }], +} + +const breakPane: Workaround = { + id: 'break-pane-exact-3-7', + name: 'break-pane on 3.7', + summary: 'Exact 3.7 ignores the name given to break-pane; a rename follows.', + releases: ['3.7'], + handling: 'repair', + apis: ['libtmux.Pane.break_out'], + commands: [{ command: 'break-pane', flags: ['-n'] }], +} + +const manifest = { + schema: CAPABILITY_SCHEMA, + port: 'py', + floor: { minimum: '3.2a' }, + capabilities: [control, runShell], + workarounds: [breakPane], +} + +describe('tmux version order', () => { + it('ranks development builds and candidates below the release they name', () => { + const ordered = ['next-3.7', '3.7-rc', '3.7-rc2', '3.7-rc3', '3.7-rc10', '3.7', '3.7a', '3.8', 'next-3.9', '3.10'] + expect([...ordered].reverse().sort(compareTmuxVersions)).toEqual(ordered) + }) + + it('refuses forms tmux never prints', () => { + for (const v of ['master', '3.3a-master', 'next-3.3a', '3.3a-rc1', '03.3a', 'openbsd-7.6']) { + expect(() => compareTmuxVersions(v, '3.3a'), v).toThrow(TypeError) + } + }) + + it('refuses candidate numbers tmux has not used', () => { + // tmux names its first candidate X.Y-rc and the next X.Y-rc2, so rc0, rc1 and padded numbers are not its. + for (const v of ['3.8-rc0', '3.8-rc1', '3.8-rc01', '3.8-rc02', '3.8-rc-2']) { + expect(() => compareTmuxVersions(v, '3.8-rc'), v).toThrow(TypeError) + expect(validateManifest({ ...manifest, floor: { minimum: v } }).errors.join('\n'), v).toContain('floor.minimum') + } + expect(compareTmuxVersions('3.8-rc', '3.8-rc2')).toBeLessThan(0) + }) +}) + +describe('cells', () => { + it('follows since, except and handling', () => { + expect(capabilityState(control, '3.6')).toBe('fallback') + expect(capabilityState(control, '3.7')).toBe('supported') + expect(capabilityState(control, '3.7-rc')).toBe('fallback') + expect(capabilityState(runShell, '3.3a')).toBe('supported') + expect(capabilityState(runShell, '3.4')).toBe('refused') + expect(capabilityState(runShell, '3.5')).toBe('supported') + }) + + it('marks only the releases a workaround names', () => { + expect(workaroundState(breakPane, '3.7')).toBe('workaround') + expect(workaroundState(breakPane, '3.7a')).toBe('supported') + }) +}) + +describe('validateManifest', () => { + it('accepts a complete manifest', () => { + const { manifest: m, errors } = validateManifest(manifest) + expect(errors).toEqual([]) + expect(m?.capabilities.map((c) => c.id)).toEqual(['control-mode', 'run-shell-capture']) + }) + + const broken: [string, unknown, string][] = [ + ['wrong schema', { ...manifest, schema: 'libtmux-capabilities/0' }, 'schema'], + ['unprintable floor', { ...manifest, floor: { minimum: 'master' } }, 'floor.minimum'], + ['duplicate id', { ...manifest, workarounds: [{ ...breakPane, id: 'control-mode' }] }, 'appears twice'], + ['refusal without an error type', { ...manifest, capabilities: [{ ...runShell, error: undefined }] }, 'names its error type'], + ['non-kebab id', { ...manifest, capabilities: [{ ...control, id: 'ControlMode' }] }, 'kebab-case'], + ['bad since', { ...manifest, capabilities: [{ ...control, since: '3.7-dev' }] }, 'since'], + ['bad flag', { ...manifest, capabilities: [{ ...control, commands: [{ command: 'attach-session', flags: ['C'] }] }] }, 'flags'], + ['empty workaround', { ...manifest, workarounds: [{ ...breakPane, releases: [] }] }, 'releases'], + ['except as a string', { ...manifest, capabilities: [{ ...runShell, except: '3.4' }] }, 'except: expected an array'], + ['except as a number', { ...manifest, capabilities: [{ ...runShell, except: 5 }] }, 'except: expected an array'], + ['except as an object', { ...manifest, capabilities: [{ ...runShell, except: { 0: '3.4' } }] }, 'except: expected an array'], + ['an unprintable except release', { ...manifest, capabilities: [{ ...runShell, except: ['3.4', 'master'] }] }, 'except[1]'], + ] + it.each(broken)('rejects a manifest with %s', (_label, value, message) => { + const { manifest: m, errors } = validateManifest(value) + expect(m).toBeUndefined() + expect(errors.join('\n')).toContain(message) + }) +}) diff --git a/scripts/gen-capabilities.mjs b/scripts/gen-capabilities.mjs new file mode 100644 index 000000000..6b2c173a2 --- /dev/null +++ b/scripts/gen-capabilities.mjs @@ -0,0 +1,283 @@ +#!/usr/bin/env node +/** + * Read each port's capability manifest and write site/src/data/capabilities.json. + * + * A port's `capabilities.json` is emitted by that port from the typed + * `support.capabilities` registry its library refuses with, and the port's own + * drift test keeps the two equal. This script does not interpret prose or + * keep a table: it validates each manifest, resolves every API name in it + * through the port's generated API model, and records the tmux releases the + * matrix columns come from. A name that does not resolve fails the run, so a + * renamed method cannot leave a capability pointing at nothing. + * + * A port that raises another port's types, as PowerShell raises .NET's + * exceptions, resolves those names through the models in its + * `apiDependencies`, by the inventory reference navigation links them with. + * + * Releases come from tmux's own refs: final tags, the version a release + * branch names in `configure.ac` (3.7d shipped from a branch before it was + * tagged), and the `next-X.Y` that master names. Only releases at or above the + * lowest floor any manifest declares are kept. + * + * `--check` compares the committed file with what the manifests say. Hosted CI + * clones this repository alone, so a port whose manifest cannot be read is + * named, not skipped in silence: its committed entry is still validated and + * every API name in it resolved through the committed API model, so a renamed + * method fails there too. Releases are compared with tmux's refs when a clone + * is present, and checked by form and order when it is not. Writing refuses + * to drop a committed port it cannot read. `--port` rewrites that port's entry + * and keeps the others as committed. + * + * A port's manifest is read from `capabilities.json` at the root of its + * checkout. `LIBTMUX_DOCS_CHECKOUT_` selects another checkout, and + * `--manifest =` selects the file itself. + * + * Usage: node scripts/gen-capabilities.mjs [--port ] [--manifest =] + * [--tmux ] [--out ] [--check] + */ +import { execFileSync } from 'node:child_process' +import { existsSync, readFileSync, writeFileSync } from 'node:fs' +import { homedir } from 'node:os' +import { dirname, join, resolve } from 'node:path' +import { fileURLToPath } from 'node:url' +import { PORTS, PORT_BY_SLUG } from '../site/src/lib/ports.ts' +import { SymbolIndex } from '../packages/api-model/src/link.ts' +import { parentInventory } from '../packages/api-model/src/parent-inventory.ts' +import { CAPABILITY_SCHEMA, compareTmuxVersions, tmuxVersionKey, validateManifest } from '../packages/api-model/src/capabilities.ts' + +const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..') +const args = process.argv.slice(2) +const value = (flag, fallback) => (args.includes(flag) ? args[args.indexOf(flag) + 1] : fallback) +const values = (flag) => args.flatMap((a, i) => (a === flag ? [args[i + 1]] : [])) +const expand = (p) => (p.startsWith('~/') ? join(homedir(), p.slice(2)) : p) +const checking = args.includes('--check') +const only = value('--port') +const out = resolve(value('--out', join(repoRoot, 'site/src/data/capabilities.json'))) +const tmuxCheckout = expand(value('--tmux', '~/study/c/tmux')) +const modelDir = resolve(value('--models', join(repoRoot, 'site/src/data/api'))) + +/** `--manifest py=path/to/capabilities.json` overrides where a port's manifest is read. */ +const overrides = Object.fromEntries(values('--manifest').map((pair) => pair.split('='))) + +/** The manifest sits at the root of the port's checkout, emitted and drift-checked there. */ +function manifestPath(port) { + const checkout = process.env[`LIBTMUX_DOCS_CHECKOUT_${port.slug.toUpperCase()}`] || port.checkout + return overrides[port.slug] ?? join(expand(checkout), 'capabilities.json') +} + +function git(...a) { + return execFileSync('git', ['-C', tmuxCheckout, ...a], { encoding: 'utf8' }).trim() +} + +/** Every tmux release a reader can run, from tmux's own refs. */ +function tmuxReleases() { + const versions = new Set() + const add = (v) => { + try { + tmuxVersionKey(v) + versions.add(v) + } catch { + // A ref that names something tmux never prints (a topic branch) is not a release. + } + } + for (const tag of git('tag', '-l').split('\n')) if (/^\d+\.\d+[a-z]?$/.test(tag)) add(tag) + const refs = git('for-each-ref', '--format=%(refname:short)', 'refs/remotes').split('\n') + const named = (ref) => /AC_INIT\(\[tmux\], ([^)]+)\)/.exec(git('show', `${ref}:configure.ac`))?.[1] + for (const ref of refs.filter((r) => /\/release_[\d.]+[a-z]?$/.test(r))) { + const v = named(ref) + if (v && /^\d+\.\d+[a-z]?$/.test(v)) add(v) + } + const master = refs.find((r) => r === 'upstream/master') ?? refs.find((r) => r === 'origin/master') + const next = master && named(master) + if (next?.startsWith('next-')) add(next) + return [...versions].sort(compareTmuxVersions) +} + +const modelFile = (slug) => join(modelDir, `${slug}.json`) +const readModel = (slug) => JSON.parse(readFileSync(modelFile(slug), 'utf8')) + +/** + * Resolve a manifest's API name to the public id the reference pages use. + * `missing` names an API model the port needs and this checkout lacks. + */ +function resolver(slug) { + const dependencies = PORT_BY_SLUG[slug]?.apiDependencies ?? [] + const missing = [slug, ...dependencies].map(modelFile).find((file) => !existsSync(file)) + if (missing) return { missing } + const index = new SymbolIndex(readModel(slug).symbols, () => '', slug) + const inherited = dependencies.map((dependency) => + new Map(parentInventory(readModel(dependency), (symbol) => symbol.publicId ?? symbol.id).map((entry) => [entry.name, entry.uri]))) + const resolve = (name) => { + const target = index.resolve(name) + if (target?.symbol) return target.symbol.publicId ?? target.symbol.id + return inherited.map((names) => names.get(name)).find(Boolean) + } + const scope = dependencies.length ? `the API model or the model of ${dependencies.join(', ')}` : 'the API model' + return { resolve, scope } +} + +/** The names a committed entry holds, as the places they appear. */ +function committedNames(kind, list) { + return list.flatMap((e) => [ + ...e.apis.map((name) => [`${kind} ${e.id}`, name]), + ...(e.error ? [[`${kind} ${e.id} error`, e.error]] : []), + ]) +} + +/** + * Check a committed entry without its manifest: it still has to be a valid + * manifest, and every name in it still has to resolve in the committed model. + */ +function verifyCommitted(slug, entry) { + const held = entry && typeof entry === 'object' ? entry : {} + const { errors: invalid } = validateManifest({ + schema: CAPABILITY_SCHEMA, port: slug, floor: held.floor, capabilities: held.capabilities, workarounds: held.workarounds, + }) + if (invalid.length) return invalid.map((e) => `${slug}: committed entry: ${e}`) + const { resolve, scope, missing } = resolver(slug) + if (missing) return [`${slug}: no API model at ${missing}; run gen-api-model first`] + return [...committedNames('capability', held.capabilities), ...committedNames('workaround', held.workarounds)] + .filter(([, name]) => !resolve(name)) + .map(([where, name]) => `${slug}: committed ${where} names "${name}", which is not in ${scope}`) +} + +const errors = [] +const ports = {} +/** Ports considered, and the ones whose manifest this machine cannot read. */ +const considered = [] +const unread = [] +for (const port of PORTS) { + if (only && port.slug !== only) continue + // A wrapper library shares its parent's checkout, where the manifest names the parent. + if (port.parentLibrary) continue + considered.push(port.slug) + const path = manifestPath(port) + if (!existsSync(path)) { + unread.push(port.slug) + continue + } + const { manifest, errors: invalid } = validateManifest(JSON.parse(readFileSync(path, 'utf8'))) + if (!manifest) { + errors.push(...invalid.map((e) => `${port.slug}: ${e}`)) + continue + } + if (manifest.port !== port.slug) errors.push(`${port.slug}: manifest names port "${manifest.port}"`) + const { resolve, scope, missing } = resolver(port.slug) + if (missing) { + errors.push(`${port.slug}: no API model at ${missing}; run gen-api-model first`) + continue + } + const link = (where, name) => { + const id = resolve(name) + if (!id) errors.push(`${port.slug}: ${where} names "${name}", which is not in ${scope}`) + return id ?? name + } + const entries = (list, kind) => list.map((e) => ({ + ...e, + apis: e.apis.map((name) => link(`${kind} ${e.id}`, name)), + ...(e.error ? { error: link(`${kind} ${e.id} error`, e.error) } : {}), + })) + ports[port.slug] = { + revision: (() => { + try { + return execFileSync('git', ['-C', dirname(path), 'rev-parse', 'HEAD'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() + } catch { + return undefined + } + })(), + floor: manifest.floor, + capabilities: entries(manifest.capabilities, 'capability'), + workarounds: entries(manifest.workarounds, 'workaround'), + } +} + +if (errors.length) { + console.error(errors.join('\n')) + process.exit(1) +} + +let committed +if (existsSync(out)) { + try { + committed = JSON.parse(readFileSync(out, 'utf8')) + } catch (error) { + if (checking) { + console.error(`${out} is not valid JSON: ${error.message}`) + process.exit(1) + } + } +} +/** Ports that read a manifest of their own; a wrapper library takes its parent's. */ +const owners = PORTS.filter((p) => !p.parentLibrary).map((p) => p.slug) +const parentOf = new Map(PORTS.filter((p) => p.parentLibrary).map((p) => [p.slug, p.parentLibrary.slug])) +/** Unread ports the committed file holds an entry for. */ +const kept = unread.filter((slug) => committed?.ports?.[slug]) +/** What the file holds for a port once this run is done: what the run read, else the entry it already has. */ +const entryOf = (slug) => ports[slug] ?? committed?.ports?.[slug] +const printable = (v) => { + try { + tmuxVersionKey(v) + return true + } catch { + return false + } +} +const lowestOf = (floors) => floors.filter(printable).sort(compareTmuxVersions)[0] +const haveTmux = existsSync(tmuxCheckout) + +if (checking) { + const problems = [] + if (!committed) problems.push(`${out} does not exist; run node scripts/gen-capabilities.mjs`) + else { + const registered = new Set(PORTS.map((p) => p.slug)) + for (const slug of Object.keys(committed.ports ?? {})) { + if (!registered.has(slug)) problems.push(`${slug}: committed, but not a registered port`) + else if (parentOf.has(slug)) problems.push(`${slug}: committed, but ${slug} is a wrapper library; its capabilities come from ${parentOf.get(slug)}'s manifest`) + } + for (const slug of Object.keys(ports)) { + if (!committed.ports?.[slug]) problems.push(`${slug}: missing from the file`) + else if (JSON.stringify(ports[slug]) !== JSON.stringify(committed.ports[slug])) problems.push(`${slug}: differs from its manifest`) + } + for (const slug of kept) problems.push(...verifyCommitted(slug, committed.ports[slug])) + const lowest = lowestOf(owners.map((slug) => entryOf(slug)?.floor?.minimum)) + const held = committed.releases ?? [] + if (!Array.isArray(held)) problems.push('releases: expected an array') + else if (haveTmux) { + const expected = lowest ? tmuxReleases().filter((v) => compareTmuxVersions(v, lowest) >= 0) : [] + if (JSON.stringify(expected) !== JSON.stringify(held)) problems.push(`releases differ from the tmux refs: the file has ${held.join(', ') || 'none'}, the refs give ${expected.join(', ') || 'none'}`) + } else { + for (const v of held) if (!printable(v)) problems.push(`releases: ${JSON.stringify(v)} is not a version tmux prints`) + const valid = held.filter(printable) + if (valid.some((v, i) => i > 0 && compareTmuxVersions(valid[i - 1], v) >= 0)) problems.push('releases are not in ascending order') + for (const v of valid) if (lowest && compareTmuxVersions(v, lowest) < 0) problems.push(`release ${v} is below the lowest floor ${lowest}`) + if (!lowest && held.length) problems.push('releases: the file holds releases but no port with a floor') + } + } + if (problems.length) { + console.error(`${out} is out of date or invalid. Fix the entries below, or run node scripts/gen-capabilities.mjs with every checkout present.`) + console.error(problems.map((p) => ` ${p}`).join('\n')) + process.exit(1) + } + const notes = [`gen-capabilities: ${out} is current for ${Object.keys(ports).length} of ${considered.length} ports`] + if (kept.length) notes.push(` committed entry verified against the API model, manifest not compared: ${kept.join(', ')}`) + const bare = unread.filter((slug) => !kept.includes(slug)) + if (bare.length) notes.push(` no manifest here and none committed: ${bare.join(', ')}`) + if (!haveTmux) notes.push(` tmux releases not compared: no tmux checkout at ${tmuxCheckout}`) + console.log(notes.join('\n')) +} else { + if (kept.length) { + console.error(`gen-capabilities: no manifest for ${kept.join(', ')}; refusing to write a partial file that drops ${kept.length === 1 ? 'its' : 'their'} committed ${kept.length === 1 ? 'entry' : 'entries'}`) + process.exit(1) + } + // A run that selects one port rewrites its entry and leaves the others as committed. + const written = Object.fromEntries(owners.filter(entryOf).map((slug) => [slug, entryOf(slug)])) + const lowest = lowestOf(Object.values(written).map((p) => p.floor?.minimum)) + if (lowest && !haveTmux) { + console.error(`gen-capabilities: no tmux checkout at ${tmuxCheckout}; pass --tmux `) + process.exit(1) + } + const releases = lowest ? tmuxReleases().filter((v) => compareTmuxVersions(v, lowest) >= 0) : [] + writeFileSync(out, `${JSON.stringify({ generated: 'scripts/gen-capabilities.mjs', releases, ports: written }, null, 2)}\n`) + const dropped = Object.keys(committed?.ports ?? {}).filter((slug) => !(slug in written)) + console.log(`wrote ${out}: ${Object.keys(written).length} ports, ${releases.length} releases${dropped.length ? `; dropped entries no port publishes: ${dropped.join(', ')}` : ''}`) +} diff --git a/scripts/test-all.sh b/scripts/test-all.sh index 51fce25dc..694ea957c 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -174,6 +174,15 @@ node scripts/gen-shell-ports.negative.mjs step 'mcp tool matrix' node scripts/gen-mcp-tools.mjs --check +# /reference/capabilities/ and the per-command tables are generated from each +# port's capabilities.json, which the port emits from its typed registry. +# Every API name in a manifest must resolve in that port's model. CI has no +# port checkouts, so a port whose manifest is absent is named as not compared +# and its committed entry is validated and resolved against the committed +# models instead; a name a model lost fails there. +step 'capability manifests' +node scripts/gen-capabilities.mjs --check + # Each port's own MCP server, built and run to compare its live tool, # resource and prompt schemas against the committed snapshot in # site/src/data/mcp-protocol/. Skips when the sibling checkouts are absent, diff --git a/scripts/tmux-usage/claims.json b/scripts/tmux-usage/claims.json index c18afa88f..267322e82 100644 --- a/scripts/tmux-usage/claims.json +++ b/scripts/tmux-usage/claims.json @@ -10021,7 +10021,7 @@ ] }, { - "at": "Sources/LibTmux/Navigation.swift:144", + "at": "Sources/LibTmux/Navigation.swift:146", "has": [ "windowAppearance(" ], @@ -10037,13 +10037,13 @@ "when": "no name is given", "evidence": [ { - "at": "Sources/LibTmux/Navigation.swift:136", + "at": "Sources/LibTmux/Navigation.swift:138", "has": [ "\"if-shell\"" ] }, { - "at": "Sources/LibTmux/Navigation.swift:144", + "at": "Sources/LibTmux/Navigation.swift:146", "has": [ "windowAppearance(" ], @@ -12709,13 +12709,13 @@ "scope": null, "evidence": [ { - "at": "Sources/LibTmux/PaneInteraction.swift:295", + "at": "Sources/LibTmux/PaneInteraction.swift:332", "has": [ "runIsolated(" ] }, { - "at": "Sources/LibTmux/PaneInteraction.swift:296", + "at": "Sources/LibTmux/PaneInteraction.swift:333", "has": [ "\"capture-pane\"" ] @@ -12760,7 +12760,7 @@ ] }, { - "at": "Sources/LibTmux/PaneInteraction.swift:322", + "at": "Sources/LibTmux/PaneInteraction.swift:359", "has": [ "formatGlobal(" ] @@ -12806,7 +12806,7 @@ ] }, { - "at": "Sources/LibTmux/PaneInteraction.swift:322", + "at": "Sources/LibTmux/PaneInteraction.swift:359", "has": [ "formatGlobal(" ] @@ -12828,19 +12828,19 @@ "scope": "server", "evidence": [ { - "at": "Sources/LibTmux/Server.swift:273", + "at": "Sources/LibTmux/Server.swift:450", "has": [ "list(" ] }, { - "at": "Sources/LibTmux/Server.swift:274", + "at": "Sources/LibTmux/Server.swift:451", "has": [ "\"list-windows\", [\"-a\"" ] }, { - "at": "Sources/LibTmux/Server.swift:269", + "at": "Sources/LibTmux/Server.swift:446", "has": [ "windowListingRows()" ] @@ -12869,19 +12869,19 @@ "when": "no index is given", "evidence": [ { - "at": "Sources/LibTmux/Server.swift:273", + "at": "Sources/LibTmux/Server.swift:450", "has": [ "list(" ] }, { - "at": "Sources/LibTmux/Server.swift:274", + "at": "Sources/LibTmux/Server.swift:451", "has": [ "\"list-windows\", [\"-a\"" ] }, { - "at": "Sources/LibTmux/Server.swift:269", + "at": "Sources/LibTmux/Server.swift:446", "has": [ "windowListingRows()" ] diff --git a/scripts/tmux-usage/dispatchers.json b/scripts/tmux-usage/dispatchers.json index a78c54ded..ce259bbd1 100644 --- a/scripts/tmux-usage/dispatchers.json +++ b/scripts/tmux-usage/dispatchers.json @@ -8637,14 +8637,14 @@ "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:132", + "at": "Sources/LibTmux/Server.swift:284", "has": [ "run(rawArguments: command.argumentVector)" ], "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -8652,7 +8652,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -8681,14 +8688,14 @@ "calls": "runGuarded" }, { - "at": "Sources/LibTmux/GuardedRequest.swift:34", + "at": "Sources/LibTmux/GuardedRequest.swift:37", "has": [ "run(rawArguments: request.commands.argumentVector)" ], "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -8696,7 +8703,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -8732,7 +8746,7 @@ "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -8740,7 +8754,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -8756,20 +8777,20 @@ ] }, { - "at": "Sources/LibTmux/Server.swift:131", + "at": "Sources/LibTmux/Server.swift:283", "has": [ "run" ], "reaches": [ { - "at": "Sources/LibTmux/Server.swift:132", + "at": "Sources/LibTmux/Server.swift:284", "has": [ "run(rawArguments: command.argumentVector)" ], "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -8777,7 +8798,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -8793,13 +8821,13 @@ ] }, { - "at": "Sources/LibTmux/Server.swift:135", + "at": "Sources/LibTmux/Server.swift:287", "has": [ "run" ], "reaches": [ { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -8807,7 +8835,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -8843,14 +8878,14 @@ "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:132", + "at": "Sources/LibTmux/Server.swift:284", "has": [ "run(rawArguments: command.argumentVector)" ], "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -8858,7 +8893,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -8881,20 +8923,20 @@ "why": "Sends the TmuxCommand it is given to the server.", "evidence": [ { - "at": "Sources/LibTmux/Server.swift:367", + "at": "Sources/LibTmux/Server.swift:557", "has": [ "list" ], "reaches": [ { - "at": "Sources/LibTmux/Server.swift:372", + "at": "Sources/LibTmux/Server.swift:562", "has": [ "run(rawArguments: command.argumentVector)" ], "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -8902,7 +8944,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -8925,13 +8974,13 @@ "why": "Sends the TmuxCommand it is given to the server.", "evidence": [ { - "at": "Sources/LibTmux/Server.swift:167", + "at": "Sources/LibTmux/Server.swift:344", "has": [ "runInOwnProcess" ], "reaches": [ { - "at": "Sources/LibTmux/Server.swift:168", + "at": "Sources/LibTmux/Server.swift:345", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -8939,7 +8988,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -8968,14 +9024,14 @@ ], "reaches": [ { - "at": "Sources/LibTmux/GuardedRequest.swift:34", + "at": "Sources/LibTmux/GuardedRequest.swift:37", "has": [ "run(rawArguments: request.commands.argumentVector)" ], "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -8983,7 +9039,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -9006,27 +9069,27 @@ "why": "Sends the TmuxCommand it is given to the server.", "evidence": [ { - "at": "Sources/LibTmux/ControlSession.swift:168", + "at": "Sources/LibTmux/ControlSession.swift:181", "has": [ "send" ], "reaches": [ { - "at": "Sources/LibTmux/ControlSession.swift:170", + "at": "Sources/LibTmux/ControlSession.swift:186", "has": [ "send(" ], "calls": "send" }, { - "at": "Sources/LibTmux/ControlSession.swift:181", + "at": "Sources/LibTmux/ControlSession.swift:197", "has": [ "enqueue(" ], "calls": "enqueue" }, { - "at": "Sources/LibTmux/ControlSession.swift:234", + "at": "Sources/LibTmux/ControlSession.swift:250", "has": [ "write(" ], @@ -9056,13 +9119,13 @@ "why": "Sends the TmuxCommand it is given to the server.", "evidence": [ { - "at": "Sources/LibTmux/Server.swift:226", + "at": "Sources/LibTmux/Server.swift:403", "has": [ "runTerminatingIsolated" ], "reaches": [ { - "at": "Sources/LibTmux/Server.swift:237", + "at": "Sources/LibTmux/Server.swift:414", "has": [ "runtime.run(" ], @@ -9070,7 +9133,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -9093,13 +9163,13 @@ "why": "Sends the TmuxCommand it is given to the server.", "evidence": [ { - "at": "Sources/LibTmux/Server.swift:171", + "at": "Sources/LibTmux/Server.swift:348", "has": [ "runIsolated" ], "reaches": [ { - "at": "Sources/LibTmux/Server.swift:175", + "at": "Sources/LibTmux/Server.swift:352", "has": [ "runtime.run(" ], @@ -9107,7 +9177,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -9136,21 +9213,21 @@ ], "reaches": [ { - "at": "Sources/LibTmux/Creation.swift:346", + "at": "Sources/LibTmux/Creation.swift:347", "has": [ "runGuarded(" ], "calls": "runGuarded" }, { - "at": "Sources/LibTmux/GuardedRequest.swift:34", + "at": "Sources/LibTmux/GuardedRequest.swift:37", "has": [ "run(rawArguments: request.commands.argumentVector)" ], "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -9158,7 +9235,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -9194,14 +9278,14 @@ "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:132", + "at": "Sources/LibTmux/Server.swift:284", "has": [ "run(rawArguments: command.argumentVector)" ], "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -9209,7 +9293,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], @@ -9245,14 +9336,14 @@ "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:132", + "at": "Sources/LibTmux/Server.swift:284", "has": [ "run(rawArguments: command.argumentVector)" ], "calls": "run" }, { - "at": "Sources/LibTmux/Server.swift:137", + "at": "Sources/LibTmux/Server.swift:289", "has": [ "runtime.run(rawArguments: rawArguments)" ], @@ -9260,7 +9351,14 @@ "on": "ServerRuntime" }, { - "at": "Sources/LibTmux/Server.swift:462", + "at": "Sources/LibTmux/Server.swift:692", + "has": [ + "send(" + ], + "calls": "send" + }, + { + "at": "Sources/LibTmux/Server.swift:839", "has": [ "transport.run(" ], diff --git a/scripts/tmux-usage/guards.json b/scripts/tmux-usage/guards.json index c8346e308..2117506bc 100644 --- a/scripts/tmux-usage/guards.json +++ b/scripts/tmux-usage/guards.json @@ -277,19 +277,19 @@ "purpose": "runs the command together with a marker that shows it ran, inside the guards that refuse a stale target", "evidence": [ { - "at": "Sources/LibTmux/GuardedRequest.swift:174", + "at": "Sources/LibTmux/GuardedRequest.swift:177", "has": [ "private static func guardedAction(" ] }, { - "at": "Sources/LibTmux/GuardedRequest.swift:179", + "at": "Sources/LibTmux/GuardedRequest.swift:182", "has": [ "\"if-shell\"" ] }, { - "at": "Sources/LibTmux/GuardedRequest.swift:25", + "at": "Sources/LibTmux/GuardedRequest.swift:28", "has": [ "GuardedRequest(" ] @@ -302,19 +302,19 @@ "purpose": "refuses the command when the server restarted or the target no longer matches what the value was read from", "evidence": [ { - "at": "Sources/LibTmux/GuardedRequest.swift:187", + "at": "Sources/LibTmux/GuardedRequest.swift:190", "has": [ "private static func commandGuard(" ] }, { - "at": "Sources/LibTmux/GuardedRequest.swift:200", + "at": "Sources/LibTmux/GuardedRequest.swift:203", "has": [ "TmuxCommand(\"if-shell\", arguments)" ] }, { - "at": "Sources/LibTmux/Server.swift:214", + "at": "Sources/LibTmux/Server.swift:391", "has": [ "GuardedRequest(" ] diff --git a/scripts/tmux-usage/not-senders.json b/scripts/tmux-usage/not-senders.json index eea8371e7..e1e3d080d 100644 --- a/scripts/tmux-usage/not-senders.json +++ b/scripts/tmux-usage/not-senders.json @@ -3721,7 +3721,7 @@ "why": "clearHistory sends clear-history; clear-prompt-history is a different command.", "evidence": [ { - "at": "Sources/LibTmux/Navigation.swift:213", + "at": "Sources/LibTmux/Navigation.swift:226", "has": [ "\"clear-history\"" ] @@ -3887,7 +3887,7 @@ "why": "windowLinks lists the windows with list-windows -a and reads their links; it does not send link-window.", "evidence": [ { - "at": "Sources/LibTmux/Server.swift:274", + "at": "Sources/LibTmux/Server.swift:451", "has": [ "\"list-windows\"" ] diff --git a/site/src/components/api/ApiCapabilities.astro b/site/src/components/api/ApiCapabilities.astro new file mode 100644 index 000000000..52170ba57 --- /dev/null +++ b/site/src/components/api/ApiCapabilities.astro @@ -0,0 +1,136 @@ +--- +/** + * tmux capabilities, generated from each port's own registry. + * + * In a port build: that port's capabilities against every tmux release from + * its floor, with the API each one gates. In the root build: one map of every + * capability against every port that publishes a manifest. No row or cell is + * written here; see site/src/lib/capabilities.ts. + */ +import CapabilityMatrix from '../capabilities/CapabilityMatrix.astro' +import DocsLayout from '../../layouts/DocsLayout.astro' +import { DEFAULT_LOCALE, localeRoot } from '../../i18n/locales' +import { CONTRIBUTE_BRANCH, CONTRIBUTE_REPO } from '../../i18n/contribute' +import { PORT_BY_SLUG, portPageUrl, referenceUrl } from '../../lib/ports' +import { buildTarget } from '../../lib/versions' +import { tmuxCommandSources } from '../../lib/tmux-reference' +import { + capabilityFloor, + capabilityPorts, + capabilityRevision, + mapRows, + portColumns, + portRows, + releaseGroups, + type Row, +} from '../../lib/capabilities' + +interface Props { port?: string; version?: string } +const { port, version = buildTarget(process.env).version } = Astro.props as Props +const name = port ? PORT_BY_SLUG[port].name : 'libtmux' +const library = port ? PORT_BY_SLUG[port].projectName : 'libtmux' +const referenceBase = port ? referenceUrl(PORT_BY_SLUG[port], version, 'core') : `${localeRoot(DEFAULT_LOCALE)}reference/` +const pagePath = 'reference/capabilities' +const pageUrl = `${referenceBase}capabilities/` +const title = port ? `${library} tmux capabilities` : 'tmux capabilities' +const description = port + ? `What ${library} can do on each tmux release, generated from its capability registry.` + : 'What each libtmux port can do on each tmux release, generated from each port\'s capability registry.' + +const floor = port ? capabilityFloor(port) : undefined +const revision = port ? capabilityRevision(port) : undefined +const { capabilities, workarounds } = port ? portRows(port) : { capabilities: mapRows(), workarounds: [] as Row[] } +const published = capabilityPorts() +const commandHref = (command: string) => tmuxCommandSources('latest', command)[0]?.href + +const sections = [...capabilities, ...workarounds] +const headings = [ + ...(capabilities.length ? [{ depth: 2, slug: 'capabilities', text: 'Capabilities' }] : []), + ...(workarounds.length ? [{ depth: 2, slug: 'workarounds', text: 'Release workarounds' }] : []), + ...sections.map((r) => ({ depth: 3, slug: r.id, text: r.label })), +] +--- + + + {port && floor ? ( +

+ {library} (libtmux for {name}) requires tmux {floor} or newer. Each capability below needs a newer + tmux release, or avoids one release. Before it sends a command, {library} checks the version of + the running tmux server. The tables and every link on this page are generated from the library's + capability registry{revision && <> at {revision.slice(0, 12)}}. +

+ ) : !port && published.length > 0 ? ( +

+ Every libtmux port supports tmux from its floor up. Each capability below needs a newer release on + some ports; a cell gives the release a port needs. Rows and cells are generated from each port's + capability registry, so a port appears here once it publishes one. +

+ ) : null} + + {published.length === 0 ? ( +

No port publishes a capability registry on this build yet.

+ ) : port && !floor ? ( +

{library} does not publish a capability registry on this build yet.

+ ) : ( + <> +

Capabilities

+ + {workarounds.length > 0 && ( + <> +

Release workarounds

+

A tmux release that gets one command wrong. {library} repairs the result, or refuses the call, on that release only.

+ + + )} + {sections.map((row) => ( +
+

{row.label}

+

{row.summary}

+
+
tmux
+
{row.requirement}
+ {row.error && (<>
Refusal
{row.error.href ? {row.error.label} : {row.error.label}}
)} + {row.apis.length > 0 && ( + <> +
API
+
{row.apis.map((api) => api.href ? {api.label} : {api.label})}
+ + )} + {row.commands.length > 0 && ( + <> +
Commands
+
{row.commands.map((c) => { + const href = commandHref(c.command) + const text = [c.command, ...(c.flags ?? [])].join(' ') + return href ? {text} : {text} + })}
+ + )} +
+
+ ))} + + )} +
diff --git a/site/src/components/api/ApiReference.astro b/site/src/components/api/ApiReference.astro index 2f0f53f96..31915400b 100644 --- a/site/src/components/api/ApiReference.astro +++ b/site/src/components/api/ApiReference.astro @@ -21,6 +21,9 @@ import { pagePortsFor } from '../../lib/page-ports-for' import { pageBreadcrumbs } from '../../lib/sidebar' import BaseLayout from '../../layouts/BaseLayout.astro' import { withRoot } from '../../lib/site-root' +import CommandSupport from '../capabilities/CommandSupport.astro' +import { commandRows } from '../../lib/capabilities' +import { tmuxSourceCommands } from '../../lib/tmux-reference' import { API_MODELS, API_NAV, PORT_NAME, indexFor, isMemberOwner, ownersOf, pageSlug, referenceAlternatives, topLevelTypesOf } from '../../lib/api-models' import { PORT_BY_SLUG, referenceUrl } from '../../lib/ports' import { productApiHref } from '../../lib/product-api' @@ -362,6 +365,9 @@ const pageSections: ApiSection[] = glossary ? apiGlossaryHeadings(glossaryContex ...(otherInherited.length ? [{ id: 'api-inherited', label: 'Inherited members', count: otherInherited.length }] : []), ] : [] const relationshipSections = owner && model ? apiRelationshipSections(model, owner) : [] +const tmuxCommandNames = source && owner ? tmuxSourceCommands(source.version, owner).map((command) => command.name) : [] +const supportedCommands = tmuxCommandNames.filter((name) => commandRows(name).length > 0) +if (supportedCommands.length) pageSections.push({ id: 'api-libtmux-support', label: 'Support in libtmux', count: supportedCommands.reduce((n, name) => n + commandRows(name).length, 0) }) const paths = (source?.paths ?? []).filter((path) => !owner || path.symbols.some((symbol) => symbol.id === owner.id)) if (relationshipSections.some((section) => ['api-calls', 'api-called-by'].includes(section.id))) pageSections.push({ id: 'api-call-network', label: 'Call neighborhood' }) if (paths.length) pageSections.push({ id: 'api-source-paths', label: 'Paths through the source', count: paths.length }) @@ -830,6 +836,7 @@ const bases = owner && 'extends' in owner ? owner.extends ?? [] : [] )} + {supportedCommands.map((name) => )} {related.length > 0 &&