@noorm/marie-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 (193) hide show
  1. package/JOY_ZONING.md +200 -0
  2. package/LICENSE.md +190 -0
  3. package/README.md +94 -0
  4. package/dist/cli-new/components/App.js +138 -0
  5. package/dist/cli-new/components/App.js.map +1 -0
  6. package/dist/cli-new/components/ApprovalDialog.js +31 -0
  7. package/dist/cli-new/components/ApprovalDialog.js.map +1 -0
  8. package/dist/cli-new/components/Banner.js +23 -0
  9. package/dist/cli-new/components/Banner.js.map +1 -0
  10. package/dist/cli-new/components/ChatArea.js +49 -0
  11. package/dist/cli-new/components/ChatArea.js.map +1 -0
  12. package/dist/cli-new/components/Header.js +20 -0
  13. package/dist/cli-new/components/Header.js.map +1 -0
  14. package/dist/cli-new/components/InputArea.js +97 -0
  15. package/dist/cli-new/components/InputArea.js.map +1 -0
  16. package/dist/cli-new/components/MessageBubble.js +114 -0
  17. package/dist/cli-new/components/MessageBubble.js.map +1 -0
  18. package/dist/cli-new/components/SessionSwitcher.js +46 -0
  19. package/dist/cli-new/components/SessionSwitcher.js.map +1 -0
  20. package/dist/cli-new/components/SetupWizard.js +283 -0
  21. package/dist/cli-new/components/SetupWizard.js.map +1 -0
  22. package/dist/cli-new/components/ToolCallDisplay.js +45 -0
  23. package/dist/cli-new/components/ToolCallDisplay.js.map +1 -0
  24. package/dist/cli-new/hooks/useGit.js +99 -0
  25. package/dist/cli-new/hooks/useGit.js.map +1 -0
  26. package/dist/cli-new/hooks/useMarie.js +249 -0
  27. package/dist/cli-new/hooks/useMarie.js.map +1 -0
  28. package/dist/cli-new/hooks/useSessions.js +75 -0
  29. package/dist/cli-new/hooks/useSessions.js.map +1 -0
  30. package/dist/cli-new/index.js +52 -0
  31. package/dist/cli-new/index.js.map +1 -0
  32. package/dist/cli-new/styles/theme.js +68 -0
  33. package/dist/cli-new/styles/theme.js.map +1 -0
  34. package/dist/cli-new/types/cli.js +2 -0
  35. package/dist/cli-new/types/cli.js.map +1 -0
  36. package/dist/extension.cjs +655 -0
  37. package/dist/monolith/adapters/CliMarieAdapter.js +72 -0
  38. package/dist/monolith/adapters/CliMarieAdapter.js.map +1 -0
  39. package/dist/monolith/adapters/VscodeMarieAdapter.js +81 -0
  40. package/dist/monolith/adapters/VscodeMarieAdapter.js.map +1 -0
  41. package/dist/monolith/cli/CliFileSystemPort.js +83 -0
  42. package/dist/monolith/cli/CliFileSystemPort.js.map +1 -0
  43. package/dist/monolith/cli/MarieToolDefinitionsCLI.js +438 -0
  44. package/dist/monolith/cli/MarieToolDefinitionsCLI.js.map +1 -0
  45. package/dist/monolith/cli/index.js +272 -0
  46. package/dist/monolith/cli/index.js.map +1 -0
  47. package/dist/monolith/cli/services/JoyAutomationServiceCLI.js +80 -0
  48. package/dist/monolith/cli/services/JoyAutomationServiceCLI.js.map +1 -0
  49. package/dist/monolith/cli/services/JoyServiceCLI.js +63 -0
  50. package/dist/monolith/cli/services/JoyServiceCLI.js.map +1 -0
  51. package/dist/monolith/cli/storage.js +119 -0
  52. package/dist/monolith/cli/storage.js.map +1 -0
  53. package/dist/monolith/domain/joy/JoyTools.js +513 -0
  54. package/dist/monolith/domain/joy/JoyTools.js.map +1 -0
  55. package/dist/monolith/domain/joy/RitualService.js +51 -0
  56. package/dist/monolith/domain/joy/RitualService.js.map +1 -0
  57. package/dist/monolith/domain/marie/MarieTypes.js +2 -0
  58. package/dist/monolith/domain/marie/MarieTypes.js.map +1 -0
  59. package/dist/monolith/infrastructure/ai/agents/MarieAscendant.js +230 -0
  60. package/dist/monolith/infrastructure/ai/agents/MarieAscendant.js.map +1 -0
  61. package/dist/monolith/infrastructure/ai/agents/MarieYOLO.js +207 -0
  62. package/dist/monolith/infrastructure/ai/agents/MarieYOLO.js.map +1 -0
  63. package/dist/monolith/infrastructure/ai/context/ContextArchiveService.js +129 -0
  64. package/dist/monolith/infrastructure/ai/context/ContextArchiveService.js.map +1 -0
  65. package/dist/monolith/infrastructure/ai/context/ContextManager.js +118 -0
  66. package/dist/monolith/infrastructure/ai/context/ContextManager.js.map +1 -0
  67. package/dist/monolith/infrastructure/ai/core/FileSystemPort.js +2 -0
  68. package/dist/monolith/infrastructure/ai/core/FileSystemPort.js.map +1 -0
  69. package/dist/monolith/infrastructure/ai/core/GhostPort.js +2 -0
  70. package/dist/monolith/infrastructure/ai/core/GhostPort.js.map +1 -0
  71. package/dist/monolith/infrastructure/ai/core/MarieAscensionTypes.js +2 -0
  72. package/dist/monolith/infrastructure/ai/core/MarieAscensionTypes.js.map +1 -0
  73. package/dist/monolith/infrastructure/ai/core/MarieEngine.js +590 -0
  74. package/dist/monolith/infrastructure/ai/core/MarieEngine.js.map +1 -0
  75. package/dist/monolith/infrastructure/ai/core/MarieEventDispatcher.js +161 -0
  76. package/dist/monolith/infrastructure/ai/core/MarieEventDispatcher.js.map +1 -0
  77. package/dist/monolith/infrastructure/ai/core/MarieLockManager.js +121 -0
  78. package/dist/monolith/infrastructure/ai/core/MarieLockManager.js.map +1 -0
  79. package/dist/monolith/infrastructure/ai/core/MarieProgressTracker.js +256 -0
  80. package/dist/monolith/infrastructure/ai/core/MarieProgressTracker.js.map +1 -0
  81. package/dist/monolith/infrastructure/ai/core/MariePulseService.js +67 -0
  82. package/dist/monolith/infrastructure/ai/core/MariePulseService.js.map +1 -0
  83. package/dist/monolith/infrastructure/ai/core/MarieResponse.js +101 -0
  84. package/dist/monolith/infrastructure/ai/core/MarieResponse.js.map +1 -0
  85. package/dist/monolith/infrastructure/ai/core/MarieSanitizer.js +86 -0
  86. package/dist/monolith/infrastructure/ai/core/MarieSanitizer.js.map +1 -0
  87. package/dist/monolith/infrastructure/ai/core/MarieSession.js +202 -0
  88. package/dist/monolith/infrastructure/ai/core/MarieSession.js.map +1 -0
  89. package/dist/monolith/infrastructure/ai/core/MarieStabilityMonitor.js +58 -0
  90. package/dist/monolith/infrastructure/ai/core/MarieStabilityMonitor.js.map +1 -0
  91. package/dist/monolith/infrastructure/ai/core/MarieToolMender.js +127 -0
  92. package/dist/monolith/infrastructure/ai/core/MarieToolMender.js.map +1 -0
  93. package/dist/monolith/infrastructure/ai/core/MarieToolProcessor.js +548 -0
  94. package/dist/monolith/infrastructure/ai/core/MarieToolProcessor.js.map +1 -0
  95. package/dist/monolith/infrastructure/ai/core/MarieYOLOTypes.js +2 -0
  96. package/dist/monolith/infrastructure/ai/core/MarieYOLOTypes.js.map +1 -0
  97. package/dist/monolith/infrastructure/ai/core/ReasoningBudget.js +125 -0
  98. package/dist/monolith/infrastructure/ai/core/ReasoningBudget.js.map +1 -0
  99. package/dist/monolith/infrastructure/ai/core/VscodeFileSystemPort.js +30 -0
  100. package/dist/monolith/infrastructure/ai/core/VscodeFileSystemPort.js.map +1 -0
  101. package/dist/monolith/infrastructure/ai/providers/AIProvider.js +2 -0
  102. package/dist/monolith/infrastructure/ai/providers/AIProvider.js.map +1 -0
  103. package/dist/monolith/infrastructure/ai/providers/AnthropicProvider.js +148 -0
  104. package/dist/monolith/infrastructure/ai/providers/AnthropicProvider.js.map +1 -0
  105. package/dist/monolith/infrastructure/ai/providers/CerebrasProvider.js +208 -0
  106. package/dist/monolith/infrastructure/ai/providers/CerebrasProvider.js.map +1 -0
  107. package/dist/monolith/infrastructure/ai/providers/OpenRouterProvider.js +404 -0
  108. package/dist/monolith/infrastructure/ai/providers/OpenRouterProvider.js.map +1 -0
  109. package/dist/monolith/infrastructure/ai/providers/OpenRouterStreamParser.js +283 -0
  110. package/dist/monolith/infrastructure/ai/providers/OpenRouterStreamParser.js.map +1 -0
  111. package/dist/monolith/infrastructure/config/ConfigService.js +398 -0
  112. package/dist/monolith/infrastructure/config/ConfigService.js.map +1 -0
  113. package/dist/monolith/infrastructure/services/MarieMemoryStore.js +140 -0
  114. package/dist/monolith/infrastructure/services/MarieMemoryStore.js.map +1 -0
  115. package/dist/monolith/infrastructure/tools/MarieToolDefinitions.js +1568 -0
  116. package/dist/monolith/infrastructure/tools/MarieToolDefinitions.js.map +1 -0
  117. package/dist/monolith/infrastructure/tools/PureStreamParser.js +147 -0
  118. package/dist/monolith/infrastructure/tools/PureStreamParser.js.map +1 -0
  119. package/dist/monolith/infrastructure/tools/SharedToolDefinitions.js +223 -0
  120. package/dist/monolith/infrastructure/tools/SharedToolDefinitions.js.map +1 -0
  121. package/dist/monolith/infrastructure/tools/ToolRegistry.js +29 -0
  122. package/dist/monolith/infrastructure/tools/ToolRegistry.js.map +1 -0
  123. package/dist/monolith/infrastructure/tools/ToolUtils.js +59 -0
  124. package/dist/monolith/infrastructure/tools/ToolUtils.js.map +1 -0
  125. package/dist/monolith/plumbing/analysis/CodeHealthService.js +146 -0
  126. package/dist/monolith/plumbing/analysis/CodeHealthService.js.map +1 -0
  127. package/dist/monolith/plumbing/analysis/ComplexityService.js +43 -0
  128. package/dist/monolith/plumbing/analysis/ComplexityService.js.map +1 -0
  129. package/dist/monolith/plumbing/analysis/DependencyService.js +51 -0
  130. package/dist/monolith/plumbing/analysis/DependencyService.js.map +1 -0
  131. package/dist/monolith/plumbing/analysis/DiscoveryService.js +49 -0
  132. package/dist/monolith/plumbing/analysis/DiscoveryService.js.map +1 -0
  133. package/dist/monolith/plumbing/analysis/JoyMapService.js +66 -0
  134. package/dist/monolith/plumbing/analysis/JoyMapService.js.map +1 -0
  135. package/dist/monolith/plumbing/analysis/LintService.js +132 -0
  136. package/dist/monolith/plumbing/analysis/LintService.js.map +1 -0
  137. package/dist/monolith/plumbing/analysis/MarieSentinelService.js +276 -0
  138. package/dist/monolith/plumbing/analysis/MarieSentinelService.js.map +1 -0
  139. package/dist/monolith/plumbing/analysis/QualityGuardrailService.js +119 -0
  140. package/dist/monolith/plumbing/analysis/QualityGuardrailService.js.map +1 -0
  141. package/dist/monolith/plumbing/analysis/SurgicalMender.js +70 -0
  142. package/dist/monolith/plumbing/analysis/SurgicalMender.js.map +1 -0
  143. package/dist/monolith/plumbing/analysis/TestService.js +104 -0
  144. package/dist/monolith/plumbing/analysis/TestService.js.map +1 -0
  145. package/dist/monolith/plumbing/filesystem/FileService.js +406 -0
  146. package/dist/monolith/plumbing/filesystem/FileService.js.map +1 -0
  147. package/dist/monolith/plumbing/filesystem/PathResolver.js +26 -0
  148. package/dist/monolith/plumbing/filesystem/PathResolver.js.map +1 -0
  149. package/dist/monolith/plumbing/git/GitService.js +71 -0
  150. package/dist/monolith/plumbing/git/GitService.js.map +1 -0
  151. package/dist/monolith/plumbing/lsp/SymbolService.js +36 -0
  152. package/dist/monolith/plumbing/lsp/SymbolService.js.map +1 -0
  153. package/dist/monolith/plumbing/terminal/ProcessRegistry.js +31 -0
  154. package/dist/monolith/plumbing/terminal/ProcessRegistry.js.map +1 -0
  155. package/dist/monolith/plumbing/terminal/TerminalService.js +180 -0
  156. package/dist/monolith/plumbing/terminal/TerminalService.js.map +1 -0
  157. package/dist/monolith/plumbing/ui/DecorationService.js +54 -0
  158. package/dist/monolith/plumbing/ui/DecorationService.js.map +1 -0
  159. package/dist/monolith/plumbing/utils/ErrorUtils.js +11 -0
  160. package/dist/monolith/plumbing/utils/ErrorUtils.js.map +1 -0
  161. package/dist/monolith/plumbing/utils/JsonUtils.js +360 -0
  162. package/dist/monolith/plumbing/utils/JsonUtils.js.map +1 -0
  163. package/dist/monolith/plumbing/utils/PrefixTree.js +153 -0
  164. package/dist/monolith/plumbing/utils/PrefixTree.js.map +1 -0
  165. package/dist/monolith/plumbing/utils/RetryUtils.js +141 -0
  166. package/dist/monolith/plumbing/utils/RetryUtils.js.map +1 -0
  167. package/dist/monolith/plumbing/utils/StreamTagDetector.js +128 -0
  168. package/dist/monolith/plumbing/utils/StreamTagDetector.js.map +1 -0
  169. package/dist/monolith/plumbing/utils/StringUtils.js +97 -0
  170. package/dist/monolith/plumbing/utils/StringUtils.js.map +1 -0
  171. package/dist/monolith/plumbing/utils/TimeoutUtils.js +21 -0
  172. package/dist/monolith/plumbing/utils/TimeoutUtils.js.map +1 -0
  173. package/dist/monolith/runtime/MarieRuntime.js +354 -0
  174. package/dist/monolith/runtime/MarieRuntime.js.map +1 -0
  175. package/dist/monolith/runtime/RuntimeAdapterBase.js +59 -0
  176. package/dist/monolith/runtime/RuntimeAdapterBase.js.map +1 -0
  177. package/dist/monolith/runtime/providerFactory.js +11 -0
  178. package/dist/monolith/runtime/providerFactory.js.map +1 -0
  179. package/dist/monolith/runtime/types.js +2 -0
  180. package/dist/monolith/runtime/types.js.map +1 -0
  181. package/dist/monolith/services/HealthService.js +38 -0
  182. package/dist/monolith/services/HealthService.js.map +1 -0
  183. package/dist/monolith/services/JoyAutomationService.js +131 -0
  184. package/dist/monolith/services/JoyAutomationService.js.map +1 -0
  185. package/dist/monolith/services/JoyLogService.js +48 -0
  186. package/dist/monolith/services/JoyLogService.js.map +1 -0
  187. package/dist/monolith/services/JoyService.js +190 -0
  188. package/dist/monolith/services/JoyService.js.map +1 -0
  189. package/dist/monolith/services/MarieGhostService.js +168 -0
  190. package/dist/monolith/services/MarieGhostService.js.map +1 -0
  191. package/dist/monolith/services/MarieSCMProvider.js +41 -0
  192. package/dist/monolith/services/MarieSCMProvider.js.map +1 -0
  193. package/package.json +168 -0
@@ -0,0 +1,101 @@
1
+ import { StringUtils } from "../../../plumbing/utils/StringUtils.js";
2
+ /**
3
+ * Normalizes AI message content (string | block[]) into a stable interface.
4
+ * This prevents TypeError breakdowns like "e.trim is not a function".
5
+ */
6
+ export class MarieResponse {
7
+ content;
8
+ cachedText;
9
+ constructor(content) {
10
+ this.content = content;
11
+ this.cachedText = StringUtils.extractText(content);
12
+ }
13
+ /**
14
+ * Returns the full text content as a single string.
15
+ */
16
+ getText() {
17
+ return this.cachedText;
18
+ }
19
+ /**
20
+ * Returns the text trimmed for one-liners or headers.
21
+ */
22
+ getTrimmed() {
23
+ return this.cachedText.trim();
24
+ }
25
+ /**
26
+ * Returns the raw content (string or block array).
27
+ */
28
+ getRaw() {
29
+ return this.content;
30
+ }
31
+ /**
32
+ * Extracts tool calls from the response if they exist.
33
+ */
34
+ hasText() {
35
+ return this.getText().length > 0;
36
+ }
37
+ isShaky() {
38
+ const text = this.getTrimmed();
39
+ const reasoning = this.getReasoning();
40
+ // A response is shaky if it's dead empty and has no reasoning or tools
41
+ if (text.length === 0 && reasoning.length === 0 && !this.hasToolCalls())
42
+ return true;
43
+ // Short text is shaky ONLY if there's also no reasoning and no tools
44
+ return text.length < 10 && reasoning.length < 10 && !this.hasToolCalls();
45
+ }
46
+ getReasoning() {
47
+ if (!Array.isArray(this.content))
48
+ return "";
49
+ let reasoning = "";
50
+ const blocks = this.content;
51
+ for (let i = 0; i < blocks.length; i++) {
52
+ const block = blocks[i];
53
+ if (block && (block.type === "thought" || block.type === "reasoning")) {
54
+ const text = block.text || block.reasoning || "";
55
+ if (reasoning)
56
+ reasoning += "\n" + text;
57
+ else
58
+ reasoning = text;
59
+ }
60
+ }
61
+ return reasoning;
62
+ }
63
+ getTools(name) {
64
+ const tools = this.getToolCalls();
65
+ if (name) {
66
+ return tools.filter((t) => t.name === name);
67
+ }
68
+ return tools;
69
+ }
70
+ getToolCalls() {
71
+ if (!Array.isArray(this.content))
72
+ return [];
73
+ const tools = [];
74
+ const blocks = this.content;
75
+ for (let i = 0; i < blocks.length; i++) {
76
+ if (blocks[i].type === "tool_use") {
77
+ tools.push(blocks[i]);
78
+ }
79
+ }
80
+ return tools;
81
+ }
82
+ /**
83
+ * Checks if the response contains any tool calls.
84
+ */
85
+ hasToolCalls() {
86
+ if (!Array.isArray(this.content))
87
+ return false;
88
+ for (let i = 0; i < this.content.length; i++) {
89
+ if (this.content[i].type === "tool_use")
90
+ return true;
91
+ }
92
+ return false;
93
+ }
94
+ /**
95
+ * Helper to wrap any possible AI message content safely.
96
+ */
97
+ static wrap(content) {
98
+ return new MarieResponse(content);
99
+ }
100
+ }
101
+ //# sourceMappingURL=MarieResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarieResponse.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/MarieRespon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O,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACI,YAAY;QACjB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU;gBAAE,OAAO,IAAI,CAAC;QACvD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,IAAI,CAAC,OAAY;QAC7B,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * QUANTUM RESILIENCE: MarieSanitizer
3
+ * Purges circular references, enforces depth and breadth limits, and truncates massive strings.
4
+ * Ensures the telemetry stream never crashes the VS Code bridge.
5
+ */
6
+ export class MarieSanitizer {
7
+ static MAX_DEPTH = 10;
8
+ static STRING_LIMIT = 5000;
9
+ static BREADTH_LIMIT = 100;
10
+ static GLOBAL_MAX_SIZE = 512 * 1024; // 512KB total safety cap
11
+ /**
12
+ * Sanitizes an object for safe JSON serialization and bridge transport.
13
+ * @param obj The object to sanitize.
14
+ */
15
+ static sanitize(obj) {
16
+ const seen = new WeakSet();
17
+ let totalSize = 0;
18
+ const sanitizer = (val, depth) => {
19
+ if (totalSize > this.GLOBAL_MAX_SIZE)
20
+ return "[Global Size Limit Reached]";
21
+ if (depth > this.MAX_DEPTH)
22
+ return "[Max Depth Reached]";
23
+ if (val === null || val === undefined)
24
+ return val;
25
+ const type = typeof val;
26
+ if (type === "string") {
27
+ const effectiveLength = Math.min(val.length, this.STRING_LIMIT);
28
+ totalSize += effectiveLength;
29
+ if (val.length > this.STRING_LIMIT) {
30
+ return val.substring(0, this.STRING_LIMIT) + "... [Truncated]";
31
+ }
32
+ return val;
33
+ }
34
+ if (type === "number") {
35
+ totalSize += 8;
36
+ return val;
37
+ }
38
+ if (type === "boolean") {
39
+ totalSize += 4;
40
+ return val;
41
+ }
42
+ if (type === "function")
43
+ return "[Function]";
44
+ if (type === "symbol")
45
+ return "[Symbol]";
46
+ if (type === "object") {
47
+ if (seen.has(val))
48
+ return "[Circular Reference]";
49
+ seen.add(val);
50
+ if (Array.isArray(val)) {
51
+ const arr = val
52
+ .slice(0, this.BREADTH_LIMIT)
53
+ .map((item) => sanitizer(item, depth + 1));
54
+ if (val.length > this.BREADTH_LIMIT) {
55
+ arr.push(`... [${val.length - this.BREADTH_LIMIT} items truncated]`);
56
+ }
57
+ return arr;
58
+ }
59
+ const sanitized = {};
60
+ const keys = Object.keys(val);
61
+ const limitedKeys = keys.slice(0, this.BREADTH_LIMIT);
62
+ for (const key of limitedKeys) {
63
+ if (key.startsWith("_") ||
64
+ key === "extensionContext" ||
65
+ key === "provider")
66
+ continue;
67
+ try {
68
+ totalSize += key.length;
69
+ sanitized[key] = sanitizer(val[key], depth + 1);
70
+ }
71
+ catch {
72
+ sanitized[key] = "[Unreadable]";
73
+ }
74
+ }
75
+ if (keys.length > this.BREADTH_LIMIT) {
76
+ sanitized["_truncated"] =
77
+ `${keys.length - this.BREADTH_LIMIT} properties truncated`;
78
+ }
79
+ return sanitized;
80
+ }
81
+ return String(val);
82
+ };
83
+ return sanitizer(obj, 0);
84
+ }
85
+ }
86
+ //# sourceMappingURL=MarieSanitizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarieSanitizer.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/MarieSanitizer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,cAAc;IACjB,MAAM,CAAU,SAAS,GAAG,EAAE,CAAC;IAC/B,MAAM,CAAU,YAAY,GAAG,IAAI,CAAC;IACpC,MAAM,CAAU,aAAa,GAAG,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AAM,CAAC;wBACP,SAAS,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC;oBAClC,CAAC;gBACH,CAAC;gBAED,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;oBACrC,SAAS,CAAC,YAAY,CAAC;wBACrB,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,uBAAuB,CAAC;gBAC/D,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC,CAAC;QAEF,OAAO,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC3B,CAAC"}
@@ -0,0 +1,202 @@
1
+ import { ConfigService } from "../../config/ConfigService.js";
2
+ import { ContextManager } from "../context/ContextManager.js";
3
+ import { SYSTEM_CONTINUATION_PROMPT, SYSTEM_PROMPT, } from "../../../../prompts.js";
4
+ import { MarieResponse } from "./MarieResponse.js";
5
+ /**
6
+ * Manages a single AI chat session with a reactive streaming model.
7
+ */
8
+ export class MarieSession {
9
+ provider;
10
+ toolRegistry;
11
+ saveHistory;
12
+ messages;
13
+ tracker;
14
+ providerFactory;
15
+ promptProfile;
16
+ constructor(provider, toolRegistry, saveHistory, messages, tracker, providerFactory, promptProfile = "full") {
17
+ this.provider = provider;
18
+ this.toolRegistry = toolRegistry;
19
+ this.saveHistory = saveHistory;
20
+ this.messages = messages;
21
+ this.tracker = tracker;
22
+ this.providerFactory = providerFactory;
23
+ this.promptProfile = promptProfile;
24
+ }
25
+ resolveSystemPrompt() {
26
+ return this.promptProfile === "continuation"
27
+ ? SYSTEM_CONTINUATION_PROMPT
28
+ : SYSTEM_PROMPT;
29
+ }
30
+ async *executeLoop(messages, signal, state) {
31
+ // PHASE 6: Generator Disposal Grace - Snapshot messages before modification
32
+ // This ensures we can restore to a consistent state if aborted mid-run
33
+ const messagesSnapshot = messages.map((m) => ({ ...m }));
34
+ let messagesModified = false;
35
+ try {
36
+ const managedMessages = await ContextManager.manage(messages, this.provider, state);
37
+ if (managedMessages !== messages) {
38
+ messages.length = 0;
39
+ for (const msg of managedMessages) {
40
+ messages.push(msg);
41
+ }
42
+ messagesModified = true;
43
+ }
44
+ const params = {
45
+ model: ConfigService.getModel(),
46
+ max_tokens: 8192,
47
+ messages: managedMessages,
48
+ system: this.resolveSystemPrompt(),
49
+ tools: this.toolRegistry.getTools(),
50
+ };
51
+ const eventQueue = [];
52
+ let resolver = null;
53
+ const onAbort = () => {
54
+ if (resolver) {
55
+ resolver({ done: true, value: undefined });
56
+ resolver = null;
57
+ }
58
+ };
59
+ signal?.addEventListener("abort", onAbort);
60
+ let streamPromise = null;
61
+ let attempts = 0;
62
+ const maxAttempts = 3;
63
+ while (attempts < maxAttempts) {
64
+ try {
65
+ streamPromise = this.provider.createMessageStream(params, (event) => {
66
+ eventQueue.push(event);
67
+ if (resolver) {
68
+ resolver({ value: eventQueue.shift(), done: false });
69
+ resolver = null;
70
+ }
71
+ }, signal);
72
+ break;
73
+ }
74
+ catch (e) {
75
+ attempts++;
76
+ const isRetryable = e.status === 429 ||
77
+ e.status >= 500 ||
78
+ e.message?.includes("rate limit");
79
+ if (isRetryable && attempts < maxAttempts && this.providerFactory) {
80
+ const currentType = ConfigService.getAiProvider();
81
+ const failoverType = currentType === "anthropic"
82
+ ? "openrouter"
83
+ : currentType === "openrouter"
84
+ ? "cerebras"
85
+ : "anthropic";
86
+ console.warn(`[SpectralFailover] Attempt ${attempts} failed for ${currentType}. Switching to ${failoverType}.`);
87
+ this.tracker?.emitEvent({
88
+ type: "reasoning",
89
+ runId: this.tracker.getRun().runId,
90
+ text: `🔄 SPECTRAL FAILOVER: ${currentType} is struggling. Switching to ${failoverType} mid-turn...`,
91
+ elapsedMs: this.tracker.elapsedMs(),
92
+ });
93
+ this.provider = this.providerFactory(failoverType);
94
+ continue;
95
+ }
96
+ throw e;
97
+ }
98
+ }
99
+ if (!streamPromise)
100
+ throw new Error("Failed to initialize AI stream.");
101
+ try {
102
+ while (true) {
103
+ if (signal?.aborted)
104
+ break;
105
+ if (eventQueue.length > 0) {
106
+ const event = eventQueue.shift();
107
+ yield event;
108
+ }
109
+ else {
110
+ const result = await Promise.race([
111
+ streamPromise.then(() => ({ done: true })),
112
+ new Promise((r) => (resolver = r)),
113
+ ]);
114
+ if (result.done) {
115
+ while (eventQueue.length > 0) {
116
+ const event = eventQueue.shift();
117
+ yield event;
118
+ }
119
+ break;
120
+ }
121
+ yield result.value;
122
+ }
123
+ }
124
+ }
125
+ finally {
126
+ signal?.removeEventListener("abort", onAbort);
127
+ }
128
+ const response = await streamPromise;
129
+ let finalContent = response.content;
130
+ if (response.tool_uses && response.tool_uses.length > 0) {
131
+ const blocks = [];
132
+ if (Array.isArray(response.content)) {
133
+ blocks.push(...response.content);
134
+ }
135
+ else if (response.content) {
136
+ blocks.push({ type: "text", text: response.content });
137
+ }
138
+ for (const tool of response.tool_uses) {
139
+ blocks.push({ type: "tool_use", ...tool });
140
+ }
141
+ finalContent = blocks;
142
+ }
143
+ if (signal?.aborted) {
144
+ console.warn("[MarieSession] Execution aborted. History will NOT be updated for this turn.");
145
+ // PHASE 6: Generator Disposal Grace - Restore messages to consistent state
146
+ if (messagesModified) {
147
+ console.warn("[MarieSession] Restoring messages array to pre-run state due to abort.");
148
+ messages.length = 0;
149
+ for (const msg of messagesSnapshot) {
150
+ messages.push(msg);
151
+ }
152
+ }
153
+ return;
154
+ }
155
+ messages.push({
156
+ role: "assistant",
157
+ content: finalContent,
158
+ timestamp: Date.now(),
159
+ });
160
+ await this.saveHistory(this.tracker?.getRun());
161
+ }
162
+ catch (error) {
163
+ // PHASE 6: Generator Disposal Grace - Restore messages on any error
164
+ if (messagesModified) {
165
+ console.warn("[MarieSession] Restoring messages array to pre-run state due to error:", error);
166
+ messages.length = 0;
167
+ for (const msg of messagesSnapshot) {
168
+ messages.push(msg);
169
+ }
170
+ }
171
+ throw error;
172
+ }
173
+ }
174
+ /**
175
+ * Non-streaming version for simpler engine integration.
176
+ */
177
+ async generate() {
178
+ const state = this.tracker?.getRun().ascensionState;
179
+ const params = {
180
+ model: ConfigService.getModel(),
181
+ max_tokens: 8192,
182
+ messages: await ContextManager.manage(this.messages, this.provider, state),
183
+ system: this.resolveSystemPrompt(),
184
+ tools: this.toolRegistry.getTools(),
185
+ };
186
+ const response = await this.provider.createMessageStream(params, () => { });
187
+ let finalContent = response.content;
188
+ if (response.tool_uses && response.tool_uses.length > 0) {
189
+ const blocks = [];
190
+ if (Array.isArray(response.content))
191
+ blocks.push(...response.content);
192
+ else if (response.content)
193
+ blocks.push({ type: "text", text: response.content });
194
+ for (const tool of response.tool_uses)
195
+ blocks.push({ type: "tool_use", ...tool });
196
+ finalContent = blocks;
197
+ }
198
+ this.messages.push({ role: "assistant", content: finalContent });
199
+ return new MarieResponse(finalContent);
200
+ }
201
+ }
202
+ //# sourceMappingURL=MarieSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarieSession.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/MarieSession.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EACL,0BAA0B,EAC1B,aAAa,GACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOnD;;GAEG;AACH,MAAM,OAAO,YAAY;IAEb;IACA;IACA;IACA;IACA;IACA;IACA;IAPV,YACU,QAAoB,EACpB,YAA0B,EAC1B,WAA+C,EAC/C,QAAe,EACf,OAA8B,EAC9B,eAA8C,EAC9C,gBAA2C,MAAM;QANjD,aAAQ,GAAR,QAAQ,CAAY;QACpB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,gBAAW,GAAX,WAAW,CAAoC;QAC/C,aAAQ,GAAR,QAAQ,CAAO;QACf,YAAO,GAAP,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AAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC3E,IAAI,YAAY,GAAQ,QAAQ,CAAC,OAAO,CAAC;QACzC,IAAI,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxD,MAAM,MAAM,GAAU,EAAE,CAAC;YACzB,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAAE,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;iBACjE,IAAI,QAAQ,CAAC,OAAO;gBACvB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;YACxD,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,SAAS;gBACnC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;YAC7C,YAAY,GAAG,MAAM,CAAC;QACxB,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;QACjE,OAAO,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,58 @@
1
+ // MarieStabilityMonitor - Proactive stability monitor for the Extension Host/CLI
2
+ /**
3
+ * Proactive stability monitor for the Extension Host.
4
+ * Detects event loop lag and heap pressure.
5
+ */
6
+ export class MarieStabilityMonitor {
7
+ static lag = 0;
8
+ static interval = null;
9
+ static lastTick = Date.now();
10
+ static cooldownActive = false;
11
+ static start() {
12
+ if (this.interval)
13
+ return;
14
+ this.lastTick = Date.now();
15
+ this.interval = setInterval(() => {
16
+ const now = Date.now();
17
+ const drift = now - this.lastTick - 1000;
18
+ this.lag = Math.max(0, drift);
19
+ this.lastTick = now;
20
+ if (this.lag > 150) {
21
+ console.warn(`[MarieStabilityMonitor] CRITICAL EVENT LOOP LAG: ${this.lag}ms. Triggering UI preservation cooldown.`);
22
+ this.cooldownActive = true;
23
+ }
24
+ else if (this.lag < 50) {
25
+ this.cooldownActive = false;
26
+ }
27
+ }, 1000);
28
+ // Ensure we don't leak if the process is weird
29
+ if (this.interval.unref) {
30
+ this.interval.unref();
31
+ }
32
+ }
33
+ static stop() {
34
+ if (this.interval) {
35
+ clearInterval(this.interval);
36
+ this.interval = null;
37
+ }
38
+ }
39
+ static isHighPressure() {
40
+ // High pressure if lag > 100ms or heap usage > 80% (if process.memoryUsage is reliable)
41
+ const mem = process.memoryUsage();
42
+ const heapPressure = mem.heapUsed / mem.heapTotal > 0.85;
43
+ return this.lag > 100 || heapPressure || this.cooldownActive;
44
+ }
45
+ static getLag() {
46
+ return this.lag;
47
+ }
48
+ static getMetrics() {
49
+ const mem = process.memoryUsage();
50
+ return {
51
+ lagMs: this.lag,
52
+ heapUsedMb: Math.round(mem.heapUsed / 1024 / 1024),
53
+ heapTotalMb: Math.round(mem.heapTotal / 1024 / 1024),
54
+ cooldown: this.cooldownActive,
55
+ };
56
+ }
57
+ }
58
+ //# sourceMappingURL=MarieStabilityMonitor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarieStabilityMonitor.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/MarieStabilityMonitor.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IACxB,MAAM,CAAC,GAAG,GAAW,CAAC,CAAC;IACvB,MAAM,CAAC,QAAQ,GAA0B,IAAI,CAAC;IAC9C,MAAM,CAAC,QAAQ,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;IACrC,MAAM,CAAC,cAAc,GAAY,KAAK,CAAC;IAExC,MA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,GAAG,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;QACzD,OAAO,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,YAAY,IAAI,IAAI,CAAC,cAAc,CAAC;IAC/D,CAAC;IAEM,MAAM,CAAC,MAAM;QAClB,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAEM,MAAM,CAAC,UAAU;QACtB,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QAClC,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,GAAG;YACf,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;YAClD,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;YACpD,QAAQ,EAAE,IAAI,CAAC,cAAc;SAC9B,CAAC;IACJ,CAAC"}
@@ -0,0 +1,127 @@
1
+ import { StringUtils } from "../../../plumbing/utils/StringUtils.js";
2
+ import { JsonUtils } from "../../../plumbing/utils/JsonUtils.js";
3
+ const PROACTIVE_REPAIRS = {
4
+ write_file: "write_to_file",
5
+ edit_file: "replace_file_content",
6
+ replace_in_file: "replace_file_content",
7
+ read_files: "read_file",
8
+ list_files: "list_dir",
9
+ search_files: "grep_search",
10
+ execute_command: "run_command",
11
+ get_folder_tree: "get_folder_structure",
12
+ multi_replace: "multi_replace_file_content",
13
+ multi_edit_file: "multi_replace_file_content",
14
+ delete_file: "discard_file", // Maps CLI to VS Code name
15
+ discard_file: "delete_file", // Maps VS Code to CLI name
16
+ };
17
+ /**
18
+ * ATMOSPHERIC SEPARATION: MarieToolMender
19
+ * Handles fuzzy hallucination repair for tool names and file paths.
20
+ */
21
+ export class MarieToolMender {
22
+ toolRegistry;
23
+ constructor(toolRegistry) {
24
+ this.toolRegistry = toolRegistry;
25
+ }
26
+ /**
27
+ * Attempts to automatically correct minor typos in tool calls using Levenshtein similarity.
28
+ */
29
+ async performFuzzyRepair(toolCall, error, tracker, processor, state, signal) {
30
+ // 0. Proactive Mapping (Quick lookups for common hallucinations)
31
+ if (PROACTIVE_REPAIRS[toolCall.name]) {
32
+ const mappedName = PROACTIVE_REPAIRS[toolCall.name];
33
+ // Only map if the target exists in the registry
34
+ if (this.toolRegistry.getTools().some((t) => t.name === mappedName)) {
35
+ tracker.emitEvent({
36
+ type: "reasoning",
37
+ runId: tracker.getRun().runId,
38
+ text: `🩹 PROACTIVE REPAIR: Mapping hallucinated tool: ${toolCall.name} -> ${mappedName}`,
39
+ elapsedMs: tracker.elapsedMs(),
40
+ });
41
+ toolCall.name = mappedName;
42
+ toolCall.repaired = true;
43
+ return await processor.process(toolCall, signal);
44
+ }
45
+ }
46
+ // 1. Tool Name Repair
47
+ const registeredTools = this.toolRegistry.getTools();
48
+ let bestToolName = "";
49
+ let bestToolSim = 0;
50
+ for (const t of registeredTools) {
51
+ const sim = StringUtils.similarity(toolCall.name, t.name);
52
+ if (sim > bestToolSim) {
53
+ bestToolSim = sim;
54
+ bestToolName = t.name;
55
+ }
56
+ }
57
+ const bestToolMatch = bestToolName
58
+ ? { name: bestToolName, similarity: bestToolSim }
59
+ : null;
60
+ if (bestToolMatch &&
61
+ bestToolMatch.similarity > 0.8 &&
62
+ bestToolMatch.name !== toolCall.name) {
63
+ tracker.emitEvent({
64
+ type: "reasoning",
65
+ runId: tracker.getRun().runId,
66
+ text: `🩹 FUZZY REPAIR: Fixing tool name hallucination: ${toolCall.name} -> ${bestToolMatch.name}`,
67
+ elapsedMs: tracker.elapsedMs(),
68
+ });
69
+ toolCall.name = bestToolMatch.name;
70
+ return await processor.process(toolCall, signal);
71
+ }
72
+ // 2. Path Repair (if "File not found")
73
+ if (error.includes("ENOENT") || error.includes("not found")) {
74
+ const problematicPath = toolCall.input?.path ||
75
+ toolCall.input?.targetFile ||
76
+ toolCall.input?.file;
77
+ if (problematicPath && typeof problematicPath === "string") {
78
+ const recentFiles = state.recentFiles || [];
79
+ let bestPathName = "";
80
+ let bestPathSim = 0;
81
+ for (const f of recentFiles) {
82
+ const sim = StringUtils.similarity(problematicPath, f);
83
+ if (sim > bestPathSim) {
84
+ bestPathSim = sim;
85
+ bestPathName = f;
86
+ }
87
+ }
88
+ const bestPathMatch = bestPathName
89
+ ? { path: bestPathName, similarity: bestPathSim }
90
+ : null;
91
+ if (bestPathMatch &&
92
+ bestPathMatch.similarity > 0.85 &&
93
+ bestPathMatch.path !== problematicPath) {
94
+ tracker.emitEvent({
95
+ type: "reasoning",
96
+ runId: tracker.getRun().runId,
97
+ text: `🩹 FUZZY REPAIR: Fixing path hallucination: ${problematicPath} -> ${bestPathMatch.path}`,
98
+ elapsedMs: tracker.elapsedMs(),
99
+ });
100
+ if (toolCall.input.path)
101
+ toolCall.input.path = bestPathMatch.path;
102
+ if (toolCall.input.targetFile)
103
+ toolCall.input.targetFile = bestPathMatch.path;
104
+ if (toolCall.input.file)
105
+ toolCall.input.file = bestPathMatch.path;
106
+ return await processor.process(toolCall, signal);
107
+ }
108
+ }
109
+ }
110
+ return null;
111
+ }
112
+ /**
113
+ * ATMOSPHERIC REPAIR: Fixes malformed JSON strings from the model (e.g. missing commas, unquoted keys).
114
+ */
115
+ repairJsonString(json) {
116
+ const { repaired } = JsonUtils.repairJsonDetailed(json);
117
+ try {
118
+ JSON.parse(repaired);
119
+ return repaired;
120
+ }
121
+ catch {
122
+ // Failed to repair, return original so caller can handle error paths explicitly.
123
+ return json;
124
+ }
125
+ }
126
+ }
127
+ //# sourceMappingURL=MarieToolMender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarieToolMender.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/MarieToolMender.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAEjE,MAAM,iBAAiB,GAA2B;IAChD,UAAU,EAA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