Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions agent_reach/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,21 +913,7 @@ def _cmd_configure(args):
# Accept two formats:
# 1. auth_token ct0 (two separate values)
# 2. Full cookie header string: "auth_token=xxx; ct0=yyy; ..."
auth_token = None
ct0 = None

if "auth_token=" in value and "ct0=" in value:
# Full cookie string β€” parse it
for part in value.replace(";", " ").split():
if part.startswith("auth_token="):
auth_token = part.split("=", 1)[1]
elif part.startswith("ct0="):
ct0 = part.split("=", 1)[1]
elif len(value.split()) == 2 and "=" not in value:
# Two separate values: AUTH_TOKEN CT0
parts = value.split()
auth_token = parts[0]
ct0 = parts[1]
auth_token, ct0 = _parse_twitter_cookie_input(value)

if auth_token and ct0:
config.set("twitter_auth_token", auth_token)
Expand Down Expand Up @@ -1009,6 +995,27 @@ def _cmd_configure(args):
print(f"βœ… Groq key configured!")


def _parse_twitter_cookie_input(value: str):
"""Parse Twitter cookie input from either separate values or a cookie header."""
auth_token = None
ct0 = None

if "auth_token=" in value and "ct0=" in value:
# Full cookie string β€” parse it.
for part in value.replace(";", " ").split():
if part.startswith("auth_token="):
auth_token = part.split("=", 1)[1]
elif part.startswith("ct0="):
ct0 = part.split("=", 1)[1]
elif len(value.split()) == 2 and "=" not in value:
# Two separate values: AUTH_TOKEN CT0.
parts = value.split()
auth_token = parts[0]
ct0 = parts[1]

return auth_token, ct0


def _configure_xhs_cookies(value):
"""Import cookies into xiaohongshu-mcp Docker container.

Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ def test_doctor_runs(self, capsys):
assert "Agent Reach" in captured.out
assert "βœ…" in captured.out

def test_parse_twitter_cookie_input_separate_values(self):
auth_token, ct0 = cli._parse_twitter_cookie_input("token123 ct0abc")
assert auth_token == "token123"
assert ct0 == "ct0abc"

def test_parse_twitter_cookie_input_cookie_header(self):
auth_token, ct0 = cli._parse_twitter_cookie_input(
"auth_token=token123; ct0=ct0abc; other=value"
)
assert auth_token == "token123"
assert ct0 == "ct0abc"


class TestCheckUpdateRetry:
def test_retry_timeout_classification(self):
Expand Down
Loading