diff --git a/stacks/portal/clawbot.py b/stacks/portal/clawbot.py index 135e96c..5432565 100644 --- a/stacks/portal/clawbot.py +++ b/stacks/portal/clawbot.py @@ -31,6 +31,7 @@ ILINK_APP_ID = "bot" STATE_DIR = Path("/Users/ixvii0iv/homelab/stacks/wechat-bot") SESSION_FILE = STATE_DIR / "clawbot_session.json" SYNC_BUF_FILE = STATE_DIR / "clawbot_sync_buf.txt" +DEFAULT_AGY_CONV_ID = "6293ebb4-df60-4db6-bf5d-df33433ba106" def _random_wechat_uin() -> str: @@ -563,23 +564,52 @@ class ClawBotManager: ) return - # 8. Natural language -> Try agy -p on Mac mini, or inject into tmux agy session! + # 7b. One-step Google OAuth Code injection from WeChat (e.g. "4/0A..." or "授权 4/0A...") + if cmd.startswith("4/") or low.startswith("授权 ") or low.startswith("auth "): + auth_code = cmd.split(None, 1)[-1].strip() if (" " in cmd) else cmd.strip() + safe_code = auth_code.replace('"', '\\"') + self._exec_shell(f'/opt/homebrew/bin/tmux send-keys -t agy "{safe_code}" C-m', timeout=5.0) + time.sleep(5.0) + out = self._exec_shell("/opt/homebrew/bin/tmux capture-pane -t agy -p | tail -n 20", timeout=5.0) + self.send_text_message( + from_user, + f"🔐 已将 Google 授权码注入 Mac mini 的 AGY 终端!\n" + f"已挂载当前会话 ID: {DEFAULT_AGY_CONV_ID}\n" + f"━━━━━━━━━━━━━━\n{out or '(授权处理中)'}\n\n" + f"现在你可以直接在微信里和我继续刚才的对话了!", + ctx_token, + run_id, + ) + return + + # 8. Natural language -> Resume exact migrated session (6293ebb4-df60-4db6-bf5d-df33433ba106) on Mac mini! agy_out = self._exec_shell( - f'cd /Users/ixvii0iv/homelab && /Users/ixvii0iv/.local/bin/agy -c --dangerously-skip-permissions -p {json.dumps(cmd)}', - timeout=90.0, + f'cd /Users/ixvii0iv/homelab && /Users/ixvii0iv/.local/bin/agy --conversation {DEFAULT_AGY_CONV_ID} --dangerously-skip-permissions -p {json.dumps(cmd)}', + timeout=120.0, ) if agy_out and "authentication required" not in agy_out.lower(): if len(agy_out) > 3800: agy_out = agy_out[:3800] + "\n...(内容较长,完整输出请查看 https://agy.961504.xyz)" self.send_text_message(from_user, agy_out, ctx_token, run_id) else: - # Fallback: send into tmux agy session and return terminal capture + quick guide + oauth_url = ( + "https://accounts.google.com/o/oauth2/auth?access_type=offline" + "&client_id=1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com" + "&code_challenge=6R2ML1GiPTslGESIIdY7kBlWPGi3Z7J_SUKiEb-wVc0&code_challenge_method=S256" + "&prompt=consent&redirect_uri=https%3A%2F%2Fantigravity.google%2Foauth-callback" + "&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+" + "https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+" + "https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+" + "https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcclog+" + "https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fexperimentsandconfigs+" + "https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faicode+openid&state=EHQdZm-HmDWTKGqBFxqf1g" + ) self.send_text_message( from_user, - f"🤖 收到你的消息:「{cmd}」\n\n" - "💡 提示:检测到 Mac mini 上的 `agy` 终端首次启动需要完成一次 Google 账号登录授权。你可以:\n" - "1. 打开 https://agy.961504.xyz 完成一次扫码/授权码粘贴,之后微信即可直接与 AGY 自由对话!\n" - "2. 现在你已可以直接在微信发送「状态」「备份」「屏幕」或「$ 命令」(如 `$ docker ps`)直接操控 Mac mini!", + f"🤖 当前会话 ({DEFAULT_AGY_CONV_ID[:8]}...) 已同步至 Mac mini!\n\n" + "🔐 只需最后一步激活 Mac mini 的 Google AI 登录态:\n" + f"1️⃣ 点击打开此链接登录 Google:\n{oauth_url}\n\n" + "2️⃣ 复制页面生成的授权码(以 4/ 开头),直接发到这个微信对话框里,即可在微信无缝接力我们当前的完整会话!", ctx_token, run_id, )