From e892bf3366e1055118697d4f59c4e659e2a6c946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 16 Apr 2026 23:27:29 -0400 Subject: [PATCH] refactor(main): simplify escalation trigger map + unify api-section curl guidance - P3-52: replace 5-deep if-chain in deriveEscalationWakeTrigger with two lookup maps (status takes precedence over rule trigger), which removes the cognitive overhead of reading the chain and makes the two inputs' roles explicit. - P3-53: rewrite the Windows-only curl warning as platform-neutral guidance that matches the surrounding examples. The old text said 'prefer fetch on Windows' while the doc showed curl POSTs everywhere; the new text recommends fetch universally and explains when the curl temp-file pattern is needed. --- src/main/automation/automation-actions.ts | 15 +++++++++++---- src/main/prompt-builder/api-section.ts | 6 +++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/automation/automation-actions.ts b/src/main/automation/automation-actions.ts index 89ff9346..68d347f4 100644 --- a/src/main/automation/automation-actions.ts +++ b/src/main/automation/automation-actions.ts @@ -20,11 +20,18 @@ function deriveHeartbeatWakeTrigger(triggerType: string, previousStatus: string } // Map the run/state combination → wake trigger for escalation to manager. +// Status-based mapping takes precedence; rule-trigger mapping is the fallback. +const ESCALATION_STATUS_TRIGGER_MAP: Record = { + in_review: "subtask_completed", + blocked: "report_blocked", +}; +const ESCALATION_RULE_TRIGGER_MAP: Record = { + run_completed: "subtask_completed", + run_failed: "report_failed", +}; function deriveEscalationWakeTrigger(newStatus: string | null, ruleTrigger: string | null): string { - if (newStatus === "in_review") return "subtask_completed"; - if (newStatus === "blocked") return "report_blocked"; - if (ruleTrigger === "run_completed") return "subtask_completed"; - if (ruleTrigger === "run_failed") return "report_failed"; + if (newStatus && ESCALATION_STATUS_TRIGGER_MAP[newStatus]) return ESCALATION_STATUS_TRIGGER_MAP[newStatus]; + if (ruleTrigger && ESCALATION_RULE_TRIGGER_MAP[ruleTrigger]) return ESCALATION_RULE_TRIGGER_MAP[ruleTrigger]; return "report_blocked"; } diff --git a/src/main/prompt-builder/api-section.ts b/src/main/prompt-builder/api-section.ts index 58052dd1..390e08ae 100644 --- a/src/main/prompt-builder/api-section.ts +++ b/src/main/prompt-builder/api-section.ts @@ -13,9 +13,9 @@ Every API call MUST include these headers: Content-Type: application/json; charset=utf-8 X-Agent-Company-Run-Id: ${ctx.runId} -IMPORTANT: On Windows, prefer using Node.js fetch() for API calls instead of curl, -because curl on Windows may corrupt non-ASCII characters (Chinese, Japanese, etc.). -If you must use curl, write the JSON body to a temp file first and use curl -d @file. +Prefer Node.js fetch() over curl so non-ASCII bodies (Chinese, Japanese, etc.) are transmitted +correctly across all platforms. When curl is the only option, write the JSON body to a temp +file first and pass it via \`-d @file\` (shown in the POST example below). Example using fetch (Node.js) — PREFERRED: const res = await fetch(\`\${process.env.AGENT_COMPANY_API_URL}/api/agents/me\`, {