memorysync-cli 1.0.3__tar.gz → 1.1.0__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 (27) hide show
  1. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/PKG-INFO +1 -1
  2. memorysync_cli-1.1.0/src/memorysync_cli/_version.py +1 -0
  3. memorysync_cli-1.1.0/src/memorysync_cli/commands/init.py +328 -0
  4. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/config.py +9 -0
  5. memorysync_cli-1.1.0/src/memorysync_cli/evaluation.py +54 -0
  6. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/http.py +31 -0
  7. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/main.py +22 -0
  8. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/registry.json +49 -3
  9. memorysync_cli-1.0.3/src/memorysync_cli/_version.py +0 -1
  10. memorysync_cli-1.0.3/src/memorysync_cli/commands/init.py +0 -109
  11. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/.gitignore +0 -0
  12. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/LICENSE +0 -0
  13. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/README.md +0 -0
  14. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/pyproject.toml +0 -0
  15. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/__init__.py +0 -0
  16. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/__main__.py +0 -0
  17. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/args.py +0 -0
  18. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/commands/__init__.py +0 -0
  19. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/commands/admin.py +0 -0
  20. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/commands/memory.py +0 -0
  21. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/commands/source.py +0 -0
  22. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/commands/tooling.py +0 -0
  23. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/completions.py +0 -0
  24. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/credentials.py +0 -0
  25. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/errors.py +0 -0
  26. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/output.py +0 -0
  27. {memorysync_cli-1.0.3 → memorysync_cli-1.1.0}/src/memorysync_cli/registry.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: memorysync-cli
3
- Version: 1.0.3
3
+ Version: 1.1.0
4
4
  Summary: MemorySync from your terminal. Zero dependencies.
5
5
  Project-URL: Documentation, https://docs.memorysync.io/cli
6
6
  Project-URL: Homepage, https://memorysync.io/cli
