Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d1b3638
fix(site) Record optional tmux feature requirements
tony Oct 17, 2026
93a1409
test(site) Check the tmux support page states each requirement
tony Oct 17, 2026
de58523
feat(api-model) Validate port capability manifests
tony Oct 17, 2026
c271491
feat(scripts) Generate capability data from port manifests
tony Oct 17, 2026
6094e92
feat(site) Render capabilities as a fixed-width matrix
tony Oct 17, 2026
c16f243
feat(site) Generate the capability reference pages
tony Oct 17, 2026
d0bd79d
feat(site) Show libtmux support on tmux command pages
tony Oct 17, 2026
4f06c3e
docs(site) Point the tmux guide at generated capabilities
tony Oct 17, 2026
63de46b
fix(site) Run the capabilities test without a tmux clone
tony Oct 22, 2026
0dcbca6
fix(site) Say only ports with a registry gate features
tony Oct 24, 2026
70e3fd2
fix(api-model) Report a non-array except as a manifest problem
tony Oct 24, 2026
651a109
fix(api-model) Refuse release-candidate numbers tmux never used
tony Oct 24, 2026
e3bba09
fix(scripts) Read a capability manifest only for its own port
tony Oct 24, 2026
7883842
fix(scripts) Compare capabilities per port and name the unread ones
tony Oct 24, 2026
903f82f
fix(site) Name each port's release on shared capability rows
tony Oct 24, 2026
b160cf6
fix(site) List a repaired cell in the legend under its own name
tony Oct 24, 2026
5e084ae
test(site) Give the Python capability fixtures the Python floor
tony Oct 24, 2026
f8056ee
docs(site) Drop the release count from the column-grouping comment
tony Oct 24, 2026
3c23a9e
fix(scripts) Resolve capability names through API dependencies
tony Oct 25, 2026
afb5cee
fix(scripts) Read capability manifests from the checkout override
tony Oct 25, 2026
1aeb40b
fix(scripts) Keep the committed ports when --port rewrites one
tony Oct 25, 2026
37fadd3
fix(scripts) Reject a committed capability entry for a wrapper library
tony Oct 25, 2026
029935d
fix(scripts) Report releases that are not a list as a problem
tony Oct 25, 2026
5678fdd
chore(site[swift]) Move the Swift API model to libtmux-swift alpha.8
tony Oct 25, 2026
568a8a0
fix(site[tmux-usage]) Record Swift's senders at its model revision
tony Oct 25, 2026
9da7450
fix(site[swift]) Record the destinations at libtmux-swift alpha.8
tony Oct 25, 2026
788ae97
feat(site[data]) Generate capability data from eleven port manifests
tony Oct 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 204 additions & 0 deletions packages/api-model/src/capabilities.ts
Original file line number Diff line number Diff line change
@@ -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<Handling, 'fallback'>
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<CapabilityManifest> | 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<string>()
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 }
}
14 changes: 14 additions & 0 deletions packages/api-model/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
116 changes: 116 additions & 0 deletions packages/api-model/test/capabilities.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
Loading
Loading