用手機 Remote Control AI Agent 寫 Code
我哋成日講「remote work」,但大部分嘅 remote coding 依然係你要坐喺一部 development machine 前面,開住 IDE,ssh 入 server,先叫做到嘢。咁有冇諗過一個更極端嘅 scenario:你一邊行街、食緊茶記、或者啱啱收工上緊巴士,攞部手機出嚟,send 一個 message,你屋企部 server 就自動 spawn 一個 AI agent,幫你寫 code、做 refactor、commit 甚至 push 上 GitHub?唔係未來科技,今日就做到。我分享一個用 HAPI(HK API Company 嘅 AI 服務)加 opencode-bar 嘅實戰 setup,真正用手機 remote control AI agent 寫 production code。
HAPI 做 Bridge:將 AI Agent 帶入手機 App
OpenCode 本身係一個 CLI tool,行喺 server 或者 desktop 上面。佢可以理解複雜嘅 coding task,讀 codebase,執行 command,甚至自己 debug。但佢有一個「死穴」:佢哋無 native UI,無 API endpoint,你冇辦法直接由手機叫醒佢。呢個就係 HAPI 出場嘅時候。
HAPI(hkapi.company)提供咗一條好簡單嘅 bridge:你喺手機上透過佢哋嘅 app 或者 API send 一個 request,HAPI 會將呢個 request forward 去你預先設定好嘅 webhook endpoint。換句話講,你只需要喺你嘅 server 上開一個好輕量嘅 HTTP server(用 Python FastAPI 或者 Node.js Express,甚至一個簡單嘅 bash script 都得),listen 住 HAPI 嘅 webhook call,然後喺收到 request 嘅時候 spawn 一個 opencode 嘅 session。
舉個 concrete 例子:我將一個 Telegram bot 同 HAPI 串埋。喺 HAPI dashboard(即係 CC Pocket app 入面)set 好 inbound rules,當佢收到特定格式嘅 Telegram message,就會 POST 去我 VPS 上嘅 webhook。我個 webhook handler 好簡單:parse 個 message,拎出 task description,然後 call opencode do "<task>"。就係咁,一個由手機到 AI agent 嘅完整 pipeline 就建成咗。
CC Pocket + opencode-bar:一個 Entry Point 嘅威力
CC Pocket 係 HAPI 推出嘅 iOS/Android app,表面係一個「快捷工具 launcher」,但你將佢同 opencode-bar(opencode 嘅 background service mode)結合之後,佢就變成咗你嘅 mobile development console。
實際 workflow 係咁:你喺 CC Pocket 度 create 一個 shortcut,入面寫好 template 嘅 prompt,例如「fix all TypeScript type errors in src/」或者「refactor utils.ts to use async/await」。然後你只要喺手機㩒個掣,CC Pocket 會 send 個 trigger 去 HAPI,HAPI forward 去你 server,opencode-bar(長行嘅 daemon process)接到 task,開始執行。
呢個 setup 嘅殺手鐧係 asynchronous execution。你唔使等佢 response。Send 完個 task,你可以熄 mon,繼續做你嘅嘢。OpenCode agent 會 autonomously 咁 reading codebase、寫 code、run tests、commit changes。做完之後可以 set 佢 send push notification 俾你,或者直接 push 上 GitHub。我甚至 set 咗一個 post-task hook:如果 test pass 就自動開 PR,如果 fail 就直接 rollback。成個 process 唔使任何人手干預。
點解呢個 Pattern 係 Game Changer
你可能會問:有咩咁特別?用 Termius SSH 入 server 打 command 唔係一樣咩?分別好大。第一,你唔需要開一個 persistent SSH session。Mobile network 唔穩定,SSH 斷線係家常便飯,斷咗你個 execution 就會 hang 住。OpenCode agent 喺 server-side 行,你 send 完 task 個 connection 就 close,agent 繼續跑,network 問題完全隔離。
第二,呢個 workflow 將你嘅 cognitive load 降到最低。你唔使諗「點樣 fix 個 bug」,你只需要判斷「呢個 bug 應該 fix」。details 交俾 AI agent。呢個係 programming 本質嘅轉變:我哋由「寫 code 嘅人」變成「審 code、定方向嘅人」。
第三,呢個 setup 係 extensible 嘅。我除咗寫 code task,仲 set 咗 deploy trigger、DB migration、monitoring alert 嘅 auto-response。例如當我收到 Grafana alert 話 server CPU 爆咗,我喺手機㩒一嘢「scale up worker」,agent 就會自動去 AWS console 做 scaling。唔使開 laptop,唔使 login AWS console。
實施建議俾香港嘅 Developer
如果你想試呢個 workflow,我建議你由最簡單嘅嘢開始。第一步:喺你嘅 VPS 或 home server 裝好 opencode 同 opencode-bar。第二步:開一個好簡單嘅 webhook server(十幾行 code 嗰啲)。第三步:用 CC Pocket 開一個 account,create 一個 shortcut,target 你個 webhook。第四步:由一個細 task 開始試,例如「add comments to all functions in models/」。唔好一步就想搞大 project。
安全方面有幾點要注意:第一,你一定要喺 webhook 加 authentication token,唔好 expose 一個 open endpoint 出街。第二,建議你用一個 isolated 嘅 Git branch 嚟行 AI agent 嘅 commit,唔好直接改 main。第三,set 好 rate limit,唔好俾人亂 call 你個 endpoint。
長遠嚟講,我認為呢個 pattern 會改變我哋對「開發環境」嘅定義。Development environment 唔再係一部裝滿 tooling 嘅 laptop,而係一個由你手機可以隨時 trigger 嘅 agent service。你嘅生產力唔再受 physical device 限制,而係取決於你嘅抽象能力同 task decomposition 能力。香港咁講求 efficiency 嘅地方,呢套嘢好值得一試。