@kuralle-agents/fs 0.6.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 +202 -0
- package/README.md +98 -0
- package/dist/composite-fs.d.ts +43 -0
- package/dist/composite-fs.js +298 -0
- package/dist/encoding.d.ts +5 -0
- package/dist/encoding.js +73 -0
- package/dist/in-memory-fs.d.ts +48 -0
- package/dist/in-memory-fs.js +523 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/interface.d.ts +1 -0
- package/dist/interface.js +1 -0
- package/dist/path-utils.d.ts +12 -0
- package/dist/path-utils.js +114 -0
- package/dist/tool.d.ts +2 -0
- package/dist/tool.js +5 -0
- package/package.json +50 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export const MAX_SYMLINK_DEPTH = 40;
|
|
2
|
+
export const DEFAULT_DIR_MODE = 0o755;
|
|
3
|
+
export const DEFAULT_FILE_MODE = 0o644;
|
|
4
|
+
export const SYMLINK_MODE = 0o777;
|
|
5
|
+
export function normalizePath(path) {
|
|
6
|
+
if (!path || path === '/')
|
|
7
|
+
return '/';
|
|
8
|
+
let normalized = path.endsWith('/') && path !== '/' ? path.slice(0, -1) : path;
|
|
9
|
+
if (!normalized.startsWith('/')) {
|
|
10
|
+
normalized = `/${normalized}`;
|
|
11
|
+
}
|
|
12
|
+
const parts = normalized.split('/').filter((p) => p && p !== '.');
|
|
13
|
+
const resolved = [];
|
|
14
|
+
for (const part of parts) {
|
|
15
|
+
if (part === '..') {
|
|
16
|
+
resolved.pop();
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
resolved.push(part);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return `/${resolved.join('/')}`;
|
|
23
|
+
}
|
|
24
|
+
export function validatePath(path, operation) {
|
|
25
|
+
if (path.includes('\0')) {
|
|
26
|
+
throw new Error(`ENOENT: path contains null byte, ${operation} '${path}'`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function dirname(path) {
|
|
30
|
+
const normalized = normalizePath(path);
|
|
31
|
+
if (normalized === '/')
|
|
32
|
+
return '/';
|
|
33
|
+
const lastSlash = normalized.lastIndexOf('/');
|
|
34
|
+
return lastSlash === 0 ? '/' : normalized.slice(0, lastSlash);
|
|
35
|
+
}
|
|
36
|
+
export function resolvePath(base, path) {
|
|
37
|
+
if (path.startsWith('/')) {
|
|
38
|
+
return normalizePath(path);
|
|
39
|
+
}
|
|
40
|
+
const combined = base === '/' ? `/${path}` : `${base}/${path}`;
|
|
41
|
+
return normalizePath(combined);
|
|
42
|
+
}
|
|
43
|
+
export function joinPath(parent, child) {
|
|
44
|
+
return parent === '/' ? `/${child}` : `${parent}/${child}`;
|
|
45
|
+
}
|
|
46
|
+
export function resolveSymlinkTarget(symlinkPath, target) {
|
|
47
|
+
if (target.startsWith('/')) {
|
|
48
|
+
return normalizePath(target);
|
|
49
|
+
}
|
|
50
|
+
const dir = dirname(symlinkPath);
|
|
51
|
+
return normalizePath(joinPath(dir, target));
|
|
52
|
+
}
|
|
53
|
+
export function createGlobMatcher(pattern) {
|
|
54
|
+
let i = 0;
|
|
55
|
+
let re = '^';
|
|
56
|
+
while (i < pattern.length) {
|
|
57
|
+
const ch = pattern[i];
|
|
58
|
+
if (ch === '*') {
|
|
59
|
+
if (pattern[i + 1] === '*') {
|
|
60
|
+
i += 2;
|
|
61
|
+
if (pattern[i] === '/') {
|
|
62
|
+
re += '(?:.+/)?';
|
|
63
|
+
i++;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
re += '.*';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
re += '[^/]*';
|
|
71
|
+
i++;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (ch === '?') {
|
|
75
|
+
re += '[^/]';
|
|
76
|
+
i++;
|
|
77
|
+
}
|
|
78
|
+
else if (ch === '[') {
|
|
79
|
+
const close = pattern.indexOf(']', i + 1);
|
|
80
|
+
if (close === -1) {
|
|
81
|
+
re += '\\[';
|
|
82
|
+
i++;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
re += pattern.slice(i, close + 1);
|
|
86
|
+
i = close + 1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (ch === '{') {
|
|
90
|
+
const close = pattern.indexOf('}', i + 1);
|
|
91
|
+
if (close === -1) {
|
|
92
|
+
re += '\\{';
|
|
93
|
+
i++;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const inner = pattern
|
|
97
|
+
.slice(i + 1, close)
|
|
98
|
+
.split(',')
|
|
99
|
+
.join('|');
|
|
100
|
+
re += `(?:${inner})`;
|
|
101
|
+
i = close + 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
re += ch.replace(/[.+^$|\\()]/g, '\\$&');
|
|
106
|
+
i++;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
re += '$';
|
|
110
|
+
return new RegExp(re);
|
|
111
|
+
}
|
|
112
|
+
export function sortPaths(paths) {
|
|
113
|
+
return [...paths].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
114
|
+
}
|
package/dist/tool.d.ts
ADDED
package/dist/tool.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// `createFsTool` lives in `@kuralle-agents/core` (it needs only `defineTool` + the
|
|
2
|
+
// `FileSystem` interface, both core-owned), so the runtime can auto-register it with a
|
|
3
|
+
// static import and no core->fs dependency cycle (RFC-02 §5.2). Re-exported here for the
|
|
4
|
+
// `@kuralle-agents/fs` public API.
|
|
5
|
+
export { createFsTool } from '@kuralle-agents/core';
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kuralle-agents/fs",
|
|
3
|
+
"license": "Apache-2.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/kuralle/kuralle-agents.git",
|
|
7
|
+
"directory": "packages/kuralle-fs"
|
|
8
|
+
},
|
|
9
|
+
"version": "0.6.0",
|
|
10
|
+
"description": "Portable filesystem primitive for Kuralle agents",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@kuralle-agents/core": "0.6.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"zod": "^3.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@cloudflare/vitest-pool-workers": "^0.12.7",
|
|
28
|
+
"@types/node": "^20.11.0",
|
|
29
|
+
"bun-types": "^1.3.0",
|
|
30
|
+
"typescript": "^5.3.0",
|
|
31
|
+
"vitest": "^3.2.4",
|
|
32
|
+
"zod": "^3.23.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"prebuild": "rm -rf dist",
|
|
43
|
+
"build": "tsc -p tsconfig.json",
|
|
44
|
+
"clean": "rm -rf dist",
|
|
45
|
+
"test": "bun test test/in-memory-fs.test.ts test/fs-tool.test.ts test/composite-fs.test.ts && vitest run --config vitest.config.ts",
|
|
46
|
+
"test:inmemoryfs": "bun test test/in-memory-fs.test.ts",
|
|
47
|
+
"test:fs-tool": "bun test test/fs-tool.test.ts",
|
|
48
|
+
"test:fs-workers": "vitest run --config vitest.config.ts"
|
|
49
|
+
}
|
|
50
|
+
}
|