mnotes-cli 1.10.0 → 1.10.1

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.
@@ -43,6 +43,21 @@ const config_utils_1 = require("../config-utils");
43
43
  const claude_code_1 = require("../../../templates/claude-code");
44
44
  const codex_1 = require("../../../templates/codex");
45
45
  const openclaw_1 = require("../../../templates/openclaw");
46
+ // Mock createClient so resolveWorkspace can validate workspaces without a real server
47
+ vitest_1.vi.mock("../../../client", () => ({
48
+ createClient: () => ({
49
+ listWorkspaces: async () => ({
50
+ data: [
51
+ { id: "ws-123", name: "Test", slug: "test-123", isDefault: true },
52
+ { id: "ws-explicit-id", name: "Explicit", slug: "explicit-id", isDefault: false },
53
+ { id: "ws-new", name: "New", slug: "new", isDefault: false },
54
+ ],
55
+ }),
56
+ createWorkspace: async (name) => ({
57
+ data: { id: name, name, slug: name, isDefault: false },
58
+ }),
59
+ }),
60
+ }));
46
61
  // -- Helper: capture stdout --
47
62
  function captureStdout(fn) {
48
63
  const chunks = [];
@@ -41,6 +41,19 @@ const wizard_1 = require("../wizard");
41
41
  const hooks_1 = require("../../../templates/claude-code/hooks");
42
42
  const skills_1 = require("../../../templates/claude-code/skills");
43
43
  const agents_1 = require("../../../templates/claude-code/agents");
44
+ // Mock createClient so resolveWorkspace can validate workspaces without a real server
45
+ vitest_1.vi.mock("../../../client", () => ({
46
+ createClient: () => ({
47
+ listWorkspaces: async () => ({
48
+ data: [
49
+ { id: "ws-123", name: "Test", slug: "test-123", isDefault: true },
50
+ ],
51
+ }),
52
+ createWorkspace: async (name) => ({
53
+ data: { id: name, name, slug: name, isDefault: false },
54
+ }),
55
+ }),
56
+ }));
44
57
  function makeTmpDir() {
45
58
  return fs.mkdtempSync(path.join(os.tmpdir(), "mnotes-wizard-test-"));
46
59
  }
@@ -38,9 +38,11 @@ exports.handleClaudeCode = handleClaudeCode;
38
38
  exports.registerConnectCommand = registerConnectCommand;
39
39
  const fs = __importStar(require("fs"));
40
40
  const path = __importStar(require("path"));
41
+ const readline = __importStar(require("readline"));
41
42
  const config_utils_1 = require("./config-utils");
42
43
  const workspace_prompt_1 = require("./workspace-prompt");
43
44
  const config_1 = require("../../config");
45
+ const client_1 = require("../../client");
44
46
  const claude_code_1 = require("../../templates/claude-code");
45
47
  const codex_1 = require("../../templates/codex");
46
48
  const openclaw_1 = require("../../templates/openclaw");
@@ -90,13 +92,45 @@ function printConnectionStatus() {
90
92
  /**
91
93
  * Resolves the workspace ID — uses --workspace flag if provided, otherwise
92
94
  * prompts interactively after validating the connection.
95
+ *
96
+ * When a workspace value is provided (flag, env, or config), validates it
97
+ * against the API by matching on ID or slug. If not found, prompts to create.
93
98
  */
94
99
  async function resolveWorkspace(opts) {
95
100
  // Check flag, env, dir map, global config
96
101
  const fromConfig = (0, config_1.resolveConfig)({ workspaceId: opts.workspace });
97
- if (fromConfig.workspaceId)
98
- return fromConfig.workspaceId;
99
- // Nothing stored interactive selection/creation
102
+ const candidate = fromConfig.workspaceId;
103
+ if (candidate) {
104
+ // Validate the candidate against the API
105
+ const client = (0, client_1.createClient)(opts.url, opts.apiKey);
106
+ let workspaces;
107
+ try {
108
+ const res = await client.listWorkspaces();
109
+ workspaces = res.data;
110
+ }
111
+ catch (err) {
112
+ const message = err instanceof Error ? err.message : String(err);
113
+ throw new Error(`Failed to fetch workspaces: ${message}`);
114
+ }
115
+ // Match by ID or slug
116
+ const match = workspaces.find((ws) => ws.id === candidate || ws.slug === candidate);
117
+ if (match) {
118
+ return match.id;
119
+ }
120
+ // Not found — ask user to create
121
+ process.stderr.write(`\nWorkspace "${candidate}" not found.\n`);
122
+ const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
123
+ const answer = await new Promise((resolve) => rl.question(`Create workspace "${candidate}"? [Y/n] `, resolve));
124
+ rl.close();
125
+ if (answer.trim() === "" || answer.trim().toLowerCase() === "y") {
126
+ const created = await client.createWorkspace(candidate);
127
+ process.stderr.write(`Created workspace "${created.data.name}" (${created.data.id})\n`);
128
+ return created.data.id;
129
+ }
130
+ // User declined — fall through to interactive
131
+ process.stderr.write("Falling back to interactive workspace selection.\n");
132
+ }
133
+ // Nothing stored or user declined — interactive selection/creation
100
134
  const resolved = await (0, workspace_prompt_1.resolveWorkspaceInteractively)(opts.url, opts.apiKey);
101
135
  return resolved.id;
102
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnotes-cli",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "CLI for m-notes AI knowledge base — manage notes, search, and CRUD from the terminal",
5
5
  "bin": {
6
6
  "mnotes": "./dist/index.js"