Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to `getmnemo-cli` are documented here. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
[SemVer](https://semver.org/).

## [0.4.0] — 2026-10-15

### Changed
- `getmnemo` core dependency `^0.5.1` → `^0.6.0`.
- A workspace ID is no longer required: with an API key, workspace identity comes from the key. Commands no longer fail with "No workspace selected".
- `login` no longer prompts for a workspace ID; `--workspace-id` is deprecated and only saved if given.
- `whoami` reports authenticated with just an API key; `doctor` drops the "workspace configured" check; `mcp` only emits `GETMNEMO_WORKSPACE_ID` when one is still configured.

### Notes
- Minor bump (not patch): `login`, `whoami`, `doctor` and `mcp` output change, and the core dependency moves a minor version.
- `GETMNEMO_WORKSPACE_ID` / a saved `workspaceId` are still accepted but ignored by getmnemo 0.6.

## [0.3.0] — 2026-09-02

### Added
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ npx getmnemo-cli --help
## Quickstart

```bash
getmnemo login # save API key + workspace to ~/.getmnemo/config.json
getmnemo login # save API key to ~/.getmnemo/config.json
getmnemo add "Acme prefers blue branding" --container org:acme
getmnemo search "what brand color does Acme use?" --container org:acme
getmnemo doctor # verify auth + API reachability
Expand All @@ -36,11 +36,11 @@ getmnemo doctor # verify auth + API reachability

| Command | Description |
| --- | --- |
| `getmnemo login` | Prompt for API key, workspace ID, and (optionally) API URL; persist to `~/.getmnemo/config.json`. |
| `getmnemo login` | Prompt for API key and (optionally) API URL; verify; persist to `~/.getmnemo/config.json`. The API key identifies the workspace. |
| `getmnemo logout` | Remove saved credentials. |
| `getmnemo whoami` | Print the active workspace + API URL. |
| `getmnemo whoami` | Print the API key preview + API URL (and workspace, if one is still configured). |

`login` flags: `--api-key`, `--workspace-id`, `--api-url` (skip the prompt).
`login` flags: `--api-key`, `--api-url` (skip the prompt). `--workspace-id` is deprecated and optional — workspace identity comes from the API key.

### Memory operations

Expand Down Expand Up @@ -108,7 +108,7 @@ With `--json`, runtime errors are written to stderr as `{"ok": false, "error": "
| Variable | Purpose | Default |
| --- | --- | --- |
| `GETMNEMO_API_KEY` | Overrides the saved API key. | — |
| `GETMNEMO_WORKSPACE_ID` | Overrides the active workspace. | — |
| `GETMNEMO_WORKSPACE_ID` | Deprecated and optional — the API key identifies the workspace. | — |
| `GETMNEMO_API_URL` | Overrides the API base URL. | `https://api.mnemohq.com` |
| `GETMNEMO_CONTAINER` | Default container tag for the memory commands when no `--container` flag is given. | — |

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "getmnemo-cli",
"version": "0.3.0",
"version": "0.4.0",
"description": "Official CLI for Mnemo — manage memories, workspaces, and integrations from your terminal.",
"type": "module",
"bin": {
Expand All @@ -23,7 +23,7 @@
},
"dependencies": {
"commander": "^12.1.0",
"getmnemo": "^0.5.1",
"getmnemo": "^0.6.0",
"kleur": "^4.1.5",
"prompts": "^2.4.2"
},
Expand Down
26 changes: 24 additions & 2 deletions src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("Mnemo CLI", () => {
} catch {
// commander throws on version by design
}
expect(stdout.trim()).toBe("0.3.0");
expect(stdout.trim()).toBe("0.4.0");
});

it("exits 2 for an unknown option on a subcommand (exit callback is inherited)", async () => {
Expand Down Expand Up @@ -357,7 +357,29 @@ describe("Mnemo CLI", () => {
expect(fetchMock).not.toHaveBeenCalled();
});

it("login verifies credentials with a synthetic probe container", async () => {
it("login honours --api-url without prompting", async () => {
vi.stubEnv(
"HOME",
join(tmpdir(), `getmnemo-cli-test-home-login-url-${process.pid}`),
);
const fetchMock = vi
.fn()
.mockResolvedValue(jsonResponse({ items: [], nextCursor: null }));
vi.stubGlobal("fetch", fetchMock);

const program = buildCli();
program.exitOverride();
await program.parseAsync([
"node", "getmnemo", "--json", "login",
"--api-key", "mk_login_test", "--api-url", "https://custom.test.invalid",
]);

const [url] = firstCall(fetchMock);
expect(url.startsWith("https://custom.test.invalid/v1/memories")).toBe(true);
expect(stdout).toMatch(/"baseUrl": "https:\/\/custom\.test\.invalid"/);
});

it("login verifies credentials with a synthetic probe container", async () => {
// Own HOME so the config write cannot leak into the shared stub path.
vi.stubEnv(
"HOME",
Expand Down
36 changes: 17 additions & 19 deletions src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export function registerAuthCommands(program: Command): void {
.command("login")
.description("authenticate with Mnemo and save credentials locally")
.option("--api-key <key>", "API key (skips interactive prompt)")
.option("--workspace-id <id>", "workspace id (skips interactive prompt)")
.option("--workspace-id <id>", "deprecated: workspace comes from the API key; saved if given")
.option("--api-url <url>", "override API base URL")
.action(async (opts: { apiKey?: string; workspaceId?: string; baseUrl?: string }, cmd: Command) => {
.action(async (opts: { apiKey?: string; workspaceId?: string; apiUrl?: string }, cmd: Command) => {
const json = rootJsonFlag(cmd);
const cfg = await readConfig();
const defaultApiUrl = resolveApiUrl(cfg);
Expand All @@ -36,13 +36,7 @@ export function registerAuthCommands(program: Command): void {
validate: (val: string) => (val.trim().length > 0 ? true : "API key is required"),
},
{
type: opts.workspaceId ? null : "text",
name: "workspaceId",
message: "Workspace ID",
validate: (val: string) => (val.trim().length > 0 ? true : "Workspace ID is required"),
},
{
type: opts.baseUrl ? null : "text",
type: opts.apiUrl ? null : "text",
name: "baseUrl",
message: "API URL",
initial: defaultApiUrl,
Expand All @@ -56,14 +50,16 @@ export function registerAuthCommands(program: Command): void {
);

const apiKey = opts.apiKey ?? (responses.apiKey as string);
const workspaceId = opts.workspaceId ?? (responses.workspaceId as string);
const baseUrl = opts.baseUrl ?? (responses.baseUrl as string) ?? defaultApiUrl;
// Deprecated: the API key identifies the workspace. Only saved if given.
const workspaceId = opts.workspaceId?.trim() || undefined;
// commander maps `--api-url` to `opts.apiUrl`.
const baseUrl = opts.apiUrl ?? (responses.baseUrl as string) ?? defaultApiUrl;

// Verify credentials before persisting — a typo should fail loudly,
// not silently overwrite a previously-working config.
try {
const probe = new Mnemo({ apiKey, workspaceId, baseUrl });
// getmnemo 0.5.1 list() throws client-side without a container, and
const probe = new Mnemo({ apiKey, baseUrl });
// getmnemo list() throws client-side without a container, and
// none is configured yet at login. Probe with a synthetic read-only
// tag: we only care whether the key authenticates (401 vs 2xx), and
// listing an empty container is a valid, cheap request.
Expand All @@ -81,13 +77,15 @@ export function registerAuthCommands(program: Command): void {
process.exit(1);
}

await writeConfig({ apiKey, workspaceId, baseUrl });
await writeConfig({ apiKey, baseUrl, ...(workspaceId ? { workspaceId } : {}) });

if (json) {
printJson({ ok: true, workspaceId, baseUrl });
printJson({ ok: true, workspaceId: workspaceId ?? null, baseUrl });
return;
}
printSuccess(`Logged in. Workspace: ${workspaceId}`);
printSuccess(
workspaceId ? `Logged in. Workspace: ${workspaceId}` : "Logged in.",
);
});

program
Expand All @@ -105,7 +103,7 @@ export function registerAuthCommands(program: Command): void {

program
.command("whoami")
.description("show the current authenticated workspace")
.description("show the current API key, API URL, and (deprecated) workspace")
.action(async (_opts: unknown, cmd: Command) => {
const json = rootJsonFlag(cmd);
const cfg = await readConfig();
Expand All @@ -114,7 +112,7 @@ export function registerAuthCommands(program: Command): void {
const baseUrl = resolveApiUrl(cfg);

const payload = {
authenticated: Boolean(apiKey && workspaceId),
authenticated: Boolean(apiKey),
workspaceId: workspaceId ?? null,
baseUrl,
apiKeyPreview: apiKey ? `${apiKey.slice(0, 4)}…${apiKey.slice(-4)}` : null,
Expand All @@ -128,7 +126,7 @@ export function registerAuthCommands(program: Command): void {
printInfo("Not logged in. Run `getmnemo login`.");
return;
}
printInfo(`Workspace: ${payload.workspaceId}`);
if (payload.workspaceId) printInfo(`Workspace: ${payload.workspaceId}`);
printInfo(`API URL: ${payload.baseUrl}`);
printInfo(`API key: ${payload.apiKeyPreview}`);
});
Expand Down
1 change: 0 additions & 1 deletion src/commands/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function registerDoctorCommand(program: Command): void {

checks.push({ name: "config file present", ok: Boolean(cfg.updatedAt), detail: cfg.updatedAt });
checks.push({ name: "API key configured", ok: Boolean(apiKey) });
checks.push({ name: "workspace configured", ok: Boolean(workspaceId), detail: workspaceId });

let healthOk = false;
let healthDetail = "";
Expand Down
6 changes: 4 additions & 2 deletions src/commands/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export function registerMcpCommand(program: Command): void {
const json = rootJsonFlag(cmd);
const cfg = await readConfig();
const apiKey = resolveApiKey(cfg) ?? "<your-getmnemo-api-key>";
const workspaceId = resolveWorkspaceId(cfg) ?? "<your-workspace-id>";
// Deprecated (the API key identifies the workspace); only emitted when
// the user still has one configured.
const workspaceId = resolveWorkspaceId(cfg);
const baseUrl = resolveApiUrl(cfg);

const snippet = {
Expand All @@ -23,7 +25,7 @@ export function registerMcpCommand(program: Command): void {
args: ["-y", "getmnemo-mcp"],
env: {
GETMNEMO_API_KEY: apiKey,
GETMNEMO_WORKSPACE_ID: workspaceId,
...(workspaceId ? { GETMNEMO_WORKSPACE_ID: workspaceId } : {}),
GETMNEMO_API_URL: baseUrl,
},
},
Expand Down
37 changes: 37 additions & 0 deletions src/lib/client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { ClientAuthError, getClient } from "./client.js";

describe("getClient", () => {
beforeEach(() => {
// Nonexistent HOME so a real ~/.getmnemo/config.json can't leak in.
vi.stubEnv("HOME", join(tmpdir(), "getmnemo-cli-client-test-nonexistent"));
vi.stubEnv("GETMNEMO_WORKSPACE_ID", undefined);
vi.stubEnv("GETMNEMO_API_URL", "https://api.test.invalid");
});

afterEach(() => {
vi.unstubAllEnvs();
});

it("builds a client from an API key alone (workspace comes from the key)", async () => {
vi.stubEnv("GETMNEMO_API_KEY", "mk_test_key");
const ctx = await getClient();
expect(ctx.apiKey).toBe("mk_test_key");
expect(ctx.workspaceId).toBeUndefined();
expect(ctx.client).toBeDefined();
});

it("still accepts a configured (deprecated) workspace id", async () => {
vi.stubEnv("GETMNEMO_API_KEY", "mk_test_key");
vi.stubEnv("GETMNEMO_WORKSPACE_ID", "ws_legacy");
const ctx = await getClient();
expect(ctx.workspaceId).toBe("ws_legacy");
});

it("still requires an API key", async () => {
vi.stubEnv("GETMNEMO_API_KEY", undefined);
await expect(getClient()).rejects.toBeInstanceOf(ClientAuthError);
});
});
16 changes: 9 additions & 7 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export interface ClientContext {
/** Transport for people/reminders/brief/timeline/meetings/merge. */
api: PersonalApi;
apiKey: string;
workspaceId: string;
/**
* Optional and deprecated: workspace identity comes from the API key. Kept
* only so configs that still set it keep working; getmnemo 0.6 ignores it.
*/
workspaceId?: string;
baseUrl: string;
cfg: CliConfig;
}
Expand All @@ -37,11 +41,9 @@ export async function getClient(): Promise<ClientContext> {
"Not authenticated. Run `getmnemo login` or set GETMNEMO_API_KEY.",
);
}
if (!workspaceId) {
throw new ClientAuthError(
"No workspace selected. Run `getmnemo login` or set GETMNEMO_WORKSPACE_ID.",
);
}
// No workspace check: the API key carries workspace identity. A configured
// workspaceId is still passed through (getmnemo 0.6 ignores it) so existing
// configs keep working unchanged.

// Backstop only: every current command resolves its container per call
// (flag > env > config) and passes it explicitly, so this seed is not
Expand All @@ -50,7 +52,7 @@ export async function getClient(): Promise<ClientContext> {
// of an SDK error. Per-call values always win over this.
const client = new Mnemo({
apiKey,
workspaceId,
...(workspaceId ? { workspaceId } : {}),
baseUrl,
defaultContainerTag: resolveContainerTag(cfg),
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ describe("CLI_VERSION", () => {
readFileSync(new URL("../../package.json", import.meta.url), "utf8"),
) as { version: string };
expect(CLI_VERSION).toBe(pkg.version);
expect(CLI_VERSION).toBe("0.3.0");
expect(CLI_VERSION).toBe("0.4.0");
});
});