Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a44ae8b
Docs(style[contributing]): Wrap the gate loop
tony Oct 4, 2026
b34dcf8
Examples(style[format]): Wrap example code at 80
tony Oct 4, 2026
732927b
Examples(style[subscribe]): Split the flag test
tony Oct 4, 2026
c153ee0
Examples(style[environment]): Wrap the package doc
tony Oct 4, 2026
bfa7877
Examples(style[quickstart]): Wrap the package doc
tony Oct 4, 2026
7a15f96
Examples(style[fast-path]): Share one request
tony Oct 4, 2026
ee5d6fc
Examples(style[option-hook]): Name the wanted text
tony Oct 4, 2026
4599d26
Examples(style[planned-build]): Loop the checks
tony Oct 4, 2026
01e60d0
Examples(style[run-to-completion]): Wrap a comment
tony Oct 4, 2026
d716d86
Examples(style[snapshot-browser]): Wrap a comment
tony Oct 4, 2026
36e7fcc
Examples(style[mcp]): Wrap the Run examples
tony Oct 4, 2026
a29ce40
Examples(style[agent-workflow]): Wrap the program
tony Oct 4, 2026
d7d8d31
Examples(style[build-workspace]): Wrap two calls
tony Oct 4, 2026
4ecf3d3
Examples(style[tmuxq]): Name the pane predicate
tony Oct 4, 2026
847e47d
Examples(style[tmuxtest]): Wrap the wait examples
tony Oct 4, 2026
8843409
Examples(style[scripted]): Wrap the doc example
tony Oct 4, 2026
364fde3
Examples(style[tmuxtest]): Continue the setup
tony Oct 4, 2026
4137516
Examples(style[workspace]): Move a YAML comment up
tony Oct 4, 2026
0a9500b
Examples(style[readme]): Wrap the examples guide
tony Oct 4, 2026
10e7f7d
Examples(style[readme]): Name the session request
tony Oct 4, 2026
89498b4
Examples(style[tmux]): Wrap the _complete examples
tony Oct 4, 2026
098e9a7
Examples(style[tmux]): Wrap the Example functions
tony Oct 4, 2026
37f1aa5
Examples(style[benchmarks]): Tag the output fence
tony Oct 4, 2026
d7824a0
Examples(style[benchmarks]): Tag the result fences
tony Oct 4, 2026
86cae64
Examples(style[benchmarks]): Wrap two commands
tony Oct 4, 2026
40d6c52
Docs(style[contributing]): Wrap four gate commands
tony Oct 4, 2026
9c4a192
Docs(style[skill]): Wrap two probe commands
tony Oct 4, 2026
3edd771
docs(WRITING[Examples]): Add example style guide
tony Oct 4, 2026
5e18e09
ai(rules[AGENTS]): Route examples to WRITING.md
tony Oct 4, 2026
2f79209
Examples(style[check]): Gate example width at 80
tony Oct 4, 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
10 changes: 7 additions & 3 deletions .agents/skills/testing-the-mcp-server/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Give the whole run its own root so a sibling checkout's suite cannot end a
server this one is using:

```console
$ export TMUX_TMPDIR=/tmp/libtmux-go-probe && mkdir -p "$TMUX_TMPDIR" && unset TMUX TMUX_PANE
$ export TMUX_TMPDIR=/tmp/libtmux-go-probe \
&& mkdir -p "$TMUX_TMPDIR" \
&& unset TMUX TMUX_PANE
```

## Climb only as high as the question needs
Expand All @@ -68,8 +70,10 @@ stdin open, matches replies by id, declines any question the server asks, and
reads a plan of JSON-RPC calls from stdin.

```console
$ ./references/drive.py "$(command -v libtmux-mcp)" TMUX_TMPDIR=/tmp/libtmux-go-probe \
<<< '[{"method":"tools/call","params":{"name":"list_panes","arguments":{}}}]'
$ ./references/drive.py "$(command -v libtmux-mcp)" \
TMUX_TMPDIR=/tmp/libtmux-go-probe <<'EOF'
[{"method":"tools/call","params":{"name":"list_panes","arguments":{}}}]
EOF
```

It reports which advertised tools a plan never called, so a sweep can be grown
Expand Down
36 changes: 31 additions & 5 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ which surfaces as a version-specific failure that has nothing to do with the
version:

```console
$ export TMUX_TMPDIR=/tmp/libtmux-go-test && mkdir -p "$TMUX_TMPDIR" && unset TMUX TMUX_PANE
$ export TMUX_TMPDIR=/tmp/libtmux-go-test \
&& mkdir -p "$TMUX_TMPDIR" \
&& unset TMUX TMUX_PANE
```

