Skip to content

Commit 3ee0edc

Browse files
Testclaude
andcommitted
docs: Phase 0 Sealing - comprehensive API documentation
Add rustdoc comments to all public items across 9 modules: - commands.rs: All 12 public functions with params, errors, examples - state.rs: OperationType, Operation, Transaction, ShellState types - proof_refs.rs: ProofReference struct, constants, helper functions - external.rs: Enhanced execute_external documentation - executable.rs: ExecutableCommand trait and ExecutionResult enum - parser.rs: Command enum and parse_command function - redirection.rs: Redirection, FileModification, RedirectSetup types - repl.rs: REPL run function with usage examples - Cargo.toml: Added docs.rs metadata configuration All documentation includes: - Comprehensive descriptions with proof theorem references - Parameter and return value documentation - Error conditions and examples - Cross-references between related items Verified with cargo doc --no-deps (builds without warnings). Completes Component 6 of Phase 0 Sealing plan. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent c60275a commit 3ee0edc

9 files changed

Lines changed: 549 additions & 42 deletions

File tree

impl/rust-cli/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ strip = true
6868
[[bin]]
6969
name = "vsh"
7070
path = "src/main.rs"
71+
72+
[package.metadata.docs.rs]
73+
all-features = true
74+
rustdoc-args = ["--cfg", "docsrs"]

impl/rust-cli/src/commands.rs

Lines changed: 269 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,31 @@ use std::fs;
1111
use crate::proof_refs;
1212
use crate::state::{Operation, OperationType, ShellState};
1313

