30 lines
906 B
TypeScript
30 lines
906 B
TypeScript
|
|
const KEYWORD_PATTERN = /\b(ultrawork|ulw)\b/gi
|
||
|
|
const WORKTREE_FLAG_PATTERN = /--worktree(?:\s+(\S+))?/
|
||
|
|
|
||
|
|
export interface ParsedUserRequest {
|
||
|
|
planName: string | null
|
||
|
|
explicitWorktreePath: string | null
|
||
|
|
}
|
||
|
|
|
||
|
|
export function parseUserRequest(promptText: string): ParsedUserRequest {
|
||
|
|
const match = promptText.match(/<user-request>\s*([\s\S]*?)\s*<\/user-request>/i)
|
||
|
|
if (!match) return { planName: null, explicitWorktreePath: null }
|
||
|
|
|
||
|
|
let rawArg = match[1].trim()
|
||
|
|
if (!rawArg) return { planName: null, explicitWorktreePath: null }
|
||
|
|
|
||
|
|
const worktreeMatch = rawArg.match(WORKTREE_FLAG_PATTERN)
|
||
|
|
const explicitWorktreePath = worktreeMatch ? (worktreeMatch[1] ?? null) : null
|
||
|
|
|
||
|
|
if (worktreeMatch) {
|
||
|
|
rawArg = rawArg.replace(worktreeMatch[0], "").trim()
|
||
|
|
}
|
||
|
|
|
||
|
|
const cleanedArg = rawArg.replace(KEYWORD_PATTERN, "").trim()
|
||
|
|
|
||
|
|
return {
|
||
|
|
planName: cleanedArg || null,
|
||
|
|
explicitWorktreePath,
|
||
|
|
}
|
||
|
|
}
|