Skip to content

feat: add AI branch and commit generation to create command#15

Merged
dubscode merged 4 commits intomainfrom
feat/create-ai-generation
Feb 21, 2026
Merged

feat: add AI branch and commit generation to create command#15
dubscode merged 4 commits intomainfrom
feat/create-ai-generation

Conversation

@dubscode
Copy link
Copy Markdown
Contributor

@dubscode dubscode commented Feb 21, 2026


🥞 DubStack

Copilot AI review requested due to automatic review settings February 21, 2026 22:33
@dubscode dubscode changed the base branch from feat/ai-thinking-stream to main February 21, 2026 22:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an AI-assisted mode to dub create so users can generate a stacked branch name and Conventional Commit message from staged changes, while also tightening branch-name validation.

Changes:

  • Add --ai/-i mode to dub create, making the branch argument optional and generating branch+commit metadata from the staged diff.
  • Introduce isValidBranchName() (git ref-format validation) and apply it during create.
  • Update tests and docs (README/Quickstart) to cover the new --ai workflow and option-combo rules.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/lib/git.ts Adds isValidBranchName() helper using git check-ref-format.
src/lib/git.test.ts Adds unit tests for isValidBranchName().
src/index.ts Updates create CLI: optional branch arg + new --ai option + revised help text.
src/commands/create.ts Implements AI branch/commit generation from staged diff; validates generated/manual branch names.
src/commands/create.test.ts Adds coverage for create --ai behavior and config gating.
README.md Updates dub create docs and examples for optional branch + --ai.
QUICKSTART.md Adds --ai examples to the quickstart flow.
Comments suppressed due to low confidence (3)

src/commands/create.ts:61

  • The JSDoc for create() still describes name as a required branch name, but the function now accepts string | undefined (to support --ai). Update the @param name description to reflect that it may be omitted when --ai is used (and required otherwise), so the docs match runtime behavior.
 * @param name - Name of the new branch to create
 * @param cwd - Working directory (auto-initializes if needed)
 * @param options - Optional create flags
 * @returns The created branch name, its parent, and committed message if applicable
 * @throws {DubError} If branch exists, HEAD is detached, invalid option combos, or nothing to commit

src/commands/create.test.ts:205

  • The create() signature now accepts name: string | undefined, so this test no longer needs to force undefined through as unknown as string. Passing undefined directly keeps the test type-safe and avoids masking real typing issues.
    const result = await create(
      undefined as unknown as string,
      dir,
      { ai: true },
      {
        generateText,
        createGoogleGenerativeAI,

src/commands/create.ts:244

  • resolveModel() duplicates the provider-selection logic (env var precedence + model IDs + error message) that already exists in src/commands/ai.ts. Consider extracting a shared helper (e.g. src/lib/ai-model.ts) and reusing it here to avoid the two implementations drifting (different model IDs, env vars, or error text).
function resolveModel(deps: CreateDependencies): {
  provider: 'google' | 'gateway';
  model: LanguageModel;
  modelId: string;
} {
  const geminiApiKey = process.env.DUBSTACK_GEMINI_API_KEY?.trim();
  if (geminiApiKey) {
    const google = deps.createGoogleGenerativeAI({ apiKey: geminiApiKey });
    return {
      provider: 'google',
      model: google('gemini-3-flash'),
      modelId: 'gemini-3-flash',
    };
  }

  const gatewayApiKey = process.env.DUBSTACK_AI_GATEWAY_API_KEY?.trim();
  if (gatewayApiKey) {
    const gateway = deps.createGateway({ apiKey: gatewayApiKey });
    return {
      provider: 'gateway',
      model: gateway('google/gemini-3-flash'),
      modelId: 'google/gemini-3-flash',
    };
  }

  throw new DubError(
    "AI assistant requires DUBSTACK_GEMINI_API_KEY or DUBSTACK_AI_GATEWAY_API_KEY. Run 'dub ai env --gemini-key <key>' or 'dub ai env --gateway-key <key>'.",
  );
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/commands/create.ts
@dubscode dubscode force-pushed the feat/create-ai-generation branch from 65d60b4 to e1eac25 Compare February 21, 2026 22:45
@dubscode dubscode merged commit c531b42 into main Feb 21, 2026
3 checks passed
@dubscode dubscode deleted the feat/create-ai-generation branch February 21, 2026 22:49
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.

2 participants