Skip to content

feat(cli): shell completion for actions and commands - #806

Open
ZhangDM-520 wants to merge 3 commits into
noctalia-dev:mainfrom
ZhangDM-520:feat/cli-completions
Open

ZhangDM-520 wants to merge 3 commits into
noctalia-dev:mainfrom
ZhangDM-520:feat/cli-completions

Conversation

@ZhangDM-520

@ZhangDM-520 ZhangDM-520 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds shell completion to the umbriel CLI for bash, zsh, and fish. umbriel completions <bash|zsh|fish> prints a script and umbriel complete -- <words> is the callback it calls. Candidates come from the tables the CLI already reads — the action specs and their argument kinds in src/config/keybind_parse.cpp, the IPC command table in src/server/ipc_commands.cpp, and the config registry's own value tables — so a position cannot offer a word the grammar rejects, and a rename in one place cannot leave completion behind.

Configured names complete with no session. Output names, window ids, workspace names, and effect pool names come from the running compositor inside one 120 ms deadline that covers connect, send, and reply; a stopped, absent, silent, or backlog-saturated compositor leaves those words out and prints nothing. Positions whose words belong to another language hand the position back to the shell: umbriel complete exits 2 for a path (-c) and 3 for a command line (spawn, the startup -s flag), and the scripts complete paths and command names respectively.

Meson installs the three scripts for a native build, and PACKAGING.md records the installed paths and the cross-build behaviour. docs/user/ipc.md documents the two verbs and the budget.

Motivation

Action ids and their arguments — layout modes, window regions, stacking anchors, scratchpad and submap names, --output/--window targets — had to be typed from memory or copied out of umbriel msg --help; live output names and window ids had to be read from umbriel windows. Completion removes that lookup without adding a protocol, a config key, or a second source of truth for the grammar.

Type of Change

  • New feature

Testing

  • meson test -C build-debug --print-errorlogs --exclude eis-socket → 160/160 pass; the completion binary runs 36 cases. eis-socket-test fails to link on this host for a pre-existing reason unrelated to the change (GCC 17 / libstdc++ 17 std::filesystem::directory_iterator default constructor), so the suite and just lint were run without it; clang-tidy ran directly over every changed translation unit with --warnings-as-errors='*' and is clean.
  • ./build-debug/tests/completion-test → 36 cases. The closed vocabularies are asserted against parseActionWords, so an offered word that the grammar refuses fails the test. The bash script is driven in a real bash with a stub umbriel first on PATH, so those assertions cover what readline receives rather than the script's own text.
  • just format and just format-docs-check → clean, no diff.
  • meson install -C build-debug --no-rebuild --destdir <dir> → share/bash-completion/completions/umbriel, share/zsh/site-functions/_umbriel, share/fish/vendor_completions.d/umbriel.fish.
  • Real binary, bash: msg window-c → window-center, window-clear-region, window-close; msg window-set-region → the eight regions; config → validate, schema; -c → exit 2 (path); msg spawn ec → echo from compgen -c; -s → exit 3.
  • Real binary, zsh: eval "$(umbriel completions zsh)" exits 0 and defines _umbriel; compinit registers it; calling it as a function still emits candidates, and the delegated positions call _path_files and _command_names.
  • Real binary, fish: __umbriel_complete passes complete -- msg window-c, renders value<TAB>description, and completes msg spawn ec to echo through __fish_complete_command.
  • Latency, measured against fake sockets: a static position issues no connection (9 ms end to end); a listener that accepts and never replies costs 132 ms including process start; a listener whose accept queue is saturated (proven by a blocking connect still waiting in it) returns in 30 ms; a reply trickled one byte every 50 ms is cut off at 129 ms with its partial payload dropped; UMBRIEL_COMPLETE_LIVE=0 skips the query entirely (14 ms).
  • Real binary, grammar agreement: a digit-only workspace name (0) is offered only after --name and not as a positional; a value beginning with -- completes after --name, --output and --window but not positionally; workspace-move-to-output c → current; spawn --json exits 2 while spawn exits 3.
  • meson install --no-rebuild --destdir <dir> strips nothing on a native build; the install step is skipped entirely when meson.is_cross_build(), as PACKAGING.md states.
  • just check session/action_dispatch → PASS.

Checklist

  • This PR is ready for review, or it is marked as Draft.
  • This change fits SCOPE.md, or its scope was agreed in an issue or on Discord first.
  • I read and followed the relevant guidance in CONTRIBUTING.md.
  • I ran just format, or this PR has no C++, shader, or Markdown changes.
  • I ran the relevant build, test, lint, or verification commands, or explained why they were not run.
  • I functionally verified compositor behavior where automated checks are insufficient.
  • I self-reviewed the changes.
  • I checked for new warnings or errors.
  • I updated docs/ and examples/config.toml, or this PR does not change user-facing configuration or behavior.
  • I used canonical names for config keys, IPC actions, paths, and identifiers.

Additional Notes

  • Size: 28 files, +2579/−89. The bulk is the engine (src/cli/complete.cpp, src/cli/completion_script.cpp), the unit test, and the three shell scripts. The compositor-side change is confined to giving each spelling one owner: windowRegionNames, the actionAllowedFlags/actionFlagMask pair, the flag words, kSkipConfirmationWord, kLayoutModeToggleWord, kCurrentOutputWord, kRevokeAllWord and kImplicitScratchpad are read by the parsers and by completion, and completion reads the configuration's own registry::Choices tables (layoutModes(), columnDisplays()) rather than a copy of their names. That is what keeps completion, the word grammar, and the config keys from drifting apart.
  • No new IPC entry, config key, protocol, or harness check. The two verbs live in the existing CLI dispatch.
  • PACKAGING.md cross-build note: the install step runs only when meson.is_cross_build() is false, so a cross build installs no completion scripts rather than scripts the target cannot regenerate.
  • Completion is degraded by design, never blocking: with no compositor the configured names are offered and the live families are simply missing.
  • The change is CLI-side — the two verbs print candidates and the scripts consume them — so the manual testing that applies is in real shells, listed under Testing rather than under the compositor coverage items.
  • Known limitation: the scripts' contract with readline and zsh is below the layer the unit tests can observe. BashCompletion drives _umbriel directly, so readline's own behaviour — the space it appends after a unique match, its quote-aware replacement — is only exercised by hand in a real shell, and no harness check can see it either. The script has been verified by hand in bash 5 and zsh 5.9 against package names, window ids carrying a colon and an apostrophe, and quoted, spliced and escaped values; review of that layer on behaviour rather than by reading is welcome.

@talia-ci talia-ci Bot 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.

Talia preliminary review

Check Result
Merge score 🟢 4/5 — No issues found; likely ready after CI and human review
Findings None found
Review depth 3/5 — how thoroughly the changed code could be checked by reading it
Coverage 31 of 31 changed files reviewed

What Talia checked: Checked completion against the action/IPC grammars (flags, arities, layout/display/region tables and enum order), dispatch paths, and the IPC client refactor (server newline-terminates and closes one-shot replies). Shell scripts and the new 1 MiB reply cap remain unverified.

Run details
  • Commit reviewed: 7c8b360
  • Source lookups: 70 file reads, 50 searches
  • Prompt version: 859b7490ca3d

Preliminary automated review: Talia read the changed code and related source; nothing was built, run or tested, and AI can make mistakes. It is not a scope acceptance or a promise to merge; a human reviewer makes the final call. See our ethos.

@ZhangDM-520

Copy link
Copy Markdown
Contributor Author

Tested on Fish, Zsh and Bash:

image

Fish

image

Bash.

image

Zsh

ZhangDM-520 added a commit to ZhangDM-520/gsa-recipe that referenced this pull request Nov 15, 2026
The patch was cut at `a8c0eb15` and had gone stale: rounds 14-17 of review
landed on the same file, and the last of them fixes a closed quoted word
whose prefix bash discarded, so the installed script completed the wrong
word. Re-cut at `7c8b360d`, the head of noctalia-dev/umbriel#806.

