@dexto/core 1.1.11 → 1.2.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/README.md +24 -4
- package/dist/Dexto.cjs +4 -14
- package/dist/Dexto.d.ts +8 -29
- package/dist/Dexto.d.ts.map +1 -1
- package/dist/Dexto.js +4 -12
- package/dist/agent/DextoAgent.cjs +92 -3
- package/dist/agent/DextoAgent.d.ts +12 -4
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +52 -3
- package/dist/agent/agentCard.js +1 -0
- package/dist/agent/error-codes.cjs +1 -0
- package/dist/agent/error-codes.d.ts +1 -0
- package/dist/agent/error-codes.d.ts.map +1 -1
- package/dist/agent/error-codes.js +2 -0
- package/dist/agent/errors.cjs +13 -0
- package/dist/agent/errors.d.ts +4 -0
- package/dist/agent/errors.d.ts.map +1 -1
- package/dist/agent/errors.js +14 -0
- package/dist/agent/index.js +1 -0
- package/dist/agent/registry/error-codes.js +1 -0
- package/dist/agent/registry/errors.js +1 -0
- package/dist/agent/registry/registry.js +1 -0
- package/dist/agent/registry/types.js +1 -0
- package/dist/agent/registry/user-registry.js +1 -0
- package/dist/agent/schemas.cjs +6 -1
- package/dist/agent/schemas.d.ts +113 -3
- package/dist/agent/schemas.d.ts.map +1 -1
- package/dist/agent/schemas.js +7 -1
- package/dist/agent/state-manager.js +1 -0
- package/dist/approval/error-codes.js +1 -0
- package/dist/approval/errors.js +1 -0
- package/dist/approval/index.js +1 -0
- package/dist/approval/manager.cjs +30 -0
- package/dist/approval/manager.d.ts +23 -1
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +31 -0
- package/dist/approval/providers/event-based-approval-provider.js +1 -0
- package/dist/approval/providers/factory.js +1 -0
- package/dist/approval/providers/noop-approval-provider.js +1 -0
- package/dist/approval/schemas.cjs +36 -0
- package/dist/approval/schemas.d.ts +173 -0
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +33 -0
- package/dist/approval/types.cjs +1 -0
- package/dist/approval/types.d.ts +27 -1
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/approval/types.js +2 -0
- package/dist/chunk-C6A6W6XS.js +53 -0
- package/dist/config/agent-resolver.js +1 -0
- package/dist/config/error-codes.js +1 -0
- package/dist/config/errors.js +1 -0
- package/dist/config/loader.js +1 -0
- package/dist/config/writer.js +1 -0
- package/dist/context/compression/middle-removal.js +1 -0
- package/dist/context/compression/oldest-removal.js +1 -0
- package/dist/context/error-codes.js +1 -0
- package/dist/context/errors.js +1 -0
- package/dist/context/index.js +1 -0
- package/dist/context/manager.cjs +36 -1
- package/dist/context/manager.d.ts.map +1 -1
- package/dist/context/manager.js +27 -1
- package/dist/context/media-helpers.js +1 -0
- package/dist/context/utils.cjs +102 -6
- package/dist/context/utils.d.ts +35 -2
- package/dist/context/utils.d.ts.map +1 -1
- package/dist/context/utils.js +100 -6
- package/dist/errors/DextoBaseError.js +1 -0
- package/dist/errors/DextoRuntimeError.js +1 -0
- package/dist/errors/DextoValidationError.js +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/errors/result-bridge.js +1 -0
- package/dist/errors/types.cjs +3 -0
- package/dist/errors/types.d.ts +7 -2
- package/dist/errors/types.d.ts.map +1 -1
- package/dist/errors/types.js +4 -0
- package/dist/events/index.cjs +1 -0
- package/dist/events/index.d.ts +6 -2
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +2 -0
- package/dist/filesystem/error-codes.cjs +53 -0
- package/dist/filesystem/error-codes.d.ts +31 -0
- package/dist/filesystem/error-codes.d.ts.map +1 -0
- package/dist/filesystem/error-codes.js +30 -0
- package/dist/filesystem/errors.cjs +303 -0
- package/dist/filesystem/errors.d.ts +109 -0
- package/dist/filesystem/errors.d.ts.map +1 -0
- package/dist/filesystem/errors.js +280 -0
- package/dist/filesystem/filesystem-service.cjs +482 -0
- package/dist/filesystem/filesystem-service.d.ts +57 -0
- package/dist/filesystem/filesystem-service.d.ts.map +1 -0
- package/dist/filesystem/filesystem-service.js +449 -0
- package/dist/filesystem/index.cjs +37 -0
- package/dist/filesystem/index.d.ts +11 -0
- package/dist/filesystem/index.d.ts.map +1 -0
- package/dist/filesystem/index.js +11 -0
- package/dist/filesystem/path-validator.cjs +172 -0
- package/dist/filesystem/path-validator.d.ts +53 -0
- package/dist/filesystem/path-validator.d.ts.map +1 -0
- package/dist/filesystem/path-validator.js +139 -0
- package/dist/filesystem/types.cjs +16 -0
- package/dist/filesystem/types.d.ts +171 -0
- package/dist/filesystem/types.d.ts.map +1 -0
- package/dist/filesystem/types.js +0 -0
- package/dist/index.browser.js +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/llm/error-codes.js +1 -0
- package/dist/llm/errors.js +1 -0
- package/dist/llm/formatters/anthropic.js +1 -0
- package/dist/llm/formatters/factory.js +1 -0
- package/dist/llm/formatters/openai.js +1 -0
- package/dist/llm/formatters/vercel.js +1 -0
- package/dist/llm/registry.cjs +15 -15
- package/dist/llm/registry.d.ts +1 -1
- package/dist/llm/registry.js +16 -15
- package/dist/llm/resolver.js +1 -0
- package/dist/llm/schemas.cjs +6 -2
- package/dist/llm/schemas.d.ts +10 -0
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/schemas.js +7 -2
- package/dist/llm/services/anthropic.cjs +67 -0
- package/dist/llm/services/anthropic.d.ts +6 -0
- package/dist/llm/services/anthropic.d.ts.map +1 -1
- package/dist/llm/services/anthropic.js +27 -0
- package/dist/llm/services/factory.js +1 -0
- package/dist/llm/services/openai.cjs +87 -0
- package/dist/llm/services/openai.d.ts +6 -0
- package/dist/llm/services/openai.d.ts.map +1 -1
- package/dist/llm/services/openai.js +47 -0
- package/dist/llm/services/test-utils.integration.cjs +1 -1
- package/dist/llm/services/test-utils.integration.js +2 -1
- package/dist/llm/services/vercel.cjs +144 -97
- package/dist/llm/services/vercel.d.ts +6 -1
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +105 -98
- package/dist/llm/tokenizer/anthropic.js +1 -0
- package/dist/llm/tokenizer/default.js +1 -0
- package/dist/llm/tokenizer/factory.js +1 -0
- package/dist/llm/tokenizer/google.js +1 -0
- package/dist/llm/tokenizer/openai.cjs +1 -1
- package/dist/llm/tokenizer/openai.d.ts +1 -1
- package/dist/llm/tokenizer/openai.js +2 -1
- package/dist/llm/tokenizer/types.js +1 -0
- package/dist/llm/types.d.ts +2 -2
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/llm/types.js +1 -0
- package/dist/llm/validation.js +1 -0
- package/dist/logger/browser.js +1 -0
- package/dist/logger/logger.d.ts +42 -0
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +1 -0
- package/dist/mcp/error-codes.cjs +1 -0
- package/dist/mcp/error-codes.d.ts +1 -0
- package/dist/mcp/error-codes.d.ts.map +1 -1
- package/dist/mcp/error-codes.js +2 -0
- package/dist/mcp/errors.cjs +12 -0
- package/dist/mcp/errors.d.ts +7 -0
- package/dist/mcp/errors.d.ts.map +1 -1
- package/dist/mcp/errors.js +13 -0
- package/dist/mcp/manager.cjs +66 -16
- package/dist/mcp/manager.d.ts +7 -0
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +67 -16
- package/dist/mcp/mcp-client.js +1 -0
- package/dist/mcp/resolver.js +1 -0
- package/dist/mcp/schemas.js +1 -0
- package/dist/mcp/types.d.ts +1 -1
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/memory/error-codes.js +1 -0
- package/dist/memory/errors.js +1 -0
- package/dist/memory/index.js +1 -0
- package/dist/memory/manager.js +1 -0
- package/dist/memory/schemas.js +1 -0
- package/dist/plugins/builtins/content-policy.js +1 -0
- package/dist/plugins/builtins/response-sanitizer.js +1 -0
- package/dist/plugins/error-codes.js +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/loader.js +1 -0
- package/dist/plugins/manager.js +1 -0
- package/dist/plugins/registrations/builtins.js +1 -0
- package/dist/plugins/schemas.js +1 -0
- package/dist/preferences/constants.js +1 -0
- package/dist/preferences/error-codes.js +1 -0
- package/dist/preferences/errors.js +1 -0
- package/dist/preferences/index.js +1 -0
- package/dist/preferences/loader.cjs +3 -1
- package/dist/preferences/loader.d.ts +10 -1
- package/dist/preferences/loader.d.ts.map +1 -1
- package/dist/preferences/loader.js +4 -1
- package/dist/preferences/schemas.cjs +2 -1
- package/dist/preferences/schemas.d.ts +8 -0
- package/dist/preferences/schemas.d.ts.map +1 -1
- package/dist/preferences/schemas.js +3 -1
- package/dist/process/command-validator.cjs +544 -0
- package/dist/process/command-validator.d.ts +46 -0
- package/dist/process/command-validator.d.ts.map +1 -0
- package/dist/process/command-validator.js +521 -0
- package/dist/process/error-codes.cjs +47 -0
- package/dist/process/error-codes.d.ts +25 -0
- package/dist/process/error-codes.d.ts.map +1 -0
- package/dist/process/error-codes.js +24 -0
- package/dist/process/errors.cjs +244 -0
- package/dist/process/errors.d.ts +87 -0
- package/dist/process/errors.d.ts.map +1 -0
- package/dist/process/errors.js +221 -0
- package/dist/process/index.cjs +37 -0
- package/dist/process/index.d.ts +11 -0
- package/dist/process/index.d.ts.map +1 -0
- package/dist/process/index.js +11 -0
- package/dist/process/process-service.cjs +443 -0
- package/dist/process/process-service.d.ts +62 -0
- package/dist/process/process-service.d.ts.map +1 -0
- package/dist/process/process-service.js +410 -0
- package/dist/process/types.cjs +16 -0
- package/dist/process/types.d.ts +107 -0
- package/dist/process/types.d.ts.map +1 -0
- package/dist/process/types.js +0 -0
- package/dist/prompts/error-codes.js +1 -0
- package/dist/prompts/errors.js +1 -0
- package/dist/prompts/index.js +1 -0
- package/dist/prompts/name-validation.js +1 -0
- package/dist/prompts/prompt-manager.js +1 -0
- package/dist/prompts/providers/custom-prompt-provider.js +1 -0
- package/dist/prompts/providers/file-prompt-provider.js +1 -0
- package/dist/prompts/providers/mcp-prompt-provider.js +1 -0
- package/dist/prompts/providers/starter-prompt-provider.js +1 -0
- package/dist/prompts/schemas.js +1 -0
- package/dist/prompts/utils.js +1 -0
- package/dist/resources/error-codes.js +1 -0
- package/dist/resources/errors.js +1 -0
- package/dist/resources/handlers/blob-handler.js +1 -0
- package/dist/resources/handlers/factory.js +1 -0
- package/dist/resources/handlers/filesystem-handler.cjs +1 -1
- package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
- package/dist/resources/handlers/filesystem-handler.js +2 -1
- package/dist/resources/index.js +1 -0
- package/dist/resources/internal-provider.js +1 -0
- package/dist/resources/manager.js +1 -0
- package/dist/resources/reference-parser.js +1 -0
- package/dist/resources/schemas.js +1 -0
- package/dist/search/index.js +1 -0
- package/dist/search/search-service.js +1 -0
- package/dist/session/chat-session.cjs +2 -2
- package/dist/session/chat-session.d.ts +2 -2
- package/dist/session/chat-session.js +3 -2
- package/dist/session/error-codes.js +1 -0
- package/dist/session/errors.js +1 -0
- package/dist/session/history/database.js +1 -0
- package/dist/session/history/factory.js +1 -0
- package/dist/session/history/memory.js +1 -0
- package/dist/session/index.js +1 -0
- package/dist/session/schemas.js +1 -0
- package/dist/session/session-manager.d.ts +6 -0
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +1 -0
- package/dist/session/title-generator.js +1 -0
- package/dist/storage/blob/factory.cjs +3 -3
- package/dist/storage/blob/factory.d.ts +3 -1
- package/dist/storage/blob/factory.d.ts.map +1 -1
- package/dist/storage/blob/factory.js +4 -3
- package/dist/storage/blob/local-blob-store.cjs +18 -2
- package/dist/storage/blob/local-blob-store.d.ts +2 -1
- package/dist/storage/blob/local-blob-store.d.ts.map +1 -1
- package/dist/storage/blob/local-blob-store.js +19 -2
- package/dist/storage/blob/schemas.js +1 -0
- package/dist/storage/cache/factory.js +1 -0
- package/dist/storage/cache/memory-cache-store.js +1 -0
- package/dist/storage/cache/redis-store.js +1 -0
- package/dist/storage/cache/schemas.js +1 -0
- package/dist/storage/database/factory.cjs +7 -5
- package/dist/storage/database/factory.d.ts +3 -1
- package/dist/storage/database/factory.d.ts.map +1 -1
- package/dist/storage/database/factory.js +8 -5
- package/dist/storage/database/memory-database-store.js +1 -0
- package/dist/storage/database/postgres-store.js +1 -0
- package/dist/storage/database/schemas.cjs +1 -1
- package/dist/storage/database/schemas.js +2 -1
- package/dist/storage/database/sqlite-store.cjs +20 -2
- package/dist/storage/database/sqlite-store.d.ts +2 -1
- package/dist/storage/database/sqlite-store.d.ts.map +1 -1
- package/dist/storage/database/sqlite-store.js +21 -2
- package/dist/storage/error-codes.cjs +1 -0
- package/dist/storage/error-codes.d.ts +1 -0
- package/dist/storage/error-codes.d.ts.map +1 -1
- package/dist/storage/error-codes.js +2 -0
- package/dist/storage/errors.cjs +15 -0
- package/dist/storage/errors.d.ts +4 -0
- package/dist/storage/errors.d.ts.map +1 -1
- package/dist/storage/errors.js +16 -0
- package/dist/storage/index.js +1 -0
- package/dist/storage/schemas.js +1 -0
- package/dist/storage/storage-manager.cjs +7 -5
- package/dist/storage/storage-manager.d.ts +5 -2
- package/dist/storage/storage-manager.d.ts.map +1 -1
- package/dist/storage/storage-manager.js +8 -5
- package/dist/systemPrompt/contributors.js +1 -0
- package/dist/systemPrompt/error-codes.js +1 -0
- package/dist/systemPrompt/errors.js +1 -0
- package/dist/systemPrompt/in-built-prompts.js +1 -0
- package/dist/systemPrompt/index.js +1 -0
- package/dist/systemPrompt/manager.js +1 -0
- package/dist/systemPrompt/registry.js +1 -0
- package/dist/systemPrompt/schemas.js +1 -0
- package/dist/telemetry/decorators.cjs +175 -0
- package/dist/telemetry/decorators.d.ts +17 -0
- package/dist/telemetry/decorators.d.ts.map +1 -0
- package/dist/telemetry/decorators.js +157 -0
- package/dist/telemetry/exporters.cjs +108 -0
- package/dist/telemetry/exporters.d.ts +29 -0
- package/dist/telemetry/exporters.d.ts.map +1 -0
- package/dist/telemetry/exporters.js +85 -0
- package/dist/telemetry/index.cjs +28 -0
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +5 -0
- package/dist/telemetry/schemas.cjs +71 -0
- package/dist/telemetry/schemas.d.ts +54 -0
- package/dist/telemetry/schemas.d.ts.map +1 -0
- package/dist/telemetry/schemas.js +48 -0
- package/dist/telemetry/telemetry.cjs +228 -0
- package/dist/telemetry/telemetry.d.ts +74 -0
- package/dist/telemetry/telemetry.d.ts.map +1 -0
- package/dist/telemetry/telemetry.js +205 -0
- package/dist/telemetry/types.cjs +16 -0
- package/dist/telemetry/types.d.ts +22 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/telemetry/types.js +0 -0
- package/dist/telemetry/utils.cjs +87 -0
- package/dist/telemetry/utils.d.ts +21 -0
- package/dist/telemetry/utils.d.ts.map +1 -0
- package/dist/telemetry/utils.js +62 -0
- package/dist/tools/confirmation/allowed-tools-provider/factory.js +1 -0
- package/dist/tools/confirmation/allowed-tools-provider/in-memory.js +1 -0
- package/dist/tools/confirmation/allowed-tools-provider/storage.js +1 -0
- package/dist/tools/error-codes.js +1 -0
- package/dist/tools/errors.js +1 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/internal-tools/constants.cjs +39 -0
- package/dist/tools/internal-tools/constants.d.ts +12 -0
- package/dist/tools/internal-tools/constants.d.ts.map +1 -0
- package/dist/tools/internal-tools/constants.js +16 -0
- package/dist/tools/internal-tools/implementations/ask-user-tool.js +1 -0
- package/dist/tools/internal-tools/implementations/bash-exec-tool.cjs +106 -0
- package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts +13 -0
- package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/bash-exec-tool.js +73 -0
- package/dist/tools/internal-tools/implementations/bash-output-tool.cjs +49 -0
- package/dist/tools/internal-tools/implementations/bash-output-tool.d.ts +12 -0
- package/dist/tools/internal-tools/implementations/bash-output-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/bash-output-tool.js +26 -0
- package/dist/tools/internal-tools/implementations/edit-file-tool.cjs +62 -0
- package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts +12 -0
- package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/edit-file-tool.js +39 -0
- package/dist/tools/internal-tools/implementations/glob-files-tool.cjs +57 -0
- package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts +12 -0
- package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/glob-files-tool.js +34 -0
- package/dist/tools/internal-tools/implementations/grep-content-tool.cjs +71 -0
- package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts +12 -0
- package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/grep-content-tool.js +48 -0
- package/dist/tools/internal-tools/implementations/kill-process-tool.cjs +47 -0
- package/dist/tools/internal-tools/implementations/kill-process-tool.d.ts +12 -0
- package/dist/tools/internal-tools/implementations/kill-process-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/kill-process-tool.js +24 -0
- package/dist/tools/internal-tools/implementations/read-file-tool.cjs +55 -0
- package/dist/tools/internal-tools/implementations/read-file-tool.d.ts +12 -0
- package/dist/tools/internal-tools/implementations/read-file-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/read-file-tool.js +32 -0
- package/dist/tools/internal-tools/implementations/search-history-tool.js +1 -0
- package/dist/tools/internal-tools/implementations/write-file-tool.cjs +56 -0
- package/dist/tools/internal-tools/implementations/write-file-tool.d.ts +12 -0
- package/dist/tools/internal-tools/implementations/write-file-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/write-file-tool.js +33 -0
- package/dist/tools/internal-tools/index.cjs +3 -1
- package/dist/tools/internal-tools/index.d.ts +1 -0
- package/dist/tools/internal-tools/index.d.ts.map +1 -1
- package/dist/tools/internal-tools/index.js +1 -0
- package/dist/tools/internal-tools/provider.js +1 -0
- package/dist/tools/internal-tools/registry.cjs +40 -4
- package/dist/tools/internal-tools/registry.d.ts +5 -9
- package/dist/tools/internal-tools/registry.d.ts.map +1 -1
- package/dist/tools/internal-tools/registry.js +41 -3
- package/dist/tools/schemas.cjs +18 -5
- package/dist/tools/schemas.d.ts +30 -1
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +15 -2
- package/dist/tools/tool-manager.cjs +158 -19
- package/dist/tools/tool-manager.d.ts +48 -2
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +118 -19
- package/dist/utils/api-key-resolver.js +1 -0
- package/dist/utils/api-key-store.js +1 -0
- package/dist/utils/async-context.js +1 -0
- package/dist/utils/debug.js +1 -0
- package/dist/utils/env.js +1 -0
- package/dist/utils/error-conversion.js +1 -0
- package/dist/utils/execution-context.js +1 -0
- package/dist/utils/fs-walk.js +1 -0
- package/dist/utils/path.js +1 -0
- package/dist/utils/port-utils.js +1 -0
- package/dist/utils/redactor.js +1 -0
- package/dist/utils/result.js +1 -0
- package/dist/utils/safe-stringify.js +1 -0
- package/dist/utils/schema-metadata.js +1 -0
- package/dist/utils/schema.js +1 -0
- package/dist/utils/service-initializer.cjs +42 -4
- package/dist/utils/service-initializer.d.ts +2 -1
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/dist/utils/service-initializer.js +33 -4
- package/dist/utils/user-info.js +1 -0
- package/dist/utils/zod-schema-converter.js +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import "../chunk-C6A6W6XS.js";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { glob } from "glob";
|
|
5
|
+
import { PathValidator } from "./path-validator.js";
|
|
6
|
+
import { FileSystemError } from "./errors.js";
|
|
7
|
+
import { logger } from "../logger/index.js";
|
|
8
|
+
const DEFAULT_ENCODING = "utf-8";
|
|
9
|
+
const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
10
|
+
const DEFAULT_MAX_RESULTS = 1e3;
|
|
11
|
+
const DEFAULT_MAX_SEARCH_RESULTS = 100;
|
|
12
|
+
class FileSystemService {
|
|
13
|
+
config;
|
|
14
|
+
pathValidator;
|
|
15
|
+
initialized = false;
|
|
16
|
+
constructor(config = {}) {
|
|
17
|
+
this.config = {
|
|
18
|
+
allowedPaths: config.allowedPaths || ["."],
|
|
19
|
+
blockedPaths: config.blockedPaths || [".git", "node_modules/.bin", ".env"],
|
|
20
|
+
blockedExtensions: config.blockedExtensions || [".exe", ".dll", ".so"],
|
|
21
|
+
maxFileSize: config.maxFileSize || DEFAULT_MAX_FILE_SIZE,
|
|
22
|
+
enableBackups: config.enableBackups ?? true,
|
|
23
|
+
backupPath: config.backupPath || ".dexto/backups",
|
|
24
|
+
backupRetentionDays: config.backupRetentionDays || 7,
|
|
25
|
+
workingDirectory: config.workingDirectory
|
|
26
|
+
};
|
|
27
|
+
this.pathValidator = new PathValidator(this.config);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the service
|
|
31
|
+
*/
|
|
32
|
+
async initialize() {
|
|
33
|
+
if (this.initialized) {
|
|
34
|
+
logger.debug("FileSystemService already initialized");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (this.config.enableBackups) {
|
|
38
|
+
try {
|
|
39
|
+
const backupDir = path.resolve(
|
|
40
|
+
this.config.workingDirectory || process.cwd(),
|
|
41
|
+
this.config.backupPath
|
|
42
|
+
);
|
|
43
|
+
await fs.mkdir(backupDir, { recursive: true });
|
|
44
|
+
logger.debug(`Backup directory created/verified: ${backupDir}`);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
logger.warn(
|
|
47
|
+
`Failed to create backup directory: ${error instanceof Error ? error.message : String(error)}`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
this.initialized = true;
|
|
52
|
+
logger.info("FileSystemService initialized successfully");
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Read a file with validation and size limits
|
|
56
|
+
*/
|
|
57
|
+
async readFile(filePath, options = {}) {
|
|
58
|
+
if (!this.initialized) {
|
|
59
|
+
throw FileSystemError.notInitialized();
|
|
60
|
+
}
|
|
61
|
+
const validation = this.pathValidator.validatePath(filePath);
|
|
62
|
+
if (!validation.isValid || !validation.normalizedPath) {
|
|
63
|
+
throw FileSystemError.invalidPath(filePath, validation.error || "Unknown error");
|
|
64
|
+
}
|
|
65
|
+
const normalizedPath = validation.normalizedPath;
|
|
66
|
+
try {
|
|
67
|
+
const stats = await fs.stat(normalizedPath);
|
|
68
|
+
if (!stats.isFile()) {
|
|
69
|
+
throw FileSystemError.invalidPath(normalizedPath, "Path is not a file");
|
|
70
|
+
}
|
|
71
|
+
if (stats.size > this.config.maxFileSize) {
|
|
72
|
+
throw FileSystemError.fileTooLarge(
|
|
73
|
+
normalizedPath,
|
|
74
|
+
stats.size,
|
|
75
|
+
this.config.maxFileSize
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error.code === "ENOENT") {
|
|
80
|
+
throw FileSystemError.fileNotFound(normalizedPath);
|
|
81
|
+
}
|
|
82
|
+
if (error.code === "EACCES") {
|
|
83
|
+
throw FileSystemError.permissionDenied(normalizedPath, "read");
|
|
84
|
+
}
|
|
85
|
+
throw FileSystemError.readFailed(
|
|
86
|
+
normalizedPath,
|
|
87
|
+
error instanceof Error ? error.message : String(error)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const encoding = options.encoding || DEFAULT_ENCODING;
|
|
92
|
+
const content = await fs.readFile(normalizedPath, encoding);
|
|
93
|
+
const lines = content.split("\n");
|
|
94
|
+
const limit = options.limit;
|
|
95
|
+
const offset1 = options.offset;
|
|
96
|
+
let selectedLines;
|
|
97
|
+
let truncated = false;
|
|
98
|
+
if (offset1 && offset1 > 0 || limit !== void 0) {
|
|
99
|
+
const start = offset1 && offset1 > 0 ? Math.max(0, offset1 - 1) : 0;
|
|
100
|
+
const end = limit !== void 0 ? start + limit : lines.length;
|
|
101
|
+
selectedLines = lines.slice(start, end);
|
|
102
|
+
truncated = end < lines.length;
|
|
103
|
+
} else {
|
|
104
|
+
selectedLines = lines;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
content: selectedLines.join("\n"),
|
|
108
|
+
lines: selectedLines.length,
|
|
109
|
+
encoding,
|
|
110
|
+
truncated,
|
|
111
|
+
size: Buffer.byteLength(content, encoding)
|
|
112
|
+
};
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw FileSystemError.readFailed(
|
|
115
|
+
normalizedPath,
|
|
116
|
+
error instanceof Error ? error.message : String(error)
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Find files matching a glob pattern
|
|
122
|
+
*/
|
|
123
|
+
async globFiles(pattern, options = {}) {
|
|
124
|
+
if (!this.initialized) {
|
|
125
|
+
throw FileSystemError.notInitialized();
|
|
126
|
+
}
|
|
127
|
+
const cwd = options.cwd || this.config.workingDirectory || process.cwd();
|
|
128
|
+
const maxResults = options.maxResults || DEFAULT_MAX_RESULTS;
|
|
129
|
+
try {
|
|
130
|
+
const files = await glob(pattern, {
|
|
131
|
+
cwd,
|
|
132
|
+
absolute: true,
|
|
133
|
+
nodir: true,
|
|
134
|
+
// Only files
|
|
135
|
+
follow: false
|
|
136
|
+
// Don't follow symlinks
|
|
137
|
+
});
|
|
138
|
+
const validFiles = [];
|
|
139
|
+
for (const file of files) {
|
|
140
|
+
const validation = this.pathValidator.validatePath(file);
|
|
141
|
+
if (!validation.isValid || !validation.normalizedPath) {
|
|
142
|
+
logger.debug(`Skipping invalid path: ${file}`);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (options.includeMetadata !== false) {
|
|
146
|
+
try {
|
|
147
|
+
const stats = await fs.stat(validation.normalizedPath);
|
|
148
|
+
validFiles.push({
|
|
149
|
+
path: validation.normalizedPath,
|
|
150
|
+
size: stats.size,
|
|
151
|
+
modified: stats.mtime,
|
|
152
|
+
isDirectory: stats.isDirectory()
|
|
153
|
+
});
|
|
154
|
+
} catch (error) {
|
|
155
|
+
logger.debug(
|
|
156
|
+
`Failed to stat file ${file}: ${error instanceof Error ? error.message : String(error)}`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
validFiles.push({
|
|
161
|
+
path: validation.normalizedPath,
|
|
162
|
+
size: 0,
|
|
163
|
+
modified: /* @__PURE__ */ new Date(),
|
|
164
|
+
isDirectory: false
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (validFiles.length >= maxResults) {
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const limited = validFiles.length >= maxResults;
|
|
172
|
+
return {
|
|
173
|
+
files: validFiles,
|
|
174
|
+
truncated: limited,
|
|
175
|
+
totalFound: validFiles.length
|
|
176
|
+
};
|
|
177
|
+
} catch (error) {
|
|
178
|
+
throw FileSystemError.globFailed(
|
|
179
|
+
pattern,
|
|
180
|
+
error instanceof Error ? error.message : String(error)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Search for content in files (grep-like functionality)
|
|
186
|
+
*/
|
|
187
|
+
async searchContent(pattern, options = {}) {
|
|
188
|
+
if (!this.initialized) {
|
|
189
|
+
throw FileSystemError.notInitialized();
|
|
190
|
+
}
|
|
191
|
+
const searchPath = options.path || this.config.workingDirectory || process.cwd();
|
|
192
|
+
const globPattern = options.glob || "**/*";
|
|
193
|
+
const maxResults = options.maxResults || DEFAULT_MAX_SEARCH_RESULTS;
|
|
194
|
+
const contextLines = options.contextLines || 0;
|
|
195
|
+
try {
|
|
196
|
+
const flags = options.caseInsensitive ? "i" : "";
|
|
197
|
+
const regex = new RegExp(pattern, flags);
|
|
198
|
+
const globResult = await this.globFiles(globPattern, {
|
|
199
|
+
cwd: searchPath,
|
|
200
|
+
maxResults: 1e4
|
|
201
|
+
// Search more files, but limit results
|
|
202
|
+
});
|
|
203
|
+
const matches = [];
|
|
204
|
+
let filesSearched = 0;
|
|
205
|
+
for (const fileInfo of globResult.files) {
|
|
206
|
+
try {
|
|
207
|
+
const fileContent = await this.readFile(fileInfo.path);
|
|
208
|
+
const lines = fileContent.content.split("\n");
|
|
209
|
+
filesSearched++;
|
|
210
|
+
for (let i = 0; i < lines.length; i++) {
|
|
211
|
+
const line = lines[i];
|
|
212
|
+
if (regex.test(line)) {
|
|
213
|
+
let context;
|
|
214
|
+
if (contextLines > 0) {
|
|
215
|
+
const before = [];
|
|
216
|
+
const after = [];
|
|
217
|
+
for (let j = Math.max(0, i - contextLines); j < i; j++) {
|
|
218
|
+
before.push(lines[j]);
|
|
219
|
+
}
|
|
220
|
+
for (let j = i + 1; j < Math.min(lines.length, i + contextLines + 1); j++) {
|
|
221
|
+
after.push(lines[j]);
|
|
222
|
+
}
|
|
223
|
+
context = { before, after };
|
|
224
|
+
}
|
|
225
|
+
matches.push({
|
|
226
|
+
file: fileInfo.path,
|
|
227
|
+
lineNumber: i + 1,
|
|
228
|
+
// 1-based line numbers
|
|
229
|
+
line,
|
|
230
|
+
...context !== void 0 && { context }
|
|
231
|
+
});
|
|
232
|
+
if (matches.length >= maxResults) {
|
|
233
|
+
return {
|
|
234
|
+
matches,
|
|
235
|
+
totalMatches: matches.length,
|
|
236
|
+
truncated: true,
|
|
237
|
+
filesSearched
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
} catch (error) {
|
|
243
|
+
logger.debug(
|
|
244
|
+
`Skipping file ${fileInfo.path}: ${error instanceof Error ? error.message : String(error)}`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
matches,
|
|
250
|
+
totalMatches: matches.length,
|
|
251
|
+
truncated: false,
|
|
252
|
+
filesSearched
|
|
253
|
+
};
|
|
254
|
+
} catch (error) {
|
|
255
|
+
if (error instanceof Error && error.message.includes("Invalid regular expression")) {
|
|
256
|
+
throw FileSystemError.invalidPattern(pattern, "Invalid regular expression syntax");
|
|
257
|
+
}
|
|
258
|
+
throw FileSystemError.searchFailed(
|
|
259
|
+
pattern,
|
|
260
|
+
error instanceof Error ? error.message : String(error)
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Write content to a file
|
|
266
|
+
*/
|
|
267
|
+
async writeFile(filePath, content, options = {}) {
|
|
268
|
+
if (!this.initialized) {
|
|
269
|
+
throw FileSystemError.notInitialized();
|
|
270
|
+
}
|
|
271
|
+
const validation = this.pathValidator.validatePath(filePath);
|
|
272
|
+
if (!validation.isValid || !validation.normalizedPath) {
|
|
273
|
+
throw FileSystemError.invalidPath(filePath, validation.error || "Unknown error");
|
|
274
|
+
}
|
|
275
|
+
const normalizedPath = validation.normalizedPath;
|
|
276
|
+
const encoding = options.encoding || DEFAULT_ENCODING;
|
|
277
|
+
let backupPath;
|
|
278
|
+
let fileExists = false;
|
|
279
|
+
try {
|
|
280
|
+
await fs.access(normalizedPath);
|
|
281
|
+
fileExists = true;
|
|
282
|
+
} catch {
|
|
283
|
+
}
|
|
284
|
+
if (fileExists && (options.backup ?? this.config.enableBackups)) {
|
|
285
|
+
backupPath = await this.createBackup(normalizedPath);
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
if (options.createDirs) {
|
|
289
|
+
const dir = path.dirname(normalizedPath);
|
|
290
|
+
await fs.mkdir(dir, { recursive: true });
|
|
291
|
+
}
|
|
292
|
+
await fs.writeFile(normalizedPath, content, encoding);
|
|
293
|
+
const bytesWritten = Buffer.byteLength(content, encoding);
|
|
294
|
+
logger.debug(`File written: ${normalizedPath} (${bytesWritten} bytes)`);
|
|
295
|
+
return {
|
|
296
|
+
success: true,
|
|
297
|
+
path: normalizedPath,
|
|
298
|
+
bytesWritten,
|
|
299
|
+
backupPath
|
|
300
|
+
};
|
|
301
|
+
} catch (error) {
|
|
302
|
+
throw FileSystemError.writeFailed(
|
|
303
|
+
normalizedPath,
|
|
304
|
+
error instanceof Error ? error.message : String(error)
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Edit a file by replacing text
|
|
310
|
+
*/
|
|
311
|
+
async editFile(filePath, operation, options = {}) {
|
|
312
|
+
if (!this.initialized) {
|
|
313
|
+
throw FileSystemError.notInitialized();
|
|
314
|
+
}
|
|
315
|
+
const validation = this.pathValidator.validatePath(filePath);
|
|
316
|
+
if (!validation.isValid || !validation.normalizedPath) {
|
|
317
|
+
throw FileSystemError.invalidPath(filePath, validation.error || "Unknown error");
|
|
318
|
+
}
|
|
319
|
+
const normalizedPath = validation.normalizedPath;
|
|
320
|
+
const fileContent = await this.readFile(normalizedPath);
|
|
321
|
+
let content = fileContent.content;
|
|
322
|
+
const occurrences = (content.match(
|
|
323
|
+
new RegExp(operation.oldString.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g")
|
|
324
|
+
) || []).length;
|
|
325
|
+
if (occurrences === 0) {
|
|
326
|
+
throw FileSystemError.stringNotFound(normalizedPath, operation.oldString);
|
|
327
|
+
}
|
|
328
|
+
if (!operation.replaceAll && occurrences > 1) {
|
|
329
|
+
throw FileSystemError.stringNotUnique(normalizedPath, operation.oldString, occurrences);
|
|
330
|
+
}
|
|
331
|
+
let backupPath;
|
|
332
|
+
if (options.backup ?? this.config.enableBackups) {
|
|
333
|
+
backupPath = await this.createBackup(normalizedPath);
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
if (operation.replaceAll) {
|
|
337
|
+
content = content.replace(
|
|
338
|
+
new RegExp(operation.oldString.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
|
|
339
|
+
operation.newString
|
|
340
|
+
);
|
|
341
|
+
} else {
|
|
342
|
+
content = content.replace(operation.oldString, operation.newString);
|
|
343
|
+
}
|
|
344
|
+
await fs.writeFile(normalizedPath, content, options.encoding || DEFAULT_ENCODING);
|
|
345
|
+
logger.debug(`File edited: ${normalizedPath} (${occurrences} replacements)`);
|
|
346
|
+
return {
|
|
347
|
+
success: true,
|
|
348
|
+
path: normalizedPath,
|
|
349
|
+
changesCount: occurrences,
|
|
350
|
+
backupPath
|
|
351
|
+
};
|
|
352
|
+
} catch (error) {
|
|
353
|
+
throw FileSystemError.editFailed(
|
|
354
|
+
normalizedPath,
|
|
355
|
+
error instanceof Error ? error.message : String(error)
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Create a backup of a file
|
|
361
|
+
*/
|
|
362
|
+
async createBackup(filePath) {
|
|
363
|
+
const backupDir = path.resolve(
|
|
364
|
+
this.config.workingDirectory || process.cwd(),
|
|
365
|
+
this.config.backupPath
|
|
366
|
+
);
|
|
367
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
368
|
+
const basename = path.basename(filePath);
|
|
369
|
+
const backupFilename = `${basename}.${timestamp}.backup`;
|
|
370
|
+
const backupPath = path.join(backupDir, backupFilename);
|
|
371
|
+
try {
|
|
372
|
+
await fs.mkdir(backupDir, { recursive: true });
|
|
373
|
+
await fs.copyFile(filePath, backupPath);
|
|
374
|
+
logger.debug(`Backup created: ${backupPath}`);
|
|
375
|
+
await this.cleanupOldBackups();
|
|
376
|
+
return backupPath;
|
|
377
|
+
} catch (error) {
|
|
378
|
+
throw FileSystemError.backupFailed(
|
|
379
|
+
filePath,
|
|
380
|
+
error instanceof Error ? error.message : String(error)
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Clean up old backup files based on retention policy
|
|
386
|
+
*/
|
|
387
|
+
async cleanupOldBackups() {
|
|
388
|
+
if (!this.config.enableBackups) {
|
|
389
|
+
return 0;
|
|
390
|
+
}
|
|
391
|
+
const backupDir = path.resolve(
|
|
392
|
+
this.config.workingDirectory || process.cwd(),
|
|
393
|
+
this.config.backupPath
|
|
394
|
+
);
|
|
395
|
+
try {
|
|
396
|
+
await fs.access(backupDir);
|
|
397
|
+
} catch {
|
|
398
|
+
return 0;
|
|
399
|
+
}
|
|
400
|
+
const cutoffDate = new Date(
|
|
401
|
+
Date.now() - this.config.backupRetentionDays * 24 * 60 * 60 * 1e3
|
|
402
|
+
);
|
|
403
|
+
let deletedCount = 0;
|
|
404
|
+
try {
|
|
405
|
+
const files = await fs.readdir(backupDir);
|
|
406
|
+
const backupFiles = files.filter((file) => file.endsWith(".backup"));
|
|
407
|
+
for (const file of backupFiles) {
|
|
408
|
+
const filePath = path.join(backupDir, file);
|
|
409
|
+
try {
|
|
410
|
+
const stats = await fs.stat(filePath);
|
|
411
|
+
if (stats.mtime < cutoffDate) {
|
|
412
|
+
await fs.unlink(filePath);
|
|
413
|
+
deletedCount++;
|
|
414
|
+
logger.debug(`Cleaned up old backup: ${file}`);
|
|
415
|
+
}
|
|
416
|
+
} catch (error) {
|
|
417
|
+
logger.warn(
|
|
418
|
+
`Failed to process backup file ${file}: ${error instanceof Error ? error.message : String(error)}`
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (deletedCount > 0) {
|
|
423
|
+
logger.info(`Backup cleanup: removed ${deletedCount} old backup files`);
|
|
424
|
+
}
|
|
425
|
+
return deletedCount;
|
|
426
|
+
} catch (error) {
|
|
427
|
+
logger.warn(
|
|
428
|
+
`Failed to cleanup backup directory: ${error instanceof Error ? error.message : String(error)}`
|
|
429
|
+
);
|
|
430
|
+
return 0;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Get service configuration
|
|
435
|
+
*/
|
|
436
|
+
getConfig() {
|
|
437
|
+
return { ...this.config };
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Check if a path is allowed
|
|
441
|
+
*/
|
|
442
|
+
isPathAllowed(filePath) {
|
|
443
|
+
const validation = this.pathValidator.validatePath(filePath);
|
|
444
|
+
return validation.isValid;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
export {
|
|
448
|
+
FileSystemService
|
|
449
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var filesystem_exports = {};
|
|
20
|
+
__export(filesystem_exports, {
|
|
21
|
+
FileSystemError: () => import_errors.FileSystemError,
|
|
22
|
+
FileSystemErrorCode: () => import_error_codes.FileSystemErrorCode,
|
|
23
|
+
FileSystemService: () => import_filesystem_service.FileSystemService,
|
|
24
|
+
PathValidator: () => import_path_validator.PathValidator
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(filesystem_exports);
|
|
27
|
+
var import_filesystem_service = require("./filesystem-service.js");
|
|
28
|
+
var import_path_validator = require("./path-validator.js");
|
|
29
|
+
var import_errors = require("./errors.js");
|
|
30
|
+
var import_error_codes = require("./error-codes.js");
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
FileSystemError,
|
|
34
|
+
FileSystemErrorCode,
|
|
35
|
+
FileSystemService,
|
|
36
|
+
PathValidator
|
|
37
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FileSystem Module
|
|
3
|
+
*
|
|
4
|
+
* Exports file system service, types, errors, and utilities
|
|
5
|
+
*/
|
|
6
|
+
export { FileSystemService } from './filesystem-service.js';
|
|
7
|
+
export { PathValidator } from './path-validator.js';
|
|
8
|
+
export { FileSystemError } from './errors.js';
|
|
9
|
+
export { FileSystemErrorCode } from './error-codes.js';
|
|
10
|
+
export type { FileSystemConfig, FileContent, ReadFileOptions, GlobOptions, GlobResult, GrepOptions, SearchResult, SearchMatch, WriteFileOptions, WriteResult, EditFileOptions, EditResult, EditOperation, FileMetadata, PathValidation, BufferEncoding, } from './types.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filesystem/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,YAAY,EACR,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,WAAW,EACX,UAAU,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,UAAU,EACV,aAAa,EACb,YAAY,EACZ,cAAc,EACd,cAAc,GACjB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "../chunk-C6A6W6XS.js";
|
|
2
|
+
import { FileSystemService } from "./filesystem-service.js";
|
|
3
|
+
import { PathValidator } from "./path-validator.js";
|
|
4
|
+
import { FileSystemError } from "./errors.js";
|
|
5
|
+
import { FileSystemErrorCode } from "./error-codes.js";
|
|
6
|
+
export {
|
|
7
|
+
FileSystemError,
|
|
8
|
+
FileSystemErrorCode,
|
|
9
|
+
FileSystemService,
|
|
10
|
+
PathValidator
|
|
11
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var path_validator_exports = {};
|
|
30
|
+
__export(path_validator_exports, {
|
|
31
|
+
PathValidator: () => PathValidator
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(path_validator_exports);
|
|
34
|
+
var path = __toESM(require("node:path"), 1);
|
|
35
|
+
var import_node_fs = require("node:fs");
|
|
36
|
+
var import_logger = require("../logger/index.js");
|
|
37
|
+
class PathValidator {
|
|
38
|
+
config;
|
|
39
|
+
normalizedAllowedPaths;
|
|
40
|
+
normalizedBlockedPaths;
|
|
41
|
+
normalizedBlockedExtensions;
|
|
42
|
+
constructor(config) {
|
|
43
|
+
this.config = config;
|
|
44
|
+
const workingDir = config.workingDirectory || process.cwd();
|
|
45
|
+
this.normalizedAllowedPaths = config.allowedPaths.map((p) => path.resolve(workingDir, p));
|
|
46
|
+
this.normalizedBlockedPaths = config.blockedPaths.map((p) => path.normalize(p));
|
|
47
|
+
this.normalizedBlockedExtensions = (config.blockedExtensions || []).map((ext) => {
|
|
48
|
+
const e = ext.startsWith(".") ? ext : `.${ext}`;
|
|
49
|
+
return e.toLowerCase();
|
|
50
|
+
});
|
|
51
|
+
import_logger.logger.debug(
|
|
52
|
+
`PathValidator initialized with ${this.normalizedAllowedPaths.length} allowed paths`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validate a file path for security and policy compliance
|
|
57
|
+
*/
|
|
58
|
+
validatePath(filePath) {
|
|
59
|
+
if (!filePath || filePath.trim() === "") {
|
|
60
|
+
return {
|
|
61
|
+
isValid: false,
|
|
62
|
+
error: "Path cannot be empty"
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const workingDir = this.config.workingDirectory || process.cwd();
|
|
66
|
+
let normalizedPath;
|
|
67
|
+
try {
|
|
68
|
+
normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
|
|
69
|
+
try {
|
|
70
|
+
normalizedPath = import_node_fs.realpathSync.native(normalizedPath);
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return {
|
|
75
|
+
isValid: false,
|
|
76
|
+
error: `Failed to normalize path: ${error instanceof Error ? error.message : String(error)}`
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (this.hasPathTraversal(filePath, normalizedPath)) {
|
|
80
|
+
return {
|
|
81
|
+
isValid: false,
|
|
82
|
+
error: "Path traversal detected"
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (!this.isPathAllowed(normalizedPath)) {
|
|
86
|
+
return {
|
|
87
|
+
isValid: false,
|
|
88
|
+
error: `Path is not within allowed paths. Allowed: ${this.normalizedAllowedPaths.join(", ")}`
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const blockedReason = this.isPathBlocked(normalizedPath);
|
|
92
|
+
if (blockedReason) {
|
|
93
|
+
return {
|
|
94
|
+
isValid: false,
|
|
95
|
+
error: `Path is blocked: ${blockedReason}`
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const ext = path.extname(normalizedPath).toLowerCase();
|
|
99
|
+
if (ext && this.normalizedBlockedExtensions.includes(ext)) {
|
|
100
|
+
return {
|
|
101
|
+
isValid: false,
|
|
102
|
+
error: `File extension ${ext} is not allowed`
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
isValid: true,
|
|
107
|
+
normalizedPath
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Check if path contains traversal attempts
|
|
112
|
+
*/
|
|
113
|
+
hasPathTraversal(originalPath, normalizedPath) {
|
|
114
|
+
if (originalPath.includes("../") || originalPath.includes("..\\")) {
|
|
115
|
+
const workingDir = this.config.workingDirectory || process.cwd();
|
|
116
|
+
const relative = path.relative(workingDir, normalizedPath);
|
|
117
|
+
if (relative.startsWith("..")) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check if path is within allowed paths (whitelist check)
|
|
125
|
+
*/
|
|
126
|
+
isPathAllowed(normalizedPath) {
|
|
127
|
+
if (this.normalizedAllowedPaths.length === 0) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return this.normalizedAllowedPaths.some((allowedPath) => {
|
|
131
|
+
const relative = path.relative(allowedPath, normalizedPath);
|
|
132
|
+
return !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Check if path matches blocked patterns (blacklist check)
|
|
137
|
+
*/
|
|
138
|
+
isPathBlocked(normalizedPath) {
|
|
139
|
+
const roots = this.normalizedAllowedPaths.length > 0 ? this.normalizedAllowedPaths : [this.config.workingDirectory || process.cwd()];
|
|
140
|
+
for (const blocked of this.normalizedBlockedPaths) {
|
|
141
|
+
for (const root of roots) {
|
|
142
|
+
const blockedFull = path.isAbsolute(blocked) ? path.normalize(blocked) : path.resolve(root, blocked);
|
|
143
|
+
if (normalizedPath === blockedFull || normalizedPath.startsWith(blockedFull + path.sep)) {
|
|
144
|
+
return `Within blocked directory: ${blocked}`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Quick check if a path is allowed (for internal use)
|
|
152
|
+
*/
|
|
153
|
+
isPathAllowedQuick(normalizedPath) {
|
|
154
|
+
return this.isPathAllowed(normalizedPath) && !this.isPathBlocked(normalizedPath);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get normalized allowed paths
|
|
158
|
+
*/
|
|
159
|
+
getAllowedPaths() {
|
|
160
|
+
return [...this.normalizedAllowedPaths];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get blocked paths
|
|
164
|
+
*/
|
|
165
|
+
getBlockedPaths() {
|
|
166
|
+
return [...this.normalizedBlockedPaths];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
170
|
+
0 && (module.exports = {
|
|
171
|
+
PathValidator
|
|
172
|
+
});
|