feat: add AI branch and commit generation to create command#15
Merged
feat: add AI branch and commit generation to create command#15
Conversation
There was a problem hiding this comment.
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/-imode todub 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
--aiworkflow 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 describesnameas a required branch name, but the function now acceptsstring | undefined(to support--ai). Update the@param namedescription to reflect that it may be omitted when--aiis 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 acceptsname: string | undefined, so this test no longer needs to forceundefinedthroughas unknown as string. Passingundefineddirectly 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 insrc/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.
65d60b4 to
e1eac25
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🥞 DubStack