@mcoda/mswarm 0.1.133 → 0.1.135-codali.10
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 +44 -0
- package/dist/codali-executor.d.ts +79 -1
- package/dist/codali-executor.d.ts.map +1 -1
- package/dist/codali-executor.js +115 -8
- package/dist/codali-executor.js.map +1 -1
- package/dist/invocation-token.d.ts.map +1 -1
- package/dist/invocation-token.js +1 -0
- package/dist/invocation-token.js.map +1 -1
- package/dist/native-reasoning.d.ts +8 -0
- package/dist/native-reasoning.d.ts.map +1 -0
- package/dist/native-reasoning.js +18 -0
- package/dist/native-reasoning.js.map +1 -0
- package/dist/runtime.d.ts +25 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +226 -22
- package/dist/runtime.js.map +1 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +58 -8
- package/dist/server.js.map +1 -1
- package/dist/vendor/codali/agents/RoleResolution.d.ts.map +1 -1
- package/dist/vendor/codali/agents/RoleResolution.js +4 -4
- package/dist/vendor/codali/api/CodaliApi.d.ts +16 -0
- package/dist/vendor/codali/api/CodaliApi.d.ts.map +1 -1
- package/dist/vendor/codali/api/CodaliApi.js +39 -10
- package/dist/vendor/codali/cli/AskCommand.d.ts +3 -0
- package/dist/vendor/codali/cli/AskCommand.d.ts.map +1 -1
- package/dist/vendor/codali/cli/AskCommand.js +76 -13
- package/dist/vendor/codali/cli/RunCommand.d.ts +4 -0
- package/dist/vendor/codali/cli/RunCommand.d.ts.map +1 -1
- package/dist/vendor/codali/cli/RunCommand.js +110 -24
- package/dist/vendor/codali/cli/TerminalCommand.d.ts +35 -0
- package/dist/vendor/codali/cli/TerminalCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalCommand.js +618 -0
- package/dist/vendor/codali/cli/TerminalCredentials.d.ts +3 -0
- package/dist/vendor/codali/cli/TerminalCredentials.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalCredentials.js +89 -0
- package/dist/vendor/codali/cli/TerminalInput.d.ts +24 -0
- package/dist/vendor/codali/cli/TerminalInput.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalInput.js +98 -0
- package/dist/vendor/codali/cli/TerminalText.d.ts +10 -0
- package/dist/vendor/codali/cli/TerminalText.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalText.js +53 -0
- package/dist/vendor/codali/cli.d.ts.map +1 -1
- package/dist/vendor/codali/cli.js +33 -4
- package/dist/vendor/codali/cognitive/ConfiguredPipeline.d.ts +34 -0
- package/dist/vendor/codali/cognitive/ConfiguredPipeline.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ConfiguredPipeline.js +50 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.d.ts +4 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.d.ts.map +1 -1
- package/dist/vendor/codali/cognitive/ValidationRunner.js +18 -41
- package/dist/vendor/codali/config/NodeOrchestration.d.ts +21 -0
- package/dist/vendor/codali/config/NodeOrchestration.d.ts.map +1 -0
- package/dist/vendor/codali/config/NodeOrchestration.js +54 -0
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts +100 -0
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts.map +1 -0
- package/dist/vendor/codali/config/OrchestrationConfig.js +245 -0
- package/dist/vendor/codali/connectors/mcp/McpClient.d.ts +3 -1
- package/dist/vendor/codali/connectors/mcp/McpClient.d.ts.map +1 -1
- package/dist/vendor/codali/connectors/mcp/McpClient.js +3 -2
- package/dist/vendor/codali/connectors/mcp/McpServerRegistry.d.ts +2 -2
- package/dist/vendor/codali/connectors/mcp/McpServerRegistry.d.ts.map +1 -1
- package/dist/vendor/codali/connectors/mcp/McpServerRegistry.js +39 -16
- package/dist/vendor/codali/connectors/mcp/McpToolAdapter.js +2 -2
- package/dist/vendor/codali/connectors/media/ConfiguredMediaTools.d.ts +6 -0
- package/dist/vendor/codali/connectors/media/ConfiguredMediaTools.d.ts.map +1 -0
- package/dist/vendor/codali/connectors/media/ConfiguredMediaTools.js +41 -0
- package/dist/vendor/codali/connectors/media/ImageGenerationTool.js +3 -3
- package/dist/vendor/codali/connectors/media/MediaArtifactReceipt.d.ts +5 -0
- package/dist/vendor/codali/connectors/media/MediaArtifactReceipt.d.ts.map +1 -0
- package/dist/vendor/codali/connectors/media/MediaArtifactReceipt.js +65 -0
- package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts +68 -0
- package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts.map +1 -0
- package/dist/vendor/codali/connectors/media/MediaJobStore.js +199 -0
- package/dist/vendor/codali/connectors/media/MediaJobWorker.d.ts +2 -0
- package/dist/vendor/codali/connectors/media/MediaJobWorker.d.ts.map +1 -0
- package/dist/vendor/codali/connectors/media/MediaJobWorker.js +65 -0
- package/dist/vendor/codali/connectors/media/RemoteMediaJob.d.ts +6 -0
- package/dist/vendor/codali/connectors/media/RemoteMediaJob.d.ts.map +1 -0
- package/dist/vendor/codali/connectors/media/RemoteMediaJob.js +80 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts +18 -1
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/vendor/codali/docdex/DocdexClient.js +135 -19
- package/dist/vendor/codali/docdex/ManagedDocdex.d.ts +29 -0
- package/dist/vendor/codali/docdex/ManagedDocdex.d.ts.map +1 -0
- package/dist/vendor/codali/docdex/ManagedDocdex.js +215 -0
- package/dist/vendor/codali/docdex/ManagedRuntime.d.ts +28 -0
- package/dist/vendor/codali/docdex/ManagedRuntime.d.ts.map +1 -0
- package/dist/vendor/codali/docdex/ManagedRuntime.js +212 -0
- package/dist/vendor/codali/eval/EvaluationProcess.d.ts +13 -0
- package/dist/vendor/codali/eval/EvaluationProcess.d.ts.map +1 -0
- package/dist/vendor/codali/eval/EvaluationProcess.js +76 -0
- package/dist/vendor/codali/eval/LongWorkflowJourney.d.ts +34 -0
- package/dist/vendor/codali/eval/LongWorkflowJourney.d.ts.map +1 -0
- package/dist/vendor/codali/eval/LongWorkflowJourney.js +243 -0
- package/dist/vendor/codali/eval/PlanningCorpus.d.ts +45 -0
- package/dist/vendor/codali/eval/PlanningCorpus.d.ts.map +1 -0
- package/dist/vendor/codali/eval/PlanningCorpus.js +189 -0
- package/dist/vendor/codali/eval/PlanningCorpusRunner.d.ts +13 -0
- package/dist/vendor/codali/eval/PlanningCorpusRunner.d.ts.map +1 -0
- package/dist/vendor/codali/eval/PlanningCorpusRunner.js +89 -0
- package/dist/vendor/codali/eval/TerminalCorpusRunner.d.ts +36 -0
- package/dist/vendor/codali/eval/TerminalCorpusRunner.d.ts.map +1 -0
- package/dist/vendor/codali/eval/TerminalCorpusRunner.js +222 -0
- package/dist/vendor/codali/eval/TerminalTaskCorpus.d.ts +26 -0
- package/dist/vendor/codali/eval/TerminalTaskCorpus.d.ts.map +1 -0
- package/dist/vendor/codali/eval/TerminalTaskCorpus.js +105 -0
- package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts +11 -0
- package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts.map +1 -0
- package/dist/vendor/codali/eval/TerminalWorkflowCorpus.js +119 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts +4 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts.map +1 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.js +10 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts +6 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts.map +1 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.js +145 -0
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.d.ts +4 -0
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.d.ts.map +1 -0
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.js +136 -0
- package/dist/vendor/codali/gateway/CodaliGateway.d.ts +2 -0
- package/dist/vendor/codali/gateway/CodaliGateway.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/CodaliGateway.js +16 -4
- package/dist/vendor/codali/gateway/ConfiguredGateway.d.ts +23 -0
- package/dist/vendor/codali/gateway/ConfiguredGateway.d.ts.map +1 -0
- package/dist/vendor/codali/gateway/ConfiguredGateway.js +44 -0
- package/dist/vendor/codali/gateway/GatewayTracer.d.ts +1 -1
- package/dist/vendor/codali/gateway/GatewayTracer.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/GatewayTracer.js +2 -27
- package/dist/vendor/codali/gateway/LocalGatewayTaskRunner.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/LocalGatewayTaskRunner.js +13 -1
- package/dist/vendor/codali/index.d.ts +24 -0
- package/dist/vendor/codali/index.d.ts.map +1 -1
- package/dist/vendor/codali/index.js +13 -0
- package/dist/vendor/codali/permissions/PermissionGate.d.ts +44 -0
- package/dist/vendor/codali/permissions/PermissionGate.d.ts.map +1 -0
- package/dist/vendor/codali/permissions/PermissionGate.js +97 -0
- package/dist/vendor/codali/providers/ConfiguredEmbeddings.d.ts +43 -0
- package/dist/vendor/codali/providers/ConfiguredEmbeddings.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ConfiguredEmbeddings.js +87 -0
- package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts +70 -0
- package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ConfiguredModelScope.js +117 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts +84 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.js +271 -0
- package/dist/vendor/codali/providers/ModelServiceError.d.ts +14 -0
- package/dist/vendor/codali/providers/ModelServiceError.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ModelServiceError.js +67 -0
- package/dist/vendor/codali/providers/MswarmWorkerProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/MswarmWorkerProvider.js +4 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +140 -52
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +16 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/vendor/codali/providers/RequestUsage.d.ts +11 -0
- package/dist/vendor/codali/providers/RequestUsage.d.ts.map +1 -0
- package/dist/vendor/codali/providers/RequestUsage.js +33 -0
- package/dist/vendor/codali/runtime/CodaliJobRuntime.d.ts +6 -0
- package/dist/vendor/codali/runtime/CodaliJobRuntime.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CodaliJobRuntime.js +36 -1
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +31 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CodaliRuntime.js +72 -1
- package/dist/vendor/codali/runtime/CompletionReport.d.ts +5 -0
- package/dist/vendor/codali/runtime/CompletionReport.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/CompletionReport.js +12 -0
- package/dist/vendor/codali/runtime/ProgressTracker.d.ts +17 -0
- package/dist/vendor/codali/runtime/ProgressTracker.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ProgressTracker.js +27 -0
- package/dist/vendor/codali/runtime/RequestedTestEvidence.d.ts +12 -0
- package/dist/vendor/codali/runtime/RequestedTestEvidence.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RequestedTestEvidence.js +16 -0
- package/dist/vendor/codali/runtime/RequiredRetrieval.d.ts +13 -0
- package/dist/vendor/codali/runtime/RequiredRetrieval.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RequiredRetrieval.js +25 -0
- package/dist/vendor/codali/runtime/ReviewContract.d.ts +35 -0
- package/dist/vendor/codali/runtime/ReviewContract.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ReviewContract.js +131 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts +41 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.js +81 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts +9 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ReviewSource.js +54 -0
- package/dist/vendor/codali/runtime/Runner.d.ts +13 -0
- package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/Runner.js +225 -158
- package/dist/vendor/codali/runtime/SecretRedaction.d.ts +11 -0
- package/dist/vendor/codali/runtime/SecretRedaction.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/SecretRedaction.js +85 -0
- package/dist/vendor/codali/runtime/SessionController.d.ts +150 -0
- package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/SessionController.js +1487 -0
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts +22 -0
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/StructuralEvidence.js +87 -0
- package/dist/vendor/codali/runtime/TaskReview.d.ts +25 -0
- package/dist/vendor/codali/runtime/TaskReview.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/TaskReview.js +84 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.d.ts +71 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.js +50 -0
- package/dist/vendor/codali/runtime/UsageReconciliation.d.ts +28 -0
- package/dist/vendor/codali/runtime/UsageReconciliation.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/UsageReconciliation.js +68 -0
- package/dist/vendor/codali/runtime/ValidationOutput.d.ts +5 -0
- package/dist/vendor/codali/runtime/ValidationOutput.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ValidationOutput.js +32 -0
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts +5 -0
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/VerificationCommand.js +76 -0
- package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts +15 -0
- package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/VerificationReceiptSelection.js +30 -0
- package/dist/vendor/codali/runtime/WorkStatusPage.d.ts +15 -0
- package/dist/vendor/codali/runtime/WorkStatusPage.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkStatusPage.js +58 -0
- package/dist/vendor/codali/runtime/WorkspaceLedger.d.ts +13 -0
- package/dist/vendor/codali/runtime/WorkspaceLedger.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkspaceLedger.js +145 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/WorkspaceLock.js +20 -17
- package/dist/vendor/codali/runtime/WorkspaceSnapshot.d.ts +13 -0
- package/dist/vendor/codali/runtime/WorkspaceSnapshot.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkspaceSnapshot.js +88 -0
- package/dist/vendor/codali/session/AtomicState.d.ts +13 -0
- package/dist/vendor/codali/session/AtomicState.d.ts.map +1 -0
- package/dist/vendor/codali/session/AtomicState.js +123 -0
- package/dist/vendor/codali/session/SessionStoragePath.d.ts +15 -0
- package/dist/vendor/codali/session/SessionStoragePath.d.ts.map +1 -0
- package/dist/vendor/codali/session/SessionStoragePath.js +101 -0
- package/dist/vendor/codali/session/SessionStore.d.ts +9 -0
- package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -1
- package/dist/vendor/codali/session/SessionStore.js +181 -47
- package/dist/vendor/codali/session/WorkState.d.ts +32 -0
- package/dist/vendor/codali/session/WorkState.d.ts.map +1 -0
- package/dist/vendor/codali/session/WorkState.js +399 -0
- package/dist/vendor/codali/session/WorkTypes.d.ts +102 -0
- package/dist/vendor/codali/session/WorkTypes.d.ts.map +1 -0
- package/dist/vendor/codali/session/WorkTypes.js +1 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts +2 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -1
- package/dist/vendor/codali/tools/ToolRegistry.js +12 -2
- package/dist/vendor/codali/tools/ToolTypes.d.ts +16 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -1
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +2 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -1
- package/dist/vendor/codali/tools/docdex/DocdexTools.js +17 -2
- package/dist/vendor/codali/tools/filesystem/FileTools.d.ts.map +1 -1
- package/dist/vendor/codali/tools/filesystem/FileTools.js +30 -10
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts +19 -0
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/AsyncProcess.js +94 -0
- package/dist/vendor/codali/tools/shell/DarwinRuntimeLibraries.d.ts +13 -0
- package/dist/vendor/codali/tools/shell/DarwinRuntimeLibraries.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/DarwinRuntimeLibraries.js +130 -0
- package/dist/vendor/codali/tools/shell/HostToolchain.d.ts +19 -0
- package/dist/vendor/codali/tools/shell/HostToolchain.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/HostToolchain.js +266 -0
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts +15 -0
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.js +138 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/ShellTool.js +9 -29
- package/dist/vendor/codali/tools/shell/ShellWorkingDirectory.d.ts +3 -0
- package/dist/vendor/codali/tools/shell/ShellWorkingDirectory.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/ShellWorkingDirectory.js +30 -0
- package/package.json +31 -29
- package/scripts/backend-http-drain.mjs +152 -0
- package/scripts/media_gpu_lock.py +238 -0
- package/scripts/native_load_guard.py +257 -0
- package/scripts/stable-audio-3-openai-server.py +45 -14
- package/scripts/stable-diffusion-cpp-openai-server.py +34 -4
- package/scripts/stable-diffusion-cpp-webm-duration.patch +22 -0
- package/scripts/wan22-openai-server.py +97 -18
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { accessSync, closeSync, constants, existsSync, openSync, readFileSync, readdirSync, readSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { discoverDarwinRuntimeLibraries } from "./DarwinRuntimeLibraries.js";
|
|
7
|
+
const packages = { npm: ["npm"], pnpm: ["pnpm", "@pnpm/exe"], yarn: ["yarn", "@yarnpkg/cli", "@yarnpkg/cli-dist"] };
|
|
8
|
+
const within = (file, root) => file === root || file.startsWith(`${root}${path.sep}`);
|
|
9
|
+
const systemPath = (file) => ["/usr", "/bin", "/sbin", "/System"].some(root => within(file, root));
|
|
10
|
+
const executableBinary = (file) => {
|
|
11
|
+
const fd = openSync(file, "r");
|
|
12
|
+
const bytes = Buffer.alloc(4);
|
|
13
|
+
try {
|
|
14
|
+
if (readSync(fd, bytes, 0, 4, 0) !== 4)
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
closeSync(fd);
|
|
19
|
+
}
|
|
20
|
+
return ["7f454c46", "feedface", "feedfacf", "cefaedfe", "cffaedfe", "cafebabe", "bebafeca", "cafebabf", "bfbafeca"].includes(bytes.toString("hex"));
|
|
21
|
+
};
|
|
22
|
+
const rustTools = new Set(["cargo", "rustc", "rustdoc"]);
|
|
23
|
+
/** Resolve a rustup proxy without executing it or consulting repository overrides.
|
|
24
|
+
* Only an already-installed, host-selected toolchain can become a runtime mount. */
|
|
25
|
+
const resolveRustProxy = (name, executable, home) => {
|
|
26
|
+
if (!rustTools.has(name))
|
|
27
|
+
return executable;
|
|
28
|
+
let proxy = path.basename(executable) === "rustup";
|
|
29
|
+
if (!proxy && existsSync(path.join(path.dirname(executable), "rustup"))) {
|
|
30
|
+
const actual = statSync(executable);
|
|
31
|
+
const rustup = statSync(path.join(path.dirname(executable), "rustup"));
|
|
32
|
+
proxy = actual.dev === rustup.dev && actual.ino === rustup.ino;
|
|
33
|
+
// Some installers copy proxies instead of linking them. Compare all bytes;
|
|
34
|
+
// a filename or matching binary header alone does not identify rustup.
|
|
35
|
+
if (!proxy && actual.size === rustup.size && actual.size <= 64 * 1024 * 1024) {
|
|
36
|
+
const digest = (file) => createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
37
|
+
proxy = digest(executable) === digest(path.join(path.dirname(executable), "rustup"));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!proxy && statSync(executable).size <= 16384 && !executableBinary(executable)) {
|
|
41
|
+
// Package managers may wrap rustup in a small shell script. Do not execute
|
|
42
|
+
// it: identify the adjacent native libexec proxies, then select host state.
|
|
43
|
+
const packageRoot = path.dirname(path.dirname(executable));
|
|
44
|
+
const nativeProxy = path.join(packageRoot, "libexec", "bin", name);
|
|
45
|
+
const nativeRustup = path.join(packageRoot, "libexec", "bin", "rustup");
|
|
46
|
+
if (existsSync(nativeProxy) && existsSync(nativeRustup)
|
|
47
|
+
&& within(realpathSync.native(nativeProxy), packageRoot) && within(realpathSync.native(nativeRustup), packageRoot)
|
|
48
|
+
&& executableBinary(nativeRustup)) {
|
|
49
|
+
const target = statSync(nativeProxy);
|
|
50
|
+
const manager = statSync(nativeRustup);
|
|
51
|
+
proxy = target.dev === manager.dev && target.ino === manager.ino;
|
|
52
|
+
if (!proxy && target.size === manager.size && target.size <= 64 * 1024 * 1024) {
|
|
53
|
+
const digest = (file) => createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
54
|
+
proxy = digest(nativeProxy) === digest(nativeRustup);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!proxy)
|
|
59
|
+
return executable;
|
|
60
|
+
const rustup = process.env.RUSTUP_HOME ?? path.join(home, ".rustup");
|
|
61
|
+
if (!path.isAbsolute(rustup))
|
|
62
|
+
throw new Error("Rustup home must be absolute");
|
|
63
|
+
const settings = path.join(rustup, "settings.toml");
|
|
64
|
+
const configured = process.env.RUSTUP_TOOLCHAIN || (statSync(settings).size <= 16384
|
|
65
|
+
? readFileSync(settings, "utf8").match(/^default_toolchain\s*=\s*"([A-Za-z0-9_.-]+)"\s*$/m)?.[1] : undefined);
|
|
66
|
+
if (!configured || !/^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(configured))
|
|
67
|
+
throw new Error("No installed host Rust toolchain selected");
|
|
68
|
+
const toolchains = path.join(rustup, "toolchains");
|
|
69
|
+
const matches = existsSync(path.join(toolchains, configured)) ? [configured]
|
|
70
|
+
: readdirSync(toolchains).filter(entry => entry.startsWith(`${configured}-`));
|
|
71
|
+
if (matches.length !== 1)
|
|
72
|
+
throw new Error("Rust toolchain selection is unavailable or ambiguous");
|
|
73
|
+
const root = realpathSync.native(path.join(toolchains, matches[0]));
|
|
74
|
+
const target = realpathSync.native(path.join(root, "bin", name));
|
|
75
|
+
if (!within(target, root))
|
|
76
|
+
throw new Error("Rust tool executable escapes selected toolchain");
|
|
77
|
+
return target;
|
|
78
|
+
};
|
|
79
|
+
const languageRuntime = (name, executable, workspace, home) => {
|
|
80
|
+
if (!executableBinary(executable) || path.basename(path.dirname(executable)) !== "bin")
|
|
81
|
+
return undefined;
|
|
82
|
+
const prefix = path.dirname(path.dirname(executable));
|
|
83
|
+
if (prefix === home || within(workspace, prefix) || within(prefix, workspace) || prefix === path.parse(prefix).root)
|
|
84
|
+
return undefined;
|
|
85
|
+
const runtime = { name, executable, readOnlyRoot: executable, directory: false, support: [] };
|
|
86
|
+
const add = (file) => {
|
|
87
|
+
const resolved = realpathSync.native(file);
|
|
88
|
+
if (!within(resolved, prefix))
|
|
89
|
+
throw new Error("Runtime support path escapes installation");
|
|
90
|
+
runtime.support.push({ readOnlyRoot: resolved, directory: statSync(resolved).isDirectory() });
|
|
91
|
+
};
|
|
92
|
+
if (rustTools.has(name)) {
|
|
93
|
+
const library = path.join(prefix, "lib");
|
|
94
|
+
if (!readdirSync(path.join(library, "rustlib")).some(file => /^manifest-rustc(?:-|$)/.test(file)))
|
|
95
|
+
return undefined;
|
|
96
|
+
add(library);
|
|
97
|
+
return runtime;
|
|
98
|
+
}
|
|
99
|
+
if (name === "python" || name === "python3") {
|
|
100
|
+
let standardLibrary = false;
|
|
101
|
+
const extensions = [];
|
|
102
|
+
for (const lib of ["lib", "lib64"]) {
|
|
103
|
+
const directory = path.join(prefix, lib);
|
|
104
|
+
if (!existsSync(directory))
|
|
105
|
+
continue;
|
|
106
|
+
for (const entry of readdirSync(directory)) {
|
|
107
|
+
const file = path.join(directory, entry);
|
|
108
|
+
if (/^python3\.\d+t?$/.test(entry) && existsSync(path.join(file, "os.py")) && existsSync(path.join(file, "encodings", "__init__.py"))) {
|
|
109
|
+
add(file);
|
|
110
|
+
standardLibrary = true;
|
|
111
|
+
const dynamic = path.join(file, "lib-dynload");
|
|
112
|
+
if (process.platform === "darwin" && existsSync(dynamic)) {
|
|
113
|
+
for (const entry of readdirSync(dynamic).filter(entry => /\.(?:so|dylib)$/.test(entry))) {
|
|
114
|
+
const extension = realpathSync.native(path.join(dynamic, entry));
|
|
115
|
+
if (!within(extension, prefix))
|
|
116
|
+
throw new Error("Python extension escapes installation");
|
|
117
|
+
extensions.push(extension);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (/^libpython3\.\d+t?(?:\.so(?:\.[\d.]+)?|(?:\.\d+)*\.dylib)$/.test(entry))
|
|
122
|
+
add(file);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (standardLibrary && process.platform === "darwin")
|
|
126
|
+
runtime.support.push(...discoverDarwinRuntimeLibraries(executable, extensions, workspace, home));
|
|
127
|
+
return standardLibrary ? runtime : undefined;
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
};
|
|
131
|
+
/** xcrun only locates installed host tools here; it never compiles repository code.
|
|
132
|
+
* Mount the selected developer installation, not /Applications or a user's home. */
|
|
133
|
+
const darwinDeveloperTools = (workspace, home) => {
|
|
134
|
+
if (process.platform !== "darwin")
|
|
135
|
+
return [];
|
|
136
|
+
try {
|
|
137
|
+
const environment = { PATH: "/usr/bin:/bin", ...(process.env.DEVELOPER_DIR ? { DEVELOPER_DIR: process.env.DEVELOPER_DIR } : {}) };
|
|
138
|
+
const query = (command, args) => {
|
|
139
|
+
const result = spawnSync(command, args, { env: environment, cwd: os.tmpdir(), timeout: 3000, encoding: "utf8", maxBuffer: 16384 });
|
|
140
|
+
if (result.status !== 0)
|
|
141
|
+
throw new Error("Developer tool lookup failed");
|
|
142
|
+
return realpathSync.native(result.stdout.trim());
|
|
143
|
+
};
|
|
144
|
+
const developer = realpathSync.native(process.env.DEVELOPER_DIR ?? query("/usr/bin/xcode-select", ["--print-path"]));
|
|
145
|
+
if (developer === home || developer === path.parse(developer).root || within(workspace, developer) || within(developer, workspace))
|
|
146
|
+
return [];
|
|
147
|
+
const sdk = query("/usr/bin/xcrun", ["--sdk", "macosx", "--show-sdk-path"]);
|
|
148
|
+
if (!within(sdk, developer) || !existsSync(path.join(sdk, "SDKSettings.plist")))
|
|
149
|
+
return [];
|
|
150
|
+
// /usr/bin/git is an Apple launcher that may invoke xcodebuild and inspect
|
|
151
|
+
// files outside Developer. Select native Git within the same trusted root.
|
|
152
|
+
return ["cc", "ar", "git"].map(name => {
|
|
153
|
+
const executable = query("/usr/bin/xcrun", ["--find", name === "cc" ? "clang" : name]);
|
|
154
|
+
if (!within(executable, developer) || !executableBinary(executable))
|
|
155
|
+
throw new Error("Developer tool escapes selected installation");
|
|
156
|
+
return { name, executable, readOnlyRoot: developer, directory: true, environment: { SDKROOT: sdk, DEVELOPER_DIR: developer } };
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
/** Discover known user-installed language tools. The workspace can neither
|
|
164
|
+
* supply this PATH nor turn its own package.json into a trusted runtime mount.
|
|
165
|
+
* Mounts are single binaries or matching package roots, never the user's home. */
|
|
166
|
+
export const discoverHostToolchain = (workspaceRoot, searchPath = process.env.PATH ?? "") => {
|
|
167
|
+
const workspace = realpathSync.native(workspaceRoot);
|
|
168
|
+
const home = realpathSync.native(os.homedir());
|
|
169
|
+
const result = darwinDeveloperTools(workspace, home);
|
|
170
|
+
for (const name of ["node", "npm", "pnpm", "yarn", "bun", "python3", "python", "rustc", "cargo", "rustdoc", "cc", "ar"]) {
|
|
171
|
+
if (result.some(runtime => runtime.name === name))
|
|
172
|
+
continue;
|
|
173
|
+
const candidates = name === "node" ? [process.execPath] : searchPath.split(path.delimiter).filter(Boolean).map(directory => path.resolve(directory, name));
|
|
174
|
+
for (const candidate of candidates) {
|
|
175
|
+
try {
|
|
176
|
+
let executable = realpathSync.native(candidate);
|
|
177
|
+
if (within(candidate, workspace) || within(executable, workspace))
|
|
178
|
+
continue;
|
|
179
|
+
executable = resolveRustProxy(name, executable, home);
|
|
180
|
+
if (within(executable, workspace))
|
|
181
|
+
continue;
|
|
182
|
+
accessSync(executable, constants.X_OK);
|
|
183
|
+
if (!statSync(executable).isFile())
|
|
184
|
+
continue;
|
|
185
|
+
if (systemPath(executable)) {
|
|
186
|
+
result.push({ name, executable, readOnlyRoot: executable, directory: false });
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
if (rustTools.has(name) || name === "python" || name === "python3") {
|
|
190
|
+
const runtime = languageRuntime(name, executable, workspace, home);
|
|
191
|
+
if (runtime) {
|
|
192
|
+
result.push(runtime);
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (executableBinary(executable)) {
|
|
198
|
+
result.push({ name, executable, readOnlyRoot: executable, directory: false });
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
// Package managers also install .bin shell shims. Never execute the shim:
|
|
202
|
+
// select the known adjacent package's declared JS entry point, which is
|
|
203
|
+
// validated by the same package-root checks as a normal symlink below.
|
|
204
|
+
if (packages[name] && path.basename(path.dirname(candidate)) === ".bin" && !/\.[cm]?js$/.test(executable)) {
|
|
205
|
+
for (const packageName of packages[name]) {
|
|
206
|
+
try {
|
|
207
|
+
const packageRoot = realpathSync.native(path.resolve(path.dirname(candidate), "..", packageName));
|
|
208
|
+
if (within(packageRoot, workspace) || within(workspace, packageRoot) || packageRoot === home)
|
|
209
|
+
continue;
|
|
210
|
+
const manifest = path.join(packageRoot, "package.json");
|
|
211
|
+
if (statSync(manifest).size > 65536)
|
|
212
|
+
continue;
|
|
213
|
+
const metadata = JSON.parse(readFileSync(manifest, "utf8"));
|
|
214
|
+
const bin = typeof metadata.bin === "string" ? metadata.bin : metadata.bin?.[name];
|
|
215
|
+
if (metadata.name !== packageName || !bin)
|
|
216
|
+
continue;
|
|
217
|
+
const target = realpathSync.native(path.resolve(packageRoot, bin));
|
|
218
|
+
if (!within(target, packageRoot) || !/\.[cm]?js$/.test(target) || !statSync(target).isFile())
|
|
219
|
+
continue;
|
|
220
|
+
accessSync(target, constants.X_OK);
|
|
221
|
+
executable = target;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
catch { /* Another allowed package layout may exist. */ }
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (!packages[name] || !/\.[cm]?js$/.test(executable))
|
|
228
|
+
continue;
|
|
229
|
+
let directory = path.dirname(executable);
|
|
230
|
+
let matched;
|
|
231
|
+
for (let depth = 0; depth < 6 && directory !== path.parse(directory).root && directory !== home; depth++, directory = path.dirname(directory)) {
|
|
232
|
+
if (within(workspace, directory) || within(directory, workspace))
|
|
233
|
+
break;
|
|
234
|
+
const manifest = path.join(directory, "package.json");
|
|
235
|
+
if (!existsSync(manifest))
|
|
236
|
+
continue;
|
|
237
|
+
if (statSync(manifest).size > 65536)
|
|
238
|
+
break;
|
|
239
|
+
const metadata = JSON.parse(readFileSync(manifest, "utf8"));
|
|
240
|
+
if (!metadata.name || !packages[name].includes(metadata.name))
|
|
241
|
+
break;
|
|
242
|
+
const bin = typeof metadata.bin === "string" ? metadata.bin : metadata.bin?.[name];
|
|
243
|
+
if (!bin || realpathSync.native(path.resolve(directory, bin)) !== executable)
|
|
244
|
+
break;
|
|
245
|
+
matched = { name, executable, readOnlyRoot: directory, directory: true };
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
if (matched) {
|
|
249
|
+
result.push(matched);
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch { /* An unavailable or unverified candidate is not mounted. */ }
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
};
|
|
258
|
+
export const extraRuntimeMounts = (runtimes) => {
|
|
259
|
+
const mounts = new Map();
|
|
260
|
+
for (const runtime of runtimes)
|
|
261
|
+
for (const mount of [runtime, ...runtime.support ?? []]) {
|
|
262
|
+
if (!systemPath(mount.readOnlyRoot))
|
|
263
|
+
mounts.set(mount.readOnlyRoot, mount);
|
|
264
|
+
}
|
|
265
|
+
return [...mounts.values()];
|
|
266
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ToolContext, type ToolHandlerResult } from "../ToolTypes.js";
|
|
2
|
+
import { type HostRuntime } from "./HostToolchain.js";
|
|
3
|
+
export interface ExecutorStatus {
|
|
4
|
+
available: boolean;
|
|
5
|
+
backend: "bubblewrap" | "sandbox-exec" | "unavailable";
|
|
6
|
+
reason?: string;
|
|
7
|
+
}
|
|
8
|
+
/** All paths have been canonicalized by the host, before launching the sandbox. */
|
|
9
|
+
export declare const darwinSandboxProfile: (root: string, scratch: string, writePaths: string[], runtimes: HostRuntime[], network?: boolean) => string;
|
|
10
|
+
export declare const executorStatus: () => ExecutorStatus;
|
|
11
|
+
export declare const createIsolatedExecutor: (options?: {
|
|
12
|
+
network?: boolean;
|
|
13
|
+
status?: ExecutorStatus;
|
|
14
|
+
}) => ((command: string, args: string[], context: ToolContext) => Promise<ToolHandlerResult>);
|
|
15
|
+
//# sourceMappingURL=IsolatedExecutor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsolatedExecutor.d.ts","sourceRoot":"","sources":["../../../src/tools/shell/IsolatedExecutor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EAA6C,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjG,MAAM,WAAW,cAAc;IAAG,SAAS,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,YAAY,GAAG,cAAc,GAAG,aAAa,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAAE;AAEhI,mFAAmF;AACnF,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,EAAE,YAAY,MAAM,EAAE,EAAE,UAAU,WAAW,EAAE,EAAE,iBAAe,KAAG,MA2BpI,CAAC;AAQF,eAAO,MAAM,cAAc,QAAO,cAcjC,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,UAAS;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,cAAc,CAAA;CAAO,KAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAoD3L,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { existsSync, realpathSync, mkdtempSync, rmSync, promises as fs } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { runProcess } from "./AsyncProcess.js";
|
|
6
|
+
import { resolveShellWorkingDirectory } from "./ShellWorkingDirectory.js";
|
|
7
|
+
import { ToolExecutionError } from "../ToolTypes.js";
|
|
8
|
+
import { discoverHostToolchain, extraRuntimeMounts } from "./HostToolchain.js";
|
|
9
|
+
/** All paths have been canonicalized by the host, before launching the sandbox. */
|
|
10
|
+
export const darwinSandboxProfile = (root, scratch, writePaths, runtimes, network = false) => {
|
|
11
|
+
const quoted = (value) => JSON.stringify(value);
|
|
12
|
+
const ancestors = new Set();
|
|
13
|
+
for (const target of [root, scratch, ...extraRuntimeMounts(runtimes).map(runtime => runtime.readOnlyRoot)]) {
|
|
14
|
+
for (let parent = path.dirname(target); parent !== path.dirname(parent); parent = path.dirname(parent))
|
|
15
|
+
ancestors.add(parent);
|
|
16
|
+
}
|
|
17
|
+
return [
|
|
18
|
+
"(version 1)", "(deny default)", "(allow process*)", "(allow sysctl-read)",
|
|
19
|
+
// dyld opens the root directory when locating its shared cache. This literal
|
|
20
|
+
// permits the directory itself, never a recursive read of the filesystem.
|
|
21
|
+
'(allow file-read* (literal "/"))',
|
|
22
|
+
// realpath/lstat needs ancestor metadata, not directory contents or sibling files.
|
|
23
|
+
...[...ancestors].map(parent => `(allow file-read-metadata (literal ${quoted(parent)}))`),
|
|
24
|
+
'(allow file-read* (subpath "/usr") (subpath "/bin") (subpath "/sbin") (subpath "/System") (subpath "/Library") (subpath "/private/etc") (subpath "/dev"))',
|
|
25
|
+
// Git and other native tools open the null device read/write for discarded IO.
|
|
26
|
+
'(allow file-write-data (literal "/dev/null"))',
|
|
27
|
+
// Apple's /bin/sh reads this system selector before starting npm scripts.
|
|
28
|
+
// Permit only that selector, not other private /var files or directories.
|
|
29
|
+
'(allow file-read* (literal "/private/var/select/sh") (literal "/var/select/sh"))',
|
|
30
|
+
'(allow file-read-metadata (literal "/private/var/select") (literal "/var/select"))',
|
|
31
|
+
`(allow file-read* (subpath ${quoted(root)}))`,
|
|
32
|
+
...extraRuntimeMounts(runtimes).map(runtime => `(allow file-read* (${runtime.directory ? "subpath" : "literal"} ${quoted(runtime.readOnlyRoot)}))`),
|
|
33
|
+
`(allow file-read* file-write* (subpath ${quoted(scratch)}))`,
|
|
34
|
+
...writePaths.map(file => `(allow file-write* (subpath ${quoted(file)}))`),
|
|
35
|
+
...[".git", ".mcoda"].map(dir => `(deny file-write* (subpath ${quoted(path.join(root, dir))}))`),
|
|
36
|
+
network ? "(allow network*)" : "(deny network*)",
|
|
37
|
+
].join("\n");
|
|
38
|
+
};
|
|
39
|
+
const bubblewrapRoot = () => {
|
|
40
|
+
const args = ["--die-with-parent", "--new-session", "--unshare-all", "--ro-bind", "/usr", "/usr", "--dev", "/dev", "--proc", "/proc", "--tmpfs", "/tmp"];
|
|
41
|
+
for (const dir of ["/bin", "/sbin", "/lib", "/lib64"])
|
|
42
|
+
if (existsSync(dir))
|
|
43
|
+
args.push("--ro-bind", realpathSync(dir), dir);
|
|
44
|
+
return args;
|
|
45
|
+
};
|
|
46
|
+
export const executorStatus = () => {
|
|
47
|
+
if (process.platform === "linux") {
|
|
48
|
+
if (!existsSync("/usr/bin/bwrap"))
|
|
49
|
+
return { available: false, backend: "unavailable", reason: "Install bubblewrap to enable isolated shell execution" };
|
|
50
|
+
const probe = spawnSync("/usr/bin/bwrap", [...bubblewrapRoot(), "--", "/usr/bin/true"], { timeout: 3000, stdio: "ignore" });
|
|
51
|
+
return probe.status === 0 ? { available: true, backend: "bubblewrap" } : { available: false, backend: "unavailable", reason: "bubblewrap user namespaces are unavailable" };
|
|
52
|
+
}
|
|
53
|
+
if (process.platform === "darwin" && existsSync("/usr/bin/sandbox-exec")) {
|
|
54
|
+
const scratch = realpathSync(mkdtempSync(path.join(os.tmpdir(), "codali-isolation-probe-")));
|
|
55
|
+
try {
|
|
56
|
+
const probe = spawnSync("/usr/bin/sandbox-exec", ["-p", darwinSandboxProfile(scratch, scratch, [], []), "/usr/bin/true"], { timeout: 3000, stdio: "ignore" });
|
|
57
|
+
if (probe.status === 0)
|
|
58
|
+
return { available: true, backend: "sandbox-exec" };
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { available: false, backend: "unavailable", reason: "No supported isolation backend on this platform" };
|
|
65
|
+
};
|
|
66
|
+
export const createIsolatedExecutor = (options = {}) => {
|
|
67
|
+
const status = options.status ?? executorStatus();
|
|
68
|
+
return async (command, args, context) => {
|
|
69
|
+
if (!status.available)
|
|
70
|
+
throw new ToolExecutionError("tool_permission_denied", status.reason ?? "Isolation unavailable");
|
|
71
|
+
const root = realpathSync(context.workspaceRoot);
|
|
72
|
+
const cwd = resolveShellWorkingDirectory(root, context.shellWorkingDirectory);
|
|
73
|
+
if (root === path.parse(root).root)
|
|
74
|
+
throw new ToolExecutionError("tool_permission_denied", "Filesystem root cannot be an isolated workspace");
|
|
75
|
+
const runtimes = discoverHostToolchain(root);
|
|
76
|
+
const writePaths = (context.allowedWritePaths ?? ["."]).map(file => {
|
|
77
|
+
const requested = path.resolve(root, file);
|
|
78
|
+
if (requested !== root && !requested.startsWith(`${root}${path.sep}`))
|
|
79
|
+
throw new ToolExecutionError("tool_permission_denied", "Shell write scope escapes workspace");
|
|
80
|
+
if (!existsSync(requested))
|
|
81
|
+
throw new ToolExecutionError("tool_permission_denied", "Create the scoped directory/file with write_file before shell execution");
|
|
82
|
+
const real = realpathSync(requested);
|
|
83
|
+
if (real !== root && !real.startsWith(`${root}${path.sep}`))
|
|
84
|
+
throw new ToolExecutionError("tool_permission_denied", "Shell write scope resolves outside workspace");
|
|
85
|
+
if ([".git", ".mcoda"].some(dir => real === path.join(root, dir) || real.startsWith(`${root}/${dir}/`)))
|
|
86
|
+
throw new ToolExecutionError("tool_permission_denied", "Repository control metadata cannot be a write scope");
|
|
87
|
+
return real;
|
|
88
|
+
});
|
|
89
|
+
if (status.backend === "bubblewrap") {
|
|
90
|
+
const launch = bubblewrapRoot();
|
|
91
|
+
if (options.network) {
|
|
92
|
+
launch.push("--share-net");
|
|
93
|
+
for (const file of ["/etc/resolv.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/ssl/certs"])
|
|
94
|
+
if (existsSync(file))
|
|
95
|
+
launch.push("--ro-bind", realpathSync(file), file);
|
|
96
|
+
}
|
|
97
|
+
launch.push("--dir", path.dirname(root), "--ro-bind", root, root);
|
|
98
|
+
for (const runtime of extraRuntimeMounts(runtimes))
|
|
99
|
+
launch.push("--dir", path.dirname(runtime.readOnlyRoot), "--ro-bind", runtime.readOnlyRoot, runtime.readOnlyRoot);
|
|
100
|
+
launch.push("--dir", "/tmp/codali-bin");
|
|
101
|
+
for (const runtime of runtimes)
|
|
102
|
+
launch.push("--symlink", runtime.executable, `/tmp/codali-bin/${runtime.name}`);
|
|
103
|
+
for (const file of writePaths)
|
|
104
|
+
launch.push("--bind", file, file);
|
|
105
|
+
launch.push("--chdir", cwd, "--dir", "/tmp/home", "--setenv", "HOME", "/tmp/home", "--setenv", "TMPDIR", "/tmp", "--setenv", "PATH", "/tmp/codali-bin:/usr/local/bin:/usr/bin:/bin");
|
|
106
|
+
for (const [key, value] of Object.entries({ CARGO_HOME: "/tmp/home/cargo", XDG_CACHE_HOME: "/tmp/home/cache", PYTHONPYCACHEPREFIX: "/tmp/home/pycache", PYTHONUSERBASE: "/tmp/home/python", GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null", GIT_ATTR_NOSYSTEM: "1" }))
|
|
107
|
+
launch.push("--setenv", key, value);
|
|
108
|
+
// Git hooks/config and private session state are not part of executable workspace access.
|
|
109
|
+
for (const dir of [".git", ".mcoda"])
|
|
110
|
+
if (existsSync(path.join(root, dir)))
|
|
111
|
+
launch.push("--ro-bind", path.join(root, dir), path.join(root, dir));
|
|
112
|
+
launch.push("--", command, ...args);
|
|
113
|
+
return runProcess("/usr/bin/bwrap", launch, context);
|
|
114
|
+
}
|
|
115
|
+
const scratch = realpathSync(await fs.mkdtemp(path.join(os.tmpdir(), "codali-shell-")));
|
|
116
|
+
try {
|
|
117
|
+
await fs.chmod(scratch, 0o700);
|
|
118
|
+
const privateHome = path.join(scratch, "home");
|
|
119
|
+
const privateBin = path.join(scratch, "bin");
|
|
120
|
+
await fs.mkdir(privateHome, { mode: 0o700 });
|
|
121
|
+
await fs.mkdir(privateBin, { mode: 0o700 });
|
|
122
|
+
for (const runtime of runtimes)
|
|
123
|
+
await fs.symlink(runtime.executable, path.join(privateBin, runtime.name));
|
|
124
|
+
const profile = darwinSandboxProfile(root, scratch, writePaths, runtimes, options.network);
|
|
125
|
+
return await runProcess("/usr/bin/sandbox-exec", ["-p", profile, runtimes.find(runtime => runtime.name === command)?.executable ?? command, ...args], context, {
|
|
126
|
+
...runtimes.find(runtime => runtime.name === "cc")?.environment,
|
|
127
|
+
HOME: privateHome, TMPDIR: scratch, PATH: `${privateBin}:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin`,
|
|
128
|
+
CARGO_HOME: path.join(privateHome, "cargo"), XDG_CACHE_HOME: path.join(privateHome, "cache"),
|
|
129
|
+
PYTHONPYCACHEPREFIX: path.join(privateHome, "pycache"), PYTHONUSERBASE: path.join(privateHome, "python"),
|
|
130
|
+
// Host Git settings can invoke external helpers or read private paths.
|
|
131
|
+
GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null", GIT_ATTR_NOSYSTEM: "1",
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
await fs.rm(scratch, { recursive: true, force: true });
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShellTool.d.ts","sourceRoot":"","sources":["../../../src/tools/shell/ShellTool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ShellTool.d.ts","sourceRoot":"","sources":["../../../src/tools/shell/ShellTool.ts"],"names":[],"mappings":"AACA,OAAO,EAAwC,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA6C5F,eAAO,MAAM,eAAe,QAAO,cAmDjC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import { ToolExecutionError } from "../ToolTypes.js";
|
|
3
|
+
import { runProcess } from "./AsyncProcess.js";
|
|
4
|
+
import { resolveShellWorkingDirectory } from "./ShellWorkingDirectory.js";
|
|
4
5
|
const resolveAllowlist = (context) => {
|
|
5
6
|
return context.shellAllowlist ?? [];
|
|
6
7
|
};
|
|
@@ -40,15 +41,17 @@ const isDestructiveShellAction = (command, args) => {
|
|
|
40
41
|
};
|
|
41
42
|
export const createShellTool = () => ({
|
|
42
43
|
name: "run_shell",
|
|
43
|
-
description:
|
|
44
|
+
description: 'Run an allowlisted executable. Default cwd is the workspace root; set cwd for a module-local command, e.g. {"command":"npm","args":["test"],"cwd":"packages/app"}. In terminal mode the workspace is read-only unless writePaths names root-relative paths inside the claimed task. Existing source files in those paths require current reads and structural analysis.',
|
|
44
45
|
readOnly: false,
|
|
45
46
|
capability: "shell",
|
|
46
47
|
inputSchema: {
|
|
47
48
|
type: "object",
|
|
48
49
|
required: ["command"],
|
|
49
50
|
properties: {
|
|
50
|
-
command: { type: "string" },
|
|
51
|
+
command: { type: "string", description: "One executable name, without arguments or shell syntax." },
|
|
51
52
|
args: { type: "array", items: { type: "string" } },
|
|
53
|
+
cwd: { type: "string", description: "Existing working directory inside the workspace, relative to its root. Default: workspace root. Does not change the base of writePaths." },
|
|
54
|
+
writePaths: { type: "array", items: { type: "string" }, description: "Terminal mode: root-relative existing files/directories to make writable, regardless of cwd. Default: no workspace writes. Must fit the claimed task scope." },
|
|
52
55
|
},
|
|
53
56
|
},
|
|
54
57
|
handler: async (args, context) => {
|
|
@@ -57,7 +60,7 @@ export const createShellTool = () => ({
|
|
|
57
60
|
retryable: false,
|
|
58
61
|
});
|
|
59
62
|
}
|
|
60
|
-
const { command, args: commandArgs = [] } = args;
|
|
63
|
+
const { command, args: commandArgs = [], cwd } = args;
|
|
61
64
|
if (!context.allowDestructiveOperations
|
|
62
65
|
&& isDestructiveShellAction(command, commandArgs)) {
|
|
63
66
|
throw new ToolExecutionError("tool_permission_denied", "Destructive operation blocked by policy", {
|
|
@@ -77,30 +80,7 @@ export const createShellTool = () => ({
|
|
|
77
80
|
details: { command },
|
|
78
81
|
});
|
|
79
82
|
}
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
encoding: "utf8",
|
|
83
|
-
});
|
|
84
|
-
if (result.error) {
|
|
85
|
-
throw result.error;
|
|
86
|
-
}
|
|
87
|
-
const stdout = result.stdout ?? "";
|
|
88
|
-
const stderr = result.stderr ?? "";
|
|
89
|
-
const exitCode = result.status ?? 0;
|
|
90
|
-
if (exitCode !== 0) {
|
|
91
|
-
const message = stderr || stdout || `Command failed with exit code ${exitCode}`;
|
|
92
|
-
throw new ToolExecutionError("tool_execution_failed", message, {
|
|
93
|
-
retryable: false,
|
|
94
|
-
details: { command, exitCode },
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
output: stdout || stderr,
|
|
99
|
-
data: {
|
|
100
|
-
stdout,
|
|
101
|
-
stderr,
|
|
102
|
-
exitCode,
|
|
103
|
-
},
|
|
104
|
-
};
|
|
83
|
+
const shellWorkingDirectory = resolveShellWorkingDirectory(context.workspaceRoot, cwd);
|
|
84
|
+
return (context.shellExecutor ?? runProcess)(command, commandArgs, { ...context, shellWorkingDirectory });
|
|
105
85
|
},
|
|
106
86
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShellWorkingDirectory.d.ts","sourceRoot":"","sources":["../../../src/tools/shell/ShellWorkingDirectory.ts"],"names":[],"mappings":"AAIA,gFAAgF;AAChF,eAAO,MAAM,4BAA4B,GAAI,eAAe,MAAM,EAAE,YAAY,MAAM,KAAG,MAoBxF,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { realpathSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ToolExecutionError } from "../ToolTypes.js";
|
|
4
|
+
/** Resolve only the process directory; write scopes still use workspaceRoot. */
|
|
5
|
+
export const resolveShellWorkingDirectory = (workspaceRoot, requested) => {
|
|
6
|
+
if (requested !== undefined && (typeof requested !== "string" || !requested.trim())) {
|
|
7
|
+
throw new ToolExecutionError("tool_invalid_args", "cwd must be a non-empty directory path inside the workspace");
|
|
8
|
+
}
|
|
9
|
+
const root = realpathSync.native(workspaceRoot);
|
|
10
|
+
const inside = (candidate) => {
|
|
11
|
+
const relative = path.relative(root, candidate);
|
|
12
|
+
return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
13
|
+
};
|
|
14
|
+
const candidate = path.resolve(root, requested ?? ".");
|
|
15
|
+
if (!inside(candidate))
|
|
16
|
+
throw new ToolExecutionError("tool_permission_denied", "Shell cwd escapes the workspace");
|
|
17
|
+
try {
|
|
18
|
+
const resolved = realpathSync.native(candidate);
|
|
19
|
+
if (!inside(resolved))
|
|
20
|
+
throw new ToolExecutionError("tool_permission_denied", "Shell cwd resolves outside the workspace");
|
|
21
|
+
if (!statSync(resolved).isDirectory())
|
|
22
|
+
throw new ToolExecutionError("tool_invalid_args", "Shell cwd must be an existing directory");
|
|
23
|
+
return resolved;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error instanceof ToolExecutionError)
|
|
27
|
+
throw error;
|
|
28
|
+
throw new ToolExecutionError("tool_invalid_args", "Shell cwd is not an accessible existing directory");
|
|
29
|
+
}
|
|
30
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"version": "0.1.133",
|
|
4
|
-
"description": "Owner-run mswarm node for exposing local mcoda agents through the mswarm self-hosted gateway.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/server.js",
|
|
7
|
-
"types": "dist/server.d.ts",
|
|
2
|
+
"author": "bekir dag",
|
|
8
3
|
"bin": {
|
|
9
|
-
"mswarm
|
|
10
|
-
"mswarm": "dist/server.js"
|
|
4
|
+
"mswarm": "dist/server.js",
|
|
5
|
+
"mswarm-self-hosted-node": "dist/server.js"
|
|
6
|
+
},
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/bekirdag/mcoda/issues"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@mcoda/db": "0.1.135-codali.10",
|
|
12
|
+
"@mcoda/shared": "0.1.135-codali.10",
|
|
13
|
+
"fastify": "^5.7.4",
|
|
14
|
+
"undici": "^6.28.0"
|
|
15
|
+
},
|
|
16
|
+
"description": "Owner-run mswarm node for exposing local mcoda agents through the mswarm self-hosted gateway.",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20"
|
|
11
19
|
},
|
|
12
20
|
"files": [
|
|
13
21
|
"dist",
|
|
@@ -16,23 +24,11 @@
|
|
|
16
24
|
"scripts",
|
|
17
25
|
"!scripts/**/__pycache__/**",
|
|
18
26
|
"!scripts/**/*.pyc",
|
|
27
|
+
"!scripts/**/*.test.mjs",
|
|
19
28
|
"README.md",
|
|
20
29
|
"LICENSE"
|
|
21
30
|
],
|
|
22
|
-
"engines": {
|
|
23
|
-
"node": ">=20"
|
|
24
|
-
},
|
|
25
|
-
"repository": {
|
|
26
|
-
"type": "git",
|
|
27
|
-
"url": "git+https://github.com/bekirdag/mcoda.git",
|
|
28
|
-
"directory": "packages/mswarm"
|
|
29
|
-
},
|
|
30
|
-
"bugs": {
|
|
31
|
-
"url": "https://github.com/bekirdag/mcoda/issues"
|
|
32
|
-
},
|
|
33
31
|
"homepage": "https://github.com/bekirdag/mcoda/tree/main/packages/mswarm#readme",
|
|
34
|
-
"license": "MIT",
|
|
35
|
-
"author": "bekir dag",
|
|
36
32
|
"keywords": [
|
|
37
33
|
"mcoda",
|
|
38
34
|
"mswarm",
|
|
@@ -42,18 +38,24 @@
|
|
|
42
38
|
"agents",
|
|
43
39
|
"ollama"
|
|
44
40
|
],
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"main": "dist/server.js",
|
|
43
|
+
"name": "@mcoda/mswarm",
|
|
45
44
|
"publishConfig": {
|
|
46
45
|
"access": "public"
|
|
47
46
|
},
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"@mcoda/shared": "0.1.133"
|
|
47
|
+
"repository": {
|
|
48
|
+
"directory": "packages/mswarm",
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/bekirdag/mcoda.git"
|
|
53
51
|
},
|
|
54
52
|
"scripts": {
|
|
55
53
|
"build": "pnpm --filter @mcoda/shared run build && pnpm --filter @mcoda/codali run build && tsc -p tsconfig.json && node ../../scripts/copy-mswarm-codali-vendor.js",
|
|
56
54
|
"lint": "echo \"lint not configured\"",
|
|
57
|
-
"test": "pnpm run build && node ../../scripts/run-node-tests.js dist"
|
|
58
|
-
|
|
59
|
-
}
|
|
55
|
+
"test": "pnpm run build && node ../../scripts/run-node-tests.js dist && pnpm run test:backend-drain",
|
|
56
|
+
"test:backend-drain": "node --experimental-websocket --test scripts/backend-http-drain.test.mjs"
|
|
57
|
+
},
|
|
58
|
+
"type": "module",
|
|
59
|
+
"types": "dist/server.d.ts",
|
|
60
|
+
"version": "0.1.135-codali.10"
|
|
61
|
+
}
|