Skip to content

Commit 1770439

Browse files
author
SqlRush
committed
Accept press-style script key aliases
1 parent dcc0439 commit 1770439

5 files changed

Lines changed: 93 additions & 0 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ M7 补充:keybinding config 和脚本 named-key 输入现在接受短修饰符
146146

147147
M7 补充:interaction script 的 `keys` 字段现在支持 printable text chunk 和空格分隔 named-key sequence,例如 `ctrl-x ctrl-k`,减少官方脚本把连续输入拆成数组的改写成本。
148148

149+
M7 补充:interaction script key input 现在接受 press-style aliases,包括 `press``keyPress``keypress``shortcutKey``presses``keyPresses``shortcuts`
150+
149151
M7 补充:interaction script 的 `message` step 现在接受 chat/transcript 风格的 `type`/`speaker` role 别名和 `content`/`body`/`message` text 别名;`image` step 和 iTerm2 image hint 接受 `fileName`/`file_name`/`name`、`mimeType`/`mime_type`/`contentType`、source path/URL 和 `data`/`base64` 内容别名;permission request step 接受 request/permission/tool-use ID、path、description 和 action 字段别名,并允许 `actions` 使用单字符串;`expectPrompt` 接受 `value`/`input`/`content`/`message`、`expandedText`/`fullText`、`cursorIndex`/`cursorPosition`、`isEmpty`/`blank` 等字段别名,且 `pastedContents` 断言接受 `pastedId`/`pastedContentId`、`kind`/`pastedType`、`value`/`data`/`base64`、`contentType`/`mimeType`、`fileName`/`name` 和 `contains` 等字段别名;`expectVim` 接受 `vimEnabled`/`isEnabled`、`vimMode`/`modeName`/`currentMode`、`vimRegister`/`registerValue`/`yankRegister`、`registerLinewise`/`linewise` 等字段别名;`expectTasks` 接受 `taskCount`/`total`/`size`/`length` 和 `statusCounts`/`countsByState` 等字段别名;`expectScreen`/`expectViewport` 接受 `columns`/`rows`、`screenWidth`/`screenHeight`、`scrollOffset`/`viewportOffset`、`visibleRows`/`lineCount` 等字段别名;`expectReverseSearch` 接受 `isActive`/`visible`/`open`、`search`/`term`/`pattern`、`cursorIndex`、`currentResult`、`matchCount`/`matches`、`noMatches` 等字段别名;`expectDialog` 可断言 body contains/not-contains、actions/action contains/not-contains、action count 和 focused action,runtime-aware scripts 会在步骤间保留 dialog focused action,且接受 `isActive`/`visible`、`dialogId`/`dialogID`、`dialogKind`、`heading`/`header`、`content`/`text`/`message` 等字段别名;`expectEvent`/`expectDialogResult` 接受 `eventType`/`event`/`name`、`payload`/`text`/`message`、`dialogId`/`dialogID`/`dialogKind`、`actionValue`/`resultStatus`/`exists`/`isStale` 等字段别名。
150152

