…

WavePath.XCapture

Capture X (Twitter) posts into WavePath chat messages. A port of the Mattermost plugin mm-x-capture to WinterCMS: the same triggers, cards, honest results, cache and cost telemetry, attached to the chat message itself.

Features

Capture modes

Mode Hashtag Menu item Result
Single post #main-tweet, #t Single post One card for the linked post.
Author thread #main-thread, #mt Main thread The chain of posts from the same author (plus one context parent).
Full conversation #conversation, #c Full conversation The author's thread if there is one, otherwise the linked post and the replies X ranks highest.
Video #video, #v With video The card, then the video file from the post.
Retry #retry, #r Retry A new capture that ignores the cache.

Priority when a message carries several mode hashtags: full conversation, then author thread, then single post. #video and #retry are modifiers: #t #v, #mt #v, #c #v, #c #r all work, in any order. On its own, #v means a single post with video. A hashtag in a thread reply without its own link captures the nearest preceding X link in that thread.

The card, the PDF and the video land on the same message. The author's text stays untouched; the plugin appends a quote of the post and a "View post on X — Name (@handle)" permalink below it. Plugin edits never show "(edited)", and a captured message never shows the plain link preview.

The message menu

Anyone who can read a conversation can capture any message that holds an X link:

  • desktop: the message's 3-dot menu → Capture from X ▸ → one of the five modes;
  • narrow window / phone: five flat "Capture from X: …" rows in the actions sheet (the rows follow the viewport width, not the user agent).

The card attaches to that message; the capture is billed to the person who asked. A selection already captured on that message answers "already captured as …".

Remove capture

The author, or anyone the host lets delete messages in that conversation, can remove a capture (desktop: last item of the Capture from X submenu; mobile: the destructive row above Delete). Removal strips the quote and the permalink and deletes the capture's own card, PDF and video files — never the author's own attachments — without an "(edited)" marker. The same pick can be captured again afterwards. A later prose-only edit does not re-capture; changing the hashtag or adding #retry does.

Honest results

  • A deleted, suspended or protected post becomes an "unavailable" card. Nothing is invented.
  • A conversation that could not be read completely is marked as incomplete on the card.
  • A failed capture replaces the progress text with the Failure Text; the user's message is never blocked or lost.

X Articles

A native X Article gets a cover card (cover image, ARTICLE badge, headline) and the whole article as a PDF on the same message — at no extra API read. Below about 25 s of remaining capture budget the PDF is skipped and the card is still delivered.

Video

#v (or the With video menu item) downloads the post's video with yt-dlp / ffmpeg after the card is delivered. Video is never the only result: when the post has no video ("No video could be found in this tweet" from yt-dlp — mm-x-capture REPORT §4), the card is still delivered and only the video is missing.

Cache and cost control

One server-wide cache keyed by post and mode: the same post captured in another conversation reuses the stored card without a second API read. #retry is the only way to force a fresh read. Removing a capture keeps the cache entry.

Web UI (plugin web extensions)

The menu above ships entirely from this plugin; vue-wavepath-app has no XCapture code.

  • Declaration. Plugin::registerWebExtensions() declares one message action, capture ("Capture from X"), with the five mode items and the destructive Remove capture item with its confirm. Golem15.WavePath lists it at GET /_wave/api/v1/web-extensions with every label resolved from lang/{en,pl}/lang.php (web.*), and the SPA's generic renderer draws the desktop submenu, the mobile rows and the confirm from that data. The list carries XCapture only while the plugin is enabled.

  • Endpoints. The items call POST /_wave/api/v1/xcapture/web-actions/capture and …/web-actions/remove with exactly {message_id, conversation_id, value, locale}. They reuse the capture/remove core of the 106 endpoints, re-check every permission on the server and answer with server-localised toasts: accepted and removed are silent, a duplicate names the mode, every capture refusal is the same error toast, and a failed remove is one 404. The old /xcapture/messages/{id}/capture POST and DELETE routes stay for one release, because cached SPA shells (PWA, desktop) keep calling them until they reload.

  • Bundle. webapp/ holds the source of a tiny predicate bundle, built with the public SDK (defineWavePathPlugin in webapp/vite.config.ts). It registers only the two checks the declarative rules cannot express: capturable (the strict X status-URL test) and removable (a capture state other than removed). The built assets/webapp/main.js is committed.

    cd plugins/wavepath/xcapture/webapp
    npm ci              # .npmrc sets allow-git=root, which npm 12 needs for the SDK git tag
    npm run build       # writes ../assets/webapp/main.js; commit it
    npm run verify      # rebuilds into a temp dir and fails unless the committed bytes match
    npm test            # the predicate truth tables, run against the committed main.js
    npm run typecheck
    
  • Pinning. After changing the bundle, run php artisan wave:web-pin (it also runs automatically after php artisan winter:up), then php artisan wave:web-pin --check. The SPA loads the bundle only with its pinned SHA-256 integrity, so bytes changed without a re-pin are refused and the Capture from X items stay hidden.

Writing a plugin like this one: see the plugin-author guide in the wavepath-plugin-sdk README (git.golem15.com/jakub/wavepath-plugin-sdk).

Settings and telemetry

  • Settings → X Capture (wavepath.xcapture.manage_settings): capture timeout, In-Progress / Failure texts, conversation and author-thread limits, and the X read rates in microdollars. The page shows the credential status. There is no token field.
  • Settings → X Capture telemetry (wavepath.xcapture.view_telemetry): a read-only list of every capture (time, requester, conversation, mode, video, retry, source, post / user reads, cost, cache) with date / mode / cache / requester / video-only filters, a totals strip for the current filter, and per-day and per-user totals on the same page (the filtered date range, or the last 30 days). Rates are frozen per row, so a rate change applies to future captures only. DM rows never show participant names.

Operations

System packages

Need Debian / Ubuntu Arch
Headless Chromium chromium chromium
Video ffmpeg, yt-dlp ffmpeg, yt-dlp
Fonts (CJK, emoji, Arabic, Hebrew) fonts-noto-core fonts-noto-cjk fonts-noto-color-emoji noto-fonts noto-fonts-cjk noto-fonts-emoji
Inter (optional) fonts-inter inter-font

PHP needs ext-sockets; composer install brings chrome-php/chrome. Paths can be overridden with CHROMIUM_PATH, X_CAPTURE_YTDLP_PATH and X_CAPTURE_FFMPEG_PATH.

yt-dlp refresh path: X extractors break often and are fixed upstream quickly. Keep yt-dlp current through regular OS package updates (apt upgrade / pacman -Syu); xcapture:doctor prints its version and age in days.

The X API token

The token is read only from the X_CAPTURE_BEARER_TOKEN environment variable — never stored in the database, never shown in the backend, never logged. It must be in the worker's environment (the app .env, or the supervisor program's environment= line).

Supervisor gotcha (mm-x-capture REPORT §2): X bearer tokens are URL-encoded and contain % (%2F, %3D). Supervisor treats % as an interpolation marker, so every % must be written %% on the environment= line. Apply changes with:

supervisorctl reread && supervisorctl update

A plain supervisorctl restart keeps the stale program config in memory and the new token never reaches the worker.

Token rotation (REPORT §10): if the token was ever printed to a terminal or a log, rotate it in the X Developer Portal, update the .env / supervisor line (with %%), reload as above and run php artisan xcapture:probe.

The worker

Captures run on the dedicated xcapture queue connection (retry_after 300 s). Install deploy/supervisor/xcapture-worker.conf: two processes running queue:work xcapture --queue=xcapture --tries=1 --timeout=150, stopwaitsecs=180, stopasgroup / killasgroup on. The header of that file documents the timing contract.

For local development: php artisan queue:work xcapture --queue=xcapture.

Checks

  • php artisan xcapture:doctor [--json] [--no-worker] [--worker-timeout=10] — Chromium (version, a headless smoke render, orphaned processes reaped), ffmpeg, yt-dlp (version and age), the Noto fonts via fc-list (Inter optional), the token (present or not — never its value), ext-sockets, chrome-php, the timeout budget and a round trip through the xcapture worker that fails within --worker-timeout seconds when the worker is down. Exit 0 when every required check passes.
  • php artisan xcapture:probe — checks the token against X now and records healthy / degraded (scheduled every ten minutes).

Chromium processes

Every render uses a private headless Chromium profile owned by the worker process. A worker that dies mid-render leaves an orphan; the next capture (and xcapture:doctor) reaps every profile whose owner is gone. pgrep -fa xcapture/chrome should print nothing on an idle box.

Description
WavePath X Capture plugin (PHP port of mm-x-capture)
Readme 707 KiB
Languages
PHP 96.4%
Twig 1.7%
JavaScript 1%
HTML 0.6%
TypeScript 0.3%