feat: add File and Process effects for real I/O

Adds two essential effects that enable Lux to interact with the system:

File effect:
- read(path) - Read file contents as string
- write(path, content) - Write string to file
- append(path, content) - Append to file
- exists(path) - Check if file/directory exists
- delete(path) - Delete a file
- readDir(path) - List directory contents
- isDir(path) - Check if path is directory
- mkdir(path) - Create directory (including parents)

Process effect:
- exec(cmd) - Run shell command, return stdout
- execStatus(cmd) - Run command, return exit code
- env(name) - Get environment variable (returns Option)
- args() - Get command line arguments
- exit(code) - Exit program with code
- cwd() - Get current working directory
- setCwd(path) - Change working directory

Also fixes formatter bug with empty handler blocks in `run ... with {}`.

These effects make Lux capable of writing real CLI tools and scripts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 16:09:20 -05:00
parent a037f5bd2f
commit b0f6756411
6 changed files with 508 additions and 14 deletions

View File

@@ -852,6 +852,109 @@ impl TypeEnv {
},
);
// Add File effect
env.effects.insert(
"File".to_string(),
EffectDef {
name: "File".to_string(),
type_params: Vec::new(),
operations: vec![
EffectOpDef {
name: "read".to_string(),
params: vec![("path".to_string(), Type::String)],
return_type: Type::String,
},
EffectOpDef {
name: "write".to_string(),
params: vec![
("path".to_string(), Type::String),
("content".to_string(), Type::String),
],
return_type: Type::Unit,
},
EffectOpDef {
name: "append".to_string(),
params: vec![
("path".to_string(), Type::String),
("content".to_string(), Type::String),
],
return_type: Type::Unit,
},
EffectOpDef {
name: "exists".to_string(),
params: vec![("path".to_string(), Type::String)],
return_type: Type::Bool,
},
EffectOpDef {
name: "delete".to_string(),
params: vec![("path".to_string(), Type::String)],
return_type: Type::Unit,
},
EffectOpDef {
name: "readDir".to_string(),
params: vec![("path".to_string(), Type::String)],
return_type: Type::List(Box::new(Type::String)),
},
EffectOpDef {
name: "isDir".to_string(),
params: vec![("path".to_string(), Type::String)],
return_type: Type::Bool,
},
EffectOpDef {
name: "mkdir".to_string(),
params: vec![("path".to_string(), Type::String)],
return_type: Type::Unit,
},
],
},
);
// Add Process effect
env.effects.insert(
"Process".to_string(),
EffectDef {
name: "Process".to_string(),
type_params: Vec::new(),
operations: vec![
EffectOpDef {
name: "exec".to_string(),
params: vec![("cmd".to_string(), Type::String)],
return_type: Type::String,
},
EffectOpDef {
name: "execStatus".to_string(),
params: vec![("cmd".to_string(), Type::String)],
return_type: Type::Int,
},
EffectOpDef {
name: "env".to_string(),
params: vec![("name".to_string(), Type::String)],
return_type: Type::Option(Box::new(Type::String)),
},
EffectOpDef {
name: "args".to_string(),
params: Vec::new(),
return_type: Type::List(Box::new(Type::String)),
},
EffectOpDef {
name: "exit".to_string(),
params: vec![("code".to_string(), Type::Int)],
return_type: Type::Unit,
},
EffectOpDef {
name: "cwd".to_string(),
params: Vec::new(),
return_type: Type::String,
},
EffectOpDef {
name: "setCwd".to_string(),
params: vec![("path".to_string(), Type::String)],
return_type: Type::Unit,
},
],
},
);
// Add Some and Ok, Err constructors
// Some : fn(a) -> Option<a>
let a = Type::var();