From deb7986db05f7e04991b880f380bceef7234f544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EC=84=B1=EC=A4=80?= Date: Sun, 29 Nov 2026 02:37:54 +0900 Subject: [PATCH] =?UTF-8?q?--allow-dir=C2=B7--allow-file=EC=97=90=20worksp?= =?UTF-8?q?ace=20=EC=95=88=20=EC=A0=88=EB=8C=80=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=ED=97=88=EC=9A=A9,=20=EB=B0=96=EC=9D=B4=EB=A9=B4=20=EC=9D=B4?= =?UTF-8?q?=EC=9C=A0=20=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 절대 경로를 주면 이유 없이 configuration_mismatch로 끝나던 문제(사내 router 연결 시험에서 발견)를 고친다. workspace 안의 절대 경로는 canonicalize 후 상대 경로로 바꿔 기존 catalog에 넘기므로 digest·재개 호환성이 그대로다(상대 Run을 절대 경로로 재개해도 완료 재생 확인). workspace 밖·없는 경로는 configuration=allow_path_outside_workspace/allow_path_unresolvable과 recovery를 출력하고 모델 호출 전에 멈춘다. 공개 오류 code는 그대로다. run_command가 clippy 줄 수 한도를 넘어 executable catalog 안내를 helper로 옮겼다(동작 동일). 검증: 단위 테스트 3개 추가, workspace 835 passed, DeepSeek 실제 Run(절대 경로 완료·밖/없는 경로 거절·상대 경로 유지·절대 경로 재개), 모델 요청 비교 8/8 동일. Co-Authored-By: Claude Opus 5.5 --- crates/xgen-cli/src/main.rs | 211 ++++++++++++++++++++++++++++++++---- docs/getting-started.md | 4 + 2 files changed, 194 insertions(+), 21 deletions(-) diff --git a/crates/xgen-cli/src/main.rs b/crates/xgen-cli/src/main.rs index 671cba8..51ddb1c 100644 --- a/crates/xgen-cli/src/main.rs +++ b/crates/xgen-cli/src/main.rs @@ -266,10 +266,10 @@ struct RunArgs { /// Stable non-secret planner identity. #[arg(long, default_value = "xgeny.cli.openai")] planner_id: String, - /// Exact relative workspace file the model may read; repeat for more files. + /// Exact workspace file the model may read, relative or absolute inside the workspace; repeat for more files. #[arg(long = "allow-file")] allow_files: Vec, - /// Relative workspace directory the model may inspect recursively; use '.' for the root. + /// Workspace directory the model may inspect recursively, relative or absolute inside the workspace; use '.' for the root. #[arg(long = "allow-dir")] allow_dirs: Vec, /// Catalog one executable as `LOGICAL_ID=ABSOLUTE_PATH`; repeat for more executables. @@ -1343,25 +1343,14 @@ fn run_command(args: RunArgs, debug: bool) -> ExitCode { None }; let allow_executables = executable_catalog(args.allow_executables, args.allow_path_executables); - // The driver refuses this too, but only as the bare shared configuration - // code. Say which half is missing, before anything asks for a token. if args.allow_execute && allow_executables.is_empty() { - let error = PublicRunError::Configuration; - eprintln!("XGEN_ERROR code={}", error.code()); - eprintln!(" configuration=executable_catalog"); - let recovery = if args.allow_path_executables { - "--allow-execute approves executions from a catalog, and PATH \ - discovery found no known developer executable. Catalog one with \ - --allow-executable ID=ABSOLUTE_PATH." - } else { - "--allow-execute approves executions from a catalog, and none was \ - supplied. Catalog one with --allow-executable ID=ABSOLUTE_PATH, \ - or add --allow-path-executables for the developer executables \ - found on PATH." - }; - eprintln!(" recovery={recovery}"); - return ExitCode::from(error.exit_code()); + return present_missing_executable_catalog(args.allow_path_executables); } + let (allow_files, allow_dirs) = + match normalize_allow_path_args(&args.workspace, args.allow_files, args.allow_dirs) { + Ok(paths) => paths, + Err(error) => return present_allow_path_error(&error), + }; let resolved = match resolve_model( args.base_url, args.model, @@ -1383,8 +1372,8 @@ fn run_command(args: RunArgs, debug: bool) -> ExitCode { credential: resolved.credential, inference_limits: resolved.inference_limits, request_options: resolved.request_options, - allow_files: args.allow_files, - allow_dirs: args.allow_dirs, + allow_files, + allow_dirs, allow_executables, allow_remote_model_egress: args.allow_remote_model_egress, allow_read: args.allow_read, @@ -1429,6 +1418,14 @@ fn resume_command(args: ResumeArgs, debug: bool) -> ExitCode { allow_execute, max_ticks, } = args; + let (allow_files, allow_dirs) = match normalize_allow_path_args( + workspace.as_deref().unwrap_or_else(|| Path::new(".")), + allow_files, + allow_dirs, + ) { + Ok(paths) => paths, + Err(error) => return present_allow_path_error(&error), + }; let request = LocalResumeRequest { run_id, workspace, @@ -2753,6 +2750,113 @@ fn print_committed_changes(run_id: &str) { } } +/// The driver refuses `--allow-execute` without a catalog too, but only as the bare +/// shared configuration code. Say which half is missing, before anything asks for a token. +fn present_missing_executable_catalog(allow_path_executables: bool) -> ExitCode { + let error = PublicRunError::Configuration; + eprintln!("XGEN_ERROR code={}", error.code()); + eprintln!(" configuration=executable_catalog"); + let recovery = if allow_path_executables { + "--allow-execute approves executions from a catalog, and PATH \ + discovery found no known developer executable. Catalog one with \ + --allow-executable ID=ABSOLUTE_PATH." + } else { + "--allow-execute approves executions from a catalog, and none was \ + supplied. Catalog one with --allow-executable ID=ABSOLUTE_PATH, \ + or add --allow-path-executables for the developer executables \ + found on PATH." + }; + eprintln!(" recovery={recovery}"); + ExitCode::from(error.exit_code()) +} + +/// One `--allow-file`/`--allow-dir` entry that cannot be expressed relative to the workspace. +#[derive(Debug, PartialEq, Eq)] +enum AllowPathError { + /// An absolute entry that resolves outside the workspace root. + OutsideWorkspace(String), + /// An absolute entry (or the workspace itself) that does not resolve, or has no UTF-8 + /// relative spelling. + Unresolvable(String), +} + +/// Rewrite absolute entries inside the workspace as the workspace-relative spelling the +/// read catalog accepts, so `--allow-dir "$PWD/src"` means `--allow-dir src`. +/// +/// Relative entries pass through unchanged; the catalog still validates them. The +/// rewrite happens before the catalog digest exists, so a Run and its resume agree +/// whichever spelling each used. +fn normalize_allow_path_args( + workspace: &Path, + allow_files: Vec, + allow_dirs: Vec, +) -> Result<(Vec, Vec), AllowPathError> { + if !allow_files + .iter() + .chain(&allow_dirs) + .any(|entry| Path::new(entry).is_absolute()) + { + return Ok((allow_files, allow_dirs)); + } + let root = std::fs::canonicalize(workspace) + .map_err(|_| AllowPathError::Unresolvable(workspace.display().to_string()))?; + let normalize = |entries: Vec| { + entries + .into_iter() + .map(|entry| workspace_relative_entry(&root, entry)) + .collect::, _>>() + }; + Ok((normalize(allow_files)?, normalize(allow_dirs)?)) +} + +fn workspace_relative_entry(root: &Path, entry: String) -> Result { + if !Path::new(&entry).is_absolute() { + return Ok(entry); + } + let Ok(physical) = std::fs::canonicalize(&entry) else { + return Err(AllowPathError::Unresolvable(entry)); + }; + let Ok(relative) = physical.strip_prefix(root) else { + return Err(AllowPathError::OutsideWorkspace(entry)); + }; + let mut parts = Vec::new(); + for component in relative.components() { + match component.as_os_str().to_str() { + Some(part) => parts.push(part), + None => return Err(AllowPathError::Unresolvable(entry)), + } + } + Ok(if parts.is_empty() { + ".".to_owned() + } else { + parts.join("/") + }) +} + +fn present_allow_path_error(error: &AllowPathError) -> ExitCode { + let code = PublicRunError::Configuration; + let (configuration, entry, recovery) = match error { + AllowPathError::OutsideWorkspace(entry) => ( + "allow_path_outside_workspace", + entry, + "--allow-file and --allow-dir name paths inside --workspace (default: the \ + current directory). Run from the directory that contains this path, or pass \ + that directory as --workspace.", + ), + AllowPathError::Unresolvable(entry) => ( + "allow_path_unresolvable", + entry, + "An absolute --allow-file or --allow-dir path must exist inside --workspace. \ + Check the path, or give it relative to the workspace, such as '.' or 'src'.", + ), + }; + eprintln!("XGEN_ERROR code={}", code.code()); + eprintln!(" configuration={configuration}"); + eprintln!(" path={}", entry.escape_debug()); + eprintln!(" recovery={recovery}"); + ExitCode::from(code.exit_code()) +} + fn present(result: Result) -> ExitCode { match result { Ok(LocalCommandResult::Responded { run_id, summary }) => { @@ -2967,3 +3071,68 @@ mod onboarding_tests { SESSION_CREDENTIAL.with(|slot| *slot.borrow_mut() = None); } } + +#[cfg(test)] +mod allow_path_argument_tests { + use super::*; + + fn text(path: &Path) -> String { + path.to_str().expect("UTF-8 temp path").to_owned() + } + + #[test] + fn relative_entries_pass_through_untouched() { + let workspace = tempfile::tempdir().expect("workspace"); + let result = normalize_allow_path_args( + workspace.path(), + vec!["src/lib.rs".to_owned()], + vec![".".to_owned(), "missing".to_owned()], + ); + assert_eq!( + result, + Ok(( + vec!["src/lib.rs".to_owned()], + vec![".".to_owned(), "missing".to_owned()] + )) + ); + } + + #[test] + fn absolute_entries_inside_the_workspace_become_relative() { + let workspace = tempfile::tempdir().expect("workspace"); + std::fs::create_dir_all(workspace.path().join("src/nested")).expect("dirs"); + std::fs::write(workspace.path().join("src/nested/a.txt"), "a").expect("file"); + let result = normalize_allow_path_args( + workspace.path(), + vec![text(&workspace.path().join("src/nested/a.txt"))], + vec![ + text(workspace.path()), + text(&workspace.path().join("src")), + "docs".to_owned(), + ], + ); + assert_eq!( + result, + Ok(( + vec!["src/nested/a.txt".to_owned()], + vec![".".to_owned(), "src".to_owned(), "docs".to_owned()] + )) + ); + } + + #[test] + fn absolute_entries_outside_or_missing_are_named() { + let workspace = tempfile::tempdir().expect("workspace"); + let outside = tempfile::tempdir().expect("outside"); + let outside_entry = text(outside.path()); + assert_eq!( + normalize_allow_path_args(workspace.path(), Vec::new(), vec![outside_entry.clone()]), + Err(AllowPathError::OutsideWorkspace(outside_entry)) + ); + let missing = text(&workspace.path().join("not-there")); + assert_eq!( + normalize_allow_path_args(workspace.path(), vec![missing.clone()], Vec::new()), + Err(AllowPathError::Unresolvable(missing)) + ); + } +} diff --git a/docs/getting-started.md b/docs/getting-started.md index daf31a9..40ad858 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -353,6 +353,10 @@ xgen run \ 허용하려면 `--allow-dir src --allow-dir tests`처럼 반복하고, directory 밖의 exact file만 `--allow-file Cargo.toml`로 추가한다. 미완료 재개에는 원래와 동일한 `--allow-dir`/`--allow-file` 집합을 다시 제공해야 한다. +경로는 workspace 기준 상대 경로가 기본이다. workspace 안의 절대 경로(`--allow-dir "$PWD/src"`)도 +받아 같은 상대 경로로 바꾸므로, 원래 Run과 재개가 서로 다른 표기를 써도 같은 집합이다. workspace 밖이거나 +존재하지 않는 절대 경로는 `configuration=allow_path_outside_workspace` 또는 `allow_path_unresolvable`과 +고치는 법을 출력하고 모델 호출 전에 멈춘다. Workspace mode에서는 test/build용 executable도 absolute path로 명시할 수 있다. 경로를 model에 보내지는 않으며 logical ID만 planning constraint에 노출한다.