@codelia/runtime 0.1.90 → 0.1.91
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/{chunk-QWJ4JW4T.js → chunk-EC2N4PCP.js} +3034 -1704
- package/dist/{chunk-DSYHEFZM.js → chunk-X4222JDX.js} +1486 -449
- package/dist/index.cjs +4434 -2099
- package/dist/index.js +2 -2
- package/dist/sdk.cjs +4842 -2504
- package/dist/sdk.d.cts +30 -3
- package/dist/sdk.d.ts +30 -3
- package/dist/sdk.js +4 -2
- package/dist/subagents/child-entry.cjs +589 -120
- package/dist/subagents/child-entry.js +1 -1
- package/package.json +12 -10
|
@@ -23,7 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
|
|
25
25
|
// src/subagents/child-entry.ts
|
|
26
|
-
var
|
|
26
|
+
var import_node_fs21 = require("fs");
|
|
27
27
|
|
|
28
28
|
// src/config.ts
|
|
29
29
|
var import_node_fs = require("fs");
|
|
@@ -3220,7 +3220,7 @@ var createChildChannel = (send3) => {
|
|
|
3220
3220
|
|
|
3221
3221
|
// src/subagents/child-runtime.ts
|
|
3222
3222
|
var import_node_crypto7 = require("crypto");
|
|
3223
|
-
var
|
|
3223
|
+
var import_node_fs20 = require("fs");
|
|
3224
3224
|
var import_core12 = require("@codelia/core");
|
|
3225
3225
|
var import_storage10 = require("@codelia/storage");
|
|
3226
3226
|
|
|
@@ -3525,21 +3525,26 @@ var createTaskProgressTracker = (options) => {
|
|
|
3525
3525
|
};
|
|
3526
3526
|
|
|
3527
3527
|
// src/subagents/read-tools.ts
|
|
3528
|
-
var
|
|
3529
|
-
var
|
|
3528
|
+
var import_node_fs19 = require("fs");
|
|
3529
|
+
var import_node_path20 = __toESM(require("path"), 1);
|
|
3530
3530
|
var import_core10 = require("@codelia/core");
|
|
3531
3531
|
var import_zod7 = require("zod");
|
|
3532
3532
|
|
|
3533
3533
|
// src/sandbox/context.ts
|
|
3534
3534
|
var import_node_crypto5 = __toESM(require("crypto"), 1);
|
|
3535
|
-
var
|
|
3536
|
-
var
|
|
3535
|
+
var import_node_fs17 = require("fs");
|
|
3536
|
+
var import_node_path18 = __toESM(require("path"), 1);
|
|
3537
3537
|
|
|
3538
3538
|
// src/permissions/git-metadata.ts
|
|
3539
3539
|
var import_node_fs5 = require("fs");
|
|
3540
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
3540
3541
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
3541
3542
|
var isMissing = (error) => error.code === "ENOENT";
|
|
3542
3543
|
var metadataPathSize = 16 * 1024;
|
|
3544
|
+
var gitConfigMaxBytes = 256 * 1024;
|
|
3545
|
+
var maxSymlinkHops = 64;
|
|
3546
|
+
var maxConfigDepth = 8;
|
|
3547
|
+
var maxConfigFiles = 32;
|
|
3543
3548
|
var readPointer = (filename, prefix) => {
|
|
3544
3549
|
const fd = (0, import_node_fs5.openSync)(
|
|
3545
3550
|
filename,
|
|
@@ -3641,6 +3646,7 @@ var eligibleObjectDirectory = (gitDirectory, commonDirectory, marker) => {
|
|
|
3641
3646
|
};
|
|
3642
3647
|
var discoverGitMetadata = (directories, includeObjectDirectories) => {
|
|
3643
3648
|
const readOnlyPaths = /* @__PURE__ */ new Set();
|
|
3649
|
+
const repositories = [];
|
|
3644
3650
|
const reservedMarkers = /* @__PURE__ */ new Set();
|
|
3645
3651
|
const objectDirectories = /* @__PURE__ */ new Map();
|
|
3646
3652
|
const hookAliases = /* @__PURE__ */ new Map();
|
|
@@ -3665,22 +3671,47 @@ var discoverGitMetadata = (directories, includeObjectDirectories) => {
|
|
|
3665
3671
|
readOnlyPaths.add(actual);
|
|
3666
3672
|
return actual;
|
|
3667
3673
|
};
|
|
3674
|
+
const rootDirectory = directories[0];
|
|
3675
|
+
const verifyLinkedWorktree = (gitDirectory, commonDirectory, actualMarker) => {
|
|
3676
|
+
try {
|
|
3677
|
+
if (gitDirectory === commonDirectory) return false;
|
|
3678
|
+
if (import_node_path4.default.dirname(gitDirectory) !== import_node_path4.default.join(commonDirectory, "worktrees"))
|
|
3679
|
+
return false;
|
|
3680
|
+
const backPointer = readPointer(import_node_path4.default.join(gitDirectory, "gitdir"), "");
|
|
3681
|
+
const resolvedBack = import_node_path4.default.resolve(gitDirectory, backPointer);
|
|
3682
|
+
const backStat = (0, import_node_fs5.lstatSync)(resolvedBack);
|
|
3683
|
+
if (backStat.isSymbolicLink() || !backStat.isFile()) return false;
|
|
3684
|
+
return (0, import_node_fs5.realpathSync)(import_node_path4.default.dirname(resolvedBack)) === import_node_path4.default.dirname(actualMarker) && (0, import_node_fs5.realpathSync)(resolvedBack) === actualMarker;
|
|
3685
|
+
} catch {
|
|
3686
|
+
return false;
|
|
3687
|
+
}
|
|
3688
|
+
};
|
|
3668
3689
|
for (const directory of new Set(directories)) {
|
|
3690
|
+
const fromRoot = directory === rootDirectory;
|
|
3669
3691
|
const marker = findMarker(directory);
|
|
3670
3692
|
const localMarker = import_node_path4.default.join(directory, ".git");
|
|
3671
3693
|
if (marker !== localMarker) reservedMarkers.add(localMarker);
|
|
3672
3694
|
if (!marker) continue;
|
|
3673
3695
|
if (readOnlyPaths.has(marker)) continue;
|
|
3696
|
+
const isWorkspaceRootRepo = fromRoot && marker === localMarker;
|
|
3697
|
+
const markerLstat = (0, import_node_fs5.lstatSync)(marker);
|
|
3674
3698
|
const actualMarker = (0, import_node_fs5.realpathSync)(marker);
|
|
3675
3699
|
readOnlyPaths.add(marker);
|
|
3676
3700
|
readOnlyPaths.add(actualMarker);
|
|
3677
3701
|
const markerInfo = (0, import_node_fs5.statSync)(actualMarker);
|
|
3678
|
-
const
|
|
3679
|
-
|
|
3702
|
+
const directoryEntries = [];
|
|
3703
|
+
let gitDirectory;
|
|
3704
|
+
if (markerInfo.isDirectory()) {
|
|
3705
|
+
gitDirectory = actualMarker;
|
|
3706
|
+
directoryEntries.push(marker, actualMarker);
|
|
3707
|
+
} else {
|
|
3708
|
+
const location = import_node_path4.default.resolve(
|
|
3680
3709
|
import_node_path4.default.dirname(marker),
|
|
3681
3710
|
readPointer(actualMarker, "gitdir: ")
|
|
3682
|
-
)
|
|
3683
|
-
|
|
3711
|
+
);
|
|
3712
|
+
gitDirectory = addDirectory(location);
|
|
3713
|
+
directoryEntries.push(location, gitDirectory);
|
|
3714
|
+
}
|
|
3684
3715
|
if (!(0, import_node_fs5.statSync)(import_node_path4.default.join(gitDirectory, "HEAD")).isFile())
|
|
3685
3716
|
throw new Error("invalid_git_metadata_directory");
|
|
3686
3717
|
const commonPointer = import_node_path4.default.join(gitDirectory, "commondir");
|
|
@@ -3690,19 +3721,34 @@ var discoverGitMetadata = (directories, includeObjectDirectories) => {
|
|
|
3690
3721
|
} catch (error) {
|
|
3691
3722
|
if (!isMissing(error)) throw error;
|
|
3692
3723
|
recordObjects(gitDirectory, gitDirectory, actualMarker);
|
|
3724
|
+
repositories.push({
|
|
3725
|
+
gitDirectory,
|
|
3726
|
+
commonDirectory: gitDirectory,
|
|
3727
|
+
worktreeRoot: import_node_path4.default.dirname(actualMarker),
|
|
3728
|
+
directoryEntries,
|
|
3729
|
+
writable: isWorkspaceRootRepo && markerLstat.isDirectory() && !markerLstat.isSymbolicLink()
|
|
3730
|
+
});
|
|
3693
3731
|
continue;
|
|
3694
3732
|
}
|
|
3695
3733
|
readOnlyPaths.add(commonPointer);
|
|
3696
3734
|
readOnlyPaths.add(common);
|
|
3697
|
-
const
|
|
3698
|
-
|
|
3699
|
-
);
|
|
3735
|
+
const commonLocation = import_node_path4.default.resolve(gitDirectory, readPointer(common, ""));
|
|
3736
|
+
const commonDirectory = addDirectory(commonLocation);
|
|
3737
|
+
directoryEntries.push(commonLocation, commonDirectory);
|
|
3700
3738
|
if (!(0, import_node_fs5.statSync)(import_node_path4.default.join(commonDirectory, "objects")).isDirectory())
|
|
3701
3739
|
throw new Error("invalid_git_common_directory");
|
|
3702
3740
|
recordObjects(gitDirectory, commonDirectory, actualMarker);
|
|
3741
|
+
repositories.push({
|
|
3742
|
+
gitDirectory,
|
|
3743
|
+
commonDirectory,
|
|
3744
|
+
worktreeRoot: import_node_path4.default.dirname(actualMarker),
|
|
3745
|
+
directoryEntries,
|
|
3746
|
+
writable: isWorkspaceRootRepo && markerLstat.isFile() && !markerLstat.isSymbolicLink() && verifyLinkedWorktree(gitDirectory, commonDirectory, actualMarker)
|
|
3747
|
+
});
|
|
3703
3748
|
}
|
|
3704
3749
|
return Object.freeze({
|
|
3705
3750
|
readOnlyPaths: Object.freeze([...readOnlyPaths].sort()),
|
|
3751
|
+
repositories: Object.freeze(repositories),
|
|
3706
3752
|
reservedMarkers: Object.freeze([...reservedMarkers].sort()),
|
|
3707
3753
|
objectDirectories: Object.freeze([...objectDirectories.values()]),
|
|
3708
3754
|
hookAliases: Object.freeze([...hookAliases.values()])
|
|
@@ -3717,10 +3763,395 @@ var resolveGitMetadata = (directories, includeObjectDirectories) => {
|
|
|
3717
3763
|
};
|
|
3718
3764
|
var gitMetadataPaths = (...directories) => resolveGitMetadata(directories, false);
|
|
3719
3765
|
var gitMetadataWithObjectDirectories = (...directories) => resolveGitMetadata(directories, true);
|
|
3766
|
+
var joinPreservingDotDot = (base, target) => {
|
|
3767
|
+
if (import_node_path4.default.isAbsolute(target)) return target;
|
|
3768
|
+
const separator = process.platform === "win32" ? import_node_path4.default.sep : "/";
|
|
3769
|
+
const trimmedBase = base.length > 1 && base.endsWith(separator) ? base.slice(0, -1) : base;
|
|
3770
|
+
return `${trimmedBase}${separator}${target}`;
|
|
3771
|
+
};
|
|
3772
|
+
var traceSymlinkHops = (target) => {
|
|
3773
|
+
const rawAbsolute = import_node_path4.default.isAbsolute(target) ? target : joinPreservingDotDot(process.cwd(), target);
|
|
3774
|
+
const root = import_node_path4.default.parse(rawAbsolute).root;
|
|
3775
|
+
const collected = /* @__PURE__ */ new Set([target, import_node_path4.default.resolve(rawAbsolute)]);
|
|
3776
|
+
let resolvedParts = [];
|
|
3777
|
+
let queue = rawAbsolute.slice(root.length).split(process.platform === "win32" ? /[\\/]/u : "/").filter(Boolean);
|
|
3778
|
+
let hops = 0;
|
|
3779
|
+
while (queue.length > 0) {
|
|
3780
|
+
const part = queue.shift();
|
|
3781
|
+
if (part === ".") continue;
|
|
3782
|
+
if (part === "..") {
|
|
3783
|
+
resolvedParts.pop();
|
|
3784
|
+
continue;
|
|
3785
|
+
}
|
|
3786
|
+
const candidate = import_node_path4.default.join(root, ...resolvedParts, part);
|
|
3787
|
+
const stat = (0, import_node_fs5.lstatSync)(candidate, { throwIfNoEntry: false });
|
|
3788
|
+
if (!stat) {
|
|
3789
|
+
if (queue.some((entry) => entry === ".."))
|
|
3790
|
+
throw new Error("reserved_path_unresolved");
|
|
3791
|
+
resolvedParts.push(part, ...queue.filter((entry) => entry !== "."));
|
|
3792
|
+
queue = [];
|
|
3793
|
+
break;
|
|
3794
|
+
}
|
|
3795
|
+
if (stat.isSymbolicLink()) {
|
|
3796
|
+
if (import_node_path4.default.dirname(candidate) !== root) collected.add(candidate);
|
|
3797
|
+
if (++hops > maxSymlinkHops) throw new Error("symlink_chain_too_deep");
|
|
3798
|
+
const referent = (0, import_node_fs5.readlinkSync)(candidate);
|
|
3799
|
+
const referentParts = referent.split(process.platform === "win32" ? /[\\/]/u : "/").filter(Boolean);
|
|
3800
|
+
if (import_node_path4.default.isAbsolute(referent)) resolvedParts = [];
|
|
3801
|
+
queue = [...referentParts, ...queue];
|
|
3802
|
+
continue;
|
|
3803
|
+
}
|
|
3804
|
+
resolvedParts.push(part);
|
|
3805
|
+
}
|
|
3806
|
+
collected.add(import_node_path4.default.join(root, ...resolvedParts));
|
|
3807
|
+
return [...collected];
|
|
3808
|
+
};
|
|
3809
|
+
var readBoundedTextFile = (filename) => {
|
|
3810
|
+
let fd;
|
|
3811
|
+
try {
|
|
3812
|
+
fd = (0, import_node_fs5.openSync)(filename, import_node_fs5.constants.O_RDONLY | (import_node_fs5.constants.O_NONBLOCK ?? 0));
|
|
3813
|
+
} catch (error) {
|
|
3814
|
+
if (isMissing(error)) return void 0;
|
|
3815
|
+
throw error;
|
|
3816
|
+
}
|
|
3817
|
+
try {
|
|
3818
|
+
const stat = (0, import_node_fs5.fstatSync)(fd);
|
|
3819
|
+
if (!stat.isFile() || stat.size > gitConfigMaxBytes)
|
|
3820
|
+
throw new Error("unreadable_git_config");
|
|
3821
|
+
const bytes = Buffer.alloc(stat.size + 1);
|
|
3822
|
+
const length = (0, import_node_fs5.readSync)(fd, bytes, 0, bytes.length, 0);
|
|
3823
|
+
if (length !== stat.size || length > gitConfigMaxBytes)
|
|
3824
|
+
throw new Error("unreadable_git_config");
|
|
3825
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(
|
|
3826
|
+
bytes.subarray(0, length)
|
|
3827
|
+
);
|
|
3828
|
+
} finally {
|
|
3829
|
+
(0, import_node_fs5.closeSync)(fd);
|
|
3830
|
+
}
|
|
3831
|
+
};
|
|
3832
|
+
var parseGitConfigValue = (raw) => {
|
|
3833
|
+
let result = "";
|
|
3834
|
+
let inQuotes = false;
|
|
3835
|
+
let pendingSpace = "";
|
|
3836
|
+
let i = 0;
|
|
3837
|
+
while (i < raw.length && (raw[i] === " " || raw[i] === " ")) i++;
|
|
3838
|
+
for (; i < raw.length; i++) {
|
|
3839
|
+
const ch = raw[i];
|
|
3840
|
+
if (ch === "\\") {
|
|
3841
|
+
if (i + 1 >= raw.length) {
|
|
3842
|
+
throw new Error("unsupported_git_config_continuation");
|
|
3843
|
+
}
|
|
3844
|
+
const next = raw[++i];
|
|
3845
|
+
if (pendingSpace) {
|
|
3846
|
+
result += pendingSpace;
|
|
3847
|
+
pendingSpace = "";
|
|
3848
|
+
}
|
|
3849
|
+
if (next === "n") result += "\n";
|
|
3850
|
+
else if (next === "t") result += " ";
|
|
3851
|
+
else if (next === "b") result += "\b";
|
|
3852
|
+
else if (next === '"' || next === "\\") result += next;
|
|
3853
|
+
else throw new Error("unsupported_git_config_escape");
|
|
3854
|
+
continue;
|
|
3855
|
+
}
|
|
3856
|
+
if (ch === '"') {
|
|
3857
|
+
if (pendingSpace && !inQuotes) {
|
|
3858
|
+
result += pendingSpace;
|
|
3859
|
+
pendingSpace = "";
|
|
3860
|
+
}
|
|
3861
|
+
inQuotes = !inQuotes;
|
|
3862
|
+
continue;
|
|
3863
|
+
}
|
|
3864
|
+
if (!inQuotes && (ch === "#" || ch === ";")) break;
|
|
3865
|
+
if (!inQuotes && (ch === " " || ch === " ")) {
|
|
3866
|
+
pendingSpace += ch;
|
|
3867
|
+
continue;
|
|
3868
|
+
}
|
|
3869
|
+
if (pendingSpace) {
|
|
3870
|
+
result += pendingSpace;
|
|
3871
|
+
pendingSpace = "";
|
|
3872
|
+
}
|
|
3873
|
+
result += ch;
|
|
3874
|
+
}
|
|
3875
|
+
if (inQuotes) throw new Error("unterminated_git_config_quote");
|
|
3876
|
+
return result;
|
|
3877
|
+
};
|
|
3878
|
+
var parseIrrelevantLineContinuation = (raw, initialInQuotes = false) => {
|
|
3879
|
+
let inQuotes = initialInQuotes;
|
|
3880
|
+
for (let i = 0; i < raw.length; i++) {
|
|
3881
|
+
const ch = raw[i];
|
|
3882
|
+
if (ch === "\\") {
|
|
3883
|
+
if (i + 1 >= raw.length) {
|
|
3884
|
+
return { continues: true, inQuotes };
|
|
3885
|
+
}
|
|
3886
|
+
i++;
|
|
3887
|
+
continue;
|
|
3888
|
+
}
|
|
3889
|
+
if (ch === '"') {
|
|
3890
|
+
inQuotes = !inQuotes;
|
|
3891
|
+
continue;
|
|
3892
|
+
}
|
|
3893
|
+
if (!inQuotes && (ch === "#" || ch === ";")) {
|
|
3894
|
+
return { continues: false, inQuotes: false };
|
|
3895
|
+
}
|
|
3896
|
+
}
|
|
3897
|
+
return { continues: false, inQuotes: false };
|
|
3898
|
+
};
|
|
3899
|
+
var expandGitHome = (value) => {
|
|
3900
|
+
if (value === "~") return import_node_os.default.homedir();
|
|
3901
|
+
if (value.startsWith("~/")) return import_node_path4.default.join(import_node_os.default.homedir(), value.slice(2));
|
|
3902
|
+
return value;
|
|
3903
|
+
};
|
|
3904
|
+
var collectGitConfigProtectedPaths = (configPath, worktreeRoot, seen, depth) => {
|
|
3905
|
+
if (depth > maxConfigDepth || seen.size >= maxConfigFiles)
|
|
3906
|
+
throw new Error("git_config_include_limit");
|
|
3907
|
+
let canonicalConfig = configPath;
|
|
3908
|
+
try {
|
|
3909
|
+
canonicalConfig = (0, import_node_fs5.realpathSync)(configPath);
|
|
3910
|
+
} catch (error) {
|
|
3911
|
+
if (isMissing(error)) return [];
|
|
3912
|
+
throw error;
|
|
3913
|
+
}
|
|
3914
|
+
const openedConfigDir = import_node_path4.default.dirname(configPath);
|
|
3915
|
+
const seenKey = `${openedConfigDir}\0${canonicalConfig}`;
|
|
3916
|
+
if (seen.has(seenKey)) return [];
|
|
3917
|
+
seen.add(seenKey);
|
|
3918
|
+
const content = readBoundedTextFile(canonicalConfig);
|
|
3919
|
+
if (content === void 0) return [];
|
|
3920
|
+
const results = [];
|
|
3921
|
+
const recordReferencedDirective = (directiveSection, rawValue) => {
|
|
3922
|
+
const parsed = parseGitConfigValue(rawValue);
|
|
3923
|
+
if (!parsed) throw new Error("empty_git_config_path");
|
|
3924
|
+
const expanded = expandGitHome(parsed);
|
|
3925
|
+
if (directiveSection === "core") {
|
|
3926
|
+
const bases2 = /* @__PURE__ */ new Set([
|
|
3927
|
+
...worktreeRoot ? [worktreeRoot] : [],
|
|
3928
|
+
openedConfigDir
|
|
3929
|
+
]);
|
|
3930
|
+
for (const base of bases2) {
|
|
3931
|
+
results.push({
|
|
3932
|
+
path: import_node_path4.default.isAbsolute(expanded) ? expanded : joinPreservingDotDot(base, expanded),
|
|
3933
|
+
kind: "hooks"
|
|
3934
|
+
});
|
|
3935
|
+
}
|
|
3936
|
+
return;
|
|
3937
|
+
}
|
|
3938
|
+
const target = import_node_path4.default.isAbsolute(expanded) ? expanded : joinPreservingDotDot(openedConfigDir, expanded);
|
|
3939
|
+
results.push({ path: target, kind: "config" });
|
|
3940
|
+
results.push(
|
|
3941
|
+
...collectGitConfigProtectedPaths(target, worktreeRoot, seen, depth + 1)
|
|
3942
|
+
);
|
|
3943
|
+
};
|
|
3944
|
+
let section = "";
|
|
3945
|
+
let continuingIrrelevantLine = false;
|
|
3946
|
+
let continuingIrrelevantQuotes = false;
|
|
3947
|
+
for (const rawLine of content.split(/\r?\n/u)) {
|
|
3948
|
+
const trimmed = rawLine.trim();
|
|
3949
|
+
if (continuingIrrelevantLine) {
|
|
3950
|
+
const state = parseIrrelevantLineContinuation(
|
|
3951
|
+
rawLine,
|
|
3952
|
+
continuingIrrelevantQuotes
|
|
3953
|
+
);
|
|
3954
|
+
continuingIrrelevantLine = state.continues;
|
|
3955
|
+
continuingIrrelevantQuotes = state.inQuotes;
|
|
3956
|
+
continue;
|
|
3957
|
+
}
|
|
3958
|
+
if (!trimmed || trimmed.startsWith("#") || trimmed.startsWith(";"))
|
|
3959
|
+
continue;
|
|
3960
|
+
if (trimmed.startsWith("[")) {
|
|
3961
|
+
const header = /^\[([A-Za-z0-9-]+)(?:\s+"(?:[^"\\]|\\.)*"|\.[A-Za-z0-9.-]+)?\s*\](.*)$/u.exec(
|
|
3962
|
+
trimmed
|
|
3963
|
+
);
|
|
3964
|
+
if (!header) throw new Error("unsupported_git_config_section");
|
|
3965
|
+
section = header[1].toLowerCase();
|
|
3966
|
+
const rest = header[2].trim();
|
|
3967
|
+
if (!rest || rest.startsWith("#") || rest.startsWith(";")) continue;
|
|
3968
|
+
const eq2 = rest.indexOf("=");
|
|
3969
|
+
if (eq2 < 0) continue;
|
|
3970
|
+
const key2 = rest.slice(0, eq2).trim().toLowerCase();
|
|
3971
|
+
const rawValue2 = rest.slice(eq2 + 1);
|
|
3972
|
+
if ((section === "include" || section === "includeif") && key2 === "path" || section === "core" && key2 === "hookspath") {
|
|
3973
|
+
recordReferencedDirective(section, rawValue2);
|
|
3974
|
+
} else {
|
|
3975
|
+
const state = parseIrrelevantLineContinuation(rawValue2);
|
|
3976
|
+
continuingIrrelevantLine = state.continues;
|
|
3977
|
+
continuingIrrelevantQuotes = state.inQuotes;
|
|
3978
|
+
}
|
|
3979
|
+
continue;
|
|
3980
|
+
}
|
|
3981
|
+
const eq = rawLine.indexOf("=");
|
|
3982
|
+
if (eq < 0) {
|
|
3983
|
+
const bareKey = trimmed.replace(/[#;].*$/u, "").trim().toLowerCase();
|
|
3984
|
+
if ((section === "include" || section === "includeif") && bareKey === "path" || section === "core" && bareKey === "hookspath")
|
|
3985
|
+
throw new Error("empty_git_config_path");
|
|
3986
|
+
continue;
|
|
3987
|
+
}
|
|
3988
|
+
const key = rawLine.slice(0, eq).trim().toLowerCase();
|
|
3989
|
+
const rawValue = rawLine.slice(eq + 1);
|
|
3990
|
+
if ((section === "include" || section === "includeif") && key === "path" || section === "core" && key === "hookspath") {
|
|
3991
|
+
recordReferencedDirective(section, rawValue);
|
|
3992
|
+
} else {
|
|
3993
|
+
const state = parseIrrelevantLineContinuation(rawValue);
|
|
3994
|
+
continuingIrrelevantLine = state.continues;
|
|
3995
|
+
continuingIrrelevantQuotes = state.inQuotes;
|
|
3996
|
+
}
|
|
3997
|
+
}
|
|
3998
|
+
return results;
|
|
3999
|
+
};
|
|
4000
|
+
var externalGitConfigFiles = () => {
|
|
4001
|
+
const files = /* @__PURE__ */ new Set();
|
|
4002
|
+
const home = import_node_os.default.homedir();
|
|
4003
|
+
const xdgConfigHome = process.env.XDG_CONFIG_HOME && import_node_path4.default.isAbsolute(process.env.XDG_CONFIG_HOME) ? process.env.XDG_CONFIG_HOME : import_node_path4.default.join(home, ".config");
|
|
4004
|
+
if (process.env.GIT_CONFIG_GLOBAL) {
|
|
4005
|
+
files.add(process.env.GIT_CONFIG_GLOBAL);
|
|
4006
|
+
} else {
|
|
4007
|
+
files.add(import_node_path4.default.join(home, ".gitconfig"));
|
|
4008
|
+
files.add(import_node_path4.default.join(xdgConfigHome, "git", "config"));
|
|
4009
|
+
}
|
|
4010
|
+
if (process.env.GIT_CONFIG_NOSYSTEM !== "1") {
|
|
4011
|
+
files.add(process.env.GIT_CONFIG_SYSTEM || "/etc/gitconfig");
|
|
4012
|
+
}
|
|
4013
|
+
return [...files];
|
|
4014
|
+
};
|
|
4015
|
+
var gitWriteScope = (repositories) => {
|
|
4016
|
+
const writeRoots = /* @__PURE__ */ new Set();
|
|
4017
|
+
const readOnly = /* @__PURE__ */ new Set();
|
|
4018
|
+
const released = /* @__PURE__ */ new Set();
|
|
4019
|
+
for (const {
|
|
4020
|
+
gitDirectory,
|
|
4021
|
+
commonDirectory,
|
|
4022
|
+
worktreeRoot,
|
|
4023
|
+
directoryEntries,
|
|
4024
|
+
writable
|
|
4025
|
+
} of repositories) {
|
|
4026
|
+
if (!writable) continue;
|
|
4027
|
+
const repoReadOnly = /* @__PURE__ */ new Set();
|
|
4028
|
+
const addProtected = (entry) => {
|
|
4029
|
+
for (const hop of traceSymlinkHops(entry)) repoReadOnly.add(hop);
|
|
4030
|
+
};
|
|
4031
|
+
const protectHooksDirectory = (hooksPath) => {
|
|
4032
|
+
addProtected(hooksPath);
|
|
4033
|
+
let resolvedHooks;
|
|
4034
|
+
try {
|
|
4035
|
+
const real = (0, import_node_fs5.realpathSync)(hooksPath);
|
|
4036
|
+
if ((0, import_node_fs5.statSync)(real).isDirectory()) resolvedHooks = real;
|
|
4037
|
+
} catch (error) {
|
|
4038
|
+
if (!["ENOENT", "ENOTDIR", "ELOOP", "EACCES", "EPERM"].includes(
|
|
4039
|
+
error.code ?? ""
|
|
4040
|
+
))
|
|
4041
|
+
throw error;
|
|
4042
|
+
}
|
|
4043
|
+
if (resolvedHooks) {
|
|
4044
|
+
for (const entry of (0, import_node_fs5.readdirSync)(resolvedHooks, {
|
|
4045
|
+
withFileTypes: true
|
|
4046
|
+
})) {
|
|
4047
|
+
if (entry.isSymbolicLink())
|
|
4048
|
+
addProtected(import_node_path4.default.join(resolvedHooks, entry.name));
|
|
4049
|
+
}
|
|
4050
|
+
}
|
|
4051
|
+
};
|
|
4052
|
+
try {
|
|
4053
|
+
const objectsDirectory = import_node_path4.default.join(commonDirectory, "objects");
|
|
4054
|
+
const objectsInfo = import_node_path4.default.join(objectsDirectory, "info");
|
|
4055
|
+
const configFiles = [
|
|
4056
|
+
import_node_path4.default.join(commonDirectory, "config"),
|
|
4057
|
+
import_node_path4.default.join(commonDirectory, "config.worktree"),
|
|
4058
|
+
import_node_path4.default.join(gitDirectory, "config.worktree")
|
|
4059
|
+
];
|
|
4060
|
+
for (const entry of [
|
|
4061
|
+
...configFiles,
|
|
4062
|
+
import_node_path4.default.join(commonDirectory, "hooks"),
|
|
4063
|
+
import_node_path4.default.join(commonDirectory, "commondir"),
|
|
4064
|
+
import_node_path4.default.join(gitDirectory, "commondir"),
|
|
4065
|
+
import_node_path4.default.join(gitDirectory, "gitdir"),
|
|
4066
|
+
...gitObjectStoreConfigPaths(objectsDirectory),
|
|
4067
|
+
import_node_path4.default.join(commonDirectory, "remotes"),
|
|
4068
|
+
import_node_path4.default.join(commonDirectory, "branches"),
|
|
4069
|
+
import_node_path4.default.join(commonDirectory, "modules"),
|
|
4070
|
+
// Rebase/sequencer todo files can contain `exec <cmd>` lines that
|
|
4071
|
+
// execute during a later unconfined `git rebase --continue`.
|
|
4072
|
+
import_node_path4.default.join(commonDirectory, "rebase-merge"),
|
|
4073
|
+
import_node_path4.default.join(commonDirectory, "rebase-apply"),
|
|
4074
|
+
import_node_path4.default.join(commonDirectory, "sequencer"),
|
|
4075
|
+
import_node_path4.default.join(gitDirectory, "rebase-merge"),
|
|
4076
|
+
import_node_path4.default.join(gitDirectory, "rebase-apply"),
|
|
4077
|
+
import_node_path4.default.join(gitDirectory, "sequencer")
|
|
4078
|
+
])
|
|
4079
|
+
addProtected(entry);
|
|
4080
|
+
if ((0, import_node_fs5.lstatSync)(objectsInfo, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
4081
|
+
const hops = traceSymlinkHops(objectsInfo);
|
|
4082
|
+
for (const hop of hops) repoReadOnly.add(hop);
|
|
4083
|
+
const targetInfo = hops[hops.length - 1];
|
|
4084
|
+
if (targetInfo) {
|
|
4085
|
+
addProtected(import_node_path4.default.join(targetInfo, "alternates"));
|
|
4086
|
+
addProtected(import_node_path4.default.join(targetInfo, "http-alternates"));
|
|
4087
|
+
}
|
|
4088
|
+
}
|
|
4089
|
+
protectHooksDirectory(import_node_path4.default.join(commonDirectory, "hooks"));
|
|
4090
|
+
const siblingConfigs = [];
|
|
4091
|
+
const worktrees = import_node_path4.default.join(commonDirectory, "worktrees");
|
|
4092
|
+
if ((0, import_node_fs5.lstatSync)(worktrees, { throwIfNoEntry: false })?.isDirectory()) {
|
|
4093
|
+
for (const entry of (0, import_node_fs5.readdirSync)(worktrees, { withFileTypes: true })) {
|
|
4094
|
+
if (!entry.isDirectory()) continue;
|
|
4095
|
+
const siblingDir = import_node_path4.default.join(worktrees, entry.name);
|
|
4096
|
+
for (const name of [
|
|
4097
|
+
"gitdir",
|
|
4098
|
+
"commondir",
|
|
4099
|
+
"config.worktree",
|
|
4100
|
+
"rebase-merge",
|
|
4101
|
+
"rebase-apply",
|
|
4102
|
+
"sequencer"
|
|
4103
|
+
])
|
|
4104
|
+
addProtected(import_node_path4.default.join(siblingDir, name));
|
|
4105
|
+
let siblingWorktreeRoot;
|
|
4106
|
+
try {
|
|
4107
|
+
const pointer = readPointer(import_node_path4.default.join(siblingDir, "gitdir"), "");
|
|
4108
|
+
siblingWorktreeRoot = import_node_path4.default.dirname(
|
|
4109
|
+
(0, import_node_fs5.realpathSync)(import_node_path4.default.resolve(siblingDir, pointer))
|
|
4110
|
+
);
|
|
4111
|
+
} catch {
|
|
4112
|
+
siblingWorktreeRoot = void 0;
|
|
4113
|
+
}
|
|
4114
|
+
siblingConfigs.push({
|
|
4115
|
+
file: import_node_path4.default.join(siblingDir, "config.worktree"),
|
|
4116
|
+
worktreeRoot: siblingWorktreeRoot
|
|
4117
|
+
});
|
|
4118
|
+
}
|
|
4119
|
+
}
|
|
4120
|
+
const seenConfigs = /* @__PURE__ */ new Set();
|
|
4121
|
+
const configSources = [
|
|
4122
|
+
...configFiles.map((file) => ({ file, worktreeRoot })),
|
|
4123
|
+
...siblingConfigs,
|
|
4124
|
+
...externalGitConfigFiles().map((file) => ({ file, worktreeRoot }))
|
|
4125
|
+
];
|
|
4126
|
+
for (const source of configSources) {
|
|
4127
|
+
for (const referenced of collectGitConfigProtectedPaths(
|
|
4128
|
+
source.file,
|
|
4129
|
+
source.worktreeRoot,
|
|
4130
|
+
seenConfigs,
|
|
4131
|
+
0
|
|
4132
|
+
)) {
|
|
4133
|
+
if (referenced.kind === "hooks")
|
|
4134
|
+
protectHooksDirectory(referenced.path);
|
|
4135
|
+
else addProtected(referenced.path);
|
|
4136
|
+
}
|
|
4137
|
+
}
|
|
4138
|
+
writeRoots.add(gitDirectory);
|
|
4139
|
+
writeRoots.add(commonDirectory);
|
|
4140
|
+
for (const entry of directoryEntries) released.add(entry);
|
|
4141
|
+
for (const entry of repoReadOnly) readOnly.add(entry);
|
|
4142
|
+
} catch {
|
|
4143
|
+
}
|
|
4144
|
+
}
|
|
4145
|
+
return Object.freeze({
|
|
4146
|
+
writeRoots: Object.freeze([...writeRoots].sort()),
|
|
4147
|
+
readOnlyPaths: Object.freeze([...readOnly].sort()),
|
|
4148
|
+
releasedPaths: Object.freeze([...released].sort())
|
|
4149
|
+
});
|
|
4150
|
+
};
|
|
3720
4151
|
|
|
3721
4152
|
// src/permissions/home-dot-paths.ts
|
|
3722
4153
|
var import_node_fs7 = require("fs");
|
|
3723
|
-
var
|
|
4154
|
+
var import_node_os2 = __toESM(require("os"), 1);
|
|
3724
4155
|
var import_node_path6 = __toESM(require("path"), 1);
|
|
3725
4156
|
|
|
3726
4157
|
// src/permissions/resource-paths.ts
|
|
@@ -3810,7 +4241,7 @@ function resolveReservedTarget(target, remaining = 64) {
|
|
|
3810
4241
|
}
|
|
3811
4242
|
|
|
3812
4243
|
// src/permissions/home-dot-paths.ts
|
|
3813
|
-
var homeDotDirectory = (writeRoots, home =
|
|
4244
|
+
var homeDotDirectory = (writeRoots, home = import_node_os2.default.homedir()) => {
|
|
3814
4245
|
if (!writeRoots.length) return void 0;
|
|
3815
4246
|
const canonicalHome = resolveReservedTarget(home);
|
|
3816
4247
|
return writeRoots.some(
|
|
@@ -3868,7 +4299,17 @@ function* linkedInodes(roots, entryLimit, ignoredObjectDirectories = [], verifie
|
|
|
3868
4299
|
try {
|
|
3869
4300
|
return (0, import_node_fs8.realpathSync)(entry);
|
|
3870
4301
|
} catch (error) {
|
|
3871
|
-
|
|
4302
|
+
const code = error.code;
|
|
4303
|
+
if (code === "ENOENT") return entry;
|
|
4304
|
+
if (code === "EOPNOTSUPP" || code === "ENXIO") {
|
|
4305
|
+
const info = (0, import_node_fs8.lstatSync)(entry, { throwIfNoEntry: false });
|
|
4306
|
+
if (info && !info.isSymbolicLink()) {
|
|
4307
|
+
return import_node_path7.default.join(
|
|
4308
|
+
(0, import_node_fs8.realpathSync)(import_node_path7.default.dirname(entry)),
|
|
4309
|
+
import_node_path7.default.basename(entry)
|
|
4310
|
+
);
|
|
4311
|
+
}
|
|
4312
|
+
}
|
|
3872
4313
|
throw error;
|
|
3873
4314
|
}
|
|
3874
4315
|
});
|
|
@@ -3895,7 +4336,8 @@ function* linkedInodes(roots, entryLimit, ignoredObjectDirectories = [], verifie
|
|
|
3895
4336
|
throw new Error("protected_alias_index_unavailable");
|
|
3896
4337
|
try {
|
|
3897
4338
|
const metadata = (0, import_node_fs8.lstatSync)(file, { bigint: true });
|
|
3898
|
-
if (metadata.isFile() && metadata.nlink > 1n)
|
|
4339
|
+
if ((metadata.isFile() || metadata.isSocket() || metadata.isFIFO()) && metadata.nlink > 1n)
|
|
4340
|
+
yield inode(metadata);
|
|
3899
4341
|
if (metadata.isSymbolicLink() && ignored.size) {
|
|
3900
4342
|
if (verifiedHook(file)) continue;
|
|
3901
4343
|
pending.push(...ignored);
|
|
@@ -3932,9 +4374,9 @@ var isProtectedAlias = (stat, paths) => stat.nlink > 1n && findProtectedAliases(
|
|
|
3932
4374
|
|
|
3933
4375
|
// src/permissions/shell-backend.ts
|
|
3934
4376
|
var import_node_child_process4 = require("child_process");
|
|
3935
|
-
var
|
|
3936
|
-
var
|
|
3937
|
-
var
|
|
4377
|
+
var import_node_fs16 = require("fs");
|
|
4378
|
+
var import_node_os5 = __toESM(require("os"), 1);
|
|
4379
|
+
var import_node_path17 = __toESM(require("path"), 1);
|
|
3938
4380
|
var import_storage9 = require("@codelia/storage");
|
|
3939
4381
|
|
|
3940
4382
|
// src/sandbox/file-mutation-helper.ts
|
|
@@ -3947,53 +4389,64 @@ var isWithin = (root, target) => {
|
|
|
3947
4389
|
return relative === "" || !import_node_path9.default.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${import_node_path9.default.sep}`);
|
|
3948
4390
|
};
|
|
3949
4391
|
|
|
3950
|
-
// src/permissions/linux-
|
|
3951
|
-
var
|
|
3952
|
-
var
|
|
3953
|
-
var
|
|
4392
|
+
// src/permissions/linux-mxc-backend.ts
|
|
4393
|
+
var import_node_fs12 = require("fs");
|
|
4394
|
+
var import_node_os3 = require("os");
|
|
4395
|
+
var import_node_path13 = __toESM(require("path"), 1);
|
|
3954
4396
|
|
|
3955
4397
|
// src/permissions/linux-mountinfo.ts
|
|
3956
4398
|
var import_node_fs9 = require("fs");
|
|
3957
4399
|
var import_node_path10 = __toESM(require("path"), 1);
|
|
3958
4400
|
|
|
4401
|
+
// src/permissions/mxc-launcher.ts
|
|
4402
|
+
var import_node_child_process2 = require("child_process");
|
|
4403
|
+
var import_node_fs10 = require("fs");
|
|
4404
|
+
var import_node_path11 = __toESM(require("path"), 1);
|
|
4405
|
+
var import_node_url = require("url");
|
|
4406
|
+
var import_meta = {};
|
|
4407
|
+
var MAX_MXC_FRAME_BYTES = 256 * 1024;
|
|
4408
|
+
var moduleDir = typeof __dirname === "string" ? __dirname : import_node_path11.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
4409
|
+
|
|
3959
4410
|
// src/permissions/shell-analysis.ts
|
|
3960
4411
|
var MAX_SOURCE_BYTES = 32 * 1024;
|
|
3961
4412
|
|
|
3962
4413
|
// src/permissions/shell-path.ts
|
|
3963
|
-
var
|
|
3964
|
-
var
|
|
4414
|
+
var import_node_fs11 = require("fs");
|
|
4415
|
+
var import_node_path12 = __toESM(require("path"), 1);
|
|
3965
4416
|
|
|
3966
|
-
// src/permissions/mxc-
|
|
4417
|
+
// src/permissions/linux-mxc-backend.ts
|
|
4418
|
+
var virtualRoots = ["/proc", "/dev", "/sys", "/run", "/var/run"];
|
|
4419
|
+
var MAX_FILESYSTEM_SPEC_BYTES = MAX_MXC_FRAME_BYTES - 16 * 1024;
|
|
4420
|
+
var disallowedExtraReadRoots = /* @__PURE__ */ new Set(["/", "/tmp", ...virtualRoots]);
|
|
4421
|
+
|
|
4422
|
+
// src/permissions/linux-shell-backend.ts
|
|
3967
4423
|
var import_node_child_process3 = require("child_process");
|
|
3968
|
-
var
|
|
3969
|
-
var
|
|
3970
|
-
var
|
|
3971
|
-
var import_meta = {};
|
|
3972
|
-
var packagePath = import_node_path13.default.join("node_modules", "@codelia", "tui-darwin-arm64");
|
|
3973
|
-
var moduleDir = typeof __dirname === "string" ? __dirname : import_node_path13.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
4424
|
+
var import_node_fs13 = require("fs");
|
|
4425
|
+
var import_node_os4 = require("os");
|
|
4426
|
+
var import_node_path14 = __toESM(require("path"), 1);
|
|
3974
4427
|
|
|
3975
4428
|
// src/permissions/system-bash.ts
|
|
3976
|
-
var
|
|
3977
|
-
var
|
|
4429
|
+
var import_node_fs14 = require("fs");
|
|
4430
|
+
var import_node_path15 = require("path");
|
|
3978
4431
|
|
|
3979
4432
|
// src/permissions/workspace-config-paths.ts
|
|
3980
|
-
var
|
|
3981
|
-
var
|
|
4433
|
+
var import_node_fs15 = require("fs");
|
|
4434
|
+
var import_node_path16 = __toESM(require("path"), 1);
|
|
3982
4435
|
var import_storage8 = require("@codelia/storage");
|
|
3983
4436
|
var confinedAutoLaunchDirectoryName = "confined-auto-launch";
|
|
3984
|
-
var isWorkspaceConfigName = (root, target) => resourceContainsPath(
|
|
4437
|
+
var isWorkspaceConfigName = (root, target) => resourceContainsPath(import_node_path16.default.dirname(resolveProjectConfigPath(root)), target);
|
|
3985
4438
|
var missing2 = (error) => error.code === "ENOENT";
|
|
3986
4439
|
function resolveConfigTarget(target, remaining = 64) {
|
|
3987
4440
|
if (!remaining) throw new Error("workspace_config_path_unresolved");
|
|
3988
4441
|
try {
|
|
3989
|
-
return (0,
|
|
4442
|
+
return (0, import_node_fs15.realpathSync)(target);
|
|
3990
4443
|
} catch (error) {
|
|
3991
|
-
const parent =
|
|
4444
|
+
const parent = import_node_path16.default.dirname(target);
|
|
3992
4445
|
if (!missing2(error) || parent === target) throw error;
|
|
3993
4446
|
const canonicalParent = resolveConfigTarget(parent, remaining - 1);
|
|
3994
|
-
if (!(0,
|
|
3995
|
-
return
|
|
3996
|
-
const referent = (0,
|
|
4447
|
+
if (!(0, import_node_fs15.lstatSync)(target, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
4448
|
+
return import_node_path16.default.join(canonicalParent, import_node_path16.default.basename(target));
|
|
4449
|
+
const referent = (0, import_node_fs15.readlinkSync)(target);
|
|
3997
4450
|
let seenName = false;
|
|
3998
4451
|
for (const part of referent.split(
|
|
3999
4452
|
process.platform === "win32" ? /[\\/]/u : "/"
|
|
@@ -4003,14 +4456,14 @@ function resolveConfigTarget(target, remaining = 64) {
|
|
|
4003
4456
|
if (part && part !== "." && part !== "..") seenName = true;
|
|
4004
4457
|
}
|
|
4005
4458
|
return resolveConfigTarget(
|
|
4006
|
-
|
|
4459
|
+
import_node_path16.default.resolve(canonicalParent, referent),
|
|
4007
4460
|
remaining - 1
|
|
4008
4461
|
);
|
|
4009
4462
|
}
|
|
4010
4463
|
}
|
|
4011
4464
|
var workspaceConfigProtection = (root) => {
|
|
4012
4465
|
const config = resolveProjectConfigPath(root);
|
|
4013
|
-
const directory =
|
|
4466
|
+
const directory = import_node_path16.default.dirname(config);
|
|
4014
4467
|
const readOnlyPaths = /* @__PURE__ */ new Set([directory]);
|
|
4015
4468
|
const readOnlyAliasPaths = /* @__PURE__ */ new Set();
|
|
4016
4469
|
const reserveTarget = (file) => {
|
|
@@ -4018,12 +4471,12 @@ var workspaceConfigProtection = (root) => {
|
|
|
4018
4471
|
readOnlyPaths.add(target);
|
|
4019
4472
|
readOnlyAliasPaths.add(target);
|
|
4020
4473
|
};
|
|
4021
|
-
if ((0,
|
|
4474
|
+
if ((0, import_node_fs15.lstatSync)(directory, { throwIfNoEntry: false })) {
|
|
4022
4475
|
const canonical = resolveConfigTarget(directory);
|
|
4023
4476
|
readOnlyPaths.add(canonical);
|
|
4024
|
-
if ((0,
|
|
4025
|
-
const file =
|
|
4026
|
-
if ((0,
|
|
4477
|
+
if ((0, import_node_fs15.lstatSync)(canonical, { throwIfNoEntry: false })?.isDirectory()) {
|
|
4478
|
+
const file = import_node_path16.default.join(canonical, import_node_path16.default.basename(config));
|
|
4479
|
+
if ((0, import_node_fs15.lstatSync)(file, { throwIfNoEntry: false })) reserveTarget(file);
|
|
4027
4480
|
const storage = (0, import_storage8.resolveStoragePaths)();
|
|
4028
4481
|
const globalStorage = [
|
|
4029
4482
|
(0, import_storage8.resolveStoragePaths)({ layout: "home" }).root,
|
|
@@ -4031,24 +4484,24 @@ var workspaceConfigProtection = (root) => {
|
|
|
4031
4484
|
storage.configDir
|
|
4032
4485
|
].some((entry) => {
|
|
4033
4486
|
try {
|
|
4034
|
-
return (0,
|
|
4487
|
+
return (0, import_node_fs15.realpathSync)(entry) === canonical;
|
|
4035
4488
|
} catch (error) {
|
|
4036
4489
|
if (!missing2(error)) throw error;
|
|
4037
4490
|
return false;
|
|
4038
4491
|
}
|
|
4039
4492
|
});
|
|
4040
4493
|
if (!globalStorage) {
|
|
4041
|
-
const worktrees =
|
|
4494
|
+
const worktrees = import_node_path16.default.join(canonical, "worktrees");
|
|
4042
4495
|
const pending = [canonical];
|
|
4043
4496
|
for (const current of pending) {
|
|
4044
|
-
const children = (0,
|
|
4497
|
+
const children = (0, import_node_fs15.opendirSync)(current);
|
|
4045
4498
|
try {
|
|
4046
4499
|
for (let entry = children.readSync(); entry; entry = children.readSync()) {
|
|
4047
|
-
const target =
|
|
4500
|
+
const target = import_node_path16.default.join(current, entry.name);
|
|
4048
4501
|
if (target === file || target === worktrees) continue;
|
|
4049
4502
|
if (entry.isSymbolicLink()) reserveTarget(target);
|
|
4050
4503
|
else if (entry.isDirectory()) pending.push(target);
|
|
4051
|
-
else if (entry.isFile() && ((0,
|
|
4504
|
+
else if (entry.isFile() && ((0, import_node_fs15.lstatSync)(target, { throwIfNoEntry: false })?.nlink ?? 0) > 1)
|
|
4052
4505
|
readOnlyAliasPaths.add(target);
|
|
4053
4506
|
}
|
|
4054
4507
|
} finally {
|
|
@@ -4067,27 +4520,27 @@ var workspaceConfigProtection = (root) => {
|
|
|
4067
4520
|
// src/permissions/shell-backend.ts
|
|
4068
4521
|
var realOrLexical = (value) => {
|
|
4069
4522
|
try {
|
|
4070
|
-
return (0,
|
|
4523
|
+
return (0, import_node_fs16.realpathSync)(value);
|
|
4071
4524
|
} catch {
|
|
4072
|
-
return
|
|
4525
|
+
return import_node_path17.default.resolve(value);
|
|
4073
4526
|
}
|
|
4074
4527
|
};
|
|
4075
4528
|
var resolvePolicyPath = (target) => {
|
|
4076
|
-
const absolute =
|
|
4529
|
+
const absolute = import_node_path17.default.resolve(target);
|
|
4077
4530
|
try {
|
|
4078
|
-
return (0,
|
|
4531
|
+
return (0, import_node_fs16.realpathSync)(absolute);
|
|
4079
4532
|
} catch (error) {
|
|
4080
|
-
const parent =
|
|
4533
|
+
const parent = import_node_path17.default.dirname(absolute);
|
|
4081
4534
|
if (error.code !== "ENOENT" || parent === absolute)
|
|
4082
4535
|
throw error;
|
|
4083
|
-
if ((0,
|
|
4536
|
+
if ((0, import_node_fs16.lstatSync)(absolute, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
4084
4537
|
throw error;
|
|
4085
|
-
return
|
|
4538
|
+
return import_node_path17.default.join(resolvePolicyPath(parent), import_node_path17.default.basename(absolute));
|
|
4086
4539
|
}
|
|
4087
4540
|
};
|
|
4088
4541
|
var canonicalPolicyPaths = (paths) => Object.freeze([
|
|
4089
4542
|
...new Set(
|
|
4090
|
-
paths.flatMap((entry) => [
|
|
4543
|
+
paths.flatMap((entry) => [import_node_path17.default.resolve(entry), resolvePolicyPath(entry)])
|
|
4091
4544
|
)
|
|
4092
4545
|
]);
|
|
4093
4546
|
var runtimeReadOnlyPaths = () => {
|
|
@@ -4104,15 +4557,15 @@ var runtimeProtectedCredentialPaths = () => {
|
|
|
4104
4557
|
const targets = [];
|
|
4105
4558
|
if (process.platform === "linux") {
|
|
4106
4559
|
try {
|
|
4107
|
-
(0,
|
|
4560
|
+
(0, import_node_fs16.mkdirSync)(storage.credentialsDir, { recursive: true, mode: 448 });
|
|
4108
4561
|
targets.push(storage.credentialsDir);
|
|
4109
4562
|
} catch {
|
|
4110
|
-
if ((0,
|
|
4563
|
+
if ((0, import_node_fs16.lstatSync)(storage.credentialsDir, { throwIfNoEntry: false })) {
|
|
4111
4564
|
targets.push(storage.credentialsDir);
|
|
4112
4565
|
}
|
|
4113
4566
|
}
|
|
4114
4567
|
for (const legacy of [storage.legacyAuthFile, storage.legacyMcpAuthFile]) {
|
|
4115
|
-
if ((0,
|
|
4568
|
+
if ((0, import_node_fs16.lstatSync)(legacy, { throwIfNoEntry: false })) {
|
|
4116
4569
|
targets.push(legacy);
|
|
4117
4570
|
}
|
|
4118
4571
|
}
|
|
@@ -4128,8 +4581,8 @@ var runtimeProtectedCredentialPaths = () => {
|
|
|
4128
4581
|
var runtimeAuthorityAliasPaths = () => {
|
|
4129
4582
|
const storage = (0, import_storage9.resolveStoragePaths)();
|
|
4130
4583
|
const databasePaths = [
|
|
4131
|
-
|
|
4132
|
-
|
|
4584
|
+
import_node_path17.default.join(storage.configDir, ".projects-policy-lock.sqlite"),
|
|
4585
|
+
import_node_path17.default.join(storage.sessionsDir, "state.db")
|
|
4133
4586
|
];
|
|
4134
4587
|
return canonicalPolicyPaths([
|
|
4135
4588
|
resolveConfigPath(),
|
|
@@ -4139,15 +4592,22 @@ var runtimeAuthorityAliasPaths = () => {
|
|
|
4139
4592
|
"launch-approvals",
|
|
4140
4593
|
"auto-review.json",
|
|
4141
4594
|
confinedAutoLaunchDirectoryName
|
|
4142
|
-
].map((entry) =>
|
|
4595
|
+
].map((entry) => import_node_path17.default.join(storage.configDir, entry)),
|
|
4143
4596
|
...databasePaths.flatMap(
|
|
4144
4597
|
(file) => ["", "-wal", "-shm", "-journal"].map((suffix) => `${file}${suffix}`)
|
|
4145
4598
|
)
|
|
4146
4599
|
]);
|
|
4147
4600
|
};
|
|
4148
4601
|
var workspacePathProtection = (root, extraProtectedPaths = [], relatedDirectories = [], sandboxMode = "workspace-write", allowSharedGitObjects = false, extraReadOnlyPaths = [], homeScope = {}) => {
|
|
4149
|
-
const discover = allowSharedGitObjects && sandboxMode === "workspace-write" ? gitMetadataWithObjectDirectories : gitMetadataPaths;
|
|
4150
|
-
const
|
|
4602
|
+
const discover = allowSharedGitObjects && sandboxMode === "workspace-write" && !homeScope.gitWrites ? gitMetadataWithObjectDirectories : gitMetadataPaths;
|
|
4603
|
+
const metadata = discover(root, ...relatedDirectories);
|
|
4604
|
+
const { reservedMarkers, objectDirectories, hookAliases } = metadata;
|
|
4605
|
+
const gitScope = homeScope.gitWrites ? gitWriteScope(metadata.repositories) : void 0;
|
|
4606
|
+
const released = new Set(gitScope?.releasedPaths ?? []);
|
|
4607
|
+
const readOnlyPaths = gitScope ? [
|
|
4608
|
+
...metadata.readOnlyPaths.filter((entry) => !released.has(entry)),
|
|
4609
|
+
...gitScope.readOnlyPaths
|
|
4610
|
+
] : metadata.readOnlyPaths;
|
|
4151
4611
|
const protectedPaths = canonicalPolicyPaths([
|
|
4152
4612
|
...extraProtectedPaths,
|
|
4153
4613
|
...runtimeProtectedCredentialPaths()
|
|
@@ -4173,14 +4633,23 @@ var workspacePathProtection = (root, extraProtectedPaths = [], relatedDirectorie
|
|
|
4173
4633
|
const objectDirectoriesWithSharedFiles = objectDirectories.filter(
|
|
4174
4634
|
(directory) => {
|
|
4175
4635
|
const overlaps = (other) => resourceContainsPath(other, directory.path) || resourceContainsPath(directory.path, other);
|
|
4176
|
-
const commonDirectory =
|
|
4636
|
+
const commonDirectory = import_node_path17.default.dirname(directory.path);
|
|
4177
4637
|
return !strongerPaths.some(overlaps) && !readOnlyPaths.some(
|
|
4178
4638
|
(other) => overlaps(other) && realOrLexical(other) !== commonDirectory
|
|
4179
4639
|
);
|
|
4180
4640
|
}
|
|
4181
4641
|
);
|
|
4642
|
+
const gitWriteRoots = (gitScope?.writeRoots ?? []).filter(
|
|
4643
|
+
(directory) => directory !== import_node_path17.default.parse(directory).root && !(homeScope.writeRoots ?? []).some((root2) => isWithin(root2, directory)) && !strongerPaths.some(
|
|
4644
|
+
(entry) => isWithin(entry, directory) || isWithin(directory, entry)
|
|
4645
|
+
)
|
|
4646
|
+
);
|
|
4182
4647
|
return {
|
|
4183
4648
|
...protectedHome ? { homeDotDirectory: protectedHome } : {},
|
|
4649
|
+
...gitScope && gitScope.releasedPaths.length > 0 ? {
|
|
4650
|
+
...gitWriteRoots.length ? { gitWriteRoots } : {},
|
|
4651
|
+
gitProtectedPaths: gitScope.readOnlyPaths
|
|
4652
|
+
} : {},
|
|
4184
4653
|
protectedPaths,
|
|
4185
4654
|
protectedAliasPaths: protectedPaths,
|
|
4186
4655
|
readOnlyPaths: Object.freeze(
|
|
@@ -4214,22 +4683,22 @@ var SecurityError = class extends Error {
|
|
|
4214
4683
|
var identity = (info) => `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`;
|
|
4215
4684
|
var directoryIdentity = (stat) => `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;
|
|
4216
4685
|
var selectMissingFile = (entry) => {
|
|
4217
|
-
let parent =
|
|
4686
|
+
let parent = import_node_path18.default.dirname(entry.target);
|
|
4218
4687
|
for (; ; ) {
|
|
4219
4688
|
try {
|
|
4220
|
-
const stat = (0,
|
|
4221
|
-
if (!stat.isDirectory() || (0,
|
|
4689
|
+
const stat = (0, import_node_fs17.lstatSync)(parent, { bigint: true });
|
|
4690
|
+
if (!stat.isDirectory() || (0, import_node_fs17.realpathSync)(parent) !== parent)
|
|
4222
4691
|
throw new SecurityError("Expected a canonical parent directory");
|
|
4223
4692
|
return Object.freeze({
|
|
4224
4693
|
...entry,
|
|
4225
4694
|
identity: null,
|
|
4226
4695
|
parent,
|
|
4227
4696
|
parentIdentity: directoryIdentity(stat),
|
|
4228
|
-
tail:
|
|
4697
|
+
tail: import_node_path18.default.relative(parent, entry.target)
|
|
4229
4698
|
});
|
|
4230
4699
|
} catch (error) {
|
|
4231
4700
|
if (error.code !== "ENOENT") throw error;
|
|
4232
|
-
const ancestor =
|
|
4701
|
+
const ancestor = import_node_path18.default.dirname(parent);
|
|
4233
4702
|
if (ancestor === parent) throw error;
|
|
4234
4703
|
parent = ancestor;
|
|
4235
4704
|
}
|
|
@@ -4237,15 +4706,15 @@ var selectMissingFile = (entry) => {
|
|
|
4237
4706
|
};
|
|
4238
4707
|
var missingDestinationCurrent = (selection) => {
|
|
4239
4708
|
try {
|
|
4240
|
-
const segments = selection.tail.split(
|
|
4709
|
+
const segments = selection.tail.split(import_node_path18.default.sep);
|
|
4241
4710
|
if (segments.some(
|
|
4242
4711
|
(segment) => !segment || segment === "." || segment === ".."
|
|
4243
|
-
) ||
|
|
4712
|
+
) || import_node_path18.default.join(selection.parent, selection.tail) !== selection.target || !directoryBindingCurrent(selection))
|
|
4244
4713
|
return false;
|
|
4245
4714
|
let current = selection.parent;
|
|
4246
4715
|
for (const [index, segment] of segments.entries()) {
|
|
4247
|
-
current =
|
|
4248
|
-
const stat = (0,
|
|
4716
|
+
current = import_node_path18.default.join(current, segment);
|
|
4717
|
+
const stat = (0, import_node_fs17.lstatSync)(current);
|
|
4249
4718
|
if (index === segments.length - 1 || !stat.isDirectory()) return false;
|
|
4250
4719
|
}
|
|
4251
4720
|
return false;
|
|
@@ -4255,8 +4724,8 @@ var missingDestinationCurrent = (selection) => {
|
|
|
4255
4724
|
};
|
|
4256
4725
|
var directoryBindingCurrent = (selection) => {
|
|
4257
4726
|
try {
|
|
4258
|
-
const stat = (0,
|
|
4259
|
-
return stat.isDirectory() && directoryIdentity(stat) === selection.parentIdentity && (0,
|
|
4727
|
+
const stat = (0, import_node_fs17.lstatSync)(selection.parent, { bigint: true });
|
|
4728
|
+
return stat.isDirectory() && directoryIdentity(stat) === selection.parentIdentity && (0, import_node_fs17.realpathSync)(selection.parent) === selection.parent;
|
|
4260
4729
|
} catch {
|
|
4261
4730
|
return false;
|
|
4262
4731
|
}
|
|
@@ -4290,10 +4759,10 @@ var SandboxContext = class _SandboxContext {
|
|
|
4290
4759
|
}
|
|
4291
4760
|
static async create(rootDir, options = {}) {
|
|
4292
4761
|
const sessionId = import_node_crypto5.default.randomUUID().slice(0, 8);
|
|
4293
|
-
const root = rootDir ?
|
|
4762
|
+
const root = rootDir ? import_node_path18.default.resolve(rootDir) : process.cwd();
|
|
4294
4763
|
if (options.sandboxMode !== "readonly")
|
|
4295
|
-
await
|
|
4296
|
-
const directory = options.protectResources ? await
|
|
4764
|
+
await import_node_fs17.promises.mkdir(root, { recursive: true });
|
|
4765
|
+
const directory = options.protectResources ? await import_node_fs17.promises.realpath(root) : root;
|
|
4297
4766
|
return new _SandboxContext({
|
|
4298
4767
|
rootDir: directory,
|
|
4299
4768
|
workingDir: directory,
|
|
@@ -4315,7 +4784,7 @@ var SandboxContext = class _SandboxContext {
|
|
|
4315
4784
|
resolvePath(targetPath, access = "write") {
|
|
4316
4785
|
if (access === "write" && this.sandboxMode === "readonly")
|
|
4317
4786
|
throw new SecurityError("Sandbox mode is readonly");
|
|
4318
|
-
const resolved =
|
|
4787
|
+
const resolved = import_node_path18.default.isAbsolute(targetPath) ? import_node_path18.default.resolve(targetPath) : import_node_path18.default.resolve(this.workingDir, targetPath);
|
|
4319
4788
|
if (this.protectedPaths) return this.resolveProtectedPath(resolved, access);
|
|
4320
4789
|
if (this.approvalMode === "full-access") {
|
|
4321
4790
|
return resolved;
|
|
@@ -4333,12 +4802,12 @@ var SandboxContext = class _SandboxContext {
|
|
|
4333
4802
|
selectFile(operand, access, directoryEntry = false) {
|
|
4334
4803
|
const target = this.resolvePath(operand, access);
|
|
4335
4804
|
if (directoryEntry) {
|
|
4336
|
-
const lexical =
|
|
4337
|
-
const name =
|
|
4338
|
-
resolvePolicyPath(
|
|
4339
|
-
|
|
4805
|
+
const lexical = import_node_path18.default.resolve(this.workingDir, operand);
|
|
4806
|
+
const name = import_node_path18.default.join(
|
|
4807
|
+
resolvePolicyPath(import_node_path18.default.dirname(lexical)),
|
|
4808
|
+
import_node_path18.default.basename(lexical)
|
|
4340
4809
|
);
|
|
4341
|
-
if (target !== name || (0,
|
|
4810
|
+
if (target !== name || (0, import_node_fs17.lstatSync)(name, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
4342
4811
|
throw new SecurityError(
|
|
4343
4812
|
"Patch deletion and move require a regular directory entry without a symbolic link"
|
|
4344
4813
|
);
|
|
@@ -4350,7 +4819,7 @@ var SandboxContext = class _SandboxContext {
|
|
|
4350
4819
|
...directoryEntry ? { directoryEntry: true } : {}
|
|
4351
4820
|
};
|
|
4352
4821
|
try {
|
|
4353
|
-
const info = (0,
|
|
4822
|
+
const info = (0, import_node_fs17.lstatSync)(target, { bigint: true });
|
|
4354
4823
|
if (!info.isFile())
|
|
4355
4824
|
throw new SecurityError("Expected a regular file for this operation");
|
|
4356
4825
|
return Object.freeze({
|
|
@@ -4398,8 +4867,8 @@ var SandboxContext = class _SandboxContext {
|
|
|
4398
4867
|
error.code = "ENOENT";
|
|
4399
4868
|
throw error;
|
|
4400
4869
|
}
|
|
4401
|
-
const flags = (mode === "read" ?
|
|
4402
|
-
const handle = await
|
|
4870
|
+
const flags = (mode === "read" ? import_node_fs17.constants.O_RDONLY : import_node_fs17.constants.O_RDWR) | (import_node_fs17.constants.O_NOFOLLOW ?? 0) | (import_node_fs17.constants.O_NONBLOCK ?? 0);
|
|
4871
|
+
const handle = await import_node_fs17.promises.open(selected.target, flags);
|
|
4403
4872
|
try {
|
|
4404
4873
|
const opened = await handle.stat({ bigint: true });
|
|
4405
4874
|
if (!opened.isFile() || identity(opened) !== selected.identity || isProtectedAlias(
|
|
@@ -4492,7 +4961,7 @@ var SandboxContext = class _SandboxContext {
|
|
|
4492
4961
|
writeProtection(target, alias = false) {
|
|
4493
4962
|
const { readOnlyPaths } = gitMetadataPaths(
|
|
4494
4963
|
this.rootDir,
|
|
4495
|
-
|
|
4964
|
+
import_node_path18.default.dirname(target)
|
|
4496
4965
|
);
|
|
4497
4966
|
const projectConfig = workspaceConfigProtection(this.rootDir);
|
|
4498
4967
|
return [
|
|
@@ -4524,16 +4993,16 @@ var SandboxContext = class _SandboxContext {
|
|
|
4524
4993
|
let probe = resolved;
|
|
4525
4994
|
for (; ; ) {
|
|
4526
4995
|
try {
|
|
4527
|
-
const actual = (0,
|
|
4528
|
-
const target =
|
|
4996
|
+
const actual = (0, import_node_fs17.realpathSync)(probe);
|
|
4997
|
+
const target = import_node_path18.default.resolve(actual, import_node_path18.default.relative(probe, resolved));
|
|
4529
4998
|
rejectProtected(target);
|
|
4530
4999
|
if (target !== resolved) rejectWrite(target);
|
|
4531
5000
|
if (probe === resolved) {
|
|
4532
|
-
const stat = (0,
|
|
5001
|
+
const stat = (0, import_node_fs17.lstatSync)(target);
|
|
4533
5002
|
if (!stat.isFile() && !stat.isDirectory())
|
|
4534
5003
|
throw new SecurityError("Unsupported file type");
|
|
4535
5004
|
if (stat.isFile() && stat.nlink > 1) {
|
|
4536
|
-
const inode2 = (0,
|
|
5005
|
+
const inode2 = (0, import_node_fs17.lstatSync)(target, { bigint: true });
|
|
4537
5006
|
if (isProtectedAlias(inode2, protectedPaths))
|
|
4538
5007
|
throw new SecurityError("Path aliases a protected file");
|
|
4539
5008
|
if (access === "write" && this.isReadOnlyAlias(inode2, target))
|
|
@@ -4543,10 +5012,10 @@ var SandboxContext = class _SandboxContext {
|
|
|
4543
5012
|
return target;
|
|
4544
5013
|
} catch (error) {
|
|
4545
5014
|
if (error.code !== "ENOENT") throw error;
|
|
4546
|
-
const ancestor =
|
|
5015
|
+
const ancestor = import_node_path18.default.dirname(probe);
|
|
4547
5016
|
if (ancestor === probe) throw error;
|
|
4548
5017
|
try {
|
|
4549
|
-
if ((0,
|
|
5018
|
+
if ((0, import_node_fs17.lstatSync)(probe).isSymbolicLink())
|
|
4550
5019
|
throw new SecurityError("Path contains a dangling symlink");
|
|
4551
5020
|
} catch (entryError) {
|
|
4552
5021
|
if (entryError.code !== "ENOENT")
|
|
@@ -4574,8 +5043,8 @@ var appendReadMetadata = (output, content) => `${output}
|
|
|
4574
5043
|
[read_metadata] content_sha256=${hashUtf8Content(content)}`;
|
|
4575
5044
|
|
|
4576
5045
|
// src/subagents/workspace-files.ts
|
|
4577
|
-
var
|
|
4578
|
-
var
|
|
5046
|
+
var import_node_fs18 = require("fs");
|
|
5047
|
+
var import_node_path19 = __toESM(require("path"), 1);
|
|
4579
5048
|
var MAX_CHILD_FILE_BYTES = 4 * 1024 * 1024;
|
|
4580
5049
|
var readContent = async (handle) => {
|
|
4581
5050
|
const buffer = Buffer.alloc(MAX_CHILD_FILE_BYTES + 1);
|
|
@@ -4602,17 +5071,17 @@ var createWorkspaceFiles = (root, extraProtectedPaths, extraReadOnlyPaths) => {
|
|
|
4602
5071
|
);
|
|
4603
5072
|
const blocked = (target) => protectedPaths.some((entry) => resourceContainsPath(entry, target));
|
|
4604
5073
|
const resolve = async (name, allowMissing = false) => {
|
|
4605
|
-
const candidate =
|
|
5074
|
+
const candidate = import_node_path19.default.resolve(root, name);
|
|
4606
5075
|
if (blocked(candidate))
|
|
4607
5076
|
throw new Error("Path is protected by the resource policy");
|
|
4608
|
-
const relative =
|
|
4609
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
5077
|
+
const relative = import_node_path19.default.relative(root, candidate);
|
|
5078
|
+
if (relative === ".." || relative.startsWith(`..${import_node_path19.default.sep}`) || import_node_path19.default.isAbsolute(relative))
|
|
4610
5079
|
throw new Error("Path outside delegated workspace");
|
|
4611
5080
|
let part = root;
|
|
4612
|
-
for (const segment of relative.split(
|
|
4613
|
-
part =
|
|
5081
|
+
for (const segment of relative.split(import_node_path19.default.sep).filter(Boolean)) {
|
|
5082
|
+
part = import_node_path19.default.join(part, segment);
|
|
4614
5083
|
try {
|
|
4615
|
-
if ((await
|
|
5084
|
+
if ((await import_node_fs18.promises.lstat(part)).isSymbolicLink())
|
|
4616
5085
|
throw new Error(
|
|
4617
5086
|
"Symbolic links are not available to delegated tools"
|
|
4618
5087
|
);
|
|
@@ -4650,7 +5119,7 @@ var createWorkspaceFiles = (root, extraProtectedPaths, extraReadOnlyPaths) => {
|
|
|
4650
5119
|
const file = await resolve(name, expected === "missing");
|
|
4651
5120
|
const repositoryReadOnly = gitMetadataPaths(
|
|
4652
5121
|
root,
|
|
4653
|
-
|
|
5122
|
+
import_node_path19.default.dirname(file)
|
|
4654
5123
|
).readOnlyPaths;
|
|
4655
5124
|
const projectConfig = workspaceConfigProtection(root);
|
|
4656
5125
|
if (homeDotDirectory2 && isHomeWriteReserved(homeDotDirectory2, file) || isWorkspaceConfigName(root, file) || [
|
|
@@ -4668,17 +5137,17 @@ var createWorkspaceFiles = (root, extraProtectedPaths, extraReadOnlyPaths) => {
|
|
|
4668
5137
|
await approval.bound.writeSelectedFile(name, value);
|
|
4669
5138
|
return hashUtf8Content(value);
|
|
4670
5139
|
}
|
|
4671
|
-
if (approval && (!selection?.identity || selection.target !== await
|
|
5140
|
+
if (approval && (!selection?.identity || selection.target !== await import_node_fs18.promises.realpath(file)))
|
|
4672
5141
|
throw new Error("File selection changed after approval");
|
|
4673
5142
|
if (approval && expected === "missing")
|
|
4674
5143
|
throw new Error("File already exists");
|
|
4675
5144
|
if (expected === "missing") {
|
|
4676
|
-
await
|
|
5145
|
+
await import_node_fs18.promises.mkdir(import_node_path19.default.dirname(file), { recursive: true });
|
|
4677
5146
|
await resolve(name, true);
|
|
4678
5147
|
}
|
|
4679
|
-
const handle = await
|
|
5148
|
+
const handle = await import_node_fs18.promises.open(
|
|
4680
5149
|
file,
|
|
4681
|
-
expected === "missing" ? "wx" :
|
|
5150
|
+
expected === "missing" ? "wx" : import_node_fs18.constants.O_RDWR | (import_node_fs18.constants.O_NOFOLLOW ?? 0)
|
|
4682
5151
|
);
|
|
4683
5152
|
try {
|
|
4684
5153
|
const stat = await handle.stat({ bigint: true });
|
|
@@ -4754,7 +5223,7 @@ var clipJsonString = (text, limit) => {
|
|
|
4754
5223
|
var createSubagentReadTools = (root, protectedPaths, options = {}) => {
|
|
4755
5224
|
const permits = options.permits ?? (() => true);
|
|
4756
5225
|
const resolveWorkspace = async () => {
|
|
4757
|
-
const sandbox = await SandboxContext.create(await
|
|
5226
|
+
const sandbox = await SandboxContext.create(await import_node_fs19.promises.realpath(root), {
|
|
4758
5227
|
protectResources: true,
|
|
4759
5228
|
extraProtectedPaths: protectedPaths
|
|
4760
5229
|
});
|
|
@@ -4782,17 +5251,17 @@ var createSubagentReadTools = (root, protectedPaths, options = {}) => {
|
|
|
4782
5251
|
signal?.throwIfAborted();
|
|
4783
5252
|
const dir = pending.shift();
|
|
4784
5253
|
if (!dir) break;
|
|
4785
|
-
const entries = await
|
|
5254
|
+
const entries = await import_node_fs19.promises.opendir(await resolve(import_node_path20.default.relative(root2, dir)));
|
|
4786
5255
|
for await (const entry of entries) {
|
|
4787
5256
|
if (entry.isSymbolicLink() || entry.name === ".git" || entry.name === "node_modules")
|
|
4788
5257
|
continue;
|
|
4789
|
-
const child =
|
|
5258
|
+
const child = import_node_path20.default.join(dir, entry.name);
|
|
4790
5259
|
if (blocked(child)) continue;
|
|
4791
5260
|
if (entry.isDirectory()) {
|
|
4792
5261
|
if (pending.length >= 2e3) return { paths, truncated: true };
|
|
4793
5262
|
pending.push(child);
|
|
4794
5263
|
} else if (entry.isFile()) {
|
|
4795
|
-
const name =
|
|
5264
|
+
const name = import_node_path20.default.relative(root2, child);
|
|
4796
5265
|
const selected = await selectRead(name, sandbox).catch(
|
|
4797
5266
|
() => void 0
|
|
4798
5267
|
);
|
|
@@ -5023,7 +5492,7 @@ var createSubagentWriteTools = (root, channel, protection, protectedPaths) => {
|
|
|
5023
5492
|
|
|
5024
5493
|
// src/subagents/child-runtime.ts
|
|
5025
5494
|
var createChildRun = async (input, llm, options = {}) => {
|
|
5026
|
-
const workspace = await
|
|
5495
|
+
const workspace = await import_node_fs20.promises.realpath(input.workspace_root);
|
|
5027
5496
|
const session_id = (0, import_node_crypto7.randomUUID)();
|
|
5028
5497
|
const run_id = (0, import_node_crypto7.randomUUID)();
|
|
5029
5498
|
const sessions = options.sessions ?? new import_storage10.SessionStateStoreImpl();
|
|
@@ -5247,7 +5716,7 @@ var createChildRun = async (input, llm, options = {}) => {
|
|
|
5247
5716
|
};
|
|
5248
5717
|
|
|
5249
5718
|
// src/subagents/child-entry.ts
|
|
5250
|
-
var bootstrap = (0,
|
|
5719
|
+
var bootstrap = (0, import_node_fs21.createReadStream)("", { fd: 3, autoClose: false });
|
|
5251
5720
|
bootstrap.setEncoding("utf8");
|
|
5252
5721
|
var controller = new AbortController();
|
|
5253
5722
|
var exitTimer;
|