Skip to content

Commit 0372ea3

Browse files
author
SqlRush
committed
Accept string prompt expectations
1 parent 27304f2 commit 0372ea3

4 files changed

Lines changed: 71 additions & 34 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ M7 补充:prompt history `LogEntry` 读取现在接受 `sessionID`/`session`/`
606606

607607
本轮补充:interaction script 的 direct expectation count alias 字段现在也递归解包 wrapper;`expectEventCount``expectTotalEventCount``expectDialogResultCount``expectTotalDialogResultCount` 可从 wrapped `value`/`count`/`total` 恢复计数断言,避免 direct expectation fixture 在 int decode 阶段失败。
608608

609-
本轮补充:interaction script 的 UpperCamel step 字段现在也复用 raw/wrapper 解析;`UpsertTask``CancelAllTasks``OpenTasksDialog``ExpectScreen``ExpectViewport``ExpectReverseSearch``ExpectTasks` 等 Go 默认字段名可直接接受 JSON:API/GraphQL-style wrapper,task status/expectation 的 ID/title/state/detail/progress、screen expectation 的 Width/Height、viewport expectation 的 Offset/VisibleLineCount 和 reverse-search expectation 的 Cursor/ResultCount/NoResults 改为 raw-first 解码并继续接受数字字符串/非严格 bool。
609+
本轮补充:interaction script 的 UpperCamel step 字段现在也复用 raw/wrapper 解析;`UpsertTask``CancelAllTasks``OpenTasksDialog``ExpectPrompt``ExpectScreen``ExpectViewport``ExpectReverseSearch``ExpectTasks` 等 Go 默认字段名可直接接受 JSON:API/GraphQL-style wrapper,task status/expectation 的 ID/title/state/detail/progress、prompt expectation 的 Cursor/PastedContentCount/NextPastedID/Empty、screen expectation 的 Width/Height、viewport expectation 的 Offset/VisibleLineCount 和 reverse-search expectation 的 Cursor/ResultCount/NoResults 改为 raw-first 解码并继续接受数字字符串/非严格 bool。
610610

611611
本轮补充:interaction script 的 direct expectation string-list alias 字段现在也递归解包 wrapper;`expectStatusContains`/`NotContains``expectSnapshotContains`/`NotContains` 可从 wrapped `value`/`values`/`contains`/`items` 恢复断言列表,避免 direct expectation fixture 在 list decode 阶段失败。
612612

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ test/parity/ # golden tests against TS/official behavior
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。
335335
- 本轮补充:interaction script 的 direct keybinding mutation 字段现在改为 raw-only 解析;`keybindings`/`key_bindings`/`keyBindings`/`keybindingSpecs`/`Keybindings` 不再先走 `[]BindingSpec` 基础解码,统一复用 keybinding loader 的 object-map、resource wrapper 和 edge/node collection parser。
336-
- 本轮补充:interaction script 的 UpperCamel step 字段现在也进入 raw/wrapper 解析路径;`UpsertTask``CancelAllTasks``OpenTasksDialog``ExpectScreen``ExpectViewport``ExpectReverseSearch``ExpectTasks` 等 Go 默认字段名可直接接受 JSON:API/GraphQL-style wrapper,task status/expectation 的 ID/title/state/detail/progress、screen expectation 的 Width/Height、viewport expectation 的 Offset/VisibleLineCount 和 reverse-search expectation 的 Cursor/ResultCount/NoResults 改为 raw-first 解码并继续接受数字字符串/非严格 bool。
336+
- 本轮补充:interaction script 的 UpperCamel step 字段现在也进入 raw/wrapper 解析路径;`UpsertTask``CancelAllTasks``OpenTasksDialog``ExpectPrompt``ExpectScreen``ExpectViewport``ExpectReverseSearch``ExpectTasks` 等 Go 默认字段名可直接接受 JSON:API/GraphQL-style wrapper,task status/expectation 的 ID/title/state/detail/progress、prompt expectation 的 Cursor/PastedContentCount/NextPastedID/Empty、screen expectation 的 Width/Height、viewport expectation 的 Offset/VisibleLineCount 和 reverse-search expectation 的 Cursor/ResultCount/NoResults 改为 raw-first 解码并继续接受数字字符串/非严格 bool。
337337
- 本轮补充:terminal CSI-u/kitty keyboard parser 接受 `codepoint:alternate``modifier:event-type` 冒号字段,按主 codepoint/modifier 解析 ctrl/alt/shift/rune 键,覆盖 kitty progressive keyboard protocol 的常见变体。
338338
- 本轮补充:terminal CSI-u/kitty keyboard parser 接受无 modifier 字段或 modifier `1` 的 base key 序列,覆盖 printable rune、Enter、Tab、Esc 和 Backspace,避免 extended-key 模式下普通键序列被解析成 unknown。
339339
- 本轮补充: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。

internal/tui/script_aliases.go

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4165,22 +4165,65 @@ func (expect *PromptExpectation) UnmarshalJSON(data []byte) error {
41654165
"emptyPrompt",
41664166
"blank",
41674167
)
4168-
data = normalizeObjectFieldsToArray(data, "pasted_contents", "pastedContents")
4168+
data = normalizeObjectFieldsToArray(data, "PastedContents", "pasted_contents", "pastedContents")
41694169
type alias PromptExpectation
41704170
var raw alias
4171-
if err := json.Unmarshal(data, &raw); err != nil {
4171+
if err := json.Unmarshal(stripJSONAliasFields(data,
4172+
"Text",
4173+
"text",
4174+
"value",
4175+
"input",
4176+
"content",
4177+
"message",
4178+
"prompt",
4179+
"prompt_text",
4180+
"promptText",
4181+
"input_text",
4182+
"inputText",
4183+
"Expanded",
4184+
"expanded",
4185+
"expanded_text",
4186+
"expandedText",
4187+
"expanded_prompt",
4188+
"expandedPrompt",
4189+
"expanded_value",
4190+
"expandedValue",
4191+
"full_text",
4192+
"fullText",
4193+
"Cursor",
4194+
"cursor",
4195+
"cursor_index",
4196+
"cursorIndex",
4197+
"cursor_position",
4198+
"cursorPosition",
4199+
"caret",
4200+
"position",
4201+
"Empty",
4202+
"empty",
4203+
"is_empty",
4204+
"isEmpty",
4205+
"empty_prompt",
4206+
"emptyPrompt",
4207+
"blank",
4208+
"PastedContentCount",
4209+
"pasted_content_count",
4210+
"pastedContentCount",
4211+
"PastedContents",
4212+
"pasted_contents",
4213+
"pastedContents",
4214+
"NextPastedID",
4215+
"next_pasted_id",
4216+
"nextPastedId",
4217+
"nextPastedID",
4218+
), &raw); err != nil {
41724219
return err
41734220
}
41744221
*expect = PromptExpectation(raw)
41754222

41764223
var fields struct {
4177-
PastedContentCount *int `json:"pasted_content_count"`
4178-
PastedContentCountCamel *int `json:"pastedContentCount"`
4179-
PastedContents []PastedContentExpectation `json:"pasted_contents"`
4180-
PastedContentsCamel []PastedContentExpectation `json:"pastedContents"`
4181-
NextPastedID *int `json:"next_pasted_id"`
4182-
NextPastedIDAlt *int `json:"nextPastedId"`
4183-
NextPastedIDUpper *int `json:"nextPastedID"`
4224+
PastedContents []PastedContentExpectation `json:"PastedContents"`
4225+
PastedContentsSnake []PastedContentExpectation `json:"pasted_contents"`
4226+
PastedContentsCamel []PastedContentExpectation `json:"pastedContents"`
41844227
}
41854228
if err := json.Unmarshal(data, &fields); err != nil {
41864229
return err
@@ -4190,37 +4233,31 @@ func (expect *PromptExpectation) UnmarshalJSON(data []byte) error {
41904233
return err
41914234
}
41924235
if expect.Text == "" {
4193-
expect.Text = stringJSONField(fieldMap, "value", "input", "content", "message", "prompt", "prompt_text", "promptText", "input_text", "inputText")
4236+
expect.Text = stringJSONField(fieldMap, "Text", "text", "value", "input", "content", "message", "prompt", "prompt_text", "promptText", "input_text", "inputText")
41944237
}
41954238
if expect.Expanded == "" {
4196-
expect.Expanded = stringJSONField(fieldMap, "expanded_text", "expandedText", "expanded_prompt", "expandedPrompt", "expanded_value", "expandedValue", "full_text", "fullText")
4239+
expect.Expanded = stringJSONField(fieldMap, "Expanded", "expanded", "expanded_text", "expandedText", "expanded_prompt", "expandedPrompt", "expanded_value", "expandedValue", "full_text", "fullText")
41974240
}
41984241
if expect.Cursor == nil {
4199-
expect.Cursor = intPtrJSONField(fieldMap, "cursor_index", "cursorIndex", "cursor_position", "cursorPosition", "caret", "position")
4242+
expect.Cursor = intPtrJSONField(fieldMap, "Cursor", "cursor", "cursor_index", "cursorIndex", "cursor_position", "cursorPosition", "caret", "position")
42004243
}
4201-
if empty := boolPtrJSONField(fieldMap, "is_empty", "isEmpty", "empty_prompt", "emptyPrompt", "blank"); empty != nil {
4244+
if empty := boolPtrJSONField(fieldMap, "Empty", "empty", "is_empty", "isEmpty", "empty_prompt", "emptyPrompt", "blank"); empty != nil {
42024245
expect.Empty = *empty
42034246
}
4204-
if fields.PastedContentCount != nil {
4205-
expect.PastedContentCount = fields.PastedContentCount
4206-
}
4207-
if fields.PastedContentCountCamel != nil {
4208-
expect.PastedContentCount = fields.PastedContentCountCamel
4247+
if expect.PastedContentCount == nil {
4248+
expect.PastedContentCount = intPtrJSONField(fieldMap, "PastedContentCount", "pasted_content_count", "pastedContentCount")
42094249
}
42104250
if fields.PastedContents != nil {
42114251
expect.PastedContents = fields.PastedContents
42124252
}
4253+
if fields.PastedContentsSnake != nil {
4254+
expect.PastedContents = fields.PastedContentsSnake
4255+
}
42134256
if fields.PastedContentsCamel != nil {
42144257
expect.PastedContents = fields.PastedContentsCamel
42154258
}
4216-
if fields.NextPastedID != nil {
4217-
expect.NextPastedID = fields.NextPastedID
4218-
}
4219-
if fields.NextPastedIDAlt != nil {
4220-
expect.NextPastedID = fields.NextPastedIDAlt
4221-
}
4222-
if fields.NextPastedIDUpper != nil {
4223-
expect.NextPastedID = fields.NextPastedIDUpper
4259+
if expect.NextPastedID == nil {
4260+
expect.NextPastedID = intPtrJSONField(fieldMap, "NextPastedID", "next_pasted_id", "nextPastedId", "nextPastedID")
42244261
}
42254262
return nil
42264263
}

internal/tui/tui_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5404,9 +5404,9 @@ func TestRunInteractionScriptAcceptsWrappedPromptExpectationAliasFields(t *testi
54045404
"expectPrompt": {
54055405
"resource": {
54065406
"attributes": {
5407-
"text": "abc",
5408-
"cursorIndex": 3,
5409-
"isEmpty": false
5407+
"Text": "abc",
5408+
"Cursor": "3",
5409+
"Empty": "false"
54105410
}
54115411
}
54125412
}
@@ -5417,9 +5417,9 @@ func TestRunInteractionScriptAcceptsWrappedPromptExpectationAliasFields(t *testi
54175417
"edge": {
54185418
"node": {
54195419
"attrs": {
5420-
"blank": true,
5421-
"pastedContentCount": 0,
5422-
"nextPastedID": 1
5420+
"Empty": "true",
5421+
"PastedContentCount": "0",
5422+
"NextPastedID": "1"
54235423
}
54245424
}
54255425
}

0 commit comments

Comments
 (0)