151153
M7 补充:interaction script 现在接受 `messages``append_messages`/`appendMessages``transcript_messages`/`transcriptMessages` 批量消息注入字段,且这些字段既可用单个对象也可用对象数组,消息对象沿用 chat/transcript role/text 别名;message 注入也接受 `pastedContent`/`attachments` 粘贴内容别名、单数 `imagePasteId` 图片引用别名,以及 pasted-content 的 `kind`/`value`/`data` 内容字段别名。
@@ -428,6 +430,8 @@ M7 补充:prompt history `LogEntry` 读取现在接受 `sessionID`/`session`/`
428430

429431
本轮补充:interaction script 的 `keys` 字段现在支持 printable text chunk 和空格分隔 named-key sequence,例如 `ctrl-x ctrl-k`,减少官方脚本把连续输入拆成数组的改写成本。
430432

433+
本轮补充:interaction script key input 现在接受 press-style aliases,包括 `press``keyPress``keypress``shortcutKey``presses``keyPresses``shortcuts`
434+
431435
本轮补充:interaction script step 接受 `resize`/`terminalSize`/`screenSize` 对象或 `[width,height]` 数组、顶层 `columns`/`rows` resize 别名、`focus`/`focused`/`blur`/`focusIn`/`focusOut` focus event 别名、`snapshot`/`snapshotId`/`snapshotLabel` capture 名称别名,以及 runtime-aware mutation 别名如 `permission`/`permissionRequest``task`/`taskStatus``removeTask`/`deleteTask``cancelPermission``cancelTasks`/`cancelReason``openTasks`/`showTasks`
432436

433437
本轮补充:interaction script step 可通过 `status`/`setStatus`/`statusLine`/`baseStatus` 设置状态行;runtime-aware scripts 会把它作为 base status,并继续叠加 permission/task 计数,便于复用带状态栏的 ANSI/interaction fixture。

docs/claude-code-go-rewrite-plan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ test/parity/ # golden tests against TS/official behavior
261261
- 本轮补充:keybinding action parser 接受更多 editor-style action aliases,包括 `cursorLeft`/`cursorRight``lineStart`/`lineEnd``deletePreviousChar`/`deleteNextChar``killLine``acceptSelection``search`
262262
- 本轮补充:keybinding config 和脚本 named-key 输入接受短修饰符别名,包括 `c-`/`m-`/`a-`/`opt-`/`s-` 以及 compact/camel 形式,可覆盖 control、meta、alt、option 和 shift key names。
263263
- 本轮补充:interaction script 的 `keys` 字段支持 printable text chunk 和空格分隔 named-key sequence,例如 `ctrl-x ctrl-k`,减少官方脚本把连续输入拆成数组的改写成本。
264+
- 本轮补充:interaction script key input 接受 press-style aliases,包括 `press``keyPress``keypress``shortcutKey``presses``keyPresses``shortcuts`
264265
- 本轮补充:terminal CSI-u/kitty keyboard parser 接受 `codepoint:alternate``modifier:event-type` 冒号字段,按主 codepoint/modifier 解析 ctrl/alt/shift/rune 键,覆盖 kitty progressive keyboard protocol 的常见变体。
265266
- 本轮补充:terminal CSI-u/kitty keyboard parser 接受无 modifier 字段或 modifier `1` 的 base key 序列,覆盖 printable rune、Enter、Tab、Esc 和 Backspace,避免 extended-key 模式下普通键序列被解析成 unknown。
266267
- 本轮补充:terminal CSI parser 把 DA/device attributes (`CSI c``CSI >c``CSI =c`) 归入 report action,并在 terminal parser dispatcher 中作为 `TerminalActionReport` 暴露。

docs/first-second-parity-audit.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ M7 progress now includes:
243243
- `internal/tui`: keybinding action parsing now accepts broader editor-style aliases such as `cursorLeft`, `lineStart`, `deletePreviousChar`, `killLine`, `acceptSelection`, and `search`.
244244
- `internal/tui`: keybinding config and named-key script input now accept short modifier aliases such as `c-left`, `cA`, `m-b`, `a-right`, `optF`, `s-tab`, and `sEnter`.
245245
- `internal/tui`: scripted interaction `keys` entries now accept printable text chunks and whitespace-separated named key sequences such as `ctrl-x ctrl-k`.
246+
- `internal/tui`: scripted interaction key input now accepts press-style aliases such as `press`, `keyPress`, `keypress`, `shortcutKey`, `presses`, `keyPresses`, and `shortcuts`.
246247
- `internal/tui`: terminal key parsing now accepts CSI-u/kitty keyboard protocol sequences for existing ctrl/alt editing keys, shift-enter, shift-tab, and printable shift-only runes.
247248
- `internal/tui`: terminal CSI-u/kitty keyboard parsing now also accepts colon-suffixed alternate codepoint and modifier event-type fields such as `CSI 97:65;5:1u`.
248249
- `internal/tui`: terminal CSI-u/kitty keyboard parsing now also accepts base/unmodified sequences such as `CSI 97u` and `CSI 13;1u`, mapping printable runes plus Enter, Tab, Esc, and Backspace instead of treating ordinary extended-key reports as unknown.

internal/tui/script_aliases.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ func (step *ScriptStep) UnmarshalJSON(data []byte) error {
211211
RawKeyCamel *string `json:"rawKey"`
212212
KeySequence *string `json:"key_sequence"`
213213
KeySequenceCamel *string `json:"keySequence"`
214+
Press *string `json:"press"`
215+
PressKey *string `json:"press_key"`
216+
PressKeyCamel *string `json:"pressKey"`
217+
KeyPress *string `json:"key_press"`
218+
KeyPressCamel *string `json:"keyPress"`
219+
Keypress *string `json:"keypress"`
220+
Shortcut *string `json:"shortcut"`
221+
ShortcutKey *string `json:"shortcut_key"`
222+
ShortcutKeyCamel *string `json:"shortcutKey"`
223+
Presses []string `json:"presses"`
224+
KeyPresses []string `json:"key_presses"`
225+
KeyPressesCamel []string `json:"keyPresses"`
226+
Keypresses []string `json:"keypresses"`
227+
Shortcuts []string `json:"shortcuts"`
214228
Input *string `json:"input"`
215229
InputText *string `json:"input_text"`
216230
InputTextCamel *string `json:"inputText"`
@@ -371,6 +385,48 @@ func (step *ScriptStep) UnmarshalJSON(data []byte) error {
371385
if fields.KeySequenceCamel != nil {
372386
step.Key = *fields.KeySequenceCamel
373387
}
388+
if fields.Press != nil {
389+
step.Key = *fields.Press
390+
}
391+
if fields.PressKey != nil {
392+
step.Key = *fields.PressKey
393+
}
394+
if fields.PressKeyCamel != nil {
395+
step.Key = *fields.PressKeyCamel
396+
}
397+
if fields.KeyPress != nil {
398+
step.Key = *fields.KeyPress
399+
}
400+
if fields.KeyPressCamel != nil {
401+
step.Key = *fields.KeyPressCamel
402+
}
403+
if fields.Keypress != nil {
404+
step.Key = *fields.Keypress
405+
}
406+
if fields.Shortcut != nil {
407+
step.Key = *fields.Shortcut
408+
}
409+
if fields.ShortcutKey != nil {
410+
step.Key = *fields.ShortcutKey
411+
}
412+
if fields.ShortcutKeyCamel != nil {
413+
step.Key = *fields.ShortcutKeyCamel
414+
}
415+
if fields.Presses != nil {
416+
step.Keys = append(step.Keys, fields.Presses...)
417+
}
418+
if fields.KeyPresses != nil {
419+
step.Keys = append(step.Keys, fields.KeyPresses...)
420+
}
421+
if fields.KeyPressesCamel != nil {
422+
step.Keys = append(step.Keys, fields.KeyPressesCamel...)
423+
}
424+
if fields.Keypresses != nil {
425+
step.Keys = append(step.Keys, fields.Keypresses...)
426+
}
427+
if fields.Shortcuts != nil {
428+
step.Keys = append(step.Keys, fields.Shortcuts...)
429+
}
374430
if fields.Input != nil {
375431
step.Text = *fields.Input
376432
}
@@ -794,6 +850,11 @@ func (step *ScriptStep) UnmarshalJSON(data []byte) error {
794850
func normalizeScriptStepJSON(data []byte) []byte {
795851
data = normalizeStringFieldsToArray(data,
796852
"keys",
853+
"presses",
854+
"key_presses",
855+
"keyPresses",
856+
"keypresses",
857+
"shortcuts",
797858
"expect_status_contains",
798859
"expectStatusContains",
799860
"expect_status_not_contains",

internal/tui/tui_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4895,6 +4895,32 @@ func TestRunInteractionScriptAcceptsKeysStringSequences(t *testing.T) {
48954895
}
48964896
}
48974897

4898+
func TestRunInteractionScriptAcceptsPressFieldAliases(t *testing.T) {
4899+
steps, err := ParseInteractionScript([]byte(`[
4900+
{"press":"a","expectPrompt":{"text":"a"}},
4901+
{"keyPress":"b","expectPrompt":{"text":"ab"}},
4902+
{"shortcutKey":"enter","expectEvent":{"type":"prompt_submitted","value":"ab"},"expectPrompt":{"empty":true}},
4903+
{"keyPresses":"ctrl-x ctrl-k","expectEvent":{"type":"kill_agents"}},
4904+
{"shortcuts":["o","k","enter"],"expectEvent":{"type":"prompt_submitted","value":"ok"},"expectPrompt":{"empty":true}},
4905+
{"presses":["y","enter"],"expectEvent":{"type":"prompt_submitted","value":"y"},"expectPrompt":{"empty":true}}
4906+
]`))
4907+
if err != nil {
4908+
t.Fatal(err)
4909+
}
4910+
screen := NewREPLScreen(40, 8, nil)
4911+
result, err := RunInteractionScriptChecked(&screen, steps)
4912+
if err != nil {
4913+
t.Fatal(err)
4914+
}
4915+
if len(result.Events) != 4 ||
4916+
result.Events[0].Type != ScreenEventPromptSubmitted || result.Events[0].Value != "ab" ||
4917+
result.Events[1].Type != ScreenEventKillAgents ||
4918+
result.Events[2].Type != ScreenEventPromptSubmitted || result.Events[2].Value != "ok" ||
4919+
result.Events[3].Type != ScreenEventPromptSubmitted || result.Events[3].Value != "y" {
4920+
t.Fatalf("events = %#v", result.Events)
4921+
}
4922+
}
4923+
48984924
func TestRunInteractionScriptAppliesStepKeybindings(t *testing.T) {
48994925
steps, err := ParseInteractionScript([]byte(`[
49004926
{"keybindings":{"keys":"ctrl-r","command":"submitPrompt"}},

0 commit comments

Comments
 (0)