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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1797 -0
  3. package/dist/adapters/evaluation-bridge.d.ts +78 -0
  4. package/dist/adapters/evaluation-bridge.d.ts.map +1 -0
  5. package/dist/adapters/evaluation-bridge.js +273 -0
  6. package/dist/adapters/evaluation-bridge.js.map +1 -0
  7. package/dist/adapters/memory-bridge.d.ts +110 -0
  8. package/dist/adapters/memory-bridge.d.ts.map +1 -0
  9. package/dist/adapters/memory-bridge.js +316 -0
  10. package/dist/adapters/memory-bridge.js.map +1 -0
  11. package/dist/adapters/migrate.d.ts +2 -0
  12. package/dist/adapters/migrate.d.ts.map +1 -0
  13. package/dist/adapters/migrate.js +63 -0
  14. package/dist/adapters/migrate.js.map +1 -0
  15. package/dist/api.d.ts +151 -0
  16. package/dist/api.d.ts.map +1 -0
  17. package/dist/api.js +179 -0
  18. package/dist/api.js.map +1 -0
  19. package/dist/cli.d.ts +16 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +350 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/core.d.ts +156 -0
  24. package/dist/core.d.ts.map +1 -0
  25. package/dist/core.js +400 -0
  26. package/dist/core.js.map +1 -0
  27. package/dist/evaluator/exec-evaluator.d.ts +102 -0
  28. package/dist/evaluator/exec-evaluator.d.ts.map +1 -0
  29. package/dist/evaluator/exec-evaluator.js +266 -0
  30. package/dist/evaluator/exec-evaluator.js.map +1 -0
  31. package/dist/evaluator/feedback.d.ts +102 -0
  32. package/dist/evaluator/feedback.d.ts.map +1 -0
  33. package/dist/evaluator/feedback.js +478 -0
  34. package/dist/evaluator/feedback.js.map +1 -0
  35. package/dist/evaluator/profiler.d.ts +56 -0
  36. package/dist/evaluator/profiler.d.ts.map +1 -0
  37. package/dist/evaluator/profiler.js +140 -0
  38. package/dist/evaluator/profiler.js.map +1 -0
  39. package/dist/guard/audit-log.d.ts +48 -0
  40. package/dist/guard/audit-log.d.ts.map +1 -0
  41. package/dist/guard/audit-log.js +213 -0
  42. package/dist/guard/audit-log.js.map +1 -0
  43. package/dist/guard/container-sandbox.d.ts +25 -0
  44. package/dist/guard/container-sandbox.d.ts.map +1 -0
  45. package/dist/guard/container-sandbox.js +145 -0
  46. package/dist/guard/container-sandbox.js.map +1 -0
  47. package/dist/guard/risk-gate.d.ts +101 -0
  48. package/dist/guard/risk-gate.d.ts.map +1 -0
  49. package/dist/guard/risk-gate.js +200 -0
  50. package/dist/guard/risk-gate.js.map +1 -0
  51. package/dist/guard/sandbox.d.ts +112 -0
  52. package/dist/guard/sandbox.d.ts.map +1 -0
  53. package/dist/guard/sandbox.js +379 -0
  54. package/dist/guard/sandbox.js.map +1 -0
  55. package/dist/guard/schema-gate.d.ts +90 -0
  56. package/dist/guard/schema-gate.d.ts.map +1 -0
  57. package/dist/guard/schema-gate.js +452 -0
  58. package/dist/guard/schema-gate.js.map +1 -0
  59. package/dist/guard/snapshot-verify.d.ts +111 -0
  60. package/dist/guard/snapshot-verify.d.ts.map +1 -0
  61. package/dist/guard/snapshot-verify.js +571 -0
  62. package/dist/guard/snapshot-verify.js.map +1 -0
  63. package/dist/index.d.ts +28 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +59 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/memory/episodic.d.ts +80 -0
  68. package/dist/memory/episodic.d.ts.map +1 -0
  69. package/dist/memory/episodic.js +305 -0
  70. package/dist/memory/episodic.js.map +1 -0
  71. package/dist/memory/semantic.d.ts +68 -0
  72. package/dist/memory/semantic.d.ts.map +1 -0
  73. package/dist/memory/semantic.js +299 -0
  74. package/dist/memory/semantic.js.map +1 -0
  75. package/dist/memory/working.d.ts +53 -0
  76. package/dist/memory/working.d.ts.map +1 -0
  77. package/dist/memory/working.js +166 -0
  78. package/dist/memory/working.js.map +1 -0
  79. package/dist/middleware/openclaw.d.ts +45 -0
  80. package/dist/middleware/openclaw.d.ts.map +1 -0
  81. package/dist/middleware/openclaw.js +95 -0
  82. package/dist/middleware/openclaw.js.map +1 -0
  83. package/dist/middleware/wrapper.d.ts +54 -0
  84. package/dist/middleware/wrapper.d.ts.map +1 -0
  85. package/dist/middleware/wrapper.js +155 -0
  86. package/dist/middleware/wrapper.js.map +1 -0
  87. package/dist/server.d.ts +45 -0
  88. package/dist/server.d.ts.map +1 -0
  89. package/dist/server.js +256 -0
  90. package/dist/server.js.map +1 -0
  91. package/dist/src/dashboard.html +9 -7
  92. package/dist/types/index.d.ts +228 -0
  93. package/dist/types/index.d.ts.map +1 -0
  94. package/dist/types/index.js +23 -0
  95. package/dist/types/index.js.map +1 -0
  96. package/package.json +1 -1
  97. package/scripts/sentinel-light.js +234 -0
