muse-cli 0.3.15__tar.gz → 0.3.17__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 (48) hide show
  1. {muse_cli-0.3.15 → muse_cli-0.3.17}/PKG-INFO +35 -15
  2. {muse_cli-0.3.15 → muse_cli-0.3.17}/README.md +32 -12
  3. {muse_cli-0.3.15 → muse_cli-0.3.17}/docs/PROTOCOL.md +12 -3
  4. {muse_cli-0.3.15 → muse_cli-0.3.17}/docs/TUI.md +19 -3
  5. {muse_cli-0.3.15 → muse_cli-0.3.17}/pyproject.toml +3 -3
  6. {muse_cli-0.3.15 → muse_cli-0.3.17}/skills/muse-cli/SKILL.md +8 -1
  7. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/__init__.py +1 -1
  8. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/bridge.py +8 -0
  9. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/browsers.py +83 -12
  10. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/cli.py +21 -17
  11. muse_cli-0.3.17/src/muse_cli/tui/bun.lock +126 -0
  12. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/package.json +6 -6
  13. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/app.tsx +82 -32
  14. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/components/Composer.tsx +52 -44
  15. muse_cli-0.3.17/src/muse_cli/tui/src/components/Header.tsx +56 -0
  16. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/components/Overlays.tsx +88 -65
  17. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/components/Panels.tsx +222 -70
  18. muse_cli-0.3.17/src/muse_cli/tui/src/components/Sidebar.tsx +153 -0
  19. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/components/Transcript.tsx +38 -46
  20. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/components/common.tsx +3 -3
  21. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/context.tsx +8 -8
  22. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/controller.ts +3 -3
  23. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/format.ts +14 -0
  24. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/store.ts +10 -9
  25. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/theme.ts +20 -22
  26. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/test/app.test.tsx +10 -10
  27. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/test/logic.test.ts +14 -7
  28. muse_cli-0.3.15/src/muse_cli/tui/bun.lock +0 -86
  29. muse_cli-0.3.15/src/muse_cli/tui/src/components/Header.tsx +0 -64
  30. muse_cli-0.3.15/src/muse_cli/tui/src/components/Sidebar.tsx +0 -122
  31. {muse_cli-0.3.15 → muse_cli-0.3.17}/.gitignore +0 -0
  32. {muse_cli-0.3.15 → muse_cli-0.3.17}/LICENSE +0 -0
  33. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/__main__.py +0 -0
  34. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/chat.py +0 -0
  35. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/demo.py +0 -0
  36. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/desc0.bin +0 -0
  37. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/desc1.bin +0 -0
  38. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/gateway.py +0 -0
  39. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/routes.json +0 -0
  40. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/skill.py +0 -0
  41. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/bridge.ts +0 -0
  42. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/components/Splash.tsx +0 -0
  43. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/main.tsx +0 -0
  44. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/src/protocol.ts +0 -0
  45. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/test/fake.ts +0 -0
  46. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui/tsconfig.json +0 -0
  47. {muse_cli-0.3.15 → muse_cli-0.3.17}/src/muse_cli/tui.py +0 -0
  48. {muse_cli-0.3.15 → muse_cli-0.3.17}/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.15
3
+ Version: 0.3.17
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
@@ -31,8 +31,8 @@ Classifier: Topic :: Terminals
31
31
  Classifier: Topic :: Utilities
32
32
  Requires-Python: >=3.10
33
33
  Requires-Dist: curl-cffi>=0.17
34
- Requires-Dist: noiseprotocol>=0.3
35
- Requires-Dist: protobuf>=5.0
34
+ Requires-Dist: noiseprotocol>=0.3.1
35
+ Requires-Dist: protobuf>=7.36.2
36
36
  Description-Content-Type: text/markdown
37
37
 
38
38
  <div align="center">
@@ -99,6 +99,22 @@ read it), and after that talks to muse.ai directly. Access tokens are reused
99
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, Windows, or Safari: agent-browser or by hand
151
+ ### Chrome on Linux or Windows, or Safari: agent-browser or by hand
136
152
 
137
- Direct reading is macOS-only and covers Chromium browsers, not Safari.
138
- Elsewhere (or with `muse-cli auth export --browser agent-browser`) the login
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 (macOS: direct read)
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
@@ -273,10 +290,12 @@ On a terminal, `muse-cli` opens a full-screen app built on
273
290
  The first run copies the app to `~/.cache/muse-cli/tui` and installs its
