@trenchwork/coder 1.3.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.
- package/LICENSE +16 -0
- package/README.md +173 -0
- package/agents/trenchwork-code.rules.json +199 -0
- package/dist/bin/deepseek.d.ts +3 -0
- package/dist/bin/deepseek.d.ts.map +1 -0
- package/dist/bin/deepseek.js +23 -0
- package/dist/bin/deepseek.js.map +1 -0
- package/dist/capabilities/baseCapability.d.ts +72 -0
- package/dist/capabilities/baseCapability.d.ts.map +1 -0
- package/dist/capabilities/baseCapability.js +183 -0
- package/dist/capabilities/baseCapability.js.map +1 -0
- package/dist/capabilities/bashCapability.d.ts +13 -0
- package/dist/capabilities/bashCapability.d.ts.map +1 -0
- package/dist/capabilities/bashCapability.js +24 -0
- package/dist/capabilities/bashCapability.js.map +1 -0
- package/dist/capabilities/editCapability.d.ts +17 -0
- package/dist/capabilities/editCapability.d.ts.map +1 -0
- package/dist/capabilities/editCapability.js +27 -0
- package/dist/capabilities/editCapability.js.map +1 -0
- package/dist/capabilities/enhancedGitCapability.d.ts +7 -0
- package/dist/capabilities/enhancedGitCapability.d.ts.map +1 -0
- package/dist/capabilities/enhancedGitCapability.js +220 -0
- package/dist/capabilities/enhancedGitCapability.js.map +1 -0
- package/dist/capabilities/filesystemCapability.d.ts +13 -0
- package/dist/capabilities/filesystemCapability.d.ts.map +1 -0
- package/dist/capabilities/filesystemCapability.js +24 -0
- package/dist/capabilities/filesystemCapability.js.map +1 -0
- package/dist/capabilities/gitHistoryCapability.d.ts +6 -0
- package/dist/capabilities/gitHistoryCapability.d.ts.map +1 -0
- package/dist/capabilities/gitHistoryCapability.js +184 -0
- package/dist/capabilities/gitHistoryCapability.js.map +1 -0
- package/dist/capabilities/hitlCapability.d.ts +18 -0
- package/dist/capabilities/hitlCapability.d.ts.map +1 -0
- package/dist/capabilities/hitlCapability.js +29 -0
- package/dist/capabilities/hitlCapability.js.map +1 -0
- package/dist/capabilities/index.d.ts +11 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +16 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/capabilities/memoryCapability.d.ts +10 -0
- package/dist/capabilities/memoryCapability.d.ts.map +1 -0
- package/dist/capabilities/memoryCapability.js +22 -0
- package/dist/capabilities/memoryCapability.js.map +1 -0
- package/dist/capabilities/notebookCapability.d.ts +6 -0
- package/dist/capabilities/notebookCapability.d.ts.map +1 -0
- package/dist/capabilities/notebookCapability.js +17 -0
- package/dist/capabilities/notebookCapability.js.map +1 -0
- package/dist/capabilities/searchCapability.d.ts +19 -0
- package/dist/capabilities/searchCapability.d.ts.map +1 -0
- package/dist/capabilities/searchCapability.js +29 -0
- package/dist/capabilities/searchCapability.js.map +1 -0
- package/dist/capabilities/skillCapability.d.ts +6 -0
- package/dist/capabilities/skillCapability.d.ts.map +1 -0
- package/dist/capabilities/skillCapability.js +17 -0
- package/dist/capabilities/skillCapability.js.map +1 -0
- package/dist/capabilities/todoCapability.d.ts +11 -0
- package/dist/capabilities/todoCapability.d.ts.map +1 -0
- package/dist/capabilities/todoCapability.js +22 -0
- package/dist/capabilities/todoCapability.js.map +1 -0
- package/dist/capabilities/toolManifest.d.ts +3 -0
- package/dist/capabilities/toolManifest.d.ts.map +1 -0
- package/dist/capabilities/toolManifest.js +163 -0
- package/dist/capabilities/toolManifest.js.map +1 -0
- package/dist/capabilities/toolRegistry.d.ts +25 -0
- package/dist/capabilities/toolRegistry.d.ts.map +1 -0
- package/dist/capabilities/toolRegistry.js +150 -0
- package/dist/capabilities/toolRegistry.js.map +1 -0
- package/dist/capabilities/unifiedCodingCapability.d.ts +62 -0
- package/dist/capabilities/unifiedCodingCapability.d.ts.map +1 -0
- package/dist/capabilities/unifiedCodingCapability.js +790 -0
- package/dist/capabilities/unifiedCodingCapability.js.map +1 -0
- package/dist/capabilities/webCapability.d.ts +23 -0
- package/dist/capabilities/webCapability.d.ts.map +1 -0
- package/dist/capabilities/webCapability.js +33 -0
- package/dist/capabilities/webCapability.js.map +1 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +181 -0
- package/dist/config.js.map +1 -0
- package/dist/contracts/agent-profiles.schema.json +25 -0
- package/dist/contracts/agent-schemas.json +158 -0
- package/dist/contracts/models.schema.json +9 -0
- package/dist/contracts/module-schema.json +367 -0
- package/dist/contracts/schemas/agent-profile.schema.json +157 -0
- package/dist/contracts/schemas/agent-rules.schema.json +238 -0
- package/dist/contracts/schemas/agent-schemas.schema.json +528 -0
- package/dist/contracts/schemas/agent.schema.json +90 -0
- package/dist/contracts/schemas/tool-selection.schema.json +174 -0
- package/dist/contracts/tools.schema.json +42 -0
- package/dist/contracts/unified-schema.json +40 -0
- package/dist/contracts/v1/agent.d.ts +225 -0
- package/dist/contracts/v1/agent.d.ts.map +1 -0
- package/dist/contracts/v1/agent.js +8 -0
- package/dist/contracts/v1/agent.js.map +1 -0
- package/dist/contracts/v1/agentProfileManifest.d.ts +60 -0
- package/dist/contracts/v1/agentProfileManifest.d.ts.map +1 -0
- package/dist/contracts/v1/agentProfileManifest.js +9 -0
- package/dist/contracts/v1/agentProfileManifest.js.map +1 -0
- package/dist/contracts/v1/agentRules.d.ts +60 -0
- package/dist/contracts/v1/agentRules.d.ts.map +1 -0
- package/dist/contracts/v1/agentRules.js +10 -0
- package/dist/contracts/v1/agentRules.js.map +1 -0
- package/dist/contracts/v1/provider.d.ts +149 -0
- package/dist/contracts/v1/provider.d.ts.map +1 -0
- package/dist/contracts/v1/provider.js +7 -0
- package/dist/contracts/v1/provider.js.map +1 -0
- package/dist/contracts/v1/tool.d.ts +136 -0
- package/dist/contracts/v1/tool.d.ts.map +1 -0
- package/dist/contracts/v1/tool.js +7 -0
- package/dist/contracts/v1/tool.js.map +1 -0
- package/dist/contracts/v1/toolAccess.d.ts +43 -0
- package/dist/contracts/v1/toolAccess.d.ts.map +1 -0
- package/dist/contracts/v1/toolAccess.js +9 -0
- package/dist/contracts/v1/toolAccess.js.map +1 -0
- package/dist/core/adversarial.d.ts +38 -0
- package/dist/core/adversarial.d.ts.map +1 -0
- package/dist/core/adversarial.js +106 -0
- package/dist/core/adversarial.js.map +1 -0
- package/dist/core/adversarialCorrection.d.ts +22 -0
- package/dist/core/adversarialCorrection.d.ts.map +1 -0
- package/dist/core/adversarialCorrection.js +25 -0
- package/dist/core/adversarialCorrection.js.map +1 -0
- package/dist/core/agent.d.ts +331 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +1637 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/agentProfileManifest.d.ts +3 -0
- package/dist/core/agentProfileManifest.d.ts.map +1 -0
- package/dist/core/agentProfileManifest.js +188 -0
- package/dist/core/agentProfileManifest.js.map +1 -0
- package/dist/core/agentProfiles.d.ts +22 -0
- package/dist/core/agentProfiles.d.ts.map +1 -0
- package/dist/core/agentProfiles.js +35 -0
- package/dist/core/agentProfiles.js.map +1 -0
- package/dist/core/agentRegistry.d.ts +111 -0
- package/dist/core/agentRegistry.d.ts.map +1 -0
- package/dist/core/agentRegistry.js +229 -0
- package/dist/core/agentRegistry.js.map +1 -0
- package/dist/core/agentRulebook.d.ts +11 -0
- package/dist/core/agentRulebook.d.ts.map +1 -0
- package/dist/core/agentRulebook.js +136 -0
- package/dist/core/agentRulebook.js.map +1 -0
- package/dist/core/agentSchemaLoader.d.ts +131 -0
- package/dist/core/agentSchemaLoader.d.ts.map +1 -0
- package/dist/core/agentSchemaLoader.js +235 -0
- package/dist/core/agentSchemaLoader.js.map +1 -0
- package/dist/core/aiErrorFixer.d.ts +57 -0
- package/dist/core/aiErrorFixer.d.ts.map +1 -0
- package/dist/core/aiErrorFixer.js +214 -0
- package/dist/core/aiErrorFixer.js.map +1 -0
- package/dist/core/bashCommandGuidance.d.ts +16 -0
- package/dist/core/bashCommandGuidance.d.ts.map +1 -0
- package/dist/core/bashCommandGuidance.js +40 -0
- package/dist/core/bashCommandGuidance.js.map +1 -0
- package/dist/core/compactionNote.d.ts +13 -0
- package/dist/core/compactionNote.d.ts.map +1 -0
- package/dist/core/compactionNote.js +13 -0
- package/dist/core/compactionNote.js.map +1 -0
- package/dist/core/constants.d.ts +31 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +62 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/contextManager.d.ts +271 -0
- package/dist/core/contextManager.d.ts.map +1 -0
- package/dist/core/contextManager.js +1076 -0
- package/dist/core/contextManager.js.map +1 -0
- package/dist/core/contextUsage.d.ts +28 -0
- package/dist/core/contextUsage.d.ts.map +1 -0
- package/dist/core/contextUsage.js +62 -0
- package/dist/core/contextUsage.js.map +1 -0
- package/dist/core/contextWindow.d.ts +42 -0
- package/dist/core/contextWindow.d.ts.map +1 -0
- package/dist/core/contextWindow.js +127 -0
- package/dist/core/contextWindow.js.map +1 -0
- package/dist/core/customCommands.d.ts +19 -0
- package/dist/core/customCommands.d.ts.map +1 -0
- package/dist/core/customCommands.js +85 -0
- package/dist/core/customCommands.js.map +1 -0
- package/dist/core/diffPanel.d.ts +30 -0
- package/dist/core/diffPanel.d.ts.map +1 -0
- package/dist/core/diffPanel.js +48 -0
- package/dist/core/diffPanel.js.map +1 -0
- package/dist/core/errorClassification.d.ts +44 -0
- package/dist/core/errorClassification.d.ts.map +1 -0
- package/dist/core/errorClassification.js +333 -0
- package/dist/core/errorClassification.js.map +1 -0
- package/dist/core/errors/apiKeyErrors.d.ts +11 -0
- package/dist/core/errors/apiKeyErrors.d.ts.map +1 -0
- package/dist/core/errors/apiKeyErrors.js +159 -0
- package/dist/core/errors/apiKeyErrors.js.map +1 -0
- package/dist/core/errors/errorTypes.d.ts +111 -0
- package/dist/core/errors/errorTypes.d.ts.map +1 -0
- package/dist/core/errors/errorTypes.js +345 -0
- package/dist/core/errors/errorTypes.js.map +1 -0
- package/dist/core/errors/index.d.ts +50 -0
- package/dist/core/errors/index.d.ts.map +1 -0
- package/dist/core/errors/index.js +156 -0
- package/dist/core/errors/index.js.map +1 -0
- package/dist/core/errors/networkErrors.d.ts +14 -0
- package/dist/core/errors/networkErrors.d.ts.map +1 -0
- package/dist/core/errors/networkErrors.js +53 -0
- package/dist/core/errors/networkErrors.js.map +1 -0
- package/dist/core/errors/safetyValidator.d.ts +109 -0
- package/dist/core/errors/safetyValidator.d.ts.map +1 -0
- package/dist/core/errors/safetyValidator.js +272 -0
- package/dist/core/errors/safetyValidator.js.map +1 -0
- package/dist/core/errors.d.ts +4 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +33 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/failureRegistry.d.ts +30 -0
- package/dist/core/failureRegistry.d.ts.map +1 -0
- package/dist/core/failureRegistry.js +74 -0
- package/dist/core/failureRegistry.js.map +1 -0
- package/dist/core/fileMentions.d.ts +40 -0
- package/dist/core/fileMentions.d.ts.map +1 -0
- package/dist/core/fileMentions.js +136 -0
- package/dist/core/fileMentions.js.map +1 -0
- package/dist/core/finalResponseFormatter.d.ts +10 -0
- package/dist/core/finalResponseFormatter.d.ts.map +1 -0
- package/dist/core/finalResponseFormatter.js +14 -0
- package/dist/core/finalResponseFormatter.js.map +1 -0
- package/dist/core/guardrails.d.ts +146 -0
- package/dist/core/guardrails.d.ts.map +1 -0
- package/dist/core/guardrails.js +361 -0
- package/dist/core/guardrails.js.map +1 -0
- package/dist/core/hitl.d.ts +119 -0
- package/dist/core/hitl.d.ts.map +1 -0
- package/dist/core/hitl.js +396 -0
- package/dist/core/hitl.js.map +1 -0
- package/dist/core/hooks.d.ts +95 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +236 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/hostedAuth.d.ts +88 -0
- package/dist/core/hostedAuth.d.ts.map +1 -0
- package/dist/core/hostedAuth.js +219 -0
- package/dist/core/hostedAuth.js.map +1 -0
- package/dist/core/inputProtection.d.ts +122 -0
- package/dist/core/inputProtection.d.ts.map +1 -0
- package/dist/core/inputProtection.js +422 -0
- package/dist/core/inputProtection.js.map +1 -0
- package/dist/core/modelDiscovery.d.ts +102 -0
- package/dist/core/modelDiscovery.d.ts.map +1 -0
- package/dist/core/modelDiscovery.js +416 -0
- package/dist/core/modelDiscovery.js.map +1 -0
- package/dist/core/multilinePasteHandler.d.ts +35 -0
- package/dist/core/multilinePasteHandler.d.ts.map +1 -0
- package/dist/core/multilinePasteHandler.js +81 -0
- package/dist/core/multilinePasteHandler.js.map +1 -0
- package/dist/core/permissionMode.d.ts +40 -0
- package/dist/core/permissionMode.d.ts.map +1 -0
- package/dist/core/permissionMode.js +86 -0
- package/dist/core/permissionMode.js.map +1 -0
- package/dist/core/postWriteDiagnostics.d.ts +32 -0
- package/dist/core/postWriteDiagnostics.d.ts.map +1 -0
- package/dist/core/postWriteDiagnostics.js +127 -0
- package/dist/core/postWriteDiagnostics.js.map +1 -0
- package/dist/core/preferences.d.ts +66 -0
- package/dist/core/preferences.d.ts.map +1 -0
- package/dist/core/preferences.js +310 -0
- package/dist/core/preferences.js.map +1 -0
- package/dist/core/quota.d.ts +61 -0
- package/dist/core/quota.d.ts.map +1 -0
- package/dist/core/quota.js +104 -0
- package/dist/core/quota.js.map +1 -0
- package/dist/core/quotaErrors.d.ts +42 -0
- package/dist/core/quotaErrors.d.ts.map +1 -0
- package/dist/core/quotaErrors.js +86 -0
- package/dist/core/quotaErrors.js.map +1 -0
- package/dist/core/refusalDetection.d.ts +2 -0
- package/dist/core/refusalDetection.d.ts.map +1 -0
- package/dist/core/refusalDetection.js +51 -0
- package/dist/core/refusalDetection.js.map +1 -0
- package/dist/core/relativeTime.d.ts +8 -0
- package/dist/core/relativeTime.d.ts.map +1 -0
- package/dist/core/relativeTime.js +29 -0
- package/dist/core/relativeTime.js.map +1 -0
- package/dist/core/resultVerification.d.ts +48 -0
- package/dist/core/resultVerification.d.ts.map +1 -0
- package/dist/core/resultVerification.js +127 -0
- package/dist/core/resultVerification.js.map +1 -0
- package/dist/core/rewind.d.ts +14 -0
- package/dist/core/rewind.d.ts.map +1 -0
- package/dist/core/rewind.js +25 -0
- package/dist/core/rewind.js.map +1 -0
- package/dist/core/schemaValidator.d.ts +49 -0
- package/dist/core/schemaValidator.d.ts.map +1 -0
- package/dist/core/schemaValidator.js +234 -0
- package/dist/core/schemaValidator.js.map +1 -0
- package/dist/core/secretStore.d.ts +59 -0
- package/dist/core/secretStore.d.ts.map +1 -0
- package/dist/core/secretStore.js +278 -0
- package/dist/core/secretStore.js.map +1 -0
- package/dist/core/sessionStorage.d.ts +10 -0
- package/dist/core/sessionStorage.d.ts.map +1 -0
- package/dist/core/sessionStorage.js +46 -0
- package/dist/core/sessionStorage.js.map +1 -0
- package/dist/core/sessionStore.d.ts +35 -0
- package/dist/core/sessionStore.d.ts.map +1 -0
- package/dist/core/sessionStore.js +190 -0
- package/dist/core/sessionStore.js.map +1 -0
- package/dist/core/shutdown.d.ts +34 -0
- package/dist/core/shutdown.d.ts.map +1 -0
- package/dist/core/shutdown.js +186 -0
- package/dist/core/shutdown.js.map +1 -0
- package/dist/core/slashCommands.d.ts +38 -0
- package/dist/core/slashCommands.d.ts.map +1 -0
- package/dist/core/slashCommands.js +72 -0
- package/dist/core/slashCommands.js.map +1 -0
- package/dist/core/subAgentNote.d.ts +15 -0
- package/dist/core/subAgentNote.d.ts.map +1 -0
- package/dist/core/subAgentNote.js +16 -0
- package/dist/core/subAgentNote.js.map +1 -0
- package/dist/core/sudoPasswordManager.d.ts +52 -0
- package/dist/core/sudoPasswordManager.d.ts.map +1 -0
- package/dist/core/sudoPasswordManager.js +115 -0
- package/dist/core/sudoPasswordManager.js.map +1 -0
- package/dist/core/taskCompletionDetector.d.ts +117 -0
- package/dist/core/taskCompletionDetector.d.ts.map +1 -0
- package/dist/core/taskCompletionDetector.js +532 -0
- package/dist/core/taskCompletionDetector.js.map +1 -0
- package/dist/core/testFailureMonitor.d.ts +67 -0
- package/dist/core/testFailureMonitor.d.ts.map +1 -0
- package/dist/core/testFailureMonitor.js +262 -0
- package/dist/core/testFailureMonitor.js.map +1 -0
- package/dist/core/thinkingVerbs.d.ts +31 -0
- package/dist/core/thinkingVerbs.d.ts.map +1 -0
- package/dist/core/thinkingVerbs.js +58 -0
- package/dist/core/thinkingVerbs.js.map +1 -0
- package/dist/core/toolPreconditions.d.ts +34 -0
- package/dist/core/toolPreconditions.d.ts.map +1 -0
- package/dist/core/toolPreconditions.js +242 -0
- package/dist/core/toolPreconditions.js.map +1 -0
- package/dist/core/toolRuntime.d.ts +193 -0
- package/dist/core/toolRuntime.d.ts.map +1 -0
- package/dist/core/toolRuntime.js +526 -0
- package/dist/core/toolRuntime.js.map +1 -0
- package/dist/core/turnGovernor.d.ts +63 -0
- package/dist/core/turnGovernor.d.ts.map +1 -0
- package/dist/core/turnGovernor.js +94 -0
- package/dist/core/turnGovernor.js.map +1 -0
- package/dist/core/types/utilityTypes.d.ts +183 -0
- package/dist/core/types/utilityTypes.d.ts.map +1 -0
- package/dist/core/types/utilityTypes.js +273 -0
- package/dist/core/types/utilityTypes.js.map +1 -0
- package/dist/core/types.d.ts +334 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +76 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/updateChecker.d.ts +148 -0
- package/dist/core/updateChecker.d.ts.map +1 -0
- package/dist/core/updateChecker.js +605 -0
- package/dist/core/updateChecker.js.map +1 -0
- package/dist/core/usage.d.ts +28 -0
- package/dist/core/usage.d.ts.map +1 -0
- package/dist/core/usage.js +77 -0
- package/dist/core/usage.js.map +1 -0
- package/dist/headless/interactiveShell.d.ts +47 -0
- package/dist/headless/interactiveShell.d.ts.map +1 -0
- package/dist/headless/interactiveShell.js +2495 -0
- package/dist/headless/interactiveShell.js.map +1 -0
- package/dist/leanAgent.d.ts +73 -0
- package/dist/leanAgent.d.ts.map +1 -0
- package/dist/leanAgent.js +177 -0
- package/dist/leanAgent.js.map +1 -0
- package/dist/plugins/providers/deepseek/index.d.ts +12 -0
- package/dist/plugins/providers/deepseek/index.d.ts.map +1 -0
- package/dist/plugins/providers/deepseek/index.js +123 -0
- package/dist/plugins/providers/deepseek/index.js.map +1 -0
- package/dist/plugins/providers/index.d.ts +2 -0
- package/dist/plugins/providers/index.d.ts.map +1 -0
- package/dist/plugins/providers/index.js +10 -0
- package/dist/plugins/providers/index.js.map +1 -0
- package/dist/providers/baseProvider.d.ts +140 -0
- package/dist/providers/baseProvider.d.ts.map +1 -0
- package/dist/providers/baseProvider.js +230 -0
- package/dist/providers/baseProvider.js.map +1 -0
- package/dist/providers/openaiChatCompletionsProvider.d.ts +70 -0
- package/dist/providers/openaiChatCompletionsProvider.d.ts.map +1 -0
- package/dist/providers/openaiChatCompletionsProvider.js +971 -0
- package/dist/providers/openaiChatCompletionsProvider.js.map +1 -0
- package/dist/providers/providerFactory.d.ts +22 -0
- package/dist/providers/providerFactory.d.ts.map +1 -0
- package/dist/providers/providerFactory.js +25 -0
- package/dist/providers/providerFactory.js.map +1 -0
- package/dist/providers/resilientProvider.d.ts +96 -0
- package/dist/providers/resilientProvider.d.ts.map +1 -0
- package/dist/providers/resilientProvider.js +251 -0
- package/dist/providers/resilientProvider.js.map +1 -0
- package/dist/runtime/agentController.d.ts +137 -0
- package/dist/runtime/agentController.d.ts.map +1 -0
- package/dist/runtime/agentController.js +784 -0
- package/dist/runtime/agentController.js.map +1 -0
- package/dist/runtime/agentHost.d.ts +61 -0
- package/dist/runtime/agentHost.d.ts.map +1 -0
- package/dist/runtime/agentHost.js +158 -0
- package/dist/runtime/agentHost.js.map +1 -0
- package/dist/runtime/agentSession.d.ts +49 -0
- package/dist/runtime/agentSession.d.ts.map +1 -0
- package/dist/runtime/agentSession.js +218 -0
- package/dist/runtime/agentSession.js.map +1 -0
- package/dist/runtime/agentSpawningWiring.d.ts +32 -0
- package/dist/runtime/agentSpawningWiring.d.ts.map +1 -0
- package/dist/runtime/agentSpawningWiring.js +114 -0
- package/dist/runtime/agentSpawningWiring.js.map +1 -0
- package/dist/runtime/node.d.ts +7 -0
- package/dist/runtime/node.d.ts.map +1 -0
- package/dist/runtime/node.js +50 -0
- package/dist/runtime/node.js.map +1 -0
- package/dist/runtime/universal.d.ts +18 -0
- package/dist/runtime/universal.d.ts.map +1 -0
- package/dist/runtime/universal.js +21 -0
- package/dist/runtime/universal.js.map +1 -0
- package/dist/shell/liveStatus.d.ts +27 -0
- package/dist/shell/liveStatus.d.ts.map +1 -0
- package/dist/shell/liveStatus.js +53 -0
- package/dist/shell/liveStatus.js.map +1 -0
- package/dist/shell/systemPrompt.d.ts +12 -0
- package/dist/shell/systemPrompt.d.ts.map +1 -0
- package/dist/shell/systemPrompt.js +16 -0
- package/dist/shell/systemPrompt.js.map +1 -0
- package/dist/shell/toolPresentation.d.ts +54 -0
- package/dist/shell/toolPresentation.d.ts.map +1 -0
- package/dist/shell/toolPresentation.js +334 -0
- package/dist/shell/toolPresentation.js.map +1 -0
- package/dist/tools/bashTools.d.ts +11 -0
- package/dist/tools/bashTools.d.ts.map +1 -0
- package/dist/tools/bashTools.js +785 -0
- package/dist/tools/bashTools.js.map +1 -0
- package/dist/tools/diffUtils.d.ts +43 -0
- package/dist/tools/diffUtils.d.ts.map +1 -0
- package/dist/tools/diffUtils.js +607 -0
- package/dist/tools/diffUtils.js.map +1 -0
- package/dist/tools/editTools.d.ts +29 -0
- package/dist/tools/editTools.d.ts.map +1 -0
- package/dist/tools/editTools.js +792 -0
- package/dist/tools/editTools.js.map +1 -0
- package/dist/tools/fileChangeTracker.d.ts +47 -0
- package/dist/tools/fileChangeTracker.d.ts.map +1 -0
- package/dist/tools/fileChangeTracker.js +154 -0
- package/dist/tools/fileChangeTracker.js.map +1 -0
- package/dist/tools/fileReadTracker.d.ts +69 -0
- package/dist/tools/fileReadTracker.d.ts.map +1 -0
- package/dist/tools/fileReadTracker.js +213 -0
- package/dist/tools/fileReadTracker.js.map +1 -0
- package/dist/tools/fileTools.d.ts +3 -0
- package/dist/tools/fileTools.d.ts.map +1 -0
- package/dist/tools/fileTools.js +389 -0
- package/dist/tools/fileTools.js.map +1 -0
- package/dist/tools/grepTools.d.ts +3 -0
- package/dist/tools/grepTools.d.ts.map +1 -0
- package/dist/tools/grepTools.js +137 -0
- package/dist/tools/grepTools.js.map +1 -0
- package/dist/tools/hitlTools.d.ts +7 -0
- package/dist/tools/hitlTools.d.ts.map +1 -0
- package/dist/tools/hitlTools.js +185 -0
- package/dist/tools/hitlTools.js.map +1 -0
- package/dist/tools/memoryTools.d.ts +27 -0
- package/dist/tools/memoryTools.d.ts.map +1 -0
- package/dist/tools/memoryTools.js +197 -0
- package/dist/tools/memoryTools.js.map +1 -0
- package/dist/tools/notebookTools.d.ts +20 -0
- package/dist/tools/notebookTools.d.ts.map +1 -0
- package/dist/tools/notebookTools.js +140 -0
- package/dist/tools/notebookTools.js.map +1 -0
- package/dist/tools/searchTools.d.ts +12 -0
- package/dist/tools/searchTools.d.ts.map +1 -0
- package/dist/tools/searchTools.js +414 -0
- package/dist/tools/searchTools.js.map +1 -0
- package/dist/tools/skillTools.d.ts +24 -0
- package/dist/tools/skillTools.d.ts.map +1 -0
- package/dist/tools/skillTools.js +140 -0
- package/dist/tools/skillTools.js.map +1 -0
- package/dist/tools/todoTools.d.ts +23 -0
- package/dist/tools/todoTools.d.ts.map +1 -0
- package/dist/tools/todoTools.js +120 -0
- package/dist/tools/todoTools.js.map +1 -0
- package/dist/tools/webTools.d.ts +26 -0
- package/dist/tools/webTools.d.ts.map +1 -0
- package/dist/tools/webTools.js +467 -0
- package/dist/tools/webTools.js.map +1 -0
- package/dist/ui/ink/App.d.ts +53 -0
- package/dist/ui/ink/App.d.ts.map +1 -0
- package/dist/ui/ink/App.js +13 -0
- package/dist/ui/ink/App.js.map +1 -0
- package/dist/ui/ink/ChatStatic.d.ts +30 -0
- package/dist/ui/ink/ChatStatic.d.ts.map +1 -0
- package/dist/ui/ink/ChatStatic.js +83 -0
- package/dist/ui/ink/ChatStatic.js.map +1 -0
- package/dist/ui/ink/InkPromptController.d.ts +321 -0
- package/dist/ui/ink/InkPromptController.d.ts.map +1 -0
- package/dist/ui/ink/InkPromptController.js +667 -0
- package/dist/ui/ink/InkPromptController.js.map +1 -0
- package/dist/ui/ink/Menu.d.ts +21 -0
- package/dist/ui/ink/Menu.d.ts.map +1 -0
- package/dist/ui/ink/Menu.js +61 -0
- package/dist/ui/ink/Menu.js.map +1 -0
- package/dist/ui/ink/Prompt.d.ts +47 -0
- package/dist/ui/ink/Prompt.d.ts.map +1 -0
- package/dist/ui/ink/Prompt.js +571 -0
- package/dist/ui/ink/Prompt.js.map +1 -0
- package/dist/ui/ink/StatusLine.d.ts +35 -0
- package/dist/ui/ink/StatusLine.d.ts.map +1 -0
- package/dist/ui/ink/StatusLine.js +66 -0
- package/dist/ui/ink/StatusLine.js.map +1 -0
- package/dist/ui/ink/pasteBuffer.d.ts +44 -0
- package/dist/ui/ink/pasteBuffer.d.ts.map +1 -0
- package/dist/ui/ink/pasteBuffer.js +73 -0
- package/dist/ui/ink/pasteBuffer.js.map +1 -0
- package/dist/ui/theme.d.ts +351 -0
- package/dist/ui/theme.d.ts.map +1 -0
- package/dist/ui/theme.js +435 -0
- package/dist/ui/theme.js.map +1 -0
- package/dist/utils/analytics.d.ts +2 -0
- package/dist/utils/analytics.d.ts.map +1 -0
- package/dist/utils/analytics.js +51 -0
- package/dist/utils/analytics.js.map +1 -0
- package/dist/utils/asyncUtils.d.ts +95 -0
- package/dist/utils/asyncUtils.d.ts.map +1 -0
- package/dist/utils/asyncUtils.js +286 -0
- package/dist/utils/asyncUtils.js.map +1 -0
- package/dist/utils/debugLogger.d.ts +6 -0
- package/dist/utils/debugLogger.d.ts.map +1 -0
- package/dist/utils/debugLogger.js +39 -0
- package/dist/utils/debugLogger.js.map +1 -0
- package/dist/utils/errorUtils.d.ts +12 -0
- package/dist/utils/errorUtils.d.ts.map +1 -0
- package/dist/utils/errorUtils.js +83 -0
- package/dist/utils/errorUtils.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +10 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +78 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/packageInfo.d.ts +14 -0
- package/dist/utils/packageInfo.d.ts.map +1 -0
- package/dist/utils/packageInfo.js +45 -0
- package/dist/utils/packageInfo.js.map +1 -0
- package/dist/utils/planFormatter.d.ts +34 -0
- package/dist/utils/planFormatter.d.ts.map +1 -0
- package/dist/utils/planFormatter.js +141 -0
- package/dist/utils/planFormatter.js.map +1 -0
- package/dist/utils/securityUtils.d.ts +132 -0
- package/dist/utils/securityUtils.d.ts.map +1 -0
- package/dist/utils/securityUtils.js +324 -0
- package/dist/utils/securityUtils.js.map +1 -0
- package/dist/utils/statusReporter.d.ts +6 -0
- package/dist/utils/statusReporter.d.ts.map +1 -0
- package/dist/utils/statusReporter.js +26 -0
- package/dist/utils/statusReporter.js.map +1 -0
- package/dist/workspace.d.ts +8 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +135 -0
- package/dist/workspace.js.map +1 -0
- package/dist/workspace.validator.d.ts +49 -0
- package/dist/workspace.validator.d.ts.map +1 -0
- package/dist/workspace.validator.js +215 -0
- package/dist/workspace.validator.js.map +1 -0
- package/package.json +116 -0
- package/scripts/postinstall.cjs +56 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /rewind preview + result text. Pure + emoji-free (the UX contract §9 bans
|
|
3
|
+
* chrome emoji, and the legacy fileChangeTracker.getRevertSummary/revertAllChanges
|
|
4
|
+
* strings use 📋/⏪ + hardcode "/revert confirm" — so the Ink shell builds its
|
|
5
|
+
* own copy here and only calls revertAllChanges for the actual file restore).
|
|
6
|
+
*/
|
|
7
|
+
export function rewindPreviewLines(items) {
|
|
8
|
+
const n = items.length;
|
|
9
|
+
const lines = [`Rewind restores ${n} file${n === 1 ? '' : 's'} to the state before this run:`, ''];
|
|
10
|
+
for (const it of items) {
|
|
11
|
+
lines.push(it.existedBefore ? ` ${it.relPath} (restore)` : ` ${it.relPath} (delete — created this run)`);
|
|
12
|
+
}
|
|
13
|
+
lines.push('');
|
|
14
|
+
lines.push('Run /rewind confirm to restore them.');
|
|
15
|
+
return lines;
|
|
16
|
+
}
|
|
17
|
+
export function rewindResultLine(restored, deleted) {
|
|
18
|
+
const parts = [];
|
|
19
|
+
if (restored > 0)
|
|
20
|
+
parts.push(`${restored} file${restored === 1 ? '' : 's'} restored`);
|
|
21
|
+
if (deleted > 0)
|
|
22
|
+
parts.push(`${deleted} file${deleted === 1 ? '' : 's'} deleted`);
|
|
23
|
+
return parts.length ? `Rewound: ${parts.join(', ')}.` : 'Nothing to rewind.';
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=rewind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewind.js","sourceRoot":"","sources":["../../src/core/rewind.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,MAAM,UAAU,kBAAkB,CAAC,KAAmB;IACpD,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IACvB,MAAM,KAAK,GAAG,CAAC,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,gCAAgC,EAAE,EAAE,CAAC,CAAC;IACnG,KAAK,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,OAAO,8BAA8B,CAAC,CAAC;IAC7G,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;IACnD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAgB,EAAE,OAAe;IAChE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,QAAQ,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,QAAQ,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC;IACtF,IAAI,OAAO,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,QAAQ,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;IAClF,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,oBAAoB,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { JSONSchemaObject } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced validation error with structured error information
|
|
4
|
+
*/
|
|
5
|
+
export declare class ToolArgumentValidationError extends Error {
|
|
6
|
+
readonly issues: readonly string[];
|
|
7
|
+
readonly toolName: string;
|
|
8
|
+
constructor(toolName: string, issues: string[]);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Runtime type guards for tool argument validation
|
|
12
|
+
*/
|
|
13
|
+
export declare namespace TypeGuards {
|
|
14
|
+
/**
|
|
15
|
+
* Type guard for string values
|
|
16
|
+
*/
|
|
17
|
+
function isString(value: unknown): value is string;
|
|
18
|
+
/**
|
|
19
|
+
* Type guard for number values
|
|
20
|
+
*/
|
|
21
|
+
function isNumber(value: unknown): value is number;
|
|
22
|
+
/**
|
|
23
|
+
* Type guard for boolean values
|
|
24
|
+
*/
|
|
25
|
+
function isBoolean(value: unknown): value is boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Type guard for array values
|
|
28
|
+
*/
|
|
29
|
+
function isArray(value: unknown): value is unknown[];
|
|
30
|
+
/**
|
|
31
|
+
* Type guard for object values
|
|
32
|
+
*/
|
|
33
|
+
function isObject(value: unknown): value is Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Type guard for non-null values
|
|
36
|
+
*/
|
|
37
|
+
function isNotNull(value: unknown): value is NonNullable<unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Type guard for enum values
|
|
40
|
+
*/
|
|
41
|
+
function isEnum<T extends string>(value: unknown, enumValues: readonly T[]): value is T;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Coerce loosely-typed tool arguments into their declared schema types.
|
|
45
|
+
* This makes tools resilient to providers that emit boolean/number values as strings.
|
|
46
|
+
*/
|
|
47
|
+
export declare function coerceToolArguments(schema: JSONSchemaObject | undefined, args: Record<string, unknown>): Record<string, unknown>;
|
|
48
|
+
export declare function validateToolArguments(toolName: string, schema: JSONSchemaObject | undefined, args: Record<string, unknown>): void;
|
|
49
|
+
//# sourceMappingURL=schemaValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaValidator.d.ts","sourceRoot":"","sources":["../../src/core/schemaValidator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,gBAAgB,EAAsB,MAAM,YAAY,CAAC;AAExF;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;CAM/C;AAED;;GAEG;AACH,yBAAiB,UAAU,CAAC;IAC1B;;OAEG;IACH,SAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;IAED;;OAEG;IACH,SAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;IAED;;OAEG;IACH,SAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAE1D;IAED;;OAEG;IACH,SAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,EAAE,CAE1D;IAED;;OAEG;IACH,SAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;IAED;;OAEG;IACH,SAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC,OAAO,CAAC,CAEvE;IAED;;OAEG;IACH,SAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC,CAE7F;CACF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,GAAG,SAAS,EACpC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiCzB;AAoCD,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,gBAAgB,GAAG,SAAS,EACpC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,IAAI,CA6BN"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced validation error with structured error information
|
|
3
|
+
*/
|
|
4
|
+
export class ToolArgumentValidationError extends Error {
|
|
5
|
+
issues;
|
|
6
|
+
toolName;
|
|
7
|
+
constructor(toolName, issues) {
|
|
8
|
+
super(formatMessage(toolName, issues));
|
|
9
|
+
this.name = 'ToolArgumentValidationError';
|
|
10
|
+
this.issues = issues;
|
|
11
|
+
this.toolName = toolName;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Runtime type guards for tool argument validation
|
|
16
|
+
*/
|
|
17
|
+
export var TypeGuards;
|
|
18
|
+
(function (TypeGuards) {
|
|
19
|
+
/**
|
|
20
|
+
* Type guard for string values
|
|
21
|
+
*/
|
|
22
|
+
function isString(value) {
|
|
23
|
+
return typeof value === 'string';
|
|
24
|
+
}
|
|
25
|
+
TypeGuards.isString = isString;
|
|
26
|
+
/**
|
|
27
|
+
* Type guard for number values
|
|
28
|
+
*/
|
|
29
|
+
function isNumber(value) {
|
|
30
|
+
return typeof value === 'number' && !Number.isNaN(value);
|
|
31
|
+
}
|
|
32
|
+
TypeGuards.isNumber = isNumber;
|
|
33
|
+
/**
|
|
34
|
+
* Type guard for boolean values
|
|
35
|
+
*/
|
|
36
|
+
function isBoolean(value) {
|
|
37
|
+
return typeof value === 'boolean';
|
|
38
|
+
}
|
|
39
|
+
TypeGuards.isBoolean = isBoolean;
|
|
40
|
+
/**
|
|
41
|
+
* Type guard for array values
|
|
42
|
+
*/
|
|
43
|
+
function isArray(value) {
|
|
44
|
+
return Array.isArray(value);
|
|
45
|
+
}
|
|
46
|
+
TypeGuards.isArray = isArray;
|
|
47
|
+
/**
|
|
48
|
+
* Type guard for object values
|
|
49
|
+
*/
|
|
50
|
+
function isObject(value) {
|
|
51
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
TypeGuards.isObject = isObject;
|
|
54
|
+
/**
|
|
55
|
+
* Type guard for non-null values
|
|
56
|
+
*/
|
|
57
|
+
function isNotNull(value) {
|
|
58
|
+
return value !== undefined && value !== null;
|
|
59
|
+
}
|
|
60
|
+
TypeGuards.isNotNull = isNotNull;
|
|
61
|
+
/**
|
|
62
|
+
* Type guard for enum values
|
|
63
|
+
*/
|
|
64
|
+
function isEnum(value, enumValues) {
|
|
65
|
+
return TypeGuards.isString(value) && enumValues.includes(value);
|
|
66
|
+
}
|
|
67
|
+
TypeGuards.isEnum = isEnum;
|
|
68
|
+
})(TypeGuards || (TypeGuards = {}));
|
|
69
|
+
/**
|
|
70
|
+
* Coerce loosely-typed tool arguments into their declared schema types.
|
|
71
|
+
* This makes tools resilient to providers that emit boolean/number values as strings.
|
|
72
|
+
*/
|
|
73
|
+
export function coerceToolArguments(schema, args) {
|
|
74
|
+
if (!schema || schema.type !== 'object' || !schema.properties) {
|
|
75
|
+
return args;
|
|
76
|
+
}
|
|
77
|
+
const coerced = { ...args };
|
|
78
|
+
for (const [key, definition] of Object.entries(schema.properties)) {
|
|
79
|
+
if (!Object.hasOwn(args, key)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const value = args[key];
|
|
83
|
+
if (value === undefined || value === null) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
switch (definition.type) {
|
|
87
|
+
case 'boolean': {
|
|
88
|
+
const normalized = coerceBoolean(value);
|
|
89
|
+
coerced[key] = normalized;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case 'number': {
|
|
93
|
+
const normalized = coerceNumber(value);
|
|
94
|
+
coerced[key] = normalized;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
default:
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return coerced;
|
|
102
|
+
}
|
|
103
|
+
function coerceBoolean(value) {
|
|
104
|
+
if (typeof value === 'boolean') {
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
if (typeof value === 'number') {
|
|
108
|
+
if (value === 1)
|
|
109
|
+
return true;
|
|
110
|
+
if (value === 0)
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (typeof value === 'string') {
|
|
114
|
+
const trimmed = value.trim().toLowerCase();
|
|
115
|
+
if (trimmed === 'true' || trimmed === '1')
|
|
116
|
+
return true;
|
|
117
|
+
if (trimmed === 'false' || trimmed === '0')
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
function coerceNumber(value) {
|
|
123
|
+
if (typeof value === 'number') {
|
|
124
|
+
// Reject NaN, Infinity, and -Infinity
|
|
125
|
+
if (!Number.isFinite(value)) {
|
|
126
|
+
return value; // Return as-is to fail validation
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
131
|
+
const parsed = Number(value);
|
|
132
|
+
// Only accept finite numbers
|
|
133
|
+
if (Number.isFinite(parsed)) {
|
|
134
|
+
return parsed;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
export function validateToolArguments(toolName, schema, args) {
|
|
140
|
+
if (!schema || schema.type !== 'object') {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const errors = [];
|
|
144
|
+
const properties = schema.properties ?? {};
|
|
145
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
146
|
+
for (const property of required) {
|
|
147
|
+
if (!hasArgument(args, property)) {
|
|
148
|
+
errors.push(`Missing required property "${property}".`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (const [key, value] of Object.entries(args)) {
|
|
152
|
+
const definition = properties[key];
|
|
153
|
+
if (!definition) {
|
|
154
|
+
// Silently ignore unknown properties - models sometimes hallucinate extra params
|
|
155
|
+
// This is more lenient than strict JSON schema validation but prevents errors
|
|
156
|
+
// when models pass extra parameters that don't affect tool behavior
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
validateSchemaProperty(definition, value, key, errors);
|
|
160
|
+
}
|
|
161
|
+
if (errors.length) {
|
|
162
|
+
throw new ToolArgumentValidationError(toolName, errors);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function validateSchemaProperty(definition, value, path, errors) {
|
|
166
|
+
switch (definition.type) {
|
|
167
|
+
case 'string': {
|
|
168
|
+
if (typeof value !== 'string') {
|
|
169
|
+
errors.push(`Argument "${path}" must be a string.`);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (definition.enum && !definition.enum.includes(value)) {
|
|
173
|
+
errors.push(`Argument "${path}" must be one of: ${definition.enum.map((entry) => `"${entry}"`).join(', ')}.`);
|
|
174
|
+
}
|
|
175
|
+
if (typeof definition.minLength === 'number' && value.length < definition.minLength) {
|
|
176
|
+
errors.push(`Argument "${path}" must be at least ${definition.minLength} character${definition.minLength === 1 ? '' : 's'} long.`);
|
|
177
|
+
}
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
case 'number': {
|
|
181
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
182
|
+
errors.push(`Argument "${path}" must be a finite number.`);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
// Validate minimum constraint
|
|
186
|
+
if (typeof definition.minimum === 'number' && value < definition.minimum) {
|
|
187
|
+
errors.push(`Argument "${path}" must be at least ${definition.minimum}.`);
|
|
188
|
+
}
|
|
189
|
+
// Validate maximum constraint
|
|
190
|
+
if (typeof definition.maximum === 'number' && value > definition.maximum) {
|
|
191
|
+
errors.push(`Argument "${path}" must be at most ${definition.maximum}.`);
|
|
192
|
+
}
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
case 'boolean': {
|
|
196
|
+
if (typeof value !== 'boolean') {
|
|
197
|
+
errors.push(`Argument "${path}" must be a boolean.`);
|
|
198
|
+
}
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
case 'array': {
|
|
202
|
+
if (!Array.isArray(value)) {
|
|
203
|
+
errors.push(`Argument "${path}" must be an array.`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
validateArrayItems(definition, value, path, errors);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
default:
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function validateArrayItems(definition, value, path, errors) {
|
|
214
|
+
const itemSchema = definition.items;
|
|
215
|
+
if (!itemSchema) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
219
|
+
const entry = value[index];
|
|
220
|
+
validateSchemaProperty(itemSchema, entry, `${path}[${index}]`, errors);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function hasArgument(args, key) {
|
|
224
|
+
if (!Object.hasOwn(args, key)) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
const value = args[key];
|
|
228
|
+
return value !== undefined && value !== null;
|
|
229
|
+
}
|
|
230
|
+
function formatMessage(toolName, issues) {
|
|
231
|
+
const detail = issues.join(' ');
|
|
232
|
+
return `Invalid arguments for "${toolName}": ${detail}`;
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=schemaValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaValidator.js","sourceRoot":"","sources":["../../src/core/schemaValidator.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC3C,MAAM,CAAoB;IAC1B,QAAQ,CAAS;IAE1B,YAAY,QAAgB,EAAE,MAAgB;QAC5C,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,KAAW,UAAU,CAiD1B;AAjDD,WAAiB,UAAU;IACzB;;OAEG;IACH,SAAgB,QAAQ,CAAC,KAAc;QACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;IACnC,CAAC;IAFe,mBAAQ,WAEvB,CAAA;IAED;;OAEG;IACH,SAAgB,QAAQ,CAAC,KAAc;QACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,C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CAAC;gBACpD,OAAO;YACT,CAAC;YACD,kBAAkB,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YACpD,OAAO;QACT,CAAC;QACD;YACE,OAAO;IACX,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CACzB,UAA2B,EAC3B,KAAgB,EAChB,IAAY,EACZ,MAAgB;IAEhB,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC;IACpC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;IACT,CAAC;IAED,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,sBAAsB,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,IAAI,IAAI,KAAK,GAAG,EAAE,MAAM,CAAC,CAAC;IACzE,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAA6B,EAAE,GAAW;IAC7D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AAC/C,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB,EAAE,MAAgB;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,OAAO,0BAA0B,QAAQ,MAAM,MAAM,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ProviderId } from './types.js';
|
|
2
|
+
export type SecretName = 'DEEPSEEK_API_KEY' | 'TAVILY_API_KEY';
|
|
3
|
+
export interface SecretDefinition {
|
|
4
|
+
id: SecretName;
|
|
5
|
+
label: string;
|
|
6
|
+
description: string;
|
|
7
|
+
envVar: SecretName;
|
|
8
|
+
providers: ProviderId[];
|
|
9
|
+
}
|
|
10
|
+
export declare class MissingSecretError extends Error {
|
|
11
|
+
readonly secret: SecretDefinition;
|
|
12
|
+
constructor(secret: SecretDefinition);
|
|
13
|
+
}
|
|
14
|
+
export declare function listSecretDefinitions(): SecretDefinition[];
|
|
15
|
+
export declare function getSecretDefinition(id: SecretName): SecretDefinition | null;
|
|
16
|
+
export declare function getSecretValue(id: SecretName): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Load all stored secrets into process.env at startup.
|
|
19
|
+
* This ensures secrets are available before any provider checks.
|
|
20
|
+
*
|
|
21
|
+
* IMPORTANT: Stored secrets always take precedence over environment variables
|
|
22
|
+
* for provider API keys. This ensures keys set via /secrets are used even if
|
|
23
|
+
* the user has old/stale keys exported in their shell environment.
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadAllSecrets(): void;
|
|
26
|
+
export declare function setSecretValue(id: SecretName, rawValue: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Route a raw `/key` argument to the secret it sets, by prefix or explicit
|
|
29
|
+
* provider word. DeepSeek keys are `sk-…`, Tavily keys are `tvly-…`, so a bare
|
|
30
|
+
* key self-identifies; `/key tavily <k>` / `/key deepseek <k>` force it. Bare
|
|
31
|
+
* keys with no known prefix default to DeepSeek (back-compat — that was the
|
|
32
|
+
* only key `/key` ever set). Returns null for an empty/blank argument.
|
|
33
|
+
*/
|
|
34
|
+
export declare function classifyKeyEntry(raw: string): {
|
|
35
|
+
id: SecretName;
|
|
36
|
+
value: string;
|
|
37
|
+
} | null;
|
|
38
|
+
export declare function maskSecret(value: string): string;
|
|
39
|
+
export declare function ensureSecretForProvider(provider: ProviderId): string;
|
|
40
|
+
export declare function getSecretDefinitionForProvider(provider: ProviderId): SecretDefinition | null;
|
|
41
|
+
/**
|
|
42
|
+
* Sanitize error messages to remove potential API keys and secrets.
|
|
43
|
+
* This prevents accidental token leakage in logs, error reports, and console output.
|
|
44
|
+
*
|
|
45
|
+
* @param message - The error message or string to sanitize
|
|
46
|
+
* @returns The sanitized string with secrets replaced by [REDACTED]
|
|
47
|
+
*/
|
|
48
|
+
export declare function sanitizeErrorMessage(message: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Sanitize an Error object's message and stack trace.
|
|
51
|
+
* Returns a new error message string with secrets removed.
|
|
52
|
+
*/
|
|
53
|
+
export declare function sanitizeError(error: Error): string;
|
|
54
|
+
/**
|
|
55
|
+
* Create a safe error message from an unknown error value.
|
|
56
|
+
* Ensures no secrets are leaked regardless of error type.
|
|
57
|
+
*/
|
|
58
|
+
export declare function safeErrorMessage(error: unknown): string;
|
|
59
|
+
//# sourceMappingURL=secretStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secretStore.d.ts","sourceRoot":"","sources":["../../src/core/secretStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,UAAU,GAClB,kBAAkB,GAClB,gBAAgB,CAAC;AAErB,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,EAAE,UAAU,EAAE,CAAC;CACzB;AA2BD,qBAAa,kBAAmB,SAAQ,KAAK;aACf,MAAM,EAAE,gBAAgB;gBAAxB,MAAM,EAAE,gBAAgB;CAIrD;AAED,wBAAgB,qBAAqB,IAAI,gBAAgB,EAAE,CAE1D;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,UAAU,GAAG,gBAAgB,GAAG,IAAI,CAE3E;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAkB5D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAYrC;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAUrE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAetF;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,CAQpE;AAED,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,UAAU,GAAG,gBAAgB,GAAG,IAAI,CAE5F;AAmED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA4B5D;AAoCD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAQlD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQvD"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
const SECRET_DEFINITIONS = [
|
|
5
|
+
{
|
|
6
|
+
id: 'DEEPSEEK_API_KEY',
|
|
7
|
+
label: 'DeepSeek API Key',
|
|
8
|
+
description: 'Required to run DeepSeek Reasoner or Chat models.',
|
|
9
|
+
envVar: 'DEEPSEEK_API_KEY',
|
|
10
|
+
providers: ['deepseek'],
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: 'TAVILY_API_KEY',
|
|
14
|
+
label: 'Tavily API Key',
|
|
15
|
+
description: 'Required: WebSearch and WebExtract provider. Get yours at https://tavily.com',
|
|
16
|
+
envVar: 'TAVILY_API_KEY',
|
|
17
|
+
providers: [],
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
const envAgiHome = process.env['TRENCHWORK_HOME'];
|
|
21
|
+
const SECRET_DIR = envAgiHome ? resolve(envAgiHome) : join(homedir(), '.trenchwork');
|
|
22
|
+
const SECRET_FILE = join(SECRET_DIR, 'secrets.json');
|
|
23
|
+
export class MissingSecretError extends Error {
|
|
24
|
+
secret;
|
|
25
|
+
constructor(secret) {
|
|
26
|
+
super(`${secret.label} is not configured.`);
|
|
27
|
+
this.secret = secret;
|
|
28
|
+
this.name = 'MissingSecretError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function listSecretDefinitions() {
|
|
32
|
+
return [...SECRET_DEFINITIONS];
|
|
33
|
+
}
|
|
34
|
+
export function getSecretDefinition(id) {
|
|
35
|
+
return SECRET_DEFINITIONS.find((entry) => entry.id === id) ?? null;
|
|
36
|
+
}
|
|
37
|
+
export function getSecretValue(id) {
|
|
38
|
+
const envValue = sanitize(process.env[id]);
|
|
39
|
+
if (envValue) {
|
|
40
|
+
return envValue;
|
|
41
|
+
}
|
|
42
|
+
const store = readSecretStore();
|
|
43
|
+
const storedValue = sanitize(store[id]);
|
|
44
|
+
if (!storedValue) {
|
|
45
|
+
// Project Glasswing: no API key is baked into the source. A keyless
|
|
46
|
+
// DeepSeek default used to live here; it shipped in the npm `dist/` and
|
|
47
|
+
// git history — a secret inside the design. Credentials are now resolved
|
|
48
|
+
// at runtime by the provider (user key, or an operator proxy).
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
process.env[id] = storedValue;
|
|
52
|
+
return storedValue;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Load all stored secrets into process.env at startup.
|
|
56
|
+
* This ensures secrets are available before any provider checks.
|
|
57
|
+
*
|
|
58
|
+
* IMPORTANT: Stored secrets always take precedence over environment variables
|
|
59
|
+
* for provider API keys. This ensures keys set via /secrets are used even if
|
|
60
|
+
* the user has old/stale keys exported in their shell environment.
|
|
61
|
+
*/
|
|
62
|
+
export function loadAllSecrets() {
|
|
63
|
+
const store = readSecretStore();
|
|
64
|
+
for (const definition of SECRET_DEFINITIONS) {
|
|
65
|
+
const storedValue = sanitize(store[definition.id]);
|
|
66
|
+
if (storedValue) {
|
|
67
|
+
// Always use stored value for API keys to ensure /secrets takes precedence
|
|
68
|
+
// over potentially stale environment variables
|
|
69
|
+
process.env[definition.id] = storedValue;
|
|
70
|
+
}
|
|
71
|
+
// No baked-in DeepSeek default (Project Glasswing — secrets never ship in
|
|
72
|
+
// source). The provider resolves credentials at runtime.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function setSecretValue(id, rawValue) {
|
|
76
|
+
const value = sanitize(rawValue);
|
|
77
|
+
if (!value) {
|
|
78
|
+
throw new Error('Secret value cannot be blank.');
|
|
79
|
+
}
|
|
80
|
+
const store = readSecretStore();
|
|
81
|
+
store[id] = value;
|
|
82
|
+
writeSecretStore(store);
|
|
83
|
+
process.env[id] = value;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Route a raw `/key` argument to the secret it sets, by prefix or explicit
|
|
87
|
+
* provider word. DeepSeek keys are `sk-…`, Tavily keys are `tvly-…`, so a bare
|
|
88
|
+
* key self-identifies; `/key tavily <k>` / `/key deepseek <k>` force it. Bare
|
|
89
|
+
* keys with no known prefix default to DeepSeek (back-compat — that was the
|
|
90
|
+
* only key `/key` ever set). Returns null for an empty/blank argument.
|
|
91
|
+
*/
|
|
92
|
+
export function classifyKeyEntry(raw) {
|
|
93
|
+
const trimmed = (raw || '').trim();
|
|
94
|
+
if (!trimmed)
|
|
95
|
+
return null;
|
|
96
|
+
const parts = trimmed.split(/\s+/);
|
|
97
|
+
const lead = (parts[0] || '').toLowerCase();
|
|
98
|
+
if (lead === 'tavily' || lead === 'tvly' || lead === 'search') {
|
|
99
|
+
const value = parts.slice(1).join(' ').trim();
|
|
100
|
+
return value ? { id: 'TAVILY_API_KEY', value } : null;
|
|
101
|
+
}
|
|
102
|
+
if (lead === 'deepseek' || lead === 'ds') {
|
|
103
|
+
const value = parts.slice(1).join(' ').trim();
|
|
104
|
+
return value ? { id: 'DEEPSEEK_API_KEY', value } : null;
|
|
105
|
+
}
|
|
106
|
+
if (/^tvly-/i.test(trimmed))
|
|
107
|
+
return { id: 'TAVILY_API_KEY', value: trimmed };
|
|
108
|
+
return { id: 'DEEPSEEK_API_KEY', value: trimmed };
|
|
109
|
+
}
|
|
110
|
+
export function maskSecret(value) {
|
|
111
|
+
if (!value) {
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
114
|
+
if (value.length <= 4) {
|
|
115
|
+
return '*'.repeat(value.length);
|
|
116
|
+
}
|
|
117
|
+
const suffix = value.slice(-4);
|
|
118
|
+
const prefix = '*'.repeat(Math.max(0, value.length - 4));
|
|
119
|
+
return `${prefix}${suffix}`;
|
|
120
|
+
}
|
|
121
|
+
export function ensureSecretForProvider(provider) {
|
|
122
|
+
const definition = findDefinitionForProvider(provider);
|
|
123
|
+
const value = getSecretValue(definition.id);
|
|
124
|
+
if (!value) {
|
|
125
|
+
throw new MissingSecretError(definition);
|
|
126
|
+
}
|
|
127
|
+
process.env[definition.envVar] = value;
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
export function getSecretDefinitionForProvider(provider) {
|
|
131
|
+
return SECRET_DEFINITIONS.find((entry) => entry.providers.includes(provider)) ?? null;
|
|
132
|
+
}
|
|
133
|
+
function readSecretStore() {
|
|
134
|
+
if (!existsSync(SECRET_FILE)) {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const content = readFileSync(SECRET_FILE, 'utf8');
|
|
139
|
+
const parsed = JSON.parse(content);
|
|
140
|
+
if (parsed && typeof parsed === 'object') {
|
|
141
|
+
return parsed;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return {};
|
|
146
|
+
}
|
|
147
|
+
return {};
|
|
148
|
+
}
|
|
149
|
+
function writeSecretStore(store) {
|
|
150
|
+
const directory = dirname(SECRET_FILE);
|
|
151
|
+
// Same posture as auth.ts: 0o700 on the dir, 0o600 on the file. The
|
|
152
|
+
// payload contains DeepSeek / Tavily / etc. API keys; on shared boxes
|
|
153
|
+
// anything looser leaves them readable to other local users.
|
|
154
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
155
|
+
const payload = JSON.stringify(store, null, 2);
|
|
156
|
+
// Atomic write: stage to a tmp file then rename. Without this, two
|
|
157
|
+
// concurrent CLIs writing the secret store at the same moment can
|
|
158
|
+
// produce a half-written file that subsequent reads parse as `{}`.
|
|
159
|
+
const tmp = `${SECRET_FILE}.${process.pid}.${Date.now()}.tmp`;
|
|
160
|
+
writeFileSync(tmp, `${payload}
|
|
161
|
+
`, { mode: 0o600 });
|
|
162
|
+
renameSync(tmp, SECRET_FILE);
|
|
163
|
+
}
|
|
164
|
+
function findDefinitionForProvider(provider) {
|
|
165
|
+
const definition = getSecretDefinitionForProvider(provider);
|
|
166
|
+
if (!definition) {
|
|
167
|
+
throw new Error(`No secret configuration for provider "${provider}".`);
|
|
168
|
+
}
|
|
169
|
+
return definition;
|
|
170
|
+
}
|
|
171
|
+
function sanitize(value) {
|
|
172
|
+
if (typeof value !== 'string') {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const trimmed = value.trim();
|
|
176
|
+
return trimmed.length ? trimmed : null;
|
|
177
|
+
}
|
|
178
|
+
// ============================================================================
|
|
179
|
+
// Secret Sanitization for Error Messages
|
|
180
|
+
// ============================================================================
|
|
181
|
+
/**
|
|
182
|
+
* Known API key patterns to detect and sanitize in error messages.
|
|
183
|
+
* These patterns match common API key formats from various providers.
|
|
184
|
+
*/
|
|
185
|
+
const API_KEY_PATTERNS = [
|
|
186
|
+
/Bearer\s+[A-Za-z0-9_.-]{20,}/gi,
|
|
187
|
+
/x-api-key['":\s]+[A-Za-z0-9_.-]{20,}/gi,
|
|
188
|
+
/[?&](?:key|api_key|apiKey|api-key|token|access_token)=([A-Za-z0-9_.-]{16,})/gi,
|
|
189
|
+
/sk-[a-f0-9]{32,}/gi,
|
|
190
|
+
/(?:api[_-]?key|token|secret|password|credential)['"]?\s*[:=]\s*['"]?([A-Za-z0-9_.-]{20,})['"]?/gi,
|
|
191
|
+
];
|
|
192
|
+
/**
|
|
193
|
+
* Sanitize error messages to remove potential API keys and secrets.
|
|
194
|
+
* This prevents accidental token leakage in logs, error reports, and console output.
|
|
195
|
+
*
|
|
196
|
+
* @param message - The error message or string to sanitize
|
|
197
|
+
* @returns The sanitized string with secrets replaced by [REDACTED]
|
|
198
|
+
*/
|
|
199
|
+
export function sanitizeErrorMessage(message) {
|
|
200
|
+
if (!message || typeof message !== 'string') {
|
|
201
|
+
return message;
|
|
202
|
+
}
|
|
203
|
+
let sanitized = message;
|
|
204
|
+
// Apply all API key patterns
|
|
205
|
+
for (const pattern of API_KEY_PATTERNS) {
|
|
206
|
+
// Reset lastIndex for global patterns
|
|
207
|
+
pattern.lastIndex = 0;
|
|
208
|
+
sanitized = sanitized.replace(pattern, (match) => {
|
|
209
|
+
// For patterns with capture groups, try to preserve context
|
|
210
|
+
if (match.includes('=') || match.includes(':')) {
|
|
211
|
+
const separator = match.includes('=') ? '=' : ':';
|
|
212
|
+
const parts = match.split(separator);
|
|
213
|
+
if (parts.length === 2) {
|
|
214
|
+
return `${parts[0]}${separator}[REDACTED]`;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return '[REDACTED]';
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
// Additionally sanitize any env var values that are currently loaded
|
|
221
|
+
sanitized = sanitizeAgainstLoadedSecrets(sanitized);
|
|
222
|
+
return sanitized;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Sanitize a string against currently loaded secret values.
|
|
226
|
+
* This catches any secrets that might not match the pattern-based detection.
|
|
227
|
+
*/
|
|
228
|
+
function sanitizeAgainstLoadedSecrets(message) {
|
|
229
|
+
const secretNames = [
|
|
230
|
+
'DEEPSEEK_API_KEY',
|
|
231
|
+
'TAVILY_API_KEY',
|
|
232
|
+
];
|
|
233
|
+
let sanitized = message;
|
|
234
|
+
for (const name of secretNames) {
|
|
235
|
+
const value = process.env[name];
|
|
236
|
+
if (value && value.length >= 4) {
|
|
237
|
+
// Only sanitize if the value appears in the message
|
|
238
|
+
// Use a case-sensitive exact match to avoid false positives
|
|
239
|
+
if (sanitized.includes(value)) {
|
|
240
|
+
sanitized = sanitized.split(value).join('[REDACTED]');
|
|
241
|
+
}
|
|
242
|
+
// Also sanitize partial matches (first 8 chars + last 4 chars pattern)
|
|
243
|
+
if (value.length >= 12) {
|
|
244
|
+
const partialPattern = `${value.substring(0, 8)}...${value.substring(value.length - 4)}`;
|
|
245
|
+
if (sanitized.includes(partialPattern)) {
|
|
246
|
+
sanitized = sanitized.split(partialPattern).join('[REDACTED_PARTIAL]');
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return sanitized;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Sanitize an Error object's message and stack trace.
|
|
255
|
+
* Returns a new error message string with secrets removed.
|
|
256
|
+
*/
|
|
257
|
+
export function sanitizeError(error) {
|
|
258
|
+
const message = sanitizeErrorMessage(error.message);
|
|
259
|
+
const stack = error.stack ? sanitizeErrorMessage(error.stack) : '';
|
|
260
|
+
if (stack && stack !== message) {
|
|
261
|
+
return `${message}\n${stack}`;
|
|
262
|
+
}
|
|
263
|
+
return message;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Create a safe error message from an unknown error value.
|
|
267
|
+
* Ensures no secrets are leaked regardless of error type.
|
|
268
|
+
*/
|
|
269
|
+
export function safeErrorMessage(error) {
|
|
270
|
+
if (error instanceof Error) {
|
|
271
|
+
return sanitizeErrorMessage(error.message);
|
|
272
|
+
}
|
|
273
|
+
if (typeof error === 'string') {
|
|
274
|
+
return sanitizeErrorMessage(error);
|
|
275
|
+
}
|
|
276
|
+
return 'Unknown error occurred';
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=secretStore.js.map
|