-
Notifications
You must be signed in to change notification settings - Fork 352
feat: infer task names from providers #1625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kchung
wants to merge
6
commits into
generalaction:main
Choose a base branch
from
kchung:model-branch-names
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fcc149a
feat(shared): add utilityCliArgs to provider registry
kchung 9a75e91
feat(main): add TaskNamingService for CLI-based task name inference
kchung e8d6092
feat(main): add task naming IPC handler
kchung cf07ac7
feat(renderer): wire up utility model task naming
kchung 4ec7742
test(main): add TaskNamingService tests
kchung aec600b
test(main): use generic provider ID in TaskNamingService tests
kchung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { ipcMain, BrowserWindow } from 'electron'; | ||
| import { inferTaskNameFromProvider } from '../services/TaskNamingService'; | ||
| import { log } from '../lib/logger'; | ||
|
|
||
| export function registerTaskNamingIpc(): void { | ||
| /** | ||
| * Fire-and-forget task name inference via provider CLI. | ||
| * Returns immediately; pushes 'task:nameInferred' to the renderer when done. | ||
| */ | ||
| ipcMain.handle( | ||
| 'task:inferName', | ||
| async ( | ||
| event, | ||
| args: { | ||
| taskId: string; | ||
| providerId: string; | ||
| initialPrompt: string; | ||
| projectPath: string; | ||
| } | ||
| ) => { | ||
| const { taskId, providerId, initialPrompt, projectPath } = args; | ||
|
|
||
| void inferTaskNameFromProvider(providerId, initialPrompt, projectPath) | ||
| .then((name) => { | ||
| const win = BrowserWindow.fromWebContents(event.sender); | ||
| if (!win || win.isDestroyed()) return; | ||
| win.webContents.send('task:nameInferred', { taskId, name }); | ||
| }) | ||
| .catch((err: unknown) => { | ||
| log.warn(`[TaskNaming] unexpected error for task ${taskId}: ${String(err)}`); | ||
| const win = BrowserWindow.fromWebContents(event.sender); | ||
| if (!win || win.isDestroyed()) return; | ||
| win.webContents.send('task:nameInferred', { taskId, name: null }); | ||
| }); | ||
|
|
||
| return { accepted: true }; | ||
| } | ||
| ); | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { spawn } from 'child_process'; | ||
| import { resolveProviderCommandConfig } from './ptyManager'; | ||
| import { log } from '../lib/logger'; | ||
|
|
||
| const NAMING_PROMPT = | ||
| 'Output only a short git branch name slug for the following task description. ' + | ||
| 'Rules: lowercase letters, numbers, and hyphens only; no spaces; max 40 characters; ' + | ||
| 'no leading or trailing hyphens; be concise and descriptive. ' + | ||
| 'Output the slug and nothing else.\n\nTask: '; | ||
|
|
||
| const TIMEOUT_MS = 15_000; | ||
| const MAX_STDOUT_BYTES = 4096; | ||
|
|
||
| function normalizeSlug(raw: string): string | null { | ||
| const slug = raw | ||
| .trim() | ||
| .toLowerCase() | ||
| .split('\n')[0] // take first line only | ||
| .replace(/[^a-z0-9-]/g, '-') | ||
| .replace(/-+/g, '-') | ||
| .replace(/^-+|-+$/g, '') | ||
| .slice(0, 40); | ||
|
|
||
| return slug.length >= 3 ? slug : null; | ||
| } | ||
|
|
||
| export async function inferTaskNameFromProvider( | ||
| providerId: string, | ||
| initialPrompt: string, | ||
| cwd: string | ||
| ): Promise<string | null> { | ||
| const resolved = resolveProviderCommandConfig(providerId); | ||
| if (!resolved) return null; | ||
|
|
||
| const { provider, cli } = resolved; | ||
| if (!provider.utilityCliArgs) return null; | ||
|
|
||
| const args = [...provider.utilityCliArgs, `${NAMING_PROMPT}${initialPrompt}`]; | ||
|
|
||
| return new Promise((resolve) => { | ||
| let stdout = ''; | ||
| let settled = false; | ||
|
|
||
| const timer = setTimeout(() => { | ||
| if (!settled) { | ||
| settled = true; | ||
| log.warn(`[TaskNaming] timed out for provider: ${providerId}`); | ||
| child.kill(); | ||
| resolve(null); | ||
| } | ||
| }, TIMEOUT_MS); | ||
|
|
||
| const child = spawn(cli, args, { | ||
| cwd, | ||
| env: process.env as Record<string, string>, | ||
| stdio: ['ignore', 'pipe', 'pipe'], | ||
| }); | ||
|
|
||
| child.stdout.on('data', (chunk: Buffer) => { | ||
| if (stdout.length < MAX_STDOUT_BYTES) { | ||
| stdout += chunk.toString(); | ||
| } | ||
| }); | ||
|
|
||
| child.stderr?.on('data', (chunk: Buffer) => { | ||
| log.debug(`[TaskNaming] stderr from ${providerId}: ${chunk.toString().trim()}`); | ||
| }); | ||
|
|
||
| child.on('close', (code) => { | ||
| clearTimeout(timer); | ||
| if (settled) return; | ||
| settled = true; | ||
|
|
||
| if (code !== 0) { | ||
| log.warn(`[TaskNaming] CLI exited with code ${code} for provider: ${providerId}`); | ||
| resolve(null); | ||
| return; | ||
| } | ||
|
|
||
| resolve(normalizeSlug(stdout)); | ||
| }); | ||
|
|
||
| child.on('error', (err) => { | ||
| clearTimeout(timer); | ||
| if (settled) return; | ||
| settled = true; | ||
| log.warn(`[TaskNaming] spawn error for ${providerId}: ${err.message}`); | ||
| resolve(null); | ||
| }); | ||
| }); | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR introduces a
utilityCliArgsfield onProviderDefinition, a general-purpose mechanism for invoking a provider's CLI in lightweight non-interactive modeTask naming is the first use case, but the same infrastructure could power other things that could use inference (like generating pull request description drafting, commit messages)