@memnexus-ai/cli 0.1.0

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 (148) hide show
  1. package/.env.example +13 -0
  2. package/.eslintrc.js +24 -0
  3. package/.github/ISSUE_TEMPLATE/phase-1-foundation.md +1078 -0
  4. package/.github/workflows/publish.yml +277 -0
  5. package/.github/workflows/test-app-token.yml +54 -0
  6. package/.npmrc.backup +3 -0
  7. package/.npmrc.example +6 -0
  8. package/.prettierignore +4 -0
  9. package/.prettierrc +8 -0
  10. package/CHANGELOG.md +138 -0
  11. package/PLATFORM_TESTING.md +243 -0
  12. package/README.md +986 -0
  13. package/RELEASE.md +428 -0
  14. package/RELEASE_READINESS.md +253 -0
  15. package/USAGE.md +1373 -0
  16. package/bin/mx.js +2 -0
  17. package/dist/commands/apikeys.d.ts +7 -0
  18. package/dist/commands/apikeys.d.ts.map +1 -0
  19. package/dist/commands/apikeys.js +133 -0
  20. package/dist/commands/apikeys.js.map +1 -0
  21. package/dist/commands/artifacts.d.ts +7 -0
  22. package/dist/commands/artifacts.d.ts.map +1 -0
  23. package/dist/commands/artifacts.js +277 -0
  24. package/dist/commands/artifacts.js.map +1 -0
  25. package/dist/commands/auth.d.ts +7 -0
  26. package/dist/commands/auth.d.ts.map +1 -0
  27. package/dist/commands/auth.js +119 -0
  28. package/dist/commands/auth.js.map +1 -0
  29. package/dist/commands/communities.d.ts +7 -0
  30. package/dist/commands/communities.d.ts.map +1 -0
  31. package/dist/commands/communities.js +137 -0
  32. package/dist/commands/communities.js.map +1 -0
  33. package/dist/commands/config.d.ts +7 -0
  34. package/dist/commands/config.d.ts.map +1 -0
  35. package/dist/commands/config.js +138 -0
  36. package/dist/commands/config.js.map +1 -0
  37. package/dist/commands/conversations.d.ts +7 -0
  38. package/dist/commands/conversations.d.ts.map +1 -0
  39. package/dist/commands/conversations.js +160 -0
  40. package/dist/commands/conversations.js.map +1 -0
  41. package/dist/commands/facts.d.ts +7 -0
  42. package/dist/commands/facts.d.ts.map +1 -0
  43. package/dist/commands/facts.js +298 -0
  44. package/dist/commands/facts.js.map +1 -0
  45. package/dist/commands/graphrag.d.ts +7 -0
  46. package/dist/commands/graphrag.d.ts.map +1 -0
  47. package/dist/commands/graphrag.js +139 -0
  48. package/dist/commands/graphrag.js.map +1 -0
  49. package/dist/commands/memories.d.ts +7 -0
  50. package/dist/commands/memories.d.ts.map +1 -0
  51. package/dist/commands/memories.js +304 -0
  52. package/dist/commands/memories.js.map +1 -0
  53. package/dist/commands/patterns.d.ts +7 -0
  54. package/dist/commands/patterns.d.ts.map +1 -0
  55. package/dist/commands/patterns.js +227 -0
  56. package/dist/commands/patterns.js.map +1 -0
  57. package/dist/commands/system.d.ts +7 -0
  58. package/dist/commands/system.d.ts.map +1 -0
  59. package/dist/commands/system.js +97 -0
  60. package/dist/commands/system.js.map +1 -0
  61. package/dist/commands/topics.d.ts +7 -0
  62. package/dist/commands/topics.d.ts.map +1 -0
  63. package/dist/commands/topics.js +314 -0
  64. package/dist/commands/topics.js.map +1 -0
  65. package/dist/index.d.ts +3 -0
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/index.js +44 -0
  68. package/dist/index.js.map +1 -0
  69. package/dist/lib/api-client.d.ts +29 -0
  70. package/dist/lib/api-client.d.ts.map +1 -0
  71. package/dist/lib/api-client.js +64 -0
  72. package/dist/lib/api-client.js.map +1 -0
  73. package/dist/lib/auth.d.ts +10 -0
  74. package/dist/lib/auth.d.ts.map +1 -0
  75. package/dist/lib/auth.js +47 -0
  76. package/dist/lib/auth.js.map +1 -0
  77. package/dist/lib/config.d.ts +19 -0
  78. package/dist/lib/config.d.ts.map +1 -0
  79. package/dist/lib/config.js +59 -0
  80. package/dist/lib/config.js.map +1 -0
  81. package/dist/lib/errors.d.ts +7 -0
  82. package/dist/lib/errors.d.ts.map +1 -0
  83. package/dist/lib/errors.js +133 -0
  84. package/dist/lib/errors.js.map +1 -0
  85. package/dist/lib/formatters.d.ts +12 -0
  86. package/dist/lib/formatters.d.ts.map +1 -0
  87. package/dist/lib/formatters.js +103 -0
  88. package/dist/lib/formatters.js.map +1 -0
  89. package/dist/lib/spinner.d.ts +54 -0
  90. package/dist/lib/spinner.d.ts.map +1 -0
  91. package/dist/lib/spinner.js +108 -0
  92. package/dist/lib/spinner.js.map +1 -0
  93. package/dist/lib/validators.d.ts +92 -0
  94. package/dist/lib/validators.d.ts.map +1 -0
  95. package/dist/lib/validators.js +257 -0
  96. package/dist/lib/validators.js.map +1 -0
  97. package/dist/types/index.d.ts +13 -0
  98. package/dist/types/index.d.ts.map +1 -0
  99. package/dist/types/index.js +3 -0
  100. package/dist/types/index.js.map +1 -0
  101. package/docs/README.md +219 -0
  102. package/docs/code-generation-strategy.md +560 -0
  103. package/docs/prd.md +748 -0
  104. package/docs/sync-strategy.md +533 -0
  105. package/jest.config.js +30 -0
  106. package/package.json +67 -0
  107. package/scripts/install-deps.sh +38 -0
  108. package/src/commands/apikeys.ts +144 -0
  109. package/src/commands/artifacts.ts +296 -0
  110. package/src/commands/auth.ts +122 -0
  111. package/src/commands/communities.ts +153 -0
  112. package/src/commands/config.ts +144 -0
  113. package/src/commands/conversations.ts +176 -0
  114. package/src/commands/facts.ts +320 -0
  115. package/src/commands/graphrag.ts +149 -0
  116. package/src/commands/memories.ts +332 -0
  117. package/src/commands/patterns.ts +251 -0
  118. package/src/commands/system.ts +102 -0
  119. package/src/commands/topics.ts +354 -0
  120. package/src/index.ts +43 -0
  121. package/src/lib/api-client.ts +68 -0
  122. package/src/lib/auth.ts +42 -0
  123. package/src/lib/config.ts +68 -0
  124. package/src/lib/errors.ts +143 -0
  125. package/src/lib/formatters.ts +123 -0
  126. package/src/lib/spinner.ts +113 -0
  127. package/src/lib/validators.ts +302 -0
  128. package/src/types/index.ts +17 -0
  129. package/tests/__mocks__/chalk.ts +16 -0
  130. package/tests/__mocks__/cli-table3.ts +37 -0
  131. package/tests/__mocks__/configstore.ts +38 -0
  132. package/tests/commands/apikeys.test.ts +179 -0
  133. package/tests/commands/artifacts.test.ts +194 -0
  134. package/tests/commands/auth.test.ts +120 -0
  135. package/tests/commands/communities.test.ts +154 -0
  136. package/tests/commands/config.test.ts +154 -0
  137. package/tests/commands/conversations.test.ts +136 -0
  138. package/tests/commands/facts.test.ts +210 -0
  139. package/tests/commands/graphrag.test.ts +194 -0
  140. package/tests/commands/memories.test.ts +215 -0
  141. package/tests/commands/patterns.test.ts +201 -0
  142. package/tests/commands/system.test.ts +172 -0
  143. package/tests/commands/topics.test.ts +274 -0
  144. package/tests/lib/auth.test.ts +77 -0
  145. package/tests/lib/config.test.ts +50 -0
  146. package/tests/lib/errors.test.ts +126 -0
  147. package/tests/lib/formatters.test.ts +87 -0
  148. package/tsconfig.json +20 -0