@@ -0,0 +1 @@
1
+ __version__ = "1.1.0"
@@ -0,0 +1,328 @@
1
+ """init: store a credential and pick defaults.
2
+
3
+ The key is verified against the API before it is written. Storing an unverified key
4
+ means the next command fails with something that looks like a network problem, and
5
+ the person has no reason to suspect the thing they just typed.
6
+
7
+ It is never written to the config file in plain text. It goes to the OS keychain
8
+ where one is reachable, and otherwise to an owner-only encrypted file, and `init`
9
+ says which of the two happened rather than implying a keychain that was never
10
+ there.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import getpass
16
+ import os
17
+ import sys
18
+
19
+ from .. import config as config_module
20
+ from .. import credentials
21
+ from ..errors import auth_error, usage_error
22
+ from ..evaluation import CLAIM_HINT
23
+ from ..http import ApiClient
24
+ from ..output import style
25
+
26
+
27
+ def _init_as_agent(ctx: dict, profile_name: str) -> dict:
28
+ """``init --agent`` — mint an evaluation key with no signup.
29
+
30
+ Stores the key exactly the way the interactive path does, so every later
31
+ command works with no further setup, and keeps the server's generated
32
+ end-user id as the profile default: an agent forced to invent one will invent
33
+ a different one next run and then wonder where its memories went.
34
+ """
35
+ flags, settings = ctx["flags"], ctx["settings"]
36
+
37
+ # No credential yet, by definition.
38
+ client = ApiClient(
39
+ base_url=settings["base_url"], api_key=None, timeout=settings["timeout"]
40
+ )
41
+ body = {}
42
+ if flags.get("agent_caller"):
43
+ body["agent_caller"] = flags["agent_caller"]
44
+ minted = client.mint_evaluation_key(body) or {}
45
+
46
+ api_key = minted.get("api_key")
47
+ if not api_key:
48
+ raise auth_error(
49
+ "The server did not return an evaluation key.",
50
+ 'Try again, or run "memorysync init" with a key from https://memorysync.io.',
51
+ )
52
+
53
+ tier = credentials.write_key(api_key, profile_name)
54
+
55
+ data = config_module.load()
56
+ entry = data.setdefault("profiles", {}).setdefault(profile_name, {})
57
+ user = flags.get("user") or minted.get("default_user_id")
58
+ if user:
59
+ entry["user"] = user
60
+ if minted.get("project_id"):
61
+ entry["project"] = minted["project_id"]
62
+ if settings["base_url"] != config_module.DEFAULT_BASE_URL:
63
+ entry["base_url"] = settings["base_url"]
64
+ path = config_module.save(data)
65
+
66
+ payload = {
67
+ "profile": profile_name,
68
+ "mode": "agent",
69
+ "api_key": api_key,
70
+ "default_user_id": minted.get("default_user_id"),
71
+ "project_id": minted.get("project_id"),
72
+ "plan": minted.get("plan"),
73
+ "claimed": False,
74
+ "expires_at": minted.get("expires_at"),
75
+ "claim_command": minted.get("claim_command") or CLAIM_HINT,
76
+ "limits": minted.get("limits"),
77
+ "mcp_url": minted.get("mcp_url"),
78
+ "stored_in": tier,
79
+ "config": str(path),
80
+ }
81
+
82
+ def render() -> str:
83
+ where = (
84
+ "the OS keychain" if tier == "keychain" else "an owner-only encrypted file"
85
+ )
86
+ return "\n".join(
87
+ [
88
+ style.green("Agent mode active."),
89
+ f"{style.dim('default user')} {payload['default_user_id'] or '-'}",
90
+ f"{style.dim('plan ')} {payload['plan'] or '-'}",
91
+ f"{style.dim('expires ')} {payload['expires_at'] or '-'}",
92
+ f"{style.dim('key stored ')} in {where}",
93
+ "",
94
+ style.dim('Try: memorysync add "I prefer TypeScript"'),
95
+ "",
96
+ style.yellow(
97
+ "Nobody owns this account yet. To keep it and everything in it:"
98
+ ),
99
+ f" {payload['claim_command']}",
100
+ ]
101
+ )
102
+
103
+ return {"data": payload, "text": render}
104
+
105
+
106
+ def _init_by_claiming(ctx: dict, profile_name: str) -> dict:
107
+ """``init --email`` — claim the evaluation account behind the stored key.
108
+
109
+ Two steps in one command, chosen by whether ``--code`` is present, because
110
+ that is how a person experiences it: run it, read the email, run it again with
111
+ the code.
112
+ """
113
+ flags, settings = ctx["flags"], ctx["settings"]
114
+ email = str(flags.get("email") or "").strip()
115
+
116
+ if flags.get("code"):
117
+ # Completing needs no credential, so this works on a machine that never
118
+ # held the key.
119
+ client = ApiClient(
120
+ base_url=settings["base_url"], api_key=None, timeout=settings["timeout"]
121
+ )
122
+ body = {"email": email, "code": str(flags["code"]).strip()}
123
+ if flags.get("password"):
124
+ body["password"] = str(flags["password"])
125
+ claimed = client.complete_evaluation_claim(body) or {}
126
+
127
+ # Recorded locally so the per-command reminder stops. The key keeps its
128
+ # ``ms_eval_`` prefix after claiming, so the prefix alone cannot tell us.
129
+ data = config_module.load()
130
+ entry = data.setdefault("profiles", {}).setdefault(profile_name, {})
131
+ entry["claimed"] = True
132
+ config_module.save(data)
133
+
134
+ payload = {**claimed, "profile": profile_name, "mode": "claim-complete"}
135
+
136
+ def render_complete() -> str:
137
+ return "\n".join(
138
+ [
139
+ style.green("Account claimed."),
140
+ f"{style.dim('email ')} {claimed.get('email') or email}",
141
+ f"{style.dim('plan ')} {claimed.get('plan') or '-'}",
142
+ "",
143
+ style.dim(
144
+ "Your existing key keeps working and no longer expires. "
145
+ "Everything stored during the evaluation is still there."
146
+ ),
147
+ ]
148
+ )
149
+
150
+ return {"data": payload, "text": render_complete}
151
+
152
+ api_key = credentials.read_key(profile_name) or os.environ.get(
153
+ "MEMORYSYNC_API_KEY"
154
+ )
155
+ if not api_key:
156
+ raise usage_error(
157
+ "No stored key, so there is no evaluation account to claim.",
158
+ 'Run "memorysync init --agent" first, or pass --code to finish a claim '
159
+ "you already started.",
160
+ )
161
+
162
+ client = ApiClient(
163
+ base_url=settings["base_url"], api_key=api_key, timeout=settings["timeout"]
164
+ )
165
+ started = client.start_evaluation_claim({"email": email}) or {}
166
+ payload = {**started, "profile": profile_name, "mode": "claim-start"}
167
+
168
+ def render_start() -> str:
169
+ target = started.get("email") or email
170
+ return "\n".join(
171
+ [
172
+ style.green("Claim code sent."),
173
+ f"{style.dim('email ')} {target}",
174
+ f"{style.dim('expires')} {started.get('expires_in_minutes') or '-'} minutes",
175
+ "",
176
+ style.dim("Check your email, then run:"),
177
+ f" memorysync init --email {target} --code <CODE>",
178
+ ]
179
+ )
180
+
181
+ return {"data": payload, "text": render_start}
182
+
183
+
184
+ def identify(ctx: dict) -> dict:
185
+ """``identify <name>`` — replace the profile's default end-user id.
186
+
187
+ Purely local. Renaming the default cannot rename memories already stored under
188
+ the old id, and pretending otherwise would be worse than saying so: the output
189
+ names the previous id so it can still be read back with ``--user``.
190
+ """
191
+ positionals = ctx.get("positionals") or []
192
+ name = (positionals[0] if positionals else "").strip()
193
+ if not name:
194
+ raise usage_error("No name given.", "Try: memorysync identify alice")
195
+
196
+ profile_name = ctx["settings"]["profile_name"]
197
+ data = config_module.load()
198
+ entry = data.setdefault("profiles", {}).setdefault(profile_name, {})
199
+ previous = entry.get("user")
200
+ entry["user"] = name
201
+ config_module.save(data)
202
+
203
+ payload = {
204
+ "profile": profile_name,
205
+ "end_user": name,
206
+ "previous_end_user": previous,
207
+ }
208
+
209
+ def render() -> str:
210
+ lines = [style.green(f"Default end user is now {name}.")]
211
+ if previous and previous != name:
212
+ lines.append(
213
+ style.dim(
214
+ f'Memories stored as "{previous}" keep that id - '
215
+ f"read them with --user {previous}."
216
+ )
217
+ )
218
+ else:
219
+ lines.append(style.dim("Nothing was stored under a different id."))
220
+ return "\n".join(lines)
221
+
222
+ return {"data": payload, "text": render}
223
+
224
+
225
+ def init(ctx: dict) -> dict:
226
+ flags, settings = ctx["flags"], ctx["settings"]
227
+ profile_name = settings["profile_name"]
228
+
229
+ # Claiming acts on the account behind an existing key rather than creating a
230
+ # profile, so it runs before the overwrite guard.
231
+ if flags.get("email"):
232
+ if flags.get("agent"):
233
+ raise usage_error(
234
+ "--agent mints a new account and --email claims the current one.",
235
+ 'Run "memorysync init --agent" first, then '
236
+ '"memorysync init --email <address>".',
237
+ )
238
+ return _init_by_claiming(ctx, profile_name)
239
+
240
+ if flags.get("agent") and flags.get("api_key"):
241
+ raise usage_error(
242
+ "--agent mints a key, so there is nothing to pass with --api-key.",
243
+ "Drop one of the two.",
244
+ )
245
+
246
+ existing = config_module.profile(profile_name)
247
+ if existing and not flags.get("force"):
248
+ stored = credentials.read_key(profile_name)
249
+ if stored:
250
+ raise usage_error(
251
+ f'Profile "{profile_name}" already has a key.',
252
+ "Pass --force to replace it, or --profile <name> to add another.",
253
+ )
254
+
255
+ if flags.get("agent"):
256
+ return _init_as_agent(ctx, profile_name)
257
+
258
+ api_key = flags.get("api_key") or os.environ.get("MEMORYSYNC_API_KEY")
259
+ if not api_key:
260
+ if not sys.stdin.isatty():
261
+ raise usage_error(
262
+ "No API key given and no terminal to prompt from.",
263
+ "Pass --api-key, or set MEMORYSYNC_API_KEY.",
264
+ )
265
+ # getpass, so the key is not echoed into the terminal or the scrollback.
266
+ api_key = getpass.getpass("MemorySync API key: ").strip()
267
+
268
+ if not api_key:
269
+ raise usage_error("No API key given.")
270
+
271
+ # Verified before storing. A key that cannot read its own plan is not usable,
272
+ # and finding that out now is far cheaper than on the next command.
273
+ probe = ApiClient(
274
+ base_url=settings["base_url"],
275
+ api_key=api_key,
276
+ timeout=settings["timeout"],
277
+ )
278
+ try:
279
+ plan = probe.current_plan() or {}
280
+ except Exception as error: # noqa: BLE001 - re-raised as an auth failure below
281
+ raise auth_error(
282
+ f"That key was refused: {error}",
283
+ "Check it in the dashboard, or pass --base-url if you are not on production.",
284
+ ) from None
285
+
286
+ tier = credentials.write_key(api_key, profile_name)
287
+
288
+ data = config_module.load()
289
+ entry = data.setdefault("profiles", {}).setdefault(profile_name, {})
290
+ if flags.get("user"):
291
+ entry["user"] = flags["user"]
292
+ if flags.get("project"):
293
+ entry["project"] = flags["project"]
294
+ if settings["base_url"] != config_module.DEFAULT_BASE_URL:
295
+ entry["base_url"] = settings["base_url"]
296
+ path = config_module.save(data)
297
+
298
+ payload = {
299
+ "profile": profile_name,
300
+ "stored_in": tier,
301
+ "config": str(path),
302
+ "user": entry.get("user"),
303
+ "project": entry.get("project"),
304
+ "plan": plan.get("plan") or plan.get("name"),
305
+ }
306
+
307
+ def render() -> str:
308
+ where = (
309
+ "the OS keychain"
310
+ if tier == "keychain"
311
+ else "an owner-only encrypted file"
312
+ )
313
+ lines = [
314
+ f"{style.green('Ready.')} Profile {style.bold(profile_name)} is set up.",
315
+ f"{style.dim('key ')} stored in {where}",
316
+ f"{style.dim('config ')} {path}",
317
+ ]
318
+ if entry.get("user"):
319
+ lines.append(f"{style.dim('user ')} {entry['user']}")
320
+ else:
321
+ lines.append(
322
+ style.dim("no default user; pass --user on each call or re-run with --user")
323
+ )
324
+ if payload["plan"]:
325
+ lines.append(f"{style.dim('plan ')} {payload['plan']}")
326
+ return "\n".join(lines)
327
+
328
+ return {"data": payload, "text": render}
@@ -151,6 +151,15 @@ def resolve(flags: dict[str, Any]) -> dict[str, Any]:
151
151
  # `-o table` saved into a profile worked under one CLI only.
152
152
  "output": pick("output", "MEMORYSYNC_OUTPUT", "output"),
153
153
  "timeout": timeout,
154
+ # Whether the evaluation account behind this profile has been claimed.
155
+ # Recorded locally by ``init --email ... --code ...`` because a claimed
156
+ # key keeps its ``ms_eval_`` prefix, so the prefix alone cannot tell us
157
+ # and the per-command reminder would never stop.
158
+ #
159
+ # Deliberately read straight off the profile rather than through ``pick``:
160
+ # it is a fact about the account, not a preference, so a flag or an
161
+ # environment variable must not be able to silence the reminder.
162
+ "claimed": stored.get("claimed") is True,
154
163
  }
155
164
 
156
165
 
@@ -0,0 +1,54 @@
1
+ """Evaluation-key awareness shared by every command.
2
+
3
+ Mirrors ``sdk/cli/src/evaluation.mjs`` exactly. The two CLIs are documented as
4
+ interchangeable, so a reminder that appears in one and not the other is a parity
5
+ bug, not a cosmetic difference.
6
+
7
+ An evaluation key is minted by an agent and expires in seven days unless a human
8
+ claims it. The most expensive outcome is somebody building on one, never noticing
9
+ it is temporary, and losing the account on day eight — so every command running
10
+ on an unclaimed key ends with one line saying so, on stderr.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from typing import Any, Mapping, Optional
16
+
17
+ #: Prefix the server puts on anonymously minted keys.
18
+ EVALUATION_KEY_PREFIX = "ms_eval_"
19
+
20
+ #: The command a human runs to keep the account.
21
+ CLAIM_HINT = "memorysync init --email you@example.com"
22
+
23
+
24
+ def is_evaluation_key(key: Optional[str]) -> bool:
25
+ """True when *key* was minted anonymously."""
26
+ return isinstance(key, str) and key.startswith(EVALUATION_KEY_PREFIX)
27
+
28
+
29
+ def claim_reminder(
30
+ api_key: Optional[str] = None,
31
+ profile: Optional[Mapping[str, Any]] = None,
32
+ ) -> Optional[str]:
33
+ """The reminder line for this invocation, or ``None``.
34
+
35
+ Reads ``claimed`` from the local profile rather than asking the API. Checking
36
+ on every command would add a round-trip to ``memorysync --help``, and the
37
+ claim path already knows the answer the moment it succeeds, so it records it.
38
+ """
39
+ if not is_evaluation_key(api_key):
40
+ return None
41
+ if profile and profile.get("claimed") is True:
42
+ return None
43
+ return (
44
+ "This is an unclaimed evaluation key and expires. "
45
+ f"Keep it: {CLAIM_HINT}"
46
+ )
47
+
48
+
49
+ __all__ = [
50
+ "EVALUATION_KEY_PREFIX",
51
+ "CLAIM_HINT",
52
+ "is_evaluation_key",
53
+ "claim_reminder",
54
+ ]
@@ -194,6 +194,37 @@ class ApiClient:
194
194
  # Named endpoints, so commands never carry raw paths
