Skip to content

Commit f36cde8

Browse files
author
SqlRush
committed
Accept prompt history session aliases
1 parent 77317b6 commit f36cde8

5 files changed

Lines changed: 20 additions & 2 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ M7 补充:Ctrl-S prompt stash 现在保存并恢复 prompt text、cursor 和 p
150150

151151
M7 补充:prompt history pasted-content 读取现在接受 `mimeType`/`mime_type`/`contentType``fileName`/`file_name`/`name``filePath`/`file_path`/`path` 等 text/image metadata 别名,历史恢复路径和 image hint/parser metadata 兼容面保持一致。
152152

153+
M7 补充:prompt history `LogEntry` 读取现在接受 `sessionID`/`session`/`sessionUuid`/`sessionUUID`/`session_uuid` 作为 session id 别名,current-session-first 历史排序不会因 session 字段拼写不同而失效。
154+
153155
当前状态不是 100% 还原,而是“核心地基 + 运行时框架 + 第一批具体工具”的可编译阶段。
154156

155157
## Milestones

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ test/parity/ # golden tests against TS/official behavior
252252
- 本轮补充:REPL message metadata 保留 `imagePasteIds`,并从已有用户消息的 image ids 和 pasted refs 初始化/推进 `NextPastedID`,贴近官方 resume/continue 避免 paste ID 重用的逻辑。
253253
- 本轮补充:reverse-search 现在按完整 `HistoryEntry` 匹配和选择历史,选中后恢复 text/image pasted-content metadata,后续 submit event 仍携带 display 与图片元数据。
254254
- 本轮补充:prompt history pasted-content 读取接受 `mimeType`/`mime_type`/`contentType``fileName`/`file_name`/`name``filePath`/`file_path`/`path` 等 text/image metadata 别名,使历史恢复路径和 image hint/parser metadata 兼容面一致。
255+
- 本轮补充:prompt history `LogEntry` 读取接受 `sessionID`/`session`/`sessionUuid`/`sessionUUID`/`session_uuid` 作为 session id 别名,current-session-first 历史排序不会因 session 字段拼写不同而失效。
255256
- 本轮补充:REPL message restore 现在可从用户消息 content blocks、`imagePasteIds` 和 pasted-content metadata 重建 prompt text、`[Image #N]` 引用和 base64 image pasted contents。
256257
- 本轮补充:Ctrl-S prompt stash 现在保存/恢复 prompt text、cursor 和 pasted-content metadata,空 prompt 下再次触发会恢复 stash,贴近官方 `chat:stash`
257258
- 本轮补充:remote history REST/link 风格分页接受 `links.next`/`links.previous`/`links.prev`/`links.older` 的字符串 URL 或 `{href,url,uri,link}` 对象,并从 `before_id``beforeId``cursor``pageCursor``previousCursor``prevCursor``beforeCursor``olderCursor``startCursor``endCursor` 等 query 参数提取续抓 before-id。

docs/first-second-parity-audit.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ M7 progress now includes:
213213
- `internal/tui`: REPL messages now preserve `imagePasteIds`, and prompt state advances `NextPastedID` from existing user-message image ids and pasted refs so resumed screens do not reuse paste IDs.
214214
- `internal/tui`: reverse-search now matches full history entries and restores text/image pasted-content metadata on selection, so the next submit still carries display text and image metadata.
215215
- `internal/session`: prompt-history pasted-content loading now accepts `mimeType`/`mime_type`/`contentType`, `fileName`/`file_name`/`name`, and `filePath`/`file_path`/`path` metadata aliases so restored image/text paste metadata matches the image hint/parser compatibility surface.
216+
- `internal/session`: prompt-history log entries now accept `sessionID`/`session`/`sessionUuid`/`sessionUUID`/`session_uuid` session id aliases so current-session-first history ordering survives field spelling differences.
216217
- `internal/tui`: REPL message restore can now rebuild prompt text and image pasted contents from user-message content blocks, `imagePasteIds`, and pasted-content metadata.
217218
- `internal/tui`: Ctrl-S prompt stash now preserves and restores prompt text, cursor position, and pasted-content metadata.
218219
- `internal/tui`: prompt submitted events now retain display text and pasted-content metadata, so downstream runtime code can build text/image content-block messages instead of receiving only the expanded prompt string.

internal/session/history_aliases.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ func (e *LogEntry) UnmarshalJSON(data []byte) error {
150150
var aux struct {
151151
*LogEntryJSON
152152
PastedContentsSnake map[int]StoredPastedContent `json:"pasted_contents"`
153+
SessionIDUpper contracts.ID `json:"sessionID"`
153154
SessionIDSnake contracts.ID `json:"session_id"`
155+
Session contracts.ID `json:"session"`
156+
SessionUUID contracts.ID `json:"sessionUuid"`
157+
SessionUUIDUpper contracts.ID `json:"sessionUUID"`
158+
SessionUUIDSnake contracts.ID `json:"session_uuid"`
154159
}
155160
base := LogEntryJSON{}
156161
aux.LogEntryJSON = &base
@@ -162,7 +167,16 @@ func (e *LogEntry) UnmarshalJSON(data []byte) error {
162167
e.PastedContents = aux.PastedContentsSnake
163168
}
164169
if e.SessionID == "" {
165-
e.SessionID = aux.SessionIDSnake
170+
e.SessionID = firstHistoryID(aux.SessionIDUpper, aux.SessionIDSnake, aux.Session, aux.SessionUUID, aux.SessionUUIDUpper, aux.SessionUUIDSnake)
166171
}
167172
return nil
168173
}
174+
175+
func firstHistoryID(values ...contracts.ID) contracts.ID {
176+
for _, value := range values {
177+
if value != "" {
178+
return value
179+
}
180+
}
181+
return ""
182+
}

internal/session/history_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestAppendAndLoadPromptHistory(t *testing.T) {
123123

124124
func TestLoadPromptHistoryAcceptsFieldAliases(t *testing.T) {
125125
path := filepath.Join(t.TempDir(), "history.jsonl")
126-
line := `{"display":"run [Pasted text #1] [Image #2] [Image #3]","pasted_contents":{"1":{"id":1,"type":"text","content_hash":"hash_1","contentType":"text/plain"},"2":{"id":2,"type":"image","media_type":"image/png","filename":"chart.png","source_path":"/tmp/chart.png","dimensions":{"original_width":4000,"original_height":2000,"display_width":1000,"display_height":500}},"3":{"id":3,"type":"image","mime_type":"image/jpeg","fileName":"photo.jpg","file_path":"/tmp/photo.jpg","dimensions":{"width":3000,"height":1500}}},"timestamp":100,"project":"/repo","session_id":"session"}`
126+
line := `{"display":"run [Pasted text #1] [Image #2] [Image #3]","pasted_contents":{"1":{"id":1,"type":"text","content_hash":"hash_1","contentType":"text/plain"},"2":{"id":2,"type":"image","media_type":"image/png","filename":"chart.png","source_path":"/tmp/chart.png","dimensions":{"original_width":4000,"original_height":2000,"display_width":1000,"display_height":500}},"3":{"id":3,"type":"image","mime_type":"image/jpeg","fileName":"photo.jpg","file_path":"/tmp/photo.jpg","dimensions":{"width":3000,"height":1500}}},"timestamp":100,"project":"/repo","sessionID":"session"}`
127127
if err := os.WriteFile(path, []byte(line+"\n"), 0o600); err != nil {
128128
t.Fatal(err)
129129
}

0 commit comments

Comments
 (0)