Skip to content

Commit 17777be

Browse files
author
SqlRush
committed
Accept remote history HAL embedded events
1 parent a9241b6 commit 17777be

5 files changed

Lines changed: 36 additions & 4 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ M6 补充:remote history pagination 现在接受 `nextPageToken`/`nextToken`/`
7272

7373
M6 补充:contract `ID` JSON 读取现在接受 JSON number/null,remote history event/message/session/parent ID alias 可继承数字 ID 兼容面并在 transcript materialization 中保留为字符串。
7474

75-
M6 补充:remote history response parser 现在会递归解包 `data.session.events``data.projectSession.eventConnection``conversation``remoteHistory` 等 GraphQL/session wrapper,继续复用 `nodes`/`edges[].node``pageInfo` pagination 解析。
75+
M6 补充:remote history response parser 现在会递归解包 `data.session.events``data.projectSession.eventConnection``conversation``remoteHistory``_embedded` 等 GraphQL/session/HAL wrapper,继续复用 `nodes`/`edges[].node``pageInfo` pagination 解析。
7676

7777
M6 补充:remote history REST/link 风格分页现在接受 `links`/`_links``next`/`previous`/`prev`/`older` 字符串 URL 或 `{href,url,uri,link}` 对象,并从 `before_id``beforeId``cursor``pageCursor``previousCursor``prevCursor``beforeCursor``olderCursor``startCursor``endCursor` 等 query 参数提取下一页 before-id。
7878

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ test/parity/ # golden tests against TS/official behavior
195195
- 本轮补充:remote history pagination cursor/id 字段现在接受 JSON number 并原样转成字符串,覆盖 `next_cursor` 等 page 字段和 `edges[].cursor` 的数字形态。
196196
- 本轮补充:remote history pagination 现在接受 `nextPageToken`/`nextToken`/`pageToken`/`continuationToken` 及 snake_case 形式,响应字段和 link URL query 参数都会归一到续抓 before-id。
197197
- 本轮补充:contract `ID` JSON 读取现在接受 JSON number/null,remote history event/message/session/parent ID alias 可继承数字 ID 兼容面并在 transcript materialization 中保留为字符串。
198-
- 本轮补充:remote history response parser 会递归解包 `data.session.events``data.projectSession.eventConnection``conversation``remoteHistory` 等 GraphQL/session wrapper,继续复用 `nodes`/`edges[].node``pageInfo` pagination 解析。
198+
- 本轮补充:remote history response parser 会递归解包 `data.session.events``data.projectSession.eventConnection``conversation``remoteHistory``_embedded` 等 GraphQL/session/HAL wrapper,继续复用 `nodes`/`edges[].node``pageInfo` pagination 解析。
199199
- 本轮补充:transcript resume 的嵌套 content block 接受 `toolUseId`/`toolUseID``isError``cacheControl``cacheReference` 字段别名,并保留 cache edit 的 `cacheReference`
200200
- 本轮补充:transcript resume 的 nested content block `id`/`tool_use_id`/`toolUseId` 现在接受 JSON number,并保留为字符串 tool-use ID。
201201
- 本轮补充:lightweight transcript metadata loader 在 `system`/`compact_boundary` 后清空旧 `marble-origami-commit`/`marble-origami-snapshot` 状态,和 full loader/官方 sessionStorage compact-boundary 语义一致。

docs/first-second-parity-audit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ M6 progress now includes:
149149
- `internal/session`: remote-history pagination cursor/id parsing now accepts JSON numbers and preserves them as string cursors for page fields and `edges[].cursor`.
150150
- `internal/session`: remote-history pagination now accepts token aliases such as `nextPageToken`, `nextToken`, `pageToken`, and `continuationToken` in response fields and link query parameters.
151151
- `internal/contracts`: ID JSON decoding now accepts JSON numbers/null so remote-history event, message, session, and parent ID aliases can preserve numeric IDs as strings during transcript materialization.
152-
- `internal/session`: remote-history response parsing now recursively unwraps GraphQL/session containers such as `data.session.events`, `data.projectSession.eventConnection`, `conversation`, and `remoteHistory` before applying `nodes`/`edges[].node` event-list and `pageInfo` pagination parsing.
152+
- `internal/session`: remote-history response parsing now recursively unwraps GraphQL/session/HAL containers such as `data.session.events`, `data.projectSession.eventConnection`, `conversation`, `remoteHistory`, and `_embedded` before applying `nodes`/`edges[].node` event-list and `pageInfo` pagination parsing.
153153
- `internal/session`: remote-history link pagination now accepts `links`/`_links` `next`/`previous`/`prev`/`older` string URLs or `{href,url,uri,link}` objects and extracts before/cursor query parameters for continuation.
154154
- `internal/session`: remote-history link pagination now also accepts RFC/JSON:API-style `links` arrays with `rel` values such as `previous`, `prev`, `older`, and `next`.
155155
- `internal/session`: remote-history pagination now also accepts HTTP `Link` header URLs with `previous`/`prev`/`older`/`next` rels as continuation cursor fallbacks.

internal/session/remote_history.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (r *sessionEventsResponse) mergeJSON(data []byte) error {
170170
for _, name := range []string{
171171
"page", "pagination", "page_info", "pageInfo", "paging", "links", "_links", "meta", "metadata",
172172
"session", "project_session", "projectSession", "conversation", "remote_history", "remoteHistory",
173-
"event_page", "eventPage", "session_history", "sessionHistory",
173+
"event_page", "eventPage", "session_history", "sessionHistory", "_embedded", "embedded",
174174
} {
175175
value, ok := raw[name]
176176
if !ok {

internal/session/remote_history_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,38 @@ func TestFetchRemoteHistoryAcceptsHALLinkCursors(t *testing.T) {
466466
}
467467
}
468468

469+
func TestFetchRemoteHistoryAcceptsHALEmbeddedEvents(t *testing.T) {
470+
var seen []url.Values
471+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
472+
seen = append(seen, r.URL.Query())
473+
w.Header().Set("Content-Type", "application/json")
474+
switch r.URL.Query().Get("before_id") {
475+
case "":
476+
_, _ = w.Write([]byte(`{"_embedded":{"events":[{"type":"status","session_id":"s","status":"latest"}]},"_links":{"prev":{"href":"/v1/sessions/s/events?before_id=evt_embed"}}}`))
477+
case "evt_embed":
478+
_, _ = w.Write([]byte(`{"embedded":{"items":[{"type":"status","session_id":"s","status":"older"}]},"_links":{}}`))
479+
default:
480+
t.Fatalf("unexpected before_id = %q", r.URL.Query().Get("before_id"))
481+
}
482+
}))
483+
defer server.Close()
484+
485+
authCtx := NewRemoteHistoryAuthContext("s", "token", "", auth.OAuthConfig{BaseAPIURL: server.URL})
486+
events, err := FetchRemoteHistory(context.Background(), server.Client(), authCtx, RemoteHistoryFetchOptions{Limit: 2})
487+
if err != nil {
488+
t.Fatal(err)
489+
}
490+
if !events.Complete || events.Pages != 2 || len(events.Events) != 2 || events.NextBeforeID != "" {
491+
t.Fatalf("events = %#v", events)
492+
}
493+
if events.Events[0].Status != "latest" || events.Events[1].Status != "older" {
494+
t.Fatalf("events = %#v", events.Events)
495+
}
496+
if len(seen) != 2 || seen[1].Get("before_id") != "evt_embed" {
497+
t.Fatalf("queries = %#v", seen)
498+
}
499+
}
500+
469501
func TestFetchRemoteHistoryAcceptsLinkHeaderCursors(t *testing.T) {
470502
var seen []url.Values
471503
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)