@yuaone/core 0.1.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/LICENSE +663 -0
- package/README.md +15 -0
- package/dist/__tests__/context-manager.test.d.ts +6 -0
- package/dist/__tests__/context-manager.test.d.ts.map +1 -0
- package/dist/__tests__/context-manager.test.js +220 -0
- package/dist/__tests__/context-manager.test.js.map +1 -0
- package/dist/__tests__/governor.test.d.ts +6 -0
- package/dist/__tests__/governor.test.d.ts.map +1 -0
- package/dist/__tests__/governor.test.js +210 -0
- package/dist/__tests__/governor.test.js.map +1 -0
- package/dist/__tests__/model-router.test.d.ts +6 -0
- package/dist/__tests__/model-router.test.d.ts.map +1 -0
- package/dist/__tests__/model-router.test.js +329 -0
- package/dist/__tests__/model-router.test.js.map +1 -0
- package/dist/agent-logger.d.ts +384 -0
- package/dist/agent-logger.d.ts.map +1 -0
- package/dist/agent-logger.js +820 -0
- package/dist/agent-logger.js.map +1 -0
- package/dist/agent-loop.d.ts +163 -0
- package/dist/agent-loop.d.ts.map +1 -0
- package/dist/agent-loop.js +609 -0
- package/dist/agent-loop.js.map +1 -0
- package/dist/agent-modes.d.ts +85 -0
- package/dist/agent-modes.d.ts.map +1 -0
- package/dist/agent-modes.js +418 -0
- package/dist/agent-modes.js.map +1 -0
- package/dist/approval.d.ts +137 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +299 -0
- package/dist/approval.js.map +1 -0
- package/dist/async-completion-queue.d.ts +56 -0
- package/dist/async-completion-queue.d.ts.map +1 -0
- package/dist/async-completion-queue.js +77 -0
- package/dist/async-completion-queue.js.map +1 -0
- package/dist/auto-fix.d.ts +174 -0
- package/dist/auto-fix.d.ts.map +1 -0
- package/dist/auto-fix.js +319 -0
- package/dist/auto-fix.js.map +1 -0
- package/dist/codebase-context.d.ts +396 -0
- package/dist/codebase-context.d.ts.map +1 -0
- package/dist/codebase-context.js +1260 -0
- package/dist/codebase-context.js.map +1 -0
- package/dist/conflict-resolver.d.ts +191 -0
- package/dist/conflict-resolver.d.ts.map +1 -0
- package/dist/conflict-resolver.js +524 -0
- package/dist/conflict-resolver.js.map +1 -0
- package/dist/constants.d.ts +52 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +141 -0
- package/dist/constants.js.map +1 -0
- package/dist/context-budget.d.ts +435 -0
- package/dist/context-budget.d.ts.map +1 -0
- package/dist/context-budget.js +903 -0
- package/dist/context-budget.js.map +1 -0
- package/dist/context-compressor.d.ts +143 -0
- package/dist/context-compressor.d.ts.map +1 -0
- package/dist/context-compressor.js +511 -0
- package/dist/context-compressor.js.map +1 -0
- package/dist/context-manager.d.ts +112 -0
- package/dist/context-manager.d.ts.map +1 -0
- package/dist/context-manager.js +247 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/continuous-reflection.d.ts +267 -0
- package/dist/continuous-reflection.d.ts.map +1 -0
- package/dist/continuous-reflection.js +338 -0
- package/dist/continuous-reflection.js.map +1 -0
- package/dist/cross-file-refactor.d.ts +352 -0
- package/dist/cross-file-refactor.d.ts.map +1 -0
- package/dist/cross-file-refactor.js +1544 -0
- package/dist/cross-file-refactor.js.map +1 -0
- package/dist/dag-orchestrator.d.ts +138 -0
- package/dist/dag-orchestrator.d.ts.map +1 -0
- package/dist/dag-orchestrator.js +379 -0
- package/dist/dag-orchestrator.js.map +1 -0
- package/dist/debate-orchestrator.d.ts +301 -0
- package/dist/debate-orchestrator.d.ts.map +1 -0
- package/dist/debate-orchestrator.js +719 -0
- package/dist/debate-orchestrator.js.map +1 -0
- package/dist/dependency-analyzer.d.ts +113 -0
- package/dist/dependency-analyzer.d.ts.map +1 -0
- package/dist/dependency-analyzer.js +444 -0
- package/dist/dependency-analyzer.js.map +1 -0
- package/dist/design-loop.d.ts +59 -0
- package/dist/design-loop.d.ts.map +1 -0
- package/dist/design-loop.js +344 -0
- package/dist/design-loop.js.map +1 -0
- package/dist/doc-intelligence.d.ts +383 -0
- package/dist/doc-intelligence.d.ts.map +1 -0
- package/dist/doc-intelligence.js +1307 -0
- package/dist/doc-intelligence.js.map +1 -0
- package/dist/dynamic-role-generator.d.ts +76 -0
- package/dist/dynamic-role-generator.d.ts.map +1 -0
- package/dist/dynamic-role-generator.js +194 -0
- package/dist/dynamic-role-generator.js.map +1 -0
- package/dist/errors.d.ts +69 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +102 -0
- package/dist/errors.js.map +1 -0
- package/dist/event-bus.d.ts +159 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js +305 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/execution-engine.d.ts +425 -0
- package/dist/execution-engine.d.ts.map +1 -0
- package/dist/execution-engine.js +1555 -0
- package/dist/execution-engine.js.map +1 -0
- package/dist/git-intelligence.d.ts +306 -0
- package/dist/git-intelligence.d.ts.map +1 -0
- package/dist/git-intelligence.js +1099 -0
- package/dist/git-intelligence.js.map +1 -0
- package/dist/governor.d.ts +77 -0
- package/dist/governor.d.ts.map +1 -0
- package/dist/governor.js +161 -0
- package/dist/governor.js.map +1 -0
- package/dist/hierarchical-planner.d.ts +313 -0
- package/dist/hierarchical-planner.d.ts.map +1 -0
- package/dist/hierarchical-planner.js +981 -0
- package/dist/hierarchical-planner.js.map +1 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +123 -0
- package/dist/index.js.map +1 -0
- package/dist/intent-inference.d.ts +103 -0
- package/dist/intent-inference.d.ts.map +1 -0
- package/dist/intent-inference.js +605 -0
- package/dist/intent-inference.js.map +1 -0
- package/dist/interrupt-manager.d.ts +143 -0
- package/dist/interrupt-manager.d.ts.map +1 -0
- package/dist/interrupt-manager.js +196 -0
- package/dist/interrupt-manager.js.map +1 -0
- package/dist/kernel.d.ts +564 -0
- package/dist/kernel.d.ts.map +1 -0
- package/dist/kernel.js +1419 -0
- package/dist/kernel.js.map +1 -0
- package/dist/language-support.d.ts +232 -0
- package/dist/language-support.d.ts.map +1 -0
- package/dist/language-support.js +1134 -0
- package/dist/language-support.js.map +1 -0
- package/dist/llm-client.d.ts +82 -0
- package/dist/llm-client.d.ts.map +1 -0
- package/dist/llm-client.js +475 -0
- package/dist/llm-client.js.map +1 -0
- package/dist/mcp-client.d.ts +232 -0
- package/dist/mcp-client.d.ts.map +1 -0
- package/dist/mcp-client.js +718 -0
- package/dist/mcp-client.js.map +1 -0
- package/dist/memory-manager.d.ts +200 -0
- package/dist/memory-manager.d.ts.map +1 -0
- package/dist/memory-manager.js +568 -0
- package/dist/memory-manager.js.map +1 -0
- package/dist/memory.d.ts +87 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +341 -0
- package/dist/memory.js.map +1 -0
- package/dist/model-router.d.ts +245 -0
- package/dist/model-router.d.ts.map +1 -0
- package/dist/model-router.js +632 -0
- package/dist/model-router.js.map +1 -0
- package/dist/parallel-executor.d.ts +125 -0
- package/dist/parallel-executor.d.ts.map +1 -0
- package/dist/parallel-executor.js +201 -0
- package/dist/parallel-executor.js.map +1 -0
- package/dist/perf-optimizer.d.ts +212 -0
- package/dist/perf-optimizer.d.ts.map +1 -0
- package/dist/perf-optimizer.js +721 -0
- package/dist/perf-optimizer.js.map +1 -0
- package/dist/persona.d.ts +305 -0
- package/dist/persona.d.ts.map +1 -0
- package/dist/persona.js +887 -0
- package/dist/persona.js.map +1 -0
- package/dist/planner.d.ts +70 -0
- package/dist/planner.d.ts.map +1 -0
- package/dist/planner.js +264 -0
- package/dist/planner.js.map +1 -0
- package/dist/qa-pipeline.d.ts +365 -0
- package/dist/qa-pipeline.d.ts.map +1 -0
- package/dist/qa-pipeline.js +1352 -0
- package/dist/qa-pipeline.js.map +1 -0
- package/dist/reasoning-adapter.d.ts +116 -0
- package/dist/reasoning-adapter.d.ts.map +1 -0
- package/dist/reasoning-adapter.js +187 -0
- package/dist/reasoning-adapter.js.map +1 -0
- package/dist/role-registry.d.ts +55 -0
- package/dist/role-registry.d.ts.map +1 -0
- package/dist/role-registry.js +192 -0
- package/dist/role-registry.js.map +1 -0
- package/dist/sandbox-tiers.d.ts +327 -0
- package/dist/sandbox-tiers.d.ts.map +1 -0
- package/dist/sandbox-tiers.js +928 -0
- package/dist/sandbox-tiers.js.map +1 -0
- package/dist/security-scanner.d.ts +222 -0
- package/dist/security-scanner.d.ts.map +1 -0
- package/dist/security-scanner.js +1129 -0
- package/dist/security-scanner.js.map +1 -0
- package/dist/security.d.ts +93 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +393 -0
- package/dist/security.js.map +1 -0
- package/dist/self-reflection.d.ts +397 -0
- package/dist/self-reflection.d.ts.map +1 -0
- package/dist/self-reflection.js +908 -0
- package/dist/self-reflection.js.map +1 -0
- package/dist/session-persistence.d.ts +191 -0
- package/dist/session-persistence.d.ts.map +1 -0
- package/dist/session-persistence.js +395 -0
- package/dist/session-persistence.js.map +1 -0
- package/dist/speculative-executor.d.ts +210 -0
- package/dist/speculative-executor.d.ts.map +1 -0
- package/dist/speculative-executor.js +618 -0
- package/dist/speculative-executor.js.map +1 -0
- package/dist/state-machine.d.ts +289 -0
- package/dist/state-machine.d.ts.map +1 -0
- package/dist/state-machine.js +695 -0
- package/dist/state-machine.js.map +1 -0
- package/dist/sub-agent.d.ts +177 -0
- package/dist/sub-agent.d.ts.map +1 -0
- package/dist/sub-agent.js +303 -0
- package/dist/sub-agent.js.map +1 -0
- package/dist/system-prompt.d.ts +26 -0
- package/dist/system-prompt.d.ts.map +1 -0
- package/dist/system-prompt.js +84 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/test-intelligence.d.ts +439 -0
- package/dist/test-intelligence.d.ts.map +1 -0
- package/dist/test-intelligence.js +1165 -0
- package/dist/test-intelligence.js.map +1 -0
- package/dist/types.d.ts +632 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/vector-index.d.ts +314 -0
- package/dist/vector-index.d.ts.map +1 -0
- package/dist/vector-index.js +618 -0
- package/dist/vector-index.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"role-registry.js","sourceRoot":"","sources":["../src/role-registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAsBH,0CAA0C;AAE1C,MAAM,YAAY,GAAuC;IACvD,YAAY,EAAE;QACZ,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,aAAa;QACpB,aAAa,EAAE,EAAE;QACjB,YAAY,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC;QAChC,QAAQ,EAAE,CAAC;QACX,oBAAoB,EAAE;YACpB,2BAA2B;YAC3B,iGAAiG;YACjG,uFAAuF;YACvF,EAAE;YACF,kBAAkB;YAClB,WAAW;SACZ,CAAC,IAAI,CAAC,IAAI,CAAC;KACb;IAED,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,eAAe;QACtB,aAAa,EAAE,EAAE;QACjB,YAAY,EAAE;YACZ,WAAW;YACX,YAAY;YACZ,WAAW;YACX,YAAY;YACZ,MAAM;YACN,MAAM;YACN,SAAS;YACT,UAAU;SACX;QACD,QAAQ,EAAE,CAAC;QACX,oBAAoB,EAAE;YACpB,wBAAwB;YACxB,+CAA+C;YAC/C,4FAA4F;YAC5F,4DAA4D;YAC5D,EAAE;YACF,kBAAkB;YAClB,WAAW;SACZ,CAAC,IAAI,CAAC,IAAI,CAAC;KACb;IAED,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,YAAY;QACnB,aAAa,EAAE,EAAE;QACjB,YAAY,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC;QACrE,QAAQ,EAAE,CAAC;QACX,oBAAoB,EAAE;YACpB,2BAA2B;YAC3B,mDAAmD;YACnD,qFAAqF;YACrF,wFAAwF;YACxF,gDAAgD;YAChD,EAAE;YACF,kBAAkB;YAClB,WAAW;SACZ,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AO,MAAM,CAAC,oBAAoB,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC;CACF"}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module sandbox-tiers
|
|
3
|
+
* @description YUAN Agent Sandbox Execution Tiers (T0–T4).
|
|
4
|
+
*
|
|
5
|
+
* 5 levels of isolation based on task risk level:
|
|
6
|
+
* - T0: Read-Only — file read, grep, glob only
|
|
7
|
+
* - T1: Write-Restricted — T0 + specific file writes, no network
|
|
8
|
+
* - T2: Project-Scoped — full project read/write, limited shell
|
|
9
|
+
* - T3: Build-Enabled — T2 + npm/pnpm, localhost network
|
|
10
|
+
* - T4: Full-Network — T3 + external network (allowlist)
|
|
11
|
+
*
|
|
12
|
+
* The SandboxManager auto-selects a tier based on requested tools,
|
|
13
|
+
* target files, and shell commands, then validates every action
|
|
14
|
+
* against the tier's policy before allowing execution.
|
|
15
|
+
*/
|
|
16
|
+
import { EventEmitter } from "node:events";
|
|
17
|
+
/** Sandbox isolation tier (0 = most restrictive, 4 = least restrictive) */
|
|
18
|
+
export type SandboxTier = 0 | 1 | 2 | 3 | 4;
|
|
19
|
+
/** Policy definition for a given sandbox tier */
|
|
20
|
+
export interface TierPolicy {
|
|
21
|
+
/** Tier level */
|
|
22
|
+
tier: SandboxTier;
|
|
23
|
+
/** Human-readable name */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Tier description */
|
|
26
|
+
description: string;
|
|
27
|
+
/** Whether file reads are allowed */
|
|
28
|
+
fileRead: boolean;
|
|
29
|
+
/** Whether file writes are allowed */
|
|
30
|
+
fileWrite: boolean;
|
|
31
|
+
/** Whether file deletes are allowed */
|
|
32
|
+
fileDelete: boolean;
|
|
33
|
+
/** Glob patterns for allowed write paths (empty = all in project) */
|
|
34
|
+
allowedWritePaths: string[];
|
|
35
|
+
/** Glob patterns that are always blocked for writes */
|
|
36
|
+
blockedWritePaths: string[];
|
|
37
|
+
/** Whether shell execution is allowed */
|
|
38
|
+
shellExec: boolean;
|
|
39
|
+
/** Allowed commands (empty = none, ["*"] = all) */
|
|
40
|
+
allowedCommands: string[];
|
|
41
|
+
/** Commands that are always blocked */
|
|
42
|
+
blockedCommands: string[];
|
|
43
|
+
/** Maximum shell execution time (ms) */
|
|
44
|
+
maxExecTime: number;
|
|
45
|
+
/** Whether network access is allowed */
|
|
46
|
+
networkAccess: boolean;
|
|
47
|
+
/** Allowed network hosts (empty = none) */
|
|
48
|
+
allowedHosts: string[];
|
|
49
|
+
/** Blocked network hosts */
|
|
50
|
+
blockedHosts: string[];
|
|
51
|
+
/** Maximum file size in bytes */
|
|
52
|
+
maxFileSize: number;
|
|
53
|
+
/** Maximum file writes per session */
|
|
54
|
+
maxTotalWrites: number;
|
|
55
|
+
/** Maximum shell executions per session */
|
|
56
|
+
maxShellCalls: number;
|
|
57
|
+
}
|
|
58
|
+
/** Result of automatic tier selection */
|
|
59
|
+
export interface SandboxDecision {
|
|
60
|
+
/** Selected tier */
|
|
61
|
+
tier: SandboxTier;
|
|
62
|
+
/** Human-readable reason for the selection */
|
|
63
|
+
reason: string;
|
|
64
|
+
/** Factors that influenced the decision */
|
|
65
|
+
factors: string[];
|
|
66
|
+
/** Whether the user can override to a higher tier */
|
|
67
|
+
overrideable: boolean;
|
|
68
|
+
}
|
|
69
|
+
/** Record of a sandbox policy violation */
|
|
70
|
+
export interface SandboxViolation {
|
|
71
|
+
/** Tier at the time of violation */
|
|
72
|
+
tier: SandboxTier;
|
|
73
|
+
/** What action was attempted */
|
|
74
|
+
action: string;
|
|
75
|
+
/** The resource involved (file path, command, host) */
|
|
76
|
+
resource: string;
|
|
77
|
+
/** Which rule was violated */
|
|
78
|
+
rule: string;
|
|
79
|
+
/** When the violation occurred (epoch ms) */
|
|
80
|
+
timestamp: number;
|
|
81
|
+
/** Whether the action was blocked (true) or just warned (false) */
|
|
82
|
+
blocked: boolean;
|
|
83
|
+
}
|
|
84
|
+
/** Configuration for the SandboxManager */
|
|
85
|
+
export interface SandboxConfig {
|
|
86
|
+
/** Project root directory */
|
|
87
|
+
projectPath: string;
|
|
88
|
+
/** Default tier for new sessions (default: 2) */
|
|
89
|
+
defaultTier?: SandboxTier;
|
|
90
|
+
/** Maximum allowed tier (default: 3) */
|
|
91
|
+
maxTier?: SandboxTier;
|
|
92
|
+
/** Auto-escalate tier when needed (default: false) */
|
|
93
|
+
enableAutoEscalation?: boolean;
|
|
94
|
+
/** Log all sandbox checks (default: true) */
|
|
95
|
+
auditLog?: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** Runtime state of the sandbox */
|
|
98
|
+
export interface SandboxState {
|
|
99
|
+
/** Current active tier */
|
|
100
|
+
currentTier: SandboxTier;
|
|
101
|
+
/** Session ID */
|
|
102
|
+
sessionId: string;
|
|
103
|
+
/** Number of file writes performed */
|
|
104
|
+
writeCount: number;
|
|
105
|
+
/** Number of shell executions performed */
|
|
106
|
+
shellCount: number;
|
|
107
|
+
/** History of policy violations */
|
|
108
|
+
violations: SandboxViolation[];
|
|
109
|
+
/** History of tier escalations */
|
|
110
|
+
escalationHistory: {
|
|
111
|
+
from: SandboxTier;
|
|
112
|
+
to: SandboxTier;
|
|
113
|
+
reason: string;
|
|
114
|
+
timestamp: number;
|
|
115
|
+
}[];
|
|
116
|
+
}
|
|
117
|
+
/** Events emitted by SandboxManager */
|
|
118
|
+
export interface SandboxManagerEvents {
|
|
119
|
+
"tier:changed": (prev: SandboxTier, next: SandboxTier, reason: string) => void;
|
|
120
|
+
"violation:blocked": (violation: SandboxViolation) => void;
|
|
121
|
+
"violation:warned": (violation: SandboxViolation) => void;
|
|
122
|
+
escalation: (from: SandboxTier, to: SandboxTier, reason: string) => void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* SandboxManager — manages execution isolation tiers for the YUAN agent.
|
|
126
|
+
*
|
|
127
|
+
* Provides 5 tiers of isolation (T0–T4), auto-selects the appropriate tier
|
|
128
|
+
* based on requested tools and commands, and validates every action against
|
|
129
|
+
* the active tier's policy before allowing execution.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* const sandbox = new SandboxManager({ projectPath: "/my/project" });
|
|
134
|
+
*
|
|
135
|
+
* // Auto-select tier
|
|
136
|
+
* const decision = sandbox.selectTier(["file_read", "file_write"], ["src/app.ts"]);
|
|
137
|
+
* // => { tier: 1, reason: "file write required", ... }
|
|
138
|
+
*
|
|
139
|
+
* // Validate actions
|
|
140
|
+
* const { allowed } = sandbox.canWriteFile("src/app.ts");
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare class SandboxManager extends EventEmitter {
|
|
144
|
+
private config;
|
|
145
|
+
private tiers;
|
|
146
|
+
private state;
|
|
147
|
+
constructor(config: SandboxConfig);
|
|
148
|
+
/**
|
|
149
|
+
* Auto-select the appropriate sandbox tier based on requested tools,
|
|
150
|
+
* target files, and shell commands.
|
|
151
|
+
*
|
|
152
|
+
* @param tools - List of tool names that will be used
|
|
153
|
+
* @param targetFiles - List of file paths that may be modified
|
|
154
|
+
* @param shellCommands - Optional list of shell commands to execute
|
|
155
|
+
* @returns Decision with selected tier, reason, and influencing factors
|
|
156
|
+
*/
|
|
157
|
+
selectTier(tools: string[], targetFiles: string[], shellCommands?: string[]): SandboxDecision;
|
|
158
|
+
/**
|
|
159
|
+
* Manually set the sandbox tier.
|
|
160
|
+
*
|
|
161
|
+
* @param tier - Target tier level
|
|
162
|
+
* @param reason - Reason for the tier change
|
|
163
|
+
* @throws If tier exceeds maxTier
|
|
164
|
+
*/
|
|
165
|
+
setTier(tier: SandboxTier, reason: string): void;
|
|
166
|
+
/**
|
|
167
|
+
* Escalate to the next higher tier.
|
|
168
|
+
*
|
|
169
|
+
* @param reason - Why escalation is needed
|
|
170
|
+
* @returns true if escalation succeeded, false if already at maxTier
|
|
171
|
+
*/
|
|
172
|
+
escalate(reason: string): boolean;
|
|
173
|
+
/** Get the current active tier */
|
|
174
|
+
getCurrentTier(): SandboxTier;
|
|
175
|
+
/**
|
|
176
|
+
* Get the policy for a specific tier, or the current tier if omitted.
|
|
177
|
+
*
|
|
178
|
+
* @param tier - Tier to get policy for (defaults to current)
|
|
179
|
+
*/
|
|
180
|
+
getTierPolicy(tier?: SandboxTier): TierPolicy;
|
|
181
|
+
/**
|
|
182
|
+
* Check if reading a file is allowed under the current tier.
|
|
183
|
+
*
|
|
184
|
+
* @param filePath - Absolute or relative file path
|
|
185
|
+
* @returns true if the read is allowed
|
|
186
|
+
*/
|
|
187
|
+
canReadFile(filePath: string): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Check if writing a file is allowed under the current tier.
|
|
190
|
+
*
|
|
191
|
+
* @param filePath - Absolute or relative file path
|
|
192
|
+
* @returns Object with allowed status and optional reason
|
|
193
|
+
*/
|
|
194
|
+
canWriteFile(filePath: string): {
|
|
195
|
+
allowed: boolean;
|
|
196
|
+
reason?: string;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Check if writing a file would be allowed WITHOUT incrementing counters.
|
|
200
|
+
* Use this for preview/validation — unlike canWriteFile, it has no side effects.
|
|
201
|
+
*/
|
|
202
|
+
checkWriteFile(filePath: string): {
|
|
203
|
+
allowed: boolean;
|
|
204
|
+
reason?: string;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Check if deleting a file is allowed under the current tier.
|
|
208
|
+
*
|
|
209
|
+
* @param filePath - Absolute or relative file path
|
|
210
|
+
* @returns Object with allowed status and optional reason
|
|
211
|
+
*/
|
|
212
|
+
canDeleteFile(filePath: string): {
|
|
213
|
+
allowed: boolean;
|
|
214
|
+
reason?: string;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Check if a shell command is allowed under the current tier.
|
|
218
|
+
*
|
|
219
|
+
* @param command - The command string (e.g. "tsc --noEmit")
|
|
220
|
+
* @param args - Optional additional arguments
|
|
221
|
+
* @returns Object with allowed status and optional reason
|
|
222
|
+
*/
|
|
223
|
+
canExecuteShell(command: string, args?: string[]): {
|
|
224
|
+
allowed: boolean;
|
|
225
|
+
reason?: string;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Check if a network request to a specific host is allowed.
|
|
229
|
+
*
|
|
230
|
+
* @param host - The hostname to check
|
|
231
|
+
* @returns Object with allowed status and optional reason
|
|
232
|
+
*/
|
|
233
|
+
canAccessNetwork(host: string): {
|
|
234
|
+
allowed: boolean;
|
|
235
|
+
reason?: string;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Validate a tool call against the current tier's policy.
|
|
239
|
+
*
|
|
240
|
+
* @param toolName - Name of the tool being called
|
|
241
|
+
* @param input - Tool input parameters
|
|
242
|
+
* @returns Object with allowed status and list of violations
|
|
243
|
+
*/
|
|
244
|
+
validateToolCall(toolName: string, input: Record<string, unknown>): {
|
|
245
|
+
allowed: boolean;
|
|
246
|
+
violations: string[];
|
|
247
|
+
};
|
|
248
|
+
/** Get all recorded violations */
|
|
249
|
+
getViolations(): SandboxViolation[];
|
|
250
|
+
/** Get current sandbox state (readonly snapshot) */
|
|
251
|
+
getState(): Readonly<SandboxState>;
|
|
252
|
+
/**
|
|
253
|
+
* Reset counters for a new session.
|
|
254
|
+
*
|
|
255
|
+
* @param sessionId - New session identifier
|
|
256
|
+
*/
|
|
257
|
+
reset(sessionId: string): void;
|
|
258
|
+
/**
|
|
259
|
+
* Build the default tier policies (T0–T4).
|
|
260
|
+
*
|
|
261
|
+
* @returns Map of tier level to policy definition
|
|
262
|
+
*/
|
|
263
|
+
private buildDefaultTiers;
|
|
264
|
+
/**
|
|
265
|
+
* Check if a relative path matches any of the given glob patterns.
|
|
266
|
+
* Uses a simplified glob matcher (supports `**`, `*`, and `?`).
|
|
267
|
+
*
|
|
268
|
+
* @param relativePath - Path relative to the project root
|
|
269
|
+
* @param patterns - Glob patterns to match against
|
|
270
|
+
* @returns true if the path matches any pattern
|
|
271
|
+
*/
|
|
272
|
+
private matchesPattern;
|
|
273
|
+
/**
|
|
274
|
+
* Simple glob matcher supporting `**` (any path segments), `*` (any chars
|
|
275
|
+
* within a segment), and `?` (single char).
|
|
276
|
+
*
|
|
277
|
+
* @param str - String to test
|
|
278
|
+
* @param pattern - Glob pattern
|
|
279
|
+
* @returns true if the string matches the pattern
|
|
280
|
+
*/
|
|
281
|
+
private globMatch;
|
|
282
|
+
/**
|
|
283
|
+
* Normalize and resolve a file path to an absolute path.
|
|
284
|
+
*
|
|
285
|
+
* @param filePath - The file path to normalize
|
|
286
|
+
* @returns Absolute resolved path
|
|
287
|
+
*/
|
|
288
|
+
private normalizePath;
|
|
289
|
+
/**
|
|
290
|
+
* Convert an absolute path to a project-relative path.
|
|
291
|
+
*
|
|
292
|
+
* @param absolutePath - Absolute file path
|
|
293
|
+
* @returns Path relative to the project root
|
|
294
|
+
*/
|
|
295
|
+
private toRelative;
|
|
296
|
+
/**
|
|
297
|
+
* Record a sandbox violation and emit the appropriate event.
|
|
298
|
+
*
|
|
299
|
+
* @param action - What action was attempted
|
|
300
|
+
* @param resource - The resource involved
|
|
301
|
+
* @param rule - Which rule was violated
|
|
302
|
+
* @param blocked - Whether the action was blocked
|
|
303
|
+
*/
|
|
304
|
+
private recordViolation;
|
|
305
|
+
/**
|
|
306
|
+
* Extract the base command name from a full command string.
|
|
307
|
+
*
|
|
308
|
+
* @param command - Full command string (e.g. "pnpm install lodash")
|
|
309
|
+
* @returns The first token / executable name (e.g. "pnpm")
|
|
310
|
+
*/
|
|
311
|
+
private extractCommand;
|
|
312
|
+
/**
|
|
313
|
+
* Check if a command is a build-related command.
|
|
314
|
+
*
|
|
315
|
+
* @param command - The extracted command name
|
|
316
|
+
* @returns true if it's a build command
|
|
317
|
+
*/
|
|
318
|
+
private isBuildCommand;
|
|
319
|
+
/**
|
|
320
|
+
* Check if a command is a network-related command.
|
|
321
|
+
*
|
|
322
|
+
* @param command - The extracted command name
|
|
323
|
+
* @returns true if it requires network access
|
|
324
|
+
*/
|
|
325
|
+
private isNetworkCommand;
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=sandbox-tiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-tiers.d.ts","sourceRoot":"","sources":["../src/sandbox-tiers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,2EAA2E;AAC3E,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE5C,iDAAiD;AACjD,MAAM,WAAW,UAAU;IACzB,iBAAiB;IACjB,IAAI,EAAE,WAAW,CAAC;IAClB,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,WAAW,EAAE,MAAM,CAAC;IAGpB,qCAAqC;IACrC,QAAQ,EAAE,OAAO,CAAC;IAClB,sCAAsC;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,uCAAuC;IACvC,UAAU,EAAE,OAAO,CAAC;IACpB,qEAAqE;IACrE,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,uDAAuD;IACvD,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAG5B,yCAAyC;IACzC,SAAS,EAAE,OAAO,CAAC;IACnB,mDAAmD;IACnD,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,uCAAuC;IACvC,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IAGpB,wCAAwC;IACxC,aAAa,EAAE,OAAO,CAAC;IACvB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,4BAA4B;IAC5B,YAAY,EAAE,MAAM,EAAE,CAAC;IAGvB,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,2CAA2C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