Skip to content

spaced-host-client: move the client's methods into modules by guest area (pure move) - #571

Merged
ac-pplx merged 1 commit into
mainfrom
ac/split-spaced-host-client
Oct 16, 2026
Merged

ac-pplx merged 1 commit into
mainfrom
ac/split-spaced-host-client

Conversation

@ac-pplx

@ac-pplx ac-pplx commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

crates/libs/spaced/host/client/src/lib.rs (1,040 code lines) is the whole typed client for the spaced host API: its types, a call macro and constructors, then 40 methods across four guest services. This keeps the types, the macro and the constructors in lib.rs and moves the methods, with the helpers only they use, into impl SpacedHostClient blocks in five modules (filesystem calls and file watching are separate). lib.rs drops to 187 code lines; the largest new file is filesystem.rs at 316.

Every moved method is already pub and stays on SpacedHostClient, so the crate's API is unchanged. The macro-generated private call_* methods stay in lib.rs; child modules can call them because they are descendants of the crate root.

This is a pure move, generated by scripts/split_rust_module.py (#562) from the spec below and proved by its verify. It is part of splitting the largest production modules into smaller ones with one job each.

What moved where

Module Holds Code lines
meta Status, readiness and lifecycle calls to the guest agent, including the process environment it configures. 93
filesystem Filesystem calls: stat, list, read, write, mkdir, remove, rename and batched writes. 316
file_watch File watching and change tracking. 213
process Process calls: start, reconnect, list, signals, input, PTY resize and kill. 224
networking Loopback bridges between the host and the guest. 31
lib.rs (parent) the client's types, the call macro and its generated private callers, and the constructors 187

How to check it

The spec (item names, not lines):

file = "crates/libs/spaced/host/client/src/lib.rs"

[[module]]
name = "meta"
doc = "Status, readiness and lifecycle calls to the guest agent, including the process environment it configures."
items = [
  "impl SpacedHostClient :: fn ping",
  "impl SpacedHostClient :: fn is_connected",
  "impl SpacedHostClient :: fn ping_guest",
  "impl SpacedHostClient :: fn get_status",
  "impl SpacedHostClient :: fn wait_ready",
  "impl SpacedHostClient :: fn configure_process_env",
  "impl SpacedHostClient :: fn notify_resume",
  "impl SpacedHostClient :: fn prepare_suspend",
  "impl SpacedHostClient :: fn flush_guest_filesystems",
]

[[module]]
name = "filesystem"
allow_unused_reexport = true
doc = "Filesystem calls: stat, list, read, write, mkdir, remove, rename and batched writes."
items = [
  "fn idempotency_key_or_generated",
  "impl SpacedHostClient :: fn stat",
  "impl SpacedHostClient :: fn stat_as_user",
  "impl SpacedHostClient :: fn list_stream_with_depth_as_user",
  "impl SpacedHostClient :: fn read_stream_as_user",
  "impl SpacedHostClient :: fn write",
  "impl SpacedHostClient :: fn write_with_idempotency",
  "impl SpacedHostClient :: fn write_stream_with_idempotency",
  "impl SpacedHostClient :: fn mkdir",
  "impl SpacedHostClient :: fn remove",
  "impl SpacedHostClient :: fn remove_as_user",
  "impl SpacedHostClient :: fn rename_as_user",
  "impl SpacedHostClient :: fn write_batch_as_user",
]

[[module]]
name = "file_watch"
doc = "File watching and change tracking."
items = [
  "impl SpacedHostClient :: fn watch_stream",
  "impl SpacedHostClient :: fn watch_stream_with_options",
  "impl SpacedHostClient :: fn create_watcher_with_options",
  "impl SpacedHostClient :: fn normalize_watch_root_as_user",
  "impl SpacedHostClient :: fn get_watcher_events",
  "impl SpacedHostClient :: fn remove_watcher",
  "impl SpacedHostClient :: fn enable_file_changes_with_options_as_user",
  "impl SpacedHostClient :: fn disable_file_changes_as_user",
  "impl SpacedHostClient :: fn get_modified_files_as_user",
]

[[module]]
name = "process"
allow_unused_reexport = true
doc = "Process calls: start, reconnect, list, signals, input, PTY resize and kill."
items = [
  "const PROCESS_LIST_*", "fn connect_process_request",
  "impl SpacedHostClient :: fn start_process_stream_with_options",
  "impl SpacedHostClient :: fn connect_process_stream_with_cursor",
  "impl SpacedHostClient :: fn list_processes",
  "impl SpacedHostClient :: fn send_signal",
  "impl SpacedHostClient :: fn send_input",
  "impl SpacedHostClient :: fn close_stdin",
  "impl SpacedHostClient :: fn resize_pty",
  "impl SpacedHostClient :: fn kill_process",
]

[[module]]
name = "networking"
doc = "Loopback bridges between the host and the guest."
items = [
  "impl SpacedHostClient :: fn open_loopback_bridge",
  "impl SpacedHostClient :: fn close_loopback_bridge",
]

The tool is scripts/split_rust_module.py from #562 (not on main yet).

  • Regenerate: on main at b9fc395e0, run split_rust_module.py apply spec.toml && cargo fmt --all. This reproduces the first commit.
  • Proof: split_rust_module.py verify origin/main → regenerated and compared 6 files from 1 split parents: identical. verify derives the spec from the diff, regenerates the split from the merge base, and requires HEAD's Rust files to equal the rustfmt'd result byte for byte.
  • Edits inside moved text: 5 private items, fields or methods → pub(super); 40 methods moved into impl blocks with the same header. Each keeps the reach the item had: one module deeper, pub(super) reaches exactly the old module.

Observable changes

  • Log targets: none change; no moved event or span lacks an explicit target:.
  • Diagnostics: the moved methods contain no explicit panic macros, tracing callsites or sql!. A #[track_caller] panic raised by Tokio inside one (for example list_processes' timeout polled without a Tokio timer) now reports process.rs instead of lib.rs. rustdoc shows SpacedHostClient's methods in six impl sections instead of one, and std::any::type_name of a moved method's future names its new module.

Validation

Run on a Linux development machine at the PR head, in the CI image:

  • cargo check --workspace --all-targets --all-features --locked: pass, no warnings.
  • Every clippy invocation in run_clippy_checks with -D warnings: pass.
  • cargo check -p pplx-space-spaced-host-client --no-default-features --all-targets: pass.
  • cargo nextest run -p pplx-space-spaced-host-client --all-features: 3/3 passed; the crate needs no Postgres or privileges.
  • cargo doc -p pplx-space-spaced-host-client --no-deps: no warnings on the branch or on main. The SpacedHostClient page lists the same 62 methods on both.
  • archcheck as CI runs it: no required findings. The only new advisory finding is the stale file_size entry below.

Interactions

No open pull request touches spaced/host/client/src/lib.rs. Consumers are sbx-mgr, spaced-host-server and the spaced host CLI; the workspace check covers them.

Follow-ups, kept out of this PR because verify allows no other Rust edits: imports in lib.rs that only the child modules use could move to them.

The archcheck file_size baseline entry for this file is now stale (an advisory finding). Split PRs leave that table alone, so they don't conflict with each other there; one follow-up prunes the stale entries after they land.

Rollback

Revert the commit(s). No data, configuration, wire or public API change.

🤖 Generated with Claude Code

…rea (pure move)

lib.rs holds the whole typed client: its types, the call macro and
constructors, and 40 methods across four guest services. Keep the types,
the macro and the constructors in lib.rs and move the methods into impl
blocks in five child modules: meta, filesystem, file_watch, process and
networking, together with the helpers only those methods use.

Generated by scripts/split_rust_module.py (#562) from the spec in the
pull request. Items move verbatim. The only edits keep each item's
reach: 5 private items, fields or methods become pub(super). The parent
re-exports the moved items, so no caller changes.
@ac-pplx
ac-pplx force-pushed the ac/split-spaced-host-client branch from d0d20b0 to 6bc3804 Compare October 16, 2026 07:11
@ac-pplx ac-pplx changed the title spaced-host-client: split the client's methods by guest service (pure move) spaced-host-client: move the client's methods into modules by guest area (pure move) Oct 16, 2026
@ac-pplx
ac-pplx marked this pull request as ready for review October 16, 2026 14:49
@the-gigi-pplx

Copy link
Copy Markdown
Collaborator

Review

No findings.

Verified against 6bc3804168af7d694a6c3461a9f5adc7f590e3e4.

What I ran:

  • scripts/split_rust_module.py verify origin/main, using the script from PR scripts: add split_rust_module.py for mechanical, verifiable Rust module splits #562's head: identical, exit 0.
  • apply with the spec in this PR's body, run on the merge base and rustfmt'd: it reproduces every .rs file at the head byte for byte. So the glob patterns in the published spec select the same items as the expanded spec verify --print-spec derives.
  • Each moved child file, grepped for self::/super:: in doc comments. The tool doesn't rewrite comments, so a link like that would point one module off after the move. There are none.
  • The non-split files, grepped for comments that name the old file next to a moved item.
  • Whether main has touched the split file since the merge base: it hasn't.

What I didn't check: whether the grouping is the right one. That's a design call, and I took the body's word for it. I also didn't rebuild or retest the crate; CI is green on this head.

@the-gigi-pplx the-gigi-pplx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. No findings; details in the review comment above.

@ac-pplx
ac-pplx added this pull request to the merge queue Oct 16, 2026
Merged via the queue into main with commit 556921c Oct 16, 2026
20 checks passed
@ac-pplx
ac-pplx deleted the ac/split-spaced-host-client branch October 16, 2026 16:49
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.

3 participants