@dexto/core 1.5.4 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/agent/DextoAgent.cjs +61 -155
  2. package/dist/agent/DextoAgent.d.ts +11 -54
  3. package/dist/agent/DextoAgent.d.ts.map +1 -1
  4. package/dist/agent/DextoAgent.js +61 -155
  5. package/dist/context/compaction/strategies/reactive-overflow.cjs +5 -3
  6. package/dist/context/compaction/strategies/reactive-overflow.d.ts +1 -0
  7. package/dist/context/compaction/strategies/reactive-overflow.d.ts.map +1 -1
  8. package/dist/context/compaction/strategies/reactive-overflow.js +5 -3
  9. package/dist/context/compaction/types.d.ts +13 -1
  10. package/dist/context/compaction/types.d.ts.map +1 -1
  11. package/dist/errors/types.cjs +0 -2
  12. package/dist/errors/types.d.ts +1 -5
  13. package/dist/errors/types.d.ts.map +1 -1
  14. package/dist/errors/types.js +0 -2
  15. package/dist/events/index.cjs +0 -2
  16. package/dist/events/index.d.ts +6 -25
  17. package/dist/events/index.d.ts.map +1 -1
  18. package/dist/events/index.js +0 -2
  19. package/dist/llm/executor/stream-processor.cjs +85 -27
  20. package/dist/llm/executor/stream-processor.d.ts +4 -0
  21. package/dist/llm/executor/stream-processor.d.ts.map +1 -1
  22. package/dist/llm/executor/stream-processor.js +85 -27
  23. package/dist/llm/executor/turn-executor.cjs +58 -130
  24. package/dist/llm/executor/turn-executor.d.ts +9 -43
  25. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  26. package/dist/llm/executor/turn-executor.js +58 -130
  27. package/dist/llm/executor/types.d.ts +0 -28
  28. package/dist/llm/executor/types.d.ts.map +1 -1
  29. package/dist/llm/services/vercel.cjs +2 -5
  30. package/dist/llm/services/vercel.d.ts +1 -6
  31. package/dist/llm/services/vercel.d.ts.map +1 -1
  32. package/dist/llm/services/vercel.js +2 -5
  33. package/dist/logger/logger.cjs +6 -7
  34. package/dist/logger/logger.d.ts +1 -0
  35. package/dist/logger/logger.d.ts.map +1 -1
  36. package/dist/logger/logger.js +6 -7
  37. package/dist/session/chat-session.cjs +19 -12
  38. package/dist/session/chat-session.d.ts +3 -6
  39. package/dist/session/chat-session.d.ts.map +1 -1
  40. package/dist/session/chat-session.js +19 -12
  41. package/dist/session/session-manager.cjs +0 -135
  42. package/dist/session/session-manager.d.ts +0 -43
  43. package/dist/session/session-manager.d.ts.map +1 -1
  44. package/dist/session/session-manager.js +0 -135
  45. package/dist/telemetry/telemetry.cjs +12 -5
  46. package/dist/telemetry/telemetry.d.ts.map +1 -1
  47. package/dist/telemetry/telemetry.js +12 -5
  48. package/dist/tools/schemas.cjs +2 -2
  49. package/dist/tools/schemas.js +2 -2
  50. package/package.json +15 -5
  51. package/dist/filesystem/error-codes.cjs +0 -53
  52. package/dist/filesystem/error-codes.d.ts +0 -31
  53. package/dist/filesystem/error-codes.d.ts.map +0 -1
  54. package/dist/filesystem/error-codes.js +0 -30
  55. package/dist/filesystem/errors.cjs +0 -303
  56. package/dist/filesystem/errors.d.ts +0 -109
  57. package/dist/filesystem/errors.d.ts.map +0 -1
  58. package/dist/filesystem/errors.js +0 -280
  59. package/dist/filesystem/filesystem-service.cjs +0 -534
  60. package/dist/filesystem/filesystem-service.d.ts +0 -97
  61. package/dist/filesystem/filesystem-service.d.ts.map +0 -1
  62. package/dist/filesystem/filesystem-service.js +0 -501
  63. package/dist/filesystem/index.cjs +0 -37
  64. package/dist/filesystem/index.d.ts +0 -11
  65. package/dist/filesystem/index.d.ts.map +0 -1
  66. package/dist/filesystem/index.js +0 -11
  67. package/dist/filesystem/path-validator.cjs +0 -250
  68. package/dist/filesystem/path-validator.d.ts +0 -103
  69. package/dist/filesystem/path-validator.d.ts.map +0 -1
  70. package/dist/filesystem/path-validator.js +0 -217
  71. package/dist/filesystem/types.cjs +0 -16
  72. package/dist/filesystem/types.d.ts +0 -175
  73. package/dist/filesystem/types.d.ts.map +0 -1
  74. package/dist/filesystem/types.js +0 -0
  75. package/dist/process/command-validator.cjs +0 -554
  76. package/dist/process/command-validator.d.ts +0 -49
  77. package/dist/process/command-validator.d.ts.map +0 -1
  78. package/dist/process/command-validator.js +0 -531
  79. package/dist/process/error-codes.cjs +0 -47
  80. package/dist/process/error-codes.d.ts +0 -25
  81. package/dist/process/error-codes.d.ts.map +0 -1
  82. package/dist/process/error-codes.js +0 -24
  83. package/dist/process/errors.cjs +0 -244
  84. package/dist/process/errors.d.ts +0 -87
  85. package/dist/process/errors.d.ts.map +0 -1
  86. package/dist/process/errors.js +0 -221
  87. package/dist/process/index.cjs +0 -37
  88. package/dist/process/index.d.ts +0 -11
  89. package/dist/process/index.d.ts.map +0 -1
  90. package/dist/process/index.js +0 -11
  91. package/dist/process/process-service.cjs +0 -497
  92. package/dist/process/process-service.d.ts +0 -69
  93. package/dist/process/process-service.d.ts.map +0 -1
  94. package/dist/process/process-service.js +0 -464
  95. package/dist/process/types.cjs +0 -16
  96. package/dist/process/types.d.ts +0 -107
  97. package/dist/process/types.d.ts.map +0 -1
  98. package/dist/process/types.js +0 -0
  99. package/dist/session/compaction-service.cjs +0 -139
  100. package/dist/session/compaction-service.d.ts +0 -81
  101. package/dist/session/compaction-service.d.ts.map +0 -1
  102. package/dist/session/compaction-service.js +0 -106
