Skip to content

feat: add workdir option to run commands#1604

Merged
dengbo11 merged 1 commit into
OpenAtom-Linyaps:masterfrom
myml:workdir
Mar 11, 2026
Merged

feat: add workdir option to run commands#1604
dengbo11 merged 1 commit into
OpenAtom-Linyaps:masterfrom
myml:workdir

Conversation

@myml

@myml myml commented Mar 10, 2026

Copy link
Copy Markdown
Collaborator

Add --workdir option to ll-builder and ll-cli run commands to specify working directory inside the application container

  1. Add workdir field to RunCommandOptions and RunOptions structs
  2. Update Builder::run method to accept workdir parameter and set process.cwd
  3. Update Cli::run method to handle workdir option and validate absolute path
  4. Add CLI option parsing for --workdir in both ll-builder and ll-cli
  5. Validate that workdir path is absolute before setting in container process
  6. Maintain backward compatibility with empty workdir (default behavior)

Log: Added --workdir option to specify working directory inside container when running applications

Influence:

  1. Test ll-builder run --workdir=/path/to/dir with absolute paths
  2. Test ll-cli run --workdir=/path/to/dir with absolute paths
  3. Verify error handling when providing relative paths
  4. Test empty workdir to ensure default behavior unchanged
  5. Test with various commands and modules to ensure workdir is properly set
  6. Verify workdir persists through command execution within container

feat: 为运行命令添加工作目录选项

为 ll-builder 和 ll-cli 的 run 命令添加 --workdir 选项,用于指定应用程序 容器内的工作目录

  1. 在 RunCommandOptions 和 RunOptions 结构体中添加 workdir 字段
  2. 更新 Builder::run 方法以接受 workdir 参数并设置 process.cwd
  3. 更新 Cli::run 方法以处理 workdir 选项并验证绝对路径
  4. 在 ll-builder 和 ll-cli 中添加 CLI 选项解析支持 --workdir
  5. 在容器进程中设置工作目录前验证路径是否为绝对路径
  6. 保持向后兼容性,空工作目录使用默认行为

Log: 新增 --workdir 选项用于在运行应用程序时指定容器内的工作目录

Influence:

  1. 测试 ll-builder run --workdir=/path/to/dir 使用绝对路径
  2. 测试 ll-cli run --workdir=/path/to/dir 使用绝对路径
  3. 验证提供相对路径时的错误处理
  4. 测试空工作目录以确保默认行为不变
  5. 使用各种命令和模块测试工作目录是否正确设置
  6. 验证工作目录在容器内的命令执行过程中保持不变

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new feature that allows users to specify the working directory inside the application container when running commands using ll-builder and ll-cli. This is achieved by adding a --workdir option to the run commands, which accepts an absolute path. The changes include updating the command options structures, modifying the builder and CLI run methods to handle the new option, and adding validation to ensure the path is absolute. Backward compatibility is maintained by defaulting to the original behavior when no workdir is specified.

Highlights

  • New Feature: Introduced the --workdir option to both ll-builder and ll-cli run commands, enabling users to specify the working directory inside the application container.
  • Path Validation: Implemented validation to ensure that the provided working directory path is an absolute path before setting it in the container process.
  • Backward Compatibility: Maintained backward compatibility by ensuring that an empty workdir defaults to the original behavior.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • apps/ll-builder/src/command_options.h
    • Added workdir field to RunCommandOptions struct.
  • apps/ll-builder/src/main.cpp
    • Updated handleRun function to pass the workdir option to the builder.run method.
    • Added command-line option parsing for --workdir.
  • apps/ll-cli/src/main.cpp
    • Added command-line option parsing for --workdir.
  • libs/linglong/src/linglong/builder/linglong_builder.cpp
    • Modified the Builder::run method to accept a workdir parameter.
    • Implemented validation to ensure that the workdir is an absolute path.
    • Set the process's current working directory (cwd) to the specified workdir.
  • libs/linglong/src/linglong/builder/linglong_builder.h
    • Updated the Builder::run method declaration to include the workdir parameter.
  • libs/linglong/src/linglong/cli/cli.cpp
    • Updated the Cli::run method to handle the workdir option.
    • Added validation to ensure that the workdir is an absolute path.
    • Set the process's current working directory (cwd) to the specified workdir.
  • libs/linglong/src/linglong/cli/cli.h
    • Added workdir field to RunOptions struct.
