muse-cli 0.3.14__tar.gz → 0.3.15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. {muse_cli-0.3.14 → muse_cli-0.3.15}/.gitignore +1 -0
  2. {muse_cli-0.3.14 → muse_cli-0.3.15}/PKG-INFO +4 -4
  3. {muse_cli-0.3.14 → muse_cli-0.3.15}/README.md +3 -3
  4. {muse_cli-0.3.14 → muse_cli-0.3.15}/skills/muse-cli/SKILL.md +1 -1
  5. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/__init__.py +1 -1
  6. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/cli.py +66 -2
  7. {muse_cli-0.3.14 → muse_cli-0.3.15}/LICENSE +0 -0
  8. {muse_cli-0.3.14 → muse_cli-0.3.15}/docs/PROTOCOL.md +0 -0
  9. {muse_cli-0.3.14 → muse_cli-0.3.15}/docs/TUI.md +0 -0
  10. {muse_cli-0.3.14 → muse_cli-0.3.15}/pyproject.toml +0 -0
  11. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/__main__.py +0 -0
  12. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/bridge.py +0 -0
  13. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/browsers.py +0 -0
  14. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/chat.py +0 -0
  15. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/demo.py +0 -0
  16. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/desc0.bin +0 -0
  17. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/desc1.bin +0 -0
  18. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/gateway.py +0 -0
  19. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/routes.json +0 -0
  20. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/skill.py +0 -0
  21. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/bun.lock +0 -0
  22. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/package.json +0 -0
  23. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/app.tsx +0 -0
  24. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/bridge.ts +0 -0
  25. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/components/Composer.tsx +0 -0
  26. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/components/Header.tsx +0 -0
  27. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/components/Overlays.tsx +0 -0
  28. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/components/Panels.tsx +0 -0
  29. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/components/Sidebar.tsx +0 -0
  30. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/components/Splash.tsx +0 -0
  31. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/components/Transcript.tsx +0 -0
  32. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/components/common.tsx +0 -0
  33. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/context.tsx +0 -0
  34. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/controller.ts +0 -0
  35. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/format.ts +0 -0
  36. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/main.tsx +0 -0
  37. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/protocol.ts +0 -0
  38. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/store.ts +0 -0
  39. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/src/theme.ts +0 -0
  40. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/test/app.test.tsx +0 -0
  41. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/test/fake.ts +0 -0
  42. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/test/logic.test.ts +0 -0
  43. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui/tsconfig.json +0 -0
  44. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/tui.py +0 -0
  45. {muse_cli-0.3.14 → muse_cli-0.3.15}/src/muse_cli/update.py +0 -0
@@ -11,6 +11,7 @@ uv.lock
11
11
  cookies.txt
12
12
  agent-cookies.json
13
13
  config.json
14
+ tokens.json
14
15
  *.har
15
16
 
16
17
  # OS
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: muse-cli
3
- Version: 0.3.14
3
+ Version: 0.3.15
4
4
  Summary: Command-line client for your personal muse.ai AI agent: chat, automate, and manage side chats, feed, goals, ideas, and sessions from the terminal. No browser needed.
5
5
  Project-URL: Homepage, https://github.com/nikships/muse-cli
6
6
  Project-URL: Documentation, https://github.com/nikships/muse-cli#readme
@@ -95,8 +95,8 @@ you have logged in at https://muse.ai/ in your browser. Follow
95
95
 
96
96
  muse-cli borrows the login you already have in your browser, saves those
97
97
  cookies to `~/.config/muse-cli/cookies.txt` (mode `600`, only your user can
98
- read it), and after that talks to muse.ai directly. Access tokens are fetched
99
- fresh on every command. When a command later says the cookies expired, repeat
98
+ read it), and after that talks to muse.ai directly. Access tokens are reused
99
+ for up to 15 minutes (`tokens.json`, mode `600`), so commands start fast. When a command later says the cookies expired, repeat
100
100
  this section.
