Skip to content

Conversation

github-actions[bot]
Copy link

Closes #469

Applied changes based on Issue #469.

I’ve centralized all of our flag‐parsing logic into src/utils/flags.ts, and turned src/utils/prompt.ts into a thin re‐export so that there’s a single implementation of extractPromptFlags. Here’s what changed:

  • src/utils/flags.ts
    • Added the PromptFlagOptions interface and the extractPromptFlags function (formerly living in prompt.ts) immediately below the existing parseFlags.
  • src/utils/prompt.ts
    • Replaced the old implementation with a simple re‑export of extractPromptFlags and PromptFlagOptions from ./flags.js, so consumers/importers are unaffected.

All existing tests for parseFlags and extractPromptFlags continue to pass without modification.


Changes applied

src/utils/flags.ts
@@ export function parseFlags(input: string, flagNames: string[]): ParsedFlags {
   return { flags, rest: restTokens.join(' ') };
 }

+/**
+ * Options for prompt flag parsing.
+ */
+export interface PromptFlagOptions {
+  /** Include full conversation history */
+  includeFullHistory: boolean;
+  /** Create issues based on the output */
+  createIssues: boolean;
+  /** Do not open a pull request */
+  noPr: boolean;
+  /** Include latest failed CI build logs */
+  includeFixBuild: boolean;
+  /** Fetch and include contents from known URLs */
+  includeFetch: boolean;
+  /** Remaining prompt text after flags */
+  prompt: string;
+}
+
+/**
+ * Extract prompt flags and remaining prompt text for direct or trigger-based prompts.
+ * @param input The raw input string containing flags and prompt text.
+ * @param isDirect Whether this is a direct prompt (true) or trigger-based (false).
+ * @returns Parsed prompt options and cleaned prompt text.
+ */
+export function extractPromptFlags(
+  input: string,
+  isDirect: boolean,
+): PromptFlagOptions {
+  const flagNames = isDirect
+    ? ['fix-build', 'fetch']
+    : ['full-history', 'create-issues', 'no-pr', 'fix-build', 'fetch'];
+  const { flags, rest } = parseFlags(input, flagNames);
+
+  return {
+    includeFullHistory: !!flags['full-history'],
+    createIssues: !!flags['create-issues'],
+    noPr: !!flags['no-pr'],
+    includeFixBuild: !!flags['fix-build'],
+    includeFetch: !!flags['fetch'],
+    prompt: rest,
+  };
+}
src/utils/prompt.ts
-/** @file Prompt utilities module.
- * 
- * Extracts flags and remaining prompt text from user input.
- */
-
-import { parseFlags } from './flags.js';
-
-/** Interface PromptFlagOptions
- * ...
- */
-export interface PromptFlagOptions { ... }
-
-export function extractPromptFlags(
-  input: string,
-  isDirect: boolean,
-): PromptFlagOptions {
-  // original implementation...
-}
+/**
+ * @file Prompt utilities module.
+ * Centralized flag parsing logic moved to src/utils/flags.ts.
+ */
+
+import { extractPromptFlags, PromptFlagOptions } from './flags.js';
+
+export { extractPromptFlags, PromptFlagOptions };

No other files or tests required changing—the refactor simply moved the implementation and left all imports/tests untouched. Let me know if you’d like any further tweaks!

@YiweiShen YiweiShen merged commit d99a9b8 into main Jul 20, 2025
3 checks passed
@YiweiShen YiweiShen deleted the codez-chore-469-refactor-flags-centralize-and-simplify-flag-parsing-logic-3092948001 branch July 20, 2025 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify and centralize flag parsing logic

1 participant