package/docs/prd.md ADDED
@@ -0,0 +1,748 @@
1
+ # MemNexus CLI - Product Requirements Document
2
+
3
+ ## Overview
4
+
5
+ The MemNexus CLI (`mx-cli`) is a command-line interface that provides developers with complete access to all mx-core-api endpoints. It enables developers to interact with the MemNexus platform directly from the terminal, facilitating testing, debugging, automation, and integration workflows.
6
+
7
+ ## Goals
8
+
9
+ ### Primary Goals
10
+ - Provide 1:1 coverage of all mx-core-api REST endpoints
11
+ - Offer an intuitive, well-documented developer experience
12
+ - Enable both interactive and scriptable usage patterns
13
+ - Support authentication and configuration management
14
+ - Maintain type safety and validation consistent with mx-core-api
15
+
16
+ ### Secondary Goals
17
+ - Enable easy integration with CI/CD pipelines
18
+ - Support multiple output formats (JSON, table, human-readable)
19
+ - Provide helpful error messages and validation feedback
20
+ - Allow for offline usage with cached schemas (where applicable)
21
+
22
+ ## Non-Goals
23
+ - GUI or web-based interface
24
+ - Real-time monitoring dashboards
25
+ - Direct database access (all operations go through mx-core-api)
26
+ - Support for deprecated or internal-only endpoints
27
+
28
+ ## Technology Stack
29
+
30
+ ### Language & Runtime
31
+ - **TypeScript** with Node.js 18+
32
+ - Leverages existing mx-core-api schemas and type definitions
33
+
34
+ ### Core Dependencies
35
+ - **@memnexus-ai/contracts** - Official TypeScript SDK and API client for mx-core-api
36
+ - Provides type-safe API client with all endpoint methods
37
+ - Auto-generated types from OpenAPI specification
38
+ - Handles HTTP requests via axios
39
+ - Includes request/response type definitions
40
+ - **commander.js** - CLI framework for command/subcommand structure
41
+ - **chalk** - Terminal output coloring
42
+ - **ora** - Loading spinners for async operations
43
+ - **cli-table3** - Pretty table formatting for list outputs
44
+ - **inquirer** - Interactive prompts when needed
45
+ - **configstore** - Configuration persistence
46
+ - **dotenv** - Environment variable management
47
+
48
+ ### Development Dependencies
49
+ - **TypeScript** - Type checking and compilation
50
+ - **Jest** - Testing framework
51
+ - **ts-node** - Development execution
52
+ - **eslint** - Code linting
53
+ - **prettier** - Code formatting
54
+
55
+ ## Architecture
56
+
57
+ ### System Architecture
58
+
59
+ ```
60
+ ┌─────────────┐
61
+ │ mx-cli │ (This CLI tool)
62
+ └──────┬──────┘
63
+
64
+ │ Uses @memnexus-ai/contracts
65
+ │ (TypeScript SDK)
66
+
67
+ ┌──────────────────┐
68
+ │ API Gateway │ (Kong OSS)
69
+ │ (Kong Plugins) │ - CORS handling
70
+ │ │ - Rate limiting
71
+ │ │ - Authentication
72
+ │ │ - Request logging
73
+ └────────┬─────────┘
74
+
75
+ │ Proxies to
76
+
77
+ ┌──────────────────┐
78
+ │ mx-core-api │ (Express.js REST API)
79
+ │ │ - Business logic
80
+ │ │ - Data validation
81
+ └────────┬─────────┘
82
+
83
+ │ Queries
84
+
85
+ ┌──────────────────┐
86
+ │ Neo4j │ (Graph Database)
87
+ │ │ - Memory storage
88
+ │ │ - Relationship graphs
89
+ └──────────────────┘
90
+ ```
91
+
92
+ **Default API Endpoints:**
93
+ - **Production**: `https://api.memnexus.io` (via API Gateway)
94
+ - **Staging**: `https://api-staging.memnexus.io` (via API Gateway)
95
+ - **Development**: Configurable via `MX_API_URL` environment variable
96
+ - Gateway: `http://localhost:8000` (Kong local)
97
+ - Direct: `http://localhost:3000` (mx-core-api for local dev/testing)
98
+
99
+ ### Project Structure
100
+ ```
101
+ mx-cli/
102
+ ├── .github/
103
+ │ └── workflows/
104
+ │ └── publish.yml # GitHub Actions publish workflow
105
+ ├── docs/
106
+ │ └── prd.md
107
+ ├── src/
108
+ │ ├── commands/ # Command implementations
109
+ │ │ ├── memories.ts
110
+ │ │ ├── conversations.ts
111
+ │ │ ├── topics.ts
112
+ │ │ ├── patterns.ts
113
+ │ │ ├── artifacts.ts
114
+ │ │ ├── facts.ts
115
+ │ │ ├── graphrag.ts
116
+ │ │ ├── apikeys.ts
117
+ │ │ ├── system.ts
118
+ │ │ └── auth.ts
119
+ │ ├── lib/ # Shared utilities
120
+ │ │ ├── api-client.ts # Wrapper around @memnexus-ai/contracts
121
+ │ │ ├── auth.ts # Authentication logic
122
+ │ │ ├── config.ts # Configuration management
123
+ │ │ ├── formatters.ts # Output formatting (table, JSON, YAML)
124
+ │ │ ├── validators.ts # Input validation helpers
125
+ │ │ └── errors.ts # Error handling and display
126
+ │ ├── types/ # TypeScript type definitions
127
+ │ │ └── index.ts
128
+ │ └── index.ts # CLI entry point
129
+ ├── tests/
130
+ │ ├── commands/
131
+ │ └── lib/
132
+ ├── package.json
133
+ ├── tsconfig.json
134
+ ├── .eslintrc.js
135
+ ├── .prettierrc
136
+ └── README.md
137
+ ```
138
+
139
+ ### Command Structure
140
+
141
+ The CLI follows a hierarchical command structure:
142
+
143
+ ```
144
+ mx <resource> <action> [options]
145
+ ```
146
+
147
+ Examples:
148
+ ```bash
149
+ # List memories
150
+ mx memories list
151
+
152
+ # Get specific memory
153
+ mx memories get <id>
154
+
155
+ # Start a conversation first (required for creating memories)
156
+ mx conversations start --user-id <userId>
157
+
158
+ # Create memory (requires conversationId from previous step)
159
+ mx memories create --content "..." --conversation-id <conversationId>
160
+
161
+ # Search conversations
162
+ mx conversations search --query "..."
163
+
164
+ # Merge topics
165
+ mx topics merge --sourceId <id> --targetId <id>
166
+ ```
167
+
168
+ ### Configuration Management
169
+
170
+ #### Config File Location
171
+ - **Linux/macOS**: `~/.config/memnexus/config.json`
172
+ - **Windows**: `%APPDATA%/memnexus/config.json`
173
+
174
+ #### Config Structure
175
+ ```json
176
+ {
177
+ "apiUrl": "https://api.memnexus.io",
178
+ "apiKey": "encrypted-api-key",
179
+ "defaultFormat": "table",
180
+ "defaultPageSize": 20
181
+ }
182
+ ```
183
+
184
+ #### Environment Variables
185
+ - `MX_API_URL` - API Gateway endpoint override (default: `https://api.memnexus.io`)
186
+ - `MX_API_KEY` - API key override
187
+ - `MX_OUTPUT_FORMAT` - Output format override (json|table|yaml)
188
+
189
+ #### API Client Integration
190
+
191
+ The CLI uses `@memnexus-ai/contracts` package for all API interactions:
192
+
193
+ ```typescript
194
+ // src/lib/api-client.ts
195
+ import { CoreApiClient, createClient } from '@memnexus-ai/contracts';
196
+ import { getConfig } from './config';
197
+
198
+ export function getApiClient(): CoreApiClient {
199
+ const config = getConfig();
200
+
201
+ return createClient({
202
+ baseURL: config.apiUrl || process.env.MX_API_URL || 'https://api.memnexus.io',
203
+ apiKey: config.apiKey || process.env.MX_API_KEY,
204
+ timeout: 30000
205
+ });
206
+ }
207
+
208
+ // Usage in commands
209
+ // src/commands/memories.ts
210
+ import { getApiClient } from '../lib/api-client';
211
+
212
+ export async function listMemories(options: any) {
213
+ const client = getApiClient();
214
+ const response = await client.memories.list({
215
+ limit: options.limit,
216
+ offset: options.page * options.limit
217
+ });
218
+ // Format and display response...
219
+ }
220
+ ```
221
+
222
+ **Benefits:**
223
+ - Type-safe API calls with auto-generated types from OpenAPI spec
224
+ - Consistent error handling across all commands
225
+ - Automatic updates when API changes (via contracts package updates)
226
+ - No need to manually define request/response types
227
+ - Leverages existing, tested API client code
228
+
229
+ ### Authentication
230
+
231
+ #### API Key Authentication
232
+ 1. User generates API key via mx-core-api or customer portal
233
+ 2. User configures CLI: `mx auth login --api-key <key>`
234
+ 3. CLI encrypts and stores key in config file
235
+ 4. All subsequent requests include API key in header: `X-API-Key: <key>`
236
+
237
+ #### JWT Authentication (Optional/Future)
238
+ - Support for JWT-based authentication for user accounts
239
+ - Token refresh logic
240
+ - Session management
241
+
242
+ ## Feature Requirements
243
+
244
+ ### Core Features
245
+
246
+ #### 1. Memories Management
247
+ Commands for managing memories:
248
+ - `mx memories list [options]` - List memories with pagination
249
+ - Options: `--page`, `--limit`, `--conversation-id`, `--format`
250
+ - `mx memories get <id>` - Get specific memory by ID
251
+ - `mx memories create [options]` - Create new memory
252
+ - **Required**: `--content`, `--conversation-id`
253
+ - **Optional**: `--tags`, `--metadata`, `--memory-type`, `--role`, `--raw-prompt`
254
+ - **Note**: Must have a valid conversationId (create with `mx conversations start` first)
255
+ - Interactive mode if options not provided
256
+ - `mx memories update <id> [options]` - Update memory
257
+ - `mx memories delete <id>` - Delete memory
258
+ - `mx memories search [options]` - Search memories
259
+ - Options: `--query`, `--mode`, `--conversation-id`, `--limit`
260
+
261
+ #### 2. Conversations Management
262
+ Commands for conversation operations:
263
+ - `mx conversations start [options]` - **Start a new conversation** (required before creating memories)
264
+ - **Required**: `--user-id`
265
+ - **Optional**: `--system-prompt`, `--metadata`
266
+ - Returns a conversationId for use in memory creation
267
+ - `mx conversations list [options]` - List conversations
268
+ - `mx conversations get <id>` - Get conversation summary
269
+ - `mx conversations timeline <id>` - Get conversation timeline
270
+ - `mx conversations search [options]` - Search conversations
271
+ - `mx conversations by-topic [options]` - Find by topic
272
+
273
+ #### 3. Topics Management
274
+ Commands for topic operations:
275
+ - `mx topics list [options]` - List topics
276
+ - `mx topics get <id>` - Get topic details
277
+ - `mx topics merge [options]` - Merge topics
278
+ - Options: `--sourceId`, `--targetId`
279
+ - `mx topics discover-related [options]` - Discover related topics
280
+ - `mx topics similarity [options]` - Calculate topic similarity
281
+ - `mx topics find-similar [options]` - Find similar topics
282
+ - `mx topics cluster [options]` - Cluster topics
283
+ - `mx topics detect-communities [options]` - Detect communities
284
+
285
+ #### 4. Communities Management
286
+ Commands for community operations:
287
+ - `mx communities list [options]` - List communities
288
+ - `mx communities get <id>` - Get community details
289
+ - `mx communities merge [options]` - Merge communities
290
+
291
+ #### 5. Patterns Management
292
+ Commands for pattern operations:
293
+ - `mx patterns list [options]` - List patterns
294
+ - `mx patterns compile [options]` - Compile patterns from memories
295
+ - `mx patterns update <id> [options]` - Update pattern
296
+ - `mx patterns feedback [options]` - Record pattern feedback
297
+ - `mx patterns behavior-state` - Get behavioral state
298
+ - `mx patterns set-behavior-state [options]` - Update behavioral state
299
+
300
+ #### 6. Artifacts Management
301
+ Commands for artifact operations:
302
+ - `mx artifacts list [options]` - List artifacts
303
+ - `mx artifacts get <id>` - Get artifact
304
+ - `mx artifacts create [options]` - Create artifact
305
+ - `mx artifacts update <id> [options]` - Update artifact
306
+ - `mx artifacts delete <id>` - Delete artifact
307
+
308
+ #### 7. Facts Management
309
+ Commands for semantic facts:
310
+ - `mx facts list [options]` - List facts
311
+ - `mx facts get <id>` - Get fact
312
+ - `mx facts create [options]` - Create fact
313
+ - `mx facts update <id> [options]` - Update fact
314
+ - `mx facts delete <id>` - Delete fact
315
+ - `mx facts search [options]` - Search facts
316
+
317
+ #### 8. GraphRAG Operations
318
+ Commands for GraphRAG queries:
319
+ - `mx graphrag query [options]` - Execute GraphRAG query
320
+ - Options: `--query`, `--contextId`, `--mode`
321
+ - `mx graphrag explain <resultId>` - Explain query result
322
+ - `mx graphrag query-communities [options]` - Query communities
323
+
324
+ #### 9. API Keys Management
325
+ Commands for API key operations:
326
+ - `mx apikeys list` - List API keys
327
+ - `mx apikeys get <id>` - Get API key details
328
+ - `mx apikeys create [options]` - Create new API key
329
+ - Options: `--name`, `--description`, `--expiresAt`
330
+ - `mx apikeys delete <id>` - Delete API key
331
+
332
+ #### 10. System Operations
333
+ Commands for system information:
334
+ - `mx system health` - Check system health
335
+ - `mx system status` - Get context status
336
+ - `mx system stats` - Get database statistics
337
+ - `mx system clear-cache` - Clear system cache
338
+
339
+ #### 11. Authentication & Configuration
340
+ Commands for CLI setup:
341
+ - `mx auth login [options]` - Configure authentication
342
+ - Options: `--api-key`, `--interactive`
343
+ - `mx auth logout` - Remove stored credentials
344
+ - `mx auth status` - Show current authentication status
345
+ - `mx config set <key> <value>` - Set configuration value
346
+ - `mx config get <key>` - Get configuration value
347
+ - `mx config list` - List all configuration
348
+ - `mx config reset` - Reset to defaults
349
+
350
+ ### Output Formatting
351
+
352
+ #### Supported Formats
353
+ 1. **Table** (default for lists)
354
+ - Human-readable tabular output
355
+ - Truncated fields for terminal width
356
+ - Colored headers and key columns
357
+
358
+ 2. **JSON** (default for single items)
359
+ - Pretty-printed JSON
360
+ - Machine-readable
361
+ - Ideal for scripting
362
+
363
+ 3. **YAML** (optional)
364
+ - Human-readable structured data
365
+ - Good for configuration-like outputs
366
+
367
+ #### Format Selection
368
+ - Global flag: `--format <json|table|yaml>`
369
+ - Config file: `defaultFormat`
370
+ - Environment: `MX_OUTPUT_FORMAT`
371
+
372
+ ### Error Handling
373
+
374
+ #### Error Types
375
+ 1. **Network Errors**
376
+ - Connection timeout
377
+ - DNS resolution failure
378
+ - Certificate errors
379
+
380
+ 2. **API Errors**
381
+ - 401 Unauthorized - Invalid or missing API key
382
+ - 403 Forbidden - Insufficient permissions
383
+ - 404 Not Found - Resource doesn't exist
384
+ - 422 Validation Error - Invalid input
385
+ - 429 Rate Limit - Too many requests
386
+ - 500 Server Error - API internal error
387
+
388
+ 3. **Validation Errors**
389
+ - Missing required arguments
390
+ - Invalid argument types
391
+ - Schema validation failures
392
+
393
+ 4. **Configuration Errors**
394
+ - Missing config file
395
+ - Invalid config format
396
+ - Missing required config values
397
+
398
+ #### Error Display
399
+ - Clear, actionable error messages
400
+ - Suggestions for resolution
401
+ - Exit codes for scripting:
402
+ - `0` - Success
403
+ - `1` - General error
404
+ - `2` - Validation error
405
+ - `3` - Authentication error
406
+ - `4` - Network error
407
+ - `5` - API error
408
+
409
+ ### User Experience Features
410
+
411
+ #### Interactive Mode
412
+ For complex commands, provide interactive prompts when required options are missing:
413
+ ```bash
414
+ $ mx memories create
415
+ ? Enter memory content: This is important information
416
+ ? Enter context ID: ctx_123
417
+ ? Add tags (comma-separated): important, meeting
418
+ ✓ Memory created successfully (mem_456)
419
+ ```
420
+
421
+ #### Progress Indicators
422
+ - Spinners for async operations
423
+ - Progress bars for batch operations
424
+ - Clear success/failure indicators
425
+
426
+ #### Help System
427
+ - Comprehensive help for all commands: `mx <command> --help`
428
+ - Examples in help output
429
+ - Global help: `mx --help`
430
+ - Command discovery: `mx` (no args shows available commands)
431
+
432
+ #### Autocomplete (Future Enhancement)
433
+ - Shell completion scripts for bash/zsh/fish
434
+ - Command and option completion
435
+ - Context-aware suggestions
436
+
437
+ ## Development Plan
438
+
439
+ ### Phase 1: Foundation (Week 1)
440
+ **Goal**: Set up project infrastructure and core utilities
441
+
442
+ - [ ] Initialize TypeScript project with package.json
443
+ - [ ] Add `@memnexus-ai/contracts` dependency for API client
444
+ - [ ] Configure TypeScript, ESLint, Prettier
445
+ - [ ] Set up project structure (src/, tests/, docs/)
446
+ - [ ] Implement configuration management (configstore)
447
+ - [ ] Create API client wrapper around `@memnexus-ai/contracts`
448
+ - [ ] Create authentication helpers
449
+ - [ ] Set up error handling framework
450
+ - [ ] Create output formatters (JSON, table, YAML)
451
+ - [ ] Write basic tests for utilities
452
+
453
+ ### Phase 2: Core Commands (Week 2)
454
+ **Goal**: Implement primary resource commands
455
+
456
+ - [ ] Implement `auth` commands (login, logout, status)
457
+ - [ ] Implement `config` commands (get, set, list, reset)
458
+ - [ ] Implement `conversations start` command (**CRITICAL**: Required before memory creation)
459
+ - [ ] Implement `memories` commands (CRUD + search, requires conversationId)
460
+ - [ ] Implement `conversations` commands (list, get, timeline, search, by-topic)
461
+ - [ ] Implement `facts` commands (CRUD + search)
462
+ - [ ] Write tests for core commands
463
+ - [ ] Create comprehensive help documentation
464
+
465
+ ### Phase 3: Advanced Commands (Week 3)
466
+ **Goal**: Implement advanced features and graph operations
467
+
468
+ - [ ] Implement `topics` commands (including graph operations)
469
+ - [ ] Implement `communities` commands
470
+ - [ ] Implement `patterns` commands
471
+ - [ ] Implement `graphrag` commands
472
+ - [ ] Implement `artifacts` commands
473
+ - [ ] Implement `apikeys` commands
474
+ - [ ] Implement `system` commands
475
+ - [ ] Write tests for advanced commands
476
+
477
+ ### Phase 4: Polish & Distribution (Week 4)
478
+ **Goal**: Prepare for release
479
+
480
+ - [ ] Add interactive prompts for complex commands
481
+ - [ ] Improve error messages and validation
482
+ - [ ] Add progress indicators and spinners
483
+ - [ ] Write comprehensive README with examples
484
+ - [ ] Create usage documentation
485
+ - [ ] Set up GitHub Actions workflow for publishing to GitHub Packages
486
+ - [ ] Configure package.json for GitHub Packages distribution
487
+ - [ ] Test installation and usage across platforms
488
+ - [ ] Create release checklist and versioning strategy
489
+ - [ ] Verify workflow publishes correctly on push to main
490
+ - [ ] Optional: Create standalone binaries with pkg
491
+
492
+ ## Testing Strategy
493
+
494
+ ### Unit Tests
495
+ - Test all utility functions (formatters, validators, config)
496
+ - Test API client wrapper initialization
497
+ - Test error handling and display logic
498
+ - Test command argument parsing
499
+ - Target: 80%+ code coverage
500
+
501
+ ### Integration Tests
502
+ - Test commands against mock API Gateway endpoints
503
+ - Test authentication flows (API key storage/retrieval)
504
+ - Test configuration management (read/write/encrypt)
505
+ - Test output formatting (JSON, table, YAML)
506
+ - Mock `@memnexus-ai/contracts` responses for consistent testing
507
+
508
+ ### Manual Testing
509
+ - Test on Linux, macOS, Windows
510
+ - Test against real API Gateway (dev/staging environments)
511
+ - Test direct connection to mx-core-api (local development)
512
+ - Test edge cases and error scenarios
513
+ - Verify help documentation accuracy
514
+ - Test with different API key permissions
515
+
516
+ ## Success Metrics
517
+
518
+ ### Development Metrics
519
+ - 100% endpoint coverage from mx-core-api
520
+ - 80%+ unit test coverage
521
+ - Zero TypeScript errors
522
+ - Passing CI/CD pipeline
523
+
524
+ ### User Experience Metrics
525
+ - Clear, helpful error messages
526
+ - Intuitive command structure
527
+ - Comprehensive documentation
528
+ - Fast response times (<2s for typical operations)
529
+
530
+ ### Adoption Metrics (Post-Launch)
531
+ - npm downloads
532
+ - GitHub stars/issues
533
+ - User feedback and feature requests
534
+ - Community contributions
535
+
536
+ ## Distribution & Deployment
537
+
538
+ ### GitHub Packages (Primary Distribution)
539
+ - Package name: `@memnexus-ai/cli`
540
+ - Published to GitHub Packages registry: `https://npm.pkg.github.com`
541
+ - Scoped to `@memnexus-ai` organization
542
+ - Semantic versioning (SemVer)
543
+ - Automated publishing via GitHub Actions
544
+ - Git tags created for each release: `cli-v{version}`
545
+ - Automatic GitHub Releases with changelog
546
+
547
+ ### Installation Methods
548
+ ```bash
549
+ # Configure npm to use GitHub Packages for @memnexus-ai scope
550
+ npm config set @memnexus-ai:registry https://npm.pkg.github.com
551
+
552
+ # Authenticate with GitHub (requires GITHUB_TOKEN with read:packages permission)
553
+ npm login --scope=@memnexus-ai --registry=https://npm.pkg.github.com
554
+
555
+ # Install globally
556
+ npm install -g @memnexus-ai/cli
557
+
558
+ # Or install in project
559
+ npm install --save-dev @memnexus-ai/cli
560
+
561
+ # Use via npx (no installation)
562
+ npx @memnexus-ai/cli memories list
563
+ ```
564
+
565
+ ### CI/CD Workflow
566
+ The package is automatically published via GitHub Actions workflow (`.github/workflows/publish.yml`):
567
+
568
+ **Triggers:**
569
+ - Push to `main` branch (with relevant file changes)
570
+ - Manual workflow dispatch with version bump (patch/minor/major)
571
+ - Pull requests for validation only
572
+
573
+ **Workflow Jobs:**
574
+ 1. **Validate** - Lint, build, test, and check package contents
575
+ 2. **Publish** - Publish to GitHub Packages (only on main/manual trigger)
576
+ - Checks if version already exists
577
+ - Publishes package to GitHub Packages
578
+ - Creates git tag (`cli-v{version}`)
579
+ - Creates GitHub Release with installation instructions
580
+
581
+ **Version Management:**
582
+ - Manual version bumps via workflow_dispatch input
583
+ - Prevents duplicate publishes by checking existing versions
584
+ - Follows existing pattern from `@memnexus-ai/contracts` package
585
+
586
+ ### package.json Configuration
587
+ ```json
588
+ {
589
+ "name": "@memnexus-ai/cli",
590
+ "version": "1.0.0",
591
+ "publishConfig": {
592
+ "registry": "https://npm.pkg.github.com",
593
+ "@memnexus-ai:registry": "https://npm.pkg.github.com"
594
+ },
595
+ "repository": {
596
+ "type": "git",
597
+ "url": "https://github.com/memnexus-ai/memnexus.git",
598
+ "directory": "mx-cli"
599
+ }
600
+ }
601
+ ```
602
+
603
+ ### Binary Distribution (Optional/Future)
604
+ - Platform-specific binaries for users without Node.js
605
+ - Hosted on GitHub Releases
606
+ - Supported platforms: Linux (x64), macOS (x64, arm64), Windows (x64)
607
+ - Built with `pkg` or similar tool
608
+
609
+ ## Future Enhancements
610
+
611
+ ### Version 1.1+
612
+ - Shell autocomplete support (bash, zsh, fish)
613
+ - Batch operations (bulk create, update, delete)
614
+ - Import/export capabilities (JSON, CSV)
615
+ - Dry-run mode for destructive operations
616
+ - Verbose/debug logging mode
617
+ - Plugins/extensions system
618
+
619
+ ### Version 2.0+
620
+ - TUI (Terminal UI) mode with terminal-kit or blessed
621
+ - Watch mode for real-time updates
622
+ - Local caching for offline usage
623
+ - GraphQL support (if API adds GraphQL)
624
+ - WebSocket support for real-time features
625
+
626
+ ## Security Considerations
627
+
628
+ ### API Key Storage
629
+ - Encrypt API keys before storing in config file
630
+ - Use keytar or similar for OS-level keychain integration (future)
631
+ - Never log API keys
632
+ - Warn users about key exposure in scripts
633
+
634
+ ### HTTPS Enforcement
635
+ - Always use HTTPS for API requests
636
+ - Validate SSL certificates
637
+ - Allow certificate bypass only with explicit flag (for development)
638
+
639
+ ### Input Sanitization
640
+ - Validate all user inputs with Zod schemas
641
+ - Prevent command injection
642
+ - Escape special characters in outputs
643
+
644
+ ## Documentation Requirements
645
+
646
+ ### README.md
647
+ - Installation instructions
648
+ - Quick start guide
649
+ - Basic usage examples
650
+ - Configuration guide
651
+ - Link to full documentation
652
+
653
+ ### docs/usage.md
654
+ - Comprehensive command reference
655
+ - Advanced usage patterns
656
+ - Scripting examples
657
+ - Troubleshooting guide
658
+
659
+ ### docs/development.md
660
+ - Development setup
661
+ - Contributing guidelines
662
+ - Architecture overview
663
+ - Testing guidelines
664
+
665
+ ### Inline Documentation
666
+ - JSDoc comments for all public functions
667
+ - Help text for all commands and options
668
+ - Examples in command help output
669
+
670
+ ## Open Questions
671
+
672
+ 1. **Binary Distribution**: Should we prioritize standalone binaries in v1.0, or focus on npm distribution first?
673
+ - *Recommendation*: Focus on npm/GitHub Packages first, add binaries in v1.1+
674
+
675
+ 2. **Authentication**: Should we support JWT authentication from day one, or start with API keys only?
676
+ - *Recommendation*: Start with API keys only (simpler, matches current contracts package)
677
+
678
+ 3. **Caching**: Should we implement local caching of frequently accessed data to reduce API calls?
679
+ - *Recommendation*: No caching in v1.0, add in v1.1+ if needed
680
+
681
+ 4. **Telemetry**: Should we collect anonymous usage telemetry to improve the CLI (opt-in)?
682
+ - *Recommendation*: No telemetry in v1.0, consider for v2.0+
683
+
684
+ 5. **Versioning**: How should we handle CLI version compatibility with mx-core-api versions?
685
+ - *Recommendation*: Pin to compatible `@memnexus-ai/contracts` version in package.json
686
+ - Document required contracts version in README
687
+ - Use semantic versioning to indicate breaking changes
688
+
689
+ 6. **Contracts Package Updates**: How often should we update the `@memnexus-ai/contracts` dependency?
690
+ - *Recommendation*: Update on each CLI release to stay in sync with API changes
691
+ - Use `^` semver range to allow patch updates automatically
692
+
693
+ ## CLI-API Synchronization
694
+
695
+ For maintaining sync between the CLI and API during development, see these comprehensive strategy documents:
696
+
697
+ ### [CLI-API Sync Strategy](./sync-strategy.md)
698
+ How to keep types, versions, and contracts in sync:
699
+ - OpenAPI specification as single source of truth
700
+ - Automated SDK generation via `openapi-typescript`
701
+ - Contract testing with Dredd/Prism
702
+ - Semantic versioning with exact pinning in v1.0
703
+ - Automated dependency updates via Dependabot
704
+ - Breaking change detection with `oasdiff`
705
+
706
+ ### [Code Generation Strategy](./code-generation-strategy.md)
707
+ How CLI command code is created/updated when APIs change:
708
+ - Why types auto-sync but commands don't
709
+ - Hybrid approach: scaffolding + manual implementation
710
+ - Coverage detection to catch missing commands (Phase 2)
711
+ - Command scaffold generator (Phase 3)
712
+ - Metadata-driven commands via OpenAPI extensions (Phase 4)
713
+
714
+ **TL;DR**: Types sync automatically via `@memnexus-ai/contracts`, but CLI commands require manual implementation in v1.0. Post-v1.0, we'll add scaffolding generators to speed this up.
715
+
716
+ ## Appendix
717
+
718
+ ### Reference Materials
719
+ - **CLI-API Sync Strategy**: [docs/sync-strategy.md](./sync-strategy.md)
720
+ - Complete workflow for keeping CLI in sync with API changes
721
+ - Version management strategy
722
+ - Contract testing setup
723
+ - CI/CD integration
724
+ - **@memnexus-ai/contracts package**: `/workspaces/memnexus/mx-api-gateway/contracts/`
725
+ - TypeScript SDK and API client (primary dependency)
726
+ - OpenAPI specification: `openapi.yaml` and `openapi.json`
727
+ - Auto-generated types: `src/generated/schema.ts`
728
+ - **API Gateway configuration**: `/workspaces/memnexus/mx-api-gateway/config/kong.yaml`
729
+ - Kong routing and plugin configuration
730
+ - Endpoint definitions and authentication setup
731
+ - **mx-core-api**: `/workspaces/memnexus/mx-core-api/`
732
+ - Backend API implementation
733
+ - Request/response schemas: `src/schemas/`
734
+ - Architecture docs: `docs/`
735
+
736
+ ### Inspiration & Prior Art
737
+ - **AWS CLI** - Command structure and output formatting
738
+ - **Heroku CLI** - User experience and interactive flows
739
+ - **GitHub CLI (gh)** - Modern CLI patterns and help system
740
+ - **Firebase CLI** - Configuration management
741
+ - **Stripe CLI** - API key authentication patterns
742
+
743
+ ---
744
+
745
+ **Document Version**: 1.0
746
+ **Last Updated**: 2025-11-13
747
+ **Author**: Claude Code
748
+ **Status**: Draft - Pending Review