274
291
  dependencies, which takes a few seconds once per release.
275
292
 
276
- - Replies stream in as they arrive, with Markdown, code blocks and file chips.
277
- Press Enter on a file to save it to `~/Downloads/muse`.
278
- - Your chats sit on the left. `Tab` moves between them and the message box,
279
- `Ctrl+N` starts a side chat.
293
+ - Replies stream in as they arrive, with Markdown, code blocks and attachments.
294
+ Click Download in a reply, or press Enter on a file in the Files tab, to
295
+ save it to `~/Downloads/muse`.
296
+ - `Tab` focuses the chat list. When it isn't docked, it opens over the current
297
+ view without rewrapping it. `Ctrl+B` pins or hides the list; `Ctrl+N` starts
298
+ a side chat.
280
299
  - `Ctrl+K` jumps to any chat, space or action. `Alt+1` to `Alt+7` open Chat,
281
300
  Feed, Goals, Ideas, Tasks, Mail and Files. Type `/` for commands, `F1` for
282
301
  every shortcut.
@@ -355,7 +374,7 @@ src/muse_cli/
355
374
  tui/ the full-screen app: TypeScript on OpenTUI and Bun
356
375
  bridge.py JSON-lines bridge the app talks to muse.ai through
357
376
  demo.py made-up data for `muse-cli tui --demo`
358
- browsers.py reads the muse.ai login from Chromium browsers on macOS
377
+ browsers.py reads the muse.ai login from Firefox, or Chromium browsers on macOS
359
378
  gateway.py gateway client (auth, Noise transport, subscriptions)
360
379
  update.py daily update notice and `muse-cli update`
361
380
  skill.py installs and refreshes the bundled agent skill
