Skip to content

armgit / chums

Public Imported from GitHub
0

Talk to Claude Code and Codex agents from an Apple Watch and an iPhone. Each agent is a character on the watch.

Private build folder, paths of any name, the running hub checked, an agent's page kept to itself on the iPhone

Lucas Couto6821bd6e1aa3
diff --git a/SECURITY.md b/SECURITY.md
index 2c9fdd6..58c6ac2 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -104,7 +104,9 @@ To take the watch API off the internet at once: `tailscale --socket ~/.chums/tai
- `chums_show` can show any file the session can read: a text file is shown as text, and the file is kept (up to
25 MB) in `~/.chums/artifacts` for the iPhone to open.
- An HTML or SVG file a session showed or you sent is served to the iPhone with `Content-Security-Policy: sandbox
- allow-scripts`: its scripts run, in an origin of their own, not the hub's.
+ allow-scripts`: its scripts run, in an origin of their own, not the hub's. The iPhone app shows it in a web view
+ of its own that keeps nothing between pages: its scripts run, but it can't go to another page, send a form or open
+ a window, and a link you tap opens in Safari.
- Speech is transcribed on the Mac by WhisperKit, and the replies are spoken by Kokoro on the Mac. Audio is not sent
to a third party by Chums. Instructions you speak go to the agent (Claude Code or Codex), which sends them to its
provider like any other prompt. With `"tts": { "engine": "openai" }` in `~/.chums/config.json`, the text of every
diff --git a/app/ChumsPhone/Viewer.swift b/app/ChumsPhone/Viewer.swift
index 9d8faab..67e7c36 100644
--- a/app/ChumsPhone/Viewer.swift
+++ b/app/ChumsPhone/Viewer.swift
@@ -148,11 +148,21 @@ struct LiveWeb: UIViewRepresentable {
w.accessibilityIdentifier = "artifact-web"
switch source {
case .url(let u): w.load(URLRequest(url: u))
- case .html(let h): w.loadHTMLString(h, baseURL: URL(string: "about:blank"))
+ case .html(let h): w.loadHTMLString(Self.contained(h), baseURL: URL(string: "about:blank"))
}
return w
}
func updateUIView(_ w: WKWebView, context: Context) { context.coordinator.loaded = loaded; context.coordinator.failed = failed }
+
+ /// An agent's page with a policy of its own first: it sends no form and gives links no other base. (Going to
+ /// another page and sending a form are also refused below; with no UI delegate, it opens no window.)
+ static func contained(_ html: String) -> String {
+ let policy = #"<meta http-equiv="Content-Security-Policy" content="form-action 'none'; base-uri 'none'">"#
+ if let head = html.range(of: "<head[^>]*>", options: [.regularExpression, .caseInsensitive]) {
+ return html.replacingCharacters(in: head, with: html[head] + policy)
+ }
+ return policy + html
+ }
func makeCoordinator() -> Coordinator { Coordinator(loaded, failed, html: { if case .html = source { true } else { false } }()) }
final class Coordinator: NSObject, WKNavigationDelegate {
@@ -167,8 +177,10 @@ struct LiveWeb: UIViewRepresentable {
func webView(_ w: WKWebView, decidePolicyFor a: WKNavigationAction, decisionHandler: @escaping @MainActor (WKNavigationActionPolicy) -> Void) {
if a.navigationType == .linkActivated, let u = a.request.url, ["http", "https"].contains(u.scheme) {
UIApplication.shared.open(u); decisionHandler(.cancel)
+ } else if html, a.navigationType == .formSubmitted || a.navigationType == .formResubmitted {
+ decisionHandler(.cancel) // a form, in the page or in a frame in it
} else if html, a.targetFrame?.isMainFrame ?? true, a.request.url?.absoluteString != "about:blank" {
- decisionHandler(.cancel) // a script or a form taking the page somewhere else
+ decisionHandler(.cancel) // a script taking the page somewhere else
} else { decisionHandler(.allow) }
}
}
diff --git a/bin/chums-agents b/bin/chums-agents
index a015a9c..cc1dab0 100755
--- a/bin/chums-agents
+++ b/bin/chums-agents
@@ -20,18 +20,19 @@ ids() { "$CHUMS_NODE" -e 'const w=process.argv[1];console.log(JSON.parse(require
runtime() { "$CHUMS_NODE" -e 'const a=JSON.parse(require("fs").readFileSync(process.env.HOME+"/.chums/agents.json","utf8")).find(a=>a.id===process.argv[1]);console.log(a?(a.runtime??"claude"):"")' "$1" }
label() { echo "$CHUMS_LABEL_PREFIX.agent.$1" }
plist() {
+ local xa=$(chums_xml "$APPX") xr=$(chums_xml "$ROOT") xn=$(chums_xml "$CHUMS_NODE") xh=$(chums_xml "$HOME")
cat > "$LA/$(label $1).plist" <<PL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>$(label $1)</string>
- <key>ProgramArguments</key><array><string>$APPX</string><string>/usr/bin/expect</string><string>$ROOT/tools/agent-host.exp</string><string>$1</string></array>
- <key>EnvironmentVariables</key><dict><key>CHUMS_NODE</key><string>$CHUMS_NODE</string>${CHUMS_NO_RC:+<key>CHUMS_NO_RC</key><string>1</string>}</dict>
+ <key>ProgramArguments</key><array><string>$xa</string><string>/usr/bin/expect</string><string>$xr/tools/agent-host.exp</string><string>$1</string></array>
+ <key>EnvironmentVariables</key><dict><key>CHUMS_NODE</key><string>$xn</string>${CHUMS_NO_RC:+<key>CHUMS_NO_RC</key><string>1</string>}</dict>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
<key>ThrottleInterval</key><integer>30</integer>
- <key>StandardOutPath</key><string>$HOME/.chums/agents/$1.launchd.log</string>
- <key>StandardErrorPath</key><string>$HOME/.chums/agents/$1.launchd.log</string>
+ <key>StandardOutPath</key><string>$xh/.chums/agents/$1.launchd.log</string>
+ <key>StandardErrorPath</key><string>$xh/.chums/agents/$1.launchd.log</string>
</dict></plist>
PL
}
diff --git a/bin/chums-claude b/bin/chums-claude
index def5aff..a087dc4 100755
--- a/bin/chums-claude
+++ b/bin/chums-claude
@@ -14,9 +14,11 @@ command -v node >/dev/null 2>&1 || die "node is not installed (the channel and t
[[ -d "$CHUMS_ROOT/node_modules/@modelcontextprotocol/sdk" ]] || die "the npm packages aren't installed. Run bin/chums-setup (or npm ci in $CHUMS_ROOT)."
command -v claude >/dev/null 2>&1 ||
die "claude is not on PATH. Install Claude Code (curl -fsSL https://claude.ai/install.sh | bash), or add its folder (often ~/.local/bin) to PATH."
+# a path inside a JSON string
+jstr() { local s=${1//\\/\\\\}; print -rn -- ${s//\"/\\\"} }
MCP_JSON="$CHUMS_ROOT/channel/mcp.json"
cat > "$MCP_JSON" <<EOF
-{ "mcpServers": { "chums": { "command": "node", "args": ["$CHUMS_ROOT/channel/chums-channel.mjs"] } } }
+{ "mcpServers": { "chums": { "command": "node", "args": ["$(jstr "$CHUMS_ROOT/channel/chums-channel.mjs")"] } } }
EOF
if [[ -n "$1" && "$1" != -* ]]; then export CHUMS_NAME="$1"; shift; fi
@@ -27,7 +29,8 @@ if [[ -n "$1" && "$1" != -* ]]; then export CHUMS_NAME="$1"; shift; fi
# Hooks report what the session is doing to the hub: tool calls and failures, permission requests, notifications,
# prompts, stops and stop failures, compaction, subagents, session start and end. See design/STATES.md.
HOOKS_JSON="$CHUMS_ROOT/channel/hooks.json"
-HOOK="node '$CHUMS_ROOT/channel/chums-hook.mjs'"
+hook=$CHUMS_ROOT/channel/chums-hook.mjs
+HOOK=$(jstr "node ${(qq)hook}") # quoted for the shell, then for JSON: any folder name works
cat > "$HOOKS_JSON" <<EOF
{ "permissions": { "deny": ["Edit(~/.chums/souls/**)", "Write(~/.chums/souls/**)", "MultiEdit(~/.chums/souls/**)", "AskUserQuestion"], "allow": ["Read(~/.chums/uploads/**)"] },
"hooks": {
diff --git a/bin/chums-install b/bin/chums-install
index dcafbbb..065711a 100755
--- a/bin/chums-install
+++ b/bin/chums-install
@@ -55,6 +55,7 @@ echo "Watch: $WNAME"
"$ROOT/tools/gen-config.sh"
cd "$ROOT/app"
+mkdir -p build && chmod 700 build # the built apps hold the watch token: readable by you only
# Sign with a paid team if Xcode has one, else your free Personal Team (installs expire after 7 days).
: ${CHUMS_TEAM:=$(chums_cfg team)}; export CHUMS_TEAM
diff --git a/bin/chums-permissions b/bin/chums-permissions
index 526a7ee..b760e77 100755
--- a/bin/chums-permissions
+++ b/bin/chums-permissions
@@ -3,7 +3,8 @@
# Chums (~/Applications/Chums.app, tools/mac-app), so everything they ask for belongs to it, and Claude Code, Codex or
# Node.js updates don't undo it. Opening Chums shows a window: Allow All, then answer each macOS dialog.
# bin/chums-permissions open Chums (the same as double-clicking it in ~/Applications); builds it if needed
-# bin/chums-permissions check what's granted, asking nothing and changing nothing
+# bin/chums-permissions check what's granted, asking nothing and changing nothing; exits 1 when something
+# needed is missing
ROOT="${0:A:h:h}"
source "$ROOT/tools/common.zsh"
chums_help "$@"
@@ -23,15 +24,23 @@ print "Chums: $APP"
[[ $(cat "$APP/Contents/Resources/stamp" 2>/dev/null) == $("$ROOT/tools/mac-app/build.zsh" --expected-stamp) ]] \
|| print " note Chums.app is out of date: bin/chums-agents install rebuilds it (then Allow All again if it's signed ad hoc)"
n=0
-[[ -f $LA/$CHUMS_LABEL_PREFIX.hub.plist ]] || { print " the hub doesn't run as a LaunchAgent: what it does on the Mac asks as the terminal it runs in, not as Chums"; n=1 }
+D=gui/$(id -u)
+hubjob=$(launchctl print $D/$CHUMS_LABEL_PREFIX.hub 2>/dev/null)
+if [[ ! -f $LA/$CHUMS_LABEL_PREFIX.hub.plist ]]; then
+ print " the hub doesn't run as a LaunchAgent: what it does on the Mac asks as the terminal it runs in, not as Chums"; n=1
+elif [[ $hubjob != *"state = running"* || $hubjob != *"program = $APPX"* ]]; then
+ print " the hub's LaunchAgent isn't running through Chums (a hub in a terminal holds the port, or it stopped)"; n=1
+fi
for f in $LA/$CHUMS_LABEL_PREFIX.hub.plist $LA/$CHUMS_LABEL_PREFIX.tailscaled.plist $LA/$CHUMS_LABEL_PREFIX.agent.*.plist(N); do
[[ -f $f && $(plutil -extract ProgramArguments.0 raw "$f" 2>/dev/null) != $APPX ]] && { print " ${f:t} doesn't start through Chums"; n=1 }
done
(( n )) && print " fix bin/chums-setup --launchd and bin/chums-agents install" || print " ok the hub, tailscaled and the agents run as Chums"
-show() { local label=$1; shift; printf " %-5s %s\n" $("$APPX" --check "$@" >/dev/null 2>&1 && print ok || print no) "$label" }
-show "Accessibility" accessibility
-show "Screen Recording" screen
-show "Full Disk Access (optional; covers your folders)" fda
+# needed: a "no" makes check exit 1; optional: shown only
+show() { local need=$1 label=$2; shift 2; if "$APPX" --check "$@" >/dev/null 2>&1; then printf " %-5s %s\n" ok "$label"
+ else printf " %-5s %s\n" no "$label"; [[ $need == need ]] && n=1; fi }
+show need "Accessibility" accessibility
+show need "Screen Recording" screen
+show optional "Full Disk Access (optional; covers your folders)" fda
"$APPX" --check apps 2>/dev/null | while IFS=$'\t' read -r st name; do
case $st in
granted) printf " %-5s control %s\n" ok "$name" ;;
@@ -40,3 +49,4 @@ show "Full Disk Access (optional; covers your folders)" fda
esac
done
print " (your folders: Chums's window shows them; checking them here would ask)"
+exit $n
diff --git a/bin/chums-setup b/bin/chums-setup
index 5fa7cee..8320086 100755
--- a/bin/chums-setup
+++ b/bin/chums-setup
@@ -107,18 +107,19 @@ if (( LAUNCHD )); then
# a LaunchAgent gets no shell PATH: node's and whisperkit-cli's folders, then Homebrew's (Apple silicon, Intel)
WK=$(command -v whisperkit-cli 2>/dev/null)
HUBPATH=${CHUMS_NODE:h}${WK:+:${WK:h}}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+ xa=$(chums_xml "$APPX") xr=$(chums_xml "$ROOT") xn=$(chums_xml "$CHUMS_NODE") xh=$(chums_xml "$HOME") xp=$(chums_xml "$HUBPATH")
cat > $hub <<PL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>$CHUMS_LABEL_PREFIX.hub</string>
- <key>ProgramArguments</key><array><string>$APPX</string><string>/usr/bin/caffeinate</string><string>-s</string><string>$CHUMS_NODE</string><string>$ROOT/hub/hub.mjs</string></array>
- <key>EnvironmentVariables</key><dict><key>PATH</key><string>$HUBPATH</string></dict>
+ <key>ProgramArguments</key><array><string>$xa</string><string>/usr/bin/caffeinate</string><string>-s</string><string>$xn</string><string>$xr/hub/hub.mjs</string></array>
+ <key>EnvironmentVariables</key><dict><key>PATH</key><string>$xp</string></dict>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
<key>ProcessType</key><string>Interactive</string>
- <key>StandardOutPath</key><string>$HOME/.chums/hub.log</string>
- <key>StandardErrorPath</key><string>$HOME/.chums/hub.log</string>
+ <key>StandardOutPath</key><string>$xh/.chums/hub.log</string>
+ <key>StandardErrorPath</key><string>$xh/.chums/hub.log</string>
</dict></plist>
PL
chums_reload $CHUMS_LABEL_PREFIX.hub $hub && ok "hub: $hub (log ~/.chums/hub.log)"
@@ -129,10 +130,10 @@ PL
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>$CHUMS_LABEL_PREFIX.tailscaled</string>
- <key>ProgramArguments</key><array><string>$APPX</string><string>$(command -v tailscaled)</string><string>--tun=userspace-networking</string>
- <string>--statedir=$HOME/.chums/tailscale</string><string>--socket=$HOME/.chums/tailscale/tailscaled.sock</string><string>--port=0</string></array>
+ <key>ProgramArguments</key><array><string>$xa</string><string>$(chums_xml "$(command -v tailscaled)")</string><string>--tun=userspace-networking</string>
+ <string>--statedir=$xh/.chums/tailscale</string><string>--socket=$xh/.chums/tailscale/tailscaled.sock</string><string>--port=0</string></array>
<key>RunAtLoad</key><true/><key>KeepAlive</key><true/>
- <key>StandardOutPath</key><string>$HOME/.chums/tailscale/tailscaled.log</string><key>StandardErrorPath</key><string>$HOME/.chums/tailscale/tailscaled.log</string>
+ <key>StandardOutPath</key><string>$xh/.chums/tailscale/tailscaled.log</string><key>StandardErrorPath</key><string>$xh/.chums/tailscale/tailscaled.log</string>
</dict></plist>
PL
chums_reload $CHUMS_LABEL_PREFIX.tailscaled $tsd && ok "tailscaled: $tsd"
diff --git a/bin/chums-sim b/bin/chums-sim
index 38b9cf0..db38295 100755
--- a/bin/chums-sim
+++ b/bin/chums-sim
@@ -12,6 +12,7 @@ NAME="Chums Watch"
"$ROOT/tools/gen-config.sh" >/dev/null
cd "$ROOT/app"
+mkdir -p build && chmod 700 build # the built apps hold the watch token: readable by you only
: ${CHUMS_BUNDLE:=$(chums_cfg bundleId)}
: ${CHUMS_BUNDLE:=dev.chums}
export CHUMS_BUNDLE
diff --git a/tools/common.zsh b/tools/common.zsh
index 9430083..51ced51 100644
--- a/tools/common.zsh
+++ b/tools/common.zsh
@@ -11,6 +11,10 @@ CHUMS_HOME=~/.chums
CHUMS_CONFIG=$CHUMS_HOME/config.json
# chums_cfg <key>: a value from ~/.chums/config.json, or nothing
+# a value written into a LaunchAgent's XML, or into a JSON string (a path with &, <, " or \ in it)
+chums_xml() { local s=${1//&/&amp;}; s=${s//</&lt;}; print -rn -- ${s//>/&gt;} }
+chums_json() { local s=${1//\\/\\\\}; print -rn -- ${s//\"/\\\"} }
+
chums_cfg() {
[[ -f $CHUMS_CONFIG ]] || return 0
python3 -c 'import json,sys
diff --git a/tools/doctor.py b/tools/doctor.py
index ec8becb..53cffa4 100644
--- a/tools/doctor.py
+++ b/tools/doctor.py
@@ -254,6 +254,8 @@ elif cfg is None:
else:
mode = os.stat(CONFIG).st_mode & 0o777
if mode & 0o077: warn(f'~/.chums/config.json is readable by other users (mode {oct(mode)[2:]}); it holds the tokens', 'chmod 600 ~/.chums/config.json')
+ dmode = os.stat(os.path.dirname(CONFIG)).st_mode & 0o777
+ if dmode & 0o077: warn(f'~/.chums is open to other users (mode {oct(dmode)[2:]}); it holds your conversations and uploads', 'chmod 700 ~/.chums (the hub does it when it starts)')
if cfg.get('token') and cfg.get('watchToken'): ok(f'~/.chums/config.json: ports {cfg.get("port", 7717)} and {cfg.get("publicPort", 7718)}, both tokens set (not shown)')
else: fail('~/.chums/config.json is missing a token', ['restart the hub: it adds the missing token', 'then bin/chums-install, so the watch app gets it'])
if cfg.get('publicURL'): ok(f'public URL {cfg["publicURL"]}')
diff --git a/tools/mac-app/build.zsh b/tools/mac-app/build.zsh
index 1476c00..6bd5ecd 100755
--- a/tools/mac-app/build.zsh
+++ b/tools/mac-app/build.zsh
@@ -41,7 +41,7 @@ lipo -create "$TMP/Chums-arm64" "$TMP/Chums-x86_64" -output "$B/Contents/MacOS/C
# the icon: Noodle (the public watch app's icon; in this repo the overlay has it, in the public one the app does)
ICON=""
-for d in "$CHUMS_ROOT"/tools/public-overlay/app "$CHUMS_ROOT"/app; do
+for d in "$CHUMS_ROOT"/app; do
ICON=$(print -l "$d"/ChumsWatch/Assets.xcassets/AppIcon.appiconset/*.png(N) | head -1); [[ -n $ICON ]] && break
done
if [[ -n $ICON ]]; then