惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
GbyAI
GbyAI
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
U
Unit 42
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
美团技术团队
雷峰网
雷峰网
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
D
DataBreaches.Net
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
罗磊的独立博客
MyScale Blog
MyScale Blog
博客园_首页
IT之家
IT之家
F
Fortinet All Blogs
博客园 - Franky

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
Relay ACP exec approval permissions · openclaw/openclaw@6...
amknight · 2026-05-09 · via Recent Commits to openclaw:main

@@ -0,0 +1,166 @@

1+

import type {

2+

PermissionOption,

3+

RequestPermissionRequest,

4+

RequestPermissionResponse,

5+

} from "@agentclientprotocol/sdk";

6+7+

export type GatewayExecApprovalDecision = "allow-once" | "allow-always" | "deny";

8+9+

export type GatewayExecApprovalEvent = {

10+

approvalId: string;

11+

command?: string;

12+

host?: string;

13+

title?: string;

14+

toolCallId?: string;

15+

};

16+17+

export type GatewayExecApprovalDetails = {

18+

allowedDecisions?: unknown;

19+

commandPreview?: unknown;

20+

commandText?: unknown;

21+

host?: unknown;

22+

};

23+24+

const FALLBACK_EXEC_APPROVAL_DECISIONS = ["allow-once", "deny"] as const;

25+26+

function readNonEmptyString(value: unknown): string | undefined {

27+

return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;

28+

}

29+30+

function normalizeGatewayExecApprovalDecision(

31+

value: unknown,

32+

): GatewayExecApprovalDecision | undefined {

33+

if (value === "allow-once" || value === "allow-always" || value === "deny") {

34+

return value;

35+

}

36+

return undefined;

37+

}

38+39+

export function normalizeGatewayExecApprovalDecisions(

40+

value: unknown,

41+

): GatewayExecApprovalDecision[] {

42+

const normalized = Array.isArray(value)

43+

? value

44+

.map(normalizeGatewayExecApprovalDecision)

45+

.filter((decision): decision is GatewayExecApprovalDecision => Boolean(decision))

46+

: [];

47+

return normalized.length > 0 ? normalized : [...FALLBACK_EXEC_APPROVAL_DECISIONS];

48+

}

49+50+

export function buildAcpPermissionOptions(

51+

decisions: readonly GatewayExecApprovalDecision[],

52+

): PermissionOption[] {

53+

const unique = new Set<GatewayExecApprovalDecision>(decisions);

54+

const options: PermissionOption[] = [];

55+

if (unique.has("allow-once")) {

56+

options.push({

57+

optionId: "allow-once",

58+

name: "Allow once",

59+

kind: "allow_once",

60+

});

61+

}

62+

if (unique.has("allow-always")) {

63+

options.push({

64+

optionId: "allow-always",

65+

name: "Allow always",

66+

kind: "allow_always",

67+

});

68+

}

69+

if (unique.has("deny")) {

70+

options.push({

71+

optionId: "deny",

72+

name: "Deny",

73+

kind: "reject_once",

74+

});

75+

}

76+

return options.length > 0 ? options : buildAcpPermissionOptions(FALLBACK_EXEC_APPROVAL_DECISIONS);

77+

}

78+79+

export function parseGatewayExecApprovalEventData(

80+

data: Record<string, unknown>,

81+

): GatewayExecApprovalEvent | null {

82+

if (data.phase !== "requested" || data.kind !== "exec" || data.status !== "pending") {

83+

return null;

84+

}

85+

const approvalId = readNonEmptyString(data.approvalId);

86+

if (!approvalId) {

87+

return null;

88+

}

89+

return {

90+

approvalId,

91+

command: readNonEmptyString(data.command),

92+

host: readNonEmptyString(data.host),

93+

title: readNonEmptyString(data.title),

94+

toolCallId: readNonEmptyString(data.toolCallId),

95+

};

96+

}

97+98+

export function parseGatewayExecApprovalRequestEventPayload(

99+

payload: Record<string, unknown>,

100+

): GatewayExecApprovalEvent | null {

101+

const approvalId = readNonEmptyString(payload.id);

102+

const request = payload.request;

103+

if (!approvalId || !request || typeof request !== "object" || Array.isArray(request)) {

104+

return null;

105+

}

106+

const requestRecord = request as Record<string, unknown>;

107+

return {

108+

approvalId,

109+

command:

110+

readNonEmptyString(requestRecord.command) ?? readNonEmptyString(requestRecord.commandPreview),

111+

host: readNonEmptyString(requestRecord.host),

112+

};

113+

}

114+115+

export function buildAcpPermissionRequest(params: {

116+

sessionId: string;

117+

event: GatewayExecApprovalEvent;

118+

details?: GatewayExecApprovalDetails | null;

119+

}): RequestPermissionRequest {

120+

const command =

121+

readNonEmptyString(params.details?.commandText) ??

122+

readNonEmptyString(params.details?.commandPreview) ??

123+

params.event.command;

124+

const host = readNonEmptyString(params.details?.host) ?? params.event.host;

125+

const decisions = normalizeGatewayExecApprovalDecisions(params.details?.allowedDecisions);

126+

const rawInput: Record<string, string> = {

127+

name: "exec",

128+

approvalId: params.event.approvalId,

129+

};

130+

if (command) {

131+

rawInput.command = command;

132+

}

133+

if (host) {

134+

rawInput.host = host;

135+

}

136+137+

return {

138+

sessionId: params.sessionId,

139+

toolCall: {

140+

// Raw approval events can arrive before Gateway emits a tool call id; the

141+

// approval id remains the stable correlation key for those early prompts.

142+

toolCallId: params.event.toolCallId ?? `exec:${params.event.approvalId}`,

143+

title: params.event.title ?? "Command approval requested",

144+

kind: "execute",

145+

status: "pending",

146+

rawInput,

147+

_meta: {

148+

toolName: "exec",

149+

approvalId: params.event.approvalId,

150+

},

151+

},

152+

options: buildAcpPermissionOptions(decisions),

153+

};

154+

}

155+156+

export function resolveGatewayDecisionFromPermissionOutcome(

157+

response: RequestPermissionResponse | undefined,

158+

options: readonly PermissionOption[],

159+

): GatewayExecApprovalDecision | undefined {

160+

const outcome = response?.outcome;

161+

if (!outcome || outcome.outcome !== "selected") {

162+

return undefined;

163+

}

164+

const selected = options.find((option) => option.optionId === outcome.optionId);

165+

return normalizeGatewayExecApprovalDecision(selected?.optionId);

166+

}