UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 9.89 kB
import{c as normalizeOptionalLowercaseString}from"./string-coerce-CpTFcSwY.mjs";import{d as normalizeSortedUniqueTrimmedStringList}from"./string-normalization-D_oBUpO3.mjs";import{r as resolveAgentConfig}from"./agent-scope-config-CG9CFpGX.mjs";import{u as resolveExecModePolicy}from"./exec-approvals-core-BZ6-zeZE.mjs";import{t as applyExecPolicyLayer}from"./exec-policy-uFwIYzyl.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import"./agent-scope-runtime-DKb8jQZx.mjs";import"./exec-approvals-runtime-By_CUGOa.mjs";import{f as OPENCLAW_MCP_TOOL_PREFIX,t as CLAUDE_CLI_BACKEND_ID}from"./cli-constants-Cc2K557b.mjs"; //!extensions/anthropic/cli-shared.ts const CLAUDE_LEGACY_SKIP_PERMISSIONS_ARG=`--dangerously-skip-permissions`;const CLAUDE_PERMISSION_MODE_ARG=`--permission-mode`;const CLAUDE_SETTING_SOURCES_ARG=`--setting-sources`;const CLAUDE_EXCLUDE_DYNAMIC_SYSTEM_PROMPT_SECTIONS_ARG=`--exclude-dynamic-system-prompt-sections`;const CLAUDE_EXCLUDE_DYNAMIC_SYSTEM_PROMPT_SECTIONS_MINIMUM_VERSION=`2.1.98`;const CLAUDE_SETTINGS_ARG=`--settings`;const CLAUDE_EFFORT_ARG=`--effort`;const CLAUDE_FAST_MODE_ARG=`--fast-mode`;const CLAUDE_BARE_ARG=`--bare`;const CLAUDE_SAFE_MODE_ARG=`--safe-mode`;const CLAUDE_DISABLE_SLASH_COMMANDS_ARG=`--disable-slash-commands`;const CLAUDE_NO_CHROME_ARG=`--no-chrome`;const CLAUDE_TOOLS_ARG=`--tools`;const CLAUDE_ALLOWED_TOOLS_ARG=`--allowedTools`;const CLAUDE_DISALLOWED_TOOLS_ARG=`--disallowedTools`;const CLAUDE_STRICT_MCP_CONFIG_ARG=`--strict-mcp-config`;const CLAUDE_NO_SESSION_PERSISTENCE_ARG=`--no-session-persistence`;const CLAUDE_MAX_TURNS_ARG=`--max-turns`;const CLAUDE_SAFE_SETTING_SOURCES=`user`;const CLAUDE_DENY_MCP_TOOLS_VALUE=`mcp__*`;const CLAUDE_RESTRICTED_SETTINGS=`{"disableAllHooks":true,"enabledPlugins":{},"autoMemoryEnabled":false,"claudeMdExcludes":["**/CLAUDE.md","**/CLAUDE.local.md","**/.claude/rules/**"]}`;function isClaudeCliProvider(e){return normalizeOptionalLowercaseString(e)===CLAUDE_CLI_BACKEND_ID}function resolveClaudeCliAutoCompactEnv(e){if(typeof e!==`number`||!Number.isFinite(e))return;const t=Math.floor(e);if(t<=0)return;return{CLAUDE_CODE_AUTO_COMPACT_WINDOW:String(t)}}function resolveClaudeCliThinkingEnv(e){switch(e){case`off`:return{MAX_THINKING_TOKENS:`0`};case`minimal`:return{CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING:`1`,MAX_THINKING_TOKENS:`1024`};case`low`:return{CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING:`1`,MAX_THINKING_TOKENS:`2048`};case`medium`:return{CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING:`1`,MAX_THINKING_TOKENS:`8192`};case`high`:case`xhigh`:return{CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING:`1`,MAX_THINKING_TOKENS:`16384`};case`max`:return{CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING:`1`,MAX_THINKING_TOKENS:`32768`};case`adaptive`:case void 0:return;default:return e}}function parseClaudeCodeVersion(e){return e?.match(/(?:^|\s)(\d+\.\d+\.\d+)(?=$|\s)/u)?.[1]}function supportsClaudeDynamicSystemPromptSections(e){const t=parseClaudeCodeVersion(e);if(!t)return false;const n=t.split(`.`).map(Number);const r=CLAUDE_EXCLUDE_DYNAMIC_SYSTEM_PROMPT_SECTIONS_MINIMUM_VERSION.split(`.`).map(Number);for(const[e,t]of n.entries()){const n=r[e];if(t===void 0||n===void 0)return false;if(t!==n)return t>n}return true}function isOpenClawRequestedYolo(e){const t=e.agentId?resolveAgentConfig(e.config??{},e.agentId)?.tools?.exec:void 0;const n=applyExecPolicyLayer(applyExecPolicyLayer({security:`full`,ask:`off`},e.config?.tools?.exec),t);return resolveExecModePolicy(n).mode===`full`}function normalizeClaudeBackendArgs(e){const t=e.baseArgs;const n=[];let r=false;let i=false;for(let e=0;e<t.length;e+=1){const a=t[e]??``;if(a===CLAUDE_LEGACY_SKIP_PERMISSIONS_ARG)continue;if(a===CLAUDE_PERMISSION_MODE_ARG||a===CLAUDE_SETTING_SOURCES_ARG){const o=t[e+1];if(typeof o===`string`&&o.trim().length>0&&!o.startsWith(`-`)){if(a===CLAUDE_PERMISSION_MODE_ARG){r=true;n.push(a,o)}else{i=true;n.push(a,CLAUDE_SAFE_SETTING_SOURCES)}e+=1}continue}if(a.startsWith(`${CLAUDE_PERMISSION_MODE_ARG}=`)){const e=a.slice(`${CLAUDE_PERMISSION_MODE_ARG}=`.length).trim();if(e.length>0&&!e.startsWith(`-`)){r=true;n.push(`${CLAUDE_PERMISSION_MODE_ARG}=${e}`)}continue}if(a.startsWith(`${CLAUDE_SETTING_SOURCES_ARG}=`)){i=true;n.push(`${CLAUDE_SETTING_SOURCES_ARG}=${CLAUDE_SAFE_SETTING_SOURCES}`);continue}n.push(a)}if(!i)n.push(CLAUDE_SETTING_SOURCES_ARG,CLAUDE_SAFE_SETTING_SOURCES);if(!r&&e.controlOperation!==`compact`&&isOpenClawRequestedYolo(e))n.push(CLAUDE_PERMISSION_MODE_ARG,`bypassPermissions`);return n}function applyClaudeCliEffortArgs(e,t){const n=normalizeOptionalLowercaseString(t);switch(n){case`minimal`:case`low`:return[...stripClaudeEffortArgs(e),CLAUDE_EFFORT_ARG,`low`];case`adaptive`:return stripClaudeEffortArgs(e);case`medium`:case`high`:case`xhigh`:case`max`:return[...stripClaudeEffortArgs(e),CLAUDE_EFFORT_ARG,n];default:return[...e]}}function applyClaudeCliFastModeArgs(e,t){return t.fastMode===true?[...e,CLAUDE_FAST_MODE_ARG,`on`]:[...e]}function stripClaudeEffortArgs(e){const t=[];for(let n=0;n<e.length;n+=1){const r=e[n]??``;if(r===CLAUDE_EFFORT_ARG){const t=e[n+1];if(typeof t===`string`&&t.trim().length>0&&!t.startsWith(`-`))n+=1;continue}if(r.startsWith(`${CLAUDE_EFFORT_ARG}=`))continue;t.push(r)}return t}const CLAUDE_SIDE_QUESTION_VARIADIC_VALUE_ARGS=/* @__PURE__ */ new Set([CLAUDE_ALLOWED_TOOLS_ARG,`--allowed-tools`,CLAUDE_DISALLOWED_TOOLS_ARG,`--disallowed-tools`,CLAUDE_TOOLS_ARG,`--mcp-config`]);const CLAUDE_RESTRICTED_VARIADIC_VALUE_ARGS=/* @__PURE__ */ new Set([.../* @__PURE__ */ new Set([CLAUDE_TOOLS_ARG,CLAUDE_ALLOWED_TOOLS_ARG,`--allowed-tools`,CLAUDE_DISALLOWED_TOOLS_ARG,`--disallowed-tools`]),`--add-dir`,`--file`]);const CLAUDE_RESTRICTED_VALUE_ARGS=/* @__PURE__ */ new Set([CLAUDE_PERMISSION_MODE_ARG,CLAUDE_SETTING_SOURCES_ARG,CLAUDE_SETTINGS_ARG,`--agent`,`--agents`,`--managed-settings`,`--plugin-dir`,`--plugin-dir-no-mcp`,`--plugin-url`,`--system-prompt`,`--system-prompt-file`,`--append-system-prompt`,`--append-system-prompt-file`]);const CLAUDE_RESTRICTED_BARE_ARGS=/* @__PURE__ */ new Set([CLAUDE_BARE_ARG,CLAUDE_SAFE_MODE_ARG,CLAUDE_DISABLE_SLASH_COMMANDS_ARG,`--chrome`,CLAUDE_NO_CHROME_ARG,CLAUDE_STRICT_MCP_CONFIG_ARG,CLAUDE_LEGACY_SKIP_PERMISSIONS_ARG,`--allow-dangerously-skip-permissions`,`--ide`]);const CLAUDE_SIDE_QUESTION_VALUE_ARGS=/* @__PURE__ */ new Set([CLAUDE_PERMISSION_MODE_ARG,`--session-id`,`--resume`,`--resume-session-at`,`-r`,CLAUDE_MAX_TURNS_ARG]);const CLAUDE_SIDE_QUESTION_BARE_ARGS=/* @__PURE__ */ new Set([`--continue`,`-c`,`--fork-session`,CLAUDE_BARE_ARG,CLAUDE_SAFE_MODE_ARG,CLAUDE_STRICT_MCP_CONFIG_ARG,CLAUDE_NO_SESSION_PERSISTENCE_ARG]);function stripClaudeArgs(e,t){const n=[];for(let r=0;r<e.length;r+=1){const i=e[r]??``;const a=i.indexOf(`=`);const o=a>0?i.slice(0,a):i;if(t.bare?.has(o))continue;if(t.variadicValue?.has(o)){if(a<0)while(typeof e[r+1]===`string`&&!e[r+1]?.startsWith(`-`))r+=1;continue}if(t.value?.has(o)){if(a<0){const t=e[r+1];if(typeof t===`string`&&!t.startsWith(`-`))r+=1}continue}n.push(i)}return n}function resolveClaudeCliSideQuestionExecutionArgs(e){return[...stripClaudeArgs(stripClaudeEffortArgs(e),{bare:CLAUDE_SIDE_QUESTION_BARE_ARGS,variadicValue:CLAUDE_SIDE_QUESTION_VARIADIC_VALUE_ARGS,value:CLAUDE_SIDE_QUESTION_VALUE_ARGS}),CLAUDE_SAFE_MODE_ARG,CLAUDE_TOOLS_ARG,``,CLAUDE_DISALLOWED_TOOLS_ARG,CLAUDE_DENY_MCP_TOOLS_VALUE,CLAUDE_STRICT_MCP_CONFIG_ARG,CLAUDE_NO_SESSION_PERSISTENCE_ARG,CLAUDE_MAX_TURNS_ARG,`1`,CLAUDE_PERMISSION_MODE_ARG,`default`]}function readClaudeToolDenials(e){const t=[];for(let n=0;n<e.length;n+=1){const r=e[n]??``;if(r===CLAUDE_DISALLOWED_TOOLS_ARG||r===`--disallowed-tools`)while(typeof e[n+1]===`string`&&!e[n+1]?.startsWith(`-`)){n+=1;t.push(...(e[n]??``).split(`,`))}else if(r.startsWith(`${CLAUDE_DISALLOWED_TOOLS_ARG}=`)||r.startsWith(`--disallowed-tools=`))t.push(...r.slice(r.indexOf(`=`)+1).split(`,`))}return t}function resolveClaudeCliRestrictedExecutionArgs(e,t,n={}){const r=readClaudeToolDenials(e);const i=stripClaudeArgs(e,{bare:CLAUDE_RESTRICTED_BARE_ARGS,variadicValue:CLAUDE_RESTRICTED_VARIADIC_VALUE_ARGS,value:CLAUDE_RESTRICTED_VALUE_ARGS});i.push(CLAUDE_SETTING_SOURCES_ARG,``,CLAUDE_SETTINGS_ARG,CLAUDE_RESTRICTED_SETTINGS,...n.preserveSlashCommands?[]:[CLAUDE_DISABLE_SLASH_COMMANDS_ARG],CLAUDE_NO_CHROME_ARG,CLAUDE_STRICT_MCP_CONFIG_ARG,CLAUDE_TOOLS_ARG,[...t.native,...t.discovery??[]].join(`,`));if(t.openClaw.length>0)i.push(CLAUDE_ALLOWED_TOOLS_ARG,t.openClaw.map(e=>`${OPENCLAW_MCP_TOOL_PREFIX}${e}`).join(`,`));const a=normalizeSortedUniqueTrimmedStringList([...r,...t.openClaw.length===0?[CLAUDE_DENY_MCP_TOOLS_VALUE]:[]]);if(a.length>0)i.push(CLAUDE_DISALLOWED_TOOLS_ARG,a.join(`,`));return i}function resolveClaudeCliExecutionArgs(e,t={}){const n=normalizeClaudeBackendArgs(e);const r=e.hostOwnedTools?.includes(`exec`)?[...stripClaudeArgs(n,{variadicValue:/* @__PURE__ */ new Set([CLAUDE_DISALLOWED_TOOLS_ARG,`--disallowed-tools`])}),CLAUDE_DISALLOWED_TOOLS_ARG,[.../* @__PURE__ */ new Set([...readClaudeToolDenials(n),`Bash`])].join(`,`)]:n;const i=e.executionMode===`side-question`?resolveClaudeCliSideQuestionExecutionArgs(r):applyClaudeCliFastModeArgs(applyClaudeCliEffortArgs(r,e.thinkingLevel),e);const a=e.toolAvailability?resolveClaudeCliRestrictedExecutionArgs(i,e.toolAvailability,{preserveSlashCommands:e.controlOperation===`compact`}):i;return t.excludeDynamicSystemPromptSections&&e.executionMode!==`side-question`?[...a,CLAUDE_EXCLUDE_DYNAMIC_SYSTEM_PROMPT_SECTIONS_ARG]:a}function normalizeClaudeBackendConfig(e){const t=e.output??`jsonl`;const n=e.input??`stdin`;return{...e,output:t,liveSession:e.liveSession??(t===`jsonl`&&n===`stdin`?`claude-stdio`:void 0),input:n}}export{resolveClaudeCliExecutionArgs as a,resolveClaudeCliAutoCompactEnv as i,normalizeClaudeBackendConfig as n,resolveClaudeCliThinkingEnv as o,parseClaudeCodeVersion as r,supportsClaudeDynamicSystemPromptSections as s,isClaudeCliProvider as t};