muse-cli 0.3.14__tar.gz → 0.3.16__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.
- {muse_cli-0.3.14 → muse_cli-0.3.16}/.gitignore +1 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/PKG-INFO +30 -12
- {muse_cli-0.3.14 → muse_cli-0.3.16}/README.md +29 -11
- {muse_cli-0.3.14 → muse_cli-0.3.16}/docs/PROTOCOL.md +8 -1
- {muse_cli-0.3.14 → muse_cli-0.3.16}/skills/muse-cli/SKILL.md +9 -2
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/__init__.py +1 -1
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/browsers.py +83 -12
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/cli.py +87 -19
- {muse_cli-0.3.14 → muse_cli-0.3.16}/LICENSE +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/docs/TUI.md +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/pyproject.toml +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/__main__.py +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/bridge.py +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/chat.py +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/demo.py +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/desc0.bin +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/desc1.bin +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/gateway.py +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/routes.json +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/skill.py +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/bun.lock +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/package.json +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/app.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/bridge.ts +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/components/Composer.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/components/Header.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/components/Overlays.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/components/Panels.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/components/Sidebar.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/components/Splash.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/components/Transcript.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/components/common.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/context.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/controller.ts +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/format.ts +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/main.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/protocol.ts +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/store.ts +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/src/theme.ts +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/test/app.test.tsx +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/test/fake.ts +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/test/logic.test.ts +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui/tsconfig.json +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/tui.py +0 -0
- {muse_cli-0.3.14 → muse_cli-0.3.16}/src/muse_cli/update.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: muse-cli
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.16
|
|
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,10 +95,26 @@ 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
|
|
99
|
-
|
|
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
|
+
### Easiest, on any system: Firefox
|
|
103
|
+
|
|
104
|
+
1. Log in at https://muse.ai/ in Firefox.
|
|
105
|
+
2. Run:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
muse-cli auth export
|
|
109
|
+
muse-cli status
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Firefox keeps cookies unencrypted, so nothing else is needed: no Node.js, no
|
|
113
|
+
debugging port, no keychain prompt, and Firefox can stay open. Success looks
|
|
114
|
+
like `saved 10 muse.ai cookies to ... (from firefox (abc123.default-release))`.
|
|
115
|
+
Every Firefox profile is checked and the newest login wins. Container tabs and
|
|
116
|
+
private windows are not read. Force this route with `--browser firefox`.
|
|
117
|
+
|
|
102
118
|
### On a Mac (Chrome, Brave, Arc, Edge or Chromium)
|
|
103
119
|
|
|
104
120
|
1. Log in at https://muse.ai/ in your browser.
|
|
@@ -132,10 +148,11 @@ disk as it was. `muse-cli status` then prints JSON with your VM id, how many
|
|
|
132
148
|
chats you have, the unread count, and your identity. That means install and
|
|
133
149
|
login both worked.
|
|
134
150
|
|
|
135
|
-
### Linux
|
|
151
|
+
### Chrome on Linux or Windows, or Safari: agent-browser or by hand
|
|
136
152
|
|
|
137
|
-
Direct reading is macOS-only
|
|
138
|
-
|
|
153
|
+
Direct reading of Chromium browsers is macOS-only (Windows Chrome uses
|
|
154
|
+
app-bound encryption), and Safari is not supported. Without a Firefox login
|
|
155
|
+
(or with `muse-cli auth export --browser agent-browser`) the login
|
|
139
156
|
is read from a running Google Chrome through [agent-browser](https://github.com/vercel-labs/agent-browser).
|
|
140
157
|
Do the steps in order. Each one checks itself before you continue.
|
|
141
158
|
|
|
@@ -224,7 +241,7 @@ muse-cli status
|
|
|
224
241
|
muse-cli # full-screen app on a terminal with Bun, else the plain chat
|
|
225
242
|
muse-cli tui # the full-screen app (`--demo`: made-up data, no account)
|
|
226
243
|
muse-cli chat # plain line-by-line chat
|
|
227
|
-
muse-cli auth export --browser auto # import the browser login (
|
|
244
|
+
muse-cli auth export --browser auto # import the browser login (Firefox anywhere, Chromium on macOS)
|
|
228
245
|
muse-cli threads # main chat + side chats
|
|
229
246
|
muse-cli history --limit 5 # recent messages
|
|
230
247
|
muse-cli history --thread <session-id> --limit 5 # one side chat
|
|
@@ -355,7 +372,7 @@ src/muse_cli/
|
|
|
355
372
|
tui/ the full-screen app: TypeScript on OpenTUI and Bun
|
|
356
373
|
bridge.py JSON-lines bridge the app talks to muse.ai through
|
|
357
374
|
demo.py made-up data for `muse-cli tui --demo`
|
|
358
|
-
browsers.py reads the muse.ai login from Chromium browsers on macOS
|
|
375
|
+
browsers.py reads the muse.ai login from Firefox, or Chromium browsers on macOS
|
|
359
376
|
gateway.py gateway client (auth, Noise transport, subscriptions)
|
|
360
377
|
update.py daily update notice and `muse-cli update`
|
|
361
378
|
skill.py installs and refreshes the bundled agent skill
|
|
@@ -374,10 +391,11 @@ release flow and contributor notes. Merging to `main` publishes a release.
|
|
|
374
391
|
|
|
375
392
|
- Login is the [Log in once](#log-in-once) section above. Cookies live at
|
|
376
393
|
`~/.config/muse-cli/cookies.txt` (mode 600). Access and gateway tokens are
|
|
377
|
-
|
|
378
|
-
- On
|
|
379
|
-
|
|
380
|
-
|
|
394
|
+
cached in `tokens.json` (mode 600) for 15 minutes and refetched when refused.
|
|
395
|
+
- On every system, `auth export` reads Firefox's `cookies.sqlite`, which holds
|
|
396
|
+
plain values. On macOS it first decrypts the muse.ai cookies from Chromium
|
|
397
|
+
browsers' cookie files, using the browser's Safe Storage key from your login
|
|
398
|
+
keychain. Without either login it reads Google Chrome through
|
|
381
399
|
[agent-browser](https://github.com/vercel-labs/agent-browser), which needs
|
|
382
400
|
Chrome open with remote debugging on (`chrome://inspect/#remote-debugging`)
|
|
383
401
|
and a logged-in muse.ai tab in front.
|
|
@@ -58,10 +58,26 @@ 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
|
|
62
|
-
|
|
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
|
+
### Easiest, on any system: Firefox
|
|
66
|
+
|
|
67
|
+
1. Log in at https://muse.ai/ in Firefox.
|
|
68
|
+
2. Run:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
muse-cli auth export
|
|
72
|
+
muse-cli status
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Firefox keeps cookies unencrypted, so nothing else is needed: no Node.js, no
|
|
76
|
+
debugging port, no keychain prompt, and Firefox can stay open. Success looks
|
|
77
|
+
like `saved 10 muse.ai cookies to ... (from firefox (abc123.default-release))`.
|
|
78
|
+
Every Firefox profile is checked and the newest login wins. Container tabs and
|
|
79
|
+
private windows are not read. Force this route with `--browser firefox`.
|
|
80
|
+
|
|
65
81
|
### On a Mac (Chrome, Brave, Arc, Edge or Chromium)
|
|
66
82
|
|
|
67
83
|
1. Log in at https://muse.ai/ in your browser.
|
|
@@ -95,10 +111,11 @@ disk as it was. `muse-cli status` then prints JSON with your VM id, how many
|
|
|
95
111
|
chats you have, the unread count, and your identity. That means install and
|
|
96
112
|
login both worked.
|
|
97
113
|
|
|
98
|
-
### Linux
|
|
114
|
+
### Chrome on Linux or Windows, or Safari: agent-browser or by hand
|
|
99
115
|
|
|
100
|
-
Direct reading is macOS-only
|
|
101
|
-
|
|
116
|
+
Direct reading of Chromium browsers is macOS-only (Windows Chrome uses
|
|
117
|
+
app-bound encryption), and Safari is not supported. Without a Firefox login
|
|
118
|
+
(or with `muse-cli auth export --browser agent-browser`) the login
|
|
102
119
|
is read from a running Google Chrome through [agent-browser](https://github.com/vercel-labs/agent-browser).
|
|
103
120
|
Do the steps in order. Each one checks itself before you continue.
|
|
104
121
|
|
|
@@ -187,7 +204,7 @@ muse-cli status
|
|
|
187
204
|
muse-cli # full-screen app on a terminal with Bun, else the plain chat
|
|
188
205
|
muse-cli tui # the full-screen app (`--demo`: made-up data, no account)
|
|
189
206
|
muse-cli chat # plain line-by-line chat
|
|
190
|
-
muse-cli auth export --browser auto # import the browser login (
|
|
207
|
+
muse-cli auth export --browser auto # import the browser login (Firefox anywhere, Chromium on macOS)
|
|
191
208
|
muse-cli threads # main chat + side chats
|
|
192
209
|
muse-cli history --limit 5 # recent messages
|
|
193
210
|
muse-cli history --thread <session-id> --limit 5 # one side chat
|
|
@@ -318,7 +335,7 @@ src/muse_cli/
|
|
|
318
335
|
tui/ the full-screen app: TypeScript on OpenTUI and Bun
|
|
319
336
|
bridge.py JSON-lines bridge the app talks to muse.ai through
|
|
320
337
|
demo.py made-up data for `muse-cli tui --demo`
|
|
321
|
-
browsers.py reads the muse.ai login from Chromium browsers on macOS
|
|
338
|
+
browsers.py reads the muse.ai login from Firefox, or Chromium browsers on macOS
|
|
322
339
|
gateway.py gateway client (auth, Noise transport, subscriptions)
|
|
323
340
|
update.py daily update notice and `muse-cli update`
|
|
324
341
|
skill.py installs and refreshes the bundled agent skill
|
|
@@ -337,10 +354,11 @@ release flow and contributor notes. Merging to `main` publishes a release.
|
|
|
337
354
|
|
|
338
355
|
- Login is the [Log in once](#log-in-once) section above. Cookies live at
|
|
339
356
|
`~/.config/muse-cli/cookies.txt` (mode 600). Access and gateway tokens are
|
|
340
|
-
|
|
341
|
-
- On
|
|
342
|
-
|
|
343
|
-
|
|
357
|
+
cached in `tokens.json` (mode 600) for 15 minutes and refetched when refused.
|
|
358
|
+
- On every system, `auth export` reads Firefox's `cookies.sqlite`, which holds
|
|
359
|
+
plain values. On macOS it first decrypts the muse.ai cookies from Chromium
|
|
360
|
+
browsers' cookie files, using the browser's Safe Storage key from your login
|
|
361
|
+
keychain. Without either login it reads Google Chrome through
|
|
344
362
|
[agent-browser](https://github.com/vercel-labs/agent-browser), which needs
|
|
345
363
|
Chrome open with remote debugging on (`chrome://inspect/#remote-debugging`)
|
|
346
364
|
and a logged-in muse.ai tab in front.
|
|
@@ -194,7 +194,14 @@ chat / feed / goals / ideas / sessions / ...
|
|
|
194
194
|
keys and keychain failures per browser to avoid repeated prompts.
|
|
195
195
|
Select only host keys `muse.ai` and `.muse.ai`: subdomain-only cookies are
|
|
196
196
|
not valid for the CLI's requests to `https://muse.ai/api/`.
|
|
197
|
-
-
|
|
197
|
+
- `auth export` reads Firefox on every system (after Chromium on macOS):
|
|
198
|
+
`<profiles root>/*/cookies.sqlite`, table `moz_cookies`, plain `value`,
|
|
199
|
+
host `muse.ai`/`.muse.ai`, `originAttributes = ''` (default container).
|
|
200
|
+
`expiry` is milliseconds in current Firefox, seconds in older releases.
|
|
201
|
+
Roots: `%APPDATA%\Mozilla\Firefox\Profiles`, `~/Library/Application
|
|
202
|
+
Support/Firefox/Profiles`, `~/.mozilla/firefox` (plus snap and flatpak).
|
|
203
|
+
The newest unexpired `hatch_sess` across profiles wins.
|
|
204
|
+
- Without those (and with `--browser agent-browser`) `auth export` reads cookies
|
|
198
205
|
from the user's own Google Chrome through agent-browser `--auto-connect`.
|
|
199
206
|
Chrome 144+ shares that profile only after remote debugging is enabled at
|
|
200
207
|
`chrome://inspect/#remote-debugging`. That export follows the active tab, so
|
|
@@ -36,9 +36,15 @@ 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
|
-
|
|
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
|
+
Easiest on any system: if the user uses Firefox, ask them to log in at
|
|
43
|
+
https://muse.ai/ there and confirm, then run `muse-cli auth export` (no
|
|
44
|
+
prompt, no Node.js; Firefox may stay open). Success ends with
|
|
45
|
+
`(from firefox (<profile>))`. Force it with `--browser firefox`. Plain
|
|
46
|
+
`auth export` already tries Firefox, after Chromium browsers on macOS.
|
|
47
|
+
|
|
42
48
|
### 2a. macOS: read the browser directly (try this first)
|
|
43
49
|
|
|
44
50
|
Needs no Node.js and no debugging port. The user must be logged in at
|
|
@@ -69,7 +75,8 @@ cookie values are never printed; do not print the cookies file either.
|
|
|
69
75
|
- Only cookies valid for `muse.ai` are exported, not subdomain-only cookies.
|
|
70
76
|
- `cookie database changed while reading ...`: close that browser and rerun
|
|
71
77
|
once. The command retries a changing database at most three times.
|
|
72
|
-
- On Linux or Windows, or if the Mac route is not
|
|
78
|
+
- On Linux or Windows without a Firefox login, or if the Mac route is not
|
|
79
|
+
possible, use 2b.
|
|
73
80
|
|
|
74
81
|
### 2b. Other systems: cookie reader (agent-browser)
|
|
75
82
|
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
"""Read the muse.ai login straight from a
|
|
1
|
+
"""Read the muse.ai login straight from a browser's cookie store.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Firefox, on every system: cookies.sqlite holds plain values, so nothing needs
|
|
4
|
+
decrypting.
|
|
5
|
+
|
|
6
|
+
Chromium browsers, macOS only: values are AES-128-CBC encrypted with a key
|
|
7
|
+
derived from the browser's "Safe Storage" password in the login keychain, so
|
|
8
|
+
macOS asks the user once before `security` may read it. (Windows Chromium uses
|
|
9
|
+
app-bound encryption that only the browser itself can undo.)
|
|
10
|
+
|
|
11
|
+
Nothing here needs Node.js or a debugging port, and the browser can stay closed.
|
|
7
12
|
"""
|
|
8
13
|
import ctypes
|
|
14
|
+
import glob
|
|
9
15
|
import hashlib
|
|
10
16
|
import os
|
|
11
17
|
import shutil
|
|
@@ -28,6 +34,12 @@ BROWSERS = {
|
|
|
28
34
|
|
|
29
35
|
KEYCHAIN_WAIT = 120 # seconds; macOS shows an Allow dialog the first time
|
|
30
36
|
|
|
37
|
+
CHROMIUM_SQL = ("SELECT host_key, name, path, is_secure, expires_utc, value, encrypted_value "
|
|
38
|
+
"FROM cookies WHERE host_key IN ('muse.ai', '.muse.ai')")
|
|
39
|
+
# Default container only: container tabs keep a second copy of each cookie.
|
|
40
|
+
FIREFOX_SQL = ("SELECT host, name, path, isSecure, expiry, value FROM moz_cookies "
|
|
41
|
+
"WHERE host IN ('muse.ai', '.muse.ai') AND originAttributes = ''")
|
|
42
|
+
|
|
31
43
|
|
|
32
44
|
class BrowserCookieError(RuntimeError):
|
|
33
45
|
pass
|
|
@@ -72,8 +84,53 @@ def _file_stamp(path):
|
|
|
72
84
|
return s.st_ino, s.st_size, s.st_mtime_ns, s.st_ctime_ns
|
|
73
85
|
|
|
74
86
|
|
|
75
|
-
def
|
|
76
|
-
"""
|
|
87
|
+
def firefox_roots():
|
|
88
|
+
"""Directories that hold Firefox profile folders on this system."""
|
|
89
|
+
if sys.platform == "win32":
|
|
90
|
+
return [os.path.join(os.environ.get("APPDATA", ""), "Mozilla", "Firefox", "Profiles")]
|
|
91
|
+
if sys.platform == "darwin":
|
|
92
|
+
return [os.path.join(SUPPORT, "Firefox", "Profiles")]
|
|
93
|
+
home = os.path.expanduser("~")
|
|
94
|
+
return [os.path.join(home, rel) for rel in (
|
|
95
|
+
".mozilla/firefox", "snap/firefox/common/.mozilla/firefox",
|
|
96
|
+
".var/app/org.mozilla.firefox/.mozilla/firefox")]
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _firefox_expires(expiry):
|
|
100
|
+
# Newer Firefox stores milliseconds, older seconds; 0 marks a session cookie.
|
|
101
|
+
return int(expiry / 1000 if expiry > 1e11 else expiry or 0)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def read_firefox_cookies():
|
|
105
|
+
"""(jar, source) from the Firefox profile with the newest muse.ai login."""
|
|
106
|
+
paths = sorted(p for root in firefox_roots()
|
|
107
|
+
for p in glob.glob(os.path.join(glob.escape(root), "*", "cookies.sqlite")))
|
|
108
|
+
if not paths:
|
|
109
|
+
raise BrowserCookieError("no Firefox profile found")
|
|
110
|
+
now = time.time()
|
|
111
|
+
best, errors = None, []
|
|
112
|
+
for path in paths:
|
|
113
|
+
try:
|
|
114
|
+
rows = _muse_rows(path, FIREFOX_SQL)
|
|
115
|
+
except BrowserCookieError as e:
|
|
116
|
+
errors.append(str(e))
|
|
117
|
+
continue
|
|
118
|
+
jar = [{"name": name, "domain": host, "path": cpath or "/", "secure": bool(secure),
|
|
119
|
+
"expires": _firefox_expires(expiry), "value": value or ""}
|
|
120
|
+
for host, name, cpath, secure, expiry, value in rows]
|
|
121
|
+
jar = [c for c in jar if not c["expires"] or c["expires"] > now]
|
|
122
|
+
sess = [c["expires"] or float("inf") for c in jar if c["name"] == "hatch_sess" and c["value"]]
|
|
123
|
+
if sess and (best is None or max(sess) > best[0]):
|
|
124
|
+
best = (max(sess), jar, path)
|
|
125
|
+
if best:
|
|
126
|
+
return best[1], f"firefox ({os.path.basename(os.path.dirname(best[2]))})"
|
|
127
|
+
if errors:
|
|
128
|
+
raise BrowserCookieError("; ".join(errors))
|
|
129
|
+
raise BrowserCookieError("no muse.ai login (hatch_sess) in Firefox")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _muse_rows(path, sql=CHROMIUM_SQL):
|
|
133
|
+
"""muse.ai rows from a copy of the database (the browser locks the original)."""
|
|
77
134
|
paths = [path, path + "-wal", path + "-journal"]
|
|
78
135
|
try:
|
|
79
136
|
for _ in range(3):
|
|
@@ -92,9 +149,7 @@ def _muse_rows(path):
|
|
|
92
149
|
continue
|
|
93
150
|
db = sqlite3.connect(copy)
|
|
94
151
|
try:
|
|
95
|
-
return db.execute(
|
|
96
|
-
"SELECT host_key, name, path, is_secure, expires_utc, value, encrypted_value "
|
|
97
|
-
"FROM cookies WHERE host_key IN ('muse.ai', '.muse.ai')").fetchall()
|
|
152
|
+
return db.execute(sql).fetchall()
|
|
98
153
|
finally:
|
|
99
154
|
db.close()
|
|
100
155
|
except (OSError, sqlite3.Error) as e:
|
|
@@ -156,10 +211,26 @@ def read_cookies(browser="auto", key_for=_safe_storage_key, decrypt=_aes_cbc_dec
|
|
|
156
211
|
jar entries match what `auth export` writes: name, value, domain, path,
|
|
157
212
|
secure, expires. The keychain is asked only once a profile with an
|
|
158
213
|
unexpired `hatch_sess` row is found, so a browser without a muse.ai login never
|
|
159
|
-
triggers a prompt.
|
|
214
|
+
triggers a prompt. `auto` tries Chromium browsers first on macOS, then
|
|
215
|
+
Firefox. Raises BrowserCookieError with a reason otherwise.
|
|
160
216
|
"""
|
|
217
|
+
if browser == "firefox" or (browser == "auto" and not supported()):
|
|
218
|
+
return read_firefox_cookies()
|
|
161
219
|
if not supported():
|
|
162
|
-
raise BrowserCookieError("reading
|
|
220
|
+
raise BrowserCookieError("reading Chromium browsers directly is macOS-only; "
|
|
221
|
+
"use --browser firefox or agent-browser")
|
|
222
|
+
try:
|
|
223
|
+
return _read_chromium(browser, key_for, decrypt)
|
|
224
|
+
except BrowserCookieError as e:
|
|
225
|
+
if browser != "auto":
|
|
226
|
+
raise
|
|
227
|
+
try:
|
|
228
|
+
return read_firefox_cookies()
|
|
229
|
+
except BrowserCookieError as ff:
|
|
230
|
+
raise BrowserCookieError(f"{e}; {ff}") from None
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _read_chromium(browser, key_for, decrypt):
|
|
163
234
|
names = None if browser == "auto" else [browser]
|
|
164
235
|
stores = cookie_stores(names)
|
|
165
236
|
if not stores:
|
|
@@ -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,
|
|
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
|
-
|
|
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):
|
|
@@ -261,9 +325,14 @@ def _browser_cookies():
|
|
|
261
325
|
def _print_need_browser_login(err):
|
|
262
326
|
print(f"Could not read a muse.ai login from your browser: {err}", file=sys.stderr)
|
|
263
327
|
print(file=sys.stderr)
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
328
|
+
if browsers.supported():
|
|
329
|
+
print("Log in at https://muse.ai/ in Firefox, Chrome, Brave, Arc or Edge, then run", file=sys.stderr)
|
|
330
|
+
print("`muse-cli auth export` again. macOS may ask to let `security` use", file=sys.stderr)
|
|
331
|
+
print("the browser's Safe Storage key; click Allow.", file=sys.stderr)
|
|
332
|
+
else:
|
|
333
|
+
print("Log in at https://muse.ai/ in Firefox, then run `muse-cli auth export` again.",
|
|
334
|
+
file=sys.stderr)
|
|
335
|
+
print("Firefox can stay open, and nothing else needs installing.", file=sys.stderr)
|
|
267
336
|
print(file=sys.stderr)
|
|
268
337
|
_print_hand_copy()
|
|
269
338
|
|
|
@@ -272,7 +341,7 @@ def cmd_auth_export(args):
|
|
|
272
341
|
os.makedirs(CONFIG_DIR, exist_ok=True)
|
|
273
342
|
choice = getattr(args, "browser", None) or "auto"
|
|
274
343
|
jar, source = None, "Chrome"
|
|
275
|
-
if choice != "agent-browser"
|
|
344
|
+
if choice != "agent-browser":
|
|
276
345
|
print("Reading muse.ai cookies from your browser...", file=sys.stderr)
|
|
277
346
|
try:
|
|
278
347
|
jar, source = browsers.read_cookies(choice)
|
|
@@ -284,10 +353,6 @@ def cmd_auth_export(args):
|
|
|
284
353
|
_print_need_browser_login(e)
|
|
285
354
|
sys.exit(1)
|
|
286
355
|
print(f"({e}; trying agent-browser)", file=sys.stderr)
|
|
287
|
-
elif choice not in ("auto", "agent-browser"):
|
|
288
|
-
print("cookie export failed: reading browser cookies directly is macOS-only; "
|
|
289
|
-
"use --browser agent-browser", file=sys.stderr)
|
|
290
|
-
sys.exit(1)
|
|
291
356
|
if jar is None:
|
|
292
357
|
if shutil.which("agent-browser") is None:
|
|
293
358
|
_print_need_agent_browser()
|
|
@@ -1154,16 +1219,19 @@ def build_parser():
|
|
|
1154
1219
|
"Copy your muse.ai login out of your browser into\n"
|
|
1155
1220
|
"~/.config/muse-cli/cookies.txt (mode 600).\n"
|
|
1156
1221
|
"\n"
|
|
1157
|
-
"
|
|
1158
|
-
"
|
|
1159
|
-
"
|
|
1160
|
-
"
|
|
1161
|
-
"
|
|
1222
|
+
"Easiest on every system: log in at https://muse.ai/ in Firefox, then run\n"
|
|
1223
|
+
"this command. Nothing else needs installing, and Firefox can stay open.\n"
|
|
1224
|
+
"\n"
|
|
1225
|
+
"On macOS it also reads Chrome, Brave, Arc, Edge or Chromium directly\n"
|
|
1226
|
+
"(tried before Firefox). macOS asks once to let `security` use the\n"
|
|
1227
|
+
"browser's Safe Storage key; click Allow. No Node.js or debugging port\n"
|
|
1228
|
+
"is needed, and the browser can be closed.\n"
|
|
1162
1229
|
"Unreadable profiles are skipped if another has a usable login.\n"
|
|
1163
1230
|
"Subdomain-only cookies are not exported.\n"
|
|
1164
1231
|
"Empty or expired login cookies never replace a saved login.\n"
|
|
1165
1232
|
"\n"
|
|
1166
|
-
"
|
|
1233
|
+
"Without a Firefox login (and on macOS no Chromium one), or with\n"
|
|
1234
|
+
"--browser agent-browser, it reads Google Chrome through\n"
|
|
1167
1235
|
"agent-browser. Chrome shares those cookies only after remote debugging is on.\n"
|
|
1168
1236
|
"In the Chrome window you already use for muse.ai:\n"
|
|
1169
1237
|
"\n"
|
|
@@ -1187,9 +1255,9 @@ def build_parser():
|
|
|
1187
1255
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
1188
1256
|
)
|
|
1189
1257
|
p.add_argument("--browser", default="auto",
|
|
1190
|
-
choices=["auto", *browsers.BROWSERS, "agent-browser"],
|
|
1191
|
-
help="where to read the login (default: auto =
|
|
1192
|
-
"
|
|
1258
|
+
choices=["auto", "firefox", *browsers.BROWSERS, "agent-browser"],
|
|
1259
|
+
help="where to read the login (default: auto = Chromium browsers "
|
|
1260
|
+
"on macOS, then Firefox, then agent-browser)")
|
|
1193
1261
|
p.set_defaults(fn=cmd_auth_export)
|
|
1194
1262
|
|
|
1195
1263
|
sub.add_parser("chat", help="plain line-by-line chat (the default with no command "
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|