Files
claude-code-action/src/modes/types.ts
Ashwin Bhat e8e8fdc051 feat: merge prepare and run steps into unified entry point
Consolidates the two-step architecture (prepare → run) into a single
step to eliminate file-based and output-based communication.

Changes:
- Add base-action/src/lib.ts with exports for main action import
- Modify run-claude-sdk.ts to accept prompt string directly and return result
- Add generatePromptContent() that returns prompt without file I/O
- Update mode prepare() to return promptContent in result
- Create src/entrypoints/run.ts as unified entry point
- Update action.yml to use single Run Claude Code step
- Update output references from steps.prepare to steps.claude-code

Benefits:
- No file I/O for prompt - data stays in memory
- No step output parsing - direct function returns
- Simpler debugging - single entry point
- Faster execution - no subprocess overhead
- Type safety - TypeScript across the boundary

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-23 11:32:00 -08:00

107 lines
2.8 KiB
TypeScript

import type { GitHubContext } from "../github/context";
import type { PreparedContext } from "../create-prompt/types";
import type { FetchDataResult } from "../github/data/fetcher";
import type { Octokits } from "../github/api/client";
export type ModeName = "tag" | "agent";
export type ModeContext = {
mode: ModeName;
githubContext: GitHubContext;
commentId?: number;
baseBranch?: string;
claudeBranch?: string;
};
export type ModeData = {
commentId?: number;
baseBranch?: string;
claudeBranch?: string;
};
/**
* Mode interface for claude-code-action execution modes.
* Each mode defines its own behavior for trigger detection, prompt generation,
* and tracking comment creation.
*
* Current modes include:
* - 'tag': Interactive mode triggered by @claude mentions
* - 'agent': Direct automation mode triggered by explicit prompts
*/
export type Mode = {
name: ModeName;
description: string;
/**
* Determines if this mode should trigger based on the GitHub context
*/
shouldTrigger(context: GitHubContext): boolean;
/**
* Prepares the mode context with any additional data needed for prompt generation
*/
prepareContext(context: GitHubContext, data?: ModeData): ModeContext;
/**
* Returns the list of tools that should be allowed for this mode
*/
getAllowedTools(): string[];
/**
* Returns the list of tools that should be disallowed for this mode
*/
getDisallowedTools(): string[];
/**
* Determines if this mode should create a tracking comment
*/
shouldCreateTrackingComment(): boolean;
/**
* Generates the prompt for this mode.
* @returns The complete prompt string
*/
generatePrompt(
context: PreparedContext,
githubData: FetchDataResult,
useCommitSigning: boolean,
): string;
/**
* Prepares the GitHub environment for this mode.
* Each mode decides how to handle different event types.
* @returns PrepareResult with commentId, branchInfo, and mcpConfig
*/
prepare(options: ModeOptions): Promise<ModeResult>;
/**
* Returns an optional system prompt to append to Claude's base system prompt.
* This allows modes to add mode-specific instructions.
* @returns The system prompt string or undefined if no additional prompt is needed
*/
getSystemPrompt?(context: ModeContext): string | undefined;
};
// Define types for mode prepare method
export type ModeOptions = {
context: GitHubContext;
octokit: Octokits;
githubToken: string;
};
export type ModeResult = {
commentId?: number;
branchInfo: {
baseBranch: string;
claudeBranch?: string;
currentBranch: string;
};
mcpConfig: string;
/** Generated prompt content for Claude */
promptContent?: string;
/** Comma-separated list of allowed tools */
allowedTools?: string;
/** Comma-separated list of disallowed tools */
disallowedTools?: string;
};