Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better tracking of shells and terminal colors, and other internal improvements #970

Merged
merged 8 commits into from
Feb 20, 2025

Conversation

Nuru
Copy link
Contributor

@Nuru Nuru commented Feb 20, 2025

what

  • Better detection of terminal color settings at startup
  • Added --light and --dark command line options to manually set terminal theme
  • By default, disable attempt to detect terminal theme changes while running
  • Make a better separation between settings that only affect the container when it launches and settings that can vary from exec'd shell to shell
  • Correlate shells exec'd into the container with their wrapper processes
  • Make detection of tracked shells much more efficient
  • Provide an opt-out mechanism for setting TF_PLUGIN_CACHE_DIR

why

  • Because of a lack of consistent implementation of features in terminal emulators, automatically determining the terminal's appearance (e.g. light/dark theme) requires a case-by-case approach. Our implementation of the OSC protocol was basically correct, but did not account for the wide variations seen in practice. We now outsource this to the terminal-colorsaurus library, which is much further along in handling all the quirks.
  • Mechanisms to detect changes in the appearance of a terminal while the shell is running are not even close to be standardized. Our attempts frequently failed. This feature has now been marked experimental and disabled by default because it does not work acceptably well and is not something we want to invest in.
  • Geodesic now has a large number of settings. Many of them only affect the launch of the container (such as what volumes to mount and where). However, many of them can and should be allowed to vary from shell to shell in the same container (e.g. TERM). Previously, Geodesic mainly limited configuration to the launch of the container, and forced later shells to inherit that launch configuration. Now, to the extent practical, each shell can have different settings.
  • Now that the Geodesic container can remain running after the initial shell exits, it becomes important to track the shells so that the container exits when and only when all shells have exited. The v4.0.0 implementation suffered from not being able to distinguish the shell the wrapper launched from the shells other wrappers launched, nor could it tell the shells launched by docker exec and the shells launch by other shells, and therefore it could not reliably report on the status of the container. Now each shell is matched with its wrapper process, and the shell monitor tracks shells according to whether or not they were launched by docker exec, making the whole process much more reliable and efficient.
  • Cloud Posse highly recommends that Terraform users take advantage of the Terraform Provider Plugin Cache, and so Geodesic has been configuring it by setting the TF_PLUGIN_CACHE_DIR environment variable to a location on the host filesystem since the feature first became available. However, the cache does not have any protection against parallel modifications, so it is not always appropriate. Previously, Geodesic did not provide a good way to opt out of having the cache configured. Now you can set TF_PLUGIN_CACHE_DIR to "false" or "disabled" and Geodesic will honor that by unsetting the variable (leaving Terraform with its default non-caching behavior) rather than forcing you into using a cache.

references

Copy link

coderabbitai bot commented Feb 20, 2025

📝 Walkthrough

Walkthrough

This pull request updates multiple aspects of the system. It adjusts configuration and ignore files to toggle summary generation and refine file exclusion rules. Documentation and release notes are revised with updates, additions, and deprecations of various environment variables and mount options for Geodesic v4. A Debian Dockerfile is enhanced with a new Rust build stage for installing terminal-related tools. Several shell and environment scripts have been reworked to standardize variable names and improve terminal theme detection and shell tracking. Additionally, a new Rust package for terminal theme detection and its associated license file are introduced in the colorsaurus component.

Changes

