Skip to content

Commit 86a1ea6

Browse files
refactor: narrow workspace visibility with hawk and delete the exposed dead code
Apply cargo-hawk's closed-world visibility fixes (258 pub -> pub(crate)/private narrowings across 43 files; the agentfs binary is the workspace's only product and this fork has no external library consumers). Then remove the dead code the narrowing exposed: the duplicate CLI telemetry snapshot, unused telemetry recorders, MountSpec, NfsServerHandle::is_finished, run_supervised_pid, the tokio set_parent_death_signal variant, and unused constructors/accessors in core. Test-only helpers (OverlayFS::delta, import_entries, KvStore::new, ToolCalls::new, ProfileSnapshot::counter) move behind #[cfg(test)], and the docs/knobs manual-generation machinery becomes #[cfg(test)] modules since its only consumers are their parity tests. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent 63cfdc7 commit 86a1ea6

43 files changed

Lines changed: 291 additions & 382 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/agentfs-cli/src/cmd/fs.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ mod tests {
382382
const S_IFREG: u32 = 0o100000;
383383

384384
#[tokio::test]
385-
pub async fn cat_file_not_found() {
385+
async fn cat_file_not_found() {
386386
let (_agentfs, path, _file) = agentfs().await;
387387
let mut buf = Vec::new();
388388
let err = cat_filesystem(&mut buf, path, "test.md", None)
@@ -392,7 +392,7 @@ mod tests {
392392
}
393393

394394
#[tokio::test]
395-
pub async fn cat_file_found() {
395+
async fn cat_file_found() {
396396
let (agentfs, path, _file) = agentfs().await;
397397
let content = b"hello, agentfs";
398398
write_file(&agentfs.fs, "test.md", content, 0, 0)
@@ -406,7 +406,7 @@ mod tests {
406406
}
407407

408408
#[tokio::test]
409-
pub async fn cat_big_file_found() {
409+
async fn cat_big_file_found() {
410410
let (agentfs, path, _file) = agentfs().await;
411411
let content = vec![100u8; 4 * 1024 * 1024];
412412
write_file(&agentfs.fs, "test.md", &content, 0, 0)
@@ -420,15 +420,15 @@ mod tests {
420420
}
421421

422422
#[tokio::test]
423-
pub async fn ls_empty() {
423+
async fn ls_empty() {
424424
let (_agentfs, path, _file) = agentfs().await;
425425
let mut buf = Vec::new();
426426
ls_filesystem(&mut buf, path, "/", None).await.unwrap();
427427
assert_eq!(buf, b"");
428428
}
429429

430430
#[tokio::test]
431-
pub async fn ls_files_only() {
431+
async fn ls_files_only() {
432432
let (agentfs, path, _file) = agentfs().await;
433433
write_file(&agentfs.fs, "1.md", b"1", 0, 0).await.unwrap();
434434
write_file(&agentfs.fs, "2.md", b"11", 0, 0).await.unwrap();
@@ -446,7 +446,7 @@ f 3.md
446446
}
447447

448448
#[tokio::test]
449-
pub async fn ls_dirs() {
449+
async fn ls_dirs() {
450450
let (agentfs, path, _file) = agentfs().await;
451451
agentfs.fs.mkdir("a", 0, 0).await.unwrap();
452452
agentfs.fs.mkdir("a/b", 0, 0).await.unwrap();
@@ -480,7 +480,7 @@ f d/e/3.md
480480
}
481481

482482
#[tokio::test]
483-
pub async fn ls_subdir_lists_only_subtree() {
483+
async fn ls_subdir_lists_only_subtree() {
484484
let (agentfs, path, _file) = agentfs().await;
485485
agentfs.fs.mkdir("a", 0, 0).await.unwrap();
486486
agentfs.fs.mkdir("a/b", 0, 0).await.unwrap();
@@ -517,7 +517,7 @@ f c/2.md
517517
}
518518

519519
#[tokio::test]
520-
pub async fn ls_missing_path_errors() {
520+
async fn ls_missing_path_errors() {
521521
let (_agentfs, path, _file) = agentfs().await;
522522
let mut buf = Vec::new();
523523
let err = ls_filesystem(&mut buf, path, "/missing", None)
@@ -530,7 +530,7 @@ f c/2.md
530530
}
531531

532532
#[tokio::test]
533-
pub async fn ls_file_path_errors() {
533+
async fn ls_file_path_errors() {
534534
let (agentfs, path, _file) = agentfs().await;
535535
write_file(&agentfs.fs, "file.md", b"1", 0, 0)
536536
.await
@@ -546,7 +546,7 @@ f c/2.md
546546
}
547547

548548
#[tokio::test]
549-
pub async fn read_commands_leave_no_wal_sidecar() {
549+
async fn read_commands_leave_no_wal_sidecar() {
550550
let (agentfs, path, _file) = agentfs().await;
551551
write_file(&agentfs.fs, "test.md", b"1", 0, 0)
552552
.await
@@ -585,7 +585,7 @@ f c/2.md
585585
// Encryption tests
586586

587587
#[tokio::test]
588-
pub async fn encrypted_write_and_cat() {
588+
async fn encrypted_write_and_cat() {
589589
let (agentfs, path, _file) = encrypted_agentfs().await;
590590
let content = b"encrypted content";
591591
write_file(&agentfs.fs, "secret.txt", content, 0, 0)
@@ -602,7 +602,7 @@ f c/2.md
602602
}
603603

604604
#[tokio::test]
605-
pub async fn encrypted_ls() {
605+
async fn encrypted_ls() {
606606
let (agentfs, path, _file) = encrypted_agentfs().await;
607607
write_file(&agentfs.fs, "file1.txt", b"1", 0, 0)
608608
.await
@@ -621,7 +621,7 @@ f c/2.md
621621
}
622622

623623
#[tokio::test]
624-
pub async fn write_filesystem_owns_entries_as_invoking_user() {
624+
async fn write_filesystem_owns_entries_as_invoking_user() {
625625
let (_agentfs, path, _file) = agentfs().await;
626626
write_filesystem(path.clone(), "/subdir/owned.txt", "content", None)
627627
.await
@@ -649,7 +649,7 @@ f c/2.md
649649
}
650650

651651
#[tokio::test]
652-
pub async fn encrypted_write_filesystem() {
652+
async fn encrypted_write_filesystem() {
653653
let (_agentfs, path, _file) = encrypted_agentfs().await;
654654

655655
let encryption = Some((TEST_KEY.to_string(), TEST_CIPHER.to_string()));

crates/agentfs-cli/src/cmd/init.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct EncryptionOptions {
1616
pub cipher: String,
1717
}
1818

19-
pub async fn open_agentfs(options: AgentFSOptions) -> Result<AgentFS, agentfs_core::error::Error> {
19+
pub(crate) async fn open_agentfs(options: AgentFSOptions) -> Result<AgentFS, agentfs_core::error::Error> {
2020
let mut options = options;
2121
if options.core_config.is_none() {
2222
options = options.with_core_config(crate::config::core_config_from_env());
@@ -34,13 +34,13 @@ pub async fn open_agentfs(options: AgentFSOptions) -> Result<AgentFS, agentfs_co
3434
/// the owning session performed (invariant I1). Best-effort — a finalize
3535
/// failure (e.g. a concurrent holder of the database) must not fail a
3636
/// command whose real work already succeeded.
37-
pub async fn finalize_readonly(agentfs: &AgentFS) {
37+
pub(crate) async fn finalize_readonly(agentfs: &AgentFS) {
3838
if let Err(error) = agentfs.fs.finalize().await {
3939
eprintln!("Warning: Failed to restore the single-file database family: {error:#}");
4040
}
4141
}
4242

43-
pub fn build_sync_options(sync_cmd_options: &SyncCommandOptions) -> SyncOptions {
43+
fn build_sync_options(sync_cmd_options: &SyncCommandOptions) -> SyncOptions {
4444
let mut sync = SyncOptions {
4545
remote_url: sync_cmd_options.sync_remote_url.clone(),
4646
auth_token: crate::config::turso_db_auth_token(),

crates/agentfs-cli/src/cmd/migrate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const S_IFREG: i64 = 0o100000;
3030
/// Names a command that actually finishes the job: supported old versions get
3131
/// `agentfs migrate <id-or-path>` (which lands at CURRENT in one invocation);
3232
/// anything else is from a newer agentfs and no local command can help.
33-
pub fn schema_upgrade_guidance(found: &str, expected: &str, id_or_path: &str) -> String {
33+
fn schema_upgrade_guidance(found: &str, expected: &str, id_or_path: &str) -> String {
3434
match SchemaVersion::parse(found) {
3535
Some(version) if version < schema::CURRENT => format!(
3636
"Filesystem `{id_or_path}` requires migration\n\n\
@@ -47,7 +47,7 @@ pub fn schema_upgrade_guidance(found: &str, expected: &str, id_or_path: &str) ->
4747

4848
/// Convert an SDK open error into an anyhow error, attaching migrate guidance
4949
/// when the failure is a schema-version mismatch.
50-
pub fn open_error_with_guidance(err: SdkError, id_or_path: &str) -> anyhow::Error {
50+
pub(crate) fn open_error_with_guidance(err: SdkError, id_or_path: &str) -> anyhow::Error {
5151
match &err {
5252
SdkError::SchemaVersionMismatch { found, expected } => {
5353
anyhow::anyhow!("{}", schema_upgrade_guidance(found, expected, id_or_path))

crates/agentfs-cli/src/cmd/profiling.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//! Adapter-specific counters register from their owning crates when those
44
//! adapters are constructed; the CLI owns only the process report lifecycle.
55
6-
pub use agentfs_core::telemetry::ProfileSnapshot;
7-
86
const PROFILE_SUMMARY_EVENT: &str = "agentfs_profile_summary";
97

108
/// Drop guard installed by the CLI binary for a single process summary.
@@ -18,7 +16,7 @@ impl ProfileReportGuard {
1816
Self { source }
1917
}
2018

21-
pub fn emit_now(&self) {
19+
fn emit_now(&self) {
2220
emit_profile_summary(self.source);
2321
}
2422
}
@@ -37,7 +35,7 @@ pub fn emit_cli_report() {
3735
emit_profile_summary("cli");
3836
}
3937

40-
pub fn report_checkpoint() {
38+
pub(crate) fn report_checkpoint() {
4139
if let Some(payload) = agentfs_core::telemetry::checkpoint_payload(PROFILE_SUMMARY_EVENT) {
4240
eprintln!("{payload}");
4341
}
@@ -50,7 +48,3 @@ fn emit_profile_summary(source: &str) {
5048
eprintln!("{payload}");
5149
}
5250
}
53-
54-
pub fn snapshot() -> ProfileSnapshot {
55-
agentfs_core::telemetry::snapshot()
56-
}

crates/agentfs-cli/src/cmd/ps.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ use serde::{Deserialize, Serialize};
1111
#[derive(Debug, Serialize, Deserialize)]
1212
pub struct ProcInfo {
1313
/// Process ID.
14-
pub pid: u32,
14+
pid: u32,
1515
/// Whether this process is the session owner (created the FUSE mount).
16-
pub owner: bool,
16+
owner: bool,
1717
/// Command being run.
18-
pub command: String,
18+
command: String,
1919
/// When the process started.
20-
pub started_at: DateTime<Utc>,
20+
started_at: DateTime<Utc>,
2121
/// Working directory when the session was started.
22-
pub cwd: PathBuf,
22+
cwd: PathBuf,
2323
}
2424

2525
/// Get the path to the procs directory for a session.
26-
pub fn procs_dir(session_id: &str) -> PathBuf {
26+
pub(crate) fn procs_dir(session_id: &str) -> PathBuf {
2727
let home = dirs::home_dir().expect("home directory");
2828
home.join(".agentfs")
2929
.join("run")
@@ -32,12 +32,12 @@ pub fn procs_dir(session_id: &str) -> PathBuf {
3232
}
3333

3434
/// Get the path to a proc file.
35-
pub fn proc_file(session_id: &str, pid: u32) -> PathBuf {
35+
fn proc_file(session_id: &str, pid: u32) -> PathBuf {
3636
procs_dir(session_id).join(format!("{}.json", pid))
3737
}
3838

3939
/// Write a proc file for the current process.
40-
pub fn write_proc_file(session_id: &str, owner: bool, command: &str, cwd: &Path) -> Result<()> {
40+
pub(crate) fn write_proc_file(session_id: &str, owner: bool, command: &str, cwd: &Path) -> Result<()> {
4141
let pid = std::process::id();
4242
let procs_dir = procs_dir(session_id);
4343
std::fs::create_dir_all(&procs_dir)?;
@@ -58,7 +58,7 @@ pub fn write_proc_file(session_id: &str, owner: bool, command: &str, cwd: &Path)
5858
}
5959

6060
/// Remove the proc file for the current process.
61-
pub fn remove_proc_file(session_id: &str) {
61+
pub(crate) fn remove_proc_file(session_id: &str) {
6262
let pid = std::process::id();
6363
let path = proc_file(session_id, pid);
6464
let _ = std::fs::remove_file(path);
@@ -88,7 +88,7 @@ struct SessionInfo {
8888
}
8989

9090
/// Get the set of active session IDs.
91-
pub fn active_session_ids() -> std::collections::HashSet<String> {
91+
pub(crate) fn active_session_ids() -> std::collections::HashSet<String> {
9292
list_sessions().into_iter().map(|s| s.session_id).collect()
9393
}
9494

crates/agentfs-cli/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub(crate) fn adopt_private_spill_dir() {
113113
}
114114

115115
/// The temp dir the user actually configured, independent of the override.
116-
pub(crate) fn original_temp_dir() -> PathBuf {
116+
fn original_temp_dir() -> PathBuf {
117117
match ORIGINAL_TMPDIR.get() {
118118
Some(Some(dir)) if !dir.is_empty() => PathBuf::from(dir),
119119
Some(None) => PathBuf::from("/tmp"),

crates/agentfs-cli/src/docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const GENERATED_END: &str = "<!-- END GENERATED COMMAND REFERENCE -->";
1818

1919
/// Render the generated command-reference region of docs/MANUAL.md,
2020
/// markers included.
21-
pub fn generated_manual_commands() -> String {
21+
fn generated_manual_commands() -> String {
2222
let cmd = Args::command();
2323
let mut out = String::new();
2424
out.push_str(GENERATED_BEGIN);

crates/agentfs-cli/src/knobs.rs

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub enum KnobClass {
9696
}
9797

9898
impl KnobClass {
99-
pub const fn as_str(self) -> &'static str {
99+
const fn as_str(self) -> &'static str {
100100
match self {
101101
Self::ProductConfig => "product-config",
102102
Self::KillSwitch => "kill-switch",
@@ -108,7 +108,6 @@ impl KnobClass {
108108
/// Code-backed default renderer for generated docs.
109109
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
110110
pub enum DefaultValue {
111-
Literal(&'static str),
112111
Unset,
113112
Removed,
114113
CloneTimingsEnabled,
@@ -170,9 +169,8 @@ pub enum DefaultValue {
170169
}
171170

172171
impl DefaultValue {
173-
pub fn render(self) -> String {
172+
fn render(self) -> String {
174173
match self {
175-
Self::Literal(value) => value.to_string(),
176174
Self::Unset => "unset".to_string(),
177175
Self::Removed => "removed".to_string(),
178176
Self::CloneTimingsEnabled => render_bool(DEFAULT_CLONE_TIMINGS_ENABLED).to_string(),
@@ -262,14 +260,14 @@ fn partial_origin_mode_as_str(mode: agentfs_core::PartialOriginMode) -> &'static
262260
/// One row in the canonical knob ledger.
263261
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
264262
pub struct Knob {
265-
pub name: &'static str,
266-
pub surface: &'static str,
267-
pub class: KnobClass,
268-
pub default: DefaultValue,
269-
pub owner: &'static str,
270-
pub description: &'static str,
271-
pub removal_criteria: &'static str,
272-
pub gate: &'static str,
263+
name: &'static str,
264+
surface: &'static str,
265+
class: KnobClass,
266+
default: DefaultValue,
267+
owner: &'static str,
268+
description: &'static str,
269+
removal_criteria: &'static str,
270+
gate: &'static str,
273271
}
274272

275273
impl Knob {
@@ -675,20 +673,20 @@ const DELETED_COMPAT_KNOBS: &[Knob] = &[Knob::sunset(
675673
)];
676674

677675
/// Active runtime knobs declared in one table.
678-
pub fn active_knobs() -> Vec<Knob> {
676+
fn active_knobs() -> Vec<Knob> {
679677
let mut knobs = Vec::with_capacity(ACTIVE_COMMON_KNOBS.len() + LINUX_FUSE_KNOBS.len());
680678
knobs.extend_from_slice(ACTIVE_COMMON_KNOBS);
681679
knobs.extend_from_slice(LINUX_FUSE_KNOBS);
682680
knobs
683681
}
684682

685683
/// Deleted compatibility knobs retained only as sunset documentation.
686-
pub fn deleted_compat_knobs() -> &'static [Knob] {
684+
fn deleted_compat_knobs() -> &'static [Knob] {
687685
DELETED_COMPAT_KNOBS
688686
}
689687

690688
/// Generate the checked-in docs/KNOBS.md contents.
691-
pub fn generated_knobs_doc() -> String {
689+
fn generated_knobs_doc() -> String {
692690
let active = active_knobs();
693691
let mut out = String::new();
694692
out.push_str("# AgentFS Runtime Knobs\n\n");
@@ -788,22 +786,6 @@ mod tests {
788786
);
789787
}
790788

791-
#[test]
792-
fn knob_ledger_defaults_are_code_backed() {
793-
let literal_defaults = active_knobs()
794-
.iter()
795-
.chain(deleted_compat_knobs())
796-
.filter_map(|knob| match knob.default {
797-
DefaultValue::Literal(value) => Some(format!("{}={value}", knob.name)),
798-
_ => None,
799-
})
800-
.collect::<Vec<_>>();
801-
assert!(
802-
literal_defaults.is_empty(),
803-
"knob defaults must render from code Default impls or constants, not hand-written literals: {literal_defaults:?}"
804-
);
805-
}
806-
807789
#[cfg(target_os = "linux")]
808790
#[test]
809791
fn knob_defaults_in_docs_match_runtime_defaults() {

crates/agentfs-cli/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
2121
pub mod cmd;
2222
pub mod config;
23-
pub mod docs;
24-
pub mod knobs;
23+
#[cfg(test)]
24+
mod docs;
25+
#[cfg(test)]
26+
mod knobs;
2527
pub mod logging;
2628
pub mod opts;
2729

0 commit comments

Comments
 (0)