Skip to content

feat: add commands.shellProfile option for custom shell profile loading#52154

Open
easyteacher wants to merge 1 commit intoopenclaw:mainfrom
easyteacher:work/commandprofile
Open

feat: add commands.shellProfile option for custom shell profile loading#52154
easyteacher wants to merge 1 commit intoopenclaw:mainfrom
easyteacher:work/commandprofile

Conversation

@easyteacher
Copy link
Copy Markdown

@easyteacher easyteacher commented Mar 22, 2026

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: Users could not specify a custom shell profile file for command execution, causing commands to run without user-defined environment variables, aliases, and functions.

  • Why it matters: Users with custom shell configurations (e.g., custom PATH, aliases, environment variables) could not leverage these in OpenClaw's command execution, leading to "command not found" errors or missing environment setup.

  • What changed: Added commands.shellProfile configuration option that accepts an absolute file path to a shell profile. When set, PowerShell, bash, zsh, and sh will source/load this profile before executing commands.

  • What did NOT change (scope boundary): Default shell behavior remains unchanged when shellProfile is not configured. No changes to existing command execution logic beyond profile loading.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • New configuration option: commands.shellProfile (string, optional)
    • Must be an absolute file path
    • When set, the specified profile file is loaded before executing shell commands
    • Supported shells: PowerShell, bash, zsh, sh
  • Example configuration:
    {
      "commands": {
        "shellProfile": "C:\\Users\\username\\Documents\\PowerShell\\Microsoft.PowerShell_profile.ps1"
      }
    }

Security Impact (required)

  • New permissions/capabilities? (Yes)

    • Risk: Users can specify arbitrary file paths to be sourced by the shell
    • Mitigation: Path validation requires absolute path; file must exist on user's local system; this is a user-configured option, not externally controlled
  • Secrets/tokens handling changed? (No)

  • New/changed network calls? (No)

  • Command/tool execution surface changed? (Yes)

    • Risk: Sourcing arbitrary profile files could execute malicious code
    • Mitigation: Only the user themselves can configure this option; it's their own profile file
  • Data access scope changed? (No)

Repro + Verification

Environment

  • OS: Windows 11 / Linux / macOS
  • Runtime/container: Node.js
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted):
    {
      "commands": {
        "shellProfile": "/home/user/.bashrc"
      }
    }

Steps

  1. Add shellProfile to openclaw.json config with an absolute path to your shell profile
  2. Run openclaw doctor to verify config is valid
  3. Execute a command that depends on environment variables or aliases defined in your profile
  4. Verify the command has access to your custom environment

Expected

  • Config validation passes
  • Commands execute with custom environment from specified profile

Actual

  • Works as expected

Evidence

Attach at least one:

  • [] Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Before:
图片

After:
After

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:

    • Config validation accepts valid absolute paths
    • Config validation rejects relative paths with clear error message
    • PowerShell profile loading works with -NoProfile flag followed by manual sourcing
  • Edge cases checked:

    • Empty string shellProfile is treated as unset
    • Whitespace-only shellProfile is treated as unset
    • Paths with single quotes are properly escaped
  • What you did not verify:
    Running on macOS/Linux

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (Yes)
    • New optional config key: commands.shellProfile
  • Migration needed? (No)

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Remove shellProfile from config or set to empty string
  • Files/config to restore: N/A (backward compatible)
  • Known bad symptoms reviewers should watch for:
    • "shellProfile must be an absolute file path" validation error
    • Commands failing to find expected aliases/functions if profile path is incorrect

Risks and Mitigations

  • Risk: User specifies non-existent profile file path

    • Mitigation: Shell will fail gracefully; user can verify file exists
  • Risk: Profile file contains syntax errors

    • Mitigation: Shell errors will be visible in command output; user can fix their profile
  • Risk: Profile loading slows down command execution

    • Mitigation: This is opt-in; users who need this feature accept the trade-off

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: S labels Mar 22, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 22, 2026

Greptile Summary

This PR adds an opt-in commands.shellProfile configuration option that lets users specify an absolute path to a shell profile file that is sourced before every command execution. When set, PowerShell, bash, zsh, and sh all load the profile inline (via . 'profile'; command concatenated into a single -c argument), which correctly handles POSIX non-interactive shell semantics.

Key changes:

  • shell-utils.ts: New getShellConfig(shellProfile?) signature and exported applyProfilePrefix helper that merges the source-prefix and command into a single argument, fixing POSIX -c semantics for all supported shells.
  • bash-tools.exec-runtime.ts / supervisor.ts: Pre-computed shell/shellArgs are passed from the exec layer to the supervisor for PTY mode, so getShellConfig (and its logWarn) is invoked exactly once per command even in the PTY path.
  • zod-schema.session.ts: Validation accepts empty string or an absolute path; cross-platform absolute-path detection covers Unix, Windows drive-letter, and UNC paths.
  • Test coverage: Windows quote-escaping, empty/whitespace profile, all supported shells, fish-fallback, and all applyProfilePrefix branches are tested.