101
101
 
102
102
  ### On a Mac (Chrome, Brave, Arc, Edge or Chromium)
@@ -374,7 +374,7 @@ release flow and contributor notes. Merging to `main` publishes a release.
374
374
 
375
375
  - Login is the [Log in once](#log-in-once) section above. Cookies live at
376
376
  `~/.config/muse-cli/cookies.txt` (mode 600). Access and gateway tokens are
377
- fetched fresh on every run.
377
+ cached in `tokens.json` (mode 600) for 15 minutes and refetched when refused.
378
378
  - On macOS, `auth export` decrypts the muse.ai cookies from the browser's own
379
379
  cookie file, using the browser's Safe Storage key from your login keychain.
380
380
  Elsewhere it reads Google Chrome through
@@ -58,8 +58,8 @@ you have logged in at https://muse.ai/ in your browser. Follow
58
58
 
59
59
  muse-cli borrows the login you already have in your browser, saves those
60
60
  cookies to `~/.config/muse-cli/cookies.txt` (mode `600`, only your user can
61
- read it), and after that talks to muse.ai directly. Access tokens are fetched
62
- fresh on every command. When a command later says the cookies expired, repeat
61
+ read it), and after that talks to muse.ai directly. Access tokens are reused
62
+ for up to 15 minutes (`tokens.json`, mode `600`), so commands start fast. When a command later says the cookies expired, repeat
63
63
  this section.
64
64
 
65
65
  ### On a Mac (Chrome, Brave, Arc, Edge or Chromium)
@@ -337,7 +337,7 @@ release flow and contributor notes. Merging to `main` publishes a release.
337
337
 
