@@ -3,25 +3,96 @@ set -euo pipefail
33BRANCH=" ${CODEIN_BRANCH:- main} "
44RAW=" https://raw.githubusercontent.com/aishervin/codein/$BRANCH "
55ROOT=" $HOME /.codein"
6- command -v pkg > /dev/null 2>&1 || { echo " Run this inside Termux." >&2 ; exit 1; }
6+
7+ # Keep logs clean while making interactive Termux installs easier to follow.
8+ if [[ -t 1 && -z " ${NO_COLOR:- } " ]]; then
9+ C_RESET=$' \033 [0m'
10+ C_BOLD=$' \033 [1m'
11+ C_CYAN=$' \033 [36m'
12+ C_BLUE=$' \033 [34m'
13+ C_GREEN=$' \033 [32m'
14+ C_YELLOW=$' \033 [33m'
15+ C_RED=$' \033 [31m'
16+ C_WHITE=$' \033 [97m'
17+ else
18+ C_RESET=' '
19+ C_BOLD=' '
20+ C_CYAN=' '
21+ C_BLUE=' '
22+ C_GREEN=' '
23+ C_YELLOW=' '
24+ C_RED=' '
25+ C_WHITE=' '
26+ fi
27+
28+ codein_banner () {
29+ printf ' \n%b' " $C_CYAN$C_BOLD "
30+ printf ' +--------------------------------------------------+\n'
31+ printf ' %b' " $C_WHITE$C_BOLD "
32+ printf ' | CODEIN / TERMUX |\n'
33+ printf ' %b' " $C_BLUE "
34+ printf ' | Local Agent Room and MCP Bridge |\n'
35+ printf ' %b' " $C_CYAN$C_BOLD "
36+ printf ' +--------------------------------------------------+\n'
37+ printf ' %b\n\n' " $C_RESET "
38+ }
39+
40+ codein_step () {
41+ printf ' \n%b[STEP]%b %s\n' " $C_BLUE$C_BOLD " " $C_RESET " " $* "
42+ }
43+
44+ codein_info () {
45+ printf ' %b[INFO]%b %s\n' " $C_CYAN " " $C_RESET " " $* "
46+ }
47+
48+ codein_success () {
49+ printf ' %b[ OK ]%b %s\n' " $C_GREEN$C_BOLD " " $C_RESET " " $* "
50+ }
51+
52+ codein_warn () {
53+ printf ' %b[WARN]%b %s\n' " $C_YELLOW$C_BOLD " " $C_RESET " " $* "
54+ }
55+
56+ codein_error () {
57+ printf ' %b[FAIL]%b %s\n' " $C_RED$C_BOLD " " $C_RESET " " $* " >&2
58+ }
59+
60+ on_error () {
61+ local status=$?
62+ trap - ERR
63+ codein_error " Setup stopped with exit code $status . Review the output above."
64+ exit " $status "
65+ }
66+ trap on_error ERR
67+
68+ codein_banner
69+ codein_step " 1/5 Preparing the Termux runtime"
70+ command -v pkg > /dev/null 2>&1 || { codein_error " Run this inside Termux." ; exit 1; }
771mkdir -p " $ROOT " /{workspace,agents,keys,sessions,events,skills,tools,logs,bin,docs}
872chmod 700 " $ROOT " " $ROOT /keys"
9- echo " [Codein] Preparing Termux runtime ..."
73+ codein_info " Updating Termux packages ..."
1074pkg update -y
1175pkg install -y python git openssh curl
76+ codein_success " Required packages are ready."
1277
1378# Validate the full update before replacing any installed bridge files.
79+ codein_step " 2/5 Downloading bridge files"
1480STAGE=" $( mktemp -d " $ROOT /.update.XXXXXX" ) "
1581cleanup () { rm -rf " $STAGE " ; }
1682trap cleanup EXIT
83+ CODEIN_FETCHED=0
84+ CODEIN_FETCH_TOTAL=17
1785fetch () {
1886 local remote target staged
1987 remote=" $1 "
2088 target=" $2 "
2189 staged=" $STAGE /$remote "
90+ CODEIN_FETCHED=$(( CODEIN_FETCHED + 1 ))
91+ printf ' \n%b[DOWNLOAD %02d/%02d]%b %s\n' " $C_CYAN$C_BOLD " " $CODEIN_FETCHED " " $CODEIN_FETCH_TOTAL " " $C_RESET " " $remote "
2292 mkdir -p " $( dirname " $staged " ) "
2393 curl --retry 3 --retry-delay 1 --fail --silent --show-error " $RAW /$remote " -o " $staged "
2494 printf ' %s|%s\n' " $remote " " $target " >> " $STAGE /install.list"
95+ codein_success " Staged $remote "
2596}
2697fetch " termux/server.py" " $ROOT /server.py"
2798fetch " termux/composio_connect.py" " $ROOT /composio_connect.py"
@@ -41,10 +112,16 @@ fetch "docs/TOOL_DOCS_INDEX.md" "$ROOT/docs/TOOL_DOCS_INDEX.md"
41112fetch " docs/AGENT_SYSTEM_PROMPT.md" " $ROOT /docs/AGENT_SYSTEM_PROMPT.md"
42113fetch " termux/LIBRARIES.md" " $ROOT /docs/LIBRARIES.md"
43114
115+ codein_step " 3/5 Validating staged files"
44116python -m py_compile " $STAGE /termux/server.py" " $STAGE /termux/composio_connect.py" " $STAGE /termux/composio_platform.py" " $STAGE /termux/with-key.py"
45117bash -n " $STAGE /termux/codein-bridge" " $STAGE /termux/codein-opencode" " $STAGE /termux/codein-links"
118+ codein_success " Python and shell syntax checks passed."
119+
120+ codein_step " 4/5 Installing the bridge and preparing Agent Room"
121+ CODEIN_INSTALLED=0
46122while IFS=' |' read -r remote target; do
47123 [ -n " $remote " ] || continue
124+ CODEIN_INSTALLED=$(( CODEIN_INSTALLED + 1 ))
48125 mkdir -p " $( dirname " $target " ) "
49126 cp " $STAGE /$remote " " $target .new.$$ "
50127 if [[ " $target " == " $ROOT /server.py" || " $target " == " $ROOT /bin/" * ]]; then
@@ -54,15 +131,18 @@ while IFS='|' read -r remote target; do
54131 fi
55132 mv -f " $target .new.$$ " " $target "
56133done < " $STAGE /install.list"
134+ codein_success " Installed $CODEIN_INSTALLED validated bridge files."
57135
58136if [ ! -f " $ROOT /config.json" ]; then
137+ codein_info " Creating a private local pairing configuration..."
59138 python - " $ROOT /config.json" << 'PY '
60139import json, secrets, sys
61140from pathlib import Path
62141p = Path(sys.argv[1])
63142p.write_text(json.dumps({"port":8765,"token":secrets.token_urlsafe(32),"workspace":str(Path.home()/".codein"/"workspace")}, indent=2)+"\n")
64143p.chmod(0o600)
65144PY
145+ codein_success " Created the local pairing configuration."
66146fi
67147
68148# Keep local user data and the Android pairing token stable across upgrades.
@@ -91,6 +171,7 @@ Shared local context for every model and agent connected to Codein.
911718. If a required credential is missing, ask for that exact credential, store it in the local vault, then continue.
921729. Check the shared vault before asking again.
93173ROOM
174+ codein_success " Created the Agent Room guide."
94175fi
95176if ! grep -Fq " ## Agent capability check" " $ROOT /ROOM.md" ; then
96177cat >> " $ROOT /ROOM.md" << 'ROOM '
@@ -106,16 +187,16 @@ if [ ! -f "$ROOT/.gitignore" ]; then
106187 printf ' %s\n' ' keys/' ' config.json' ' *.secret' > " $ROOT /.gitignore"
107188fi
108189
109- echo
110- echo " [Codein] Starting the local bridge..."
190+ codein_step " 5/5 Starting and verifying local services "
191+ codein_info " Restarting the local bridge..."
111192" $ROOT /bin/codein-bridge" restart
112193TOKEN=" $( python - " $ROOT /config.json" << 'PY '
113194import json, sys
114195from pathlib import Path
115196print(json.loads(Path(sys.argv[1]).read_text())["token"])
116197PY
117198) "
118- python - " $ROOT /config.json" << 'PY '
199+ MCP_VERSION= " $( python - " $ROOT /config.json" << 'PY '
119200import json, sys
120201from urllib.request import Request, urlopen
121202config = json.load(open(sys.argv[1], encoding="utf-8"))
@@ -130,34 +211,34 @@ version = result.get("serverInfo", {}).get("version", "")
130211parts = [int(part) if part.isdigit() else 0 for part in version.split(".")]
131212if (parts + [0, 0])[:3] < [1, 5, 1]:
132213 raise SystemExit("[Codein] MCP bridge update verification failed; expected version 1.5.1 or newer.")
133- print("[Codein] MCP bridge verified: version " + version)
214+ print(version)
134215PY
216+ ) "
217+ codein_success " MCP bridge verified: version $MCP_VERSION "
218+ codein_info " Workspace and documentation skills are ready at $ROOT "
219+ codein_info " Bridge controls: $ROOT /bin/codein-bridge {start|stop|restart|status|logs}"
220+ codein_info " Bridge log: $ROOT /logs/server.log"
221+ codein_info " Keep Termux open while Codein uses it."
135222
136- echo
137- echo " [Codein] Workspace and documentation skills ready: $ROOT "
138- echo " [Codein] Bridge controls: $ROOT /bin/codein-bridge {start|stop|restart|status|logs}"
139- echo " [Codein] Bridge log: $ROOT /logs/server.log"
140- echo " [Codein] Keep Termux open while Codein uses it."
141- echo
142- echo " [Codein] Opening parallel connections (bridge + OpenCode + Quick Tunnel)..."
223+ codein_step " Opening parallel connections"
143224if " $ROOT /bin/codein-links" start; then
144- echo " [Codein] Parallel links are up; the watchdog keeps them alive."
225+ codein_success " Parallel links are up; the watchdog keeps them alive."
145226else
146- echo " [Codein] Some links are not ready yet. The watchdog retries every 10s ."
147- echo " [Codein] Check: $ROOT /bin/codein-links status"
227+ codein_warn " Some links are not ready yet. The watchdog retries every 10 seconds ."
228+ codein_info " Check their status with : $ROOT /bin/codein-links status"
148229fi
149230
150- echo
151- echo " ============================================================"
152- echo " [Codein] TERMUX CONNECTION TOKEN"
153- echo " Copy this token into Codein app > Termux connection:"
231+ printf ' \n%b' " $C_YELLOW$C_BOLD "
232+ printf ' +--------------------------------------------------+\n'
233+ printf ' | TERMUX CONNECTION TOKEN |\n'
234+ printf ' | Copy this token into Codein > Termux settings |\n'
235+ printf ' +--------------------------------------------------+\n'
236+ printf ' %b' " $C_RESET "
154237python - " $ROOT /config.json" << 'PY '
155238import json, sys
156239from pathlib import Path
157240config = json.loads(Path(sys.argv[1]).read_text())
158241print(config["token"])
159242PY
160- echo " ============================================================"
161- echo " This token is private. Do not share it or post a screenshot."
162- echo
163- echo " [Codein] Bridge log: $ROOT /logs/server.log"
243+ codein_warn " This token is private. Do not share it or post a screenshot."
244+ codein_info " Bridge log: $ROOT /logs/server.log"
0 commit comments