All issues raised in prior review rounds have been addressed: the --init-file / non-interactive bash bug, the POSIX -c argument-dropping issue for zsh/sh, the duplicate logWarn in PTY mode, the missing applyProfilePrefix helper, and the Windows test assertion suffix.

Confidence Score: 4/5

  • This PR is safe to merge; all previously identified critical and logic-level issues have been resolved and the implementation is correct.
  • All P0/P1 issues from prior review rounds are resolved: the POSIX -c argument-dropping bug for zsh/sh/fish-fallback, the bash --init-file non-interactive shell bug, the duplicate logWarn in PTY mode, and the missing applyProfilePrefix abstraction. The test suite now correctly asserts the trailing '; ' suffix for Windows assertions. No new logic bugs are apparent. Score is 4 rather than 5 only because macOS/Linux end-to-end verification was explicitly noted as not performed by the author, and the feature touches shell execution paths where environment differences can surface unexpectedly.
  • No files require special attention — the core logic changes in src/agents/shell-utils.ts and src/agents/bash-tools.exec-runtime.ts look correct.

Reviews (4): Last reviewed commit: "feat: add commands.shellProfile option f..." | Re-trigger Greptile

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a17a503db6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch 3 times, most recently from e25351b to 5401087 Compare March 22, 2026 09:32
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5401087b69

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch from 5401087 to b288254 Compare March 22, 2026 09:41
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b28825483d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch from b288254 to e2ab098 Compare March 22, 2026 09:51
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e2ab098faa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch from e2ab098 to 2eedd81 Compare March 22, 2026 10:03
@easyteacher
Copy link
Copy Markdown
Author

@greptile-apps Please re-evaluate

@easyteacher easyteacher force-pushed the work/commandprofile branch 2 times, most recently from b56603a to e90f1e1 Compare March 22, 2026 10:26
@easyteacher
Copy link
Copy Markdown
Author

@greptile-apps Please re-evaluate

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e90f1e13f8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher
Copy link
Copy Markdown
Author

@greptile-apps Please re-evaluate

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9b57fe3bd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch from d9b57fe to 8f84703 Compare March 23, 2026 09:21
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c9052235e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch 5 times, most recently from 4e73b7f to 49bb269 Compare March 23, 2026 15:40
@easyteacher
Copy link
Copy Markdown
Author

easyteacher commented Mar 23, 2026

All passed, and it turns out scripts\generate-base-config-schema.ts doesn't work properly on Windows.

#52989

@easyteacher easyteacher force-pushed the work/commandprofile branch 4 times, most recently from 50446e7 to e1a14c6 Compare March 26, 2026 07:01
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1a14c6536

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch 2 times, most recently from f9b1a99 to e41f7a4 Compare March 26, 2026 14:27
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e41f7a4b6e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db912620ce

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch 2 times, most recently from b4c1659 to 16dc185 Compare March 27, 2026 01:13
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16dc185eaf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch from 16dc185 to 9f051b3 Compare March 27, 2026 01:43
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f051b329c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch from 9f051b3 to 019c33f Compare March 27, 2026 02:34
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 019c33fd66

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@easyteacher easyteacher force-pushed the work/commandprofile branch from 019c33f to 3bef192 Compare March 27, 2026 02:50
- Add shellProfile option to CommandsConfig type
- Add Zod schema validation requiring absolute file path
- Add help text and label for shellProfile config
- Update getShellConfig() to accept and use shellProfile parameter
- Support PowerShell, bash, zsh, and sh profile loading
- PowerShell: source profile with . 'path'; prefix
- Bash/Zsh/Sh: use source command prefix (non-interactive shells ignore --init-file)
- Fix POSIX shell -c argument handling: concatenate source prefix with command
- Pass shellProfile through exec tool chain
- Add tests for shellProfile functionality
@easyteacher easyteacher force-pushed the work/commandprofile branch from 3bef192 to 969cdaa Compare March 28, 2026 15:07
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 969cdaaf85

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +101 to +103
if (baseName === "bash" || baseName === "zsh" || baseName === "sh") {
return { shell, args: ["-c", buildSourcePrefix(profile)] };
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Source shellProfile for dash/ksh-style POSIX shells

The profile-loading branch only runs when baseName is exactly bash, zsh, or sh, so hosts where $SHELL is dash/ksh (or other POSIX shells that still support .) silently skip commands.shellProfile and execute with plain -c. In those environments, commands that rely on profile-defined PATH/aliases/functions will fail even though a valid absolute shellProfile is configured.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: allow command exec to specify shell profile

1 participant