@@ -0,0 +1,101 @@
1
+ import { RiskScore } from '../types';
2
+ /**
3
+ * Impact level — how broadly the operation affects the system.
4
+ */
5
+ export type ImpactLevel = 'local' | 'workspace' | 'project' | 'system';
6
+ /**
7
+ * Sensitivity level — how sensitive the data involved is.
8
+ */
9
+ export type SensitivityLevel = 'none' | 'low' | 'medium' | 'high' | 'critical';
10
+ /**
11
+ * Tool-level risk profile — users define this per tool.
12
+ */
13
+ export interface ToolRiskProfile {
14
+ /** Tool name to match */
15
+ tool: string;
16
+ /** Impact level of this tool */
17
+ impact: ImpactLevel;
18
+ /** How reversible the operation is (0 = irreversible, 1 = fully reversible) */
19
+ reversibility: number;
20
+ /** Sensitivity of data this tool accesses */
21
+ sensitivity: SensitivityLevel;
22
+ /** Tool category for default error rate */
23
+ category?: 'read' | 'write' | 'delete' | 'network' | 'compute';
24
+ /** Optional override for initial error rate (skips category default) */
25
+ initialErrorRate?: number;
26
+ }
27
+ /**
28
+ * Tool call statistics for dynamic error-rate tracking.
29
+ */
30
+ interface ToolStats {
31
+ totalCalls: number;
32
+ failures: number;
33
+ errorRate: number;
34
+ lastUpdated: number;
35
+ }
36
+ /**
37
+ * Threshold configuration for risk-based actions.
38
+ */
39
+ export interface RiskThresholds {
40
+ /** Score ≤ autoApprove → execute immediately */
41
+ autoApprove: number;
42
+ /** Score ≤ notify → execute but notify user */
43
+ notify: number;
44
+ /** Score ≤ confirm → pause and ask for user confirmation */
45
+ confirm: number;
46
+ /** Score > deny → block entirely */
47
+ deny: number;
48
+ }
49
+ /**
50
+ * Default thresholds — conservative but workable.
51
+ */
52
+ export declare const DEFAULT_RISK_THRESHOLDS: RiskThresholds;
53
+ /**
54
+ * Risk Gate — deterministic, pure-math risk scoring.
55
+ *
56
+ * Formula: RiskScore = Impact × (1 - Reversibility) × Sensitivity × (1 + ErrorRate)
57
+ *
58
+ * Zero LLM dependency. The formula, thresholds, and mappings are all
59
+ * explicit and auditable.
60
+ */
61
+ export declare class RiskGate {
62
+ private profiles;
63
+ private stats;
64
+ private thresholds;
65
+ constructor(thresholds?: RiskThresholds);
66
+ /** Register a risk profile for a tool */
67
+ registerProfile(profile: ToolRiskProfile): void;
68
+ /** Register multiple profiles at once */
69
+ registerProfiles(profiles: ToolRiskProfile[]): void;
70
+ /** Get all registered profiles */
71
+ getProfiles(): ToolRiskProfile[];
72
+ /** Check if a tool has a registered profile */
73
+ hasProfile(tool: string): boolean;
74
+ /**
75
+ * Compute the risk score for a tool call.
76
+ *
77
+ * If no profile is registered, returns a default moderate-risk score
78
+ * (auto-approve with notification).
79
+ */
80
+ evaluate(tool: string, _params?: Record<string, unknown>): RiskScore;
81
+ /**
82
+ * Evaluate risk for an unregistered tool by scanning params for danger patterns.
83
+ */
84
+ private evaluateUntracked;
85
+ /** Record the outcome of a tool call to update stats */
86
+ recordOutcome(tool: string, success: boolean): void;
87
+ /** Get tool statistics */
88
+ getStats(tool: string): ToolStats | undefined;
89
+ /** Get all tool statistics */
90
+ getAllStats(): Map<string, ToolStats>;
91
+ /** Update thresholds at runtime */
92
+ setThresholds(thresholds: Partial<RiskThresholds>): void;
93
+ /** Get current thresholds */
94
+ getThresholds(): RiskThresholds;
95
+ /**
96
+ * Map a numeric risk score to the appropriate action.
97
+ */
98
+ private scoreToAction;
99
+ }
100
+ export {};
101
+ //# sourceMappingURL=risk-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"risk-gate.d.ts","sourceRoot":"","sources":["../../src/guard/risk-gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AASvE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AAsC/E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,MAAM,EAAE,WAAW,CAAC;IACpB,+EAA+E;IAC/E,aAAa,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,WAAW,EAAE,gBAAgB,CAAC;IAC9B,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAC/D,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,UAAU,SAAS;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,cAKrC,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAA2C;IAC3D,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,UAAU,CAAiB;gBAEvB,UAAU,GAAE,cAAwC;IAIhE,yCAAyC;IACzC,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAgB/C,yCAAyC;IACzC,gBAAgB,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,IAAI;IAInD,kCAAkC;IAClC,WAAW,IAAI,eAAe,EAAE;IAIhC,+CAA+C;IAC/C,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IA+BpE;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAiCzB,wDAAwD;IACxD,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAWnD,0BAA0B;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAI7C,8BAA8B;IAC9B,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC;IAIrC,mCAAmC;IACnC,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;IAIxD,6BAA6B;IAC7B,aAAa,IAAI,cAAc;IAI/B;;OAEG;IACH,OAAO,CAAC,aAAa;CAMtB"}
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RiskGate = exports.DEFAULT_RISK_THRESHOLDS = void 0;
4
+ const IMPACT_VALUES = {
5
+ local: 1,
6
+ workspace: 3,
7
+ project: 6,
8
+ system: 10,
9
+ };
10
+ const SENSITIVITY_VALUES = {
11
+ none: 0.0,
12
+ low: 0.3,
13
+ medium: 0.6,
14
+ high: 0.9,
15
+ critical: 1.0,
16
+ };
17
+ /**
18
+ * Default error rates by tool category (cold start).
19
+ */
20
+ const DEFAULT_ERROR_RATES = {
21
+ read: 0.01,
22
+ write: 0.05,
23
+ delete: 0.10,
24
+ network: 0.08,
25
+ compute: 0.02,
26
+ };
27
+ // Danger patterns for content-based fallback (used when no profile registered)
28
+ const DANGER_PATTERNS = [
29
+ { regex: new RegExp('rm\\s+-rf\\s+(?:[/~]|\\*)', 'i'), impact: 'system', reversibility: 0.0, sensitivity: 'critical' },
30
+ { regex: new RegExp('sudo\\s+rm\\s+-rf', 'i'), impact: 'system', reversibility: 0.0, sensitivity: 'critical' },
31
+ { regex: new RegExp('del\\s+[/][fsq]\\s+[a-z]:[\\\\]?', 'i'), impact: 'system', reversibility: 0.0, sensitivity: 'critical' },
32
+ { regex: new RegExp('\\bmkfs\\b', 'i'), impact: 'system', reversibility: 0.0, sensitivity: 'critical' },
33
+ { regex: new RegExp('\\bdd\\s+if=', 'i'), impact: 'system', reversibility: 0.0, sensitivity: 'critical' },
34
+ { regex: new RegExp('chmod\\s+777\\s+-R', 'i'), impact: 'system', reversibility: 0.1, sensitivity: 'high' },
35
+ { regex: /drop\s+(table|database|schema)/i, impact: 'project', reversibility: 0.0, sensitivity: 'critical' },
36
+ { regex: /truncate\s+(table\s+)?/i, impact: 'project', reversibility: 0.0, sensitivity: 'high' },
37
+ { regex: /git\s+push\s+[\w\s-]*--force/i, impact: 'project', reversibility: 0.2, sensitivity: 'high' },
38
+ { regex: /git\s+reset\s+--hard/i, impact: 'project', reversibility: 0.3, sensitivity: 'high' },
39
+ { regex: /npm\s+unpublish\b/i, impact: 'project', reversibility: 0.0, sensitivity: 'high' },
40
+ { regex: /\.(?:env|key|pem|p12|pfx|jks|keystore)/i, impact: 'workspace', reversibility: 0.5, sensitivity: 'critical' },
41
+ ];
42
+ /**
43
+ * Default thresholds — conservative but workable.
44
+ */
45
+ exports.DEFAULT_RISK_THRESHOLDS = {
46
+ autoApprove: 0.5,
47
+ notify: 1.0,
48
+ confirm: 3.0,
49
+ deny: 8.0,
50
+ };
51
+ /**
52
+ * Risk Gate — deterministic, pure-math risk scoring.
53
+ *
54
+ * Formula: RiskScore = Impact × (1 - Reversibility) × Sensitivity × (1 + ErrorRate)
55
+ *
56
+ * Zero LLM dependency. The formula, thresholds, and mappings are all
57
+ * explicit and auditable.
58
+ */
59
+ class RiskGate {
60
+ profiles = new Map();
61
+ stats = new Map();
62
+ thresholds;
63
+ constructor(thresholds = exports.DEFAULT_RISK_THRESHOLDS) {
64
+ this.thresholds = thresholds;
65
+ }
66
+ /** Register a risk profile for a tool */
67
+ registerProfile(profile) {
68
+ this.profiles.set(profile.tool, profile);
69
+ // Initialize stats if not already tracked
70
+ if (!this.stats.has(profile.tool)) {
71
+ const errorRate = profile.initialErrorRate ??
72
+ (profile.category ? (DEFAULT_ERROR_RATES[profile.category] ?? 0.05) : 0.05);
73
+ this.stats.set(profile.tool, {
74
+ totalCalls: 0,
75
+ failures: 0,
76
+ errorRate,
77
+ lastUpdated: Date.now(),
78
+ });
79
+ }
80
+ }
81
+ /** Register multiple profiles at once */
82
+ registerProfiles(profiles) {
83
+ profiles.forEach((p) => this.registerProfile(p));
84
+ }
85
+ /** Get all registered profiles */
86
+ getProfiles() {
87
+ return Array.from(this.profiles.values());
88
+ }
89
+ /** Check if a tool has a registered profile */
90
+ hasProfile(tool) {
91
+ return this.profiles.has(tool);
92
+ }
93
+ /**
94
+ * Compute the risk score for a tool call.
95
+ *
96
+ * If no profile is registered, returns a default moderate-risk score
97
+ * (auto-approve with notification).
98
+ */
99
+ evaluate(tool, _params) {
100
+ const profile = this.profiles.get(tool);
101
+ // Fallback for unregistered tools — content-based danger analysis
102
+ if (!profile) {
103
+ return this.evaluateUntracked(_params ?? {});
104
+ }
105
+ const impact = IMPACT_VALUES[profile.impact];
106
+ const reversibility = Math.min(1, Math.max(0, profile.reversibility));
107
+ const sensitivity = SENSITIVITY_VALUES[profile.sensitivity];
108
+ const stats = this.stats.get(profile.tool);
109
+ const errorRate = stats?.errorRate ?? 0.05;
110
+ const score = impact * (1 - reversibility) * sensitivity * (1 + errorRate);
111
+ const action = this.scoreToAction(score);
112
+ return {
113
+ score: Math.round(score * 100) / 100, // round to 2 decimal places
114
+ action,
115
+ dimensions: {
116
+ impact,
117
+ reversibility,
118
+ sensitivity,
119
+ errorRate: Math.round(errorRate * 1000) / 1000,
120
+ },
121
+ };
122
+ }
123
+ /**
124
+ * Evaluate risk for an unregistered tool by scanning params for danger patterns.
125
+ */
126
+ evaluateUntracked(params) {
127
+ const paramText = Object.values(params).join(' ');
128
+ for (const pattern of DANGER_PATTERNS) {
129
+ if (pattern.regex.test(paramText)) {
130
+ const impact = IMPACT_VALUES[pattern.impact];
131
+ const reversibility = Math.min(1, Math.max(0, pattern.reversibility));
132
+ const sensitivity = SENSITIVITY_VALUES[pattern.sensitivity];
133
+ const errorRate = DEFAULT_ERROR_RATES['write'] ?? 0.05;
134
+ const score = impact * (1 - reversibility) * sensitivity * (1 + errorRate);
135
+ let action;
136
+ if (score >= this.thresholds.deny)
137
+ action = 'deny';
138
+ else if (score >= this.thresholds.confirm)
139
+ action = 'confirm';
140
+ else if (score >= this.thresholds.notify)
141
+ action = 'notify';
142
+ else
143
+ action = 'auto';
144
+ return {
145
+ score: Math.round(score * 100) / 100,
146
+ action,
147
+ dimensions: { impact, reversibility, sensitivity, errorRate: Math.round(errorRate * 1000) / 1000 },
148
+ };
149
+ }
150
+ }
151
+ // No danger pattern matched — low risk
152
+ return {
153
+ score: 0.2,
154
+ action: 'auto',
155
+ dimensions: { impact: 1, reversibility: 1, sensitivity: 0, errorRate: 0 },
156
+ };
157
+ }
158
+ /** Record the outcome of a tool call to update stats */
159
+ recordOutcome(tool, success) {
160
+ const stats = this.stats.get(tool);
161
+ if (!stats)
162
+ return;
163
+ stats.totalCalls++;
164
+ if (!success)
165
+ stats.failures++;
166
+ stats.errorRate =
167
+ stats.totalCalls > 0 ? stats.failures / stats.totalCalls : 0;
168
+ stats.lastUpdated = Date.now();
169
+ }
170
+ /** Get tool statistics */
171
+ getStats(tool) {
172
+ return this.stats.get(tool);
173
+ }
174
+ /** Get all tool statistics */
175
+ getAllStats() {
176
+ return new Map(this.stats);
177
+ }
178
+ /** Update thresholds at runtime */
179
+ setThresholds(thresholds) {
180
+ this.thresholds = { ...this.thresholds, ...thresholds };
181
+ }
182
+ /** Get current thresholds */
183
+ getThresholds() {
184
+ return { ...this.thresholds };
185
+ }
186
+ /**
187
+ * Map a numeric risk score to the appropriate action.
188
+ */
189
+ scoreToAction(score) {
190
+ if (score <= this.thresholds.autoApprove)
191
+ return 'auto';
192
+ if (score <= this.thresholds.notify)
193
+ return 'notify';
194
+ if (score <= this.thresholds.confirm)
195
+ return 'confirm';
196
+ return 'deny';
197
+ }
198
+ }
199
+ exports.RiskGate = RiskGate;
200
+ //# sourceMappingURL=risk-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"risk-gate.js","sourceRoot":"","sources":["../../src/guard/risk-gate.ts"],"names":[],"mappings":";;;AAOA,MAAM,aAAa,GAAgC;IACjD,KAAK,EAAE,CAAC;IACR,SAAS,EAAE,CAAC;IACZ,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,EAAE;CACX,CAAC;AAOF,MAAM,kBAAkB,GAAqC;IAC3D,IAAI,EAAE,GAAG;IACT,GAAG,EAAE,GAAG;IACR,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,GAAG;IACT,QAAQ,EAAE,GAAG;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAA2B;IAClD,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,IAAI;CACd,CAAC;AAEF,+EAA+E;AAC/E,MAAM,eAAe,GAAw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C;IAED,0BAA0B;IAC1B,QAAQ,CAAC,IAAY;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,8BAA8B;IAC9B,WAAW;QACT,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,mCAAmC;IACnC,aAAa,CAAC,UAAmC;QAC/C,IAAI,CAAC,UAAU,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC;IAC1D,CAAC;IAED,6BAA6B;IAC7B,aAAa;QACX,OAAO,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,KAAa;QACjC,IAAI,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW;YAAE,OAAO,MAAM,CAAC;QACxD,IAAI,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM;YAAE,OAAO,QAAQ,CAAC;QACrD,IAAI,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QACvD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA3JD,4BA2JC"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Execution mode — from DESIGN.md §4.5
3
+ */
4
+ export type ExecutionMode = 'direct' | 'sandbox' | 'dry-run';
5
+ /**
6
+ * Network access policy for sandbox mode.
7
+ */
8
+ export type NetworkPolicy = 'none' | 'localhost' | 'whitelist';
9
+ /**
10
+ * Execution context configuration — full DESIGN.md §4.5 interface.
11
+ */
12
+ export interface ExecutionContext {
13
+ /** Execution mode */
14
+ mode: ExecutionMode;
15
+ /** Timeout in milliseconds */
16
+ timeoutMs: number;
17
+ /** Network policy (sandbox mode only) */
18
+ networkAccess?: NetworkPolicy;
19
+ /** Allowed network hosts (sandbox + whitelist mode only) */
20
+ networkWhitelist?: string[];
21
+ /** Writable paths (sandbox mode) */
22
+ writablePaths?: string[];
23
+ /** Read-only paths (sandbox mode) */
24
+ readonlyPaths?: string[];
25
+ /** Workspace root */
26
+ workspaceRoot: string;
27
+ /** Max output size before truncation */
28
+ maxOutputSize?: number;
29
+ /** Allowed tools in sandbox mode */
30
+ allowedTools?: string[];
31
+ /** Forbidden tools in any mode */
32
+ forbiddenTools?: string[];
33
+ }
34
+ /**
35
+ * Sandbox execution result.
36
+ */
37
+ export interface SandboxResult {
38
+ /** Execution outcome */
39
+ success: boolean;
40
+ /** Exit code (0 = success) */
41
+ exitCode: number;
42
+ /** stdout */
43
+ stdout: string;
44
+ /** stderr */
45
+ stderr: string;
46
+ /** Truncated flag */
47
+ truncated: boolean;
48
+ /** Error message if sandbox rejected */
49
+ sandboxRejectReason?: string;
50
+ /** Dry-run: what would have happened */
51
+ dryRunSummary?: string;
52
+ /** Execution time in ms */
53
+ durationMs: number;
54
+ }
55
+ /**
56
+ * Sandbox Violation types.
57
+ */
58
+ export declare enum SandboxViolation {
59
+ NETWORK_FORBIDDEN = "NETWORK_FORBIDDEN",
60
+ PATH_NOT_WRITABLE = "PATH_NOT_WRITABLE",
61
+ PATH_READONLY = "PATH_READONLY",
62
+ TOOL_FORBIDDEN = "TOOL_FORBIDDEN",
63
+ TOOL_NOT_ALLOWED = "TOOL_NOT_ALLOWED",
64
+ COMMAND_FORBIDDEN = "COMMAND_FORBIDDEN"
65
+ }
66
+ /**
67
+ * Sandbox Executor — controlled execution environment.
68
+ *
69
+ * Implements three execution modes from DESIGN.md §4.5:
70
+ * - direct: Execute in shared environment (default, no sandboxing)
71
+ * - sandbox: Restricted execution with network + filesystem policies
72
+ * - dry-run: Preview only, no actual execution
73
+ */
74
+ export declare class SandboxExecutor {
75
+ private config;
76
+ /** Forbidden shell commands (dangerous patterns) */
77
+ private static FORBIDDEN_COMMANDS;
78
+ constructor(config: ExecutionContext);
79
+ /**
80
+ * Validate and possibly reject a tool call before execution.
81
+ *
82
+ * @returns {SandboxResult} with sandboxRejectReason if rejected
83
+ */
84
+ validate(toolName: string, params: Record<string, unknown>): SandboxResult | null;
85
+ /**
86
+ * Execute a shell command in the configured mode.
87
+ */
88
+ execute(toolName: string, params: Record<string, unknown>): Promise<SandboxResult>;
89
+ /**
90
+ * Dry-run: return a summary of what would happen.
91
+ */
92
+ private dryRun;
93
+ /**
94
+ * Execute shell commands with sandbox policies.
95
+ */
96
+ private executeShell;
97
+ /**
98
+ * Build environment with sandbox network restrictions.
99
+ */
100
+ private buildSandboxEnv;
101
+ /**
102
+ * Validate a filesystem path against sandbox policies.
103
+ */
104
+ private validatePath;
105
+ /**
106
+ * Validate a shell command against forbidden patterns.
107
+ */
108
+ private validateCommand;
109
+ private isShellTool;
110
+ private isWriteTool;
111
+ }
112
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../src/guard/sandbox.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,WAAW,GAAG,WAAW,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qBAAqB;IACrB,IAAI,EAAE,aAAa,CAAC;IACpB,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,oCAAoC;IACpC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,qCAAqC;IACrC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,qBAAqB;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oCAAoC;I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