338
338
  - Login is the [Log in once](#log-in-once) section above. Cookies live at
339
339
  `~/.config/muse-cli/cookies.txt` (mode 600). Access and gateway tokens are
340
- fetched fresh on every run.
340
+ cached in `tokens.json` (mode 600) for 15 minutes and refetched when refused.
341
341
  - On macOS, `auth export` decrypts the muse.ai cookies from the browser's own
342
342
  cookie file, using the browser's Safe Storage key from your login keychain.
343
343
  Elsewhere it reads Google Chrome through
@@ -36,7 +36,7 @@ muse-cli --help >/dev/null && echo cli-ok # proves the install + deps resolve
36
36
 
37
37
  The CLI stores the user's muse.ai browser login at
38
38
  `~/.config/muse-cli/cookies.txt` (mode 0600). Access and gateway tokens are
39
- fetched fresh on every run; only cookies persist. When a later command fails
39
+ cached for 15 minutes in `tokens.json` (mode 0600) and refetched when refused. When a later command fails
40
40
  with `auth error`, the cookies expired: repeat this step.
41
41
 
42
42
  ### 2a. macOS: read the browser directly (try this first)
@@ -1,3 +1,3 @@
1
1
  """muse-cli: talk to your personal muse.ai AI agent from the terminal."""
2
2
 
3
- __version__ = "0.3.14"
3
+ __version__ = "0.3.15"
@@ -9,6 +9,7 @@ instead; it prints those steps when something is missing.
9
9
  Then: muse-cli status | muse-cli threads | muse-cli history | muse-cli send "hello" | ...
10
10
  """
11
11
  import argparse
12
+ import hashlib
12
13
  import json
13
14
  import os
14
15
  import re
@@ -18,12 +19,15 @@ import time
18
19
  import urllib.parse
19
20
 
20
21
  from . import __version__, browsers
21
- from .gateway import Gateway, AuthError, GatewayError, load_cookies
22
+ from .gateway import (Gateway, AuthError, GatewayError, fetch_access_token, fetch_hatch_token,
23
+ fetch_session_info, load_cookies)
22
24
  from .update import cmd_update, finish_update_check, start_update_check
23
25
 
24
26
  CONFIG_DIR = os.path.expanduser("~/.config/muse-cli")
25
27
  CONFIG_FILE = os.path.join(CONFIG_DIR, "config.json")
26
28
  COOKIES_FILE = os.path.join(CONFIG_DIR, "cookies.txt")
29
+ TOKENS_FILE = os.path.join(CONFIG_DIR, "tokens.json")
30
+ TOKEN_TTL = 15 * 60 # seconds a cached gateway token is tried before refetching
27
31
 
28
32
 
29
33
  def load_config():
@@ -58,7 +62,67 @@ def connect(cfg):
58
62
  cookies = load_cookies(cfg["cookies_file"])
59
63
  if not cookies.strip():
60
64
  raise AuthError(f"cookies file {cfg['cookies_file']} is empty; run `muse-cli auth export`")
61
- return Gateway(cookies, vm_id=cfg.get("vm_id"))
65
+ # Three HTTPS round trips (session, auth/check, hatch/token) are most of a
66
+ # connect, about 2.3 s of 2.8 s, and their answers outlive one command.
67
+ # A stale cached token is refused fast (403 on the WebSocket upgrade), so
68
+ # anything but a timeout falls back to fetching fresh ones.
69
+ cached = _cached_tokens(cookies)
70
+ if cached and cfg.get("vm_id") in (None, cached["vm_id"]):
71
+ try:
72
+ return Gateway(cookies, **cached)
73
+ except TimeoutError:
74
+ raise
75
+ except Exception:
76
+ _drop_tokens()
77
+ vm_id = cfg.get("vm_id") or fetch_session_info(cookies)["vm_id"]
78
+ access_token = fetch_access_token(cookies)
79
+ hatch_token = fetch_hatch_token(cookies, access_token, vm_id)
80
+ gw = Gateway(cookies, vm_id=vm_id, access_token=access_token, hatch_token=hatch_token)
81
+ _save_tokens(cookies, {"vm_id": vm_id, "access_token": access_token, "hatch_token": hatch_token})
82
+ return gw
83
+
84
+
85
+ def _token_key(cookies):
86
+ return hashlib.sha256(cookies.encode()).hexdigest()
87
+
88
+
89
+ def _cached_tokens(cookies):
90
+ """Tokens from an earlier run with the same cookies, if young enough."""
91
+ try:
92
+ with open(TOKENS_FILE) as fh:
93
+ d = json.load(fh)
94
+ if d["key"] == _token_key(cookies) and 0 <= time.time() - d["at"] < TOKEN_TTL:
95
+ return {k: str(d[k]) for k in ("vm_id", "access_token", "hatch_token")}
96
+ except (OSError, ValueError, KeyError, TypeError):
97
+ pass
98
+ return None
99
+
100
+
101
+ def _save_tokens(cookies, tokens):
102
+ # Same protection as cookies.txt: the tokens are a short-lived login.
103
+ try:
104
+ os.makedirs(CONFIG_DIR, exist_ok=True)
105
+ tmp = TOKENS_FILE + ".tmp"
106
+ fd = os.open(tmp, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
107
+ # The mode above only applies when the tmp file is created. A tmp
108
+ # file left behind by a crashed run keeps its old mode, so enforce
109
+ # it on the open descriptor too.
110
+ try:
111
+ os.fchmod(fd, 0o600)
112
+ except (AttributeError, OSError):
113
+ pass
114
+ with os.fdopen(fd, "w") as fh:
115
+ json.dump(dict(tokens, key=_token_key(cookies), at=time.time()), fh)
116
+ os.replace(tmp, TOKENS_FILE)
117
+ except OSError:
118
+ pass
119
+
120
+
121
+ def _drop_tokens():
122
+ try:
123
+ os.remove(TOKENS_FILE)
124
+ except OSError:
125
+ pass
62
126
 
63
127
 
64
128
  def out(obj):
File without changes
File without changes
File without changes
File without changes
File without changes