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

推荐订阅源

Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
V
V2EX
博客园 - 叶小钗
雷峰网
雷峰网
小众软件
小众软件
量子位
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Martin Fowler
Martin Fowler
G
Google Developers Blog
博客园_首页
博客园 - 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
Preserve elevated exec followup defaults · openclaw/openc...
bitloi · 2026-05-10 · via Recent Commits to openclaw:main

@@ -0,0 +1,123 @@

1+

import { randomUUID } from "node:crypto";

2+

import { normalizeOptionalString } from "../shared/string-coerce.js";

3+

import type { ExecElevatedDefaults } from "./bash-tools.exec-types.js";

4+5+

const EXEC_APPROVAL_FOLLOWUP_IDEMPOTENCY_PREFIX = "exec-approval-followup:";

6+

const EXEC_APPROVAL_FOLLOWUP_ELEVATED_TOKEN_MARKER = ":elevated:";

7+

const EXEC_APPROVAL_FOLLOWUP_ELEVATED_TTL_MS = 5 * 60 * 1000;

8+9+

type ExecApprovalFollowupElevatedEntry = {

10+

sessionKey: string;

11+

bashElevated: ExecElevatedDefaults;

12+

expiresAtMs: number;

13+

};

14+15+

const execApprovalFollowupElevatedDefaults = new Map<string, ExecApprovalFollowupElevatedEntry>();

16+17+

function cloneExecElevatedDefaults(value: ExecElevatedDefaults): ExecElevatedDefaults {

18+

return {

19+

enabled: value.enabled,

20+

allowed: value.allowed,

21+

defaultLevel: value.defaultLevel,

22+

...(value.fullAccessAvailable !== undefined

23+

? { fullAccessAvailable: value.fullAccessAvailable }

24+

: {}),

25+

...(value.fullAccessBlockedReason !== undefined

26+

? { fullAccessBlockedReason: value.fullAccessBlockedReason }

27+

: {}),

28+

};

29+

}

30+31+

function pruneExpiredExecApprovalFollowupElevatedDefaults(nowMs: number): void {

32+

for (const [token, entry] of execApprovalFollowupElevatedDefaults) {

33+

if (entry.expiresAtMs <= nowMs) {

34+

execApprovalFollowupElevatedDefaults.delete(token);

35+

}

36+

}

37+

}

38+39+

export function buildExecApprovalFollowupIdempotencyKey(params: {

40+

approvalId: string;

41+

execApprovalFollowupToken?: string;

42+

}): string {

43+

const base = `${EXEC_APPROVAL_FOLLOWUP_IDEMPOTENCY_PREFIX}${params.approvalId}`;

44+

return params.execApprovalFollowupToken

45+

? `${base}${EXEC_APPROVAL_FOLLOWUP_ELEVATED_TOKEN_MARKER}${params.execApprovalFollowupToken}`

46+

: base;

47+

}

48+49+

function parseExecApprovalFollowupToken(idempotencyKey: string): string | undefined {

50+

if (!idempotencyKey.startsWith(EXEC_APPROVAL_FOLLOWUP_IDEMPOTENCY_PREFIX)) {

51+

return undefined;

52+

}

53+

const tokenMarker = idempotencyKey.lastIndexOf(EXEC_APPROVAL_FOLLOWUP_ELEVATED_TOKEN_MARKER);

54+

if (tokenMarker < EXEC_APPROVAL_FOLLOWUP_IDEMPOTENCY_PREFIX.length) {

55+

return undefined;

56+

}

57+

return normalizeOptionalString(

58+

idempotencyKey.slice(tokenMarker + EXEC_APPROVAL_FOLLOWUP_ELEVATED_TOKEN_MARKER.length),

59+

);

60+

}

61+62+

export function registerExecApprovalFollowupElevatedDefaults(params: {

63+

sessionKey: string;

64+

bashElevated?: ExecElevatedDefaults;

65+

nowMs?: number;

66+

}): string | undefined {

67+

const sessionKey = normalizeOptionalString(params.sessionKey);

68+

if (!params.bashElevated || !sessionKey) {

69+

return undefined;

70+

}

71+

const nowMs = params.nowMs ?? Date.now();

72+

pruneExpiredExecApprovalFollowupElevatedDefaults(nowMs);

73+

const token = randomUUID();

74+

execApprovalFollowupElevatedDefaults.set(token, {

75+

sessionKey,

76+

bashElevated: cloneExecElevatedDefaults(params.bashElevated),

77+

expiresAtMs: nowMs + EXEC_APPROVAL_FOLLOWUP_ELEVATED_TTL_MS,

78+

});

79+

return token;

80+

}

81+82+

export function consumeExecApprovalFollowupElevatedDefaults(params: {

83+

token?: string;

84+

sessionKey?: string;

85+

nowMs?: number;

86+

}): ExecElevatedDefaults | undefined {

87+

const token = normalizeOptionalString(params.token);

88+

if (!token) {

89+

return undefined;

90+

}

91+

const nowMs = params.nowMs ?? Date.now();

92+

pruneExpiredExecApprovalFollowupElevatedDefaults(nowMs);

93+

const entry = execApprovalFollowupElevatedDefaults.get(token);

94+

if (!entry) {

95+

return undefined;

96+

}

97+

if (entry.expiresAtMs <= nowMs) {

98+

execApprovalFollowupElevatedDefaults.delete(token);

99+

return undefined;

100+

}

101+

const sessionKey = normalizeOptionalString(params.sessionKey);

102+

if (entry.sessionKey !== sessionKey) {

103+

return undefined;

104+

}

105+

execApprovalFollowupElevatedDefaults.delete(token);

106+

return cloneExecElevatedDefaults(entry.bashElevated);

107+

}

108+109+

export function consumeExecApprovalFollowupElevatedDefaultsFromIdempotencyKey(params: {

110+

idempotencyKey: string;

111+

sessionKey?: string;

112+

nowMs?: number;

113+

}): ExecElevatedDefaults | undefined {

114+

return consumeExecApprovalFollowupElevatedDefaults({

115+

token: parseExecApprovalFollowupToken(params.idempotencyKey),

116+

sessionKey: params.sessionKey,

117+

nowMs: params.nowMs,

118+

});

119+

}

120+121+

export function resetExecApprovalFollowupElevatedDefaultsForTests(): void {

122+

execApprovalFollowupElevatedDefaults.clear();

123+

}