Activity
  • New feature added: --workdir option for specifying the working directory inside the container.
  • Path validation implemented to ensure the working directory is an absolute path.
  • Backward compatibility maintained for empty workdir values.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 为 ll-builderll-clirun 命令添加了 --workdir 选项,用于指定容器内的工作目录。代码变更清晰地实现了此功能,包括更新了相关的选项结构体、命令行解析以及 run 方法的实现。实现中包含了对 workdir 路径必须为绝对路径的校验,保证了功能的健壮性。

我有一个关于代码明确性和可移植性的建议,请查看具体的审查意见。

this->printer.printErr(LINGLONG_ERRV(msg));
return -1;
}
process.cwd = workdir;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高代码的明确性和可移植性,建议在将 std::filesystem::path 类型的 workdir 赋给 std::string 类型的 process.cwd 时,显式调用 .string() 方法。虽然隐式转换在许多情况下有效,但显式转换可以避免在处理非 ASCII 路径时可能出现的编码问题,使代码意图更清晰。

        process.cwd = workdir.string();

@codecov

codecov Bot commented Mar 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 21 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
libs/linglong/src/linglong/cli/cli.cpp 0.00% 9 Missing ⚠️
apps/ll-builder/src/main.cpp 0.00% 6 Missing ⚠️
...linglong/src/linglong/builder/linglong_builder.cpp 0.00% 4 Missing ⚠️
apps/ll-cli/src/main.cpp 0.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
...s/linglong/src/linglong/builder/linglong_builder.h 0.00% <ø> (ø)
libs/linglong/src/linglong/cli/cli.h 8.33% <ø> (ø)
apps/ll-cli/src/main.cpp 0.00% <0.00%> (ø)
...linglong/src/linglong/builder/linglong_builder.cpp 2.32% <0.00%> (-0.01%) ⬇️
apps/ll-builder/src/main.cpp 0.00% <0.00%> (ø)
libs/linglong/src/linglong/cli/cli.cpp 1.00% <0.00%> (-0.01%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

dengbo11
dengbo11 previously approved these changes Mar 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a --workdir option to the ll-builder run and ll-cli run commands, allowing users to specify the working directory inside the application container. The feature validates that the provided path is absolute and gracefully falls back to default behavior when the option is not specified.

Changes:

  • Added workdir field to RunCommandOptions, RunOptions, and Builder::run method signature with appropriate defaults for backward compatibility
  • Implemented workdir validation (must be absolute path) and assignment to process.cwd in both Cli::run and Builder::run methods
  • Registered --workdir CLI option in both ll-cli and ll-builder run subcommands

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
libs/linglong/src/linglong/cli/cli.h Added workdir field to RunOptions struct
libs/linglong/src/linglong/cli/cli.cpp Implemented workdir validation and process.cwd assignment in Cli::run
libs/linglong/src/linglong/builder/linglong_builder.h Added workdir parameter to Builder::run signature
libs/linglong/src/linglong/builder/linglong_builder.cpp Implemented workdir validation and process.cwd assignment in Builder::run
apps/ll-cli/src/main.cpp Added --workdir CLI option to run subcommand
apps/ll-builder/src/main.cpp Added --workdir CLI option and passes it to Builder::run
apps/ll-builder/src/command_options.h Added workdir field to RunCommandOptions struct

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/ll-cli/src/main.cpp
Comment on lines +182 to +183
cliRun->add_option("--workdir", runOptions.workdir, _("Working directory inside the app"))
->type_name("PATH");

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI flag --workdir is inconsistent with the existing --working-directory flag used in the enter subcommand (see apps/ll-cli/src/main.cpp:227). For a consistent user experience across ll-cli subcommands, consider using --working-directory here as well (or at least adding it as an alias).

Copilot uses AI. Check for mistakes.
this->printer.printErr(LINGLONG_ERRV(msg));
return -1;
}
process.cwd = workdir;

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.cwd = workdir; relies on implicit conversion from std::filesystem::path to std::string. While this works on POSIX, the rest of the codebase consistently uses explicit .string() calls when converting std::filesystem::path to std::string (e.g., cli.cpp:679, cli.cpp:807). Use workdir.string() for consistency and clarity.

