Skip to content

Commit e3b19d0

Browse files
author
SqlRush
committed
Use raw keybinding mutation fields
1 parent 30536dd commit e3b19d0

5 files changed

Lines changed: 28 additions & 22 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ M7 补充:prompt history `LogEntry` 读取现在接受 `sessionID`/`session`/`
644644

645645
本轮补充:interaction script 的 direct image 字段现在改为 raw payload 解析;`image`/`Image` 可复用 pasteImage action 的 wrapper 解析,递归解包 `resource.attributes``edge.node.attrs` 和单元素数组,保留 filename/media/content/source-path 后再生成 prompt pasted-image。
646646

647+
本轮补充:interaction script 的 direct keybinding mutation 字段现在改为 raw-only 解析;`keybindings`/`key_bindings`/`keyBindings`/`keybindingSpecs`/`Keybindings` 不再先走 `[]BindingSpec` 基础解码,统一复用 keybinding loader 的 object-map、resource wrapper 和 edge/node collection parser。
648+
647649
本轮补充:interaction script 的 runtime mutation action 现在也递归解包 wrapped `removeTask`/`cancelPermission` ID 和 `cancelTasks` cancellation detail;`payload.resource.attributes``edge.node` 和相邻 API envelope 可直接驱动 task removal、permission cancellation 与 task bulk-cancel。
648650

649651
本轮补充:interaction script 的 direct runtime mutation alias 字段现在接受 object payload;`removeTask: {resource:{id}}``cancelPermission: {edge:{node:{id}}}``cancelTasks: {resource:{attributes:{reasonText}}}` 会走同一递归解析路径,不再被 string/bool alias 字段提前拒绝。

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ test/parity/ # golden tests against TS/official behavior
332332
- 本轮补充:interaction script 的 direct single message 字段现在也复用 raw message parser;`message`/`Message` 可递归解包 `resource.attributes``edge.node.attrs`,并在数组形态下回退为多条 message 追加,避免单条消息 wrapper 被基础解码成空消息。
333333
- 本轮补充:interaction script 的 direct dialog 字段现在改为 raw payload 解析;`dialog`/`Dialog` 可递归解包 `resource.attributes``edge.node.attrs` 和单元素数组,`showDialog` action payload 也复用同一解析路径,避免 wrapper-only dialog 被解码成空弹窗。
334334
- 本轮补充:interaction script 的 direct image 字段现在改为 raw payload 解析;`image`/`Image` 可复用 pasteImage action 的 wrapper 解析,递归解包 `resource.attributes``edge.node.attrs` 和单元素数组,保留 filename/media/content/source-path 后再生成 prompt pasted-image。
335+
- 本轮补充:interaction script 的 direct keybinding mutation 字段现在改为 raw-only 解析;`keybindings`/`key_bindings`/`keyBindings`/`keybindingSpecs`/`Keybindings` 不再先走 `[]BindingSpec` 基础解码,统一复用 keybinding loader 的 object-map、resource wrapper 和 edge/node collection parser。
335336
- 本轮补充:terminal CSI-u/kitty keyboard parser 接受 `codepoint:alternate``modifier:event-type` 冒号字段,按主 codepoint/modifier 解析 ctrl/alt/shift/rune 键,覆盖 kitty progressive keyboard protocol 的常见变体。
336337
- 本轮补充:terminal CSI-u/kitty keyboard parser 接受无 modifier 字段或 modifier `1` 的 base key 序列,覆盖 printable rune、Enter、Tab、Esc 和 Backspace,避免 extended-key 模式下普通键序列被解析成 unknown。
337338
- 本轮补充:terminal input parser 接受 xterm modified arrow 序列(如 `CSI 1;2D``CSI 1;6C``CSI 1;7D`),把 shift-arrow 降级为方向键、alt-arrow 映射到 word-motion key、ctrl/ctrl+alt-arrow 映射到 ctrl word-motion key,避免 extended navigation 序列落入 unknown。

docs/first-second-parity-audit.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ M7 progress now includes:
386386
- `internal/tui`: interaction script direct single-message fields now reuse the raw message parser, so `message`/`Message` can unwrap `resource.attributes` or `edge.node.attrs`, and array-shaped single-message payloads fall back to appending multiple messages instead of producing an empty decoded message.
387387
- `internal/tui`: interaction script direct dialog fields now use raw payload parsing, so `dialog`/`Dialog` and `showDialog` action payloads can unwrap `resource.attributes`, `edge.node.attrs`, and single-element arrays instead of decoding wrapper-only dialogs as empty popups.
388388
- `internal/tui`: interaction script direct image fields now use raw payload parsing, so `image`/`Image` can reuse pasteImage action wrapper parsing for `resource.attributes`, `edge.node.attrs`, and single-element arrays while preserving filename/media/content/source-path metadata before prompt image insertion.
389+
- `internal/tui`: interaction script direct keybinding mutation fields now use raw-only parsing, so `keybindings`/`key_bindings`/`keyBindings`/`keybindingSpecs`/`Keybindings` avoid early `[]BindingSpec` decoding and consistently reuse object-map, resource-wrapper, and edge/node collection parsing from the keybinding loader.
389390
- `internal/contracts`/`internal/session`: image content blocks now normalize source aliases such as `mediaType`/`mimeType`/`contentType` and `base64`/`payload`, including top-level image block fields, into canonical `ImageSource` values during transcript resume.
390391
- `internal/tui`: interaction script single-step JSON now unwraps `step`/`scriptStep`/`interactionStep`/`record`/`entry`/`item`/`event` objects in arrays, JSONL records, and wrapper-object step lists.
391392
- `internal/tui`: interaction script single-step JSON now also unwraps JSON:API/resource-style `resource`/`node`/`attributes`/`properties`/`attrs` step items, so API fixture arrays and JSONL records can keep step resource envelopes.

internal/tui/script_aliases.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,15 @@ func taskStatusJSONField(fields map[string]json.RawMessage, names ...string) *Ta
259259
func scriptKeybindingsJSONField(fields map[string]json.RawMessage) ([]BindingSpec, bool, error) {
260260
names := []string{
261261
"bindings",
262+
"Keybindings",
262263
"keybindings",
264+
"KeyBindings",
263265
"key_bindings",
264266
"keyBindings",
265267
"keyboardBindings",
266268
"keyboardShortcuts",
267269
"keyboard_shortcuts",
270+
"KeybindingSpecs",
268271
"keybinding_specs",
269272
"keybindingSpecs",
270273
"keymap",
@@ -539,11 +542,11 @@ func (step *ScriptStep) UnmarshalJSON(data []byte) error {
539542
Mouse *json.RawMessage `json:"mouse"`
540543
MouseEvent *json.RawMessage `json:"mouse_event"`
541544
MouseEventCamel *json.RawMessage `json:"mouseEvent"`
542-
Keybindings []BindingSpec `json:"keybindings"`
543-
KeyBindings []BindingSpec `json:"key_bindings"`
544-
KeyBindingsCamel []BindingSpec `json:"keyBindings"`
545-
KeybindingSpecs []BindingSpec `json:"keybinding_specs"`
546-
KeybindingSpecsCamel []BindingSpec `json:"keybindingSpecs"`
545+
Keybindings *json.RawMessage `json:"keybindings"`
546+
KeyBindings *json.RawMessage `json:"key_bindings"`
547+
KeyBindingsCamel *json.RawMessage `json:"keyBindings"`
548+
KeybindingSpecs *json.RawMessage `json:"keybinding_specs"`
549+
KeybindingSpecsCamel *json.RawMessage `json:"keybindingSpecs"`
547550
UpsertTask *json.RawMessage `json:"upsert_task"`
548551
UpsertTaskCamel *json.RawMessage `json:"upsertTask"`
549552
RemoveTaskID *json.RawMessage `json:"remove_task_id"`
@@ -825,21 +828,6 @@ func (step *ScriptStep) UnmarshalJSON(data []byte) error {
825828
if image := scriptImageJSONField(rawFieldMap, "Image", "image"); image != nil {
826829
step.Image = image
827830
}
828-
if fields.Keybindings != nil {
829-
step.Keybindings = fields.Keybindings
830-
}
831-
if fields.KeyBindings != nil {
832-
step.Keybindings = fields.KeyBindings
833-
}
834-
if fields.KeyBindingsCamel != nil {
835-
step.Keybindings = fields.KeyBindingsCamel
836-
}
837-
if fields.KeybindingSpecs != nil {
838-
step.Keybindings = fields.KeybindingSpecs
839-
}
840-
if fields.KeybindingSpecsCamel != nil {
841-
step.Keybindings = fields.KeybindingSpecsCamel
842-
}
843831
if specs, ok, err := scriptKeybindingsJSONField(rawFieldMap); err != nil {
844832
return err
845833
} else if ok {
@@ -3259,6 +3247,14 @@ func stripScriptStepRawScalarAliasFields(data []byte) []byte {
32593247
"dialog",
32603248
"Image",
32613249
"image",
3250+
"Keybindings",
3251+
"keybindings",
3252+
"KeyBindings",
3253+
"key_bindings",
3254+
"keyBindings",
3255+
"KeybindingSpecs",
3256+
"keybinding_specs",
3257+
"keybindingSpecs",
32623258
"SnapshotName",
32633259
"snapshotName",
32643260
"RequestPermission",

internal/tui/tui_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6497,6 +6497,10 @@ func TestRunInteractionScriptAcceptsKeybindingCollectionAliases(t *testing.T) {
64976497
{"text":"second","key":"ctrl-w","expectEvent":{"type":"prompt_submitted","value":"second"},"expectPrompt":{"empty":true}},
64986498
{"keyboard":{"resource":{"attributes":{"keymap":{"ctrl-y":"submitPrompt"}}}}},
64996499
{"text":"third","key":"ctrl-y","expectEvent":{"type":"prompt_submitted","value":"third"},"expectPrompt":{"empty":true}},
6500+
{"Keybindings":{"resource":{"attributes":{"keymap":{"ctrl-a":"submitPrompt"}}}}},
6501+
{"text":"fourth","key":"ctrl-a","expectEvent":{"type":"prompt_submitted","value":"fourth"},"expectPrompt":{"empty":true}},
6502+
{"keybindingSpecs":{"edges":[{"node":{"attrs":{"shortcutKey":"ctrl-e","commandName":"submitPrompt"}}}]}},
6503+
{"text":"fifth","key":"ctrl-e","expectEvent":{"type":"prompt_submitted","value":"fifth"},"expectPrompt":{"empty":true}},
65006504
{"hotkeys":{"ctrl-x ctrl-k":false}},
65016505
{"keys":"ctrl-x ctrl-k","expectNoEvent":true}
65026506
]`))
@@ -6508,10 +6512,12 @@ func TestRunInteractionScriptAcceptsKeybindingCollectionAliases(t *testing.T) {
65086512
if err != nil {
65096513
t.Fatal(err)
65106514
}
6511-
if len(result.Events) != 3 ||
6515+
if len(result.Events) != 5 ||
65126516
result.Events[0].Type != ScreenEventPromptSubmitted || result.Events[0].Value != "first" ||
65136517
result.Events[1].Type != ScreenEventPromptSubmitted || result.Events[1].Value != "second" ||
6514-
result.Events[2].Type != ScreenEventPromptSubmitted || result.Events[2].Value != "third" {
6518+
result.Events[2].Type != ScreenEventPromptSubmitted || result.Events[2].Value != "third" ||
6519+
result.Events[3].Type != ScreenEventPromptSubmitted || result.Events[3].Value != "fourth" ||
6520+
result.Events[4].Type != ScreenEventPromptSubmitted || result.Events[4].Value != "fifth" {
65156521
t.Fatalf("events = %#v", result.Events)
65166522
}
65176523
}

0 commit comments

Comments
 (0)