## The gates
Expand All @@ -36,7 +38,9 @@ packages as typecheck failures, and a newer one reports lints an older one has
no analyzer for. Run the pinned release before believing a clean local one:

```console
$ go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0 run ./...
$ go run \
github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0 \
run ./...
```

Format, lint, vet, and test the tmux module:
Expand All @@ -48,7 +52,14 @@ $ gofumpt -w . && golangci-lint run ./... && go vet ./... && go test ./...
Then each of the others, from its own directory:

```console
$ for module in examples workspace mcp benchmarks internal/tools; do (cd "$module" && gofumpt -w . && golangci-lint run ./... && go vet ./... && go test ./...) || break; done
$ for module in examples workspace mcp benchmarks internal/tools; do
(cd "$module" \
&& gofumpt -w . \
&& golangci-lint run ./... \
&& go vet ./... \
&& go test ./...) \
|| break
done
```

Run them with the workspace on, which is the only way they see the working
Expand Down Expand Up @@ -82,7 +93,8 @@ agreeing on one stale version is the failure that check exists for, and it is
the failure that happened:

```console
$ go test ./tmux/internal/integration/ -run TestEveryRequirementNamesTheNewestRelease
$ go test ./tmux/internal/integration/ \
-run TestEveryRequirementNamesTheNewestRelease
```

Release sibling modules in dependency order: core, workspace, then MCP. After
Expand All @@ -105,7 +117,11 @@ Known vulnerabilities are checked per module, because each resolves its own
dependencies:

```console
$ for module in . examples workspace mcp benchmarks internal/tools; do (cd "$module" && go run golang.org/x/vuln/cmd/govulncheck@v1.6.0 ./...) || break; done
$ for module in . examples workspace mcp benchmarks internal/tools; do
(cd "$module" \
&& go run golang.org/x/vuln/cmd/govulncheck@v1.6.0 ./...) \
|| break
done
```

It reports the standard library as well as dependencies, so it fails on a
Expand Down Expand Up @@ -133,6 +149,16 @@ Then confirm that regeneration changed nothing:
$ git diff --exit-code
```

Examples stay within 80 columns, which gofumpt does not enforce.
`.github/example-width.toml` names the files the check reads and lists the few
lines allowed to stay wider. The self-test comes first because it proves the
check can fail:

```console
$ python3 internal/tools/check_example_width.py --self-test && \
python3 internal/tools/check_example_width.py
```

The race detector is not optional before anything ships:

```console
Expand Down
95 changes: 95 additions & 0 deletions .github/WRITING.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,101 @@ Go blocks between `docs:` markers are generated. Edit their source program,
not the Markdown block; [the examples README](../examples/README.md) identifies
them. Unmarked blocks are handwritten.

## Examples

<!-- shared:examples -->

