feat(kugetsu): smart delegate with worktree awareness #130

Merged
shoko merged 1 commits from feature/smart-delegate-worktree-awareness into main 2026-04-03 16:31:31 +02:00
Owner

Summary

Improve cmd_delegate to be worktree-aware and inject context about missing information.

Changes

New Helper Functions

  • parse_issue_ref_from_message() - Extract gitserver/owner/repo/issue from message
  • get_missing_info() - Identify which fields are missing
  • build_missing_info_context() - Build context string for missing info
  • find_worktrees_by_issue_number() - Find existing worktrees by issue number
  • find_sessions_by_issue_number() - Find existing sessions by issue number

Modified cmd_delegate

  1. Parse message for issue refs (supports gitserver.com/owner/repo/issues/123 and owner/repo#123 patterns)
  2. Find existing worktrees/sessions matching the issue number
  3. Ask user to confirm which worktree to use, or delegate anyway
  4. Inject missing info context into delegation message
  5. Inject selected worktree context into delegation message

How It Works

kugetsu delegate "work on gitserver.com/owner/repo/issues/123"

# Output:
# NOTE: Delegation missing information: git server
# Found 1 existing worktree(s)/session(s) for issue #123:
# 1) /path/to/worktree (worktree)
# r) Delegate anyway (without routing)
# Which one to use? [1/r]: 1
# Using worktree: /path/to/worktree
# Delegated to PM agent (logged to delegate-xxx.log)

PM agent receives context about:

  • Missing information (so it knows to ask clarifying questions if needed)
  • Selected worktree (so it can route appropriately)

Note on Routing

This implementation uses "context injection" approach rather than automatic routing to cmd_start/cmd_continue. The PM agent receives full context and can decide how to act. This is more conservative and allows PM agent flexibility.

Closes

Fixes #128

## Summary Improve `cmd_delegate` to be worktree-aware and inject context about missing information. ## Changes ### New Helper Functions - `parse_issue_ref_from_message()` - Extract gitserver/owner/repo/issue from message - `get_missing_info()` - Identify which fields are missing - `build_missing_info_context()` - Build context string for missing info - `find_worktrees_by_issue_number()` - Find existing worktrees by issue number - `find_sessions_by_issue_number()` - Find existing sessions by issue number ### Modified `cmd_delegate` 1. Parse message for issue refs (supports `gitserver.com/owner/repo/issues/123` and `owner/repo#123` patterns) 2. Find existing worktrees/sessions matching the issue number 3. Ask user to confirm which worktree to use, or delegate anyway 4. Inject missing info context into delegation message 5. Inject selected worktree context into delegation message ## How It Works ``` kugetsu delegate "work on gitserver.com/owner/repo/issues/123" # Output: # NOTE: Delegation missing information: git server # Found 1 existing worktree(s)/session(s) for issue #123: # 1) /path/to/worktree (worktree) # r) Delegate anyway (without routing) # Which one to use? [1/r]: 1 # Using worktree: /path/to/worktree # Delegated to PM agent (logged to delegate-xxx.log) ``` PM agent receives context about: - Missing information (so it knows to ask clarifying questions if needed) - Selected worktree (so it can route appropriately) ## Note on Routing This implementation uses "context injection" approach rather than automatic routing to `cmd_start`/`cmd_continue`. The PM agent receives full context and can decide how to act. This is more conservative and allows PM agent flexibility. ## Closes Fixes #128
shoko added 1 commit 2026-04-03 16:21:11 +02:00
- Parse issue refs from message (gitserver.com/owner/repo/issues/123 or owner/repo#123)
- Find existing worktrees/sessions by issue number
- Ask user to confirm which worktree to use, or delegate anyway
- Inject missing info context to PM agent
- Inject selected worktree context to PM agent

Fixes #128
han approved these changes 2026-04-03 16:31:05 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko merged commit 5d12f6ca42 into main 2026-04-03 16:31:31 +02:00
Sign in to join this conversation.