Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/ikesu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/kazuph/ikesu/internal/tui"
)

const version = "0.4.226"
const version = "0.4.227"

func main() {
if len(os.Args) == 2 && os.Args[1] == "__job-runner" {
Expand Down
141 changes: 136 additions & 5 deletions internal/agyview/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package agyview

import (
"regexp"
"strconv"
"strings"
)

Expand Down Expand Up @@ -133,6 +134,106 @@ func Tail(lines []string) bool {

var questionHeader = regexp.MustCompile(`^\s*Question ([1-9][0-9]*)/([1-9][0-9]*):`)

// OptionRow matches selectable agy choice rows (which carry a leading cursor or indentation),
// distinguishing them from column-0 numbered bullets inside a question body.
var OptionRow = regexp.MustCompile(`^(?:\s*([❯›>])\s*|\s+)(\d+)\.\s+(.*)$`)
var optionCheckbox = regexp.MustCompile(`^\[([ ✔✓xX])\]\s*(.*)$`)

func isRule(line string) bool {
t := strings.TrimSpace(line)
return strings.HasPrefix(t, "─") && strings.Trim(t, "─") == ""
}

func isPromptBoundary(trim string) bool {
return isRule(trim) || strings.Contains(trim, "↑/↓ Navigate") || strings.HasPrefix(trim, "esc to cancel") || trim == "Question" || questionHeader.MatchString(trim)
}

func hasBrokenQuestionHeader(lines []string) bool {
for i, line := range lines {
if strings.TrimSpace(line) != "Question" || i+1 >= len(lines) || !isRule(lines[i+1]) {
continue
}
j := i + 2
for j < len(lines) && strings.TrimSpace(lines[j]) == "" {
j++
}
if j < len(lines) && !questionHeader.MatchString(strings.TrimSpace(lines[j])) {
return true
}
}
return false
}

// HasWriteInOptionBlock checks whether lines end (ignoring trailing blanks) with a valid
// consecutive agy 1..N option block ending in "N. Write-in...", returning the start row index.
func HasWriteInOptionBlock(lines []string) (int, bool) {
lastIdx := len(lines) - 1
for lastIdx >= 0 && strings.TrimSpace(lines[lastIdx]) == "" {
lastIdx--
}
if lastIdx < 1 {
return 0, false
}
lastMatch := OptionRow.FindStringSubmatch(lines[lastIdx])
if lastMatch == nil || strings.TrimSpace(lastMatch[3]) != "Write-in..." {
return 0, false
}
total, err := strconv.Atoi(lastMatch[2])
if err != nil || total < 2 {
return 0, false
}
expected := total - 1
optStart := -1
for i := lastIdx - 1; i >= 0; i-- {
line := lines[i]
trim := strings.TrimSpace(line)
if trim == "" || isPromptBoundary(trim) {
return 0, false
}
if m := OptionRow.FindStringSubmatch(line); m != nil {
n, err := strconv.Atoi(m[2])
if err != nil || n != expected {
return 0, false
}
expected--
if expected == 0 {
optStart = i
break
}
}
}
if optStart < 0 {
return 0, false
}
selected := 0
seenWriteIn := false
for _, line := range lines[optStart : lastIdx+1] {
m := OptionRow.FindStringSubmatch(line)
if m == nil {
continue
}
if m[1] != "" {
selected++
}
val := strings.TrimSpace(m[3])
if val == "" || optionCheckbox.MatchString(val) {
return 0, false
}
if val == "Write-in..." {
if seenWriteIn {
return 0, false
}
seenWriteIn = true
} else if seenWriteIn {
return 0, false
}
}
if selected != 1 || !seenWriteIn {
return 0, false
}
return optStart, true
}

// ShortFooter is the footer of a lone question on a choice: "enter Select" with
// no Next and no Submit. It is valid only under "Question 1/1:"; in a longer set
// the last one shows Submit. A Write-in row ("enter Write-in") is the last
Expand All @@ -145,20 +246,50 @@ func ShortFooter(line string) bool {
func HasCurrentFooter(lines []string) bool {
for i := len(lines) - 1; i >= 0; i-- {
if strings.Contains(lines[i], "↑/↓ Navigate") && strings.Contains(lines[i], "enter ") {
if ShortFooter(lines[i]) && !singleQuestionAbove(lines[:i]) {
if !Tail(lines[i+1:]) {
return false
}
return Tail(lines[i+1:])
above := lines[:i]
if idx, oneOfOne, found := findQuestionHeaderAbove(above); found {
if hasRuleWithWrongHeadingAbove(above[:idx]) {
return false
}
if ShortFooter(lines[i]) && !oneOfOne {
return false
}
return true
}
if hasBrokenQuestionHeader(above) {
return false
}
_, ok := HasWriteInOptionBlock(above)
return ok
}
}
return false
}

// singleQuestionAbove reports whether the nearest question header above the footer is "Question 1/1:".
func singleQuestionAbove(lines []string) bool {
func findQuestionHeaderAbove(lines []string) (idx int, oneOfOne bool, found bool) {
for i := len(lines) - 1; i >= 0; i-- {
if m := questionHeader.FindStringSubmatch(lines[i]); m != nil {
return m[1] == "1" && m[2] == "1"
return i, m[1] == "1" && m[2] == "1", true
}
}
return -1, false, false
}

func hasRuleWithWrongHeadingAbove(aboveHeader []string) bool {
j := len(aboveHeader) - 1
for j >= 0 && strings.TrimSpace(aboveHeader[j]) == "" {
j--
}
if j >= 0 && isRule(aboveHeader[j]) {
k := j - 1
for k >= 0 && strings.TrimSpace(aboveHeader[k]) == "" {
k--
}
if k >= 0 && strings.TrimSpace(aboveHeader[k]) != "Question" {
return true
}
}
return false
Expand Down
38 changes: 38 additions & 0 deletions internal/agyview/tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,41 @@ func TestHasCancelTail(t *testing.T) {
}
}
}

func TestHasCurrentFooterAndWriteInOptionBlockForClippedPrompt(t *testing.T) {
clipped := []string{
"1. 推奨: mimamorin-web の main から専用 worktree を切って",
".claude/settings.json を修正する。",
"2. 調査のみで終了する。",
"",
"> 1. (Recommended) 案1を実行",
"extra line",
" 2. 案2を実行",
" 3. Write-in...",
"",
" ↑/↓ Navigate · enter Select · esc Skip",
"esc to cancel auto · Gemini 4 Neon · medium",
}
start, ok := HasWriteInOptionBlock(clipped[:len(clipped)-2])
if !ok || start != 4 {
t.Fatalf("HasWriteInOptionBlock = (%d, %v), want (4, true)", start, ok)
}
if !HasCurrentFooter(clipped) {
t.Fatal("HasCurrentFooter rejected clipped 1/1 prompt with Write-in block")
}

brokenHeader := append([]string{"Question", "────────────────────────────", "", "Permission: blocked"}, clipped[3:]...)
if HasCurrentFooter(brokenHeader) {
t.Fatal("HasCurrentFooter accepted broken Question/Permission header")
}

missingWriteIn := []string{
"> 1. Only option",
" 2. Second option",
" ↑/↓ Navigate · enter Select · esc Skip",
"esc to cancel",
}
if HasCurrentFooter(missingWriteIn) {
t.Fatal("HasCurrentFooter accepted clipped prompt without Write-in...")
}
}
38 changes: 38 additions & 0 deletions internal/detect/agy_question_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,41 @@ func TestAgyWorkingDetection(t *testing.T) {
t.Fatalf("braille prose without working markers falsely working: %+v", d)
}
}

func TestAgyClippedLiveP5QuestionDetection(t *testing.T) {
// Verbatim structure from live pane p5 (agy 1.5.22) where Ink clipped "Question / ─── / Question 1/1:" off the top.
lines := []string{
"╭─ kazuph@Air-3 · ~/dotfiles · git master",
"╰─ ❯ agy",
"○ Thought for 59.3s (Standard hooks documentation recommends re...)",
"- dotfiles / ~/.claude/settings.json には参照なし(2026-07 に削除済み)。",
"",
"【各選択肢の結果】",
"1. 推奨: mimamorin-web の main から専用 worktree を切って .claude/settings.json を修正。",
"2. 作業中 worktree 修正: feat/biz-device-setup 内の .claude/settings.json を直接修正。",
"3. 削除: mimamorin-web の .claude/settings.json から該当 hook 定義を外す。",
"4. 変更しない: ここで終了する。",
"",
`> 1. (Recommended) mimamorin-web に切り替えて、新 worktree で`,
`"$CLAUDE_PROJECT_DIR"/.claude/hooks/env-production-guard.py`,
"に修正する(PR 用の独立修正)",
` 2. mimamorin-web の作業中 worktree(feat/biz-device-setup)内の`,
`.claude/settings.json だけ今すぐ "$CLAUDE_PROJECT_DIR" 参照に直す`,
" 3. env-production-guard hook は不要なので mimamorin-web から設定・スクリプトを削除する",
" 4. 調査のみで終了する(変更しない)",
" 5. Write-in...",
"",
" ↑/↓ Navigate · enter Select · esc Skip",
"esc to cancel auto · Gemini 4 Neon · medium",
"Gemini 5h 26% (1h22m) · wk 41% (5d19h)",
"Claude/GPT 5h 0% (<1m) · wk 0% (<1m)",
}
full := strings.Join(lines, "\n") + "\n"
if d := Detect("agy", Input{Screen: full}); d.State != Blocked || d.RuleID != "question_prompt" {
t.Fatalf("clipped p5 full: %+v", d)
}
visibleOnly := strings.Join(lines[3:], "\n") + "\n"
if d := Detect("agy", Input{Screen: visibleOnly}); d.State != Blocked || d.RuleID != "question_prompt" {
t.Fatalf("clipped p5 visible-only: %+v", d)
}
}
2 changes: 1 addition & 1 deletion internal/detect/manifests/antigravity.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ any = [
{ contains = ["enter Submit"] },
]
not = [{ contains = ["Toggle"] }]
line_regex = ['^\s*Question [1-9][0-9]*/[1-9][0-9]*:']
line_regex = ['^(?:\s*Question [1-9][0-9]*/[1-9][0-9]*:|(?:\s*[❯›>]\s*|\s+)[1-9][0-9]*\.\s+Write-in\.\.\.\s*$)']

[[rules]]
id = "idle_prompt"
Expand Down
Loading