An example is code written for a reader: a program under `examples/`, code in
a doc comment or docstring, and every fenced block in a README or docs page.
Shell blocks also follow [Code blocks](#code-blocks).

The text between the shared markers is the same in every libtmux port.
Change it in all of them together.

### Width

- **Examples stay within 80 columns.** They render in fixed-width boxes that
scroll sideways, and 80 columns fits a libtmux.org code block in a
laptop-width window. Comments inside examples wrap at 80 too.
- **The width check enforces it.** It reads the tracked files that
`.github/example-width.toml` names and fails on a wider line. It measures
the whole source line, so code in a doc comment counts its indent and
comment marker. It skips output (a fence tagged `text`, and what a
`console` block prints), hidden setup lines, and a line that is only a URL;
an untagged fence counts as code.
- **A line that must stay wider is listed there with its reason.** An entry
that no longer matches a line fails the check, so no stale entry stays.
- **The formatter's width is the hard limit for all other source.** Example
directories set their formatter to 80 where the formatter takes a width.

### Reaching 80

- **Change the code, not the line breaks.** A formatter rejoins any line that
fits its width. Name a sub-expression, use a short example name, hide setup
the reader does not need, or print less.
- **Break at the outermost level when a break is still needed:** after an
opening parenthesis with one argument per line, one call per line in a
chain, one field per line in a literal.
- **Put a comment on its own line above the code it explains.** Never trail
one after code in an example, unless the repository's example runner reads
it there, as with an assertion marker.
- **Break a long string at a word boundary,** never inside a tmux format
(`#{...}`) or an escape sequence; the joined text stays the same.
- **Continue a long command in a `console` block the way its shell does:**
`\` after a `$ ` prompt, a backtick after `PS> `, one flag per continuation
line.

### What never breaks

- **Output a test compares.** Wrapping it changes what the test expects.
- **A block copied from a source file.** Fix the width in the source, then
refresh the copy with the sync command the port block names, or by hand
where it names none; never fix the copy alone.
- **Marker lines and URLs,** which tools and readers take whole.

<!-- /shared:examples -->

### In this repository

- **Hard limit:** `golines` in `examples/.golangci.yml` (`max-len` and
`tab-len`), enabled beside gofumpt in the `examples` module only; the width
check counts a tab as 4 columns, as `tab-len` does. `golangci-lint run`
fails a file either formatter would change, and
`(cd examples && golangci-lint fmt ./...)` applies both; use the version
`.github/workflows/tests.yml` pins, since another can format differently.
The width check is `python3 internal/tools/check_example_width.py`.
- **Not formatted:** other modules run gofumpt only. Their `example_test.go`
files, the `mcp/examples` and `workspace/examples` programs,
`examples/go.mod`, `examples/.golangci.yml`, Markdown blocks and doc-comment
code are held to 80 by hand and by the width check. Tag a table of program
output `text`; the check skips it.
- **Runs, compiles, exempt:** an `Example` runs only when it ends in
`// Output:`. One without output compiles only, and `examplesWithoutOutput`
in `tmux/documentation_test.go` lists it with a reason. A Markdown block
between `docs:` markers is quoted from a program that compiles and runs. An
unmarked block is handwritten and is neither.
- **Compared output and copied blocks:** `// Output:` text and `// docs:<name>`
marker lines stay whole. After editing a program under `examples/`, run
`go generate ./...` in `tmux/`; after changing an MCP tool, run it in `mcp/`
to rebuild `TOOLS.md`. CI fails on any diff.

Bad, over 80:

```go
if _, err := connectedPane.Capture(ctx, tmux.CapturePaneRequest{}); !errors.Is(
err,
tmux.ErrConnectionRequiresProcess,
) {
```

Good, a named request and one statement per step:

```go
request := tmux.CapturePaneRequest{}
_, err = connectedPane.Capture(ctx, request)
if !errors.Is(err, tmux.ErrConnectionRequiresProcess) {
```

## Commits

```text
Expand Down
38 changes: 38 additions & 0 deletions .github/example-width.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
width = 80
tab_width = 4
shared_digest = "28b74bae1f7a06731fea5a150cbde4430179b7788b7564ea1644c3951df8531b"
checker_digest = "eb87afceb3fc8f11ef5a478cd38f901ef3950e89ff94fbe0ca281c0cfc1a0e2e"
allow_ceiling = 4
markdown = ["**/*.md"]
sources = [
"**/examples/**/*.go",
"**/example_test.go",
"**/*_example_test.go",
"**/examples/go.mod",
"**/examples/.golangci.yml",
]
doc_comments = ["**/*.go"]

[[exclude]]
glob = "examples/LICENSE"
reason = "license text; nobody reads it for code"

[[allow]]
path = "examples/byte-streams/main.go"
line = "\t// docs:byte-streams given:ctx context.Context; server tmux.Server; pane tmux.Pane; payload *strings.Reader; archive string; marker string"
reason = "docs marker line; the generator reads it whole"

[[allow]]
path = "examples/control-mode-subscribe/main.go"
line = "\t// docs:subscribing given:ctx context.Context; session tmux.Session; stream *tmux.NotificationStream"
reason = "docs marker line; the generator reads it whole"

[[allow]]
path = "tmux/example_test.go"
line = "\t// Output: {\"id\":\"\",\"sessionId\":\"\",\"windowId\":\"\",\"windowIndex\":0,\"index\":0,\"formats\":{}}"
reason = "output the test compares"

[[allow]]
path = ".github/WRITING.md"
line = "\tif _, err := connectedPane.Capture(ctx, tmux.CapturePaneRequest{}); !errors.Is("
reason = "the Bad example in the port block; it shows the width problem the Good example fixes"
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ jobs:
exit 1
fi

# Examples render in fixed-width boxes, and gofumpt never wraps a line,
# so the width has its own check. The self-test runs first: a check that
# cannot fail is not evidence.
- name: Check example width
run: |
python3 internal/tools/check_example_width.py --self-test
python3 internal/tools/check_example_width.py

# An exported identifier can change or vanish without anything saying so: the
# changelog is written by hand, and nothing compares what a release exports
# against what the last one did. This reports that difference into the run
Expand Down
6 changes: 4 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ subprocess transport, the checked-in generators, and `internal/integration`.
## Which policy applies

- Documentation, user-facing text, `CHANGELOG.md`, release notes, commit
messages, doc comments, and source comments:
[.github/WRITING.md](.github/WRITING.md)
messages, doc comments, source comments, and any code example (example
programs, Example functions, Markdown code blocks):
[.github/WRITING.md](.github/WRITING.md), and its
[Examples](.github/WRITING.md#examples) section for code a reader sees
- Building, testing, linting, the Go floor, the tmux matrix, and pull requests:
[.github/CONTRIBUTING.md](.github/CONTRIBUTING.md)
- Anything under `mcp/`: [mcp/AGENTS.md](mcp/AGENTS.md)
Expand Down
29 changes: 16 additions & 13 deletions BENCHMARKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Each table below contains the same workload on a different tmux.

## tmux 3.2a

```
```text
path wall processes clients query answer
----------------------------------------------------------------------------------------
process 105ms 17 0 7 panes on the server [0 0 1 2 3 4 5]
Expand All @@ -31,7 +31,7 @@ chained + connection 7ms 0 1 7 panes on the server [0 0

## tmux 3.3a

```
```text
path wall processes clients query answer
----------------------------------------------------------------------------------------
process 105ms 17 0 7 panes on the server [0 0 1 2 3 4 5]
Expand All @@ -43,7 +43,7 @@ chained + connection 8ms 0 1 7 panes on the server [0 0

## tmux 3.4

```
```text
path wall processes clients query answer
----------------------------------------------------------------------------------------
process 116ms 17 0 7 panes on the server [0 0 1 2 3 4 5]
Expand All @@ -55,7 +55,7 @@ chained + connection 19ms 0 1 7 panes on the server [0 0

## tmux 3.5

```
```text
path wall processes clients query answer
----------------------------------------------------------------------------------------
process 143ms 17 0 7 panes on the server [0 0 1 2 3 4 5]
Expand All @@ -67,7 +67,7 @@ chained + connection 9ms 0 1 7 panes on the server [0 0

## tmux 3.6

```
```text
path wall processes clients query answer
----------------------------------------------------------------------------------------
process 108ms 17 0 7 panes on the server [0 0 1 2 3 4 5]
Expand All @@ -79,7 +79,7 @@ chained + connection 18ms 0 1 7 panes on the server [0 0

## tmux 3.7

```
```text
path wall processes clients query answer
----------------------------------------------------------------------------------------
process 113ms 17 0 7 panes on the server [0 0 1 2 3 4 5]
Expand All @@ -91,7 +91,7 @@ chained + connection 9ms 0 1 7 panes on the server [0 0

## tmux 3.7a

```
```text
path wall processes clients query answer
----------------------------------------------------------------------------------------
process 187ms 17 0 7 panes on the server [0 0 1 2 3 4 5]
Expand All @@ -103,7 +103,7 @@ chained + connection 10ms 0 1 7 panes on the server [0 0

## tmux 3.7b

```
```text
path wall processes clients query answer
----------------------------------------------------------------------------------------
process 92ms 17 0 7 panes on the server [0 0 1 2 3 4 5]
Expand All @@ -115,7 +115,7 @@ chained + connection 7ms 0 1 7 panes on the server [0 0

## tmux 3.7c

```
```text
path wall processes clients query answer
----------------------------------------------------------------------------------------
process 102ms 17 0 7 panes on the server [0 0 1 2 3 4 5]
Expand All @@ -127,7 +127,7 @@ chained + connection 8ms 0 1 7 panes on the server [0 0

## tmux 3.8-rc2

```
```text
path wall processes clients query answer
----------------------------------------------------------------------------------------
process 67ms 17 0 7 panes on the server [0 0 1 2 3 4 5]
Expand Down Expand Up @@ -193,7 +193,7 @@ named above against tmux 3.7c, 20 iterations per size:
```console
$ go test ./tmux/ \
-run '^$' \
-bench 'BenchmarkLoadBufferFrom|BenchmarkSaveBufferTo|BenchmarkCaptureScrollback' \
-bench 'Benchmark(LoadBufferFrom|SaveBufferTo|CaptureScrollback)' \
-benchtime 20x \
-benchmem
```
Expand Down Expand Up @@ -236,7 +236,7 @@ woken by tmux. Ten waits each, for output 150ms away, on tmux 3.7d and the
machine named above. `go -C benchmarks run .` prints this table too, and
`TestWaitingEventDrivenCostsFewerProcesses` gates the comparison.

```
```text
path wall processes clients measurement
----------------------------------------------------------------------------------------
polled capture 161ms 18 0 10 waits for output 150ms away
Expand Down Expand Up @@ -323,7 +323,10 @@ No tmux and no disk: decoding YAML into the document map and normalizing it
into a build plan, on a fixed six-window, three-pane-each document.

```console
$ go test ./workspace/internal/cli/ -run '^$' -bench 'BenchmarkDecodeDocument|BenchmarkNormalize' -benchmem
$ go test ./workspace/internal/cli/ \
-run '^$' \
-bench 'Benchmark(DecodeDocument|Normalize)' \
-benchmem
```

| Call | Cost |
Expand Down
Loading
Loading