Skip to content

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: always end with the newest mod; pictures in iTerm2 and herdr

razorback160b0187205297
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1911b65..66f5e98 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,7 @@ All releases of Intelligent UI for Claude Code (`cc-intelligent-ui`). Claude Cod
### New
-- **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, and turns on auto-update for the marketplace in `~/.claude/settings.json` (`extraKnownMarketplaces`, with a backup; all other settings stay byte for byte). Run it again to update. It never uses `sudo`. `IUI_NO_TYPST=1` and `IUI_NO_AUTO_UPDATE=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). 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
diff --git a/README.md b/README.md
index 3610643..c84b1c3 100644
--- a/README.md
+++ b/README.md
@@ -26,10 +26,11 @@ 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.
-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 old file as `settings.json.bak-iui`. If the file is not valid JSON, the script does not change it and shows the lines to add.
+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.
-`IUI_NO_TYPST=1` skips step 2, and `IUI_NO_AUTO_UPDATE=1` skips step 4, for example `curl -fsSL https://intelligentui.art/install.sh | IUI_NO_AUTO_UPDATE=1 bash`.
+`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`.
To undo: `claude plugin uninstall cc-intelligent-ui@razorback16`, then `claude plugin marketplace remove razorback16` (this also removes its entry in `settings.json`). If the script installed Typst: `rm ~/.local/bin/typst`. Refer to [The install script](docs/install.md#the-install-script).
@@ -131,7 +132,7 @@ The mod sends nothing about you or your sessions anywhere.
- **Network:** one GET request each day at most, to `raw.githubusercontent.com`, for the public `plugin.json` of this mod. It only tells you about a new version. `/iui updates off` stops it. It also stops when `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`, `DISABLE_UPDATES` or `DISABLE_AUTOUPDATER` is set.
- **Clipboard, read:** a small `perl` process watches the clipboard while the mod is on and has drawn a picture (not over ssh). On macOS it reads only the change counter; when the counter changes, the mod reads the text once with a short `perl` script (PerlObjCBridge). On Linux a notifier (`wl-paste --watch`, `clipnotify` or GTK 3 from `python3`) tells it of each change, and it then reads the text with `wl-paste`, `xclip` or GTK. `/iui grab` with no mouse selection also reads the clipboard once. The text is only checked for picture cells (then a toast names `/iui grab`); it is kept in memory only and sent nowhere (`/iui dump` writes the last clipboard with picture cells to `copy-debug.json` in the cache folder). A password manager's copy is never read: on macOS a copy with a concealed or transient type, on Linux a copy that offers the `x-kde-passwordManagerHint` target, and on Wayland also a copy marked sensitive. (On Wayland, `wl-paste --watch` hands each new copy to `cat`, which drops it.)
- **Clipboard, written:** only at these times: when you release a picture selection, when you click a link, a file path, a command or a copy button in a picture, on `/iui grab`, when you press the command button in a link row (in fullscreen with `/iui select off`, where Claude Code gets the click), and when the mod changes a `$.ui.copy` that has picture cells to its text.
-- **Files:** a private cache folder in `$TMPDIR` (`cc-intelligent-ui-<uid>`, `/tmp` when `TMPDIR` is not set; mode 700, its folders deleted after 2 days). Each compile makes a folder of its own in it (the Typst root, see below) and deletes it after the compile. Also `~/.cache/cc-intelligent-ui/designs` (files deleted after 180 days) and `~/.cache/cc-intelligent-ui/fonts` (fonts copied out of a terminal app, such as Ghostty's JetBrains Mono; `$XDG_CACHE_HOME` in place of `~/.cache` when it is set). `/iui setup` on macOS changes your shell start file, only when you run it or agree to its question.
+- **Files:** a private cache folder in `$TMPDIR` (`cc-intelligent-ui-<uid>`, `/tmp` when `TMPDIR` is not set; mode 700, its folders deleted after 2 days). Each compile makes a folder of its own in it (the Typst root, see below) and deletes it after the compile. Also `~/.cache/cc-intelligent-ui/designs` (files deleted after 180 days) and `~/.cache/cc-intelligent-ui/fonts` (fonts copied out of a terminal app, such as Ghostty's JetBrains Mono; `$XDG_CACHE_HOME` in place of `~/.cache` when it is set). `/iui setup` on macOS changes your shell start file, only when you run it or agree to its question. The install script adds the same block when iTerm2 or herdr is there (`IUI_NO_SHELL_SETUP=1` stops it).
- **Processes:** `typst`, the `perl` watcher, and short helper commands such as `perl`, `sh`, `osascript`, `defaults`, `plutil`, `fc-list` and `fc-match`. On Linux also `wl-paste`, `xclip`, `clipnotify` or `python3 -I` (GTK 3; isolated, so it loads no code from the project folder) for the clipboard.
- **Typst:** each compile of an answer or a plan runs with a narrow root: a new folder with the mod's template, the theme and the images that the text names. So the code in an answer cannot read other files on your computer. The skill's `check.sh` compiles the same way.
diff --git a/docs/install.md b/docs/install.md
index fba2c79..1ea2df4 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -43,6 +43,12 @@ The 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.
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.
+
+ 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 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`:
```json
@@ -54,13 +60,15 @@ 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 old file as `settings.json.bak-iui`, only when it changed the file. If the file is not there, it makes it. If `autoUpdate` is `true` already, it changes nothing. 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. **Summary.** What was installed or updated, where Typst is, the state of auto-update, and how to undo each step.
+ `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.
+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):
- `IUI_NO_TYPST=1`: no Typst step. The script does not look for Typst and downloads nothing.
- `IUI_NO_AUTO_UPDATE=1`: no auto-update step. `settings.json` does not change.
+- `IUI_NO_SHELL_SETUP=1`: no shell setup step (5). No shell start file changes.
For example: `curl -fsSL https://intelligentui.art/install.sh | IUI_NO_TYPST=1 bash`.
@@ -70,8 +78,11 @@ To undo:
- The mod: `claude plugin uninstall cc-intelligent-ui@razorback16`
- The marketplace: `claude plugin marketplace remove razorback16`. Claude Code also removes the `razorback16` entry of `extraKnownMarketplaces` from your settings.
-- Only auto-update: in Claude Code, type `/plugin`, go to **Marketplaces**, select **razorback16**, then select **Disable auto-update**. Or copy `settings.json.bak-iui` back to `settings.json`.
+- Only auto-update: in Claude Code, type `/plugin`, go to **Marketplaces**, select **razorback16**, then select **Disable auto-update**. In Claude Code 2.1.307, this also sets `"autoUpdate": false` in the settings file that declares the marketplace. Or copy `settings.json.bak-iui` back to `settings.json` (it is the file before the auto-update change only).
+- The old marketplace source, if the script replaced it: `claude plugin marketplace remove razorback16`, then `claude plugin marketplace add <old source>` (the script shows the old source).
+- A copy from another marketplace that the script uninstalled: `claude plugin install <id> --scope user` (the script shows the id).
- Typst, if the script installed it: `rm ~/.local/bin/typst`
+- The shell setup: `/iui setup remove` in Claude Code, or delete the lines from `# >>> cc-intelligent-ui` to `# <<< cc-intelligent-ui <<<` in the start file that the script names.
### By hand
diff --git a/site/install.sh b/site/install.sh
index d5a21cb..ffc8787 100755
--- a/site/install.sh
+++ b/site/install.sh
@@ -8,11 +8,18 @@
# 2. Typst: when no Typst 0.15 or later is found, downloads the official Typst 0.15.1
# release from GitHub, checks its SHA-256 (in this file) and puts it in ~/.local/bin.
# 3. Adds the razorback16 marketplace and installs the mod, with the `claude plugin`
-# commands (or updates both when they are there).
+# commands (or updates both when they are there). A razorback16 marketplace from
+# another source (a fork, a pinned ref, a local folder) is removed and added again
+# from GitHub. Another user copy of the mod (from another marketplace) is uninstalled;
+# 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.
+# settings.json (extraKnownMarketplaces), with a backup of the file before that change.
# Run it again to update. It never uses sudo.
-# Options: IUI_NO_TYPST=1 (no Typst step), IUI_NO_AUTO_UPDATE=1 (no auto-update step).
+# 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
+# your login shell, with a backup. /iui setup remove removes it.
+# Options: IUI_NO_TYPST=1 (no Typst step), IUI_NO_AUTO_UPDATE=1 (no auto-update step),
+# IUI_NO_SHELL_SETUP=1 (no shell setup step).
# All the work is in functions, and the last line runs it: a cut download runs nothing.
if [ -z "${BASH_VERSION:-}" ]; then
@@ -157,9 +164,12 @@ typst_version() {
}
# The typst that the mod uses: the PATH first, then TYPST_DIRS in order.
-mod_typst() {
+mod_typst() { find_tool typst; }
+
+# The program $1: on the PATH, else in TYPST_DIRS in order.
+find_tool() {
local p d
- p=$(command -v typst 2> /dev/null || true)
+ p=$(command -v "$1" 2> /dev/null || true)
case $p in /*)
printf '%s' "$p"
return 0
@@ -167,8 +177,8 @@ mod_typst() {
esac
for d in $TYPST_DIRS; do
case $d in \~/*) d=$HOME/${d#\~/} ;; esac
- if [ -e "$d/typst" ]; then
- printf '%s' "$d/typst"
+ if [ -e "$d/$1" ]; then
+ printf '%s' "$d/$1"
return 0
fi
done
@@ -263,10 +273,15 @@ install_typst() {
# A small strict JSON reader that keeps the byte place of each value, so a
# change to settings.json inserts text and keeps all other bytes. It needs
# only core perl (no modules). Modes:
-# has-name NAME stdin: a JSON array; exit 0 when an object in it has "name": NAME
-# plugin ID stdin: a JSON array; prints the "version" and "enabled" of "id": ID, "scope": "user"
+# marketplace NAME stdin: the marketplace list (a JSON array); prints 3 lines for "name": NAME:
+# official or other, the source for `marketplace add`, and a description.
+# 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).
+# Exit 3: stdin is not a JSON array.
json_pl() {
cat << 'PERL'
use strict; use warnings;
@@ -339,26 +354,69 @@ sub parse {
# The last member named $k (JSON.parse keeps the last one).
sub member { my ($o, $k) = @_; my $f; for (@{ $o->{m} }) { $f = $_ if $_->{k} eq $k } return $f }
-if ($mode eq 'has-name' || $mode eq 'plugin') {
+# 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 }
+# 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 {
+ my $o = shift;
+ for my $k (qw(ref path)) { my $x = sv($o, $k); return 0 if defined $x && $x ne '' }
+ return 0 if member($o, 'sparsePaths');
+ my $kind = sv($o, 'source') // '';
+ my $repo = sv($o, 'repo') // '';
+ my $url = sv($o, 'url') // '';
+ return 1 if $kind eq 'github' && lc($repo) eq 'razorback16/cc-intelligent-ui';
+ return 1 if $kind eq 'git' && $url =~ m{\Ahttps://github\.com/razorback16/cc-intelligent-ui(?:\.git)?\z}i;
+ return 0;
+}
+
+if ($mode eq 'marketplace' || $mode eq 'plugin' || $mode eq 'copies') {
local $/; my $in = <STDIN> // '';
my $v = eval { parse($in) } or exit 3;
exit 3 unless $v->{t} eq 'a';
for my $x (@{ $v->{l} }) {
next unless $x->{t} eq 'o';
- if ($mode eq 'has-name') {
- my $n = member($x, 'name');
- exit 0 if $n && $n->{v}{t} eq 's' && $n->{v}{s} eq $args[0];
- } else {
- my ($id, $sc, $ver, $en) = map { member($x, $_) } qw(id scope version enabled);
- next unless $id && $id->{v}{t} eq 's' && $id->{v}{s} eq $args[0];
+ if ($mode eq 'marketplace') {
+ next unless (sv($x, 'name') // '') eq $args[0];
+ my ($kind, $ref, $path) = map { clean(sv($x, $_)) } qw(source ref path);
+ my ($spec, $desc);
+ if ($kind eq 'github' || $kind eq 'git') {
+ my $at = clean(sv($x, $kind eq 'git' ? 'url' : 'repo'));
+ $spec = $at . ($ref ne '' ? "#$ref" : '');
+ $desc = ($kind eq 'git' ? "the git URL $at" : "the GitHub repository $at") . ($ref ne '' ? " (ref $ref)" : '') . ($path ne '' ? " (folder $path)" : '');
+ } elsif ($kind eq 'directory' || $kind eq 'file') {
+ $spec = $path;
+ $desc = ($kind eq 'file' ? 'the local file ' : 'the local folder ') . $path;
+ } elsif ($kind eq 'url') {
+ $spec = clean(sv($x, 'url'));
+ $desc = "the URL $spec";
+ } else {
+ $spec = '';
+ $desc = "a source of the type '$kind'";
+ }
+ print official($x) ? 'official' : 'other', "\n$spec\n$desc\n";
+ exit 0;
+ }
+ my ($id, $sc, $ver, $en) = map { member($x, $_) } qw(id scope version enabled);
+ next unless $id && $id->{v}{t} eq 's';
+ my $vs = ($ver && $ver->{v}{t} eq 's') ? $ver->{v}{s} : '?';
+ $vs =~ s/[^\x21-\x7e]//g;
+ my $state = ($en && $en->{v}{t} eq 'false') ? 'disabled' : 'enabled';
+ if ($mode eq 'plugin') {
+ next unless $id->{v}{s} eq $args[0];
next unless $sc && $sc->{v}{t} eq 's' && $sc->{v}{s} eq 'user';
- my $vs = ($ver && $ver->{v}{t} eq 's') ? $ver->{v}{s} : '?';
- $vs =~ s/[^\x21-\x7e]//g;
- print $vs, ' ', (($en && $en->{v}{t} eq 'false') ? 'disabled' : 'enabled'), "\n";
+ print $vs eq '' ? '?' : $vs, " $state\n";
exit 0;
}
+ # copies: only ids that are safe to give to `claude plugin`.
+ 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";
}
- exit 1;
+ exit($mode eq 'copies' ? 0 : 1);
}
exit 4 unless $mode eq 'settings';
@@ -452,6 +510,9 @@ if (!defined $old || $old =~ /\A\s*\z/) {
} elsif ($rb->{v}{t} ne 'o') {
refuse("extraKnownMarketplaces.$name in $file is not an object");
} else {
+ my $src = member($rb->{v}, 'source');
+ refuse("extraKnownMarketplaces.$name in $file has another source, not the GitHub repository razorback16/cc-intelligent-ui")
+ 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 }
if ($au) {
@@ -490,51 +551,217 @@ json() { perl -e "$(json_pl)" "$@"; }
# --- 3. The mod ----------------------------------------------------------------
SUM_PLUGIN=
+COPIES=
+# Undo lines of step 3 that are not always there (one per line).
+UNDO_MORE=
+TAB=$(printf '\t')
+# $1 quoted for a shell command line, when it needs quotes.
+shq() {
+ case $1 in
+ '' | *[!A-Za-z0-9_./:@#%+=,-]*) printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")" ;;
+ *) printf '%s' "$1" ;;
+ esac
+}
+# The version in a plugin_state line, or "?".
+ver_of() {
+ local v=${1%% *}
+ printf '%s' "${v:-?}"
+}
+
# "VERSION enabled|disabled" of the mod in user scope, or nothing.
plugin_state() {
"$CLAUDE" plugin list --json < /dev/null 2> /dev/null | json plugin "$PLUGIN" 2> /dev/null || true
}
-marketplace_known() {
- local out rc=0
+# Each copy of the mod, from any marketplace, in any scope (lines of
+# id, scope, version, enabled and projectPath, with tabs).
+plugin_copies() {
+ "$CLAUDE" plugin list --json < /dev/null 2> /dev/null | json copies "$PLUGIN_NAME" 2> /dev/null || true
+}
+
+# The razorback16 marketplace. MKT_KIND: official, other (another source:
+# MKT_SPEC and MKT_DESC tell which), none (not known) or unknown (no JSON list).
+MKT_KIND=
+MKT_SPEC=
+MKT_DESC=
+marketplace_source() {
+ local out info rc=0
+ MKT_KIND=unknown
if out=$("$CLAUDE" plugin marketplace list --json < /dev/null 2> /dev/null); then
- printf '%s' "$out" | json has-name "$MARKETPLACE" 2> /dev/null || rc=$?
- case $rc in 0 | 1) return $rc ;; esac
+ info=$(printf '%s' "$out" | json marketplace "$MARKETPLACE" 2> /dev/null) || rc=$?
+ case $rc in
+ 0)
+ {
+ IFS= read -r MKT_KIND
+ IFS= read -r MKT_SPEC
+ IFS= read -r MKT_DESC
+ } << INFO || true
+$info
+INFO
+ return 0
+ ;;
+ 1)
+ MKT_KIND=none
+ return 0
+ ;;
+ esac
fi
- # No JSON: the text list.
- "$CLAUDE" plugin marketplace list < /dev/null 2> /dev/null | grep -qw "$MARKETPLACE"
+ # No JSON: the text list. The source is not known.
+ if ! "$CLAUDE" plugin marketplace list < /dev/null 2> /dev/null | grep -qw "$MARKETPLACE"; then MKT_KIND=none; fi
}
-install_plugin() {
- local before after
- step "3. The mod: $PLUGIN"
- if marketplace_known; then
- claude_run plugin marketplace update "$MARKETPLACE" || warn "the marketplace update failed. The mod is updated from the copy that Claude Code has."
+# 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.
+OLD_STATE=
+REPOINTED=
+repoint_marketplace() {
+ local id scope ver pp undo
+ warn "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 "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)
+ while IFS=$TAB read -r id scope ver _ pp; do
+ if [ "$id" = "$PLUGIN" ] && [ "$scope" != user ]; then
+ note "Claude Code can also remove the copy of the mod in $scope scope for ${pp:-a project}."
+ fi
+ done << COPIES
+$COPIES
+COPIES
+ if [ -n "$MKT_SPEC" ]; then
+ undo="claude plugin marketplace remove $MARKETPLACE, then claude plugin marketplace add $(shq "$MKT_SPEC")"
else
- claude_run plugin marketplace add "$MARKETPLACE_REPO" || die "Claude Code could not add the marketplace $MARKETPLACE_REPO."
+ undo="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:-?}")"
fi
+ note "The $MARKETPLACE marketplace comes from $MARKETPLACE_REPO now (before: $MKT_DESC)."
+ REPOINTED=1
+ UNDO_MORE="${UNDO_MORE}Old source: $undo
+"
+}
+
+# A copy that is in $2 (copies lines) with the id, scope and path of line $1.
+copy_in() {
+ local id scope pp i s p
+ IFS=$TAB read -r id scope _ _ pp << LINE
+$1
+LINE
+ while IFS=$TAB read -r i s _ _ p; do
+ if [ "$i" = "$id" ] && [ "$s" = "$scope" ] && [ "$p" = "$pp" ]; then return 0; fi
+ done << LIST
+$2
+LIST
+ return 1
+}
+
+install_plugin() {
+ local before after rc=0 mkt_ok=1 now line id scope ver pp old new
+ step "3. The mod: $PLUGIN"
+ COPIES=$(plugin_copies)
+ marketplace_source
+ case $MKT_KIND in
+ none) claude_run plugin marketplace add "$MARKETPLACE_REPO" || die "Claude Code could not add the marketplace $MARKETPLACE_REPO." ;;
+ other) repoint_marketplace ;;
+ *)
+ if ! claude_run plugin marketplace update "$MARKETPLACE"; then
+ mkt_ok=
+ warn "the marketplace update failed. The mod is updated from the copy of the marketplace that Claude Code has, which can be old."
+ fi
+ ;;
+ esac
before=$(plugin_state)
if [ -n "$before" ]; then
- claude_run plugin update "$PLUGIN" --scope user || warn "the update of the mod failed. The installed version stays."
+ claude_run plugin update "$PLUGIN" --scope user || rc=$?
after=$(plugin_state)
- if [ "${after%% *}" = "${before%% *}" ]; then
- SUM_PLUGIN="$PLUGIN_NAME ${after%% *} (the newest version was installed already)"
+ if [ "$rc" != 0 ]; then
+ warn "the update of the mod failed. The installed version ($(ver_of "$after")) stays."
+ SUM_PLUGIN="$PLUGIN_NAME $(ver_of "$after") (NOT updated: the update failed, refer to the warning above)"
+ PROBLEM=1
+ elif [ "$(ver_of "$after")" != "$(ver_of "$before")" ]; then
+ SUM_PLUGIN="$PLUGIN_NAME $(ver_of "$after") (updated from $(ver_of "$before"))"
+ elif [ -z "$mkt_ok" ]; then
+ SUM_PLUGIN="$PLUGIN_NAME $(ver_of "$after") (NOT checked for a newer version: the marketplace update failed)"
+ PROBLEM=1
+ elif [ "$MKT_KIND" = unknown ]; then
+ SUM_PLUGIN="$PLUGIN_NAME $(ver_of "$after") (no newer version found)"
else
- SUM_PLUGIN="$PLUGIN_NAME ${after%% *} (updated from ${before%% *})"
+ SUM_PLUGIN="$PLUGIN_NAME $(ver_of "$after") (the newest version was installed already)"
fi
else
claude_run plugin install "$PLUGIN" --scope user || die "Claude Code could not install $PLUGIN."
after=$(plugin_state)
- SUM_PLUGIN="$PLUGIN_NAME ${after%% *} (installed)"
+ SUM_PLUGIN="$PLUGIN_NAME $(ver_of "$after") (installed)"
+ fi
+ if [ -n "$REPOINTED" ] && [ "$rc" = 0 ]; then
+ SUM_PLUGIN="$PLUGIN_NAME $(ver_of "$after") (from $MARKETPLACE_REPO now; before: $(ver_of "$OLD_STATE") from $MKT_DESC)"
+ # A local folder can have a version that is not released yet.
+ old=$(ver_of "$OLD_STATE")
+ new=$(ver_of "$after")
+ if [ "$old" != '?' ] && [ "$new" != '?' ] && [ "$old" != "$new" ] && version_ge "$old" "$new"; then
+ warn "the version from the old source ($old) is newer than the version on GitHub ($new). To use the old source again: $(printf '%s' "$UNDO_MORE" | sed -n 's/^Old source: *//p')"
+ fi
fi
+ # A mod that was disabled before the new marketplace stays disabled.
+ case $OLD_STATE:$after in
+ *' disabled:'*' enabled')
+ claude_run plugin disable "$PLUGIN" --scope user || warn "Claude Code could not disable the mod again."
+ after=$(plugin_state)
+ ;;
+ esac
case $after in
*' disabled') warn "the mod is disabled in Claude Code. To turn it on: claude plugin enable $PLUGIN" ;;
esac
+ now=$(plugin_copies)
+ # Another copy in user scope (from another marketplace) would run too.
+ if [ -n "$after" ]; then
+ while IFS=$TAB read -r id scope ver _ pp; do
+ case $id in '' | "$PLUGIN") continue ;; esac
+ [ "$scope" = user ] || continue
+ note "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
+ note "Uninstalled $id. Its /iui settings are kept under its own name; set them again with /iui if you want."
+ UNDO_MORE="${UNDO_MORE}Other copy: claude plugin install $id --scope user
+"
+ else
+ warn "Claude Code could not uninstall $id. Two copies of the mod run. To remove it: claude plugin uninstall $id --scope user"
+ PROBLEM=1
+ fi
+ done << NOW
+$now
+NOW
+ now=$(plugin_copies)
+ fi
+ # Copies in a project: not changed. In that folder, they can hide the user copy.
+ while IFS=$TAB read -r id scope ver _ pp; do
+ case $scope in '' | user) continue ;; esac
+ warn "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
+NOW
+ # Copies that Claude Code removed with the old marketplace.
+ if [ -n "$REPOINTED" ]; then
+ while IFS= read -r line; do
+ IFS=$TAB read -r id scope _ _ pp << LINE
+$line
+LINE
+ case $scope in '' | user) continue ;; esac
+ [ "$id" = "$PLUGIN" ] || continue
+ copy_in "$line" "$now" && continue
+ warn "Claude Code removed the copy of the mod in $scope scope for ${pp:-a project} with the old marketplace. To install it there again: cd $(shq "${pp:-.}") && claude plugin install $PLUGIN --scope $scope"
+ done << COPIES
+$COPIES
+COPIES
+ fi
}
# --- 4. Auto-update ------------------------------------------------------------
SUM_AUTO=
+AUTO_ON=
UNDO_AUTO=
PROBLEM=
manual_auto_update() {
@@ -586,17 +813,20 @@ auto_update() {
0:unchanged)
note "Auto-update is on already ($(tilde "$file")). Not changed."
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)"
- UNDO_AUTO="delete $(tilde "$file")"
+ AUTO_ON=1
;;
0:changed)
note "Set extraKnownMarketplaces.$MARKETPLACE.autoUpdate = true in $(tilde "$file")."
- note "All other settings are kept. The file before the change: $(tilde "$file").bak-iui"
+ 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"))"
- UNDO_AUTO="copy $(tilde "$file").bak-iui back to $(tilde "$file")"
+ AUTO_ON=1
+ UNDO_AUTO="copy $(tilde "$file").bak-iui (the file before the auto-update change only) back to $(tilde "$file")"
;;
*)
warn "$(tilde "$file") was not changed: ${result:-an unknown error}"
@@ -607,13 +837,176 @@ auto_update() {
esac
}
-# --- 5. Summary ----------------------------------------------------------------
+# --- 5. Pictures in iTerm2 and herdr -------------------------------------------
+
+# The mod's own setup block (SETUP_START, SETUP_END and setupBlock() of
+# hooks/lib/setup.ts, byte for byte): Claude Code shows pictures in iTerm2 and
+# herdr only with CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 when it starts. The mod's
+# /iui setup sees this block as done, and /iui setup remove removes it.
+SETUP_START='# >>> cc-intelligent-ui: Claude Code pictures in iTerm2 >>>'
+SETUP_END='# <<< cc-intelligent-ui <<<'
+# shellcheck disable=SC2016 # the shell reads these lines later, not now
+SETUP_SH='if { [ "$TERM_PROGRAM" = "iTerm.app" ] || [ "$TERM_PROGRAM" = "herdr" ]; } && [ -z "$TMUX" ] && [ -z "$STY" ]; then export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1; fi'
+# shellcheck disable=SC2016
+SETUP_FISH='if test "$TERM_PROGRAM" = "iTerm.app" -o "$TERM_PROGRAM" = "herdr"; and not set -q TMUX; and not set -q STY; set -gx CLAUDE_CODE_FORCE_TERMINAL_IMAGES 1; end'
+
+# 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).
+setup_pl() {
+ cat << 'PERL'
+use strict; use warnings;
+use Fcntl;
+my ($file, $start, $line, $end, $bak) = @ARGV;
+sub refuse { print "$_[0]\n"; exit 2 }
+my $real = $file;
+if (-l $file) {
+ require Cwd;
+ $real = Cwd::realpath($file);
+ refuse("$file is a link to a file that is not there") unless defined $real && -e $real;
+}
+my $old;
+if (-e $real) {
+ refuse("$file is not a regular file") unless -f $real;
+ refuse("$file is larger than 4 MB") if -s $real > 4 * 1024 * 1024;
+ open(my $fh, '<:raw', $real) or refuse("can not read $file: $!");
+ local $/; $old = <$fh>; close $fh;
+ refuse("can not read $file") unless defined $old;
+}
+my $text = $old // '';
+my $block = "$start\n$line\n$end\n";
+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;
+for (my $i = 0; $i < @lines; $i++) {
+ if ($lines[$i] ne $start) { push @out, $lines[$i]; next }
+ my $e = -1;
+ for my $j ($i .. $#lines) { if ($lines[$j] eq $end) { $e = $j; last } }
+ if ($e < 0) { push @out, $lines[$i]; next }
+ pop @out if @out && $out[-1] eq '';
+ $i = $e;
+}
+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 $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";
+ chmod($fmode, $tmp) if defined $fmode;
+ rename($tmp, $path) or do { unlink $tmp; die "can not write $path: $!\n" };
+}
+my $fmode = defined $old ? (stat $real)[2] & 07777 : undef;
+eval {
+ put($bak, $old, $fmode) if defined $old;
+ put($real, $new, $fmode);
+ 1;
+} or refuse("$@");
+print defined $old ? "changed\n" : "created\n";
+PERL
+}
+
+# 0 when iTerm2 is installed (macOS). IUI_TEST_ROOT is only for the tests.
+has_iterm() {
+ local p
+ [ "$OS" = macos ] || return 1
+ for p in "${IUI_TEST_ROOT:-}/Applications/iTerm.app" "$HOME/Applications/iTerm.app"; do
+ if [ -d "$p" ]; then return 0; fi
+ done
+ command -v mdfind > /dev/null 2>&1 || return 1
+ # Spotlight, stopped after 5 s.
+ p=$(perl -e 'alarm 5; exec @ARGV' mdfind "kMDItemCFBundleIdentifier == 'com.googlecode.iterm2'" < /dev/null 2> /dev/null | grep -m 1 '\.app$' || true)
+ [ -n "$p" ]
+}
+
+SUM_SHELL=
+UNDO_SHELL=
+shell_setup() {
+ local apps='' name file kind line result rc t
+ step "5. Pictures in iTerm2 and herdr"
+ if on "${IUI_NO_SHELL_SETUP:-}"; then
+ note "Skipped (IUI_NO_SHELL_SETUP is set)."
+ SUM_SHELL="not changed (IUI_NO_SHELL_SETUP is set)"
+ return 0
+ fi
+ if has_iterm; then apps=iTerm2; fi
+ if [ -n "$(find_tool herdr)" ]; then apps=${apps:+$apps and }herdr; fi
+ if [ -z "$apps" ]; then
+ note "No iTerm2 or herdr found. Not needed: other terminals need no setup."
+ SUM_SHELL="not needed (no iTerm2 or herdr)"
+ return 0
+ fi
+ note "$apps found. Claude Code shows pictures there only with CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1."
+ # The start file of the login shell, as the mod's shellRcOf() picks it.
+ name=${SHELL:-}
+ name=${name##*/}
+ case $name in
+ zsh) file=${ZDOTDIR:-$HOME}/.zshrc kind='sh' ;;
+ bash)
+ kind='sh'
+ if [ "$OS" = macos ]; then file=$HOME/.bash_profile; else file=$HOME/.bashrc; fi
+ ;;
+ fish) file=${XDG_CONFIG_HOME:-$HOME/.config}/fish/conf.d/cc-intelligent-ui.fish kind='fish' ;;
+ *)
+ note "Your shell (${name:-not known}) is not one that the mod knows, so no file was changed."
+ note "Add this to your shell's start file: export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 (only in iTerm2 and herdr, not in tmux or screen)"
+ SUM_SHELL="NOT added (your shell is not known; refer to the lines above)"
+ return 0
+ ;;
+ esac
+ if [ "$kind" = fish ]; then line=$SETUP_FISH; else line=$SETUP_SH; fi
+ if ! command -v perl > /dev/null 2>&1; then
+ result="perl is not installed"
+ rc=2
+ else
+ if [ "$kind" = fish ] && [ ! -e "$file" ] && [ ! -L "$file" ]; then mkdir -p "${file%/*}"; fi
+ rc=0
+ result=$(perl -e "$(setup_pl)" "$file" "$SETUP_START" "$line" "$SETUP_END" "$file.bak-iui" 2>&1) || rc=$?
+ fi
+ t="~"
+ result=${result//"$HOME"/$t}
+ case $rc:$result in
+ 0:unchanged)
+ note "$(tilde "$file") has the Intelligent UI block already. Not changed."
+ SUM_SHELL="set already in $(tilde "$file")"
+ ;;
+ 0:created)
+ note "Made $(tilde "$file") with the Intelligent UI block."
+ 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 "The file before this change: $(tilde "$file").bak-iui"
+ SUM_SHELL="added to $(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
+ printf ' %s\n' "$SETUP_START" "$line" "$SETUP_END" >&2
+ SUM_SHELL="NOT added (refer to the warning above)"
+ PROBLEM=1
+ return 0
+ ;;
+ esac
+ UNDO_SHELL="/iui setup remove in Claude Code, or delete the lines from '$SETUP_START' to '$SETUP_END' in $(tilde "$file")"
+}
+
+# --- 6. Summary ----------------------------------------------------------------
summary() {
step "Done"
note "Typst: $SUM_TYPST"
note "Mod: $SUM_PLUGIN"
note "Auto-update: $SUM_AUTO"
+ note "Pictures in iTerm2/herdr: $SUM_SHELL"
say ""
say "Restart Claude Code, or type /reload-plugins in a session that runs now."
say "Intelligent UI works best in fullscreen mode: type /tui fullscreen in Claude Code."
@@ -624,9 +1017,13 @@ summary() {
if [ -n "$UNDO_TYPST" ]; then note "Typst: $UNDO_TYPST"; fi
note "Mod: claude plugin uninstall $PLUGIN"
note "Marketplace: claude plugin marketplace remove $MARKETPLACE (also removes its settings entry)"
- if [ -n "$UNDO_AUTO" ]; then
- note "Auto-update: /plugin > Marketplaces > $MARKETPLACE > Disable auto-update, or $UNDO_AUTO"
+ if [ -n "$UNDO_MORE" ]; then printf '%s' "$UNDO_MORE" | sed 's/^/ /'; fi
+ if [ -n "$AUTO_ON" ]; then
+ note "Auto-update: /plugin > Marketplaces > $MARKETPLACE > Disable auto-update"
+ note " (it also sets extraKnownMarketplaces.$MARKETPLACE.autoUpdate to false in settings.json)"
+ if [ -n "$UNDO_AUTO" ]; then note " or $UNDO_AUTO"; fi
fi
+ if [ -n "$UNDO_SHELL" ]; then note "Shell setup: $UNDO_SHELL"; fi
}
main() {
@@ -636,7 +1033,8 @@ main() {
trap 'exit 143' TERM
say "${BOLD}Intelligent UI for Claude Code: installer${PLAIN}"
say "It installs Typst $TYPST_VERSION (when no Typst $TYPST_MIN or later is found), the mod $PLUGIN,"
- say "and turns on auto-update for the $MARKETPLACE marketplace. It never uses sudo."
+ say "turns on auto-update for the $MARKETPLACE marketplace, and sets up pictures in iTerm2 and herdr."
+ say "It never uses sudo."
step "1. Checks"
check_platform
check_claude
@@ -645,6 +1043,7 @@ main() {
WORK=
install_plugin
auto_update
+ shell_setup
summary
if [ -n "$PROBLEM" ]; then
say ""
diff --git a/tests/install-sh-test.sh b/tests/install-sh-test.sh
index 7c1daa6..782b482 100644
--- a/tests/install-sh-test.sh
+++ b/tests/install-sh-test.sh
@@ -6,9 +6,14 @@
# system that is not supported, changes nothing; a Typst 0.15 that is there
# 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; the IUI_NO_* options; a cut download runs
+# is not valid JSON or set already; 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.
# Usage: sh tests/install-sh-test.sh (exit 0 when all pass)
set -u
@@ -23,7 +28,9 @@ ok() { pass=$((pass + 1)); }
bad() { fail=$((fail + 1)); echo "FAIL: $*"; }
sys=/usr/bin:/bin:/usr/sbin:/sbin
-# The fakes. claude: its state (marketplace added, mod version) in $FAKE_STATE.
+# The fakes. claude: its state in $FAKE_STATE: mkt (the razorback16 entry of the
+# marketplace list, as JSON; no file: not known) and plugins (the installed
+# copies: id, scope, version, enabled, projectPath, extra JSON; with tabs).
fake=$tmp/fake
nocl=$tmp/fake-no-claude
mkdir -p "$fake" "$nocl" "$tmp/assets" "$tmp/build"
@@ -32,18 +39,72 @@ cat > "$fake/claude" << 'EOF'
st=${FAKE_STATE:?}
echo "$*" >> "$st/claude.log"
if IFS= read -r line; then echo "$line" >> "$st/stdin.log"; fi
+P=$st/plugins
+touch "$P"
+T=$(printf '\t')
+ours=cc-intelligent-ui@razorback16
+official='{"name": "razorback16", "source": "github", "repo": "razorback16/cc-intelligent-ui", "installLocation": "/fake/marketplaces/razorback16"}'
+# setp ID SCOPE VERSION ENABLED: one line for the id and scope.
+setp() {
+ grep -v "^$1$T$2$T" "$P" > "$P.new"
+ printf '%s\t%s\t%s\t%s\t\t\n' "$1" "$2" "$3" "$4" >> "$P.new"
+ mv "$P.new" "$P"
+}
+# getp ID SCOPE FIELD
+getp() { awk -F"$T" -v i="$1" -v s="$2" -v f="$3" '$1 == i && $2 == s { print $f }' "$P"; }
case "$*" in
--version) echo "${FAKE_CLAUDE_VERSION:-2.1.307} (Claude Code)" ;;
'plugin marketplace list --json')
- if [ -f "$st/mkt" ]; then printf '[\n {\n "name": "razorback16",\n "source": "github",\n "repo": "razorback16/cc-intelligent-ui"\n }\n]\n'
- else printf '[\n {\n "name": "other",\n "source": "github",\n "repo": "o/r"\n }\n]\n'; fi ;;
- 'plugin marketplace add razorback16/cc-intelligent-ui') touch "$st/mkt"; echo 'Successfully added marketplace: razorback16 (declared in user settings)' ;;
- 'plugin marketplace update razorback16') echo 'Successfully updated marketplace: razorback16' ;;
+ printf '[\n {\n "name": "other",\n "source": "github",\n "repo": "o/r",\n "installLocation": "/fake/marketplaces/other"\n }'
+ if [ -f "$st/mkt" ]; then printf ',\n %s' "$(cat "$st/mkt")"; fi
+ printf '\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
+ exit 1
+ fi
+ [ -z "${FAKE_ADD_FAIL:-}" ] || exit 1
+ echo "$official" > "$st/mkt"
+ echo 'Successfully added marketplace: razorback16 (declared in user settings)' ;;
+ 'plugin marketplace update razorback16')
+ [ -z "${FAKE_MKT_UPDATE_FAIL:-}" ] || { echo 'Failed to update marketplace' >&2; exit 1; }
+ echo '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"
+ 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
+ grep -v "^[^$T]*@razorback16$T" "$P" > "$P.new"
+ mv "$P.new" "$P"
+ echo 'Also uninstalled 1 plugin from this marketplace:'
+ fi ;;
'plugin list --json')
- if [ -f "$st/plugin" ]; then printf '[{"id":"cc-intelligent-ui@razorback16","version":"%s","scope":"user","enabled":%s}]\n' "$(cat "$st/plugin")" "${FAKE_ENABLED:-true}"
- else echo '[{"id":"cc-intelligent-ui@razorback16","version":"0.1.0","scope":"project","enabled":true}]'; fi ;;
- 'plugin install cc-intelligent-ui@razorback16 --scope user') echo 0.3.3 > "$st/plugin"; echo 'Installed cc-intelligent-ui' ;;
- 'plugin update cc-intelligent-ui@razorback16 --scope user') echo 0.3.3 > "$st/plugin"; echo 'Updated cc-intelligent-ui' ;;
+ awk -F"$T" 'BEGIN { printf "[" }
+ { printf "%s\n {\"id\": \"%s\", \"version\": \"%s\", \"scope\": \"%s\", \"enabled\": %s, \"installPath\": \"/fake/cache/%s\"%s%s, \"projectEnabled\": false}",
+ (NR > 1 ? "," : ""), $1, $3, $2, $4, $1, ($5 != "" ? ", \"projectPath\": \"" $5 "\"" : ""), ($6 != "" ? ", " $6 : "") }
+ END { print "\n]" }' "$P" ;;
+ "plugin install $ours --scope user")
+ [ -z "${FAKE_INSTALL_FAIL:-}" ] || exit 1
+ [ -f "$st/mkt" ] || { echo 'Plugin not found' >&2; exit 1; }
+ setp "$ours" user "${FAKE_LATEST:-0.3.3}" "${FAKE_ENABLED:-true}"
+ echo 'Installed cc-intelligent-ui' ;;
+ "plugin update $ours --scope user")
+ [ -z "${FAKE_UPDATE_FAIL:-}" ] || { echo 'Failed to update' >&2; exit 1; }
+ en=$(getp "$ours" user 4)
+ [ -n "$en" ] || { echo 'not installed' >&2; exit 1; }
+ # Only the official marketplace has the newest version.
+ if [ "$(cat "$st/mkt" 2> /dev/null)" = "$official" ]; then
+ setp "$ours" user "${FAKE_LATEST:-0.3.3}" "$en"
+ echo 'Updated cc-intelligent-ui'
+ else
+ echo "cc-intelligent-ui is already at the latest version ($(getp "$ours" user 3))"
+ fi ;;
+ "plugin disable $ours --scope user")
+ setp "$ours" user "$(getp "$ours" user 3)" false ;;
+ 'plugin uninstall '*' --scope user')
+ grep -v "^$3${T}user$T" "$P" > "$P.new"
+ mv "$P.new" "$P" ;;
*) echo "fake claude: unknown command: $*" >&2; exit 1 ;;
esac
EOF
@@ -69,8 +130,10 @@ case ${1:-} in
*) echo "${FAKE_OS:-Darwin}" ;;
esac
EOF
-chmod 755 "$fake/claude" "$fake/curl" "$fake/uname"
-cp "$fake/curl" "$fake/uname" "$nocl/"
+# mdfind (Spotlight) finds iTerm2 only when FAKE_MDFIND is set.
+printf '#!/bin/sh\n[ -n "${FAKE_MDFIND:-}" ] && echo "$FAKE_MDFIND"\nexit 0\n' > "$fake/mdfind"
+chmod 755 "$fake/claude" "$fake/curl" "$fake/uname" "$fake/mdfind"
+cp "$fake/curl" "$fake/uname" "$fake/mdfind" "$nocl/"
# A fake typst of a version: mktypst DIR VERSION
mktypst() {
@@ -107,7 +170,7 @@ run() {
shift
d=$tmp/$name
mkdir -p "$d/home" "$d/state"
- env -i HOME="$d/home" PATH="${BIN:-$fake}${XPATH:+:$XPATH}:$sys" TMPDIR="$d" FAKE_STATE="$d/state" FAKE_ASSETS="$tmp/assets" \
+ env -i HOME="$d/home" PATH="${BIN:-$fake}${XPATH:+:$XPATH}:$sys" TMPDIR="$d" FAKE_STATE="$d/state" FAKE_ASSETS="$tmp/assets" IUI_TEST_ROOT="$d/root" \
"$@" bash "${SCRIPT:-$tmp/install.sh}" < /dev/null > "$d/out" 2>&1
rc=$?
# sh keeps an assignment before a function call: clear them.
@@ -186,7 +249,7 @@ else
# The second run: Typst is found in ~/.local/bin; the mod and the marketplace are updated.
cp "$d/home/.claude/settings.json" "$tmp/settings-1"
- env -i HOME="$d/home" PATH="$fake:$sys" TMPDIR="$d" FAKE_STATE="$d/state" FAKE_ASSETS="$tmp/assets" bash "$tmp/install.sh" < /dev/null > "$d/out2" 2>&1
+ env -i HOME="$d/home" PATH="$fake:$sys" TMPDIR="$d" FAKE_STATE="$d/state" FAKE_ASSETS="$tmp/assets" IUI_TEST_ROOT="$d/root" bash "$tmp/install.sh" < /dev/null > "$d/out2" 2>&1
rc=$?
[ "$rc" = 0 ] && ok || bad "the second run: exit $rc"
[ "$(wc -l < "$d/state/curl.log" | tr -d ' ')" = 1 ] && ok || bad "the second run downloaded again"
@@ -226,10 +289,11 @@ else
# A piped run (curl ... | bash) works.
d=$tmp/piped
mkdir -p "$d/home" "$d/state"
- env -i HOME="$d/home" PATH="$fake:$sys" TMPDIR="$d" FAKE_STATE="$d/state" FAKE_ASSETS="$tmp/assets" bash < "$tmp/install.sh" > "$d/out" 2>&1
+ env -i HOME="$d/home" PATH="$fake:$sys" TMPDIR="$d" FAKE_STATE="$d/state" FAKE_ASSETS="$tmp/assets" IUI_TEST_ROOT="$d/root" bash < "$tmp/install.sh" > "$d/out" 2>&1
rc=$?
[ "$rc" = 0 ] && [ -x "$d/home/.local/bin/typst" ] && [ -f "$d/home/.claude/settings.json" ] && ok || { bad "a piped run: exit $rc"; show; }
[ ! -e "$d/state/stdin.log" ] && ok || bad "a piped run: claude read the script"
+
fi
run no-typst IUI_NO_TYPST=1
@@ -237,10 +301,143 @@ run no-typst IUI_NO_TYPST=1
# --- 3. The mod ---------------------------------------------------------------
+# seed NAME MKT [PLUGIN LINE ...]: the fake claude's state before a run. MKT
+# is the razorback16 entry of the marketplace list (empty: not known); each
+# plugin line is "id scope version enabled [projectPath [extra JSON]]" with tabs.
+seed() {
+ sd=$tmp/$1/state
+ mkdir -p "$sd"
+ if [ -n "$2" ]; then printf '%s\n' "$2" > "$sd/mkt"; fi
+ : > "$sd/plugins"
+ shift 2
+ for l in "$@"; do printf '%s\n' "$l" >> "$sd/plugins"; done
+}
+T=$(printf '\t')
+ours=cc-intelligent-ui@razorback16
+mkt_official='{"name": "razorback16", "source": "github", "repo": "razorback16/cc-intelligent-ui", "installLocation": "/fake/marketplaces/razorback16"}'
+# The version and enabled of a copy after the run: plugin ID SCOPE
+plugin() { 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; }
+
+seed disabled '' "$ours${T}project${T}0.1.0${T}true${T}/work/p"
run disabled IUI_NO_TYPST=1 FAKE_ENABLED=false
[ "$rc" = 0 ] && out 'claude plugin enable cc-intelligent-ui@razorback16' && ok || bad "a disabled mod: no words"
log 'plugin install cc-intelligent-ui@razorback16 --scope user' && ok || bad "a project install is not a user install"
+# The official source: updated, not removed.
+seed official "$mkt_official" "$ours${T}user${T}0.3.2${T}true"
+run official IUI_NO_TYPST=1
+[ "$rc" = 0 ] && log 'plugin marketplace update razorback16' && log "plugin update $ours --scope user" && ok || { bad "official: exit $rc, or no update"; show; }
+grep -q 'marketplace remove' "$d/state/claude.log" && bad "official: the marketplace was removed" || ok
+[ "$(plugin "$ours" user)" = '0.3.3 true' ] && out 'updated from 0.3.2' && ok || bad "official: not updated: $(plugin "$ours" user)"
+out 'Disable auto-update' && ok || bad "official: no undo line for auto-update"
+
+# Git URLs of the official repository with no ref: not removed.
+n=0
+for u in 'https://github.com/razorback16/cc-intelligent-ui.git' 'https://GitHub.com/Razorback16/CC-Intelligent-UI' 'https://github.com/razorback16/cc-intelligent-ui'; do
+ n=$((n + 1))
+ seed "git-official-$n" '{"name": "razorback16", "source": "git", "url": "'"$u"'", "installLocation": "/fake/m"}' "$ours${T}user${T}0.3.2${T}true"
+ run "git-official-$n" IUI_NO_TYPST=1
+ [ "$rc" = 0 ] && log 'plugin marketplace update razorback16' && ok || bad "git URL $u: exit $rc, or no marketplace update"
+ grep -q 'marketplace remove' "$d/state/claude.log" && bad "git URL $u: the marketplace was removed" || ok
+done
+
+# Another source: removed, added from GitHub, the mod installed again.
+# repointed NAME MKT UNDO-SOURCE DESCRIPTION
+repointed() {
+ seed "$1" "$2" "$ours${T}user${T}0.3.0${T}true"
+ 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")"
+ [ "$(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"
+ out "comes from $4, not from the GitHub repository" && ok || { bad "$1: no words on the old source"; show; }
+ out "claude plugin marketplace add $3" && ok || { bad "$1: no undo line: $3"; show; }
+ 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" || ok
+ out 'Kept: your /iui settings' && ok || bad "$1: no words on the settings kept"
+}
+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'
+repointed pinned '{"name": "razorback16", "source": "github", "repo": "razorback16/cc-intelligent-ui", "ref": "v0.3.0", "installLocation": "/fake/m"}' \
+ 'razorback16/cc-intelligent-ui#v0.3.0' 'the GitHub repository razorback16/cc-intelligent-ui (ref v0.3.0)'
+repointed git-ref '{"name": "razorback16", "source": "git", "url": "https://github.com/razorback16/cc-intelligent-ui.git", "ref": "releases", "installLocation": "/fake/m"}' \
+ 'https://github.com/razorback16/cc-intelligent-ui.git#releases' 'the git URL https://github.com/razorback16/cc-intelligent-ui.git (ref releases)'
+# A local folder (as Claude Code 2.1.307 lists it).
+repointed folder '{"name": "razorback16", "source": "directory", "path": "/Users/claude/iui/7e5933a06955", "installLocation": "/Users/claude/iui/7e5933a06955"}' \
+ '/Users/claude/iui/7e5933a06955' 'the local folder /Users/claude/iui/7e5933a06955'
+repointed folder-space '{"name": "razorback16", "source": "directory", "path": "/Users/me/my iui", "installLocation": "/Users/me/my iui"}' \
+ "'/Users/me/my iui'" 'the local folder /Users/me/my iui'
+
+# The old source had a newer version (a work folder): a warning.
+seed folder-newer '{"name": "razorback16", "source": "directory", "path": "/work/iui"}' "$ours${T}user${T}0.4.0${T}true"
+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.
+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
+[ "$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
+# 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
+[ "$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" || ok
+out "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
+[ "$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"
+run 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"
+run 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; }
+
+# A user copy from another marketplace: uninstalled after ours is there.
+seed other-copy "$mkt_official" "$ours${T}user${T}0.3.2${T}true" "cc-intelligent-ui@other-mkt${T}user${T}0.2.0${T}true"
+run other-copy IUI_NO_TYPST=1
+[ "$rc" = 0 ] && log 'plugin uninstall cc-intelligent-ui@other-mkt --scope user' && [ -z "$(plugin cc-intelligent-ui@other-mkt user)" ] && ok || { bad "another copy: exit $rc, not uninstalled"; show; }
+[ "$(at "plugin update $ours --scope user")" -lt "$(at 'plugin uninstall cc-intelligent-ui@other-mkt --scope user')" ] && ok || bad "another copy: uninstalled before ours was updated"
+out 'claude plugin install cc-intelligent-ui@other-mkt --scope user' && ok || bad "another copy: no undo line"
+[ "$(plugin "$ours" user)" = '0.3.3 true' ] && ok || bad "another copy: ours is $(plugin "$ours" user)"
+# Only another copy (ours not installed): ours installed first.
+seed other-only '' "cc-intelligent-ui@other-mkt${T}user${T}0.2.0${T}true"
+run other-only IUI_NO_TYPST=1
+[ "$rc" = 0 ] && [ "$(at "plugin install $ours --scope user")" -lt "$(at 'plugin uninstall cc-intelligent-ui@other-mkt --scope user')" ] && ok || { bad "only another copy: exit $rc"; show; }
+
+# Copies in a project or local scope: not changed, a warning.
+seed project-copies "$mkt_official" "$ours${T}user${T}0.3.2${T}true" "$ours${T}project${T}0.1.0${T}true${T}/work/proj" "cc-intelligent-ui@other-mkt${T}local${T}0.2.0${T}true${T}/work/my b"
+run project-copies IUI_NO_TYPST=1
+[ "$rc" = 0 ] && ok || bad "project copies: exit $rc"
+grep -q 'uninstall' "$d/state/claude.log" && bad "project copies: a copy was uninstalled" || ok
+[ "$(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 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
+[ "$rc" = 1 ] && out 'NOT updated: the update failed' && ok || { bad "update fails: exit $rc"; show; }
+out 'the newest version was installed already' && bad "update fails: the summary says newest" || ok
+# A failed marketplace update and no new version: not "the newest".
+seed mkt-update-fails "$mkt_official" "$ours${T}user${T}0.3.2${T}true"
+run mkt-update-fails IUI_NO_TYPST=1 FAKE_MKT_UPDATE_FAIL=1 FAKE_LATEST=0.3.2
+[ "$rc" = 1 ] && out 'NOT checked for a newer version' && ok || { bad "marketplace update fails: exit $rc"; show; }
+out 'the newest version was installed already' && bad "marketplace update fails: the summary says newest" || ok
+
# --- 4. Auto-update: settings.json --------------------------------------------
# setting NAME INPUT EXPECTED: settings.json is INPUT (printf format) before the
@@ -271,7 +468,7 @@ out 'new file' && ok || bad "a missing settings.json: summary"
setting other-keys \
'{\n "model": "opus",\n "permissions": {\n "allow": [\n "Bash(ls)"\n ]\n },\n "note": "caf\303\251 \\u00e9 \\"x\\"",\n "n": -1.5e3,\n "enabledPlugins": {\n "x@y": true\n }\n}\n' \
'{\n "model": "opus",\n "permissions": {\n "allow": [\n "Bash(ls)"\n ]\n },\n "note": "caf\303\251 \\u00e9 \\"x\\"",\n "n": -1.5e3,\n "enabledPlugins": {\n "x@y": true\n },\n "extraKnownMarketplaces": '"$entry2"'\n}\n'
-grep -q 'All other settings are kept' "$d/out" && ok || bad "other keys: no words on the backup"
+grep -q 'All other settings are kept' "$d/out" && out 'before this auto-update change' && out 'undoes only the auto-update change' && ok || bad "other keys: no words on the backup"
# As `claude plugin marketplace add` declares it: source only.
setting declared \
@@ -290,6 +487,7 @@ setting already-set \
'{\n "a": 1,\n "extraKnownMarketplaces": {\n "razorback16": {\n "source": {"source": "github", "repo": "razorback16/cc-intelligent-ui"},\n "autoUpdate": true\n }\n }\n}\n' \
'{\n "a": 1,\n "extraKnownMarketplaces": {\n "razorback16": {\n "source": {"source": "github", "repo": "razorback16/cc-intelligent-ui"},\n "autoUpdate": true\n }\n }\n}\n'
grep -q 'Auto-update is on already' "$d/out" && ok || bad "already set: no words"
+out 'Disable auto-update' && ok || bad "already set: no undo line for auto-update"
setting tabs \
'{\n\t"a": [1, 2],\n\t"b": {}\n}\n' \
@@ -340,6 +538,7 @@ refused bad-marketplaces '{"extraKnownMarketplaces": []}\n'
refused bad-entry '{"extraKnownMarketplaces": {"razorback16": "x"}}\n'
refused control-char '{"a": "x\001y"}\n'
refused two-values '{} {}\n'
+refused other-source '{"extraKnownMarketplaces": {"razorback16": {"source": {"source": "directory", "path": "/x"}}}}\n'
# The place of the settings: CLAUDE_CONFIG_DIR.
mkdir -p "$tmp/config/conf"
@@ -360,6 +559,155 @@ 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"
+# --- 5. Pictures in iTerm2 and herdr: the shell setup -------------------------
+
+# The block of install.sh is the block of the mod (hooks/lib/setup.ts, or the
+# file in IUI_SETUP_TS), so they can not drift.
+setup_ts=${IUI_SETUP_TS:-$here/hooks/lib/setup.ts}
+ts_part() { perl -ne "print \"\$1\\n\" if /$1/" "$setup_ts" | head -n 1; }
+sh_part() { sed -n "s/^$1='\(.*\)'\$/\1/p" "$script"; }
+S_START=$(sh_part SETUP_START)
+S_END=$(sh_part SETUP_END)
+S_SH=$(sh_part SETUP_SH)
+S_FISH=$(sh_part SETUP_FISH)
+[ -n "$S_START" ] && [ -n "$S_END" ] && [ -n "$S_SH" ] && [ -n "$S_FISH" ] && ok || bad "install.sh: no SETUP_ lines"
+if grep -q '"herdr"' "$setup_ts"; then
+ [ "$S_START" = "$(ts_part "SETUP_START = '(.*)'")" ] && [ "$S_END" = "$(ts_part "SETUP_END = '(.*)'")" ] && ok || bad "the setup markers are not the ones of $setup_ts"
+ [ "$S_FISH" = "$(ts_part "^ *\\? '(if test .*)'\$")" ] && [ "$S_SH" = "$(ts_part "^ *: '(if .*)'\$")" ] && ok || bad "the setup lines are not the ones of $setup_ts"
+else
+ echo "install-sh-test: the block check with setup.ts skipped ($setup_ts is the older iTerm2-only version; set IUI_SETUP_TS)"
+fi
+block_sh=$(printf '%s\n%s\n%s\n_' "$S_START" "$S_SH" "$S_END")
+block_sh=${block_sh%_}
+block_fish=$(printf '%s\n%s\n%s\n_' "$S_START" "$S_FISH" "$S_END")
+block_fish=${block_fish%_}
+# The old block of the mod (iTerm2 only).
+old_block='# >>> cc-intelligent-ui: Claude Code pictures in iTerm2 >>>
+if [ "$TERM_PROGRAM" = "iTerm.app" ] && [ -z "$TMUX" ] && [ -z "$STY" ]; then export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1; fi
+# <<< cc-intelligent-ui <<<
+'
+# iterm NAME: iTerm2 in /Applications for the run NAME.
+iterm() { mkdir -p "$tmp/$1/root/Applications/iTerm.app"; }
+# is FILE TEXT: FILE has exactly TEXT.
+is() { printf '%s' "$2" > "$d/want-rc" && cmp -s "$d/want-rc" "$1"; }
+
+run no-iterm IUI_NO_TYPST=1 SHELL=/bin/zsh
+[ "$rc" = 0 ] && out 'not needed (no iTerm2 or herdr)' && [ ! -e "$d/home/.zshrc" ] && ok || bad "no iTerm2 or herdr: exit $rc, or a change"
+
+iterm iterm-zsh
+run iterm-zsh IUI_NO_TYPST=1 SHELL=/bin/zsh
+[ "$rc" = 0 ] && is "$d/home/.zshrc" "$block_sh" && ok || { bad "iTerm2, zsh: ~/.zshrc is not the block"; show; }
+out 'added to ~/.zshrc (open a new tab or pane)' && out '/iui setup remove' && [ ! -e "$d/home/.zshrc.bak-iui" ] && ok || bad "iTerm2, zsh: summary, undo or a backup"
+run iterm-zsh IUI_NO_TYPST=1 SHELL=/bin/zsh
+[ "$rc" = 0 ] && is "$d/home/.zshrc" "$block_sh" && [ ! -e "$d/home/.zshrc.bak-iui" ] && out 'set already in ~/.zshrc' && ok || bad "iTerm2, zsh, the second run: changed"
+
+iterm zsh-lines
+mkdir -p "$tmp/zsh-lines/home"
+printf 'export A=1\n\n\n' > "$tmp/zsh-lines/home/.zshrc"
+chmod 640 "$tmp/zsh-lines/home/.zshrc"
+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; }
+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")" ;; esac
+no_work_left && ok || bad "zsh with lines: a temp file left"
+
+# An old block of the mod (iTerm2 only) is replaced: one block.
+iterm old-block
+mkdir -p "$tmp/old-block/home"
+printf 'a\n\n%sb\n' "$old_block" > "$tmp/old-block/home/.zshrc"
+run old-block IUI_NO_TYPST=1 SHELL=/bin/zsh
+[ "$rc" = 0 ] && is "$d/home/.zshrc" "a
+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"
+
+iterm zdotdir
+mkdir -p "$tmp/zdotdir/zdot"
+run zdotdir IUI_NO_TYPST=1 SHELL=/bin/zsh ZDOTDIR="$tmp/zdotdir/zdot"
+[ "$rc" = 0 ] && is "$d/zdot/.zshrc" "$block_sh" && [ ! -e "$d/home/.zshrc" ] && ok || bad "ZDOTDIR: not used"
+
+iterm bash-mac
+run 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"
+
+# herdr on Linux (in ~/.local/bin, as the script looks for Typst).
+mkdir -p "$tmp/bash-linux/home/.local/bin"
+printf '#!/bin/sh\n' > "$tmp/bash-linux/home/.local/bin/herdr"
+chmod 755 "$tmp/bash-linux/home/.local/bin/herdr"
+run bash-linux IUI_NO_TYPST=1 FAKE_OS=Linux FAKE_ARCH=x86_64 SHELL=/bin/bash
+[ "$rc" = 0 ] && is "$d/home/.bashrc" "$block_sh" && [ ! -e "$d/home/.bash_profile" ] && out 'herdr found' && ok || { bad "herdr, bash on Linux: not ~/.bashrc"; show; }
+# iTerm2 is for macOS only.
+iterm linux-iterm
+run linux-iterm IUI_NO_TYPST=1 FAKE_OS=Linux FAKE_ARCH=x86_64 SHELL=/bin/bash
+[ "$rc" = 0 ] && out 'not needed' && [ ! -e "$d/home/.bashrc" ] && ok || bad "Linux with an iTerm.app folder: a change"
+
+iterm fish
+run fish IUI_NO_TYPST=1 SHELL=/opt/homebrew/bin/fish
+[ "$rc" = 0 ] && is "$d/home/.config/fish/conf.d/cc-intelligent-ui.fish" "$block_fish" && ok || { bad "fish: no conf.d file"; show; }
+iterm fish-xdg
+mkdir -p "$tmp/fish-xdg/xdg"
+run fish-xdg IUI_NO_TYPST=1 SHELL=/usr/bin/fish XDG_CONFIG_HOME="$tmp/fish-xdg/xdg"
+[ "$rc" = 0 ] && is "$d/xdg/fish/conf.d/cc-intelligent-ui.fish" "$block_fish" && ok || bad "fish: XDG_CONFIG_HOME not used"
+
+# Found by Spotlight, or herdr on the PATH.
+run mdfind IUI_NO_TYPST=1 SHELL=/bin/zsh FAKE_MDFIND=/Applications/iTerm.app
+[ "$rc" = 0 ] && is "$d/home/.zshrc" "$block_sh" && out 'iTerm2 found' && ok || bad "iTerm2 found by mdfind: no block"
+mkdir -p "$tmp/herdr-bin"
+printf '#!/bin/sh\n' > "$tmp/herdr-bin/herdr"
+chmod 755 "$tmp/herdr-bin/herdr"
+XPATH=$tmp/herdr-bin run herdr-path IUI_NO_TYPST=1 SHELL=/bin/zsh
+[ "$rc" = 0 ] && is "$d/home/.zshrc" "$block_sh" && out 'herdr found' && ok || bad "herdr on the PATH: no block"
+
+# A link (dotfiles): the file it points to changes, the link stays.
+iterm rc-link
+mkdir -p "$tmp/rc-link/home" "$tmp/rc-link/dotfiles"
+printf 'x=1\n' > "$tmp/rc-link/dotfiles/zshrc"
+ln -s "$tmp/rc-link/dotfiles/zshrc" "$tmp/rc-link/home/.zshrc"
+run rc-link IUI_NO_TYPST=1 SHELL=/bin/zsh
+[ "$rc" = 0 ] && [ -L "$d/home/.zshrc" ] && is "$d/dotfiles/zshrc" "x=1
+
+$block_sh" && ok || bad "a linked ~/.zshrc: the link was replaced, or its file not changed"
+[ "$(cat "$d/home/.zshrc.bak-iui")" = 'x=1' ] && ok || bad "a linked ~/.zshrc: no backup"
+
+# Not changed: a file that can not be read, a folder, a big file.
+# rc_refused NAME: ~/.zshrc stays as it is, exit 1, the lines to add.
+rc_refused() {
+ [ "$rc" = 1 ] && out 'was not changed' && out 'CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1; fi' && out 'NOT added' && ok || { bad "$1: exit $rc, or no words"; show; }
+ [ ! -e "$d/home/.zshrc.bak-iui" ] && no_work_left && ok || bad "$1: a backup or a temp file"
+}
+if [ "$(id -u)" != 0 ]; then
+ iterm unreadable
+ mkdir -p "$tmp/unreadable/home"
+ printf 'secret\n' > "$tmp/unreadable/home/.zshrc"
+ chmod 000 "$tmp/unreadable/home/.zshrc"
+ run unreadable IUI_NO_TYPST=1 SHELL=/bin/zsh
+ chmod 600 "$d/home/.zshrc"
+ rc_refused unreadable
+ [ "$(cat "$d/home/.zshrc")" = secret ] && ok || bad "unreadable: changed"
+fi
+iterm rc-folder
+mkdir -p "$tmp/rc-folder/home/.zshrc"
+run rc-folder IUI_NO_TYPST=1 SHELL=/bin/zsh
+rc_refused rc-folder
+iterm rc-big
+mkdir -p "$tmp/rc-big/home"
+perl -e 'print "# x\n" x (1300 * 1024)' > "$tmp/rc-big/home/.zshrc"
+cp "$tmp/rc-big/home/.zshrc" "$tmp/rc-big/big"
+run rc-big IUI_NO_TYPST=1 SHELL=/bin/zsh
+rc_refused rc-big
+cmp -s "$d/big" "$d/home/.zshrc" && ok || bad "a big ~/.zshrc: changed"
+
+iterm no-shell-setup
+run no-shell-setup IUI_NO_TYPST=1 SHELL=/bin/zsh IUI_NO_SHELL_SETUP=1
+[ "$rc" = 0 ] && out 'IUI_NO_SHELL_SETUP is set' && [ ! -e "$d/home/.zshrc" ] && ok || bad "IUI_NO_SHELL_SETUP: a change"
+iterm tcsh
+run tcsh IUI_NO_TYPST=1 SHELL=/bin/tcsh
+[ "$rc" = 0 ] && out 'Your shell (tcsh) is not one that the mod knows' && out "export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 (only in iTerm2 and herdr" && ok || { bad "an unknown shell: no manual line"; show; }
+[ -z "$(cd "$d/home" && find . -name '.*rc' -o -name '.bash_profile' -o -name '*.fish')" ] && ok || bad "an unknown shell: a file was made"
+
# The output is plain ASCII when it is not a terminal.
LC_ALL=C cat "$tmp"/*/out | LC_ALL=C grep -n '[^ -~ ]' > "$tmp/nonascii" && bad "an output that is not plain ASCII: $(head -n 2 "$tmp/nonascii")" || ok