@probelabs/probe 0.6.0-rc174 → 0.6.0-rc176
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/build/agent/ProbeAgent.d.ts +6 -0
- package/build/agent/ProbeAgent.js +69 -1
- package/build/agent/index.js +332 -233
- package/build/agent/simpleTelemetry.js +13 -0
- package/build/extract.js +13 -5
- package/build/query.js +9 -2
- package/build/search.js +10 -2
- package/build/tools/bash.js +5 -5
- package/build/tools/edit.js +7 -7
- package/build/tools/langchain.js +15 -6
- package/build/tools/vercel.js +29 -33
- package/build/utils/path-validation.js +58 -0
- package/cjs/agent/ProbeAgent.cjs +453 -364
- package/cjs/agent/simpleTelemetry.cjs +11 -0
- package/cjs/index.cjs +487 -378
- package/index.d.ts +12 -1
- package/package.json +1 -1
- package/src/agent/ProbeAgent.d.ts +6 -0
- package/src/agent/ProbeAgent.js +69 -1
- package/src/agent/simpleTelemetry.js +13 -0
- package/src/extract.js +13 -5
- package/src/query.js +9 -2
- package/src/search.js +10 -2
- package/src/tools/bash.js +5 -5
- package/src/tools/edit.js +7 -7
- package/src/tools/langchain.js +15 -6
- package/src/tools/vercel.js +29 -33
- package/src/utils/path-validation.js +58 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path validation utilities for the probe package
|
|
3
|
+
* @module utils/path-validation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { promises as fs } from 'fs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Validates and normalizes a path to be used as working directory (cwd).
|
|
11
|
+
*
|
|
12
|
+
* Security considerations:
|
|
13
|
+
* - Normalizes path to resolve '..' and '.' components
|
|
14
|
+
* - Returns absolute path to prevent ambiguity
|
|
15
|
+
* - Does NOT restrict access to specific directories (that's the responsibility
|
|
16
|
+
* of higher-level components like ProbeAgent with allowedFolders)
|
|
17
|
+
*
|
|
18
|
+
* @param {string} inputPath - The path to validate
|
|
19
|
+
* @param {string} [defaultPath] - Default path to use if inputPath is not provided
|
|
20
|
+
* @returns {Promise<string>} Normalized absolute path
|
|
21
|
+
* @throws {Error} If the path is invalid or doesn't exist
|
|
22
|
+
*/
|
|
23
|
+
export async function validateCwdPath(inputPath, defaultPath = process.cwd()) {
|
|
24
|
+
// Use default if not provided
|
|
25
|
+
const targetPath = inputPath || defaultPath;
|
|
26
|
+
|
|
27
|
+
// Normalize and resolve to absolute path
|
|
28
|
+
// This handles '..' traversal and makes the path unambiguous
|
|
29
|
+
const normalizedPath = path.normalize(path.resolve(targetPath));
|
|
30
|
+
|
|
31
|
+
// Verify the path exists and is a directory
|
|
32
|
+
try {
|
|
33
|
+
const stats = await fs.stat(normalizedPath);
|
|
34
|
+
if (!stats.isDirectory()) {
|
|
35
|
+
throw new Error(`Path is not a directory: ${normalizedPath}`);
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error.code === 'ENOENT') {
|
|
39
|
+
throw new Error(`Path does not exist: ${normalizedPath}`);
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return normalizedPath;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Validates a path option without requiring it to exist.
|
|
49
|
+
* Use this for paths that might be created or are optional.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} inputPath - The path to validate
|
|
52
|
+
* @param {string} [defaultPath] - Default path to use if inputPath is not provided
|
|
53
|
+
* @returns {string} Normalized absolute path
|
|
54
|
+
*/
|
|
55
|
+
export function normalizePath(inputPath, defaultPath = process.cwd()) {
|
|
56
|
+
const targetPath = inputPath || defaultPath;
|
|
57
|
+
return path.normalize(path.resolve(targetPath));
|
|
58
|
+
}
|