Return commands available to the current user for ``cwd``. Merges builtins (fresh) + filesystem skills (cached by cwd), then filters by availability + is_enabled FRESH on every call so auth/flag changes take effect immediately. De-duplicated by name (builtins own their names — see
(
cwd: str | Path | None = None,
*,
is_claude_ai_subscriber: bool = False,
is_console_user: bool = False,
)
| 84 | |
| 85 | |
| 86 | def get_commands( |
| 87 | cwd: str | Path | None = None, |
| 88 | *, |
| 89 | is_claude_ai_subscriber: bool = False, |
| 90 | is_console_user: bool = False, |
| 91 | ) -> list[Command]: |
| 92 | """ |
| 93 | Return commands available to the current user for ``cwd``. |
| 94 | |
| 95 | Merges builtins (fresh) + filesystem skills (cached by cwd), then filters by |
| 96 | availability + is_enabled FRESH on every call so auth/flag changes take effect |
| 97 | immediately. De-duplicated by name (builtins own their names — see below). |
| 98 | |
| 99 | Port of commands.ts:500 getCommands(cwd). |
| 100 | """ |
| 101 | cwd_key = str(cwd) if cwd is not None else str(Path.cwd()) |
| 102 | |
| 103 | # Builtins fresh (re-evaluates conditional appends); skills cached by cwd. |
| 104 | all_commands: list[Command] = [ |
| 105 | *get_builtin_commands(), |
| 106 | *_load_workflow_commands_cached(cwd_key), |
| 107 | *_load_skill_commands_cached(cwd_key), |
| 108 | ] |
| 109 | |
| 110 | seen: set[str] = set() |
| 111 | result: list[Command] = [] |
| 112 | for cmd in all_commands: |
| 113 | if cmd.name in seen: |
| 114 | continue # name already claimed by an earlier command |
| 115 | # Reserve the name BEFORE filtering: a builtin owns its name even when it is |
| 116 | # disabled/unavailable, so a same-named skill (enumerated later) can never |
| 117 | # shadow it. Builtins are enumerated first -> builtins win. This diverges |
| 118 | # from TS's filter-then-dedupe order on purpose (prevents a user skill named |
| 119 | # `help`/`clear` from shadowing a core builtin). |
| 120 | # |
| 121 | # This assumes filter-gated builtins (is_enabled / availability) are never |
| 122 | # meant to be *replaced* by a same-named skill. A command that should yield |
| 123 | # to a skill must instead be omitted from the source list entirely (an |
| 124 | # "append-gate", like buddy's is_buddy_command_enabled()), so it never |
| 125 | # reaches this loop and never reserves its name. |
| 126 | seen.add(cmd.name) |
| 127 | if not meets_availability_requirement( |
| 128 | cmd, is_claude_ai_subscriber, is_console_user |
| 129 | ): |
| 130 | continue |
| 131 | if not is_command_enabled(cmd): |
| 132 | continue |
| 133 | result.append(cmd) |
| 134 | return result |
| 135 | |
| 136 | |
| 137 | @lru_cache(maxsize=32) |