Skip to content

2026.9.28.1: interface update_packages reports its progress, and nothing but NDJSON reaches stdout - #625

Merged
Sunrisepeak merged 2 commits into
mainfrom
feat/interface-index-progress
Sep 27, 2026
Merged

Sunrisepeak merged 2 commits into
mainfrom
feat/interface-index-progress

Conversation

@speak-agent

Copy link
Copy Markdown
Collaborator

Summary

xlings interface update_packages now reports its work as NDJSON events. No capability run through xlings interface writes anything but NDJSON to stdout. The interface protocol becomes 1.2, which is additive, and the version becomes 2026.9.28.1.

What was wrong

Measured with xlings 2026.9.27.1:

  • No progress for an index refresh. xlings interface update_packages --args '{}' emitted only heartbeat events and the final result. A refresh of several seconds therefore gave a client nothing to show.
  • Terminal text on the NDJSON stream. Whenever the index cache was rebuilt, lines such as [1/7] awesome::xim.lua\x1b[K appeared on stdout. The text comes from the pkgindex-build.lua script that ships inside an index repository: libxpkg's run_pkgindex_build runs it with the real io library, and its progress() writes to fd 1 directly. The protocol forbids this output, and it reached install_packages as well, which rebuilds the cache on first use.

Change

  • platform::StdoutCapture. It redirects fd 1 into a pipe for the duration of one capability's execution. InterfaceSession writes NDJSON through a duplicate of fd 1 taken before any capture, so the protocol's own output cannot be captured. A captured [i/n] <message> line becomes a progress event with phase index_rebuild; any other captured line goes to stderr. The capture wraps every capability, so the protection does not depend on the one script.
  • cmd_update progress. It emits a progress event with phase index_sync for each repository it syncs, i/n within its group. It emits a download_progress data event with the same files[] shape as install_packages while an index artifact downloads with known bytes. The callbacks are optional parameters of sync_all_repos, sync_one_repo and fetch_index_artifact, so no other caller changes.
  • Protocol document. docs/spec/interface-ndjson-v1.md gains the stdout rule (§5), the phases of update_packages (§6.1.1), the download_progress shape (§6.3.2), and version 1.2.

Consumer

mcpp (mcpp-community/mcpp#727) moves its index refresh from the bare xlings update to this interface, and renders the events with the same bar it uses for installs. Without these events it shows only its status line.

Tests

  • tests/e2e/interface_update_packages_progress_test.sh (E2E-122) builds an offline index fixture whose own pkgindex-build.lua reproduces the stray output. It asserts that every stdout line parses as JSON and that at least one progress event is emitted. It fails with the released 2026.9.27.1 and passes with this branch.
  • Also passing: mcpp test (58 unit tests, including the 26 InterfaceProtocol tests), interface_multi_repo_error_visibility_test.sh, tui_output_contract_test.sh (including the S6 glyph rule), update_package_test.sh, self_update_failure_test.sh, index_artifact_update_test.sh and custom_index_artifact_test.sh.
  • The Windows StdoutCapture branch (_pipe, _dup2, _read) is exercised by this PR's Windows CI.

…erface mode

`interface update_packages` reported no progress at all for an index
refresh, and when the refresh rebuilt a stale index cache it let a
downloaded pkgindex-build.lua's raw terminal text (carriage returns, ANSI
clear-to-end-of-line) straight onto stdout, breaking the NDJSON stream the
protocol requires there.

The text comes from libxpkg's plain-Lua build sandbox: run_pkgindex_build
executes the index repo's own pkgindex-build.lua with the real io library,
and that script's self-refreshing progress line writes directly to the
process's real stdout, bypassing every abstraction xlings routes through
platform::is_tui_mode(). It is data the index repo ships, not code this
repository owns, so the fix is at the boundary rather than in that script.

platform::StdoutCapture redirects the real fd 1 into a pipe for the
duration of a capability's execution and delivers whatever is written
there line by line; interface::run() installs it around every capability,
converting a recognisable "[i/n] ..." step into a progress event and
routing anything else to stderr. The NDJSON writer itself is decoupled
from fd 1 (InterfaceSession now writes through a duplicate taken before
any capture starts), so the protocol's own output is never captured along
with what this exists to catch. Because the guard sits around capability
execution rather than around one call site, install_packages benefits the
same way when its own first-run index rebuild hits the same script.

cmd_update also reports two new progress phases -- index_sync (one event
per repository, i/n within its group) and index_rebuild (from the
captured scan) -- and reuses install_packages' own download_progress data
event shape for an index artifact download's byte progress, so a client
renders both the same way.

Adds interface_update_packages_progress_test.sh (E2E-122): builds an
offline index fixture whose own pkgindex-build.lua reproduces the exact
defect shape, asserts every stdout line parses as JSON, and asserts at
least one progress event fires. Confirmed it fails against the released
2026.9.27.1 binary before this change and passes after.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants