Skip to content

Commit cb84dc7

Browse files
authored
feat(control-ui): approval attention chip + approval history page (#108776)
Adds the sidebar approval attention chip and a dedicated approval history page backed by the new approval.history gateway RPC (30-day retention window). Extracts buildSidebarAttentionItems into its own module so the Lit component consumes it as a real cross-module dependency, and wires the strict i18n catalog for the new strings (fallbacks=0).
1 parent b6e90cb commit cb84dc7

95 files changed

Lines changed: 3160 additions & 1405 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/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ enum class GatewayMethod(
378378
MigrationsMemoryPlan("migrations.memory.plan"),
379379
MigrationsMemoryApply("migrations.memory.apply"),
380380
UiCommand("ui.command"),
381+
ApprovalHistory("approval.history"),
381382
}
382383

383384
enum class GatewayEvent(

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11629,6 +11629,8 @@ public struct AllowedApprovalSnapshot: Codable, Sendable {
1162911629
public let expiresatms: Int
1163011630
public let presentation: ApprovalPresentation
1163111631
public let resolvedatms: Int
11632+
public let source: [String: AnyCodable]?
11633+
public let resolver: [String: AnyCodable]?
1163211634
public let status: String
1163311635
public let decision: ApprovalAllowDecision
1163411636
public let reason: ApprovalAllowedReason
@@ -11640,6 +11642,8 @@ public struct AllowedApprovalSnapshot: Codable, Sendable {
1164011642
expiresatms: Int,
1164111643
presentation: ApprovalPresentation,
1164211644
resolvedatms: Int,
11645+
source: [String: AnyCodable]? = nil,
11646+
resolver: [String: AnyCodable]? = nil,
1164311647
status: String,
1164411648
decision: ApprovalAllowDecision,
1164511649
reason: ApprovalAllowedReason)
@@ -11650,6 +11654,8 @@ public struct AllowedApprovalSnapshot: Codable, Sendable {
1165011654
self.expiresatms = expiresatms
1165111655
self.presentation = presentation
1165211656
self.resolvedatms = resolvedatms
11657+
self.source = source
11658+
self.resolver = resolver
1165311659
self.status = status
1165411660
self.decision = decision
1165511661
self.reason = reason
@@ -11662,6 +11668,8 @@ public struct AllowedApprovalSnapshot: Codable, Sendable {
1166211668
case expiresatms = "expiresAtMs"
1166311669
case presentation
1166411670
case resolvedatms = "resolvedAtMs"
11671+
case source
11672+
case resolver
1166511673
case status
1166611674
case decision
1166711675
case reason
@@ -11675,6 +11683,8 @@ public struct DeniedApprovalSnapshot: Codable, Sendable {
1167511683
public let expiresatms: Int
1167611684
public let presentation: ApprovalPresentation
1167711685
public let resolvedatms: Int
11686+
public let source: [String: AnyCodable]?
11687+
public let resolver: [String: AnyCodable]?
1167811688
public let status: String
1167911689
public let decision: String
1168011690
public let reason: ApprovalDeniedReason
@@ -11686,6 +11696,8 @@ public struct DeniedApprovalSnapshot: Codable, Sendable {
1168611696
expiresatms: Int,
1168711697
presentation: ApprovalPresentation,
1168811698
resolvedatms: Int,
11699+
source: [String: AnyCodable]? = nil,
11700+
resolver: [String: AnyCodable]? = nil,
1168911701
status: String,
1169011702
decision: String,
1169111703
reason: ApprovalDeniedReason)
@@ -11696,6 +11708,8 @@ public struct DeniedApprovalSnapshot: Codable, Sendable {
1169611708
self.expiresatms = expiresatms
1169711709
self.presentation = presentation
1169811710
self.resolvedatms = resolvedatms
11711+
self.source = source
11712+
self.resolver = resolver
1169911713
self.status = status
1170011714
self.decision = decision
1170111715
self.reason = reason
@@ -11708,6 +11722,8 @@ public struct DeniedApprovalSnapshot: Codable, Sendable {
1170811722
case expiresatms = "expiresAtMs"
1170911723
case presentation
1171011724
case resolvedatms = "resolvedAtMs"
11725+
case source
11726+
case resolver
1171111727
case status
1171211728
case decision
1171311729
case reason
@@ -11721,6 +11737,8 @@ public struct ExpiredApprovalSnapshot: Codable, Sendable {
1172111737
public let expiresatms: Int
1172211738
public let presentation: ApprovalPresentation
1172311739
public let resolvedatms: Int
11740+
public let source: [String: AnyCodable]?
11741+
public let resolver: [String: AnyCodable]?
1172411742
public let status: String
1172511743
public let reason: ApprovalExpiredReason
1172611744

@@ -11731,6 +11749,8 @@ public struct ExpiredApprovalSnapshot: Codable, Sendable {
1173111749
expiresatms: Int,
1173211750
presentation: ApprovalPresentation,
1173311751
resolvedatms: Int,
11752+
source: [String: AnyCodable]? = nil,
11753+
resolver: [String: AnyCodable]? = nil,
1173411754
status: String,
1173511755
reason: ApprovalExpiredReason)
1173611756
{
@@ -11740,6 +11760,8 @@ public struct ExpiredApprovalSnapshot: Codable, Sendable {
1174011760
self.expiresatms = expiresatms
1174111761
self.presentation = presentation
1174211762
self.resolvedatms = resolvedatms
11763+
self.source = source
11764+
self.resolver = resolver
1174311765
self.status = status
1174411766
self.reason = reason
1174511767
}
@@ -11751,6 +11773,8 @@ public struct ExpiredApprovalSnapshot: Codable, Sendable {
1175111773
case expiresatms = "expiresAtMs"
1175211774
case presentation
1175311775
case resolvedatms = "resolvedAtMs"
11776+
case source
11777+
case resolver
1175411778
case status
1175511779
case reason
1175611780
}
@@ -11763,6 +11787,8 @@ public struct CancelledApprovalSnapshot: Codable, Sendable {
1176311787
public let expiresatms: Int
1176411788
public let presentation: ApprovalPresentation
1176511789
public let resolvedatms: Int
11790+
public let source: [String: AnyCodable]?
11791+
public let resolver: [String: AnyCodable]?
1176611792
public let status: String
1176711793
public let reason: ApprovalCancelledReason
1176811794

@@ -11773,6 +11799,8 @@ public struct CancelledApprovalSnapshot: Codable, Sendable {
1177311799
expiresatms: Int,
1177411800
presentation: ApprovalPresentation,
1177511801
resolvedatms: Int,
11802+
source: [String: AnyCodable]? = nil,
11803+
resolver: [String: AnyCodable]? = nil,
1177611804
status: String,
1177711805
reason: ApprovalCancelledReason)
1177811806
{
@@ -11782,6 +11810,8 @@ public struct CancelledApprovalSnapshot: Codable, Sendable {
1178211810
self.expiresatms = expiresatms
1178311811
self.presentation = presentation
1178411812
self.resolvedatms = resolvedatms
11813+
self.source = source
11814+
self.resolver = resolver
1178511815
self.status = status
1178611816
self.reason = reason
1178711817
}
@@ -11793,6 +11823,8 @@ public struct CancelledApprovalSnapshot: Codable, Sendable {
1179311823
case expiresatms = "expiresAtMs"
1179411824
case presentation
1179511825
case resolvedatms = "resolvedAtMs"
11826+
case source
11827+
case resolver
1179611828
case status
1179711829
case reason
1179811830
}
@@ -11826,6 +11858,46 @@ public struct ApprovalGetResult: Codable, Sendable {
1182611858
}
1182711859
}
1182811860

11861+
public struct ApprovalHistoryParams: Codable, Sendable {
11862+
public let cursor: String?
11863+
public let limit: Int?
11864+
public let kind: ApprovalKind?
11865+
11866+
public init(
11867+
cursor: String? = nil,
11868+
limit: Int? = nil,
11869+
kind: ApprovalKind? = nil)
11870+
{
11871+
self.cursor = cursor
11872+
self.limit = limit
11873+
self.kind = kind
11874+
}
11875+
11876+
private enum CodingKeys: String, CodingKey {
11877+
case cursor
11878+
case limit
11879+
case kind
11880+
}
11881+
}
11882+
11883+
public struct ApprovalHistoryResult: Codable, Sendable {
11884+
public let items: [TerminalApprovalSnapshot]
11885+
public let nextcursor: String?
11886+
11887+
public init(
11888+
items: [TerminalApprovalSnapshot],
11889+
nextcursor: String? = nil)
11890+
{
11891+
self.items = items
11892+
self.nextcursor = nextcursor
11893+
}
11894+
11895+
private enum CodingKeys: String, CodingKey {
11896+
case items
11897+
case nextcursor = "nextCursor"
11898+
}
11899+
}
11900+
1182911901
public struct ApprovalResolveParams: Codable, Sendable {
1183011902
public let id: String
1183111903
public let kind: ApprovalKind

‎packages/gateway-protocol/src/approval-result-validators.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
type ApprovalDecision,
44
type ApprovalGetResult,
55
ApprovalGetResultSchema,
6+
type ApprovalHistoryResult,
7+
ApprovalHistoryResultSchema,
68
type ApprovalPresentation,
79
type ApprovalResolveResult,
810
ApprovalResolveResultSchema,
@@ -12,10 +14,12 @@ import {
1214
export type {
1315
ApprovalDecision,
1416
ApprovalGetResult,
17+
ApprovalHistoryResult,
1518
ApprovalPresentation,
1619
ApprovalResolveResult,
1720
ApprovalSnapshot,
1821
};
1922

2023
export const validateApprovalGetResult = lazyCompile(ApprovalGetResultSchema);
24+
export const validateApprovalHistoryResult = lazyCompile(ApprovalHistoryResultSchema);
2125
export const validateApprovalResolveResult = lazyCompile(ApprovalResolveResultSchema);

‎packages/gateway-protocol/src/approvals-validators.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
validateApprovalAllowDecision,
44
validateApprovalGetParams,
55
validateApprovalGetResult,
6+
validateApprovalHistoryParams,
7+
validateApprovalHistoryResult,
68
validateApprovalDecision,
79
validateApprovalKind,
810
validateApprovalPresentation,
@@ -217,6 +219,32 @@ describe("unified approval protocol validators", () => {
217219
).toBe(false);
218220
});
219221

222+
it("validates terminal history pages and optional attribution", () => {
223+
const terminal = {
224+
...pluginRecord,
225+
status: "denied",
226+
decision: "deny",
227+
resolvedAtMs: pluginRecord.createdAtMs + 1_000,
228+
reason: "user",
229+
source: { agentId: "release", sessionKey: "agent:release:main" },
230+
resolver: { kind: "device", id: "reviewer-device" },
231+
} as const;
232+
233+
expect(validateApprovalHistoryParams({})).toBe(true);
234+
expect(validateApprovalHistoryParams({ cursor: "cursor", limit: 50, kind: "plugin" })).toBe(
235+
true,
236+
);
237+
expect(validateApprovalHistoryParams({ limit: 0 })).toBe(false);
238+
expect(validateApprovalHistoryParams({ limit: 101 })).toBe(false);
239+
expect(validateApprovalHistoryParams({ kind: "tool" })).toBe(false);
240+
241+
expect(validateApprovalHistoryResult({ items: [terminal], nextCursor: "next" })).toBe(true);
242+
expect(validateApprovalHistoryResult({ items: [{ ...execRecord, status: "pending" }] })).toBe(
243+
false,
244+
);
245+
expect(validateApprovalHistoryResult({ items: [terminal], extra: true })).toBe(false);
246+
});
247+
220248
it("returns the canonical recorded snapshot to losing resolvers", () => {
221249
const recorded = {
222250
...execRecord,

‎packages/gateway-protocol/src/index.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
export * from "./clawhub-trust-error-details.js";
22
export * from "./terminal-validators.js";
3-
export { validateApprovalGetResult } from "./approval-result-validators.js";
4-
export { validateApprovalResolveResult } from "./approval-result-validators.js";
3+
export {
4+
validateApprovalGetResult,
5+
validateApprovalHistoryResult,
6+
validateApprovalResolveResult,
7+
} from "./approval-result-validators.js";
58
import type { ValidationError } from "./validation-errors.js";
69
export { formatValidationErrors, type ValidationError } from "./validation-errors.js";
710
import { lazyCompile } from "./protocol-validator.js";
@@ -148,6 +151,8 @@ import {
148151
ApprovalDecisionSchema,
149152
ApprovalGetParamsSchema,
150153
ApprovalGetResultSchema,
154+
ApprovalHistoryParamsSchema,
155+
ApprovalHistoryResultSchema,
151156
ApprovalKindSchema,
152157
ApprovalPresentationSchema,
153158
ApprovalResolveParamsSchema,
@@ -797,6 +802,7 @@ export const validateCancelledApprovalSnapshot = lazyCompile(CancelledApprovalSn
797802
export const validateApprovalSnapshot = lazyCompile(ApprovalSnapshotSchema);
798803
export const validateTerminalApprovalSnapshot = lazyCompile(TerminalApprovalSnapshotSchema);
799804
export const validateApprovalGetParams = lazyCompile(ApprovalGetParamsSchema);
805+
export const validateApprovalHistoryParams = lazyCompile(ApprovalHistoryParamsSchema);
800806
export const validateApprovalResolveParams = lazyCompile(ApprovalResolveParamsSchema);
801807
export const validateExecApprovalsGetParams = lazyCompile(ExecApprovalsGetParamsSchema);
802808
export const validateExecApprovalsSetParams = lazyCompile(ExecApprovalsSetParamsSchema);
@@ -1240,6 +1246,8 @@ export {
12401246
TerminalApprovalSnapshotSchema,
12411247
ApprovalGetParamsSchema,
12421248
ApprovalGetResultSchema,
1249+
ApprovalHistoryParamsSchema,
1250+
ApprovalHistoryResultSchema,
12431251
ApprovalResolveParamsSchema,
12441252
ApprovalResolveResultSchema,
12451253
SessionApprovalEventSchema,
@@ -1622,6 +1630,8 @@ export type {
16221630
TerminalApprovalSnapshot,
16231631
ApprovalGetParams,
16241632
ApprovalGetResult,
1633+
ApprovalHistoryParams,
1634+
ApprovalHistoryResult,
16251635
ApprovalResolveParams,
16261636
ApprovalResolveResult,
16271637
SessionApprovalEvent,

‎packages/gateway-protocol/src/schema/approvals.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,27 @@ const ApprovalRecordCommonFields = {
141141
presentation: ApprovalPresentationSchema,
142142
};
143143

144+
/** Reviewer-safe origin attribution for terminal approval history. */
145+
const ApprovalHistorySourceAttributionSchema = closedObject({
146+
agentId: Type.Optional(NonEmptyString),
147+
sessionKey: Type.Optional(NonEmptyString),
148+
});
149+
150+
/** Reviewer attribution recorded by the durable approval ledger. */
151+
const ApprovalHistoryResolverAttributionSchema = closedObject({
152+
kind: Type.Union([
153+
Type.Literal("device"),
154+
Type.Literal("channel"),
155+
Type.Literal("runtime"),
156+
Type.Literal("system"),
157+
]),
158+
id: Type.Optional(NonEmptyString),
159+
});
160+
144161
const ApprovalResolutionFields = {
145162
resolvedAtMs: Type.Integer({ minimum: 0 }),
163+
source: Type.Optional(ApprovalHistorySourceAttributionSchema),
164+
resolver: Type.Optional(ApprovalHistoryResolverAttributionSchema),
146165
};
147166

148167
/** Approval that has not yet accepted a reviewer decision. */
@@ -208,6 +227,19 @@ export const ApprovalGetParamsSchema = closedObject({ id: ApprovalRecordCommonFi
208227
/** Current durable state for one authorized approval lookup. */
209228
export const ApprovalGetResultSchema = closedObject({ approval: ApprovalSnapshotSchema });
210229

230+
/** Cursor-based query for the retained terminal approval ledger. */
231+
export const ApprovalHistoryParamsSchema = closedObject({
232+
cursor: Type.Optional(Type.String({ minLength: 1, maxLength: 512 })),
233+
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 100 })),
234+
kind: Type.Optional(ApprovalKindSchema),
235+
});
236+
237+
/** Newest-first page from the retained terminal approval ledger. */
238+
export const ApprovalHistoryResultSchema = closedObject({
239+
items: Type.Array(TerminalApprovalSnapshotSchema),
240+
nextCursor: Type.Optional(Type.String({ minLength: 1, maxLength: 512 })),
241+
});
242+
211243
/** Reviewer decision for one approval identified by its exact full id. */
212244
export const ApprovalResolveParamsSchema = closedObject({
213245
id: ApprovalRecordCommonFields.id,
@@ -270,6 +302,8 @@ export type PendingApprovalSnapshot = Static<typeof PendingApprovalSnapshotSchem
270302
export type ApprovalSnapshot = Static<typeof ApprovalSnapshotSchema>;
271303
export type ApprovalGetParams = Static<typeof ApprovalGetParamsSchema>;
272304
export type ApprovalGetResult = Static<typeof ApprovalGetResultSchema>;
305+
export type ApprovalHistoryParams = Static<typeof ApprovalHistoryParamsSchema>;
306+
export type ApprovalHistoryResult = Static<typeof ApprovalHistoryResultSchema>;
273307
export type ApprovalResolveParams = Static<typeof ApprovalResolveParamsSchema>;
274308
export type ApprovalResolveResult = Static<typeof ApprovalResolveResultSchema>;
275309
export type AllowedApprovalSnapshot = Static<typeof AllowedApprovalSnapshotSchema>;

‎packages/gateway-protocol/src/schema/protocol-schemas.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ import {
100100
ApprovalExpiredReasonSchema,
101101
ApprovalGetParamsSchema,
102102
ApprovalGetResultSchema,
103+
ApprovalHistoryParamsSchema,
104+
ApprovalHistoryResultSchema,
103105
ApprovalKindSchema,
104106
ApprovalPresentationSchema,
105107
ApprovalResolveParamsSchema,
@@ -893,6 +895,8 @@ export const ProtocolSchemas = {
893895
TerminalApprovalSnapshot: TerminalApprovalSnapshotSchema,
894896
ApprovalGetParams: ApprovalGetParamsSchema,
895897
ApprovalGetResult: ApprovalGetResultSchema,
898+
ApprovalHistoryParams: ApprovalHistoryParamsSchema,
899+
ApprovalHistoryResult: ApprovalHistoryResultSchema,
896900
ApprovalResolveParams: ApprovalResolveParamsSchema,
897901
ApprovalResolveResult: ApprovalResolveResultSchema,
898902
PendingSessionApprovalEvent: PendingSessionApprovalEventSchema,

‎src/gateway/method-scopes.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ describe("operator scope authorization", () => {
492492

493493
it.each([
494494
"approval.get",
495+
"approval.history",
495496
"approval.resolve",
496497
"exec.approval.get",
497498
"exec.approval.list",

0 commit comments

Comments
 (0)