Skip to content

fix(gateway): read_thoughts range/last queries now include branch thoughts#100

Open
glassBead-tc wants to merge 2 commits intomainfrom
fix/read-thoughts-range
Open

fix(gateway): read_thoughts range/last queries now include branch thoughts#100
glassBead-tc wants to merge 2 commits intomainfrom
fix/read-thoughts-range

Conversation

@glassBead-tc
Copy link
Member

Summary

Test plan

  • 4 new tests: range with branches, branch-only range, main-only range, last N with branches
  • All 22 gateway tests pass (no regressions)
  • All 13 branch-retrieval tests pass
  • TypeScript compiles cleanly

🤖 Generated with Claude Code

… queries

read_thoughts range, last N, and default queries used getThoughts()
which only returns main chain. Branch thoughts were invisible to these
queries despite get_structure and deep_analysis being fixed in PR #99.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 7, 2026

Greptile Overview

Greptile Summary

This PR completes the branch visibility fix started in PR #99 by updating the remaining three query paths in read_thoughts to use getAllThoughts() instead of getThoughts().

Changes:

  • Range queries now include branch thoughts (e.g., range [4, 8] returns main thoughts 4-5 + branch thoughts 6-8)
  • Last N queries now include branch thoughts in the count
  • Default queries (no parameters) now include branch thoughts in the last 5 results
  • All three changes use the same getAllThoughts() method already implemented for get_structure and deep_analysis

Test coverage:

  • 4 new tests verify range with branches, branch-only range, main-only range, and last N with branches
  • All tests validate correct thought counts and thought numbers
  • PR author confirms all 22 gateway tests and 13 branch-retrieval tests pass

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The changes are minimal, focused, and follow the exact same pattern established in PR fix(gateway): surface branch thoughts in get_structure, read_thoughts, deep_analysis #99. The implementation uses the existing getAllThoughts() method correctly across all three query paths. Comprehensive test coverage validates all scenarios. No breaking changes, security issues, or edge cases identified.
  • No files require special attention

Important Files Changed

Filename Overview
src/gateway/gateway-handler.ts Changed three query paths in read_thoughts to use getAllThoughts() instead of getThoughts(), ensuring branch thoughts are included in range, last N, and default queries. Logic is correct and consistent with PR #99 fixes.
src/gateway/tests/branch-retrieval.test.ts Added 4 comprehensive tests covering range with branches, branch-only range, main-only range, and last N with branches. Tests verify correct behavior across different query scenarios.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Gateway as GatewayHandler
    participant Storage as ThoughtboxStorage
    participant Store as LinkedThoughtStore

    Note over Client,Store: Range Query Example: [4, 8]
    Client->>Gateway: read_thoughts(range: [4, 8])
    Gateway->>Storage: getAllThoughts(sessionId)
    Storage->>Store: getSessionNodes(sessionId)
    Note over Store: Returns ALL nodes<br/>(main chain + branches)
    Store-->>Storage: [nodes 1-10]
    Storage-->>Gateway: [thoughts 1-10]
    Gateway->>Gateway: Filter: t.thoughtNumber >= 4 && <= 8
    Note over Gateway: Returns: main 4-5 + branch 6-8
    Gateway-->>Client: {count: 5, thoughts: [4,5,6,7,8]}

    Note over Client,Store: Last N Query Example: last 3
    Client->>Gateway: read_thoughts(last: 3)
    Gateway->>Storage: getAllThoughts(sessionId)
    Storage->>Store: getSessionNodes(sessionId)
    Store-->>Storage: [nodes 1-10]
    Storage-->>Gateway: [thoughts 1-10]
    Gateway->>Gateway: Slice: allThoughts.slice(-3)
    Note over Gateway: Returns: thoughts 8, 9, 10
    Gateway-->>Client: {count: 3, thoughts: [8,9,10]}

    Note over Client,Store: Default Query (no params)
    Client->>Gateway: read_thoughts()
    Gateway->>Storage: getAllThoughts(sessionId)
    Storage->>Store: getSessionNodes(sessionId)
    Store-->>Storage: [nodes 1-10]
    Storage-->>Gateway: [thoughts 1-10]
    Gateway->>Gateway: Slice: allThoughts.slice(-5)
    Note over Gateway: Returns: last 5 thoughts
    Gateway-->>Client: {count: 5, thoughts: [6,7,8,9,10]}
Loading

notebook, session, mental_models, and deep_analysis had no args
documentation in the gateway tool description. Agents had to guess
or fail once to learn the schema. Now each points to its resource
or lists its args inline.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant