fix(git): materialize draft session for generate#3
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors session creation and context resolution by introducing a reusable materializeOpenDraftSession helper and transitioning to asynchronous generation session context resolution. Feedback on these changes includes improving type safety and code reuse by leveraging resolveDirectoryKey instead of accessing created.directory directly, simplifying folder assignment logic by reusing the normalized createdDirectory variable, and applying optional chaining to lastChoice.modelID for consistency.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| persistDraftTarget({ | ||
| projectId: draftProjectId, | ||
| directory: normalizePath(draftDirectoryOverride ?? created.directory ?? null), | ||
| }) | ||
|
|
||
| const draftSyntheticParts = draft.syntheticParts | ||
| const createdDirectory = normalizePath(draftDirectoryOverride ?? created.directory ?? null) |
There was a problem hiding this comment.
Instead of accessing created.directory directly (which is not type-safe on the Session object and doesn't handle fallback fields like project.worktree), we should leverage the existing resolveDirectoryKey helper. We can define createdDirectory first and reuse it for both persistDraftTarget and subsequent operations to keep the code DRY and robust.
| persistDraftTarget({ | |
| projectId: draftProjectId, | |
| directory: normalizePath(draftDirectoryOverride ?? created.directory ?? null), | |
| }) | |
| const draftSyntheticParts = draft.syntheticParts | |
| const createdDirectory = normalizePath(draftDirectoryOverride ?? created.directory ?? null) | |
| const createdDirectory = normalizePath(draftDirectoryOverride) ?? resolveDirectoryKey(created) | |
| persistDraftTarget({ | |
| projectId: draftProjectId, | |
| directory: createdDirectory, | |
| }) | |
| const draftSyntheticParts = draft.syntheticParts |
| if (draftTargetFolderId) { | ||
| const scopeKey = draftDirectoryOverride || created.directory || null | ||
| if (scopeKey) { | ||
| useSessionFoldersStore.getState().addSessionToFolder(scopeKey, draftTargetFolderId, created.id) | ||
| } | ||
| } |
There was a problem hiding this comment.
We can simplify this block by reusing the already resolved and normalized createdDirectory variable instead of duplicating the fallback logic with draftDirectoryOverride || created.directory || null.
if (draftTargetFolderId && createdDirectory) {
useSessionFoldersStore.getState().addSessionToFolder(createdDirectory, draftTargetFolderId, created.id)
}| const lastChoiceModel = lastChoice?.providerID && lastChoice.modelID | ||
| ? { providerId: lastChoice.providerID, modelId: lastChoice.modelID } | ||
| : null; |
There was a problem hiding this comment.
For better type safety and consistency, use optional chaining on lastChoice.modelID as well. This prevents potential static analysis or TypeScript compiler warnings under strict null-checking configurations.
| const lastChoiceModel = lastChoice?.providerID && lastChoice.modelID | |
| ? { providerId: lastChoice.providerID, modelId: lastChoice.modelID } | |
| : null; | |
| const lastChoiceModel = lastChoice?.providerID && lastChoice?.modelID | |
| ? { providerId: lastChoice.providerID, modelId: lastChoice.modelID } | |
| : null; |
No description provided.