sentinel-agentos 0.3.8 → 0.3.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/LICENSE +21 -0
- package/README.md +1797 -0
- package/dist/adapters/evaluation-bridge.d.ts +78 -0
- package/dist/adapters/evaluation-bridge.d.ts.map +1 -0
- package/dist/adapters/evaluation-bridge.js +273 -0
- package/dist/adapters/evaluation-bridge.js.map +1 -0
- package/dist/adapters/memory-bridge.d.ts +110 -0
- package/dist/adapters/memory-bridge.d.ts.map +1 -0
- package/dist/adapters/memory-bridge.js +316 -0
- package/dist/adapters/memory-bridge.js.map +1 -0
- package/dist/adapters/migrate.d.ts +2 -0
- package/dist/adapters/migrate.d.ts.map +1 -0
- package/dist/adapters/migrate.js +63 -0
- package/dist/adapters/migrate.js.map +1 -0
- package/dist/api.d.ts +151 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +179 -0
- package/dist/api.js.map +1 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +350 -0
- package/dist/cli.js.map +1 -0
- package/dist/core.d.ts +156 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +400 -0
- package/dist/core.js.map +1 -0
- package/dist/evaluator/exec-evaluator.d.ts +102 -0
- package/dist/evaluator/exec-evaluator.d.ts.map +1 -0
- package/dist/evaluator/exec-evaluator.js +266 -0
- package/dist/evaluator/exec-evaluator.js.map +1 -0
- package/dist/evaluator/feedback.d.ts +102 -0
- package/dist/evaluator/feedback.d.ts.map +1 -0
- package/dist/evaluator/feedback.js +478 -0
- package/dist/evaluator/feedback.js.map +1 -0
- package/dist/evaluator/profiler.d.ts +56 -0
- package/dist/evaluator/profiler.d.ts.map +1 -0
- package/dist/evaluator/profiler.js +140 -0
- package/dist/evaluator/profiler.js.map +1 -0
- package/dist/guard/audit-log.d.ts +48 -0
- package/dist/guard/audit-log.d.ts.map +1 -0
- package/dist/guard/audit-log.js +213 -0
- package/dist/guard/audit-log.js.map +1 -0
- package/dist/guard/container-sandbox.d.ts +25 -0
- package/dist/guard/container-sandbox.d.ts.map +1 -0
- package/dist/guard/container-sandbox.js +145 -0
- package/dist/guard/container-sandbox.js.map +1 -0
- package/dist/guard/risk-gate.d.ts +101 -0
- package/dist/guard/risk-gate.d.ts.map +1 -0
- package/dist/guard/risk-gate.js +200 -0
- package/dist/guard/risk-gate.js.map +1 -0
- package/dist/guard/sandbox.d.ts +112 -0
- package/dist/guard/sandbox.d.ts.map +1 -0
- package/dist/guard/sandbox.js +379 -0
- package/dist/guard/sandbox.js.map +1 -0
- package/dist/guard/schema-gate.d.ts +90 -0
- package/dist/guard/schema-gate.d.ts.map +1 -0
- package/dist/guard/schema-gate.js +452 -0
- package/dist/guard/schema-gate.js.map +1 -0
- package/dist/guard/snapshot-verify.d.ts +111 -0
- package/dist/guard/snapshot-verify.d.ts.map +1 -0
- package/dist/guard/snapshot-verify.js +571 -0
- package/dist/guard/snapshot-verify.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/episodic.d.ts +80 -0
- package/dist/memory/episodic.d.ts.map +1 -0
- package/dist/memory/episodic.js +305 -0
- package/dist/memory/episodic.js.map +1 -0
- package/dist/memory/semantic.d.ts +68 -0
- package/dist/memory/semantic.d.ts.map +1 -0
- package/dist/memory/semantic.js +299 -0
- package/dist/memory/semantic.js.map +1 -0
- package/dist/memory/working.d.ts +53 -0
- package/dist/memory/working.d.ts.map +1 -0
- package/dist/memory/working.js +166 -0
- package/dist/memory/working.js.map +1 -0
- package/dist/middleware/openclaw.d.ts +45 -0
- package/dist/middleware/openclaw.d.ts.map +1 -0
- package/dist/middleware/openclaw.js +95 -0
- package/dist/middleware/openclaw.js.map +1 -0
- package/dist/middleware/wrapper.d.ts +54 -0
- package/dist/middleware/wrapper.d.ts.map +1 -0
- package/dist/middleware/wrapper.js +155 -0
- package/dist/middleware/wrapper.js.map +1 -0
- package/dist/server.d.ts +45 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +256 -0
- package/dist/server.js.map +1 -0
- package/dist/src/dashboard.html +9 -7
- package/dist/types/index.d.ts +228 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +1 -1
- package/scripts/sentinel-light.js +234 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SandboxExecutor = exports.SandboxViolation = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const child_process_1 = require("child_process");
|
|
40
|
+
/**
|
|
41
|
+
* Sandbox Violation types.
|
|
42
|
+
*/
|
|
43
|
+
var SandboxViolation;
|
|
44
|
+
(function (SandboxViolation) {
|
|
45
|
+
SandboxViolation["NETWORK_FORBIDDEN"] = "NETWORK_FORBIDDEN";
|
|
46
|
+
SandboxViolation["PATH_NOT_WRITABLE"] = "PATH_NOT_WRITABLE";
|
|
47
|
+
SandboxViolation["PATH_READONLY"] = "PATH_READONLY";
|
|
48
|
+
SandboxViolation["TOOL_FORBIDDEN"] = "TOOL_FORBIDDEN";
|
|
49
|
+
SandboxViolation["TOOL_NOT_ALLOWED"] = "TOOL_NOT_ALLOWED";
|
|
50
|
+
SandboxViolation["COMMAND_FORBIDDEN"] = "COMMAND_FORBIDDEN";
|
|
51
|
+
})(SandboxViolation || (exports.SandboxViolation = SandboxViolation = {}));
|
|
52
|
+
/**
|
|
53
|
+
* Sandbox Executor — controlled execution environment.
|
|
54
|
+
*
|
|
55
|
+
* Implements three execution modes from DESIGN.md §4.5:
|
|
56
|
+
* - direct: Execute in shared environment (default, no sandboxing)
|
|
57
|
+
* - sandbox: Restricted execution with network + filesystem policies
|
|
58
|
+
* - dry-run: Preview only, no actual execution
|
|
59
|
+
*/
|
|
60
|
+
class SandboxExecutor {
|
|
61
|
+
config;
|
|
62
|
+
/** Forbidden shell commands (dangerous patterns) */
|
|
63
|
+
static FORBIDDEN_COMMANDS = [
|
|
64
|
+
/rm\s+-rf\s+\//,
|
|
65
|
+
/sudo\s/,
|
|
66
|
+
/chmod\s+777/,
|
|
67
|
+
/>\s*\/dev\//,
|
|
68
|
+
/mkfs\./,
|
|
69
|
+
/dd\s+if=/,
|
|
70
|
+
/:()\s*\{\s*:/, // fork bomb
|
|
71
|
+
/curl.*\|\s*bash/,
|
|
72
|
+
/wget.*\|\s*sh/,
|
|
73
|
+
];
|
|
74
|
+
constructor(config) {
|
|
75
|
+
this.config = {
|
|
76
|
+
maxOutputSize: 1024 * 1024, // 1MB default
|
|
77
|
+
...config,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Validate and possibly reject a tool call before execution.
|
|
82
|
+
*
|
|
83
|
+
* @returns {SandboxResult} with sandboxRejectReason if rejected
|
|
84
|
+
*/
|
|
85
|
+
validate(toolName, params) {
|
|
86
|
+
// Check forbidden tools
|
|
87
|
+
if (this.config.forbiddenTools) {
|
|
88
|
+
if (this.config.forbiddenTools.includes(toolName)) {
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
exitCode: 126,
|
|
92
|
+
stdout: '',
|
|
93
|
+
stderr: '',
|
|
94
|
+
truncated: false,
|
|
95
|
+
durationMs: 0,
|
|
96
|
+
sandboxRejectReason: `Tool "${toolName}" is forbidden by sandbox policy`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Check allowed tools (sandbox mode)
|
|
101
|
+
if (this.config.mode === 'sandbox' && this.config.allowedTools) {
|
|
102
|
+
if (!this.config.allowedTools.includes(toolName)) {
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
exitCode: 126,
|
|
106
|
+
stdout: '',
|
|
107
|
+
stderr: '',
|
|
108
|
+
truncated: false,
|
|
109
|
+
durationMs: 0,
|
|
110
|
+
sandboxRejectReason: `Tool "${toolName}" is not in the sandbox allowed-tools list`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Check filesystem writes
|
|
115
|
+
if (this.config.mode === 'sandbox') {
|
|
116
|
+
const pathParam = params['path'] || params['file'] || params['filePath'];
|
|
117
|
+
if (typeof pathParam === 'string') {
|
|
118
|
+
const fsCheck = this.validatePath(pathParam, this.isWriteTool(toolName));
|
|
119
|
+
if (fsCheck)
|
|
120
|
+
return fsCheck;
|
|
121
|
+
}
|
|
122
|
+
// Check multiple paths
|
|
123
|
+
const paths = params['paths'] || params['files'] || params['targets'];
|
|
124
|
+
if (Array.isArray(paths)) {
|
|
125
|
+
for (const p of paths) {
|
|
126
|
+
if (typeof p === 'string') {
|
|
127
|
+
const fsCheck = this.validatePath(p, this.isWriteTool(toolName));
|
|
128
|
+
if (fsCheck)
|
|
129
|
+
return fsCheck;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Check shell commands for dangerous patterns
|
|
135
|
+
if (toolName === 'exec' || toolName === 'shell' || toolName === 'command') {
|
|
136
|
+
const command = String(params['command'] || params['cmd'] || '');
|
|
137
|
+
const cmdCheck = this.validateCommand(command);
|
|
138
|
+
if (cmdCheck)
|
|
139
|
+
return cmdCheck;
|
|
140
|
+
}
|
|
141
|
+
return null; // All clear
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Execute a shell command in the configured mode.
|
|
145
|
+
*/
|
|
146
|
+
async execute(toolName, params) {
|
|
147
|
+
const startTime = Date.now();
|
|
148
|
+
// 1. Pre-flight validation
|
|
149
|
+
const rejection = this.validate(toolName, params);
|
|
150
|
+
if (rejection)
|
|
151
|
+
return rejection;
|
|
152
|
+
// 2. Dry-run mode
|
|
153
|
+
if (this.config.mode === 'dry-run') {
|
|
154
|
+
return this.dryRun(toolName, params);
|
|
155
|
+
}
|
|
156
|
+
// 3. Build command for exec-based tools
|
|
157
|
+
if (this.isShellTool(toolName)) {
|
|
158
|
+
return this.executeShell(params);
|
|
159
|
+
}
|
|
160
|
+
// 4. For non-shell tools: delegate (no sandbox exec here — that's the agent runtime's job)
|
|
161
|
+
// Sandbox mode only applies to shell commands at this level
|
|
162
|
+
return {
|
|
163
|
+
success: true,
|
|
164
|
+
exitCode: 0,
|
|
165
|
+
stdout: '',
|
|
166
|
+
stderr: '',
|
|
167
|
+
truncated: false,
|
|
168
|
+
durationMs: Date.now() - startTime,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Dry-run: return a summary of what would happen.
|
|
173
|
+
*/
|
|
174
|
+
dryRun(toolName, params) {
|
|
175
|
+
const summaryParts = [];
|
|
176
|
+
if (this.isShellTool(toolName)) {
|
|
177
|
+
const command = String(params['command'] || '');
|
|
178
|
+
summaryParts.push(`Would execute: ${command}`);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
summaryParts.push(`Would call: ${toolName}(${JSON.stringify(params)})`);
|
|
182
|
+
}
|
|
183
|
+
// Check files that would be affected
|
|
184
|
+
const pathParam = params['path'] || params['file'] || params['filePath'];
|
|
185
|
+
if (typeof pathParam === 'string') {
|
|
186
|
+
const fullPath = path.resolve(this.config.workspaceRoot, pathParam);
|
|
187
|
+
if (fs.existsSync(fullPath)) {
|
|
188
|
+
const stat = fs.statSync(fullPath);
|
|
189
|
+
summaryParts.push(`File exists: ${pathParam} (${stat.size} bytes)`);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
summaryParts.push(`File would be created: ${pathParam}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
success: true,
|
|
197
|
+
exitCode: 0,
|
|
198
|
+
stdout: '',
|
|
199
|
+
stderr: '',
|
|
200
|
+
truncated: false,
|
|
201
|
+
durationMs: 0,
|
|
202
|
+
dryRunSummary: summaryParts.join('\n'),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Execute shell commands with sandbox policies.
|
|
207
|
+
*/
|
|
208
|
+
async executeShell(params) {
|
|
209
|
+
const startTime = Date.now();
|
|
210
|
+
const command = String(params['command'] || '');
|
|
211
|
+
const cwd = String(params['cwd'] || this.config.workspaceRoot);
|
|
212
|
+
try {
|
|
213
|
+
// Apply network restrictions
|
|
214
|
+
const env = this.buildSandboxEnv();
|
|
215
|
+
let output;
|
|
216
|
+
try {
|
|
217
|
+
output = (0, child_process_1.execSync)(command, {
|
|
218
|
+
cwd,
|
|
219
|
+
encoding: 'utf-8',
|
|
220
|
+
env,
|
|
221
|
+
timeout: this.config.timeoutMs,
|
|
222
|
+
maxBuffer: this.config.maxOutputSize,
|
|
223
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
catch (execErr) {
|
|
227
|
+
return {
|
|
228
|
+
success: false,
|
|
229
|
+
exitCode: execErr.status ?? 1,
|
|
230
|
+
stdout: execErr.stdout?.slice(0, this.config.maxOutputSize) ?? '',
|
|
231
|
+
stderr: execErr.stderr?.slice(0, this.config.maxOutputSize) ?? '',
|
|
232
|
+
truncated: (execErr.stdout?.length ?? 0) > (this.config.maxOutputSize ?? 1024 * 1024),
|
|
233
|
+
durationMs: Date.now() - startTime,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const truncated = output.length > (this.config.maxOutputSize ?? 1024 * 1024);
|
|
237
|
+
const finalOutput = truncated
|
|
238
|
+
? output.slice(0, this.config.maxOutputSize ?? 1024 * 1024)
|
|
239
|
+
: output;
|
|
240
|
+
return {
|
|
241
|
+
success: true,
|
|
242
|
+
exitCode: 0,
|
|
243
|
+
stdout: finalOutput,
|
|
244
|
+
stderr: '',
|
|
245
|
+
truncated,
|
|
246
|
+
durationMs: Date.now() - startTime,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
return {
|
|
251
|
+
success: false,
|
|
252
|
+
exitCode: 1,
|
|
253
|
+
stdout: '',
|
|
254
|
+
stderr: err.message ?? 'Unknown execution error',
|
|
255
|
+
truncated: false,
|
|
256
|
+
durationMs: Date.now() - startTime,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Build environment with sandbox network restrictions.
|
|
262
|
+
*/
|
|
263
|
+
buildSandboxEnv() {
|
|
264
|
+
if (this.config.mode !== 'sandbox' || this.config.networkAccess === undefined) {
|
|
265
|
+
return undefined; // Use default env
|
|
266
|
+
}
|
|
267
|
+
const env = { ...process.env };
|
|
268
|
+
switch (this.config.networkAccess) {
|
|
269
|
+
case 'none':
|
|
270
|
+
env['http_proxy'] = 'http://0.0.0.0:0'; // Blackhole
|
|
271
|
+
env['https_proxy'] = 'http://0.0.0.0:0';
|
|
272
|
+
env['HTTP_PROXY'] = 'http://0.0.0.0:0';
|
|
273
|
+
env['HTTPS_PROXY'] = 'http://0.0.0.0:0';
|
|
274
|
+
env['NO_PROXY'] = '';
|
|
275
|
+
break;
|
|
276
|
+
case 'localhost':
|
|
277
|
+
env['http_proxy'] = 'http://0.0.0.0:0';
|
|
278
|
+
env['https_proxy'] = 'http://0.0.0.0:0';
|
|
279
|
+
env['HTTP_PROXY'] = 'http://0.0.0.0:0';
|
|
280
|
+
env['HTTPS_PROXY'] = 'http://0.0.0.0:0';
|
|
281
|
+
env['NO_PROXY'] = 'localhost,127.0.0.1,::1';
|
|
282
|
+
break;
|
|
283
|
+
case 'whitelist':
|
|
284
|
+
if (this.config.networkWhitelist) {
|
|
285
|
+
env['http_proxy'] = 'http://0.0.0.0:0';
|
|
286
|
+
env['https_proxy'] = 'http://0.0.0.0:0';
|
|
287
|
+
env['HTTP_PROXY'] = 'http://0.0.0.0:0';
|
|
288
|
+
env['HTTPS_PROXY'] = 'http://0.0.0.0:0';
|
|
289
|
+
env['NO_PROXY'] = this.config.networkWhitelist.join(',') + ',localhost,127.0.0.1';
|
|
290
|
+
}
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
return env;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Validate a filesystem path against sandbox policies.
|
|
297
|
+
*/
|
|
298
|
+
validatePath(filePath, isWrite) {
|
|
299
|
+
const resolvedPath = path.resolve(this.config.workspaceRoot, filePath);
|
|
300
|
+
const normalizedRoot = path.resolve(this.config.workspaceRoot);
|
|
301
|
+
// Check if path is within workspace
|
|
302
|
+
if (!resolvedPath.startsWith(normalizedRoot + path.sep) && resolvedPath !== normalizedRoot) {
|
|
303
|
+
return {
|
|
304
|
+
success: false,
|
|
305
|
+
exitCode: 126,
|
|
306
|
+
stdout: '',
|
|
307
|
+
stderr: '',
|
|
308
|
+
truncated: false,
|
|
309
|
+
durationMs: 0,
|
|
310
|
+
sandboxRejectReason: `Path "${filePath}" is outside workspace boundaries`,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
if (isWrite) {
|
|
314
|
+
// Check writable paths
|
|
315
|
+
if (this.config.writablePaths && this.config.writablePaths.length > 0) {
|
|
316
|
+
const isWritable = this.config.writablePaths.some((wp) => resolvedPath.startsWith(path.resolve(this.config.workspaceRoot, wp)));
|
|
317
|
+
if (!isWritable) {
|
|
318
|
+
return {
|
|
319
|
+
success: false,
|
|
320
|
+
exitCode: 126,
|
|
321
|
+
stdout: '',
|
|
322
|
+
stderr: '',
|
|
323
|
+
truncated: false,
|
|
324
|
+
durationMs: 0,
|
|
325
|
+
sandboxRejectReason: `Path "${filePath}" is not in the sandbox writable paths list`,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// Check readonly paths
|
|
330
|
+
if (this.config.readonlyPaths) {
|
|
331
|
+
const isReadonly = this.config.readonlyPaths.some((rp) => resolvedPath.startsWith(path.resolve(this.config.workspaceRoot, rp)));
|
|
332
|
+
if (isReadonly) {
|
|
333
|
+
return {
|
|
334
|
+
success: false,
|
|
335
|
+
exitCode: 126,
|
|
336
|
+
stdout: '',
|
|
337
|
+
stderr: '',
|
|
338
|
+
truncated: false,
|
|
339
|
+
durationMs: 0,
|
|
340
|
+
sandboxRejectReason: `Path "${filePath}" is read-only in sandbox mode`,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Validate a shell command against forbidden patterns.
|
|
349
|
+
*/
|
|
350
|
+
validateCommand(command) {
|
|
351
|
+
for (const pattern of SandboxExecutor.FORBIDDEN_COMMANDS) {
|
|
352
|
+
if (pattern.test(command)) {
|
|
353
|
+
return {
|
|
354
|
+
success: false,
|
|
355
|
+
exitCode: 126,
|
|
356
|
+
stdout: '',
|
|
357
|
+
stderr: '',
|
|
358
|
+
truncated: false,
|
|
359
|
+
durationMs: 0,
|
|
360
|
+
sandboxRejectReason: `Command matches forbidden pattern: "${pattern.source}"`,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
isShellTool(toolName) {
|
|
367
|
+
return ['exec', 'shell', 'command', 'bash', 'sh', 'cmd'].includes(toolName);
|
|
368
|
+
}
|
|
369
|
+
isWriteTool(toolName) {
|
|
370
|
+
const writeTools = [
|
|
371
|
+
'write_file', 'write', 'edit', 'edit_file', 'create_file',
|
|
372
|
+
'mkdir', 'rm', 'unlink', 'delete_file', 'delete', 'mv', 'cp',
|
|
373
|
+
'exec', 'shell', 'git_commit', 'git_push',
|
|
374
|
+
];
|
|
375
|
+
return writeTools.some((t) => toolName.includes(t));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
exports.SandboxExecutor = SandboxExecutor;
|
|
379
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../../src/guard/sandbox.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,iDAAyC;AA4DzC;;GAEG;AACH,IAAY,gBAOX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QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;;AA7VH,0CA8VC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { SchemaCheck } from '../types';
|
|
2
|
+
import type { GuardConfig } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Extended schema rule — supports all x- extensions from DESIGN.md §4.2.
|
|
5
|
+
*/
|
|
6
|
+
export interface SchemaRule {
|
|
7
|
+
/** Tool name to match */
|
|
8
|
+
tool: string;
|
|
9
|
+
/** Required parameter names */
|
|
10
|
+
required?: string[];
|
|
11
|
+
/** Parameter type constraints */
|
|
12
|
+
types?: Record<string, 'string' | 'number' | 'boolean' | 'object' | 'array'>;
|
|
13
|
+
/** Allowed values for specific parameters */
|
|
14
|
+
allowedValues?: Record<string, unknown[]>;
|
|
15
|
+
/** Min/max numeric constraints */
|
|
16
|
+
min?: Record<string, number>;
|
|
17
|
+
max?: Record<string, number>;
|
|
18
|
+
/** Regex patterns for string validation */
|
|
19
|
+
patterns?: Record<string, string>;
|
|
20
|
+
/** Custom validation functions */
|
|
21
|
+
custom?: Record<string, (value: unknown) => string | null>;
|
|
22
|
+
/** x- extensions: path scope constraint */
|
|
23
|
+
pathScope?: Record<string, 'workspace' | 'temp' | 'global'>;
|
|
24
|
+
/** x- extensions: allowed path glob patterns */
|
|
25
|
+
pathAllow?: Record<string, string[]>;
|
|
26
|
+
/** x- extensions: denied path glob patterns */
|
|
27
|
+
pathDeny?: Record<string, string[]>;
|
|
28
|
+
/** x- extensions: max parameter size in bytes */
|
|
29
|
+
maxSize?: Record<string, number>;
|
|
30
|
+
/** x- extensions: parameters marked as secret (redacted in logs) */
|
|
31
|
+
secrets?: string[];
|
|
32
|
+
/** x- extensions: parameter dependency — if X is set, Y is required */
|
|
33
|
+
dependsOn?: Record<string, {
|
|
34
|
+
required: string[];
|
|
35
|
+
}>;
|
|
36
|
+
/** x- extensions: mutually exclusive parameter groups */
|
|
37
|
+
mutuallyExclusive?: string[][];
|
|
38
|
+
/** Workspace root for path validation */
|
|
39
|
+
workspaceRoot?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Schema Gate — deterministic parameter validation with JSON Schema x- extensions.
|
|
43
|
+
*
|
|
44
|
+
* Implements every validation rule from DESIGN.md §4.2:
|
|
45
|
+
* - required fields ✓
|
|
46
|
+
* - type checking ✓
|
|
47
|
+
* - allowed values ✓
|
|
48
|
+
* - numeric range ✓
|
|
49
|
+
* - regex patterns ✓
|
|
50
|
+
* - path scope constraint (x-path-scope) ✓
|
|
51
|
+
* - path allow/deny globs (x-path-allow/x-path-deny) ✓
|
|
52
|
+
* - max parameter size (x-max-size) ✓
|
|
53
|
+
* - secret parameter marking (x-secret) ✓
|
|
54
|
+
* - parameter dependencies (x-depends-on) ✓
|
|
55
|
+
* - mutually exclusive params (x-mutually-exclusive) ✓
|
|
56
|
+
* - custom validators ✓
|
|
57
|
+
*
|
|
58
|
+
* Zero LLM dependency. Pure deterministic logic.
|
|
59
|
+
*/
|
|
60
|
+
export declare class SchemaGate {
|
|
61
|
+
private rules;
|
|
62
|
+
constructor(config?: GuardConfig);
|
|
63
|
+
/** Register a schema rule for a tool */
|
|
64
|
+
registerRule(rule: SchemaRule): void;
|
|
65
|
+
/** Register multiple rules at once */
|
|
66
|
+
registerRules(rules: SchemaRule[]): void;
|
|
67
|
+
/** Get all registered rules */
|
|
68
|
+
getRules(): SchemaRule[];
|
|
69
|
+
/** Check if a tool has a registered rule */
|
|
70
|
+
hasRule(tool: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Full validation: runs all applicable checks.
|
|
73
|
+
* Returns { pass: boolean, errors: SchemaError[] }.
|
|
74
|
+
*/
|
|
75
|
+
check(toolName: string, params: Record<string, unknown>): SchemaCheck;
|
|
76
|
+
/**
|
|
77
|
+
* Check if a parameter is marked as secret (x-secret).
|
|
78
|
+
*/
|
|
79
|
+
isSecret(toolName: string, field: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Get all secret field names for a tool.
|
|
82
|
+
*/
|
|
83
|
+
getSecrets(toolName: string): string[];
|
|
84
|
+
/**
|
|
85
|
+
* Simple glob matching for path allow/deny patterns.
|
|
86
|
+
* Supports *, **, ? wildcards.
|
|
87
|
+
*/
|
|
88
|
+
private matchGlob;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=schema-gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-gate.d.ts","sourceRoot":"","sources":["../../src/guard/schema-gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC,CAAC;IAC7E,6CAA6C;IAC7C,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1C,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC;IAC3D,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAA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