@@ -1,250 +0,0 @@
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 fs = __toESM(require("node:fs/promises"), 1);
36
- class PathValidator {
37
- config;
38
- normalizedAllowedPaths;
39
- normalizedBlockedPaths;
40
- normalizedBlockedExtensions;
41
- logger;
42
- directoryApprovalChecker;
43
- constructor(config, logger) {
44
- this.config = config;
45
- this.logger = logger;
46
- const workingDir = config.workingDirectory || process.cwd();
47
- this.normalizedAllowedPaths = config.allowedPaths.map((p) => path.resolve(workingDir, p));
48
- this.normalizedBlockedPaths = config.blockedPaths.map((p) => path.normalize(p));
49
- this.normalizedBlockedExtensions = (config.blockedExtensions || []).map((ext) => {
50
- const e = ext.startsWith(".") ? ext : `.${ext}`;
51
- return e.toLowerCase();
52
- });
53
- this.logger.debug(
54
- `PathValidator initialized with ${this.normalizedAllowedPaths.length} allowed paths`
55
- );
56
- }
57
- /**
58
- * Set a callback to check if a path is in an approved directory.
59
- * This allows PathValidator to consult ApprovalManager without a direct dependency.
60
- *
61
- * @param checker Function that returns true if path is in an approved directory
62
- */
63
- setDirectoryApprovalChecker(checker) {
64
- this.directoryApprovalChecker = checker;
65
- this.logger.debug("Directory approval checker configured");
66
- }
67
- /**
68
- * Validate a file path for security and policy compliance
69
- */
70
- async validatePath(filePath) {
71
- if (!filePath || filePath.trim() === "") {
72
- return {
73
- isValid: false,
74
- error: "Path cannot be empty"
75
- };
76
- }
77
- const workingDir = this.config.workingDirectory || process.cwd();
78
- let normalizedPath;
79
- try {
80
- normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
81
- try {
82
- normalizedPath = await fs.realpath(normalizedPath);
83
- } catch {
84
- }
85
- } catch (error) {
86
- return {
87
- isValid: false,
88
- error: `Failed to normalize path: ${error instanceof Error ? error.message : String(error)}`
89
- };
90
- }
91
- if (this.hasPathTraversal(filePath, normalizedPath)) {
92
- return {
93
- isValid: false,
94
- error: "Path traversal detected"
95
- };
96
- }
97
- if (!this.isPathAllowed(normalizedPath)) {
98
- return {
99
- isValid: false,
100
- error: `Path is not within allowed paths. Allowed: ${this.normalizedAllowedPaths.join(", ")}`
101
- };
102
- }
103
- const blockedReason = this.isPathBlocked(normalizedPath);
104
- if (blockedReason) {
105
- return {
106
- isValid: false,
107
- error: `Path is blocked: ${blockedReason}`
108
- };
109
- }
110
- const ext = path.extname(normalizedPath).toLowerCase();
111
- if (ext && this.normalizedBlockedExtensions.includes(ext)) {
112
- return {
113
- isValid: false,
114
- error: `File extension ${ext} is not allowed`
115
- };
116
- }
117
- return {
118
- isValid: true,
119
- normalizedPath
120
- };
121
- }
122
- /**
123
- * Check if path contains traversal attempts
124
- */
125
- hasPathTraversal(originalPath, normalizedPath) {
126
- if (originalPath.includes("../") || originalPath.includes("..\\")) {
127
- const workingDir = this.config.workingDirectory || process.cwd();
128
- const relative = path.relative(workingDir, normalizedPath);
129
- if (relative.startsWith("..")) {
130
- return true;
131
- }
132
- }
133
- return false;
134
- }
135
- /**
136
- * Check if path is within allowed paths (whitelist check)
137
- * Also consults the directory approval checker if configured.
138
- * Uses the sync version since the path is already normalized at this point.
139
- */
140
- isPathAllowed(normalizedPath) {
141
- return this.isPathAllowedSync(normalizedPath);
142
- }
143
- /**
144
- * Synchronous path allowed check (for already-normalized paths)
145
- * This is used internally when we already have a canonicalized path
146
- */
147
- isPathAllowedSync(normalizedPath) {
148
- if (this.normalizedAllowedPaths.length === 0) {
149
- return true;
150
- }
151
- const isInConfigPaths = this.normalizedAllowedPaths.some((allowedPath) => {
152
- const relative = path.relative(allowedPath, normalizedPath);
153
- return !relative.startsWith("..") && !path.isAbsolute(relative);
154
- });
155
- if (isInConfigPaths) {
156
- return true;
157
- }
158
- if (this.directoryApprovalChecker) {
159
- return this.directoryApprovalChecker(normalizedPath);
160
- }
161
- return false;
162
- }
163
- /**
164
- * Check if path matches blocked patterns (blacklist check)
165
- */
166
- isPathBlocked(normalizedPath) {
167
- const roots = this.normalizedAllowedPaths.length > 0 ? this.normalizedAllowedPaths : [this.config.workingDirectory || process.cwd()];
168
- for (const blocked of this.normalizedBlockedPaths) {
169
- for (const root of roots) {
170
- const blockedFull = path.isAbsolute(blocked) ? path.normalize(blocked) : path.resolve(root, blocked);
171
- if (normalizedPath === blockedFull || normalizedPath.startsWith(blockedFull + path.sep)) {
172
- return `Within blocked directory: ${blocked}`;
173
- }
174
- }
175
- }
176
- return null;
177
- }
178
- /**
179
- * Quick check if a path is allowed (for internal use)
180
- * Note: This assumes the path is already normalized/canonicalized
181
- */
182
- isPathAllowedQuick(normalizedPath) {
183
- return this.isPathAllowedSync(normalizedPath) && !this.isPathBlocked(normalizedPath);
184
- }
185
- /**
186
- * Check if a file path is within the configured allowed paths (from config only).
187
- * This method does NOT consult ApprovalManager - it only checks the static config paths.
188
- *
189
- * This is used by ToolManager.checkDirectoryAccess() to determine if a path
190
- * needs directory approval. Paths within config-allowed directories don't need
191
- * directory approval prompts.
192
- *
193
- * @param filePath The file path to check (can be relative or absolute)
194
- * @returns true if the path is within config-allowed paths, false otherwise
195
- *
196
- * @example
197
- * ```typescript
198
- * // Check if path needs directory approval
199
- * if (!await pathValidator.isPathWithinAllowed('/external/project/file.ts')) {
200
- * // Request directory access approval
201
- * }
202
- * ```
203
- */
204
- async isPathWithinAllowed(filePath) {
205
- if (!filePath || filePath.trim() === "") {
206
- return false;
207
- }
208
- const workingDir = this.config.workingDirectory || process.cwd();
209
- let normalizedPath;
210
- try {
211
- normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
212
- try {
213
- normalizedPath = await fs.realpath(normalizedPath);
214
- } catch {
215
- }
216
- } catch {
217
- return false;
218
- }
219
- return this.isInConfigAllowedPaths(normalizedPath);
220
- }
221
- /**
222
- * Check if path is within config-allowed paths only (no approval checker).
223
- * Used for prompting decisions.
224
- */
225
- isInConfigAllowedPaths(normalizedPath) {
226
- if (this.normalizedAllowedPaths.length === 0) {
227
- return true;
228
- }
229
- return this.normalizedAllowedPaths.some((allowedPath) => {
230
- const relative = path.relative(allowedPath, normalizedPath);
231
- return !relative.startsWith("..") && !path.isAbsolute(relative);
232
- });
233
- }
234
- /**
235
- * Get normalized allowed paths
236
- */
237
- getAllowedPaths() {
238
- return [...this.normalizedAllowedPaths];
239
- }
240
- /**
241
- * Get blocked paths
242
- */
243
- getBlockedPaths() {
244
- return [...this.normalizedBlockedPaths];
245
- }
246
- }
247
- // Annotate the CommonJS export names for ESM import in node:
248
- 0 && (module.exports = {
249
- PathValidator
250
- });
@@ -1,103 +0,0 @@
1
- /**
2
- * Path Validator
3
- *
4
- * Security-focused path validation for file system operations
5
- */
6
- import { FileSystemConfig, PathValidation } from './types.js';
7
- import type { IDextoLogger } from '../logger/v2/types.js';
8
- /**
9
- * Callback type for checking if a path is in an approved directory.
10
- * Used to consult ApprovalManager without creating a direct dependency.
11
- */
12
- export type DirectoryApprovalChecker = (filePath: string) => boolean;
13
- /**
14
- * PathValidator - Validates file paths for security and policy compliance
15
- *
16
- * Security checks:
17
- * 1. Path traversal detection (../, symbolic links)
18
- * 2. Allowed paths enforcement (whitelist + approved directories)
19
- * 3. Blocked paths detection (blacklist)
20
- * 4. File extension restrictions
21
- * 5. Absolute path normalization
22
- *
23
- * PathValidator can optionally consult an external approval checker (e.g., ApprovalManager)
24
- * to determine if paths outside the config's allowed paths are accessible.
25
- */
26
- export declare class PathValidator {
27
- private config;
28
- private normalizedAllowedPaths;
29
- private normalizedBlockedPaths;
30
- private normalizedBlockedExtensions;
31
- private logger;
32
- private directoryApprovalChecker;
33
- constructor(config: FileSystemConfig, logger: IDextoLogger);
34
- /**
35
- * Set a callback to check if a path is in an approved directory.
36
- * This allows PathValidator to consult ApprovalManager without a direct dependency.
37
- *
38
- * @param checker Function that returns true if path is in an approved directory
39
- */
40
- setDirectoryApprovalChecker(checker: DirectoryApprovalChecker): void;
41
- /**
42
- * Validate a file path for security and policy compliance
43
- */
44
- validatePath(filePath: string): Promise<PathValidation>;
45
- /**
46
- * Check if path contains traversal attempts
47
- */
48
- private hasPathTraversal;
49
- /**
50
- * Check if path is within allowed paths (whitelist check)
51
- * Also consults the directory approval checker if configured.
52
- * Uses the sync version since the path is already normalized at this point.
53
- */
54
- private isPathAllowed;
55
- /**
56
- * Synchronous path allowed check (for already-normalized paths)
57
- * This is used internally when we already have a canonicalized path
58
- */
59
- private isPathAllowedSync;
60
- /**
61
- * Check if path matches blocked patterns (blacklist check)
62
- */
63
- private isPathBlocked;
64
- /**
65
- * Quick check if a path is allowed (for internal use)
66
- * Note: This assumes the path is already normalized/canonicalized
67
- */
68
- isPathAllowedQuick(normalizedPath: string): boolean;
69
- /**
70
- * Check if a file path is within the configured allowed paths (from config only).
71
- * This method does NOT consult ApprovalManager - it only checks the static config paths.
72
- *
73
- * This is used by ToolManager.checkDirectoryAccess() to determine if a path
74
- * needs directory approval. Paths within config-allowed directories don't need
75
- * directory approval prompts.
76
- *
77
- * @param filePath The file path to check (can be relative or absolute)
78
- * @returns true if the path is within config-allowed paths, false otherwise
79
- *
80
- * @example
81
- * ```typescript
82
- * // Check if path needs directory approval
83
- * if (!await pathValidator.isPathWithinAllowed('/external/project/file.ts')) {
84
- * // Request directory access approval
85
- * }
86
- * ```
87
- */
88
- isPathWithinAllowed(filePath: string): Promise<boolean>;
89
- /**
90
- * Check if path is within config-allowed paths only (no approval checker).
91
- * Used for prompting decisions.
92
- */
93
- private isInConfigAllowedPaths;
94
- /**
95
- * Get normalized allowed paths
96
- */
97
- getAllowedPaths(): string[];
98
- /**
99
- * Get blocked paths
100
- */
101
- getBlockedPaths(): string[];
102
- }
103
- //# sourceMappingURL=path-validator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path-validator.d.ts","sourceRoot":"","sources":["../../src/filesystem/path-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,sBAAsB,CAAW;IACzC,OAAO,CAAC,sBAAsB,CAAW;IACzC,OAAO,CAAC,2BAA2B,CAAW;IAC9C,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,wBAAwB,CAAuC;gBAE3D,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY;IAsB1D;;;;;OAKG;IACH,2BAA2B,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAKpE;;OAEG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAyE7D;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAaxB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAyBzB;;OAEG;IACH,OAAO,CAAC,aAAa;IAyBrB;;;OAGG;IACH,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO;IAInD;;;;;;;;;;;;;;;;;;OAkBG;IACG,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA8B7D;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;IAI3B;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;CAG9B"}
@@ -1,217 +0,0 @@
1
- import "../chunk-PTJYTZNU.js";
2
- import * as path from "node:path";
3
- import * as fs from "node:fs/promises";
4
- class PathValidator {
5
- config;
6
- normalizedAllowedPaths;
7
- normalizedBlockedPaths;
8
- normalizedBlockedExtensions;
9
- logger;
10
- directoryApprovalChecker;
11
- constructor(config, logger) {
12
- this.config = config;
13
- this.logger = logger;
14
- const workingDir = config.workingDirectory || process.cwd();
15
- this.normalizedAllowedPaths = config.allowedPaths.map((p) => path.resolve(workingDir, p));
16
- this.normalizedBlockedPaths = config.blockedPaths.map((p) => path.normalize(p));
17
- this.normalizedBlockedExtensions = (config.blockedExtensions || []).map((ext) => {
18
- const e = ext.startsWith(".") ? ext : `.${ext}`;
19
- return e.toLowerCase();
20
- });
21
- this.logger.debug(
22
- `PathValidator initialized with ${this.normalizedAllowedPaths.length} allowed paths`
23
- );
24
- }
25
- /**
26
- * Set a callback to check if a path is in an approved directory.
27
- * This allows PathValidator to consult ApprovalManager without a direct dependency.
28
- *
29
- * @param checker Function that returns true if path is in an approved directory
30
- */
31
- setDirectoryApprovalChecker(checker) {
32
- this.directoryApprovalChecker = checker;
33
- this.logger.debug("Directory approval checker configured");
34
- }
35
- /**
36
- * Validate a file path for security and policy compliance
37
- */
38
- async validatePath(filePath) {
39
- if (!filePath || filePath.trim() === "") {
40
- return {
41
- isValid: false,
42
- error: "Path cannot be empty"
43
- };
44
- }
45
- const workingDir = this.config.workingDirectory || process.cwd();
46
- let normalizedPath;
47
- try {
48
- normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
49
- try {
50
- normalizedPath = await fs.realpath(normalizedPath);
51
- } catch {
52
- }
53
- } catch (error) {
54
- return {
55
- isValid: false,
56
- error: `Failed to normalize path: ${error instanceof Error ? error.message : String(error)}`
57
- };
58
- }
59
- if (this.hasPathTraversal(filePath, normalizedPath)) {
60
- return {
61
- isValid: false,
62
- error: "Path traversal detected"
63
- };
64
- }
65
- if (!this.isPathAllowed(normalizedPath)) {
66
- return {
67
- isValid: false,
68
- error: `Path is not within allowed paths. Allowed: ${this.normalizedAllowedPaths.join(", ")}`
69
- };
70
- }
71
- const blockedReason = this.isPathBlocked(normalizedPath);
72
- if (blockedReason) {
73
- return {
74
- isValid: false,
75
- error: `Path is blocked: ${blockedReason}`
76
- };
77
- }
78
- const ext = path.extname(normalizedPath).toLowerCase();
79
- if (ext && this.normalizedBlockedExtensions.includes(ext)) {
80
- return {
81
- isValid: false,
82
- error: `File extension ${ext} is not allowed`
83
- };
84
- }
85
- return {
86
- isValid: true,
87
- normalizedPath
88
- };
89
- }
90
- /**
91
- * Check if path contains traversal attempts
92
- */
93
- hasPathTraversal(originalPath, normalizedPath) {
94
- if (originalPath.includes("../") || originalPath.includes("..\\")) {
95
- const workingDir = this.config.workingDirectory || process.cwd();
96
- const relative = path.relative(workingDir, normalizedPath);
97
- if (relative.startsWith("..")) {
98
- return true;
99
- }
100
- }
101
- return false;
102
- }
103
- /**
104
- * Check if path is within allowed paths (whitelist check)
105
- * Also consults the directory approval checker if configured.
106
- * Uses the sync version since the path is already normalized at this point.
107
- */
108
- isPathAllowed(normalizedPath) {
109
- return this.isPathAllowedSync(normalizedPath);
110
- }
111
- /**
112
- * Synchronous path allowed check (for already-normalized paths)
113
- * This is used internally when we already have a canonicalized path
114
- */
115
- isPathAllowedSync(normalizedPath) {
116
- if (this.normalizedAllowedPaths.length === 0) {
117
- return true;
118
- }
119
- const isInConfigPaths = this.normalizedAllowedPaths.some((allowedPath) => {
120
- const relative = path.relative(allowedPath, normalizedPath);
121
- return !relative.startsWith("..") && !path.isAbsolute(relative);
122
- });
123
- if (isInConfigPaths) {
124
- return true;
125
- }
126
- if (this.directoryApprovalChecker) {
127
- return this.directoryApprovalChecker(normalizedPath);
128
- }
129
- return false;
130
- }
131
- /**
132
- * Check if path matches blocked patterns (blacklist check)
133
- */
134
- isPathBlocked(normalizedPath) {
135
- const roots = this.normalizedAllowedPaths.length > 0 ? this.normalizedAllowedPaths : [this.config.workingDirectory || process.cwd()];
136
- for (const blocked of this.normalizedBlockedPaths) {
137
- for (const root of roots) {
138
- const blockedFull = path.isAbsolute(blocked) ? path.normalize(blocked) : path.resolve(root, blocked);
139
- if (normalizedPath === blockedFull || normalizedPath.startsWith(blockedFull + path.sep)) {
140
- return `Within blocked directory: ${blocked}`;
141
- }
142
- }
143
- }
144
- return null;
145
- }
146
- /**
147
- * Quick check if a path is allowed (for internal use)
148
- * Note: This assumes the path is already normalized/canonicalized
149
- */
150
- isPathAllowedQuick(normalizedPath) {
151
- return this.isPathAllowedSync(normalizedPath) && !this.isPathBlocked(normalizedPath);
152
- }
153
- /**
154
- * Check if a file path is within the configured allowed paths (from config only).
155
- * This method does NOT consult ApprovalManager - it only checks the static config paths.
156
- *
157
- * This is used by ToolManager.checkDirectoryAccess() to determine if a path
158
- * needs directory approval. Paths within config-allowed directories don't need
159
- * directory approval prompts.
160
- *
161
- * @param filePath The file path to check (can be relative or absolute)
162
- * @returns true if the path is within config-allowed paths, false otherwise
163
- *
164
- * @example
165
- * ```typescript
166
- * // Check if path needs directory approval
167
- * if (!await pathValidator.isPathWithinAllowed('/external/project/file.ts')) {
168
- * // Request directory access approval
169
- * }
170
- * ```
171
- */
172
- async isPathWithinAllowed(filePath) {
173
- if (!filePath || filePath.trim() === "") {
174
- return false;
175
- }
176
- const workingDir = this.config.workingDirectory || process.cwd();
177
- let normalizedPath;
178
- try {
179
- normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
180
- try {
181
- normalizedPath = await fs.realpath(normalizedPath);
182
- } catch {
183
- }
184
- } catch {
185
- return false;
186
- }
187
- return this.isInConfigAllowedPaths(normalizedPath);
188
- }
189
- /**
190
- * Check if path is within config-allowed paths only (no approval checker).
191
- * Used for prompting decisions.
192
- */
193
- isInConfigAllowedPaths(normalizedPath) {
194
- if (this.normalizedAllowedPaths.length === 0) {
195
- return true;
196
- }
197
- return this.normalizedAllowedPaths.some((allowedPath) => {
198
- const relative = path.relative(allowedPath, normalizedPath);
199
- return !relative.startsWith("..") && !path.isAbsolute(relative);
200
- });
201
- }
202
- /**
203
- * Get normalized allowed paths
204
- */
205
- getAllowedPaths() {
206
- return [...this.normalizedAllowedPaths];
207
- }
208
- /**
209
- * Get blocked paths
210
- */
211
- getBlockedPaths() {
212
- return [...this.normalizedBlockedPaths];
213
- }
214
- }
215
- export {
216
- PathValidator
217
- };
@@ -1,16 +0,0 @@
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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);