Skip to content

feat(tui): infer workspace agent when launching TUI#39591

Merged
altaywtf merged 5 commits intoopenclaw:mainfrom
arceus77-7:feat/tui-workspace-agent-default
Mar 8, 2026
Merged

feat(tui): infer workspace agent when launching TUI#39591
altaywtf merged 5 commits intoopenclaw:mainfrom
arceus77-7:feat/tui-workspace-agent-default

Conversation

@arceus77-7
Copy link
Copy Markdown
Contributor

Summary

When openclaw tui is started from inside an agent workspace directory, TUI now infers that agent and uses it for default session routing.

This makes local workspace workflows feel automatic:

  • run TUI inside workspace-ops → default session routes to ops
  • run TUI inside workspace-main → default session routes to main

Behavior

  • New resolver in agent scope:
    • resolveAgentIdsByWorkspacePath(cfg, workspacePath)
    • resolveAgentIdByWorkspacePath(cfg, workspacePath)
  • Matching rule: pick the most specific workspace path (longest prefix match).
  • Explicit session target still wins:
    • --session agent:<id>:... keeps that explicit agent.
  • If no workspace matches, behavior is unchanged (fallback to default agent).

Code changes

  • src/agents/agent-scope.ts
    • added workspace-path → agent resolution helpers
  • src/tui/tui.ts
    • added resolveInitialTuiAgentId(...)
    • wired startup agent selection to infer from CWD when session is not agent-prefixed
  • docs/cli/tui.md
    • documented workspace-based auto-selection behavior

Tests

Added/updated tests for:

  • specific vs broad workspace matching
  • no-match behavior
  • ordered match list by specificity
  • TUI startup inference behavior
  • explicit agent: session override behavior

Executed:

  • npx vitest run src/agents/agent-scope.test.ts src/tui/tui.test.ts src/cli/program.smoke.test.ts

@openclaw-barnacle openclaw-barnacle bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Mar 8, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 8, 2026

Greptile Summary

This PR adds workspace-based agent inference to the TUI startup flow. When openclaw tui is launched from inside a configured agent workspace directory, it automatically selects that agent as the active context — without requiring any explicit --session agent:<id>:... flag.

Key implementation details:

  • resolveAgentIdsByWorkspacePath / resolveAgentIdByWorkspacePath in agent-scope.ts normalize both the current working directory and configured workspace paths consistently via fs.realpathSync.native() (with lexical fallback for non-existent paths), then compare specificity using path length.
  • resolveInitialTuiAgentId in tui.ts enforces a clear priority: explicit agent-prefixed session keys win first, then falls through to workspace inference, then to the default fallback agent.
  • All returned agent IDs are normalized (via listAgentIdsnormalizeAgentId), ensuring consistency across all three code paths.
  • Tests comprehensively cover specificity ordering, no-match fallback, symlink alias resolution via realpath, explicit session override behavior, and TUI startup inference logic.

No issues found. Path normalization is applied consistently to both sides of every comparison. The explicit-session-wins contract is properly enforced before workspace inference is attempted. The workspace-inferred agent ID is already normalized and gracefully handled by the existing TUI state reconciliation in case the inferred agent is not present in the live server agent list.

Confidence Score: 5/5

  • This PR is safe to merge — the workspace inference logic is well-isolated, properly tested, and does not introduce any functional bugs or regressions.
  • The workspace-based agent inference is a low-risk, well-scoped feature. Path normalization is consistent and delegates properly to OS-level calls for cross-platform robustness. The priority order in resolveInitialTuiAgentId is enforced correctly (explicit > inferred > default). All code paths produce normalized agent IDs, and the TUI state reconciliation gracefully handles agents that may not be present on the live server. Tests comprehensively verify the critical invariants including specificity ordering, no-match fallback, symlink resolution, and the explicit-override path.
  • No files require special attention.

Last reviewed commit: 2968436

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: 7d7fa771ef

ℹ️ 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".

@altaywtf altaywtf force-pushed the feat/tui-workspace-agent-default branch from 9741729 to 2968436 Compare March 8, 2026 09:49
@altaywtf
Copy link
Copy Markdown
Member

altaywtf commented Mar 8, 2026

@codex review
@greptileai review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

We were unable to download your code in a timely manner.
ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@altaywtf altaywtf force-pushed the feat/tui-workspace-agent-default branch from 2968436 to 23533e2 Compare March 8, 2026 10:30
@altaywtf altaywtf merged commit 492fe67 into openclaw:main Mar 8, 2026
3 checks passed
@altaywtf
Copy link
Copy Markdown
Member

altaywtf commented Mar 8, 2026

Merged via squash.

Thanks @arceus77-7!

Saitop pushed a commit to NomiciAI/openclaw that referenced this pull request Mar 8, 2026
Merged via squash.

Prepared head SHA: 23533e2
Co-authored-by: arceus77-7 <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
GordonSH-oss pushed a commit to GordonSH-oss/openclaw that referenced this pull request Mar 9, 2026
Merged via squash.

Prepared head SHA: 23533e2
Co-authored-by: arceus77-7 <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
Merged via squash.

Prepared head SHA: 23533e2
Co-authored-by: arceus77-7 <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
sauerdaniel pushed a commit to sauerdaniel/openclaw that referenced this pull request Mar 11, 2026
Merged via squash.

Prepared head SHA: 23533e2
Co-authored-by: arceus77-7 <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
Merged via squash.

Prepared head SHA: 23533e2
Co-authored-by: arceus77-7 <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 14, 2026
Merged via squash.

Prepared head SHA: 23533e2
Co-authored-by: arceus77-7 <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf

(cherry picked from commit 492fe67)
alexey-pelykh added a commit to remoteclaw/remoteclaw that referenced this pull request Mar 14, 2026
…1253)

Merged via squash.

Prepared head SHA: 23533e2
Co-authored-by: arceus77-7 <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf

(cherry picked from commit 492fe67)

Co-authored-by: arceus77-7 <[email protected]>
senw-developers pushed a commit to senw-developers/va-openclaw that referenced this pull request Mar 17, 2026
Merged via squash.

Prepared head SHA: 23533e2
Co-authored-by: arceus77-7 <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
V-Gutierrez pushed a commit to V-Gutierrez/openclaw-vendor that referenced this pull request Mar 17, 2026
Merged via squash.

Prepared head SHA: 23533e2
Co-authored-by: arceus77-7 <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
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.

2 participants