|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text.Json.Serialization; |
| 4 | + |
| 5 | +namespace OpenClaw.Shared.ExecApprovals; |
| 6 | + |
| 7 | +// ── Config enums ────────────────────────────────────────────────────────────── |
| 8 | + |
| 9 | +public enum ExecSecurity |
| 10 | +{ |
| 11 | + Deny, |
| 12 | + Allowlist, |
| 13 | + Full, |
| 14 | +} |
| 15 | + |
| 16 | +public enum ExecAsk |
| 17 | +{ |
| 18 | + Off, |
| 19 | + OnMiss, |
| 20 | + Always, |
| 21 | + Deny, |
| 22 | +} |
| 23 | + |
| 24 | +public enum ExecApprovalDecision |
| 25 | +{ |
| 26 | + Allow, |
| 27 | + Deny, |
| 28 | + AllowOnce, |
| 29 | + AllowAlways, |
| 30 | +} |
| 31 | + |
| 32 | +// ── Allowlist contracts ─────────────────────────────────────────────────────── |
| 33 | + |
| 34 | +public sealed class ExecAllowlistEntry |
| 35 | +{ |
| 36 | + public Guid? Id { get; set; } |
| 37 | + public string? Pattern { get; set; } |
| 38 | + public double? LastUsedAt { get; set; } |
| 39 | + public string? LastUsedCommand { get; set; } |
| 40 | + public string? LastResolvedPath { get; set; } |
| 41 | +} |
| 42 | + |
| 43 | +// ── Persisted config contracts ──────────────────────────────────────────────── |
| 44 | + |
| 45 | +public sealed class ExecApprovalsSocketConfig |
| 46 | +{ |
| 47 | + public string? Path { get; set; } |
| 48 | + public string? Token { get; set; } |
| 49 | +} |
| 50 | + |
| 51 | +public sealed class ExecApprovalsDefaults |
| 52 | +{ |
| 53 | + public ExecSecurity? Security { get; set; } |
| 54 | + public ExecAsk? Ask { get; set; } |
| 55 | + public ExecAsk? AskFallback { get; set; } |
| 56 | + public bool? AutoAllowSkills { get; set; } |
| 57 | +} |
| 58 | + |
| 59 | +public sealed class ExecApprovalsAgent |
| 60 | +{ |
| 61 | + public ExecSecurity? Security { get; set; } |
| 62 | + public ExecAsk? Ask { get; set; } |
| 63 | + public ExecAsk? AskFallback { get; set; } |
| 64 | + public bool? AutoAllowSkills { get; set; } |
| 65 | + public List<ExecAllowlistEntry>? Allowlist { get; set; } |
| 66 | +} |
| 67 | + |
| 68 | +public sealed class ExecApprovalsFile |
| 69 | +{ |
| 70 | + public int? Version { get; set; } |
| 71 | + public ExecApprovalsSocketConfig? Socket { get; set; } |
| 72 | + public ExecApprovalsDefaults? Defaults { get; set; } |
| 73 | + public Dictionary<string, ExecApprovalsAgent>? Agents { get; set; } |
| 74 | +} |
| 75 | + |
| 76 | +// ── Resolved/runtime contracts (not serialized) ─────────────────────────────── |
| 77 | + |
| 78 | +public sealed class ExecApprovalsResolvedDefaults |
| 79 | +{ |
| 80 | + public ExecSecurity Security { get; init; } |
| 81 | + public ExecAsk Ask { get; init; } |
| 82 | + public ExecAsk AskFallback { get; init; } |
| 83 | + public bool AutoAllowSkills { get; init; } |
| 84 | +} |
| 85 | + |
| 86 | +public sealed class ExecApprovalsResolved |
| 87 | +{ |
| 88 | + public string AgentId { get; init; } = string.Empty; |
| 89 | + public ExecApprovalsResolvedDefaults Defaults { get; init; } = null!; |
| 90 | + public IReadOnlyList<ExecAllowlistEntry> Allowlist { get; init; } = []; |
| 91 | + public string? SocketToken { get; init; } |
| 92 | +} |
0 commit comments