agentmux_srv_core/backend/blockcontroller/shell/mod.rs
1// Copyright 2025-2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! ShellController: manages lifecycle of shell and command blocks.
5//! Port of Go's pkg/blockcontroller/shellcontroller.go.
6//!
7//! State machine:
8//! INIT ─(start)─> RUNNING ─(exit/stop)─> DONE
9//! DONE ─(resync+force)─> RUNNING
10//!
11//! I/O model (3 async tasks when running):
12//! 1. PTY read loop: process stdout → FileStore + MPS event
13//! 2. Input loop: input channel → process stdin
14//! 3. Wait loop: monitor process exit, update status
15//!
16//! ## Module layout
17//!
18//! This was one 2,394-line file; it is now a submodule directory (pure
19//! reorganization, no logic changes). The `impl Controller for ShellController`
20//! block is kept whole in [`lifecycle`] — a trait impl cannot be split across
21//! files — and it calls the free-function helpers extracted into [`pty`],
22//! [`file_ops`], [`indexing`], and [`translation`]. The struct definitions,
23//! constructor, and small accessor/meta helpers live in [`controller`].
24//!
25//! The `pub use` re-exports below preserve the pre-split flat paths
26//! (`shell::<item>`) that callers elsewhere in the crate already import, so the
27//! reorganization changed no call site.
28
29pub mod agent_identity;
30pub mod container_pane;
31pub mod controller;
32pub mod file_ops;
33pub mod indexing;
34pub mod lifecycle;
35pub mod post_spawn;
36pub mod pty;
37pub mod pty_tasks;
38pub mod spawn_command;
39pub mod spawn_cwd;
40pub mod ssh_pane;
41pub mod stamps;
42pub mod start_io;
43pub mod start_steps;
44pub mod term_cap;
45pub mod translation;
46pub mod wait_task;
47
48// Flat re-exports preserving the pre-split `shell::<item>` call sites used
49// elsewhere in the crate (blockcontroller/mod.rs, acp, persistent, subprocess,
50// watchdog, agent_handlers/input, blockfile, app_api).
51pub use controller::ShellController;
52pub use file_ops::handle_append_block_file;
53pub use indexing::{extend_output_idx, lines_before_byte, output_index, output_now, read_via_index, read_via_stale_index};
54// A full rebuild from byte 0: the readers extend instead (`extend_output_idx`
55// falls back to one itself), so only tests call it directly.
56#[cfg(any(test, feature = "test-support"))]
57pub use indexing::rebuild_output_idx;
58
59#[cfg(test)]
60mod tests;
61#[cfg(test)]
62mod tests_transcript;