bidi2pdf 0.1.23 โ†’ 0.1.25

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: 9bff5f993e54cb0f70e6a2c83e022bf29fdef7b0fafc6ce8b641d5ec33aea7ea
4
- data.tar.gz: e2466bb66703e3a7ac4ca16bfdea22f836c8fff07492e9f44904ecf5bc9c9c63
3
+ metadata.gz: f000e35aacf91ebfd7691be7ce8e989ab8d384dd96075e9ef705692f5f68bc3b
4
+ data.tar.gz: ef370866fad4eacca3d74a23f4ea7b83caf157f498cae29c26fcdb19757ada9e
5
5
  SHA512:
6
- metadata.gz: 6958ef3cc24d5350fdb090598940410f5cd3ab9abef4003f118d52ab61142b45c6427e0225ed4d37a9fa3a23d0dfd033e67a07cc981f891cb2f1f95f7af67612
7
- data.tar.gz: 74a366dc1c4953bb6e17e8c7578d3ec79cd7a0ea9f1f058f9d353ebdab12b2b046d7e25424b22745081895b09f60a5ca7a701eb29763472b9320e6a564142ad7
6
+ metadata.gz: 4a6025a10a1ebab333371dbf80e8d733e57052a08da043574e9b661551f02259c163afc7b0fe79580faafe5e4a1ad8bb03ab1655074eea77d77f02fd80b6c10f
7
+ data.tar.gz: efa593482aba4d15785007ac2612afafbe61f04c8dc6555b6052e7cb04d775661b2d0b2d286fe64a401fe22cc7050697b734aae1a2c97f0b4c88d28856134a6f
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "bidi2pdf",
3
+ "interface": {
4
+ "displayName": "bidi2pdf"
5
+ },
6
+ "plugins": [
7
+ {
8
+ "name": "bidi2pdf",
9
+ "source": {
10
+ "source": "local",
11
+ "path": "./claude-plugin"
12
+ },
13
+ "policy": {
14
+ "installation": "AVAILABLE",
15
+ "authentication": "ON_USE",
16
+ "products": ["CODEX"]
17
+ },
18
+ "category": "Developer Tools"
19
+ }
20
+ ]
21
+ }
data/CHANGELOG.md CHANGED
@@ -8,10 +8,47 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
- [unreleased]: https://github.com/dieter-medium/bidi2pdf/compare/v0.1.23..HEAD
11
+ [unreleased]: https://github.com/dieter-medium/bidi2pdf/compare/v0.1.25..HEAD
12
12
 
13
13
  <!-- generated by git-cliff end -->
14
14
 
15
+ ## [0.1.25] - 2026-10-27
16
+
17
+ ### ๐Ÿ› Fixed
18
+ - Keep the websocket-native hint off stdout
19
+ - Load the version constant with the library
20
+ - Trim plugin ground rules and preflight
21
+ - Keep plugin agents on bidi2pdf's own path
22
+ - Follow the gem's 0.1.25.pre in the Codex manifest
23
+ - Set SKILL_DIR before the screenshot script runs
24
+ - Check landing page options per command
25
+
26
+ ### ๐Ÿ”„ Changed
27
+ - Merge pull request #181 from dieter-medium/fix/require-version
28
+ - Merge pull request #180 from dieter-medium/fix/plugin-ground-rules
29
+ - Merge pull request #179 from dieter-medium/feat/codex-plugin
30
+ - Merge pull request #178 from dieter-medium/feat/agent-landing-page
31
+ - Merge pull request #177 from dieter-medium/chore/plugin-icon
32
+
33
+ ### ๐Ÿš€ Added
34
+ - Offer the plugin's skills to Codex
35
+ - Publish a landing page and llms.txt for agents
36
+
37
+ ## [0.1.24] - 2026-10-27
38
+
39
+ ### ๐Ÿ› Fixed
40
+ - Release every live slot after a fork
41
+ - Release a forked child's in-flight slots too
42
+ - Close a forked child's copies of inherited sockets
43
+ - Give a forked child its own session warmer
44
+
45
+ ### ๐Ÿ”„ Changed
46
+ - Merge pull request #174 from dieter-medium/fix/warmer-after-fork
47
+ - Merge pull request #173 from dieter-medium/dependabot/bundler/main/rubocop-1.92.1
48
+
49
+ ### ๐Ÿ”ง Build
50
+ - Bump rubocop from 1.92.0 to 1.92.1
51
+
15
52
  ## [0.1.23] - 2026-10-18
16
53
 
17
54
  ### ๐Ÿ› Fixed
@@ -596,7 +633,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
596
633
 
597
634
  ### ๐Ÿ”„ Released
598
635
 
599
- - [unreleased](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.23..HEAD)
636
+ - [unreleased](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.25..HEAD)
637
+ - [0.1.25](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.24..v0.1.25)
638
+ - [0.1.24](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.23..v0.1.24)
600
639
  - [0.1.23](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.22..v0.1.23)
601
640
  - [0.1.22](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.21..v0.1.22)
602
641
  - [0.1.21](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.20..v0.1.21)
data/README.md CHANGED
@@ -11,6 +11,10 @@
11
11
  **BiDirectional (BiDi)** protocol. Whether you're automating reports, archiving websites, or shipping documentation,
12
12
  Bidi2pdf gives you **precision, flexibility, and full control**.
13
13
 