Copilot uses AI. Check for mistakes.
utils::error::Result<void> Builder::run(std::vector<std::string> modules,
std::vector<std::string> args,
bool debug,
std::string workdir,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string &workdir

@deepin-ci-robot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: myml

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown
Collaborator

deepin pr auto review

这段代码主要是为 ll-builderll-cli 添加了 --workdir 功能,允许用户指定容器内应用运行的工作目录。经过审查,整体逻辑清晰,功能实现正确,但在代码质量、性能和安全性方面还有优化的空间。

以下是详细的审查意见和改进建议:

1. 代码逻辑与安全性

意见 1:路径验证逻辑存在重复
linglong_builder.cppcli.cpp 中,都出现了检查 workdir 是否为绝对路径的逻辑。这种重复违反了 DRY (Don't Repeat Yourself) 原则,且容易导致未来修改时出现不一致。

  • 建议:将路径验证逻辑提取为一个公共的辅助函数,例如在 utils 命名空间下,或者作为 Builder 类的一个私有静态方法。

意见 2:路径有效性验证不充分
当前代码仅检查了路径是否为绝对路径(以 / 开头)。如果用户输入了一个绝对路径但该路径在容器内不存在,或者包含非法字符,容器运行时可能会报错或行为未定义。

  • 建议:虽然构建阶段无法完全预知容器内文件系统结构,但至少应验证路径字符串的合法性(例如不包含空字符,符合 POSIX 路径规范)。如果可能,建议在文档中明确指出该目录必须在容器内存在。

意见 3:默认值处理
command_options.h 中,workdir 被初始化为空字符串 ""。在 cli.h 中,workdirstd::optional<std::string>

  • 建议:为了保持一致性,建议 RunCommandOptions 中的 workdir 也使用 std::optional<std::string>。这样可以更清晰地表达"未设置"和"设置为空"的区别,虽然在当前场景下两者效果相近,但 optional 语义更明确。

2. 代码质量

意见 1:字符串拷贝性能
linglong_builder.h 中:

std::string workdir = "",

这里按值传递参数。虽然对于短字符串(如路径)来说,现代 C++ 的 SSO (Small String Optimization) 优化使得拷贝开销很小,但作为最佳实践,参数传递应考虑使用 const std::string&std::string_view

  • 建议:修改为 const std::string &workdirstd::string_view workdir。如果函数内部需要存储该字符串(看起来是直接传递给底层),按值传递配合 std::move 也是可以的,但目前的实现是直接读取,所以引用传递更合适。

意见 2:类型转换与格式化
cli.cpp 中:

auto msg = fmt::format("Workdir must be an absolute path: {}", workdir);

这里 workdirstd::filesystem::path 类型。fmt 库通常能很好地处理路径,但显式地将其转换为字符串(如 workdir.string())可以避免潜在的格式化歧义或依赖特定版本的 fmt 实现。

  • 建议:修改为 fmt::format("...: {}", workdir.string())

3. 具体代码修改建议

A. 统一路径验证逻辑 (建议在公共头文件中添加)

// 假设放在 utils/path.h
#include <filesystem>
#include <string>
#include <system_error>

namespace linglong::utils {

inline bool IsValidAbsolutePath(const std::string &pathStr) {
    if (pathStr.empty()) {
        return false;
    }
    std::error_code ec;
    std::filesystem::path p(pathStr);
    // 检查是否为绝对路径
    if (!p.is_absolute()) {
        return false;
    }
    // 可选:检查路径是否包含非法字符(如 null)
    if (pathStr.find('\0') != std::string::npos) {
        return false;
    }
    return true;
}

} // namespace linglong::utils

B. 修改 command_options.h

#include <optional>

struct RunCommandOptions
{
    std::vector<std::string> execModules;
    std::vector<std::string> commands;
    bool debugMode = false;
    std::optional<std::string> workdir; // 改为 optional
    std::vector<std::string> extensions;
};

C. 修改 linglong_builder.hlinglong_builder.cpp

头文件修改:

// linglong_builder.h
#include <optional>

// ...
    auto run(std::vector<std::string> modules,
             std::vector<std::string> args,
             bool debug = false,
             const std::optional<std::string> &workdir = std::nullopt, // 使用引用传递 optional
             std::vector<std::string> extensions = {}) -> utils::error::Result<void>;

源文件修改:

// linglong_builder.cpp
// 引入公共工具
#include "utils/path.h" 

// ...
    if (workdir.has_value()) {
        // 使用公共验证函数
        if (!utils::IsValidAbsolutePath(workdir.value())) {
            return LINGLONG_ERR(fmt::format("Workdir must be an absolute path: {}", workdir.value()));
        }
        process.cwd = workdir.value();
    }
// ...

D. 修改 cli.cpp

// 引入公共工具
#include "utils/path.h"

// ...
    auto process = ocppi::runtime::config::types::Process{ .args = std::move(commands) };
    
    if (options.workdir.has_value()) {
        // 使用公共验证函数
        if (!utils::IsValidAbsolutePath(options.workdir.value())) {
            auto msg = fmt::format("Workdir must be an absolute path: {}", options.workdir.value());
            this->printer.printErr(LINGLONG_ERRV(msg));
            return -1;
        }
        process.cwd = options.workdir.value();
    }
// ...

总结

该 diff 实现了基本功能,但通过引入 std::optional 统一类型、提取公共路径验证函数以及优化参数传递方式,可以显著提高代码的可维护性、健壮性和一致性。

dengbo11
dengbo11 previously approved these changes Mar 11, 2026
Add --workdir option to ll-builder and ll-cli run commands to specify
working directory inside the application container
1. Add workdir field to RunCommandOptions and RunOptions structs
2. Update Builder::run method to accept workdir parameter and set
process.cwd
3. Update Cli::run method to handle workdir option and validate absolute
path
4. Add CLI option parsing for --workdir in both ll-builder and ll-cli
5. Validate that workdir path is absolute before setting in container
process
6. Maintain backward compatibility with empty workdir (default behavior)

Log: Added --workdir option to specify working directory inside
container when running applications

Influence:
1. Test ll-builder run --workdir=/path/to/dir with absolute paths
2. Test ll-cli run <app> --workdir=/path/to/dir with absolute paths
3. Verify error handling when providing relative paths
4. Test empty workdir to ensure default behavior unchanged
5. Test with various commands and modules to ensure workdir is properly
set
6. Verify workdir persists through command execution within container

feat: 为运行命令添加工作目录选项

为 ll-builder 和 ll-cli 的 run 命令添加 --workdir 选项,用于指定应用程序
容器内的工作目录
1. 在 RunCommandOptions 和 RunOptions 结构体中添加 workdir 字段
2. 更新 Builder::run 方法以接受 workdir 参数并设置 process.cwd
3. 更新 Cli::run 方法以处理 workdir 选项并验证绝对路径
4. 在 ll-builder 和 ll-cli 中添加 CLI 选项解析支持 --workdir
5. 在容器进程中设置工作目录前验证路径是否为绝对路径
6. 保持向后兼容性,空工作目录使用默认行为

Log: 新增 --workdir 选项用于在运行应用程序时指定容器内的工作目录

Influence:
1. 测试 ll-builder run --workdir=/path/to/dir 使用绝对路径
2. 测试 ll-cli run <app> --workdir=/path/to/dir 使用绝对路径
3. 验证提供相对路径时的错误处理
4. 测试空工作目录以确保默认行为不变
5. 使用各种命令和模块测试工作目录是否正确设置
6. 验证工作目录在容器内的命令执行过程中保持不变
@dengbo11 dengbo11 merged commit e128fcd into OpenAtom-Linyaps:master Mar 11, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants