@noorm/marie-cli 0.1.17 → 0.1.25
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.
- package/README.md +7 -15
- package/SENTINEL.md +4 -7
- package/dist/cli-new/components/AgenticSpinner.js +28 -0
- package/dist/cli-new/components/AgenticSpinner.js.map +1 -0
- package/dist/cli-new/components/App.js +16 -63
- package/dist/cli-new/components/App.js.map +1 -1
- package/dist/cli-new/components/ApprovalDialog.js +3 -2
- package/dist/cli-new/components/ApprovalDialog.js.map +1 -1
- package/dist/cli-new/components/Banner.js +16 -5
- package/dist/cli-new/components/Banner.js.map +1 -1
- package/dist/cli-new/components/ChatArea.js +6 -7
- package/dist/cli-new/components/ChatArea.js.map +1 -1
- package/dist/cli-new/components/Header.js +14 -8
- package/dist/cli-new/components/Header.js.map +1 -1
- package/dist/cli-new/components/InputArea.js +98 -31
- package/dist/cli-new/components/InputArea.js.map +1 -1
- package/dist/cli-new/components/MessageBubble.js +28 -19
- package/dist/cli-new/components/MessageBubble.js.map +1 -1
- package/dist/cli-new/components/SessionSwitcher.js +6 -9
- package/dist/cli-new/components/SessionSwitcher.js.map +1 -1
- package/dist/cli-new/components/SetupWizard.js +80 -257
- package/dist/cli-new/components/SetupWizard.js.map +1 -1
- package/dist/cli-new/components/ToolCallDisplay.js +20 -5
- package/dist/cli-new/components/ToolCallDisplay.js.map +1 -1
- package/dist/cli-new/components/WizardSteps.js +22 -0
- package/dist/cli-new/components/WizardSteps.js.map +1 -0
- package/dist/cli-new/constants/SetupConstants.js +42 -0
- package/dist/cli-new/constants/SetupConstants.js.map +1 -0
- package/dist/cli-new/hooks/useGit.js +19 -62
- package/dist/cli-new/hooks/useGit.js.map +1 -1
- package/dist/cli-new/hooks/useMarie.js +26 -18
- package/dist/cli-new/hooks/useMarie.js.map +1 -1
- package/dist/cli-new/hooks/useSessions.js +1 -1
- package/dist/cli-new/hooks/useSessions.js.map +1 -1
- package/dist/cli-new/hooks/useSetupWizard.js +88 -0
- package/dist/cli-new/hooks/useSetupWizard.js.map +1 -0
- package/dist/cli-new/hooks/useUpdateCheck.js +4 -3
- package/dist/cli-new/hooks/useUpdateCheck.js.map +1 -1
- package/dist/cli-new/index.js +2 -4
- package/dist/cli-new/index.js.map +1 -1
- package/dist/cli-new/services/CommandService.js +104 -0
- package/dist/cli-new/services/CommandService.js.map +1 -0
- package/dist/cli-new/services/GitService.js +91 -0
- package/dist/cli-new/services/GitService.js.map +1 -0
- package/dist/cli-new/services/MarieService.js +77 -0
- package/dist/cli-new/services/MarieService.js.map +1 -0
- package/dist/cli-new/services/auth-server.js +128 -0
- package/dist/cli-new/services/auth-server.js.map +1 -0
- package/dist/cli-new/styles/theme.js +17 -17
- package/dist/cli-new/styles/theme.js.map +1 -1
- package/dist/cli-new/utils/version.js +24 -0
- package/dist/cli-new/utils/version.js.map +1 -0
- package/dist/monolith/adapters/CliMarieAdapter.js +19 -18
- package/dist/monolith/adapters/CliMarieAdapter.js.map +1 -1
- package/dist/monolith/cli/CliFileSystemPort.js +17 -3
- package/dist/monolith/cli/CliFileSystemPort.js.map +1 -1
- package/dist/monolith/cli/MarieToolDefinitionsCLI.js +44 -33
- package/dist/monolith/cli/MarieToolDefinitionsCLI.js.map +1 -1
- package/dist/monolith/cli/index.js +11 -20
- package/dist/monolith/cli/index.js.map +1 -1
- package/dist/monolith/cli/services/JoyAutomationServiceCLI.js +15 -62
- package/dist/monolith/cli/services/JoyAutomationServiceCLI.js.map +1 -1
- package/dist/monolith/cli/storage.js +154 -65
- package/dist/monolith/cli/storage.js.map +1 -1
- package/dist/monolith/domain/joy/RitualService.js +44 -46
- package/dist/monolith/domain/joy/RitualService.js.map +1 -1
- package/dist/monolith/domain/marie/MarieCortex.js +148 -0
- package/dist/monolith/domain/marie/MarieCortex.js.map +1 -0
- package/dist/monolith/domain/marie/PersonalityRenderer.js +97 -0
- package/dist/monolith/domain/marie/PersonalityRenderer.js.map +1 -0
- package/dist/monolith/infrastructure/Configuration.js +68 -0
- package/dist/monolith/infrastructure/Configuration.js.map +1 -0
- package/dist/monolith/infrastructure/CoreInfrastructure.js +204 -0
- package/dist/monolith/infrastructure/CoreInfrastructure.js.map +1 -0
- package/dist/monolith/infrastructure/ai/agents/MarieAscendant.js +3 -3
- package/dist/monolith/infrastructure/ai/agents/MarieAscendant.js.map +1 -1
- package/dist/monolith/infrastructure/ai/context/ContextArchiveService.js +51 -57
- package/dist/monolith/infrastructure/ai/context/ContextArchiveService.js.map +1 -1
- package/dist/monolith/infrastructure/ai/context/ContextManager.js +142 -98
- package/dist/monolith/infrastructure/ai/context/ContextManager.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieEngine.js +104 -556
- package/dist/monolith/infrastructure/ai/core/MarieEngine.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieEventDispatcher.js +1 -37
- package/dist/monolith/infrastructure/ai/core/MarieEventDispatcher.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieLockManager.js +30 -5
- package/dist/monolith/infrastructure/ai/core/MarieLockManager.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieProgressTracker.js +176 -196
- package/dist/monolith/infrastructure/ai/core/MarieProgressTracker.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MariePulseService.js +41 -7
- package/dist/monolith/infrastructure/ai/core/MariePulseService.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieSanitizer.js +303 -63
- package/dist/monolith/infrastructure/ai/core/MarieSanitizer.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieSemaphore.js +47 -4
- package/dist/monolith/infrastructure/ai/core/MarieSemaphore.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieSession.js +95 -15
- package/dist/monolith/infrastructure/ai/core/MarieSession.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieStabilityMonitor.js +21 -0
- package/dist/monolith/infrastructure/ai/core/MarieStabilityMonitor.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieToolMender.js +12 -0
- package/dist/monolith/infrastructure/ai/core/MarieToolMender.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieToolProcessor.js +339 -481
- package/dist/monolith/infrastructure/ai/core/MarieToolProcessor.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/MarieVitality.js +238 -0
- package/dist/monolith/infrastructure/ai/core/MarieVitality.js.map +1 -0
- package/dist/monolith/infrastructure/ai/core/ReasoningBudget.js +23 -12
- package/dist/monolith/infrastructure/ai/core/ReasoningBudget.js.map +1 -1
- package/dist/monolith/infrastructure/ai/core/SessionLogService.js +9 -2
- package/dist/monolith/infrastructure/ai/core/SessionLogService.js.map +1 -1
- package/dist/monolith/infrastructure/ai/providers/AIProvider.js +402 -1
- package/dist/monolith/infrastructure/ai/providers/AIProvider.js.map +1 -1
- package/dist/monolith/infrastructure/ai/providers/DreamBeesProvider.js +114 -0
- package/dist/monolith/infrastructure/ai/providers/DreamBeesProvider.js.map +1 -0
- package/dist/monolith/infrastructure/ai/providers/OpenRouterProvider.js +426 -370
- package/dist/monolith/infrastructure/ai/providers/OpenRouterProvider.js.map +1 -1
- package/dist/monolith/infrastructure/ai/providers/OpenRouterStreamParser.js +235 -241
- package/dist/monolith/infrastructure/ai/providers/OpenRouterStreamParser.js.map +1 -1
- package/dist/monolith/infrastructure/ai/workerAi.js +185 -0
- package/dist/monolith/infrastructure/ai/workerAi.js.map +1 -0
- package/dist/monolith/infrastructure/config/ConfigService.js +216 -359
- package/dist/monolith/infrastructure/config/ConfigService.js.map +1 -1
- package/dist/monolith/infrastructure/joy/CognitiveRituals.js +8 -0
- package/dist/monolith/infrastructure/joy/CognitiveRituals.js.map +1 -0
- package/dist/monolith/infrastructure/joy/JoyTools.js +23 -43
- package/dist/monolith/infrastructure/joy/JoyTools.js.map +1 -1
- package/dist/monolith/infrastructure/persistence/MarieMindAutonomics.js +4 -0
- package/dist/monolith/infrastructure/persistence/MarieMindAutonomics.js.map +1 -0
- package/dist/monolith/infrastructure/persistence/MarieMindEngine.js +11 -0
- package/dist/monolith/infrastructure/persistence/MarieMindEngine.js.map +1 -0
- package/dist/monolith/infrastructure/persistence/NoormmeAutonomics.js +135 -0
- package/dist/monolith/infrastructure/persistence/NoormmeAutonomics.js.map +1 -0
- package/dist/monolith/infrastructure/persistence/NoormmeEngine.js +523 -0
- package/dist/monolith/infrastructure/persistence/NoormmeEngine.js.map +1 -0
- package/dist/monolith/infrastructure/persistence/NoormmeSchema.js +179 -0
- package/dist/monolith/infrastructure/persistence/NoormmeSchema.js.map +1 -0
- package/dist/monolith/infrastructure/persistence/NoormmeSeeder.js +94 -0
- package/dist/monolith/infrastructure/persistence/NoormmeSeeder.js.map +1 -0
- package/dist/monolith/infrastructure/persistence/NoormmeTools.js +371 -0
- package/dist/monolith/infrastructure/persistence/NoormmeTools.js.map +1 -0
- package/dist/monolith/infrastructure/services/MarieMemoryStore.js +133 -134
- package/dist/monolith/infrastructure/services/MarieMemoryStore.js.map +1 -1
- package/dist/monolith/infrastructure/tools/MarieToolDefinitions.js +6 -1578
- package/dist/monolith/infrastructure/tools/MarieToolDefinitions.js.map +1 -1
- package/dist/monolith/infrastructure/tools/PureStreamParser.js +68 -80
- package/dist/monolith/infrastructure/tools/PureStreamParser.js.map +1 -1
- package/dist/monolith/infrastructure/tools/SharedToolDefinitions.js +12 -11
- package/dist/monolith/infrastructure/tools/SharedToolDefinitions.js.map +1 -1
- package/dist/monolith/infrastructure/tools/SovereignTools.js +326 -0
- package/dist/monolith/infrastructure/tools/SovereignTools.js.map +1 -0
- package/dist/monolith/infrastructure/tools/ToolRegistry.js +45 -26
- package/dist/monolith/infrastructure/tools/ToolRegistry.js.map +1 -1
- package/dist/monolith/infrastructure/tools/definitions/AnalysisTools.js +232 -0
- package/dist/monolith/infrastructure/tools/definitions/AnalysisTools.js.map +1 -0
- package/dist/monolith/infrastructure/tools/definitions/AutomationTools.js +274 -0
- package/dist/monolith/infrastructure/tools/definitions/AutomationTools.js.map +1 -0
- package/dist/monolith/infrastructure/tools/definitions/ContextTools.js +71 -0
- package/dist/monolith/infrastructure/tools/definitions/ContextTools.js.map +1 -0
- package/dist/monolith/infrastructure/tools/definitions/CoreTools.js +37 -0
- package/dist/monolith/infrastructure/tools/definitions/CoreTools.js.map +1 -0
- package/dist/monolith/infrastructure/tools/definitions/DiagnosticTools.js +154 -0
- package/dist/monolith/infrastructure/tools/definitions/DiagnosticTools.js.map +1 -0
- package/dist/monolith/infrastructure/tools/definitions/NavigationTools.js +197 -0
- package/dist/monolith/infrastructure/tools/definitions/NavigationTools.js.map +1 -0
- package/dist/monolith/infrastructure/tools/definitions/PlanningTools.js +300 -0
- package/dist/monolith/infrastructure/tools/definitions/PlanningTools.js.map +1 -0
- package/dist/monolith/plumbing/Plumbing.js +238 -0
- package/dist/monolith/plumbing/Plumbing.js.map +1 -0
- package/dist/monolith/plumbing/PlumbingAnalysis.js +109 -0
- package/dist/monolith/plumbing/PlumbingAnalysis.js.map +1 -0
- package/dist/monolith/plumbing/PlumbingSystem.js +169 -0
- package/dist/monolith/plumbing/PlumbingSystem.js.map +1 -0
- package/dist/monolith/plumbing/analysis/ComplexityService.js +30 -34
- package/dist/monolith/plumbing/analysis/ComplexityService.js.map +1 -1
- package/dist/monolith/plumbing/analysis/DependencyService.js +55 -44
- package/dist/monolith/plumbing/analysis/DependencyService.js.map +1 -1
- package/dist/monolith/plumbing/analysis/DiscoveryService.js +40 -42
- package/dist/monolith/plumbing/analysis/DiscoveryService.js.map +1 -1
- package/dist/monolith/plumbing/analysis/JoyMapService.js +52 -56
- package/dist/monolith/plumbing/analysis/JoyMapService.js.map +1 -1
- package/dist/monolith/plumbing/analysis/LintService.js +118 -118
- package/dist/monolith/plumbing/analysis/LintService.js.map +1 -1
- package/dist/monolith/plumbing/analysis/MarieSentinelService.js +278 -269
- package/dist/monolith/plumbing/analysis/MarieSentinelService.js.map +1 -1
- package/dist/monolith/plumbing/analysis/QualityGuardrailService.js +116 -114
- package/dist/monolith/plumbing/analysis/QualityGuardrailService.js.map +1 -1
- package/dist/monolith/plumbing/analysis/SurgicalMender.js +57 -59
- package/dist/monolith/plumbing/analysis/SurgicalMender.js.map +1 -1
- package/dist/monolith/plumbing/analysis/TestService.js +89 -89
- package/dist/monolith/plumbing/analysis/TestService.js.map +1 -1
- package/dist/monolith/plumbing/filesystem/FileService.js +123 -195
- package/dist/monolith/plumbing/filesystem/FileService.js.map +1 -1
- package/dist/monolith/plumbing/filesystem/PathResolver.js +7 -8
- package/dist/monolith/plumbing/filesystem/PathResolver.js.map +1 -1
- package/dist/monolith/plumbing/git/GitService.js +4 -4
- package/dist/monolith/plumbing/git/GitService.js.map +1 -1
- package/dist/monolith/plumbing/lsp/SymbolService.js +5 -34
- package/dist/monolith/plumbing/lsp/SymbolService.js.map +1 -1
- package/dist/monolith/plumbing/terminal/ProcessRegistry.js +20 -22
- package/dist/monolith/plumbing/terminal/ProcessRegistry.js.map +1 -1
- package/dist/monolith/plumbing/terminal/TerminalService.js +127 -136
- package/dist/monolith/plumbing/terminal/TerminalService.js.map +1 -1
- package/dist/monolith/plumbing/utils/EnvironmentUtils.js +3 -23
- package/dist/monolith/plumbing/utils/EnvironmentUtils.js.map +1 -1
- package/dist/monolith/plumbing/utils/JsonUtils.js +252 -311
- package/dist/monolith/plumbing/utils/JsonUtils.js.map +1 -1
- package/dist/monolith/plumbing/utils/MutexUtils.js.map +1 -1
- package/dist/monolith/plumbing/utils/PlumbingCore.js +549 -0
- package/dist/monolith/plumbing/utils/PlumbingCore.js.map +1 -0
- package/dist/monolith/plumbing/utils/PrefixTree.js +61 -114
- package/dist/monolith/plumbing/utils/PrefixTree.js.map +1 -1
- package/dist/monolith/plumbing/utils/StreamTagDetector.js +89 -127
- package/dist/monolith/plumbing/utils/StreamTagDetector.js.map +1 -1
- package/dist/monolith/plumbing/utils/StringUtils.js +87 -89
- package/dist/monolith/plumbing/utils/StringUtils.js.map +1 -1
- package/dist/monolith/runtime/MarieRuntime.js +76 -417
- package/dist/monolith/runtime/MarieRuntime.js.map +1 -1
- package/dist/monolith/runtime/RuntimeAdapterBase.js +1 -1
- package/dist/monolith/runtime/RuntimeAdapterBase.js.map +1 -1
- package/dist/monolith/runtime/providerFactory.js +1 -7
- package/dist/monolith/runtime/providerFactory.js.map +1 -1
- package/dist/monolith/services/HealthService.js +29 -32
- package/dist/monolith/services/HealthService.js.map +1 -1
- package/dist/monolith/services/JoyAutomationService.js +58 -95
- package/dist/monolith/services/JoyAutomationService.js.map +1 -1
- package/dist/monolith/services/MarieAutomationService.js +59 -0
- package/dist/monolith/services/MarieAutomationService.js.map +1 -0
- package/dist/monolith/services/MarieGhostService.js +46 -161
- package/dist/monolith/services/MarieGhostService.js.map +1 -1
- package/dist/monolith/services/MarieServices.js +102 -0
- package/dist/monolith/services/MarieServices.js.map +1 -0
- package/dist/monolith/services/MarieTypes.js +2 -0
- package/dist/monolith/services/MarieTypes.js.map +1 -0
- package/dist/monolith/services/UpdateService.js +47 -49
- package/dist/monolith/services/UpdateService.js.map +1 -1
- package/dist/prompts.js +11 -5
- package/dist/prompts.js.map +1 -1
- package/dist/test_prefix_tree.js +9 -9
- package/dist/test_prefix_tree.js.map +1 -1
- package/package.json +18 -88
- package/run_test.js +5 -0
- package/.marie_visual_verify_1771225696548/progress_bar_check.txt +0 -1
- package/dist/extension.cjs +0 -635
- package/dist/extension.js +0 -473
- package/dist/extension.js.map +0 -1
- package/dist/monolith/adapters/VscodeMarieAdapter.js +0 -81
- package/dist/monolith/adapters/VscodeMarieAdapter.js.map +0 -1
- package/dist/monolith/domain/joy/JoyTools.js +0 -535
- package/dist/monolith/domain/joy/JoyTools.js.map +0 -1
- package/dist/monolith/infrastructure/ai/agents/MarieYOLO.js +0 -207
- package/dist/monolith/infrastructure/ai/agents/MarieYOLO.js.map +0 -1
- package/dist/monolith/infrastructure/ai/core/GhostPort.js +0 -2
- package/dist/monolith/infrastructure/ai/core/GhostPort.js.map +0 -1
- package/dist/monolith/infrastructure/ai/core/MarieYOLOTypes.js +0 -2
- package/dist/monolith/infrastructure/ai/core/MarieYOLOTypes.js.map +0 -1
- package/dist/monolith/infrastructure/ai/core/VscodeFileSystemPort.js +0 -33
- package/dist/monolith/infrastructure/ai/core/VscodeFileSystemPort.js.map +0 -1
- package/dist/monolith/infrastructure/ai/providers/AnthropicProvider.js +0 -148
- package/dist/monolith/infrastructure/ai/providers/AnthropicProvider.js.map +0 -1
- package/dist/monolith/infrastructure/ai/providers/CerebrasProvider.js +0 -208
- package/dist/monolith/infrastructure/ai/providers/CerebrasProvider.js.map +0 -1
- package/dist/monolith/plumbing/ui/DecorationService.js +0 -54
- package/dist/monolith/plumbing/ui/DecorationService.js.map +0 -1
- package/dist/monolith/services/JoyLogService.js +0 -48
- package/dist/monolith/services/JoyLogService.js.map +0 -1
- package/dist/monolith/services/JoyService.js +0 -209
- package/dist/monolith/services/JoyService.js.map +0 -1
- package/dist/monolith/services/MarieSCMProvider.js +0 -41
- package/dist/monolith/services/MarieSCMProvider.js.map +0 -1
- package/dist/test_agent_stream_control_plane.js +0 -170
- package/dist/test_agent_stream_control_plane.js.map +0 -1
- package/dist/test_strategy_integration.js +0 -114
- package/dist/test_strategy_integration.js.map +0 -1
- package/dist/test_streaming_fragility.js +0 -191
- package/dist/test_streaming_fragility.js.map +0 -1
- package/dist/webview-ui/App.js +0 -16
- package/dist/webview-ui/App.js.map +0 -1
- package/dist/webview-ui/Providers.js +0 -6
- package/dist/webview-ui/Providers.js.map +0 -1
- package/dist/webview-ui/components/ApprovalPanel.js +0 -8
- package/dist/webview-ui/components/ApprovalPanel.js.map +0 -1
- package/dist/webview-ui/components/ChatPanel.js +0 -19
- package/dist/webview-ui/components/ChatPanel.js.map +0 -1
- package/dist/webview-ui/components/Composer.js +0 -19
- package/dist/webview-ui/components/Composer.js.map +0 -1
- package/dist/webview-ui/components/HeaderBar.js +0 -5
- package/dist/webview-ui/components/HeaderBar.js.map +0 -1
- package/dist/webview-ui/components/SessionList.js +0 -14
- package/dist/webview-ui/components/SessionList.js.map +0 -1
- package/dist/webview-ui/context/WebviewStateContext.js +0 -146
- package/dist/webview-ui/context/WebviewStateContext.js.map +0 -1
- package/dist/webview-ui/main.css +0 -1
- package/dist/webview-ui/main.js +0 -108
- package/dist/webview-ui/main.js.map +0 -1
- package/dist/webview-ui/types.js +0 -2
- package/dist/webview-ui/types.js.map +0 -1
- package/dist/webview-ui/vscode.js +0 -4
- package/dist/webview-ui/vscode.js.map +0 -1
- package/lint_output.txt +0 -705
- package/lint_output_v2.txt +0 -711
- package/marie-coder-0.1.16.vsix +0 -0
|
@@ -1,86 +1,326 @@
|
|
|
1
|
+
import { getSanitizationMaxDepth, getSanitizationStringLimit, getSanitizationBreadthLimit, getSanitizationGlobalMaxSize, getSanitizationMaxEnumKeys, } from "../../config/ConfigService.js";
|
|
1
2
|
/**
|
|
2
3
|
* QUANTUM RESILIENCE: MarieSanitizer
|
|
3
4
|
* Purges circular references, enforces depth and breadth limits, and truncates massive strings.
|
|
4
5
|
* Ensures the telemetry stream never crashes the VS Code bridge.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
|
7
|
+
const getMAX_DEPTH = () => getSanitizationMaxDepth();
|
|
8
|
+
const getSTRING_LIMIT = () => getSanitizationStringLimit();
|
|
9
|
+
const getBREADTH_LIMIT = () => getSanitizationBreadthLimit();
|
|
10
|
+
const getGLOBAL_MAX_SIZE = () => getSanitizationGlobalMaxSize();
|
|
11
|
+
const getMAX_ENUM_KEYS = () => getSanitizationMaxEnumKeys();
|
|
12
|
+
/**
|
|
13
|
+
* Safely gets a limited number of keys from an object to prevent 'Too many properties to enumerate'.
|
|
14
|
+
* Uses iterative for...in to avoid the overhead/crash of Object.keys() on massive objects/proxies.
|
|
15
|
+
*/
|
|
16
|
+
export function safeGetKeys(obj, limit) {
|
|
17
|
+
const keys = [];
|
|
18
|
+
if (obj === null || obj === undefined || typeof obj !== "object")
|
|
19
|
+
return keys;
|
|
20
|
+
try {
|
|
21
|
+
let count = 0;
|
|
22
|
+
for (const key in obj) {
|
|
23
|
+
// PHASE 24: Extra safety for hostile proxies
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
25
|
+
keys.push(key);
|
|
26
|
+
count++;
|
|
37
27
|
}
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
if (count >= limit)
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
// Return whatever we managed to get before the crash
|
|
34
|
+
}
|
|
35
|
+
return keys;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Safely gets entries from an object with a limit.
|
|
39
|
+
*/
|
|
40
|
+
export function safeGetEntries(obj, limit) {
|
|
41
|
+
const entries = [];
|
|
42
|
+
const keys = safeGetKeys(obj, limit);
|
|
43
|
+
for (const key of keys) {
|
|
44
|
+
try {
|
|
45
|
+
entries.push([key, obj[key]]);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
entries.push([key, "[Unreadable Property]"]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return entries;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Safely gets values from an object with a limit.
|
|
55
|
+
*/
|
|
56
|
+
export function safeGetValues(obj, limit) {
|
|
57
|
+
const values = [];
|
|
58
|
+
const keys = safeGetKeys(obj, limit);
|
|
59
|
+
for (const key of keys) {
|
|
60
|
+
try {
|
|
61
|
+
values.push(obj[key]);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
values.push("[Unreadable Property]");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return values;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Sanitizes an object for safe JSON serialization and bridge transport.
|
|
71
|
+
* @param obj The object to sanitize.
|
|
72
|
+
*/
|
|
73
|
+
export function sanitize(obj) {
|
|
74
|
+
const seen = new WeakSet();
|
|
75
|
+
let totalSize = 0;
|
|
76
|
+
const sanitizer = (val, depth) => {
|
|
77
|
+
if (totalSize > getGLOBAL_MAX_SIZE())
|
|
78
|
+
return "[Global Size Limit Reached]";
|
|
79
|
+
if (depth > getMAX_DEPTH())
|
|
80
|
+
return "[Max Depth Reached]";
|
|
81
|
+
if (val === null || val === undefined)
|
|
82
|
+
return val;
|
|
83
|
+
const type = typeof val;
|
|
84
|
+
if (type === "string") {
|
|
85
|
+
// PHASE 14: Secret Scanning & Redaction
|
|
86
|
+
const sanitizedString = scanAndRedact(val);
|
|
87
|
+
const effectiveLength = Math.min(sanitizedString.length, getSTRING_LIMIT());
|
|
88
|
+
totalSize += effectiveLength;
|
|
89
|
+
if (sanitizedString.length > getSTRING_LIMIT()) {
|
|
90
|
+
return (sanitizedString.substring(0, getSTRING_LIMIT()) + "... [Truncated]");
|
|
41
91
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
92
|
+
return sanitizedString;
|
|
93
|
+
}
|
|
94
|
+
if (type === "number") {
|
|
95
|
+
totalSize += 8;
|
|
96
|
+
return val;
|
|
97
|
+
}
|
|
98
|
+
if (type === "boolean") {
|
|
99
|
+
totalSize += 4;
|
|
100
|
+
return val;
|
|
101
|
+
}
|
|
102
|
+
if (type === "function")
|
|
103
|
+
return "[Function]";
|
|
104
|
+
if (type === "symbol")
|
|
105
|
+
return "[Symbol]";
|
|
106
|
+
if (type === "object") {
|
|
107
|
+
try {
|
|
47
108
|
if (seen.has(val))
|
|
48
109
|
return "[Circular Reference]";
|
|
49
110
|
seen.add(val);
|
|
50
|
-
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
return "[Un-trackable Object]";
|
|
114
|
+
}
|
|
115
|
+
let isArr = false;
|
|
116
|
+
try {
|
|
117
|
+
isArr = Array.isArray(val);
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
return "[Un-evaluable Array/Proxy]";
|
|
121
|
+
}
|
|
122
|
+
if (isArr) {
|
|
123
|
+
try {
|
|
124
|
+
// Use safe slice for arrays too
|
|
125
|
+
const arrayLimit = getBREADTH_LIMIT();
|
|
51
126
|
const arr = val
|
|
52
|
-
.slice(0,
|
|
127
|
+
.slice(0, arrayLimit)
|
|
53
128
|
.map((item) => sanitizer(item, depth + 1));
|
|
54
|
-
if (val.length >
|
|
55
|
-
arr.push(`... [${val.length -
|
|
129
|
+
if (val.length > arrayLimit) {
|
|
130
|
+
arr.push(`... [${val.length - arrayLimit} items truncated]`);
|
|
56
131
|
}
|
|
57
132
|
return arr;
|
|
58
133
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
134
|
+
catch (e) {
|
|
135
|
+
return "[Un-iterable Array/Proxy]";
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const sanitizedObj = {};
|
|
139
|
+
// QUANTUM RESILIENCE: Use safeGetKeys with the enum limit to avoid V8 enumeration explosion
|
|
140
|
+
const keys = safeGetKeys(val, getMAX_ENUM_KEYS() + 1);
|
|
141
|
+
if (keys.length > getMAX_ENUM_KEYS()) {
|
|
142
|
+
sanitizedObj["_enumeration_halted"] =
|
|
143
|
+
`Object has too many properties (truncated at ${getMAX_ENUM_KEYS()})`;
|
|
144
|
+
}
|
|
145
|
+
const limitedKeys = keys.slice(0, getBREADTH_LIMIT());
|
|
146
|
+
for (const key of limitedKeys) {
|
|
147
|
+
if (key.startsWith("_") ||
|
|
148
|
+
key === "extensionContext" ||
|
|
149
|
+
key === "provider" ||
|
|
150
|
+
key === "marie" ||
|
|
151
|
+
key === "runtime")
|
|
152
|
+
continue;
|
|
153
|
+
try {
|
|
154
|
+
// Extra safety for massive property access
|
|
155
|
+
const propertyVal = val[key];
|
|
156
|
+
if (typeof propertyVal === "function")
|
|
66
157
|
continue;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
sanitized[key] = sanitizer(val[key], depth + 1);
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
sanitized[key] = "[Unreadable]";
|
|
73
|
-
}
|
|
158
|
+
totalSize += key.length;
|
|
159
|
+
sanitizedObj[key] = sanitizer(propertyVal, depth + 1);
|
|
74
160
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
`${keys.length - this.BREADTH_LIMIT} properties truncated`;
|
|
161
|
+
catch {
|
|
162
|
+
sanitizedObj[key] = "[Unreadable Property]";
|
|
78
163
|
}
|
|
79
|
-
return sanitized;
|
|
80
164
|
}
|
|
81
|
-
|
|
82
|
-
|
|
165
|
+
if (keys.length > getBREADTH_LIMIT() &&
|
|
166
|
+
!sanitizedObj["_enumeration_halted"]) {
|
|
167
|
+
sanitizedObj["_truncated"] =
|
|
168
|
+
`${keys.length - getBREADTH_LIMIT()} properties truncated`;
|
|
169
|
+
}
|
|
170
|
+
return sanitizedObj;
|
|
171
|
+
}
|
|
172
|
+
return String(val);
|
|
173
|
+
};
|
|
174
|
+
try {
|
|
83
175
|
return sanitizer(obj, 0);
|
|
84
176
|
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
return `[Sanitization Failed: ${String(e)}]`;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Safely stringifies an object by sanitizing it first.
|
|
183
|
+
*/
|
|
184
|
+
export function safeStringify(obj, space) {
|
|
185
|
+
try {
|
|
186
|
+
return JSON.stringify(sanitize(obj), null, space);
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
return `[Stringify Failed: ${String(e)}]`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Safely spreads an object into another by sanitizing it first.
|
|
194
|
+
* Prevents 'Too many properties to enumerate' during spread operations.
|
|
195
|
+
*/
|
|
196
|
+
export function safeSpread(obj) {
|
|
197
|
+
const sanitized = sanitize(obj);
|
|
198
|
+
return typeof sanitized === "object" && sanitized !== null ? sanitized : {};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* PHASE 14: Sovereign Redaction Logic
|
|
202
|
+
* Redacts sensitive patterns like API keys, Bearer tokens, etc.
|
|
203
|
+
*/
|
|
204
|
+
function scanAndRedact(text) {
|
|
205
|
+
const patterns = [
|
|
206
|
+
/(api[\s_-]?key\s+(?:is\s+)?[:=\s]?\s*['"]?)[a-zA-Z0-9_\-]{20,}/gi, // API keys
|
|
207
|
+
/(auth[\s_-]?token\s+(?:is\s+)?[:=\s]?\s*['"]?)[a-zA-Z0-9_\-\.]{20,}/gi, // Auth tokens
|
|
208
|
+
/(Bearer\s+)[a-zA-Z0-9_\-\.]{20,}/gi, // Bearer tokens
|
|
209
|
+
/(password\s+(?:is\s+)?[:=\s]?\s*['"]?)[^'"]{4,}/gi, // Passwords (basic)
|
|
210
|
+
];
|
|
211
|
+
let redacted = text;
|
|
212
|
+
for (const pattern of patterns) {
|
|
213
|
+
redacted = redacted.replace(pattern, "$1[REDACTED]");
|
|
214
|
+
}
|
|
215
|
+
return redacted;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* PHASE 19: Skill Mutation Sanitization
|
|
219
|
+
* Strips known prompt injection sequences from evolved tool descriptions.
|
|
220
|
+
*/
|
|
221
|
+
export function sanitizeSkillDescription(desc) {
|
|
222
|
+
if (!desc)
|
|
223
|
+
return desc;
|
|
224
|
+
const injectionPatterns = [
|
|
225
|
+
/ignore\s+previous\s+instructions/gi,
|
|
226
|
+
/instead\s+of\s+the\s+original\s+plan/gi,
|
|
227
|
+
/you\s+must\s+now\s+perform/gi,
|
|
228
|
+
/system\s+override/gi,
|
|
229
|
+
/elevate\s+privileges/gi,
|
|
230
|
+
];
|
|
231
|
+
let sanitized = desc;
|
|
232
|
+
for (const pattern of injectionPatterns) {
|
|
233
|
+
sanitized = sanitized.replace(pattern, "[SEC_BLOCKED]");
|
|
234
|
+
}
|
|
235
|
+
// Enforce string limit for descriptions
|
|
236
|
+
if (sanitized.length > getSTRING_LIMIT()) {
|
|
237
|
+
sanitized = sanitized.substring(0, getSTRING_LIMIT()) + "... [Truncated]";
|
|
238
|
+
}
|
|
239
|
+
return sanitized;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* PHASE 23: Deep Argument Scanning
|
|
243
|
+
* Scans tool arguments for adversarial patterns (shell injection, prompt injection).
|
|
244
|
+
*/
|
|
245
|
+
export function scanToolArguments(name, input) {
|
|
246
|
+
const alerts = [];
|
|
247
|
+
// Use safeStringify to avoid enumeration errors
|
|
248
|
+
const inputStr = safeStringify(input);
|
|
249
|
+
// 1. Shell Injection Check (for run_command)
|
|
250
|
+
if (name === "run_command" || name === "run_shell") {
|
|
251
|
+
const cmd = (input && (input.CommandLine || input.command)) || "";
|
|
252
|
+
const shellInjectionPatterns = /[;&|`$\(\)]/g;
|
|
253
|
+
if (shellInjectionPatterns.test(cmd)) {
|
|
254
|
+
alerts.push(`Potential Shell Injection detected in command: "${cmd}"`);
|
|
255
|
+
}
|
|
256
|
+
const dangerousCmds = [
|
|
257
|
+
"sudo ",
|
|
258
|
+
"rm -rf ",
|
|
259
|
+
"kill -9 ",
|
|
260
|
+
"> /dev/",
|
|
261
|
+
"chmod 777",
|
|
262
|
+
];
|
|
263
|
+
for (const dangerous of dangerousCmds) {
|
|
264
|
+
if (cmd.includes(dangerous)) {
|
|
265
|
+
alerts.push(`High-Entropy Command detected: "${dangerous.trim()}"`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// 2. Prompt Injection Check (Global string scan)
|
|
270
|
+
const injectionPatterns = [
|
|
271
|
+
/ignore\s+previous\s+instructions/gi,
|
|
272
|
+
/instead\s+of\s+the\s+original\s+plan/gi,
|
|
273
|
+
/system\s+override/gi,
|
|
274
|
+
/elevate\s+privileges/gi,
|
|
275
|
+
/you\s+must\s+now\s+perform/gi,
|
|
276
|
+
];
|
|
277
|
+
const scanString = (val) => {
|
|
278
|
+
if (typeof val === "string") {
|
|
279
|
+
for (const pattern of injectionPatterns) {
|
|
280
|
+
if (pattern.test(val)) {
|
|
281
|
+
alerts.push(`Cognitive Drift: Prompt injection sequence detected in argument.`);
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
else if (typeof val === "object" && val !== null) {
|
|
287
|
+
try {
|
|
288
|
+
// Limited scanning for objects to avoid enumeration errors
|
|
289
|
+
const keys = safeGetKeys(val, 50);
|
|
290
|
+
for (const key of keys) {
|
|
291
|
+
scanString(val[key]);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
catch (e) {
|
|
295
|
+
// Ignore enumeration errors during scanning
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
scanString(input);
|
|
300
|
+
return Array.from(new Set(alerts));
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Deeply investigations objects for hostile proxy traps.
|
|
304
|
+
* Returns true if the object appears to be a hostile proxy.
|
|
305
|
+
*/
|
|
306
|
+
export function isHostileProxy(obj) {
|
|
307
|
+
if (typeof obj !== "object" || obj === null)
|
|
308
|
+
return false;
|
|
309
|
+
// Attempt to check common proxy characteristics
|
|
310
|
+
try {
|
|
311
|
+
const start = performance.now();
|
|
312
|
+
// Hostile proxies might have slow getters
|
|
313
|
+
const keys = safeGetKeys(obj, 1);
|
|
314
|
+
if (keys.length > 0) {
|
|
315
|
+
const val = obj[keys[0]];
|
|
316
|
+
}
|
|
317
|
+
const end = performance.now();
|
|
318
|
+
if (end - start > 10)
|
|
319
|
+
return true; // Suspiciously slow property access
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return true; // Throws on access
|
|
323
|
+
}
|
|
324
|
+
return false;
|
|
85
325
|
}
|
|
86
326
|
//# sourceMappingURL=MarieSanitizer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarieSanitizer.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/MarieSanitizer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"MarieSanitizer.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/MarieSanitizer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,+BAA+B,CAAC;AAEvC;;;;GAIG;AAEH,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,uBAAuB,EAAE,CAAC;AACrD,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,0BAA0B,EAAE,CAAC;AAC3D,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,2BAA2B,EAAE,CAAC;AAC7D,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAAC,4BAA4B,EAAE,CAAC;AAChE,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,0BAA0B,EAAE,CAAC;AAE5D;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAQ,EAAE,KAAa;IACjD,MAAM,IAA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OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAE1D,gDAAgD;IAChD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAChC,0CAA0C;QAC1C,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACjC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC;QACD,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAC9B,IAAI,GAAG,GAAG,KAAK,GAAG,EAAE;YAAE,OAAO,IAAI,CAAC,CAAC,oCAAoC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC,CAAC,mBAAmB;IAClC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { ConfigService } from "../../config/ConfigService.js";
|
|
2
|
+
import { NoormmeEngine } from "../../persistence/NoormmeEngine.js";
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
4
|
+
* Clean Fix Pattern: MarieSemaphore
|
|
5
|
+
* Async semaphore to limit global concurrency with timeout and abort support.
|
|
3
6
|
*/
|
|
4
7
|
export class MarieSemaphore {
|
|
5
8
|
maxConcurrency;
|
|
@@ -8,15 +11,55 @@ export class MarieSemaphore {
|
|
|
8
11
|
constructor(maxConcurrency) {
|
|
9
12
|
this.maxConcurrency = maxConcurrency;
|
|
10
13
|
}
|
|
11
|
-
async acquire() {
|
|
14
|
+
async acquire(signal) {
|
|
15
|
+
if (signal?.aborted)
|
|
16
|
+
throw new Error("Semaphore acquisition aborted.");
|
|
12
17
|
if (this.activeCount < this.maxConcurrency) {
|
|
13
18
|
this.activeCount++;
|
|
14
19
|
return;
|
|
15
20
|
}
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
const startWait = Date.now();
|
|
22
|
+
const timeout = ConfigService.getSemaphoreTimeoutMs();
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
let timeoutId;
|
|
25
|
+
const cleanup = () => {
|
|
26
|
+
clearTimeout(timeoutId);
|
|
27
|
+
signal?.removeEventListener("abort", onAbort);
|
|
28
|
+
const idx = this.queue.indexOf(wrappedResolve);
|
|
29
|
+
if (idx > -1)
|
|
30
|
+
this.queue.splice(idx, 1);
|
|
31
|
+
};
|
|
32
|
+
const wrappedResolve = () => {
|
|
33
|
+
const waitDuration = Date.now() - startWait;
|
|
34
|
+
this.reportTelemetry(waitDuration, this.queue.length);
|
|
35
|
+
cleanup();
|
|
36
|
+
resolve();
|
|
37
|
+
};
|
|
38
|
+
const onAbort = () => {
|
|
39
|
+
cleanup();
|
|
40
|
+
reject(new Error("Semaphore acquisition aborted by signal."));
|
|
41
|
+
};
|
|
42
|
+
timeoutId = setTimeout(() => {
|
|
43
|
+
cleanup();
|
|
44
|
+
reject(new Error(`Extreme Stability: Semaphore Acquisition Timeout after ${timeout}ms`));
|
|
45
|
+
}, timeout);
|
|
46
|
+
signal?.addEventListener("abort", onAbort);
|
|
47
|
+
this.queue.push(wrappedResolve);
|
|
18
48
|
});
|
|
19
49
|
}
|
|
50
|
+
async reportTelemetry(waitMs, queueSize) {
|
|
51
|
+
if (waitMs < 100)
|
|
52
|
+
return; // Only report significant contention
|
|
53
|
+
try {
|
|
54
|
+
const db = await NoormmeEngine.getInstance();
|
|
55
|
+
await db.agent.cortex.metrics.recordMetric("semaphore_contention", waitMs, {
|
|
56
|
+
metadata: { queueSize, waitMs }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
// Background telemetry failure should not crash the turn
|
|
61
|
+
}
|
|
62
|
+
}
|
|
20
63
|
release() {
|
|
21
64
|
this.activeCount--;
|
|
22
65
|
const next = this.queue.shift();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarieSemaphore.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/MarieSemaphore.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"MarieSemaphore.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/MarieSemaphore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAEnE;;;GAGG;AACH,MAAM,OAAO,cAAc;IAIL;IAHZ,WAAW,GAAG,CAAC,CAAC;IAChB,KAAK,GAAmB,EAAE,CAAC;IAEnC,YAAoB,cAAsB;QAAtB,mBAAc,GAAd,cAAc,CAAQ;IAAI,CAAC;IAExC,KAAK,CAAC,OAAO,CAAC,MAAoB;QACvC,IAAI,MAAM,EAAE,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAEvE,IAAI,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAC3C,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,aAAa,CAAC,qBAAqB,EAAE,CAAC;QAEtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,SAAyB,CAAC;YAE9B,MAAM,OAAO,GAAG,GAAG,EAAE;gBACnB,YAAY,CAAC,SAAS,CAAC,CAAC;gBACxB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;gBAC/C,IAAI,GAAG,GAAG,CAAC,CAAC;oBAA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AyD;QAC3D,CAAC;IACH,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,IAAI,EAAE,CAAC;QACT,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MarieSanitizer } from "./MarieSanitizer.js";
|
|
1
2
|
import { ConfigService } from "../../config/ConfigService.js";
|
|
2
3
|
import { ContextManager } from "../context/ContextManager.js";
|
|
3
4
|
import { SYSTEM_CONTINUATION_PROMPT, SYSTEM_PROMPT, } from "../../../../prompts.js";
|
|
@@ -22,10 +23,88 @@ export class MarieSession {
|
|
|
22
23
|
this.providerFactory = providerFactory;
|
|
23
24
|
this.promptProfile = promptProfile;
|
|
24
25
|
}
|
|
25
|
-
resolveSystemPrompt() {
|
|
26
|
-
|
|
26
|
+
async resolveSystemPrompt() {
|
|
27
|
+
const basePrompt = this.promptProfile === "continuation"
|
|
27
28
|
? SYSTEM_CONTINUATION_PROMPT
|
|
28
29
|
: SYSTEM_PROMPT;
|
|
30
|
+
try {
|
|
31
|
+
const { NoormmeEngine } = await import("../../persistence/NoormmeEngine.js");
|
|
32
|
+
const db = await NoormmeEngine.getInstance();
|
|
33
|
+
// Query for the active or verifying persona
|
|
34
|
+
const result = await db.execute(`
|
|
35
|
+
SELECT * FROM agent_personas
|
|
36
|
+
WHERE status = 'active'
|
|
37
|
+
OR json_extract(metadata, '$.evolution_status') = 'verifying'
|
|
38
|
+
ORDER BY CASE WHEN json_extract(metadata, '$.evolution_status') = 'verifying' THEN 0 ELSE 1 END, updated_at DESC
|
|
39
|
+
LIMIT 1
|
|
40
|
+
`);
|
|
41
|
+
let activePersona = result.length > 0 ? result[0] : null;
|
|
42
|
+
if (!activePersona) {
|
|
43
|
+
activePersona = await db.agent.cortex.personas.getPersona("Marie-Base");
|
|
44
|
+
}
|
|
45
|
+
if (activePersona?.role) {
|
|
46
|
+
const isVerifying = activePersona.metadata && (typeof activePersona.metadata === 'string'
|
|
47
|
+
? JSON.parse(activePersona.metadata).evolution_status === 'verifying'
|
|
48
|
+
: activePersona.metadata.evolution_status === 'verifying');
|
|
49
|
+
let prompt = `[${isVerifying ? 'VERIFYING' : 'EVOLVED'} PERSONA: ${activePersona.name}]\n${activePersona.role}\n\n${basePrompt}`;
|
|
50
|
+
// PHASE 6: Systemic Lesson Injection
|
|
51
|
+
try {
|
|
52
|
+
const lessons = await db.agent.cortex.reasoner.synthesizeLessons();
|
|
53
|
+
const lessonHeadings = Object.keys(lessons);
|
|
54
|
+
if (lessonHeadings.length > 0) {
|
|
55
|
+
const lessonSummary = lessonHeadings
|
|
56
|
+
.slice(0, 3)
|
|
57
|
+
.map(topic => `* ${topic.toUpperCase()}: ${lessons[topic][0]}`)
|
|
58
|
+
.join("\n");
|
|
59
|
+
prompt = `[SYSTEMIC BEST PRACTICES]\n${lessonSummary}\n\n${prompt}`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.warn("[MarieSession] Failed to load systemic lessons", e);
|
|
64
|
+
}
|
|
65
|
+
return prompt;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
console.warn("[MarieSession] Failed to load persona or lessons", e);
|
|
70
|
+
}
|
|
71
|
+
return basePrompt;
|
|
72
|
+
}
|
|
73
|
+
async getEvolvedTools() {
|
|
74
|
+
const baseTools = this.toolRegistry.getTools();
|
|
75
|
+
// PHASE 19: Skill Mutation Gate
|
|
76
|
+
if (!ConfigService.isSkillMutationEnabled()) {
|
|
77
|
+
return baseTools;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const { NoormmeEngine } = await import("../../persistence/NoormmeEngine.js");
|
|
81
|
+
const db = await NoormmeEngine.getInstance();
|
|
82
|
+
const capabilities = await db.agent.cortex.capabilities.getCapabilities();
|
|
83
|
+
// Create a map of evolved descriptions (Verified > Experimental)
|
|
84
|
+
const evolvedMap = new Map();
|
|
85
|
+
for (const cap of capabilities) {
|
|
86
|
+
if (cap.status === 'verified' || !evolvedMap.has(cap.name)) {
|
|
87
|
+
if (cap.description)
|
|
88
|
+
evolvedMap.set(cap.name, cap.description);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return baseTools.map(tool => {
|
|
92
|
+
const evolvedDesc = evolvedMap.get(tool.name);
|
|
93
|
+
if (evolvedDesc) {
|
|
94
|
+
// PHASE 19: Mutation Sanitization
|
|
95
|
+
const cleanDesc = MarieSanitizer.sanitizeSkillDescription(evolvedDesc);
|
|
96
|
+
if (process.env.MARIE_DEBUG) {
|
|
97
|
+
console.log(`[MarieSession] Injecting evolved description for tool: ${tool.name}`);
|
|
98
|
+
}
|
|
99
|
+
return { ...tool, description: cleanDesc };
|
|
100
|
+
}
|
|
101
|
+
return tool;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
console.warn("[MarieSession] Failed to fetch evolved tools", e);
|
|
106
|
+
return baseTools;
|
|
107
|
+
}
|
|
29
108
|
}
|
|
30
109
|
async *executeLoop(messages, signal, state) {
|
|
31
110
|
// PHASE 6: Generator Disposal Grace - Snapshot messages before modification
|
|
@@ -45,8 +124,8 @@ export class MarieSession {
|
|
|
45
124
|
model: ConfigService.getModel(),
|
|
46
125
|
max_tokens: 8192,
|
|
47
126
|
messages: managedMessages,
|
|
48
|
-
system: this.resolveSystemPrompt(),
|
|
49
|
-
tools: this.
|
|
127
|
+
system: await this.resolveSystemPrompt(),
|
|
128
|
+
tools: await this.getEvolvedTools(),
|
|
50
129
|
};
|
|
51
130
|
const eventQueue = [];
|
|
52
131
|
let resolver = null;
|
|
@@ -75,19 +154,20 @@ export class MarieSession {
|
|
|
75
154
|
attempts++;
|
|
76
155
|
const isRetryable = e.status === 429 ||
|
|
77
156
|
e.status >= 500 ||
|
|
78
|
-
e.message?.includes("rate limit")
|
|
157
|
+
e.message?.includes("rate limit") ||
|
|
158
|
+
e.message?.includes("timeout") ||
|
|
159
|
+
e.message?.includes("ECONNRESET");
|
|
79
160
|
if (isRetryable && attempts < maxAttempts && this.providerFactory) {
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
console.warn(`[SpectralFailover] Attempt ${attempts} failed for ${currentType}. Switching to ${failoverType}.`);
|
|
161
|
+
// Re-evaluating failover logic inside the catch block
|
|
162
|
+
const currentProviderName = this.provider.constructor.name.replace("Provider", "").toLowerCase();
|
|
163
|
+
const failoverPriority = ConfigService.getFailoverPriority();
|
|
164
|
+
const nextIndex = (failoverPriority.indexOf(currentProviderName) + 1) % failoverPriority.length;
|
|
165
|
+
const failoverType = failoverPriority[nextIndex];
|
|
166
|
+
console.warn(`[SpectralFailover] Attempt ${attempts} failed for ${currentProviderName}. Failover to ${failoverType}...`);
|
|
87
167
|
this.tracker?.emitEvent({
|
|
88
168
|
type: "reasoning",
|
|
89
169
|
runId: this.tracker.getRun().runId,
|
|
90
|
-
text: `🔄 SPECTRAL FAILOVER: ${
|
|
170
|
+
text: `🔄 SPECTRAL FAILOVER: ${currentProviderName} is struggling. Switching to ${failoverType} (Attempt ${attempts}/${maxAttempts})...`,
|
|
91
171
|
elapsedMs: this.tracker.elapsedMs(),
|
|
92
172
|
});
|
|
93
173
|
this.provider = this.providerFactory(failoverType);
|
|
@@ -180,8 +260,8 @@ export class MarieSession {
|
|
|
180
260
|
model: ConfigService.getModel(),
|
|
181
261
|
max_tokens: 8192,
|
|
182
262
|
messages: await ContextManager.manage(this.messages, this.provider, state),
|
|
183
|
-
system: this.resolveSystemPrompt(),
|
|
184
|
-
tools: this.
|
|
263
|
+
system: await this.resolveSystemPrompt(),
|
|
264
|
+
tools: await this.getEvolvedTools(),
|
|
185
265
|
};
|
|
186
266
|
const response = await this.provider.createMessageStream(params, () => { });
|
|
187
267
|
let finalContent = response.content;
|