@habitat-ai/cli 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/dist/{application-gZ8XAszE.js → application-fyrwZzvC.js} +3 -3
- package/dist/application.js +1 -1
- package/dist/{cli-hhbbymEz.js → cli-B3N248Jk.js} +2451 -363
- package/dist/cli.js +1 -1
- package/dist/generators/cli-command.js +1 -1
- package/dist/generators/service.js +2 -2
- package/dist/{habitat.app-Cl-58zQB.js → habitat.app-B8eGl9YJ.js} +1990 -319
- package/dist/habitat.app.js +1 -1
- package/dist/index.js +1 -1
- package/dist/nx-plugin.js +12 -6
- package/dist/{oclif-CJS8CHjO.js → oclif-fzwqfE6X.js} +1 -1
- package/dist/oclif.js +1 -1
- package/generators/service/files/AGENTS.md.template +3 -0
- package/generators/service/files/habitat.toml.template +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +7 -7
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as AgentPluginPackageOutputRuntimeResource, B as RuleEvaluationRuntimeResource, C as PluginVersionSchema, D as ClaudeNativeAgentProviderRuntimeResource, E as AntigravityNativeAgentProviderRuntimeResource, F as SourceInventoryResultSchema, L as MAX_RULE_EVALUATION_FAILURE_DETAIL, M as MAX_SOURCE_INVENTORY_ROOT_LENGTH, N as ObserveSourceInventoryInputSchema, O as CodexNativeAgentProviderRuntimeResource, P as SourceInventoryPathSchema, R as RuleEvaluationRequestSchema, S as ObservedMcpServerNameSchema, T as VersionedContentRuntimeResource, V as FilesystemRuntimeResource, _ as NativeProviderMcpServerAddInputSchema, a as MaterializeRemoteInputSchema, b as NativeProviderPluginSelectorInputSchema, c as CanonicalGitRepositoryUrlSchema, f as NativeManagedMcpServerRecordSchema, g as NativeProviderMarketplaceIdentityInputSchema, h as NativeProviderInventorySchema, i as MAX_VERSIONED_CONTENT_FAILURE_DETAIL, j as MAX_SOURCE_INVENTORY_FAILURE_DETAIL, k as ContentWorkspaceRuntimeResource, l as MAX_NATIVE_PROVIDER_MCP_SERVERS, m as NativeProviderInventoryOptionsSchema, n as ChildProcessRuntimeResource, o as ObserveRemoteInputSchema, p as NativeMarketplaceSourceSchema, r as AncestryInputSchema, s as VersionedContentTreeEntrySchema, t as habitatApp, v as NativeProviderMcpServerRemoveInputSchema, w as projectAntigravityPluginBundle, x as NativeProviderSessionInputSchema, y as NativeProviderPluginFilesReadInputSchema, z as SourceInventoryRuntimeResource } from "./habitat.app-B8eGl9YJ.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";
|
|
12
|
-
import { ChildProcess, ChildProcessSpawner } from "effect/
|
|
13
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
13
14
|
import { TelemetryRuntimeResource, defineOpenTelemetryNodeRuntimeProvider } from "@habitat-ai/sdk/telemetry";
|
|
14
15
|
import { defineRuntimeProvider } from "@habitat-ai/sdk/runtime/providers";
|
|
15
16
|
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,17 +1111,17 @@ 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
|
-
if (canonical !== filePath || info.type !== "File" || info.dev !== parent.dev || ino === void 0 || nlink !==
|
|
1118
|
-
const bytes = yield* fs.readFile(filePath).pipe(mapPlatform$
|
|
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");
|
|
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$
|
|
1121
|
-
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) !==
|
|
1123
|
+
const after = yield* fs.stat(filePath).pipe(mapPlatform$6("publish-output", reason, `${phase}-revalidation`, filePath));
|
|
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,
|
|
1124
1127
|
dev: info.dev,
|
|
@@ -1143,14 +1146,14 @@ 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
|
-
if (fileInfo.type !== "File" || fileInfo.dev !== parent.dev || ino === void 0 || Option.getOrUndefined(fileInfo.nlink) !==
|
|
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({
|
|
1155
1158
|
parent,
|
|
1156
1159
|
path: temporaryPath,
|
|
@@ -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,15 +1178,15 @@ 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$
|
|
1179
|
-
if (canonical !== owned.path || info.type !== "File" || info.dev !== owned.dev || Option.getOrUndefined(info.ino) !== owned.ino || Option.getOrUndefined(info.nlink) !== expectedLinks) return yield* rejected(operation, "TemporaryFailed", "temporary-revalidation", owned.path, "Owned temporary identity changed");
|
|
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))]);
|
|
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
|
-
if (canonical !== created.path || info.type !== "File" || info.dev !== created.parent.dev || ino === void 0 || Option.getOrUndefined(info.nlink) !==
|
|
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({
|
|
1188
1191
|
parent: created.parent,
|
|
1189
1192
|
path: created.path,
|
|
@@ -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,31 +1710,34 @@ 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
|
-
return yield* Effect.
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
yield*
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1720
|
+
return yield* Effect.uninterruptibleMask((restore) => Effect.gen(function* () {
|
|
1721
|
+
const stage = yield* fs.makeTempDirectory({
|
|
1722
|
+
directory: parent,
|
|
1723
|
+
prefix: CONTENT_TREE_STAGE_PREFIX
|
|
1724
|
+
}).pipe(mapPlatform$5("materialize-content-tree", parent));
|
|
1725
|
+
const attempted = yield* Effect.exit(restore(Effect.gen(function* () {
|
|
1726
|
+
yield* requireContentTreeStage(fs, parent, stage);
|
|
1727
|
+
yield* populateContentTree(fs, stage, input);
|
|
1728
|
+
yield* cutOverContentTree(fs, parent, root, stage, present);
|
|
1729
|
+
})));
|
|
1730
|
+
if (Exit.isSuccess(attempted)) return Object.freeze({ root });
|
|
1731
|
+
const cleaned = yield* Effect.exit(cleanupContentTreeStage(fs, parent, stage));
|
|
1732
|
+
const cause = Exit.isFailure(cleaned) ? Cause.combine(attempted.cause, cleaned.cause) : attempted.cause;
|
|
1733
|
+
return yield* Effect.failCause(cause);
|
|
1734
|
+
}));
|
|
1729
1735
|
});
|
|
1730
1736
|
const capture = Effect.fn("contentWorkspace.capture")(function* (input) {
|
|
1731
1737
|
const fs = yield* FileSystem.FileSystem;
|
|
1732
1738
|
const root = yield* requireCanonicalRoot(fs, input.root, "capture");
|
|
1733
1739
|
yield* requireGitWorkspaceRoot(gitExecutable, root, "capture");
|
|
1734
|
-
const rootIdentity = yield* fs.stat(root).pipe(mapPlatform$
|
|
1740
|
+
const rootIdentity = yield* fs.stat(root).pipe(mapPlatform$5("capture", root));
|
|
1735
1741
|
yield* checked("capture", () => {
|
|
1736
1742
|
validateOpaque(input.readToken, "readToken", "capture");
|
|
1737
1743
|
validateLimits(input.maxEntries, input.maxBytes, "capture");
|
|
@@ -1740,7 +1746,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1740
1746
|
const budget = makeCaptureBudget(input);
|
|
1741
1747
|
const paths = yield* Effect.forEach(input.paths, (relative) => Effect.gen(function* () {
|
|
1742
1748
|
const candidate = yield* checked("capture", () => resolveContained(root, relative, false, "capture"));
|
|
1743
|
-
if (!(yield* fs.exists(candidate).pipe(mapPlatform$
|
|
1749
|
+
if (!(yield* fs.exists(candidate).pipe(mapPlatform$5("capture", candidate)))) return Object.freeze({
|
|
1744
1750
|
path: relative,
|
|
1745
1751
|
entries: null
|
|
1746
1752
|
});
|
|
@@ -1784,19 +1790,19 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1784
1790
|
validateOpaque(input.captureHandle, "captureHandle", "apply");
|
|
1785
1791
|
});
|
|
1786
1792
|
const authority = yield* requireCaptureAuthority(fs, captureAuthorities, consumedHandles, input.captureHandle, root, input.readToken, input.planDigest, "apply");
|
|
1787
|
-
if (authority.lifecycle === "Partial" || authority.lifecycle === "Applying" || authority.lifecycle === "Restoring") return yield* fail$
|
|
1788
|
-
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");
|
|
1789
1795
|
yield* validateWriteSet(root, authority, input.writes);
|
|
1790
1796
|
if ((yield* Effect.forEach(input.writes, (write) => writeIsExact(fs, root, write, makeCaptureBudget(authority)))).every(Boolean)) {
|
|
1791
1797
|
authority.planDigest = input.planDigest;
|
|
1792
1798
|
authority.lifecycle = authority.lifecycle === "Applied" ? "Applied" : "Converged";
|
|
1793
1799
|
return receipt(input.planDigest, input.readToken, "Converged", []);
|
|
1794
1800
|
}
|
|
1795
|
-
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}`);
|
|
1796
1802
|
for (const write of input.writes) {
|
|
1797
1803
|
const expected = authority.preimages.get(write.path);
|
|
1798
|
-
if (expected === void 0) return yield* fail$
|
|
1799
|
-
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");
|
|
1800
1806
|
}
|
|
1801
1807
|
authority.planDigest = input.planDigest;
|
|
1802
1808
|
authority.lifecycle = "Applying";
|
|
@@ -1805,11 +1811,11 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1805
1811
|
const expected = authority.preimages.get(write.path);
|
|
1806
1812
|
if (expected === void 0) {
|
|
1807
1813
|
authority.lifecycle = "Partial";
|
|
1808
|
-
return yield* fail$
|
|
1814
|
+
return yield* fail$5("apply", "InvalidInput", write.path, "Write path lost its captured preimage");
|
|
1809
1815
|
}
|
|
1810
1816
|
if (!equalPreimage(yield* observePreimage(fs, root, write.path, "apply", makeCaptureBudget(authority)), expected)) {
|
|
1811
1817
|
authority.lifecycle = "Partial";
|
|
1812
|
-
return yield* fail$
|
|
1818
|
+
return yield* fail$5("apply", "IdentityChanged", write.path, "Write path changed immediately before mutation");
|
|
1813
1819
|
}
|
|
1814
1820
|
authority.mutatedPaths.add(write.path);
|
|
1815
1821
|
const applied = yield* Effect.result(applyWrite(fs, root, write, makeCaptureBudget(authority)));
|
|
@@ -1839,12 +1845,12 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1839
1845
|
authority.lifecycle = "Restored";
|
|
1840
1846
|
return receipt(input.planDigest, input.readToken, "Restored", []);
|
|
1841
1847
|
}
|
|
1842
|
-
if (authority.lifecycle !== "Applied" && authority.lifecycle !== "Partial") return yield* fail$
|
|
1843
|
-
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");
|
|
1844
1850
|
for (const relative of authority.paths) {
|
|
1845
1851
|
const preimage = authority.preimages.get(relative);
|
|
1846
1852
|
const postimage = authority.postimages.get(relative);
|
|
1847
|
-
if (preimage === void 0) return yield* fail$
|
|
1853
|
+
if (preimage === void 0) return yield* fail$5("restore", "HandleState", relative, "Capture evidence is incomplete");
|
|
1848
1854
|
const current = yield* observePreimage(fs, root, relative, "restore", makeCaptureBudget(authority));
|
|
1849
1855
|
if (equalPreimage(current, preimage)) {
|
|
1850
1856
|
if (authority.mutatedPaths.has(relative)) authority.restoredPaths.add(relative);
|
|
@@ -1852,7 +1858,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1852
1858
|
}
|
|
1853
1859
|
if (postimage === void 0 || !equalPreimage(current, postimage)) {
|
|
1854
1860
|
authority.lifecycle = "Partial";
|
|
1855
|
-
return yield* fail$
|
|
1861
|
+
return yield* fail$5("restore", "IdentityChanged", relative, "Path changed after apply; restore refused");
|
|
1856
1862
|
}
|
|
1857
1863
|
}
|
|
1858
1864
|
authority.lifecycle = "Restoring";
|
|
@@ -1863,7 +1869,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1863
1869
|
const postimage = authority.postimages.get(relative);
|
|
1864
1870
|
if (preimage === void 0 || postimage === void 0) {
|
|
1865
1871
|
authority.lifecycle = "Partial";
|
|
1866
|
-
return yield* fail$
|
|
1872
|
+
return yield* fail$5("restore", "HandleState", relative, "Restore evidence is incomplete");
|
|
1867
1873
|
}
|
|
1868
1874
|
const immediate = yield* observePreimage(fs, root, relative, "restore", makeCaptureBudget(authority));
|
|
1869
1875
|
if (equalPreimage(immediate, preimage)) {
|
|
@@ -1872,7 +1878,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1872
1878
|
}
|
|
1873
1879
|
if (!equalPreimage(immediate, postimage)) {
|
|
1874
1880
|
authority.lifecycle = "Partial";
|
|
1875
|
-
return yield* fail$
|
|
1881
|
+
return yield* fail$5("restore", "IdentityChanged", relative, "Path changed immediately before restore");
|
|
1876
1882
|
}
|
|
1877
1883
|
const restoredPath = yield* Effect.result(restorePreimage(fs, root, preimage, makeCaptureBudget(authority)));
|
|
1878
1884
|
if (restoredPath._tag === "Failure") {
|
|
@@ -1884,7 +1890,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1884
1890
|
}
|
|
1885
1891
|
if (!equalPreimage(yield* observePreimage(fs, root, relative, "restore", makeCaptureBudget(authority)), preimage)) {
|
|
1886
1892
|
authority.lifecycle = "Partial";
|
|
1887
|
-
return yield* fail$
|
|
1893
|
+
return yield* fail$5("restore", "IdentityChanged", relative, "Restored path did not match its captured preimage");
|
|
1888
1894
|
}
|
|
1889
1895
|
authority.restoredPaths.add(relative);
|
|
1890
1896
|
authority.postimages.set(relative, preimage);
|
|
@@ -1903,7 +1909,7 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1903
1909
|
validateOpaque(input.captureHandle, "captureHandle", "settle");
|
|
1904
1910
|
});
|
|
1905
1911
|
const authority = yield* requireCaptureAuthority(fs, captureAuthorities, consumedHandles, input.captureHandle, root, input.readToken, input.planDigest, "settle");
|
|
1906
|
-
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}`);
|
|
1907
1913
|
captureAuthorities.delete(input.captureHandle);
|
|
1908
1914
|
consumedHandles.add(input.captureHandle);
|
|
1909
1915
|
return Object.freeze({
|
|
@@ -1924,8 +1930,8 @@ function makeContentWorkspaceResource(options = {}) {
|
|
|
1924
1930
|
const authority = yield* requireCaptureAuthority(fs, captureAuthorities, consumedHandles, input.captureHandle, root, input.readToken, void 0, "release");
|
|
1925
1931
|
const noMutation = authority.lifecycle === "Captured" || authority.lifecycle === "Converged";
|
|
1926
1932
|
const unsettled = authority.lifecycle === "Partial" || authority.lifecycle === "Applying" || authority.lifecycle === "Restoring";
|
|
1927
|
-
if (input.disposition === "NoMutation" && !noMutation) return yield* fail$
|
|
1928
|
-
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}`);
|
|
1929
1935
|
captureAuthorities.delete(input.captureHandle);
|
|
1930
1936
|
consumedHandles.add(input.captureHandle);
|
|
1931
1937
|
return Object.freeze({
|
|
@@ -1995,22 +2001,22 @@ function readLocalTree(fs, root, objectFormat, maxEntries, maxBytes) {
|
|
|
1995
2001
|
let bytesRead = 0;
|
|
1996
2002
|
const walk = (directory, relative) => Effect.gen(function* () {
|
|
1997
2003
|
yield* requireExactExistingPath(fs, directory, "read-tree");
|
|
1998
|
-
if ((yield* fs.stat(directory).pipe(mapPlatform$
|
|
1999
|
-
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);
|
|
2000
2006
|
for (const name of names) {
|
|
2001
2007
|
const childRelative = relative === "" ? name : `${relative}/${name}`;
|
|
2002
2008
|
yield* checked("read-tree", () => validateRelativePath(childRelative, false, "read-tree"));
|
|
2003
2009
|
const child = path.join(directory, name);
|
|
2004
2010
|
yield* requireExactExistingPath(fs, child, "read-tree");
|
|
2005
|
-
const childInfo = yield* fs.stat(child).pipe(mapPlatform$
|
|
2011
|
+
const childInfo = yield* fs.stat(child).pipe(mapPlatform$5("read-tree", child));
|
|
2006
2012
|
if (childInfo.type === "Directory") {
|
|
2007
2013
|
yield* walk(child, childRelative);
|
|
2008
2014
|
continue;
|
|
2009
2015
|
}
|
|
2010
|
-
if (childInfo.type !== "File") return yield* fail$
|
|
2011
|
-
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");
|
|
2012
2018
|
const remaining = maxBytes - bytesRead;
|
|
2013
|
-
if (remaining < 0) return yield* fail$
|
|
2019
|
+
if (remaining < 0) return yield* fail$5("read-tree", "LimitExceeded", childRelative, "Content tree exceeds maxBytes");
|
|
2014
2020
|
const bytes = yield* readBoundedRegularFile(fs, child, remaining, "read-tree");
|
|
2015
2021
|
bytesRead += bytes.byteLength;
|
|
2016
2022
|
entries.push(Object.freeze({
|
|
@@ -2020,18 +2026,18 @@ function readLocalTree(fs, root, objectFormat, maxEntries, maxBytes) {
|
|
|
2020
2026
|
}));
|
|
2021
2027
|
}
|
|
2022
2028
|
});
|
|
2023
|
-
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)))));
|
|
2024
2030
|
}
|
|
2025
2031
|
function captureTree(fs, root, operation, budget) {
|
|
2026
2032
|
const entries = [];
|
|
2027
2033
|
const walk = (candidate, relative) => Effect.gen(function* () {
|
|
2028
2034
|
yield* requireExactExistingPath(fs, candidate, operation);
|
|
2029
|
-
const info = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2030
|
-
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");
|
|
2031
2037
|
budget.entries += 1;
|
|
2032
2038
|
if (info.type === "File") {
|
|
2033
2039
|
const remaining = budget.maxBytes - budget.bytes;
|
|
2034
|
-
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");
|
|
2035
2041
|
const bytes = yield* readBoundedRegularFile(fs, candidate, remaining, operation);
|
|
2036
2042
|
budget.bytes += bytes.byteLength;
|
|
2037
2043
|
entries.push(Object.freeze({
|
|
@@ -2042,13 +2048,13 @@ function captureTree(fs, root, operation, budget) {
|
|
|
2042
2048
|
}));
|
|
2043
2049
|
return;
|
|
2044
2050
|
}
|
|
2045
|
-
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");
|
|
2046
2052
|
entries.push(Object.freeze({
|
|
2047
2053
|
kind: "Directory",
|
|
2048
2054
|
path: relative,
|
|
2049
2055
|
mode: info.mode & 511
|
|
2050
2056
|
}));
|
|
2051
|
-
const names = (yield* fs.readDirectory(candidate).pipe(mapPlatform$
|
|
2057
|
+
const names = (yield* fs.readDirectory(candidate).pipe(mapPlatform$5(operation, candidate))).sort(compareText$9);
|
|
2052
2058
|
for (const name of names) {
|
|
2053
2059
|
const nextRelative = relative === "" ? name : `${relative}/${name}`;
|
|
2054
2060
|
yield* checked(operation, () => validateRelativePath(nextRelative, false, operation));
|
|
@@ -2059,12 +2065,12 @@ function captureTree(fs, root, operation, budget) {
|
|
|
2059
2065
|
}
|
|
2060
2066
|
function removePathIfPresent(fs, candidate, operation, budget) {
|
|
2061
2067
|
return Effect.gen(function* () {
|
|
2062
|
-
if (!(yield* fs.exists(candidate).pipe(mapPlatform$
|
|
2068
|
+
if (!(yield* fs.exists(candidate).pipe(mapPlatform$5(operation, candidate)))) return;
|
|
2063
2069
|
const entries = yield* captureTree(fs, candidate, operation, budget);
|
|
2064
2070
|
for (const entry of [...entries].reverse()) {
|
|
2065
2071
|
const target = entry.path === "" ? candidate : path.join(candidate, ...entry.path.split("/"));
|
|
2066
2072
|
yield* requireExactExistingPath(fs, target, operation);
|
|
2067
|
-
if (entry.kind === "File") yield* fs.remove(target).pipe(mapPlatform$
|
|
2073
|
+
if (entry.kind === "File") yield* fs.remove(target).pipe(mapPlatform$5(operation, target));
|
|
2068
2074
|
else yield* removeEmptyDirectory(fs, target, operation);
|
|
2069
2075
|
}
|
|
2070
2076
|
});
|
|
@@ -2072,7 +2078,7 @@ function removePathIfPresent(fs, candidate, operation, budget) {
|
|
|
2072
2078
|
function observePreimage(fs, root, relative, operation, budget) {
|
|
2073
2079
|
return Effect.gen(function* () {
|
|
2074
2080
|
const candidate = yield* checked(operation, () => resolveContained(root, relative, false, operation));
|
|
2075
|
-
if (!(yield* fs.exists(candidate).pipe(mapPlatform$
|
|
2081
|
+
if (!(yield* fs.exists(candidate).pipe(mapPlatform$5(operation, candidate)))) return Object.freeze({
|
|
2076
2082
|
path: relative,
|
|
2077
2083
|
entries: null
|
|
2078
2084
|
});
|
|
@@ -2085,15 +2091,15 @@ function observePreimage(fs, root, relative, operation, budget) {
|
|
|
2085
2091
|
}
|
|
2086
2092
|
function requireCaptureAuthority(fs, authorities, consumed, handle, root, readToken, planDigest, operation) {
|
|
2087
2093
|
return Effect.gen(function* () {
|
|
2088
|
-
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");
|
|
2089
2095
|
const authority = authorities.get(handle);
|
|
2090
|
-
if (authority === void 0) return yield* fail$
|
|
2091
|
-
if (authority.root !== root) return yield* fail$
|
|
2092
|
-
const rootIdentity = yield* fs.stat(root).pipe(mapPlatform$
|
|
2093
|
-
if (rootIdentity.dev !== authority.rootDev || !Equal.equals(rootIdentity.ino, authority.rootIno)) return yield* fail$
|
|
2094
|
-
if (authority.readToken !== readToken) return yield* fail$
|
|
2095
|
-
if (planDigest !== void 0 && authority.planDigest !== void 0 && authority.planDigest !== planDigest) return yield* fail$
|
|
2096
|
-
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");
|
|
2097
2103
|
return authority;
|
|
2098
2104
|
});
|
|
2099
2105
|
}
|
|
@@ -2113,7 +2119,7 @@ function validateContentTreeInput(input) {
|
|
|
2113
2119
|
let totalBytes = 0;
|
|
2114
2120
|
const exactPaths = /* @__PURE__ */ new Set();
|
|
2115
2121
|
for (const entry of input.entries) {
|
|
2116
|
-
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");
|
|
2117
2123
|
previousPath = entry.path;
|
|
2118
2124
|
exactPaths.add(entry.path);
|
|
2119
2125
|
totalBytes += entry.bytes.byteLength;
|
|
@@ -2130,32 +2136,32 @@ function validateContentTreeInput(input) {
|
|
|
2130
2136
|
function requireContentTreeParent(fs, candidate) {
|
|
2131
2137
|
const operation = "materialize-content-tree";
|
|
2132
2138
|
return Effect.gen(function* () {
|
|
2133
|
-
if (!path.isAbsolute(candidate) || path.normalize(candidate) !== candidate || candidate === path.parse(candidate).root) return yield* fail$
|
|
2134
|
-
if ((yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2135
|
-
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");
|
|
2136
2142
|
return candidate;
|
|
2137
2143
|
});
|
|
2138
2144
|
}
|
|
2139
2145
|
function revalidateContentTreeParent(fs, parent) {
|
|
2140
2146
|
const operation = "materialize-content-tree";
|
|
2141
2147
|
return Effect.gen(function* () {
|
|
2142
|
-
const canonical = yield* fs.realPath(parent).pipe(mapPlatform$
|
|
2143
|
-
const info = yield* fs.stat(parent).pipe(mapPlatform$
|
|
2144
|
-
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");
|
|
2145
2151
|
});
|
|
2146
2152
|
}
|
|
2147
2153
|
function requireContentTreeDirectory(fs, parent, candidate) {
|
|
2148
2154
|
const operation = "materialize-content-tree";
|
|
2149
2155
|
return Effect.gen(function* () {
|
|
2150
2156
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2151
|
-
if (path.dirname(candidate) !== parent) return yield* fail$
|
|
2152
|
-
if ((yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2153
|
-
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");
|
|
2154
2160
|
});
|
|
2155
2161
|
}
|
|
2156
2162
|
function requireContentTreeStage(fs, parent, candidate) {
|
|
2157
2163
|
const operation = "materialize-content-tree";
|
|
2158
|
-
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");
|
|
2159
2165
|
return requireContentTreeDirectory(fs, parent, candidate);
|
|
2160
2166
|
}
|
|
2161
2167
|
function populateContentTree(fs, root, input) {
|
|
@@ -2171,8 +2177,8 @@ function populateContentTree(fs, root, input) {
|
|
|
2171
2177
|
yield* fs.makeDirectory(directory, {
|
|
2172
2178
|
recursive: false,
|
|
2173
2179
|
mode: 448
|
|
2174
|
-
}).pipe(mapPlatform$
|
|
2175
|
-
yield* fs.chmod(directory, 448).pipe(mapPlatform$
|
|
2180
|
+
}).pipe(mapPlatform$5(operation, directory));
|
|
2181
|
+
yield* fs.chmod(directory, 448).pipe(mapPlatform$5(operation, directory));
|
|
2176
2182
|
createdDirectories.add(relativeDirectory);
|
|
2177
2183
|
}
|
|
2178
2184
|
const destination = path.join(root, ...segments);
|
|
@@ -2180,8 +2186,8 @@ function populateContentTree(fs, root, input) {
|
|
|
2180
2186
|
yield* fs.writeFile(destination, entry.bytes, {
|
|
2181
2187
|
flag: "wx",
|
|
2182
2188
|
mode
|
|
2183
|
-
}).pipe(mapPlatform$
|
|
2184
|
-
yield* fs.chmod(destination, mode).pipe(mapPlatform$
|
|
2189
|
+
}).pipe(mapPlatform$5(operation, destination));
|
|
2190
|
+
yield* fs.chmod(destination, mode).pipe(mapPlatform$5(operation, destination));
|
|
2185
2191
|
}
|
|
2186
2192
|
});
|
|
2187
2193
|
}
|
|
@@ -2214,14 +2220,14 @@ function removeContentTreeDirectory(fs, parent, candidate) {
|
|
|
2214
2220
|
yield* fs.remove(candidate, {
|
|
2215
2221
|
recursive: true,
|
|
2216
2222
|
force: false
|
|
2217
|
-
}).pipe(mapPlatform$
|
|
2223
|
+
}).pipe(mapPlatform$5(operation, candidate));
|
|
2218
2224
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2219
2225
|
});
|
|
2220
2226
|
}
|
|
2221
2227
|
function cleanupContentTreeStage(fs, parent, stage) {
|
|
2222
2228
|
const operation = "materialize-content-tree";
|
|
2223
2229
|
return Effect.gen(function* () {
|
|
2224
|
-
if (!(yield* fs.exists(stage).pipe(mapPlatform$
|
|
2230
|
+
if (!(yield* fs.exists(stage).pipe(mapPlatform$5(operation, stage)))) return;
|
|
2225
2231
|
yield* requireContentTreeStage(fs, parent, stage);
|
|
2226
2232
|
yield* removeContentTreeDirectory(fs, parent, stage);
|
|
2227
2233
|
});
|
|
@@ -2234,13 +2240,13 @@ function cutOverContentTree(fs, parent, root, stage, hadPreimage) {
|
|
|
2234
2240
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2235
2241
|
yield* requireContentTreeStage(fs, parent, stage);
|
|
2236
2242
|
yield* revalidateContentTreePreimage(fs, parent, root, hadPreimage);
|
|
2237
|
-
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");
|
|
2238
2244
|
yield* restore(Effect.yieldNow);
|
|
2239
2245
|
if (hadPreimage) {
|
|
2240
|
-
yield* fs.rename(root, backup).pipe(mapPlatform$
|
|
2246
|
+
yield* fs.rename(root, backup).pipe(mapPlatform$5(operation, root));
|
|
2241
2247
|
yield* requireContentTreeDirectory(fs, parent, backup);
|
|
2242
2248
|
}
|
|
2243
|
-
yield* fs.rename(stage, root).pipe(mapPlatform$
|
|
2249
|
+
yield* fs.rename(stage, root).pipe(mapPlatform$5(operation, root));
|
|
2244
2250
|
yield* requireContentTreeDirectory(fs, parent, root);
|
|
2245
2251
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2246
2252
|
}));
|
|
@@ -2255,12 +2261,12 @@ function cutOverContentTree(fs, parent, root, stage, hadPreimage) {
|
|
|
2255
2261
|
function revalidateContentTreePreimage(fs, parent, root, hadPreimage) {
|
|
2256
2262
|
const operation = "materialize-content-tree";
|
|
2257
2263
|
return Effect.gen(function* () {
|
|
2258
|
-
const present = yield* fs.exists(root).pipe(mapPlatform$
|
|
2264
|
+
const present = yield* fs.exists(root).pipe(mapPlatform$5(operation, root));
|
|
2259
2265
|
if (!hadPreimage) {
|
|
2260
|
-
if (present) return yield* fail$
|
|
2266
|
+
if (present) return yield* fail$5(operation, "IdentityChanged", root, "Absent disposable content tree became occupied before cutover");
|
|
2261
2267
|
return;
|
|
2262
2268
|
}
|
|
2263
|
-
if (!present) return yield* fail$
|
|
2269
|
+
if (!present) return yield* fail$5(operation, "IdentityChanged", root, "Prior disposable content tree disappeared before cutover");
|
|
2264
2270
|
yield* requireContentTreeDirectory(fs, parent, root);
|
|
2265
2271
|
});
|
|
2266
2272
|
}
|
|
@@ -2268,27 +2274,27 @@ function restoreContentTreeCutover(fs, parent, root, stage, backup, hadPreimage)
|
|
|
2268
2274
|
const operation = "materialize-content-tree";
|
|
2269
2275
|
return Effect.gen(function* () {
|
|
2270
2276
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2271
|
-
const rootPresent = yield* fs.exists(root).pipe(mapPlatform$
|
|
2272
|
-
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));
|
|
2273
2279
|
if (!hadPreimage) {
|
|
2274
2280
|
if (rootPresent) {
|
|
2275
|
-
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");
|
|
2276
2282
|
yield* removeContentTreeDirectory(fs, parent, root);
|
|
2277
2283
|
}
|
|
2278
2284
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2279
2285
|
return;
|
|
2280
2286
|
}
|
|
2281
|
-
if (!(yield* fs.exists(backup).pipe(mapPlatform$
|
|
2282
|
-
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");
|
|
2283
2289
|
yield* requireContentTreeDirectory(fs, parent, root);
|
|
2284
2290
|
return;
|
|
2285
2291
|
}
|
|
2286
2292
|
yield* requireContentTreeDirectory(fs, parent, backup);
|
|
2287
2293
|
if (rootPresent) {
|
|
2288
|
-
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");
|
|
2289
2295
|
yield* removeContentTreeDirectory(fs, parent, root);
|
|
2290
2296
|
}
|
|
2291
|
-
yield* fs.rename(backup, root).pipe(mapPlatform$
|
|
2297
|
+
yield* fs.rename(backup, root).pipe(mapPlatform$5(operation, root));
|
|
2292
2298
|
yield* requireContentTreeDirectory(fs, parent, root);
|
|
2293
2299
|
yield* revalidateContentTreeParent(fs, parent);
|
|
2294
2300
|
});
|
|
@@ -2367,12 +2373,12 @@ function replaceTree(fs, candidate, entries, operation, budget) {
|
|
|
2367
2373
|
yield* fs.makeDirectory(candidate, {
|
|
2368
2374
|
recursive: false,
|
|
2369
2375
|
mode: 448
|
|
2370
|
-
}).pipe(mapPlatform$
|
|
2376
|
+
}).pipe(mapPlatform$5(operation, candidate));
|
|
2371
2377
|
yield* requireExactExistingPath(fs, candidate, operation);
|
|
2372
2378
|
const seen = /* @__PURE__ */ new Set();
|
|
2373
2379
|
for (const entry of entries) {
|
|
2374
2380
|
yield* checked(operation, () => validateRelativePath(entry.path, false, operation));
|
|
2375
|
-
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");
|
|
2376
2382
|
seen.add(entry.path);
|
|
2377
2383
|
yield* writeAtomic(fs, path.join(candidate, ...entry.path.split("/")), entry.bytes, fileMode(entry.mode), operation);
|
|
2378
2384
|
}
|
|
@@ -2400,12 +2406,12 @@ function restoreTree(fs, candidate, entries) {
|
|
|
2400
2406
|
for (const entry of directories) {
|
|
2401
2407
|
const destination = entry.path === "" ? candidate : path.join(candidate, ...entry.path.split("/"));
|
|
2402
2408
|
yield* ensureDirectoryChain(fs, path.dirname(destination), "restore");
|
|
2403
|
-
if (!(yield* fs.exists(destination).pipe(mapPlatform$
|
|
2409
|
+
if (!(yield* fs.exists(destination).pipe(mapPlatform$5("restore", destination)))) yield* fs.makeDirectory(destination, {
|
|
2404
2410
|
recursive: false,
|
|
2405
2411
|
mode: entry.mode
|
|
2406
|
-
}).pipe(mapPlatform$
|
|
2412
|
+
}).pipe(mapPlatform$5("restore", destination));
|
|
2407
2413
|
yield* requireExactExistingPath(fs, destination, "restore");
|
|
2408
|
-
yield* fs.chmod(destination, entry.mode).pipe(mapPlatform$
|
|
2414
|
+
yield* fs.chmod(destination, entry.mode).pipe(mapPlatform$5("restore", destination));
|
|
2409
2415
|
}
|
|
2410
2416
|
for (const entry of entries) {
|
|
2411
2417
|
if (entry.kind !== "File") continue;
|
|
@@ -2421,30 +2427,30 @@ function writeAtomic(fs, destination, bytes, mode, operation) {
|
|
|
2421
2427
|
yield* Effect.acquireUseRelease(fs.writeFile(temporary, bytes, {
|
|
2422
2428
|
flag: "wx",
|
|
2423
2429
|
mode: 384
|
|
2424
|
-
}).pipe(mapPlatform$
|
|
2425
|
-
yield* fs.chmod(owned, mode).pipe(mapPlatform$
|
|
2426
|
-
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));
|
|
2427
2433
|
}), (owned) => fs.exists(owned).pipe(Effect.flatMap((exists) => exists ? fs.remove(owned, { force: false }) : Effect.void), Effect.ignore));
|
|
2428
2434
|
});
|
|
2429
2435
|
}
|
|
2430
2436
|
function readBoundedRegularFile(fs, candidate, maxBytes, operation) {
|
|
2431
2437
|
return Effect.gen(function* () {
|
|
2432
|
-
if ((yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2433
|
-
const before = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2434
|
-
if (before.type !== "File") return yield* fail$
|
|
2435
|
-
if (before.size > BigInt(maxBytes)) return yield* fail$
|
|
2436
|
-
const bytes = yield* fs.readFile(candidate).pipe(mapPlatform$
|
|
2437
|
-
const after = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2438
|
-
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");
|
|
2439
2445
|
return bytes;
|
|
2440
2446
|
});
|
|
2441
2447
|
}
|
|
2442
2448
|
function requireCanonicalRoot(fs, candidate, operation) {
|
|
2443
2449
|
return Effect.gen(function* () {
|
|
2444
|
-
if (!path.isAbsolute(candidate) || path.normalize(candidate) !== candidate) return yield* fail$
|
|
2445
|
-
const canonical = yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2446
|
-
const info = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2447
|
-
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");
|
|
2448
2454
|
return candidate;
|
|
2449
2455
|
});
|
|
2450
2456
|
}
|
|
@@ -2455,14 +2461,14 @@ function requireExactGitRoot(fs, executable, candidate, operation) {
|
|
|
2455
2461
|
"rev-parse",
|
|
2456
2462
|
"--path-format=absolute",
|
|
2457
2463
|
"--show-toplevel"
|
|
2458
|
-
], operation)) !== root) return yield* fail$
|
|
2464
|
+
], operation)) !== root) return yield* fail$5(operation, "Aliased", root, "Workspace locator is not the exact Git root");
|
|
2459
2465
|
return root;
|
|
2460
2466
|
});
|
|
2461
2467
|
}
|
|
2462
2468
|
function observeGitWorkspaceAnchor(fs, executable, locator, input, operation) {
|
|
2463
2469
|
return Effect.gen(function* () {
|
|
2464
2470
|
const root = yield* requireExactGitRoot(fs, executable, locator, operation);
|
|
2465
|
-
const rootInfo = yield* fs.stat(root).pipe(mapPlatform$
|
|
2471
|
+
const rootInfo = yield* fs.stat(root).pipe(mapPlatform$5(operation, root));
|
|
2466
2472
|
const objectFormat = yield* gitObjectFormat$1(executable, root, operation);
|
|
2467
2473
|
const refName = yield* gitText$1(executable, root, [
|
|
2468
2474
|
"symbolic-ref",
|
|
@@ -2482,7 +2488,7 @@ function observeGitWorkspaceAnchor(fs, executable, locator, input, operation) {
|
|
|
2482
2488
|
return Object.freeze({
|
|
2483
2489
|
root,
|
|
2484
2490
|
rootDevice: String(rootInfo.dev),
|
|
2485
|
-
rootInode: String(Option.getOrElse(rootInfo.ino, () => -
|
|
2491
|
+
rootInode: String(Option.getOrElse(rootInfo.ino, () => -1n)),
|
|
2486
2492
|
refName,
|
|
2487
2493
|
commit,
|
|
2488
2494
|
refCommit,
|
|
@@ -2525,7 +2531,7 @@ function observeClosingGitStagedIndexBinding(fs, executable, input, operation) {
|
|
|
2525
2531
|
function stagedRegularBlobObjectIds(entries, materializedPaths, materializedRoots) {
|
|
2526
2532
|
const objectIds = /* @__PURE__ */ new Set();
|
|
2527
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);
|
|
2528
|
-
return Object.freeze([...objectIds].sort(compareText$
|
|
2534
|
+
return Object.freeze([...objectIds].sort(compareText$9));
|
|
2529
2535
|
}
|
|
2530
2536
|
function observeGitWorktreeObjectIds(fs, executable, root, admittedPaths, objectFormat, maxFileBytes, maxTotalBytes) {
|
|
2531
2537
|
const operation = "capture-git-evidence";
|
|
@@ -2538,7 +2544,7 @@ function observeGitWorktreeObjectIds(fs, executable, root, admittedPaths, object
|
|
|
2538
2544
|
"hash-object",
|
|
2539
2545
|
"--no-filters",
|
|
2540
2546
|
"--stdin-paths"
|
|
2541
|
-
], 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))));
|
|
2542
2548
|
const objectIds = yield* checked(operation, () => parseGitObjectIdLines(output, admittedPaths.length, objectFormat, operation));
|
|
2543
2549
|
yield* Effect.forEach(identities, (identity) => revalidateGitWorktreeFileIdentity(fs, identity, operation), {
|
|
2544
2550
|
concurrency: 32,
|
|
@@ -2553,10 +2559,10 @@ function observeGitWorktreeObjectIds(fs, executable, root, admittedPaths, object
|
|
|
2553
2559
|
function inspectGitWorktreeFileIdentity(fs, root, relativePath, maxBytes, operation) {
|
|
2554
2560
|
const candidate = path.join(root, relativePath);
|
|
2555
2561
|
return Effect.gen(function* () {
|
|
2556
|
-
if ((yield* fs.realPath(candidate).pipe(mapPlatform$
|
|
2557
|
-
const observed = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2558
|
-
if (observed.type !== "File") return yield* fail$
|
|
2559
|
-
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");
|
|
2560
2566
|
return Object.freeze({
|
|
2561
2567
|
candidate,
|
|
2562
2568
|
device: observed.dev,
|
|
@@ -2567,16 +2573,16 @@ function inspectGitWorktreeFileIdentity(fs, root, relativePath, maxBytes, operat
|
|
|
2567
2573
|
}
|
|
2568
2574
|
function revalidateGitWorktreeFileIdentity(fs, identity, operation) {
|
|
2569
2575
|
return Effect.gen(function* () {
|
|
2570
|
-
const canonical = yield* fs.realPath(identity.candidate).pipe(mapPlatform$
|
|
2571
|
-
const observed = yield* fs.stat(identity.candidate).pipe(mapPlatform$
|
|
2572
|
-
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");
|
|
2573
2579
|
});
|
|
2574
2580
|
}
|
|
2575
2581
|
function requireAggregateWorktreeBound(identities, maxBytes, operation) {
|
|
2576
2582
|
let total = 0n;
|
|
2577
2583
|
for (const identity of identities) {
|
|
2578
2584
|
total += identity.size;
|
|
2579
|
-
if (total > BigInt(maxBytes)) throw failure$
|
|
2585
|
+
if (total > BigInt(maxBytes)) throw failure$5(operation, "LimitExceeded", identity.candidate, "Admitted worktree files exceed maxBytes");
|
|
2580
2586
|
}
|
|
2581
2587
|
}
|
|
2582
2588
|
function gitObjectIdLinesOutputLimit(count, objectFormat, operation) {
|
|
@@ -2589,12 +2595,12 @@ function parseGitObjectIdLines(output, expectedCount, objectFormat, operation) {
|
|
|
2589
2595
|
try {
|
|
2590
2596
|
encoded = decoder$2.decode(output);
|
|
2591
2597
|
} catch {
|
|
2592
|
-
throw failure$
|
|
2598
|
+
throw failure$5(operation, "GitFailed", void 0, "Git worktree object output is not UTF-8");
|
|
2593
2599
|
}
|
|
2594
|
-
if (!encoded.endsWith("\n")) throw failure$
|
|
2600
|
+
if (!encoded.endsWith("\n")) throw failure$5(operation, "GitFailed", void 0, "Git worktree object output is truncated");
|
|
2595
2601
|
const objectIds = encoded.slice(0, -1).split("\n");
|
|
2596
2602
|
const pattern = objectFormat === "sha1" ? /^[0-9a-f]{40}$/u : /^[0-9a-f]{64}$/u;
|
|
2597
|
-
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");
|
|
2598
2604
|
return Object.freeze(objectIds);
|
|
2599
2605
|
}
|
|
2600
2606
|
function readSelectedRemoteUrls(executable, root, selection, operation) {
|
|
@@ -2612,7 +2618,7 @@ function readSelectedRemoteUrls(executable, root, selection, operation) {
|
|
|
2612
2618
|
"--all",
|
|
2613
2619
|
remoteName
|
|
2614
2620
|
], operation));
|
|
2615
|
-
return Object.freeze(remoteUrls.flat().sort(compareText$
|
|
2621
|
+
return Object.freeze(remoteUrls.flat().sort(compareText$9));
|
|
2616
2622
|
});
|
|
2617
2623
|
}
|
|
2618
2624
|
function readGitStatus(executable, root, maxBytes) {
|
|
@@ -2645,7 +2651,7 @@ function requireGitObjectType(executable, root, object, expected, operation) {
|
|
|
2645
2651
|
"cat-file",
|
|
2646
2652
|
"-t",
|
|
2647
2653
|
object
|
|
2648
|
-
], 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}`)));
|
|
2649
2655
|
}
|
|
2650
2656
|
function requireExactCommit(executable, root, candidate, operation) {
|
|
2651
2657
|
return gitText$1(executable, root, [
|
|
@@ -2653,7 +2659,7 @@ function requireExactCommit(executable, root, candidate, operation) {
|
|
|
2653
2659
|
"--verify",
|
|
2654
2660
|
"--end-of-options",
|
|
2655
2661
|
`${candidate}^{commit}`
|
|
2656
|
-
], 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")));
|
|
2657
2663
|
}
|
|
2658
2664
|
function localGitAncestry(executable, root, ancestor, descendant, operation) {
|
|
2659
2665
|
return gitExitCode(executable, root, [
|
|
@@ -2664,18 +2670,18 @@ function localGitAncestry(executable, root, ancestor, descendant, operation) {
|
|
|
2664
2670
|
], operation).pipe(Effect.flatMap((code) => {
|
|
2665
2671
|
if (code === 0) return Effect.succeed(true);
|
|
2666
2672
|
if (code === 1) return Effect.succeed(false);
|
|
2667
|
-
return fail$
|
|
2673
|
+
return fail$5(operation, "GitFailed", root, `Git ancestry query exited ${code}`);
|
|
2668
2674
|
}));
|
|
2669
2675
|
}
|
|
2670
2676
|
function requireGitWorkspaceRoot(gitExecutable, root, operation) {
|
|
2671
2677
|
return Effect.gen(function* () {
|
|
2672
|
-
if (root === path.parse(root).root) return yield* fail$
|
|
2673
|
-
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");
|
|
2674
2680
|
});
|
|
2675
2681
|
}
|
|
2676
2682
|
function requireExactExistingPath(fs, candidate, operation) {
|
|
2677
2683
|
return Effect.gen(function* () {
|
|
2678
|
-
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");
|
|
2679
2685
|
});
|
|
2680
2686
|
}
|
|
2681
2687
|
function ensureDirectoryChain(fs, directory, operation) {
|
|
@@ -2685,28 +2691,28 @@ function ensureDirectoryChain(fs, directory, operation) {
|
|
|
2685
2691
|
let current = parsed.root;
|
|
2686
2692
|
for (const segment of segments) {
|
|
2687
2693
|
current = path.join(current, segment);
|
|
2688
|
-
if (!(yield* fs.exists(current).pipe(mapPlatform$
|
|
2694
|
+
if (!(yield* fs.exists(current).pipe(mapPlatform$5(operation, current)))) yield* fs.makeDirectory(current, {
|
|
2689
2695
|
recursive: false,
|
|
2690
2696
|
mode: 448
|
|
2691
|
-
}).pipe(mapPlatform$
|
|
2697
|
+
}).pipe(mapPlatform$5(operation, current));
|
|
2692
2698
|
yield* requireExactExistingPath(fs, current, operation);
|
|
2693
|
-
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");
|
|
2694
2700
|
}
|
|
2695
2701
|
});
|
|
2696
2702
|
}
|
|
2697
2703
|
function removeEmptyDirectory(fs, candidate, operation) {
|
|
2698
2704
|
return Effect.gen(function* () {
|
|
2699
2705
|
yield* requireExactExistingPath(fs, candidate, operation);
|
|
2700
|
-
const before = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2701
|
-
const entries = yield* fs.readDirectory(candidate).pipe(mapPlatform$
|
|
2702
|
-
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");
|
|
2703
2709
|
yield* requireExactExistingPath(fs, candidate, operation);
|
|
2704
|
-
const after = yield* fs.stat(candidate).pipe(mapPlatform$
|
|
2705
|
-
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");
|
|
2706
2712
|
yield* fs.remove(candidate, {
|
|
2707
2713
|
recursive: true,
|
|
2708
2714
|
force: false
|
|
2709
|
-
}).pipe(mapPlatform$
|
|
2715
|
+
}).pipe(mapPlatform$5(operation, candidate));
|
|
2710
2716
|
});
|
|
2711
2717
|
}
|
|
2712
2718
|
function resolveContained(root, relative, allowEmpty, operation) {
|
|
@@ -2744,7 +2750,7 @@ function readGitBlobBatch(executable, root, input, operation) {
|
|
|
2744
2750
|
return gitBlobBatchOutputLimit(input, operation);
|
|
2745
2751
|
});
|
|
2746
2752
|
if (input.blobs.length === 0) return Object.freeze([]);
|
|
2747
|
-
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))));
|
|
2748
2754
|
return yield* checked(operation, () => parseGitBlobBatch(output, input, operation));
|
|
2749
2755
|
});
|
|
2750
2756
|
}
|
|
@@ -2773,73 +2779,73 @@ function parseGitBlobBatch(output, input, operation) {
|
|
|
2773
2779
|
let totalBytes = 0;
|
|
2774
2780
|
for (const expectedBlob of input.blobs) {
|
|
2775
2781
|
const headerEnd = output.indexOf(10, offset);
|
|
2776
|
-
if (headerEnd < 0) throw failure$
|
|
2782
|
+
if (headerEnd < 0) throw failure$5(operation, "GitFailed", expectedBlob, "Git blob batch omitted an object header");
|
|
2777
2783
|
const header = decodeGitBlobBatchHeader(output.subarray(offset, headerEnd), expectedBlob, operation);
|
|
2778
|
-
if (header === `${expectedBlob} missing`) throw failure$
|
|
2784
|
+
if (header === `${expectedBlob} missing`) throw failure$5(operation, "GitFailed", expectedBlob, "Git blob batch returned a missing object");
|
|
2779
2785
|
const match = /^([0-9a-f]+) ([a-z][a-z0-9-]*) ([0-9]+)$/u.exec(header);
|
|
2780
|
-
if (match === null) throw failure$
|
|
2781
|
-
if (match[1] !== expectedBlob) throw failure$
|
|
2782
|
-
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");
|
|
2783
2789
|
const size = Number(match[3]);
|
|
2784
|
-
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");
|
|
2785
2791
|
totalBytes += size;
|
|
2786
|
-
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");
|
|
2787
2793
|
const contentStart = headerEnd + 1;
|
|
2788
2794
|
const contentEnd = contentStart + size;
|
|
2789
|
-
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");
|
|
2790
2796
|
observations.push(Object.freeze({
|
|
2791
2797
|
blob: expectedBlob,
|
|
2792
2798
|
bytes: output.slice(contentStart, contentEnd)
|
|
2793
2799
|
}));
|
|
2794
2800
|
offset = contentEnd + 1;
|
|
2795
2801
|
}
|
|
2796
|
-
if (offset !== output.byteLength) throw failure$
|
|
2802
|
+
if (offset !== output.byteLength) throw failure$5(operation, "GitFailed", void 0, "Git blob batch returned trailing output");
|
|
2797
2803
|
return Object.freeze(observations);
|
|
2798
2804
|
}
|
|
2799
2805
|
function decodeGitBlobBatchHeader(header, expectedBlob, operation) {
|
|
2800
2806
|
try {
|
|
2801
2807
|
return decoder$2.decode(header);
|
|
2802
2808
|
} catch {
|
|
2803
|
-
throw failure$
|
|
2809
|
+
throw failure$5(operation, "GitFailed", expectedBlob, "Git blob batch returned a non-UTF-8 object header");
|
|
2804
2810
|
}
|
|
2805
2811
|
}
|
|
2806
2812
|
function parseGitTrackedPathFlags(output, admittedPaths, root) {
|
|
2807
2813
|
return Effect.gen(function* () {
|
|
2808
2814
|
if (output.byteLength === 0) return Object.freeze([]);
|
|
2809
|
-
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");
|
|
2810
2816
|
const admitted = new Set(admittedPaths);
|
|
2811
2817
|
const facts = [];
|
|
2812
2818
|
const factsByPath = /* @__PURE__ */ new Map();
|
|
2813
2819
|
let recordStart = 0;
|
|
2814
2820
|
for (let index = 0; index < output.byteLength; index += 1) {
|
|
2815
2821
|
if (output[index] !== 0) continue;
|
|
2816
|
-
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");
|
|
2817
2823
|
const record = yield* Effect.try({
|
|
2818
2824
|
try: () => decoder$2.decode(output.subarray(recordStart, index)),
|
|
2819
|
-
catch: () => failure$
|
|
2825
|
+
catch: () => failure$5("capture-git-evidence", "GitFailed", root, "Git tracked-path output contains invalid UTF-8")
|
|
2820
2826
|
});
|
|
2821
2827
|
recordStart = index + 1;
|
|
2822
2828
|
const tag = record[0];
|
|
2823
|
-
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");
|
|
2824
2830
|
const entryPath = record.slice(2);
|
|
2825
2831
|
const status = gitTrackedPathStatus(tag);
|
|
2826
|
-
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");
|
|
2827
2833
|
const fact = Object.freeze({
|
|
2828
2834
|
path: entryPath,
|
|
2829
2835
|
status,
|
|
2830
2836
|
assumeUnchanged: tag === "h" || tag === "s"
|
|
2831
2837
|
});
|
|
2832
|
-
if (!gitTrackedPathFlagValidator.Check(fact)) return yield* fail$
|
|
2833
|
-
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");
|
|
2834
2840
|
const prior = factsByPath.get(fact.path);
|
|
2835
|
-
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");
|
|
2836
2842
|
factsByPath.set(fact.path, Object.freeze({
|
|
2837
2843
|
status: fact.status,
|
|
2838
2844
|
count: (prior?.count ?? 0) + 1
|
|
2839
2845
|
}));
|
|
2840
2846
|
facts.push(fact);
|
|
2841
2847
|
}
|
|
2842
|
-
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));
|
|
2843
2849
|
return Object.freeze(facts);
|
|
2844
2850
|
});
|
|
2845
2851
|
}
|
|
@@ -2854,43 +2860,43 @@ function gitTrackedPathStatus(tag) {
|
|
|
2854
2860
|
function parseGitStagedIndexOutput(output, objectFormat, maxEntries, root) {
|
|
2855
2861
|
return Effect.gen(function* () {
|
|
2856
2862
|
if (output.byteLength === 0) return Object.freeze([]);
|
|
2857
|
-
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");
|
|
2858
2864
|
const entries = [];
|
|
2859
2865
|
const identities = /* @__PURE__ */ new Set();
|
|
2860
2866
|
let recordStart = 0;
|
|
2861
2867
|
for (let index = 0; index < output.byteLength; index += 1) {
|
|
2862
2868
|
if (output[index] !== 0) continue;
|
|
2863
|
-
if (entries.length >= maxEntries) return yield* fail$
|
|
2864
|
-
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");
|
|
2865
2871
|
const record = yield* Effect.try({
|
|
2866
2872
|
try: () => decoder$2.decode(output.subarray(recordStart, index)),
|
|
2867
|
-
catch: () => failure$
|
|
2873
|
+
catch: () => failure$5("observe-git-staged-index", "GitFailed", root, "Git index output contains invalid UTF-8")
|
|
2868
2874
|
});
|
|
2869
2875
|
recordStart = index + 1;
|
|
2870
2876
|
const separator = record.indexOf(" ");
|
|
2871
|
-
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");
|
|
2872
2878
|
const header = record.slice(0, separator);
|
|
2873
2879
|
const entryPath = record.slice(separator + 1);
|
|
2874
2880
|
const headerMatch = /^([0-7]{6}) ([0-9A-Za-z]+) ([0-3])$/u.exec(header);
|
|
2875
2881
|
const mode = headerMatch?.[1];
|
|
2876
2882
|
const objectId = headerMatch?.[2];
|
|
2877
2883
|
const rawStage = headerMatch?.[3];
|
|
2878
|
-
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");
|
|
2879
2885
|
const objectLength = objectFormat === "sha1" ? 40 : 64;
|
|
2880
|
-
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");
|
|
2881
2887
|
const entry = Object.freeze({
|
|
2882
2888
|
path: entryPath,
|
|
2883
2889
|
mode,
|
|
2884
2890
|
objectId,
|
|
2885
2891
|
stage: gitIndexStage(rawStage)
|
|
2886
2892
|
});
|
|
2887
|
-
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");
|
|
2888
2894
|
const identity = `${entry.path}\0${entry.stage}`;
|
|
2889
|
-
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");
|
|
2890
2896
|
identities.add(identity);
|
|
2891
2897
|
entries.push(entry);
|
|
2892
2898
|
}
|
|
2893
|
-
entries.sort((left, right) => compareText$
|
|
2899
|
+
entries.sort((left, right) => compareText$9(left.path, right.path) || left.stage - right.stage);
|
|
2894
2900
|
return Object.freeze(entries);
|
|
2895
2901
|
});
|
|
2896
2902
|
}
|
|
@@ -2906,42 +2912,42 @@ function gitIndexStage(value) {
|
|
|
2906
2912
|
function parseGitTreeOutput(output, objectFormat, maxEntries, root) {
|
|
2907
2913
|
return Effect.gen(function* () {
|
|
2908
2914
|
if (output.byteLength === 0) return Object.freeze([]);
|
|
2909
|
-
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");
|
|
2910
2916
|
const entries = [];
|
|
2911
2917
|
const paths = /* @__PURE__ */ new Set();
|
|
2912
2918
|
let recordStart = 0;
|
|
2913
2919
|
for (let index = 0; index < output.byteLength; index += 1) {
|
|
2914
2920
|
if (output[index] !== 0) continue;
|
|
2915
|
-
if (entries.length >= maxEntries) return yield* fail$
|
|
2916
|
-
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");
|
|
2917
2923
|
const record = yield* Effect.try({
|
|
2918
2924
|
try: () => decoder$2.decode(output.subarray(recordStart, index)),
|
|
2919
|
-
catch: () => failure$
|
|
2925
|
+
catch: () => failure$5("read-git-tree", "GitFailed", root, "Git tree output contains invalid UTF-8")
|
|
2920
2926
|
});
|
|
2921
2927
|
recordStart = index + 1;
|
|
2922
2928
|
const separator = record.indexOf(" ");
|
|
2923
|
-
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");
|
|
2924
2930
|
const header = record.slice(0, separator);
|
|
2925
2931
|
const entryPath = record.slice(separator + 1);
|
|
2926
2932
|
const headerMatch = /^([0-7]{6}) ([a-z][a-z0-9-]*) ([0-9A-Za-z]+)$/u.exec(header);
|
|
2927
2933
|
const mode = headerMatch?.[1];
|
|
2928
2934
|
const objectType = headerMatch?.[2];
|
|
2929
2935
|
const blob = headerMatch?.[3];
|
|
2930
|
-
if (mode === void 0 || objectType === void 0 || blob === void 0) return yield* fail$
|
|
2931
|
-
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");
|
|
2932
2938
|
const objectLength = objectFormat === "sha1" ? 40 : 64;
|
|
2933
|
-
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");
|
|
2934
2940
|
const entry = Object.freeze({
|
|
2935
2941
|
path: entryPath,
|
|
2936
2942
|
mode,
|
|
2937
2943
|
blob
|
|
2938
2944
|
});
|
|
2939
|
-
if (!contentTreeEntryValidator.Check(entry)) return yield* fail$
|
|
2940
|
-
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");
|
|
2941
2947
|
paths.add(entry.path);
|
|
2942
2948
|
entries.push(entry);
|
|
2943
2949
|
}
|
|
2944
|
-
entries.sort((left, right) => compareText$
|
|
2950
|
+
entries.sort((left, right) => compareText$9(left.path, right.path));
|
|
2945
2951
|
return Object.freeze(entries);
|
|
2946
2952
|
});
|
|
2947
2953
|
}
|
|
@@ -2980,16 +2986,16 @@ function validateObjectForFormat(value, format, label, operation) {
|
|
|
2980
2986
|
if (value.length !== expectedLength || !/^[0-9a-f]+$/u.test(value)) throw invalidInput(operation, value, `${label} must match the selected Git object format`);
|
|
2981
2987
|
}
|
|
2982
2988
|
function gitObjectFormat$1(executable, root, operation) {
|
|
2983
|
-
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}`)));
|
|
2984
2990
|
}
|
|
2985
2991
|
function gitText$1(executable, root, args, operation) {
|
|
2986
|
-
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()));
|
|
2987
2993
|
}
|
|
2988
2994
|
function gitLines(executable, root, args, operation) {
|
|
2989
2995
|
return gitText$1(executable, root, args, operation).pipe(Effect.map((output) => output === "" ? [] : output.split("\n").filter((line) => line !== "")));
|
|
2990
2996
|
}
|
|
2991
2997
|
function gitBytes$1(executable, root, args, operation, maxBytes) {
|
|
2992
|
-
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))));
|
|
2993
2999
|
}
|
|
2994
3000
|
function gitExitCode(executable, root, args, operation) {
|
|
2995
3001
|
return runGitCommand$1(executable, root, args, operation, 65536).pipe(Effect.map((result) => result.exitCode));
|
|
@@ -3003,7 +3009,7 @@ function runGitCommand$1(executable, root, args, operation, maxStdoutBytes, stdi
|
|
|
3003
3009
|
forceKillAfter: "5 seconds"
|
|
3004
3010
|
});
|
|
3005
3011
|
return Effect.scoped(Effect.gen(function* () {
|
|
3006
|
-
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))));
|
|
3007
3013
|
const [stdout, stderr, exitCode] = yield* Effect.all([
|
|
3008
3014
|
collectBoundedGitOutput(process.stdout, maxStdoutBytes, operation, root, "stdout"),
|
|
3009
3015
|
collectBoundedGitOutput(process.stderr, stderrLimit, operation, root, "stderr"),
|
|
@@ -3014,14 +3020,14 @@ function runGitCommand$1(executable, root, args, operation, maxStdoutBytes, stdi
|
|
|
3014
3020
|
stderr,
|
|
3015
3021
|
exitCode: Number(exitCode)
|
|
3016
3022
|
});
|
|
3017
|
-
})).pipe(Effect.catchTag("PlatformError", (cause) => fail$
|
|
3023
|
+
})).pipe(Effect.catchTag("PlatformError", (cause) => fail$5(operation, "GitFailed", root, cause.message)));
|
|
3018
3024
|
}
|
|
3019
3025
|
function collectBoundedGitOutput(stream, maxBytes, operation, root, output) {
|
|
3020
3026
|
return Effect.gen(function* () {
|
|
3021
3027
|
const chunks = [];
|
|
3022
3028
|
let length = 0;
|
|
3023
3029
|
yield* Stream.runForEach(stream, (chunk) => {
|
|
3024
|
-
if (length + chunk.byteLength > maxBytes) return fail$
|
|
3030
|
+
if (length + chunk.byteLength > maxBytes) return fail$5(operation, "LimitExceeded", root, `Git ${output} exceeds ${maxBytes} bytes`);
|
|
3025
3031
|
chunks.push(chunk);
|
|
3026
3032
|
length += chunk.byteLength;
|
|
3027
3033
|
return Effect.void;
|
|
@@ -3038,7 +3044,7 @@ function collectBoundedGitOutput(stream, maxBytes, operation, root, output) {
|
|
|
3038
3044
|
function decodeGitOutput$2(bytes, operation, root) {
|
|
3039
3045
|
return Effect.try({
|
|
3040
3046
|
try: () => decoder$2.decode(bytes),
|
|
3041
|
-
catch: (cause) => failure$
|
|
3047
|
+
catch: (cause) => failure$5(operation, "GitFailed", root, errorMessage$3(cause))
|
|
3042
3048
|
});
|
|
3043
3049
|
}
|
|
3044
3050
|
function gitFailureDetail$2(args, stderr) {
|
|
@@ -3072,28 +3078,28 @@ function equalBytes(left, right) {
|
|
|
3072
3078
|
function pathsOverlap(left, right) {
|
|
3073
3079
|
return left === right || left.startsWith(`${right}/`) || right.startsWith(`${left}/`);
|
|
3074
3080
|
}
|
|
3075
|
-
function mapPlatform$
|
|
3076
|
-
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)))));
|
|
3077
3083
|
}
|
|
3078
|
-
function platformFailure$
|
|
3079
|
-
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);
|
|
3080
3086
|
}
|
|
3081
3087
|
function invalidInput(operation, candidate, detail) {
|
|
3082
|
-
return failure$
|
|
3088
|
+
return failure$5(operation, "InvalidInput", candidate, detail);
|
|
3083
3089
|
}
|
|
3084
3090
|
function checked(operation, evaluate) {
|
|
3085
3091
|
return Effect.try({
|
|
3086
3092
|
try: evaluate,
|
|
3087
|
-
catch: (cause) => isContentWorkspaceFailure(cause) ? cause : failure$
|
|
3093
|
+
catch: (cause) => isContentWorkspaceFailure(cause) ? cause : failure$5(operation, "InvalidInput", void 0, errorMessage$3(cause))
|
|
3088
3094
|
});
|
|
3089
3095
|
}
|
|
3090
3096
|
function isContentWorkspaceFailure(input) {
|
|
3091
3097
|
return typeof input === "object" && input !== null && "_tag" in input && input._tag === "ContentWorkspaceFailure";
|
|
3092
3098
|
}
|
|
3093
|
-
function fail$
|
|
3094
|
-
return Effect.fail(failure$
|
|
3099
|
+
function fail$5(operation, reason, candidate, detail) {
|
|
3100
|
+
return Effect.fail(failure$5(operation, reason, candidate, detail));
|
|
3095
3101
|
}
|
|
3096
|
-
function failure$
|
|
3102
|
+
function failure$5(operation, reason, candidate, detail) {
|
|
3097
3103
|
return Object.freeze({
|
|
3098
3104
|
_tag: "ContentWorkspaceFailure",
|
|
3099
3105
|
operation,
|
|
@@ -3102,10 +3108,10 @@ function failure$4(operation, reason, candidate, detail) {
|
|
|
3102
3108
|
detail
|
|
3103
3109
|
});
|
|
3104
3110
|
}
|
|
3105
|
-
function errorMessage$
|
|
3111
|
+
function errorMessage$3(error) {
|
|
3106
3112
|
return error instanceof Error ? error.message : String(error);
|
|
3107
3113
|
}
|
|
3108
|
-
function compareText$
|
|
3114
|
+
function compareText$9(left, right) {
|
|
3109
3115
|
const leftBytes = encoder.encode(left);
|
|
3110
3116
|
const rightBytes = encoder.encode(right);
|
|
3111
3117
|
const length = Math.min(leftBytes.length, rightBytes.length);
|
|
@@ -3152,6 +3158,428 @@ function defineNodeFilesystemRuntimeProvider() {
|
|
|
3152
3158
|
});
|
|
3153
3159
|
}
|
|
3154
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
|
|
3155
3583
|
//#region ../../resources/native-agent-provider/providers/effect-platform-node-shared.ts
|
|
3156
3584
|
const MAX_PROCESS_OUTPUT_BYTES = 4194304;
|
|
3157
3585
|
const PROCESS_START_TIMEOUT = "10 seconds";
|
|
@@ -3165,21 +3593,45 @@ const processSemaphores = /* @__PURE__ */ new Map();
|
|
|
3165
3593
|
* The concrete provider fixes its ordinary command before acquisition; the
|
|
3166
3594
|
* caller supplies only the provider-owned home for this session.
|
|
3167
3595
|
*/
|
|
3168
|
-
function acquireEffectPlatformNodeProvider(provider, command, input) {
|
|
3596
|
+
function acquireEffectPlatformNodeProvider(provider, command, input, options = {}) {
|
|
3169
3597
|
return Effect.gen(function* () {
|
|
3170
3598
|
if (!Value.Check(NativeProviderSessionInputSchema, input)) return yield* fail$3(provider, "acquire", "InvalidInput", "not-started", void 0, "Provider session input is invalid");
|
|
3171
3599
|
const fs = yield* FileSystem.FileSystem;
|
|
3172
3600
|
const paths = yield* Path.Path;
|
|
3173
3601
|
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
3174
3602
|
const home = yield* requireCanonicalDirectory(fs, paths, provider, "acquire", input.home);
|
|
3175
|
-
const
|
|
3176
|
-
|
|
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)));
|
|
3177
3617
|
const run = (operation, args) => runCommand({
|
|
3178
3618
|
provider,
|
|
3179
3619
|
operation,
|
|
3180
3620
|
command,
|
|
3181
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,
|
|
3182
3632
|
args,
|
|
3633
|
+
cwd,
|
|
3634
|
+
env: mergeProcessEnvironment(env),
|
|
3183
3635
|
spawner
|
|
3184
3636
|
});
|
|
3185
3637
|
const mutation = (operation, args) => run(operation, args).pipe(Effect.as(Object.freeze({
|
|
@@ -3188,19 +3640,51 @@ function acquireEffectPlatformNodeProvider(provider, command, input) {
|
|
|
3188
3640
|
commandPhase: "command-returned"
|
|
3189
3641
|
})));
|
|
3190
3642
|
const requireLocalDirectory = (operation, candidate) => requireCanonicalDirectory(fs, paths, provider, operation, candidate);
|
|
3191
|
-
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);
|
|
3192
3651
|
return Object.freeze({
|
|
3193
3652
|
provider,
|
|
3194
3653
|
home,
|
|
3654
|
+
geminiRoot,
|
|
3655
|
+
fs,
|
|
3656
|
+
paths,
|
|
3195
3657
|
serialized,
|
|
3196
3658
|
run,
|
|
3659
|
+
runExternalCommand,
|
|
3197
3660
|
mutation,
|
|
3198
3661
|
requireLocalDirectory,
|
|
3199
3662
|
readPluginEntry,
|
|
3663
|
+
readOptionalHomeJson,
|
|
3664
|
+
readClaudeUserConfigJson,
|
|
3665
|
+
readCodexConfigToml,
|
|
3666
|
+
readAntigravityMcpConfigJson,
|
|
3667
|
+
readManagedMcpLedger,
|
|
3668
|
+
writeManagedMcpLedger,
|
|
3669
|
+
sweepTransientMcpLedger,
|
|
3200
3670
|
homePath: (...segments) => paths.join(home, ...segments)
|
|
3201
3671
|
});
|
|
3202
3672
|
});
|
|
3203
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
|
+
}
|
|
3204
3688
|
/** Validates a marketplace source before a concrete provider constructs native arguments. */
|
|
3205
3689
|
function requireMarketplaceSource(provider, operation, source) {
|
|
3206
3690
|
return Value.Check(NativeMarketplaceSourceSchema, source) ? Effect.succeed(source) : fail$3(provider, operation, "InvalidInput", "not-started", void 0, "Marketplace source is invalid");
|
|
@@ -3227,6 +3711,25 @@ function requireMarketplaceIdentityInput(provider, operation, input) {
|
|
|
3227
3711
|
function requirePluginSelectorInput(provider, operation, input) {
|
|
3228
3712
|
return Value.Check(NativeProviderPluginSelectorInputSchema, input) ? Effect.succeed(input.selector) : fail$3(provider, operation, "InvalidInput", "not-started", void 0, "Plugin selector is not canonical");
|
|
3229
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
|
+
relevantOwnerPluginIds: void 0
|
|
3719
|
+
}));
|
|
3720
|
+
return Value.Check(NativeProviderInventoryOptionsSchema, options) ? Effect.succeed(Object.freeze({
|
|
3721
|
+
observeMcpServers: options.observeMcpServers ?? true,
|
|
3722
|
+
relevantOwnerPluginIds: options.relevantOwnerPluginIds === void 0 ? void 0 : Object.freeze([...options.relevantOwnerPluginIds])
|
|
3723
|
+
})) : fail$3(provider, "inventory", "InvalidInput", "not-started", void 0, "Provider inventory options are invalid");
|
|
3724
|
+
}
|
|
3725
|
+
/** Validates one host-scoped HTTP MCP server add request before native command construction. */
|
|
3726
|
+
function requireMcpServerAddInput(provider, operation, input) {
|
|
3727
|
+
return Value.Check(NativeProviderMcpServerAddInputSchema, input) ? Effect.succeed(input) : fail$3(provider, operation, "InvalidInput", "not-started", void 0, "MCP server add input is not canonical");
|
|
3728
|
+
}
|
|
3729
|
+
/** Validates one MCP server name before native removal argument construction. */
|
|
3730
|
+
function requireMcpServerRemoveInput(provider, operation, input) {
|
|
3731
|
+
return Value.Check(NativeProviderMcpServerRemoveInputSchema, input) ? Effect.succeed(input.name) : fail$3(provider, operation, "InvalidInput", "not-started", void 0, "MCP server name is not canonical");
|
|
3732
|
+
}
|
|
3230
3733
|
/** Validates one bounded point-addressed plugin-file read request. */
|
|
3231
3734
|
function requirePluginFilesReadInput(provider, operation, input) {
|
|
3232
3735
|
return Value.Check(NativeProviderPluginFilesReadInputSchema, input) ? Effect.succeed(input) : fail$3(provider, operation, "InvalidInput", "not-started", void 0, "Plugin file batch request is invalid");
|
|
@@ -3252,15 +3755,46 @@ function requireGitMarketplaceSource(provider, operation, repositoryUrl, revisio
|
|
|
3252
3755
|
return Object.freeze({
|
|
3253
3756
|
repositoryUrl,
|
|
3254
3757
|
revision,
|
|
3255
|
-
sparsePaths: Object.freeze([...present].sort(compareText$
|
|
3758
|
+
sparsePaths: Object.freeze([...present].sort(compareText$7))
|
|
3256
3759
|
});
|
|
3257
3760
|
});
|
|
3258
3761
|
}
|
|
3259
3762
|
function runCommand(input) {
|
|
3763
|
+
return Effect.gen(function* () {
|
|
3764
|
+
const cwd = input.provider === "antigravity" ? yield* prepareAntigravityGeminiRoot(input.fs, input.paths, input.operation, input.home) : input.home;
|
|
3765
|
+
const env = providerEnvironment(input.paths, input.provider, input.home, input.claudeUserHome);
|
|
3766
|
+
return yield* spawnBoundedCommand({
|
|
3767
|
+
provider: input.provider,
|
|
3768
|
+
operation: input.operation,
|
|
3769
|
+
command: input.command,
|
|
3770
|
+
args: input.args,
|
|
3771
|
+
cwd,
|
|
3772
|
+
env,
|
|
3773
|
+
spawner: input.spawner
|
|
3774
|
+
});
|
|
3775
|
+
});
|
|
3776
|
+
}
|
|
3777
|
+
function prepareAntigravityGeminiRoot(fs, paths, operation, home) {
|
|
3778
|
+
const { agyProcessHome, geminiRoot } = antigravityHomeLayout(paths, home);
|
|
3779
|
+
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)))));
|
|
3780
|
+
}
|
|
3781
|
+
function requireNoAncestorAgentsDirectory(fs, paths, operation, agyProcessHome) {
|
|
3782
|
+
return Effect.gen(function* () {
|
|
3783
|
+
let current = paths.dirname(agyProcessHome);
|
|
3784
|
+
while (true) {
|
|
3785
|
+
const candidate = paths.join(current, ".agents");
|
|
3786
|
+
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");
|
|
3787
|
+
const parent = paths.dirname(current);
|
|
3788
|
+
if (parent === current) break;
|
|
3789
|
+
current = parent;
|
|
3790
|
+
}
|
|
3791
|
+
});
|
|
3792
|
+
}
|
|
3793
|
+
function spawnBoundedCommand(input) {
|
|
3260
3794
|
const command = ChildProcess.make(input.command, input.args, {
|
|
3261
|
-
cwd: input.
|
|
3262
|
-
env:
|
|
3263
|
-
extendEnv:
|
|
3795
|
+
cwd: input.cwd,
|
|
3796
|
+
env: input.env,
|
|
3797
|
+
extendEnv: false,
|
|
3264
3798
|
stdin: "ignore",
|
|
3265
3799
|
forceKillAfter: PROCESS_FORCE_KILL_AFTER$2
|
|
3266
3800
|
});
|
|
@@ -3295,14 +3829,20 @@ function collectBoundedOutput$3(stream, provider, operation, phase) {
|
|
|
3295
3829
|
catch: (cause) => failure$3(provider, operation, "ProtocolFailed", phase, void 0, errorMessage$1(cause))
|
|
3296
3830
|
})));
|
|
3297
3831
|
}
|
|
3298
|
-
function
|
|
3832
|
+
function resolvePluginRootInput(fs, paths, provider, operation, home, claudeUserHome, rootInput) {
|
|
3833
|
+
if (provider !== "claude" || claudeUserHome === null || !isCanonicalAbsolutePath(paths, rootInput)) return Effect.succeed(rootInput);
|
|
3834
|
+
const claudeDefaultHomeAlias = paths.join(claudeUserHome, ".claude");
|
|
3835
|
+
if (rootInput !== claudeDefaultHomeAlias && !isContained$2(paths, claudeDefaultHomeAlias, rootInput)) return Effect.succeed(rootInput);
|
|
3836
|
+
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")));
|
|
3837
|
+
}
|
|
3838
|
+
function readBoundedPluginFile(fs, paths, provider, operation, home, claudeUserHome, rootInput, input) {
|
|
3299
3839
|
return Effect.gen(function* () {
|
|
3300
3840
|
const relativePath = canonicalRelativeFile(input.relativePath);
|
|
3301
3841
|
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");
|
|
3302
|
-
const root = yield* requireCanonicalDirectory(fs, paths, provider, operation, rootInput);
|
|
3303
|
-
if (!isContained(paths, home, root)) return yield* fail$3(provider, operation, "Aliased", "not-started", root, "Installed plugin root escaped the explicit provider home");
|
|
3842
|
+
const root = yield* requireCanonicalDirectory(fs, paths, provider, operation, yield* resolvePluginRootInput(fs, paths, provider, operation, home, claudeUserHome, rootInput));
|
|
3843
|
+
if (!isContained$2(paths, home, root)) return yield* fail$3(provider, operation, "Aliased", "not-started", root, "Installed plugin root escaped the explicit provider home");
|
|
3304
3844
|
const candidate = paths.join(root, ...relativePath.split("/"));
|
|
3305
|
-
if (!isContained(paths, root, candidate)) return yield* fail$3(provider, operation, "Aliased", "not-started", candidate, "Plugin file path escaped its installed package root");
|
|
3845
|
+
if (!isContained$2(paths, root, candidate)) return yield* fail$3(provider, operation, "Aliased", "not-started", candidate, "Plugin file path escaped its installed package root");
|
|
3306
3846
|
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");
|
|
3307
3847
|
const status = yield* fs.stat(candidate).pipe(mapPlatform$3(provider, operation, candidate, "not-started"));
|
|
3308
3848
|
const size = Number(status.size);
|
|
@@ -3337,12 +3877,40 @@ function canonicalRelativeFile(input) {
|
|
|
3337
3877
|
function isCanonicalAbsolutePath(paths, candidate) {
|
|
3338
3878
|
return candidate.length <= 16384 && paths.isAbsolute(candidate) && paths.normalize(candidate) === candidate && candidate !== paths.parse(candidate).root;
|
|
3339
3879
|
}
|
|
3340
|
-
function isContained(paths, root, candidate) {
|
|
3880
|
+
function isContained$2(paths, root, candidate) {
|
|
3341
3881
|
const relative = paths.relative(root, candidate);
|
|
3342
3882
|
return relative !== "" && relative !== ".." && !relative.startsWith(`..${paths.sep}`) && !paths.isAbsolute(relative);
|
|
3343
3883
|
}
|
|
3344
|
-
function
|
|
3345
|
-
return
|
|
3884
|
+
function antigravityHomeLayout(paths, home) {
|
|
3885
|
+
return paths.basename(home) === ".gemini" ? Object.freeze({
|
|
3886
|
+
agyProcessHome: paths.dirname(home),
|
|
3887
|
+
geminiRoot: home
|
|
3888
|
+
}) : Object.freeze({
|
|
3889
|
+
agyProcessHome: home,
|
|
3890
|
+
geminiRoot: paths.join(home, ".gemini")
|
|
3891
|
+
});
|
|
3892
|
+
}
|
|
3893
|
+
function copyDefinedProcessEnv(skipKey) {
|
|
3894
|
+
const env = {};
|
|
3895
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
3896
|
+
if (value === void 0 || key === skipKey) continue;
|
|
3897
|
+
env[key] = value;
|
|
3898
|
+
}
|
|
3899
|
+
return env;
|
|
3900
|
+
}
|
|
3901
|
+
function mergeProcessEnvironment(overrides) {
|
|
3902
|
+
const env = copyDefinedProcessEnv();
|
|
3903
|
+
for (const [key, value] of Object.entries(overrides)) if (value === void 0) delete env[key];
|
|
3904
|
+
else env[key] = value;
|
|
3905
|
+
return env;
|
|
3906
|
+
}
|
|
3907
|
+
function providerEnvironment(paths, provider, home, claudeUserHome) {
|
|
3908
|
+
const env = copyDefinedProcessEnv(provider === "claude" && claudeUserHome !== null ? "CLAUDE_CONFIG_DIR" : void 0);
|
|
3909
|
+
if (provider === "codex") env.CODEX_HOME = home;
|
|
3910
|
+
else if (provider === "antigravity") env.HOME = antigravityHomeLayout(paths, home).agyProcessHome;
|
|
3911
|
+
else if (claudeUserHome !== null) env.HOME = claudeUserHome;
|
|
3912
|
+
else env.CLAUDE_CONFIG_DIR = home;
|
|
3913
|
+
return env;
|
|
3346
3914
|
}
|
|
3347
3915
|
function processSemaphore(provider, home) {
|
|
3348
3916
|
const key = `${provider}\u0000${home}`;
|
|
@@ -3385,124 +3953,1444 @@ function failure$3(provider, operation, reason, commandPhase, candidate, detail)
|
|
|
3385
3953
|
function errorMessage$1(error) {
|
|
3386
3954
|
return error instanceof Error ? error.message : String(error);
|
|
3387
3955
|
}
|
|
3388
|
-
function compareText$
|
|
3956
|
+
function compareText$7(left, right) {
|
|
3389
3957
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
3390
3958
|
}
|
|
3391
3959
|
//#endregion
|
|
3392
|
-
//#region ../../resources/native-agent-provider/dist/providers/
|
|
3393
|
-
const
|
|
3394
|
-
const
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3960
|
+
//#region ../../resources/native-agent-provider/dist/providers/antigravity-effect-platform-node/ledger.js
|
|
3961
|
+
const utf8Decoder$1 = new TextDecoder("utf-8", { fatal: true });
|
|
3962
|
+
const utf8Encoder$1 = new TextEncoder();
|
|
3963
|
+
/** Provider-owned ledger filename stored under `<geminiRoot>/config/` outside installed plugins. */
|
|
3964
|
+
const PLUGIN_LEDGER_FILENAME = ".habitat-plugin-ledger.json";
|
|
3965
|
+
const MAX_PLUGIN_LEDGER_BYTES = 2097152;
|
|
3966
|
+
/** Canonical lowercase plugin identifier required for Habitat-managed Antigravity installs. */
|
|
3967
|
+
const CanonicalPluginNameSchema = Type.String({
|
|
3968
|
+
pattern: "^[a-z0-9][a-z0-9._-]*$",
|
|
3969
|
+
maxLength: 128
|
|
3398
3970
|
});
|
|
3399
|
-
const
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
"marketplace-add",
|
|
3418
|
-
"marketplace-remove",
|
|
3419
|
-
"marketplace-update",
|
|
3420
|
-
"plugin-list",
|
|
3421
|
-
"plugin-install",
|
|
3422
|
-
"plugin-enable",
|
|
3423
|
-
"plugin-disable",
|
|
3424
|
-
"plugin-remove",
|
|
3425
|
-
"plugin-update"
|
|
3426
|
-
];
|
|
3971
|
+
const MarketplaceNameSchema$1 = Type.String({
|
|
3972
|
+
pattern: "^[a-z0-9][a-z0-9_-]*$",
|
|
3973
|
+
maxLength: 128
|
|
3974
|
+
});
|
|
3975
|
+
const Sha256HexSchema = Type.String({ pattern: "^[0-9a-f]{64}$" });
|
|
3976
|
+
const PluginLedgerEntrySchema = Type.Object({
|
|
3977
|
+
name: CanonicalPluginNameSchema,
|
|
3978
|
+
marketplaceIdentity: MarketplaceNameSchema$1,
|
|
3979
|
+
installedTreeSha256: Sha256HexSchema,
|
|
3980
|
+
acceptedTreeSha256s: Type.Optional(Type.Array(Sha256HexSchema, {
|
|
3981
|
+
minItems: 1,
|
|
3982
|
+
maxItems: 2
|
|
3983
|
+
}))
|
|
3984
|
+
}, { additionalProperties: false });
|
|
3985
|
+
const PluginLedgerSchema = Type.Object({
|
|
3986
|
+
schemaVersion: Type.Literal(1),
|
|
3987
|
+
plugins: Type.Array(PluginLedgerEntrySchema, { maxItems: 4096 })
|
|
3988
|
+
}, { additionalProperties: false });
|
|
3427
3989
|
/**
|
|
3428
|
-
*
|
|
3990
|
+
* Checks whether a live plugin directory digest matches an entry recorded in the Habitat ledger.
|
|
3429
3991
|
*/
|
|
3430
|
-
function
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
"
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
installPlugin: (request) => kernel.serialized("plugin-install", requirePluginSelectorInput("claude", "plugin-install", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-install", "install", selector)))),
|
|
3471
|
-
enablePlugin: (request) => kernel.serialized("plugin-enable", requirePluginSelectorInput("claude", "plugin-enable", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-enable", "enable", selector)))),
|
|
3472
|
-
removePlugin: (request) => kernel.serialized("plugin-remove", requirePluginSelectorInput("claude", "plugin-remove", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-remove", "uninstall", selector))))
|
|
3992
|
+
function isLedgerAcceptedDigest(entry, liveTreeSha256) {
|
|
3993
|
+
return entry !== void 0 && liveTreeSha256 !== null && entry.acceptedTreeSha256s.includes(liveTreeSha256);
|
|
3994
|
+
}
|
|
3995
|
+
/**
|
|
3996
|
+
* Computes the canonical whole-tree SHA-256 over all regular files in a plugin directory,
|
|
3997
|
+
* skipping any top-level `.in_use` runtime directory created by the Antigravity desktop app.
|
|
3998
|
+
*/
|
|
3999
|
+
function computeDirectoryTreeSha256(kernel, operation, containmentRoot, pluginRoot, phase) {
|
|
4000
|
+
return Effect.gen(function* () {
|
|
4001
|
+
if (!isContained$1(kernel.paths, containmentRoot, pluginRoot)) return yield* Effect.fail(ledgerFailure(operation, "Aliased", phase, "Plugin directory escaped its containment root", pluginRoot));
|
|
4002
|
+
const verifiedRoot = yield* kernel.requireLocalDirectory(operation, pluginRoot).pipe(Effect.mapError((error) => ({
|
|
4003
|
+
...error,
|
|
4004
|
+
commandPhase: phase
|
|
4005
|
+
})));
|
|
4006
|
+
const collected = [];
|
|
4007
|
+
const visit = (currentDir, prefix) => Effect.gen(function* () {
|
|
4008
|
+
const names = yield* kernel.fs.readDirectory(currentDir).pipe(mapLedgerFs(operation, currentDir, phase));
|
|
4009
|
+
for (const name of [...names].sort(compareText$6)) {
|
|
4010
|
+
if (prefix === "" && name === ".in_use") continue;
|
|
4011
|
+
const candidate = kernel.paths.join(currentDir, name);
|
|
4012
|
+
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));
|
|
4013
|
+
const stat = yield* kernel.fs.stat(candidate).pipe(mapLedgerFs(operation, candidate, phase));
|
|
4014
|
+
const relativePath = prefix === "" ? name : `${prefix}/${name}`;
|
|
4015
|
+
if (stat.type === "Directory") {
|
|
4016
|
+
yield* visit(candidate, relativePath);
|
|
4017
|
+
continue;
|
|
4018
|
+
}
|
|
4019
|
+
if (stat.type !== "File") return yield* Effect.fail(ledgerFailure(operation, "UnsupportedEntry", phase, "Plugin tree entry must be a regular file or directory", candidate));
|
|
4020
|
+
if (collected.length >= 16384) return yield* Effect.fail(ledgerFailure(operation, "LimitExceeded", phase, "Plugin tree file count exceeds the provider bound", verifiedRoot));
|
|
4021
|
+
const size = Number(stat.size);
|
|
4022
|
+
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));
|
|
4023
|
+
const bytes = yield* kernel.fs.readFile(candidate).pipe(mapLedgerFs(operation, candidate, phase));
|
|
4024
|
+
const mode = (Number(stat.mode) & 73) !== 0 ? "0755" : "0644";
|
|
4025
|
+
const fileSha256 = createHash("sha256").update(bytes).digest("hex");
|
|
4026
|
+
collected.push(Object.freeze({
|
|
4027
|
+
path: relativePath,
|
|
4028
|
+
mode,
|
|
4029
|
+
fileSha256
|
|
4030
|
+
}));
|
|
4031
|
+
}
|
|
3473
4032
|
});
|
|
3474
|
-
|
|
4033
|
+
yield* visit(verifiedRoot, "");
|
|
4034
|
+
collected.sort((left, right) => compareText$6(left.path, right.path));
|
|
4035
|
+
const hash = createHash("sha256");
|
|
4036
|
+
for (const item of collected) hash.update(`${item.path}\u0000${item.mode}\u0000${item.fileSha256}\n`);
|
|
4037
|
+
return hash.digest("hex");
|
|
4038
|
+
});
|
|
3475
4039
|
}
|
|
3476
4040
|
/**
|
|
3477
|
-
*
|
|
3478
|
-
*
|
|
4041
|
+
* Computes the whole-tree SHA-256 for a ledger-known installed plugin directory.
|
|
4042
|
+
*
|
|
4043
|
+
* Missing, aliased, or non-directory roots return `null` so inventory treats the slot as
|
|
4044
|
+
* unmanaged, while `FilesystemFailed` (such as `EACCES`) and `LimitExceeded` propagate as
|
|
4045
|
+
* typed provider failures rather than misclassifying I/O errors as foreign collisions.
|
|
3479
4046
|
*/
|
|
3480
|
-
function
|
|
3481
|
-
|
|
3482
|
-
return
|
|
4047
|
+
function readLedgerKnownPluginTreeSha256(kernel, operation, pluginRootCandidate, phase) {
|
|
4048
|
+
if (pluginRootCandidate === null || !isContained$1(kernel.paths, kernel.home, pluginRootCandidate)) return Effect.succeed(null);
|
|
4049
|
+
return computeDirectoryTreeSha256(kernel, operation, kernel.home, pluginRootCandidate, phase).pipe(Effect.catchIf((error) => error.reason === "Missing" || error.reason === "Aliased" || error.reason === "UnsupportedEntry", () => Effect.succeed(null)));
|
|
3483
4050
|
}
|
|
3484
|
-
|
|
4051
|
+
/**
|
|
4052
|
+
* Reads and validates `<geminiRoot>/config/.habitat-plugin-ledger.json`.
|
|
4053
|
+
*/
|
|
4054
|
+
function readPluginLedger(kernel, operation, phase) {
|
|
3485
4055
|
return Effect.gen(function* () {
|
|
3486
|
-
const
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
4056
|
+
const ledgerPath = kernel.paths.join(kernel.geminiRoot, "config", PLUGIN_LEDGER_FILENAME);
|
|
4057
|
+
if (!(yield* kernel.fs.exists(ledgerPath).pipe(mapLedgerFs(operation, ledgerPath, phase)))) return Object.freeze([]);
|
|
4058
|
+
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));
|
|
4059
|
+
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));
|
|
4060
|
+
const stat = yield* kernel.fs.stat(ledgerPath).pipe(mapLedgerFs(operation, ledgerPath, phase));
|
|
4061
|
+
if (stat.type !== "File") return yield* Effect.fail(ledgerFailure(operation, "UnsupportedEntry", phase, "Plugin ledger must be a regular file", ledgerPath));
|
|
4062
|
+
const size = Number(stat.size);
|
|
4063
|
+
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));
|
|
4064
|
+
const bytes = yield* kernel.fs.readFile(ledgerPath).pipe(mapLedgerFs(operation, ledgerPath, phase));
|
|
4065
|
+
const rawText = yield* Effect.try({
|
|
4066
|
+
try: () => utf8Decoder$1.decode(bytes),
|
|
4067
|
+
catch: () => ledgerFailure(operation, "ProtocolFailed", phase, "Plugin ledger is not valid UTF-8", ledgerPath)
|
|
4068
|
+
});
|
|
4069
|
+
const decoded = yield* decodeLedgerJson(operation, PluginLedgerSchema, rawText, phase);
|
|
4070
|
+
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));
|
|
4071
|
+
return Object.freeze(decoded.plugins.map((entry) => {
|
|
4072
|
+
const accepted = entry.acceptedTreeSha256s === void 0 ? [entry.installedTreeSha256] : [.../* @__PURE__ */ new Set([entry.installedTreeSha256, ...entry.acceptedTreeSha256s])].slice(0, 2);
|
|
4073
|
+
return Object.freeze({
|
|
4074
|
+
name: entry.name,
|
|
4075
|
+
marketplaceIdentity: entry.marketplaceIdentity,
|
|
4076
|
+
installedTreeSha256: entry.installedTreeSha256,
|
|
4077
|
+
acceptedTreeSha256s: Object.freeze(accepted)
|
|
4078
|
+
});
|
|
4079
|
+
}));
|
|
4080
|
+
});
|
|
4081
|
+
}
|
|
4082
|
+
/**
|
|
4083
|
+
* Records a pending plugin install in `.habitat-plugin-ledger.json` BEFORE invoking `agy plugin install`
|
|
4084
|
+
* so neither pre-copy failure nor post-copy crash/non-zero exit can strand ownership attribution.
|
|
4085
|
+
*/
|
|
4086
|
+
function recordPendingPluginInstall(kernel, existingLedger, input) {
|
|
4087
|
+
return Effect.gen(function* () {
|
|
4088
|
+
const accepted = input.previousTreeSha256 !== null && input.previousTreeSha256 !== input.stagedTreeSha256 ? Object.freeze([input.previousTreeSha256, input.stagedTreeSha256]) : Object.freeze([input.stagedTreeSha256]);
|
|
4089
|
+
const byName = new Map(existingLedger.map((entry) => [entry.name, entry]));
|
|
4090
|
+
byName.set(input.name, Object.freeze({
|
|
4091
|
+
name: input.name,
|
|
4092
|
+
marketplaceIdentity: input.marketplaceIdentity,
|
|
4093
|
+
installedTreeSha256: input.stagedTreeSha256,
|
|
4094
|
+
acceptedTreeSha256s: accepted
|
|
4095
|
+
}));
|
|
4096
|
+
yield* writePluginLedger(kernel, "plugin-install", [...byName.values()], "not-started");
|
|
4097
|
+
return Object.freeze({ needsPostInstallSettle: accepted.length > 1 });
|
|
4098
|
+
});
|
|
4099
|
+
}
|
|
4100
|
+
/**
|
|
4101
|
+
* Narrows `acceptedTreeSha256s` to `[stagedTreeSha256]` once `agy plugin install` completes cleanly.
|
|
4102
|
+
*/
|
|
4103
|
+
function settlePluginInstall(kernel, input) {
|
|
4104
|
+
return Effect.gen(function* () {
|
|
4105
|
+
const existing = yield* readPluginLedger(kernel, "plugin-install", "command-returned");
|
|
4106
|
+
const byName = new Map(existing.map((entry) => [entry.name, entry]));
|
|
4107
|
+
byName.set(input.name, Object.freeze({
|
|
4108
|
+
name: input.name,
|
|
4109
|
+
marketplaceIdentity: input.marketplaceIdentity,
|
|
4110
|
+
installedTreeSha256: input.stagedTreeSha256,
|
|
4111
|
+
acceptedTreeSha256s: Object.freeze([input.stagedTreeSha256])
|
|
4112
|
+
}));
|
|
4113
|
+
yield* writePluginLedger(kernel, "plugin-install", [...byName.values()], "command-returned");
|
|
4114
|
+
});
|
|
4115
|
+
}
|
|
4116
|
+
/**
|
|
4117
|
+
* Removes only `removedName` from `.habitat-plugin-ledger.json` without pruning unrelated entries.
|
|
4118
|
+
*/
|
|
4119
|
+
function deletePluginLedgerEntry(kernel, operation, removedName) {
|
|
4120
|
+
return Effect.gen(function* () {
|
|
4121
|
+
const existing = yield* readPluginLedger(kernel, operation, "command-returned");
|
|
4122
|
+
const retained = existing.filter((entry) => entry.name !== removedName);
|
|
4123
|
+
if (retained.length === existing.length) return;
|
|
4124
|
+
yield* writePluginLedger(kernel, operation, retained, "command-returned");
|
|
4125
|
+
});
|
|
4126
|
+
}
|
|
4127
|
+
/**
|
|
4128
|
+
* Sweeps crash-leftover `<geminiRoot>/config/.habitat-plugin-ledger.json.tmp-*` and
|
|
4129
|
+
* `<geminiRoot>/config/.habitat-host-mcp-ledger.json.tmp-*` regular files and
|
|
4130
|
+
* `<geminiRoot>/config/marketplaces/.staging-*` entries at the start of serialized provider
|
|
4131
|
+
* mutations without following symbolic links.
|
|
4132
|
+
*/
|
|
4133
|
+
function sweepAntigravityTransientArtifacts(kernel, operation) {
|
|
4134
|
+
return Effect.gen(function* () {
|
|
4135
|
+
if (!(yield* kernel.fs.exists(kernel.geminiRoot).pipe(mapLedgerFs(operation, kernel.geminiRoot, "not-started")))) return;
|
|
4136
|
+
yield* kernel.requireLocalDirectory(operation, kernel.geminiRoot).pipe(Effect.mapError((error) => ({
|
|
4137
|
+
...error,
|
|
4138
|
+
commandPhase: "not-started"
|
|
4139
|
+
})));
|
|
4140
|
+
const configDir = kernel.paths.join(kernel.geminiRoot, "config");
|
|
4141
|
+
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));
|
|
4142
|
+
if (!(yield* kernel.fs.exists(configDir).pipe(mapLedgerFs(operation, configDir, "not-started")))) return;
|
|
4143
|
+
const verifiedConfigDir = yield* kernel.requireLocalDirectory(operation, configDir).pipe(Effect.mapError((error) => ({
|
|
4144
|
+
...error,
|
|
4145
|
+
commandPhase: "not-started"
|
|
4146
|
+
})));
|
|
4147
|
+
yield* sweepTransientMcpLedgerArtifacts(kernel.fs, kernel.paths, "antigravity", operation, verifiedConfigDir, "not-started");
|
|
4148
|
+
const pluginLedgerTempPrefix = `${PLUGIN_LEDGER_FILENAME}.tmp-`;
|
|
4149
|
+
const configEntries = yield* kernel.fs.readDirectory(verifiedConfigDir).pipe(mapLedgerFs(operation, verifiedConfigDir, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed([])));
|
|
4150
|
+
const nowMs = Date.now();
|
|
4151
|
+
for (const name of [...configEntries].sort(compareText$6)) {
|
|
4152
|
+
if (!name.startsWith(pluginLedgerTempPrefix)) continue;
|
|
4153
|
+
const candidate = kernel.paths.join(verifiedConfigDir, name);
|
|
4154
|
+
if (!isContained$1(kernel.paths, verifiedConfigDir, candidate)) continue;
|
|
4155
|
+
const info = yield* lstatOptional(kernel, operation, candidate);
|
|
4156
|
+
if (info === null || info.type === "SymbolicLink") continue;
|
|
4157
|
+
if (info.type === "File") {
|
|
4158
|
+
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));
|
|
4159
|
+
} else if (info.type === "Directory") yield* removeEmptyDirectoryNonRecursive("antigravity", operation, candidate, "not-started");
|
|
4160
|
+
}
|
|
4161
|
+
const marketplacesDir = kernel.paths.join(verifiedConfigDir, "marketplaces");
|
|
4162
|
+
if (!(yield* kernel.fs.exists(marketplacesDir).pipe(mapLedgerFs(operation, marketplacesDir, "not-started")))) return;
|
|
4163
|
+
const verifiedMarketplacesDir = yield* kernel.requireLocalDirectory(operation, marketplacesDir).pipe(Effect.mapError((error) => ({
|
|
4164
|
+
...error,
|
|
4165
|
+
commandPhase: "not-started"
|
|
4166
|
+
})));
|
|
4167
|
+
const stagingLivePidPattern = /^\.staging-[a-z0-9][a-z0-9_-]*-([1-9][0-9]{0,9})-[0-9]+-/u;
|
|
4168
|
+
const marketplaceEntries = yield* kernel.fs.readDirectory(verifiedMarketplacesDir).pipe(mapLedgerFs(operation, verifiedMarketplacesDir, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed([])));
|
|
4169
|
+
for (const name of [...marketplaceEntries].sort(compareText$6)) {
|
|
4170
|
+
if (!name.startsWith(".staging-")) continue;
|
|
4171
|
+
const stagingPidMatch = stagingLivePidPattern.exec(name);
|
|
4172
|
+
if (stagingPidMatch !== null) {
|
|
4173
|
+
const stagingPid = Number(stagingPidMatch[1]);
|
|
4174
|
+
if (Number.isSafeInteger(stagingPid) && stagingPid > 0 && isProcessAlive(stagingPid)) continue;
|
|
4175
|
+
}
|
|
4176
|
+
yield* removeContainedTransientEntry(kernel, operation, verifiedMarketplacesDir, kernel.paths.join(verifiedMarketplacesDir, name));
|
|
4177
|
+
}
|
|
4178
|
+
});
|
|
4179
|
+
}
|
|
4180
|
+
function removeContainedTransientEntry(kernel, operation, containmentRoot, candidate) {
|
|
4181
|
+
return Effect.gen(function* () {
|
|
4182
|
+
if (!isContained$1(kernel.paths, containmentRoot, candidate)) return;
|
|
4183
|
+
const info = yield* lstatOptional(kernel, operation, candidate);
|
|
4184
|
+
if (info === null || info.type === "SymbolicLink") return;
|
|
4185
|
+
if (info.type === "Directory") {
|
|
4186
|
+
const children = yield* kernel.fs.readDirectory(candidate).pipe(mapLedgerFs(operation, candidate, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.succeed([])));
|
|
4187
|
+
for (const child of [...children].sort(compareText$6)) yield* removeContainedTransientEntry(kernel, operation, containmentRoot, kernel.paths.join(candidate, child));
|
|
4188
|
+
yield* removeEmptyDirectoryNonRecursive("antigravity", operation, candidate, "not-started");
|
|
4189
|
+
return;
|
|
4190
|
+
}
|
|
4191
|
+
yield* kernel.fs.remove(candidate).pipe(mapLedgerFs(operation, candidate, "not-started"), Effect.catchIf((error) => error.reason === "Missing", () => Effect.void));
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
4194
|
+
function lstatOptional(kernel, operation, candidate) {
|
|
4195
|
+
return kernel.fs.lstat(candidate).pipe(Effect.catchIf((cause) => cause.reason._tag === "NotFound", () => Effect.succeed(null)), mapLedgerFs(operation, candidate, "not-started"));
|
|
4196
|
+
}
|
|
4197
|
+
function writePluginLedger(kernel, operation, entries, phase) {
|
|
4198
|
+
return Effect.gen(function* () {
|
|
4199
|
+
const configDir = kernel.paths.join(kernel.geminiRoot, "config");
|
|
4200
|
+
yield* kernel.fs.makeDirectory(configDir, { recursive: true }).pipe(mapLedgerFs(operation, configDir, phase));
|
|
4201
|
+
const verifiedConfigDir = yield* kernel.requireLocalDirectory(operation, configDir).pipe(Effect.mapError((error) => ({
|
|
4202
|
+
...error,
|
|
4203
|
+
commandPhase: phase
|
|
4204
|
+
})));
|
|
4205
|
+
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));
|
|
4206
|
+
const sorted = [...entries].sort((left, right) => compareText$6(left.name, right.name)).map((entry) => ({
|
|
4207
|
+
name: entry.name,
|
|
4208
|
+
marketplaceIdentity: entry.marketplaceIdentity,
|
|
4209
|
+
installedTreeSha256: entry.installedTreeSha256,
|
|
4210
|
+
acceptedTreeSha256s: [...entry.acceptedTreeSha256s]
|
|
4211
|
+
}));
|
|
4212
|
+
const payload = utf8Encoder$1.encode(`${JSON.stringify({
|
|
4213
|
+
schemaVersion: 1,
|
|
4214
|
+
plugins: sorted
|
|
4215
|
+
}, null, 2)}\n`);
|
|
4216
|
+
const tempName = `${PLUGIN_LEDGER_FILENAME}.tmp-${process.pid}-${Date.now()}-${randomUUID()}`;
|
|
4217
|
+
const tempPath = kernel.paths.join(verifiedConfigDir, tempName);
|
|
4218
|
+
const targetPath = kernel.paths.join(verifiedConfigDir, PLUGIN_LEDGER_FILENAME);
|
|
4219
|
+
return yield* Effect.acquireUseRelease(kernel.fs.writeFile(tempPath, payload, {
|
|
4220
|
+
flag: "wx",
|
|
4221
|
+
mode: 420
|
|
4222
|
+
}).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));
|
|
4223
|
+
});
|
|
4224
|
+
}
|
|
4225
|
+
function decodeLedgerJson(operation, schema, text, phase) {
|
|
4226
|
+
return Effect.try({
|
|
4227
|
+
try: () => JSON.parse(text),
|
|
4228
|
+
catch: (cause) => ledgerFailure(operation, "InvalidJson", phase, cause instanceof Error ? cause.message : String(cause))
|
|
4229
|
+
}).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"))));
|
|
4230
|
+
}
|
|
4231
|
+
function mapLedgerFs(operation, candidate, phase) {
|
|
4232
|
+
return (effect) => effect.pipe(Effect.mapError((cause) => ledgerFailure(operation, cause.reason._tag === "NotFound" ? "Missing" : "FilesystemFailed", phase, cause.message, candidate)));
|
|
4233
|
+
}
|
|
4234
|
+
function ledgerFailure(operation, reason, commandPhase, detail, candidate) {
|
|
4235
|
+
return Object.freeze({
|
|
4236
|
+
_tag: "NativeAgentProviderFailure",
|
|
4237
|
+
provider: "antigravity",
|
|
4238
|
+
operation,
|
|
4239
|
+
reason,
|
|
4240
|
+
commandPhase,
|
|
4241
|
+
...candidate === void 0 ? {} : { path: candidate },
|
|
4242
|
+
detail: detail.slice(0, 4096)
|
|
4243
|
+
});
|
|
4244
|
+
}
|
|
4245
|
+
function isContained$1(paths, root, candidate) {
|
|
4246
|
+
const relative = paths.relative(root, candidate);
|
|
4247
|
+
return relative !== "" && relative !== ".." && !relative.startsWith(`..${paths.sep}`) && !paths.isAbsolute(relative);
|
|
4248
|
+
}
|
|
4249
|
+
function compareText$6(left, right) {
|
|
4250
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
4251
|
+
}
|
|
4252
|
+
//#endregion
|
|
4253
|
+
//#region ../../resources/native-agent-provider/dist/providers/antigravity-effect-platform-node/mcp.js
|
|
4254
|
+
const MAX_OBSERVED_URL_LENGTH$2 = 4096;
|
|
4255
|
+
/**
|
|
4256
|
+
* Reads and permissively normalizes Antigravity's offline `<geminiRoot>/config/mcp_config.json`
|
|
4257
|
+
* `mcpServers` entries without invoking network-probing CLI commands.
|
|
4258
|
+
*/
|
|
4259
|
+
function readAntigravityLiveMcpServers(kernel, operation, commandPhase = "not-started") {
|
|
4260
|
+
return kernel.readAntigravityMcpConfigJson(operation, commandPhase).pipe(Effect.flatMap((mcpConfig) => decodeAntigravityMcpServers(operation, commandPhase, mcpConfig)));
|
|
4261
|
+
}
|
|
4262
|
+
/**
|
|
4263
|
+
* Executes a serialized Antigravity user-scope HTTP MCP add (`agy mcp add --type http`) guarded by
|
|
4264
|
+
* preflight unmanaged-upsert checks, write-ahead ledger ownership under `<geminiRoot>/config/`,
|
|
4265
|
+
* and rollback on confirmed absence after a failed command.
|
|
4266
|
+
*/
|
|
4267
|
+
function addAntigravityMcpServer(kernel, request) {
|
|
4268
|
+
return kernel.serialized("mcp-add", requireMcpServerAddInput("antigravity", "mcp-add", request).pipe(Effect.flatMap(({ name, url, ownerPluginId }) => Effect.gen(function* () {
|
|
4269
|
+
yield* sweepAntigravityTransientArtifacts(kernel, "mcp-add");
|
|
4270
|
+
const previousLedger = yield* kernel.readManagedMcpLedger("mcp-add");
|
|
4271
|
+
const liveBefore = yield* readAntigravityLiveMcpServers(kernel, "mcp-add", "not-started");
|
|
4272
|
+
const previousEntry = previousLedger.find((entry) => entry.name === name);
|
|
4273
|
+
const existingLive = liveBefore.find((entry) => entry.name === name);
|
|
4274
|
+
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}`));
|
|
4275
|
+
const nextLedger = [...previousLedger.filter((entry) => entry.name !== name), Object.freeze({
|
|
4276
|
+
name,
|
|
4277
|
+
url,
|
|
4278
|
+
ownerPluginId
|
|
4279
|
+
})];
|
|
4280
|
+
yield* kernel.writeManagedMcpLedger("mcp-add", nextLedger, "not-started");
|
|
4281
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-add", [
|
|
4282
|
+
"mcp",
|
|
4283
|
+
"add",
|
|
4284
|
+
"--type",
|
|
4285
|
+
"http",
|
|
4286
|
+
name,
|
|
4287
|
+
url
|
|
4288
|
+
]));
|
|
4289
|
+
if (Result.isSuccess(attempt)) return attempt.success;
|
|
4290
|
+
if (attempt.failure.commandPhase === "not-started") return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
4291
|
+
const liveAfterAttempt = yield* Effect.result(readAntigravityLiveMcpServers(kernel, "mcp-add", attempt.failure.commandPhase));
|
|
4292
|
+
if (Result.isSuccess(liveAfterAttempt)) {
|
|
4293
|
+
const liveAfter = liveAfterAttempt.success.find((entry) => entry.name === name);
|
|
4294
|
+
if (liveAfter === void 0 || liveAfter.transport !== "http" || liveAfter.url !== url) return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
4295
|
+
}
|
|
4296
|
+
return yield* Effect.fail(attempt.failure);
|
|
4297
|
+
}))));
|
|
4298
|
+
}
|
|
4299
|
+
/**
|
|
4300
|
+
* Executes a serialized Antigravity user-scope MCP removal guarded by exact ledger URL ownership
|
|
4301
|
+
* and prunes orphan ledger records without invoking `agy mcp remove` when already absent.
|
|
4302
|
+
*/
|
|
4303
|
+
function removeAntigravityMcpServer(kernel, request) {
|
|
4304
|
+
return kernel.serialized("mcp-remove", requireMcpServerRemoveInput("antigravity", "mcp-remove", request).pipe(Effect.flatMap((name) => Effect.gen(function* () {
|
|
4305
|
+
yield* sweepAntigravityTransientArtifacts(kernel, "mcp-remove");
|
|
4306
|
+
const currentLedger = yield* kernel.readManagedMcpLedger("mcp-remove");
|
|
4307
|
+
const liveBefore = yield* readAntigravityLiveMcpServers(kernel, "mcp-remove", "not-started");
|
|
4308
|
+
const ledgerEntry = currentLedger.find((entry) => entry.name === name);
|
|
4309
|
+
const liveEntry = liveBefore.find((entry) => entry.name === name);
|
|
4310
|
+
if (liveEntry === void 0) {
|
|
4311
|
+
if (ledgerEntry !== void 0) yield* kernel.writeManagedMcpLedger("mcp-remove", currentLedger.filter((entry) => entry.name !== name), "not-started");
|
|
4312
|
+
return Object.freeze({
|
|
4313
|
+
provider: "antigravity",
|
|
4314
|
+
operation: "mcp-remove",
|
|
4315
|
+
commandPhase: "command-returned"
|
|
4316
|
+
});
|
|
4317
|
+
}
|
|
4318
|
+
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}`));
|
|
4319
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-remove", [
|
|
4320
|
+
"mcp",
|
|
4321
|
+
"remove",
|
|
4322
|
+
name
|
|
4323
|
+
]));
|
|
4324
|
+
if (Result.isSuccess(attempt)) {
|
|
4325
|
+
yield* pruneManagedMcpLedgerEntry$2(kernel, name, "command-returned");
|
|
4326
|
+
return attempt.success;
|
|
4327
|
+
}
|
|
4328
|
+
if (attempt.failure.commandPhase !== "command-returned") return yield* Effect.fail(attempt.failure);
|
|
4329
|
+
const liveAfterAttempt = yield* Effect.result(readAntigravityLiveMcpServers(kernel, "mcp-remove", "command-returned"));
|
|
4330
|
+
if (Result.isSuccess(liveAfterAttempt) && !liveAfterAttempt.success.some((entry) => entry.name === name)) {
|
|
4331
|
+
yield* pruneManagedMcpLedgerEntry$2(kernel, name, "command-returned");
|
|
4332
|
+
return Object.freeze({
|
|
4333
|
+
provider: "antigravity",
|
|
4334
|
+
operation: "mcp-remove",
|
|
4335
|
+
commandPhase: "command-returned"
|
|
4336
|
+
});
|
|
4337
|
+
}
|
|
4338
|
+
return yield* Effect.fail(attempt.failure);
|
|
4339
|
+
}))));
|
|
4340
|
+
}
|
|
4341
|
+
function decodeAntigravityMcpServers(operation, commandPhase, mcpConfig) {
|
|
4342
|
+
if (mcpConfig === null) return Effect.succeed(Object.freeze([]));
|
|
4343
|
+
if (!isPlainRecord$2(mcpConfig)) return Effect.fail(antigravityMcpFailure(operation, "ProtocolFailed", commandPhase, "Antigravity mcp_config.json top-level value must be a JSON object"));
|
|
4344
|
+
const rawServers = Reflect.get(mcpConfig, "mcpServers");
|
|
4345
|
+
if (rawServers === void 0 || rawServers === null) return Effect.succeed(Object.freeze([]));
|
|
4346
|
+
if (!isPlainRecord$2(rawServers)) return Effect.fail(antigravityMcpFailure(operation, "ProtocolFailed", commandPhase, "Antigravity mcp_config.json mcpServers must be a JSON object"));
|
|
4347
|
+
const entries = Object.entries(rawServers).filter(([name]) => name !== "__proto__" && Value.Check(ObservedMcpServerNameSchema, name));
|
|
4348
|
+
if (entries.length > 1024) return Effect.fail(antigravityMcpFailure(operation, "LimitExceeded", commandPhase, "Antigravity mcp_config.json MCP server count exceeds the resource limit"));
|
|
4349
|
+
return Effect.succeed(Object.freeze(entries.map(([name, entry]) => normalizeAntigravityMcpServer(name, entry))));
|
|
4350
|
+
}
|
|
4351
|
+
const ALLOWED_HTTP_ENTRY_KEYS = /* @__PURE__ */ new Set([
|
|
4352
|
+
"serverUrl",
|
|
4353
|
+
"url",
|
|
4354
|
+
"disabled",
|
|
4355
|
+
"type"
|
|
4356
|
+
]);
|
|
4357
|
+
function normalizeAntigravityMcpServer(name, entry) {
|
|
4358
|
+
if (!isPlainRecord$2(entry)) return Object.freeze({
|
|
4359
|
+
name,
|
|
4360
|
+
transport: "other",
|
|
4361
|
+
url: null,
|
|
4362
|
+
enabled: null
|
|
4363
|
+
});
|
|
4364
|
+
const rawDisabled = Reflect.get(entry, "disabled");
|
|
4365
|
+
if (rawDisabled !== void 0 && typeof rawDisabled !== "boolean") return Object.freeze({
|
|
4366
|
+
name,
|
|
4367
|
+
transport: "other",
|
|
4368
|
+
url: null,
|
|
4369
|
+
enabled: null
|
|
4370
|
+
});
|
|
4371
|
+
const enabled = typeof rawDisabled === "boolean" ? !rawDisabled : true;
|
|
4372
|
+
const rawType = Reflect.get(entry, "type");
|
|
4373
|
+
const hasCustomConfig = Object.keys(entry).some((key) => !ALLOWED_HTTP_ENTRY_KEYS.has(key)) || rawType !== void 0 && rawType !== "http";
|
|
4374
|
+
const rawServerUrl = Reflect.get(entry, "serverUrl");
|
|
4375
|
+
const rawUrl = Reflect.get(entry, "url");
|
|
4376
|
+
let validUrl = null;
|
|
4377
|
+
if ((rawServerUrl === void 0 || typeof rawServerUrl === "string") && (rawUrl === void 0 || typeof rawUrl === "string") && !(rawServerUrl !== void 0 && rawUrl !== void 0 && rawServerUrl !== rawUrl)) {
|
|
4378
|
+
const candidate = rawServerUrl !== void 0 ? rawServerUrl : rawUrl;
|
|
4379
|
+
if (typeof candidate === "string" && candidate.length > 0 && candidate.length <= MAX_OBSERVED_URL_LENGTH$2) validUrl = candidate;
|
|
4380
|
+
}
|
|
4381
|
+
if (!hasCustomConfig && validUrl !== null) return Object.freeze({
|
|
4382
|
+
name,
|
|
4383
|
+
transport: "http",
|
|
4384
|
+
url: validUrl,
|
|
4385
|
+
enabled
|
|
4386
|
+
});
|
|
4387
|
+
return Object.freeze({
|
|
4388
|
+
name,
|
|
4389
|
+
transport: "other",
|
|
4390
|
+
url: null,
|
|
4391
|
+
enabled
|
|
4392
|
+
});
|
|
4393
|
+
}
|
|
4394
|
+
function pruneManagedMcpLedgerEntry$2(kernel, name, commandPhase) {
|
|
4395
|
+
return kernel.readManagedMcpLedger("mcp-remove").pipe(Effect.mapError((error) => error.commandPhase === commandPhase ? error : Object.freeze({
|
|
4396
|
+
...error,
|
|
4397
|
+
commandPhase
|
|
4398
|
+
})), Effect.flatMap((current) => {
|
|
4399
|
+
const next = current.filter((entry) => entry.name !== name);
|
|
4400
|
+
return next.length === current.length ? Effect.void : kernel.writeManagedMcpLedger("mcp-remove", next, commandPhase);
|
|
4401
|
+
}));
|
|
4402
|
+
}
|
|
4403
|
+
function isPlainRecord$2(value) {
|
|
4404
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4405
|
+
}
|
|
4406
|
+
function antigravityMcpFailure(operation, reason, commandPhase, detail) {
|
|
4407
|
+
return Object.freeze({
|
|
4408
|
+
_tag: "NativeAgentProviderFailure",
|
|
4409
|
+
provider: "antigravity",
|
|
4410
|
+
operation,
|
|
4411
|
+
reason,
|
|
4412
|
+
commandPhase,
|
|
4413
|
+
detail
|
|
4414
|
+
});
|
|
4415
|
+
}
|
|
4416
|
+
//#endregion
|
|
4417
|
+
//#region ../../resources/native-agent-provider/dist/providers/antigravity-effect-platform-node/index.js
|
|
4418
|
+
const utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
4419
|
+
const utf8Encoder = new TextEncoder();
|
|
4420
|
+
const MAX_MARKETPLACE_MANIFEST_BYTES = 2097152;
|
|
4421
|
+
const NullableStringSchema$2 = Type.Union([Type.String(), Type.Null()]);
|
|
4422
|
+
const ObservedPluginNameSchema = Type.String({
|
|
4423
|
+
pattern: "^[^\\u0000-\\u001f\\u007f@/\\\\]{1,256}$",
|
|
4424
|
+
minLength: 1,
|
|
4425
|
+
maxLength: 256
|
|
4426
|
+
});
|
|
4427
|
+
const MarketplaceNameSchema = Type.String({
|
|
4428
|
+
pattern: "^[a-z0-9][a-z0-9_-]*$",
|
|
4429
|
+
maxLength: 128
|
|
4430
|
+
});
|
|
4431
|
+
const AntigravityPluginListSchema = Type.Array(Type.Object({
|
|
4432
|
+
name: Type.String(),
|
|
4433
|
+
enabled: Type.Optional(Type.Union([Type.Boolean(), Type.Null()])),
|
|
4434
|
+
version: Type.Optional(NullableStringSchema$2),
|
|
4435
|
+
source: Type.Optional(NullableStringSchema$2),
|
|
4436
|
+
path: Type.Optional(NullableStringSchema$2)
|
|
4437
|
+
}, { additionalProperties: true }), { maxItems: 4096 });
|
|
4438
|
+
const StagedMarketplaceRecordSchema = Type.Object({
|
|
4439
|
+
identity: MarketplaceNameSchema,
|
|
4440
|
+
source: Type.Union([
|
|
4441
|
+
Type.Object({
|
|
4442
|
+
kind: Type.Literal("git"),
|
|
4443
|
+
repositoryUrl: CanonicalGitRepositoryUrlSchema,
|
|
4444
|
+
revision: Type.Union([Type.String({
|
|
4445
|
+
pattern: "^[^\\s#]+$",
|
|
4446
|
+
minLength: 1,
|
|
4447
|
+
maxLength: 256
|
|
4448
|
+
}), Type.Null()])
|
|
4449
|
+
}, { additionalProperties: false }),
|
|
4450
|
+
Type.Object({
|
|
4451
|
+
kind: Type.Literal("local"),
|
|
4452
|
+
root: Type.String({
|
|
4453
|
+
minLength: 1,
|
|
4454
|
+
maxLength: 16384
|
|
4455
|
+
})
|
|
4456
|
+
}, { additionalProperties: false }),
|
|
4457
|
+
Type.Null()
|
|
4458
|
+
]),
|
|
4459
|
+
plugins: Type.Array(CanonicalPluginNameSchema, { maxItems: 4096 })
|
|
4460
|
+
}, { additionalProperties: false });
|
|
4461
|
+
const ClaudeSourceMarketplaceSchema = Type.Object({
|
|
4462
|
+
name: MarketplaceNameSchema,
|
|
4463
|
+
plugins: Type.Array(Type.Object({
|
|
4464
|
+
name: CanonicalPluginNameSchema,
|
|
4465
|
+
source: Type.String({
|
|
4466
|
+
minLength: 1,
|
|
4467
|
+
maxLength: 1024
|
|
4468
|
+
})
|
|
4469
|
+
}, { additionalProperties: true }), {
|
|
4470
|
+
minItems: 1,
|
|
4471
|
+
maxItems: 4096
|
|
4472
|
+
})
|
|
4473
|
+
}, { additionalProperties: true });
|
|
4474
|
+
const CodexSourceMarketplaceSchema = Type.Object({
|
|
4475
|
+
name: MarketplaceNameSchema,
|
|
4476
|
+
plugins: Type.Array(Type.Object({
|
|
4477
|
+
name: CanonicalPluginNameSchema,
|
|
4478
|
+
source: Type.Object({
|
|
4479
|
+
source: Type.Literal("local"),
|
|
4480
|
+
path: Type.String({
|
|
4481
|
+
minLength: 1,
|
|
4482
|
+
maxLength: 1024
|
|
4483
|
+
})
|
|
4484
|
+
}, { additionalProperties: true })
|
|
4485
|
+
}, { additionalProperties: true }), {
|
|
4486
|
+
minItems: 1,
|
|
4487
|
+
maxItems: 4096
|
|
4488
|
+
})
|
|
4489
|
+
}, { additionalProperties: true });
|
|
4490
|
+
const ANTIGRAVITY_CAPABILITIES = [
|
|
4491
|
+
"marketplace-list",
|
|
4492
|
+
"marketplace-add",
|
|
4493
|
+
"marketplace-remove",
|
|
4494
|
+
"plugin-list",
|
|
4495
|
+
"plugin-install",
|
|
4496
|
+
"plugin-enable",
|
|
4497
|
+
"plugin-disable",
|
|
4498
|
+
"plugin-remove",
|
|
4499
|
+
"mcp-add",
|
|
4500
|
+
"mcp-remove"
|
|
4501
|
+
];
|
|
4502
|
+
/**
|
|
4503
|
+
* Constructs the platform-requiring Antigravity provider without choosing a runtime.
|
|
4504
|
+
*/
|
|
4505
|
+
function makeAntigravityEffectPlatformNodeProvider(options = {}) {
|
|
4506
|
+
const command = options.command ?? "agy";
|
|
4507
|
+
const gitCommand = options.gitCommand ?? "git";
|
|
4508
|
+
return Object.freeze({ acquire: (input) => acquireEffectPlatformNodeProvider("antigravity", command, input).pipe(Effect.map((kernel) => {
|
|
4509
|
+
const probe = () => kernel.serialized("probe", Effect.gen(function* () {
|
|
4510
|
+
const version = yield* kernel.run("probe", ["--version"]);
|
|
4511
|
+
return Object.freeze({
|
|
4512
|
+
provider: "antigravity",
|
|
4513
|
+
home: kernel.home,
|
|
4514
|
+
version: yield* requireVersion$2(version.stdout),
|
|
4515
|
+
capabilities: [...ANTIGRAVITY_CAPABILITIES]
|
|
4516
|
+
});
|
|
4517
|
+
}));
|
|
4518
|
+
const inventory = (inventoryOptions) => kernel.serialized("inventory", requireInventoryOptions("antigravity", inventoryOptions).pipe(Effect.flatMap((validated) => antigravityInventory(kernel, validated))));
|
|
4519
|
+
return Object.freeze({
|
|
4520
|
+
provider: "antigravity",
|
|
4521
|
+
home: kernel.home,
|
|
4522
|
+
probe,
|
|
4523
|
+
inventory,
|
|
4524
|
+
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) => {
|
|
4525
|
+
const missing = Object.freeze({
|
|
4526
|
+
kind: error.reason === "Missing" ? "Missing" : "TooLarge",
|
|
4527
|
+
relativePath: file.relativePath
|
|
4528
|
+
});
|
|
4529
|
+
return Effect.succeed(missing);
|
|
4530
|
+
})), { concurrency: 1 }).pipe(Effect.map((files) => {
|
|
4531
|
+
return Object.freeze({
|
|
4532
|
+
selector: validated.selector,
|
|
4533
|
+
files: Object.freeze(files)
|
|
4534
|
+
});
|
|
4535
|
+
}))))))))),
|
|
4536
|
+
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)))))),
|
|
4537
|
+
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)))))),
|
|
4538
|
+
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)))))),
|
|
4539
|
+
enablePlugin: (request) => kernel.serialized("plugin-enable", requirePluginSelectorInput("antigravity", "plugin-enable", request).pipe(Effect.flatMap((selector) => {
|
|
4540
|
+
const parsed = splitSelector(selector, "plugin-enable");
|
|
4541
|
+
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", [
|
|
4542
|
+
"plugin",
|
|
4543
|
+
"enable",
|
|
4544
|
+
parsed.name
|
|
4545
|
+
])));
|
|
4546
|
+
}))),
|
|
4547
|
+
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)))))),
|
|
4548
|
+
addMcpServer: (request) => addAntigravityMcpServer(kernel, request),
|
|
4549
|
+
removeMcpServer: (request) => removeAntigravityMcpServer(kernel, request)
|
|
4550
|
+
});
|
|
4551
|
+
})) });
|
|
4552
|
+
}
|
|
4553
|
+
/**
|
|
4554
|
+
* Constructs a ready Antigravity resource whose Node platform is supplied only while
|
|
4555
|
+
* acquiring a session.
|
|
4556
|
+
*/
|
|
4557
|
+
function makeNodeAntigravityNativeAgentProviderResource(options = {}) {
|
|
4558
|
+
const provider = makeAntigravityEffectPlatformNodeProvider(options);
|
|
4559
|
+
return Object.freeze({ acquire: (input) => provider.acquire(input).pipe(Effect.provide(NodeServices.layer)) });
|
|
4560
|
+
}
|
|
4561
|
+
function antigravityInstalledPlugins(kernel) {
|
|
4562
|
+
return Effect.gen(function* () {
|
|
4563
|
+
const pluginOutput = yield* kernel.run("inventory", [
|
|
4564
|
+
"plugin",
|
|
4565
|
+
"list",
|
|
4566
|
+
"--json"
|
|
4567
|
+
]);
|
|
4568
|
+
const pluginRecord = yield* decodeProviderJson("antigravity", "inventory", AntigravityPluginListSchema, pluginOutput.stdout);
|
|
4569
|
+
const stagedMarketplaces = yield* readStagedMarketplaces(kernel);
|
|
4570
|
+
const pluginLedger = yield* readPluginLedger(kernel, "inventory", "command-returned");
|
|
4571
|
+
const ledgerByName = new Map(pluginLedger.map((entry) => [entry.name, entry]));
|
|
4572
|
+
const marketplaces = stagedMarketplaces.map((entry) => Object.freeze({
|
|
4573
|
+
identity: entry.identity,
|
|
4574
|
+
source: entry.source,
|
|
4575
|
+
installedRoot: entry.installedRoot
|
|
4576
|
+
}));
|
|
4577
|
+
const plugins = yield* Effect.forEach(pluginRecord, (entry) => normalizePlugin$2(kernel, ledgerByName, entry), { concurrency: 1 });
|
|
4578
|
+
yield* requireUniqueInventory$2(marketplaces, plugins, []);
|
|
4579
|
+
return Object.freeze([...plugins].sort(bySelector$2));
|
|
4580
|
+
});
|
|
4581
|
+
}
|
|
4582
|
+
function antigravityInventory(kernel, options) {
|
|
4583
|
+
return Effect.gen(function* () {
|
|
4584
|
+
const pluginOutput = yield* kernel.run("inventory", [
|
|
4585
|
+
"plugin",
|
|
4586
|
+
"list",
|
|
4587
|
+
"--json"
|
|
4588
|
+
]);
|
|
4589
|
+
const pluginRecord = yield* decodeProviderJson("antigravity", "inventory", AntigravityPluginListSchema, pluginOutput.stdout);
|
|
4590
|
+
const stagedMarketplaces = yield* readStagedMarketplaces(kernel);
|
|
4591
|
+
const pluginLedger = yield* readPluginLedger(kernel, "inventory", "command-returned");
|
|
4592
|
+
const managedMcpServers = yield* kernel.readManagedMcpLedger("inventory");
|
|
4593
|
+
const mcpServers = shouldObserveProviderMcpConfig(options, managedMcpServers) ? yield* readAntigravityLiveMcpServers(kernel, "inventory", "not-started") : Object.freeze([]);
|
|
4594
|
+
const ledgerByName = new Map(pluginLedger.map((entry) => [entry.name, entry]));
|
|
4595
|
+
const marketplaces = stagedMarketplaces.map((entry) => Object.freeze({
|
|
4596
|
+
identity: entry.identity,
|
|
4597
|
+
source: entry.source,
|
|
4598
|
+
installedRoot: entry.installedRoot
|
|
4599
|
+
}));
|
|
4600
|
+
const plugins = yield* Effect.forEach(pluginRecord, (entry) => normalizePlugin$2(kernel, ledgerByName, entry), { concurrency: 1 });
|
|
4601
|
+
yield* requireUniqueInventory$2(marketplaces, plugins, mcpServers);
|
|
4602
|
+
const normalized = Object.freeze({
|
|
4603
|
+
provider: "antigravity",
|
|
4604
|
+
marketplaces: [...marketplaces].sort(byIdentity$2),
|
|
4605
|
+
plugins: [...plugins].sort(bySelector$2),
|
|
4606
|
+
mcpServers: [...mcpServers].sort(byMcpName$2),
|
|
4607
|
+
managedMcpServers
|
|
4608
|
+
});
|
|
4609
|
+
return Value.Check(NativeProviderInventorySchema, normalized) ? normalized : yield* Effect.fail(providerFailure$2("inventory", "ProtocolFailed", "command-returned", "Antigravity native inventory contains non-canonical facts"));
|
|
4610
|
+
});
|
|
4611
|
+
}
|
|
4612
|
+
function readStagedMarketplaces(kernel) {
|
|
4613
|
+
return Effect.gen(function* () {
|
|
4614
|
+
const marketplacesDir = kernel.paths.join(kernel.geminiRoot, "config", "marketplaces");
|
|
4615
|
+
if (!(yield* kernel.fs.exists(marketplacesDir).pipe(mapFs("inventory", marketplacesDir, "command-returned")))) return Object.freeze([]);
|
|
4616
|
+
const verifiedMarketplacesDir = yield* kernel.requireLocalDirectory("inventory", marketplacesDir);
|
|
4617
|
+
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));
|
|
4618
|
+
const childNames = yield* kernel.fs.readDirectory(verifiedMarketplacesDir).pipe(mapFs("inventory", verifiedMarketplacesDir, "command-returned"));
|
|
4619
|
+
const records = [];
|
|
4620
|
+
for (const childName of [...childNames].sort(compareText$5)) {
|
|
4621
|
+
if (childName.startsWith(".")) continue;
|
|
4622
|
+
const entryDir = kernel.paths.join(verifiedMarketplacesDir, childName);
|
|
4623
|
+
const entryRoot = yield* kernel.requireLocalDirectory("inventory", entryDir);
|
|
4624
|
+
const manifestPath = kernel.paths.join(entryRoot, "marketplace.json");
|
|
4625
|
+
const rawText = yield* readBoundedRegularUtf8File(kernel, "inventory", entryRoot, manifestPath, MAX_MARKETPLACE_MANIFEST_BYTES, "command-returned");
|
|
4626
|
+
const decoded = yield* decodeProviderJson("antigravity", "inventory", StagedMarketplaceRecordSchema, rawText);
|
|
4627
|
+
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));
|
|
4628
|
+
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));
|
|
4629
|
+
records.push(Object.freeze({
|
|
4630
|
+
identity: decoded.identity,
|
|
4631
|
+
source: decoded.source === null ? null : decoded.source.kind === "git" ? Object.freeze({
|
|
4632
|
+
kind: "git",
|
|
4633
|
+
repositoryUrl: decoded.source.repositoryUrl,
|
|
4634
|
+
revision: decoded.source.revision
|
|
4635
|
+
}) : Object.freeze({
|
|
4636
|
+
kind: "local",
|
|
4637
|
+
root: decoded.source.root
|
|
4638
|
+
}),
|
|
4639
|
+
plugins: Object.freeze([...decoded.plugins]),
|
|
4640
|
+
installedRoot: entryRoot
|
|
4641
|
+
}));
|
|
4642
|
+
}
|
|
4643
|
+
return Object.freeze(records);
|
|
4644
|
+
});
|
|
4645
|
+
}
|
|
4646
|
+
function normalizePlugin$2(kernel, pluginLedgerByName, entry) {
|
|
4647
|
+
return Effect.gen(function* () {
|
|
4648
|
+
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"));
|
|
4649
|
+
const isCanonicalLowercaseName = Value.Check(CanonicalPluginNameSchema, entry.name);
|
|
4650
|
+
const source = entry.source ?? null;
|
|
4651
|
+
let marketplaceIdentity;
|
|
4652
|
+
if (source === "claude-code" || source === "gemini-cli") marketplaceIdentity = `imported-${source}`;
|
|
4653
|
+
else if (source === "antigravity") {
|
|
4654
|
+
if (!isCanonicalLowercaseName) marketplaceIdentity = "antigravity-marketplace";
|
|
4655
|
+
else {
|
|
4656
|
+
const ledgerEntry = pluginLedgerByName.get(entry.name);
|
|
4657
|
+
if (ledgerEntry === void 0) marketplaceIdentity = "antigravity-marketplace";
|
|
4658
|
+
else marketplaceIdentity = isLedgerAcceptedDigest(ledgerEntry, yield* readLedgerKnownPluginTreeSha256(kernel, "inventory", entry.path ?? null, "command-returned")) ? ledgerEntry.marketplaceIdentity : "antigravity-marketplace";
|
|
4659
|
+
}
|
|
4660
|
+
} else if (source === null || source === "") marketplaceIdentity = "unmanaged-local";
|
|
4661
|
+
else return yield* Effect.fail(providerFailure$2("inventory", "ProtocolFailed", "command-returned", "Antigravity plugin source kind is unsupported"));
|
|
4662
|
+
const rawVersion = entry.version ?? null;
|
|
4663
|
+
const version = rawVersion !== null && Value.Check(PluginVersionSchema, rawVersion) ? rawVersion : null;
|
|
4664
|
+
const selector = `${entry.name}@${marketplaceIdentity}`;
|
|
4665
|
+
return Object.freeze({
|
|
4666
|
+
selector,
|
|
4667
|
+
marketplaceIdentity,
|
|
4668
|
+
name: entry.name,
|
|
4669
|
+
installed: true,
|
|
4670
|
+
enabled: entry.enabled ?? null,
|
|
4671
|
+
version,
|
|
4672
|
+
root: entry.path ?? null
|
|
4673
|
+
});
|
|
4674
|
+
});
|
|
4675
|
+
}
|
|
4676
|
+
function readLivePluginListPreflight(kernel, operation) {
|
|
4677
|
+
return kernel.run(operation, [
|
|
4678
|
+
"plugin",
|
|
4679
|
+
"list",
|
|
4680
|
+
"--json"
|
|
4681
|
+
]).pipe(Effect.flatMap((output) => decodeProviderJson("antigravity", operation, AntigravityPluginListSchema, output.stdout)), Effect.mapError((error) => ({
|
|
4682
|
+
...error,
|
|
4683
|
+
commandPhase: "not-started"
|
|
4684
|
+
})));
|
|
4685
|
+
}
|
|
4686
|
+
function readLivePluginNamesBestEffort(kernel, operation) {
|
|
4687
|
+
return kernel.run(operation, [
|
|
4688
|
+
"plugin",
|
|
4689
|
+
"list",
|
|
4690
|
+
"--json"
|
|
4691
|
+
]).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)));
|
|
4692
|
+
}
|
|
4693
|
+
function readInstalledPluginDirectoryNames(kernel, operation) {
|
|
4694
|
+
return Effect.gen(function* () {
|
|
4695
|
+
const pluginsDir = kernel.paths.join(kernel.geminiRoot, "config", "plugins");
|
|
4696
|
+
if (!(yield* kernel.fs.exists(pluginsDir).pipe(mapFs(operation, pluginsDir, "not-started")))) return Object.freeze([]);
|
|
4697
|
+
const verifiedDir = yield* kernel.requireLocalDirectory(operation, pluginsDir).pipe(Effect.mapError((error) => ({
|
|
4698
|
+
...error,
|
|
4699
|
+
commandPhase: "not-started"
|
|
4700
|
+
})));
|
|
4701
|
+
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));
|
|
4702
|
+
const names = yield* kernel.fs.readDirectory(verifiedDir).pipe(mapFs(operation, verifiedDir, "not-started"));
|
|
4703
|
+
return Object.freeze(names.filter((name) => !name.startsWith(".")));
|
|
4704
|
+
});
|
|
4705
|
+
}
|
|
4706
|
+
function verifyInstallSlotOwnership(kernel, parsed) {
|
|
4707
|
+
return Effect.gen(function* () {
|
|
4708
|
+
const liveList = yield* readLivePluginListPreflight(kernel, "plugin-install");
|
|
4709
|
+
const existingLedger = yield* readPluginLedger(kernel, "plugin-install", "not-started");
|
|
4710
|
+
const ledgerEntry = existingLedger.find((entry) => entry.name === parsed.name);
|
|
4711
|
+
const targetLower = parsed.name.toLowerCase();
|
|
4712
|
+
const listMatches = liveList.filter((entry) => entry.name.toLowerCase() === targetLower);
|
|
4713
|
+
let previousOwnedTreeSha256 = null;
|
|
4714
|
+
for (const match of listMatches) {
|
|
4715
|
+
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));
|
|
4716
|
+
const liveTreeSha256 = yield* readLedgerKnownPluginTreeSha256(kernel, "plugin-install", match.path ?? null, "not-started");
|
|
4717
|
+
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));
|
|
4718
|
+
previousOwnedTreeSha256 = liveTreeSha256;
|
|
4719
|
+
}
|
|
4720
|
+
if (listMatches.length === 0) {
|
|
4721
|
+
const collidingDirs = (yield* readInstalledPluginDirectoryNames(kernel, "plugin-install")).filter((name) => name.toLowerCase() === targetLower);
|
|
4722
|
+
for (const dirName of collidingDirs) {
|
|
4723
|
+
const dirPath = kernel.paths.join(kernel.geminiRoot, "config", "plugins", dirName);
|
|
4724
|
+
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));
|
|
4725
|
+
const dirTreeSha256 = yield* readLedgerKnownPluginTreeSha256(kernel, "plugin-install", dirPath, "not-started");
|
|
4726
|
+
if (!isLedgerAcceptedDigest(ledgerEntry, dirTreeSha256)) return yield* Effect.fail(providerFailure$2("plugin-install", "InvalidInput", "not-started", "Refusing to overwrite unmanaged Antigravity plugin", dirPath));
|
|
4727
|
+
previousOwnedTreeSha256 = dirTreeSha256;
|
|
4728
|
+
}
|
|
4729
|
+
}
|
|
4730
|
+
return Object.freeze({
|
|
4731
|
+
existingLedger,
|
|
4732
|
+
previousOwnedTreeSha256
|
|
4733
|
+
});
|
|
4734
|
+
});
|
|
4735
|
+
}
|
|
4736
|
+
function verifyRemoveSlotOwnership(kernel, parsed) {
|
|
4737
|
+
return Effect.gen(function* () {
|
|
4738
|
+
const liveList = yield* readLivePluginListPreflight(kernel, "plugin-remove");
|
|
4739
|
+
const ledgerEntry = (yield* readPluginLedger(kernel, "plugin-remove", "not-started")).find((entry) => entry.name === parsed.name);
|
|
4740
|
+
const targetLower = parsed.name.toLowerCase();
|
|
4741
|
+
const listMatches = liveList.filter((entry) => entry.name.toLowerCase() === targetLower);
|
|
4742
|
+
for (const match of listMatches) {
|
|
4743
|
+
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));
|
|
4744
|
+
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));
|
|
4745
|
+
}
|
|
4746
|
+
if (listMatches.length === 0) {
|
|
4747
|
+
const collidingDirs = (yield* readInstalledPluginDirectoryNames(kernel, "plugin-remove")).filter((name) => name.toLowerCase() === targetLower);
|
|
4748
|
+
for (const dirName of collidingDirs) {
|
|
4749
|
+
const dirPath = kernel.paths.join(kernel.geminiRoot, "config", "plugins", dirName);
|
|
4750
|
+
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));
|
|
4751
|
+
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));
|
|
4752
|
+
}
|
|
4753
|
+
}
|
|
4754
|
+
});
|
|
4755
|
+
}
|
|
4756
|
+
function stageAntigravityMarketplace(kernel, gitCommand, source) {
|
|
4757
|
+
if (source.kind === "local") return kernel.requireLocalDirectory("marketplace-add", source.root).pipe(Effect.flatMap((localRoot) => stageFromResolvedSourceRoot(kernel, {
|
|
4758
|
+
sourceRoot: localRoot,
|
|
4759
|
+
repositoryUrl: null,
|
|
4760
|
+
sourceObservation: Object.freeze({
|
|
4761
|
+
kind: "local",
|
|
4762
|
+
root: localRoot
|
|
4763
|
+
})
|
|
4764
|
+
})));
|
|
4765
|
+
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* () {
|
|
4766
|
+
const gitEnv = { GIT_TERMINAL_PROMPT: "0" };
|
|
4767
|
+
yield* kernel.runExternalCommand("marketplace-add", gitCommand, ["init", "--quiet"], tempDir, gitEnv);
|
|
4768
|
+
yield* kernel.runExternalCommand("marketplace-add", gitCommand, [
|
|
4769
|
+
"fetch",
|
|
4770
|
+
"--depth",
|
|
4771
|
+
"1",
|
|
4772
|
+
"--quiet",
|
|
4773
|
+
git.repositoryUrl,
|
|
4774
|
+
`refs/tags/${git.revision}`
|
|
4775
|
+
], tempDir, gitEnv).pipe(Effect.catch(() => kernel.runExternalCommand("marketplace-add", gitCommand, [
|
|
4776
|
+
"fetch",
|
|
4777
|
+
"--depth",
|
|
4778
|
+
"1",
|
|
4779
|
+
"--quiet",
|
|
4780
|
+
git.repositoryUrl,
|
|
4781
|
+
git.revision
|
|
4782
|
+
], tempDir, gitEnv)));
|
|
4783
|
+
yield* kernel.runExternalCommand("marketplace-add", gitCommand, [
|
|
4784
|
+
"checkout",
|
|
4785
|
+
"--detach",
|
|
4786
|
+
"--force",
|
|
4787
|
+
"--quiet",
|
|
4788
|
+
"FETCH_HEAD"
|
|
4789
|
+
], tempDir, gitEnv);
|
|
4790
|
+
return yield* stageFromResolvedSourceRoot(kernel, {
|
|
4791
|
+
sourceRoot: tempDir,
|
|
4792
|
+
repositoryUrl: git.repositoryUrl,
|
|
4793
|
+
sourceObservation: Object.freeze({
|
|
4794
|
+
kind: "git",
|
|
4795
|
+
repositoryUrl: git.repositoryUrl,
|
|
4796
|
+
revision: git.revision
|
|
4797
|
+
})
|
|
4798
|
+
});
|
|
4799
|
+
}), (tempDir) => kernel.fs.remove(tempDir, {
|
|
4800
|
+
recursive: true,
|
|
4801
|
+
force: true
|
|
4802
|
+
}).pipe(Effect.ignore))));
|
|
4803
|
+
}
|
|
4804
|
+
function stageFromResolvedSourceRoot(kernel, input) {
|
|
4805
|
+
return Effect.gen(function* () {
|
|
4806
|
+
const catalog = yield* readSourceMarketplaceCatalog(kernel, input.sourceRoot);
|
|
4807
|
+
const marketplacesParent = kernel.paths.join(kernel.geminiRoot, "config", "marketplaces");
|
|
4808
|
+
yield* kernel.fs.makeDirectory(marketplacesParent, { recursive: true }).pipe(mapFs("marketplace-add", marketplacesParent, "not-started"));
|
|
4809
|
+
const verifiedMarketplacesParent = yield* kernel.requireLocalDirectory("marketplace-add", marketplacesParent);
|
|
4810
|
+
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));
|
|
4811
|
+
const stagingName = `.staging-${catalog.identity}-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2, 10)}`;
|
|
4812
|
+
const stagingDir = kernel.paths.join(verifiedMarketplacesParent, stagingName);
|
|
4813
|
+
const targetDir = kernel.paths.join(verifiedMarketplacesParent, catalog.identity);
|
|
4814
|
+
return yield* Effect.acquireUseRelease(kernel.fs.makeDirectory(stagingDir, { recursive: true }).pipe(mapFs("marketplace-add", stagingDir, "not-started"), Effect.as(stagingDir)), () => Effect.gen(function* () {
|
|
4815
|
+
const pluginNames = [];
|
|
4816
|
+
for (const declared of catalog.plugins) {
|
|
4817
|
+
const pluginSourceCandidate = kernel.paths.join(input.sourceRoot, ...declared.relativeSourcePath.split("/"));
|
|
4818
|
+
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));
|
|
4819
|
+
const pluginSourceRoot = yield* kernel.requireLocalDirectory("marketplace-add", pluginSourceCandidate);
|
|
4820
|
+
const entries = yield* readPluginSourceTreeEntries(kernel, pluginSourceRoot);
|
|
4821
|
+
const projected = projectAntigravityPluginBundle({
|
|
4822
|
+
entries,
|
|
4823
|
+
repositoryUrl: input.repositoryUrl
|
|
4824
|
+
});
|
|
4825
|
+
if (!projected.ok) return yield* Effect.fail(providerFailure$2("marketplace-add", "ProtocolFailed", "not-started", `Antigravity bundle projection failed for ${declared.name}: ${projected.detail}`, pluginSourceRoot));
|
|
4826
|
+
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));
|
|
4827
|
+
const stagedPluginDir = kernel.paths.join(stagingDir, "plugins", declared.name);
|
|
4828
|
+
yield* writeProjectedBundle(kernel, stagedPluginDir, projected.entries);
|
|
4829
|
+
yield* kernel.run("marketplace-add", [
|
|
4830
|
+
"plugin",
|
|
4831
|
+
"validate",
|
|
4832
|
+
stagedPluginDir,
|
|
4833
|
+
"--strict",
|
|
4834
|
+
"--json"
|
|
4835
|
+
]);
|
|
4836
|
+
pluginNames.push(declared.name);
|
|
4837
|
+
}
|
|
4838
|
+
const marketplaceRecord = {
|
|
4839
|
+
identity: catalog.identity,
|
|
4840
|
+
source: input.sourceObservation,
|
|
4841
|
+
plugins: pluginNames
|
|
4842
|
+
};
|
|
4843
|
+
const marketplaceJsonPath = kernel.paths.join(stagingDir, "marketplace.json");
|
|
4844
|
+
yield* kernel.fs.writeFile(marketplaceJsonPath, utf8Encoder.encode(`${JSON.stringify(marketplaceRecord, null, 2)}\n`)).pipe(mapFs("marketplace-add", marketplaceJsonPath, "command-returned"));
|
|
4845
|
+
yield* kernel.fs.chmod(marketplaceJsonPath, 420).pipe(mapFs("marketplace-add", marketplaceJsonPath, "command-returned"));
|
|
4846
|
+
if (yield* kernel.fs.exists(targetDir).pipe(mapFs("marketplace-add", targetDir, "command-returned"))) {
|
|
4847
|
+
const verifiedExisting = yield* kernel.requireLocalDirectory("marketplace-add", targetDir);
|
|
4848
|
+
yield* kernel.fs.remove(verifiedExisting, { recursive: true }).pipe(mapFs("marketplace-add", verifiedExisting, "command-returned"));
|
|
4849
|
+
}
|
|
4850
|
+
yield* kernel.fs.rename(stagingDir, targetDir).pipe(mapFs("marketplace-add", targetDir, "command-returned"));
|
|
4851
|
+
return Object.freeze({
|
|
4852
|
+
provider: "antigravity",
|
|
4853
|
+
operation: "marketplace-add",
|
|
4854
|
+
commandPhase: "command-returned"
|
|
4855
|
+
});
|
|
4856
|
+
}), (dir) => kernel.fs.remove(dir, {
|
|
4857
|
+
recursive: true,
|
|
4858
|
+
force: true
|
|
4859
|
+
}).pipe(Effect.ignore));
|
|
4860
|
+
});
|
|
4861
|
+
}
|
|
4862
|
+
function readSourceMarketplaceCatalog(kernel, sourceRoot) {
|
|
4863
|
+
return Effect.gen(function* () {
|
|
4864
|
+
const claudePath = kernel.paths.join(sourceRoot, ".claude-plugin", "marketplace.json");
|
|
4865
|
+
const codexPath = kernel.paths.join(sourceRoot, ".agents", "plugins", "marketplace.json");
|
|
4866
|
+
const hasClaude = yield* kernel.fs.exists(claudePath).pipe(mapFs("marketplace-add", claudePath, "not-started"));
|
|
4867
|
+
const hasCodex = yield* kernel.fs.exists(codexPath).pipe(mapFs("marketplace-add", codexPath, "not-started"));
|
|
4868
|
+
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));
|
|
4869
|
+
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;
|
|
4870
|
+
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;
|
|
4871
|
+
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));
|
|
4872
|
+
const identity = claudeCatalog?.name ?? codexCatalog?.name;
|
|
4873
|
+
if (identity === void 0) return yield* Effect.fail(providerFailure$2("marketplace-add", "ProtocolFailed", "not-started", "Marketplace manifest omitted its identity", sourceRoot));
|
|
4874
|
+
const claudePlugins = claudeCatalog === null ? null : yield* normalizeDeclaredSourcePlugins(claudeCatalog.plugins.map((entry) => ({
|
|
4875
|
+
name: entry.name,
|
|
4876
|
+
rawPath: entry.source
|
|
4877
|
+
})), claudePath);
|
|
4878
|
+
const codexPlugins = codexCatalog === null ? null : yield* normalizeDeclaredSourcePlugins(codexCatalog.plugins.map((entry) => ({
|
|
4879
|
+
name: entry.name,
|
|
4880
|
+
rawPath: entry.source.path
|
|
4881
|
+
})), codexPath);
|
|
4882
|
+
if (claudePlugins !== null && codexPlugins !== null) {
|
|
4883
|
+
if (claudePlugins.length !== codexPlugins.length || claudePlugins.some((plugin, index) => {
|
|
4884
|
+
const other = codexPlugins[index];
|
|
4885
|
+
return other === void 0 || plugin.name !== other.name || plugin.relativeSourcePath !== other.relativeSourcePath;
|
|
4886
|
+
})) return yield* Effect.fail(providerFailure$2("marketplace-add", "ProtocolFailed", "not-started", "Claude and Codex marketplace manifests declare different plugin sets", sourceRoot));
|
|
4887
|
+
}
|
|
4888
|
+
return Object.freeze({
|
|
4889
|
+
identity,
|
|
4890
|
+
plugins: claudePlugins ?? codexPlugins ?? []
|
|
4891
|
+
});
|
|
4892
|
+
});
|
|
4893
|
+
}
|
|
4894
|
+
function normalizeDeclaredSourcePlugins(entries, manifestPath) {
|
|
4895
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4896
|
+
const normalized = [];
|
|
4897
|
+
for (const entry of entries) {
|
|
4898
|
+
if (seen.has(entry.name)) return Effect.fail(providerFailure$2("marketplace-add", "ProtocolFailed", "not-started", `Marketplace manifest contains duplicate plugin ${entry.name}`, manifestPath));
|
|
4899
|
+
seen.add(entry.name);
|
|
4900
|
+
const trimmed = entry.rawPath.startsWith("./") ? entry.rawPath.slice(2) : entry.rawPath;
|
|
4901
|
+
if (!isCanonicalRelativePath(trimmed)) return Effect.fail(providerFailure$2("marketplace-add", "InvalidInput", "not-started", `Marketplace plugin ${entry.name} source path is not canonical`, manifestPath));
|
|
4902
|
+
normalized.push(Object.freeze({
|
|
4903
|
+
name: entry.name,
|
|
4904
|
+
relativeSourcePath: trimmed
|
|
4905
|
+
}));
|
|
4906
|
+
}
|
|
4907
|
+
return Effect.succeed(Object.freeze([...normalized].sort((left, right) => compareText$5(left.name, right.name))));
|
|
4908
|
+
}
|
|
4909
|
+
function readPluginSourceTreeEntries(kernel, pluginSourceRoot) {
|
|
4910
|
+
return Effect.gen(function* () {
|
|
4911
|
+
const entries = [];
|
|
4912
|
+
const visit = (currentDir, prefix) => Effect.gen(function* () {
|
|
4913
|
+
const names = yield* kernel.fs.readDirectory(currentDir).pipe(mapFs("marketplace-add", currentDir, "not-started"));
|
|
4914
|
+
for (const name of [...names].sort(compareText$5)) {
|
|
4915
|
+
const candidate = kernel.paths.join(currentDir, name);
|
|
4916
|
+
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));
|
|
4917
|
+
const stat = yield* kernel.fs.stat(candidate).pipe(mapFs("marketplace-add", candidate, "not-started"));
|
|
4918
|
+
const relativePath = prefix === "" ? name : `${prefix}/${name}`;
|
|
4919
|
+
if (stat.type === "Directory") {
|
|
4920
|
+
yield* visit(candidate, relativePath);
|
|
4921
|
+
continue;
|
|
4922
|
+
}
|
|
4923
|
+
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));
|
|
4924
|
+
if (entries.length >= 16384) return yield* Effect.fail(providerFailure$2("marketplace-add", "LimitExceeded", "not-started", "Plugin source file count exceeds the provider bound", pluginSourceRoot));
|
|
4925
|
+
const size = Number(stat.size);
|
|
4926
|
+
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));
|
|
4927
|
+
const bytes = yield* kernel.fs.readFile(candidate).pipe(mapFs("marketplace-add", candidate, "not-started"));
|
|
4928
|
+
const mode = (Number(stat.mode) & 73) !== 0 ? 493 : 420;
|
|
4929
|
+
entries.push(Object.freeze({
|
|
4930
|
+
path: relativePath,
|
|
4931
|
+
mode,
|
|
4932
|
+
bytes
|
|
4933
|
+
}));
|
|
4934
|
+
}
|
|
4935
|
+
});
|
|
4936
|
+
yield* visit(pluginSourceRoot, "");
|
|
4937
|
+
return Object.freeze(entries);
|
|
4938
|
+
});
|
|
4939
|
+
}
|
|
4940
|
+
function writeProjectedBundle(kernel, stagedPluginDir, entries) {
|
|
4941
|
+
return Effect.gen(function* () {
|
|
4942
|
+
yield* kernel.fs.makeDirectory(stagedPluginDir, { recursive: true }).pipe(mapFs("marketplace-add", stagedPluginDir, "not-started"));
|
|
4943
|
+
for (const entry of entries) {
|
|
4944
|
+
const targetPath = kernel.paths.join(stagedPluginDir, ...entry.path.split("/"));
|
|
4945
|
+
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));
|
|
4946
|
+
const parentDir = kernel.paths.dirname(targetPath);
|
|
4947
|
+
yield* kernel.fs.makeDirectory(parentDir, { recursive: true }).pipe(mapFs("marketplace-add", parentDir, "not-started"));
|
|
4948
|
+
yield* kernel.fs.writeFile(targetPath, entry.bytes).pipe(mapFs("marketplace-add", targetPath, "not-started"));
|
|
4949
|
+
yield* kernel.fs.chmod(targetPath, entry.mode).pipe(mapFs("marketplace-add", targetPath, "not-started"));
|
|
4950
|
+
}
|
|
4951
|
+
});
|
|
4952
|
+
}
|
|
4953
|
+
function removeStagedMarketplace(kernel, identity) {
|
|
4954
|
+
return Effect.gen(function* () {
|
|
4955
|
+
const targetDir = kernel.paths.join(kernel.geminiRoot, "config", "marketplaces", identity);
|
|
4956
|
+
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));
|
|
4957
|
+
const verifiedTarget = yield* kernel.requireLocalDirectory("marketplace-remove", targetDir);
|
|
4958
|
+
yield* kernel.fs.remove(verifiedTarget, { recursive: true }).pipe(mapFs("marketplace-remove", verifiedTarget, "not-started"));
|
|
4959
|
+
return Object.freeze({
|
|
4960
|
+
provider: "antigravity",
|
|
4961
|
+
operation: "marketplace-remove",
|
|
4962
|
+
commandPhase: "command-returned"
|
|
4963
|
+
});
|
|
4964
|
+
});
|
|
4965
|
+
}
|
|
4966
|
+
function installStagedPlugin(kernel, selector) {
|
|
4967
|
+
return Effect.gen(function* () {
|
|
4968
|
+
const parsed = splitSelector(selector, "plugin-install");
|
|
4969
|
+
if (parsed === null) return yield* Effect.fail(providerFailure$2("plugin-install", "InvalidInput", "not-started", "Plugin selector is not canonical"));
|
|
4970
|
+
const stagedPluginDir = kernel.paths.join(kernel.geminiRoot, "config", "marketplaces", parsed.marketplaceIdentity, "plugins", parsed.name);
|
|
4971
|
+
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));
|
|
4972
|
+
const verifiedPluginDir = yield* kernel.requireLocalDirectory("plugin-install", stagedPluginDir);
|
|
4973
|
+
const { existingLedger, previousOwnedTreeSha256 } = yield* verifyInstallSlotOwnership(kernel, parsed);
|
|
4974
|
+
const stagedTreeSha256 = yield* computeDirectoryTreeSha256(kernel, "plugin-install", kernel.home, verifiedPluginDir, "not-started");
|
|
4975
|
+
const pending = yield* recordPendingPluginInstall(kernel, existingLedger, {
|
|
4976
|
+
name: parsed.name,
|
|
4977
|
+
marketplaceIdentity: parsed.marketplaceIdentity,
|
|
4978
|
+
previousTreeSha256: previousOwnedTreeSha256,
|
|
4979
|
+
stagedTreeSha256
|
|
4980
|
+
});
|
|
4981
|
+
const result = yield* kernel.mutation("plugin-install", [
|
|
4982
|
+
"plugin",
|
|
4983
|
+
"install",
|
|
4984
|
+
verifiedPluginDir
|
|
4985
|
+
]);
|
|
4986
|
+
if (pending.needsPostInstallSettle) yield* settlePluginInstall(kernel, {
|
|
4987
|
+
name: parsed.name,
|
|
4988
|
+
marketplaceIdentity: parsed.marketplaceIdentity,
|
|
4989
|
+
stagedTreeSha256
|
|
4990
|
+
});
|
|
4991
|
+
return result;
|
|
4992
|
+
});
|
|
4993
|
+
}
|
|
4994
|
+
function removeInstalledPlugin(kernel, selector) {
|
|
4995
|
+
return Effect.gen(function* () {
|
|
4996
|
+
const parsed = splitSelector(selector, "plugin-remove");
|
|
4997
|
+
if (parsed === null) return yield* Effect.fail(providerFailure$2("plugin-remove", "InvalidInput", "not-started", "Plugin selector is not canonical"));
|
|
4998
|
+
yield* verifyRemoveSlotOwnership(kernel, parsed);
|
|
4999
|
+
const result = yield* kernel.mutation("plugin-remove", [
|
|
5000
|
+
"plugin",
|
|
5001
|
+
"uninstall",
|
|
5002
|
+
parsed.name
|
|
5003
|
+
]).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));
|
|
5004
|
+
yield* deletePluginLedgerEntry(kernel, "plugin-remove", parsed.name);
|
|
5005
|
+
return result;
|
|
5006
|
+
});
|
|
5007
|
+
}
|
|
5008
|
+
function readBoundedRegularBytes(kernel, operation, containmentRoot, candidatePath, maxBytes, phase) {
|
|
5009
|
+
return Effect.gen(function* () {
|
|
5010
|
+
if (!isContained(kernel.paths, containmentRoot, candidatePath)) return yield* Effect.fail(providerFailure$2(operation, "Aliased", phase, "File path escaped its containment root", candidatePath));
|
|
5011
|
+
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));
|
|
5012
|
+
const stat = yield* kernel.fs.stat(candidatePath).pipe(mapFs(operation, candidatePath, phase));
|
|
5013
|
+
if (stat.type !== "File") return yield* Effect.fail(providerFailure$2(operation, "UnsupportedEntry", phase, "Expected a regular file", candidatePath));
|
|
5014
|
+
const size = Number(stat.size);
|
|
5015
|
+
if (!Number.isSafeInteger(size) || size < 0 || size > maxBytes) return yield* Effect.fail(providerFailure$2(operation, "LimitExceeded", phase, "File exceeds bounded size", candidatePath));
|
|
5016
|
+
return yield* kernel.fs.readFile(candidatePath).pipe(mapFs(operation, candidatePath, phase));
|
|
5017
|
+
});
|
|
5018
|
+
}
|
|
5019
|
+
function readBoundedRegularUtf8File(kernel, operation, containmentRoot, candidatePath, maxBytes, phase) {
|
|
5020
|
+
return readBoundedRegularBytes(kernel, operation, containmentRoot, candidatePath, maxBytes, phase).pipe(Effect.flatMap((bytes) => Effect.try({
|
|
5021
|
+
try: () => utf8Decoder.decode(bytes),
|
|
5022
|
+
catch: () => providerFailure$2(operation, "ProtocolFailed", phase, "File is not valid UTF-8", candidatePath)
|
|
5023
|
+
})));
|
|
5024
|
+
}
|
|
5025
|
+
function decodeJsonWithPhase(operation, schema, text, phase) {
|
|
5026
|
+
return Effect.try({
|
|
5027
|
+
try: () => JSON.parse(text),
|
|
5028
|
+
catch: (cause) => providerFailure$2(operation, "InvalidJson", phase, cause instanceof Error ? cause.message : String(cause))
|
|
5029
|
+
}).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"))));
|
|
5030
|
+
}
|
|
5031
|
+
function requireUniqueInventory$2(marketplaces, plugins, mcpServers) {
|
|
5032
|
+
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"));
|
|
5033
|
+
}
|
|
5034
|
+
function selectPluginRoot$2(plugins, selector) {
|
|
5035
|
+
const matches = plugins.filter((entry) => entry.selector === selector && entry.installed);
|
|
5036
|
+
const selected = matches[0];
|
|
5037
|
+
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"));
|
|
5038
|
+
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);
|
|
5039
|
+
}
|
|
5040
|
+
function splitSelector(selector, _operation) {
|
|
5041
|
+
const separator = selector.lastIndexOf("@");
|
|
5042
|
+
if (separator <= 0 || separator === selector.length - 1) return null;
|
|
5043
|
+
return Object.freeze({
|
|
5044
|
+
name: selector.slice(0, separator),
|
|
5045
|
+
marketplaceIdentity: selector.slice(separator + 1)
|
|
5046
|
+
});
|
|
5047
|
+
}
|
|
5048
|
+
function requireVersion$2(stdout) {
|
|
5049
|
+
const version = stdout.trim();
|
|
5050
|
+
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"));
|
|
5051
|
+
}
|
|
5052
|
+
function mapFs(operation, candidate, phase) {
|
|
5053
|
+
return (effect) => effect.pipe(Effect.mapError((cause) => providerFailure$2(operation, cause.reason._tag === "NotFound" ? "Missing" : "FilesystemFailed", phase, cause.message, candidate)));
|
|
5054
|
+
}
|
|
5055
|
+
function providerFailure$2(operation, reason, commandPhase, detail, candidate) {
|
|
5056
|
+
return Object.freeze({
|
|
5057
|
+
_tag: "NativeAgentProviderFailure",
|
|
5058
|
+
provider: "antigravity",
|
|
5059
|
+
operation,
|
|
5060
|
+
reason,
|
|
5061
|
+
commandPhase,
|
|
5062
|
+
...candidate === void 0 ? {} : { path: candidate },
|
|
5063
|
+
detail: detail.slice(0, 4096)
|
|
5064
|
+
});
|
|
5065
|
+
}
|
|
5066
|
+
function isContained(paths, root, candidate) {
|
|
5067
|
+
const relative = paths.relative(root, candidate);
|
|
5068
|
+
return relative !== "" && relative !== ".." && !relative.startsWith(`..${paths.sep}`) && !paths.isAbsolute(relative);
|
|
5069
|
+
}
|
|
5070
|
+
function isCanonicalRelativePath(value) {
|
|
5071
|
+
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 !== "..");
|
|
5072
|
+
}
|
|
5073
|
+
function byIdentity$2(left, right) {
|
|
5074
|
+
return compareText$5(left.identity, right.identity);
|
|
5075
|
+
}
|
|
5076
|
+
function bySelector$2(left, right) {
|
|
5077
|
+
return compareText$5(left.selector, right.selector);
|
|
5078
|
+
}
|
|
5079
|
+
function byMcpName$2(left, right) {
|
|
5080
|
+
return compareText$5(left.name, right.name);
|
|
5081
|
+
}
|
|
5082
|
+
function compareText$5(left, right) {
|
|
5083
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
5084
|
+
}
|
|
5085
|
+
//#endregion
|
|
5086
|
+
//#region ../../resources/native-agent-provider/dist/providers/antigravity-effect-platform-node/runtime.js
|
|
5087
|
+
/** Acquire a fresh capability factory without opening any caller-selected workspace or home. */
|
|
5088
|
+
function defineNodeAntigravityNativeAgentProviderRuntimeProvider() {
|
|
5089
|
+
return defineRuntimeProvider({
|
|
5090
|
+
id: "native-agent-provider.antigravity.antigravity-effect-platform-node",
|
|
5091
|
+
title: "Antigravity native agent provider (antigravity-effect-platform-node)",
|
|
5092
|
+
provides: AntigravityNativeAgentProviderRuntimeResource,
|
|
5093
|
+
requires: [],
|
|
5094
|
+
build: () => providerFx.acquireRelease({
|
|
5095
|
+
acquire: Effect.sync(() => makeNodeAntigravityNativeAgentProviderResource()),
|
|
5096
|
+
release: () => Effect.void
|
|
5097
|
+
})
|
|
5098
|
+
});
|
|
5099
|
+
}
|
|
5100
|
+
//#endregion
|
|
5101
|
+
//#region ../../resources/native-agent-provider/dist/providers/claude-effect-platform-node/mcp.js
|
|
5102
|
+
const MAX_OBSERVED_URL_LENGTH$1 = 4096;
|
|
5103
|
+
/**
|
|
5104
|
+
* Reads and permissively normalizes Claude's user-scope `.claude.json` `mcpServers` entries.
|
|
5105
|
+
*/
|
|
5106
|
+
function readClaudeLiveMcpServers(kernel, operation, commandPhase = "not-started") {
|
|
5107
|
+
return kernel.readClaudeUserConfigJson(operation, commandPhase).pipe(Effect.flatMap((userConfig) => decodeClaudeMcpServers(operation, commandPhase, userConfig)));
|
|
5108
|
+
}
|
|
5109
|
+
/**
|
|
5110
|
+
* Executes a serialized Claude user-scope HTTP MCP add with write-ahead ledger ownership and
|
|
5111
|
+
* rollback on confirmed absence after a failed command.
|
|
5112
|
+
*/
|
|
5113
|
+
function addClaudeMcpServer(kernel, request) {
|
|
5114
|
+
return kernel.serialized("mcp-add", requireMcpServerAddInput("claude", "mcp-add", request).pipe(Effect.flatMap(({ name, url, ownerPluginId }) => Effect.gen(function* () {
|
|
5115
|
+
yield* requireSupportedClaudeOAuthEnvironment("mcp-add", "not-started");
|
|
5116
|
+
yield* kernel.sweepTransientMcpLedger("mcp-add", "not-started");
|
|
5117
|
+
const previousLedger = yield* kernel.readManagedMcpLedger("mcp-add");
|
|
5118
|
+
const liveBefore = yield* readClaudeLiveMcpServers(kernel, "mcp-add", "not-started");
|
|
5119
|
+
const previousEntry = previousLedger.find((entry) => entry.name === name);
|
|
5120
|
+
const existingLive = liveBefore.find((entry) => entry.name === name);
|
|
5121
|
+
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}`));
|
|
5122
|
+
const nextLedger = [...previousLedger.filter((entry) => entry.name !== name), Object.freeze({
|
|
5123
|
+
name,
|
|
5124
|
+
url,
|
|
5125
|
+
ownerPluginId
|
|
5126
|
+
})];
|
|
5127
|
+
yield* kernel.writeManagedMcpLedger("mcp-add", nextLedger, "not-started");
|
|
5128
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-add", [
|
|
5129
|
+
"mcp",
|
|
5130
|
+
"add",
|
|
5131
|
+
"--scope",
|
|
5132
|
+
"user",
|
|
5133
|
+
"--transport",
|
|
5134
|
+
"http",
|
|
5135
|
+
name,
|
|
5136
|
+
url
|
|
5137
|
+
]));
|
|
5138
|
+
if (Result.isSuccess(attempt)) return attempt.success;
|
|
5139
|
+
if (attempt.failure.commandPhase === "not-started") return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
5140
|
+
const liveAfterAttempt = yield* Effect.result(readClaudeLiveMcpServers(kernel, "mcp-add", attempt.failure.commandPhase));
|
|
5141
|
+
if (Result.isSuccess(liveAfterAttempt)) {
|
|
5142
|
+
const liveAfter = liveAfterAttempt.success.find((entry) => entry.name === name);
|
|
5143
|
+
if (liveAfter === void 0 || liveAfter.transport !== "http" || liveAfter.url !== url) return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
5144
|
+
}
|
|
5145
|
+
return yield* Effect.fail(attempt.failure);
|
|
5146
|
+
}))));
|
|
5147
|
+
}
|
|
5148
|
+
/**
|
|
5149
|
+
* Executes a serialized Claude user-scope MCP removal guarded by exact ledger URL ownership and
|
|
5150
|
+
* prunes orphan ledger records without invoking the native CLI when already absent.
|
|
5151
|
+
*/
|
|
5152
|
+
function removeClaudeMcpServer(kernel, request) {
|
|
5153
|
+
return kernel.serialized("mcp-remove", requireMcpServerRemoveInput("claude", "mcp-remove", request).pipe(Effect.flatMap((name) => Effect.gen(function* () {
|
|
5154
|
+
yield* requireSupportedClaudeOAuthEnvironment("mcp-remove", "not-started");
|
|
5155
|
+
yield* kernel.sweepTransientMcpLedger("mcp-remove", "not-started");
|
|
5156
|
+
const currentLedger = yield* kernel.readManagedMcpLedger("mcp-remove");
|
|
5157
|
+
const liveBefore = yield* readClaudeLiveMcpServers(kernel, "mcp-remove", "not-started");
|
|
5158
|
+
const ledgerEntry = currentLedger.find((entry) => entry.name === name);
|
|
5159
|
+
const liveEntry = liveBefore.find((entry) => entry.name === name);
|
|
5160
|
+
if (liveEntry === void 0) {
|
|
5161
|
+
if (ledgerEntry !== void 0) yield* kernel.writeManagedMcpLedger("mcp-remove", currentLedger.filter((entry) => entry.name !== name), "not-started");
|
|
5162
|
+
return Object.freeze({
|
|
5163
|
+
provider: "claude",
|
|
5164
|
+
operation: "mcp-remove",
|
|
5165
|
+
commandPhase: "command-returned"
|
|
5166
|
+
});
|
|
5167
|
+
}
|
|
5168
|
+
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}`));
|
|
5169
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-remove", [
|
|
5170
|
+
"mcp",
|
|
5171
|
+
"remove",
|
|
5172
|
+
"--scope",
|
|
5173
|
+
"user",
|
|
5174
|
+
name
|
|
5175
|
+
]));
|
|
5176
|
+
if (Result.isSuccess(attempt)) {
|
|
5177
|
+
yield* pruneManagedMcpLedgerEntry$1(kernel, name, "command-returned");
|
|
5178
|
+
return attempt.success;
|
|
5179
|
+
}
|
|
5180
|
+
if (attempt.failure.commandPhase !== "command-returned") return yield* Effect.fail(attempt.failure);
|
|
5181
|
+
const liveAfterAttempt = yield* Effect.result(readClaudeLiveMcpServers(kernel, "mcp-remove", "command-returned"));
|
|
5182
|
+
if (Result.isSuccess(liveAfterAttempt) && !liveAfterAttempt.success.some((entry) => entry.name === name)) {
|
|
5183
|
+
yield* pruneManagedMcpLedgerEntry$1(kernel, name, "command-returned");
|
|
5184
|
+
return Object.freeze({
|
|
5185
|
+
provider: "claude",
|
|
5186
|
+
operation: "mcp-remove",
|
|
5187
|
+
commandPhase: "command-returned"
|
|
5188
|
+
});
|
|
5189
|
+
}
|
|
5190
|
+
return yield* Effect.fail(attempt.failure);
|
|
5191
|
+
}))));
|
|
5192
|
+
}
|
|
5193
|
+
function decodeClaudeMcpServers(operation, commandPhase, userConfig) {
|
|
5194
|
+
if (userConfig === null) return Effect.succeed(Object.freeze([]));
|
|
5195
|
+
if (!isPlainRecord$1(userConfig)) return Effect.fail(claudeMcpFailure(operation, "ProtocolFailed", commandPhase, "Claude .claude.json top-level value must be a JSON object"));
|
|
5196
|
+
const rawServers = Reflect.get(userConfig, "mcpServers");
|
|
5197
|
+
if (rawServers === void 0 || rawServers === null) return Effect.succeed(Object.freeze([]));
|
|
5198
|
+
if (!isPlainRecord$1(rawServers)) return Effect.fail(claudeMcpFailure(operation, "ProtocolFailed", commandPhase, "Claude .claude.json mcpServers must be a JSON object"));
|
|
5199
|
+
const entries = Object.entries(rawServers).filter(([name]) => Value.Check(ObservedMcpServerNameSchema, name));
|
|
5200
|
+
if (entries.length > 1024) return Effect.fail(claudeMcpFailure(operation, "LimitExceeded", commandPhase, "Claude .claude.json MCP server count exceeds the resource limit"));
|
|
5201
|
+
return Effect.succeed(Object.freeze(entries.map(([name, entry]) => normalizeClaudeMcpServer(name, entry))));
|
|
5202
|
+
}
|
|
5203
|
+
function normalizeClaudeMcpServer(name, entry) {
|
|
5204
|
+
if (!isPlainRecord$1(entry)) return Object.freeze({
|
|
5205
|
+
name,
|
|
5206
|
+
transport: "other",
|
|
5207
|
+
url: null,
|
|
5208
|
+
enabled: null
|
|
5209
|
+
});
|
|
5210
|
+
const rawEnabled = Reflect.get(entry, "enabled");
|
|
5211
|
+
const rawDisabled = Reflect.get(entry, "disabled");
|
|
5212
|
+
const enabled = typeof rawEnabled === "boolean" ? rawEnabled : typeof rawDisabled === "boolean" ? !rawDisabled : null;
|
|
5213
|
+
const rawUrl = Reflect.get(entry, "url");
|
|
5214
|
+
const url = typeof rawUrl === "string" && rawUrl.length > 0 && rawUrl.length <= MAX_OBSERVED_URL_LENGTH$1 ? rawUrl : null;
|
|
5215
|
+
if (Reflect.get(entry, "type") === "http" && url !== null) return Object.freeze({
|
|
5216
|
+
name,
|
|
5217
|
+
transport: "http",
|
|
5218
|
+
url,
|
|
5219
|
+
enabled
|
|
5220
|
+
});
|
|
5221
|
+
return Object.freeze({
|
|
5222
|
+
name,
|
|
5223
|
+
transport: "other",
|
|
5224
|
+
url,
|
|
5225
|
+
enabled
|
|
5226
|
+
});
|
|
5227
|
+
}
|
|
5228
|
+
function pruneManagedMcpLedgerEntry$1(kernel, name, commandPhase) {
|
|
5229
|
+
return kernel.readManagedMcpLedger("mcp-remove").pipe(Effect.mapError((error) => error.commandPhase === commandPhase ? error : Object.freeze({
|
|
5230
|
+
...error,
|
|
5231
|
+
commandPhase
|
|
5232
|
+
})), Effect.flatMap((current) => {
|
|
5233
|
+
const next = current.filter((entry) => entry.name !== name);
|
|
5234
|
+
return next.length === current.length ? Effect.void : kernel.writeManagedMcpLedger("mcp-remove", next, commandPhase);
|
|
5235
|
+
}));
|
|
5236
|
+
}
|
|
5237
|
+
function isPlainRecord$1(value) {
|
|
5238
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5239
|
+
}
|
|
5240
|
+
function claudeMcpFailure(operation, reason, commandPhase, detail) {
|
|
5241
|
+
return Object.freeze({
|
|
5242
|
+
_tag: "NativeAgentProviderFailure",
|
|
5243
|
+
provider: "claude",
|
|
5244
|
+
operation,
|
|
5245
|
+
reason,
|
|
5246
|
+
commandPhase,
|
|
5247
|
+
detail
|
|
5248
|
+
});
|
|
5249
|
+
}
|
|
5250
|
+
//#endregion
|
|
5251
|
+
//#region ../../resources/native-agent-provider/dist/providers/claude-effect-platform-node/index.js
|
|
5252
|
+
const NullableStringSchema$1 = Type.Union([Type.String(), Type.Null()]);
|
|
5253
|
+
const GitHubRepositorySchema = Type.String({
|
|
5254
|
+
pattern: "^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$",
|
|
5255
|
+
minLength: 3,
|
|
5256
|
+
maxLength: 256
|
|
5257
|
+
});
|
|
5258
|
+
const ClaudeMarketplaceListSchema = Type.Array(Type.Object({
|
|
5259
|
+
name: Type.String(),
|
|
5260
|
+
source: Type.Optional(NullableStringSchema$1),
|
|
5261
|
+
url: Type.Optional(NullableStringSchema$1),
|
|
5262
|
+
repo: Type.Optional(Type.Union([GitHubRepositorySchema, Type.Null()])),
|
|
5263
|
+
path: Type.Optional(NullableStringSchema$1),
|
|
5264
|
+
installLocation: Type.Optional(NullableStringSchema$1),
|
|
5265
|
+
revision: Type.Optional(NullableStringSchema$1),
|
|
5266
|
+
ref: Type.Optional(NullableStringSchema$1)
|
|
5267
|
+
}, { additionalProperties: true }), { maxItems: 1024 });
|
|
5268
|
+
const ClaudePluginListSchema = Type.Array(Type.Object({
|
|
5269
|
+
id: Type.String(),
|
|
5270
|
+
version: Type.Optional(NullableStringSchema$1),
|
|
5271
|
+
enabled: Type.Optional(Type.Union([Type.Boolean(), Type.Null()])),
|
|
5272
|
+
installPath: Type.Optional(NullableStringSchema$1)
|
|
5273
|
+
}, { additionalProperties: true }), { maxItems: 4096 });
|
|
5274
|
+
const CLAUDE_CAPABILITIES = [
|
|
5275
|
+
"marketplace-list",
|
|
5276
|
+
"marketplace-add",
|
|
5277
|
+
"marketplace-remove",
|
|
5278
|
+
"marketplace-update",
|
|
5279
|
+
"plugin-list",
|
|
5280
|
+
"plugin-install",
|
|
5281
|
+
"plugin-enable",
|
|
5282
|
+
"plugin-disable",
|
|
5283
|
+
"plugin-remove",
|
|
5284
|
+
"plugin-update",
|
|
5285
|
+
"mcp-list",
|
|
5286
|
+
"mcp-add",
|
|
5287
|
+
"mcp-remove"
|
|
5288
|
+
];
|
|
5289
|
+
/**
|
|
5290
|
+
* Constructs the platform-requiring Claude provider without choosing a runtime.
|
|
5291
|
+
*/
|
|
5292
|
+
function makeClaudeEffectPlatformNodeProvider(options = {}) {
|
|
5293
|
+
const command = options.command ?? "claude";
|
|
5294
|
+
return Object.freeze({ acquire: (input) => acquireEffectPlatformNodeProvider("claude", command, input, { hostUserHome: options.hostUserHome }).pipe(Effect.map((kernel) => {
|
|
5295
|
+
const probe = () => kernel.serialized("probe", Effect.gen(function* () {
|
|
5296
|
+
const version = yield* kernel.run("probe", ["--version"]);
|
|
5297
|
+
return Object.freeze({
|
|
5298
|
+
provider: "claude",
|
|
5299
|
+
home: kernel.home,
|
|
5300
|
+
version: yield* requireVersion$1(version.stdout),
|
|
5301
|
+
capabilities: [...CLAUDE_CAPABILITIES]
|
|
5302
|
+
});
|
|
5303
|
+
}));
|
|
5304
|
+
const inventory = (inventoryOptions) => kernel.serialized("inventory", requireInventoryOptions("claude", inventoryOptions).pipe(Effect.flatMap((normalized) => claudeInventory(kernel, normalized))));
|
|
5305
|
+
return Object.freeze({
|
|
5306
|
+
provider: "claude",
|
|
5307
|
+
home: kernel.home,
|
|
5308
|
+
probe,
|
|
5309
|
+
inventory,
|
|
5310
|
+
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) => {
|
|
5311
|
+
const missing = Object.freeze({
|
|
5312
|
+
kind: error.reason === "Missing" ? "Missing" : "TooLarge",
|
|
5313
|
+
relativePath: file.relativePath
|
|
5314
|
+
});
|
|
5315
|
+
return Effect.succeed(missing);
|
|
5316
|
+
})), { concurrency: 1 }).pipe(Effect.map((files) => {
|
|
5317
|
+
return Object.freeze({
|
|
5318
|
+
selector: validated.selector,
|
|
5319
|
+
files: Object.freeze(files)
|
|
5320
|
+
});
|
|
5321
|
+
}))))))))),
|
|
5322
|
+
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)))),
|
|
5323
|
+
removeMarketplace: (request) => kernel.serialized("marketplace-remove", requireMarketplaceIdentityInput("claude", "marketplace-remove", request).pipe(Effect.flatMap((identity) => kernel.mutation("marketplace-remove", [
|
|
5324
|
+
"plugin",
|
|
5325
|
+
"marketplace",
|
|
5326
|
+
"remove",
|
|
5327
|
+
identity,
|
|
5328
|
+
"--scope",
|
|
5329
|
+
"user"
|
|
5330
|
+
])))),
|
|
5331
|
+
installPlugin: (request) => kernel.serialized("plugin-install", requirePluginSelectorInput("claude", "plugin-install", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-install", "install", selector)))),
|
|
5332
|
+
enablePlugin: (request) => kernel.serialized("plugin-enable", requirePluginSelectorInput("claude", "plugin-enable", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-enable", "enable", selector)))),
|
|
5333
|
+
removePlugin: (request) => kernel.serialized("plugin-remove", requirePluginSelectorInput("claude", "plugin-remove", request).pipe(Effect.flatMap((selector) => pluginMutation(kernel, "plugin-remove", "uninstall", selector)))),
|
|
5334
|
+
addMcpServer: (request) => addClaudeMcpServer(kernel, request),
|
|
5335
|
+
removeMcpServer: (request) => removeClaudeMcpServer(kernel, request)
|
|
5336
|
+
});
|
|
5337
|
+
})) });
|
|
5338
|
+
}
|
|
5339
|
+
/**
|
|
5340
|
+
* Constructs a ready Claude resource whose Node platform is supplied only while
|
|
5341
|
+
* acquiring a session.
|
|
5342
|
+
*/
|
|
5343
|
+
function makeNodeClaudeNativeAgentProviderResource(options = {}) {
|
|
5344
|
+
const provider = makeClaudeEffectPlatformNodeProvider(options);
|
|
5345
|
+
return Object.freeze({ acquire: (input) => provider.acquire(input).pipe(Effect.provide(NodeServices.layer)) });
|
|
5346
|
+
}
|
|
5347
|
+
function claudeInstalledPlugins(kernel) {
|
|
5348
|
+
return Effect.gen(function* () {
|
|
5349
|
+
const marketplaceOutput = yield* kernel.run("inventory", [
|
|
5350
|
+
"plugin",
|
|
5351
|
+
"marketplace",
|
|
5352
|
+
"list",
|
|
5353
|
+
"--json"
|
|
5354
|
+
]);
|
|
5355
|
+
const pluginOutput = yield* kernel.run("inventory", [
|
|
5356
|
+
"plugin",
|
|
5357
|
+
"list",
|
|
5358
|
+
"--json"
|
|
5359
|
+
]);
|
|
5360
|
+
const marketplaceRecord = yield* decodeProviderJson("claude", "inventory", ClaudeMarketplaceListSchema, marketplaceOutput.stdout);
|
|
5361
|
+
const pluginRecord = yield* decodeProviderJson("claude", "inventory", ClaudePluginListSchema, pluginOutput.stdout);
|
|
5362
|
+
const marketplaces = yield* Effect.forEach(marketplaceRecord, normalizeMarketplace$1, { concurrency: 1 });
|
|
5363
|
+
const plugins = yield* Effect.forEach(pluginRecord, normalizePlugin$1, { concurrency: 1 });
|
|
5364
|
+
yield* requireUniqueInventory$1(marketplaces, plugins, []);
|
|
5365
|
+
return Object.freeze([...plugins].sort(bySelector$1));
|
|
5366
|
+
});
|
|
5367
|
+
}
|
|
5368
|
+
function claudeInventory(kernel, options) {
|
|
5369
|
+
return Effect.gen(function* () {
|
|
5370
|
+
const marketplaceOutput = yield* kernel.run("inventory", [
|
|
5371
|
+
"plugin",
|
|
5372
|
+
"marketplace",
|
|
5373
|
+
"list",
|
|
5374
|
+
"--json"
|
|
3491
5375
|
]);
|
|
3492
5376
|
const pluginOutput = yield* kernel.run("inventory", [
|
|
3493
5377
|
"plugin",
|
|
3494
5378
|
"list",
|
|
3495
5379
|
"--json"
|
|
3496
5380
|
]);
|
|
5381
|
+
const managedMcpServers = yield* kernel.readManagedMcpLedger("inventory");
|
|
5382
|
+
const mcpServers = shouldObserveProviderMcpConfig(options, managedMcpServers) ? yield* readClaudeLiveMcpServers(kernel, "inventory", "not-started") : Object.freeze([]);
|
|
3497
5383
|
const marketplaceRecord = yield* decodeProviderJson("claude", "inventory", ClaudeMarketplaceListSchema, marketplaceOutput.stdout);
|
|
3498
5384
|
const pluginRecord = yield* decodeProviderJson("claude", "inventory", ClaudePluginListSchema, pluginOutput.stdout);
|
|
3499
5385
|
const marketplaces = yield* Effect.forEach(marketplaceRecord, normalizeMarketplace$1, { concurrency: 1 });
|
|
3500
5386
|
const plugins = yield* Effect.forEach(pluginRecord, normalizePlugin$1, { concurrency: 1 });
|
|
3501
|
-
yield* requireUniqueInventory$1(marketplaces, plugins);
|
|
5387
|
+
yield* requireUniqueInventory$1(marketplaces, plugins, mcpServers);
|
|
3502
5388
|
const normalized = Object.freeze({
|
|
3503
5389
|
provider: "claude",
|
|
3504
5390
|
marketplaces: [...marketplaces].sort(byIdentity$1),
|
|
3505
|
-
plugins: [...plugins].sort(bySelector$1)
|
|
5391
|
+
plugins: [...plugins].sort(bySelector$1),
|
|
5392
|
+
mcpServers: [...mcpServers].sort(byMcpName$1),
|
|
5393
|
+
managedMcpServers
|
|
3506
5394
|
});
|
|
3507
5395
|
return Value.Check(NativeProviderInventorySchema, normalized) ? normalized : yield* Effect.fail(providerFailure$1("inventory", "ProtocolFailed", "Claude native inventory contains non-canonical facts"));
|
|
3508
5396
|
});
|
|
@@ -3562,8 +5450,8 @@ function normalizePlugin$1(entry) {
|
|
|
3562
5450
|
root: entry.installPath ?? null
|
|
3563
5451
|
}));
|
|
3564
5452
|
}
|
|
3565
|
-
function requireUniqueInventory$1(marketplaces, plugins) {
|
|
3566
|
-
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"));
|
|
5453
|
+
function requireUniqueInventory$1(marketplaces, plugins, mcpServers) {
|
|
5454
|
+
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"));
|
|
3567
5455
|
}
|
|
3568
5456
|
function selectPluginRoot$1(plugins, selector) {
|
|
3569
5457
|
const matches = plugins.filter((entry) => entry.selector === selector && entry.installed);
|
|
@@ -3619,6 +5507,9 @@ function byIdentity$1(left, right) {
|
|
|
3619
5507
|
function bySelector$1(left, right) {
|
|
3620
5508
|
return compareText$4(left.selector, right.selector);
|
|
3621
5509
|
}
|
|
5510
|
+
function byMcpName$1(left, right) {
|
|
5511
|
+
return compareText$4(left.name, right.name);
|
|
5512
|
+
}
|
|
3622
5513
|
function compareText$4(left, right) {
|
|
3623
5514
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
3624
5515
|
}
|
|
@@ -3638,6 +5529,151 @@ function defineNodeClaudeNativeAgentProviderRuntimeProvider() {
|
|
|
3638
5529
|
});
|
|
3639
5530
|
}
|
|
3640
5531
|
//#endregion
|
|
5532
|
+
//#region ../../resources/native-agent-provider/dist/providers/codex-effect-platform-node/mcp.js
|
|
5533
|
+
const MAX_OBSERVED_URL_LENGTH = 4096;
|
|
5534
|
+
/**
|
|
5535
|
+
* Reads and permissively normalizes Codex's offline `<CODEX_HOME>/config.toml` `[mcp_servers]`
|
|
5536
|
+
* table without triggering network-probing `codex mcp list` commands.
|
|
5537
|
+
*/
|
|
5538
|
+
function readCodexLiveMcpServers(kernel, operation, commandPhase = "not-started") {
|
|
5539
|
+
return kernel.readCodexConfigToml(operation, commandPhase).pipe(Effect.flatMap((configToml) => decodeCodexMcpServers(operation, commandPhase, configToml)));
|
|
5540
|
+
}
|
|
5541
|
+
/**
|
|
5542
|
+
* Executes a serialized Codex user-scope HTTP MCP add with write-ahead ledger ownership and
|
|
5543
|
+
* rollback on confirmed absence after a failed command.
|
|
5544
|
+
*/
|
|
5545
|
+
function addCodexMcpServer(kernel, request) {
|
|
5546
|
+
return kernel.serialized("mcp-add", requireMcpServerAddInput("codex", "mcp-add", request).pipe(Effect.flatMap(({ name, url, ownerPluginId }) => Effect.gen(function* () {
|
|
5547
|
+
yield* kernel.sweepTransientMcpLedger("mcp-add", "not-started");
|
|
5548
|
+
const previousLedger = yield* kernel.readManagedMcpLedger("mcp-add");
|
|
5549
|
+
const liveBefore = yield* readCodexLiveMcpServers(kernel, "mcp-add", "not-started");
|
|
5550
|
+
const previousEntry = previousLedger.find((entry) => entry.name === name);
|
|
5551
|
+
const existingLive = liveBefore.find((entry) => entry.name === name);
|
|
5552
|
+
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}`));
|
|
5553
|
+
const nextLedger = [...previousLedger.filter((entry) => entry.name !== name), Object.freeze({
|
|
5554
|
+
name,
|
|
5555
|
+
url,
|
|
5556
|
+
ownerPluginId
|
|
5557
|
+
})];
|
|
5558
|
+
yield* kernel.writeManagedMcpLedger("mcp-add", nextLedger, "not-started");
|
|
5559
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-add", [
|
|
5560
|
+
"mcp",
|
|
5561
|
+
"add",
|
|
5562
|
+
name,
|
|
5563
|
+
"--url",
|
|
5564
|
+
url
|
|
5565
|
+
]));
|
|
5566
|
+
if (Result.isSuccess(attempt)) return attempt.success;
|
|
5567
|
+
if (attempt.failure.commandPhase === "not-started") return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
5568
|
+
const liveAfterAttempt = yield* Effect.result(readCodexLiveMcpServers(kernel, "mcp-add", attempt.failure.commandPhase));
|
|
5569
|
+
if (Result.isSuccess(liveAfterAttempt)) {
|
|
5570
|
+
const liveAfter = liveAfterAttempt.success.find((entry) => entry.name === name);
|
|
5571
|
+
if (liveAfter === void 0 || liveAfter.transport !== "http" || liveAfter.url !== url) return yield* rollbackWriteAheadMcpLedger(kernel.writeManagedMcpLedger, previousLedger, attempt.failure);
|
|
5572
|
+
}
|
|
5573
|
+
return yield* Effect.fail(attempt.failure);
|
|
5574
|
+
}))));
|
|
5575
|
+
}
|
|
5576
|
+
/**
|
|
5577
|
+
* Executes a serialized Codex user-scope MCP removal guarded by exact ledger URL ownership and
|
|
5578
|
+
* prunes orphan ledger records without invoking the native CLI when already absent.
|
|
5579
|
+
*/
|
|
5580
|
+
function removeCodexMcpServer(kernel, request) {
|
|
5581
|
+
return kernel.serialized("mcp-remove", requireMcpServerRemoveInput("codex", "mcp-remove", request).pipe(Effect.flatMap((name) => Effect.gen(function* () {
|
|
5582
|
+
yield* kernel.sweepTransientMcpLedger("mcp-remove", "not-started");
|
|
5583
|
+
const currentLedger = yield* kernel.readManagedMcpLedger("mcp-remove");
|
|
5584
|
+
const liveBefore = yield* readCodexLiveMcpServers(kernel, "mcp-remove", "not-started");
|
|
5585
|
+
const ledgerEntry = currentLedger.find((entry) => entry.name === name);
|
|
5586
|
+
const liveEntry = liveBefore.find((entry) => entry.name === name);
|
|
5587
|
+
if (liveEntry === void 0) {
|
|
5588
|
+
if (ledgerEntry !== void 0) yield* kernel.writeManagedMcpLedger("mcp-remove", currentLedger.filter((entry) => entry.name !== name), "not-started");
|
|
5589
|
+
return Object.freeze({
|
|
5590
|
+
provider: "codex",
|
|
5591
|
+
operation: "mcp-remove",
|
|
5592
|
+
commandPhase: "command-returned"
|
|
5593
|
+
});
|
|
5594
|
+
}
|
|
5595
|
+
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}`));
|
|
5596
|
+
const attempt = yield* Effect.result(kernel.mutation("mcp-remove", [
|
|
5597
|
+
"mcp",
|
|
5598
|
+
"remove",
|
|
5599
|
+
name
|
|
5600
|
+
]));
|
|
5601
|
+
if (Result.isSuccess(attempt)) {
|
|
5602
|
+
yield* pruneManagedMcpLedgerEntry(kernel, name, "command-returned");
|
|
5603
|
+
return attempt.success;
|
|
5604
|
+
}
|
|
5605
|
+
if (attempt.failure.commandPhase !== "command-returned") return yield* Effect.fail(attempt.failure);
|
|
5606
|
+
const liveAfterAttempt = yield* Effect.result(readCodexLiveMcpServers(kernel, "mcp-remove", "command-returned"));
|
|
5607
|
+
if (Result.isSuccess(liveAfterAttempt) && !liveAfterAttempt.success.some((entry) => entry.name === name)) {
|
|
5608
|
+
yield* pruneManagedMcpLedgerEntry(kernel, name, "command-returned");
|
|
5609
|
+
return Object.freeze({
|
|
5610
|
+
provider: "codex",
|
|
5611
|
+
operation: "mcp-remove",
|
|
5612
|
+
commandPhase: "command-returned"
|
|
5613
|
+
});
|
|
5614
|
+
}
|
|
5615
|
+
return yield* Effect.fail(attempt.failure);
|
|
5616
|
+
}))));
|
|
5617
|
+
}
|
|
5618
|
+
function decodeCodexMcpServers(operation, commandPhase, configToml) {
|
|
5619
|
+
if (configToml === null) return Effect.succeed(Object.freeze([]));
|
|
5620
|
+
if (!isPlainRecord(configToml)) return Effect.fail(codexMcpFailure(operation, "ProtocolFailed", commandPhase, "Codex config.toml top-level value must be a TOML table"));
|
|
5621
|
+
const rawServers = Reflect.get(configToml, "mcp_servers");
|
|
5622
|
+
if (rawServers === void 0 || rawServers === null) return Effect.succeed(Object.freeze([]));
|
|
5623
|
+
if (!isPlainRecord(rawServers)) return Effect.fail(codexMcpFailure(operation, "ProtocolFailed", commandPhase, "Codex config.toml mcp_servers must be a TOML table"));
|
|
5624
|
+
const entries = Object.entries(rawServers).filter(([name]) => Value.Check(ObservedMcpServerNameSchema, name));
|
|
5625
|
+
if (entries.length > 1024) return Effect.fail(codexMcpFailure(operation, "LimitExceeded", commandPhase, "Codex config.toml MCP server count exceeds the resource limit"));
|
|
5626
|
+
return Effect.succeed(Object.freeze(entries.map(([name, entry]) => normalizeCodexMcpServer(name, entry))));
|
|
5627
|
+
}
|
|
5628
|
+
function normalizeCodexMcpServer(name, entry) {
|
|
5629
|
+
if (!isPlainRecord(entry)) return Object.freeze({
|
|
5630
|
+
name,
|
|
5631
|
+
transport: "other",
|
|
5632
|
+
url: null,
|
|
5633
|
+
enabled: true
|
|
5634
|
+
});
|
|
5635
|
+
const rawEnabled = Reflect.get(entry, "enabled");
|
|
5636
|
+
const hasValidEnabled = rawEnabled === void 0 || typeof rawEnabled === "boolean";
|
|
5637
|
+
const enabled = typeof rawEnabled === "boolean" ? rawEnabled : true;
|
|
5638
|
+
const rawCommand = Reflect.get(entry, "command");
|
|
5639
|
+
const rawUrl = Reflect.get(entry, "url");
|
|
5640
|
+
const validUrl = typeof rawUrl === "string" && rawUrl.length > 0 && rawUrl.length <= MAX_OBSERVED_URL_LENGTH ? rawUrl : null;
|
|
5641
|
+
if (rawCommand === void 0 && validUrl !== null && hasValidEnabled) return Object.freeze({
|
|
5642
|
+
name,
|
|
5643
|
+
transport: "http",
|
|
5644
|
+
url: validUrl,
|
|
5645
|
+
enabled
|
|
5646
|
+
});
|
|
5647
|
+
return Object.freeze({
|
|
5648
|
+
name,
|
|
5649
|
+
transport: "other",
|
|
5650
|
+
url: null,
|
|
5651
|
+
enabled
|
|
5652
|
+
});
|
|
5653
|
+
}
|
|
5654
|
+
function pruneManagedMcpLedgerEntry(kernel, name, commandPhase) {
|
|
5655
|
+
return kernel.readManagedMcpLedger("mcp-remove").pipe(Effect.mapError((error) => error.commandPhase === commandPhase ? error : Object.freeze({
|
|
5656
|
+
...error,
|
|
5657
|
+
commandPhase
|
|
5658
|
+
})), Effect.flatMap((current) => {
|
|
5659
|
+
const next = current.filter((entry) => entry.name !== name);
|
|
5660
|
+
return next.length === current.length ? Effect.void : kernel.writeManagedMcpLedger("mcp-remove", next, commandPhase);
|
|
5661
|
+
}));
|
|
5662
|
+
}
|
|
5663
|
+
function isPlainRecord(value) {
|
|
5664
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5665
|
+
}
|
|
5666
|
+
function codexMcpFailure(operation, reason, commandPhase, detail) {
|
|
5667
|
+
return Object.freeze({
|
|
5668
|
+
_tag: "NativeAgentProviderFailure",
|
|
5669
|
+
provider: "codex",
|
|
5670
|
+
operation,
|
|
5671
|
+
reason,
|
|
5672
|
+
commandPhase,
|
|
5673
|
+
detail
|
|
5674
|
+
});
|
|
5675
|
+
}
|
|
5676
|
+
//#endregion
|
|
3641
5677
|
//#region ../../resources/native-agent-provider/dist/providers/codex-effect-platform-node/index.js
|
|
3642
5678
|
const NullableStringSchema = Type.Union([Type.String(), Type.Null()]);
|
|
3643
5679
|
const CodexMarketplaceSourceSchema = Type.Union([Type.Object({
|
|
@@ -3663,7 +5699,10 @@ const CODEX_CAPABILITIES = [
|
|
|
3663
5699
|
"marketplace-remove",
|
|
3664
5700
|
"plugin-list",
|
|
3665
5701
|
"plugin-install",
|
|
3666
|
-
"plugin-remove"
|
|
5702
|
+
"plugin-remove",
|
|
5703
|
+
"mcp-list",
|
|
5704
|
+
"mcp-add",
|
|
5705
|
+
"mcp-remove"
|
|
3667
5706
|
];
|
|
3668
5707
|
/**
|
|
3669
5708
|
* Constructs the platform-requiring Codex provider without choosing a runtime.
|
|
@@ -3680,14 +5719,13 @@ function makeCodexEffectPlatformNodeProvider(options = {}) {
|
|
|
3680
5719
|
capabilities: [...CODEX_CAPABILITIES]
|
|
3681
5720
|
});
|
|
3682
5721
|
}));
|
|
3683
|
-
const
|
|
3684
|
-
const inventory = () => kernel.serialized("inventory", readInventory());
|
|
5722
|
+
const inventory = (inventoryOptions) => kernel.serialized("inventory", requireInventoryOptions("codex", inventoryOptions).pipe(Effect.flatMap((normalized) => codexInventory(kernel, normalized))));
|
|
3685
5723
|
return Object.freeze({
|
|
3686
5724
|
provider: "codex",
|
|
3687
5725
|
home: kernel.home,
|
|
3688
5726
|
probe,
|
|
3689
5727
|
inventory,
|
|
3690
|
-
readPluginFiles: (request) => kernel.serialized("plugin-files-read", requirePluginFilesReadInput("codex", "plugin-files-read", request).pipe(Effect.flatMap((validated) =>
|
|
5728
|
+
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) => {
|
|
3691
5729
|
const missing = Object.freeze({
|
|
3692
5730
|
kind: error.reason === "Missing" ? "Missing" : "TooLarge",
|
|
3693
5731
|
relativePath: file.relativePath
|
|
@@ -3718,7 +5756,9 @@ function makeCodexEffectPlatformNodeProvider(options = {}) {
|
|
|
3718
5756
|
"remove",
|
|
3719
5757
|
selector,
|
|
3720
5758
|
"--json"
|
|
3721
|
-
]))))
|
|
5759
|
+
])))),
|
|
5760
|
+
addMcpServer: (request) => addCodexMcpServer(kernel, request),
|
|
5761
|
+
removeMcpServer: (request) => removeCodexMcpServer(kernel, request)
|
|
3722
5762
|
});
|
|
3723
5763
|
})) });
|
|
3724
5764
|
}
|
|
@@ -3730,7 +5770,28 @@ function makeNodeCodexNativeAgentProviderResource(options = {}) {
|
|
|
3730
5770
|
const provider = makeCodexEffectPlatformNodeProvider(options);
|
|
3731
5771
|
return Object.freeze({ acquire: (input) => provider.acquire(input).pipe(Effect.provide(NodeServices.layer)) });
|
|
3732
5772
|
}
|
|
3733
|
-
function
|
|
5773
|
+
function codexInstalledPlugins(kernel) {
|
|
5774
|
+
return Effect.gen(function* () {
|
|
5775
|
+
const marketplaceOutput = yield* kernel.run("inventory", [
|
|
5776
|
+
"plugin",
|
|
5777
|
+
"marketplace",
|
|
5778
|
+
"list",
|
|
5779
|
+
"--json"
|
|
5780
|
+
]);
|
|
5781
|
+
const pluginOutput = yield* kernel.run("inventory", [
|
|
5782
|
+
"plugin",
|
|
5783
|
+
"list",
|
|
5784
|
+
"--json"
|
|
5785
|
+
]);
|
|
5786
|
+
const marketplaceRecord = yield* decodeProviderJson("codex", "inventory", CodexMarketplaceListSchema, marketplaceOutput.stdout);
|
|
5787
|
+
const pluginRecord = yield* decodeProviderJson("codex", "inventory", CodexPluginListSchema, pluginOutput.stdout);
|
|
5788
|
+
const marketplaces = yield* Effect.forEach(marketplaceRecord.marketplaces, normalizeMarketplace, { concurrency: 1 });
|
|
5789
|
+
const plugins = yield* Effect.forEach(pluginRecord.installed, normalizePlugin, { concurrency: 1 });
|
|
5790
|
+
yield* requireUniqueInventory(marketplaces, plugins, []);
|
|
5791
|
+
return Object.freeze([...plugins].sort(bySelector));
|
|
5792
|
+
});
|
|
5793
|
+
}
|
|
5794
|
+
function codexInventory(kernel, options) {
|
|
3734
5795
|
return Effect.gen(function* () {
|
|
3735
5796
|
const marketplaceOutput = yield* kernel.run("inventory", [
|
|
3736
5797
|
"plugin",
|
|
@@ -3743,15 +5804,19 @@ function codexInventory(kernel) {
|
|
|
3743
5804
|
"list",
|
|
3744
5805
|
"--json"
|
|
3745
5806
|
]);
|
|
5807
|
+
const managedMcpServers = yield* kernel.readManagedMcpLedger("inventory");
|
|
5808
|
+
const mcpServers = shouldObserveProviderMcpConfig(options, managedMcpServers) ? yield* readCodexLiveMcpServers(kernel, "inventory", "not-started") : Object.freeze([]);
|
|
3746
5809
|
const marketplaceRecord = yield* decodeProviderJson("codex", "inventory", CodexMarketplaceListSchema, marketplaceOutput.stdout);
|
|
3747
5810
|
const pluginRecord = yield* decodeProviderJson("codex", "inventory", CodexPluginListSchema, pluginOutput.stdout);
|
|
3748
5811
|
const marketplaces = yield* Effect.forEach(marketplaceRecord.marketplaces, normalizeMarketplace, { concurrency: 1 });
|
|
3749
5812
|
const plugins = yield* Effect.forEach(pluginRecord.installed, normalizePlugin, { concurrency: 1 });
|
|
3750
|
-
yield* requireUniqueInventory(marketplaces, plugins);
|
|
5813
|
+
yield* requireUniqueInventory(marketplaces, plugins, mcpServers);
|
|
3751
5814
|
const normalized = Object.freeze({
|
|
3752
5815
|
provider: "codex",
|
|
3753
5816
|
marketplaces: [...marketplaces].sort(byIdentity),
|
|
3754
|
-
plugins: [...plugins].sort(bySelector)
|
|
5817
|
+
plugins: [...plugins].sort(bySelector),
|
|
5818
|
+
mcpServers: [...mcpServers].sort(byMcpName),
|
|
5819
|
+
managedMcpServers
|
|
3755
5820
|
});
|
|
3756
5821
|
return Value.Check(NativeProviderInventorySchema, normalized) ? normalized : yield* Effect.fail(providerFailure("inventory", "ProtocolFailed", "Codex native inventory contains non-canonical facts"));
|
|
3757
5822
|
});
|
|
@@ -3789,8 +5854,8 @@ function normalizePlugin(entry) {
|
|
|
3789
5854
|
root: null
|
|
3790
5855
|
})) : Effect.fail(providerFailure("inventory", "ProtocolFailed", "Codex plugin identity fields do not describe one selector"));
|
|
3791
5856
|
}
|
|
3792
|
-
function requireUniqueInventory(marketplaces, plugins) {
|
|
3793
|
-
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"));
|
|
5857
|
+
function requireUniqueInventory(marketplaces, plugins, mcpServers) {
|
|
5858
|
+
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"));
|
|
3794
5859
|
}
|
|
3795
5860
|
function selectPluginRoot(kernel, plugins, selector) {
|
|
3796
5861
|
const matches = plugins.filter((entry) => entry.selector === selector && entry.installed);
|
|
@@ -3838,6 +5903,9 @@ function byIdentity(left, right) {
|
|
|
3838
5903
|
function bySelector(left, right) {
|
|
3839
5904
|
return compareText$3(left.selector, right.selector);
|
|
3840
5905
|
}
|
|
5906
|
+
function byMcpName(left, right) {
|
|
5907
|
+
return compareText$3(left.name, right.name);
|
|
5908
|
+
}
|
|
3841
5909
|
function compareText$3(left, right) {
|
|
3842
5910
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
3843
5911
|
}
|
|
@@ -3863,6 +5931,8 @@ const GRIT_PATTERN_PREFIX = "habitat_rule_evaluation_";
|
|
|
3863
5931
|
const MAX_GRIT_STDOUT_BYTES = 262144;
|
|
3864
5932
|
const GRIT_REPORT_HEADROOM_BYTES = 262144;
|
|
3865
5933
|
const MAX_GRIT_STDERR_BYTES = 16777216;
|
|
5934
|
+
const WINDOWS_COMMAND_LINE_LIMIT = 32767;
|
|
5935
|
+
const WINDOWS_DISK_SUBJECT_PATH = /^(?:[A-Za-z]:\/|\/\/(?![.?]\/)[^/]+\/[^/]+(?:\/|$))/u;
|
|
3866
5936
|
/** Structural schema for Grit provider construction. */
|
|
3867
5937
|
const GritRuleEvaluationProviderConfigSchema = ReadonlyObject(Type.Object({
|
|
3868
5938
|
command: Type.String({
|
|
@@ -3934,12 +6004,26 @@ function makeGritRuleEvaluationResource(config) {
|
|
|
3934
6004
|
const [firstProgram, ...remainingPrograms] = input.programs;
|
|
3935
6005
|
if (firstProgram === void 0) return yield* fail$2("InvalidInput", "Rule-evaluation request requires at least one program");
|
|
3936
6006
|
if (new Set(input.programs.map(({ id }) => id)).size !== input.programs.length) return yield* fail$2("InvalidInput", "Rule-evaluation program identities must be unique");
|
|
6007
|
+
const subjectPaths = path.sep === "\\" ? yield* windowsFileArguments(input.subjectPaths) : input.subjectPaths;
|
|
3937
6008
|
const programs = [materializeProgram(firstProgram, 0), ...remainingPrograms.map((program) => materializeProgram(program, 0))];
|
|
3938
|
-
const evaluations = yield* Effect.forEach(programs, (program) => Effect.scoped(withScopedGritCatalog([program], (catalog) => runGritCheck(config, catalog, [program],
|
|
6009
|
+
const evaluations = yield* Effect.forEach(programs, (program) => Effect.scoped(withScopedGritCatalog([program], (catalog) => runGritCheck(config, catalog, [program], subjectPaths))), { concurrency: 1 });
|
|
3939
6010
|
return Object.freeze({ results: Object.freeze(evaluations.flatMap(({ results }) => results)) });
|
|
3940
6011
|
});
|
|
3941
6012
|
return Object.freeze({ evaluate });
|
|
3942
6013
|
}
|
|
6014
|
+
const windowsFileArguments = Effect.fn(function* (subjectPaths) {
|
|
6015
|
+
const args = subjectPaths.map((subjectPath) => subjectPath.replaceAll("\\", "/"));
|
|
6016
|
+
if (args.some((arg) => !WINDOWS_DISK_SUBJECT_PATH.test(arg))) return yield* fail$2("InvalidInput", "Windows Grit subjects must use drive-absolute or UNC paths outside device namespaces");
|
|
6017
|
+
const fs = yield* FileSystem.FileSystem;
|
|
6018
|
+
for (const subjectPath of subjectPaths) {
|
|
6019
|
+
const info = yield* fs.stat(subjectPath).pipe(mapPlatform$2("ExecutionFailed", `Failed to inspect Windows Grit subject '${subjectPath}'`));
|
|
6020
|
+
if (info.type === "Directory") return yield* fail$2("ExecutionFailed", `Grit cannot evaluate on Windows when a subject is a directory. Run this check on a POSIX host (macOS or Linux). Directory: '${subjectPath}'`);
|
|
6021
|
+
if (info.type !== "File") return yield* fail$2("ExecutionFailed", `Unsupported Windows Grit subject type '${info.type}'; expected a regular file: '${subjectPath}'`);
|
|
6022
|
+
}
|
|
6023
|
+
const subjectUnits = args.reduce((total, arg) => total + arg.length + 1, 0);
|
|
6024
|
+
if (subjectUnits > WINDOWS_COMMAND_LINE_LIMIT) return yield* fail$2("ExecutionFailed", `Grit file arguments exceed the Windows command line limit of ${WINDOWS_COMMAND_LINE_LIMIT} UTF-16 code units (selected files: ${args.length}; minimum required: ${subjectUnits}). Run this check on a POSIX host (macOS or Linux).`);
|
|
6025
|
+
return args;
|
|
6026
|
+
});
|
|
3943
6027
|
function withScopedGritCatalog(programs, use) {
|
|
3944
6028
|
return Effect.gen(function* () {
|
|
3945
6029
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -4673,6 +6757,10 @@ const localProfile = defineRuntimeProfile({
|
|
|
4673
6757
|
resource: ClaudeNativeAgentProviderRuntimeResource,
|
|
4674
6758
|
provider: defineNodeClaudeNativeAgentProviderRuntimeProvider()
|
|
4675
6759
|
}),
|
|
6760
|
+
providerSelection({
|
|
6761
|
+
resource: AntigravityNativeAgentProviderRuntimeResource,
|
|
6762
|
+
provider: defineNodeAntigravityNativeAgentProviderRuntimeProvider()
|
|
6763
|
+
}),
|
|
4676
6764
|
providerSelection({
|
|
4677
6765
|
resource: FilesystemRuntimeResource,
|
|
4678
6766
|
provider: defineNodeFilesystemRuntimeProvider()
|