From 4aaf0b8bfe59d23c334e2df75f522a558a2421d8 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:10:32 -0400 Subject: [PATCH] refactor(default-automation-rules): stringify typed config once at seed time --- src/main/default-automation-rules.ts | 46 +++++++++++++++------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/main/default-automation-rules.ts b/src/main/default-automation-rules.ts index 53bb4f9b..d0bf131b 100644 --- a/src/main/default-automation-rules.ts +++ b/src/main/default-automation-rules.ts @@ -1,12 +1,16 @@ -export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ +interface DefaultAutomationRule { name: string; description: string; trigger: string; action: string; - conditionsJson?: string; - actionConfigJson?: string; + /** Typed condition config. Stringified once at seed time. */ + conditions?: Record; + /** Typed action config. Stringified once at seed time. */ + actionConfig?: Record; priority?: number; -}> = [ +} + +export const DEFAULT_AUTOMATION_RULES: ReadonlyArray = [ { name: "Auto-assign new tasks", description: "Automatically assign new unassigned tasks to the best-fit agent based on capabilities and workload.", @@ -19,7 +23,7 @@ export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ description: "When a task is blocked, escalate to the assignee's manager.", trigger: "task_blocked", action: "escalate_to_manager", - actionConfigJson: JSON.stringify({ body: "A task assigned to your report is blocked and needs your attention." }), + actionConfig: { body: "A task assigned to your report is blocked and needs your attention." }, priority: 85, }, { @@ -27,7 +31,7 @@ export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ description: "When a run completes successfully, escalate to the assignee's manager so they can review the completed work.", trigger: "run_completed", action: "escalate_to_manager", - actionConfigJson: JSON.stringify({ body: "A task run has completed successfully. The task has moved to review status. Please review and either approve (mark as done) or send back with feedback." }), + actionConfig: { body: "A task run has completed successfully. The task has moved to review status. Please review and either approve (mark as done) or send back with feedback." }, priority: 80, }, { @@ -35,7 +39,7 @@ export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ description: "When a run fails after exhausting retries, attempt to reassign the task to another capable agent.", trigger: "run_failed", action: "reassign_task", - conditionsJson: JSON.stringify({ afterRetryExhaustion: true }), + conditions: { afterRetryExhaustion: true }, priority: 75, }, { @@ -43,7 +47,7 @@ export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ description: "Send an alert when an agent reaches 80% of their monthly budget.", trigger: "budget_threshold", action: "send_message", - actionConfigJson: JSON.stringify({ subject: "Budget warning", body: "Agent is approaching budget limit (80% utilized).", priority: "urgent" }), + actionConfig: { subject: "Budget warning", body: "Agent is approaching budget limit (80% utilized).", priority: "urgent" }, priority: 70, }, { @@ -51,7 +55,7 @@ export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ description: "When a run completes successfully, send a status update to the agent's department channel.", trigger: "run_completed", action: "send_message", - actionConfigJson: JSON.stringify({ channel: "department", subject: "Task completed", body: "A task has been completed successfully. Check the task details for more information.", priority: "low" }), + actionConfig: { channel: "department", subject: "Task completed", body: "A task has been completed successfully. Check the task details for more information.", priority: "low" }, priority: 40, }, { @@ -59,16 +63,16 @@ export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ description: "When a new agent hire is approved, immediately wake the new agent to start onboarding.", trigger: "hire_approved", action: "trigger_heartbeat", - actionConfigJson: JSON.stringify({}), + actionConfig: {}, priority: 90, }, { name: "Auto-run assigned tasks", description: "When a task transitions to 'todo' status, automatically wake the assigned agent to start working on it.", trigger: "task_status_changed", - conditionsJson: JSON.stringify({ status: "todo" }), + conditions: { status: "todo" }, action: "run_task", - actionConfigJson: JSON.stringify({}), + actionConfig: {}, priority: 65, }, { @@ -76,7 +80,7 @@ export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ description: "When a sprint starts, notify the entire company.", trigger: "sprint_started", action: "send_message", - actionConfigJson: JSON.stringify({ channel: "company", subject: "Sprint started", body: "A new sprint has begun. Check your assigned tasks and start execution.", priority: "normal" }), + actionConfig: { channel: "company", subject: "Sprint started", body: "A new sprint has begun. Check your assigned tasks and start execution.", priority: "normal" }, priority: 50, }, { @@ -84,7 +88,7 @@ export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ description: "When a sprint ends, schedule a retrospective meeting.", trigger: "sprint_ended", action: "schedule_meeting", - actionConfigJson: JSON.stringify({ meetingType: "retrospective", title: "Sprint Retrospective", durationMinutes: 45 }), + actionConfig: { meetingType: "retrospective", title: "Sprint Retrospective", durationMinutes: 45 }, priority: 55, }, { @@ -105,18 +109,18 @@ export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ name: "Wake manager when task moves to review", description: "When a task status changes to in_review, wake the assignee's manager to review the work.", trigger: "task_status_changed", - conditionsJson: JSON.stringify({ status: "in_review" }), + conditions: { status: "in_review" }, action: "escalate_to_manager", - actionConfigJson: JSON.stringify({ body: "A task from your report has been submitted for review. Please review the work and either approve (mark as done) or send back with feedback." }), + actionConfig: { body: "A task from your report has been submitted for review. Please review the work and either approve (mark as done) or send back with feedback." }, priority: 82, }, { name: "Wake assigned agent on task feedback", description: "When a reviewed task is sent back to in_progress with feedback, wake the assigned agent to address the feedback.", trigger: "task_status_changed", - conditionsJson: JSON.stringify({ status: "in_progress", previousStatus: "in_review" }), + conditions: { status: "in_progress", previousStatus: "in_review" }, action: "trigger_heartbeat", - actionConfigJson: JSON.stringify({}), + actionConfig: {}, priority: 78, }, { @@ -124,7 +128,7 @@ export const DEFAULT_AUTOMATION_RULES: ReadonlyArray<{ description: "When a new approval request is created and not auto-approved, escalate to the requesting agent's manager for review.", trigger: "approval_created", action: "escalate_to_manager", - actionConfigJson: JSON.stringify({ body: "A new approval request needs your review. Please check the Approvals section." }), + actionConfig: { body: "A new approval request needs your review. Please check the Approvals section." }, priority: 88, }, ]; @@ -156,9 +160,9 @@ export function seedDefaultAutomationRules( name: rule.name, description: rule.description, trigger: rule.trigger, - conditionsJson: rule.conditionsJson ?? "{}", + conditionsJson: JSON.stringify(rule.conditions ?? {}), action: rule.action, - actionConfigJson: rule.actionConfigJson ?? "{}", + actionConfigJson: JSON.stringify(rule.actionConfig ?? {}), priority: rule.priority ?? 50, status: "active", });