@codelia/runtime 0.1.89 → 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-LNUGYGST.js → chunk-EC2N4PCP.js} +3628 -2238
- package/dist/{chunk-NPCH2IMV.js → chunk-X4222JDX.js} +1644 -540
- package/dist/index.cjs +5241 -2786
- package/dist/index.js +2 -2
- package/dist/sdk.cjs +7567 -5109
- 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 +653 -137
- 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");
|
|
@@ -47,6 +47,7 @@ var resolveConfigPath = () => {
|
|
|
47
47
|
return storage.resolvePaths().configFile;
|
|
48
48
|
};
|
|
49
49
|
var resolveProjectConfigPath = (workingDir) => import_node_path.default.resolve(workingDir, ".codelia", "config.json");
|
|
50
|
+
var normalizeModelLevel = (value) => value.trim().toLowerCase();
|
|
50
51
|
var resolveReasoningEffort = (value) => {
|
|
51
52
|
return resolveModelLevelOption(value, "model.reasoning", {
|
|
52
53
|
allowXhigh: true
|
|
@@ -59,7 +60,7 @@ var resolveTextVerbosity = (value) => {
|
|
|
59
60
|
};
|
|
60
61
|
function resolveModelLevelOption(value, fieldName, options) {
|
|
61
62
|
if (!value) return void 0;
|
|
62
|
-
const normalized = value
|
|
63
|
+
const normalized = normalizeModelLevel(value);
|
|
63
64
|
if (normalized === "low" || normalized === "medium" || normalized === "high") {
|
|
64
65
|
return normalized;
|
|
65
66
|
}
|
|
@@ -71,15 +72,16 @@ function resolveModelLevelOption(value, fieldName, options) {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
// src/rpc/ui-requests.ts
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
// src/rpc/transport.ts
|
|
77
|
-
var import_node_async_hooks = require("async_hooks");
|
|
75
|
+
var import_protocol3 = require("@codelia/protocol");
|
|
78
76
|
|
|
79
77
|
// src/logger.ts
|
|
80
78
|
var import_logger = require("@codelia/logger");
|
|
81
79
|
|
|
80
|
+
// src/rpc/protocol.ts
|
|
81
|
+
var import_protocol2 = require("@codelia/protocol");
|
|
82
|
+
|
|
82
83
|
// src/rpc/transport.ts
|
|
84
|
+
var import_node_async_hooks = require("async_hooks");
|
|
83
85
|
var responseContext = new import_node_async_hooks.AsyncLocalStorage();
|
|
84
86
|
var describeRpcMessage = (msg) => {
|
|
85
87
|
if ("method" in msg && typeof msg.method === "string") {
|
|
@@ -110,16 +112,47 @@ var send = (msg) => {
|
|
|
110
112
|
}
|
|
111
113
|
};
|
|
112
114
|
|
|
115
|
+
// src/rpc/protocol.ts
|
|
116
|
+
var MAX_ISSUES = 10;
|
|
117
|
+
var describeIssues = (error) => error.issues.slice(0, MAX_ISSUES).map((issue) => ({
|
|
118
|
+
path: issue.path.map(String).join("."),
|
|
119
|
+
code: issue.code,
|
|
120
|
+
message: issue.message
|
|
121
|
+
}));
|
|
122
|
+
var schemaFor = (method, slot) => {
|
|
123
|
+
const spec = import_protocol2.protocolMethods[method];
|
|
124
|
+
if (slot === "params") return spec.params;
|
|
125
|
+
if (!("result" in spec))
|
|
126
|
+
throw new Error(`${method} is a notification without a result`);
|
|
127
|
+
return spec.result;
|
|
128
|
+
};
|
|
129
|
+
var assertOutgoing = (method, slot, value) => {
|
|
130
|
+
if (process.env.CODELIA_PROTOCOL_ASSERT !== "1") return;
|
|
131
|
+
const result = schemaFor(method, slot).safeParse(value);
|
|
132
|
+
if (!result.success)
|
|
133
|
+
throw new Error(
|
|
134
|
+
`protocol assertion failed for ${method} ${slot}: ${JSON.stringify(describeIssues(result.error))}`
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
var notificationMessage = (method, params) => {
|
|
138
|
+
assertOutgoing(method, "params", params);
|
|
139
|
+
return { jsonrpc: "2.0", method, params };
|
|
140
|
+
};
|
|
141
|
+
var requestMessage = (method, id, params) => {
|
|
142
|
+
assertOutgoing(method, "params", params);
|
|
143
|
+
return { jsonrpc: "2.0", id, method, params };
|
|
144
|
+
};
|
|
145
|
+
var parseUiResult = (method, raw) => {
|
|
146
|
+
const result = schemaFor(method, "result").safeParse(raw);
|
|
147
|
+
if (result.success) return { ok: true, result: result.data };
|
|
148
|
+
return { ok: false, issues: describeIssues(result.error) };
|
|
149
|
+
};
|
|
150
|
+
|
|
113
151
|
// src/rpc/ui-requests.ts
|
|
114
152
|
var requestUi = async (state, method, params, signal) => {
|
|
115
153
|
if (signal?.aborted) return null;
|
|
116
154
|
const id = state.nextUiRequestId();
|
|
117
|
-
const request =
|
|
118
|
-
jsonrpc: "2.0",
|
|
119
|
-
id,
|
|
120
|
-
method,
|
|
121
|
-
params
|
|
122
|
-
};
|
|
155
|
+
const request = requestMessage(method, id, params);
|
|
123
156
|
const response = state.waitForUiResponse(id);
|
|
124
157
|
let sent = false;
|
|
125
158
|
const abort = () => {
|
|
@@ -127,13 +160,12 @@ var requestUi = async (state, method, params, signal) => {
|
|
|
127
160
|
jsonrpc: "2.0",
|
|
128
161
|
id,
|
|
129
162
|
error: {
|
|
130
|
-
code:
|
|
163
|
+
code: import_protocol3.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
131
164
|
message: "UI request cancelled"
|
|
132
165
|
}
|
|
133
166
|
});
|
|
134
|
-
if (cancelled
|
|
135
|
-
|
|
136
|
-
}
|
|
167
|
+
if (!cancelled || !sent || method !== "ui.pick.request") return;
|
|
168
|
+
send(notificationMessage("ui.pick.cancelled", { id }));
|
|
137
169
|
};
|
|
138
170
|
signal?.addEventListener("abort", abort, { once: true });
|
|
139
171
|
try {
|
|
@@ -142,7 +174,12 @@ var requestUi = async (state, method, params, signal) => {
|
|
|
142
174
|
send(request);
|
|
143
175
|
sent = true;
|
|
144
176
|
}
|
|
145
|
-
|
|
177
|
+
const parsed = parseUiResult(method, await response);
|
|
178
|
+
if (parsed.ok) return parsed.result;
|
|
179
|
+
(0, import_logger.log)(
|
|
180
|
+
`protocol mismatch: ${method} result: ${JSON.stringify(parsed.issues)}`
|
|
181
|
+
);
|
|
182
|
+
return null;
|
|
146
183
|
} catch {
|
|
147
184
|
return null;
|
|
148
185
|
} finally {
|
|
@@ -2699,6 +2736,7 @@ var RuntimeState = class {
|
|
|
2699
2736
|
authority
|
|
2700
2737
|
]);
|
|
2701
2738
|
}
|
|
2739
|
+
acceptedSteerIds = /* @__PURE__ */ new Map();
|
|
2702
2740
|
pendingSteersByRun = /* @__PURE__ */ new Map();
|
|
2703
2741
|
steerClosedRuns = /* @__PURE__ */ new Set();
|
|
2704
2742
|
uiRequestCounter = 0;
|
|
@@ -2833,6 +2871,7 @@ var RuntimeState = class {
|
|
|
2833
2871
|
this.lastContextLeftPercent = null;
|
|
2834
2872
|
this.runSeq.delete(runId);
|
|
2835
2873
|
this.pendingSteersByRun.delete(runId);
|
|
2874
|
+
this.acceptedSteerIds.delete(runId);
|
|
2836
2875
|
this.steerClosedRuns.delete(runId);
|
|
2837
2876
|
if (this.activeRunId === null) {
|
|
2838
2877
|
this.sessionAppend = null;
|
|
@@ -2845,10 +2884,18 @@ var RuntimeState = class {
|
|
|
2845
2884
|
canSteerRun(runId) {
|
|
2846
2885
|
return this.activeRunId === runId && !this.cancelRequested && !this.steerClosedRuns.has(runId);
|
|
2847
2886
|
}
|
|
2887
|
+
acceptedRunSteerId(runId, clientSteerId) {
|
|
2888
|
+
return this.acceptedSteerIds.get(runId)?.get(clientSteerId);
|
|
2889
|
+
}
|
|
2848
2890
|
enqueueRunSteer(runId, content, clientSteerId, approvalUserText) {
|
|
2849
2891
|
this.signalApprovalChange();
|
|
2850
2892
|
this.runSteerCounter += 1;
|
|
2851
2893
|
const steerId = `s${this.runSteerCounter}`;
|
|
2894
|
+
if (clientSteerId !== void 0) {
|
|
2895
|
+
const accepted = this.acceptedSteerIds.get(runId) ?? /* @__PURE__ */ new Map();
|
|
2896
|
+
accepted.set(clientSteerId, steerId);
|
|
2897
|
+
this.acceptedSteerIds.set(runId, accepted);
|
|
2898
|
+
}
|
|
2852
2899
|
if (this.approvalIntent?.runId === runId) {
|
|
2853
2900
|
this.approvalIntent.steers.push({
|
|
2854
2901
|
id: steerId,
|
|
@@ -2859,7 +2906,7 @@ var RuntimeState = class {
|
|
|
2859
2906
|
const queue = this.pendingSteersByRun.get(runId) ?? [];
|
|
2860
2907
|
queue.push({
|
|
2861
2908
|
steer_id: steerId,
|
|
2862
|
-
...clientSteerId ? { client_steer_id: clientSteerId } : {},
|
|
2909
|
+
...clientSteerId !== void 0 ? { client_steer_id: clientSteerId } : {},
|
|
2863
2910
|
content
|
|
2864
2911
|
});
|
|
2865
2912
|
this.pendingSteersByRun.set(runId, queue);
|
|
@@ -3173,7 +3220,7 @@ var createChildChannel = (send3) => {
|
|
|
3173
3220
|
|
|
3174
3221
|
// src/subagents/child-runtime.ts
|
|
3175
3222
|
var import_node_crypto7 = require("crypto");
|
|
3176
|
-
var
|
|
3223
|
+
var import_node_fs20 = require("fs");
|
|
3177
3224
|
var import_core12 = require("@codelia/core");
|
|
3178
3225
|
var import_storage10 = require("@codelia/storage");
|
|
3179
3226
|
|
|
@@ -3478,21 +3525,26 @@ var createTaskProgressTracker = (options) => {
|
|
|
3478
3525
|
};
|
|
3479
3526
|
|
|
3480
3527
|
// src/subagents/read-tools.ts
|
|
3481
|
-
var
|
|
3482
|
-
var
|
|
3528
|
+
var import_node_fs19 = require("fs");
|
|
3529
|
+
var import_node_path20 = __toESM(require("path"), 1);
|
|
3483
3530
|
var import_core10 = require("@codelia/core");
|
|
3484
3531
|
var import_zod7 = require("zod");
|
|
3485
3532
|
|
|
3486
3533
|
// src/sandbox/context.ts
|
|
3487
3534
|
var import_node_crypto5 = __toESM(require("crypto"), 1);
|
|
3488
|
-
var
|
|
3489
|
-
var
|
|
3535
|
+
var import_node_fs17 = require("fs");
|
|
3536
|
+
var import_node_path18 = __toESM(require("path"), 1);
|
|
3490
3537
|
|
|
3491
3538
|
// src/permissions/git-metadata.ts
|
|
3492
3539
|
var import_node_fs5 = require("fs");
|
|
3540
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
3493
3541
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
3494
3542
|
var isMissing = (error) => error.code === "ENOENT";
|
|
3495
3543
|
var metadataPathSize = 16 * 1024;
|
|
3544
|
+
var gitConfigMaxBytes = 256 * 1024;
|
|
3545
|
+
var maxSymlinkHops = 64;
|
|
3546
|
+
var maxConfigDepth = 8;
|
|
3547
|
+
var maxConfigFiles = 32;
|
|
3496
3548
|
var readPointer = (filename, prefix) => {
|
|
3497
3549
|
const fd = (0, import_node_fs5.openSync)(
|
|
3498
3550
|
filename,
|
|
@@ -3594,6 +3646,7 @@ var eligibleObjectDirectory = (gitDirectory, commonDirectory, marker) => {
|
|
|
3594
3646
|
};
|
|
3595
3647
|
var discoverGitMetadata = (directories, includeObjectDirectories) => {
|
|
3596
3648
|
const readOnlyPaths = /* @__PURE__ */ new Set();
|
|
3649
|
+
const repositories = [];
|
|
3597
3650
|
const reservedMarkers = /* @__PURE__ */ new Set();
|
|
3598
3651
|
const objectDirectories = /* @__PURE__ */ new Map();
|
|
3599
3652
|
const hookAliases = /* @__PURE__ */ new Map();
|
|
@@ -3618,22 +3671,47 @@ var discoverGitMetadata = (directories, includeObjectDirectories) => {
|
|
|
3618
3671
|
readOnlyPaths.add(actual);
|
|
3619
3672
|
return actual;
|
|
3620
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
|
+
};
|
|
3621
3689
|
for (const directory of new Set(directories)) {
|
|
3690
|
+
const fromRoot = directory === rootDirectory;
|
|
3622
3691
|
const marker = findMarker(directory);
|
|
3623
3692
|
const localMarker = import_node_path4.default.join(directory, ".git");
|
|
3624
3693
|
if (marker !== localMarker) reservedMarkers.add(localMarker);
|
|
3625
3694
|
if (!marker) continue;
|
|
3626
3695
|
if (readOnlyPaths.has(marker)) continue;
|
|
3696
|
+
const isWorkspaceRootRepo = fromRoot && marker === localMarker;
|
|
3697
|
+
const markerLstat = (0, import_node_fs5.lstatSync)(marker);
|
|
3627
3698
|
const actualMarker = (0, import_node_fs5.realpathSync)(marker);
|
|
3628
3699
|
readOnlyPaths.add(marker);
|
|
3629
3700
|
readOnlyPaths.add(actualMarker);
|
|
3630
3701
|
const markerInfo = (0, import_node_fs5.statSync)(actualMarker);
|
|
3631
|
-
const
|
|
3632
|
-
|
|
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(
|
|
3633
3709
|
import_node_path4.default.dirname(marker),
|
|
3634
3710
|
readPointer(actualMarker, "gitdir: ")
|
|
3635
|
-
)
|
|
3636
|
-
|
|
3711
|
+
);
|
|
3712
|
+
gitDirectory = addDirectory(location);
|
|
3713
|
+
directoryEntries.push(location, gitDirectory);
|
|
3714
|
+
}
|
|
3637
3715
|
if (!(0, import_node_fs5.statSync)(import_node_path4.default.join(gitDirectory, "HEAD")).isFile())
|
|
3638
3716
|
throw new Error("invalid_git_metadata_directory");
|
|
3639
3717
|
const commonPointer = import_node_path4.default.join(gitDirectory, "commondir");
|
|
@@ -3643,19 +3721,34 @@ var discoverGitMetadata = (directories, includeObjectDirectories) => {
|
|
|
3643
3721
|
} catch (error) {
|
|
3644
3722
|
if (!isMissing(error)) throw error;
|
|
3645
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
|
+
});
|
|
3646
3731
|
continue;
|
|
3647
3732
|
}
|
|
3648
3733
|
readOnlyPaths.add(commonPointer);
|
|
3649
3734
|
readOnlyPaths.add(common);
|
|
3650
|
-
const
|
|
3651
|
-
|
|
3652
|
-
);
|
|
3735
|
+
const commonLocation = import_node_path4.default.resolve(gitDirectory, readPointer(common, ""));
|
|
3736
|
+
const commonDirectory = addDirectory(commonLocation);
|
|
3737
|
+
directoryEntries.push(commonLocation, commonDirectory);
|
|
3653
3738
|
if (!(0, import_node_fs5.statSync)(import_node_path4.default.join(commonDirectory, "objects")).isDirectory())
|
|
3654
3739
|
throw new Error("invalid_git_common_directory");
|
|
3655
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
|
+
});
|
|
3656
3748
|
}
|
|
3657
3749
|
return Object.freeze({
|
|
3658
3750
|
readOnlyPaths: Object.freeze([...readOnlyPaths].sort()),
|
|
3751
|
+
repositories: Object.freeze(repositories),
|
|
3659
3752
|
reservedMarkers: Object.freeze([...reservedMarkers].sort()),
|
|
3660
3753
|
objectDirectories: Object.freeze([...objectDirectories.values()]),
|
|
3661
3754
|
hookAliases: Object.freeze([...hookAliases.values()])
|
|
@@ -3670,10 +3763,395 @@ var resolveGitMetadata = (directories, includeObjectDirectories) => {
|
|
|
3670
3763
|
};
|
|
3671
3764
|
var gitMetadataPaths = (...directories) => resolveGitMetadata(directories, false);
|
|
3672
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
|
+
};
|
|
3673
4151
|
|
|
3674
4152
|
// src/permissions/home-dot-paths.ts
|
|
3675
4153
|
var import_node_fs7 = require("fs");
|
|
3676
|
-
var
|
|
4154
|
+
var import_node_os2 = __toESM(require("os"), 1);
|
|
3677
4155
|
var import_node_path6 = __toESM(require("path"), 1);
|
|
3678
4156
|
|
|
3679
4157
|
// src/permissions/resource-paths.ts
|
|
@@ -3763,7 +4241,7 @@ function resolveReservedTarget(target, remaining = 64) {
|
|
|
3763
4241
|
}
|
|
3764
4242
|
|
|
3765
4243
|
// src/permissions/home-dot-paths.ts
|
|
3766
|
-
var homeDotDirectory = (writeRoots, home =
|
|
4244
|
+
var homeDotDirectory = (writeRoots, home = import_node_os2.default.homedir()) => {
|
|
3767
4245
|
if (!writeRoots.length) return void 0;
|
|
3768
4246
|
const canonicalHome = resolveReservedTarget(home);
|
|
3769
4247
|
return writeRoots.some(
|
|
@@ -3821,7 +4299,17 @@ function* linkedInodes(roots, entryLimit, ignoredObjectDirectories = [], verifie
|
|
|
3821
4299
|
try {
|
|
3822
4300
|
return (0, import_node_fs8.realpathSync)(entry);
|
|
3823
4301
|
} catch (error) {
|
|
3824
|
-
|
|
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
|
+
}
|
|
3825
4313
|
throw error;
|
|
3826
4314
|
}
|
|
3827
4315
|
});
|
|
@@ -3848,7 +4336,8 @@ function* linkedInodes(roots, entryLimit, ignoredObjectDirectories = [], verifie
|
|
|
3848
4336
|
throw new Error("protected_alias_index_unavailable");
|
|
3849
4337
|
try {
|
|
3850
4338
|
const metadata = (0, import_node_fs8.lstatSync)(file, { bigint: true });
|
|
3851
|
-
if (metadata.isFile() && metadata.nlink > 1n)
|
|
4339
|
+
if ((metadata.isFile() || metadata.isSocket() || metadata.isFIFO()) && metadata.nlink > 1n)
|
|
4340
|
+
yield inode(metadata);
|
|
3852
4341
|
if (metadata.isSymbolicLink() && ignored.size) {
|
|
3853
4342
|
if (verifiedHook(file)) continue;
|
|
3854
4343
|
pending.push(...ignored);
|
|
@@ -3885,9 +4374,9 @@ var isProtectedAlias = (stat, paths) => stat.nlink > 1n && findProtectedAliases(
|
|
|
3885
4374
|
|
|
3886
4375
|
// src/permissions/shell-backend.ts
|
|
3887
4376
|
var import_node_child_process4 = require("child_process");
|
|
3888
|
-
var
|
|
3889
|
-
var
|
|
3890
|
-
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);
|
|
3891
4380
|
var import_storage9 = require("@codelia/storage");
|
|
3892
4381
|
|
|
3893
4382
|
// src/sandbox/file-mutation-helper.ts
|
|
@@ -3900,53 +4389,64 @@ var isWithin = (root, target) => {
|
|
|
3900
4389
|
return relative === "" || !import_node_path9.default.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${import_node_path9.default.sep}`);
|
|
3901
4390
|
};
|
|
3902
4391
|
|
|
3903
|
-
// src/permissions/linux-
|
|
3904
|
-
var
|
|
3905
|
-
var
|
|
3906
|
-
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);
|
|
3907
4396
|
|
|
3908
4397
|
// src/permissions/linux-mountinfo.ts
|
|
3909
4398
|
var import_node_fs9 = require("fs");
|
|
3910
4399
|
var import_node_path10 = __toESM(require("path"), 1);
|
|
3911
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
|
+
|
|
3912
4410
|
// src/permissions/shell-analysis.ts
|
|
3913
4411
|
var MAX_SOURCE_BYTES = 32 * 1024;
|
|
3914
4412
|
|
|
3915
4413
|
// src/permissions/shell-path.ts
|
|
3916
|
-
var
|
|
3917
|
-
var
|
|
4414
|
+
var import_node_fs11 = require("fs");
|
|
4415
|
+
var import_node_path12 = __toESM(require("path"), 1);
|
|
3918
4416
|
|
|
3919
|
-
// 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
|
|
3920
4423
|
var import_node_child_process3 = require("child_process");
|
|
3921
|
-
var
|
|
3922
|
-
var
|
|
3923
|
-
var
|
|
3924
|
-
var import_meta = {};
|
|
3925
|
-
var packagePath = import_node_path13.default.join("node_modules", "@codelia", "tui-darwin-arm64");
|
|
3926
|
-
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);
|
|
3927
4427
|
|
|
3928
4428
|
// src/permissions/system-bash.ts
|
|
3929
|
-
var
|
|
3930
|
-
var
|
|
4429
|
+
var import_node_fs14 = require("fs");
|
|
4430
|
+
var import_node_path15 = require("path");
|
|
3931
4431
|
|
|
3932
4432
|
// src/permissions/workspace-config-paths.ts
|
|
3933
|
-
var
|
|
3934
|
-
var
|
|
4433
|
+
var import_node_fs15 = require("fs");
|
|
4434
|
+
var import_node_path16 = __toESM(require("path"), 1);
|
|
3935
4435
|
var import_storage8 = require("@codelia/storage");
|
|
3936
4436
|
var confinedAutoLaunchDirectoryName = "confined-auto-launch";
|
|
3937
|
-
var isWorkspaceConfigName = (root, target) => resourceContainsPath(
|
|
4437
|
+
var isWorkspaceConfigName = (root, target) => resourceContainsPath(import_node_path16.default.dirname(resolveProjectConfigPath(root)), target);
|
|
3938
4438
|
var missing2 = (error) => error.code === "ENOENT";
|
|
3939
4439
|
function resolveConfigTarget(target, remaining = 64) {
|
|
3940
4440
|
if (!remaining) throw new Error("workspace_config_path_unresolved");
|
|
3941
4441
|
try {
|
|
3942
|
-
return (0,
|
|
4442
|
+
return (0, import_node_fs15.realpathSync)(target);
|
|
3943
4443
|
} catch (error) {
|
|
3944
|
-
const parent =
|
|
4444
|
+
const parent = import_node_path16.default.dirname(target);
|
|
3945
4445
|
if (!missing2(error) || parent === target) throw error;
|
|
3946
4446
|
const canonicalParent = resolveConfigTarget(parent, remaining - 1);
|
|
3947
|
-
if (!(0,
|
|
3948
|
-
return
|
|
3949
|
-
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);
|
|
3950
4450
|
let seenName = false;
|
|
3951
4451
|
for (const part of referent.split(
|
|
3952
4452
|
process.platform === "win32" ? /[\\/]/u : "/"
|
|
@@ -3956,14 +4456,14 @@ function resolveConfigTarget(target, remaining = 64) {
|
|
|
3956
4456
|
if (part && part !== "." && part !== "..") seenName = true;
|
|
3957
4457
|
}
|
|
3958
4458
|
return resolveConfigTarget(
|
|
3959
|
-
|
|
4459
|
+
import_node_path16.default.resolve(canonicalParent, referent),
|
|
3960
4460
|
remaining - 1
|
|
3961
4461
|
);
|
|
3962
4462
|
}
|
|
3963
4463
|
}
|
|
3964
4464
|
var workspaceConfigProtection = (root) => {
|
|
3965
4465
|
const config = resolveProjectConfigPath(root);
|
|
3966
|
-
const directory =
|
|
4466
|
+
const directory = import_node_path16.default.dirname(config);
|
|
3967
4467
|
const readOnlyPaths = /* @__PURE__ */ new Set([directory]);
|
|
3968
4468
|
const readOnlyAliasPaths = /* @__PURE__ */ new Set();
|
|
3969
4469
|
const reserveTarget = (file) => {
|
|
@@ -3971,12 +4471,12 @@ var workspaceConfigProtection = (root) => {
|
|
|
3971
4471
|
readOnlyPaths.add(target);
|
|
3972
4472
|
readOnlyAliasPaths.add(target);
|
|
3973
4473
|
};
|
|
3974
|
-
if ((0,
|
|
4474
|
+
if ((0, import_node_fs15.lstatSync)(directory, { throwIfNoEntry: false })) {
|
|
3975
4475
|
const canonical = resolveConfigTarget(directory);
|
|
3976
4476
|
readOnlyPaths.add(canonical);
|
|
3977
|
-
if ((0,
|
|
3978
|
-
const file =
|
|
3979
|
-
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);
|
|
3980
4480
|
const storage = (0, import_storage8.resolveStoragePaths)();
|
|
3981
4481
|
const globalStorage = [
|
|
3982
4482
|
(0, import_storage8.resolveStoragePaths)({ layout: "home" }).root,
|
|
@@ -3984,24 +4484,24 @@ var workspaceConfigProtection = (root) => {
|
|
|
3984
4484
|
storage.configDir
|
|
3985
4485
|
].some((entry) => {
|
|
3986
4486
|
try {
|
|
3987
|
-
return (0,
|
|
4487
|
+
return (0, import_node_fs15.realpathSync)(entry) === canonical;
|
|
3988
4488
|
} catch (error) {
|
|
3989
4489
|
if (!missing2(error)) throw error;
|
|
3990
4490
|
return false;
|
|
3991
4491
|
}
|
|
3992
4492
|
});
|
|
3993
4493
|
if (!globalStorage) {
|
|
3994
|
-
const worktrees =
|
|
4494
|
+
const worktrees = import_node_path16.default.join(canonical, "worktrees");
|
|
3995
4495
|
const pending = [canonical];
|
|
3996
4496
|
for (const current of pending) {
|
|
3997
|
-
const children = (0,
|
|
4497
|
+
const children = (0, import_node_fs15.opendirSync)(current);
|
|
3998
4498
|
try {
|
|
3999
4499
|
for (let entry = children.readSync(); entry; entry = children.readSync()) {
|
|
4000
|
-
const target =
|
|
4500
|
+
const target = import_node_path16.default.join(current, entry.name);
|
|
4001
4501
|
if (target === file || target === worktrees) continue;
|
|
4002
4502
|
if (entry.isSymbolicLink()) reserveTarget(target);
|
|
4003
4503
|
else if (entry.isDirectory()) pending.push(target);
|
|
4004
|
-
else if (entry.isFile() && ((0,
|
|
4504
|
+
else if (entry.isFile() && ((0, import_node_fs15.lstatSync)(target, { throwIfNoEntry: false })?.nlink ?? 0) > 1)
|
|
4005
4505
|
readOnlyAliasPaths.add(target);
|
|
4006
4506
|
}
|
|
4007
4507
|
} finally {
|
|
@@ -4020,27 +4520,27 @@ var workspaceConfigProtection = (root) => {
|
|
|
4020
4520
|
// src/permissions/shell-backend.ts
|
|
4021
4521
|
var realOrLexical = (value) => {
|
|
4022
4522
|
try {
|
|
4023
|
-
return (0,
|
|
4523
|
+
return (0, import_node_fs16.realpathSync)(value);
|
|
4024
4524
|
} catch {
|
|
4025
|
-
return
|
|
4525
|
+
return import_node_path17.default.resolve(value);
|
|
4026
4526
|
}
|
|
4027
4527
|
};
|
|
4028
4528
|
var resolvePolicyPath = (target) => {
|
|
4029
|
-
const absolute =
|
|
4529
|
+
const absolute = import_node_path17.default.resolve(target);
|
|
4030
4530
|
try {
|
|
4031
|
-
return (0,
|
|
4531
|
+
return (0, import_node_fs16.realpathSync)(absolute);
|
|
4032
4532
|
} catch (error) {
|
|
4033
|
-
const parent =
|
|
4533
|
+
const parent = import_node_path17.default.dirname(absolute);
|
|
4034
4534
|
if (error.code !== "ENOENT" || parent === absolute)
|
|
4035
4535
|
throw error;
|
|
4036
|
-
if ((0,
|
|
4536
|
+
if ((0, import_node_fs16.lstatSync)(absolute, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
4037
4537
|
throw error;
|
|
4038
|
-
return
|
|
4538
|
+
return import_node_path17.default.join(resolvePolicyPath(parent), import_node_path17.default.basename(absolute));
|
|
4039
4539
|
}
|
|
4040
4540
|
};
|
|
4041
4541
|
var canonicalPolicyPaths = (paths) => Object.freeze([
|
|
4042
4542
|
...new Set(
|
|
4043
|
-
paths.flatMap((entry) => [
|
|
4543
|
+
paths.flatMap((entry) => [import_node_path17.default.resolve(entry), resolvePolicyPath(entry)])
|
|
4044
4544
|
)
|
|
4045
4545
|
]);
|
|
4046
4546
|
var runtimeReadOnlyPaths = () => {
|
|
@@ -4057,15 +4557,15 @@ var runtimeProtectedCredentialPaths = () => {
|
|
|
4057
4557
|
const targets = [];
|
|
4058
4558
|
if (process.platform === "linux") {
|
|
4059
4559
|
try {
|
|
4060
|
-
(0,
|
|
4560
|
+
(0, import_node_fs16.mkdirSync)(storage.credentialsDir, { recursive: true, mode: 448 });
|
|
4061
4561
|
targets.push(storage.credentialsDir);
|
|
4062
4562
|
} catch {
|
|
4063
|
-
if ((0,
|
|
4563
|
+
if ((0, import_node_fs16.lstatSync)(storage.credentialsDir, { throwIfNoEntry: false })) {
|
|
4064
4564
|
targets.push(storage.credentialsDir);
|
|
4065
4565
|
}
|
|
4066
4566
|
}
|
|
4067
4567
|
for (const legacy of [storage.legacyAuthFile, storage.legacyMcpAuthFile]) {
|
|
4068
|
-
if ((0,
|
|
4568
|
+
if ((0, import_node_fs16.lstatSync)(legacy, { throwIfNoEntry: false })) {
|
|
4069
4569
|
targets.push(legacy);
|
|
4070
4570
|
}
|
|
4071
4571
|
}
|
|
@@ -4081,8 +4581,8 @@ var runtimeProtectedCredentialPaths = () => {
|
|
|
4081
4581
|
var runtimeAuthorityAliasPaths = () => {
|
|
4082
4582
|
const storage = (0, import_storage9.resolveStoragePaths)();
|
|
4083
4583
|
const databasePaths = [
|
|
4084
|
-
|
|
4085
|
-
|
|
4584
|
+
import_node_path17.default.join(storage.configDir, ".projects-policy-lock.sqlite"),
|
|
4585
|
+
import_node_path17.default.join(storage.sessionsDir, "state.db")
|
|
4086
4586
|
];
|
|
4087
4587
|
return canonicalPolicyPaths([
|
|
4088
4588
|
resolveConfigPath(),
|
|
@@ -4092,15 +4592,22 @@ var runtimeAuthorityAliasPaths = () => {
|
|
|
4092
4592
|
"launch-approvals",
|
|
4093
4593
|
"auto-review.json",
|
|
4094
4594
|
confinedAutoLaunchDirectoryName
|
|
4095
|
-
].map((entry) =>
|
|
4595
|
+
].map((entry) => import_node_path17.default.join(storage.configDir, entry)),
|
|
4096
4596
|
...databasePaths.flatMap(
|
|
4097
4597
|
(file) => ["", "-wal", "-shm", "-journal"].map((suffix) => `${file}${suffix}`)
|
|
4098
4598
|
)
|
|
4099
4599
|
]);
|
|
4100
4600
|
};
|
|
4101
4601
|
var workspacePathProtection = (root, extraProtectedPaths = [], relatedDirectories = [], sandboxMode = "workspace-write", allowSharedGitObjects = false, extraReadOnlyPaths = [], homeScope = {}) => {
|
|
4102
|
-
const discover = allowSharedGitObjects && sandboxMode === "workspace-write" ? gitMetadataWithObjectDirectories : gitMetadataPaths;
|
|
4103
|
-
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;
|
|
4104
4611
|
const protectedPaths = canonicalPolicyPaths([
|
|
4105
4612
|
...extraProtectedPaths,
|
|
4106
4613
|
...runtimeProtectedCredentialPaths()
|
|
@@ -4126,14 +4633,23 @@ var workspacePathProtection = (root, extraProtectedPaths = [], relatedDirectorie
|
|
|
4126
4633
|
const objectDirectoriesWithSharedFiles = objectDirectories.filter(
|
|
4127
4634
|
(directory) => {
|
|
4128
4635
|
const overlaps = (other) => resourceContainsPath(other, directory.path) || resourceContainsPath(directory.path, other);
|
|
4129
|
-
const commonDirectory =
|
|
4636
|
+
const commonDirectory = import_node_path17.default.dirname(directory.path);
|
|
4130
4637
|
return !strongerPaths.some(overlaps) && !readOnlyPaths.some(
|
|
4131
4638
|
(other) => overlaps(other) && realOrLexical(other) !== commonDirectory
|
|
4132
4639
|
);
|
|
4133
4640
|
}
|
|
4134
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
|
+
);
|
|
4135
4647
|
return {
|
|
4136
4648
|
...protectedHome ? { homeDotDirectory: protectedHome } : {},
|
|
4649
|
+
...gitScope && gitScope.releasedPaths.length > 0 ? {
|
|
4650
|
+
...gitWriteRoots.length ? { gitWriteRoots } : {},
|
|
4651
|
+
gitProtectedPaths: gitScope.readOnlyPaths
|
|
4652
|
+
} : {},
|
|
4137
4653
|
protectedPaths,
|
|
4138
4654
|
protectedAliasPaths: protectedPaths,
|
|
4139
4655
|
readOnlyPaths: Object.freeze(
|
|
@@ -4167,22 +4683,22 @@ var SecurityError = class extends Error {
|
|
|
4167
4683
|
var identity = (info) => `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`;
|
|
4168
4684
|
var directoryIdentity = (stat) => `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;
|
|
4169
4685
|
var selectMissingFile = (entry) => {
|
|
4170
|
-
let parent =
|
|
4686
|
+
let parent = import_node_path18.default.dirname(entry.target);
|
|
4171
4687
|
for (; ; ) {
|
|
4172
4688
|
try {
|
|
4173
|
-
const stat = (0,
|
|
4174
|
-
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)
|
|
4175
4691
|
throw new SecurityError("Expected a canonical parent directory");
|
|
4176
4692
|
return Object.freeze({
|
|
4177
4693
|
...entry,
|
|
4178
4694
|
identity: null,
|
|
4179
4695
|
parent,
|
|
4180
4696
|
parentIdentity: directoryIdentity(stat),
|
|
4181
|
-
tail:
|
|
4697
|
+
tail: import_node_path18.default.relative(parent, entry.target)
|
|
4182
4698
|
});
|
|
4183
4699
|
} catch (error) {
|
|
4184
4700
|
if (error.code !== "ENOENT") throw error;
|
|
4185
|
-
const ancestor =
|
|
4701
|
+
const ancestor = import_node_path18.default.dirname(parent);
|
|
4186
4702
|
if (ancestor === parent) throw error;
|
|
4187
4703
|
parent = ancestor;
|
|
4188
4704
|
}
|
|
@@ -4190,15 +4706,15 @@ var selectMissingFile = (entry) => {
|
|
|
4190
4706
|
};
|
|
4191
4707
|
var missingDestinationCurrent = (selection) => {
|
|
4192
4708
|
try {
|
|
4193
|
-
const segments = selection.tail.split(
|
|
4709
|
+
const segments = selection.tail.split(import_node_path18.default.sep);
|
|
4194
4710
|
if (segments.some(
|
|
4195
4711
|
(segment) => !segment || segment === "." || segment === ".."
|
|
4196
|
-
) ||
|
|
4712
|
+
) || import_node_path18.default.join(selection.parent, selection.tail) !== selection.target || !directoryBindingCurrent(selection))
|
|
4197
4713
|
return false;
|
|
4198
4714
|
let current = selection.parent;
|
|
4199
4715
|
for (const [index, segment] of segments.entries()) {
|
|
4200
|
-
current =
|
|
4201
|
-
const stat = (0,
|
|
4716
|
+
current = import_node_path18.default.join(current, segment);
|
|
4717
|
+
const stat = (0, import_node_fs17.lstatSync)(current);
|
|
4202
4718
|
if (index === segments.length - 1 || !stat.isDirectory()) return false;
|
|
4203
4719
|
}
|
|
4204
4720
|
return false;
|
|
@@ -4208,8 +4724,8 @@ var missingDestinationCurrent = (selection) => {
|
|
|
4208
4724
|
};
|
|
4209
4725
|
var directoryBindingCurrent = (selection) => {
|
|
4210
4726
|
try {
|
|
4211
|
-
const stat = (0,
|
|
4212
|
-
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;
|
|
4213
4729
|
} catch {
|
|
4214
4730
|
return false;
|
|
4215
4731
|
}
|
|
@@ -4243,10 +4759,10 @@ var SandboxContext = class _SandboxContext {
|
|
|
4243
4759
|
}
|
|
4244
4760
|
static async create(rootDir, options = {}) {
|
|
4245
4761
|
const sessionId = import_node_crypto5.default.randomUUID().slice(0, 8);
|
|
4246
|
-
const root = rootDir ?
|
|
4762
|
+
const root = rootDir ? import_node_path18.default.resolve(rootDir) : process.cwd();
|
|
4247
4763
|
if (options.sandboxMode !== "readonly")
|
|
4248
|
-
await
|
|
4249
|
-
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;
|
|
4250
4766
|
return new _SandboxContext({
|
|
4251
4767
|
rootDir: directory,
|
|
4252
4768
|
workingDir: directory,
|
|
@@ -4268,7 +4784,7 @@ var SandboxContext = class _SandboxContext {
|
|
|
4268
4784
|
resolvePath(targetPath, access = "write") {
|
|
4269
4785
|
if (access === "write" && this.sandboxMode === "readonly")
|
|
4270
4786
|
throw new SecurityError("Sandbox mode is readonly");
|
|
4271
|
-
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);
|
|
4272
4788
|
if (this.protectedPaths) return this.resolveProtectedPath(resolved, access);
|
|
4273
4789
|
if (this.approvalMode === "full-access") {
|
|
4274
4790
|
return resolved;
|
|
@@ -4286,12 +4802,12 @@ var SandboxContext = class _SandboxContext {
|
|
|
4286
4802
|
selectFile(operand, access, directoryEntry = false) {
|
|
4287
4803
|
const target = this.resolvePath(operand, access);
|
|
4288
4804
|
if (directoryEntry) {
|
|
4289
|
-
const lexical =
|
|
4290
|
-
const name =
|
|
4291
|
-
resolvePolicyPath(
|
|
4292
|
-
|
|
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)
|
|
4293
4809
|
);
|
|
4294
|
-
if (target !== name || (0,
|
|
4810
|
+
if (target !== name || (0, import_node_fs17.lstatSync)(name, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
4295
4811
|
throw new SecurityError(
|
|
4296
4812
|
"Patch deletion and move require a regular directory entry without a symbolic link"
|
|
4297
4813
|
);
|
|
@@ -4303,7 +4819,7 @@ var SandboxContext = class _SandboxContext {
|
|
|
4303
4819
|
...directoryEntry ? { directoryEntry: true } : {}
|
|
4304
4820
|
};
|
|
4305
4821
|
try {
|
|
4306
|
-
const info = (0,
|
|
4822
|
+
const info = (0, import_node_fs17.lstatSync)(target, { bigint: true });
|
|
4307
4823
|
if (!info.isFile())
|
|
4308
4824
|
throw new SecurityError("Expected a regular file for this operation");
|
|
4309
4825
|
return Object.freeze({
|
|
@@ -4351,8 +4867,8 @@ var SandboxContext = class _SandboxContext {
|
|
|
4351
4867
|
error.code = "ENOENT";
|
|
4352
4868
|
throw error;
|
|
4353
4869
|
}
|
|
4354
|
-
const flags = (mode === "read" ?
|
|
4355
|
-
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);
|
|
4356
4872
|
try {
|
|
4357
4873
|
const opened = await handle.stat({ bigint: true });
|
|
4358
4874
|
if (!opened.isFile() || identity(opened) !== selected.identity || isProtectedAlias(
|
|
@@ -4445,7 +4961,7 @@ var SandboxContext = class _SandboxContext {
|
|
|
4445
4961
|
writeProtection(target, alias = false) {
|
|
4446
4962
|
const { readOnlyPaths } = gitMetadataPaths(
|
|
4447
4963
|
this.rootDir,
|
|
4448
|
-
|
|
4964
|
+
import_node_path18.default.dirname(target)
|
|
4449
4965
|
);
|
|
4450
4966
|
const projectConfig = workspaceConfigProtection(this.rootDir);
|
|
4451
4967
|
return [
|
|
@@ -4477,16 +4993,16 @@ var SandboxContext = class _SandboxContext {
|
|
|
4477
4993
|
let probe = resolved;
|
|
4478
4994
|
for (; ; ) {
|
|
4479
4995
|
try {
|
|
4480
|
-
const actual = (0,
|
|
4481
|
-
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));
|
|
4482
4998
|
rejectProtected(target);
|
|
4483
4999
|
if (target !== resolved) rejectWrite(target);
|
|
4484
5000
|
if (probe === resolved) {
|
|
4485
|
-
const stat = (0,
|
|
5001
|
+
const stat = (0, import_node_fs17.lstatSync)(target);
|
|
4486
5002
|
if (!stat.isFile() && !stat.isDirectory())
|
|
4487
5003
|
throw new SecurityError("Unsupported file type");
|
|
4488
5004
|
if (stat.isFile() && stat.nlink > 1) {
|
|
4489
|
-
const inode2 = (0,
|
|
5005
|
+
const inode2 = (0, import_node_fs17.lstatSync)(target, { bigint: true });
|
|
4490
5006
|
if (isProtectedAlias(inode2, protectedPaths))
|
|
4491
5007
|
throw new SecurityError("Path aliases a protected file");
|
|
4492
5008
|
if (access === "write" && this.isReadOnlyAlias(inode2, target))
|
|
@@ -4496,10 +5012,10 @@ var SandboxContext = class _SandboxContext {
|
|
|
4496
5012
|
return target;
|
|
4497
5013
|
} catch (error) {
|
|
4498
5014
|
if (error.code !== "ENOENT") throw error;
|
|
4499
|
-
const ancestor =
|
|
5015
|
+
const ancestor = import_node_path18.default.dirname(probe);
|
|
4500
5016
|
if (ancestor === probe) throw error;
|
|
4501
5017
|
try {
|
|
4502
|
-
if ((0,
|
|
5018
|
+
if ((0, import_node_fs17.lstatSync)(probe).isSymbolicLink())
|
|
4503
5019
|
throw new SecurityError("Path contains a dangling symlink");
|
|
4504
5020
|
} catch (entryError) {
|
|
4505
5021
|
if (entryError.code !== "ENOENT")
|
|
@@ -4527,8 +5043,8 @@ var appendReadMetadata = (output, content) => `${output}
|
|
|
4527
5043
|
[read_metadata] content_sha256=${hashUtf8Content(content)}`;
|
|
4528
5044
|
|
|
4529
5045
|
// src/subagents/workspace-files.ts
|
|
4530
|
-
var
|
|
4531
|
-
var
|
|
5046
|
+
var import_node_fs18 = require("fs");
|
|
5047
|
+
var import_node_path19 = __toESM(require("path"), 1);
|
|
4532
5048
|
var MAX_CHILD_FILE_BYTES = 4 * 1024 * 1024;
|
|
4533
5049
|
var readContent = async (handle) => {
|
|
4534
5050
|
const buffer = Buffer.alloc(MAX_CHILD_FILE_BYTES + 1);
|
|
@@ -4555,17 +5071,17 @@ var createWorkspaceFiles = (root, extraProtectedPaths, extraReadOnlyPaths) => {
|
|
|
4555
5071
|
);
|
|
4556
5072
|
const blocked = (target) => protectedPaths.some((entry) => resourceContainsPath(entry, target));
|
|
4557
5073
|
const resolve = async (name, allowMissing = false) => {
|
|
4558
|
-
const candidate =
|
|
5074
|
+
const candidate = import_node_path19.default.resolve(root, name);
|
|
4559
5075
|
if (blocked(candidate))
|
|
4560
5076
|
throw new Error("Path is protected by the resource policy");
|
|
4561
|
-
const relative =
|
|
4562
|
-
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))
|
|
4563
5079
|
throw new Error("Path outside delegated workspace");
|
|
4564
5080
|
let part = root;
|
|
4565
|
-
for (const segment of relative.split(
|
|
4566
|
-
part =
|
|
5081
|
+
for (const segment of relative.split(import_node_path19.default.sep).filter(Boolean)) {
|
|
5082
|
+
part = import_node_path19.default.join(part, segment);
|
|
4567
5083
|
try {
|
|
4568
|
-
if ((await
|
|
5084
|
+
if ((await import_node_fs18.promises.lstat(part)).isSymbolicLink())
|
|
4569
5085
|
throw new Error(
|
|
4570
5086
|
"Symbolic links are not available to delegated tools"
|
|
4571
5087
|
);
|
|
@@ -4603,7 +5119,7 @@ var createWorkspaceFiles = (root, extraProtectedPaths, extraReadOnlyPaths) => {
|
|
|
4603
5119
|
const file = await resolve(name, expected === "missing");
|
|
4604
5120
|
const repositoryReadOnly = gitMetadataPaths(
|
|
4605
5121
|
root,
|
|
4606
|
-
|
|
5122
|
+
import_node_path19.default.dirname(file)
|
|
4607
5123
|
).readOnlyPaths;
|
|
4608
5124
|
const projectConfig = workspaceConfigProtection(root);
|
|
4609
5125
|
if (homeDotDirectory2 && isHomeWriteReserved(homeDotDirectory2, file) || isWorkspaceConfigName(root, file) || [
|
|
@@ -4621,17 +5137,17 @@ var createWorkspaceFiles = (root, extraProtectedPaths, extraReadOnlyPaths) => {
|
|
|
4621
5137
|
await approval.bound.writeSelectedFile(name, value);
|
|
4622
5138
|
return hashUtf8Content(value);
|
|
4623
5139
|
}
|
|
4624
|
-
if (approval && (!selection?.identity || selection.target !== await
|
|
5140
|
+
if (approval && (!selection?.identity || selection.target !== await import_node_fs18.promises.realpath(file)))
|
|
4625
5141
|
throw new Error("File selection changed after approval");
|
|
4626
5142
|
if (approval && expected === "missing")
|
|
4627
5143
|
throw new Error("File already exists");
|
|
4628
5144
|
if (expected === "missing") {
|
|
4629
|
-
await
|
|
5145
|
+
await import_node_fs18.promises.mkdir(import_node_path19.default.dirname(file), { recursive: true });
|
|
4630
5146
|
await resolve(name, true);
|
|
4631
5147
|
}
|
|
4632
|
-
const handle = await
|
|
5148
|
+
const handle = await import_node_fs18.promises.open(
|
|
4633
5149
|
file,
|
|
4634
|
-
expected === "missing" ? "wx" :
|
|
5150
|
+
expected === "missing" ? "wx" : import_node_fs18.constants.O_RDWR | (import_node_fs18.constants.O_NOFOLLOW ?? 0)
|
|
4635
5151
|
);
|
|
4636
5152
|
try {
|
|
4637
5153
|
const stat = await handle.stat({ bigint: true });
|
|
@@ -4707,7 +5223,7 @@ var clipJsonString = (text, limit) => {
|
|
|
4707
5223
|
var createSubagentReadTools = (root, protectedPaths, options = {}) => {
|
|
4708
5224
|
const permits = options.permits ?? (() => true);
|
|
4709
5225
|
const resolveWorkspace = async () => {
|
|
4710
|
-
const sandbox = await SandboxContext.create(await
|
|
5226
|
+
const sandbox = await SandboxContext.create(await import_node_fs19.promises.realpath(root), {
|
|
4711
5227
|
protectResources: true,
|
|
4712
5228
|
extraProtectedPaths: protectedPaths
|
|
4713
5229
|
});
|
|
@@ -4735,17 +5251,17 @@ var createSubagentReadTools = (root, protectedPaths, options = {}) => {
|
|
|
4735
5251
|
signal?.throwIfAborted();
|
|
4736
5252
|
const dir = pending.shift();
|
|
4737
5253
|
if (!dir) break;
|
|
4738
|
-
const entries = await
|
|
5254
|
+
const entries = await import_node_fs19.promises.opendir(await resolve(import_node_path20.default.relative(root2, dir)));
|
|
4739
5255
|
for await (const entry of entries) {
|
|
4740
5256
|
if (entry.isSymbolicLink() || entry.name === ".git" || entry.name === "node_modules")
|
|
4741
5257
|
continue;
|
|
4742
|
-
const child =
|
|
5258
|
+
const child = import_node_path20.default.join(dir, entry.name);
|
|
4743
5259
|
if (blocked(child)) continue;
|
|
4744
5260
|
if (entry.isDirectory()) {
|
|
4745
5261
|
if (pending.length >= 2e3) return { paths, truncated: true };
|
|
4746
5262
|
pending.push(child);
|
|
4747
5263
|
} else if (entry.isFile()) {
|
|
4748
|
-
const name =
|
|
5264
|
+
const name = import_node_path20.default.relative(root2, child);
|
|
4749
5265
|
const selected = await selectRead(name, sandbox).catch(
|
|
4750
5266
|
() => void 0
|
|
4751
5267
|
);
|
|
@@ -4976,7 +5492,7 @@ var createSubagentWriteTools = (root, channel, protection, protectedPaths) => {
|
|
|
4976
5492
|
|
|
4977
5493
|
// src/subagents/child-runtime.ts
|
|
4978
5494
|
var createChildRun = async (input, llm, options = {}) => {
|
|
4979
|
-
const workspace = await
|
|
5495
|
+
const workspace = await import_node_fs20.promises.realpath(input.workspace_root);
|
|
4980
5496
|
const session_id = (0, import_node_crypto7.randomUUID)();
|
|
4981
5497
|
const run_id = (0, import_node_crypto7.randomUUID)();
|
|
4982
5498
|
const sessions = options.sessions ?? new import_storage10.SessionStateStoreImpl();
|
|
@@ -5200,7 +5716,7 @@ var createChildRun = async (input, llm, options = {}) => {
|
|
|
5200
5716
|
};
|
|
5201
5717
|
|
|
5202
5718
|
// src/subagents/child-entry.ts
|
|
5203
|
-
var bootstrap = (0,
|
|
5719
|
+
var bootstrap = (0, import_node_fs21.createReadStream)("", { fd: 3, autoClose: false });
|
|
5204
5720
|
bootstrap.setEncoding("utf8");
|
|
5205
5721
|
var controller = new AbortController();
|
|
5206
5722
|
var exitTimer;
|