Files Change Summary
.coderabbit.yaml, .dockerignore, .gitignore Toggled summary generation flags; added new ignore entries for src/colorsaurus/target/** and restored/fixed patterns for $RECYCLE.BIN.
ReleaseNotes-v4.md, docs/environment.md Revised release notes and environment documentation to reflect new, modified, and deprecated environment variables, mounting options, and caching configurations for Geodesic v4.
os/debian/Dockerfile.debian Introduced a multi-stage build with a new rust stage to build and install a Rust application, copying the terminal-theme-detector binary into the final image.
rootfs/etc/profile.d/_07-term-mode.sh, _10-colors.sh, _60-register-stray-shells.sh, prompt.sh, terraform.sh Updated terminal theme detection and management by renaming variables/functions, adding a shell tracking script, and modifying TF_PLUGIN_CACHE_DIR logic.
rootfs/templates/wrapper-body.sh, rootfs/usr/local/sbin/list-wrapper-shells, rootfs/usr/local/sbin/shell-monitor Enhanced shell and container management by adding new CLI options for theme selection, new functions for shell PID tracking, and improved container exit/wait handling.
rootfs/usr/local/bin/terminal-colorsaurus-license.txt Added a new MIT license file for the terminal-theme-detector library.
src/colorsaurus/Cargo.toml, src/colorsaurus/lib/display.rs, src/colorsaurus/src/main.rs Introduced a new Rust package terminal-theme-detector with a dependency on terminal-colorsaurus, added a helper Display wrapper, and defined a main function for terminal theme detection.

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (18)
rootfs/templates/wrapper-body.sh (4)

255-258: Array Population in _running_shell_count()
The function collects PIDs via command substitution into an array using syntax like:

local count=($(_running_shell_pids || true))

While this works in many cases, it can be fragile when output contains whitespace. Consider using a more robust approach (e.g. using mapfile -t if available) to ensure safe splitting.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 256-256: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


318-360: Robust Array Processing in run_exit_hooks()
The function uses command substitution to populate arrays (e.g. at lines 319 and 330) which can be error prone when outputs contain whitespace or special characters. It is recommended to use techniques such as mapfile -t (if using Bash ≥ 4) or proper IFS handling to avoid potential splitting issues.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 318-318: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 319-319: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 330-330: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


400-404: Use of Positional Parameters in docker exec Commands
In the branches where the script calls docker exec, the unquoted use of $* is observed. To preserve argument boundaries and protect against word splitting, it is recommended to replace $* with "$@". For example:

- docker exec --env G_HOST_PID=$WRAPPER_PID --detach-keys "ctrl-^,ctrl-[,ctrl-@" "${DOCKER_EXEC_ARGS[@]}" "${DOCKER_NAME}" $*
+ docker exec --env G_HOST_PID="$WRAPPER_PID" --detach-keys "ctrl-^,ctrl-[,ctrl-@" "${DOCKER_EXEC_ARGS[@]}" "${DOCKER_NAME}" "$@"

Apply a similar change in the other branch (around line 607).

Also applies to: 607-611

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 403-403: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)


256-610: General Shellcheck and Quoting Improvements
Several static analysis warnings suggest improvements that would increase robustness:

  • Word Splitting & Array Handling: Use constructs like mapfile -t or read -a (instead of bare command substitution) when populating arrays (e.g. in lines 256, 319, and 330).
  • Brace Expansion with Variables: Avoid using variable expansions in brace ranges (line 276) and switch to arithmetic for loops as suggested above.
  • Quoting Variables: Ensure variables (e.g. in docker exec calls and environment assignments) are consistently quoted to prevent unwanted word splitting or globbing.

These changes will help mitigate potential runtime issues across different environments and Bash versions.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 256-256: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 276-276: Bash doesn't support variables in brace range expansions.

(SC2051)


[warning] 318-318: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 319-319: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 330-330: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 384-384: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 403-403: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)


[warning] 421-421: docker_install_prompt is referenced but not assigned.

(SC2154)


[warning] 486-486: Expanding an array without an index only gives the first element.

(SC2128)


[warning] 582-582: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 582-582: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 584-584: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 595-595: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)


[warning] 610-610: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)

rootfs/usr/local/sbin/shell-monitor (5)

5-5: Leverage local arrays if scope is limited
wrapper_pids is declared globally. If you do not require it elsewhere, consider declaring it with local within the functions to limit scope.


10-12: Consider returning instead of echoing
count_shells() echoes the count, which you parse externally. Returning the count directly, or setting a global or environment variable, could simplify usage.


31-54: Consolidate repeated kill logic
The kill_shells() function uses multiple loops to send different signals. This is valid, but you could reduce repetition by iterating once over each signal: for signal in HUP TERM KILL; do ....


61-69: Make timeout configurable
You have a hard-coded 60-second timeout before exiting if no shells connect. Consider using an environment variable to allow users or administrators to adjust the waiting period.


86-90: Reassess the 0.67s sleep interval
Sleeping for 0.67 seconds is precise but may be confusing for future maintainers. If sub-second responsiveness is desired, consider using 0.5 for consistency with the earlier wait logic.

src/colorsaurus/lib/display.rs (1)

11-15: Be aware of potential differences between Display and Debug
Here, Debug formatting is delegated directly to the type’s Display implementation. This is safe if you want consistent textual representations, but you may miss typical “debug info” often included in Debug. Ensure this is intentional.

src/colorsaurus/src/main.rs (1)

17-21: Consider using standard 2-digit hex format for RGB values.

The current implementation uses 4 digits per color component (:04x). Standard RGB hex format typically uses 2 digits per component.

Apply this diff to use standard RGB hex format:

-        "{:04x}/{:04x}/{:04x};{:04x}/{:04x}/{:04x}",
+        "{:02x}/{:02x}/{:02x};{:02x}/{:02x}/{:02x}",
rootfs/etc/profile.d/_07-term-mode.sh (2)

82-114: Terminal luminance retrieval function.
The _get_terminal_luminance() function now correctly handles forced modes (“light” or “dark”) by returning fixed luminance values. For dynamic detection, it calls terminal-theme-detector with a timeout, then computes luminance using the standard sRGB formula.

A minor nitpick: a brief inline comment on why the constant 1000000000 is used (for scaling to integer precision) would aid future maintainers.

🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 93-93: Argument mixes string and array. Use * or separate argument.

(SC2145)


231-301: Retain legacy OSC query function as reference.
The _raw_query_term_mode() function is preserved as a reference for OSC queries. Although it is no longer used in primary detection (thanks to the new terminal-colorsaurus library), leaving it here helps future developers understand the evolution of the implementation. Consider marking it as deprecated in an inline comment to avoid confusion.

ReleaseNotes-v4.md (5)

247-256: Clarify and polish the TF_PLUGIN_CACHE_DIR documentation.
The new documentation clearly explains that setting TF_PLUGIN_CACHE_DIR to an empty string, "false", or "disabled" will unset the variable for users who wish to opt out of the plugin cache. However, the phrase “valuable saver of time and bandwidth” is somewhat awkward. Consider rewording it to something like “this saves time and bandwidth” for improved clarity and professionalism.


541-552: Enhance clarity in the new customization command-line options section.
The section describing new command-line options (such as --no-custom, --trace, and --dark/--light) is informative. However, the description for --trace="custom terminal hist appears to be truncated. Please review and complete the description to ensure it fully conveys its intent. Additionally, providing a brief example or further clarification for these options could help users understand their usage better.

🧰 Tools
🪛 LanguageTool

[style] ~548-~548: ‘with respect to’ might be wordy. Consider a shorter alternative.
Context: ...zations, terminal configuration (mainly with respect to light and dark mode support), and deter...

(EN_WORDINESS_PREMIUM_WITH_RESPECT_TO)


594-595: Rephrase repetitive sentences in the theme setting instructions.
The two sentences—“If you provide an argument, it will set the terminal theme to that argument. If you do not provide an argument, it will attempt to determine the terminal theme itself.”—start similarly and sound repetitive. Consider rewording one (or both) to vary the sentence structure and improve readability.


580-587: Review grammar in the experimental theme detection section.
Static analysis flagged a grammar issue around this segment (line ~580) regarding the use of articles before a countable noun. Please review the sentences in this experimental theme detection block to ensure that a proper article or possessive pronoun is present where needed for clarity.

🧰 Tools
🪛 LanguageTool

[grammar] ~580-~580: Before the countable noun ‘in’ an article or a possessive pronoun is necessary.
Context: ...ns.sh` file. #### Detecting changes in theme while running (experimental) You may h...

(IN_NN_CC_VBG)


723-725: Correct a minor typo in environment variable descriptions.
In the descriptions for GEODESIC_TERM_THEME and GEODESIC_TERM_THEME_AUTO, the phrase “light/dark them detection” should be corrected to “light/dark theme detection.” This small update will improve the clarity and professionalism of the release notes.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35c47fe and d86f0ea.

⛔ Files ignored due to path filters (1)
  • src/colorsaurus/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (18)
  • .coderabbit.yaml (1 hunks)
  • .dockerignore (2 hunks)
  • .gitignore (2 hunks)
  • ReleaseNotes-v4.md (6 hunks)
  • docs/environment.md (2 hunks)
  • os/debian/Dockerfile.debian (2 hunks)
  • rootfs/etc/profile.d/_07-term-mode.sh (3 hunks)
  • rootfs/etc/profile.d/_10-colors.sh (7 hunks)
  • rootfs/etc/profile.d/_60-register-stray-shells.sh (1 hunks)
  • rootfs/etc/profile.d/prompt.sh (1 hunks)
  • rootfs/etc/profile.d/terraform.sh (1 hunks)
  • rootfs/templates/wrapper-body.sh (12 hunks)
  • rootfs/usr/local/bin/terminal-colorsaurus-license.txt (1 hunks)
  • rootfs/usr/local/sbin/list-wrapper-shells (1 hunks)
  • rootfs/usr/local/sbin/shell-monitor (1 hunks)
  • src/colorsaurus/Cargo.toml (1 hunks)
  • src/colorsaurus/lib/display.rs (1 hunks)
  • src/colorsaurus/src/main.rs (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • rootfs/usr/local/bin/terminal-colorsaurus-license.txt
  • .gitignore
  • src/colorsaurus/Cargo.toml
🧰 Additional context used
🪛 Shellcheck (0.10.0)
rootfs/etc/profile.d/_60-register-stray-shells.sh

[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

(SC2148)

rootfs/etc/profile.d/_07-term-mode.sh

[error] 93-93: Argument mixes string and array. Use * or separate argument.

(SC2145)


[warning] 122-122: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)

rootfs/templates/wrapper-body.sh

[warning] 256-256: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 276-276: Bash doesn't support variables in brace range expansions.

(SC2051)


[warning] 318-318: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 319-319: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 330-330: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 384-384: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 403-403: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)


[warning] 486-486: Expanding an array without an index only gives the first element.

(SC2128)


[warning] 582-582: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 582-582: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 584-584: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 595-595: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)


[warning] 610-610: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)

🪛 LanguageTool
docs/environment.md

[style] ~39-~39: To form a complete sentence, be sure to include a subject.
Context: ... dark themes. - GEODESIC_MOTD_ENABLED can be set to "false" to disable printing t...

(MISSING_IT_THERE)

ReleaseNotes-v4.md

[grammar] ~580-~580: Before the countable noun ‘in’ an article or a possessive pronoun is necessary.
Context: ...ns.sh` file. #### Detecting changes in theme while running (experimental) You may h...

(IN_NN_CC_VBG)


[style] ~596-~596: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...et the terminal theme to that argument. If you do not provide an argument, it will...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-push (debian)
🔇 Additional comments (29)
.dockerignore (2)

27-28: New entry for terminal colorsaurus target directory added.
The new line src/colorsaurus/target/** ensures that compiled/generated files in the specified directory are excluded from the Docker image. This change maintains consistency with the similar update in the .gitignore file.


46-47: $RECYCLE.BIN entry correction.
The adjustment to the $RECYCLE.BIN ignore pattern ensures that this directory is consistently ignored in Docker builds, aligning with the corrections made in the .gitignore file.

rootfs/templates/wrapper-body.sh (4)

120-125: Add Terminal Theme Options (--dark and --light)
The new options in the parse_args() function correctly export GEODESIC_TERM_THEME as "dark" or "light". This change clearly documents the user’s intent to override automatic terminal color detection. Consider adding tests or updating the documentation accordingly.


182-192: Update Help Message for Terminal Theme Settings
The enhancements to the help() function now include clear instructions for the --dark and --light options. This makes the UI more informative and aligns well with the new flag handling in argument parsing.


247-249: Introduce _running_shell_pids() Function
The new helper function using docker exec to list running shell PIDs is straightforward. Ensure that the external command (list-wrapper-shells) reliably returns the expected PID list.


251-253: Introduce _our_shell_pid() Function
This function neatly wraps a call to docker exec for retrieving the current shell’s PID. The inclusion of || true helps guard against command failures.

rootfs/usr/local/sbin/shell-monitor (3)

3-3: Ensure the source path is valid
Sourcing list-wrapper-shells here is fine, but consider verifying error handling or fallback if the script is missing or unreadable.


14-28: Validate the exit-checking logic
The shell_has_exited() function immediately returns once it finds any PID that is missing from /proc. Ensure this is your intended behavior if multiple shells may exit at various times. Consider updating wrapper_pids to remove exited shells to maintain accurate state.


74-83: Helpful inline documentation
These detailed comments about exit timing are insightful and clarify the script's logic. Thank you for including them.

src/colorsaurus/lib/display.rs (1)

3-9: Neat newtype for bridging Display and Debug
Wrapping types as DisplayAsDebug<T> is a creative way to unify Display output with a debug interface. This approach can reduce duplication for simple types.

rootfs/usr/local/sbin/list-wrapper-shells (2)

6-15: Validate approach to parsing /proc
This method of filtering processes by scanning /proc/$pid/environ is effective in many environments. However, in heavily locked-down or containerized situations, /proc/$pid/environ may be inaccessible. Confirm this approach covers edge cases where advanced security restrictions might be in place.


19-19: Graceful handling when sourcing
Allowing this script to be either sourced or executed is a good design approach. This dual usage avoids redundant calls yet remains user-friendly when used as an independent tool.

src/colorsaurus/src/main.rs (1)

7-12: Verify if the commented code should be removed.

The code contains commented-out logic for color scheme detection. If this functionality is no longer needed, consider removing it to improve code clarity.

rootfs/etc/profile.d/_60-register-stray-shells.sh (1)

20-23: LGTM!

The shell tracking logic is well-implemented:

  • Correctly identifies shells launched by docker exec using PPID check.
  • Properly handles the initial shell case.
  • Uses clear and descriptive output message.
rootfs/etc/profile.d/terraform.sh (1)

48-56: LGTM!

The implementation of the opt-out functionality for TF_PLUGIN_CACHE_DIR is well-designed:

  • Handles various opt-out values: empty string, "false", "disabled".
  • Properly unsets the variable when opted out.
  • Gracefully handles directory creation failure.
.coderabbit.yaml (1)

8-8: LGTM!

The configuration changes are valid and align with the schema:

  • Disabling high-level summary in PR description.
  • Enabling high-level summary in walkthrough.

Also applies to: 10-10

rootfs/etc/profile.d/prompt.sh (1)

54-60: Refactor terminal update logic to use theme detection instead of color mode.
The previous variable used for color updates has been replaced by a new check that looks at whether automatic terminal theme detection is enabled. Setting

[[ ${GEODESIC_TERM_THEME_AUTO} == "enabled" ]] && export GEODESIC_TERM_THEME_UPDATING="needed"

and then later calling auto-update-terminal-theme is clear and concise. Please verify that all corresponding calls in other scripts have been updated accordingly.

docs/environment.md (1)

37-38: Document new terminal theme environment variables.
The new entries for GEODESIC_TERM_THEME and GEODESIC_TERM_THEME_AUTO are clearly explained and align with the updated detection logic. Ensure that their intended defaults (i.e. defaulting to light when not explicitly set) are consistent with the behavior in the shell scripts.

rootfs/etc/profile.d/_07-term-mode.sh (3)

50-67: Robust integration of terminal-theme-detector in query verification.
Within the _verify_terminal_queries_are_supported() function, you now:

  • Use tput colors to determine terminal capabilities.
  • Fall back by exporting GEODESIC_TERM_THEME_AUTO=unsupported when either (a) the terminal does not support colors or (b) the external binary (terminal-theme-detector) fails.

This enhances robustness by clearly flagging unsupported environments. One suggestion is to consider caching the outcome if repeated calls are expected.


80-80: Conditional startup verification.
By checking

[[ "${GEODESIC_TERM_THEME}" == "light" ]] || [[ "${GEODESIC_TERM_THEME}" == "dark" ]] || _verify_terminal_queries_are_supported

you ensure that the automatic detection is only attempted when needed. Please verify that cases where GEODESIC_TERM_THEME is not set are handled as intended.


121-163: Determine terminal theme mode based on luminance.
The _is_term_dark_mode() function clearly compares the foreground and background luminance values and maps them to “dark”, “light”, or “unknown”. Defaulting to “unknown” (which later falls back to light mode) preserves historical behavior and avoids abrupt changes.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 122-122: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)

rootfs/etc/profile.d/_10-colors.sh (6)

13-32: Rename and update terminal theme update function.
The function formerly known as update-terminal-color-mode() is now update-terminal-theme(). The handling of explicit modes (“dark” or “light”) and the fallback when no valid mode is provided is clear. The updated usage message helps users understand the expected arguments.

🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 19-19: Couldn't parse this case item. Fix to allow more checks.

(SC1073)


[error] 23-23: Expected a command. Fix any mentioned problems and try again.

(SC1072)


67-76: Introduce set-terminal-theme for manual overrides.
The new set-terminal-theme() function neatly encapsulates user-initiated theme changes. By checking for valid arguments ("dark" or "light") and otherwise unsetting the override to fall back on automatic detection, this design upholds the separation of manual and auto-detection logic.


78-80: Provide a getter for the current terminal theme.
The get-terminal-theme() function returns the cached theme state (defaulting to “light” if not explicitly set). This helper is consistent with the overall design and makes theme state queries straightforward.


322-333: Automatic terminal theme update handling is solid.
In auto-update-terminal-theme(), the function checks that automatic updates are enabled and temporarily locks the update state with GEODESIC_TERM_THEME_UPDATING. In the event of a failure (detected by the exit code 9), it marks the automatic mechanism as failed. This prevents repeated, futile update attempts.


341-345: Improved SIGWINCH handler for theme updates.
The _update-terminal-theme-sigwinch() function replaces its color-mode predecessor, simply setting GEODESIC_TERM_THEME_UPDATING to “needed”. This streamlined approach avoids running full updates inside the signal handler and defers them to the prompt hook.


347-362: Integrate new SIGWINCH trap with any existing handlers.
The updated trap setup preserves any preexisting SIGWINCH traps while appending the new theme update call. This careful combination helps prevent conflicts with other signal-dependent functionality.

os/debian/Dockerfile.debian (2)

25-29: Introduce multi-stage Rust build for terminal-theme-detector.
A new build stage using a Rust base image is added to compile the terminal-theme-detector binary. Copying the /src/colorsaurus directory, setting the working directory, and running cargo install to place the binary in /usr/local is a clean approach. Please verify that dependencies (including the terminal-colorsaurus library) are correctly specified in Cargo.toml.


165-167: Copy terminal-theme-detector binary into the final image.
The command

COPY --from=rust /usr/local/bin/terminal-theme-detector /usr/local/bin/terminal-theme-detector

ensures that the detector is present in the final Debian image. This integration is essential for the new automatic terminal theme detection and looks correct.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (7)
rootfs/etc/profile.d/_07-term-mode.sh (3)

95-98: Improve Logging of Function Stack
In the block where the terminal mode is forced, the trace message:
  _terminal_trace "Function stack is ${FUNCNAME[@]}."
may trigger a shellcheck warning due to mixing string and array. Consider using "${FUNCNAME[*]}" instead to safely expand the array.

🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 98-98: Argument mixes string and array. Use * or separate argument.

(SC2145)


127-127: Safer Array Splitting for Luminance Values
At the start of the _is_term_dark_mode() function, the command
  local lum=($(_get_terminal_luminance))
relies on word splitting which can be fragile. It would be preferable to use a more robust approach (e.g., read -a lum <<< "$(_get_terminal_luminance)") to ensure correct parsing of the output.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 127-127: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


235-306: _raw_query_term_mode() as a Reference Implementation
The new helper function _raw_query_term_mode() is well annotated and serves as a useful reference for OSC-based color queries. If this function is not actively used in the new detection logic, consider deprecating it (or clearly marking it as legacy) in future releases to reduce maintenance overhead.

ReleaseNotes-v4.md (2)

541-549: Enhanced Documentation for New Command-Line Options
The added list of new customization options is very informative. As a minor stylistic suggestion, consider rephrasing “with respect to light and dark mode support” to a more concise form (e.g. “for light/dark mode support”) to improve readability.

🧰 Tools
🪛 LanguageTool

[style] ~548-~548: ‘with respect to’ might be wordy. Consider a shorter alternative.
Context: ...zations, terminal configuration (mainly with respect to light and dark mode support), and the d...

(EN_WORDINESS_PREMIUM_WITH_RESPECT_TO)


605-606: Minor Grammatical Improvement in Signal Description
In the sentence “Geodesic also sends this signal to its shell when it detects change in the size of the window,” consider adding an article for clarity (e.g. “when it detects a change in the size of the window”).

🧰 Tools
🪛 LanguageTool

[uncategorized] ~606-~606: Possible missing article found.
Context: ...his signal to its shell when it detects change in the size of the window. You can set ...

(AI_HYDRA_LEO_MISSING_A)

rootfs/templates/wrapper-body.sh (2)

256-257: Refine Shell Count Retrieval in _running_shell_count

Currently, the count is built via a command substitution that may be prone to word-splitting issues. For improved robustness, consider using readarray (or its synonym mapfile) to capture the output as an array. For example:

-  local count=($(_running_shell_pids || true))
-  echo "${#count[@]}"
+  readarray -t count < <(_running_shell_pids || true)
+  echo "${#count[@]}"

This change improves readability and maintains predictable behavior in diverse shell environments.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 256-256: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


318-320: Capture Running Shell PIDs in run_exit_hooks

Within run_exit_hooks(), the code assigns the output of _our_shell_pid and _running_shell_pids to variables. As with the _running_shell_count() function, using simple command substitution for array creation may be fragile when handling whitespace.

A suggestion would be to utilize readarray to robustly populate the shell_pids array. For example:

- local shell_pids=($(_running_shell_pids))
+ readarray -t shell_pids < <(_running_shell_pids)

This change helps avoid potential splitting issues.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 318-318: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 319-319: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d86f0ea and 90befb0.

📒 Files selected for processing (4)
  • .gitignore (2 hunks)
  • ReleaseNotes-v4.md (5 hunks)
  • rootfs/etc/profile.d/_07-term-mode.sh (3 hunks)
  • rootfs/templates/wrapper-body.sh (12 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .gitignore
🧰 Additional context used
🪛 Shellcheck (0.10.0)
rootfs/templates/wrapper-body.sh

[warning] 256-256: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 318-318: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 319-319: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 330-330: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 384-384: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 403-403: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)


[warning] 486-486: Expanding an array without an index only gives the first element.

(SC2128)


[warning] 582-582: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 582-582: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 584-584: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 595-595: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)


[warning] 610-610: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)

rootfs/etc/profile.d/_07-term-mode.sh

[error] 98-98: Argument mixes string and array. Use * or separate argument.

(SC2145)


[warning] 127-127: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)

🪛 LanguageTool
ReleaseNotes-v4.md

[style] ~548-~548: ‘with respect to’ might be wordy. Consider a shorter alternative.
Context: ...zations, terminal configuration (mainly with respect to light and dark mode support), and the d...

(EN_WORDINESS_PREMIUM_WITH_RESPECT_TO)


[grammar] ~580-~580: Before the countable noun ‘in’ an article or a possessive pronoun is necessary.
Context: ...ns.sh` file. #### Detecting changes in theme while running (experimental) You may h...

(IN_NN_CC_VBG)


[style] ~596-~596: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...et the terminal theme to that argument. If you do not provide an argument, it will...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[uncategorized] ~606-~606: Possible missing article found.
Context: ...his signal to its shell when it detects change in the size of the window. You can set ...

(AI_HYDRA_LEO_MISSING_A)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-push (debian)
🔇 Additional comments (20)
rootfs/etc/profile.d/_07-term-mode.sh (5)

9-38: Detailed Documentation on Theme Detection Modes
The new comment block clearly explains the two different auto‐detection approaches (initial startup vs. runtime changes) with ample detail. This helps future readers understand the rationale and configuration options.


52-53: Clarification on tput Limitations
The added comments explain that even if the terminal supports color, tput might not, and thus a fallback to a monochrome mode is needed. This extra context is useful.


59-59: Explicit Fallback When Color Detection Fails
Setting GEODESIC_TERM_THEME_AUTO=unsupported immediately when the terminal isn’t supported is a clear and appropriate fallback mechanism.


63-67: Robust Check with External Detector
The new conditional block using /usr/local/bin/terminal-theme-detector enhances reliability by verifying if the external utility works. Consider, as a follow‐up, logging any error details returned by the detector for easier debugging.


80-80: Concise Conditional Invocation for Terminal Verification
The compound condition checking for a forced theme ("light" or "dark") before invoking _verify_terminal_queries_are_supported is both concise and effective.

ReleaseNotes-v4.md (4)

247-256: Clear Explanation of TF_PLUGIN_CACHE_DIR Opt-Out Mechanism
The revised section explains how Geodesic now handles the Terraform Provider Plugin Cache, including the opt-out mechanism by unsetting the variable. The description is clear and aligns well with the PR objectives.


592-597: Clear Usage Instructions for Setting Terminal Theme
The instructions on how to use the set-terminal-theme [light|dark] command are clear and direct. They effectively communicate both the behavior when an argument is provided and when it is not.

🧰 Tools
🪛 LanguageTool

[style] ~596-~596: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...et the terminal theme to that argument. If you do not provide an argument, it will...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


601-603: Effective Query Mechanism for Cached Terminal Theme
The snippet showing how to use get-terminal-theme to query the cached theme setting is straightforward and informative.


723-725: Documentation of New Environment Variables for Theme Configuration
The update clearly documents the use and expected behavior of GEODESIC_TERM_THEME and GEODESIC_TERM_THEME_AUTO. This ensures users understand how to disable automatic theme detection or enable experimental auto-detection.

rootfs/templates/wrapper-body.sh (11)

120-125: Add New Terminal Theme Options in Argument Parsing

The new --dark and --light options are cleanly implemented by setting the GEODESIC_TERM_THEME environment variable accordingly. This enhancement aligns the CLI with the updated documentation and provides users with manual control of the terminal theme.


181-193: Enhance Help Message with Theme Options

The help output has been updated to list the new terminal theme options (--dark and --light) along with their descriptions. This improvement improves discoverability and user guidance.


247-249: Introduce _running_shell_pids Helper Function

The new _running_shell_pids() function encapsulates the logic for retrieving running shell PIDs via a Docker exec call. Its minimal design is appropriate for its purpose.


251-253: Introduce _our_shell_pid Helper Function

The newly added _our_shell_pid() function effectively retrieves the PID corresponding to our shell by using Docker exec with the $WRAPPER_PID variable. The fallback (|| true) ensures that errors during retrieval are safely suppressed.


271-304: Implement Robust Container Exit Waiting Logic

The new wait_for_container_exit() function uses a C-style loop (for (( i=0; i<=n; i++ ))) that replaces the problematic brace expansion, which is a more portable and reliable construct. The loop checks for the disappearance of the container and handles cases where other shells continue running.

A couple of points to consider:

  • Verify that the condition combining [_our_shell_pid] with _running_shell_count truly captures the intended exit scenarios.
  • The sleep interval (0.4 seconds per iteration) is hardcoded; if shell exit latency might vary, consider parameterizing the wait time for greater flexibility.

343-359: Wait for Shell Exit with Timeout in run_exit_hooks

The logic that waits for our shell to finish exiting is clear: it loops while _our_shell_pid returns a value, with a timeout of 15 iterations and an initial delay. This approach provides feedback to the user (via a debug message) and eventually calls wait_for_container_exit().

Consider logging additional context if timeouts occur frequently, although the current implementation is functionally sound.


366-367: Store the Wrapper PID for Later Use

Storing the current shell’s PID in WRAPPER_PID using $$ is correct and makes the later Docker exec calls traceable to the proper shell process.


400-400: Conditionally Add Interactive Flag for Docker Exec

The check [ -t 0 ] && DOCKER_EXEC_ARGS+=(-it) is a nice touch to ensure that interactive terminals get the appropriate flag.


543-549: Consolidate Workspace Mounting in Docker Launch Arguments

The block that builds the DOCKER_LAUNCH_ARGS for mounting the workspace is well structured. The concatenation of mount_dir with the host directory is straightforward, but please verify that mount_dir is always set appropriately (even if empty) so that the constructed container paths are as intended.


575-575: Include Host Mounts Environment Variable

Appending the --env GEODESIC_HOST_MOUNTS flag to DOCKER_LAUNCH_ARGS ensures that the container is aware of what host mounts are configured. This is a useful addition for later processing inside the container.


580-588: Refine Docker Launch Argument Composition

The addition of privileges, port mappings, and environment variables in the DOCKER_LAUNCH_ARGS block looks comprehensive. One minor note is to ensure that the use of parameter substitution (e.g. "${DOCKER_IMAGE%:*}") aligns with the intended semantics of stripping the image tag.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 582-582: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 582-582: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 584-584: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)

)

if [ "$ONE_SHELL" = "true" ]; then
DOCKER_NAME="${DOCKER_NAME}-$(date +%d%H%M%S)"
echo "# Starting single shell ${DOCKER_NAME} session from ${DOCKER_IMAGE}"
echo "# Exposing port ${GEODESIC_PORT}"
[ -z "${GEODESIC_DOCKER_EXTRA_ARGS}" ] || echo "# Launching with extra Docker args: ${GEODESIC_DOCKER_EXTRA_ARGS}"
docker run --name "${DOCKER_NAME}" "${DOCKER_ARGS[@]}" ${GEODESIC_DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} -l $*
docker run --name "${DOCKER_NAME}" "${DOCKER_LAUNCH_ARGS[@]}" "${DOCKER_EXEC_ARGS[@]}" ${GEODESIC_DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} -l $*
Copy link

@coderabbitai coderabbitai bot Feb 20, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

(Repeated) Ensure Proper Quoting in ONE_SHELL Branch

As mentioned earlier, please change unquoted $* in the ONE_SHELL branch command invocation to "$@" to prevent issues with argument splitting.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 595-595: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)


🛠️ Refactor suggestion

Use Quoted Argument Handling in Docker Run Command

In the ONE_SHELL branch, the Docker run command currently expands additional arguments via $*. This can lead to word-splitting issues when arguments contain spaces. A more robust solution is to use "$@" to preserve argument boundaries. For example:

- docker run --name "${DOCKER_NAME}" "${DOCKER_LAUNCH_ARGS[@]}" "${DOCKER_EXEC_ARGS[@]}" ${GEODESIC_DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} -l $*
+ docker run --name "${DOCKER_NAME}" "${DOCKER_LAUNCH_ARGS[@]}" "${DOCKER_EXEC_ARGS[@]}" ${GEODESIC_DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} -l "$@"

This change ensures that each argument is correctly passed to the container.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
docker run --name "${DOCKER_NAME}" "${DOCKER_LAUNCH_ARGS[@]}" "${DOCKER_EXEC_ARGS[@]}" ${GEODESIC_DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} -l $*
docker run --name "${DOCKER_NAME}" "${DOCKER_LAUNCH_ARGS[@]}" "${DOCKER_EXEC_ARGS[@]}" ${GEODESIC_DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} -l "$@"
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 595-595: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allowing word splitting is intentional

Copy link

Choose a reason for hiding this comment

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

@Nuru Understood, I'll make note of this intentional design choice. Thank you for the clarification.


✏️ Learnings added
Learnt from: Nuru
PR: cloudposse/geodesic#970
File: rootfs/templates/wrapper-body.sh:595-595
Timestamp: 2025-02-20T06:20:41.294Z
Learning: In the Geodesic wrapper script's ONE_SHELL branch, word splitting with `$*` in the Docker run command is intentional and should not be changed to `"$@"`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment on lines 607 to 610
[ -t 0 ] && DOCKER_EXEC_ARGS+=(-it)
# We set unusual detach keys because (a) the default first char is ctrl-p, which is used for command history,
# and (b) if you detach from the shell, there is no way to reattach to it, so we want to effectively disable detach.
docker exec --env G_HOST_PID=$$ --detach-keys "ctrl-^,ctrl-[,ctrl-@" "${DOCKER_EXEC_ARGS[@]}" "${DOCKER_NAME}" $*
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure Robust Argument Handling in Docker Exec

Similarly, in the docker exec command within the non-ONE_SHELL branch, replace $* with "$@" to preserve argument boundaries and avoid potential splitting issues.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 610-610: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (9)
rootfs/templates/wrapper-body.sh (4)

256-258: Consider Robust Splitting in Shell Count Calculation
In _running_shell_count(), the line

local count=($(_running_shell_pids || true))

splits the output into an array. This construction can be fragile if the output contains unexpected whitespace. Consider using a more robust method (e.g. using mapfile -t or read -a) if your Bash version permits.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 256-256: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


272-304: Review of wait_for_container_exit() Logic
The new wait_for_container_exit() function implements a looping mechanism to periodically check for container and shell status before taking action. The logic is generally sound; however, note that resetting the loop counter (i=0) upon detecting container exit may be non-obvious to future maintainers. Consider adding a comment explaining this design choice or using a dedicated flag variable for clarity.


318-320: Array Splitting in run_exit_hooks(): Shell PID Retrieval & Filtering
Within run_exit_hooks(), the assignment to local variables using:

local our_shell_pid=$(_our_shell_pid)
local shell_pids=($(_running_shell_pids))

and the subsequent filtering via:

shell_pids=($(printf "%s\n" "${shell_pids[@]}" | grep -v "^$our_shell_pid\$"))

relies on word splitting that can be error‐prone if any output contains spaces or unusual characters. For improved robustness, consider using mapfile -t or a similar mechanism to split the output based on newline delimiters.

Also applies to: 327-330

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 318-318: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 319-319: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


343-356: Waiting Loop for Our Shell Exit
The loop that waits for the current shell to finish exiting (using a counter and sleep intervals) is clear and achieves its purpose. However, the repeated “wait” pattern in both this block and in wait_for_container_exit() could be refactored into a helper to avoid duplication and improve maintainability.

ReleaseNotes-v4.md (5)

541-553: Customization Command-Line Options Clarity & Wordiness
This added block detailing new command-line options (such as --no-custom, --trace, --dark, and --light) is generally clear. However, note that in list item 3 the phrase “with respect to light/dark mode support” (around line 549) might be a bit wordy. Consider replacing it with a shorter alternative (for example, “regarding light/dark support”). Also, review the flow in these bullet points to ensure varied sentence beginnings, as starting consecutive sentences with “If you…” may sound repetitive.

🧰 Tools
🪛 LanguageTool

[style] ~548-~548: ‘with respect to’ might be wordy. Consider a shorter alternative.
Context: ...zations, terminal configuration (mainly with respect to light/dark mode support), and the deter...

(EN_WORDINESS_PREMIUM_WITH_RESPECT_TO)


580-588: Experimental Detection of Theme Changes While Running
This section properly documents the experimental nature of automatic theme change detection and its limitations. It provides useful context about why the feature is disabled by default. Please verify the minor grammatical construction (e.g. ensuring that countable nouns following “in” are correctly preceded by an article where needed).

🧰 Tools
🪛 LanguageTool

[grammar] ~580-~580: Before the countable noun ‘in’ an article or a possessive pronoun is necessary.
Context: ...ns.sh` file. #### Detecting changes in theme while running (experimental) You may h...

(IN_NN_CC_VBG)


596-603: Terminal Theme Setting Behavior and Query Instructions
This segment explains what happens when an argument is provided versus when none is given, and it guides the user on how to query the cached theme with get-terminal-theme. While the explanation is clear, consider varying the sentence starters if three successive sentences begin the same way.

🧰 Tools
🪛 LanguageTool

[style] ~596-~596: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...et the terminal theme to that argument. If you do not provide an argument, it will...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


614-617: Disclaimer on Theme Update Limitations
The disclaimer on the limitations and the disabled-by-default status of the automatic theme change detection is appropriately cautious. It might be beneficial to slightly rephrase for clarity, but the current wording effectively sets user expectations.


676-677: Clarification on Yellow/Magenta Usage in Light Mode
The note on how yellow is too light in light mode and is therefore replaced with magenta is informative. However, it may seem slightly contradictory to discourage using magenta when it is the substitute. A brief clarification—explaining that while the substitution happens automatically, users should avoid explicitly using magenta to prevent visual ambiguity—might improve the clarity.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90befb0 and 44f59ae.

📒 Files selected for processing (2)
  • ReleaseNotes-v4.md (5 hunks)
  • rootfs/templates/wrapper-body.sh (12 hunks)
🧰 Additional context used
🧠 Learnings (1)
rootfs/templates/wrapper-body.sh (3)
Learnt from: Nuru
PR: cloudposse/geodesic#970
File: rootfs/templates/wrapper-body.sh:595-595
Timestamp: 2025-02-20T06:20:41.753Z
Learning: In the Geodesic wrapper script's ONE_SHELL branch, word splitting with `$*` in the Docker run command is intentional and should not be changed to `"$@"`.
Learnt from: Nuru
PR: cloudposse/geodesic#961
File: rootfs/templates/wrapper-body.sh:304-304
Timestamp: 2025-01-28T06:17:36.167Z
Learning: In the Geodesic codebase, the use of `$*` instead of `"$@"` in Docker commands is intentional, particularly in wrapper scripts that pass arguments to `docker exec` and `docker run` commands.
Learnt from: Nuru
PR: cloudposse/geodesic#970
File: rootfs/templates/wrapper-body.sh:603-607
Timestamp: 2025-02-20T06:20:15.610Z
Learning: In the Geodesic wrapper script's Docker exec command, using unquoted `$*` for argument expansion is intentional to allow word splitting, rather than using `"$@"` which would preserve argument boundaries.
🪛 Shellcheck (0.10.0)
rootfs/templates/wrapper-body.sh

[warning] 256-256: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 318-318: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 319-319: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 330-330: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[warning] 384-384: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 486-486: Expanding an array without an index only gives the first element.

(SC2128)


[warning] 582-582: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 582-582: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)


[warning] 584-584: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)

🪛 LanguageTool
ReleaseNotes-v4.md

[style] ~548-~548: ‘with respect to’ might be wordy. Consider a shorter alternative.
Context: ...zations, terminal configuration (mainly with respect to light/dark mode support), and the deter...

(EN_WORDINESS_PREMIUM_WITH_RESPECT_TO)


[grammar] ~580-~580: Before the countable noun ‘in’ an article or a possessive pronoun is necessary.
Context: ...ns.sh` file. #### Detecting changes in theme while running (experimental) You may h...

(IN_NN_CC_VBG)


[style] ~596-~596: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...et the terminal theme to that argument. If you do not provide an argument, it will...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-push (debian)
🔇 Additional comments (15)
rootfs/templates/wrapper-body.sh (8)

120-125: Terminal Theme Options Added
The addition of the --dark and --light options in the parse_args() function is clear and aligns with the PR objectives to offer manual control over terminal colors. This implementation correctly sets the GEODESIC_TERM_THEME variable based on user selection.


182-193: Updated Help Text for New Options
The help function now reflects the new terminal theme options (and other updates) with accurate usage instructions. This helps users understand how to set the terminal theme explicitly.


247-249: New Helper Function: _running_shell_pids()
The newly introduced _running_shell_pids() function encapsulates the logic for fetching running shell PIDs via a docker exec call. This improves the modularity of the shell management code.


251-253: New Helper Function: _our_shell_pid()
The _our_shell_pid() function is added to isolate the logic needed to retrieve the current shell’s PID. The use of a fallback with || true is acceptable here since the intended behavior is to avoid unexpected exits.


366-373: Setting Wrapper PID and Docker Exec Arguments
Assigning the current shell’s PID to WRAPPER_PID and initializing DOCKER_EXEC_ARGS is straightforward. This setup is important for correlating executed shells with their wrapper process and looks correct.


591-597: Docker Run Command in ONE_SHELL Branch
In the ONE_SHELL branch, the code modifies DOCKER_NAME by appending a timestamp and then launches a container via docker run. Note that while GEODESIC_DOCKER_EXTRA_ARGS is intentionally left unquoted (as documented) to allow it to represent a list of arguments, the final command correctly uses "$@" for passing the remaining parameters. This aligns with the PR objectives and the intentional design choices communicated via learnings.


608-612: Docker Exec Command for Existing Containers
For the non-ONE_SHELL branch, the script uses a docker exec call to attach to an already running container. The construction (including the use of unusual detach keys and conditionally appending -it) is appropriate and consistent with the project’s design decisions.


543-549: Workspace Mounting and DOCKER_LAUNCH_ARGS Setup
The block that appends workspace mounting configurations to DOCKER_LAUNCH_ARGS clearly constructs the necessary docker run options for host directory mounts. The use of unquoted variables in this context (for variables like mount_dir) is acceptable given the controlled input paths. Overall, this segment is well-structured and aligns with the intended shell-to-container mapping improvements.

ReleaseNotes-v4.md (7)

247-256: TF_PLUGIN_CACHE_DIR Opt‐Out Documentation
This section clearly explains the new behavior for the Terraform Provider Plugin Cache. The explanation of how Geodesic now “unsets” the variable when it is empty, "false", or "disabled" is concise and informs users how to opt out. Please double‑check that the conditions documented here match the implementation in the code.


561-571: Section on Switching Between Light and Dark Themes
The new “Switching between light and dark themes” section succinctly describes Geodesic’s basic support for terminal themes. The explanation of why different colors are used (e.g. “black in light mode and white in dark mode”) is clear. Minor stylistic improvements are possible, but overall this segment is informative and well‑structured.


572-579: Initial Terminal Theme Detection Details
This hunk explains the critical nature of detecting the terminal theme at startup and specifies how users can override the automatic detection. The instructions are straightforward.


590-595: Manual Notification of Theme Changes
The instructions for manually notifying Geodesic of a theme change using the set-terminal-theme [light|dark] command are clear and are well‑demonstrated with a formatted code block.


605-613: SIGWINCH and Automatic Theme Update Behavior
This section gives a detailed account of how Geodesic leverages the SIGWINCH signal for detecting terminal changes and outlines the role of the GEODESIC_TERM_THEME_AUTO variable. The explanation is thorough and should help users troubleshoot if the terminal does not respond promptly.


623-623: Named Text Color Helpers Explanation
By adding details about the provided named text color helpers and the reasoning behind avoiding certain colors, this segment is very helpful. The text clearly explains that colors like blue and magenta are avoided due to potential issues in dark mode and that yellow is substituted in light mode. This guidance should help users choose colors appropriately in their customizations.

Also applies to: 635-640


723-724: Environment Variable Changes for Terminal Theme Settings
This part documents the changes to GEODESIC_TERM_THEME and GEODESIC_TERM_THEME_AUTO comprehensively. It clearly instructs users on when and how to set these environment variables. The clear technical specification aligns well with the update objectives.

@Nuru Nuru merged commit cdf5e15 into main Feb 20, 2025
4 checks passed
@Nuru Nuru deleted the v4-better-tracking branch February 20, 2025 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant