feat(run): add --fs-root / MARQDO_FS_ROOT for subdirectory entries

marqdo run cli/… sandboxes to the entry directory by default; repo-root
sandbox+cwd lets qdagent keep thin CLI wrappers under cli/ without
escaping .marqdo or polluting cli/.marqdo.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-28 22:17:24 +08:00
1 parent fe15603a91
commit 5554b1642c
2 files changed
+22

No files matched your search

+12
View File
@@ -207,6 +207,10 @@ pub fn run_file(path: &Path, opts: &RunOptions) -> Result<i32> {
let mut host = HostContext::for_run(Some(path), opts.host_caps(), opts.argv.clone());
host.set_entry_source(Some(path), &source);
host.entry_metadata = module.metadata.clone();
if let Some(root) = &opts.fs_root {
host.fs_root = Some(root.clone());
host.cwd = root.clone();
}
let mut interp = Interpreter::new(Some(path), opts.trace_eval)
.with_stdin(stdin_lines.clone())
.with_host(host);
@@ -229,6 +233,10 @@ pub fn run_file(path: &Path, opts: &RunOptions) -> Result<i32> {
let mut host = HostContext::for_run(Some(path), opts.host_caps(), opts.argv.clone());
host.set_entry_source(Some(path), &source);
host.entry_metadata = module.metadata.clone();
if let Some(root) = &opts.fs_root {
host.fs_root = Some(root.clone());
host.cwd = root.clone();
}
let mut vm = Vm::new(Some(path))
.with_stdin(stdin_lines)
.with_trace(opts.trace_eval)
@@ -283,6 +291,7 @@ pub fn run_file_capture(path: &Path, opts: &RunOptions) -> Result<RunCapture> {
host.entry_metadata = module.metadata.clone();
if let Some(root) = &opts.fs_root {
host.fs_root = Some(root.clone());
host.cwd = root.clone();
}
if let Some(lim) = opts.sleep_limit_ms {
host.sleep_limit_ms = Some(lim);
@@ -307,6 +316,7 @@ pub fn run_file_capture(path: &Path, opts: &RunOptions) -> Result<RunCapture> {
host.entry_metadata = module.metadata.clone();
if let Some(root) = &opts.fs_root {
host.fs_root = Some(root.clone());
host.cwd = root.clone();
}
if let Some(lim) = opts.sleep_limit_ms {
host.sleep_limit_ms = Some(lim);
@@ -341,6 +351,7 @@ pub fn run_source(source: &str, opts: &RunOptions) -> Result<RunCapture> {
host.entry_metadata = module.metadata.clone();
if let Some(root) = &opts.fs_root {
host.fs_root = Some(root.clone());
host.cwd = root.clone();
}
if let Some(lim) = opts.sleep_limit_ms {
host.sleep_limit_ms = Some(lim);
@@ -365,6 +376,7 @@ pub fn run_source(source: &str, opts: &RunOptions) -> Result<RunCapture> {
host.entry_metadata = module.metadata.clone();
if let Some(root) = &opts.fs_root {
host.fs_root = Some(root.clone());
host.cwd = root.clone();
}
if let Some(lim) = opts.sleep_limit_ms {
host.sleep_limit_ms = Some(lim);
+10
View File
@@ -78,6 +78,11 @@ enum Commands {
#[arg(long = "bind", value_name = "KEY=VALUE")]
binds: Vec<String>,
/// Filesystem sandbox + process cwd root (default: entry file's directory).
/// Also read from env `MARQDO_FS_ROOT`. Use repo root when running `cli/…` entries.
#[arg(long = "fs-root", value_name = "DIR")]
fs_root: Option<PathBuf>,
/// Emit diagnostics as JSON on stderr (machine-readable; AI/MLSP 面).
#[arg(long)]
json: bool,
@@ -412,6 +417,7 @@ fn try_main(cli: Cli) -> Result<i32> {
stdin_file,
emit_result,
binds,
fs_root,
json: _,
} => {
let path = file.unwrap_or_else(|| PathBuf::from("index.mq.md"));
@@ -423,11 +429,14 @@ fn try_main(cli: Cli) -> Result<i32> {
for b in &binds {
bind_pairs.push(marqdo::binding::parse_bind_kv(b)?);
}
let env_fs_root = std::env::var_os("MARQDO_FS_ROOT").map(PathBuf::from);
let fs_root = fs_root.or(env_fs_root);
let mut opts = if dump_all {
RunOptions {
stdin_lines: stdin_lines.clone(),
emit_result: emit_result.clone(),
binds: bind_pairs.clone(),
fs_root: fs_root.clone(),
..RunOptions::dump_all()
}
} else {
@@ -442,6 +451,7 @@ fn try_main(cli: Cli) -> Result<i32> {
stdin_lines,
emit_result,
binds: bind_pairs,
fs_root,
..RunOptions::default()
}
};