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: one line installs Typst, the mod and auto-update

razorback162b3ebee5a3d4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 540b911..1911b65 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ All releases of Intelligent UI for Claude Code (`cc-intelligent-ui`). Claude Cod
## 0.3.3 (2026-10-22)
+### 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).
+
### 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.
diff --git a/README.md b/README.md
index 6fbb900..3610643 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,27 @@ Intelligent UI draws each answer from Claude as a typeset picture, with [Typst](
## Install
+In a shell, on macOS or Linux:
+
+```
+curl -fsSL https://intelligentui.art/install.sh | bash
+```
+
+Then restart Claude Code, or type `/reload-plugins` in a session. To update, run the command again. You can [read the script](site/install.sh) before you run it.
+
+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.
+
+`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`.
+
+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).
+
+### Install by hand
+
```
brew install typst
```
@@ -28,9 +49,11 @@ Then, in Claude Code:
It works at once, with no restart.
+### Fullscreen, updates and terminals
+
Intelligent UI works best in fullscreen mode (recommended). To use it, run `/tui fullscreen` in Claude Code.
-To get new versions, turn on auto-update for the `razorback16` marketplace in `/plugin`, or update manually. Refer to [Update](docs/install.md#update). The mod also shows a notice when a new version is available (`/iui updates off` stops it).
+To get new versions, turn on auto-update for the `razorback16` marketplace in `/plugin` (the install script does this for you), or update manually. Refer to [Update](docs/install.md#update). The mod also shows a notice when a new version is available (`/iui updates off` stops it).
You need Claude Code 2.1.298 or later, [Typst](https://typst.app) 0.15, and macOS or Linux (X11 or Wayland). The pictures show only in some terminals:
diff --git a/docs/development.md b/docs/development.md
index 904444d..284204b 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -17,6 +17,7 @@ sh tests/code-sh-test.sh # code blocks of md.typ (width, header, copy butt
sh tests/root-sh-test.sh # the Typst root of a compile (STAGE_SH): answer code reads no other file, with the real Typst (its compiles skip with no typst)
sh tests/check-sh-test.sh # the skill's check.sh: a private cache folder, and a block reads no other file (skips with no Typst 0.15)
sh tests/footprint-sh-test.sh # release gate: the validator's footprint is whole (no [+N chars] mark, calls line of 850 characters at most)
+sh tests/install-sh-test.sh # the installer site/install.sh in a sandbox HOME with a fake claude, curl and uname (shellcheck when installed)
claude plugin validate .
```
diff --git a/docs/install.md b/docs/install.md
index 02d24c9..fba2c79 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -26,6 +26,55 @@ Where pictures cannot draw, the mod shows the normal text. To see why a terminal
## Install steps
+There are two ways: the install script, or by hand.
+
+### The install script
+
+In a shell, on macOS or Linux:
+
+```
+curl -fsSL https://intelligentui.art/install.sh | bash
+```
+
+You can also download the script, read it, and run it with `bash install.sh`. Its source is [`site/install.sh`](../site/install.sh). When it is done, restart Claude Code, or type `/reload-plugins` in a session. To update, run it again: each step that is done already changes nothing.
+
+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.
+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
+ "extraKnownMarketplaces": {
+ "razorback16": {
+ "source": { "source": "github", "repo": "razorback16/cc-intelligent-ui" },
+ "autoUpdate": true
+ }
+ }
+ ```
+
+ `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.
+
+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.
+
+For example: `curl -fsSL https://intelligentui.art/install.sh | IUI_NO_TYPST=1 bash`.
+
+The script never uses `sudo` and runs no downloaded code other than the Typst program that it checked. All its work is in functions that the last line runs, so a download that stops in the middle runs nothing. Its output is plain text.
+
+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`.
+- Typst, if the script installed it: `rm ~/.local/bin/typst`
+
+### By hand
+
1. Install Typst: `brew install typst` on macOS. On Linux, refer to [Install Typst on Linux](#install-typst-on-linux). For all the ways, refer to [Typst's install page](https://github.com/typst/typst#installation).
2. At the prompt of a Claude Code session in the terminal, type:
@@ -81,6 +130,8 @@ Claude Code finds a new version of the mod from the version number in its `plugi
### Turn on auto-update
+The [install script](#the-install-script) turns it on for you. To turn it on yourself:
+
1. In Claude Code, type `/plugin`.
2. Go to **Marketplaces**, then select **razorback16**.
3. Select **Enable auto-update**.
@@ -89,7 +140,7 @@ Claude Code then updates the mod in approximately 10 minutes after the first mes
### Update manually
-From a shell:
+Run the [install script](#the-install-script) again, or, from a shell:
```
claude plugin marketplace update razorback16
diff --git a/site/index.html b/site/index.html
index 5229cf0..4d3f314 100644
--- a/site/index.html
+++ b/site/index.html
@@ -228,6 +228,7 @@
footer .big em { font-style: italic; color: var(--accent); }
.install { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; justify-items: center; margin-top: 28px; }
.install .cmd { margin: 0; }
+ .install .or { margin: 0; color: var(--muted); font-size: 13px; }
.links { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 28px; }
.fine { margin: 40px auto 0; max-width: 620px; color: var(--muted); font-size: 13px; }
@@ -264,8 +265,8 @@
<div class="dock" id="dock"><div class="tabs" role="tablist" aria-label="Example answers" id="tabs"></div></div>
</div>
<div><div class="cmd">
- <code><b>/</b>plugin install cc-intelligent-ui --marketplace razorback16/cc-intelligent-ui</code>
- <button class="copy" type="button" data-copy="/plugin install cc-intelligent-ui --marketplace razorback16/cc-intelligent-ui">Copy</button>
+ <code><b>$ </b>curl -fsSL https://intelligentui.art/install.sh | bash</code>
+ <button class="copy" type="button" data-copy="curl -fsSL https://intelligentui.art/install.sh | bash">Copy</button>
</div></div>
</div>
</section>
@@ -282,11 +283,14 @@
<div class="wrap">
<p class="big">Ask once. <em>See it.</em></p>
<div class="install">
+ <div class="cmd"><code><b>$ </b>curl -fsSL https://intelligentui.art/install.sh | bash</code><button class="copy" type="button" data-copy="curl -fsSL https://intelligentui.art/install.sh | bash">Copy</button></div>
+ <p class="or">or by hand</p>
<div class="cmd"><code><b>$ </b>brew install typst</code><button class="copy" type="button" data-copy="brew install typst">Copy</button></div>
<div class="cmd"><code><b>/</b>plugin install cc-intelligent-ui --marketplace razorback16/cc-intelligent-ui</code><button class="copy" type="button" data-copy="/plugin install cc-intelligent-ui --marketplace razorback16/cc-intelligent-ui">Copy</button></div>
</div>
<div class="links">
<a class="icon-btn" href="https://github.com/razorback16/cc-intelligent-ui">GitHub</a>
+ <a class="icon-btn" href="install.sh">install.sh</a>
<a class="icon-btn" href="https://github.com/razorback16/cc-intelligent-ui/blob/main/docs/install.md">Install guide</a>
</div>
<p class="fine">Needs Claude Code 2.1.298 or later, Typst 0.15, and macOS or Linux. An independent, community-made mod, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic, PBC. MIT licence.</p>
diff --git a/site/install.sh b/site/install.sh
new file mode 100755
index 0000000..d5a21cb
--- /dev/null
+++ b/site/install.sh
@@ -0,0 +1,656 @@
+#!/usr/bin/env bash
+# Intelligent UI for Claude Code: the one-line installer.
+#
+# curl -fsSL https://intelligentui.art/install.sh | bash
+#
+# What it does (refer to docs/install.md):
+# 1. Checks the system (macOS or Linux, arm64 or x86_64) and that Claude Code is installed.
+# 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).
+# 4. Turns on auto-update for the razorback16 marketplace in your Claude Code
+# settings.json (extraKnownMarketplaces), with a backup.
+# 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).
+# All the work is in functions, and the last line runs it: a cut download runs nothing.
+
+if [ -z "${BASH_VERSION:-}" ]; then
+ echo "Run this script with bash: curl -fsSL https://intelligentui.art/install.sh | bash" >&2
+ exit 1
+fi
+set -euo pipefail
+
+MARKETPLACE=razorback16
+MARKETPLACE_REPO=razorback16/cc-intelligent-ui
+PLUGIN_NAME=cc-intelligent-ui
+PLUGIN=cc-intelligent-ui@razorback16
+# The oldest Claude Code that the mod works with (docs/install.md).
+MIN_CLAUDE=2.1.298
+CLAUDE_SETUP_URL=https://code.claude.com/docs/en/setup
+TYPST_VERSION=0.15.1
+TYPST_MIN=0.15
+TYPST_URL=https://github.com/typst/typst/releases/download/v$TYPST_VERSION
+# Where the mod looks for Typst when it is not on the PATH, in its order
+# (TYPST_FALLBACKS in hooks/lib/settings.ts). `~` is $HOME.
+TYPST_DIRS='/opt/homebrew/bin /usr/local/bin /usr/bin /snap/bin ~/.cargo/bin ~/.local/bin /home/linuxbrew/.linuxbrew/bin ~/.linuxbrew/bin'
+
+# SHA-256 of the official Typst 0.15.1 release files. Computed from the files
+# downloaded from github.com/typst/typst/releases/tag/v0.15.1, and the same as
+# the `digest` of each file in the GitHub release API.
+typst_sha256() {
+ case $1 in
+ typst-aarch64-apple-darwin.tar.xz) echo 48f62ed034aa3a7978309579ac6ca00045e2ef0da73114e8af27cfd8e74dc05a ;;
+ typst-x86_64-apple-darwin.tar.xz) echo 7f9fdd9584866245de9a79e0add8f9236fae6f40a8a45e2c4771ccc14db4e0fa ;;
+ typst-aarch64-unknown-linux-musl.tar.xz) echo 5aa8d74a3d906e60ea12a66ac2f37f8eef1b14cbad7182a745e393a10c23dcee ;;
+ typst-x86_64-unknown-linux-musl.tar.xz) echo a6d077d0a95eed5a2eba715b2dae06be954f624ccbf85758a03f389ded33118c ;;
+ *) return 1 ;;
+ esac
+}
+
+# Output: plain ASCII; bold headings only on a terminal.
+BOLD=
+PLAIN=
+init_output() {
+ if [ -t 1 ] && [ "${TERM:-dumb}" != dumb ] && [ -z "${NO_COLOR:-}" ]; then
+ BOLD=$(printf '\033[1m')
+ PLAIN=$(printf '\033[0m')
+ fi
+}
+say() { printf '%s\n' "$*"; }
+step() { printf '\n%s%s%s\n' "$BOLD" "$*" "$PLAIN"; }
+note() { printf ' %s\n' "$*"; }
+warn() { printf ' Warning: %s\n' "$*" >&2; }
+die() {
+ printf '\nError: %s\n' "$*" >&2
+ exit 1
+}
+# Shows a claude command, then runs it (stdin closed: it can not read this script).
+claude_run() {
+ printf ' $ claude %s\n' "$*"
+ "$CLAUDE" "$@" < /dev/null
+}
+
+on() { [ -n "${1:-}" ] && [ "$1" != 0 ]; }
+
+# The work folder, removed at the end.
+WORK=
+cleanup() { if [ -n "$WORK" ]; then rm -rf "$WORK"; fi; }
+
+# 0 when version $1 >= $2 (dotted numbers).
+version_ge() {
+ awk -v a="$1" -v b="$2" 'BEGIN {
+ n = split(a, x, "."); m = split(b, y, "."); if (m > n) n = m
+ for (i = 1; i <= n; i++) { if (x[i] + 0 > y[i] + 0) exit 0; if (x[i] + 0 < y[i] + 0) exit 1 }
+ exit 0 }'
+}
+
+# "~/..." with $HOME, for messages and paths.
+tilde() {
+ case $1 in
+ "$HOME"/*) printf '~%s' "${1#"$HOME"}" ;;
+ *) printf '%s' "$1" ;;
+ esac
+}
+
+# --- 1. Checks -------------------------------------------------------------
+
+OS=
+ARCH=
+TARGET=
+check_platform() {
+ local s m
+ s=$(uname -s)
+ m=$(uname -m)
+ case $s in
+ Darwin) OS=macos TARGET=apple-darwin ;;
+ Linux) OS=linux TARGET=unknown-linux-musl ;;
+ *) die "this system ($s) is not supported. Intelligent UI works on macOS and Linux." ;;
+ esac
+ case $m in
+ arm64 | aarch64) ARCH=aarch64 ;;
+ x86_64 | amd64) ARCH=x86_64 ;;
+ *) die "this processor ($m) is not supported. Intelligent UI works on arm64 and x86_64." ;;
+ esac
+ # A shell under Rosetta says x86_64 on an Apple silicon Mac.
+ if [ "$OS" = macos ] && [ "$ARCH" = x86_64 ] && [ "$(sysctl -n sysctl.proc_translated 2> /dev/null || true)" = 1 ]; then
+ ARCH=aarch64
+ fi
+ note "System: $OS, $ARCH"
+}
+
+CLAUDE=
+check_claude() {
+ local v
+ CLAUDE=$(command -v claude 2> /dev/null || true)
+ if [ -z "$CLAUDE" ]; then
+ # The native installer's place, when the shell has not put it on the PATH yet.
+ for v in "$HOME/.local/bin/claude" "$HOME/.claude/local/claude"; do
+ if [ -x "$v" ]; then
+ CLAUDE=$v
+ break
+ fi
+ done
+ fi
+ if [ -z "$CLAUDE" ]; then
+ printf '\nError: Claude Code is not installed (no claude command on your PATH).\n' >&2
+ printf 'Install Claude Code first: %s\nThen run this installer again. Nothing was changed.\n' "$CLAUDE_SETUP_URL" >&2
+ exit 1
+ fi
+ v=$("$CLAUDE" --version < /dev/null 2> /dev/null | awk 'NR == 1 { print $1 }' || true)
+ case $v in
+ [0-9]*.[0-9]*.[0-9]*)
+ note "Claude Code: $v ($(tilde "$CLAUDE"))"
+ if ! version_ge "$v" "$MIN_CLAUDE"; then
+ warn "Intelligent UI needs Claude Code $MIN_CLAUDE or later. Update Claude Code: claude update"
+ fi
+ ;;
+ *) warn "could not read the version of Claude Code ($(tilde "$CLAUDE")). Intelligent UI needs $MIN_CLAUDE or later." ;;
+ esac
+}
+
+# --- 2. Typst --------------------------------------------------------------
+
+# The version of the typst at $1 (for example 0.15.1), or nothing.
+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() {
+ local p d
+ p=$(command -v typst 2> /dev/null || true)
+ case $p in /*)
+ printf '%s' "$p"
+ return 0
+ ;;
+ esac
+ for d in $TYPST_DIRS; do
+ case $d in \~/*) d=$HOME/${d#\~/} ;; esac
+ if [ -e "$d/typst" ]; then
+ printf '%s' "$d/typst"
+ return 0
+ fi
+ done
+ return 0
+}
+
+sha256_of() {
+ if command -v sha256sum > /dev/null 2>&1; then
+ sha256sum "$1" | awk '{ print $1 }'
+ elif command -v shasum > /dev/null 2>&1; then
+ shasum -a 256 "$1" | awk '{ print $1 }'
+ else
+ perl -MDigest::SHA -e 'print Digest::SHA->new(256)->addfile($ARGV[0], "b")->hexdigest' "$1"
+ fi
+}
+
+# tar extracts .tar.xz with the xz command, or by itself (bsdtar, as on macOS).
+tar_reads_xz() {
+ command -v xz > /dev/null 2>&1 && return 0
+ tar --version 2> /dev/null | grep -qi bsdtar
+}
+
+SUM_TYPST=
+UNDO_TYPST=
+install_typst() {
+ local pick v dest asset want got bin
+ step "2. Typst"
+ if on "${IUI_NO_TYPST:-}"; then
+ note "Skipped (IUI_NO_TYPST is set)."
+ SUM_TYPST="not checked (IUI_NO_TYPST is set)"
+ return 0
+ fi
+ dest=$HOME/.local/bin/typst
+ pick=$(mod_typst)
+ if [ -n "$pick" ]; then
+ v=$(typst_version "$pick")
+ if [ -n "$v" ] && version_ge "$v" "$TYPST_MIN"; then
+ note "Typst $v is installed: $(tilde "$pick"). Not changed."
+ SUM_TYPST="Typst $v, $(tilde "$pick") (already installed)"
+ return 0
+ fi
+ note "Typst ${v:-of an unknown version} is at $(tilde "$pick"). Intelligent UI needs $TYPST_MIN or later."
+ fi
+ v=
+ if [ -x "$dest" ]; then v=$(typst_version "$dest"); fi
+ if [ -n "$v" ] && version_ge "$v" "$TYPST_MIN"; then
+ note "Typst $v is in $(tilde "$dest") already. Not changed."
+ SUM_TYPST="Typst $v, $(tilde "$dest") (already installed)"
+ else
+ command -v curl > /dev/null 2>&1 || die "curl is not installed. Install curl, or install Typst $TYPST_MIN yourself (refer to https://github.com/typst/typst#installation)."
+ tar_reads_xz || die "tar can not extract .tar.xz files here. Install xz (xz-utils on Debian and Ubuntu), then run this installer again."
+ if [ -d "$dest" ] && [ ! -L "$dest" ]; then die "$(tilde "$dest") is a folder. Typst was not installed."; fi
+ asset=typst-$ARCH-$TARGET.tar.xz
+ want=$(typst_sha256 "$asset") || die "no Typst release file for $ARCH-$TARGET."
+ WORK=$(mktemp -d "${TMPDIR:-/tmp}/iui-install.XXXXXX")
+ note "Downloading the official Typst $TYPST_VERSION release: $TYPST_URL/$asset"
+ curl -fsSL --proto '=https' --proto-redir '=https' --tlsv1.2 --retry 2 -o "$WORK/$asset" "$TYPST_URL/$asset" < /dev/null \
+ || die "the download of Typst failed. Nothing was installed."
+ got=$(sha256_of "$WORK/$asset")
+ if [ "$got" != "$want" ]; then
+ die "the SHA-256 of the downloaded Typst file is not correct (expected $want, got $got). The file was deleted, and nothing was installed."
+ fi
+ note "SHA-256 is correct: $got"
+ mkdir "$WORK/x"
+ tar -xJf "$WORK/$asset" -C "$WORK/x" < /dev/null || die "tar could not extract $asset. Nothing was installed."
+ bin=$WORK/x/typst-$ARCH-$TARGET/typst
+ if [ ! -f "$bin" ] || [ -L "$bin" ]; then die "no typst program in $asset. Nothing was installed."; fi
+ chmod 755 "$bin"
+ v=$(typst_version "$bin")
+ [ "$v" = "$TYPST_VERSION" ] || die "the downloaded typst does not run here (it gave '${v}'). Nothing was installed."
+ mkdir -p "$HOME/.local/bin"
+ # A copy in the same folder, then one rename: never a half-written typst.
+ cp "$bin" "$HOME/.local/bin/.typst.iui-$$"
+ chmod 755 "$HOME/.local/bin/.typst.iui-$$"
+ mv -f "$HOME/.local/bin/.typst.iui-$$" "$dest"
+ note "Installed Typst $TYPST_VERSION: $(tilde "$dest")"
+ SUM_TYPST="Typst $TYPST_VERSION, $(tilde "$dest") (downloaded and installed)"
+ UNDO_TYPST="rm ~/.local/bin/typst"
+ fi
+ case ":$PATH:" in
+ *":$HOME/.local/bin:"*) ;;
+ *) note "Your PATH does not have ~/.local/bin. Intelligent UI finds Typst there. To run typst in a shell, add ~/.local/bin to your PATH." ;;
+ esac
+ pick=$(mod_typst)
+ if [ -n "$pick" ] && [ "$pick" != "$dest" ]; then
+ warn "Intelligent UI uses the first Typst it finds: $(tilde "$pick") (Typst $(typst_version "$pick")). Remove or update that one, or put ~/.local/bin before it in your PATH."
+ fi
+}
+
+# --- JSON (perl) -------------------------------------------------------------
+
+# 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"
+# 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).
+json_pl() {
+ cat << 'PERL'
+use strict; use warnings;
+use Fcntl;
+my ($mode, @args) = @ARGV;
+my $s;
+sub err { die "not valid JSON (byte " . (pos($s) // 0) . ": expected $_[0])\n" }
+sub ws { $s =~ /\G[ \t\n\r]*/gc }
+# The next byte (no zero-length match: perl allows no two at one place).
+sub peek { substr($s, pos($s), 1) eq $_[0] }
+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;
+ return $r;
+}
+sub val {
+ ws();
+ my $b = pos($s);
+ if ($s =~ /\G\{/gc) {
+ my @m;
+ ws();
+ unless ($s =~ /\G\}/gc) {
+ while (1) {
+ ws();
+ my $ks = pos($s);
+ peek('"') or err('a key');
+ my $k = str();
+ my $ke = pos($s);
+ ws();
+ $s =~ /\G:/gc or err("':'");
+ my $v = val();
+ push @m, { k => $k, ks => $ks, ke => $ke, v => $v };
+ ws();
+ next if $s =~ /\G,/gc;
+ last if $s =~ /\G\}/gc;
+ err("',' or '}'");
+ }
+ }
+ return { t => 'o', m => \@m, b => $b, e => pos($s) };
+ }
+ if ($s =~ /\G\[/gc) {
+ my @l;
+ ws();
+ unless ($s =~ /\G\]/gc) {
+ while (1) {
+ push @l, val();
+ ws();
+ next if $s =~ /\G,/gc;
+ last if $s =~ /\G\]/gc;
+ err("',' or ']'");
+ }
+ }
+ return { t => 'a', l => \@l, b => $b, e => pos($s) };
+ }
+ if (peek('"')) { my $x = str(); return { t => 's', s => $x, b => $b, e => pos($s) } }
+ if ($s =~ /\G-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?/gc) { return { t => 'n', b => $b, e => pos($s) } }
+ if ($s =~ /\G(true|false|null)/gc) { return { t => $1, b => $b, e => pos($s) } }
+ err('a value');
+}
+sub parse {
+ $s = $_[0];
+ pos($s) = ($s =~ /^\xEF\xBB\xBF/) ? 3 : 0;
+ my $v = val();
+ ws();
+ pos($s) == length($s) or err('the end of the file');
+ return $v;
+}
+# 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') {
+ 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];
+ 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";
+ exit 0;
+ }
+ }
+ exit 1;
+}
+exit 4 unless $mode eq 'settings';
+
+my ($file, $bak) = @args;
+my $name = 'razorback16';
+my @source = ([source => '"github"'], [repo => '"razorback16/cc-intelligent-ui"']);
+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, $text);
+if (-e $real) {
+ refuse("$file is not a file") unless -f $real;
+ open(my $fh, '<:raw', $real) or refuse("can not read $file: $!");
+ local $/; $old = <$fh> // ''; close $fh;
+}
+# 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" };
+}
+# The line end of the file (CRLF kept).
+our $NL = (defined $old && $old =~ /\r\n/) ? "\r\n" : "\n";
+# JSON text for a value: [key, value] lists are objects, a string is raw JSON.
+sub render {
+ my ($v, $ind, $unit, $multi, $kv) = @_;
+ return $v unless ref $v;
+ my @p = map { '"' . $_->[0] . '"' . $kv . render($_->[1], $ind . $unit, $unit, $multi, $kv) } @$v;
+ return $multi ? "{$NL" . join(",$NL", map { "$ind$unit$_" } @p) . "$NL$ind}" : '{' . join($kv eq ':' ? ',' : ', ', @p) . '}';
+}
+my $out;
+if (!defined $old || $old =~ /\A\s*\z/) {
+ $text = render([[extraKnownMarketplaces => [[$name => [[source => \@source], [autoUpdate => 'true']]]]]], '', ' ', 1, ': ') . "\n";
+ $out = defined $old ? 'changed' : 'created';
+} else {
+ my $root = eval { parse($old) };
+ unless ($root) { chomp(my $why = $@); refuse("$file is $why") }
+ refuse("$file is not a JSON object") unless $root->{t} eq 'o';
+ my $lineind = sub { my $p = shift; my $l = rindex($old, "\n", $p - 1) + 1; substr($old, $l) =~ /^([ \t]*)/; $1 };
+ my $nl = ($old =~ /\n/);
+ my ($unit, $kv) = (' ', ': ');
+ if (@{ $root->{m} }) {
+ my $f = $root->{m}[0];
+ my $gap = substr($old, $root->{b} + 1, $f->{ks} - $root->{b} - 1);
+ $unit = $1 if $gap =~ /\n([ \t]+)\z/;
+ $kv = (substr($old, $f->{ke}, $f->{v}{b} - $f->{ke}) =~ / /) ? ': ' : ':';
+ } elsif (!$nl) {
+ $kv = ':';
+ }
+ # Each change: [begin, end, new text].
+ my @edits;
+ my $add = sub {
+ my ($o, @members) = @_;
+ my $li = $lineind->($o->{b});
+ if (@{ $o->{m} }) {
+ my $f = $o->{m}[0];
+ my $l = $o->{m}[-1];
+ my $gap = substr($old, $o->{b} + 1, $f->{ks} - $o->{b} - 1);
+ my $okv = (substr($old, $f->{ke}, $f->{v}{b} - $f->{ke}) =~ / /) ? ': ' : ':';
+ if ($gap =~ /\n([ \t]*)\z/) {
+ my $mi = $1;
+ my $u = (length($mi) > length($li) && substr($mi, 0, length $li) eq $li) ? substr($mi, length $li) : $unit;
+ push @edits, [$l->{v}{e}, $l->{v}{e}, join('', map { ",$NL$mi\"$_->[0]\"$okv" . render($_->[1], $mi, $u, 1, $okv) } @members)];
+ } else {
+ my $sep = $okv eq ':' ? ',' : ', ';
+ push @edits, [$l->{v}{e}, $l->{v}{e}, join('', map { "$sep\"$_->[0]\"$okv" . render($_->[1], '', '', 0, $okv) } @members)];
+ }
+ } else {
+ push @edits, [$o->{b}, $o->{e}, render(\@members, $li, $unit, $nl ? 1 : 0, $kv)];
+ }
+ };
+ my $ekm = member($root, 'extraKnownMarketplaces');
+ if (!$ekm) {
+ $add->($root, [extraKnownMarketplaces => [[$name => [[source => \@source], [autoUpdate => 'true']]]]]);
+ } 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']]]);
+ } elsif ($rb->{v}{t} ne 'o') {
+ refuse("extraKnownMarketplaces.$name in $file is not an object");
+ } else {
+ my $au = member($rb->{v}, 'autoUpdate');
+ if ($au && $au->{v}{t} eq 'true') { print "unchanged\n"; exit 0 }
+ if ($au) {
+ push @edits, [$au->{v}{b}, $au->{v}{e}, 'true'];
+ } else {
+ $add->($rb->{v}, (member($rb->{v}, 'source') ? () : [source => \@source]), [autoUpdate => 'true']);
+ }
+ }
+ }
+ $text = $old;
+ for my $e (sort { $b->[0] <=> $a->[0] } @edits) { substr($text, $e->[0], $e->[1] - $e->[0]) = $e->[2] }
+ $out = 'changed';
+}
+# The new text must read back with the entry set.
+my $check = eval { parse($text) };
+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');
+ $check = $m->{v} if $ok;
+}
+refuse("the change of $file did not read back (nothing was written)") unless $ok;
+my $fmode = defined $old ? (stat $real)[2] & 07777 : undef;
+eval {
+ put($bak, $old, $fmode) if defined $old;
+ put($real, $text, $fmode);
+ 1;
+} or refuse("$@");
+print "$out\n";
+PERL
+}
+
+json() { perl -e "$(json_pl)" "$@"; }
+
+# --- 3. The mod ----------------------------------------------------------------
+
+SUM_PLUGIN=
+# "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
+ 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
+ fi
+ # No JSON: the text list.
+ "$CLAUDE" plugin marketplace list < /dev/null 2> /dev/null | grep -qw "$MARKETPLACE"
+}
+
+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."
+ else
+ claude_run plugin marketplace add "$MARKETPLACE_REPO" || die "Claude Code could not add the marketplace $MARKETPLACE_REPO."
+ fi
+ 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."
+ after=$(plugin_state)
+ if [ "${after%% *}" = "${before%% *}" ]; then
+ SUM_PLUGIN="$PLUGIN_NAME ${after%% *} (the newest version was installed already)"
+ else
+ SUM_PLUGIN="$PLUGIN_NAME ${after%% *} (updated from ${before%% *})"
+ 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)"
+ fi
+ case $after in
+ *' disabled') warn "the mod is disabled in Claude Code. To turn it on: claude plugin enable $PLUGIN" ;;
+ esac
+}
+
+# --- 4. Auto-update ------------------------------------------------------------
+
+SUM_AUTO=
+UNDO_AUTO=
+PROBLEM=
+manual_auto_update() {
+ say " To turn on auto-update yourself: in Claude Code, type /plugin, go to Marketplaces," >&2
+ say " select $MARKETPLACE, then select Enable auto-update. Or add this to $1:" >&2
+ cat >&2 << EOF
+ "extraKnownMarketplaces": {
+ "$MARKETPLACE": {
+ "source": { "source": "github", "repo": "$MARKETPLACE_REPO" },
+ "autoUpdate": true
+ }
+ }
+EOF
+}
+
+auto_update() {
+ local dir file result rc t
+ step "4. Auto-update for the $MARKETPLACE marketplace"
+ if on "${IUI_NO_AUTO_UPDATE:-}"; then
+ note "Skipped (IUI_NO_AUTO_UPDATE is set)."
+ SUM_AUTO="not changed (IUI_NO_AUTO_UPDATE is set)"
+ return 0
+ fi
+ dir=${CLAUDE_CONFIG_DIR:-$HOME/.claude}
+ file=$dir/settings.json
+ case $dir in
+ /*) ;;
+ *)
+ warn "CLAUDE_CONFIG_DIR ($dir) is not an absolute path, so the settings file is not known. Nothing was changed."
+ manual_auto_update "your settings.json"
+ SUM_AUTO="NOT turned on (refer to the warning above)"
+ PROBLEM=1
+ return 0
+ ;;
+ esac
+ if ! command -v perl > /dev/null 2>&1; then
+ warn "perl is not installed, so $(tilde "$file") was not changed."
+ manual_auto_update "$(tilde "$file")"
+ SUM_AUTO="NOT turned on (refer to the warning above)"
+ PROBLEM=1
+ return 0
+ fi
+ if [ ! -e "$file" ] && [ ! -L "$file" ]; then mkdir -p "$dir"; fi
+ rc=0
+ result=$(json settings "$file" "$file.bak-iui" 2>&1) || rc=$?
+ t="~"
+ result=${result//"$HOME"/$t}
+ case $rc:$result in
+ 0:unchanged)
+ note "Auto-update is on already ($(tilde "$file")). Not changed."
+ SUM_AUTO="on (it was on already)"
+ ;;
+ 0:created)
+ note "Made $(tilde "$file") with extraKnownMarketplaces.$MARKETPLACE.autoUpdate = true."
+ SUM_AUTO="on ($(tilde "$file"), new file)"
+ UNDO_AUTO="delete $(tilde "$file")"
+ ;;
+ 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"
+ SUM_AUTO="on ($(tilde "$file"))"
+ UNDO_AUTO="copy $(tilde "$file").bak-iui back to $(tilde "$file")"
+ ;;
+ *)
+ warn "$(tilde "$file") was not changed: ${result:-an unknown error}"
+ manual_auto_update "$(tilde "$file")"
+ SUM_AUTO="NOT turned on (refer to the warning above)"
+ PROBLEM=1
+ ;;
+ esac
+}
+
+# --- 5. Summary ----------------------------------------------------------------
+
+summary() {
+ step "Done"
+ note "Typst: $SUM_TYPST"
+ note "Mod: $SUM_PLUGIN"
+ note "Auto-update: $SUM_AUTO"
+ 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."
+ say "Pictures show only in some terminals (kitty, Ghostty, iTerm2 and others). To see why"
+ say "pictures do or do not show, type /iui details. Docs: https://github.com/razorback16/cc-intelligent-ui"
+ say ""
+ say "To undo:"
+ 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"
+ fi
+}
+
+main() {
+ init_output
+ trap cleanup EXIT
+ trap 'exit 130' INT
+ 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."
+ step "1. Checks"
+ check_platform
+ check_claude
+ install_typst
+ cleanup
+ WORK=
+ install_plugin
+ auto_update
+ summary
+ if [ -n "$PROBLEM" ]; then
+ say ""
+ say "Finished with a problem: refer to the warning above."
+ exit 1
+ fi
+}
+
+main "$@"
diff --git a/tests/install-sh-test.sh b/tests/install-sh-test.sh
new file mode 100644
index 0000000..7c1daa6
--- /dev/null
+++ b/tests/install-sh-test.sh
@@ -0,0 +1,389 @@
+#!/bin/sh
+# Runs the one-line installer (site/install.sh) with bash in a sandbox: a HOME
+# of its own, a fake `claude` that logs its arguments and fakes the plugin
+# lists, a fake `curl` that serves local files and a fake `uname`. The real
+# HOME and the real Claude Code are never used. Checks: no claude, or a
+# 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;
+# 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
+# nothing; shellcheck when it is installed.
+# Usage: sh tests/install-sh-test.sh (exit 0 when all pass)
+set -u
+here=$(cd "$(dirname "$0")/.." && pwd -P)
+script=$here/site/install.sh
+tmp=$(mktemp -d "${TMPDIR:-/tmp}/iui-install-test.XXXXXX")
+tmp=$(cd "$tmp" && pwd -P)
+trap 'rm -rf "$tmp"' EXIT
+pass=0
+fail=0
+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.
+fake=$tmp/fake
+nocl=$tmp/fake-no-claude
+mkdir -p "$fake" "$nocl" "$tmp/assets" "$tmp/build"
+cat > "$fake/claude" << 'EOF'
+#!/bin/sh
+st=${FAKE_STATE:?}
+echo "$*" >> "$st/claude.log"
+if IFS= read -r line; then echo "$line" >> "$st/stdin.log"; fi
+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' ;;
+ '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' ;;
+ *) echo "fake claude: unknown command: $*" >&2; exit 1 ;;
+esac
+EOF
+cat > "$fake/curl" << 'EOF'
+#!/bin/sh
+out= url=
+while [ $# -gt 0 ]; do
+ case $1 in
+ -o | --proto | --proto-redir | --retry) [ "$1" = -o ] && out=$2; shift 2 ;;
+ -*) shift ;;
+ *) url=$1; shift ;;
+ esac
+done
+echo "$url" >> "${FAKE_STATE:?}/curl.log"
+src=${FAKE_ASSETS:?}/${url##*/}
+[ -f "$src" ] || { echo "curl: (22) The requested URL returned error: 404" >&2; exit 22; }
+cp "$src" "$out"
+EOF
+cat > "$fake/uname" << 'EOF'
+#!/bin/sh
+case ${1:-} in
+ -m) echo "${FAKE_ARCH:-arm64}" ;;
+ *) echo "${FAKE_OS:-Darwin}" ;;
+esac
+EOF
+chmod 755 "$fake/claude" "$fake/curl" "$fake/uname"
+cp "$fake/curl" "$fake/uname" "$nocl/"
+
+# A fake typst of a version: mktypst DIR VERSION
+mktypst() {
+ mkdir -p "$1"
+ printf '#!/bin/sh\necho "typst %s (fake)"\n' "$2" > "$1/typst"
+ chmod 755 "$1/typst"
+}
+
+# The fake release file (Darwin arm64), and its SHA-256.
+asset=typst-aarch64-apple-darwin
+mktypst "$tmp/build/$asset" 0.15.1
+can_xz=1
+(cd "$tmp/build" && tar -cJf "$tmp/assets/$asset.tar.xz" "$asset") 2> /dev/null || can_xz=
+sha() { if command -v sha256sum > /dev/null 2>&1; then sha256sum "$1"; else shasum -a 256 "$1"; fi | awk '{ print $1 }'; }
+real_sum=48f62ed034aa3a7978309579ac6ca00045e2ef0da73114e8af27cfd8e74dc05a
+fake_sum=$( [ -n "$can_xz" ] && sha "$tmp/assets/$asset.tar.xz")
+
+# The script with the mod's Typst folders in the sandbox (sys/a ... sys/e for
+# the folders outside HOME); install.sh also has the SHA-256 of the fake file.
+grep -q "$real_sum" "$script" && ok || bad "the arm64 macOS SHA-256 is not in install.sh"
+dirs="$tmp/sys/a $tmp/sys/b $tmp/sys/c $tmp/sys/d ~/.cargo/bin ~/.local/bin $tmp/sys/e ~/.linuxbrew/bin"
+perl -pe 's#^TYPST_DIRS=.*#TYPST_DIRS='"'$dirs'"'#' "$script" > "$tmp/install-badsum.sh"
+perl -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"
+
+typst_on_sys=
+PATH=$sys command -v typst > /dev/null 2>&1 && 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
+# script and the fake folder; XPATH goes before the system folders (each for one run).
+run() {
+ name=$1
+ 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" \
+ "$@" bash "${SCRIPT:-$tmp/install.sh}" < /dev/null > "$d/out" 2>&1
+ rc=$?
+ # sh keeps an assignment before a function call: clear them.
+ BIN='' SCRIPT='' XPATH=''
+}
+# The checks after a run.
+out() { grep -q -- "$1" "$d/out"; }
+log() { grep -qx -- "$1" "$d/state/claude.log" 2> /dev/null; }
+empty_home() { [ -z "$(cd "$d/home" && find . -mindepth 1 2> /dev/null)" ]; }
+no_claude_calls() { [ ! -e "$d/state/claude.log" ]; }
+no_downloads() { [ ! -e "$d/state/curl.log" ]; }
+no_work_left() { [ -z "$(find "$d" -maxdepth 1 -name 'iui-install.*' 2> /dev/null)" ] && [ -z "$(find "$d/home" -name '.typst.iui-*' -o -name '*.iui-[0-9]*' 2> /dev/null)" ]; }
+show() { sed 's/^/ | /' "$d/out"; }
+
+# --- The script's shape -------------------------------------------------------
+
+[ "$(tail -n 1 "$script")" = 'main "$@"' ] && ok || bad "the last line is not: main \"\$@\""
+head -n 1 "$script" | grep -qx '#!/usr/bin/env bash' && ok || bad "the first line is not #!/usr/bin/env bash"
+grep -q '^set -euo pipefail$' "$script" && ok || bad "no set -euo pipefail"
+LC_ALL=C grep -n '[^ -~ ]' "$script" > "$tmp/nonascii" && bad "install.sh has a character that is not ASCII: $(head -n 1 "$tmp/nonascii")" || ok
+[ -z "$(grep -n 'sudo' "$script" | grep -v 'never uses sudo')" ] && ok || bad "install.sh names sudo: $(grep -n sudo "$script" | grep -v 'never uses sudo')"
+[ -z "$(grep -nE '^[[:space:]]*eval[[:space:]]+[^{[:space:]]|[;&|][[:space:]]*eval[[:space:]]' "$script")" ] && ok || bad "install.sh uses eval"
+grep -q "curl -fsSL --proto '=https' --proto-redir '=https' --tlsv1.2" "$script" && ok || bad "the download is not https only"
+# The Typst folders are the mod's (TYPST_FALLBACKS), in its order.
+mod_dirs=$(perl -0ne '/TYPST_FALLBACKS = \[(.*?)\]/s or exit 1; my $l = $1; print join(" ", map { s#/typst$##r } $l =~ /\x27([^\x27]+)\x27/g)' "$here/hooks/lib/settings.ts")
+inst_dirs=$(sed -n "s/^TYPST_DIRS='\(.*\)'$/\1/p" "$script")
+[ -n "$mod_dirs" ] && [ "$mod_dirs" = "$inst_dirs" ] && ok || bad "TYPST_DIRS ($inst_dirs) is not TYPST_FALLBACKS of hooks/lib/settings.ts ($mod_dirs)"
+# The oldest Claude Code is the one of docs/install.md.
+doc_min=$(sed -n 's/^- Claude Code \([0-9.]*\) or later.*/\1/p' "$here/docs/install.md")
+[ -n "$doc_min" ] && grep -qx "MIN_CLAUDE=$doc_min" "$script" && ok || bad "MIN_CLAUDE is not $doc_min (docs/install.md)"
+if command -v shellcheck > /dev/null 2>&1; then
+ shellcheck -s bash "$script" > "$tmp/shellcheck" 2>&1 && ok || bad "shellcheck: $(head -n 20 "$tmp/shellcheck")"
+else
+ echo "install-sh-test: shellcheck skipped (not installed)"
+fi
+
+# --- 1. Checks ----------------------------------------------------------------
+
+BIN=$nocl run no-claude
+[ "$rc" = 1 ] && ok || bad "no claude: exit $rc, not 1"
+out 'code.claude.com/docs/en/setup' && out 'Nothing was changed' && ok || bad "no claude: no words on how to install Claude Code"
+empty_home && no_downloads && ok || bad "no claude: something changed"
+
+run freebsd FAKE_OS=FreeBSD
+[ "$rc" = 1 ] && out 'FreeBSD) is not supported' && ok || bad "FreeBSD: exit $rc"
+empty_home && no_claude_calls && no_downloads && ok || bad "FreeBSD: something changed"
+run armv7 FAKE_OS=Linux FAKE_ARCH=armv7l
+[ "$rc" = 1 ] && out 'armv7l) is not supported' && ok || bad "armv7l: exit $rc"
+empty_home && no_claude_calls && no_downloads && ok || bad "armv7l: something changed"
+
+run old-claude IUI_NO_TYPST=1 FAKE_CLAUDE_VERSION=2.1.200
+[ "$rc" = 0 ] && out 'needs Claude Code 2.1.298 or later' && ok || bad "an old Claude Code: exit $rc, or no warning"
+
+# --- 2. Typst -----------------------------------------------------------------
+
+mktypst "$tmp/path-new" 0.15.2
+XPATH=$tmp/path-new run typst-on-path
+[ "$rc" = 0 ] && out 'Typst 0.15.2 is installed' && ok || bad "Typst on the PATH: exit $rc"
+no_downloads && [ ! -e "$d/home/.local/bin/typst" ] && ok || bad "Typst on the PATH: a download"
+
+mkdir -p "$tmp/cargo/home"
+mktypst "$tmp/cargo/home/.cargo/bin" 0.15.0
+run 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"
+
+if [ -n "$typst_on_sys" ] || [ -z "$can_xz" ]; then
+ echo "install-sh-test: the Typst download skipped (a typst in $sys, or tar can not make .tar.xz)"
+else
+ run download
+ [ "$rc" = 0 ] && ok || { bad "the download: exit $rc"; show; }
+ [ "$(cat "$d/state/curl.log")" = "https://github.com/typst/typst/releases/download/v0.15.1/$asset.tar.xz" ] && ok || bad "the download URL: $(cat "$d/state/curl.log")"
+ [ -x "$d/home/.local/bin/typst" ] && [ "$("$d/home/.local/bin/typst" --version)" = "typst 0.15.1 (fake)" ] && ok || bad "the download: no typst in ~/.local/bin"
+ out 'SHA-256 is correct' && out 'Your PATH does not have ~/.local/bin' && ok || bad "the download: no SHA-256 or PATH line"
+ no_work_left && ok || bad "the download: files left: $(find "$d" -name 'iui-install.*' -o -name '.typst.iui-*')"
+ out 'rm ~/.local/bin/typst' && ok || bad "the download: no undo line"
+
+ # 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
+ 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"
+ grep -q 'Typst 0.15.1 is installed: ~/.local/bin/typst' "$d/out2" && ok || bad "the second run: Typst not found in ~/.local/bin"
+ log 'plugin marketplace add razorback16/cc-intelligent-ui' && log 'plugin install cc-intelligent-ui@razorback16 --scope user' && ok || bad "the first run: no add or install"
+ log 'plugin marketplace update razorback16' && log 'plugin update cc-intelligent-ui@razorback16 --scope user' && ok || bad "the second run: no update"
+ [ "$(grep -c '^plugin marketplace add' "$d/state/claude.log")" = 1 ] && [ "$(grep -c '^plugin install' "$d/state/claude.log")" = 1 ] && ok || bad "the second run added or installed again"
+ cmp -s "$tmp/settings-1" "$d/home/.claude/settings.json" && [ ! -e "$d/home/.claude/settings.json.bak-iui" ] && ok || bad "the second run changed settings.json"
+ grep -q 'on (it was on already)' "$d/out2" && grep -q 'the newest version was installed already' "$d/out2" && ok || bad "the second run: summary"
+ [ ! -e "$d/state/stdin.log" ] && ok || bad "claude read stdin: $(cat "$d/state/stdin.log")"
+
+ # An old Typst first on the PATH: the new one is installed, with a warning.
+ mktypst "$tmp/path-old" 0.13.1
+ XPATH=$tmp/path-old run old-typst
+ [ "$rc" = 0 ] && [ -x "$d/home/.local/bin/typst" ] && ok || bad "an old Typst: exit $rc, or no new typst"
+ out 'Typst 0.13.1 is at' && out 'uses the first Typst it finds' && ok || bad "an old Typst: no warning"
+
+ # An old Typst in ~/.local/bin is replaced.
+ mkdir -p "$tmp/replace/home"
+ mktypst "$tmp/replace/home/.local/bin" 0.12.0
+ XPATH=$tmp/replace/home/.local/bin run replace
+ [ "$rc" = 0 ] && [ "$("$d/home/.local/bin/typst" --version)" = "typst 0.15.1 (fake)" ] && ok || bad "an old Typst in ~/.local/bin was not replaced"
+ out 'Your PATH does not have ~/.local/bin' && bad "the PATH line with ~/.local/bin on the PATH" || ok
+
+ # The SHA-256 is not correct: refused, nothing installed, nothing else run.
+ SCRIPT=$tmp/install-badsum.sh run badsum
+ [ "$rc" = 1 ] && out 'SHA-256 of the downloaded Typst file is not correct' && ok || bad "a bad SHA-256: exit $rc"
+ [ ! -e "$d/home/.local/bin/typst" ] && [ ! -e "$d/home/.claude" ] && ok || bad "a bad SHA-256: something was installed"
+ grep -q '^plugin' "$d/state/claude.log" && bad "a bad SHA-256: claude plugin was run" || ok
+ no_work_left && ok || bad "a bad SHA-256: files left"
+
+ # The download fails (no such file for Linux x86_64 here).
+ run nofile FAKE_OS=Linux FAKE_ARCH=x86_64
+ [ "$rc" = 1 ] && out 'download of Typst failed' && [ ! -e "$d/home/.local/bin" ] && ok || bad "a failed download: exit $rc"
+ grep -q 'typst-x86_64-unknown-linux-musl.tar.xz$' "$d/state/curl.log" && ok || bad "Linux x86_64: the wrong file"
+
+ # 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
+ 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
+[ "$rc" = 0 ] && no_downloads && out 'IUI_NO_TYPST is set' && [ ! -e "$d/home/.local/bin" ] && ok || bad "IUI_NO_TYPST: exit $rc, or a download"
+
+# --- 3. The mod ---------------------------------------------------------------
+
+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"
+
+# --- 4. Auto-update: settings.json --------------------------------------------
+
+# setting NAME INPUT EXPECTED: settings.json is INPUT (printf format) before the
+# run and EXPECTED after it; a backup only when it changed.
+setting() {
+ name=$1
+ mkdir -p "$tmp/$name/home/.claude"
+ printf "$2" > "$tmp/$name/in"
+ printf "$3" > "$tmp/$name/want"
+ cp "$tmp/$name/in" "$tmp/$name/home/.claude/settings.json"
+ run "$name" IUI_NO_TYPST=1
+ [ "$rc" = 0 ] && ok || { bad "$name: exit $rc"; show; }
+ cmp -s "$d/want" "$d/home/.claude/settings.json" && ok || { bad "$name: settings.json is not as expected:"; diff "$d/want" "$d/home/.claude/settings.json" | sed 's/^/ /'; }
+ if cmp -s "$d/in" "$d/want"; then
+ [ ! -e "$d/home/.claude/settings.json.bak-iui" ] && ok || bad "$name: a backup with no change"
+ else
+ cmp -s "$d/in" "$d/home/.claude/settings.json.bak-iui" && ok || bad "$name: the backup is not the old file"
+ fi
+ no_work_left && ok || bad "$name: a temp file left"
+}
+entry2='{\n "razorback16": {\n "source": {\n "source": "github",\n "repo": "razorback16/cc-intelligent-ui"\n },\n "autoUpdate": true\n }\n }'
+
+run missing IUI_NO_TYPST=1
+printf '{\n "extraKnownMarketplaces": %s\n}\n' "$(printf "$entry2")" > "$d/want"
+cmp -s "$d/want" "$d/home/.claude/settings.json" && [ ! -e "$d/home/.claude/settings.json.bak-iui" ] && ok || bad "a missing settings.json: not made as expected"
+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"
+
+# As `claude plugin marketplace add` declares it: source only.
+setting declared \
+ '{\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 }\n },\n "theme": "dark"\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 "theme": "dark"\n}'
+
+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'
+
+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": true,\n "source": {"source": "github", "repo": "razorback16/cc-intelligent-ui"}\n }\n }\n}\n'
+
+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"
+
+setting tabs \
+ '{\n\t"a": [1, 2],\n\t"b": {}\n}\n' \
+ '{\n\t"a": [1, 2],\n\t"b": {},\n\t"extraKnownMarketplaces": {\n\t\t"razorback16": {\n\t\t\t"source": {\n\t\t\t\t"source": "github",\n\t\t\t\t"repo": "razorback16/cc-intelligent-ui"\n\t\t\t},\n\t\t\t"autoUpdate": true\n\t\t}\n\t}\n}\n'
+
+setting four-spaces \
+ '{\n "a": true\n}' \
+ '{\n "a": true,\n "extraKnownMarketplaces": {\n "razorback16": {\n "source": {\n "source": "github",\n "repo": "razorback16/cc-intelligent-ui"\n },\n "autoUpdate": true\n }\n }\n}'
+
+setting minified \
+ '{"a":1,"b":[true,null]}' \
+ '{"a":1,"b":[true,null],"extraKnownMarketplaces":{"razorback16":{"source":{"source":"github","repo":"razorback16/cc-intelligent-ui"},"autoUpdate":true}}}'
+
+setting one-line \
+ '{ "a": 1 }\n' \
+ '{ "a": 1, "extraKnownMarketplaces": {"razorback16": {"source": {"source": "github", "repo": "razorback16/cc-intelligent-ui"}, "autoUpdate": true}} }\n'
+
+setting empty-object \
+ '{}\n' \
+ '{\n "extraKnownMarketplaces": '"$entry2"'\n}\n'
+
+setting empty-marketplaces \
+ '{\n "extraKnownMarketplaces": {},\n "z": 0\n}\n' \
+ '{\n "extraKnownMarketplaces": '"$entry2"',\n "z": 0\n}\n'
+
+setting crlf \
+ '{\r\n "a": 1\r\n}\r\n' \
+ '{\r\n "a": 1,\r\n "extraKnownMarketplaces": '"$(printf '%s' "$entry2" | sed 's/\\n/\\r\\n/g')"'\r\n}\r\n'
+
+# Not valid JSON, or not the shape: no change, no backup, the snippet, exit 1.
+refused() {
+ name=$1
+ mkdir -p "$tmp/$name/home/.claude"
+ printf "$2" > "$tmp/$name/in"
+ cp "$tmp/$name/in" "$tmp/$name/home/.claude/settings.json"
+ run "$name" IUI_NO_TYPST=1
+ [ "$rc" = 1 ] && ok || bad "$name: exit $rc, not 1"
+ cmp -s "$d/in" "$d/home/.claude/settings.json" && [ ! -e "$d/home/.claude/settings.json.bak-iui" ] && ok || bad "$name: settings.json changed"
+ out 'was not changed' && out '"autoUpdate": true' && out 'Enable auto-update' && out 'NOT turned on' && ok || { bad "$name: no snippet"; show; }
+ log 'plugin install cc-intelligent-ui@razorback16 --scope user' && ok || bad "$name: the mod was not installed"
+ no_work_left && ok || bad "$name: a temp file left"
+}
+refused invalid '{\n "a": 1,\n}\n'
+refused comments '{\n // my settings\n "a": 1\n}\n'
+refused truncated '{\n "a": {\n'
+refused root-array '[1, 2]\n'
+refused bad-marketplaces '{"extraKnownMarketplaces": []}\n'
+refused bad-entry '{"extraKnownMarketplaces": {"razorback16": "x"}}\n'
+refused control-char '{"a": "x\001y"}\n'
+refused two-values '{} {}\n'
+
+# The place of the settings: CLAUDE_CONFIG_DIR.
+mkdir -p "$tmp/config/conf"
+run config IUI_NO_TYPST=1 CLAUDE_CONFIG_DIR="$tmp/config/conf"
+[ "$rc" = 0 ] && grep -q '"autoUpdate": true' "$tmp/config/conf/settings.json" && [ ! -e "$d/home/.claude" ] && ok || bad "CLAUDE_CONFIG_DIR: not used"
+
+# A settings.json that is a link: the link stays, its file changes, with its mode.
+mkdir -p "$tmp/link/home/.claude" "$tmp/link/dotfiles"
+printf '{\n "a": 1\n}\n' > "$tmp/link/dotfiles/settings.json"
+chmod 600 "$tmp/link/dotfiles/settings.json"
+ln -s "$tmp/link/dotfiles/settings.json" "$tmp/link/home/.claude/settings.json"
+run link IUI_NO_TYPST=1
+[ "$rc" = 0 ] && [ -L "$d/home/.claude/settings.json" ] && grep -q '"autoUpdate": true' "$d/dotfiles/settings.json" && ok || bad "a link: exit $rc, or the link was replaced"
+case $(ls -l "$d/dotfiles/settings.json") in -rw-------*) ok ;; *) bad "a link: the mode changed: $(ls -l "$d/dotfiles/settings.json")" ;; esac
+case $(ls -l "$d/home/.claude/settings.json.bak-iui") in -rw-------*) ok ;; *) bad "the backup mode is not the file's" ;; esac
+
+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"
+
+# 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
+
+# --- A cut download runs nothing ---------------------------------------------
+
+size=$(wc -c < "$tmp/install.sh" | tr -d ' ')
+last=$(tail -n 1 "$tmp/install.sh" | wc -c | tr -d ' ')
+cuts="$((size - last)) $((size - 3))"
+i=1
+while [ "$i" -lt 40 ]; do
+ cuts="$cuts $((size * i / 40))"
+ i=$((i + 1))
+done
+n=0
+for c in $cuts; do
+ n=$((n + 1))
+ head -c "$c" "$tmp/install.sh" > "$tmp/cut.sh"
+ SCRIPT=$tmp/cut.sh run "cut-$n"
+ empty_home && no_claude_calls && no_downloads && ok || { bad "a script cut at byte $c ran something (exit $rc)"; show; }
+done
+# The full file (the same size cut) runs: the test can see a run.
+head -c "$(wc -c < "$tmp/install.sh" | tr -d ' ')" "$tmp/install.sh" > "$tmp/cut.sh"
+SCRIPT=$tmp/cut.sh run cut-full IUI_NO_TYPST=1
+[ "$rc" = 0 ] && log 'plugin install cc-intelligent-ui@razorback16 --scope user' && ok || bad "the uncut script did not run"
+
+echo "install-sh-test: $pass passed, $fail failed"
+[ "$fail" = 0 ]