31 files +2681/-152, sha256 59d89e53. pkgrel 2 so the installed version
identifies its content within the same pkgver.

Assisted-by: LLM (human-reviewed)
Signed-off-by: ZhangDM-520 <jixianqiang1540@gmail.com>
ZhangDM-520 added a commit to ZhangDM-520/umbriel-nightly that referenced this pull request Nov 19, 2026
ZhangDM-520 added a commit to ZhangDM-520/umbriel-nightly that referenced this pull request Nov 19, 2026
feat/cli-completions returns resp["ok"] into std::optional<nlohmann::json>.
json converts both to optional<json> and to json itself, so the return is
ambiguous on GCC 16.2.1, which is what CI builds with. This host carries a GCC
17 snapshot that resolves it, which is why the merge tested green locally and
failed in CI.

The explicit construction is the minimal disambiguation and changes no
behaviour. Upstream should carry it in noctalia-dev#806; nightly records it until then.

Assisted-by: LLM (human-reviewed)
Signed-off-by: ZhangDM-520 <jixianqiang1540@gmail.com>
ZhangDM-520 added a commit to ZhangDM-520/umbriel-nightly that referenced this pull request Nov 20, 2026
ZhangDM-520 added a commit to ZhangDM-520/umbriel-nightly that referenced this pull request Nov 21, 2026
Assisted-by: LLM (human-reviewed)

Signed-off-by: ZhangDM-520 <jixianqiang1540@gmail.com>
ZhangDM-520 added a commit to ZhangDM-520/umbriel-nightly that referenced this pull request Nov 22, 2026
ZhangDM-520 added a commit to ZhangDM-520/umbriel-nightly that referenced this pull request Nov 22, 2026
Row 3 (noctalia-dev#745) is retired: it landed upstream as 01a7828. C7 is retired:
noctalia-dev#806 carries the std::in_place conversion. Thirteen rows were refreshed
against the modal scratchpad rework and one (feat/resize-physics) was
rebased after a branch-owned conflict stopped the round before any
merge. The ten standing recipes are re-derived (C1, C2, C6, C8, C9,
C10, C11, C12, C13, C14), the gate stays local, and the falsification
results say which unions the suite actually watches.
Each of these spellings existed as a literal at one call site while the parser beside it compared the same text again: the window regions, the revoke-all word, the implicit scratchpad, `toggle`, `current`, `skip-confirmation`, the submap reset word and the `--output`/`--window`/`--name` flags. They move to the header that owns the enum or table, so shell completion can offer the exact word the parser accepts instead of a second copy of it.

`actionAllowedFlags` is now the one table mapping an argument kind to the flags it takes, and the parsers read it rather than each passing its own mask.

Assisted-by: LLM (human-reviewed)
Signed-off-by: ZhangDM-520 <jixianqiang1540@gmail.com>
`umbriel completions <shell>` prints a bash, zsh, or fish script that calls back into `umbriel complete`, so the candidates come from the same tables the parsers read and cannot drift from the grammar: actions and their argument kinds, the IPC command table, and the config registry's own value spellings.

Configured names need no session; outputs, window ids, workspaces and effect pools are asked of a running compositor inside one 120 ms deadline covering connect, send and reply, so a stopped or saturated one simply leaves those out. `umbriel complete` exits 2 for a path and 3 for a command line, which hands those positions to the shell.

Meson installs the generated scripts for a native build and skips the step on a cross build.

Assisted-by: LLM (human-reviewed)
Signed-off-by: ZhangDM-520 <jixianqiang1540@gmail.com>
Every closed vocabulary a position offers is asserted to parse through `parseActionWords`, so a word the grammar rejects fails here. The generated bash script is driven in a real shell against a stub `umbriel`, which checks what readline receives rather than the script's text.

Assisted-by: LLM (human-reviewed)
Signed-off-by: ZhangDM-520 <jixianqiang1540@gmail.com>
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.

1 participant