libtmux-async 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b04b3b0c18cd4645fa9a2223d30e6200f56c73ae91b7ecb37b054cd18a70a0d
4
- data.tar.gz: 69c5afd946fd894896d4ef8ef5b4174c8f2749d0e5b08d4d4267045d570bc06f
3
+ metadata.gz: b9f1187e16c3168c804d6486a470701bfd82dc435ff435430863cd07613cb406
4
+ data.tar.gz: 62950e54ee7646a57cfc0f5d78d74ea6bed7fbeb7934b280ea0a81817e103cc5
5
5
  SHA512:
6
- metadata.gz: e3259a0b36dd4df7729c2bf570639306f98622a9bc7fdabc589f0ea6c248f210f95fc610acf9be38712c328c2fc1ab08b4aadf89f3f5d53557658ac6fec7ebb8
7
- data.tar.gz: bc457afb6e85da08a1ffa2b88c39e3bfdc4b1b9136f6c86223cda74c125a7df16a89c85f5c183019079876fd98afa91fd527140b54cfabb5704df3c553915e42
6
+ metadata.gz: 22fe413b5e3fa8d1b764c0313d6e27aae9f6c1c7e13a0bc036b68d08b181ec20541f183a937a6eac47a35d2fb2b0275484c7f315506fecf004f06ddb600ffe7e
7
+ data.tar.gz: 7b278ad583a5c392f1e6dc2013347d034e147c04ff6f5e1f9ca052ea657b7e08e8a83051b6b1ad26d8cc43c02d7e90f077034f58d640bba7766a8277feb20f6d
data/CHANGELOG.md CHANGED
@@ -9,7 +9,11 @@ The gems are released together at one version, so every release has a section
9
9
  here. Changes that span gems, such as documentation, CI and release tooling, are
10
10
  in the [main changelog](../../CHANGELOG.md).
11
11
 
12
- ## 0.1.3 (unreleased)
12
+ ## 0.1.4 (unreleased)
13
+
14
+ ## 0.1.3 (2026-12-05)
15
+
16
+ No entries for `libtmux-async`.
13
17
 
14
18
  ## 0.1.2 (2026-11-04)
15
19
 
