Claude's answers, rendered: Markdown, math, charts and diagrams drawn in the Claude Code terminal. Independent project, not affiliated with Anthropic.
TypeScript claude-code-mod
Installer and /iui setup: fixes of the merge review (package I)
razorback16d3e15c338a30
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex eb79b03..43c94e6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,13 +11,15 @@ All releases of Intelligent UI for Claude Code (`cc-intelligent-ui`). Claude Cod- **herdr in iTerm2.** iTerm2 shows each row of a herdr picture from the bottom of the image, so the rows of a page showed in the wrong order. When the herdr client in use is iTerm2, the mod stores the bands of rows of each page and picture in reverse order. Then iTerm2 shows them in the correct order. `/iui details` shows `pages and pictures stored upside down by rows` when this is on. It does not work with `herdr --remote` in iTerm2.- `/iui setup` works in herdr on Linux too.- `/iui details` names herdr, its version, the terminal that it runs in and how the mod found that terminal, for example `herdr 0.9.5 (in kitty, the terminal in front)`. If the mod uses the variables of the herdr server, it shows `(in Ghostty, from the server's start)`.-- **A one-line installer.** `curl -fsSL https://intelligentui.art/install.sh | bash` checks the system and Claude Code, installs Typst 0.15.1 when no Typst 0.15 or later is found (the official release from GitHub, checked against a SHA-256 in the script, into `~/.local/bin`), adds the `razorback16` marketplace and installs the mod with the `claude plugin` commands (a `razorback16` marketplace from another source, such as a fork, a pinned ref or a local folder, is added again from GitHub; a second user copy from another marketplace is uninstalled), and turns on auto-update for the marketplace in `~/.claude/settings.json` (`extraKnownMarketplaces`, with a backup of the file before the auto-update change; all other settings stay byte for byte). Run it again to update. It never uses `sudo`. When iTerm2 or herdr is there, it also adds the mod's `/iui setup` block to your shell's start file (with a backup). `IUI_NO_TYPST=1`, `IUI_NO_AUTO_UPDATE=1` and `IUI_NO_SHELL_SETUP=1` skip a step. Refer to [The install script](docs/install.md#the-install-script).+- **A one-line installer.** `curl -fsSL https://intelligentui.art/install.sh | bash` checks the system and Claude Code, installs Typst 0.15.1 when no Typst 0.15 or later is found (the official release from GitHub, checked against a SHA-256 in the script, into `~/.local/bin`), adds the `razorback16` marketplace and installs the mod with the `claude plugin` commands (a `razorback16` marketplace from another source, such as a fork, a pinned ref or a local folder, is added again from GitHub; a second user copy from another marketplace is uninstalled), and turns on auto-update for the marketplace in `~/.claude/settings.json` (`extraKnownMarketplaces`, with a backup of the file before the auto-update change; all other settings stay byte for byte; an `"autoUpdate": false` that you set stays). Run it again to update. It never uses `sudo`. When iTerm2 or herdr is there, it also adds the mod's `/iui setup` block to your shell's start file (with a backup). `IUI_NO_TYPST=1`, `IUI_NO_AUTO_UPDATE=1` and `IUI_NO_SHELL_SETUP=1` skip a step. Refer to [The install script](docs/install.md#the-install-script).### Fixed- **The newest copy wins.** A click, a picture selection's up, `/iui grab` and the `ui.copy` change of picture cells each read their text first. An older one that was still reading wrote the clipboard over a newer copy. Now it writes nothing when a newer copy came: a newer click or up, a `$.ui.copy` (another plugin's, or the command button of a link row), Claude Code's own copy of a selection, or a copy in another app. A `ui.copy` change that lost its turn is refused. `/iui grab`, a click on no target and an up with no text copy nothing and cancel no other copy. An older copy (a click, an up, `/iui grab` or a `ui.copy` change) waits for a newer click or up that still reads its text, so it never writes first and is then overwritten. A copy in another app counts from the time the clipboard changed, not from the time the mod read it.- **A password manager's copy is never read.** On macOS the mod reads the clipboard with a short `perl` script (PerlObjCBridge) in place of `pbpaste`, and stops at a copy with a concealed or transient type. On Linux, `xclip`, `wl-paste` and GTK look for the `x-kde-passwordManagerHint` target before and after the read. On Wayland, a copy marked sensitive was skipped already.- **The code in an answer can read no other file.** Each compile of an answer or a plan had `/` as its Typst root, so a Typst block could read any file (`read`, `include`, `image`, `json`, `csv`), and `read("/dev/zero")` used all the memory. Now each compile runs in a root of its own, with only the template, the theme and the answer's images. The skill's `check.sh` does the same, and it stops with an error when its cache folder is a link or not yours. Pictures are the same as before.+- `/iui setup` with bash on macOS writes the first of `~/.bash_profile`, `~/.bash_login` and `~/.profile` that exists. Before, it made `~/.bash_profile`, and a login bash then no longer read `~/.profile`.+- In a session that shows pictures already, `/iui setup` says so, not to open a new tab.- `/iui setup`, `/iui setup remove` and the setup question never write a shell start file that they cannot read (no permission, or too large). Before, such a file was replaced with only the Intelligent UI block. Now the mod changes no file and shows the line to add.- **Plan mode:** when Claude Code runs two `ExitPlanMode` calls at once, the mod does not ask its question, so the answer for one plan can not go to the other (a rejected plan was allowed). Claude Code's own dialog asks.- `/iui theme` runs one at a time: an older `/iui theme` that was still loading no longer sets its theme over a newer one. A setting that you change with `/iui` while the mod starts is kept (before, the start set it back to the stored value).diff --git a/README.md b/README.mdindex dedc60e..fbe45c4 100644--- a/README.md+++ b/README.md@@ -26,9 +26,9 @@ What `install.sh` does:1. It checks that the system is macOS or Linux (arm64 or x86_64) and that Claude Code is installed. If Claude Code is not installed, it stops and changes nothing.2. If it finds no Typst 0.15 or later, it downloads the official Typst 0.15.1 release from GitHub, checks its SHA-256 (written in the script), and puts `typst` in `~/.local/bin`. It never uses `sudo`.-3. It adds the `razorback16` marketplace and installs the mod with the `claude plugin` commands. If they are installed, it updates them. If your `razorback16` marketplace comes from another source (a fork, a pinned ref or a local folder), an update can not get the newest version: the script removes that marketplace, adds it again from GitHub and installs the mod again (a disabled mod stays disabled). It uninstalls a second user copy of the mod from another marketplace, and only shows copies in a project. It tells you each change and how to undo it.-4. It turns on auto-update for the `razorback16` marketplace: `"autoUpdate": true` for `razorback16` in `extraKnownMarketplaces` of `~/.claude/settings.json`. It keeps all other settings and keeps the file before this change as `settings.json.bak-iui` (step 3 changed the file already; the backup undoes only the auto-update change). If the file is not valid JSON, the script does not change it and shows the lines to add.-5. If iTerm2 or herdr is there, it adds the mod's own `/iui setup` block to the start file of your login shell (`~/.zshrc`, `~/.bash_profile` on macOS, `~/.bashrc` on Linux, or a fish `conf.d` file), with a backup `<file>.bak-iui`. The block sets `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` in iTerm2 and herdr only. Undo: `/iui setup remove` in Claude Code.+3. It adds the `razorback16` marketplace and installs the mod with the `claude plugin` commands. If they are installed, it updates them. If your `razorback16` marketplace comes from another source (a fork, a pinned ref or a local folder), an update can not get the newest version: the script adds it again from GitHub and updates the mod (if Claude Code uninstalled it with the old marketplace, the script installs it again; a disabled mod stays disabled). It uninstalls a second user copy of the mod from another marketplace, and only shows copies in a project. It tells you each change and how to undo it.+4. It turns on auto-update for the `razorback16` marketplace: `"autoUpdate": true` for `razorback16` in `extraKnownMarketplaces` of `~/.claude/settings.json`. If you turned auto-update off (`"autoUpdate": false`), it stays off. It keeps all other settings and keeps the file before this change as `settings.json.bak-iui` (step 3 changed the file already; the backup undoes only the auto-update change). If the file is not valid JSON, the script does not change it and shows the lines to add.+5. If iTerm2 or herdr is there, it adds the mod's own `/iui setup` block to the start file of your login shell (`~/.zshrc`; for bash, `~/.bashrc` on Linux, or on macOS the first of `~/.bash_profile`, `~/.bash_login` and `~/.profile` that exists; or a fish `conf.d` file), with a backup `<file>.bak-iui`. The block sets `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` in iTerm2 and herdr only. Undo: `/iui setup remove` in Claude Code.`IUI_NO_TYPST=1` skips step 2, `IUI_NO_AUTO_UPDATE=1` skips step 4, and `IUI_NO_SHELL_SETUP=1` skips step 5, for example `curl -fsSL https://intelligentui.art/install.sh | IUI_NO_AUTO_UPDATE=1 bash`.diff --git a/docs/development.md b/docs/development.mdindex 8e39f56..ee60f4a 100644--- a/docs/development.md+++ b/docs/development.md@@ -26,6 +26,14 @@ claude plugin validate .`.claude-plugin/types/` is not in git. `tsconfig.json` extends the `tsconfig.json` in it, so run Claude Code with the folder once before `tsc`.+## Release++Claude Code updates the mod only when the `version` in `.claude-plugin/plugin.json` changes. For a release, change the version and `CHANGELOG.md`, run the tests above, and tag the commit `v<version>`. Deploy the site together with the release: it serves `site/install.sh` at https://intelligentui.art/install.sh. After the deploy, check that the script is there:++```+curl -fsSL https://intelligentui.art/install.sh | head -1 # #!/usr/bin/env bash+```+## Debug logSet `IUI_DEBUG=1` before you start Claude Code. The mod then writes trace lines to `debug.log` in the cache folder (`${TMPDIR}/cc-intelligent-ui-<uid>/`, `/tmp` when `TMPDIR` is not set).diff --git a/docs/install.md b/docs/install.mdindex d086820..502f828 100644--- a/docs/install.md+++ b/docs/install.md@@ -12,8 +12,9 @@## Terminals- **kitty (0.28 or later), Ghostty and cmux (Ghostty inside, macOS only):** pictures work with no setting. kitty and Ghostty work on macOS and on Linux.-- **iTerm2 3.6 or later (3.7.5 tested, macOS only):** Claude Code needs `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` when it starts. A mod cannot set it early enough. The first time the mod runs in iTerm2, it asks to add one line to your shell's start file (`~/.zshrc`, `~/.bash_profile` or a fish `conf.d` file). The line sets the variable in iTerm2 and herdr only, not in tmux or screen. Then close the tab, open a new iTerm2 tab, and start Claude Code there. You can also run `/iui setup` (undo: `/iui setup remove`).+- **iTerm2 3.6 or later (3.7.5 tested, macOS only):** Claude Code needs `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` when it starts. A mod cannot set it early enough. The first time the mod runs in iTerm2, it asks to add one line to your shell's start file (`~/.zshrc`, a fish `conf.d` file, or for bash on macOS the first of `~/.bash_profile`, `~/.bash_login` and `~/.profile` that exists; it makes `~/.bash_profile` only when none of them exists). The line sets the variable in iTerm2 and herdr only, not in tmux or screen. Then close the tab, open a new iTerm2 tab, and start Claude Code there. You can also run `/iui setup` (undo: `/iui setup remove`).- **herdr (0.9.5 tested, in Ghostty and iTerm2):** herdr is a terminal multiplexer. It draws the pictures of its panes in the terminal that it runs in, so that terminal must show kitty pictures (kitty, Ghostty or iTerm2 3.6 or later). Claude Code needs `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` in herdr too. The first time the mod runs in a herdr pane, it asks to add the same line to your shell's start file. If the file has the line of an older version (iTerm2 only), the mod asks to update it. Then close the pane, open a new herdr pane, and start Claude Code there. You can also run `/iui setup` (undo: `/iui setup remove`). herdr works on macOS and on Linux.+ - herdr runs the shell of `SHELL` in its panes. If herdr starts with no `SHELL` in its environment (for example from a launcher or a service), its panes run `/bin/sh`, which does not read your shell's start file, so the line has no effect. Start herdr from a normal shell, or set `SHELL` for it.- herdr hides the name of the terminal that it runs in. With the `auto` theme, the mod gets the background from herdr: herdr gives the background of the terminal in front. This also works with `herdr --remote`.- For the font, the mod finds the herdr client that you use. You can attach to one herdr server from more than one terminal (for example Ghostty and kitty). On macOS, the mod uses the client in the terminal app in front. If that app has two or more clients, it uses the one where you typed last. If the app in front has no client (for example, a browser), the mod keeps the client that it used before. On Linux, the mod uses the client where you typed last. The mod does not use only the place where you typed last on macOS, because iTerm2 answers each picture that herdr sends, and that looks like typing in iTerm2. The mod reads the variables and the terminal app of that client, then reads the font of that terminal. When you go to a different terminal, the mod finds it at the next check (every 1 s) and draws the pictures again with that font. If you attach a new client in the app that is in front, or on Linux, the mod can find it only at the full check (every 10 s). If the mod cannot find a client, it uses the variables that herdr keeps of the terminal that started the herdr server (`GHOSTTY_RESOURCES_DIR` for Ghostty, `KITTY_PID` for kitty, `ITERM_PROFILE` for iTerm2). `/iui details` shows the terminal and how the mod found it, for example `herdr 0.9.5 (in Ghostty, the terminal in front)`, `herdr 0.9.5 (in kitty, the client you used last)` or `herdr 0.9.5 (in Ghostty, from the server's start)`.- Pages are shorter in herdr, so that herdr can send each one to the terminal. Refer to [Limitations](limitations.md).@@ -55,12 +56,12 @@ You can also download the script, read it, and run it with `bash install.sh`. ItThe script does these steps, in this order:1. **Checks.** The system must be macOS or Linux, on arm64 or x86_64. The `claude` command must be on your `PATH` (or in `~/.local/bin` or `~/.claude/local`). If Claude Code is not installed, the script tells you where to get it ([Set up Claude Code](https://code.claude.com/docs/en/setup)), changes nothing, and stops with exit code 1. If Claude Code is older than 2.1.298, it shows a warning and continues.-2. **Typst.** The script looks for Typst as the mod does: on the `PATH`, then in `/opt/homebrew/bin`, `/usr/local/bin`, `/usr/bin`, `/snap/bin`, `~/.cargo/bin`, `~/.local/bin`, `/home/linuxbrew/.linuxbrew/bin` and `~/.linuxbrew/bin`. If the first Typst that it finds is 0.15 or later, it changes nothing. If not, it downloads the official Typst 0.15.1 release file for your system from [github.com/typst/typst/releases](https://github.com/typst/typst/releases/tag/v0.15.1) (`typst-aarch64-apple-darwin`, `typst-x86_64-apple-darwin`, `typst-aarch64-unknown-linux-musl` or `typst-x86_64-unknown-linux-musl`, `.tar.xz`), with `curl` over HTTPS only. It compares the file's SHA-256 with the value written in the script. If they are not the same, it deletes the file, installs nothing and stops. Then it extracts the file in a private temporary folder (deleted at the end), makes sure that the program runs, and moves it to `~/.local/bin/typst` in one step. An older `typst` in `~/.local/bin` is replaced. Linux needs `xz` for `tar` (the `xz-utils` package on Debian and Ubuntu). The script tells you when `~/.local/bin` is not on your `PATH` (the mod finds Typst there anyway), and when an older Typst comes first, so that the mod uses that one.+2. **Typst.** The script looks for Typst as the mod does: in the `PATH` of a login shell (`sh -l`; on macOS this puts `/usr/local/bin` first), then on the `PATH`, then in `/opt/homebrew/bin`, `/usr/local/bin`, `/usr/bin`, `/snap/bin`, `~/.cargo/bin`, `~/.local/bin`, `/home/linuxbrew/.linuxbrew/bin` and `~/.linuxbrew/bin`. If the first Typst that it finds is 0.15 or later, it changes nothing. If not, it downloads the official Typst 0.15.1 release file for your system from [github.com/typst/typst/releases](https://github.com/typst/typst/releases/tag/v0.15.1) (`typst-aarch64-apple-darwin`, `typst-x86_64-apple-darwin`, `typst-aarch64-unknown-linux-musl` or `typst-x86_64-unknown-linux-musl`, `.tar.xz`), with `curl` over HTTPS only. It compares the file's SHA-256 with the value written in the script. If they are not the same, it deletes the file, installs nothing and stops. Then it extracts the file in a private temporary folder (deleted at the end), makes sure that the program runs, and moves it to `~/.local/bin/typst` in one step. An older `typst` in `~/.local/bin` is replaced. Linux needs `xz` for `tar` (the `xz-utils` package on Debian and Ubuntu). The script tells you when `~/.local/bin` is not on your `PATH` (the mod finds Typst there anyway), and when an older Typst comes first, so that the mod uses that one.3. **The mod.** With the Claude Code commands only. If the `razorback16` marketplace is not known (`claude plugin marketplace list`), it runs `claude plugin marketplace add razorback16/cc-intelligent-ui`; else `claude plugin marketplace update razorback16`. Then, if the mod is not installed for your user (`claude plugin list`), it runs `claude plugin install cc-intelligent-ui@razorback16 --scope user`; else `claude plugin update cc-intelligent-ui@razorback16 --scope user`. The script shows each command before it runs it.- The script gets the newest version only from the official source: the GitHub repository `razorback16/cc-intelligent-ui` (or its `https://github.com/...` git URL) with no ref. If the `razorback16` marketplace comes from another source, for example a fork, a pinned ref (`#v0.3.0`) or a local folder, an update can not get the newest version. Then the script runs `claude plugin marketplace remove razorback16 --scope user` and `claude plugin marketplace add razorback16/cc-intelligent-ui`, and installs the mod again. Claude Code 2.1.307 uninstalls the mod (also its copies in projects) when it removes the marketplace; your `/iui` settings are kept, because Claude Code keeps them under the name `cc-intelligent-ui@razorback16`. If the mod was disabled, the script disables it again. The script shows the old source and the command to add it back. If the old source had a newer version (for example a work folder), the script says so.+ The script gets the newest version only from the official source: the GitHub repository `razorback16/cc-intelligent-ui` (or its `https://github.com/...` git URL) with no ref. If the `razorback16` marketplace comes from another source, for example a fork, a pinned ref (`#v0.3.0`) or a local folder, an update can not get the newest version. Then, if your user settings (`settings.json`) declare the `razorback16` marketplace, the script runs `claude plugin marketplace remove razorback16 --scope user` (this removes only that entry) and `claude plugin marketplace add razorback16/cc-intelligent-ui`. If they do not declare it (an older Claude Code added it, or another scope declares it), `remove --scope user` would fail, so the script runs only `claude plugin marketplace add razorback16/cc-intelligent-ui`, which changes the source by itself. Then it updates the mod. Claude Code can uninstall the mod (also its copies in projects) with the old marketplace; if it does, the script installs the mod again. Your `/iui` settings are kept, because Claude Code keeps them under the name `cc-intelligent-ui@razorback16`. If the mod was disabled, it stays disabled. The script shows the old source and the command to add it back. If the old source had a newer version (for example a work folder), the script says so.- If a copy of the mod from another marketplace is installed for your user (for example `cc-intelligent-ui@other`), both copies would run. The script uninstalls that copy after the `razorback16` copy is installed, and shows the command to install it again. The script does not change copies in project or local scope. It shows each one, with its project folder and the command to remove it, because in that project such a copy can be used instead of the user copy.+ If a copy of the mod from another marketplace is installed for your user (for example `cc-intelligent-ui@other`), both copies would run. The script uninstalls that copy after the `razorback16` copy is installed, and shows the command to install it again. A copy with no marketplace (`cc-intelligent-ui@skills-dir` in a skills folder of Claude Code, or `cc-intelligent-ui@inline` from `--plugin-dir`) can not be uninstalled with `claude plugin`: the script shows it with its folder and does not change it. The `razorback16` copy is used, not that one. The script does not change copies in project or local scope. It shows each one, with its project folder and the command to remove it, because in that project such a copy can be used instead of the user copy.If the update of the mod or of the marketplace fails, the summary says that the mod was not updated (not that the newest version is installed), and the script ends with exit code 1.4. **Auto-update.** The script sets this entry in your user settings, `~/.claude/settings.json` (or `$CLAUDE_CONFIG_DIR/settings.json`). This is the setting that Claude Code documents for a marketplace in `extraKnownMarketplaces`:@@ -74,8 +75,8 @@ The script does these steps, in this order:}```- `claude plugin marketplace add` already writes the `razorback16` entry with its `source`; the script adds `"autoUpdate": true` to it. It changes only that: all other bytes of the file (keys, their order, values, spaces) stay the same. It writes a new file in the same folder and then renames it over the old one, with the same permissions. If `settings.json` is a link, the file that it points to changes. It keeps the file before this change as `settings.json.bak-iui`, only when it changed the file. Step 3 (`claude plugin marketplace add` and `install`) changed `settings.json` already, so the backup undoes only the auto-update change, not step 3. If the file is not there, it makes it. If `autoUpdate` is `true` already, it changes nothing. If the `razorback16` entry has another `source`, the script does not change the file. If the file is not valid JSON (for example, it has comments), the script changes nothing, shows the entry to add, and ends with exit code 1. It uses `perl` (no modules) to read and change the JSON. It never uses `sed` on JSON.-5. **Pictures in iTerm2 and herdr.** Claude Code shows pictures in iTerm2 and herdr only when `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` is set when it starts. If iTerm2 is installed (macOS: `/Applications/iTerm.app`, `~/Applications/iTerm.app`, or Spotlight finds it) or `herdr` is there (on the `PATH` or in the folders of step 2), the script adds the mod's own block, the same that `/iui setup` adds, to the start file of your login shell (from `SHELL`): `${ZDOTDIR:-~}/.zshrc` for zsh, `~/.bash_profile` (macOS) or `~/.bashrc` (Linux) for bash, `${XDG_CONFIG_HOME:-~/.config}/fish/conf.d/cc-intelligent-ui.fish` for fish. The block is between the lines `# >>> cc-intelligent-ui: Claude Code pictures in iTerm2 >>>` and `# <<< cc-intelligent-ui <<<`. It sets the variable in iTerm2 and herdr only, not in tmux or screen. An older block of the mod is replaced, not added again; if the block is there already, nothing changes. If the file is a link, the file that it points to changes. The script writes a new file in the same folder and renames it over the old one, with the same permissions, and keeps the old file as `<file>.bak-iui`. If the file can not be read, is not a regular file, or is larger than 4 MB, the script changes nothing, shows the lines to add, and ends with exit code 1. For another shell, it changes nothing and shows the line to add. Undo: `/iui setup remove` in Claude Code, or delete the marked lines.+ `claude plugin marketplace add` already writes the `razorback16` entry with its `source`; the script adds `"autoUpdate": true` to it. It changes only that: all other bytes of the file (keys, their order, values, spaces) stay the same. It writes a new file in the same folder and then renames it over the old one, with the same permissions. If `settings.json` is a link, the file that it points to changes. It keeps the file before this change as `settings.json.bak-iui`, only when it changed the file. Step 3 (`claude plugin marketplace add` and `install`) changed `settings.json` already, so the backup undoes only the auto-update change, not step 3. If the file is not there, it makes it. If `autoUpdate` is `true` already, it changes nothing. If `autoUpdate` is `false` (you selected **Disable auto-update**), the script keeps it, says that auto-update is off by your choice, and tells you how to turn it on. When it adds the marketplace again from GitHub (step 3), it keeps `"autoUpdate": false` for the new entry. If the file is read-only, or has more than one name (a hard link), the script does not change it. If the `razorback16` entry has another `source`, the script does not change the file. If the file is not valid JSON (for example, it has comments), the script changes nothing, shows the entry to add, and ends with exit code 1. It uses `perl` (no modules) to read and change the JSON. It never uses `sed` on JSON.+5. **Pictures in iTerm2 and herdr.** Claude Code shows pictures in iTerm2 and herdr only when `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` is set when it starts. If iTerm2 is installed (macOS: `/Applications/iTerm.app`, `~/Applications/iTerm.app`, or Spotlight finds it) or `herdr` is there (on the `PATH` or in the folders of step 2), the script adds the mod's own block, the same that `/iui setup` adds, to the start file of your login shell (from `SHELL`): `${ZDOTDIR:-~}/.zshrc` for zsh; for bash, `~/.bashrc` on Linux, and on macOS the first of `~/.bash_profile`, `~/.bash_login` and `~/.profile` that exists (a login bash reads only that one; the script makes `~/.bash_profile` only when none exists); `${XDG_CONFIG_HOME:-~/.config}/fish/conf.d/cc-intelligent-ui.fish` for fish. The block is between the lines `# >>> cc-intelligent-ui: Claude Code pictures in iTerm2 >>>` and `# <<< cc-intelligent-ui <<<`. It sets the variable in iTerm2 and herdr only, not in tmux or screen. An older block of the mod is replaced, not added again; if the block is there already, nothing changes. If the file is a link, the file that it points to changes. The script writes a new file in the same folder and renames it over the old one, with the same permissions, and keeps the old file as `<file>.bak-iui`. If the file can not be read, is not a regular file, is read-only, has more than one name (a hard link), or is larger than 4 MB, the script changes nothing, shows the lines to add, and ends with exit code 1. For another shell, it changes nothing and shows the line to add. Undo: `/iui setup remove` in Claude Code, or delete the marked lines.6. **Summary.** What was installed or updated, where Typst is, the state of auto-update and of the shell setup, and how to undo each step.Options (environment variables):diff --git a/hooks/lib/setup.ts b/hooks/lib/setup.tsindex 884b8c0..393313c 100644--- a/hooks/lib/setup.ts+++ b/hooks/lib/setup.ts@@ -5,6 +5,7 @@ import type { EngineInterface } from 'claude-code'import { S } from './state'import { readText } from './host'import { getenv, exists, write, exec, load, save, ask, log, toast } from './api'+import { isSet } from './terminal'// Claude Code turns pictures on by itself in kitty and Ghostty only; iTerm2// and herdr need CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 when Claude Code starts@@ -15,13 +16,16 @@ import { getenv, exists, write, exec, load, save, ask, log, toast } from './api'export const SETUP_START = '# >>> cc-intelligent-ui: Claude Code pictures in iTerm2 >>>'export const SETUP_END = '# <<< cc-intelligent-ui <<<'export type ShellRc = { path: string; kind: 'sh' | 'fish' }+// The start files of a login bash, in its order: it reads only the first that exists.+export const BASH_LOGIN = ['.bash_profile', '.bash_login', '.profile']// The start file the setup writes for the login shell (`SHELL`); null for a// shell it does not know. iTerm2 (and herdr on macOS) starts login shells:-// bash reads .bash_profile on macOS. fish gets a file of its own in conf.d.-export function shellRcOf(o: { shell: string; home: string; zdotdir?: string; xdgConfig?: string; isMac: boolean }): ShellRc | null {+// bash on macOS gets the first of BASH_LOGIN in `loginFiles` (those in HOME),+// a new .bash_profile only when none is there. fish gets a file of its own in conf.d.+export function shellRcOf(o: { shell: string; home: string; zdotdir?: string; xdgConfig?: string; isMac: boolean; loginFiles?: readonly string[] }): ShellRc | null {const name = o.shell.split('/').pop() ?? ''if (name === 'zsh') return { path: `${o.zdotdir || o.home}/.zshrc`, kind: 'sh' }- if (name === 'bash') return { path: `${o.home}/${o.isMac ? '.bash_profile' : '.bashrc'}`, kind: 'sh' }+ if (name === 'bash') return { path: `${o.home}/${o.isMac ? (BASH_LOGIN.find(f => o.loginFiles?.includes(f)) ?? BASH_LOGIN[0]) : '.bashrc'}`, kind: 'sh' }if (name === 'fish') return { path: `${o.xdgConfig || `${o.home}/.config`}/fish/conf.d/cc-intelligent-ui.fish`, kind: 'fish' }return null}@@ -61,12 +65,21 @@ export function withSetup(text: string, kind: ShellRc['kind']): string {// The shell start file for this user, or null when the shell is not known.async function shellRc($: EngineInterface): Promise<ShellRc | null> {+ const shell = (await getenv($, 'SHELL')) ?? ''+ const home = (await getenv($, 'HOME')) ?? ''+ const isMac = S.hostOs === 'Darwin'+ // Which login files of bash are there (macOS only).+ const loginFiles: string[] = []+ if (isMac && shell.split('/').pop() === 'bash') {+ for (const f of BASH_LOGIN) if (await exists($, `${home}/${f}`).catch(() => false)) loginFiles.push(f)+ }return shellRcOf({- shell: (await getenv($, 'SHELL')) ?? '',- home: (await getenv($, 'HOME')) ?? '',+ shell,+ home,zdotdir: (await getenv($, 'ZDOTDIR')) || undefined,xdgConfig: (await getenv($, 'XDG_CONFIG_HOME')) || undefined,- isMac: S.hostOs === 'Darwin',+ isMac,+ loginFiles,})}@@ -96,7 +109,10 @@ export async function runSetup($: EngineInterface, remove: boolean): Promise<strif (!rc) return `Intelligent UI does not know your shell, so it changed no file. Add this to your shell's start file: ${manual}`const text = await readRc($, rc.path)if (text === null) return `Intelligent UI could not read ${rc.path}, so it changed no file. Add this to it yourself: ${manual}`- const restart = `Close this ${tab}, open a new ${app} ${tab}, and start Claude Code there to see pictures.`+ // Pictures on in this session already: no new tab needed.+ const restart = isSet(await getenv($, 'CLAUDE_CODE_FORCE_TERMINAL_IMAGES'))+ ? `Pictures are on in this ${tab} already.`+ : `Close this ${tab}, open a new ${app} ${tab}, and start Claude Code there to see pictures.`if (remove) {if (!hasSetup(text)) return `${rc.path} has no Intelligent UI block.`await write($, rc.path, withoutSetup(text))diff --git a/site/install.sh b/site/install.shindex ffc8787..cb32c74 100755--- a/site/install.sh+++ b/site/install.sh@@ -14,6 +14,7 @@# copies in a project are not changed, only shown.# 4. Turns on auto-update for the razorback16 marketplace in your Claude Code# settings.json (extraKnownMarketplaces), with a backup of the file before that change.+# An autoUpdate: false that you set is kept.# Run it again to update. It never uses sudo.# 5. When iTerm2 or herdr is there: adds the mod's own /iui setup block (it sets# CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 in iTerm2 and herdr only) to the start file of@@ -163,8 +164,19 @@ typst_version() {"$1" --version < /dev/null 2> /dev/null | awk 'NR == 1 && $1 == "typst" { print $2 }' || true}-# The typst that the mod uses: the PATH first, then TYPST_DIRS in order.-mod_typst() { find_tool typst; }+# The typst that the mod uses (findTypst in hooks/lib/typst.ts): a login+# shell's PATH (macOS puts /usr/local/bin first there), then the PATH, then+# TYPST_DIRS in order.+mod_typst() {+ local p+ p=$(perl -e 'alarm 5; exec @ARGV' sh -lc 'command -v typst' < /dev/null 2> /dev/null | head -n 1 || true)+ case $p in /*)+ printf '%s' "$p"+ return 0+ ;;+ esac+ find_tool typst+}# The program $1: on the PATH, else in TYPST_DIRS in order.find_tool() {@@ -278,13 +290,18 @@ install_typst() {# Exit 1: no such marketplace.# plugin ID stdin: the plugin list; prints the "version" and "enabled" of "id": ID, "scope": "user"# copies NAME stdin: the plugin list; prints "id TAB scope TAB version TAB enabled TAB projectPath"-# for each copy of the plugin NAME (any marketplace, any scope)-# settings FILE BACKUP sets extraKnownMarketplaces.razorback16 (source and autoUpdate: true)-# in FILE; prints created, changed or unchanged. Exit 2: not changed (the reason on stdout).+# for each copy of the plugin NAME (any marketplace, any scope); a copy with no+# marketplace (@skills-dir, @inline) has its folder (installPath) for projectPath+# entry FILE prints declared, or off (autoUpdate: false), for extraKnownMarketplaces.razorback16+# in FILE. Exit 1: not there. Exit 2: FILE can not be read.+# settings FILE BACKUP [OFF]+# sets extraKnownMarketplaces.razorback16 (source and autoUpdate: true, or false with OFF)+# in FILE; prints created, changed, unchanged or off (false already, kept).+# Exit 2: not changed (the reason on stdout).# Exit 3: stdin is not a JSON array.json_pl() {cat << 'PERL'-use strict; use warnings;+use strict; use warnings; no warnings 'recursion';use Fcntl;my ($mode, @args) = @ARGV;my $s;@@ -296,9 +313,12 @@ sub str {$s =~ /\G"((?:[^"\\\x00-\x1f]++|\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4}))*+)"/gc or err('a string');my $r = $1;my %e = (n => "\n", t => "\t", b => "\b", f => "\f", r => "\r");- $r =~ s{\\(?:u([0-9a-fA-F]{4})|(.))}{defined $1 ? chr(hex $1) : ($e{$2} // $2)}ge;+ # \u escapes as UTF-8 bytes (a pair for a character past U+FFFF), as the file's own bytes.+ $r =~ s{\\u([dD][89abAB][0-9a-fA-F]{2})\\u([dD][c-fC-F][0-9a-fA-F]{2})|\\u([0-9a-fA-F]{4})|\\(.)}+ {defined $1 ? u8(0x10000 + ((hex($1) - 0xD800) << 10) + hex($2) - 0xDC00) : defined $3 ? u8(hex $3) : ($e{$4} // $4)}ge;return $r;}+sub u8 { my $c = chr(shift); utf8::encode($c); return $c }sub val {ws();my $b = pos($s);@@ -356,8 +376,8 @@ sub member { my ($o, $k) = @_; my $f; for (@{ $o->{m} }) { $f = $_ if $_->{k} eq# A string member, or undef.sub sv { my ($o, $k) = @_; my $m = member($o, $k); return ($m && $m->{v}{t} eq 's') ? $m->{v}{s} : undef }-# Printable ASCII only (for the shell's messages).-sub clean { my $x = shift // ''; $x =~ s/[^\x20-\x7e]//g; return $x }+# No control bytes (for the shell's messages); other bytes, such as UTF-8 letters, are kept.+sub clean { my $x = shift // ''; $x =~ s/[\x00-\x1f\x7f]|\xc2[\x80-\x9f]//g; return $x }# 1 when a source (an object with source, repo, url, ref, path) is the official# one: GitHub razorback16/cc-intelligent-ui, with no ref, path or sparse paths.sub official {@@ -414,14 +434,31 @@ if ($mode eq 'marketplace' || $mode eq 'plugin' || $mode eq 'copies') {next unless $id->{v}{s} =~ /\A\Q$args[0]\E\@[A-Za-z0-9._-]+\z/;my $scope = clean(sv($x, 'scope'));$scope = '?' unless $scope =~ /\A[a-z]+\z/;- print join("\t", $id->{v}{s}, $scope, $vs eq '' ? '?' : $vs, $state, clean(sv($x, 'projectPath'))), "\n";+ my $where = sv($x, $id->{v}{s} =~ /\@(?:skills-dir|inline)\z/ ? 'installPath' : 'projectPath');+ print join("\t", $id->{v}{s}, $scope, $vs eq '' ? '?' : $vs, $state, clean($where)), "\n";}exit($mode eq 'copies' ? 0 : 1);}+my $name = 'razorback16';+if ($mode eq 'entry') {+ my $f = $args[0];+ exit 1 unless -e $f;+ open(my $fh, '<:raw', $f) or exit 2;+ local $/; my $t = <$fh> // ''; close $fh;+ exit 1 if $t =~ /\A\s*\z/;+ my $root = eval { parse($t) } or exit 2;+ exit 2 unless $root->{t} eq 'o';+ my $ekm = member($root, 'extraKnownMarketplaces');+ exit 1 unless $ekm && $ekm->{v}{t} eq 'o';+ my $rb = member($ekm->{v}, $name) or exit 1;+ my $au = $rb->{v}{t} eq 'o' ? member($rb->{v}, 'autoUpdate') : undef;+ print $au && $au->{v}{t} eq 'false' ? "off\n" : "declared\n";+ exit 0;+}exit 4 unless $mode eq 'settings';-my ($file, $bak) = @args;-my $name = 'razorback16';+my ($file, $bak, $off) = @args;+my $want = $off ? 'false' : 'true';my @source = ([source => '"github"'], [repo => '"razorback16/cc-intelligent-ui"']);sub refuse { print "$_[0]\n"; exit 2 }my $real = $file;@@ -438,15 +475,22 @@ if (-e $real) {}# Writes: a new file in the same folder, then one rename.sub put {- my ($path, $data, $fmode) = @_;+ my ($path, $data, $fmode, $then) = @_;my $tmp = "$path.iui-$$";unlink $tmp;sysopen(my $fh, $tmp, O_WRONLY | O_CREAT | O_EXCL, defined $fmode ? 0600 : 0666) or die "can not write $tmp: $!\n";binmode $fh;- print {$fh} $data or die "can not write $tmp: $!\n";- close $fh or die "can not write $tmp: $!\n";+ unless ((print {$fh} $data) && close $fh) { my $e = $!; unlink $tmp; die "can not write $tmp: $e\n" }chmod($fmode, $tmp) if defined $fmode;- rename($tmp, $path) or do { unlink $tmp; die "can not write $path: $!\n" };+ # The backup only when the new file is written.+ if ($then) { eval { $then->(); 1 } or do { unlink $tmp; die $@ } }+ rename($tmp, $path) or do { my $e = $!; unlink $tmp; die "can not write $path: $e\n" };+}+# A file that is not writable, or one with more names (hard links), is not replaced.+sub writable {+ my $nl = (stat $real)[3];+ refuse("$file is not writable") unless -w $real;+ refuse("$file has $nl hard links, and a new file would break them") if $nl > 1;}# The line end of the file (CRLF kept).our $NL = (defined $old && $old =~ /\r\n/) ? "\r\n" : "\n";@@ -459,7 +503,7 @@ sub render {}my $out;if (!defined $old || $old =~ /\A\s*\z/) {- $text = render([[extraKnownMarketplaces => [[$name => [[source => \@source], [autoUpdate => 'true']]]]]], '', ' ', 1, ': ') . "\n";+ $text = render([[extraKnownMarketplaces => [[$name => [[source => \@source], [autoUpdate => $want]]]]]], '', ' ', 1, ': ') . "\n";$out = defined $old ? 'changed' : 'created';} else {my $root = eval { parse($old) };@@ -500,13 +544,13 @@ if (!defined $old || $old =~ /\A\s*\z/) {};my $ekm = member($root, 'extraKnownMarketplaces');if (!$ekm) {- $add->($root, [extraKnownMarketplaces => [[$name => [[source => \@source], [autoUpdate => 'true']]]]]);+ $add->($root, [extraKnownMarketplaces => [[$name => [[source => \@source], [autoUpdate => $want]]]]]);} elsif ($ekm->{v}{t} ne 'o') {refuse("extraKnownMarketplaces in $file is not an object");} else {my $rb = member($ekm->{v}, $name);if (!$rb) {- $add->($ekm->{v}, [$name => [[source => \@source], [autoUpdate => 'true']]]);+ $add->($ekm->{v}, [$name => [[source => \@source], [autoUpdate => $want]]]);} elsif ($rb->{v}{t} ne 'o') {refuse("extraKnownMarketplaces.$name in $file is not an object");} else {@@ -515,10 +559,12 @@ if (!defined $old || $old =~ /\A\s*\z/) {if $src && !($src->{v}{t} eq 'o' && official($src->{v}));my $au = member($rb->{v}, 'autoUpdate');if ($au && $au->{v}{t} eq 'true') { print "unchanged\n"; exit 0 }+ # Off by the person's choice (Disable auto-update): kept.+ if ($au && $au->{v}{t} eq 'false') { print "off\n"; exit 0 }if ($au) {- push @edits, [$au->{v}{b}, $au->{v}{e}, 'true'];+ push @edits, [$au->{v}{b}, $au->{v}{e}, $want];} else {- $add->($rb->{v}, (member($rb->{v}, 'source') ? () : [source => \@source]), [autoUpdate => 'true']);+ $add->($rb->{v}, (member($rb->{v}, 'source') ? () : [source => \@source]), [autoUpdate => $want]);}}}@@ -532,21 +578,22 @@ my $ok = $check && $check->{t} eq 'o';for my $k ('extraKnownMarketplaces', $name, 'autoUpdate') {last unless $ok;my $m = member($check, $k);- $ok = $m && ($k eq 'autoUpdate' ? $m->{v}{t} eq 'true' : $m->{v}{t} eq 'o');+ $ok = $m && ($k eq 'autoUpdate' ? $m->{v}{t} eq $want : $m->{v}{t} eq 'o');$check = $m->{v} if $ok;}refuse("the change of $file did not read back (nothing was written)") unless $ok;+writable() if defined $old;my $fmode = defined $old ? (stat $real)[2] & 07777 : undef;eval {- put($bak, $old, $fmode) if defined $old;- put($real, $text, $fmode);+ put($real, $text, $fmode, defined $old ? sub { put($bak, $old, $fmode) } : undef);1;-} or refuse("$@");+} or do { chomp(my $why = $@); refuse($why) };print "$out\n";PERL}-json() { perl -e "$(json_pl)" "$@"; }+# LC_ALL=C: no perl locale warnings (a LANG that is not installed).+json() { LC_ALL=C perl -e "$(json_pl)" "$@"; }# --- 3. The mod ----------------------------------------------------------------@@ -610,18 +657,44 @@ INFOif ! "$CLAUDE" plugin marketplace list < /dev/null 2> /dev/null | grep -qw "$MARKETPLACE"; then MKT_KIND=none; fi}+# The user settings file of Claude Code.+settings_file() { printf '%s/settings.json' "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"; }++# The razorback16 entry of the user settings: none, declared, off (autoUpdate+# false) or unknown (the file can not be read).+user_entry() {+ local f out rc=0+ f=$(settings_file)+ case $f in /*) ;; *)+ printf unknown+ return 0+ ;;+ esac+ out=$(json entry "$f" 2> /dev/null) || rc=$?+ case $rc in+ 0) printf '%s' "$out" ;;+ 1) printf none ;;+ *) printf unknown ;;+ esac+}+# The marketplace has another source (a fork, a pinned ref, a local folder):-# an update from it can not get the newest version. Remove it and add the-# official one. Claude Code also uninstalls the mod with the marketplace.+# an update from it can not get the newest version. Remove its entry in the+# user settings, then add the official one. Claude Code can uninstall the mod+# with the marketplace; if it does, the installer installs it again.OLD_STATE=REPOINTED=+AUTO_OFF=repoint_marketplace() {- local id scope ver pp undo+ local id scope ver pp undo entrywarn "the $MARKETPLACE marketplace comes from $MKT_DESC, not from the GitHub repository $MARKETPLACE_REPO. An update from there can not get the newest version of the mod."- note "So the installer removes the $MARKETPLACE marketplace and adds it again from $MARKETPLACE_REPO."- note "Claude Code also uninstalls the mod with the marketplace; the installer then installs it again."+ note "So the installer adds the $MARKETPLACE marketplace again from $MARKETPLACE_REPO."+ note "Claude Code can uninstall the mod with the old marketplace; if it does, the installer installs it again."note "Kept: your /iui settings (Claude Code keeps them under the name $PLUGIN). The mod has no other saved options, secrets or data."OLD_STATE=$(plugin_state)+ entry=$(user_entry)+ # Auto-update that you turned off stays off for the new source.+ if [ "$entry" = off ]; then AUTO_OFF=1; fiwhile IFS=$TAB read -r id scope ver _ pp; doif [ "$id" = "$PLUGIN" ] && [ "$scope" != user ]; thennote "Claude Code can also remove the copy of the mod in $scope scope for ${pp:-a project}."@@ -634,9 +707,18 @@ COPIESelseundo="claude plugin marketplace remove $MARKETPLACE, then add $MKT_DESC again"fi- claude_run plugin marketplace remove "$MARKETPLACE" --scope user || die "Claude Code could not remove the marketplace $MARKETPLACE (from $MKT_DESC). The mod was not updated."- if ! claude_run plugin marketplace add "$MARKETPLACE_REPO"; then- die "Claude Code could not add the marketplace $MARKETPLACE_REPO. To add the old one back: claude plugin marketplace add $(shq "${MKT_SPEC:-?}")"+ # `remove --scope user` fails when the user settings do not declare it (an+ # older Claude Code, or another scope); then `add` changes its source by itself.+ if [ "$entry" = none ]; then+ note "Your user settings do not declare the $MARKETPLACE marketplace, so claude plugin marketplace add changes its source."+ if ! claude_run plugin marketplace add "$MARKETPLACE_REPO"; then+ die "Claude Code could not add the marketplace $MARKETPLACE_REPO. The old marketplace was not changed. The mod was not updated."+ fi+ else+ claude_run plugin marketplace remove "$MARKETPLACE" --scope user || die "Claude Code could not remove the marketplace $MARKETPLACE (from $MKT_DESC). The mod was not updated."+ if ! claude_run plugin marketplace add "$MARKETPLACE_REPO"; then+ die "Claude Code could not add the marketplace $MARKETPLACE_REPO. To add the old one back: claude plugin marketplace add $(shq "${MKT_SPEC:-?}")"+ fifinote "The $MARKETPLACE marketplace comes from $MARKETPLACE_REPO now (before: $MKT_DESC)."REPOINTED=1@@ -716,10 +798,19 @@ install_plugin() {*' disabled') warn "the mod is disabled in Claude Code. To turn it on: claude plugin enable $PLUGIN" ;;esacnow=$(plugin_copies)+ # A copy with no marketplace: Claude Code can not uninstall it.+ while IFS=$TAB read -r id scope ver _ pp; do+ case $id in+ *@skills-dir) warn "a copy of the mod is in a skills folder of Claude Code ($(tilde "${pp:-${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills}")): $id $ver. It has no marketplace, so Claude Code can not uninstall it. The copy from $MARKETPLACE is used, not that one. To remove it, delete its folder (claude plugin list shows it)." ;;+ *@inline) warn "a copy of the mod is loaded with --plugin-dir${pp:+ from $pp}: $id $ver. Claude Code can not uninstall it. To stop it, start Claude Code without that --plugin-dir." ;;+ esac+ done << NOW+$now+NOW# Another copy in user scope (from another marketplace) would run too.if [ -n "$after" ]; thenwhile IFS=$TAB read -r id scope ver _ pp; do- case $id in '' | "$PLUGIN") continue ;; esac+ case $id in '' | "$PLUGIN" | *@skills-dir | *@inline) continue ;; esac[ "$scope" = user ] || continuenote "Another copy of the mod is installed for your user: $id $ver. Two copies would both run, so the installer uninstalls that one."if claude_run plugin uninstall "$id" --scope user; then@@ -738,6 +829,7 @@ NOW# Copies in a project: not changed. In that folder, they can hide the user copy.while IFS=$TAB read -r id scope ver _ pp; docase $scope in '' | user) continue ;; esac+ case $id in *@skills-dir | *@inline) continue ;; esacwarn "a copy of the mod is installed in $scope scope for ${pp:-a project}: $id $ver. In that project it can be used instead of the version above. To remove it: cd $(shq "${pp:-.}") && claude plugin uninstall $id --scope $scope"done << NOW$now@@ -777,6 +869,21 @@ manual_auto_update() {EOF}+# Auto-update turned on: $1 is created or changed, $2 the file.+auto_on() {+ AUTO_ON=1+ if [ "$1" = created ]; then+ note "Made $(tilde "$2") with extraKnownMarketplaces.$MARKETPLACE.autoUpdate = true."+ SUM_AUTO="on ($(tilde "$2"), new file)"+ return 0+ fi+ note "Set extraKnownMarketplaces.$MARKETPLACE.autoUpdate = true in $(tilde "$2")."+ note "All other settings are kept. The file before this auto-update change: $(tilde "$2").bak-iui"+ note "(It has the changes of step 3 already: the backup undoes only the auto-update change.)"+ SUM_AUTO="on ($(tilde "$2"))"+ UNDO_AUTO="copy $(tilde "$2").bak-iui (the file before the auto-update change only) back to $(tilde "$2")"+}+auto_update() {local dir file result rc tstep "4. Auto-update for the $MARKETPLACE marketplace"@@ -786,7 +893,7 @@ auto_update() {return 0fidir=${CLAUDE_CONFIG_DIR:-$HOME/.claude}- file=$dir/settings.json+ file=$(settings_file)case $dir in/*) ;;*)@@ -806,7 +913,8 @@ auto_update() {fiif [ ! -e "$file" ] && [ ! -L "$file" ]; then mkdir -p "$dir"; firc=0- result=$(json settings "$file" "$file.bak-iui" 2>&1) || rc=$?+ # Only stdout is the result; perl's stderr goes to the screen.+ result=$(json settings "$file" "$file.bak-iui" ${AUTO_OFF:+off}) || rc=$?t="~"result=${result//"$HOME"/$t}case $rc:$result in@@ -815,18 +923,18 @@ auto_update() {SUM_AUTO="on (it was on already)"AUTO_ON=1;;- 0:created)- note "Made $(tilde "$file") with extraKnownMarketplaces.$MARKETPLACE.autoUpdate = true."- SUM_AUTO="on ($(tilde "$file"), new file)"- AUTO_ON=1+ 0:off)+ note "Auto-update is off: you turned it off (extraKnownMarketplaces.$MARKETPLACE.autoUpdate = false in $(tilde "$file")). Not changed."+ SUM_AUTO="off (your choice; not changed)";;- 0:changed)- note "Set extraKnownMarketplaces.$MARKETPLACE.autoUpdate = true in $(tilde "$file")."- note "All other settings are kept. The file before this auto-update change: $(tilde "$file").bak-iui"- note "(It has the changes of step 3 already: the backup undoes only the auto-update change.)"- SUM_AUTO="on ($(tilde "$file"))"- AUTO_ON=1- UNDO_AUTO="copy $(tilde "$file").bak-iui (the file before the auto-update change only) back to $(tilde "$file")"+ 0:created | 0:changed)+ if [ -z "$AUTO_OFF" ]; then+ auto_on "$result" "$file"+ else+ note "Auto-update stays off for the new source, as you set it: extraKnownMarketplaces.$MARKETPLACE.autoUpdate = false in $(tilde "$file")."+ if [ "$result" = changed ]; then note "The file before this change: $(tilde "$file").bak-iui"; fi+ SUM_AUTO="off (your choice; kept for the new source)"+ fi;;*)warn "$(tilde "$file") was not changed: ${result:-an unknown error}"@@ -853,8 +961,8 @@ SETUP_FISH='if test "$TERM_PROGRAM" = "iTerm.app" -o "$TERM_PROGRAM" = "herdr";# Puts the block in a start file as the mod's withSetup() does: an older block# of the mod is replaced, one blank line goes before the block, and the exact# block already there changes nothing. Args: FILE START LINE END BACKUP. A link-# keeps its place and its file changes. Prints created, changed or unchanged.-# Exit 2: not changed (the reason on stdout).+# keeps its place and its file changes. Prints created, changed (block added),+# updated (an older block replaced) or unchanged. Exit 2: not changed (the reason on stdout).setup_pl() {cat << 'PERL'use strict; use warnings;@@ -881,6 +989,7 @@ if (index($text, $block) >= 0) { print "unchanged\n"; exit 0 }# withoutSetup(): each START ... END block goes, with one blank line before it.my @lines = split /\n/, $text, -1;my @out;+my $replaced = 0;for (my $i = 0; $i < @lines; $i++) {if ($lines[$i] ne $start) { push @out, $lines[$i]; next }my $e = -1;@@ -888,29 +997,36 @@ for (my $i = 0; $i < @lines; $i++) {if ($e < 0) { push @out, $lines[$i]; next }pop @out if @out && $out[-1] eq '';$i = $e;+ $replaced++;}my $base = join("\n", @out);$base =~ s/\n*\z//;my $new = $base . ($base ne '' ? "\n\n" : '') . $block;# Writes: a new file in the same folder, then one rename.sub put {- my ($path, $data, $fmode) = @_;+ my ($path, $data, $fmode, $then) = @_;my $tmp = "$path.iui-$$";unlink $tmp;sysopen(my $fh, $tmp, O_WRONLY | O_CREAT | O_EXCL, defined $fmode ? 0600 : 0666) or die "can not write $tmp: $!\n";binmode $fh;- print {$fh} $data or die "can not write $tmp: $!\n";- close $fh or die "can not write $tmp: $!\n";+ unless ((print {$fh} $data) && close $fh) { my $e = $!; unlink $tmp; die "can not write $tmp: $e\n" }chmod($fmode, $tmp) if defined $fmode;- rename($tmp, $path) or do { unlink $tmp; die "can not write $path: $!\n" };+ # The backup only when the new file is written.+ if ($then) { eval { $then->(); 1 } or do { unlink $tmp; die $@ } }+ rename($tmp, $path) or do { my $e = $!; unlink $tmp; die "can not write $path: $e\n" };+}+# A file that is not writable, or one with more names (hard links), is not replaced.+if (defined $old) {+ my $nl = (stat $real)[3];+ refuse("$file is not writable") unless -w $real;+ refuse("$file has $nl hard links, and a new file would break them") if $nl > 1;}my $fmode = defined $old ? (stat $real)[2] & 07777 : undef;eval {- put($bak, $old, $fmode) if defined $old;- put($real, $new, $fmode);+ put($real, $new, $fmode, defined $old ? sub { put($bak, $old, $fmode) } : undef);1;-} or refuse("$@");-print defined $old ? "changed\n" : "created\n";+} or do { chomp(my $why = $@); refuse($why) };+print !defined $old ? "created\n" : $replaced ? "updated\n" : "changed\n";PERL}@@ -930,7 +1046,7 @@ has_iterm() {SUM_SHELL=UNDO_SHELL=shell_setup() {- local apps='' name file kind line result rc t+ local apps='' name file kind line result rc t fstep "5. Pictures in iTerm2 and herdr"if on "${IUI_NO_SHELL_SETUP:-}"; thennote "Skipped (IUI_NO_SHELL_SETUP is set)."@@ -952,7 +1068,17 @@ shell_setup() {zsh) file=${ZDOTDIR:-$HOME}/.zshrc kind='sh' ;;bash)kind='sh'- if [ "$OS" = macos ]; then file=$HOME/.bash_profile; else file=$HOME/.bashrc; fi+ file=$HOME/.bashrc+ if [ "$OS" = macos ]; then+ # Login bash reads only the first of these that exists: a new .bash_profile would hide the others.+ file=$HOME/.bash_profile+ for f in .bash_profile .bash_login .profile; do+ if [ -e "$HOME/$f" ] || [ -L "$HOME/$f" ]; then+ file=$HOME/$f+ break+ fi+ done+ fi;;fish) file=${XDG_CONFIG_HOME:-$HOME/.config}/fish/conf.d/cc-intelligent-ui.fish kind='fish' ;;*)@@ -969,7 +1095,8 @@ shell_setup() {elseif [ "$kind" = fish ] && [ ! -e "$file" ] && [ ! -L "$file" ]; then mkdir -p "${file%/*}"; firc=0- result=$(perl -e "$(setup_pl)" "$file" "$SETUP_START" "$line" "$SETUP_END" "$file.bak-iui" 2>&1) || rc=$?+ # Only stdout is the result (LC_ALL=C: no perl locale warnings).+ result=$(LC_ALL=C perl -e "$(setup_pl)" "$file" "$SETUP_START" "$line" "$SETUP_END" "$file.bak-iui") || rc=$?fit="~"result=${result//"$HOME"/$t}@@ -983,10 +1110,15 @@ shell_setup() {SUM_SHELL="added to $(tilde "$file") (open a new tab or pane)";;0:changed)- note "Added the Intelligent UI block to $(tilde "$file") (an older block of the mod is replaced)."+ note "Added the Intelligent UI block to $(tilde "$file")."note "The file before this change: $(tilde "$file").bak-iui"SUM_SHELL="added to $(tilde "$file") (open a new tab or pane)";;+ 0:updated)+ note "Updated the Intelligent UI block in $(tilde "$file") (an older block of the mod is replaced)."+ note "The file before this change: $(tilde "$file").bak-iui"+ SUM_SHELL="updated in $(tilde "$file") (open a new tab or pane)"+ ;;*)warn "$(tilde "$file") was not changed: ${result:-an unknown error}"say " To set it yourself, add these lines to $(tilde "$file"), or run /iui setup in Claude Code in iTerm2 or herdr:" >&2@@ -1023,6 +1155,12 @@ summary() {note " (it also sets extraKnownMarketplaces.$MARKETPLACE.autoUpdate to false in settings.json)"if [ -n "$UNDO_AUTO" ]; then note " or $UNDO_AUTO"; fifi+ case $SUM_AUTO in off*)+ say ""+ say "Auto-update is off, as you set it. To turn it on: in Claude Code, type /plugin, go to"+ say "Marketplaces, select $MARKETPLACE, then select Enable auto-update."+ ;;+ esacif [ -n "$UNDO_SHELL" ]; then note "Shell setup: $UNDO_SHELL"; fi}diff --git a/tests/install-sh-test.sh b/tests/install-sh-test.shindex 782b482..442c826 100644--- a/tests/install-sh-test.sh+++ b/tests/install-sh-test.sh@@ -7,11 +7,13 @@# is kept; a missing Typst is downloaded and installed only with the correct# SHA-256; the marketplace and the mod are added, or updated on a second run;# a marketplace from another source (fork, ref, folder) is added again from-# GitHub, a disabled mod stays disabled, another user copy is uninstalled,-# project copies are only shown, and a failed update is not called newest;-# settings.json gets extraKnownMarketplaces.razorback16.autoUpdate = true with-# all other bytes kept, a backup only when it changed, and no change when it-# is not valid JSON or set already; with iTerm2 or herdr, the mod's setup block+# GitHub (with remove --scope user only when the user settings declare it), a+# disabled mod stays disabled, another user copy is uninstalled (not one with+# no marketplace), project copies are only shown, and a failed update is not+# called newest; settings.json gets extraKnownMarketplaces.razorback16.autoUpdate+# = true with all other bytes kept, a backup only when it changed, and no change+# when it is not valid JSON, set already, turned off by you, read-only or a hard+# link; a perl locale warning is not a result; with iTerm2 or herdr, the mod's setup block# (the one of hooks/lib/setup.ts, or of IUI_SETUP_TS) in the start file of the# login shell, as the mod writes it; the IUI_NO_* options; a cut download runs# nothing; shellcheck when it is installed.@@ -52,6 +54,9 @@ setp() {}# getp ID SCOPE FIELDgetp() { awk -F"$T" -v i="$1" -v s="$2" -v f="$3" '$1 == i && $2 == s { print $f }' "$P"; }+# The user settings declare razorback16.+cfg=${CLAUDE_CONFIG_DIR:-$HOME/.claude}/settings.json+declared() { grep -q '"razorback16"' "$cfg" 2> /dev/null; }case "$*" in--version) echo "${FAKE_CLAUDE_VERSION:-2.1.307} (Claude Code)" ;;'plugin marketplace list --json')@@ -59,8 +64,9 @@ case "$*" inif [ -f "$st/mkt" ]; then printf ',\n %s' "$(cat "$st/mkt")"; fiprintf '\n]\n' ;;'plugin marketplace add razorback16/cc-intelligent-ui')- if [ -f "$st/mkt" ] && [ "$(cat "$st/mkt")" != "$official" ]; then- echo 'Failed to add marketplace: Cannot add marketplace "razorback16": its source does not match' >&2+ # Another source: refused when the user settings declare it, else changed (2.1.307).+ if [ -f "$st/mkt" ] && [ "$(cat "$st/mkt")" != "$official" ] && declared; then+ echo 'Failed to add marketplace: Cannot add marketplace "razorback16": its source does not match its extraKnownMarketplaces entry' >&2exit 1fi[ -z "${FAKE_ADD_FAIL:-}" ] || exit 1@@ -71,10 +77,16 @@ case "$*" inecho 'Successfully updated marketplace: razorback16' ;;'plugin marketplace remove razorback16 --scope user')[ -z "${FAKE_REMOVE_FAIL:-}" ] || { echo 'Failed to remove marketplace' >&2; exit 1; }- rm -f "$st/mkt"+ if ! declared; then+ echo "Failed to remove marketplace: Marketplace 'razorback16' is not declared in user settings. Omit --scope to remove it from all scopes." >&2+ exit 1+ fi+ # 2.1.307: the entry in the user settings goes; the marketplace stays known, the mod installed.+ perl -0pi -e 's/,?\s*"razorback16"\s*:\s*\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}//' "$cfg"echo 'Successfully removed marketplace: razorback16 (from user settings)'- # Claude Code 2.1.307 uninstalls the plugins of the marketplace (in all scopes).- if [ -z "${FAKE_REMOVE_KEEPS:-}" ]; then+ # It can also uninstall the plugins of the marketplace (in all scopes): VM runs saw both.+ if [ -n "${FAKE_REMOVE_UNINSTALLS:-}" ]; then+ rm -f "$st/mkt"grep -v "^[^$T]*@razorback16$T" "$P" > "$P.new"mv "$P.new" "$P"echo 'Also uninstalled 1 plugin from this marketplace:'@@ -102,6 +114,9 @@ case "$*" infi ;;"plugin disable $ours --scope user")setp "$ours" user "$(getp "$ours" user 3)" false ;;+ 'plugin uninstall '*'@skills-dir --scope user' | 'plugin uninstall '*'@inline --scope user')+ echo "Failed to uninstall plugin \"$3\": it has no marketplace backing; it cannot be uninstalled." >&2+ exit 1 ;;'plugin uninstall '*' --scope user')grep -v "^$3${T}user$T" "$P" > "$P.new"mv "$P.new" "$P" ;;@@ -159,8 +174,10 @@ perl -pe 's#^TYPST_DIRS=.*#TYPST_DIRS='"'$dirs'"'#' "$script" > "$tmp/install-baperl -pe "s/$real_sum/$fake_sum/" "$tmp/install-badsum.sh" > "$tmp/install.sh"grep -q "^TYPST_DIRS='$tmp/sys/a " "$tmp/install.sh" && ok || bad "the test could not set TYPST_DIRS"+# A typst that the installer finds outside the sandbox (also in a login shell's PATH).typst_on_sys=PATH=$sys command -v typst > /dev/null 2>&1 && typst_on_sys=1+env -i HOME="$tmp" PATH="$sys" sh -lc 'command -v typst' < /dev/null 2> /dev/null | grep -q '^/' && typst_on_sys=1# run NAME [VAR=value ...]: runs the installer with HOME $tmp/NAME/home; the# output in $tmp/NAME/out, the exit code in $rc. SCRIPT and BIN change the@@ -236,6 +253,15 @@ mktypst "$tmp/cargo/home/.cargo/bin" 0.15.0run cargo[ "$rc" = 0 ] && out 'Typst 0.15.0 is installed: ~/.cargo/bin/typst' && no_downloads && ok || bad "Typst in ~/.cargo/bin: exit $rc, or a download"+# A login shell's PATH comes first, as for the mod (macOS puts /usr/local/bin+# first there): its Typst 0.15.2 is used, not the 0.13.1 of this PATH.+mktypst "$tmp/login-new" 0.15.2+mktypst "$tmp/login-old" 0.13.1+mkdir -p "$tmp/login/home"+printf 'PATH=%s:$PATH\nexport PATH\n' "$tmp/login-new" > "$tmp/login/home/.profile"+XPATH=$tmp/login-old run login+[ "$rc" = 0 ] && out "Typst 0.15.2 is installed: $tmp/login-new/typst" && no_downloads && ok || { bad "a Typst in the login shell's PATH: not used"; show; }+if [ -n "$typst_on_sys" ] || [ -z "$can_xz" ]; thenecho "install-sh-test: the Typst download skipped (a typst in $sys, or tar can not make .tar.xz)"else@@ -319,6 +345,14 @@ mkt_official='{"name": "razorback16", "source": "github", "repo": "razorback16/cplugin() { awk -F"$T" -v i="$1" -v s="$2" '$1 == i && $2 == s { print $3 " " $4 }' "$d/state/plugins"; }# Line numbers in the claude log: the order of the commands.at() { grep -nx -- "$1" "$d/state/claude.log" | head -n 1 | cut -d: -f1; }+# old_entry NAME [AUTO]: the user settings declare razorback16 from another+# source (as `claude plugin marketplace add` of it did); AUTO: its autoUpdate.+old_entry() {+ mkdir -p "$tmp/$1/home/.claude"+ printf '{\n "extraKnownMarketplaces": {\n "razorback16": {\n "source": {"source": "github", "repo": "someone/cc-intelligent-ui"}%s\n }\n }\n}\n' \+ "${2:+,+ \"autoUpdate\": $2}" > "$tmp/$1/home/.claude/settings.json"+}seed disabled '' "$ours${T}project${T}0.1.0${T}true${T}/work/p"run disabled IUI_NO_TYPST=1 FAKE_ENABLED=false@@ -343,13 +377,15 @@ for u in 'https://github.com/razorback16/cc-intelligent-ui.git' 'https://GitHub.grep -q 'marketplace remove' "$d/state/claude.log" && bad "git URL $u: the marketplace was removed" || okdone-# Another source: removed, added from GitHub, the mod installed again.+# Another source, declared in the user settings: its entry removed, added from+# GitHub, the mod (kept by Claude Code) updated.# repointed NAME MKT UNDO-SOURCE DESCRIPTIONrepointed() {seed "$1" "$2" "$ours${T}user${T}0.3.0${T}true"+ old_entry "$1"run "$1" IUI_NO_TYPST=1[ "$rc" = 0 ] && ok || { bad "$1: exit $rc"; show; }- log 'plugin marketplace remove razorback16 --scope user' && log 'plugin marketplace add razorback16/cc-intelligent-ui' && log "plugin install $ours --scope user" && ok || bad "$1: not removed, added and installed: $(tr '\n' ';' < "$d/state/claude.log")"+ log 'plugin marketplace remove razorback16 --scope user' && log 'plugin marketplace add razorback16/cc-intelligent-ui' && log "plugin update $ours --scope user" && ok || bad "$1: not removed, added and updated: $(tr '\n' ';' < "$d/state/claude.log")"[ "$(at 'plugin marketplace remove razorback16 --scope user')" -lt "$(at 'plugin marketplace add razorback16/cc-intelligent-ui')" ] && ok || bad "$1: the order of remove and add"log 'plugin marketplace update razorback16' && bad "$1: an update from the old source" || ok[ "$(plugin "$ours" user)" = '0.3.3 true' ] && ok || bad "$1: the mod is $(plugin "$ours" user), not 0.3.3"@@ -358,6 +394,8 @@ repointed() {out "before: 0.3.0 from $4" && ok || bad "$1: the summary does not say the old version and source"out 'the newest version was installed already' && bad "$1: the summary says newest" || okout 'Kept: your /iui settings' && ok || bad "$1: no words on the settings kept"+ out 'Claude Code can uninstall the mod with the old marketplace; if it does, the installer installs it again' && ok || bad "$1: no honest words on the uninstall"+ grep -q '"repo": "razorback16/cc-intelligent-ui"' "$d/home/.claude/settings.json" && ! grep -q someone "$d/home/.claude/settings.json" && grep -q '"autoUpdate": true' "$d/home/.claude/settings.json" && ok || bad "$1: settings.json: $(cat "$d/home/.claude/settings.json")"}repointed fork '{"name": "razorback16", "source": "github", "repo": "someone/cc-intelligent-ui", "installLocation": "/fake/m"}' \'someone/cc-intelligent-ui' 'the GitHub repository someone/cc-intelligent-ui'@@ -377,33 +415,60 @@ run folder-newer IUI_NO_TYPST=1[ "$rc" = 0 ] && out 'from the old source (0.4.0) is newer than the version on GitHub (0.3.3)' && out 'then claude plugin marketplace add /work/iui' && ok || { bad "a newer old source: no warning"; show; }out 'is newer than the version on GitHub' && [ "$(grep -c 'is newer than' "$tmp/fork/out")" = 0 ] && ok || bad "an older old source: a newer warning"-# A disabled mod stays disabled after the new marketplace.+# Not declared in the user settings (an older Claude Code, or `remove --scope+# user` before): `remove --scope user` would fail, so add changes the source.+seed undeclared '{"name": "razorback16", "source": "github", "repo": "razorback16/cc-intelligent-ui", "ref": "main", "installLocation": "/fake/m"}' "$ours${T}user${T}0.3.0${T}true"+mkdir -p "$tmp/undeclared/home/.claude"+printf '{\n "enabledPlugins": {\n "%s": true\n }\n}\n' "$ours" > "$tmp/undeclared/home/.claude/settings.json"+run undeclared IUI_NO_TYPST=1+[ "$rc" = 0 ] && log 'plugin marketplace add razorback16/cc-intelligent-ui' && [ "$(plugin "$ours" user)" = '0.3.3 true' ] && ok || { bad "undeclared: exit $rc, $(plugin "$ours" user)"; show; }+grep -q 'marketplace remove' "$d/state/claude.log" && bad "undeclared: remove --scope user was run" || ok+out 'do not declare the razorback16 marketplace' && out 'before: 0.3.0 from the GitHub repository razorback16/cc-intelligent-ui (ref main)' && ok || { bad "undeclared: no words"; show; }+seed undeclared-add-fails '{"name": "razorback16", "source": "directory", "path": "/work/iui"}' "$ours${T}user${T}0.3.0${T}true"+run undeclared-add-fails IUI_NO_TYPST=1 FAKE_ADD_FAIL=1+[ "$rc" = 1 ] && out 'The old marketplace was not changed' && ok || { bad "undeclared, add fails: exit $rc"; show; }++# Auto-update that you turned off stays off for the new source.+seed repoint-off '{"name": "razorback16", "source": "github", "repo": "someone/cc-intelligent-ui"}' "$ours${T}user${T}0.3.0${T}true"+old_entry repoint-off false+run repoint-off IUI_NO_TYPST=1+[ "$rc" = 0 ] && log 'plugin marketplace remove razorback16 --scope user' && ok || { bad "re-point, auto-update off: exit $rc"; show; }+grep -q '"repo": "razorback16/cc-intelligent-ui"' "$d/home/.claude/settings.json" && grep -q '"autoUpdate": false' "$d/home/.claude/settings.json" && ! grep -q '"autoUpdate": true' "$d/home/.claude/settings.json" && ok || bad "re-point, auto-update off: settings.json: $(cat "$d/home/.claude/settings.json")"+out 'Auto-update stays off for the new source' && out 'off (your choice; kept for the new source)' && out 'select Enable auto-update' && ok || { bad "re-point, auto-update off: no words"; show; }+out 'Disable auto-update' && bad "re-point, auto-update off: an undo line for auto-update" || ok++# A disabled mod stays disabled after the new marketplace (Claude Code uninstalled it).seed repoint-disabled '{"name": "razorback16", "source": "github", "repo": "someone/cc-intelligent-ui"}' "$ours${T}user${T}0.3.0${T}false"-run repoint-disabled IUI_NO_TYPST=1+old_entry repoint-disabled+run repoint-disabled IUI_NO_TYPST=1 FAKE_REMOVE_UNINSTALLS=1[ "$rc" = 0 ] && log "plugin disable $ours --scope user" && [ "$(plugin "$ours" user)" = '0.3.3 false' ] && ok || { bad "re-point, disabled: exit $rc, $(plugin "$ours" user)"; show; }[ "$(at "plugin install $ours --scope user")" -lt "$(at "plugin disable $ours --scope user")" ] && ok || bad "re-point, disabled: disabled before the install"out "claude plugin enable $ours" && ok || bad "re-point, disabled: no words"-# remove does not uninstall the mod: it is updated, not installed again. A+# remove does not uninstall the mod (2.1.307): it is updated, not installed again. A# copy of ours in a project that Claude Code removed with the marketplace, or not.seed remove-keeps '{"name": "razorback16", "source": "github", "repo": "someone/cc-intelligent-ui"}' "$ours${T}user${T}0.3.0${T}true" "$ours${T}project${T}0.3.0${T}true${T}/work/proj"-run remove-keeps IUI_NO_TYPST=1 FAKE_REMOVE_KEEPS=1+old_entry remove-keeps+run remove-keeps IUI_NO_TYPST=1[ "$rc" = 0 ] && log "plugin update $ours --scope user" && [ "$(plugin "$ours" user)" = '0.3.3 true' ] && ok || { bad "remove keeps the mod: exit $rc, $(plugin "$ours" user)"; show; }log "plugin install $ours --scope user" && bad "remove keeps the mod: installed again" || okout "before: 0.3.0 from" && ok || bad "remove keeps the mod: summary"out "project scope for /work/proj: $ours 0.3.0" && out "cd /work/proj && claude plugin uninstall $ours --scope project" && ok || { bad "remove keeps the mod: no project warning"; show; }seed remove-uninstalls '{"name": "razorback16", "source": "github", "repo": "someone/cc-intelligent-ui"}' "$ours${T}user${T}0.3.0${T}true" "$ours${T}project${T}0.3.0${T}true${T}/work/proj"-run remove-uninstalls IUI_NO_TYPST=1+old_entry remove-uninstalls+run remove-uninstalls IUI_NO_TYPST=1 FAKE_REMOVE_UNINSTALLS=1[ "$rc" = 0 ] && log "plugin install $ours --scope user" && [ "$(plugin "$ours" user)" = '0.3.3 true' ] && ok || { bad "remove uninstalls: exit $rc"; show; }out "removed the copy of the mod in project scope for /work/proj" && out "cd /work/proj && claude plugin install $ours --scope project" && ok || { bad "remove uninstalls: no words on the project copy"; show; }# The remove fails: stop, nothing added.seed remove-fails '{"name": "razorback16", "source": "github", "repo": "someone/cc-intelligent-ui"}' "$ours${T}user${T}0.3.0${T}true"+old_entry remove-failsrun remove-fails IUI_NO_TYPST=1 FAKE_REMOVE_FAIL=1[ "$rc" = 1 ] && out 'could not remove the marketplace razorback16' && ok || bad "remove fails: exit $rc"grep -q 'marketplace add\|plugin install\|plugin update' "$d/state/claude.log" && bad "remove fails: more was run" || ok# The add fails after the remove: how to add the old one back.seed add-fails '{"name": "razorback16", "source": "github", "repo": "someone/cc-intelligent-ui"}' "$ours${T}user${T}0.3.0${T}true"+old_entry add-failsrun add-fails IUI_NO_TYPST=1 FAKE_ADD_FAIL=1[ "$rc" = 1 ] && out 'To add the old one back: claude plugin marketplace add someone/cc-intelligent-ui' && ok || { bad "add fails: exit $rc"; show; }@@ -427,6 +492,25 @@ grep -q 'uninstall' "$d/state/claude.log" && bad "project copies: a copy was uni[ "$(plugin "$ours" project)" = '0.1.0 true' ] && [ "$(plugin cc-intelligent-ui@other-mkt local)" = '0.2.0 true' ] && ok || bad "project copies: changed"out "cd /work/proj && claude plugin uninstall $ours --scope project" && out "cd '/work/my b' && claude plugin uninstall cc-intelligent-ui@other-mkt --scope local" && ok || { bad "project copies: no warnings"; show; }+# A folder name with letters that are not ASCII shows as it is (also from a+# \u escape); a control byte (ESC) does not.+seed utf8-folder '{"name": "razorback16", "source": "directory", "path": "/work/caf\u00e9 \u001b[31m'"$(printf '\303\251t\303\251')"'"}' "$ours${T}user${T}0.3.0${T}true"+run utf8-folder IUI_NO_TYPST=1+[ "$rc" = 0 ] && grep -qF "$(printf 'comes from the local folder /work/caf\303\251 [31m\303\251t\303\251, not')" "$d/out" && grep -qF "$(printf "claude plugin marketplace add '/work/caf\303\251 [31m\303\251t\303\251'")" "$d/out" && ok || { bad "a folder name that is not ASCII: not shown as it is"; show; }+grep -q "$(printf '\033')" "$d/out" && bad "a folder name: a control byte came through" || ok+# Not in the ASCII check below.+mv "$d/out" "$d/out-utf8"++# A copy with no marketplace (a skills folder, --plugin-dir): Claude Code can+# not uninstall it, so it is not tried; a warning with its folder.+seed skills-dir "$mkt_official" "$ours${T}user${T}0.3.2${T}true" "cc-intelligent-ui@skills-dir${T}user${T}0.3.1${T}true" "cc-intelligent-ui@inline${T}session${T}0.3.1${T}true"+run skills-dir IUI_NO_TYPST=1+[ "$rc" = 0 ] && ok || { bad "a skills folder copy: exit $rc"; show; }+grep -q 'uninstall' "$d/state/claude.log" && bad "a skills folder copy: uninstall was run" || ok+out 'in a skills folder of Claude Code (/fake/cache/cc-intelligent-ui@skills-dir): cc-intelligent-ui@skills-dir 0.3.1' && out 'delete its folder' && ok || { bad "a skills folder copy: no warning with the folder"; show; }+out 'loaded with --plugin-dir from /fake/cache/cc-intelligent-ui@inline' && ok || { bad "a --plugin-dir copy: no warning"; show; }+out 'session scope' && bad "a --plugin-dir copy: shown as a project copy" || ok+# A failed update: an honest summary and exit 1.seed update-fails "$mkt_official" "$ours${T}user${T}0.3.2${T}true"run update-fails IUI_NO_TYPST=1 FAKE_UPDATE_FAIL=1@@ -479,8 +563,14 @@ setting other-marketplace \'{\n "extraKnownMarketplaces": {\n "other": {\n "source": {\n "source": "github",\n "repo": "o/r"\n }\n }\n }\n}\n' \'{\n "extraKnownMarketplaces": {\n "other": {\n "source": {\n "source": "github",\n "repo": "o/r"\n }\n },\n "razorback16": {\n "source": {\n "source": "github",\n "repo": "razorback16/cc-intelligent-ui"\n },\n "autoUpdate": true\n }\n }\n}\n'+# Turned off by you (Disable auto-update): kept, with how to turn it on.setting turned-off \'{\n "extraKnownMarketplaces": {\n "razorback16": {\n "autoUpdate": false,\n "source": {"source": "github", "repo": "razorback16/cc-intelligent-ui"}\n }\n }\n}\n' \+ '{\n "extraKnownMarketplaces": {\n "razorback16": {\n "autoUpdate": false,\n "source": {"source": "github", "repo": "razorback16/cc-intelligent-ui"}\n }\n }\n}\n'+out 'Auto-update is off: you turned it off' && out 'off (your choice; not changed)' && out 'select Enable auto-update' && ok || { bad "turned off: no words"; show; }+out 'Disable auto-update' && bad "turned off: an undo line for auto-update" || ok+setting not-bool \+ '{\n "extraKnownMarketplaces": {\n "razorback16": {\n "autoUpdate": "no",\n "source": {"source": "github", "repo": "razorback16/cc-intelligent-ui"}\n }\n }\n}\n' \'{\n "extraKnownMarketplaces": {\n "razorback16": {\n "autoUpdate": true,\n "source": {"source": "github", "repo": "razorback16/cc-intelligent-ui"}\n }\n }\n}\n'setting already-set \@@ -555,6 +645,37 @@ run link IUI_NO_TYPST=1case $(ls -l "$d/dotfiles/settings.json") in -rw-------*) ok ;; *) bad "a link: the mode changed: $(ls -l "$d/dotfiles/settings.json")" ;; esaccase $(ls -l "$d/home/.claude/settings.json.bak-iui") in -rw-------*) ok ;; *) bad "the backup mode is not the file's" ;; esac+# A file that a rename would harm: read-only, a hard link (two names, one+# file), or a link into a folder that is not writable. Not changed, no backup.+if [ "$(id -u)" != 0 ]; then+ mkdir -p "$tmp/ro-file/home/.claude"+ printf '{\n "a": 1\n}\n' > "$tmp/ro-file/home/.claude/settings.json"+ chmod 444 "$tmp/ro-file/home/.claude/settings.json"+ run ro-file IUI_NO_TYPST=1+ [ "$rc" = 1 ] && out 'settings.json is not writable' && out '"autoUpdate": true' && ok || { bad "a read-only settings.json: exit $rc, or no words"; show; }+ [ "$(cat "$d/home/.claude/settings.json")" = "$(printf '{\n "a": 1\n}')" ] && [ ! -e "$d/home/.claude/settings.json.bak-iui" ] && no_work_left && ok || bad "a read-only settings.json: changed, or a backup"+ mkdir -p "$tmp/hard-link/home/.claude" "$tmp/hard-link/dotfiles"+ printf '{\n "a": 1\n}\n' > "$tmp/hard-link/dotfiles/settings.json"+ ln "$tmp/hard-link/dotfiles/settings.json" "$tmp/hard-link/home/.claude/settings.json"+ run hard-link IUI_NO_TYPST=1+ [ "$rc" = 1 ] && out 'has 2 hard links' && ok || { bad "a hard link: exit $rc, or no words"; show; }+ [ "$(ls -l "$d/dotfiles/settings.json" | awk '{ print $2 }')" = 2 ] && [ ! -e "$d/home/.claude/settings.json.bak-iui" ] && ! grep -q autoUpdate "$d/dotfiles/settings.json" && ok || bad "a hard link: broken, changed, or a backup"+ mkdir -p "$tmp/ro-dir/home/.claude" "$tmp/ro-dir/ro"+ printf '{\n "a": 1\n}\n' > "$tmp/ro-dir/ro/settings.json"+ ln -s "$tmp/ro-dir/ro/settings.json" "$tmp/ro-dir/home/.claude/settings.json"+ chmod 555 "$tmp/ro-dir/ro"+ run ro-dir IUI_NO_TYPST=1+ chmod 755 "$d/ro"+ [ "$rc" = 1 ] && out 'can not write' && [ ! -e "$d/home/.claude/settings.json.bak-iui" ] && no_work_left && ok || { bad "a link into a read-only folder: exit $rc, or a backup left"; show; }+fi++# A LANG that is not installed: perl's locale warning is not the result.+mkdir -p "$tmp/locale/home/.claude" "$tmp/locale/root/Applications/iTerm.app"+printf '{\n "a": 1\n}\n' > "$tmp/locale/home/.claude/settings.json"+run locale IUI_NO_TYPST=1 SHELL=/bin/zsh LANG=xx_YY.UTF-8+[ "$rc" = 0 ] && grep -q '"autoUpdate": true' "$d/home/.claude/settings.json" && out 'Set extraKnownMarketplaces.razorback16.autoUpdate = true' && out 'Made ~/.zshrc' && ok || { bad "a LANG that is not installed: exit $rc, or a done change called not changed"; show; }+out 'was not changed' && bad "a LANG that is not installed: 'was not changed'" || ok+run no-auto-update IUI_NO_TYPST=1 IUI_NO_AUTO_UPDATE=1[ "$rc" = 0 ] && [ ! -e "$d/home/.claude" ] && out 'IUI_NO_AUTO_UPDATE is set' && ok || bad "IUI_NO_AUTO_UPDATE: exit $rc, or settings.json was made"log 'plugin install cc-intelligent-ui@razorback16 --scope user' && ok || bad "IUI_NO_AUTO_UPDATE: the mod was not installed"@@ -609,6 +730,7 @@ run zsh-lines IUI_NO_TYPST=1 SHELL=/usr/local/bin/zsh[ "$rc" = 0 ] && is "$d/home/.zshrc" "export A=1$block_sh" && ok || { bad "zsh with lines: not as the mod's withSetup()"; show; }+out 'Added the Intelligent UI block to ~/.zshrc.' && ! out 'older block' && ok || { bad "zsh with lines: the words of an update"; show; }printf 'export A=1\n\n\n' | cmp -s - "$d/home/.zshrc.bak-iui" && ok || bad "zsh with lines: the backup is not the old file"case $(ls -l "$d/home/.zshrc") in -rw-r-----*) ok ;; *) bad "zsh with lines: the mode changed: $(ls -l "$d/home/.zshrc")" ;; esacno_work_left && ok || bad "zsh with lines: a temp file left"@@ -623,6 +745,7 @@ b$block_sh" && ok || { bad "an old block: not replaced as the mod does"; cat "$d/home/.zshrc"; }[ "$(grep -c 'cc-intelligent-ui: Claude Code pictures' "$d/home/.zshrc")" = 1 ] && ok || bad "an old block: two blocks"+out 'Updated the Intelligent UI block in ~/.zshrc (an older block of the mod is replaced)' && out 'updated in ~/.zshrc' && ok || { bad "an old block: no words of an update"; show; }iterm zdotdirmkdir -p "$tmp/zdotdir/zdot"@@ -632,6 +755,21 @@ run zdotdir IUI_NO_TYPST=1 SHELL=/bin/zsh ZDOTDIR="$tmp/zdotdir/zdot"iterm bash-macrun bash-mac IUI_NO_TYPST=1 SHELL=/bin/bash[ "$rc" = 0 ] && is "$d/home/.bash_profile" "$block_sh" && [ ! -e "$d/home/.bashrc" ] && ok || bad "bash on macOS: not ~/.bash_profile"+# Login bash reads only the first of .bash_profile, .bash_login and .profile:+# the block goes there, and no .bash_profile hides the others.+iterm bash-profile+mkdir -p "$tmp/bash-profile/home"+printf 'export MY=1\n' > "$tmp/bash-profile/home/.profile"+run bash-profile IUI_NO_TYPST=1 SHELL=/bin/bash+[ "$rc" = 0 ] && is "$d/home/.profile" "export MY=1++$block_sh" && [ ! -e "$d/home/.bash_profile" ] && ok || { bad "bash on macOS with ~/.profile: a new ~/.bash_profile"; show; }+iterm bash-login+mkdir -p "$tmp/bash-login/home"+printf 'export MY=1\n' > "$tmp/bash-login/home/.bash_login"+printf 'export MY=2\n' > "$tmp/bash-login/home/.profile"+run bash-login IUI_NO_TYPST=1 SHELL=/bin/bash+[ "$rc" = 0 ] && grep -q 'cc-intelligent-ui' "$d/home/.bash_login" && [ "$(cat "$d/home/.profile")" = 'export MY=2' ] && [ ! -e "$d/home/.bash_profile" ] && ok || { bad "bash on macOS with ~/.bash_login: not that file"; show; }# herdr on Linux (in ~/.local/bin, as the script looks for Typst).mkdir -p "$tmp/bash-linux/home/.local/bin"@@ -688,6 +826,15 @@ if [ "$(id -u)" != 0 ]; thenrc_refused unreadable[ "$(cat "$d/home/.zshrc")" = secret ] && ok || bad "unreadable: changed"fi+if [ "$(id -u)" != 0 ]; then+ iterm rc-readonly+ mkdir -p "$tmp/rc-readonly/home"+ printf 'x=1\n' > "$tmp/rc-readonly/home/.zshrc"+ chmod 444 "$tmp/rc-readonly/home/.zshrc"+ run rc-readonly IUI_NO_TYPST=1 SHELL=/bin/zsh+ rc_refused rc-readonly+ out '.zshrc is not writable' && [ "$(cat "$d/home/.zshrc")" = 'x=1' ] && ok || bad "a read-only ~/.zshrc: changed, or no words"+fiiterm rc-foldermkdir -p "$tmp/rc-folder/home/.zshrc"run rc-folder IUI_NO_TYPST=1 SHELL=/bin/zshdiff --git a/tests/setup.test.ts b/tests/setup.test.tsindex 954533a..b868bdc 100644--- a/tests/setup.test.ts+++ b/tests/setup.test.ts@@ -11,6 +11,15 @@ test('the setup writes the start file of the login shell', () => {expect(shellRcOf({ shell: '/bin/tcsh', home: '/h', isMac: true })).toBe(null)})+test('bash on macOS: the first of .bash_profile, .bash_login and .profile that is there; a new .bash_profile only when none is', () => {+ const bash = (loginFiles: string[], isMac = true) => shellRcOf({ shell: '/bin/bash', home: '/h', isMac, loginFiles })!.path+ expect(bash(['.profile'])).toBe('/h/.profile')+ expect(bash(['.bash_login', '.profile'])).toBe('/h/.bash_login')+ expect(bash(['.profile', '.bash_profile'])).toBe('/h/.bash_profile')+ expect(bash([])).toBe('/h/.bash_profile')+ expect(bash(['.profile'], false)).toBe('/h/.bashrc')+})+test('the start file: an empty ZDOTDIR or XDG_CONFIG_HOME is not used, a shell with no path works, no shell gives none', () => {expect(shellRcOf({ shell: 'zsh', home: '/h', zdotdir: '', isMac: false })!.path).toBe('/h/.zshrc')expect(shellRcOf({ shell: '/usr/bin/fish', home: '/h', xdgConfig: '/x', isMac: false })!.path).toBe('/x/fish/conf.d/cc-intelligent-ui.fish')@@ -142,6 +151,22 @@ test('in iTerm2 with pictures off, the plugin asks once and adds the block on yeexpect(files['/h/.zshrc']).toBe('export A=1\n')})+test('bash on macOS: /iui setup writes ~/.profile when it is the login file, and makes no ~/.bash_profile', async ($, on) => {+ const files: Record<string, string> = { '/h/.profile': 'export A=1\n' }+ iterm(on, files, 'Not now', { stored: { setup: 'never' }, env: { SHELL: '/bin/bash' } })+ const ran = await $.command.run({ command: 'iui', args: 'setup' } as any)+ expect(ran.text).toContain('Added the Intelligent UI block to /h/.profile.')+ expect(files['/h/.profile']).toBe(`export A=1\n\n${setupBlock('sh')}`)+ expect(Object.keys(files)).toEqual(['/h/.profile'])+})++test('/iui setup in a session that shows pictures already says so, not to open a new tab', async ($, on) => {+ const files: Record<string, string> = { '/h/.zshrc': withSetup('export A=1\n', 'sh') }+ iterm(on, files, 'Not now', { stored: { setup: 'never' }, env: { CLAUDE_CODE_FORCE_TERMINAL_IMAGES: '1' } })+ const ran = await $.command.run({ command: 'iui', args: 'setup' } as any)+ expect(ran.text).toBe('/h/.zshrc already has the Intelligent UI block. Pictures are on in this tab already.')+})+test('a dismissed question changes no file', async ($, on) => {const files: Record<string, string> = { '/h/.zshrc': 'export A=1\n' }const { asked, clock } = iterm(on, files, null)