simplify: remove workflow_dispatch/schedule from create-prompt

- Remove workflow_dispatch and schedule event handling from create-prompt
  since agent mode doesn't use the standard prompt generation flow
- Enforce mode compatibility at selection time in the registry instead
  of runtime validation in tag mode
- Add explanatory comment in agent mode about why prompt file is needed
- Update tests to reflect simplified event handling

This reduces code duplication and makes the separation between tag mode
(entity-based events) and agent mode (automation events) clearer.
This commit is contained in:
km-anthropic
2025-07-29 10:15:22 -07:00
parent 859e93f18e
commit 26d6ecc65d
8 changed files with 64 additions and 144 deletions

View File

@@ -350,24 +350,6 @@ export function prepareContext(
};
break;
case "workflow_dispatch":
eventData = {
eventName: "workflow_dispatch",
isPR: false,
...(baseBranch && { baseBranch }),
...(claudeBranch && { claudeBranch }),
};
break;
case "schedule":
eventData = {
eventName: "schedule",
isPR: false,
...(baseBranch && { baseBranch }),
...(claudeBranch && { claudeBranch }),
};
break;
default:
throw new Error(`Unsupported event type: ${eventName}`);
}
@@ -430,18 +412,6 @@ export function getEventTypeAndContext(envVars: PreparedContext): {
: `pull request event`,
};
case "workflow_dispatch":
return {
eventType: "WORKFLOW_DISPATCH",
triggerContext: `workflow dispatch event`,
};
case "schedule":
return {
eventType: "SCHEDULE",
triggerContext: `scheduled automation event`,
};
default:
throw new Error(`Unexpected event type`);
}

View File

@@ -88,20 +88,6 @@ type PullRequestEvent = {
baseBranch?: string;
};
type WorkflowDispatchEvent = {
eventName: "workflow_dispatch";
isPR?: false;
baseBranch?: string;
claudeBranch?: string;
};
type ScheduleEvent = {
eventName: "schedule";
isPR?: false;
baseBranch?: string;
claudeBranch?: string;
};
// Union type for all possible event types
export type EventData =
| PullRequestReviewCommentEvent
@@ -111,9 +97,7 @@ export type EventData =
| IssueOpenedEvent
| IssueAssignedEvent
| IssueLabeledEvent
| PullRequestEvent
| WorkflowDispatchEvent
| ScheduleEvent;
| PullRequestEvent;
// Combined type with separate eventData field
export type PreparedContext = CommonFields & {

View File

@@ -34,7 +34,7 @@ async function run() {
}
// Step 4: Get mode and check trigger conditions
const mode = getMode(context.inputs.mode);
const mode = getMode(context.inputs.mode, context);
const containsTrigger = mode.shouldTrigger(context);
// Set output for action.yml to check

View File

@@ -53,7 +53,10 @@ export const agentMode: Mode = {
recursive: true,
});
// Write the prompt - either override_prompt, direct_prompt, or a minimal default
// Write the prompt file - the base action requires a prompt_file parameter,
// so we must create this file even though agent mode typically uses
// override_prompt or direct_prompt. If neither is provided, we write
// a minimal prompt with just the repository information.
const promptContent =
context.inputs.overridePrompt ||
context.inputs.directPrompt ||

View File

@@ -13,6 +13,7 @@
import type { Mode, ModeName } from "./types";
import { tagMode } from "./tag";
import { agentMode } from "./agent";
import type { ParsedGitHubContext } from "../github/context";
export const DEFAULT_MODE = "tag" as const;
export const VALID_MODES = ["tag", "agent"] as const;
@@ -27,12 +28,13 @@ const modes = {
} as const satisfies Record<ModeName, Mode>;
/**
* Retrieves a mode by name.
* Retrieves a mode by name and validates it can handle the event type.
* @param name The mode name to retrieve
* @param context The GitHub context to validate against
* @returns The requested mode
* @throws Error if the mode is not found
* @throws Error if the mode is not found or cannot handle the event
*/
export function getMode(name: ModeName): Mode {
export function getMode(name: ModeName, context: ParsedGitHubContext): Mode {
const mode = modes[name];
if (!mode) {
const validModes = VALID_MODES.join("', '");
@@ -40,6 +42,18 @@ export function getMode(name: ModeName): Mode {
`Invalid mode '${name}'. Valid modes are: '${validModes}'. Please check your workflow configuration.`,
);
}
// Validate mode can handle the event type
if (
name === "tag" &&
(context.eventName === "workflow_dispatch" ||
context.eventName === "schedule")
) {
throw new Error(
`Tag mode cannot handle ${context.eventName} events. Use 'agent' mode for automation events.`,
);
}
return mode;
}

View File

@@ -53,17 +53,6 @@ export const tagMode: Mode = {
}: ModeOptions): Promise<ModeResult> {
// Tag mode handles entity-based events (issues, PRs, comments)
// Validate this mode can handle the event
if (
context.eventName === "workflow_dispatch" ||
context.eventName === "schedule"
) {
throw new Error(
`Tag mode cannot handle ${context.eventName} events. ` +
`Use 'agent' mode for automation events.`,
);
}
// Check if actor is human
await checkHumanActor(octokit.rest, context);