14
+ **For agents and automation:** the use cases on one page - [dieter-medium.github.io/bidi2pdf](https://dieter-medium.github.io/bidi2pdf/),
15
+ and as plain text for language models: [llms.txt](https://dieter-medium.github.io/bidi2pdf/llms.txt). Both are
16
+ published from `site/` by `.github/workflows/pages.yml`.
17
+
14
18
  ---
15
19
 
16
20
  ## ๐Ÿ“š Table of Contents
@@ -202,7 +206,8 @@ still emits exactly this shape, with `ok: false` and a structured `error` (`code
202
206
  ### stdin/stdout, manifests, and progress streaming
203
207
 
204
208
  ```bash
205
- # Render HTML piped on stdin, PDF bytes piped out on stdout - no files touched
209
+ # Render HTML piped on stdin, PDF bytes piped out on stdout - no input or output file of your own
210
+ # (the PDF goes straight to stdout; the HTML is kept in a temporary file while Chrome loads it, then deleted)
206
211
  cat page.html | bidi2pdf render --stdin --output - > page.pdf
207
212
 
208
213
  # A render manifest: enough to reproduce and diagnose the render later
@@ -283,13 +288,17 @@ agent uses bidi2pdf the way it is meant to be used instead of guessing options:
283
288
 
284
289
  | Skill | For |
285
290
  |---|---|
286
- | `render-pdf` | a URL or HTML file to PDF with the CLI: order of commands, waits, screen/dark/mobile view, reading the JSON result and exit codes |
291
+ | `render-pdf` | a URL or HTML file to PDF with the CLI: a preflight that suggests how to get Ruby and a browser, order of commands, waits, screen/dark/mobile view, reading the JSON result and exit codes |
287
292
  | `pdf-recipe` | a recipe for pages that need steps before printing, validated without a browser |
288
293
  | `diagnose-pdf` | a blank, unstyled or wrongly paged PDF: a checklist around `bidi2pdf diagnose` |
289
294
  | `remote-chrome` | a shared chromedriver container: settings, sizing, session cleanup, untrusted HTML |
290
295
  | `page-screenshots` | review screenshots per page at phone and desktop width, light and dark (with a script) |
291
296
  | `pdf-specs` | RSpec specs with the gem's PDF matchers and Chrome container helpers |
292
297
 
298
+ Every skill starts with short ground rules: bidi2pdf is the only renderer (a failure is reported,
299
+ not worked around with another PDF engine), nothing is installed without the user's go-ahead, and
300
+ bidi2pdf's own JSON result comes before other PDF tools. `render-pdf`'s preflight has the setup details.
301
+
293
302
  #### Installing the skills
294
303
 
295
304
  The plugin is not in a central store: this repository is its own Claude Code marketplace
@@ -361,6 +370,22 @@ shapes; a spec (`spec/unit/claude_plugin_spec.rb`) checks every command, option,
361
370
  method they name against the gem, so they cannot drift from it. The plugin is not part of the gem
362
371
  itself.
363
372
 
373
+ #### In Codex
374
+
375
+ The same six skills install in OpenAI's Codex. Codex reads the plugin folder through its portable manifest
376
+ (`claude-plugin/plugin.json`, Agent Plugins 1.0.0, listing under `extensions.com.openai`) and the repository's
377
+ own marketplace, `.agents/plugins/marketplace.json`:
378
+
379
+ ```bash
380
+ codex plugin marketplace add dieter-medium/bidi2pdf # follows the default branch
381
+ codex plugin marketplace add dieter-medium/bidi2pdf@v<version> # pinned to a release tag (or a commit SHA)
382
+ ```
383
+
384
+ Then install **bidi2pdf** from that marketplace in Codex's plugin browser (`/plugins` in the CLI, or the
385
+ Plugins Directory in the desktop app) and start a new session. The marketplace entry offers the plugin for Codex
386
+ only (`"products": ["CODEX"]`, as in OpenAI's own marketplace): the skills run `bidi2pdf` in a shell, which
387
+ ChatGPT does not have. `codex plugin marketplace upgrade bidi2pdf` fetches a newer state of the marketplace.
388
+
364
389
  ---
365
390
 
366
391
  ## ๐Ÿง  Programmatic API
@@ -825,6 +850,61 @@ session becomes a leftover like any other. Only processes that share the registr
825
850
  each other's leases: give job workers in another container the same `registry_dir` on a shared
826
851
  volume. Sessions other tools opened have no lease; under `scope: :all` only `min_age` protects them.
827
852
 
853
+ **Forked processes (Puma workers).** The warmer belongs to the process that configured it. A child
854
+ forked after that - Rails boots the app, and with it the warmer, in Puma's master before it forks its
855
+ workers - does not use the copy it inherits: its threads did not survive the fork, and its slots,
856
+ WebSocket connections included, are the parent's (a render on one used to time out while the parent
857
+ took the answers). The child drops that copy - it closes only its own copies of the spare slots'
858
+ sockets, locally, with no WebSocket close frame and no session end, so nothing of its parent's is
859
+ touched - and builds its own warmer. The parent keeps its warmer.
860
+
861
+ Without further setup the child builds it on its first render, and that render then waits for the
862
+ whole warm-up: `size` new Chrome sessions, one after the other. To warm each worker before it takes
863
+ requests:
864
+
865
+ ```ruby
866
+ # config/puma.rb
867
+ on_worker_boot do
868
+ Bidi2pdf::SessionWarmer.after_fork
869
+ end
870
+ ```
871
+
872
+ Every worker then holds `size` spares of its own, besides the master's: with `W` workers, `size * (W + 1)`
873
+ idle sessions after boot - 2 workers at `size = 1` keep 3 Chromes waiting - and during renders one more
874
+ per render in flight plus the replacements warming. Count them in when sizing the chromedriver
875
+ (`max_sessions`, its memory and its process limit).
876
+
877
+ Puma's master renders nothing. To keep it from holding warm sessions nobody uses, end its warmer before
878
+ it forks - at that point no worker exists yet, so no child holds a copy of those sessions:
879
+
880
+ ```ruby
881
+ # config/puma.rb
882
+ before_fork do
883
+ Bidi2pdf::SessionWarmer.shutdown
884
+ end
885
+ ```
886
+
887
+ With `fork_worker`, worker 0 serves requests and forks the other workers itself; `before_fork` runs only
888
+ in the master and does not cover those forks. Puma runs `before_refork` in worker 0 before it forks and
889
+ `after_refork` once the cycle is done, so end worker 0's warmer before and give it a new one after:
890
+
891
+ ```ruby
892
+ # config/puma.rb, with fork_worker
893
+ before_refork do
894
+ Bidi2pdf::SessionWarmer.shutdown
895
+ end
896
+
897
+ after_refork do
898
+ Bidi2pdf::SessionWarmer.after_fork # builds worker 0 a warmer of its own again
899
+ end
900
+ ```
901
+
902
+ The workers worker 0 forks run `on_worker_boot` like any other. A render still in flight in worker 0 when
903
+ it forks is fine: a child releases every slot it inherited - warm, out for a render, or being checked out
904
+ or retired - and a release that fails is logged while the others go on. Not covered is a session still
905
+ being built in the forking process at that instant: its socket copy in the child is left to garbage
906
+ collection (a file descriptor, nothing the child or the parent uses).
907
+
828
908
  **Last resort: pressure.** `sweep!(pressure: true)` closes every session nobody holds that is past
829
909
  `min_age`, without waiting for `orphan_age`, the unresponsive checks or the limit. `with_retry` does
830
910
  that when its block fails with a resource error - chromedriver refusing a session
@@ -82,6 +82,23 @@ module Bidi2pdf
82
82
  end
83
83
  end
84
84
 
85
+ # In a forked child: drops this process's copy of a connection the parent opened, without a word
86
+ # to the peer - no close frame, no TLS close_notify (the underlying TCP socket is closed, not the
87
+ # SSL one), no :close event - so the parent goes on using it. Closing a descriptor the parent also
88
+ # holds ends nothing for the peer; the reader thread did not survive the fork.
89
+ def release_after_fork
90
+ @close_monitor.synchronize do
91
+ return if @closed
92
+
93
+ @closed = true
94
+ io = @socket.respond_to?(:to_io) ? @socket.to_io : @socket
95
+ io&.close unless io.nil? || io.closed?
96
+ @socket = nil
97
+ end
98
+ rescue IOError, SystemCallError
99
+ nil
100
+ end
101
+
85
102
  def open? = @handshaked && !@closed
86
103
 
87
104
  def closed? = @closed
@@ -154,6 +154,12 @@ module Bidi2pdf
154
154
  end
155
155
 
156
156
  # Closes the WebSocket connection.
157
+ # In a forked child: lets go of the parent's connection locally (BufferedWebSocketClient#release_after_fork).
158
+ def release_after_fork
159
+ @socket&.release_after_fork
160
+ @socket = nil
161
+ end
162
+
157
163
  def close
158
164
  return unless @socket
159
165
 
@@ -167,6 +167,14 @@ module Bidi2pdf
167
167
  end
168
168
  end
169
169
 
170
+ # In a forked child: drops this process's copies of the parent's connections - the command client
171
+ # and the event socket - without ending the session, which is the parent's (see #close for that).
172
+ def release_after_fork
173
+ @client&.release_after_fork
174
+ @event_socket&.release_after_fork
175
+ @client = @event_socket = nil
176
+ end
177
+
170
178
  private
171
179
 
172
180
  # Sends a command to the WebSocket client.
@@ -157,11 +157,13 @@ module Bidi2pdf
157
157
  def configure
158
158
  @config = Configuration.new
159
159
  yield @config if block_given?
160
+ abandon_inherited_instance
160
161
  @instance&.shutdown
161
162
  # Cleared first: if the constructor below raises, a stale, already-shut-down instance must
162
163
  # not stay registered (it would keep serving cold slots but never warm again).
163
164
  @instance = nil
164
165
  @instance = new(@config, slot_factory: @config.slot_factory)
166
+ @instance_pid = Process.pid
165
167
  end
166
168
 
167
169
  # Returns the warmer's configuration, initializing defaults if needed.
@@ -197,9 +199,18 @@ module Bidi2pdf
197
199
  Bidi2pdf.logger.warn "session_warmer: error closing #{label}: #{e.message}"
198
200
  end
199
201
 
200
- # Returns the shared singleton warmer instance, creating it (and pre-warming it) on first call.
202
+ # Returns the shared singleton warmer instance, creating it (and pre-warming it) on first call -
203
+ # and in a forked child, its own one instead of the copy it inherited (see
204
+ # #abandon_inherited_instance).
201
205
  def instance
202
- @instance ||= new(config, slot_factory: config.slot_factory)
206
+ abandon_inherited_instance
207
+ @instance ||= new(config, slot_factory: config.slot_factory).tap { @instance_pid = Process.pid }
208
+ end
209
+
210
+ # Warms this process's own slots now - for a forked child (a Puma worker's on_worker_boot), so
211
+ # its first render does not pay for them. Without it the child warms on its first render.
212
+ def after_fork
213
+ instance
203
214
  end
204
215
 
205
216
  # Checks out a slot, yields a fresh tab for one render, then retires the slot.
@@ -210,17 +221,37 @@ module Bidi2pdf
210
221
  # Sweeps the remote chromedriver with the configured sweeper; nil when there is none (or no
211
222
  # warmer yet - this never creates one).
212
223
  def sweep!(reason: :manual)
224
+ abandon_inherited_instance
213
225
  @instance&.sweep!(reason: reason)
214
226
  end
215
227
 
216
- # Retires every currently-warm spare and resets the singleton.
228
+ # Retires every currently-warm spare and resets the singleton. In a forked child it only drops
229
+ # the inherited copy: those spares are the parent's.
217
230
  def shutdown
231
+ abandon_inherited_instance
218
232
  @instance&.shutdown
219
233
  @instance = nil
220
234
  end
221
235
 
222
236
  private
223
237
 
238
+ # The instance belongs to the process that created it. A forked child (a Puma worker - Rails
239
+ # boots the app, and with it this warmer, in the master before the fork) inherits a copy whose
240
+ # threads did not survive the fork and whose slots are its parent's, WebSocket connections
241
+ # included: a render on one sent its commands down the parent's socket, the parent's reader
242
+ # thread took the answers ("Unknown response"), and the child timed out. So the child lets go
243
+ # of its copy - closing only its own copies of the spare slots' sockets, never their sessions,
244
+ # which are its parent's (#release_after_fork) - and builds its own from the same
245
+ # configuration.
246
+ def abandon_inherited_instance
247
+ return if @instance.nil? || @instance_pid == Process.pid
248
+
249
+ inherited = @instance
250
+ @instance = nil
251
+ @instance_pid = nil
252
+ inherited.release_after_fork
253
+ end
254
+
224
255
  # Records each part in +parts+ the moment it exists, so #default_slot_factory's rescue can
225
256
  # retire exactly what was created so far. Mirrors Launcher#session's local/remote branch.
226
257
  def build_slot(config, parts)
@@ -250,6 +281,9 @@ module Bidi2pdf
250
281
  @slot_factory = slot_factory || self.class.default_slot_factory(config)
251
282
  @mutex = Mutex.new
252
283
  @available = []
284
+ # Every slot from its creation to its retirement - warm, out for a render, or in between - so a
285
+ # forked child can let go of all of them (#release_after_fork).
286
+ @live = []
253
287
  @replenish_threads = []
254
288
  @warming = 0
255
289
  @shutdown = false
@@ -262,6 +296,29 @@ module Bidi2pdf
262
296
  start_background_work
263
297
  end
264
298
 
299
+ # In a forked child, for the copy it inherited: closes the child's copies of the sockets of every
300
+ # slot the parent had - warm, out for a render, or between the two (being checked out, being
301
+ # retired) - locally (Session#release_after_fork: no close frame, no session end), and forgets the
302
+ # slots. The parent's sessions, its renders in flight, its leases and its threads are untouched.
303
+ # One slot that fails to release does not stop the others. The warmer itself is unusable
304
+ # afterwards - .instance builds the child its own.
305
+ #
306
+ # Not covered: a session still being built when the parent forked - between chromedriver's
307
+ # answer and #create_slot listing it, a fraction of a second. Its socket copy in the child is left
308
+ # to garbage collection. That needs a fork from a process that is building a slot on another
309
+ # thread at that moment; Puma's master never renders, so its forks do not meet it.
310
+ def release_after_fork
311
+ inherited = @live.dup
312
+ @available = []
313
+ @live = []
314
+ inherited.each do |slot|
315
+ session = slot[:session]
316
+ session.release_after_fork if session.respond_to?(:release_after_fork)
317
+ rescue StandardError => e
318
+ Bidi2pdf.logger.warn "session_warmer: releasing an inherited slot failed: #{e.message}"
319
+ end
320
+ end
321
+
265
322
  # Sweeps the remote chromedriver now - for an application that suspects leaked sessions.
266
323
  #
267
324
  # @return [ChromeSweeper::Result, nil] nil when no sweeper is configured.
@@ -381,7 +438,10 @@ module Bidi2pdf
381
438
  slot = new_slot
382
439
  id = session_id_of(slot)
383
440
  @registry&.hold(id)
384
- @mutex.synchronize { @own_sessions << id } if id
441
+ @mutex.synchronize do
442
+ @own_sessions << id if id
443
+ @live << slot
444
+ end
385
445
  slot
386
446
  end
387
447
 
@@ -563,7 +623,10 @@ module Bidi2pdf
563
623
  self.class.retire_slot(session: slot[:session], manager: slot[:manager])
564
624
  id = session_id_of(slot)
565
625
  @registry&.forget(id)
566
- @mutex.synchronize { @own_sessions.delete(id) }
626
+ @mutex.synchronize do
627
+ @own_sessions.delete(id)
628
+ @live.delete_if { |live| live.equal?(slot) }
629
+ end
567
630
  end
568
631
 
569
632
  def safe_close(label, &)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bidi2pdf
4
- VERSION = "0.1.23"
4
+ VERSION = "0.1.25"
5
5
  end
data/lib/bidi2pdf.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "concurrent-ruby"
4
4
  require "logger"
5
5
 
6
+ require_relative "bidi2pdf/version"
6
7
  require_relative "bidi2pdf/process_tree"
7
8
  require_relative "bidi2pdf/launcher"
8
9
  require_relative "bidi2pdf/bidi/session"
@@ -193,7 +194,9 @@ module Bidi2pdf # rubocop:disable Metrics/ModuleLength
193
194
  rescue LoadError => e
194
195
  raise unless e.message =~ /websocket-native/
195
196
 
196
- logger.warn "websocket-native not available; installing it may enhance performance."
197
+ # Debug, not warn: this runs while the library loads, before the CLI moves logs off stdout, and a
198
+ # missing optional speed-up is no problem to report on every run.
199
+ logger.debug "websocket-native not available; installing it may enhance performance."
197
200
  end
198
201
  end
199
202
 
@@ -51,6 +51,12 @@ module Bidi2pdf
51
51
  # nor be killed before :close has been emitted.
52
52
  def close: (?untyped? error) -> untyped
53
53
 
54
+ # In a forked child: drops this process's copy of a connection the parent opened, without a word
55
+ # to the peer - no close frame, no TLS close_notify (the underlying TCP socket is closed, not the
56
+ # SSL one), no :close event - so the parent goes on using it. Closing a descriptor the parent also
57
+ # holds ends nothing for the peer; the reader thread did not survive the fork.
58
+ def release_after_fork: () -> untyped
59
+
54
60
  def open?: () -> untyped
55
61
 
56
62
  def closed?: () -> untyped
@@ -114,6 +114,9 @@ module Bidi2pdf
114
114
  def remove_event_listener: (*untyped names, untyped listener) -> untyped
115
115
 
116
116
  # Closes the WebSocket connection.
117
+ # In a forked child: lets go of the parent's connection locally (BufferedWebSocketClient#release_after_fork).
118
+ def release_after_fork: () -> untyped
119
+
117
120
  def close: () -> (nil | untyped)
118
121
 
119
122
  private
@@ -101,6 +101,10 @@ module Bidi2pdf
101
101
  # @return [String] The WebSocket URL.
102
102
  def websocket_url: () -> untyped
103
103
 
104
+ # In a forked child: drops this process's copies of the parent's connections - the command client
105
+ # and the event socket - without ending the session, which is the parent's (see #close for that).
106
+ def release_after_fork: () -> untyped
107
+
104
108
  private
105
109
 
106
110
  # Sends a command to the WebSocket client.
@@ -26,6 +26,8 @@ module Bidi2pdf
26
26
  # not stay registered (it would keep serving cold slots but never warm again).
27
27
  self.@instance: untyped
28
28
 
29
+ self.@instance_pid: untyped
30
+
29
31
  @config: untyped
30
32
 
31
33
  @slot_factory: untyped
@@ -34,6 +36,10 @@ module Bidi2pdf
34
36
 
35
37
  @available: untyped
36
38
 
39
+ # Every slot from its creation to its retirement - warm, out for a render, or in between - so a
40
+ # forked child can let go of all of them (#release_after_fork).
41
+ @live: untyped
42
+
37
43
  @replenish_threads: untyped
38
44
 
39
45
  @warming: untyped
@@ -180,9 +186,15 @@ module Bidi2pdf
180
186
 
181
187
  def self.safe_close: (untyped label) { () -> untyped } -> untyped
182
188
 
183
- # Returns the shared singleton warmer instance, creating it (and pre-warming it) on first call.
189
+ # Returns the shared singleton warmer instance, creating it (and pre-warming it) on first call -
190
+ # and in a forked child, its own one instead of the copy it inherited (see
191
+ # #abandon_inherited_instance).
184
192
  def self.instance: () -> untyped
185
193
 
194
+ # Warms this process's own slots now - for a forked child (a Puma worker's on_worker_boot), so
195
+ # its first render does not pay for them. Without it the child warms on its first render.
196
+ def self.after_fork: () -> untyped
197
+
186
198
  # Checks out a slot, yields a fresh tab for one render, then retires the slot.
187
199
  def self.with_tab: () { (?) -> untyped } -> untyped
188
200
 
@@ -190,11 +202,22 @@ module Bidi2pdf
190
202
  # warmer yet - this never creates one).
191
203
  def self.sweep!: (?reason: ::Symbol) -> untyped
192
204
 
193
- # Retires every currently-warm spare and resets the singleton.
205
+ # Retires every currently-warm spare and resets the singleton. In a forked child it only drops
206
+ # the inherited copy: those spares are the parent's.
194
207
  def self.shutdown: () -> untyped
195
208
 
196
209
  private
197
210
 
211
+ # The instance belongs to the process that created it. A forked child (a Puma worker - Rails
212
+ # boots the app, and with it this warmer, in the master before the fork) inherits a copy whose
213
+ # threads did not survive the fork and whose slots are its parent's, WebSocket connections
214
+ # included: a render on one sent its commands down the parent's socket, the parent's reader
215
+ # thread took the answers ("Unknown response"), and the child timed out. So the child lets go
216
+ # of its copy - closing only its own copies of the spare slots' sockets, never their sessions,
217
+ # which are its parent's (#release_after_fork) - and builds its own from the same
218
+ # configuration.
219
+ def self.abandon_inherited_instance: () -> (nil | untyped)
220
+
198
221
  # Records each part in +parts+ the moment it exists, so #default_slot_factory's rescue can
199
222
  # retire exactly what was created so far. Mirrors Launcher#session's local/remote branch.
200
223
  def self.build_slot: (untyped config, untyped parts) -> { session: untyped, browser: untyped, manager: untyped }
@@ -207,6 +230,19 @@ module Bidi2pdf
207
230
 
208
231
  def initialize: (untyped config, ?slot_factory: untyped?) -> void
209
232
 
233
+ # In a forked child, for the copy it inherited: closes the child's copies of the sockets of every
234
+ # slot the parent had - warm, out for a render, or between the two (being checked out, being
235
+ # retired) - locally (Session#release_after_fork: no close frame, no session end), and forgets the
236
+ # slots. The parent's sessions, its renders in flight, its leases and its threads are untouched.
237
+ # One slot that fails to release does not stop the others. The warmer itself is unusable
238
+ # afterwards - .instance builds the child its own.
239
+ #
240
+ # Not covered: a session still being built when the parent forked - between chromedriver's
241
+ # answer and #create_slot listing it, a fraction of a second. Its socket copy in the child is left
242
+ # to garbage collection. That needs a fork from a process that is building a slot on another
243
+ # thread at that moment; Puma's master never renders, so its forks do not meet it.
244
+ def release_after_fork: () -> untyped
245
+
210
246
  # Sweeps the remote chromedriver now - for an application that suspects leaked sessions.
211
247
  #
212
248
  # @return [ChromeSweeper::Result, nil] nil when no sweeper is configured.
@@ -1,3 +1,3 @@
1
1
  module Bidi2pdf
2
- VERSION: "0.1.23"
2
+ VERSION: "0.1.25"
3
3
  end
data/site/index.html ADDED
@@ -0,0 +1,135 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>bidi2pdf โ€“ HTML to PDF with Chrome's BiDi protocol, for scripts, CI and AI agents</title>
7
+ <meta name="description" content="bidi2pdf is an open-source Ruby gem and CLI that converts web pages and HTML to PDF with headless Chrome over WebDriver BiDi โ€“ for Ruby and Rails apps, CI pipelines and AI agents: JSON results, stable exit codes, page diagnosis and declarative recipes.">
8
+ <link rel="canonical" href="https://dieter-medium.github.io/bidi2pdf/">
9
+ <link rel="alternate" type="text/plain" href="llms.txt" title="llms.txt">
10
+ <link rel="icon" type="image/png" href="icon.png">
11
+ <meta property="og:type" content="website">
12
+ <meta property="og:title" content="bidi2pdf โ€“ HTML to PDF for scripts, CI and AI agents">
13
+ <meta property="og:description" content="Render URLs and HTML to PDF with headless Chrome over WebDriver BiDi: JSON output, exit codes, JSON Schemas, diagnosis and recipes.">
14
+ <meta property="og:url" content="https://dieter-medium.github.io/bidi2pdf/">
15
+ <meta property="og:image" content="https://dieter-medium.github.io/bidi2pdf/icon.png">
16
+ <script type="application/ld+json">
17
+ {
18
+ "@context": "https://schema.org",
19
+ "@type": "SoftwareSourceCode",
20
+ "name": "bidi2pdf",
21
+ "description": "A Ruby gem and CLI that renders URLs and HTML to PDF and screenshots with headless Chrome over WebDriver BiDi, with structured JSON output for scripts, CI and AI agents.",
22
+ "codeRepository": "https://github.com/dieter-medium/bidi2pdf",
23
+ "programmingLanguage": "Ruby",
24
+ "runtimePlatform": "Ruby 3.4 or later, Chrome or Chromium",
25
+ "license": "https://opensource.org/licenses/MIT",
26
+ "url": "https://dieter-medium.github.io/bidi2pdf/",
27
+ "keywords": ["HTML to PDF", "PDF generation", "headless Chrome", "WebDriver BiDi", "CLI", "Ruby", "Rails", "AI agents", "Claude Code"]
28
+ }
29
+ </script>
30
+ <style>
31
+ :root { color-scheme: light dark; --bg: #fffce6; --fg: #1b1b18; --muted: #55534a; --accent: #b23a26; --panel: #fff8d6; --line: #e7dfb5; }
32
+ @media (prefers-color-scheme: dark) {
33
+ :root { --bg: #16150f; --fg: #f3f0dc; --muted: #c4c0a8; --accent: #f08a73; --panel: #22201a; --line: #3a372c; }
34
+ }
35
+ * { box-sizing: border-box; }
36
+ body { margin: 0; background: var(--bg); color: var(--fg); font: 1.0625rem/1.6 system-ui, -apple-system, "Segoe UI", sans-serif; }
37
+ main { max-width: 46rem; margin: 0 auto; padding: 2.5rem 1rem 4rem; }
38
+ header { display: flex; align-items: center; gap: 1rem; }
39
+ header img { width: 4rem; height: 4rem; border-radius: 0.75rem; }
40
+ h1 { font-size: 2rem; line-height: 1.2; margin: 0; }
41
+ .lead { font-size: 1.15rem; color: var(--muted); }
42
+ h2 { font-size: 1.35rem; margin: 2.5rem 0 0.75rem; }
43
+ a { color: var(--accent); }
44
+ a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
45
+ ul { padding-left: 1.25rem; }
46
+ li { margin: 0.4rem 0; }
47
+ pre { background: var(--panel); border: 1px solid var(--line); border-radius: 0.5rem; padding: 0.9rem 1rem; overflow-x: auto; font-size: 0.9rem; line-height: 1.5; }
48
+ code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
49
+ table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
50
+ th, td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
51
+ footer { margin-top: 3rem; color: var(--muted); font-size: 0.95rem; }
52
+ @media (max-width: 30rem) {
53
+ header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
54
+ h1 { font-size: 1.6rem; }
55
+ }
56
+ .visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
57
+ </style>
58
+ </head>
59
+ <body>
60
+ <main>
61
+ <header>
62
+ <img src="icon.png" alt="" width="64" height="64">
63
+ <h1>HTML to PDF in Ruby, with headless Chrome and WebDriver BiDi</h1>
64
+ </header>
65
+ <p class="lead"><strong>bidi2pdf</strong> is an open-source Ruby gem and command-line tool that turns web pages and HTML into PDFs. It is built for developers, CI pipelines and AI coding agents that need PDF generation they can script: structured JSON results, predictable exit codes and rendering by a real browser.</p>
66
+
67
+ <h2 id="use-cases">What it does</h2>
68
+ <ul>
69
+ <li><strong>A web page or HTML file to PDF</strong> from the command line, with waits for page load or network idle, cookies, headers and basic auth.</li>
70
+ <li><strong>HTML in, PDF out</strong>: <code>--stdin</code> and <code>--output -</code> pipe without an input or output file of your own. The PDF goes straight to stdout; the piped HTML is kept in a temporary file while Chrome loads it, then deleted.</li>
71
+ <li><strong>Automation and agents</strong>: with <code>--json</code>, stdout carries exactly one JSON document per call; failures come back in the same shape with a structured error and a stable exit code; the JSON Schema of every shape is built in.</li>
72
+ <li><strong>Why does the PDF not look like the page?</strong> <code>bidi2pdf diagnose</code> reports console errors, failed requests, font loading, print rules and Paged.js โ€“ without producing a PDF.</li>
73
+ <li><strong>Pages that need steps before printing</strong>: declarative recipes, validated without launching a browser.</li>
74
+ <li><strong>Screen, dark and mobile views</strong> of a page as PDF (<code>--media</code>, <code>--color_scheme</code>), and screenshots through the Ruby API, for review.</li>
75
+ <li><strong>A shared remote Chrome</strong> for several processes โ€“ Puma workers, job workers โ€“ with pre-warmed sessions and a sweeper for leaked ones.</li>
76
+ <li><strong>Ruby and Rails</strong>: a programmatic API and DSL, <a href="https://github.com/dieter-medium/bidi2pdf-rails">bidi2pdf-rails</a> for <code>render pdf:</code> in controllers, and RSpec matchers for PDF specs.</li>
77
+ </ul>
78
+
79
+ <h2 id="quick-start">Quick start</h2>
80
+ <pre tabindex="0"><code>gem install bidi2pdf
81
+ bidi2pdf render --url https://example.com --output example.pdf</code></pre>
82
+ <p>Requires Ruby 3.4 or later and Chrome or Chromium โ€“ or use the published Docker image.</p>
83
+
84
+ <h2 id="tasks">Common tasks</h2>
85
+ <ul>
86
+ <li><strong>Generate PDFs in Ruby or Rails</strong> โ€“ reports, invoices and other HTML templates, rendered by headless Chrome: <a href="https://github.com/dieter-medium/bidi2pdf-rails">bidi2pdf-rails</a> gives controllers <code>render pdf:</code>; plain Ruby uses the gem's API.</li>
87
+ <li><strong>Convert HTML to PDF in CI</strong> โ€“ one command, then read <code>ok</code> and the exit code instead of parsing logs:
88
+ <pre tabindex="0"><code>bidi2pdf render --html-file report.html --output report.pdf --json</code></pre></li>
89
+ <li><strong>Debug a PDF that looks wrong</strong> โ€“ missing fonts, failed requests, print CSS, JavaScript errors, without producing a PDF:
90
+ <pre tabindex="0"><code>bidi2pdf diagnose --url https://example.com/invoice --json</code></pre></li>
91
+ </ul>
92
+
93
+ <h2 id="when">When to use bidi2pdf</h2>
94
+ <p>It fits when the PDF should look like the page does in a browser โ€“ modern CSS, web fonts, content a script renders, Paged.js print layouts โ€“ because Chrome itself renders it; when PDFs are made unattended, in CI, background jobs or by an agent, and a failure has to say what went wrong; and when the code around it is Ruby or Rails, or several processes share one remote Chrome.</p>
95
+ <p>Something else fits better when the PDF is drawn in code rather than from HTML โ€“ a PDF library does that without a browser โ€“ or where neither Chrome nor Docker can run.</p>
96
+
97
+ <h2 id="agents">For agents and CI</h2>
98
+ <pre tabindex="0"><code># check compatibility - no browser launched
99
+ bidi2pdf version --json
100
+
101
+ # discover the shape of every result
102
+ bidi2pdf schema render
103
+
104
+ # validate a recipe without a browser, then run it
105
+ bidi2pdf run recipe.yml --validate
106
+ bidi2pdf run recipe.yml --json
107
+
108
+ # render with a machine-readable result
109
+ bidi2pdf render --url https://example.com --output example.pdf --json</code></pre>
110
+ <table>
111
+ <caption class="visually-hidden">Exit codes</caption>
112
+ <thead><tr><th scope="col">Exit code</th><th scope="col">Meaning</th></tr></thead>
113
+ <tbody>
114
+ <tr><td><code>0</code></td><td>success</td></tr>
115
+ <tr><td><code>2</code></td><td>CLI, configuration or recipe-validation error</td></tr>
116
+ <tr><td><code>3</code></td><td>browser or navigation error</td></tr>
117
+ <tr><td><code>4</code></td><td>page not as expected (a recipe action or assertion, or a diagnose selector, failed)</td></tr>
118
+ <tr><td><code>6</code></td><td>output or PDF generation failure</td></tr>
119
+ <tr><td><code>70</code></td><td>unexpected internal error</td></tr>
120
+ </tbody>
121
+ </table>
122
+ <p>Details: <a href="https://github.com/dieter-medium/bidi2pdf#structured-render-output">structured output</a>, <a href="https://github.com/dieter-medium/bidi2pdf#stdinstdout-manifests-and-progress-streaming">stdin/stdout and progress events</a>, <a href="https://github.com/dieter-medium/bidi2pdf#diagnosing-a-page-before-trusting-its-pdf">diagnose</a>, <a href="https://github.com/dieter-medium/bidi2pdf#declarative-recipes">recipes</a>. A plain-text summary for language models: <a href="llms.txt">llms.txt</a>.</p>
123
+
124
+ <h2 id="claude-code">Claude Code plugin</h2>
125
+ <p>Six skills teach an agent to use bidi2pdf as intended: rendering, recipes, diagnosing a wrong PDF, a shared remote Chrome, review screenshots and PDF specs.</p>
126
+ <pre tabindex="0"><code>/plugin marketplace add dieter-medium/bidi2pdf
127
+ /plugin install bidi2pdf@bidi2pdf</code></pre>
128
+ <p><a href="https://github.com/dieter-medium/bidi2pdf#claude-code-skills">About the skills</a></p>
129
+
130
+ <footer>
131
+ <p><a href="https://github.com/dieter-medium/bidi2pdf">Source on GitHub</a> ยท <a href="https://rubygems.org/gems/bidi2pdf">RubyGems</a> ยท <a href="https://github.com/dieter-medium/bidi2pdf/blob/main/CHANGELOG.md">Changelog</a> ยท MIT License</p>
132
+ </footer>
133
+ </main>
134
+ </body>
135
+ </html>
data/site/llms.txt ADDED
@@ -0,0 +1,22 @@
1
+ # bidi2pdf
2
+
3
+ > bidi2pdf is a Ruby gem and CLI that renders a URL or HTML to PDF with headless Chrome over WebDriver BiDi. It is built to be driven by scripts, CI and AI agents: with `--json` every call writes exactly one JSON document to stdout, failures come back in the same shape with a structured error and a stable exit code, and the JSON Schema of every result is built into the CLI.
4
+
5
+ Use it to: render a web page or HTML file to PDF (`bidi2pdf render --url https://example.com --output example.pdf`); pipe HTML in and PDF out (`--stdin`, `--output -`); find out why a PDF does not look like the page (`bidi2pdf diagnose`); print pages that need steps first with declarative recipes, validated without a browser (`bidi2pdf run recipe.yml --validate`); print screen, dark or mobile views (`--media`, `--color_scheme`); share one remote Chrome between processes with pre-warmed sessions; render from Ruby, Rails (bidi2pdf-rails) and RSpec.
6
+
7
+ Start with `bidi2pdf version --json` (no browser launched), then `bidi2pdf schema render`, `bidi2pdf schema diagnose`, `bidi2pdf schema run` or `bidi2pdf schema recipe` for the shape of a result or a recipe. Exit codes: 0 success, 2 CLI/configuration/recipe-validation error, 3 browser or navigation error, 4 page not as expected, 6 output or PDF generation failure, 70 unexpected internal error. Requires Ruby 3.4 or later and Chrome or Chromium; a Docker image is published.
8
+
9
+ ## Docs
10
+
11
+ - [README](https://github.com/dieter-medium/bidi2pdf#readme): installation, CLI, library API, Docker, configuration
12
+ - [Structured render output](https://github.com/dieter-medium/bidi2pdf#structured-render-output): the JSON result and exit codes
13
+ - [stdin/stdout, manifests and progress streaming](https://github.com/dieter-medium/bidi2pdf#stdinstdout-manifests-and-progress-streaming): piping, render manifests, NDJSON progress events
14
+ - [Diagnosing a page](https://github.com/dieter-medium/bidi2pdf#diagnosing-a-page-before-trusting-its-pdf): console errors, failed requests, fonts, print rules, Paged.js
15
+ - [Declarative recipes](https://github.com/dieter-medium/bidi2pdf#declarative-recipes): waits and PDF assertions as a YAML contract
16
+ - [Claude Code skills](https://github.com/dieter-medium/bidi2pdf#claude-code-skills): the plugin with six skills and how to install it
17
+
18
+ ## Optional
19
+
20
+ - [Rails integration](https://github.com/dieter-medium/bidi2pdf-rails): `render pdf:` in controllers
21
+ - [Changelog](https://github.com/dieter-medium/bidi2pdf/blob/main/CHANGELOG.md)
22
+ - [RubyGems](https://rubygems.org/gems/bidi2pdf)
data/site/sitemap.xml ADDED
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
+ <url><loc>https://dieter-medium.github.io/bidi2pdf/</loc></url>
4
+ <url><loc>https://dieter-medium.github.io/bidi2pdf/llms.txt</loc></url>
5
+ </urlset>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bidi2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter S.
@@ -391,6 +391,7 @@ executables:
391
391
  extensions: []
392
392
  extra_rdoc_files: []
393
393
  files:
394
+ - ".agents/plugins/marketplace.json"
394
395
  - ".devcontainer/Dockerfile"
395
396
  - ".devcontainer/devcontainer.json"
396
397
  - ".devcontainer/docker-compose.yml"
@@ -632,6 +633,9 @@ files:
632
633
  - sig/bidi2pdf/verbose_logger.rbs
633
634
  - sig/bidi2pdf/version.rbs
634
635
  - sig/vendor/thor.rbs
636
+ - site/index.html
637
+ - site/llms.txt
638
+ - site/sitemap.xml
635
639
  - tasks/changelog.rake
636
640
  - tasks/coverage.rake
637
641
  - tasks/generate_rbs.rake