@habitat-ai/cli 0.7.0 → 0.8.1
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/README.md +10 -2
- package/dist/{application-Idvdhc9h.js → application-8f0_AsW-.js} +3 -3
- package/dist/application.js +1 -1
- package/dist/{cli-DxjKzwlV.js → cli-C6a6rMyL.js} +2442 -342
- package/dist/cli.js +1 -1
- package/dist/{habitat.app-CgdXa2f2.js → habitat.app-C6w7oWGp.js} +2134 -244
- package/dist/habitat.app.js +1 -1
- package/dist/index.js +1 -1
- package/dist/nx-plugin.js +1 -1
- package/dist/{oclif-DBwcAyVK.js → oclif-Cv5SdrBu.js} +1 -1
- package/dist/oclif.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as ContentWorkspaceRuntimeResource, B as SourceInventoryRuntimeResource, C as ObservedMcpServerNameSchema, D as AntigravityNativeAgentProviderRuntimeResource, E as VersionedContentRuntimeResource, F as SourceInventoryPathSchema, H as FilesystemRuntimeResource, I as SourceInventoryResultSchema, M as MAX_SOURCE_INVENTORY_FAILURE_DETAIL, N as MAX_SOURCE_INVENTORY_ROOT_LENGTH, O as ClaudeNativeAgentProviderRuntimeResource, P as ObserveSourceInventoryInputSchema, R as MAX_RULE_EVALUATION_FAILURE_DETAIL, S as NativeProviderSessionInputSchema, T as projectAntigravityPluginBundle, V as RuleEvaluationRuntimeResource, _ as NativeProviderMarketplaceIdentityInputSchema, a as MaterializeRemoteInputSchema, b as NativeProviderPluginFilesReadInputSchema, c as CanonicalGitRepositoryUrlSchema, g as NativeProviderInventorySchema, h as NativeProviderInventoryOptionsSchema, i as MAX_VERSIONED_CONTENT_FAILURE_DETAIL, j as AgentPluginPackageOutputRuntimeResource, k as CodexNativeAgentProviderRuntimeResource, l as MAX_NATIVE_PROVIDER_MCP_SERVERS, m as NativeMarketplaceSourceSchema, n as ChildProcessRuntimeResource, o as ObserveRemoteInputSchema, p as NativeManagedMcpServerRecordSchema, r as AncestryInputSchema, s as VersionedContentTreeEntrySchema, t as habitatApp, v as NativeProviderMcpServerAddInputSchema, w as PluginVersionSchema, x as NativeProviderPluginSelectorInputSchema, y as NativeProviderMcpServerRemoveInputSchema, z as RuleEvaluationRequestSchema } from "./habitat.app-C6w7oWGp.js";
|
|
2
2
|
import { t as createOclifHost } from "./host-BcptPYDL.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { requireResource } from "@habitat-ai/sdk/runtime/resources";
|
|
5
5
|
import { RuntimeSchema } from "@habitat-ai/sdk/runtime/schema";
|
|
6
|
-
import { Cause, Context, Effect, Equal, Exit, FileSystem, Layer, Option, Path, Random, Semaphore, Stream } from "effect";
|
|
6
|
+
import { Cause, Context, Effect, Equal, Exit, FileSystem, Layer, Option, Path, Random, Result, Semaphore, Stream } from "effect";
|
|
7
7
|
import { ReadonlyObject, Refine, Type } from "typebox";
|
|
8
8
|
import Schema, { Validator } from "typebox/schema";
|
|
9
|
+
import { parse } from "smol-toml";
|
|
9
10
|
import { Value } from "typebox/value";
|
|
10
11
|
import { defineEntrypoint, defineProcessCatalog, startApp } from "@habitat-ai/sdk/app";
|
|
11
12
|
import path from "node:path";
|
|
@@ -16,6 +17,8 @@ import { providerFx } from "@habitat-ai/sdk/runtime/providers/effect";
|
|
|
16
17
|
import { Buffer as Buffer$1 } from "node:buffer";
|
|
17
18
|
import { NodeChildProcessSpawner, NodeServices } from "@effect/platform-node";
|
|
18
19
|
import { createHash, randomUUID } from "node:crypto";
|
|
20
|
+
import { homedir } from "node:os";
|
|
21
|
+
import { rmdir } from "node:fs/promises";
|
|
19
22
|
import { defineRuntimeProfile, providerSelection } from "@habitat-ai/sdk/runtime/profiles";
|
|
20
23
|
//#region \0rolldown/runtime.js
|
|
21
24
|
var __create = Object.create;
|
|
@@ -962,7 +965,7 @@ function provideNodeServices$2(operation) {
|
|
|
962
965
|
function encodeCoworkV1(request) {
|
|
963
966
|
return Effect.tryPromise({
|
|
964
967
|
try: () => encodeArchive(request),
|
|
965
|
-
catch: (cause) => failure$
|
|
968
|
+
catch: (cause) => failure$6("encode-archive", "ArchiveEncodingFailed", "archive-codec", void 0, errorMessage$4(cause))
|
|
966
969
|
});
|
|
967
970
|
}
|
|
968
971
|
function encodeArchive(request) {
|
|
@@ -1021,20 +1024,20 @@ function publishOutput(input, options) {
|
|
|
1021
1024
|
yield* revalidatePrior(fs, input.outputPath, parent, prior, input.maxPriorOutputBytes);
|
|
1022
1025
|
yield* revalidateOwnedTemporaryFile(fs, paths, temporary, 1, "publish-output");
|
|
1023
1026
|
if (prior.kind === "Absent") {
|
|
1024
|
-
yield* fs.link(temporary.path, input.outputPath).pipe(mapPlatform$
|
|
1027
|
+
yield* fs.link(temporary.path, input.outputPath).pipe(mapPlatform$6("publish-output", "OutputCommitFailed", "output-no-replace", input.outputPath));
|
|
1025
1028
|
committed = true;
|
|
1026
1029
|
temporaryLinks = 2;
|
|
1027
1030
|
cleanupAttempted = true;
|
|
1028
1031
|
const released = yield* Effect.result(releaseOwnedTemporaryFile(fs, paths, temporary, temporaryLinks));
|
|
1029
1032
|
if (released._tag === "Failure") return Object.freeze({
|
|
1030
1033
|
kind: "OutputUnsettled",
|
|
1031
|
-
primaryFailure: failure$
|
|
1034
|
+
primaryFailure: failure$6("publish-output", "OutputVerifyFailed", "temporary-link-release", input.outputPath, "Output committed but the owned temporary link did not settle"),
|
|
1032
1035
|
cleanupFailure: released.failure
|
|
1033
1036
|
});
|
|
1034
1037
|
temporary = void 0;
|
|
1035
1038
|
createdTemporary = void 0;
|
|
1036
1039
|
} else {
|
|
1037
|
-
yield* fs.rename(temporary.path, input.outputPath).pipe(mapPlatform$
|
|
1040
|
+
yield* fs.rename(temporary.path, input.outputPath).pipe(mapPlatform$6("publish-output", "OutputCommitFailed", "output-atomic-replace", input.outputPath));
|
|
1038
1041
|
committed = true;
|
|
1039
1042
|
temporary = void 0;
|
|
1040
1043
|
createdTemporary = void 0;
|
|
@@ -1056,7 +1059,7 @@ function publishOutput(input, options) {
|
|
|
1056
1059
|
});
|
|
1057
1060
|
if (cleanup?._tag === "Failure") return Object.freeze({
|
|
1058
1061
|
kind: committed ? "OutputUnsettled" : "RejectedBeforeOutputMutation",
|
|
1059
|
-
primaryFailure: failure$
|
|
1062
|
+
primaryFailure: failure$6("cleanup", "TemporaryFailed", "temporary-cleanup", temporary?.path ?? createdTemporary?.path, "Package output operation completed but its owned temporary did not settle"),
|
|
1060
1063
|
cleanupFailure: cleanup.failure
|
|
1061
1064
|
});
|
|
1062
1065
|
return attempted.success;
|
|
@@ -1068,7 +1071,7 @@ function validatePublicationInput(input) {
|
|
|
1068
1071
|
if (!(input.bytes instanceof Uint8Array)) throw new Error("Output bytes must be a Uint8Array");
|
|
1069
1072
|
if (!Number.isSafeInteger(input.maxPriorOutputBytes) || input.maxPriorOutputBytes < 0) throw new Error("maxPriorOutputBytes must be a safe non-negative integer");
|
|
1070
1073
|
},
|
|
1071
|
-
catch: (cause) => failure$
|
|
1074
|
+
catch: (cause) => failure$6("publish-output", "InvalidInput", "request", input.outputPath, errorMessage$4(cause))
|
|
1072
1075
|
});
|
|
1073
1076
|
}
|
|
1074
1077
|
const captureParent = Effect.fn("agentPluginPackageOutput.captureParent")(function* (fs, paths, outputPath) {
|
|
@@ -1080,10 +1083,10 @@ const captureParent = Effect.fn("agentPluginPackageOutput.captureParent")(functi
|
|
|
1080
1083
|
if (name.length === 0 || paths.join(parent, name) !== outputPath) throw new Error("Output must name one direct child file");
|
|
1081
1084
|
return parent;
|
|
1082
1085
|
},
|
|
1083
|
-
catch: (cause) => failure$
|
|
1086
|
+
catch: (cause) => failure$6("publish-output", "InvalidInput", "output-path", outputPath, errorMessage$4(cause))
|
|
1084
1087
|
});
|
|
1085
|
-
if ((yield* fs.realPath(parentPath).pipe(mapPlatform$
|
|
1086
|
-
const info = yield* fs.stat(parentPath).pipe(mapPlatform$
|
|
1088
|
+
if ((yield* fs.realPath(parentPath).pipe(mapPlatform$6("publish-output", "OutputParentUnsafe", "output-parent-realpath", parentPath))) !== parentPath) return yield* rejected("publish-output", "OutputParentUnsafe", "output-parent-realpath", parentPath, "Output parent must be its exact canonical path");
|
|
1089
|
+
const info = yield* fs.stat(parentPath).pipe(mapPlatform$6("publish-output", "OutputParentUnsafe", "output-parent", parentPath));
|
|
1087
1090
|
if (info.type !== "Directory") return yield* rejected("publish-output", "OutputParentUnsafe", "output-parent", parentPath, "Output parent must be a directory");
|
|
1088
1091
|
const ino = Option.getOrUndefined(info.ino);
|
|
1089
1092
|
if (ino === void 0) return yield* rejected("publish-output", "OutputParentUnsafe", "output-parent", parentPath, "Output parent identity is unavailable");
|
|
@@ -1095,12 +1098,12 @@ const captureParent = Effect.fn("agentPluginPackageOutput.captureParent")(functi
|
|
|
1095
1098
|
});
|
|
1096
1099
|
const revalidateParent = Effect.fn("agentPluginPackageOutput.revalidateParent")(function* (fs, parent, operation = "publish-output") {
|
|
1097
1100
|
const reason = operation === "cleanup" ? "TemporaryFailed" : "OutputParentUnsafe";
|
|
1098
|
-
const canonical = yield* fs.realPath(parent.path).pipe(mapPlatform$
|
|
1099
|
-
const info = yield* fs.stat(parent.path).pipe(mapPlatform$
|
|
1101
|
+
const canonical = yield* fs.realPath(parent.path).pipe(mapPlatform$6(operation, reason, "output-parent-revalidation", parent.path));
|
|
1102
|
+
const info = yield* fs.stat(parent.path).pipe(mapPlatform$6(operation, reason, "output-parent-revalidation", parent.path));
|
|
1100
1103
|
if (canonical !== parent.path || info.type !== "Directory" || info.dev !== parent.dev || Option.getOrUndefined(info.ino) !== parent.ino) return yield* rejected(operation, reason, "output-parent-revalidation", parent.path, "Output parent identity changed");
|
|
1101
1104
|
});
|
|
1102
1105
|
const captureOutput = Effect.fn("agentPluginPackageOutput.captureOutput")(function* (fs, outputPath, parent, maxBytes) {
|
|
1103
|
-
if (!(yield* fs.exists(outputPath).pipe(mapPlatform$
|
|
1106
|
+
if (!(yield* fs.exists(outputPath).pipe(mapPlatform$6("publish-output", "FilesystemFailed", "output-exists", outputPath)))) return Object.freeze({ kind: "Absent" });
|
|
1104
1107
|
const file = yield* captureRegularFile(fs, outputPath, parent, maxBytes, "OutputUnsafe", "output-capture");
|
|
1105
1108
|
return Object.freeze({
|
|
1106
1109
|
kind: "Present",
|
|
@@ -1108,16 +1111,16 @@ const captureOutput = Effect.fn("agentPluginPackageOutput.captureOutput")(functi
|
|
|
1108
1111
|
});
|
|
1109
1112
|
});
|
|
1110
1113
|
const captureRegularFile = Effect.fn("agentPluginPackageOutput.captureRegularFile")(function* (fs, filePath, parent, maxBytes, reason, phase) {
|
|
1111
|
-
const canonical = yield* fs.realPath(filePath).pipe(mapPlatform$
|
|
1112
|
-
const info = yield* fs.stat(filePath).pipe(mapPlatform$
|
|
1114
|
+
const canonical = yield* fs.realPath(filePath).pipe(mapPlatform$6("publish-output", reason, `${phase}-realpath`, filePath));
|
|
1115
|
+
const info = yield* fs.stat(filePath).pipe(mapPlatform$6("publish-output", reason, phase, filePath));
|
|
1113
1116
|
const ino = Option.getOrUndefined(info.ino);
|
|
1114
1117
|
const nlink = Option.getOrUndefined(info.nlink);
|
|
1115
1118
|
const mtime = Option.getOrUndefined(info.mtime)?.getTime();
|
|
1116
1119
|
const size = Number(info.size);
|
|
1117
1120
|
if (canonical !== filePath || info.type !== "File" || info.dev !== parent.dev || ino === void 0 || nlink !== 1n || mtime === void 0 || !Number.isSafeInteger(size) || size < 0 || size > maxBytes) return yield* rejected("publish-output", reason, phase, filePath, "Output must be one bounded canonical regular file in its captured parent");
|
|
1118
|
-
const bytes = yield* fs.readFile(filePath).pipe(mapPlatform$
|
|
1121
|
+
const bytes = yield* fs.readFile(filePath).pipe(mapPlatform$6("publish-output", reason, `${phase}-read`, filePath));
|
|
1119
1122
|
if (bytes.byteLength !== size) return yield* rejected("publish-output", reason, `${phase}-read`, filePath, "Output size changed while it was read");
|
|
1120
|
-
const after = yield* fs.stat(filePath).pipe(mapPlatform$
|
|
1123
|
+
const after = yield* fs.stat(filePath).pipe(mapPlatform$6("publish-output", reason, `${phase}-revalidation`, filePath));
|
|
1121
1124
|
if (after.type !== "File" || after.dev !== info.dev || Option.getOrUndefined(after.ino) !== ino || after.mode !== info.mode || Number(after.size) !== size || Option.getOrUndefined(after.mtime)?.getTime() !== mtime || Option.getOrUndefined(after.nlink) !== 1n) return yield* rejected("publish-output", reason, `${phase}-revalidation`, filePath, "Output identity changed while it was read");
|
|
1122
1125
|
return Object.freeze({
|
|
1123
1126
|
path: filePath,
|
|
@@ -1143,12 +1146,12 @@ const allocateTemporaryFile = Effect.fn("agentPluginPackageOutput.allocateTempor
|
|
|
1143
1146
|
const file = yield* fs.open(temporaryPath, {
|
|
1144
1147
|
flag: "wx",
|
|
1145
1148
|
mode: OUTPUT_MODE
|
|
1146
|
-
}).pipe(mapPlatform$
|
|
1149
|
+
}).pipe(mapPlatform$6("publish-output", "TemporaryFailed", "temporary-create", temporaryPath));
|
|
1147
1150
|
onCreated(Object.freeze({
|
|
1148
1151
|
parent,
|
|
1149
1152
|
path: temporaryPath
|
|
1150
1153
|
}));
|
|
1151
|
-
const fileInfo = yield* file.stat.pipe(mapPlatform$
|
|
1154
|
+
const fileInfo = yield* file.stat.pipe(mapPlatform$6("publish-output", "TemporaryFailed", "temporary-identity", temporaryPath));
|
|
1152
1155
|
const ino = Option.getOrUndefined(fileInfo.ino);
|
|
1153
1156
|
if (fileInfo.type !== "File" || fileInfo.dev !== parent.dev || ino === void 0 || Option.getOrUndefined(fileInfo.nlink) !== 1n) return yield* rejected("publish-output", "TemporaryFailed", "temporary-identity", temporaryPath, "Created temporary file descriptor did not provide one stable regular-file identity");
|
|
1154
1157
|
const captured = Object.freeze({
|
|
@@ -1158,11 +1161,11 @@ const allocateTemporaryFile = Effect.fn("agentPluginPackageOutput.allocateTempor
|
|
|
1158
1161
|
ino
|
|
1159
1162
|
});
|
|
1160
1163
|
onOwned(captured);
|
|
1161
|
-
yield* file.writeAll(bytes).pipe(mapPlatform$
|
|
1162
|
-
yield* file.sync.pipe(mapPlatform$
|
|
1164
|
+
yield* file.writeAll(bytes).pipe(mapPlatform$6("publish-output", "TemporaryFailed", "temporary-write", temporaryPath));
|
|
1165
|
+
yield* file.sync.pipe(mapPlatform$6("publish-output", "TemporaryFailed", "temporary-flush", temporaryPath));
|
|
1163
1166
|
return captured;
|
|
1164
1167
|
}));
|
|
1165
|
-
yield* fs.chmod(temporaryPath, OUTPUT_MODE).pipe(mapPlatform$
|
|
1168
|
+
yield* fs.chmod(temporaryPath, OUTPUT_MODE).pipe(mapPlatform$6("publish-output", "TemporaryFailed", "temporary-mode", temporaryPath));
|
|
1166
1169
|
yield* revalidateParent(fs, parent);
|
|
1167
1170
|
yield* revalidateOwnedTemporaryFile(fs, paths, owned, 1, "publish-output");
|
|
1168
1171
|
return owned;
|
|
@@ -1175,13 +1178,13 @@ const verifyTemporary = Effect.fn("agentPluginPackageOutput.verifyTemporary")(fu
|
|
|
1175
1178
|
const revalidateOwnedTemporaryFile = Effect.fn("agentPluginPackageOutput.revalidateOwnedTemporaryFile")(function* (fs, paths, owned, expectedLinks, operation) {
|
|
1176
1179
|
yield* revalidateParent(fs, owned.parent, operation);
|
|
1177
1180
|
if (paths.dirname(owned.path) !== owned.parent.path || !paths.basename(owned.path).startsWith(PRIVATE_TEMPORARY_PREFIX)) return yield* rejected(operation, "TemporaryFailed", "temporary-revalidation", owned.path, "Owned temporary escaped its exact output parent");
|
|
1178
|
-
const [canonical, info] = yield* Effect.all([fs.realPath(owned.path).pipe(mapPlatform$
|
|
1181
|
+
const [canonical, info] = yield* Effect.all([fs.realPath(owned.path).pipe(mapPlatform$6(operation, "TemporaryFailed", "temporary-revalidation", owned.path)), fs.stat(owned.path).pipe(mapPlatform$6(operation, "TemporaryFailed", "temporary-revalidation", owned.path))]);
|
|
1179
1182
|
if (canonical !== owned.path || info.type !== "File" || info.dev !== owned.dev || Option.getOrUndefined(info.ino) !== owned.ino || Option.getOrUndefined(info.nlink) !== BigInt(expectedLinks)) return yield* rejected(operation, "TemporaryFailed", "temporary-revalidation", owned.path, "Owned temporary identity changed");
|
|
1180
1183
|
});
|
|
1181
1184
|
const admitCreatedTemporaryFile = Effect.fn("agentPluginPackageOutput.admitCreatedTemporaryFile")(function* (fs, paths, created) {
|
|
1182
1185
|
yield* revalidateParent(fs, created.parent, "cleanup");
|
|
1183
1186
|
if (paths.dirname(created.path) !== created.parent.path || !paths.basename(created.path).startsWith(PRIVATE_TEMPORARY_PREFIX)) return yield* rejected("cleanup", "TemporaryFailed", "temporary-admission", created.path, "Created temporary escaped its exact output parent");
|
|
1184
|
-
const [canonical, info] = yield* Effect.all([fs.realPath(created.path).pipe(mapPlatform$
|
|
1187
|
+
const [canonical, info] = yield* Effect.all([fs.realPath(created.path).pipe(mapPlatform$6("cleanup", "TemporaryFailed", "temporary-admission", created.path)), fs.stat(created.path).pipe(mapPlatform$6("cleanup", "TemporaryFailed", "temporary-admission", created.path))]);
|
|
1185
1188
|
const ino = Option.getOrUndefined(info.ino);
|
|
1186
1189
|
if (canonical !== created.path || info.type !== "File" || info.dev !== created.parent.dev || ino === void 0 || Option.getOrUndefined(info.nlink) !== 1n) return yield* rejected("cleanup", "TemporaryFailed", "temporary-admission", created.path, "Created temporary could not be admitted as one owned regular file");
|
|
1187
1190
|
return Object.freeze({
|
|
@@ -1201,14 +1204,14 @@ const releaseOwnedTemporaryFile = Effect.fn("agentPluginPackageOutput.releaseOwn
|
|
|
1201
1204
|
yield* fs.remove(owned.path, {
|
|
1202
1205
|
recursive: false,
|
|
1203
1206
|
force: false
|
|
1204
|
-
}).pipe(mapPlatform$
|
|
1205
|
-
if (yield* fs.exists(owned.path).pipe(mapPlatform$
|
|
1207
|
+
}).pipe(mapPlatform$6("cleanup", "TemporaryFailed", "temporary-remove", owned.path));
|
|
1208
|
+
if (yield* fs.exists(owned.path).pipe(mapPlatform$6("cleanup", "TemporaryFailed", "temporary-remove-verification", owned.path))) return yield* rejected("cleanup", "TemporaryFailed", "temporary-remove-verification", owned.path, "Owned temporary cleanup did not settle");
|
|
1206
1209
|
yield* Effect.scoped(Effect.gen(function* () {
|
|
1207
|
-
yield* (yield* fs.open(owned.parent.path, { flag: "r" }).pipe(mapPlatform$
|
|
1210
|
+
yield* (yield* fs.open(owned.parent.path, { flag: "r" }).pipe(mapPlatform$6("cleanup", "TemporaryFailed", "temporary-parent-flush", owned.parent.path))).sync.pipe(mapPlatform$6("cleanup", "TemporaryFailed", "temporary-parent-flush", owned.parent.path));
|
|
1208
1211
|
}));
|
|
1209
1212
|
});
|
|
1210
1213
|
const revalidatePrior = Effect.fn("agentPluginPackageOutput.revalidatePrior")(function* (fs, outputPath, parent, prior, maxBytes) {
|
|
1211
|
-
const current = yield* captureOutput(fs, outputPath, parent, maxBytes).pipe(Effect.mapError((cause) => failure$
|
|
1214
|
+
const current = yield* captureOutput(fs, outputPath, parent, maxBytes).pipe(Effect.mapError((cause) => failure$6(cause.operation, "OutputChanged", cause.phase, cause.path, cause.detail)));
|
|
1212
1215
|
if (prior.kind === "Absent") {
|
|
1213
1216
|
if (current.kind !== "Absent") return yield* rejected("publish-output", "OutputChanged", "output-precommit", outputPath, "Absent output became occupied before no-replace publication");
|
|
1214
1217
|
return;
|
|
@@ -1226,7 +1229,7 @@ const verifyPublishedOutput = Effect.fn("agentPluginPackageOutput.verifyPublishe
|
|
|
1226
1229
|
});
|
|
1227
1230
|
function syncFile(fs, candidate, phase, reason) {
|
|
1228
1231
|
return Effect.scoped(Effect.gen(function* () {
|
|
1229
|
-
yield* (yield* fs.open(candidate, { flag: "r" }).pipe(mapPlatform$
|
|
1232
|
+
yield* (yield* fs.open(candidate, { flag: "r" }).pipe(mapPlatform$6("publish-output", reason, phase, candidate))).sync.pipe(mapPlatform$6("publish-output", reason, phase, candidate));
|
|
1230
1233
|
}));
|
|
1231
1234
|
}
|
|
1232
1235
|
function hitFailpoint(input, failpoints, point, temporaryPath) {
|
|
@@ -1241,16 +1244,16 @@ function hitFailpoint(input, failpoints, point, temporaryPath) {
|
|
|
1241
1244
|
await input.control?.onEvent?.(event);
|
|
1242
1245
|
await failpoints?.hit(point, event);
|
|
1243
1246
|
},
|
|
1244
|
-
catch: (cause) => failure$
|
|
1247
|
+
catch: (cause) => failure$6("publish-output", "FilesystemFailed", point, input.outputPath, `Provider failpoint failed: ${errorMessage$4(cause)}`)
|
|
1245
1248
|
});
|
|
1246
1249
|
}
|
|
1247
|
-
function mapPlatform$
|
|
1248
|
-
return (effect) => effect.pipe(Effect.mapError((cause) => failure$
|
|
1250
|
+
function mapPlatform$6(operation, reason, phase, candidate) {
|
|
1251
|
+
return (effect) => effect.pipe(Effect.mapError((cause) => failure$6(operation, reason, phase, candidate, cause.message)));
|
|
1249
1252
|
}
|
|
1250
1253
|
function rejected(operation, reason, phase, candidate, detail) {
|
|
1251
|
-
return Effect.fail(failure$
|
|
1254
|
+
return Effect.fail(failure$6(operation, reason, phase, candidate, detail));
|
|
1252
1255
|
}
|
|
1253
|
-
function failure$
|
|
1256
|
+
function failure$6(operation, reason, phase, candidate, detail) {
|
|
1254
1257
|
return Object.freeze({
|
|
1255
1258
|
_tag: "PackageOutputFailure",
|
|
1256
1259
|
operation,
|
|
@@ -1266,7 +1269,7 @@ function sameFileIdentity(left, right) {
|
|
|
1266
1269
|
function equalBytes$1(left, right) {
|
|
1267
1270
|
return left.byteLength === right.byteLength && left.every((value, index) => value === right[index]);
|
|
1268
1271
|
}
|
|
1269
|
-
function errorMessage$
|
|
1272
|
+
function errorMessage$4(error) {
|
|
1270
1273
|
return error instanceof Error ? error.message : String(error);
|
|
1271
1274
|
}
|
|
1272
1275
|
//#endregion
|
|
@@ -1443,7 +1446,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1443
1446
|
const consumedHandles = /* @__PURE__ */ new Set();
|
|
1444
1447
|
const inspectWorkspace = Effect.fn("contentWorkspace.inspect")(function* (input) {
|
|
1445
1448
|
const root = yield* requireCanonicalRoot(yield* FileSystem.FileSystem, input.locator, "inspect");
|
|
1446
|
-
if ((yield* gitText$1(gitExecutable, root, ["rev-parse", "--show-toplevel"], "inspect")) !== root) return yield* fail$
|
|
1449
|
+
if ((yield* gitText$1(gitExecutable, root, ["rev-parse", "--show-toplevel"], "inspect")) !== root) return yield* fail$5("inspect", "Aliased", root, "Workspace locator resolves to a different Git root");
|
|
1447
1450
|
const [refName, commit, tree, objectFormat, remoteNames] = yield* Effect.all([
|
|
1448
1451
|
gitText$1(gitExecutable, root, [
|
|
1449
1452
|
"symbolic-ref",
|
|
@@ -1475,7 +1478,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1475
1478
|
commit,
|
|
1476
1479
|
tree,
|
|
1477
1480
|
objectFormat,
|
|
1478
|
-
remoteUrls: Object.freeze(remoteUrls.flat().sort(compareText$
|
|
1481
|
+
remoteUrls: Object.freeze(remoteUrls.flat().sort(compareText$9))
|
|
1479
1482
|
});
|
|
1480
1483
|
});
|
|
1481
1484
|
const inspectGitWorkspace = Effect.fn("contentWorkspace.inspectGitWorkspace")(function* (input) {
|
|
@@ -1626,7 +1629,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1626
1629
|
validateLimit(input.maxBytes, "maxBytes", "read-git-blob-at-path");
|
|
1627
1630
|
});
|
|
1628
1631
|
const refCommit = yield* requireExactCommit(executable, root, input.refName, "read-git-blob-at-path");
|
|
1629
|
-
if (!(yield* localGitAncestry(executable, root, input.commit, refCommit, "read-git-blob-at-path"))) return yield* fail$
|
|
1632
|
+
if (!(yield* localGitAncestry(executable, root, input.commit, refCommit, "read-git-blob-at-path"))) return yield* fail$5("read-git-blob-at-path", "GitFailed", input.commit, "Selected commit is not reachable from the selected ref");
|
|
1630
1633
|
const commit = yield* requireExactCommit(executable, root, input.commit, "read-git-blob-at-path");
|
|
1631
1634
|
const tree = yield* gitText$1(executable, root, [
|
|
1632
1635
|
"rev-parse",
|
|
@@ -1634,7 +1637,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1634
1637
|
"--end-of-options",
|
|
1635
1638
|
`${commit}^{tree}`
|
|
1636
1639
|
], "read-git-blob-at-path");
|
|
1637
|
-
if (tree !== input.tree) return yield* fail$
|
|
1640
|
+
if (tree !== input.tree) return yield* fail$5("read-git-blob-at-path", "IdentityChanged", input.tree, "Commit tree differs");
|
|
1638
1641
|
const blob = yield* gitText$1(executable, root, [
|
|
1639
1642
|
"rev-parse",
|
|
1640
1643
|
"--verify",
|
|
@@ -1707,18 +1710,18 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1707
1710
|
});
|
|
1708
1711
|
const materializeContentTree = Effect.fn("contentWorkspace.materializeContentTree")(function* (input) {
|
|
1709
1712
|
const fs = yield* FileSystem.FileSystem;
|
|
1710
|
-
if (!materializeContentTreeInputValidator.Check(input)) return yield* fail$
|
|
1713
|
+
if (!materializeContentTreeInputValidator.Check(input)) return yield* fail$5("materialize-content-tree", "InvalidInput", void 0, "Content tree input does not match the bounded resource contract");
|
|
1711
1714
|
yield* checked("materialize-content-tree", () => validateContentTreeInput(input));
|
|
1712
1715
|
const parent = yield* requireContentTreeParent(fs, input.parentRoot);
|
|
1713
1716
|
const root = path.join(parent, input.directoryName);
|
|
1714
|
-
const present = yield* fs.exists(root).pipe(mapPlatform$
|
|
1717
|
+
const present = yield* fs.exists(root).pipe(mapPlatform$5("materialize-content-tree", root));
|
|
1715
1718
|
if (present) yield* requireContentTreeDirectory(fs, parent, root);
|
|
1716
1719
|
if (present && (yield* contentTreeMatches(fs, parent, root, input))) return Object.freeze({ root });
|
|
1717
1720
|
return yield* Effect.uninterruptibleMask((restore) => Effect.gen(function* () {
|
|
1718
1721
|
const stage = yield* fs.makeTempDirectory({
|
|
1719
1722
|
directory: parent,
|
|
1720
1723
|
prefix: CONTENT_TREE_STAGE_PREFIX
|
|
1721
|
-
}).pipe(mapPlatform$
|
|
1724
|
+
}).pipe(mapPlatform$5("materialize-content-tree", parent));
|
|
1722
1725
|
const attempted = yield* Effect.exit(restore(Effect.gen(function* () {
|
|
1723
1726
|
yield* requireContentTreeStage(fs, parent, stage);
|
|
1724
1727
|
yield* populateContentTree(fs, stage, input);
|
|
@@ -1734,7 +1737,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1734
1737
|
const fs = yield* FileSystem.FileSystem;
|
|
1735
1738
|
const root = yield* requireCanonicalRoot(fs, input.root, "capture");
|
|
1736
1739
|
yield* requireGitWorkspaceRoot(gitExecutable, root, "capture");
|
|
1737
|
-
const rootIdentity = yield* fs.stat(root).pipe(mapPlatform$
|
|
1740
|
+
const rootIdentity = yield* fs.stat(root).pipe(mapPlatform$5("capture", root));
|
|
1738
1741
|
yield* checked("capture", () => {
|
|
1739
1742
|
validateOpaque(input.readToken, "readToken", "capture");
|
|
1740
1743
|
validateLimits(input.maxEntries, input.maxBytes, "capture");
|
|
@@ -1743,7 +1746,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1743
1746
|
const budget = makeCaptureBudget(input);
|
|
1744
1747
|
const paths = yield* Effect.forEach(input.paths, (relative) => Effect.gen(function* () {
|
|
1745
1748
|
const candidate = yield* checked("capture", () => resolveContained(root, relative, false, "capture"));
|
|
1746
|
-
if (!(yield* fs.exists(candidate).pipe(mapPlatform$
|
|
1749
|
+
if (!(yield* fs.exists(candidate).pipe(mapPlatform$5("capture", candidate)))) return Object.freeze({
|
|
1747
1750
|
path: relative,
|
|
1748
1751
|
entries: null
|
|
1749
1752
|
});
|
|
@@ -1787,19 +1790,19 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1787
1790
|
validateOpaque(input.captureHandle, "captureHandle", "apply");
|
|
1788
1791
|
});
|
|
1789
1792
|
const authority = yield* requireCaptureAuthority(fs, captureAuthorities, consumedHandles, input.captureHandle, root, input.readToken, input.planDigest, "apply");
|
|
1790
|
-
if (authority.lifecycle === "Partial" || authority.lifecycle === "Applying" || authority.lifecycle === "Restoring") return yield* fail$
|
|
1791
|
-
if (authority.lifecycle === "Restored") return yield* fail$
|
|
1793
|
+
if (authority.lifecycle === "Partial" || authority.lifecycle === "Applying" || authority.lifecycle === "Restoring") return yield* fail$5("apply", "HandleState", void 0, `Capture handle is ${authority.lifecycle}`);
|
|
1794
|
+
if (authority.lifecycle === "Restored") return yield* fail$5("apply", "HandleConsumed", void 0, "Capture handle has already been restored");
|
|
1792
1795
|
yield* validateWriteSet(root, authority, input.writes);
|
|
1793
1796
|
if ((yield* Effect.forEach(input.writes, (write) => writeIsExact(fs, root, write, makeCaptureBudget(authority)))).every(Boolean)) {
|
|
1794
1797
|
authority.planDigest = input.planDigest;
|
|
1795
1798
|
authority.lifecycle = authority.lifecycle === "Applied" ? "Applied" : "Converged";
|
|
1796
1799
|
return receipt(input.planDigest, input.readToken, "Converged", []);
|
|
1797
1800
|
}
|
|
1798
|
-
if (authority.lifecycle !== "Captured") return yield* fail$
|
|
1801
|
+
if (authority.lifecycle !== "Captured") return yield* fail$5("apply", "HandleState", void 0, `Capture handle cannot apply from ${authority.lifecycle}`);
|
|
1799
1802
|
for (const write of input.writes) {
|
|
1800
1803
|
const expected = authority.preimages.get(write.path);
|
|
1801
|
-
if (expected === void 0) return yield* fail$
|
|
1802
|
-
if (!equalPreimage(yield* observePreimage(fs, root, write.path, "apply", makeCaptureBudget(authority)), expected)) return yield* fail$
|
|
1804
|
+
if (expected === void 0) return yield* fail$5("apply", "InvalidInput", write.path, "Write path has no captured preimage");
|
|
1805
|
+
if (!equalPreimage(yield* observePreimage(fs, root, write.path, "apply", makeCaptureBudget(authority)), expected)) return yield* fail$5("apply", "IdentityChanged", write.path, "Write path changed after capture");
|
|
1803
1806
|
}
|
|
1804
1807
|
authority.planDigest = input.planDigest;
|
|
1805
1808
|
authority.lifecycle = "Applying";
|
|
@@ -1808,11 +1811,11 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1808
1811
|
const expected = authority.preimages.get(write.path);
|
|
1809
1812
|
if (expected === void 0) {
|
|
1810
1813
|
authority.lifecycle = "Partial";
|
|
1811
|
-
return yield* fail$
|
|
1814
|
+
return yield* fail$5("apply", "InvalidInput", write.path, "Write path lost its captured preimage");
|
|
1812
1815
|
}
|
|
1813
1816
|
if (!equalPreimage(yield* observePreimage(fs, root, write.path, "apply", makeCaptureBudget(authority)), expected)) {
|
|
1814
1817
|
authority.lifecycle = "Partial";
|
|
1815
|
-
return yield* fail$
|
|
1818
|
+
return yield* fail$5("apply", "IdentityChanged", write.path, "Write path changed immediately before mutation");
|
|
1816
1819
|
}
|
|
1817
1820
|
authority.mutatedPaths.add(write.path);
|
|
1818
1821
|
const applied = yield* Effect.result(applyWrite(fs, root, write, makeCaptureBudget(authority)));
|
|
@@ -1842,12 +1845,12 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1842
1845
|
authority.lifecycle = "Restored";
|
|
1843
1846
|
return receipt(input.planDigest, input.readToken, "Restored", []);
|
|
1844
1847
|
}
|
|
1845
|
-
if (authority.lifecycle !== "Applied" && authority.lifecycle !== "Partial") return yield* fail$
|
|
1846
|
-
if (authority.uncertainPaths.size > 0) return yield* fail$
|
|
1848
|
+
if (authority.lifecycle !== "Applied" && authority.lifecycle !== "Partial") return yield* fail$5("restore", authority.lifecycle === "Restored" ? "HandleConsumed" : "HandleState", void 0, `Capture handle cannot restore from ${authority.lifecycle}`);
|
|
1849
|
+
if (authority.uncertainPaths.size > 0) return yield* fail$5("restore", "HandleState", void 0, "Capture handle has an unobservable partial postimage");
|
|
1847
1850
|
for (const relative of authority.paths) {
|
|
1848
1851
|
const preimage = authority.preimages.get(relative);
|
|
1849
1852
|
const postimage = authority.postimages.get(relative);
|
|
1850
|
-
if (preimage === void 0) return yield* fail$
|
|
1853
|
+
if (preimage === void 0) return yield* fail$5("restore", "HandleState", relative, "Capture evidence is incomplete");
|
|
1851
1854
|
const current = yield* observePreimage(fs, root, relative, "restore", makeCaptureBudget(authority));
|
|
1852
1855
|
if (equalPreimage(current, preimage)) {
|
|
1853
1856
|
if (authority.mutatedPaths.has(relative)) authority.restoredPaths.add(relative);
|
|
@@ -1855,7 +1858,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1855
1858
|
}
|
|
1856
1859
|
if (postimage === void 0 || !equalPreimage(current, postimage)) {
|
|
1857
1860
|
authority.lifecycle = "Partial";
|
|
1858
|
-
return yield* fail$
|
|
1861
|
+
return yield* fail$5("restore", "IdentityChanged", relative, "Path changed after apply; restore refused");
|
|
1859
1862
|
}
|
|
1860
1863
|
}
|
|
1861
1864
|
authority.lifecycle = "Restoring";
|
|
@@ -1866,7 +1869,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1866
1869
|
const postimage = authority.postimages.get(relative);
|
|
1867
1870
|
if (preimage === void 0 || postimage === void 0) {
|
|
1868
1871
|
authority.lifecycle = "Partial";
|
|
1869
|
-
return yield* fail$
|
|
1872
|
+
return yield* fail$5("restore", "HandleState", relative, "Restore evidence is incomplete");
|
|
1870
1873
|
}
|
|
1871
1874
|
const immediate = yield* observePreimage(fs, root, relative, "restore", makeCaptureBudget(authority));
|
|
1872
1875
|
if (equalPreimage(immediate, preimage)) {
|
|
@@ -1875,7 +1878,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1875
1878
|
}
|
|
1876
1879
|
if (!equalPreimage(immediate, postimage)) {
|
|
1877
1880
|
authority.lifecycle = "Partial";
|
|
1878
|
-
return yield* fail$
|
|
1881
|
+
return yield* fail$5("restore", "IdentityChanged", relative, "Path changed immediately before restore");
|
|
1879
1882
|
}
|
|
1880
1883
|
const restoredPath = yield* Effect.result(restorePreimage(fs, root, preimage, makeCaptureBudget(authority)));
|
|
1881
1884
|
if (restoredPath._tag === "Failure") {
|
|
@@ -1887,7 +1890,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1887
1890
|
}
|
|
1888
1891
|
if (!equalPreimage(yield* observePreimage(fs, root, relative, "restore", makeCaptureBudget(authority)), preimage)) {
|
|
1889
1892
|
authority.lifecycle = "Partial";
|
|
1890
|
-
return yield* fail$
|
|
1893
|
+
return yield* fail$5("restore", "IdentityChanged", relative, "Restored path did not match its captured preimage");
|
|
1891
1894
|
}
|
|
1892
1895
|
authority.restoredPaths.add(relative);
|
|
1893
1896
|
authority.postimages.set(relative, preimage);
|
|
@@ -1906,7 +1909,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1906
1909
|
validateOpaque(input.captureHandle, "captureHandle", "settle");
|
|
1907
1910
|
});
|
|
1908
1911
|
const authority = yield* requireCaptureAuthority(fs, captureAuthorities, consumedHandles, input.captureHandle, root, input.readToken, input.planDigest, "settle");
|
|
1909
|
-
if (authority.lifecycle !== "Applied" && authority.lifecycle !== "Converged" && authority.lifecycle !== "Restored") return yield* fail$
|
|
1912
|
+
if (authority.lifecycle !== "Applied" && authority.lifecycle !== "Converged" && authority.lifecycle !== "Restored") return yield* fail$5("settle", "HandleState", void 0, `Capture handle cannot settle from ${authority.lifecycle}`);
|
|
1910
1913
|
captureAuthorities.delete(input.captureHandle);
|
|
1911
1914
|
consumedHandles.add(input.captureHandle);
|
|
1912
1915
|
return Object.freeze({
|
|
@@ -1927,8 +1930,8 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1927
1930
|
const authority = yield* requireCaptureAuthority(fs, captureAuthorities, consumedHandles, input.captureHandle, root, input.readToken, void 0, "release");
|
|
1928
1931
|
const noMutation = authority.lifecycle === "Captured" || authority.lifecycle === "Converged";
|
|
1929
1932
|
const unsettled = authority.lifecycle === "Partial" || authority.lifecycle === "Applying" || authority.lifecycle === "Restoring";
|
|
1930
|
-
if (input.disposition === "NoMutation" && !noMutation) return yield* fail$
|
|
1931
|
-
if (input.disposition === "UnsettledRecovery" && !unsettled) return yield* fail$
|
|
1933
|
+
if (input.disposition === "NoMutation" && !noMutation) return yield* fail$5("release", "HandleState", void 0, `No-mutation release is false from ${authority.lifecycle}`);
|
|
1934
|
+
if (input.disposition === "UnsettledRecovery" && !unsettled) return yield* fail$5("release", "HandleState", void 0, `Unsettled release is false from ${authority.lifecycle}`);
|
|
1932
1935
|
captureAuthorities.delete(input.captureHandle);
|
|
1933
1936
|
consumedHandles.add(input.captureHandle);
|
|
1934
1937
|
return Object.freeze({
|
|
@@ -1998,22 +2001,22 @@ function readLocalTree(fs, root, objectFormat, maxEntries, maxBytes) {
|
|
|
1998
2001
|
let bytesRead = 0;
|
|
1999
2002
|
const walk = (directory, relative) => Effect.gen(function* () {
|
|
2000
2003
|
yield* requireExactExistingPath(fs, directory, "read-tree");
|
|
2001
|
-
if ((yield* fs.stat(directory).pipe(mapPlatform$
|
|
2002
|
-
const names = (yield* fs.readDirectory(directory).pipe(mapPlatform$
|
|
2004
|
+
if ((yield* fs.stat(directory).pipe(mapPlatform$5("read-tree", directory))).type !== "Directory") return yield* fail$5("read-tree", "UnsupportedEntry", directory, "Content tree root must be a directory");
|
|
2005
|
+
const names = (yield* fs.readDirectory(directory).pipe(mapPlatform$5("read-tree", directory))).sort(compareText$9);
|
|
2003
2006
|
for (const name of names) {
|
|
2004
2007
|
const childRelative = relative === "" ? name : `${relative}/${name}`;
|
|
2005
2008
|
yield* checked("read-tree", () => validateRelativePath(childRelative, false, "read-tree"));
|
|
2006
2009
|
const child = path.join(directory, name);
|
|
2007
2010
|
yield* requireExactExistingPath(fs, child, "read-tree");
|
|
2008
|
-
const childInfo = yield* fs.stat(child).pipe(mapPlatform$
|
|
2011
|
+
const childInfo = yield* fs.stat(child).pipe(mapPlatform$5("read-tree", child));
|
|
2009
2012
|
if (childInfo.type === "Directory") {
|
|
2010
2013
|
yield* walk(child, childRelative);
|
|
2011
2014
|
continue;
|
|
2012
2015
|
}
|
|
2013
|
-
if (childInfo.type !== "File") return yield* fail$
|
|
2014
|
-
if (entries.length >= maxEntries) return yield* fail$
|
|
2016
|
+
if (childInfo.type !== "File") return yield* fail$5("read-tree", "UnsupportedEntry", childRelative, "Content tree contains a non-regular entry");
|
|
2017
|
+
if (entries.length >= maxEntries) return yield* fail$5("read-tree", "LimitExceeded", childRelative, "Content tree exceeds maxEntries");
|
|
2015
2018
|
const remaining = maxBytes - bytesRead;
|
|
2016
|
-
if (remaining < 0) return yield* fail$
|
|
2019
|
+
if (remaining < 0) return yield* fail$5("read-tree", "LimitExceeded", childRelative, "Content tree exceeds maxBytes");
|
|
2017
2020
|
const bytes = yield* readBoundedRegularFile(fs, child, remaining, "read-tree");
|
|
2018
2021
|
bytesRead += bytes.byteLength;
|
|
2019
2022
|
entries.push(Object.freeze({
|
|
@@ -2023,18 +2026,18 @@ function readLocalTree(fs, root, objectFormat, maxEntries, maxBytes) {
|
|
|
2023
2026
|
}));
|
|
2024
2027
|
}
|
|
2025
2028
|
});
|
|
2026
|
-
return walk(root, "").pipe(Effect.map(() => Object.freeze(entries.sort((left, right) => compareText$
|
|
2029
|
+
return walk(root, "").pipe(Effect.map(() => Object.freeze(entries.sort((left, right) => compareText$9(left.path, right.path)))));
|
|
2027
2030
|
}
|
|
2028
2031
|
function captureTree(fs, root, operation, budget) {
|
|
2029
2032
|
const entries = [];
|
|
2030
2033
|
const walk = (candidate, relative) => Effect.gen(function* () {
|
|
2031
2034
|
yield* requireExactExistingPath(fs, candidate, operation);
|
|
2032
|
-
const info = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2033
|
-
if (budget.entries >= budget.maxEntries) return yield* fail$
|
|
2035
|
+
const info = yield* fs.stat(candidate).pipe(mapPlatform$5(operation, candidate));
|
|
2036
|
+
if (budget.entries >= budget.maxEntries) return yield* fail$5(operation, "LimitExceeded", candidate, "Captured paths exceed maxEntries");
|
|
2034
2037
|
budget.entries += 1;
|
|
2035
2038
|
if (info.type === "File") {
|
|
2036
2039
|
const remaining = budget.maxBytes - budget.bytes;
|
|
2037
|
-
if (remaining < 0 || info.size > BigInt(remaining)) return yield* fail$
|
|
2040
|
+
if (remaining < 0 || info.size > BigInt(remaining)) return yield* fail$5(operation, "LimitExceeded", candidate, "Captured paths exceed maxBytes");
|
|
2038
2041
|
const bytes = yield* readBoundedRegularFile(fs, candidate, remaining, operation);
|
|
2039
2042
|
budget.bytes += bytes.byteLength;
|
|
2040
2043
|
entries.push(Object.freeze({
|
|
@@ -2045,13 +2048,13 @@ function captureTree(fs, root, operation, budget) {
|
|
|
2045
2048
|
}));
|
|
2046
2049
|
return;
|
|
2047
2050
|
}
|
|
2048
|
-
if (info.type !== "Directory") return yield* fail$
|
|
2051
|
+
if (info.type !== "Directory") return yield* fail$5(operation, "UnsupportedEntry", candidate, "Path preimage contains a non-regular entry");
|
|
2049
2052
|
entries.push(Object.freeze({
|
|
2050
2053
|
kind: "Directory",
|
|
2051
2054
|
path: relative,
|
|
2052
2055
|
mode: info.mode & 511
|
|
2053
2056
|
}));
|
|
2054
|
-
const names = (yield* fs.readDirectory(candidate).pipe(mapPlatform$
|
|
2057
|
+
const names = (yield* fs.readDirectory(candidate).pipe(mapPlatform$5(operation, candidate))).sort(compareText$9);
|
|
2055
2058
|
for (const name of names) {
|
|
2056
2059
|
const nextRelative = relative === "" ? name : `${relative}/${name}`;
|
|
2057
2060
|
yield* checked(operation, () => validateRelativePath(nextRelative, false, operation));
|
|
@@ -2062,12 +2065,12 @@ function captureTree(fs, root, operation, budget) {
|
|
|
2062
2065
|
}
|
|
2063
2066
|
function removePathIfPresent(fs, candidate, operation, budget) {
|
|
2064
2067
|
return Effect.gen(function* () {
|
|
2065
|
-
if (!(yield* fs.exists(candidate).pipe(mapPlatform$
|
|
2068
|
+
if (!(yield* fs.exists(candidate).pipe(mapPlatform$5(operation, candidate)))) return;
|
|
2066
2069
|
const entries = yield* captureTree(fs, candidate, operation, budget);
|
|
2067
2070
|
for (const entry of [...entries].reverse()) {
|
|
2068
2071
|
const target = entry.path === "" ? candidate : path.join(candidate, ...entry.path.split("/"));
|
|
2069
2072
|
yield* requireExactExistingPath(fs, target, operation);
|
|
2070
|
-
if (entry.kind === "File") yield* fs.remove(target).pipe(mapPlatform$
|
|
2073
|
+
if (entry.kind === "File") yield* fs.remove(target).pipe(mapPlatform$5(operation, target));
|
|
2071
2074
|
else yield* removeEmptyDirectory(fs, target, operation);
|
|
2072
2075
|
}
|
|
2073
2076
|
});
|
|
@@ -2075,7 +2078,7 @@ function removePathIfPresent(fs, candidate, operation, budget) {
|
|
|
2075
2078
|
function observePreimage(fs, root, relative, operation, budget) {
|
|
2076
2079
|
return Effect.gen(function* () {
|
|
2077
2080
|
const candidate = yield* checked(operation, () => resolveContained(root, relative, false, operation));
|
|
2078
|
-
if (!(yield* fs.exists(candidate).pipe(mapPlatform$
|
|
2081
|
+
if (!(yield* fs.exists(candidate).pipe(mapPlatform$5(operation, candidate)))) return Object.freeze({
|
|
2079
2082
|
path: relative,
|
|
2080
2083
|
entries: null
|
|
2081
2084
|
});
|
|
@@ -2088,15 +2091,15 @@ function observePreimage(fs, root, relative, operation, budget) {
|
|
|
2088
2091
|
}
|
|
2089
2092
|
function requireCaptureAuthority(fs, authorities, consumed, handle, root, readToken, planDigest, operation) {
|
|
2090
2093
|
return Effect.gen(function* () {
|
|
2091
|
-
if (consumed.has(handle)) return yield* fail$
|
|
2094
|
+
if (consumed.has(handle)) return yield* fail$5(operation, "HandleConsumed", void 0, "Capture handle was already settled");
|
|
2092
2095
|
const authority = authorities.get(handle);
|
|
2093
|
-
if (authority === void 0) return yield* fail$
|
|
2094
|
-
if (authority.root !== root) return yield* fail$
|
|
2095
|
-
const rootIdentity = yield* fs.stat(root).pipe(mapPlatform$
|
|
2096
|
-
if (rootIdentity.dev !== authority.rootDev || !Equal.equals(rootIdentity.ino, authority.rootIno)) return yield* fail$
|
|
2097
|
-
if (authority.readToken !== readToken) return yield* fail$
|
|
2098
|
-
if (planDigest !== void 0 && authority.planDigest !== void 0 && authority.planDigest !== planDigest) return yield* fail$
|
|
2099
|
-
if (operation !== "apply" && operation !== "release" && authority.planDigest === void 0) return yield* fail$
|
|
2096
|
+
if (authority === void 0) return yield* fail$5(operation, "InvalidHandle", void 0, "Capture handle is not owned by this provider");
|
|
2097
|
+
if (authority.root !== root) return yield* fail$5(operation, "WrongRoot", root, "Capture handle belongs to a different Git root");
|
|
2098
|
+
const rootIdentity = yield* fs.stat(root).pipe(mapPlatform$5(operation, root));
|
|
2099
|
+
if (rootIdentity.dev !== authority.rootDev || !Equal.equals(rootIdentity.ino, authority.rootIno)) return yield* fail$5(operation, "WrongRoot", root, "Capture handle Git-root filesystem identity changed");
|
|
2100
|
+
if (authority.readToken !== readToken) return yield* fail$5(operation, "WrongToken", void 0, "Capture handle readToken does not match");
|
|
2101
|
+
if (planDigest !== void 0 && authority.planDigest !== void 0 && authority.planDigest !== planDigest) return yield* fail$5(operation, "WrongPlan", void 0, "Capture handle belongs to a different write plan");
|
|
2102
|
+
if (operation !== "apply" && operation !== "release" && authority.planDigest === void 0) return yield* fail$5(operation, "WrongPlan", void 0, "Capture handle has not been bound to a write plan");
|
|
2100
2103
|
return authority;
|
|
2101
2104
|
});
|
|
2102
2105
|
}
|
|
@@ -2116,7 +2119,7 @@ function validateContentTreeInput(input) {
|
|
|
2116
2119
|
let totalBytes = 0;
|
|
2117
2120
|
const exactPaths = /* @__PURE__ */ new Set();
|
|
2118
2121
|
for (const entry of input.entries) {
|
|
2119
|
-
if (previousPath !== void 0 && compareText$
|
|
2122
|
+
if (previousPath !== void 0 && compareText$9(previousPath, entry.path) >= 0) throw invalidInput(operation, entry.path, "Content tree entries must be in strict canonical path order");
|
|
2120
2123
|
previousPath = entry.path;
|
|
2121
2124
|
exactPaths.add(entry.path);
|
|
2122
2125
|
totalBytes += entry.bytes.byteLength;
|
|
@@ -2133,32 +2136,32 @@ function validateContentTreeInput(input) {
|
|
|
2133
2136
|
function requireContentTreeParent(fs, candidate) {
|
|
2134
2137
|
const operation = "materialize-content-tree";
|
|
2135
2138
|
return Effect.gen(function* () {
|
|
2136
|
-
if (!path.isAbsolute(candidate) || path.normalize(candidate) !== candidate || candidate === path.parse(candidate).root) return yield* fail$
|
|
2137
|
-
if ((yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2138
|
-
if ((yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2139
|
+
if (!path.isAbsolute(candidate) || path.normalize(candidate) !== candidate || candidate === path.parse(candidate).root) return yield* fail$5(operation, "InvalidInput", candidate, "Content tree parent must be a normalized non-root absolute path");
|
|
2140
|
+
if ((yield* fs.realPath(candidate).pipe(mapPlatform$5(operation, candidate))) !== candidate) return yield* fail$5(operation, "Aliased", candidate, "Content tree parent must be an exact non-symbolic path");
|
|
2141
|
+
if ((yield* fs.stat(candidate).pipe(mapPlatform$5(operation, candidate))).type !== "Directory") return yield* fail$5(operation, "UnsupportedEntry", candidate, "Content tree parent must be a directory");
|
|
2139
2142
|
return candidate;
|
|
2140
2143
|
});
|
|
2141
2144
|
}
|
|
2142
2145
|
function revalidateContentTreeParent(fs, parent) {
|
|
2143
2146
|
const operation = "materialize-content-tree";
|
|
2144
2147
|
return Effect.gen(function* () {
|
|
2145
|
-
const canonical = yield* fs.realPath(parent).pipe(mapPlatform$
|
|
2146
|
-
const info = yield* fs.stat(parent).pipe(mapPlatform$
|
|
2147
|
-
if (canonical !== parent || info.type !== "Directory") return yield* fail$
|
|
2148
|
+
const canonical = yield* fs.realPath(parent).pipe(mapPlatform$5(operation, parent));
|
|
2149
|
+
const info = yield* fs.stat(parent).pipe(mapPlatform$5(operation, parent));
|
|
2150
|
+
if (canonical !== parent || info.type !== "Directory") return yield* fail$5(operation, "IdentityChanged", parent, "Content tree parent path changed");
|
|
2148
2151
|
});
|
|
2149
2152
|
}
|
|
2150
2153
|
function requireContentTreeDirectory(fs, parent, candidate) {
|
|
2151
2154
|
const operation = "materialize-content-tree";
|
|
2152
2155
|
return Effect.gen(function* () {
|
|
2153
2156
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2154
|
-
if (path.dirname(candidate) !== parent) return yield* fail$
|
|
2155
|
-
if ((yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2156
|
-
if ((yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2157
|
+
if (path.dirname(candidate) !== parent) return yield* fail$5(operation, "IdentityChanged", candidate, "Disposable content tree must remain one direct child of its caller-owned parent");
|
|
2158
|
+
if ((yield* fs.realPath(candidate).pipe(mapPlatform$5(operation, candidate))) !== candidate) return yield* fail$5(operation, "Aliased", candidate, "Disposable content tree must be one exact non-symbolic directory");
|
|
2159
|
+
if ((yield* fs.stat(candidate).pipe(mapPlatform$5(operation, candidate))).type !== "Directory") return yield* fail$5(operation, "UnsupportedEntry", candidate, "Disposable content tree must be a directory");
|
|
2157
2160
|
});
|
|
2158
2161
|
}
|
|
2159
2162
|
function requireContentTreeStage(fs, parent, candidate) {
|
|
2160
2163
|
const operation = "materialize-content-tree";
|
|
2161
|
-
if (!path.basename(candidate).startsWith(CONTENT_TREE_STAGE_PREFIX)) return fail$
|
|
2164
|
+
if (!path.basename(candidate).startsWith(CONTENT_TREE_STAGE_PREFIX)) return fail$5(operation, "IdentityChanged", candidate, "Allocated content tree stage does not have the private stage prefix");
|
|
2162
2165
|
return requireContentTreeDirectory(fs, parent, candidate);
|
|
2163
2166
|
}
|
|
2164
2167
|
function populateContentTree(fs, root, input) {
|
|
@@ -2174,8 +2177,8 @@ function populateContentTree(fs, root, input) {
|
|
|
2174
2177
|
yield* fs.makeDirectory(directory, {
|
|
2175
2178
|
recursive: false,
|
|
2176
2179
|
mode: 448
|
|
2177
|
-
}).pipe(mapPlatform$
|
|
2178
|
-
yield* fs.chmod(directory, 448).pipe(mapPlatform$
|
|
2180
|
+
}).pipe(mapPlatform$5(operation, directory));
|
|
2181
|
+
yield* fs.chmod(directory, 448).pipe(mapPlatform$5(operation, directory));
|
|
2179
2182
|
createdDirectories.add(relativeDirectory);
|
|
2180
2183
|
}
|
|
2181
2184
|
const destination = path.join(root, ...segments);
|
|
@@ -2183,8 +2186,8 @@ function populateContentTree(fs, root, input) {
|
|
|
2183
2186
|
yield* fs.writeFile(destination, entry.bytes, {
|
|
2184
2187
|
flag: "wx",
|
|
2185
2188
|
mode
|
|
2186
|
-
}).pipe(mapPlatform$
|
|
2187
|
-
yield* fs.chmod(destination, mode).pipe(mapPlatform$
|
|
2189
|
+
}).pipe(mapPlatform$5(operation, destination));
|
|
2190
|
+
yield* fs.chmod(destination, mode).pipe(mapPlatform$5(operation, destination));
|
|
2188
2191
|
}
|
|
2189
2192
|
});
|
|
2190
2193
|
}
|
|
@@ -2217,14 +2220,14 @@ function removeContentTreeDirectory(fs, parent, candidate) {
|
|
|
2217
2220
|
yield* fs.remove(candidate, {
|
|
2218
2221
|
recursive: true,
|
|
2219
2222
|
force: false
|
|
2220
|
-
}).pipe(mapPlatform$
|
|
2223
|
+
}).pipe(mapPlatform$5(operation, candidate));
|
|
2221
2224
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2222
2225
|
});
|
|
2223
2226
|
}
|
|
2224
2227
|
function cleanupContentTreeStage(fs, parent, stage) {
|
|
2225
2228
|
const operation = "materialize-content-tree";
|
|
2226
2229
|
return Effect.gen(function* () {
|
|
2227
|
-
if (!(yield* fs.exists(stage).pipe(mapPlatform$
|
|
2230
|
+
if (!(yield* fs.exists(stage).pipe(mapPlatform$5(operation, stage)))) return;
|
|
2228
2231
|
yield* requireContentTreeStage(fs, parent, stage);
|
|
2229
2232
|
yield* removeContentTreeDirectory(fs, parent, stage);
|
|
2230
2233
|
});
|
|
@@ -2237,13 +2240,13 @@ function cutOverContentTree(fs, parent, root, stage, hadPreimage) {
|
|
|
2237
2240
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2238
2241
|
yield* requireContentTreeStage(fs, parent, stage);
|
|
2239
2242
|
yield* revalidateContentTreePreimage(fs, parent, root, hadPreimage);
|
|
2240
|
-
if (yield* fs.exists(backup).pipe(mapPlatform$
|
|
2243
|
+
if (yield* fs.exists(backup).pipe(mapPlatform$5(operation, backup))) return yield* fail$5(operation, "IdentityChanged", backup, "Private content tree backup path became occupied before cutover");
|
|
2241
2244
|
yield* restore(Effect.yieldNow);
|
|
2242
2245
|
if (hadPreimage) {
|
|
2243
|
-
yield* fs.rename(root, backup).pipe(mapPlatform$
|
|
2246
|
+
yield* fs.rename(root, backup).pipe(mapPlatform$5(operation, root));
|
|
2244
2247
|
yield* requireContentTreeDirectory(fs, parent, backup);
|
|
2245
2248
|
}
|
|
2246
|
-
yield* fs.rename(stage, root).pipe(mapPlatform$
|
|
2249
|
+
yield* fs.rename(stage, root).pipe(mapPlatform$5(operation, root));
|
|
2247
2250
|
yield* requireContentTreeDirectory(fs, parent, root);
|
|
2248
2251
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2249
2252
|
}));
|
|
@@ -2258,12 +2261,12 @@ function cutOverContentTree(fs, parent, root, stage, hadPreimage) {
|
|
|
2258
2261
|
function revalidateContentTreePreimage(fs, parent, root, hadPreimage) {
|
|
2259
2262
|
const operation = "materialize-content-tree";
|
|
2260
2263
|
return Effect.gen(function* () {
|
|
2261
|
-
const present = yield* fs.exists(root).pipe(mapPlatform$
|
|
2264
|
+
const present = yield* fs.exists(root).pipe(mapPlatform$5(operation, root));
|
|
2262
2265
|
if (!hadPreimage) {
|
|
2263
|
-
if (present) return yield* fail$
|
|
2266
|
+
if (present) return yield* fail$5(operation, "IdentityChanged", root, "Absent disposable content tree became occupied before cutover");
|
|
2264
2267
|
return;
|
|
2265
2268
|
}
|
|
2266
|
-
if (!present) return yield* fail$
|
|
2269
|
+
if (!present) return yield* fail$5(operation, "IdentityChanged", root, "Prior disposable content tree disappeared before cutover");
|
|
2267
2270
|
yield* requireContentTreeDirectory(fs, parent, root);
|
|
2268
2271
|
});
|
|
2269
2272
|
}
|
|
@@ -2271,27 +2274,27 @@ function restoreContentTreeCutover(fs, parent, root, stage, backup, hadPreimage)
|
|
|
2271
2274
|
const operation = "materialize-content-tree";
|
|
2272
2275
|
return Effect.gen(function* () {
|
|
2273
2276
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2274
|
-
const rootPresent = yield* fs.exists(root).pipe(mapPlatform$
|
|
2275
|
-
const stagePresent = yield* fs.exists(stage).pipe(mapPlatform$
|
|
2277
|
+
const rootPresent = yield* fs.exists(root).pipe(mapPlatform$5(operation, root));
|
|
2278
|
+
const stagePresent = yield* fs.exists(stage).pipe(mapPlatform$5(operation, stage));
|
|
2276
2279
|
if (!hadPreimage) {
|
|
2277
2280
|
if (rootPresent) {
|
|
2278
|
-
if (stagePresent) return yield* fail$
|
|
2281
|
+
if (stagePresent) return yield* fail$5(operation, "CleanupFailed", root, "Cannot distinguish an installed tree while its private stage also exists");
|
|
2279
2282
|
yield* removeContentTreeDirectory(fs, parent, root);
|
|
2280
2283
|
}
|
|
2281
2284
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2282
2285
|
return;
|
|
2283
2286
|
}
|
|
2284
|
-
if (!(yield* fs.exists(backup).pipe(mapPlatform$
|
|
2285
|
-
if (!rootPresent) return yield* fail$
|
|
2287
|
+
if (!(yield* fs.exists(backup).pipe(mapPlatform$5(operation, backup)))) {
|
|
2288
|
+
if (!rootPresent) return yield* fail$5(operation, "CleanupFailed", root, "Prior content tree and its private backup are both absent");
|
|
2286
2289
|
yield* requireContentTreeDirectory(fs, parent, root);
|
|
2287
2290
|
return;
|
|
2288
2291
|
}
|
|
2289
2292
|
yield* requireContentTreeDirectory(fs, parent, backup);
|
|
2290
2293
|
if (rootPresent) {
|
|
2291
|
-
if (stagePresent) return yield* fail$
|
|
2294
|
+
if (stagePresent) return yield* fail$5(operation, "CleanupFailed", root, "Cannot replace an unexpected root while the private stage still exists");
|
|
2292
2295
|
yield* removeContentTreeDirectory(fs, parent, root);
|
|
2293
2296
|
}
|
|
2294
|
-
yield* fs.rename(backup, root).pipe(mapPlatform$
|
|
2297
|
+
yield* fs.rename(backup, root).pipe(mapPlatform$5(operation, root));
|
|
2295
2298
|
yield* requireContentTreeDirectory(fs, parent, root);
|
|
2296
2299
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2297
2300
|
});
|
|
@@ -2370,12 +2373,12 @@ function replaceTree(fs, candidate, entries, operation, budget) {
|
|
|
2370
2373
|
yield* fs.makeDirectory(candidate, {
|
|
2371
2374
|
recursive: false,
|
|
2372
2375
|
mode: 448
|
|
2373
|
-
}).pipe(mapPlatform$
|
|
2376
|
+
}).pipe(mapPlatform$5(operation, candidate));
|
|
2374
2377
|
yield* requireExactExistingPath(fs, candidate, operation);
|
|
2375
2378
|
const seen = /* @__PURE__ */ new Set();
|
|
2376
2379
|
for (const entry of entries) {
|
|
2377
2380
|
yield* checked(operation, () => validateRelativePath(entry.path, false, operation));
|
|
2378
|
-
if (seen.has(entry.path)) return yield* fail$
|
|
2381
|
+
if (seen.has(entry.path)) return yield* fail$5(operation, "InvalidInput", entry.path, "Replacement tree has duplicate paths");
|
|
2379
2382
|
seen.add(entry.path);
|
|
2380
2383
|
yield* writeAtomic(fs, path.join(candidate, ...entry.path.split("/")), entry.bytes, fileMode(entry.mode), operation);
|
|
2381
2384
|
}
|
|
@@ -2403,12 +2406,12 @@ function restoreTree(fs, candidate, entries) {
|
|
|
2403
2406
|
for (const entry of directories) {
|
|
2404
2407
|
const destination = entry.path === "" ? candidate : path.join(candidate, ...entry.path.split("/"));
|
|
2405
2408
|
yield* ensureDirectoryChain(fs, path.dirname(destination), "restore");
|
|
2406
|
-
if (!(yield* fs.exists(destination).pipe(mapPlatform$
|
|
2409
|
+
if (!(yield* fs.exists(destination).pipe(mapPlatform$5("restore", destination)))) yield* fs.makeDirectory(destination, {
|
|
2407
2410
|
recursive: false,
|
|
2408
2411
|
mode: entry.mode
|
|
2409
|
-
}).pipe(mapPlatform$
|
|
2412
|
+
}).pipe(mapPlatform$5("restore", destination));
|
|
2410
2413
|
yield* requireExactExistingPath(fs, destination, "restore");
|
|
2411
|
-
yield* fs.chmod(destination, entry.mode).pipe(mapPlatform$
|
|
2414
|
+
yield* fs.chmod(destination, entry.mode).pipe(mapPlatform$5("restore", destination));
|
|
2412
2415
|
}
|
|
2413
2416
|
for (const entry of entries) {
|
|
2414
2417
|
if (entry.kind !== "File") continue;
|
|
@@ -2424,30 +2427,30 @@ function writeAtomic(fs, destination, bytes, mode, operation) {
|
|
|
2424
2427
|
yield* Effect.acquireUseRelease(fs.writeFile(temporary, bytes, {
|
|
2425
2428
|
flag: "wx",
|
|
2426
2429
|
mode: 384
|
|
2427
|
-
}).pipe(mapPlatform$
|
|
2428
|
-
yield* fs.chmod(owned, mode).pipe(mapPlatform$
|
|
2429
|
-
yield* fs.rename(owned, destination).pipe(mapPlatform$
|
|
2430
|
+
}).pipe(mapPlatform$5(operation, temporary), Effect.as(temporary)), (owned) => Effect.gen(function* () {
|
|
2431
|
+
yield* fs.chmod(owned, mode).pipe(mapPlatform$5(operation, owned));
|
|
2432
|
+
yield* fs.rename(owned, destination).pipe(mapPlatform$5(operation, destination));
|
|
2430
2433
|
}), (owned) => fs.exists(owned).pipe(Effect.flatMap((exists) => exists ? fs.remove(owned, { force: false }) : Effect.void), Effect.ignore));
|
|
2431
2434
|
});
|
|
2432
2435
|
}
|
|
2433
2436
|
function readBoundedRegularFile(fs, candidate, maxBytes, operation) {
|
|
2434
2437
|
return Effect.gen(function* () {
|
|
2435
|
-
if ((yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2436
|
-
const before = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2437
|
-
if (before.type !== "File") return yield* fail$
|
|
2438
|
-
if (before.size > BigInt(maxBytes)) return yield* fail$
|
|
2439
|
-
const bytes = yield* fs.readFile(candidate).pipe(mapPlatform$
|
|
2440
|
-
const after = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2441
|
-
if (after.type !== "File" || before.dev !== after.dev || !Equal.equals(before.ino, after.ino) || before.size !== after.size || bytes.byteLength !== Number(after.size)) return yield* fail$
|
|
2438
|
+
if ((yield* fs.realPath(candidate).pipe(mapPlatform$5(operation, candidate))) !== candidate) return yield* fail$5(operation, "Aliased", candidate, "File path is not canonical");
|
|
2439
|
+
const before = yield* fs.stat(candidate).pipe(mapPlatform$5(operation, candidate));
|
|
2440
|
+
if (before.type !== "File") return yield* fail$5(operation, "UnsupportedEntry", candidate, "Expected a regular file");
|
|
2441
|
+
if (before.size > BigInt(maxBytes)) return yield* fail$5(operation, "LimitExceeded", candidate, "File exceeds maxBytes");
|
|
2442
|
+
const bytes = yield* fs.readFile(candidate).pipe(mapPlatform$5(operation, candidate));
|
|
2443
|
+
const after = yield* fs.stat(candidate).pipe(mapPlatform$5(operation, candidate));
|
|
2444
|
+
if (after.type !== "File" || before.dev !== after.dev || !Equal.equals(before.ino, after.ino) || before.size !== after.size || bytes.byteLength !== Number(after.size)) return yield* fail$5(operation, "IdentityChanged", candidate, "File identity changed while reading");
|
|
2442
2445
|
return bytes;
|
|
2443
2446
|
});
|
|
2444
2447
|
}
|
|
2445
2448
|
function requireCanonicalRoot(fs, candidate, operation) {
|
|
2446
2449
|
return Effect.gen(function* () {
|
|
2447
|
-
if (!path.isAbsolute(candidate) || path.normalize(candidate) !== candidate) return yield* fail$
|
|
2448
|
-
const canonical = yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2449
|
-
const info = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2450
|
-
if (canonical !== candidate || info.type !== "Directory") return yield* fail$
|
|
2450
|
+
if (!path.isAbsolute(candidate) || path.normalize(candidate) !== candidate) return yield* fail$5(operation, "InvalidInput", candidate, "Workspace root must be a normalized absolute path");
|
|
2451
|
+
const canonical = yield* fs.realPath(candidate).pipe(mapPlatform$5(operation, candidate));
|
|
2452
|
+
const info = yield* fs.stat(candidate).pipe(mapPlatform$5(operation, candidate));
|
|
2453
|
+
if (canonical !== candidate || info.type !== "Directory") return yield* fail$5(operation, "Aliased", candidate, "Workspace root must be a canonical directory");
|
|
2451
2454
|
return candidate;
|
|
2452
2455
|
});
|
|
2453
2456
|
}
|
|
@@ -2458,14 +2461,14 @@ function requireExactGitRoot(fs, executable, candidate, operation) {
|
|
|
2458
2461
|
"rev-parse",
|
|
2459
2462
|
"--path-format=absolute",
|
|
2460
2463
|
"--show-toplevel"
|
|
2461
|
-
], operation)) !== root) return yield* fail$
|
|
2464
|
+
], operation)) !== root) return yield* fail$5(operation, "Aliased", root, "Workspace locator is not the exact Git root");
|
|
2462
2465
|
return root;
|
|
2463
2466
|
});
|
|
2464
2467
|
}
|
|
2465
2468
|
function observeGitWorkspaceAnchor(fs, executable, locator, input, operation) {
|
|
2466
2469
|
return Effect.gen(function* () {
|
|
2467
2470
|
const root = yield* requireExactGitRoot(fs, executable, locator, operation);
|
|
2468
|
-
const rootInfo = yield* fs.stat(root).pipe(mapPlatform$
|
|
2471
|
+
const rootInfo = yield* fs.stat(root).pipe(mapPlatform$5(operation, root));
|
|
2469
2472
|
const objectFormat = yield* gitObjectFormat$1(executable, root, operation);
|
|
2470
2473
|
const refName = yield* gitText$1(executable, root, [
|
|
2471
2474
|
"symbolic-ref",
|
|
@@ -2528,7 +2531,7 @@ function observeClosingGitStagedIndexBinding(fs, executable, input, operation) {
|
|
|
2528
2531
|
function stagedRegularBlobObjectIds(entries, materializedPaths, materializedRoots) {
|
|
2529
2532
|
const objectIds = /* @__PURE__ */ new Set();
|
|
2530
2533
|
for (const entry of entries) if ((materializedPaths.includes(entry.path) || materializedRoots.some((root) => entry.path === root || entry.path.startsWith(`${root}/`))) && entry.stage === 0 && (entry.mode === "100644" || entry.mode === "100755")) objectIds.add(entry.objectId);
|
|
2531
|
-
return Object.freeze([...objectIds].sort(compareText$
|
|
2534
|
+
return Object.freeze([...objectIds].sort(compareText$9));
|
|
2532
2535
|
}
|
|
2533
2536
|
function observeGitWorktreeObjectIds(fs, executable, root, admittedPaths, objectFormat, maxFileBytes, maxTotalBytes) {
|
|
2534
2537
|
const operation = "capture-git-evidence";
|
|
@@ -2541,7 +2544,7 @@ function observeGitWorktreeObjectIds(fs, executable, root, admittedPaths, object
|
|
|
2541
2544
|
"hash-object",
|
|
2542
2545
|
"--no-filters",
|
|
2543
2546
|
"--stdin-paths"
|
|
2544
|
-
], operation, outputLimit, `${admittedPaths.join("\n")}\n`).pipe(Effect.flatMap((result) => result.exitCode === 0 ? Effect.succeed(result.stdout) : fail$
|
|
2547
|
+
], operation, outputLimit, `${admittedPaths.join("\n")}\n`).pipe(Effect.flatMap((result) => result.exitCode === 0 ? Effect.succeed(result.stdout) : fail$5(operation, "GitFailed", root, gitFailureDetail$2(["hash-object", "--stdin-paths"], result.stderr))));
|
|
2545
2548
|
const objectIds = yield* checked(operation, () => parseGitObjectIdLines(output, admittedPaths.length, objectFormat, operation));
|
|
2546
2549
|
yield* Effect.forEach(identities, (identity) => revalidateGitWorktreeFileIdentity(fs, identity, operation), {
|
|
2547
2550
|
concurrency: 32,
|
|
@@ -2556,10 +2559,10 @@ function observeGitWorktreeObjectIds(fs, executable, root, admittedPaths, object
|
|
|
2556
2559
|
function inspectGitWorktreeFileIdentity(fs, root, relativePath, maxBytes, operation) {
|
|
2557
2560
|
const candidate = path.join(root, relativePath);
|
|
2558
2561
|
return Effect.gen(function* () {
|
|
2559
|
-
if ((yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2560
|
-
const observed = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2561
|
-
if (observed.type !== "File") return yield* fail$
|
|
2562
|
-
if (observed.size > BigInt(maxBytes)) return yield* fail$
|
|
2562
|
+
if ((yield* fs.realPath(candidate).pipe(mapPlatform$5(operation, candidate))) !== candidate) return yield* fail$5(operation, "Aliased", candidate, "File path is not canonical");
|
|
2563
|
+
const observed = yield* fs.stat(candidate).pipe(mapPlatform$5(operation, candidate));
|
|
2564
|
+
if (observed.type !== "File") return yield* fail$5(operation, "UnsupportedEntry", candidate, "Expected a regular file");
|
|
2565
|
+
if (observed.size > BigInt(maxBytes)) return yield* fail$5(operation, "LimitExceeded", candidate, "File exceeds maxBytes");
|
|
2563
2566
|
return Object.freeze({
|
|
2564
2567
|
candidate,
|
|
2565
2568
|
device: observed.dev,
|
|
@@ -2570,16 +2573,16 @@ function inspectGitWorktreeFileIdentity(fs, root, relativePath, maxBytes, operat
|
|
|
2570
2573
|
}
|
|
2571
2574
|
function revalidateGitWorktreeFileIdentity(fs, identity, operation) {
|
|
2572
2575
|
return Effect.gen(function* () {
|
|
2573
|
-
const canonical = yield* fs.realPath(identity.candidate).pipe(mapPlatform$
|
|
2574
|
-
const observed = yield* fs.stat(identity.candidate).pipe(mapPlatform$
|
|
2575
|
-
if (canonical !== identity.candidate || observed.type !== "File" || !Equal.equals(identity.device, observed.dev) || !Equal.equals(identity.inode, observed.ino) || identity.size !== observed.size) return yield* fail$
|
|
2576
|
+
const canonical = yield* fs.realPath(identity.candidate).pipe(mapPlatform$5(operation, identity.candidate));
|
|
2577
|
+
const observed = yield* fs.stat(identity.candidate).pipe(mapPlatform$5(operation, identity.candidate));
|
|
2578
|
+
if (canonical !== identity.candidate || observed.type !== "File" || !Equal.equals(identity.device, observed.dev) || !Equal.equals(identity.inode, observed.ino) || identity.size !== observed.size) return yield* fail$5(operation, "IdentityChanged", identity.candidate, "File identity changed while hashing");
|
|
2576
2579
|
});
|
|
2577
2580
|
}
|
|
2578
2581
|
function requireAggregateWorktreeBound(identities, maxBytes, operation) {
|
|
2579
2582
|
let total = 0n;
|
|
2580
2583
|
for (const identity of identities) {
|
|
2581
2584
|
total += identity.size;
|
|
2582
|
-
if (total > BigInt(maxBytes)) throw failure$
|
|
2585
|
+
if (total > BigInt(maxBytes)) throw failure$5(operation, "LimitExceeded", identity.candidate, "Admitted worktree files exceed maxBytes");
|
|
2583
2586
|
}
|
|
2584
2587
|
}
|
|
2585
2588
|
function gitObjectIdLinesOutputLimit(count, objectFormat, operation) {
|
|
@@ -2592,12 +2595,12 @@ function parseGitObjectIdLines(output, expectedCount, objectFormat, operation) {
|
|
|
2592
2595
|
try {
|
|
2593
2596
|
encoded = decoder$2.decode(output);
|
|
2594
2597
|
} catch {
|
|
2595
|
-
throw failure$
|
|
2598
|
+
throw failure$5(operation, "GitFailed", void 0, "Git worktree object output is not UTF-8");
|
|
2596
2599
|
}
|
|
2597
|
-
if (!encoded.endsWith("\n")) throw failure$
|
|
2600
|
+
if (!encoded.endsWith("\n")) throw failure$5(operation, "GitFailed", void 0, "Git worktree object output is truncated");
|
|
2598
2601
|
const objectIds = encoded.slice(0, -1).split("\n");
|
|
2599
2602
|
const pattern = objectFormat === "sha1" ? /^[0-9a-f]{40}$/u : /^[0-9a-f]{64}$/u;
|
|
2600
|
-
if (objectIds.length !== expectedCount || objectIds.some((objectId) => !pattern.test(objectId))) throw failure$
|
|
2603
|
+
if (objectIds.length !== expectedCount || objectIds.some((objectId) => !pattern.test(objectId))) throw failure$5(operation, "GitFailed", void 0, "Git worktree object output is malformed");
|
|
2601
2604
|
return Object.freeze(objectIds);
|
|
2602
2605
|
}
|
|
2603
2606
|
function readSelectedRemoteUrls(executable, root, selection, operation) {
|
|
@@ -2615,7 +2618,7 @@ function readSelectedRemoteUrls(executable, root, selection, operation) {
|
|
|
2615
2618
|
"--all",
|
|
2616
2619
|
remoteName
|
|
2617
2620
|
], operation));
|
|
2618
|
-
return Object.freeze(remoteUrls.flat().sort(compareText$
|
|
2621
|
+
return Object.freeze(remoteUrls.flat().sort(compareText$9));
|
|
2619
2622
|
});
|
|
2620
2623
|
}
|
|
2621
2624
|
function readGitStatus(executable, root, maxBytes) {
|
|
@@ -2648,7 +2651,7 @@ function requireGitObjectType(executable, root, object, expected, operation) {
|
|
|
2648
2651
|
"cat-file",
|
|
2649
2652
|
"-t",
|
|
2650
2653
|
object
|
|
2651
|
-
], operation).pipe(Effect.flatMap((observed) => observed === expected ? Effect.void : fail$
|
|
2654
|
+
], operation).pipe(Effect.flatMap((observed) => observed === expected ? Effect.void : fail$5(operation, "UnsupportedEntry", object, `Git object is not a ${expected}`)));
|
|
2652
2655
|
}
|
|
2653
2656
|
function requireExactCommit(executable, root, candidate, operation) {
|
|
2654
2657
|
return gitText$1(executable, root, [
|
|
@@ -2656,7 +2659,7 @@ function requireExactCommit(executable, root, candidate, operation) {
|
|
|
2656
2659
|
"--verify",
|
|
2657
2660
|
"--end-of-options",
|
|
2658
2661
|
`${candidate}^{commit}`
|
|
2659
|
-
], operation).pipe(Effect.flatMap((observed) => candidate === "HEAD" || candidate.startsWith("refs/") || observed === candidate ? Effect.succeed(observed) : fail$
|
|
2662
|
+
], operation).pipe(Effect.flatMap((observed) => candidate === "HEAD" || candidate.startsWith("refs/") || observed === candidate ? Effect.succeed(observed) : fail$5(operation, "IdentityChanged", candidate, "Git commit selection is not exact")));
|
|
2660
2663
|
}
|
|
2661
2664
|
function localGitAncestry(executable, root, ancestor, descendant, operation) {
|
|
2662
2665
|
return gitExitCode(executable, root, [
|
|
@@ -2667,18 +2670,18 @@ function localGitAncestry(executable, root, ancestor, descendant, operation) {
|
|
|
2667
2670
|
], operation).pipe(Effect.flatMap((code) => {
|
|
2668
2671
|
if (code === 0) return Effect.succeed(true);
|
|
2669
2672
|
if (code === 1) return Effect.succeed(false);
|
|
2670
|
-
return fail$
|
|
2673
|
+
return fail$5(operation, "GitFailed", root, `Git ancestry query exited ${code}`);
|
|
2671
2674
|
}));
|
|
2672
2675
|
}
|
|
2673
2676
|
function requireGitWorkspaceRoot(gitExecutable, root, operation) {
|
|
2674
2677
|
return Effect.gen(function* () {
|
|
2675
|
-
if (root === path.parse(root).root) return yield* fail$
|
|
2676
|
-
if ((yield* gitText$1(gitExecutable, root, ["rev-parse", "--show-toplevel"], operation)) !== root) return yield* fail$
|
|
2678
|
+
if (root === path.parse(root).root) return yield* fail$5(operation, "InvalidInput", root, "Filesystem root cannot be a content workspace mutation root");
|
|
2679
|
+
if ((yield* gitText$1(gitExecutable, root, ["rev-parse", "--show-toplevel"], operation)) !== root) return yield* fail$5(operation, "Aliased", root, "Mutation root must be the exact Git workspace root");
|
|
2677
2680
|
});
|
|
2678
2681
|
}
|
|
2679
2682
|
function requireExactExistingPath(fs, candidate, operation) {
|
|
2680
2683
|
return Effect.gen(function* () {
|
|
2681
|
-
if ((yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2684
|
+
if ((yield* fs.realPath(candidate).pipe(mapPlatform$5(operation, candidate))) !== candidate) return yield* fail$5(operation, "Aliased", candidate, "Refusing to traverse an aliased or symbolic path");
|
|
2682
2685
|
});
|
|
2683
2686
|
}
|
|
2684
2687
|
function ensureDirectoryChain(fs, directory, operation) {
|
|
@@ -2688,28 +2691,28 @@ function ensureDirectoryChain(fs, directory, operation) {
|
|
|
2688
2691
|
let current = parsed.root;
|
|
2689
2692
|
for (const segment of segments) {
|
|
2690
2693
|
current = path.join(current, segment);
|
|
2691
|
-
if (!(yield* fs.exists(current).pipe(mapPlatform$
|
|
2694
|
+
if (!(yield* fs.exists(current).pipe(mapPlatform$5(operation, current)))) yield* fs.makeDirectory(current, {
|
|
2692
2695
|
recursive: false,
|
|
2693
2696
|
mode: 448
|
|
2694
|
-
}).pipe(mapPlatform$
|
|
2697
|
+
}).pipe(mapPlatform$5(operation, current));
|
|
2695
2698
|
yield* requireExactExistingPath(fs, current, operation);
|
|
2696
|
-
if ((yield* fs.stat(current).pipe(mapPlatform$
|
|
2699
|
+
if ((yield* fs.stat(current).pipe(mapPlatform$5(operation, current))).type !== "Directory") return yield* fail$5(operation, "UnsupportedEntry", current, "Write parent must be a directory");
|
|
2697
2700
|
}
|
|
2698
2701
|
});
|
|
2699
2702
|
}
|
|
2700
2703
|
function removeEmptyDirectory(fs, candidate, operation) {
|
|
2701
2704
|
return Effect.gen(function* () {
|
|
2702
2705
|
yield* requireExactExistingPath(fs, candidate, operation);
|
|
2703
|
-
const before = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2704
|
-
const entries = yield* fs.readDirectory(candidate).pipe(mapPlatform$
|
|
2705
|
-
if (before.type !== "Directory" || entries.length !== 0) return yield* fail$
|
|
2706
|
+
const before = yield* fs.stat(candidate).pipe(mapPlatform$5(operation, candidate));
|
|
2707
|
+
const entries = yield* fs.readDirectory(candidate).pipe(mapPlatform$5(operation, candidate));
|
|
2708
|
+
if (before.type !== "Directory" || entries.length !== 0) return yield* fail$5(operation, "IdentityChanged", candidate, "Exact directory is no longer empty");
|
|
2706
2709
|
yield* requireExactExistingPath(fs, candidate, operation);
|
|
2707
|
-
const after = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2708
|
-
if (after.type !== "Directory" || before.dev !== after.dev || !Equal.equals(before.ino, after.ino)) return yield* fail$
|
|
2710
|
+
const after = yield* fs.stat(candidate).pipe(mapPlatform$5(operation, candidate));
|
|
2711
|
+
if (after.type !== "Directory" || before.dev !== after.dev || !Equal.equals(before.ino, after.ino)) return yield* fail$5(operation, "IdentityChanged", candidate, "Exact empty directory identity changed before removal");
|
|
2709
2712
|
yield* fs.remove(candidate, {
|
|
2710
2713
|
recursive: true,
|
|
2711
2714
|
force: false
|
|
2712
|
-
}).pipe(mapPlatform$
|
|
2715
|
+
}).pipe(mapPlatform$5(operation, candidate));
|
|
2713
2716
|
});
|
|
2714
2717
|
}
|
|
2715
2718
|
function resolveContained(root, relative, allowEmpty, operation) {
|
|
@@ -2747,7 +2750,7 @@ function readGitBlobBatch(executable, root, input, operation) {
|
|
|
2747
2750
|
return gitBlobBatchOutputLimit(input, operation);
|
|
2748
2751
|
});
|
|
2749
2752
|
if (input.blobs.length === 0) return Object.freeze([]);
|
|
2750
|
-
const output = yield* runGitCommand$1(executable, root, ["cat-file", "--batch"], operation, outputLimit, `${input.blobs.join("\n")}\n`).pipe(Effect.flatMap((result) => result.exitCode === 0 ? Effect.succeed(result.stdout) : fail$
|
|
2753
|
+
const output = yield* runGitCommand$1(executable, root, ["cat-file", "--batch"], operation, outputLimit, `${input.blobs.join("\n")}\n`).pipe(Effect.flatMap((result) => result.exitCode === 0 ? Effect.succeed(result.stdout) : fail$5(operation, "GitFailed", root, gitFailureDetail$2(["cat-file", "--batch"], result.stderr))));
|
|
2751
2754
|
return yield* checked(operation, () => parseGitBlobBatch(output, input, operation));
|
|
2752
2755
|
});
|
|
2753
2756
|
}
|
|
@@ -2776,73 +2779,73 @@ function parseGitBlobBatch(output, input, operation) {
|
|
|
2776
2779
|
let totalBytes = 0;
|
|
2777
2780
|
for (const expectedBlob of input.blobs) {
|
|
2778
2781
|
const headerEnd = output.indexOf(10, offset);
|
|
2779
|
-
if (headerEnd < 0) throw failure$
|
|
2782
|
+
if (headerEnd < 0) throw failure$5(operation, "GitFailed", expectedBlob, "Git blob batch omitted an object header");
|
|
2780
2783
|
const header = decodeGitBlobBatchHeader(output.subarray(offset, headerEnd), expectedBlob, operation);
|
|
2781
|
-
if (header === `${expectedBlob} missing`) throw failure$
|
|
2784
|
+
if (header === `${expectedBlob} missing`) throw failure$5(operation, "GitFailed", expectedBlob, "Git blob batch returned a missing object");
|
|
2782
2785
|
const match = /^([0-9a-f]+) ([a-z][a-z0-9-]*) ([0-9]+)$/u.exec(header);
|
|
2783
|
-
if (match === null) throw failure$
|
|
2784
|
-
if (match[1] !== expectedBlob) throw failure$
|
|
2785
|
-
if (match[2] !== "blob") throw failure$
|
|
2786
|
+
if (match === null) throw failure$5(operation, "GitFailed", expectedBlob, "Git blob batch returned a malformed object header");
|
|
2787
|
+
if (match[1] !== expectedBlob) throw failure$5(operation, "GitFailed", expectedBlob, "Git blob batch returned a reordered object");
|
|
2788
|
+
if (match[2] !== "blob") throw failure$5(operation, "UnsupportedEntry", expectedBlob, "Git object is not a blob");
|
|
2786
2789
|
const size = Number(match[3]);
|
|
2787
|
-
if (!Number.isSafeInteger(size) || size < 0 || size > input.maxBlobBytes) throw failure$
|
|
2790
|
+
if (!Number.isSafeInteger(size) || size < 0 || size > input.maxBlobBytes) throw failure$5(operation, "LimitExceeded", expectedBlob, "Git blob batch member exceeds maxBlobBytes");
|
|
2788
2791
|
totalBytes += size;
|
|
2789
|
-
if (!Number.isSafeInteger(totalBytes) || totalBytes > input.maxTotalBytes) throw failure$
|
|
2792
|
+
if (!Number.isSafeInteger(totalBytes) || totalBytes > input.maxTotalBytes) throw failure$5(operation, "LimitExceeded", expectedBlob, "Git blob batch exceeds maxTotalBytes");
|
|
2790
2793
|
const contentStart = headerEnd + 1;
|
|
2791
2794
|
const contentEnd = contentStart + size;
|
|
2792
|
-
if (contentEnd >= output.byteLength || output[contentEnd] !== 10) throw failure$
|
|
2795
|
+
if (contentEnd >= output.byteLength || output[contentEnd] !== 10) throw failure$5(operation, "GitFailed", expectedBlob, "Git blob batch returned truncated content");
|
|
2793
2796
|
observations.push(Object.freeze({
|
|
2794
2797
|
blob: expectedBlob,
|
|
2795
2798
|
bytes: output.slice(contentStart, contentEnd)
|
|
2796
2799
|
}));
|
|
2797
2800
|
offset = contentEnd + 1;
|
|
2798
2801
|
}
|
|
2799
|
-
if (offset !== output.byteLength) throw failure$
|
|
2802
|
+
if (offset !== output.byteLength) throw failure$5(operation, "GitFailed", void 0, "Git blob batch returned trailing output");
|
|
2800
2803
|
return Object.freeze(observations);
|
|
2801
2804
|
}
|
|
2802
2805
|
function decodeGitBlobBatchHeader(header, expectedBlob, operation) {
|
|
2803
2806
|
try {
|
|
2804
2807
|
return decoder$2.decode(header);
|
|
2805
2808
|
} catch {
|
|
2806
|
-
throw failure$
|
|
2809
|
+
throw failure$5(operation, "GitFailed", expectedBlob, "Git blob batch returned a non-UTF-8 object header");
|
|
2807
2810
|
}
|
|
2808
2811
|
}
|
|
2809
2812
|
function parseGitTrackedPathFlags(output, admittedPaths, root) {
|
|
2810
2813
|
return Effect.gen(function* () {
|
|
2811
2814
|
if (output.byteLength === 0) return Object.freeze([]);
|
|
2812
|
-
if (output[output.byteLength - 1] !== 0) return yield* fail$
|
|
2815
|
+
if (output[output.byteLength - 1] !== 0) return yield* fail$5("capture-git-evidence", "GitFailed", root, "Git tracked-path output is truncated before its terminal NUL");
|
|
2813
2816
|
const admitted = new Set(admittedPaths);
|
|
2814
2817
|
const facts = [];
|
|
2815
2818
|
const factsByPath = /* @__PURE__ */ new Map();
|
|
2816
2819
|
let recordStart = 0;
|
|
2817
2820
|
for (let index = 0; index < output.byteLength; index += 1) {
|
|
2818
2821
|
if (output[index] !== 0) continue;
|
|
2819
|
-
if (index === recordStart) return yield* fail$
|
|
2822
|
+
if (index === recordStart) return yield* fail$5("capture-git-evidence", "GitFailed", root, "Git tracked-path output contains an empty record");
|
|
2820
2823
|
const record = yield* Effect.try({
|
|
2821
2824
|
try: () => decoder$2.decode(output.subarray(recordStart, index)),
|
|
2822
|
-
catch: () => failure$
|
|
2825
|
+
catch: () => failure$5("capture-git-evidence", "GitFailed", root, "Git tracked-path output contains invalid UTF-8")
|
|
2823
2826
|
});
|
|
2824
2827
|
recordStart = index + 1;
|
|
2825
2828
|
const tag = record[0];
|
|
2826
|
-
if (tag === void 0 || record[1] !== " " || record.length < 3 || !/^[HSMhs]$/u.test(tag)) return yield* fail$
|
|
2829
|
+
if (tag === void 0 || record[1] !== " " || record.length < 3 || !/^[HSMhs]$/u.test(tag)) return yield* fail$5("capture-git-evidence", "GitFailed", root, "Git tracked-path output contains a malformed record");
|
|
2827
2830
|
const entryPath = record.slice(2);
|
|
2828
2831
|
const status = gitTrackedPathStatus(tag);
|
|
2829
|
-
if (status === void 0) return yield* fail$
|
|
2832
|
+
if (status === void 0) return yield* fail$5("capture-git-evidence", "GitFailed", root, "Git tracked-path output contains an unsupported status tag");
|
|
2830
2833
|
const fact = Object.freeze({
|
|
2831
2834
|
path: entryPath,
|
|
2832
2835
|
status,
|
|
2833
2836
|
assumeUnchanged: tag === "h" || tag === "s"
|
|
2834
2837
|
});
|
|
2835
|
-
if (!gitTrackedPathFlagValidator.Check(fact)) return yield* fail$
|
|
2836
|
-
if (!admitted.has(fact.path)) return yield* fail$
|
|
2838
|
+
if (!gitTrackedPathFlagValidator.Check(fact)) return yield* fail$5("capture-git-evidence", "UnsupportedEntry", entryPath, "Git tracked path is outside the tracked-path contract");
|
|
2839
|
+
if (!admitted.has(fact.path)) return yield* fail$5("capture-git-evidence", "UnsupportedEntry", fact.path, "Git returned a tracked path outside the admitted selection");
|
|
2837
2840
|
const prior = factsByPath.get(fact.path);
|
|
2838
|
-
if (prior !== void 0 && (prior.status !== "Unmerged" || fact.status !== "Unmerged" || prior.count >= 3)) return yield* fail$
|
|
2841
|
+
if (prior !== void 0 && (prior.status !== "Unmerged" || fact.status !== "Unmerged" || prior.count >= 3)) return yield* fail$5("capture-git-evidence", "GitFailed", fact.path, "Git tracked-path output contains an impossible index-state combination");
|
|
2839
2842
|
factsByPath.set(fact.path, Object.freeze({
|
|
2840
2843
|
status: fact.status,
|
|
2841
2844
|
count: (prior?.count ?? 0) + 1
|
|
2842
2845
|
}));
|
|
2843
2846
|
facts.push(fact);
|
|
2844
2847
|
}
|
|
2845
|
-
facts.sort((left, right) => compareText$
|
|
2848
|
+
facts.sort((left, right) => compareText$9(left.path, right.path) || compareText$9(left.status, right.status) || Number(left.assumeUnchanged) - Number(right.assumeUnchanged));
|
|
2846
2849
|
return Object.freeze(facts);
|
|
2847
2850
|
});
|
|
2848
2851
|
}
|
|
@@ -2857,43 +2860,43 @@ function gitTrackedPathStatus(tag) {
|
|
|
2857
2860
|
function parseGitStagedIndexOutput(output, objectFormat, maxEntries, root) {
|
|
2858
2861
|
return Effect.gen(function* () {
|
|
2859
2862
|
if (output.byteLength === 0) return Object.freeze([]);
|
|
2860
|
-
if (output[output.byteLength - 1] !== 0) return yield* fail$
|
|
2863
|
+
if (output[output.byteLength - 1] !== 0) return yield* fail$5("observe-git-staged-index", "GitFailed", root, "Git index output is truncated before its terminal NUL");
|
|
2861
2864
|
const entries = [];
|
|
2862
2865
|
const identities = /* @__PURE__ */ new Set();
|
|
2863
2866
|
let recordStart = 0;
|
|
2864
2867
|
for (let index = 0; index < output.byteLength; index += 1) {
|
|
2865
2868
|
if (output[index] !== 0) continue;
|
|
2866
|
-
if (entries.length >= maxEntries) return yield* fail$
|
|
2867
|
-
if (index === recordStart) return yield* fail$
|
|
2869
|
+
if (entries.length >= maxEntries) return yield* fail$5("observe-git-staged-index", "LimitExceeded", root, "Git index output exceeds maxEntries");
|
|
2870
|
+
if (index === recordStart) return yield* fail$5("observe-git-staged-index", "GitFailed", root, "Git index output contains an empty record");
|
|
2868
2871
|
const record = yield* Effect.try({
|
|
2869
2872
|
try: () => decoder$2.decode(output.subarray(recordStart, index)),
|
|
2870
|
-
catch: () => failure$
|
|
2873
|
+
catch: () => failure$5("observe-git-staged-index", "GitFailed", root, "Git index output contains invalid UTF-8")
|
|
2871
2874
|
});
|
|
2872
2875
|
recordStart = index + 1;
|
|
2873
2876
|
const separator = record.indexOf(" ");
|
|
2874
|
-
if (separator <= 0) return yield* fail$
|
|
2877
|
+
if (separator <= 0) return yield* fail$5("observe-git-staged-index", "GitFailed", root, "Git index output contains a malformed record");
|
|
2875
2878
|
const header = record.slice(0, separator);
|
|
2876
2879
|
const entryPath = record.slice(separator + 1);
|
|
2877
2880
|
const headerMatch = /^([0-7]{6}) ([0-9A-Za-z]+) ([0-3])$/u.exec(header);
|
|
2878
2881
|
const mode = headerMatch?.[1];
|
|
2879
2882
|
const objectId = headerMatch?.[2];
|
|
2880
2883
|
const rawStage = headerMatch?.[3];
|
|
2881
|
-
if (mode === void 0 || objectId === void 0 || rawStage === void 0) return yield* fail$
|
|
2884
|
+
if (mode === void 0 || objectId === void 0 || rawStage === void 0) return yield* fail$5("observe-git-staged-index", "GitFailed", root, "Git index output contains a malformed record header");
|
|
2882
2885
|
const objectLength = objectFormat === "sha1" ? 40 : 64;
|
|
2883
|
-
if (objectId.length !== objectLength || !/^[0-9a-f]+$/u.test(objectId)) return yield* fail$
|
|
2886
|
+
if (objectId.length !== objectLength || !/^[0-9a-f]+$/u.test(objectId)) return yield* fail$5("observe-git-staged-index", "GitFailed", entryPath, "Git index output contains an object ID for a different or malformed object format");
|
|
2884
2887
|
const entry = Object.freeze({
|
|
2885
2888
|
path: entryPath,
|
|
2886
2889
|
mode,
|
|
2887
2890
|
objectId,
|
|
2888
2891
|
stage: gitIndexStage(rawStage)
|
|
2889
2892
|
});
|
|
2890
|
-
if (!gitStagedIndexEntryValidator.Check(entry)) return yield* fail$
|
|
2893
|
+
if (!gitStagedIndexEntryValidator.Check(entry)) return yield* fail$5("observe-git-staged-index", "UnsupportedEntry", entryPath, "Git index path is outside the staged-entry contract");
|
|
2891
2894
|
const identity = `${entry.path}\0${entry.stage}`;
|
|
2892
|
-
if (identities.has(identity)) return yield* fail$
|
|
2895
|
+
if (identities.has(identity)) return yield* fail$5("observe-git-staged-index", "GitFailed", entry.path, "Git index output contains a duplicate path and stage");
|
|
2893
2896
|
identities.add(identity);
|
|
2894
2897
|
entries.push(entry);
|
|
2895
2898
|
}
|
|
2896
|
-
entries.sort((left, right) => compareText$
|
|
2899
|
+
entries.sort((left, right) => compareText$9(left.path, right.path) || left.stage - right.stage);
|
|
2897
2900
|
return Object.freeze(entries);
|
|
2898
2901
|
});
|
|
2899
2902
|
}
|
|
@@ -2909,42 +2912,42 @@ function gitIndexStage(value) {
|
|
|
2909
2912
|
function parseGitTreeOutput(output, objectFormat, maxEntries, root) {
|
|
2910
2913
|
return Effect.gen(function* () {
|
|
2911
2914
|
if (output.byteLength === 0) return Object.freeze([]);
|
|
2912
|
-
if (output[output.byteLength - 1] !== 0) return yield* fail$
|
|
2915
|
+
if (output[output.byteLength - 1] !== 0) return yield* fail$5("read-git-tree", "GitFailed", root, "Git tree output is truncated before its terminal NUL");
|
|
2913
2916
|
const entries = [];
|
|
2914
2917
|
const paths = /* @__PURE__ */ new Set();
|
|
2915
2918
|
let recordStart = 0;
|
|
2916
2919
|
for (let index = 0; index < output.byteLength; index += 1) {
|
|
2917
2920
|
if (output[index] !== 0) continue;
|
|
2918
|
-
if (entries.length >= maxEntries) return yield* fail$
|
|
2919
|
-
if (index === recordStart) return yield* fail$
|
|
2921
|
+
if (entries.length >= maxEntries) return yield* fail$5("read-git-tree", "LimitExceeded", root, "Git tree output exceeds maxEntries");
|
|
2922
|
+
if (index === recordStart) return yield* fail$5("read-git-tree", "GitFailed", root, "Git tree output contains an empty record");
|
|
2920
2923
|
const record = yield* Effect.try({
|
|
2921
2924
|
try: () => decoder$2.decode(output.subarray(recordStart, index)),
|
|
2922
|
-
catch: () => failure$
|
|
2925
|
+
catch: () => failure$5("read-git-tree", "GitFailed", root, "Git tree output contains invalid UTF-8")
|
|
2923
2926
|
});
|
|
2924
2927
|
recordStart = index + 1;
|
|
2925
2928
|
const separator = record.indexOf(" ");
|
|
2926
|
-
if (separator <= 0) return yield* fail$
|
|
2929
|
+
if (separator <= 0) return yield* fail$5("read-git-tree", "GitFailed", root, "Git tree output contains a malformed record");
|
|
2927
2930
|
const header = record.slice(0, separator);
|
|
2928
2931
|
const entryPath = record.slice(separator + 1);
|
|
2929
2932
|
const headerMatch = /^([0-7]{6}) ([a-z][a-z0-9-]*) ([0-9A-Za-z]+)$/u.exec(header);
|
|
2930
2933
|
const mode = headerMatch?.[1];
|
|
2931
2934
|
const objectType = headerMatch?.[2];
|
|
2932
2935
|
const blob = headerMatch?.[3];
|
|
2933
|
-
if (mode === void 0 || objectType === void 0 || blob === void 0) return yield* fail$
|
|
2934
|
-
if (mode !== "100644" && mode !== "100755" || objectType !== "blob") return yield* fail$
|
|
2936
|
+
if (mode === void 0 || objectType === void 0 || blob === void 0) return yield* fail$5("read-git-tree", "GitFailed", root, "Git tree output contains a malformed record header");
|
|
2937
|
+
if (mode !== "100644" && mode !== "100755" || objectType !== "blob") return yield* fail$5("read-git-tree", "UnsupportedEntry", entryPath, "Git tree contains a non-regular entry");
|
|
2935
2938
|
const objectLength = objectFormat === "sha1" ? 40 : 64;
|
|
2936
|
-
if (blob.length !== objectLength || !/^[0-9a-f]+$/u.test(blob)) return yield* fail$
|
|
2939
|
+
if (blob.length !== objectLength || !/^[0-9a-f]+$/u.test(blob)) return yield* fail$5("read-git-tree", "GitFailed", entryPath, "Git tree output contains an object ID for a different or malformed object format");
|
|
2937
2940
|
const entry = Object.freeze({
|
|
2938
2941
|
path: entryPath,
|
|
2939
2942
|
mode,
|
|
2940
2943
|
blob
|
|
2941
2944
|
});
|
|
2942
|
-
if (!contentTreeEntryValidator.Check(entry)) return yield* fail$
|
|
2943
|
-
if (paths.has(entry.path)) return yield* fail$
|
|
2945
|
+
if (!contentTreeEntryValidator.Check(entry)) return yield* fail$5("read-git-tree", "UnsupportedEntry", entryPath, "Git tree path is outside the regular-entry contract");
|
|
2946
|
+
if (paths.has(entry.path)) return yield* fail$5("read-git-tree", "GitFailed", entry.path, "Git tree output contains a duplicate path");
|
|
2944
2947
|
paths.add(entry.path);
|
|
2945
2948
|
entries.push(entry);
|
|
2946
2949
|
}
|
|
2947
|
-
entries.sort((left, right) => compareText$
|
|
2950
|
+
entries.sort((left, right) => compareText$9(left.path, right.path));
|
|
2948
2951
|
return Object.freeze(entries);
|
|
2949
2952
|
});
|
|
2950
2953
|
}
|
|
@@ -2983,16 +2986,16 @@ function validateObjectForFormat(value, format, label, operation) {
|
|
|
2983
2986
|
if (value.length !== expectedLength || !/^[0-9a-f]+$/u.test(value)) throw invalidInput(operation, value, `${label} must match the selected Git object format`);
|
|
2984
2987
|
}
|
|
2985
2988
|
function gitObjectFormat$1(executable, root, operation) {
|
|
2986
|
-
return gitText$1(executable, root, ["rev-parse", "--show-object-format"], operation).pipe(Effect.flatMap((format) => format === "sha1" || format === "sha256" ? Effect.succeed(format === "sha1" ? "sha1" : "sha256") : fail$
|
|
2989
|
+
return gitText$1(executable, root, ["rev-parse", "--show-object-format"], operation).pipe(Effect.flatMap((format) => format === "sha1" || format === "sha256" ? Effect.succeed(format === "sha1" ? "sha1" : "sha256") : fail$5(operation, "GitFailed", root, `Unsupported Git object format: ${format}`)));
|
|
2987
2990
|
}
|
|
2988
2991
|
function gitText$1(executable, root, args, operation) {
|
|
2989
|
-
return runGitCommand$1(executable, root, args, operation, 1048576).pipe(Effect.flatMap((result) => result.exitCode === 0 ? decodeGitOutput$2(result.stdout, operation, root) : fail$
|
|
2992
|
+
return runGitCommand$1(executable, root, args, operation, 1048576).pipe(Effect.flatMap((result) => result.exitCode === 0 ? decodeGitOutput$2(result.stdout, operation, root) : fail$5(operation, "GitFailed", root, gitFailureDetail$2(args, result.stderr))), Effect.map((output) => output.trim()));
|
|
2990
2993
|
}
|
|
2991
2994
|
function gitLines(executable, root, args, operation) {
|
|
2992
2995
|
return gitText$1(executable, root, args, operation).pipe(Effect.map((output) => output === "" ? [] : output.split("\n").filter((line) => line !== "")));
|
|
2993
2996
|
}
|
|
2994
2997
|
function gitBytes$1(executable, root, args, operation, maxBytes) {
|
|
2995
|
-
return runGitCommand$1(executable, root, args, operation, maxBytes).pipe(Effect.flatMap((result) => result.exitCode === 0 ? Effect.succeed(result.stdout) : fail$
|
|
2998
|
+
return runGitCommand$1(executable, root, args, operation, maxBytes).pipe(Effect.flatMap((result) => result.exitCode === 0 ? Effect.succeed(result.stdout) : fail$5(operation, "GitFailed", root, gitFailureDetail$2(args, result.stderr))));
|
|
2996
2999
|
}
|
|
2997
3000
|
function gitExitCode(executable, root, args, operation) {
|
|
2998
3001
|
return runGitCommand$1(executable, root, args, operation, 65536).pipe(Effect.map((result) => result.exitCode));
|
|
@@ -3006,7 +3009,7 @@ function runGitCommand$1(executable, root, args, operation, maxStdoutBytes, stdi
|
|
|
3006
3009
|
forceKillAfter: "5 seconds"
|
|
3007
3010
|
});
|
|
3008
3011
|
return Effect.scoped(Effect.gen(function* () {
|
|
3009
|
-
const process = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).spawn(command).pipe(Effect.catchDefect((cause) => fail$
|
|
3012
|
+
const process = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).spawn(command).pipe(Effect.catchDefect((cause) => fail$5(operation, "GitFailed", root, errorMessage$3(cause))));
|
|
3010
3013
|
const [stdout, stderr, exitCode] = yield* Effect.all([
|
|
3011
3014
|
collectBoundedGitOutput(process.stdout, maxStdoutBytes, operation, root, "stdout"),
|
|
3012
3015
|
collectBoundedGitOutput(process.stderr, stderrLimit, operation, root, "stderr"),
|
|
@@ -3017,14 +3020,14 @@ function runGitCommand$1(executable, root, args, operation, maxStdoutBytes, stdi
|
|
|
3017
3020
|
stderr,
|
|
3018
3021
|
exitCode: Number(exitCode)
|
|
3019
3022
|
});
|
|
3020
|
-
})).pipe(Effect.catchTag("PlatformError", (cause) => fail$
|
|
3023
|
+
})).pipe(Effect.catchTag("PlatformError", (cause) => fail$5(operation, "GitFailed", root, cause.message)));
|
|
3021
3024
|
}
|
|
3022
3025
|
function collectBoundedGitOutput(stream, maxBytes, operation, root, output) {
|
|
3023
3026
|
return Effect.gen(function* () {
|
|
3024
3027
|
const chunks = [];
|
|
3025
3028
|
let length = 0;
|
|
3026
3029
|
yield* Stream.runForEach(stream, (chunk) => {
|
|
3027
|
-
if (length + chunk.byteLength > maxBytes) return fail$
|
|
3030
|
+
if (length + chunk.byteLength > maxBytes) return fail$5(operation, "LimitExceeded", root, `Git ${output} exceeds ${maxBytes} bytes`);
|
|
3028
3031
|
chunks.push(chunk);
|
|
3029
3032
|
length += chunk.byteLength;
|
|
3030
3033
|
return Effect.void;
|
|
@@ -3041,7 +3044,7 @@ function collectBoundedGitOutput(stream, maxBytes, operation, root, output) {
|
|
|
3041
3044
|
function decodeGitOutput$2(bytes, operation, root) {
|
|
3042
3045
|
return Effect.try({
|
|
3043
3046
|
try: () => decoder$2.decode(bytes),
|
|
3044
|
-
catch: (cause) => failure$
|
|
3047
|
+
catch: (cause) => failure$5(operation, "GitFailed", root, errorMessage$3(cause))
|
|
3045
3048
|
});
|
|
3046
3049
|
}
|
|
3047
3050
|
function gitFailureDetail$2(args, stderr) {
|
|
@@ -3075,28 +3078,28 @@ function equalBytes(left, right) {
|
|
|
3075
3078
|
function pathsOverlap(left, right) {
|
|
3076
3079
|
return left === right || left.startsWith(`${right}/`) || right.startsWith(`${left}/`);
|
|
3077
3080
|
}
|
|
3078
|
-
function mapPlatform$
|
|
3079
|
-
return (effect) => effect.pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (failure) => platformFailure$
|
|
3081
|
+
function mapPlatform$5(operation, candidate) {
|
|
3082
|
+
return (effect) => effect.pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (failure) => platformFailure$4(operation, candidate, failure)))));
|
|
3080
3083
|
}
|
|
3081
|
-
function platformFailure$
|
|
3082
|
-
return failure$
|
|
3084
|
+
function platformFailure$4(operation, candidate, cause, fallback = "FilesystemFailed") {
|
|
3085
|
+
return failure$5(operation, cause.reason._tag === "NotFound" ? "Missing" : fallback, candidate, cause.message);
|
|
3083
3086
|
}
|
|
3084
3087
|
function invalidInput(operation, candidate, detail) {
|
|
3085
|
-
return failure$
|
|
3088
|
+
return failure$5(operation, "InvalidInput", candidate, detail);
|
|
3086
3089
|
}
|
|
3087
3090
|
function checked(operation, evaluate) {
|
|
3088
3091
|
return Effect.try({
|
|
3089
3092
|
try: evaluate,
|
|
3090
|
-
catch: (cause) => isContentWorkspaceFailure(cause) ? cause : failure$
|
|
3093
|
+
catch: (cause) => isContentWorkspaceFailure(cause) ? cause : failure$5(operation, "InvalidInput", void 0, errorMessage$3(cause))
|
|
3091
3094
|
});
|
|
3092
3095
|
}
|
|
3093
3096
|
function isContentWorkspaceFailure(input) {
|
|
3094
3097
|
return typeof input === "object" && input !== null && "_tag" in input && input._tag === "ContentWorkspaceFailure";
|
|
3095
3098
|
}
|
|
3096
|
-
function fail$
|
|
3097
|
-
return Effect.fail(failure$
|
|
3099
|
+
function fail$5(operation, reason, candidate, detail) {
|
|
3100
|
+
return Effect.fail(failure$5(operation, reason, candidate, detail));
|
|
3098
3101
|
}
|
|
3099
|
-
function failure$
|
|
3102
|
+
function failure$5(operation, reason, candidate, detail) {
|
|
3100
3103
|
return Object.freeze({
|
|
3101
3104
|
_tag: "ContentWorkspaceFailure",
|
|
3102
3105
|
operation,
|
|
@@ -3105,10 +3108,10 @@ function failure$4(operation, reason, candidate, detail) {
|
|
|
3105
3108
|
detail
|
|
3106
3109
|
});
|
|
3107
3110
|
}
|
|
3108
|
-
function errorMessage$
|
|
3111
|
+
function errorMessage$3(error) {
|
|
3109
3112
|
return error instanceof Error ? error.message : String(error);
|
|
3110
3113
|
}
|
|
3111
|
-
function compareText$
|
|
3114
|
+
function compareText$9(left, right) {
|
|
3112
3115
|
const leftBytes = encoder.encode(left);
|
|
3113
3116
|
const rightBytes = encoder.encode(right);
|
|
3114
3117
|
const length = Math.min(leftBytes.length, rightBytes.length);
|
|
@@ -3155,6 +3158,428 @@ function defineNodeFilesystemRuntimeProvider() {
|
|
|
3155
3158
|
});
|
|
3156
3159
|
}
|
|
3157
3160
|
//#endregion
|
|
3161
|
+
//#region ../../resources/native-agent-provider/providers/host-mcp-ledger.ts
|
|
3162
|
+
const MAX_HOME_JSON_FILE_BYTES = 4194304;
|
|
3163
|
+
const MAX_CLAUDE_USER_CONFIG_BYTES = 67108864;
|
|
3164
|
+
const MAX_CODEX_CONFIG_BYTES = 16777216;
|
|
3165
|
+
const USER_CONFIG_READ_RETRIES = 2;
|
|
3166
|
+
const USER_CONFIG_RETRY_DELAY = "25 millis";
|
|
3167
|
+
const MAX_FAILURE_DETAIL$1 = 4096;
|
|
3168
|
+
/** Reserved provider-home ledger filename outside installed plugin directories. */
|
|
3169
|
+
const HOST_MCP_LEDGER_FILENAME = ".habitat-host-mcp-ledger.json";
|
|
3170
|
+
const CURRENT_SIBLING_MCP_LEDGER_TEMP_PREFIX = `${HOST_MCP_LEDGER_FILENAME}.tmp-`;
|
|
3171
|
+
const LEGACY_MKDTEMP_MCP_LEDGER_DIR_PATTERN = /^\.habitat-host-mcp-ledger-[A-Za-z0-9]{6}$/u;
|
|
3172
|
+
const LEDGER_TEMP_PID_SUFFIX_PATTERN = /^([1-9][0-9]{0,9})-[0-9]+-/u;
|
|
3173
|
+
const NON_PID_LEDGER_TEMP_STALE_MS = 6e5;
|
|
3174
|
+
/** Returns true unless `process.kill(pid, 0)` throws `ESRCH` (any non-`ESRCH` error, including `EPERM`, counts as alive). */
|
|
3175
|
+
function isProcessAlive(pid) {
|
|
3176
|
+
try {
|
|
3177
|
+
process.kill(pid, 0);
|
|
3178
|
+
return true;
|
|
3179
|
+
} catch (cause) {
|
|
3180
|
+
return (typeof cause === "object" && cause !== null ? Reflect.get(cause, "code") : void 0) !== "ESRCH";
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
/**
|
|
3184
|
+
* Decides whether a ledger `.tmp-*` regular file is safe to sweep without deleting another
|
|
3185
|
+
* live process's in-flight atomic write.
|
|
3186
|
+
*/
|
|
3187
|
+
function shouldSweepLedgerTempFile(filename, prefix, mtimeMs, nowMs = Date.now()) {
|
|
3188
|
+
if (!filename.startsWith(prefix)) return false;
|
|
3189
|
+
const suffix = filename.slice(prefix.length);
|
|
3190
|
+
const pidMatch = LEDGER_TEMP_PID_SUFFIX_PATTERN.exec(suffix);
|
|
3191
|
+
if (pidMatch !== null) {
|
|
3192
|
+
const pid = Number(pidMatch[1]);
|
|
3193
|
+
if (Number.isSafeInteger(pid) && pid > 0) return !isProcessAlive(pid);
|
|
3194
|
+
}
|
|
3195
|
+
return mtimeMs !== null && Number.isFinite(mtimeMs) && nowMs - mtimeMs >= NON_PID_LEDGER_TEMP_STALE_MS;
|
|
3196
|
+
}
|
|
3197
|
+
/** Returns true when a PlatformError represents POSIX `EEXIST` (`AlreadyExists`) on exclusive open. */
|
|
3198
|
+
function isAlreadyExistsPlatformError(cause) {
|
|
3199
|
+
if (cause.reason._tag === "AlreadyExists") return true;
|
|
3200
|
+
const underlying = Reflect.get(cause.reason, "cause");
|
|
3201
|
+
return typeof underlying === "object" && underlying !== null && Reflect.get(underlying, "code") === "EEXIST";
|
|
3202
|
+
}
|
|
3203
|
+
/**
|
|
3204
|
+
* Removes an empty directory via POSIX `rmdir(2)` without recursion or symlink traversal,
|
|
3205
|
+
* treating `ENOENT` and `ENOTEMPTY`/`EEXIST` as safe no-op skips.
|
|
3206
|
+
*/
|
|
3207
|
+
function removeEmptyDirectoryNonRecursive(provider, operation, candidate, commandPhase = "not-started") {
|
|
3208
|
+
return Effect.tryPromise({
|
|
3209
|
+
try: () => rmdir(candidate),
|
|
3210
|
+
catch: (cause) => cause
|
|
3211
|
+
}).pipe(Effect.catchIf((cause) => {
|
|
3212
|
+
const code = typeof cause === "object" && cause !== null ? Reflect.get(cause, "code") : void 0;
|
|
3213
|
+
return code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST";
|
|
3214
|
+
}, () => Effect.void), Effect.mapError((cause) => failure$4(provider, operation, "FilesystemFailed", commandPhase, candidate, errorMessage$2(cause))));
|
|
3215
|
+
}
|
|
3216
|
+
/**
|
|
3217
|
+
* Sweeps direct-child crash-temp MCP ledger artifacts in `ledgerDir` at the start of serialized
|
|
3218
|
+
* mutations without blocking on symlinks or deleting live-PID in-flight temp files:
|
|
3219
|
+
* - `.habitat-host-mcp-ledger.json.tmp-*` (`SymbolicLink` -> skip; `File` -> remove when dead-PID or stale; `Directory` -> non-recursive `rmdir`)
|
|
3220
|
+
* - on `claude` and `codex` only, legacy `mkdtemp` directories matching `/^\.habitat-host-mcp-ledger-[A-Za-z0-9]{6}$/u` (`SymbolicLink` -> skip; `Directory` -> non-recursive `rmdir`; `File` -> untouched)
|
|
3221
|
+
*/
|
|
3222
|
+
function sweepTransientMcpLedgerArtifacts(fs, paths, provider, operation, ledgerDir, commandPhase = "not-started") {
|
|
3223
|
+
return Effect.gen(function* () {
|
|
3224
|
+
const allowLegacyMkdtempSweep = provider === "claude" || provider === "codex";
|
|
3225
|
+
const entries = yield* fs.readDirectory(ledgerDir).pipe(mapPlatform$4(provider, operation, ledgerDir, commandPhase), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed([])));
|
|
3226
|
+
const nowMs = Date.now();
|
|
3227
|
+
for (const name of [...entries].sort()) {
|
|
3228
|
+
const isSiblingTemp = name.startsWith(CURRENT_SIBLING_MCP_LEDGER_TEMP_PREFIX);
|
|
3229
|
+
const isLegacyMkdtemp = allowLegacyMkdtempSweep && LEGACY_MKDTEMP_MCP_LEDGER_DIR_PATTERN.test(name);
|
|
3230
|
+
if (!isSiblingTemp && !isLegacyMkdtemp) continue;
|
|
3231
|
+
const candidate = paths.join(ledgerDir, name);
|
|
3232
|
+
if (!isContained$3(paths, ledgerDir, candidate)) continue;
|
|
3233
|
+
const info = yield* fs.lstat(candidate).pipe(mapPlatform$4(provider, operation, candidate, commandPhase), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3234
|
+
if (info === null || info.type === "SymbolicLink") continue;
|
|
3235
|
+
if (isSiblingTemp) {
|
|
3236
|
+
if (info.type === "File") {
|
|
3237
|
+
const mtimeMs = Option.isSome(info.mtime) ? info.mtime.value.getTime() : null;
|
|
3238
|
+
if (shouldSweepLedgerTempFile(name, CURRENT_SIBLING_MCP_LEDGER_TEMP_PREFIX, mtimeMs, nowMs)) yield* fs.remove(candidate).pipe(mapPlatform$4(provider, operation, candidate, commandPhase), Effect.catchIf((error) => error.reason === "Missing", () => Effect.void));
|
|
3239
|
+
} else if (info.type === "Directory") yield* removeEmptyDirectoryNonRecursive(provider, operation, candidate, commandPhase);
|
|
3240
|
+
} else if (info.type === "Directory") yield* removeEmptyDirectoryNonRecursive(provider, operation, candidate, commandPhase);
|
|
3241
|
+
}
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
const HostMcpLedgerSchema = Type.Readonly(Type.Object({
|
|
3245
|
+
schemaVersion: Type.Literal(1),
|
|
3246
|
+
servers: Type.Readonly(Type.Array(NativeManagedMcpServerRecordSchema, { maxItems: MAX_NATIVE_PROVIDER_MCP_SERVERS }))
|
|
3247
|
+
}, { additionalProperties: false }));
|
|
3248
|
+
/**
|
|
3249
|
+
* Decides whether inventory must inspect live user-scope MCP configuration based on caller flags
|
|
3250
|
+
* and relevant managed ledger records.
|
|
3251
|
+
*/
|
|
3252
|
+
function shouldObserveProviderMcpConfig(options, managedMcpServers) {
|
|
3253
|
+
if (options.observeMcpServers) return true;
|
|
3254
|
+
if (options.relevantOwnerPluginIds === void 0) return managedMcpServers.length > 0;
|
|
3255
|
+
const relevantOwners = new Set(options.relevantOwnerPluginIds);
|
|
3256
|
+
return managedMcpServers.some((entry) => relevantOwners.has(entry.ownerPluginId));
|
|
3257
|
+
}
|
|
3258
|
+
/**
|
|
3259
|
+
* Fails closed when `CLAUDE_CODE_CUSTOM_OAUTH_URL` is non-empty (untrimmed), which redirects
|
|
3260
|
+
* native Claude user-scope MCP commands to an OAuth-suffixed `.claude-<suffix>.json` file.
|
|
3261
|
+
*/
|
|
3262
|
+
function requireSupportedClaudeOAuthEnvironment(operation, commandPhase = "not-started") {
|
|
3263
|
+
const raw = process.env.CLAUDE_CODE_CUSTOM_OAUTH_URL;
|
|
3264
|
+
if (raw !== void 0 && raw.length > 0) return fail$4("claude", operation, "InvalidInput", commandPhase, void 0, "Claude custom OAuth environment (CLAUDE_CODE_CUSTOM_OAUTH_URL) is unsupported for user-scope MCP convergence");
|
|
3265
|
+
return Effect.void;
|
|
3266
|
+
}
|
|
3267
|
+
/**
|
|
3268
|
+
* Restores the previous managed MCP ledger after a failed `mcp-add` whose target server is not
|
|
3269
|
+
* present at the desired URL, combining any rollback write error onto the originating failure.
|
|
3270
|
+
*/
|
|
3271
|
+
function rollbackWriteAheadMcpLedger(writeLedger, previousLedger, originFailure) {
|
|
3272
|
+
return Effect.result(writeLedger("mcp-add", previousLedger, originFailure.commandPhase)).pipe(Effect.flatMap((rollbackAttempt) => {
|
|
3273
|
+
if (rollbackAttempt._tag === "Success") return Effect.fail(originFailure);
|
|
3274
|
+
const combinedDetail = `${originFailure.detail}; ledger rollback also failed: ${rollbackAttempt.failure.detail}`.slice(0, MAX_FAILURE_DETAIL$1);
|
|
3275
|
+
return Effect.fail(Object.freeze({
|
|
3276
|
+
...originFailure,
|
|
3277
|
+
detail: combinedDetail
|
|
3278
|
+
}));
|
|
3279
|
+
}));
|
|
3280
|
+
}
|
|
3281
|
+
/**
|
|
3282
|
+
* Reads and validates `<home>/.habitat-host-mcp-ledger.json` (or
|
|
3283
|
+
* `<geminiRoot>/config/.habitat-host-mcp-ledger.json` on Antigravity), returning an empty list
|
|
3284
|
+
* when absent and failing closed on aliased, oversized, or schema-invalid files.
|
|
3285
|
+
*/
|
|
3286
|
+
function readProviderManagedMcpLedger(fs, paths, provider, operation, home, geminiRoot = home) {
|
|
3287
|
+
return Effect.gen(function* () {
|
|
3288
|
+
const ledgerDir = provider === "antigravity" ? yield* resolveExistingAntigravityConfigDir(fs, paths, provider, operation, home, geminiRoot, "not-started") : home;
|
|
3289
|
+
if (ledgerDir === null) return Object.freeze([]);
|
|
3290
|
+
const raw = yield* readBoundedOptionalHomeJson(fs, paths, provider, operation, ledgerDir, HOST_MCP_LEDGER_FILENAME);
|
|
3291
|
+
if (raw === null) return Object.freeze([]);
|
|
3292
|
+
const ledgerPath = paths.join(ledgerDir, HOST_MCP_LEDGER_FILENAME);
|
|
3293
|
+
if (!Value.Check(HostMcpLedgerSchema, raw)) return yield* fail$4(provider, operation, "ProtocolFailed", "not-started", ledgerPath, "Provider host MCP ledger did not match expected schema");
|
|
3294
|
+
const names = raw.servers.map((entry) => entry.name);
|
|
3295
|
+
if (new Set(names).size !== names.length) return yield* fail$4(provider, operation, "ProtocolFailed", "not-started", ledgerPath, "Provider host MCP ledger contains duplicate server names");
|
|
3296
|
+
return Object.freeze([...raw.servers].map((entry) => Object.freeze({ ...entry })).sort((left, right) => compareText$8(left.name, right.name)));
|
|
3297
|
+
});
|
|
3298
|
+
}
|
|
3299
|
+
/**
|
|
3300
|
+
* Atomically writes `<home>/.habitat-host-mcp-ledger.json` (or
|
|
3301
|
+
* `<geminiRoot>/config/.habitat-host-mcp-ledger.json` on Antigravity) within the explicit
|
|
3302
|
+
* provider home while preserving the caller's native command phase on any filesystem failure.
|
|
3303
|
+
*/
|
|
3304
|
+
function writeProviderManagedMcpLedger(fs, paths, provider, operation, home, servers, commandPhase = "not-started", geminiRoot = home) {
|
|
3305
|
+
return Effect.gen(function* () {
|
|
3306
|
+
const candidateLedgerDir = provider === "antigravity" ? paths.join(geminiRoot, "config") : home;
|
|
3307
|
+
const candidateLedgerPath = paths.join(candidateLedgerDir, HOST_MCP_LEDGER_FILENAME);
|
|
3308
|
+
if (!isContained$3(paths, home, candidateLedgerPath)) return yield* fail$4(provider, operation, "Aliased", commandPhase, candidateLedgerPath, "Provider host MCP ledger escaped the explicit provider home");
|
|
3309
|
+
const sorted = [...servers].map((entry) => Object.freeze({ ...entry })).sort((left, right) => compareText$8(left.name, right.name));
|
|
3310
|
+
const candidatePayload = {
|
|
3311
|
+
schemaVersion: 1,
|
|
3312
|
+
servers: sorted
|
|
3313
|
+
};
|
|
3314
|
+
if (!Value.Check(HostMcpLedgerSchema, candidatePayload) || new Set(sorted.map((entry) => entry.name)).size !== sorted.length) return yield* fail$4(provider, operation, "InvalidInput", commandPhase, candidateLedgerPath, "Provider host MCP ledger write payload is invalid");
|
|
3315
|
+
const ledgerDir = provider === "antigravity" ? yield* ensureWritableAntigravityConfigDir(fs, paths, provider, operation, home, geminiRoot, commandPhase) : home;
|
|
3316
|
+
const ledgerPath = paths.join(ledgerDir, HOST_MCP_LEDGER_FILENAME);
|
|
3317
|
+
const existing = yield* fs.lstat(ledgerPath).pipe(mapPlatform$4(provider, operation, ledgerPath, commandPhase), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3318
|
+
if (existing !== null) {
|
|
3319
|
+
if (existing.type === "SymbolicLink") return yield* fail$4(provider, operation, "Aliased", commandPhase, ledgerPath, "Provider host MCP ledger path is aliased");
|
|
3320
|
+
if (existing.type !== "File") return yield* fail$4(provider, operation, "UnsupportedEntry", commandPhase, ledgerPath, "Provider host MCP ledger entry is not a regular file");
|
|
3321
|
+
if ((yield* fs.realPath(ledgerPath).pipe(mapPlatform$4(provider, operation, ledgerPath, commandPhase))) !== ledgerPath) return yield* fail$4(provider, operation, "Aliased", commandPhase, ledgerPath, "Provider host MCP ledger path is aliased");
|
|
3322
|
+
}
|
|
3323
|
+
const serialized = `${JSON.stringify(candidatePayload, null, 2)}\n`;
|
|
3324
|
+
const tempName = `${HOST_MCP_LEDGER_FILENAME}.tmp-${process.pid}-${Date.now()}-${randomUUID()}`;
|
|
3325
|
+
const tempPath = paths.join(ledgerDir, tempName);
|
|
3326
|
+
yield* Effect.acquireUseRelease(fs.writeFileString(tempPath, serialized, {
|
|
3327
|
+
flag: "wx",
|
|
3328
|
+
mode: 384
|
|
3329
|
+
}).pipe(Effect.tapError((cause) => isAlreadyExistsPlatformError(cause) ? Effect.void : fs.remove(tempPath, { force: true }).pipe(Effect.ignore)), mapPlatform$4(provider, operation, tempPath, commandPhase), Effect.as(tempPath)), (createdTemp) => fs.rename(createdTemp, ledgerPath).pipe(mapPlatform$4(provider, operation, ledgerPath, commandPhase)), (createdTemp) => fs.remove(createdTemp, { force: true }).pipe(Effect.ignore));
|
|
3330
|
+
});
|
|
3331
|
+
}
|
|
3332
|
+
/**
|
|
3333
|
+
* Reads an optional bounded JSON file strictly inside the explicit provider home without following
|
|
3334
|
+
* symbolic links.
|
|
3335
|
+
*/
|
|
3336
|
+
function readBoundedOptionalHomeJson(fs, paths, provider, operation, home, relativePathInput) {
|
|
3337
|
+
return Effect.gen(function* () {
|
|
3338
|
+
const relativePath = canonicalRelativeFile$1(relativePathInput);
|
|
3339
|
+
if (relativePath === void 0) return yield* fail$4(provider, operation, "InvalidInput", "not-started", relativePathInput, "Provider home JSON path must be one canonical relative POSIX file path");
|
|
3340
|
+
const candidate = paths.join(home, ...relativePath.split("/"));
|
|
3341
|
+
if (!isContained$3(paths, home, candidate)) return yield* fail$4(provider, operation, "Aliased", "not-started", candidate, "Provider home JSON path escaped the explicit provider home");
|
|
3342
|
+
const linkStatus = yield* fs.lstat(candidate).pipe(mapPlatform$4(provider, operation, candidate, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3343
|
+
if (linkStatus === null) return null;
|
|
3344
|
+
if (linkStatus.type === "SymbolicLink") return yield* fail$4(provider, operation, "Aliased", "not-started", candidate, "Provider home JSON path is aliased");
|
|
3345
|
+
const resolved = yield* fs.realPath(candidate).pipe(mapPlatform$4(provider, operation, candidate, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3346
|
+
if (resolved === null) return null;
|
|
3347
|
+
if (resolved !== candidate) return yield* fail$4(provider, operation, "Aliased", "not-started", candidate, "Provider home JSON path is aliased");
|
|
3348
|
+
const status = yield* fs.stat(candidate).pipe(mapPlatform$4(provider, operation, candidate, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3349
|
+
if (status === null) return null;
|
|
3350
|
+
const size = Number(status.size);
|
|
3351
|
+
if (status.type !== "File") return yield* fail$4(provider, operation, "UnsupportedEntry", "not-started", candidate, "Provider home JSON entry is not a regular file");
|
|
3352
|
+
if (!Number.isSafeInteger(size) || size < 0 || size > MAX_HOME_JSON_FILE_BYTES) return yield* fail$4(provider, operation, "LimitExceeded", "not-started", candidate, "Provider home JSON file exceeds bounded limit");
|
|
3353
|
+
const bytes = yield* fs.readFile(candidate).pipe(mapPlatform$4(provider, operation, candidate, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3354
|
+
if (bytes === null) return null;
|
|
3355
|
+
if (bytes.byteLength !== size) return yield* fail$4(provider, operation, "FilesystemFailed", "not-started", candidate, "Provider home JSON file size changed while reading");
|
|
3356
|
+
const text = yield* Effect.try({
|
|
3357
|
+
try: () => new TextDecoder("utf-8", { fatal: true }).decode(bytes),
|
|
3358
|
+
catch: (cause) => failure$4(provider, operation, "ProtocolFailed", "not-started", candidate, errorMessage$2(cause))
|
|
3359
|
+
});
|
|
3360
|
+
return yield* Effect.try({
|
|
3361
|
+
try: () => JSON.parse(text),
|
|
3362
|
+
catch: (cause) => failure$4(provider, operation, "InvalidJson", "not-started", candidate, errorMessage$2(cause))
|
|
3363
|
+
});
|
|
3364
|
+
});
|
|
3365
|
+
}
|
|
3366
|
+
/**
|
|
3367
|
+
* Dynamically resolves and reads Claude's active user-scope JSON configuration, checking OAuth
|
|
3368
|
+
* environment safety and honoring non-empty legacy `<home>/.config.json` precedence before
|
|
3369
|
+
* falling back to `<configRoot>/.claude.json`.
|
|
3370
|
+
*/
|
|
3371
|
+
function resolveActiveClaudeUserConfigJson(fs, paths, provider, operation, home, primaryConfigRoot, primaryCandidate, commandPhase = "not-started") {
|
|
3372
|
+
return Effect.gen(function* () {
|
|
3373
|
+
yield* requireSupportedClaudeOAuthEnvironment(operation, commandPhase);
|
|
3374
|
+
const legacyCandidate = paths.join(home, ".config.json");
|
|
3375
|
+
const legacyResult = yield* readResilientConfigFile({
|
|
3376
|
+
fs,
|
|
3377
|
+
paths,
|
|
3378
|
+
provider,
|
|
3379
|
+
operation,
|
|
3380
|
+
configRoot: home,
|
|
3381
|
+
candidate: legacyCandidate,
|
|
3382
|
+
maxBytes: MAX_CLAUDE_USER_CONFIG_BYTES,
|
|
3383
|
+
label: "Claude legacy user configuration",
|
|
3384
|
+
commandPhase,
|
|
3385
|
+
treatZeroByteAsAbsent: true,
|
|
3386
|
+
retryOnceOnEmptyText: false,
|
|
3387
|
+
parse: (text) => Effect.try({
|
|
3388
|
+
try: () => JSON.parse(text),
|
|
3389
|
+
catch: (cause) => failure$4(provider, operation, "InvalidJson", commandPhase, legacyCandidate, errorMessage$2(cause))
|
|
3390
|
+
})
|
|
3391
|
+
});
|
|
3392
|
+
if (legacyResult.present) return legacyResult.value;
|
|
3393
|
+
const primaryResult = yield* readResilientConfigFile({
|
|
3394
|
+
fs,
|
|
3395
|
+
paths,
|
|
3396
|
+
provider,
|
|
3397
|
+
operation,
|
|
3398
|
+
configRoot: primaryConfigRoot,
|
|
3399
|
+
candidate: primaryCandidate,
|
|
3400
|
+
maxBytes: MAX_CLAUDE_USER_CONFIG_BYTES,
|
|
3401
|
+
label: "Claude user configuration",
|
|
3402
|
+
commandPhase,
|
|
3403
|
+
treatZeroByteAsAbsent: false,
|
|
3404
|
+
retryOnceOnEmptyText: false,
|
|
3405
|
+
parse: (text) => Effect.try({
|
|
3406
|
+
try: () => JSON.parse(text),
|
|
3407
|
+
catch: (cause) => failure$4(provider, operation, "InvalidJson", commandPhase, primaryCandidate, errorMessage$2(cause))
|
|
3408
|
+
})
|
|
3409
|
+
});
|
|
3410
|
+
return primaryResult.present ? primaryResult.value : null;
|
|
3411
|
+
});
|
|
3412
|
+
}
|
|
3413
|
+
/**
|
|
3414
|
+
* Reads Codex's `<CODEX_HOME>/config.toml` offline with a 16 MiB bound, non-symlink containment
|
|
3415
|
+
* checks, a single 25ms re-read when a present `config.toml` is transiently `0` bytes (or empty),
|
|
3416
|
+
* and bounded retries against mid-write TOML truncation.
|
|
3417
|
+
*/
|
|
3418
|
+
function readResilientCodexConfigToml(fs, paths, provider, operation, home, commandPhase = "not-started") {
|
|
3419
|
+
const candidate = paths.join(home, "config.toml");
|
|
3420
|
+
return readResilientConfigFile({
|
|
3421
|
+
fs,
|
|
3422
|
+
paths,
|
|
3423
|
+
provider,
|
|
3424
|
+
operation,
|
|
3425
|
+
configRoot: home,
|
|
3426
|
+
candidate,
|
|
3427
|
+
maxBytes: MAX_CODEX_CONFIG_BYTES,
|
|
3428
|
+
label: "Codex configuration",
|
|
3429
|
+
commandPhase,
|
|
3430
|
+
treatZeroByteAsAbsent: false,
|
|
3431
|
+
retryOnceOnEmptyText: true,
|
|
3432
|
+
parse: (text) => Effect.try({
|
|
3433
|
+
try: () => parse(text),
|
|
3434
|
+
catch: (cause) => failure$4(provider, operation, "ProtocolFailed", commandPhase, candidate, errorMessage$2(cause))
|
|
3435
|
+
})
|
|
3436
|
+
}).pipe(Effect.map((result) => result.present ? result.value : null));
|
|
3437
|
+
}
|
|
3438
|
+
/**
|
|
3439
|
+
* Reads Antigravity's `<geminiRoot>/config/mcp_config.json` offline with a 4 MiB bound,
|
|
3440
|
+
* non-symlink containment checks on `<geminiRoot>`, `<geminiRoot>/config`, and `mcp_config.json`,
|
|
3441
|
+
* and bounded 25ms retries against `0`-byte or mid-write JSON truncation, treating persistently
|
|
3442
|
+
* empty or whitespace-only files as absent (`null`).
|
|
3443
|
+
*/
|
|
3444
|
+
function readResilientAntigravityMcpConfigJson(fs, paths, provider, operation, home, geminiRoot, commandPhase = "not-started") {
|
|
3445
|
+
return Effect.gen(function* () {
|
|
3446
|
+
const configDir = yield* resolveExistingAntigravityConfigDir(fs, paths, provider, operation, home, geminiRoot, commandPhase);
|
|
3447
|
+
if (configDir === null) return null;
|
|
3448
|
+
const candidate = paths.join(configDir, "mcp_config.json");
|
|
3449
|
+
const result = yield* readResilientConfigFile({
|
|
3450
|
+
fs,
|
|
3451
|
+
paths,
|
|
3452
|
+
provider,
|
|
3453
|
+
operation,
|
|
3454
|
+
configRoot: configDir,
|
|
3455
|
+
candidate,
|
|
3456
|
+
maxBytes: MAX_HOME_JSON_FILE_BYTES,
|
|
3457
|
+
label: "Antigravity MCP configuration",
|
|
3458
|
+
commandPhase,
|
|
3459
|
+
treatZeroByteAsAbsent: false,
|
|
3460
|
+
retryOnceOnEmptyText: true,
|
|
3461
|
+
parse: (text) => text.trim().length === 0 ? Effect.succeed(null) : Effect.try({
|
|
3462
|
+
try: () => JSON.parse(text),
|
|
3463
|
+
catch: (cause) => failure$4(provider, operation, "InvalidJson", commandPhase, candidate, errorMessage$2(cause))
|
|
3464
|
+
})
|
|
3465
|
+
});
|
|
3466
|
+
return result.present ? result.value : null;
|
|
3467
|
+
});
|
|
3468
|
+
}
|
|
3469
|
+
function resolveExistingAntigravityConfigDir(fs, paths, provider, operation, home, geminiRoot, commandPhase) {
|
|
3470
|
+
return Effect.gen(function* () {
|
|
3471
|
+
const configDir = paths.join(geminiRoot, "config");
|
|
3472
|
+
if (!isContained$3(paths, home, configDir)) return yield* fail$4(provider, operation, "Aliased", commandPhase, configDir, "Antigravity config directory escaped the explicit provider home");
|
|
3473
|
+
if ((yield* verifyOptionalCanonicalDirectory(fs, provider, operation, geminiRoot, "Antigravity .gemini directory", commandPhase)) === null) return null;
|
|
3474
|
+
return yield* verifyOptionalCanonicalDirectory(fs, provider, operation, configDir, "Antigravity config directory", commandPhase);
|
|
3475
|
+
});
|
|
3476
|
+
}
|
|
3477
|
+
function ensureWritableAntigravityConfigDir(fs, paths, provider, operation, home, geminiRoot, commandPhase) {
|
|
3478
|
+
return Effect.gen(function* () {
|
|
3479
|
+
const configDir = paths.join(geminiRoot, "config");
|
|
3480
|
+
if (!isContained$3(paths, home, configDir) || !isContained$3(paths, geminiRoot, configDir)) return yield* fail$4(provider, operation, "Aliased", commandPhase, configDir, "Antigravity config directory escaped the explicit provider home");
|
|
3481
|
+
yield* verifyOptionalCanonicalDirectory(fs, provider, operation, geminiRoot, "Antigravity .gemini directory", commandPhase);
|
|
3482
|
+
yield* verifyOptionalCanonicalDirectory(fs, provider, operation, configDir, "Antigravity config directory", commandPhase);
|
|
3483
|
+
yield* fs.makeDirectory(configDir, { recursive: true }).pipe(mapPlatform$4(provider, operation, configDir, commandPhase));
|
|
3484
|
+
const verifiedGeminiRoot = yield* verifyOptionalCanonicalDirectory(fs, provider, operation, geminiRoot, "Antigravity .gemini directory", commandPhase);
|
|
3485
|
+
const verifiedConfigDir = yield* verifyOptionalCanonicalDirectory(fs, provider, operation, configDir, "Antigravity config directory", commandPhase);
|
|
3486
|
+
if (verifiedGeminiRoot === null || verifiedConfigDir === null) return yield* fail$4(provider, operation, "FilesystemFailed", commandPhase, configDir, "Antigravity config directory could not be created");
|
|
3487
|
+
return verifiedConfigDir;
|
|
3488
|
+
});
|
|
3489
|
+
}
|
|
3490
|
+
function verifyOptionalCanonicalDirectory(fs, provider, operation, candidate, label, commandPhase) {
|
|
3491
|
+
return Effect.gen(function* () {
|
|
3492
|
+
const linkStatus = yield* fs.lstat(candidate).pipe(mapPlatform$4(provider, operation, candidate, commandPhase), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3493
|
+
if (linkStatus === null) return null;
|
|
3494
|
+
if (linkStatus.type === "SymbolicLink") return yield* fail$4(provider, operation, "Aliased", commandPhase, candidate, `${label} path is aliased`);
|
|
3495
|
+
if (linkStatus.type !== "Directory") return yield* fail$4(provider, operation, "UnsupportedEntry", commandPhase, candidate, `${label} entry is not a directory`);
|
|
3496
|
+
const resolved = yield* fs.realPath(candidate).pipe(mapPlatform$4(provider, operation, candidate, commandPhase), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3497
|
+
if (resolved === null) return null;
|
|
3498
|
+
if (resolved !== candidate) return yield* fail$4(provider, operation, "Aliased", commandPhase, candidate, `${label} path is aliased`);
|
|
3499
|
+
return candidate;
|
|
3500
|
+
});
|
|
3501
|
+
}
|
|
3502
|
+
function readResilientConfigFile(input) {
|
|
3503
|
+
return Effect.gen(function* () {
|
|
3504
|
+
const { fs, paths, provider, operation, configRoot, candidate, maxBytes, label, commandPhase } = input;
|
|
3505
|
+
if (!isContained$3(paths, configRoot, candidate)) return yield* fail$4(provider, operation, "Aliased", commandPhase, candidate, `${label} path escaped its resolved home`);
|
|
3506
|
+
let lastError;
|
|
3507
|
+
for (let attempt = 0; attempt <= USER_CONFIG_READ_RETRIES; attempt += 1) {
|
|
3508
|
+
if (attempt > 0) yield* Effect.sleep(USER_CONFIG_RETRY_DELAY);
|
|
3509
|
+
const linkStatus = yield* fs.lstat(candidate).pipe(mapPlatform$4(provider, operation, candidate, commandPhase), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3510
|
+
if (linkStatus === null) return Object.freeze({ present: false });
|
|
3511
|
+
if (linkStatus.type === "SymbolicLink") return yield* fail$4(provider, operation, "Aliased", commandPhase, candidate, `${label} path is aliased`);
|
|
3512
|
+
const resolved = yield* fs.realPath(candidate).pipe(mapPlatform$4(provider, operation, candidate, commandPhase), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3513
|
+
if (resolved === null) return Object.freeze({ present: false });
|
|
3514
|
+
if (resolved !== candidate) return yield* fail$4(provider, operation, "Aliased", commandPhase, candidate, `${label} path is aliased`);
|
|
3515
|
+
const status = yield* fs.stat(candidate).pipe(mapPlatform$4(provider, operation, candidate, commandPhase), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3516
|
+
if (status === null) return Object.freeze({ present: false });
|
|
3517
|
+
const size = Number(status.size);
|
|
3518
|
+
if (status.type !== "File") return yield* fail$4(provider, operation, "UnsupportedEntry", commandPhase, candidate, `${label} entry is not a regular file`);
|
|
3519
|
+
if (!Number.isSafeInteger(size) || size < 0 || size > maxBytes) return yield* fail$4(provider, operation, "LimitExceeded", commandPhase, candidate, `${label} file exceeds bounded limit`);
|
|
3520
|
+
if (input.treatZeroByteAsAbsent && size === 0) return Object.freeze({ present: false });
|
|
3521
|
+
const bytes = yield* fs.readFile(candidate).pipe(mapPlatform$4(provider, operation, candidate, commandPhase), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed(null)));
|
|
3522
|
+
if (bytes === null) return Object.freeze({ present: false });
|
|
3523
|
+
if (bytes.byteLength !== size) {
|
|
3524
|
+
lastError = failure$4(provider, operation, "FilesystemFailed", commandPhase, candidate, `${label} file size changed while reading`);
|
|
3525
|
+
continue;
|
|
3526
|
+
}
|
|
3527
|
+
const decoded = yield* Effect.result(Effect.try({
|
|
3528
|
+
try: () => new TextDecoder("utf-8", { fatal: true }).decode(bytes),
|
|
3529
|
+
catch: (cause) => failure$4(provider, operation, "ProtocolFailed", commandPhase, candidate, errorMessage$2(cause))
|
|
3530
|
+
}));
|
|
3531
|
+
if (decoded._tag === "Failure") {
|
|
3532
|
+
lastError = decoded.failure;
|
|
3533
|
+
continue;
|
|
3534
|
+
}
|
|
3535
|
+
if (input.treatZeroByteAsAbsent && decoded.success === "") return Object.freeze({ present: false });
|
|
3536
|
+
if (input.retryOnceOnEmptyText && attempt === 0 && decoded.success.trim().length === 0) continue;
|
|
3537
|
+
const parsed = yield* Effect.result(input.parse(decoded.success));
|
|
3538
|
+
if (parsed._tag === "Success") return Object.freeze({
|
|
3539
|
+
present: true,
|
|
3540
|
+
value: parsed.success
|
|
3541
|
+
});
|
|
3542
|
+
lastError = parsed.failure;
|
|
3543
|
+
}
|
|
3544
|
+
return yield* Effect.fail(lastError ?? failure$4(provider, operation, "FilesystemFailed", commandPhase, candidate, `${label} file could not be read`));
|
|
3545
|
+
});
|
|
3546
|
+
}
|
|
3547
|
+
function canonicalRelativeFile$1(input) {
|
|
3548
|
+
if (input.length === 0 || input.length > 1024 || input.includes("\\") || input.startsWith("/")) return;
|
|
3549
|
+
const segments = input.split("/");
|
|
3550
|
+
return segments.some((segment) => segment === "" || segment === "." || segment === "..") ? void 0 : segments.join("/");
|
|
3551
|
+
}
|
|
3552
|
+
function isContained$3(paths, root, candidate) {
|
|
3553
|
+
const relative = paths.relative(root, candidate);
|
|
3554
|
+
return relative !== "" && relative !== ".." && !relative.startsWith(`..${paths.sep}`) && !paths.isAbsolute(relative);
|
|
3555
|
+
}
|
|
3556
|
+
function mapPlatform$4(provider, operation, candidate, phase, fallback = "FilesystemFailed") {
|
|
3557
|
+
return (effect) => effect.pipe(Effect.mapError((cause) => platformFailure$3(provider, operation, candidate, cause, fallback, phase)));
|
|
3558
|
+
}
|
|
3559
|
+
function platformFailure$3(provider, operation, candidate, cause, fallback, phase) {
|
|
3560
|
+
return failure$4(provider, operation, cause.reason._tag === "NotFound" ? "Missing" : fallback, phase, candidate, cause.message);
|
|
3561
|
+
}
|
|
3562
|
+
function fail$4(provider, operation, reason, phase, candidate, detail) {
|
|
3563
|
+
return Effect.fail(failure$4(provider, operation, reason, phase, candidate, detail));
|
|
3564
|
+
}
|
|
3565
|
+
function failure$4(provider, operation, reason, commandPhase, candidate, detail) {
|
|
3566
|
+
return Object.freeze({
|
|
3567
|
+
_tag: "NativeAgentProviderFailure",
|
|
3568
|
+
provider,
|
|
3569
|
+
operation,
|
|
3570
|
+
reason,
|
|
3571
|
+
commandPhase,
|
|
3572
|
+
...candidate === void 0 ? {} : { path: candidate },
|
|
3573
|
+
detail: detail.slice(0, MAX_FAILURE_DETAIL$1)
|
|
3574
|
+
});
|
|
3575
|
+
}
|
|
3576
|
+
function errorMessage$2(error) {
|
|
3577
|
+
return error instanceof Error ? error.message : String(error);
|
|
3578
|
+
}
|
|
3579
|
+
function compareText$8(left, right) {
|
|
3580
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
3581
|
+
}
|
|
3582
|
+
//#endregion
|
|
3158
3583
|
//#region ../../resources/native-agent-provider/providers/effect-platform-node-shared.ts
|
|
3159
3584
|
const MAX_PROCESS_OUTPUT_BYTES = 4194304;
|
|
3160
3585
|
const PROCESS_START_TIMEOUT = "10 seconds";
|
|
@@ -3168,21 +3593,45 @@ const processSemaphores = /* @__PURE__ */ new Map();
|
|
|
3168
3593
|
* The concrete provider fixes its ordinary command before acquisition; the
|
|
3169
3594
|
* caller supplies only the provider-owned home for this session.
|
|
3170
3595
|
*/
|
|
3171
|
-
function acquireEffectPlatformNodeProvider(provider, command, input) {
|
|
3596
|
+
function acquireEffectPlatformNodeProvider(provider, command, input, options = {}) {
|
|
3172
3597
|
return Effect.gen(function* () {
|
|
3173
3598
|
if (!Value.Check(NativeProviderSessionInputSchema, input)) return yield* fail$3(provider, "acquire", "InvalidInput", "not-started", void 0, "Provider session input is invalid");
|
|
3174
3599
|
const fs = yield* FileSystem.FileSystem;
|
|
3175
3600
|
const paths = yield* Path.Path;
|
|
3176
3601
|
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
3177
3602
|
const home = yield* requireCanonicalDirectory(fs, paths, provider, "acquire", input.home);
|
|
3178
|
-
const
|
|
3179
|
-
|
|
3603
|
+
const antigravityLayout = provider === "antigravity" ? antigravityHomeLayout(paths, home) : null;
|
|
3604
|
+
if (antigravityLayout !== null) yield* requireNoAncestorAgentsDirectory(fs, paths, "acquire", antigravityLayout.agyProcessHome);
|
|
3605
|
+
const geminiRoot = antigravityLayout !== null ? antigravityLayout.geminiRoot : home;
|
|
3606
|
+
const claudeUserHome = provider === "claude" ? yield* resolveClaudeDefaultUserHome(fs, paths, home, options.hostUserHome ?? homedir()) : null;
|
|
3607
|
+
const claudeUserConfigRoot = claudeUserHome ?? home;
|
|
3608
|
+
const claudeUserConfigPath = paths.join(claudeUserConfigRoot, ".claude.json");
|
|
3609
|
+
if (input.disposableRoot !== void 0) {
|
|
3610
|
+
const disposableRoot = yield* requireCanonicalDirectory(fs, paths, provider, "acquire", input.disposableRoot);
|
|
3611
|
+
if (!isContained$2(paths, disposableRoot, home)) return yield* fail$3(provider, "acquire", "InvalidInput", "not-started", home, "OutsideDisposableRoot: Provider home escaped the explicit disposable root");
|
|
3612
|
+
if (antigravityLayout !== null && (!isContained$2(paths, disposableRoot, geminiRoot) || antigravityLayout.agyProcessHome !== disposableRoot && !isContained$2(paths, disposableRoot, antigravityLayout.agyProcessHome))) return yield* fail$3(provider, "acquire", "InvalidInput", "not-started", antigravityLayout.agyProcessHome, "OutsideDisposableRoot: Antigravity home layout escaped the explicit disposable root");
|
|
3613
|
+
if (provider === "claude" && (claudeUserHome !== null && !isContained$2(paths, disposableRoot, claudeUserHome) || !isContained$2(paths, disposableRoot, claudeUserConfigPath))) return yield* fail$3(provider, "acquire", "InvalidInput", "not-started", claudeUserConfigPath, "OutsideDisposableRoot: Claude .claude home resolves its user config outside an isolated disposable child home");
|
|
3614
|
+
}
|
|
3615
|
+
const semaphore = processSemaphore(provider, provider === "antigravity" ? geminiRoot : home);
|
|
3616
|
+
const serialized = (operation, effect) => semaphore.withPermits(1)(requireCanonicalDirectory(fs, paths, provider, operation, home).pipe(Effect.flatMap(() => claudeUserHome === null ? Effect.void : requireCanonicalDirectory(fs, paths, provider, operation, claudeUserHome).pipe(Effect.asVoid)), Effect.andThen(effect)));
|
|
3180
3617
|
const run = (operation, args) => runCommand({
|
|
3181
3618
|
provider,
|
|
3182
3619
|
operation,
|
|
3183
3620
|
command,
|
|
3184
3621
|
home,
|
|
3622
|
+
claudeUserHome,
|
|
3623
|
+
args,
|
|
3624
|
+
fs,
|
|
3625
|
+
paths,
|
|
3626
|
+
spawner
|
|
3627
|
+
});
|
|
3628
|
+
const runExternalCommand = (operation, executable, args, cwd, env = {}) => spawnBoundedCommand({
|
|
3629
|
+
provider,
|
|
3630
|
+
operation,
|
|
3631
|
+
command: executable,
|
|
3185
3632
|
args,
|
|
3633
|
+
cwd,
|
|
3634
|
+
env: mergeProcessEnvironment(env),
|
|
3186
3635
|
spawner
|
|
3187
3636
|
});
|
|
3188
3637
|
const mutation = (operation, args) => run(operation, args).pipe(Effect.as(Object.freeze({
|
|
@@ -3191,19 +3640,51 @@ function acquireEffectPlatformNodeProvider(provider, command, input) {
|
|
|
3191
3640
|
commandPhase: "command-returned"
|
|
3192
3641
|
})));
|
|
3193
3642
|
const requireLocalDirectory = (operation, candidate) => requireCanonicalDirectory(fs, paths, provider, operation, candidate);
|
|
3194
|
-
const readPluginEntry = (operation, root, request) => readBoundedPluginFile(fs, paths, provider, operation, home, root, request);
|
|
3643
|
+
const readPluginEntry = (operation, root, request) => readBoundedPluginFile(fs, paths, provider, operation, home, claudeUserHome, root, request);
|
|
3644
|
+
const readOptionalHomeJson = (operation, relativePath) => readBoundedOptionalHomeJson(fs, paths, provider, operation, home, relativePath);
|
|
3645
|
+
const readClaudeUserConfigJson = (operation, commandPhase = "not-started") => resolveActiveClaudeUserConfigJson(fs, paths, provider, operation, home, claudeUserConfigRoot, claudeUserConfigPath, commandPhase);
|
|
3646
|
+
const readCodexConfigToml = (operation, commandPhase = "not-started") => readResilientCodexConfigToml(fs, paths, provider, operation, home, commandPhase);
|
|
3647
|
+
const readAntigravityMcpConfigJson = (operation, commandPhase = "not-started") => readResilientAntigravityMcpConfigJson(fs, paths, provider, operation, home, geminiRoot, commandPhase);
|
|
3648
|
+
const readManagedMcpLedger = (operation) => readProviderManagedMcpLedger(fs, paths, provider, operation, home, geminiRoot);
|
|
3649
|
+
const writeManagedMcpLedger = (operation, servers, commandPhase = "not-started") => writeProviderManagedMcpLedger(fs, paths, provider, operation, home, servers, commandPhase, geminiRoot);
|
|
3650
|
+
const sweepTransientMcpLedger = (operation, commandPhase = "not-started") => sweepTransientMcpLedgerArtifacts(fs, paths, provider, operation, provider === "antigravity" ? paths.join(geminiRoot, "config") : home, commandPhase);
|
|
3195
3651
|
return Object.freeze({
|
|
3196
3652
|
provider,
|
|
3197
3653
|
home,
|
|
3654
|
+
geminiRoot,
|
|
3655
|
+
fs,
|
|
3656
|
+
paths,
|
|
3198
3657
|
serialized,
|
|
3199
3658
|
run,
|
|
3659
|
+
runExternalCommand,
|
|
3200
3660
|
mutation,
|
|
3201
3661
|
requireLocalDirectory,
|
|
3202
3662
|
readPluginEntry,
|
|
3663
|
+
readOptionalHomeJson,
|
|
3664
|
+
readClaudeUserConfigJson,
|
|
3665
|
+
readCodexConfigToml,
|
|
3666
|
+
readAntigravityMcpConfigJson,
|
|
3667
|
+
readManagedMcpLedger,
|
|
3668
|
+
writeManagedMcpLedger,
|
|
3669
|
+
sweepTransientMcpLedger,
|
|
3203
3670
|
homePath: (...segments) => paths.join(home, ...segments)
|
|
3204
3671
|
});
|
|
3205
3672
|
});
|
|
3206
3673
|
}
|
|
3674
|
+
function resolveClaudeDefaultUserHome(fs, paths, home, rawHostUserHome) {
|
|
3675
|
+
return Effect.gen(function* () {
|
|
3676
|
+
const effectiveHostUserHome = yield* fs.realPath(rawHostUserHome).pipe(Effect.orElseSucceed(() => paths.normalize(rawHostUserHome)));
|
|
3677
|
+
const defaultClaudeHomePath = paths.join(effectiveHostUserHome, ".claude");
|
|
3678
|
+
if (home !== (yield* fs.realPath(defaultClaudeHomePath).pipe(Effect.orElseSucceed(() => defaultClaudeHomePath))) && home !== defaultClaudeHomePath) return null;
|
|
3679
|
+
const rawClaudeConfigDir = process.env.CLAUDE_CONFIG_DIR;
|
|
3680
|
+
if (rawClaudeConfigDir !== void 0 && rawClaudeConfigDir !== "") {
|
|
3681
|
+
const normalizedConfigDir = paths.normalize(rawClaudeConfigDir);
|
|
3682
|
+
if (rawClaudeConfigDir === home || normalizedConfigDir === home || normalizedConfigDir === defaultClaudeHomePath) return null;
|
|
3683
|
+
if ((yield* fs.realPath(rawClaudeConfigDir).pipe(Effect.orElseSucceed(() => normalizedConfigDir))) === home) return null;
|
|
3684
|
+
}
|
|
3685
|
+
return yield* requireCanonicalDirectory(fs, paths, "claude", "acquire", effectiveHostUserHome);
|
|
3686
|
+
});
|
|
3687
|
+
}
|
|
3207
3688
|
/** Validates a marketplace source before a concrete provider constructs native arguments. */
|
|
3208
3689
|
function requireMarketplaceSource(provider, operation, source) {
|
|
3209
3690
|
return Value.Check(NativeMarketplaceSourceSchema, source) ? Effect.succeed(source) : fail$3(provider, operation, "InvalidInput", "not-started", void 0, "Marketplace source is invalid");
|
|
@@ -3230,6 +3711,27 @@ function requireMarketplaceIdentityInput(provider, operation, input) {
|
|
|
3230
3711
|
function requirePluginSelectorInput(provider, operation, input) {
|
|
3231
3712
|
return Value.Check(NativeProviderPluginSelectorInputSchema, input) ? Effect.succeed(input.selector) : fail$3(provider, operation, "InvalidInput", "not-started", void 0, "Plugin selector is not canonical");
|
|
3232
3713
|
}
|
|
3714
|
+
/** Validates optional inventory observation flags before native inspection runs. */
|
|
3715
|
+
function requireInventoryOptions(provider, options) {
|
|
3716
|
+
if (options === void 0) return Effect.succeed(Object.freeze({
|
|
3717
|
+
observeMcpServers: true,
|
|
3718
|
+
observePluginConfigForMarketplace: void 0,
|
|
3719
|
+
relevantOwnerPluginIds: void 0
|
|
3720
|
+
}));
|
|
3721
|
+
return Value.Check(NativeProviderInventoryOptionsSchema, options) ? Effect.succeed(Object.freeze({
|
|
3722
|
+
observeMcpServers: options.observeMcpServers ?? true,
|
|
3723
|
+
observePluginConfigForMarketplace: options.observePluginConfigForMarketplace,
|
|
3724
|
+
relevantOwnerPluginIds: options.relevantOwnerPluginIds === void 0 ? void 0 : Object.freeze([...options.relevantOwnerPluginIds])
|
|
3725
|
+
})) : fail$3(provider, "inventory", "InvalidInput", "not-started", void 0, "Provider inventory options are invalid");
|
|
3726
|
+
}
|
|
3727
|
+
/** Validates one host-scoped HTTP MCP server add request before native command construction. */
|
|
3728
|
+
function requireMcpServerAddInput(provider, operation, input) {
|
|
3729
|
+
return Value.Check(NativeProviderMcpServerAddInputSchema, input) ? Effect.succeed(input) : fail$3(provider, operation, "InvalidInput", "not-started", void 0, "MCP server add input is not canonical");
|
|
3730
|
+
}
|
|
3731
|
+
/** Validates one MCP server name before native removal argument construction. */
|
|
3732
|
+
function requireMcpServerRemoveInput(provider, operation, input) {
|
|
3733
|
+
return Value.Check(NativeProviderMcpServerRemoveInputSchema, input) ? Effect.succeed(input.name) : fail$3(provider, operation, "InvalidInput", "not-started", void 0, "MCP server name is not canonical");
|
|
3734
|
+
}
|
|
3233
3735
|
/** Validates one bounded point-addressed plugin-file read request. */
|
|
3234
3736
|
function requirePluginFilesReadInput(provider, operation, input) {
|
|
3235
3737
|
return Value.Check(NativeProviderPluginFilesReadInputSchema, input) ? Effect.succeed(input) : fail$3(provider, operation, "InvalidInput", "not-started", void 0, "Plugin file batch request is invalid");
|
|
@@ -3255,15 +3757,46 @@ function requireGitMarketplaceSource(provider, operation, repositoryUrl, revisio
|
|
|
3255
3757
|
return Object.freeze({
|
|
3256
3758
|
repositoryUrl,
|
|
3257
3759
|
revision,
|
|
3258
|
-
sparsePaths: Object.freeze([...present].sort(compareText$
|
|
3760
|
+
sparsePaths: Object.freeze([...present].sort(compareText$7))
|
|
3259
3761
|
});
|
|
3260
3762
|
});
|
|
3261
3763
|
}
|
|
3262
3764
|
function runCommand(input) {
|
|
3765
|
+
return Effect.gen(function* () {
|
|
3766
|
+
const cwd = input.provider === "antigravity" ? yield* prepareAntigravityGeminiRoot(input.fs, input.paths, input.operation, input.home) : input.home;
|
|
3767
|
+
const env = providerEnvironment(input.paths, input.provider, input.home, input.claudeUserHome);
|
|
3768
|
+
return yield* spawnBoundedCommand({
|
|
3769
|
+
provider: input.provider,
|
|
3770
|
+
operation: input.operation,
|
|
3771
|
+
command: input.command,
|
|
3772
|
+
args: input.args,
|
|
3773
|
+
cwd,
|
|
3774
|
+
env,
|
|
3775
|
+
spawner: input.spawner
|
|
3776
|
+
});
|
|
3777
|
+
});
|
|
3778
|
+
}
|
|
3779
|
+
function prepareAntigravityGeminiRoot(fs, paths, operation, home) {
|
|
3780
|
+
const { agyProcessHome, geminiRoot } = antigravityHomeLayout(paths, home);
|
|
3781
|
+
return requireNoAncestorAgentsDirectory(fs, paths, operation, agyProcessHome).pipe(Effect.andThen(geminiRoot === home ? Effect.succeed(geminiRoot) : fs.makeDirectory(geminiRoot, { recursive: true }).pipe(mapPlatform$3("antigravity", operation, geminiRoot, "not-started"), Effect.andThen(requireCanonicalDirectory(fs, paths, "antigravity", operation, geminiRoot)))));
|
|
3782
|
+
}
|
|
3783
|
+
function requireNoAncestorAgentsDirectory(fs, paths, operation, agyProcessHome) {
|
|
3784
|
+
return Effect.gen(function* () {
|
|
3785
|
+
let current = paths.dirname(agyProcessHome);
|
|
3786
|
+
while (true) {
|
|
3787
|
+
const candidate = paths.join(current, ".agents");
|
|
3788
|
+
if (yield* fs.exists(candidate).pipe(mapPlatform$3("antigravity", operation, candidate, "not-started"))) return yield* fail$3("antigravity", operation, "InvalidInput", "not-started", agyProcessHome, "Antigravity target home cannot reside beneath an ancestor .agents directory");
|
|
3789
|
+
const parent = paths.dirname(current);
|
|
3790
|
+
if (parent === current) break;
|
|
3791
|
+
current = parent;
|
|
3792
|
+
}
|
|
3793
|
+
});
|
|
3794
|
+
}
|
|
3795
|
+
function spawnBoundedCommand(input) {
|
|
3263
3796
|
const command = ChildProcess.make(input.command, input.args, {
|
|
3264
|
-
cwd: input.
|
|
3265
|
-
env:
|
|
3266
|
-
extendEnv:
|
|
3797
|
+
cwd: input.cwd,
|
|
3798
|
+
env: input.env,
|
|
3799
|
+
extendEnv: false,
|
|
3267
3800
|
stdin: "ignore",
|
|
3268
3801
|
forceKillAfter: PROCESS_FORCE_KILL_AFTER$2
|
|
3269
3802
|
});
|
|
@@ -3298,14 +3831,20 @@ function collectBoundedOutput$3(stream, provider, operation, phase) {
|
|
|
3298
3831
|
catch: (cause) => failure$3(provider, operation, "ProtocolFailed", phase, void 0, errorMessage$1(cause))
|
|
3299
3832
|
})));
|
|
3300
3833
|
}
|
|
3301
|
-
function
|
|
3834
|
+
function resolvePluginRootInput(fs, paths, provider, operation, home, claudeUserHome, rootInput) {
|
|
3835
|
+
if (provider !== "claude" || claudeUserHome === null || !isCanonicalAbsolutePath(paths, rootInput)) return Effect.succeed(rootInput);
|
|
3836
|
+
const claudeDefaultHomeAlias = paths.join(claudeUserHome, ".claude");
|
|
3837
|
+
if (rootInput !== claudeDefaultHomeAlias && !isContained$2(paths, claudeDefaultHomeAlias, rootInput)) return Effect.succeed(rootInput);
|
|
3838
|
+
return fs.realPath(claudeDefaultHomeAlias).pipe(mapPlatform$3(provider, operation, claudeDefaultHomeAlias, "not-started"), Effect.flatMap((resolvedAlias) => resolvedAlias === home ? Effect.succeed(rootInput === claudeDefaultHomeAlias ? home : paths.join(home, paths.relative(claudeDefaultHomeAlias, rootInput))) : fail$3(provider, operation, "Aliased", "not-started", rootInput, "Directory path is aliased")));
|
|
3839
|
+
}
|
|
3840
|
+
function readBoundedPluginFile(fs, paths, provider, operation, home, claudeUserHome, rootInput, input) {
|
|
3302
3841
|
return Effect.gen(function* () {
|
|
3303
3842
|
const relativePath = canonicalRelativeFile(input.relativePath);
|
|
3304
3843
|
if (relativePath === void 0) return yield* fail$3(provider, operation, "InvalidInput", "not-started", input.relativePath, "Plugin file path must be one canonical relative POSIX file path");
|
|
3305
|
-
const root = yield* requireCanonicalDirectory(fs, paths, provider, operation, rootInput);
|
|
3306
|
-
if (!isContained(paths, home, root)) return yield* fail$3(provider, operation, "Aliased", "not-started", root, "Installed plugin root escaped the explicit provider home");
|
|
3844
|
+
const root = yield* requireCanonicalDirectory(fs, paths, provider, operation, yield* resolvePluginRootInput(fs, paths, provider, operation, home, claudeUserHome, rootInput));
|
|
3845
|
+
if (!isContained$2(paths, home, root)) return yield* fail$3(provider, operation, "Aliased", "not-started", root, "Installed plugin root escaped the explicit provider home");
|
|
3307
3846
|
const candidate = paths.join(root, ...relativePath.split("/"));
|
|
3308
|
-
if (!isContained(paths, root, candidate)) return yield* fail$3(provider, operation, "Aliased", "not-started", candidate, "Plugin file path escaped its installed package root");
|
|
3847
|
+
if (!isContained$2(paths, root, candidate)) return yield* fail$3(provider, operation, "Aliased", "not-started", candidate, "Plugin file path escaped its installed package root");
|
|
3309
3848
|
if ((yield* fs.realPath(candidate).pipe(mapPlatform$3(provider, operation, candidate, "not-started"))) !== candidate) return yield* fail$3(provider, operation, "Aliased", "not-started", candidate, "Plugin file path is aliased");
|
|
3310
3849
|
const status = yield* fs.stat(candidate).pipe(mapPlatform$3(provider, operation, candidate, "not-started"));
|
|
3311
3850
|
const size = Number(status.size);
|
|
@@ -3340,12 +3879,40 @@ function canonicalRelativeFile(input) {
|
|
|
3340
3879
|
function isCanonicalAbsolutePath(paths, candidate) {
|
|
3341
3880
|
return candidate.length <= 16384 && paths.isAbsolute(candidate) && paths.normalize(candidate) === candidate && candidate !== paths.parse(candidate).root;
|
|
3342
3881
|
}
|
|
3343
|
-
function isContained(paths, root, candidate) {
|
|
3882
|
+
function isContained$2(paths, root, candidate) {
|
|
3344
3883
|
const relative = paths.relative(root, candidate);
|
|
3345
3884
|
return relative !== "" && relative !== ".." && !relative.startsWith(`..${paths.sep}`) && !paths.isAbsolute(relative);
|
|
3346
3885
|
}
|
|
3347
|
-
function
|
|
3348
|
-
return
|
|
3886
|
+
function antigravityHomeLayout(paths, home) {
|
|
3887
|
+
return paths.basename(home) === ".gemini" ? Object.freeze({
|
|
3888
|
+
agyProcessHome: paths.dirname(home),
|
|
3889
|
+
geminiRoot: home
|
|
3890
|
+
}) : Object.freeze({
|
|
3891
|
+
agyProcessHome: home,
|
|
3892
|
+
geminiRoot: paths.join(home, ".gemini")
|
|
3893
|
+
});
|
|
3894
|
+
}
|
|
3895
|
+
function copyDefinedProcessEnv(skipKey) {
|
|
3896
|
+
const env = {};
|
|
3897
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
3898
|
+
if (value === void 0 || key === skipKey) continue;
|
|
3899
|
+
env[key] = value;
|
|
3900
|
+
}
|
|
3901
|
+
return env;
|
|
3902
|
+
}
|
|
3903
|
+
function mergeProcessEnvironment(overrides) {
|
|
3904
|
+
const env = copyDefinedProcessEnv();
|
|
3905
|
+
for (const [key, value] of Object.entries(overrides)) if (value === void 0) delete env[key];
|
|
3906
|
+
else env[key] = value;
|
|
3907
|
+
return env;
|
|
3908
|
+
}
|
|
3909
|
+
function providerEnvironment(paths, provider, home, claudeUserHome) {
|
|
3910
|
+
const env = copyDefinedProcessEnv(provider === "claude" && claudeUserHome !== null ? "CLAUDE_CONFIG_DIR" : void 0);
|
|
3911
|
+
if (provider === "codex") env.CODEX_HOME = home;
|
|
3912
|
+
else if (provider === "antigravity") env.HOME = antigravityHomeLayout(paths, home).agyProcessHome;
|
|
3913
|
+
else if (claudeUserHome !== null) env.HOME = claudeUserHome;
|
|
3914
|
+
else env.CLAUDE_CONFIG_DIR = home;
|
|
3915
|
+
return env;
|
|
3349
3916
|
}
|
|
3350
3917
|
function processSemaphore(provider, home) {
|
|
3351
3918
|
const key = `${provider}\u0000${home}`;
|
|
@@ -3388,105 +3955,1421 @@ function failure$3(provider, operation, reason, commandPhase, candidate, detail)
|
|
|
3388
3955
|
function errorMessage$1(error) {
|
|
3389
3956
|
return error instanceof Error ? error.message : String(error);
|
|
3390
3957
|
}
|
|
3391
|
-
function compareText$
|
|
3958
|
+
function compareText$7(left, right) {
|
|
3392
3959
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
3393
3960
|
}
|
|
3394
3961
|
//#endregion
|
|
3395
|
-
//#region ../../resources/native-agent-provider/dist/providers/
|
|
3396
|
-
const
|
|
3397
|
-
const
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3962
|
+
//#region ../../resources/native-agent-provider/dist/providers/antigravity-effect-platform-node/ledger.js
|
|
3963
|
+
const utf8Decoder$1 = new TextDecoder("utf-8", { fatal: true });
|
|
3964
|
+
const utf8Encoder$1 = new TextEncoder();
|
|
3965
|
+
/** Provider-owned ledger filename stored under `<geminiRoot>/config/` outside installed plugins. */
|
|
3966
|
+
const PLUGIN_LEDGER_FILENAME = ".habitat-plugin-ledger.json";
|
|
3967
|
+
const MAX_PLUGIN_LEDGER_BYTES = 2097152;
|
|
3968
|
+
/** Canonical lowercase plugin identifier required for Habitat-managed Antigravity installs. */
|
|
3969
|
+
const CanonicalPluginNameSchema = Type.String({
|
|
3970
|
+
pattern: "^[a-z0-9][a-z0-9._-]*$",
|
|
3971
|
+
maxLength: 128
|
|
3401
3972
|
});
|
|
3402
|
-
const
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
"marketplace-add",
|
|
3421
|
-
"marketplace-remove",
|
|
3422
|
-
"marketplace-update",
|
|
3423
|
-
"plugin-list",
|
|
3424
|
-
"plugin-install",
|
|
3425
|
-
"plugin-enable",
|
|
3426
|
-
"plugin-disable",
|
|
3427
|
-
"plugin-remove",
|
|
3428
|
-
"plugin-update"
|
|
3429
|
-
];
|
|
3973
|
+
const MarketplaceNameSchema$1 = Type.String({
|
|
3974
|
+
pattern: "^[a-z0-9][a-z0-9_-]*$",
|
|
3975
|
+
maxLength: 128
|
|
3976
|
+
});
|
|
3977
|
+
const Sha256HexSchema = Type.String({ pattern: "^[0-9a-f]{64}$" });
|
|
3978
|
+
const PluginLedgerEntrySchema = Type.Object({
|
|
3979
|
+
name: CanonicalPluginNameSchema,
|
|
3980
|
+
marketplaceIdentity: MarketplaceNameSchema$1,
|
|
3981
|
+
installedTreeSha256: Sha256HexSchema,
|
|
3982
|
+
acceptedTreeSha256s: Type.Optional(Type.Array(Sha256HexSchema, {
|
|
3983
|
+
minItems: 1,
|
|
3984
|
+
maxItems: 2
|
|
3985
|
+
}))
|
|
3986
|
+
}, { additionalProperties: false });
|
|
3987
|
+
const PluginLedgerSchema = Type.Object({
|
|
3988
|
+
schemaVersion: Type.Literal(1),
|
|
3989
|
+
plugins: Type.Array(PluginLedgerEntrySchema, { maxItems: 4096 })
|
|
3990
|
+
}, { additionalProperties: false });
|
|
3430
3991
|
/**
|
|
3431
|
-
*
|
|
3992
|
+
* Checks whether a live plugin directory digest matches an entry recorded in the Habitat ledger.
|
|
3432
3993
|
*/
|
|
3433
|
-
function
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3994
|
+
function isLedgerAcceptedDigest(entry, liveTreeSha256) {
|
|
3995
|
+
return entry !== void 0 && liveTreeSha256 !== null && entry.acceptedTreeSha256s.includes(liveTreeSha256);
|
|
3996
|
+
}
|
|
3997
|
+
/**
|
|
3998
|
+
* Computes the canonical whole-tree SHA-256 over all regular files in a plugin directory,
|
|
3999
|
+
* skipping any top-level `.in_use` runtime directory created by the Antigravity desktop app.
|
|
4000
|
+
*/
|
|
4001
|
+
function computeDirectoryTreeSha256(kernel, operation, containmentRoot, pluginRoot, phase) {
|
|
4002
|
+
return Effect.gen(function* () {
|
|
4003
|
+
if (!isContained$1(kernel.paths, containmentRoot, pluginRoot)) return yield* Effect.fail(ledgerFailure(operation, "Aliased", phase, "Plugin directory escaped its containment root", pluginRoot));
|
|
4004
|
+
const verifiedRoot = yield* kernel.requireLocalDirectory(operation, pluginRoot).pipe(Effect.mapError((error) => ({
|
|
4005
|
+
...error,
|
|
4006
|
+
commandPhase: phase
|
|
4007
|
+
})));
|
|
4008
|
+
const collected = [];
|
|
4009
|
+
const visit = (currentDir, prefix) => Effect.gen(function* () {
|
|
4010
|
+
const names = yield* kernel.fs.readDirectory(currentDir).pipe(mapLedgerFs(operation, currentDir, phase));
|
|
4011
|
+
for (const name of [...names].sort(compareText$6)) {
|
|
4012
|
+
if (prefix === "" && name === ".in_use") continue;
|
|
4013
|
+
const candidate = kernel.paths.join(currentDir, name);
|
|
4014
|
+
if ((yield* kernel.fs.realPath(candidate).pipe(mapLedgerFs(operation, candidate, phase))) !== candidate) return yield* Effect.fail(ledgerFailure(operation, "Aliased", phase, "Plugin tree entry is aliased", candidate));
|
|
4015
|
+
const stat = yield* kernel.fs.stat(candidate).pipe(mapLedgerFs(operation, candidate, phase));
|
|
4016
|
+
const relativePath = prefix === "" ? name : `${prefix}/${name}`;
|
|
4017
|
+
if (stat.type === "Directory") {
|
|
4018
|
+
yield* visit(candidate, relativePath);
|
|
4019
|
+
continue;
|
|
4020
|
+
}
|
|
4021
|
+
if (stat.type !== "File") return yield* Effect.fail(ledgerFailure(operation, "UnsupportedEntry", phase, "Plugin tree entry must be a regular file or directory", candidate));
|
|
4022
|
+
if (collected.length >= 16384) return yield* Effect.fail(ledgerFailure(operation, "LimitExceeded", phase, "Plugin tree file count exceeds the provider bound", verifiedRoot));
|
|
4023
|
+
const size = Number(stat.size);
|
|
4024
|
+
if (!Number.isSafeInteger(size) || size < 0 || size > 67108864) return yield* Effect.fail(ledgerFailure(operation, "LimitExceeded", phase, "Plugin tree file exceeds the provider byte bound", candidate));
|
|
4025
|
+
const bytes = yield* kernel.fs.readFile(candidate).pipe(mapLedgerFs(operation, candidate, phase));
|
|
4026
|
+
const mode = (Number(stat.mode) & 73) !== 0 ? "0755" : "0644";
|
|
4027
|
+
const fileSha256 = createHash("sha256").update(bytes).digest("hex");
|
|
4028
|
+
collected.push(Object.freeze({
|
|
4029
|
+
path: relativePath,
|
|
4030
|
+
mode,
|
|
4031
|
+
fileSha256
|
|
4032
|
+
}));
|
|
4033
|
+
}
|
|
4034
|
+
});
|
|
4035
|
+
yield* visit(verifiedRoot, "");
|
|
4036
|
+
collected.sort((left, right) => compareText$6(left.path, right.path));
|
|
4037
|
+
const hash = createHash("sha256");
|
|
4038
|
+
for (const item of collected) hash.update(`${item.path}\u0000${item.mode}\u0000${item.fileSha256}\n`);
|
|
4039
|
+
return hash.digest("hex");
|
|
4040
|
+
});
|
|
4041
|
+
}
|
|
4042
|
+
/**
|
|
4043
|
+
* Computes the whole-tree SHA-256 for a ledger-known installed plugin directory.
|
|
4044
|
+
*
|
|
4045
|
+
* Missing, aliased, or non-directory roots return `null` so inventory treats the slot as
|
|
4046
|
+
* unmanaged, while `FilesystemFailed` (such as `EACCES`) and `LimitExceeded` propagate as
|
|
4047
|
+
* typed provider failures rather than misclassifying I/O errors as foreign collisions.
|
|
4048
|
+
*/
|
|
4049
|
+
function readLedgerKnownPluginTreeSha256(kernel, operation, pluginRootCandidate, phase) {
|
|
4050
|
+
if (pluginRootCandidate === null || !isContained$1(kernel.paths, kernel.home, pluginRootCandidate)) return Effect.succeed(null);
|
|
4051
|
+
return computeDirectoryTreeSha256(kernel, operation, kernel.home, pluginRootCandidate, phase).pipe(Effect.catchIf((error) => error.reason === "Missing" || error.reason === "Aliased" || error.reason === "UnsupportedEntry", () => Effect.succeed(null)));
|
|
4052
|
+
}
|
|
4053
|
+
/**
|
|
4054
|
+
* Reads and validates `<geminiRoot>/config/.habitat-plugin-ledger.json`.
|
|
4055
|
+
*/
|
|
4056
|
+
function readPluginLedger(kernel, operation, phase) {
|
|
4057
|
+
return Effect.gen(function* () {
|
|
4058
|
+
const ledgerPath = kernel.paths.join(kernel.geminiRoot, "config", PLUGIN_LEDGER_FILENAME);
|
|
4059
|
+
if (!(yield* kernel.fs.exists(ledgerPath).pipe(mapLedgerFs(operation, ledgerPath, phase)))) return Object.freeze([]);
|
|
4060
|
+
if (!isContained$1(kernel.paths, kernel.home, ledgerPath)) return yield* Effect.fail(ledgerFailure(operation, "Aliased", phase, "Antigravity plugin ledger escaped the explicit provider home", ledgerPath));
|
|
4061
|
+
if ((yield* kernel.fs.realPath(ledgerPath).pipe(mapLedgerFs(operation, ledgerPath, phase))) !== ledgerPath) return yield* Effect.fail(ledgerFailure(operation, "Aliased", phase, "Plugin ledger path is aliased", ledgerPath));
|
|
4062
|
+
const stat = yield* kernel.fs.stat(ledgerPath).pipe(mapLedgerFs(operation, ledgerPath, phase));
|
|
4063
|
+
if (stat.type !== "File") return yield* Effect.fail(ledgerFailure(operation, "UnsupportedEntry", phase, "Plugin ledger must be a regular file", ledgerPath));
|
|
4064
|
+
const size = Number(stat.size);
|
|
4065
|
+
if (!Number.isSafeInteger(size) || size < 0 || size > MAX_PLUGIN_LEDGER_BYTES) return yield* Effect.fail(ledgerFailure(operation, "LimitExceeded", phase, "Plugin ledger exceeds bounded size", ledgerPath));
|
|
4066
|
+
const bytes = yield* kernel.fs.readFile(ledgerPath).pipe(mapLedgerFs(operation, ledgerPath, phase));
|
|
4067
|
+
const rawText = yield* Effect.try({
|
|
4068
|
+
try: () => utf8Decoder$1.decode(bytes),
|
|
4069
|
+
catch: () => ledgerFailure(operation, "ProtocolFailed", phase, "Plugin ledger is not valid UTF-8", ledgerPath)
|
|
4070
|
+
});
|
|
4071
|
+
const decoded = yield* decodeLedgerJson(operation, PluginLedgerSchema, rawText, phase);
|
|
4072
|
+
if (new Set(decoded.plugins.map((entry) => entry.name)).size !== decoded.plugins.length) return yield* Effect.fail(ledgerFailure(operation, "ProtocolFailed", phase, "Antigravity plugin ledger contains duplicate plugin names", ledgerPath));
|
|
4073
|
+
return Object.freeze(decoded.plugins.map((entry) => {
|
|
4074
|
+
const accepted = entry.acceptedTreeSha256s === void 0 ? [entry.installedTreeSha256] : [.../* @__PURE__ */ new Set([entry.installedTreeSha256, ...entry.acceptedTreeSha256s])].slice(0, 2);
|
|
3438
4075
|
return Object.freeze({
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
4076
|
+
name: entry.name,
|
|
4077
|
+
marketplaceIdentity: entry.marketplaceIdentity,
|
|
4078
|
+
installedTreeSha256: entry.installedTreeSha256,
|
|
4079
|
+
acceptedTreeSha256s: Object.freeze(accepted)
|
|
3443
4080
|
});
|
|
3444
4081
|
}));
|
|
3445
|
-
|
|
3446
|
-
const inventory = () => kernel.serialized("inventory", readInventory());
|
|
3447
|
-
return Object.freeze({
|
|
3448
|
-
provider: "claude",
|
|
3449
|
-
home: kernel.home,
|
|
3450
|
-
probe,
|
|
3451
|
-
inventory,
|
|
3452
|
-
readPluginFiles: (request) => kernel.serialized("plugin-files-read", requirePluginFilesReadInput("claude", "plugin-files-read", request).pipe(Effect.flatMap((validated) => readInventory().pipe(Effect.flatMap((live) => selectPluginRoot$1(live.plugins, validated.selector).pipe(Effect.flatMap((root) => Effect.forEach(validated.files, (file) => kernel.readPluginEntry("plugin-files-read", root, file).pipe(Effect.catchIf((error) => error.reason === "Missing" || error.reason === "LimitExceeded", (error) => {
|
|
3453
|
-
const missing = Object.freeze({
|
|
3454
|
-
kind: error.reason === "Missing" ? "Missing" : "TooLarge",
|
|
3455
|
-
relativePath: file.relativePath
|
|
3456
|
-
});
|
|
3457
|
-
return Effect.succeed(missing);
|
|
3458
|
-
})), { concurrency: 1 }).pipe(Effect.map((files) => {
|
|
3459
|
-
return Object.freeze({
|
|
3460
|
-
selector: validated.selector,
|
|
3461
|
-
files: Object.freeze(files)
|
|
3462
|
-
});
|
|
3463
|
-
}))))))))),
|
|
3464
|
-
addMarketplace: (source) => kernel.serialized("marketplace-add", requireMarketplaceSource("claude", "marketplace-add", source).pipe(Effect.flatMap((validated) => claudeMarketplaceAddArgs(kernel, validated)), Effect.flatMap((args) => kernel.mutation("marketplace-add", args)))),
|
|
3465
|
-
removeMarketplace: (request) => kernel.serialized("marketplace-remove", requireMarketplaceIdentityInput("claude", "marketplace-remove", request).pipe(Effect.flatMap((identity) => kernel.mutation("marketplace-remove", [
|
|
3466
|
-
"plugin",
|
|
3467
|
-
"marketplace",
|
|
3468
|
-
"remove",
|
|
3469
|
-
identity,
|
|
3470
|
-
"--scope",
|
|
3471
|
-
"user"
|
|
3472
|
-
])))),
|
|
3473
|
-
installPlugin: (request) => kernel.serialized("plugin-install", requirePluginSelectorInput("claude", "plugin-install", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-install", "install", selector)))),
|
|
3474
|
-
enablePlugin: (request) => kernel.serialized("plugin-enable", requirePluginSelectorInput("claude", "plugin-enable", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-enable", "enable", selector)))),
|
|
3475
|
-
removePlugin: (request) => kernel.serialized("plugin-remove", requirePluginSelectorInput("claude", "plugin-remove", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-remove", "uninstall", selector))))
|
|
3476
|
-
});
|
|
3477
|
-
})) });
|
|
4082
|
+
});
|
|
3478
4083
|
}
|
|
3479
4084
|
/**
|
|
3480
|
-
*
|
|
3481
|
-
*
|
|
4085
|
+
* Records a pending plugin install in `.habitat-plugin-ledger.json` BEFORE invoking `agy plugin install`
|
|
4086
|
+
* so neither pre-copy failure nor post-copy crash/non-zero exit can strand ownership attribution.
|
|
3482
4087
|
*/
|
|
3483
|
-
function
|
|
3484
|
-
const provider = makeClaudeEffectPlatformNodeProvider(options);
|
|
3485
|
-
return Object.freeze({ acquire: (input) => provider.acquire(input).pipe(Effect.provide(NodeServices.layer)) });
|
|
3486
|
-
}
|
|
3487
|
-
function claudeInventory(kernel) {
|
|
4088
|
+
function recordPendingPluginInstall(kernel, existingLedger, input) {
|
|
3488
4089
|
return Effect.gen(function* () {
|
|
3489
|
-
const
|
|
4090
|
+
const accepted = input.previousTreeSha256 !== null && input.previousTreeSha256 !== input.stagedTreeSha256 ? Object.freeze([input.previousTreeSha256, input.stagedTreeSha256]) : Object.freeze([input.stagedTreeSha256]);
|
|
4091
|
+
const byName = new Map(existingLedger.map((entry) => [entry.name, entry]));
|
|
4092
|
+
byName.set(input.name, Object.freeze({
|
|
4093
|
+
name: input.name,
|
|
4094
|
+
marketplaceIdentity: input.marketplaceIdentity,
|
|
4095
|
+
installedTreeSha256: input.stagedTreeSha256,
|
|
4096
|
+
acceptedTreeSha256s: accepted
|
|
4097
|
+
}));
|
|
4098
|
+
yield* writePluginLedger(kernel, "plugin-install", [...byName.values()], "not-started");
|
|
4099
|
+
return Object.freeze({ needsPostInstallSettle: accepted.length > 1 });
|
|
4100
|
+
});
|
|
4101
|
+
}
|
|
4102
|
+
/**
|
|
4103
|
+
* Narrows `acceptedTreeSha256s` to `[stagedTreeSha256]` once `agy plugin install` completes cleanly.
|
|
4104
|
+
*/
|
|
4105
|
+
function settlePluginInstall(kernel, input) {
|
|
4106
|
+
return Effect.gen(function* () {
|
|
4107
|
+
const existing = yield* readPluginLedger(kernel, "plugin-install", "command-returned");
|
|
4108
|
+
const byName = new Map(existing.map((entry) => [entry.name, entry]));
|
|
4109
|
+
byName.set(input.name, Object.freeze({
|
|
4110
|
+
name: input.name,
|
|
4111
|
+
marketplaceIdentity: input.marketplaceIdentity,
|
|
4112
|
+
installedTreeSha256: input.stagedTreeSha256,
|
|
4113
|
+
acceptedTreeSha256s: Object.freeze([input.stagedTreeSha256])
|
|
4114
|
+
}));
|
|
4115
|
+
yield* writePluginLedger(kernel, "plugin-install", [...byName.values()], "command-returned");
|
|
4116
|
+
});
|
|
4117
|
+
}
|
|
4118
|
+
/**
|
|
4119
|
+
* Removes only `removedName` from `.habitat-plugin-ledger.json` without pruning unrelated entries.
|
|
4120
|
+
*/
|
|
4121
|
+
function deletePluginLedgerEntry(kernel, operation, removedName) {
|
|
4122
|
+
return Effect.gen(function* () {
|
|
4123
|
+
const existing = yield* readPluginLedger(kernel, operation, "command-returned");
|
|
4124
|
+
const retained = existing.filter((entry) => entry.name !== removedName);
|
|
4125
|
+
if (retained.length === existing.length) return;
|
|
4126
|
+
yield* writePluginLedger(kernel, operation, retained, "command-returned");
|
|
4127
|
+
});
|
|
4128
|
+
}
|
|
4129
|
+
/**
|
|
4130
|
+
* Sweeps crash-leftover `<geminiRoot>/config/.habitat-plugin-ledger.json.tmp-*` and
|
|
4131
|
+
* `<geminiRoot>/config/.habitat-host-mcp-ledger.json.tmp-*` regular files and
|
|
4132
|
+
* `<geminiRoot>/config/marketplaces/.staging-*` entries at the start of serialized provider
|
|
4133
|
+
* mutations without following symbolic links.
|
|
4134
|
+
*/
|
|
4135
|
+
function sweepAntigravityTransientArtifacts(kernel, operation) {
|
|
4136
|
+
return Effect.gen(function* () {
|
|
4137
|
+
if (!(yield* kernel.fs.exists(kernel.geminiRoot).pipe(mapLedgerFs(operation, kernel.geminiRoot, "not-started")))) return;
|
|
4138
|
+
yield* kernel.requireLocalDirectory(operation, kernel.geminiRoot).pipe(Effect.mapError((error) => ({
|
|
4139
|
+
...error,
|
|
4140
|
+
commandPhase: "not-started"
|
|
4141
|
+
})));
|
|
4142
|
+
const configDir = kernel.paths.join(kernel.geminiRoot, "config");
|
|
4143
|
+
if (!isContained$1(kernel.paths, kernel.home, configDir)) return yield* Effect.fail(ledgerFailure(operation, "Aliased", "not-started", "Antigravity config directory escaped the explicit provider home", configDir));
|
|
4144
|
+
if (!(yield* kernel.fs.exists(configDir).pipe(mapLedgerFs(operation, configDir, "not-started")))) return;
|
|
4145
|
+
const verifiedConfigDir = yield* kernel.requireLocalDirectory(operation, configDir).pipe(Effect.mapError((error) => ({
|
|
4146
|
+
...error,
|
|
4147
|
+
commandPhase: "not-started"
|
|
4148
|
+
})));
|
|
4149
|
+
yield* sweepTransientMcpLedgerArtifacts(kernel.fs, kernel.paths, "antigravity", operation, verifiedConfigDir, "not-started");
|
|
4150
|
+
const pluginLedgerTempPrefix = `${PLUGIN_LEDGER_FILENAME}.tmp-`;
|
|
4151
|
+
const configEntries = yield* kernel.fs.readDirectory(verifiedConfigDir).pipe(mapLedgerFs(operation, verifiedConfigDir, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed([])));
|
|
4152
|
+
const nowMs = Date.now();
|
|
4153
|
+
for (const name of [...configEntries].sort(compareText$6)) {
|
|
4154
|
+
if (!name.startsWith(pluginLedgerTempPrefix)) continue;
|
|
4155
|
+
const candidate = kernel.paths.join(verifiedConfigDir, name);
|
|
4156
|
+
if (!isContained$1(kernel.paths, verifiedConfigDir, candidate)) continue;
|
|
4157
|
+
const info = yield* lstatOptional(kernel, operation, candidate);
|
|
4158
|
+
if (info === null || info.type === "SymbolicLink") continue;
|
|
4159
|
+
if (info.type === "File") {
|
|
4160
|
+
if (shouldSweepLedgerTempFile(name, pluginLedgerTempPrefix, Option.isSome(info.mtime) ? info.mtime.value.getTime() : null, nowMs)) yield* kernel.fs.remove(candidate).pipe(mapLedgerFs(operation, candidate, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.void));
|
|
4161
|
+
} else if (info.type === "Directory") yield* removeEmptyDirectoryNonRecursive("antigravity", operation, candidate, "not-started");
|
|
4162
|
+
}
|
|
4163
|
+
const marketplacesDir = kernel.paths.join(verifiedConfigDir, "marketplaces");
|
|
4164
|
+
if (!(yield* kernel.fs.exists(marketplacesDir).pipe(mapLedgerFs(operation, marketplacesDir, "not-started")))) return;
|
|
4165
|
+
const verifiedMarketplacesDir = yield* kernel.requireLocalDirectory(operation, marketplacesDir).pipe(Effect.mapError((error) => ({
|
|
4166
|
+
...error,
|
|
4167
|
+
commandPhase: "not-started"
|
|
4168
|
+
})));
|
|
4169
|
+
const stagingLivePidPattern = /^\.staging-[a-z0-9][a-z0-9_-]*-([1-9][0-9]{0,9})-[0-9]+-/u;
|
|
4170
|
+
const marketplaceEntries = yield* kernel.fs.readDirectory(verifiedMarketplacesDir).pipe(mapLedgerFs(operation, verifiedMarketplacesDir, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed([])));
|
|
4171
|
+
for (const name of [...marketplaceEntries].sort(compareText$6)) {
|
|
4172
|
+
if (!name.startsWith(".staging-")) continue;
|
|
4173
|
+
const stagingPidMatch = stagingLivePidPattern.exec(name);
|
|
4174
|
+
if (stagingPidMatch !== null) {
|
|
4175
|
+
const stagingPid = Number(stagingPidMatch[1]);
|
|
4176
|
+
if (Number.isSafeInteger(stagingPid) && stagingPid > 0 && isProcessAlive(stagingPid)) continue;
|
|
4177
|
+
}
|
|
4178
|
+
yield* removeContainedTransientEntry(kernel, operation, verifiedMarketplacesDir, kernel.paths.join(verifiedMarketplacesDir, name));
|
|
4179
|
+
}
|
|
4180
|
+
});
|
|
4181
|
+
}
|
|
4182
|
+
function removeContainedTransientEntry(kernel, operation, containmentRoot, candidate) {
|
|
4183
|
+
return Effect.gen(function* () {
|
|
4184
|
+
if (!isContained$1(kernel.paths, containmentRoot, candidate)) return;
|
|
4185
|
+
const info = yield* lstatOptional(kernel, operation, candidate);
|
|
4186
|
+
if (info === null || info.type === "SymbolicLink") return;
|
|
4187
|
+
if (info.type === "Directory") {
|
|
4188
|
+
const children = yield* kernel.fs.readDirectory(candidate).pipe(mapLedgerFs(operation, candidate, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed([])));
|
|
4189
|
+
for (const child of [...children].sort(compareText$6)) yield* removeContainedTransientEntry(kernel, operation, containmentRoot, kernel.paths.join(candidate, child));
|
|
4190
|
+
yield* removeEmptyDirectoryNonRecursive("antigravity", operation, candidate, "not-started");
|
|
4191
|
+
return;
|
|
4192
|
+
}
|
|
4193
|
+
yield* kernel.fs.remove(candidate).pipe(mapLedgerFs(operation, candidate, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.void));
|
|
4194
|
+
});
|
|
4195
|
+
}
|
|
4196
|
+
function lstatOptional(kernel, operation, candidate) {
|
|
4197
|
+
return kernel.fs.lstat(candidate).pipe(Effect.catchIf((cause) => cause.reason._tag === "NotFound", () => Effect.succeed(null)), mapLedgerFs(operation, candidate, "not-started"));
|
|
4198
|
+
}
|
|
4199
|
+
function writePluginLedger(kernel, operation, entries, phase) {
|
|
4200
|
+
return Effect.gen(function* () {
|
|
4201
|
+
const configDir = kernel.paths.join(kernel.geminiRoot, "config");
|
|
4202
|
+
yield* kernel.fs.makeDirectory(configDir, { recursive: true }).pipe(mapLedgerFs(operation, configDir, phase));
|
|
4203
|
+
const verifiedConfigDir = yield* kernel.requireLocalDirectory(operation, configDir).pipe(Effect.mapError((error) => ({
|
|
4204
|
+
...error,
|
|
4205
|
+
commandPhase: phase
|
|
4206
|
+
})));
|
|
4207
|
+
if (!isContained$1(kernel.paths, kernel.home, verifiedConfigDir)) return yield* Effect.fail(ledgerFailure(operation, "Aliased", phase, "Antigravity config directory escaped the explicit provider home", verifiedConfigDir));
|
|
4208
|
+
const sorted = [...entries].sort((left, right) => compareText$6(left.name, right.name)).map((entry) => ({
|
|
4209
|
+
name: entry.name,
|
|
4210
|
+
marketplaceIdentity: entry.marketplaceIdentity,
|
|
4211
|
+
installedTreeSha256: entry.installedTreeSha256,
|
|
4212
|
+
acceptedTreeSha256s: [...entry.acceptedTreeSha256s]
|
|
4213
|
+
}));
|
|
4214
|
+
const payload = utf8Encoder$1.encode(`${JSON.stringify({
|
|
4215
|
+
schemaVersion: 1,
|
|
4216
|
+
plugins: sorted
|
|
4217
|
+
}, null, 2)}\n`);
|
|
4218
|
+
const tempName = `${PLUGIN_LEDGER_FILENAME}.tmp-${process.pid}-${Date.now()}-${randomUUID()}`;
|
|
4219
|
+
const tempPath = kernel.paths.join(verifiedConfigDir, tempName);
|
|
4220
|
+
const targetPath = kernel.paths.join(verifiedConfigDir, PLUGIN_LEDGER_FILENAME);
|
|
4221
|
+
return yield* Effect.acquireUseRelease(kernel.fs.writeFile(tempPath, payload, {
|
|
4222
|
+
flag: "wx",
|
|
4223
|
+
mode: 420
|
|
4224
|
+
}).pipe(Effect.tapError((cause) => isAlreadyExistsPlatformError(cause) ? Effect.void : kernel.fs.remove(tempPath, { force: true }).pipe(Effect.ignore)), mapLedgerFs(operation, tempPath, phase), Effect.as(tempPath)), () => kernel.fs.chmod(tempPath, 420).pipe(mapLedgerFs(operation, tempPath, phase), Effect.andThen(kernel.fs.rename(tempPath, targetPath).pipe(mapLedgerFs(operation, targetPath, phase)))), (createdTemp) => kernel.fs.remove(createdTemp, { force: true }).pipe(Effect.ignore));
|
|
4225
|
+
});
|
|
4226
|
+
}
|
|
4227
|
+
function decodeLedgerJson(operation, schema, text, phase) {
|
|
4228
|
+
return Effect.try({
|
|
4229
|
+
try: () => JSON.parse(text),
|
|
4230
|
+
catch: (cause) => ledgerFailure(operation, "InvalidJson", phase, cause instanceof Error ? cause.message : String(cause))
|
|
4231
|
+
}).pipe(Effect.flatMap((value) => Value.Check(schema, value) ? Effect.succeed(value) : Effect.fail(ledgerFailure(operation, "ProtocolFailed", phase, "Antigravity plugin ledger did not match expected schema"))));
|
|
4232
|
+
}
|
|
4233
|
+
function mapLedgerFs(operation, candidate, phase) {
|
|
4234
|
+
return (effect) => effect.pipe(Effect.mapError((cause) => ledgerFailure(operation, cause.reason._tag === "NotFound" ? "Missing" : "FilesystemFailed", phase, cause.message, candidate)));
|
|
4235
|
+
}
|
|
4236
|
+
function ledgerFailure(operation, reason, commandPhase, detail, candidate) {
|
|
4237
|
+
return Object.freeze({
|
|
4238
|
+
_tag: "NativeAgentProviderFailure",
|
|
4239
|
+
provider: "antigravity",
|
|
4240
|
+
operation,
|
|
4241
|
+
reason,
|
|
4242
|
+
commandPhase,
|
|
4243
|
+
...candidate === void 0 ? {} : { path: candidate },
|
|
4244
|
+
detail: detail.slice(0, 4096)
|
|
4245
|
+
});
|
|
4246
|
+
}
|
|
4247
|
+
function isContained$1(paths, root, candidate) {
|
|
4248
|
+
const relative = paths.relative(root, candidate);
|
|
4249
|
+
return relative !== "" && relative !== ".." && !relative.startsWith(`..${paths.sep}`) && !paths.isAbsolute(relative);
|
|
4250
|
+
}
|
|
4251
|
+
function compareText$6(left, right) {
|
|
4252
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
4253
|
+
}
|
|
4254
|
+
//#endregion
|
|
4255
|
+
//#region ../../resources/native-agent-provider/dist/providers/antigravity-effect-platform-node/mcp.js
|
|
4256
|
+
const MAX_OBSERVED_URL_LENGTH$2 = 4096;
|
|
4257
|
+
/**
|
|
4258
|
+
* Reads and permissively normalizes Antigravity's offline `<geminiRoot>/config/mcp_config.json`
|
|
4259
|
+
* `mcpServers` entries without invoking network-probing CLI commands.
|
|
4260
|
+
*/
|
|
4261
|
+
function readAntigravityLiveMcpServers(kernel, operation, commandPhase = "not-started") {
|
|
4262
|
+
return kernel.readAntigravityMcpConfigJson(operation, commandPhase).pipe(Effect.flatMap((mcpConfig) => decodeAntigravityMcpServers(operation, commandPhase, mcpConfig)));
|
|
4263
|
+
}
|
|
4264
|
+
/**
|
|
4265
|
+
* Executes a serialized Antigravity user-scope HTTP MCP add (`agy mcp add --type http`) guarded by
|
|
4266
|
+
* preflight unmanaged-upsert checks, write-ahead ledger ownership under `<geminiRoot>/config/`,
|
|
4267
|
+
* and rollback on confirmed absence after a failed command.
|
|
4268
|
+
*/
|
|
4269
|
+
function addAntigravityMcpServer(kernel, request) {
|
|
4270
|
+
return kernel.serialized("mcp-add", requireMcpServerAddInput("antigravity", "mcp-add", request).pipe(Effect.flatMap(({ name, url, ownerPluginId }) => Effect.gen(function* () {
|
|
4271
|
+
yield* sweepAntigravityTransientArtifacts(kernel, "mcp-add");
|
|
4272
|
+
const previousLedger = yield* kernel.readManagedMcpLedger("mcp-add");
|
|
4273
|
+
const liveBefore = yield* readAntigravityLiveMcpServers(kernel, "mcp-add", "not-started");
|
|
4274
|
+
const previousEntry = previousLedger.find((entry) => entry.name === name);
|
|
4275
|
+
const existingLive = liveBefore.find((entry) => entry.name === name);
|
|
4276
|
+
if (existingLive !== void 0 && (previousEntry === void 0 || existingLive.transport !== "http" || existingLive.url !== previousEntry.url)) return yield* Effect.fail(antigravityMcpFailure("mcp-add", "InvalidInput", "not-started", `Refusing to overwrite unmanaged MCP server ${name}`));
|
|
4277
|
+
const nextLedger = [...previousLedger.filter((entry) => entry.name !== name), Object.freeze({
|
|
4278
|
+
name,
|
|
4279
|
+
url,
|
|
4280
|
+
ownerPluginId
|
|
4281
|
+
})];
|
|
4282
|
+
yield* kernel.writeManagedMcpLedger("mcp-add", nextLedger, "not-started");
|
|
4283
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-add", [
|
|
4284
|
+
"mcp",
|
|
4285
|
+
"add",
|
|
4286
|
+
"--type",
|
|
4287
|
+
"http",
|
|
4288
|
+
name,
|
|
4289
|
+
url
|
|
4290
|
+
]));
|
|
4291
|
+
if (Result.isSuccess(attempt)) return attempt.success;
|
|
4292
|
+
if (attempt.failure.commandPhase === "not-started") return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
4293
|
+
const liveAfterAttempt = yield* Effect.result(readAntigravityLiveMcpServers(kernel, "mcp-add", attempt.failure.commandPhase));
|
|
4294
|
+
if (Result.isSuccess(liveAfterAttempt)) {
|
|
4295
|
+
const liveAfter = liveAfterAttempt.success.find((entry) => entry.name === name);
|
|
4296
|
+
if (liveAfter === void 0 || liveAfter.transport !== "http" || liveAfter.url !== url) return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
4297
|
+
}
|
|
4298
|
+
return yield* Effect.fail(attempt.failure);
|
|
4299
|
+
}))));
|
|
4300
|
+
}
|
|
4301
|
+
/**
|
|
4302
|
+
* Executes a serialized Antigravity user-scope MCP removal guarded by exact ledger URL ownership
|
|
4303
|
+
* and prunes orphan ledger records without invoking `agy mcp remove` when already absent.
|
|
4304
|
+
*/
|
|
4305
|
+
function removeAntigravityMcpServer(kernel, request) {
|
|
4306
|
+
return kernel.serialized("mcp-remove", requireMcpServerRemoveInput("antigravity", "mcp-remove", request).pipe(Effect.flatMap((name) => Effect.gen(function* () {
|
|
4307
|
+
yield* sweepAntigravityTransientArtifacts(kernel, "mcp-remove");
|
|
4308
|
+
const currentLedger = yield* kernel.readManagedMcpLedger("mcp-remove");
|
|
4309
|
+
const liveBefore = yield* readAntigravityLiveMcpServers(kernel, "mcp-remove", "not-started");
|
|
4310
|
+
const ledgerEntry = currentLedger.find((entry) => entry.name === name);
|
|
4311
|
+
const liveEntry = liveBefore.find((entry) => entry.name === name);
|
|
4312
|
+
if (liveEntry === void 0) {
|
|
4313
|
+
if (ledgerEntry !== void 0) yield* kernel.writeManagedMcpLedger("mcp-remove", currentLedger.filter((entry) => entry.name !== name), "not-started");
|
|
4314
|
+
return Object.freeze({
|
|
4315
|
+
provider: "antigravity",
|
|
4316
|
+
operation: "mcp-remove",
|
|
4317
|
+
commandPhase: "command-returned"
|
|
4318
|
+
});
|
|
4319
|
+
}
|
|
4320
|
+
if (ledgerEntry === void 0 || liveEntry.transport !== "http" || liveEntry.url !== ledgerEntry.url) return yield* Effect.fail(antigravityMcpFailure("mcp-remove", "InvalidInput", "not-started", `Refusing to remove unmanaged MCP server ${name}`));
|
|
4321
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-remove", [
|
|
4322
|
+
"mcp",
|
|
4323
|
+
"remove",
|
|
4324
|
+
name
|
|
4325
|
+
]));
|
|
4326
|
+
if (Result.isSuccess(attempt)) {
|
|
4327
|
+
yield* pruneManagedMcpLedgerEntry$2(kernel, name, "command-returned");
|
|
4328
|
+
return attempt.success;
|
|
4329
|
+
}
|
|
4330
|
+
if (attempt.failure.commandPhase !== "command-returned") return yield* Effect.fail(attempt.failure);
|
|
4331
|
+
const liveAfterAttempt = yield* Effect.result(readAntigravityLiveMcpServers(kernel, "mcp-remove", "command-returned"));
|
|
4332
|
+
if (Result.isSuccess(liveAfterAttempt) && !liveAfterAttempt.success.some((entry) => entry.name === name)) {
|
|
4333
|
+
yield* pruneManagedMcpLedgerEntry$2(kernel, name, "command-returned");
|
|
4334
|
+
return Object.freeze({
|
|
4335
|
+
provider: "antigravity",
|
|
4336
|
+
operation: "mcp-remove",
|
|
4337
|
+
commandPhase: "command-returned"
|
|
4338
|
+
});
|
|
4339
|
+
}
|
|
4340
|
+
return yield* Effect.fail(attempt.failure);
|
|
4341
|
+
}))));
|
|
4342
|
+
}
|
|
4343
|
+
function decodeAntigravityMcpServers(operation, commandPhase, mcpConfig) {
|
|
4344
|
+
if (mcpConfig === null) return Effect.succeed(Object.freeze([]));
|
|
4345
|
+
if (!isPlainRecord$2(mcpConfig)) return Effect.fail(antigravityMcpFailure(operation, "ProtocolFailed", commandPhase, "Antigravity mcp_config.json top-level value must be a JSON object"));
|
|
4346
|
+
const rawServers = Reflect.get(mcpConfig, "mcpServers");
|
|
4347
|
+
if (rawServers === void 0 || rawServers === null) return Effect.succeed(Object.freeze([]));
|
|
4348
|
+
if (!isPlainRecord$2(rawServers)) return Effect.fail(antigravityMcpFailure(operation, "ProtocolFailed", commandPhase, "Antigravity mcp_config.json mcpServers must be a JSON object"));
|
|
4349
|
+
const entries = Object.entries(rawServers).filter(([name]) => name !== "__proto__" && Value.Check(ObservedMcpServerNameSchema, name));
|
|
4350
|
+
if (entries.length > 1024) return Effect.fail(antigravityMcpFailure(operation, "LimitExceeded", commandPhase, "Antigravity mcp_config.json MCP server count exceeds the resource limit"));
|
|
4351
|
+
return Effect.succeed(Object.freeze(entries.map(([name, entry]) => normalizeAntigravityMcpServer(name, entry))));
|
|
4352
|
+
}
|
|
4353
|
+
const ALLOWED_HTTP_ENTRY_KEYS = /* @__PURE__ */ new Set([
|
|
4354
|
+
"serverUrl",
|
|
4355
|
+
"url",
|
|
4356
|
+
"disabled",
|
|
4357
|
+
"type"
|
|
4358
|
+
]);
|
|
4359
|
+
function normalizeAntigravityMcpServer(name, entry) {
|
|
4360
|
+
if (!isPlainRecord$2(entry)) return Object.freeze({
|
|
4361
|
+
name,
|
|
4362
|
+
transport: "other",
|
|
4363
|
+
url: null,
|
|
4364
|
+
enabled: null
|
|
4365
|
+
});
|
|
4366
|
+
const rawDisabled = Reflect.get(entry, "disabled");
|
|
4367
|
+
if (rawDisabled !== void 0 && typeof rawDisabled !== "boolean") return Object.freeze({
|
|
4368
|
+
name,
|
|
4369
|
+
transport: "other",
|
|
4370
|
+
url: null,
|
|
4371
|
+
enabled: null
|
|
4372
|
+
});
|
|
4373
|
+
const enabled = typeof rawDisabled === "boolean" ? !rawDisabled : true;
|
|
4374
|
+
const rawType = Reflect.get(entry, "type");
|
|
4375
|
+
const hasCustomConfig = Object.keys(entry).some((key) => !ALLOWED_HTTP_ENTRY_KEYS.has(key)) || rawType !== void 0 && rawType !== "http";
|
|
4376
|
+
const rawServerUrl = Reflect.get(entry, "serverUrl");
|
|
4377
|
+
const rawUrl = Reflect.get(entry, "url");
|
|
4378
|
+
let validUrl = null;
|
|
4379
|
+
if ((rawServerUrl === void 0 || typeof rawServerUrl === "string") && (rawUrl === void 0 || typeof rawUrl === "string") && !(rawServerUrl !== void 0 && rawUrl !== void 0 && rawServerUrl !== rawUrl)) {
|
|
4380
|
+
const candidate = rawServerUrl !== void 0 ? rawServerUrl : rawUrl;
|
|
4381
|
+
if (typeof candidate === "string" && candidate.length > 0 && candidate.length <= MAX_OBSERVED_URL_LENGTH$2) validUrl = candidate;
|
|
4382
|
+
}
|
|
4383
|
+
if (!hasCustomConfig && validUrl !== null) return Object.freeze({
|
|
4384
|
+
name,
|
|
4385
|
+
transport: "http",
|
|
4386
|
+
url: validUrl,
|
|
4387
|
+
enabled
|
|
4388
|
+
});
|
|
4389
|
+
return Object.freeze({
|
|
4390
|
+
name,
|
|
4391
|
+
transport: "other",
|
|
4392
|
+
url: null,
|
|
4393
|
+
enabled
|
|
4394
|
+
});
|
|
4395
|
+
}
|
|
4396
|
+
function pruneManagedMcpLedgerEntry$2(kernel, name, commandPhase) {
|
|
4397
|
+
return kernel.readManagedMcpLedger("mcp-remove").pipe(Effect.mapError((error) => error.commandPhase === commandPhase ? error : Object.freeze({
|
|
4398
|
+
...error,
|
|
4399
|
+
commandPhase
|
|
4400
|
+
})), Effect.flatMap((current) => {
|
|
4401
|
+
const next = current.filter((entry) => entry.name !== name);
|
|
4402
|
+
return next.length === current.length ? Effect.void : kernel.writeManagedMcpLedger("mcp-remove", next, commandPhase);
|
|
4403
|
+
}));
|
|
4404
|
+
}
|
|
4405
|
+
function isPlainRecord$2(value) {
|
|
4406
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4407
|
+
}
|
|
4408
|
+
function antigravityMcpFailure(operation, reason, commandPhase, detail) {
|
|
4409
|
+
return Object.freeze({
|
|
4410
|
+
_tag: "NativeAgentProviderFailure",
|
|
4411
|
+
provider: "antigravity",
|
|
4412
|
+
operation,
|
|
4413
|
+
reason,
|
|
4414
|
+
commandPhase,
|
|
4415
|
+
detail
|
|
4416
|
+
});
|
|
4417
|
+
}
|
|
4418
|
+
//#endregion
|
|
4419
|
+
//#region ../../resources/native-agent-provider/dist/providers/antigravity-effect-platform-node/index.js
|
|
4420
|
+
const utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
4421
|
+
const utf8Encoder = new TextEncoder();
|
|
4422
|
+
const MAX_MARKETPLACE_MANIFEST_BYTES = 2097152;
|
|
4423
|
+
const NullableStringSchema$2 = Type.Union([Type.String(), Type.Null()]);
|
|
4424
|
+
const ObservedPluginNameSchema = Type.String({
|
|
4425
|
+
pattern: "^[^\\u0000-\\u001f\\u007f@/\\\\]{1,256}$",
|
|
4426
|
+
minLength: 1,
|
|
4427
|
+
maxLength: 256
|
|
4428
|
+
});
|
|
4429
|
+
const MarketplaceNameSchema = Type.String({
|
|
4430
|
+
pattern: "^[a-z0-9][a-z0-9_-]*$",
|
|
4431
|
+
maxLength: 128
|
|
4432
|
+
});
|
|
4433
|
+
const AntigravityPluginListSchema = Type.Array(Type.Object({
|
|
4434
|
+
name: Type.String(),
|
|
4435
|
+
enabled: Type.Optional(Type.Union([Type.Boolean(), Type.Null()])),
|
|
4436
|
+
version: Type.Optional(NullableStringSchema$2),
|
|
4437
|
+
source: Type.Optional(NullableStringSchema$2),
|
|
4438
|
+
path: Type.Optional(NullableStringSchema$2)
|
|
4439
|
+
}, { additionalProperties: true }), { maxItems: 4096 });
|
|
4440
|
+
const StagedMarketplaceRecordSchema = Type.Object({
|
|
4441
|
+
identity: MarketplaceNameSchema,
|
|
4442
|
+
source: Type.Union([
|
|
4443
|
+
Type.Object({
|
|
4444
|
+
kind: Type.Literal("git"),
|
|
4445
|
+
repositoryUrl: CanonicalGitRepositoryUrlSchema,
|
|
4446
|
+
revision: Type.Union([Type.String({
|
|
4447
|
+
pattern: "^[^\\s#]+$",
|
|
4448
|
+
minLength: 1,
|
|
4449
|
+
maxLength: 256
|
|
4450
|
+
}), Type.Null()])
|
|
4451
|
+
}, { additionalProperties: false }),
|
|
4452
|
+
Type.Object({
|
|
4453
|
+
kind: Type.Literal("local"),
|
|
4454
|
+
root: Type.String({
|
|
4455
|
+
minLength: 1,
|
|
4456
|
+
maxLength: 16384
|
|
4457
|
+
})
|
|
4458
|
+
}, { additionalProperties: false }),
|
|
4459
|
+
Type.Null()
|
|
4460
|
+
]),
|
|
4461
|
+
plugins: Type.Array(CanonicalPluginNameSchema, { maxItems: 4096 })
|
|
4462
|
+
}, { additionalProperties: false });
|
|
4463
|
+
const ClaudeSourceMarketplaceSchema = Type.Object({
|
|
4464
|
+
name: MarketplaceNameSchema,
|
|
4465
|
+
plugins: Type.Array(Type.Object({
|
|
4466
|
+
name: CanonicalPluginNameSchema,
|
|
4467
|
+
source: Type.String({
|
|
4468
|
+
minLength: 1,
|
|
4469
|
+
maxLength: 1024
|
|
4470
|
+
})
|
|
4471
|
+
}, { additionalProperties: true }), {
|
|
4472
|
+
minItems: 1,
|
|
4473
|
+
maxItems: 4096
|
|
4474
|
+
})
|
|
4475
|
+
}, { additionalProperties: true });
|
|
4476
|
+
const CodexSourceMarketplaceSchema = Type.Object({
|
|
4477
|
+
name: MarketplaceNameSchema,
|
|
4478
|
+
plugins: Type.Array(Type.Object({
|
|
4479
|
+
name: CanonicalPluginNameSchema,
|
|
4480
|
+
source: Type.Object({
|
|
4481
|
+
source: Type.Literal("local"),
|
|
4482
|
+
path: Type.String({
|
|
4483
|
+
minLength: 1,
|
|
4484
|
+
maxLength: 1024
|
|
4485
|
+
})
|
|
4486
|
+
}, { additionalProperties: true })
|
|
4487
|
+
}, { additionalProperties: true }), {
|
|
4488
|
+
minItems: 1,
|
|
4489
|
+
maxItems: 4096
|
|
4490
|
+
})
|
|
4491
|
+
}, { additionalProperties: true });
|
|
4492
|
+
const ANTIGRAVITY_CAPABILITIES = [
|
|
4493
|
+
"marketplace-list",
|
|
4494
|
+
"marketplace-add",
|
|
4495
|
+
"marketplace-remove",
|
|
4496
|
+
"plugin-list",
|
|
4497
|
+
"plugin-install",
|
|
4498
|
+
"plugin-enable",
|
|
4499
|
+
"plugin-disable",
|
|
4500
|
+
"plugin-remove",
|
|
4501
|
+
"mcp-add",
|
|
4502
|
+
"mcp-remove"
|
|
4503
|
+
];
|
|
4504
|
+
/**
|
|
4505
|
+
* Constructs the platform-requiring Antigravity provider without choosing a runtime.
|
|
4506
|
+
*/
|
|
4507
|
+
function makeAntigravityEffectPlatformNodeProvider(options = {}) {
|
|
4508
|
+
const command = options.command ?? "agy";
|
|
4509
|
+
const gitCommand = options.gitCommand ?? "git";
|
|
4510
|
+
return Object.freeze({ acquire: (input) => acquireEffectPlatformNodeProvider("antigravity", command, input).pipe(Effect.map((kernel) => {
|
|
4511
|
+
const probe = () => kernel.serialized("probe", Effect.gen(function* () {
|
|
4512
|
+
const version = yield* kernel.run("probe", ["--version"]);
|
|
4513
|
+
return Object.freeze({
|
|
4514
|
+
provider: "antigravity",
|
|
4515
|
+
home: kernel.home,
|
|
4516
|
+
version: yield* requireVersion$2(version.stdout),
|
|
4517
|
+
capabilities: [...ANTIGRAVITY_CAPABILITIES]
|
|
4518
|
+
});
|
|
4519
|
+
}));
|
|
4520
|
+
const inventory = (inventoryOptions) => kernel.serialized("inventory", requireInventoryOptions("antigravity", inventoryOptions).pipe(Effect.flatMap((validated) => antigravityInventory(kernel, validated))));
|
|
4521
|
+
return Object.freeze({
|
|
4522
|
+
provider: "antigravity",
|
|
4523
|
+
home: kernel.home,
|
|
4524
|
+
probe,
|
|
4525
|
+
inventory,
|
|
4526
|
+
readPluginFiles: (request) => kernel.serialized("plugin-files-read", requirePluginFilesReadInput("antigravity", "plugin-files-read", request).pipe(Effect.flatMap((validated) => antigravityInstalledPlugins(kernel).pipe(Effect.flatMap((livePlugins) => selectPluginRoot$2(livePlugins, validated.selector).pipe(Effect.flatMap((root) => Effect.forEach(validated.files, (file) => kernel.readPluginEntry("plugin-files-read", root, file).pipe(Effect.catchIf((error) => error.reason === "Missing" || error.reason === "LimitExceeded", (error) => {
|
|
4527
|
+
const missing = Object.freeze({
|
|
4528
|
+
kind: error.reason === "Missing" ? "Missing" : "TooLarge",
|
|
4529
|
+
relativePath: file.relativePath
|
|
4530
|
+
});
|
|
4531
|
+
return Effect.succeed(missing);
|
|
4532
|
+
})), { concurrency: 1 }).pipe(Effect.map((files) => {
|
|
4533
|
+
return Object.freeze({
|
|
4534
|
+
selector: validated.selector,
|
|
4535
|
+
files: Object.freeze(files)
|
|
4536
|
+
});
|
|
4537
|
+
}))))))))),
|
|
4538
|
+
addMarketplace: (source) => kernel.serialized("marketplace-add", requireMarketplaceSource("antigravity", "marketplace-add", source).pipe(Effect.flatMap((validated) => sweepAntigravityTransientArtifacts(kernel, "marketplace-add").pipe(Effect.andThen(stageAntigravityMarketplace(kernel, gitCommand, validated)))))),
|
|
4539
|
+
removeMarketplace: (request) => kernel.serialized("marketplace-remove", requireMarketplaceIdentityInput("antigravity", "marketplace-remove", request).pipe(Effect.flatMap((identity) => sweepAntigravityTransientArtifacts(kernel, "marketplace-remove").pipe(Effect.andThen(removeStagedMarketplace(kernel, identity)))))),
|
|
4540
|
+
installPlugin: (request) => kernel.serialized("plugin-install", requirePluginSelectorInput("antigravity", "plugin-install", request).pipe(Effect.flatMap((selector) => sweepAntigravityTransientArtifacts(kernel, "plugin-install").pipe(Effect.andThen(installStagedPlugin(kernel, selector)))))),
|
|
4541
|
+
enablePlugin: (request) => kernel.serialized("plugin-enable", requirePluginSelectorInput("antigravity", "plugin-enable", request).pipe(Effect.flatMap((selector) => {
|
|
4542
|
+
const parsed = splitSelector(selector, "plugin-enable");
|
|
4543
|
+
return parsed === null ? Effect.fail(providerFailure$2("plugin-enable", "InvalidInput", "not-started", "Plugin selector is not canonical")) : sweepAntigravityTransientArtifacts(kernel, "plugin-enable").pipe(Effect.andThen(kernel.mutation("plugin-enable", [
|
|
4544
|
+
"plugin",
|
|
4545
|
+
"enable",
|
|
4546
|
+
parsed.name
|
|
4547
|
+
])));
|
|
4548
|
+
}))),
|
|
4549
|
+
removePlugin: (request) => kernel.serialized("plugin-remove", requirePluginSelectorInput("antigravity", "plugin-remove", request).pipe(Effect.flatMap((selector) => sweepAntigravityTransientArtifacts(kernel, "plugin-remove").pipe(Effect.andThen(removeInstalledPlugin(kernel, selector)))))),
|
|
4550
|
+
addMcpServer: (request) => addAntigravityMcpServer(kernel, request),
|
|
4551
|
+
removeMcpServer: (request) => removeAntigravityMcpServer(kernel, request)
|
|
4552
|
+
});
|
|
4553
|
+
})) });
|
|
4554
|
+
}
|
|
4555
|
+
/**
|
|
4556
|
+
* Constructs a ready Antigravity resource whose Node platform is supplied only while
|
|
4557
|
+
* acquiring a session.
|
|
4558
|
+
*/
|
|
4559
|
+
function makeNodeAntigravityNativeAgentProviderResource(options = {}) {
|
|
4560
|
+
const provider = makeAntigravityEffectPlatformNodeProvider(options);
|
|
4561
|
+
return Object.freeze({ acquire: (input) => provider.acquire(input).pipe(Effect.provide(NodeServices.layer)) });
|
|
4562
|
+
}
|
|
4563
|
+
function antigravityInstalledPlugins(kernel) {
|
|
4564
|
+
return Effect.gen(function* () {
|
|
4565
|
+
const pluginOutput = yield* kernel.run("inventory", [
|
|
4566
|
+
"plugin",
|
|
4567
|
+
"list",
|
|
4568
|
+
"--json"
|
|
4569
|
+
]);
|
|
4570
|
+
const pluginRecord = yield* decodeProviderJson("antigravity", "inventory", AntigravityPluginListSchema, pluginOutput.stdout);
|
|
4571
|
+
const stagedMarketplaces = yield* readStagedMarketplaces(kernel);
|
|
4572
|
+
const pluginLedger = yield* readPluginLedger(kernel, "inventory", "command-returned");
|
|
4573
|
+
const ledgerByName = new Map(pluginLedger.map((entry) => [entry.name, entry]));
|
|
4574
|
+
const marketplaces = stagedMarketplaces.map((entry) => Object.freeze({
|
|
4575
|
+
identity: entry.identity,
|
|
4576
|
+
source: entry.source,
|
|
4577
|
+
installedRoot: entry.installedRoot
|
|
4578
|
+
}));
|
|
4579
|
+
const plugins = yield* Effect.forEach(pluginRecord, (entry) => normalizePlugin$2(kernel, ledgerByName, entry), { concurrency: 1 });
|
|
4580
|
+
yield* requireUniqueInventory$2(marketplaces, plugins, []);
|
|
4581
|
+
return Object.freeze([...plugins].sort(bySelector$2));
|
|
4582
|
+
});
|
|
4583
|
+
}
|
|
4584
|
+
function antigravityInventory(kernel, options) {
|
|
4585
|
+
return Effect.gen(function* () {
|
|
4586
|
+
const pluginOutput = yield* kernel.run("inventory", [
|
|
4587
|
+
"plugin",
|
|
4588
|
+
"list",
|
|
4589
|
+
"--json"
|
|
4590
|
+
]);
|
|
4591
|
+
const pluginRecord = yield* decodeProviderJson("antigravity", "inventory", AntigravityPluginListSchema, pluginOutput.stdout);
|
|
4592
|
+
const stagedMarketplaces = yield* readStagedMarketplaces(kernel);
|
|
4593
|
+
const pluginLedger = yield* readPluginLedger(kernel, "inventory", "command-returned");
|
|
4594
|
+
const managedMcpServers = yield* kernel.readManagedMcpLedger("inventory");
|
|
4595
|
+
const mcpServers = shouldObserveProviderMcpConfig(options, managedMcpServers) ? yield* readAntigravityLiveMcpServers(kernel, "inventory", "not-started") : Object.freeze([]);
|
|
4596
|
+
const ledgerByName = new Map(pluginLedger.map((entry) => [entry.name, entry]));
|
|
4597
|
+
const marketplaces = stagedMarketplaces.map((entry) => Object.freeze({
|
|
4598
|
+
identity: entry.identity,
|
|
4599
|
+
source: entry.source,
|
|
4600
|
+
installedRoot: entry.installedRoot
|
|
4601
|
+
}));
|
|
4602
|
+
const plugins = yield* Effect.forEach(pluginRecord, (entry) => normalizePlugin$2(kernel, ledgerByName, entry), { concurrency: 1 });
|
|
4603
|
+
yield* requireUniqueInventory$2(marketplaces, plugins, mcpServers);
|
|
4604
|
+
const normalized = Object.freeze({
|
|
4605
|
+
provider: "antigravity",
|
|
4606
|
+
marketplaces: [...marketplaces].sort(byIdentity$2),
|
|
4607
|
+
plugins: [...plugins].sort(bySelector$2),
|
|
4608
|
+
mcpServers: [...mcpServers].sort(byMcpName$2),
|
|
4609
|
+
managedMcpServers
|
|
4610
|
+
});
|
|
4611
|
+
return Value.Check(NativeProviderInventorySchema, normalized) ? normalized : yield* Effect.fail(providerFailure$2("inventory", "ProtocolFailed", "command-returned", "Antigravity native inventory contains non-canonical facts"));
|
|
4612
|
+
});
|
|
4613
|
+
}
|
|
4614
|
+
function readStagedMarketplaces(kernel) {
|
|
4615
|
+
return Effect.gen(function* () {
|
|
4616
|
+
const marketplacesDir = kernel.paths.join(kernel.geminiRoot, "config", "marketplaces");
|
|
4617
|
+
if (!(yield* kernel.fs.exists(marketplacesDir).pipe(mapFs("inventory", marketplacesDir, "command-returned")))) return Object.freeze([]);
|
|
4618
|
+
const verifiedMarketplacesDir = yield* kernel.requireLocalDirectory("inventory", marketplacesDir);
|
|
4619
|
+
if (!isContained(kernel.paths, kernel.home, verifiedMarketplacesDir)) return yield* Effect.fail(providerFailure$2("inventory", "Aliased", "command-returned", "Antigravity marketplaces directory escaped the explicit provider home", verifiedMarketplacesDir));
|
|
4620
|
+
const childNames = yield* kernel.fs.readDirectory(verifiedMarketplacesDir).pipe(mapFs("inventory", verifiedMarketplacesDir, "command-returned"));
|
|
4621
|
+
const records = [];
|
|
4622
|
+
for (const childName of [...childNames].sort(compareText$5)) {
|
|
4623
|
+
if (childName.startsWith(".")) continue;
|
|
4624
|
+
const entryDir = kernel.paths.join(verifiedMarketplacesDir, childName);
|
|
4625
|
+
const entryRoot = yield* kernel.requireLocalDirectory("inventory", entryDir);
|
|
4626
|
+
const manifestPath = kernel.paths.join(entryRoot, "marketplace.json");
|
|
4627
|
+
const rawText = yield* readBoundedRegularUtf8File(kernel, "inventory", entryRoot, manifestPath, MAX_MARKETPLACE_MANIFEST_BYTES, "command-returned");
|
|
4628
|
+
const decoded = yield* decodeProviderJson("antigravity", "inventory", StagedMarketplaceRecordSchema, rawText);
|
|
4629
|
+
if (decoded.identity !== childName) return yield* Effect.fail(providerFailure$2("inventory", "ProtocolFailed", "command-returned", `Staged marketplace identity ${decoded.identity} does not match directory ${childName}`, manifestPath));
|
|
4630
|
+
if (new Set(decoded.plugins).size !== decoded.plugins.length) return yield* Effect.fail(providerFailure$2("inventory", "ProtocolFailed", "command-returned", `Staged marketplace ${decoded.identity} contains duplicate plugin names`, manifestPath));
|
|
4631
|
+
records.push(Object.freeze({
|
|
4632
|
+
identity: decoded.identity,
|
|
4633
|
+
source: decoded.source === null ? null : decoded.source.kind === "git" ? Object.freeze({
|
|
4634
|
+
kind: "git",
|
|
4635
|
+
repositoryUrl: decoded.source.repositoryUrl,
|
|
4636
|
+
revision: decoded.source.revision
|
|
4637
|
+
}) : Object.freeze({
|
|
4638
|
+
kind: "local",
|
|
4639
|
+
root: decoded.source.root
|
|
4640
|
+
}),
|
|
4641
|
+
plugins: Object.freeze([...decoded.plugins]),
|
|
4642
|
+
installedRoot: entryRoot
|
|
4643
|
+
}));
|
|
4644
|
+
}
|
|
4645
|
+
return Object.freeze(records);
|
|
4646
|
+
});
|
|
4647
|
+
}
|
|
4648
|
+
function normalizePlugin$2(kernel, pluginLedgerByName, entry) {
|
|
4649
|
+
return Effect.gen(function* () {
|
|
4650
|
+
if (!Value.Check(ObservedPluginNameSchema, entry.name) || entry.name === "." || entry.name === "..") return yield* Effect.fail(providerFailure$2("inventory", "ProtocolFailed", "command-returned", "Antigravity plugin name is not canonical"));
|
|
4651
|
+
const isCanonicalLowercaseName = Value.Check(CanonicalPluginNameSchema, entry.name);
|
|
4652
|
+
const source = entry.source ?? null;
|
|
4653
|
+
let marketplaceIdentity;
|
|
4654
|
+
if (source === "claude-code" || source === "gemini-cli") marketplaceIdentity = `imported-${source}`;
|
|
4655
|
+
else if (source === "antigravity") {
|
|
4656
|
+
if (!isCanonicalLowercaseName) marketplaceIdentity = "antigravity-marketplace";
|
|
4657
|
+
else {
|
|
4658
|
+
const ledgerEntry = pluginLedgerByName.get(entry.name);
|
|
4659
|
+
if (ledgerEntry === void 0) marketplaceIdentity = "antigravity-marketplace";
|
|
4660
|
+
else marketplaceIdentity = isLedgerAcceptedDigest(ledgerEntry, yield* readLedgerKnownPluginTreeSha256(kernel, "inventory", entry.path ?? null, "command-returned")) ? ledgerEntry.marketplaceIdentity : "antigravity-marketplace";
|
|
4661
|
+
}
|
|
4662
|
+
} else if (source === null || source === "") marketplaceIdentity = "unmanaged-local";
|
|
4663
|
+
else return yield* Effect.fail(providerFailure$2("inventory", "ProtocolFailed", "command-returned", "Antigravity plugin source kind is unsupported"));
|
|
4664
|
+
const rawVersion = entry.version ?? null;
|
|
4665
|
+
const version = rawVersion !== null && Value.Check(PluginVersionSchema, rawVersion) ? rawVersion : null;
|
|
4666
|
+
const selector = `${entry.name}@${marketplaceIdentity}`;
|
|
4667
|
+
return Object.freeze({
|
|
4668
|
+
selector,
|
|
4669
|
+
marketplaceIdentity,
|
|
4670
|
+
name: entry.name,
|
|
4671
|
+
installed: true,
|
|
4672
|
+
enabled: entry.enabled ?? null,
|
|
4673
|
+
version,
|
|
4674
|
+
root: entry.path ?? null
|
|
4675
|
+
});
|
|
4676
|
+
});
|
|
4677
|
+
}
|
|
4678
|
+
function readLivePluginListPreflight(kernel, operation) {
|
|
4679
|
+
return kernel.run(operation, [
|
|
4680
|
+
"plugin",
|
|
4681
|
+
"list",
|
|
4682
|
+
"--json"
|
|
4683
|
+
]).pipe(Effect.flatMap((output) => decodeProviderJson("antigravity", operation, AntigravityPluginListSchema, output.stdout)), Effect.mapError((error) => ({
|
|
4684
|
+
...error,
|
|
4685
|
+
commandPhase: "not-started"
|
|
4686
|
+
})));
|
|
4687
|
+
}
|
|
4688
|
+
function readLivePluginNamesBestEffort(kernel, operation) {
|
|
4689
|
+
return kernel.run(operation, [
|
|
4690
|
+
"plugin",
|
|
4691
|
+
"list",
|
|
4692
|
+
"--json"
|
|
4693
|
+
]).pipe(Effect.flatMap((output) => decodeProviderJson("antigravity", operation, AntigravityPluginListSchema, output.stdout)), Effect.map((list) => new Set(list.map((entry) => entry.name))), Effect.catch(() => Effect.succeed(null)));
|
|
4694
|
+
}
|
|
4695
|
+
function readInstalledPluginDirectoryNames(kernel, operation) {
|
|
4696
|
+
return Effect.gen(function* () {
|
|
4697
|
+
const pluginsDir = kernel.paths.join(kernel.geminiRoot, "config", "plugins");
|
|
4698
|
+
if (!(yield* kernel.fs.exists(pluginsDir).pipe(mapFs(operation, pluginsDir, "not-started")))) return Object.freeze([]);
|
|
4699
|
+
const verifiedDir = yield* kernel.requireLocalDirectory(operation, pluginsDir).pipe(Effect.mapError((error) => ({
|
|
4700
|
+
...error,
|
|
4701
|
+
commandPhase: "not-started"
|
|
4702
|
+
})));
|
|
4703
|
+
if (!isContained(kernel.paths, kernel.home, verifiedDir)) return yield* Effect.fail(providerFailure$2(operation, "Aliased", "not-started", "Antigravity plugins directory escaped the explicit provider home", verifiedDir));
|
|
4704
|
+
const names = yield* kernel.fs.readDirectory(verifiedDir).pipe(mapFs(operation, verifiedDir, "not-started"));
|
|
4705
|
+
return Object.freeze(names.filter((name) => !name.startsWith(".")));
|
|
4706
|
+
});
|
|
4707
|
+
}
|
|
4708
|
+
function verifyInstallSlotOwnership(kernel, parsed) {
|
|
4709
|
+
return Effect.gen(function* () {
|
|
4710
|
+
const liveList = yield* readLivePluginListPreflight(kernel, "plugin-install");
|
|
4711
|
+
const existingLedger = yield* readPluginLedger(kernel, "plugin-install", "not-started");
|
|
4712
|
+
const ledgerEntry = existingLedger.find((entry) => entry.name === parsed.name);
|
|
4713
|
+
const targetLower = parsed.name.toLowerCase();
|
|
4714
|
+
const listMatches = liveList.filter((entry) => entry.name.toLowerCase() === targetLower);
|
|
4715
|
+
let previousOwnedTreeSha256 = null;
|
|
4716
|
+
for (const match of listMatches) {
|
|
4717
|
+
if (match.name !== parsed.name || (match.source ?? null) !== "antigravity" || ledgerEntry === void 0 || ledgerEntry.marketplaceIdentity !== parsed.marketplaceIdentity) return yield* Effect.fail(providerFailure$2("plugin-install", "InvalidInput", "not-started", "Refusing to overwrite unmanaged Antigravity plugin", match.path ?? void 0));
|
|
4718
|
+
const liveTreeSha256 = yield* readLedgerKnownPluginTreeSha256(kernel, "plugin-install", match.path ?? null, "not-started");
|
|
4719
|
+
if (!isLedgerAcceptedDigest(ledgerEntry, liveTreeSha256)) return yield* Effect.fail(providerFailure$2("plugin-install", "InvalidInput", "not-started", "Refusing to overwrite unmanaged Antigravity plugin", match.path ?? void 0));
|
|
4720
|
+
previousOwnedTreeSha256 = liveTreeSha256;
|
|
4721
|
+
}
|
|
4722
|
+
if (listMatches.length === 0) {
|
|
4723
|
+
const collidingDirs = (yield* readInstalledPluginDirectoryNames(kernel, "plugin-install")).filter((name) => name.toLowerCase() === targetLower);
|
|
4724
|
+
for (const dirName of collidingDirs) {
|
|
4725
|
+
const dirPath = kernel.paths.join(kernel.geminiRoot, "config", "plugins", dirName);
|
|
4726
|
+
if (dirName !== parsed.name || ledgerEntry === void 0 || ledgerEntry.marketplaceIdentity !== parsed.marketplaceIdentity) return yield* Effect.fail(providerFailure$2("plugin-install", "InvalidInput", "not-started", "Refusing to overwrite unmanaged Antigravity plugin", dirPath));
|
|
4727
|
+
const dirTreeSha256 = yield* readLedgerKnownPluginTreeSha256(kernel, "plugin-install", dirPath, "not-started");
|
|
4728
|
+
if (!isLedgerAcceptedDigest(ledgerEntry, dirTreeSha256)) return yield* Effect.fail(providerFailure$2("plugin-install", "InvalidInput", "not-started", "Refusing to overwrite unmanaged Antigravity plugin", dirPath));
|
|
4729
|
+
previousOwnedTreeSha256 = dirTreeSha256;
|
|
4730
|
+
}
|
|
4731
|
+
}
|
|
4732
|
+
return Object.freeze({
|
|
4733
|
+
existingLedger,
|
|
4734
|
+
previousOwnedTreeSha256
|
|
4735
|
+
});
|
|
4736
|
+
});
|
|
4737
|
+
}
|
|
4738
|
+
function verifyRemoveSlotOwnership(kernel, parsed) {
|
|
4739
|
+
return Effect.gen(function* () {
|
|
4740
|
+
const liveList = yield* readLivePluginListPreflight(kernel, "plugin-remove");
|
|
4741
|
+
const ledgerEntry = (yield* readPluginLedger(kernel, "plugin-remove", "not-started")).find((entry) => entry.name === parsed.name);
|
|
4742
|
+
const targetLower = parsed.name.toLowerCase();
|
|
4743
|
+
const listMatches = liveList.filter((entry) => entry.name.toLowerCase() === targetLower);
|
|
4744
|
+
for (const match of listMatches) {
|
|
4745
|
+
if (match.name !== parsed.name || (match.source ?? null) !== "antigravity" || ledgerEntry === void 0 || ledgerEntry.marketplaceIdentity !== parsed.marketplaceIdentity) return yield* Effect.fail(providerFailure$2("plugin-remove", "InvalidInput", "not-started", "Refusing to uninstall unmanaged Antigravity plugin", match.path ?? void 0));
|
|
4746
|
+
if (!isLedgerAcceptedDigest(ledgerEntry, yield* readLedgerKnownPluginTreeSha256(kernel, "plugin-remove", match.path ?? null, "not-started"))) return yield* Effect.fail(providerFailure$2("plugin-remove", "InvalidInput", "not-started", "Refusing to uninstall unmanaged Antigravity plugin", match.path ?? void 0));
|
|
4747
|
+
}
|
|
4748
|
+
if (listMatches.length === 0) {
|
|
4749
|
+
const collidingDirs = (yield* readInstalledPluginDirectoryNames(kernel, "plugin-remove")).filter((name) => name.toLowerCase() === targetLower);
|
|
4750
|
+
for (const dirName of collidingDirs) {
|
|
4751
|
+
const dirPath = kernel.paths.join(kernel.geminiRoot, "config", "plugins", dirName);
|
|
4752
|
+
if (dirName !== parsed.name || ledgerEntry === void 0 || ledgerEntry.marketplaceIdentity !== parsed.marketplaceIdentity) return yield* Effect.fail(providerFailure$2("plugin-remove", "InvalidInput", "not-started", "Refusing to uninstall unmanaged Antigravity plugin", dirPath));
|
|
4753
|
+
if (!isLedgerAcceptedDigest(ledgerEntry, yield* readLedgerKnownPluginTreeSha256(kernel, "plugin-remove", dirPath, "not-started"))) return yield* Effect.fail(providerFailure$2("plugin-remove", "InvalidInput", "not-started", "Refusing to uninstall unmanaged Antigravity plugin", dirPath));
|
|
4754
|
+
}
|
|
4755
|
+
}
|
|
4756
|
+
});
|
|
4757
|
+
}
|
|
4758
|
+
function stageAntigravityMarketplace(kernel, gitCommand, source) {
|
|
4759
|
+
if (source.kind === "local") return kernel.requireLocalDirectory("marketplace-add", source.root).pipe(Effect.flatMap((localRoot) => stageFromResolvedSourceRoot(kernel, {
|
|
4760
|
+
sourceRoot: localRoot,
|
|
4761
|
+
repositoryUrl: null,
|
|
4762
|
+
sourceObservation: Object.freeze({
|
|
4763
|
+
kind: "local",
|
|
4764
|
+
root: localRoot
|
|
4765
|
+
})
|
|
4766
|
+
})));
|
|
4767
|
+
return requireGitMarketplaceSource("antigravity", "marketplace-add", source.repositoryUrl, source.revision, source.sparsePaths).pipe(Effect.flatMap((git) => Effect.acquireUseRelease(kernel.fs.makeTempDirectory({ prefix: "habitat-antigravity-git-" }).pipe(mapFs("marketplace-add", void 0, "not-started"), Effect.flatMap((tempDir) => kernel.fs.realPath(tempDir).pipe(mapFs("marketplace-add", tempDir, "not-started")))), (tempDir) => Effect.gen(function* () {
|
|
4768
|
+
const gitEnv = { GIT_TERMINAL_PROMPT: "0" };
|
|
4769
|
+
yield* kernel.runExternalCommand("marketplace-add", gitCommand, ["init", "--quiet"], tempDir, gitEnv);
|
|
4770
|
+
yield* kernel.runExternalCommand("marketplace-add", gitCommand, [
|
|
4771
|
+
"fetch",
|
|
4772
|
+
"--depth",
|
|
4773
|
+
"1",
|
|
4774
|
+
"--quiet",
|
|
4775
|
+
git.repositoryUrl,
|
|
4776
|
+
`refs/tags/${git.revision}`
|
|
4777
|
+
], tempDir, gitEnv).pipe(Effect.catch(() => kernel.runExternalCommand("marketplace-add", gitCommand, [
|
|
4778
|
+
"fetch",
|
|
4779
|
+
"--depth",
|
|
4780
|
+
"1",
|
|
4781
|
+
"--quiet",
|
|
4782
|
+
git.repositoryUrl,
|
|
4783
|
+
git.revision
|
|
4784
|
+
], tempDir, gitEnv)));
|
|
4785
|
+
yield* kernel.runExternalCommand("marketplace-add", gitCommand, [
|
|
4786
|
+
"checkout",
|
|
4787
|
+
"--detach",
|
|
4788
|
+
"--force",
|
|
4789
|
+
"--quiet",
|
|
4790
|
+
"FETCH_HEAD"
|
|
4791
|
+
], tempDir, gitEnv);
|
|
4792
|
+
return yield* stageFromResolvedSourceRoot(kernel, {
|
|
4793
|
+
sourceRoot: tempDir,
|
|
4794
|
+
repositoryUrl: git.repositoryUrl,
|
|
4795
|
+
sourceObservation: Object.freeze({
|
|
4796
|
+
kind: "git",
|
|
4797
|
+
repositoryUrl: git.repositoryUrl,
|
|
4798
|
+
revision: git.revision
|
|
4799
|
+
})
|
|
4800
|
+
});
|
|
4801
|
+
}), (tempDir) => kernel.fs.remove(tempDir, {
|
|
4802
|
+
recursive: true,
|
|
4803
|
+
force: true
|
|
4804
|
+
}).pipe(Effect.ignore))));
|
|
4805
|
+
}
|
|
4806
|
+
function stageFromResolvedSourceRoot(kernel, input) {
|
|
4807
|
+
return Effect.gen(function* () {
|
|
4808
|
+
const catalog = yield* readSourceMarketplaceCatalog(kernel, input.sourceRoot);
|
|
4809
|
+
const marketplacesParent = kernel.paths.join(kernel.geminiRoot, "config", "marketplaces");
|
|
4810
|
+
yield* kernel.fs.makeDirectory(marketplacesParent, { recursive: true }).pipe(mapFs("marketplace-add", marketplacesParent, "not-started"));
|
|
4811
|
+
const verifiedMarketplacesParent = yield* kernel.requireLocalDirectory("marketplace-add", marketplacesParent);
|
|
4812
|
+
if (!isContained(kernel.paths, kernel.home, verifiedMarketplacesParent)) return yield* Effect.fail(providerFailure$2("marketplace-add", "Aliased", "not-started", "Antigravity marketplaces directory escaped the explicit provider home", verifiedMarketplacesParent));
|
|
4813
|
+
const stagingName = `.staging-${catalog.identity}-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2, 10)}`;
|
|
4814
|
+
const stagingDir = kernel.paths.join(verifiedMarketplacesParent, stagingName);
|
|
4815
|
+
const targetDir = kernel.paths.join(verifiedMarketplacesParent, catalog.identity);
|
|
4816
|
+
return yield* Effect.acquireUseRelease(kernel.fs.makeDirectory(stagingDir, { recursive: true }).pipe(mapFs("marketplace-add", stagingDir, "not-started"), Effect.as(stagingDir)), () => Effect.gen(function* () {
|
|
4817
|
+
const pluginNames = [];
|
|
4818
|
+
for (const declared of catalog.plugins) {
|
|
4819
|
+
const pluginSourceCandidate = kernel.paths.join(input.sourceRoot, ...declared.relativeSourcePath.split("/"));
|
|
4820
|
+
if (!isContained(kernel.paths, input.sourceRoot, pluginSourceCandidate)) return yield* Effect.fail(providerFailure$2("marketplace-add", "Aliased", "not-started", `Marketplace plugin ${declared.name} source escaped the marketplace root`, pluginSourceCandidate));
|
|
4821
|
+
const pluginSourceRoot = yield* kernel.requireLocalDirectory("marketplace-add", pluginSourceCandidate);
|
|
4822
|
+
const entries = yield* readPluginSourceTreeEntries(kernel, pluginSourceRoot);
|
|
4823
|
+
const projected = projectAntigravityPluginBundle({
|
|
4824
|
+
entries,
|
|
4825
|
+
repositoryUrl: input.repositoryUrl
|
|
4826
|
+
});
|
|
4827
|
+
if (!projected.ok) return yield* Effect.fail(providerFailure$2("marketplace-add", "ProtocolFailed", "not-started", `Antigravity bundle projection failed for ${declared.name}: ${projected.detail}`, pluginSourceRoot));
|
|
4828
|
+
if (projected.pluginName !== declared.name) return yield* Effect.fail(providerFailure$2("marketplace-add", "ProtocolFailed", "not-started", `Projected plugin manifest name ${projected.pluginName} does not match marketplace entry ${declared.name}`, pluginSourceRoot));
|
|
4829
|
+
const stagedPluginDir = kernel.paths.join(stagingDir, "plugins", declared.name);
|
|
4830
|
+
yield* writeProjectedBundle(kernel, stagedPluginDir, projected.entries);
|
|
4831
|
+
yield* kernel.run("marketplace-add", [
|
|
4832
|
+
"plugin",
|
|
4833
|
+
"validate",
|
|
4834
|
+
stagedPluginDir,
|
|
4835
|
+
"--strict",
|
|
4836
|
+
"--json"
|
|
4837
|
+
]);
|
|
4838
|
+
pluginNames.push(declared.name);
|
|
4839
|
+
}
|
|
4840
|
+
const marketplaceRecord = {
|
|
4841
|
+
identity: catalog.identity,
|
|
4842
|
+
source: input.sourceObservation,
|
|
4843
|
+
plugins: pluginNames
|
|
4844
|
+
};
|
|
4845
|
+
const marketplaceJsonPath = kernel.paths.join(stagingDir, "marketplace.json");
|
|
4846
|
+
yield* kernel.fs.writeFile(marketplaceJsonPath, utf8Encoder.encode(`${JSON.stringify(marketplaceRecord, null, 2)}\n`)).pipe(mapFs("marketplace-add", marketplaceJsonPath, "command-returned"));
|
|
4847
|
+
yield* kernel.fs.chmod(marketplaceJsonPath, 420).pipe(mapFs("marketplace-add", marketplaceJsonPath, "command-returned"));
|
|
4848
|
+
if (yield* kernel.fs.exists(targetDir).pipe(mapFs("marketplace-add", targetDir, "command-returned"))) {
|
|
4849
|
+
const verifiedExisting = yield* kernel.requireLocalDirectory("marketplace-add", targetDir);
|
|
4850
|
+
yield* kernel.fs.remove(verifiedExisting, { recursive: true }).pipe(mapFs("marketplace-add", verifiedExisting, "command-returned"));
|
|
4851
|
+
}
|
|
4852
|
+
yield* kernel.fs.rename(stagingDir, targetDir).pipe(mapFs("marketplace-add", targetDir, "command-returned"));
|
|
4853
|
+
return Object.freeze({
|
|
4854
|
+
provider: "antigravity",
|
|
4855
|
+
operation: "marketplace-add",
|
|
4856
|
+
commandPhase: "command-returned"
|
|
4857
|
+
});
|
|
4858
|
+
}), (dir) => kernel.fs.remove(dir, {
|
|
4859
|
+
recursive: true,
|
|
4860
|
+
force: true
|
|
4861
|
+
}).pipe(Effect.ignore));
|
|
4862
|
+
});
|
|
4863
|
+
}
|
|
4864
|
+
function readSourceMarketplaceCatalog(kernel, sourceRoot) {
|
|
4865
|
+
return Effect.gen(function* () {
|
|
4866
|
+
const claudePath = kernel.paths.join(sourceRoot, ".claude-plugin", "marketplace.json");
|
|
4867
|
+
const codexPath = kernel.paths.join(sourceRoot, ".agents", "plugins", "marketplace.json");
|
|
4868
|
+
const hasClaude = yield* kernel.fs.exists(claudePath).pipe(mapFs("marketplace-add", claudePath, "not-started"));
|
|
4869
|
+
const hasCodex = yield* kernel.fs.exists(codexPath).pipe(mapFs("marketplace-add", codexPath, "not-started"));
|
|
4870
|
+
if (!hasClaude && !hasCodex) return yield* Effect.fail(providerFailure$2("marketplace-add", "Missing", "not-started", "Marketplace source does not contain .claude-plugin/marketplace.json or .agents/plugins/marketplace.json", sourceRoot));
|
|
4871
|
+
const claudeCatalog = hasClaude ? yield* readBoundedRegularUtf8File(kernel, "marketplace-add", sourceRoot, claudePath, MAX_MARKETPLACE_MANIFEST_BYTES, "not-started").pipe(Effect.flatMap((text) => decodeJsonWithPhase("marketplace-add", ClaudeSourceMarketplaceSchema, text, "not-started"))) : null;
|
|
4872
|
+
const codexCatalog = hasCodex ? yield* readBoundedRegularUtf8File(kernel, "marketplace-add", sourceRoot, codexPath, MAX_MARKETPLACE_MANIFEST_BYTES, "not-started").pipe(Effect.flatMap((text) => decodeJsonWithPhase("marketplace-add", CodexSourceMarketplaceSchema, text, "not-started"))) : null;
|
|
4873
|
+
if (claudeCatalog !== null && codexCatalog !== null && claudeCatalog.name !== codexCatalog.name) return yield* Effect.fail(providerFailure$2("marketplace-add", "ProtocolFailed", "not-started", "Claude and Codex marketplace manifests disagree on marketplace identity", sourceRoot));
|
|
4874
|
+
const identity = claudeCatalog?.name ?? codexCatalog?.name;
|
|
4875
|
+
if (identity === void 0) return yield* Effect.fail(providerFailure$2("marketplace-add", "ProtocolFailed", "not-started", "Marketplace manifest omitted its identity", sourceRoot));
|
|
4876
|
+
const claudePlugins = claudeCatalog === null ? null : yield* normalizeDeclaredSourcePlugins(claudeCatalog.plugins.map((entry) => ({
|
|
4877
|
+
name: entry.name,
|
|
4878
|
+
rawPath: entry.source
|
|
4879
|
+
})), claudePath);
|
|
4880
|
+
const codexPlugins = codexCatalog === null ? null : yield* normalizeDeclaredSourcePlugins(codexCatalog.plugins.map((entry) => ({
|
|
4881
|
+
name: entry.name,
|
|
4882
|
+
rawPath: entry.source.path
|
|
4883
|
+
})), codexPath);
|
|
4884
|
+
if (claudePlugins !== null && codexPlugins !== null) {
|
|
4885
|
+
if (claudePlugins.length !== codexPlugins.length || claudePlugins.some((plugin, index) => {
|
|
4886
|
+
const other = codexPlugins[index];
|
|
4887
|
+
return other === void 0 || plugin.name !== other.name || plugin.relativeSourcePath !== other.relativeSourcePath;
|
|
4888
|
+
})) return yield* Effect.fail(providerFailure$2("marketplace-add", "ProtocolFailed", "not-started", "Claude and Codex marketplace manifests declare different plugin sets", sourceRoot));
|
|
4889
|
+
}
|
|
4890
|
+
return Object.freeze({
|
|
4891
|
+
identity,
|
|
4892
|
+
plugins: claudePlugins ?? codexPlugins ?? []
|
|
4893
|
+
});
|
|
4894
|
+
});
|
|
4895
|
+
}
|
|
4896
|
+
function normalizeDeclaredSourcePlugins(entries, manifestPath) {
|
|
4897
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4898
|
+
const normalized = [];
|
|
4899
|
+
for (const entry of entries) {
|
|
4900
|
+
if (seen.has(entry.name)) return Effect.fail(providerFailure$2("marketplace-add", "ProtocolFailed", "not-started", `Marketplace manifest contains duplicate plugin ${entry.name}`, manifestPath));
|
|
4901
|
+
seen.add(entry.name);
|
|
4902
|
+
const trimmed = entry.rawPath.startsWith("./") ? entry.rawPath.slice(2) : entry.rawPath;
|
|
4903
|
+
if (!isCanonicalRelativePath(trimmed)) return Effect.fail(providerFailure$2("marketplace-add", "InvalidInput", "not-started", `Marketplace plugin ${entry.name} source path is not canonical`, manifestPath));
|
|
4904
|
+
normalized.push(Object.freeze({
|
|
4905
|
+
name: entry.name,
|
|
4906
|
+
relativeSourcePath: trimmed
|
|
4907
|
+
}));
|
|
4908
|
+
}
|
|
4909
|
+
return Effect.succeed(Object.freeze([...normalized].sort((left, right) => compareText$5(left.name, right.name))));
|
|
4910
|
+
}
|
|
4911
|
+
function readPluginSourceTreeEntries(kernel, pluginSourceRoot) {
|
|
4912
|
+
return Effect.gen(function* () {
|
|
4913
|
+
const entries = [];
|
|
4914
|
+
const visit = (currentDir, prefix) => Effect.gen(function* () {
|
|
4915
|
+
const names = yield* kernel.fs.readDirectory(currentDir).pipe(mapFs("marketplace-add", currentDir, "not-started"));
|
|
4916
|
+
for (const name of [...names].sort(compareText$5)) {
|
|
4917
|
+
const candidate = kernel.paths.join(currentDir, name);
|
|
4918
|
+
if ((yield* kernel.fs.realPath(candidate).pipe(mapFs("marketplace-add", candidate, "not-started"))) !== candidate) return yield* Effect.fail(providerFailure$2("marketplace-add", "Aliased", "not-started", "Plugin source entry is aliased", candidate));
|
|
4919
|
+
const stat = yield* kernel.fs.stat(candidate).pipe(mapFs("marketplace-add", candidate, "not-started"));
|
|
4920
|
+
const relativePath = prefix === "" ? name : `${prefix}/${name}`;
|
|
4921
|
+
if (stat.type === "Directory") {
|
|
4922
|
+
yield* visit(candidate, relativePath);
|
|
4923
|
+
continue;
|
|
4924
|
+
}
|
|
4925
|
+
if (stat.type !== "File") return yield* Effect.fail(providerFailure$2("marketplace-add", "UnsupportedEntry", "not-started", "Plugin source entry must be a regular file or directory", candidate));
|
|
4926
|
+
if (entries.length >= 16384) return yield* Effect.fail(providerFailure$2("marketplace-add", "LimitExceeded", "not-started", "Plugin source file count exceeds the provider bound", pluginSourceRoot));
|
|
4927
|
+
const size = Number(stat.size);
|
|
4928
|
+
if (!Number.isSafeInteger(size) || size < 0 || size > 67108864) return yield* Effect.fail(providerFailure$2("marketplace-add", "LimitExceeded", "not-started", "Plugin source file exceeds the provider byte bound", candidate));
|
|
4929
|
+
const bytes = yield* kernel.fs.readFile(candidate).pipe(mapFs("marketplace-add", candidate, "not-started"));
|
|
4930
|
+
const mode = (Number(stat.mode) & 73) !== 0 ? 493 : 420;
|
|
4931
|
+
entries.push(Object.freeze({
|
|
4932
|
+
path: relativePath,
|
|
4933
|
+
mode,
|
|
4934
|
+
bytes
|
|
4935
|
+
}));
|
|
4936
|
+
}
|
|
4937
|
+
});
|
|
4938
|
+
yield* visit(pluginSourceRoot, "");
|
|
4939
|
+
return Object.freeze(entries);
|
|
4940
|
+
});
|
|
4941
|
+
}
|
|
4942
|
+
function writeProjectedBundle(kernel, stagedPluginDir, entries) {
|
|
4943
|
+
return Effect.gen(function* () {
|
|
4944
|
+
yield* kernel.fs.makeDirectory(stagedPluginDir, { recursive: true }).pipe(mapFs("marketplace-add", stagedPluginDir, "not-started"));
|
|
4945
|
+
for (const entry of entries) {
|
|
4946
|
+
const targetPath = kernel.paths.join(stagedPluginDir, ...entry.path.split("/"));
|
|
4947
|
+
if (!isContained(kernel.paths, stagedPluginDir, targetPath)) return yield* Effect.fail(providerFailure$2("marketplace-add", "Aliased", "not-started", "Projected bundle entry escaped the staged plugin directory", targetPath));
|
|
4948
|
+
const parentDir = kernel.paths.dirname(targetPath);
|
|
4949
|
+
yield* kernel.fs.makeDirectory(parentDir, { recursive: true }).pipe(mapFs("marketplace-add", parentDir, "not-started"));
|
|
4950
|
+
yield* kernel.fs.writeFile(targetPath, entry.bytes).pipe(mapFs("marketplace-add", targetPath, "not-started"));
|
|
4951
|
+
yield* kernel.fs.chmod(targetPath, entry.mode).pipe(mapFs("marketplace-add", targetPath, "not-started"));
|
|
4952
|
+
}
|
|
4953
|
+
});
|
|
4954
|
+
}
|
|
4955
|
+
function removeStagedMarketplace(kernel, identity) {
|
|
4956
|
+
return Effect.gen(function* () {
|
|
4957
|
+
const targetDir = kernel.paths.join(kernel.geminiRoot, "config", "marketplaces", identity);
|
|
4958
|
+
if (!isContained(kernel.paths, kernel.home, targetDir)) return yield* Effect.fail(providerFailure$2("marketplace-remove", "Aliased", "not-started", "Marketplace directory escaped the explicit provider home", targetDir));
|
|
4959
|
+
const verifiedTarget = yield* kernel.requireLocalDirectory("marketplace-remove", targetDir);
|
|
4960
|
+
yield* kernel.fs.remove(verifiedTarget, { recursive: true }).pipe(mapFs("marketplace-remove", verifiedTarget, "not-started"));
|
|
4961
|
+
return Object.freeze({
|
|
4962
|
+
provider: "antigravity",
|
|
4963
|
+
operation: "marketplace-remove",
|
|
4964
|
+
commandPhase: "command-returned"
|
|
4965
|
+
});
|
|
4966
|
+
});
|
|
4967
|
+
}
|
|
4968
|
+
function installStagedPlugin(kernel, selector) {
|
|
4969
|
+
return Effect.gen(function* () {
|
|
4970
|
+
const parsed = splitSelector(selector, "plugin-install");
|
|
4971
|
+
if (parsed === null) return yield* Effect.fail(providerFailure$2("plugin-install", "InvalidInput", "not-started", "Plugin selector is not canonical"));
|
|
4972
|
+
const stagedPluginDir = kernel.paths.join(kernel.geminiRoot, "config", "marketplaces", parsed.marketplaceIdentity, "plugins", parsed.name);
|
|
4973
|
+
if (!isContained(kernel.paths, kernel.home, stagedPluginDir)) return yield* Effect.fail(providerFailure$2("plugin-install", "Aliased", "not-started", "Staged plugin directory escaped the explicit provider home", stagedPluginDir));
|
|
4974
|
+
const verifiedPluginDir = yield* kernel.requireLocalDirectory("plugin-install", stagedPluginDir);
|
|
4975
|
+
const { existingLedger, previousOwnedTreeSha256 } = yield* verifyInstallSlotOwnership(kernel, parsed);
|
|
4976
|
+
const stagedTreeSha256 = yield* computeDirectoryTreeSha256(kernel, "plugin-install", kernel.home, verifiedPluginDir, "not-started");
|
|
4977
|
+
const pending = yield* recordPendingPluginInstall(kernel, existingLedger, {
|
|
4978
|
+
name: parsed.name,
|
|
4979
|
+
marketplaceIdentity: parsed.marketplaceIdentity,
|
|
4980
|
+
previousTreeSha256: previousOwnedTreeSha256,
|
|
4981
|
+
stagedTreeSha256
|
|
4982
|
+
});
|
|
4983
|
+
const result = yield* kernel.mutation("plugin-install", [
|
|
4984
|
+
"plugin",
|
|
4985
|
+
"install",
|
|
4986
|
+
verifiedPluginDir
|
|
4987
|
+
]);
|
|
4988
|
+
if (pending.needsPostInstallSettle) yield* settlePluginInstall(kernel, {
|
|
4989
|
+
name: parsed.name,
|
|
4990
|
+
marketplaceIdentity: parsed.marketplaceIdentity,
|
|
4991
|
+
stagedTreeSha256
|
|
4992
|
+
});
|
|
4993
|
+
return result;
|
|
4994
|
+
});
|
|
4995
|
+
}
|
|
4996
|
+
function removeInstalledPlugin(kernel, selector) {
|
|
4997
|
+
return Effect.gen(function* () {
|
|
4998
|
+
const parsed = splitSelector(selector, "plugin-remove");
|
|
4999
|
+
if (parsed === null) return yield* Effect.fail(providerFailure$2("plugin-remove", "InvalidInput", "not-started", "Plugin selector is not canonical"));
|
|
5000
|
+
yield* verifyRemoveSlotOwnership(kernel, parsed);
|
|
5001
|
+
const result = yield* kernel.mutation("plugin-remove", [
|
|
5002
|
+
"plugin",
|
|
5003
|
+
"uninstall",
|
|
5004
|
+
parsed.name
|
|
5005
|
+
]).pipe(Effect.tapError((error) => error.commandPhase === "command-returned" ? readLivePluginNamesBestEffort(kernel, "plugin-remove").pipe(Effect.flatMap((liveNames) => liveNames !== null && !liveNames.has(parsed.name) ? deletePluginLedgerEntry(kernel, "plugin-remove", parsed.name).pipe(Effect.ignore) : Effect.void)) : Effect.void));
|
|
5006
|
+
yield* deletePluginLedgerEntry(kernel, "plugin-remove", parsed.name);
|
|
5007
|
+
return result;
|
|
5008
|
+
});
|
|
5009
|
+
}
|
|
5010
|
+
function readBoundedRegularBytes(kernel, operation, containmentRoot, candidatePath, maxBytes, phase) {
|
|
5011
|
+
return Effect.gen(function* () {
|
|
5012
|
+
if (!isContained(kernel.paths, containmentRoot, candidatePath)) return yield* Effect.fail(providerFailure$2(operation, "Aliased", phase, "File path escaped its containment root", candidatePath));
|
|
5013
|
+
if ((yield* kernel.fs.realPath(candidatePath).pipe(mapFs(operation, candidatePath, phase))) !== candidatePath) return yield* Effect.fail(providerFailure$2(operation, "Aliased", phase, "File path is aliased", candidatePath));
|
|
5014
|
+
const stat = yield* kernel.fs.stat(candidatePath).pipe(mapFs(operation, candidatePath, phase));
|
|
5015
|
+
if (stat.type !== "File") return yield* Effect.fail(providerFailure$2(operation, "UnsupportedEntry", phase, "Expected a regular file", candidatePath));
|
|
5016
|
+
const size = Number(stat.size);
|
|
5017
|
+
if (!Number.isSafeInteger(size) || size < 0 || size > maxBytes) return yield* Effect.fail(providerFailure$2(operation, "LimitExceeded", phase, "File exceeds bounded size", candidatePath));
|
|
5018
|
+
return yield* kernel.fs.readFile(candidatePath).pipe(mapFs(operation, candidatePath, phase));
|
|
5019
|
+
});
|
|
5020
|
+
}
|
|
5021
|
+
function readBoundedRegularUtf8File(kernel, operation, containmentRoot, candidatePath, maxBytes, phase) {
|
|
5022
|
+
return readBoundedRegularBytes(kernel, operation, containmentRoot, candidatePath, maxBytes, phase).pipe(Effect.flatMap((bytes) => Effect.try({
|
|
5023
|
+
try: () => utf8Decoder.decode(bytes),
|
|
5024
|
+
catch: () => providerFailure$2(operation, "ProtocolFailed", phase, "File is not valid UTF-8", candidatePath)
|
|
5025
|
+
})));
|
|
5026
|
+
}
|
|
5027
|
+
function decodeJsonWithPhase(operation, schema, text, phase) {
|
|
5028
|
+
return Effect.try({
|
|
5029
|
+
try: () => JSON.parse(text),
|
|
5030
|
+
catch: (cause) => providerFailure$2(operation, "InvalidJson", phase, cause instanceof Error ? cause.message : String(cause))
|
|
5031
|
+
}).pipe(Effect.flatMap((value) => Value.Check(schema, value) ? Effect.succeed(value) : Effect.fail(providerFailure$2(operation, "ProtocolFailed", phase, "JSON document did not match the expected schema"))));
|
|
5032
|
+
}
|
|
5033
|
+
function requireUniqueInventory$2(marketplaces, plugins, mcpServers) {
|
|
5034
|
+
return new Set(marketplaces.map((entry) => entry.identity)).size === marketplaces.length && new Set(plugins.map((entry) => entry.selector)).size === plugins.length && new Set(mcpServers.map((entry) => entry.name)).size === mcpServers.length ? Effect.void : Effect.fail(providerFailure$2("inventory", "ProtocolFailed", "command-returned", "Antigravity native inventory contains duplicate identities"));
|
|
5035
|
+
}
|
|
5036
|
+
function selectPluginRoot$2(plugins, selector) {
|
|
5037
|
+
const matches = plugins.filter((entry) => entry.selector === selector && entry.installed);
|
|
5038
|
+
const selected = matches[0];
|
|
5039
|
+
if (matches.length !== 1 || selected === void 0) return Effect.fail(providerFailure$2("plugin-files-read", matches.length === 0 ? "Missing" : "ProtocolFailed", "command-returned", matches.length === 0 ? "Antigravity installed plugin selector is absent" : "Antigravity installed plugin selector is ambiguous"));
|
|
5040
|
+
return selected.root === null ? Effect.fail(providerFailure$2("plugin-files-read", "ProtocolFailed", "command-returned", "Antigravity installed plugin omitted its native package root")) : Effect.succeed(selected.root);
|
|
5041
|
+
}
|
|
5042
|
+
function splitSelector(selector, _operation) {
|
|
5043
|
+
const separator = selector.lastIndexOf("@");
|
|
5044
|
+
if (separator <= 0 || separator === selector.length - 1) return null;
|
|
5045
|
+
return Object.freeze({
|
|
5046
|
+
name: selector.slice(0, separator),
|
|
5047
|
+
marketplaceIdentity: selector.slice(separator + 1)
|
|
5048
|
+
});
|
|
5049
|
+
}
|
|
5050
|
+
function requireVersion$2(stdout) {
|
|
5051
|
+
const version = stdout.trim();
|
|
5052
|
+
return version.length > 0 && version.length <= 4096 ? Effect.succeed(version) : Effect.fail(providerFailure$2("probe", "ProtocolFailed", "command-returned", "Antigravity version output is empty or oversized"));
|
|
5053
|
+
}
|
|
5054
|
+
function mapFs(operation, candidate, phase) {
|
|
5055
|
+
return (effect) => effect.pipe(Effect.mapError((cause) => providerFailure$2(operation, cause.reason._tag === "NotFound" ? "Missing" : "FilesystemFailed", phase, cause.message, candidate)));
|
|
5056
|
+
}
|
|
5057
|
+
function providerFailure$2(operation, reason, commandPhase, detail, candidate) {
|
|
5058
|
+
return Object.freeze({
|
|
5059
|
+
_tag: "NativeAgentProviderFailure",
|
|
5060
|
+
provider: "antigravity",
|
|
5061
|
+
operation,
|
|
5062
|
+
reason,
|
|
5063
|
+
commandPhase,
|
|
5064
|
+
...candidate === void 0 ? {} : { path: candidate },
|
|
5065
|
+
detail: detail.slice(0, 4096)
|
|
5066
|
+
});
|
|
5067
|
+
}
|
|
5068
|
+
function isContained(paths, root, candidate) {
|
|
5069
|
+
const relative = paths.relative(root, candidate);
|
|
5070
|
+
return relative !== "" && relative !== ".." && !relative.startsWith(`..${paths.sep}`) && !paths.isAbsolute(relative);
|
|
5071
|
+
}
|
|
5072
|
+
function isCanonicalRelativePath(value) {
|
|
5073
|
+
return value.length > 0 && value.length <= 1024 && !value.startsWith("/") && !value.endsWith("/") && !value.includes("\\") && !/[\u0000-\u001f\u007f]/u.test(value) && value.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
5074
|
+
}
|
|
5075
|
+
function byIdentity$2(left, right) {
|
|
5076
|
+
return compareText$5(left.identity, right.identity);
|
|
5077
|
+
}
|
|
5078
|
+
function bySelector$2(left, right) {
|
|
5079
|
+
return compareText$5(left.selector, right.selector);
|
|
5080
|
+
}
|
|
5081
|
+
function byMcpName$2(left, right) {
|
|
5082
|
+
return compareText$5(left.name, right.name);
|
|
5083
|
+
}
|
|
5084
|
+
function compareText$5(left, right) {
|
|
5085
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
5086
|
+
}
|
|
5087
|
+
//#endregion
|
|
5088
|
+
//#region ../../resources/native-agent-provider/dist/providers/antigravity-effect-platform-node/runtime.js
|
|
5089
|
+
/** Acquire a fresh capability factory without opening any caller-selected workspace or home. */
|
|
5090
|
+
function defineNodeAntigravityNativeAgentProviderRuntimeProvider() {
|
|
5091
|
+
return defineRuntimeProvider({
|
|
5092
|
+
id: "native-agent-provider.antigravity.antigravity-effect-platform-node",
|
|
5093
|
+
title: "Antigravity native agent provider (antigravity-effect-platform-node)",
|
|
5094
|
+
provides: AntigravityNativeAgentProviderRuntimeResource,
|
|
5095
|
+
requires: [],
|
|
5096
|
+
build: () => providerFx.acquireRelease({
|
|
5097
|
+
acquire: Effect.sync(() => makeNodeAntigravityNativeAgentProviderResource()),
|
|
5098
|
+
release: () => Effect.void
|
|
5099
|
+
})
|
|
5100
|
+
});
|
|
5101
|
+
}
|
|
5102
|
+
//#endregion
|
|
5103
|
+
//#region ../../resources/native-agent-provider/dist/providers/claude-effect-platform-node/mcp.js
|
|
5104
|
+
const MAX_OBSERVED_URL_LENGTH$1 = 4096;
|
|
5105
|
+
/**
|
|
5106
|
+
* Reads and permissively normalizes Claude's user-scope `.claude.json` `mcpServers` entries.
|
|
5107
|
+
*/
|
|
5108
|
+
function readClaudeLiveMcpServers(kernel, operation, commandPhase = "not-started") {
|
|
5109
|
+
return kernel.readClaudeUserConfigJson(operation, commandPhase).pipe(Effect.flatMap((userConfig) => decodeClaudeMcpServers(operation, commandPhase, userConfig)));
|
|
5110
|
+
}
|
|
5111
|
+
/**
|
|
5112
|
+
* Executes a serialized Claude user-scope HTTP MCP add with write-ahead ledger ownership and
|
|
5113
|
+
* rollback on confirmed absence after a failed command.
|
|
5114
|
+
*/
|
|
5115
|
+
function addClaudeMcpServer(kernel, request) {
|
|
5116
|
+
return kernel.serialized("mcp-add", requireMcpServerAddInput("claude", "mcp-add", request).pipe(Effect.flatMap(({ name, url, ownerPluginId }) => Effect.gen(function* () {
|
|
5117
|
+
yield* requireSupportedClaudeOAuthEnvironment("mcp-add", "not-started");
|
|
5118
|
+
yield* kernel.sweepTransientMcpLedger("mcp-add", "not-started");
|
|
5119
|
+
const previousLedger = yield* kernel.readManagedMcpLedger("mcp-add");
|
|
5120
|
+
const liveBefore = yield* readClaudeLiveMcpServers(kernel, "mcp-add", "not-started");
|
|
5121
|
+
const previousEntry = previousLedger.find((entry) => entry.name === name);
|
|
5122
|
+
const existingLive = liveBefore.find((entry) => entry.name === name);
|
|
5123
|
+
if (existingLive !== void 0 && (previousEntry === void 0 || existingLive.transport !== "http" || existingLive.url !== previousEntry.url)) return yield* Effect.fail(claudeMcpFailure("mcp-add", "InvalidInput", "not-started", `Refusing to overwrite unmanaged MCP server ${name}`));
|
|
5124
|
+
const nextLedger = [...previousLedger.filter((entry) => entry.name !== name), Object.freeze({
|
|
5125
|
+
name,
|
|
5126
|
+
url,
|
|
5127
|
+
ownerPluginId
|
|
5128
|
+
})];
|
|
5129
|
+
yield* kernel.writeManagedMcpLedger("mcp-add", nextLedger, "not-started");
|
|
5130
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-add", [
|
|
5131
|
+
"mcp",
|
|
5132
|
+
"add",
|
|
5133
|
+
"--scope",
|
|
5134
|
+
"user",
|
|
5135
|
+
"--transport",
|
|
5136
|
+
"http",
|
|
5137
|
+
name,
|
|
5138
|
+
url
|
|
5139
|
+
]));
|
|
5140
|
+
if (Result.isSuccess(attempt)) return attempt.success;
|
|
5141
|
+
if (attempt.failure.commandPhase === "not-started") return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
5142
|
+
const liveAfterAttempt = yield* Effect.result(readClaudeLiveMcpServers(kernel, "mcp-add", attempt.failure.commandPhase));
|
|
5143
|
+
if (Result.isSuccess(liveAfterAttempt)) {
|
|
5144
|
+
const liveAfter = liveAfterAttempt.success.find((entry) => entry.name === name);
|
|
5145
|
+
if (liveAfter === void 0 || liveAfter.transport !== "http" || liveAfter.url !== url) return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
5146
|
+
}
|
|
5147
|
+
return yield* Effect.fail(attempt.failure);
|
|
5148
|
+
}))));
|
|
5149
|
+
}
|
|
5150
|
+
/**
|
|
5151
|
+
* Executes a serialized Claude user-scope MCP removal guarded by exact ledger URL ownership and
|
|
5152
|
+
* prunes orphan ledger records without invoking the native CLI when already absent.
|
|
5153
|
+
*/
|
|
5154
|
+
function removeClaudeMcpServer(kernel, request) {
|
|
5155
|
+
return kernel.serialized("mcp-remove", requireMcpServerRemoveInput("claude", "mcp-remove", request).pipe(Effect.flatMap((name) => Effect.gen(function* () {
|
|
5156
|
+
yield* requireSupportedClaudeOAuthEnvironment("mcp-remove", "not-started");
|
|
5157
|
+
yield* kernel.sweepTransientMcpLedger("mcp-remove", "not-started");
|
|
5158
|
+
const currentLedger = yield* kernel.readManagedMcpLedger("mcp-remove");
|
|
5159
|
+
const liveBefore = yield* readClaudeLiveMcpServers(kernel, "mcp-remove", "not-started");
|
|
5160
|
+
const ledgerEntry = currentLedger.find((entry) => entry.name === name);
|
|
5161
|
+
const liveEntry = liveBefore.find((entry) => entry.name === name);
|
|
5162
|
+
if (liveEntry === void 0) {
|
|
5163
|
+
if (ledgerEntry !== void 0) yield* kernel.writeManagedMcpLedger("mcp-remove", currentLedger.filter((entry) => entry.name !== name), "not-started");
|
|
5164
|
+
return Object.freeze({
|
|
5165
|
+
provider: "claude",
|
|
5166
|
+
operation: "mcp-remove",
|
|
5167
|
+
commandPhase: "command-returned"
|
|
5168
|
+
});
|
|
5169
|
+
}
|
|
5170
|
+
if (ledgerEntry === void 0 || liveEntry.transport !== "http" || liveEntry.url !== ledgerEntry.url) return yield* Effect.fail(claudeMcpFailure("mcp-remove", "InvalidInput", "not-started", `Refusing to remove unmanaged MCP server ${name}`));
|
|
5171
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-remove", [
|
|
5172
|
+
"mcp",
|
|
5173
|
+
"remove",
|
|
5174
|
+
"--scope",
|
|
5175
|
+
"user",
|
|
5176
|
+
name
|
|
5177
|
+
]));
|
|
5178
|
+
if (Result.isSuccess(attempt)) {
|
|
5179
|
+
yield* pruneManagedMcpLedgerEntry$1(kernel, name, "command-returned");
|
|
5180
|
+
return attempt.success;
|
|
5181
|
+
}
|
|
5182
|
+
if (attempt.failure.commandPhase !== "command-returned") return yield* Effect.fail(attempt.failure);
|
|
5183
|
+
const liveAfterAttempt = yield* Effect.result(readClaudeLiveMcpServers(kernel, "mcp-remove", "command-returned"));
|
|
5184
|
+
if (Result.isSuccess(liveAfterAttempt) && !liveAfterAttempt.success.some((entry) => entry.name === name)) {
|
|
5185
|
+
yield* pruneManagedMcpLedgerEntry$1(kernel, name, "command-returned");
|
|
5186
|
+
return Object.freeze({
|
|
5187
|
+
provider: "claude",
|
|
5188
|
+
operation: "mcp-remove",
|
|
5189
|
+
commandPhase: "command-returned"
|
|
5190
|
+
});
|
|
5191
|
+
}
|
|
5192
|
+
return yield* Effect.fail(attempt.failure);
|
|
5193
|
+
}))));
|
|
5194
|
+
}
|
|
5195
|
+
function decodeClaudeMcpServers(operation, commandPhase, userConfig) {
|
|
5196
|
+
if (userConfig === null) return Effect.succeed(Object.freeze([]));
|
|
5197
|
+
if (!isPlainRecord$1(userConfig)) return Effect.fail(claudeMcpFailure(operation, "ProtocolFailed", commandPhase, "Claude .claude.json top-level value must be a JSON object"));
|
|
5198
|
+
const rawServers = Reflect.get(userConfig, "mcpServers");
|
|
5199
|
+
if (rawServers === void 0 || rawServers === null) return Effect.succeed(Object.freeze([]));
|
|
5200
|
+
if (!isPlainRecord$1(rawServers)) return Effect.fail(claudeMcpFailure(operation, "ProtocolFailed", commandPhase, "Claude .claude.json mcpServers must be a JSON object"));
|
|
5201
|
+
const entries = Object.entries(rawServers).filter(([name]) => Value.Check(ObservedMcpServerNameSchema, name));
|
|
5202
|
+
if (entries.length > 1024) return Effect.fail(claudeMcpFailure(operation, "LimitExceeded", commandPhase, "Claude .claude.json MCP server count exceeds the resource limit"));
|
|
5203
|
+
return Effect.succeed(Object.freeze(entries.map(([name, entry]) => normalizeClaudeMcpServer(name, entry))));
|
|
5204
|
+
}
|
|
5205
|
+
function normalizeClaudeMcpServer(name, entry) {
|
|
5206
|
+
if (!isPlainRecord$1(entry)) return Object.freeze({
|
|
5207
|
+
name,
|
|
5208
|
+
transport: "other",
|
|
5209
|
+
url: null,
|
|
5210
|
+
enabled: null
|
|
5211
|
+
});
|
|
5212
|
+
const rawEnabled = Reflect.get(entry, "enabled");
|
|
5213
|
+
const rawDisabled = Reflect.get(entry, "disabled");
|
|
5214
|
+
const enabled = typeof rawEnabled === "boolean" ? rawEnabled : typeof rawDisabled === "boolean" ? !rawDisabled : null;
|
|
5215
|
+
const rawUrl = Reflect.get(entry, "url");
|
|
5216
|
+
const url = typeof rawUrl === "string" && rawUrl.length > 0 && rawUrl.length <= MAX_OBSERVED_URL_LENGTH$1 ? rawUrl : null;
|
|
5217
|
+
if (Reflect.get(entry, "type") === "http" && url !== null) return Object.freeze({
|
|
5218
|
+
name,
|
|
5219
|
+
transport: "http",
|
|
5220
|
+
url,
|
|
5221
|
+
enabled
|
|
5222
|
+
});
|
|
5223
|
+
return Object.freeze({
|
|
5224
|
+
name,
|
|
5225
|
+
transport: "other",
|
|
5226
|
+
url,
|
|
5227
|
+
enabled
|
|
5228
|
+
});
|
|
5229
|
+
}
|
|
5230
|
+
function pruneManagedMcpLedgerEntry$1(kernel, name, commandPhase) {
|
|
5231
|
+
return kernel.readManagedMcpLedger("mcp-remove").pipe(Effect.mapError((error) => error.commandPhase === commandPhase ? error : Object.freeze({
|
|
5232
|
+
...error,
|
|
5233
|
+
commandPhase
|
|
5234
|
+
})), Effect.flatMap((current) => {
|
|
5235
|
+
const next = current.filter((entry) => entry.name !== name);
|
|
5236
|
+
return next.length === current.length ? Effect.void : kernel.writeManagedMcpLedger("mcp-remove", next, commandPhase);
|
|
5237
|
+
}));
|
|
5238
|
+
}
|
|
5239
|
+
function isPlainRecord$1(value) {
|
|
5240
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5241
|
+
}
|
|
5242
|
+
function claudeMcpFailure(operation, reason, commandPhase, detail) {
|
|
5243
|
+
return Object.freeze({
|
|
5244
|
+
_tag: "NativeAgentProviderFailure",
|
|
5245
|
+
provider: "claude",
|
|
5246
|
+
operation,
|
|
5247
|
+
reason,
|
|
5248
|
+
commandPhase,
|
|
5249
|
+
detail
|
|
5250
|
+
});
|
|
5251
|
+
}
|
|
5252
|
+
//#endregion
|
|
5253
|
+
//#region ../../resources/native-agent-provider/dist/providers/claude-effect-platform-node/index.js
|
|
5254
|
+
const NullableStringSchema$1 = Type.Union([Type.String(), Type.Null()]);
|
|
5255
|
+
const GitHubRepositorySchema = Type.String({
|
|
5256
|
+
pattern: "^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$",
|
|
5257
|
+
minLength: 3,
|
|
5258
|
+
maxLength: 256
|
|
5259
|
+
});
|
|
5260
|
+
const ClaudeMarketplaceListSchema = Type.Array(Type.Object({
|
|
5261
|
+
name: Type.String(),
|
|
5262
|
+
source: Type.Optional(NullableStringSchema$1),
|
|
5263
|
+
url: Type.Optional(NullableStringSchema$1),
|
|
5264
|
+
repo: Type.Optional(Type.Union([GitHubRepositorySchema, Type.Null()])),
|
|
5265
|
+
path: Type.Optional(NullableStringSchema$1),
|
|
5266
|
+
installLocation: Type.Optional(NullableStringSchema$1),
|
|
5267
|
+
revision: Type.Optional(NullableStringSchema$1),
|
|
5268
|
+
ref: Type.Optional(NullableStringSchema$1)
|
|
5269
|
+
}, { additionalProperties: true }), { maxItems: 1024 });
|
|
5270
|
+
const ClaudePluginListSchema = Type.Array(Type.Object({
|
|
5271
|
+
id: Type.String(),
|
|
5272
|
+
version: Type.Optional(NullableStringSchema$1),
|
|
5273
|
+
enabled: Type.Optional(Type.Union([Type.Boolean(), Type.Null()])),
|
|
5274
|
+
installPath: Type.Optional(NullableStringSchema$1)
|
|
5275
|
+
}, { additionalProperties: true }), { maxItems: 4096 });
|
|
5276
|
+
const CLAUDE_CAPABILITIES = [
|
|
5277
|
+
"marketplace-list",
|
|
5278
|
+
"marketplace-add",
|
|
5279
|
+
"marketplace-remove",
|
|
5280
|
+
"marketplace-update",
|
|
5281
|
+
"plugin-list",
|
|
5282
|
+
"plugin-install",
|
|
5283
|
+
"plugin-enable",
|
|
5284
|
+
"plugin-disable",
|
|
5285
|
+
"plugin-remove",
|
|
5286
|
+
"plugin-update",
|
|
5287
|
+
"mcp-list",
|
|
5288
|
+
"mcp-add",
|
|
5289
|
+
"mcp-remove"
|
|
5290
|
+
];
|
|
5291
|
+
/**
|
|
5292
|
+
* Constructs the platform-requiring Claude provider without choosing a runtime.
|
|
5293
|
+
*/
|
|
5294
|
+
function makeClaudeEffectPlatformNodeProvider(options = {}) {
|
|
5295
|
+
const command = options.command ?? "claude";
|
|
5296
|
+
return Object.freeze({ acquire: (input) => acquireEffectPlatformNodeProvider("claude", command, input, { hostUserHome: options.hostUserHome }).pipe(Effect.map((kernel) => {
|
|
5297
|
+
const probe = () => kernel.serialized("probe", Effect.gen(function* () {
|
|
5298
|
+
const version = yield* kernel.run("probe", ["--version"]);
|
|
5299
|
+
return Object.freeze({
|
|
5300
|
+
provider: "claude",
|
|
5301
|
+
home: kernel.home,
|
|
5302
|
+
version: yield* requireVersion$1(version.stdout),
|
|
5303
|
+
capabilities: [...CLAUDE_CAPABILITIES]
|
|
5304
|
+
});
|
|
5305
|
+
}));
|
|
5306
|
+
const inventory = (inventoryOptions) => kernel.serialized("inventory", requireInventoryOptions("claude", inventoryOptions).pipe(Effect.flatMap((normalized) => claudeInventory(kernel, normalized))));
|
|
5307
|
+
return Object.freeze({
|
|
5308
|
+
provider: "claude",
|
|
5309
|
+
home: kernel.home,
|
|
5310
|
+
probe,
|
|
5311
|
+
inventory,
|
|
5312
|
+
readPluginFiles: (request) => kernel.serialized("plugin-files-read", requirePluginFilesReadInput("claude", "plugin-files-read", request).pipe(Effect.flatMap((validated) => claudeInstalledPlugins(kernel).pipe(Effect.flatMap((plugins) => selectPluginRoot$1(plugins, validated.selector).pipe(Effect.flatMap((root) => Effect.forEach(validated.files, (file) => kernel.readPluginEntry("plugin-files-read", root, file).pipe(Effect.catchIf((error) => error.reason === "Missing" || error.reason === "LimitExceeded", (error) => {
|
|
5313
|
+
const missing = Object.freeze({
|
|
5314
|
+
kind: error.reason === "Missing" ? "Missing" : "TooLarge",
|
|
5315
|
+
relativePath: file.relativePath
|
|
5316
|
+
});
|
|
5317
|
+
return Effect.succeed(missing);
|
|
5318
|
+
})), { concurrency: 1 }).pipe(Effect.map((files) => {
|
|
5319
|
+
return Object.freeze({
|
|
5320
|
+
selector: validated.selector,
|
|
5321
|
+
files: Object.freeze(files)
|
|
5322
|
+
});
|
|
5323
|
+
}))))))))),
|
|
5324
|
+
addMarketplace: (source) => kernel.serialized("marketplace-add", requireMarketplaceSource("claude", "marketplace-add", source).pipe(Effect.flatMap((validated) => claudeMarketplaceAddArgs(kernel, validated)), Effect.flatMap((args) => kernel.mutation("marketplace-add", args)))),
|
|
5325
|
+
removeMarketplace: (request) => kernel.serialized("marketplace-remove", requireMarketplaceIdentityInput("claude", "marketplace-remove", request).pipe(Effect.flatMap((identity) => kernel.mutation("marketplace-remove", [
|
|
5326
|
+
"plugin",
|
|
5327
|
+
"marketplace",
|
|
5328
|
+
"remove",
|
|
5329
|
+
identity,
|
|
5330
|
+
"--scope",
|
|
5331
|
+
"user"
|
|
5332
|
+
])))),
|
|
5333
|
+
installPlugin: (request) => kernel.serialized("plugin-install", requirePluginSelectorInput("claude", "plugin-install", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-install", "install", selector)))),
|
|
5334
|
+
enablePlugin: (request) => kernel.serialized("plugin-enable", requirePluginSelectorInput("claude", "plugin-enable", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-enable", "enable", selector)))),
|
|
5335
|
+
removePlugin: (request) => kernel.serialized("plugin-remove", requirePluginSelectorInput("claude", "plugin-remove", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-remove", "uninstall", selector)))),
|
|
5336
|
+
addMcpServer: (request) => addClaudeMcpServer(kernel, request),
|
|
5337
|
+
removeMcpServer: (request) => removeClaudeMcpServer(kernel, request)
|
|
5338
|
+
});
|
|
5339
|
+
})) });
|
|
5340
|
+
}
|
|
5341
|
+
/**
|
|
5342
|
+
* Constructs a ready Claude resource whose Node platform is supplied only while
|
|
5343
|
+
* acquiring a session.
|
|
5344
|
+
*/
|
|
5345
|
+
function makeNodeClaudeNativeAgentProviderResource(options = {}) {
|
|
5346
|
+
const provider = makeClaudeEffectPlatformNodeProvider(options);
|
|
5347
|
+
return Object.freeze({ acquire: (input) => provider.acquire(input).pipe(Effect.provide(NodeServices.layer)) });
|
|
5348
|
+
}
|
|
5349
|
+
function claudeInstalledPlugins(kernel) {
|
|
5350
|
+
return Effect.gen(function* () {
|
|
5351
|
+
const marketplaceOutput = yield* kernel.run("inventory", [
|
|
5352
|
+
"plugin",
|
|
5353
|
+
"marketplace",
|
|
5354
|
+
"list",
|
|
5355
|
+
"--json"
|
|
5356
|
+
]);
|
|
5357
|
+
const pluginOutput = yield* kernel.run("inventory", [
|
|
5358
|
+
"plugin",
|
|
5359
|
+
"list",
|
|
5360
|
+
"--json"
|
|
5361
|
+
]);
|
|
5362
|
+
const marketplaceRecord = yield* decodeProviderJson("claude", "inventory", ClaudeMarketplaceListSchema, marketplaceOutput.stdout);
|
|
5363
|
+
const pluginRecord = yield* decodeProviderJson("claude", "inventory", ClaudePluginListSchema, pluginOutput.stdout);
|
|
5364
|
+
const marketplaces = yield* Effect.forEach(marketplaceRecord, normalizeMarketplace$1, { concurrency: 1 });
|
|
5365
|
+
const plugins = yield* Effect.forEach(pluginRecord, normalizePlugin$1, { concurrency: 1 });
|
|
5366
|
+
yield* requireUniqueInventory$1(marketplaces, plugins, []);
|
|
5367
|
+
return Object.freeze([...plugins].sort(bySelector$1));
|
|
5368
|
+
});
|
|
5369
|
+
}
|
|
5370
|
+
function claudeInventory(kernel, options) {
|
|
5371
|
+
return Effect.gen(function* () {
|
|
5372
|
+
const marketplaceOutput = yield* kernel.run("inventory", [
|
|
3490
5373
|
"plugin",
|
|
3491
5374
|
"marketplace",
|
|
3492
5375
|
"list",
|
|
@@ -3497,15 +5380,19 @@ function claudeInventory(kernel) {
|
|
|
3497
5380
|
"list",
|
|
3498
5381
|
"--json"
|
|
3499
5382
|
]);
|
|
5383
|
+
const managedMcpServers = yield* kernel.readManagedMcpLedger("inventory");
|
|
5384
|
+
const mcpServers = shouldObserveProviderMcpConfig(options, managedMcpServers) ? yield* readClaudeLiveMcpServers(kernel, "inventory", "not-started") : Object.freeze([]);
|
|
3500
5385
|
const marketplaceRecord = yield* decodeProviderJson("claude", "inventory", ClaudeMarketplaceListSchema, marketplaceOutput.stdout);
|
|
3501
5386
|
const pluginRecord = yield* decodeProviderJson("claude", "inventory", ClaudePluginListSchema, pluginOutput.stdout);
|
|
3502
5387
|
const marketplaces = yield* Effect.forEach(marketplaceRecord, normalizeMarketplace$1, { concurrency: 1 });
|
|
3503
5388
|
const plugins = yield* Effect.forEach(pluginRecord, normalizePlugin$1, { concurrency: 1 });
|
|
3504
|
-
yield* requireUniqueInventory$1(marketplaces, plugins);
|
|
5389
|
+
yield* requireUniqueInventory$1(marketplaces, plugins, mcpServers);
|
|
3505
5390
|
const normalized = Object.freeze({
|
|
3506
5391
|
provider: "claude",
|
|
3507
5392
|
marketplaces: [...marketplaces].sort(byIdentity$1),
|
|
3508
|
-
plugins: [...plugins].sort(bySelector$1)
|
|
5393
|
+
plugins: [...plugins].sort(bySelector$1),
|
|
5394
|
+
mcpServers: [...mcpServers].sort(byMcpName$1),
|
|
5395
|
+
managedMcpServers
|
|
3509
5396
|
});
|
|
3510
5397
|
return Value.Check(NativeProviderInventorySchema, normalized) ? normalized : yield* Effect.fail(providerFailure$1("inventory", "ProtocolFailed", "Claude native inventory contains non-canonical facts"));
|
|
3511
5398
|
});
|
|
@@ -3565,8 +5452,8 @@ function normalizePlugin$1(entry) {
|
|
|
3565
5452
|
root: entry.installPath ?? null
|
|
3566
5453
|
}));
|
|
3567
5454
|
}
|
|
3568
|
-
function requireUniqueInventory$1(marketplaces, plugins) {
|
|
3569
|
-
return new Set(marketplaces.map((entry) => entry.identity)).size === marketplaces.length && new Set(plugins.map((entry) => entry.selector)).size === plugins.length ? Effect.void : Effect.fail(providerFailure$1("inventory", "ProtocolFailed", "Claude native inventory contains duplicate identities"));
|
|
5455
|
+
function requireUniqueInventory$1(marketplaces, plugins, mcpServers) {
|
|
5456
|
+
return new Set(marketplaces.map((entry) => entry.identity)).size === marketplaces.length && new Set(plugins.map((entry) => entry.selector)).size === plugins.length && new Set(mcpServers.map((entry) => entry.name)).size === mcpServers.length ? Effect.void : Effect.fail(providerFailure$1("inventory", "ProtocolFailed", "Claude native inventory contains duplicate identities"));
|
|
3570
5457
|
}
|
|
3571
5458
|
function selectPluginRoot$1(plugins, selector) {
|
|
3572
5459
|
const matches = plugins.filter((entry) => entry.selector === selector && entry.installed);
|
|
@@ -3622,6 +5509,9 @@ function byIdentity$1(left, right) {
|
|
|
3622
5509
|
function bySelector$1(left, right) {
|
|
3623
5510
|
return compareText$4(left.selector, right.selector);
|
|
3624
5511
|
}
|
|
5512
|
+
function byMcpName$1(left, right) {
|
|
5513
|
+
return compareText$4(left.name, right.name);
|
|
5514
|
+
}
|
|
3625
5515
|
function compareText$4(left, right) {
|
|
3626
5516
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
3627
5517
|
}
|
|
@@ -3641,6 +5531,152 @@ function defineNodeClaudeNativeAgentProviderRuntimeProvider() {
|
|
|
3641
5531
|
});
|
|
3642
5532
|
}
|
|
3643
5533
|
//#endregion
|
|
5534
|
+
//#region ../../resources/native-agent-provider/dist/providers/codex-effect-platform-node/mcp.js
|
|
5535
|
+
const MAX_OBSERVED_URL_LENGTH = 4096;
|
|
5536
|
+
/**
|
|
5537
|
+
* Reads and permissively normalizes Codex's offline `<CODEX_HOME>/config.toml` `[mcp_servers]`
|
|
5538
|
+
* table without triggering network-probing `codex mcp list` commands.
|
|
5539
|
+
*/
|
|
5540
|
+
function readCodexLiveMcpServers(kernel, operation, commandPhase = "not-started") {
|
|
5541
|
+
return kernel.readCodexConfigToml(operation, commandPhase).pipe(Effect.flatMap((configToml) => decodeCodexMcpServers(operation, commandPhase, configToml)));
|
|
5542
|
+
}
|
|
5543
|
+
/**
|
|
5544
|
+
* Executes a serialized Codex user-scope HTTP MCP add with write-ahead ledger ownership and
|
|
5545
|
+
* rollback on confirmed absence after a failed command.
|
|
5546
|
+
*/
|
|
5547
|
+
function addCodexMcpServer(kernel, request) {
|
|
5548
|
+
return kernel.serialized("mcp-add", requireMcpServerAddInput("codex", "mcp-add", request).pipe(Effect.flatMap(({ name, url, ownerPluginId }) => Effect.gen(function* () {
|
|
5549
|
+
yield* kernel.sweepTransientMcpLedger("mcp-add", "not-started");
|
|
5550
|
+
const previousLedger = yield* kernel.readManagedMcpLedger("mcp-add");
|
|
5551
|
+
const liveBefore = yield* readCodexLiveMcpServers(kernel, "mcp-add", "not-started");
|
|
5552
|
+
const previousEntry = previousLedger.find((entry) => entry.name === name);
|
|
5553
|
+
const existingLive = liveBefore.find((entry) => entry.name === name);
|
|
5554
|
+
if (existingLive !== void 0 && (previousEntry === void 0 || existingLive.transport !== "http" || existingLive.url !== previousEntry.url)) return yield* Effect.fail(codexMcpFailure("mcp-add", "InvalidInput", "not-started", `Refusing to overwrite unmanaged MCP server ${name}`));
|
|
5555
|
+
const nextLedger = [...previousLedger.filter((entry) => entry.name !== name), Object.freeze({
|
|
5556
|
+
name,
|
|
5557
|
+
url,
|
|
5558
|
+
ownerPluginId
|
|
5559
|
+
})];
|
|
5560
|
+
yield* kernel.writeManagedMcpLedger("mcp-add", nextLedger, "not-started");
|
|
5561
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-add", [
|
|
5562
|
+
"mcp",
|
|
5563
|
+
"add",
|
|
5564
|
+
name,
|
|
5565
|
+
"--url",
|
|
5566
|
+
url
|
|
5567
|
+
]));
|
|
5568
|
+
if (Result.isSuccess(attempt)) return attempt.success;
|
|
5569
|
+
if (attempt.failure.commandPhase === "not-started") return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
5570
|
+
const liveAfterAttempt = yield* Effect.result(readCodexLiveMcpServers(kernel, "mcp-add", attempt.failure.commandPhase));
|
|
5571
|
+
if (Result.isSuccess(liveAfterAttempt)) {
|
|
5572
|
+
const liveAfter = liveAfterAttempt.success.find((entry) => entry.name === name);
|
|
5573
|
+
if (liveAfter === void 0 || liveAfter.transport !== "http" || liveAfter.url !== url) return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
5574
|
+
}
|
|
5575
|
+
return yield* Effect.fail(attempt.failure);
|
|
5576
|
+
}))));
|
|
5577
|
+
}
|
|
5578
|
+
/**
|
|
5579
|
+
* Executes a serialized Codex user-scope MCP removal guarded by exact ledger URL ownership and
|
|
5580
|
+
* prunes orphan ledger records without invoking the native CLI when already absent.
|
|
5581
|
+
*/
|
|
5582
|
+
function removeCodexMcpServer(kernel, request) {
|
|
5583
|
+
return kernel.serialized("mcp-remove", requireMcpServerRemoveInput("codex", "mcp-remove", request).pipe(Effect.flatMap((name) => Effect.gen(function* () {
|
|
5584
|
+
yield* kernel.sweepTransientMcpLedger("mcp-remove", "not-started");
|
|
5585
|
+
const currentLedger = yield* kernel.readManagedMcpLedger("mcp-remove");
|
|
5586
|
+
const liveBefore = yield* readCodexLiveMcpServers(kernel, "mcp-remove", "not-started");
|
|
5587
|
+
const ledgerEntry = currentLedger.find((entry) => entry.name === name);
|
|
5588
|
+
const liveEntry = liveBefore.find((entry) => entry.name === name);
|
|
5589
|
+
if (liveEntry === void 0) {
|
|
5590
|
+
if (ledgerEntry !== void 0) yield* kernel.writeManagedMcpLedger("mcp-remove", currentLedger.filter((entry) => entry.name !== name), "not-started");
|
|
5591
|
+
return Object.freeze({
|
|
5592
|
+
provider: "codex",
|
|
5593
|
+
operation: "mcp-remove",
|
|
5594
|
+
commandPhase: "command-returned"
|
|
5595
|
+
});
|
|
5596
|
+
}
|
|
5597
|
+
if (ledgerEntry === void 0 || liveEntry.transport !== "http" || liveEntry.url !== ledgerEntry.url) return yield* Effect.fail(codexMcpFailure("mcp-remove", "InvalidInput", "not-started", `Refusing to remove unmanaged MCP server ${name}`));
|
|
5598
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-remove", [
|
|
5599
|
+
"mcp",
|
|
5600
|
+
"remove",
|
|
5601
|
+
name
|
|
5602
|
+
]));
|
|
5603
|
+
if (Result.isSuccess(attempt)) {
|
|
5604
|
+
yield* pruneManagedMcpLedgerEntry(kernel, name, "command-returned");
|
|
5605
|
+
return attempt.success;
|
|
5606
|
+
}
|
|
5607
|
+
if (attempt.failure.commandPhase !== "command-returned") return yield* Effect.fail(attempt.failure);
|
|
5608
|
+
const liveAfterAttempt = yield* Effect.result(readCodexLiveMcpServers(kernel, "mcp-remove", "command-returned"));
|
|
5609
|
+
if (Result.isSuccess(liveAfterAttempt) && !liveAfterAttempt.success.some((entry) => entry.name === name)) {
|
|
5610
|
+
yield* pruneManagedMcpLedgerEntry(kernel, name, "command-returned");
|
|
5611
|
+
return Object.freeze({
|
|
5612
|
+
provider: "codex",
|
|
5613
|
+
operation: "mcp-remove",
|
|
5614
|
+
commandPhase: "command-returned"
|
|
5615
|
+
});
|
|
5616
|
+
}
|
|
5617
|
+
return yield* Effect.fail(attempt.failure);
|
|
5618
|
+
}))));
|
|
5619
|
+
}
|
|
5620
|
+
/** Normalizes the MCP table from an already-read Codex user configuration. */
|
|
5621
|
+
function decodeCodexMcpServers(operation, commandPhase, configToml) {
|
|
5622
|
+
if (configToml === null) return Effect.succeed(Object.freeze([]));
|
|
5623
|
+
if (!isPlainRecord(configToml)) return Effect.fail(codexMcpFailure(operation, "ProtocolFailed", commandPhase, "Codex config.toml top-level value must be a TOML table"));
|
|
5624
|
+
const rawServers = Reflect.get(configToml, "mcp_servers");
|
|
5625
|
+
if (rawServers === void 0 || rawServers === null) return Effect.succeed(Object.freeze([]));
|
|
5626
|
+
if (!isPlainRecord(rawServers)) return Effect.fail(codexMcpFailure(operation, "ProtocolFailed", commandPhase, "Codex config.toml mcp_servers must be a TOML table"));
|
|
5627
|
+
const entries = Object.entries(rawServers).filter(([name]) => Value.Check(ObservedMcpServerNameSchema, name));
|
|
5628
|
+
if (entries.length > 1024) return Effect.fail(codexMcpFailure(operation, "LimitExceeded", commandPhase, "Codex config.toml MCP server count exceeds the resource limit"));
|
|
5629
|
+
return Effect.succeed(Object.freeze(entries.map(([name, entry]) => normalizeCodexMcpServer(name, entry))));
|
|
5630
|
+
}
|
|
5631
|
+
function normalizeCodexMcpServer(name, entry) {
|
|
5632
|
+
if (!isPlainRecord(entry)) return Object.freeze({
|
|
5633
|
+
name,
|
|
5634
|
+
transport: "other",
|
|
5635
|
+
url: null,
|
|
5636
|
+
enabled: true
|
|
5637
|
+
});
|
|
5638
|
+
const rawEnabled = Reflect.get(entry, "enabled");
|
|
5639
|
+
const hasValidEnabled = rawEnabled === void 0 || typeof rawEnabled === "boolean";
|
|
5640
|
+
const enabled = typeof rawEnabled === "boolean" ? rawEnabled : true;
|
|
5641
|
+
const rawCommand = Reflect.get(entry, "command");
|
|
5642
|
+
const rawUrl = Reflect.get(entry, "url");
|
|
5643
|
+
const validUrl = typeof rawUrl === "string" && rawUrl.length > 0 && rawUrl.length <= MAX_OBSERVED_URL_LENGTH ? rawUrl : null;
|
|
5644
|
+
if (rawCommand === void 0 && validUrl !== null && hasValidEnabled) return Object.freeze({
|
|
5645
|
+
name,
|
|
5646
|
+
transport: "http",
|
|
5647
|
+
url: validUrl,
|
|
5648
|
+
enabled
|
|
5649
|
+
});
|
|
5650
|
+
return Object.freeze({
|
|
5651
|
+
name,
|
|
5652
|
+
transport: "other",
|
|
5653
|
+
url: null,
|
|
5654
|
+
enabled
|
|
5655
|
+
});
|
|
5656
|
+
}
|
|
5657
|
+
function pruneManagedMcpLedgerEntry(kernel, name, commandPhase) {
|
|
5658
|
+
return kernel.readManagedMcpLedger("mcp-remove").pipe(Effect.mapError((error) => error.commandPhase === commandPhase ? error : Object.freeze({
|
|
5659
|
+
...error,
|
|
5660
|
+
commandPhase
|
|
5661
|
+
})), Effect.flatMap((current) => {
|
|
5662
|
+
const next = current.filter((entry) => entry.name !== name);
|
|
5663
|
+
return next.length === current.length ? Effect.void : kernel.writeManagedMcpLedger("mcp-remove", next, commandPhase);
|
|
5664
|
+
}));
|
|
5665
|
+
}
|
|
5666
|
+
function isPlainRecord(value) {
|
|
5667
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5668
|
+
}
|
|
5669
|
+
function codexMcpFailure(operation, reason, commandPhase, detail) {
|
|
5670
|
+
return Object.freeze({
|
|
5671
|
+
_tag: "NativeAgentProviderFailure",
|
|
5672
|
+
provider: "codex",
|
|
5673
|
+
operation,
|
|
5674
|
+
reason,
|
|
5675
|
+
commandPhase,
|
|
5676
|
+
detail
|
|
5677
|
+
});
|
|
5678
|
+
}
|
|
5679
|
+
//#endregion
|
|
3644
5680
|
//#region ../../resources/native-agent-provider/dist/providers/codex-effect-platform-node/index.js
|
|
3645
5681
|
const NullableStringSchema = Type.Union([Type.String(), Type.Null()]);
|
|
3646
5682
|
const CodexMarketplaceSourceSchema = Type.Union([Type.Object({
|
|
@@ -3666,7 +5702,10 @@ const CODEX_CAPABILITIES = [
|
|
|
3666
5702
|
"marketplace-remove",
|
|
3667
5703
|
"plugin-list",
|
|
3668
5704
|
"plugin-install",
|
|
3669
|
-
"plugin-remove"
|
|
5705
|
+
"plugin-remove",
|
|
5706
|
+
"mcp-list",
|
|
5707
|
+
"mcp-add",
|
|
5708
|
+
"mcp-remove"
|
|
3670
5709
|
];
|
|
3671
5710
|
/**
|
|
3672
5711
|
* Constructs the platform-requiring Codex provider without choosing a runtime.
|
|
@@ -3683,14 +5722,13 @@ function makeCodexEffectPlatformNodeProvider(options = {}) {
|
|
|
3683
5722
|
capabilities: [...CODEX_CAPABILITIES]
|
|
3684
5723
|
});
|
|
3685
5724
|
}));
|
|
3686
|
-
const
|
|
3687
|
-
const inventory = () => kernel.serialized("inventory", readInventory());
|
|
5725
|
+
const inventory = (inventoryOptions) => kernel.serialized("inventory", requireInventoryOptions("codex", inventoryOptions).pipe(Effect.flatMap((normalized) => codexInventory(kernel, normalized))));
|
|
3688
5726
|
return Object.freeze({
|
|
3689
5727
|
provider: "codex",
|
|
3690
5728
|
home: kernel.home,
|
|
3691
5729
|
probe,
|
|
3692
5730
|
inventory,
|
|
3693
|
-
readPluginFiles: (request) => kernel.serialized("plugin-files-read", requirePluginFilesReadInput("codex", "plugin-files-read", request).pipe(Effect.flatMap((validated) =>
|
|
5731
|
+
readPluginFiles: (request) => kernel.serialized("plugin-files-read", requirePluginFilesReadInput("codex", "plugin-files-read", request).pipe(Effect.flatMap((validated) => codexInstalledPlugins(kernel).pipe(Effect.flatMap((plugins) => selectPluginRoot(kernel, plugins, validated.selector).pipe(Effect.flatMap((root) => Effect.forEach(validated.files, (file) => kernel.readPluginEntry("plugin-files-read", root, file).pipe(Effect.catchIf((error) => error.reason === "Missing" || error.reason === "LimitExceeded", (error) => {
|
|
3694
5732
|
const missing = Object.freeze({
|
|
3695
5733
|
kind: error.reason === "Missing" ? "Missing" : "TooLarge",
|
|
3696
5734
|
relativePath: file.relativePath
|
|
@@ -3716,12 +5754,14 @@ function makeCodexEffectPlatformNodeProvider(options = {}) {
|
|
|
3716
5754
|
selector,
|
|
3717
5755
|
"--json"
|
|
3718
5756
|
])))),
|
|
3719
|
-
removePlugin: (request) => kernel.serialized("plugin-remove", requirePluginSelectorInput("codex", "plugin-remove", request).pipe(Effect.flatMap((selector) => kernel.mutation("plugin-remove", [
|
|
5757
|
+
removePlugin: (request) => kernel.serialized("plugin-remove", requirePluginSelectorInput("codex", "plugin-remove", request).pipe(Effect.flatMap((selector) => CODEX_PLUGIN_NAME.test(selector.slice(0, selector.indexOf("@"))) ? kernel.mutation("plugin-remove", [
|
|
3720
5758
|
"plugin",
|
|
3721
5759
|
"remove",
|
|
3722
5760
|
selector,
|
|
3723
5761
|
"--json"
|
|
3724
|
-
]))))
|
|
5762
|
+
]) : Effect.fail(providerFailure("plugin-remove", "InvalidInput", "Codex plugin name is invalid", "not-started"))))),
|
|
5763
|
+
addMcpServer: (request) => addCodexMcpServer(kernel, request),
|
|
5764
|
+
removeMcpServer: (request) => removeCodexMcpServer(kernel, request)
|
|
3725
5765
|
});
|
|
3726
5766
|
})) });
|
|
3727
5767
|
}
|
|
@@ -3733,7 +5773,28 @@ function makeNodeCodexNativeAgentProviderResource(options = {}) {
|
|
|
3733
5773
|
const provider = makeCodexEffectPlatformNodeProvider(options);
|
|
3734
5774
|
return Object.freeze({ acquire: (input) => provider.acquire(input).pipe(Effect.provide(NodeServices.layer)) });
|
|
3735
5775
|
}
|
|
3736
|
-
function
|
|
5776
|
+
function codexInstalledPlugins(kernel) {
|
|
5777
|
+
return Effect.gen(function* () {
|
|
5778
|
+
const marketplaceOutput = yield* kernel.run("inventory", [
|
|
5779
|
+
"plugin",
|
|
5780
|
+
"marketplace",
|
|
5781
|
+
"list",
|
|
5782
|
+
"--json"
|
|
5783
|
+
]);
|
|
5784
|
+
const pluginOutput = yield* kernel.run("inventory", [
|
|
5785
|
+
"plugin",
|
|
5786
|
+
"list",
|
|
5787
|
+
"--json"
|
|
5788
|
+
]);
|
|
5789
|
+
const marketplaceRecord = yield* decodeProviderJson("codex", "inventory", CodexMarketplaceListSchema, marketplaceOutput.stdout);
|
|
5790
|
+
const pluginRecord = yield* decodeProviderJson("codex", "inventory", CodexPluginListSchema, pluginOutput.stdout);
|
|
5791
|
+
const marketplaces = yield* Effect.forEach(marketplaceRecord.marketplaces, normalizeMarketplace, { concurrency: 1 });
|
|
5792
|
+
const plugins = yield* Effect.forEach(pluginRecord.installed, normalizePlugin, { concurrency: 1 });
|
|
5793
|
+
yield* requireUniqueInventory(marketplaces, plugins, []);
|
|
5794
|
+
return Object.freeze([...plugins].sort(bySelector));
|
|
5795
|
+
});
|
|
5796
|
+
}
|
|
5797
|
+
function codexInventory(kernel, options) {
|
|
3737
5798
|
return Effect.gen(function* () {
|
|
3738
5799
|
const marketplaceOutput = yield* kernel.run("inventory", [
|
|
3739
5800
|
"plugin",
|
|
@@ -3746,19 +5807,51 @@ function codexInventory(kernel) {
|
|
|
3746
5807
|
"list",
|
|
3747
5808
|
"--json"
|
|
3748
5809
|
]);
|
|
5810
|
+
const managedMcpServers = yield* kernel.readManagedMcpLedger("inventory");
|
|
5811
|
+
const shouldObserveMcp = shouldObserveProviderMcpConfig(options, managedMcpServers);
|
|
5812
|
+
const pluginConfigMarketplace = options.observePluginConfigForMarketplace;
|
|
5813
|
+
const configToml = shouldObserveMcp || pluginConfigMarketplace !== void 0 ? yield* kernel.readCodexConfigToml("inventory") : null;
|
|
5814
|
+
const mcpServers = shouldObserveMcp ? yield* decodeCodexMcpServers("inventory", "not-started", configToml) : Object.freeze([]);
|
|
5815
|
+
const pluginConfig = pluginConfigMarketplace === void 0 ? void 0 : yield* decodeCodexPluginConfig(pluginConfigMarketplace, configToml);
|
|
3749
5816
|
const marketplaceRecord = yield* decodeProviderJson("codex", "inventory", CodexMarketplaceListSchema, marketplaceOutput.stdout);
|
|
3750
5817
|
const pluginRecord = yield* decodeProviderJson("codex", "inventory", CodexPluginListSchema, pluginOutput.stdout);
|
|
3751
5818
|
const marketplaces = yield* Effect.forEach(marketplaceRecord.marketplaces, normalizeMarketplace, { concurrency: 1 });
|
|
3752
5819
|
const plugins = yield* Effect.forEach(pluginRecord.installed, normalizePlugin, { concurrency: 1 });
|
|
3753
|
-
yield* requireUniqueInventory(marketplaces, plugins);
|
|
5820
|
+
yield* requireUniqueInventory(marketplaces, plugins, mcpServers);
|
|
3754
5821
|
const normalized = Object.freeze({
|
|
3755
5822
|
provider: "codex",
|
|
3756
5823
|
marketplaces: [...marketplaces].sort(byIdentity),
|
|
3757
|
-
plugins: [...plugins].sort(bySelector)
|
|
5824
|
+
plugins: [...plugins].sort(bySelector),
|
|
5825
|
+
...pluginConfig === void 0 ? {} : { pluginConfig },
|
|
5826
|
+
mcpServers: [...mcpServers].sort(byMcpName),
|
|
5827
|
+
managedMcpServers
|
|
3758
5828
|
});
|
|
3759
5829
|
return Value.Check(NativeProviderInventorySchema, normalized) ? normalized : yield* Effect.fail(providerFailure("inventory", "ProtocolFailed", "Codex native inventory contains non-canonical facts"));
|
|
3760
5830
|
});
|
|
3761
5831
|
}
|
|
5832
|
+
const CODEX_PLUGIN_NAME = /^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/u;
|
|
5833
|
+
const CodexConfigTableSchema = Type.Record(Type.String(), Type.Unknown());
|
|
5834
|
+
const CodexPluginConfigEntrySchema = Type.Object({ enabled: Type.Optional(Type.Boolean()) });
|
|
5835
|
+
function decodeCodexPluginConfig(marketplaceIdentity, configToml) {
|
|
5836
|
+
return Effect.gen(function* () {
|
|
5837
|
+
if (configToml !== null && !Value.Check(CodexConfigTableSchema, configToml)) return yield* Effect.fail(providerFailure("inventory", "ProtocolFailed", "Codex config.toml must be a TOML table"));
|
|
5838
|
+
const plugins = configToml?.plugins;
|
|
5839
|
+
if (plugins !== void 0 && !Value.Check(CodexConfigTableSchema, plugins)) return yield* Effect.fail(providerFailure("inventory", "ProtocolFailed", "Codex config.toml plugins must be a TOML table"));
|
|
5840
|
+
const configuredPlugins = plugins ?? {};
|
|
5841
|
+
const selectors = [];
|
|
5842
|
+
for (const selector of Object.keys(configuredPlugins)) {
|
|
5843
|
+
const delimiter = selector.indexOf("@");
|
|
5844
|
+
if (delimiter < 0 || selector.slice(delimiter + 1) !== marketplaceIdentity || !CODEX_PLUGIN_NAME.test(selector.slice(0, delimiter))) continue;
|
|
5845
|
+
if (!Value.Check(CodexPluginConfigEntrySchema, configuredPlugins[selector])) return yield* Effect.fail(providerFailure("inventory", "ProtocolFailed", "Codex config.toml contains an invalid plugin entry in the requested marketplace"));
|
|
5846
|
+
if (selectors.length === 4096) return yield* Effect.fail(providerFailure("inventory", "LimitExceeded", "Codex config.toml plugin selector count exceeds the resource limit"));
|
|
5847
|
+
selectors.push(selector);
|
|
5848
|
+
}
|
|
5849
|
+
return Object.freeze({
|
|
5850
|
+
marketplaceIdentity,
|
|
5851
|
+
selectors: selectors.sort(compareText$3)
|
|
5852
|
+
});
|
|
5853
|
+
});
|
|
5854
|
+
}
|
|
3762
5855
|
function normalizeMarketplace(entry) {
|
|
3763
5856
|
const nativeSource = entry.marketplaceSource;
|
|
3764
5857
|
if (nativeSource === null || nativeSource === void 0) return Effect.succeed(Object.freeze({
|
|
@@ -3792,8 +5885,8 @@ function normalizePlugin(entry) {
|
|
|
3792
5885
|
root: null
|
|
3793
5886
|
})) : Effect.fail(providerFailure("inventory", "ProtocolFailed", "Codex plugin identity fields do not describe one selector"));
|
|
3794
5887
|
}
|
|
3795
|
-
function requireUniqueInventory(marketplaces, plugins) {
|
|
3796
|
-
return new Set(marketplaces.map((entry) => entry.identity)).size === marketplaces.length && new Set(plugins.map((entry) => entry.selector)).size === plugins.length ? Effect.void : Effect.fail(providerFailure("inventory", "ProtocolFailed", "Codex native inventory contains duplicate identities"));
|
|
5888
|
+
function requireUniqueInventory(marketplaces, plugins, mcpServers) {
|
|
5889
|
+
return new Set(marketplaces.map((entry) => entry.identity)).size === marketplaces.length && new Set(plugins.map((entry) => entry.selector)).size === plugins.length && new Set(mcpServers.map((entry) => entry.name)).size === mcpServers.length ? Effect.void : Effect.fail(providerFailure("inventory", "ProtocolFailed", "Codex native inventory contains duplicate identities"));
|
|
3797
5890
|
}
|
|
3798
5891
|
function selectPluginRoot(kernel, plugins, selector) {
|
|
3799
5892
|
const matches = plugins.filter((entry) => entry.selector === selector && entry.installed);
|
|
@@ -3825,13 +5918,13 @@ function requireVersion(stdout) {
|
|
|
3825
5918
|
const version = stdout.trim();
|
|
3826
5919
|
return version.length > 0 && version.length <= 4096 ? Effect.succeed(version) : Effect.fail(providerFailure("probe", "ProtocolFailed", "Codex version output is empty or oversized"));
|
|
3827
5920
|
}
|
|
3828
|
-
function providerFailure(operation, reason, detail) {
|
|
5921
|
+
function providerFailure(operation, reason, detail, commandPhase = "command-returned") {
|
|
3829
5922
|
return Object.freeze({
|
|
3830
5923
|
_tag: "NativeAgentProviderFailure",
|
|
3831
5924
|
provider: "codex",
|
|
3832
5925
|
operation,
|
|
3833
5926
|
reason,
|
|
3834
|
-
commandPhase
|
|
5927
|
+
commandPhase,
|
|
3835
5928
|
detail
|
|
3836
5929
|
});
|
|
3837
5930
|
}
|
|
@@ -3841,6 +5934,9 @@ function byIdentity(left, right) {
|
|
|
3841
5934
|
function bySelector(left, right) {
|
|
3842
5935
|
return compareText$3(left.selector, right.selector);
|
|
3843
5936
|
}
|
|
5937
|
+
function byMcpName(left, right) {
|
|
5938
|
+
return compareText$3(left.name, right.name);
|
|
5939
|
+
}
|
|
3844
5940
|
function compareText$3(left, right) {
|
|
3845
5941
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
3846
5942
|
}
|
|
@@ -4692,6 +6788,10 @@ const localProfile = defineRuntimeProfile({
|
|
|
4692
6788
|
resource: ClaudeNativeAgentProviderRuntimeResource,
|
|
4693
6789
|
provider: defineNodeClaudeNativeAgentProviderRuntimeProvider()
|
|
4694
6790
|
}),
|
|
6791
|
+
providerSelection({
|
|
6792
|
+
resource: AntigravityNativeAgentProviderRuntimeResource,
|
|
6793
|
+
provider: defineNodeAntigravityNativeAgentProviderRuntimeProvider()
|
|
6794
|
+
}),
|
|
4695
6795
|
providerSelection({
|
|
4696
6796
|
resource: FilesystemRuntimeResource,
|
|
4697
6797
|
provider: defineNodeFilesystemRuntimeProvider()
|