Skip to content

resolve_command_invocation fails with 'Command path is outside the selected scope' when project is active #4

Description

@wgnrai

Bug Description

When a project is active, global commands (defined in usr/plugins/commands/commands/) cannot be executed. The /end and /start commands appear in the slash picker (list works) but fail at resolution time with:

ValueError: Command path is outside the selected scope

This happens every time a globally-defined command is invoked while a project context is active.

Steps to Reproduce

  1. Install the commands plugin and define commands in the global scope (usr/plugins/commands/commands/)
  2. Activate an Agent Zero project (e.g., any project with a .a0proj/ directory)
  3. Type /end (or any global command) in the CLI or web UI
  4. Observe the error: Command path is outside the selected scope

Expected Behavior

Global commands should resolve correctly when a project is active. The resolution path should follow the same precedence logic as list_effective_commands() — check project scope first, then fall back to global scope.

Actual Behavior

resolve_command_invocation() (line 371) passes project_name directly to get_command(), which calls _validate_command_path(). This validation checks if the global command path is within the project scope directory — it isn't, so it raises ValueError.

resolve_command_invocation(project_name="my_project")
  → get_command(path, project_name="my_project")
    → _validate_command_path(path, project_name="my_project")
      → get_scope_directory("my_project") → /path/to/project/.a0proj/plugins/commands/commands/
      → files.is_in_dir(global_path, project_dir) → FALSE
      → ValueError: "Command path is outside the selected scope"

Root Cause

list_effective_commands() (line 232) correctly uses _iter_precedence_scopes() which yields both project and global scopes. But resolve_command_invocation() (line 371) does NOT use this precedence chain — it validates against only the project scope.

Suggested Fix

Modify resolve_command_invocation() to iterate through _iter_precedence_scopes() when validating the command path, matching the behavior of list_effective_commands(). If the command is not found in the project scope, fall back to the global scope before raising an error.

Workaround

Copying global command files into the project's .a0proj/plugins/commands/commands/ directory works but must be repeated per project and is lost on project resets.

Environment

  • Plugin version: 0.2.1
  • Agent Zero: v1.9.x
  • OS: macOS (Apple Silicon) + Docker

Impact

Severity: High — All global commands are unusable when a project is active, which is the primary use case for most users. The workaround is fragile and must be applied per-project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions