@lousy-agents/mcp 5.14.1 → 5.14.2
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/mcp-server.js +3864 -182
- package/package.json +1 -1
package/dist/mcp-server.js
CHANGED
|
@@ -6559,7 +6559,7 @@ function escapeJsonPtr(str) {
|
|
|
6559
6559
|
|
|
6560
6560
|
|
|
6561
6561
|
},
|
|
6562
|
-
|
|
6562
|
+
2415(__unused_rspack_module, __unused_rspack___webpack_exports__, __webpack_require__) {
|
|
6563
6563
|
// NAMESPACE OBJECT: ../../node_modules/micromark/lib/constructs.js
|
|
6564
6564
|
var constructs_namespaceObject = {};
|
|
6565
6565
|
__webpack_require__.r(constructs_namespaceObject);
|
|
@@ -26479,8 +26479,6 @@ const EMPTY_COMPLETION_RESULT = {
|
|
|
26479
26479
|
}
|
|
26480
26480
|
};
|
|
26481
26481
|
//# sourceMappingURL=mcp.js.map
|
|
26482
|
-
// EXTERNAL MODULE: external "node:fs/promises"
|
|
26483
|
-
var promises_ = __webpack_require__(1455);
|
|
26484
26482
|
// EXTERNAL MODULE: external "node:path"
|
|
26485
26483
|
var external_node_path_ = __webpack_require__(6760);
|
|
26486
26484
|
;// CONCATENATED MODULE: ../core/src/gateways/action-version-gateway.ts
|
|
@@ -26506,34 +26504,3651 @@ var external_node_path_ = __webpack_require__(6760);
|
|
|
26506
26504
|
// Simulate async lookup (for future remote API compatibility)
|
|
26507
26505
|
return DEFAULT_ACTION_VERSIONS[actionName];
|
|
26508
26506
|
}
|
|
26509
|
-
async getVersions(actionNames) {
|
|
26510
|
-
const result = {};
|
|
26511
|
-
for (const actionName of actionNames){
|
|
26512
|
-
const version = await this.getVersion(actionName);
|
|
26513
|
-
if (version) {
|
|
26514
|
-
result[actionName] = version;
|
|
26507
|
+
async getVersions(actionNames) {
|
|
26508
|
+
const result = {};
|
|
26509
|
+
for (const actionName of actionNames){
|
|
26510
|
+
const version = await this.getVersion(actionName);
|
|
26511
|
+
if (version) {
|
|
26512
|
+
result[actionName] = version;
|
|
26513
|
+
}
|
|
26514
|
+
}
|
|
26515
|
+
return result;
|
|
26516
|
+
}
|
|
26517
|
+
}
|
|
26518
|
+
/**
|
|
26519
|
+
* Creates and returns the default action version gateway
|
|
26520
|
+
*/ function createActionVersionGateway() {
|
|
26521
|
+
return new LocalActionVersionGateway();
|
|
26522
|
+
}
|
|
26523
|
+
/**
|
|
26524
|
+
* List of known action names for convenience
|
|
26525
|
+
*/ const KNOWN_ACTIONS = Object.keys(DEFAULT_ACTION_VERSIONS);
|
|
26526
|
+
|
|
26527
|
+
// EXTERNAL MODULE: external "node:fs/promises"
|
|
26528
|
+
var promises_ = __webpack_require__(1455);
|
|
26529
|
+
// EXTERNAL MODULE: external "node:fs"
|
|
26530
|
+
var external_node_fs_ = __webpack_require__(3024);
|
|
26531
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/errors.js
|
|
26532
|
+
const OPERATIONAL_CODES = new Set([
|
|
26533
|
+
"helper-failed",
|
|
26534
|
+
"helper-unavailable",
|
|
26535
|
+
"permission-unverified",
|
|
26536
|
+
"timeout",
|
|
26537
|
+
"unsupported-platform",
|
|
26538
|
+
]);
|
|
26539
|
+
function categorizeFsSafeError(code) {
|
|
26540
|
+
return OPERATIONAL_CODES.has(code) ? "operational" : "policy";
|
|
26541
|
+
}
|
|
26542
|
+
class errors_FsSafeError extends Error {
|
|
26543
|
+
code;
|
|
26544
|
+
category;
|
|
26545
|
+
constructor(code, message, options = {}) {
|
|
26546
|
+
super(message, options);
|
|
26547
|
+
this.name = "FsSafeError";
|
|
26548
|
+
this.code = code;
|
|
26549
|
+
this.category = categorizeFsSafeError(code);
|
|
26550
|
+
}
|
|
26551
|
+
}
|
|
26552
|
+
|
|
26553
|
+
// EXTERNAL MODULE: external "node:crypto"
|
|
26554
|
+
var external_node_crypto_ = __webpack_require__(7598);
|
|
26555
|
+
// EXTERNAL MODULE: external "node:stream/promises"
|
|
26556
|
+
var external_node_stream_promises_ = __webpack_require__(6466);
|
|
26557
|
+
// EXTERNAL MODULE: external "node:stream"
|
|
26558
|
+
var external_node_stream_ = __webpack_require__(7075);
|
|
26559
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/bounded-read-stream.js
|
|
26560
|
+
|
|
26561
|
+
|
|
26562
|
+
function createMaxBytesTransform(maxBytes) {
|
|
26563
|
+
let bytes = 0;
|
|
26564
|
+
return new external_node_stream_.Transform({
|
|
26565
|
+
transform(chunk, _encoding, callback) {
|
|
26566
|
+
const buffer = chunk instanceof Buffer ? chunk : Buffer.from(chunk);
|
|
26567
|
+
bytes += buffer.byteLength;
|
|
26568
|
+
if (bytes > maxBytes) {
|
|
26569
|
+
callback(new errors_FsSafeError("too-large", `file exceeds limit of ${maxBytes} bytes (got at least ${bytes})`));
|
|
26570
|
+
return;
|
|
26571
|
+
}
|
|
26572
|
+
callback(null, buffer);
|
|
26573
|
+
},
|
|
26574
|
+
});
|
|
26575
|
+
}
|
|
26576
|
+
function createBoundedReadStream(opened, maxBytes) {
|
|
26577
|
+
const stream = opened.handle.createReadStream();
|
|
26578
|
+
return maxBytes === undefined ? stream : stream.pipe(createMaxBytesTransform(maxBytes));
|
|
26579
|
+
}
|
|
26580
|
+
|
|
26581
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/file-identity.js
|
|
26582
|
+
function isZero(value) {
|
|
26583
|
+
return value === 0 || value === 0n;
|
|
26584
|
+
}
|
|
26585
|
+
function file_identity_sameFileIdentity(left, right, platform = process.platform) {
|
|
26586
|
+
if (left.ino !== right.ino) {
|
|
26587
|
+
return false;
|
|
26588
|
+
}
|
|
26589
|
+
// On Windows, path-based stat calls can report dev=0 while fd-based stat
|
|
26590
|
+
// reports a real volume serial; treat either-side dev=0 as "unknown device".
|
|
26591
|
+
if (left.dev === right.dev) {
|
|
26592
|
+
return true;
|
|
26593
|
+
}
|
|
26594
|
+
return platform === "win32" && (isZero(left.dev) || isZero(right.dev));
|
|
26595
|
+
}
|
|
26596
|
+
|
|
26597
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/string-coerce.js
|
|
26598
|
+
function readStringValue(value) {
|
|
26599
|
+
return typeof value === "string" ? value : undefined;
|
|
26600
|
+
}
|
|
26601
|
+
function normalizeNullableString(value) {
|
|
26602
|
+
if (typeof value !== "string") {
|
|
26603
|
+
return null;
|
|
26604
|
+
}
|
|
26605
|
+
const trimmed = value.trim();
|
|
26606
|
+
return trimmed ? trimmed : null;
|
|
26607
|
+
}
|
|
26608
|
+
function normalizeOptionalString(value) {
|
|
26609
|
+
return normalizeNullableString(value) ?? undefined;
|
|
26610
|
+
}
|
|
26611
|
+
function normalizeStringifiedOptionalString(value) {
|
|
26612
|
+
if (typeof value === "string") {
|
|
26613
|
+
return normalizeOptionalString(value);
|
|
26614
|
+
}
|
|
26615
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
26616
|
+
return normalizeOptionalString(String(value));
|
|
26617
|
+
}
|
|
26618
|
+
return undefined;
|
|
26619
|
+
}
|
|
26620
|
+
function normalizeOptionalLowercaseString(value) {
|
|
26621
|
+
return normalizeOptionalString(value)?.toLowerCase();
|
|
26622
|
+
}
|
|
26623
|
+
function normalizeLowercaseStringOrEmpty(value) {
|
|
26624
|
+
return normalizeOptionalLowercaseString(value) ?? "";
|
|
26625
|
+
}
|
|
26626
|
+
function normalizeFastMode(raw) {
|
|
26627
|
+
if (typeof raw === "boolean") {
|
|
26628
|
+
return raw;
|
|
26629
|
+
}
|
|
26630
|
+
if (!raw) {
|
|
26631
|
+
return undefined;
|
|
26632
|
+
}
|
|
26633
|
+
const key = normalizeLowercaseStringOrEmpty(raw);
|
|
26634
|
+
if (["off", "false", "no", "0", "disable", "disabled", "normal"].includes(key)) {
|
|
26635
|
+
return false;
|
|
26636
|
+
}
|
|
26637
|
+
if (["on", "true", "yes", "1", "enable", "enabled", "fast"].includes(key)) {
|
|
26638
|
+
return true;
|
|
26639
|
+
}
|
|
26640
|
+
return undefined;
|
|
26641
|
+
}
|
|
26642
|
+
function lowercasePreservingWhitespace(value) {
|
|
26643
|
+
return value.toLowerCase();
|
|
26644
|
+
}
|
|
26645
|
+
function localeLowercasePreservingWhitespace(value) {
|
|
26646
|
+
return value.toLocaleLowerCase();
|
|
26647
|
+
}
|
|
26648
|
+
function resolvePrimaryStringValue(value) {
|
|
26649
|
+
if (typeof value === "string") {
|
|
26650
|
+
return normalizeOptionalString(value);
|
|
26651
|
+
}
|
|
26652
|
+
if (!value || typeof value !== "object") {
|
|
26653
|
+
return undefined;
|
|
26654
|
+
}
|
|
26655
|
+
return normalizeOptionalString(value.primary);
|
|
26656
|
+
}
|
|
26657
|
+
function normalizeOptionalThreadValue(value) {
|
|
26658
|
+
if (typeof value === "number") {
|
|
26659
|
+
return Number.isFinite(value) ? Math.trunc(value) : undefined;
|
|
26660
|
+
}
|
|
26661
|
+
return normalizeOptionalString(value);
|
|
26662
|
+
}
|
|
26663
|
+
function normalizeOptionalStringifiedId(value) {
|
|
26664
|
+
const normalized = normalizeOptionalThreadValue(value);
|
|
26665
|
+
return normalized == null ? undefined : String(normalized);
|
|
26666
|
+
}
|
|
26667
|
+
function hasNonEmptyString(value) {
|
|
26668
|
+
return normalizeOptionalString(value) !== undefined;
|
|
26669
|
+
}
|
|
26670
|
+
|
|
26671
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/path.js
|
|
26672
|
+
|
|
26673
|
+
|
|
26674
|
+
|
|
26675
|
+
|
|
26676
|
+
const NOT_FOUND_CODES = new Set(["ENOENT", "ENOTDIR"]);
|
|
26677
|
+
const SYMLINK_OPEN_CODES = new Set(["ELOOP", "EINVAL", "ENOTSUP"]);
|
|
26678
|
+
const POSIX_SEPARATOR_CHAR_CODE = 0x2f;
|
|
26679
|
+
function normalizeWindowsPathForComparison(input) {
|
|
26680
|
+
let normalized = external_node_path_.win32.normalize(input);
|
|
26681
|
+
if (normalized.startsWith("\\\\?\\")) {
|
|
26682
|
+
normalized = normalized.slice(4);
|
|
26683
|
+
if (normalized.toUpperCase().startsWith("UNC\\")) {
|
|
26684
|
+
normalized = `\\\\${normalized.slice(4)}`;
|
|
26685
|
+
}
|
|
26686
|
+
}
|
|
26687
|
+
return normalizeLowercaseStringOrEmpty(normalized.replaceAll("/", "\\"));
|
|
26688
|
+
}
|
|
26689
|
+
function isNodeError(value) {
|
|
26690
|
+
return Boolean(value && typeof value === "object" && "code" in value);
|
|
26691
|
+
}
|
|
26692
|
+
function hasNodeErrorCode(value, code) {
|
|
26693
|
+
return isNodeError(value) && value.code === code;
|
|
26694
|
+
}
|
|
26695
|
+
function path_assertNoNulPathInput(filePath, message = "path contains a NUL byte") {
|
|
26696
|
+
if (filePath.includes("\0")) {
|
|
26697
|
+
throw new errors_FsSafeError("invalid-path", message);
|
|
26698
|
+
}
|
|
26699
|
+
}
|
|
26700
|
+
function path_isNotFoundPathError(value) {
|
|
26701
|
+
return isNodeError(value) && typeof value.code === "string" && NOT_FOUND_CODES.has(value.code);
|
|
26702
|
+
}
|
|
26703
|
+
function isSymlinkOpenError(value) {
|
|
26704
|
+
return isNodeError(value) && typeof value.code === "string" && SYMLINK_OPEN_CODES.has(value.code);
|
|
26705
|
+
}
|
|
26706
|
+
function path_isPathInside(root, target) {
|
|
26707
|
+
if (process.platform === "win32") {
|
|
26708
|
+
const rootForCompare = normalizeWindowsPathForComparison(external_node_path_.win32.resolve(root));
|
|
26709
|
+
const targetForCompare = normalizeWindowsPathForComparison(external_node_path_.win32.resolve(target));
|
|
26710
|
+
const relative = external_node_path_.win32.relative(rootForCompare, targetForCompare);
|
|
26711
|
+
const firstSegment = relative.split(external_node_path_.win32.sep)[0];
|
|
26712
|
+
return (relative === "" || (firstSegment !== ".." && !external_node_path_.win32.isAbsolute(relative)));
|
|
26713
|
+
}
|
|
26714
|
+
if (root.length > 0 &&
|
|
26715
|
+
root.charCodeAt(0) === POSIX_SEPARATOR_CHAR_CODE &&
|
|
26716
|
+
target.length >= root.length &&
|
|
26717
|
+
target.charCodeAt(0) === POSIX_SEPARATOR_CHAR_CODE &&
|
|
26718
|
+
!target.includes("/..") &&
|
|
26719
|
+
(target === root ||
|
|
26720
|
+
(target.startsWith(root) && target.charCodeAt(root.length) === POSIX_SEPARATOR_CHAR_CODE))) {
|
|
26721
|
+
return true;
|
|
26722
|
+
}
|
|
26723
|
+
const resolvedRoot = external_node_path_.resolve(root);
|
|
26724
|
+
const resolvedTarget = external_node_path_.resolve(target);
|
|
26725
|
+
const relative = external_node_path_.relative(resolvedRoot, resolvedTarget);
|
|
26726
|
+
const firstSegment = relative.split(external_node_path_.posix.sep)[0];
|
|
26727
|
+
return relative === "" || (firstSegment !== ".." && !external_node_path_.isAbsolute(relative));
|
|
26728
|
+
}
|
|
26729
|
+
function resolveSafeBaseDir(rootDir) {
|
|
26730
|
+
const resolved = path.resolve(rootDir);
|
|
26731
|
+
return resolved.endsWith(path.sep) ? resolved : `${resolved}${path.sep}`;
|
|
26732
|
+
}
|
|
26733
|
+
function isWithinDir(rootDir, targetPath) {
|
|
26734
|
+
return path_isPathInside(rootDir, targetPath);
|
|
26735
|
+
}
|
|
26736
|
+
function safeRealpathSync(targetPath, cache) {
|
|
26737
|
+
const cached = cache?.get(targetPath);
|
|
26738
|
+
if (cached) {
|
|
26739
|
+
return cached;
|
|
26740
|
+
}
|
|
26741
|
+
try {
|
|
26742
|
+
const resolved = fs.realpathSync(targetPath);
|
|
26743
|
+
cache?.set(targetPath, resolved);
|
|
26744
|
+
cache?.set(resolved, resolved);
|
|
26745
|
+
return resolved;
|
|
26746
|
+
}
|
|
26747
|
+
catch {
|
|
26748
|
+
return null;
|
|
26749
|
+
}
|
|
26750
|
+
}
|
|
26751
|
+
function isPathInsideWithRealpath(basePath, candidatePath, opts) {
|
|
26752
|
+
if (!path_isPathInside(basePath, candidatePath)) {
|
|
26753
|
+
return false;
|
|
26754
|
+
}
|
|
26755
|
+
const baseReal = safeRealpathSync(basePath, opts?.cache);
|
|
26756
|
+
const candidateReal = safeRealpathSync(candidatePath, opts?.cache);
|
|
26757
|
+
if (!baseReal || !candidateReal) {
|
|
26758
|
+
return opts?.requireRealpath === false;
|
|
26759
|
+
}
|
|
26760
|
+
return path_isPathInside(baseReal, candidateReal);
|
|
26761
|
+
}
|
|
26762
|
+
function safeStatSync(targetPath) {
|
|
26763
|
+
try {
|
|
26764
|
+
return fs.statSync(targetPath);
|
|
26765
|
+
}
|
|
26766
|
+
catch {
|
|
26767
|
+
return null;
|
|
26768
|
+
}
|
|
26769
|
+
}
|
|
26770
|
+
function splitSafeRelativePath(relativePath) {
|
|
26771
|
+
if (relativePath.length === 0 || relativePath === ".") {
|
|
26772
|
+
return [];
|
|
26773
|
+
}
|
|
26774
|
+
path_assertNoNulPathInput(relativePath, "relative path contains a NUL byte");
|
|
26775
|
+
if (relativePath.includes("\\")) {
|
|
26776
|
+
throw new FsSafeError("invalid-path", "relative path must use forward slashes");
|
|
26777
|
+
}
|
|
26778
|
+
if (path.posix.isAbsolute(relativePath) ||
|
|
26779
|
+
path.win32.isAbsolute(relativePath) ||
|
|
26780
|
+
relativePath.startsWith("//")) {
|
|
26781
|
+
throw new FsSafeError("invalid-path", "relative path must not be absolute");
|
|
26782
|
+
}
|
|
26783
|
+
const segments = relativePath.split("/").filter((segment) => segment.length > 0 && segment !== ".");
|
|
26784
|
+
for (const segment of segments) {
|
|
26785
|
+
if (segment === "..") {
|
|
26786
|
+
throw new FsSafeError("invalid-path", "relative path must not contain '..'");
|
|
26787
|
+
}
|
|
26788
|
+
}
|
|
26789
|
+
return segments;
|
|
26790
|
+
}
|
|
26791
|
+
function resolveSafeRelativePath(rootDir, relativePath) {
|
|
26792
|
+
const root = path.resolve(rootDir);
|
|
26793
|
+
const target = path.resolve(root, ...splitSafeRelativePath(relativePath));
|
|
26794
|
+
if (target !== root && !target.startsWith(root + path.sep)) {
|
|
26795
|
+
throw new FsSafeError("outside-workspace", "relative path escapes root");
|
|
26796
|
+
}
|
|
26797
|
+
return target;
|
|
26798
|
+
}
|
|
26799
|
+
|
|
26800
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/directory-guard.js
|
|
26801
|
+
|
|
26802
|
+
|
|
26803
|
+
|
|
26804
|
+
|
|
26805
|
+
|
|
26806
|
+
|
|
26807
|
+
async function directory_guard_createAsyncDirectoryGuard(dir) {
|
|
26808
|
+
const stat = await promises_.lstat(dir);
|
|
26809
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
26810
|
+
throw new errors_FsSafeError("not-file", "directory component must be a directory");
|
|
26811
|
+
}
|
|
26812
|
+
return { dir, realPath: await promises_.realpath(dir), stat };
|
|
26813
|
+
}
|
|
26814
|
+
async function assertAsyncDirectoryGuard(guard) {
|
|
26815
|
+
const stat = await promises_.lstat(guard.dir);
|
|
26816
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
26817
|
+
throw new errors_FsSafeError("not-file", "directory component must be a directory");
|
|
26818
|
+
}
|
|
26819
|
+
if (!file_identity_sameFileIdentity(stat, guard.stat) || (await promises_.realpath(guard.dir)) !== guard.realPath) {
|
|
26820
|
+
throw new errors_FsSafeError("path-mismatch", "directory changed during operation");
|
|
26821
|
+
}
|
|
26822
|
+
}
|
|
26823
|
+
function directory_guard_createSyncDirectoryGuard(dir) {
|
|
26824
|
+
const stat = fsSync.lstatSync(dir);
|
|
26825
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
26826
|
+
throw new FsSafeError("not-file", "directory component must be a directory");
|
|
26827
|
+
}
|
|
26828
|
+
return { dir, realPath: fsSync.realpathSync(dir), stat };
|
|
26829
|
+
}
|
|
26830
|
+
function directory_guard_assertSyncDirectoryGuard(guard) {
|
|
26831
|
+
const stat = fsSync.lstatSync(guard.dir);
|
|
26832
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
26833
|
+
throw new FsSafeError("not-file", "directory component must be a directory");
|
|
26834
|
+
}
|
|
26835
|
+
if (!sameFileIdentity(stat, guard.stat) || fsSync.realpathSync(guard.dir) !== guard.realPath) {
|
|
26836
|
+
throw new FsSafeError("path-mismatch", "directory changed during operation");
|
|
26837
|
+
}
|
|
26838
|
+
}
|
|
26839
|
+
async function directory_guard_createNearestExistingDirectoryGuard(rootReal, targetPath) {
|
|
26840
|
+
let current = external_node_path_.resolve(targetPath);
|
|
26841
|
+
const root = external_node_path_.resolve(rootReal);
|
|
26842
|
+
while (current !== root) {
|
|
26843
|
+
try {
|
|
26844
|
+
return await directory_guard_createAsyncDirectoryGuard(current);
|
|
26845
|
+
}
|
|
26846
|
+
catch (error) {
|
|
26847
|
+
if (!path_isNotFoundPathError(error)) {
|
|
26848
|
+
throw error;
|
|
26849
|
+
}
|
|
26850
|
+
current = external_node_path_.dirname(current);
|
|
26851
|
+
}
|
|
26852
|
+
}
|
|
26853
|
+
return await directory_guard_createAsyncDirectoryGuard(root);
|
|
26854
|
+
}
|
|
26855
|
+
function directory_guard_createNearestExistingSyncDirectoryGuard(rootReal, targetPath) {
|
|
26856
|
+
let current = path.resolve(targetPath);
|
|
26857
|
+
const root = path.resolve(rootReal);
|
|
26858
|
+
while (current !== root) {
|
|
26859
|
+
try {
|
|
26860
|
+
return directory_guard_createSyncDirectoryGuard(current);
|
|
26861
|
+
}
|
|
26862
|
+
catch (error) {
|
|
26863
|
+
if (!isNotFoundPathError(error)) {
|
|
26864
|
+
throw error;
|
|
26865
|
+
}
|
|
26866
|
+
current = path.dirname(current);
|
|
26867
|
+
}
|
|
26868
|
+
}
|
|
26869
|
+
return directory_guard_createSyncDirectoryGuard(root);
|
|
26870
|
+
}
|
|
26871
|
+
|
|
26872
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/guarded-mkdir.js
|
|
26873
|
+
|
|
26874
|
+
|
|
26875
|
+
|
|
26876
|
+
|
|
26877
|
+
function isSameOrChildPath(candidate, parent) {
|
|
26878
|
+
return candidate === parent || candidate.startsWith(`${parent}${external_node_path_.sep}`);
|
|
26879
|
+
}
|
|
26880
|
+
function isPathEscape(relativePath) {
|
|
26881
|
+
return relativePath === ".." || relativePath.startsWith(`..${external_node_path_.sep}`) || external_node_path_.isAbsolute(relativePath);
|
|
26882
|
+
}
|
|
26883
|
+
async function mkdirPathComponentsWithGuards(params) {
|
|
26884
|
+
const root = external_node_path_.resolve(params.rootReal);
|
|
26885
|
+
const target = external_node_path_.resolve(params.targetPath);
|
|
26886
|
+
const relative = external_node_path_.relative(root, target);
|
|
26887
|
+
if (isPathEscape(relative)) {
|
|
26888
|
+
throw new errors_FsSafeError("outside-workspace", "directory is outside workspace root");
|
|
26889
|
+
}
|
|
26890
|
+
let current = root;
|
|
26891
|
+
for (const part of relative.split(external_node_path_.sep).filter(Boolean)) {
|
|
26892
|
+
const next = external_node_path_.join(current, part);
|
|
26893
|
+
const parentGuard = await directory_guard_createAsyncDirectoryGuard(current);
|
|
26894
|
+
await params.beforeComponent?.(next);
|
|
26895
|
+
await assertAsyncDirectoryGuard(parentGuard);
|
|
26896
|
+
try {
|
|
26897
|
+
await promises_.mkdir(next);
|
|
26898
|
+
}
|
|
26899
|
+
catch (error) {
|
|
26900
|
+
if (!error || typeof error !== "object" || !("code" in error) || error.code !== "EEXIST") {
|
|
26901
|
+
throw error;
|
|
26902
|
+
}
|
|
26903
|
+
}
|
|
26904
|
+
const stat = await promises_.lstat(next);
|
|
26905
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
26906
|
+
throw new errors_FsSafeError("not-file", "directory component must be a directory");
|
|
26907
|
+
}
|
|
26908
|
+
// Node's recursive mkdir follows symlinks in missing components. Build one
|
|
26909
|
+
// segment at a time and realpath-check each segment before descending.
|
|
26910
|
+
if (!isSameOrChildPath(external_node_path_.resolve(await promises_.realpath(next)), root)) {
|
|
26911
|
+
throw new errors_FsSafeError("outside-workspace", "directory escaped workspace root");
|
|
26912
|
+
}
|
|
26913
|
+
await directory_guard_createAsyncDirectoryGuard(next);
|
|
26914
|
+
await assertAsyncDirectoryGuard(parentGuard);
|
|
26915
|
+
current = next;
|
|
26916
|
+
}
|
|
26917
|
+
}
|
|
26918
|
+
|
|
26919
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/guarded-mutation.js
|
|
26920
|
+
|
|
26921
|
+
|
|
26922
|
+
|
|
26923
|
+
|
|
26924
|
+
async function withAsyncDirectoryGuards(guards, mutate, options = {}) {
|
|
26925
|
+
for (const guard of guards) {
|
|
26926
|
+
await assertAsyncDirectoryGuard(guard);
|
|
26927
|
+
}
|
|
26928
|
+
const result = await mutate();
|
|
26929
|
+
if (options.verifyAfter !== false) {
|
|
26930
|
+
try {
|
|
26931
|
+
for (const guard of guards) {
|
|
26932
|
+
await assertAsyncDirectoryGuard(guard);
|
|
26933
|
+
}
|
|
26934
|
+
}
|
|
26935
|
+
catch (error) {
|
|
26936
|
+
if (options.onPostGuardFailure) {
|
|
26937
|
+
try {
|
|
26938
|
+
// The mutation may have returned an owned resource before the post-guard
|
|
26939
|
+
// check detected a swapped directory. Give callers one chance to close
|
|
26940
|
+
// handles without letting cleanup hide the boundary failure.
|
|
26941
|
+
await options.onPostGuardFailure(result, error);
|
|
26942
|
+
}
|
|
26943
|
+
catch {
|
|
26944
|
+
// Preserve the boundary failure. Cleanup is best-effort.
|
|
26945
|
+
}
|
|
26946
|
+
}
|
|
26947
|
+
throw error;
|
|
26948
|
+
}
|
|
26949
|
+
}
|
|
26950
|
+
return result;
|
|
26951
|
+
}
|
|
26952
|
+
function withSyncDirectoryGuards(guards, mutate, options = {}) {
|
|
26953
|
+
for (const guard of guards) {
|
|
26954
|
+
assertSyncDirectoryGuard(guard);
|
|
26955
|
+
}
|
|
26956
|
+
const result = mutate();
|
|
26957
|
+
if (options.verifyAfter !== false) {
|
|
26958
|
+
for (const guard of guards) {
|
|
26959
|
+
assertSyncDirectoryGuard(guard);
|
|
26960
|
+
}
|
|
26961
|
+
}
|
|
26962
|
+
return result;
|
|
26963
|
+
}
|
|
26964
|
+
async function guardedRename(params) {
|
|
26965
|
+
const sourceGuard = await createAsyncDirectoryGuard(path.dirname(params.from));
|
|
26966
|
+
const targetGuard = params.targetRoot
|
|
26967
|
+
? await createNearestExistingDirectoryGuard(params.targetRoot, path.dirname(params.to))
|
|
26968
|
+
: await createAsyncDirectoryGuard(path.dirname(params.to));
|
|
26969
|
+
await withAsyncDirectoryGuards([sourceGuard, targetGuard], async () => {
|
|
26970
|
+
await fs.rename(params.from, params.to);
|
|
26971
|
+
}, { verifyAfter: params.verifyAfter });
|
|
26972
|
+
}
|
|
26973
|
+
function guardedRenameSync(params) {
|
|
26974
|
+
const sourceGuard = createSyncDirectoryGuard(path.dirname(params.from));
|
|
26975
|
+
const targetGuard = params.targetRoot
|
|
26976
|
+
? createNearestExistingSyncDirectoryGuard(params.targetRoot, path.dirname(params.to))
|
|
26977
|
+
: createSyncDirectoryGuard(path.dirname(params.to));
|
|
26978
|
+
withSyncDirectoryGuards([sourceGuard, targetGuard], () => fsSync.renameSync(params.from, params.to), { verifyAfter: params.verifyAfter });
|
|
26979
|
+
}
|
|
26980
|
+
async function guardedRm(params) {
|
|
26981
|
+
const guard = await createAsyncDirectoryGuard(path.dirname(params.target));
|
|
26982
|
+
await withAsyncDirectoryGuards([guard], async () => {
|
|
26983
|
+
await fs.rm(params.target, {
|
|
26984
|
+
...(params.recursive !== undefined ? { recursive: params.recursive } : {}),
|
|
26985
|
+
...(params.force !== undefined ? { force: params.force } : {}),
|
|
26986
|
+
});
|
|
26987
|
+
}, { verifyAfter: params.verifyAfter });
|
|
26988
|
+
}
|
|
26989
|
+
function guardedRmSync(params) {
|
|
26990
|
+
const guard = createSyncDirectoryGuard(path.dirname(params.target));
|
|
26991
|
+
withSyncDirectoryGuards([guard], () => fsSync.rmSync(params.target, {
|
|
26992
|
+
...(params.recursive !== undefined ? { recursive: params.recursive } : {}),
|
|
26993
|
+
...(params.force !== undefined ? { force: params.force } : {}),
|
|
26994
|
+
}), { verifyAfter: params.verifyAfter });
|
|
26995
|
+
}
|
|
26996
|
+
|
|
26997
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/pinned-python-config.js
|
|
26998
|
+
let overrideConfig = {};
|
|
26999
|
+
function parseMode(value) {
|
|
27000
|
+
if (!value) {
|
|
27001
|
+
return undefined;
|
|
27002
|
+
}
|
|
27003
|
+
const normalized = value.trim().toLowerCase();
|
|
27004
|
+
if (normalized === "0" || normalized === "false" || normalized === "off" || normalized === "never") {
|
|
27005
|
+
return "off";
|
|
27006
|
+
}
|
|
27007
|
+
if (normalized === "1" || normalized === "true" || normalized === "on" || normalized === "auto") {
|
|
27008
|
+
return "auto";
|
|
27009
|
+
}
|
|
27010
|
+
if (normalized === "required" || normalized === "require") {
|
|
27011
|
+
return "require";
|
|
27012
|
+
}
|
|
27013
|
+
return undefined;
|
|
27014
|
+
}
|
|
27015
|
+
function configureFsSafePython(config) {
|
|
27016
|
+
overrideConfig = { ...overrideConfig, ...config };
|
|
27017
|
+
}
|
|
27018
|
+
function getFsSafePythonConfig() {
|
|
27019
|
+
return {
|
|
27020
|
+
mode: overrideConfig.mode ??
|
|
27021
|
+
parseMode(process.env.FS_SAFE_PYTHON_MODE) ??
|
|
27022
|
+
parseMode(process.env.OPENCLAW_FS_SAFE_PYTHON_MODE) ??
|
|
27023
|
+
"auto",
|
|
27024
|
+
pythonPath: overrideConfig.pythonPath ??
|
|
27025
|
+
process.env.FS_SAFE_PYTHON ??
|
|
27026
|
+
process.env.OPENCLAW_FS_SAFE_PYTHON ??
|
|
27027
|
+
process.env.OPENCLAW_PINNED_PYTHON ??
|
|
27028
|
+
process.env.OPENCLAW_PINNED_WRITE_PYTHON,
|
|
27029
|
+
};
|
|
27030
|
+
}
|
|
27031
|
+
function canFallbackFromPythonError(error) {
|
|
27032
|
+
return (getFsSafePythonConfig().mode !== "require" &&
|
|
27033
|
+
error instanceof Error &&
|
|
27034
|
+
"code" in error &&
|
|
27035
|
+
error.code === "helper-unavailable");
|
|
27036
|
+
}
|
|
27037
|
+
|
|
27038
|
+
// EXTERNAL MODULE: external "node:child_process"
|
|
27039
|
+
var external_node_child_process_ = __webpack_require__(1421);
|
|
27040
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/pinned-python.js
|
|
27041
|
+
|
|
27042
|
+
|
|
27043
|
+
|
|
27044
|
+
|
|
27045
|
+
const PINNED_PYTHON_WORKER_SOURCE = String.raw `
|
|
27046
|
+
import base64
|
|
27047
|
+
import errno
|
|
27048
|
+
import json
|
|
27049
|
+
import os
|
|
27050
|
+
import secrets
|
|
27051
|
+
import stat
|
|
27052
|
+
import sys
|
|
27053
|
+
|
|
27054
|
+
DIR_FLAGS = os.O_RDONLY
|
|
27055
|
+
if hasattr(os, "O_DIRECTORY"):
|
|
27056
|
+
DIR_FLAGS |= os.O_DIRECTORY
|
|
27057
|
+
if hasattr(os, "O_NOFOLLOW"):
|
|
27058
|
+
DIR_FLAGS |= os.O_NOFOLLOW
|
|
27059
|
+
READ_FLAGS = os.O_RDONLY
|
|
27060
|
+
if hasattr(os, "O_NOFOLLOW"):
|
|
27061
|
+
READ_FLAGS |= os.O_NOFOLLOW
|
|
27062
|
+
WRITE_FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL
|
|
27063
|
+
if hasattr(os, "O_NOFOLLOW"):
|
|
27064
|
+
WRITE_FLAGS |= os.O_NOFOLLOW
|
|
27065
|
+
|
|
27066
|
+
def split_relative(value):
|
|
27067
|
+
if value in ("", "."):
|
|
27068
|
+
return []
|
|
27069
|
+
if "\x00" in value or value.startswith("/") or value.startswith("//"):
|
|
27070
|
+
raise OSError(errno.EPERM, "invalid relative path")
|
|
27071
|
+
if value.startswith("..\\"):
|
|
27072
|
+
raise OSError(errno.EPERM, "path traversal is not allowed")
|
|
27073
|
+
parts = [part for part in value.split("/") if part and part != "."]
|
|
27074
|
+
for part in parts:
|
|
27075
|
+
if part == "..":
|
|
27076
|
+
raise OSError(errno.EPERM, "path traversal is not allowed")
|
|
27077
|
+
return parts
|
|
27078
|
+
|
|
27079
|
+
def open_dir(path_value, dir_fd=None):
|
|
27080
|
+
return os.open(path_value, DIR_FLAGS, dir_fd=dir_fd)
|
|
27081
|
+
|
|
27082
|
+
def walk_dir(root_fd, segments, mkdir_enabled=False):
|
|
27083
|
+
current_fd = os.dup(root_fd)
|
|
27084
|
+
try:
|
|
27085
|
+
for segment in segments:
|
|
27086
|
+
try:
|
|
27087
|
+
next_fd = open_dir(segment, dir_fd=current_fd)
|
|
27088
|
+
except FileNotFoundError:
|
|
27089
|
+
if not mkdir_enabled:
|
|
27090
|
+
raise
|
|
27091
|
+
os.mkdir(segment, 0o777, dir_fd=current_fd)
|
|
27092
|
+
next_fd = open_dir(segment, dir_fd=current_fd)
|
|
27093
|
+
os.close(current_fd)
|
|
27094
|
+
current_fd = next_fd
|
|
27095
|
+
return current_fd
|
|
27096
|
+
except Exception:
|
|
27097
|
+
os.close(current_fd)
|
|
27098
|
+
raise
|
|
27099
|
+
|
|
27100
|
+
def parent_and_basename(root_fd, relative):
|
|
27101
|
+
segments = split_relative(relative)
|
|
27102
|
+
if not segments:
|
|
27103
|
+
raise OSError(errno.EPERM, "operation requires a non-root path")
|
|
27104
|
+
parent_fd = walk_dir(root_fd, segments[:-1])
|
|
27105
|
+
return parent_fd, segments[-1]
|
|
27106
|
+
|
|
27107
|
+
def encode_stat(st):
|
|
27108
|
+
mode = st.st_mode
|
|
27109
|
+
return {
|
|
27110
|
+
"dev": st.st_dev,
|
|
27111
|
+
"gid": st.st_gid,
|
|
27112
|
+
"ino": st.st_ino,
|
|
27113
|
+
"isDirectory": stat.S_ISDIR(mode),
|
|
27114
|
+
"isFile": stat.S_ISREG(mode),
|
|
27115
|
+
"isSymbolicLink": stat.S_ISLNK(mode),
|
|
27116
|
+
"mode": mode,
|
|
27117
|
+
"mtimeMs": st.st_mtime * 1000,
|
|
27118
|
+
"nlink": st.st_nlink,
|
|
27119
|
+
"size": st.st_size,
|
|
27120
|
+
"uid": st.st_uid,
|
|
27121
|
+
}
|
|
27122
|
+
|
|
27123
|
+
def reject_unsafe_endpoint(st):
|
|
27124
|
+
mode = st.st_mode
|
|
27125
|
+
if stat.S_ISLNK(mode):
|
|
27126
|
+
raise OSError(errno.ELOOP, "symlink endpoint is not allowed")
|
|
27127
|
+
if stat.S_ISREG(mode) and st.st_nlink > 1:
|
|
27128
|
+
raise OSError(errno.EPERM, "hardlinked file endpoint is not allowed")
|
|
27129
|
+
|
|
27130
|
+
def stat_path(root_fd, payload):
|
|
27131
|
+
relative = payload.get("relativePath", "")
|
|
27132
|
+
segments = split_relative(relative)
|
|
27133
|
+
if not segments:
|
|
27134
|
+
return encode_stat(os.fstat(root_fd))
|
|
27135
|
+
parent_fd, basename = parent_and_basename(root_fd, relative)
|
|
27136
|
+
try:
|
|
27137
|
+
st = os.lstat(basename, dir_fd=parent_fd)
|
|
27138
|
+
if payload.get("rejectSymlink", True) and stat.S_ISLNK(st.st_mode):
|
|
27139
|
+
raise OSError(errno.ELOOP, "symlink endpoint is not allowed")
|
|
27140
|
+
return encode_stat(st)
|
|
27141
|
+
finally:
|
|
27142
|
+
os.close(parent_fd)
|
|
27143
|
+
|
|
27144
|
+
def readdir_path(root_fd, payload):
|
|
27145
|
+
dir_fd = walk_dir(root_fd, split_relative(payload.get("relativePath", "")))
|
|
27146
|
+
try:
|
|
27147
|
+
names = sorted(os.listdir(dir_fd))
|
|
27148
|
+
if not payload.get("withFileTypes", False):
|
|
27149
|
+
return names
|
|
27150
|
+
entries = []
|
|
27151
|
+
for name in names:
|
|
27152
|
+
st = os.lstat(name, dir_fd=dir_fd)
|
|
27153
|
+
entry = encode_stat(st)
|
|
27154
|
+
entry["name"] = name
|
|
27155
|
+
entries.append(entry)
|
|
27156
|
+
return entries
|
|
27157
|
+
finally:
|
|
27158
|
+
os.close(dir_fd)
|
|
27159
|
+
|
|
27160
|
+
def mkdirp_path(root_fd, payload):
|
|
27161
|
+
dir_fd = walk_dir(root_fd, split_relative(payload.get("relativePath", "")), mkdir_enabled=True)
|
|
27162
|
+
os.close(dir_fd)
|
|
27163
|
+
return None
|
|
27164
|
+
|
|
27165
|
+
def remove_tree(parent_fd, basename):
|
|
27166
|
+
st = os.lstat(basename, dir_fd=parent_fd)
|
|
27167
|
+
if stat.S_ISDIR(st.st_mode) and not stat.S_ISLNK(st.st_mode):
|
|
27168
|
+
dir_fd = open_dir(basename, dir_fd=parent_fd)
|
|
27169
|
+
try:
|
|
27170
|
+
for child in os.listdir(dir_fd):
|
|
27171
|
+
remove_tree(dir_fd, child)
|
|
27172
|
+
finally:
|
|
27173
|
+
os.close(dir_fd)
|
|
27174
|
+
os.rmdir(basename, dir_fd=parent_fd)
|
|
27175
|
+
else:
|
|
27176
|
+
os.unlink(basename, dir_fd=parent_fd)
|
|
27177
|
+
|
|
27178
|
+
def remove_path(root_fd, payload):
|
|
27179
|
+
parent_fd, basename = parent_and_basename(root_fd, payload.get("relativePath", ""))
|
|
27180
|
+
try:
|
|
27181
|
+
try:
|
|
27182
|
+
st = os.lstat(basename, dir_fd=parent_fd)
|
|
27183
|
+
except FileNotFoundError:
|
|
27184
|
+
if payload.get("force", True):
|
|
27185
|
+
return None
|
|
27186
|
+
raise
|
|
27187
|
+
if stat.S_ISDIR(st.st_mode) and not stat.S_ISLNK(st.st_mode):
|
|
27188
|
+
if payload.get("recursive", False):
|
|
27189
|
+
remove_tree(parent_fd, basename)
|
|
27190
|
+
else:
|
|
27191
|
+
os.rmdir(basename, dir_fd=parent_fd)
|
|
27192
|
+
else:
|
|
27193
|
+
os.unlink(basename, dir_fd=parent_fd)
|
|
27194
|
+
return None
|
|
27195
|
+
finally:
|
|
27196
|
+
os.close(parent_fd)
|
|
27197
|
+
|
|
27198
|
+
def rename_path(root_fd, payload):
|
|
27199
|
+
from_parent_fd, from_base = parent_and_basename(root_fd, payload["from"])
|
|
27200
|
+
to_parent_fd, to_base = parent_and_basename(root_fd, payload["to"])
|
|
27201
|
+
try:
|
|
27202
|
+
from_stat = os.lstat(from_base, dir_fd=from_parent_fd)
|
|
27203
|
+
reject_unsafe_endpoint(from_stat)
|
|
27204
|
+
if not payload.get("overwrite", True):
|
|
27205
|
+
try:
|
|
27206
|
+
os.lstat(to_base, dir_fd=to_parent_fd)
|
|
27207
|
+
raise FileExistsError(errno.EEXIST, "destination exists", to_base)
|
|
27208
|
+
except FileNotFoundError:
|
|
27209
|
+
pass
|
|
27210
|
+
os.rename(from_base, to_base, src_dir_fd=from_parent_fd, dst_dir_fd=to_parent_fd)
|
|
27211
|
+
os.fsync(from_parent_fd)
|
|
27212
|
+
if from_parent_fd != to_parent_fd:
|
|
27213
|
+
os.fsync(to_parent_fd)
|
|
27214
|
+
return None
|
|
27215
|
+
finally:
|
|
27216
|
+
os.close(from_parent_fd)
|
|
27217
|
+
os.close(to_parent_fd)
|
|
27218
|
+
|
|
27219
|
+
def create_temp_file(parent_fd, basename, mode):
|
|
27220
|
+
prefix = "." + basename + "."
|
|
27221
|
+
for _ in range(128):
|
|
27222
|
+
candidate = prefix + secrets.token_hex(6) + ".tmp"
|
|
27223
|
+
try:
|
|
27224
|
+
fd = os.open(candidate, WRITE_FLAGS, mode, dir_fd=parent_fd)
|
|
27225
|
+
return candidate, fd
|
|
27226
|
+
except FileExistsError:
|
|
27227
|
+
continue
|
|
27228
|
+
raise RuntimeError("failed to allocate pinned temp file")
|
|
27229
|
+
|
|
27230
|
+
def write_path(root_fd, payload):
|
|
27231
|
+
parent_fd = walk_dir(root_fd, split_relative(payload.get("relativeParentPath", "")), bool(payload.get("mkdir", True)))
|
|
27232
|
+
temp_fd = None
|
|
27233
|
+
temp_name = None
|
|
27234
|
+
basename = payload["basename"]
|
|
27235
|
+
mode = int(payload.get("mode", 0o600))
|
|
27236
|
+
overwrite = bool(payload.get("overwrite", True))
|
|
27237
|
+
max_bytes = int(payload.get("maxBytes", -1))
|
|
27238
|
+
data = base64.b64decode(payload.get("base64", ""))
|
|
27239
|
+
try:
|
|
27240
|
+
if max_bytes >= 0 and len(data) > max_bytes:
|
|
27241
|
+
raise RuntimeError("fs-safe-too-large:%d:%d" % (max_bytes, len(data)))
|
|
27242
|
+
if not overwrite:
|
|
27243
|
+
try:
|
|
27244
|
+
os.lstat(basename, dir_fd=parent_fd)
|
|
27245
|
+
raise FileExistsError(errno.EEXIST, "destination exists", basename)
|
|
27246
|
+
except FileNotFoundError:
|
|
27247
|
+
pass
|
|
27248
|
+
temp_name, temp_fd = create_temp_file(parent_fd, basename, mode)
|
|
27249
|
+
view = memoryview(data)
|
|
27250
|
+
while view:
|
|
27251
|
+
written = os.write(temp_fd, view)
|
|
27252
|
+
if written <= 0:
|
|
27253
|
+
raise OSError(errno.EIO, "short write")
|
|
27254
|
+
view = view[written:]
|
|
27255
|
+
os.fsync(temp_fd)
|
|
27256
|
+
os.close(temp_fd)
|
|
27257
|
+
temp_fd = None
|
|
27258
|
+
os.replace(temp_name, basename, src_dir_fd=parent_fd, dst_dir_fd=parent_fd)
|
|
27259
|
+
temp_name = None
|
|
27260
|
+
os.fsync(parent_fd)
|
|
27261
|
+
result_stat = os.stat(basename, dir_fd=parent_fd, follow_symlinks=False)
|
|
27262
|
+
return {"dev": result_stat.st_dev, "ino": result_stat.st_ino}
|
|
27263
|
+
finally:
|
|
27264
|
+
if temp_fd is not None:
|
|
27265
|
+
os.close(temp_fd)
|
|
27266
|
+
if temp_name is not None:
|
|
27267
|
+
try:
|
|
27268
|
+
os.unlink(temp_name, dir_fd=parent_fd)
|
|
27269
|
+
except FileNotFoundError:
|
|
27270
|
+
pass
|
|
27271
|
+
os.close(parent_fd)
|
|
27272
|
+
|
|
27273
|
+
def copy_path(root_fd, payload):
|
|
27274
|
+
source_fd = os.open(payload["sourcePath"], READ_FLAGS)
|
|
27275
|
+
parent_fd = None
|
|
27276
|
+
temp_fd = None
|
|
27277
|
+
temp_name = None
|
|
27278
|
+
try:
|
|
27279
|
+
source_stat = os.fstat(source_fd)
|
|
27280
|
+
if not stat.S_ISREG(source_stat.st_mode):
|
|
27281
|
+
raise RuntimeError("fs-safe-not-file")
|
|
27282
|
+
if source_stat.st_dev != int(payload["sourceDev"]) or source_stat.st_ino != int(payload["sourceIno"]):
|
|
27283
|
+
raise RuntimeError("fs-safe-source-mismatch")
|
|
27284
|
+
basename = payload["basename"]
|
|
27285
|
+
mode = int(payload.get("mode", 0o600))
|
|
27286
|
+
overwrite = bool(payload.get("overwrite", True))
|
|
27287
|
+
max_bytes = int(payload.get("maxBytes", -1))
|
|
27288
|
+
if max_bytes >= 0 and source_stat.st_size > max_bytes:
|
|
27289
|
+
raise RuntimeError("fs-safe-too-large:%d:%d" % (max_bytes, source_stat.st_size))
|
|
27290
|
+
parent_fd = walk_dir(root_fd, split_relative(payload.get("relativeParentPath", "")), bool(payload.get("mkdir", True)))
|
|
27291
|
+
if not overwrite:
|
|
27292
|
+
try:
|
|
27293
|
+
os.lstat(basename, dir_fd=parent_fd)
|
|
27294
|
+
raise FileExistsError(errno.EEXIST, "destination exists", basename)
|
|
27295
|
+
except FileNotFoundError:
|
|
27296
|
+
pass
|
|
27297
|
+
temp_name, temp_fd = create_temp_file(parent_fd, basename, mode)
|
|
27298
|
+
written_bytes = 0
|
|
27299
|
+
while True:
|
|
27300
|
+
chunk = os.read(source_fd, 65536)
|
|
27301
|
+
if not chunk:
|
|
27302
|
+
break
|
|
27303
|
+
written_bytes += len(chunk)
|
|
27304
|
+
if max_bytes >= 0 and written_bytes > max_bytes:
|
|
27305
|
+
raise RuntimeError("fs-safe-too-large:%d:%d" % (max_bytes, written_bytes))
|
|
27306
|
+
view = memoryview(chunk)
|
|
27307
|
+
while view:
|
|
27308
|
+
written = os.write(temp_fd, view)
|
|
27309
|
+
if written <= 0:
|
|
27310
|
+
raise OSError(errno.EIO, "short write")
|
|
27311
|
+
view = view[written:]
|
|
27312
|
+
os.fsync(temp_fd)
|
|
27313
|
+
os.close(temp_fd)
|
|
27314
|
+
temp_fd = None
|
|
27315
|
+
os.replace(temp_name, basename, src_dir_fd=parent_fd, dst_dir_fd=parent_fd)
|
|
27316
|
+
temp_name = None
|
|
27317
|
+
os.fsync(parent_fd)
|
|
27318
|
+
result_stat = os.stat(basename, dir_fd=parent_fd, follow_symlinks=False)
|
|
27319
|
+
return {"dev": result_stat.st_dev, "ino": result_stat.st_ino}
|
|
27320
|
+
finally:
|
|
27321
|
+
os.close(source_fd)
|
|
27322
|
+
if temp_fd is not None:
|
|
27323
|
+
os.close(temp_fd)
|
|
27324
|
+
if temp_name is not None and parent_fd is not None:
|
|
27325
|
+
try:
|
|
27326
|
+
os.unlink(temp_name, dir_fd=parent_fd)
|
|
27327
|
+
except FileNotFoundError:
|
|
27328
|
+
pass
|
|
27329
|
+
if parent_fd is not None:
|
|
27330
|
+
os.close(parent_fd)
|
|
27331
|
+
|
|
27332
|
+
def run_operation(operation, root_path, payload):
|
|
27333
|
+
root_fd = open_dir(root_path)
|
|
27334
|
+
try:
|
|
27335
|
+
if operation == "stat":
|
|
27336
|
+
return stat_path(root_fd, payload)
|
|
27337
|
+
if operation == "readdir":
|
|
27338
|
+
return readdir_path(root_fd, payload)
|
|
27339
|
+
if operation == "mkdirp":
|
|
27340
|
+
return mkdirp_path(root_fd, payload)
|
|
27341
|
+
if operation == "remove":
|
|
27342
|
+
return remove_path(root_fd, payload)
|
|
27343
|
+
if operation == "rename":
|
|
27344
|
+
return rename_path(root_fd, payload)
|
|
27345
|
+
if operation == "write":
|
|
27346
|
+
return write_path(root_fd, payload)
|
|
27347
|
+
if operation == "copy":
|
|
27348
|
+
return copy_path(root_fd, payload)
|
|
27349
|
+
raise RuntimeError("unknown operation: " + operation)
|
|
27350
|
+
finally:
|
|
27351
|
+
os.close(root_fd)
|
|
27352
|
+
|
|
27353
|
+
for line in sys.stdin:
|
|
27354
|
+
try:
|
|
27355
|
+
request = json.loads(line)
|
|
27356
|
+
result = run_operation(request["operation"], request["rootPath"], request.get("payload") or {})
|
|
27357
|
+
response = {"id": request["id"], "ok": True, "result": result}
|
|
27358
|
+
except Exception as exc:
|
|
27359
|
+
response = {
|
|
27360
|
+
"id": request.get("id") if isinstance(locals().get("request"), dict) else None,
|
|
27361
|
+
"ok": False,
|
|
27362
|
+
"code": exc.__class__.__name__,
|
|
27363
|
+
"errno": getattr(exc, "errno", None),
|
|
27364
|
+
"message": str(exc),
|
|
27365
|
+
}
|
|
27366
|
+
print(json.dumps(response, separators=(",", ":")), flush=True)
|
|
27367
|
+
`;
|
|
27368
|
+
let nextRequestId = 1;
|
|
27369
|
+
let worker = null;
|
|
27370
|
+
function __resetPinnedPythonWorkerForTest() {
|
|
27371
|
+
const currentWorker = worker;
|
|
27372
|
+
worker = null;
|
|
27373
|
+
if (!currentWorker) {
|
|
27374
|
+
return;
|
|
27375
|
+
}
|
|
27376
|
+
currentWorker.pending.clear();
|
|
27377
|
+
currentWorker.child.kill("SIGTERM");
|
|
27378
|
+
}
|
|
27379
|
+
const PYTHON_CANDIDATE_DEFAULTS = [
|
|
27380
|
+
"/usr/bin/python3",
|
|
27381
|
+
"/opt/homebrew/bin/python3",
|
|
27382
|
+
"/usr/local/bin/python3",
|
|
27383
|
+
];
|
|
27384
|
+
function canExecute(binPath) {
|
|
27385
|
+
try {
|
|
27386
|
+
external_node_fs_.accessSync(binPath, external_node_fs_.constants.X_OK);
|
|
27387
|
+
return true;
|
|
27388
|
+
}
|
|
27389
|
+
catch {
|
|
27390
|
+
return false;
|
|
27391
|
+
}
|
|
27392
|
+
}
|
|
27393
|
+
function resolvePython() {
|
|
27394
|
+
const configured = getFsSafePythonConfig().pythonPath;
|
|
27395
|
+
if (configured) {
|
|
27396
|
+
return configured;
|
|
27397
|
+
}
|
|
27398
|
+
for (const candidate of PYTHON_CANDIDATE_DEFAULTS) {
|
|
27399
|
+
if (canExecute(candidate)) {
|
|
27400
|
+
return candidate;
|
|
27401
|
+
}
|
|
27402
|
+
}
|
|
27403
|
+
return "python3";
|
|
27404
|
+
}
|
|
27405
|
+
function assertPinnedHelperSupported() {
|
|
27406
|
+
if (process.platform === "win32") {
|
|
27407
|
+
throw new errors_FsSafeError("unsupported-platform", "fd-relative pinned filesystem operations are not available on Windows");
|
|
27408
|
+
}
|
|
27409
|
+
if (getFsSafePythonConfig().mode === "off") {
|
|
27410
|
+
throw new errors_FsSafeError("helper-unavailable", "Python helper is disabled");
|
|
27411
|
+
}
|
|
27412
|
+
}
|
|
27413
|
+
function isSpawnUnavailable(error) {
|
|
27414
|
+
if (!(error instanceof Error)) {
|
|
27415
|
+
return false;
|
|
27416
|
+
}
|
|
27417
|
+
const maybeErrno = error;
|
|
27418
|
+
return (typeof maybeErrno.syscall === "string" &&
|
|
27419
|
+
maybeErrno.syscall.startsWith("spawn") &&
|
|
27420
|
+
["EACCES", "ENOENT", "ENOEXEC"].includes(maybeErrno.code ?? ""));
|
|
27421
|
+
}
|
|
27422
|
+
function mapWorkerError(response) {
|
|
27423
|
+
const code = typeof response.code === "string" ? response.code : "";
|
|
27424
|
+
const errno = typeof response.errno === "number" ? response.errno : undefined;
|
|
27425
|
+
const message = typeof response.message === "string" && response.message
|
|
27426
|
+
? response.message
|
|
27427
|
+
: "pinned helper failed";
|
|
27428
|
+
const tooLarge = message.match(/fs-safe-too-large:(\d+):(\d+)/);
|
|
27429
|
+
if (tooLarge) {
|
|
27430
|
+
const [, limit, got] = tooLarge;
|
|
27431
|
+
return new errors_FsSafeError("too-large", `file exceeds limit of ${limit} bytes (got at least ${got})`);
|
|
27432
|
+
}
|
|
27433
|
+
if (message.includes("fs-safe-not-file")) {
|
|
27434
|
+
return new errors_FsSafeError("not-file", "not a file");
|
|
27435
|
+
}
|
|
27436
|
+
if (message.includes("fs-safe-source-mismatch")) {
|
|
27437
|
+
return new errors_FsSafeError("path-mismatch", "source path changed during copy");
|
|
27438
|
+
}
|
|
27439
|
+
if (code === "FileNotFoundError" || errno === 2) {
|
|
27440
|
+
return new errors_FsSafeError("not-found", "file not found");
|
|
27441
|
+
}
|
|
27442
|
+
if (code === "FileExistsError" || errno === 17) {
|
|
27443
|
+
return new errors_FsSafeError("already-exists", message);
|
|
27444
|
+
}
|
|
27445
|
+
if (errno === 39) {
|
|
27446
|
+
return new errors_FsSafeError("not-empty", "directory is not empty");
|
|
27447
|
+
}
|
|
27448
|
+
if (errno === 1 || errno === 13 || errno === 21) {
|
|
27449
|
+
return new errors_FsSafeError("not-removable", "path is not removable under root");
|
|
27450
|
+
}
|
|
27451
|
+
if (code === "NotADirectoryError" || code === "OSError" || errno === 20 || errno === 40) {
|
|
27452
|
+
return new errors_FsSafeError("path-alias", message);
|
|
27453
|
+
}
|
|
27454
|
+
return new errors_FsSafeError("helper-failed", message);
|
|
27455
|
+
}
|
|
27456
|
+
function rejectPending(error) {
|
|
27457
|
+
if (!worker) {
|
|
27458
|
+
return;
|
|
27459
|
+
}
|
|
27460
|
+
setWorkerRef(worker, false);
|
|
27461
|
+
for (const pending of worker.pending.values()) {
|
|
27462
|
+
pending.reject(error);
|
|
27463
|
+
}
|
|
27464
|
+
worker.pending.clear();
|
|
27465
|
+
worker = null;
|
|
27466
|
+
}
|
|
27467
|
+
function handleWorkerLine(line) {
|
|
27468
|
+
if (!worker || !line.trim()) {
|
|
27469
|
+
return;
|
|
27470
|
+
}
|
|
27471
|
+
let decoded;
|
|
27472
|
+
try {
|
|
27473
|
+
decoded = JSON.parse(line);
|
|
27474
|
+
}
|
|
27475
|
+
catch {
|
|
27476
|
+
rejectPending(new errors_FsSafeError("helper-failed", `pinned helper returned invalid JSON: ${line}`));
|
|
27477
|
+
return;
|
|
27478
|
+
}
|
|
27479
|
+
if (typeof decoded !== "object" || decoded === null || !("id" in decoded)) {
|
|
27480
|
+
rejectPending(new errors_FsSafeError("helper-failed", "pinned helper returned invalid response"));
|
|
27481
|
+
return;
|
|
27482
|
+
}
|
|
27483
|
+
const response = decoded;
|
|
27484
|
+
const id = typeof response.id === "number" ? response.id : undefined;
|
|
27485
|
+
if (id === undefined) {
|
|
27486
|
+
return;
|
|
27487
|
+
}
|
|
27488
|
+
const pending = worker.pending.get(id);
|
|
27489
|
+
if (!pending) {
|
|
27490
|
+
return;
|
|
27491
|
+
}
|
|
27492
|
+
worker.pending.delete(id);
|
|
27493
|
+
if (worker.pending.size === 0) {
|
|
27494
|
+
setWorkerRef(worker, false);
|
|
27495
|
+
}
|
|
27496
|
+
if (response.ok === true) {
|
|
27497
|
+
pending.resolve(response.result);
|
|
27498
|
+
return;
|
|
27499
|
+
}
|
|
27500
|
+
pending.reject(mapWorkerError(decoded));
|
|
27501
|
+
}
|
|
27502
|
+
function getWorker() {
|
|
27503
|
+
assertPinnedHelperSupported();
|
|
27504
|
+
if (worker) {
|
|
27505
|
+
return worker;
|
|
27506
|
+
}
|
|
27507
|
+
const child = (0,external_node_child_process_.spawn)(resolvePython(), ["-u", "-c", PINNED_PYTHON_WORKER_SOURCE], {
|
|
27508
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
27509
|
+
});
|
|
27510
|
+
worker = { child, pending: new Map(), stderr: "", stdoutBuffer: "" };
|
|
27511
|
+
child.stdout.setEncoding("utf8");
|
|
27512
|
+
child.stderr.setEncoding("utf8");
|
|
27513
|
+
child.stdout.on("data", (chunk) => {
|
|
27514
|
+
const current = worker;
|
|
27515
|
+
if (!current) {
|
|
27516
|
+
return;
|
|
27517
|
+
}
|
|
27518
|
+
current.stdoutBuffer += chunk;
|
|
27519
|
+
for (;;) {
|
|
27520
|
+
const newline = current.stdoutBuffer.indexOf("\n");
|
|
27521
|
+
if (newline < 0) {
|
|
27522
|
+
break;
|
|
27523
|
+
}
|
|
27524
|
+
const line = current.stdoutBuffer.slice(0, newline);
|
|
27525
|
+
current.stdoutBuffer = current.stdoutBuffer.slice(newline + 1);
|
|
27526
|
+
handleWorkerLine(line);
|
|
27527
|
+
}
|
|
27528
|
+
});
|
|
27529
|
+
child.stderr.on("data", (chunk) => {
|
|
27530
|
+
if (worker) {
|
|
27531
|
+
worker.stderr = `${worker.stderr}${chunk}`.slice(-4096);
|
|
27532
|
+
}
|
|
27533
|
+
});
|
|
27534
|
+
child.once("error", (error) => {
|
|
27535
|
+
const mapped = isSpawnUnavailable(error)
|
|
27536
|
+
? new errors_FsSafeError("helper-unavailable", "Python helper is unavailable", { cause: error })
|
|
27537
|
+
: error instanceof Error
|
|
27538
|
+
? error
|
|
27539
|
+
: new Error(String(error));
|
|
27540
|
+
rejectPending(mapped);
|
|
27541
|
+
});
|
|
27542
|
+
child.once("close", (code, signal) => {
|
|
27543
|
+
const stderr = worker?.stderr.trim();
|
|
27544
|
+
rejectPending(new errors_FsSafeError("helper-failed", stderr || `pinned helper exited with code ${code ?? "null"} (${signal ?? "?"})`));
|
|
27545
|
+
});
|
|
27546
|
+
process.once("exit", () => {
|
|
27547
|
+
child.kill("SIGTERM");
|
|
27548
|
+
});
|
|
27549
|
+
setWorkerRef(worker, false);
|
|
27550
|
+
return worker;
|
|
27551
|
+
}
|
|
27552
|
+
function setRefable(value, ref) {
|
|
27553
|
+
if (!value) {
|
|
27554
|
+
return;
|
|
27555
|
+
}
|
|
27556
|
+
const method = ref ? "ref" : "unref";
|
|
27557
|
+
const refable = value;
|
|
27558
|
+
refable[method]?.();
|
|
27559
|
+
}
|
|
27560
|
+
function setWorkerRef(currentWorker, ref) {
|
|
27561
|
+
setRefable(currentWorker.child, ref);
|
|
27562
|
+
setRefable(currentWorker.child.stdin, ref);
|
|
27563
|
+
setRefable(currentWorker.child.stdout, ref);
|
|
27564
|
+
setRefable(currentWorker.child.stderr, ref);
|
|
27565
|
+
}
|
|
27566
|
+
async function runPinnedPythonOperation(params) {
|
|
27567
|
+
const requestId = nextRequestId++;
|
|
27568
|
+
const currentWorker = getWorker();
|
|
27569
|
+
if (typeof currentWorker.child.stdin?.write !== "function") {
|
|
27570
|
+
throw new errors_FsSafeError("helper-unavailable", "Python helper stdin is unavailable");
|
|
27571
|
+
}
|
|
27572
|
+
setWorkerRef(currentWorker, true);
|
|
27573
|
+
return await new Promise((resolve, reject) => {
|
|
27574
|
+
currentWorker.pending.set(requestId, {
|
|
27575
|
+
reject,
|
|
27576
|
+
resolve: (value) => resolve(value),
|
|
27577
|
+
});
|
|
27578
|
+
const request = JSON.stringify({
|
|
27579
|
+
id: requestId,
|
|
27580
|
+
operation: params.operation,
|
|
27581
|
+
rootPath: params.rootPath,
|
|
27582
|
+
payload: params.payload,
|
|
27583
|
+
});
|
|
27584
|
+
currentWorker.child.stdin.write(`${request}\n`, (error) => {
|
|
27585
|
+
if (error) {
|
|
27586
|
+
currentWorker.pending.delete(requestId);
|
|
27587
|
+
if (currentWorker.pending.size === 0) {
|
|
27588
|
+
setWorkerRef(currentWorker, false);
|
|
27589
|
+
}
|
|
27590
|
+
reject(error);
|
|
27591
|
+
}
|
|
27592
|
+
});
|
|
27593
|
+
});
|
|
27594
|
+
}
|
|
27595
|
+
function assertPinnedPythonOperationAvailable() {
|
|
27596
|
+
const currentWorker = getWorker();
|
|
27597
|
+
if (typeof currentWorker.child.stdin?.write !== "function") {
|
|
27598
|
+
throw new errors_FsSafeError("helper-unavailable", "Python helper stdin is unavailable");
|
|
27599
|
+
}
|
|
27600
|
+
}
|
|
27601
|
+
function validatePinnedOperationPayload(payload) {
|
|
27602
|
+
if (typeof payload.relativePath === "string") {
|
|
27603
|
+
validatePinnedRelativePath(payload.relativePath);
|
|
27604
|
+
}
|
|
27605
|
+
if (typeof payload.relativeParentPath === "string") {
|
|
27606
|
+
validatePinnedRelativePath(payload.relativeParentPath);
|
|
27607
|
+
}
|
|
27608
|
+
if (typeof payload.from === "string") {
|
|
27609
|
+
validatePinnedRelativePath(payload.from);
|
|
27610
|
+
}
|
|
27611
|
+
if (typeof payload.to === "string") {
|
|
27612
|
+
validatePinnedRelativePath(payload.to);
|
|
27613
|
+
}
|
|
27614
|
+
}
|
|
27615
|
+
function isPinnedHelperUnavailable(error) {
|
|
27616
|
+
return error instanceof Error &&
|
|
27617
|
+
"code" in error &&
|
|
27618
|
+
error.code === "helper-unavailable";
|
|
27619
|
+
}
|
|
27620
|
+
function validatePinnedRelativePath(relativePath) {
|
|
27621
|
+
if (relativePath.length === 0 || relativePath === ".") {
|
|
27622
|
+
return;
|
|
27623
|
+
}
|
|
27624
|
+
if (relativePath.includes("\0")) {
|
|
27625
|
+
throw new errors_FsSafeError("invalid-path", "relative path contains a NUL byte");
|
|
27626
|
+
}
|
|
27627
|
+
if (relativePath.startsWith("/") ||
|
|
27628
|
+
relativePath.startsWith("//") ||
|
|
27629
|
+
relativePath === ".." ||
|
|
27630
|
+
relativePath.startsWith("../") ||
|
|
27631
|
+
relativePath.startsWith("..\\")) {
|
|
27632
|
+
throw new errors_FsSafeError("invalid-path", "relative path must not escape root");
|
|
27633
|
+
}
|
|
27634
|
+
for (const segment of relativePath.split("/")) {
|
|
27635
|
+
if (segment === "..") {
|
|
27636
|
+
throw new errors_FsSafeError("invalid-path", "relative path must not contain '..'");
|
|
27637
|
+
}
|
|
27638
|
+
}
|
|
27639
|
+
}
|
|
27640
|
+
|
|
27641
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/pinned-helper.js
|
|
27642
|
+
|
|
27643
|
+
|
|
27644
|
+
async function runPinnedHelper(operation, rootDir, payload) {
|
|
27645
|
+
validatePinnedOperationPayload(payload);
|
|
27646
|
+
return await runPinnedPythonOperation({
|
|
27647
|
+
operation,
|
|
27648
|
+
rootPath: rootDir,
|
|
27649
|
+
payload,
|
|
27650
|
+
});
|
|
27651
|
+
}
|
|
27652
|
+
async function helperStat(rootDir, relativePath) {
|
|
27653
|
+
return await runPinnedHelper("stat", rootDir, { relativePath });
|
|
27654
|
+
}
|
|
27655
|
+
async function helperReaddir(rootDir, relativePath, withFileTypes) {
|
|
27656
|
+
return await runPinnedHelper("readdir", rootDir, {
|
|
27657
|
+
relativePath,
|
|
27658
|
+
withFileTypes,
|
|
27659
|
+
});
|
|
27660
|
+
}
|
|
27661
|
+
|
|
27662
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/pinned-path.js
|
|
27663
|
+
|
|
27664
|
+
|
|
27665
|
+
|
|
27666
|
+
function isPinnedPathHelperSpawnError(error) {
|
|
27667
|
+
return canFallbackFromPythonError(error);
|
|
27668
|
+
}
|
|
27669
|
+
async function runPinnedPathHelper(params) {
|
|
27670
|
+
try {
|
|
27671
|
+
await runPinnedHelper(params.operation, params.rootPath, {
|
|
27672
|
+
relativePath: params.relativePath,
|
|
27673
|
+
});
|
|
27674
|
+
}
|
|
27675
|
+
catch (error) {
|
|
27676
|
+
if (error instanceof errors_FsSafeError) {
|
|
27677
|
+
throw error;
|
|
27678
|
+
}
|
|
27679
|
+
throw new errors_FsSafeError("helper-failed", "pinned path helper failed", {
|
|
27680
|
+
cause: error instanceof Error ? error : undefined,
|
|
27681
|
+
});
|
|
27682
|
+
}
|
|
27683
|
+
}
|
|
27684
|
+
|
|
27685
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/pinned-write.js
|
|
27686
|
+
|
|
27687
|
+
|
|
27688
|
+
|
|
27689
|
+
|
|
27690
|
+
|
|
27691
|
+
|
|
27692
|
+
|
|
27693
|
+
|
|
27694
|
+
|
|
27695
|
+
|
|
27696
|
+
|
|
27697
|
+
function pinned_write_byteLength(input, encoding) {
|
|
27698
|
+
return typeof input === "string"
|
|
27699
|
+
? Buffer.byteLength(input, encoding ?? "utf8")
|
|
27700
|
+
: input.byteLength;
|
|
27701
|
+
}
|
|
27702
|
+
function assertSafeBasename(basename) {
|
|
27703
|
+
if (!basename ||
|
|
27704
|
+
basename === "." ||
|
|
27705
|
+
basename === ".." ||
|
|
27706
|
+
basename.includes("/") ||
|
|
27707
|
+
basename.includes("\0")) {
|
|
27708
|
+
throw new errors_FsSafeError("invalid-path", "invalid target path");
|
|
27709
|
+
}
|
|
27710
|
+
}
|
|
27711
|
+
function assertWithinMaxBytes(bytes, maxBytes) {
|
|
27712
|
+
if (maxBytes !== undefined && bytes > maxBytes) {
|
|
27713
|
+
throw new errors_FsSafeError("too-large", `file exceeds limit of ${maxBytes} bytes (got at least ${bytes})`);
|
|
27714
|
+
}
|
|
27715
|
+
}
|
|
27716
|
+
function pinned_write_createMaxBytesTransform(maxBytes) {
|
|
27717
|
+
if (maxBytes === undefined) {
|
|
27718
|
+
return undefined;
|
|
27719
|
+
}
|
|
27720
|
+
let bytes = 0;
|
|
27721
|
+
return new external_node_stream_.Transform({
|
|
27722
|
+
transform(chunk, _encoding, callback) {
|
|
27723
|
+
bytes += chunk.byteLength;
|
|
27724
|
+
if (bytes > maxBytes) {
|
|
27725
|
+
callback(new errors_FsSafeError("too-large", `file exceeds limit of ${maxBytes} bytes (got at least ${bytes})`));
|
|
27726
|
+
return;
|
|
27727
|
+
}
|
|
27728
|
+
callback(null, chunk);
|
|
27729
|
+
},
|
|
27730
|
+
});
|
|
27731
|
+
}
|
|
27732
|
+
async function pipelineWithMaxBytes(stream, destination, maxBytes) {
|
|
27733
|
+
const limiter = pinned_write_createMaxBytesTransform(maxBytes);
|
|
27734
|
+
if (limiter) {
|
|
27735
|
+
await (0,external_node_stream_promises_.pipeline)(stream, limiter, destination);
|
|
27736
|
+
return;
|
|
27737
|
+
}
|
|
27738
|
+
await (0,external_node_stream_promises_.pipeline)(stream, destination);
|
|
27739
|
+
}
|
|
27740
|
+
async function inputToBase64(input, maxBytes) {
|
|
27741
|
+
if (input.kind === "buffer") {
|
|
27742
|
+
assertWithinMaxBytes(pinned_write_byteLength(input.data, input.encoding), maxBytes);
|
|
27743
|
+
return (typeof input.data === "string"
|
|
27744
|
+
? Buffer.from(input.data, input.encoding ?? "utf8")
|
|
27745
|
+
: input.data).toString("base64");
|
|
27746
|
+
}
|
|
27747
|
+
const chunks = [];
|
|
27748
|
+
let bytes = 0;
|
|
27749
|
+
for await (const chunk of input.stream) {
|
|
27750
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
27751
|
+
bytes += buffer.byteLength;
|
|
27752
|
+
assertWithinMaxBytes(bytes, maxBytes);
|
|
27753
|
+
chunks.push(buffer);
|
|
27754
|
+
}
|
|
27755
|
+
return Buffer.concat(chunks, bytes).toString("base64");
|
|
27756
|
+
}
|
|
27757
|
+
async function runPinnedWriteHelper(params) {
|
|
27758
|
+
assertSafeBasename(params.basename);
|
|
27759
|
+
validatePinnedOperationPayload({
|
|
27760
|
+
relativeParentPath: params.relativeParentPath,
|
|
27761
|
+
});
|
|
27762
|
+
if (getFsSafePythonConfig().mode === "off") {
|
|
27763
|
+
return await runPinnedWriteFallback(params);
|
|
27764
|
+
}
|
|
27765
|
+
if (params.input.kind === "stream") {
|
|
27766
|
+
try {
|
|
27767
|
+
assertPinnedPythonOperationAvailable();
|
|
27768
|
+
}
|
|
27769
|
+
catch (error) {
|
|
27770
|
+
if (canFallbackFromPythonError(error)) {
|
|
27771
|
+
return await runPinnedWriteFallback(params);
|
|
27772
|
+
}
|
|
27773
|
+
throw error;
|
|
27774
|
+
}
|
|
27775
|
+
}
|
|
27776
|
+
const payload = {
|
|
27777
|
+
base64: await inputToBase64(params.input, params.maxBytes),
|
|
27778
|
+
basename: params.basename,
|
|
27779
|
+
maxBytes: params.maxBytes ?? -1,
|
|
27780
|
+
mkdir: params.mkdir,
|
|
27781
|
+
mode: params.mode || 0o600,
|
|
27782
|
+
overwrite: params.overwrite !== false,
|
|
27783
|
+
relativeParentPath: params.relativeParentPath,
|
|
27784
|
+
};
|
|
27785
|
+
try {
|
|
27786
|
+
return await runPinnedPythonOperation({
|
|
27787
|
+
operation: "write",
|
|
27788
|
+
rootPath: params.rootPath,
|
|
27789
|
+
payload,
|
|
27790
|
+
});
|
|
27791
|
+
}
|
|
27792
|
+
catch (error) {
|
|
27793
|
+
if (canFallbackFromPythonError(error)) {
|
|
27794
|
+
return await runPinnedWriteFallback(params);
|
|
27795
|
+
}
|
|
27796
|
+
throw error;
|
|
27797
|
+
}
|
|
27798
|
+
}
|
|
27799
|
+
async function runPinnedCopyHelper(params) {
|
|
27800
|
+
assertSafeBasename(params.basename);
|
|
27801
|
+
validatePinnedOperationPayload({
|
|
27802
|
+
relativeParentPath: params.relativeParentPath,
|
|
27803
|
+
});
|
|
27804
|
+
return await runPinnedPythonOperation({
|
|
27805
|
+
operation: "copy",
|
|
27806
|
+
rootPath: params.rootPath,
|
|
27807
|
+
payload: {
|
|
27808
|
+
basename: params.basename,
|
|
27809
|
+
maxBytes: params.maxBytes ?? -1,
|
|
27810
|
+
mkdir: params.mkdir,
|
|
27811
|
+
mode: params.mode || 0o600,
|
|
27812
|
+
overwrite: params.overwrite !== false,
|
|
27813
|
+
relativeParentPath: params.relativeParentPath,
|
|
27814
|
+
sourceDev: params.sourceIdentity.dev,
|
|
27815
|
+
sourceIno: params.sourceIdentity.ino,
|
|
27816
|
+
sourcePath: params.sourcePath,
|
|
27817
|
+
},
|
|
27818
|
+
});
|
|
27819
|
+
}
|
|
27820
|
+
async function runPinnedWriteFallback(params) {
|
|
27821
|
+
const parentPath = params.relativeParentPath
|
|
27822
|
+
? external_node_path_.join(params.rootPath, ...params.relativeParentPath.split("/"))
|
|
27823
|
+
: params.rootPath;
|
|
27824
|
+
const parentGuard = await directory_guard_createNearestExistingDirectoryGuard(params.rootPath, parentPath);
|
|
27825
|
+
if (params.mkdir) {
|
|
27826
|
+
await withAsyncDirectoryGuards([parentGuard], async () => {
|
|
27827
|
+
await promises_.mkdir(parentPath, { recursive: true });
|
|
27828
|
+
});
|
|
27829
|
+
}
|
|
27830
|
+
const targetPath = external_node_path_.join(parentPath, params.basename);
|
|
27831
|
+
if (params.overwrite === false) {
|
|
27832
|
+
let handle = await withAsyncDirectoryGuards([parentGuard], async () => await promises_.open(targetPath, external_node_fs_.constants.O_WRONLY | external_node_fs_.constants.O_CREAT | external_node_fs_.constants.O_EXCL, params.mode), {
|
|
27833
|
+
onPostGuardFailure: async (openedHandle) => {
|
|
27834
|
+
// The parent failed verification, so targetPath may now resolve
|
|
27835
|
+
// somewhere else. Close the fd, but do not clean up by path.
|
|
27836
|
+
await openedHandle.close().catch(() => undefined);
|
|
27837
|
+
},
|
|
27838
|
+
});
|
|
27839
|
+
let created = true;
|
|
27840
|
+
try {
|
|
27841
|
+
if (params.input.kind === "buffer") {
|
|
27842
|
+
assertWithinMaxBytes(pinned_write_byteLength(params.input.data, params.input.encoding), params.maxBytes);
|
|
27843
|
+
if (typeof params.input.data === "string") {
|
|
27844
|
+
await handle.writeFile(params.input.data, params.input.encoding ?? "utf8");
|
|
27845
|
+
}
|
|
27846
|
+
else {
|
|
27847
|
+
await handle.writeFile(params.input.data);
|
|
27848
|
+
}
|
|
27849
|
+
}
|
|
27850
|
+
else {
|
|
27851
|
+
await pipelineWithMaxBytes(params.input.stream, handle.createWriteStream(), params.maxBytes);
|
|
27852
|
+
}
|
|
27853
|
+
const stat = await handle.stat();
|
|
27854
|
+
created = false;
|
|
27855
|
+
return { dev: stat.dev, ino: stat.ino };
|
|
27856
|
+
}
|
|
27857
|
+
finally {
|
|
27858
|
+
await handle.close().catch(() => undefined);
|
|
27859
|
+
if (created) {
|
|
27860
|
+
await promises_.rm(targetPath, { force: true }).catch(() => undefined);
|
|
27861
|
+
}
|
|
27862
|
+
}
|
|
27863
|
+
}
|
|
27864
|
+
const tempPath = external_node_path_.join(parentPath, `.${params.basename}.${(0,external_node_crypto_.randomUUID)()}.fallback.tmp`);
|
|
27865
|
+
const tempFlags = external_node_fs_.constants.O_WRONLY |
|
|
27866
|
+
external_node_fs_.constants.O_CREAT |
|
|
27867
|
+
external_node_fs_.constants.O_EXCL |
|
|
27868
|
+
(process.platform !== "win32" && "O_NOFOLLOW" in external_node_fs_.constants
|
|
27869
|
+
? external_node_fs_.constants.O_NOFOLLOW
|
|
27870
|
+
: 0);
|
|
27871
|
+
let handle;
|
|
27872
|
+
let handleClosedByStream = false;
|
|
27873
|
+
try {
|
|
27874
|
+
handle = await promises_.open(tempPath, tempFlags, params.mode);
|
|
27875
|
+
if (params.input.kind === "buffer") {
|
|
27876
|
+
assertWithinMaxBytes(pinned_write_byteLength(params.input.data, params.input.encoding), params.maxBytes);
|
|
27877
|
+
if (typeof params.input.data === "string") {
|
|
27878
|
+
await handle.writeFile(params.input.data, params.input.encoding ?? "utf8");
|
|
27879
|
+
}
|
|
27880
|
+
else {
|
|
27881
|
+
await handle.writeFile(params.input.data);
|
|
27882
|
+
}
|
|
27883
|
+
}
|
|
27884
|
+
else {
|
|
27885
|
+
const writable = handle.createWriteStream();
|
|
27886
|
+
writable.once("close", () => {
|
|
27887
|
+
handleClosedByStream = true;
|
|
27888
|
+
});
|
|
27889
|
+
await pipelineWithMaxBytes(params.input.stream, writable, params.maxBytes);
|
|
27890
|
+
}
|
|
27891
|
+
if (!handleClosedByStream) {
|
|
27892
|
+
await handle.close().catch(() => undefined);
|
|
27893
|
+
handle = undefined;
|
|
27894
|
+
}
|
|
27895
|
+
await withAsyncDirectoryGuards([parentGuard], async () => {
|
|
27896
|
+
await promises_.rename(tempPath, targetPath);
|
|
27897
|
+
});
|
|
27898
|
+
}
|
|
27899
|
+
catch (error) {
|
|
27900
|
+
if (handle && !handleClosedByStream) {
|
|
27901
|
+
await handle.close().catch(() => undefined);
|
|
27902
|
+
}
|
|
27903
|
+
await promises_.rm(tempPath, { force: true }).catch(() => undefined);
|
|
27904
|
+
throw error;
|
|
27905
|
+
}
|
|
27906
|
+
const stat = await promises_.stat(targetPath);
|
|
27907
|
+
return { dev: stat.dev, ino: stat.ino };
|
|
27908
|
+
}
|
|
27909
|
+
|
|
27910
|
+
// EXTERNAL MODULE: external "node:os"
|
|
27911
|
+
var external_node_os_ = __webpack_require__(8161);
|
|
27912
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-path.js
|
|
27913
|
+
|
|
27914
|
+
|
|
27915
|
+
|
|
27916
|
+
|
|
27917
|
+
|
|
27918
|
+
const ROOT_PATH_ALIAS_POLICIES = {
|
|
27919
|
+
strict: Object.freeze({
|
|
27920
|
+
allowFinalSymlinkForUnlink: false,
|
|
27921
|
+
allowFinalHardlinkForUnlink: false,
|
|
27922
|
+
}),
|
|
27923
|
+
unlinkTarget: Object.freeze({
|
|
27924
|
+
allowFinalSymlinkForUnlink: true,
|
|
27925
|
+
allowFinalHardlinkForUnlink: true,
|
|
27926
|
+
}),
|
|
27927
|
+
};
|
|
27928
|
+
async function resolveRootPath(params) {
|
|
27929
|
+
const rootPath = external_node_path_.resolve(params.rootPath);
|
|
27930
|
+
const absolutePath = external_node_path_.resolve(params.absolutePath);
|
|
27931
|
+
const rootCanonicalPath = params.rootCanonicalPath
|
|
27932
|
+
? external_node_path_.resolve(params.rootCanonicalPath)
|
|
27933
|
+
: await resolvePathViaExistingAncestor(rootPath);
|
|
27934
|
+
const context = createBoundaryResolutionContext({
|
|
27935
|
+
resolveParams: params,
|
|
27936
|
+
rootPath,
|
|
27937
|
+
absolutePath,
|
|
27938
|
+
rootCanonicalPath,
|
|
27939
|
+
outsideLexicalCanonicalPath: await resolveOutsideLexicalCanonicalPathAsync({
|
|
27940
|
+
rootPath,
|
|
27941
|
+
absolutePath,
|
|
27942
|
+
}),
|
|
27943
|
+
});
|
|
27944
|
+
const outsideResult = await resolveOutsideRootPathAsync({
|
|
27945
|
+
boundaryLabel: params.boundaryLabel,
|
|
27946
|
+
context,
|
|
27947
|
+
});
|
|
27948
|
+
if (outsideResult) {
|
|
27949
|
+
return outsideResult;
|
|
27950
|
+
}
|
|
27951
|
+
return resolveRootPathLexicalAsync({
|
|
27952
|
+
params,
|
|
27953
|
+
absolutePath: context.absolutePath,
|
|
27954
|
+
rootPath: context.rootPath,
|
|
27955
|
+
rootCanonicalPath: context.rootCanonicalPath,
|
|
27956
|
+
});
|
|
27957
|
+
}
|
|
27958
|
+
function resolveRootPathSync(params) {
|
|
27959
|
+
const rootPath = path.resolve(params.rootPath);
|
|
27960
|
+
const absolutePath = path.resolve(params.absolutePath);
|
|
27961
|
+
const rootCanonicalPath = params.rootCanonicalPath
|
|
27962
|
+
? path.resolve(params.rootCanonicalPath)
|
|
27963
|
+
: resolvePathViaExistingAncestorSync(rootPath);
|
|
27964
|
+
const context = createBoundaryResolutionContext({
|
|
27965
|
+
resolveParams: params,
|
|
27966
|
+
rootPath,
|
|
27967
|
+
absolutePath,
|
|
27968
|
+
rootCanonicalPath,
|
|
27969
|
+
outsideLexicalCanonicalPath: resolveOutsideLexicalCanonicalPathSync({
|
|
27970
|
+
rootPath,
|
|
27971
|
+
absolutePath,
|
|
27972
|
+
}),
|
|
27973
|
+
});
|
|
27974
|
+
const outsideResult = resolveOutsideRootPathSync({
|
|
27975
|
+
boundaryLabel: params.boundaryLabel,
|
|
27976
|
+
context,
|
|
27977
|
+
});
|
|
27978
|
+
if (outsideResult) {
|
|
27979
|
+
return outsideResult;
|
|
27980
|
+
}
|
|
27981
|
+
return resolveRootPathLexicalSync({
|
|
27982
|
+
params,
|
|
27983
|
+
absolutePath: context.absolutePath,
|
|
27984
|
+
rootPath: context.rootPath,
|
|
27985
|
+
rootCanonicalPath: context.rootCanonicalPath,
|
|
27986
|
+
});
|
|
27987
|
+
}
|
|
27988
|
+
function isPromiseLike(value) {
|
|
27989
|
+
return Boolean(value &&
|
|
27990
|
+
(typeof value === "object" || typeof value === "function") &&
|
|
27991
|
+
"then" in value &&
|
|
27992
|
+
typeof value.then === "function");
|
|
27993
|
+
}
|
|
27994
|
+
function createLexicalTraversalState(params) {
|
|
27995
|
+
const relative = external_node_path_.relative(params.rootPath, params.absolutePath);
|
|
27996
|
+
return {
|
|
27997
|
+
segments: relative.split(external_node_path_.sep).filter(Boolean),
|
|
27998
|
+
allowFinalSymlink: params.params.policy?.allowFinalSymlinkForUnlink === true,
|
|
27999
|
+
canonicalCursor: params.rootCanonicalPath,
|
|
28000
|
+
lexicalCursor: params.rootPath,
|
|
28001
|
+
preserveFinalSymlink: false,
|
|
28002
|
+
};
|
|
28003
|
+
}
|
|
28004
|
+
function assertLexicalCursorInsideBoundary(params) {
|
|
28005
|
+
assertInsideBoundary({
|
|
28006
|
+
boundaryLabel: params.params.boundaryLabel,
|
|
28007
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28008
|
+
candidatePath: params.candidatePath,
|
|
28009
|
+
absolutePath: params.absolutePath,
|
|
28010
|
+
});
|
|
28011
|
+
}
|
|
28012
|
+
function applyMissingSuffixToCanonicalCursor(params) {
|
|
28013
|
+
const missingSuffix = params.state.segments.slice(params.missingFromIndex);
|
|
28014
|
+
params.state.canonicalCursor = external_node_path_.resolve(params.state.canonicalCursor, ...missingSuffix);
|
|
28015
|
+
assertLexicalCursorInsideBoundary({
|
|
28016
|
+
params: params.params,
|
|
28017
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28018
|
+
candidatePath: params.state.canonicalCursor,
|
|
28019
|
+
absolutePath: params.absolutePath,
|
|
28020
|
+
});
|
|
28021
|
+
}
|
|
28022
|
+
function advanceCanonicalCursorForSegment(params) {
|
|
28023
|
+
params.state.canonicalCursor = external_node_path_.resolve(params.state.canonicalCursor, params.segment);
|
|
28024
|
+
assertLexicalCursorInsideBoundary({
|
|
28025
|
+
params: params.params,
|
|
28026
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28027
|
+
candidatePath: params.state.canonicalCursor,
|
|
28028
|
+
absolutePath: params.absolutePath,
|
|
28029
|
+
});
|
|
28030
|
+
}
|
|
28031
|
+
function finalizeLexicalResolution(params) {
|
|
28032
|
+
assertLexicalCursorInsideBoundary({
|
|
28033
|
+
params: params.params,
|
|
28034
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28035
|
+
candidatePath: params.state.canonicalCursor,
|
|
28036
|
+
absolutePath: params.absolutePath,
|
|
28037
|
+
});
|
|
28038
|
+
return buildResolvedRootPath({
|
|
28039
|
+
absolutePath: params.absolutePath,
|
|
28040
|
+
canonicalPath: params.state.canonicalCursor,
|
|
28041
|
+
rootPath: params.rootPath,
|
|
28042
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28043
|
+
kind: params.kind,
|
|
28044
|
+
});
|
|
28045
|
+
}
|
|
28046
|
+
function handleLexicalLstatFailure(params) {
|
|
28047
|
+
if (!path_isNotFoundPathError(params.error)) {
|
|
28048
|
+
return false;
|
|
28049
|
+
}
|
|
28050
|
+
applyMissingSuffixToCanonicalCursor({
|
|
28051
|
+
state: params.state,
|
|
28052
|
+
missingFromIndex: params.missingFromIndex,
|
|
28053
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28054
|
+
params: params.resolveParams,
|
|
28055
|
+
absolutePath: params.absolutePath,
|
|
28056
|
+
});
|
|
28057
|
+
return true;
|
|
28058
|
+
}
|
|
28059
|
+
function handleLexicalStatReadFailure(params) {
|
|
28060
|
+
if (handleLexicalLstatFailure({
|
|
28061
|
+
error: params.error,
|
|
28062
|
+
state: params.state,
|
|
28063
|
+
missingFromIndex: params.missingFromIndex,
|
|
28064
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28065
|
+
resolveParams: params.resolveParams,
|
|
28066
|
+
absolutePath: params.absolutePath,
|
|
28067
|
+
})) {
|
|
28068
|
+
return null;
|
|
28069
|
+
}
|
|
28070
|
+
throw params.error;
|
|
28071
|
+
}
|
|
28072
|
+
function handleLexicalStatDisposition(params) {
|
|
28073
|
+
if (!params.isSymbolicLink) {
|
|
28074
|
+
advanceCanonicalCursorForSegment({
|
|
28075
|
+
state: params.state,
|
|
28076
|
+
segment: params.segment,
|
|
28077
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28078
|
+
params: params.resolveParams,
|
|
28079
|
+
absolutePath: params.absolutePath,
|
|
28080
|
+
});
|
|
28081
|
+
return "continue";
|
|
28082
|
+
}
|
|
28083
|
+
if (params.state.allowFinalSymlink && params.isLast) {
|
|
28084
|
+
params.state.preserveFinalSymlink = true;
|
|
28085
|
+
advanceCanonicalCursorForSegment({
|
|
28086
|
+
state: params.state,
|
|
28087
|
+
segment: params.segment,
|
|
28088
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28089
|
+
params: params.resolveParams,
|
|
28090
|
+
absolutePath: params.absolutePath,
|
|
28091
|
+
});
|
|
28092
|
+
return "break";
|
|
28093
|
+
}
|
|
28094
|
+
return "resolve-link";
|
|
28095
|
+
}
|
|
28096
|
+
function applyResolvedSymlinkHop(params) {
|
|
28097
|
+
if (!path_isPathInside(params.rootCanonicalPath, params.linkCanonical)) {
|
|
28098
|
+
throw symlinkEscapeError({
|
|
28099
|
+
boundaryLabel: params.boundaryLabel,
|
|
28100
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28101
|
+
symlinkPath: params.state.lexicalCursor,
|
|
28102
|
+
});
|
|
28103
|
+
}
|
|
28104
|
+
params.state.canonicalCursor = params.linkCanonical;
|
|
28105
|
+
params.state.lexicalCursor = params.linkCanonical;
|
|
28106
|
+
}
|
|
28107
|
+
function readLexicalStat(params) {
|
|
28108
|
+
try {
|
|
28109
|
+
const stat = params.read(params.state.lexicalCursor);
|
|
28110
|
+
if (isPromiseLike(stat)) {
|
|
28111
|
+
return Promise.resolve(stat).catch((error) => handleLexicalStatReadFailure({ ...params, error }));
|
|
28112
|
+
}
|
|
28113
|
+
return stat;
|
|
28114
|
+
}
|
|
28115
|
+
catch (error) {
|
|
28116
|
+
return handleLexicalStatReadFailure({ ...params, error });
|
|
28117
|
+
}
|
|
28118
|
+
}
|
|
28119
|
+
function resolveAndApplySymlinkHop(params) {
|
|
28120
|
+
const linkCanonical = params.resolveLinkCanonical(params.state.lexicalCursor);
|
|
28121
|
+
if (isPromiseLike(linkCanonical)) {
|
|
28122
|
+
return Promise.resolve(linkCanonical).then((value) => applyResolvedSymlinkHop({
|
|
28123
|
+
state: params.state,
|
|
28124
|
+
linkCanonical: value,
|
|
28125
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28126
|
+
boundaryLabel: params.boundaryLabel,
|
|
28127
|
+
}));
|
|
28128
|
+
}
|
|
28129
|
+
applyResolvedSymlinkHop({
|
|
28130
|
+
state: params.state,
|
|
28131
|
+
linkCanonical,
|
|
28132
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28133
|
+
boundaryLabel: params.boundaryLabel,
|
|
28134
|
+
});
|
|
28135
|
+
}
|
|
28136
|
+
function* iterateLexicalTraversal(state) {
|
|
28137
|
+
for (let idx = 0; idx < state.segments.length; idx += 1) {
|
|
28138
|
+
const segment = state.segments[idx] ?? "";
|
|
28139
|
+
const isLast = idx === state.segments.length - 1;
|
|
28140
|
+
state.lexicalCursor = external_node_path_.join(state.lexicalCursor, segment);
|
|
28141
|
+
yield { idx, segment, isLast };
|
|
28142
|
+
}
|
|
28143
|
+
}
|
|
28144
|
+
async function resolveRootPathLexicalAsync(params) {
|
|
28145
|
+
const state = createLexicalTraversalState(params);
|
|
28146
|
+
const sharedStepParams = {
|
|
28147
|
+
state,
|
|
28148
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28149
|
+
resolveParams: params.params,
|
|
28150
|
+
absolutePath: params.absolutePath,
|
|
28151
|
+
};
|
|
28152
|
+
for (const { idx, segment, isLast } of iterateLexicalTraversal(state)) {
|
|
28153
|
+
const stat = await readLexicalStat({
|
|
28154
|
+
...sharedStepParams,
|
|
28155
|
+
missingFromIndex: idx,
|
|
28156
|
+
read: (cursor) => promises_.lstat(cursor),
|
|
28157
|
+
});
|
|
28158
|
+
if (!stat) {
|
|
28159
|
+
break;
|
|
28160
|
+
}
|
|
28161
|
+
const disposition = handleLexicalStatDisposition({
|
|
28162
|
+
...sharedStepParams,
|
|
28163
|
+
isSymbolicLink: stat.isSymbolicLink(),
|
|
28164
|
+
segment,
|
|
28165
|
+
isLast,
|
|
28166
|
+
});
|
|
28167
|
+
if (disposition === "continue") {
|
|
28168
|
+
continue;
|
|
28169
|
+
}
|
|
28170
|
+
if (disposition === "break") {
|
|
28171
|
+
break;
|
|
28172
|
+
}
|
|
28173
|
+
await resolveAndApplySymlinkHop({
|
|
28174
|
+
state,
|
|
28175
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28176
|
+
boundaryLabel: params.params.boundaryLabel,
|
|
28177
|
+
resolveLinkCanonical: (cursor) => resolveSymlinkHopPath(cursor),
|
|
28178
|
+
});
|
|
28179
|
+
}
|
|
28180
|
+
const kind = await getPathKind(params.absolutePath, state.preserveFinalSymlink);
|
|
28181
|
+
return finalizeLexicalResolution({
|
|
28182
|
+
...params,
|
|
28183
|
+
state,
|
|
28184
|
+
kind,
|
|
28185
|
+
});
|
|
28186
|
+
}
|
|
28187
|
+
function resolveRootPathLexicalSync(params) {
|
|
28188
|
+
const state = createLexicalTraversalState(params);
|
|
28189
|
+
for (let idx = 0; idx < state.segments.length; idx += 1) {
|
|
28190
|
+
const segment = state.segments[idx] ?? "";
|
|
28191
|
+
const isLast = idx === state.segments.length - 1;
|
|
28192
|
+
state.lexicalCursor = path.join(state.lexicalCursor, segment);
|
|
28193
|
+
const maybeStat = readLexicalStat({
|
|
28194
|
+
state,
|
|
28195
|
+
missingFromIndex: idx,
|
|
28196
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28197
|
+
resolveParams: params.params,
|
|
28198
|
+
absolutePath: params.absolutePath,
|
|
28199
|
+
read: (cursor) => fs.lstatSync(cursor),
|
|
28200
|
+
});
|
|
28201
|
+
if (isPromiseLike(maybeStat)) {
|
|
28202
|
+
throw new Error("Unexpected async lexical stat");
|
|
28203
|
+
}
|
|
28204
|
+
const stat = maybeStat;
|
|
28205
|
+
if (!stat) {
|
|
28206
|
+
break;
|
|
28207
|
+
}
|
|
28208
|
+
const disposition = handleLexicalStatDisposition({
|
|
28209
|
+
state,
|
|
28210
|
+
isSymbolicLink: stat.isSymbolicLink(),
|
|
28211
|
+
segment,
|
|
28212
|
+
isLast,
|
|
28213
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28214
|
+
resolveParams: params.params,
|
|
28215
|
+
absolutePath: params.absolutePath,
|
|
28216
|
+
});
|
|
28217
|
+
if (disposition === "continue") {
|
|
28218
|
+
continue;
|
|
28219
|
+
}
|
|
28220
|
+
if (disposition === "break") {
|
|
28221
|
+
break;
|
|
28222
|
+
}
|
|
28223
|
+
const maybeApplied = resolveAndApplySymlinkHop({
|
|
28224
|
+
state,
|
|
28225
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28226
|
+
boundaryLabel: params.params.boundaryLabel,
|
|
28227
|
+
resolveLinkCanonical: (cursor) => resolveSymlinkHopPathSync(cursor),
|
|
28228
|
+
});
|
|
28229
|
+
if (isPromiseLike(maybeApplied)) {
|
|
28230
|
+
throw new Error("Unexpected async symlink resolution");
|
|
28231
|
+
}
|
|
28232
|
+
}
|
|
28233
|
+
const kind = getPathKindSync(params.absolutePath, state.preserveFinalSymlink);
|
|
28234
|
+
return finalizeLexicalResolution({
|
|
28235
|
+
...params,
|
|
28236
|
+
state,
|
|
28237
|
+
kind,
|
|
28238
|
+
});
|
|
28239
|
+
}
|
|
28240
|
+
function resolveCanonicalOutsideLexicalPath(params) {
|
|
28241
|
+
return params.outsideLexicalCanonicalPath ?? params.absolutePath;
|
|
28242
|
+
}
|
|
28243
|
+
function createBoundaryResolutionContext(params) {
|
|
28244
|
+
const lexicalInside = path_isPathInside(params.rootPath, params.absolutePath);
|
|
28245
|
+
const canonicalOutsideLexicalPath = resolveCanonicalOutsideLexicalPath({
|
|
28246
|
+
absolutePath: params.absolutePath,
|
|
28247
|
+
outsideLexicalCanonicalPath: params.outsideLexicalCanonicalPath,
|
|
28248
|
+
});
|
|
28249
|
+
assertLexicalBoundaryOrCanonicalAlias({
|
|
28250
|
+
skipLexicalRootCheck: params.resolveParams.skipLexicalRootCheck,
|
|
28251
|
+
lexicalInside,
|
|
28252
|
+
canonicalOutsideLexicalPath,
|
|
28253
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28254
|
+
boundaryLabel: params.resolveParams.boundaryLabel,
|
|
28255
|
+
rootPath: params.rootPath,
|
|
28256
|
+
absolutePath: params.absolutePath,
|
|
28257
|
+
});
|
|
28258
|
+
return {
|
|
28259
|
+
rootPath: params.rootPath,
|
|
28260
|
+
absolutePath: params.absolutePath,
|
|
28261
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28262
|
+
lexicalInside,
|
|
28263
|
+
canonicalOutsideLexicalPath,
|
|
28264
|
+
};
|
|
28265
|
+
}
|
|
28266
|
+
async function resolveOutsideRootPathAsync(params) {
|
|
28267
|
+
if (params.context.lexicalInside) {
|
|
28268
|
+
return null;
|
|
28269
|
+
}
|
|
28270
|
+
const kind = await getPathKind(params.context.absolutePath, false);
|
|
28271
|
+
return buildOutsideRootPathFromContext({
|
|
28272
|
+
boundaryLabel: params.boundaryLabel,
|
|
28273
|
+
context: params.context,
|
|
28274
|
+
kind,
|
|
28275
|
+
});
|
|
28276
|
+
}
|
|
28277
|
+
function resolveOutsideRootPathSync(params) {
|
|
28278
|
+
if (params.context.lexicalInside) {
|
|
28279
|
+
return null;
|
|
28280
|
+
}
|
|
28281
|
+
const kind = getPathKindSync(params.context.absolutePath, false);
|
|
28282
|
+
return buildOutsideRootPathFromContext({
|
|
28283
|
+
boundaryLabel: params.boundaryLabel,
|
|
28284
|
+
context: params.context,
|
|
28285
|
+
kind,
|
|
28286
|
+
});
|
|
28287
|
+
}
|
|
28288
|
+
function buildOutsideRootPathFromContext(params) {
|
|
28289
|
+
return buildOutsideLexicalRootPath({
|
|
28290
|
+
boundaryLabel: params.boundaryLabel,
|
|
28291
|
+
rootCanonicalPath: params.context.rootCanonicalPath,
|
|
28292
|
+
absolutePath: params.context.absolutePath,
|
|
28293
|
+
canonicalOutsideLexicalPath: params.context.canonicalOutsideLexicalPath,
|
|
28294
|
+
rootPath: params.context.rootPath,
|
|
28295
|
+
kind: params.kind,
|
|
28296
|
+
});
|
|
28297
|
+
}
|
|
28298
|
+
async function resolveOutsideLexicalCanonicalPathAsync(params) {
|
|
28299
|
+
if (path_isPathInside(params.rootPath, params.absolutePath)) {
|
|
28300
|
+
return undefined;
|
|
28301
|
+
}
|
|
28302
|
+
return await resolvePathViaExistingAncestor(params.absolutePath);
|
|
28303
|
+
}
|
|
28304
|
+
function resolveOutsideLexicalCanonicalPathSync(params) {
|
|
28305
|
+
if (isPathInside(params.rootPath, params.absolutePath)) {
|
|
28306
|
+
return undefined;
|
|
28307
|
+
}
|
|
28308
|
+
return resolvePathViaExistingAncestorSync(params.absolutePath);
|
|
28309
|
+
}
|
|
28310
|
+
function buildOutsideLexicalRootPath(params) {
|
|
28311
|
+
assertInsideBoundary({
|
|
28312
|
+
boundaryLabel: params.boundaryLabel,
|
|
28313
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28314
|
+
candidatePath: params.canonicalOutsideLexicalPath,
|
|
28315
|
+
absolutePath: params.absolutePath,
|
|
28316
|
+
});
|
|
28317
|
+
return buildResolvedRootPath({
|
|
28318
|
+
absolutePath: params.absolutePath,
|
|
28319
|
+
canonicalPath: params.canonicalOutsideLexicalPath,
|
|
28320
|
+
rootPath: params.rootPath,
|
|
28321
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28322
|
+
kind: params.kind,
|
|
28323
|
+
});
|
|
28324
|
+
}
|
|
28325
|
+
function assertLexicalBoundaryOrCanonicalAlias(params) {
|
|
28326
|
+
if (params.skipLexicalRootCheck || params.lexicalInside) {
|
|
28327
|
+
return;
|
|
28328
|
+
}
|
|
28329
|
+
if (path_isPathInside(params.rootCanonicalPath, params.canonicalOutsideLexicalPath)) {
|
|
28330
|
+
return;
|
|
28331
|
+
}
|
|
28332
|
+
throw pathEscapeError({
|
|
28333
|
+
boundaryLabel: params.boundaryLabel,
|
|
28334
|
+
rootPath: params.rootPath,
|
|
28335
|
+
absolutePath: params.absolutePath,
|
|
28336
|
+
});
|
|
28337
|
+
}
|
|
28338
|
+
function buildResolvedRootPath(params) {
|
|
28339
|
+
return {
|
|
28340
|
+
absolutePath: params.absolutePath,
|
|
28341
|
+
canonicalPath: params.canonicalPath,
|
|
28342
|
+
rootPath: params.rootPath,
|
|
28343
|
+
rootCanonicalPath: params.rootCanonicalPath,
|
|
28344
|
+
relativePath: relativeInsideRoot(params.rootCanonicalPath, params.canonicalPath),
|
|
28345
|
+
exists: params.kind.exists,
|
|
28346
|
+
kind: params.kind.kind,
|
|
28347
|
+
};
|
|
28348
|
+
}
|
|
28349
|
+
async function resolvePathViaExistingAncestor(targetPath) {
|
|
28350
|
+
const normalized = external_node_path_.resolve(targetPath);
|
|
28351
|
+
let cursor = normalized;
|
|
28352
|
+
const missingSuffix = [];
|
|
28353
|
+
while (!isFilesystemRoot(cursor) && !(await pathExists(cursor))) {
|
|
28354
|
+
missingSuffix.unshift(external_node_path_.basename(cursor));
|
|
28355
|
+
const parent = external_node_path_.dirname(cursor);
|
|
28356
|
+
if (parent === cursor) {
|
|
28357
|
+
break;
|
|
28358
|
+
}
|
|
28359
|
+
cursor = parent;
|
|
28360
|
+
}
|
|
28361
|
+
if (!(await pathExists(cursor))) {
|
|
28362
|
+
return normalized;
|
|
28363
|
+
}
|
|
28364
|
+
try {
|
|
28365
|
+
const resolvedAncestor = external_node_path_.resolve(await promises_.realpath(cursor));
|
|
28366
|
+
if (missingSuffix.length === 0) {
|
|
28367
|
+
return resolvedAncestor;
|
|
28368
|
+
}
|
|
28369
|
+
return external_node_path_.resolve(resolvedAncestor, ...missingSuffix);
|
|
28370
|
+
}
|
|
28371
|
+
catch {
|
|
28372
|
+
return normalized;
|
|
28373
|
+
}
|
|
28374
|
+
}
|
|
28375
|
+
function resolvePathViaExistingAncestorSync(targetPath) {
|
|
28376
|
+
const normalized = path.resolve(targetPath);
|
|
28377
|
+
let cursor = normalized;
|
|
28378
|
+
const missingSuffix = [];
|
|
28379
|
+
while (!isFilesystemRoot(cursor) && !fs.existsSync(cursor)) {
|
|
28380
|
+
missingSuffix.unshift(path.basename(cursor));
|
|
28381
|
+
const parent = path.dirname(cursor);
|
|
28382
|
+
if (parent === cursor) {
|
|
28383
|
+
break;
|
|
28384
|
+
}
|
|
28385
|
+
cursor = parent;
|
|
28386
|
+
}
|
|
28387
|
+
if (!fs.existsSync(cursor)) {
|
|
28388
|
+
return normalized;
|
|
28389
|
+
}
|
|
28390
|
+
try {
|
|
28391
|
+
// Keep sync behavior aligned with async (`fsp.realpath`) to avoid
|
|
28392
|
+
// platform-specific canonical alias drift (notably on Windows).
|
|
28393
|
+
const resolvedAncestor = path.resolve(fs.realpathSync(cursor));
|
|
28394
|
+
if (missingSuffix.length === 0) {
|
|
28395
|
+
return resolvedAncestor;
|
|
28396
|
+
}
|
|
28397
|
+
return path.resolve(resolvedAncestor, ...missingSuffix);
|
|
28398
|
+
}
|
|
28399
|
+
catch {
|
|
28400
|
+
return normalized;
|
|
28401
|
+
}
|
|
28402
|
+
}
|
|
28403
|
+
async function getPathKind(absolutePath, preserveFinalSymlink) {
|
|
28404
|
+
try {
|
|
28405
|
+
const stat = preserveFinalSymlink
|
|
28406
|
+
? await promises_.lstat(absolutePath)
|
|
28407
|
+
: await promises_.stat(absolutePath);
|
|
28408
|
+
return { exists: true, kind: toResolvedKind(stat) };
|
|
28409
|
+
}
|
|
28410
|
+
catch (error) {
|
|
28411
|
+
if (path_isNotFoundPathError(error)) {
|
|
28412
|
+
return { exists: false, kind: "missing" };
|
|
28413
|
+
}
|
|
28414
|
+
throw error;
|
|
28415
|
+
}
|
|
28416
|
+
}
|
|
28417
|
+
function getPathKindSync(absolutePath, preserveFinalSymlink) {
|
|
28418
|
+
try {
|
|
28419
|
+
const stat = preserveFinalSymlink ? fs.lstatSync(absolutePath) : fs.statSync(absolutePath);
|
|
28420
|
+
return { exists: true, kind: toResolvedKind(stat) };
|
|
28421
|
+
}
|
|
28422
|
+
catch (error) {
|
|
28423
|
+
if (isNotFoundPathError(error)) {
|
|
28424
|
+
return { exists: false, kind: "missing" };
|
|
28425
|
+
}
|
|
28426
|
+
throw error;
|
|
28427
|
+
}
|
|
28428
|
+
}
|
|
28429
|
+
function toResolvedKind(stat) {
|
|
28430
|
+
if (stat.isFile()) {
|
|
28431
|
+
return "file";
|
|
28432
|
+
}
|
|
28433
|
+
if (stat.isDirectory()) {
|
|
28434
|
+
return "directory";
|
|
28435
|
+
}
|
|
28436
|
+
if (stat.isSymbolicLink()) {
|
|
28437
|
+
return "symlink";
|
|
28438
|
+
}
|
|
28439
|
+
return "other";
|
|
28440
|
+
}
|
|
28441
|
+
function relativeInsideRoot(rootPath, targetPath) {
|
|
28442
|
+
const relative = external_node_path_.relative(external_node_path_.resolve(rootPath), external_node_path_.resolve(targetPath));
|
|
28443
|
+
if (!relative || relative === ".") {
|
|
28444
|
+
return "";
|
|
28445
|
+
}
|
|
28446
|
+
if (relative.startsWith("..") || external_node_path_.isAbsolute(relative)) {
|
|
28447
|
+
return "";
|
|
28448
|
+
}
|
|
28449
|
+
return relative;
|
|
28450
|
+
}
|
|
28451
|
+
function assertInsideBoundary(params) {
|
|
28452
|
+
if (path_isPathInside(params.rootCanonicalPath, params.candidatePath)) {
|
|
28453
|
+
return;
|
|
28454
|
+
}
|
|
28455
|
+
throw new Error(`Path resolves outside ${params.boundaryLabel} (${shortPath(params.rootCanonicalPath)}): ${shortPath(params.absolutePath)}`);
|
|
28456
|
+
}
|
|
28457
|
+
function pathEscapeError(params) {
|
|
28458
|
+
return new Error(`Path escapes ${params.boundaryLabel} (${shortPath(params.rootPath)}): ${shortPath(params.absolutePath)}`);
|
|
28459
|
+
}
|
|
28460
|
+
function symlinkEscapeError(params) {
|
|
28461
|
+
return new Error(`Symlink escapes ${params.boundaryLabel} (${shortPath(params.rootCanonicalPath)}): ${shortPath(params.symlinkPath)}`);
|
|
28462
|
+
}
|
|
28463
|
+
function shortPath(value) {
|
|
28464
|
+
const home = external_node_os_.homedir();
|
|
28465
|
+
if (value.startsWith(home)) {
|
|
28466
|
+
return `~${value.slice(home.length)}`;
|
|
28467
|
+
}
|
|
28468
|
+
return value;
|
|
28469
|
+
}
|
|
28470
|
+
function isFilesystemRoot(candidate) {
|
|
28471
|
+
return external_node_path_.parse(candidate).root === candidate;
|
|
28472
|
+
}
|
|
28473
|
+
async function pathExists(targetPath) {
|
|
28474
|
+
try {
|
|
28475
|
+
await promises_.lstat(targetPath);
|
|
28476
|
+
return true;
|
|
28477
|
+
}
|
|
28478
|
+
catch (error) {
|
|
28479
|
+
if (path_isNotFoundPathError(error)) {
|
|
28480
|
+
return false;
|
|
28481
|
+
}
|
|
28482
|
+
throw error;
|
|
28483
|
+
}
|
|
28484
|
+
}
|
|
28485
|
+
async function resolveSymlinkHopPath(symlinkPath) {
|
|
28486
|
+
try {
|
|
28487
|
+
return external_node_path_.resolve(await promises_.realpath(symlinkPath));
|
|
28488
|
+
}
|
|
28489
|
+
catch (error) {
|
|
28490
|
+
if (!path_isNotFoundPathError(error)) {
|
|
28491
|
+
throw error;
|
|
28492
|
+
}
|
|
28493
|
+
const linkTarget = await promises_.readlink(symlinkPath);
|
|
28494
|
+
const linkAbsolute = external_node_path_.resolve(external_node_path_.dirname(symlinkPath), linkTarget);
|
|
28495
|
+
return resolvePathViaExistingAncestor(linkAbsolute);
|
|
28496
|
+
}
|
|
28497
|
+
}
|
|
28498
|
+
function resolveSymlinkHopPathSync(symlinkPath) {
|
|
28499
|
+
try {
|
|
28500
|
+
return path.resolve(fs.realpathSync(symlinkPath));
|
|
28501
|
+
}
|
|
28502
|
+
catch (error) {
|
|
28503
|
+
if (!isNotFoundPathError(error)) {
|
|
28504
|
+
throw error;
|
|
28505
|
+
}
|
|
28506
|
+
const linkTarget = fs.readlinkSync(symlinkPath);
|
|
28507
|
+
const linkAbsolute = path.resolve(path.dirname(symlinkPath), linkTarget);
|
|
28508
|
+
return resolvePathViaExistingAncestorSync(linkAbsolute);
|
|
28509
|
+
}
|
|
28510
|
+
}
|
|
28511
|
+
|
|
28512
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/path-policy.js
|
|
28513
|
+
|
|
28514
|
+
|
|
28515
|
+
|
|
28516
|
+
|
|
28517
|
+
const PATH_ALIAS_POLICIES = ROOT_PATH_ALIAS_POLICIES;
|
|
28518
|
+
async function assertNoPathAliasEscape(params) {
|
|
28519
|
+
const resolved = await resolveRootPath({
|
|
28520
|
+
absolutePath: params.absolutePath,
|
|
28521
|
+
rootPath: params.rootPath,
|
|
28522
|
+
boundaryLabel: params.boundaryLabel,
|
|
28523
|
+
policy: params.policy,
|
|
28524
|
+
});
|
|
28525
|
+
const allowFinalSymlink = params.policy?.allowFinalSymlinkForUnlink === true;
|
|
28526
|
+
if (allowFinalSymlink && resolved.kind === "symlink") {
|
|
28527
|
+
return;
|
|
28528
|
+
}
|
|
28529
|
+
await assertNoHardlinkedFinalPath({
|
|
28530
|
+
filePath: resolved.absolutePath,
|
|
28531
|
+
root: resolved.rootPath,
|
|
28532
|
+
boundaryLabel: params.boundaryLabel,
|
|
28533
|
+
allowFinalHardlinkForUnlink: params.policy?.allowFinalHardlinkForUnlink,
|
|
28534
|
+
});
|
|
28535
|
+
}
|
|
28536
|
+
async function assertNoHardlinkedFinalPath(params) {
|
|
28537
|
+
if (params.allowFinalHardlinkForUnlink) {
|
|
28538
|
+
return;
|
|
28539
|
+
}
|
|
28540
|
+
let stat;
|
|
28541
|
+
try {
|
|
28542
|
+
stat = await promises_.stat(params.filePath);
|
|
28543
|
+
}
|
|
28544
|
+
catch (err) {
|
|
28545
|
+
if (path_isNotFoundPathError(err)) {
|
|
28546
|
+
return;
|
|
28547
|
+
}
|
|
28548
|
+
throw err;
|
|
28549
|
+
}
|
|
28550
|
+
if (!stat.isFile()) {
|
|
28551
|
+
return;
|
|
28552
|
+
}
|
|
28553
|
+
if (stat.nlink > 1) {
|
|
28554
|
+
throw new Error(`Hardlinked path is not allowed under ${params.boundaryLabel} (${path_policy_shortPath(params.root)}): ${path_policy_shortPath(params.filePath)}`);
|
|
28555
|
+
}
|
|
28556
|
+
}
|
|
28557
|
+
function path_policy_shortPath(value) {
|
|
28558
|
+
if (value.startsWith(external_node_os_.homedir())) {
|
|
28559
|
+
return `~${value.slice(external_node_os_.homedir().length)}`;
|
|
28560
|
+
}
|
|
28561
|
+
return value;
|
|
28562
|
+
}
|
|
28563
|
+
|
|
28564
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/path-stat.js
|
|
28565
|
+
function pathStatFromStats(stat) {
|
|
28566
|
+
return {
|
|
28567
|
+
dev: Number(stat.dev),
|
|
28568
|
+
gid: Number(stat.gid),
|
|
28569
|
+
ino: Number(stat.ino),
|
|
28570
|
+
isDirectory: stat.isDirectory(),
|
|
28571
|
+
isFile: stat.isFile(),
|
|
28572
|
+
isSymbolicLink: stat.isSymbolicLink(),
|
|
28573
|
+
mode: stat.mode,
|
|
28574
|
+
mtimeMs: stat.mtimeMs,
|
|
28575
|
+
nlink: stat.nlink,
|
|
28576
|
+
size: stat.size,
|
|
28577
|
+
uid: stat.uid,
|
|
28578
|
+
};
|
|
28579
|
+
}
|
|
28580
|
+
|
|
28581
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/home-dir.js
|
|
28582
|
+
|
|
28583
|
+
|
|
28584
|
+
|
|
28585
|
+
function normalize(value) {
|
|
28586
|
+
const trimmed = normalizeOptionalString(value);
|
|
28587
|
+
if (!trimmed) {
|
|
28588
|
+
return undefined;
|
|
28589
|
+
}
|
|
28590
|
+
if (trimmed === "undefined" || trimmed === "null") {
|
|
28591
|
+
return undefined;
|
|
28592
|
+
}
|
|
28593
|
+
return trimmed;
|
|
28594
|
+
}
|
|
28595
|
+
function resolveEffectiveHomeDir(env = process.env, homedir = external_node_os_.homedir) {
|
|
28596
|
+
const raw = resolveRawHomeDir(env, homedir);
|
|
28597
|
+
return raw ? external_node_path_.resolve(raw) : undefined;
|
|
28598
|
+
}
|
|
28599
|
+
function resolveOsHomeDir(env = process.env, homedir = os.homedir) {
|
|
28600
|
+
const raw = resolveRawOsHomeDir(env, homedir);
|
|
28601
|
+
return raw ? path.resolve(raw) : undefined;
|
|
28602
|
+
}
|
|
28603
|
+
function resolveRawHomeDir(env, homedir) {
|
|
28604
|
+
const explicitHome = normalize(env.OPENCLAW_HOME);
|
|
28605
|
+
if (!explicitHome) {
|
|
28606
|
+
return resolveRawOsHomeDir(env, homedir);
|
|
28607
|
+
}
|
|
28608
|
+
const segments = external_node_path_.normalize(explicitHome).split(external_node_path_.sep);
|
|
28609
|
+
if (segments[0] !== "~") {
|
|
28610
|
+
return explicitHome;
|
|
28611
|
+
}
|
|
28612
|
+
// OPENCLAW_HOME starts with "~"; expand against the os home dir. Fall
|
|
28613
|
+
// back to undefined when there is no os home to expand against rather
|
|
28614
|
+
// than returning a raw "~"-prefixed path the caller cannot use.
|
|
28615
|
+
const fallbackHome = resolveRawOsHomeDir(env, homedir);
|
|
28616
|
+
if (!fallbackHome) {
|
|
28617
|
+
return undefined;
|
|
28618
|
+
}
|
|
28619
|
+
return expandHomePrefix(explicitHome, { home: fallbackHome });
|
|
28620
|
+
}
|
|
28621
|
+
function resolveRawOsHomeDir(env, homedir) {
|
|
28622
|
+
const envHome = normalize(env.HOME);
|
|
28623
|
+
if (envHome) {
|
|
28624
|
+
return envHome;
|
|
28625
|
+
}
|
|
28626
|
+
const userProfile = normalize(env.USERPROFILE);
|
|
28627
|
+
if (userProfile) {
|
|
28628
|
+
return userProfile;
|
|
28629
|
+
}
|
|
28630
|
+
return normalizeSafe(homedir);
|
|
28631
|
+
}
|
|
28632
|
+
function normalizeSafe(homedir) {
|
|
28633
|
+
try {
|
|
28634
|
+
return normalize(homedir());
|
|
28635
|
+
}
|
|
28636
|
+
catch {
|
|
28637
|
+
return undefined;
|
|
28638
|
+
}
|
|
28639
|
+
}
|
|
28640
|
+
function resolveRequiredHomeDir(env = process.env, homedir = os.homedir) {
|
|
28641
|
+
return resolveEffectiveHomeDir(env, homedir) ?? path.resolve(process.cwd());
|
|
28642
|
+
}
|
|
28643
|
+
function resolveRequiredOsHomeDir(env = process.env, homedir = os.homedir) {
|
|
28644
|
+
return resolveOsHomeDir(env, homedir) ?? path.resolve(process.cwd());
|
|
28645
|
+
}
|
|
28646
|
+
function expandHomePrefix(input, opts) {
|
|
28647
|
+
const segments = external_node_path_.normalize(input).split(external_node_path_.sep);
|
|
28648
|
+
if (segments[0] !== "~") {
|
|
28649
|
+
return input;
|
|
28650
|
+
}
|
|
28651
|
+
const home = normalize(opts?.home) ??
|
|
28652
|
+
resolveEffectiveHomeDir(opts?.env ?? process.env, opts?.homedir ?? external_node_os_.homedir);
|
|
28653
|
+
if (!home) {
|
|
28654
|
+
return input;
|
|
28655
|
+
}
|
|
28656
|
+
return external_node_path_.join(home, ...segments.slice(1));
|
|
28657
|
+
}
|
|
28658
|
+
function resolveHomeRelativePath(input, opts) {
|
|
28659
|
+
if (!input) {
|
|
28660
|
+
return input;
|
|
28661
|
+
}
|
|
28662
|
+
const segments = path.normalize(input).split(path.sep);
|
|
28663
|
+
if (segments[0] !== "~") {
|
|
28664
|
+
return path.resolve(input);
|
|
28665
|
+
}
|
|
28666
|
+
const expanded = expandHomePrefix(input, {
|
|
28667
|
+
home: resolveRequiredHomeDir(opts?.env ?? process.env, opts?.homedir ?? os.homedir),
|
|
28668
|
+
env: opts?.env,
|
|
28669
|
+
homedir: opts?.homedir,
|
|
28670
|
+
});
|
|
28671
|
+
return path.resolve(expanded);
|
|
28672
|
+
}
|
|
28673
|
+
function resolveUserPath(input, optsOrEnv, homedir) {
|
|
28674
|
+
const opts = optsOrEnv && ("env" in optsOrEnv || "homedir" in optsOrEnv)
|
|
28675
|
+
? optsOrEnv
|
|
28676
|
+
: { env: optsOrEnv, homedir };
|
|
28677
|
+
return resolveHomeRelativePath(input, opts);
|
|
28678
|
+
}
|
|
28679
|
+
function resolveOsHomeRelativePath(input, opts) {
|
|
28680
|
+
if (!input) {
|
|
28681
|
+
return input;
|
|
28682
|
+
}
|
|
28683
|
+
const segments = path.normalize(input).split(path.sep);
|
|
28684
|
+
if (segments[0] !== "~") {
|
|
28685
|
+
return path.resolve(input);
|
|
28686
|
+
}
|
|
28687
|
+
const expanded = expandHomePrefix(input, {
|
|
28688
|
+
home: resolveRequiredOsHomeDir(opts?.env ?? process.env, opts?.homedir ?? os.homedir),
|
|
28689
|
+
env: opts?.env,
|
|
28690
|
+
homedir: opts?.homedir,
|
|
28691
|
+
});
|
|
28692
|
+
return path.resolve(expanded);
|
|
28693
|
+
}
|
|
28694
|
+
|
|
28695
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-context.js
|
|
28696
|
+
|
|
28697
|
+
|
|
28698
|
+
|
|
28699
|
+
|
|
28700
|
+
|
|
28701
|
+
|
|
28702
|
+
const ensureTrailingSep = (value) => value.endsWith(external_node_path_.sep) ? value : value + external_node_path_.sep;
|
|
28703
|
+
function assertValidRootRelativePath(relativePath) {
|
|
28704
|
+
path_assertNoNulPathInput(relativePath, "relative path contains a NUL byte");
|
|
28705
|
+
}
|
|
28706
|
+
let cachedHomePath;
|
|
28707
|
+
async function expandRelativePathWithHome(relativePath) {
|
|
28708
|
+
const rawHome = process.env.HOME || process.env.USERPROFILE || external_node_os_.homedir();
|
|
28709
|
+
if (cachedHomePath?.raw !== rawHome) {
|
|
28710
|
+
let realHome = rawHome;
|
|
28711
|
+
try {
|
|
28712
|
+
realHome = await promises_.realpath(rawHome);
|
|
28713
|
+
}
|
|
28714
|
+
catch {
|
|
28715
|
+
// If the home dir cannot be canonicalized, keep lexical expansion behavior.
|
|
28716
|
+
}
|
|
28717
|
+
cachedHomePath = { raw: rawHome, real: realHome };
|
|
28718
|
+
}
|
|
28719
|
+
return expandHomePrefix(relativePath, { home: cachedHomePath.real });
|
|
28720
|
+
}
|
|
28721
|
+
async function resolveRootContext(rootDir) {
|
|
28722
|
+
path_assertNoNulPathInput(rootDir, "root dir contains a NUL byte");
|
|
28723
|
+
let rootReal;
|
|
28724
|
+
try {
|
|
28725
|
+
rootReal = await promises_.realpath(rootDir);
|
|
28726
|
+
const rootStat = await promises_.stat(rootReal);
|
|
28727
|
+
if (!rootStat.isDirectory()) {
|
|
28728
|
+
throw new errors_FsSafeError("invalid-path", "root dir is not a directory");
|
|
28729
|
+
}
|
|
28730
|
+
}
|
|
28731
|
+
catch (err) {
|
|
28732
|
+
if (err instanceof errors_FsSafeError) {
|
|
28733
|
+
throw err;
|
|
28734
|
+
}
|
|
28735
|
+
if (path_isNotFoundPathError(err)) {
|
|
28736
|
+
throw new errors_FsSafeError("not-found", "root dir not found");
|
|
28737
|
+
}
|
|
28738
|
+
throw err;
|
|
28739
|
+
}
|
|
28740
|
+
return {
|
|
28741
|
+
rootDir: external_node_path_.resolve(rootDir),
|
|
28742
|
+
rootReal,
|
|
28743
|
+
rootWithSep: ensureTrailingSep(rootReal),
|
|
28744
|
+
};
|
|
28745
|
+
}
|
|
28746
|
+
async function resolvePathInRoot(root, relativePath) {
|
|
28747
|
+
assertValidRootRelativePath(relativePath);
|
|
28748
|
+
const expanded = await expandRelativePathWithHome(relativePath);
|
|
28749
|
+
const resolved = external_node_path_.resolve(root.rootWithSep, expanded);
|
|
28750
|
+
if (!path_isPathInside(root.rootWithSep, resolved)) {
|
|
28751
|
+
throw new errors_FsSafeError("outside-workspace", "file is outside workspace root");
|
|
28752
|
+
}
|
|
28753
|
+
return { rootReal: root.rootReal, rootWithSep: root.rootWithSep, resolved };
|
|
28754
|
+
}
|
|
28755
|
+
async function resolvePathWithinRoot(params) {
|
|
28756
|
+
return await resolvePathInRoot(await resolveRootContext(params.rootDir), params.relativePath);
|
|
28757
|
+
}
|
|
28758
|
+
|
|
28759
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-errors.js
|
|
28760
|
+
|
|
28761
|
+
|
|
28762
|
+
function isAlreadyExistsError(error) {
|
|
28763
|
+
return hasNodeErrorCode(error, "EEXIST") || /File exists|EEXIST/i.test(String(error));
|
|
28764
|
+
}
|
|
28765
|
+
function normalizePinnedWriteError(error) {
|
|
28766
|
+
if (error instanceof errors_FsSafeError) {
|
|
28767
|
+
return error;
|
|
28768
|
+
}
|
|
28769
|
+
return new errors_FsSafeError("invalid-path", "path is not a regular file under root", {
|
|
28770
|
+
cause: error instanceof Error ? error : undefined,
|
|
28771
|
+
});
|
|
28772
|
+
}
|
|
28773
|
+
function normalizePinnedPathError(error) {
|
|
28774
|
+
if (error instanceof errors_FsSafeError) {
|
|
28775
|
+
return error;
|
|
28776
|
+
}
|
|
28777
|
+
return new errors_FsSafeError("path-alias", "path is not under root", {
|
|
28778
|
+
cause: error instanceof Error ? error : undefined,
|
|
28779
|
+
});
|
|
28780
|
+
}
|
|
28781
|
+
|
|
28782
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/test-hooks.js
|
|
28783
|
+
let test_hooks_fsSafeTestHooks;
|
|
28784
|
+
function allowFsSafeTestHooks() {
|
|
28785
|
+
return false || process.env.VITEST === "true";
|
|
28786
|
+
}
|
|
28787
|
+
function getFsSafeTestHooks() {
|
|
28788
|
+
return test_hooks_fsSafeTestHooks;
|
|
28789
|
+
}
|
|
28790
|
+
function __setFsSafeTestHooksForTest(hooks) {
|
|
28791
|
+
if (hooks && !allowFsSafeTestHooks()) {
|
|
28792
|
+
throw new Error("__setFsSafeTestHooksForTest is only available in tests");
|
|
28793
|
+
}
|
|
28794
|
+
test_hooks_fsSafeTestHooks = hooks;
|
|
28795
|
+
}
|
|
28796
|
+
|
|
28797
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/temp-cleanup.js
|
|
28798
|
+
|
|
28799
|
+
const tempCleanupEntries = new Map();
|
|
28800
|
+
let cleanupRegistered = false;
|
|
28801
|
+
function cleanupRegisteredTempPathsSync() {
|
|
28802
|
+
for (const entry of tempCleanupEntries.values()) {
|
|
28803
|
+
try {
|
|
28804
|
+
external_node_fs_.rmSync(entry.path, { force: true, recursive: entry.recursive });
|
|
28805
|
+
}
|
|
28806
|
+
catch {
|
|
28807
|
+
// Process-exit cleanup is best-effort.
|
|
28808
|
+
}
|
|
28809
|
+
}
|
|
28810
|
+
tempCleanupEntries.clear();
|
|
28811
|
+
}
|
|
28812
|
+
function registerTempPathForExit(tempPath, options) {
|
|
28813
|
+
if (!cleanupRegistered) {
|
|
28814
|
+
cleanupRegistered = true;
|
|
28815
|
+
process.once("exit", cleanupRegisteredTempPathsSync);
|
|
28816
|
+
}
|
|
28817
|
+
tempCleanupEntries.set(tempPath, {
|
|
28818
|
+
path: tempPath,
|
|
28819
|
+
recursive: options?.recursive === true,
|
|
28820
|
+
});
|
|
28821
|
+
return () => {
|
|
28822
|
+
tempCleanupEntries.delete(tempPath);
|
|
28823
|
+
};
|
|
28824
|
+
}
|
|
28825
|
+
function __cleanupRegisteredTempPathsForTest() {
|
|
28826
|
+
cleanupRegisteredTempPathsSync();
|
|
28827
|
+
}
|
|
28828
|
+
function __cleanupRegisteredTempPathForTest(tempPath) {
|
|
28829
|
+
const entry = tempCleanupEntries.get(tempPath);
|
|
28830
|
+
if (!entry) {
|
|
28831
|
+
return;
|
|
28832
|
+
}
|
|
28833
|
+
try {
|
|
28834
|
+
fsSync.rmSync(entry.path, { force: true, recursive: entry.recursive });
|
|
28835
|
+
}
|
|
28836
|
+
finally {
|
|
28837
|
+
tempCleanupEntries.delete(tempPath);
|
|
28838
|
+
}
|
|
28839
|
+
}
|
|
28840
|
+
|
|
28841
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/write-queue.js
|
|
28842
|
+
const writeQueues = new Map();
|
|
28843
|
+
async function serializePathWrite(key, run) {
|
|
28844
|
+
const previous = writeQueues.get(key) ?? Promise.resolve();
|
|
28845
|
+
const task = (async () => {
|
|
28846
|
+
await previous.catch(() => undefined);
|
|
28847
|
+
return await run();
|
|
28848
|
+
})();
|
|
28849
|
+
const done = task.then(() => undefined, () => undefined);
|
|
28850
|
+
writeQueues.set(key, done);
|
|
28851
|
+
try {
|
|
28852
|
+
return await task;
|
|
28853
|
+
}
|
|
28854
|
+
finally {
|
|
28855
|
+
if (writeQueues.get(key) === done) {
|
|
28856
|
+
writeQueues.delete(key);
|
|
28857
|
+
}
|
|
28858
|
+
}
|
|
28859
|
+
}
|
|
28860
|
+
|
|
28861
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-impl.js
|
|
28862
|
+
|
|
28863
|
+
|
|
28864
|
+
|
|
28865
|
+
|
|
28866
|
+
|
|
28867
|
+
|
|
28868
|
+
|
|
28869
|
+
|
|
28870
|
+
|
|
28871
|
+
|
|
28872
|
+
|
|
28873
|
+
|
|
28874
|
+
|
|
28875
|
+
|
|
28876
|
+
|
|
28877
|
+
|
|
28878
|
+
|
|
28879
|
+
|
|
28880
|
+
|
|
28881
|
+
|
|
28882
|
+
|
|
28883
|
+
|
|
28884
|
+
|
|
28885
|
+
|
|
28886
|
+
function logWarn(message) {
|
|
28887
|
+
if (process.env.FS_SAFE_DEBUG_WARNINGS === "1") {
|
|
28888
|
+
console.warn(message);
|
|
28889
|
+
}
|
|
28890
|
+
}
|
|
28891
|
+
const SUPPORTS_NOFOLLOW = process.platform !== "win32" && "O_NOFOLLOW" in external_node_fs_.constants;
|
|
28892
|
+
const NONBLOCK_OPEN_FLAG = "O_NONBLOCK" in external_node_fs_.constants ? external_node_fs_.constants.O_NONBLOCK : 0;
|
|
28893
|
+
const OPEN_READ_FLAGS = external_node_fs_.constants.O_RDONLY | (SUPPORTS_NOFOLLOW ? external_node_fs_.constants.O_NOFOLLOW : 0);
|
|
28894
|
+
const OPEN_READ_NONBLOCK_FLAGS = OPEN_READ_FLAGS | NONBLOCK_OPEN_FLAG;
|
|
28895
|
+
const OPEN_READ_FOLLOW_FLAGS = external_node_fs_.constants.O_RDONLY;
|
|
28896
|
+
const OPEN_READ_FOLLOW_NONBLOCK_FLAGS = OPEN_READ_FOLLOW_FLAGS | NONBLOCK_OPEN_FLAG;
|
|
28897
|
+
const OPEN_WRITE_EXISTING_FLAGS = external_node_fs_.constants.O_WRONLY | (SUPPORTS_NOFOLLOW ? external_node_fs_.constants.O_NOFOLLOW : 0);
|
|
28898
|
+
const OPEN_WRITE_CREATE_FLAGS = external_node_fs_.constants.O_WRONLY |
|
|
28899
|
+
external_node_fs_.constants.O_CREAT |
|
|
28900
|
+
external_node_fs_.constants.O_EXCL |
|
|
28901
|
+
(SUPPORTS_NOFOLLOW ? external_node_fs_.constants.O_NOFOLLOW : 0);
|
|
28902
|
+
const OPEN_APPEND_EXISTING_FLAGS = external_node_fs_.constants.O_RDWR | external_node_fs_.constants.O_APPEND | (SUPPORTS_NOFOLLOW ? external_node_fs_.constants.O_NOFOLLOW : 0);
|
|
28903
|
+
const OPEN_APPEND_CREATE_FLAGS = external_node_fs_.constants.O_RDWR |
|
|
28904
|
+
external_node_fs_.constants.O_APPEND |
|
|
28905
|
+
external_node_fs_.constants.O_CREAT |
|
|
28906
|
+
external_node_fs_.constants.O_EXCL |
|
|
28907
|
+
(SUPPORTS_NOFOLLOW ? external_node_fs_.constants.O_NOFOLLOW : 0);
|
|
28908
|
+
const DEFAULT_ROOT_MAX_BYTES = 16 * 1024 * 1024;
|
|
28909
|
+
function closeHandleForDispose(handle) {
|
|
28910
|
+
return handle.close().catch(() => undefined);
|
|
28911
|
+
}
|
|
28912
|
+
function openResult(params) {
|
|
28913
|
+
return {
|
|
28914
|
+
handle: params.handle,
|
|
28915
|
+
realPath: params.realPath,
|
|
28916
|
+
stat: params.stat,
|
|
28917
|
+
[Symbol.asyncDispose]: async () => {
|
|
28918
|
+
await closeHandleForDispose(params.handle);
|
|
28919
|
+
},
|
|
28920
|
+
};
|
|
28921
|
+
}
|
|
28922
|
+
async function openVerifiedLocalFile(filePath, options) {
|
|
28923
|
+
const fsSafeTestHooks = getFsSafeTestHooks();
|
|
28924
|
+
// Reject directories before opening so we never surface EISDIR to callers (e.g. tool
|
|
28925
|
+
// results that get sent to messaging channels). See openclaw/openclaw#31186.
|
|
28926
|
+
try {
|
|
28927
|
+
const preStat = await promises_.lstat(filePath);
|
|
28928
|
+
if (preStat.isDirectory()) {
|
|
28929
|
+
throw new errors_FsSafeError("not-file", "not a file");
|
|
28930
|
+
}
|
|
28931
|
+
await fsSafeTestHooks?.afterPreOpenLstat?.(filePath);
|
|
28932
|
+
}
|
|
28933
|
+
catch (err) {
|
|
28934
|
+
if (err instanceof errors_FsSafeError) {
|
|
28935
|
+
throw err;
|
|
28936
|
+
}
|
|
28937
|
+
// ENOENT and other lstat errors: fall through and let fs.open handle.
|
|
28938
|
+
}
|
|
28939
|
+
let handle;
|
|
28940
|
+
try {
|
|
28941
|
+
const openFlags = options?.symlinks === "follow-within-root"
|
|
28942
|
+
? options?.nonBlockingRead
|
|
28943
|
+
? OPEN_READ_FOLLOW_NONBLOCK_FLAGS
|
|
28944
|
+
: OPEN_READ_FOLLOW_FLAGS
|
|
28945
|
+
: options?.nonBlockingRead
|
|
28946
|
+
? OPEN_READ_NONBLOCK_FLAGS
|
|
28947
|
+
: OPEN_READ_FLAGS;
|
|
28948
|
+
await fsSafeTestHooks?.beforeOpen?.(filePath, openFlags);
|
|
28949
|
+
handle = await promises_.open(filePath, openFlags);
|
|
28950
|
+
try {
|
|
28951
|
+
await fsSafeTestHooks?.afterOpen?.(filePath, handle);
|
|
28952
|
+
}
|
|
28953
|
+
catch (err) {
|
|
28954
|
+
await handle.close().catch(() => { });
|
|
28955
|
+
throw err;
|
|
28956
|
+
}
|
|
28957
|
+
}
|
|
28958
|
+
catch (err) {
|
|
28959
|
+
if (path_isNotFoundPathError(err)) {
|
|
28960
|
+
throw new errors_FsSafeError("not-found", "file not found");
|
|
28961
|
+
}
|
|
28962
|
+
if (isSymlinkOpenError(err)) {
|
|
28963
|
+
throw new errors_FsSafeError("symlink", "symlink open blocked", { cause: err });
|
|
28964
|
+
}
|
|
28965
|
+
// Defensive: if open still throws EISDIR (e.g. race), sanitize so it never leaks.
|
|
28966
|
+
if (hasNodeErrorCode(err, "EISDIR")) {
|
|
28967
|
+
throw new errors_FsSafeError("not-file", "not a file");
|
|
28968
|
+
}
|
|
28969
|
+
throw err;
|
|
28970
|
+
}
|
|
28971
|
+
try {
|
|
28972
|
+
const stat = await handle.stat();
|
|
28973
|
+
if (!stat.isFile()) {
|
|
28974
|
+
throw new errors_FsSafeError("not-file", "not a file");
|
|
28975
|
+
}
|
|
28976
|
+
if (options?.hardlinks === "reject" && stat.nlink > 1) {
|
|
28977
|
+
throw new errors_FsSafeError("hardlink", "hardlinked path not allowed");
|
|
28978
|
+
}
|
|
28979
|
+
if (options?.symlinks === "follow-within-root") {
|
|
28980
|
+
const pathStat = await promises_.stat(filePath);
|
|
28981
|
+
if (!file_identity_sameFileIdentity(stat, pathStat)) {
|
|
28982
|
+
throw new errors_FsSafeError("path-mismatch", "path changed during read");
|
|
28983
|
+
}
|
|
28984
|
+
}
|
|
28985
|
+
else {
|
|
28986
|
+
const pathStat = await promises_.lstat(filePath);
|
|
28987
|
+
if (pathStat.isSymbolicLink()) {
|
|
28988
|
+
throw new errors_FsSafeError("symlink", "symlink not allowed");
|
|
28989
|
+
}
|
|
28990
|
+
if (!file_identity_sameFileIdentity(stat, pathStat)) {
|
|
28991
|
+
throw new errors_FsSafeError("path-mismatch", "path changed during read");
|
|
28992
|
+
}
|
|
28993
|
+
}
|
|
28994
|
+
const realPath = await resolveOpenedFileRealPathForHandle(handle, filePath);
|
|
28995
|
+
const realStat = await promises_.stat(realPath);
|
|
28996
|
+
if (options?.hardlinks === "reject" && realStat.nlink > 1) {
|
|
28997
|
+
throw new errors_FsSafeError("hardlink", "hardlinked path not allowed");
|
|
28998
|
+
}
|
|
28999
|
+
if (!file_identity_sameFileIdentity(stat, realStat)) {
|
|
29000
|
+
throw new errors_FsSafeError("path-mismatch", "path mismatch");
|
|
29001
|
+
}
|
|
29002
|
+
return openResult({ handle, realPath, stat });
|
|
29003
|
+
}
|
|
29004
|
+
catch (err) {
|
|
29005
|
+
await handle.close().catch(() => { });
|
|
29006
|
+
if (err instanceof errors_FsSafeError) {
|
|
29007
|
+
throw err;
|
|
29008
|
+
}
|
|
29009
|
+
if (path_isNotFoundPathError(err)) {
|
|
29010
|
+
throw new errors_FsSafeError("not-found", "file not found");
|
|
29011
|
+
}
|
|
29012
|
+
throw err;
|
|
29013
|
+
}
|
|
29014
|
+
}
|
|
29015
|
+
class RootHandle {
|
|
29016
|
+
rootDir;
|
|
29017
|
+
rootReal;
|
|
29018
|
+
rootWithSep;
|
|
29019
|
+
defaults;
|
|
29020
|
+
constructor(context, defaults = {}) {
|
|
29021
|
+
this.rootDir = context.rootDir;
|
|
29022
|
+
this.rootReal = context.rootReal;
|
|
29023
|
+
this.rootWithSep = context.rootWithSep;
|
|
29024
|
+
this.defaults = defaults;
|
|
29025
|
+
}
|
|
29026
|
+
get context() {
|
|
29027
|
+
return {
|
|
29028
|
+
rootDir: this.rootDir,
|
|
29029
|
+
rootReal: this.rootReal,
|
|
29030
|
+
rootWithSep: this.rootWithSep,
|
|
29031
|
+
};
|
|
29032
|
+
}
|
|
29033
|
+
async resolve(relativePath) {
|
|
29034
|
+
return (await resolvePathInRoot(this.context, relativePath)).resolved;
|
|
29035
|
+
}
|
|
29036
|
+
async open(relativePath, options = {}) {
|
|
29037
|
+
return await openFileInRoot(this.context, {
|
|
29038
|
+
relativePath,
|
|
29039
|
+
...readDefaults(this.defaults),
|
|
29040
|
+
...options,
|
|
29041
|
+
});
|
|
29042
|
+
}
|
|
29043
|
+
async read(relativePath, options = {}) {
|
|
29044
|
+
return await readFileInRoot(this.context, {
|
|
29045
|
+
relativePath,
|
|
29046
|
+
...readDefaults(this.defaults),
|
|
29047
|
+
...options,
|
|
29048
|
+
});
|
|
29049
|
+
}
|
|
29050
|
+
async readBytes(relativePath, options = {}) {
|
|
29051
|
+
return (await this.read(relativePath, options)).buffer;
|
|
29052
|
+
}
|
|
29053
|
+
async readText(relativePath, options = {}) {
|
|
29054
|
+
const { encoding = "utf8", ...readOptions } = options;
|
|
29055
|
+
return (await this.read(relativePath, readOptions)).buffer.toString(encoding);
|
|
29056
|
+
}
|
|
29057
|
+
async readJson(relativePath, options = {}) {
|
|
29058
|
+
return JSON.parse(await this.readText(relativePath, options));
|
|
29059
|
+
}
|
|
29060
|
+
async readAbsolute(filePath, options = {}) {
|
|
29061
|
+
return await readPathInRoot(this.context, {
|
|
29062
|
+
filePath,
|
|
29063
|
+
...readDefaults(this.defaults),
|
|
29064
|
+
...options,
|
|
29065
|
+
});
|
|
29066
|
+
}
|
|
29067
|
+
reader(options = {}) {
|
|
29068
|
+
return async (filePath) => {
|
|
29069
|
+
return (await this.readAbsolute(filePath, options)).buffer;
|
|
29070
|
+
};
|
|
29071
|
+
}
|
|
29072
|
+
async openWritable(relativePath, options = {}) {
|
|
29073
|
+
const writeMode = options.writeMode ?? "replace";
|
|
29074
|
+
return await openWritableFileInRoot(this.context, {
|
|
29075
|
+
relativePath,
|
|
29076
|
+
mkdir: this.defaults.mkdir,
|
|
29077
|
+
mode: this.defaults.mode,
|
|
29078
|
+
...options,
|
|
29079
|
+
append: writeMode === "append",
|
|
29080
|
+
truncateExisting: writeMode === "replace",
|
|
29081
|
+
});
|
|
29082
|
+
}
|
|
29083
|
+
async append(relativePath, data, options = {}) {
|
|
29084
|
+
await appendFileInRoot(this.context, {
|
|
29085
|
+
relativePath,
|
|
29086
|
+
data,
|
|
29087
|
+
mkdir: this.defaults.mkdir,
|
|
29088
|
+
mode: this.defaults.mode,
|
|
29089
|
+
...options,
|
|
29090
|
+
});
|
|
29091
|
+
}
|
|
29092
|
+
async remove(relativePath) {
|
|
29093
|
+
assertValidRootRelativePath(relativePath);
|
|
29094
|
+
await removePathInRoot(this.context, relativePath);
|
|
29095
|
+
}
|
|
29096
|
+
async mkdir(relativePath) {
|
|
29097
|
+
assertValidRootRelativePath(relativePath);
|
|
29098
|
+
await mkdirPathInRoot(this.context, { relativePath });
|
|
29099
|
+
}
|
|
29100
|
+
async ensureRoot() {
|
|
29101
|
+
await mkdirPathInRoot(this.context, { relativePath: "", allowRoot: true });
|
|
29102
|
+
}
|
|
29103
|
+
async write(relativePath, data, options = {}) {
|
|
29104
|
+
await writeFileInRoot(this.context, {
|
|
29105
|
+
relativePath,
|
|
29106
|
+
data,
|
|
29107
|
+
mkdir: this.defaults.mkdir,
|
|
29108
|
+
mode: this.defaults.mode,
|
|
29109
|
+
...options,
|
|
29110
|
+
});
|
|
29111
|
+
}
|
|
29112
|
+
async create(relativePath, data, options = {}) {
|
|
29113
|
+
await writeFileInRoot(this.context, {
|
|
29114
|
+
relativePath,
|
|
29115
|
+
data,
|
|
29116
|
+
mkdir: this.defaults.mkdir,
|
|
29117
|
+
mode: this.defaults.mode,
|
|
29118
|
+
...options,
|
|
29119
|
+
overwrite: false,
|
|
29120
|
+
});
|
|
29121
|
+
}
|
|
29122
|
+
async writeJson(relativePath, data, options = {}) {
|
|
29123
|
+
const { replacer, space, trailingNewline = true, ...writeOptions } = options;
|
|
29124
|
+
const json = JSON.stringify(data, replacer, space);
|
|
29125
|
+
await this.write(relativePath, trailingNewline ? `${json}\n` : json, writeOptions);
|
|
29126
|
+
}
|
|
29127
|
+
async createJson(relativePath, data, options = {}) {
|
|
29128
|
+
const { replacer, space, trailingNewline = true, ...writeOptions } = options;
|
|
29129
|
+
const json = JSON.stringify(data, replacer, space);
|
|
29130
|
+
await this.create(relativePath, trailingNewline ? `${json}\n` : json, writeOptions);
|
|
29131
|
+
}
|
|
29132
|
+
async copyIn(relativePath, sourcePath, options = {}) {
|
|
29133
|
+
assertValidRootRelativePath(relativePath);
|
|
29134
|
+
await copyFileInRoot(this.context, {
|
|
29135
|
+
sourcePath,
|
|
29136
|
+
relativePath,
|
|
29137
|
+
maxBytes: this.defaults.maxBytes,
|
|
29138
|
+
mkdir: this.defaults.mkdir,
|
|
29139
|
+
mode: this.defaults.mode,
|
|
29140
|
+
...options,
|
|
29141
|
+
});
|
|
29142
|
+
}
|
|
29143
|
+
async exists(relativePath) {
|
|
29144
|
+
try {
|
|
29145
|
+
await this.stat(relativePath);
|
|
29146
|
+
return true;
|
|
29147
|
+
}
|
|
29148
|
+
catch (err) {
|
|
29149
|
+
if (err instanceof errors_FsSafeError && err.code === "not-found") {
|
|
29150
|
+
return false;
|
|
26515
29151
|
}
|
|
29152
|
+
throw err;
|
|
29153
|
+
}
|
|
29154
|
+
}
|
|
29155
|
+
async stat(relativePath) {
|
|
29156
|
+
assertValidRootRelativePath(relativePath);
|
|
29157
|
+
try {
|
|
29158
|
+
return await helperStat(this.rootReal, relativePath);
|
|
29159
|
+
}
|
|
29160
|
+
catch (error) {
|
|
29161
|
+
if (canFallbackFromPythonError(error)) {
|
|
29162
|
+
return await statPathFallback(this.context, relativePath);
|
|
29163
|
+
}
|
|
29164
|
+
throw error;
|
|
29165
|
+
}
|
|
29166
|
+
}
|
|
29167
|
+
async list(relativePath, options = {}) {
|
|
29168
|
+
assertValidRootRelativePath(relativePath);
|
|
29169
|
+
try {
|
|
29170
|
+
return options.withFileTypes === true
|
|
29171
|
+
? await helperReaddir(this.rootReal, relativePath, true)
|
|
29172
|
+
: await helperReaddir(this.rootReal, relativePath, false);
|
|
29173
|
+
}
|
|
29174
|
+
catch (error) {
|
|
29175
|
+
if (canFallbackFromPythonError(error)) {
|
|
29176
|
+
return await listPathFallback(this.context, relativePath, options.withFileTypes === true);
|
|
29177
|
+
}
|
|
29178
|
+
throw error;
|
|
29179
|
+
}
|
|
29180
|
+
}
|
|
29181
|
+
async move(fromRelative, toRelative, options = {}) {
|
|
29182
|
+
assertValidRootRelativePath(fromRelative);
|
|
29183
|
+
assertValidRootRelativePath(toRelative);
|
|
29184
|
+
try {
|
|
29185
|
+
await runPinnedHelper("rename", this.rootReal, {
|
|
29186
|
+
from: fromRelative,
|
|
29187
|
+
overwrite: options.overwrite ?? false,
|
|
29188
|
+
to: toRelative,
|
|
29189
|
+
});
|
|
29190
|
+
}
|
|
29191
|
+
catch (error) {
|
|
29192
|
+
if (canFallbackFromPythonError(error)) {
|
|
29193
|
+
await movePathFallback(this.context, {
|
|
29194
|
+
fromRelative,
|
|
29195
|
+
overwrite: options.overwrite ?? false,
|
|
29196
|
+
toRelative,
|
|
29197
|
+
});
|
|
29198
|
+
return;
|
|
29199
|
+
}
|
|
29200
|
+
throw error;
|
|
26516
29201
|
}
|
|
26517
|
-
return result;
|
|
26518
29202
|
}
|
|
26519
29203
|
}
|
|
26520
|
-
|
|
26521
|
-
|
|
26522
|
-
|
|
26523
|
-
|
|
29204
|
+
function readDefaults(defaults) {
|
|
29205
|
+
return {
|
|
29206
|
+
hardlinks: defaults.hardlinks,
|
|
29207
|
+
maxBytes: defaults.maxBytes ?? DEFAULT_ROOT_MAX_BYTES,
|
|
29208
|
+
nonBlockingRead: defaults.nonBlockingRead,
|
|
29209
|
+
symlinks: defaults.symlinks,
|
|
29210
|
+
};
|
|
29211
|
+
}
|
|
29212
|
+
async function root_impl_root(rootDir, defaults = {}) {
|
|
29213
|
+
return new RootHandle(await resolveRootContext(rootDir), defaults);
|
|
29214
|
+
}
|
|
29215
|
+
async function openFileInRoot(root, params) {
|
|
29216
|
+
const { rootWithSep, resolved } = await resolvePathInRoot(root, params.relativePath);
|
|
29217
|
+
let opened;
|
|
29218
|
+
try {
|
|
29219
|
+
opened = await openVerifiedLocalFile(resolved, {
|
|
29220
|
+
nonBlockingRead: params.nonBlockingRead,
|
|
29221
|
+
symlinks: params.symlinks,
|
|
29222
|
+
});
|
|
29223
|
+
}
|
|
29224
|
+
catch (err) {
|
|
29225
|
+
if (err instanceof errors_FsSafeError) {
|
|
29226
|
+
throw err;
|
|
29227
|
+
}
|
|
29228
|
+
throw err;
|
|
29229
|
+
}
|
|
29230
|
+
if (params.hardlinks !== "allow" && opened.stat.nlink > 1) {
|
|
29231
|
+
await opened.handle.close().catch(() => { });
|
|
29232
|
+
throw new errors_FsSafeError("hardlink", "hardlinked path not allowed");
|
|
29233
|
+
}
|
|
29234
|
+
if (!path_isPathInside(rootWithSep, opened.realPath)) {
|
|
29235
|
+
await opened.handle.close().catch(() => { });
|
|
29236
|
+
throw new errors_FsSafeError("outside-workspace", "file is outside workspace root");
|
|
29237
|
+
}
|
|
29238
|
+
return opened;
|
|
29239
|
+
}
|
|
29240
|
+
async function readFileInRoot(root, params) {
|
|
29241
|
+
const opened = await openFileInRoot(root, params);
|
|
29242
|
+
try {
|
|
29243
|
+
return await readOpenedFileSafely({ opened, maxBytes: params.maxBytes });
|
|
29244
|
+
}
|
|
29245
|
+
finally {
|
|
29246
|
+
await opened.handle.close().catch(() => { });
|
|
29247
|
+
}
|
|
29248
|
+
}
|
|
29249
|
+
async function readPathInRoot(root, params) {
|
|
29250
|
+
const rootDir = root.rootDir;
|
|
29251
|
+
const candidatePath = external_node_path_.isAbsolute(params.filePath)
|
|
29252
|
+
? external_node_path_.resolve(params.filePath)
|
|
29253
|
+
: external_node_path_.resolve(rootDir, params.filePath);
|
|
29254
|
+
const relativePath = external_node_path_.relative(rootDir, candidatePath);
|
|
29255
|
+
return await readFileInRoot(root, {
|
|
29256
|
+
relativePath,
|
|
29257
|
+
hardlinks: params.hardlinks,
|
|
29258
|
+
maxBytes: params.maxBytes,
|
|
29259
|
+
nonBlockingRead: params.nonBlockingRead,
|
|
29260
|
+
symlinks: params.symlinks,
|
|
29261
|
+
});
|
|
29262
|
+
}
|
|
29263
|
+
async function readLocalFileSafely(params) {
|
|
29264
|
+
const opened = await openLocalFileSafely({ filePath: params.filePath });
|
|
29265
|
+
try {
|
|
29266
|
+
return await readOpenedFileSafely({ opened, maxBytes: params.maxBytes });
|
|
29267
|
+
}
|
|
29268
|
+
finally {
|
|
29269
|
+
await opened.handle.close().catch(() => { });
|
|
29270
|
+
}
|
|
29271
|
+
}
|
|
29272
|
+
async function openLocalFileSafely(params) {
|
|
29273
|
+
assertNoNulPathInput(params.filePath, "file path contains a NUL byte");
|
|
29274
|
+
return await openVerifiedLocalFile(params.filePath);
|
|
29275
|
+
}
|
|
29276
|
+
async function readOpenedFileSafely(params) {
|
|
29277
|
+
if (params.maxBytes !== undefined && params.opened.stat.size > params.maxBytes) {
|
|
29278
|
+
throw new errors_FsSafeError("too-large", `file exceeds limit of ${params.maxBytes} bytes (got ${params.opened.stat.size})`);
|
|
29279
|
+
}
|
|
29280
|
+
const buffer = await params.opened.handle.readFile();
|
|
29281
|
+
if (params.maxBytes !== undefined && buffer.byteLength > params.maxBytes) {
|
|
29282
|
+
throw new errors_FsSafeError("too-large", `file exceeds limit of ${params.maxBytes} bytes (got ${buffer.byteLength})`);
|
|
29283
|
+
}
|
|
29284
|
+
return {
|
|
29285
|
+
buffer,
|
|
29286
|
+
realPath: params.opened.realPath,
|
|
29287
|
+
stat: params.opened.stat,
|
|
29288
|
+
};
|
|
29289
|
+
}
|
|
29290
|
+
function emitWriteBoundaryWarning(reason) {
|
|
29291
|
+
logWarn(`security: fs-safe write boundary warning (${reason})`);
|
|
29292
|
+
}
|
|
29293
|
+
function buildAtomicWriteTempPath(targetPath) {
|
|
29294
|
+
const dir = external_node_path_.dirname(targetPath);
|
|
29295
|
+
const base = external_node_path_.basename(targetPath);
|
|
29296
|
+
return external_node_path_.join(dir, `.${base}.${process.pid}.${(0,external_node_crypto_.randomUUID)()}.tmp`);
|
|
29297
|
+
}
|
|
29298
|
+
function rootWriteQueueKey(root, relativePath) {
|
|
29299
|
+
return `${root.rootReal}\0${relativePath}`;
|
|
29300
|
+
}
|
|
29301
|
+
async function writeTempFileForAtomicReplace(params) {
|
|
29302
|
+
const tempHandle = await promises_.open(params.tempPath, OPEN_WRITE_CREATE_FLAGS, params.mode);
|
|
29303
|
+
try {
|
|
29304
|
+
if (typeof params.data === "string") {
|
|
29305
|
+
await tempHandle.writeFile(params.data, params.encoding ?? "utf8");
|
|
29306
|
+
}
|
|
29307
|
+
else {
|
|
29308
|
+
await tempHandle.writeFile(params.data);
|
|
29309
|
+
}
|
|
29310
|
+
return await tempHandle.stat();
|
|
29311
|
+
}
|
|
29312
|
+
finally {
|
|
29313
|
+
await tempHandle.close().catch(() => { });
|
|
29314
|
+
}
|
|
29315
|
+
}
|
|
29316
|
+
async function verifyAtomicWriteResult(params) {
|
|
29317
|
+
const opened = await openVerifiedLocalFile(params.targetPath, { hardlinks: "reject" });
|
|
29318
|
+
try {
|
|
29319
|
+
if (!file_identity_sameFileIdentity(opened.stat, params.expectedIdentity)) {
|
|
29320
|
+
throw new errors_FsSafeError("path-mismatch", "path changed during write");
|
|
29321
|
+
}
|
|
29322
|
+
if (!path_isPathInside(params.root.rootWithSep, opened.realPath)) {
|
|
29323
|
+
throw new errors_FsSafeError("outside-workspace", "file is outside workspace root");
|
|
29324
|
+
}
|
|
29325
|
+
}
|
|
29326
|
+
finally {
|
|
29327
|
+
await opened.handle.close().catch(() => { });
|
|
29328
|
+
}
|
|
29329
|
+
}
|
|
29330
|
+
async function resolveOpenedFileRealPathForHandle(handle, ioPath) {
|
|
29331
|
+
const handleStat = await handle.stat();
|
|
29332
|
+
const fdCandidates = process.platform === "linux"
|
|
29333
|
+
? [`/proc/self/fd/${handle.fd}`, `/dev/fd/${handle.fd}`]
|
|
29334
|
+
: process.platform === "win32"
|
|
29335
|
+
? []
|
|
29336
|
+
: [`/dev/fd/${handle.fd}`];
|
|
29337
|
+
for (const fdPath of fdCandidates) {
|
|
29338
|
+
try {
|
|
29339
|
+
const fdRealPath = await promises_.realpath(fdPath);
|
|
29340
|
+
const fdRealStat = await promises_.stat(fdRealPath);
|
|
29341
|
+
if (file_identity_sameFileIdentity(handleStat, fdRealStat)) {
|
|
29342
|
+
return fdRealPath;
|
|
29343
|
+
}
|
|
29344
|
+
}
|
|
29345
|
+
catch {
|
|
29346
|
+
// try next fd path
|
|
29347
|
+
}
|
|
29348
|
+
}
|
|
29349
|
+
try {
|
|
29350
|
+
const ioRealPath = await promises_.realpath(ioPath);
|
|
29351
|
+
const ioRealStat = await promises_.stat(ioRealPath);
|
|
29352
|
+
if (file_identity_sameFileIdentity(handleStat, ioRealStat)) {
|
|
29353
|
+
return ioRealPath;
|
|
29354
|
+
}
|
|
29355
|
+
}
|
|
29356
|
+
catch (err) {
|
|
29357
|
+
if (!path_isNotFoundPathError(err)) {
|
|
29358
|
+
throw err;
|
|
29359
|
+
}
|
|
29360
|
+
}
|
|
29361
|
+
const parentResolved = await resolveOpenedFileRealPathFromParent(handleStat, ioPath);
|
|
29362
|
+
if (parentResolved) {
|
|
29363
|
+
return parentResolved;
|
|
29364
|
+
}
|
|
29365
|
+
throw new errors_FsSafeError("path-mismatch", "unable to resolve opened file path");
|
|
29366
|
+
}
|
|
29367
|
+
async function resolveOpenedFileRealPathFromParent(handleStat, ioPath) {
|
|
29368
|
+
let parentReal;
|
|
29369
|
+
try {
|
|
29370
|
+
parentReal = await promises_.realpath(external_node_path_.dirname(ioPath));
|
|
29371
|
+
}
|
|
29372
|
+
catch (err) {
|
|
29373
|
+
if (path_isNotFoundPathError(err)) {
|
|
29374
|
+
return null;
|
|
29375
|
+
}
|
|
29376
|
+
throw err;
|
|
29377
|
+
}
|
|
29378
|
+
let entries;
|
|
29379
|
+
try {
|
|
29380
|
+
entries = await promises_.readdir(parentReal);
|
|
29381
|
+
}
|
|
29382
|
+
catch (err) {
|
|
29383
|
+
if (path_isNotFoundPathError(err)) {
|
|
29384
|
+
return null;
|
|
29385
|
+
}
|
|
29386
|
+
throw err;
|
|
29387
|
+
}
|
|
29388
|
+
for (const entry of entries.toSorted()) {
|
|
29389
|
+
const candidatePath = external_node_path_.join(parentReal, entry);
|
|
29390
|
+
try {
|
|
29391
|
+
const candidateStat = await promises_.lstat(candidatePath);
|
|
29392
|
+
if (candidateStat.isFile() && file_identity_sameFileIdentity(handleStat, candidateStat)) {
|
|
29393
|
+
return await promises_.realpath(candidatePath);
|
|
29394
|
+
}
|
|
29395
|
+
}
|
|
29396
|
+
catch (err) {
|
|
29397
|
+
if (!path_isNotFoundPathError(err)) {
|
|
29398
|
+
throw err;
|
|
29399
|
+
}
|
|
29400
|
+
}
|
|
29401
|
+
}
|
|
29402
|
+
return null;
|
|
29403
|
+
}
|
|
29404
|
+
async function openWritableFileInRoot(root, params) {
|
|
29405
|
+
const { rootReal, rootWithSep, resolved } = await resolvePathInRoot(root, params.relativePath);
|
|
29406
|
+
try {
|
|
29407
|
+
await assertNoPathAliasEscape({
|
|
29408
|
+
absolutePath: resolved,
|
|
29409
|
+
rootPath: rootReal,
|
|
29410
|
+
boundaryLabel: "root",
|
|
29411
|
+
});
|
|
29412
|
+
}
|
|
29413
|
+
catch (err) {
|
|
29414
|
+
throw new errors_FsSafeError("path-alias", "path alias escape blocked", { cause: err });
|
|
29415
|
+
}
|
|
29416
|
+
if (params.mkdir !== false) {
|
|
29417
|
+
const parentGuard = await directory_guard_createNearestExistingDirectoryGuard(rootReal, external_node_path_.dirname(resolved));
|
|
29418
|
+
await withAsyncDirectoryGuards([parentGuard], async () => {
|
|
29419
|
+
await promises_.mkdir(external_node_path_.dirname(resolved), { recursive: true });
|
|
29420
|
+
});
|
|
29421
|
+
}
|
|
29422
|
+
let ioPath = resolved;
|
|
29423
|
+
try {
|
|
29424
|
+
const resolvedRealPath = await promises_.realpath(resolved);
|
|
29425
|
+
if (!path_isPathInside(rootWithSep, resolvedRealPath)) {
|
|
29426
|
+
throw new errors_FsSafeError("outside-workspace", "file is outside workspace root");
|
|
29427
|
+
}
|
|
29428
|
+
ioPath = resolvedRealPath;
|
|
29429
|
+
}
|
|
29430
|
+
catch (err) {
|
|
29431
|
+
if (err instanceof errors_FsSafeError) {
|
|
29432
|
+
throw err;
|
|
29433
|
+
}
|
|
29434
|
+
if (!path_isNotFoundPathError(err)) {
|
|
29435
|
+
throw err;
|
|
29436
|
+
}
|
|
29437
|
+
}
|
|
29438
|
+
const mode = params.mode ?? 0o600;
|
|
29439
|
+
let handle;
|
|
29440
|
+
let createdForWrite = false;
|
|
29441
|
+
const existingFlags = params.append ? OPEN_APPEND_EXISTING_FLAGS : OPEN_WRITE_EXISTING_FLAGS;
|
|
29442
|
+
const createFlags = params.append ? OPEN_APPEND_CREATE_FLAGS : OPEN_WRITE_CREATE_FLAGS;
|
|
29443
|
+
try {
|
|
29444
|
+
try {
|
|
29445
|
+
handle = await promises_.open(ioPath, existingFlags, mode);
|
|
29446
|
+
}
|
|
29447
|
+
catch (err) {
|
|
29448
|
+
if (!path_isNotFoundPathError(err)) {
|
|
29449
|
+
throw err;
|
|
29450
|
+
}
|
|
29451
|
+
handle = await promises_.open(ioPath, createFlags, mode);
|
|
29452
|
+
createdForWrite = true;
|
|
29453
|
+
}
|
|
29454
|
+
}
|
|
29455
|
+
catch (err) {
|
|
29456
|
+
if (path_isNotFoundPathError(err)) {
|
|
29457
|
+
throw new errors_FsSafeError("not-found", "file not found");
|
|
29458
|
+
}
|
|
29459
|
+
if (isSymlinkOpenError(err)) {
|
|
29460
|
+
throw new errors_FsSafeError("symlink", "symlink open blocked", { cause: err });
|
|
29461
|
+
}
|
|
29462
|
+
if (hasNodeErrorCode(err, "EISDIR")) {
|
|
29463
|
+
throw new errors_FsSafeError("not-file", "not a file", { cause: err });
|
|
29464
|
+
}
|
|
29465
|
+
throw err;
|
|
29466
|
+
}
|
|
29467
|
+
let realPathForCleanup = null;
|
|
29468
|
+
try {
|
|
29469
|
+
const stat = await handle.stat();
|
|
29470
|
+
if (!stat.isFile()) {
|
|
29471
|
+
throw new errors_FsSafeError("invalid-path", "path is not a regular file under root");
|
|
29472
|
+
}
|
|
29473
|
+
if (stat.nlink > 1) {
|
|
29474
|
+
throw new errors_FsSafeError("hardlink", "hardlinked path not allowed");
|
|
29475
|
+
}
|
|
29476
|
+
try {
|
|
29477
|
+
const lstat = await promises_.lstat(ioPath);
|
|
29478
|
+
if (lstat.isSymbolicLink() || !lstat.isFile()) {
|
|
29479
|
+
throw new errors_FsSafeError(lstat.isSymbolicLink() ? "symlink" : "not-file", "path is not a regular file under root");
|
|
29480
|
+
}
|
|
29481
|
+
if (!file_identity_sameFileIdentity(stat, lstat)) {
|
|
29482
|
+
throw new errors_FsSafeError("path-mismatch", "path changed during write");
|
|
29483
|
+
}
|
|
29484
|
+
}
|
|
29485
|
+
catch (err) {
|
|
29486
|
+
if (!path_isNotFoundPathError(err)) {
|
|
29487
|
+
throw err;
|
|
29488
|
+
}
|
|
29489
|
+
}
|
|
29490
|
+
const realPath = await resolveOpenedFileRealPathForHandle(handle, ioPath);
|
|
29491
|
+
realPathForCleanup = realPath;
|
|
29492
|
+
const realStat = await promises_.stat(realPath);
|
|
29493
|
+
if (!file_identity_sameFileIdentity(stat, realStat)) {
|
|
29494
|
+
throw new errors_FsSafeError("path-mismatch", "path mismatch");
|
|
29495
|
+
}
|
|
29496
|
+
if (realStat.nlink > 1) {
|
|
29497
|
+
throw new errors_FsSafeError("hardlink", "hardlinked path not allowed");
|
|
29498
|
+
}
|
|
29499
|
+
if (!path_isPathInside(rootWithSep, realPath)) {
|
|
29500
|
+
throw new errors_FsSafeError("outside-workspace", "file is outside workspace root");
|
|
29501
|
+
}
|
|
29502
|
+
// Truncate only after boundary and identity checks complete. This avoids
|
|
29503
|
+
// irreversible side effects if a symlink target changes before validation.
|
|
29504
|
+
if (params.append !== true && params.truncateExisting !== false && !createdForWrite) {
|
|
29505
|
+
await handle.truncate(0);
|
|
29506
|
+
}
|
|
29507
|
+
return {
|
|
29508
|
+
handle,
|
|
29509
|
+
createdForWrite,
|
|
29510
|
+
realPath,
|
|
29511
|
+
stat,
|
|
29512
|
+
[Symbol.asyncDispose]: async () => {
|
|
29513
|
+
await closeHandleForDispose(handle);
|
|
29514
|
+
},
|
|
29515
|
+
};
|
|
29516
|
+
}
|
|
29517
|
+
catch (err) {
|
|
29518
|
+
const cleanupCreatedPath = createdForWrite && err instanceof errors_FsSafeError;
|
|
29519
|
+
const cleanupPath = realPathForCleanup ?? ioPath;
|
|
29520
|
+
await handle.close().catch(() => { });
|
|
29521
|
+
if (cleanupCreatedPath) {
|
|
29522
|
+
await promises_.rm(cleanupPath, { force: true }).catch(() => { });
|
|
29523
|
+
}
|
|
29524
|
+
throw err;
|
|
29525
|
+
}
|
|
29526
|
+
}
|
|
29527
|
+
async function appendFileInRoot(root, params) {
|
|
29528
|
+
const target = await openWritableFileInRoot(root, {
|
|
29529
|
+
relativePath: params.relativePath,
|
|
29530
|
+
mkdir: params.mkdir,
|
|
29531
|
+
mode: params.mode,
|
|
29532
|
+
truncateExisting: false,
|
|
29533
|
+
append: true,
|
|
29534
|
+
});
|
|
29535
|
+
try {
|
|
29536
|
+
let prefix = "";
|
|
29537
|
+
if (params.prependNewlineIfNeeded === true &&
|
|
29538
|
+
!target.createdForWrite &&
|
|
29539
|
+
target.stat.size > 0 &&
|
|
29540
|
+
((typeof params.data === "string" && !params.data.startsWith("\n")) ||
|
|
29541
|
+
(Buffer.isBuffer(params.data) && params.data.length > 0 && params.data[0] !== 0x0a))) {
|
|
29542
|
+
const lastByte = Buffer.alloc(1);
|
|
29543
|
+
const { bytesRead } = await target.handle.read(lastByte, 0, 1, target.stat.size - 1);
|
|
29544
|
+
if (bytesRead === 1 && lastByte[0] !== 0x0a) {
|
|
29545
|
+
prefix = "\n";
|
|
29546
|
+
}
|
|
29547
|
+
}
|
|
29548
|
+
if (typeof params.data === "string") {
|
|
29549
|
+
await target.handle.appendFile(`${prefix}${params.data}`, params.encoding ?? "utf8");
|
|
29550
|
+
return;
|
|
29551
|
+
}
|
|
29552
|
+
const payload = prefix.length > 0 ? Buffer.concat([Buffer.from(prefix, "utf8"), params.data]) : params.data;
|
|
29553
|
+
await target.handle.appendFile(payload);
|
|
29554
|
+
}
|
|
29555
|
+
finally {
|
|
29556
|
+
await target.handle.close().catch(() => { });
|
|
29557
|
+
}
|
|
29558
|
+
}
|
|
29559
|
+
async function removePathInRoot(root, relativePath) {
|
|
29560
|
+
const resolved = await resolvePinnedRemovePathInRoot(root, relativePath);
|
|
29561
|
+
if (process.platform === "win32") {
|
|
29562
|
+
await removePathFallback(resolved);
|
|
29563
|
+
return;
|
|
29564
|
+
}
|
|
29565
|
+
try {
|
|
29566
|
+
await runPinnedPathHelper({
|
|
29567
|
+
operation: "remove",
|
|
29568
|
+
rootPath: resolved.rootReal,
|
|
29569
|
+
relativePath: resolved.relativePosix,
|
|
29570
|
+
});
|
|
29571
|
+
}
|
|
29572
|
+
catch (error) {
|
|
29573
|
+
if (isPinnedPathHelperSpawnError(error)) {
|
|
29574
|
+
await removePathFallback(resolved);
|
|
29575
|
+
return;
|
|
29576
|
+
}
|
|
29577
|
+
throw normalizePinnedPathError(error);
|
|
29578
|
+
}
|
|
29579
|
+
}
|
|
29580
|
+
async function mkdirPathInRoot(root, params) {
|
|
29581
|
+
const resolved = await resolvePinnedPathInRoot(root, params);
|
|
29582
|
+
if (process.platform === "win32") {
|
|
29583
|
+
await mkdirPathFallback(resolved);
|
|
29584
|
+
return;
|
|
29585
|
+
}
|
|
29586
|
+
try {
|
|
29587
|
+
await runPinnedPathHelper({
|
|
29588
|
+
operation: "mkdirp",
|
|
29589
|
+
rootPath: resolved.rootReal,
|
|
29590
|
+
relativePath: resolved.relativePosix,
|
|
29591
|
+
});
|
|
29592
|
+
}
|
|
29593
|
+
catch (error) {
|
|
29594
|
+
if (isPinnedPathHelperSpawnError(error)) {
|
|
29595
|
+
await mkdirPathFallback(resolved);
|
|
29596
|
+
return;
|
|
29597
|
+
}
|
|
29598
|
+
throw normalizePinnedPathError(error);
|
|
29599
|
+
}
|
|
29600
|
+
}
|
|
29601
|
+
async function writeFileInRoot(root, params) {
|
|
29602
|
+
if (process.platform === "win32") {
|
|
29603
|
+
await serializePathWrite(rootWriteQueueKey(root, params.relativePath), async () => {
|
|
29604
|
+
await writeFileFallback(root, params);
|
|
29605
|
+
});
|
|
29606
|
+
return;
|
|
29607
|
+
}
|
|
29608
|
+
const pinned = await resolvePinnedWriteTargetInRoot(root, params.relativePath, params.mode);
|
|
29609
|
+
await serializePathWrite(pinned.targetPath, async () => {
|
|
29610
|
+
let identity;
|
|
29611
|
+
try {
|
|
29612
|
+
identity = await runPinnedWriteHelper({
|
|
29613
|
+
rootPath: pinned.rootReal,
|
|
29614
|
+
relativeParentPath: pinned.relativeParentPath,
|
|
29615
|
+
basename: pinned.basename,
|
|
29616
|
+
mkdir: params.mkdir !== false,
|
|
29617
|
+
mode: params.mode ?? pinned.mode,
|
|
29618
|
+
overwrite: params.overwrite,
|
|
29619
|
+
input: {
|
|
29620
|
+
kind: "buffer",
|
|
29621
|
+
data: params.data,
|
|
29622
|
+
encoding: params.encoding,
|
|
29623
|
+
},
|
|
29624
|
+
});
|
|
29625
|
+
}
|
|
29626
|
+
catch (error) {
|
|
29627
|
+
if (params.overwrite === false && isAlreadyExistsError(error)) {
|
|
29628
|
+
throw new errors_FsSafeError("already-exists", "file already exists", {
|
|
29629
|
+
cause: error instanceof Error ? error : undefined,
|
|
29630
|
+
});
|
|
29631
|
+
}
|
|
29632
|
+
throw normalizePinnedWriteError(error);
|
|
29633
|
+
}
|
|
29634
|
+
try {
|
|
29635
|
+
await verifyAtomicWriteResult({
|
|
29636
|
+
root,
|
|
29637
|
+
targetPath: pinned.targetPath,
|
|
29638
|
+
expectedIdentity: identity,
|
|
29639
|
+
});
|
|
29640
|
+
}
|
|
29641
|
+
catch (err) {
|
|
29642
|
+
emitWriteBoundaryWarning(`post-write verification failed: ${String(err)}`);
|
|
29643
|
+
throw err;
|
|
29644
|
+
}
|
|
29645
|
+
});
|
|
29646
|
+
}
|
|
29647
|
+
async function copyFileInRoot(root, params) {
|
|
29648
|
+
assertValidRootRelativePath(params.relativePath);
|
|
29649
|
+
path_assertNoNulPathInput(params.sourcePath, "source path contains a NUL byte");
|
|
29650
|
+
const source = await openVerifiedLocalFile(params.sourcePath, {
|
|
29651
|
+
hardlinks: params.sourceHardlinks,
|
|
29652
|
+
});
|
|
29653
|
+
if (params.maxBytes !== undefined && source.stat.size > params.maxBytes) {
|
|
29654
|
+
await source.handle.close().catch(() => { });
|
|
29655
|
+
throw new errors_FsSafeError("too-large", `file exceeds limit of ${params.maxBytes} bytes (got ${source.stat.size})`);
|
|
29656
|
+
}
|
|
29657
|
+
try {
|
|
29658
|
+
if (process.platform === "win32") {
|
|
29659
|
+
await serializePathWrite(rootWriteQueueKey(root, params.relativePath), async () => {
|
|
29660
|
+
await copyFileFallback(root, params, source);
|
|
29661
|
+
});
|
|
29662
|
+
return;
|
|
29663
|
+
}
|
|
29664
|
+
const pinned = await resolvePinnedWriteTargetInRoot(root, params.relativePath, params.mode);
|
|
29665
|
+
await serializePathWrite(pinned.targetPath, async () => {
|
|
29666
|
+
let identity;
|
|
29667
|
+
try {
|
|
29668
|
+
if (getFsSafePythonConfig().mode === "off") {
|
|
29669
|
+
await copyFileFallback(root, params, source);
|
|
29670
|
+
return;
|
|
29671
|
+
}
|
|
29672
|
+
identity = await runPinnedCopyHelper({
|
|
29673
|
+
rootPath: pinned.rootReal,
|
|
29674
|
+
relativeParentPath: pinned.relativeParentPath,
|
|
29675
|
+
basename: pinned.basename,
|
|
29676
|
+
mkdir: params.mkdir !== false,
|
|
29677
|
+
mode: pinned.mode,
|
|
29678
|
+
overwrite: true,
|
|
29679
|
+
maxBytes: params.maxBytes,
|
|
29680
|
+
sourcePath: source.realPath,
|
|
29681
|
+
sourceIdentity: { dev: source.stat.dev, ino: source.stat.ino },
|
|
29682
|
+
});
|
|
29683
|
+
}
|
|
29684
|
+
catch (error) {
|
|
29685
|
+
if (canFallbackFromPythonError(error)) {
|
|
29686
|
+
await copyFileFallback(root, params, source);
|
|
29687
|
+
return;
|
|
29688
|
+
}
|
|
29689
|
+
throw normalizePinnedWriteError(error);
|
|
29690
|
+
}
|
|
29691
|
+
try {
|
|
29692
|
+
await verifyAtomicWriteResult({
|
|
29693
|
+
root,
|
|
29694
|
+
targetPath: pinned.targetPath,
|
|
29695
|
+
expectedIdentity: identity,
|
|
29696
|
+
});
|
|
29697
|
+
}
|
|
29698
|
+
catch (err) {
|
|
29699
|
+
emitWriteBoundaryWarning(`post-copy verification failed: ${String(err)}`);
|
|
29700
|
+
throw err;
|
|
29701
|
+
}
|
|
29702
|
+
});
|
|
29703
|
+
}
|
|
29704
|
+
finally {
|
|
29705
|
+
await source.handle.close().catch(() => { });
|
|
29706
|
+
}
|
|
29707
|
+
}
|
|
29708
|
+
async function resolvePinnedWriteTargetInRoot(root, relativePath, requestedMode) {
|
|
29709
|
+
const { rootReal, rootWithSep, resolved } = await resolvePathInRoot(root, relativePath);
|
|
29710
|
+
try {
|
|
29711
|
+
await assertNoPathAliasEscape({
|
|
29712
|
+
absolutePath: resolved,
|
|
29713
|
+
rootPath: rootReal,
|
|
29714
|
+
boundaryLabel: "root",
|
|
29715
|
+
});
|
|
29716
|
+
}
|
|
29717
|
+
catch (err) {
|
|
29718
|
+
throw new errors_FsSafeError("path-alias", "path alias escape blocked", { cause: err });
|
|
29719
|
+
}
|
|
29720
|
+
// resolvePathInRoot already enforces isPathInside, so any actual escape
|
|
29721
|
+
// is rejected upstream.
|
|
29722
|
+
const relativeResolved = external_node_path_.relative(rootReal, resolved);
|
|
29723
|
+
if (external_node_path_.isAbsolute(relativeResolved)) {
|
|
29724
|
+
throw new errors_FsSafeError("outside-workspace", "file is outside workspace root");
|
|
29725
|
+
}
|
|
29726
|
+
const relativePosix = relativeResolved
|
|
29727
|
+
? relativeResolved.split(external_node_path_.sep).join(external_node_path_.posix.sep)
|
|
29728
|
+
: "";
|
|
29729
|
+
const basename = external_node_path_.posix.basename(relativePosix);
|
|
29730
|
+
if (!basename || basename === "." || basename === "/") {
|
|
29731
|
+
throw new errors_FsSafeError("invalid-path", "invalid target path");
|
|
29732
|
+
}
|
|
29733
|
+
let mode = requestedMode ?? 0o600;
|
|
29734
|
+
try {
|
|
29735
|
+
const opened = await openFileInRoot(root, {
|
|
29736
|
+
relativePath,
|
|
29737
|
+
hardlinks: "reject",
|
|
29738
|
+
nonBlockingRead: true,
|
|
29739
|
+
});
|
|
29740
|
+
try {
|
|
29741
|
+
mode = requestedMode ?? (opened.stat.mode & 0o777);
|
|
29742
|
+
if (!path_isPathInside(rootWithSep, opened.realPath)) {
|
|
29743
|
+
throw new errors_FsSafeError("outside-workspace", "file is outside workspace root");
|
|
29744
|
+
}
|
|
29745
|
+
}
|
|
29746
|
+
finally {
|
|
29747
|
+
await opened.handle.close().catch(() => { });
|
|
29748
|
+
}
|
|
29749
|
+
}
|
|
29750
|
+
catch (err) {
|
|
29751
|
+
if (!(err instanceof errors_FsSafeError) || err.code !== "not-found") {
|
|
29752
|
+
throw err;
|
|
29753
|
+
}
|
|
29754
|
+
}
|
|
29755
|
+
return {
|
|
29756
|
+
rootReal,
|
|
29757
|
+
targetPath: resolved,
|
|
29758
|
+
relativeParentPath: external_node_path_.posix.dirname(relativePosix) === "." ? "" : external_node_path_.posix.dirname(relativePosix),
|
|
29759
|
+
basename,
|
|
29760
|
+
mode: mode || 0o600,
|
|
29761
|
+
};
|
|
29762
|
+
}
|
|
29763
|
+
async function resolvePinnedPathInRoot(root, params) {
|
|
29764
|
+
return await resolvePinnedOperationPathInRoot(root, {
|
|
29765
|
+
allowRoot: params.allowRoot,
|
|
29766
|
+
relativePath: params.relativePath,
|
|
29767
|
+
policy: PATH_ALIAS_POLICIES.strict,
|
|
29768
|
+
});
|
|
29769
|
+
}
|
|
29770
|
+
async function resolvePinnedRemovePathInRoot(root, relativePath) {
|
|
29771
|
+
return await resolvePinnedOperationPathInRoot(root, {
|
|
29772
|
+
relativePath,
|
|
29773
|
+
policy: PATH_ALIAS_POLICIES.unlinkTarget,
|
|
29774
|
+
});
|
|
29775
|
+
}
|
|
29776
|
+
async function resolvePinnedOperationPathInRoot(root, params) {
|
|
29777
|
+
const resolved = await resolvePinnedRootPathInRoot(root, {
|
|
29778
|
+
relativePath: params.relativePath,
|
|
29779
|
+
policy: params.policy,
|
|
29780
|
+
});
|
|
29781
|
+
const relativeResolved = external_node_path_.relative(resolved.rootReal, resolved.canonicalPath);
|
|
29782
|
+
if ((relativeResolved === "" || relativeResolved === ".") && params.allowRoot === true) {
|
|
29783
|
+
return { rootReal: resolved.rootReal, resolved: resolved.canonicalPath, relativePosix: "" };
|
|
29784
|
+
}
|
|
29785
|
+
const firstSegment = relativeResolved.split(external_node_path_.sep)[0];
|
|
29786
|
+
if (relativeResolved === "" ||
|
|
29787
|
+
relativeResolved === "." ||
|
|
29788
|
+
firstSegment === ".." ||
|
|
29789
|
+
external_node_path_.isAbsolute(relativeResolved)) {
|
|
29790
|
+
throw new errors_FsSafeError("outside-workspace", "file is outside workspace root");
|
|
29791
|
+
}
|
|
29792
|
+
const relativePosix = relativeResolved.split(external_node_path_.sep).join(external_node_path_.posix.sep);
|
|
29793
|
+
if (!path_isPathInside(resolved.rootWithSep, resolved.canonicalPath)) {
|
|
29794
|
+
throw new errors_FsSafeError("outside-workspace", "file is outside workspace root");
|
|
29795
|
+
}
|
|
29796
|
+
return { rootReal: resolved.rootReal, resolved: resolved.canonicalPath, relativePosix };
|
|
29797
|
+
}
|
|
29798
|
+
async function resolvePinnedRootPathInRoot(root, params) {
|
|
29799
|
+
const rootReal = root.rootReal;
|
|
29800
|
+
let resolved;
|
|
29801
|
+
try {
|
|
29802
|
+
resolved = await resolveRootPath({
|
|
29803
|
+
absolutePath: external_node_path_.resolve(rootReal, await expandRelativePathWithHome(params.relativePath)),
|
|
29804
|
+
rootPath: rootReal,
|
|
29805
|
+
rootCanonicalPath: rootReal,
|
|
29806
|
+
boundaryLabel: "root",
|
|
29807
|
+
policy: params.policy,
|
|
29808
|
+
});
|
|
29809
|
+
}
|
|
29810
|
+
catch (err) {
|
|
29811
|
+
throw new errors_FsSafeError("path-alias", "path alias escape blocked", { cause: err });
|
|
29812
|
+
}
|
|
29813
|
+
const rootWithSep = ensureTrailingSep(resolved.rootCanonicalPath);
|
|
29814
|
+
return {
|
|
29815
|
+
rootReal: resolved.rootCanonicalPath,
|
|
29816
|
+
rootWithSep,
|
|
29817
|
+
canonicalPath: resolved.canonicalPath,
|
|
29818
|
+
};
|
|
29819
|
+
}
|
|
29820
|
+
async function removePathFallback(resolved) {
|
|
29821
|
+
const guard = await directory_guard_createAsyncDirectoryGuard(external_node_path_.dirname(resolved.resolved));
|
|
29822
|
+
await getFsSafeTestHooks()?.beforeRootFallbackMutation?.("remove", resolved.resolved);
|
|
29823
|
+
await assertAsyncDirectoryGuard(guard);
|
|
29824
|
+
await ((await promises_.lstat(resolved.resolved)).isDirectory() ? promises_.rmdir(resolved.resolved) : promises_.rm(resolved.resolved));
|
|
29825
|
+
await assertAsyncDirectoryGuard(guard).catch(() => undefined);
|
|
29826
|
+
}
|
|
29827
|
+
async function mkdirPathFallback(resolved) {
|
|
29828
|
+
await mkdirPathComponentsWithGuards({
|
|
29829
|
+
rootReal: resolved.rootReal, targetPath: resolved.resolved,
|
|
29830
|
+
beforeComponent: async (componentPath) => await getFsSafeTestHooks()?.beforeRootFallbackMutation?.("mkdir", componentPath),
|
|
29831
|
+
});
|
|
29832
|
+
}
|
|
29833
|
+
async function statPathFallback(root, relativePath) {
|
|
29834
|
+
const resolved = await resolvePinnedPathInRoot(root, { relativePath, allowRoot: true });
|
|
29835
|
+
try {
|
|
29836
|
+
return pathStatFromStats(await promises_.lstat(resolved.resolved));
|
|
29837
|
+
}
|
|
29838
|
+
catch (error) {
|
|
29839
|
+
if (path_isNotFoundPathError(error)) {
|
|
29840
|
+
throw new errors_FsSafeError("not-found", "file not found", {
|
|
29841
|
+
cause: error instanceof Error ? error : undefined,
|
|
29842
|
+
});
|
|
29843
|
+
}
|
|
29844
|
+
throw error;
|
|
29845
|
+
}
|
|
29846
|
+
}
|
|
29847
|
+
async function listPathFallback(root, relativePath, withFileTypes) {
|
|
29848
|
+
const resolved = await resolvePinnedPathInRoot(root, { relativePath, allowRoot: true });
|
|
29849
|
+
try {
|
|
29850
|
+
const names = await promises_.readdir(resolved.resolved);
|
|
29851
|
+
const sortedNames = names.toSorted();
|
|
29852
|
+
if (!withFileTypes) {
|
|
29853
|
+
return sortedNames;
|
|
29854
|
+
}
|
|
29855
|
+
const entries = [];
|
|
29856
|
+
for (const name of sortedNames) {
|
|
29857
|
+
entries.push({
|
|
29858
|
+
name,
|
|
29859
|
+
...pathStatFromStats(await promises_.lstat(external_node_path_.join(resolved.resolved, name))),
|
|
29860
|
+
});
|
|
29861
|
+
}
|
|
29862
|
+
return entries;
|
|
29863
|
+
}
|
|
29864
|
+
catch (error) {
|
|
29865
|
+
if (path_isNotFoundPathError(error)) {
|
|
29866
|
+
throw new errors_FsSafeError("not-found", "directory not found", {
|
|
29867
|
+
cause: error instanceof Error ? error : undefined,
|
|
29868
|
+
});
|
|
29869
|
+
}
|
|
29870
|
+
throw error;
|
|
29871
|
+
}
|
|
29872
|
+
}
|
|
29873
|
+
async function movePathFallback(root, params) {
|
|
29874
|
+
const source = await resolvePathInRoot(root, params.fromRelative);
|
|
29875
|
+
await resolvePinnedRootPathInRoot(root, {
|
|
29876
|
+
relativePath: params.fromRelative,
|
|
29877
|
+
policy: PATH_ALIAS_POLICIES.strict,
|
|
29878
|
+
});
|
|
29879
|
+
const target = await resolvePathInRoot(root, params.toRelative);
|
|
29880
|
+
await resolvePinnedRootPathInRoot(root, {
|
|
29881
|
+
relativePath: params.toRelative,
|
|
29882
|
+
policy: PATH_ALIAS_POLICIES.unlinkTarget,
|
|
29883
|
+
});
|
|
29884
|
+
try {
|
|
29885
|
+
await assertNoPathAliasEscape({
|
|
29886
|
+
absolutePath: target.resolved,
|
|
29887
|
+
rootPath: target.rootReal,
|
|
29888
|
+
boundaryLabel: "root",
|
|
29889
|
+
});
|
|
29890
|
+
}
|
|
29891
|
+
catch (error) {
|
|
29892
|
+
throw new errors_FsSafeError("path-alias", "path alias escape blocked", {
|
|
29893
|
+
cause: error instanceof Error ? error : undefined,
|
|
29894
|
+
});
|
|
29895
|
+
}
|
|
29896
|
+
let sourceStat;
|
|
29897
|
+
try {
|
|
29898
|
+
sourceStat = await promises_.lstat(source.resolved);
|
|
29899
|
+
}
|
|
29900
|
+
catch (error) {
|
|
29901
|
+
if (path_isNotFoundPathError(error)) {
|
|
29902
|
+
throw new errors_FsSafeError("not-found", "file not found", {
|
|
29903
|
+
cause: error instanceof Error ? error : undefined,
|
|
29904
|
+
});
|
|
29905
|
+
}
|
|
29906
|
+
throw error;
|
|
29907
|
+
}
|
|
29908
|
+
if (sourceStat.isSymbolicLink()) {
|
|
29909
|
+
throw new errors_FsSafeError("symlink", "symlink not allowed");
|
|
29910
|
+
}
|
|
29911
|
+
if (sourceStat.isFile() && sourceStat.nlink > 1) {
|
|
29912
|
+
throw new errors_FsSafeError("hardlink", "hardlinked path not allowed");
|
|
29913
|
+
}
|
|
29914
|
+
if (!params.overwrite) {
|
|
29915
|
+
try {
|
|
29916
|
+
await promises_.lstat(target.resolved);
|
|
29917
|
+
throw new errors_FsSafeError("already-exists", "destination exists");
|
|
29918
|
+
}
|
|
29919
|
+
catch (error) {
|
|
29920
|
+
if (error instanceof errors_FsSafeError) {
|
|
29921
|
+
throw error;
|
|
29922
|
+
}
|
|
29923
|
+
if (!path_isNotFoundPathError(error)) {
|
|
29924
|
+
throw error;
|
|
29925
|
+
}
|
|
29926
|
+
}
|
|
29927
|
+
}
|
|
29928
|
+
const sourceParentGuard = await directory_guard_createAsyncDirectoryGuard(external_node_path_.dirname(source.resolved));
|
|
29929
|
+
const targetParentGuard = await directory_guard_createNearestExistingDirectoryGuard(target.rootReal, external_node_path_.dirname(target.resolved));
|
|
29930
|
+
await getFsSafeTestHooks()?.beforeRootFallbackMutation?.("move", target.resolved);
|
|
29931
|
+
await assertAsyncDirectoryGuard(sourceParentGuard);
|
|
29932
|
+
await assertAsyncDirectoryGuard(targetParentGuard);
|
|
29933
|
+
try {
|
|
29934
|
+
await promises_.rename(source.resolved, target.resolved);
|
|
29935
|
+
}
|
|
29936
|
+
catch (error) {
|
|
29937
|
+
if (path_isNotFoundPathError(error)) {
|
|
29938
|
+
throw new errors_FsSafeError("not-found", "file not found", {
|
|
29939
|
+
cause: error instanceof Error ? error : undefined,
|
|
29940
|
+
});
|
|
29941
|
+
}
|
|
29942
|
+
if (hasNodeErrorCode(error, "EEXIST")) {
|
|
29943
|
+
throw new errors_FsSafeError("already-exists", "destination exists", {
|
|
29944
|
+
cause: error instanceof Error ? error : undefined,
|
|
29945
|
+
});
|
|
29946
|
+
}
|
|
29947
|
+
throw error;
|
|
29948
|
+
}
|
|
29949
|
+
await assertAsyncDirectoryGuard(targetParentGuard).catch(() => undefined);
|
|
29950
|
+
}
|
|
29951
|
+
async function writeFileFallback(root, params) {
|
|
29952
|
+
if (params.overwrite === false) {
|
|
29953
|
+
await writeMissingFileFallback(root, params);
|
|
29954
|
+
return;
|
|
29955
|
+
}
|
|
29956
|
+
const target = await openWritableFileInRoot(root, {
|
|
29957
|
+
relativePath: params.relativePath,
|
|
29958
|
+
mkdir: params.mkdir,
|
|
29959
|
+
mode: params.mode,
|
|
29960
|
+
truncateExisting: false,
|
|
29961
|
+
});
|
|
29962
|
+
const destinationPath = target.realPath;
|
|
29963
|
+
const mode = params.mode ?? (target.stat.mode & 0o777);
|
|
29964
|
+
await target.handle.close().catch(() => { });
|
|
29965
|
+
const destinationGuard = await directory_guard_createAsyncDirectoryGuard(external_node_path_.dirname(destinationPath));
|
|
29966
|
+
let tempPath = null;
|
|
29967
|
+
let unregisterTempPath = null;
|
|
29968
|
+
try {
|
|
29969
|
+
tempPath = buildAtomicWriteTempPath(destinationPath);
|
|
29970
|
+
unregisterTempPath = registerTempPathForExit(tempPath);
|
|
29971
|
+
const writtenStat = await writeTempFileForAtomicReplace({
|
|
29972
|
+
tempPath,
|
|
29973
|
+
data: params.data,
|
|
29974
|
+
encoding: params.encoding,
|
|
29975
|
+
mode: mode || 0o600,
|
|
29976
|
+
});
|
|
29977
|
+
const commitTempPath = tempPath;
|
|
29978
|
+
await withAsyncDirectoryGuards([destinationGuard], async () => {
|
|
29979
|
+
await promises_.rename(commitTempPath, destinationPath);
|
|
29980
|
+
});
|
|
29981
|
+
tempPath = null;
|
|
29982
|
+
unregisterTempPath();
|
|
29983
|
+
unregisterTempPath = null;
|
|
29984
|
+
try {
|
|
29985
|
+
await verifyAtomicWriteResult({
|
|
29986
|
+
root,
|
|
29987
|
+
targetPath: destinationPath,
|
|
29988
|
+
expectedIdentity: writtenStat,
|
|
29989
|
+
});
|
|
29990
|
+
}
|
|
29991
|
+
catch (err) {
|
|
29992
|
+
emitWriteBoundaryWarning(`post-write verification failed: ${String(err)}`);
|
|
29993
|
+
throw err;
|
|
29994
|
+
}
|
|
29995
|
+
}
|
|
29996
|
+
finally {
|
|
29997
|
+
if (tempPath) {
|
|
29998
|
+
await promises_.rm(tempPath, { force: true }).catch(() => { });
|
|
29999
|
+
}
|
|
30000
|
+
unregisterTempPath?.();
|
|
30001
|
+
}
|
|
30002
|
+
}
|
|
30003
|
+
async function writeMissingFileFallback(root, params) {
|
|
30004
|
+
const { rootReal, resolved } = await resolvePathInRoot(root, params.relativePath);
|
|
30005
|
+
try {
|
|
30006
|
+
await assertNoPathAliasEscape({
|
|
30007
|
+
absolutePath: resolved,
|
|
30008
|
+
rootPath: rootReal,
|
|
30009
|
+
boundaryLabel: "root",
|
|
30010
|
+
});
|
|
30011
|
+
}
|
|
30012
|
+
catch (err) {
|
|
30013
|
+
throw new errors_FsSafeError("path-alias", "path alias escape blocked", { cause: err });
|
|
30014
|
+
}
|
|
30015
|
+
if (params.mkdir !== false) {
|
|
30016
|
+
await promises_.mkdir(external_node_path_.dirname(resolved), { recursive: true });
|
|
30017
|
+
}
|
|
30018
|
+
const parentGuard = await directory_guard_createAsyncDirectoryGuard(external_node_path_.dirname(resolved));
|
|
30019
|
+
let created = false;
|
|
30020
|
+
try {
|
|
30021
|
+
const { handle, writtenStat } = await withAsyncDirectoryGuards([parentGuard], async () => {
|
|
30022
|
+
const handle = await promises_.open(resolved, OPEN_WRITE_CREATE_FLAGS, params.mode ?? 0o600);
|
|
30023
|
+
created = true;
|
|
30024
|
+
try {
|
|
30025
|
+
if (typeof params.data === "string") {
|
|
30026
|
+
await handle.writeFile(params.data, params.encoding ?? "utf8");
|
|
30027
|
+
}
|
|
30028
|
+
else {
|
|
30029
|
+
await handle.writeFile(params.data);
|
|
30030
|
+
}
|
|
30031
|
+
return { handle, writtenStat: await handle.stat() };
|
|
30032
|
+
}
|
|
30033
|
+
catch (error) {
|
|
30034
|
+
await handle.close().catch(() => undefined);
|
|
30035
|
+
throw error;
|
|
30036
|
+
}
|
|
30037
|
+
}, {
|
|
30038
|
+
onPostGuardFailure: async ({ handle }) => {
|
|
30039
|
+
created = false; // Parent is untrusted now; skip outer path cleanup by name.
|
|
30040
|
+
await handle.close().catch(() => undefined);
|
|
30041
|
+
},
|
|
30042
|
+
});
|
|
30043
|
+
await handle.close();
|
|
30044
|
+
await verifyAtomicWriteResult({
|
|
30045
|
+
root,
|
|
30046
|
+
targetPath: resolved,
|
|
30047
|
+
expectedIdentity: writtenStat,
|
|
30048
|
+
});
|
|
30049
|
+
created = false;
|
|
30050
|
+
}
|
|
30051
|
+
catch (err) {
|
|
30052
|
+
if (hasNodeErrorCode(err, "EEXIST")) {
|
|
30053
|
+
throw new errors_FsSafeError("already-exists", "file already exists", {
|
|
30054
|
+
cause: err instanceof Error ? err : undefined,
|
|
30055
|
+
});
|
|
30056
|
+
}
|
|
30057
|
+
throw err;
|
|
30058
|
+
}
|
|
30059
|
+
finally {
|
|
30060
|
+
if (created) {
|
|
30061
|
+
await promises_.rm(resolved, { force: true }).catch(() => undefined);
|
|
30062
|
+
}
|
|
30063
|
+
}
|
|
30064
|
+
}
|
|
30065
|
+
async function copyFileFallback(root, params, source) {
|
|
30066
|
+
let target = null;
|
|
30067
|
+
let sourceClosedByStream = false;
|
|
30068
|
+
let targetClosedByUs = false;
|
|
30069
|
+
let tempHandle = null;
|
|
30070
|
+
let tempPath = null;
|
|
30071
|
+
let unregisterTempPath = null;
|
|
30072
|
+
let tempClosedByStream = false;
|
|
30073
|
+
try {
|
|
30074
|
+
target = await openWritableFileInRoot(root, {
|
|
30075
|
+
relativePath: params.relativePath,
|
|
30076
|
+
mkdir: params.mkdir,
|
|
30077
|
+
mode: params.mode,
|
|
30078
|
+
truncateExisting: false,
|
|
30079
|
+
});
|
|
30080
|
+
const destinationPath = target.realPath;
|
|
30081
|
+
const mode = params.mode ?? (target.stat.mode & 0o777);
|
|
30082
|
+
await target.handle.close().catch(() => { });
|
|
30083
|
+
targetClosedByUs = true;
|
|
30084
|
+
const destinationGuard = await directory_guard_createAsyncDirectoryGuard(external_node_path_.dirname(destinationPath));
|
|
30085
|
+
tempPath = buildAtomicWriteTempPath(destinationPath);
|
|
30086
|
+
unregisterTempPath = registerTempPathForExit(tempPath);
|
|
30087
|
+
tempHandle = await promises_.open(tempPath, OPEN_WRITE_CREATE_FLAGS, mode || 0o600);
|
|
30088
|
+
const sourceStream = createBoundedReadStream(source, params.maxBytes);
|
|
30089
|
+
const targetStream = tempHandle.createWriteStream();
|
|
30090
|
+
sourceStream.once("close", () => {
|
|
30091
|
+
sourceClosedByStream = true;
|
|
30092
|
+
});
|
|
30093
|
+
targetStream.once("close", () => {
|
|
30094
|
+
tempClosedByStream = true;
|
|
30095
|
+
});
|
|
30096
|
+
await (0,external_node_stream_promises_.pipeline)(sourceStream, targetStream);
|
|
30097
|
+
const writtenStat = await promises_.stat(tempPath);
|
|
30098
|
+
if (!tempClosedByStream) {
|
|
30099
|
+
await tempHandle.close().catch(() => { });
|
|
30100
|
+
tempClosedByStream = true;
|
|
30101
|
+
}
|
|
30102
|
+
tempHandle = null;
|
|
30103
|
+
const commitTempPath = tempPath;
|
|
30104
|
+
await withAsyncDirectoryGuards([destinationGuard], async () => {
|
|
30105
|
+
await promises_.rename(commitTempPath, destinationPath);
|
|
30106
|
+
});
|
|
30107
|
+
tempPath = null;
|
|
30108
|
+
unregisterTempPath();
|
|
30109
|
+
unregisterTempPath = null;
|
|
30110
|
+
try {
|
|
30111
|
+
await verifyAtomicWriteResult({
|
|
30112
|
+
root,
|
|
30113
|
+
targetPath: destinationPath,
|
|
30114
|
+
expectedIdentity: writtenStat,
|
|
30115
|
+
});
|
|
30116
|
+
}
|
|
30117
|
+
catch (err) {
|
|
30118
|
+
emitWriteBoundaryWarning(`post-copy verification failed: ${String(err)}`);
|
|
30119
|
+
throw err;
|
|
30120
|
+
}
|
|
30121
|
+
}
|
|
30122
|
+
catch (err) {
|
|
30123
|
+
if (target?.createdForWrite) {
|
|
30124
|
+
await promises_.rm(target.realPath, { force: true }).catch(() => { });
|
|
30125
|
+
}
|
|
30126
|
+
throw err;
|
|
30127
|
+
}
|
|
30128
|
+
finally {
|
|
30129
|
+
if (!sourceClosedByStream) {
|
|
30130
|
+
await source.handle.close().catch(() => { });
|
|
30131
|
+
}
|
|
30132
|
+
if (tempHandle && !tempClosedByStream) {
|
|
30133
|
+
await tempHandle.close().catch(() => { });
|
|
30134
|
+
}
|
|
30135
|
+
if (tempPath) {
|
|
30136
|
+
await promises_.rm(tempPath, { force: true }).catch(() => { });
|
|
30137
|
+
}
|
|
30138
|
+
unregisterTempPath?.();
|
|
30139
|
+
if (target && !targetClosedByUs) {
|
|
30140
|
+
await target.handle.close().catch(() => { });
|
|
30141
|
+
}
|
|
30142
|
+
}
|
|
26524
30143
|
}
|
|
26525
|
-
/**
|
|
26526
|
-
* List of known action names for convenience
|
|
26527
|
-
*/ const KNOWN_ACTIONS = Object.keys(DEFAULT_ACTION_VERSIONS);
|
|
26528
30144
|
|
|
26529
|
-
// EXTERNAL MODULE: external "node:fs"
|
|
26530
|
-
var external_node_fs_ = __webpack_require__(3024);
|
|
26531
30145
|
;// CONCATENATED MODULE: ../core/src/gateways/file-system-utils.ts
|
|
26532
30146
|
/**
|
|
26533
30147
|
* Shared file system utilities for gateways.
|
|
26534
30148
|
*/
|
|
26535
30149
|
|
|
26536
30150
|
|
|
30151
|
+
|
|
26537
30152
|
/**
|
|
26538
30153
|
* Checks if a file or directory exists.
|
|
26539
30154
|
*/ async function file_system_utils_fileExists(path) {
|
|
@@ -26547,9 +30162,92 @@ var external_node_fs_ = __webpack_require__(3024);
|
|
|
26547
30162
|
function isPathWithinRoot(rootPath, candidatePath) {
|
|
26548
30163
|
return candidatePath === rootPath || candidatePath.startsWith(`${rootPath}${external_node_path_.sep}`);
|
|
26549
30164
|
}
|
|
30165
|
+
function mapFsSafeError(error, relativePath) {
|
|
30166
|
+
if (error instanceof errors_FsSafeError) {
|
|
30167
|
+
switch(error.code){
|
|
30168
|
+
case "outside-workspace":
|
|
30169
|
+
case "invalid-path":
|
|
30170
|
+
throw new Error(`Resolved path is outside target directory: ${relativePath}`, {
|
|
30171
|
+
cause: error
|
|
30172
|
+
});
|
|
30173
|
+
case "path-alias":
|
|
30174
|
+
case "symlink":
|
|
30175
|
+
throw new Error(`Symlinks are not allowed: path contains symbolic link: ${relativePath}`, {
|
|
30176
|
+
cause: error
|
|
30177
|
+
});
|
|
30178
|
+
case "too-large":
|
|
30179
|
+
throw new Error(`File ${relativePath} exceeds size limit: ${error.message}`, {
|
|
30180
|
+
cause: error
|
|
30181
|
+
});
|
|
30182
|
+
default:
|
|
30183
|
+
throw error;
|
|
30184
|
+
}
|
|
30185
|
+
}
|
|
30186
|
+
throw error;
|
|
30187
|
+
}
|
|
30188
|
+
async function createSafeRoot(targetDir, maxBytes) {
|
|
30189
|
+
return root_impl_root(targetDir, {
|
|
30190
|
+
hardlinks: "reject",
|
|
30191
|
+
maxBytes,
|
|
30192
|
+
symlinks: "reject"
|
|
30193
|
+
});
|
|
30194
|
+
}
|
|
30195
|
+
async function file_system_utils_readTextWithinRoot(targetDir, relativePath, maxBytes) {
|
|
30196
|
+
try {
|
|
30197
|
+
const safeRoot = await createSafeRoot(targetDir, maxBytes);
|
|
30198
|
+
return await safeRoot.readText(relativePath, {
|
|
30199
|
+
maxBytes
|
|
30200
|
+
});
|
|
30201
|
+
} catch (error) {
|
|
30202
|
+
mapFsSafeError(error, relativePath);
|
|
30203
|
+
}
|
|
30204
|
+
}
|
|
30205
|
+
async function file_system_utils_listDirectoryWithinRoot(targetDir, relativePath) {
|
|
30206
|
+
try {
|
|
30207
|
+
const safeRoot = await createSafeRoot(targetDir);
|
|
30208
|
+
const entries = await safeRoot.list(relativePath, {
|
|
30209
|
+
withFileTypes: true
|
|
30210
|
+
});
|
|
30211
|
+
return entries.map(toSafeDirEntry);
|
|
30212
|
+
} catch (error) {
|
|
30213
|
+
mapFsSafeError(error, relativePath);
|
|
30214
|
+
}
|
|
30215
|
+
}
|
|
30216
|
+
function toSafeDirEntry(entry) {
|
|
30217
|
+
return {
|
|
30218
|
+
name: entry.name,
|
|
30219
|
+
isDirectory: ()=>entry.isDirectory,
|
|
30220
|
+
isFile: ()=>entry.isFile,
|
|
30221
|
+
isSymbolicLink: ()=>entry.isSymbolicLink
|
|
30222
|
+
};
|
|
30223
|
+
}
|
|
30224
|
+
async function file_system_utils_pathExistsWithinRoot(targetDir, relativePath) {
|
|
30225
|
+
try {
|
|
30226
|
+
const safeRoot = await createSafeRoot(targetDir);
|
|
30227
|
+
return await safeRoot.exists(relativePath);
|
|
30228
|
+
} catch (error) {
|
|
30229
|
+
mapFsSafeError(error, relativePath);
|
|
30230
|
+
}
|
|
30231
|
+
}
|
|
30232
|
+
/**
|
|
30233
|
+
* Returns true if the error originated from an fs-safe security check
|
|
30234
|
+
* (symlink, traversal, or size-limit violation). These errors carry a
|
|
30235
|
+
* FsSafeError as their `cause` and should be re-thrown rather than
|
|
30236
|
+
* silently swallowed by per-file error handlers.
|
|
30237
|
+
*/ function isFsSafeViolation(error) {
|
|
30238
|
+
return error instanceof Error && error.cause instanceof errors_FsSafeError;
|
|
30239
|
+
}
|
|
30240
|
+
async function file_system_utils_statWithinRoot(targetDir, relativePath) {
|
|
30241
|
+
try {
|
|
30242
|
+
const safeRoot = await createSafeRoot(targetDir);
|
|
30243
|
+
return await safeRoot.stat(relativePath);
|
|
30244
|
+
} catch (error) {
|
|
30245
|
+
mapFsSafeError(error, relativePath);
|
|
30246
|
+
}
|
|
30247
|
+
}
|
|
26550
30248
|
/**
|
|
26551
30249
|
* Resolves a relative path under targetDir and rejects traversal outside the root.
|
|
26552
|
-
*/ async function
|
|
30250
|
+
*/ async function file_system_utils_resolvePathWithinRoot(targetDir, relativePath) {
|
|
26553
30251
|
if (!relativePath) {
|
|
26554
30252
|
throw new Error("Path must not be empty");
|
|
26555
30253
|
}
|
|
@@ -26591,14 +30289,14 @@ function isPathWithinRoot(rootPath, candidatePath) {
|
|
|
26591
30289
|
/**
|
|
26592
30290
|
* Resolves a relative path under targetDir and validates it does not pass through symlinks.
|
|
26593
30291
|
*/ async function file_system_utils_resolveSafePath(targetDir, relativePath) {
|
|
26594
|
-
const resolvedPath = await
|
|
30292
|
+
const resolvedPath = await file_system_utils_resolvePathWithinRoot(targetDir, relativePath);
|
|
26595
30293
|
await file_system_utils_assertPathHasNoSymbolicLinks(targetDir, resolvedPath);
|
|
26596
30294
|
return resolvedPath;
|
|
26597
30295
|
}
|
|
26598
30296
|
/**
|
|
26599
30297
|
* Enforces a maximum file size before reading/parsing.
|
|
26600
|
-
*/ async function
|
|
26601
|
-
const fileStats = await
|
|
30298
|
+
*/ async function assertFileSizeWithinLimit(filePath, maxBytes, context) {
|
|
30299
|
+
const fileStats = await stat(filePath);
|
|
26602
30300
|
if (fileStats.size > maxBytes) {
|
|
26603
30301
|
throw new Error(`${context} exceeds size limit (${fileStats.size} bytes > ${maxBytes} bytes)`);
|
|
26604
30302
|
}
|
|
@@ -26684,16 +30382,17 @@ function isPathWithinRoot(rootPath, candidatePath) {
|
|
|
26684
30382
|
* Handles reading and writing .claude/settings.json and CLAUDE.md files.
|
|
26685
30383
|
*/
|
|
26686
30384
|
|
|
30385
|
+
const MAX_CLAUDE_SETTINGS_BYTES = 1_048_576;
|
|
30386
|
+
const MAX_CLAUDE_DOC_BYTES = 1_048_576;
|
|
26687
30387
|
/**
|
|
26688
30388
|
* File system implementation of ClaudeFileGateway
|
|
26689
30389
|
*/ class FileSystemClaudeFileGateway {
|
|
26690
30390
|
async readSettings(targetDir) {
|
|
26691
|
-
|
|
26692
|
-
if (!await file_system_utils_fileExists(settingsPath)) {
|
|
30391
|
+
if (!await file_system_utils_pathExistsWithinRoot(targetDir, ".claude/settings.json")) {
|
|
26693
30392
|
return null;
|
|
26694
30393
|
}
|
|
30394
|
+
const content = await file_system_utils_readTextWithinRoot(targetDir, ".claude/settings.json", MAX_CLAUDE_SETTINGS_BYTES);
|
|
26695
30395
|
try {
|
|
26696
|
-
const content = await (0,promises_.readFile)(settingsPath, "utf-8");
|
|
26697
30396
|
return JSON.parse(content);
|
|
26698
30397
|
} catch {
|
|
26699
30398
|
// If JSON parsing fails, treat as if file doesn't exist
|
|
@@ -26712,11 +30411,10 @@ function isPathWithinRoot(rootPath, candidatePath) {
|
|
|
26712
30411
|
await (0,promises_.writeFile)(settingsPath, content, "utf-8");
|
|
26713
30412
|
}
|
|
26714
30413
|
async readDocumentation(targetDir) {
|
|
26715
|
-
|
|
26716
|
-
if (!await file_system_utils_fileExists(docPath)) {
|
|
30414
|
+
if (!await file_system_utils_pathExistsWithinRoot(targetDir, "CLAUDE.md")) {
|
|
26717
30415
|
return null;
|
|
26718
30416
|
}
|
|
26719
|
-
return (
|
|
30417
|
+
return file_system_utils_readTextWithinRoot(targetDir, "CLAUDE.md", MAX_CLAUDE_DOC_BYTES);
|
|
26720
30418
|
}
|
|
26721
30419
|
async writeDocumentation(targetDir, content) {
|
|
26722
30420
|
const docPath = await file_system_utils_resolveSafePath(targetDir, "CLAUDE.md");
|
|
@@ -26779,7 +30477,7 @@ const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
|
26779
30477
|
const _EXTNAME_RE = /.(\.[^./]+|\.)$/;
|
|
26780
30478
|
const _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/;
|
|
26781
30479
|
const pathe_M_eThtNZ_sep = "/";
|
|
26782
|
-
const
|
|
30480
|
+
const pathe_M_eThtNZ_normalize = function(path) {
|
|
26783
30481
|
if (path.length === 0) {
|
|
26784
30482
|
return ".";
|
|
26785
30483
|
}
|
|
@@ -26827,7 +30525,7 @@ const pathe_M_eThtNZ_join = function(...segments) {
|
|
|
26827
30525
|
path += seg;
|
|
26828
30526
|
}
|
|
26829
30527
|
}
|
|
26830
|
-
return
|
|
30528
|
+
return pathe_M_eThtNZ_normalize(path);
|
|
26831
30529
|
};
|
|
26832
30530
|
function pathe_M_eThtNZ_cwd() {
|
|
26833
30531
|
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
@@ -26980,7 +30678,7 @@ const pathe_M_eThtNZ_parse = function(p) {
|
|
|
26980
30678
|
};
|
|
26981
30679
|
};
|
|
26982
30680
|
const matchesGlob = (path, pattern) => {
|
|
26983
|
-
return zeptomatch(pattern,
|
|
30681
|
+
return zeptomatch(pattern, pathe_M_eThtNZ_normalize(path));
|
|
26984
30682
|
};
|
|
26985
30683
|
|
|
26986
30684
|
const pathe_M_eThtNZ_path = (/* unused pure expression or super */ null && ({
|
|
@@ -26992,7 +30690,7 @@ const pathe_M_eThtNZ_path = (/* unused pure expression or super */ null && ({
|
|
|
26992
30690
|
isAbsolute: pathe_M_eThtNZ_isAbsolute,
|
|
26993
30691
|
join: pathe_M_eThtNZ_join,
|
|
26994
30692
|
matchesGlob: matchesGlob,
|
|
26995
|
-
normalize:
|
|
30693
|
+
normalize: pathe_M_eThtNZ_normalize,
|
|
26996
30694
|
normalizeString: normalizeString,
|
|
26997
30695
|
parse: pathe_M_eThtNZ_parse,
|
|
26998
30696
|
relative: pathe_M_eThtNZ_relative,
|
|
@@ -27007,8 +30705,6 @@ const pathe_M_eThtNZ_path = (/* unused pure expression or super */ null && ({
|
|
|
27007
30705
|
var lib_main = __webpack_require__(5599);
|
|
27008
30706
|
// EXTERNAL MODULE: external "node:url"
|
|
27009
30707
|
var external_node_url_ = __webpack_require__(3136);
|
|
27010
|
-
// EXTERNAL MODULE: external "node:os"
|
|
27011
|
-
var external_node_os_ = __webpack_require__(8161);
|
|
27012
30708
|
// EXTERNAL MODULE: external "node:assert"
|
|
27013
30709
|
var external_node_assert_ = __webpack_require__(4589);
|
|
27014
30710
|
// EXTERNAL MODULE: external "node:v8"
|
|
@@ -28545,8 +32241,8 @@ function findFarthestFile(filename, options = {}) {
|
|
|
28545
32241
|
});
|
|
28546
32242
|
}
|
|
28547
32243
|
function _resolvePath(id, opts = {}) {
|
|
28548
|
-
if (id instanceof URL || id.startsWith("file://")) return
|
|
28549
|
-
if (pathe_M_eThtNZ_isAbsolute(id)) return
|
|
32244
|
+
if (id instanceof URL || id.startsWith("file://")) return pathe_M_eThtNZ_normalize((0,external_node_url_.fileURLToPath)(id));
|
|
32245
|
+
if (pathe_M_eThtNZ_isAbsolute(id)) return pathe_M_eThtNZ_normalize(id);
|
|
28550
32246
|
return resolveModulePath(id, {
|
|
28551
32247
|
...opts,
|
|
28552
32248
|
from: opts.from || opts.parent || opts.url
|
|
@@ -29155,7 +32851,7 @@ function tryResolve(id, options) {
|
|
|
29155
32851
|
extensions: SUPPORTED_EXTENSIONS,
|
|
29156
32852
|
cache: false
|
|
29157
32853
|
});
|
|
29158
|
-
return res ?
|
|
32854
|
+
return res ? pathe_M_eThtNZ_normalize(res) : void 0;
|
|
29159
32855
|
}
|
|
29160
32856
|
//#endregion
|
|
29161
32857
|
//#region src/types.ts
|
|
@@ -29603,11 +33299,9 @@ const CopilotSetupConfigSchema = schemas_object({
|
|
|
29603
33299
|
|
|
29604
33300
|
|
|
29605
33301
|
|
|
29606
|
-
|
|
29607
33302
|
const MAX_VERSION_FILE_BYTES = 16 * 1024;
|
|
29608
|
-
async function readVersionFileContent(
|
|
29609
|
-
await
|
|
29610
|
-
const content = await (0,promises_.readFile)(filePath, "utf-8");
|
|
33303
|
+
async function readVersionFileContent(targetDir, relativePath) {
|
|
33304
|
+
const content = await file_system_utils_readTextWithinRoot(targetDir, relativePath, MAX_VERSION_FILE_BYTES);
|
|
29611
33305
|
return content.trim();
|
|
29612
33306
|
}
|
|
29613
33307
|
/**
|
|
@@ -29636,16 +33330,14 @@ async function readVersionFileContent(filePath) {
|
|
|
29636
33330
|
};
|
|
29637
33331
|
}
|
|
29638
33332
|
async detectMise(targetDir) {
|
|
29639
|
-
|
|
29640
|
-
return file_system_utils_fileExists(miseTomlPath);
|
|
33333
|
+
return file_system_utils_pathExistsWithinRoot(targetDir, "mise.toml");
|
|
29641
33334
|
}
|
|
29642
33335
|
async detectVersionFiles(targetDir, config) {
|
|
29643
33336
|
const filenameToType = getVersionFilenameToTypeMap(config);
|
|
29644
33337
|
const versionFiles = [];
|
|
29645
33338
|
for (const fileConfig of config.versionFiles){
|
|
29646
|
-
|
|
29647
|
-
|
|
29648
|
-
const version = await readVersionFileContent(filePath);
|
|
33339
|
+
if (await file_system_utils_pathExistsWithinRoot(targetDir, fileConfig.filename)) {
|
|
33340
|
+
const version = await readVersionFileContent(targetDir, fileConfig.filename);
|
|
29649
33341
|
versionFiles.push({
|
|
29650
33342
|
type: filenameToType[fileConfig.filename],
|
|
29651
33343
|
filename: fileConfig.filename,
|
|
@@ -29674,8 +33366,7 @@ async function readVersionFileContent(filePath) {
|
|
|
29674
33366
|
return packageManagers;
|
|
29675
33367
|
}
|
|
29676
33368
|
async detectNodePackageManager(targetDir, nodePackageManagers) {
|
|
29677
|
-
|
|
29678
|
-
if (!await file_system_utils_fileExists(packageJsonPath)) {
|
|
33369
|
+
if (!await file_system_utils_pathExistsWithinRoot(targetDir, "package.json")) {
|
|
29679
33370
|
return null;
|
|
29680
33371
|
}
|
|
29681
33372
|
const lockfileOrder = [
|
|
@@ -29688,8 +33379,7 @@ async function readVersionFileContent(filePath) {
|
|
|
29688
33379
|
if (!pmConfig?.lockfile) {
|
|
29689
33380
|
continue;
|
|
29690
33381
|
}
|
|
29691
|
-
|
|
29692
|
-
if (await file_system_utils_fileExists(lockfilePath)) {
|
|
33382
|
+
if (await file_system_utils_pathExistsWithinRoot(targetDir, pmConfig.lockfile)) {
|
|
29693
33383
|
return {
|
|
29694
33384
|
type: pmConfig.type,
|
|
29695
33385
|
filename: pmConfig.manifestFile,
|
|
@@ -29713,10 +33403,9 @@ async function readVersionFileContent(filePath) {
|
|
|
29713
33403
|
if (!pmConfig) {
|
|
29714
33404
|
continue;
|
|
29715
33405
|
}
|
|
29716
|
-
|
|
29717
|
-
if (await file_system_utils_fileExists(manifestPath)) {
|
|
33406
|
+
if (await file_system_utils_pathExistsWithinRoot(targetDir, pmConfig.manifestFile)) {
|
|
29718
33407
|
const lockfilePath = pmConfig.lockfile ? await file_system_utils_resolveSafePath(targetDir, pmConfig.lockfile) : undefined;
|
|
29719
|
-
const hasLockfile = lockfilePath ? await
|
|
33408
|
+
const hasLockfile = lockfilePath ? await file_system_utils_pathExistsWithinRoot(targetDir, pmConfig.lockfile) : false;
|
|
29720
33409
|
if (pmConfig.requiresLockfile && !hasLockfile) {
|
|
29721
33410
|
continue;
|
|
29722
33411
|
}
|
|
@@ -29732,10 +33421,9 @@ async function readVersionFileContent(filePath) {
|
|
|
29732
33421
|
async detectOtherPackageManagers(targetDir, otherPackageManagers) {
|
|
29733
33422
|
const packageManagers = [];
|
|
29734
33423
|
for (const pmConfig of otherPackageManagers){
|
|
29735
|
-
|
|
29736
|
-
if (await file_system_utils_fileExists(manifestPath)) {
|
|
33424
|
+
if (await file_system_utils_pathExistsWithinRoot(targetDir, pmConfig.manifestFile)) {
|
|
29737
33425
|
const lockfilePath = pmConfig.lockfile ? await file_system_utils_resolveSafePath(targetDir, pmConfig.lockfile) : undefined;
|
|
29738
|
-
const hasLockfile = lockfilePath ? await
|
|
33426
|
+
const hasLockfile = lockfilePath ? await file_system_utils_pathExistsWithinRoot(targetDir, pmConfig.lockfile) : false;
|
|
29739
33427
|
if (pmConfig.requiresLockfile && !hasLockfile) {
|
|
29740
33428
|
continue;
|
|
29741
33429
|
}
|
|
@@ -29756,8 +33444,6 @@ async function readVersionFileContent(filePath) {
|
|
|
29756
33444
|
return new FileSystemEnvironmentGateway(cwd);
|
|
29757
33445
|
}
|
|
29758
33446
|
|
|
29759
|
-
// EXTERNAL MODULE: external "node:child_process"
|
|
29760
|
-
var external_node_child_process_ = __webpack_require__(1421);
|
|
29761
33447
|
;// CONCATENATED MODULE: ../core/src/gateways/github-ruleset-gateway.ts
|
|
29762
33448
|
/**
|
|
29763
33449
|
* Gateway for interacting with GitHub repository rulesets via Octokit.
|
|
@@ -29936,8 +33622,6 @@ function defaultExec(command, args, options) {
|
|
|
29936
33622
|
return new OctokitRulesetGateway(octokit);
|
|
29937
33623
|
}
|
|
29938
33624
|
|
|
29939
|
-
// EXTERNAL MODULE: external "node:crypto"
|
|
29940
|
-
var external_node_crypto_ = __webpack_require__(7598);
|
|
29941
33625
|
;// CONCATENATED MODULE: ../core/src/gateways/init-hooks-config-gateway.ts
|
|
29942
33626
|
|
|
29943
33627
|
|
|
@@ -30175,7 +33859,7 @@ function createInitHooksConfigGateway() {
|
|
|
30175
33859
|
* Gateway for analyzing repository instructions for feedback loop coverage
|
|
30176
33860
|
*/
|
|
30177
33861
|
|
|
30178
|
-
|
|
33862
|
+
const MAX_INSTRUCTION_FILE_BYTES = 1_048_576;
|
|
30179
33863
|
/**
|
|
30180
33864
|
* File system implementation of instruction analysis gateway
|
|
30181
33865
|
*/ class FileSystemInstructionAnalysisGateway {
|
|
@@ -30184,17 +33868,17 @@ function createInitHooksConfigGateway() {
|
|
|
30184
33868
|
const references = [];
|
|
30185
33869
|
const documentedTargets = new Set();
|
|
30186
33870
|
for (const file of instructionFiles){
|
|
30187
|
-
const content = await (
|
|
33871
|
+
const content = await file_system_utils_readTextWithinRoot(targetDir, file, MAX_INSTRUCTION_FILE_BYTES);
|
|
30188
33872
|
const lines = content.split("\n");
|
|
30189
33873
|
for (const script of scripts){
|
|
30190
|
-
const scriptRefs = this.findReferencesInContent(script.name, content, lines, file, targetDir);
|
|
33874
|
+
const scriptRefs = this.findReferencesInContent(script.name, content, lines, (0,external_node_path_.join)(targetDir, file), targetDir);
|
|
30191
33875
|
if (scriptRefs.length > 0) {
|
|
30192
33876
|
references.push(...scriptRefs);
|
|
30193
33877
|
documentedTargets.add(script.name);
|
|
30194
33878
|
}
|
|
30195
33879
|
}
|
|
30196
33880
|
for (const tool of tools){
|
|
30197
|
-
const toolRefs = this.findReferencesInContent(tool.name, content, lines, file, targetDir);
|
|
33881
|
+
const toolRefs = this.findReferencesInContent(tool.name, content, lines, (0,external_node_path_.join)(targetDir, file), targetDir);
|
|
30198
33882
|
if (toolRefs.length > 0) {
|
|
30199
33883
|
references.push(...toolRefs);
|
|
30200
33884
|
documentedTargets.add(tool.name);
|
|
@@ -30223,19 +33907,26 @@ function createInitHooksConfigGateway() {
|
|
|
30223
33907
|
}
|
|
30224
33908
|
};
|
|
30225
33909
|
}
|
|
33910
|
+
async safePathExists(targetDir, relativePath) {
|
|
33911
|
+
try {
|
|
33912
|
+
return await file_system_utils_pathExistsWithinRoot(targetDir, relativePath);
|
|
33913
|
+
} catch {
|
|
33914
|
+
return false;
|
|
33915
|
+
}
|
|
33916
|
+
}
|
|
30226
33917
|
async findInstructionFiles(targetDir) {
|
|
30227
33918
|
const files = [];
|
|
30228
|
-
const copilotInstructions = (0,external_node_path_.join)(
|
|
30229
|
-
if (await
|
|
33919
|
+
const copilotInstructions = (0,external_node_path_.join)(".github", "copilot-instructions.md");
|
|
33920
|
+
if (await this.safePathExists(targetDir, copilotInstructions)) {
|
|
30230
33921
|
files.push(copilotInstructions);
|
|
30231
33922
|
}
|
|
30232
|
-
const instructionsDir = (0,external_node_path_.join)(
|
|
30233
|
-
if (await
|
|
33923
|
+
const instructionsDir = (0,external_node_path_.join)(".github", "instructions");
|
|
33924
|
+
if (await this.safePathExists(targetDir, instructionsDir)) {
|
|
30234
33925
|
try {
|
|
30235
|
-
const instructionFiles = await (
|
|
33926
|
+
const instructionFiles = await file_system_utils_listDirectoryWithinRoot(targetDir, instructionsDir);
|
|
30236
33927
|
for (const file of instructionFiles){
|
|
30237
|
-
if (file.endsWith(".md")) {
|
|
30238
|
-
files.push((0,external_node_path_.join)(instructionsDir, file));
|
|
33928
|
+
if (file.isFile() && file.name.endsWith(".md")) {
|
|
33929
|
+
files.push((0,external_node_path_.join)(instructionsDir, file.name));
|
|
30239
33930
|
}
|
|
30240
33931
|
}
|
|
30241
33932
|
} catch {}
|
|
@@ -30390,7 +34081,6 @@ const lesson_schema_LessonFrontmatterSchema = schemas_object({
|
|
|
30390
34081
|
|
|
30391
34082
|
|
|
30392
34083
|
|
|
30393
|
-
|
|
30394
34084
|
const MAX_LESSON_FILE_BYTES = 1_048_576; // 1 MB
|
|
30395
34085
|
const MAX_LESSON_FILES = 500;
|
|
30396
34086
|
const MAX_AGGREGATE_BYTES = (/* unused pure expression or super */ null && (20 * 1024 * 1024)); // 20 MB
|
|
@@ -30420,12 +34110,16 @@ const LESSONS_RELATIVE_PATH = (0,external_node_path_.join)(".lousy-agents", "les
|
|
|
30420
34110
|
}
|
|
30421
34111
|
class LessonFileGateway {
|
|
30422
34112
|
async readLessons(rootDir) {
|
|
30423
|
-
const
|
|
30424
|
-
|
|
30425
|
-
|
|
30426
|
-
|
|
34113
|
+
const lessonsDir = join(rootDir, LESSONS_RELATIVE_PATH);
|
|
34114
|
+
if (!await pathExistsWithinRoot(rootDir, LESSONS_RELATIVE_PATH)) {
|
|
34115
|
+
return {
|
|
34116
|
+
lessons: [],
|
|
34117
|
+
errors: []
|
|
34118
|
+
};
|
|
34119
|
+
}
|
|
34120
|
+
let lessonsStat;
|
|
30427
34121
|
try {
|
|
30428
|
-
|
|
34122
|
+
lessonsStat = await statWithinRoot(rootDir, LESSONS_RELATIVE_PATH);
|
|
30429
34123
|
} catch (error) {
|
|
30430
34124
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
30431
34125
|
return {
|
|
@@ -30435,14 +34129,12 @@ class LessonFileGateway {
|
|
|
30435
34129
|
}
|
|
30436
34130
|
throw error;
|
|
30437
34131
|
}
|
|
30438
|
-
if (!
|
|
34132
|
+
if (!lessonsStat.isDirectory) {
|
|
30439
34133
|
throw new Error(`Lessons path exists but is not a directory: ${lessonsDir}`);
|
|
30440
34134
|
}
|
|
30441
34135
|
let entries;
|
|
30442
34136
|
try {
|
|
30443
|
-
entries = await
|
|
30444
|
-
withFileTypes: true
|
|
30445
|
-
});
|
|
34137
|
+
entries = await listDirectoryWithinRoot(rootDir, LESSONS_RELATIVE_PATH);
|
|
30446
34138
|
} catch (error) {
|
|
30447
34139
|
const reason = error instanceof Error ? error.message : String(error);
|
|
30448
34140
|
const wrapped = new Error(`Cannot read lessons directory ${lessonsDir}: ${reason}`);
|
|
@@ -30453,7 +34145,7 @@ class LessonFileGateway {
|
|
|
30453
34145
|
}
|
|
30454
34146
|
throw wrapped;
|
|
30455
34147
|
}
|
|
30456
|
-
const mdFiles = entries.filter((e)=>e.isFile() && e.name.endsWith(".md")).map((e)=>join(
|
|
34148
|
+
const mdFiles = entries.filter((e)=>e.isFile() && e.name.endsWith(".md")).map((e)=>join(LESSONS_RELATIVE_PATH, e.name)).sort();
|
|
30457
34149
|
if (mdFiles.length > MAX_LESSON_FILES) {
|
|
30458
34150
|
throw new Error(`Lesson file count exceeds limit: ${mdFiles.length} files found (max ${MAX_LESSON_FILES})`);
|
|
30459
34151
|
}
|
|
@@ -30461,13 +34153,14 @@ class LessonFileGateway {
|
|
|
30461
34153
|
const errors = [];
|
|
30462
34154
|
let aggregateBytes = 0;
|
|
30463
34155
|
for (const filePath of mdFiles){
|
|
34156
|
+
const absoluteFilePath = join(rootDir, filePath);
|
|
30464
34157
|
let content;
|
|
30465
34158
|
try {
|
|
30466
|
-
content = await
|
|
34159
|
+
content = await readTextWithinRoot(rootDir, filePath, MAX_LESSON_FILE_BYTES);
|
|
30467
34160
|
} catch (error) {
|
|
30468
34161
|
const reason = error instanceof Error ? error.message : String(error);
|
|
30469
34162
|
errors.push({
|
|
30470
|
-
filePath,
|
|
34163
|
+
filePath: absoluteFilePath,
|
|
30471
34164
|
reason
|
|
30472
34165
|
});
|
|
30473
34166
|
continue;
|
|
@@ -30481,7 +34174,7 @@ class LessonFileGateway {
|
|
|
30481
34174
|
if (!parseResult.ok) {
|
|
30482
34175
|
const reason = parseResult.reason === "invalid" ? `Invalid YAML frontmatter: ${parseResult.detail}` : "Missing YAML frontmatter";
|
|
30483
34176
|
errors.push({
|
|
30484
|
-
filePath,
|
|
34177
|
+
filePath: absoluteFilePath,
|
|
30485
34178
|
reason
|
|
30486
34179
|
});
|
|
30487
34180
|
continue;
|
|
@@ -30490,7 +34183,7 @@ class LessonFileGateway {
|
|
|
30490
34183
|
if (!schemaResult.success) {
|
|
30491
34184
|
const reason = schemaResult.error.issues.map((i)=>`${i.path.join(".")}: ${i.message}`).join("; ");
|
|
30492
34185
|
errors.push({
|
|
30493
|
-
filePath,
|
|
34186
|
+
filePath: absoluteFilePath,
|
|
30494
34187
|
reason
|
|
30495
34188
|
});
|
|
30496
34189
|
continue;
|
|
@@ -30513,7 +34206,7 @@ class LessonFileGateway {
|
|
|
30513
34206
|
};
|
|
30514
34207
|
lessons.push({
|
|
30515
34208
|
lesson,
|
|
30516
|
-
filePath
|
|
34209
|
+
filePath: absoluteFilePath
|
|
30517
34210
|
});
|
|
30518
34211
|
}
|
|
30519
34212
|
return {
|
|
@@ -31123,11 +34816,11 @@ var external_node_tty_namespaceObject = /*#__PURE__*/__webpack_require__.t(exter
|
|
|
31123
34816
|
const {
|
|
31124
34817
|
env: consola_DXBYu_KD_env = {},
|
|
31125
34818
|
argv = [],
|
|
31126
|
-
platform = ""
|
|
34819
|
+
platform: consola_DXBYu_KD_platform = ""
|
|
31127
34820
|
} = typeof process === "undefined" ? {} : process;
|
|
31128
34821
|
const isDisabled = "NO_COLOR" in consola_DXBYu_KD_env || argv.includes("--no-color");
|
|
31129
34822
|
const isForced = "FORCE_COLOR" in consola_DXBYu_KD_env || argv.includes("--color");
|
|
31130
|
-
const consola_DXBYu_KD_isWindows =
|
|
34823
|
+
const consola_DXBYu_KD_isWindows = consola_DXBYu_KD_platform === "win32";
|
|
31131
34824
|
const isDumbTerminal = consola_DXBYu_KD_env.TERM === "dumb";
|
|
31132
34825
|
const isCompatibleTerminal = external_node_tty_namespaceObject && external_node_tty_.isatty && external_node_tty_.isatty(1) && consola_DXBYu_KD_env.TERM && !isDumbTerminal;
|
|
31133
34826
|
const isCI = "CI" in consola_DXBYu_KD_env && ("GITHUB_ACTIONS" in consola_DXBYu_KD_env || "GITLAB_CI" in consola_DXBYu_KD_env || "CIRCLECI" in consola_DXBYu_KD_env);
|
|
@@ -32077,12 +35770,10 @@ const MAX_NPMRC_BYTES = (/* unused pure expression or super */ null && (64 * 102
|
|
|
32077
35770
|
this.dryRun = dryRun;
|
|
32078
35771
|
}
|
|
32079
35772
|
async readNpmrc(targetDir) {
|
|
32080
|
-
|
|
32081
|
-
if (!await fileExists(npmrcPath)) {
|
|
35773
|
+
if (!await pathExistsWithinRoot(targetDir, ".npmrc")) {
|
|
32082
35774
|
return null;
|
|
32083
35775
|
}
|
|
32084
|
-
|
|
32085
|
-
return readFile(npmrcPath, "utf-8");
|
|
35776
|
+
return readTextWithinRoot(targetDir, ".npmrc", MAX_NPMRC_BYTES);
|
|
32086
35777
|
}
|
|
32087
35778
|
async writeNpmrc(targetDir, content) {
|
|
32088
35779
|
const npmrcPath = await resolveSafePath(targetDir, ".npmrc");
|
|
@@ -32341,7 +36032,6 @@ const PackageJsonSchema = schemas_object({
|
|
|
32341
36032
|
*/
|
|
32342
36033
|
|
|
32343
36034
|
|
|
32344
|
-
|
|
32345
36035
|
/** Maximum skill file size: 1 MB */ const MAX_SKILL_FILE_BYTES = 1_048_576;
|
|
32346
36036
|
/**
|
|
32347
36037
|
* Skill directory locations to search for SKILL.md files.
|
|
@@ -32356,30 +36046,22 @@ const PackageJsonSchema = schemas_object({
|
|
|
32356
36046
|
async discoverSkills(targetDir) {
|
|
32357
36047
|
const skills = [];
|
|
32358
36048
|
for (const relativeDir of SKILL_DIRECTORIES){
|
|
32359
|
-
const
|
|
32360
|
-
const discovered = await this.discoverSkillsInDir(skillsDir);
|
|
36049
|
+
const discovered = await this.discoverSkillsInDir(targetDir, relativeDir);
|
|
32361
36050
|
skills.push(...discovered);
|
|
32362
36051
|
}
|
|
32363
36052
|
return skills;
|
|
32364
36053
|
}
|
|
32365
|
-
async discoverSkillsInDir(skillsDir) {
|
|
32366
|
-
let dirStats;
|
|
36054
|
+
async discoverSkillsInDir(targetDir, skillsDir) {
|
|
32367
36055
|
try {
|
|
32368
|
-
|
|
32369
|
-
} catch (error) {
|
|
32370
|
-
if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
|
36056
|
+
if (!await pathExistsWithinRoot(targetDir, skillsDir)) {
|
|
32371
36057
|
return [];
|
|
32372
36058
|
}
|
|
32373
|
-
|
|
32374
|
-
}
|
|
32375
|
-
if (dirStats.isSymbolicLink() || !dirStats.isDirectory()) {
|
|
36059
|
+
} catch {
|
|
32376
36060
|
return [];
|
|
32377
36061
|
}
|
|
32378
36062
|
let entries;
|
|
32379
36063
|
try {
|
|
32380
|
-
entries = await
|
|
32381
|
-
withFileTypes: true
|
|
32382
|
-
});
|
|
36064
|
+
entries = await listDirectoryWithinRoot(targetDir, skillsDir);
|
|
32383
36065
|
} catch (error) {
|
|
32384
36066
|
if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
|
32385
36067
|
return [];
|
|
@@ -32394,20 +36076,16 @@ const PackageJsonSchema = schemas_object({
|
|
|
32394
36076
|
if (entry.name.includes("..") || entry.name.includes("/") || entry.name.includes("\\")) {
|
|
32395
36077
|
continue;
|
|
32396
36078
|
}
|
|
32397
|
-
const
|
|
32398
|
-
let
|
|
36079
|
+
const skillRelativePath = join(skillsDir, entry.name, "SKILL.md");
|
|
36080
|
+
let hasSkillFile = false;
|
|
32399
36081
|
try {
|
|
32400
|
-
|
|
32401
|
-
} catch
|
|
32402
|
-
|
|
32403
|
-
skillStat = null;
|
|
32404
|
-
} else {
|
|
32405
|
-
throw error;
|
|
32406
|
-
}
|
|
36082
|
+
hasSkillFile = await pathExistsWithinRoot(targetDir, skillRelativePath);
|
|
36083
|
+
} catch {
|
|
36084
|
+
hasSkillFile = false;
|
|
32407
36085
|
}
|
|
32408
|
-
if (
|
|
36086
|
+
if (hasSkillFile) {
|
|
32409
36087
|
skills.push({
|
|
32410
|
-
filePath:
|
|
36088
|
+
filePath: join(targetDir, skillRelativePath),
|
|
32411
36089
|
skillName: entry.name
|
|
32412
36090
|
});
|
|
32413
36091
|
}
|
|
@@ -32434,26 +36112,30 @@ const PackageJsonSchema = schemas_object({
|
|
|
32434
36112
|
|
|
32435
36113
|
|
|
32436
36114
|
|
|
32437
|
-
|
|
36115
|
+
const MAX_WORKFLOW_FILE_BYTES = 1_048_576;
|
|
32438
36116
|
/**
|
|
32439
36117
|
* File system implementation of tool discovery gateway
|
|
32440
36118
|
*/ class FileSystemToolDiscoveryGateway {
|
|
32441
36119
|
async discoverTools(targetDir) {
|
|
32442
|
-
const workflowsDir = (0,external_node_path_.join)(
|
|
32443
|
-
if (!await
|
|
36120
|
+
const workflowsDir = (0,external_node_path_.join)(".github", "workflows");
|
|
36121
|
+
if (!await file_system_utils_pathExistsWithinRoot(targetDir, workflowsDir)) {
|
|
32444
36122
|
return [];
|
|
32445
36123
|
}
|
|
32446
|
-
const files = await (
|
|
32447
|
-
const yamlFiles = files.filter((f)=>f.endsWith(".yml") || f.endsWith(".yaml"));
|
|
36124
|
+
const files = await file_system_utils_listDirectoryWithinRoot(targetDir, workflowsDir);
|
|
36125
|
+
const yamlFiles = files.filter((f)=>f.isFile() && (f.name.endsWith(".yml") || f.name.endsWith(".yaml")));
|
|
32448
36126
|
const allTools = [];
|
|
32449
36127
|
for (const file of yamlFiles){
|
|
32450
|
-
const filePath = (0,external_node_path_.join)(workflowsDir, file);
|
|
36128
|
+
const filePath = (0,external_node_path_.join)(workflowsDir, file.name);
|
|
32451
36129
|
try {
|
|
32452
|
-
const content = await (
|
|
36130
|
+
const content = await file_system_utils_readTextWithinRoot(targetDir, filePath, MAX_WORKFLOW_FILE_BYTES);
|
|
32453
36131
|
const workflow = (0,yaml_dist/* .parse */.qg)(content);
|
|
32454
|
-
const tools = this.extractToolsFromWorkflow(workflow, file);
|
|
36132
|
+
const tools = this.extractToolsFromWorkflow(workflow, file.name);
|
|
32455
36133
|
allTools.push(...tools);
|
|
32456
|
-
} catch
|
|
36134
|
+
} catch (error) {
|
|
36135
|
+
if (isFsSafeViolation(error)) {
|
|
36136
|
+
throw error;
|
|
36137
|
+
}
|
|
36138
|
+
}
|
|
32457
36139
|
}
|
|
32458
36140
|
return this.deduplicateTools(allTools);
|
|
32459
36141
|
}
|
|
@@ -32768,7 +36450,7 @@ const COPILOT_SETUP_WORKFLOW_FILENAMES = [
|
|
|
32768
36450
|
"copilot-setup-steps.yml",
|
|
32769
36451
|
"copilot-setup-steps.yaml"
|
|
32770
36452
|
];
|
|
32771
|
-
const
|
|
36453
|
+
const file_system_workflow_gateway_MAX_WORKFLOW_FILE_BYTES = 1024 * 1024;
|
|
32772
36454
|
class FileSystemWorkflowGateway {
|
|
32773
36455
|
cwd;
|
|
32774
36456
|
config = null;
|
|
@@ -32783,31 +36465,35 @@ class FileSystemWorkflowGateway {
|
|
|
32783
36465
|
}
|
|
32784
36466
|
async findCopilotSetupWorkflowPath(targetDir) {
|
|
32785
36467
|
for (const filename of COPILOT_SETUP_WORKFLOW_FILENAMES){
|
|
32786
|
-
const
|
|
32787
|
-
if (await
|
|
32788
|
-
return
|
|
36468
|
+
const relativePath = `.github/workflows/${filename}`;
|
|
36469
|
+
if (await file_system_utils_pathExistsWithinRoot(targetDir, relativePath)) {
|
|
36470
|
+
return file_system_utils_resolveSafePath(targetDir, relativePath);
|
|
32789
36471
|
}
|
|
32790
36472
|
}
|
|
32791
36473
|
return null;
|
|
32792
36474
|
}
|
|
32793
36475
|
async parseWorkflowsForSetupActions(targetDir) {
|
|
32794
|
-
const
|
|
32795
|
-
if (!await
|
|
36476
|
+
const workflowsRelativeDir = ".github/workflows";
|
|
36477
|
+
if (!await file_system_utils_pathExistsWithinRoot(targetDir, workflowsRelativeDir)) {
|
|
32796
36478
|
return [];
|
|
32797
36479
|
}
|
|
32798
|
-
const files = await (
|
|
32799
|
-
const yamlFiles = files.filter((f)=>f.endsWith(".yml") || f.endsWith(".yaml"));
|
|
36480
|
+
const files = await file_system_utils_listDirectoryWithinRoot(targetDir, workflowsRelativeDir);
|
|
36481
|
+
const yamlFiles = files.filter((f)=>f.isFile() && (f.name.endsWith(".yml") || f.name.endsWith(".yaml")));
|
|
32800
36482
|
const config = await this.getConfig();
|
|
32801
36483
|
const allCandidates = [];
|
|
32802
36484
|
for (const file of yamlFiles){
|
|
32803
|
-
const
|
|
32804
|
-
await file_system_utils_assertFileSizeWithinLimit(filePath, MAX_WORKFLOW_FILE_BYTES, `Workflow file '${file}'`);
|
|
36485
|
+
const relativePath = `.github/workflows/${file.name}`;
|
|
32805
36486
|
try {
|
|
32806
|
-
const content = await (
|
|
36487
|
+
const content = await file_system_utils_readTextWithinRoot(targetDir, relativePath, file_system_workflow_gateway_MAX_WORKFLOW_FILE_BYTES);
|
|
32807
36488
|
const workflow = (0,yaml_dist/* .parse */.qg)(content);
|
|
32808
36489
|
const candidates = extractSetupStepsFromWorkflow(workflow, config.setupActionPatterns);
|
|
32809
36490
|
allCandidates.push(...candidates);
|
|
32810
|
-
} catch
|
|
36491
|
+
} catch (error) {
|
|
36492
|
+
if (isFsSafeViolation(error)) {
|
|
36493
|
+
throw error;
|
|
36494
|
+
}
|
|
36495
|
+
// Skip workflow files with YAML parse errors or transient I/O failures
|
|
36496
|
+
}
|
|
32811
36497
|
}
|
|
32812
36498
|
return deduplicateCandidates(allCandidates);
|
|
32813
36499
|
}
|
|
@@ -32827,8 +36513,8 @@ class FileSystemWorkflowGateway {
|
|
|
32827
36513
|
if (!workflowPath) {
|
|
32828
36514
|
return null;
|
|
32829
36515
|
}
|
|
32830
|
-
|
|
32831
|
-
const content = await (
|
|
36516
|
+
const workflowRelativePath = workflowPath.endsWith("copilot-setup-steps.yaml") ? ".github/workflows/copilot-setup-steps.yaml" : ".github/workflows/copilot-setup-steps.yml";
|
|
36517
|
+
const content = await file_system_utils_readTextWithinRoot(targetDir, workflowRelativePath, file_system_workflow_gateway_MAX_WORKFLOW_FILE_BYTES);
|
|
32832
36518
|
return (0,yaml_dist/* .parse */.qg)(content);
|
|
32833
36519
|
}
|
|
32834
36520
|
async writeCopilotSetupWorkflow(targetDir, content) {
|
|
@@ -32907,12 +36593,11 @@ function createWorkflowGateway(cwd) {
|
|
|
32907
36593
|
|
|
32908
36594
|
|
|
32909
36595
|
|
|
32910
|
-
|
|
32911
36596
|
/**
|
|
32912
36597
|
* Parses a workflow file and extracts action references.
|
|
32913
|
-
*/ async function parseWorkflowFile(
|
|
36598
|
+
*/ async function parseWorkflowFile(rootDir, relativePath) {
|
|
32914
36599
|
try {
|
|
32915
|
-
const content = await (
|
|
36600
|
+
const content = await file_system_utils_readTextWithinRoot(rootDir, relativePath, 1_048_576);
|
|
32916
36601
|
const workflow = (0,yaml_dist/* .parse */.qg)(content);
|
|
32917
36602
|
return extractActionsFromWorkflow(workflow);
|
|
32918
36603
|
} catch {
|
|
@@ -32941,8 +36626,8 @@ function createWorkflowGateway(cwd) {
|
|
|
32941
36626
|
if (!await file_system_utils_fileExists(dir)) {
|
|
32942
36627
|
return types_errorResponse(`Target directory does not exist: ${dir}`);
|
|
32943
36628
|
}
|
|
32944
|
-
const
|
|
32945
|
-
if (!await
|
|
36629
|
+
const workflowsRelativeDir = (0,external_node_path_.join)(".github", "workflows");
|
|
36630
|
+
if (!await file_system_utils_pathExistsWithinRoot(dir, workflowsRelativeDir)) {
|
|
32946
36631
|
return successResponse({
|
|
32947
36632
|
workflows: [],
|
|
32948
36633
|
uniqueActions: [],
|
|
@@ -32950,12 +36635,13 @@ function createWorkflowGateway(cwd) {
|
|
|
32950
36635
|
});
|
|
32951
36636
|
}
|
|
32952
36637
|
// Read all workflow files
|
|
32953
|
-
const
|
|
36638
|
+
const entries = await file_system_utils_listDirectoryWithinRoot(dir, workflowsRelativeDir);
|
|
36639
|
+
const files = entries.filter((entry)=>entry.isFile()).map((entry)=>entry.name);
|
|
32954
36640
|
const yamlFiles = files.filter((f)=>f.endsWith(".yml") || f.endsWith(".yaml"));
|
|
32955
36641
|
const workflows = [];
|
|
32956
36642
|
for (const file of yamlFiles){
|
|
32957
|
-
const filePath = (0,external_node_path_.join)(
|
|
32958
|
-
const actions = await parseWorkflowFile(filePath);
|
|
36643
|
+
const filePath = (0,external_node_path_.join)(workflowsRelativeDir, file);
|
|
36644
|
+
const actions = await parseWorkflowFile(dir, filePath);
|
|
32959
36645
|
if (actions && actions.length > 0) {
|
|
32960
36646
|
workflows.push({
|
|
32961
36647
|
file,
|
|
@@ -32983,53 +36669,57 @@ function createWorkflowGateway(cwd) {
|
|
|
32983
36669
|
* Supports GitHub Copilot, Claude Code, and community agent instruction formats.
|
|
32984
36670
|
*/
|
|
32985
36671
|
|
|
32986
|
-
|
|
32987
36672
|
/**
|
|
32988
36673
|
* File system implementation of the instruction file discovery gateway.
|
|
32989
36674
|
*/ class FileSystemInstructionFileDiscoveryGateway {
|
|
32990
36675
|
async discoverInstructionFiles(targetDir) {
|
|
32991
36676
|
const files = [];
|
|
32992
36677
|
// .github/copilot-instructions.md
|
|
32993
|
-
const copilotInstructions = (0,external_node_path_.join)(
|
|
32994
|
-
if (await
|
|
36678
|
+
const copilotInstructions = (0,external_node_path_.join)(".github", "copilot-instructions.md");
|
|
36679
|
+
if (await this.safePathExists(targetDir, copilotInstructions)) {
|
|
32995
36680
|
files.push({
|
|
32996
|
-
filePath: copilotInstructions,
|
|
36681
|
+
filePath: (0,external_node_path_.join)(targetDir, copilotInstructions),
|
|
32997
36682
|
format: "copilot-instructions"
|
|
32998
36683
|
});
|
|
32999
36684
|
}
|
|
33000
36685
|
// .github/instructions/*.md
|
|
33001
|
-
const instructionsDir = (0,external_node_path_.join)(
|
|
33002
|
-
await this.discoverMdFilesInDir(instructionsDir, "copilot-scoped", files);
|
|
36686
|
+
const instructionsDir = (0,external_node_path_.join)(".github", "instructions");
|
|
36687
|
+
await this.discoverMdFilesInDir(targetDir, instructionsDir, "copilot-scoped", files);
|
|
33003
36688
|
// .github/agents/*.md
|
|
33004
|
-
const agentsDir = (0,external_node_path_.join)(
|
|
33005
|
-
await this.discoverMdFilesInDir(agentsDir, "copilot-agent", files);
|
|
36689
|
+
const agentsDir = (0,external_node_path_.join)(".github", "agents");
|
|
36690
|
+
await this.discoverMdFilesInDir(targetDir, agentsDir, "copilot-agent", files);
|
|
33006
36691
|
// AGENTS.md at repo root
|
|
33007
|
-
const agentsMd =
|
|
33008
|
-
if (await
|
|
36692
|
+
const agentsMd = "AGENTS.md";
|
|
36693
|
+
if (await this.safePathExists(targetDir, agentsMd)) {
|
|
33009
36694
|
files.push({
|
|
33010
|
-
filePath: agentsMd,
|
|
36695
|
+
filePath: (0,external_node_path_.join)(targetDir, agentsMd),
|
|
33011
36696
|
format: "agents-md"
|
|
33012
36697
|
});
|
|
33013
36698
|
}
|
|
33014
36699
|
// CLAUDE.md at repo root
|
|
33015
|
-
const claudeMd =
|
|
33016
|
-
if (await
|
|
36700
|
+
const claudeMd = "CLAUDE.md";
|
|
36701
|
+
if (await this.safePathExists(targetDir, claudeMd)) {
|
|
33017
36702
|
files.push({
|
|
33018
|
-
filePath: claudeMd,
|
|
36703
|
+
filePath: (0,external_node_path_.join)(targetDir, claudeMd),
|
|
33019
36704
|
format: "claude-md"
|
|
33020
36705
|
});
|
|
33021
36706
|
}
|
|
33022
36707
|
return files;
|
|
33023
36708
|
}
|
|
33024
|
-
async
|
|
33025
|
-
|
|
36709
|
+
async safePathExists(targetDir, relativePath) {
|
|
36710
|
+
try {
|
|
36711
|
+
return await file_system_utils_pathExistsWithinRoot(targetDir, relativePath);
|
|
36712
|
+
} catch {
|
|
36713
|
+
return false;
|
|
36714
|
+
}
|
|
36715
|
+
}
|
|
36716
|
+
async discoverMdFilesInDir(targetDir, dirPath, format, files) {
|
|
36717
|
+
if (!await this.safePathExists(targetDir, dirPath)) {
|
|
33026
36718
|
return;
|
|
33027
36719
|
}
|
|
33028
36720
|
try {
|
|
33029
|
-
const entries = await (
|
|
33030
|
-
|
|
33031
|
-
});
|
|
33032
|
-
const resolvedDirPath = (0,external_node_path_.resolve)(dirPath);
|
|
36721
|
+
const entries = await file_system_utils_listDirectoryWithinRoot(targetDir, dirPath);
|
|
36722
|
+
const resolvedDirPath = (0,external_node_path_.resolve)(targetDir, dirPath);
|
|
33033
36723
|
for (const entry of entries){
|
|
33034
36724
|
if (entry.isSymbolicLink()) {
|
|
33035
36725
|
continue;
|
|
@@ -33042,7 +36732,7 @@ function createWorkflowGateway(cwd) {
|
|
|
33042
36732
|
continue;
|
|
33043
36733
|
}
|
|
33044
36734
|
if (name.endsWith(".md")) {
|
|
33045
|
-
const filePath = (0,external_node_path_.join)(dirPath, name);
|
|
36735
|
+
const filePath = (0,external_node_path_.join)(targetDir, dirPath, name);
|
|
33046
36736
|
const resolvedFilePath = (0,external_node_path_.resolve)(filePath);
|
|
33047
36737
|
const rel = (0,external_node_path_.relative)(resolvedDirPath, resolvedFilePath);
|
|
33048
36738
|
if (rel.startsWith("..") || rel.startsWith(external_node_path_.sep)) {
|
|
@@ -33058,14 +36748,6 @@ function createWorkflowGateway(cwd) {
|
|
|
33058
36748
|
// Skip directory if we can't read it
|
|
33059
36749
|
}
|
|
33060
36750
|
}
|
|
33061
|
-
async isSymlink(filePath) {
|
|
33062
|
-
try {
|
|
33063
|
-
const stats = await (0,promises_.lstat)(filePath);
|
|
33064
|
-
return stats.isSymbolicLink();
|
|
33065
|
-
} catch {
|
|
33066
|
-
return false;
|
|
33067
|
-
}
|
|
33068
|
-
}
|
|
33069
36751
|
}
|
|
33070
36752
|
/**
|
|
33071
36753
|
* Creates and returns the default instruction file discovery gateway.
|
|
@@ -51906,12 +55588,12 @@ const remark = unified().use(remarkParse).use(remarkStringify).freeze()
|
|
|
51906
55588
|
*/
|
|
51907
55589
|
|
|
51908
55590
|
|
|
51909
|
-
/** Maximum instruction file size: 1 MB */ const
|
|
55591
|
+
/** Maximum instruction file size: 1 MB */ const markdown_ast_gateway_MAX_INSTRUCTION_FILE_BYTES = 1_048_576;
|
|
51910
55592
|
/**
|
|
51911
55593
|
* Remark-based implementation of the Markdown AST gateway.
|
|
51912
55594
|
*/ class RemarkMarkdownAstGateway {
|
|
51913
55595
|
async parseFile(filePath) {
|
|
51914
|
-
const content = await file_system_utils_readFileNoFollow(filePath,
|
|
55596
|
+
const content = await file_system_utils_readFileNoFollow(filePath, markdown_ast_gateway_MAX_INSTRUCTION_FILE_BYTES);
|
|
51915
55597
|
return this.parseContent(content);
|
|
51916
55598
|
}
|
|
51917
55599
|
parseContent(content) {
|
|
@@ -64368,4 +68050,4 @@ if (installedChunkData !== 0) { // 0 means "already installed".'
|
|
|
64368
68050
|
// module factories are used so entry inlining is disabled
|
|
64369
68051
|
// startup
|
|
64370
68052
|
// Load entry module and return exports
|
|
64371
|
-
var __webpack_exports__ = __webpack_require__(
|
|
68053
|
+
var __webpack_exports__ = __webpack_require__(2415);
|