195
195
  # -----------------------------------------------------------------------
196
196
 
197
+ def mint_evaluation_key(self, body: dict) -> Any:
198
+ """Mint an evaluation key. The only endpoint here needing no credential.
199
+
200
+ Rate limited server-side per IP and per /24, failing closed, so a 429 is a
201
+ real answer rather than a transient error — it carries
202
+ ``retry_after_seconds`` pointing at the next UTC day.
203
+ """
204
+ return self.request("POST", "/evaluation/keys", body=body)
205
+
206
+ def start_evaluation_claim(self, body: dict) -> Any:
207
+ """Ask for a claim code by email. Needs the evaluation key."""
208
+ return self.request("POST", "/evaluation/claim/start", body=body)
209
+
210
+ def complete_evaluation_claim(self, body: dict) -> Any:
211
+ """Redeem a claim code.
212
+
213
+ Deliberately does not require the key: the code is the proof, so a claim
214
+ started on one machine can be finished on another — which is what happens
215
+ whenever somebody reads the code off their phone.
216
+ """
217
+ return self.request("POST", "/evaluation/claim/complete", body=body)
218
+
219
+ def evaluation_usage(self) -> Any:
220
+ """Remaining allowance for an evaluation key.
221
+
222
+ Evaluation keys are not granted ``billing:read``, so
223
+ ``/org/billing/usage`` is closed to them. This reports the same counters
224
+ without the pricing fields.
225
+ """
226
+ return self.request("GET", "/evaluation/usage")
227
+
197
228
  def add_memory(self, body: dict) -> Any:
