@yeseh/cortex-cli 0.6.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 (189) hide show
  1. package/README.md +144 -0
  2. package/dist/category/commands/create.d.ts +44 -0
  3. package/dist/category/commands/create.d.ts.map +1 -0
  4. package/dist/category/commands/create.spec.d.ts +7 -0
  5. package/dist/category/commands/create.spec.d.ts.map +1 -0
  6. package/dist/category/index.d.ts +19 -0
  7. package/dist/category/index.d.ts.map +1 -0
  8. package/dist/commands/init.d.ts +58 -0
  9. package/dist/commands/init.d.ts.map +1 -0
  10. package/dist/commands/init.spec.d.ts +2 -0
  11. package/dist/commands/init.spec.d.ts.map +1 -0
  12. package/dist/context.d.ts +18 -0
  13. package/dist/context.d.ts.map +1 -0
  14. package/dist/context.spec.d.ts +2 -0
  15. package/dist/context.spec.d.ts.map +1 -0
  16. package/dist/create-cli-command.d.ts +23 -0
  17. package/dist/create-cli-command.d.ts.map +1 -0
  18. package/dist/create-cli-command.spec.d.ts +10 -0
  19. package/dist/create-cli-command.spec.d.ts.map +1 -0
  20. package/dist/errors.d.ts +57 -0
  21. package/dist/errors.d.ts.map +1 -0
  22. package/dist/errors.spec.d.ts +2 -0
  23. package/dist/errors.spec.d.ts.map +1 -0
  24. package/dist/input.d.ts +42 -0
  25. package/dist/input.d.ts.map +1 -0
  26. package/dist/input.spec.d.ts +2 -0
  27. package/dist/input.spec.d.ts.map +1 -0
  28. package/dist/memory/commands/add.d.ts +62 -0
  29. package/dist/memory/commands/add.d.ts.map +1 -0
  30. package/dist/memory/commands/add.spec.d.ts +7 -0
  31. package/dist/memory/commands/add.spec.d.ts.map +1 -0
  32. package/dist/memory/commands/definitions.spec.d.ts +10 -0
  33. package/dist/memory/commands/definitions.spec.d.ts.map +1 -0
  34. package/dist/memory/commands/handlers.spec.d.ts +2 -0
  35. package/dist/memory/commands/handlers.spec.d.ts.map +1 -0
  36. package/dist/memory/commands/list.d.ts +119 -0
  37. package/dist/memory/commands/list.d.ts.map +1 -0
  38. package/dist/memory/commands/list.spec.d.ts +2 -0
  39. package/dist/memory/commands/list.spec.d.ts.map +1 -0
  40. package/dist/memory/commands/move.d.ts +42 -0
  41. package/dist/memory/commands/move.d.ts.map +1 -0
  42. package/dist/memory/commands/move.spec.d.ts +2 -0
  43. package/dist/memory/commands/move.spec.d.ts.map +1 -0
  44. package/dist/memory/commands/remove.d.ts +41 -0
  45. package/dist/memory/commands/remove.d.ts.map +1 -0
  46. package/dist/memory/commands/remove.spec.d.ts +2 -0
  47. package/dist/memory/commands/remove.spec.d.ts.map +1 -0
  48. package/dist/memory/commands/show.d.ts +81 -0
  49. package/dist/memory/commands/show.d.ts.map +1 -0
  50. package/dist/memory/commands/show.spec.d.ts +2 -0
  51. package/dist/memory/commands/show.spec.d.ts.map +1 -0
  52. package/dist/memory/commands/test-helpers.spec.d.ts +19 -0
  53. package/dist/memory/commands/test-helpers.spec.d.ts.map +1 -0
  54. package/dist/memory/commands/update.d.ts +73 -0
  55. package/dist/memory/commands/update.d.ts.map +1 -0
  56. package/dist/memory/commands/update.spec.d.ts +2 -0
  57. package/dist/memory/commands/update.spec.d.ts.map +1 -0
  58. package/dist/memory/index.d.ts +29 -0
  59. package/dist/memory/index.d.ts.map +1 -0
  60. package/dist/memory/index.spec.d.ts +10 -0
  61. package/dist/memory/index.spec.d.ts.map +1 -0
  62. package/dist/memory/parsing.d.ts +3 -0
  63. package/dist/memory/parsing.d.ts.map +1 -0
  64. package/dist/memory/parsing.spec.d.ts +7 -0
  65. package/dist/memory/parsing.spec.d.ts.map +1 -0
  66. package/dist/output.d.ts +87 -0
  67. package/dist/output.d.ts.map +1 -0
  68. package/dist/output.spec.d.ts +2 -0
  69. package/dist/output.spec.d.ts.map +1 -0
  70. package/dist/paths.d.ts +27 -0
  71. package/dist/paths.d.ts.map +1 -0
  72. package/dist/paths.spec.d.ts +7 -0
  73. package/dist/paths.spec.d.ts.map +1 -0
  74. package/dist/program.d.ts +41 -0
  75. package/dist/program.d.ts.map +1 -0
  76. package/dist/program.spec.d.ts +11 -0
  77. package/dist/program.spec.d.ts.map +1 -0
  78. package/dist/run.d.ts +7 -0
  79. package/dist/run.d.ts.map +1 -0
  80. package/dist/run.spec.d.ts +12 -0
  81. package/dist/run.spec.d.ts.map +1 -0
  82. package/dist/store/commands/add.d.ts +73 -0
  83. package/dist/store/commands/add.d.ts.map +1 -0
  84. package/dist/store/commands/add.spec.d.ts +17 -0
  85. package/dist/store/commands/add.spec.d.ts.map +1 -0
  86. package/dist/store/commands/init.d.ts +75 -0
  87. package/dist/store/commands/init.d.ts.map +1 -0
  88. package/dist/store/commands/init.spec.d.ts +7 -0
  89. package/dist/store/commands/init.spec.d.ts.map +1 -0
  90. package/dist/store/commands/list.d.ts +62 -0
  91. package/dist/store/commands/list.d.ts.map +1 -0
  92. package/dist/store/commands/list.spec.d.ts +7 -0
  93. package/dist/store/commands/list.spec.d.ts.map +1 -0
  94. package/dist/store/commands/prune.d.ts +92 -0
  95. package/dist/store/commands/prune.d.ts.map +1 -0
  96. package/dist/store/commands/prune.spec.d.ts +7 -0
  97. package/dist/store/commands/prune.spec.d.ts.map +1 -0
  98. package/dist/store/commands/reindexs.d.ts +54 -0
  99. package/dist/store/commands/reindexs.d.ts.map +1 -0
  100. package/dist/store/commands/reindexs.spec.d.ts +7 -0
  101. package/dist/store/commands/reindexs.spec.d.ts.map +1 -0
  102. package/dist/store/commands/remove.d.ts +63 -0
  103. package/dist/store/commands/remove.d.ts.map +1 -0
  104. package/dist/store/commands/remove.spec.d.ts +17 -0
  105. package/dist/store/commands/remove.spec.d.ts.map +1 -0
  106. package/dist/store/index.d.ts +32 -0
  107. package/dist/store/index.d.ts.map +1 -0
  108. package/dist/store/index.spec.d.ts +9 -0
  109. package/dist/store/index.spec.d.ts.map +1 -0
  110. package/dist/store/utils/resolve-store-name.d.ts +30 -0
  111. package/dist/store/utils/resolve-store-name.d.ts.map +1 -0
  112. package/dist/store/utils/resolve-store-name.spec.d.ts +2 -0
  113. package/dist/store/utils/resolve-store-name.spec.d.ts.map +1 -0
  114. package/dist/test-helpers.spec.d.ts +224 -0
  115. package/dist/test-helpers.spec.d.ts.map +1 -0
  116. package/dist/tests/cli.integration.spec.d.ts +11 -0
  117. package/dist/tests/cli.integration.spec.d.ts.map +1 -0
  118. package/dist/toon.d.ts +197 -0
  119. package/dist/toon.d.ts.map +1 -0
  120. package/dist/toon.spec.d.ts +9 -0
  121. package/dist/toon.spec.d.ts.map +1 -0
  122. package/dist/utils/git.d.ts +20 -0
  123. package/dist/utils/git.d.ts.map +1 -0
  124. package/dist/utils/git.spec.d.ts +7 -0
  125. package/dist/utils/git.spec.d.ts.map +1 -0
  126. package/package.json +45 -0
  127. package/src/category/commands/create.spec.ts +139 -0
  128. package/src/category/commands/create.ts +115 -0
  129. package/src/category/index.ts +24 -0
  130. package/src/commands/init.spec.ts +203 -0
  131. package/src/commands/init.ts +301 -0
  132. package/src/context.spec.ts +60 -0
  133. package/src/context.ts +175 -0
  134. package/src/errors.spec.ts +264 -0
  135. package/src/errors.ts +105 -0
  136. package/src/memory/commands/add.spec.ts +169 -0
  137. package/src/memory/commands/add.ts +157 -0
  138. package/src/memory/commands/definitions.spec.ts +80 -0
  139. package/src/memory/commands/list.spec.ts +123 -0
  140. package/src/memory/commands/list.ts +268 -0
  141. package/src/memory/commands/move.spec.ts +85 -0
  142. package/src/memory/commands/move.ts +115 -0
  143. package/src/memory/commands/remove.spec.ts +79 -0
  144. package/src/memory/commands/remove.ts +104 -0
  145. package/src/memory/commands/show.spec.ts +71 -0
  146. package/src/memory/commands/show.ts +164 -0
  147. package/src/memory/commands/test-helpers.spec.ts +127 -0
  148. package/src/memory/commands/update.spec.ts +86 -0
  149. package/src/memory/commands/update.ts +229 -0
  150. package/src/memory/index.spec.ts +59 -0
  151. package/src/memory/index.ts +44 -0
  152. package/src/memory/parsing.spec.ts +105 -0
  153. package/src/memory/parsing.ts +22 -0
  154. package/src/observability.spec.ts +139 -0
  155. package/src/observability.ts +63 -0
  156. package/src/output.spec.ts +835 -0
  157. package/src/output.ts +119 -0
  158. package/src/program.spec.ts +46 -0
  159. package/src/program.ts +75 -0
  160. package/src/run.spec.ts +31 -0
  161. package/src/run.ts +9 -0
  162. package/src/store/commands/add.spec.ts +131 -0
  163. package/src/store/commands/add.ts +231 -0
  164. package/src/store/commands/init.spec.ts +236 -0
  165. package/src/store/commands/init.ts +256 -0
  166. package/src/store/commands/list.spec.ts +175 -0
  167. package/src/store/commands/list.ts +102 -0
  168. package/src/store/commands/prune.spec.ts +120 -0
  169. package/src/store/commands/prune.ts +152 -0
  170. package/src/store/commands/reindexs.spec.ts +94 -0
  171. package/src/store/commands/reindexs.ts +96 -0
  172. package/src/store/commands/remove.spec.ts +97 -0
  173. package/src/store/commands/remove.ts +189 -0
  174. package/src/store/index.spec.ts +60 -0
  175. package/src/store/index.ts +49 -0
  176. package/src/store/utils/resolve-store-name.spec.ts +62 -0
  177. package/src/store/utils/resolve-store-name.ts +79 -0
  178. package/src/test-helpers.spec.ts +430 -0
  179. package/src/tests/cli.integration.spec.ts +1170 -0
  180. package/src/toon.spec.ts +183 -0
  181. package/src/toon.ts +462 -0
  182. package/src/utils/git.spec.ts +95 -0
  183. package/src/utils/git.ts +51 -0
  184. package/src/utils/input.spec.ts +326 -0
  185. package/src/utils/input.ts +145 -0
  186. package/src/utils/paths.spec.ts +235 -0
  187. package/src/utils/paths.ts +75 -0
  188. package/src/utils/prompts.spec.ts +23 -0
  189. package/src/utils/prompts.ts +88 -0
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # @yeseh/cortex-cli
2
+
3
+ Command-line interface for the Cortex memory system. Manage memories, categories, and stores from your terminal.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add -g @yeseh/cortex-cli
9
+ ```
10
+
11
+ Or run directly with bun:
12
+
13
+ ```bash
14
+ bunx @yeseh/cortex-cli memory list
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```bash
20
+ # Initialize global configuration
21
+ cortex init
22
+
23
+ # Add a memory
24
+ cortex memory add project/notes/architecture -c "Use event sourcing for state management"
25
+
26
+ # List memories in a category
27
+ cortex memory list project/notes
28
+
29
+ # Show a specific memory
30
+ cortex memory show project/notes/architecture
31
+
32
+ # Update a memory
33
+ cortex memory update project/notes/architecture -c "Updated content here"
34
+
35
+ # Remove a memory
36
+ cortex memory remove project/notes/architecture
37
+ ```
38
+
39
+ ## Commands
40
+
41
+ ### Global
42
+
43
+ | Command | Description |
44
+ |---------|-------------|
45
+ | `cortex init` | Initialize global Cortex configuration |
46
+
47
+ ### Memory Commands
48
+
49
+ | Command | Description |
50
+ |---------|-------------|
51
+ | `cortex memory add <path>` | Create a new memory |
52
+ | `cortex memory show <path>` | Display a memory |
53
+ | `cortex memory update <path>` | Update an existing memory |
54
+ | `cortex memory remove <path>` | Delete a memory |
55
+ | `cortex memory move <from> <to>` | Move or rename a memory |
56
+ | `cortex memory list [category]` | List memories in a category |
57
+
58
+ ### Store Commands
59
+
60
+ | Command | Description |
61
+ |---------|-------------|
62
+ | `cortex store list` | List all registered stores |
63
+ | `cortex store add <name> <path>` | Register an existing store |
64
+ | `cortex store remove <name>` | Unregister a store |
65
+ | `cortex store init [path]` | Initialize a new store |
66
+ | `cortex store prune` | Remove expired memories |
67
+ | `cortex store reindex` | Rebuild the store index |
68
+
69
+ ## Common Options
70
+
71
+ Most commands support these flags:
72
+
73
+ | Flag | Short | Description |
74
+ |------|-------|-------------|
75
+ | `--store` | `-s` | Use a specific named store |
76
+ | `--format` | `-o` | Output format (yaml, json, toon) |
77
+ | `--include-expired` | `-x` | Include expired memories |
78
+
79
+ ## Store Resolution
80
+
81
+ When you run a command, Cortex resolves which store to use:
82
+
83
+ 1. **Explicit**: `--store <name>` flag specifies a registered store
84
+ 2. **Local**: `.cortex/memory` directory in current working directory
85
+ 3. **Global**: `~/.config/cortex/memory` (the default store)
86
+
87
+ This allows project-specific memories when working in a directory with a local `.cortex` folder.
88
+
89
+ ## Examples
90
+
91
+ ### Project-Specific Memory
92
+
93
+ ```bash
94
+ # Initialize a store in your project
95
+ cd my-project
96
+ cortex store init .cortex -n my-project
97
+
98
+ # Add project memories (uses local store automatically)
99
+ cortex memory add decisions/database -c "PostgreSQL for ACID compliance"
100
+ ```
101
+
102
+ ### Organizing with Categories
103
+
104
+ ```bash
105
+ # Create a hierarchy
106
+ cortex memory add project/backend/api/auth -c "JWT with refresh tokens"
107
+ cortex memory add project/backend/api/rate-limiting -c "100 req/min per user"
108
+
109
+ # List by category
110
+ cortex memory list project/backend/api
111
+ ```
112
+
113
+ ### Temporary Memories with Expiration
114
+
115
+ ```bash
116
+ # Create a memory that expires
117
+ cortex memory add temp/meeting-notes -c "Discuss API changes" -e "2024-12-15"
118
+
119
+ # Clean up expired memories
120
+ cortex store prune
121
+ ```
122
+
123
+ ### Output Formats
124
+
125
+ ```bash
126
+ # YAML output (default)
127
+ cortex memory list project
128
+
129
+ # JSON output
130
+ cortex memory list project -o json
131
+
132
+ # TOON output (compact)
133
+ cortex memory list project -o toon
134
+ ```
135
+
136
+ ## Related Packages
137
+
138
+ - `@yeseh/cortex-core` - Core types and domain logic
139
+ - `@yeseh/cortex-storage-fs` - Filesystem storage adapter
140
+ - `@yeseh/cortex-server` - MCP server for AI agent integration
141
+
142
+ ## License
143
+
144
+ MIT
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Category create command.
3
+ *
4
+ * Creates a category at the specified path, including any missing ancestors.
5
+ *
6
+ * @example
7
+ * ```bash
8
+ * # Create a category in default store
9
+ * cortex category create standards/typescript
10
+ *
11
+ * # Create a category in a specific store
12
+ * cortex category --store my-store create standards/typescript
13
+ *
14
+ * # Serialize output as JSON
15
+ * cortex category create standards --format json
16
+ * ```
17
+ */
18
+ import { Command } from '@commander-js/extra-typings';
19
+ import { type CortexContext } from '@yeseh/cortex-core';
20
+ /** Options parsed by Commander for the create command */
21
+ export interface CreateCommandOptions {
22
+ description?: string;
23
+ format?: string;
24
+ }
25
+ /**
26
+ * Handler for the category create command.
27
+ * Exported for direct testing without Commander parsing.
28
+ *
29
+ * @param ctx - CLI execution context
30
+ * @param storeName - Optional store name from parent command
31
+ * @param path - Category path (e.g., "standards/typescript")
32
+ * @param options - Command options from Commander
33
+ */
34
+ export declare function handleCreate(ctx: CortexContext, storeName: string | undefined, path: string, options?: CreateCommandOptions): Promise<void>;
35
+ /**
36
+ * The `category create` subcommand.
37
+ *
38
+ * Creates a category and any missing ancestors.
39
+ */
40
+ export declare const createCommand: Command<[string], {
41
+ description?: string | undefined;
42
+ format?: string | undefined;
43
+ }, {}>;
44
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/category/commands/create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMxD,yDAAyD;AACzD,MAAM,WAAW,oBAAoB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAC9B,GAAG,EAAE,aAAa,EAClB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GACnC,OAAO,CAAC,IAAI,CAAC,CAuCf;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;MAapB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Unit tests for the handleCreate command handler.
3
+ *
4
+ * @module cli/category/commands/create.spec
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=create.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.spec.d.ts","sourceRoot":"","sources":["../../../src/category/commands/create.spec.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Category command group for the CLI.
3
+ *
4
+ * This module defines the `category` command group, which provides operations
5
+ * for managing categories in the Cortex memory system. The `--store` option
6
+ * is defined at the group level and inherited by all subcommands.
7
+ */
8
+ import { Command } from '@commander-js/extra-typings';
9
+ /**
10
+ * The `category` command group.
11
+ *
12
+ * Provides category management operations. The `--store` option allows
13
+ * targeting a specific named store instead of the default store.
14
+ * This option is inherited by all subcommands.
15
+ */
16
+ export declare const categoryCommand: Command<[], {
17
+ store?: string | undefined;
18
+ }, {}>;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/category/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe;;MAEmC,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Init command for initializing the global cortex configuration store.
3
+ *
4
+ * Creates the global config store at ~/.config/cortex/ with:
5
+ * - config.yaml: Global configuration with default settings
6
+ * - stores.yaml: Store registry with a 'default' store pointing to the memory directory
7
+ * - memory/: Default store with 'global' and 'projects' categories
8
+ *
9
+ * @example
10
+ * ```bash
11
+ * # Initialize global cortex configuration
12
+ * cortex init
13
+ *
14
+ * # Reinitialize even if already initialized
15
+ * cortex init --force
16
+ * ```
17
+ */
18
+ import { Command } from '@commander-js/extra-typings';
19
+ import { type CortexContext } from '@yeseh/cortex-core';
20
+ /**
21
+ * Options for the init command.
22
+ */
23
+ export interface InitCommandOptions {
24
+ /** Reinitialize even if already initialized */
25
+ force?: boolean;
26
+ /** Output format (yaml, json, toon) */
27
+ format?: string;
28
+ }
29
+ /**
30
+ * The `init` command for initializing the global cortex configuration.
31
+ *
32
+ * Creates the global config store at ~/.config/cortex/ with default settings
33
+ * and store registry.
34
+ *
35
+ * @example
36
+ * ```bash
37
+ * cortex init # Initialize global config
38
+ * cortex init --force # Reinitialize even if exists
39
+ * ```
40
+ */
41
+ export declare const initCommand: Command<[], {
42
+ force?: true | undefined;
43
+ format: string;
44
+ }, {}>;
45
+ /**
46
+ * Handles the init command execution.
47
+ *
48
+ * This function:
49
+ * 1. Initializes the global cortex config store
50
+ * 2. Creates default categories
51
+ * 3. Outputs the result
52
+ *
53
+ * @param options - Command options (force, format)
54
+ * @throws {InvalidArgumentError} When arguments are invalid
55
+ * @throws {CommanderError} When initialization fails
56
+ */
57
+ export declare function handleInit(ctx: CortexContext, options?: InitCommandOptions): Promise<void>;
58
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAStD,OAAO,EAIH,KAAK,aAAa,EAErB,MAAM,oBAAoB,CAAC;AAG5B;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,+CAA+C;IAC/C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW;;;MAalB,CAAC;AAEP;;;;;;;;;;;GAWG;AAIH,wBAAsB,UAAU,CAC5B,GAAG,EAAE,aAAa,EAClB,OAAO,GAAE,kBAAuB,GACjC,OAAO,CAAC,IAAI,CAAC,CAoBf"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=init.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.spec.d.ts","sourceRoot":"","sources":["../../src/commands/init.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Store resolution utilities for CLI commands.
3
+ *
4
+ * This module provides functions to resolve the store context (root directory)
5
+ * based on command-line options, current working directory, and the global
6
+ * store configuration.
7
+ */
8
+ /**
9
+ * Default path to the global store.
10
+ */
11
+ export declare const getDefaultGlobalStorePath: () => string;
12
+ /**
13
+ * Default path to the store configuration file.
14
+ * Respects CORTEX_CONFIG (config file path) and CORTEX_CONFIG_DIR (config directory)
15
+ * environment variables when set.
16
+ */
17
+ export declare const getDefaultConfigPath: () => string;
18
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;GAEG;AACH,eAAO,MAAM,yBAAyB,QAAO,MACQ,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,QAAO,MAWvC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=context.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.spec.d.ts","sourceRoot":"","sources":["../src/context.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import { getDefaultSettings, type ConfigValidationError, type CortexContext, type Result } from '@yeseh/cortex-core';
2
+ import { FilesystemStorageAdapter, FilesystemConfigAdapter } from '@yeseh/cortex-storage-fs';
3
+ export declare const validateStorePath: (storePath: string, storeName: string) => Result<void, ConfigValidationError>;
4
+ export interface ConfigLoadOptions {
5
+ cwd?: string;
6
+ globalConfigPath?: string;
7
+ localConfigPath?: string;
8
+ }
9
+ export interface CliContextOptions {
10
+ configDir?: string;
11
+ configCwd?: string;
12
+ }
13
+ export interface CliConfigContext {
14
+ configAdapter: FilesystemConfigAdapter;
15
+ stores: Record<string, any>;
16
+ settings: ReturnType<typeof getDefaultSettings>;
17
+ effectiveCwd: string;
18
+ }
19
+ export declare const createCliConfigAdapter: (configPath: string) => FilesystemConfigAdapter;
20
+ export declare const createCliAdapterFactory: (configAdapter: FilesystemConfigAdapter) => (storeName: string) => FilesystemStorageAdapter;
21
+ export declare const createCliConfigContext: (options?: CliContextOptions) => Promise<Result<CliConfigContext, any>>;
22
+ export declare const createCliCommandContext: (configDir?: string) => Promise<Result<CortexContext, any>>;
23
+ //# sourceMappingURL=create-cli-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-cli-command.d.ts","sourceRoot":"","sources":["../src/create-cli-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,kBAAkB,EAElB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,MAAM,EACd,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAY7F,eAAO,MAAM,iBAAiB,GAC1B,WAAW,MAAM,EACjB,WAAW,MAAM,KAClB,MAAM,CAAC,IAAI,EAAE,qBAAqB,CAWpC,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC7B,aAAa,EAAE,uBAAuB,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,QAAQ,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;IAChD,YAAY,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,sBAAsB,GAAI,YAAY,MAAM,KAAG,uBAE3D,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,eAAe,uBAAuB,MAClE,WAAW,MAAM,6BAkB5B,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAC/B,UAAS,iBAAsB,KAChC,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,GAAG,CAAC,CA0CvC,CAAC;AAKF,eAAO,MAAM,uBAAuB,GAChC,YAAY,MAAM,KACnB,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,CAoCpC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Unit tests for create-cli-command.ts — validateStorePath.
3
+ *
4
+ * Verifies that absolute paths pass validation and relative paths
5
+ * produce a typed INVALID_STORE_PATH error result.
6
+ *
7
+ * @module cli/create-cli-command.spec
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=create-cli-command.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-cli-command.spec.d.ts","sourceRoot":"","sources":["../src/create-cli-command.spec.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Error mapping utilities for CLI commands.
3
+ *
4
+ * This module provides utilities to map core Result errors to Commander.js
5
+ * exceptions. Commander.js uses specific exception types to control error
6
+ * output and exit codes:
7
+ *
8
+ * - `InvalidArgumentError` - For user input validation errors (shows usage help)
9
+ * - `CommanderError` - For other errors (shows error message only)
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const result = await runAddCommand(options);
14
+ * if (!result.ok()) {
15
+ * mapCoreError(result.error);
16
+ * }
17
+ * ```
18
+ */
19
+ /**
20
+ * Represents a core error with a code and message.
21
+ *
22
+ * This interface matches the error shape used throughout the CLI commands,
23
+ * allowing consistent error handling across all command implementations.
24
+ */
25
+ export interface CoreError {
26
+ code: string;
27
+ message: string;
28
+ cause?: unknown;
29
+ }
30
+ /**
31
+ * Maps a core error to a Commander.js exception and throws it.
32
+ *
33
+ * This function examines the error code to determine the appropriate
34
+ * Commander.js exception type:
35
+ *
36
+ * - **Argument errors** (`InvalidArgumentError`): For errors caused by invalid
37
+ * user input. Commander.js displays usage help for these errors.
38
+ *
39
+ * - **Other errors** (`CommanderError`): For system errors, missing resources,
40
+ * or internal failures. Commander.js displays only the error message.
41
+ *
42
+ * @param error - The core error to map
43
+ * @throws {InvalidArgumentError} When the error code indicates invalid input
44
+ * @throws {CommanderError} For all other error codes
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * // In a command action handler
49
+ * const result = await runShowCommand(options);
50
+ * if (!result.ok()) {
51
+ * mapCoreError(result.error);
52
+ * // Never reaches here - mapCoreError always throws
53
+ * }
54
+ * ```
55
+ */
56
+ export declare function throwCliError(error: CoreError): never;
57
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAyCD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,CAMrD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=errors.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.spec.d.ts","sourceRoot":"","sources":["../src/errors.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * CLI helpers for resolving memory content input.
3
+ */
4
+ import { type Result } from '@yeseh/cortex-core';
5
+ export type MemoryContentSource = 'flag' | 'file' | 'stdin' | 'none';
6
+ export type InputSource = {
7
+ content?: string;
8
+ filePath?: string;
9
+ /**
10
+ * stdin stream to read from.
11
+ *
12
+ * NOTE: Passing a stream does not necessarily mean stdin is intended as an input
13
+ * source. Use `stdinRequested: true` when a command semantics include reading from
14
+ * stdin by default (e.g. `memory add`), typically when piping.
15
+ */
16
+ stream?: NodeJS.ReadableStream;
17
+ /**
18
+ * Explicitly indicates stdin should be considered as an input source.
19
+ *
20
+ * This is `false` by default so that inheriting a non-TTY stdin in test harnesses
21
+ * or subprocess environments does not accidentally count as providing `--stdin`.
22
+ */
23
+ stdinRequested?: boolean;
24
+ };
25
+ export interface InputContent {
26
+ content: string | null;
27
+ source: MemoryContentSource;
28
+ }
29
+ export type InputErrorCode = 'MULTIPLE_CONTENT_SOURCES' | 'FILE_READ_FAILED' | 'MISSING_CONTENT' | 'INVALID_FILE_PATH';
30
+ export interface InputError {
31
+ code: InputErrorCode;
32
+ message: string;
33
+ path?: string;
34
+ cause?: unknown;
35
+ }
36
+ type InputResult = Result<InputContent, InputError>;
37
+ type OptionalContentResult = Result<InputContent | null, InputError>;
38
+ export declare const readContentFromFile: (filePath: string | undefined) => Promise<OptionalContentResult>;
39
+ export declare const readContentFromStream: (stream: NodeJS.ReadableStream) => Promise<OptionalContentResult>;
40
+ export declare const resolveInput: (source: InputSource) => Promise<InputResult>;
41
+ export {};
42
+ //# sourceMappingURL=input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE1D,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAErE,MAAM,MAAM,WAAW,GAAG;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC/B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,mBAAmB,CAAC;CAC/B;AAED,MAAM,MAAM,cAAc,GACpB,0BAA0B,GAC1B,kBAAkB,GAClB,iBAAiB,GACjB,mBAAmB,CAAC;AAE1B,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,WAAW,GAAG,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AACpD,KAAK,qBAAqB,GAAG,MAAM,CAAC,YAAY,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC;AAErE,eAAO,MAAM,mBAAmB,GAC5B,UAAU,MAAM,GAAG,SAAS,KAC7B,OAAO,CAAC,qBAAqB,CAsB/B,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAC9B,QAAQ,MAAM,CAAC,cAAc,KAC9B,OAAO,CAAC,qBAAqB,CAgB/B,CAAC;AAKF,eAAO,MAAM,YAAY,GAAU,QAAQ,WAAW,KAAG,OAAO,CAAC,WAAW,CA6C3E,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=input.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.spec.d.ts","sourceRoot":"","sources":["../src/input.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Memory add command implementation using Commander.js.
3
+ *
4
+ * Creates a new memory at the specified path with content from inline text,
5
+ * a file, or stdin.
6
+ *
7
+ * @example
8
+ * ```bash
9
+ * # Add memory with inline content
10
+ * cortex memory add project/tech-stack --content "Using TypeScript and Node.js"
11
+ *
12
+ * # Add memory from a file
13
+ * cortex memory add project/notes --file ./notes.md
14
+ *
15
+ * # Add memory from stdin
16
+ * echo "My notes" | cortex memory add project/notes
17
+ *
18
+ * # Add memory with tags and expiration
19
+ * cortex memory add project/temp --content "Temporary note" \
20
+ * --tags "temp,cleanup" --expires-at "2025-12-31T00:00:00Z"
21
+ * ```
22
+ */
23
+ import { Command } from '@commander-js/extra-typings';
24
+ import { type CortexContext } from '@yeseh/cortex-core';
25
+ /** Options parsed by Commander for the add command */
26
+ export interface AddCommandOptions {
27
+ content?: string;
28
+ file?: string;
29
+ tags?: string[];
30
+ expiresAt?: string;
31
+ citations?: string[];
32
+ format?: string;
33
+ }
34
+ /**
35
+ * Handler for the memory add command.
36
+ * Exported for direct testing without Commander parsing.
37
+ *
38
+ * @param path - Memory path (e.g., "project/tech-stack")
39
+ * @param options - Command options from Commander
40
+ * @param storeName - Optional store name from parent command
41
+ * @param deps - Injectable dependencies for testing
42
+ */
43
+ export declare function handleAdd(ctx: CortexContext, storeName: string | undefined, path: string, options: AddCommandOptions): Promise<void>;
44
+ /**
45
+ * The `memory add` subcommand.
46
+ *
47
+ * Creates a new memory at the specified path. Content can be provided via:
48
+ * - `--content` flag for inline text
49
+ * - `--file` flag to read from a file
50
+ * - stdin when piped
51
+ *
52
+ * The `--store` option is inherited from the parent `memory` command.
53
+ */
54
+ export declare const addCommand: Command<[string], {
55
+ content?: string | undefined;
56
+ file?: string | undefined;
57
+ tags?: string[] | undefined;
58
+ expiresAt?: string | undefined;
59
+ citation?: string[] | undefined;
60
+ format?: string | undefined;
61
+ }, {}>;
62
+ //# sourceMappingURL=add.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../../src/memory/commands/add.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAEtD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMxD,sDAAsD;AACtD,MAAM,WAAW,iBAAiB;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AACD;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC3B,GAAG,EAAE,aAAa,EAClB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAyEf;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU;;;;;;;MAiBjB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Unit tests for the handleAdd command handler.
3
+ *
4
+ * @module cli/memory/commands/add.spec
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=add.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add.spec.d.ts","sourceRoot":"","sources":["../../../src/memory/commands/add.spec.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Unit tests for memory command definitions.
3
+ *
4
+ * Verifies that memory subcommands expose the expected names,
5
+ * arguments, and options.
6
+ *
7
+ * @module cli/memory/commands/definitions.spec
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=definitions.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.spec.d.ts","sourceRoot":"","sources":["../../../src/memory/commands/definitions.spec.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=handlers.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.spec.d.ts","sourceRoot":"","sources":["../../../src/memory/commands/handlers.spec.ts"],"names":[],"mappings":""}