
























@@ -1,3 +1,8 @@
1+import {
2+summarizeCommandSegmentsForDisplay,
3+type CommandExplanationSummary,
4+} from "../../infra/command-analysis/explain.js";
5+import { analyzeCommandForPolicy } from "../../infra/command-analysis/policy.js";
16import {
27resolveExecApprovalCommandDisplay,
38sanitizeExecApprovalDisplayText,
@@ -42,6 +47,43 @@ const APPROVAL_ALLOW_ALWAYS_UNAVAILABLE_DETAILS = {
4247} as const;
4348const RESERVED_PLUGIN_APPROVAL_ID_PREFIX = "plugin:";
444950+function sanitizeCommandAnalysisSummary(
51+summary: CommandExplanationSummary,
52+): CommandExplanationSummary {
53+return {
54+commandCount: summary.commandCount,
55+nestedCommandCount: summary.nestedCommandCount,
56+riskKinds: summary.riskKinds.map((kind) => sanitizeExecApprovalWarningText(kind)),
57+warningLines: summary.warningLines.map((line) => sanitizeExecApprovalWarningText(line)),
58+};
59+}
60+61+function resolveExecApprovalCommandAnalysis(params: {
62+host: string;
63+commandText: string;
64+commandArgv?: string[];
65+cwd?: string | null;
66+}): CommandExplanationSummary | null {
67+const analysis =
68+Array.isArray(params.commandArgv) && params.commandArgv.length > 0
69+ ? analyzeCommandForPolicy({
70+source: "argv",
71+argv: params.commandArgv,
72+cwd: params.cwd ?? undefined,
73+})
74+ : params.host === "node"
75+ ? null
76+ : analyzeCommandForPolicy({
77+source: "shell",
78+command: params.commandText,
79+cwd: params.cwd ?? undefined,
80+});
81+if (!analysis?.ok) {
82+return null;
83+}
84+return sanitizeCommandAnalysisSummary(summarizeCommandSegmentsForDisplay(analysis.segments));
85+}
86+4587type ExecApprovalIosPushDelivery = {
4688handleRequested?: (request: ExecApprovalRequest) => Promise<boolean>;
4789handleResolved?: (resolved: ExecApprovalResolved) => Promise<void>;
@@ -207,6 +249,12 @@ export function createExecApprovalHandlers(
207249}
208250const envBinding = buildSystemRunApprovalEnvBinding(p.env);
209251const warningText = normalizeOptionalString(p.warningText);
252+const commandAnalysis = resolveExecApprovalCommandAnalysis({
253+ host,
254+commandText: effectiveCommandText,
255+commandArgv: effectiveCommandArgv,
256+cwd: effectiveCwd,
257+});
210258const systemRunBinding =
211259host === "node"
212260 ? buildSystemRunApprovalBinding({
@@ -241,6 +289,7 @@ export function createExecApprovalHandlers(
241289security: p.security ?? null,
242290ask: p.ask ?? null,
243291warningText: warningText ? sanitizeExecApprovalWarningText(warningText) : null,
292+ commandAnalysis,
244293allowedDecisions: resolveExecApprovalAllowedDecisions({ ask: p.ask ?? null }),
245294agentId: effectiveAgentId ?? null,
246295resolvedPath: p.resolvedPath ?? null,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。