14-
/// Create a directory
14+
/// Create a directory at the specified path.
15+
///
16+
/// This operation is reversible via [`undo`] and corresponds to the Lean 4 theorem
17+
/// `mkdir_rmdir_reversible` in FilesystemModel.lean.
18+
///
19+
/// # Arguments
20+
/// * `state` - Mutable shell state for recording the operation
21+
/// * `path` - Path relative to shell root or absolute path
22+
/// * `verbose` - Whether to show proof references
23+
///
24+
/// # Errors
25+
/// Returns error if:
26+
/// - Path already exists (EEXIST)
27+
/// - Parent directory doesn't exist (ENOENT)
28+
/// - Insufficient permissions
29+
///
30+
/// # Examples
31+
/// ```no_run
32+
/// use vsh::commands;
33+
/// use vsh::state::ShellState;
34+
///
35+
/// let mut state = ShellState::new("/tmp/test")?;
36+
/// commands::mkdir(&mut state, "project", false)?;
37+
/// # Ok::<(), anyhow::Error>(())
38+
/// ```
1539
pub fn mkdir(state: &mut ShellState, path: &str, verbose: bool) -> Result<()> {
1640
let full_path = state.resolve_path(path);
1741

@@ -54,7 +78,32 @@ pub fn mkdir(state: &mut ShellState, path: &str, verbose: bool) -> Result<()> {
5478
Ok(())
5579
}
5680

57-
/// Remove a directory
81+
/// Remove an empty directory at the specified path.
82+
///
83+
/// This operation is reversible via [`undo`] and corresponds to the Lean 4 theorem
84+
/// `rmdir_mkdir_reversible` in FilesystemModel.lean.
85+
///
86+
/// # Arguments
87+
/// * `state` - Mutable shell state for recording the operation
88+
/// * `path` - Path relative to shell root or absolute path
89+
/// * `verbose` - Whether to show proof references
90+
///
91+
/// # Errors
92+
/// Returns error if:
93+
/// - Path does not exist (ENOENT)
94+
/// - Path is not a directory (ENOTDIR)
95+
/// - Directory is not empty (ENOTEMPTY)
96+
/// - Insufficient permissions
97+
///
98+
/// # Examples
99+
/// ```no_run
100+
/// # use vsh::commands;
101+
/// # use vsh::state::ShellState;
102+
/// let mut state = ShellState::new("/tmp/test")?;
103+
/// commands::mkdir(&mut state, "old_dir", false)?;
104+
/// commands::rmdir(&mut state, "old_dir", false)?;
105+
/// # Ok::<(), anyhow::Error>(())
106+
/// ```
58107
pub fn rmdir(state: &mut ShellState, path: &str, verbose: bool) -> Result<()> {
59108
let full_path = state.resolve_path(path);
60109

@@ -92,7 +141,30 @@ pub fn rmdir(state: &mut ShellState, path: &str, verbose: bool) -> Result<()> {
92141
Ok(())
93142
}
94143

95-
/// Create a file
144+
/// Create an empty file at the specified path.
145+
///
146+
/// This operation is reversible via [`undo`] and corresponds to the Lean 4 theorem
147+
/// `createFile_deleteFile_reversible` in FileOperations.lean.
148+
///
149+
/// # Arguments
150+
/// * `state` - Mutable shell state for recording the operation
151+
/// * `path` - Path relative to shell root or absolute path
152+
/// * `verbose` - Whether to show proof references
153+
///
154+
/// # Errors
155+
/// Returns error if:
156+
/// - Path already exists (EEXIST)
157+
/// - Parent directory doesn't exist (ENOENT)
158+
/// - Insufficient permissions
159+
///
160+
/// # Examples
161+
/// ```no_run
162+
/// # use vsh::commands;
163+
/// # use vsh::state::ShellState;
164+
/// let mut state = ShellState::new("/tmp/test")?;
165+
/// commands::touch(&mut state, "README.md", false)?;
166+
/// # Ok::<(), anyhow::Error>(())
167+
/// ```
96168
pub fn touch(state: &mut ShellState, path: &str, verbose: bool) -> Result<()> {
97169
let full_path = state.resolve_path(path);
98170

@@ -127,7 +199,32 @@ pub fn touch(state: &mut ShellState, path: &str, verbose: bool) -> Result<()> {
127199
Ok(())
128200
}
129201

130-
/// Remove a file
202+
/// Remove a file at the specified path.
203+
///
204+
/// The file's content is preserved for undo. This operation is reversible via [`undo`]
205+
/// and corresponds to the Lean 4 theorem `deleteFile_createFile_reversible`.
206+
///
207+
/// # Arguments
208+
/// * `state` - Mutable shell state for recording the operation
209+
/// * `path` - Path relative to shell root or absolute path
210+
/// * `verbose` - Whether to show proof references
211+
///
212+
/// # Errors
213+
/// Returns error if:
214+
/// - Path does not exist (ENOENT)
215+
/// - Path is a directory (EISDIR) - use [`rmdir`] instead
216+
/// - Insufficient permissions
217+
///
218+
/// # Examples
219+
/// ```no_run
220+
/// # use vsh::commands;
221+
/// # use vsh::state::ShellState;
222+
/// let mut state = ShellState::new("/tmp/test")?;
223+
/// commands::touch(&mut state, "temp.txt", false)?;
224+
/// commands::rm(&mut state, "temp.txt", false)?;
225+
/// commands::undo(&mut state, 1, false)?; // File restored
226+
/// # Ok::<(), anyhow::Error>(())
227+
/// ```
131228
pub fn rm(state: &mut ShellState, path: &str, verbose: bool) -> Result<()> {
132229
let full_path = state.resolve_path(path);
133230

@@ -163,7 +260,31 @@ pub fn rm(state: &mut ShellState, path: &str, verbose: bool) -> Result<()> {
163260
Ok(())
164261
}
165262

166-
/// Undo operations
263+
/// Undo the last N operations.
264+
///
265+
/// Reverses operations in reverse order, executing their inverse operations.
266+
/// Each undo is itself a new operation and can be undone with [`redo`].
267+
///
268+
/// # Arguments
269+
/// * `state` - Mutable shell state for accessing history
270+
/// * `count` - Number of operations to undo (default: 1)
271+
/// * `verbose` - Whether to show proof references
272+
///
273+
/// # Errors
274+
/// Returns error if:
275+
/// - No operations to undo
276+
/// - Inverse operation fails (filesystem inconsistency)
277+
/// - Missing undo data for file operations
278+
///
279+
/// # Examples
280+
/// ```no_run
281+
/// # use vsh::commands;
282+
/// # use vsh::state::ShellState;
283+
/// let mut state = ShellState::new("/tmp/test")?;
284+
/// commands::mkdir(&mut state, "test", false)?;
285+
/// commands::undo(&mut state, 1, false)?; // Removes test/
286+
/// # Ok::<(), anyhow::Error>(())
287+
/// ```
167288
pub fn undo(state: &mut ShellState, count: usize, verbose: bool) -> Result<()> {
168289
// Clone operations to avoid borrowing state
169290
let ops_to_undo: Vec<Operation> = state.last_n_undoable(count).into_iter().cloned().collect();
@@ -244,7 +365,31 @@ pub fn undo(state: &mut ShellState, count: usize, verbose: bool) -> Result<()> {
244365
Ok(())
245366
}
246367

247-
/// Redo operations
368+
/// Redo the last N undone operations.
369+
///
370+
/// Re-applies operations that were reversed with [`undo`]. Redo moves forward
371+
/// in the operation history, restoring the previous state.
372+
///
373+
/// # Arguments
374+
/// * `state` - Mutable shell state for accessing redo stack
375+
/// * `count` - Number of operations to redo (default: 1)
376+
/// * `verbose` - Whether to show proof references
377+
///
378+
/// # Errors
379+
/// Returns error if:
380+
/// - No operations to redo
381+
/// - Re-executing operation fails (filesystem changed externally)
382+
///
383+
/// # Examples
384+
/// ```no_run
385+
/// # use vsh::commands;
386+
/// # use vsh::state::ShellState;
387+
/// let mut state = ShellState::new("/tmp/test")?;
388+
/// commands::mkdir(&mut state, "test", false)?;
389+
/// commands::undo(&mut state, 1, false)?; // Removes test/
390+
/// commands::redo(&mut state, 1, false)?; // Recreates test/
391+
/// # Ok::<(), anyhow::Error>(())
392+
/// ```
248393
pub fn redo(state: &mut ShellState, count: usize, verbose: bool) -> Result<()> {
249394
for _ in 0..count {
250395
let op = match state.pop_redo() {
@@ -305,7 +450,25 @@ pub fn redo(state: &mut ShellState, count: usize, verbose: bool) -> Result<()> {
305450
Ok(())
306451
}
307452

308-
/// Show history
453+
/// Show operation history with optional proof references.
454+
///
455+
/// Displays the last N operations in reverse chronological order, showing operation
456+
/// IDs, timestamps, types, and paths. With `show_proofs`, includes theorem references.
457+
///
458+
/// # Arguments
459+
/// * `state` - Shell state for accessing history
460+
/// * `count` - Number of operations to show (default: 10)
461+
/// * `show_proofs` - Whether to show Lean 4 theorem references
462+
///
463+
/// # Examples
464+
/// ```no_run
465+
/// # use vsh::commands;
466+
/// # use vsh::state::ShellState;
467+
/// let state = ShellState::new("/tmp/test")?;
468+
/// commands::history(&state, 10, false)?; // Show last 10 operations
469+
/// commands::history(&state, 5, true)?; // Show last 5 with proofs
470+
/// # Ok::<(), anyhow::Error>(())
471+
/// ```
309472
pub fn history(state: &ShellState, count: usize, show_proofs: bool) -> Result<()> {
310473
let history = state.get_history(count);
311474

@@ -350,7 +513,31 @@ pub fn history(state: &ShellState, count: usize, show_proofs: bool) -> Result<()
350513
Ok(())
351514
}
352515

353-
/// Begin a transaction
516+
/// Begin a new transaction group.
517+
///
518+
/// All subsequent operations are grouped under this transaction until
519+
/// [`commit_transaction`] or [`rollback_transaction`] is called.
520+
///
521+
/// # Arguments
522+
/// * `state` - Mutable shell state for transaction management
523+
/// * `name` - Transaction name for identification
524+
///
525+
/// # Errors
526+
/// Returns error if:
527+
/// - A transaction is already active
528+
/// - State persistence fails
529+
///
530+
/// # Examples
531+
/// ```no_run
532+
/// # use vsh::commands;
533+
/// # use vsh::state::ShellState;
534+
/// let mut state = ShellState::new("/tmp/test")?;
535+
/// commands::begin_transaction(&mut state, "setup")?;
536+
/// commands::mkdir(&mut state, "src", false)?;
537+
/// commands::touch(&mut state, "src/main.rs", false)?;
538+
/// commands::commit_transaction(&mut state)?;
539+
/// # Ok::<(), anyhow::Error>(())
540+
/// ```
354541
pub fn begin_transaction(state: &mut ShellState, name: &str) -> Result<()> {
355542
let id = state.begin_transaction(name)?;
356543
println!(
@@ -362,7 +549,29 @@ pub fn begin_transaction(state: &mut ShellState, name: &str) -> Result<()> {
362549
Ok(())
363550
}
364551

365-
/// Commit current transaction
552+
/// Commit the current transaction, making all operations permanent.
553+
///
554+
/// Finalizes the active transaction started with [`begin_transaction`].
555+
/// All operations in the transaction become part of the permanent history.
556+
///
557+
/// # Arguments
558+
/// * `state` - Mutable shell state for transaction management
559+
///
560+
/// # Errors
561+
/// Returns error if:
562+
/// - No active transaction
563+
/// - State persistence fails
564+
///
565+
/// # Examples
566+
/// ```no_run
567+
/// # use vsh::commands;
568+
/// # use vsh::state::ShellState;
569+
/// let mut state = ShellState::new("/tmp/test")?;
570+
/// commands::begin_transaction(&mut state, "feature")?;
571+
/// commands::mkdir(&mut state, "new_feature", false)?;
572+
/// commands::commit_transaction(&mut state)?; // Makes changes permanent
573+
/// # Ok::<(), anyhow::Error>(())
574+
/// ```
366575
pub fn commit_transaction(state: &mut ShellState) -> Result<()> {
367576
let ops = state.current_transaction_ops();
368577
let op_count = ops.len();
@@ -377,7 +586,30 @@ pub fn commit_transaction(state: &mut ShellState) -> Result<()> {
377586
Ok(())
378587
}
379588

380-
/// Rollback current transaction
589+
/// Rollback the current transaction, reversing all operations atomically.
590+
///
591+
/// Undoes all operations in the active transaction started with [`begin_transaction`].
592+
/// Operations are reversed in LIFO order. Reports partial failures if any rollback fails.
593+
///
594+
/// # Arguments
595+
/// * `state` - Mutable shell state for transaction management
596+
///
597+
/// # Errors
598+
/// Returns error if:
599+
/// - No active transaction
600+
/// - Rollback operations fail (reports which operations failed)
601+
///
602+
/// # Examples
603+
/// ```no_run
604+
/// # use vsh::commands;
605+
/// # use vsh::state::ShellState;
606+
/// let mut state = ShellState::new("/tmp/test")?;
607+
/// commands::begin_transaction(&mut state, "experiment")?;
608+
/// commands::mkdir(&mut state, "temp", false)?;
609+
/// commands::touch(&mut state, "temp/file.txt", false)?;
610+
/// commands::rollback_transaction(&mut state)?; // Removes temp/ and file
611+
/// # Ok::<(), anyhow::Error>(())
612+
/// ```
381613
pub fn rollback_transaction(state: &mut ShellState) -> Result<()> {
382614
let ops: Vec<_> = state.current_transaction_ops().iter().map(|o| (*o).clone()).collect();
383615

@@ -475,7 +707,22 @@ pub fn rollback_transaction(state: &mut ShellState) -> Result<()> {
475707
}
476708
}
477709

478-
/// Show operation graph
710+
/// Display the operation dependency graph (DAG).
711+
///
712+
/// Shows the current state in the operation history as a directed acyclic graph.
713+
/// Illustrates how operations build upon each other and the undo path.
714+
///
715+
/// # Arguments
716+
/// * `state` - Shell state for accessing operation history
717+
///
718+
/// # Examples
719+
/// ```no_run
720+
/// # use vsh::commands;
721+
/// # use vsh::state::ShellState;
722+
/// let state = ShellState::new("/tmp/test")?;
723+
/// commands::show_graph(&state)?; // Displays ASCII DAG
724+
/// # Ok::<(), anyhow::Error>(())
725+
/// ```
479726
pub fn show_graph(state: &ShellState) -> Result<()> {
480727
let history = state.get_history(20);
481728

@@ -548,7 +795,17 @@ pub fn show_graph(state: &ShellState) -> Result<()> {
548795
Ok(())
549796
}
550797

551-
/// Show proof information
798+
/// Display formal verification status and proof system coverage.
799+
///
800+
/// Shows all proof references with their locations in Coq, Lean 4, Agda,
801+
/// Isabelle, and other verification systems. Provides verification statistics.
802+
///
803+
/// # Examples
804+
/// ```no_run
805+
/// use vsh::commands;
806+
/// commands::show_proofs()?; // Displays proof verification summary
807+
/// # Ok::<(), anyhow::Error>(())
808+
/// ```
552809
pub fn show_proofs() -> Result<()> {
553810
proof_refs::print_verification_summary();
554811
Ok(())

0 commit comments

Comments
 (0)