Customizable Source Control AI action recipes with per-action agent and command templates (#4868)

* WIP: Changes before auto-review fixes

* Customize Source Control AI action recipes

- Add per-action CLI arguments for generation and launch flows so saved
  recipes can select model flags without putting prompts in argv.
- Share the text-generation dialog between commit messages and hosted-review
  details, with first-run defaults and repo/global recipe support.
- Launch fix-check agents directly from saved recipes and harden prompt/template
  handling for invalid args, blank prompts, and inherited variables.

* Allow custom commands for source control action recipes

- Let text action recipes save and resolve the custom-command sentinel
- Add settings UI for custom command recipes and preserve per-action defaults
- Split large source-control dialogs and direct launch helpers into focused modules
- Keep launch actions from treating custom text agents as runnable TUI agents

* Add per-repo Source Control AI enablement, custom command, and save-targ

- Repo overrides now support `enabled` and `customAgentCommand`, letting
  repositories opt in/out of Source Control AI independently and supply a
  repo-scoped custom command that takes precedence over the global one.
- Recipe-save dialogs gained a save-target selector ("Don't save / Save for
  this repo / Save as global default") replacing the old boolean checkbox,
  routing saves through the new `saveSourceControlActionRecipe` helper in
  `source-control-ai-recipe-save.ts`.
- `normalizeRepoSourceControlAiOverrides` now returns `undefined` for empty
  objects and passes the `null` sentinel through the IPC/RPC layer so the
  persistence layer can clear repo overrides cleanly.
- `resolveSourceControlLaunchPlatform` resolves the correct shell platform
  for SSH and WSL worktrees so agent launch commands are built correctly.
- Settings UI gained `RepositorySourceControlAiEnablement` and
  `RepositorySourceControlAiCustomCommand` rows; draft/label logic was
  extracted into focused modules to stay within lint line limits.

* Extract action recipe defaults into own component and use id-prefixed wo

- Move action recipe draft state and UI out of CommitMessageAiPane into SourceControlAiActionRecipeDefaults and source-control-ai-action-recipe-draft.ts to respect the max-lines lint rule
- Use toRuntimeWorktreeSelector() across all runtime git RPC calls so the runtime can resolve worktrees by ID rather than path
- Fix SSH launch platform resolution to use the repo's connection when the newly created worktree isn't hydrated yet
- Add edit and delete handlers for PR conversation comments with confirmation dialog
- Use text-status-success design token instead of hardcoded text-emerald-500

* add more search keyword

* Rename "Enable Source Control AI defaults" to "Show Source Control AI ac

* fix test

* Remove unused imports and variable assignment in launch-work-item-direct

* Fix test mocks to use `mocks.store` instead of `storeState.value` for di

* Extract Source Control AI logic into focused modules with fix-checks dia

---------

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinjing
2026-06-08 14:08:35 -07:00
committed by GitHub
co-authored by Orca
parent c16e7044aa
commit 006a4ef3a5
96 changed files with 9985 additions and 3978 deletions
+63 -52
View File
@@ -1,6 +1,7 @@
/* eslint-disable max-lines -- Why: this table is the runtime git RPC contract; splitting it would make method coverage harder to audit. */
import { defineMethod, type RpcMethod } from '../core'
import type { GlobalSettings } from '../../../../shared/types'
import type { ResolvedSourceControlAiGenerationParams } from '../../../../shared/source-control-ai'
import {
GitBranchCompare,
GitBranchDiff,
@@ -23,6 +24,62 @@ import {
WorktreeSelector
} from './git-params'
type CommitMessageGenerationOverride = {
commitMessageAi?: GlobalSettings['commitMessageAi']
sourceControlAi?: GlobalSettings['sourceControlAi']
sourceControlAiResolvedParams?: ResolvedSourceControlAiGenerationParams
agentCmdOverrides?: GlobalSettings['agentCmdOverrides']
enableGitHubAttribution?: boolean
commitMessageDiscoveryHostKey?: string
}
// Why: generateCommitMessage and generatePullRequestFields share the same optional
// override fields; returning undefined when none are set keeps the no-override call path.
function buildCommitMessageGenerationOverride(params: {
commitMessageAi?: unknown
sourceControlAi?: unknown
sourceControlAiResolvedParams?: unknown
agentCmdOverrides?: unknown
enableGitHubAttribution?: boolean
commitMessageDiscoveryHostKey?: string
}): CommitMessageGenerationOverride | undefined {
if (
params.commitMessageAi === undefined &&
params.sourceControlAi === undefined &&
params.sourceControlAiResolvedParams === undefined &&
params.agentCmdOverrides === undefined &&
params.enableGitHubAttribution === undefined &&
params.commitMessageDiscoveryHostKey === undefined
) {
return undefined
}
return {
...(params.commitMessageAi !== undefined
? { commitMessageAi: params.commitMessageAi as GlobalSettings['commitMessageAi'] }
: {}),
...(params.sourceControlAi !== undefined
? { sourceControlAi: params.sourceControlAi as GlobalSettings['sourceControlAi'] }
: {}),
...(params.sourceControlAiResolvedParams !== undefined
? {
sourceControlAiResolvedParams:
params.sourceControlAiResolvedParams as ResolvedSourceControlAiGenerationParams
}
: {}),
...(params.agentCmdOverrides !== undefined
? {
agentCmdOverrides: params.agentCmdOverrides as GlobalSettings['agentCmdOverrides']
}
: {}),
...(params.enableGitHubAttribution !== undefined
? { enableGitHubAttribution: params.enableGitHubAttribution }
: {}),
...(params.commitMessageDiscoveryHostKey !== undefined
? { commitMessageDiscoveryHostKey: params.commitMessageDiscoveryHostKey }
: {})
}
}
export const GIT_METHODS: RpcMethod[] = [
defineMethod({
name: 'git.status',
@@ -166,34 +223,11 @@ export const GIT_METHODS: RpcMethod[] = [
name: 'git.generateCommitMessage',
params: GitGenerateCommitMessage,
handler: async (params, { runtime }) => {
if (
params.commitMessageAi === undefined &&
params.sourceControlAi === undefined &&
params.agentCmdOverrides === undefined &&
params.enableGitHubAttribution === undefined &&
params.commitMessageDiscoveryHostKey === undefined
) {
const override = buildCommitMessageGenerationOverride(params)
if (override === undefined) {
return runtime.generateRuntimeCommitMessage(params.worktree)
}
return runtime.generateRuntimeCommitMessage(params.worktree, {
...(params.commitMessageAi !== undefined
? { commitMessageAi: params.commitMessageAi as GlobalSettings['commitMessageAi'] }
: {}),
...(params.sourceControlAi !== undefined
? { sourceControlAi: params.sourceControlAi as GlobalSettings['sourceControlAi'] }
: {}),
...(params.agentCmdOverrides !== undefined
? {
agentCmdOverrides: params.agentCmdOverrides as GlobalSettings['agentCmdOverrides']
}
: {}),
...(params.enableGitHubAttribution !== undefined
? { enableGitHubAttribution: params.enableGitHubAttribution }
: {}),
...(params.commitMessageDiscoveryHostKey !== undefined
? { commitMessageDiscoveryHostKey: params.commitMessageDiscoveryHostKey }
: {})
})
return runtime.generateRuntimeCommitMessage(params.worktree, override)
}
}),
defineMethod({
@@ -226,34 +260,11 @@ export const GIT_METHODS: RpcMethod[] = [
body: params.body,
draft: params.draft
}
if (
params.commitMessageAi === undefined &&
params.sourceControlAi === undefined &&
params.agentCmdOverrides === undefined &&
params.enableGitHubAttribution === undefined &&
params.commitMessageDiscoveryHostKey === undefined
) {
const override = buildCommitMessageGenerationOverride(params)
if (override === undefined) {
return runtime.generateRuntimePullRequestFields(params.worktree, input)
}
return runtime.generateRuntimePullRequestFields(params.worktree, input, {
...(params.commitMessageAi !== undefined
? { commitMessageAi: params.commitMessageAi as GlobalSettings['commitMessageAi'] }
: {}),
...(params.sourceControlAi !== undefined
? { sourceControlAi: params.sourceControlAi as GlobalSettings['sourceControlAi'] }
: {}),
...(params.agentCmdOverrides !== undefined
? {
agentCmdOverrides: params.agentCmdOverrides as GlobalSettings['agentCmdOverrides']
}
: {}),
...(params.enableGitHubAttribution !== undefined
? { enableGitHubAttribution: params.enableGitHubAttribution }
: {}),
...(params.commitMessageDiscoveryHostKey !== undefined
? { commitMessageDiscoveryHostKey: params.commitMessageDiscoveryHostKey }
: {})
})
return runtime.generateRuntimePullRequestFields(params.worktree, input, override)
}
}),
defineMethod({