protoagent 0.1.15 → 0.1.17
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/dist/tools/write-file.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import fs from 'node:fs/promises';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { validatePath } from '../utils/path-validation.js';
|
|
7
|
-
import { findSimilarPaths } from '../utils/path-suggestions.js';
|
|
8
7
|
import { requestApproval } from '../utils/approval.js';
|
|
9
8
|
import { recordRead } from '../utils/file-time.js';
|
|
10
9
|
export const writeFileTool = {
|
|
@@ -23,22 +22,8 @@ export const writeFileTool = {
|
|
|
23
22
|
},
|
|
24
23
|
};
|
|
25
24
|
export async function writeFile(filePath, content, sessionId) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
validated = await validatePath(filePath);
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
// If file not found, try to suggest similar paths
|
|
32
|
-
if (err.message?.includes('does not exist') || err.code === 'ENOENT') {
|
|
33
|
-
const suggestions = await findSimilarPaths(filePath);
|
|
34
|
-
let msg = `File not found: '${filePath}'`;
|
|
35
|
-
if (suggestions.length > 0) {
|
|
36
|
-
msg += '\nDid you mean one of these?\n' + suggestions.map(s => ` ${s}`).join('\n');
|
|
37
|
-
}
|
|
38
|
-
return msg;
|
|
39
|
-
}
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
25
|
+
// validatePath handles non-existent files by validating the parent directory
|
|
26
|
+
const validated = await validatePath(filePath);
|
|
42
27
|
// Request approval
|
|
43
28
|
const preview = content.length > 500
|
|
44
29
|
? `${content.slice(0, 250)}\n... (${content.length} chars total) ...\n${content.slice(-250)}`
|
|
@@ -7,11 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import fs from 'node:fs/promises';
|
|
9
9
|
import path from 'node:path';
|
|
10
|
-
import isPathInside from 'is-path-inside';
|
|
11
10
|
const workingDirectory = process.cwd();
|
|
12
11
|
let allowedRoots = [];
|
|
12
|
+
function isWithinRoot(targetPath, rootPath) {
|
|
13
|
+
const relative = path.relative(rootPath, targetPath);
|
|
14
|
+
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
|
|
15
|
+
}
|
|
13
16
|
function isAllowedPath(targetPath) {
|
|
14
|
-
return
|
|
17
|
+
return isWithinRoot(targetPath, workingDirectory) || allowedRoots.some((root) => isWithinRoot(targetPath, root));
|
|
15
18
|
}
|
|
16
19
|
export async function setAllowedPathRoots(roots) {
|
|
17
20
|
const normalizedRoots = await Promise.all(roots.map(async (root) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protoagent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"he": "^1.2.0",
|
|
53
53
|
"html-to-text": "^9.0.5",
|
|
54
54
|
"ink": "^6.8.0",
|
|
55
|
-
"is-path-inside": "^4.0.0",
|
|
56
55
|
"jsonc-parser": "^3.3.1",
|
|
57
56
|
"leven": "^4.1.0",
|
|
58
57
|
"openai": "^5.23.1",
|