data/README.md CHANGED
@@ -20,8 +20,10 @@ Run libtmux operations inside an application-owned Async task: a
20
20
  [Guide](https://libtmux.org/en/ruby/latest/guides/async/) ·
21
21
  [RubyGems](https://rubygems.org/gems/libtmux-async)
22
22
 
23
- [![libtmux.org](https://img.shields.io/badge/docs-libtmux.org-0b7285)](https://libtmux.org/en/ruby/)
23
+ [![compatibility](https://github.com/libtmux/libtmux-ruby/actions/workflows/compatibility.yml/badge.svg)](https://github.com/libtmux/libtmux-ruby/actions/workflows/compatibility.yml)
24
24
  [![libtmux-async](https://img.shields.io/gem/v/libtmux-async?label=libtmux-async)](https://rubygems.org/gems/libtmux-async)
25
+ [![libtmux.org](https://img.shields.io/badge/docs-libtmux.org-0b7285)](https://libtmux.org/en/ruby/)
26
+ [![license](https://img.shields.io/badge/license-MIT-blue)](https://github.com/libtmux/libtmux-ruby/blob/master/LICENSE)
25
27
 
26
28
  </div>
27
29
 
@@ -63,7 +65,9 @@ LibTmux::Server.start do |server|
63
65
  Async do |parent|
64
66
  LibTmux::Async.open(parent: parent, server: server) do |scope|
65
67
  refs = scope.server.list_panes.map(&:ref)
66
- screens = scope.map(refs, concurrency: 2) { |ref| scope.server.pane(ref).capture }
68
+ screens = scope.map(refs, concurrency: 2) do |ref|
69
+ scope.server.pane(ref).capture
70
+ end
67
71
  puts "captured panes: #{screens.length}"
68
72
  puts "all succeeded: #{screens.all?(&:success?)}"
69
73
  end
@@ -166,6 +170,35 @@ every scope:
166
170
 
167
171
  The contract is in [Async map][behavior-async-map].
168
172
 
173
+ ## Check optional features
174
+
175
+ ### [`Async::Server#capabilities`][async-server-capabilities]: read the bound daemon
176
+
177
+ The report uses the same feature registry as the core and a fiber-aware
178
+ request. Its immutable decisions remain usable after the scope closes.
179
+
180
+ <!-- example: api_async_capabilities/main -->
181
+ ```ruby
182
+ require "libtmux"
183
+ require "libtmux/async"
184
+
185
+ LibTmux::Server.start do |server|
186
+ Async do |parent|
187
+ LibTmux::Async.open(parent: parent, server: server) do |scope|
188
+ report = scope.server.capabilities
189
+ puts "Control mode requires tmux #{report.feature('control-mode').since}"
190
+ end
191
+ end.wait
192
+ end
193
+ ```
194
+ <!-- /example -->
195
+
196
+ ```text
197
+ Control mode requires tmux 3.7
198
+ ```
199
+
200
+ More: [Support queries and snapshot limits][behavior-capabilities].
201
+
169
202
  ## Read control events in a scope
170
203
 
171
204
  ### [`Async::Server#open_control`][async-server-open_control]: replies and events
@@ -227,6 +260,9 @@ The contract is in [Control connections][behavior-control].
227
260
 
228
261
  - **Terminal attachment.** `attach` stays on the blocking core and raises
229
262
  [`UnsupportedFeatureError`][unsupportedfeatureerror] on this facade.
263
+ - **Server factories.** `Async::Server.start` and `Async::Server.open` raise
264
+ [`UnsupportedFeatureError`][unsupportedfeatureerror]. Start or open the core
265
+ server, then pass it to `LibTmux::Async.open(server:)`.
230
266
  - **Replay.** Reconnect and resume never replay requests or missed output. See
231
267
  [Control connections][behavior-control].
232
268
  - **A scheduler.** Imports start no scheduler or background task, and your
@@ -236,27 +272,21 @@ The contract is in [Control connections][behavior-control].
236
272
 
237
273
  ## Support and status
238
274
 
239
- Releases are numbered `0.1.N`, and each release increments `N`. The API is not
240
- settled: any release may change or remove exported identifiers, and the
241
- changelogs mark each break. Pin an exact version to avoid one.
242
- See the [changelog](CHANGELOG.md), and the [main
243
- changelog](https://github.com/libtmux/libtmux-ruby/blob/master/CHANGELOG.md)
244
- for changes that span gems.
245
-
246
- - **Ruby 3.3 or newer** and **tmux 3.3a or newer.** The facade dispatches
247
- through a version-checked core server, so it carries the same daemon release
248
- check.
275
+ - **Unstable API.** Releases are numbered `0.1.N`, and any release may change
276
+ or remove exported identifiers. Pin an exact version. See the
277
+ [changelog](CHANGELOG.md), and the [main
278
+ changelog](https://github.com/libtmux/libtmux-ruby/blob/master/CHANGELOG.md)
279
+ for changes that span gems.
280
+ - **Ruby 3.3 or newer** and **tmux 3.3a or newer.** The facade runs through a
281
+ core server, so it refuses an older daemon the same way.
249
282
  - **Control connections need tmux 3.7 or newer.**
250
283
  [`open_control`][async-server-open_control] refuses an older daemon before a
251
284
  control client attaches.
252
- - **Async 2.46.** The gem depends on `async` ~> 2.46.0 and the same version of
253
- `libtmux`.
254
- - **Linux, including WSL, and macOS.** The [compatibility workflow][compat]
255
- runs Ruby 3.3, 3.4 and 4.0 with tmux 3.3a through 3.8 on Ubuntu 24.04 and
256
- retains per-revision results. A push and a pull request run the oldest and
257
- newest of those releases, 3.3a and 3.8, and a release runs all of them. macOS
258
- is supported on a best-effort basis, and CI coverage for it is highly
259
- limited.
285
+ - **Dependencies.** The gem needs `async` and `libtmux` at the same version as
286
+ itself; the gemspec pins the range.
287
+ - **Linux, including WSL, and macOS.** CI runs on Linux; macOS is best effort.
288
+ See the [compatibility workflow][compat] and the
289
+ [CI matrix](../../.github/CONTRIBUTING.md#running-ci-against-any-tmux).
260
290
 
261
291
  ## Documentation
262
292
 
@@ -265,7 +295,7 @@ for changes that span gems.
265
295
  | [Reference](https://libtmux.org/en/ruby/latest/reference/libtmux-async/) | The Async classes, one page each |
266
296
  | [Async guide](https://libtmux.org/en/ruby/latest/guides/async/) | Running concurrent commands within an owned scope |
267
297
  | [Execution modes][doc-modes] | Blocking calls, Async tasks and control subscriptions |
268
- | [Recipes][doc-recipes] | Complete programs with checked excerpts |
298
+ | [Recipes][doc-recipes] | Complete programs and their excerpts |
269
299
  | [Public behavior][behavior-async-scope] | Scheduling, ownership and limits of a scope |
270
300
 
271
301
  [async-controlconnection-events]: https://libtmux.org/en/ruby/latest/reference/libtmux-async-controlconnection-events/
@@ -292,3 +322,6 @@ for changes that span gems.
292
322
  [server]: https://libtmux.org/en/ruby/latest/reference/libtmux-server/
293
323
  [server-start]: https://libtmux.org/en/ruby/latest/reference/libtmux-server-start/
294
324
  [unsupportedfeatureerror]: https://libtmux.org/en/ruby/latest/reference/libtmux-unsupportedfeatureerror/
325
+
326
+ [async-server-capabilities]: https://libtmux.org/en/ruby/latest/reference/libtmux-async-server-capabilities/
327
+ [behavior-capabilities]: ../../docs/reference/behavior.md#daemon-capabilities
@@ -11,7 +11,11 @@ module LibTmux
11
11
  end
12
12
  private_constant :Notification
13
13
 
14
+ private_class_method :new
15
+
14
16
  def initialize(scope:, **options)
17
+ raise ArgumentError, "scope must be a LibTmux::Async::Scope" unless scope.is_a?(Scope)
18
+
15
19
  super(**options)
16
20
  @scope = scope
17
21
  @changed = Notification.new
@@ -62,7 +66,11 @@ module LibTmux
62
66
  end
63
67
 
64
68
  class ControlConnection < LibTmux::ControlConnection
69
+ private_class_method :new
70
+
65
71
  def initialize(scope:, binding:, session_id:, reconnect: nil, **limits)
72
+ raise ArgumentError, "scope must be a LibTmux::Async::Scope" unless scope.is_a?(Scope)
73
+
66
74
  @scope = scope
67
75
  @release = binding.release
68
76
  @writer_changed = ::Async::Notification.new
@@ -211,7 +219,7 @@ module LibTmux
211
219
  end
212
220
 
213
221
  def build_subscription(**options)
214
- ControlSubscription.new(scope: @scope, **options)
222
+ ControlSubscription.__send__(:new, scope: @scope, **options)
215
223
  end
216
224
 
217
225
  def wake(writer)
@@ -11,17 +11,21 @@ module LibTmux
11
11
 
12
12
  attr_reader :pid, :result
13
13
 
14
- def initialize(scope, ticket, argv, input, deadline, cancel, limits)
14
+ def initialize(scope, ticket, argv, input, deadline, cancel, limits, stdout_tail: nil)
15
15
  @scope, @ticket, @argv, @input = scope, ticket, argv, input
16
16
  @deadline, @cancel, @limits = deadline, cancel, limits
17
17
  @started = clock
18
18
  @changed = ::Async::Notification.new
19
19
  @tasks, @streams = [], []
20
- @buffers = {stdout: +"".b, stderr: +"".b}
20
+ @stdout_tail = stdout_tail
21
21
  @finished_reads = 0
22
22
  end
23
23
 
24
24
  def call
25
+ @buffers = {
26
+ stdout: Internal::CommandOutput.new(@limits.fetch(:stdout), tail: @stdout_tail),
27
+ stderr: Internal::CommandOutput.new(@limits.fetch(:stderr))
28
+ }
25
29
  failure = nil
26
30
  begin
27
31
  watch_cancellation
@@ -219,16 +223,13 @@ module LibTmux
219
223
  def read_stream(io, stream)
220
224
  buffer = @buffers.fetch(stream)
221
225
  loop do
222
- remaining = @limits.fetch(stream) - buffer.bytesize
223
- bytes = io.read_nonblock([CHUNK, remaining + 1].min, exception: false)
226
+ bytes = io.read_nonblock(buffer.read_size(CHUNK), exception: false)
224
227
  case bytes
225
228
  when nil then break
226
229
  when :wait_readable then Fiber.scheduler.io_wait(io, IO::READABLE)
227
230
  when String
228
- raise CapacityError.new("command #{stream} exceeded its byte limit", **details(:read)) if bytes.bytesize > remaining
229
-
230
- @scope.__send__(:retain_output, @ticket, bytes.bytesize)
231
- buffer << bytes
231
+ appended = buffer.append(bytes) { |retained| @scope.__send__(:retain_output, @ticket, retained) }
232
+ raise CapacityError.new("command #{stream} exceeded its byte limit", **details(:read)) unless appended
232
233
  end
233
234
  end
234
235
  @finished_reads += 1
@@ -273,7 +274,8 @@ module LibTmux
273
274
  raise @failure if @failure
274
275
  if @status && @finished_reads == 2
275
276
  check_budget(:publish)
276
- @result = CommandResult.new(**@buffers, status: @status, pid: @pid, argv: @argv, elapsed_seconds: clock - @started)
277
+ @result = CommandResult.new(**@buffers.transform_values(&:bytes), status: @status,
278
+ pid: @pid, argv: @argv, elapsed_seconds: clock - @started)
277
279
  return
278
280
  end
279
281
  phase = observed? ? :drain : :read
@@ -30,7 +30,7 @@ module LibTmux
30
30
  @requests, @waiting, @maps = [], [], []
31
31
  @active = @queued_bytes = @output_bytes = 0
32
32
  @changed = ::Async::Notification.new
33
- @server = Server.new(self, server)
33
+ @server = Server.__send__(:new, self, server)
34
34
  end
35
35
 
36
36
  def close
@@ -279,7 +279,7 @@ module LibTmux
279
279
  raise ClosedError.new("Async scope is closed", phase: :admission) if @closed || @parent.finished?
280
280
  end
281
281
 
282
- def execute(argv, input: "".b, timeout: 5.0, cancel: nil)
282
+ def execute(argv, input: "".b, timeout: 5.0, cancel: nil, stdout_tail: nil)
283
283
  ensure_open
284
284
  deadline = clock + timeout if timeout.is_a?(Numeric) && timeout.finite?
285
285
  raise ArgumentError, "timeout must be finite" unless deadline
@@ -304,7 +304,7 @@ module LibTmux
304
304
  @waiting << ticket
305
305
  @queued_bytes += bytes
306
306
  ticket.execution = ProcessDriver.new(self, ticket, argv.map { |arg| arg.dup.freeze }.freeze,
307
- input.b.freeze, deadline, cancel, @limits)
307
+ input.b.freeze, deadline, cancel, @limits, stdout_tail: stdout_tail)
308
308
  ticket.task = ::Async::Task.new(@parent) do
309
309
  begin
310
310
  ticket.result = ticket.execution.call
@@ -4,6 +4,7 @@ module LibTmux
4
4
  module Async
5
5
  class Server < LibTmux::Server
6
6
  def initialize(scope, source)
7
+ raise ArgumentError, "scope must be a LibTmux::Async::Scope" unless scope.is_a?(Scope)
7
8
  raise ArgumentError, "server must be a bound LibTmux::Server" unless source.is_a?(LibTmux::Server)
8
9
 
9
10
  @scope, @source = scope, source
@@ -57,9 +58,15 @@ module LibTmux
57
58
  raise UnsupportedFeatureError.new("create an owned core server before opening its Async scope", phase: :admission)
58
59
  end
59
60
 
61
+ def self.open(**)
62
+ raise UnsupportedFeatureError.new("open the core server, then call LibTmux::Async.open(server:) to get an Async facade", phase: :admission)
63
+ end
64
+
65
+ private_class_method :new
66
+
60
67
  private
61
68
 
62
- def dispatch(argv, input: "".b, timeout: 5.0, cancel: nil, repaired_break: false)
69
+ def dispatch(argv, input: "".b, timeout: 5.0, cancel: nil, repaired_break: false, stdout_tail: nil)
63
70
  ensure_owner
64
71
  ensure_open
65
72
  validate_argv(argv)
@@ -67,7 +74,8 @@ module LibTmux
67
74
 
68
75
  Internal::NativeGuard.check(argv, @release, repaired_break: repaired_break)
69
76
  fence, marker = Internal::TmuxVersion.fence(@release)
70
- result = @scope.__send__(:execute, @pin.command_prefix + fence + argv, input: input, timeout: timeout, cancel: cancel)
77
+ result = @scope.__send__(:execute, @pin.command_prefix + fence + argv,
78
+ input: input, timeout: timeout, cancel: cancel, stdout_tail: stdout_tail)
71
79
  Internal::TmuxVersion.check_fence(result, marker, @release)
72
80
  end
73
81
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module LibTmux
4
4
  module Async
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
data/lib/libtmux/async.rb CHANGED
@@ -28,6 +28,16 @@ module LibTmux
28
28
  end
29
29
  private_class_method :attach_cleanup
30
30
 
31
+ # Own a private terminal program with scheduler-aware tmux requests.
32
+ def self.start_program(argv, parent: ::Async::Task.current, **options, &block)
33
+ adapter = ->(server) { Scope.new(parent: parent, server: server) unless server.is_a?(Server) }
34
+ Program.__send__(:start_with, adapter, argv, **options, &block)
35
+ end
36
+
37
+ def self.run_program(argv, **options)
38
+ Program.__send__(:run_with, self, argv, **options)
39
+ end
40
+
31
41
  def self.open(server:, parent: ::Async::Task.current, **options)
32
42
  raise ArgumentError, "Async scope requires a block" unless block_given?
33
43
 
@@ -4,6 +4,10 @@ module LibTmux
4
4
 
5
5
  def self.open: [T] (server: LibTmux::Server, ?parent: untyped, **untyped) { (Scope) -> T } -> T
6
6
 
7
+ def self.start_program: (Array[String], ?parent: untyped, ?server: LibTmux::Server?, ?executable: String, ?cwd: String?, ?environment: Hash[String, String], ?width: Integer, ?height: Integer, ?history_lines: Integer, ?timeout: Numeric, ?cancel: untyped) -> LibTmux::Program
8
+ | [T] (Array[String], ?parent: untyped, ?server: LibTmux::Server?, ?executable: String, ?cwd: String?, ?environment: Hash[String, String], ?width: Integer, ?height: Integer, ?history_lines: Integer, ?timeout: Numeric, ?cancel: untyped) { (LibTmux::Program) -> T } -> T
9
+ def self.run_program: (Array[String], ?parent: untyped, ?server: LibTmux::Server?, ?executable: String, ?cwd: String?, ?environment: Hash[String, String], ?width: Integer, ?height: Integer, ?history_lines: Integer, ?timeout: Numeric, ?cancel: untyped) -> LibTmux::Program::Result
10
+
7
11
  type scope_diagnostics = {
8
12
  transport: :async_process, closed: bool, admitted_requests: Integer,
9
13
  reserved_process_slots: Integer,
@@ -31,6 +35,7 @@ module LibTmux
31
35
  end
32
36
 
33
37
  class Server < LibTmux::Server
38
+ private def self.new: (*untyped, **untyped) -> instance
34
39
  def initialize: (Scope, LibTmux::Server) -> void
35
40
  def run: (Array[String], ?input: String, ?timeout: Numeric, ?cancel: untyped) -> CommandResult
36
41
  def close: () -> nil
@@ -39,9 +44,11 @@ module LibTmux
39
44
  | (session: EntityRef, ?reconnect: LibTmux::ControlConnection?, **Integer) -> ControlConnection
40
45
  def attach: (**untyped) -> bot
41
46
  def self.start: (**untyped) -> bot
47
+ def self.open: (**untyped) -> bot
42
48
  end
43
49
 
44
50
  class ControlConnection < LibTmux::ControlConnection
51
+ private def self.new: (*untyped, **untyped) -> instance
45
52
  def initialize: (scope: Scope, binding: untyped, session_id: String, ?reconnect: LibTmux::ControlConnection?, **Integer) -> void
46
53
  attr_reader events: ControlSubscription
47
54
  def exchange: (String, ?timeout: Numeric, ?cancel: untyped) -> GuardedReply
@@ -51,6 +58,7 @@ module LibTmux
51
58
  end
52
59
 
53
60
  class ControlSubscription < LibTmux::ControlSubscription
61
+ private def self.new: (*untyped, **untyped) -> instance
54
62
  def initialize: (scope: Scope, **untyped) -> void
55
63
  def next: (?timeout: Numeric?) -> ControlEvent
56
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libtmux-async
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - libtmux contributors
@@ -15,28 +15,34 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.1.2
18
+ version: 0.1.3
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.1.2
25
+ version: 0.1.3
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: async
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - "~>"
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.46.0
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '3'
33
36
  type: :runtime
34
37
  prerelease: false
35
38
  version_requirements: !ruby/object:Gem::Requirement
36
39
  requirements:
37
- - - "~>"
40
+ - - ">="
38
41
  - !ruby/object:Gem::Version
39
42
  version: 2.46.0
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: '3'
40
46
  description: Run concurrent libtmux commands and bounded control subscriptions inside
41
47
  application-owned Async tasks.
42
48
  executables: []
@@ -61,7 +67,7 @@ licenses:
61
67
  metadata:
62
68
  source_code_uri: https://github.com/libtmux/libtmux-ruby
63
69
  changelog_uri: https://github.com/libtmux/libtmux-ruby/blob/master/gems/libtmux-async/CHANGELOG.md
64
- documentation_uri: https://libtmux.org/en/ruby/v0.1.2/reference/
70
+ documentation_uri: https://libtmux.org/en/ruby/v0.1.3/reference/
65
71
  rdoc_options: []
66
72
  require_paths:
67
73
  - lib