|
1 | | -import { |
2 | | - summarizeCommandSegmentsForDisplay, |
3 | | - type CommandExplanationSummary, |
4 | | -} from "../../infra/command-analysis/explain.js"; |
5 | | -import { analyzeCommandForPolicy } from "../../infra/command-analysis/policy.js"; |
| 1 | +import { resolveCommandAnalysisSummaryForDisplay } from "../../infra/command-analysis/explain.js"; |
6 | 2 | import { |
7 | 3 | resolveExecApprovalCommandDisplay, |
8 | 4 | sanitizeExecApprovalDisplayText, |
@@ -47,43 +43,6 @@ const APPROVAL_ALLOW_ALWAYS_UNAVAILABLE_DETAILS = { |
47 | 43 | } as const; |
48 | 44 | const RESERVED_PLUGIN_APPROVAL_ID_PREFIX = "plugin:"; |
49 | 45 |
|
50 | | -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 | | - |
87 | 46 | type ExecApprovalIosPushDelivery = { |
88 | 47 | handleRequested?: (request: ExecApprovalRequest) => Promise<boolean>; |
89 | 48 | handleResolved?: (resolved: ExecApprovalResolved) => Promise<void>; |
@@ -249,11 +208,12 @@ export function createExecApprovalHandlers( |
249 | 208 | } |
250 | 209 | const envBinding = buildSystemRunApprovalEnvBinding(p.env); |
251 | 210 | const warningText = normalizeOptionalString(p.warningText); |
252 | | - const commandAnalysis = resolveExecApprovalCommandAnalysis({ |
| 211 | + const commandAnalysis = resolveCommandAnalysisSummaryForDisplay({ |
253 | 212 | host, |
254 | 213 | commandText: effectiveCommandText, |
255 | 214 | commandArgv: effectiveCommandArgv, |
256 | 215 | cwd: effectiveCwd, |
| 216 | + sanitizeText: sanitizeExecApprovalWarningText, |
257 | 217 | }); |
258 | 218 | const systemRunBinding = |
259 | 219 | host === "node" |
|
0 commit comments