muse-cli 0.3.9__tar.gz → 0.3.10__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: muse-cli
3
- Version: 0.3.9
3
+ Version: 0.3.10
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
@@ -252,6 +252,8 @@ muse-cli raw <method> --body '{}' # escape hatch: any of 258 gat
252
252
  The interactive chat prints plain text, one message per line, so it works well
253
253
  with screen readers. It resumes the conversation you used last; type `/help`
254
254
  inside it for `/chats`, `/open N`, `/main`, `/new`, `/history`, and `/login`.
255
+ Any command above can also be run with a leading slash (`/status`, `/goals`,
256
+ `/files`, etc.) with `<TAB>` auto-completion.
255
257
 
256
258
  Every other command prints JSON. Your VM is auto-discovered from your session, and a
257
259
  random device id is generated on first run.
@@ -215,6 +215,8 @@ muse-cli raw <method> --body '{}' # escape hatch: any of 258 gat
215
215
  The interactive chat prints plain text, one message per line, so it works well
216
216
  with screen readers. It resumes the conversation you used last; type `/help`
217
217
  inside it for `/chats`, `/open N`, `/main`, `/new`, `/history`, and `/login`.
218
+ Any command above can also be run with a leading slash (`/status`, `/goals`,
219
+ `/files`, etc.) with `<TAB>` auto-completion.
218
220
 
219
221
  Every other command prints JSON. Your VM is auto-discovered from your session, and a
220
222
  random device id is generated on first run.
@@ -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.9"
3
+ __version__ = "0.3.10"
@@ -5,6 +5,7 @@ reader. Picks up the conversation you used last. Type /help for commands.
5
5
  """
6
6
  import json
7
7
  import os
8
+ import shlex
8
9
  import time
9
10
  # Enable GNU readline / libedit for line editing, history, and proper
10
11
  # CJK/wide-character deletion (wcwidth). It is a standard library C extension,
@@ -14,7 +15,7 @@ try:
14
15
  except ImportError:
15
16
  readline = None
16
17
 
17
- from .cli import CONFIG_DIR, cmd_auth_export, connect, fmt_event, load_config, start_session
18
+ from .cli import CONFIG_DIR, build_parser, cmd_auth_export, connect, fmt_event, load_config, start_session
18
19
  from .gateway import AuthError, GatewayError
19
20
 
20
21
  WAIT = 300 # seconds to wait for the first reply
@@ -30,6 +31,7 @@ HELP = """Commands:
30
31
  /new [title] start a new conversation
31
32
  /history [N] read the last N messages here (default 10)
32
33
  /login save your muse.ai login from Chrome again (same as `muse-cli auth export`)
34
+ /<command> run any muse-cli command (/status, /goals, /ideas, /files, etc.)
33
35
  /exit quit (Ctrl+C works too)"""
34
36
 
35
37
 
@@ -58,6 +60,31 @@ class Chat:
58
60
  self.st = load_state()
59
61
  self.gw = connect(self.cfg)
60
62
  self.listing = []
63
+ self.parser = build_parser()
64
+ if readline is not None:
65
+ sub_actions = [a for a in self.parser._actions if a.dest == "cmd"]
66
+ choices = [k for k in sub_actions[0].choices if k != "chat"] if sub_actions else []
67
+ repl_cmds = ["chats", "open", "main", "new", "history", "login", "help", "exit", "quit"]
68
+ all_cmds = sorted(set(f"/{c}" for c in repl_cmds + choices))
69
+
70
+ def complete(text, state):
71
+ line = (readline.get_line_buffer().lstrip() if hasattr(readline, "get_line_buffer") else "") or text
72
+ if " " not in line and line.startswith("/"):
73
+ matches = [c for c in all_cmds if c.startswith(text)]
74
+ return matches[state] if state < len(matches) else None
75
+ return None
76
+
77
+ self.complete = complete
78
+ try:
79
+ delims = readline.get_completer_delims().replace("/", "").replace("-", "")
80
+ readline.set_completer_delims(delims)
81
+ except Exception:
82
+ pass
83
+ readline.set_completer(complete)
84
+ if "libedit" in (readline.__doc__ or ""):
85
+ readline.parse_and_bind("bind ^I rl_complete")
86
+ else:
87
+ readline.parse_and_bind("tab: complete")
61
88
 
62
89
  def scope(self):
63
90
  return {"session_id": self.st["session_id"]} if self.st["session_id"] else {}
@@ -175,6 +202,40 @@ class Chat:
175
202
  self.gw.close()
176
203
  self.gw = connect(self.cfg)
177
204
 
205
+ def run_cli(self, line):
206
+ try:
207
+ tokens = shlex.split(line.lstrip("/"))
208
+ except ValueError as e:
209
+ print(f"Error parsing command: {e}")
210
+ return True
211
+ if not tokens:
212
+ return False
213
+ if tokens[0] in ("chat", "exit", "quit"):
214
+ if tokens[0] == "chat":
215
+ print("Already in chat.")
216
+ return True
217
+ return False
218
+
219
+ sub_actions = [a for a in self.parser._actions if a.dest == "cmd"]
220
+ choices = sub_actions[0].choices if sub_actions else {}
221
+ if tokens[0] not in choices:
222
+ return False
223
+
224
+ try:
225
+ args = self.parser.parse_args(tokens)
226
+ except SystemExit:
227
+ return True
228
+
229
+ if getattr(args, "fn", None):
230
+ if hasattr(args, "thread") and args.thread is None and self.st.get("session_id"):
231
+ args.thread = self.st["session_id"]
232
+ try:
233
+ args.fn(args)
234
+ except (SystemExit, KeyboardInterrupt):
235
+ print() # command stopped or exited; stay in the chat
236
+ return True
237
+ return False
238
+
178
239
  def handle(self, line):
179
240
  cmd, _, arg = line.partition(" ")
180
241
  arg = arg.strip()
@@ -188,12 +249,14 @@ class Chat:
188
249
  self.switch(None, "main chat")
189
250
  elif cmd == "/new":
190
251
  self.new_chat(arg)
191
- elif cmd == "/history":
252
+ elif cmd == "/history" and (not arg or arg.isdigit()):
192
253
  self.show_history(int(arg) if arg.isdigit() else 10)
193
254
  elif cmd == "/login":
194
255
  if login():
195
256
  self.reconnect()
196
257
  print("Signed in.")
258
+ elif self.run_cli(line):
259
+ pass
197
260
  else:
198
261
  print("Unknown command. Type /help.")
199
262
 
@@ -880,7 +880,7 @@ def _chat(args):
880
880
  cmd_chat(args)
881
881
 
882
882
 
883
- def main():
883
+ def build_parser():
884
884
  ap = argparse.ArgumentParser(prog="muse-cli", description="CLI for your personal muse.ai agent")
885
885
  ap.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
886
886
  sub = ap.add_subparsers(dest="cmd")
@@ -1000,8 +1000,12 @@ def main():
1000
1000
  p.add_argument("method"); p.add_argument("--body", default=None)
1001
1001
  p.add_argument("--param", action="append", default=[], help="path param k=v (repeatable)")
1002
1002
  p.add_argument("--timeout", type=int, default=30); p.set_defaults(fn=cmd_raw)
1003
+ return ap
1003
1004
 
1004
- args = ap.parse_args()
1005
+
1006
+ def main(argv=None):
1007
+ ap = build_parser()
1008
+ args = ap.parse_args(argv)
1005
1009
  if args.cmd is None:
1006
1010
  args.cmd, args.fn = "chat", _chat
1007
1011
  # A piped command prints JSON. The notice stays off unless both streams
File without changes
File without changes
File without changes
File without changes