Skip to content

Commit 9eae43b

Browse files
authored
refactor(infra): move exec approvals into the shared SQLite state DB (#114063)
* refactor(infra): move exec approvals into the shared SQLite state DB Delete the file-runtime exec-approvals store (exec-approvals.json + .lock sidecar machinery) on both runtimes and make the reserved exec_approvals_config singleton row canonical. Doctor owns the one-time import with claim/verify/receipt discipline; runtime fails closed with a doctor instruction while un-migrated legacy state exists. The wire CAS contract, socket semantics, and gateway auth-token derivations are unchanged. Kills the #113929 lock-contention bug class structurally and nets around -2.9k lines. * fix(infra): green CI gates and retire file-era exec approvals tests Break the migration-type import cycle with a leaf contract, regenerate the plugin-SDK API and native i18n baselines for the intentional surface change, drop unused exports, and replace the macOS file-era approvals test suite with SQLite-backed behavior coverage per the obsolete-internals test policy. * chore: green max-lines ratchet, native i18n baseline, and unused-export scan
1 parent cd5a5ec commit 9eae43b

61 files changed

Lines changed: 3459 additions & 4441 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/.i18n/native-source.json‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32411,87 +32411,87 @@
3241132411
},
3241232412
{
3241332413
"kind": "conditional-branch",
32414-
"line": 15,
32414+
"line": 16,
3241532415
"path": "apps/macos/Sources/OpenClaw/ExecApprovals.swift",
3241632416
"source": "Allowlist",
3241732417
"surface": "apple",
3241832418
"id": "native.apple.3bed795cded1caa6"
3241932419
},
3242032420
{
3242132421
"kind": "conditional-branch",
32422-
"line": 42,
32422+
"line": 43,
3242332423
"path": "apps/macos/Sources/OpenClaw/ExecApprovals.swift",
3242432424
"source": "Deny",
3242532425
"surface": "apple",
3242632426
"id": "native.apple.aec1bd885ac9d40b"
3242732427
},
3242832428
{
3242932429
"kind": "conditional-branch",
32430-
"line": 44,
32430+
"line": 45,
3243132431
"path": "apps/macos/Sources/OpenClaw/ExecApprovals.swift",
3243232432
"source": "Always Allow",
3243332433
"surface": "apple",
3243432434
"id": "native.apple.0922ae2298cc7215"
3243532435
},
3243632436
{
3243732437
"kind": "conditional-branch",
32438-
"line": 87,
32438+
"line": 80,
3243932439
"path": "apps/macos/Sources/OpenClaw/ExecApprovals.swift",
3244032440
"source": "Never Ask",
3244132441
"surface": "apple",
3244232442
"id": "native.apple.feee9ce5c746096b"
3244332443
},
3244432444
{
3244532445
"kind": "conditional-branch",
32446-
"line": 88,
32446+
"line": 81,
3244732447
"path": "apps/macos/Sources/OpenClaw/ExecApprovals.swift",
3244832448
"source": "Ask on Allowlist Miss",
3244932449
"surface": "apple",
3245032450
"id": "native.apple.aa8b4e24f0bfb8b4"
3245132451
},
3245232452
{
3245332453
"kind": "conditional-branch",
32454-
"line": 89,
32454+
"line": 82,
3245532455
"path": "apps/macos/Sources/OpenClaw/ExecApprovals.swift",
3245632456
"source": "Always Ask",
3245732457
"surface": "apple",
3245832458
"id": "native.apple.6d4f37b9ae9027d3"
3245932459
},
3246032460
{
3246132461
"kind": "conditional-branch",
32462-
"line": 119,
32462+
"line": 112,
3246332463
"path": "apps/macos/Sources/OpenClaw/ExecApprovals.swift",
3246432464
"source": "Pattern cannot be empty.",
3246532465
"surface": "apple",
3246632466
"id": "native.apple.a46f0710e99df741"
3246732467
},
3246832468
{
3246932469
"kind": "conditional-branch",
32470-
"line": 121,
32470+
"line": 114,
3247132471
"path": "apps/macos/Sources/OpenClaw/ExecApprovals.swift",
3247232472
"source": "Path patterns only. Include '/', '~', or '\\'.",
3247332473
"surface": "apple",
3247432474
"id": "native.apple.e69fc6a151dd8879"
3247532475
},
3247632476
{
3247732477
"kind": "conditional-branch",
32478-
"line": 283,
32478+
"line": 170,
3247932479
"path": "apps/macos/Sources/OpenClaw/ExecApprovals.swift",
3248032480
"source": "This allowlist entry is inherited. Edit its owning scope and retry.",
3248132481
"surface": "apple",
3248232482
"id": "native.apple.5b9878c76d9a0995"
3248332483
},
3248432484
{
3248532485
"kind": "conditional-branch",
32486-
"line": 285,
32486+
"line": 172,
3248732487
"path": "apps/macos/Sources/OpenClaw/ExecApprovals.swift",
3248832488
"source": "Could not save exec approvals. Last known settings are shown; retry the change.",
3248932489
"surface": "apple",
3249032490
"id": "native.apple.511333a8588db7e2"
3249132491
},
3249232492
{
3249332493
"kind": "conditional-branch",
32494-
"line": 950,
32494+
"line": 802,
3249532495
"path": "apps/macos/Sources/OpenClaw/ExecApprovalsStore.swift",
3249632496
"source": "missing:\\(hash)",
3249732497
"surface": "apple",

‎apps/macos/Sources/OpenClaw/ExecApprovals.swift‎

Lines changed: 10 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import Foundation
2+
import OpenClawKit
23

3-
enum ExecSecurity: String, CaseIterable, Codable, Identifiable, Sendable {
4-
case deny
5-
case allowlist
6-
case full
7-
8-
var id: String {
9-
rawValue
10-
}
4+
typealias ExecSecurity = ExecApprovalsSecurity
5+
typealias ExecAsk = ExecApprovalsAsk
6+
typealias ExecAllowlistEntry = ExecApprovalsAllowlistEntry
7+
typealias ExecApprovalsDefaults = ExecApprovalsDefaultsDocument
8+
typealias ExecApprovalsAgent = ExecApprovalsAgentDocument
9+
typealias ExecApprovalsSocketConfig = ExecApprovalsSocketDocument
10+
typealias ExecApprovalsFile = ExecApprovalsDocument
1111

12+
extension ExecApprovalsSecurity {
1213
var title: String {
1314
switch self {
1415
case .deny: "Deny"
@@ -73,15 +74,7 @@ enum ExecApprovalQuickMode: String, CaseIterable, Identifiable {
7374
}
7475
}
7576

76-
enum ExecAsk: String, CaseIterable, Codable, Identifiable, Sendable {
77-
case off
78-
case onMiss = "on-miss"
79-
case always
80-
81-
var id: String {
82-
rawValue
83-
}
84-
77+
extension ExecApprovalsAsk {
8578
var title: String {
8679
switch self {
8780
case .off: "Never Ask"
@@ -134,80 +127,6 @@ struct ExecAllowlistRejectedEntry: Equatable {
134127
let reason: ExecAllowlistPatternValidationReason
135128
}
136129

137-
struct ExecAllowlistEntry: Codable, Hashable, Identifiable, Sendable {
138-
var id: String
139-
var pattern: String
140-
var source: String?
141-
var commandText: String?
142-
var argPattern: String?
143-
var lastUsedAt: Double?
144-
var lastUsedCommand: String?
145-
var lastResolvedPath: String?
146-
147-
init(
148-
id: String = UUID().uuidString,
149-
pattern: String,
150-
source: String? = nil,
151-
commandText: String? = nil,
152-
argPattern: String? = nil,
153-
lastUsedAt: Double? = nil,
154-
lastUsedCommand: String? = nil,
155-
lastResolvedPath: String? = nil)
156-
{
157-
self.id = id
158-
self.pattern = pattern
159-
self.source = source
160-
self.commandText = commandText
161-
self.argPattern = argPattern
162-
self.lastUsedAt = lastUsedAt
163-
self.lastUsedCommand = lastUsedCommand
164-
self.lastResolvedPath = lastResolvedPath
165-
}
166-
167-
private enum CodingKeys: String, CodingKey {
168-
case id
169-
case pattern
170-
case source
171-
case commandText
172-
case argPattern
173-
case lastUsedAt
174-
case lastUsedCommand
175-
case lastResolvedPath
176-
}
177-
178-
init(from decoder: Decoder) throws {
179-
if let container = try? decoder.singleValueContainer(),
180-
let legacyPattern = try? container.decode(String.self)
181-
{
182-
self.init(pattern: legacyPattern.trimmingCharacters(in: .whitespacesAndNewlines))
183-
return
184-
}
185-
let container = try decoder.container(keyedBy: CodingKeys.self)
186-
let decodedID = try container.decodeIfPresent(String.self, forKey: .id)
187-
let id = decodedID.flatMap { $0.isEmpty ? nil : $0 } ?? UUID().uuidString
188-
try self.init(
189-
id: id,
190-
pattern: container.decode(String.self, forKey: .pattern),
191-
source: container.decodeIfPresent(String.self, forKey: .source),
192-
commandText: container.decodeIfPresent(String.self, forKey: .commandText),
193-
argPattern: container.decodeIfPresent(String.self, forKey: .argPattern),
194-
lastUsedAt: container.decodeIfPresent(Double.self, forKey: .lastUsedAt),
195-
lastUsedCommand: container.decodeIfPresent(String.self, forKey: .lastUsedCommand),
196-
lastResolvedPath: container.decodeIfPresent(String.self, forKey: .lastResolvedPath))
197-
}
198-
199-
func encode(to encoder: Encoder) throws {
200-
var container = encoder.container(keyedBy: CodingKeys.self)
201-
try container.encode(self.id, forKey: .id)
202-
try container.encode(self.pattern, forKey: .pattern)
203-
try container.encodeIfPresent(self.source, forKey: .source)
204-
try container.encodeIfPresent(self.argPattern, forKey: .argPattern)
205-
try container.encodeIfPresent(self.lastUsedAt, forKey: .lastUsedAt)
206-
try container.encodeIfPresent(self.lastUsedCommand, forKey: .lastUsedCommand)
207-
try container.encodeIfPresent(self.lastResolvedPath, forKey: .lastResolvedPath)
208-
}
209-
}
210-
211130
struct ExecAllowlistUse: Sendable {
212131
let match: ExecAllowlistEntry
213132
let resolvedPath: String?
@@ -223,38 +142,6 @@ struct ExecAllowlistEntryMatchKey: Hashable, Sendable {
223142
}
224143
}
225144

226-
struct ExecApprovalsDefaults: Codable, Sendable {
227-
var security: ExecSecurity?
228-
var ask: ExecAsk?
229-
var askFallback: ExecSecurity?
230-
var autoAllowSkills: Bool?
231-
}
232-
233-
struct ExecApprovalsAgent: Codable, Sendable {
234-
var security: ExecSecurity?
235-
var ask: ExecAsk?
236-
var askFallback: ExecSecurity?
237-
var autoAllowSkills: Bool?
238-
var allowlist: [ExecAllowlistEntry]?
239-
240-
var isEmpty: Bool {
241-
self.security == nil && self.ask == nil && self.askFallback == nil && self
242-
.autoAllowSkills == nil && (self.allowlist?.isEmpty ?? true)
243-
}
244-
}
245-
246-
struct ExecApprovalsSocketConfig: Codable, Sendable {
247-
var path: String?
248-
var token: String?
249-
}
250-
251-
struct ExecApprovalsFile: Codable, Sendable {
252-
var version: Int
253-
var socket: ExecApprovalsSocketConfig?
254-
var defaults: ExecApprovalsDefaults?
255-
var agents: [String: ExecApprovalsAgent]?
256-
}
257-
258145
struct ExecApprovalsSnapshot: Codable, Sendable {
259146
var path: String
260147
var exists: Bool

0 commit comments

Comments
 (0)