claude-cognitive 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 (196) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +256 -0
  3. package/bin/claude-cognitive.js +9 -0
  4. package/dist/agents/context.d.ts +40 -0
  5. package/dist/agents/context.d.ts.map +1 -0
  6. package/dist/agents/context.js +144 -0
  7. package/dist/agents/context.js.map +1 -0
  8. package/dist/agents/index.d.ts +9 -0
  9. package/dist/agents/index.d.ts.map +1 -0
  10. package/dist/agents/index.js +11 -0
  11. package/dist/agents/index.js.map +1 -0
  12. package/dist/agents/loader.d.ts +48 -0
  13. package/dist/agents/loader.d.ts.map +1 -0
  14. package/dist/agents/loader.js +157 -0
  15. package/dist/agents/loader.js.map +1 -0
  16. package/dist/agents/templates.d.ts +51 -0
  17. package/dist/agents/templates.d.ts.map +1 -0
  18. package/dist/agents/templates.js +186 -0
  19. package/dist/agents/templates.js.map +1 -0
  20. package/dist/agents/types.d.ts +52 -0
  21. package/dist/agents/types.d.ts.map +1 -0
  22. package/dist/agents/types.js +6 -0
  23. package/dist/agents/types.js.map +1 -0
  24. package/dist/cli/commands/config.d.ts +10 -0
  25. package/dist/cli/commands/config.d.ts.map +1 -0
  26. package/dist/cli/commands/config.js +22 -0
  27. package/dist/cli/commands/config.js.map +1 -0
  28. package/dist/cli/commands/index.d.ts +17 -0
  29. package/dist/cli/commands/index.d.ts.map +1 -0
  30. package/dist/cli/commands/index.js +17 -0
  31. package/dist/cli/commands/index.js.map +1 -0
  32. package/dist/cli/commands/init.d.ts +10 -0
  33. package/dist/cli/commands/init.d.ts.map +1 -0
  34. package/dist/cli/commands/init.js +109 -0
  35. package/dist/cli/commands/init.js.map +1 -0
  36. package/dist/cli/commands/install.d.ts +10 -0
  37. package/dist/cli/commands/install.d.ts.map +1 -0
  38. package/dist/cli/commands/install.js +440 -0
  39. package/dist/cli/commands/install.js.map +1 -0
  40. package/dist/cli/commands/learn.d.ts +10 -0
  41. package/dist/cli/commands/learn.d.ts.map +1 -0
  42. package/dist/cli/commands/learn.js +33 -0
  43. package/dist/cli/commands/learn.js.map +1 -0
  44. package/dist/cli/commands/recall.d.ts +10 -0
  45. package/dist/cli/commands/recall.d.ts.map +1 -0
  46. package/dist/cli/commands/recall.js +52 -0
  47. package/dist/cli/commands/recall.js.map +1 -0
  48. package/dist/cli/commands/reflect.d.ts +10 -0
  49. package/dist/cli/commands/reflect.d.ts.map +1 -0
  50. package/dist/cli/commands/reflect.js +48 -0
  51. package/dist/cli/commands/reflect.js.map +1 -0
  52. package/dist/cli/commands/semantic.d.ts +10 -0
  53. package/dist/cli/commands/semantic.d.ts.map +1 -0
  54. package/dist/cli/commands/semantic.js +67 -0
  55. package/dist/cli/commands/semantic.js.map +1 -0
  56. package/dist/cli/commands/serve.d.ts +10 -0
  57. package/dist/cli/commands/serve.d.ts.map +1 -0
  58. package/dist/cli/commands/serve.js +61 -0
  59. package/dist/cli/commands/serve.js.map +1 -0
  60. package/dist/cli/commands/status.d.ts +10 -0
  61. package/dist/cli/commands/status.d.ts.map +1 -0
  62. package/dist/cli/commands/status.js +44 -0
  63. package/dist/cli/commands/status.js.map +1 -0
  64. package/dist/cli/commands/sync.d.ts +10 -0
  65. package/dist/cli/commands/sync.d.ts.map +1 -0
  66. package/dist/cli/commands/sync.js +260 -0
  67. package/dist/cli/commands/sync.js.map +1 -0
  68. package/dist/cli/commands/uninstall.d.ts +10 -0
  69. package/dist/cli/commands/uninstall.d.ts.map +1 -0
  70. package/dist/cli/commands/uninstall.js +205 -0
  71. package/dist/cli/commands/uninstall.js.map +1 -0
  72. package/dist/cli/commands/update-bank.d.ts +10 -0
  73. package/dist/cli/commands/update-bank.d.ts.map +1 -0
  74. package/dist/cli/commands/update-bank.js +129 -0
  75. package/dist/cli/commands/update-bank.js.map +1 -0
  76. package/dist/cli/index.d.ts +6 -0
  77. package/dist/cli/index.d.ts.map +1 -0
  78. package/dist/cli/index.js +56 -0
  79. package/dist/cli/index.js.map +1 -0
  80. package/dist/cli/utils/errors.d.ts +42 -0
  81. package/dist/cli/utils/errors.d.ts.map +1 -0
  82. package/dist/cli/utils/errors.js +78 -0
  83. package/dist/cli/utils/errors.js.map +1 -0
  84. package/dist/cli/utils/index.d.ts +9 -0
  85. package/dist/cli/utils/index.d.ts.map +1 -0
  86. package/dist/cli/utils/index.js +7 -0
  87. package/dist/cli/utils/index.js.map +1 -0
  88. package/dist/cli/utils/output.d.ts +90 -0
  89. package/dist/cli/utils/output.d.ts.map +1 -0
  90. package/dist/cli/utils/output.js +164 -0
  91. package/dist/cli/utils/output.js.map +1 -0
  92. package/dist/client.d.ts +200 -0
  93. package/dist/client.d.ts.map +1 -0
  94. package/dist/client.js +447 -0
  95. package/dist/client.js.map +1 -0
  96. package/dist/config.d.ts +44 -0
  97. package/dist/config.d.ts.map +1 -0
  98. package/dist/config.js +264 -0
  99. package/dist/config.js.map +1 -0
  100. package/dist/errors.d.ts +72 -0
  101. package/dist/errors.d.ts.map +1 -0
  102. package/dist/errors.js +188 -0
  103. package/dist/errors.js.map +1 -0
  104. package/dist/events.d.ts +148 -0
  105. package/dist/events.d.ts.map +1 -0
  106. package/dist/events.js +115 -0
  107. package/dist/events.js.map +1 -0
  108. package/dist/hooks/index.d.ts +7 -0
  109. package/dist/hooks/index.d.ts.map +1 -0
  110. package/dist/hooks/index.js +7 -0
  111. package/dist/hooks/index.js.map +1 -0
  112. package/dist/hooks/inject-context.d.ts +18 -0
  113. package/dist/hooks/inject-context.d.ts.map +1 -0
  114. package/dist/hooks/inject-context.js +57 -0
  115. package/dist/hooks/inject-context.js.map +1 -0
  116. package/dist/hooks/process-session.d.ts +18 -0
  117. package/dist/hooks/process-session.d.ts.map +1 -0
  118. package/dist/hooks/process-session.js +119 -0
  119. package/dist/hooks/process-session.js.map +1 -0
  120. package/dist/index.d.ts +63 -0
  121. package/dist/index.d.ts.map +1 -0
  122. package/dist/index.js +59 -0
  123. package/dist/index.js.map +1 -0
  124. package/dist/learn/analyzers/git.d.ts +62 -0
  125. package/dist/learn/analyzers/git.d.ts.map +1 -0
  126. package/dist/learn/analyzers/git.js +183 -0
  127. package/dist/learn/analyzers/git.js.map +1 -0
  128. package/dist/learn/analyzers/index.d.ts +15 -0
  129. package/dist/learn/analyzers/index.d.ts.map +1 -0
  130. package/dist/learn/analyzers/index.js +10 -0
  131. package/dist/learn/analyzers/index.js.map +1 -0
  132. package/dist/learn/analyzers/package.d.ts +57 -0
  133. package/dist/learn/analyzers/package.d.ts.map +1 -0
  134. package/dist/learn/analyzers/package.js +245 -0
  135. package/dist/learn/analyzers/package.js.map +1 -0
  136. package/dist/learn/analyzers/readme.d.ts +27 -0
  137. package/dist/learn/analyzers/readme.d.ts.map +1 -0
  138. package/dist/learn/analyzers/readme.js +163 -0
  139. package/dist/learn/analyzers/readme.js.map +1 -0
  140. package/dist/learn/analyzers/source.d.ts +70 -0
  141. package/dist/learn/analyzers/source.d.ts.map +1 -0
  142. package/dist/learn/analyzers/source.js +231 -0
  143. package/dist/learn/analyzers/source.js.map +1 -0
  144. package/dist/learn/analyzers/structure.d.ts +39 -0
  145. package/dist/learn/analyzers/structure.d.ts.map +1 -0
  146. package/dist/learn/analyzers/structure.js +172 -0
  147. package/dist/learn/analyzers/structure.js.map +1 -0
  148. package/dist/learn/extractor.d.ts +76 -0
  149. package/dist/learn/extractor.d.ts.map +1 -0
  150. package/dist/learn/extractor.js +302 -0
  151. package/dist/learn/extractor.js.map +1 -0
  152. package/dist/learn/index.d.ts +31 -0
  153. package/dist/learn/index.d.ts.map +1 -0
  154. package/dist/learn/index.js +165 -0
  155. package/dist/learn/index.js.map +1 -0
  156. package/dist/mcp/handlers.d.ts +23 -0
  157. package/dist/mcp/handlers.d.ts.map +1 -0
  158. package/dist/mcp/handlers.js +124 -0
  159. package/dist/mcp/handlers.js.map +1 -0
  160. package/dist/mcp/index.d.ts +32 -0
  161. package/dist/mcp/index.d.ts.map +1 -0
  162. package/dist/mcp/index.js +40 -0
  163. package/dist/mcp/index.js.map +1 -0
  164. package/dist/mcp/server.d.ts +79 -0
  165. package/dist/mcp/server.d.ts.map +1 -0
  166. package/dist/mcp/server.js +277 -0
  167. package/dist/mcp/server.js.map +1 -0
  168. package/dist/mcp/tools.d.ts +59 -0
  169. package/dist/mcp/tools.d.ts.map +1 -0
  170. package/dist/mcp/tools.js +43 -0
  171. package/dist/mcp/tools.js.map +1 -0
  172. package/dist/mcp/types.d.ts +65 -0
  173. package/dist/mcp/types.d.ts.map +1 -0
  174. package/dist/mcp/types.js +6 -0
  175. package/dist/mcp/types.js.map +1 -0
  176. package/dist/mind.d.ts +250 -0
  177. package/dist/mind.d.ts.map +1 -0
  178. package/dist/mind.js +637 -0
  179. package/dist/mind.js.map +1 -0
  180. package/dist/promotion.d.ts +112 -0
  181. package/dist/promotion.d.ts.map +1 -0
  182. package/dist/promotion.js +196 -0
  183. package/dist/promotion.js.map +1 -0
  184. package/dist/retry.d.ts +70 -0
  185. package/dist/retry.d.ts.map +1 -0
  186. package/dist/retry.js +122 -0
  187. package/dist/retry.js.map +1 -0
  188. package/dist/semantic.d.ts +202 -0
  189. package/dist/semantic.d.ts.map +1 -0
  190. package/dist/semantic.js +424 -0
  191. package/dist/semantic.js.map +1 -0
  192. package/dist/types.d.ts +363 -0
  193. package/dist/types.d.ts.map +1 -0
  194. package/dist/types.js +30 -0
  195. package/dist/types.js.map +1 -0
  196. package/package.json +70 -0
@@ -0,0 +1,52 @@
1
+ /**
2
+ * CLI recall command - search memories.
3
+ * @module cli/commands/recall
4
+ */
5
+ import { Mind } from "../../mind.js";
6
+ import { CLIError, ExitCode, output, formatMemories } from "../utils/index.js";
7
+ /**
8
+ * Register the recall command.
9
+ */
10
+ export function registerRecallCommand(cli) {
11
+ cli
12
+ .command("recall <query>", "Search memories for relevant context")
13
+ .option("--project <path>", "Project directory (default: current directory)")
14
+ .option("--type <type>", "Memory type: world, experience, opinion, or all (default: all)")
15
+ .option("--budget <level>", "Search thoroughness: low, mid, or high (default: mid)")
16
+ .option("--limit <n>", "Maximum number of results")
17
+ .option("--json", "Output as JSON")
18
+ .option("--quiet", "Suppress output")
19
+ .action(async (query, options) => {
20
+ const projectPath = options.project ?? process.cwd();
21
+ // Validate options
22
+ const validTypes = ["world", "experience", "opinion", "all"];
23
+ if (options.type && !validTypes.includes(options.type)) {
24
+ throw new CLIError(`Invalid type: ${options.type}. Use one of: ${validTypes.join(", ")}`, ExitCode.CONFIG_ERROR);
25
+ }
26
+ const validBudgets = ["low", "mid", "high"];
27
+ if (options.budget && !validBudgets.includes(options.budget)) {
28
+ throw new CLIError(`Invalid budget: ${options.budget}. Use one of: ${validBudgets.join(", ")}`, ExitCode.CONFIG_ERROR);
29
+ }
30
+ const mind = new Mind({ projectPath });
31
+ await mind.init();
32
+ if (mind.isDegraded) {
33
+ // Return empty results in degraded mode
34
+ output([], formatMemories, options);
35
+ return;
36
+ }
37
+ const recallOptions = {};
38
+ if (options.type) {
39
+ recallOptions.factType = options.type;
40
+ }
41
+ if (options.budget) {
42
+ recallOptions.budget = options.budget;
43
+ }
44
+ const memories = await mind.recall(query, recallOptions);
45
+ // Apply limit if specified
46
+ const limited = options.limit
47
+ ? memories.slice(0, options.limit)
48
+ : memories;
49
+ output(limited, formatMemories, options);
50
+ });
51
+ }
52
+ //# sourceMappingURL=recall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recall.js","sourceRoot":"","sources":["../../../src/cli/commands/recall.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAW/E;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAQ;IAC5C,GAAG;SACA,OAAO,CAAC,gBAAgB,EAAE,sCAAsC,CAAC;SACjE,MAAM,CAAC,kBAAkB,EAAE,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,wCAAwC;YACxC,MAAM,CAAC,EAAE,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;YACpC,OAAO;QACT,CAAC;QAED,MAAM,aAAa,GAAsB,EAAE,CAAC;QAC5C,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,aAAa,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAwB,CAAC;QAC5D,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,aAAa,CAAC,MAAM,GAAG,OAAO,CAAC,MAAsB,CAAC;QACxD,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QAEzD,2BAA2B;QAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK;YAC3B,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC;YAClC,CAAC,CAAC,QAAQ,CAAC;QAEb,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CLI reflect command - reason about accumulated knowledge.
3
+ * @module cli/commands/reflect
4
+ */
5
+ import type { CAC } from "cac";
6
+ /**
7
+ * Register the reflect command.
8
+ */
9
+ export declare function registerReflectCommand(cli: CAC): void;
10
+ //# sourceMappingURL=reflect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflect.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/reflect.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAwC/B;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAwBrD"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * CLI reflect command - reason about accumulated knowledge.
3
+ * @module cli/commands/reflect
4
+ */
5
+ import { Mind } from "../../mind.js";
6
+ import { CLIError, ExitCode, output, formatOpinions } from "../utils/index.js";
7
+ /**
8
+ * Format reflection result for human-readable output.
9
+ */
10
+ function formatReflection(result) {
11
+ const lines = [];
12
+ lines.push(result.text);
13
+ lines.push("");
14
+ if (result.opinions.length > 0) {
15
+ lines.push("Opinions formed:");
16
+ lines.push(formatOpinions(result.opinions));
17
+ lines.push("");
18
+ }
19
+ const worldCount = result.basedOn.world.length;
20
+ const expCount = result.basedOn.experience.length;
21
+ const opinionCount = result.basedOn.opinion.length;
22
+ const total = worldCount + expCount + opinionCount;
23
+ if (total > 0) {
24
+ lines.push(`Based on ${total} memories: ${worldCount} world facts, ${expCount} experiences, ${opinionCount} prior opinions.`);
25
+ }
26
+ return lines.join("\n").trim();
27
+ }
28
+ /**
29
+ * Register the reflect command.
30
+ */
31
+ export function registerReflectCommand(cli) {
32
+ cli
33
+ .command("reflect <query>", "Reason about accumulated knowledge")
34
+ .option("--project <path>", "Project directory (default: current directory)")
35
+ .option("--json", "Output as JSON")
36
+ .option("--quiet", "Suppress output")
37
+ .action(async (query, options) => {
38
+ const projectPath = options.project ?? process.cwd();
39
+ const mind = new Mind({ projectPath });
40
+ await mind.init();
41
+ if (mind.isDegraded) {
42
+ throw new CLIError("Cannot reflect: Hindsight is unavailable.", ExitCode.CONNECTION_ERROR, "Make sure Hindsight is running and accessible.");
43
+ }
44
+ const result = await mind.reflect(query);
45
+ output(result, formatReflection, options);
46
+ });
47
+ }
48
+ //# sourceMappingURL=reflect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflect.js","sourceRoot":"","sources":["../../../src/cli/commands/reflect.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAS/E;;GAEG;AACH,SAAS,g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EAAE,OAAuB,EAAE,EAAE;QACvD,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAErD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;QACvC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAElB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,IAAI,QAAQ,CAChB,2CAA2C,EAC3C,QAAQ,CAAC,gBAAgB,EACzB,gDAAgD,CACjD,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAEzC,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CLI semantic command - show/manage semantic memory.
3
+ * @module cli/commands/semantic
4
+ */
5
+ import type { CAC } from "cac";
6
+ /**
7
+ * Register the semantic command.
8
+ */
9
+ export declare function registerSemanticCommand(cli: CAC): void;
10
+ //# sourceMappingURL=semantic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/semantic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAW/B;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAyEtD"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * CLI semantic command - show/manage semantic memory.
3
+ * @module cli/commands/semantic
4
+ */
5
+ import { Mind } from "../../mind.js";
6
+ import { CLIError, ExitCode, output, info } from "../utils/index.js";
7
+ /**
8
+ * Register the semantic command.
9
+ */
10
+ export function registerSemanticCommand(cli) {
11
+ cli
12
+ .command("semantic [section]", "Show or manage semantic memory")
13
+ .option("--project <path>", "Project directory (default: current directory)")
14
+ .option("--set <content>", "Set section content (requires section argument)")
15
+ .option("--json", "Output as JSON")
16
+ .option("--quiet", "Suppress output")
17
+ .action(async (section, options) => {
18
+ const projectPath = options.project ?? process.cwd();
19
+ const mind = new Mind({ projectPath });
20
+ await mind.init();
21
+ const semantic = mind.getSemanticMemory();
22
+ if (!semantic || !semantic.isLoaded()) {
23
+ throw new CLIError("Semantic memory not loaded.", ExitCode.CONFIG_ERROR, `Check that ${mind.getSemanticPath()} exists.`);
24
+ }
25
+ // Set section content if --set is provided
26
+ if (options.set !== undefined) {
27
+ if (!section) {
28
+ throw new CLIError("Section name required when using --set.", ExitCode.CONFIG_ERROR, "Usage: claude-cognitive semantic 'Section Name' --set 'content'");
29
+ }
30
+ semantic.set(section, options.set);
31
+ await semantic.save();
32
+ info(`Updated section: ${section}`, options);
33
+ return;
34
+ }
35
+ // Show specific section or all
36
+ if (section) {
37
+ const content = semantic.get(section);
38
+ if (content === undefined) {
39
+ throw new CLIError(`Section not found: ${section}`, ExitCode.CONFIG_ERROR, `Available sections: ${semantic.getSectionNames().join(", ")}`);
40
+ }
41
+ if (options.json) {
42
+ output({ section, content }, (d) => d.content, options);
43
+ }
44
+ else {
45
+ console.log(`## ${section}\n\n${content}`);
46
+ }
47
+ }
48
+ else {
49
+ // Show all sections
50
+ const sections = semantic.getSectionNames();
51
+ const result = {};
52
+ for (const name of sections) {
53
+ const content = semantic.get(name);
54
+ if (content !== undefined) {
55
+ result[name] = content;
56
+ }
57
+ }
58
+ if (options.json) {
59
+ output(result, () => "", options);
60
+ }
61
+ else {
62
+ console.log(semantic.toContext());
63
+ }
64
+ }
65
+ });
66
+ }
67
+ //# sourceMappingURL=semantic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic.js","sourceRoot":"","sources":["../../../src/cli/commands/semantic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,C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OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;YACpC,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CLI serve command - start the MCP server.
3
+ * @module cli/commands/serve
4
+ */
5
+ import type { CAC } from "cac";
6
+ /**
7
+ * Register the serve command.
8
+ */
9
+ export declare function registerServeCommand(cli: CAC): void;
10
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/serve.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAe/B;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CA+DnD"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * CLI serve command - start the MCP server.
3
+ * @module cli/commands/serve
4
+ */
5
+ import { Mind } from "../../mind.js";
6
+ import { ClaudeMindMcpServer } from "../../mcp/index.js";
7
+ import { CLIError, ExitCode, info } from "../utils/index.js";
8
+ /**
9
+ * Register the serve command.
10
+ */
11
+ export function registerServeCommand(cli) {
12
+ cli
13
+ .command("serve", "Start the MCP server")
14
+ .option("--project <path>", "Project directory (default: current directory)")
15
+ .option("--transport <type>", "Transport type: stdio or http (default: stdio)")
16
+ .option("--port <port>", "HTTP port (default: 3000)", { default: 3000 })
17
+ .option("--host <host>", "HTTP host (default: 127.0.0.1)", {
18
+ default: "127.0.0.1",
19
+ })
20
+ .option("--cors", "Enable CORS for HTTP transport")
21
+ .option("--json", "Output as JSON")
22
+ .option("--quiet", "Suppress output")
23
+ .action(async (options) => {
24
+ const projectPath = options.project ?? process.cwd();
25
+ const transport = (options.transport ?? "stdio");
26
+ if (transport !== "stdio" && transport !== "http") {
27
+ throw new CLIError(`Invalid transport: ${transport}. Use 'stdio' or 'http'.`, ExitCode.CONFIG_ERROR);
28
+ }
29
+ // Initialize Mind
30
+ const mind = new Mind({ projectPath });
31
+ await mind.init();
32
+ if (mind.isDegraded) {
33
+ info("Warning: Running in degraded mode (Hindsight unavailable). Memory tools will return limited results.", options);
34
+ }
35
+ // Create and start server
36
+ const httpConfig = {};
37
+ if (options.port !== undefined)
38
+ httpConfig.port = options.port;
39
+ if (options.host !== undefined)
40
+ httpConfig.host = options.host;
41
+ if (options.cors !== undefined)
42
+ httpConfig.cors = options.cors;
43
+ const server = new ClaudeMindMcpServer({
44
+ mind,
45
+ transport,
46
+ http: httpConfig,
47
+ });
48
+ await server.start();
49
+ // Keep process running
50
+ process.on("SIGINT", async () => {
51
+ info("\nShutting down...", options);
52
+ await server.stop();
53
+ process.exit(0);
54
+ });
55
+ process.on("SIGTERM", async () => {
56
+ await server.stop();
57
+ process.exit(0);
58
+ });
59
+ });
60
+ }
61
+ //# sourceMappingURL=serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../../../src/cli/commands/serve.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAyB,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAY7D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAQ;IAC3C,GAAG;SACA,OAAO,CAAC,OAAO,EAAE,sBAAsB,CAAC;SACxC,MAAM,CAAC,kBAAkB,EAAE,gDAAgD,CAAC;SAC5E,MAAM,CACL,oBAAoB,EACpB,gDAAgD,CACjD;SACA,MAAM,CAAC,eAAe,EAAE,2BAA2B,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;SACvE,MAAM,CAAC,eAAe,EAAE,gCAAgC,EAAE;QACzD,OAAO,EAAE,WAAW;KACrB,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AAC;QAErB,uBAAuB;QACvB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;YAC9B,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;YACpC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;YAC/B,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CLI status command - show connection and project status.
3
+ * @module cli/commands/status
4
+ */
5
+ import type { CAC } from "cac";
6
+ /**
7
+ * Register the status command.
8
+ */
9
+ export declare function registerStatusCommand(cli: CAC): void;
10
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/status.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAuB/B;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAoCpD"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * CLI status command - show connection and project status.
3
+ * @module cli/commands/status
4
+ */
5
+ import { Mind } from "../../mind.js";
6
+ import { output, formatStatus } from "../utils/index.js";
7
+ /**
8
+ * Register the status command.
9
+ */
10
+ export function registerStatusCommand(cli) {
11
+ cli
12
+ .command("status", "Show connection and project status")
13
+ .option("--project <path>", "Project directory (default: current directory)")
14
+ .option("--json", "Output as JSON")
15
+ .option("--quiet", "Suppress output")
16
+ .action(async (options) => {
17
+ const projectPath = options.project ?? process.cwd();
18
+ const mind = new Mind({ projectPath });
19
+ await mind.init();
20
+ const result = {
21
+ hindsight: {
22
+ healthy: !mind.isDegraded,
23
+ },
24
+ bankId: mind.getBankId(),
25
+ semanticPath: mind.getSemanticPath(),
26
+ semanticLoaded: mind.getSemanticMemory()?.isLoaded() ?? false,
27
+ degraded: mind.isDegraded,
28
+ };
29
+ // Get bank info if not degraded
30
+ if (!mind.isDegraded) {
31
+ try {
32
+ const bank = await mind.getBank();
33
+ if (bank) {
34
+ result.memoryCount = bank.memoryCount;
35
+ }
36
+ }
37
+ catch {
38
+ // Ignore errors getting bank info
39
+ }
40
+ }
41
+ output(result, formatStatus, options);
42
+ });
43
+ }
44
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/cli/commands/status.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAqBzD;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAQ;IAC5C,GAAG;SACA,OAAO,CAAC,QAAQ,EAAE,oCAAoC,CAAC;SACvD,MAAM,CAAC,kBAAkB,EAAE,gDAAgD,CAAC;SAC5E,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC;SAClC,MAAM,CAAC,SAAS,EAAE,iBAAiB,CAAC;SACpC,MAAM,CAAC,KAAK,EAAE,OAAsB,EAAE,EAAE;QACvC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAErD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;QACvC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAElB,MAAM,MAAM,GAAiB;YAC3B,SAAS,EAAE;gBACT,OAAO,EAAE,CAAC,IAAI,CAAC,UAAU;aAC1B;YACD,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE;YACxB,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,cAAc,EAAE,IAAI,CAAC,iBAAiB,EAAE,EAAE,QAAQ,EAAE,IAAI,KAAK;YAC7D,QAAQ,EAAE,IAAI,CAAC,UAAU;SAC1B,CAAC;QAEF,gCAAgC;QAChC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClC,IAAI,IAAI,EAAE,CAAC;oBACT,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;gBACxC,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,kCAAkC;YACpC,CAAC;QACH,CAAC;QAED,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CLI sync command - regenerate memory.md from Hindsight.
3
+ * @module cli/commands/sync
4
+ */
5
+ import type { CAC } from "cac";
6
+ /**
7
+ * Register the sync command.
8
+ */
9
+ export declare function registerSyncCommand(cli: CAC): void;
10
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/sync.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AA0O/B;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CA2FlD"}
@@ -0,0 +1,260 @@
1
+ /**
2
+ * CLI sync command - regenerate memory.md from Hindsight.
3
+ * @module cli/commands/sync
4
+ */
5
+ import { Mind } from "../../mind.js";
6
+ import { CLIError, ExitCode, info, output } from "../utils/index.js";
7
+ /**
8
+ * Deduplicate memories by ID.
9
+ */
10
+ function deduplicateMemories(memories) {
11
+ const seen = new Set();
12
+ return memories.filter((m) => {
13
+ if (seen.has(m.id)) {
14
+ return false;
15
+ }
16
+ seen.add(m.id);
17
+ return true;
18
+ });
19
+ }
20
+ /**
21
+ * Group memories by fact type.
22
+ */
23
+ function groupByType(memories) {
24
+ const groups = {
25
+ world: [],
26
+ experience: [],
27
+ opinion: [],
28
+ observation: [],
29
+ };
30
+ for (const memory of memories) {
31
+ const type = memory.factType || "world";
32
+ if (groups[type]) {
33
+ groups[type].push(memory);
34
+ }
35
+ }
36
+ return groups;
37
+ }
38
+ /**
39
+ * Extract tech stack facts from world memories.
40
+ */
41
+ function extractTechStack(worldMemories) {
42
+ const techKeywords = [
43
+ "uses",
44
+ "built with",
45
+ "framework",
46
+ "library",
47
+ "database",
48
+ "typescript",
49
+ "javascript",
50
+ "react",
51
+ "node",
52
+ "python",
53
+ "rust",
54
+ "go",
55
+ "api",
56
+ "sdk",
57
+ ];
58
+ return worldMemories
59
+ .filter((m) => {
60
+ const text = m.text.toLowerCase();
61
+ return techKeywords.some((kw) => text.includes(kw));
62
+ })
63
+ .map((m) => `- ${m.text}`)
64
+ .slice(0, 15); // Limit to top 15
65
+ }
66
+ /**
67
+ * Extract patterns from opinions.
68
+ */
69
+ function extractPatterns(opinions) {
70
+ return opinions
71
+ .filter((m) => (m.confidence ?? 0) >= 0.5)
72
+ .sort((a, b) => (b.confidence ?? 0) - (a.confidence ?? 0))
73
+ .map((m) => {
74
+ const confidence = ((m.confidence ?? 0) * 100).toFixed(0);
75
+ return `- ${m.text} (${confidence}% confidence)`;
76
+ })
77
+ .slice(0, 10); // Top 10 patterns
78
+ }
79
+ /**
80
+ * Extract high-confidence observations.
81
+ */
82
+ function extractObservations(opinions) {
83
+ return opinions
84
+ .filter((m) => (m.confidence ?? 0) >= 0.8)
85
+ .sort((a, b) => (b.confidence ?? 0) - (a.confidence ?? 0))
86
+ .map((m) => {
87
+ const date = new Date(m.createdAt).toISOString().split("T")[0];
88
+ const confidence = ((m.confidence ?? 0) * 100).toFixed(0);
89
+ return `- ${m.text} (${date}, ${confidence}%)`;
90
+ })
91
+ .slice(0, 10);
92
+ }
93
+ /**
94
+ * Extract recent experiences.
95
+ */
96
+ function extractRecentActivity(experiences) {
97
+ return experiences
98
+ .sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
99
+ .map((m) => {
100
+ const date = new Date(m.createdAt).toISOString().split("T")[0];
101
+ // Truncate long experiences
102
+ const text = m.text.length > 150 ? m.text.substring(0, 147) + "..." : m.text;
103
+ return `- ${date}: ${text}`;
104
+ })
105
+ .slice(0, 10);
106
+ }
107
+ /**
108
+ * Generate the memory.md content.
109
+ */
110
+ function generateMemoryContent(memories, timestamp) {
111
+ const groups = groupByType(memories);
112
+ const techStack = extractTechStack(groups.world ?? []);
113
+ const patterns = extractPatterns(groups.opinion ?? []);
114
+ const observations = extractObservations(groups.opinion ?? []);
115
+ const recentActivity = extractRecentActivity(groups.experience ?? []);
116
+ const sections = {
117
+ techStack: techStack.length,
118
+ patterns: patterns.length,
119
+ observations: observations.length,
120
+ recentActivity: recentActivity.length,
121
+ };
122
+ const parts = [];
123
+ // Header with timestamp
124
+ parts.push(`<!-- Last synced: ${timestamp} -->`);
125
+ parts.push(`<!-- Auto-generated by claude-cognitive sync -->`);
126
+ parts.push("");
127
+ // Tech Stack section
128
+ parts.push("## Tech Stack");
129
+ parts.push("");
130
+ if (techStack.length > 0) {
131
+ parts.push(...techStack);
132
+ }
133
+ else {
134
+ parts.push("<!-- No tech stack information found -->");
135
+ }
136
+ parts.push("");
137
+ // Key Patterns section
138
+ parts.push("## Key Patterns");
139
+ parts.push("");
140
+ if (patterns.length > 0) {
141
+ parts.push(...patterns);
142
+ }
143
+ else {
144
+ parts.push("<!-- No patterns identified yet -->");
145
+ }
146
+ parts.push("");
147
+ // Observations section (high-confidence insights)
148
+ parts.push("## Observations");
149
+ parts.push("");
150
+ if (observations.length > 0) {
151
+ parts.push(...observations);
152
+ }
153
+ else {
154
+ parts.push("<!-- No high-confidence observations yet -->");
155
+ }
156
+ parts.push("");
157
+ // Recent Activity section
158
+ parts.push("## Recent Activity");
159
+ parts.push("");
160
+ if (recentActivity.length > 0) {
161
+ parts.push(...recentActivity);
162
+ }
163
+ else {
164
+ parts.push("<!-- No recent activity recorded -->");
165
+ }
166
+ parts.push("");
167
+ return { content: parts.join("\n"), sections };
168
+ }
169
+ /**
170
+ * Format sync result for human-readable output.
171
+ */
172
+ function formatSyncResult(result) {
173
+ const lines = [];
174
+ if (result.dryRun) {
175
+ lines.push("=== DRY RUN (no changes written) ===");
176
+ lines.push("");
177
+ }
178
+ lines.push(`Synced memory.md from Hindsight`);
179
+ lines.push(` Timestamp: ${result.timestamp}`);
180
+ lines.push(` Memories processed: ${result.memoriesProcessed}`);
181
+ lines.push(` Path: ${result.path}`);
182
+ lines.push("");
183
+ lines.push("Sections generated:");
184
+ lines.push(` Tech Stack: ${result.sections.techStack} items`);
185
+ lines.push(` Key Patterns: ${result.sections.patterns} items`);
186
+ lines.push(` Observations: ${result.sections.observations} items`);
187
+ lines.push(` Recent Activity: ${result.sections.recentActivity} items`);
188
+ return lines.join("\n");
189
+ }
190
+ /**
191
+ * Register the sync command.
192
+ */
193
+ export function registerSyncCommand(cli) {
194
+ cli
195
+ .command("sync", "Regenerate memory.md from Hindsight memories")
196
+ .option("--project <path>", "Project directory (default: current directory)")
197
+ .option("--dry-run", "Preview changes without writing")
198
+ .option("--json", "Output as JSON")
199
+ .option("--quiet", "Suppress output")
200
+ .action(async (options) => {
201
+ const projectPath = options.project ?? process.cwd();
202
+ const mind = new Mind({ projectPath });
203
+ await mind.init();
204
+ if (mind.isDegraded) {
205
+ throw new CLIError("Cannot sync: Hindsight is unavailable.", ExitCode.CONNECTION_ERROR, "Make sure Hindsight is running and accessible.");
206
+ }
207
+ info("Syncing memory.md from Hindsight...", options);
208
+ // Query all memory types
209
+ const [worldMemories, experienceMemories, opinionMemories] = await Promise.all([
210
+ mind.recall("project technology stack architecture", {
211
+ factType: "world",
212
+ budget: "high",
213
+ }),
214
+ mind.recall("recent work changes fixes", {
215
+ factType: "experience",
216
+ budget: "mid",
217
+ }),
218
+ mind.recall("patterns insights observations beliefs", {
219
+ factType: "opinion",
220
+ budget: "high",
221
+ }),
222
+ ]);
223
+ // Deduplicate memories (recall queries may overlap)
224
+ const allMemories = deduplicateMemories([
225
+ ...worldMemories,
226
+ ...experienceMemories,
227
+ ...opinionMemories,
228
+ ]);
229
+ const timestamp = new Date().toISOString();
230
+ const { content, sections } = generateMemoryContent(allMemories, timestamp);
231
+ const semanticMemory = mind.getSemanticMemory();
232
+ if (!semanticMemory) {
233
+ throw new CLIError("Semantic memory not initialized.", ExitCode.GENERAL_ERROR);
234
+ }
235
+ const result = {
236
+ timestamp,
237
+ memoriesProcessed: allMemories.length,
238
+ sections,
239
+ path: semanticMemory.getFilePath(),
240
+ dryRun: options.dryRun ?? false,
241
+ };
242
+ // Write unless dry run
243
+ if (!options.dryRun) {
244
+ const { writeFile, mkdir } = await import("node:fs/promises");
245
+ const { dirname } = await import("node:path");
246
+ // Ensure directory exists
247
+ await mkdir(dirname(semanticMemory.getFilePath()), { recursive: true });
248
+ // Write the file
249
+ await writeFile(semanticMemory.getFilePath(), content, "utf-8");
250
+ }
251
+ else if (!options.json && !options.quiet) {
252
+ // In dry-run mode, show the content that would be written
253
+ console.error("\n--- Generated content ---\n");
254
+ console.error(content);
255
+ console.error("--- End generated content ---\n");
256
+ }
257
+ output(result, formatSyncResult, options);
258
+ });
259
+ }
260
+ //# sourceMappingURL=sync.js.map