198
229
  return self.request("POST", "/memory/add", body=body)
199
230
 
@@ -21,6 +21,7 @@ from .args import parse_args, suggest
21
21
  from .commands import admin, init as init_command, memory, source as source_command, tooling
22
22
  from .credentials import read_key
23
23
  from .errors import CliError, Exit, auth_error, usage_error
24
+ from .evaluation import claim_reminder
24
25
  from .http import ApiClient
25
26
  from .output import (
26
27
  emit,
@@ -37,8 +38,23 @@ Handler = Callable[[dict], dict]
37
38
  # which is the same reason the Node CLI keeps its HANDLERS map next to its own. A
38
39
  # name in the registry with no entry here fails as "not available" rather than
39
40
  # "unknown command", so `help --json` stays honest about what exists.
41
+ def _note_unclaimed_key(api_key: str | None, settings: dict) -> None:
42
+ """Tell the user their evaluation key is temporary, once per command.
43
+
44
+ On stderr so stdout stays machine-parseable — an agent piping ``--json``
45
+ somewhere sees nothing extra, and a person sees the line. Silent for a claimed
46
+ key or a normal one. Matches the Node CLI line for line.
47
+ """
48
+ reminder = claim_reminder(
49
+ api_key, {"claimed": bool((settings or {}).get("claimed"))}
50
+ )
51
+ if reminder:
52
+ print(reminder, file=sys.stderr)
53
+
54
+
40
55
  _HANDLERS: dict[str, Handler] = {
41
56
  "init": init_command.init,
57
+ "identify": init_command.identify,
42
58
  "add": memory.add,
43
59
  "search": memory.search,
44
60
  "list": memory.list_memories,
@@ -260,6 +276,7 @@ def dispatch(argv: list[str]) -> int:
260
276
  # command list.
261
277
  if command_name == "help" and (agent_mode or fmt == "json"):
262
278
  write(json.dumps(result["data"], indent=2))
279
+ _note_unclaimed_key(api_key, settings)
263
280
  return Exit.OK
264
281
 
265
282
  if agent_mode:
@@ -274,6 +291,7 @@ def dispatch(argv: list[str]) -> int:
274
291
  indent=2,
275
292
  )
276
293
  )