@@ -375,9 +394,10 @@ release flow and contributor notes. Merging to `main` publishes a release.
375
394
  - Login is the [Log in once](#log-in-once) section above. Cookies live at
376
395
  `~/.config/muse-cli/cookies.txt` (mode 600). Access and gateway tokens are
377
396
  cached in `tokens.json` (mode 600) for 15 minutes and refetched when refused.
378
- - On macOS, `auth export` decrypts the muse.ai cookies from the browser's own
379
- cookie file, using the browser's Safe Storage key from your login keychain.
380
- Elsewhere it reads Google Chrome through
397
+ - On every system, `auth export` reads Firefox's `cookies.sqlite`, which holds
398
+ plain values. On macOS it first decrypts the muse.ai cookies from Chromium
399
+ browsers' cookie files, using the browser's Safe Storage key from your login
400
+ keychain. Without either login it reads Google Chrome through
381
401
  [agent-browser](https://github.com/vercel-labs/agent-browser), which needs
382
402
  Chrome open with remote debugging on (`chrome://inspect/#remote-debugging`)
383
403
  and a logged-in muse.ai tab in front.
@@ -62,6 +62,22 @@ read it), and after that talks to muse.ai directly. Access tokens are reused
62
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, Windows, or Safari: agent-browser or by hand
114
+ ### Chrome on Linux or Windows, or Safari: agent-browser or by hand
99
115
 
100
- Direct reading is macOS-only and covers Chromium browsers, not Safari.
101
- Elsewhere (or with `muse-cli auth export --browser agent-browser`) the login
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 (macOS: direct read)
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
@@ -236,10 +253,12 @@ On a terminal, `muse-cli` opens a full-screen app built on
236
253
  The first run copies the app to `~/.cache/muse-cli/tui` and installs its
237
254
  dependencies, which takes a few seconds once per release.
238
255
 
239
- - Replies stream in as they arrive, with Markdown, code blocks and file chips.
240
- Press Enter on a file to save it to `~/Downloads/muse`.
241
- - Your chats sit on the left. `Tab` moves between them and the message box,
242
- `Ctrl+N` starts a side chat.
256
+ - Replies stream in as they arrive, with Markdown, code blocks and attachments.
257
+ Click Download in a reply, or press Enter on a file in the Files tab, to
258
+ save it to `~/Downloads/muse`.
259
+ - `Tab` focuses the chat list. When it isn't docked, it opens over the current
260
+ view without rewrapping it. `Ctrl+B` pins or hides the list; `Ctrl+N` starts
261
+ a side chat.
243
262
  - `Ctrl+K` jumps to any chat, space or action. `Alt+1` to `Alt+7` open Chat,
244
263
  Feed, Goals, Ideas, Tasks, Mail and Files. Type `/` for commands, `F1` for
245
264
  every shortcut.
@@ -318,7 +337,7 @@ src/muse_cli/
318
337
  tui/ the full-screen app: TypeScript on OpenTUI and Bun
319
338
  bridge.py JSON-lines bridge the app talks to muse.ai through
320
339
  demo.py made-up data for `muse-cli tui --demo`
321
- browsers.py reads the muse.ai login from Chromium browsers on macOS
340
+ browsers.py reads the muse.ai login from Firefox, or Chromium browsers on macOS
322
341
  gateway.py gateway client (auth, Noise transport, subscriptions)
323
342
  update.py daily update notice and `muse-cli update`
324
343
  skill.py installs and refreshes the bundled agent skill
@@ -338,9 +357,10 @@ release flow and contributor notes. Merging to `main` publishes a release.
338
357
  - Login is the [Log in once](#log-in-once) section above. Cookies live at
339
358
  `~/.config/muse-cli/cookies.txt` (mode 600). Access and gateway tokens are
340
359
  cached in `tokens.json` (mode 600) for 15 minutes and refetched when refused.
341
- - On macOS, `auth export` decrypts the muse.ai cookies from the browser's own
342
- cookie file, using the browser's Safe Storage key from your login keychain.
343
- Elsewhere it reads Google Chrome through
360
+ - On every system, `auth export` reads Firefox's `cookies.sqlite`, which holds
361
+ plain values. On macOS it first decrypts the muse.ai cookies from Chromium
362
+ browsers' cookie files, using the browser's Safe Storage key from your login
363
+ keychain. Without either login it reads Google Chrome through
344
364
  [agent-browser](https://github.com/vercel-labs/agent-browser), which needs
345
365
  Chrome open with remote debugging on (`chrome://inspect/#remote-debugging`)
346
366
  and a logged-in muse.ai tab in front.
@@ -152,8 +152,10 @@ chat / feed / goals / ideas / sessions / ...
152
152
  values with counts. `voice.speak` (`{voice_id, text, format: "mp3",
153
153
  stream: true}`, binary `audio/mpeg`) returned 404 `preview_audio_disabled`
154
154
  on the test account.
155
- - Muse Mail (`email.*`) answers 403 `{"code": "email_not_enabled"}` when the
156
- account has no mailbox. Thread list: `{data: [{id, subject,
155
+ - Muse Mail (`email.*`) can answer 403 `email_not_enabled` or 404
156
+ `email_upstream_rejected` when the account has no mailbox. For the latter,
157
+ the error's message contains JSON with `type: "emailMailboxNotFound"` and
158
+ a human-readable `detail`. Thread list: `{data: [{id, subject,
157
159
  message_count, participants, last_message}], paging: {cursors: {after}}}`,
158
160
  next page with `{cursor}`. Messages carry `header_from`,
159
161
  `header_from_name`, `header_to`, `text_body`/`html_body`/`extracted_text`,
@@ -194,7 +196,14 @@ chat / feed / goals / ideas / sessions / ...
194
196
  keys and keychain failures per browser to avoid repeated prompts.
195
197
  Select only host keys `muse.ai` and `.muse.ai`: subdomain-only cookies are
196
198
  not valid for the CLI's requests to `https://muse.ai/api/`.
197
- - Elsewhere (and with `--browser agent-browser`) `auth export` reads cookies
199
+ - `auth export` reads Firefox on every system (after Chromium on macOS):
200
+ `<profiles root>/*/cookies.sqlite`, table `moz_cookies`, plain `value`,
201
+ host `muse.ai`/`.muse.ai`, `originAttributes = ''` (default container).
202
+ `expiry` is milliseconds in current Firefox, seconds in older releases.
203
+ Roots: `%APPDATA%\Mozilla\Firefox\Profiles`, `~/Library/Application
204
+ Support/Firefox/Profiles`, `~/.mozilla/firefox` (plus snap and flatpak).
205
+ The newest unexpired `hatch_sess` across profiles wins.
206
+ - Without those (and with `--browser agent-browser`) `auth export` reads cookies
198
207
  from the user's own Google Chrome through agent-browser `--auto-connect`.
199
208
  Chrome 144+ shares that profile only after remote debugging is enabled at
200
209
  `chrome://inspect/#remote-debugging`. That export follows the active tab, so
@@ -24,6 +24,22 @@ python -m muse_cli.bridge (muse_cli/bridge.py) ── owns the Gateway
24
24
  points `sys.stdout` and fd 1 at stderr, so a stray `print()` from a CLI
25
25
  helper can never corrupt the protocol. The app writes the bridge's stderr
26
26
  to `~/.config/muse-cli/tui.log`.
27
+ - OpenTUI parses the transcript's Markdown natively. The app adds a language
28
+ label and frame to fenced blocks through `renderBlock`; it leaves the
29
+ Markdown source unchanged while a reply streams.
30
+
31
+ From 60 columns, `Tab` opens a full-width chat picker when the list isn't
32
+ docked. Only Chat docks the list automatically, at 144 columns or wider. Use
33
+ `Esc` or `Tab` to return to the view, or `Ctrl+B` to pin the list.
34
+ The dock groups chat names and unread counts by pin and recency. Click
35
+ **Switch chat** above the transcript, **Browse all** in the dock, or run
36
+ **Browse all chats** from the command palette for exact recency and longer
37
+ names without resizing the transcript.
38
+
39
+ In Tasks, select a schedule to see its latest runs or a single run to see its
40
+ full explanation. The list uses short summaries for common diagnostics.
41
+ Consecutive runs with the same outcome and explanation share one note while
42
+ keeping each timestamp, grouped by day when all outcomes match.
27
43
 
28
44
  ### Launcher
29
45
 
@@ -66,9 +82,9 @@ Bridge to app (response, exactly one per request id):
66
82
  Error `kind`: `auth` (no or expired login), `not_found` (deleted chat),
67
83
  `gateway`, `timeout`, `bad_request` (unknown method or bad params),
68
84
  `internal`. A gateway error whose body carries the server's reason uses its
69
- `message`, and adds its `code` (for example `email_not_enabled`). The app
70
- shows a code ending in `_not_enabled` as a feature the account lacks rather
71
- than a failure to retry.
85
+ message and code (for example `email_not_enabled` or `emailMailboxNotFound`).
86
+ The app treats those Mail codes as an unavailable inbox rather than a failure
87
+ to retry.
72
88
 
73
89
  Bridge to app (event, no id):
74
90
 
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["hatchling>=1.27"]
2
+ requires = ["hatchling>=1.33"]
3
3
  build-backend = "hatchling.build"
4
4
 
5
5
  [project]
@@ -54,8 +54,8 @@ classifiers = [
54
54
  ]
55
55
  dependencies = [
56
56
  "curl_cffi>=0.17",
57
- "noiseprotocol>=0.3",
58
- "protobuf>=5.0",
57
+ "noiseprotocol>=0.3.1",
58
+ "protobuf>=7.36.2",
59
59
  ]
60
60
 
61
61
  [project.urls]
@@ -39,6 +39,12 @@ The CLI stores the user's muse.ai browser login at
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 possible, use 2b.
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,3 +1,3 @@
1
1
  """muse-cli: talk to your personal muse.ai AI agent from the terminal."""
2
2
 
3
- __version__ = "0.3.15"
3
+ __version__ = "0.3.17"
@@ -186,6 +186,14 @@ def server_reason(e):
186
186
  return None, None
187
187
  code = err.get("code") if isinstance(err.get("code"), str) else None
188
188
  message = err.get("message") if isinstance(err.get("message"), str) else None
189
+ if e.status == 404 and code == "email_upstream_rejected" and message:
190
+ try:
191
+ problem = json.loads(message)
192
+ except ValueError:
193
+ return code, message
194
+ if isinstance(problem, dict) and problem.get("type") == "emailMailboxNotFound":
195
+ detail = problem.get("detail")
196
+ return "emailMailboxNotFound", detail if isinstance(detail, str) else None
189
197
  return code, message
190
198
 
191
199
 
@@ -1,11 +1,17 @@
1
- """Read the muse.ai login straight from a Chromium browser's cookie store on macOS.
1
+ """Read the muse.ai login straight from a browser's cookie store.
2
2
 
3
- Chromium keeps cookies in a SQLite file. Values are AES-128-CBC encrypted with
4
- a key derived from the browser's "Safe Storage" password in the login
5
- keychain, so macOS asks the user once before `security` may read it. Nothing
6
- here needs Node.js or a debugging port, and the browser can stay closed.
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 _muse_rows(path):
76
- """Encrypted muse.ai rows from a copy of the database (the browser locks the original)."""
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. Raises BrowserCookieError with a reason otherwise.
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 browser cookies directly is macOS-only")
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:
@@ -325,9 +325,14 @@ def _browser_cookies():
325
325
  def _print_need_browser_login(err):
326
326
  print(f"Could not read a muse.ai login from your browser: {err}", file=sys.stderr)
327
327
  print(file=sys.stderr)
328
- print("Log in at https://muse.ai/ in Chrome, Brave, Arc or Edge, then run", file=sys.stderr)
329
- print("`muse-cli auth export` again. macOS may ask to let `security` use", file=sys.stderr)
330
- print("the browser's Safe Storage key; click Allow.", file=sys.stderr)
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)
331
336
  print(file=sys.stderr)
332
337
  _print_hand_copy()
333
338
 
@@ -336,7 +341,7 @@ def cmd_auth_export(args):
336
341
  os.makedirs(CONFIG_DIR, exist_ok=True)
337
342
  choice = getattr(args, "browser", None) or "auto"
338
343
  jar, source = None, "Chrome"
339
- if choice != "agent-browser" and browsers.supported():
344
+ if choice != "agent-browser":
340
345
  print("Reading muse.ai cookies from your browser...", file=sys.stderr)
341
346
  try:
342
347
  jar, source = browsers.read_cookies(choice)
@@ -348,10 +353,6 @@ def cmd_auth_export(args):
348
353
  _print_need_browser_login(e)
349
354
  sys.exit(1)
350
355
  print(f"({e}; trying agent-browser)", file=sys.stderr)
351
- elif choice not in ("auto", "agent-browser"):
352
- print("cookie export failed: reading browser cookies directly is macOS-only; "
353
- "use --browser agent-browser", file=sys.stderr)
354
- sys.exit(1)
355
356
  if jar is None:
356
357
  if shutil.which("agent-browser") is None:
357
358
  _print_need_agent_browser()
@@ -1218,16 +1219,19 @@ def build_parser():
1218
1219
  "Copy your muse.ai login out of your browser into\n"
1219
1220
  "~/.config/muse-cli/cookies.txt (mode 600).\n"
1220
1221
  "\n"
1221
- "On macOS it reads the cookies of Chrome, Brave, Arc, Edge or Chromium\n"
1222
- "directly: log in at https://muse.ai/ once, then run this command.\n"
1223
- "macOS asks once to let `security` use the browser's Safe Storage key;\n"
1224
- "click Allow. No Node.js or debugging port is needed, and the browser\n"
1225
- "can be closed.\n"
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"
1226
1229
  "Unreadable profiles are skipped if another has a usable login.\n"
1227
1230
  "Subdomain-only cookies are not exported.\n"
1228
1231
  "Empty or expired login cookies never replace a saved login.\n"
1229
1232
  "\n"
1230
- "Elsewhere, or with --browser agent-browser, it reads Google Chrome through\n"
1233
+ "Without a Firefox login (and on macOS no Chromium one), or with\n"
1234
+ "--browser agent-browser, it reads Google Chrome through\n"
1231
1235
  "agent-browser. Chrome shares those cookies only after remote debugging is on.\n"
1232
1236
  "In the Chrome window you already use for muse.ai:\n"
1233
1237
  "\n"
@@ -1251,9 +1255,9 @@ def build_parser():
1251
1255
  formatter_class=argparse.RawDescriptionHelpFormatter,
1252
1256
  )
1253
1257
  p.add_argument("--browser", default="auto",
1254
- choices=["auto", *browsers.BROWSERS, "agent-browser"],
1255
- help="where to read the login (default: auto = any logged-in "
1256
- "Chromium browser on macOS, else agent-browser)")
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)")
1257
1261
  p.set_defaults(fn=cmd_auth_export)
1258
1262
 
1259
1263
  sub.add_parser("chat", help="plain line-by-line chat (the default with no command "