@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
@@ -0,0 +1,533 @@
1
+ # CLI-API Sync Strategy
2
+
3
+ ## Overview
4
+
5
+ This document outlines the strategy for keeping the mx-cli in sync with mx-core-api during active development. The goal is to ensure that CLI commands always work correctly with the latest API changes while maintaining version compatibility and preventing breaking changes from affecting users.
6
+
7
+ ## Current Architecture
8
+
9
+ ```
10
+ mx-core-api (OpenAPI spec)
11
+ ↓ (generates)
12
+ @memnexus-ai/contracts (TypeScript SDK)
13
+ ↓ (dependency)
14
+ @memnexus-ai/cli (CLI tool)
15
+ ```
16
+
17
+ **Key Insight**: The `@memnexus-ai/contracts` package serves as the intermediary layer between the API and CLI, providing type safety and automatic synchronization.
18
+
19
+ ## Important Note: Code Generation
20
+
21
+ **Question**: What updates the actual CLI command code when APIs change?
22
+
23
+ **Answer**: See **[Code Generation Strategy](./code-generation-strategy.md)** for the complete answer.
24
+
25
+ **Summary**:
26
+ - ✅ **Types sync automatically** via `@memnexus-ai/contracts`
27
+ - ❌ **CLI commands are manual** (for v1.0)
28
+ - 🔧 **Future**: Hybrid scaffolding generator (post-v1.0)
29
+ - 📊 **Solution**: Coverage detection alerts when commands are missing
30
+
31
+ This document covers type safety, contract testing, and version management. The code generation strategy document covers how to implement new CLI commands efficiently.
32
+
33
+ ## Sync Strategy
34
+
35
+ ### 1. OpenAPI as Single Source of Truth
36
+
37
+ **Principle**: The OpenAPI specification in mx-core-api is the canonical definition of the API contract.
38
+
39
+ **Implementation**:
40
+ - OpenAPI spec lives in: `/mx-api-gateway/contracts/openapi.yaml`
41
+ - All API changes MUST update the OpenAPI spec first (API-first development)
42
+ - TypeScript types are auto-generated from OpenAPI via `openapi-typescript`
43
+
44
+ **Benefits**:
45
+ - ✅ Single source of truth for API structure
46
+ - ✅ Prevents API drift between services
47
+ - ✅ Enables automatic SDK generation
48
+ - ✅ Powers contract testing
49
+
50
+ ### 2. Automated SDK Generation
51
+
52
+ **Tool**: `openapi-typescript` (already in use by contracts package)
53
+
54
+ **Workflow**:
55
+ ```bash
56
+ # In mx-api-gateway/contracts/
57
+ npm run generate:sdk # Generates src/generated/schema.ts from openapi.yaml
58
+ npm run build # Compiles TypeScript
59
+ npm run test # Validates generated code
60
+ ```
61
+
62
+ **Integration Points**:
63
+ - Generation happens automatically in the `@memnexus-ai/contracts` build process
64
+ - CLI inherits types via dependency on `@memnexus-ai/contracts`
65
+ - No manual type definitions needed in CLI
66
+
67
+ ### 3. Contract Testing
68
+
69
+ **Purpose**: Verify that the API implementation matches the OpenAPI specification and that the CLI works with the actual API.
70
+
71
+ **Recommended Tools**:
72
+
73
+ #### Option A: Dredd (Lightweight, CLI-focused)
74
+ ```bash
75
+ # Install
76
+ npm install -g dredd
77
+
78
+ # Run contract tests
79
+ dredd openapi.yaml http://localhost:3000
80
+ ```
81
+
82
+ **Pros**: Simple, fast, good for CI/CD
83
+ **Cons**: Basic validation only
84
+
85
+ #### Option B: Prism (Mock server + validation)
86
+ ```bash
87
+ # Install
88
+ npm install -g @stoplight/prism-cli
89
+
90
+ # Run mock server during development
91
+ prism mock openapi.yaml
92
+
93
+ # Run validation proxy
94
+ prism proxy openapi.yaml http://localhost:3000
95
+ ```
96
+
97
+ **Pros**: Can mock API during CLI development, validates requests/responses
98
+ **Cons**: More complex setup
99
+
100
+ #### Option C: Postman/Newman (Already in use)
101
+ The repo already has Postman collection sync in the contracts workflow. Can extend this for CLI testing.
102
+
103
+ **Recommendation**: Use **Prism** for development (instant feedback) + **Dredd** in CI/CD (automated validation)
104
+
105
+ ### 4. Version Management Strategy
106
+
107
+ #### Semantic Versioning (SemVer)
108
+
109
+ All packages follow strict semantic versioning:
110
+
111
+ **Format**: `MAJOR.MINOR.PATCH`
112
+
113
+ **Rules**:
114
+ - **MAJOR**: Breaking changes (incompatible API changes)
115
+ - **MINOR**: New features (backward compatible)
116
+ - **PATCH**: Bug fixes (backward compatible)
117
+
118
+ #### Version Coupling Strategy
119
+
120
+ **Tight Coupling** (Recommended for v1.0):
121
+ ```json
122
+ // mx-cli/package.json
123
+ {
124
+ "dependencies": {
125
+ "@memnexus-ai/contracts": "1.0.4" // Exact version pinning
126
+ }
127
+ }
128
+ ```
129
+
130
+ **Pros**:
131
+ - ✅ Guaranteed compatibility
132
+ - ✅ Predictable behavior
133
+ - ✅ Easy to debug
134
+
135
+ **Cons**:
136
+ - ❌ Requires CLI release for every contracts update
137
+ - ❌ Manual version bumps
138
+
139
+ **Loose Coupling** (Consider for v1.1+):
140
+ ```json
141
+ // mx-cli/package.json
142
+ {
143
+ "dependencies": {
144
+ "@memnexus-ai/contracts": "^1.0.0" // Allow minor/patch updates
145
+ }
146
+ }
147
+ ```
148
+
149
+ **Pros**:
150
+ - ✅ Automatic compatibility with new features
151
+ - ✅ Bug fixes flow through automatically
152
+
153
+ **Cons**:
154
+ - ❌ Risk of unexpected behavior
155
+ - ❌ Harder to reproduce issues
156
+
157
+ **Recommendation**: Start with exact pinning, move to `^` (caret) after v1.0 stabilizes.
158
+
159
+ ### 5. Development Workflow
160
+
161
+ #### Daily Development Flow
162
+
163
+ ```mermaid
164
+ graph TD
165
+ A[Developer changes API] --> B[Update OpenAPI spec]
166
+ B --> C[Run contracts build]
167
+ C --> D[Generate TypeScript types]
168
+ D --> E[Run contract tests]
169
+ E --> F{Tests pass?}
170
+ F -->|Yes| G[Commit changes]
171
+ F -->|No| A
172
+ G --> H[Publish contracts package]
173
+ H --> I[Update CLI dependency]
174
+ I --> J[Test CLI commands]
175
+ J --> K[Publish CLI]
176
+ ```
177
+
178
+ #### Step-by-Step Process
179
+
180
+ **1. API Change in mx-core-api**
181
+ ```bash
182
+ # Developer adds new endpoint to mx-core-api
183
+ cd /workspaces/memnexus/mx-core-api
184
+ # Add route, controller, schema
185
+ ```
186
+
187
+ **2. Update OpenAPI Spec**
188
+ ```bash
189
+ cd /workspaces/memnexus/mx-api-gateway/contracts
190
+ # Edit openapi.yaml to add new endpoint
191
+ vim openapi.yaml
192
+ ```
193
+
194
+ **3. Regenerate SDK**
195
+ ```bash
196
+ # Auto-generates TypeScript types
197
+ npm run generate:sdk
198
+ npm run build
199
+ npm run test
200
+ ```
201
+
202
+ **4. Run Contract Tests**
203
+ ```bash
204
+ # Validate API matches spec
205
+ prism proxy openapi.yaml http://localhost:3000
206
+
207
+ # Or use Dredd
208
+ dredd openapi.yaml http://localhost:3000
209
+ ```
210
+
211
+ **5. Publish Contracts Package** (if tests pass)
212
+ ```bash
213
+ # Via GitHub Actions workflow_dispatch
214
+ # Or manual:
215
+ npm version patch
216
+ git push origin main
217
+ git push --tags
218
+ ```
219
+
220
+ **6. Update CLI Dependency**
221
+ ```bash
222
+ cd /workspaces/memnexus/mx-cli
223
+ npm install @memnexus-ai/contracts@latest
224
+ ```
225
+
226
+ **7. Add CLI Command** (if new endpoint)
227
+ ```bash
228
+ # Add new command implementation
229
+ vim src/commands/new-feature.ts
230
+ ```
231
+
232
+ **8. Test CLI Against Real API**
233
+ ```bash
234
+ # Integration testing
235
+ npm run build
236
+ ./bin/mx new-feature list --api-url http://localhost:3000
237
+ ```
238
+
239
+ **9. Publish CLI**
240
+ ```bash
241
+ # Via GitHub Actions workflow_dispatch
242
+ ```
243
+
244
+ ### 6. CI/CD Integration
245
+
246
+ #### Contracts Package CI/CD (Already Exists)
247
+ ```yaml
248
+ # .github/workflows/publish-contracts.yaml
249
+ jobs:
250
+ validate:
251
+ - Lint OpenAPI spec
252
+ - Generate SDK
253
+ - Run tests
254
+
255
+ publish:
256
+ - Bump version
257
+ - Publish to GitHub Packages
258
+ - Create git tag
259
+ ```
260
+
261
+ #### CLI Package CI/CD (Already Created)
262
+ ```yaml
263
+ # .github/workflows/publish.yml
264
+ jobs:
265
+ validate:
266
+ - Lint code
267
+ - Build
268
+ - Run tests
269
+
270
+ publish:
271
+ - Bump version
272
+ - Publish to GitHub Packages
273
+ - Create git tag
274
+ ```
275
+
276
+ #### Proposed: Add Contract Testing to Both
277
+
278
+ **Add to contracts workflow**:
279
+ ```yaml
280
+ # .github/workflows/publish-contracts.yaml
281
+ jobs:
282
+ contract-tests:
283
+ runs-on: ubuntu-latest
284
+ steps:
285
+ - name: Start mx-core-api
286
+ run: |
287
+ docker-compose up -d mx-core-api
288
+ # Wait for API to be ready
289
+
290
+ - name: Run Dredd contract tests
291
+ run: |
292
+ npm install -g dredd
293
+ dredd openapi.yaml http://localhost:3000
294
+ ```
295
+
296
+ **Add to CLI workflow**:
297
+ ```yaml
298
+ # .github/workflows/publish.yml
299
+ jobs:
300
+ integration-tests:
301
+ runs-on: ubuntu-latest
302
+ steps:
303
+ - name: Start mock API with Prism
304
+ run: |
305
+ npm install -g @stoplight/prism-cli
306
+ prism mock contracts/openapi.yaml &
307
+
308
+ - name: Run CLI integration tests
309
+ run: |
310
+ npm run test:integration
311
+ ```
312
+
313
+ ### 7. Automated Dependency Updates
314
+
315
+ #### Option A: Dependabot (GitHub Native)
316
+ ```yaml
317
+ # .github/dependabot.yml
318
+ version: 2
319
+ updates:
320
+ - package-ecosystem: "npm"
321
+ directory: "/mx-cli"
322
+ schedule:
323
+ interval: "daily"
324
+ allow:
325
+ - dependency-name: "@memnexus-ai/contracts"
326
+ commit-message:
327
+ prefix: "chore(deps)"
328
+ ```
329
+
330
+ **Pros**: Free, built into GitHub, automatic PRs
331
+ **Cons**: Can be noisy, requires manual review
332
+
333
+ #### Option B: Renovate (More Configurable)
334
+ ```json
335
+ // renovate.json
336
+ {
337
+ "extends": ["config:base"],
338
+ "packageRules": [
339
+ {
340
+ "matchPackagePatterns": ["@memnexus-ai/*"],
341
+ "groupName": "memnexus packages",
342
+ "automerge": false,
343
+ "schedule": ["before 9am on monday"]
344
+ }
345
+ ]
346
+ }
347
+ ```
348
+
349
+ **Pros**: Highly configurable, better monorepo support
350
+ **Cons**: Requires setup
351
+
352
+ **Recommendation**: Start with **Dependabot** for simplicity, migrate to **Renovate** if more control needed.
353
+
354
+ ### 8. Breaking Change Management
355
+
356
+ #### Detecting Breaking Changes
357
+
358
+ **Automated Tools**:
359
+ - `oasdiff` - Detects breaking changes in OpenAPI specs
360
+ - `openapi-diff` - Alternative tool
361
+
362
+ ```bash
363
+ # Install
364
+ npm install -g oasdiff
365
+
366
+ # Compare versions
367
+ oasdiff diff openapi-old.yaml openapi-new.yaml
368
+ ```
369
+
370
+ **Integration**:
371
+ ```yaml
372
+ # .github/workflows/publish-contracts.yaml
373
+ jobs:
374
+ breaking-change-check:
375
+ steps:
376
+ - name: Check for breaking changes
377
+ run: |
378
+ oasdiff breaking openapi-old.yaml openapi.yaml
379
+ if [ $? -eq 1 ]; then
380
+ echo "::error::Breaking changes detected!"
381
+ exit 1
382
+ fi
383
+ ```
384
+
385
+ #### Handling Breaking Changes
386
+
387
+ **Process**:
388
+ 1. **Detect**: Automated check in CI/CD
389
+ 2. **Document**: Add to CHANGELOG.md with migration guide
390
+ 3. **Version**: Bump MAJOR version in contracts package
391
+ 4. **Notify**: Create GitHub issue, notify in PR
392
+ 5. **Update CLI**: Update CLI code to handle new contract
393
+ 6. **Version CLI**: Bump MAJOR version in CLI package
394
+ 7. **Deprecation**: Keep old version available if possible
395
+
396
+ **Example Migration**:
397
+ ```typescript
398
+ // v1.x - Old API
399
+ client.memories.list({ limit: 10 })
400
+
401
+ // v2.x - Breaking change (renamed parameter)
402
+ client.memories.list({ pageSize: 10 })
403
+
404
+ // CLI handles both versions
405
+ if (contractsVersion.startsWith('1.')) {
406
+ await client.memories.list({ limit: options.limit });
407
+ } else {
408
+ await client.memories.list({ pageSize: options.limit });
409
+ }
410
+ ```
411
+
412
+ ### 9. Monitoring and Alerts
413
+
414
+ #### Version Compatibility Dashboard
415
+
416
+ **Recommended**: Create a simple status page showing:
417
+ - Current mx-core-api version
418
+ - Current @memnexus-ai/contracts version
419
+ - Current @memnexus-ai/cli version
420
+ - Compatibility matrix
421
+
422
+ **Implementation**:
423
+ ```bash
424
+ # Can be a simple GitHub README badge
425
+ ![CLI Version](https://img.shields.io/github/package-json/v/memnexus-ai/memnexus?filename=mx-cli%2Fpackage.json)
426
+ ![Contracts Version](https://img.shields.io/github/package-json/v/memnexus-ai/mx-api-gateway?filename=contracts%2Fpackage.json)
427
+ ```
428
+
429
+ #### Slack/Discord Notifications
430
+
431
+ **On contracts package publish**:
432
+ ```yaml
433
+ - name: Notify team
434
+ uses: 8398a7/action-slack@v3
435
+ with:
436
+ status: custom
437
+ text: |
438
+ 📦 New @memnexus-ai/contracts v${{ steps.version.outputs.version }} published
439
+ 🔗 Update CLI: npm install @memnexus-ai/contracts@${{ steps.version.outputs.version }}
440
+ ```
441
+
442
+ ### 10. Documentation Sync
443
+
444
+ **Keep docs in sync automatically**:
445
+
446
+ ```yaml
447
+ # .github/workflows/sync-docs.yml
448
+ name: Sync API Documentation
449
+
450
+ on:
451
+ workflow_run:
452
+ workflows: ["Publish Contracts Package"]
453
+ types: [completed]
454
+
455
+ jobs:
456
+ update-cli-docs:
457
+ runs-on: ubuntu-latest
458
+ steps:
459
+ - name: Generate CLI docs from OpenAPI
460
+ run: |
461
+ npm install -g widdershins
462
+ widdershins openapi.yaml -o CLI_API_REFERENCE.md
463
+
464
+ - name: Create PR to update CLI docs
465
+ uses: peter-evans/create-pull-request@v5
466
+ with:
467
+ title: "docs: update API reference from contracts v${{ version }}"
468
+ body: "Automated update from contracts package"
469
+ ```
470
+
471
+ ## Recommended Tooling Setup
472
+
473
+ ### Phase 1: Immediate (Week 1)
474
+ - [x] Use existing `@memnexus-ai/contracts` as intermediary
475
+ - [ ] Pin exact version in CLI's package.json
476
+ - [ ] Add contract tests to contracts CI/CD (Dredd)
477
+ - [ ] Document version compatibility in CLI README
478
+
479
+ ### Phase 2: Short-term (Week 2-4)
480
+ - [ ] Set up Dependabot for automated dependency updates
481
+ - [ ] Add breaking change detection (oasdiff) to contracts workflow
482
+ - [ ] Create version compatibility badge/dashboard
483
+ - [ ] Add Prism mock server to CLI development workflow
484
+
485
+ ### Phase 3: Medium-term (Month 2)
486
+ - [ ] Implement automated CLI integration tests against Prism
487
+ - [ ] Set up Slack/Discord notifications for new releases
488
+ - [ ] Create migration guides for breaking changes
489
+ - [ ] Consider loose version coupling (^1.0.0) after stabilization
490
+
491
+ ### Phase 4: Long-term (Month 3+)
492
+ - [ ] Evaluate Changesets for monorepo-wide versioning
493
+ - [ ] Implement automated documentation generation
494
+ - [ ] Add telemetry to track CLI version distribution
495
+ - [ ] Consider API versioning strategy (v1, v2, etc.)
496
+
497
+ ## Key Takeaways
498
+
499
+ 1. **OpenAPI First**: Always update the spec before changing the API
500
+ 2. **Contracts as Bridge**: Let `@memnexus-ai/contracts` handle API changes
501
+ 3. **Exact Pinning**: Start with exact versions for stability
502
+ 4. **Automate Testing**: Contract tests catch breaking changes early
503
+ 5. **Clear Versioning**: Follow SemVer strictly
504
+ 6. **Fast Feedback**: Use Prism during development
505
+ 7. **Monitor Compatibility**: Keep version dashboard updated
506
+ 8. **Document Everything**: Migration guides for breaking changes
507
+
508
+ ## Success Metrics
509
+
510
+ **Short-term**:
511
+ - ✅ Zero "API not found" errors in CLI
512
+ - ✅ All CI/CD pipelines passing
513
+ - ✅ <1 day lag between API changes and CLI updates
514
+
515
+ **Long-term**:
516
+ - ✅ Zero breaking changes without MAJOR version bump
517
+ - ✅ <1 hour from API change to contracts publish
518
+ - ✅ 100% OpenAPI spec coverage
519
+ - ✅ Automated contract test success rate >95%
520
+
521
+ ## References
522
+
523
+ - **Stripe's Approach**: https://docs.stripe.com/libraries/set-version
524
+ - **Contract Testing with OpenAPI**: https://www.speakeasy.com/blog/contract-testing-with-openapi
525
+ - **Monorepo Versioning**: https://turbo.build/repo/docs/handbook/publishing-packages/versioning-and-publishing
526
+ - **OpenAPI Tools**: https://openapi.tools/
527
+
528
+ ---
529
+
530
+ **Document Version**: 1.0
531
+ **Last Updated**: 2025-11-13
532
+ **Author**: Claude Code
533
+ **Status**: Proposed Strategy
package/jest.config.js ADDED
@@ -0,0 +1,30 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ roots: ['<rootDir>/tests'],
5
+ testMatch: ['**/*.test.ts'],
6
+ collectCoverageFrom: ['src/**/*.ts', '!src/index.ts', '!src/**/*.d.ts'],
7
+ coverageThreshold: {
8
+ global: {
9
+ branches: 70,
10
+ functions: 70,
11
+ lines: 70,
12
+ statements: 70,
13
+ },
14
+ },
15
+ moduleNameMapper: {
16
+ '^@/(.*)$': '<rootDir>/src/$1',
17
+ '^chalk$': '<rootDir>/tests/__mocks__/chalk.ts',
18
+ '^configstore$': '<rootDir>/tests/__mocks__/configstore.ts',
19
+ '^cli-table3$': '<rootDir>/tests/__mocks__/cli-table3.ts',
20
+ },
21
+ transform: {
22
+ '^.+\\.ts$': [
23
+ 'ts-jest',
24
+ {
25
+ useESM: false,
26
+ isolatedModules: true,
27
+ },
28
+ ],
29
+ },
30
+ };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@memnexus-ai/cli",
3
+ "version": "0.1.0",
4
+ "description": "Command-line interface for MemNexus Core API",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "mx": "./bin/mx.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "dev": "ts-node src/index.ts",
12
+ "test": "jest",
13
+ "test:watch": "jest --watch",
14
+ "test:coverage": "jest --coverage",
15
+ "lint": "eslint 'src/**/*.ts'",
16
+ "lint:fix": "eslint 'src/**/*.ts' --fix",
17
+ "format": "prettier --write 'src/**/*.ts'",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "keywords": [
21
+ "memnexus",
22
+ "cli",
23
+ "api",
24
+ "memory",
25
+ "ai"
26
+ ],
27
+ "author": "MemNexus Team",
28
+ "license": "UNLICENSED",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/memnexus-ai/mx-cli.git"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "engines": {
37
+ "node": ">=18.0.0"
38
+ },
39
+ "dependencies": {
40
+ "@memnexus-ai/mx-typescript-sdk": "^1.0.10",
41
+ "axios": "^1.13.2",
42
+ "chalk": "^5.3.0",
43
+ "cli-table3": "^0.6.3",
44
+ "commander": "^11.1.0",
45
+ "configstore": "^7.0.0",
46
+ "dotenv": "^16.3.1",
47
+ "inquirer": "^9.2.12",
48
+ "js-yaml": "^4.1.0",
49
+ "ora": "^7.0.1"
50
+ },
51
+ "devDependencies": {
52
+ "@types/inquirer": "^9.0.7",
53
+ "@types/jest": "^29.5.8",
54
+ "@types/js-yaml": "^4.0.9",
55
+ "@types/node": "^20.10.0",
56
+ "@typescript-eslint/eslint-plugin": "^6.13.2",
57
+ "@typescript-eslint/parser": "^6.13.2",
58
+ "eslint": "^8.55.0",
59
+ "eslint-config-prettier": "^9.1.0",
60
+ "eslint-plugin-prettier": "^5.0.1",
61
+ "jest": "^29.7.0",
62
+ "prettier": "^3.1.0",
63
+ "ts-jest": "^29.1.1",
64
+ "ts-node": "^10.9.2",
65
+ "typescript": "^5.3.3"
66
+ }
67
+ }
@@ -0,0 +1,38 @@
1
+ #!/bin/bash
2
+ # Install dependencies with GitHub Packages authentication
3
+ # This script uses gh CLI to authenticate with GitHub Packages
4
+
5
+ set -e
6
+
7
+ echo "🔐 Setting up GitHub Packages authentication..."
8
+
9
+ # Check if gh CLI is available
10
+ if ! command -v gh &> /dev/null; then
11
+ echo "❌ Error: gh CLI is not installed"
12
+ echo "Please install it from: https://cli.github.com/"
13
+ exit 1
14
+ fi
15
+
16
+ # Check if gh is authenticated
17
+ if ! gh auth status &> /dev/null; then
18
+ echo "❌ Error: gh CLI is not authenticated"
19
+ echo "Please run: gh auth login"
20
+ exit 1
21
+ fi
22
+
23
+ # Get the GitHub token
24
+ GITHUB_TOKEN=$(gh auth token)
25
+
26
+ if [ -z "$GITHUB_TOKEN" ]; then
27
+ echo "❌ Error: Could not get GitHub token"
28
+ exit 1
29
+ fi
30
+
31
+ echo "✅ GitHub authentication configured"
32
+ echo "📦 Installing dependencies..."
33
+
34
+ # Install with the token
35
+ GITHUB_TOKEN=$GITHUB_TOKEN npm install
36
+
37
+ echo "✅ Dependencies installed successfully!"
38
+