294
+ _note_unclaimed_key(api_key, settings)
277
295
  return result.get("exit_code", Exit.OK)
278
296
 
279
297
  # `completion` and `mcp` emit text that must not be decorated or reshaped.
@@ -281,9 +299,13 @@ def dispatch(argv: list[str]) -> int:
281
299
  text = result["text"]()
282
300
  if text:
283
301
  write(text)
302
+ # No reminder here: `completion` and `mcp` emit text that gets pasted
303
+ # into a shell profile or a config file, and a stray line would be
304
+ # pasted too.
284
305
  return result.get("exit_code", Exit.OK)
285
306
 
286
307
  emit(fmt=fmt, data=result["data"], text=result["text"])
308
+ _note_unclaimed_key(api_key, settings)
287
309
  return result.get("exit_code", Exit.OK)
288
310
 
289
311
  except CliError as error:
@@ -92,14 +92,38 @@
92
92
  {
93
93
  "name": "init",
94
94
  "summary": "Store a credential and pick a default user and project.",
95
- "description": "Prompts for an API key, verifies it against the API, then writes a profile. The key is never written to the config file in plain text: it goes to the OS keychain where one is reachable, and otherwise to an encrypted file readable only by you.",
96
- "usage": "memorysync init [--api-key <key>] [--user <id>] [--project <id>] [--force]",
95
+ "description": "Prompts for an API key, verifies it against the API, then writes a profile. The key is never written to the config file in plain text: it goes to the OS keychain where one is reachable, and otherwise to an encrypted file readable only by you.\n\nWith --agent it mints an evaluation key instead of asking for one, so a coding agent can get working memory with no email, no verification code and no human. That key expires after seven days and nobody owns it until somebody claims it with --email.",
96
+ "usage": "memorysync init [--api-key <key> | --agent | --email <address>] [--user <id>] [--project <id>] [--force]",
97
97
  "flags": [
98
98
  {
99
99
  "name": "--api-key",
100
100
  "value": "key",
101
101
  "description": "Skip the prompt and use this key."
102
102
  },
103
+ {
104
+ "name": "--agent",
105
+ "description": "Mint an evaluation key with no signup. Expires in 7 days unless claimed."
106
+ },
107
+ {
108
+ "name": "--agent-caller",
109
+ "value": "name",
110
+ "description": "Which tool is minting the key, e.g. claude-code. Attribution only."
111
+ },
112
+ {
113
+ "name": "--email",
114
+ "value": "address",
115
+ "description": "Claim the current evaluation account. Sends a code, then pass it with --code."
116
+ },
117
+ {
118
+ "name": "--code",
119
+ "value": "code",
120
+ "description": "The claim code from the email."
121
+ },
122
+ {
123
+ "name": "--password",
124
+ "value": "password",
125
+ "description": "Set a dashboard password while claiming. Optional."
126
+ },
103
127
  {
104
128
  "name": "--user",
105
129
  "short": "-u",
@@ -124,7 +148,29 @@
124
148
  ],
125
149
  "examples": [
126
150
  "memorysync init",
127
- "memorysync init --api-key ms_live_xxx --user alice --force"
151
+ "memorysync init --api-key ms_live_xxx --user alice --force",
152
+ "memorysync init --agent --agent-caller claude-code",
153
+ "memorysync init --email you@example.com",
154
+ "memorysync init --email you@example.com --code K7MP-3XQR"
155
+ ],
156
+ "requires_auth": false
157
+ },
158
+ {
159
+ "name": "identify",
160
+ "summary": "Name the end user that later commands default to.",
161
+ "description": "An evaluation key starts with a generated end-user id like swift-otter-4821, because a key minted by an agent has nobody to name it after. This replaces it with something meaningful.\n\nOnly changes the local default: memories already stored under the old id keep that id, so pass --user explicitly to read them back.",
162
+ "usage": "memorysync identify <name> [--profile <name>]",
163
+ "flags": [
164
+ {
165
+ "name": "--profile",
166
+ "short": "-p",
167
+ "value": "name",
168
+ "description": "Profile to change. Default \"default\"."
169
+ }
170
+ ],
171
+ "examples": [
172
+ "memorysync identify alice",
173
+ "memorysync identify alice@example.com"
128
174
  ],
129
175
  "requires_auth": false
130
176
  },
@@ -1 +0,0 @@
1
- __version__ = "1.0.3"
@@ -1,109 +0,0 @@
1
- """init: store a credential and pick defaults.
2
-
3
- The key is verified against the API before it is written. Storing an unverified key
4
- means the next command fails with something that looks like a network problem, and
5
- the person has no reason to suspect the thing they just typed.
6
-
7
- It is never written to the config file in plain text. It goes to the OS keychain
8
- where one is reachable, and otherwise to an owner-only encrypted file, and `init`
9
- says which of the two happened rather than implying a keychain that was never
10
- there.
11
- """
12
-
13
- from __future__ import annotations
14
-
15
- import getpass
16
- import os
17
- import sys
18
-
19
- from .. import config as config_module
20
- from .. import credentials
21
- from ..errors import auth_error, usage_error
22
- from ..http import ApiClient
23
- from ..output import style
24
-
25
-
26
- def init(ctx: dict) -> dict:
27
- flags, settings = ctx["flags"], ctx["settings"]
28
- profile_name = settings["profile_name"]
29
-
30
- existing = config_module.profile(profile_name)
31
- if existing and not flags.get("force"):
32
- stored = credentials.read_key(profile_name)
33
- if stored:
34
- raise usage_error(
35
- f'Profile "{profile_name}" already has a key.',
36
- "Pass --force to replace it, or --profile <name> to add another.",
37
- )
38
-
39
- api_key = flags.get("api_key") or os.environ.get("MEMORYSYNC_API_KEY")
40
- if not api_key:
41
- if not sys.stdin.isatty():
42
- raise usage_error(
43
- "No API key given and no terminal to prompt from.",
44
- "Pass --api-key, or set MEMORYSYNC_API_KEY.",
45
- )
46
- # getpass, so the key is not echoed into the terminal or the scrollback.
47
- api_key = getpass.getpass("MemorySync API key: ").strip()
48
-
49
- if not api_key:
50
- raise usage_error("No API key given.")
51
-
52
- # Verified before storing. A key that cannot read its own plan is not usable,
53
- # and finding that out now is far cheaper than on the next command.
54
- probe = ApiClient(
55
- base_url=settings["base_url"],
56
- api_key=api_key,
57
- timeout=settings["timeout"],
58
- )
59
- try:
60
- plan = probe.current_plan() or {}
61
- except Exception as error: # noqa: BLE001 - re-raised as an auth failure below
62
- raise auth_error(
63
- f"That key was refused: {error}",
64
- "Check it in the dashboard, or pass --base-url if you are not on production.",
65
- ) from None
66
-
67
- tier = credentials.write_key(api_key, profile_name)
68
-
69
- data = config_module.load()
70
- entry = data.setdefault("profiles", {}).setdefault(profile_name, {})
71
- if flags.get("user"):
72
- entry["user"] = flags["user"]
73
- if flags.get("project"):
74
- entry["project"] = flags["project"]
75
- if settings["base_url"] != config_module.DEFAULT_BASE_URL:
76
- entry["base_url"] = settings["base_url"]
77
- path = config_module.save(data)
78
-
79
- payload = {
80
- "profile": profile_name,
81
- "stored_in": tier,
82
- "config": str(path),
83
- "user": entry.get("user"),
84
- "project": entry.get("project"),
85
- "plan": plan.get("plan") or plan.get("name"),
86
- }
87
-
88
- def render() -> str:
89
- where = (
90
- "the OS keychain"
91
- if tier == "keychain"
92
- else "an owner-only encrypted file"
93
- )
94
- lines = [
95
- f"{style.green('Ready.')} Profile {style.bold(profile_name)} is set up.",
96
- f"{style.dim('key ')} stored in {where}",
97
- f"{style.dim('config ')} {path}",
98
- ]
99
- if entry.get("user"):
100
- lines.append(f"{style.dim('user ')} {entry['user']}")
101
- else:
102
- lines.append(
103
- style.dim("no default user; pass --user on each call or re-run with --user")
104
- )
105
- if payload["plan"]:
106
- lines.append(f"{style.dim('plan ')} {payload['plan']}")
107
- return "\n".join(lines)
108
-
109
- return {"data": payload, "text": render}
File without changes
File without changes