@ellery/terminal-mcp 0.2.1 → 0.3.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 +301 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -61
- package/dist/client.js.map +1 -1
- package/dist/index.js +286 -14
- package/dist/index.js.map +1 -1
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +8 -0
- package/dist/prompts/index.js.map +1 -1
- package/dist/recording/index.d.ts +4 -0
- package/dist/recording/index.d.ts.map +1 -0
- package/dist/recording/index.js +3 -0
- package/dist/recording/index.js.map +1 -0
- package/dist/recording/manager.d.ts +62 -0
- package/dist/recording/manager.d.ts.map +1 -0
- package/dist/recording/manager.js +123 -0
- package/dist/recording/manager.js.map +1 -0
- package/dist/recording/recorder.d.ts +95 -0
- package/dist/recording/recorder.d.ts.map +1 -0
- package/dist/recording/recorder.js +296 -0
- package/dist/recording/recorder.js.map +1 -0
- package/dist/recording/types.d.ts +65 -0
- package/dist/recording/types.d.ts.map +1 -0
- package/dist/recording/types.js +2 -0
- package/dist/recording/types.js.map +1 -0
- package/dist/sandbox/config.d.ts +46 -0
- package/dist/sandbox/config.d.ts.map +1 -0
- package/dist/sandbox/config.js +144 -0
- package/dist/sandbox/config.js.map +1 -0
- package/dist/sandbox/controller.d.ts +72 -0
- package/dist/sandbox/controller.d.ts.map +1 -0
- package/dist/sandbox/controller.js +208 -0
- package/dist/sandbox/controller.js.map +1 -0
- package/dist/sandbox/index.d.ts +6 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +4 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/prompt.d.ts +10 -0
- package/dist/sandbox/prompt.d.ts.map +1 -0
- package/dist/sandbox/prompt.js +434 -0
- package/dist/sandbox/prompt.js.map +1 -0
- package/dist/server.d.ts +2 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +21 -0
- package/dist/server.js.map +1 -1
- package/dist/terminal/index.d.ts +1 -0
- package/dist/terminal/index.d.ts.map +1 -1
- package/dist/terminal/manager.d.ts +89 -31
- package/dist/terminal/manager.d.ts.map +1 -1
- package/dist/terminal/manager.js +313 -44
- package/dist/terminal/manager.js.map +1 -1
- package/dist/terminal/session.d.ts +34 -1
- package/dist/terminal/session.d.ts.map +1 -1
- package/dist/terminal/session.js +160 -3
- package/dist/terminal/session.js.map +1 -1
- package/dist/tools/createSession.d.ts +44 -0
- package/dist/tools/createSession.d.ts.map +1 -0
- package/dist/tools/createSession.js +41 -0
- package/dist/tools/createSession.js.map +1 -0
- package/dist/tools/definitions.d.ts +18 -0
- package/dist/tools/definitions.d.ts.map +1 -0
- package/dist/tools/definitions.js +116 -0
- package/dist/tools/definitions.js.map +1 -0
- package/dist/tools/destroySession.d.ts +31 -0
- package/dist/tools/destroySession.d.ts.map +1 -0
- package/dist/tools/destroySession.js +32 -0
- package/dist/tools/destroySession.js.map +1 -0
- package/dist/tools/getContent.d.ts +7 -0
- package/dist/tools/getContent.d.ts.map +1 -1
- package/dist/tools/getContent.js +8 -3
- package/dist/tools/getContent.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +26 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/listSessions.d.ts +19 -0
- package/dist/tools/listSessions.d.ts.map +1 -0
- package/dist/tools/listSessions.js +23 -0
- package/dist/tools/listSessions.js.map +1 -0
- package/dist/tools/screenshot.d.ts +26 -3
- package/dist/tools/screenshot.d.ts.map +1 -1
- package/dist/tools/screenshot.js +55 -5
- package/dist/tools/screenshot.js.map +1 -1
- package/dist/tools/sendKey.d.ts +7 -0
- package/dist/tools/sendKey.d.ts.map +1 -1
- package/dist/tools/sendKey.js +7 -2
- package/dist/tools/sendKey.js.map +1 -1
- package/dist/tools/startRecording.d.ts +68 -0
- package/dist/tools/startRecording.d.ts.map +1 -0
- package/dist/tools/startRecording.js +111 -0
- package/dist/tools/startRecording.js.map +1 -0
- package/dist/tools/stopRecording.d.ts +31 -0
- package/dist/tools/stopRecording.d.ts.map +1 -0
- package/dist/tools/stopRecording.js +76 -0
- package/dist/tools/stopRecording.js.map +1 -0
- package/dist/tools/type.d.ts +7 -0
- package/dist/tools/type.d.ts.map +1 -1
- package/dist/tools/type.js +7 -2
- package/dist/tools/type.js.map +1 -1
- package/dist/transport/socket.d.ts.map +1 -1
- package/dist/transport/socket.js +10 -0
- package/dist/transport/socket.js.map +1 -1
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +17 -1
- package/dist/ui/index.js.map +1 -1
- package/dist/utils/platform.d.ts +6 -0
- package/dist/utils/platform.d.ts.map +1 -1
- package/dist/utils/platform.js +15 -0
- package/dist/utils/platform.js.map +1 -1
- package/dist/utils/render.d.ts +21 -0
- package/dist/utils/render.d.ts.map +1 -0
- package/dist/utils/render.js +162 -0
- package/dist/utils/render.js.map +1 -0
- package/package.json +6 -2
- package/sandbox-permissions.png +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/sandbox/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAgC7B;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAuB;IACrD,UAAU,EAAE;QACV,SAAS,EAAE;YACT,aAAa;YACb,GAAG,EAAe,4BAA4B;YAC9C,MAAM,EAAY,aAAa;YAE/B,kBAAkB;YAClB,UAAU,EAAQ,gCAAgC;YAClD,UAAU,EAAQ,kBAAkB;YACpC,gBAAgB,EAAE,cAAc;YAChC,iBAAiB,EAAE,eAAe;YAClC,sBAAsB,EAAE,oBAAoB;YAC5C,mBAAmB,EAAE,iBAAiB;YAEtC,mBAAmB;YACnB,QAA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AAS,CAAC,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI;YAClD,cAAc,EAAE,SAAS,CAAC,OAAO,EAAE,cAAc,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc;SACjF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { SandboxPermissions } from "./config.js";
|
|
2
|
+
export type SandboxPlatform = "darwin" | "linux" | "win32" | "unsupported";
|
|
3
|
+
export interface SandboxStatus {
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
platform: SandboxPlatform;
|
|
6
|
+
reason?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Controller that wraps sandbox-runtime for terminal-mcp
|
|
10
|
+
* Manages sandbox lifecycle and command wrapping
|
|
11
|
+
*/
|
|
12
|
+
export declare class SandboxController {
|
|
13
|
+
private initialized;
|
|
14
|
+
private permissions;
|
|
15
|
+
private platform;
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Get the current platform
|
|
19
|
+
*/
|
|
20
|
+
getPlatform(): SandboxPlatform;
|
|
21
|
+
/**
|
|
22
|
+
* Check if sandboxing is supported on this platform
|
|
23
|
+
*/
|
|
24
|
+
isSupported(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Check if Linux dependencies are available
|
|
27
|
+
*/
|
|
28
|
+
checkLinuxDependencies(): {
|
|
29
|
+
supported: boolean;
|
|
30
|
+
message?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Clean up sandbox artifacts left by previous runs.
|
|
34
|
+
*
|
|
35
|
+
* Workaround for sandbox-runtime bug: when sandbox binds /dev/null to .claude,
|
|
36
|
+
* it leaves a 0-byte file artifact. On the next run, sandbox-runtime tries to
|
|
37
|
+
* create .claude/commands inside this file, which fails with "Not a directory".
|
|
38
|
+
*
|
|
39
|
+
* This removes the .claude artifact if it's a 0-byte file (not a real directory).
|
|
40
|
+
*/
|
|
41
|
+
cleanupSandboxArtifacts(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Convert our permission model to sandbox-runtime config format
|
|
44
|
+
*/
|
|
45
|
+
private toSandboxConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Initialize the sandbox with given permissions
|
|
48
|
+
* Returns status indicating whether sandbox is active
|
|
49
|
+
*/
|
|
50
|
+
initialize(permissions: SandboxPermissions): Promise<SandboxStatus>;
|
|
51
|
+
/**
|
|
52
|
+
* Wrap a shell command with sandbox restrictions
|
|
53
|
+
* Returns the wrapped command string to execute
|
|
54
|
+
*/
|
|
55
|
+
wrapShellCommand(shell: string, args: string[]): Promise<{
|
|
56
|
+
cmd: string;
|
|
57
|
+
args: string[];
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Check if sandbox is currently active
|
|
61
|
+
*/
|
|
62
|
+
isActive(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Get current permissions (if initialized)
|
|
65
|
+
*/
|
|
66
|
+
getPermissions(): SandboxPermissions | null;
|
|
67
|
+
/**
|
|
68
|
+
* Cleanup sandbox resources
|
|
69
|
+
*/
|
|
70
|
+
cleanup(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/sandbox/controller.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAc,MAAM,aAAa,CAAC;AAI7D,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,aAAa,CAAC;AAE3E,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,eAAe,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAmC;IACtD,OAAO,CAAC,QAAQ,CAAkB;;IAYlC;;OAEG;IACH,WAAW,IAAI,eAAe;IAI9B;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,sBAAsB,IAAI;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAUlE;;;;;;;;OAQG;IACH,uBAAuB,IAAI,IAAI;IAgB/B;;OAEG;IACH,OAAO,CAAC,eAAe;IA6CvB;;;OAGG;IACG,UAAU,CAAC,WAAW,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC;IAkDzE;;;OAGG;IACG,gBAAgB,CACpB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IA2B3C;;OAEG;IACH,QAAQ,IAAI,OAAO;IAInB;;OAEG;IACH,cAAc,IAAI,kBAAkB,GAAG,IAAI;IAI3C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAO/B"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { SandboxManager, } from "@anthropic-ai/sandbox-runtime";
|
|
2
|
+
import { expandPath } from "./config.js";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
/**
|
|
6
|
+
* Controller that wraps sandbox-runtime for terminal-mcp
|
|
7
|
+
* Manages sandbox lifecycle and command wrapping
|
|
8
|
+
*/
|
|
9
|
+
export class SandboxController {
|
|
10
|
+
initialized = false;
|
|
11
|
+
permissions = null;
|
|
12
|
+
platform;
|
|
13
|
+
constructor() {
|
|
14
|
+
// Get platform from Node
|
|
15
|
+
const nodePlatform = process.platform;
|
|
16
|
+
if (nodePlatform === "darwin" || nodePlatform === "linux" || nodePlatform === "win32") {
|
|
17
|
+
this.platform = nodePlatform;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.platform = "unsupported";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the current platform
|
|
25
|
+
*/
|
|
26
|
+
getPlatform() {
|
|
27
|
+
return this.platform;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if sandboxing is supported on this platform
|
|
31
|
+
*/
|
|
32
|
+
isSupported() {
|
|
33
|
+
return SandboxManager.isSupportedPlatform();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if Linux dependencies are available
|
|
37
|
+
*/
|
|
38
|
+
checkLinuxDependencies() {
|
|
39
|
+
if (this.platform !== "linux") {
|
|
40
|
+
return { supported: true };
|
|
41
|
+
}
|
|
42
|
+
const depCheck = SandboxManager.checkDependencies();
|
|
43
|
+
const supported = depCheck.errors.length === 0;
|
|
44
|
+
const message = supported ? undefined : depCheck.errors.join("; ");
|
|
45
|
+
return { supported, message };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Clean up sandbox artifacts left by previous runs.
|
|
49
|
+
*
|
|
50
|
+
* Workaround for sandbox-runtime bug: when sandbox binds /dev/null to .claude,
|
|
51
|
+
* it leaves a 0-byte file artifact. On the next run, sandbox-runtime tries to
|
|
52
|
+
* create .claude/commands inside this file, which fails with "Not a directory".
|
|
53
|
+
*
|
|
54
|
+
* This removes the .claude artifact if it's a 0-byte file (not a real directory).
|
|
55
|
+
*/
|
|
56
|
+
cleanupSandboxArtifacts() {
|
|
57
|
+
const claudePath = path.join(process.cwd(), ".claude");
|
|
58
|
+
try {
|
|
59
|
+
const stat = fs.statSync(claudePath);
|
|
60
|
+
// If .claude is a file (not directory) and 0 bytes, it's a sandbox artifact
|
|
61
|
+
if (stat.isFile() && stat.size === 0) {
|
|
62
|
+
fs.unlinkSync(claudePath);
|
|
63
|
+
if (process.env.DEBUG_SANDBOX) {
|
|
64
|
+
console.error("[sandbox-debug] Cleaned up .claude artifact (0-byte file from previous sandbox run)");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// File doesn't exist or can't be accessed - that's fine
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Convert our permission model to sandbox-runtime config format
|
|
74
|
+
*/
|
|
75
|
+
toSandboxConfig(permissions) {
|
|
76
|
+
// Expand all paths
|
|
77
|
+
const expandPaths = (paths) => paths.map((p) => expandPath(p));
|
|
78
|
+
// Configure network based on mode
|
|
79
|
+
let allowedDomains;
|
|
80
|
+
let deniedDomains = [];
|
|
81
|
+
switch (permissions.network.mode) {
|
|
82
|
+
case "none":
|
|
83
|
+
// Block all network by using empty allowed list
|
|
84
|
+
allowedDomains = [];
|
|
85
|
+
break;
|
|
86
|
+
case "allowlist":
|
|
87
|
+
allowedDomains = permissions.network.allowedDomains ?? [];
|
|
88
|
+
break;
|
|
89
|
+
case "all":
|
|
90
|
+
default:
|
|
91
|
+
// Allow all network access with wildcard
|
|
92
|
+
allowedDomains = ["*"];
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
const config = {
|
|
96
|
+
filesystem: {
|
|
97
|
+
// Read/write paths go to allowWrite
|
|
98
|
+
allowWrite: expandPaths(permissions.filesystem.readWrite),
|
|
99
|
+
// Blocked paths go to denyRead (blocks both read and write)
|
|
100
|
+
denyRead: expandPaths(permissions.filesystem.blocked),
|
|
101
|
+
// Read-only paths: we want to allow read but deny write
|
|
102
|
+
// Paths not in allowWrite are read-only by default
|
|
103
|
+
denyWrite: [],
|
|
104
|
+
},
|
|
105
|
+
network: {
|
|
106
|
+
allowedDomains,
|
|
107
|
+
deniedDomains,
|
|
108
|
+
},
|
|
109
|
+
// Enable PTY support since we're spawning a shell
|
|
110
|
+
allowPty: true,
|
|
111
|
+
};
|
|
112
|
+
return config;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Initialize the sandbox with given permissions
|
|
116
|
+
* Returns status indicating whether sandbox is active
|
|
117
|
+
*/
|
|
118
|
+
async initialize(permissions) {
|
|
119
|
+
// Check platform support
|
|
120
|
+
if (!this.isSupported()) {
|
|
121
|
+
return {
|
|
122
|
+
enabled: false,
|
|
123
|
+
platform: this.platform,
|
|
124
|
+
reason: this.platform === "win32"
|
|
125
|
+
? "Sandbox not available on Windows"
|
|
126
|
+
: `Platform ${this.platform} is not supported`,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// Check Linux dependencies
|
|
130
|
+
if (this.platform === "linux") {
|
|
131
|
+
const depCheck = this.checkLinuxDependencies();
|
|
132
|
+
if (!depCheck.supported) {
|
|
133
|
+
return {
|
|
134
|
+
enabled: false,
|
|
135
|
+
platform: this.platform,
|
|
136
|
+
reason: depCheck.message ?? "Linux sandbox dependencies not available",
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Clean up any sandbox artifacts from previous runs
|
|
141
|
+
// This works around a sandbox-runtime bug where .claude becomes a 0-byte file
|
|
142
|
+
this.cleanupSandboxArtifacts();
|
|
143
|
+
try {
|
|
144
|
+
const config = this.toSandboxConfig(permissions);
|
|
145
|
+
await SandboxManager.initialize(config, undefined, true);
|
|
146
|
+
this.initialized = true;
|
|
147
|
+
this.permissions = permissions;
|
|
148
|
+
return {
|
|
149
|
+
enabled: true,
|
|
150
|
+
platform: this.platform,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
155
|
+
return {
|
|
156
|
+
enabled: false,
|
|
157
|
+
platform: this.platform,
|
|
158
|
+
reason: `Failed to initialize sandbox: ${message}`,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Wrap a shell command with sandbox restrictions
|
|
164
|
+
* Returns the wrapped command string to execute
|
|
165
|
+
*/
|
|
166
|
+
async wrapShellCommand(shell, args) {
|
|
167
|
+
if (!this.initialized) {
|
|
168
|
+
throw new Error("Sandbox not initialized");
|
|
169
|
+
}
|
|
170
|
+
// Build the full command string
|
|
171
|
+
const fullCommand = [shell, ...args].join(" ");
|
|
172
|
+
// Wrap with sandbox
|
|
173
|
+
const sandboxedCommand = await SandboxManager.wrapWithSandbox(fullCommand, shell);
|
|
174
|
+
// Debug: log the generated command
|
|
175
|
+
if (process.env.DEBUG_SANDBOX) {
|
|
176
|
+
console.error("[sandbox-debug] Generated command:", sandboxedCommand);
|
|
177
|
+
}
|
|
178
|
+
// The sandboxed command should be executed via shell
|
|
179
|
+
// Return it as a shell -c command
|
|
180
|
+
return {
|
|
181
|
+
cmd: "/bin/sh",
|
|
182
|
+
args: ["-c", sandboxedCommand],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Check if sandbox is currently active
|
|
187
|
+
*/
|
|
188
|
+
isActive() {
|
|
189
|
+
return this.initialized;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get current permissions (if initialized)
|
|
193
|
+
*/
|
|
194
|
+
getPermissions() {
|
|
195
|
+
return this.permissions;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Cleanup sandbox resources
|
|
199
|
+
*/
|
|
200
|
+
async cleanup() {
|
|
201
|
+
if (this.initialized) {
|
|
202
|
+
await SandboxManager.reset();
|
|
203
|
+
this.initialized = false;
|
|
204
|
+
this.permissions = null;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/sandbox/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAEf,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAsB,UAAU,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;A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,WAAW,EAAE,CAAC;YACrB,MAAM,cAAc,CAAC,KAAK,EAAE,CAAC;YAC7B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { SandboxPermissions, FilesystemPermissions, NetworkPermissions, } from "./config.js";
|
|
2
|
+
export { DEFAULT_PERMISSIONS, loadConfigFromFile, expandPath, mergePermissions, } from "./config.js";
|
|
3
|
+
export type { SandboxPlatform, SandboxStatus, } from "./controller.js";
|
|
4
|
+
export { SandboxController, } from "./controller.js";
|
|
5
|
+
export { promptForPermissions, displayPermissionsSummary, } from "./prompt.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,UAAU,EACV,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,eAAe,EACf,aAAa,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DEFAULT_PERMISSIONS, loadConfigFromFile, expandPath, mergePermissions, } from "./config.js";
|
|
2
|
+
export { SandboxController, } from "./controller.js";
|
|
3
|
+
export { promptForPermissions, displayPermissionsSummary, } from "./prompt.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,UAAU,EACV,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAOrB,OAAO,EACL,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SandboxPermissions } from "./config.js";
|
|
2
|
+
/**
|
|
3
|
+
* Interactive permission selection prompt
|
|
4
|
+
*/
|
|
5
|
+
export declare function promptForPermissions(): Promise<SandboxPermissions>;
|
|
6
|
+
/**
|
|
7
|
+
* Display a summary of the sandbox permissions
|
|
8
|
+
*/
|
|
9
|
+
export declare function displayPermissionsSummary(permissions: SandboxPermissions): void;
|
|
10
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/sandbox/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAiEjD;;GAEG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CA+VxE;AAoED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI,CAmB/E"}
|